Change in osmo-bsc[master]: dissolve gsm0808_cipher_mode() into bssmap_handle_cipher_mode()

2021-06-20 Thread neels
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 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria 
Gerrit-Reviewer: laforge 
Gerrit-Reviewer: neels 
Gerrit-Reviewer: pespin 
Gerrit-MessageType: merged


Change in osmo-bsc[master]: dissolve gsm0808_cipher_mode() into bssmap_handle_cipher_mode()

2021-06-19 Thread fixeria
fixeria has posted comments on this change. ( 
https://gerrit.osmocom.org/c/osmo-bsc/+/24677 )

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


Patch Set 2: Code-Review+2


--
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 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria 
Gerrit-Reviewer: laforge 
Gerrit-Reviewer: pespin 
Gerrit-Comment-Date: Sat, 19 Jun 2021 09:49:03 +
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment


Change in osmo-bsc[master]: dissolve gsm0808_cipher_mode() into bssmap_handle_cipher_mode()

2021-06-15 Thread laforge
laforge has posted comments on this change. ( 
https://gerrit.osmocom.org/c/osmo-bsc/+/24677 )

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


Patch Set 1: Code-Review+1


--
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: 1
Gerrit-Owner: neels 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge 
Gerrit-Reviewer: pespin 
Gerrit-Comment-Date: Tue, 15 Jun 2021 16:33:22 +
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment


Change in osmo-bsc[master]: dissolve gsm0808_cipher_mode() into bssmap_handle_cipher_mode()

2021-06-15 Thread pespin
pespin has posted comments on this change. ( 
https://gerrit.osmocom.org/c/osmo-bsc/+/24677 )

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


Patch Set 1: Code-Review+1


--
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: 1
Gerrit-Owner: neels 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: pespin 
Gerrit-Comment-Date: Tue, 15 Jun 2021 14:31:32 +
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment


Change in osmo-bsc[master]: dissolve gsm0808_cipher_mode() into bssmap_handle_cipher_mode()

2021-06-15 Thread neels
neels has uploaded this change for review. ( 
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(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-bsc refs/changes/77/24677/1

diff --git a/src/osmo-bsc/osmo_bsc_bssap.c b/src/osmo-bsc/osmo_bsc_bssap.c
index da0429b..0b1c649 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: 1
Gerrit-Owner: neels 
Gerrit-MessageType: newchange