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