xref: /openbsd/lib/libusbhid/usbhid.h (revision 404b540a)
1 /*	$OpenBSD: usbhid.h,v 1.3 2004/06/04 00:47:32 deraadt Exp $	*/
2 /*	$NetBSD: usbhid.h,v 1.1 2001/12/28 17:45:27 augustss Exp $	*/
3 
4 /*
5  * Copyright (c) 1999 Lennart Augustsson <augustss@netbsd.org>
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29 
30 typedef struct report_desc *report_desc_t;
31 
32 typedef struct hid_data *hid_data_t;
33 
34 typedef enum hid_kind {
35 	hid_input = 0,
36 	hid_output = 1,
37 	hid_feature = 2,
38 	hid_collection,
39 	hid_endcollection
40 } hid_kind_t;
41 
42 typedef struct hid_item {
43 	/* Global */
44 	int _usage_page;
45 	int logical_minimum;
46 	int logical_maximum;
47 	int physical_minimum;
48 	int physical_maximum;
49 	int unit_exponent;
50 	int unit;
51 	int report_size;
52 	int report_ID;
53 #define NO_REPORT_ID 0
54 	int report_count;
55 	/* Local */
56 	unsigned int usage;
57 	int usage_minimum;
58 	int usage_maximum;
59 	int designator_index;
60 	int designator_minimum;
61 	int designator_maximum;
62 	int string_index;
63 	int string_minimum;
64 	int string_maximum;
65 	int set_delimiter;
66 	/* Misc */
67 	int collection;
68 	int collevel;
69 	enum hid_kind kind;
70 	unsigned int flags;
71 	/* Absolute data position (bits) */
72 	unsigned int pos;
73 	/* */
74 	struct hid_item *next;
75 } hid_item_t;
76 
77 #define HID_PAGE(u) (((u) >> 16) & 0xffff)
78 #define HID_USAGE(u) ((u) & 0xffff)
79 
80 /* Obtaining a report descriptor, descr.c: */
81 report_desc_t	hid_get_report_desc(int file);
82 report_desc_t	hid_use_report_desc(unsigned char *data, unsigned int size);
83 void		hid_dispose_report_desc(report_desc_t);
84 
85 /* Parsing of a HID report descriptor, parse.c: */
86 hid_data_t	hid_start_parse(report_desc_t d, int kindset, int id);
87 void		hid_end_parse(hid_data_t s);
88 int		hid_get_item(hid_data_t s, hid_item_t *h);
89 int		hid_report_size(report_desc_t d, enum hid_kind k, int id);
90 int		hid_locate(report_desc_t d, unsigned int usage, enum hid_kind k,
91 		    hid_item_t *h, int id);
92 
93 /* Conversion to/from usage names, usage.c: */
94 const char	*hid_usage_page(int i);
95 const char	*hid_usage_in_page(unsigned int u);
96 void		hid_init(const char *file);
97 int		hid_start(const char *file);
98 int		hid_parse_usage_in_page(const char *name);
99 int		hid_parse_usage_page(const char *name);
100 
101 /* Extracting/insertion of data, data.c: */
102 int		hid_get_data(const void *p, const hid_item_t *h);
103 void		hid_set_data(void *p, const hid_item_t *h, int data);
104