]> git.saurik.com Git - apple/xnu.git/blob - iokit/Families/IOHIDSystem/IOHIDDescriptorParser/HIDProcessGlobalItem.c
xnu-124.13.tar.gz
[apple/xnu.git] / iokit / Families / IOHIDSystem / IOHIDDescriptorParser / HIDProcessGlobalItem.c
1 /*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /*
23 File: HIDProcessGlobalItem.c
24
25 Contains: xxx put contents here xxx
26
27 Version: xxx put version here xxx
28
29 Copyright: © 1999 by Apple Computer, Inc., all rights reserved.
30
31 File Ownership:
32
33 DRI: xxx put dri here xxx
34
35 Other Contact: xxx put other contact here xxx
36
37 Technology: xxx put technology here xxx
38
39 Writers:
40
41 (DF) David Ferguson
42 (BWS) Brent Schorsch
43
44 Change History (most recent first):
45
46 <USB2> 10/18/99 DF Lets try not reporting an error with zero report count
47 <USB1> 3/5/99 BWS first checked in
48 */
49
50 #include "HIDLib.h"
51
52 /*
53 *------------------------------------------------------------------------------
54 *
55 * HIDProcessGlobalItem - Process a GlobalItem
56 *
57 * Input:
58 * ptDescriptor - The Descriptor Structure
59 * ptPreparsedData - The PreParsedData Structure
60 * Output:
61 * ptDescriptor - The Descriptor Structure
62 * ptPreparsedData - The PreParsedData Structure
63 * Returns:
64 * kHIDSuccess - Success
65 * kHIDNullPointerErr - Argument, Pointer was Null
66 *
67 *------------------------------------------------------------------------------
68 */
69 OSStatus HIDProcessGlobalItem(HIDReportDescriptor *ptDescriptor, HIDPreparsedDataPtr ptPreparsedData)
70 {
71 HIDReportSizes *ptReport;
72 HIDGlobalItems *ptGlobals;
73 HIDItem *ptItem;
74 int reportIndex;
75 /*
76 * Disallow NULL Pointers
77 */
78 if ((ptDescriptor == NULL) || (ptPreparsedData == NULL))
79 return kHIDNullPointerErr;
80 /*
81 * Process by tag
82 */
83 ptItem = &ptDescriptor->item;
84 ptGlobals = &ptDescriptor->globals;
85 switch (ptItem->tag)
86 {
87 /*
88 * usage Page
89 */
90 case kHIDTagUsagePage:
91 if (ptItem->unsignedValue == 0)
92 return kHIDUsagePageZeroErr;
93 ptGlobals->usagePage = ptItem->unsignedValue;
94 break;
95 /*
96 * Logical Minimum
97 */
98 case kHIDTagLogicalMinimum:
99 ptGlobals->logicalMinimum = ptItem->signedValue;
100 break;
101 /*
102 * Logical Maximum
103 */
104 case kHIDTagLogicalMaximum:
105 ptGlobals->logicalMaximum = ptItem->signedValue;
106 break;
107 /*
108 * Physical Minimum
109 */
110 case kHIDTagPhysicalMinimum:
111 ptGlobals->physicalMinimum = ptItem->signedValue;
112 break;
113 /*
114 * Physical Maximum
115 */
116 case kHIDTagPhysicalMaximum:
117 ptGlobals->physicalMaximum = ptItem->signedValue;
118 break;
119 /*
120 * Unit Exponent
121 */
122 case kHIDTagUnitExponent:
123 ptGlobals->unitExponent = ptItem->signedValue;
124 break;
125 /*
126 * Unit
127 */
128 case kHIDTagUnit:
129 ptGlobals->units = ptItem->unsignedValue;
130 break;
131 /*
132 * Report Size in Bits
133 */
134 case kHIDTagReportSize:
135 ptGlobals->reportSize = ptItem->unsignedValue;
136 if (ptGlobals->reportSize == 0)
137 return kHIDReportSizeZeroErr;
138 break;
139 /*
140 * Report ID
141 */
142 case kHIDTagReportID:
143 if (ptItem->unsignedValue == 0)
144 return kHIDReportIDZeroErr;
145 /*
146 * Look for the Report ID in the table
147 */
148 reportIndex = 0;
149 while ((reportIndex < ptPreparsedData->reportCount)
150 && (ptPreparsedData->reports[reportIndex].reportID != ptItem->unsignedValue))
151 reportIndex++;
152 /*
153 * Initialize the entry if it's new and there's room for it
154 * Start with 8 bits for the Report ID
155 */
156 if (reportIndex == ptPreparsedData->reportCount)
157 {
158 ptReport = &ptPreparsedData->reports[ptPreparsedData->reportCount++];
159 ptReport->reportID = ptItem->unsignedValue;
160 ptReport->inputBitCount = 8;
161 ptReport->outputBitCount = 8;
162 ptReport->featureBitCount = 8;
163 }
164 /*
165 * Remember which report is being processed
166 */
167 ptGlobals->reportID = ptItem->unsignedValue;
168 ptGlobals->reportIndex = reportIndex;
169 break;
170 /*
171 * Report Count
172 */
173 case kHIDTagReportCount:
174 #if 0
175 // some device actually have a report count of zero specified. we must allow it!
176 if (ptItem->unsignedValue == 0)
177 return kHIDReportCountZeroErr;
178 #endif
179 ptGlobals->reportCount = ptItem->unsignedValue;
180 break;
181 /*
182 * Push Globals
183 */
184 case kHIDTagPush:
185 ptDescriptor->globalsStack[ptDescriptor->globalsNesting++] = ptDescriptor->globals;
186 break;
187 /*
188 * Pop Globals
189 */
190 case kHIDTagPop:
191 ptDescriptor->globals = ptDescriptor->globalsStack[--ptDescriptor->globalsNesting];
192 break;
193 }
194 return kHIDSuccess;
195 }