usbhid, hid_get_report_desc, hid_use_report_desc,
hid_dispose_report_desc, hid_start_parse, hid_end_parse,
hid_report_size, hid_locate, hid_usage_page,
hid_start, hid_init, hid_get_data, hid_set_data - USB HID
hid_use_report_desc(unsigned char *data, unsigned int size);
hid_start_parse(report_desc_t d, int kindset, int id);
hid_get_item(hid_data_t s, hid_item_t *h);
hid_report_size(report_desc_t d, hid_kind_t k, int id);
hid_locate(report_desc_t d, u_int usage, hid_kind_t k,
hid_parse_usage_page(const char *);
hid_parse_usage_in_page(const char *);
hid_get_data(void *data, hid_item_t *h);
hid_set_data(void *data, hid_item_t *h, u_int data);
The usbhid library provides routines to extract data from
USB Human Interface
INTRODUCTION [Toc] [Back]
USB HID devices send and receive data laid out in a device
The usbhid library contains routines to extract the report
which contains the data layout information and then use this
The routines can be divided into four parts: extraction of
parsing of the descriptor, translating to/from symbolic
DESCRIPTOR FUNCTIONS [Toc] [Back]
A report descriptor can be obtained by calling
a file descriptor obtained by opening a uhid(4) device. Alternatively a
data buffer containing the report descriptor can be passed
hid_use_report_desc(). The data is copied into an internal
When the report descriptor is no longer needed it should be
calling hid_dispose_report_desc(). The type report_desc_t
is opaque and
should be used when calling the parsing functions. If
hid_dispose_report_desc() fails it will return NULL.
DESCRIPTOR PARSING FUNCTIONS [Toc] [Back]
To parse the report descriptor the hid_start_parse() 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 report ID (if
given by id. The function returns NULL if the initialization fails, otherwise
an opaque value to be used in subsequent calls. After parsing the
hid_end_parse() function should be called to free internal
To iterate through all the items in the report descriptor,
should be called while it returns a value greater than 0.
When the report
descriptor ends it will return 0; a syntax error within
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.
of hid_item_t can be found in <usbhid.h> and the meaning of
in the USB HID documentation.
Data should be read/written to the device in the size of the
size of a report (of a certain kind) can be computed by the
hid_report_size() function. If the report is prefixed by an
ID byte it
is given by id.
To locate a single item the hid_locate() function can be
used. It should
be given the usage code of the item and its kind and it will
item and return non-zero if the item was found.
NAME TRANSLATION FUNCTIONS [Toc] [Back]
The function hid_usage_page() will return the symbolic name
of a usage
page, and the function hid_usage_in_page() will return the
of the usage within the page. Both these functions may return a pointer
to static data.
The functions hid_parse_usage_page() and
the inverses of hid_usage_page() and hid_usage_in_page().
They take a
usage string and return the number of the usage, or -1 if it
Before any of these functions can be called the usage table
parsed, this is done by calling hid_start() with the name of
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
DATA EXTRACTION FUNCTIONS [Toc] [Back]
Given the data obtained from a HID device and an item in the
the hid_get_data() function extracts the value of
Conversely hid_set_data() 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:
The usbhid library first appeared in OpenBSD 3.0.
This man page is woefully incomplete.
OpenBSD 3.6 December 29, 2001
[ Back ]