aboutsummaryrefslogtreecommitdiffstats
path: root/src/sim
diff options
context:
space:
mode:
Diffstat (limited to 'src/sim')
-rw-r--r--src/sim/Makefile.am11
-rw-r--r--src/sim/card_fs_hpsim.c4
-rw-r--r--src/sim/card_fs_isim.c4
-rw-r--r--src/sim/card_fs_sim.c4
-rw-r--r--src/sim/card_fs_tetra.c4
-rw-r--r--src/sim/card_fs_uicc.c4
-rw-r--r--src/sim/card_fs_usim.c72
-rw-r--r--src/sim/class_tables.c94
-rw-r--r--src/sim/core.c4
-rw-r--r--src/sim/reader.c28
-rw-r--r--src/sim/reader_pcsc.c63
11 files changed, 237 insertions, 55 deletions
diff --git a/src/sim/Makefile.am b/src/sim/Makefile.am
index 0539dd98..0f6be576 100644
--- a/src/sim/Makefile.am
+++ b/src/sim/Makefile.am
@@ -1,9 +1,9 @@
# This is _NOT_ the library release version, it's an API version.
# Please read chapter "Library interface versions" of the libtool documentation
# before making any modifications: https://www.gnu.org/software/libtool/manual/html_node/Versioning.html
-LIBVERSION=1:2:1
+LIBVERSION=3:2:1
-AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include -I$(top_builddir)/include
+AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include -I$(top_builddir)
AM_CFLAGS = -fPIC -Wall $(TALLOC_CFLAGS)
AM_LDFLAGS = $(COVERAGE_LDFLAGS)
@@ -15,9 +15,12 @@ lib_LTLIBRARIES = libosmosim.la
libosmosim_la_SOURCES = core.c reader.c class_tables.c \
card_fs_sim.c card_fs_usim.c card_fs_uicc.c \
card_fs_isim.c card_fs_hpsim.c card_fs_tetra.c
-libosmosim_la_LDFLAGS = -version-info $(LIBVERSION)
+libosmosim_la_LDFLAGS = \
+ -version-info $(LIBVERSION) \
+ -no-undefined \
+ $(NULL)
libosmosim_la_LIBADD = \
- $(top_builddir)/src/libosmocore.la \
+ $(top_builddir)/src/core/libosmocore.la \
$(top_builddir)/src/gsm/libosmogsm.la \
$(TALLOC_LIBS)
if ENABLE_PCSC
diff --git a/src/sim/card_fs_hpsim.c b/src/sim/card_fs_hpsim.c
index 4a5f7d9a..2c115b75 100644
--- a/src/sim/card_fs_hpsim.c
+++ b/src/sim/card_fs_hpsim.c
@@ -17,10 +17,6 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
*/
diff --git a/src/sim/card_fs_isim.c b/src/sim/card_fs_isim.c
index f11c0294..1a38da2f 100644
--- a/src/sim/card_fs_isim.c
+++ b/src/sim/card_fs_isim.c
@@ -17,10 +17,6 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
*/
diff --git a/src/sim/card_fs_sim.c b/src/sim/card_fs_sim.c
index 55ce9af7..f07a2370 100644
--- a/src/sim/card_fs_sim.c
+++ b/src/sim/card_fs_sim.c
@@ -17,10 +17,6 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
*/
#include <errno.h>
diff --git a/src/sim/card_fs_tetra.c b/src/sim/card_fs_tetra.c
index 12853a52..597e38b7 100644
--- a/src/sim/card_fs_tetra.c
+++ b/src/sim/card_fs_tetra.c
@@ -17,10 +17,6 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
*/
#include <errno.h>
diff --git a/src/sim/card_fs_uicc.c b/src/sim/card_fs_uicc.c
index 5dcaaa12..87def0e4 100644
--- a/src/sim/card_fs_uicc.c
+++ b/src/sim/card_fs_uicc.c
@@ -17,10 +17,6 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
*/
diff --git a/src/sim/card_fs_usim.c b/src/sim/card_fs_usim.c
index 4c8f79c4..8cff3fc3 100644
--- a/src/sim/card_fs_usim.c
+++ b/src/sim/card_fs_usim.c
@@ -15,10 +15,6 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
*/
@@ -348,6 +344,68 @@ static const struct osim_file_desc usim_ef_in_df_hnb[] = {
"Oprator Home NodeB Name"),
};
+/* 31.102 Chapter 4.4.8 */
+static const struct osim_file_desc usim_ef_in_df_prose[] = {
+ EF_LIN_FIX_N(0x4F01, 0x01, "EF.PROSE_MON", F_OPTIONAL, 1, 64,
+ "ProSe Monitoring Parameters"),
+ EF_LIN_FIX_N(0x4F02, 0x02, "EF.PROSE_ANN", F_OPTIONAL, 1, 64,
+ "ProSe Announcing Parameters"),
+ EF_LIN_FIX_N(0x4F03, 0x03, "EF.PROSEFUNC", F_OPTIONAL, 1, 64,
+ "HPLMN ProSe Function"),
+ EF_TRANSP_N(0x4F04, 0x04, "EF.PROSE_RADIO_COM", F_OPTIONAL, 1, 128,
+ "ProSe Direct Communication Radio Parameters"),
+ EF_TRANSP_N(0x4F05, 0x05, "EF.PROSE_RADIO_MON", F_OPTIONAL, 1, 128,
+ "ProSe Direct Discovery Monitoring Radio Parameters"),
+ EF_TRANSP_N(0x4F06, 0x06, "EF.PROSE_RADIO_ANN", F_OPTIONAL, 1, 128,
+ "ProSe Direct Discovery Announcing Radio Parameters"),
+ EF_LIN_FIX_N(0x4F07, 0x07, "EF.PROSE_POLICY", F_OPTIONAL, 1, 64,
+ "ProSe Direct Discovery Announcing Radio Parameters"),
+ EF_LIN_FIX_N(0x4F08, 0x08, "EF.PROSE_PLMN", F_OPTIONAL, 1, 64,
+ "ProSe PLMN Parametes"),
+ EF_TRANSP_N(0x4F09, 0x09, "EF.PROSE_GC", F_OPTIONAL, 8, 64,
+ "ProSe Direct Discovery Announcing Radio Parameters"),
+ EF_TRANSP_N(0x4F10, 0x10, "EF.PST", F_OPTIONAL, 1, 2,
+ "ProSe Service Table"),
+ EF_TRANSP_N(0x4F11, 0x11, "EF.PROSE_UIRC", F_OPTIONAL, 1, 128,
+ "ProSe UsageInformationReportingConfiguration"),
+ EF_LIN_FIX_N(0x4F12, 0x12, "EF.PROSE_GM_DISCOVERY", F_OPTIONAL, 1, 64,
+ "ProSe Group Member Discovery Parameters"),
+ EF_LIN_FIX_N(0x4F13, 0x13, "EF.PROSE_RELAY", F_OPTIONAL, 1, 64,
+ "ProSe Relay Parameters"),
+ EF_TRANSP_N(0x4F14, 0x14, "EF.PROSE_RELAY_DISCOVERY", F_OPTIONAL, 5, 64,
+ "ProSe Relay Discovery Parameters"),
+};
+
+/* 31.102 Chapter 4.4.9 */
+static const struct osim_file_desc usim_ef_in_df_acdc[] = {
+ EF_TRANSP_N(0x4F01, 0x01, "EF.ACDC_LIST", F_OPTIONAL, 1, 128,
+ "ACDC List"),
+};
+
+/* 31.102 Chapter 4.4.11 */
+static const struct osim_file_desc usim_ef_in_df_5gs[] = {
+ EF_TRANSP_N(0x4F01, 0x01, "EF.5GS3GPPLOCI", F_OPTIONAL, 20, 20,
+ "5GS 3GPP location information"),
+ EF_TRANSP_N(0x4F02, 0x02, "EF.5GSN3GPPLOCI", F_OPTIONAL, 20, 20,
+ "5GS non-3GPP location information"),
+ EF_LIN_FIX_N(0x4F03, 0x03, "EF.5GS3GPPNSC", F_OPTIONAL, 57, 57,
+ "5GS 3GPP Access NAS Security Context"),
+ EF_LIN_FIX_N(0x4F04, 0x04, "EF.5GSN3GPPNSC", F_OPTIONAL, 57, 57,
+ "5GS non-3GPP Access NAS Security Context"),
+ EF_TRANSP_N(0x4F05, 0x05, "EF.5GAUTHKEYS", F_OPTIONAL, 68, 68,
+ "5GS authentication keys"),
+ EF_TRANSP_N(0x4F06, 0x06, "EF.UAC_AIC", F_OPTIONAL, 4, 4,
+ "UAC Access Identities Configuration"),
+ EF_TRANSP_N(0x4F07, 0x07, "EF.SUCI_Calc_Info", F_OPTIONAL, 2, 64,
+ "Subscription Concealed Identifier Calculation Information"),
+ EF_LIN_FIX_N(0x4F08, 0x08, "EF.OPL5G", F_OPTIONAL, 10, 10,
+ "5GS Operator PLMN List"),
+ EF_TRANSP_N(0x4F09, 0x09, "EF.NSI", F_OPTIONAL, 1, 64,
+ "Network Specific Identifier"),
+ EF_TRANSP_N(0x4F0A, 0x0A, "EF.Routing_Indicator", F_OPTIONAL, 4, 4,
+ "Routing Indicator"),
+};
+
/* Annex E - TS 101 220 */
static const uint8_t adf_usim_aid[] = { 0xA0, 0x00, 0x00, 0x00, 0x87, 0x10, 0x02 };
@@ -375,6 +433,8 @@ struct osim_card_app_profile *osim_aprof_usim(void *ctx)
ARRAY_SIZE(usim_ef_in_df_mexe));
add_df_with_ef(uadf, 0x5F40, "DF.WLAN", usim_ef_in_df_wlan,
ARRAY_SIZE(usim_ef_in_df_wlan));
+ add_df_with_ef(uadf, 0x5FC0, "DF.5GS", usim_ef_in_df_5gs,
+ ARRAY_SIZE(usim_ef_in_df_5gs));
/* Home-NodeB (femtocell) */
add_df_with_ef(uadf, 0x5F50, "DF.HNB", usim_ef_in_df_hnb,
ARRAY_SIZE(usim_ef_in_df_hnb));
@@ -383,6 +443,10 @@ struct osim_card_app_profile *osim_aprof_usim(void *ctx)
ARRAY_SIZE(usim_ef_in_solsa));
/* OMA BCAST Smart Card Profile */
add_df_with_ef(uadf, 0x5F80, "DF.BCAST", NULL, 0);
+ add_df_with_ef(uadf, 0x5F90, "DF.ProSe", usim_ef_in_df_prose,
+ ARRAY_SIZE(usim_ef_in_df_prose));
+ add_df_with_ef(uadf, 0x5FA0, "DF.ACDC", usim_ef_in_df_acdc,
+ ARRAY_SIZE(usim_ef_in_df_acdc));
return aprof;
}
diff --git a/src/sim/class_tables.c b/src/sim/class_tables.c
index 6f541ee2..29c1e40e 100644
--- a/src/sim/class_tables.c
+++ b/src/sim/class_tables.c
@@ -13,17 +13,13 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdint.h>
#include <osmocom/core/utils.h>
#include <osmocom/sim/class_tables.h>
-static const uint8_t iso7816_ins_tbl[] = {
+static const uint8_t iso7816_ins_tbl[256] = {
[0xB0] = 2, /* READ BIN */
[0xD0] = 3, /* WRITE BIN */
[0xD6] = 3, /* UPDATE BIN */
@@ -117,7 +113,7 @@ static const uint8_t uicc_ins_tbl_046[256] = {
[0xD6] = 3, /* UPDATE BINARY */
[0xB2] = 2, /* READ RECORD */
[0xDC] = 3, /* UPDATE RECORD */
- [0xA2] = 4, /* SEEK */
+ [0xA2] = 4, /* SEARCH RECORD */
[0x20] = 3, /* VERIFY PIN */
[0x24] = 3, /* CHANGE PIN */
[0x26] = 3, /* DISABLE PIN */
@@ -177,6 +173,24 @@ static int uicc046_cla_ins_helper(const struct osim_cla_ins_case *cic,
return 0;
}
+static int gp_cla_ins_helper(const struct osim_cla_ins_case *cic,
+ const uint8_t *hdr)
+{
+ uint8_t ins = hdr[1];
+ uint8_t p1 = hdr[2];
+
+ switch (ins) {
+ case 0xE2: /* STORE DATA */
+ switch (p1 & 0x01) {
+ case 1:
+ return 4;
+ default:
+ return 3;
+ }
+ }
+ return 0;
+}
+
/* ETSI TS 102 221, Table 10.5, CLA = 0x8x, 0xCx or 0xEx */
static const uint8_t uicc_ins_tbl_8ce[256] = {
[0xF2] = 2, /* STATUS */
@@ -184,6 +198,7 @@ static const uint8_t uicc_ins_tbl_8ce[256] = {
[0xCB] = 4, /* RETRIEVE DATA */
[0xDB] = 3, /* SET DATA */
[0xAA] = 3, /* TERMINAL CAPABILITY */
+ [0x78] = 4, /* GET IDENTITY */
};
/* ETSI TS 102 221, Table 10.5, CLA = 0x80 */
@@ -192,6 +207,22 @@ static const uint8_t uicc_ins_tbl_80[256] = {
[0xC2] = 4, /* ENVELOPE */
[0x12] = 2, /* FETCH */
[0x14] = 3, /* TERMINAL RESPONSE */
+ [0x76] = 4, /* SUSPEND UICC */
+ [0x7A] = 4, /* EXCHANGE CAPABILITIES */
+};
+
+/* Card Specification v2.3.1*/
+static const uint8_t gp_ins_tbl_8ce[256] = {
+ [0xE4] = 4, /* DELETE */
+ [0xE2] = 0x80, /* STORE DATA */
+ [0xCA] = 4, /* GET DATA */
+ [0xCB] = 4, /* GET DATA */
+ [0xF2] = 4, /* GET STATUS */
+ [0xE6] = 4, /* INSTALL */
+ [0xE8] = 4, /* LOAD */
+ [0xD8] = 4, /* PUT KEY */
+ [0xF0] = 3, /* SET STATUS */
+ [0xC0] = 2, /* GET RESPONSE */
};
static const struct osim_cla_ins_case uicc_ins_case[] = {
@@ -226,6 +257,21 @@ static const struct osim_cla_ins_case uicc_ins_case[] = {
.cla = 0xE0,
.cla_mask = 0xF0,
.ins_tbl = uicc_ins_tbl_8ce,
+ }, {
+ .cla = 0x80,
+ .cla_mask = 0xF0,
+ .helper = gp_cla_ins_helper,
+ .ins_tbl = gp_ins_tbl_8ce,
+ }, {
+ .cla = 0xC0,
+ .cla_mask = 0xF0,
+ .helper = gp_cla_ins_helper,
+ .ins_tbl = gp_ins_tbl_8ce,
+ }, {
+ .cla = 0xE0,
+ .cla_mask = 0xF0,
+ .helper = gp_cla_ins_helper,
+ .ins_tbl = gp_ins_tbl_8ce,
},
};
@@ -273,7 +319,23 @@ static const struct osim_cla_ins_case uicc_sim_ins_case[] = {
.cla = 0xE0,
.cla_mask = 0xF0,
.ins_tbl = uicc_ins_tbl_8ce,
+ }, {
+ .cla = 0x80,
+ .cla_mask = 0xF0,
+ .helper = gp_cla_ins_helper,
+ .ins_tbl = gp_ins_tbl_8ce,
+ }, {
+ .cla = 0xC0,
+ .cla_mask = 0xF0,
+ .helper = gp_cla_ins_helper,
+ .ins_tbl = gp_ins_tbl_8ce,
+ }, {
+ .cla = 0xE0,
+ .cla_mask = 0xF0,
+ .helper = gp_cla_ins_helper,
+ .ins_tbl = gp_ins_tbl_8ce,
},
+
};
const struct osim_cla_ins_card_profile osim_uicc_sim_cic_profile = {
@@ -288,6 +350,13 @@ const uint8_t usim_ins_case[256] = {
[0x88] = 4, /* AUTHENTICATE */
};
+/* https://learn.microsoft.com/en-us/windows-hardware/drivers/smartcard/discovery-process */
+static const uint8_t microsoft_discovery_ins_tbl[256] = {
+ [0xA4] = 4, /* SELECT FILE */
+ [0xCA] = 2, /* GET DATA */
+ [0xC0] = 2, /* GET RESPONSE */
+};
+
int osim_determine_apdu_case(const struct osim_cla_ins_card_profile *prof,
const uint8_t *hdr)
{
@@ -305,12 +374,23 @@ int osim_determine_apdu_case(const struct osim_cla_ins_card_profile *prof,
case 0x80:
return cic->helper(cic, hdr);
case 0x00:
- /* continue with fruther cic, rather than abort
+ /* continue with further cic, rather than abort
* now */
continue;
default:
return rc;
}
}
+ /* special handling for Microsoft who insists to use INS=0xCA in CLA=0x00 which is not
+ * really part of GSM SIM, ETSI UICC or 3GPP USIM specifications, but only ISO7816. Rather than adding
+ * it to each and every card profile, let's add the instructions listed at
+ * https://learn.microsoft.com/en-us/windows-hardware/drivers/smartcard/discovery-process explicitly
+ * here. They will only be used in case no more specific match was found in the actual profile above. */
+ if (cla == 0x00) {
+ rc = microsoft_discovery_ins_tbl[ins];
+ if (rc)
+ return rc;
+ }
+
return 0;
}
diff --git a/src/sim/core.c b/src/sim/core.c
index d11c2d83..fa17e12d 100644
--- a/src/sim/core.c
+++ b/src/sim/core.c
@@ -17,10 +17,6 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
*/
diff --git a/src/sim/reader.c b/src/sim/reader.c
index d5292baa..982b2eef 100644
--- a/src/sim/reader.c
+++ b/src/sim/reader.c
@@ -17,10 +17,6 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
*/
@@ -44,7 +40,7 @@ static int get_sw(struct msgb *resp)
{
int ret;
- if (!msgb_apdu_de(resp) || msgb_apdu_le(resp) < 2)
+ if (!resp->l2h || msgb_apdu_le(resp) < 2)
return -EIO;
ret = msgb_get_u16(resp);
@@ -123,7 +119,6 @@ transceive_again:
/* save SW */
sw = msgb_apdu_sw(tmsg);
- printf("sw = 0x%04x\n", sw);
msgb_apdu_sw(amsg) = sw;
switch (msgb_apdu_case(amsg)) {
@@ -278,3 +273,24 @@ struct osim_card_hdl *osim_card_open(struct osim_reader_hdl *rh, enum osim_proto
return ch;
}
+
+int osim_card_reset(struct osim_card_hdl *card, bool cold_reset)
+{
+ struct osim_reader_hdl *rh = card->reader;
+
+ return rh->ops->card_reset(card, cold_reset);
+}
+
+int osim_card_close(struct osim_card_hdl *card)
+{
+ struct osim_reader_hdl *rh = card->reader;
+ int rc;
+
+ rc = rh->ops->card_close(card);
+
+ card->reader = NULL;
+ talloc_free(card);
+ rh->card = NULL;
+
+ return rc;
+}
diff --git a/src/sim/reader_pcsc.c b/src/sim/reader_pcsc.c
index c37380a3..c37072ee 100644
--- a/src/sim/reader_pcsc.c
+++ b/src/sim/reader_pcsc.c
@@ -17,10 +17,6 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
*/
@@ -41,12 +37,9 @@
if (rv != SCARD_S_SUCCESS) { \
fprintf(stderr, text ": %s (0x%lX)\n", pcsc_stringify_error(rv), rv); \
goto end; \
-} else { \
- printf(text ": OK\n\n"); \
}
-
struct pcsc_reader_state {
SCARDCONTEXT hContext;
SCARDHANDLE hCard;
@@ -56,6 +49,27 @@ struct pcsc_reader_state {
char *name;
};
+static int pcsc_get_atr(struct osim_card_hdl *card)
+{
+ struct osim_reader_hdl *rh = card->reader;
+ struct pcsc_reader_state *st = rh->priv;
+ char pbReader[MAX_READERNAME];
+ DWORD dwReaderLen = sizeof(pbReader);
+ DWORD dwAtrLen = sizeof(card->atr);
+ DWORD dwState, dwProt;
+ long rc;
+
+ rc = SCardStatus(st->hCard, pbReader, &dwReaderLen, &dwState, &dwProt,
+ card->atr, &dwAtrLen);
+ PCSC_ERROR(rc, "SCardStatus");
+ card->atr_len = dwAtrLen;
+
+ return 0;
+
+end:
+ return -EIO;
+}
+
static struct osim_reader_hdl *pcsc_reader_open(int num, const char *id, void *ctx)
{
struct osim_reader_hdl *rh;
@@ -130,12 +144,42 @@ static struct osim_card_hdl *pcsc_card_open(struct osim_reader_hdl *rh,
chan->card = card;
llist_add(&chan->list, &card->channels);
+ pcsc_get_atr(card);
+
return card;
end:
return NULL;
}
+static int pcsc_card_reset(struct osim_card_hdl *card, bool cold_reset)
+{
+ struct pcsc_reader_state *st = card->reader->priv;
+ LONG rc;
+
+ rc = SCardReconnect(st->hCard, SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0,
+ cold_reset ? SCARD_UNPOWER_CARD : SCARD_RESET_CARD,
+ &st->dwActiveProtocol);
+ PCSC_ERROR(rc, "SCardReconnect");
+
+ return 0;
+end:
+ return -EIO;
+}
+
+static int pcsc_card_close(struct osim_card_hdl *card)
+{
+ struct pcsc_reader_state *st = card->reader->priv;
+ LONG rc;
+
+ rc = SCardDisconnect(st->hCard, SCARD_UNPOWER_CARD);
+ PCSC_ERROR(rc, "SCardDisconnect");
+
+ return 0;
+end:
+ return -EIO;
+}
+
static int pcsc_transceive(struct osim_reader_hdl *rh, struct msgb *msg)
{
@@ -143,13 +187,10 @@ static int pcsc_transceive(struct osim_reader_hdl *rh, struct msgb *msg)
DWORD rlen = msgb_tailroom(msg);
LONG rc;
- printf("TX: %s\n", osmo_hexdump(msg->data, msg->len));
-
rc = SCardTransmit(st->hCard, st->pioSendPci, msg->data, msgb_length(msg),
&st->pioRecvPci, msg->tail, &rlen);
PCSC_ERROR(rc, "SCardEndTransaction");
- printf("RX: %s\n", osmo_hexdump(msg->tail, rlen));
msgb_put(msg, rlen);
msgb_apdu_le(msg) = rlen;
@@ -162,6 +203,8 @@ const struct osim_reader_ops pcsc_reader_ops = {
.name = "PC/SC",
.reader_open = pcsc_reader_open,
.card_open = pcsc_card_open,
+ .card_reset = pcsc_card_reset,
+ .card_close = pcsc_card_close,
.transceive = pcsc_transceive,
};