|
|
1.1 root 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 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: (BWS) Brent Schorsch
42:
43: Change History (most recent first):
44:
45: <USB1> 3/5/99 BWS first checked in
46: */
47:
48: #include "HIDLib.h"
49:
50: /*
51: *------------------------------------------------------------------------------
52: *
53: * HIDCheckReport - Check the Report ID, Type, and Length
54: *
55: * Input:
56: * reportType - The Specified Report Type
57: * ptPreparsedData - The Preparsed Data
58: * ptReportItem - The Report Item
59: * psReport - The Report
60: * iReportLength - The Report Length
61: * Output:
62: * Returns:
63: * kHIDSuccess, HidP_IncompatibleReportID,
64: * kHIDInvalidReportLengthErr, kHIDInvalidReportTypeErr
65: *
66: *------------------------------------------------------------------------------
67: */
68: OSStatus HIDCheckReport(HIDReportType reportType, HIDPreparsedDataRef preparsedDataRef,
69: HIDReportItem *ptReportItem, void *report, UInt32 iReportLength)
70: {
71: HIDPreparsedDataPtr ptPreparsedData = (HIDPreparsedDataPtr) preparsedDataRef;
72: int reportID, reportIndex;
73: int iExpectedLength;
74: Byte * psReport = report;
75: /*
76: * See if this is the correct Report ID
77: */
78: reportID = psReport[0]&0xFF;
79: if ((ptPreparsedData->reportCount > 1)
80: && (reportID != ptReportItem->globals.reportID))
81: return kHIDIncompatibleReportErr;
82: /*
83: * Check for the correct Length for the Type
84: */
85: reportIndex = ptReportItem->globals.reportIndex;
86: switch(reportType)
87: {
88: case kHIDInputReport:
89: iExpectedLength = (ptPreparsedData->reports[reportIndex].inputBitCount + 7)/8;
90: break;
91: case kHIDOutputReport:
92: iExpectedLength = (ptPreparsedData->reports[reportIndex].outputBitCount + 7)/8;
93: break;
94: case kHIDFeatureReport:
95: iExpectedLength = (ptPreparsedData->reports[reportIndex].featureBitCount + 7)/8;
96: break;
97: default:
98: return kHIDInvalidReportTypeErr;
99: }
100: if (iExpectedLength != iReportLength)
101: return kHIDInvalidReportLengthErr;
102: if (reportType != ptReportItem->reportType)
103: return kHIDIncompatibleReportErr;
104: return kHIDSuccess;
105: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.