Apply fix "OpenUSBByName(): the device bus & addr must match" (8b9f6f33) for libusb

Maximilian Stein <[email protected]> Thu, 16 Feb 2017 16:34:49 +0100
Newsgroups gmane.comp.lib.muscle
Message-ID <[email protected]>
Hi,

I noticed that commits [1] and [2], which fixed initialising a wrong USB
device if the PID/VID are identical, only regards pcscd configured with
libudev. In my opinion this can and should be fixed for pcscd configured
with libusb as well. Please see the attached patch.

Kind regards
Maximilian Stein

[1] 8b9f6f33b16e808a5769dbc4193e5f107a09a693 - OpenUSBByName(): the
device bus & addr must match
[2] e46fa30ead3f1eff72769d70be6adf031fafe606 - OpenUSBByName(): use
device bus and address only when available

_______________________________________________
Pcsclite-muscle mailing list
[email protected]
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pcsclite-muscle
openusbbyname_match_bus_addr_libusb.patch (text/x-patch, 721 B)
diff --git a/src/ccid_usb.c b/src/ccid_usb.c
index 1598f9e..9d86c37 100644
--- a/src/ccid_usb.c
+++ b/src/ccid_usb.c
@@ -270,6 +270,16 @@ status_t OpenUSBByName(unsigned int reader_index, /*@null@*/ char *device)
 				DEBUG_COMM3("usb bus/device: %d/%d", device_bus, device_addr);
 			}
 		}
+		/* format usb:%04x/%04x:libusb-1.0:%d:%d:%d */
+		else if ((dirname = strstr(device, "libusb-1.0:")) != NULL)
+		{
+			/* convert the interface number, bus and device ids */
+			if (sscanf(dirname + 11, "%d:%d:%d", &device_bus, &device_addr, &interface_number) == 3)
+			{
+				DEBUG_COMM2("interface_number: %d", interface_number);
+				DEBUG_COMM3("usb bus/device: %d/%d", device_bus, device_addr);
+			}
+		}
 	}
 #endif