2 * Copyright (c) 1998-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: HIDOpenCloseDescriptor.c
25 Contains: xxx put contents here xxx
27 Version: xxx put version here xxx
29 Copyright: © 1999 by Apple Computer, Inc., all rights reserved.
33 DRI: xxx put dri here xxx
35 Other Contact: xxx put other contact here xxx
37 Technology: xxx put technology here xxx
43 Change History (most recent first):
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
55 *------------------------------------------------------------------------------
57 * HIDCloseReportDescriptor - Close the Descriptor
60 * ptPreparsedData - The PreParsedData Structure
62 * ptPreparsedData - The PreParsedData Structure
64 * kHIDSuccess - Success
65 * kHIDNullPointerErr - Argument, Pointer was Null
67 *------------------------------------------------------------------------------
69 OSStatus
HIDCloseReportDescriptor(HIDPreparsedDataRef preparsedDataRef
)
71 HIDPreparsedDataPtr ptPreparsedData
= (HIDPreparsedDataPtr
) preparsedDataRef
;
74 * Disallow NULL Pointers
76 if (ptPreparsedData
== NULL
)
77 return kHIDNullPointerErr
;
79 * If it's marked closed then don't do anything
81 if (ptPreparsedData
->hidTypeIfValid
!= kHIDOSType
)
82 return kHIDInvalidPreparsedDataErr
;
84 * Free any memory that was allocated
86 if (ptPreparsedData
->rawMemPtr
!= NULL
)
88 PoolDeallocate (ptPreparsedData
->rawMemPtr
, ptPreparsedData
->numBytesAllocated
);
89 ptPreparsedData
->rawMemPtr
= NULL
;
94 ptPreparsedData
->hidTypeIfValid
= 0;
96 * Deallocate the preparsed data
98 iStatus
= PoolDeallocate (ptPreparsedData
, sizeof(HIDPreparsedData
));
104 *------------------------------------------------------------------------------
106 * HIDOpenReportDescriptor - Initialize the HID Parser
109 * psHidReportDescriptor - The HID Report Descriptor (String)
110 * descriptorLength - Length of the Descriptor in bytes
111 * ptPreparsedData - The PreParsedData Structure
113 * ptPreparsedData - The PreParsedData Structure
115 * kHIDSuccess - Success
116 * kHIDNullPointerErr - Argument, Pointer was Null
118 *------------------------------------------------------------------------------
121 HIDOpenReportDescriptor (void * hidReportDescriptor
,
122 UInt32 descriptorLength
,
123 HIDPreparsedDataRef
* preparsedDataRef
,
126 HIDPreparsedDataPtr ptPreparsedData
= (HIDPreparsedDataPtr
) preparsedDataRef
;
128 HIDReportDescriptor tDescriptor
;
131 * Disallow NULL Pointers
133 if ((hidReportDescriptor
== NULL
) || (preparsedDataRef
== NULL
))
134 return kHIDNullPointerErr
;
137 * Initialize the return result, and allocate space for preparsed data
139 *preparsedDataRef
= NULL
;
141 ptPreparsedData
= PoolAllocateResident (sizeof (HIDPreparsedData
), kShouldClearMem
);
144 * Make sure we got the memory
146 if (ptPreparsedData
== NULL
)
147 return kHIDNotEnoughMemoryErr
;
150 * Copy the flags field
152 ptPreparsedData
->flags
= flags
;
154 * Initialize the memory allocation pointer
156 ptPreparsedData
->rawMemPtr
= NULL
;
158 * Set up the descriptor structure
160 tDescriptor
.descriptor
= hidReportDescriptor
;
161 tDescriptor
.descriptorLength
= descriptorLength
;
163 * Count various items in the descriptor
164 * allocate space within the PreparsedData structure
165 * and initialize the counters there
167 iStatus
= HIDCountDescriptorItems(&tDescriptor
,ptPreparsedData
);
168 if (iStatus
!= kHIDSuccess
)
171 * Parse the Descriptor
172 * filling in the structures in the PreparsedData structure
174 iStatus
= HIDParseDescriptor(&tDescriptor
,ptPreparsedData
);
176 * Mark the PreparsedData initialized, maybe
178 if (iStatus
== kHIDSuccess
&& ptPreparsedData
->rawMemPtr
!= NULL
)
180 ptPreparsedData
->hidTypeIfValid
= kHIDOSType
;
181 *preparsedDataRef
= (HIDPreparsedDataRef
) ptPreparsedData
;
183 else // something failed, deallocate everything, and make sure we return an error
185 if (ptPreparsedData
->rawMemPtr
!= NULL
)
186 PoolDeallocate (ptPreparsedData
->rawMemPtr
, ptPreparsedData
->numBytesAllocated
);
188 PoolDeallocate (ptPreparsedData
, sizeof(HIDPreparsedData
));
190 if (iStatus
== kHIDSuccess
)
191 iStatus
= kHIDNotEnoughMemoryErr
;