[PATCH 2/5] sgsn: Extract the MSISDN from the subscr data structure

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/OpenBSC@lists.osmocom.org/.

Holger Freyther holger at freyther.de
Wed May 6 15:48:28 UTC 2015


From: Holger Hans Peter Freyther <holger at moiji-mobile.com>

In case there is a subscr attached to the MM context and there
is an encoded MSISDN we will attempt to decode it and in case
of an international number prepend a '+'. Assume that the array
size of gsm_mmcc_called->number is as big as ctx->msisdn for the
strncpy.
---
 openbsc/src/gprs/gprs_gmm.c    | 34 ++++++++++++++++++++++++++++++++++
 openbsc/tests/sgsn/sgsn_test.c |  4 ++++
 2 files changed, 38 insertions(+)

diff --git a/openbsc/src/gprs/gprs_gmm.c b/openbsc/src/gprs/gprs_gmm.c
index ace0c2e..2a856a6 100644
--- a/openbsc/src/gprs/gprs_gmm.c
+++ b/openbsc/src/gprs/gprs_gmm.c
@@ -545,6 +545,38 @@ static int gsm48_rx_gmm_auth_ciph_resp(struct sgsn_mm_ctx *ctx,
 	return gsm48_gmm_authorize(ctx);
 }
 
+static void extract_subscr_msisdn(struct sgsn_mm_ctx *ctx)
+{
+	struct gsm_mncc_number called;
+	uint8_t msisdn[sizeof(ctx->subscr->sgsn_data->msisdn) + 1];
+
+	/* Convert MSISDN from encoded to string.. */
+	if (!ctx->subscr)
+		return;
+
+	if (ctx->subscr->sgsn_data->msisdn_len < 1)
+		return;
+
+	/* prepare the data for the decoder */
+	memset(&called, 0, sizeof(called));
+	msisdn[0] = ctx->subscr->sgsn_data->msisdn_len;
+	memcpy(&msisdn[1], ctx->subscr->sgsn_data->msisdn,
+		ctx->subscr->sgsn_data->msisdn_len);
+
+	/* decode the string now */
+	gsm48_decode_called(&called, msisdn);
+
+	/* Prepend a '+' for international numbers */
+	if (called.plan == 1 && called.type == 1) {
+		ctx->msisdn[0] = '+';
+		strncpy(&ctx->msisdn[1], called.number,
+			sizeof(ctx->msisdn) - 1);
+	} else {
+		strncpy(&ctx->msisdn[0], called.number,
+			sizeof(ctx->msisdn) - 1);
+	}
+}
+
 /* Check if we can already authorize a subscriber */
 static int gsm48_gmm_authorize(struct sgsn_mm_ctx *ctx)
 {
@@ -604,6 +636,8 @@ static int gsm48_gmm_authorize(struct sgsn_mm_ctx *ctx)
 			  "no pending request, authorization completed\n");
 		break;
 	case GSM48_MT_GMM_ATTACH_REQ:
+
+		extract_subscr_msisdn(ctx);
 #ifdef PTMSI_ALLOC
 		/* Start T3350 and re-transmit up to 5 times until ATTACH COMPLETE */
 		mmctx_timer_start(ctx, 3350, GSM0408_T3350_SECS);
diff --git a/openbsc/tests/sgsn/sgsn_test.c b/openbsc/tests/sgsn/sgsn_test.c
index d9b162d..879dfe3 100644
--- a/openbsc/tests/sgsn/sgsn_test.c
+++ b/openbsc/tests/sgsn/sgsn_test.c
@@ -953,6 +953,8 @@ retry_attach_req:
 		/* check that the MM context has not been removed due to a
 		 * failed authorization */
 		OSMO_ASSERT(ctx == sgsn_mm_ctx_by_tlli(foreign_tlli, &raid));
+		if (ctx->subscr && ctx->subscr->sgsn_data->msisdn_len > 0)
+			OSMO_ASSERT(strcmp(ctx->msisdn, "+49166213323") == 0);
 	}
 
 	if (retry && sgsn_tx_counter == 0)
@@ -1151,6 +1153,8 @@ int my_subscr_request_update_gsup_auth(struct sgsn_mm_ctx *mmctx) {
 			0x10, 0x01, 0x01,
 			0x11, 0x02, 0xf1, 0x21, /* IPv4 */
 			0x12, 0x09, 0x04, 't', 'e', 's', 't', 0x03, 'a', 'p', 'n',
+		0x08, 0x07, /* MSISDN 49166213323 encoded */
+			0x91, 0x94, 0x61, 0x26, 0x31, 0x23, 0xF3,
 	};
 
 	OSMO_ASSERT(!mmctx || mmctx->subscr);
-- 
2.3.5




More information about the OpenBSC mailing list