aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@osmocom.org>2021-01-25 17:59:06 +0100
committerlaforge <laforge@osmocom.org>2021-01-29 21:24:36 +0000
commit5e01039d79674171d20c5ea40266635a576eee56 (patch)
tree7309fb5d50ad727f93060c181a4a0bdc89a042eb
parent6d32c92e4fbc67e09f77157baef72ea3044ab534 (diff)
select_best_cipher(): Prefer A5/1 over A5/2
We cannot simply use the highest 'x' in A5/x codecs. For A5/7 through A5/3, larger 'x' means better. But: A5/1 is better than A5/2, so we need to prefer the former over the latter. Change-Id: I399fff8d07d1bfcbc6b385e90914ff6d9e00eb73 Closes: OS#4975
-rw-r--r--src/osmo-bsc/osmo_bsc_bssap.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/osmo-bsc/osmo_bsc_bssap.c b/src/osmo-bsc/osmo_bsc_bssap.c
index 63dee9e3d..9d7815314 100644
--- a/src/osmo-bsc/osmo_bsc_bssap.c
+++ b/src/osmo-bsc/osmo_bsc_bssap.c
@@ -402,12 +402,16 @@ int bsc_paging_start(struct bsc_paging_params *params)
/* select the best cipher permitted by the intersection of both masks */
static int select_best_cipher(uint8_t msc_mask, uint8_t bsc_mask)
{
+ /* A5/7 ... A5/3: We assume higher is better,
+ * but: A5/1 is better than A5/2, which is better than A5/0 */
+ const uint8_t codec_strength[8] = { 7, 6, 5, 4, 3, 1, 2, 0 };
uint8_t intersection = msc_mask & bsc_mask;
int i;
- for (i = 7; i >= 0; i--) {
- if (intersection & (1 << i))
- return i;
+ for (i = 0; i < ARRAY_SIZE(codec_strength); i++) {
+ uint8_t codec = codec_strength[i];
+ if (intersection & (1 << codec))
+ return codec;
}
return -1;
}