Page MenuHomeFreeBSD

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

Authored by wulf on Dec 23 2020, 9:19 PM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Apr 17, 8:23 AM
Unknown Object (File)
Fri, Apr 12, 10:50 AM
Unknown Object (File)
Mar 7 2024, 6:14 PM
Unknown Object (File)
Feb 25 2024, 3:38 AM
Unknown Object (File)
Feb 14 2024, 7:27 AM
Unknown Object (File)
Feb 12 2024, 1:19 PM
Unknown Object (File)
Jan 19 2024, 2:28 PM
Unknown Object (File)
Jan 19 2024, 1:14 AM
Subscribers
None

Details

Summary

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

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

wulf requested review of this revision.Dec 23 2020, 9:19 PM
wulf created this revision.
sys/dev/usb/usb_hid.c
115

Use memset() here instead of bzero().

279

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.
sys/dev/usb/usb_hid.c
279

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
sys/dev/usb/usbhid.h
211

Should this be called HID_MAXUSAGE ?

sys/dev/usb/usbhid.h
211

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