Chaskiel, please look at the ccid_open_usb(), and try to help me
figure out why I had to add ifd_sysdep_usb_reset() in order to make
the reader respond to the initial status query.

It appears that ccid_card_status always fails if it has to probe the device and no card is present. That's because the response to the GetSlotStatus message when no card is present has the 'command failed' bit set and the error code set to ICC_MUTE (spec implies this is the desired behavior). The reset you did somehow causes the device to post an event notifying us that the card was removed. Once that event comes in, ccid_card_status never sends another GetSlotStatus message. The attached patch catches this specific error and interprets it correctly. (Actually, there are two patches. One takes the IFD_ERROR_NO_CARD error from ccid_command and asserts that means the card is absent. The other ignores the IFD_ERROR_NO_CARD error and parses the result as if no error had been reported. Either should work)
Index: src/ifd/ifd-ccid.c
===================================================================
--- src/ifd/ifd-ccid.c	(revision 1094)
+++ src/ifd/ifd-ccid.c	(working copy)
@@ -925,6 +925,10 @@
 	if (r < 0)
 		return r;
 	r = ccid_command(reader, cmdbuf, 10, ret, 10);
+	if (r == IFD_ERROR_NO_CARD) {
+		stat = 0;
+		goto ok;
+	}
 	if (r < 0)
 		return r;
 	switch (ret[7] & 3) {
@@ -934,6 +938,7 @@
 	default:
 		stat = IFD_CARD_PRESENT;
 	}
+ok:
 	ifd_debug(1, "probed result: %d", IFD_CARD_STATUS_CHANGED | stat);
 
 	*status = IFD_CARD_STATUS_CHANGED | stat;
Index: src/ifd/ifd-ccid.c
===================================================================
--- src/ifd/ifd-ccid.c  (revision 1094)
+++ src/ifd/ifd-ccid.c  (working copy)
@@ -925,7 +925,7 @@
        if (r < 0)
                return r;
        r = ccid_command(reader, cmdbuf, 10, ret, 10);
-       if (r < 0)
+       if (r < 0 && r != IFD_ERROR_NO_CARD)
                return r;
        switch (ret[7] & 3) {
        case 2:
_______________________________________________
opensc-devel mailing list
opensc-devel@lists.opensc-project.org
http://www.opensc-project.org/mailman/listinfo/opensc-devel

Reply via email to