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

Fallback to lsusb behaviour for iSerial #13

Closed
haata opened this issue Nov 9, 2023 · 1 comment · Fixed by #14
Closed

Fallback to lsusb behaviour for iSerial #13

haata opened this issue Nov 9, 2023 · 1 comment · Fixed by #14

Comments

@haata
Copy link
Contributor

haata commented Nov 9, 2023

On linux the true iProduct/iManufacturer/iSerial are available (without root) through sysfs.
Usually the device provided names are more accurate than the database (or may have additional information, such as in my case).

What cyme currently does

[dev]: cyme -d 0x308f --lsusb -v                                     

Bus 005 Device 025: ID 308f:0013 Input Club Kira
Couldn't open device, some information will be missing
Device Descriptor:
  bcdUSB              2.00
  bDeviceClass           0 UseInterfaceDescriptor
  bDeviceSubClass        0
  bDeviceProtocol        0
  bMaxPacketSize0       64
  idVendor          0x308f Input Club
  idProduct         0x0013 Kira
  bcdDevice           4.c6
  iManufacturer          2 Input Club
  iProduct               1 Kira
  iSerialNumber          3

What lsusb does

[dev]: lsusb -d 0x308f: -v                                            

Bus 005 Device 025: ID 308f:0013 Input Club Kira
Couldn't open device, some information will be missing
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            0 [unknown]
  bDeviceSubClass         0 [unknown]
  bDeviceProtocol         0
  bMaxPacketSize0        64
  idVendor           0x308f Input Club
  idProduct          0x0013 Kira
  bcdDevice            4.c6
  iManufacturer           1 Input Club
  iProduct                2 Keyboard - Kira PixelMap USB
  iSerial                 3 5337310036384B323430313035353031 - sam4s8

Accessing this info from sysfs

: cat /sys/bus/usb/devices/5-4/5-4.3/{manufacturer,product,serial}
Input Club
Keyboard - Kira PixelMap USB
5337310036384B323430313035353031 - sam4s8
: ls -l  /sys/bus/usb/devices/5-4/5-4.3/{manufacturer,product,serial}
-r--r--r-- 1 root root 4096 Nov  9 04:59 /sys/bus/usb/devices/5-4/5-4.3/manufacturer
-r--r--r-- 1 root root 4096 Nov  9 04:59 /sys/bus/usb/devices/5-4/5-4.3/product
-r--r--r-- 1 root root 4096 Nov  9 04:59 /sys/bus/usb/devices/5-4/5-4.3/serial

No udev rules have been applied to this device

: ls -l /dev/bus/usb/005/025                          
crw-rw-r-- 1 root root 189, 536 Nov  9 04:59 /dev/bus/usb/005/025

lsusb (linux) prefers sysfs afaict https://github.com/gregkh/usbutils/blob/master/lsusb.c#L267

@haata
Copy link
Contributor Author

haata commented Nov 9, 2023

Looking through the code it might take a bit of refactoring around here: https://github.com/tuna-f1sh/cyme/blob/main/src/lsusb.rs#L390

In my mind the priority should go something like this:

  1. lsusb attempt to read strings from device (these are always the most accurate, but may not be available due to permission issue)
  2. Use some sort of OS database that read the descriptors (i.e. sysfs/udev on linux)
  3. Fall back to linux device database

I may take a stab at this over the next couple of days.

haata added a commit to haata/cyme that referenced this issue Nov 9, 2023
- Fixes tuna-f1sh#13
- Always prefers reading descriptors directly if possible (then udev,
  then usb id database)
- Requires udev feature
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant