Change in libosmocore[master]: sim: Add osim_card_{reset, close}() API

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

laforge gerrit-no-reply at lists.osmocom.org
Tue Jun 1 18:29:24 UTC 2021


laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/24504 )


Change subject: sim: Add osim_card_{reset,close}() API
......................................................................

sim: Add osim_card_{reset,close}() API

This is required to reset and close a card under software control
after opening it with osim_card_open()

Change-Id: Ie9ec66db4d54fdb1331f4ae05ca3ca4274912e9d
---
M TODO-RELEASE
M include/osmocom/sim/sim.h
M src/sim/reader.c
M src/sim/reader_pcsc.c
4 files changed, 56 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/04/24504/1

diff --git a/TODO-RELEASE b/TODO-RELEASE
index e57ffab..ad644aa 100644
--- a/TODO-RELEASE
+++ b/TODO-RELEASE
@@ -12,3 +12,4 @@
 libosmosim	osim_card_hdl		ABI + API breakage due to new struct members
 libosmocore	osmo_tdef_fsm_inst_state_chg	change default_timeout arg from unsigned long to long type (API breakage, not ABI)
 libosmovty      vty_read_config_filep   New API
+libosmosim	osim_card_{reset,close}	New API
diff --git a/include/osmocom/sim/sim.h b/include/osmocom/sim/sim.h
index 16b9f1f..5e7099f 100644
--- a/include/osmocom/sim/sim.h
+++ b/include/osmocom/sim/sim.h
@@ -375,6 +375,8 @@
 	const char *name;
 	struct osim_reader_hdl *(*reader_open)(int idx, const char *name, void *ctx);
 	struct osim_card_hdl *(*card_open)(struct osim_reader_hdl *rh, enum osim_proto proto);
+	int (*card_reset)(struct osim_card_hdl *card, bool cold_reset);
+	int (*card_close)(struct osim_card_hdl *card);
 	int (*transceive)(struct osim_reader_hdl *rh, struct msgb *msg);
 };
 
@@ -441,4 +443,6 @@
 struct osim_reader_hdl *osim_reader_open(enum osim_reader_driver drv, int idx,
 					 const char *name, void *ctx);
 struct osim_card_hdl *osim_card_open(struct osim_reader_hdl *rh, enum osim_proto proto);
+int osim_card_reset(struct osim_card_hdl *card, bool cold_reset);
+int osim_card_close(struct osim_card_hdl *card);
 #endif /* _OSMOCOM_SIM_H */
diff --git a/src/sim/reader.c b/src/sim/reader.c
index ae0aba9..7f3f18d 100644
--- a/src/sim/reader.c
+++ b/src/sim/reader.c
@@ -277,3 +277,24 @@
 
 	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 234a9a7..fa867c0 100644
--- a/src/sim/reader_pcsc.c
+++ b/src/sim/reader_pcsc.c
@@ -156,6 +156,34 @@
 	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)
 {
@@ -179,6 +207,8 @@
 	.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,
 };
 

-- 
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/24504
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Ie9ec66db4d54fdb1331f4ae05ca3ca4274912e9d
Gerrit-Change-Number: 24504
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge at osmocom.org>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210601/d4c1fab8/attachment.htm>


More information about the gerrit-log mailing list