Harald Welte has submitted this change and it was merged.

Change subject: implement support for 3-digit MNC with leading zeros
......................................................................


implement support for 3-digit MNC with leading zeros

Receive the mnc_3_digits flag from the PCU interface.

Bump the PCU interface to 9.
This is one part of the three identical pcuif_proto.h patches:
- I49cd762c3c9d7ee6a82451bdf3ffa2a060767947 (osmo-bts)
- I787fed84a7b613158a5618dd5cffafe4e4927234 (osmo-pcu)
- I78f30aef7aa224b2e9db54c3a844d8f520b3aee0 (osmo-bsc)

Add 3-digit flags and use the new RAI and LAI API from libosmocore throughout
the code base to be able to handle an MNC < 100 that has three digits (leading
zeros).

Depends: Id2240f7f518494c9df6c8bda52c0d5092f90f221 (libosmocore),
         Ib7176b1d65a03b76f41f94bc9d3293a8a07d24c6 (libosmocore)

Change-Id: I787fed84a7b613158a5618dd5cffafe4e4927234
---
M include/osmocom/pcu/pcuif_proto.h
M src/gprs_bssgp_pcu.cpp
M src/gprs_bssgp_pcu.h
M src/pcu_l1_if.cpp
M src/pcu_main.cpp
M tests/alloc/AllocTest.cpp
M tests/alloc/MslotTest.cpp
M tests/edge/EdgeTest.cpp
M tests/emu/pcu_emu.cpp
M tests/fn/FnTest.cpp
M tests/llc/LlcTest.cpp
M tests/ms/MsTest.cpp
M tests/tbf/TbfTest.cpp
M tests/types/TypesTest.cpp
14 files changed, 40 insertions(+), 21 deletions(-)

Approvals:
  Neels Hofmeyr: Verified
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/include/osmocom/pcu/pcuif_proto.h 
b/include/osmocom/pcu/pcuif_proto.h
index 00b7bd5..b06077c 100644
--- a/include/osmocom/pcu/pcuif_proto.h
+++ b/include/osmocom/pcu/pcuif_proto.h
@@ -5,7 +5,7 @@
 
 #define PCU_SOCK_DEFAULT       "/tmp/pcu_bts"
 
-#define PCU_IF_VERSION         0x08
+#define PCU_IF_VERSION         0x09
 #define TXT_MAX_LEN    128
 
 /* msg_type */
@@ -122,7 +122,9 @@
        struct gsm_pcu_if_info_trx trx[8];      /* TRX infos per BTS */
        uint8_t         bsic;
        /* RAI */
-       uint16_t        mcc, mnc, lac, rac;
+       uint16_t        mcc, mnc;
+       uint8_t         mnc_3_digits;
+       uint16_t        lac, rac;
        /* NSE */
        uint16_t        nsei;
        uint8_t         nse_timer[7];
diff --git a/src/gprs_bssgp_pcu.cpp b/src/gprs_bssgp_pcu.cpp
index 3cc86e2..6727735 100644
--- a/src/gprs_bssgp_pcu.cpp
+++ b/src/gprs_bssgp_pcu.cpp
@@ -44,6 +44,7 @@
 
 extern void *tall_pcu_ctx;
 extern uint16_t spoof_mcc, spoof_mnc;
+extern bool spoof_mnc_3_digits;
 
 static void bvc_timeout(void *_priv);
 
@@ -876,15 +877,11 @@
 struct gprs_bssgp_pcu *gprs_bssgp_create_and_connect(struct gprs_rlcmac_bts 
*bts,
        uint16_t local_port, uint32_t sgsn_ip,
        uint16_t sgsn_port, uint16_t nsei, uint16_t nsvci, uint16_t bvci,
-       uint16_t mcc, uint16_t mnc, uint16_t lac, uint16_t rac,
+       uint16_t mcc, uint16_t mnc, bool mnc_3_digits, uint16_t lac, uint16_t 
rac,
        uint16_t cell_id)
 {
        struct sockaddr_in dest;
        int rc;
-
-       mcc = ((mcc & 0xf00) >> 8) * 100 + ((mcc & 0x0f0) >> 4) * 10 + (mcc & 
0x00f);
-       mnc = ((mnc & 0xf00) >> 8) * 100 + ((mnc & 0x0f0) >> 4) * 10 + (mnc & 
0x00f);
-       cell_id = ntohs(cell_id);
 
        /* if already created... return the current address */
        if (the_pcu.bctx)
@@ -930,7 +927,13 @@
                return NULL;
        }
        the_pcu.bctx->ra_id.mcc = spoof_mcc ? : mcc;
-       the_pcu.bctx->ra_id.mnc = spoof_mnc ? : mnc;
+       if (spoof_mnc) {
+               the_pcu.bctx->ra_id.mnc = spoof_mnc;
+               the_pcu.bctx->ra_id.mnc_3_digits = spoof_mnc_3_digits;
+       } else {
+               the_pcu.bctx->ra_id.mnc = mnc;
+               the_pcu.bctx->ra_id.mnc_3_digits = mnc_3_digits;
+       }
        the_pcu.bctx->ra_id.lac = lac;
        the_pcu.bctx->ra_id.rac = rac;
        the_pcu.bctx->cell_id = cell_id;
diff --git a/src/gprs_bssgp_pcu.h b/src/gprs_bssgp_pcu.h
index 4eda57d..4127244 100644
--- a/src/gprs_bssgp_pcu.h
+++ b/src/gprs_bssgp_pcu.h
@@ -77,7 +77,7 @@
 struct gprs_bssgp_pcu *gprs_bssgp_create_and_connect(struct gprs_rlcmac_bts 
*bts,
                uint16_t local_port,
                uint32_t sgsn_ip, uint16_t sgsn_port, uint16_t nsei,
-               uint16_t nsvci, uint16_t bvci, uint16_t mcc, uint16_t mnc,
+               uint16_t nsvci, uint16_t bvci, uint16_t mcc, uint16_t mnc, bool 
mnc_3_digits,
                uint16_t lac, uint16_t rac, uint16_t cell_id);
 
 void gprs_bssgp_destroy(void);
diff --git a/src/pcu_l1_if.cpp b/src/pcu_l1_if.cpp
index 664a7b7..85dbfb9 100644
--- a/src/pcu_l1_if.cpp
+++ b/src/pcu_l1_if.cpp
@@ -408,6 +408,7 @@
        int rc = 0;
        unsigned int trx, ts;
        int i;
+       uint16_t cell_id = ntohs(info_ind->cell_id);
 
        if (info_ind->version != PCU_IF_VERSION) {
                fprintf(stderr, "PCU interface version number of BTS (%d) is "
@@ -434,11 +435,11 @@
                exit(0);
        }
        LOGP(DL1IF, LOGL_INFO, "BTS available\n");
-       LOGP(DL1IF, LOGL_DEBUG, " mcc=%x\n", info_ind->mcc);
-       LOGP(DL1IF, LOGL_DEBUG, " mnc=%x\n", info_ind->mnc);
+       LOGP(DL1IF, LOGL_DEBUG, " mcc=%03u\n", info_ind->mcc);
+       LOGP(DL1IF, LOGL_DEBUG, " mnc=%0*u\n", info_ind->mnc_3_digits, 
info_ind->mnc);
        LOGP(DL1IF, LOGL_DEBUG, " lac=%d\n", info_ind->lac);
        LOGP(DL1IF, LOGL_DEBUG, " rac=%d\n", info_ind->rac);
-       LOGP(DL1IF, LOGL_DEBUG, " cell_id=%d\n", ntohs(info_ind->cell_id));
+       LOGP(DL1IF, LOGL_DEBUG, " cell_id=%d\n", cell_id);
        LOGP(DL1IF, LOGL_DEBUG, " bsic=%d\n", info_ind->bsic);
        LOGP(DL1IF, LOGL_DEBUG, " nsei=%d\n", info_ind->nsei);
        LOGP(DL1IF, LOGL_DEBUG, " nse_timer=%d %d %d %d %d %d %d\n",
@@ -488,8 +489,8 @@
        pcu = gprs_bssgp_create_and_connect(bts, info_ind->local_port[0],
                info_ind->remote_ip[0], info_ind->remote_port[0],
                info_ind->nsei, info_ind->nsvci[0], info_ind->bvci,
-               info_ind->mcc, info_ind->mnc, info_ind->lac, info_ind->rac,
-               info_ind->cell_id);
+               info_ind->mcc, info_ind->mnc, info_ind->mnc_3_digits, 
info_ind->lac, info_ind->rac,
+               cell_id);
        if (!pcu) {
                LOGP(DL1IF, LOGL_NOTICE, "SGSN not available\n");
                goto bssgp_failed;
diff --git a/src/pcu_main.cpp b/src/pcu_main.cpp
index 0c3a414..84ade6f 100644
--- a/src/pcu_main.cpp
+++ b/src/pcu_main.cpp
@@ -52,6 +52,7 @@
 
 extern struct gprs_nsvc *nsvc;
 uint16_t spoof_mcc = 0, spoof_mnc = 0;
+bool spoof_mnc_3_digits = false;
 static int config_given = 0;
 static char *config_file = strdup("osmo-pcu.cfg");
 extern struct vty_app_info pcu_vty_info;
@@ -114,7 +115,10 @@
                        spoof_mcc = atoi(optarg);
                        break;
                case 'n':
-                       spoof_mnc = atoi(optarg);
+                       if (osmo_mnc_from_str(optarg, &spoof_mnc, 
&spoof_mnc_3_digits)) {
+                               fprintf(stderr, "Error decoding MNC '%s'\n", 
optarg);
+                               exit(1);
+                       }
                        break;
                case 'V':
                        print_version(1);
diff --git a/tests/alloc/AllocTest.cpp b/tests/alloc/AllocTest.cpp
index 1c98e46..9f6e6c4 100644
--- a/tests/alloc/AllocTest.cpp
+++ b/tests/alloc/AllocTest.cpp
@@ -36,6 +36,7 @@
 /* globals used by the code */
 void *tall_pcu_ctx;
 int16_t spoof_mnc = 0, spoof_mcc = 0;
+bool spoof_mnc_3_digits = false;
 
 static gprs_rlcmac_tbf *tbf_alloc(struct gprs_rlcmac_bts *bts,
                GprsMs *ms, gprs_rlcmac_tbf_direction dir,
diff --git a/tests/alloc/MslotTest.cpp b/tests/alloc/MslotTest.cpp
index 92f92fa..ebe04ca 100644
--- a/tests/alloc/MslotTest.cpp
+++ b/tests/alloc/MslotTest.cpp
@@ -37,6 +37,7 @@
 /* globals used by the code */
 void *tall_pcu_ctx;
 int16_t spoof_mnc = 0, spoof_mcc = 0;
+bool spoof_mnc_3_digits = false;
 
 static inline void test_all_classes(struct gprs_rlcmac_trx *trx, bool 
clear_masks)
 {
diff --git a/tests/edge/EdgeTest.cpp b/tests/edge/EdgeTest.cpp
index eb9ef42..cd80c05 100644
--- a/tests/edge/EdgeTest.cpp
+++ b/tests/edge/EdgeTest.cpp
@@ -46,6 +46,7 @@
 
 void *tall_pcu_ctx;
 int16_t spoof_mnc = 0, spoof_mcc = 0;
+bool spoof_mnc_3_digits = false;
 
 static void check_coding_scheme(GprsCodingScheme& cs, GprsCodingScheme::Mode 
mode)
 {
diff --git a/tests/emu/pcu_emu.cpp b/tests/emu/pcu_emu.cpp
index 957ddf6..4cc37f3 100644
--- a/tests/emu/pcu_emu.cpp
+++ b/tests/emu/pcu_emu.cpp
@@ -40,6 +40,7 @@
 /* Extern data to please the underlying code */
 void *tall_pcu_ctx;
 int16_t spoof_mnc = 0, spoof_mcc = 0;
+bool spoof_mnc_3_digits = false;
 
 extern void test_replay_gprs_attach(struct gprs_bssgp_pcu *pcu);
 extern void test_replay_gprs_data(struct gprs_bssgp_pcu *, struct msgb *, 
struct tlv_parsed *);
@@ -99,7 +100,7 @@
        struct gprs_bssgp_pcu *pcu;
 
        pcu = gprs_bssgp_create_and_connect(bts, 0, sgsn_ip, sgsn_port,
-                                       20, 20, 20, 0x901, 0x99, 1, 0, 0);
+                                       20, 20, 20, 901, 99, false, 1, 0, 0);
        pcu->on_unblock_ack = bvci_unblocked;
        pcu->on_dl_unit_data = bssgp_data;
 }
diff --git a/tests/fn/FnTest.cpp b/tests/fn/FnTest.cpp
index 279903c..1e3ff11 100644
--- a/tests/fn/FnTest.cpp
+++ b/tests/fn/FnTest.cpp
@@ -34,6 +34,7 @@
 
 /* globals used by the code */ void *tall_pcu_ctx;
 int16_t spoof_mnc = 0, spoof_mcc = 0;
+bool spoof_mnc_3_digits = false;
 
 static uint32_t calc_fn(BTS * bts, uint32_t rfn)
 {
diff --git a/tests/llc/LlcTest.cpp b/tests/llc/LlcTest.cpp
index f827ef1..eb693f5 100644
--- a/tests/llc/LlcTest.cpp
+++ b/tests/llc/LlcTest.cpp
@@ -40,6 +40,7 @@
 
 void *tall_pcu_ctx;
 int16_t spoof_mnc = 0, spoof_mcc = 0;
+bool spoof_mnc_3_digits = false;
 
 static void enqueue_data(gprs_llc_queue *queue, const uint8_t *data, size_t 
len,
        gprs_llc_queue::MetaInfo *info = 0)
diff --git a/tests/ms/MsTest.cpp b/tests/ms/MsTest.cpp
index ac35998..4601504 100644
--- a/tests/ms/MsTest.cpp
+++ b/tests/ms/MsTest.cpp
@@ -41,6 +41,7 @@
 
 void *tall_pcu_ctx;
 int16_t spoof_mnc = 0, spoof_mcc = 0;
+bool spoof_mnc_3_digits = false;
 
 static void test_ms_state()
 {
diff --git a/tests/tbf/TbfTest.cpp b/tests/tbf/TbfTest.cpp
index fb9158f..662708a 100644
--- a/tests/tbf/TbfTest.cpp
+++ b/tests/tbf/TbfTest.cpp
@@ -47,6 +47,7 @@
 
 void *tall_pcu_ctx;
 int16_t spoof_mnc = 0, spoof_mcc = 0;
+bool spoof_mnc_3_digits = false;
 
 static void check_tbf(gprs_rlcmac_tbf *tbf)
 {
@@ -449,7 +450,7 @@
        bts = the_bts.bts_data();
        setup_bts(&the_bts, ts_no);
        gprs_bssgp_create_and_connect(bts, 33001, 0, 33001,
-               1234, 1234, 1234, 1, 1, 0, 0, 0);
+               1234, 1234, 1234, 1, 1, false, 0, 0, 0);
 
        for (i = 0; i < 1024; i++) {
                uint32_t tlli = 0xc0000000 + i;
@@ -492,7 +493,7 @@
        bts->ms_idle_sec = 10; /* keep the MS object */
 
        gprs_bssgp_create_and_connect(bts, 33001, 0, 33001,
-               1234, 1234, 1234, 1, 1, 0, 0, 0);
+               1234, 1234, 1234, 1, 1, false, 0, 0, 0);
 
        /* Handle LLC frame 1 */
        memset(buf, 1, sizeof(buf));
@@ -2161,7 +2162,7 @@
        bts->egprs_enabled = 1;
 
        gprs_bssgp_create_and_connect(bts, 33001, 0, 33001,
-               1234, 1234, 1234, 1, 1, 0, 0, 0);
+               1234, 1234, 1234, 1, 1, false, 0, 0, 0);
 
        /* Does not support EGPRS */
        rc = gprs_rlcmac_dl_tbf::handle(bts, tlli, 0, imsi, ms_class, 0,
@@ -2223,7 +2224,7 @@
        bts->trx[0].pdch[5].enable();
 
        gprs_bssgp_create_and_connect(bts, 33001, 0, 33001,
-               1234, 1234, 1234, 1, 1, 0, 0, 0);
+               1234, 1234, 1234, 1, 1, false, 0, 0, 0);
 
        /* Does no support EGPRS */
        dl_tbf = tbf_alloc_dl_tbf(bts, NULL, 0, ms_class, 0, false);
@@ -2261,7 +2262,7 @@
        bts->trx[0].pdch[5].enable();
 
        gprs_bssgp_create_and_connect(bts, 33001, 0, 33001,
-               1234, 1234, 1234, 1, 1, 0, 0, 0);
+               1234, 1234, 1234, 1, 1, false, 0, 0, 0);
 
        /* EGPRS-only */
        bts->egprs_enabled = 1;
diff --git a/tests/types/TypesTest.cpp b/tests/types/TypesTest.cpp
index 5c4da22..3a43897 100644
--- a/tests/types/TypesTest.cpp
+++ b/tests/types/TypesTest.cpp
@@ -44,6 +44,7 @@
 
 void *tall_pcu_ctx;
 int16_t spoof_mnc = 0, spoof_mcc = 0;
+bool spoof_mnc_3_digits = false;
 
 static void test_llc(void)
 {

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I787fed84a7b613158a5618dd5cffafe4e4927234
Gerrit-PatchSet: 3
Gerrit-Project: osmo-pcu
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofm...@sysmocom.de>
Gerrit-Reviewer: Harald Welte <lafo...@gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Neels Hofmeyr <nhofm...@sysmocom.de>

Reply via email to