Skip to content

Commit

Permalink
windows: Base HID device descriptor on cached values
Browse files Browse the repository at this point in the history
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 libusb#1360

Signed-off-by: Tormod Volden <[email protected]>
  • Loading branch information
tormodvolden committed Dec 13, 2023
1 parent 87d6686 commit 2006cea
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions libusb/os/windows_winusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -3498,24 +3498,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;
Expand Down Expand Up @@ -3743,7 +3745,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)
Expand Down

0 comments on commit 2006cea

Please sign in to comment.