-
Notifications
You must be signed in to change notification settings - Fork 76
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
improve USB device detection logic #39
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both my USB dongles, both before and with this change generate the following error for usb_probe
:
$ python3 ./apps/usb_probe.py --verbose
Traceback (most recent call last):
File "/home/mturon/src/nest/ble/bumble/./apps/usb_probe.py", line 228, in <module>
main(verbose)
File "/home/mturon/src/nest/ble/bumble/./apps/usb_probe.py", line 199, in main
if device.getSerialNumber() and not serial_number_collision:
File "/home/mturon/src/nest/connectedhomeip/turon/.environment/pigweed-venv/lib/python3.10/site-packages/usb1/__init__.py", line 2019, in getSerialNumber
return self.open().getSerialNumber()
File "/home/mturon/src/nest/connectedhomeip/turon/.environment/pigweed-venv/lib/python3.10/site-packages/usb1/__init__.py", line 2055, in open
mayRaiseUSBError(libusb1.libusb_open(self.device_p, byref(handle)))
File "/home/mturon/src/nest/connectedhomeip/turon/.environment/pigweed-venv/lib/python3.10/site-packages/usb1/__init__.py", line 127, in mayRaiseUSBError
__raiseUSBError(value)
File "/home/mturon/src/nest/connectedhomeip/turon/.environment/pigweed-venv/lib/python3.10/site-packages/usb1/__init__.py", line 119, in raiseUSBError
raise __STATUS_TO_EXCEPTION_DICT.get(value, __USBError)(value)
usb1.USBErrorAccess: LIBUSB_ERROR_ACCESS [-3]
Interestingly, the python3 ./apps/scan.py usb:0
command works fine for both (vendor:product syntax is not required).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
@turon My guess is that this is caused by a permission denied error on some USB device. I'll try to replicate it locally and should have a PR to fix it soon after. |
Some USB device properties are only accessible if the user has the appropriate permissions. Handle libusb1 errors to graciously skip showing details for these devices.
@turon I have pushed a commit on top to fix the issue you reporeted, could you please give it a try? |
I tried this change with Asus BT-400 usb bluetooth adapter, which reports itself as deviceclass 0xff. ID 0B05:17CB But run_scanner.py example fails: python run_scanner.py usb:0B05:17CB With v0.0.121 scanner works if I comment out this line in usb.py: device.getDeviceClass() == USB_DEVICE_CLASS_WIRELESS_CONTROLLER and python run_scanner.py usb:0B05:17CB! with exclamation mark works, however. |
That works better now for both dongles I have. Error -3 output remains though if that is important: [Broadcom]
[CSR]
|
This is the expected behavior. A recent change updated the USB discovery logic to not hardcode the USB endpoint addresses as was done previously, because some controllers don't use the "usual" endpoint addresses of (0x81, 0x82, 0x02) (they are "usual", but as it turns out, not specifically required to be exactly that by the BT specification), so the updated logic is to discover the endpoint addresses dynamically, for endpoint with the normative class/subclass/protocol. The BT-400 dongle doesn't use the normative class/subclass/protocol, but does use (0x81, 0x82, 0x02), so that's why it worked before, when those addresses were hardcoded and there was no check for class/subclass/protocol. As a result, the '!' suffix is introduced in this PR to allow overriding the check for class/subclass/protocol. |
This error is normal on Linux. Getting the manufacturer name and serial number for a USB device requires actually opening the device to read those strings (as opposed to the other properties that are available purely from the USB descriptors without requiring libusb to open the device). On a platform like macOS, there's no issue with that, but on Linux you don't have the permission to open all the devices, so reading those properties will fail. This isn't a problem for our use case, since you wouldn't be able to use those with the Bumble library either, so the fact that usb_probe.py can't fully list all properties isn't a limitation. |
Some USB devices don't use compliant descriptors for their interfaces. This PR allows forcing the auto-detection logic to use those devices nonetheless.
Also included is better way to detect compliant devices (devices where the BT class is set on the interfaces but not on the whole device), so they can be used as
usb:<index>
rather than requiring an explicitusb:<vendor>:<product>
.Finally, a
--verbose
option is added tousb_probe.py
that will list all the endpoints for each enumerated device.