]> git.saurik.com Git - apple/xnu.git/blob - iokit/Families/IOHIDSystem/IOHIDDescriptorParser/HIDGetCaps.c
xnu-123.5.tar.gz
[apple/xnu.git] / iokit / Families / IOHIDSystem / IOHIDDescriptorParser / HIDGetCaps.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: HIDGetCaps.c
24
25 Contains: xxx put contents here xxx
26
27 Version: xxx put version here xxx
28
29 Copyright: © 1999-2000 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 (KH) Keithen Hayenga
42 (BWS) Brent Schorsch
43
44 Change History (most recent first):
45
46 <USB3> 4/21/00 KH Added HIDGetCapabilities to be consistant with
47 HIDGetButtonCapabilities, HIDGetSpecificButtonCapabilities,
48 HIDGetValueCapabilities, and HIDGetSpecificValueCapabilities.
49 <USB2> 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 <USB1> 3/5/99 BWS first checked in
54 */
55
56 #include "HIDLib.h"
57
58 /*
59 *------------------------------------------------------------------------------
60 *
61 * HIDP_GetCaps
62 *
63 * Input:
64 * ptPreparsedData - Pre-Parsed Data
65 * ptCapabilities - Pointer to caller-provided structure
66 * Output:
67 * ptCapabilities - Capabilities data
68 * Returns:
69 *
70 *------------------------------------------------------------------------------
71 */
72 OSStatus HIDGetCaps(HIDPreparsedDataRef preparsedDataRef, HIDCapsPtr ptCapabilities)
73 {
74 HIDPreparsedDataPtr ptPreparsedData = (HIDPreparsedDataPtr) preparsedDataRef;
75 HIDCollection *ptCollection;
76 HIDReportItem *ptReportItem;
77 HIDReportSizes *ptReport;
78 int iFirstUsage;
79 int i;
80 /*
81 * Disallow Null Pointers
82 */
83
84 if ((ptPreparsedData == NULL) || (ptCapabilities == NULL))
85 return kHIDNullPointerErr;
86 if (ptPreparsedData->hidTypeIfValid != kHIDOSType)
87 return kHIDInvalidPreparsedDataErr;
88 /*
89 * Copy the capabilities to the user
90 * Collection Capabilities
91 */
92
93 ptCollection = &ptPreparsedData->collections[1];
94 ptCapabilities->usagePage = ptCollection->usagePage;
95 iFirstUsage = ptCollection->firstUsageItem;
96 ptCapabilities->usage = ptPreparsedData->usageItems[iFirstUsage].usage;
97 ptCapabilities->numberCollectionNodes = ptPreparsedData->collectionCount;
98 /*
99 * Report Capabilities Summary
100 */
101
102 ptCapabilities->inputReportByteLength = 0;
103 ptCapabilities->outputReportByteLength = 0;
104 ptCapabilities->featureReportByteLength = 0;
105 for (i=0; i<ptPreparsedData->reportCount; i++)
106 {
107 ptReport = &ptPreparsedData->reports[i];
108 if (ptCapabilities->inputReportByteLength < ptReport->inputBitCount)
109 ptCapabilities->inputReportByteLength = ptReport->inputBitCount;
110 if (ptCapabilities->outputReportByteLength < ptReport->outputBitCount)
111 ptCapabilities->outputReportByteLength = ptReport->outputBitCount;
112 if (ptCapabilities->featureReportByteLength < ptReport->featureBitCount)
113 ptCapabilities->featureReportByteLength = ptReport->featureBitCount;
114 }
115 ptCapabilities->inputReportByteLength = (ptCapabilities->inputReportByteLength + 7) /8;
116 ptCapabilities->outputReportByteLength = (ptCapabilities->outputReportByteLength + 7)/8;
117 ptCapabilities->featureReportByteLength = (ptCapabilities->featureReportByteLength + 7)/8;
118 /*
119 * Sum the capabilities types
120 */
121
122 ptCapabilities->numberInputButtonCaps = 0;
123 ptCapabilities->numberInputValueCaps = 0;
124 ptCapabilities->numberOutputButtonCaps = 0;
125 ptCapabilities->numberOutputValueCaps = 0;
126 ptCapabilities->numberFeatureButtonCaps = 0;
127 ptCapabilities->numberFeatureValueCaps = 0;
128 for (i=0; i<ptPreparsedData->reportItemCount; i++)
129 {
130 ptReportItem = &ptPreparsedData->reportItems[i];
131 switch (ptReportItem->reportType)
132 {
133 case kHIDInputReport:
134 if (HIDIsButton(ptReportItem, preparsedDataRef))
135 ptCapabilities->numberInputButtonCaps += ptReportItem->usageItemCount;
136 else if (HIDIsVariable(ptReportItem, preparsedDataRef))
137 ptCapabilities->numberInputValueCaps += ptReportItem->usageItemCount;
138 break;
139 case kHIDOutputReport:
140 if (HIDIsButton(ptReportItem, preparsedDataRef))
141 ptCapabilities->numberOutputButtonCaps += ptReportItem->usageItemCount;
142 else if (HIDIsVariable(ptReportItem, preparsedDataRef))
143 ptCapabilities->numberOutputValueCaps += ptReportItem->usageItemCount;
144 break;
145 case kHIDFeatureReport:
146 if (HIDIsButton(ptReportItem, preparsedDataRef))
147 ptCapabilities->numberFeatureButtonCaps += ptReportItem->usageItemCount;
148 else if (HIDIsVariable(ptReportItem, preparsedDataRef))
149 ptCapabilities->numberFeatureValueCaps += ptReportItem->usageItemCount;
150 break;
151 }
152 }
153 return kHIDSuccess;
154 }
155
156
157 /*
158 *------------------------------------------------------------------------------
159 *
160 * HIDGetCapabilities This is exactly the same as HIDGetCaps. It does take a
161 * HIDCapabiitiesPtr instead of a HIDCapsPtr, but the structures
162 * of each are exactly the same. The only reason this call
163 * exists seperately is for uniformity of naming with
164 * HIDGetValueCapabilities, HIDGetSpecificButtonCapabilities, etc.
165 *
166 * Input:
167 * ptPreparsedData - Pre-Parsed Data
168 * ptCapabilities - Pointer to caller-provided structure
169 * Output:
170 * ptCapabilities - Capabilities data
171 * Returns:
172 *
173 *------------------------------------------------------------------------------
174 */
175 OSStatus HIDGetCapabilities(HIDPreparsedDataRef preparsedDataRef, HIDCapabilitiesPtr ptCapabilities)
176 {
177 HIDPreparsedDataPtr ptPreparsedData = (HIDPreparsedDataPtr) preparsedDataRef;
178 HIDCollection *ptCollection;
179 HIDReportItem *ptReportItem;
180 HIDReportSizes *ptReport;
181 int iFirstUsage;
182 int i;
183 /*
184 * Disallow Null Pointers
185 */
186
187 if ((ptPreparsedData == NULL) || (ptCapabilities == NULL))
188 return kHIDNullPointerErr;
189 if (ptPreparsedData->hidTypeIfValid != kHIDOSType)
190 return kHIDInvalidPreparsedDataErr;
191 /*
192 * Copy the capabilities to the user
193 * Collection Capabilities
194 */
195
196 ptCollection = &ptPreparsedData->collections[1];
197 ptCapabilities->usagePage = ptCollection->usagePage;
198 iFirstUsage = ptCollection->firstUsageItem;
199 ptCapabilities->usage = ptPreparsedData->usageItems[iFirstUsage].usage;
200 ptCapabilities->numberCollectionNodes = ptPreparsedData->collectionCount;
201 /*
202 * Report Capabilities Summary
203 */
204
205 ptCapabilities->inputReportByteLength = 0;
206 ptCapabilities->outputReportByteLength = 0;
207 ptCapabilities->featureReportByteLength = 0;
208 for (i=0; i<ptPreparsedData->reportCount; i++)
209 {
210 ptReport = &ptPreparsedData->reports[i];
211 if (ptCapabilities->inputReportByteLength < ptReport->inputBitCount)
212 ptCapabilities->inputReportByteLength = ptReport->inputBitCount;
213 if (ptCapabilities->outputReportByteLength < ptReport->outputBitCount)
214 ptCapabilities->outputReportByteLength = ptReport->outputBitCount;
215 if (ptCapabilities->featureReportByteLength < ptReport->featureBitCount)
216 ptCapabilities->featureReportByteLength = ptReport->featureBitCount;
217 }
218 ptCapabilities->inputReportByteLength = (ptCapabilities->inputReportByteLength + 7) /8;
219 ptCapabilities->outputReportByteLength = (ptCapabilities->outputReportByteLength + 7)/8;
220 ptCapabilities->featureReportByteLength = (ptCapabilities->featureReportByteLength + 7)/8;
221 /*
222 * Sum the capabilities types
223 */
224
225 ptCapabilities->numberInputButtonCaps = 0;
226 ptCapabilities->numberInputValueCaps = 0;
227 ptCapabilities->numberOutputButtonCaps = 0;
228 ptCapabilities->numberOutputValueCaps = 0;
229 ptCapabilities->numberFeatureButtonCaps = 0;
230 ptCapabilities->numberFeatureValueCaps = 0;
231 for (i=0; i<ptPreparsedData->reportItemCount; i++)
232 {
233 ptReportItem = &ptPreparsedData->reportItems[i];
234 switch (ptReportItem->reportType)
235 {
236 case kHIDInputReport:
237 if (HIDIsButton(ptReportItem, preparsedDataRef))
238 ptCapabilities->numberInputButtonCaps += ptReportItem->usageItemCount;
239 else if (HIDIsVariable(ptReportItem, preparsedDataRef))
240 ptCapabilities->numberInputValueCaps += ptReportItem->usageItemCount;
241 break;
242 case kHIDOutputReport:
243 if (HIDIsButton(ptReportItem, preparsedDataRef))
244 ptCapabilities->numberOutputButtonCaps += ptReportItem->usageItemCount;
245 else if (HIDIsVariable(ptReportItem, preparsedDataRef))
246 ptCapabilities->numberOutputValueCaps += ptReportItem->usageItemCount;
247 break;
248 case kHIDFeatureReport:
249 if (HIDIsButton(ptReportItem, preparsedDataRef))
250 ptCapabilities->numberFeatureButtonCaps += ptReportItem->usageItemCount;
251 else if (HIDIsVariable(ptReportItem, preparsedDataRef))
252 ptCapabilities->numberFeatureValueCaps += ptReportItem->usageItemCount;
253 break;
254 }
255 }
256 return kHIDSuccess;
257 }