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: HIDCheckReport.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
45 Change History (most recent first):
47 <USB3> 1/2/01 DF Change length checking to check for the minimum size instead of
49 <USB2> 12/12/00 KH Correcting cast of void *
50 <USB1> 3/5/99 BWS first checked in
56 *------------------------------------------------------------------------------
58 * HIDCheckReport - Check the Report ID, Type, and Length
61 * reportType - The Specified Report Type
62 * ptPreparsedData - The Preparsed Data
63 * ptReportItem - The Report Item
64 * psReport - The Report
65 * iReportLength - The Report Length
68 * kHIDSuccess, HidP_IncompatibleReportID,
69 * kHIDInvalidReportLengthErr, kHIDInvalidReportTypeErr
71 *------------------------------------------------------------------------------
73 OSStatus
HIDCheckReport(HIDReportType reportType
, HIDPreparsedDataRef preparsedDataRef
,
74 HIDReportItem
*ptReportItem
, void *report
, UInt32 iReportLength
)
76 HIDPreparsedDataPtr ptPreparsedData
= (HIDPreparsedDataPtr
) preparsedDataRef
;
77 int reportID
, reportIndex
;
79 Byte
* psReport
= (Byte
*)report
;
81 * See if this is the correct Report ID
83 reportID
= psReport
[0]&0xFF;
84 if ((ptPreparsedData
->reportCount
> 1)
85 && (reportID
!= ptReportItem
->globals
.reportID
))
86 return kHIDIncompatibleReportErr
;
88 * See if this is the correct ReportType
90 if (reportType
!= ptReportItem
->reportType
)
91 return kHIDIncompatibleReportErr
;
93 * Check for the correct Length for the Type
95 reportIndex
= ptReportItem
->globals
.reportIndex
;
99 iExpectedLength
= (ptPreparsedData
->reports
[reportIndex
].inputBitCount
+ 7)/8;
101 case kHIDOutputReport
:
102 iExpectedLength
= (ptPreparsedData
->reports
[reportIndex
].outputBitCount
+ 7)/8;
104 case kHIDFeatureReport
:
105 iExpectedLength
= (ptPreparsedData
->reports
[reportIndex
].featureBitCount
+ 7)/8;
108 return kHIDInvalidReportTypeErr
;
110 if (iExpectedLength
> iReportLength
)
111 return kHIDInvalidReportLengthErr
;