[USB-BRINGUP]
[reactos.git] / lib / drivers / hidparser / parser.h
1
2 #pragma once
3 #include <ntddk.h>
4 #include <assert.h>
5 #include <pshpack1.h>
6 #include "hidparser.h"
7 #include <ntddkbd.h>
8
9 /*
10 * Copyright 2007, Haiku, Inc. All Rights Reserved.
11 * Distributed under the terms of the MIT License.
12 */
13
14 #define HID_REPORT_TYPE_ANY 0x07
15
16
17 #define ITEM_TYPE_MAIN 0x0
18 #define ITEM_TYPE_GLOBAL 0x1
19 #define ITEM_TYPE_LOCAL 0x2
20 #define ITEM_TYPE_LONG 0x3
21
22 #define ITEM_TAG_MAIN_INPUT 0x8
23 #define ITEM_TAG_MAIN_OUTPUT 0x9
24 #define ITEM_TAG_MAIN_FEATURE 0xb
25 #define ITEM_TAG_MAIN_COLLECTION 0xa
26 #define ITEM_TAG_MAIN_END_COLLECTION 0xc
27
28 #define ITEM_TAG_GLOBAL_USAGE_PAGE 0x0
29 #define ITEM_TAG_GLOBAL_LOGICAL_MINIMUM 0x1
30 #define ITEM_TAG_GLOBAL_LOGICAL_MAXIMUM 0x2
31 #define ITEM_TAG_GLOBAL_PHYSICAL_MINIMUM 0x3
32 #define ITEM_TAG_GLOBAL_PHYSICAL_MAXIMUM 0x4
33 #define ITEM_TAG_GLOBAL_UNIT_EXPONENT 0x5
34 #define ITEM_TAG_GLOBAL_UNIT 0x6
35 #define ITEM_TAG_GLOBAL_REPORT_SIZE 0x7
36 #define ITEM_TAG_GLOBAL_REPORT_ID 0x8
37 #define ITEM_TAG_GLOBAL_REPORT_COUNT 0x9
38 #define ITEM_TAG_GLOBAL_PUSH 0xa
39 #define ITEM_TAG_GLOBAL_POP 0xb
40
41 #define ITEM_TAG_LOCAL_USAGE 0x0
42 #define ITEM_TAG_LOCAL_USAGE_MINIMUM 0x1
43 #define ITEM_TAG_LOCAL_USAGE_MAXIMUM 0x2
44 #define ITEM_TAG_LOCAL_DESIGNATOR_INDEX 0x3
45 #define ITEM_TAG_LOCAL_DESIGNATOR_MINIMUM 0x4
46 #define ITEM_TAG_LOCAL_DESIGNATOR_MAXIMUM 0x5
47 #define ITEM_TAG_LOCAL_STRING_INDEX 0x7
48 #define ITEM_TAG_LOCAL_STRING_MINIMUM 0x8
49 #define ITEM_TAG_LOCAL_STRING_MAXIMUM 0x9
50 #define ITEM_TAG_LOCAL_DELIMITER 0xa
51
52 #define ITEM_TAG_LONG 0xf
53
54 #define COLLECTION_PHYSICAL 0x00
55 #define COLLECTION_APPLICATION 0x01
56 #define COLLECTION_LOGICAL 0x02
57 #define COLLECTION_REPORT 0x03
58 #define COLLECTION_NAMED_ARRAY 0x04
59 #define COLLECTION_USAGE_SWITCH 0x05
60 #define COLLECTION_USAGE_MODIFIER 0x06
61 #define COLLECTION_ALL 0xff
62
63 #define UNIT_SYSTEM 0x0
64 #define UNIT_LENGTH 0x1
65 #define UNIT_MASS 0x2
66 #define UNIT_TIME 0x3
67 #define UNIT_TEMPERATURE 0x4
68 #define UNIT_CURRENT 0x5
69 #define UNIT_LUMINOUS_INTENSITY 0x6
70
71 #define USAGE_PAGE_SHIFT 16
72 #define USAGE_PAGE_MASK 0xffff
73 #define USAGE_ID_SHIFT 0
74 #define USAGE_ID_MASK 0xffff
75
76 typedef struct
77 {
78 UCHAR Size:2;
79 UCHAR Type:2;
80 UCHAR Tag:4;
81 }ITEM_PREFIX, *PITEM_PREFIX;
82
83 typedef struct
84 {
85 ITEM_PREFIX Prefix;
86
87 union
88 {
89 UCHAR UData8[4];
90 CHAR SData8[4];
91 USHORT UData16[2];
92 SHORT SData16[2];
93 ULONG UData32;
94 LONG SData32;
95 }Data;
96
97 }SHORT_ITEM, *PSHORT_ITEM;
98
99 typedef struct
100 {
101 ITEM_PREFIX Prefix;
102 UCHAR DataSize;
103 UCHAR LongItemTag;
104 UCHAR Data[0];
105
106 }LONG_ITEM,*PLONG_ITEM;
107
108
109 #define LBITFIELD9(b1,b2,b3,b4,b5,b6,b7,b8,b9) USHORT b9,b8,b7,b6,b5,b4,b3,b2,b1
110 typedef struct
111 {
112 USHORT DataConstant:1;
113 USHORT ArrayVariable:1;
114 USHORT Relative:1;
115 USHORT Wrap:1;
116 USHORT NonLinear:1;
117 USHORT NoPreferred:1;
118 USHORT NullState:1;
119 USHORT IsVolatile:1;
120 USHORT BitsBytes:1;
121 UCHAR reserved[2];
122
123 }MAIN_ITEM_DATA, *PMAIN_ITEM_DATA;
124
125 typedef struct __GLOBAL_ITEM_STATE_
126 {
127 USHORT UsagePage;
128 ULONG LogicalMinimum;
129 ULONG LogicialMaximum;
130 ULONG PhysicalMinimum;
131 ULONG PhysicalMaximum;
132 UCHAR UnitExponent;
133 UCHAR Unit;
134 ULONG ReportSize;
135 ULONG ReportCount;
136 UCHAR ReportId;
137 struct __GLOBAL_ITEM_STATE__ * Next;
138 }GLOBAL_ITEM_STATE, *PGLOBAL_ITEM_STATE;
139
140
141 typedef struct usage_value
142 {
143 union
144 {
145 struct {
146 USHORT UsageId;
147 USHORT UsagePage;
148 }s;
149 ULONG Extended;
150 }u;
151
152 UCHAR IsExtended;
153 }USAGE_VALUE, *PUSAGE_VALUE;
154
155
156 typedef struct
157 {
158 PUSAGE_VALUE UsageStack;
159 ULONG UsageStackUsed;
160 ULONG UsageStackAllocated;
161
162 USAGE_VALUE UsageMinimum;
163 USAGE_VALUE UsageMaximum;
164
165 UCHAR UsageMinimumSet;
166 UCHAR UsageMaximumSet;
167
168 ULONG DesignatorIndex;
169 UCHAR DesignatorIndexSet;
170
171 ULONG DesignatorMinimum;
172 ULONG DesignatorMaximum;
173
174 UCHAR StringIndex;
175 UCHAR StringIndexSet;
176 UCHAR StringMinimum;
177 UCHAR StringMaximum;
178
179 }LOCAL_ITEM_STATE, *PLOCAL_ITEM_STATE;
180
181 typedef struct
182 {
183 ULONG ByteOffset;
184 UCHAR Shift;
185 ULONG Mask;
186 UCHAR BitCount;
187 UCHAR HasData;
188 UCHAR Array;
189 UCHAR Relative;
190 ULONG Minimum;
191 ULONG Maximum;
192 ULONG UsageMinimum;
193 ULONG UsageMaximum;
194 ULONG Data;
195 UCHAR Valid;
196 }HID_REPORT_ITEM, *PHID_REPORT_ITEM;
197
198 struct HID_REPORT;
199
200 typedef struct __HID_COLLECTION__
201 {
202 struct __HID_COLLECTION__ * Root;
203
204 UCHAR Type;
205 ULONG Usage;
206 UCHAR StringID;
207 UCHAR PhysicalID;
208 ULONG NodeCount;
209 struct __HID_COLLECTION__ ** Nodes;
210
211 ULONG ItemCount;
212 ULONG ItemCountAllocated;
213 PHID_REPORT_ITEM * Items;
214
215 //ULONG ReportCount;
216 //struct HID_REPORT ** Reports;
217
218 }HID_COLLECTION, *PHID_COLLECTION;
219
220 typedef struct
221 {
222 UCHAR Type;
223 UCHAR ReportID;
224 ULONG ReportSize;
225
226 ULONG ItemCount;
227 ULONG ItemAllocated;
228 PHID_REPORT_ITEM *Items;
229
230 ULONG ReportStatus;
231 UCHAR * CurrentReport;
232 ULONG BusyCount;
233 }HID_REPORT, *PHID_REPORT;
234
235 typedef struct
236 {
237 //
238 // global item state
239 //
240 GLOBAL_ITEM_STATE GlobalItemState;
241
242 //
243 // local item state
244 //
245 LOCAL_ITEM_STATE LocalItemState;
246
247 //
248 // root collection
249 //
250 PHID_COLLECTION RootCollection;
251
252 //
253 // report count
254 //
255 ULONG ReportCount;
256
257 //
258 // reports
259 //
260 PHID_REPORT * Reports;
261
262 //
263 // uses report ids
264 //
265 UCHAR UseReportIDs;
266
267 }HID_PARSER_CONTEXT, *PHID_PARSER_CONTEXT;
268
269 HIDPARSER_STATUS
270 HidParser_ParseReportDescriptor(
271 PHID_PARSER Parser,
272 PUCHAR Report,
273 ULONG ReportSize);
274
275 ULONG
276 HidParser_NumberOfTopCollections(
277 IN PHID_PARSER Parser);
278
279 #define HID_REPORT_TYPE_INPUT 0x01
280 #define HID_REPORT_TYPE_OUTPUT 0x02
281 #define HID_REPORT_TYPE_FEATURE 0x04
282
283 ULONG
284 HidParser_NumberOfReports(
285 IN PHID_PARSER Parser,
286 IN ULONG ReportType);
287
288 HIDPARSER_STATUS
289 HidParser_GetCollectionUsagePage(
290 IN PHID_PARSER Parser,
291 IN ULONG CollectionNumber,
292 OUT PUSHORT Usage,
293 OUT PUSHORT UsagePage);
294
295 ULONG
296 HidParser_GetReportLength(
297 IN PHID_PARSER Parser,
298 IN ULONG ReportType);
299
300 UCHAR
301 HidParser_IsReportIDUsed(
302 IN PHID_PARSER Parser);
303
304 ULONG
305 HidParser_GetReportItemCountFromReportType(
306 IN PHID_PARSER Parser,
307 IN ULONG ReportType);
308
309 ULONG
310 HidParser_GetReportItemTypeCountFromReportType(
311 IN PHID_PARSER Parser,
312 IN ULONG ReportType,
313 IN ULONG bData);
314
315 ULONG
316 HidParser_GetContextSize(
317 IN PHID_PARSER Parser);
318
319 VOID
320 HidParser_FreeContext(
321 IN PHID_PARSER Parser,
322 IN PUCHAR Context,
323 IN ULONG ContextLength);
324
325 ULONG
326 HidParser_GetTotalCollectionCount(
327 IN PHID_PARSER Parser);
328
329 ULONG
330 HidParser_GetMaxUsageListLengthWithReportAndPage(
331 IN PHID_PARSER Parser,
332 IN ULONG ReportType,
333 IN USAGE UsagePage OPTIONAL);
334
335 HIDPARSER_STATUS
336 HidParser_GetSpecificValueCapsWithReport(
337 IN PHID_PARSER Parser,
338 IN ULONG ReportType,
339 IN USHORT UsagePage,
340 IN USHORT Usage,
341 OUT PHIDP_VALUE_CAPS ValueCaps,
342 IN OUT PULONG ValueCapsLength);
343
344
345 HIDPARSER_STATUS
346 HidParser_GetUsagesWithReport(
347 IN PHID_PARSER Parser,
348 IN ULONG ReportType,
349 IN USAGE UsagePage,
350 OUT USAGE *UsageList,
351 IN OUT PULONG UsageLength,
352 IN PCHAR ReportDescriptor,
353 IN ULONG ReportDescriptorLength);
354
355 HIDPARSER_STATUS
356 HidParser_GetScaledUsageValueWithReport(
357 IN PHID_PARSER Parser,
358 IN ULONG ReportType,
359 IN USAGE UsagePage,
360 IN USAGE Usage,
361 OUT PLONG UsageValue,
362 IN PCHAR ReportDescriptor,
363 IN ULONG ReportDescriptorLength);