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: HIDSetUsageValue.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 * HIDSetUsageValue - Set the value for a usage
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
74 * piValue - Pointer to usage Value
77 *------------------------------------------------------------------------------
79 OSStatus
HIDSetUsageValue(HIDReportType reportType
,
84 HIDPreparsedDataRef preparsedDataRef
,
86 ByteCount iReportLength
)
88 HIDPreparsedDataPtr ptPreparsedData
= (HIDPreparsedDataPtr
) preparsedDataRef
;
89 HIDCollection
*ptCollection
;
90 HIDReportItem
*ptReportItem
;
96 Boolean bIncompatibleReport
= false;
98 * Disallow Null Pointers
100 if ((ptPreparsedData
== NULL
)
101 || (psReport
== NULL
))
102 return kHIDNullPointerErr
;
103 if (ptPreparsedData
->hidTypeIfValid
!= kHIDOSType
)
104 return kHIDInvalidPreparsedDataErr
;
106 * The Collection must be in range
108 if ((iCollection
< 0) || (iCollection
>= ptPreparsedData
->collectionCount
))
109 return kHIDBadParameterErr
;
111 * Search only the scope of the Collection specified
112 * Go through the ReportItems
113 * Filter on ReportType and usagePage
115 ptCollection
= &ptPreparsedData
->collections
[iCollection
];
116 for (iR
=0; iR
<ptCollection
->reportItemCount
; iR
++)
118 iReportItem
= ptCollection
->firstReportItem
+ iR
;
119 ptReportItem
= &ptPreparsedData
->reportItems
[iReportItem
];
120 if (HIDIsVariable(ptReportItem
, preparsedDataRef
)
121 && HIDHasUsage(preparsedDataRef
,ptReportItem
,usagePage
,usage
,&iUsageIndex
,NULL
))
124 * This may be the proper place
125 * Let's check for the proper Report ID, Type, and Length
127 iStatus
= HIDCheckReport(reportType
,preparsedDataRef
,ptReportItem
,
128 psReport
,iReportLength
);
130 * The Report ID or Type may not match.
131 * This may not be an error (yet)
133 if (iStatus
== kHIDIncompatibleReportErr
)
134 bIncompatibleReport
= true;
135 else if (iStatus
!= kHIDSuccess
)
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
)
153 if (bIncompatibleReport
)
154 return kHIDIncompatibleReportErr
;
155 return kHIDUsageNotFoundErr
;