]> git.saurik.com Git - apple/xnu.git/blob - iokit/Families/IOHIDSystem/IOHIDDescriptorParser/HIDCheckReport.c
ca7be8202b957142c82dcbb3d2db0fdb054eb4d5
[apple/xnu.git] / iokit / Families / IOHIDSystem / IOHIDDescriptorParser / HIDCheckReport.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: HIDCheckReport.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 (DF) David Ferguson
42 (KH) Keithen Hayenga
43 (BWS) Brent Schorsch
44
45 Change History (most recent first):
46
47 <USB3> 1/2/01 DF Change length checking to check for the minimum size instead of
48 the "exact" size.
49 <USB2> 12/12/00 KH Correcting cast of void *
50 <USB1> 3/5/99 BWS first checked in
51 */
52
53 #include "HIDLib.h"
54
55 /*
56 *------------------------------------------------------------------------------
57 *
58 * HIDCheckReport - Check the Report ID, Type, and Length
59 *
60 * Input:
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
66 * Output:
67 * Returns:
68 * kHIDSuccess, HidP_IncompatibleReportID,
69 * kHIDInvalidReportLengthErr, kHIDInvalidReportTypeErr
70 *
71 *------------------------------------------------------------------------------
72 */
73 OSStatus HIDCheckReport(HIDReportType reportType, HIDPreparsedDataRef preparsedDataRef,
74 HIDReportItem *ptReportItem, void *report, UInt32 iReportLength)
75 {
76 HIDPreparsedDataPtr ptPreparsedData = (HIDPreparsedDataPtr) preparsedDataRef;
77 int reportID, reportIndex;
78 int iExpectedLength;
79 Byte * psReport = (Byte *)report;
80 /*
81 * See if this is the correct Report ID
82 */
83 reportID = psReport[0]&0xFF;
84 if ((ptPreparsedData->reportCount > 1)
85 && (reportID != ptReportItem->globals.reportID))
86 return kHIDIncompatibleReportErr;
87 /*
88 * See if this is the correct ReportType
89 */
90 if (reportType != ptReportItem->reportType)
91 return kHIDIncompatibleReportErr;
92 /*
93 * Check for the correct Length for the Type
94 */
95 reportIndex = ptReportItem->globals.reportIndex;
96 switch(reportType)
97 {
98 case kHIDInputReport:
99 iExpectedLength = (ptPreparsedData->reports[reportIndex].inputBitCount + 7)/8;
100 break;
101 case kHIDOutputReport:
102 iExpectedLength = (ptPreparsedData->reports[reportIndex].outputBitCount + 7)/8;
103 break;
104 case kHIDFeatureReport:
105 iExpectedLength = (ptPreparsedData->reports[reportIndex].featureBitCount + 7)/8;
106 break;
107 default:
108 return kHIDInvalidReportTypeErr;
109 }
110 if (iExpectedLength > iReportLength)
111 return kHIDInvalidReportLengthErr;
112 return kHIDSuccess;
113 }