aboutsummaryrefslogtreecommitdiffstats
path: root/scd/apdu.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2011-12-12 19:34:12 +0000
committerWerner Koch <[email protected]>2011-12-12 19:34:12 +0000
commitcd29dc0f1cf7f3bd7938ffa65bf13f9a75d8c156 (patch)
treeb262c6244c3043c43eaf200ea029c71060d77bc9 /scd/apdu.c
parentgitlog-to-changelog: New option --tear-off. (diff)
downloadgnupg-cd29dc0f1cf7f3bd7938ffa65bf13f9a75d8c156.tar.gz
gnupg-cd29dc0f1cf7f3bd7938ffa65bf13f9a75d8c156.zip
Fix detection of card removal and insertion.
* scd/apdu.c (apdu_connect): Return status codes for no card available and inactive card. * scd/command.c (TEST_CARD_REMOVAL): Also test for GPG_ERR_CARD_RESET. (open_card): Map apdu_connect status to GPG_ERR_CARD_RESET.
Diffstat (limited to '')
-rw-r--r--scd/apdu.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/scd/apdu.c b/scd/apdu.c
index c130d89bc..ae910825f 100644
--- a/scd/apdu.c
+++ b/scd/apdu.c
@@ -3051,11 +3051,14 @@ apdu_enum_reader (int slot, int *used)
/* Connect a card. This is used to power up the card and make sure
- that an ATR is available. */
+ that an ATR is available. Depending on the reader backend it may
+ return an error for an inactive card or if no card is
+ available. */
int
apdu_connect (int slot)
{
int sw;
+ unsigned int status;
if (slot < 0 || slot >= MAX_READER || !reader_table[slot].used )
return SW_HOST_NO_DRIVER;
@@ -3080,7 +3083,15 @@ apdu_connect (int slot)
scdaemon is fired up and apdu_get_status has not yet been called.
Without that we would force a reset of the card with the next
call to apdu_get_status. */
- apdu_get_status_internal (slot, 1, 1, NULL, NULL);
+ apdu_get_status_internal (slot, 1, 1, &status, NULL);
+ if (sw)
+ ;
+ else if (!(status & APDU_CARD_PRESENT))
+ sw = SW_HOST_NO_CARD;
+ else if (((status & APDU_CARD_PRESENT) && !(status & APDU_CARD_ACTIVE))
+ || !reader_table[slot].atrlen)
+ sw = SW_HOST_CARD_INACTIVE;
+
return sw;
}