aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorVadim Yanitskiy <vyanitskiy@sysmocom.de>2022-03-14 01:01:53 +0300
committerfixeria <vyanitskiy@sysmocom.de>2022-03-29 11:50:12 +0000
commit7fb4817b78b538ebbda305754dbd13c5948dd1bd (patch)
treefd81ef6092dc5f2a763045b6889007357cb7e3f9 /include
parenteba0a02017ab327d725f4fd374b3ea5dea1ce7bd (diff)
struct gsm_encr: store alg_id in human-readable format
I find it weird that we store the A5 algorithm ID in a format that is used on the wire: N + 1 (valid for both A-bis and A interfaces). What confused me even more is that in some functions we print it as if it was in a normal, human-readable format. And this is also why one can see weird constructions like: if (lchan->encr.alg_id > ALG_A5_NR_TO_RSL(0)) { ... } Let's ensure that our internal structures use the A5/N format: alg_id=0: A5/0 (0x01 on the A-bis/A interface) alg_id=1: A5/1 (0x02 on the A-bis/A interface) alg_id=2: A5/2 (0x03 on the A-bis/A interface) ... alg_id=7: A5/7 (0x08 on the A-bis/A interface) so that we can print and compare the value of alg_id without using additional arithmetics. Let's also rename 'alg_id' to 'alg_a5_n' as it most clearly indicates which representation it is storing. This is how the above code snippet would look like: if (lchan->encr.alg_a5_n > 0) { ... } Change-Id: Ieb50c9a352cfa5481aebac2379e0a461663543ec
Diffstat (limited to 'include')
-rw-r--r--include/osmocom/bsc/gsm_08_08.h2
-rw-r--r--include/osmocom/bsc/gsm_data.h3
2 files changed, 3 insertions, 2 deletions
diff --git a/include/osmocom/bsc/gsm_08_08.h b/include/osmocom/bsc/gsm_08_08.h
index da5e2f1ac..07f08214d 100644
--- a/include/osmocom/bsc/gsm_08_08.h
+++ b/include/osmocom/bsc/gsm_08_08.h
@@ -7,7 +7,7 @@
struct gsm_subscriber_connection;
void bsc_sapi_n_reject(struct gsm_subscriber_connection *conn, uint8_t dlci, enum gsm0808_cause cause);
-void bsc_cipher_mode_compl(struct gsm_subscriber_connection *conn, struct msgb *msg, uint8_t chosen_encr);
+void bsc_cipher_mode_compl(struct gsm_subscriber_connection *conn, struct msgb *msg, uint8_t chosen_a5_n);
int bsc_compl_l3(struct gsm_lchan *lchan, struct msgb *msg, uint16_t chosen_channel);
void bsc_dtap(struct gsm_subscriber_connection *conn, uint8_t link_id, struct msgb *msg);
void bsc_cm_update(struct gsm_subscriber_connection *conn,
diff --git a/include/osmocom/bsc/gsm_data.h b/include/osmocom/bsc/gsm_data.h
index 4fe97a28b..fcd888367 100644
--- a/include/osmocom/bsc/gsm_data.h
+++ b/include/osmocom/bsc/gsm_data.h
@@ -546,6 +546,7 @@ struct om2k_mo {
* 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_BSSAP(A5_N) ALG_A5_NR_TO_RSL(A5_N)
#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.
@@ -608,7 +609,7 @@ enum lchan_sapi_state {
#define MAX_A5_KEY_LEN (128/8)
struct gsm_encr {
- uint8_t alg_id;
+ uint8_t alg_a5_n; /* N: 0 (A5/0), 1 (A5/1), ... 7 (A5/7) */
uint8_t key_len;
uint8_t key[MAX_A5_KEY_LEN];
bool kc128_present;