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