Skip to content

Commit

Permalink
Fixed missing auto-enumeration
Browse files Browse the repository at this point in the history
  • Loading branch information
k1-801 committed Nov 21, 2023
1 parent 74f61b3 commit f7fee2c
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions libusb/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,11 @@ int HID_API_EXPORT hid_exit(void)
return 0;
}

static int hid_internal_match_device_id(unsigned short vendor_id, unsigned short product_id, unsigned short expected_vendor_id, unsigned short expected_product_id)
{
return (expected_vendor_id == 0x0 || vendor_id == expected_vendor_id) && (expected_product_id == 0x0 || product_id == expected_product_id);
}

static int hid_get_report_descriptor_libusb(libusb_device_handle *handle, int interface_num, uint16_t expected_report_descriptor_size, unsigned char *buf, size_t buf_size)
{
unsigned char tmp[HID_API_MAX_REPORT_DESCRIPTOR_SIZE];
Expand Down Expand Up @@ -752,8 +757,7 @@ static struct hid_device_info* hid_enumerate_from_libusb(libusb_device *dev, uns
unsigned short dev_vid = desc.idVendor;
unsigned short dev_pid = desc.idProduct;

if ((vendor_id != 0x0 && vendor_id != dev_vid) ||
(product_id != 0x0 && product_id != dev_pid)) {
if (hid_internal_match_device_id(dev_vid, dev_pid, vendor_id, product_id)) {
return NULL;
}
if (res < 0)
Expand Down Expand Up @@ -1021,6 +1025,17 @@ int HID_API_EXPORT HID_API_CALL hid_hotplug_register_callback(unsigned short ven
LIBUSB_HOTPLUG_MATCH_ANY, &hid_libusb_hotplug_callback, hotplug_cb,
&hotplug_cb->handle_internal);

if ((flags & HID_API_HOTPLUG_ENUMERATE) && (events & HID_API_HOTPLUG_EVENT_DEVICE_ARRIVED)) {
struct hid_device_info* device = hid_hotplug_context.devs;
/* Notify about already connected devices, if asked so */
while (device != NULL) {
if (hid_internal_match_device_id(device->vendor_id, device->product_id, hotplug_cb->vendor_id, hotplug_cb->product_id)) {
(*hotplug_cb->callback)(hotplug_cb->handle, device, HID_API_HOTPLUG_EVENT_DEVICE_ARRIVED, hotplug_cb->user_data);
}

device = device->next;
}
}
return 0;
}

Expand Down

0 comments on commit f7fee2c

Please sign in to comment.