From a87646cd8449a0658d1f6af681aa3773a587ca6b Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Fri, 29 May 2020 03:53:59 +0200 Subject: use osmo_mobile_identity API everywhere Depends: If4f7be606e54cfa1c59084cf169785b1cbda5cf5 (libosmocore) Change-Id: I71c3b4c65dbfdfa51409e09d4868aea83225338a --- src/osmo-bsc/abis_rsl.c | 17 ++++++++++++++--- src/osmo-bsc/gsm_04_08_rr.c | 14 -------------- src/osmo-bsc/osmo_bsc_bssap.c | 39 ++++++++++++++++++++++----------------- src/osmo-bsc/paging.c | 20 +++++++++++++------- src/osmo-bsc/pcu_sock.c | 21 ++++++++++++--------- 5 files changed, 61 insertions(+), 50 deletions(-) (limited to 'src/osmo-bsc') diff --git a/src/osmo-bsc/abis_rsl.c b/src/osmo-bsc/abis_rsl.c index 705e75904..2fb1a22ef 100644 --- a/src/osmo-bsc/abis_rsl.c +++ b/src/osmo-bsc/abis_rsl.c @@ -664,18 +664,29 @@ int rsl_tx_rf_chan_release(struct gsm_lchan *lchan) 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/gsm_04_08_rr.c b/src/osmo-bsc/gsm_04_08_rr.c index 4630b47ce..8a74aabac 100644 --- a/src/osmo-bsc/gsm_04_08_rr.c +++ b/src/osmo-bsc/gsm_04_08_rr.c @@ -828,20 +828,6 @@ struct msgb *gsm48_create_loc_upd_rej(uint8_t cause) 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 864d96d18..6b225e44e 100644 --- a/src/osmo-bsc/osmo_bsc_bssap.c +++ b/src/osmo-bsc/osmo_bsc_bssap.c @@ -293,7 +293,7 @@ static int bssmap_handle_paging(struct bsc_msc_data *msc, struct msgb *msg, unsigned int payload_length) { struct tlv_parsed tp; - char mi_string[GSM48_MI_SIZE]; + struct osmo_mobile_identity mi_imsi; uint32_t tmsi = GSM_RESERVED_TMSI; uint8_t data_length; int remain; @@ -332,8 +332,11 @@ static int bssmap_handle_paging(struct bsc_msc_data *msc, /* * 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 +346,8 @@ static int bssmap_handle_paging(struct bsc_msc_data *msc, 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_to_str_c(OTC_SELECT, &mi_imsi)); return -1; } remain = 0; @@ -360,43 +363,45 @@ static int bssmap_handle_paging(struct bsc_msc_data *msc, switch (cil.id_discr) { case CELL_IDENT_NO_CELL: - page_all_bts(msc, tmsi, mi_string, chan_needed); + page_all_bts(msc, 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, 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, tmsi, mi_imsi.imsi, chan_needed); break; case CELL_IDENT_CI: - page_ci(msc, &cil, tmsi, mi_string, chan_needed); + page_ci(msc, &cil, 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, tmsi, mi_imsi.imsi, chan_needed); break; case CELL_IDENT_LAC: - page_lac(msc, &cil, tmsi, mi_string, chan_needed); + page_lac(msc, &cil, 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_to_str_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, 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_to_str_c(OTC_SELECT, &mi_imsi), + cil.id_discr, osmo_hexdump(data, data_length)); + page_all_bts(msc, tmsi, mi_imsi.imsi, chan_needed); break; } diff --git a/src/osmo-bsc/paging.c b/src/osmo-bsc/paging.c index 7b89dad9b..7859c69d0 100644 --- a/src/osmo-bsc/paging.c +++ b/src/osmo-bsc/paging.c @@ -78,10 +78,9 @@ static void paging_remove_request(struct gsm_bts_paging_state *paging_bts, 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 @@ static void page_ms(struct gsm_paging_request *request) "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 b04140277..bb1874637 100644 --- a/src/osmo-bsc/pcu_sock.c +++ b/src/osmo-bsc/pcu_sock.c @@ -290,27 +290,30 @@ static int pcu_rx_rr_paging(struct gsm_bts *bts, uint8_t paging_group, { 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_to_str_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: -- cgit v1.2.3