diff options
author | Pau Espin Pedrol <pespin@sysmocom.de> | 2023-05-17 15:29:35 +0200 |
---|---|---|
committer | Pau Espin Pedrol <pespin@sysmocom.de> | 2023-05-19 13:56:58 +0200 |
commit | 7b53ad536c6c4fd8cbea4ae0f6f1a5716b72108b (patch) | |
tree | 878f189e7ca85185c346b3bec17baf384a80a6bf | |
parent | 8be5119702ac8cedc9691badbe71972d0aa4a155 (diff) |
layer23: Generalize subscriber SIM insert API
With this patch, during VTY config the SIM type is selected, and the app
calls a generic gsm_subscriber_insert() API which will take of
internally initializing and starting whatever specific-backend setup is
needed.
Change-Id: I5aa34ae297ec0114e1d2355d59fdd77b43b35464
-rw-r--r-- | src/host/layer23/include/osmocom/bb/common/settings.h | 3 | ||||
-rw-r--r-- | src/host/layer23/include/osmocom/bb/common/subscriber.h | 13 | ||||
-rw-r--r-- | src/host/layer23/src/common/subscriber.c | 83 | ||||
-rw-r--r-- | src/host/layer23/src/common/vty.c | 13 | ||||
-rw-r--r-- | src/host/layer23/src/mobile/app_mobile.c | 19 | ||||
-rw-r--r-- | src/host/layer23/src/modem/app_modem.c | 19 |
6 files changed, 73 insertions, 77 deletions
diff --git a/src/host/layer23/include/osmocom/bb/common/settings.h b/src/host/layer23/include/osmocom/bb/common/settings.h index 01db2a79..e312a1c1 100644 --- a/src/host/layer23/include/osmocom/bb/common/settings.h +++ b/src/host/layer23/include/osmocom/bb/common/settings.h @@ -90,7 +90,8 @@ struct gsm_settings { int plmn_mode; /* PLMN_MODE_* */ /* SIM */ - int sim_type; /* selects card on power on */ + int sim_type; /* enum gsm_subscriber_sim_type, + * selects card on power on */ char emergency_imsi[OSMO_IMSI_BUF_SIZE]; /* SMS */ diff --git a/src/host/layer23/include/osmocom/bb/common/subscriber.h b/src/host/layer23/include/osmocom/bb/common/subscriber.h index 8f0966ef..81191037 100644 --- a/src/host/layer23/include/osmocom/bb/common/subscriber.h +++ b/src/host/layer23/include/osmocom/bb/common/subscriber.h @@ -32,7 +32,7 @@ struct gsm_sub_plmn_na { #define GSM_SIM_IS_READER(type) \ (type == GSM_SIM_TYPE_L1PHY || type == GSM_SIM_TYPE_SAP) -enum { +enum gsm_subscriber_sim_type { GSM_SIM_TYPE_NONE = 0, GSM_SIM_TYPE_L1PHY, GSM_SIM_TYPE_TEST, @@ -43,8 +43,8 @@ struct gsm_subscriber { struct osmocom_ms *ms; /* status */ - uint8_t sim_type; /* type of sim */ - uint8_t sim_valid; /* sim inserted and valid */ + enum gsm_subscriber_sim_type sim_type; /* type of sim */ + bool sim_valid; /* sim inserted and valid */ enum gsm_sub_sim_ustate ustate; /* update status */ uint8_t imsi_attached; /* attached state */ @@ -98,17 +98,16 @@ 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); +int gsm_subscr_insert(struct osmocom_ms *ms); +int gsm_subscr_remove(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); -int gsm_subscr_simcard(struct osmocom_ms *ms); void gsm_subscr_sim_pin(struct osmocom_ms *ms, char *pin1, char *pin2, int8_t mode); int gsm_subscr_write_loci(struct osmocom_ms *ms); int gsm_subscr_generate_kc(struct osmocom_ms *ms, uint8_t key_seq, uint8_t *rand, uint8_t no_sim); -int gsm_subscr_remove(struct osmocom_ms *ms); void new_sim_ustate(struct gsm_subscriber *subscr, int state); int gsm_subscr_del_forbidden_plmn(struct gsm_subscriber *subscr, uint16_t mcc, uint16_t mnc); diff --git a/src/host/layer23/src/common/subscriber.c b/src/host/layer23/src/common/subscriber.c index e284c9c0..b6237420 100644 --- a/src/host/layer23/src/common/subscriber.c +++ b/src/host/layer23/src/common/subscriber.c @@ -45,6 +45,10 @@ const struct value_string gsm_sub_sim_ustate_names[] = { { 0, NULL } }; +static int gsm_subscr_insert_simcard(struct osmocom_ms *ms); +static int gsm_subscr_insert_testcard(struct osmocom_ms *ms); +static int gsm_subscr_insert_sapcard(struct osmocom_ms *ms); + static int gsm_subscr_remove_sapcard(struct osmocom_ms *ms); static void subscr_sim_query_cb(struct osmocom_ms *ms, struct msgb *msg); @@ -141,6 +145,46 @@ int gsm_subscr_exit(struct osmocom_ms *ms) return 0; } +/* Insert card */ +int gsm_subscr_insert(struct osmocom_ms *ms) +{ + struct gsm_settings *set = &ms->settings; + struct gsm_subscriber *subscr = &ms->subscr; + int rc; + + if (subscr->sim_valid) { + LOGP(DMM, LOGL_ERROR, "Cannot insert card, until current card is removed.\n"); + return -EBUSY; + } + + /* reset subscriber */ + gsm_subscr_exit(ms); + gsm_subscr_init(ms); + + subscr->sim_valid = true; + + switch (set->sim_type) { + case GSM_SIM_TYPE_L1PHY: + /* trigger sim card reader process */ + rc = gsm_subscr_insert_simcard(ms); + break; + case GSM_SIM_TYPE_TEST: + rc = gsm_subscr_insert_testcard(ms); + break; + case GSM_SIM_TYPE_SAP: + rc = gsm_subscr_insert_sapcard(ms); + break; + default: + return -EINVAL; + } + + if (rc < 0) { + subscr->sim_valid = false; + return rc; + } + return rc; +} + /* Detach card */ int gsm_subscr_remove(struct osmocom_ms *ms) { @@ -175,29 +219,18 @@ void new_sim_ustate(struct gsm_subscriber *subscr, int state) */ /* Attach test card, no SIM must be currently attached */ -int gsm_subscr_testcard(struct osmocom_ms *ms) +int gsm_subscr_insert_testcard(struct osmocom_ms *ms) { struct gsm_settings *set = &ms->settings; struct gsm_subscriber *subscr = &ms->subscr; - if (subscr->sim_valid) { - LOGP(DMM, LOGL_ERROR, "Cannot insert card, until current card " - "is detached.\n"); - return -EBUSY; - } - if (!osmo_imsi_str_valid(set->test_sim.imsi)) { LOGP(DMM, LOGL_ERROR, "Wrong IMSI format\n"); return -EINVAL; } - /* reset subscriber */ - gsm_subscr_exit(ms); - gsm_subscr_init(ms); - subscr->sim_type = GSM_SIM_TYPE_TEST; sprintf(subscr->sim_name, "test"); - subscr->sim_valid = 1; 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 */ @@ -762,23 +795,12 @@ void gsm_subscr_sim_pin(struct osmocom_ms *ms, char *pin1, char *pin2, } /* Attach SIM reader, no SIM must be currently attached */ -int gsm_subscr_simcard(struct osmocom_ms *ms) +int gsm_subscr_insert_simcard(struct osmocom_ms *ms) { struct gsm_subscriber *subscr = &ms->subscr; - if (subscr->sim_valid) { - LOGP(DMM, LOGL_ERROR, "Cannot attach card, until current card " - "is detached.\n"); - return -EBUSY; - } - - /* reset subscriber */ - gsm_subscr_exit(ms); - gsm_subscr_init(ms); - subscr->sim_type = GSM_SIM_TYPE_L1PHY; sprintf(subscr->sim_name, "sim"); - subscr->sim_valid = 1; subscr->ustate = GSM_SIM_U2_NOT_UPDATED; /* start with first index */ @@ -1215,24 +1237,13 @@ void gsm_subscr_dump(struct gsm_subscriber *subscr, */ /* Attach SIM card over SAP */ -int gsm_subscr_sapcard(struct osmocom_ms *ms) +int gsm_subscr_insert_sapcard(struct osmocom_ms *ms) { struct gsm_subscriber *subscr = &ms->subscr; int rc; - if (subscr->sim_valid) { - LOGP(DMM, LOGL_ERROR, "Cannot insert card, until current card " - "is detached.\n"); - return -EBUSY; - } - - /* reset subscriber */ - gsm_subscr_exit(ms); - gsm_subscr_init(ms); - subscr->sim_type = GSM_SIM_TYPE_SAP; sprintf(subscr->sim_name, "sap"); - subscr->sim_valid = 1; /* Try to connect to the SAP interface */ l23_vty_ms_notify(ms, NULL); diff --git a/src/host/layer23/src/common/vty.c b/src/host/layer23/src/common/vty.c index 56ff6bcd..427c8aa3 100644 --- a/src/host/layer23/src/common/vty.c +++ b/src/host/layer23/src/common/vty.c @@ -496,6 +496,7 @@ static int _sim_test_cmd(struct vty *vty, int argc, const char *argv[], } set = &ms->settings; + set->sim_type = GSM_SIM_TYPE_TEST; if (argc == 2) { vty_out(vty, "Give MNC together with MCC%s", VTY_NEWLINE); @@ -527,7 +528,7 @@ static int _sim_test_cmd(struct vty *vty, int argc, const char *argv[], set->test_sim.imsi_attached = attached; - rc = gsm_subscr_testcard(ms); + rc = gsm_subscr_insert(ms); if (rc < 0) { vty_out(vty, "Attach test SIM card failed: %d%s", rc, VTY_NEWLINE); return CMD_WARNING; @@ -562,6 +563,7 @@ DEFUN(sim_sap, sim_sap_cmd, "sim sap MS_NAME", "Name of MS (see \"show ms\")\n") { struct osmocom_ms *ms; + struct gsm_settings *set; ms = l23_vty_get_ms(argv[0], vty); if (!ms) @@ -573,7 +575,9 @@ DEFUN(sim_sap, sim_sap_cmd, "sim sap MS_NAME", return CMD_WARNING; } - if (gsm_subscr_sapcard(ms) != 0) + set = &ms->settings; + set->sim_type = GSM_SIM_TYPE_SAP; + if (gsm_subscr_insert(ms) != 0) return CMD_WARNING; return CMD_SUCCESS; @@ -583,6 +587,7 @@ DEFUN(sim_reader, sim_reader_cmd, "sim reader MS_NAME", "SIM actions\nAttach SIM from reader\nName of MS (see \"show ms\")") { struct osmocom_ms *ms; + struct gsm_settings *set; ms = l23_vty_get_ms(argv[0], vty); if (!ms) @@ -594,7 +599,9 @@ DEFUN(sim_reader, sim_reader_cmd, "sim reader MS_NAME", return CMD_WARNING; } - gsm_subscr_simcard(ms); + set = &ms->settings; + set->sim_type = GSM_SIM_TYPE_L1PHY; + gsm_subscr_insert(ms); return CMD_SUCCESS; } diff --git a/src/host/layer23/src/mobile/app_mobile.c b/src/host/layer23/src/mobile/app_mobile.c index 76f11f38..9ce1ad2b 100644 --- a/src/host/layer23/src/mobile/app_mobile.c +++ b/src/host/layer23/src/mobile/app_mobile.c @@ -139,7 +139,6 @@ static int mobile_signal_cb(unsigned int subsys, unsigned int signal, void *handler_data, void *signal_data) { struct osmocom_ms *ms; - struct gsm_settings *set; struct msgb *nmsg; if (subsys != SS_L1CTL) @@ -148,7 +147,6 @@ static int mobile_signal_cb(unsigned int subsys, unsigned int signal, switch (signal) { case S_L1CTL_RESET: ms = signal_data; - set = &ms->settings; /* waiting for reset after shutdown */ if (ms->shutdown == MS_SHUTDOWN_WAIT_RESET) { @@ -160,19 +158,10 @@ static int mobile_signal_cb(unsigned int subsys, unsigned int signal, if (ms->started) break; - /* insert test card, if enabled */ - switch (set->sim_type) { - case GSM_SIM_TYPE_L1PHY: - /* trigger sim card reader process */ - gsm_subscr_simcard(ms); - break; - case GSM_SIM_TYPE_TEST: - gsm_subscr_testcard(ms); - break; - case GSM_SIM_TYPE_SAP: - gsm_subscr_sapcard(ms); - break; - default: + if (ms->settings.sim_type != GSM_SIM_TYPE_NONE) { + /* insert sim card */ + gsm_subscr_insert(ms); + } else { /* no SIM, trigger PLMN selection process */ nmsg = gsm322_msgb_alloc(GSM322_EVENT_SWITCH_ON); if (!nmsg) diff --git a/src/host/layer23/src/modem/app_modem.c b/src/host/layer23/src/modem/app_modem.c index 211a008c..fdb38212 100644 --- a/src/host/layer23/src/modem/app_modem.c +++ b/src/host/layer23/src/modem/app_modem.c @@ -194,7 +194,6 @@ static int global_signal_cb(unsigned int subsys, unsigned int signal, void *handler_data, void *signal_data) { struct osmocom_ms *ms; - struct gsm_settings *set; if (subsys != SS_L1CTL) return 0; @@ -206,24 +205,14 @@ static int global_signal_cb(unsigned int subsys, unsigned int signal, app_data.ms = ms; /* insert test card, if enabled */ - set = &ms->settings; - switch (set->sim_type) { - case GSM_SIM_TYPE_L1PHY: - /* trigger sim card reader process */ - gsm_subscr_simcard(ms); - break; - case GSM_SIM_TYPE_TEST: - gsm_subscr_testcard(ms); - break; - case GSM_SIM_TYPE_SAP: - gsm_subscr_sapcard(ms); - break; - default: + if (ms->settings.sim_type != GSM_SIM_TYPE_NONE) { + /* insert sim card */ + gsm_subscr_insert(ms); + } else { /* No SIM, trigger PLMN selection process. * FIXME: not implemented. Code in mobile needs to be * moved to common/ and reuse it here. */ - break; } ms->started = true; |