From 051dedd23551854ceecc0241af2edad07e15df88 Mon Sep 17 00:00:00 2001 From: Andreas Eversberg Date: Sun, 26 Jun 2011 10:53:28 +0200 Subject: [PATCH] [layer23] Added special return value for invalid MCC/MNC input This way an MNC of 000 can be entered. --- .../include/osmocom/bb/common/networks.h | 2 ++ src/host/layer23/src/common/networks.c | 11 +++++---- src/host/layer23/src/mobile/vty_interface.c | 24 +++++++++---------- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/host/layer23/include/osmocom/bb/common/networks.h b/src/host/layer23/include/osmocom/bb/common/networks.h index e8c1b18..e681216 100644 --- a/src/host/layer23/include/osmocom/bb/common/networks.h +++ b/src/host/layer23/include/osmocom/bb/common/networks.h @@ -1,6 +1,8 @@ #ifndef _NETWORKS_H #define _NETWORKS_H +#define GSM_INPUT_INVALID 0xffff + struct gsm_networks { uint16_t mcc; int16_t mnc; diff --git a/src/host/layer23/src/common/networks.c b/src/host/layer23/src/common/networks.c index f35dcb1..63221f0 100644 --- a/src/host/layer23/src/common/networks.c +++ b/src/host/layer23/src/common/networks.c @@ -1857,16 +1857,19 @@ const uint16_t gsm_input_mcc(char *string) uint16_t mcc; if (strlen(string) != 3) - return 0; + return GSM_INPUT_INVALID; if (string[0] < '0' || string [0] > '9' || string[1] < '0' || string [1] > '9' || string[2] < '0' || string [2] > '9') - return 0; + return GSM_INPUT_INVALID; mcc = ((string[0] - '0') << 8) | ((string[1] - '0') << 4) | ((string[2] - '0')); + if (mcc == 0x000) + return GSM_INPUT_INVALID; + return mcc; } @@ -1877,7 +1880,7 @@ const uint16_t gsm_input_mnc(char *string) if (strlen(string) == 2) { if (string[0] < '0' || string [0] > '9' || string[1] < '0' || string [1] > '9') - return 0; + return GSM_INPUT_INVALID; mnc = ((string[0] - '0') << 8) | ((string[1] - '0') << 4) @@ -1887,7 +1890,7 @@ const uint16_t gsm_input_mnc(char *string) if (string[0] < '0' || string [0] > '9' || string[1] < '0' || string [1] > '9' || string[2] < '0' || string [2] > '9') - return 0; + return GSM_INPUT_INVALID; mnc = ((string[0] - '0') << 8) | ((string[1] - '0') << 4) diff --git a/src/host/layer23/src/mobile/vty_interface.c b/src/host/layer23/src/mobile/vty_interface.c index f5ccac3..5fe3441 100644 --- a/src/host/layer23/src/mobile/vty_interface.c +++ b/src/host/layer23/src/mobile/vty_interface.c @@ -391,11 +391,11 @@ DEFUN(show_ba, show_ba_cmd, "show ba MS_NAME [MCC] [MNC]", if (argc >= 3) { mcc = gsm_input_mcc((char *)argv[1]); mnc = gsm_input_mnc((char *)argv[2]); - if (!mcc) { + if (mcc == GSM_INPUT_INVALID) { vty_out(vty, "Given MCC invalid%s", VTY_NEWLINE); return CMD_WARNING; } - if (!mnc) { + if (mnc == GSM_INPUT_INVALID) { vty_out(vty, "Given MNC invalid%s", VTY_NEWLINE); return CMD_WARNING; } @@ -487,11 +487,11 @@ DEFUN(sim_test, sim_test_cmd, "sim testcard MS_NAME [MCC] [MNC] [LAC] [TMSI]", if (argc >= 3) { mcc = gsm_input_mcc((char *)argv[1]); mnc = gsm_input_mnc((char *)argv[2]); - if (!mcc) { + if (mcc == GSM_INPUT_INVALID) { vty_out(vty, "Given MCC invalid%s", VTY_NEWLINE); return CMD_WARNING; } - if (!mnc) { + if (mnc == GSM_INPUT_INVALID) { vty_out(vty, "Given MNC invalid%s", VTY_NEWLINE); return CMD_WARNING; } @@ -674,11 +674,11 @@ DEFUN(sim_lai, sim_lai_cmd, "sim lai MS_NAME MCC MNC LAC", if (!ms) return CMD_WARNING; - if (!mcc) { + if (mcc == GSM_INPUT_INVALID) { vty_out(vty, "Given MCC invalid%s", VTY_NEWLINE); return CMD_WARNING; } - if (!mnc) { + if (mnc == GSM_INPUT_INVALID) { vty_out(vty, "Given MNC invalid%s", VTY_NEWLINE); return CMD_WARNING; } @@ -719,11 +719,11 @@ DEFUN(network_select, network_select_cmd, return CMD_WARNING; } - if (!mcc) { + if (mcc == GSM_INPUT_INVALID) { vty_out(vty, "Given MCC invalid%s", VTY_NEWLINE); return CMD_WARNING; } - if (!mnc) { + if (mnc == GSM_INPUT_INVALID) { vty_out(vty, "Given MNC invalid%s", VTY_NEWLINE); return CMD_WARNING; } @@ -877,11 +877,11 @@ DEFUN(delete_forbidden_plmn, delete_forbidden_plmn_cmd, if (!ms) return CMD_WARNING; - if (!mcc) { + if (mcc == GSM_INPUT_INVALID) { vty_out(vty, "Given MCC invalid%s", VTY_NEWLINE); return CMD_WARNING; } - if (!mnc) { + if (mnc == GSM_INPUT_INVALID) { vty_out(vty, "Given MNC invalid%s", VTY_NEWLINE); return CMD_WARNING; } @@ -2410,11 +2410,11 @@ DEFUN(cfg_test_rplmn, cfg_test_rplmn_cmd, "rplmn MCC MNC [LAC] [TMSI]", uint16_t mcc = gsm_input_mcc((char *)argv[0]), mnc = gsm_input_mnc((char *)argv[1]); - if (!mcc) { + if (mcc == GSM_INPUT_INVALID) { vty_out(vty, "Given MCC invalid%s", VTY_NEWLINE); return CMD_WARNING; } - if (!mnc) { + if (mnc == GSM_INPUT_INVALID) { vty_out(vty, "Given MNC invalid%s", VTY_NEWLINE); return CMD_WARNING; } -- 2.20.1