hidreport-parsing.rst 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. .. SPDX-License-Identifier: GPL-2.0
  2. ========================================
  3. Manual parsing of HID report descriptors
  4. ========================================
  5. Consider again the mouse HID report descriptor
  6. introduced in Documentation/hid/hidintro.rst::
  7. $ hexdump -C /sys/bus/hid/devices/0003\:093A\:2510.0002/report_descriptor
  8. 00000000 05 01 09 02 a1 01 09 01 a1 00 05 09 19 01 29 03 |..............).|
  9. 00000010 15 00 25 01 75 01 95 03 81 02 75 05 95 01 81 01 |..%.u.....u.....|
  10. 00000020 05 01 09 30 09 31 09 38 15 81 25 7f 75 08 95 03 |...0.1.8..%.u...|
  11. 00000030 81 06 c0 c0 |....|
  12. 00000034
  13. and try to parse it by hand.
  14. Start with the first number, 0x05: it carries 2 bits for the
  15. length of the item, 2 bits for the type of the item and 4 bits for the
  16. function::
  17. +----------+
  18. | 00000101 |
  19. +----------+
  20. ^^
  21. ---- Length of data (see HID spec 6.2.2.2)
  22. ^^
  23. ------ Type of the item (see HID spec 6.2.2.2, then jump to 6.2.2.7)
  24. ^^^^
  25. --------- Function of the item (see HID spec 6.2.2.7, then HUT Sec 3)
  26. In our case, the length is 1 byte, the type is ``Global`` and the
  27. function is ``Usage Page``, thus for parsing the value 0x01 in the second byte
  28. we need to refer to HUT Sec 3.
  29. The second number is the actual data, and its meaning can be found in
  30. the HUT. We have a ``Usage Page``, thus we need to refer to HUT
  31. Sec. 3, "Usage Pages"; from there, one sees that ``0x01`` stands for
  32. ``Generic Desktop Page``.
  33. Moving now to the second two bytes, and following the same scheme,
  34. ``0x09`` (i.e. ``00001001``) will be followed by one byte (``01``)
  35. and is a ``Local`` item (``10``). Thus, the meaning of the remaining four bits
  36. (``0000``) is given in the HID spec Sec. 6.2.2.8 "Local Items", so that
  37. we have a ``Usage``. From HUT, Sec. 4, "Generic Desktop Page", we see that
  38. 0x02 stands for ``Mouse``.
  39. The following numbers can be parsed in the same way.