-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
windows: get_dev_port_number try using VID / PID #1269
base: master
Are you sure you want to change the base?
windows: get_dev_port_number try using VID / PID #1269
Conversation
e9887b4
to
bead4d8
Compare
Please help to share some background info and show one example that |
bead4d8
to
76aaed0
Compare
As stated in a comment in the current code: "try SPDRP_ADDRESS, which returns a REG_DWORD. The address may be the port number", or it may not. When experimenting with "FabulaTech Virtual USB Host Controller" (USB-Ethernet bridge) under Hyper-V virtual machine, I found out that indeed, SPDRP_ADDRESS access returns true (so this key is found in registry) but we get an obviously wrong port number. This is because SPDRP_ADDRESS registry key does not seem to be standardised. In my case the number found here was simply an instance number not related to port number at all. Under regular Windows, I experienced that either we get an port number from SPDRP_LOCATION_INFORMATION or SPDRP_LOCATION_PATHS, or trying SPDRP_ADDRESS return false (such key don't exist). Therefore I devised another alternate way to obtain a valid port_number. In my experience, either this code is not called at all (nor is the call using SDRP_ADDRESS) because earlier access to registry lead to a valid port_number, or the SDRP_ADDRESS is not valid and it makes sense to call my new, somehow heavier, implementation. |
I see. I think your explanation is good. I do not have such device to test though. But at least I do not see any regressions.
|
Since SPDRP_ADDRESS may return the actual port number, but not always, try another way of getting port number by matching VID/PID obtained via IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX with values encoded in dev_id string, by brute-forcing initialization of temporary device objects. If a match is found, Serial Number is verified as well. If all is succeed then port_nr is assigned to the value found, otherwise revert to port_nr and return value from SPDRP_ADDRESS.
76aaed0
to
25fffc1
Compare
I think this PR is good to go. Please review as well. Thanks. |
Since SPDRP_ADDRESS may return the actual port number, but not always, try another way of getting port number by matching VID/PID obtained via IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX with values encoded in dev_id string, by brute-forcing initialization of temporary device objects.
If a match is found, Serial Number is verified as well. If all is succeed then port_nr is assigned to the value found, otherwise revert to port_nr and return value from SPDRP_ADDRESS.