1/*	$NetBSD: usbhid.h,v 1.6 2016/01/22 23:51:23 dholland Exp $	*/
2
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
29#ifndef _USBHID_H_
30#define _USBHID_H_
31
32#include <sys/cdefs.h>
33#include <stdint.h>
34
35typedef struct report_desc *report_desc_t;
36
37typedef struct hid_data *hid_data_t;
38
39typedef enum hid_kind {
40	hid_input = 0,
41	hid_output = 1,
42	hid_feature = 2,
43	hid_collection,
44	hid_endcollection
45} hid_kind_t;
46
47typedef struct hid_item {
48	/* Global */
49	int _usage_page;
50	int logical_minimum;
51	int logical_maximum;
52	int physical_minimum;
53	int physical_maximum;
54	int unit_exponent;
55	int unit;
56	int report_size;
57	int report_ID;
58#define NO_REPORT_ID 0
59	int report_count;
60	/* Local */
61	unsigned int usage;
62	int usage_minimum;
63	int usage_maximum;
64	int designator_index;
65	int designator_minimum;
66	int designator_maximum;
67	int string_index;
68	int string_minimum;
69	int string_maximum;
70	int set_delimiter;
71	/* Misc */
72	int collection;
73	int collevel;
74	enum hid_kind kind;
75	unsigned int flags;
76	/* Absolute data position (bits) */
77	unsigned int pos;
78	/* */
79	struct hid_item *next;
80} hid_item_t;
81
82#define HID_PAGE(u) (((uint32_t)(u) >> 16) & 0xffff)
83#define HID_USAGE(u) ((u) & 0xffff)
84
85__BEGIN_DECLS
86
87/* Obtaining a report descriptor, descr.c: */
88report_desc_t hid_get_report_desc(int file);
89report_desc_t hid_use_report_desc(const uint8_t *data, unsigned int size);
90void hid_dispose_report_desc(report_desc_t);
91
92/* Parsing of a HID report descriptor, parse.c: */
93hid_data_t hid_start_parse(report_desc_t d, int kindset, int id);
94void hid_end_parse(hid_data_t s);
95int hid_get_item(hid_data_t s, hid_item_t *h);
96int hid_report_size(report_desc_t d, enum hid_kind k, int id);
97int hid_locate(report_desc_t d, unsigned int usage, enum hid_kind k, hid_item_t *h, int id);
98
99/* Conversion to/from usage names, usage.c: */
100const char *hid_usage_page(int i);
101const char *hid_usage_in_page(unsigned int u);
102void hid_init(const char *file);
103int hid_parse_usage_in_page(const char *name);
104int hid_parse_usage_page(const char *name);
105
106/* Extracting/insertion of data, data.c: */
107int hid_get_data(const void *p, const hid_item_t *h);
108void hid_set_data(void *p, const hid_item_t *h, int data);
109
110__END_DECLS
111
112#endif /* _USBHID_H_ */
113