b/src/host/layer23/include/osmocom/bb/common/sap_interface.h
@@ -11,6 +11,7 @@ int osmosap_sapsocket(struct osmocom_ms *ms, const char
*path);
int osmosap_init(struct osmocom_ms *ms);
enum osmosap_state {
+ SAP_SOCKET_ERROR,
SAP_NOT_CONNECTED,
SAP_IDLE,
SAP_CONNECTION_UNDER_NEGOTIATION,
b/src/host/layer23/include/osmocom/bb/mobile/subscriber.h
@@ -23,7 +23,8 @@ struct gsm_sub_plmn_na {
enum {
GSM_SIM_TYPE_NONE = 0,
GSM_SIM_TYPE_READER,
- GSM_SIM_TYPE_TEST
+ GSM_SIM_TYPE_TEST,
+ GSM_SIM_TYPE_SAP
};
struct gsm_subscriber {
@@ -86,6 +87,8 @@ 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_sapcard(struct osmocom_ms *ms);
+int gsm_subscr_remove_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);
b/src/host/layer23/src/common/sap_interface.c
@@ -515,7 +515,7 @@ int sap_open(struct osmocom_ms *ms, const char
*socket_path)
rc = connect(ms->sap_wq.bfd.fd, (struct sockaddr *) &local,
sizeof(local));
if (rc < 0) {
fprintf(stderr, "Failed to connect to '%s'\n", local.sun_path);
- set->sap_socket_path[0] = 0;
+ ms->sap_entity.sap_state = SAP_SOCKET_ERROR;
close(ms->sap_wq.bfd.fd);
return rc;
}
@@ -582,22 +582,11 @@ int osmosap_sapsocket(struct osmocom_ms *ms, const
char *path)
int osmosap_init(struct osmocom_ms *ms)
{
struct osmosap_entity *sap = &ms->sap_entity;
- int rc;
+ LOGP(DSAP, LOGL_INFO, "init SAP client\n");
sap->sap_state = SAP_NOT_CONNECTED;
sap->max_msg_size = GSM_SAP_LENGTH;
- LOGP(DSAP, LOGL_INFO, "init SAP client\n");
-
- if(ms->settings.sap_socket_path){
- rc = sap_open(ms, ms->settings.sap_socket_path);
- if (rc < 0) {
- fprintf(stderr, "Failed during sap_open(), no SAP based SIM
reader\n");
- ms->sap_wq.bfd.fd = -1;
- return rc;
- }
- }
-
return 0;
}
b/src/host/layer23/src/common/sim.c
@@ -188,12 +188,12 @@ static int sim_apdu_send(struct osmocom_ms *ms,
uint8_t *data, uint16_t length)
/* adding SAP client support
* it makes more sense to do it here then in L1CTL */
- if(ms->settings.sap_socket_path[0] == 0) {
- LOGP(DSIM, LOGL_INFO, "Using built-in SIM reader\n");
- l1ctl_tx_sim_req(ms, data, length);
- } else {
+ if (ms->subscr.sim_type == GSM_SIM_TYPE_SAP) {
LOGP(DSIM, LOGL_INFO, "Using SAP backend\n");
osmosap_send_apdu(ms, data, length);
+ } else {
+ LOGP(DSIM, LOGL_INFO, "Using built-in SIM reader\n");
+ l1ctl_tx_sim_req(ms, data, length);
}
return 0;
b/src/host/layer23/src/mobile/app_mobile.c
@@ -115,6 +115,9 @@ int mobile_signal_cb(unsigned int subsys, unsigned int
signal,
set->test_rplmn_mnc, set->test_lac,
set->test_tmsi, set->test_imsi_attached);
break;
+ case GSM_SIM_TYPE_SAP:
+ gsm_subscr_sapcard(ms);
+ break;
default:
/* no SIM, trigger PLMN selection process */
nmsg = gsm322_msgb_alloc(GSM322_EVENT_SWITCH_ON);
b/src/host/layer23/src/mobile/subscriber.c
@@ -28,6 +28,7 @@
#include <osmocom/bb/common/logging.h>
#include <osmocom/bb/common/osmocom_data.h>
+#include <osmocom/bb/common/sap_interface.h>
#include <osmocom/bb/common/networks.h>
#include <osmocom/bb/mobile/vty.h>
@@ -1256,3 +1257,55 @@ void gsm_subscr_dump(struct gsm_subscriber *subscr,
}
}
+/*
+ * SAP interface integration
+ */
+
+/* Attach SIM card over SAP */
+int gsm_subscr_sapcard(struct osmocom_ms *ms)
+{
+ struct gsm_subscriber *subscr = &ms->subscr;
+ struct msgb *nmsg;
+ 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 */
+ vty_notify(ms, NULL);
+ vty_notify(ms, "Connecting to the SAP interface...\n");
+ rc = sap_open(ms, ms->settings.sap_socket_path);
+ if (rc < 0) {
+ LOGP(DSAP, LOGL_ERROR, "Failed during sap_open(), no SAP based SIM
reader\n");
+ vty_notify(ms, "SAP connection error!\n");
+ ms->sap_wq.bfd.fd = -1;
+
+ /* Detach SIM */
+ subscr->sim_valid = 0;
+ nmsg = gsm48_mmr_msgb_alloc(GSM48_MMR_NREG_REQ);
+ if (!nmsg)
+ return -ENOMEM;
+ gsm48_mmr_downmsg(ms, nmsg);
+
+ return rc;
+ }
+
+ return 0;
+}
+
+/* Deattach sapcard */
+int gsm_subscr_remove_sapcard(struct osmocom_ms *ms)
+{
+ return sap_close(ms);
+}
b/src/host/layer23/src/mobile/vty_interface.c
@@ -534,6 +534,29 @@ DEFUN(sim_test_att, sim_test_att_cmd,
return _sim_test_cmd(vty, argc, argv, 1);
}
+DEFUN(sim_sap, sim_sap_cmd, "sim sap MS_NAME",
+ "SIM actions\nAttach SIM over SAP interface\n"
+ "Name of MS (see \"show ms\")\n")
+{
+ struct osmocom_ms *ms;
+
+ ms = get_ms(argv[0], vty);
+ if (!ms)
+ return CMD_WARNING;
+
+ if (ms->subscr.sim_valid) {
+ vty_out(vty, "SIM already attached, remove first!%s",
+ VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ if (gsm_subscr_sapcard(ms) != 0) {
+ return CMD_WARNING;
+ }
+
+ return CMD_SUCCESS;
+}
+
DEFUN(sim_reader, sim_reader_cmd, "sim reader MS_NAME",
"SIM actions\nAttach SIM from reader\nName of MS (see \"show ms\")")
{
@@ -568,8 +591,11 @@ DEFUN(sim_remove, sim_remove_cmd, "sim remove MS_NAME",
return CMD_WARNING;
}
- gsm_subscr_remove(ms);
+ if (ms->subscr.sim_type == GSM_SIM_TYPE_SAP) {
+ gsm_subscr_remove_sapcard(ms);
+ }
+ gsm_subscr_remove(ms);
return CMD_SUCCESS;
}
@@ -1067,7 +1093,7 @@ DEFUN(cfg_no_gps_enable, cfg_no_gps_enable_cmd, "no
gps enable",
}
#ifdef _HAVE_GPSD
-DEFUN(cfg_gps_host, cfg_gps_host_cmd, "gps host HOST:PORT",
+DEFUN(cfg_gpsd_host, cfg_gpsd_host_cmd, "gpsd host HOST:PORT",
"GPS receiver\nSelect gpsd host and port\n"
"IP and port (optional) of the host running gpsd")