Windows: Close HID handles when closing composite devices
authorChris Dickens <christopher.a.dickens@gmail.com>
Wed, 29 Jul 2015 05:51:09 +0000 (22:51 -0700)
committerChris Dickens <christopher.a.dickens@gmail.com>
Wed, 29 Jul 2015 06:10:24 +0000 (23:10 -0700)
* Closes #81

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
libusb/os/windows_usb.c
libusb/version_nano.h

index 734c47e..f505139 100644 (file)
@@ -4425,24 +4425,31 @@ static void composite_close(int sub_api, struct libusb_device_handle *dev_handle
 {
        struct windows_device_priv *priv = _device_priv(dev_handle->dev);
        uint8_t i;
-       bool available[SUB_API_MAX];
-
-       for (i = 0; i<SUB_API_MAX; i++) {
-               available[i] = false;
-       }
+       // SUB_API_MAX+1 as the SUB_API_MAX pos is used to indicate availability of HID
+       bool available[SUB_API_MAX+1] = {0};
 
        for (i=0; i<USB_MAXINTERFACES; i++) {
-               if ( (priv->usb_interface[i].apib->id == USB_API_WINUSBX)
-                 && (priv->usb_interface[i].sub_api != SUB_API_NOTSET) ) {
-                       available[priv->usb_interface[i].sub_api] = true;
+               switch (priv->usb_interface[i].apib->id) {
+               case USB_API_WINUSBX:
+                       if (priv->usb_interface[i].sub_api != SUB_API_NOTSET)
+                               available[priv->usb_interface[i].sub_api] = true;
+                       break;
+               case USB_API_HID:
+                       available[SUB_API_MAX] = true;
+                       break;
+               default:
+                       break;
                }
        }
 
-       for (i=0; i<SUB_API_MAX; i++) {
+       for (i=0; i<SUB_API_MAX; i++) { // WinUSB-like drivers
                if (available[i]) {
                        usb_api_backend[USB_API_WINUSBX].close(i, dev_handle);
                }
        }
+       if (available[SUB_API_MAX]) {   // HID driver
+               hid_close(SUB_API_NOTSET, dev_handle);
+       }
 }
 
 static int composite_claim_interface(int sub_api, struct libusb_device_handle *dev_handle, int iface)
index 1135a18..248dd43 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 10987
+#define LIBUSB_NANO 10988