]> git.saurik.com Git - apple/xnu.git/blob - iokit/Families/IOHIDSystem/IOHIDDescriptorParser/HIDSetUsageValueArray.c
29c5ab2cc8563c645e96f679f9b77661590d4b4f
[apple/xnu.git] / iokit / Families / IOHIDSystem / IOHIDDescriptorParser / HIDSetUsageValueArray.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: HIDSetUsageValueArray.c
24
25 Contains: xxx put contents here xxx
26
27 Version: xxx put version here xxx
28
29 Copyright: © 1999-2001 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 <USB5> 1/18/01 KH Fix for complex descriptors only needed for buttons.
47 <USB4> 3/24/00 KH Complex report descriptors could lead to reporting
48 kHIDUsageNotFoundErr's as kHIDIncompatibleReportErr's instead.
49 <USB3> 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 <USB2> 4/7/99 BWS Add support for reversed report items
54 <USB1> 3/5/99 BWS first checked in
55 */
56
57 #include "HIDLib.h"
58
59 /*
60 *------------------------------------------------------------------------------
61 *
62 * HIDSetUsageValueArray - Set the values for a usage
63 *
64 * Input:
65 * reportType - HIDP_Input, HIDP_Output, HIDP_Feature
66 * usagePage - Page Criteria
67 * iCollection - Collection Criteria or zero
68 * usage - usage Criteria
69 * psBuffer - Pointer to usage Buffer
70 * iByteLength - Length of usage Buffer
71 * ptPreparsedData - Pre-Parsed Data
72 * psReport - An HID Report
73 * iReportLength - The length of the Report
74 * Output:
75 * piValue - Pointer to usage Value
76 * Returns:
77 *
78 *------------------------------------------------------------------------------
79 */
80 OSStatus HIDSetUsageValueArray(HIDReportType reportType,
81 HIDUsage usagePage,
82 UInt32 iCollection,
83 HIDUsage usage,
84 UInt8 *psUsageBuffer,
85 UInt32 iByteLength,
86 HIDPreparsedDataRef preparsedDataRef,
87 void *psReport,
88 UInt32 iReportLength)
89 {
90 HIDPreparsedDataPtr ptPreparsedData = (HIDPreparsedDataPtr) preparsedDataRef;
91 HIDCollection *ptCollection;
92 HIDReportItem *ptReportItem;
93 OSStatus iStatus;
94 int i;
95 int iR;
96 long iValue;
97 int iStart;
98 int iReportItem;
99 UInt32 iUsageIndex;
100 UInt32 iCount;
101 int byteCount;
102 Boolean bIncompatibleReport = false;
103 /*
104 * Disallow Null Pointers
105 */
106 if ((ptPreparsedData == NULL)
107 || (psUsageBuffer == NULL)
108 || (psReport == NULL))
109 return kHIDNullPointerErr;
110 if (ptPreparsedData->hidTypeIfValid != kHIDOSType)
111 return kHIDInvalidPreparsedDataErr;
112 /*
113 * The Collection must be in range
114 */
115 if ((iCollection < 0) || (iCollection >= ptPreparsedData->collectionCount))
116 return kHIDBadParameterErr;
117 /*
118 * Search only the scope of the Collection specified
119 * Go through the ReportItems
120 * Filter on ReportType and usagePage
121 */
122 ptCollection = &ptPreparsedData->collections[iCollection];
123 for (iR=0; iR<ptCollection->reportItemCount; iR++)
124 {
125 iReportItem = ptCollection->firstReportItem + iR;
126 ptReportItem = &ptPreparsedData->reportItems[iReportItem];
127 if (HIDIsVariable(ptReportItem, preparsedDataRef)
128 && HIDHasUsage(preparsedDataRef,ptReportItem,usagePage,usage,&iUsageIndex,&iCount))
129 {
130 /*
131 * This may be the proper place
132 * Let's check for the proper Report ID, Type, and Length
133 */
134 iStatus = HIDCheckReport(reportType,preparsedDataRef,ptReportItem,
135 psReport,iReportLength);
136 /*
137 * The Report ID or Type may not match.
138 * This may not be an error (yet)
139 */
140 if (iStatus == kHIDIncompatibleReportErr)
141 bIncompatibleReport = true;
142 else if (iStatus != kHIDSuccess)
143 return iStatus;
144 else
145 {
146 /*
147 * Disallow single count variables
148 * Count is set by HasUsage
149 */
150 if (iCount <= 1)
151 return kHIDNotValueArrayErr;
152 /*
153 * Write out the data
154 */
155 iStart = ptReportItem->startBit + (ptReportItem->globals.reportSize * iUsageIndex);
156 byteCount = (ptReportItem->globals.reportSize * iCount + 7)/8;
157 if (byteCount > iByteLength)
158 byteCount = iByteLength;
159 for (i=0; i<byteCount; i++)
160 {
161 iValue = *psUsageBuffer++;
162 iStatus = HIDPreProcessRIValue (ptReportItem, &iValue);
163 iStatus = HIDPutData(psReport, iReportLength, iStart, 8, iValue);
164 if (iStatus != kHIDSuccess)
165 return iStatus;
166 iStart += 8;
167 }
168 return kHIDSuccess;
169 }
170 }
171 }
172 if (bIncompatibleReport)
173 return kHIDIncompatibleReportErr;
174 return kHIDUsageNotFoundErr;
175 }