Change in osmo-bsc[master]: use osmo_mobile_identity API everywhere

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 gerrit-no-reply at lists.osmocom.org
Sun Jun 7 20:52:59 UTC 2020


neels has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-bsc/+/18713 )


Change subject: use osmo_mobile_identity API everywhere
......................................................................

use osmo_mobile_identity API everywhere

Depends: Ic3f969e739654c1e8c387aedeeba5cce07fe2307 (libosmocore)
Change-Id: I71c3b4c65dbfdfa51409e09d4868aea83225338a
---
M include/osmocom/bsc/abis_rsl.h
M include/osmocom/bsc/gsm_04_08_rr.h
M src/osmo-bsc/abis_rsl.c
M src/osmo-bsc/bsc_subscriber.c
M src/osmo-bsc/gsm_04_08_rr.c
M src/osmo-bsc/osmo_bsc_bssap.c
M src/osmo-bsc/paging.c
M src/osmo-bsc/pcu_sock.c
8 files changed, 73 insertions(+), 59 deletions(-)



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

diff --git a/include/osmocom/bsc/abis_rsl.h b/include/osmocom/bsc/abis_rsl.h
index b43e3ae..2611a3d 100644
--- a/include/osmocom/bsc/abis_rsl.h
+++ b/include/osmocom/bsc/abis_rsl.h
@@ -43,8 +43,9 @@
 int rsl_tx_chan_activ(struct gsm_lchan *lchan, uint8_t act_type, uint8_t ho_ref);
 int rsl_chan_mode_modify_req(struct gsm_lchan *ts);
 int rsl_encryption_cmd(struct msgb *msg);
-int rsl_paging_cmd(struct gsm_bts *bts, uint8_t paging_group, uint8_t len,
-		   uint8_t *ms_ident, uint8_t chan_needed, bool is_gprs);
+int rsl_paging_cmd(struct gsm_bts *bts, uint8_t paging_group,
+		   const struct osmo_mobile_identity *mi,
+		   uint8_t chan_needed, bool is_gprs);
 int rsl_imm_assign_cmd(struct gsm_bts *bts, uint8_t len, uint8_t *val);
 int rsl_tx_imm_assignment(struct gsm_lchan *lchan);
 int rsl_tx_imm_ass_rej(struct gsm_bts *bts, struct gsm48_req_ref *rqd_ref);
diff --git a/include/osmocom/bsc/gsm_04_08_rr.h b/include/osmocom/bsc/gsm_04_08_rr.h
index d34e695..8821251 100644
--- a/include/osmocom/bsc/gsm_04_08_rr.h
+++ b/include/osmocom/bsc/gsm_04_08_rr.h
@@ -39,7 +39,6 @@
 			 enum gsm48_reject_value value);
 
 struct msgb *gsm48_create_mm_serv_rej(enum gsm48_reject_value value);
-int gsm48_extract_mi(uint8_t *classmark2_lv, int length, char *mi_string, uint8_t *mi_type);
 struct msgb *gsm48_create_loc_upd_rej(uint8_t cause);
 
 struct msgb *gsm48_create_rr_status(uint8_t cause);
diff --git a/src/osmo-bsc/abis_rsl.c b/src/osmo-bsc/abis_rsl.c
index 4a1d314..43c52ad 100644
--- a/src/osmo-bsc/abis_rsl.c
+++ b/src/osmo-bsc/abis_rsl.c
@@ -664,18 +664,29 @@
 	return abis_rsl_sendmsg(msg);
 }
 
-int rsl_paging_cmd(struct gsm_bts *bts, uint8_t paging_group, uint8_t len,
-		   uint8_t *ms_ident, uint8_t chan_needed, bool is_gprs)
+int rsl_paging_cmd(struct gsm_bts *bts, uint8_t paging_group,
+		   const struct osmo_mobile_identity *mi,
+		   uint8_t chan_needed, bool is_gprs)
 {
 	struct abis_rsl_dchan_hdr *dh;
 	struct msgb *msg = rsl_msgb_alloc();
+	uint8_t *l;
+	int rc;
 
 	dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
 	init_dchan_hdr(dh, RSL_MT_PAGING_CMD);
 	dh->chan_nr = RSL_CHAN_PCH_AGCH;
 
 	msgb_tv_put(msg, RSL_IE_PAGING_GROUP, paging_group);
-	msgb_tlv_put(msg, RSL_IE_MS_IDENTITY, len-2, ms_ident+2);
+
+	l = msgb_tl_put(msg, RSL_IE_MS_IDENTITY);
+	rc = osmo_mobile_identity_encode_msgb(msg, mi, false);
+	if (rc < 0) {
+		msgb_free(msg);
+		return -EINVAL;
+	}
+	*l = rc;
+
 	msgb_tv_put(msg, RSL_IE_CHAN_NEEDED, chan_needed);
 
 	/* Ericsson wants to have this IE in case a paging message
diff --git a/src/osmo-bsc/bsc_subscriber.c b/src/osmo-bsc/bsc_subscriber.c
index ecd6f3d..9ddfcaa 100644
--- a/src/osmo-bsc/bsc_subscriber.c
+++ b/src/osmo-bsc/bsc_subscriber.c
@@ -81,7 +81,7 @@
 		return NULL;
 	switch (mi->type) {
 	case GSM_MI_TYPE_IMSI:
-		return bsc_subscr_find_by_imsi(list, mi->string);
+		return bsc_subscr_find_by_imsi(list, mi->imsi);
 	case GSM_MI_TYPE_TMSI:
 		return bsc_subscr_find_by_tmsi(list, mi->tmsi);
 	default:
@@ -130,7 +130,7 @@
 		return NULL;
 	switch (mi->type) {
 	case GSM_MI_TYPE_IMSI:
-		return bsc_subscr_find_or_create_by_imsi(list, mi->string);
+		return bsc_subscr_find_or_create_by_imsi(list, mi->imsi);
 	case GSM_MI_TYPE_TMSI:
 		return bsc_subscr_find_or_create_by_tmsi(list, mi->tmsi);
 	default:
diff --git a/src/osmo-bsc/gsm_04_08_rr.c b/src/osmo-bsc/gsm_04_08_rr.c
index 4630b47..8a74aab 100644
--- a/src/osmo-bsc/gsm_04_08_rr.c
+++ b/src/osmo-bsc/gsm_04_08_rr.c
@@ -828,20 +828,6 @@
 	return msg;
 }
 
-int gsm48_extract_mi(uint8_t *classmark2_lv, int length, char *mi_string, uint8_t *mi_type)
-{
-	/* Check the size for the classmark */
-	if (length < 1 + *classmark2_lv)
-		return -1;
-
-	uint8_t *mi_lv = classmark2_lv + *classmark2_lv + 1;
-	if (length < 2 + *classmark2_lv + mi_lv[0])
-		return -2;
-
-	*mi_type = mi_lv[1] & GSM_MI_TYPE_MASK;
-	return gsm48_mi_to_string(mi_string, GSM48_MI_SIZE, mi_lv+1, *mi_lv);
-}
-
 /* As per TS 03.03 Section 2.2, the IMSI has 'not more than 15 digits' */
 uint64_t str_to_imsi(const char *imsi_str)
 {
diff --git a/src/osmo-bsc/osmo_bsc_bssap.c b/src/osmo-bsc/osmo_bsc_bssap.c
index 864d96d..49a5765 100644
--- a/src/osmo-bsc/osmo_bsc_bssap.c
+++ b/src/osmo-bsc/osmo_bsc_bssap.c
@@ -293,13 +293,13 @@
 				struct msgb *msg, unsigned int payload_length)
 {
 	struct tlv_parsed tp;
-	char mi_string[GSM48_MI_SIZE];
-	uint32_t tmsi = GSM_RESERVED_TMSI;
 	uint8_t data_length;
 	int remain;
 	const uint8_t *data;
 	uint8_t chan_needed = RSL_CHANNEED_ANY;
 	struct gsm0808_cell_id_list2 cil;
+	struct osmo_mobile_identity mi_imsi;
+	struct osmo_mobile_identity mi_tmsi = { .tmsi = GSM_RESERVED_TMSI };
 
 	tlv_parse(&tp, gsm0808_att_tlvdef(), msg->l4h + 1, payload_length - 1, 0, 0);
 	remain = payload_length - 1;
@@ -318,9 +318,12 @@
 		return -1;
 	}
 
-	if (TLVP_PRESENT(&tp, GSM0808_IE_TMSI) &&
-	    TLVP_LEN(&tp, GSM0808_IE_TMSI) == 4) {
-		tmsi = ntohl(tlvp_val32_unal(&tp, GSM0808_IE_TMSI));
+	if (TLVP_PRESENT(&tp, GSM0808_IE_TMSI)) {
+		if (osmo_mobile_identity_decode(&mi_tmsi, TLVP_VAL(&tp, GSM0808_IE_TMSI), TLVP_LEN(&tp, GSM0808_IE_TMSI), false)
+		    || mi_tmsi.type != GSM_MI_TYPE_TMSI) {
+			LOGP(DMSC, LOGL_ERROR, "Paging: could not parse TMSI\n");
+			return -1;
+		}
 		remain -= TLVP_LEN(&tp, GSM0808_IE_TMSI);
 	}
 
@@ -332,8 +335,11 @@
 	/*
 	 * parse the IMSI
 	 */
-	gsm48_mi_to_string(mi_string, sizeof(mi_string),
-			   TLVP_VAL(&tp, GSM0808_IE_IMSI), TLVP_LEN(&tp, GSM0808_IE_IMSI));
+	if (osmo_mobile_identity_decode(&mi_imsi, TLVP_VAL(&tp, GSM0808_IE_IMSI), TLVP_LEN(&tp, GSM0808_IE_IMSI), false)
+	    || mi_imsi.type != GSM_MI_TYPE_IMSI) {
+		LOGP(DMSC, LOGL_ERROR, "Paging: could not parse IMSI\n");
+		return -1;
+	}
 
 	/*
 	 * There are various cell identifier list types defined at 3GPP TS § 08.08, we don't support all
@@ -343,8 +349,8 @@
 	data_length = TLVP_LEN(&tp, GSM0808_IE_CELL_IDENTIFIER_LIST);
 	data = TLVP_VAL(&tp, GSM0808_IE_CELL_IDENTIFIER_LIST);
 	if (gsm0808_dec_cell_id_list2(&cil, data, data_length) < 0) {
-		LOGP(DMSC, LOGL_ERROR, "Paging IMSI %s: Could not parse Cell Identifier List\n",
-		     mi_string);
+		LOGP(DMSC, LOGL_ERROR, "Paging %s: Could not parse Cell Identifier List\n",
+		     osmo_mobile_identity_name_c(OTC_SELECT, &mi_imsi));
 		return -1;
 	}
 	remain = 0;
@@ -360,43 +366,45 @@
 
 	switch (cil.id_discr) {
 	case CELL_IDENT_NO_CELL:
-		page_all_bts(msc, tmsi, mi_string, chan_needed);
+		page_all_bts(msc, mi_tmsi.tmsi, mi_imsi.imsi, chan_needed);
 		break;
 
 	case CELL_IDENT_WHOLE_GLOBAL:
-		page_cgi(msc, &cil, tmsi, mi_string, chan_needed);
+		page_cgi(msc, &cil, mi_tmsi.tmsi, mi_imsi.imsi, chan_needed);
 		break;
 
 	case CELL_IDENT_LAC_AND_CI:
-		page_lac_and_ci(msc, &cil, tmsi, mi_string, chan_needed);
+		page_lac_and_ci(msc, &cil, mi_tmsi.tmsi, mi_imsi.imsi, chan_needed);
 		break;
 
 	case CELL_IDENT_CI:
-		page_ci(msc, &cil, tmsi, mi_string, chan_needed);
+		page_ci(msc, &cil, mi_tmsi.tmsi, mi_imsi.imsi, chan_needed);
 		break;
 
 	case CELL_IDENT_LAI_AND_LAC:
-		page_lai_and_lac(msc, &cil, tmsi, mi_string, chan_needed);
+		page_lai_and_lac(msc, &cil, mi_tmsi.tmsi, mi_imsi.imsi, chan_needed);
 		break;
 
 	case CELL_IDENT_LAC:
-		page_lac(msc, &cil, tmsi, mi_string, chan_needed);
+		page_lac(msc, &cil, mi_tmsi.tmsi, mi_imsi.imsi, chan_needed);
 		break;
 
 	case CELL_IDENT_BSS:
 		if (data_length != 1) {
-			LOGP(DMSC, LOGL_ERROR, "Paging IMSI %s: Cell Identifier List for BSS (0x%x)"
+			LOGP(DMSC, LOGL_ERROR, "Paging %s: Cell Identifier List for BSS (0x%x)"
 			     " has invalid length: %u, paging entire BSS anyway (%s)\n",
-			     mi_string, CELL_IDENT_BSS, data_length, osmo_hexdump(data, data_length));
+			     osmo_mobile_identity_name_c(OTC_SELECT, &mi_imsi),
+			     CELL_IDENT_BSS, data_length, osmo_hexdump(data, data_length));
 		}
-		page_all_bts(msc, tmsi, mi_string, chan_needed);
+		page_all_bts(msc, mi_tmsi.tmsi, mi_imsi.imsi, chan_needed);
 		break;
 
 	default:
-		LOGP(DMSC, LOGL_NOTICE, "Paging IMSI %s: unimplemented Cell Identifier List (0x%x),"
+		LOGP(DMSC, LOGL_NOTICE, "Paging %s: unimplemented Cell Identifier List (0x%x),"
 		     " paging entire BSS instead (%s)\n",
-		     mi_string, cil.id_discr, osmo_hexdump(data, data_length));
-		page_all_bts(msc, tmsi, mi_string, chan_needed);
+		     osmo_mobile_identity_name_c(OTC_SELECT, &mi_imsi),
+		     cil.id_discr, osmo_hexdump(data, data_length));
+		page_all_bts(msc, mi_tmsi.tmsi, mi_imsi.imsi, chan_needed);
 		break;
 	}
 
diff --git a/src/osmo-bsc/paging.c b/src/osmo-bsc/paging.c
index 7b89dad..7859c69 100644
--- a/src/osmo-bsc/paging.c
+++ b/src/osmo-bsc/paging.c
@@ -78,10 +78,9 @@
 
 static void page_ms(struct gsm_paging_request *request)
 {
-	uint8_t mi[128];
-	unsigned int mi_len;
 	unsigned int page_group;
 	struct gsm_bts *bts = request->bts;
+	struct osmo_mobile_identity mi;
 
 	log_set_context(LOG_CTX_BSC_SUBSCR, request->bsub);
 
@@ -89,14 +88,21 @@
 		"0x%08x for ch. type %d (attempt %d)\n", request->bsub->imsi,
 		request->bsub->tmsi, request->chan_type, request->attempts);
 
-	if (request->bsub->tmsi == GSM_RESERVED_TMSI)
-		mi_len = gsm48_generate_mid_from_imsi(mi, request->bsub->imsi);
-	else
-		mi_len = gsm48_generate_mid_from_tmsi(mi, request->bsub->tmsi);
+	if (request->bsub->tmsi == GSM_RESERVED_TMSI) {
+		mi = (struct osmo_mobile_identity){
+			.type = GSM_MI_TYPE_IMSI,
+		};
+		OSMO_STRLCPY_ARRAY(mi.imsi, request->bsub->imsi);
+	} else {
+		mi = (struct osmo_mobile_identity){
+			.type = GSM_MI_TYPE_TMSI,
+			.tmsi = request->bsub->tmsi,
+		};
+	}
 
 	page_group = gsm0502_calc_paging_group(&bts->si_common.chan_desc,
 					       str_to_imsi(request->bsub->imsi));
-	rsl_paging_cmd(bts, page_group, mi_len, mi, request->chan_type, false);
+	rsl_paging_cmd(bts, page_group, &mi, request->chan_type, false);
 	log_set_context(LOG_CTX_BSC_SUBSCR, NULL);
 }
 
diff --git a/src/osmo-bsc/pcu_sock.c b/src/osmo-bsc/pcu_sock.c
index b041402..a2f9f4e 100644
--- a/src/osmo-bsc/pcu_sock.c
+++ b/src/osmo-bsc/pcu_sock.c
@@ -290,27 +290,30 @@
 {
 	struct gsm48_paging1 *p1 = (struct gsm48_paging1 *) raw_rr_msg;
 	uint8_t chan_needed;
-	unsigned int mi_len;
-	uint8_t *mi;
+	struct osmo_mobile_identity mi;
 	int rc;
 
 	switch (p1->msg_type) {
 	case GSM48_MT_RR_PAG_REQ_1:
 		chan_needed = (p1->cneed2 << 2) | p1->cneed1;
-		mi_len = p1->data[0];
-		mi = p1->data+1;
+		rc = osmo_mobile_identity_decode(&mi, p1->data+1, p1->data[0], false);
+		if (rc) {
+			LOGP(DPCU, LOGL_ERROR, "PCU Sends paging "
+			     "request type %02x (chan_needed=%02x): Unable to decode Mobile Identity\n",
+			     p1->msg_type, chan_needed);
+			rc = -EINVAL;
+			break;
+		}
 		LOGP(DPCU, LOGL_ERROR, "PCU Sends paging "
-		     "request type %02x (chan_needed=%02x, mi_len=%u, mi=%s)\n",
-		     p1->msg_type, chan_needed, mi_len,
-		     osmo_hexdump_nospc(mi,mi_len));
+		     "request type %02x (chan_needed=%02x, mi=%s)\n",
+		     p1->msg_type, chan_needed, osmo_mobile_identity_name_c(OTC_SELECT, &mi));
 		/* NOTE: We will have to add 2 to mi_len and subtract 2 from
 		 * the mi pointer because rsl_paging_cmd() will perform the
 		 * reverse operations. This is because rsl_paging_cmd() is
 		 * normally expected to chop off the element identifier (0xC0)
 		 * and the length field. In our parameter, we do not have
 		 * those fields included. */
-		rc = rsl_paging_cmd(bts, paging_group, mi_len+2, mi-2,
-				    chan_needed, true);
+		rc = rsl_paging_cmd(bts, paging_group, &mi, chan_needed, true);
 		break;
 	case GSM48_MT_RR_PAG_REQ_2:
 	case GSM48_MT_RR_PAG_REQ_3:

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

Gerrit-Project: osmo-bsc
Gerrit-Branch: master
Gerrit-Change-Id: I71c3b4c65dbfdfa51409e09d4868aea83225338a
Gerrit-Change-Number: 18713
Gerrit-PatchSet: 1
Gerrit-Owner: neels <nhofmeyr at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200607/29773b88/attachment.htm>


More information about the gerrit-log mailing list