[Pcsclite-cvs-commit] CVS Drivers/ccid/src
CVS User rousseau
ludovic.rousseau@free.fr
Tue, 26 Apr 2005 13:43:13 +0000
Update of /cvsroot/pcsclite/Drivers/ccid/src
In directory haydn:/tmp/cvs-serv10036
Modified Files:
ccid_usb.c
Log Message:
OpenUSBByName(): get the list of data rates the reader supports
See 3.7.3 Get Data Rates (page 25) from CCID spec 1.00
--- /cvsroot/pcsclite/Drivers/ccid/src/ccid_usb.c 2005/03/14 18:56:51 1.47
+++ /cvsroot/pcsclite/Drivers/ccid/src/ccid_usb.c 2005/04/26 13:43:13 1.48
@@ -18,7 +18,7 @@
*/
/*
- * $Id: ccid_usb.c,v 1.47 2005/03/14 18:56:51 rousseau Exp $
+ * $Id: ccid_usb.c,v 1.48 2005/04/26 13:43:13 rousseau Exp $
*/
#define __CCID_USB__
@@ -91,6 +91,7 @@
static int get_end_points(struct usb_device *dev, _usbDevice *usb_device);
int ccid_check_firmware(struct usb_device *dev);
+static int *get_data_rates(unsigned int reader_index);
/* ne need to initialize to 0 since it is static */
static _usbDevice usbDevice[CCID_DRIVER_MAX_READERS];
@@ -403,6 +404,7 @@
usbDevice[reader_index].ccid.dwMaxDataRate = dw2i(usb_interface->altsetting->extra, 23);
usbDevice[reader_index].ccid.bMaxSlotIndex = usb_interface->altsetting->extra[4];
usbDevice[reader_index].ccid.bCurrentSlotIndex = 0;
+ usbDevice[reader_index].ccid.arrayOfSupportedDataRates = get_data_rates(reader_index);
goto end;
}
}
@@ -508,6 +510,9 @@
usbDevice[reader_index].dev->bus->dirname,
usbDevice[reader_index].dev->filename);
+ if (usbDevice[reader_index].ccid.arrayOfSupportedDataRates)
+ free(usbDevice[reader_index].ccid.arrayOfSupportedDataRates);
+
/* reset so that bSeq starts at 0 again */
usb_reset(usbDevice[reader_index].handle);
@@ -686,3 +691,53 @@
return FALSE;
} /* ccid_check_firmware */
+/*****************************************************************************
+ *
+ * get_data_rates
+ *
+ ****************************************************************************/
+static int *get_data_rates(unsigned int reader_index)
+{
+ int n, i;
+ unsigned char buffer[256*sizeof(int)]; /* maximum is 256 records */
+ unsigned int *int_array;
+
+ /* See CCID 3.7.3 page 25 */
+ n = usb_control_msg(usbDevice[reader_index].handle,
+ 0xA1, /* request type */
+ 0x03, /* GET_DATA_RATES */
+ 0x00, /* value */
+ 0x00, /* interface */
+ buffer,
+ sizeof(buffer),
+ USB_READ_TIMEOUT);
+
+ /* we got an error? */
+ if (n <= 0)
+ {
+ DEBUG_CRITICAL2("IFD does not support GET_DATA_RATES request but should: %s", strerror(errno));
+ return NULL;
+ }
+
+ /* allocate the buffer (including the end marker) */
+ n /= sizeof(int);
+ int_array = calloc(n+1, sizeof(int));
+ if (NULL == buffer)
+ {
+ DEBUG_CRITICAL("Memory allocation failed");
+ return NULL;
+ }
+
+ /* convert in correct endianess */
+ for (i=0; i<n; i++)
+ {
+ int_array[i] = dw2i(buffer, i*4);
+ DEBUG_INFO2("declared: %d bps", int_array[i]);
+ }
+
+ /* end of array marker */
+ int_array[i] = 0;
+
+ return int_array;
+}
+