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)
Fri, Nov 1, 2:41 PM
Unknown Object (File)
Tue, Oct 29, 6:46 PM
Unknown Object (File)
Mon, Oct 28, 7:58 PM
Unknown Object (File)
Sat, Oct 19, 11:36 AM
Unknown Object (File)
Sat, Oct 19, 11:34 AM
Unknown Object (File)
Sep 24 2024, 9:15 AM
Unknown Object (File)
Sep 22 2024, 6:48 AM
Unknown Object (File)
Sep 18 2024, 10:11 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