1/* 2 * @APPLE_LICENSE_HEADER_START@ 3 * 4 * Copyright (c) 1999-2012 Apple Computer, Inc. All Rights Reserved. 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23/* 24 File: HIDCheckReport.c 25 26 Contains: xxx put contents here xxx 27 28 Version: xxx put version here xxx 29 30 Copyright: � 1999-2001 by Apple Computer, Inc., all rights reserved. 31 32 File Ownership: 33 34 DRI: xxx put dri here xxx 35 36 Other Contact: xxx put other contact here xxx 37 38 Technology: xxx put technology here xxx 39 40 Writers: 41 42 (DF) David Ferguson 43 (KH) Keithen Hayenga 44 (BWS) Brent Schorsch 45 46 Change History (most recent first): 47 48 <USB3> 1/2/01 DF Change length checking to check for the minimum size instead of 49 the "exact" size. 50 <USB2> 12/12/00 KH Correcting cast of void * 51 <USB1> 3/5/99 BWS first checked in 52*/ 53 54#include "HIDLib.h" 55 56/* 57 *------------------------------------------------------------------------------ 58 * 59 * HIDCheckReport - Check the Report ID, Type, and Length 60 * 61 * Input: 62 * reportType - The Specified Report Type 63 * ptPreparsedData - The Preparsed Data 64 * ptReportItem - The Report Item 65 * psReport - The Report 66 * iReportLength - The Report Length 67 * Output: 68 * Returns: 69 * kHIDSuccess, HidP_IncompatibleReportID, 70 * kHIDInvalidReportLengthErr, kHIDInvalidReportTypeErr 71 * 72 *------------------------------------------------------------------------------ 73*/ 74OSStatus HIDCheckReport(HIDReportType reportType, HIDPreparsedDataRef preparsedDataRef, 75 HIDReportItem *ptReportItem, void *report, IOByteCount iReportLength) 76{ 77 HIDPreparsedDataPtr ptPreparsedData = (HIDPreparsedDataPtr) preparsedDataRef; 78 int reportID, reportIndex; 79 int iExpectedLength; 80 UInt8 * psReport = (UInt8 *)report; 81/* 82 * See if this is the correct Report ID 83*/ 84 reportID = psReport[0]&0xFF; 85 if ((ptPreparsedData->reportCount > 1) 86 && (reportID != ptReportItem->globals.reportID)) 87 return kHIDIncompatibleReportErr; 88/* 89 * See if this is the correct ReportType 90*/ 91 if (reportType != ptReportItem->reportType) 92 return kHIDIncompatibleReportErr; 93/* 94 * Check for the correct Length for the Type 95*/ 96 reportIndex = ptReportItem->globals.reportIndex; 97 switch(reportType) 98 { 99 case kHIDInputReport: 100 iExpectedLength = (ptPreparsedData->reports[reportIndex].inputBitCount + 7)/8; 101 break; 102 case kHIDOutputReport: 103 iExpectedLength = (ptPreparsedData->reports[reportIndex].outputBitCount + 7)/8; 104 break; 105 case kHIDFeatureReport: 106 iExpectedLength = (ptPreparsedData->reports[reportIndex].featureBitCount + 7)/8; 107 break; 108 default: 109 return kHIDInvalidReportTypeErr; 110 } 111 if (iExpectedLength > iReportLength) 112 return kHIDInvalidReportLengthErr; 113 return kHIDSuccess; 114} 115