[Pcsclite-cvs-commit] r6252 - in /trunk/Drivers/ccid/src: ccid.c ccid.h ccid_serial.c ccid_usb.c commands.c

rousseau at users.alioth.debian.org rousseau at users.alioth.debian.org
Tue Mar 27 12:58:13 UTC 2012


Author: rousseau
Date: Tue Mar 27 12:58:12 2012
New Revision: 6252

URL: http://svn.debian.org/wsvn/pcsclite/?sc=1&rev=6252
Log:
Add support of Gemalto firmware features

Gemalto readers support an Escape command to report features supported
(or not) by the reader. The reader can also report if specific bugs are
fixed or not.

One of the fixed bug (in recent readers) is the bNumberMessage
management used in the Secure Modify CCID command.

Thanks to Jean Lusetti for the patch

Modified:
    trunk/Drivers/ccid/src/ccid.c
    trunk/Drivers/ccid/src/ccid.h
    trunk/Drivers/ccid/src/ccid_serial.c
    trunk/Drivers/ccid/src/ccid_usb.c
    trunk/Drivers/ccid/src/commands.c

Modified: trunk/Drivers/ccid/src/ccid.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/Drivers/ccid/src/ccid.c?rev=6252&op=diff
==============================================================================
--- trunk/Drivers/ccid/src/ccid.c (original)
+++ trunk/Drivers/ccid/src/ccid.c Tue Mar 27 12:58:12 2012
@@ -110,6 +110,102 @@
 
 	return 0;
 } /* ccid_open_hack_pre */
+
+#ifndef NO_LOG
+/*****************************************************************************
+ *
+ *					dump_gemalto_firmware_features
+ *
+ ****************************************************************************/
+static void dump_gemalto_firmware_features(struct GEMALTO_FIRMWARE_FEATURES *gff)
+{
+	DEBUG_INFO2("Dumping Gemalto firmware features (%ld bytes):",
+		sizeof(struct GEMALTO_FIRMWARE_FEATURES));
+
+#define YESNO(x) (x) ? "yes" : "no"
+
+	DEBUG_INFO2(" bLogicalLCDLineNumber: %d", gff->bLogicalLCDLineNumber);
+	DEBUG_INFO2(" bLogicalLCDRowNumber: %d", gff->bLogicalLCDRowNumber);
+	DEBUG_INFO2(" bLcdInfo: 0x%02X", gff->bLcdInfo);
+	DEBUG_INFO2(" bEntryValidationCondition: 0x%02X",
+		gff->bEntryValidationCondition);
+
+	DEBUG_INFO(" Reader supports PC/SCv2 features:");
+	DEBUG_INFO2("  VerifyPinStart: %s", YESNO(gff->VerifyPinStart));
+	DEBUG_INFO2("  VerifyPinFinish: %s", YESNO(gff->VerifyPinFinish));
+	DEBUG_INFO2("  ModifyPinStart: %s", YESNO(gff->ModifyPinStart));
+	DEBUG_INFO2("  ModifyPinFinish: %s", YESNO(gff->ModifyPinFinish));
+	DEBUG_INFO2("  GetKeyPressed: %s", YESNO(gff->GetKeyPressed));
+	DEBUG_INFO2("  VerifyPinDirect: %s", YESNO(gff->VerifyPinDirect));
+	DEBUG_INFO2("  ModifyPinDirect: %s", YESNO(gff->ModifyPinDirect));
+	DEBUG_INFO2("  Abort: %s", YESNO(gff->Abort));
+	DEBUG_INFO2("  GetKey: %s", YESNO(gff->GetKey));
+	DEBUG_INFO2("  WriteDisplay: %s", YESNO(gff->WriteDisplay));
+	DEBUG_INFO2("  SetSpeMessage: %s", YESNO(gff->SetSpeMessage));
+	DEBUG_INFO2("  bTimeOut2: %s", YESNO(gff->bTimeOut2));
+	DEBUG_INFO2("  bPPDUSupportOverXferBlock: %s",
+		YESNO(gff->bPPDUSupportOverXferBlock));
+	DEBUG_INFO2("  bPPDUSupportOverEscape: %s",
+		YESNO(gff->bPPDUSupportOverEscape));
+
+	DEBUG_INFO2(" bListSupportedLanguages: %s",
+		YESNO(gff->bListSupportedLanguages));
+	DEBUG_INFO2(" bNumberMessageFix: %s", YESNO(gff->bNumberMessageFix));
+
+	DEBUG_INFO2(" VersionNumber: 0x%02X", gff->VersionNumber);
+	DEBUG_INFO2(" MinimumPINSize: %d", gff->MinimumPINSize);
+	DEBUG_INFO2(" MaximumPINSize: %d", gff->MaximumPINSize);
+	DEBUG_INFO2(" Firewall: %s", YESNO(gff->Firewall));
+	if (gff->Firewall && gff->FirewalledCommand_SW1
+		&& gff->FirewalledCommand_SW2)
+	{
+		DEBUG_INFO2("  FirewalledCommand_SW1: 0x%02X",
+			gff->FirewalledCommand_SW1);
+		DEBUG_INFO2("  FirewalledCommand_SW2: 0x%02X",
+			gff->FirewalledCommand_SW2);
+	}
+
+} /* dump_gemalto_firmware_features */
+#endif
+
+/*****************************************************************************
+ *
+ *					set_gemalto_firmware_features
+ *
+ ****************************************************************************/
+static void set_gemalto_firmware_features(unsigned int reader_index)
+{
+	_ccid_descriptor *ccid_descriptor = get_ccid_descriptor(reader_index);
+	struct GEMALTO_FIRMWARE_FEATURES *gf_features;
+
+	gf_features = malloc(sizeof(struct GEMALTO_FIRMWARE_FEATURES));
+	if (gf_features)
+	{
+		unsigned char cmd[] = { 0x6A }; /* GET_FIRMWARE_FEATURES command id */
+		unsigned int len_features = sizeof *gf_features;
+		RESPONSECODE ret;
+
+		ret = CmdEscape(reader_index, cmd, sizeof cmd,
+			(unsigned char*)gf_features, &len_features);
+		if ((IFD_SUCCESS == ret) &&
+		    (len_features == sizeof *gf_features))
+		{
+			/* Command is supported if it succeeds at CCID level */
+			/* and returned size matches our expectation */
+			ccid_descriptor->gemalto_firmware_features = gf_features;
+#ifndef NO_LOG
+			dump_gemalto_firmware_features(gf_features);
+#endif
+		}
+		else
+		{
+			/* Command is not supported, let's free allocated memory */
+			free(gf_features);
+			DEBUG_INFO3("GET_FIRMWARE_FEATURES failed: %ld, len=%d",
+				ret, len_features);
+		}
+	}
+} /* set_gemalto_firmware_features */
 
 /*****************************************************************************
  *
@@ -377,6 +473,10 @@
 #endif
 	}
 
+	/* Gemalto readers may report additional information */
+	if (GET_VENDOR(ccid_descriptor->readerID) == VENDOR_GEMALTO)
+		set_gemalto_firmware_features(reader_index);
+
 	return return_value;
 } /* ccid_open_hack_post */
 

Modified: trunk/Drivers/ccid/src/ccid.h
URL: http://svn.debian.org/wsvn/pcsclite/trunk/Drivers/ccid/src/ccid.h?rev=6252&op=diff
==============================================================================
--- trunk/Drivers/ccid/src/ccid.h (original)
+++ trunk/Drivers/ccid/src/ccid.h Tue Mar 27 12:58:12 2012
@@ -136,6 +136,11 @@
 	 * USB bcdDevice
 	 */
 	int IFD_bcdDevice;
+
+	/*
+	 * Gemalto extra features, if any
+	 */
+	struct GEMALTO_FIRMWARE_FEATURES *gemalto_firmware_features;
 } _ccid_descriptor;
 
 /* Features from dwFeatures */
@@ -257,7 +262,7 @@
 #define GEMPLUS_CUSTOM_DATA_RATES 10753, 21505, 43011, 125000
 
 /* Structure returned by Gemalto readers for the CCID Escape command 0x6A */
-typedef struct
+struct GEMALTO_FIRMWARE_FEATURES
 {
 	UCHAR	bLogicalLCDLineNumber;	/* Logical number of LCD lines */
 	UCHAR	bLogicalLCDRowNumber;	/* Logical number of characters per LCD line */
@@ -310,5 +315,5 @@
 	UCHAR	FirewalledCommand_SW1;
 	UCHAR	FirewalledCommand_SW2;
 	UCHAR	RFUb6[3];
-} GEMALTO_FIRMWARE_FEATURES;
-
+};
+

Modified: trunk/Drivers/ccid/src/ccid_serial.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/Drivers/ccid/src/ccid_serial.c?rev=6252&op=diff
==============================================================================
--- trunk/Drivers/ccid/src/ccid_serial.c (original)
+++ trunk/Drivers/ccid/src/ccid_serial.c Tue Mar 27 12:58:12 2012
@@ -600,6 +600,7 @@
 	serialDevice[reader_index].ccid.arrayOfSupportedDataRates = SerialTwinDataRates;
 	serialDevice[reader_index].ccid.dwSlotStatus = IFD_ICC_PRESENT;
 	serialDevice[reader_index].ccid.bVoltageSupport = 0x07;	/* 1.8V, 3V and 5V */
+	serialDevice[reader_index].ccid.gemalto_firmware_features = NULL;
 	serialDevice[reader_index].echo = TRUE;
 
 	/* change some values depending on the reader */

Modified: trunk/Drivers/ccid/src/ccid_usb.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/Drivers/ccid/src/ccid_usb.c?rev=6252&op=diff
==============================================================================
--- trunk/Drivers/ccid/src/ccid_usb.c (original)
+++ trunk/Drivers/ccid/src/ccid_usb.c Tue Mar 27 12:58:12 2012
@@ -561,6 +561,7 @@
 				usbDevice[reader_index].ccid.dwSlotStatus = IFD_ICC_PRESENT;
 				usbDevice[reader_index].ccid.bVoltageSupport = device_descriptor[5];
 				usbDevice[reader_index].ccid.sIFD_serial_number = NULL;
+				usbDevice[reader_index].ccid.gemalto_firmware_features = NULL;
 				if (desc.iSerialNumber)
 				{
 					unsigned char serial[128];
@@ -733,6 +734,12 @@
 	{
 		free(usbDevice[reader_index].ccid.arrayOfSupportedDataRates);
 		usbDevice[reader_index].ccid.arrayOfSupportedDataRates = NULL;
+	}
+
+	if (usbDevice[reader_index].ccid.gemalto_firmware_features)
+	{
+		free(usbDevice[reader_index].ccid.gemalto_firmware_features);
+		usbDevice[reader_index].ccid.gemalto_firmware_features = NULL ;
 	}
 
 	/* one slot closed */

Modified: trunk/Drivers/ccid/src/commands.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/Drivers/ccid/src/commands.c?rev=6252&op=diff
==============================================================================
--- trunk/Drivers/ccid/src/commands.c (original)
+++ trunk/Drivers/ccid/src/commands.c Tue Mar 27 12:58:12 2012
@@ -500,6 +500,44 @@
 	return ret;
 } /* SecurePINVerify */
 
+
+#ifdef BOGUS_PINPAD_FIRMWARE
+/*****************************************************************************
+ *
+ *					has_gemalto_modify_pin_bug
+ *
+ ****************************************************************************/
+static int has_gemalto_modify_pin_bug(_ccid_descriptor *ccid_descriptor)
+{
+	/* Bug not present by default */
+	int has_bug = 0;
+
+	/* Covadis Véga-Alpha reader */
+	if (VEGAALPHA == ccid_descriptor->readerID)
+	{
+		/* This reader has the bug (uses a Gemalto firmware) */
+		has_bug = 1;
+	}
+	else
+	{
+		/* Gemalto reader */
+		if ((GET_VENDOR(ccid_descriptor->readerID) == VENDOR_GEMALTO))
+		{
+			has_bug = 1; /* assume it has the bug */
+
+			if (ccid_descriptor->gemalto_firmware_features &&
+				ccid_descriptor->gemalto_firmware_features->bNumberMessageFix)
+			{
+				/* A Gemalto reader has the ModifyPIN structure bug */
+				/* unless it explicitly reports it has been fixed */
+				has_bug = 0;
+			}
+		}
+	}
+
+	return has_bug;
+} /* has_gemalto_modify_pin_bug */
+#endif
 
 /*****************************************************************************
  *
@@ -518,6 +556,7 @@
 	RESPONSECODE ret;
 #ifdef BOGUS_PINPAD_FIRMWARE
 	int bNumberMessage = 0; /* for GemPC Pinpad */
+	int gemalto_modify_pin_bug;
 #endif
 
 	pms = (PIN_MODIFY_STRUCTURE *)TxBuffer;
@@ -608,6 +647,12 @@
 				TxBuffer[10]);
 			TxBuffer[10] = 0x02;	/* validation key pressed */
 		}
+	}
+
+	gemalto_modify_pin_bug = has_gemalto_modify_pin_bug(ccid_descriptor);
+	if (gemalto_modify_pin_bug)
+	{
+		DEBUG_INFO("Gemalto CCID Modify Pin Bug");
 
 		/* The reader requests a value for bMsgIndex2 and bMsgIndex3
 		 * even if they should not be present. So we fake
@@ -693,8 +738,7 @@
 		cmd[21] = 0x00; /* set bNumberMessage to 0 */
 	}
 
-	if ((GEMPCPINPAD == ccid_descriptor->readerID)
-		|| (VEGAALPHA == ccid_descriptor->readerID))
+	if (gemalto_modify_pin_bug)
 		cmd[21] = bNumberMessage;	/* restore the real value */
 #endif
 




More information about the Pcsclite-cvs-commit mailing list