device filtering support

Xiaofan Chen xiaofanc at gmail.com
Tue Jan 31 21:40:40 EST 2012


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).

-- 
Xiaofan



More information about the libusbx mailing list