From 772ab4cefbfb48cb544c0959fe60ef51723b40c4 Mon Sep 17 00:00:00 2001 From: vtarasov Date: Tue, 11 Jan 2011 10:29:23 +0000 Subject: [PATCH] libopensc: parse EF.ATR: redefine 'STATUS' macros ... thanks to Andre Zepezauer for his precious remarks git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5083 c6295689-39f2-0310-b995-f0e70906c6a9 --- src/libopensc/ef-atr.c | 19 +++++++++++++++---- src/libopensc/iso7816.h | 19 ++++++++++++------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/libopensc/ef-atr.c b/src/libopensc/ef-atr.c index 6a949f6a..16136480 100644 --- a/src/libopensc/ef-atr.c +++ b/src/libopensc/ef-atr.c @@ -38,8 +38,16 @@ sc_parse_ef_atr_content(struct sc_card *card, unsigned char *buf, size_t buflen) const unsigned char *tag = NULL; size_t taglen; struct sc_ef_atr ef_atr; + unsigned char category = *buf; LOG_FUNC_CALLED(ctx); + + category = *buf; + + /* IAS/ECC specific: skip second 'zero' byte */ + if (*(++buf) == 0x00) + ++buf; + tag = sc_asn1_find_tag(ctx, buf, buflen, ISO7816_TAG_II_CARD_SERVICE, &taglen); if (tag && taglen >= 1) { ef_atr.card_service = *tag; @@ -74,6 +82,7 @@ sc_parse_ef_atr_content(struct sc_card *card, unsigned char *buf, size_t buflen) sc_log(ctx, "EF.ATR: AID '%s'", sc_dump_hex(ef_atr.aid.value, ef_atr.aid.len)); } + /* IAS/ECC specific issuer data: contains the max send/recv buffer sizes in plain and SM modes */ tag = sc_asn1_find_tag(ctx, buf, buflen, IASECC_TAG_II_IO_BUFFER_SIZES, &taglen); if (tag) { size_t len = taglen > sizeof(ef_atr.issuer_data) ? sizeof(ef_atr.issuer_data) : taglen; @@ -90,10 +99,12 @@ sc_parse_ef_atr_content(struct sc_card *card, unsigned char *buf, size_t buflen) memcpy(ef_atr.allocation_oid.value, tag, taglen); } - tag = sc_asn1_find_tag(ctx, buf, buflen, ISO7816_TAG_II_STATUS, &taglen); - if (tag && taglen == 2) { - ef_atr.status = *(tag + 0) * 0x100 + *(tag + 1); - sc_log(ctx, "EF.ATR: status word 0x%X", ef_atr.status); + if (category == ISO7816_II_CATEGORY_TLV) { + tag = sc_asn1_find_tag(ctx, buf, buflen, ISO7816_TAG_II_STATUS_SW, &taglen); + if (tag && taglen == 2) { + ef_atr.status = *(tag + 0) * 0x100 + *(tag + 1); + sc_log(ctx, "EF.ATR: status word 0x%X", ef_atr.status); + } } if (!card->ef_atr) diff --git a/src/libopensc/iso7816.h b/src/libopensc/iso7816.h index 3488325e..839da42d 100644 --- a/src/libopensc/iso7816.h +++ b/src/libopensc/iso7816.h @@ -21,14 +21,19 @@ extern "C" { #define ISO7816_TAG_FCP_ACLS 0x86 /* ISO7816 interindustry data tags */ -#define ISO7816_TAG_II_CARD_SERVICE 0x43 -#define ISO7816_TAG_II_INITIAL_ACCESS_DATA 0x44 -#define ISO7816_TAG_II_CARD_ISSUER_DATA 0x45 -#define ISO7816_TAG_II_PRE_ISSUING 0x46 -#define ISO7816_TAG_II_CARD_CAPABILITIES 0x47 -#define ISO7816_TAG_II_AID 0x4F +#define ISO7816_II_CATEGORY_TLV 0x80 +#define ISO7816_II_CATEGORY_NOT_TLV 0x00 + +#define ISO7816_TAG_II_CARD_SERVICE 0x43 +#define ISO7816_TAG_II_INITIAL_ACCESS_DATA 0x44 +#define ISO7816_TAG_II_CARD_ISSUER_DATA 0x45 +#define ISO7816_TAG_II_PRE_ISSUING 0x46 +#define ISO7816_TAG_II_CARD_CAPABILITIES 0x47 +#define ISO7816_TAG_II_AID 0x4F #define ISO7816_TAG_II_ALLOCATION_SCHEME 0x78 -#define ISO7816_TAG_II_STATUS 0x82 +#define ISO7816_TAG_II_STATUS_LCS 0x81 +#define ISO7816_TAG_II_STATUS_SW 0x82 +#define ISO7816_TAG_II_STATUS_LCS_SW 0x83 /* Other interindustry data tags */ #define IASECC_TAG_II_IO_BUFFER_SIZES 0xE0