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

RFC: Add HID bus type in hid_device_info #308

Merged
merged 3 commits into from
Sep 10, 2022
Merged

Conversation

DJm00n
Copy link
Contributor

@DJm00n DJm00n commented Jul 22, 2021

It happens that Bluetooth HID gamepads are having the same VID/PID as when connected via USB (DualShock4 and DualSense for example). But they have different report descriptors and thus input/output reports. We need a way to differentiate them.

To address this I have added a new hid_bus_type enum and hid_bus_type bus_type field to hid_device_info struct:

typedef enum {
	/* Unknown bus type */
	HID_API_BUS_UNKNOWN = 0x00,

	/* USB bus
	   Specifications:
	   https://usb.org/hid */
	HID_API_BUS_USB = 0x01,

	/* Bluetooth or Bluetooth LE bus
	   Specifications:
	   https://www.bluetooth.com/specifications/specs/human-interface-device-profile-1-1-1/
	   https://www.bluetooth.com/specifications/specs/hid-service-1-0/
	   https://www.bluetooth.com/specifications/specs/hid-over-gatt-profile-1-0/ */
	HID_API_BUS_BLUETOOTH = 0x02,

	/* I2C bus
	   Specifications:
	   https://docs.microsoft.com/previous-versions/windows/hardware/design/dn642101(v=vs.85) */
	HID_API_BUS_I2C = 0x03,

	/* SPI bus
	   Specifications:
	   https://www.microsoft.com/download/details.aspx?id=103325 */
	HID_API_BUS_SPI = 0x04,
} hid_bus_type;

Implemented it for Windows, libusb, hidraw and MacOS backends.

@DJm00n DJm00n changed the title WIP: Hid bus type in hid_device_info RFC: Hid bus type in hid_device_info Jul 22, 2021
@DJm00n DJm00n changed the title RFC: Hid bus type in hid_device_info RFC: Add HID bus type in hid_device_info Jul 22, 2021
@mcuee mcuee added Core Related to common codes like hidapi.h hidraw Related to Linux/hidraw backend libusb Related to libusb backend macOS Related to macOS backend Windows Related to Windows backend enhancement New feature or request labels Jul 22, 2021
@DJm00n
Copy link
Contributor Author

DJm00n commented Jul 22, 2021

Sony DualSense controller example.

Before:

Device Found
  type: 054c 0ce6
  path: \\?\hid#{00001124-0000-1000-8000-00805f9b34fb}_vid&0002054c_pid&0ce6#8&3265df1c&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: a0ab518cf90a
  Manufacturer: Sony Interactive Entertainment
  Product:      Wireless Controller
  Release:      0
  Interface:    -1
  Usage (page): 0x5 (0x1)

Device Found
  type: 054c 0ce6
  path: \\?\hid#vid_054c&pid_0ce6&mi_03#7&2a5e324d&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number:
  Manufacturer: Sony Interactive Entertainment
  Product:      Wireless Controller
  Release:      100
  Interface:    3
  Usage (page): 0x5 (0x1)

After:

Device Found
  type: 054c 0ce6
  path: \\?\hid#{00001124-0000-1000-8000-00805f9b34fb}_vid&0002054c_pid&0ce6#8&3265df1c&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: a0ab518cf90a
  Manufacturer: Sony Interactive Entertainment
  Product:      Wireless Controller
  Release:      0
  Interface:    -1
  Usage (page): 0x5 (0x1)
  Bus type: 2
  
Device Found
  type: 054c 0ce6
  path: \\?\hid#vid_054c&pid_0ce6&mi_03#7&2a5e324d&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number:
  Manufacturer: Sony Interactive Entertainment
  Product:      Wireless Controller
  Release:      100
  Interface:    3
  Usage (page): 0x5 (0x1)
  Bus type: 1

@DJm00n
Copy link
Contributor Author

DJm00n commented Jul 22, 2021

I didn't test Linux version yet.

@DJm00n
Copy link
Contributor Author

DJm00n commented Jul 23, 2021

@mcuee @Youw can you test it on Linux?

@Youw
Copy link
Member

Youw commented Jul 23, 2021

Technically I could, but right now I'm a little short on time regarding everything, so I can only ask not to make any expectations when I'll do it
I can only promice that I will, and I'm also going to see if this can be implemented for macOS as well

@mcuee
Copy link
Member

mcuee commented Jul 24, 2021

Here is the test results on my Raspberry Pi 400 running 64bit Ubuntu Linux.

click to expand for the run log
hidapi_djm on  hid_bus_type via △ v3.18.4 took 3s ❯ ./hidtest/hidtest-libusb 
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: 04d9 0007
  path: 1-1.4:1.0
  serial_number: (null)
  Manufacturer: (null)
  Product:      (null)
  Release:      161
  Interface:    0
  Usage (page): 0x0 (0x0)
  Bus type: 1

Device Found
  type: 04d9 0007
  path: 1-1.4:1.1
  serial_number: (null)
  Manufacturer: (null)
  Product:      (null)
  Release:      161
  Interface:    1
  Usage (page): 0x0 (0x0)
  Bus type: 1

Device Found
  type: 047f c025
  path: 1-1.2.1.2.6:1.3
  serial_number: (null)
  Manufacturer: (null)
  Product:      (null)
  Release:      135
  Interface:    3
  Usage (page): 0x0 (0x0)
  Bus type: 1

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

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

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

unable to open device

hidapi_djm on  hid_bus_type via △ v3.18.4 ❯ ./hidtest/hidtest-hidraw 
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 101b
  path: /dev/hidraw4
  serial_number: 101b-ae-8a-0c-8c
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2410
  Interface:    2
  Usage (page): 0x2 (0x1)
  Bus type: 1

Device Found
  type: 046d 101b
  path: /dev/hidraw4
  serial_number: 101b-ae-8a-0c-8c
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2410
  Interface:    2
  Usage (page): 0x1 (0x1)
  Bus type: 0

Device Found
  type: 046d 101b
  path: /dev/hidraw4
  serial_number: 101b-ae-8a-0c-8c
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2410
  Interface:    2
  Usage (page): 0x1 (0xff00)
  Bus type: 0

Device Found
  type: 046d 101b
  path: /dev/hidraw4
  serial_number: 101b-ae-8a-0c-8c
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2410
  Interface:    2
  Usage (page): 0x2 (0xff00)
  Bus type: 0

Device Found
  type: 046d 101b
  path: /dev/hidraw4
  serial_number: 101b-ae-8a-0c-8c
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2410
  Interface:    2
  Usage (page): 0x4 (0xff00)
  Bus type: 0

Device Found
  type: 046d 2008
  path: /dev/hidraw5
  serial_number: 2008-b6-b4-d3-96
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2410
  Interface:    2
  Usage (page): 0x6 (0x1)
  Bus type: 1

Device Found
  type: 046d 2008
  path: /dev/hidraw5
  serial_number: 2008-b6-b4-d3-96
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2410
  Interface:    2
  Usage (page): 0x1 (0xc)
  Bus type: 0

Device Found
  type: 046d 2008
  path: /dev/hidraw5
  serial_number: 2008-b6-b4-d3-96
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2410
  Interface:    2
  Usage (page): 0x80 (0x1)
  Bus type: 0

Device Found
  type: 046d 2008
  path: /dev/hidraw5
  serial_number: 2008-b6-b4-d3-96
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2410
  Interface:    2
  Usage (page): 0x88 (0xffbc)
  Bus type: 0

Device Found
  type: 046d 2008
  path: /dev/hidraw5
  serial_number: 2008-b6-b4-d3-96
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2410
  Interface:    2
  Usage (page): 0x1 (0xff00)
  Bus type: 0

Device Found
  type: 046d 2008
  path: /dev/hidraw5
  serial_number: 2008-b6-b4-d3-96
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2410
  Interface:    2
  Usage (page): 0x2 (0xff00)
  Bus type: 0

Device Found
  type: 046d 2008
  path: /dev/hidraw5
  serial_number: 2008-b6-b4-d3-96
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2410
  Interface:    2
  Usage (page): 0x4 (0xff00)
  Bus type: 0

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

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

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

Device Found
  type: 046d b010
  path: /dev/hidraw6
  serial_number: 34:88:5d:ab:0c:12
  Manufacturer: 
  Product:      Bluetooth Mouse M557
  Release:      0
  Interface:    -1
  Usage (page): 0x2 (0x1)
  Bus type: 2

Device Found
  type: 046d b010
  path: /dev/hidraw6
  serial_number: 34:88:5d:ab:0c:12
  Manufacturer: 
  Product:      Bluetooth Mouse M557
  Release:      0
  Interface:    -1
  Usage (page): 0x1 (0x1)
  Bus type: 0

Device Found
  type: 046d b010
  path: /dev/hidraw6
  serial_number: 34:88:5d:ab:0c:12
  Manufacturer: 
  Product:      Bluetooth Mouse M557
  Release:      0
  Interface:    -1
  Usage (page): 0x1 (0xc)
  Bus type: 0

Device Found
  type: 046d b010
  path: /dev/hidraw6
  serial_number: 34:88:5d:ab:0c:12
  Manufacturer: 
  Product:      Bluetooth Mouse M557
  Release:      0
  Interface:    -1
  Usage (page): 0x1 (0xff00)
  Bus type: 0

Device Found
  type: 046d b010
  path: /dev/hidraw6
  serial_number: 34:88:5d:ab:0c:12
  Manufacturer: 
  Product:      Bluetooth Mouse M557
  Release:      0
  Interface:    -1
  Usage (page): 0x2 (0xff00)
  Bus type: 0

Device Found
  type: 046d b010
  path: /dev/hidraw6
  serial_number: 34:88:5d:ab:0c:12
  Manufacturer: 
  Product:      Bluetooth Mouse M557
  Release:      0
  Interface:    -1
  Usage (page): 0x6 (0x1)
  Bus type: 0

Device Found
  type: 046d b010
  path: /dev/hidraw6
  serial_number: 34:88:5d:ab:0c:12
  Manufacturer: 
  Product:      Bluetooth Mouse M557
  Release:      0
  Interface:    -1
  Usage (page): 0x1 (0xc)
  Bus type: 0

Device Found
  type: 047f c025
  path: /dev/hidraw3
  serial_number: CB13A3E40E8E47D6A40769C27E90A38E
  Manufacturer: Plantronics
  Product:      Plantronics C320-M
  Release:      135
  Interface:    3
  Usage (page): 0x1 (0xc)
  Bus type: 1

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

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

Device Found
  type: 04d9 0007
  path: /dev/hidraw0
  serial_number: 
  Manufacturer:  
  Product:      Raspberry Pi Internal Keyboard
  Release:      161
  Interface:    0
  Usage (page): 0x6 (0x1)
  Bus type: 1

Device Found
  type: 04d9 0007
  path: /dev/hidraw1
  serial_number: 
  Manufacturer:  
  Product:      Raspberry Pi Internal Keyboard
  Release:      161
  Interface:    1
  Usage (page): 0x1 (0xc)
  Bus type: 1

unable to open device

@mcuee
Copy link
Member

mcuee commented Jul 24, 2021

@DJm00n You can see that libusb backend output is expected. As for the hidraw backend, on one hand it seems to work, but on the other hand, many reports bus type "0". Is this expected by your design? Take note hidraw backend has the feature of ""split by usage_page/usage" as per #287 .

@mcuee
Copy link
Member

mcuee commented Jul 24, 2021

Under my Windows 10 laptop (Windows 10 Enterprise x64 20H2), it seems to me Microsoft HIDI2C device is not listed correctly.

click to expand
C:\work\hid\hidapi_djm\windows\x64\Release [ble_device_info ≡]> .\hidtest.exe
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 c534
  path: \\?\hid#vid_046d&pid_c534&mi_01&col03#7&1ebb799e&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2901
  Interface:    1
  Usage (page): 0x80 (0x1)
  Bus type: 1

Device Found
  type: 046d c534
  path: \\?\hid#vid_046d&pid_c534&mi_01&col04#7&1ebb799e&0&0003#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2901
  Interface:    1
  Usage (page): 0x1 (0xff00)
  Bus type: 1

Device Found
  type: 046d c534
  path: \\?\hid#vid_046d&pid_c534&mi_01&col05#7&1ebb799e&0&0004#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2901
  Interface:    1
  Usage (page): 0x2 (0xff00)
  Bus type: 1

Device Found
  type: 0488 121f
  path: \\?\hid#dell091a&col01#5&99b72d3&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: 9999
  Manufacturer: Microsoft
  Product:      HIDI2C Device
  Release:      40d
  Interface:    -1
  Usage (page): 0x2 (0x1)
  Bus type: 255

Device Found
  type: 8087 0a1e
  path: \\?\hid#intc816&col01#3&36a7043c&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number:
  Manufacturer:
  Product:
  Release:      200
  Interface:    -1
  Usage (page): 0xc (0x1)
  Bus type: 255

Device Found
  type: 044e 1212
  path: \\?\hid#vid_044e&pid_1212&col01&col02#7&290aacae&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}\kbd
  serial_number:
  Manufacturer:
  Product:
  Release:      0
  Interface:    -1
  Usage (page): 0x6 (0x1)
  Bus type: 255

Device Found
  type: 8087 0a1e
  path: \\?\hid#intc816&col02#3&36a7043c&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number:
  Manufacturer:
  Product:
  Release:      200
  Interface:    -1
  Usage (page): 0xd (0x1)
  Bus type: 255

Device Found
  type: 044e 1212
  path: \\?\hid#vid_044e&pid_1212&col01&col01#7&290aacae&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number:
  Manufacturer:
  Product:
  Release:      0
  Interface:    -1
  Usage (page): 0x2 (0x1)
  Bus type: 255

Device Found
  type: 0488 121f
  path: \\?\hid#dell091a&col02#5&99b72d3&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: 9999
  Manufacturer: Microsoft
  Product:      HIDI2C Device
  Release:      40d
  Interface:    -1
  Usage (page): 0x5 (0xd)
  Bus type: 255

Device Found
  type: 047f c056
  path: \\?\hid#vid_047f&pid_c056&mi_03&col01#f&39e6f119&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: D1CEC32927974D5F9BD6B2AEBF2EA8E3
  Manufacturer: Plantronics
  Product:      Plantronics Blackwire 3220 Series
  Release:      210
  Interface:    3
  Usage (page): 0x1 (0xc)
  Bus type: 1

Device Found
  type: 045e 0000
  path: \\?\hid#converteddevice&col02#5&379854aa&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number:
  Manufacturer:
  Product:
  Release:      0
  Interface:    -1
  Usage (page): 0x1 (0xc)
  Bus type: 255

Device Found
  type: 047f c056
  path: \\?\hid#vid_047f&pid_c056&mi_03&col02#f&39e6f119&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: D1CEC32927974D5F9BD6B2AEBF2EA8E3
  Manufacturer: Plantronics
  Product:      Plantronics Blackwire 3220 Series
  Release:      210
  Interface:    3
  Usage (page): 0x5 (0xb)
  Bus type: 1

Device Found
  type: 045e 0000
  path: \\?\hid#converteddevice&col03#5&379854aa&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number:
  Manufacturer:
  Product:
  Release:      0
  Interface:    -1
  Usage (page): 0x80 (0x1)
  Bus type: 255

Device Found
  type: 047f c056
  path: \\?\hid#vid_047f&pid_c056&mi_03&col03#f&39e6f119&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: D1CEC32927974D5F9BD6B2AEBF2EA8E3
  Manufacturer: Plantronics
  Product:      Plantronics Blackwire 3220 Series
  Release:      210
  Interface:    3
  Usage (page): 0x3 (0xffa0)
  Bus type: 1

Device Found
  type: 0488 121f
  path: \\?\hid#dell091a&col03#5&99b72d3&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: 9999
  Manufacturer: Microsoft
  Product:      HIDI2C Device
  Release:      40d
  Interface:    -1
  Usage (page): 0x1 (0xff01)
  Bus type: 255

Device Found
  type: 0488 121f
  path: \\?\hid#dell091a&col04#5&99b72d3&0&0003#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: 9999
  Manufacturer: Microsoft
  Product:      HIDI2C Device
  Release:      40d
  Interface:    -1
  Usage (page): 0x1 (0xff02)
  Bus type: 255

Device Found
  type: 046d c534
  path: \\?\hid#vid_046d&pid_c534&mi_00#7&51bc424&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}\kbd
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2901
  Interface:    0
  Usage (page): 0x6 (0x1)
  Bus type: 1

Device Found
  type: 0488 121f
  path: \\?\hid#dell091a&col05#5&99b72d3&0&0004#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: 9999
  Manufacturer: Microsoft
  Product:      HIDI2C Device
  Release:      40d
  Interface:    -1
  Usage (page): 0xe (0xd)
  Bus type: 255

Device Found
  type: 046d c534
  path: \\?\hid#vid_046d&pid_c534&mi_01&col01#7&1ebb799e&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2901
  Interface:    1
  Usage (page): 0x2 (0x1)
  Bus type: 1

Device Found
  type: 046d c534
  path: \\?\hid#vid_046d&pid_c534&mi_01&col02#7&1ebb799e&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2901
  Interface:    1
  Usage (page): 0x1 (0xc)
  Bus type: 1

Device Found
  type: 045e 0000
  path: \\?\hid#converteddevice&col01#5&379854aa&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}\kbd
  serial_number:
  Manufacturer:
  Product:
  Release:      0
  Interface:    -1
  Usage (page): 0x6 (0x1)
  Bus type: 255

Device Found
  type: 046d b010
  path: \\?\hid#{00001124-0000-1000-8000-00805f9b34fb}_vid&0002046d_pid&b010&col01#8&1cf1c1b9&2&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: 34885dab0c12
  Manufacturer: Logitech
  Product:      Logitech Bluetooth Wireless Mouse
  Release:      0
  Interface:    -1
  Usage (page): 0x2 (0x1)
  Bus type: 2

Device Found
  type: 046d b010
  path: \\?\hid#{00001124-0000-1000-8000-00805f9b34fb}_vid&0002046d_pid&b010&col02#8&1cf1c1b9&2&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: 34885dab0c12
  Manufacturer: Logitech
  Product:      Logitech Bluetooth Wireless Mouse
  Release:      0
  Interface:    -1
  Usage (page): 0x1 (0xc)
  Bus type: 2

Device Found
  type: 046d b010
  path: \\?\hid#{00001124-0000-1000-8000-00805f9b34fb}_vid&0002046d_pid&b010&col03#8&1cf1c1b9&2&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: 34885dab0c12
  Manufacturer: Logitech
  Product:      Logitech Bluetooth Wireless Mouse
  Release:      0
  Interface:    -1
  Usage (page): 0x1 (0xff00)
  Bus type: 2

Device Found
  type: 046d b010
  path: \\?\hid#{00001124-0000-1000-8000-00805f9b34fb}_vid&0002046d_pid&b010&col04#8&1cf1c1b9&2&0003#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: 34885dab0c12
  Manufacturer: Logitech
  Product:      Logitech Bluetooth Wireless Mouse
  Release:      0
  Interface:    -1
  Usage (page): 0x2 (0xff00)
  Bus type: 2

Device Found
  type: 046d b010
  path: \\?\hid#{00001124-0000-1000-8000-00805f9b34fb}_vid&0002046d_pid&b010&col05#8&1cf1c1b9&2&0004#{4d1e55b2-f16f-11cf-88cb-001111000030}\kbd
  serial_number: 34885dab0c12
  Manufacturer: Logitech
  Product:      Logitech Bluetooth Wireless Mouse
  Release:      0
  Interface:    -1
  Usage (page): 0x6 (0x1)
  Bus type: 2

Device Found
  type: 046d b010
  path: \\?\hid#{00001124-0000-1000-8000-00805f9b34fb}_vid&0002046d_pid&b010&col06#8&1cf1c1b9&2&0005#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: 34885dab0c12
  Manufacturer: Logitech
  Product:      Logitech Bluetooth Wireless Mouse
  Release:      0
  Interface:    -1
  Usage (page): 0x1 (0xc)
  Bus type: 2

unable to open device

@mcuee
Copy link
Member

mcuee commented Jul 24, 2021

@DJm00n For the I2C HID device, you have the following codes for Windows.

	/* I2C HID devices have a special ACPI ID
	   https://docs.microsoft.com/windows-hardware/drivers/hid/plug-and-play-support-and-power-management */
	if (wcsstr(device_id, L"ACPI\\PNP0C50") != 0) {
		dev->bus_type = HID_BUS_I2C;
		goto close;
	}

And I checked the Microsoft I2CHID device in Device Manager "Human Interface Devices" section and indeed it has a "Compatible device id" and "Matching device id" value of "ACPI\PNP0C50".

@mcuee
Copy link
Member

mcuee commented Jul 24, 2021

@DJm00n And for those "\?\hid#converteddevice", I am not exactly sure if 255 is the right one to use. I tend to think they are more like "virtual hid bus type". But I am okay as well if you use 255 if there are no better ways.

@mcuee
Copy link
Member

mcuee commented Jul 24, 2021

@DJm00n From what I see, the following Windows codes are not good enough (just using "Device_InstanceId"). On the other hand, for the purpose of HIDAPI, maybe it is still okay. I do not think we can do much with the "Microsoft I2CHID device" anyway.

	/* Get the device id from parent devnode */
	len = 0;
	cr = CM_Get_DevNode_PropertyW(dev_node, &DEVPKEY_Device_InstanceId, &property_type, NULL, &len, 0);
	if (cr == CR_BUFFER_SMALL && property_type == DEVPROP_TYPE_STRING) {
		free(device_id);
		device_id = (wchar_t*)calloc(len, sizeof(BYTE));
		cr = CM_Get_DevNode_PropertyW(dev_node, &DEVPKEY_Device_InstanceId, &property_type, (PBYTE)device_id, &len, 0);
	}

@DJm00n
Copy link
Contributor Author

DJm00n commented Jul 24, 2021

@mcuee Thank you for testing it!

I don't have such I2C or SPI HID devices in person. So I need some further help.

Can you debug the code a bit and look what exact device_id (acquired with DEVPKEY_Device_InstanceId property) your devices are having?

For example you can add:

wprintf(L"DEVPKEY_Device_InstanceId: %s\n", device_id);

before if (wcsstr(...)) checks.

@mcuee
Copy link
Member

mcuee commented Jul 24, 2021

@DJm00n This is what I get.

click to expand
C:\work\hid\hidapi_djm\windows\x64\Debug [ble_device_info ≡ +0 ~1 -0 !]> .\hidtest.exe
hidapi test/example tool. Compiled with hidapi version 0.11.0, runtime version 0.11.0.
Compile-time version matches runtime version of hidapi.

DEVPKEY_Device_InstanceId: USB\VID_046D&PID_C534&MI_01\6&1CFA36F4&0&0001
DEVPKEY_Device_InstanceId: USB\VID_046D&PID_C534&MI_01\6&1CFA36F4&0&0001
DEVPKEY_Device_InstanceId: USB\VID_046D&PID_C534&MI_01\6&1CFA36F4&0&0001
DEVPKEY_Device_InstanceId: ACPI\DELL091A\4&27F2A591&0
DEVPKEY_Device_InstanceId: ACPI\INT33D5\2&DABA3FF&0
DEVPKEY_Device_InstanceId: HID\VID_044E&PID_1212&COL01\6&298C10D6&0&0000
DEVPKEY_Device_InstanceId: ACPI\INT33D5\2&DABA3FF&0
DEVPKEY_Device_InstanceId: HID\VID_044E&PID_1212&COL01\6&298C10D6&0&0000
DEVPKEY_Device_InstanceId: ACPI\DELL091A\4&27F2A591&0
DEVPKEY_Device_InstanceId: USB\VID_047F&PID_C056&MI_03\E&3A27DC9B&0&0003
DEVPKEY_Device_InstanceId: BUTTONCONVERTER\CONVERTEDDEVICE\4&32F8A6A3&0&0
DEVPKEY_Device_InstanceId: USB\VID_047F&PID_C056&MI_03\E&3A27DC9B&0&0003
DEVPKEY_Device_InstanceId: BUTTONCONVERTER\CONVERTEDDEVICE\4&32F8A6A3&0&0
DEVPKEY_Device_InstanceId: USB\VID_047F&PID_C056&MI_03\E&3A27DC9B&0&0003
DEVPKEY_Device_InstanceId: BTHENUM\{00001124-0000-1000-8000-00805F9B34FB}_VID&0002046D_PID&B010\7&31D658D&0&34885DAB0C12_C00000000
DEVPKEY_Device_InstanceId: ACPI\DELL091A\4&27F2A591&0
DEVPKEY_Device_InstanceId: ACPI\DELL091A\4&27F2A591&0
DEVPKEY_Device_InstanceId: BTHENUM\{00001124-0000-1000-8000-00805F9B34FB}_VID&0002046D_PID&B010\7&31D658D&0&34885DAB0C12_C00000000
DEVPKEY_Device_InstanceId: USB\VID_046D&PID_C534&MI_00\6&1CFA36F4&0&0000
DEVPKEY_Device_InstanceId: BTHENUM\{00001124-0000-1000-8000-00805F9B34FB}_VID&0002046D_PID&B010\7&31D658D&0&34885DAB0C12_C00000000
DEVPKEY_Device_InstanceId: BTHENUM\{00001124-0000-1000-8000-00805F9B34FB}_VID&0002046D_PID&B010\7&31D658D&0&34885DAB0C12_C00000000
DEVPKEY_Device_InstanceId: ACPI\DELL091A\4&27F2A591&0
DEVPKEY_Device_InstanceId: BTHENUM\{00001124-0000-1000-8000-00805F9B34FB}_VID&0002046D_PID&B010\7&31D658D&0&34885DAB0C12_C00000000
DEVPKEY_Device_InstanceId: USB\VID_046D&PID_C534&MI_01\6&1CFA36F4&0&0001
DEVPKEY_Device_InstanceId: BTHENUM\{00001124-0000-1000-8000-00805F9B34FB}_VID&0002046D_PID&B010\7&31D658D&0&34885DAB0C12_C00000000
DEVPKEY_Device_InstanceId: USB\VID_046D&PID_C534&MI_01\6&1CFA36F4&0&0001
DEVPKEY_Device_InstanceId: BUTTONCONVERTER\CONVERTEDDEVICE\4&32F8A6A3&0&0
Device Found
  type: 046d c534
  path: \\?\hid#vid_046d&pid_c534&mi_01&col03#7&1ebb799e&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2901
  Interface:    1
  Usage (page): 0x80 (0x1)
  Bus type: 1

Device Found
  type: 046d c534
  path: \\?\hid#vid_046d&pid_c534&mi_01&col04#7&1ebb799e&0&0003#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2901
  Interface:    1
  Usage (page): 0x1 (0xff00)
  Bus type: 1

Device Found
  type: 046d c534
  path: \\?\hid#vid_046d&pid_c534&mi_01&col05#7&1ebb799e&0&0004#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2901
  Interface:    1
  Usage (page): 0x2 (0xff00)
  Bus type: 1

Device Found
  type: 0488 121f
  path: \\?\hid#dell091a&col01#5&99b72d3&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: 9999
  Manufacturer: Microsoft
  Product:      HIDI2C Device
  Release:      40d
  Interface:    -1
  Usage (page): 0x2 (0x1)
  Bus type: 255

Device Found
  type: 8087 0a1e
  path: \\?\hid#intc816&col01#3&36a7043c&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number:
  Manufacturer:
  Product:
  Release:      200
  Interface:    -1
  Usage (page): 0xc (0x1)
  Bus type: 255

Device Found
  type: 044e 1212
  path: \\?\hid#vid_044e&pid_1212&col01&col02#7&290aacae&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}\kbd
  serial_number:
  Manufacturer:
  Product:
  Release:      0
  Interface:    -1
  Usage (page): 0x6 (0x1)
  Bus type: 255

Device Found
  type: 8087 0a1e
  path: \\?\hid#intc816&col02#3&36a7043c&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number:
  Manufacturer:
  Product:
  Release:      200
  Interface:    -1
  Usage (page): 0xd (0x1)
  Bus type: 255

Device Found
  type: 044e 1212
  path: \\?\hid#vid_044e&pid_1212&col01&col01#7&290aacae&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number:
  Manufacturer:
  Product:
  Release:      0
  Interface:    -1
  Usage (page): 0x2 (0x1)
  Bus type: 255

Device Found
  type: 0488 121f
  path: \\?\hid#dell091a&col02#5&99b72d3&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: 9999
  Manufacturer: Microsoft
  Product:      HIDI2C Device
  Release:      40d
  Interface:    -1
  Usage (page): 0x5 (0xd)
  Bus type: 255

Device Found
  type: 047f c056
  path: \\?\hid#vid_047f&pid_c056&mi_03&col01#f&39e6f119&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: D1CEC32927974D5F9BD6B2AEBF2EA8E3
  Manufacturer: Plantronics
  Product:      Plantronics Blackwire 3220 Series
  Release:      210
  Interface:    3
  Usage (page): 0x1 (0xc)
  Bus type: 1

Device Found
  type: 045e 0000
  path: \\?\hid#converteddevice&col02#5&379854aa&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number:
  Manufacturer:
  Product:
  Release:      0
  Interface:    -1
  Usage (page): 0x1 (0xc)
  Bus type: 255

Device Found
  type: 047f c056
  path: \\?\hid#vid_047f&pid_c056&mi_03&col02#f&39e6f119&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: D1CEC32927974D5F9BD6B2AEBF2EA8E3
  Manufacturer: Plantronics
  Product:      Plantronics Blackwire 3220 Series
  Release:      210
  Interface:    3
  Usage (page): 0x5 (0xb)
  Bus type: 1

Device Found
  type: 045e 0000
  path: \\?\hid#converteddevice&col03#5&379854aa&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number:
  Manufacturer:
  Product:
  Release:      0
  Interface:    -1
  Usage (page): 0x80 (0x1)
  Bus type: 255

Device Found
  type: 047f c056
  path: \\?\hid#vid_047f&pid_c056&mi_03&col03#f&39e6f119&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: D1CEC32927974D5F9BD6B2AEBF2EA8E3
  Manufacturer: Plantronics
  Product:      Plantronics Blackwire 3220 Series
  Release:      210
  Interface:    3
  Usage (page): 0x3 (0xffa0)
  Bus type: 1

Device Found
  type: 046d b010
  path: \\?\hid#{00001124-0000-1000-8000-00805f9b34fb}_vid&0002046d_pid&b010&col05#8&1cf1c1b9&2&0004#{4d1e55b2-f16f-11cf-88cb-001111000030}\kbd
  serial_number: 34885dab0c12
  Manufacturer: Logitech
  Product:      Logitech Bluetooth Wireless Mouse
  Release:      0
  Interface:    -1
  Usage (page): 0x6 (0x1)
  Bus type: 2

Device Found
  type: 0488 121f
  path: \\?\hid#dell091a&col03#5&99b72d3&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: 9999
  Manufacturer: Microsoft
  Product:      HIDI2C Device
  Release:      40d
  Interface:    -1
  Usage (page): 0x1 (0xff01)
  Bus type: 255

Device Found
  type: 0488 121f
  path: \\?\hid#dell091a&col04#5&99b72d3&0&0003#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: 9999
  Manufacturer: Microsoft
  Product:      HIDI2C Device
  Release:      40d
  Interface:    -1
  Usage (page): 0x1 (0xff02)
  Bus type: 255

Device Found
  type: 046d b010
  path: \\?\hid#{00001124-0000-1000-8000-00805f9b34fb}_vid&0002046d_pid&b010&col01#8&1cf1c1b9&2&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: 34885dab0c12
  Manufacturer: Logitech
  Product:      Logitech Bluetooth Wireless Mouse
  Release:      0
  Interface:    -1
  Usage (page): 0x2 (0x1)
  Bus type: 2

Device Found
  type: 046d c534
  path: \\?\hid#vid_046d&pid_c534&mi_00#7&51bc424&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}\kbd
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2901
  Interface:    0
  Usage (page): 0x6 (0x1)
  Bus type: 1

Device Found
  type: 046d b010
  path: \\?\hid#{00001124-0000-1000-8000-00805f9b34fb}_vid&0002046d_pid&b010&col02#8&1cf1c1b9&2&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: 34885dab0c12
  Manufacturer: Logitech
  Product:      Logitech Bluetooth Wireless Mouse
  Release:      0
  Interface:    -1
  Usage (page): 0x1 (0xc)
  Bus type: 2

Device Found
  type: 046d b010
  path: \\?\hid#{00001124-0000-1000-8000-00805f9b34fb}_vid&0002046d_pid&b010&col03#8&1cf1c1b9&2&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: 34885dab0c12
  Manufacturer: Logitech
  Product:      Logitech Bluetooth Wireless Mouse
  Release:      0
  Interface:    -1
  Usage (page): 0x1 (0xff00)
  Bus type: 2

Device Found
  type: 0488 121f
  path: \\?\hid#dell091a&col05#5&99b72d3&0&0004#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: 9999
  Manufacturer: Microsoft
  Product:      HIDI2C Device
  Release:      40d
  Interface:    -1
  Usage (page): 0xe (0xd)
  Bus type: 255

Device Found
  type: 046d b010
  path: \\?\hid#{00001124-0000-1000-8000-00805f9b34fb}_vid&0002046d_pid&b010&col04#8&1cf1c1b9&2&0003#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: 34885dab0c12
  Manufacturer: Logitech
  Product:      Logitech Bluetooth Wireless Mouse
  Release:      0
  Interface:    -1
  Usage (page): 0x2 (0xff00)
  Bus type: 2

Device Found
  type: 046d c534
  path: \\?\hid#vid_046d&pid_c534&mi_01&col01#7&1ebb799e&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2901
  Interface:    1
  Usage (page): 0x2 (0x1)
  Bus type: 1

Device Found
  type: 046d b010
  path: \\?\hid#{00001124-0000-1000-8000-00805f9b34fb}_vid&0002046d_pid&b010&col06#8&1cf1c1b9&2&0005#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: 34885dab0c12
  Manufacturer: Logitech
  Product:      Logitech Bluetooth Wireless Mouse
  Release:      0
  Interface:    -1
  Usage (page): 0x1 (0xc)
  Bus type: 2

Device Found
  type: 046d c534
  path: \\?\hid#vid_046d&pid_c534&mi_01&col02#7&1ebb799e&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2901
  Interface:    1
  Usage (page): 0x1 (0xc)
  Bus type: 1

Device Found
  type: 045e 0000
  path: \\?\hid#converteddevice&col01#5&379854aa&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}\kbd
  serial_number:
  Manufacturer:
  Product:
  Release:      0
  Interface:    -1
  Usage (page): 0x6 (0x1)
  Bus type: 255

unable to open device

@mcuee
Copy link
Member

mcuee commented Jul 24, 2021

@DJm00n The Microsoft I2C HID device has the following

DEVPKEY_Device_InstanceId: ACPI\DELL091A\4&27F2A591&0.

If I look at the Device Manager "Human Device Interface" entries, Device_InstanceId printed out is the same as what is listed as "Device Instance Path" in Device Manager.

The one you want to get here is "Compatible IDs" which has two values, "ACPI\PNP0C50" and "PNP0C50".

@mcuee
Copy link
Member

mcuee commented Jul 24, 2021

@DJm00n
From the link in your code,
https://docs.microsoft.com/en-us/windows-hardware/drivers/hid/plug-and-play-support-and-power-management

The ACPI 5.0 Specification includes support for HID Class Devices. the ACPI definitions for HID I²C are as follows.

Field Value ACPI object Format Comments
Compatible ID PNP0C50 _CID String in the format of ACPI0C50 or PNP0C50 CompatibleID

@mcuee
Copy link
Member

mcuee commented Jul 24, 2021

Same for SPI HID device.
https://docs.microsoft.com/en-us/windows-hardware/drivers/hid/plug-and-play-for-spi

The ACPI 5.0 Specification includes support for HID Class Devices. the ACPI definitions for HID SPI are as follows.

Field Value ACPI object Format Comments
Hardware ID Vendor Specific _HID String in the format of VVVVdddd (e.g. MSFT0011) VendorID + DeviceID
Compatible ID PNP0C51 _CID String in the format of ACPIxxxx or PNPxxxx CompatibleID

@mcuee
Copy link
Member

mcuee commented Jul 24, 2021

Compatible ID should work for your purpose, no matter it is USB, Bluetooth, I2C or SPI.
https://docs.microsoft.com/en-us/windows-hardware/drivers/install/compatible-ids

@mcuee
Copy link
Member

mcuee commented Jul 24, 2021

More info about HID Transport under Windows
https://docs.microsoft.com/en-us/windows-hardware/drivers/hid/hid-transports

@mcuee
Copy link
Member

mcuee commented Jul 24, 2021

Built-in device for my Dell Laptop (without any external USB/Bluetooth devices).

click to expand
C:\work\hid\hidapi_djm\windows\x64\Debug [ble_device_info ≡ +0 ~1 -0 !]> .\hidtest.exe
hidapi test/example tool. Compiled with hidapi version 0.11.0, runtime version 0.11.0.
Compile-time version matches runtime version of hidapi.

DEVPKEY_Device_InstanceId: ACPI\DELL091A\4&27F2A591&0
DEVPKEY_Device_InstanceId: ACPI\INT33D5\2&DABA3FF&0
DEVPKEY_Device_InstanceId: HID\VID_044E&PID_1212&COL01\6&298C10D6&0&0000
DEVPKEY_Device_InstanceId: ACPI\INT33D5\2&DABA3FF&0
DEVPKEY_Device_InstanceId: HID\VID_044E&PID_1212&COL01\6&298C10D6&0&0000
DEVPKEY_Device_InstanceId: ACPI\DELL091A\4&27F2A591&0
DEVPKEY_Device_InstanceId: BUTTONCONVERTER\CONVERTEDDEVICE\4&32F8A6A3&0&0
DEVPKEY_Device_InstanceId: BUTTONCONVERTER\CONVERTEDDEVICE\4&32F8A6A3&0&0
DEVPKEY_Device_InstanceId: ACPI\DELL091A\4&27F2A591&0
DEVPKEY_Device_InstanceId: ACPI\DELL091A\4&27F2A591&0
DEVPKEY_Device_InstanceId: ACPI\DELL091A\4&27F2A591&0
DEVPKEY_Device_InstanceId: BUTTONCONVERTER\CONVERTEDDEVICE\4&32F8A6A3&0&0
Device Found
  type: 0488 121f
  path: \\?\hid#dell091a&col01#5&99b72d3&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: 9999
  Manufacturer: Microsoft
  Product:      HIDI2C Device
  Release:      40d
  Interface:    -1
  Usage (page): 0x2 (0x1)
  Bus type: 255

Device Found
  type: 8087 0a1e
  path: \\?\hid#intc816&col01#3&36a7043c&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number:
  Manufacturer:
  Product:
  Release:      200
  Interface:    -1
  Usage (page): 0xc (0x1)
  Bus type: 255

Device Found
  type: 044e 1212
  path: \\?\hid#vid_044e&pid_1212&col01&col02#7&290aacae&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}\kbd
  serial_number:
  Manufacturer:
  Product:
  Release:      0
  Interface:    -1
  Usage (page): 0x6 (0x1)
  Bus type: 255

Device Found
  type: 8087 0a1e
  path: \\?\hid#intc816&col02#3&36a7043c&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number:
  Manufacturer:
  Product:
  Release:      200
  Interface:    -1
  Usage (page): 0xd (0x1)
  Bus type: 255

Device Found
  type: 044e 1212
  path: \\?\hid#vid_044e&pid_1212&col01&col01#7&290aacae&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number:
  Manufacturer:
  Product:
  Release:      0
  Interface:    -1
  Usage (page): 0x2 (0x1)
  Bus type: 255

Device Found
  type: 0488 121f
  path: \\?\hid#dell091a&col02#5&99b72d3&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: 9999
  Manufacturer: Microsoft
  Product:      HIDI2C Device
  Release:      40d
  Interface:    -1
  Usage (page): 0x5 (0xd)
  Bus type: 255

Device Found
  type: 045e 0000
  path: \\?\hid#converteddevice&col02#5&379854aa&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number:
  Manufacturer:
  Product:
  Release:      0
  Interface:    -1
  Usage (page): 0x1 (0xc)
  Bus type: 255

Device Found
  type: 045e 0000
  path: \\?\hid#converteddevice&col03#5&379854aa&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number:
  Manufacturer:
  Product:
  Release:      0
  Interface:    -1
  Usage (page): 0x80 (0x1)
  Bus type: 255

Device Found
  type: 0488 121f
  path: \\?\hid#dell091a&col03#5&99b72d3&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: 9999
  Manufacturer: Microsoft
  Product:      HIDI2C Device
  Release:      40d
  Interface:    -1
  Usage (page): 0x1 (0xff01)
  Bus type: 255

Device Found
  type: 0488 121f
  path: \\?\hid#dell091a&col04#5&99b72d3&0&0003#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: 9999
  Manufacturer: Microsoft
  Product:      HIDI2C Device
  Release:      40d
  Interface:    -1
  Usage (page): 0x1 (0xff02)
  Bus type: 255

Device Found
  type: 0488 121f
  path: \\?\hid#dell091a&col05#5&99b72d3&0&0004#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: 9999
  Manufacturer: Microsoft
  Product:      HIDI2C Device
  Release:      40d
  Interface:    -1
  Usage (page): 0xe (0xd)
  Bus type: 255

Device Found
  type: 045e 0000
  path: \\?\hid#converteddevice&col01#5&379854aa&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}\kbd
  serial_number:
  Manufacturer:
  Product:
  Release:      0
  Interface:    -1
  Usage (page): 0x6 (0x1)
  Bus type: 255

unable to open device

@mcuee
Copy link
Member

mcuee commented Jul 16, 2022

And it is also good for macOS.


mcuee@mcuees-Mac-mini hidapi_pr308 % ./build_darwin/hidtest/hidtest
hidapi test/example tool. Compiled with hidapi version 0.12.0, runtime version 0.12.0.
Compile-time version matches runtime version of hidapi.

Device Found
  type: 1915 1025
  path: DevSrvsID:4294969659
  serial_number: 
  Manufacturer: ZY.Ltd
  Product:      ZY Control Mic
  Release:      173
  Interface:    3
  Usage (page): 0x2 (0x1)
  Bus type: 1

Device Found
  type: 1915 1025
  path: DevSrvsID:4294969659
  serial_number: 
  Manufacturer: ZY.Ltd
  Product:      ZY Control Mic
  Release:      173
  Interface:    3
  Usage (page): 0x1 (0x1)
  Bus type: 1

Device Found
  type: 1915 1025
  path: DevSrvsID:4294969659
  serial_number: 
  Manufacturer: ZY.Ltd
  Product:      ZY Control Mic
  Release:      173
  Interface:    3
  Usage (page): 0x1 (0xc)
  Bus type: 1

Device Found
  type: 1915 1025
  path: DevSrvsID:4294969659
  serial_number: 
  Manufacturer: ZY.Ltd
  Product:      ZY Control Mic
  Release:      173
  Interface:    3
  Usage (page): 0x80 (0x1)
  Bus type: 1

Device Found
  type: 1915 1025
  path: DevSrvsID:4294969659
  serial_number: 
  Manufacturer: ZY.Ltd
  Product:      ZY Control Mic
  Release:      173
  Interface:    3
  Usage (page): 0x0 (0xff00)
  Bus type: 1

Device Found
  type: 1915 1025
  path: DevSrvsID:4294969661
  serial_number: 
  Manufacturer: ZY.Ltd
  Product:      ZY Control Mic
  Release:      173
  Interface:    2
  Usage (page): 0x6 (0x1)
  Bus type: 1

Device Found
  type: 045e 082f
  path: DevSrvsID:4294969867
  serial_number: 734762612322
  Manufacturer: Microsoft
  Product:      Microsoft Bluetooth Mouse
  Release:      212
  Interface:    -1
  Usage (page): 0x2 (0x1)
  Bus type: 0

Device Found
  type: 045e 082f
  path: DevSrvsID:4294969867
  serial_number: 734762612322
  Manufacturer: Microsoft
  Product:      Microsoft Bluetooth Mouse
  Release:      212
  Interface:    -1
  Usage (page): 0x1 (0x1)
  Bus type: 0

Device Found
  type: 045e 082f
  path: DevSrvsID:4294969867
  serial_number: 734762612322
  Manufacturer: Microsoft
  Product:      Microsoft Bluetooth Mouse
  Release:      212
  Interface:    -1
  Usage (page): 0x6 (0x1)
  Bus type: 0

Device Found
  type: 045e 082f
  path: DevSrvsID:4294969867
  serial_number: 734762612322
  Manufacturer: Microsoft
  Product:      Microsoft Bluetooth Mouse
  Release:      212
  Interface:    -1
  Usage (page): 0x212 (0xff07)
  Bus type: 0

Device Found
  type: 046d b33d
  path: DevSrvsID:4294969883
  serial_number: f4-73-35-4b-c5-aa
  Manufacturer: Unknown
  Product:      Keyboard K480
  Release:      2803
  Interface:    -1
  Usage (page): 0x6 (0x1)
  Bus type: 2

Device Found
  type: 046d b33d
  path: DevSrvsID:4294969883
  serial_number: f4-73-35-4b-c5-aa
  Manufacturer: Unknown
  Product:      Keyboard K480
  Release:      2803
  Interface:    -1
  Usage (page): 0x1 (0xc)
  Bus type: 2

Device Found
  type: 046d b33d
  path: DevSrvsID:4294969883
  serial_number: f4-73-35-4b-c5-aa
  Manufacturer: Unknown
  Product:      Keyboard K480
  Release:      2803
  Interface:    -1
  Usage (page): 0x80 (0x1)
  Bus type: 2

Device Found
  type: 046d b33d
  path: DevSrvsID:4294969883
  serial_number: f4-73-35-4b-c5-aa
  Manufacturer: Unknown
  Product:      Keyboard K480
  Release:      2803
  Interface:    -1
  Usage (page): 0x1 (0xff00)
  Bus type: 2

Device Found
  type: 046d b33d
  path: DevSrvsID:4294969883
  serial_number: f4-73-35-4b-c5-aa
  Manufacturer: Unknown
  Product:      Keyboard K480
  Release:      2803
  Interface:    -1
  Usage (page): 0x2 (0xff00)
  Bus type: 2

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

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

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

unable to open device

@DJm00n
Copy link
Contributor Author

DJm00n commented Jul 16, 2022

@mcuee thanks! “Microsoft Bluetooth Mouse” - what kind of mouse is that? Looks like bus type is not detected in this case? Does it use some kind of custom driver?

@mcuee
Copy link
Member

mcuee commented Jul 16, 2022

thanks! “Microsoft Bluetooth Mouse” - what kind of mouse is that? Looks like bus type is not detected in this case? Does it use some kind of custom driver?

I have the Logitech K480 bluetooth keyboard and Microsoft Bluetooth Mouse.

The MS Bluetooth Mouse seems to use Bluetooth Low Energy.
https://www.microsoft.com/en-sg/d/microsoft-bluetooth-mouse/8qbx2w3xsp2h?activetab=pivot:techspecstab
Connection interface: Bluetooth® Low Energy compatible 4.0/4.1/4.2/5.0

Not so sure if you need to deal with BLE specially.


mcuee@mcuees-Mac-mini ~ % system_profiler SPBluetoothDataType
Bluetooth:

      Bluetooth Controller:
          Address: 4C:20:B8:E1:4C:F8
          State: On
          Chipset: BCM_4378
          Discoverable: Off
          Firmware Version: 19.6.482.2793
          Product ID: 0x0001
          Supported services: 0x382039 < HFP AVRCP A2DP HID Braille AACP GATT Serial >
          Transport: PCIe
          Vendor ID: 0x004C (Apple)
      Connected:
          Keyboard K480:
              Address: F4:73:35:4B:C5:AA
              Vendor ID: 0x046D
              Product ID: 0xB33D
              Firmware Version: 40.0.3
              Minor Type: Keyboard
              Services: 0x800020 < HID ACL >
          Microsoft Bluetooth Mouse:
              Address: C8:3B:57:79:31:AA
              Vendor ID: 0x045E
              Product ID: 0x082F
              Battery Level: 100%
              Firmware Version: V2.12
              Minor Type: Mouse
              Services: 0x400000 < BLE >
      Not Connected:
          Bluetooth Mouse M557:
              Address: 34:88:5D:AB:0C:12
              Vendor ID: 0x046D
              Product ID: 0xB010
              Firmware Version: 0.0.0
              Minor Type: Mouse
          Xbox Wireless Controller:
              Address: 9C:AA:1B:1C:CA:E2
              Vendor ID: 0x045E
              Product ID: 0x02FD
              Firmware Version: 0.0.0
              Minor Type: Gamepad

@Youw
Copy link
Member

Youw commented Jul 16, 2022

@mcuee can you modify the code locally a bit, to print
CFStringGetCStringPtr((CFStringRef)transport_prop, kCFStringEncodingMacRoman) ?
So we could check what is the Transport as detected by IOHIDManager

@mcuee
Copy link
Member

mcuee commented Jul 16, 2022

Test results under Linux Ubuntu 20.04 (dual boot with the above Windows 11 machine) and it seems to be fine.

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

Device Found
  type: 046d 400a
  path: /dev/hidraw2
  serial_number: 400a-49-13-e7-23
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    2
  Usage (page): 0x2 (0x1)
  Bus type: 1

Device Found
  type: 046d 400a
  path: /dev/hidraw2
  serial_number: 400a-49-13-e7-23
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    2
  Usage (page): 0x1 (0x1)
  Bus type: 1

Device Found
  type: 046d 400a
  path: /dev/hidraw2
  serial_number: 400a-49-13-e7-23
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    2
  Usage (page): 0x1 (0xff00)
  Bus type: 1

Device Found
  type: 046d 400a
  path: /dev/hidraw2
  serial_number: 400a-49-13-e7-23
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    2
  Usage (page): 0x2 (0xff00)
  Bus type: 1

Device Found
  type: 046d 400a
  path: /dev/hidraw2
  serial_number: 400a-49-13-e7-23
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    2
  Usage (page): 0x4 (0xff00)
  Bus type: 1

Device Found
  type: 046d c52b
  path: /dev/hidraw1
  serial_number: 
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    2
  Usage (page): 0x1 (0xff00)
  Bus type: 1

Device Found
  type: 046d c52b
  path: /dev/hidraw1
  serial_number: 
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    2
  Usage (page): 0x2 (0xff00)
  Bus type: 1

Device Found
  type: 046d c52b
  path: /dev/hidraw1
  serial_number: 
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    2
  Usage (page): 0x4 (0xff00)
  Bus type: 1

Device Found
  type: 06cb cd40
  path: /dev/hidraw0
  serial_number: 
  Manufacturer: 
  Product:      SYNA7DAB:01 06CB:CD40
  Release:      0
  Interface:    -1
  Usage (page): 0x2 (0x1)
  Bus type: 3

Device Found
  type: 06cb cd40
  path: /dev/hidraw0
  serial_number: 
  Manufacturer: 
  Product:      SYNA7DAB:01 06CB:CD40
  Release:      0
  Interface:    -1
  Usage (page): 0x1 (0x1)
  Bus type: 3

Device Found
  type: 06cb cd40
  path: /dev/hidraw0
  serial_number: 
  Manufacturer: 
  Product:      SYNA7DAB:01 06CB:CD40
  Release:      0
  Interface:    -1
  Usage (page): 0x5 (0xd)
  Bus type: 3

Device Found
  type: 06cb cd40
  path: /dev/hidraw0
  serial_number: 
  Manufacturer: 
  Product:      SYNA7DAB:01 06CB:CD40
  Release:      0
  Interface:    -1
  Usage (page): 0x22 (0xd)
  Bus type: 3

Device Found
  type: 06cb cd40
  path: /dev/hidraw0
  serial_number: 
  Manufacturer: 
  Product:      SYNA7DAB:01 06CB:CD40
  Release:      0
  Interface:    -1
  Usage (page): 0x22 (0xd)
  Bus type: 3

Device Found
  type: 06cb cd40
  path: /dev/hidraw0
  serial_number: 
  Manufacturer: 
  Product:      SYNA7DAB:01 06CB:CD40
  Release:      0
  Interface:    -1
  Usage (page): 0x22 (0xd)
  Bus type: 3

Device Found
  type: 06cb cd40
  path: /dev/hidraw0
  serial_number: 
  Manufacturer: 
  Product:      SYNA7DAB:01 06CB:CD40
  Release:      0
  Interface:    -1
  Usage (page): 0x22 (0xd)
  Bus type: 3

Device Found
  type: 06cb cd40
  path: /dev/hidraw0
  serial_number: 
  Manufacturer: 
  Product:      SYNA7DAB:01 06CB:CD40
  Release:      0
  Interface:    -1
  Usage (page): 0x22 (0xd)
  Bus type: 3

Device Found
  type: 06cb cd40
  path: /dev/hidraw0
  serial_number: 
  Manufacturer: 
  Product:      SYNA7DAB:01 06CB:CD40
  Release:      0
  Interface:    -1
  Usage (page): 0xe (0xd)
  Bus type: 3

Device Found
  type: 06cb cd40
  path: /dev/hidraw0
  serial_number: 
  Manufacturer: 
  Product:      SYNA7DAB:01 06CB:CD40
  Release:      0
  Interface:    -1
  Usage (page): 0x22 (0xd)
  Bus type: 3

Device Found
  type: 06cb cd40
  path: /dev/hidraw0
  serial_number: 
  Manufacturer: 
  Product:      SYNA7DAB:01 06CB:CD40
  Release:      0
  Interface:    -1
  Usage (page): 0x22 (0xd)
  Bus type: 3

Device Found
  type: 06cb cd40
  path: /dev/hidraw0
  serial_number: 
  Manufacturer: 
  Product:      SYNA7DAB:01 06CB:CD40
  Release:      0
  Interface:    -1
  Usage (page): 0x1 (0xff00)
  Bus type: 3

unable to open device

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

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

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

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

unable to open device


@DJm00n
Copy link
Contributor Author

DJm00n commented Jul 16, 2022

Oh.
image
But kIOHIDTransportBluetoothLowEnergyValue is BluetoothLowEnergy. That's...unexpected.
Update: MacOS 12.2.1.

@mcuee
Copy link
Member

mcuee commented Jul 16, 2022

Oh. image But kIOHIDTransportBluetoothLowEnergyValue is BluetoothLowEnergy. That's...unexpected.

That is exactly the reason.

@mcuee
Copy link
Member

mcuee commented Jul 16, 2022

@mcuee can you modify the code locally a bit, to print CFStringGetCStringPtr((CFStringRef)transport_prop, kCFStringEncodingMacRoman) ? So we could check what is the Transport as detected by IOHIDManager

As mentioned by @DJm00n, somehow macOS 12.4 comes out with Bluetooth Low Energy. However, kIOHIDTransportBluetoothLowEnergyValue is BluetoothLowEnergy

mcuee@mcuees-Mac-mini hidapi_pr308 % git diff
diff --git a/mac/hid.c b/mac/hid.c
index 25b912f..0f0b68e 100644
--- a/mac/hid.c
+++ b/mac/hid.c
@@ -456,7 +456,7 @@ static struct hid_device_info *create_device_info_with_usage(IOHIDDeviceRef dev,
 
        /* Bus Type */
        transport_prop = IOHIDDeviceGetProperty(dev, CFSTR(kIOHIDTransportKey));
-
+       printf("%s\n", CFStringGetCStringPtr((CFStringRef)transport_prop, kCFStringEncodingMacRoman));
        if (transport_prop != NULL && CFGetTypeID(transport_prop) == CFStringGetTypeID()) {
                if (CFStringCompare((CFStringRef)transport_prop, CFSTR(kIOHIDTransportUSBValue), 0) == kCFCompareEqualTo) {
                        cur_dev->bus_type = HID_API_BUS_USB;
mcuee@mcuees-Mac-mini hidapi_pr308 % ./build_darwin_print/hidtest/hidtest
hidapi test/example tool. Compiled with hidapi version 0.12.0, runtime version 0.12.0.
Compile-time version matches runtime version of hidapi.

(null)
(null)
(null)
(null)
(null)
(null)
(null)
(null)
(null)
(null)
(null)
Bluetooth Low Energy
Bluetooth Low Energy
Bluetooth Low Energy
Bluetooth Low Energy
(null)
(null)
(null)
Device Found
  type: 1915 1025
  path: DevSrvsID:4294969646
  serial_number: 
  Manufacturer: ZY.Ltd
  Product:      ZY Control Mic
  Release:      173
  Interface:    3
  Usage (page): 0x2 (0x1)
  Bus type: 1

Device Found
  type: 1915 1025
  path: DevSrvsID:4294969646
  serial_number: 
  Manufacturer: ZY.Ltd
  Product:      ZY Control Mic
  Release:      173
  Interface:    3
  Usage (page): 0x1 (0x1)
  Bus type: 1

Device Found
  type: 1915 1025
  path: DevSrvsID:4294969646
  serial_number: 
  Manufacturer: ZY.Ltd
  Product:      ZY Control Mic
  Release:      173
  Interface:    3
  Usage (page): 0x1 (0xc)
  Bus type: 1

Device Found
  type: 1915 1025
  path: DevSrvsID:4294969646
  serial_number: 
  Manufacturer: ZY.Ltd
  Product:      ZY Control Mic
  Release:      173
  Interface:    3
  Usage (page): 0x80 (0x1)
  Bus type: 1

Device Found
  type: 1915 1025
  path: DevSrvsID:4294969646
  serial_number: 
  Manufacturer: ZY.Ltd
  Product:      ZY Control Mic
  Release:      173
  Interface:    3
  Usage (page): 0x0 (0xff00)
  Bus type: 1

Device Found
  type: 046d b33d
  path: DevSrvsID:4294969894
  serial_number: f4-73-35-4b-c5-aa
  Manufacturer: Unknown
  Product:      Keyboard K480
  Release:      2803
  Interface:    -1
  Usage (page): 0x6 (0x1)
  Bus type: 2

Device Found
  type: 046d b33d
  path: DevSrvsID:4294969894
  serial_number: f4-73-35-4b-c5-aa
  Manufacturer: Unknown
  Product:      Keyboard K480
  Release:      2803
  Interface:    -1
  Usage (page): 0x1 (0xc)
  Bus type: 2

Device Found
  type: 046d b33d
  path: DevSrvsID:4294969894
  serial_number: f4-73-35-4b-c5-aa
  Manufacturer: Unknown
  Product:      Keyboard K480
  Release:      2803
  Interface:    -1
  Usage (page): 0x80 (0x1)
  Bus type: 2

Device Found
  type: 046d b33d
  path: DevSrvsID:4294969894
  serial_number: f4-73-35-4b-c5-aa
  Manufacturer: Unknown
  Product:      Keyboard K480
  Release:      2803
  Interface:    -1
  Usage (page): 0x1 (0xff00)
  Bus type: 2

Device Found
  type: 046d b33d
  path: DevSrvsID:4294969894
  serial_number: f4-73-35-4b-c5-aa
  Manufacturer: Unknown
  Product:      Keyboard K480
  Release:      2803
  Interface:    -1
  Usage (page): 0x2 (0xff00)
  Bus type: 2

Device Found
  type: 1915 1025
  path: DevSrvsID:4294969642
  serial_number: 
  Manufacturer: ZY.Ltd
  Product:      ZY Control Mic
  Release:      173
  Interface:    2
  Usage (page): 0x6 (0x1)
  Bus type: 1

Device Found
  type: 045e 082f
  path: DevSrvsID:4294969798
  serial_number: 734762612322
  Manufacturer: Microsoft
  Product:      Microsoft Bluetooth Mouse
  Release:      212
  Interface:    -1
  Usage (page): 0x2 (0x1)
  Bus type: 0

Device Found
  type: 045e 082f
  path: DevSrvsID:4294969798
  serial_number: 734762612322
  Manufacturer: Microsoft
  Product:      Microsoft Bluetooth Mouse
  Release:      212
  Interface:    -1
  Usage (page): 0x1 (0x1)
  Bus type: 0

Device Found
  type: 045e 082f
  path: DevSrvsID:4294969798
  serial_number: 734762612322
  Manufacturer: Microsoft
  Product:      Microsoft Bluetooth Mouse
  Release:      212
  Interface:    -1
  Usage (page): 0x6 (0x1)
  Bus type: 0

Device Found
  type: 045e 082f
  path: DevSrvsID:4294969798
  serial_number: 734762612322
  Manufacturer: Microsoft
  Product:      Microsoft Bluetooth Mouse
  Release:      212
  Interface:    -1
  Usage (page): 0x212 (0xff07)
  Bus type: 0

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

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

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

unable to open device

@DJm00n
Copy link
Contributor Author

DJm00n commented Jul 16, 2022

I have pushed a fix. Just checking for "Bluetooth" prefix now.

@mcuee
Copy link
Member

mcuee commented Jul 16, 2022

I have pushed a fix. Just checking for "Bluetooth" prefix now.

Why not match both Bluetooth Low Energy and kIOHIDTransportBluetoothLowEnergyValue (=BluetoothLowEnergy) for BLE device under macOS?

@DJm00n
Copy link
Contributor Author

DJm00n commented Jul 16, 2022

@mcuee CurrentCFStringHasPrefix((CFStringRef)transport_prop, CFSTR(kIOHIDTransportBluetoothValue)) check will match for "Bluetooth", "BluetoothLowEnergy" and "Bluetooth Low Energy" strings.

@Youw
Copy link
Member

Youw commented Jul 16, 2022

It would make 3 matches, which will break, once Apple deside to invent somethink like Bluetooth_Low_Energy

@DJm00n
Copy link
Contributor Author

DJm00n commented Jul 16, 2022

@Youw or "Bluetooth LE" or "Bluetooth Smart" like it was named before :)

@mcuee
Copy link
Member

mcuee commented Jul 16, 2022

@Youw and @DJm00n
Ok, I understand.

Now it is fine under macOS.

mcuee@mcuees-Mac-mini hidapi_pr308 % cd hidapi_pr308
mcuee@mcuees-Mac-mini hidapi_pr308 % git checkout hid_bus_type
mcuee@mcuees-Mac-mini hidapi_pr308 % cmake -D CMAKE_BUILD_TYPE=RelWithDebInfo -D HIDAPI_BUILD_HIDTEST=ON -B build_darwin
mcuee@mcuees-Mac-mini hidapi_pr308 % cmake --build build_darwin

mcuee@mcuees-Mac-mini hidapi_pr308 % ./build_darwin/hidtest/hidtest 
hidapi test/example tool. Compiled with hidapi version 0.12.0, runtime version 0.12.0.
Compile-time version matches runtime version of hidapi.

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

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

Device Found
  type: 1915 1025
  path: DevSrvsID:4294969646
  serial_number: 
  Manufacturer: ZY.Ltd
  Product:      ZY Control Mic
  Release:      173
  Interface:    3
  Usage (page): 0x2 (0x1)
  Bus type: 1

Device Found
  type: 1915 1025
  path: DevSrvsID:4294969646
  serial_number: 
  Manufacturer: ZY.Ltd
  Product:      ZY Control Mic
  Release:      173
  Interface:    3
  Usage (page): 0x1 (0x1)
  Bus type: 1

Device Found
  type: 1915 1025
  path: DevSrvsID:4294969646
  serial_number: 
  Manufacturer: ZY.Ltd
  Product:      ZY Control Mic
  Release:      173
  Interface:    3
  Usage (page): 0x1 (0xc)
  Bus type: 1

Device Found
  type: 1915 1025
  path: DevSrvsID:4294969646
  serial_number: 
  Manufacturer: ZY.Ltd
  Product:      ZY Control Mic
  Release:      173
  Interface:    3
  Usage (page): 0x80 (0x1)
  Bus type: 1

Device Found
  type: 1915 1025
  path: DevSrvsID:4294969646
  serial_number: 
  Manufacturer: ZY.Ltd
  Product:      ZY Control Mic
  Release:      173
  Interface:    3
  Usage (page): 0x0 (0xff00)
  Bus type: 1

Device Found
  type: 1915 1025
  path: DevSrvsID:4294969642
  serial_number: 
  Manufacturer: ZY.Ltd
  Product:      ZY Control Mic
  Release:      173
  Interface:    2
  Usage (page): 0x6 (0x1)
  Bus type: 1

Device Found
  type: 045e 082f
  path: DevSrvsID:4294969798
  serial_number: 734762612322
  Manufacturer: Microsoft
  Product:      Microsoft Bluetooth Mouse
  Release:      212
  Interface:    -1
  Usage (page): 0x2 (0x1)
  Bus type: 2

Device Found
  type: 045e 082f
  path: DevSrvsID:4294969798
  serial_number: 734762612322
  Manufacturer: Microsoft
  Product:      Microsoft Bluetooth Mouse
  Release:      212
  Interface:    -1
  Usage (page): 0x1 (0x1)
  Bus type: 2

Device Found
  type: 045e 082f
  path: DevSrvsID:4294969798
  serial_number: 734762612322
  Manufacturer: Microsoft
  Product:      Microsoft Bluetooth Mouse
  Release:      212
  Interface:    -1
  Usage (page): 0x6 (0x1)
  Bus type: 2

Device Found
  type: 045e 082f
  path: DevSrvsID:4294969798
  serial_number: 734762612322
  Manufacturer: Microsoft
  Product:      Microsoft Bluetooth Mouse
  Release:      212
  Interface:    -1
  Usage (page): 0x212 (0xff07)
  Bus type: 2

Device Found
  type: 046d b33d
  path: DevSrvsID:4294969894
  serial_number: f4-73-35-4b-c5-aa
  Manufacturer: Unknown
  Product:      Keyboard K480
  Release:      2803
  Interface:    -1
  Usage (page): 0x6 (0x1)
  Bus type: 2

Device Found
  type: 046d b33d
  path: DevSrvsID:4294969894
  serial_number: f4-73-35-4b-c5-aa
  Manufacturer: Unknown
  Product:      Keyboard K480
  Release:      2803
  Interface:    -1
  Usage (page): 0x1 (0xc)
  Bus type: 2

Device Found
  type: 046d b33d
  path: DevSrvsID:4294969894
  serial_number: f4-73-35-4b-c5-aa
  Manufacturer: Unknown
  Product:      Keyboard K480
  Release:      2803
  Interface:    -1
  Usage (page): 0x80 (0x1)
  Bus type: 2

Device Found
  type: 046d b33d
  path: DevSrvsID:4294969894
  serial_number: f4-73-35-4b-c5-aa
  Manufacturer: Unknown
  Product:      Keyboard K480
  Release:      2803
  Interface:    -1
  Usage (page): 0x1 (0xff00)
  Bus type: 2

Device Found
  type: 046d b33d
  path: DevSrvsID:4294969894
  serial_number: f4-73-35-4b-c5-aa
  Manufacturer: Unknown
  Product:      Keyboard K480
  Release:      2803
  Interface:    -1
  Usage (page): 0x2 (0xff00)
  Bus type: 2

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

unable to open device

@mcuee
Copy link
Member

mcuee commented Jul 18, 2022

One last test result under Windows 10 and it seems to be okay as well.

C:\work\hid\hidapi_pr308\windows\x64\Release [hid_bus_type ≡]> .\hidtest.exe
hidapi test/example tool. Compiled with hidapi version 0.12.0, runtime version 0.12.0.
Compile-time version matches runtime version of hidapi.

Device Found
  type: 046d b010
  path: \\?\HID#{00001124-0000-1000-8000-00805f9b34fb}_VID&0002046d_PID&b010&Col03#8&1cf1c1b9&5&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: 34885dab0c12
  Manufacturer: Logitech
  Product:      Logitech Bluetooth Wireless Mouse
  Release:      0
  Interface:    -1
  Usage (page): 0x1 (0xff00)
  Bus type: 2

Device Found
  type: 046d b010
  path: \\?\HID#{00001124-0000-1000-8000-00805f9b34fb}_VID&0002046d_PID&b010&Col04#8&1cf1c1b9&5&0003#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: 34885dab0c12
  Manufacturer: Logitech
  Product:      Logitech Bluetooth Wireless Mouse
  Release:      0
  Interface:    -1
  Usage (page): 0x2 (0xff00)
  Bus type: 2

Device Found
  type: 046d c534
  path: \\?\HID#VID_046D&PID_C534&MI_01&Col03#7&7e9f97e&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2901
  Interface:    1
  Usage (page): 0x80 (0x1)
  Bus type: 1

Device Found
  type: 0488 121f
  path: \\?\HID#DELL091A&Col01#5&99b72d3&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: 9999
  Manufacturer: Microsoft
  Product:      HIDI2C Device
  Release:      40d
  Interface:    -1
  Usage (page): 0x2 (0x1)
  Bus type: 3

Device Found
  type: 046d b010
  path: \\?\HID#{00001124-0000-1000-8000-00805f9b34fb}_VID&0002046d_PID&b010&Col05#8&1cf1c1b9&5&0004#{4d1e55b2-f16f-11cf-88cb-001111000030}\KBD
  serial_number: 34885dab0c12
  Manufacturer: Logitech
  Product:      Logitech Bluetooth Wireless Mouse
  Release:      0
  Interface:    -1
  Usage (page): 0x6 (0x1)
  Bus type: 2

Device Found
  type: 046d b010
  path: \\?\HID#{00001124-0000-1000-8000-00805f9b34fb}_VID&0002046d_PID&b010&Col06#8&1cf1c1b9&5&0005#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: 34885dab0c12
  Manufacturer: Logitech
  Product:      Logitech Bluetooth Wireless Mouse
  Release:      0
  Interface:    -1
  Usage (page): 0x1 (0xc)
  Bus type: 2

Device Found
  type: 8087 0a1e
  path: \\?\HID#INTC816&Col01#3&36a7043c&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number:
  Manufacturer:
  Product:
  Release:      200
  Interface:    -1
  Usage (page): 0xc (0x1)
  Bus type: 0

Device Found
  type: 044e 1212
  path: \\?\HID#Vid_044E&Pid_1212&Col01&Col02#7&290aacae&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}\KBD
  serial_number:
  Manufacturer:
  Product:
  Release:      0
  Interface:    -1
  Usage (page): 0x6 (0x1)
  Bus type: 0

Device Found
  type: 8087 0a1e
  path: \\?\HID#INTC816&Col02#3&36a7043c&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number:
  Manufacturer:
  Product:
  Release:      200
  Interface:    -1
  Usage (page): 0xd (0x1)
  Bus type: 0

Device Found
  type: 044e 1212
  path: \\?\HID#Vid_044E&Pid_1212&Col01&Col01#7&290aacae&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number:
  Manufacturer:
  Product:
  Release:      0
  Interface:    -1
  Usage (page): 0x2 (0x1)
  Bus type: 0

Device Found
  type: 046d c534
  path: \\?\HID#VID_046D&PID_C534&MI_01&Col04#7&7e9f97e&0&0003#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2901
  Interface:    1
  Usage (page): 0x1 (0xff00)
  Bus type: 1

Device Found
  type: 0488 121f
  path: \\?\HID#DELL091A&Col02#5&99b72d3&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: 9999
  Manufacturer: Microsoft
  Product:      HIDI2C Device
  Release:      40d
  Interface:    -1
  Usage (page): 0x5 (0xd)
  Bus type: 3

Device Found
  type: 413c b06e
  path: \\?\HID#VID_413C&PID_B06E#c&37ff1248&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number:
  Manufacturer:
  Product:
  Release:      101
  Interface:    -1
  Usage (page): 0xda (0xffda)
  Bus type: 1

Device Found
  type: 047f c056
  path: \\?\HID#VID_047F&PID_C056&MI_03&Col01#f&39e6f119&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: D1CEC32927974D5F9BD6B2AEBF2EA8E3
  Manufacturer: Plantronics
  Product:      Plantronics Blackwire 3220 Series
  Release:      210
  Interface:    3
  Usage (page): 0x1 (0xc)
  Bus type: 1

Device Found
  type: 045e 0000
  path: \\?\HID#ConvertedDevice&Col02#5&379854aa&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number:
  Manufacturer:
  Product:
  Release:      0
  Interface:    -1
  Usage (page): 0x1 (0xc)
  Bus type: 0

Device Found
  type: 047f c056
  path: \\?\HID#VID_047F&PID_C056&MI_03&Col02#f&39e6f119&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: D1CEC32927974D5F9BD6B2AEBF2EA8E3
  Manufacturer: Plantronics
  Product:      Plantronics Blackwire 3220 Series
  Release:      210
  Interface:    3
  Usage (page): 0x5 (0xb)
  Bus type: 1

Device Found
  type: 045e 0000
  path: \\?\HID#ConvertedDevice&Col03#5&379854aa&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number:
  Manufacturer:
  Product:
  Release:      0
  Interface:    -1
  Usage (page): 0x80 (0x1)
  Bus type: 0

Device Found
  type: 047f c056
  path: \\?\HID#VID_047F&PID_C056&MI_03&Col03#f&39e6f119&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: D1CEC32927974D5F9BD6B2AEBF2EA8E3
  Manufacturer: Plantronics
  Product:      Plantronics Blackwire 3220 Series
  Release:      210
  Interface:    3
  Usage (page): 0x3 (0xffa0)
  Bus type: 1

Device Found
  type: 046d c534
  path: \\?\HID#VID_046D&PID_C534&MI_01&Col05#7&7e9f97e&0&0004#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2901
  Interface:    1
  Usage (page): 0x2 (0xff00)
  Bus type: 1

Device Found
  type: 0488 121f
  path: \\?\HID#DELL091A&Col03#5&99b72d3&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: 9999
  Manufacturer: Microsoft
  Product:      HIDI2C Device
  Release:      40d
  Interface:    -1
  Usage (page): 0x1 (0xff01)
  Bus type: 3

Device Found
  type: 046d c534
  path: \\?\HID#VID_046D&PID_C534&MI_00#7&32158c2f&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}\KBD
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2901
  Interface:    0
  Usage (page): 0x6 (0x1)
  Bus type: 1

Device Found
  type: 413c 2107
  path: \\?\HID#VID_413C&PID_2107#e&1de7f0c0&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}\KBD
  serial_number:
  Manufacturer: DELL
  Product:      Dell USB Entry Keyboard
  Release:      178
  Interface:    -1
  Usage (page): 0x6 (0x1)
  Bus type: 1

Device Found
  type: 0488 121f
  path: \\?\HID#DELL091A&Col04#5&99b72d3&0&0003#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: 9999
  Manufacturer: Microsoft
  Product:      HIDI2C Device
  Release:      40d
  Interface:    -1
  Usage (page): 0x1 (0xff02)
  Bus type: 3

Device Found
  type: 046d c534
  path: \\?\HID#VID_046D&PID_C534&MI_01&Col01#7&7e9f97e&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2901
  Interface:    1
  Usage (page): 0x2 (0x1)
  Bus type: 1

Device Found
  type: 046d c077
  path: \\?\HID#VID_046D&PID_C077#e&fde55df&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number:
  Manufacturer: Logitech
  Product:      USB Optical Mouse
  Release:      7200
  Interface:    -1
  Usage (page): 0x2 (0x1)
  Bus type: 1

Device Found
  type: 0488 121f
  path: \\?\HID#DELL091A&Col05#5&99b72d3&0&0004#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: 9999
  Manufacturer: Microsoft
  Product:      HIDI2C Device
  Release:      40d
  Interface:    -1
  Usage (page): 0xe (0xd)
  Bus type: 3

Device Found
  type: 046d b010
  path: \\?\HID#{00001124-0000-1000-8000-00805f9b34fb}_VID&0002046d_PID&b010&Col01#8&1cf1c1b9&5&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: 34885dab0c12
  Manufacturer: Logitech
  Product:      Logitech Bluetooth Wireless Mouse
  Release:      0
  Interface:    -1
  Usage (page): 0x2 (0x1)
  Bus type: 2

Device Found
  type: 413c b06f
  path: \\?\HID#VID_413C&PID_B06F#d&3624b04c&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number:
  Manufacturer:
  Product:
  Release:      101
  Interface:    -1
  Usage (page): 0xda (0xffda)
  Bus type: 1

Device Found
  type: 046d c534
  path: \\?\HID#VID_046D&PID_C534&MI_01&Col02#7&7e9f97e&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2901
  Interface:    1
  Usage (page): 0x1 (0xc)
  Bus type: 1

Device Found
  type: 045e 0000
  path: \\?\HID#ConvertedDevice&Col01#5&379854aa&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}\KBD
  serial_number:
  Manufacturer:
  Product:
  Release:      0
  Interface:    -1
  Usage (page): 0x6 (0x1)
  Bus type: 0

Device Found
  type: 046d b010
  path: \\?\HID#{00001124-0000-1000-8000-00805f9b34fb}_VID&0002046d_PID&b010&Col02#8&1cf1c1b9&5&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: 34885dab0c12
  Manufacturer: Logitech
  Product:      Logitech Bluetooth Wireless Mouse
  Release:      0
  Interface:    -1
  Usage (page): 0x1 (0xc)
  Bus type: 2

unable to open device

@mcuee
Copy link
Member

mcuee commented Aug 16, 2022

@Youw

Just wondering if this can be merged for 0.13 release. Thanks.

@Youw
Copy link
Member

Youw commented Aug 16, 2022

Yes, probably. Just need to resolve the conflicts.

@mcuee
Copy link
Member

mcuee commented Aug 16, 2022

@DJm00n
Please help to resolve the mergeing conflicts. Thanks.

hidapi/hidapi.h Outdated Show resolved Hide resolved
Copy link
Member

@Youw Youw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed merge conflict and applied review comments.

@Youw Youw merged commit 0f2cf88 into libusb:master Sep 10, 2022
@DJm00n DJm00n deleted the hid_bus_type branch October 13, 2022 09:38
@jonasmalacofilho
Copy link
Contributor

If I'm not mistaken, this breaks the ABI. I'm in no position to argue whether that's fine or not here, but given #292 (comment),

Practically speaking, each new HIDAPI release always been API/ABI backward compatible with previouse releases.

it might be worth adding a note about this in the 0.13.0 release notes.

@Youw
Copy link
Member

Youw commented Jan 6, 2023

I haven't performed any specific tests, but it shouldn't break the ABI, since we added the new field at the end of the struct.
And all of the handling (allocation/deallocation) is done with the API functions.

@jonasmalacofilho
Copy link
Contributor

@Youw,

You're right.

I wasn't completely sure that the new field being added at the end of the struct was sufficient, and had also hit (but not yet looked into) an invalid read with valgrind when running an executable built against 0.12.0 with 0.13.0.

But it turned out that the valgrind error was unrelated to this (see #497). And since we only manipulate hid_device_info through pointers, I agree that it's size doesn't matter.

Sorry for the noise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Core Related to common codes like hidapi.h enhancement New feature or request hidraw Related to Linux/hidraw backend libusb Related to libusb backend macOS Related to macOS backend Windows Related to Windows backend
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants