pespin has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/osmocom-bb/+/32418 )


Change subject: layer23: Use libosmocore API to validate IMSI string
......................................................................

layer23: Use libosmocore API to validate IMSI string

Change-Id: I2d4737dabcfb83a7b675c35ad973029a36658d5b
---
M src/host/layer23/include/osmocom/bb/common/subscriber.h
M src/host/layer23/src/common/subscriber.c
M src/host/layer23/src/mobile/vty_interface.c
3 files changed, 17 insertions(+), 27 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/18/32418/1

diff --git a/src/host/layer23/include/osmocom/bb/common/subscriber.h 
b/src/host/layer23/include/osmocom/bb/common/subscriber.h
index 698b0fd..8b15295 100644
--- a/src/host/layer23/include/osmocom/bb/common/subscriber.h
+++ b/src/host/layer23/include/osmocom/bb/common/subscriber.h
@@ -112,7 +112,6 @@
                        void (*print)(void *, const char *, ...), void *priv);
 void gsm_subscr_dump(struct gsm_subscriber *subscr,
                        void (*print)(void *, const char *, ...), void *priv);
-char *gsm_check_imsi(const char *imsi);
 int gsm_subscr_get_key_seq(struct osmocom_ms *ms, struct gsm_subscriber 
*subscr);

 #endif /* _SUBSCRIBER_H */
diff --git a/src/host/layer23/src/common/subscriber.c 
b/src/host/layer23/src/common/subscriber.c
index 05771ff..e3f5a8c 100644
--- a/src/host/layer23/src/common/subscriber.c
+++ b/src/host/layer23/src/common/subscriber.c
@@ -21,6 +21,7 @@
 #include <arpa/inet.h>
 #include <osmocom/core/talloc.h>
 #include <osmocom/crypt/auth.h>
+#include <osmocom/gsm/gsm23003.h>

 #include <osmocom/bb/common/logging.h>
 #include <osmocom/bb/common/osmocom_data.h>
@@ -43,21 +44,6 @@
  * support
  */

-char *gsm_check_imsi(const char *imsi)
-{
-       int i;
-
-       if (!imsi || strlen(imsi) != 15)
-               return "IMSI must have 15 digits!";
-
-       for (i = 0; i < strlen(imsi); i++) {
-               if (imsi[i] < '0' || imsi[i] > '9')
-                       return "IMSI must have digits 0 to 9 only!";
-       }
-
-       return NULL;
-}
-
 static char *sim_decode_bcd(uint8_t *data, uint8_t length)
 {
        int i, j = 0;
@@ -154,7 +140,6 @@
        struct gsm_settings *set = &ms->settings;
        struct gsm_subscriber *subscr = &ms->subscr;
        struct msgb *nmsg;
-       char *error;

        if (subscr->sim_valid) {
                LOGP(DMM, LOGL_ERROR, "Cannot insert card, until current card "
@@ -162,9 +147,8 @@
                return -EBUSY;
        }

-       error = gsm_check_imsi(set->test_imsi);
-       if (error) {
-               LOGP(DMM, LOGL_ERROR, "%s\n", error);
+       if (!osmo_imsi_str_valid(set->test_imsi)) {
+               LOGP(DMM, LOGL_ERROR, "Wrong IMSI format\n");
                return -EINVAL;
        }

diff --git a/src/host/layer23/src/mobile/vty_interface.c 
b/src/host/layer23/src/mobile/vty_interface.c
index f4dc8a9..b2ddfe7 100644
--- a/src/host/layer23/src/mobile/vty_interface.c
+++ b/src/host/layer23/src/mobile/vty_interface.c
@@ -26,6 +26,7 @@
 #include <osmocom/core/talloc.h>
 #include <osmocom/core/signal.h>
 #include <osmocom/crypt/auth.h>
+#include <osmocom/gsm/gsm23003.h>

 #include <osmocom/bb/common/osmocom_data.h>
 #include <osmocom/bb/common/ms.h>
@@ -1750,11 +1751,9 @@
 {
        struct osmocom_ms *ms = vty->index;
        struct gsm_settings *set = &ms->settings;
-       char *error;
 
-       error = gsm_check_imsi(argv[0]);
-       if (error) {
-               vty_out(vty, "%s%s", error, VTY_NEWLINE);
+       if (!osmo_imsi_str_valid(argv[0])) {
+               vty_out(vty, "Wrong IMSI format%s", VTY_NEWLINE);
                return CMD_WARNING;
        }
        strcpy(set->emergency_imsi, argv[0]);
@@ -2586,10 +2585,9 @@
 {
        struct osmocom_ms *ms = vty->index;
        struct gsm_settings *set = &ms->settings;
-       char *error = gsm_check_imsi(argv[0]);

-       if (error) {
-               vty_out(vty, "%s%s", error, VTY_NEWLINE);
+       if (!osmo_imsi_str_valid(argv[0])) {
+               vty_out(vty, "Wrong IMSI format%s", VTY_NEWLINE);
                return CMD_WARNING;
        }


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

Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Change-Id: I2d4737dabcfb83a7b675c35ad973029a36658d5b
Gerrit-Change-Number: 32418
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <[email protected]>
Gerrit-MessageType: newchange

Reply via email to