blueman icon indicating copy to clipboard operation
blueman copied to clipboard

USB device reset button (feature request)

Open drws opened this issue 3 years ago • 4 comments

blueman: 2.3.1 BlueZ: 5.65 Distribution: Arch Desktop environment: MATE

Some buggy USB adapters occasionally need usbreset (USBDEVFS_RESET) to get them from an error state. I know this is a workaround, but that is the reality with some drivers. It would be great to have such functionality avaliable in Blueman. Namely a Reset USB device button in blueman-adapters in case of an USB device.

drws avatar Aug 14 '22 23:08 drws

I just had issue with my adapter not responding and successfully fixed it with fcntl.ioctl(open("/dev/bus/usb/003/008", "w"), ord('U') << 8 | 20, 0). I think this is a useful addition / tool.

A couple of observations:

  • I currently have no straightforward idea how to get to an adapter's device file.
  • The Python library does not provide a constant for the operation but we can hard-code it of course.
  • Its a privileged operation, so we'd need to implement it in blueman-mechanism.

cschramm avatar Aug 19 '22 18:08 cschramm

What exactly does 'U' cause, unbind? In that case it is similar to but not completely the same as USBDEVFS_RESET as per the internets. If it happens again please try to reset your adapter also with usbreset (source code at link).

drws avatar Aug 22 '22 17:08 drws

ord('U') << 8 | 20 is exactly the definition of USBDEVFS_RESET. It's the character 'U', the magic value for USB IO opcodes, as the first byte and the serial number 20 for the specific operation (The decimal value is 21780). The call is exactly the same as in the usbreset tool.

cschramm avatar Aug 22 '22 18:08 cschramm

I currently have no straightforward idea how to get to an adapter's device file.

This is a blocker. Ideas welcome.

To illustrate: When we know about an adapter, we do have:

  • D-Bus object path like /org/bluez/hci0
  • Device name like hci0 (at least we can easily extract it from the object path)
  • Bluetooth hardware address like 00:00:00:00:00:00
  • Modalias like usb:v0000p0000d0000

We need to get to know the corresponding USB device file like /dev/bus/usb/003/008 in order to talk to it.

There might be some way via data linked to from /sys/class/bluetooth/hci0 but I did not find it yet. It might also boil down to iterating over USB devices and checking them against the data we know, especially the modalias - not a good identifier, though...

cschramm avatar Sep 08 '22 13:09 cschramm