winusb: Check for ClassGuid changes on re-enumeration
authorTormod Volden <debian.tormod@gmail.com>
Thu, 25 Mar 2021 22:47:27 +0000 (23:47 +0100)
committerNathan Hjelm <hjelmn@google.com>
Fri, 11 Jun 2021 03:06:30 +0000 (21:06 -0600)
Previously only the dev_id (VID/PID/serial) was checked, but if the
bcdDevice has changed, Windows will have re-enumerated the device and
possibly attributed another ClassGuid to it.

Fixes issue #897.
Closes #900

Thanks to Craig Hutchinson for reporting, suggestion and testing.

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
Signed-off-by: Nathan Hjelm <hjelmn@google.com>
libusb/os/windows_common.h
libusb/os/windows_winusb.c
libusb/version_nano.h

index 2de2b60..792a31e 100644 (file)
@@ -259,6 +259,7 @@ struct winusb_device_priv {
        } usb_interface[USB_MAXINTERFACES];
        struct hid_device_priv *hid;
        PUSB_CONFIGURATION_DESCRIPTOR *config_descriptor; // list of pointers to the cached config descriptors
+       GUID class_guid; // checked for change during re-enumeration
 };
 
 struct usbdk_device_handle_priv {
index e1e599c..cdca6cb 100644 (file)
@@ -1721,6 +1721,7 @@ static int winusb_get_device_list(struct libusb_context *ctx, struct discovered_
 
                                        priv = winusb_device_priv_init(dev);
                                        priv->dev_id = _strdup(dev_id);
+                                       priv->class_guid = dev_info_data.ClassGuid;
                                        if (priv->dev_id == NULL) {
                                                libusb_unref_device(dev);
                                                LOOP_BREAK(LIBUSB_ERROR_NO_MEM);
@@ -1735,6 +1736,12 @@ static int winusb_get_device_list(struct libusb_context *ctx, struct discovered_
                                                libusb_unref_device(dev);
                                                goto alloc_device;
                                        }
+                                       if (!IsEqualGUID(&priv->class_guid, &dev_info_data.ClassGuid)) {
+                                               usbi_dbg("device class GUID for session [%lX] changed", session_id);
+                                               usbi_disconnect_device(dev);
+                                               libusb_unref_device(dev);
+                                               goto alloc_device;
+                                       }
                                }
 
                        track_unref:
index 3924959..e0c04dc 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 11625
+#define LIBUSB_NANO 11626