1.\" $NetBSD: usb.3,v 1.10 2000/02/22 12:39:22 augustss Exp $ 2.\" $FreeBSD$ 3.\" 4.\" Copyright (c) 1999 Lennart Augustsson <augustss@netbsd.org> 5.\" All rights reserved. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 1. Redistributions of source code must retain the above copyright 11.\" notice, this list of conditions and the following disclaimer. 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice, this list of conditions and the following disclaimer in the 14.\" documentation and/or other materials provided with the distribution. 15.\" 16.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26.\" SUCH DAMAGE. 27.\" 28.Dd May 11, 1999 29.Dt USB 3 30.Os 31.Sh NAME 32.Nm usb , 33.Nm hid_get_report_desc , 34.Nm hid_dispose_report_desc , 35.Nm hid_start_parse , 36.Nm hid_end_parse , 37.Nm hid_get_item , 38.Nm hid_report_size , 39.Nm hid_locate , 40.Nm hid_usage_page , 41.Nm hid_usage_in_page , 42.Nm hid_init , 43.Nm hid_get_data , 44.Nm hid_set_data 45.Nd USB HID access routines 46.Sh LIBRARY 47.Lb libusb 48.Sh SYNOPSIS 49.Fd #include <libusb.h> 50.Ft report_desc_t 51.Fn hid_get_report_desc "int file" 52.Ft void 53.Fn hid_dispose_report_desc "report_desc_t d" 54.Ft hid_data_t 55.Fn hid_start_parse "report_desc_t d" "int kindset" 56.Ft void 57.Fn hid_end_parse "hid_data_t s" 58.Ft int 59.Fn hid_get_item "hid_data_t s" "hid_item_t *h" 60.Ft int 61.Fn hid_report_size "report_desc_t d" "hid_kind_t k" "int *idp" 62.Ft int 63.Fn hid_locate "report_desc_t d" "u_int usage" "hid_kind_t k" "hid_item_t *h" 64.Ft char * 65.Fn hid_usage_page "int i" 66.Ft char * 67.Fn hid_usage_in_page "u_int u" 68.Ft void 69.Fn hid_init "char *file" 70.Ft int 71.Fn hid_get_data "void *data" "hid_item_t *h" 72.Ft void 73.Fn hid_set_data "void *data" "hid_item_t *h" "u_int data" 74.Sh DESCRIPTION 75The 76.Nm 77library provides routines to extract data from USB Human Interface Devices. 78.Ss INTRODUCTION 79USB HID devices send and receive data layed out in a device dependent 80way. The 81.Nm 82library contains routines to extract the 83.Em report descriptor 84which contains the data layout information and then use this information. 85.Pp 86The routines can be divided into four parts: extraction of the descriptor, 87parsing of the descriptor, translating to/from symbolic names, and 88data manipulation. 89.Ss DESCRIPTOR FUNCTIONS 90A report descriptor can be obtained by calling 91.Fn hid_get_report_desc 92with a file descriptor obtained by opening a 93.Xr uhid 4 94device. 95When the report descriptor is no longer needed it should be freed 96by calling 97.Fn hid_dispose_report_desc . 98The type 99.Fa report_desc_t 100is opaque and should be used when calling the parsing functions. 101.Ss DESCRIPTOR PARSING FUNCTIONS 102To parse the report descriptor the 103.Fn hid_start_parse 104function should be called with a report descriptor and a set that 105describes which items that are interesting. The set is obtained 106by or-ing together values 107.Fa "(1 << k)" 108where 109.Fa k 110is an item of type 111.Fa hid_kind_t . 112The function returns 113.Fa NULL 114if the initialization fails, otherwise an opaque value to be used 115in subsequent calls. 116After parsing the 117.Fn hid_end_parse 118function should be called to free internal data structures. 119.Pp 120To iterate through all the items in the report descriptor 121.Fn hid_get_item 122should be called while it returns a value greater than 0. 123When the report descriptor ends it will returns 0; a syntax 124error within the report descriptor will cause a return value less 125than 0. 126The struct pointed to by 127.Fa h 128will be filled with the relevant data for the item. 129The definition of 130.Fa hid_item_t 131can be found in 132.Pa <libusb.h> 133and the meaning of the components in the USB HID documentation. 134.Pp 135Data should be read/written to the device in the size of 136the report. The size of a report (of a certain kind) can be 137computed by the 138.Fn hid_report_size 139function. If the report is prefixed by an ID byte it is 140stored at 141.Fa idp , 142otherwise it will contain 0. 143.Pp 144To locate a single item the 145.Fn hid_locate 146function can be used. It should be given the usage code of 147the item and its kind and it will fill the item and return 148non-zero if the item was found. 149.Pp 150.Ss NAME TRANSLATION FUNCTIONS 151The function 152.Fn hid_usage_page 153will return the symbolic name of a usage page, and the function 154.Fn hid_usage_in_page 155will return the symbolic name of the usage within the page. 156Both these functions may return a pointer to static data. 157Before either of these functions can be called the usage table 158must be parsed, this is done by calling 159.Fn hid_init 160with the name of the table. Passing 161.Fa NULL 162to this function will cause it to use the default table. 163.Ss DATA EXTRACTION FUNCTIONS 164Given the data obtained from a HID device and an item in the 165report descriptor the 166.Fn hid_get_data 167function extracts the value of the item. 168Conversely 169.Fn hid_set_data 170can be used to put data into a report (which must be zeroed first). 171.Sh EXAMPLE 172Not yet. 173.Sh FILES 174.Pa /usr/share/misc/usb_hid_usages 175The default HID usage table. 176.Sh BUGS 177This man page is woefully incomplete. 178.Sh SEE ALSO 179The 180.Tn USB 181specifications can be found at 182.Dv http://www.usb.org/developers/docs.htm . 183.Pp 184.Xr hid 4 , 185.Xr usb 4 . 186.Sh HISTORY 187The 188.Nm 189library first appeared in 190.Nx 1.5 . 191