2 * Copyright (c) 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: HIDGetReportLength.c
25 Contains: xxx put contents here xxx
27 Version: xxx put version here xxx
29 Copyright: © 2000 by Apple Computer, Inc., all rights reserved.
35 Other Contact: Keithen Hayenga
37 Technology: technologies, usb
42 Change History (most recent first):
49 *------------------------------------------------------------------------------
51 * HIDGetReportLength - Get the length of a report
54 * reportType - HIDP_Input, HIDP_Output, HIDP_Feature
55 * reportID - Desired Report
56 * preparsedDataRef - opaque Pre-Parsed Data
58 * reportLength - The length of the Report
60 * status kHIDNullPointerErr, kHIDInvalidPreparsedDataErr,
61 * kHIDUsageNotFoundErr
63 *------------------------------------------------------------------------------
65 OSStatus
HIDGetReportLength(HIDReportType reportType
,
67 ByteCount
* reportLength
,
68 HIDPreparsedDataRef preparsedDataRef
)
70 HIDPreparsedDataPtr ptPreparsedData
= (HIDPreparsedDataPtr
)preparsedDataRef
;
71 ByteCount dataLength
= 0;
72 OSStatus iStatus
= kHIDUsageNotFoundErr
;
75 // Disallow Null Pointers.
77 if (ptPreparsedData
== NULL
|| reportLength
== NULL
)
78 return kHIDNullPointerErr
;
79 if (ptPreparsedData
->hidTypeIfValid
!= kHIDOSType
)
80 return kHIDInvalidPreparsedDataErr
;
82 // Go through the Reports.
84 for (iR
= 0; iR
< ptPreparsedData
->reportCount
; iR
++)
86 if (ptPreparsedData
->reports
[iR
].reportID
== reportID
)
91 dataLength
= (ptPreparsedData
->reports
[iR
].inputBitCount
+ 7)/8;
93 case kHIDOutputReport
:
94 dataLength
= (ptPreparsedData
->reports
[iR
].outputBitCount
+ 7)/8;
96 case kHIDFeatureReport
:
97 dataLength
= (ptPreparsedData
->reports
[iR
].featureBitCount
+ 7)/8;
100 return kHIDInvalidReportTypeErr
;
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.)
110 if ((reportID
== 0) && (dataLength
> 0) || dataLength
> 1)
116 dataLength
= 0; // Ignore report that had id, but no data.
119 *reportLength
= dataLength
;