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: HIDParseDescriptor.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 <USB1> 3/5/99 BWS first checked in
52 *------------------------------------------------------------------------------
54 * HIDParseDescriptor - Fill in the PreparsedData structures
57 * ptDescriptor - Descriptor Pointer Structure
58 * ptPreparsedData - The PreParsedData Structure
60 * ptPreparsedData - The PreParsedData Structure
62 * kHIDSuccess - Success
63 * kHIDNullPointerErr - Argument, Pointer was Null
65 * NOTE: HIDCountDescriptorItems MUST have been called to set up the
66 * array pointers in the HIDPreparsedData structure!
68 *------------------------------------------------------------------------------
70 OSStatus
HIDParseDescriptor(HIDReportDescriptor
*ptDescriptor
, HIDPreparsedDataPtr ptPreparsedData
)
74 HIDCollection
*ptCollection
;
75 HIDReportSizes
*ptReport
;
77 * Disallow NULL Pointers
79 if ((ptDescriptor
== NULL
) || (ptPreparsedData
== NULL
))
80 return kHIDNullPointerErr
;
84 ptPreparsedData
->collectionCount
= 1;
85 ptPreparsedData
->reportItemCount
= 0;
86 ptPreparsedData
->reportCount
= 1;
87 ptPreparsedData
->usageItemCount
= 0;
88 ptPreparsedData
->stringItemCount
= 0;
89 ptPreparsedData
->desigItemCount
= 0;
91 * Initialize the Descriptor Data
93 ptDescriptor
->index
= 0;
94 ptDescriptor
->collectionNesting
= 0;
95 ptDescriptor
->globalsNesting
= 0;
96 ptDescriptor
->firstUsageItem
= 0;
97 ptDescriptor
->firstStringItem
= 0;
98 ptDescriptor
->firstDesigItem
= 0;
99 ptDescriptor
->parent
= 0;
100 ptDescriptor
->sibling
= 0;
101 ptDescriptor
->globals
.usagePage
= 0;
102 ptDescriptor
->globals
.logicalMinimum
= 0;
103 ptDescriptor
->globals
.logicalMaximum
= 0;
104 ptDescriptor
->globals
.physicalMinimum
= 0;
105 ptDescriptor
->globals
.physicalMaximum
= 0;
106 ptDescriptor
->globals
.unitExponent
= 0;
107 ptDescriptor
->globals
.units
= 0;
108 ptDescriptor
->globals
.reportSize
= 0;
109 ptDescriptor
->globals
.reportID
= 0;
110 ptDescriptor
->globals
.reportCount
= 0;
111 ptDescriptor
->globals
.reportIndex
= 0;
112 ptDescriptor
->haveUsageMin
= false;
113 ptDescriptor
->haveUsageMax
= false;
114 ptDescriptor
->haveStringMin
= false;
115 ptDescriptor
->haveStringMax
= false;
116 ptDescriptor
->haveDesigMin
= false;
117 ptDescriptor
->haveDesigMax
= false;
118 ptItem
= &ptDescriptor
->item
;
120 * Initialize the virtual collection
122 ptCollection
= ptPreparsedData
->collections
;
123 ptCollection
->data
= 0;
124 ptCollection
->usagePage
= 0;
125 ptCollection
->firstUsageItem
= 0;
126 ptCollection
->usageItemCount
= 0;
127 ptCollection
->firstReportItem
= 0;
128 ptCollection
->reportItemCount
= 0;
129 ptCollection
->parent
= 0;
130 ptCollection
->children
= 0;
131 ptCollection
->firstChild
= 0;
132 ptCollection
->nextSibling
= 0;
134 * Initialize the default report
136 ptReport
= ptPreparsedData
->reports
;
137 ptReport
->reportID
= 0;
138 ptReport
->inputBitCount
= 0;
139 ptReport
->outputBitCount
= 0;
140 ptReport
->featureBitCount
= 0;
143 * Parse the Descriptor
145 while ((iStatus
= HIDNextItem(ptDescriptor
)) == kHIDSuccess
)
147 switch (ptItem
->itemType
)
150 iStatus
= HIDProcessMainItem(ptDescriptor
,ptPreparsedData
);
153 iStatus
= HIDProcessGlobalItem(ptDescriptor
,ptPreparsedData
);
156 iStatus
= HIDProcessLocalItem(ptDescriptor
,ptPreparsedData
);
159 if (iStatus
!= kHIDSuccess
)
162 if (iStatus
== kHIDEndOfDescriptorErr
)
163 iStatus
= kHIDSuccess
;
165 * Update the virtual collection
167 ptCollection
= ptPreparsedData
->collections
;
168 ptCollection
->reportItemCount
= ptPreparsedData
->reportItemCount
;
170 * Mark the PreparsedData initialized