2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
23 File: HIDSetUsageValueArray.c
25 Contains: xxx put contents here xxx
27 Version: xxx put version here xxx
29 Copyright: © 1999-2001 by Apple Computer, Inc., all rights reserved.
33 DRI: xxx put dri here xxx
35 Other Contact: xxx put other contact here xxx
37 Technology: xxx put technology here xxx
44 Change History (most recent first):
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
60 *------------------------------------------------------------------------------
62 * HIDSetUsageValueArray - Set the values for a usage
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
75 * piValue - Pointer to usage Value
78 *------------------------------------------------------------------------------
80 OSStatus
HIDSetUsageValueArray(HIDReportType reportType
,
86 HIDPreparsedDataRef preparsedDataRef
,
90 HIDPreparsedDataPtr ptPreparsedData
= (HIDPreparsedDataPtr
) preparsedDataRef
;
91 HIDCollection
*ptCollection
;
92 HIDReportItem
*ptReportItem
;
102 Boolean bIncompatibleReport
= false;
104 * Disallow Null Pointers
106 if ((ptPreparsedData
== NULL
)
107 || (psUsageBuffer
== NULL
)
108 || (psReport
== NULL
))
109 return kHIDNullPointerErr
;
110 if (ptPreparsedData
->hidTypeIfValid
!= kHIDOSType
)
111 return kHIDInvalidPreparsedDataErr
;
113 * The Collection must be in range
115 if ((iCollection
< 0) || (iCollection
>= ptPreparsedData
->collectionCount
))
116 return kHIDBadParameterErr
;
118 * Search only the scope of the Collection specified
119 * Go through the ReportItems
120 * Filter on ReportType and usagePage
122 ptCollection
= &ptPreparsedData
->collections
[iCollection
];
123 for (iR
=0; iR
<ptCollection
->reportItemCount
; iR
++)
125 iReportItem
= ptCollection
->firstReportItem
+ iR
;
126 ptReportItem
= &ptPreparsedData
->reportItems
[iReportItem
];
127 if (HIDIsVariable(ptReportItem
, preparsedDataRef
)
128 && HIDHasUsage(preparsedDataRef
,ptReportItem
,usagePage
,usage
,&iUsageIndex
,&iCount
))
131 * This may be the proper place
132 * Let's check for the proper Report ID, Type, and Length
134 iStatus
= HIDCheckReport(reportType
,preparsedDataRef
,ptReportItem
,
135 psReport
,iReportLength
);
137 * The Report ID or Type may not match.
138 * This may not be an error (yet)
140 if (iStatus
== kHIDIncompatibleReportErr
)
141 bIncompatibleReport
= true;
142 else if (iStatus
!= kHIDSuccess
)
147 * Disallow single count variables
148 * Count is set by HasUsage
151 return kHIDNotValueArrayErr
;
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
++)
161 iValue
= *psUsageBuffer
++;
162 iStatus
= HIDPreProcessRIValue (ptReportItem
, &iValue
);
163 iStatus
= HIDPutData(psReport
, iReportLength
, iStart
, 8, iValue
);
164 if (iStatus
!= kHIDSuccess
)
172 if (bIncompatibleReport
)
173 return kHIDIncompatibleReportErr
;
174 return kHIDUsageNotFoundErr
;