Skip to content

USB: HID Report Descriptor

hasu@tmk edited this page Jun 23, 2021 · 40 revisions

On Windows and MacOS

See this page.

https://github.com/tmk/tmk_keyboard/wiki/USB:-Descriptor

On Linux

lsusb on Linux

http://www.slashdev.ca/2010/05/08/get-usb-report-descriptor-with-linux/

Find vendor id of device interested(046d)

$ lsusb
...
Bus 002 Device 007: ID 046d:c01d Logitech, Inc. MX510 Optical Mouse
...

Find device path from dmesg output(2-2.4:1.0)

$ dmesg | grep -i 046d | grep devices | tail -5
Aug 12 09:15:55 desk kernel: [166377.779960] input: Logitech USB-PS/2 Optical Mouse as /devices/pci0000:00/0000:00:04.1/usb2/2-2/2-2.4/2-2.4:1.0/0003:046D:C01D.0067/input/input106

Unbind the device and it stops working

$ echo -n 2-2.4:1.0 | sudo tee /sys/bus/usb/drivers/usbhid/unbind

Dump report descriptor with lsusb

$ sudo lsusb -d046d: -v
...
  iInterface              0
    HID Device Descriptor:
      bLength                 9
      bDescriptorType        33
      bcdHID               1.10
      bCountryCode            0 Not supported
      bNumDescriptors         1
      bDescriptorType        34 Report
      wDescriptorLength      77
      Report Descriptor: (length is 77)
        Item(Global): Usage Page, data= [ 0x01 ] 1
                        Generic Desktop Controls
        Item(Local ): Usage, data= [ 0x02 ] 2
                        Mouse
        Item(Main  ): Collection, data= [ 0x01 ] 1
                        Application
        Item(Local ): Usage, data= [ 0x01 ] 1
                        Pointer
        Item(Main  ): Collection, data= [ 0x00 ] 0
                        Physical
        Item(Global): Usage Page, data= [ 0x09 ] 9
                        Buttons
...

Bind the deivce and it starts working again

$ echo -n 2-2.4:1.0 | sudo tee /sys/bus/usb/drivers/usbhid/bind

usbhid-dump on Linux

Dump descriptor and parse it like this.

$ sudo usbhid-dump -d046d -i255
001:005:000:DESCRIPTOR         1468982571.405056
 05 01 09 02 A1 01 09 01 A1 00 05 09 19 01 29 08
 15 00 25 01 95 08 75 01 81 02 95 00 81 03 06 00
 FF 09 40 95 02 75 08 15 81 25 7F 81 02 05 01 09
 38 15 81 25 7F 75 08 95 01 81 06 09 30 09 31 16
 01 F8 26 FF 07 75 0C 95 02 81 06 C0 C0          
         
$ sudo usbhid-dump -d046d -i255 |grep -v : | xxd -r -p | hidrd-convert -o spec
Usage Page (Desktop),               ; Generic desktop controls (01h)
Usage (Mouse),                      ; Mouse (02h, application collection)
Collection (Application),
    Usage (Pointer),                ; Pointer (01h, physical collection)
    Collection (Physical),
        Usage Page (Button),        ; Button (09h)
        Usage Minimum (01h),
        Usage Maximum (08h),
        Logical Minimum (0),
        Logical Maximum (1),
        Report Count (8),
        Report Size (1),
        Input (Variable),
        Report Count (0),
        Input (Constant, Variable),
        Usage Page (FF00h),         ; FF00h, vendor-defined
        Usage (40h),
        Report Count (2),
...

How to build

$ git clone https://github.com/DIGImend/hidrd.git
$ git clone https://github.com/DIGImend/usbhid-dump.git
$ cd hidrd # or usbhid-dump
$ autoreconf --force --install
$ ./configure
$ make

Descriptors Examples

Logitech MX510 mouse

$ sudo usbhid-dump -d 046d -i255 | grep -v : | xxd -r -p | hidrd-convert -o spec
Usage Page (Desktop),               ; Generic desktop controls (01h)
Usage (Mouse),                      ; Mouse (02h, application collection)
Collection (Application),
    Usage (Pointer),                ; Pointer (01h, physical collection)
    Collection (Physical),
        Usage Page (Button),        ; Button (09h)
        Usage Minimum (01h),
        Usage Maximum (08h),
        Logical Minimum (0),
        Logical Maximum (1),
        Report Count (8),
        Report Size (1),
        Input (Variable),
        Report Count (0),
        Input (Constant, Variable),
        Usage Page (FF00h),         ; FF00h, vendor-defined
        Usage (40h),
        Report Count (2),
        Report Size (8),
        Logical Minimum (-127),
        Logical Maximum (127),
        Input (Variable),
        Usage Page (Desktop),       ; Generic desktop controls (01h)
        Usage (Wheel),              ; Wheel (38h, dynamic value)
        Logical Minimum (-127),
        Logical Maximum (127),
        Report Size (8),
        Report Count (1),
        Input (Variable, Relative),
        Usage (X),                  ; X (30h, dynamic value)
        Usage (Y),                  ; Y (31h, dynamic value)
        Logical Minimum (-2047),
        Logical Maximum (2047),
        Report Size (12),
        Report Count (2),
        Input (Variable, Relative),
    End Collection,
End Collection

Bus 005 Device 005: ID 046d:c01d Logitech, Inc. MX510 Optical Mouse
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            0 
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0         8
  idVendor           0x046d Logitech, Inc.
  idProduct          0xc01d MX510 Optical Mouse
  bcdDevice           21.00
  iManufacturer           1 Logitech
  iProduct                2 USB-PS/2 Optical Mouse
  iSerial                 0 
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x0022
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0 
    bmAttributes         0xa0
      (Bus Powered)
      Remote Wakeup
    MaxPower               98mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         3 Human Interface Device
      bInterfaceSubClass      1 Boot Interface Subclass
      bInterfaceProtocol      2 Mouse
      iInterface              0 
        HID Device Descriptor:
          bLength                 9
          bDescriptorType        33
          bcdHID               1.10
          bCountryCode            0 Not supported
          bNumDescriptors         1
          bDescriptorType        34 Report
          wDescriptorLength      77
          Report Descriptor: (length is 77)
            Item(Global): Usage Page, data= [ 0x01 ] 1
                            Generic Desktop Controls
            Item(Local ): Usage, data= [ 0x02 ] 2
                            Mouse
            Item(Main  ): Collection, data= [ 0x01 ] 1
                            Application
            Item(Local ): Usage, data= [ 0x01 ] 1
                            Pointer
            Item(Main  ): Collection, data= [ 0x00 ] 0
                            Physical
            Item(Global): Usage Page, data= [ 0x09 ] 9
                            Buttons
            Item(Local ): Usage Minimum, data= [ 0x01 ] 1
                            Button 1 (Primary)
            Item(Local ): Usage Maximum, data= [ 0x08 ] 8
                            (null)
            Item(Global): Logical Minimum, data= [ 0x00 ] 0
            Item(Global): Logical Maximum, data= [ 0x01 ] 1
            Item(Global): Report Count, data= [ 0x08 ] 8
            Item(Global): Report Size, data= [ 0x01 ] 1
            Item(Main  ): Input, data= [ 0x02 ] 2
                            Data Variable Absolute No_Wrap Linear
                            Preferred_State No_Null_Position Non_Volatile Bitfield
            Item(Global): Report Count, data= [ 0x00 ] 0
            Item(Main  ): Input, data= [ 0x03 ] 3
                            Constant Variable Absolute No_Wrap Linear
                            Preferred_State No_Null_Position Non_Volatile Bitfield
            Item(Global): Usage Page, data= [ 0x00 0xff ] 65280
                            (null)
            Item(Local ): Usage, data= [ 0x40 ] 64
                            (null)
            Item(Global): Report Count, data= [ 0x02 ] 2
            Item(Global): Report Size, data= [ 0x08 ] 8
            Item(Global): Logical Minimum, data= [ 0x81 ] 129
            Item(Global): Logical Maximum, data= [ 0x7f ] 127
            Item(Main  ): Input, data= [ 0x02 ] 2
                            Data Variable Absolute No_Wrap Linear
                            Preferred_State No_Null_Position Non_Volatile Bitfield
            Item(Global): Usage Page, data= [ 0x01 ] 1
                            Generic Desktop Controls
            Item(Local ): Usage, data= [ 0x38 ] 56
                            Wheel
            Item(Global): Logical Minimum, data= [ 0x81 ] 129
            Item(Global): Logical Maximum, data= [ 0x7f ] 127
            Item(Global): Report Size, data= [ 0x08 ] 8
            Item(Global): Report Count, data= [ 0x01 ] 1
            Item(Main  ): Input, data= [ 0x06 ] 6
                            Data Variable Relative No_Wrap Linear
                            Preferred_State No_Null_Position Non_Volatile Bitfield
            Item(Local ): Usage, data= [ 0x30 ] 48
                            Direction-X
            Item(Local ): Usage, data= [ 0x31 ] 49
                            Direction-Y
            Item(Global): Logical Minimum, data= [ 0x01 0xf8 ] 63489
            Item(Global): Logical Maximum, data= [ 0xff 0x07 ] 2047
            Item(Global): Report Size, data= [ 0x0c ] 12
            Item(Global): Report Count, data= [ 0x02 ] 2
            Item(Main  ): Input, data= [ 0x06 ] 6
                            Data Variable Relative No_Wrap Linear
                            Preferred_State No_Null_Position Non_Volatile Bitfield
            Item(Main  ): End Collection, data=none
            Item(Main  ): End Collection, data=none
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0007  1x 7 bytes
        bInterval              10
Device Status:     0x0000
  (Bus Powered)

Apple Magic Keyboard model A1644

https://gist.github.com/tmk/0626b78f73575d5c1efa86470c4cdb18

https://github.com/tmk/tmk_keyboard/issues/606

HHKB Classic

https://gist.github.com/tmk/5e29450724fc30d06681212b0e9b5056

Adafruit nRF52 Arduino hid_keyboard example

https://gist.github.com/tmk/8e8e6185af93e4e3ccd2660684f9cf7c

Griffin PowerMate

https://forum.pjrc.com/threads/52752-USBHost-for-Griffin-Powermate?p=181527&viewfull=1#post181527

EzKEY Corp. USB to PS2 Adaptor v1.09

https://gist.github.com/tmk/593657709a4cdc67799db60665e18f4b

Ducky One 2 Mini

https://gist.github.com/tmk/2f3a680cfe4cba78b678611032ac20e4

Clone this wiki locally