From 10d47901fd60606a69e207b60663aaa9e0a09ad0 Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Fri, 2 Feb 2024 08:34:29 +0100 Subject: [PATCH] make default RAN codecs configurable in ran_infra Instead of generating the default codecs list for a RAN for each call, place a pre-composed list in ran_infra.c. (1) The main aim is to allow configuring this list -- subsequent commit Ib5655214ce48c66d095e8f1b7b7106ac3ee43ec0 will add the VTY commands to modify the predefined lists. (2) As a free side effect, this also allows configuring the order of preference for specific codecs. (3) It may also save us some iterations of the codec_map[], which may grow a lot more variants; for example, we could add one entry for each possible AMR mode-set... Change-Id: If46231a53f7512dbd81790fd30462d65fe059aa3 --- include/osmocom/msc/codec_filter.h | 2 +- include/osmocom/msc/ran_infra.h | 3 ++ src/libmsc/codec_filter.c | 48 ++++-------------------------- src/libmsc/ran_infra.c | 29 ++++++++++++++++++ src/libmsc/transaction_cc.c | 3 +- 5 files changed, 41 insertions(+), 44 deletions(-) diff --git a/include/osmocom/msc/codec_filter.h b/include/osmocom/msc/codec_filter.h index da4a67e04..a8be8445e 100644 --- a/include/osmocom/msc/codec_filter.h +++ b/include/osmocom/msc/codec_filter.h @@ -44,7 +44,7 @@ struct codec_filter { struct sdp_audio_codec assignment; }; -void codec_filter_set_ran(struct codec_filter *codec_filter, enum osmo_rat_type ran_type); +void codec_filter_set_ran(struct codec_filter *codec_filter, const struct sdp_audio_codecs *codecs); void codec_filter_set_bss(struct codec_filter *codec_filter, const struct gsm0808_speech_codec_list *codec_list_bss_supported); int codec_filter_run(struct codec_filter *codec_filter, struct sdp_msg *result, const struct sdp_msg *remote); diff --git a/include/osmocom/msc/ran_infra.h b/include/osmocom/msc/ran_infra.h index 262a9c82e..f96e2cfc9 100644 --- a/include/osmocom/msc/ran_infra.h +++ b/include/osmocom/msc/ran_infra.h @@ -26,6 +26,9 @@ struct ran_infra { const ran_dec_l2_t ran_dec_l2; const ran_encode_t ran_encode; struct sccp_ran_inst *sri; + /* Codecs available on this RAN type by default, in order of preference. If empty, all known codecs will be + * allowed and offered to peers. */ + struct sdp_audio_codecs codecs; /* To always set up the MGW endpoint facing the RAN side with specific codecs, list those here. Otherwise leave * empty (to use the result of codecs filtering). This exists for IuCS, to always set the MGW endpoint facing * RAN to IUFP, to decapsulate the IuUP headers. */ diff --git a/src/libmsc/codec_filter.c b/src/libmsc/codec_filter.c index 5485814f6..249df858a 100644 --- a/src/libmsc/codec_filter.c +++ b/src/libmsc/codec_filter.c @@ -25,52 +25,16 @@ #include #include +#include #include -/* Add all known payload types encountered in GSM networks */ -static void sdp_add_all_geran_codecs(struct sdp_audio_codecs *ac) -{ - /* In order of preference. TODO: make configurable */ - static const enum gsm48_bcap_speech_ver mobile_codecs[] = { - GSM48_BCAP_SV_AMR_F /*!< 4 GSM FR V3 (FR AMR) */, - GSM48_BCAP_SV_AMR_H /*!< 5 GSM HR V3 (HR_AMR) */, - GSM48_BCAP_SV_EFR /*!< 2 GSM FR V2 (GSM EFR) */, - GSM48_BCAP_SV_FR /*!< 0 GSM FR V1 (GSM FR) */, - GSM48_BCAP_SV_HR /*!< 1 GSM HR V1 (GSM HR) */, - }; - int i; - for (i = 0; i < ARRAY_SIZE(mobile_codecs); i++) - sdp_audio_codecs_add_speech_ver(ac, mobile_codecs[i]); -} - -/* Add all known AMR payload types encountered in UTRAN networks */ -static void sdp_add_all_utran_codecs(struct sdp_audio_codecs *ac) -{ - /* In order of preference. TODO: make configurable */ - static const enum gsm48_bcap_speech_ver utran_codecs[] = { - GSM48_BCAP_SV_AMR_F /*!< 4 GSM FR V3 (FR AMR) */, - GSM48_BCAP_SV_AMR_H /*!< 5 GSM HR V3 (HR_AMR) */, - GSM48_BCAP_SV_AMR_FW /*!< 8 GSM FR V5 (FR AMR-WB) */, - }; - int i; - for (i = 0; i < ARRAY_SIZE(utran_codecs); i++) - sdp_audio_codecs_add_speech_ver(ac, utran_codecs[i]); -} - -void codec_filter_set_ran(struct codec_filter *codec_filter, enum osmo_rat_type ran_type) +void codec_filter_set_ran(struct codec_filter *codec_filter, const struct sdp_audio_codecs *codecs) { + const struct sdp_audio_codec *c; codec_filter->ran = (struct sdp_audio_codecs){}; - - switch (ran_type) { - default: - case OSMO_RAT_GERAN_A: - sdp_add_all_geran_codecs(&codec_filter->ran); - break; - - case OSMO_RAT_UTRAN_IU: - sdp_add_all_utran_codecs(&codec_filter->ran); - break; - } + /* Add codecs one by one, to resolve any payload type number conflicts or duplicates. */ + sdp_audio_codecs_foreach (c, codecs) + sdp_audio_codecs_add_copy(&codec_filter->ran, c, true, true); } void codec_filter_set_bss(struct codec_filter *codec_filter, diff --git a/src/libmsc/ran_infra.c b/src/libmsc/ran_infra.c index 6a178403f..07a1cd2da 100644 --- a/src/libmsc/ran_infra.c +++ b/src/libmsc/ran_infra.c @@ -28,6 +28,7 @@ #include #include #include +#include #include @@ -128,3 +129,31 @@ struct ran_infra msc_ran_infra[] = { }; const int msc_ran_infra_len = ARRAY_SIZE(msc_ran_infra); + +static __attribute__((constructor)) void on_dso_load_geran(void) +{ + /* Initialize GERAN default codecs, in order of preference. By definition, all codec_mapping entries that match + * one of the GERAN GMSK Speech Versions are available. */ + static const enum gsm48_bcap_speech_ver mobile_codecs[] = { + GSM48_BCAP_SV_AMR_F /*!< 4 GSM FR V3 (FR AMR) */, + GSM48_BCAP_SV_AMR_H /*!< 5 GSM HR V3 (HR_AMR) */, + GSM48_BCAP_SV_EFR /*!< 2 GSM FR V2 (GSM EFR) */, + GSM48_BCAP_SV_FR /*!< 0 GSM FR V1 (GSM FR) */, + GSM48_BCAP_SV_HR /*!< 1 GSM HR V1 (GSM HR) */, + }; + int i; + for (i = 0; i < ARRAY_SIZE(mobile_codecs); i++) + sdp_audio_codecs_add_speech_ver(&msc_ran_infra[OSMO_RAT_GERAN_A].codecs, mobile_codecs[i]); +} + +static __attribute__((constructor)) void on_dso_load_utran(void) +{ + static const enum gsm48_bcap_speech_ver utran_codecs[] = { + GSM48_BCAP_SV_AMR_F /*!< 4 GSM FR V3 (FR AMR) */, + GSM48_BCAP_SV_AMR_H /*!< 5 GSM HR V3 (HR_AMR) */, + GSM48_BCAP_SV_AMR_FW /*!< 8 GSM FR V5 (FR AMR-WB) */, + }; + int i; + for (i = 0; i < ARRAY_SIZE(utran_codecs); i++) + sdp_audio_codecs_add_speech_ver(&msc_ran_infra[OSMO_RAT_UTRAN_IU].codecs, utran_codecs[i]); +} diff --git a/src/libmsc/transaction_cc.c b/src/libmsc/transaction_cc.c index 2a540bfa5..e88598278 100644 --- a/src/libmsc/transaction_cc.c +++ b/src/libmsc/transaction_cc.c @@ -25,6 +25,7 @@ #include #include #include +#include void trans_cc_filter_init(struct gsm_trans *trans) { @@ -34,7 +35,7 @@ void trans_cc_filter_init(struct gsm_trans *trans) void trans_cc_filter_set_ran(struct gsm_trans *trans, enum osmo_rat_type ran_type) { - codec_filter_set_ran(&trans->cc.codecs, ran_type); + codec_filter_set_ran(&trans->cc.codecs, &msc_ran_infra[ran_type].codecs); csd_filter_set_ran(&trans->cc.csd, ran_type); }