mgcp: Allow to freely control the a=fmtp line for experiments

In case of AMR one can specify the available codecs out-of-band. Allow
to configure this line statically in the configuration file.
diff --git a/openbsc/include/openbsc/mgcp.h b/openbsc/include/openbsc/mgcp.h
index 858a29d..7a416dd 100644
--- a/openbsc/include/openbsc/mgcp.h
+++ b/openbsc/include/openbsc/mgcp.h
@@ -111,6 +111,7 @@
 	int trunk_nr;
 	int trunk_type;
 
+	char *audio_fmtp_extra;
 	char *audio_name;
 	int audio_payload;
 	int audio_loop;
diff --git a/openbsc/include/openbsc/mgcp_internal.h b/openbsc/include/openbsc/mgcp_internal.h
index bcef872..455bb53 100644
--- a/openbsc/include/openbsc/mgcp_internal.h
+++ b/openbsc/include/openbsc/mgcp_internal.h
@@ -67,7 +67,9 @@
 	/* in network byte order */
 	int rtp_port, rtcp_port;
 
+	/* per endpoint data */
 	int payload_type;
+	char *fmtp_extra;
 
 	/*
 	 * Each end has a socket...
diff --git a/openbsc/src/libmgcp/mgcp_protocol.c b/openbsc/src/libmgcp/mgcp_protocol.c
index 63fee5f..6919a59 100644
--- a/openbsc/src/libmgcp/mgcp_protocol.c
+++ b/openbsc/src/libmgcp/mgcp_protocol.c
@@ -190,6 +190,7 @@
 					     const char *msg, const char *trans_id)
 {
 	const char *addr = endp->cfg->local_ip;
+	const char *fmtp_extra = endp->bts_end.fmtp_extra;
 	char sdp_record[4096];
 
 	if (!addr)
@@ -202,10 +203,12 @@
 			"c=IN IP4 %s\r\n"
 			"t=0 0\r\n"
 			"m=audio %d RTP/AVP %d\r\n"
-			"a=rtpmap:%d %s\r\n",
+			"a=rtpmap:%d %s\r\n"
+			"%s%s",
 			endp->ci, endp->ci, addr, addr,
 			endp->net_end.local_port, endp->bts_end.payload_type,
-			endp->bts_end.payload_type, endp->tcfg->audio_name);
+			endp->bts_end.payload_type, endp->tcfg->audio_name,
+			fmtp_extra ? fmtp_extra : "", fmtp_extra ? "\r\n" : "");
 	return create_resp(endp, 200, " OK", msg, trans_id, NULL, sdp_record);
 }
 
@@ -587,6 +590,8 @@
 
 	endp->allocated = 1;
 	endp->bts_end.payload_type = tcfg->audio_payload;
+	endp->bts_end.fmtp_extra = talloc_strdup(tcfg->endpoints,
+						tcfg->audio_fmtp_extra);
 
 	/* policy CB */
 	if (p->cfg->policy_cb) {
@@ -958,6 +963,8 @@
 	end->rtp_port = end->rtcp_port = 0;
 	end->payload_type = -1;
 	end->local_alloc = -1;
+	talloc_free(end->fmtp_extra);
+	end->fmtp_extra = NULL;
 }
 
 static void mgcp_rtp_end_init(struct mgcp_rtp_end *end)
diff --git a/openbsc/src/libmgcp/mgcp_vty.c b/openbsc/src/libmgcp/mgcp_vty.c
index 122fa84..88d793f 100644
--- a/openbsc/src/libmgcp/mgcp_vty.c
+++ b/openbsc/src/libmgcp/mgcp_vty.c
@@ -94,6 +94,9 @@
 	if (g_cfg->trunk.audio_name)
 		vty_out(vty, "  sdp audio-payload name %s%s",
 			g_cfg->trunk.audio_name, VTY_NEWLINE);
+	if (g_cfg->trunk.audio_fmtp_extra)
+		vty_out(vty, "  sdp audio fmtp-extra %s%s",
+			g_cfg->trunk.audio_fmtp_extra, VTY_NEWLINE);
 	vty_out(vty, "  loop %u%s", !!g_cfg->trunk.audio_loop, VTY_NEWLINE);
 	vty_out(vty, "  number endpoints %u%s", g_cfg->trunk.number_endpoints - 1, VTY_NEWLINE);
 	if (g_cfg->call_agent_addr)
@@ -321,6 +324,19 @@
       RTP_STR
       "Apply IP_TOS to the audio stream\n" "The DSCP value\n")
 
+DEFUN(cfg_mgcp_sdp_fmtp_extra,
+      cfg_mgcp_sdp_fmtp_extra_cmd,
+      "sdp audio fmtp-extra .NAME",
+      "Add extra fmtp for the SDP file\n")
+{
+	char *txt = argv_concat(argv, argc, 0);
+	if (!txt)
+		return CMD_WARNING;
+
+	bsc_replace_string(g_cfg, &g_cfg->trunk.audio_fmtp_extra, txt);
+	talloc_free(txt);
+	return CMD_SUCCESS;
+}
 
 #define SDP_STR "SDP File related options\n"
 #define AUDIO_STR "Audio payload options\n"
@@ -481,11 +497,29 @@
 			vty_out(vty, "  rtcp-omit%s", VTY_NEWLINE);
 		else
 			vty_out(vty, "  no rtcp-omit%s", VTY_NEWLINE);
+		if (trunk->audio_fmtp_extra)
+			vty_out(vty, "   sdp audio fmtp-extra %s%s",
+				trunk->audio_fmtp_extra, VTY_NEWLINE);
 	}
 
 	return CMD_SUCCESS;
 }
 
+DEFUN(cfg_trunk_sdp_fmtp_extra,
+      cfg_trunk_sdp_fmtp_extra_cmd,
+      "sdp audio fmtp-extra .NAME",
+      "Add extra fmtp for the SDP file\n")
+{
+	struct mgcp_trunk_config *trunk = vty->index;
+	char *txt = argv_concat(argv, argc, 0);
+	if (!txt)
+		return CMD_WARNING;
+
+	bsc_replace_string(g_cfg, &trunk->audio_fmtp_extra, txt);
+	talloc_free(txt);
+	return CMD_SUCCESS;
+}
+
 DEFUN(cfg_trunk_payload_number,
       cfg_trunk_payload_number_cmd,
       "sdp audio-payload number <1-255>",
@@ -780,6 +814,7 @@
 	install_element(MGCP_NODE, &cfg_mgcp_number_endp_cmd);
 	install_element(MGCP_NODE, &cfg_mgcp_omit_rtcp_cmd);
 	install_element(MGCP_NODE, &cfg_mgcp_no_omit_rtcp_cmd);
+	install_element(MGCP_NODE, &cfg_mgcp_sdp_fmtp_extra_cmd);
 
 	install_element(MGCP_NODE, &cfg_mgcp_trunk_cmd);
 	install_node(&trunk_node, config_write_trunk);
@@ -793,6 +828,7 @@
 	install_element(TRUNK_NODE, &cfg_trunk_loop_cmd);
 	install_element(TRUNK_NODE, &cfg_trunk_omit_rtcp_cmd);
 	install_element(TRUNK_NODE, &cfg_trunk_no_omit_rtcp_cmd);
+	install_element(TRUNK_NODE, &cfg_trunk_sdp_fmtp_extra_cmd);
 
 	return 0;
 }