[USB-BRINGUP]
[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, NULL, &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, PreparsedData, &Parser);
118
119 //
120 // get caps
121 //
122 return HidParser_GetCaps(&Parser, 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 PHID_PARSER Parser;
134 HIDPARSER_STATUS Status;
135
136 //
137 // first allocate the parser
138 //
139 Status = HidParser_AllocateParser(AllocFunction, FreeFunction, ZeroFunction, CopyFunction, DebugFunction, &Parser);
140 if (Status != HIDPARSER_STATUS_SUCCESS)
141 {
142 //
143 // not enough memory
144 //
145 return STATUS_INSUFFICIENT_RESOURCES;
146 }
147
148 //
149 // get description;
150 //
151 Status = HidParser_GetCollectionDescription(Parser, ReportDesc, DescLength, PoolType, DeviceDescription);
152
153 //
154 // FIXME parser memory leak
155 //
156 return Status;
157 }
158
159 HIDAPI
160 ULONG
161 NTAPI
162 HidP_MaxUsageListLength(
163 IN HIDP_REPORT_TYPE ReportType,
164 IN USAGE UsagePage OPTIONAL,
165 IN PHIDP_PREPARSED_DATA PreparsedData)
166 {
167 HID_PARSER Parser;
168
169 //
170 // sanity check
171 //
172 ASSERT(ReportType == HidP_Input || ReportType == HidP_Output || ReportType == HidP_Feature);
173
174 //
175 // init parser
176 //
177 HidParser_InitParser(AllocFunction, FreeFunction, ZeroFunction, CopyFunction, DebugFunction, PreparsedData, &Parser);
178
179
180 //
181 // get usage length
182 //
183 return HidParser_MaxUsageListLength(&Parser, ReportType, UsagePage);
184 }
185
186 HIDAPI
187 NTSTATUS
188 NTAPI
189 HidP_GetSpecificValueCaps(
190 IN HIDP_REPORT_TYPE ReportType,
191 IN USAGE UsagePage,
192 IN USHORT LinkCollection,
193 IN USAGE Usage,
194 OUT PHIDP_VALUE_CAPS ValueCaps,
195 IN OUT PULONG ValueCapsLength,
196 IN PHIDP_PREPARSED_DATA PreparsedData)
197 {
198 HID_PARSER Parser;
199
200 //
201 // sanity check
202 //
203 ASSERT(ReportType == HidP_Input || ReportType == HidP_Output || ReportType == HidP_Feature);
204
205 //
206 // init parser
207 //
208 HidParser_InitParser(AllocFunction, FreeFunction, ZeroFunction, CopyFunction, DebugFunction, PreparsedData, &Parser);
209
210 //
211 // get value caps
212 //
213 return HidParser_GetSpecificValueCaps(&Parser, ReportType, UsagePage, LinkCollection, Usage, ValueCaps, ValueCapsLength);
214 }
215
216 HIDAPI
217 NTSTATUS
218 NTAPI
219 HidP_GetUsages(
220 IN HIDP_REPORT_TYPE ReportType,
221 IN USAGE UsagePage,
222 IN USHORT LinkCollection OPTIONAL,
223 OUT USAGE *UsageList,
224 IN OUT ULONG *UsageLength,
225 IN PHIDP_PREPARSED_DATA PreparsedData,
226 IN PCHAR Report,
227 IN ULONG ReportLength)
228 {
229 HID_PARSER Parser;
230
231 //
232 // sanity check
233 //
234 ASSERT(ReportType == HidP_Input || ReportType == HidP_Output || ReportType == HidP_Feature);
235
236 //
237 // init parser
238 //
239 HidParser_InitParser(AllocFunction, FreeFunction, ZeroFunction, CopyFunction, DebugFunction, PreparsedData, &Parser);
240
241 //
242 // get usages
243 //
244 return HidParser_GetUsages(&Parser, ReportType, UsagePage, LinkCollection, UsageList, UsageLength, Report, ReportLength);
245 }
246
247
248 #undef HidP_GetButtonCaps
249
250 HIDAPI
251 NTSTATUS
252 NTAPI
253 HidP_UsageListDifference(
254 IN PUSAGE PreviousUsageList,
255 IN PUSAGE CurrentUsageList,
256 OUT PUSAGE BreakUsageList,
257 OUT PUSAGE MakeUsageList,
258 IN ULONG UsageListLength)
259 {
260 return HidParser_UsageListDifference(PreviousUsageList, CurrentUsageList, BreakUsageList, MakeUsageList, UsageListLength);
261 }
262
263 HIDAPI
264 NTSTATUS
265 NTAPI
266 HidP_GetUsagesEx(
267 IN HIDP_REPORT_TYPE ReportType,
268 IN USHORT LinkCollection,
269 OUT PUSAGE_AND_PAGE ButtonList,
270 IN OUT ULONG *UsageLength,
271 IN PHIDP_PREPARSED_DATA PreparsedData,
272 IN PCHAR Report,
273 IN ULONG ReportLength)
274 {
275 return HidP_GetUsages(ReportType, HID_USAGE_PAGE_UNDEFINED, LinkCollection, (PUSAGE)ButtonList, UsageLength, PreparsedData, Report, ReportLength);
276 }
277
278 HIDAPI
279 NTSTATUS
280 NTAPI
281 HidP_UsageAndPageListDifference(
282 IN PUSAGE_AND_PAGE PreviousUsageList,
283 IN PUSAGE_AND_PAGE CurrentUsageList,
284 OUT PUSAGE_AND_PAGE BreakUsageList,
285 OUT PUSAGE_AND_PAGE MakeUsageList,
286 IN ULONG UsageListLength)
287 {
288 return HidParser_UsageAndPageListDifference(PreviousUsageList, CurrentUsageList, BreakUsageList, MakeUsageList, UsageListLength);
289 }
290
291 HIDAPI
292 NTSTATUS
293 NTAPI
294 HidP_GetScaledUsageValue(
295 IN HIDP_REPORT_TYPE ReportType,
296 IN USAGE UsagePage,
297 IN USHORT LinkCollection OPTIONAL,
298 IN USAGE Usage,
299 OUT PLONG UsageValue,
300 IN PHIDP_PREPARSED_DATA PreparsedData,
301 IN PCHAR Report,
302 IN ULONG ReportLength)
303 {
304 HID_PARSER Parser;
305
306 //
307 // sanity check
308 //
309 ASSERT(ReportType == HidP_Input || ReportType == HidP_Output || ReportType == HidP_Feature);
310
311 //
312 // init parser
313 //
314 HidParser_InitParser(AllocFunction, FreeFunction, ZeroFunction, CopyFunction, DebugFunction, PreparsedData, &Parser);
315
316 //
317 // get scaled usage value
318 //
319 return HidParser_GetScaledUsageValue(&Parser, ReportType, UsagePage, LinkCollection, Usage, UsageValue, Report, ReportLength);
320 }
321
322 HIDAPI
323 NTSTATUS
324 NTAPI
325 HidP_TranslateUsageAndPagesToI8042ScanCodes(
326 IN PUSAGE_AND_PAGE ChangedUsageList,
327 IN ULONG UsageListLength,
328 IN HIDP_KEYBOARD_DIRECTION KeyAction,
329 IN OUT PHIDP_KEYBOARD_MODIFIER_STATE ModifierState,
330 IN PHIDP_INSERT_SCANCODES InsertCodesProcedure,
331 IN PVOID InsertCodesContext)
332 {
333 HID_PARSER Parser;
334
335 //
336 // init parser
337 //
338 HidParser_InitParser(AllocFunction, FreeFunction, ZeroFunction, CopyFunction, DebugFunction, NULL, &Parser);
339
340 //
341 // translate usage pages
342 //
343 return HidParser_TranslateUsageAndPagesToI8042ScanCodes(&Parser, ChangedUsageList, UsageListLength, KeyAction, ModifierState, InsertCodesProcedure, InsertCodesContext);
344 }
345
346
347
348 HIDAPI
349 NTSTATUS
350 NTAPI
351 HidP_GetButtonCaps(
352 HIDP_REPORT_TYPE ReportType,
353 PHIDP_BUTTON_CAPS ButtonCaps,
354 PUSHORT ButtonCapsLength,
355 PHIDP_PREPARSED_DATA PreparsedData)
356 {
357 return HidP_GetSpecificButtonCaps(ReportType, HID_USAGE_PAGE_UNDEFINED, 0, 0, ButtonCaps, (PULONG)ButtonCapsLength, PreparsedData);
358 }
359
360 HIDAPI
361 NTSTATUS
362 NTAPI
363 HidP_GetSpecificButtonCaps(
364 IN HIDP_REPORT_TYPE ReportType,
365 IN USAGE UsagePage,
366 IN USHORT LinkCollection,
367 IN USAGE Usage,
368 OUT PHIDP_BUTTON_CAPS ButtonCaps,
369 IN OUT PULONG ButtonCapsLength,
370 IN PHIDP_PREPARSED_DATA PreparsedData)
371 {
372 UNIMPLEMENTED
373 ASSERT(FALSE);
374 return STATUS_NOT_IMPLEMENTED;
375 }
376
377 HIDAPI
378 NTSTATUS
379 NTAPI
380 HidP_GetData(
381 IN HIDP_REPORT_TYPE ReportType,
382 OUT PHIDP_DATA DataList,
383 IN OUT PULONG DataLength,
384 IN PHIDP_PREPARSED_DATA PreparsedData,
385 IN PCHAR Report,
386 IN ULONG ReportLength)
387 {
388 UNIMPLEMENTED
389 ASSERT(FALSE);
390 return STATUS_NOT_IMPLEMENTED;
391 }
392
393 HIDAPI
394 NTSTATUS
395 NTAPI
396 HidP_GetExtendedAttributes(
397 IN HIDP_REPORT_TYPE ReportType,
398 IN USAGE UsagePage,
399 IN PHIDP_PREPARSED_DATA PreparsedData,
400 OUT PHIDP_EXTENDED_ATTRIBUTES Attributes,
401 IN OUT PULONG LengthAttributes)
402 {
403 UNIMPLEMENTED
404 ASSERT(FALSE);
405 return STATUS_NOT_IMPLEMENTED;
406 }
407
408 HIDAPI
409 NTSTATUS
410 NTAPI
411 HidP_GetLinkCollectionNodes(
412 OUT PHIDP_LINK_COLLECTION_NODE LinkCollectionNodes,
413 IN OUT PULONG LinkCollectionNodesLength,
414 IN PHIDP_PREPARSED_DATA PreparsedData)
415 {
416 UNIMPLEMENTED
417 ASSERT(FALSE);
418 return STATUS_NOT_IMPLEMENTED;
419 }
420
421 HIDAPI
422 NTSTATUS
423 NTAPI
424 HidP_GetUsageValue(
425 IN HIDP_REPORT_TYPE ReportType,
426 IN USAGE UsagePage,
427 IN USHORT LinkCollection,
428 IN USAGE Usage,
429 OUT PULONG UsageValue,
430 IN PHIDP_PREPARSED_DATA PreparsedData,
431 IN PCHAR Report,
432 IN ULONG ReportLength)
433 {
434 UNIMPLEMENTED
435 ASSERT(FALSE);
436 return STATUS_NOT_IMPLEMENTED;
437 }
438
439 NTSTATUS
440 NTAPI
441 HidP_SysPowerEvent (
442 IN PCHAR HidPacket,
443 IN USHORT HidPacketLength,
444 IN PHIDP_PREPARSED_DATA Ppd,
445 OUT PULONG OutputBuffer)
446 {
447 UNIMPLEMENTED
448 ASSERT(FALSE);
449 return STATUS_NOT_IMPLEMENTED;
450 }
451
452 NTSTATUS
453 NTAPI
454 HidP_SysPowerCaps (
455 IN PHIDP_PREPARSED_DATA Ppd,
456 OUT PULONG OutputBuffer)
457 {
458 UNIMPLEMENTED
459 ASSERT(FALSE);
460 return STATUS_NOT_IMPLEMENTED;
461 }
462
463 HIDAPI
464 NTSTATUS
465 NTAPI
466 HidP_GetUsageValueArray(
467 IN HIDP_REPORT_TYPE ReportType,
468 IN USAGE UsagePage,
469 IN USHORT LinkCollection OPTIONAL,
470 IN USAGE Usage,
471 OUT PCHAR UsageValue,
472 IN USHORT UsageValueByteLength,
473 IN PHIDP_PREPARSED_DATA PreparsedData,
474 IN PCHAR Report,
475 IN ULONG ReportLength)
476 {
477 UNIMPLEMENTED
478 ASSERT(FALSE);
479 return STATUS_NOT_IMPLEMENTED;
480 }
481
482
483 HIDAPI
484 NTSTATUS
485 NTAPI
486 HidP_UnsetUsages(
487 IN HIDP_REPORT_TYPE ReportType,
488 IN USAGE UsagePage,
489 IN USHORT LinkCollection,
490 IN PUSAGE UsageList,
491 IN OUT PULONG UsageLength,
492 IN PHIDP_PREPARSED_DATA PreparsedData,
493 IN OUT PCHAR Report,
494 IN ULONG ReportLength)
495 {
496 UNIMPLEMENTED
497 ASSERT(FALSE);
498 return STATUS_NOT_IMPLEMENTED;
499 }
500
501 HIDAPI
502 NTSTATUS
503 NTAPI
504 HidP_TranslateUsagesToI8042ScanCodes(
505 IN PUSAGE ChangedUsageList,
506 IN ULONG UsageListLength,
507 IN HIDP_KEYBOARD_DIRECTION KeyAction,
508 IN OUT PHIDP_KEYBOARD_MODIFIER_STATE ModifierState,
509 IN PHIDP_INSERT_SCANCODES InsertCodesProcedure,
510 IN PVOID InsertCodesContext)
511 {
512 UNIMPLEMENTED
513 ASSERT(FALSE);
514 return STATUS_NOT_IMPLEMENTED;
515 }
516
517 HIDAPI
518 NTSTATUS
519 NTAPI
520 HidP_SetUsages(
521 IN HIDP_REPORT_TYPE ReportType,
522 IN USAGE UsagePage,
523 IN USHORT LinkCollection,
524 IN PUSAGE UsageList,
525 IN OUT PULONG UsageLength,
526 IN PHIDP_PREPARSED_DATA PreparsedData,
527 IN OUT PCHAR Report,
528 IN ULONG ReportLength)
529 {
530 UNIMPLEMENTED
531 ASSERT(FALSE);
532 return STATUS_NOT_IMPLEMENTED;
533 }
534
535 HIDAPI
536 NTSTATUS
537 NTAPI
538 HidP_SetUsageValueArray(
539 IN HIDP_REPORT_TYPE ReportType,
540 IN USAGE UsagePage,
541 IN USHORT LinkCollection OPTIONAL,
542 IN USAGE Usage,
543 IN PCHAR UsageValue,
544 IN USHORT UsageValueByteLength,
545 IN PHIDP_PREPARSED_DATA PreparsedData,
546 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_SetUsageValue(
558 IN HIDP_REPORT_TYPE ReportType,
559 IN USAGE UsagePage,
560 IN USHORT LinkCollection,
561 IN USAGE Usage,
562 IN ULONG UsageValue,
563 IN PHIDP_PREPARSED_DATA PreparsedData,
564 IN OUT PCHAR Report,
565 IN ULONG ReportLength)
566 {
567 UNIMPLEMENTED
568 ASSERT(FALSE);
569 return STATUS_NOT_IMPLEMENTED;
570 }
571
572 HIDAPI
573 NTSTATUS
574 NTAPI
575 HidP_SetScaledUsageValue(
576 IN HIDP_REPORT_TYPE ReportType,
577 IN USAGE UsagePage,
578 IN USHORT LinkCollection OPTIONAL,
579 IN USAGE Usage,
580 IN LONG UsageValue,
581 IN PHIDP_PREPARSED_DATA PreparsedData,
582 IN OUT PCHAR Report,
583 IN ULONG ReportLength)
584 {
585 UNIMPLEMENTED
586 ASSERT(FALSE);
587 return STATUS_NOT_IMPLEMENTED;
588 }
589
590 HIDAPI
591 NTSTATUS
592 NTAPI
593 HidP_SetData(
594 IN HIDP_REPORT_TYPE ReportType,
595 IN PHIDP_DATA DataList,
596 IN OUT PULONG DataLength,
597 IN PHIDP_PREPARSED_DATA PreparsedData,
598 IN OUT PCHAR Report,
599 IN ULONG ReportLength)
600 {
601 UNIMPLEMENTED
602 ASSERT(FALSE);
603 return STATUS_NOT_IMPLEMENTED;
604 }
605
606 HIDAPI
607 ULONG
608 NTAPI
609 HidP_MaxDataListLength(
610 IN HIDP_REPORT_TYPE ReportType,
611 IN PHIDP_PREPARSED_DATA PreparsedData)
612 {
613 UNIMPLEMENTED
614 ASSERT(FALSE);
615 return STATUS_NOT_IMPLEMENTED;
616 }
617
618 HIDAPI
619 NTSTATUS
620 NTAPI
621 HidP_InitializeReportForID(
622 IN HIDP_REPORT_TYPE ReportType,
623 IN UCHAR ReportID,
624 IN PHIDP_PREPARSED_DATA PreparsedData,
625 IN OUT PCHAR Report,
626 IN ULONG ReportLength)
627 {
628 UNIMPLEMENTED
629 ASSERT(FALSE);
630 return STATUS_NOT_IMPLEMENTED;
631 }
632
633 #undef HidP_GetValueCaps
634
635 HIDAPI
636 NTSTATUS
637 NTAPI
638 HidP_GetValueCaps(
639 HIDP_REPORT_TYPE ReportType,
640 PHIDP_VALUE_CAPS ValueCaps,
641 PULONG ValueCapsLength,
642 PHIDP_PREPARSED_DATA PreparsedData)
643 {
644 UNIMPLEMENTED
645 ASSERT(FALSE);
646 return STATUS_NOT_IMPLEMENTED;
647 }
648
649 NTSTATUS
650 NTAPI
651 DriverEntry(
652 IN PDRIVER_OBJECT DriverObject,
653 IN PUNICODE_STRING RegPath)
654 {
655
656 DPRINT1("********* HID PARSE *********\n");
657 return STATUS_SUCCESS;
658 }