[Pcsclite-muscle] [PATCH ccid]: Fix to get the supported clock frequencies

Guido Trentalancia guido at trentalancia.com
Thu Apr 8 21:36:45 BST 2021


Ask for bNumClockSupported supported clock frequencies
    
Some devices set bNumClockSupported to a value different from 0 but
libusb_control_transfer() fails if another value (like 256) is used.

The Bit4Id miniLector AIR NFC v3 (25DD:3403) seems to need this fix.

Signed-off-by: Guido Trentalancia <guido at trentalancia.com>

diff -pru ccid-1.4.34-to-git-08042021-0700/src/parse.c ccid-git-08042021-0700/src/parse.c
--- ccid-1.4.34-to-git-08042021-0700/src/parse.c	2021-04-08 21:51:23.354942352 +0200
+++ ccid-git-08042021-0700/src/parse.c	2021-04-08 06:55:26.700371266 +0200
@@ -412,16 +412,11 @@ static int ccid_parse_interface_descript
 
 	(void)printf("  dwDefaultClock: %.3f MHz\n", dw2i(device_descriptor, 10)/1000.0);
 	(void)printf("  dwMaximumClock: %.3f MHz\n", dw2i(device_descriptor, 14)/1000.0);
-	int bNumClockSupported = device_descriptor[18];
-	(void)printf("  bNumClockSupported: %d%s\n", bNumClockSupported,
-		bNumClockSupported ? "" : " (will use whatever is returned)");
+	(void)printf("  bNumClockSupported: %d%s\n", device_descriptor[18],
+		device_descriptor[18] ? "" : " (will use whatever is returned)");
 	{
 		int n;
 
-		if (0 == bNumClockSupported)
-			/* read up to the buffer size */
-			bNumClockSupported = sizeof(buffer) / sizeof(int);
-
 		/* See CCID 5.3.2 page 24 */
 		n = libusb_control_transfer(handle,
 			0xA1, /* request type */
@@ -429,7 +424,7 @@ static int ccid_parse_interface_descript
 			0x00, /* value */
 			usb_interface_descriptor->bInterfaceNumber, /* interface */
 			buffer,
-			bNumClockSupported * sizeof(int),
+			sizeof(buffer),
 			2 * 1000);
 
 		/* we got an error? */
@@ -451,15 +446,15 @@ static int ccid_parse_interface_descript
 				int i;
 
 				/* we do not get the expected number of data rates */
-				if ((n != bNumClockSupported*4) && bNumClockSupported)
+				if ((n != device_descriptor[18]*4) && device_descriptor[18])
 				{
 					(void)printf("   Got %d clock frequencies but was expecting %d\n",
-						n/4, bNumClockSupported);
+						n/4, device_descriptor[18]);
 
 					/* we got more data than expected */
 #ifndef DISPLAY_EXTRA_VALUES
-					if (n > bNumClockSupported*4)
-						n = bNumClockSupported*4;
+					if (n > device_descriptor[18]*4)
+						n = device_descriptor[18]*4;
 #endif
 				}
 
@@ -501,15 +496,15 @@ static int ccid_parse_interface_descript
 				int i;
 
 				/* we do not get the expected number of data rates */
-				if ((n != bNumDataRatesSupported*4) && bNumDataRatesSupported)
+				if ((n != device_descriptor[27]*4) && device_descriptor[27])
 				{
 					(void)printf("   Got %d data rates but was expecting %d\n", n/4,
-						bNumDataRatesSupported);
+						device_descriptor[27]);
 
 					/* we got more data than expected */
 #ifndef DISPLAY_EXTRA_VALUES
-					if (n > bNumDataRatesSupported*4)
-						n = bNumDataRatesSupported*4;
+					if (n > device_descriptor[27]*4)
+						n = device_descriptor[27]*4;
 #endif
 				}
 



More information about the pcsclite-muscle mailing list