]> git.saurik.com Git - apple/xnu.git/blob - iokit/Families/IOHIDSystem/IOHIDDescriptorParser/HIDSetUsageValue.c
xnu-123.5.tar.gz
[apple/xnu.git] / iokit / Families / IOHIDSystem / IOHIDDescriptorParser / HIDSetUsageValue.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: HIDSetUsageValue.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 * HIDSetUsageValue - 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 HIDSetUsageValue(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 int iStart;
94 int iReportItem;
95 UInt32 iUsageIndex;
96 Boolean bIncompatibleReport = false;
97 /*
98 * Disallow Null Pointers
99 */
100 if ((ptPreparsedData == NULL)
101 || (psReport == NULL))
102 return kHIDNullPointerErr;
103 if (ptPreparsedData->hidTypeIfValid != kHIDOSType)
104 return kHIDInvalidPreparsedDataErr;
105 /*
106 * The Collection must be in range
107 */
108 if ((iCollection < 0) || (iCollection >= ptPreparsedData->collectionCount))
109 return kHIDBadParameterErr;
110 /*
111 * Search only the scope of the Collection specified
112 * Go through the ReportItems
113 * Filter on ReportType and usagePage
114 */
115 ptCollection = &ptPreparsedData->collections[iCollection];
116 for (iR=0; iR<ptCollection->reportItemCount; iR++)
117 {
118 iReportItem = ptCollection->firstReportItem + iR;
119 ptReportItem = &ptPreparsedData->reportItems[iReportItem];
120 if (HIDIsVariable(ptReportItem, preparsedDataRef)
121 && HIDHasUsage(preparsedDataRef,ptReportItem,usagePage,usage,&iUsageIndex,NULL))
122 {
123 /*
124 * This may be the proper place
125 * Let's check for the proper Report ID, Type, and Length
126 */
127 iStatus = HIDCheckReport(reportType,preparsedDataRef,ptReportItem,
128 psReport,iReportLength);
129 /*
130 * The Report ID or Type may not match.
131 * This may not be an error (yet)
132 */
133 if (iStatus == kHIDIncompatibleReportErr)
134 bIncompatibleReport = true;
135 else if (iStatus != kHIDSuccess)
136 return iStatus;
137 else
138 {
139 /*
140 * Write out the data
141 */
142 iStart = ptReportItem->startBit
143 + (ptReportItem->globals.reportSize * iUsageIndex);
144 iStatus = HIDPreProcessRIValue (ptReportItem, &iUsageValue);
145 iStatus = HIDPutData(psReport, iReportLength, iStart,
146 ptReportItem->globals.reportSize, iUsageValue);
147 if (iStatus != kHIDSuccess)
148 return iStatus;
149 return kHIDSuccess;
150 }
151 }
152 }
153 if (bIncompatibleReport)
154 return kHIDIncompatibleReportErr;
155 return kHIDUsageNotFoundErr;
156 }