1/*
2 * @APPLE_LICENSE_HEADER_START@
3 *
4 * Copyright (c) 1999-2012 Apple Computer, Inc.  All Rights Reserved.
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23#ifndef _IOKIT_HID_IOHIDPARSERPRIV_H
24#define _IOKIT_HID_IOHIDPARSERPRIV_H
25
26/* the following constants are from the USB HID Specification (www.usb.org)*/
27
28/*------------------------------------------------------------------------------*/
29/*																				*/
30/* HID Main Item Header Bit Definitions											*/
31/*																				*/
32/*------------------------------------------------------------------------------*/
33enum {
34	kHIDDataBufferedBytes		= 0x0100,
35	kHIDDataVolatileBit			= 0x80,
36	kHIDDataVolatile			= 0x80,
37	kHIDDataNullStateBit		= 0x40,
38	kHIDDataNullState			= 0x40,
39	kHIDDataNoPreferredBit		= 0x20,
40	kHIDDataNoPreferred			= 0x20,
41	kHIDDataNonlinearBit		= 0x10,
42	kHIDDataNonlinear			= 0x10,
43	kHIDDataWrapBit				= 0x08,
44	kHIDDataWrap				= 0x08,
45	kHIDDataRelativeBit			= 0x04,
46	kHIDDataRelative			= 0x04,
47	kHIDDataAbsolute			= 0x00,
48	kHIDDataVariableBit			= 0x02,
49	kHIDDataVariable			= 0x02,
50	kHIDDataArrayBit			= 0x02,
51	kHIDDataArray				= 0x00,
52	kHIDDataConstantBit			= 0x01,
53	kHIDDataConstant			= 0x01
54};
55
56#if KERNEL
57/*------------------------------------------------------------------------------*/
58/*																				*/
59/* HID Header																	*/
60/*																				*/
61/* ---------------------------------------------------------					*/
62/* |  7	  |	 6	 |	5	|  4   |  3	  |	 2	 |	1	|  0   |					*/
63/* |			Tag			   |	Type	 |	  Size	   |					*/
64/* ---------------------------------------------------------					*/
65/*------------------------------------------------------------------------------*/
66enum {
67	kHIDItemSizeMask			= 0x03,
68	kHIDItemTagMask				= 0xF0,
69	kHIDItemTagShift			= 4,
70	kHIDItemTypeMask			= 0x0C,
71	kHIDItemTypeShift			= 2,
72	kHIDLongItemHeader			= 0xFE
73};
74
75/*------------------------------------------------------------------------------*/
76/*																				*/
77/* HID Item Type Definitions													*/
78/*																				*/
79/*------------------------------------------------------------------------------*/
80enum {
81	kHIDTypeMain				= 0,
82	kHIDTypeGlobal				= 1,
83	kHIDTypeLocal				= 2,
84	kHIDTypeLong				= 3
85};
86
87/*------------------------------------------------------------------------------*/
88/*																				*/
89/* HID Item Tag Definitions - Main Items										*/
90/*																				*/
91/*------------------------------------------------------------------------------*/
92enum {
93	kHIDTagInput				= 8,
94	kHIDTagOutput				= 9,
95	kHIDTagCollection			= 0x0A,
96	kHIDTagFeature				= 0x0B,
97	kHIDTagEndCollection		= 0x0C
98};
99
100/*------------------------------------------------------------------------------*/
101/*																				*/
102/* HID Item Tag Definitions - Globals											*/
103/*																				*/
104/*------------------------------------------------------------------------------*/
105enum {
106	kHIDTagUsagePage			= 0,
107	kHIDTagLogicalMinimum		= 1,
108	kHIDTagLogicalMaximum		= 2,
109	kHIDTagPhysicalMinimum		= 3,
110	kHIDTagPhysicalMaximum		= 4,
111	kHIDTagUnitExponent			= 5,
112	kHIDTagUnit					= 6,
113	kHIDTagReportSize			= 7,
114	kHIDTagReportID				= 8,
115	kHIDTagReportCount			= 9,
116	kHIDTagPush					= 0x0A,
117	kHIDTagPop					= 0x0B
118};
119
120/*------------------------------------------------------------------------------*/
121/*																				*/
122/* HID Item Tag Definitions - Locals											*/
123/*																				*/
124/*------------------------------------------------------------------------------*/
125enum {
126	kHIDTagUsage				= 0,
127	kHIDTagUsageMinimum			= 1,
128	kHIDTagUsageMaximum			= 2,
129	kHIDTagDesignatorIndex		= 3,
130	kHIDTagDesignatorMinimum	= 4,
131	kHIDTagDesignatorMaximum	= 5,
132	kHIDTagStringIndex			= 7,
133	kHIDTagStringMinimum		= 8,
134	kHIDTagStringMaximum		= 9,
135	kHIDTagSetDelimiter			= 0x0A
136};
137
138/*------------------------------------------------------------------------------*/
139/*																				*/
140/* HID Collection Data Definitions												*/
141/*																				*/
142/*------------------------------------------------------------------------------*/
143enum {
144	kHIDPhysicalCollection		= 0x00,
145	kHIDApplicationCollection	= 0x01
146};
147
148/*------------------------------------------------------------------------------*/
149/*																				*/
150/* HIDLibrary private defs														*/
151/*																				*/
152/*------------------------------------------------------------------------------*/
153
154enum
155{
156	kHIDOSType			=	'hid '
157};
158
159struct HIDItem
160{
161	IOByteCount		byteCount;
162	SInt32			itemType;
163	SInt32			tag;
164	SInt32			signedValue;
165	UInt32			unsignedValue;
166};
167typedef struct HIDItem HIDItem;
168
169struct HIDGlobalItems
170{
171	HIDUsage		usagePage;
172	SInt32			logicalMinimum;
173	SInt32			logicalMaximum;
174	SInt32			physicalMinimum;
175	SInt32			physicalMaximum;
176	SInt32			unitExponent;
177	SInt32			units;
178	IOByteCount		reportSize;
179	SInt32			reportID;
180	SInt32			reportCount;
181	SInt32			reportIndex;
182};
183typedef struct HIDGlobalItems HIDGlobalItems;
184
185struct HIDReportSizes
186{
187	SInt32		reportID;
188	SInt32		inputBitCount;
189	SInt32		outputBitCount;
190	SInt32		featureBitCount;
191};
192typedef struct HIDReportSizes HIDReportSizes;
193
194struct HIDCollection
195{
196	SInt32		data;
197	SInt32		usagePage;
198	SInt32		firstUsageItem;
199	SInt32		usageItemCount;
200	SInt32		firstReportItem;
201	SInt32		reportItemCount;
202	SInt32		parent;
203	SInt32		children;
204	SInt32		firstChild;
205	SInt32		nextSibling;
206};
207typedef struct HIDCollection HIDCollection;
208
209struct HIDCollectionExtendedNode
210{
211	HIDUsage	collectionUsage;
212	HIDUsage	collectionUsagePage;
213	UInt32		parent;
214	UInt32		numberOfChildren;
215	UInt32		nextSibling;
216	UInt32		firstChild;
217        UInt32		data;
218};
219typedef struct HIDCollectionExtendedNode HIDCollectionExtendedNode, * HIDCollectionExtendedNodePtr;
220
221enum
222{
223	kHIDReportItemFlag_Reversed			=	0x00000001
224};
225
226struct HIDReportItem
227{
228	UInt32				reportType;
229	HIDGlobalItems		globals;
230	SInt32				startBit;
231	SInt32				parent;
232	SInt32				dataModes;
233	SInt32				firstUsageItem;
234	SInt32				usageItemCount;
235	SInt32				firstStringItem;
236	SInt32				stringItemCount;
237	SInt32				firstDesigItem;
238	SInt32				desigItemCount;
239	UInt32				flags;
240};
241typedef struct HIDReportItem HIDReportItem;
242
243struct HIDP_UsageItem
244{
245	Boolean		isRange;
246	Boolean		reserved;
247	HIDUsage	usagePage;
248	HIDUsage	usage;
249	SInt32		usageMinimum;
250	SInt32		usageMaximum;
251};
252typedef struct HIDP_UsageItem HIDP_UsageItem;
253
254struct HIDStringItem
255{
256	Boolean		isRange;
257	Boolean		reserved;
258	SInt32		index;
259	SInt32		minimum;
260	SInt32		maximum;
261};
262typedef struct HIDStringItem HIDStringItem;
263typedef HIDStringItem HIDDesignatorItem;
264
265struct HIDPreparsedData
266{
267	UInt32				hidTypeIfValid;
268	HIDCollection 		*collections;
269	UInt32				collectionCount;
270	HIDReportItem 		*reportItems;
271	UInt32				reportItemCount;
272	HIDReportSizes 		*reports;
273	UInt32				reportCount;
274	HIDP_UsageItem 		*usageItems;
275	UInt32				usageItemCount;
276	HIDStringItem 		*stringItems;
277	UInt32				stringItemCount;
278	HIDDesignatorItem 	*desigItems;
279	UInt32				desigItemCount;
280	UInt8 *				rawMemPtr;
281	UInt32				flags;
282	IOByteCount			numBytesAllocated;
283};
284typedef struct HIDPreparsedData HIDPreparsedData;
285typedef HIDPreparsedData * HIDPreparsedDataPtr;
286
287#ifdef __cplusplus
288extern "C" {
289#endif
290
291// Private methods
292extern
293OSStatus
294HIDGetCollectionExtendedNodes ( HIDCollectionExtendedNodePtr	collectionNodes,
295                                UInt32 *			collectionNodesSize,
296                                HIDPreparsedDataRef		preparsedDataRef );
297#ifdef __cplusplus
298}
299#endif
300
301
302#endif
303
304#endif /* !_IOKIT_HID_IOHIDPARSERPRIV_H */
305