summaryrefslogtreecommitdiffstats
path: root/src/host/layer23/src/common/vty.c
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2023-05-18 18:51:03 +0200
committerPau Espin Pedrol <pespin@sysmocom.de>2023-05-22 16:12:04 +0200
commit3348f491792788974c6bb3ee75f3a4f1d159aef9 (patch)
tree815af8fd65748bb4792edf2a6cebeec52a2a428c /src/host/layer23/src/common/vty.c
parent554e7cfb56ff61e83c7321b7737baf4476bf8280 (diff)
Migrate network identifier fields to modern osmocom structures
This allows using well tested standarized API to print, compare, etc. usual identifiers like PLMN, LAI, etc. It also simplifies code by avoiding passing lots of parameters and making it easier to identify which fields go packed together. This is specially important since in the future more of those identifiers will be added for GPRS. Change-Id: I07a9289825c09ed748e53d36a746ea164c8a5d7f
Diffstat (limited to 'src/host/layer23/src/common/vty.c')
-rw-r--r--src/host/layer23/src/common/vty.c44
1 files changed, 21 insertions, 23 deletions
diff --git a/src/host/layer23/src/common/vty.c b/src/host/layer23/src/common/vty.c
index 427c8aa3..424efb22 100644
--- a/src/host/layer23/src/common/vty.c
+++ b/src/host/layer23/src/common/vty.c
@@ -503,18 +503,16 @@ static int _sim_test_cmd(struct vty *vty, int argc, const char *argv[],
return CMD_WARNING;
}
if (argc >= 3) {
- uint16_t mcc = gsm_input_mcc((char *)argv[1]);
- uint16_t mnc = gsm_input_mnc((char *)argv[2]);
- if (mcc == GSM_INPUT_INVALID) {
+ struct osmo_plmn_id plmn;
+ if (osmo_mcc_from_str(argv[1], &plmn.mcc) < 0) {
vty_out(vty, "Given MCC invalid%s", VTY_NEWLINE);
return CMD_WARNING;
}
- if (mnc == GSM_INPUT_INVALID) {
+ if (osmo_mnc_from_str(argv[2], &plmn.mnc, &plmn.mnc_3_digits) < 0) {
vty_out(vty, "Given MNC invalid%s", VTY_NEWLINE);
return CMD_WARNING;
}
- set->test_sim.rplmn_mcc = mcc;
- set->test_sim.rplmn_mnc = mnc;
+ memcpy(&set->test_sim.rplmn, &plmn, sizeof(plmn));
set->test_sim.rplmn_valid = 1;
} else {
set->test_sim.rplmn_valid = 0;
@@ -743,26 +741,26 @@ DEFUN(sim_lai, sim_lai_cmd, "sim lai MS_NAME MCC MNC LAC",
" (use 0000 to remove LAI)")
{
struct osmocom_ms *ms;
- uint16_t mcc = gsm_input_mcc((char *)argv[1]),
- mnc = gsm_input_mnc((char *)argv[2]),
- lac = strtoul(argv[3], NULL, 16);
+ struct osmo_plmn_id plmn;
+ uint16_t lac;
ms = l23_vty_get_ms(argv[0], vty);
if (!ms)
return CMD_WARNING;
- if (mcc == GSM_INPUT_INVALID) {
+ if (osmo_mcc_from_str(argv[1], &plmn.mcc) < 0) {
vty_out(vty, "Given MCC invalid%s", VTY_NEWLINE);
return CMD_WARNING;
}
- if (mnc == GSM_INPUT_INVALID) {
+ if (osmo_mnc_from_str(argv[2], &plmn.mnc, &plmn.mnc_3_digits) < 0) {
vty_out(vty, "Given MNC invalid%s", VTY_NEWLINE);
return CMD_WARNING;
}
- ms->subscr.mcc = mcc;
- ms->subscr.mnc = mnc;
- ms->subscr.lac = lac;
+ lac = strtoul(argv[3], NULL, 0);
+
+ memcpy(&ms->subscr.lai.plmn, &plmn, sizeof(plmn));
+ ms->subscr.lai.lac = lac;
ms->subscr.tmsi = GSM_RESERVED_TMSI;
gsm_subscr_write_loci(ms);
@@ -1044,7 +1042,9 @@ DEFUN(cfg_test_no_rplmn, cfg_test_no_rplmn_cmd, "no rplmn",
struct gsm_settings *set = &ms->settings;
set->test_sim.rplmn_valid = 0;
- set->test_sim.rplmn_mcc = set->test_sim.rplmn_mnc = 1;
+ set->test_sim.rplmn.mcc = 1;
+ set->test_sim.rplmn.mnc = 1;
+ set->test_sim.rplmn.mnc_3_digits = false;
set->test_sim.lac = 0x0000;
set->test_sim.tmsi = GSM_RESERVED_TMSI;
@@ -1058,20 +1058,18 @@ static int _test_rplmn_cmd(struct vty *vty, int argc, const char *argv[],
{
struct osmocom_ms *ms = vty->index;
struct gsm_settings *set = &ms->settings;
- uint16_t mcc = gsm_input_mcc((char *)argv[0]),
- mnc = gsm_input_mnc((char *)argv[1]);
+ struct osmo_plmn_id plmn;
- if (mcc == GSM_INPUT_INVALID) {
+ if (osmo_mcc_from_str(argv[0], &plmn.mcc) < 0) {
vty_out(vty, "Given MCC invalid%s", VTY_NEWLINE);
return CMD_WARNING;
}
- if (mnc == GSM_INPUT_INVALID) {
+ if (osmo_mnc_from_str(argv[1], &plmn.mnc, &plmn.mnc_3_digits) < 0) {
vty_out(vty, "Given MNC invalid%s", VTY_NEWLINE);
return CMD_WARNING;
}
set->test_sim.rplmn_valid = 1;
- set->test_sim.rplmn_mcc = mcc;
- set->test_sim.rplmn_mnc = mnc;
+ memcpy(&set->test_sim.rplmn, &plmn, sizeof(plmn));
if (argc >= 3)
set->test_sim.lac = strtoul(argv[2], NULL, 16);
@@ -1205,8 +1203,8 @@ static int l23_vty_config_write_testsim_node(struct vty *vty, const struct osmoc
(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_sim.rplmn_mcc),
- gsm_print_mnc(set->test_sim.rplmn_mnc));
+ osmo_mcc_name(set->test_sim.rplmn.mcc),
+ osmo_mnc_name(set->test_sim.rplmn.mnc, set->test_sim.rplmn.mnc_3_digits));
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) {