laforge has submitted this change. ( 
https://gerrit.osmocom.org/c/osmocom-bb/+/32744 )

Change subject: layer23: Move all test_sim settings to its own substruct
......................................................................

layer23: Move all test_sim settings to its own substruct

This way it becomes clear those fields are related only to test_sim
module, and not some general "test" feature.

Change-Id: I56830c6b905bcbce7e19adbfe5427fd826d15e8c
---
M src/host/layer23/include/osmocom/bb/common/settings.h
M src/host/layer23/src/common/settings.c
M src/host/layer23/src/common/subscriber.c
M src/host/layer23/src/common/vty.c
M src/host/layer23/src/mobile/app_mobile.c
M src/host/layer23/src/modem/app_modem.c
6 files changed, 86 insertions(+), 70 deletions(-)

Approvals:
  laforge: Looks good to me, approved
  fixeria: Looks good to me, but someone else must approve
  Jenkins Builder: Verified




diff --git a/src/host/layer23/include/osmocom/bb/common/settings.h 
b/src/host/layer23/include/osmocom/bb/common/settings.h
index 38faa4b..01db2a7 100644
--- a/src/host/layer23/include/osmocom/bb/common/settings.h
+++ b/src/host/layer23/include/osmocom/bb/common/settings.h
@@ -57,6 +57,19 @@
        char alsa_input_dev[128];
 };

+struct test_sim_settings {
+       char                    imsi[OSMO_IMSI_BUF_SIZE];
+       uint32_t                tmsi;
+       uint8_t                 ki_type;
+       uint8_t                 ki[16]; /* 128 bit max */
+       uint8_t                 barr;
+       uint8_t                 rplmn_valid;
+       uint16_t                rplmn_mcc, rplmn_mnc;
+       uint16_t                lac;
+       uint8_t                 imsi_attached;
+       uint8_t                 always; /* ...search hplmn... */
+};
+
 struct gsm_settings {
        char                    layer2_socket_path[128];
        char                    sap_socket_path[128];
@@ -85,16 +98,7 @@
        bool                    store_sms;

        /* test card simulator settings */
-       char                    test_imsi[OSMO_IMSI_BUF_SIZE];
-       uint32_t                test_tmsi;
-       uint8_t                 test_ki_type;
-       uint8_t                 test_ki[16]; /* 128 bit max */
-       uint8_t                 test_barr;
-       uint8_t                 test_rplmn_valid;
-       uint16_t                test_rplmn_mcc, test_rplmn_mnc;
-       uint16_t                test_lac;
-       uint8_t                 test_imsi_attached;
-       uint8_t                 test_always; /* ...search hplmn... */
+       struct test_sim_settings test_sim;

        /* call related settings */
        uint8_t                 cw; /* set if call-waiting is allowed */
diff --git a/src/host/layer23/src/common/settings.c 
b/src/host/layer23/src/common/settings.c
index bf1f71b..6c58e65 100644
--- a/src/host/layer23/src/common/settings.c
+++ b/src/host/layer23/src/common/settings.c
@@ -67,10 +67,10 @@
        set->sim_type = GSM_SIM_TYPE_L1PHY;

        /* test SIM */
-       OSMO_STRLCPY_ARRAY(set->test_imsi, "001010000000000");
-       set->test_rplmn_mcc = set->test_rplmn_mnc = 1;
-       set->test_lac = 0x0000;
-       set->test_tmsi = GSM_RESERVED_TMSI;
+       OSMO_STRLCPY_ARRAY(set->test_sim.imsi, "001010000000000");
+       set->test_sim.rplmn_mcc = set->test_sim.rplmn_mnc = 1;
+       set->test_sim.lac = 0x0000;
+       set->test_sim.tmsi = GSM_RESERVED_TMSI;

        /* set all supported features */
        set->sms_ptp = sup->sms_ptp;
diff --git a/src/host/layer23/src/common/subscriber.c 
b/src/host/layer23/src/common/subscriber.c
index 84d08e1..bbbb940 100644
--- a/src/host/layer23/src/common/subscriber.c
+++ b/src/host/layer23/src/common/subscriber.c
@@ -148,7 +148,7 @@
                return -EBUSY;
        }

-       if (!osmo_imsi_str_valid(set->test_imsi)) {
+       if (!osmo_imsi_str_valid(set->test_sim.imsi)) {
                LOGP(DMM, LOGL_ERROR, "Wrong IMSI format\n");
                return -EINVAL;
        }
@@ -160,14 +160,14 @@
        subscr->sim_type = GSM_SIM_TYPE_TEST;
        sprintf(subscr->sim_name, "test");
        subscr->sim_valid = 1;
-       if (imsi_attached && set->test_rplmn_valid) {
+       if (imsi_attached && set->test_sim.rplmn_valid) {
                subscr->imsi_attached = imsi_attached;
                subscr->ustate = GSM_SIM_U1_UPDATED;
        } else
                subscr->ustate = GSM_SIM_U2_NOT_UPDATED;
-       subscr->acc_barr = set->test_barr; /* we may access barred cell */
+       subscr->acc_barr = set->test_sim.barr; /* we may access barred cell */
        subscr->acc_class = 0xffff; /* we have any access class */
-       subscr->plmn_valid = set->test_rplmn_valid;
+       subscr->plmn_valid = set->test_sim.rplmn_valid;
        subscr->plmn_mcc = mcc;
        subscr->plmn_mnc = mnc;
        subscr->mcc = mcc;
@@ -175,9 +175,9 @@
        subscr->lac = lac;
        subscr->tmsi = tmsi;
        subscr->ptmsi = GSM_RESERVED_TMSI;
-       subscr->always_search_hplmn = set->test_always;
+       subscr->always_search_hplmn = set->test_sim.always;
        subscr->t6m_hplmn = 1; /* try to find home network every 6 min */
-       OSMO_STRLCPY_ARRAY(subscr->imsi, set->test_imsi);
+       OSMO_STRLCPY_ARRAY(subscr->imsi, set->test_sim.imsi);

        LOGP(DMM, LOGL_INFO, "(ms %s) Inserting test card (IMSI=%s %s, %s)\n",
                ms->name, subscr->imsi, gsm_imsi_mcc(subscr->imsi),
@@ -902,8 +902,8 @@
                struct osmo_auth_vector _vec;
                struct osmo_auth_vector *vec = &_vec;

-               auth.algo = set->test_ki_type;
-               memcpy(auth.u.gsm.ki, set->test_ki, sizeof(auth.u.gsm.ki));
+               auth.algo = set->test_sim.ki_type;
+               memcpy(auth.u.gsm.ki, set->test_sim.ki, sizeof(auth.u.gsm.ki));
                int ret = osmo_auth_gen_vec(vec, &auth, rand);
                if (ret < 0)
                        return ret;
diff --git a/src/host/layer23/src/common/vty.c 
b/src/host/layer23/src/common/vty.c
index f9ceda8..cdcff6b 100644
--- a/src/host/layer23/src/common/vty.c
+++ b/src/host/layer23/src/common/vty.c
@@ -500,15 +500,15 @@
        }

        set = &ms->settings;
-       if (set->test_rplmn_valid) {
-               mcc = set->test_rplmn_mcc;
-               mnc = set->test_rplmn_mnc;
+       if (set->test_sim.rplmn_valid) {
+               mcc = set->test_sim.rplmn_mcc;
+               mnc = set->test_sim.rplmn_mnc;

-               if (set->test_lac > 0x0000 && set->test_lac < 0xfffe)
-                       lac = set->test_lac;
+               if (set->test_sim.lac > 0x0000 && set->test_sim.lac < 0xfffe)
+                       lac = set->test_sim.lac;

-               if (set->test_tmsi != GSM_RESERVED_TMSI)
-                       tmsi = set->test_tmsi;
+               if (set->test_sim.tmsi != GSM_RESERVED_TMSI)
+                       tmsi = set->test_sim.tmsi;
        }

        if (argc == 2) {
@@ -953,7 +953,7 @@
                return CMD_WARNING;
        }

-       OSMO_STRLCPY_ARRAY(set->test_imsi, argv[0]);
+       OSMO_STRLCPY_ARRAY(set->test_sim.imsi, argv[0]);

        l23_vty_restart_required_warn(vty, ms);

@@ -984,8 +984,8 @@
                ki[i] = strtoul(p, NULL, 16);
        }

-       set->test_ki_type = OSMO_AUTH_ALG_XOR;
-       memcpy(set->test_ki, ki, 12);
+       set->test_sim.ki_type = OSMO_AUTH_ALG_XOR;
+       memcpy(set->test_sim.ki, ki, 12);
        return CMD_SUCCESS;
 }

@@ -1013,8 +1013,8 @@
                ki[i] = strtoul(p, NULL, 16);
        }

-       set->test_ki_type = OSMO_AUTH_ALG_COMP128v1;
-       memcpy(set->test_ki, ki, 16);
+       set->test_sim.ki_type = OSMO_AUTH_ALG_COMP128v1;
+       memcpy(set->test_sim.ki, ki, 16);
        return CMD_SUCCESS;
 }

@@ -1024,7 +1024,7 @@
        struct osmocom_ms *ms = vty->index;
        struct gsm_settings *set = &ms->settings;

-       set->test_barr = 1;
+       set->test_sim.barr = 1;

        return CMD_SUCCESS;
 }
@@ -1035,7 +1035,7 @@
        struct osmocom_ms *ms = vty->index;
        struct gsm_settings *set = &ms->settings;

-       set->test_barr = 0;
+       set->test_sim.barr = 0;

        return CMD_SUCCESS;
 }
@@ -1046,7 +1046,7 @@
        struct osmocom_ms *ms = vty->index;
        struct gsm_settings *set = &ms->settings;

-       set->test_rplmn_valid = 0;
+       set->test_sim.rplmn_valid = 0;

        l23_vty_restart_required_warn(vty, ms);

@@ -1069,24 +1069,24 @@
                vty_out(vty, "Given MNC invalid%s", VTY_NEWLINE);
                return CMD_WARNING;
        }
-       set->test_rplmn_valid = 1;
-       set->test_rplmn_mcc = mcc;
-       set->test_rplmn_mnc = mnc;
+       set->test_sim.rplmn_valid = 1;
+       set->test_sim.rplmn_mcc = mcc;
+       set->test_sim.rplmn_mnc = mnc;

        if (argc >= 3)
-               set->test_lac = strtoul(argv[2], NULL, 16);
+               set->test_sim.lac = strtoul(argv[2], NULL, 16);
        else
-               set->test_lac = 0xfffe;
+               set->test_sim.lac = 0xfffe;

        if (argc >= 4)
-               set->test_tmsi = strtoul(argv[3], NULL, 16);
+               set->test_sim.tmsi = strtoul(argv[3], NULL, 16);
        else
-               set->test_tmsi = GSM_RESERVED_TMSI;
+               set->test_sim.tmsi = GSM_RESERVED_TMSI;

        if (attached)
-               set->test_imsi_attached = 1;
+               set->test_sim.imsi_attached = 1;
        else
-               set->test_imsi_attached = 0;
+               set->test_sim.imsi_attached = 0;

        l23_vty_restart_required_warn(vty, ms);
 
@@ -1121,10 +1121,10 @@

        switch (argv[0][0]) {
        case 'e':
-               set->test_always = 1;
+               set->test_sim.always = 1;
                break;
        case 'f':
-               set->test_always = 0;
+               set->test_sim.always = 0;
                break;
        }

@@ -1189,29 +1189,29 @@
 {
        const struct gsm_settings *set = &ms->settings;
        vty_out(vty, "%stest-sim%s", prefix, VTY_NEWLINE);
-       vty_out(vty, "%s imsi %s%s", prefix, set->test_imsi, VTY_NEWLINE);
-       switch (set->test_ki_type) {
+       vty_out(vty, "%s imsi %s%s", prefix, set->test_sim.imsi, VTY_NEWLINE);
+       switch (set->test_sim.ki_type) {
        case OSMO_AUTH_ALG_XOR:
                vty_out(vty, "%s ki xor %s%s",
-                       prefix, osmo_hexdump(set->test_ki, 12), VTY_NEWLINE);
+                       prefix, osmo_hexdump(set->test_sim.ki, 12), 
VTY_NEWLINE);
                break;
        case OSMO_AUTH_ALG_COMP128v1:
                vty_out(vty, "%s ki comp128 %s%s",
-                       prefix, osmo_hexdump(set->test_ki, 16), VTY_NEWLINE);
+                       prefix, osmo_hexdump(set->test_sim.ki, 16), 
VTY_NEWLINE);
                break;
        }
-       if (!l23_vty_hide_default || set->test_barr)
+       if (!l23_vty_hide_default || set->test_sim.barr)
                vty_out(vty, "%s %sbarred-access%s", prefix,
-                       (set->test_barr) ? "" : "no ", VTY_NEWLINE);
-       if (set->test_rplmn_valid) {
+                       (set->test_sim.barr) ? "" : "no ", VTY_NEWLINE);
+       if (set->test_sim.rplmn_valid) {
                vty_out(vty, "%s rplmn %s %s", prefix,
-                       gsm_print_mcc(set->test_rplmn_mcc),
-                       gsm_print_mnc(set->test_rplmn_mnc));
-               if (set->test_lac > 0x0000 && set->test_lac < 0xfffe) {
-                       vty_out(vty, " 0x%04x", set->test_lac);
-                       if (set->test_tmsi != GSM_RESERVED_TMSI) {
-                               vty_out(vty, " 0x%08x", set->test_tmsi);
-                               if (set->test_imsi_attached)
+                       gsm_print_mcc(set->test_sim.rplmn_mcc),
+                       gsm_print_mnc(set->test_sim.rplmn_mnc));
+               if (set->test_sim.lac > 0x0000 && set->test_sim.lac < 0xfffe) {
+                       vty_out(vty, " 0x%04x", set->test_sim.lac);
+                       if (set->test_sim.tmsi != GSM_RESERVED_TMSI) {
+                               vty_out(vty, " 0x%08x", set->test_sim.tmsi);
+                               if (set->test_sim.imsi_attached)
                                        vty_out(vty, " attached");
                        }
                }
@@ -1219,9 +1219,9 @@
        } else
                if (!l23_vty_hide_default)
                        vty_out(vty, "%s no rplmn%s", prefix, VTY_NEWLINE);
-       if (!l23_vty_hide_default || set->test_always)
+       if (!l23_vty_hide_default || set->test_sim.always)
                vty_out(vty, "%s hplmn-search %s%s", prefix,
-                       (set->test_always) ? "everywhere" : "foreign-country",
+                       (set->test_sim.always) ? "everywhere" : 
"foreign-country",
                        VTY_NEWLINE);
        return CMD_SUCCESS;
 }
diff --git a/src/host/layer23/src/mobile/app_mobile.c 
b/src/host/layer23/src/mobile/app_mobile.c
index e7caed2..6f00207 100644
--- a/src/host/layer23/src/mobile/app_mobile.c
+++ b/src/host/layer23/src/mobile/app_mobile.c
@@ -167,9 +167,9 @@
                        gsm_subscr_simcard(ms);
                        break;
                case GSM_SIM_TYPE_TEST:
-                       gsm_subscr_testcard(ms, set->test_rplmn_mcc,
-                               set->test_rplmn_mnc, set->test_lac,
-                               set->test_tmsi, set->test_imsi_attached);
+                       gsm_subscr_testcard(ms, set->test_sim.rplmn_mcc,
+                               set->test_sim.rplmn_mnc, set->test_sim.lac,
+                               set->test_sim.tmsi, 
set->test_sim.imsi_attached);
                        break;
                case GSM_SIM_TYPE_SAP:
                        gsm_subscr_sapcard(ms);
diff --git a/src/host/layer23/src/modem/app_modem.c 
b/src/host/layer23/src/modem/app_modem.c
index 68e2930..1f0ebb7 100644
--- a/src/host/layer23/src/modem/app_modem.c
+++ b/src/host/layer23/src/modem/app_modem.c
@@ -213,9 +213,9 @@
                        gsm_subscr_simcard(ms);
                        break;
                case GSM_SIM_TYPE_TEST:
-                       gsm_subscr_testcard(ms, set->test_rplmn_mcc,
-                               set->test_rplmn_mnc, set->test_lac,
-                               set->test_tmsi, set->test_imsi_attached);
+                       gsm_subscr_testcard(ms, set->test_sim.rplmn_mcc,
+                               set->test_sim.rplmn_mnc, set->test_sim.lac,
+                               set->test_sim.tmsi, 
set->test_sim.imsi_attached);
                        break;
                case GSM_SIM_TYPE_SAP:
                        gsm_subscr_sapcard(ms);

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

Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Change-Id: I56830c6b905bcbce7e19adbfe5427fd826d15e8c
Gerrit-Change-Number: 32744
Gerrit-PatchSet: 2
Gerrit-Owner: pespin <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <[email protected]>
Gerrit-Reviewer: laforge <[email protected]>
Gerrit-Reviewer: osmith <[email protected]>
Gerrit-MessageType: merged

Reply via email to