pok3rtool icon indicating copy to clipboard operation
pok3rtool copied to clipboard

Use LibUSB-1.0 RawHID backend for Windows/macOS/Linux

Open hansemro opened this issue 3 years ago • 5 comments

In preparation for ISP protocol support for all platforms, this PR replaces platform-specific rawhid backends with a common LibUSB-1.0 backend. With only one backend to maintain, it becomes easier to add control transfer functionality to RawHID and HIDDevice which is required by #13 for working flash programming (see #12 for more information).

Tasks:

  • [x] Implement base rawhid functions using LibUSB-1.0 backend
  • ~Add control transfer function to RawHID and HIDDevice~ (support will be added with ISP protocol support)
    • Tested prototype:
      • https://github.com/hansemro/pok3rtool/blob/182e5cee8bf0d04dd6d8db5920214e1e5146bf0a/rawhid/hiddevice.cpp#L105-L121
      • https://github.com/hansemro/pok3rtool/blob/182e5cee8bf0d04dd6d8db5920214e1e5146bf0a/rawhid/hid_libusb.c#L124-L145
  • [x] Support Linux
    • [x] Replace hid_LINUX.c
  • [x] Support macOS
    • [x] Replace hid_MACOSX.c
  • [x] Support Windows (with MSYS2/MinGW build environment)
    • [x] Replace hid_WINDOWS.c

hansemro avatar Nov 19 '22 15:11 hansemro

I am going to drop/revert control transfer support in this PR so that it can be included alongside ISP protocol support.

hansemro avatar Nov 27 '22 17:11 hansemro

@ChaoticEnigma This is ready for review.

hansemro avatar Nov 27 '22 18:11 hansemro

Having issues with Windows again. It works for detecting ISP but not keyboards. The error is related to matching Usage and Usage Page in the HID Report descriptor.

hansemro avatar Nov 28 '22 05:11 hansemro

I might be able to workaround this by using libusb/hidapi

hansemro avatar Nov 28 '22 05:11 hansemro

hidapi works much better than the current implementation.

hansemro avatar Nov 28 '22 06:11 hansemro

Reverting libhidapi changes due to odd behavior in macOS that prevents the usb device from being detected on subsequent access attempts.

Related: https://github.com/libusb/hidapi/issues/385

hansemro avatar Dec 09 '22 09:12 hansemro

Workaround for Windows:

  • (Option 1) Temporarily install WinUSB (or libusb-win32) driver for the interface we are interested in using Zadig (https://zadig.akeo.ie/)
    • On Windows 10, HidUsb driver fails to access some HID Report descriptors for devices with multiple interfaces.
    • Example: Cooler Master Pro S RGB (bootloader) detection can be fixed by installing WinUSB driver on interface 1.
  • (Option 2) Keep rawhid_WINDOWS.c (and implement control transfer at a later point)

hansemro avatar Dec 09 '22 21:12 hansemro