]> git.saurik.com Git - apple/xnu.git/blob - iokit/Families/IOHIDSystem/IOHIDDescriptorParser/HIDGetReportLength.c
010dcf6df5dace8131ebf4cafe25e16ad72d7d81
[apple/xnu.git] / iokit / Families / IOHIDSystem / IOHIDDescriptorParser / HIDGetReportLength.c
1 /*
2 * Copyright (c) 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: HIDGetReportLength.c
24
25 Contains: xxx put contents here xxx
26
27 Version: xxx put version here xxx
28
29 Copyright: © 2000 by Apple Computer, Inc., all rights reserved.
30
31 File Ownership:
32
33 DRI: David Ferguson
34
35 Other Contact: Keithen Hayenga
36
37 Technology: technologies, usb
38
39 Writers:
40
41
42 Change History (most recent first):
43
44 */
45
46 #include "HIDLib.h"
47
48 /*
49 *------------------------------------------------------------------------------
50 *
51 * HIDGetReportLength - Get the length of a report
52 *
53 * Input:
54 * reportType - HIDP_Input, HIDP_Output, HIDP_Feature
55 * reportID - Desired Report
56 * preparsedDataRef - opaque Pre-Parsed Data
57 * Output:
58 * reportLength - The length of the Report
59 * Returns:
60 * status kHIDNullPointerErr, kHIDInvalidPreparsedDataErr,
61 * kHIDUsageNotFoundErr
62 *
63 *------------------------------------------------------------------------------
64 */
65 OSStatus HIDGetReportLength(HIDReportType reportType,
66 UInt8 reportID,
67 ByteCount * reportLength,
68 HIDPreparsedDataRef preparsedDataRef)
69 {
70 HIDPreparsedDataPtr ptPreparsedData = (HIDPreparsedDataPtr)preparsedDataRef;
71 ByteCount dataLength = 0;
72 OSStatus iStatus = kHIDUsageNotFoundErr;
73 int iR;
74
75 // Disallow Null Pointers.
76
77 if (ptPreparsedData == NULL || reportLength == NULL)
78 return kHIDNullPointerErr;
79 if (ptPreparsedData->hidTypeIfValid != kHIDOSType)
80 return kHIDInvalidPreparsedDataErr;
81
82 // Go through the Reports.
83
84 for (iR = 0; iR < ptPreparsedData->reportCount; iR++)
85 {
86 if (ptPreparsedData->reports[iR].reportID == reportID)
87 {
88 switch(reportType)
89 {
90 case kHIDInputReport:
91 dataLength = (ptPreparsedData->reports[iR].inputBitCount + 7)/8;
92 break;
93 case kHIDOutputReport:
94 dataLength = (ptPreparsedData->reports[iR].outputBitCount + 7)/8;
95 break;
96 case kHIDFeatureReport:
97 dataLength = (ptPreparsedData->reports[iR].featureBitCount + 7)/8;
98 break;
99 default:
100 return kHIDInvalidReportTypeErr;
101 }
102 break;
103 }
104 }
105
106 // If the reportID > 0, there must be 1 byte for reportID, so total report must be > 1.
107 // (Would come into play if we had input report 3, but searched for ouput report 3
108 // that didn't exist.)
109
110 if ((reportID == 0) && (dataLength > 0) || dataLength > 1)
111 {
112 iStatus = noErr;
113 }
114 else
115 {
116 dataLength = 0; // Ignore report that had id, but no data.
117 }
118
119 *reportLength = dataLength;
120
121 return iStatus;
122 }