From b59fb4597eba67d6ba77ca1747508b4ff2f6b6ce Mon Sep 17 00:00:00 2001 From: sth Date: Sun, 30 Jan 2005 19:20:38 +0000 Subject: [PATCH] Have the option add a delay before resending an APDU (after a 6CXX response). Is needed for most current belpic cards on fast readers git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@2117 c6295689-39f2-0310-b995-f0e70906c6a9 --- src/include/winconfig.h | 2 -- src/libopensc/card-belpic.c | 5 +++++ src/libopensc/card.c | 3 +++ src/libopensc/opensc.h | 4 ++++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/include/winconfig.h b/src/include/winconfig.h index d799c43d..2c8c57d8 100644 --- a/src/include/winconfig.h +++ b/src/include/winconfig.h @@ -54,8 +54,6 @@ #define PATH_MAX _MAX_PATH -#define sleep(t) Sleep((t) * 1000) - #ifndef VERSION #define VERSION "0.9.4" #endif diff --git a/src/libopensc/card-belpic.c b/src/libopensc/card-belpic.c index c4df9f33..75c1a67e 100644 --- a/src/libopensc/card-belpic.c +++ b/src/libopensc/card-belpic.c @@ -1008,6 +1008,11 @@ static int belpic_init(struct sc_card *card) SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_HASH_NONE, 0); } + /* V1 applets have a problem: if the card sends a 6C XX (only XX bytes available), + * and we resend the command too soon (i.e. the reader is too fast), the card + * doesn't respond. So we build in a delay. */ + card->wait_resend_apdu = 40; + /* State that we have an RNG */ card->caps |= SC_CARD_CAP_RNG; diff --git a/src/libopensc/card.c b/src/libopensc/card.c index cc8b84b4..896ffcd6 100644 --- a/src/libopensc/card.c +++ b/src/libopensc/card.c @@ -260,6 +260,9 @@ int sc_transmit_apdu(struct sc_card *card, struct sc_apdu *apdu) if (apdu->sw1 == 0x6C && apdu->resplen == 0) { apdu->resplen = orig_resplen; apdu->le = apdu->sw2; + /* Fix for cards (e.g. belpic) that need a delay on fast readers */ + if (card->wait_resend_apdu != 0) + msleep(card->wait_resend_apdu); r = sc_transceive(card, apdu); if (r != 0) { sc_unlock(card); diff --git a/src/libopensc/opensc.h b/src/libopensc/opensc.h index 1dcf98cd..a3924536 100644 --- a/src/libopensc/opensc.h +++ b/src/libopensc/opensc.h @@ -179,8 +179,11 @@ extern "C" { /* A 64-bit uint, used in sc_current_time() */ #ifndef _WIN32 typedef unsigned long long sc_timestamp_t; +#define msleep(t) usleep((t) * 1000) #else typedef unsigned __int64 sc_timestamp_t; +#define msleep(t) Sleep(t) +#define sleep(t) Sleep((t) * 1000) #endif /* Event masks for sc_wait_for_event() */ @@ -440,6 +443,7 @@ struct sc_card { struct sc_slot_info *slot; unsigned long caps, flags; + unsigned int wait_resend_apdu; /* Delay (msec) before responding to an SW12 = 6CXX */ int cla; u8 atr[SC_MAX_ATR_SIZE]; size_t atr_len;