BSC_Tests: use correct payload types and encoding names on MGCP

The test currently use a hardcoded payload type and encoding name.
This does mean in practice that even when an assignment with EFR
is happeining. The MGCP responses to the BSC tell that the codec
is AMR. This is not correct. The testcases should always pick a
suitable payload type / encoding name in the MGCP response

- Add constants for IANA/3GPP assigned payload types
- Add function to lookup the right encoding name for a payload type
- Initalize the encoding name and payload type in g_media according
  to the BSSAP PDU.

Change-Id: I2735267091059e2f2169da80bdcd30abc2b1554b
Realted: OS#2728
diff --git a/bsc/MSC_ConnectionHandler.ttcn b/bsc/MSC_ConnectionHandler.ttcn
index 2042979..0f123b6 100644
--- a/bsc/MSC_ConnectionHandler.ttcn
+++ b/bsc/MSC_ConnectionHandler.ttcn
@@ -32,6 +32,24 @@
  * Media related handling
  ***********************************************************************/
 
+/* Get the matching payload type for a specified BSSAP codec type
+ * (see also: BSSAP_Types.ttcn */
+private function f_get_mgcp_pt(BSSMAP_FIELD_CodecType codecType) return SDP_FIELD_PayloadType {
+	if (codecType == GSM_FR) {
+		return PT_GSM;
+	} else if (codecType == GSM_HR) {
+		return PT_GSMHR;
+	} else if (codecType == GSM_EFR) {
+		return PT_GSMEFR;
+	} else if (codecType == FR_AMR or codecType == HR_AMR) {
+		return PT_AMR;
+	} else if (codecType == FR_AMR_WB or codecType == OHR_AMR or codecType == OFR_AMR_WB or codecType == OHR_AMR_WB) {
+		return PT_AMRWB;
+	}
+
+	return PT_PCMU;
+}
+
 /* Tuple containing host/ip and port */
 type record HostPort {
 	HostName	host,
@@ -66,7 +84,7 @@
 	BtsMediaState	bts1 /* only during hand-over */
 };
 
-function f_MediaState_init(inout MediaState g_media, integer nr, HostName bts, HostName mgw) {
+function f_MediaState_init(inout MediaState g_media, integer nr, HostName bts, HostName mgw, BSSMAP_FIELD_CodecType codecType) {
 	/* BTS Side */
 	g_media.bts := {
 		ipa_crcx_seen := false,
@@ -93,10 +111,10 @@
 	g_media.mgcp_ep := "rtpbridge/" & int2str(nr) & "@mgw";
 
 	for (var integer i:= 0; i < sizeof(g_media.mgcp_conn); i := i+1) {
-		g_media.mgcp_conn[i].mime_type := "AMR";
+		g_media.mgcp_conn[i].mime_type := f_encoding_name_from_pt(f_get_mgcp_pt(codecType));
 		g_media.mgcp_conn[i].sample_rate := 8000;
 		g_media.mgcp_conn[i].ptime := 20;
-		g_media.mgcp_conn[i].rtp_pt := 98;
+		g_media.mgcp_conn[i].rtp_pt := enum2int(f_get_mgcp_pt(codecType));
 		g_media.mgcp_conn[i].crcx_seen := false;
 		g_media.mgcp_conn[i].conn_id := f_mgcp_alloc_conn_id();
 	}
@@ -301,8 +319,8 @@
 }
 
 /* initialize all parameters */
-function f_MscConnHdlr_init(integer i, HostName bts, HostName mgw) runs on MSC_ConnHdlr {
-	f_MediaState_init(g_media, i, bts, mgw);
+function f_MscConnHdlr_init(integer i, HostName bts, HostName mgw, BSSMAP_FIELD_CodecType codecType) runs on MSC_ConnHdlr {
+	f_MediaState_init(g_media, i, bts, mgw, codecType);
 	if (not g_vty_initialized) {
 		map(self:BSCVTY, system:BSCVTY);
 		f_vty_set_prompts(BSCVTY);
@@ -754,7 +772,18 @@
 /* establish a channel fully, expecting an assignment matching 'exp' */
 function f_establish_fully(template (omit) PDU_BSSAP ass_tpl, template PDU_BSSAP exp_ass_cpl)
 runs on MSC_ConnHdlr {
-	f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3");
+
+	var BSSMAP_FIELD_CodecType codecType;
+
+	if (isvalue(ass_tpl.pdu.bssmap.assignmentRequest.codecList)) {
+		codecType := valueof(ass_tpl.pdu.bssmap.assignmentRequest.codecList.codecElements[0].codecType);
+	} else {
+		/* Make sure a meaningful default is assigned in case the
+		 * codecList is not populated */
+		codecType := FR_AMR;
+	}
+
+	f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", codecType);
 
 	/* patch in the LCLS related items, as needed */
 	f_ass_patch_lcls(ass_tpl, exp_ass_cpl);