device filtering support

Hans de Goede hdegoede at redhat.com
Tue Jan 31 02:50:40 EST 2012


Hi,

On 01/31/2012 07:06 AM, Vitali Lovich wrote:
> https://github.com/vlovich/libusb/tree/filter_support feature rebase on top of rc3
>
> Request for review.  Verified works on Linux.  Pretty sure that it works on OSX&  Windows as those code paths are even simpler.  I'm planning for this to go into the first forked release of libusbx (i.e. not 1.0.9).  This can have significant benefit in terms of CPU usage since it avoids unnecessary allocations&  usb querying if the device is of no interest to upper layers.  It also simplifies a lot of user code since they typically will filter for a specific vid/pid from the list anyways.
>
> 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.

Regards,

Hans



More information about the libusbx mailing list