Skip to content

Commit

Permalink
libusb: same logic to get the config descriptor for hid_open_path() a…
Browse files Browse the repository at this point in the history
…nd hid_enumerate() (#568)
  • Loading branch information
slouken authored Jun 7, 2023
1 parent c6c4dd0 commit 80e8d62
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion libusb/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,9 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
int j, k;

int res = libusb_get_device_descriptor(dev, &desc);
if (res < 0)
continue;

unsigned short dev_vid = desc.idVendor;
unsigned short dev_pid = desc.idProduct;

Expand Down Expand Up @@ -1089,11 +1092,20 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path)

libusb_get_device_list(usb_context, &devs);
while ((usb_dev = devs[d++]) != NULL && !good_open) {
struct libusb_device_descriptor desc;
struct libusb_config_descriptor *conf_desc = NULL;
int j,k;

if (libusb_get_active_config_descriptor(usb_dev, &conf_desc) < 0)
res = libusb_get_device_descriptor(usb_dev, &desc);
if (res < 0)
continue;

res = libusb_get_active_config_descriptor(usb_dev, &conf_desc);
if (res < 0)
libusb_get_config_descriptor(usb_dev, 0, &conf_desc);
if (!conf_desc)
continue;

for (j = 0; j < conf_desc->bNumInterfaces && !good_open; j++) {
const struct libusb_interface *intf = &conf_desc->interface[j];
for (k = 0; k < intf->num_altsetting && !good_open; k++) {
Expand Down

0 comments on commit 80e8d62

Please sign in to comment.