Windows: Try alternative methods to query port number
authorJim Chen <darchons@users.noreply.github.com>
Wed, 3 Feb 2021 18:13:55 +0000 (13:13 -0500)
committerNathan Hjelm <hjelmn@google.com>
Tue, 8 Jun 2021 03:25:35 +0000 (21:25 -0600)
commitd551802db593436947a2464a7da1020edf0e7b56
tree897cf88b201e0cc7e096bafa7d4053ad40327e49
parent0ce010cdb12e45f4bf81ac82755bad3b4ab050b6
Windows: Try alternative methods to query port number

This commit is similar to #634 but I think it offers a better approach. The commit adds two more methods for querying the port number, in addition to the existing SPDRP_ADDRESS method, which may not actually return the port number when using USB drivers other than the Microsoft driver.

The first method uses SPDRP_LOCATION_INFORMATION, which may return a port in a format similar to "Port_#0002.Hub_#000D".

The second method uses SPDRP_LOCATION_PATHS, which returns the device location in a format similar to "PCIROOT(B2)#PCI(0300)#PCI(0000)#USBROOT(0)#USB(1)#USB(2)#USBMI(3)", where the port number is the number within the last "#USB()" token.

If both methods fail, SPDRP_ADDRESS is still used as a fallback.

Closes #867

Signed-off-by: Nathan Hjelm <hjelmn@google.com>
libusb/os/windows_winusb.c
libusb/version_nano.h