— USB HID access
char *data, unsigned int
d, int kindset,
d, hid_kind_t k,
d, u_int usage,
const char *
const char *
usbhid library provides routines to
extract data from USB Human Interface Devices.
USB HID devices send and receive data laid out in a device
dependent way. The
usbhid library contains routines
to extract the
descriptor which contains the data layout information and then use
The routines can be divided into four parts: extraction of the descriptor, parsing of the descriptor, translating to/from symbolic names, and data manipulation.
A report descriptor can be obtained by calling
with a file descriptor obtained by opening a
uhid(4) device. Alternatively a data buffer containing the report
descriptor can be passed into
The data is copied into an internal structure. When the report descriptor is
no longer needed it should be freed by calling
The type report_desc_t is opaque and should be used
when calling the parsing functions.
NULL on failure.
DESCRIPTOR PARSING FUNCTIONS
To parse the report descriptor the
function should be called with a report descriptor and a set that describes
which items that are interesting. The set is obtained by or-ing together
values (1 << k) where k is
an item of type hid_kind_t. The desired report ID, or
-1 to obtain items of all report IDs, is given by id.
The function returns NULL if the initialization fails,
otherwise an opaque value to be used in subsequent calls. After parsing the
function should be called to free internal data structures.
To iterate through all the items in the report
should be called while it returns a value greater than 0. When the report
descriptor ends it will return 0; a syntax error within the report
descriptor will cause a return value less than 0. The struct pointed to by
h will be filled with the relevant data for the item.
The definition of hid_item_t can be found in
<usbhid.h> and the meaning
of the components in the USB HID documentation.
Data should be read/written to the device in
the size of the report. The size of a report (of a certain kind) can be
computed by the
function. If the report is prefixed by an ID byte it is given by
To locate a single item the
function can be used. It should be given the usage code of the item and its
kind and it will fill the item and return non-zero if the item was
NAME TRANSLATION FUNCTIONS
will return the symbolic name of a usage page, and the function
will return the symbolic name of the usage within the page. Both these
functions may return a pointer to static data.
are the inverses of
hid_usage_in_page(). They take a usage string and
return the number of the usage, or -1 if it cannot be found.
Before any of these functions can be called the
usage table must be parsed, this is done by calling
with the name of the table. Passing NULL to this
function will cause it to use the default table. A return value of -1
indicates that an error has occurred, and errno is
DATA EXTRACTION FUNCTIONS
Given the data obtained from a HID device and an item in the
report descriptor the
function extracts the value of the item. Conversely
can be used to put data into a report (which must be zeroed first).
/usr/share/misc/usb_hid_usages The default HID usage table.
The USB specifications can be found at: https://www.usb.org/documents/
usbhid library first appeared in
This man page is woefully incomplete.