summaryrefslogtreecommitdiff
path: root/usr/src/uts/common/sys/usb/clients/hidparser/hidparser_impl.h
blob: 8b646fed11fedd0985884f1fbf8e6d517718f017 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#ifndef _SYS_USB_HIDPARSER_IMPL_H
#define	_SYS_USB_HIDPARSER_IMPL_H


#ifdef __cplusplus
extern "C" {
#endif


/*
 * This header file is only included by the hidparser.  It contains
 * implementation specifc information for the hidparser.
 */


/*
 *  This is for Global and Local items like Usage Page,
 *  Usage Min, Logical Min, Report Count, Report Size etc.
 *  "value" was declared as char array to handle
 *  the case of extended items which can be up to
 *  255 bytes.
 */
typedef struct entity_attribute {
	uint_t	entity_attribute_tag;		/* see tag codes below */
	char	*entity_attribute_value;	/* Data bytes */
	int	entity_attribute_length; 	/* No. of data bytes */

	/* linked list of attributes */
	struct	entity_attribute	*entity_attribute_next;
} entity_attribute_t;


/*
 *  This is for these entities: Collection, Input, Output,
 *  Feature and End Collection.
 */
typedef struct entity_item {

	/* input, output, collection, feature or end collection */
	int		entity_item_type;

	/* constant, variable, relative, etc... */
	char		*entity_item_params;

	int		entity_item_params_leng; /* No. of bytes for params */

	/*
	 *   linked list of entity and control attributes. Parser is
	 *   responsbile for handling entity attributes' inheritance,
	 *   therefore this is NULL for end collection. But not for
	 *   begin collection.
	 */
	entity_attribute_t	*entity_item_attributes;

	/*
	 *  linked list of children if this is a collection
	 *  otherwise pointer to data for input/output
	 */
	union info  {
		struct entity_item	*child;
		void			*data;
	} info;

	/* pointer to the right sibling */
	struct entity_item	*entity_item_right_sibling;

	struct entity_item	*prev_coll;

} entity_item_t;



/* Use this typedef in defining the FIRSTs */
typedef int			hidparser_terminal_t;


/*
 * Hid parser handle
 */
typedef struct hidparser_handle_impl {

	/* Pointer to the parser tree */
	entity_item_t		*hidparser_handle_parse_tree;

	/* Pointer to the hid descriptor */
	usb_hid_descr_t		*hidparser_handle_hid_descr;
} hidparser_handle;


/*
 * Additional items that are not defined in hid_parser.h because they should
 * not be exposed to the hid streams modules.
 */


/*
 * Additional Local Items
 *      See section 6.2.2.8 of the HID 1.0 specification for
 *      more details.
 */

#define	HIDPARSER_ITEM_SET_DELIMITER 0xA8


/*
 * Addtional Global Items
 *      See section 6.2.2.7 of the HID 1.0 specifations for
 *      more details.
 */
#define	HIDPARSER_ITEM_USAGE_PAGE 0x04
#define	HIDPARSER_ITEM_PUSH 0xA4
#define	HIDPARSER_ITEM_POP 0xB4

/*
 * Main Items
 *      See section 6.2.2.5 of the HID 1.0 specification for
 *      more details.
 */
#define	HIDPARSER_ITEM_COLLECTION 0xA0
#define	HIDPARSER_ITEM_END_COLLECTION 0xC0

typedef struct entity_attribute_stack {
	struct entity_attribute_stack	*next;
	entity_attribute_t	*list;
} entity_attribute_stack_t;

/*
 * This structure is the interface between the parser
 * and the scanner.
 */
typedef struct hidparser_tok {
	unsigned char		*hidparser_tok_text;	/* Data bytes */
	int			hidparser_tok_leng;	/* No. of data bytes */

	/* Maximum buffer size */
	size_t			hidparser_tok_max_bsize;

	/* Raw descriptor */
	unsigned char		*hidparser_tok_entity_descriptor;

	/* Index to token currently being processed */
	size_t			hidparser_tok_index;

	/* Current token being processed */
	int			hidparser_tok_token;

	/* Pointer to the Global Item list */
	entity_attribute_t	*hidparser_tok_gitem_head;

	/* Pointer to the Local Item list */
	entity_attribute_t	*hidparser_tok_litem_head;

	/* Stack for push|pop Items */
	entity_attribute_stack_t	*hidparser_head;

} hidparser_tok_t;


/*  Entity Item Tags - HID 5.4.3  */
#define	R_ITEM_INPUT 0x80
#define	R_ITEM_OUTPUT 0x90
#define	R_ITEM_COLLECTION 0xA0
#define	R_ITEM_FEATURE 0xB0
#define	R_ITEM_END_COLLECTION 0xC0

/*  Entity Attribute Item Tags HID 5.4.4 */
#define	R_ITEM_USAGE_PAGE 0x04
#define	R_ITEM_LOGICAL_MINIMUM 0x14
#define	R_ITEM_LOGICAL_MAXIMUM 0x24
#define	R_ITEM_PHYSICAL_MINIMUM 0x34
#define	R_ITEM_PHYSICAL_MAXIMUM 0x44
#define	R_ITEM_EXPONENT 0x54
#define	R_ITEM_UNIT 0x64
#define	R_ITEM_REPORT_SIZE 0x74
#define	R_ITEM_REPORT_ID 0x84
#define	R_ITEM_REPORT_COUNT 0x94
#define	R_ITEM_PUSH 0xA4
#define	R_ITEM_POP 0xB4

/*  Control Attribute Item Tags  */
#define	R_ITEM_USAGE 0x08
#define	R_ITEM_USAGE_MIN 0x18
#define	R_ITEM_USAGE_MAX 0x28
#define	R_ITEM_DESIGNATOR_INDEX 0x38
#define	R_ITEM_DESIGNATOR_MIN 0x48
#define	R_ITEM_DESIGNATOR_MAX 0x58
#define	R_ITEM_STRING_INDEX 0x78
#define	R_ITEM_STRING_MIN 0x88
#define	R_ITEM_STRING_MAX 0x98
#define	R_ITEM_SET_DELIMITER 0xA8


/* Tags used to find the FIRST tokens corresponding to a nonterminal */

#define	HIDPARSER_ITEMS		0

/* Used for hidparser Error check */
#define	HIDPARSER_ERR_ERROR		0x8000
#define	HIDPARSER_ERR_WARN		0x0000
#define	HIDPARSER_ERR_STANDARD		0x0000
#define	HIDPARSER_ERR_VENDOR		0x4000
#define	HIDPARSER_ERR_TAG_MASK		0x3f00
#define	HIDPARSER_ERR_SUBCODE_MASK	0xff
#define	HIDPARSER_DELIM_ERR1		1
#define	HIDPARSER_DELIM_ERR2		2
#define	HIDPARSER_DELIM_ERR3		3


/* other */
#define	EXTENDED_ITEM			0xFE
#define	HIDPARSER_TEXT_LENGTH		500
#define	HIDPARSER_ISLOCAL_MASK		0x08

/*
 * Debug printing
 */
#define	PRINT_MASK_ALL		0xFFFFFFFF


#ifdef __cplusplus
}
#endif

#endif	/* _SYS_USB_HIDPARSER_IMPL_H */