[Pcsclite-git-commit] [CCID] 01/01: OpenUSBByName(): the device bus & addr must match
Ludovic Rousseau
rousseau at moszumanska.debian.org
Tue Nov 10 16:09:25 UTC 2015
This is an automated email from the git hooks/post-receive script.
rousseau pushed a commit to branch master
in repository CCID.
commit 8b9f6f33b16e808a5769dbc4193e5f107a09a693
Author: Santiago Gimeno <santiago.gimeno at ionide.es>
Date: Tue Nov 3 17:24:49 2015 +0100
OpenUSBByName(): the device bus & addr must match
In Linux, before this change, if there were multiple card readers of the same
model connected, a new Reader could be initialized by opening the wrong USB
device.
---
src/ccid_usb.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/src/ccid_usb.c b/src/ccid_usb.c
index c5d3fa0..92edf93 100644
--- a/src/ccid_usb.c
+++ b/src/ccid_usb.c
@@ -214,6 +214,8 @@ status_t OpenUSBByName(unsigned int reader_index, /*@null@*/ char *device)
char infofile[FILENAME_MAX];
#ifndef __APPLE__
unsigned int device_vendor, device_product;
+ unsigned int device_bus = 0;
+ unsigned int device_addr = 0;
#else
/* 100 ms delay */
struct timespec sleep_time = { 0, 100 * 1000 * 1000 };
@@ -259,9 +261,11 @@ status_t OpenUSBByName(unsigned int reader_index, /*@null@*/ char *device)
*/
if ((dirname = strstr(device, "libudev:")) != NULL)
{
- /* convert the interface number */
- interface_number = atoi(dirname + 8 /* "libudev:" */);
- DEBUG_COMM2("interface_number: %d", interface_number);
+ /* convert the interface number, bus and device ids */
+ if (sscanf(dirname + 8, "%d:/dev/bus/usb/%d/%d", &interface_number, &device_bus, &device_addr) == 3) {
+ DEBUG_COMM2("interface_number: %d", interface_number);
+ DEBUG_COMM3("usb bus/device: %d/%d", device_bus, device_addr);
+ }
}
}
#endif
@@ -373,6 +377,14 @@ again_libusb:
uint8_t bus_number = libusb_get_bus_number(dev);
uint8_t device_address = libusb_get_device_address(dev);
+#ifndef __APPLE__
+ if ((bus_number != device_bus)
+ || (device_address != device_addr)) {
+ /* not USB the device we are looking for */
+ continue;
+ }
+#endif
+
int r = libusb_get_device_descriptor(dev, &desc);
if (r < 0)
{
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pcsclite/CCID.git
More information about the Pcsclite-cvs-commit
mailing list