Sync with trunk r63174.
[reactos.git] / drivers / hid / hidparse / hidparse.c
1 /*
2 * PROJECT: ReactOS Universal Serial Bus Bulk Enhanced Host Controller Interface
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: drivers/usb/hidparse/hidparse.c
5 * PURPOSE: HID Parser
6 * PROGRAMMERS:
7 * Michael Martin (michael.martin@reactos.org)
8 * Johannes Anderwald (johannes.anderwald@reactos.org)
9 */
10
11 #include "hidparse.h"
12
13 #define NDEBUG
14 #include <debug.h>
15
16 PVOID
17 NTAPI
18 AllocFunction(
19 IN ULONG ItemSize)
20 {
21 PVOID Item = ExAllocatePoolWithTag(NonPagedPool, ItemSize, HIDPARSE_TAG);
22 if (Item)
23 {
24 //
25 // zero item
26 //
27 RtlZeroMemory(Item, ItemSize);
28 }
29
30 //
31 // done
32 //
33 return Item;
34 }
35
36 VOID
37 NTAPI
38 FreeFunction(
39 IN PVOID Item)
40 {
41 //
42 // free item
43 //
44 ExFreePoolWithTag(Item, HIDPARSE_TAG);
45 }
46
47 VOID
48 NTAPI
49 ZeroFunction(
50 IN PVOID Item,
51 IN ULONG ItemSize)
52 {
53 //
54 // zero item
55 //
56 RtlZeroMemory(Item, ItemSize);
57 }
58
59 VOID
60 NTAPI
61 CopyFunction(
62 IN PVOID Target,
63 IN PVOID Source,
64 IN ULONG Length)
65 {
66 //
67 // copy item
68 //
69 RtlCopyMemory(Target, Source, Length);
70 }
71
72 VOID
73 NTAPI
74 DebugFunction(
75 IN LPCSTR FormatStr, ...)
76 {
77 #if HID_DBG
78 va_list args;
79 char printbuffer[1024];
80
81 va_start(args, FormatStr);
82 vsprintf(printbuffer, FormatStr, args);
83 va_end(args);
84
85 DbgPrint(printbuffer);
86 #endif
87 }
88
89 VOID
90 NTAPI
91 HidP_FreeCollectionDescription(
92 IN PHIDP_DEVICE_DESC DeviceDescription)
93 {
94 HID_PARSER Parser;
95
96 //
97 // init parser
98 //
99 HidParser_InitParser(AllocFunction, FreeFunction, ZeroFunction, CopyFunction, DebugFunction, &Parser);
100
101 //
102 // free collection
103 //
104 HidParser_FreeCollectionDescription(&Parser, DeviceDescription);
105 }
106
107
108 HIDAPI
109 NTSTATUS
110 NTAPI
111 HidP_GetCaps(
112 IN PHIDP_PREPARSED_DATA PreparsedData,
113 OUT PHIDP_CAPS Capabilities)
114 {
115 HID_PARSER Parser;
116
117 //
118 // init parser
119 //
120 HidParser_InitParser(AllocFunction, FreeFunction, ZeroFunction, CopyFunction, DebugFunction, &Parser);
121
122 //
123 // get caps
124 //
125 return HidParser_GetCaps(&Parser, PreparsedData, Capabilities);
126 }
127
128 NTSTATUS
129 NTAPI
130 HidP_GetCollectionDescription(
131 IN PHIDP_REPORT_DESCRIPTOR ReportDesc,
132 IN ULONG DescLength,
133 IN POOL_TYPE PoolType,
134 OUT PHIDP_DEVICE_DESC DeviceDescription)
135 {
136 HID_PARSER Parser;
137
138 //
139 // init parser
140 //
141 HidParser_InitParser(AllocFunction, FreeFunction, ZeroFunction, CopyFunction, DebugFunction, &Parser);
142
143 //
144 // get description;
145 //
146 return HidParser_GetCollectionDescription(&Parser, ReportDesc, DescLength, PoolType, DeviceDescription);
147 }
148
149 HIDAPI
150 ULONG
151 NTAPI
152 HidP_MaxUsageListLength(
153 IN HIDP_REPORT_TYPE ReportType,
154 IN USAGE UsagePage OPTIONAL,
155 IN PHIDP_PREPARSED_DATA PreparsedData)
156 {
157 HID_PARSER Parser;
158
159 //
160 // sanity check
161 //
162 ASSERT(ReportType == HidP_Input || ReportType == HidP_Output || ReportType == HidP_Feature);
163
164 //
165 // init parser
166 //
167 HidParser_InitParser(AllocFunction, FreeFunction, ZeroFunction, CopyFunction, DebugFunction, &Parser);
168
169
170 //
171 // get usage length
172 //
173 return HidParser_MaxUsageListLength(&Parser, PreparsedData, ReportType, UsagePage);
174 }
175
176 HIDAPI
177 NTSTATUS
178 NTAPI
179 HidP_GetSpecificValueCaps(
180 IN HIDP_REPORT_TYPE ReportType,
181 IN USAGE UsagePage,
182 IN USHORT LinkCollection,
183 IN USAGE Usage,
184 OUT PHIDP_VALUE_CAPS ValueCaps,
185 IN OUT PUSHORT ValueCapsLength,
186 IN PHIDP_PREPARSED_DATA PreparsedData)
187 {
188 HID_PARSER Parser;
189
190 //
191 // sanity check
192 //
193 ASSERT(ReportType == HidP_Input || ReportType == HidP_Output || ReportType == HidP_Feature);
194
195 //
196 // init parser
197 //
198 HidParser_InitParser(AllocFunction, FreeFunction, ZeroFunction, CopyFunction, DebugFunction, &Parser);
199
200 //
201 // get value caps
202 //
203 return HidParser_GetSpecificValueCaps(&Parser, PreparsedData, ReportType, UsagePage, LinkCollection, Usage, ValueCaps, ValueCapsLength);
204 }
205
206 HIDAPI
207 NTSTATUS
208 NTAPI
209 HidP_GetUsages(
210 IN HIDP_REPORT_TYPE ReportType,
211 IN USAGE UsagePage,
212 IN USHORT LinkCollection OPTIONAL,
213 OUT PUSAGE UsageList,
214 IN OUT PULONG UsageLength,
215 IN PHIDP_PREPARSED_DATA PreparsedData,
216 IN PCHAR Report,
217 IN ULONG ReportLength)
218 {
219 HID_PARSER Parser;
220
221 //
222 // sanity check
223 //
224 ASSERT(ReportType == HidP_Input || ReportType == HidP_Output || ReportType == HidP_Feature);
225
226 //
227 // init parser
228 //
229 HidParser_InitParser(AllocFunction, FreeFunction, ZeroFunction, CopyFunction, DebugFunction, &Parser);
230
231 //
232 // get usages
233 //
234 return HidParser_GetUsages(&Parser, PreparsedData, ReportType, UsagePage, LinkCollection, UsageList, UsageLength, Report, ReportLength);
235 }
236
237
238 #undef HidP_GetButtonCaps
239
240 HIDAPI
241 NTSTATUS
242 NTAPI
243 HidP_UsageListDifference(
244 IN PUSAGE PreviousUsageList,
245 IN PUSAGE CurrentUsageList,
246 OUT PUSAGE BreakUsageList,
247 OUT PUSAGE MakeUsageList,
248 IN ULONG UsageListLength)
249 {
250 return HidParser_UsageListDifference(PreviousUsageList, CurrentUsageList, BreakUsageList, MakeUsageList, UsageListLength);
251 }
252
253 HIDAPI
254 NTSTATUS
255 NTAPI
256 HidP_GetUsagesEx(
257 IN HIDP_REPORT_TYPE ReportType,
258 IN USHORT LinkCollection,
259 OUT PUSAGE_AND_PAGE ButtonList,
260 IN OUT ULONG *UsageLength,
261 IN PHIDP_PREPARSED_DATA PreparsedData,
262 IN PCHAR Report,
263 IN ULONG ReportLength)
264 {
265 return HidP_GetUsages(ReportType, HID_USAGE_PAGE_UNDEFINED, LinkCollection, &ButtonList->Usage, UsageLength, PreparsedData, Report, ReportLength);
266 }
267
268 HIDAPI
269 NTSTATUS
270 NTAPI
271 HidP_UsageAndPageListDifference(
272 IN PUSAGE_AND_PAGE PreviousUsageList,
273 IN PUSAGE_AND_PAGE CurrentUsageList,
274 OUT PUSAGE_AND_PAGE BreakUsageList,
275 OUT PUSAGE_AND_PAGE MakeUsageList,
276 IN ULONG UsageListLength)
277 {
278 return HidParser_UsageAndPageListDifference(PreviousUsageList, CurrentUsageList, BreakUsageList, MakeUsageList, UsageListLength);
279 }
280
281 HIDAPI
282 NTSTATUS
283 NTAPI
284 HidP_GetScaledUsageValue(
285 IN HIDP_REPORT_TYPE ReportType,
286 IN USAGE UsagePage,
287 IN USHORT LinkCollection OPTIONAL,
288 IN USAGE Usage,
289 OUT PLONG UsageValue,
290 IN PHIDP_PREPARSED_DATA PreparsedData,
291 IN PCHAR Report,
292 IN ULONG ReportLength)
293 {
294 HID_PARSER Parser;
295
296 //
297 // sanity check
298 //
299 ASSERT(ReportType == HidP_Input || ReportType == HidP_Output || ReportType == HidP_Feature);
300
301 //
302 // init parser
303 //
304 HidParser_InitParser(AllocFunction, FreeFunction, ZeroFunction, CopyFunction, DebugFunction, &Parser);
305
306 //
307 // get scaled usage value
308 //
309 return HidParser_GetScaledUsageValue(&Parser, PreparsedData, ReportType, UsagePage, LinkCollection, Usage, UsageValue, Report, ReportLength);
310 }
311
312 HIDAPI
313 NTSTATUS
314 NTAPI
315 HidP_GetUsageValue(
316 IN HIDP_REPORT_TYPE ReportType,
317 IN USAGE UsagePage,
318 IN USHORT LinkCollection,
319 IN USAGE Usage,
320 OUT PULONG UsageValue,
321 IN PHIDP_PREPARSED_DATA PreparsedData,
322 IN PCHAR Report,
323 IN ULONG ReportLength)
324 {
325 HID_PARSER Parser;
326
327 //
328 // sanity check
329 //
330 ASSERT(ReportType == HidP_Input || ReportType == HidP_Output || ReportType == HidP_Feature);
331
332 //
333 // init parser
334 //
335 HidParser_InitParser(AllocFunction, FreeFunction, ZeroFunction, CopyFunction, DebugFunction, &Parser);
336
337 //
338 // get scaled usage value
339 //
340 return HidParser_GetUsageValue(&Parser, PreparsedData, ReportType, UsagePage, LinkCollection, Usage, UsageValue, Report, ReportLength);
341 }
342
343
344 HIDAPI
345 NTSTATUS
346 NTAPI
347 HidP_TranslateUsageAndPagesToI8042ScanCodes(
348 IN PUSAGE_AND_PAGE ChangedUsageList,
349 IN ULONG UsageListLength,
350 IN HIDP_KEYBOARD_DIRECTION KeyAction,
351 IN OUT PHIDP_KEYBOARD_MODIFIER_STATE ModifierState,
352 IN PHIDP_INSERT_SCANCODES InsertCodesProcedure,
353 IN PVOID InsertCodesContext)
354 {
355 HID_PARSER Parser;
356
357 //
358 // init parser
359 //
360 HidParser_InitParser(AllocFunction, FreeFunction, ZeroFunction, CopyFunction, DebugFunction, &Parser);
361
362 //
363 // translate usage pages
364 //
365 return HidParser_TranslateUsageAndPagesToI8042ScanCodes(&Parser, ChangedUsageList, UsageListLength, KeyAction, ModifierState, InsertCodesProcedure, InsertCodesContext);
366 }
367
368 HIDAPI
369 NTSTATUS
370 NTAPI
371 HidP_GetButtonCaps(
372 HIDP_REPORT_TYPE ReportType,
373 PHIDP_BUTTON_CAPS ButtonCaps,
374 PUSHORT ButtonCapsLength,
375 PHIDP_PREPARSED_DATA PreparsedData)
376 {
377 return HidP_GetSpecificButtonCaps(ReportType, HID_USAGE_PAGE_UNDEFINED, 0, 0, ButtonCaps, ButtonCapsLength, PreparsedData);
378 }
379
380 HIDAPI
381 NTSTATUS
382 NTAPI
383 HidP_GetSpecificButtonCaps(
384 IN HIDP_REPORT_TYPE ReportType,
385 IN USAGE UsagePage,
386 IN USHORT LinkCollection,
387 IN USAGE Usage,
388 OUT PHIDP_BUTTON_CAPS ButtonCaps,
389 IN OUT PUSHORT ButtonCapsLength,
390 IN PHIDP_PREPARSED_DATA PreparsedData)
391 {
392 UNIMPLEMENTED
393 ASSERT(FALSE);
394 return STATUS_NOT_IMPLEMENTED;
395 }
396
397 HIDAPI
398 NTSTATUS
399 NTAPI
400 HidP_GetData(
401 IN HIDP_REPORT_TYPE ReportType,
402 OUT PHIDP_DATA DataList,
403 IN OUT PULONG DataLength,
404 IN PHIDP_PREPARSED_DATA PreparsedData,
405 IN PCHAR Report,
406 IN ULONG ReportLength)
407 {
408 UNIMPLEMENTED
409 ASSERT(FALSE);
410 return STATUS_NOT_IMPLEMENTED;
411 }
412
413 HIDAPI
414 NTSTATUS
415 NTAPI
416 HidP_GetExtendedAttributes(
417 IN HIDP_REPORT_TYPE ReportType,
418 IN USHORT DataIndex,
419 IN PHIDP_PREPARSED_DATA PreparsedData,
420 OUT PHIDP_EXTENDED_ATTRIBUTES Attributes,
421 IN OUT PULONG LengthAttributes)
422 {
423 UNIMPLEMENTED
424 ASSERT(FALSE);
425 return STATUS_NOT_IMPLEMENTED;
426 }
427
428 HIDAPI
429 NTSTATUS
430 NTAPI
431 HidP_GetLinkCollectionNodes(
432 OUT PHIDP_LINK_COLLECTION_NODE LinkCollectionNodes,
433 IN OUT PULONG LinkCollectionNodesLength,
434 IN PHIDP_PREPARSED_DATA PreparsedData)
435 {
436 UNIMPLEMENTED
437 ASSERT(FALSE);
438 return STATUS_NOT_IMPLEMENTED;
439 }
440
441 NTSTATUS
442 NTAPI
443 HidP_SysPowerEvent(
444 IN PCHAR HidPacket,
445 IN USHORT HidPacketLength,
446 IN PHIDP_PREPARSED_DATA Ppd,
447 OUT PULONG OutputBuffer)
448 {
449 UNIMPLEMENTED
450 ASSERT(FALSE);
451 return STATUS_NOT_IMPLEMENTED;
452 }
453
454 NTSTATUS
455 NTAPI
456 HidP_SysPowerCaps(
457 IN PHIDP_PREPARSED_DATA Ppd,
458 OUT PULONG OutputBuffer)
459 {
460 UNIMPLEMENTED
461 ASSERT(FALSE);
462 return STATUS_NOT_IMPLEMENTED;
463 }
464
465 HIDAPI
466 NTSTATUS
467 NTAPI
468 HidP_GetUsageValueArray(
469 IN HIDP_REPORT_TYPE ReportType,
470 IN USAGE UsagePage,
471 IN USHORT LinkCollection OPTIONAL,
472 IN USAGE Usage,
473 OUT PCHAR UsageValue,
474 IN USHORT UsageValueByteLength,
475 IN PHIDP_PREPARSED_DATA PreparsedData,
476 IN PCHAR Report,
477 IN ULONG ReportLength)
478 {
479 UNIMPLEMENTED
480 ASSERT(FALSE);
481 return STATUS_NOT_IMPLEMENTED;
482 }
483
484
485 HIDAPI
486 NTSTATUS
487 NTAPI
488 HidP_UnsetUsages(
489 IN HIDP_REPORT_TYPE ReportType,
490 IN USAGE UsagePage,
491 IN USHORT LinkCollection,
492 IN PUSAGE UsageList,
493 IN OUT PULONG UsageLength,
494 IN PHIDP_PREPARSED_DATA PreparsedData,
495 IN OUT PCHAR Report,
496 IN ULONG ReportLength)
497 {
498 UNIMPLEMENTED
499 ASSERT(FALSE);
500 return STATUS_NOT_IMPLEMENTED;
501 }
502
503 HIDAPI
504 NTSTATUS
505 NTAPI
506 HidP_TranslateUsagesToI8042ScanCodes(
507 IN PUSAGE ChangedUsageList,
508 IN ULONG UsageListLength,
509 IN HIDP_KEYBOARD_DIRECTION KeyAction,
510 IN OUT PHIDP_KEYBOARD_MODIFIER_STATE ModifierState,
511 IN PHIDP_INSERT_SCANCODES InsertCodesProcedure,
512 IN PVOID InsertCodesContext)
513 {
514 UNIMPLEMENTED
515 ASSERT(FALSE);
516 return STATUS_NOT_IMPLEMENTED;
517 }
518
519 HIDAPI
520 NTSTATUS
521 NTAPI
522 HidP_SetUsages(
523 IN HIDP_REPORT_TYPE ReportType,
524 IN USAGE UsagePage,
525 IN USHORT LinkCollection,
526 IN PUSAGE UsageList,
527 IN OUT PULONG UsageLength,
528 IN PHIDP_PREPARSED_DATA PreparsedData,
529 IN OUT PCHAR Report,
530 IN ULONG ReportLength)
531 {
532 UNIMPLEMENTED
533 ASSERT(FALSE);
534 return STATUS_NOT_IMPLEMENTED;
535 }
536
537 HIDAPI
538 NTSTATUS
539 NTAPI
540 HidP_SetUsageValueArray(
541 IN HIDP_REPORT_TYPE ReportType,
542 IN USAGE UsagePage,
543 IN USHORT LinkCollection OPTIONAL,
544 IN USAGE Usage,
545 IN PCHAR UsageValue,
546 IN USHORT UsageValueByteLength,
547 IN PHIDP_PREPARSED_DATA PreparsedData,
548 OUT PCHAR Report,
549 IN ULONG ReportLength)
550 {
551 UNIMPLEMENTED
552 ASSERT(FALSE);
553 return STATUS_NOT_IMPLEMENTED;
554 }
555
556 HIDAPI
557 NTSTATUS
558 NTAPI
559 HidP_SetUsageValue(
560 IN HIDP_REPORT_TYPE ReportType,
561 IN USAGE UsagePage,
562 IN USHORT LinkCollection,
563 IN USAGE Usage,
564 IN ULONG UsageValue,
565 IN PHIDP_PREPARSED_DATA PreparsedData,
566 IN OUT PCHAR Report,
567 IN ULONG ReportLength)
568 {
569 UNIMPLEMENTED
570 ASSERT(FALSE);
571 return STATUS_NOT_IMPLEMENTED;
572 }
573
574 HIDAPI
575 NTSTATUS
576 NTAPI
577 HidP_SetScaledUsageValue(
578 IN HIDP_REPORT_TYPE ReportType,
579 IN USAGE UsagePage,
580 IN USHORT LinkCollection OPTIONAL,
581 IN USAGE Usage,
582 IN LONG UsageValue,
583 IN PHIDP_PREPARSED_DATA PreparsedData,
584 IN OUT PCHAR Report,
585 IN ULONG ReportLength)
586 {
587 UNIMPLEMENTED
588 ASSERT(FALSE);
589 return STATUS_NOT_IMPLEMENTED;
590 }
591
592 HIDAPI
593 NTSTATUS
594 NTAPI
595 HidP_SetData(
596 IN HIDP_REPORT_TYPE ReportType,
597 IN PHIDP_DATA DataList,
598 IN OUT PULONG DataLength,
599 IN PHIDP_PREPARSED_DATA PreparsedData,
600 IN OUT PCHAR Report,
601 IN ULONG ReportLength)
602 {
603 UNIMPLEMENTED
604 ASSERT(FALSE);
605 return STATUS_NOT_IMPLEMENTED;
606 }
607
608 HIDAPI
609 ULONG
610 NTAPI
611 HidP_MaxDataListLength(
612 IN HIDP_REPORT_TYPE ReportType,
613 IN PHIDP_PREPARSED_DATA PreparsedData)
614 {
615 UNIMPLEMENTED
616 ASSERT(FALSE);
617 return STATUS_NOT_IMPLEMENTED;
618 }
619
620 HIDAPI
621 NTSTATUS
622 NTAPI
623 HidP_InitializeReportForID(
624 IN HIDP_REPORT_TYPE ReportType,
625 IN UCHAR ReportID,
626 IN PHIDP_PREPARSED_DATA PreparsedData,
627 IN OUT PCHAR Report,
628 IN ULONG ReportLength)
629 {
630 UNIMPLEMENTED
631 ASSERT(FALSE);
632 return STATUS_NOT_IMPLEMENTED;
633 }
634
635 #undef HidP_GetValueCaps
636
637 HIDAPI
638 NTSTATUS
639 NTAPI
640 HidP_GetValueCaps(
641 HIDP_REPORT_TYPE ReportType,
642 PHIDP_VALUE_CAPS ValueCaps,
643 PUSHORT ValueCapsLength,
644 PHIDP_PREPARSED_DATA PreparsedData)
645 {
646 UNIMPLEMENTED
647 ASSERT(FALSE);
648 return STATUS_NOT_IMPLEMENTED;
649 }
650
651 NTSTATUS
652 NTAPI
653 DriverEntry(
654 IN PDRIVER_OBJECT DriverObject,
655 IN PUNICODE_STRING RegPath)
656 {
657 DPRINT("********* HID PARSE *********\n");
658 return STATUS_SUCCESS;
659 }