device filtering support
Hans de Goede
hdegoede at redhat.com
Wed Feb 1 02:28:05 EST 2012
Hi,
On 02/01/2012 03:40 AM, Xiaofan Chen wrote:
> On Tue, Jan 31, 2012 at 3:50 PM, Hans de Goede<hdegoede at redhat.com> wrote:
>>>
>>> libusb_filter_vid_pid(libusb_context *ctx, int *vids, int *pids, int
>>> nfilters);
>>
>> I hate to throw a spanner in the works, but as someone who has very recently
>> added very similar code to his own code (to filter out devices from redirection to
>> a virtual machine) I think that this API is insufficient.
>>
>> The user may also want to filter by device class and/or revision, and since
>> you allow wildcards in your filter rules, you also need to be able to indicate if a
>> rule is a deny or allow rule, so that you can say for example:
>>
>> vid pid allow/deny
>> 1234 2345 deny
>> 1234 9876 deny
>> 1234 Any allow
>>
>> And something like the pcscd/lite ccid driver wants to be able to say:
>>
>> class vid pid allow/deny
>> ccid 4567 1234 deny
>> ccid Any Any allow
>> Any Any Any deny
>>
>> Note that class checking is non trivial, since class is usually per
>> interface and a device may have multiple interfaces.
>>
>> So we probably need some flags for the filter code, to specify whether
>> the class check is done on all interfaces (so a combined mass-storage
>> / ccid device would be filtered out by the above filter), or if it
>> matches if any interface matches (making a theoretical combined mass-storage
>> / ccid device be not filtered out).
>>
>> See here for what I came up with for my usbredirection code, esp. also
>> the part about how my code does class based filtering:
>> http://cgit.freedesktop.org/~jwrdegoede/usbredir/tree/usbredirparser/usbredirfilter.h
>>
>> Note I'm not saying this is perfect and should be copied 1 on 1, but
>> hopefully it is helpful.
>
> Class filter is a nice idea but I am not so sure if we can achieve it
> under Windows. Filtering the device will make the current Windows
> backend's enumeration process less expensive, but then once
> you find the class of device, what can you do without a generic
> class driver to be used with libusb under Windows?
>
> libusb0.sys can be a class filter driver for this purpose but we
> discourage the use of this mode because of stability concerns.
> Rather we recommend that the filter driver is only used for
> one or more specific device (with specific VID/PIDs).
>
Ok, so lets drop the class filtering bit, even then it still makes
sense to:
1) Have a per filter rule allow/deny result, since we support wildcards
it makes a lot of sense to also do this, so that you can deny a couple
of devices from one manufacturer and then get all the others with 1
allow rule
2) Support filtering on bcdVersion this is part of the device descriptors
just like vid/pid, so available at the same time and for some devices
having a different bccdVersion means that it really is a completely
different chipset but the vendor thought it would be a good idea to
just resue the vid+pid and only change the version. Note that windows
encourages this by allowing drivers to bind to specific versions.
Regards,
Hans
More information about the libusbx
mailing list