From d5c45dc580472b9f5507987872534a33fcabd508 Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Fri, 19 Jan 2024 06:50:17 +0100 Subject: [PATCH] codecs: match all AMR rates and modes In msc_a_up_call_assignment_complete(), iterate all the new AMR modes and rates recently added to codec_mapping, and enlist all possible matches. Change-Id: I6163a51765efff998e05c9ee4e82a0a3759f2043 --- src/libmsc/codec_mapping.c | 3 ++- src/libmsc/msc_a.c | 23 +++++++++++++++++++---- tests/msc_vlr/msc_vlr_test_call.c | 17 +++++++++++------ 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/libmsc/codec_mapping.c b/src/libmsc/codec_mapping.c index 7ddf4e017..f2c3c1aee 100644 --- a/src/libmsc/codec_mapping.c +++ b/src/libmsc/codec_mapping.c @@ -204,7 +204,7 @@ static const struct codec_mapping codec_map[] = { AMR_FR(IS_OA, FMTP_PREFIX "mode-set=0,2,3,4", S(10)), \ AMR_FR(IS_OA, FMTP_PREFIX "mode-set=0,2,3,6", S(12)), \ AMR_FR(IS_OA, FMTP_PREFIX "mode-set=0,2,5,7", S(14)), \ - /* AMR FR: S1 in compatibility with AMR-HR = without 12k2 */ \ + /* AMR-FR with a mode-set compatible with AMR-HR on S1 */ \ AMR_FR(IS_OA, FMTP_PREFIX "mode-set=0,2,4", S(1)), \ \ /* HR rates */ \ @@ -225,6 +225,7 @@ static const struct codec_mapping codec_map[] = { /* FR rates */ \ AMR_FR(IS_OA, FMTP_PREFIX "mode-set=0,2,4,7", S(1)), \ AMR_FR(IS_OA, FMTP_PREFIX "mode-set=7", S(7)), \ + /* AMR-FR with a mode-set compatible with AMR-HR on S1 */ \ AMR_FR(IS_OA, FMTP_PREFIX "mode-set=0,2,4", S(1)), \ \ /* HR rates */ \ diff --git a/src/libmsc/msc_a.c b/src/libmsc/msc_a.c index 38f05a6d4..991661c55 100644 --- a/src/libmsc/msc_a.c +++ b/src/libmsc/msc_a.c @@ -1463,6 +1463,8 @@ static void msc_a_up_call_assignment_complete(struct msc_a *msc_a, const struct if (codec_if_known) { const struct codec_mapping *codec_assigned; + const struct codec_mapping *m; + bool use_octet_aligned_on_aoip = true; /* TODO: by VTY config */ /* Check for unexpected codec with CSD */ if (cc_trans->bearer_cap.transfer == GSM48_BCAP_ITCAP_UNR_DIG_INF && @@ -1486,15 +1488,28 @@ static void msc_a_up_call_assignment_complete(struct msc_a *msc_a, const struct * - ran_msg_iu.c always returns FR3 (AMR FR) for the assigned codec. Set that at the MGW towards CN. * - So the MGW decapsulates IuUP <-> AMR */ - codec_assigned = codec_mapping_by_gsm0808_speech_codec_type(codec_if_known->type); - /* TODO: use codec_mapping_by_gsm0808_speech_codec() to also match on codec_if_known->cfg */ + + codec_assigned = NULL; + codec_mapping_foreach (m) { + /* look for a full match, including the S0-S15 bits in codec.cfg that configure AMR rates. */ + if (!codec_mapping_matches_gsm0808_speech_codec(m, codec_if_known)) + continue; + /* In case of AMR, match OA/BE with what osmo-msc should use on AoIP (configured in VTY) */ + if (m->amr.is_amr && m->amr.is_octet_aligned != use_octet_aligned_on_aoip) + continue; + codec_assigned = m; + break; + } + if (!codec_assigned) { - LOG_TRANS(cc_trans, LOGL_ERROR, "Unknown codec in Assignment Complete: %s\n", - gsm0808_speech_codec_type_name(codec_if_known->type)); + LOG_TRANS(cc_trans, LOGL_ERROR, "Unknown codec in Assignment Complete: %s 0x%x\n", + gsm0808_speech_codec_type_name(codec_if_known->type), codec_if_known->cfg); call_leg_release(msc_a->cc.call_leg); return; } + /* TODO: validate that the codec was indeed allowed */ + /* Update RAN-side endpoint CI from Assignment result -- unless it is forced by the ran_infra, in which * case it remains unchanged as passed to the earlier call of call_leg_ensure_ci(). */ if (msc_a->c.ran->force_mgw_codecs_to_ran.count == 0) diff --git a/tests/msc_vlr/msc_vlr_test_call.c b/tests/msc_vlr/msc_vlr_test_call.c index 658b490a0..78a5c2a55 100644 --- a/tests/msc_vlr/msc_vlr_test_call.c +++ b/tests/msc_vlr/msc_vlr_test_call.c @@ -871,27 +871,32 @@ struct codec_test { LIST_END \ } -#define SDP_CODECS_ALL_GSM \ - { \ - "AMR:octet-align=1;mode-set=0,2,4,7#112", \ + +/* EXPECTED FAILURE: These entries are currently missing until upcoming patches are merged: "AMR:octet-align=1;mode-set=7#114", \ "AMR:octet-align=1;mode-set=0,2,4#115", \ "AMR:mode-set=0,2,4,7#116", \ "AMR:mode-set=7#117", \ "AMR:mode-set=0,2,4#118", \ +*/ +#define SDP_CODECS_ALL_GSM \ + { \ + "AMR:octet-align=1;mode-set=0,2,4,7#112", \ "GSM-EFR#110", \ "GSM#3", \ "GSM-HR-08#111", \ } -#define SDP_CODECS_ALL_GSM_WITH_ODD_PT_NRS \ - { \ - "AMR:octet-align=1;mode-set=0,2,4,7#127", \ +/* EXPECTED FAILURE: These entries are currently missing until upcoming patches are merged: "AMR:octet-align=1;mode-set=7#126", \ "AMR:octet-align=1;mode-set=0,2,4#125", \ "AMR:mode-set=0,2,4,7#124", \ "AMR:mode-set=7#123", \ "AMR:mode-set=0,2,4#122", \ +*/ +#define SDP_CODECS_ALL_GSM_WITH_ODD_PT_NRS \ + { \ + "AMR:octet-align=1;mode-set=0,2,4,7#127", \ "GSM-EFR#110", \ "GSM#3", \ "GSM-HR-08#111", \