ReactOS 0.4.16-dev-122-g325d74c
parser.h File Reference
#include <wdm.h>
#include <hidpddi.h>
#include "hidparser.h"
#include "hidp.h"
#include <pshpack1.h>
#include <poppack.h>
Include dependency graph for parser.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ITEM_PREFIX
 
struct  SHORT_ITEM
 
struct  LONG_ITEM
 
struct  MAIN_ITEM_DATA
 
struct  __GLOBAL_ITEM_STATE_
 
struct  usage_value
 
struct  LOCAL_ITEM_STATE
 
struct  HID_REPORT_ITEM
 
struct  __HID_COLLECTION__
 
struct  _HID_REPORT
 
struct  HID_PARSER_CONTEXT
 

Macros

#define _HIDPI_
 
#define _HIDPI_NO_FUNCTION_MACROS_
 
#define HID_REPORT_TYPE_ANY   0x07
 
#define ITEM_TYPE_MAIN   0x0
 
#define ITEM_TYPE_GLOBAL   0x1
 
#define ITEM_TYPE_LOCAL   0x2
 
#define ITEM_TYPE_LONG   0x3
 
#define ITEM_TAG_MAIN_INPUT   0x8
 
#define ITEM_TAG_MAIN_OUTPUT   0x9
 
#define ITEM_TAG_MAIN_FEATURE   0xb
 
#define ITEM_TAG_MAIN_COLLECTION   0xa
 
#define ITEM_TAG_MAIN_END_COLLECTION   0xc
 
#define ITEM_TAG_GLOBAL_USAGE_PAGE   0x0
 
#define ITEM_TAG_GLOBAL_LOGICAL_MINIMUM   0x1
 
#define ITEM_TAG_GLOBAL_LOGICAL_MAXIMUM   0x2
 
#define ITEM_TAG_GLOBAL_PHYSICAL_MINIMUM   0x3
 
#define ITEM_TAG_GLOBAL_PHYSICAL_MAXIMUM   0x4
 
#define ITEM_TAG_GLOBAL_UNIT_EXPONENT   0x5
 
#define ITEM_TAG_GLOBAL_UNIT   0x6
 
#define ITEM_TAG_GLOBAL_REPORT_SIZE   0x7
 
#define ITEM_TAG_GLOBAL_REPORT_ID   0x8
 
#define ITEM_TAG_GLOBAL_REPORT_COUNT   0x9
 
#define ITEM_TAG_GLOBAL_PUSH   0xa
 
#define ITEM_TAG_GLOBAL_POP   0xb
 
#define ITEM_TAG_LOCAL_USAGE   0x0
 
#define ITEM_TAG_LOCAL_USAGE_MINIMUM   0x1
 
#define ITEM_TAG_LOCAL_USAGE_MAXIMUM   0x2
 
#define ITEM_TAG_LOCAL_DESIGNATOR_INDEX   0x3
 
#define ITEM_TAG_LOCAL_DESIGNATOR_MINIMUM   0x4
 
#define ITEM_TAG_LOCAL_DESIGNATOR_MAXIMUM   0x5
 
#define ITEM_TAG_LOCAL_STRING_INDEX   0x7
 
#define ITEM_TAG_LOCAL_STRING_MINIMUM   0x8
 
#define ITEM_TAG_LOCAL_STRING_MAXIMUM   0x9
 
#define ITEM_TAG_LOCAL_DELIMITER   0xa
 
#define ITEM_TAG_LONG   0xf
 
#define COLLECTION_PHYSICAL   0x00
 
#define COLLECTION_APPLICATION   0x01
 
#define COLLECTION_LOGICAL   0x02
 
#define COLLECTION_REPORT   0x03
 
#define COLLECTION_NAMED_ARRAY   0x04
 
#define COLLECTION_USAGE_SWITCH   0x05
 
#define COLLECTION_USAGE_MODIFIER   0x06
 
#define COLLECTION_ALL   0xff
 
#define UNIT_SYSTEM   0x0
 
#define UNIT_LENGTH   0x1
 
#define UNIT_MASS   0x2
 
#define UNIT_TIME   0x3
 
#define UNIT_TEMPERATURE   0x4
 
#define UNIT_CURRENT   0x5
 
#define UNIT_LUMINOUS_INTENSITY   0x6
 
#define USAGE_PAGE_SHIFT   16
 
#define USAGE_PAGE_MASK   0xffff
 
#define USAGE_ID_SHIFT   0
 
#define USAGE_ID_MASK   0xffff
 
#define LBITFIELD9(b1, b2, b3, b4, b5, b6, b7, b8, b9)   USHORT b9,b8,b7,b6,b5,b4,b3,b2,b1
 
#define HID_REPORT_TYPE_INPUT   0x01
 
#define HID_REPORT_TYPE_OUTPUT   0x02
 
#define HID_REPORT_TYPE_FEATURE   0x04
 

Typedefs

typedef struct ITEM_PREFIXPITEM_PREFIX
 
typedef struct SHORT_ITEMPSHORT_ITEM
 
typedef struct LONG_ITEMPLONG_ITEM
 
typedef struct MAIN_ITEM_DATAPMAIN_ITEM_DATA
 
typedef struct __GLOBAL_ITEM_STATE_ GLOBAL_ITEM_STATE
 
typedef struct __GLOBAL_ITEM_STATE_PGLOBAL_ITEM_STATE
 
typedef struct usage_value USAGE_VALUE
 
typedef struct usage_valuePUSAGE_VALUE
 
typedef struct LOCAL_ITEM_STATEPLOCAL_ITEM_STATE
 
typedef struct HID_REPORT_ITEMPHID_REPORT_ITEM
 
typedef struct __HID_COLLECTION__ HID_COLLECTION
 
typedef struct __HID_COLLECTION__PHID_COLLECTION
 
typedef struct _HID_REPORT HID_REPORT
 
typedef struct _HID_REPORTPHID_REPORT
 
typedef struct HID_PARSER_CONTEXTPHID_PARSER_CONTEXT
 

Functions

ULONG HidParser_UsesReportId (IN PVOID CollectionContext, IN UCHAR ReportType)
 
NTSTATUS 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)
 
ULONG HidParser_GetMaxUsageListLengthWithReportAndPage (IN PVOID CollectionContext, IN UCHAR ReportType, IN USAGE UsagePage OPTIONAL)
 
NTSTATUS HidParser_GetSpecificValueCapsWithReport (IN PVOID CollectionContext, IN UCHAR ReportType, IN USHORT UsagePage, IN USHORT Usage, OUT PHIDP_VALUE_CAPS ValueCaps, IN OUT PUSHORT ValueCapsLength)
 
NTSTATUS HidParser_GetUsagesWithReport (IN PVOID CollectionContext, IN UCHAR ReportType, IN USAGE UsagePage, OUT USAGE *UsageList, IN OUT PULONG UsageLength, IN PCHAR ReportDescriptor, IN ULONG ReportDescriptorLength)
 
NTSTATUS HidParser_GetScaledUsageValueWithReport (IN PVOID CollectionContext, IN UCHAR ReportType, IN USAGE UsagePage, IN USAGE Usage, OUT PLONG UsageValue, IN PCHAR ReportDescriptor, IN ULONG ReportDescriptorLength)
 
NTSTATUS HidParser_GetUsageValueWithReport (IN PVOID CollectionContext, IN UCHAR ReportType, IN USAGE UsagePage, IN USAGE Usage, OUT PULONG UsageValue, IN PCHAR ReportDescriptor, IN ULONG ReportDescriptorLength)
 
NTSTATUS HidParser_BuildContext (IN PVOID ParserContext, IN ULONG CollectionIndex, IN ULONG ContextSize, OUT PVOID *CollectionContext)
 
ULONG HidParser_CalculateContextSize (IN PHID_COLLECTION Collection)
 
NTSTATUS HidParser_ParseReportDescriptor (PUCHAR Report, ULONG ReportSize, OUT PVOID *ParserContext)
 
ULONG HidParser_NumberOfTopCollections (IN PVOID ParserContext)
 
ULONG HidParser_GetContextSize (IN PVOID ParserContext, IN ULONG CollectionNumber)
 
PHID_COLLECTION HidParser_GetCollectionFromContext (IN PVOID Context)
 
ULONG HidParser_GetTotalCollectionCount (IN PVOID CollectionContext)
 
NTSTATUS HidParser_BuildCollectionContext (IN PHID_COLLECTION RootCollection, IN PVOID Context, IN ULONG ContextSize)
 
PHID_REPORT HidParser_GetReportInCollection (IN PVOID Context, IN UCHAR ReportType)
 

Macro Definition Documentation

◆ _HIDPI_

#define _HIDPI_

Definition at line 5 of file parser.h.

◆ _HIDPI_NO_FUNCTION_MACROS_

#define _HIDPI_NO_FUNCTION_MACROS_

Definition at line 6 of file parser.h.

◆ COLLECTION_ALL

#define COLLECTION_ALL   0xff

Definition at line 64 of file parser.h.

◆ COLLECTION_APPLICATION

#define COLLECTION_APPLICATION   0x01

Definition at line 58 of file parser.h.

◆ COLLECTION_LOGICAL

#define COLLECTION_LOGICAL   0x02

Definition at line 59 of file parser.h.

◆ COLLECTION_NAMED_ARRAY

#define COLLECTION_NAMED_ARRAY   0x04

Definition at line 61 of file parser.h.

◆ COLLECTION_PHYSICAL

#define COLLECTION_PHYSICAL   0x00

Definition at line 57 of file parser.h.

◆ COLLECTION_REPORT

#define COLLECTION_REPORT   0x03

Definition at line 60 of file parser.h.

◆ COLLECTION_USAGE_MODIFIER

#define COLLECTION_USAGE_MODIFIER   0x06

Definition at line 63 of file parser.h.

◆ COLLECTION_USAGE_SWITCH

#define COLLECTION_USAGE_SWITCH   0x05

Definition at line 62 of file parser.h.

◆ HID_REPORT_TYPE_ANY

#define HID_REPORT_TYPE_ANY   0x07

Definition at line 17 of file parser.h.

◆ HID_REPORT_TYPE_FEATURE

#define HID_REPORT_TYPE_FEATURE   0x04

Definition at line 263 of file parser.h.

◆ HID_REPORT_TYPE_INPUT

#define HID_REPORT_TYPE_INPUT   0x01

Definition at line 261 of file parser.h.

◆ HID_REPORT_TYPE_OUTPUT

#define HID_REPORT_TYPE_OUTPUT   0x02

Definition at line 262 of file parser.h.

◆ ITEM_TAG_GLOBAL_LOGICAL_MAXIMUM

#define ITEM_TAG_GLOBAL_LOGICAL_MAXIMUM   0x2

Definition at line 33 of file parser.h.

◆ ITEM_TAG_GLOBAL_LOGICAL_MINIMUM

#define ITEM_TAG_GLOBAL_LOGICAL_MINIMUM   0x1

Definition at line 32 of file parser.h.

◆ ITEM_TAG_GLOBAL_PHYSICAL_MAXIMUM

#define ITEM_TAG_GLOBAL_PHYSICAL_MAXIMUM   0x4

Definition at line 35 of file parser.h.

◆ ITEM_TAG_GLOBAL_PHYSICAL_MINIMUM

#define ITEM_TAG_GLOBAL_PHYSICAL_MINIMUM   0x3

Definition at line 34 of file parser.h.

◆ ITEM_TAG_GLOBAL_POP

#define ITEM_TAG_GLOBAL_POP   0xb

Definition at line 42 of file parser.h.

◆ ITEM_TAG_GLOBAL_PUSH

#define ITEM_TAG_GLOBAL_PUSH   0xa

Definition at line 41 of file parser.h.

◆ ITEM_TAG_GLOBAL_REPORT_COUNT

#define ITEM_TAG_GLOBAL_REPORT_COUNT   0x9

Definition at line 40 of file parser.h.

◆ ITEM_TAG_GLOBAL_REPORT_ID

#define ITEM_TAG_GLOBAL_REPORT_ID   0x8

Definition at line 39 of file parser.h.

◆ ITEM_TAG_GLOBAL_REPORT_SIZE

#define ITEM_TAG_GLOBAL_REPORT_SIZE   0x7

Definition at line 38 of file parser.h.

◆ ITEM_TAG_GLOBAL_UNIT

#define ITEM_TAG_GLOBAL_UNIT   0x6

Definition at line 37 of file parser.h.

◆ ITEM_TAG_GLOBAL_UNIT_EXPONENT

#define ITEM_TAG_GLOBAL_UNIT_EXPONENT   0x5

Definition at line 36 of file parser.h.

◆ ITEM_TAG_GLOBAL_USAGE_PAGE

#define ITEM_TAG_GLOBAL_USAGE_PAGE   0x0

Definition at line 31 of file parser.h.

◆ ITEM_TAG_LOCAL_DELIMITER

#define ITEM_TAG_LOCAL_DELIMITER   0xa

Definition at line 53 of file parser.h.

◆ ITEM_TAG_LOCAL_DESIGNATOR_INDEX

#define ITEM_TAG_LOCAL_DESIGNATOR_INDEX   0x3

Definition at line 47 of file parser.h.

◆ ITEM_TAG_LOCAL_DESIGNATOR_MAXIMUM

#define ITEM_TAG_LOCAL_DESIGNATOR_MAXIMUM   0x5

Definition at line 49 of file parser.h.

◆ ITEM_TAG_LOCAL_DESIGNATOR_MINIMUM

#define ITEM_TAG_LOCAL_DESIGNATOR_MINIMUM   0x4

Definition at line 48 of file parser.h.

◆ ITEM_TAG_LOCAL_STRING_INDEX

#define ITEM_TAG_LOCAL_STRING_INDEX   0x7

Definition at line 50 of file parser.h.

◆ ITEM_TAG_LOCAL_STRING_MAXIMUM

#define ITEM_TAG_LOCAL_STRING_MAXIMUM   0x9

Definition at line 52 of file parser.h.

◆ ITEM_TAG_LOCAL_STRING_MINIMUM

#define ITEM_TAG_LOCAL_STRING_MINIMUM   0x8

Definition at line 51 of file parser.h.

◆ ITEM_TAG_LOCAL_USAGE

#define ITEM_TAG_LOCAL_USAGE   0x0

Definition at line 44 of file parser.h.

◆ ITEM_TAG_LOCAL_USAGE_MAXIMUM

#define ITEM_TAG_LOCAL_USAGE_MAXIMUM   0x2

Definition at line 46 of file parser.h.

◆ ITEM_TAG_LOCAL_USAGE_MINIMUM

#define ITEM_TAG_LOCAL_USAGE_MINIMUM   0x1

Definition at line 45 of file parser.h.

◆ ITEM_TAG_LONG

#define ITEM_TAG_LONG   0xf

Definition at line 55 of file parser.h.

◆ ITEM_TAG_MAIN_COLLECTION

#define ITEM_TAG_MAIN_COLLECTION   0xa

Definition at line 28 of file parser.h.

◆ ITEM_TAG_MAIN_END_COLLECTION

#define ITEM_TAG_MAIN_END_COLLECTION   0xc

Definition at line 29 of file parser.h.

◆ ITEM_TAG_MAIN_FEATURE

#define ITEM_TAG_MAIN_FEATURE   0xb

Definition at line 27 of file parser.h.

◆ ITEM_TAG_MAIN_INPUT

#define ITEM_TAG_MAIN_INPUT   0x8

Definition at line 25 of file parser.h.

◆ ITEM_TAG_MAIN_OUTPUT

#define ITEM_TAG_MAIN_OUTPUT   0x9

Definition at line 26 of file parser.h.

◆ ITEM_TYPE_GLOBAL

#define ITEM_TYPE_GLOBAL   0x1

Definition at line 21 of file parser.h.

◆ ITEM_TYPE_LOCAL

#define ITEM_TYPE_LOCAL   0x2

Definition at line 22 of file parser.h.

◆ ITEM_TYPE_LONG

#define ITEM_TYPE_LONG   0x3

Definition at line 23 of file parser.h.

◆ ITEM_TYPE_MAIN

#define ITEM_TYPE_MAIN   0x0

Definition at line 20 of file parser.h.

◆ LBITFIELD9

#define LBITFIELD9 (   b1,
  b2,
  b3,
  b4,
  b5,
  b6,
  b7,
  b8,
  b9 
)    USHORT b9,b8,b7,b6,b5,b4,b3,b2,b1

Definition at line 114 of file parser.h.

◆ UNIT_CURRENT

#define UNIT_CURRENT   0x5

Definition at line 71 of file parser.h.

◆ UNIT_LENGTH

#define UNIT_LENGTH   0x1

Definition at line 67 of file parser.h.

◆ UNIT_LUMINOUS_INTENSITY

#define UNIT_LUMINOUS_INTENSITY   0x6

Definition at line 72 of file parser.h.

◆ UNIT_MASS

#define UNIT_MASS   0x2

Definition at line 68 of file parser.h.

◆ UNIT_SYSTEM

#define UNIT_SYSTEM   0x0

Definition at line 66 of file parser.h.

◆ UNIT_TEMPERATURE

#define UNIT_TEMPERATURE   0x4

Definition at line 70 of file parser.h.

◆ UNIT_TIME

#define UNIT_TIME   0x3

Definition at line 69 of file parser.h.

◆ USAGE_ID_MASK

#define USAGE_ID_MASK   0xffff

Definition at line 77 of file parser.h.

◆ USAGE_ID_SHIFT

#define USAGE_ID_SHIFT   0

Definition at line 76 of file parser.h.

◆ USAGE_PAGE_MASK

#define USAGE_PAGE_MASK   0xffff

Definition at line 75 of file parser.h.

◆ USAGE_PAGE_SHIFT

#define USAGE_PAGE_SHIFT   16

Definition at line 74 of file parser.h.

Typedef Documentation

◆ GLOBAL_ITEM_STATE

◆ HID_COLLECTION

◆ HID_REPORT

◆ PGLOBAL_ITEM_STATE

◆ PHID_COLLECTION

◆ PHID_PARSER_CONTEXT

◆ PHID_REPORT

◆ PHID_REPORT_ITEM

◆ PITEM_PREFIX

◆ PLOCAL_ITEM_STATE

◆ PLONG_ITEM

◆ PMAIN_ITEM_DATA

◆ PSHORT_ITEM

◆ PUSAGE_VALUE

◆ USAGE_VALUE

Function Documentation

◆ HidParser_BuildCollectionContext()

NTSTATUS HidParser_BuildCollectionContext ( IN PHID_COLLECTION  RootCollection,
IN PVOID  Context,
IN ULONG  ContextSize 
)

Definition at line 185 of file context.c.

189{
190 PHID_COLLECTION_CONTEXT CollectionContext;
191 ULONG CollectionSize;
192
193 //
194 // init context
195 //
196 CollectionContext = (PHID_COLLECTION_CONTEXT)Context;
197 CollectionContext->Size = ContextSize;
198
199 //
200 // store collections
201 //
202 CollectionSize = HidParser_StoreCollection(RootCollection, CollectionContext, 0);
203
204 //
205 // sanity check
206 //
207 ASSERT(CollectionSize + sizeof(HID_COLLECTION_CONTEXT) == ContextSize);
208
209 DPRINT("CollectionContext %p\n", CollectionContext);
210 DPRINT("CollectionContext RawData %p\n", CollectionContext->RawData);
211 DPRINT("CollectionContext Size %lu\n", CollectionContext->Size);
212
213 //
214 // done
215 //
216 return HIDP_STATUS_SUCCESS;
217}
_Must_inspect_result_ _In_ FLT_CONTEXT_TYPE _In_ SIZE_T ContextSize
Definition: fltkernel.h:1444
#define HIDP_STATUS_SUCCESS
Definition: hidpi.h:248
#define ASSERT(a)
Definition: mode.c:44
ULONG HidParser_StoreCollection(IN PHID_COLLECTION Collection, IN PHID_COLLECTION_CONTEXT CollectionContext, IN ULONG CurrentOffset)
Definition: context.c:83
struct HID_COLLECTION_CONTEXT * PHID_COLLECTION_CONTEXT
#define DPRINT
Definition: sndvol32.h:73
uint32_t ULONG
Definition: typedefs.h:59

Referenced by HidParser_BuildContext().

◆ HidParser_BuildContext()

NTSTATUS HidParser_BuildContext ( IN PVOID  ParserContext,
IN ULONG  CollectionIndex,
IN ULONG  ContextSize,
OUT PVOID CollectionContext 
)

Definition at line 1303 of file parser.c.

1308{
1310 PVOID Context;
1312
1313 //
1314 // lets get the collection
1315 //
1316 Collection = HidParser_GetCollection((PHID_PARSER_CONTEXT)ParserContext, CollectionIndex);
1318
1319 //
1320 // lets allocate the context
1321 //
1323 if (Context == NULL)
1324 {
1325 //
1326 // no memory
1327 //
1329 }
1330
1331 //
1332 // lets build the context
1333 //
1336 {
1337 //
1338 // store context
1339 //
1340 *CollectionContext = Context;
1341 }
1342
1343 //
1344 // done
1345 //
1346 return Status;
1347}
LONG NTSTATUS
Definition: precomp.h:26
#define NULL
Definition: types.h:112
Status
Definition: gdiplustypes.h:25
PVOID NTAPI AllocFunction(IN ULONG ItemSize)
Definition: hid.c:45
#define HIDP_STATUS_INTERNAL_ERROR
Definition: hidpi.h:257
NTSTATUS HidParser_BuildCollectionContext(IN PHID_COLLECTION RootCollection, IN PVOID Context, IN ULONG ContextSize)
Definition: context.c:185
PHID_COLLECTION HidParser_GetCollection(PHID_PARSER_CONTEXT ParserContext, IN ULONG CollectionNumber)
Definition: parser.c:1248
WDF_EXTERN_C_START typedef _Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFCOLLECTION * Collection
Definition: wdfcollection.h:67
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _In_opt_ PWDF_OBJECT_ATTRIBUTES _In_ WDFCOLLECTION Collection
Definition: wdfregistry.h:374

Referenced by HidParser_GetCollectionDescription().

◆ HidParser_CalculateContextSize()

ULONG HidParser_CalculateContextSize ( IN PHID_COLLECTION  Collection)

Definition at line 65 of file context.c.

67{
68 ULONG Size;
69
70 //
71 // minimum size is the size of the collection
72 //
74
75 //
76 // append collection context size
77 //
79 return Size;
80}
ULONG HidParser_CalculateCollectionSize(IN PHID_COLLECTION Collection)
Definition: context.c:26
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533

Referenced by HidParser_GetContextSize().

◆ HidParser_GetCollectionFromContext()

PHID_COLLECTION HidParser_GetCollectionFromContext ( IN PVOID  Context)

Definition at line 290 of file context.c.

292{
294
295 //
296 // return root collection
297 //
298 return (PHID_COLLECTION)CollectionContext->RawData;
299}

Referenced by HidParser_GetCollectionUsagePage().

◆ HidParser_GetCollectionUsagePage()

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

Definition at line 65 of file api.c.

69{
71
72 //
73 // find collection
74 //
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}
_Must_inspect_result_ _In_ USAGE UsagePage
Definition: hidpi.h:382
#define HIDP_STATUS_USAGE_NOT_FOUND
Definition: hidpi.h:253
USAGE Usage
Definition: api.c:38
PHID_COLLECTION HidParser_GetCollectionFromContext(IN PVOID Context)
Definition: context.c:290

Referenced by HidParser_GetCaps(), and HidParser_GetCollectionDescription().

◆ HidParser_GetContextSize()

ULONG HidParser_GetContextSize ( IN PVOID  ParserContext,
IN ULONG  CollectionNumber 
)

Definition at line 1351 of file parser.c.

1354{
1356 ULONG Size;
1357
1358 //
1359 // lets get the collection
1360 //
1361 Collection = HidParser_GetCollection((PHID_PARSER_CONTEXT)ParserContext, CollectionIndex);
1362
1363 //
1364 // calculate size
1365 //
1367 return Size;
1368}
ULONG HidParser_CalculateContextSize(IN PHID_COLLECTION Collection)
Definition: context.c:65

Referenced by HidParser_GetCollectionDescription().

◆ HidParser_GetMaxUsageListLengthWithReportAndPage()

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

Definition at line 210 of file api.c.

214{
215 ULONG Index;
216 PHID_REPORT Report;
217 ULONG ItemCount = 0;
218 USHORT CurrentUsagePage;
219
220 //
221 // get report
222 //
223 Report = HidParser_GetReportInCollection(CollectionContext, ReportType);
224 if (!Report)
225 {
226 //
227 // no such report
228 //
229 return 0;
230 }
231
232 for(Index = 0; Index < Report->ItemCount; Index++)
233 {
234 //
235 // check usage page
236 //
237 CurrentUsagePage = (Report->Items[Index].UsageMinimum >> 16);
238 if (CurrentUsagePage == UsagePage && Report->Items[Index].HasData)
239 {
240 //
241 // found item
242 //
243 ItemCount++;
244 }
245 }
246
247 //
248 // done
249 //
250 return ItemCount;
251}
unsigned short USHORT
Definition: pedump.c:61
PHID_REPORT HidParser_GetReportInCollection(IN PVOID Context, IN UCHAR ReportType)
Definition: context.c:277
ULONG UsageMinimum
Definition: parser.h:197
UCHAR HasData
Definition: parser.h:192
HID_REPORT_ITEM Items[1]
Definition: parser.h:229
ULONG ItemCount
Definition: parser.h:227
_In_ WDFCOLLECTION _In_ ULONG Index

Referenced by HidParser_MaxUsageListLength().

◆ HidParser_GetReportInCollection()

PHID_REPORT HidParser_GetReportInCollection ( IN PVOID  Context,
IN UCHAR  ReportType 
)

Definition at line 277 of file context.c.

280{
282
283 //
284 // done
285 //
286 return HidParser_SearchReportInCollection(CollectionContext, (PHID_COLLECTION)&CollectionContext->RawData, ReportType);
287}
PHID_REPORT HidParser_SearchReportInCollection(IN PHID_COLLECTION_CONTEXT CollectionContext, IN PHID_COLLECTION Collection, IN UCHAR ReportType)
Definition: context.c:220

Referenced by HidParser_GetMaxUsageListLengthWithReportAndPage(), HidParser_GetReportItemCountFromReportType(), HidParser_GetReportItemTypeCountFromReportType(), HidParser_GetReportLength(), HidParser_GetScaledUsageValueWithReport(), HidParser_GetSpecificValueCapsWithReport(), HidParser_GetUsagesWithReport(), HidParser_GetUsageValueWithReport(), and HidParser_UsesReportId().

◆ 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}

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}
#define FALSE
Definition: types.h:117

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}
_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:226

Referenced by HidParser_GetCaps(), and HidParser_GetCollectionDescription().

◆ HidParser_GetScaledUsageValueWithReport()

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

Definition at line 646 of file api.c.

654{
655 ULONG Index;
656 PHID_REPORT Report;
657 USHORT CurrentUsagePage;
658 PHID_REPORT_ITEM ReportItem;
659 ULONG Data;
660
661 //
662 // get report
663 //
664 Report = HidParser_GetReportInCollection(CollectionContext, ReportType);
665 if (!Report)
666 {
667 //
668 // no such report
669 //
671 }
672
673 if (Report->ReportSize / 8 != (ReportDescriptorLength - 1))
674 {
675 //
676 // invalid report descriptor length
677 //
679 }
680
681 for (Index = 0; Index < Report->ItemCount; Index++)
682 {
683 //
684 // get report item
685 //
686 ReportItem = &Report->Items[Index];
687
688 //
689 // check usage page
690 //
691 CurrentUsagePage = (ReportItem->UsageMinimum >> 16);
692
693 //
694 // does usage page match
695 //
696 if (UsagePage != CurrentUsagePage)
697 continue;
698
699 //
700 // does the usage match
701 //
702 if (Usage != (ReportItem->UsageMinimum & 0xFFFF))
703 continue;
704
705 //
706 // check if the specified usage is activated
707 //
708 ASSERT(ReportItem->ByteOffset < ReportDescriptorLength);
709
710 //
711 // one extra shift for skipping the prepended report id
712 //
713 Data = 0;
714 CopyFunction(&Data, &ReportDescriptor[ReportItem->ByteOffset + 1], min(sizeof(ULONG), ReportDescriptorLength - (ReportItem->ByteOffset + 1)));
715
716 //
717 // shift data
718 //
719 Data >>= ReportItem->Shift;
720
721 //
722 // clear unwanted bits
723 //
724 Data &= ReportItem->Mask;
725
726 if (ReportItem->Minimum > ReportItem->Maximum)
727 {
728 //
729 // logical boundaries are signed values
730 //
731
732 // FIXME: scale with physical min/max
733 if ((Data & ~(ReportItem->Mask >> 1)) != 0)
734 {
735 Data |= ~ReportItem->Mask;
736 }
737 }
738 else
739 {
740 // logical boundaries are absolute values
742 }
743
744 //
745 // store result
746 //
747 *UsageValue = Data;
748 return HIDP_STATUS_SUCCESS;
749 }
750
751 //
752 // usage not found
753 //
755}
#define HIDP_STATUS_REPORT_DOES_NOT_EXIST
Definition: hidpi.h:265
#define HIDP_STATUS_BAD_LOG_PHY_VALUES
Definition: hidpi.h:255
#define HIDP_STATUS_INVALID_REPORT_LENGTH
Definition: hidpi.h:252
#define min(a, b)
Definition: monoChain.cc:55
ULONG Mask
Definition: parser.h:190
UCHAR Shift
Definition: parser.h:189
ULONG ByteOffset
Definition: parser.h:188
ULONG Minimum
Definition: parser.h:195
ULONG Maximum
Definition: parser.h:196
_Inout_ PSIZE_T _In_opt_ PMDLX _In_ MM_ROTATE_DIRECTION _In_ PMM_ROTATE_COPY_CALLBACK_FUNCTION CopyFunction
Definition: mmfuncs.h:775

Referenced by HidParser_GetScaledUsageValue().

◆ HidParser_GetSpecificValueCapsWithReport()

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

Definition at line 254 of file api.c.

261{
262 ULONG Index;
263 PHID_REPORT Report;
264 USHORT ItemCount = 0;
265 USHORT CurrentUsagePage;
266 USHORT CurrentUsage;
267
268 //
269 // get report
270 //
271 Report = HidParser_GetReportInCollection(CollectionContext, ReportType);
272 if (!Report)
273 {
274 //
275 // no such report
276 //
278 }
279
280 for(Index = 0; Index < Report->ItemCount; Index++)
281 {
282 //
283 // check usage page
284 //
285 CurrentUsagePage = (Report->Items[Index].UsageMinimum >> 16);
286 CurrentUsage = (Report->Items[Index].UsageMinimum & 0xFFFF);
287
288 if ((Usage == CurrentUsage && UsagePage == CurrentUsagePage) || (Usage == 0 && UsagePage == CurrentUsagePage) || (Usage == CurrentUsage && UsagePage == 0) || (Usage == 0 && UsagePage == 0))
289 {
290 //
291 // check if there is enough place for the caps
292 //
293 if (ItemCount < *ValueCapsLength)
294 {
295 //
296 // zero caps
297 //
298 ZeroFunction(&ValueCaps[ItemCount], sizeof(HIDP_VALUE_CAPS));
299
300 //
301 // init caps
302 //
303 ValueCaps[ItemCount].UsagePage = CurrentUsagePage;
304 ValueCaps[ItemCount].ReportID = Report->ReportID;
305 ValueCaps[ItemCount].LogicalMin = Report->Items[Index].Minimum;
306 ValueCaps[ItemCount].LogicalMax = Report->Items[Index].Maximum;
307 ValueCaps[ItemCount].IsAbsolute = !Report->Items[Index].Relative;
308 ValueCaps[ItemCount].BitSize = Report->Items[Index].BitCount;
309
310 //
311 // FIXME: FILLMEIN
312 //
313 }
314
315
316 //
317 // found item
318 //
319 ItemCount++;
320 }
321 }
322
323 //
324 // store result
325 //
326 *ValueCapsLength = ItemCount;
327
328 if (ItemCount)
329 {
330 //
331 // success
332 //
333 return HIDP_STATUS_SUCCESS;
334 }
335
336 //
337 // item not found
338 //
340}
VOID NTAPI ZeroFunction(IN PVOID Item, IN ULONG ItemSize)
Definition: hid.c:61
_Must_inspect_result_ _In_ USAGE _In_ USHORT _In_ USAGE _Out_ PHIDP_VALUE_CAPS _Inout_ PUSHORT ValueCapsLength
Definition: hidpi.h:400
_Must_inspect_result_ _In_ USAGE _In_ USHORT _In_ USAGE _Out_ PHIDP_VALUE_CAPS ValueCaps
Definition: hidpi.h:399
UCHAR BitCount
Definition: parser.h:191
UCHAR Relative
Definition: parser.h:194
USHORT BitSize
Definition: hidpi.h:214
LONG LogicalMin
Definition: hidpi.h:219
USAGE UsagePage
Definition: hidpi.h:201
UCHAR ReportID
Definition: hidpi.h:202
BOOLEAN IsAbsolute
Definition: hidpi.h:211
LONG LogicalMax
Definition: hidpi.h:219
UCHAR ReportID
Definition: parser.h:225

Referenced by HidParser_GetSpecificValueCaps().

◆ HidParser_GetTotalCollectionCount()

ULONG HidParser_GetTotalCollectionCount ( IN PVOID  CollectionContext)

Definition at line 330 of file context.c.

332{
333 PHID_COLLECTION_CONTEXT CollectionContext;
334
335 //
336 // get parser context
337 //
338 CollectionContext = (PHID_COLLECTION_CONTEXT)Context;
339
340 //
341 // count collections
342 //
343 return HidParser_GetCollectionCount(CollectionContext, (PHID_COLLECTION)CollectionContext->RawData);
344}
ULONG HidParser_GetCollectionCount(IN PHID_COLLECTION_CONTEXT CollectionContext, IN PHID_COLLECTION Collection)
Definition: context.c:302

Referenced by HidParser_GetCaps().

◆ HidParser_GetUsagesWithReport()

NTSTATUS HidParser_GetUsagesWithReport ( 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 343 of file api.c.

351{
352 ULONG Index;
353 PHID_REPORT Report;
354 ULONG ItemCount = 0;
355 USHORT CurrentUsagePage;
356 PHID_REPORT_ITEM ReportItem;
357 UCHAR Activated;
358 ULONG Data;
359 PUSAGE_AND_PAGE UsageAndPage = NULL;
360
361 //
362 // get report
363 //
364 Report = HidParser_GetReportInCollection(CollectionContext, ReportType);
365 if (!Report)
366 {
367 //
368 // no such report
369 //
371 }
372
373 if (Report->ReportSize / 8 != (ReportDescriptorLength - 1))
374 {
375 //
376 // invalid report descriptor length
377 //
379 }
380
381 //
382 // cast to usage and page
383 //
385 {
386 //
387 // the caller requested any set usages
388 //
389 UsageAndPage = (PUSAGE_AND_PAGE)UsageList;
390 }
391
392 for(Index = 0; Index < Report->ItemCount; Index++)
393 {
394 //
395 // get report item
396 //
397 ReportItem = &Report->Items[Index];
398
399 //
400 // does it have data
401 //
402 if (!ReportItem->HasData)
403 continue;
404
405 //
406 // check usage page
407 //
408 CurrentUsagePage = (ReportItem->UsageMinimum >> 16);
409
411 {
412 //
413 // does usage match
414 //
415 if (UsagePage != CurrentUsagePage)
416 continue;
417 }
418
419 //
420 // check if the specified usage is activated
421 //
422 ASSERT(ReportItem->ByteOffset < ReportDescriptorLength);
423 ASSERT(ReportItem->BitCount <= 8);
424
425 //
426 // one extra shift for skipping the prepended report id
427 //
428 Data = ReportDescriptor[ReportItem->ByteOffset + 1];
429
430 //
431 // shift data
432 //
433 Data >>= ReportItem->Shift;
434
435 //
436 // clear unwanted bits
437 //
438 Data &= ReportItem->Mask;
439
440 //
441 // is it activated
442 //
443 Activated = (Data != 0);
444
445 if (!Activated)
446 continue;
447
448 //
449 // is there enough space for the usage
450 //
451 if (ItemCount >= *UsageLength)
452 {
453 ItemCount++;
454 continue;
455 }
456
458 {
459 //
460 // store item
461 //
462 UsageList[ItemCount] = (ReportItem->UsageMinimum & 0xFFFF);
463 }
464 else
465 {
466 //
467 // store usage and page
468 //
469 if (ReportItem->BitCount == 1)
470 {
471 //
472 // use usage minimum
473 //
474 UsageAndPage[ItemCount].Usage =(ReportItem->UsageMinimum & 0xFFFF);
475 }
476 else
477 {
478 //
479 // use value from control
480 //
481 UsageAndPage[ItemCount].Usage = (USHORT)Data;
482 }
483 UsageAndPage[ItemCount].UsagePage = CurrentUsagePage;
484 }
485 ItemCount++;
486 }
487
488 if (ItemCount > *UsageLength)
489 {
490 //
491 // list too small
492 //
494 }
495
497 {
498 //
499 // success, clear rest of array
500 //
501 ZeroFunction(&UsageAndPage[ItemCount], (*UsageLength - ItemCount) * sizeof(USAGE_AND_PAGE));
502 }
503 else
504 {
505 //
506 // success, clear rest of array
507 //
508 ZeroFunction(&UsageList[ItemCount], (*UsageLength - ItemCount) * sizeof(USAGE));
509 }
510
511
512 //
513 // store result size
514 //
515 *UsageLength = ItemCount;
516
517 //
518 // done
519 //
520 return HIDP_STATUS_SUCCESS;
521}
_Must_inspect_result_ _In_ USHORT _Inout_updates_to_ UsageLength PUSAGE_AND_PAGE _Inout_ ULONG * UsageLength
Definition: hidpi.h:426
#define HIDP_STATUS_BUFFER_TOO_SMALL
Definition: hidpi.h:256
struct _USAGE_AND_PAGE * PUSAGE_AND_PAGE
USHORT USAGE
Definition: hidusage.h:30
#define HID_USAGE_PAGE_UNDEFINED
Definition: hidusage.h:175
USAGE UsagePage
Definition: hidpi.h:80
USAGE Usage
Definition: hidpi.h:79
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by HidParser_GetUsages().

◆ HidParser_GetUsageValueWithReport()

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

Definition at line 550 of file api.c.

558{
559 ULONG Index;
560 PHID_REPORT Report;
561 USHORT CurrentUsagePage;
562 PHID_REPORT_ITEM ReportItem;
563 ULONG Data;
564
565 //
566 // get report
567 //
568 Report = HidParser_GetReportInCollection(CollectionContext, ReportType);
569 if (!Report)
570 {
571 //
572 // no such report
573 //
575 }
576
577 if (Report->ReportSize / 8 != (ReportDescriptorLength - 1))
578 {
579 //
580 // invalid report descriptor length
581 //
583 }
584
585 for (Index = 0; Index < Report->ItemCount; Index++)
586 {
587 //
588 // get report item
589 //
590 ReportItem = &Report->Items[Index];
591
592 //
593 // check usage page
594 //
595 CurrentUsagePage = (ReportItem->UsageMinimum >> 16);
596
597 //
598 // does usage page match
599 //
600 if (UsagePage != CurrentUsagePage)
601 continue;
602
603 //
604 // does the usage match
605 //
606 if (Usage != (ReportItem->UsageMinimum & 0xFFFF))
607 continue;
608
609 //
610 // check if the specified usage is activated
611 //
612 ASSERT(ReportItem->ByteOffset < ReportDescriptorLength);
613
614 //
615 // one extra shift for skipping the prepended report id
616 //
617 Data = 0;
618 CopyFunction(&Data, &ReportDescriptor[ReportItem->ByteOffset + 1], min(sizeof(ULONG), ReportDescriptorLength - (ReportItem->ByteOffset + 1)));
619
620 //
621 // shift data
622 //
623 Data >>= ReportItem->Shift;
624
625 //
626 // clear unwanted bits
627 //
628 Data &= ReportItem->Mask;
629
630 //
631 // store result
632 //
633 *UsageValue = Data;
634 return HIDP_STATUS_SUCCESS;
635 }
636
637 //
638 // usage not found
639 //
641}

Referenced by HidParser_GetUsageValue().

◆ HidParser_NumberOfTopCollections()

ULONG HidParser_NumberOfTopCollections ( IN PVOID  ParserContext)

Definition at line 1279 of file parser.c.

1281{
1282 PHID_PARSER_CONTEXT ParserContext;
1283
1284 //
1285 // get parser context
1286 //
1287 ParserContext = (PHID_PARSER_CONTEXT)ParserCtx;
1288
1289 //
1290 // sanity checks
1291 //
1292 ASSERT(ParserContext);
1293 ASSERT(ParserContext->RootCollection);
1294 ASSERT(ParserContext->RootCollection->NodeCount);
1295
1296 //
1297 // number of top collections
1298 //
1299 return ParserContext->RootCollection->NodeCount;
1300}
struct HID_PARSER_CONTEXT * PHID_PARSER_CONTEXT
PHID_COLLECTION RootCollection
Definition: parser.h:247

Referenced by HidParser_GetCollectionDescription().

◆ HidParser_ParseReportDescriptor()

NTSTATUS HidParser_ParseReportDescriptor ( PUCHAR  Report,
ULONG  ReportSize,
OUT PVOID ParserContext 
)

◆ HidParser_UsesReportId()

ULONG HidParser_UsesReportId ( IN PVOID  CollectionContext,
IN UCHAR  ReportType 
)

Definition at line 524 of file api.c.

527{
528 PHID_REPORT Report;
529
530 //
531 // get report
532 //
533 Report = HidParser_GetReportInCollection(CollectionContext, ReportType);
534 if (!Report)
535 {
536 //
537 // no such report
538 //
539 return 0;
540 }
541
542 //
543 // returns true when report id != 0
544 //
545 return (Report->ReportID != 0);
546
547}

Referenced by HidParser_GetCollectionDescription().