windows: Base HID device descriptor on cached values
Some checks failed
linux / build (push) Has been cancelled
macOS / build (push) Has been cancelled
MSYS2 build / build (push) Has been cancelled
MSYS2 clang32 build / build (push) Has been cancelled
MSYS2 clang64 build / build (push) Has been cancelled

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 <debian.tormod@gmail.com>
This commit is contained in:
Tormod Volden 2023-12-13 13:50:48 +01:00
parent d04fc0e60b
commit 4528752cbe
2 changed files with 12 additions and 10 deletions

View file

@ -3513,24 +3513,26 @@ static int _hid_wcslen(WCHAR *str)
return i; 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; 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.bLength = LIBUSB_DT_DEVICE_SIZE;
d.bDescriptorType = LIBUSB_DT_DEVICE; d.bDescriptorType = LIBUSB_DT_DEVICE;
d.bcdUSB = 0x0200; /* 2.00 */ d.bcdUSB = dev->device_descriptor.bcdUSB;
d.bDeviceClass = 0; d.bDeviceClass = dev->device_descriptor.bDeviceClass;
d.bDeviceSubClass = 0; d.bDeviceSubClass = dev->device_descriptor.bDeviceSubClass;
d.bDeviceProtocol = 0; d.bDeviceProtocol = dev->device_descriptor.bDeviceProtocol;
d.bMaxPacketSize0 = 64; /* fix this! */ d.bMaxPacketSize0 = dev->device_descriptor.bMaxPacketSize0;
d.idVendor = (uint16_t)hid_priv->vid; d.idVendor = (uint16_t)hid_priv->vid;
d.idProduct = (uint16_t)hid_priv->pid; d.idProduct = (uint16_t)hid_priv->pid;
d.bcdDevice = 0x0100; d.bcdDevice = dev->device_descriptor.bcdDevice;
d.iManufacturer = hid_priv->string_index[0]; d.iManufacturer = hid_priv->string_index[0];
d.iProduct = hid_priv->string_index[1]; d.iProduct = hid_priv->string_index[1];
d.iSerialNumber = hid_priv->string_index[2]; d.iSerialNumber = hid_priv->string_index[2];
d.bNumConfigurations = 1; d.bNumConfigurations = dev->device_descriptor.bNumConfigurations;
if (*size > LIBUSB_DT_DEVICE_SIZE) if (*size > LIBUSB_DT_DEVICE_SIZE)
*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) { switch (type) {
case LIBUSB_DT_DEVICE: case LIBUSB_DT_DEVICE:
usbi_dbg(DEVICE_CTX(dev), "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: case LIBUSB_DT_CONFIG:
usbi_dbg(DEVICE_CTX(dev), "LIBUSB_DT_CONFIG"); usbi_dbg(DEVICE_CTX(dev), "LIBUSB_DT_CONFIG");
if (!_index) if (!_index)

View file

@ -1 +1 @@
#define LIBUSB_NANO 11931 #define LIBUSB_NANO 11932