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