Skip to content
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

DeviceInfo::bus_number() is wrong on Windows #70

Closed
kevinmehall opened this issue Aug 3, 2024 · 2 comments
Closed

DeviceInfo::bus_number() is wrong on Windows #70

kevinmehall opened this issue Aug 3, 2024 · 2 comments
Labels
bug Something isn't working Windows

Comments

@kevinmehall
Copy link
Owner

When adding two XHCI controllers in QEMU, devices on both are returning bus number 0. I think the DEVPKEY_Device_BusNumber may be the PCI bus number rather than anything specific to USB.

Libusb assigns bus numbers sequentially by iterating host controllers, but it's not clear that this ordering and thus numbering is deterministic.

I am wondering if the whole concept of bus number is a Linux-ism, though it turns out that macOS has something similar in the high 8 bits of locationID. Would it be better to expose the bus ID as a string rather than a number? Even Linux may be better served by a PCI path than a small integer in the presence of hotpluggable USB controllers such as Thunderbolt docks.

@kevinmehall kevinmehall added bug Something isn't working Windows labels Aug 3, 2024
@martinling
Copy link
Contributor

Since the nature of the ID can differ between platforms, how about a BusId type that wraps whatever the platform's internal representation is. That should guarantee the API remains portable.

That type could then implement Display so that programs can get something OS-appropriate to show the user.

@kevinmehall
Copy link
Owner Author

kevinmehall commented Aug 12, 2024

In #71 I just went with DeviceInfo::bus_id returning a string. It's a stringified number on Linux and macOS, and the host controller part of the first matching location path on Windows. The underlying busnum, locationID, or locationPaths are are also exposed with platform-specific methods. It could have been an opaque type, but a string seemed simpler than introducing more API surface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Windows
Projects
None yet
Development

No branches or pull requests

2 participants