[USB-BRINGUP-TRUNK]
[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 // sanity check
337 //
338 ASSERT(ReportType == HidP_Input || ReportType == HidP_Output || ReportType == HidP_Feature);
339
340 //
341 // init parser
342 //
343 HidParser_InitParser(AllocFunction, FreeFunction, ZeroFunction, CopyFunction, DebugFunction, NULL, &Parser);
344
345 //
346 // translate usage pages
347 //
348 return HidParser_TranslateUsageAndPagesToI8042ScanCodes(Parser, UsageListLength, KeyAction, ModifierState, InsertCodesProcedure, InsertCodesContext);
349 }
350
351
352
353 HIDAPI
354 NTSTATUS
355 NTAPI
356 HidP_GetButtonCaps(
357 HIDP_REPORT_TYPE ReportType,
358 PHIDP_BUTTON_CAPS ButtonCaps,
359 PUSHORT ButtonCapsLength,
360 PHIDP_PREPARSED_DATA PreparsedData)
361 {
362 return HidP_GetSpecificButtonCaps(ReportType, HID_USAGE_PAGE_UNDEFINED, 0, 0, ButtonCaps, (PULONG)ButtonCapsLength, PreparsedData);
363 }
364
365 HIDAPI
366 NTSTATUS
367 NTAPI
368 HidP_GetSpecificButtonCaps(
369 IN HIDP_REPORT_TYPE ReportType,
370 IN USAGE UsagePage,
371 IN USHORT LinkCollection,
372 IN USAGE Usage,
373 OUT PHIDP_BUTTON_CAPS ButtonCaps,
374 IN OUT PULONG ButtonCapsLength,
375 IN PHIDP_PREPARSED_DATA PreparsedData)
376 {
377 UNIMPLEMENTED
378 ASSERT(FALSE);
379 return STATUS_NOT_IMPLEMENTED;
380 }
381
382 HIDAPI
383 NTSTATUS
384 NTAPI
385 HidP_GetData(
386 IN HIDP_REPORT_TYPE ReportType,
387 OUT PHIDP_DATA DataList,
388 IN OUT PULONG DataLength,
389 IN PHIDP_PREPARSED_DATA PreparsedData,
390 IN PCHAR Report,
391 IN ULONG ReportLength)
392 {
393 UNIMPLEMENTED
394 ASSERT(FALSE);
395 return STATUS_NOT_IMPLEMENTED;
396 }
397
398 HIDAPI
399 NTSTATUS
400 NTAPI
401 HidP_GetExtendedAttributes(
402 IN HIDP_REPORT_TYPE ReportType,
403 IN USAGE UsagePage,
404 IN PHIDP_PREPARSED_DATA PreparsedData,
405 OUT PHIDP_EXTENDED_ATTRIBUTES Attributes,
406 IN OUT PULONG LengthAttributes)
407 {
408 UNIMPLEMENTED
409 ASSERT(FALSE);
410 return STATUS_NOT_IMPLEMENTED;
411 }
412
413 HIDAPI
414 NTSTATUS
415 NTAPI
416 HidP_GetLinkCollectionNodes(
417 OUT PHIDP_LINK_COLLECTION_NODE LinkCollectionNodes,
418 IN OUT PULONG LinkCollectionNodesLength,
419 IN PHIDP_PREPARSED_DATA PreparsedData)
420 {
421 UNIMPLEMENTED
422 ASSERT(FALSE);
423 return STATUS_NOT_IMPLEMENTED;
424 }
425
426 HIDAPI
427 NTSTATUS
428 NTAPI
429 HidP_GetUsageValue(
430 IN HIDP_REPORT_TYPE ReportType,
431 IN USAGE UsagePage,
432 IN USHORT LinkCollection,
433 IN USAGE Usage,
434 OUT PULONG UsageValue,
435 IN PHIDP_PREPARSED_DATA PreparsedData,
436 IN PCHAR Report,
437 IN ULONG ReportLength)
438 {
439 UNIMPLEMENTED
440 ASSERT(FALSE);
441 return STATUS_NOT_IMPLEMENTED;
442 }
443
444 NTSTATUS
445 NTAPI
446 HidP_SysPowerEvent (
447 IN PCHAR HidPacket,
448 IN USHORT HidPacketLength,
449 IN PHIDP_PREPARSED_DATA Ppd,
450 OUT PULONG OutputBuffer)
451 {
452 UNIMPLEMENTED
453 ASSERT(FALSE);
454 return STATUS_NOT_IMPLEMENTED;
455 }
456
457 NTSTATUS
458 NTAPI
459 HidP_SysPowerCaps (
460 IN PHIDP_PREPARSED_DATA Ppd,
461 OUT PULONG OutputBuffer)
462 {
463 UNIMPLEMENTED
464 ASSERT(FALSE);
465 return STATUS_NOT_IMPLEMENTED;
466 }
467
468 HIDAPI
469 NTSTATUS
470 NTAPI
471 HidP_GetUsageValueArray(
472 IN HIDP_REPORT_TYPE ReportType,
473 IN USAGE UsagePage,
474 IN USHORT LinkCollection OPTIONAL,
475 IN USAGE Usage,
476 OUT PCHAR UsageValue,
477 IN USHORT UsageValueByteLength,
478 IN PHIDP_PREPARSED_DATA PreparsedData,
479 IN PCHAR Report,
480 IN ULONG ReportLength)
481 {
482 UNIMPLEMENTED
483 ASSERT(FALSE);
484 return STATUS_NOT_IMPLEMENTED;
485 }
486
487
488 HIDAPI
489 NTSTATUS
490 NTAPI
491 HidP_UnsetUsages(
492 IN HIDP_REPORT_TYPE ReportType,
493 IN USAGE UsagePage,
494 IN USHORT LinkCollection,
495 IN PUSAGE UsageList,
496 IN OUT PULONG UsageLength,
497 IN PHIDP_PREPARSED_DATA PreparsedData,
498 IN OUT PCHAR Report,
499 IN ULONG ReportLength)
500 {
501 UNIMPLEMENTED
502 ASSERT(FALSE);
503 return STATUS_NOT_IMPLEMENTED;
504 }
505
506 HIDAPI
507 NTSTATUS
508 NTAPI
509 HidP_TranslateUsagesToI8042ScanCodes(
510 IN PUSAGE ChangedUsageList,
511 IN ULONG UsageListLength,
512 IN HIDP_KEYBOARD_DIRECTION KeyAction,
513 IN OUT PHIDP_KEYBOARD_MODIFIER_STATE ModifierState,
514 IN PHIDP_INSERT_SCANCODES InsertCodesProcedure,
515 IN PVOID InsertCodesContext)
516 {
517 UNIMPLEMENTED
518 ASSERT(FALSE);
519 return STATUS_NOT_IMPLEMENTED;
520 }
521
522 HIDAPI
523 NTSTATUS
524 NTAPI
525 HidP_SetUsages(
526 IN HIDP_REPORT_TYPE ReportType,
527 IN USAGE UsagePage,
528 IN USHORT LinkCollection,
529 IN PUSAGE UsageList,
530 IN OUT PULONG UsageLength,
531 IN PHIDP_PREPARSED_DATA PreparsedData,
532 IN OUT PCHAR Report,
533 IN ULONG ReportLength)
534 {
535 UNIMPLEMENTED
536 ASSERT(FALSE);
537 return STATUS_NOT_IMPLEMENTED;
538 }
539
540 HIDAPI
541 NTSTATUS
542 NTAPI
543 HidP_SetUsageValueArray(
544 IN HIDP_REPORT_TYPE ReportType,
545 IN USAGE UsagePage,
546 IN USHORT LinkCollection OPTIONAL,
547 IN USAGE Usage,
548 IN PCHAR UsageValue,
549 IN USHORT UsageValueByteLength,
550 IN PHIDP_PREPARSED_DATA PreparsedData,
551 OUT PCHAR Report,
552 IN ULONG ReportLength)
553 {
554 UNIMPLEMENTED
555 ASSERT(FALSE);
556 return STATUS_NOT_IMPLEMENTED;
557 }
558
559 HIDAPI
560 NTSTATUS
561 NTAPI
562 HidP_SetUsageValue(
563 IN HIDP_REPORT_TYPE ReportType,
564 IN USAGE UsagePage,
565 IN USHORT LinkCollection,
566 IN USAGE Usage,
567 IN ULONG UsageValue,
568 IN PHIDP_PREPARSED_DATA PreparsedData,
569 IN OUT PCHAR Report,
570 IN ULONG ReportLength)
571 {
572 UNIMPLEMENTED
573 ASSERT(FALSE);
574 return STATUS_NOT_IMPLEMENTED;
575 }
576
577 HIDAPI
578 NTSTATUS
579 NTAPI
580 HidP_SetScaledUsageValue(
581 IN HIDP_REPORT_TYPE ReportType,
582 IN USAGE UsagePage,
583 IN USHORT LinkCollection OPTIONAL,
584 IN USAGE Usage,
585 IN LONG UsageValue,
586 IN PHIDP_PREPARSED_DATA PreparsedData,
587 IN OUT PCHAR Report,
588 IN ULONG ReportLength)
589 {
590 UNIMPLEMENTED
591 ASSERT(FALSE);
592 return STATUS_NOT_IMPLEMENTED;
593 }
594
595 HIDAPI
596 NTSTATUS
597 NTAPI
598 HidP_SetData(
599 IN HIDP_REPORT_TYPE ReportType,
600 IN PHIDP_DATA DataList,
601 IN OUT PULONG DataLength,
602 IN PHIDP_PREPARSED_DATA PreparsedData,
603 IN OUT PCHAR Report,
604 IN ULONG ReportLength)
605 {
606 UNIMPLEMENTED
607 ASSERT(FALSE);
608 return STATUS_NOT_IMPLEMENTED;
609 }
610
611 HIDAPI
612 ULONG
613 NTAPI
614 HidP_MaxDataListLength(
615 IN HIDP_REPORT_TYPE ReportType,
616 IN PHIDP_PREPARSED_DATA PreparsedData)
617 {
618 UNIMPLEMENTED
619 ASSERT(FALSE);
620 return STATUS_NOT_IMPLEMENTED;
621 }
622
623 HIDAPI
624 NTSTATUS
625 NTAPI
626 HidP_InitializeReportForID(
627 IN HIDP_REPORT_TYPE ReportType,
628 IN UCHAR ReportID,
629 IN PHIDP_PREPARSED_DATA PreparsedData,
630 IN OUT PCHAR Report,
631 IN ULONG ReportLength)
632 {
633 UNIMPLEMENTED
634 ASSERT(FALSE);
635 return STATUS_NOT_IMPLEMENTED;
636 }
637
638 #undef HidP_GetValueCaps
639
640 HIDAPI
641 NTSTATUS
642 NTAPI
643 HidP_GetValueCaps(
644 HIDP_REPORT_TYPE ReportType,
645 PHIDP_VALUE_CAPS ValueCaps,
646 PULONG ValueCapsLength,
647 PHIDP_PREPARSED_DATA PreparsedData)
648 {
649 UNIMPLEMENTED
650 ASSERT(FALSE);
651 return STATUS_NOT_IMPLEMENTED;
652 }
653
654 NTSTATUS
655 NTAPI
656 DriverEntry(
657 IN PDRIVER_OBJECT DriverObject,
658 IN PUNICODE_STRING RegPath)
659 {
660
661 DPRINT1("********* HID PARSE *********\n");
662 return STATUS_SUCCESS;
663 }