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

libusb: fix enumerating device path w/o root access #442

Merged
merged 1 commit into from
Aug 15, 2022
Merged

Conversation

Youw
Copy link
Member

@Youw Youw commented Aug 13, 2022

A small bug introduced by #432.

@mcuee mcuee added the libusb Related to libusb backend label Aug 14, 2022
@mcuee
Copy link
Member

mcuee commented Aug 14, 2022

Just wondering what is the small problem here?

Somehow I do not see any differences between this and git main.

mcuee@UbuntuSwift3:~/build/hidapi_pr440/build$ lsusb
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 006: ID 1c7a:0575 LighTuning Technology Inc. EgisTec EH575
Bus 003 Device 005: ID 04f2:b6dd Chicony Electronics Co., Ltd HD User Facing
Bus 003 Device 009: ID 046d:c52b Logitech, Inc. Unifying Receiver
Bus 003 Device 008: ID 04d8:003f Microchip Technology, Inc. USB Receiver
Bus 003 Device 003: ID 05e3:0610 Genesys Logic, Inc. 4-port hub
Bus 003 Device 007: ID 8087:0026 Intel Corp. 
Bus 003 Device 002: ID 16c0:05dc Van Ooijen Technische Informatica shared ID for use with libusb
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 002: ID 05e3:0612 Genesys Logic, Inc. Hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
mcuee@UbuntuSwift3:~/build/hidapi_pr440/build$ ls -la /dev/bus/usb/003/008
crw-rw-rw- 1 root root 189, 263 Aug 14 11:34 /dev/bus/usb/003/008
mcuee@UbuntuSwift3:~/build/hidapi_pr440/build$ sudo chmod 664 /dev/bus/usb/003/008
[sudo] password for mcuee: 

mcuee@UbuntuSwift3:~/build/hidapi/build$ ./hidtest/hidtest_libusb 
hidapi test/example tool. Compiled with hidapi version 0.13.0, runtime version 0.13.0.
Compile-time version matches runtime version of hidapi.

Device Found
  type: 046d c52b
  path: 3-3:1.0
  serial_number: (null)
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    0
  Usage (page): 0x0 (0x0)

Device Found
  type: 046d c52b
  path: 3-3:1.1
  serial_number: (null)
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    1
  Usage (page): 0x0 (0x0)

Device Found
  type: 046d c52b
  path: 3-3:1.2
  serial_number: (null)
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    2
  Usage (page): 0x0 (0x0)

Device Found
  type: 04d8 003f
  path: 3-3:1.0
  serial_number: (null)
  Manufacturer: (null)
  Product:      (null)
  Release:      2
  Interface:    0
  Usage (page): 0x0 (0x0)

Device Found
  type: 16c0 05dc
  path: 3-1:1.1
  serial_number: 0001
  Manufacturer: www.fischl.de
  Product:      USBasp
  Release:      110
  Interface:    1
  Usage (page): 0x0 (0x0)

unable to open device

mcuee@UbuntuSwift3:~/build/hidapi/hidapi_pr442/build$ ./hidtest/hidtest_libusb 
hidapi test/example tool. Compiled with hidapi version 0.13.0, runtime version 0.13.0.
Compile-time version matches runtime version of hidapi.

Device Found
  type: 046d c52b
  path: 3-3:1.0
  serial_number: (null)
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    0
  Usage (page): 0x0 (0x0)

Device Found
  type: 046d c52b
  path: 3-3:1.1
  serial_number: (null)
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    1
  Usage (page): 0x0 (0x0)

Device Found
  type: 046d c52b
  path: 3-3:1.2
  serial_number: (null)
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    2
  Usage (page): 0x0 (0x0)

Device Found
  type: 04d8 003f
  path: 3-2.3:1.0
  serial_number: (null)
  Manufacturer: (null)
  Product:      (null)
  Release:      2
  Interface:    0
  Usage (page): 0x0 (0x0)

Device Found
  type: 16c0 05dc
  path: 3-1:1.1
  serial_number: 0001
  Manufacturer: www.fischl.de
  Product:      USBasp
  Release:      110
  Interface:    1
  Usage (page): 0x0 (0x0)

unable to open device

@Youw
Copy link
Member Author

Youw commented Aug 14, 2022

Those are interesting results.
W/o the fix I get:

./hidtest/hidtest_libusb 
hidapi test/example tool. Compiled with hidapi version 0.13.0, runtime version 0.13.0.
Compile-time version matches runtime version of hidapi.

Device Found
  type: 046d c52b
  path: (null)
  serial_number: (null)
  Manufacturer: (null)
  Product:      (null)
  Release:      1210
  Interface:    0
  Usage (page): 0x0 (0x0)

Device Found
  type: 046d c52b
  path: (null)
  serial_number: (null)
  Manufacturer: (null)
  Product:      (null)
  Release:      1210
  Interface:    1
  Usage (page): 0x0 (0x0)

Device Found
  type: 046d c52b
  path: (null)
  serial_number: (null)
  Manufacturer: (null)
  Product:      (null)
  Release:      1210
  Interface:    2
  Usage (page): 0x0 (0x0)

unable to open device

With the fix:

./hidtest/hidtest_libusb 
hidapi test/example tool. Compiled with hidapi version 0.13.0, runtime version 0.13.0.
Compile-time version matches runtime version of hidapi.

Device Found
  type: 046d c52b
  path: 1-3:1.0
  serial_number: (null)
  Manufacturer: (null)
  Product:      (null)
  Release:      1210
  Interface:    0
  Usage (page): 0x0 (0x0)

Device Found
  type: 046d c52b
  path: 1-3:1.1
  serial_number: (null)
  Manufacturer: (null)
  Product:      (null)
  Release:      1210
  Interface:    1
  Usage (page): 0x0 (0x0)

Device Found
  type: 046d c52b
  path: 1-3:1.2
  serial_number: (null)
  Manufacturer: (null)
  Product:      (null)
  Release:      1210
  Interface:    2
  Usage (page): 0x0 (0x0)

unable to open device

Both runs w/o root.


In your case looks like libusb is able to open all of the devices.
As if you're executed something like chmod -r 666 /dev/bus/usb/*/*.

@Youw Youw merged commit 7793462 into master Aug 15, 2022
@Youw Youw deleted the libusb_enumerate branch August 15, 2022 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libusb Related to libusb backend
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants