1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*
22 * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23 * Use is subject to license terms.
24 */
25
26#ifndef _SYS_USB_HIDPARSER_IMPL_H
27#define	_SYS_USB_HIDPARSER_IMPL_H
28
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34
35/*
36 * This header file is only included by the hidparser.  It contains
37 * implementation specifc information for the hidparser.
38 */
39
40
41/*
42 *  This is for Global and Local items like Usage Page,
43 *  Usage Min, Logical Min, Report Count, Report Size etc.
44 *  "value" was declared as char array to handle
45 *  the case of extended items which can be up to
46 *  255 bytes.
47 */
48typedef struct entity_attribute {
49	uint_t	entity_attribute_tag;		/* see tag codes below */
50	char	*entity_attribute_value;	/* Data bytes */
51	int	entity_attribute_length; 	/* No. of data bytes */
52
53	/* linked list of attributes */
54	struct	entity_attribute	*entity_attribute_next;
55} entity_attribute_t;
56
57
58/*
59 *  This is for these entities: Collection, Input, Output,
60 *  Feature and End Collection.
61 */
62typedef struct entity_item {
63
64	/* input, output, collection, feature or end collection */
65	int		entity_item_type;
66
67	/* constant, variable, relative, etc... */
68	char		*entity_item_params;
69
70	int		entity_item_params_leng; /* No. of bytes for params */
71
72	/*
73	 *   linked list of entity and control attributes. Parser is
74	 *   responsbile for handling entity attributes' inheritance,
75	 *   therefore this is NULL for end collection. But not for
76	 *   begin collection.
77	 */
78	entity_attribute_t	*entity_item_attributes;
79
80	/*
81	 *  linked list of children if this is a collection
82	 *  otherwise pointer to data for input/output
83	 */
84	union info  {
85		struct entity_item	*child;
86		void			*data;
87	} info;
88
89	/* pointer to the right sibling */
90	struct entity_item	*entity_item_right_sibling;
91
92	struct entity_item	*prev_coll;
93
94} entity_item_t;
95
96
97
98/* Use this typedef in defining the FIRSTs */
99typedef int			hidparser_terminal_t;
100
101
102/*
103 * Hid parser handle
104 */
105typedef struct hidparser_handle_impl {
106
107	/* Pointer to the parser tree */
108	entity_item_t		*hidparser_handle_parse_tree;
109
110	/* Pointer to the hid descriptor */
111	usb_hid_descr_t		*hidparser_handle_hid_descr;
112} hidparser_handle;
113
114
115/*
116 * Additional items that are not defined in hid_parser.h because they should
117 * not be exposed to the hid streams modules.
118 */
119
120
121/*
122 * Additional Local Items
123 *      See section 6.2.2.8 of the HID 1.0 specification for
124 *      more details.
125 */
126
127#define	HIDPARSER_ITEM_SET_DELIMITER 0xA8
128
129
130/*
131 * Addtional Global Items
132 *      See section 6.2.2.7 of the HID 1.0 specifations for
133 *      more details.
134 */
135#define	HIDPARSER_ITEM_USAGE_PAGE 0x04
136#define	HIDPARSER_ITEM_PUSH 0xA4
137#define	HIDPARSER_ITEM_POP 0xB4
138
139/*
140 * Main Items
141 *      See section 6.2.2.5 of the HID 1.0 specification for
142 *      more details.
143 */
144#define	HIDPARSER_ITEM_COLLECTION 0xA0
145#define	HIDPARSER_ITEM_END_COLLECTION 0xC0
146
147typedef struct entity_attribute_stack {
148	struct entity_attribute_stack	*next;
149	entity_attribute_t	*list;
150} entity_attribute_stack_t;
151
152/*
153 * This structure is the interface between the parser
154 * and the scanner.
155 */
156typedef struct hidparser_tok {
157	unsigned char		*hidparser_tok_text;	/* Data bytes */
158	int			hidparser_tok_leng;	/* No. of data bytes */
159
160	/* Maximum buffer size */
161	size_t			hidparser_tok_max_bsize;
162
163	/* Raw descriptor */
164	unsigned char		*hidparser_tok_entity_descriptor;
165
166	/* Index to token currently being processed */
167	size_t			hidparser_tok_index;
168
169	/* Current token being processed */
170	int			hidparser_tok_token;
171
172	/* Pointer to the Global Item list */
173	entity_attribute_t	*hidparser_tok_gitem_head;
174
175	/* Pointer to the Local Item list */
176	entity_attribute_t	*hidparser_tok_litem_head;
177
178	/* Stack for push|pop Items */
179	entity_attribute_stack_t	*hidparser_head;
180
181} hidparser_tok_t;
182
183
184/*  Entity Item Tags - HID 5.4.3  */
185#define	R_ITEM_INPUT 0x80
186#define	R_ITEM_OUTPUT 0x90
187#define	R_ITEM_COLLECTION 0xA0
188#define	R_ITEM_FEATURE 0xB0
189#define	R_ITEM_END_COLLECTION 0xC0
190
191/*  Entity Attribute Item Tags HID 5.4.4 */
192#define	R_ITEM_USAGE_PAGE 0x04
193#define	R_ITEM_LOGICAL_MINIMUM 0x14
194#define	R_ITEM_LOGICAL_MAXIMUM 0x24
195#define	R_ITEM_PHYSICAL_MINIMUM 0x34
196#define	R_ITEM_PHYSICAL_MAXIMUM 0x44
197#define	R_ITEM_EXPONENT 0x54
198#define	R_ITEM_UNIT 0x64
199#define	R_ITEM_REPORT_SIZE 0x74
200#define	R_ITEM_REPORT_ID 0x84
201#define	R_ITEM_REPORT_COUNT 0x94
202#define	R_ITEM_PUSH 0xA4
203#define	R_ITEM_POP 0xB4
204
205/*  Control Attribute Item Tags  */
206#define	R_ITEM_USAGE 0x08
207#define	R_ITEM_USAGE_MIN 0x18
208#define	R_ITEM_USAGE_MAX 0x28
209#define	R_ITEM_DESIGNATOR_INDEX 0x38
210#define	R_ITEM_DESIGNATOR_MIN 0x48
211#define	R_ITEM_DESIGNATOR_MAX 0x58
212#define	R_ITEM_STRING_INDEX 0x78
213#define	R_ITEM_STRING_MIN 0x88
214#define	R_ITEM_STRING_MAX 0x98
215#define	R_ITEM_SET_DELIMITER 0xA8
216
217
218/* Tags used to find the FIRST tokens corresponding to a nonterminal */
219
220#define	HIDPARSER_ITEMS		0
221
222/* Used for hidparser Error check */
223#define	HIDPARSER_ERR_ERROR		0x8000
224#define	HIDPARSER_ERR_WARN		0x0000
225#define	HIDPARSER_ERR_STANDARD		0x0000
226#define	HIDPARSER_ERR_VENDOR		0x4000
227#define	HIDPARSER_ERR_TAG_MASK		0x3f00
228#define	HIDPARSER_ERR_SUBCODE_MASK	0xff
229#define	HIDPARSER_DELIM_ERR1		1
230#define	HIDPARSER_DELIM_ERR2		2
231#define	HIDPARSER_DELIM_ERR3		3
232
233
234/* other */
235#define	EXTENDED_ITEM			0xFE
236#define	HIDPARSER_TEXT_LENGTH		500
237#define	HIDPARSER_ISLOCAL_MASK		0x08
238
239/*
240 * Debug printing
241 */
242#define	PRINT_MASK_ALL		0xFFFFFFFF
243
244
245#ifdef __cplusplus
246}
247#endif
248
249#endif	/* _SYS_USB_HIDPARSER_IMPL_H */
250