desowin / usbpcap

USB packet capture for Windows
http://desowin.org/usbpcap
896 stars 170 forks source link

Allow filtering by port number #114

Open desowin opened 3 years ago

desowin commented 3 years ago

Currently USBPcapCMD allows filtering by device address. The address gets saved between subsequent extcap starts. This is ok if the user does not reconnect the device and the device address stays intact.

It might be worthwhile to allow specifying filtered devices using port numbers. When filtered device is connected via hub, the full "path" should be used (e.g. 1:2:3 is when device is connected via two hubs in following way [Root Hub port 1] <- [USB Hub port 2] <- [USB Hub port 3] <- [device]).

kamathba commented 1 year ago

I will leave a breadcrumb here in case I don't get to making a PR.

Main hint was here: https://libusb-win32-devel.narkive.com/5JWg4Ofi/identify-the-physical-usb-ports-used-by-a-driver-handle#post3

Which refers to this code: usb_enumerate_hub: https://github.com/libusb/libusb/blob/116d34f608b02f4e14668450b158acf5db726f95/libusb/os/windows_usb.c#L870 set_device_paths: https://github.com/libusb/libusb/blob/116d34f608b02f4e14668450b158acf5db726f95/libusb/os/windows_usb.c#L1401

Since that code is >10 years old, here is the most recent form of it: get_dev_port_number: https://github.com/libusb/libusb/blob/master/libusb/os/windows_winusb.c#L1231

I haven't done any windows kernel work, and I'm not too familiar with this code base, but if there is enough information (files/functions in this codebase you think are in scope for modification) to make a shot at this that is reasonably likely to work and you be on board with, I could give it a go.