From 4528752cbecd0ff84c5df2e17453060d8971b3b2 Mon Sep 17 00:00:00 2001 From: Tormod Volden Date: Wed, 13 Dec 2023 13:50:48 +0100 Subject: [PATCH] windows: Base HID device descriptor on cached values Instead of filling in the blanks with hard-coded made-up values that are sometimes correct, use the cached descriptor values retrieved during enumeration, which should be a better fallback. References #1360 Closes #1378 Signed-off-by: Tormod Volden --- libusb/os/windows_winusb.c | 20 +++++++++++--------- libusb/version_nano.h | 2 +- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/libusb/os/windows_winusb.c b/libusb/os/windows_winusb.c index 5bfcb2b0..dd4675b5 100644 --- a/libusb/os/windows_winusb.c +++ b/libusb/os/windows_winusb.c @@ -3513,24 +3513,26 @@ static int _hid_wcslen(WCHAR *str) return i; } -static int _hid_get_device_descriptor(struct hid_device_priv *hid_priv, void *data, size_t *size) +static int _hid_get_device_descriptor(struct libusb_device *dev, struct hid_device_priv *hid_priv, void *data, size_t *size) { struct libusb_device_descriptor d; + /* Copy some values from the cached device descriptor + * because we cannot get them through HID */ d.bLength = LIBUSB_DT_DEVICE_SIZE; d.bDescriptorType = LIBUSB_DT_DEVICE; - d.bcdUSB = 0x0200; /* 2.00 */ - d.bDeviceClass = 0; - d.bDeviceSubClass = 0; - d.bDeviceProtocol = 0; - d.bMaxPacketSize0 = 64; /* fix this! */ + d.bcdUSB = dev->device_descriptor.bcdUSB; + d.bDeviceClass = dev->device_descriptor.bDeviceClass; + d.bDeviceSubClass = dev->device_descriptor.bDeviceSubClass; + d.bDeviceProtocol = dev->device_descriptor.bDeviceProtocol; + d.bMaxPacketSize0 = dev->device_descriptor.bMaxPacketSize0; d.idVendor = (uint16_t)hid_priv->vid; d.idProduct = (uint16_t)hid_priv->pid; - d.bcdDevice = 0x0100; + d.bcdDevice = dev->device_descriptor.bcdDevice; d.iManufacturer = hid_priv->string_index[0]; d.iProduct = hid_priv->string_index[1]; d.iSerialNumber = hid_priv->string_index[2]; - d.bNumConfigurations = 1; + d.bNumConfigurations = dev->device_descriptor.bNumConfigurations; if (*size > LIBUSB_DT_DEVICE_SIZE) *size = LIBUSB_DT_DEVICE_SIZE; @@ -3758,7 +3760,7 @@ static int _hid_get_descriptor(struct libusb_device *dev, HANDLE hid_handle, int switch (type) { case LIBUSB_DT_DEVICE: usbi_dbg(DEVICE_CTX(dev), "LIBUSB_DT_DEVICE"); - return _hid_get_device_descriptor(priv->hid, data, size); + return _hid_get_device_descriptor(dev, priv->hid, data, size); case LIBUSB_DT_CONFIG: usbi_dbg(DEVICE_CTX(dev), "LIBUSB_DT_CONFIG"); if (!_index) diff --git a/libusb/version_nano.h b/libusb/version_nano.h index ad5d874d..c3f29dd7 100644 --- a/libusb/version_nano.h +++ b/libusb/version_nano.h @@ -1 +1 @@ -#define LIBUSB_NANO 11931 +#define LIBUSB_NANO 11932