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