diff options
author | Pau Espin Pedrol <pespin@sysmocom.de> | 2023-04-24 17:06:10 +0200 |
---|---|---|
committer | Pau Espin Pedrol <pespin@sysmocom.de> | 2023-04-24 17:06:10 +0200 |
commit | 234c1f14fd0ca8ea71bf75dccc5eb4f37863380a (patch) | |
tree | 2825f45686926daaf7503e8e97c93e4ff0e31976 | |
parent | a78c3927a0b241b78665e23d6df0d9c6da9f4e55 (diff) |
layer23: Use libosmocore API to validate IMSI string
Change-Id: I2d4737dabcfb83a7b675c35ad973029a36658d5b
-rw-r--r-- | src/host/layer23/include/osmocom/bb/common/subscriber.h | 1 | ||||
-rw-r--r-- | src/host/layer23/src/common/subscriber.c | 22 | ||||
-rw-r--r-- | src/host/layer23/src/mobile/vty_interface.c | 12 |
3 files changed, 8 insertions, 27 deletions
diff --git a/src/host/layer23/include/osmocom/bb/common/subscriber.h b/src/host/layer23/include/osmocom/bb/common/subscriber.h index 698b0fdc..8b15295c 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 @@ int gsm_subscr_dump_forbidden_plmn(struct osmocom_ms *ms, 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 05771ffd..e3f5a8c0 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 @@ static void subscr_sim_key_cb(struct osmocom_ms *ms, struct msgb *msg); * 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 @@ int gsm_subscr_testcard(struct osmocom_ms *ms, uint16_t mcc, uint16_t mnc, 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 @@ int gsm_subscr_testcard(struct osmocom_ms *ms, uint16_t mcc, uint16_t mnc, 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 f4dc8a9b..b2ddfe75 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 @@ DEFUN(cfg_ms_emerg_imsi, cfg_ms_emerg_imsi_cmd, "emergency-imsi IMSI", { 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 @@ DEFUN(cfg_test_imsi, cfg_test_imsi_cmd, "imsi IMSI", { 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; } |