diff --git a/bsc/MSC_ConnectionHandler.ttcn b/bsc/MSC_ConnectionHandler.ttcn index 2042979db..0f123b6ae 100644 --- a/bsc/MSC_ConnectionHandler.ttcn +++ b/bsc/MSC_ConnectionHandler.ttcn @@ -32,6 +32,24 @@ import from Osmocom_VTY_Functions all; * 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 @@ type record MediaState { 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 @@ function f_MediaState_init(inout MediaState g_media, integer nr, HostName bts, H 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 @@ type component MSC_ConnHdlr extends BSSAP_ConnHdlr, RSL_DchanHdlr, MGCP_ConnHdlr } /* 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 @@ function f_ass_patch_lcls(inout template (omit) PDU_BSSAP ass_tpl, /* 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); diff --git a/library/MGCP_Emulation.ttcn b/library/MGCP_Emulation.ttcn index b02dc0615..0863511eb 100644 --- a/library/MGCP_Emulation.ttcn +++ b/library/MGCP_Emulation.ttcn @@ -441,5 +441,26 @@ runs on MGCP_Emulation_CT return template MgcpMessage { return omit; } +/* Determine encoding name for a specified payload type number */ +function f_encoding_name_from_pt(SDP_FIELD_PayloadType pt) return charstring { + if (pt == PT_PCMU) { + return "PCMU"; + } else if (pt == PT_GSM) { + return "GSM"; + } else if (pt == PT_PCMA) { + return "PCMA"; + } else if (pt == PT_GSMEFR) { + return "GSM-EFR"; + } else if (pt == PT_GSMHR) { + return "GSM-HR-08"; + } else if (pt == PT_AMR) { + return "AMR"; + } else if (pt == PT_AMRWB) { + return "AMR-WB"; + } + + setverdict(fail); + return ""; +} } diff --git a/library/MGCP_Types.ttcn b/library/MGCP_Types.ttcn index 9d1a4e138..6bb266ea3 100644 --- a/library/MGCP_Types.ttcn +++ b/library/MGCP_Types.ttcn @@ -121,5 +121,16 @@ module MGCP_Types { external function dec_MgcpMessage(in charstring id) return MgcpMessage with { extension "prototype(convert) decode(TEXT)" }; + /* IANA / 3gpp assigned payload type numbers */ + type enumerated SDP_FIELD_PayloadType { + PT_PCMU(0), + PT_GSM(3), + PT_PCMA(8), + PT_G729(18), + PT_GSMEFR(110), + PT_GSMHR(111), + PT_AMR(112), + PT_AMRWB(113) + } } with { encode "TEXT" }