neels has submitted this change. ( 
https://gerrit.osmocom.org/c/osmo-bsc/+/24677 )

Change subject: dissolve gsm0808_cipher_mode() into bssmap_handle_cipher_mode()
......................................................................

dissolve gsm0808_cipher_mode() into bssmap_handle_cipher_mode()

An upcoming patch for A5/4 would need to add a kc128 arg and reject
cause rc to gsm0808_cipher_mode(). Instead prepare for less cruft by
just having a single function.

Related: SYS#5324
Change-Id: I7f7c635943990a251ae28ae7a0d69cc3a239a154
---
M src/osmo-bsc/osmo_bsc_bssap.c
1 file changed, 25 insertions(+), 32 deletions(-)

Approvals:
  Jenkins Builder: Verified
  fixeria: Looks good to me, approved
  pespin: Looks good to me, but someone else must approve
  laforge: Looks good to me, but someone else must approve



diff --git a/src/osmo-bsc/osmo_bsc_bssap.c b/src/osmo-bsc/osmo_bsc_bssap.c
index 563a957..9177e6b 100644
--- a/src/osmo-bsc/osmo_bsc_bssap.c
+++ b/src/osmo-bsc/osmo_bsc_bssap.c
@@ -416,34 +416,6 @@
        return -1;
 }

-/*! We received a GSM 08.08 CIPHER MODE from the MSC */
-static int gsm0808_cipher_mode(struct gsm_subscriber_connection *conn, int 
cipher,
-                              const uint8_t *key, int len, int include_imeisv)
-{
-       if (cipher > 0 && key == NULL) {
-               LOGP(DRSL, LOGL_ERROR, "%s: Need to have an encryption key.\n",
-                    bsc_subscr_name(conn->bsub));
-               return -1;
-       }
-
-       if (len > MAX_A5_KEY_LEN) {
-               LOGP(DRSL, LOGL_ERROR, "%s: The key is too long: %d\n",
-                    bsc_subscr_name(conn->bsub), len);
-               return -1;
-       }
-
-       LOGP(DRSL, LOGL_DEBUG, "(subscr %s) Cipher Mode: cipher=%d key=%s 
include_imeisv=%d\n",
-            bsc_subscr_name(conn->bsub), cipher, osmo_hexdump_nospc(key, len), 
include_imeisv);
-
-       conn->lchan->encr.alg_id = RSL_ENC_ALG_A5(cipher);
-       if (key) {
-               conn->lchan->encr.key_len = len;
-               memcpy(conn->lchan->encr.key, key, len);
-       }
-
-       return gsm48_send_rr_ciph_mode(conn->lchan, include_imeisv);
-}
-
 static int bssmap_handle_clear_cmd(struct gsm_subscriber_connection *conn,
                                   struct msgb *msg, unsigned int length)
 {
@@ -553,13 +525,34 @@
                goto reject;
        }

-       /* To complete the confusion, gsm0808_cipher_mode again expects the 
encryption as a number
-        * from 0 to 7. */
-       if (gsm0808_cipher_mode(conn, chosen_cipher, enc_key, enc_key_len,
-                               include_imeisv)) {
+       if (chosen_cipher > 0 && !enc_key_len) {
+               LOGP(DRSL, LOGL_ERROR, "%s: Need to have an encryption key.\n",
+                    bsc_subscr_name(conn->bsub));
                reject_cause = GSM0808_CAUSE_PROTOCOL_ERROR_BETWEEN_BSS_AND_MSC;
                goto reject;
        }
+
+       if (enc_key_len > MAX_A5_KEY_LEN) {
+               LOGP(DRSL, LOGL_ERROR, "%s: The key is too long: %d\n",
+                    bsc_subscr_name(conn->bsub), len);
+               reject_cause = GSM0808_CAUSE_PROTOCOL_ERROR_BETWEEN_BSS_AND_MSC;
+               goto reject;
+       }
+
+       conn->lchan->encr.alg_id = RSL_ENC_ALG_A5(chosen_cipher);
+       if (enc_key_len) {
+               conn->lchan->encr.key_len = enc_key_len;
+               memcpy(conn->lchan->encr.key, enc_key, enc_key_len);
+       }
+
+       LOGP(DRSL, LOGL_DEBUG, "(subscr %s) Cipher Mode: cipher=%d key=%s 
include_imeisv=%d\n",
+            bsc_subscr_name(conn->bsub), chosen_cipher, 
osmo_hexdump_nospc(enc_key, enc_key_len),
+            include_imeisv);
+
+       if (gsm48_send_rr_ciph_mode(conn->lchan, include_imeisv) < 0) {
+               reject_cause = GSM0808_CAUSE_RADIO_INTERFACE_FAILURE;
+               goto reject;
+       }
        return 0;

 reject:

--
To view, visit https://gerrit.osmocom.org/c/osmo-bsc/+/24677
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-bsc
Gerrit-Branch: master
Gerrit-Change-Id: I7f7c635943990a251ae28ae7a0d69cc3a239a154
Gerrit-Change-Number: 24677
Gerrit-PatchSet: 2
Gerrit-Owner: neels <nhofm...@sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanits...@sysmocom.de>
Gerrit-Reviewer: laforge <lafo...@osmocom.org>
Gerrit-Reviewer: neels <nhofm...@sysmocom.de>
Gerrit-Reviewer: pespin <pes...@sysmocom.de>
Gerrit-MessageType: merged

Reply via email to