]> git.saurik.com Git - apple/xnu.git/blob - iokit/Families/IOHIDSystem/IOHIDDescriptorParser/HIDSetScaledUsageValue.c
46fabf8f9a3654dae9f7c7556423fdb0be14ca11
[apple/xnu.git] / iokit / Families / IOHIDSystem / IOHIDDescriptorParser / HIDSetScaledUsageValue.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: HIDSetScaledUsageValue.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 * HIDSetScaledUsageValue - Set the value for a usage
63 *
64 * Input:
65 * reportType - HIDP_Input, HIDP_Output, HIDP_Feature
66 * usagePage - Page Criteria or zero
67 * iCollection - Collection Criteria or zero
68 * usage - usage Criteria or zero
69 * iValue - The usage Value
70 * ptPreparsedData - Pre-Parsed Data
71 * psReport - An HID Report
72 * iReportLength - The length of the Report
73 * Output:
74 * piValue - Pointer to usage Value
75 * Returns:
76 *
77 *------------------------------------------------------------------------------
78 */
79 OSStatus HIDSetScaledUsageValue(HIDReportType reportType,
80 HIDUsage usagePage,
81 UInt32 iCollection,
82 HIDUsage usage,
83 SInt32 iUsageValue,
84 HIDPreparsedDataRef preparsedDataRef,
85 void *psReport,
86 ByteCount iReportLength)
87 {
88 HIDPreparsedDataPtr ptPreparsedData = (HIDPreparsedDataPtr) preparsedDataRef;
89 HIDCollection *ptCollection;
90 HIDReportItem *ptReportItem;
91 OSStatus iStatus;
92 int iR;
93 SInt32 data;
94 int iStart;
95 int iReportItem;
96 UInt32 iUsageIndex;
97 Boolean bIncompatibleReport = false;
98 /*
99 * Disallow Null Pointers
100 */
101 if ((ptPreparsedData == NULL)
102 || (psReport == NULL))
103 return kHIDNullPointerErr;
104 if (ptPreparsedData->hidTypeIfValid != kHIDOSType)
105 return kHIDInvalidPreparsedDataErr;
106 /*
107 * The Collection must be in range
108 */
109 if ((iCollection < 0) || (iCollection >= ptPreparsedData->collectionCount))
110 return kHIDBadParameterErr;
111 /*
112 * Search only the scope of the Collection specified
113 * Go through the ReportItems
114 * Filter on ReportType and usagePage
115 */
116 ptCollection = &ptPreparsedData->collections[iCollection];
117 for (iR=0; iR<ptCollection->reportItemCount; iR++)
118 {
119 iReportItem = ptCollection->firstReportItem + iR;
120 ptReportItem = &ptPreparsedData->reportItems[iReportItem];
121 if ((ptReportItem->reportType == reportType)
122 && HIDIsVariable(ptReportItem, preparsedDataRef)
123 && HIDHasUsage(preparsedDataRef,ptReportItem,usagePage,usage,&iUsageIndex,NULL))
124 {
125 /*
126 * This may be the proper place to write data
127 * Let's check for the proper Report ID, Type, and Length
128 */
129 iStatus = HIDCheckReport(reportType,preparsedDataRef,ptReportItem,psReport,iReportLength);
130 /*
131 * The Report ID or Type may not match.
132 * This may not be an error (yet)
133 */
134 if (iStatus == kHIDIncompatibleReportErr)
135 bIncompatibleReport = true;
136 else if (iStatus != kHIDSuccess)
137 return iStatus;
138 else
139 {
140 iStatus = HIDScaleUsageValueOut(ptReportItem,iUsageValue,&data);
141 if (iStatus != kHIDSuccess)
142 return iStatus;
143 iStart = ptReportItem->startBit + (ptReportItem->globals.reportSize * iUsageIndex);
144 iStatus = HIDPreProcessRIValue (ptReportItem, &data);
145 iStatus = HIDPutData(psReport, iReportLength, iStart, ptReportItem->globals.reportSize, data);
146 if (iStatus != kHIDSuccess)
147 return iStatus;
148 return kHIDSuccess;
149 }
150 }
151 }
152 if (bIncompatibleReport)
153 return kHIDIncompatibleReportErr;
154 return kHIDUsageNotFoundErr;
155 }