layer23: rework store & pass of test_sim param to gsm_subscr_testcard() API

This way the gsm_subscr_testcard() API looks similar to that of other
backends (sim, sap). Furthermore, the callers of the API don't need to
pass tons of params. This is important since in the future there will be
more params (eg. gprs related ones), so it makes no sense to keep
increasing the param list in there.

Change-Id: I07fc5a6ed59e65d6b96c0a2f87b1f496d39ad76d
This commit is contained in:
Pau Espin 2023-05-17 12:48:15 +02:00
parent f05ac96fd6
commit 1ad195e28f
5 changed files with 34 additions and 43 deletions

View File

@ -98,8 +98,7 @@ struct gsm_subscriber {
int gsm_subscr_init(struct osmocom_ms *ms);
int gsm_subscr_exit(struct osmocom_ms *ms);
int gsm_subscr_testcard(struct osmocom_ms *ms, uint16_t mcc, uint16_t mnc,
uint16_t lac, uint32_t tmsi, uint8_t imsi_attached);
int gsm_subscr_testcard(struct osmocom_ms *ms);
int gsm_subscr_sap_rsp_cb(struct osmocom_ms *ms, int res_code,
uint8_t res_type, uint16_t param_len, const uint8_t *param_val);
int gsm_subscr_sapcard(struct osmocom_ms *ms);

View File

@ -136,8 +136,7 @@ int gsm_subscr_exit(struct osmocom_ms *ms)
*/
/* Attach test card, no SIM must be currently attached */
int gsm_subscr_testcard(struct osmocom_ms *ms, uint16_t mcc, uint16_t mnc,
uint16_t lac, uint32_t tmsi, uint8_t imsi_attached)
int gsm_subscr_testcard(struct osmocom_ms *ms)
{
struct gsm_settings *set = &ms->settings;
struct gsm_subscriber *subscr = &ms->subscr;
@ -160,34 +159,35 @@ int gsm_subscr_testcard(struct osmocom_ms *ms, uint16_t mcc, uint16_t mnc,
subscr->sim_type = GSM_SIM_TYPE_TEST;
sprintf(subscr->sim_name, "test");
subscr->sim_valid = 1;
if (imsi_attached && set->test_sim.rplmn_valid) {
subscr->imsi_attached = imsi_attached;
subscr->ustate = GSM_SIM_U1_UPDATED;
} else
subscr->ustate = GSM_SIM_U2_NOT_UPDATED;
subscr->imsi_attached = set->test_sim.imsi_attached;
subscr->acc_barr = set->test_sim.barr; /* we may access barred cell */
subscr->acc_class = 0xffff; /* we have any access class */
subscr->plmn_valid = set->test_sim.rplmn_valid;
subscr->plmn_mcc = mcc;
subscr->plmn_mnc = mnc;
subscr->mcc = mcc;
subscr->mnc = mnc;
subscr->lac = lac;
subscr->tmsi = tmsi;
subscr->plmn_mcc = set->test_sim.rplmn_mcc;
subscr->plmn_mnc = set->test_sim.rplmn_mnc;
subscr->mcc = set->test_sim.rplmn_mcc;
subscr->mnc = set->test_sim.rplmn_mnc;
subscr->lac = set->test_sim.lac;
subscr->tmsi = set->test_sim.tmsi;
subscr->ptmsi = GSM_RESERVED_TMSI;
subscr->always_search_hplmn = set->test_sim.always;
subscr->t6m_hplmn = 1; /* try to find home network every 6 min */
OSMO_STRLCPY_ARRAY(subscr->imsi, set->test_sim.imsi);
if (subscr->imsi_attached && subscr->plmn_valid)
subscr->ustate = GSM_SIM_U1_UPDATED;
else
subscr->ustate = GSM_SIM_U2_NOT_UPDATED;
LOGP(DMM, LOGL_INFO, "(ms %s) Inserting test card (IMSI=%s %s, %s)\n",
ms->name, subscr->imsi, gsm_imsi_mcc(subscr->imsi),
gsm_imsi_mnc(subscr->imsi));
if (subscr->plmn_valid)
LOGP(DMM, LOGL_INFO, "-> Test card registered to %s %s 0x%04x"
"(%s, %s)\n", gsm_print_mcc(mcc),
gsm_print_mnc(mnc), lac, gsm_get_mcc(mcc),
gsm_get_mnc(mcc, mnc));
"(%s, %s)\n", gsm_print_mcc(subscr->mcc),
gsm_print_mnc(subscr->mnc), subscr->lac, gsm_get_mcc(subscr->mcc),
gsm_get_mnc(subscr->mcc, subscr->mnc));
else
LOGP(DMM, LOGL_INFO, "-> Test card not registered\n");
if (subscr->imsi_attached)

View File

@ -485,10 +485,6 @@ static int _sim_test_cmd(struct vty *vty, int argc, const char *argv[],
struct gsm_settings *set;
int rc;
/* Initial testcard settings */
uint16_t mcc = 0x001, mnc = 0x01f, lac = 0x0000;
uint32_t tmsi = GSM_RESERVED_TMSI;
ms = l23_vty_get_ms(argv[0], vty);
if (!ms)
return CMD_WARNING;
@ -500,24 +496,14 @@ static int _sim_test_cmd(struct vty *vty, int argc, const char *argv[],
}
set = &ms->settings;
if (set->test_sim.rplmn_valid) {
mcc = set->test_sim.rplmn_mcc;
mnc = set->test_sim.rplmn_mnc;
if (set->test_sim.lac > 0x0000 && set->test_sim.lac < 0xfffe)
lac = set->test_sim.lac;
if (set->test_sim.tmsi != GSM_RESERVED_TMSI)
tmsi = set->test_sim.tmsi;
}
if (argc == 2) {
vty_out(vty, "Give MNC together with MCC%s", VTY_NEWLINE);
return CMD_WARNING;
}
if (argc >= 3) {
mcc = gsm_input_mcc((char *)argv[1]);
mnc = gsm_input_mnc((char *)argv[2]);
uint16_t mcc = gsm_input_mcc((char *)argv[1]);
uint16_t mnc = gsm_input_mnc((char *)argv[2]);
if (mcc == GSM_INPUT_INVALID) {
vty_out(vty, "Given MCC invalid%s", VTY_NEWLINE);
return CMD_WARNING;
@ -526,15 +512,22 @@ static int _sim_test_cmd(struct vty *vty, int argc, const char *argv[],
vty_out(vty, "Given MNC invalid%s", VTY_NEWLINE);
return CMD_WARNING;
}
set->test_sim.rplmn_mcc = mcc;
set->test_sim.rplmn_mnc = mnc;
set->test_sim.rplmn_valid = 1;
} else {
set->test_sim.rplmn_valid = 0;
}
if (argc >= 4)
lac = strtoul(argv[3], NULL, 16);
set->test_sim.lac = strtoul(argv[3], NULL, 16);
if (argc >= 5)
tmsi = strtoul(argv[4], NULL, 16);
set->test_sim.tmsi = strtoul(argv[4], NULL, 16);
rc = gsm_subscr_testcard(ms, mcc, mnc, lac, tmsi, attached);
set->test_sim.imsi_attached = attached;
rc = gsm_subscr_testcard(ms);
if (rc < 0) {
vty_out(vty, "Attach test SIM card failed: %d%s", rc, VTY_NEWLINE);
return CMD_WARNING;
@ -1047,6 +1040,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.lac = 0x0000;
set->test_sim.tmsi = GSM_RESERVED_TMSI;
l23_vty_restart_required_warn(vty, ms);

View File

@ -167,9 +167,7 @@ static int mobile_signal_cb(unsigned int subsys, unsigned int signal,
gsm_subscr_simcard(ms);
break;
case GSM_SIM_TYPE_TEST:
gsm_subscr_testcard(ms, set->test_sim.rplmn_mcc,
set->test_sim.rplmn_mnc, set->test_sim.lac,
set->test_sim.tmsi, set->test_sim.imsi_attached);
gsm_subscr_testcard(ms);
break;
case GSM_SIM_TYPE_SAP:
gsm_subscr_sapcard(ms);

View File

@ -213,9 +213,7 @@ static int global_signal_cb(unsigned int subsys, unsigned int signal,
gsm_subscr_simcard(ms);
break;
case GSM_SIM_TYPE_TEST:
gsm_subscr_testcard(ms, set->test_sim.rplmn_mcc,
set->test_sim.rplmn_mnc, set->test_sim.lac,
set->test_sim.tmsi, set->test_sim.imsi_attached);
gsm_subscr_testcard(ms);
break;
case GSM_SIM_TYPE_SAP:
gsm_subscr_sapcard(ms);