[vbox-dev] USB filtering on Windows
Ivo at UFO-Net.nl
Tue Oct 15 12:15:58 UTC 2013
Klaus Espenlaub schreef op 14-10-2013 14:25:
> The USB spec actually requires a serial number (not that many USB device
> manufacturers would care), so the information VirtualBox uses for
> filtering should be unique. Of course we know that in reality this
> doesn't always work...
Most of the devices I'm working with (keyboards and mice) do not have a
serial number at all...
>> On the kernel side, there appears to be a
>> which would allow the filter driver to get an unique identification of
>> the USB controller and the path of hub ports to the device. This should
>> uniquely identify the device, as long as it is not unplugged.
> VirtualBox should already report something along this lines in the
> "Address" attribute, but I'd have to dig through the USB handling code
> for Windows to find out if it's used or not during matching.
The Address attribute on Windows is the "driver key" (SPDRP_DRIVER),
which identifies the driver instance, not necessarily the device itself.
The driver key does not exist if no driver is installed for the device
on the host, and is probably not available when the USB filter code has
to do its work, because no driver has been selected at this point. This
also explains why the code related to the driver key is disabled in
(vboxUsbFltDevPopulate, line 527).
>> On the user mode side, the PCI bus, device and function numbers can be
>> obtained from a query (SPDRP_BUSNUMBER and SPDRP_ADDRESS) against the
>> USB controller device node (which is available as the root of the USB
>> enumeration anyway), and the path of hub ports can be constructed as the
>> USB tree is enumerated.
>> This information can be stored in a filter structure in string format
>> Combined with Vid and Pid, this should provide sufficient information to
>> uniquely identify a USB device on a port before and after "virtual
>> replugging". Added bonus: it could be used to forward a specific host
>> USB port to a VM, regardless of what is plugged into that port.
>> Any technical reason why this is not yet implemented? Am I missing
>> something? If not, I'd better start working on it.
> I'd hope you're missing the Address attribute I mentioned above, because
> that should contain the information you're after, without all the
> additional effort of collecting the entire device hierarchy information.
Enumerating the entire USB device tree is one of two ways I know of to
find all connected USB devices in Windows. VirtualBox primarily uses
this method, so the port numbers are already available.
> I wouldn't like to go this way, as it'd hard code that the device tree
> uses the PCI standard on the highest levels, which isn't set in stone
> (even though it's unlikely to change in the near future).
I completely agree. I've read about USB 2 controllers hosted on an USB 3
bus (to optimize speed). Unfortunately, Microsoft seems to have decided
that USB controllers only exist on PCI buses in their
USB_TOPOLOGY_ADDRESS structure, and without complicating things further
it seems to me like this is the only way to identify a device in this
More information about the vbox-dev