[PATCH] osmo-msc[master]: cosmetic: move translation of vlr_ciph into msc_vlr_set_ciph...

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Mon Dec 18 02:27:27 UTC 2017


Hello Harald Welte, Jenkins Builder,

I'd like you to reexamine a change.  Please visit

    https://gerrit.osmocom.org/5377

to look at the new patch set (#3).

cosmetic: move translation of vlr_ciph into msc_vlr_set_ciph_mode()

a_iface_tx_cipher_mode() is a bit too far away from the VLR to be handling its
ciphering enums. Instead, construct the gsm0808_encrypt_info in the
msc_vlr_set_ciph_mode() callback.

Greatly simplify the sanity checking code: a_iface_tx_cipher_mode() no longer
needs to re-verify the presence of the gsm0808_encrypt_info contents.

Change-Id: Id46f9a513b555d0a481f7124c9984c2b5b196b3e
---
M include/osmocom/msc/a_iface.h
M src/libmsc/a_iface.c
M src/libmsc/gsm_04_08.c
3 files changed, 21 insertions(+), 28 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-msc refs/changes/77/5377/3

diff --git a/include/osmocom/msc/a_iface.h b/include/osmocom/msc/a_iface.h
index f0da248..30a10af 100644
--- a/include/osmocom/msc/a_iface.h
+++ b/include/osmocom/msc/a_iface.h
@@ -57,7 +57,7 @@
 
 /* Send Cipher mode command via A-interface */
 int a_iface_tx_cipher_mode(const struct gsm_subscriber_connection *conn,
-			   int cipher, const uint8_t *key, int len, int include_imeisv);
+			   struct gsm0808_encrypt_info *ei, int include_imeisv);
 
 /* Page a subscriber via A-interface */
 int a_iface_tx_paging(const char *imsi, uint32_t tmsi, uint16_t lac);
diff --git a/src/libmsc/a_iface.c b/src/libmsc/a_iface.c
index e264aee..9083f0e 100644
--- a/src/libmsc/a_iface.c
+++ b/src/libmsc/a_iface.c
@@ -165,38 +165,20 @@
 
 /* Send Cipher mode command via A-interface */
 int a_iface_tx_cipher_mode(const struct gsm_subscriber_connection *conn,
-			   int cipher, const uint8_t *key, int len, int include_imeisv)
+			   struct gsm0808_encrypt_info *ei, int include_imeisv)
 {
 	/* TODO generalize for A- and Iu interfaces, don't name after 08.08 */
 	struct msgb *msg_resp;
-	struct gsm0808_encrypt_info ei;
+	uint8_t crm = 0x01;
 
 	OSMO_ASSERT(conn);
 
-	LOGP(DMSC, LOGL_DEBUG, "(subscr %s, conn_id %d) Cipher Mode Command to BSC,"
-	     " cipher=%d key=%s\n",
-	     vlr_subscr_name(conn->vsub), conn->a.conn_id, cipher, osmo_hexdump_nospc(key, len));
-	uint8_t crm = 0x01;
-	uint8_t *crm_ptr = NULL;
+	LOGP(DMSC, LOGL_DEBUG, "(subscr %s, conn_id %d) Cipher Mode Command to BSC, %u ciphers (%s)",
+	     vlr_subscr_name(conn->vsub), conn->a.conn_id, ei->perm_algo_len,
+	     osmo_hexdump_nospc(ei->perm_algo, ei->perm_algo_len));
+	LOGPC(DMSC, LOGL_DEBUG, " key %s\n", osmo_hexdump_nospc(ei->key, ei->key_len));
 
-	/* Setup encryption information */
-	if (len > ENCRY_INFO_KEY_MAXLEN || !key) {
-		LOGP(DMSC, LOGL_ERROR,
-		     "Cipher mode command message could not be generated due to invalid key! (conn_id=%i)\n",
-		     conn->a.conn_id);
-		return -EINVAL;
-	} else {
-		memcpy(&ei.key, key, len);
-		ei.key_len = len;
-	}
-
-	if (include_imeisv)
-		crm_ptr = &crm;
-
-	ei.perm_algo[0] = vlr_ciph_to_gsm0808_alg_id(cipher);
-	ei.perm_algo_len = 1;
-
-	msg_resp = gsm0808_create_cipher(&ei, crm_ptr);
+	msg_resp = gsm0808_create_cipher(ei, include_imeisv ? &crm : NULL);
 	LOGP(DMSC, LOGL_DEBUG, "N-DATA.req(%u, %s)\n", conn->a.conn_id, osmo_hexdump(msg_resp->data, msg_resp->len));
 
 	return osmo_sccp_tx_data_msg(conn->a.scu, conn->a.conn_id, msg_resp);
diff --git a/src/libmsc/gsm_04_08.c b/src/libmsc/gsm_04_08.c
index d71b48b..f9dffac 100644
--- a/src/libmsc/gsm_04_08.c
+++ b/src/libmsc/gsm_04_08.c
@@ -3410,8 +3410,19 @@
 	case RAN_GERAN_A:
 		DEBUGP(DMM, "-> CIPHER MODE COMMAND %s\n",
 		       vlr_subscr_name(conn->vsub));
-		return a_iface_tx_cipher_mode(conn, ciph, tuple->vec.kc, 8,
-					      retrieve_imeisv);
+		{
+			struct gsm0808_encrypt_info ei;
+
+			ei.perm_algo[0] = vlr_ciph_to_gsm0808_alg_id(ciph);
+			ei.perm_algo_len = 1;
+
+			OSMO_ASSERT(sizeof(ei.key) >= sizeof(tuple->vec.kc));
+			memcpy(ei.key, tuple->vec.kc, sizeof(tuple->vec.kc));
+			ei.key_len = sizeof(tuple->vec.kc);
+
+			return a_iface_tx_cipher_mode(conn, &ei, retrieve_imeisv);
+		}
+
 	case RAN_UTRAN_IU:
 #ifdef BUILD_IU
 		DEBUGP(DMM, "-> SECURITY MODE CONTROL %s\n",

-- 
To view, visit https://gerrit.osmocom.org/5377
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: Id46f9a513b555d0a481f7124c9984c2b5b196b3e
Gerrit-PatchSet: 3
Gerrit-Project: osmo-msc
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder



More information about the gerrit-log mailing list