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 __HIDPriv__
24#define __HIDPriv__
25
26/*
27	File:		HIDPriv.i
28
29	Contains:	xxx put contents here xxx
30
31	Version:	xxx put version here xxx
32
33	Copyright:	� 1999 by Apple Computer, Inc., all rights reserved.
34
35	File Ownership:
36
37		DRI:				xxx put dri here xxx
38
39		Other Contact:		xxx put other contact here xxx
40
41		Technology:			xxx put technology here xxx
42
43	Writers:
44
45		(BWS)	Brent Schorsch
46
47	Change History (most recent first):
48
49		 <5>	 11/1/99	BWS		[2405720]  We need a better check for 'bit padding' items,
50									rather than just is constant. We will check to make sure the
51									item is constant, and has no usage, or zero usage. This means we
52									need to pass an additional parameter to some internal functions
53		 <4>	  4/7/99	BWS		Add flags to report items (for reverse)
54		 <3>	 3/19/99	BWS		Build stub library
55		 <2>	 3/17/99	BWS		[2314839]  Add flags field to HIDPreparsedData, is set in
56									HIDOpenReportDescriptor
57		 <1>	  3/5/99	BWS		first checked in
58*/
59
60#include "HIDMacTypes.h"
61#include <IOKit/hidsystem/IOHIDDescriptorParser.h>
62
63/* the following constants are from the USB HID Specification (www.usb.org)*/
64
65/*------------------------------------------------------------------------------*/
66/*																				*/
67/* HID Header																	*/
68/*																				*/
69/* ---------------------------------------------------------					*/
70/* |  7	  |	 6	 |	5	|  4   |  3	  |	 2	 |	1	|  0   |					*/
71/* |			Tag			   |	Type	 |	  Size	   |					*/
72/* ---------------------------------------------------------					*/
73/*------------------------------------------------------------------------------*/
74enum {
75	kHIDItemSizeMask			= 0x03,
76	kHIDItemTagMask				= 0xF0,
77	kHIDItemTagShift			= 4,
78	kHIDItemTypeMask			= 0x0C,
79	kHIDItemTypeShift			= 2,
80	kHIDLongItemHeader			= 0xFE
81};
82
83/*------------------------------------------------------------------------------*/
84/*																				*/
85/* HID Item Type Definitions													*/
86/*																				*/
87/*------------------------------------------------------------------------------*/
88enum {
89	kHIDTypeMain				= 0,
90	kHIDTypeGlobal				= 1,
91	kHIDTypeLocal				= 2,
92	kHIDTypeLong				= 3
93};
94
95/*------------------------------------------------------------------------------*/
96/*																				*/
97/* HID Item Tag Definitions - Main Items										*/
98/*																				*/
99/*------------------------------------------------------------------------------*/
100enum {
101	kHIDTagInput				= 8,
102	kHIDTagOutput				= 9,
103	kHIDTagCollection			= 0x0A,
104	kHIDTagFeature				= 0x0B,
105	kHIDTagEndCollection		= 0x0C
106};
107
108/*------------------------------------------------------------------------------*/
109/*																				*/
110/* HID Item Tag Definitions - Globals											*/
111/*																				*/
112/*------------------------------------------------------------------------------*/
113enum {
114	kHIDTagUsagePage			= 0,
115	kHIDTagLogicalMinimum		= 1,
116	kHIDTagLogicalMaximum		= 2,
117	kHIDTagPhysicalMinimum		= 3,
118	kHIDTagPhysicalMaximum		= 4,
119	kHIDTagUnitExponent			= 5,
120	kHIDTagUnit					= 6,
121	kHIDTagReportSize			= 7,
122	kHIDTagReportID				= 8,
123	kHIDTagReportCount			= 9,
124	kHIDTagPush					= 0x0A,
125	kHIDTagPop					= 0x0B
126};
127
128/*------------------------------------------------------------------------------*/
129/*																				*/
130/* HID Item Tag Definitions - Locals											*/
131/*																				*/
132/*------------------------------------------------------------------------------*/
133enum {
134	kHIDTagUsage				= 0,
135	kHIDTagUsageMinimum			= 1,
136	kHIDTagUsageMaximum			= 2,
137	kHIDTagDesignatorIndex		= 3,
138	kHIDTagDesignatorMinimum	= 4,
139	kHIDTagDesignatorMaximum	= 5,
140	kHIDTagStringIndex			= 7,
141	kHIDTagStringMinimum		= 8,
142	kHIDTagStringMaximum		= 9,
143	kHIDTagSetDelimiter			= 0x0A
144};
145
146/*------------------------------------------------------------------------------*/
147/*																				*/
148/* HID Main Item Header Bit Definitions											*/
149/*																				*/
150/*------------------------------------------------------------------------------*/
151enum {
152	kHIDDataBufferedBytes		= 0x0100,
153	kHIDDataVolatileBit			= 0x80,
154	kHIDDataVolatile			= 0x80,
155	kHIDDataNullStateBit		= 0x40,
156	kHIDDataNullState			= 0x40,
157	kHIDDataNoPreferredBit		= 0x20,
158	kHIDDataNoPreferred			= 0x20,
159	kHIDDataNonlinearBit		= 0x10,
160	kHIDDataNonlinear			= 0x10,
161	kHIDDataWrapBit				= 0x08,
162	kHIDDataWrap				= 0x08,
163	kHIDDataRelativeBit			= 0x04,
164	kHIDDataRelative			= 0x04,
165	kHIDDataAbsolute			= 0x00,
166	kHIDDataVariableBit			= 0x02,
167	kHIDDataVariable			= 0x02,
168	kHIDDataArrayBit			= 0x02,
169	kHIDDataArray				= 0x00,
170	kHIDDataConstantBit			= 0x01,
171	kHIDDataConstant			= 0x01
172};
173
174/*------------------------------------------------------------------------------*/
175/*																				*/
176/* HID Collection Data Definitions												*/
177/*																				*/
178/*------------------------------------------------------------------------------*/
179enum {
180	kHIDPhysicalCollection		= 0x00,
181	kHIDApplicationCollection	= 0x01
182};
183
184/*------------------------------------------------------------------------------*/
185/*																				*/
186/* HIDLibrary private defs														*/
187/*																				*/
188/*------------------------------------------------------------------------------*/
189
190enum
191{
192	kHIDOSType			=	'hid '
193};
194
195struct HIDItem
196{
197	IOByteCount 	byteCount;
198	SInt32			itemType;
199	SInt32			tag;
200	SInt32			signedValue;
201	UInt32			unsignedValue;
202};
203typedef struct HIDItem HIDItem;
204
205struct HIDGlobalItems
206{
207	HIDUsage		usagePage;
208	SInt32			logicalMinimum;
209	SInt32			logicalMaximum;
210	SInt32			physicalMinimum;
211	SInt32			physicalMaximum;
212	SInt32			unitExponent;
213	SInt32			units;
214	IOByteCount		reportSize;
215	SInt32			reportID;
216	SInt32			reportCount;
217	SInt32			reportIndex;
218};
219typedef struct HIDGlobalItems HIDGlobalItems;
220
221struct HIDReportSizes
222{
223	SInt32		reportID;
224	SInt32		inputBitCount;
225	SInt32		outputBitCount;
226	SInt32		featureBitCount;
227};
228typedef struct HIDReportSizes HIDReportSizes;
229
230struct HIDCollection
231{
232	SInt32		data;
233	SInt32		usagePage;
234	SInt32		firstUsageItem;
235	SInt32		usageItemCount;
236	SInt32		firstReportItem;
237	SInt32		reportItemCount;
238	SInt32		parent;
239	SInt32		children;
240	SInt32		firstChild;
241	SInt32		nextSibling;
242};
243typedef struct HIDCollection HIDCollection;
244
245struct HIDCollectionExtendedNode
246{
247	HIDUsage	collectionUsage;
248	HIDUsage	collectionUsagePage;
249	UInt32		parent;
250	UInt32		numberOfChildren;
251	UInt32		nextSibling;
252	UInt32		firstChild;
253        UInt32		data;
254};
255typedef struct HIDCollectionExtendedNode HIDCollectionExtendedNode, * HIDCollectionExtendedNodePtr;
256
257enum
258{
259	kHIDReportItemFlag_Reversed			=	0x00000001
260};
261
262struct HIDReportItem
263{
264	UInt32				reportType;
265	HIDGlobalItems		globals;
266	SInt32				startBit;
267	SInt32				parent;
268	SInt32				dataModes;
269	SInt32				firstUsageItem;
270	SInt32				usageItemCount;
271	SInt32				firstStringItem;
272	SInt32				stringItemCount;
273	SInt32				firstDesigItem;
274	SInt32				desigItemCount;
275	UInt32				flags;
276};
277typedef struct HIDReportItem HIDReportItem;
278
279struct HIDP_UsageItem
280{
281	Boolean		isRange;
282	Boolean		reserved;
283	HIDUsage	usagePage;
284	HIDUsage	usage;
285	SInt32		usageMinimum;
286	SInt32		usageMaximum;
287};
288typedef struct HIDP_UsageItem HIDP_UsageItem;
289
290struct HIDStringItem
291{
292	Boolean		isRange;
293	Boolean		reserved;
294	SInt32		index;
295	SInt32		minimum;
296	SInt32		maximum;
297};
298typedef struct HIDStringItem HIDStringItem;
299typedef HIDStringItem HIDDesignatorItem;
300
301struct HIDPreparsedData
302{
303	UInt32				hidTypeIfValid;
304	HIDCollection *		collections;
305	UInt32				collectionCount;
306	HIDReportItem *		reportItems;
307	UInt32				reportItemCount;
308	HIDReportSizes *	reports;
309	UInt32				reportCount;
310	HIDP_UsageItem *	usageItems;
311	UInt32				usageItemCount;
312	HIDStringItem *		stringItems;
313	UInt32				stringItemCount;
314	HIDDesignatorItem * desigItems;
315	UInt32				desigItemCount;
316	UInt8 *				rawMemPtr;
317	UInt32				flags;
318	IOByteCount			numBytesAllocated;
319};
320typedef struct HIDPreparsedData HIDPreparsedData;
321typedef HIDPreparsedData * HIDPreparsedDataPtr;
322
323extern
324OSStatus
325HIDCheckReport			   (HIDReportType 			reportType,
326							HIDPreparsedDataRef		preparsedDataRef,
327							HIDReportItem *			reportItem,
328							void * 					report,
329							IOByteCount				reportLength);
330
331
332extern
333OSStatus
334HIDGetData				   (void *					report,
335							IOByteCount				reportLength,
336							UInt32					start,
337							UInt32					size,
338							SInt32 *				value,
339							Boolean 				signExtend);
340
341extern
342OSStatus
343HIDPostProcessRIValue 	   (HIDReportItem *			reportItem,
344							SInt32 *				value);
345
346extern
347OSStatus
348HIDPreProcessRIValue  	   (HIDReportItem *	 		reportItem,
349							SInt32 *				value);
350
351extern
352Boolean
353HIDHasUsage				   (HIDPreparsedDataRef		preparsedDataRef,
354							HIDReportItem *			reportItem,
355							HIDUsage				usagePage,
356							HIDUsage				usage,
357							UInt32 *				usageIndex,
358							UInt32 *				count);
359
360extern
361Boolean
362HIDIsButton				   (HIDReportItem *			reportItem,
363							HIDPreparsedDataRef		preparsedDataRef);
364
365extern
366Boolean
367HIDIsVariable			   (HIDReportItem *			reportItem,
368							HIDPreparsedDataRef		preparsedDataRef);
369
370extern
371OSStatus
372HIDPutData				   (void *					report,
373							IOByteCount				reportLength,
374							UInt32					start,
375							UInt32					size,
376							SInt32 					value);
377
378extern
379OSStatus
380HIDScaleUsageValueIn	   (HIDReportItem *			reportItem,
381							UInt32 					value,
382							SInt32 *				scaledValue);
383
384extern
385OSStatus
386HIDScaleUsageValueOut	   (HIDReportItem *			reportItem,
387							UInt32 					value,
388							SInt32 *				scaledValue);
389
390extern
391void
392HIDUsageAndPageFromIndex   (HIDPreparsedDataRef		preparsedDataRef,
393							HIDReportItem *			reportItem,
394							UInt32 					index,
395							HIDUsageAndPage *		usageAndPage);
396
397extern
398Boolean
399HIDUsageInRange			   (HIDP_UsageItem *		usageItem,
400							HIDUsage				usagePage,
401							HIDUsage				usage);
402
403#endif
404