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

Change subject: layer23: Migrate sim_ustate to enum + value_string
......................................................................

layer23: Migrate sim_ustate to enum + value_string

Change-Id: I83607caa0b76b6b30db59c53438a55726483b85d
---
M src/host/layer23/include/osmocom/bb/common/subscriber.h
M src/host/layer23/src/common/subscriber.c
2 files changed, 32 insertions(+), 13 deletions(-)

Approvals:
  laforge: Looks good to me, approved
  fixeria: Looks good to me, approved
  Jenkins Builder: Verified




diff --git a/src/host/layer23/include/osmocom/bb/common/subscriber.h 
b/src/host/layer23/include/osmocom/bb/common/subscriber.h
index 1dd1869..1a9bc6e 100644
--- a/src/host/layer23/include/osmocom/bb/common/subscriber.h
+++ b/src/host/layer23/include/osmocom/bb/common/subscriber.h
@@ -1,13 +1,22 @@
 #ifndef _SUBSCRIBER_H
 #define _SUBSCRIBER_H

+#include <osmocom/core/utils.h>
 #include <osmocom/gsm/protocol/gsm_23_003.h>

 /* GSM 04.08 4.1.2.2 SIM update status */
-#define GSM_SIM_U0_NULL                0
-#define GSM_SIM_U1_UPDATED     1
-#define GSM_SIM_U2_NOT_UPDATED 2
-#define GSM_SIM_U3_ROAMING_NA  3
+enum gsm_sub_sim_ustate {
+       GSM_SIM_U0_NULL,
+       GSM_SIM_U1_UPDATED,
+       GSM_SIM_U2_NOT_UPDATED,
+       GSM_SIM_U3_ROAMING_NA,
+};
+extern const struct value_string gsm_sub_sim_ustate_names[];
+static inline const char *gsm_sub_sim_ustate_name(enum gsm_sub_sim_ustate val)
+{
+       return get_value_string(gsm_sub_sim_ustate_names, val);
+}
+

 struct gsm_sub_plmn_list {
        struct llist_head       entry;
@@ -36,7 +45,7 @@
        /* status */
        uint8_t                 sim_type; /* type of sim */
        uint8_t                 sim_valid; /* sim inserted and valid */
-       uint8_t                 ustate; /* update status */
+       enum gsm_sub_sim_ustate ustate; /* update status */
        uint8_t                 imsi_attached; /* attached state */

        /* IMSI & co */
diff --git a/src/host/layer23/src/common/subscriber.c 
b/src/host/layer23/src/common/subscriber.c
index bbbb940..97c1d1e 100644
--- a/src/host/layer23/src/common/subscriber.c
+++ b/src/host/layer23/src/common/subscriber.c
@@ -1016,19 +1016,20 @@
  * state and lists
  */

-static const char *subscr_ustate_names[] = {
-       "U0_NULL",
-       "U1_UPDATED",
-       "U2_NOT_UPDATED",
-       "U3_ROAMING_NA"
+const struct value_string gsm_sub_sim_ustate_names[] = {
+       { GSM_SIM_U0_NULL, "U0_NULL" },
+       { GSM_SIM_U1_UPDATED, "U1_UPDATED" },
+       { GSM_SIM_U2_NOT_UPDATED, "U2_NOT_UPDATED" },
+       { GSM_SIM_U3_ROAMING_NA, "U3_ROAMING_NA" },
+       { 0, NULL }
 };
 
 /* change to new U state */
 void new_sim_ustate(struct gsm_subscriber *subscr, int state)
 {
        LOGP(DMM, LOGL_INFO, "(ms %s) new state %s -> %s\n", subscr->ms->name,
-               subscr_ustate_names[subscr->ustate],
-               subscr_ustate_names[state]);
+               gsm_sub_sim_ustate_name(subscr->ustate),
+               gsm_sub_sim_ustate_name(state));

        subscr->ustate = state;
 }
@@ -1153,7 +1154,7 @@
        if (subscr->sms_sca[0])
                print(priv, " SMS Service Center Address: %s\n",
                        subscr->sms_sca);
-       print(priv, " Status: %s  IMSI %s", subscr_ustate_names[subscr->ustate],
+       print(priv, " Status: %s  IMSI %s", 
gsm_sub_sim_ustate_name(subscr->ustate),
                (subscr->imsi_attached) ? "attached" : "detached");
        if (subscr->tmsi != GSM_RESERVED_TMSI)
                print(priv, "  TMSI 0x%08x", subscr->tmsi);

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

Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Change-Id: I83607caa0b76b6b30db59c53438a55726483b85d
Gerrit-Change-Number: 32745
Gerrit-PatchSet: 3
Gerrit-Owner: pespin <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <[email protected]>
Gerrit-Reviewer: laforge <[email protected]>
Gerrit-MessageType: merged

Reply via email to