From patchwork Sun Jan 10 13:14:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Vadim Yanitskiy X-Patchwork-Id: 565368 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.osmocom.org (tmp.osmocom.org [144.76.43.76]) by ozlabs.org (Postfix) with ESMTP id C8E371402BC for ; Mon, 11 Jan 2016 00:14:57 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=iVUrMP1i; dkim-atps=neutral Received: from lists.osmocom.org (lists.osmocom.org [144.76.43.76]) by lists.osmocom.org (Postfix) with ESMTP id 77487AFE7; Sun, 10 Jan 2016 13:14:55 +0000 (UTC) X-Original-To: baseband-devel@lists.osmocom.org Delivered-To: baseband-devel@lists.osmocom.org Received: from mail-lb0-x241.google.com (mail-lb0-x241.google.com [IPv6:2a00:1450:4010:c04::241]) by lists.osmocom.org (Postfix) with ESMTP id 8AD3EAFCD for ; Sun, 10 Jan 2016 13:14:48 +0000 (UTC) Received: by mail-lb0-x241.google.com with SMTP id tz10so23588284lbb.2 for ; Sun, 10 Jan 2016 05:14:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=xu3rTggcYjHdxM/yxvEyQcCffXo448PnTGeKW9VxxaM=; b=iVUrMP1iJb8u4Gzhy0c6pQwWjyO1f1+6BZ/34bi2t48Q8yjkZOC1YZ0L0tGm2f0v2/ RngM3bgX8phqodVnuAvBNr37SRsLHt0oYeF95QFjbH4UUfu7Vo7Xa3lD3nh7cmIrgCy4 H+V3Md+PuC+VtKi/yL+VNlaRm3wjLinPQST9zpJtY82+8KadrlhIZR8Ezk+j79KJxq31 ifj95Eb+7TjgZzIrh59dA2Dp9yGNs1mT9EnDXQKc7GlVQ4JYmoOW2LJpAhTc+qlmJYod 3Re0aH8PLuWFYfKyiM5zyX6pYCozBWODkdlyhlRGrLl7gP6XWbpvqQkngWyMJIkvORqZ ViPw== X-Received: by 10.112.143.163 with SMTP id sf3mr7764656lbb.117.1452431687848; Sun, 10 Jan 2016 05:14:47 -0800 (PST) Received: from DELL.lan ([212.164.216.34]) by smtp.gmail.com with ESMTPSA id 34sm14306903lfs.25.2016.01.10.05.14.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 10 Jan 2016 05:14:47 -0800 (PST) From: Vadim Yanitskiy To: baseband-devel@lists.osmocom.org Subject: [PATCH 2/2] host/mobile: Improved SAP interface integration Date: Sun, 10 Jan 2016 19:14:18 +0600 Message-Id: <1452431658-13570-2-git-send-email-axilirator@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1452431658-13570-1-git-send-email-axilirator@gmail.com> References: <1452431658-13570-1-git-send-email-axilirator@gmail.com> MIME-Version: 1.0 X-BeenThere: baseband-devel@lists.osmocom.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: OsmocomBB - open source GSM baseband firmware List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?=D0=AF=D0=BD=D0=B8=D1=86=D0=BA=D0=B8=D0=B9=20=D0=92=D0=B0?= =?UTF-8?q?=D0=B4=D0=B8=D0=BC?= , tnt@246tNt.com Errors-To: baseband-devel-bounces@lists.osmocom.org Sender: "baseband-devel" From: Яницкий Ва дим 1) Now the SAP interface is selectable as SIM source using the 'sim sap' command in VTY. 2) SAP connection starts only if it is configured as SIM source. 3) Fixed sap_socket_path configuration r/w errors. --- .../include/osmocom/bb/common/sap_interface.h | 1 + .../layer23/include/osmocom/bb/mobile/subscriber.h | 5 +- src/host/layer23/src/common/sap_interface.c | 15 +----- src/host/layer23/src/common/sim.c | 8 ++-- src/host/layer23/src/mobile/app_mobile.c | 3 ++ src/host/layer23/src/mobile/subscriber.c | 53 ++++++++++++++++++++++ src/host/layer23/src/mobile/vty_interface.c | 40 ++++++++++++++-- 7 files changed, 104 insertions(+), 21 deletions(-) diff --git a/src/host/layer23/include/osmocom/bb/common/sap_interface.h b/src/host/layer23/include/osmocom/bb/common/sap_interface.h index bf19356..e4e64ce 100644 --- a/src/host/layer23/include/osmocom/bb/common/sap_interface.h +++ 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, diff --git a/src/host/layer23/include/osmocom/bb/mobile/subscriber.h b/src/host/layer23/include/osmocom/bb/mobile/subscriber.h index 79a2ecc..ac785d4 100644 --- a/src/host/layer23/include/osmocom/bb/mobile/subscriber.h +++ 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); diff --git a/src/host/layer23/src/common/sap_interface.c b/src/host/layer23/src/common/sap_interface.c index a56f4f2..052646a 100644 --- a/src/host/layer23/src/common/sap_interface.c +++ 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; } diff --git a/src/host/layer23/src/common/sim.c b/src/host/layer23/src/common/sim.c index 8e8d7bf..9aad966 100644 --- a/src/host/layer23/src/common/sim.c +++ 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; diff --git a/src/host/layer23/src/mobile/app_mobile.c b/src/host/layer23/src/mobile/app_mobile.c index 3895ad6..e076741 100644 --- a/src/host/layer23/src/mobile/app_mobile.c +++ 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); diff --git a/src/host/layer23/src/mobile/subscriber.c b/src/host/layer23/src/mobile/subscriber.c index ba3c328..455db50 100644 --- a/src/host/layer23/src/mobile/subscriber.c +++ b/src/host/layer23/src/mobile/subscriber.c @@ -28,6 +28,7 @@ #include #include +#include #include #include @@ -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); +} diff --git a/src/host/layer23/src/mobile/vty_interface.c b/src/host/layer23/src/mobile/vty_interface.c index 73aaa78..7cb2259 100644 --- a/src/host/layer23/src/mobile/vty_interface.c +++ 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; } @@ -1295,6 +1321,9 @@ static void config_write_ms(struct vty *vty, struct osmocom_ms *ms) case GSM_SIM_TYPE_TEST: vty_out(vty, " sim test%s", VTY_NEWLINE); break; + case GSM_SIM_TYPE_SAP: + vty_out(vty, " sim sap%s", VTY_NEWLINE); + break; } vty_out(vty, " network-selection-mode %s%s", (set->plmn_mode == PLMN_MODE_AUTO) ? "auto" : "manual", VTY_NEWLINE); @@ -1557,9 +1586,10 @@ DEFUN(cfg_ms_sap, cfg_ms_sap_cmd, "sap-socket PATH", return CMD_SUCCESS; } -DEFUN(cfg_ms_sim, cfg_ms_sim_cmd, "sim (none|reader|test)", +DEFUN(cfg_ms_sim, cfg_ms_sim_cmd, "sim (none|reader|test|sap)", "Set SIM card to attach when powering on\nAttach no SIM\n" - "Attach SIM from reader\nAttach bulit in test SIM") + "Attach SIM from reader\nAttach bulit in test SIM\n" + "Attach SIM over SAP interface") { struct osmocom_ms *ms = vty->index; struct gsm_settings *set = &ms->settings; @@ -1574,6 +1604,9 @@ DEFUN(cfg_ms_sim, cfg_ms_sim_cmd, "sim (none|reader|test)", case 't': set->sim_type = GSM_SIM_TYPE_TEST; break; + case 's': + set->sim_type = GSM_SIM_TYPE_SAP; + break; default: vty_out(vty, "unknown SIM type%s", VTY_NEWLINE); return CMD_WARNING; @@ -2801,6 +2834,7 @@ int ms_vty_init(void) install_element(ENABLE_NODE, &sim_test_cmd); install_element(ENABLE_NODE, &sim_test_att_cmd); + install_element(ENABLE_NODE, &sim_sap_cmd); install_element(ENABLE_NODE, &sim_reader_cmd); install_element(ENABLE_NODE, &sim_remove_cmd); install_element(ENABLE_NODE, &sim_pin_cmd);