sim: Obtain card ATR when opening the card
Change-Id: I42e387535c40f371b06f384af0ca5dc1e42ed00e
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: