Page MenuHomeFreeBSD

hid: Allow HID report descriptor parser to return more then 1 usage per item.

Authored by wulf on Dec 23 2020, 9:19 PM.



Allow HID report descriptor parser to return more then 1 usage per item with changing usage field type of struct hid_item to array

This handles parsing of following report descriptor, containing array of usages:

0x05, 0x01,        // Usage Page (Generic Desktop Ctrls)
0x09, 0x80,        // Usage (Sys Control)
0xA1, 0x01,        // Collection (Application)
0x75, 0x02,        //   Report Size (2)
0x95, 0x01,        //   Report Count (1)
0x15, 0x01,        //   Logical Minimum (1)
0x25, 0x03,        //   Logical Maximum (3)
0x09, 0x82,        //   Usage (Sys Sleep)
0x09, 0x81,        //   Usage (Sys Power Down)
0x09, 0x83,        //   Usage (Sys Wake Up)
0x81, 0x60,        //   Input (Data,Array,Abs)
0x75, 0x06,        //   Report Size (6)
0x81, 0x03,        //   Input (Const,Var,Abs)
0xC0,              // End Collection

Our current parser returns only first usage (Sys Sleep) and loses next two.
Set HI_MAXUSAGE limit relatively low as existing code usually allocates
hid_item on stack and aforementioned report descripror snippet is only
sample I have seen.

Diff Detail

R10 FreeBSD src repository
Automatic diff as part of commit; lint not applicable.
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

wulf requested review of this revision.Dec 23 2020, 9:19 PM
wulf created this revision.

Use memset() here instead of bzero().


Should you check for HIO_CONST too?

replace bzero() with memset()

wulf marked an inline comment as done.Dec 24 2020, 4:27 PM
wulf added inline comments.

I doubt. I can't find any connection between Array attribute and Data/Const attribute in HID1_11.pdf except that such combination is legal:

If the Input item is an array, only the Data/Constant, Variable/Array and Absolute/Relative attributes apply`

This revision is now accepted and ready to land.Dec 24 2020, 10:33 PM

Should this be called HID_MAXUSAGE ?


HI is acronym for HID item. Perhaps HID_ITEM_MAXUSAGE would be better name.

Should the user-space hid library also be updated?

Should the user-space hid library also be updated?

I think so. I think anonymous union should be removed in that case to get better compatibility with ANSI/C++

I will prepare the patch