Re: GemPC Express Reader

Joachim Breitner <[email protected]> Wed, 18 Feb 2009 00:43:16 +0100
Newsgroups gmane.comp.lib.libchipcard.devel
Message-ID <1234914196.4413.49.camel@localhost>
Hi again Martin and Ludovic,

I digged some deeper into libccid et al, and here is what I found out:

When calling IFDHSetProtocolParameters after IFDHPowerICC, I can
actually successfully talk to the card reader, use HBCI and use my gnupg
smartcard.

Here is what I found out:

 * The correct protocol (T=0 or T=1) can be gathered from the usb
information:

$ lsusb -v|grep -i dwProtocols
        dwProtocols             3  T=0 T=1

but strangely, for me it only worked with T=1.

 * The function IFDHSetProtocolParameters in
libccid’s ./src/ifdhandler.c seems have a wrongly documented calling
convention: The comment says
         * Protocol - 0 .... 14 T=0 .... T=14
for the protocol parameter, but the code (

        if (SCARD_PROTOCOL_T0 == Protocol)
                pps[1] |= ATR_PROTOCOL_TYPE_T0;
        else
                if (SCARD_PROTOCOL_T1 == Protocol)
                        pps[1] |= ATR_PROTOCOL_TYPE_T1;
                else
                        return IFD_PROTOCOL_NOT_SUPPORTED;

shows that the right parameters are 1 for T=0 and 2 for T=2. This is
also what I observed from testing.

 * To be able to use the card more than once in a row, without having to
eject and re-insert it, the protocol has to be set after a reset again.

I have attached a patch for libchipcard that makes it work for me. If it
is ok to always set protocol to T=1 (at least until there is someone for
whom it breaks), maybe it can be applied?


Thanks,
Joachim

-- 
Joachim Breitner
  e-Mail: [email protected]
  Homepage: http://www.joachim-breitner.de
  ICQ#: 74513189
  Jabber-ID: [email protected]

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H

_______________________________________________
Libchipcard-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libchipcard-devel
libchipcard-ccid.patch (text/plain, 3.3 KB)
diff -u libchipcard-4.2.4/debian/changelog libchipcard-4.2.4/debian/changelog
--- libchipcard-4.2.4/debian/changelog
+++ libchipcard-4.2.4/debian/changelog
@@ -1,3 +1,9 @@
+libchipcard (4.2.4-1.nomeata1) UNRELEASED; urgency=low
+
+  * Testing GemPC Express
+
+ -- Joachim Breitner <[email protected]>  Wed, 18 Feb 2009 00:22:52 +0100
+
 libchipcard (4.2.4-1) experimental; urgency=low
 
   * New upstream release
only in patch2:
unchanged:
--- libchipcard-4.2.4.orig/src/drivers/ifd/driverifd.c
+++ libchipcard-4.2.4/src/drivers/ifd/driverifd.c
@@ -285,6 +285,9 @@
   case CCID_ICC_NOT_PRESENT:
     s="Card not present";
     break;
+  case CCID_COMMUNICATION_ERROR:
+    s="Communication error";
+    break;
   default:
     s="Unknow error code";
   };
@@ -603,49 +606,35 @@
 
 
 uint32_t DriverIFD_ConnectSlot(LCD_DRIVER *d, LCD_SLOT *sl) {
-  int i;
+  int protocol;
   DRIVER_IFD *dct;
   long retval;
 
   assert(d);
   dct=GWEN_INHERIT_GETDATA(LCD_DRIVER, DRIVER_IFD, d);
   assert(dct);
-
+  
   retval=DriverIFD__ConnectSlot(d, sl);
-  if (retval!=CCID_ERROR_POWER_ACTION) {
+  if (retval) {
     DBG_INFO(LCD_Reader_GetLogger(LCD_Slot_GetReader(sl)),
-	     "CCID: Result is not POWER_ACTION (%d)",
+	     "CCID: Could not connect to slot (%d)",
 	     (int)retval);
     return retval;
   }
 
-  if (dct->setProtoFn==NULL)
+  // Here the protocol should be read from the usb field dwProtocol
+  DBG_INFO(LCD_Reader_GetLogger(LCD_Slot_GetReader(sl)),
+	   "CCID: Setting Protocol 1");
+  protocol = 2; // T1
+  retval=dct->setProtoFn(LCD_Slot_GetSlotNum(sl),
+			 protocol, 0, 0, 0, 0);
+  if (retval) {
+    DBG_INFO(LCD_Reader_GetLogger(LCD_Slot_GetReader(sl)),
+	     "CCID: Error setting protocol %d (%d)",
+	     protocol, (int)retval);
     return retval;
-
-  /* try protocols 0 through 15 */
-  for (i=0; i<16; i++) {
-    /* set protocol bt don't change PTS */
-    retval=dct->setProtoFn(LCD_Slot_GetSlotNum(sl),
-			   i, 0, 0, 0, 0);
-    if (retval) {
-      DBG_INFO(LCD_Reader_GetLogger(LCD_Slot_GetReader(sl)),
-	       "CCID: Error setting protocol %d (%d)",
-	       i, (int)retval);
-    }
-    else {
-      retval=DriverIFD__ConnectSlot(d, sl);
-      if (retval!=CCID_ERROR_POWER_ACTION) {
-	DBG_INFO(LCD_Reader_GetLogger(LCD_Slot_GetReader(sl)),
-		 "CCID: Result is not POWER_ACTION (%d, proto=%d)",
-		 (int)retval, i);
-	return retval;
-      }
-    }
   }
 
-  /* assuming no card inserted */
-  DBG_INFO(LCD_Reader_GetLogger(LCD_Slot_GetReader(sl)),
-	   "Assuming no card is inserted");
   return 0;
 }
 
@@ -689,6 +678,7 @@
 uint32_t DriverIFD_ResetSlot(LCD_DRIVER *d, LCD_SLOT *sl) {
   long retval;
   unsigned char atrBuffer[300];
+  int protocol;
   DWORD atrLen;
   DRIVER_IFD *dct;
 
@@ -724,6 +714,19 @@
     LCD_Slot_SubStatus(sl, LCD_SLOT_STATUS_CARD_INSERTED);
   }
 
+  // Here the protocol should be read from the usb field dwProtocol
+  DBG_INFO(LCD_Reader_GetLogger(LCD_Slot_GetReader(sl)),
+	   "CCID: Setting Protocol 1");
+  protocol = 2; // T1
+  retval=dct->setProtoFn(LCD_Slot_GetSlotNum(sl),
+			 protocol, 0, 0, 0, 0);
+  if (retval) {
+    DBG_INFO(LCD_Reader_GetLogger(LCD_Slot_GetReader(sl)),
+	     "CCID: Error setting protocol %d (%d)",
+	     protocol, (int)retval);
+    return retval;
+  }
+
   return 0;
 }
signature.asc (application/pgp-signature, 197 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEABECAAYFAkmbS5QACgkQ9ijrk0dDIGy1zACeMFKvOcne+12YGXDTxijxvlKS
DY8Anj1+2dhYuIl8F96rGoxjewBwC6eA
=K3Jo
-----END PGP SIGNATURE-----