scd: Don't keep CCID reader open when card is not available.
authorNIIBE Yutaka <gniibe@fsij.org>
Fri, 7 Apr 2017 03:18:16 +0000 (12:18 +0900)
committerNIIBE Yutaka <gniibe@fsij.org>
Fri, 7 Apr 2017 03:18:16 +0000 (12:18 +0900)
* scd/apdu.c (open_ccid_reader): Fail if no ATR.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
scd/apdu.c

index 147bf73..65f770d 100644 (file)
@@ -1496,6 +1496,9 @@ open_ccid_reader (struct dev_list *dl)
 
   err = ccid_open_reader (dl->portstr, dl->idx, dl->ccid_table,
                           &slotp->ccid.handle, &slotp->rdrname);
 
   err = ccid_open_reader (dl->portstr, dl->idx, dl->ccid_table,
                           &slotp->ccid.handle, &slotp->rdrname);
+  if (!err)
+    err = ccid_get_atr (slotp->ccid.handle,
+                        slotp->atr, sizeof slotp->atr, &slotp->atrlen);
   if (err)
     {
       slotp->used = 0;
   if (err)
     {
       slotp->used = 0;
@@ -1503,14 +1506,6 @@ open_ccid_reader (struct dev_list *dl)
       return -1;
     }
 
       return -1;
     }
 
-  err = ccid_get_atr (slotp->ccid.handle,
-                      slotp->atr, sizeof slotp->atr, &slotp->atrlen);
-  if (err)
-    {
-      slotp->atrlen = 0;
-      err = 0;
-    }
-
   require_get_status = ccid_require_get_status (slotp->ccid.handle);
 
   reader_table[slot].close_reader = close_ccid_reader;
   require_get_status = ccid_require_get_status (slotp->ccid.handle);
 
   reader_table[slot].close_reader = close_ccid_reader;