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

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

use osmo_mobile_identity API everywhere

Depends: If4f7be606e54cfa1c59084cf169785b1cbda5cf5 (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/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
7 files changed, 64 insertions(+), 53 deletions(-)

Approvals:
  Jenkins Builder: Verified
  neels: Looks good to me, approved



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 705e759..2fb1a22 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/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..6b225e4 100644
--- a/src/osmo-bsc/osmo_bsc_bssap.c
+++ b/src/osmo-bsc/osmo_bsc_bssap.c
@@ -293,7 +293,7 @@
                                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 @@
        /*
         * 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 @@
        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 @@

        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 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..bb18746 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_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:

--
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: 5
Gerrit-Owner: neels <nhofm...@sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <lafo...@osmocom.org>
Gerrit-Reviewer: neels <nhofm...@sysmocom.de>
Gerrit-Reviewer: pespin <pes...@sysmocom.de>
Gerrit-MessageType: merged

Reply via email to