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