RFC: add filter function based enumeration #584

Open
opened 2023-05-31 12:28:43 -05:00 by Youw · 2 comments
Youw commented 2023-05-31 12:28:43 -05:00 (Migrated from github.com)
          We could do both: allow SDL filter out devices like this, _and_ avoid patching HIDAPI sources if we would introduce something like:
typedef int (*HID_API_CALL hidapi_ven_dev_filter_func)(unsigned short vendor_id, unsigned short product_id);
struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate_ven_dev_filter(hidapi_ven_dev_filter_func);

But that is a different effort, and would definitely need an implementation on all platforms.

Originally posted by @Youw in https://github.com/libusb/hidapi/issues/575#issuecomment-1570629007

We could do both: allow SDL filter out devices like this, _and_ avoid patching HIDAPI sources if we would introduce something like: ```c typedef int (*HID_API_CALL hidapi_ven_dev_filter_func)(unsigned short vendor_id, unsigned short product_id); struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate_ven_dev_filter(hidapi_ven_dev_filter_func); ``` But that is a different effort, and would definitely need an implementation on all platforms. _Originally posted by @Youw in https://github.com/libusb/hidapi/issues/575#issuecomment-1570629007_
JoergAtGithub commented 2023-06-03 13:59:31 -05:00 (Migrated from github.com)

We filter devices in the postprocessing after enumeration. But it would make sense to define blacklist entries before enumeration. This makes als sense when we think about hot-plugging.
We currently use the following criteria:

  • VID/PID to filter a few problematic devices
  • Usage-Table/Usage to filter out whole device categories like mouses, joysticks and gamepads
  • Bus-Type to filter out all embedded (SPI/I2C) laptop devices
  • There is also one case where we use the interface number, but it seems this is only, because at that time Usage-Table/Usage detection wasn't reliable.
We filter devices in the postprocessing after enumeration. But it would make sense to define blacklist entries before enumeration. This makes als sense when we think about hot-plugging. We currently use the following criteria: - VID/PID to filter a few problematic devices - Usage-Table/Usage to filter out whole device categories like mouses, joysticks and gamepads - Bus-Type to filter out all embedded (SPI/I2C) laptop devices - There is also one case where we use the interface number, but it seems this is only, because at that time Usage-Table/Usage detection wasn't reliable.
Youw commented 2023-06-04 10:12:28 -05:00 (Migrated from github.com)

I agree all of those are valid points.

Knowing the codebase, I must say that to implement (early) filtering for each criteria will be challenging, e.g.: it is impossible to get the usage_pages/usages of the device with libusb backend w/o opening the device, which is so much for "early" filtering.

I believe on all (not sure about macOS - that one is a bit different) platforms, having an early filter for vid/pid only is simple-enough and probably should be our first step towards that direction.

I agree all of those are valid points. Knowing the codebase, I must say that to implement (early) filtering for each criteria will be challenging, e.g.: it is impossible to get the usage_pages/usages of the device with libusb backend w/o opening the device, which is so much for "early" filtering. I believe on all (not sure about macOS - that one is a bit different) platforms, having an early filter for vid/pid only is simple-enough and probably should be our first step towards that direction.
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-libusb/hidapi#584
No description provided.