ReactOS  0.4.13-dev-551-gf37fb1f
api.c File Reference
#include "parser.h"
#include <debug.h>
Include dependency graph for api.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define NTOHS(n)   (((((unsigned short)(n) & 0xFF)) << 8) | (((unsigned short)(n) & 0xFF00) >> 8))
 

Functions

HIDPARSER_STATUS HidParser_GetCollectionUsagePage (IN PVOID CollectionContext, OUT PUSHORT Usage, OUT PUSHORT UsagePage)
 
ULONG HidParser_GetReportLength (IN PVOID CollectionContext, IN UCHAR ReportType)
 
ULONG HidParser_GetReportItemCountFromReportType (IN PVOID CollectionContext, IN UCHAR ReportType)
 
ULONG HidParser_GetReportItemTypeCountFromReportType (IN PVOID CollectionContext, IN UCHAR ReportType, IN ULONG bData)
 
VOID HidParser_InitParser (IN PHIDPARSER_ALLOC_FUNCTION AllocFunction, IN PHIDPARSER_FREE_FUNCTION FreeFunction, IN PHIDPARSER_ZERO_FUNCTION ZeroFunction, IN PHIDPARSER_COPY_FUNCTION CopyFunction, IN PHIDPARSER_DEBUG_FUNCTION DebugFunction, OUT PHID_PARSER Parser)
 
ULONG HidParser_GetMaxUsageListLengthWithReportAndPage (IN PVOID CollectionContext, IN UCHAR ReportType, IN USAGE UsagePage OPTIONAL)
 
HIDPARSER_STATUS HidParser_GetSpecificValueCapsWithReport (IN PHID_PARSER Parser, IN PVOID CollectionContext, IN UCHAR ReportType, IN USHORT UsagePage, IN USHORT Usage, OUT PHIDP_VALUE_CAPS ValueCaps, IN OUT PUSHORT ValueCapsLength)
 
HIDPARSER_STATUS HidParser_GetUsagesWithReport (IN PHID_PARSER Parser, IN PVOID CollectionContext, IN UCHAR ReportType, IN USAGE UsagePage, OUT USAGE *UsageList, IN OUT PULONG UsageLength, IN PCHAR ReportDescriptor, IN ULONG ReportDescriptorLength)
 
ULONG HidParser_UsesReportId (IN PVOID CollectionContext, IN UCHAR ReportType)
 
HIDPARSER_STATUS HidParser_GetUsageValueWithReport (IN PHID_PARSER Parser, IN PVOID CollectionContext, IN UCHAR ReportType, IN USAGE UsagePage, IN USAGE Usage, OUT PULONG UsageValue, IN PCHAR ReportDescriptor, IN ULONG ReportDescriptorLength)
 
HIDPARSER_STATUS HidParser_GetScaledUsageValueWithReport (IN PHID_PARSER Parser, IN PVOID CollectionContext, IN UCHAR ReportType, IN USAGE UsagePage, IN USAGE Usage, OUT PLONG UsageValue, IN PCHAR ReportDescriptor, IN ULONG ReportDescriptorLength)
 
ULONG HidParser_GetScanCodeFromKbdUsage (IN USAGE Usage)
 
ULONG HidParser_GetScanCodeFromCustUsage (IN USAGE Usage)
 
VOID HidParser_DispatchKey (IN PCHAR ScanCodes, IN HIDP_KEYBOARD_DIRECTION KeyAction, IN PHIDP_INSERT_SCANCODES InsertCodesProcedure, IN PVOID InsertCodesContext)
 
HIDPARSER_STATUS HidParser_TranslateKbdUsage (IN PHID_PARSER Parser, IN USAGE Usage, IN HIDP_KEYBOARD_DIRECTION KeyAction, IN OUT PHIDP_KEYBOARD_MODIFIER_STATE ModifierState, IN PHIDP_INSERT_SCANCODES InsertCodesProcedure, IN PVOID InsertCodesContext)
 
HIDPARSER_STATUS HidParser_TranslateCustUsage (IN PHID_PARSER Parser, IN USAGE Usage, IN HIDP_KEYBOARD_DIRECTION KeyAction, IN OUT PHIDP_KEYBOARD_MODIFIER_STATE ModifierState, IN PHIDP_INSERT_SCANCODES InsertCodesProcedure, IN PVOID InsertCodesContext)
 

Variables

static ULONG KeyboardScanCodes [256]
 
struct {
   USAGE   Usage
 
   ULONG   ScanCode
 
CustomerScanCodes []
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file api.c.

◆ NTOHS

#define NTOHS (   n)    (((((unsigned short)(n) & 0xFF)) << 8) | (((unsigned short)(n) & 0xFF00) >> 8))

Definition at line 62 of file api.c.

Function Documentation

◆ HidParser_DispatchKey()

VOID HidParser_DispatchKey ( IN PCHAR  ScanCodes,
IN HIDP_KEYBOARD_DIRECTION  KeyAction,
IN PHIDP_INSERT_SCANCODES  InsertCodesProcedure,
IN PVOID  InsertCodesContext 
)

Definition at line 823 of file api.c.

828 {
829  ULONG Index;
830  ULONG Length = 0;
831 
832  //
833  // count code length
834  //
835  for(Index = 0; Index < sizeof(ULONG); Index++)
836  {
837  if (ScanCodes[Index] == 0)
838  {
839  //
840  // last scan code
841  //
842  break;
843  }
844 
845  //
846  // is this a key break
847  //
848  if (KeyAction == HidP_Keyboard_Break)
849  {
850  //
851  // add break - see USB HID to PS/2 Scan Code Translation Table
852  //
853  ScanCodes[Index] |= 0x80;
854  }
855 
856  //
857  // more scan counts
858  //
859  Length++;
860  }
861 
862  if (Length > 0)
863  {
864  //
865  // dispatch scan codes
866  //
867  InsertCodesProcedure(InsertCodesContext, ScanCodes, Length);
868  }
869 }
static const UCHAR Index[8]
Definition: usbohci.c:18
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
unsigned int ULONG
Definition: retypes.h:1

Referenced by HidParser_TranslateCustUsage(), and HidParser_TranslateKbdUsage().

◆ HidParser_GetCollectionUsagePage()

HIDPARSER_STATUS HidParser_GetCollectionUsagePage ( IN PVOID  CollectionContext,
OUT PUSHORT  Usage,
OUT PUSHORT  UsagePage 
)

Definition at line 65 of file api.c.

69 {
70  PHID_COLLECTION Collection;
71 
72  //
73  // find collection
74  //
75  Collection = HidParser_GetCollectionFromContext(CollectionContext);
76  if (!Collection)
77  {
78  //
79  // collection not found
80  //
82  }
83 
84  //
85  // store result
86  //
87  *UsagePage = (Collection->Usage >> 16);
88  *Usage = (Collection->Usage & 0xFFFF);
90 }
PHID_COLLECTION HidParser_GetCollectionFromContext(IN PVOID Context)
Definition: context.c:292
_Must_inspect_result_ _In_ USAGE UsagePage
Definition: hidpi.h:382
USAGE Usage
Definition: api.c:38

Referenced by HidParser_GetCaps(), and HidParser_GetCollectionDescription().

◆ HidParser_GetMaxUsageListLengthWithReportAndPage()

ULONG HidParser_GetMaxUsageListLengthWithReportAndPage ( IN PVOID  CollectionContext,
IN UCHAR  ReportType,
IN USAGE UsagePage  OPTIONAL 
)

Definition at line 227 of file api.c.

231 {
232  ULONG Index;
233  PHID_REPORT Report;
234  ULONG ItemCount = 0;
235  USHORT CurrentUsagePage;
236 
237  //
238  // get report
239  //
240  Report = HidParser_GetReportInCollection(CollectionContext, ReportType);
241  if (!Report)
242  {
243  //
244  // no such report
245  //
246  return 0;
247  }
248 
249  for(Index = 0; Index < Report->ItemCount; Index++)
250  {
251  //
252  // check usage page
253  //
254  CurrentUsagePage = (Report->Items[Index].UsageMinimum >> 16);
255  if (CurrentUsagePage == UsagePage && Report->Items[Index].HasData)
256  {
257  //
258  // found item
259  //
260  ItemCount++;
261  }
262  }
263 
264  //
265  // done
266  //
267  return ItemCount;
268 }
HID_REPORT_ITEM Items[1]
Definition: parser.h:227
ULONG UsageMinimum
Definition: parser.h:195
_Must_inspect_result_ _In_ USAGE UsagePage
Definition: hidpi.h:382
UCHAR HasData
Definition: parser.h:190
static const UCHAR Index[8]
Definition: usbohci.c:18
ULONG ItemCount
Definition: parser.h:225
unsigned short USHORT
Definition: pedump.c:61
PHID_REPORT HidParser_GetReportInCollection(IN PVOID Context, IN UCHAR ReportType)
Definition: context.c:279
unsigned int ULONG
Definition: retypes.h:1

Referenced by HidParser_MaxUsageListLength().

◆ HidParser_GetReportItemCountFromReportType()

ULONG HidParser_GetReportItemCountFromReportType ( IN PVOID  CollectionContext,
IN UCHAR  ReportType 
)

Definition at line 132 of file api.c.

135 {
136  PHID_REPORT Report;
137 
138  //
139  // get report
140  //
141  Report = HidParser_GetReportInCollection(CollectionContext, ReportType);
142  if (!Report)
143  {
144  //
145  // no such report
146  //
147  return 0;
148  }
149 
150  //
151  // return report item count
152  //
153  return Report->ItemCount;
154 }
ULONG ItemCount
Definition: parser.h:225
PHID_REPORT HidParser_GetReportInCollection(IN PVOID Context, IN UCHAR ReportType)
Definition: context.c:279

Referenced by HidParser_GetCaps().

◆ HidParser_GetReportItemTypeCountFromReportType()

ULONG HidParser_GetReportItemTypeCountFromReportType ( IN PVOID  CollectionContext,
IN UCHAR  ReportType,
IN ULONG  bData 
)

Definition at line 158 of file api.c.

162 {
163  ULONG Index;
164  PHID_REPORT Report;
165  ULONG ItemCount = 0;
166 
167  //
168  // get report
169  //
170  Report = HidParser_GetReportInCollection(CollectionContext, ReportType);
171  if (!Report)
172  {
173  //
174  // no such report
175  //
176  return 0;
177  }
178 
179  //
180  // enumerate all items
181  //
182  for(Index = 0; Index < Report->ItemCount; Index++)
183  {
184  //
185  // check item type
186  //
187  if (Report->Items[Index].HasData && bData)
188  {
189  //
190  // found data item
191  //
192  ItemCount++;
193  }
194  else if (Report->Items[Index].HasData == FALSE && bData == FALSE)
195  {
196  //
197  // found value item
198  //
199  ItemCount++;
200  }
201  }
202 
203  //
204  // no report items
205  //
206  return ItemCount;
207 }
HID_REPORT_ITEM Items[1]
Definition: parser.h:227
UCHAR HasData
Definition: parser.h:190
static const UCHAR Index[8]
Definition: usbohci.c:18
ULONG ItemCount
Definition: parser.h:225
PHID_REPORT HidParser_GetReportInCollection(IN PVOID Context, IN UCHAR ReportType)
Definition: context.c:279
unsigned int ULONG
Definition: retypes.h:1

Referenced by HidParser_GetCaps().

◆ HidParser_GetReportLength()

ULONG HidParser_GetReportLength ( IN PVOID  CollectionContext,
IN UCHAR  ReportType 
)

Definition at line 93 of file api.c.

96 {
97  PHID_REPORT Report;
99 
100  //
101  // get first report
102  //
103  Report = HidParser_GetReportInCollection(CollectionContext, ReportType);
104  if (!Report)
105  {
106  //
107  // no report found
108  //
109  return 0;
110  }
111 
112  //
113  // get report length
114  //
115  ReportLength = Report->ReportSize;
116 
117  //
118  // done
119  //
120  if (ReportLength)
121  {
122  //
123  // byte aligned length
124  //
125  ASSERT(ReportLength % 8 == 0);
126  return ReportLength / 8;
127  }
128  return ReportLength;
129 }
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_Must_inspect_result_ _Out_writes_to_ DataLength PHIDP_DATA _Inout_ PULONG _In_ PHIDP_PREPARSED_DATA _In_ ULONG ReportLength
Definition: hidpi.h:337
ULONG ReportSize
Definition: parser.h:224
PHID_REPORT HidParser_GetReportInCollection(IN PVOID Context, IN UCHAR ReportType)
Definition: context.c:279
unsigned int ULONG
Definition: retypes.h:1

Referenced by HidParser_GetCaps(), and HidParser_GetCollectionDescription().

◆ HidParser_GetScaledUsageValueWithReport()

HIDPARSER_STATUS HidParser_GetScaledUsageValueWithReport ( IN PHID_PARSER  Parser,
IN PVOID  CollectionContext,
IN UCHAR  ReportType,
IN USAGE  UsagePage,
IN USAGE  Usage,
OUT PLONG  UsageValue,
IN PCHAR  ReportDescriptor,
IN ULONG  ReportDescriptorLength 
)

Definition at line 666 of file api.c.

675 {
676  ULONG Index;
677  PHID_REPORT Report;
678  USHORT CurrentUsagePage;
679  PHID_REPORT_ITEM ReportItem;
680  ULONG Data;
681 
682  //
683  // get report
684  //
685  Report = HidParser_GetReportInCollection(CollectionContext, ReportType);
686  if (!Report)
687  {
688  //
689  // no such report
690  //
692  }
693 
694  if (Report->ReportSize / 8 != (ReportDescriptorLength - 1))
695  {
696  //
697  // invalid report descriptor length
698  //
700  }
701 
702  for (Index = 0; Index < Report->ItemCount; Index++)
703  {
704  //
705  // get report item
706  //
707  ReportItem = &Report->Items[Index];
708 
709  //
710  // check usage page
711  //
712  CurrentUsagePage = (ReportItem->UsageMinimum >> 16);
713 
714  //
715  // does usage page match
716  //
717  if (UsagePage != CurrentUsagePage)
718  continue;
719 
720  //
721  // does the usage match
722  //
723  if (Usage != (ReportItem->UsageMinimum & 0xFFFF))
724  continue;
725 
726  //
727  // check if the specified usage is activated
728  //
729  ASSERT(ReportItem->ByteOffset < ReportDescriptorLength);
730 
731  //
732  // one extra shift for skipping the prepended report id
733  //
734  Data = 0;
735  Parser->Copy(&Data, &ReportDescriptor[ReportItem->ByteOffset + 1], min(sizeof(ULONG), ReportDescriptorLength - (ReportItem->ByteOffset + 1)));
736 
737  //
738  // shift data
739  //
740  Data >>= ReportItem->Shift;
741 
742  //
743  // clear unwanted bits
744  //
745  Data &= ReportItem->Mask;
746 
747  if (ReportItem->Minimum > ReportItem->Maximum)
748  {
749  //
750  // logical boundaries are signed values
751  //
752 
753  // FIXME: scale with physical min/max
754  if ((Data & ~(ReportItem->Mask >> 1)) != 0)
755  {
756  Data |= ~ReportItem->Mask;
757  }
758  }
759  else
760  {
761  // logical boundaries are absolute values
763  }
764 
765  //
766  // store result
767  //
768  *UsageValue = Data;
770  }
771 
772  //
773  // usage not found
774  //
776 }
HID_REPORT_ITEM Items[1]
Definition: parser.h:227
ULONG UsageMinimum
Definition: parser.h:195
_In_ LPGUID _In_ PVOID Data
Definition: classpnp.h:778
_Must_inspect_result_ _In_ USAGE UsagePage
Definition: hidpi.h:382
static const UCHAR Index[8]
Definition: usbohci.c:18
USAGE Usage
Definition: api.c:38
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
ULONG Maximum
Definition: parser.h:194
ULONG Minimum
Definition: parser.h:193
ULONG ReportSize
Definition: parser.h:224
ULONG ItemCount
Definition: parser.h:225
unsigned short USHORT
Definition: pedump.c:61
ULONG ByteOffset
Definition: parser.h:186
#define min(a, b)
Definition: monoChain.cc:55
UCHAR Shift
Definition: parser.h:187
PHID_REPORT HidParser_GetReportInCollection(IN PVOID Context, IN UCHAR ReportType)
Definition: context.c:279
unsigned int ULONG
Definition: retypes.h:1
ULONG Mask
Definition: parser.h:188

Referenced by HidParser_GetScaledUsageValue().

◆ HidParser_GetScanCodeFromCustUsage()

ULONG HidParser_GetScanCodeFromCustUsage ( IN USAGE  Usage)

Definition at line 797 of file api.c.

799 {
800  ULONG i;
801 
802  //
803  // find usage in array
804  //
805  for (i = 0; i < sizeof(CustomerScanCodes) / sizeof(CustomerScanCodes[0]); ++i)
806  {
807  if (CustomerScanCodes[i].Usage == Usage)
808  {
809  //
810  // valid usage
811  //
812  return CustomerScanCodes[i].ScanCode;
813  }
814  }
815 
816  //
817  // invalid usage
818  //
819  return 0;
820 }
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
USAGE Usage
Definition: api.c:38
static struct @3916 CustomerScanCodes[]
unsigned int ULONG
Definition: retypes.h:1

Referenced by HidParser_TranslateCustUsage().

◆ HidParser_GetScanCodeFromKbdUsage()

ULONG HidParser_GetScanCodeFromKbdUsage ( IN USAGE  Usage)

Definition at line 779 of file api.c.

781 {
782  if (Usage < sizeof(KeyboardScanCodes) / sizeof(KeyboardScanCodes[0]))
783  {
784  //
785  // valid usage
786  //
787  return KeyboardScanCodes[Usage];
788  }
789 
790  //
791  // invalid usage
792  //
793  return 0;
794 }
static ULONG KeyboardScanCodes[256]
Definition: api.c:16
USAGE Usage
Definition: api.c:38

Referenced by HidParser_TranslateKbdUsage().

◆ HidParser_GetSpecificValueCapsWithReport()

HIDPARSER_STATUS HidParser_GetSpecificValueCapsWithReport ( IN PHID_PARSER  Parser,
IN PVOID  CollectionContext,
IN UCHAR  ReportType,
IN USHORT  UsagePage,
IN USHORT  Usage,
OUT PHIDP_VALUE_CAPS  ValueCaps,
IN OUT PUSHORT  ValueCapsLength 
)

Definition at line 271 of file api.c.

279 {
280  ULONG Index;
281  PHID_REPORT Report;
282  USHORT ItemCount = 0;
283  USHORT CurrentUsagePage;
284  USHORT CurrentUsage;
285 
286  //
287  // get report
288  //
289  Report = HidParser_GetReportInCollection(CollectionContext, ReportType);
290  if (!Report)
291  {
292  //
293  // no such report
294  //
296  }
297 
298  for(Index = 0; Index < Report->ItemCount; Index++)
299  {
300  //
301  // check usage page
302  //
303  CurrentUsagePage = (Report->Items[Index].UsageMinimum >> 16);
304  CurrentUsage = (Report->Items[Index].UsageMinimum & 0xFFFF);
305 
306  if ((Usage == CurrentUsage && UsagePage == CurrentUsagePage) || (Usage == 0 && UsagePage == CurrentUsagePage) || (Usage == CurrentUsage && UsagePage == 0) || (Usage == 0 && UsagePage == 0))
307  {
308  //
309  // check if there is enough place for the caps
310  //
311  if (ItemCount < *ValueCapsLength)
312  {
313  //
314  // zero caps
315  //
316  Parser->Zero(&ValueCaps[ItemCount], sizeof(HIDP_VALUE_CAPS));
317 
318  //
319  // init caps
320  //
321  ValueCaps[ItemCount].UsagePage = CurrentUsagePage;
322  ValueCaps[ItemCount].ReportID = Report->ReportID;
323  ValueCaps[ItemCount].LogicalMin = Report->Items[Index].Minimum;
324  ValueCaps[ItemCount].LogicalMax = Report->Items[Index].Maximum;
325  ValueCaps[ItemCount].IsAbsolute = !Report->Items[Index].Relative;
326  ValueCaps[ItemCount].BitSize = Report->Items[Index].BitCount;
327 
328  //
329  // FIXME: FILLMEIN
330  //
331  }
332 
333 
334  //
335  // found item
336  //
337  ItemCount++;
338  }
339  }
340 
341  //
342  // store result
343  //
344  *ValueCapsLength = ItemCount;
345 
346  if (ItemCount)
347  {
348  //
349  // success
350  //
352  }
353 
354  //
355  // item not found
356  //
358 }
UCHAR ReportID
Definition: parser.h:223
BOOLEAN IsAbsolute
Definition: hidpi.h:211
HID_REPORT_ITEM Items[1]
Definition: parser.h:227
USAGE UsagePage
Definition: hidpi.h:201
USHORT BitSize
Definition: hidpi.h:214
ULONG UsageMinimum
Definition: parser.h:195
_Must_inspect_result_ _In_ USAGE _In_ USHORT _In_ USAGE _Out_ PHIDP_VALUE_CAPS ValueCaps
Definition: hidpi.h:396
UCHAR ReportID
Definition: hidpi.h:202
UCHAR Relative
Definition: parser.h:192
LONG LogicalMin
Definition: hidpi.h:219
_Must_inspect_result_ _In_ USAGE UsagePage
Definition: hidpi.h:382
UCHAR BitCount
Definition: parser.h:189
static const UCHAR Index[8]
Definition: usbohci.c:18
USAGE Usage
Definition: api.c:38
ULONG Maximum
Definition: parser.h:194
ULONG Minimum
Definition: parser.h:193
ULONG ItemCount
Definition: parser.h:225
LONG LogicalMax
Definition: hidpi.h:219
unsigned short USHORT
Definition: pedump.c:61
PHID_REPORT HidParser_GetReportInCollection(IN PVOID Context, IN UCHAR ReportType)
Definition: context.c:279
unsigned int ULONG
Definition: retypes.h:1
_Must_inspect_result_ _In_ USAGE _In_ USHORT _In_ USAGE _Out_ PHIDP_VALUE_CAPS _Inout_ PUSHORT ValueCapsLength
Definition: hidpi.h:396

Referenced by HidParser_GetSpecificValueCaps().

◆ HidParser_GetUsagesWithReport()

HIDPARSER_STATUS HidParser_GetUsagesWithReport ( IN PHID_PARSER  Parser,
IN PVOID  CollectionContext,
IN UCHAR  ReportType,
IN USAGE  UsagePage,
OUT USAGE UsageList,
IN OUT PULONG  UsageLength,
IN PCHAR  ReportDescriptor,
IN ULONG  ReportDescriptorLength 
)

Definition at line 361 of file api.c.

370 {
371  ULONG Index;
372  PHID_REPORT Report;
373  ULONG ItemCount = 0;
374  USHORT CurrentUsagePage;
375  PHID_REPORT_ITEM ReportItem;
376  UCHAR Activated;
377  ULONG Data;
378  PUSAGE_AND_PAGE UsageAndPage = NULL;
379 
380  //
381  // get report
382  //
383  Report = HidParser_GetReportInCollection(CollectionContext, ReportType);
384  if (!Report)
385  {
386  //
387  // no such report
388  //
390  }
391 
392  if (Report->ReportSize / 8 != (ReportDescriptorLength - 1))
393  {
394  //
395  // invalid report descriptor length
396  //
398  }
399 
400  //
401  // cast to usage and page
402  //
404  {
405  //
406  // the caller requested any set usages
407  //
408  UsageAndPage = (PUSAGE_AND_PAGE)UsageList;
409  }
410 
411  for(Index = 0; Index < Report->ItemCount; Index++)
412  {
413  //
414  // get report item
415  //
416  ReportItem = &Report->Items[Index];
417 
418  //
419  // does it have data
420  //
421  if (!ReportItem->HasData)
422  continue;
423 
424  //
425  // check usage page
426  //
427  CurrentUsagePage = (ReportItem->UsageMinimum >> 16);
428 
430  {
431  //
432  // does usage match
433  //
434  if (UsagePage != CurrentUsagePage)
435  continue;
436  }
437 
438  //
439  // check if the specified usage is activated
440  //
441  ASSERT(ReportItem->ByteOffset < ReportDescriptorLength);
442  ASSERT(ReportItem->BitCount <= 8);
443 
444  //
445  // one extra shift for skipping the prepended report id
446  //
447  Data = ReportDescriptor[ReportItem->ByteOffset + 1];
448 
449  //
450  // shift data
451  //
452  Data >>= ReportItem->Shift;
453 
454  //
455  // clear unwanted bits
456  //
457  Data &= ReportItem->Mask;
458 
459  //
460  // is it activated
461  //
462  Activated = (Data != 0);
463 
464  if (!Activated)
465  continue;
466 
467  //
468  // is there enough space for the usage
469  //
470  if (ItemCount >= *UsageLength)
471  {
472  ItemCount++;
473  continue;
474  }
475 
477  {
478  //
479  // store item
480  //
481  UsageList[ItemCount] = (ReportItem->UsageMinimum & 0xFFFF);
482  }
483  else
484  {
485  //
486  // store usage and page
487  //
488  if (ReportItem->BitCount == 1)
489  {
490  //
491  // use usage minimum
492  //
493  UsageAndPage[ItemCount].Usage =(ReportItem->UsageMinimum & 0xFFFF);
494  }
495  else
496  {
497  //
498  // use value from control
499  //
500  UsageAndPage[ItemCount].Usage = (USHORT)Data;
501  }
502  UsageAndPage[ItemCount].UsagePage = CurrentUsagePage;
503  }
504  ItemCount++;
505  }
506 
507  if (ItemCount > *UsageLength)
508  {
509  //
510  // list too small
511  //
513  }
514 
516  {
517  //
518  // success, clear rest of array
519  //
520  Parser->Zero(&UsageAndPage[ItemCount], (*UsageLength - ItemCount) * sizeof(USAGE_AND_PAGE));
521  }
522  else
523  {
524  //
525  // success, clear rest of array
526  //
527  Parser->Zero(&UsageList[ItemCount], (*UsageLength - ItemCount) * sizeof(USAGE));
528  }
529 
530 
531  //
532  // store result size
533  //
534  *UsageLength = ItemCount;
535 
536  //
537  // done
538  //
540 }
USAGE UsagePage
Definition: hidpi.h:80
HID_REPORT_ITEM Items[1]
Definition: parser.h:227
USAGE Usage
Definition: hidpi.h:79
_Must_inspect_result_ _In_ USHORT _Inout_updates_to_ UsageLength PUSAGE_AND_PAGE _Inout_ ULONG * UsageLength
Definition: hidpi.h:425
ULONG UsageMinimum
Definition: parser.h:195
smooth NULL
Definition: ftsmooth.c:416
_In_ LPGUID _In_ PVOID Data
Definition: classpnp.h:778
_Must_inspect_result_ _In_ USAGE UsagePage
Definition: hidpi.h:382
UCHAR BitCount
Definition: parser.h:189
UCHAR HasData
Definition: parser.h:190
static const UCHAR Index[8]
Definition: usbohci.c:18
USHORT USAGE
Definition: hidusage.h:30
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
unsigned char UCHAR
Definition: xmlstorage.h:181
ULONG ReportSize
Definition: parser.h:224
ULONG ItemCount
Definition: parser.h:225
#define HID_USAGE_PAGE_UNDEFINED
Definition: hidusage.h:175
unsigned short USHORT
Definition: pedump.c:61
ULONG ByteOffset
Definition: parser.h:186
UCHAR Shift
Definition: parser.h:187
struct _USAGE_AND_PAGE * PUSAGE_AND_PAGE
PHID_REPORT HidParser_GetReportInCollection(IN PVOID Context, IN UCHAR ReportType)
Definition: context.c:279
unsigned int ULONG
Definition: retypes.h:1
ULONG Mask
Definition: parser.h:188

Referenced by HidParser_GetUsages().

◆ HidParser_GetUsageValueWithReport()

HIDPARSER_STATUS HidParser_GetUsageValueWithReport ( IN PHID_PARSER  Parser,
IN PVOID  CollectionContext,
IN UCHAR  ReportType,
IN USAGE  UsagePage,
IN USAGE  Usage,
OUT PULONG  UsageValue,
IN PCHAR  ReportDescriptor,
IN ULONG  ReportDescriptorLength 
)

Definition at line 569 of file api.c.

578 {
579  ULONG Index;
580  PHID_REPORT Report;
581  USHORT CurrentUsagePage;
582  PHID_REPORT_ITEM ReportItem;
583  ULONG Data;
584 
585  //
586  // get report
587  //
588  Report = HidParser_GetReportInCollection(CollectionContext, ReportType);
589  if (!Report)
590  {
591  //
592  // no such report
593  //
595  }
596 
597  if (Report->ReportSize / 8 != (ReportDescriptorLength - 1))
598  {
599  //
600  // invalid report descriptor length
601  //
603  }
604 
605  for (Index = 0; Index < Report->ItemCount; Index++)
606  {
607  //
608  // get report item
609  //
610  ReportItem = &Report->Items[Index];
611 
612  //
613  // check usage page
614  //
615  CurrentUsagePage = (ReportItem->UsageMinimum >> 16);
616 
617  //
618  // does usage page match
619  //
620  if (UsagePage != CurrentUsagePage)
621  continue;
622 
623  //
624  // does the usage match
625  //
626  if (Usage != (ReportItem->UsageMinimum & 0xFFFF))
627  continue;
628 
629  //
630  // check if the specified usage is activated
631  //
632  ASSERT(ReportItem->ByteOffset < ReportDescriptorLength);
633 
634  //
635  // one extra shift for skipping the prepended report id
636  //
637  Data = 0;
638  Parser->Copy(&Data, &ReportDescriptor[ReportItem->ByteOffset + 1], min(sizeof(ULONG), ReportDescriptorLength - (ReportItem->ByteOffset + 1)));
639 
640  //
641  // shift data
642  //
643  Data >>= ReportItem->Shift;
644 
645  //
646  // clear unwanted bits
647  //
648  Data &= ReportItem->Mask;
649 
650  //
651  // store result
652  //
653  *UsageValue = Data;
655  }
656 
657  //
658  // usage not found
659  //
661 }
HID_REPORT_ITEM Items[1]
Definition: parser.h:227
ULONG UsageMinimum
Definition: parser.h:195
_In_ LPGUID _In_ PVOID Data
Definition: classpnp.h:778
_Must_inspect_result_ _In_ USAGE UsagePage
Definition: hidpi.h:382
static const UCHAR Index[8]
Definition: usbohci.c:18
USAGE Usage
Definition: api.c:38
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
ULONG ReportSize
Definition: parser.h:224
ULONG ItemCount
Definition: parser.h:225
unsigned short USHORT
Definition: pedump.c:61
ULONG ByteOffset
Definition: parser.h:186
#define min(a, b)
Definition: monoChain.cc:55
UCHAR Shift
Definition: parser.h:187
PHID_REPORT HidParser_GetReportInCollection(IN PVOID Context, IN UCHAR ReportType)
Definition: context.c:279
unsigned int ULONG
Definition: retypes.h:1
ULONG Mask
Definition: parser.h:188

Referenced by HidParser_GetUsageValue().

◆ HidParser_InitParser()

VOID HidParser_InitParser ( IN PHIDPARSER_ALLOC_FUNCTION  AllocFunction,
IN PHIDPARSER_FREE_FUNCTION  FreeFunction,
IN PHIDPARSER_ZERO_FUNCTION  ZeroFunction,
IN PHIDPARSER_COPY_FUNCTION  CopyFunction,
IN PHIDPARSER_DEBUG_FUNCTION  DebugFunction,
OUT PHID_PARSER  Parser 
)

Definition at line 211 of file api.c.

218 {
219  Parser->Alloc = AllocFunction;
220  Parser->Free = FreeFunction;
221  Parser->Zero = ZeroFunction;
222  Parser->Copy = CopyFunction;
223  Parser->Debug = DebugFunction;
224 }
VOID NTAPI FreeFunction(IN PVOID Item)
Definition: hid.c:53
VOID NTAPI ZeroFunction(IN PVOID Item, IN ULONG ItemSize)
Definition: hid.c:61
VOID __cdecl DebugFunction(IN LPCSTR FormatStr,...)
Definition: hid.c:80
PVOID NTAPI AllocFunction(IN ULONG ItemSize)
Definition: hid.c:45
_Inout_ PSIZE_T _In_opt_ PMDLX _In_ MM_ROTATE_DIRECTION _In_ PMM_ROTATE_COPY_CALLBACK_FUNCTION CopyFunction
Definition: mmfuncs.h:773

Referenced by HidP_FreeCollectionDescription(), HidP_GetCaps(), HidP_GetCollectionDescription(), HidP_GetScaledUsageValue(), HidP_GetSpecificValueCaps(), HidP_GetUsages(), HidP_GetUsageValue(), HidP_MaxUsageListLength(), and HidP_TranslateUsageAndPagesToI8042ScanCodes().

◆ HidParser_TranslateCustUsage()

HIDPARSER_STATUS HidParser_TranslateCustUsage ( IN PHID_PARSER  Parser,
IN USAGE  Usage,
IN HIDP_KEYBOARD_DIRECTION  KeyAction,
IN OUT PHIDP_KEYBOARD_MODIFIER_STATE  ModifierState,
IN PHIDP_INSERT_SCANCODES  InsertCodesProcedure,
IN PVOID  InsertCodesContext 
)

Definition at line 935 of file api.c.

942 {
943  ULONG ScanCode;
944 
945  //
946  // get scan code
947  //
949  if (!ScanCode)
950  {
951  //
952  // invalid lookup or no scan code available
953  //
954  DPRINT1("No Scan code for Usage %x\n", Usage);
956  }
957 
958  if (ScanCode & 0xFF00)
959  {
960  //
961  // swap scan code
962  //
964  }
965 
966  //
967  // FIXME: translate modifier states
968  //
969  HidParser_DispatchKey((PCHAR)&ScanCode, KeyAction, InsertCodesProcedure, InsertCodesContext);
970 
971  //
972  // done
973  //
975 }
signed char * PCHAR
Definition: retypes.h:7
ULONG ScanCode
Definition: api.c:39
ULONG HidParser_GetScanCodeFromCustUsage(IN USAGE Usage)
Definition: api.c:797
#define NTOHS(n)
Definition: api.c:62
USAGE Usage
Definition: api.c:38
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
VOID HidParser_DispatchKey(IN PCHAR ScanCodes, IN HIDP_KEYBOARD_DIRECTION KeyAction, IN PHIDP_INSERT_SCANCODES InsertCodesProcedure, IN PVOID InsertCodesContext)
Definition: api.c:823

Referenced by HidParser_TranslateUsageAndPagesToI8042ScanCodes().

◆ HidParser_TranslateKbdUsage()

HIDPARSER_STATUS HidParser_TranslateKbdUsage ( IN PHID_PARSER  Parser,
IN USAGE  Usage,
IN HIDP_KEYBOARD_DIRECTION  KeyAction,
IN OUT PHIDP_KEYBOARD_MODIFIER_STATE  ModifierState,
IN PHIDP_INSERT_SCANCODES  InsertCodesProcedure,
IN PVOID  InsertCodesContext 
)

Definition at line 872 of file api.c.

879 {
880  ULONG ScanCode;
881  CHAR FakeShift[] = {0xE0, 0x2A, 0x00};
882  CHAR FakeCtrl[] = {0xE1, 0x1D, 0x00};
883 
884  //
885  // get scan code
886  //
888  if (!ScanCode)
889  {
890  //
891  // invalid lookup or no scan code available
892  //
893  DPRINT1("No Scan code for Usage %x\n", Usage);
895  }
896 
897  if (ScanCode & 0xFF00)
898  {
899  //
900  // swap scan code
901  //
903  }
904 
905  if (Usage == 0x46 && KeyAction == HidP_Keyboard_Make)
906  {
907  // Print Screen generates additional FakeShift
908  HidParser_DispatchKey(FakeShift, KeyAction, InsertCodesProcedure, InsertCodesContext);
909  }
910 
911  if (Usage == 0x48)
912  {
913  // Pause/Break generates additional FakeCtrl. Note: it's always before key press/release.
914  HidParser_DispatchKey(FakeCtrl, KeyAction, InsertCodesProcedure, InsertCodesContext);
915  }
916 
917  //
918  // FIXME: translate modifier states
919  //
920  HidParser_DispatchKey((PCHAR)&ScanCode, KeyAction, InsertCodesProcedure, InsertCodesContext);
921 
922  if (Usage == 0x46 && KeyAction == HidP_Keyboard_Break)
923  {
924  // Print Screen generates additional FakeShift
925  HidParser_DispatchKey(FakeShift, KeyAction, InsertCodesProcedure, InsertCodesContext);
926  }
927 
928  //
929  // done
930  //
932 }
signed char * PCHAR
Definition: retypes.h:7
ULONG ScanCode
Definition: api.c:39
char CHAR
Definition: xmlstorage.h:175
ULONG HidParser_GetScanCodeFromKbdUsage(IN USAGE Usage)
Definition: api.c:779
#define NTOHS(n)
Definition: api.c:62
USAGE Usage
Definition: api.c:38
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
VOID HidParser_DispatchKey(IN PCHAR ScanCodes, IN HIDP_KEYBOARD_DIRECTION KeyAction, IN PHIDP_INSERT_SCANCODES InsertCodesProcedure, IN PVOID InsertCodesContext)
Definition: api.c:823

Referenced by HidParser_TranslateUsageAndPagesToI8042ScanCodes().

◆ HidParser_UsesReportId()

ULONG HidParser_UsesReportId ( IN PVOID  CollectionContext,
IN UCHAR  ReportType 
)

Definition at line 543 of file api.c.

546 {
547  PHID_REPORT Report;
548 
549  //
550  // get report
551  //
552  Report = HidParser_GetReportInCollection(CollectionContext, ReportType);
553  if (!Report)
554  {
555  //
556  // no such report
557  //
558  return 0;
559  }
560 
561  //
562  // returns true when report id != 0
563  //
564  return (Report->ReportID != 0);
565 
566 }
UCHAR ReportID
Definition: parser.h:223
PHID_REPORT HidParser_GetReportInCollection(IN PVOID Context, IN UCHAR ReportType)
Definition: context.c:279

Referenced by HidParser_GetCollectionDescription().

Variable Documentation

◆ CustomerScanCodes

struct { ... } CustomerScanCodes[]
Initial value:
=
{
{ 0x00B5, 0xE019 },
{ 0x00B6, 0xE010 },
{ 0x00B7, 0xE024 },
{ 0x00CD, 0xE022 },
{ 0x00E2, 0xE020 },
{ 0x00E9, 0xE030 },
{ 0x00EA, 0xE02E },
{ 0x0183, 0xE06D },
{ 0x018A, 0xE06C },
{ 0x0192, 0xE021 },
{ 0x0194, 0xE06B },
{ 0x0221, 0xE065 },
{ 0x0223, 0xE032 },
{ 0x0224, 0xE06A },
{ 0x0225, 0xE069 },
{ 0x0226, 0xE068 },
{ 0x0227, 0xE067 },
{ 0x022A, 0xE066 },
}

Referenced by HidParser_GetScanCodeFromCustUsage().

◆ KeyboardScanCodes

ULONG KeyboardScanCodes[256]
static
Initial value:
=
{
0x0000, 0x0000, 0x0000, 0x0000, 0x001e, 0x0030, 0x002e, 0x0020, 0x0012, 0x0021, 0x0022, 0x0023, 0x0017, 0x0024, 0x0025, 0x0026,
0x0032, 0x0031, 0x0018, 0x0019, 0x0010, 0x0013, 0x001f, 0x0014, 0x0016, 0x002f, 0x0011, 0x002d, 0x0015, 0x002c, 0x0002, 0x0003,
0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x001c, 0x0001, 0x000e, 0x000f, 0x0039, 0x000c, 0x000d, 0x001a,
0x001b, 0x002b, 0x002b, 0x0027, 0x0028, 0x0029, 0x0033, 0x0034, 0x0035, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f, 0x0040,
0x0041, 0x0042, 0x0043, 0x0044, 0x0057, 0x0058, 0xE037, 0x0046, 0x0045, 0xE052, 0xE047, 0xE049, 0xE053, 0xE04F, 0xE051, 0xE04D,
0xE04B, 0xE050, 0xE048, 0x0045, 0xE035, 0x0037, 0x004a, 0x004e, 0xE01C, 0x004f, 0x0050, 0x0051, 0x004b, 0x004c, 0x004d, 0x0047,
0x0048, 0x0049, 0x0052, 0x0053, 0x0056, 0xE05D, 0xE05E, 0x0075, 0x00b7, 0x00b8, 0x00b9, 0x00ba, 0x00bb, 0x00bc, 0x00bd, 0x00be,
0x00bf, 0x00c0, 0x00c1, 0x00c2, 0x0086, 0x008a, 0x0082, 0x0084, 0x0080, 0x0081, 0x0083, 0x0089, 0x0085, 0x0087, 0x0088, 0x0071,
0x0073, 0x0072, 0x0000, 0x0000, 0x0000, 0x0079, 0x0000, 0x0059, 0x005d, 0x007c, 0x005c, 0x005e, 0x005f, 0x0000, 0x0000, 0x0000,
0x007a, 0x007b, 0x005a, 0x005b, 0x0055, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x001D, 0x002A, 0x0038, 0xE05B, 0xE01D, 0x0036, 0xE038, 0xE05C, 0x00a4, 0x00a6, 0x00a5, 0x00a3, 0x00a1, 0x0073, 0x0072, 0x0071,
0x0096, 0x009e, 0x009f, 0x0080, 0x0088, 0x00b1, 0x00b2, 0x00b0, 0x008e, 0x0098, 0x00ad, 0x008c, 0x0000, 0x0000, 0x0000, 0x0000,
}

Definition at line 16 of file api.c.

Referenced by HidParser_GetScanCodeFromKbdUsage().

◆ ScanCode

◆ Usage