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

Guido Trentalancia guido at trentalancia.com
Thu Apr 8 22:15:39 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-git-08042021-0700/src/parse.c ccid-1.4.34-to-git-08042021-0700/src/parse.c
--- ccid-git-08042021-0700/src/parse.c	2021-04-08 06:55:26.700371266 +0200
+++ ccid-1.4.34-to-git-08042021-0700/src/parse.c	2021-04-08 21:51:23.354942352 +0200
@@ -412,11 +412,16 @@ 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);
-	(void)printf("  bNumClockSupported: %d%s\n", device_descriptor[18],
-		device_descriptor[18] ? "" : " (will use whatever is returned)");
+	int bNumClockSupported = device_descriptor[18];
+	(void)printf("  bNumClockSupported: %d%s\n", bNumClockSupported,
+		bNumClockSupported ? "" : " (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 */
@@ -424,7 +429,7 @@ static int ccid_parse_interface_descript
 			0x00, /* value */
 			usb_interface_descriptor->bInterfaceNumber, /* interface */
 			buffer,
-			sizeof(buffer),
+			bNumClockSupported * sizeof(int),
 			2 * 1000);
 
 		/* we got an error? */
@@ -446,15 +451,15 @@ static int ccid_parse_interface_descript
 				int i;
 
 				/* we do not get the expected number of data rates */
-				if ((n != device_descriptor[18]*4) && device_descriptor[18])
+				if ((n != bNumClockSupported*4) && bNumClockSupported)
 				{
 					(void)printf("   Got %d clock frequencies but was expecting %d\n",
-						n/4, device_descriptor[18]);
+						n/4, bNumClockSupported);
 
 					/* we got more data than expected */
 #ifndef DISPLAY_EXTRA_VALUES
-					if (n > device_descriptor[18]*4)
-						n = device_descriptor[18]*4;
+					if (n > bNumClockSupported*4)
+						n = bNumClockSupported*4;
 #endif
 				}
 



More information about the pcsclite-muscle mailing list