codec_pref: also check physical channels
At the moment codec_pref only checks the codec configuration, but it
does not check if there is actually a matching physical channel
available. This should be checked too we must make sure that the codec
we select fits the physical channels available on the BTS.
Change-Id: I2d29dfed450e5ef93c26ed5ec9fdc0730eb3d7dd
Related: OS#3503
diff --git a/src/osmo-bsc/codec_pref.c b/src/osmo-bsc/codec_pref.c
index a741e11..9f30c7b 100644
--- a/src/osmo-bsc/codec_pref.c
+++ b/src/osmo-bsc/codec_pref.c
@@ -176,8 +176,38 @@
/* Helper function to check if the given permitted speech value is supported
* by the BTS. (vty option bts->codec-support). */
-static bool test_codec_support_bts(const struct bts_codec_conf *bts_codec, uint8_t perm_spch)
+static bool test_codec_support_bts(const struct gsm_bts *bts, uint8_t perm_spch)
{
+ struct gsm_bts_trx *trx;
+ const struct bts_codec_conf *bts_codec = &bts->codec;
+ unsigned int i;
+ bool full_rate;
+ int rc;
+ enum gsm_phys_chan_config pchan;
+ bool rate_match = false;
+
+ /* Check if the BTS provides a physical channel that matches the
+ * bandwith of the desired codec. */
+ rc = full_rate_from_perm_spch(&full_rate, perm_spch);
+ if (rc < 0)
+ return false;
+ llist_for_each_entry(trx, &bts->trx_list, list) {
+ for (i = 0; i < TRX_NR_TS; i++) {
+ pchan = trx->ts[i].pchan_from_config;
+ if (pchan == GSM_PCHAN_TCH_F_TCH_H_PDCH)
+ rate_match = true;
+ else if (full_rate && pchan == GSM_PCHAN_TCH_F)
+ rate_match = true;
+ else if (full_rate && pchan == GSM_PCHAN_TCH_F_PDCH)
+ rate_match = true;
+ else if (!full_rate && pchan == GSM_PCHAN_TCH_H)
+ rate_match = true;
+ }
+ }
+ if (!rate_match)
+ return false;
+
+ /* Check codec support */
switch (perm_spch) {
case GSM0808_PERM_FR1:
/* GSM-FR is always supported by all BTSs. There is also no way to
@@ -269,7 +299,7 @@
/* Check this permitted speech value against the BTS specific parameters.
* if the BTS does not support the codec, try the next one */
- if (!test_codec_support_bts(&bts->codec, perm_spch))
+ if (!test_codec_support_bts(bts, perm_spch))
continue;
/* Match the permitted speech value against the codec lists that were
@@ -345,7 +375,7 @@
/* Check this permitted speech value against the BTS specific parameters.
* if the BTS does not support the codec, try the next one */
- if (!test_codec_support_bts(&bts->codec, perm_spch))
+ if (!test_codec_support_bts(bts, perm_spch))
continue;
/* Write item into codec list */
@@ -380,7 +410,7 @@
gen_bss_supported_codec_list(&scl, msc, bts);
if (scl.len <= 0) {
LOGP(DMSC, LOGL_FATAL,
- "codec-support of BTS %u does not intersect with codec-list of MSC %u\n",
+ "codec-support/trx config of BTS %u does not intersect with codec-list of MSC %u\n",
bts->nr, msc->nr);
rc = -1;
}
diff --git a/tests/codec_pref/codec_pref_test.c b/tests/codec_pref/codec_pref_test.c
index e2876e2..534b99e 100644
--- a/tests/codec_pref/codec_pref_test.c
+++ b/tests/codec_pref/codec_pref_test.c
@@ -294,6 +294,7 @@
/* Note: FR is supported by all BTSs, so there is no flag for it */
struct gsm48_multi_rate_conf *cfg;
+ static struct gsm_bts_trx trx;
OSMO_ASSERT(config_no < N_CONFIG_VARIANTS);
@@ -324,6 +325,13 @@
cfg->m10_2 = 0;
cfg->m12_2 = 0;
+ /* Initalize TRX with a TCH/F and a TCH/H channel */
+ memset(&trx, 0, sizeof(trx));
+ INIT_LLIST_HEAD(&bts->trx_list);
+ llist_add(&trx.list, &bts->trx_list);
+ trx.ts[0].pchan_from_config = GSM_PCHAN_TCH_F;
+ trx.ts[1].pchan_from_config = GSM_PCHAN_TCH_H;
+
switch (config_no) {
case 0:
/* FR1 (implicit) only */