Change in libosmocore[master]: sim: Obtain card ATR when opening the card

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
Sun Apr 25 19:09:34 UTC 2021


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


Change subject: sim: Obtain card ATR when opening the card
......................................................................

sim: Obtain card ATR when opening the card

Change-Id: I42e387535c40f371b06f384af0ca5dc1e42ed00e
---
M TODO-RELEASE
M include/osmocom/sim/sim.h
M src/sim/reader_pcsc.c
3 files changed, 35 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/95/23895/1

diff --git a/TODO-RELEASE b/TODO-RELEASE
index ed04a14..7ba9347 100644
--- a/TODO-RELEASE
+++ b/TODO-RELEASE
@@ -9,3 +9,4 @@
 #library	what			description / commit summary line
 libosmovty	_LAST_OSMOVTY_NODE 	Raise _LAST_OSMOVTY_NODE by introducing some RESERVED*_NODE
 libosmogsm      gsm0808_old_bss_to_new_bss_info ABI break (struct changes size), gsm0808_old_bss_to_new_bss_info_att_tlvdef symbol added
+libosmosim	osim_card_hdl		ABI + API breakage due to new struct members
diff --git a/include/osmocom/sim/sim.h b/include/osmocom/sim/sim.h
index 72e7904..16b9f1f 100644
--- a/include/osmocom/sim/sim.h
+++ b/include/osmocom/sim/sim.h
@@ -11,6 +11,13 @@
 #define APDU_HDR_LEN	5
 #define MAX_AID_LEN	16 /* Table 13.2 of TS 102 221 */
 
+
+/*! Maximum Answer-To-Reset (ATR) size in bytes
+ *  @note defined in ISO/IEC 7816-3:2006(E) section 8.2.1 as 32, on top the initial character TS of section 8.1
+ *  @remark technical there is no size limitation since Yi present in T0,TDi will indicate if more interface bytes are present, including TDi+i
+ */
+#define OSIM_MAX_ATR_LEN 33
+
 /*! command-response pairs cases
  *
  * Enumeration used to identify the APDU structure based on command-response pair case , as specified in ISO/IEC 7816-3:2006(E) §12.1.
@@ -409,6 +416,10 @@
 
 	/*! list of applications found on card */
 	struct llist_head apps;
+
+	/*! ATR (Answer To Reset) of the card */
+	uint8_t atr[OSIM_MAX_ATR_LEN];
+	unsigned int atr_len;
 };
 
 struct osim_chan_hdl {
diff --git a/src/sim/reader_pcsc.c b/src/sim/reader_pcsc.c
index c37380a..7d424b8 100644
--- a/src/sim/reader_pcsc.c
+++ b/src/sim/reader_pcsc.c
@@ -56,6 +56,27 @@
 	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,6 +151,8 @@
 	chan->card = card;
 	llist_add(&chan->list, &card->channels);
 
+	pcsc_get_atr(card);
+
 	return card;
 
 end:

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

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I42e387535c40f371b06f384af0ca5dc1e42ed00e
Gerrit-Change-Number: 23895
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/20210425/1891689c/attachment.htm>


More information about the gerrit-log mailing list