components/ccid/patches/01-ccid_usb.c.patch
author Stephen Gaul Jr <steve.gaul@oracle.com>
Fri, 03 Jun 2016 09:30:42 -0700
changeset 6133 73641150a4de
permissions -rw-r--r--
PSARC/2016/217 Smartcard Reintroduction PSARC/2016/218 USB CCID PSARC/2016/221 PC/SC Lite smartcard middleware 22017759 Add pcsclite v1.8.14 to Userland consolidation 22017751 Add libccid v1.4.20 to Userland consolidation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6133
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
     1
In-house patch created for multiple CCID usb issues seen on Solaris:
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
     2
busy loop, race condition and the closing of libusb. 
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
     3
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
     4
This is similar to several different upstream patches for the same ccid_usb.c 
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
     5
issues to that will be fixed in a future release of ccid.
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
     6
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
     7
--- ccid-1.4.20/src/ccid_usb.c	2016-05-17 10:28:40.585070162 -0400
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
     8
+++ ccid-1.4.20/src/ccid_usb.c	2016-05-10 22:55:51.214474582 -0400
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
     9
@@ -17,10 +17,6 @@
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    10
 	Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    11
 */
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    12
 
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    13
-/*
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    14
- * $Id$
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    15
- */
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    16
-
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    17
 #define __CCID_USB__
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    18
 
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    19
 #include <stdio.h>
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    20
@@ -178,6 +174,9 @@
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    21
 {
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    22
 	int i, to_exit = TRUE;
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    23
 
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    24
+	if (NULL == ctx)
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    25
+		return;
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    26
+
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    27
 	/* if at least 1 reader is still in use we do not exit libusb */
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    28
 	for (i=0; i<CCID_DRIVER_MAX_READERS; i++)
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    29
 	{
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    30
@@ -218,9 +217,12 @@
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    31
 	char infofile[FILENAME_MAX];
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    32
 #ifndef __APPLE__
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    33
 	unsigned int device_vendor, device_product;
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    34
+	unsigned int device_bus = 0;
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    35
+	unsigned int device_addr = 0;
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    36
 #else
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    37
 	/* 100 ms delay */
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    38
 	struct timespec sleep_time = { 0, 100 * 1000 * 1000 };
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    39
+	int count_libusb = 10;
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    40
 #endif
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    41
 	int interface_number = -1;
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    42
 	int i;
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    43
@@ -262,9 +264,11 @@
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    44
 		 */
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    45
 		if ((dirname = strstr(device, "libudev:")) != NULL)
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    46
 		{
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    47
-			/* convert the interface number */
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    48
-			interface_number = atoi(dirname + 8 /* "libudev:" */);
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    49
-			DEBUG_COMM2("interface_number: %d", interface_number);
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    50
+			/* convert the interface number, bus and device ids */
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    51
+			if (sscanf(dirname + 8, "%d:/dev/bus/usb/%d/%d", &interface_number, &device_bus, &device_addr) == 3) {
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    52
+				DEBUG_COMM2("interface_number: %d", interface_number);
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    53
+				DEBUG_COMM3("usb bus/device: %d/%d", device_bus, device_addr);
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    54
+			}
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    55
 		}
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    56
 	}
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    57
 #endif
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    58
@@ -307,31 +311,19 @@
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    59
 		rv = libusb_init(&ctx);
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    60
 		if (rv != 0)
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    61
 		{
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    62
-			DEBUG_CRITICAL2("libusb_init failed: %d", rv);
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    63
+			DEBUG_CRITICAL2("libusb_init failed: %s", libusb_error_name(rv));
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    64
 			return_value = STATUS_UNSUCCESSFUL;
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    65
 			goto end1;
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    66
 		}
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    67
 	}
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    68
 
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    69
-#ifdef __APPLE__
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    70
-	/* give some time to libusb to detect the new USB devices on Mac OS X */
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    71
-	nanosleep(&sleep_time, NULL);
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    72
-#endif
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    73
-	cnt = libusb_get_device_list(ctx, &devs);
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    74
-	if (cnt < 0)
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    75
-	{
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    76
-		DEBUG_CRITICAL("libusb_get_device_list() failed\n");
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    77
-		return_value = STATUS_UNSUCCESSFUL;
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    78
-		goto end1;
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    79
-	}
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    80
-
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    81
 #define GET_KEYS(key, values) \
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    82
 	rv = LTPBundleFindValueWithKey(&plist, key, values); \
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    83
 	if (rv) \
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    84
 	{ \
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    85
 		DEBUG_CRITICAL2("Value/Key not defined for " key " in %s", infofile); \
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    86
 		return_value = STATUS_UNSUCCESSFUL; \
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    87
-		goto end2; \
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    88
+		goto end1; \
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    89
 	}
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    90
 
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    91
 	GET_KEYS("ifdVendorID", &ifdVendorID)
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    92
@@ -347,6 +339,17 @@
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    93
 		goto end1;
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    94
 	}
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    95
 
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    96
+#ifdef __APPLE__
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    97
+again_libusb:
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    98
+#endif
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    99
+	cnt = libusb_get_device_list(ctx, &devs);
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   100
+	if (cnt < 0)
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   101
+	{
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   102
+		DEBUG_CRITICAL("libusb_get_device_list() failed\n");
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   103
+		return_value = STATUS_UNSUCCESSFUL;
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   104
+		goto end1;
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   105
+	}
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   106
+
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   107
 	/* for any supported reader */
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   108
 	for (alias=0; alias<list_size(ifdVendorID); alias++)
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   109
 	{
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   110
@@ -377,6 +380,16 @@
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   111
 			uint8_t bus_number = libusb_get_bus_number(dev);
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   112
 			uint8_t device_address = libusb_get_device_address(dev);
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   113
 
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   114
+#ifndef __APPLE__
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   115
+			if ((device_bus || device_addr)
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   116
+				&& ((bus_number != device_bus)
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   117
+				|| (device_address != device_addr))) {
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   118
+				/* not USB the device we are looking for */
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   119
+				continue;
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   120
+			}
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   121
+#endif
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   122
+			DEBUG_COMM3("Try device: %d/%d", bus_number, device_address);
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   123
+
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   124
 			int r = libusb_get_device_descriptor(dev, &desc);
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   125
 			if (r < 0)
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   126
 			{
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   127
@@ -385,6 +398,8 @@
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   128
 				continue;
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   129
 			}
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   130
 
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   131
+			DEBUG_COMM3("vid/pid : %04X/%04X", desc.idVendor, desc.idProduct);
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   132
+
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   133
 			if (desc.idVendor == vendorID && desc.idProduct == productID)
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   134
 			{
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   135
 				int already_used;
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   136
@@ -399,7 +414,8 @@
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   137
 
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   138
 				/* simulate a composite device as when libudev is used */
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   139
 				if ((GEMALTOPROXDU == readerID)
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   140
-					|| (GEMALTOPROXSU == readerID))
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   141
+					|| (GEMALTOPROXSU == readerID)
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   142
+					|| (FEITIANR502DUAL == readerID))
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   143
 				{
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   144
 						/*
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   145
 						 * We can't talk to the two CCID interfaces
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   146
@@ -496,8 +512,8 @@
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   147
 				r = libusb_open(dev, &dev_handle);
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   148
 				if (r < 0)
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   149
 				{
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   150
-					DEBUG_CRITICAL4("Can't libusb_open(%d/%d): %d",
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   151
-						bus_number, device_address, r);
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   152
+					DEBUG_CRITICAL4("Can't libusb_open(%d/%d): %s",
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   153
+						bus_number, device_address, libusb_error_name(r));
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   154
 
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   155
 					continue;
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   156
 				}
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   157
@@ -522,8 +538,9 @@
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   158
 						if (r < 0)
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   159
 						{
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   160
 							(void)libusb_close(dev_handle);
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   161
-							DEBUG_CRITICAL4("Can't set configuration on %d/%d: %d",
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   162
-									bus_number, device_address, r);
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   163
+							DEBUG_CRITICAL4("Can't set configuration on %d/%d: %s",
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   164
+									bus_number, device_address,
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   165
+									libusb_error_name(r));
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   166
 							continue;
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   167
 						}
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   168
 					}
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   169
@@ -534,8 +551,8 @@
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   170
 					{
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   171
 #endif
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   172
 						(void)libusb_close(dev_handle);
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   173
-						DEBUG_CRITICAL4("Can't get config descriptor on %d/%d: %d",
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   174
-							bus_number, device_address, r);
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   175
+						DEBUG_CRITICAL4("Can't get config descriptor on %d/%d: %s",
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   176
+							bus_number, device_address, libusb_error_name(r));
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   177
 						continue;
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   178
 					}
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   179
 #ifdef __APPLE__
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   180
@@ -570,7 +587,7 @@
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   181
 					/* an interface was specified and it is not the
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   182
 					 * current one */
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   183
 					DEBUG_INFO3("Found interface %d but expecting %d",
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   184
-						interface_number, interface);
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   185
+						interface, interface_number);
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   186
 					DEBUG_INFO3("Wrong interface for USB device %d/%d."
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   187
 						" Checking next one.", bus_number, device_address);
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   188
 
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   189
@@ -584,8 +601,8 @@
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   190
 				if (r < 0)
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   191
 				{
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   192
 					(void)libusb_close(dev_handle);
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   193
-					DEBUG_CRITICAL4("Can't claim interface %d/%d: %d",
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   194
-						bus_number, device_address, r);
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   195
+					DEBUG_CRITICAL4("Can't claim interface %d/%d: %s",
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   196
+						bus_number, device_address, libusb_error_name(r));
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   197
 					claim_failed = TRUE;
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   198
 					interface_number = -1;
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   199
 					continue;
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   200
@@ -610,7 +627,7 @@
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   201
 
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   202
 				/* reset for a next reader */
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   203
 				if (static_interface > 2)
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   204
-					static_interface = 1;
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   205
+					static_interface = (FEITIANR502DUAL == readerID) ? 0: 1;
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   206
 #endif
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   207
 
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   208
 				/* Get Endpoints values*/
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   209
@@ -696,7 +713,23 @@
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   210
 end:
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   211
 	if (usbDevice[reader_index].dev_handle == NULL)
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   212
 	{
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   213
+		/* free the libusb allocated list & devices */
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   214
+		libusb_free_device_list(devs, 1);
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   215
+
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   216
+#ifdef __APPLE__
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   217
+		/* give some time to libusb to detect the new USB devices on Mac OS X */
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   218
+		if (count_libusb > 0)
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   219
+		{
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   220
+			count_libusb--;
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   221
+			DEBUG_INFO2("Wait after libusb: %d", count_libusb);
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   222
+			nanosleep(&sleep_time, NULL);
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   223
+
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   224
+			goto again_libusb;
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   225
+		}
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   226
+#endif
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   227
+		/* failed */
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   228
 		close_libusb_if_needed();
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   229
+
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   230
 		if (claim_failed)
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   231
 			return STATUS_COMM_ERROR;
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   232
 		DEBUG_INFO1("Device not found?");
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   233
@@ -715,6 +748,9 @@
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   234
 	/* free bundle list */
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   235
 	bundleRelease(&plist);
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   236
 
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   237
+	if (return_value != STATUS_SUCCESS)
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   238
+		close_libusb_if_needed();
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   239
+
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   240
 	return return_value;
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   241
 } /* OpenUSBByName */
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   242
 
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   243
@@ -868,10 +904,6 @@
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   244
 		if (usbDevice[reader_index].ccid.sIFD_iManufacturer)
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   245
 			free(usbDevice[reader_index].ccid.sIFD_iManufacturer);
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   246
 
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   247
-		/* reset so that bSeq starts at 0 again */
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   248
-		if (DriverOptions & DRIVER_OPTION_RESET_ON_CLOSE)
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   249
-			(void)libusb_reset_device(usbDevice[reader_index].dev_handle);
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   250
-
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   251
 		if (usbDevice[reader_index].ccid.arrayOfSupportedDataRates)
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   252
 			free(usbDevice[reader_index].ccid.arrayOfSupportedDataRates);
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   253
 
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   254
@@ -1210,7 +1242,8 @@
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   255
 	ret = libusb_submit_transfer(transfer);
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   256
 	if (ret < 0) {
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   257
 		libusb_free_transfer(transfer);
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   258
-		DEBUG_CRITICAL2("libusb_submit_transfer failed: %d", ret);
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   259
+		DEBUG_CRITICAL2("libusb_submit_transfer failed: %s",
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   260
+			libusb_error_name(ret));
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   261
 		return ret;
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   262
 	}
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   263
 
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   264
@@ -1218,17 +1251,18 @@
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   265
 
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   266
 	while (!completed)
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   267
 	{
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   268
-		ret = libusb_handle_events(ctx);
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   269
+		ret = libusb_handle_events_completed(ctx, &completed);
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   270
 		if (ret < 0)
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   271
 		{
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   272
 			if (ret == LIBUSB_ERROR_INTERRUPTED)
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   273
 				continue;
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   274
 			libusb_cancel_transfer(transfer);
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   275
 			while (!completed)
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   276
-				if (libusb_handle_events(ctx) < 0)
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   277
+				if (libusb_handle_events_completed(ctx, &completed) < 0)
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   278
 					break;
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   279
 			libusb_free_transfer(transfer);
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   280
-			DEBUG_CRITICAL2("libusb_handle_events failed: %d", ret);
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   281
+			DEBUG_CRITICAL2("libusb_handle_events failed: %s",
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   282
+				libusb_error_name(ret));
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   283
 			return ret;
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   284
 		}
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   285
 	}
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   286
@@ -1344,7 +1378,7 @@
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   287
 		completed = 0;
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   288
 		while (!completed && !msExt->terminated)
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   289
 		{
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   290
-			rv = libusb_handle_events(ctx);
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   291
+			rv = libusb_handle_events_completed(ctx, &completed);
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   292
 			if (rv < 0)
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   293
 			{
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   294
 				DEBUG_COMM2("libusb_handle_events err %d", rv);
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   295
@@ -1356,7 +1390,7 @@
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   296
 
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   297
 				while (!completed && !msExt->terminated)
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   298
 				{
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   299
-					if (libusb_handle_events(ctx) < 0)
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   300
+					if (libusb_handle_events_completed(ctx, &completed) < 0)
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   301
 						break;
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   302
 				}
73641150a4de PSARC/2016/217 Smartcard Reintroduction
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   303