Annotation of XNU/iokit/Families/IOHIDSystem/IOHIDDescriptorParser/HIDOpenCloseDescriptor.c, revision 1.1

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:           HIDOpenCloseDescriptor.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:          <USB2>         3/17/99        BWS             [2314839]  Added flags field to HIDPreparsedData which is set in
        !            46:                                                                        new parameter to HIDOpenReportDescriptor
        !            47:          <USB1>          3/5/99        BWS             first checked in
        !            48: */
        !            49: 
        !            50: #include "HIDLib.h"
        !            51: 
        !            52: //#include <stdlib.h>
        !            53: 
        !            54: /*
        !            55:  *------------------------------------------------------------------------------
        !            56:  *
        !            57:  * HIDCloseReportDescriptor - Close the Descriptor
        !            58:  *
        !            59:  *      Input:
        !            60:  *                       ptPreparsedData               - The PreParsedData Structure
        !            61:  *      Output:
        !            62:  *                       ptPreparsedData               - The PreParsedData Structure
        !            63:  *      Returns:
        !            64:  *                       kHIDSuccess              - Success
        !            65:  *                       kHIDNullPointerErr      - Argument, Pointer was Null
        !            66:  *
        !            67:  *------------------------------------------------------------------------------
        !            68: */
        !            69: OSStatus HIDCloseReportDescriptor(HIDPreparsedDataRef preparsedDataRef)
        !            70: {
        !            71:        HIDPreparsedDataPtr ptPreparsedData = (HIDPreparsedDataPtr) preparsedDataRef;
        !            72:        OSStatus iStatus;
        !            73: /*
        !            74:  *     Disallow NULL Pointers
        !            75: */
        !            76:        if (ptPreparsedData == NULL)
        !            77:                return kHIDNullPointerErr;
        !            78: /*
        !            79:  *     If it's marked closed then don't do anything
        !            80: */
        !            81:        if (ptPreparsedData->hidTypeIfValid != kHIDOSType)
        !            82:                return kHIDInvalidPreparsedDataErr;
        !            83: /*
        !            84:  *     Free any memory that was allocated
        !            85: */
        !            86:        if (ptPreparsedData->rawMemPtr != NULL)
        !            87:        {
        !            88:                PoolDeallocate (ptPreparsedData->rawMemPtr, ptPreparsedData->numBytesAllocated);
        !            89:                ptPreparsedData->rawMemPtr = NULL;
        !            90:        }
        !            91: /*
        !            92:  *     Mark closed
        !            93: */
        !            94:        ptPreparsedData->hidTypeIfValid = 0;
        !            95: /*
        !            96:  *     Deallocate the preparsed data
        !            97: */
        !            98:        iStatus = PoolDeallocate (ptPreparsedData, sizeof(HIDPreparsedData));
        !            99: 
        !           100:        return iStatus;
        !           101: }
        !           102: 
        !           103: /*
        !           104:  *------------------------------------------------------------------------------
        !           105:  *
        !           106:  * HIDOpenReportDescriptor - Initialize the HID Parser
        !           107:  *
        !           108:  *      Input:
        !           109:  *                       psHidReportDescriptor - The HID Report Descriptor (String)
        !           110:  *                       descriptorLength         - Length of the Descriptor in bytes
        !           111:  *                       ptPreparsedData               - The PreParsedData Structure
        !           112:  *      Output:
        !           113:  *                       ptPreparsedData               - The PreParsedData Structure
        !           114:  *      Returns:
        !           115:  *                       kHIDSuccess              - Success
        !           116:  *                       kHIDNullPointerErr      - Argument, Pointer was Null
        !           117:  *
        !           118:  *------------------------------------------------------------------------------
        !           119: */
        !           120: OSStatus
        !           121: HIDOpenReportDescriptor           (void *                                      hidReportDescriptor,
        !           122:                                                        UInt32                                  descriptorLength,
        !           123:                                                        HIDPreparsedDataRef *   preparsedDataRef,
        !           124:                                                        UInt32                                  flags)
        !           125: {
        !           126:        HIDPreparsedDataPtr ptPreparsedData = (HIDPreparsedDataPtr) preparsedDataRef;
        !           127:        OSStatus iStatus;
        !           128:        HIDReportDescriptor tDescriptor;
        !           129: 
        !           130: /*
        !           131:  *     Disallow NULL Pointers
        !           132: */
        !           133:        if ((hidReportDescriptor == NULL) || (preparsedDataRef == NULL))
        !           134:                return kHIDNullPointerErr;
        !           135:        
        !           136: /*
        !           137:  *     Initialize the return result, and allocate space for preparsed data
        !           138: */
        !           139:        *preparsedDataRef = NULL;
        !           140:        
        !           141:        ptPreparsedData = PoolAllocateResident (sizeof (HIDPreparsedData), kShouldClearMem);
        !           142:        
        !           143: /*
        !           144:  *     Make sure we got the memory
        !           145: */
        !           146:        if (ptPreparsedData == NULL)
        !           147:                return kHIDNotEnoughMemoryErr;
        !           148: 
        !           149: /*
        !           150:  *     Copy the flags field
        !           151: */
        !           152:        ptPreparsedData->flags = flags;
        !           153: /*
        !           154:  *     Initialize the memory allocation pointer
        !           155: */
        !           156:        ptPreparsedData->rawMemPtr = NULL;
        !           157: /*
        !           158:  *     Set up the descriptor structure
        !           159: */
        !           160:        tDescriptor.descriptor = hidReportDescriptor;
        !           161:        tDescriptor.descriptorLength = descriptorLength;
        !           162: /*
        !           163:  *     Count various items in the descriptor
        !           164:  *       allocate space within the PreparsedData structure
        !           165:  *       and initialize the counters there
        !           166: */
        !           167:        iStatus = HIDCountDescriptorItems(&tDescriptor,ptPreparsedData);
        !           168:        if (iStatus != kHIDSuccess)
        !           169:                return iStatus;
        !           170: /*
        !           171:  *     Parse the Descriptor
        !           172:  *       filling in the structures in the PreparsedData structure
        !           173: */
        !           174:        iStatus = HIDParseDescriptor(&tDescriptor,ptPreparsedData);
        !           175: /*
        !           176:  *     Mark the PreparsedData initialized, maybe
        !           177: */
        !           178:        if (iStatus == kHIDSuccess && ptPreparsedData->rawMemPtr != NULL)
        !           179:        {
        !           180:                ptPreparsedData->hidTypeIfValid = kHIDOSType;
        !           181:                *preparsedDataRef = (HIDPreparsedDataRef) ptPreparsedData;
        !           182:        }
        !           183:        else    // something failed, deallocate everything, and make sure we return an error
        !           184:        {
        !           185:                if (ptPreparsedData->rawMemPtr != NULL)
        !           186:                        PoolDeallocate (ptPreparsedData->rawMemPtr, ptPreparsedData->numBytesAllocated);
        !           187:                        
        !           188:                PoolDeallocate (ptPreparsedData, sizeof(HIDPreparsedData));
        !           189:                
        !           190:                if (iStatus == kHIDSuccess)
        !           191:                        iStatus = kHIDNotEnoughMemoryErr;
        !           192:        }
        !           193:        
        !           194:        return iStatus;
        !           195: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.