aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorNeels Hofmeyr <nhofmeyr@sysmocom.de>2022-02-17 23:10:08 +0100
committerNeels Hofmeyr <nhofmeyr@sysmocom.de>2022-02-18 13:21:56 +0100
commita0fb37906d60910909b288e29b9501eaf7213711 (patch)
tree3ceee306ac261cb519c3b3dd38064f85e84ba146 /include
parent3900aae7a3f2bcae146e77c3e7f4d1ae3320ff12 (diff)
rename RSL_ENC_ALG_A5 to ALG_A5_NR_TO_RSL, clarify
The naming confused me so that I wrote buggy code again. Hopefully this clarifies which representations the code paths are using. In the macro code, highlight the error case of n <= -1 explicitly. Also add ALG_A5_NR_TO_PERM_ALG_BITS. I need the 1<<n case in an upcoming patch. Related: SYS#5839 Change-Id: I7557ae97764bba09c906748a18e9031dfb362611
Diffstat (limited to 'include')
-rw-r--r--include/osmocom/bsc/gsm_data.h19
1 files changed, 18 insertions, 1 deletions
diff --git a/include/osmocom/bsc/gsm_data.h b/include/osmocom/bsc/gsm_data.h
index 910c3d33a..07d141da5 100644
--- a/include/osmocom/bsc/gsm_data.h
+++ b/include/osmocom/bsc/gsm_data.h
@@ -528,7 +528,24 @@ struct om2k_mo {
#define A38_XOR_MIN_KEY_LEN 12
#define A38_XOR_MAX_KEY_LEN 16
#define A38_COMP128_KEY_LEN 16
-#define RSL_ENC_ALG_A5(x) (x+1)
+
+/* There are these representations of A5/n:
+ *
+ * - (uint8_t)(1<<n), either as a single bit, or combined as a list of
+ * permitted algorithms.
+ * A5/0 == 0x01, A5/3 == 0x08, none = 0
+ *
+ * - n+1, used on the RSL wire.
+ * A5/0 == 1, A5/3 == 4, none = 0
+ *
+ * - n, used for human interaction and returned by select_best_cipher().
+ * A5/0 == 0, A5/3 == 3, none <= -1
+ *
+ * These macros convert from n to the other representations:
+ */
+#define ALG_A5_NR_TO_RSL(A5_N) ((A5_N) >= 0 ? (A5_N)+1 : 0)
+#define ALG_A5_NR_TO_PERM_ALG_BITS(A5_N) ((A5_N) >= 0 ? 1<<(A5_N) : 0)
+
/* Up to 16 SI2quater are multiplexed; each fits 3 EARFCNS, so the practical maximum is 3*16.
* The real maximum that fits in a total of 16 SI2quater rest octets also depends on the bits left by other SI2quater
* rest octets elements, so to really fit 48 EARFCNs most other SI2quater elements need to be omitted. */