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

macOS: use IORegistryEntryGetRegistryEntryID to resolve paths #322

Merged
merged 1 commit into from
Aug 23, 2021

Conversation

Youw
Copy link
Member

@Youw Youw commented Aug 14, 2021

With some device connection configurations,
the device paths become over 512 bytes (io_string_t max length)
which makes them unusable with current implementation.

Rather than using ServiceRegistry string path, use its ID,
which is uint64_t and easily serializable/deserializable into a string.

Implementation idea by felix.schwarz@iospirit.com
flirc/hidapi@8d251c3

Fixes: #127, #236.

With some device connection configurations,
the device paths become over 512 bytes (io_string_t max length)
which makes them unusable with current implementation.

Rather than using ServiceRegistry string path, use its ID,
which is uint64_t and easily serializable/deserializable into a string.

Implementation idea by felix.schwarz@iospirit.com
flirc/hidapi@8d251c3

Fixes: #127, #236.
@Youw
Copy link
Member Author

Youw commented Aug 15, 2021

@erikmwerner, @mcuee will you be able to try this out?

@mcuee
Copy link
Member

mcuee commented Aug 15, 2021

This seems to work fine.


hidapi_macospath/build on  macos-path [?] via △ v3.21.1 ❯ ./hidtest/hidtest 
hidapi test/example tool. Compiled with hidapi version 0.11.0, runtime version 0.11.0.
Compile-time version matches runtime version of hidapi.

Device Found
  type: 046d c52b
  path: DevSrvsID:4294969658
  serial_number: 
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2410
  Interface:    1
  Usage (page): 0x2 (0x1)

Device Found
  type: 046d c52b
  path: DevSrvsID:4294969658
  serial_number: 
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2410
  Interface:    1
  Usage (page): 0x1 (0x1)

Device Found
  type: 046d c52b
  path: DevSrvsID:4294969658
  serial_number: 
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2410
  Interface:    1
  Usage (page): 0x1 (0xc)

Device Found
  type: 046d c52b
  path: DevSrvsID:4294969658
  serial_number: 
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2410
  Interface:    1
  Usage (page): 0x80 (0x1)

Device Found
  type: 046d c52b
  path: DevSrvsID:4294969658
  serial_number: 
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2410
  Interface:    1
  Usage (page): 0x88 (0xffbc)

Device Found
  type: 046d 1000
  path: DevSrvsID:4294969745
  serial_number: 
  Manufacturer: Logitech
  Product:      LogiVirtualHIDDevice
  Release:      1
  Interface:    2
  Usage (page): 0x2 (0x1)

Device Found
  type: 046d 1000
  path: DevSrvsID:4294969745
  serial_number: 
  Manufacturer: Logitech
  Product:      LogiVirtualHIDDevice
  Release:      1
  Interface:    2
  Usage (page): 0x1 (0x1)

Device Found
  type: 0000 0000
  path: DevSrvsID:4294969106
  serial_number: 
  Manufacturer: Apple
  Product:      
  Release:      0
  Interface:    -1
  Usage (page): 0xff (0xff00)

Device Found
  type: 0000 0000
  path: DevSrvsID:4294968838
  serial_number: 
  Manufacturer: APPL
  Product:      BTM
  Release:      0
  Interface:    -1
  Usage (page): 0x48 (0xff00)

Device Found
  type: 046d b010
  path: DevSrvsID:4294970231
  serial_number: 34-88-5d-ab-0c-12
  Manufacturer: Unknown
  Product:      Bluetooth Mouse M557
  Release:      1002
  Interface:    -1
  Usage (page): 0x2 (0x1)

Device Found
  type: 046d b010
  path: DevSrvsID:4294970231
  serial_number: 34-88-5d-ab-0c-12
  Manufacturer: Unknown
  Product:      Bluetooth Mouse M557
  Release:      1002
  Interface:    -1
  Usage (page): 0x1 (0x1)

Device Found
  type: 046d b010
  path: DevSrvsID:4294970231
  serial_number: 34-88-5d-ab-0c-12
  Manufacturer: Unknown
  Product:      Bluetooth Mouse M557
  Release:      1002
  Interface:    -1
  Usage (page): 0x1 (0xc)

Device Found
  type: 046d b010
  path: DevSrvsID:4294970231
  serial_number: 34-88-5d-ab-0c-12
  Manufacturer: Unknown
  Product:      Bluetooth Mouse M557
  Release:      1002
  Interface:    -1
  Usage (page): 0x1 (0xff00)

Device Found
  type: 046d b010
  path: DevSrvsID:4294970231
  serial_number: 34-88-5d-ab-0c-12
  Manufacturer: Unknown
  Product:      Bluetooth Mouse M557
  Release:      1002
  Interface:    -1
  Usage (page): 0x2 (0xff00)

Device Found
  type: 046d b010
  path: DevSrvsID:4294970231
  serial_number: 34-88-5d-ab-0c-12
  Manufacturer: Unknown
  Product:      Bluetooth Mouse M557
  Release:      1002
  Interface:    -1
  Usage (page): 0x6 (0x1)

Device Found
  type: 046d c52b
  path: DevSrvsID:4294969655
  serial_number: 
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2410
  Interface:    2
  Usage (page): 0x1 (0xff00)

Device Found
  type: 046d c52b
  path: DevSrvsID:4294969655
  serial_number: 
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2410
  Interface:    2
  Usage (page): 0x2 (0xff00)

Device Found
  type: 046d c52b
  path: DevSrvsID:4294969655
  serial_number: 
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2410
  Interface:    2
  Usage (page): 0x4 (0xff00)

Device Found
  type: 0000 0000
  path: DevSrvsID:4294968456
  serial_number: 
  Manufacturer: Apple
  Product:      Headset
  Release:      0
  Interface:    -1
  Usage (page): 0x1 (0xc)

Device Found
  type: 046d c52b
  path: DevSrvsID:4294969651
  serial_number: 
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2410
  Interface:    0
  Usage (page): 0x6 (0x1)

Device Found
  type: 047f c025
  path: DevSrvsID:4294969649
  serial_number: CB13A3E40E8E47D6A40769C27E90A38E
  Manufacturer: Plantronics
  Product:      Plantronics C320-M
  Release:      135
  Interface:    3
  Usage (page): 0x1 (0xc)

Device Found
  type: 047f c025
  path: DevSrvsID:4294969649
  serial_number: CB13A3E40E8E47D6A40769C27E90A38E
  Manufacturer: Plantronics
  Product:      Plantronics C320-M
  Release:      135
  Interface:    3
  Usage (page): 0x5 (0xb)

Device Found
  type: 047f c025
  path: DevSrvsID:4294969649
  serial_number: CB13A3E40E8E47D6A40769C27E90A38E
  Manufacturer: Plantronics
  Product:      Plantronics C320-M
  Release:      135
  Interface:    3
  Usage (page): 0x1 (0xffa0)

unable to open device

Without this pull request, it is problematic for my setup whhere I have two powered hub (which are nested hub themselves).


hidapi on  master [?] via △ v3.21.1 ❯ ./buildarm64/hidtest/hidtest 
hidapi test/example tool. Compiled with hidapi version 0.11.0, runtime version 0.11.0.
Compile-time version matches runtime version of hidapi.

Device Found
  type: 046d c52b
  path: 
  serial_number: 
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2410
  Interface:    0
  Usage (page): 0x6 (0x1)

Device Found
  type: 0000 0000
  path: IOService:/AppleARMPE/arm-io@10F00000/AppleT810xIO/aop@4A400000/AppleASCWrapV4/iop-aop-nub/RTBuddyV2/AOPEndpoint6/AppleSPU@10000001/wakehint/AppleSPUHIDDevice
  serial_number: 
  Manufacturer: Apple
  Product:      
  Release:      0
  Interface:    -1
  Usage (page): 0xff (0xff00)

Device Found
  type: 046d b010
  path: IOService:/IOResources/IOBluetoothHCIController/AppleBroadcomBluetoothHostController/IOBluetoothDevice/IOBluetoothL2CAPChannel/IOBluetoothHIDDriver
  serial_number: 34-88-5d-ab-0c-12
  Manufacturer: Unknown
  Product:      Bluetooth Mouse M557
  Release:      1002
  Interface:    -1
  Usage (page): 0x2 (0x1)

Device Found
  type: 046d b010
  path: IOService:/IOResources/IOBluetoothHCIController/AppleBroadcomBluetoothHostController/IOBluetoothDevice/IOBluetoothL2CAPChannel/IOBluetoothHIDDriver
  serial_number: 34-88-5d-ab-0c-12
  Manufacturer: Unknown
  Product:      Bluetooth Mouse M557
  Release:      1002
  Interface:    -1
  Usage (page): 0x1 (0x1)

Device Found
  type: 046d b010
  path: IOService:/IOResources/IOBluetoothHCIController/AppleBroadcomBluetoothHostController/IOBluetoothDevice/IOBluetoothL2CAPChannel/IOBluetoothHIDDriver
  serial_number: 34-88-5d-ab-0c-12
  Manufacturer: Unknown
  Product:      Bluetooth Mouse M557
  Release:      1002
  Interface:    -1
  Usage (page): 0x1 (0xc)

Device Found
  type: 046d b010
  path: IOService:/IOResources/IOBluetoothHCIController/AppleBroadcomBluetoothHostController/IOBluetoothDevice/IOBluetoothL2CAPChannel/IOBluetoothHIDDriver
  serial_number: 34-88-5d-ab-0c-12
  Manufacturer: Unknown
  Product:      Bluetooth Mouse M557
  Release:      1002
  Interface:    -1
  Usage (page): 0x1 (0xff00)

Device Found
  type: 046d b010
  path: IOService:/IOResources/IOBluetoothHCIController/AppleBroadcomBluetoothHostController/IOBluetoothDevice/IOBluetoothL2CAPChannel/IOBluetoothHIDDriver
  serial_number: 34-88-5d-ab-0c-12
  Manufacturer: Unknown
  Product:      Bluetooth Mouse M557
  Release:      1002
  Interface:    -1
  Usage (page): 0x2 (0xff00)

Device Found
  type: 046d b010
  path: IOService:/IOResources/IOBluetoothHCIController/AppleBroadcomBluetoothHostController/IOBluetoothDevice/IOBluetoothL2CAPChannel/IOBluetoothHIDDriver
  serial_number: 34-88-5d-ab-0c-12
  Manufacturer: Unknown
  Product:      Bluetooth Mouse M557
  Release:      1002
  Interface:    -1
  Usage (page): 0x6 (0x1)

Device Found
  type: 046d 1000
  path: 
  serial_number: 
  Manufacturer: Logitech
  Product:      LogiVirtualHIDDevice
  Release:      1
  Interface:    2
  Usage (page): 0x2 (0x1)

Device Found
  type: 046d 1000
  path: 
  serial_number: 
  Manufacturer: Logitech
  Product:      LogiVirtualHIDDevice
  Release:      1
  Interface:    2
  Usage (page): 0x1 (0x1)

Device Found
  type: 046d c52b
  path: 
  serial_number: 
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2410
  Interface:    2
  Usage (page): 0x1 (0xff00)

Device Found
  type: 046d c52b
  path: 
  serial_number: 
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2410
  Interface:    2
  Usage (page): 0x2 (0xff00)

Device Found
  type: 046d c52b
  path: 
  serial_number: 
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2410
  Interface:    2
  Usage (page): 0x4 (0xff00)

Device Found
  type: 047f c025
  path: IOService:/AppleARMPE/arm-io@10F00000/AppleT810xIO/apcie@90000000/AppleT8103PCIe/pci-bridge1@1/IOPP/pcie-xhci@0/AppleT8103USBXHCIFL1100@02000000/pcie-xhci-hs-port2@02200000/4-Port USB 2.0 Hub@02200000/AppleUSB20Hub@02200000/AppleUSB20HubPort@02210000/4-Port USB 2.0 Hub@02210000/AppleUSB20Hub@02210000/AppleUSB20HubPort@02212000/USB 2.0 Hub [MTT]@02212000/AppleUSB20Hub@02212000/AppleUSB20HubPort@02212600/Plantronics C320-M@02212600/IOUSBHostInterface@3/AppleUserUSBHostHIDDevice
  serial_number: CB13A3E40E8E47D6A40769C27E90A38E
  Manufacturer: Plantronics
  Product:      Plantronics C320-M
  Release:      135
  Interface:    3
  Usage (page): 0x1 (0xc)

Device Found
  type: 047f c025
  path: IOService:/AppleARMPE/arm-io@10F00000/AppleT810xIO/apcie@90000000/AppleT8103PCIe/pci-bridge1@1/IOPP/pcie-xhci@0/AppleT8103USBXHCIFL1100@02000000/pcie-xhci-hs-port2@02200000/4-Port USB 2.0 Hub@02200000/AppleUSB20Hub@02200000/AppleUSB20HubPort@02210000/4-Port USB 2.0 Hub@02210000/AppleUSB20Hub@02210000/AppleUSB20HubPort@02212000/USB 2.0 Hub [MTT]@02212000/AppleUSB20Hub@02212000/AppleUSB20HubPort@02212600/Plantronics C320-M@02212600/IOUSBHostInterface@3/AppleUserUSBHostHIDDevice
  serial_number: CB13A3E40E8E47D6A40769C27E90A38E
  Manufacturer: Plantronics
  Product:      Plantronics C320-M
  Release:      135
  Interface:    3
  Usage (page): 0x5 (0xb)

Device Found
  type: 047f c025
  path: IOService:/AppleARMPE/arm-io@10F00000/AppleT810xIO/apcie@90000000/AppleT8103PCIe/pci-bridge1@1/IOPP/pcie-xhci@0/AppleT8103USBXHCIFL1100@02000000/pcie-xhci-hs-port2@02200000/4-Port USB 2.0 Hub@02200000/AppleUSB20Hub@02200000/AppleUSB20HubPort@02210000/4-Port USB 2.0 Hub@02210000/AppleUSB20Hub@02210000/AppleUSB20HubPort@02212000/USB 2.0 Hub [MTT]@02212000/AppleUSB20Hub@02212000/AppleUSB20HubPort@02212600/Plantronics C320-M@02212600/IOUSBHostInterface@3/AppleUserUSBHostHIDDevice
  serial_number: CB13A3E40E8E47D6A40769C27E90A38E
  Manufacturer: Plantronics
  Product:      Plantronics C320-M
  Release:      135
  Interface:    3
  Usage (page): 0x1 (0xffa0)

Device Found
  type: 0000 0000
  path: IOService:/AppleARMPE/arm-io@10F00000/AppleT810xIO/nub-spmi@3D0D9300/AppleT8101SPMIController/btm@F/AppleBTM
  serial_number: 
  Manufacturer: APPL
  Product:      BTM
  Release:      0
  Interface:    -1
  Usage (page): 0x48 (0xff00)

Device Found
  type: 0000 0000
  path: IOService:/AppleARMPE/arm-io@10F00000/AppleT810xIO/i2c2@35018000/AppleS5L8940XI2CController/audio-codec-output@48/AppleCS42L83Audio/AppleCS42L83Mikey
  serial_number: 
  Manufacturer: Apple
  Product:      Headset
  Release:      0
  Interface:    -1
  Usage (page): 0x1 (0xc)

Device Found
  type: 046d c52b
  path: 
  serial_number: 
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2410
  Interface:    1
  Usage (page): 0x2 (0x1)

Device Found
  type: 046d c52b
  path: 
  serial_number: 
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2410
  Interface:    1
  Usage (page): 0x1 (0x1)

Device Found
  type: 046d c52b
  path: 
  serial_number: 
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2410
  Interface:    1
  Usage (page): 0x1 (0xc)

Device Found
  type: 046d c52b
  path: 
  serial_number: 
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2410
  Interface:    1
  Usage (page): 0x80 (0x1)

Device Found
  type: 046d c52b
  path: 
  serial_number: 
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2410
  Interface:    1
  Usage (page): 0x88 (0xffbc)

unable to open device

@mcuee mcuee added the macOS Related to macOS backend label Aug 15, 2021
@Youw Youw merged commit 4d63a50 into master Aug 23, 2021
@Youw Youw deleted the macos-path branch August 23, 2021 17:58
@mcuee
Copy link
Member

mcuee commented Aug 25, 2021

@Youw Is it possible to integrate this patch with the branch https://github.com/libusb/hidapi/tree/get-descriptor? Or what is the simple way for me to merge this patch with my local repo? Sorry I am not good at using git. Or maybe the other way around, integrate get-descriptor branch to the main branch.

@mcuee
Copy link
Member

mcuee commented Aug 25, 2021

Not so sure if the following is the correct way.

hidapi on  master [?] via △ v3.21.1 ❯ git branch mytest

hidapi on  master [?] via △ v3.21.1 ❯ git checkout mytest
Switched to branch 'mytest'
		
hidapi on  mytest [?] via △ v3.21.1 ❯ wget https://github.com/libusb/hidapi/commit/0db25f9132efaa3dfed3e376ba4cfea5e7c7fed8.patch
...

2021-08-25 19:16:44 (23.1 MB/s) - ‘0db25f9132efaa3dfed3e376ba4cfea5e7c7fed8.patch’ saved [5560/5560]

hidapi on  mytest [?] via △ v3.21.1 ❯ git apply 0db25f9132efaa3dfed3e376ba4cfea5e7c7fed8.patch 
hidapi on  mytest [!?] via △ v3.21.1 took 9s ❯ wget https://github.com/libusb/hidapi/commit/26d45bf4272ddcf4c845a5f28e5c451cf7999695.patch
...
2021-08-25 19:17:52 (2.32 MB/s) - ‘26d45bf4272ddcf4c845a5f28e5c451cf7999695.patch’ saved [592/592]

hidapi on  mytest [!?] via △ v3.21.1 ❯ git apply 26d45bf4272ddcf4c845a5f28e5c451cf7999695.patch 

@Youw
Copy link
Member Author

Youw commented Aug 25, 2021

Is it possible to integrate this patch with the branch https://github.com/libusb/hidapi/tree/get-descriptor?

Technically we want to "sync get-descriptor branch with master".
I did so by "merge master into get-descriptor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
macOS Related to macOS backend
Projects
None yet
Development

Successfully merging this pull request may close these issues.

macOS: Bluetooth HID devices have the same path
2 participants