ReactOS 0.4.15-dev-7928-g68a8619
hid.c File Reference
#include "precomp.h"
#include <stdarg.h>
#include <winbase.h>
#include <debug.h>
#include "hidp.h"
Include dependency graph for hid.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

PVOID NTAPI AllocFunction (IN ULONG ItemSize)
 
VOID NTAPI FreeFunction (IN PVOID Item)
 
VOID NTAPI ZeroFunction (IN PVOID Item, IN ULONG ItemSize)
 
VOID NTAPI CopyFunction (IN PVOID Target, IN PVOID Source, IN ULONG Length)
 
VOID __cdecl DebugFunction (IN LPCSTR FormatStr,...)
 
BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpvReserved)
 
HIDAPI BOOLEAN WINAPI HidD_FlushQueue (IN HANDLE HidDeviceObject)
 
HIDAPI BOOLEAN WINAPI HidD_FreePreparsedData (IN PHIDP_PREPARSED_DATA PreparsedData)
 
HIDAPI BOOLEAN WINAPI HidD_GetAttributes (IN HANDLE HidDeviceObject, OUT PHIDD_ATTRIBUTES Attributes)
 
HIDAPI BOOLEAN WINAPI HidD_GetFeature (IN HANDLE HidDeviceObject, OUT PVOID ReportBuffer, IN ULONG ReportBufferLength)
 
HIDAPI VOID WINAPI HidD_GetHidGuid (OUT LPGUID HidGuid)
 
HIDAPI BOOLEAN WINAPI HidD_GetInputReport (IN HANDLE HidDeviceObject, IN OUT PVOID ReportBuffer, IN ULONG ReportBufferLength)
 
HIDAPI BOOLEAN WINAPI HidD_GetManufacturerString (IN HANDLE HidDeviceObject, OUT PVOID Buffer, IN ULONG BufferLength)
 
HIDAPI BOOLEAN WINAPI HidD_GetNumInputBuffers (IN HANDLE HidDeviceObject, OUT PULONG NumberBuffers)
 
HIDAPI BOOLEAN WINAPI HidD_GetPhysicalDescriptor (IN HANDLE HidDeviceObject, OUT PVOID Buffer, IN ULONG BufferLength)
 
HIDAPI BOOLEAN WINAPI HidD_GetPreparsedData (IN HANDLE HidDeviceObject, OUT PHIDP_PREPARSED_DATA *PreparsedData)
 
HIDAPI BOOLEAN WINAPI HidD_GetProductString (IN HANDLE HidDeviceObject, OUT PVOID Buffer, IN ULONG BufferLength)
 
HIDAPI BOOLEAN WINAPI HidD_GetSerialNumberString (IN HANDLE HidDeviceObject, OUT PVOID Buffer, IN ULONG BufferLength)
 
HIDAPI ULONG WINAPI HidD_Hello (OUT PCHAR Buffer, IN ULONG BufferLength)
 
HIDAPI BOOLEAN WINAPI HidD_SetFeature (IN HANDLE HidDeviceObject, IN PVOID ReportBuffer, IN ULONG ReportBufferLength)
 
HIDAPI BOOLEAN WINAPI HidD_SetNumInputBuffers (IN HANDLE HidDeviceObject, IN ULONG NumberBuffers)
 
HIDAPI BOOLEAN WINAPI HidD_SetOutputReport (IN HANDLE HidDeviceObject, IN PVOID ReportBuffer, IN ULONG ReportBufferLength)
 
HIDAPI BOOLEAN WINAPI HidD_GetIndexedString (IN HANDLE HidDeviceObject, IN ULONG StringIndex, OUT PVOID Buffer, IN ULONG BufferLength)
 
HIDAPI BOOLEAN WINAPI HidD_GetMsGenreDescriptor (IN HANDLE HidDeviceObject, OUT PVOID Buffer, IN ULONG BufferLength)
 
HIDAPI BOOLEAN WINAPI HidD_GetConfiguration (IN HANDLE HidDeviceObject, OUT PHIDD_CONFIGURATION Configuration, IN ULONG ConfigurationLength)
 
HIDAPI BOOLEAN WINAPI HidD_SetConfiguration (IN HANDLE HidDeviceObject, IN PHIDD_CONFIGURATION Configuration, IN ULONG ConfigurationLength)
 

Variables

HINSTANCE hDllInstance
 
const GUID HidClassGuid = {0x4D1E55B2, 0xF16F, 0x11CF, {0x88,0xCB,0x00,0x11,0x11,0x00,0x00,0x30}}
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 34 of file hid.c.

Function Documentation

◆ AllocFunction()

◆ CopyFunction()

VOID NTAPI CopyFunction ( IN PVOID  Target,
IN PVOID  Source,
IN ULONG  Length 
)

Definition at line 70 of file hid.c.

74{
76}
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3169
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
_In_ WDFIOTARGET Target
Definition: wdfrequest.h:306

◆ DebugFunction()

VOID __cdecl DebugFunction ( IN LPCSTR  FormatStr,
  ... 
)

Definition at line 80 of file hid.c.

82{
83#if 0
85 va_start(list, FormatStr);
86 vDbgPrintEx(FormatStr, list);
87 va_end(list);
88#endif
89}
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define va_arg(ap, T)
Definition: acmsvcex.h:89
NTSYSAPI ULONG NTAPI vDbgPrintEx(_In_ ULONG ComponentId, _In_ ULONG Level, _In_z_ PCCH Format, _In_ va_list ap)
Definition: list.h:37
#define list
Definition: rosglue.h:35

Referenced by HidParser_AllocateCollection(), HidParser_GetCollection(), HidParser_GetCollectionDescription(), and HidParser_ParseReportDescriptor().

◆ DllMain()

BOOL WINAPI DllMain ( HINSTANCE  hinstDLL,
DWORD  dwReason,
LPVOID  lpvReserved 
)

Definition at line 92 of file hid.c.

95{
96 switch(dwReason)
97 {
99 hDllInstance = hinstDLL;
100 break;
101
103 break;
104
106 break;
107
109 break;
110 }
111 return TRUE;
112}
DWORD dwReason
Definition: misc.cpp:154
#define TRUE
Definition: types.h:120
#define DLL_THREAD_DETACH
Definition: compat.h:133
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
#define DLL_PROCESS_DETACH
Definition: compat.h:130
#define DLL_THREAD_ATTACH
Definition: compat.h:132
HINSTANCE hDllInstance
Definition: hid.c:38

◆ FreeFunction()

◆ HidD_FlushQueue()

HIDAPI BOOLEAN WINAPI HidD_FlushQueue ( IN HANDLE  HidDeviceObject)

Definition at line 122 of file hid.c.

123{
124 DWORD RetLen;
125 return DeviceIoControl(HidDeviceObject, IOCTL_HID_FLUSH_QUEUE,
126 NULL, 0,
127 NULL, 0,
128 &RetLen, NULL) != 0;
129}
BOOL WINAPI DeviceIoControl(IN HANDLE hDevice, IN DWORD dwIoControlCode, IN LPVOID lpInBuffer OPTIONAL, IN DWORD nInBufferSize OPTIONAL, OUT LPVOID lpOutBuffer OPTIONAL, IN DWORD nOutBufferSize OPTIONAL, OUT LPDWORD lpBytesReturned OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: deviceio.c:136
#define NULL
Definition: types.h:112
unsigned long DWORD
Definition: ntddk_ex.h:95
#define IOCTL_HID_FLUSH_QUEUE
Definition: hidclass.h:57

◆ HidD_FreePreparsedData()

HIDAPI BOOLEAN WINAPI HidD_FreePreparsedData ( IN PHIDP_PREPARSED_DATA  PreparsedData)

Definition at line 139 of file hid.c.

140{
141 return (LocalFree((HLOCAL)PreparsedData) == NULL);
142}
_Must_inspect_result_ _Out_writes_to_ DataLength PHIDP_DATA _Inout_ PULONG _In_ PHIDP_PREPARSED_DATA PreparsedData
Definition: hidpi.h:335

Referenced by get_device(), test_device_info(), test_get_input_report(), and test_read_device().

◆ HidD_GetAttributes()

HIDAPI BOOLEAN WINAPI HidD_GetAttributes ( IN HANDLE  HidDeviceObject,
OUT PHIDD_ATTRIBUTES  Attributes 
)

Definition at line 152 of file hid.c.

154{
156 DWORD RetLen;
157
159 NULL, 0,
160 &hci, sizeof(HID_COLLECTION_INFORMATION),
161 &RetLen, NULL))
162 {
163 return FALSE;
164 }
165
166 /* copy the fields */
167 Attributes->Size = sizeof(HIDD_ATTRIBUTES);
168 Attributes->VendorID = hci.VendorID;
169 Attributes->ProductID = hci.ProductID;
170 Attributes->VersionNumber = hci.VersionNumber;
171
172 return TRUE;
173}
#define FALSE
Definition: types.h:117
#define IOCTL_HID_GET_COLLECTION_INFORMATION
Definition: hidclass.h:59
struct _HIDD_ATTRIBUTES HIDD_ATTRIBUTES
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes

Referenced by test_device_info().

◆ HidD_GetConfiguration()

HIDAPI BOOLEAN WINAPI HidD_GetConfiguration ( IN HANDLE  HidDeviceObject,
OUT PHIDD_CONFIGURATION  Configuration,
IN ULONG  ConfigurationLength 
)

Definition at line 502 of file hid.c.

505{
506
507 // magic cookie
509
510 return DeviceIoControl(HidDeviceObject, IOCTL_HID_GET_DRIVER_CONFIG,
511 0, 0,
512 &Configuration->size, ConfigurationLength - sizeof(ULONG),
513 (PULONG)&Configuration->cookie, NULL) != 0;
514}
HIDAPI BOOLEAN WINAPI HidD_GetConfiguration(IN HANDLE HidDeviceObject, OUT PHIDD_CONFIGURATION Configuration, IN ULONG ConfigurationLength)
Definition: hid.c:502
#define IOCTL_HID_GET_DRIVER_CONFIG
Definition: hidclass.h:74
uint32_t * PULONG
Definition: typedefs.h:59
void * PVOID
Definition: typedefs.h:50
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_INTERRUPT_CONFIG Configuration
Definition: wdfinterrupt.h:374

Referenced by HidD_GetConfiguration(), and HidD_SetConfiguration().

◆ HidD_GetFeature()

HIDAPI BOOLEAN WINAPI HidD_GetFeature ( IN HANDLE  HidDeviceObject,
OUT PVOID  ReportBuffer,
IN ULONG  ReportBufferLength 
)

Definition at line 183 of file hid.c.

186{
187 DWORD RetLen;
188 return DeviceIoControl(HidDeviceObject, IOCTL_HID_GET_FEATURE,
189 NULL, 0,
190 ReportBuffer, ReportBufferLength,
191 &RetLen, NULL) != 0;
192}
#define IOCTL_HID_GET_FEATURE
Definition: hidclass.h:60

◆ HidD_GetHidGuid()

HIDAPI VOID WINAPI HidD_GetHidGuid ( OUT LPGUID  HidGuid)

Definition at line 202 of file hid.c.

203{
204 *HidGuid = HidClassGuid;
205}
const GUID HidClassGuid
Definition: hid.c:41

Referenced by get_device(), and run_for_each_device().

◆ HidD_GetIndexedString()

HIDAPI BOOLEAN WINAPI HidD_GetIndexedString ( IN HANDLE  HidDeviceObject,
IN ULONG  StringIndex,
OUT PVOID  Buffer,
IN ULONG  BufferLength 
)

Definition at line 465 of file hid.c.

469{
470 DWORD RetLen;
471 return DeviceIoControl(HidDeviceObject, IOCTL_HID_GET_INDEXED_STRING,
472 &StringIndex, sizeof(ULONG),
474 &RetLen, NULL) != 0;
475}
Definition: bufpool.h:45
#define IOCTL_HID_GET_INDEXED_STRING
Definition: hidclass.h:76
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3771
_Must_inspect_result_ _In_ WDFUSBDEVICE _In_opt_ WDFREQUEST _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_writes_opt_ NumCharacters PUSHORT _Inout_ PUSHORT _In_ UCHAR StringIndex
Definition: wdfusb.h:1080

◆ HidD_GetInputReport()

HIDAPI BOOLEAN WINAPI HidD_GetInputReport ( IN HANDLE  HidDeviceObject,
IN OUT PVOID  ReportBuffer,
IN ULONG  ReportBufferLength 
)

Definition at line 215 of file hid.c.

218{
219 DWORD RetLen;
220 return DeviceIoControl(HidDeviceObject, IOCTL_HID_GET_INPUT_REPORT,
221 NULL, 0,
222 ReportBuffer, ReportBufferLength,
223 &RetLen, NULL) != 0;
224}
#define IOCTL_HID_GET_INPUT_REPORT
Definition: hidclass.h:63

Referenced by test_get_input_report().

◆ HidD_GetManufacturerString()

HIDAPI BOOLEAN WINAPI HidD_GetManufacturerString ( IN HANDLE  HidDeviceObject,
OUT PVOID  Buffer,
IN ULONG  BufferLength 
)

Definition at line 234 of file hid.c.

237{
238 DWORD RetLen;
240 NULL, 0,
242 &RetLen, NULL) != 0;
243}
#define IOCTL_HID_GET_MANUFACTURER_STRING
Definition: hidclass.h:64

◆ HidD_GetMsGenreDescriptor()

HIDAPI BOOLEAN WINAPI HidD_GetMsGenreDescriptor ( IN HANDLE  HidDeviceObject,
OUT PVOID  Buffer,
IN ULONG  BufferLength 
)

Definition at line 484 of file hid.c.

487{
488 DWORD RetLen;
490 0, 0,
492 &RetLen, NULL) != 0;
493}
#define IOCTL_HID_GET_MS_GENRE_DESCRIPTOR
Definition: hidclass.h:77

◆ HidD_GetNumInputBuffers()

HIDAPI BOOLEAN WINAPI HidD_GetNumInputBuffers ( IN HANDLE  HidDeviceObject,
OUT PULONG  NumberBuffers 
)

Definition at line 253 of file hid.c.

255{
256 DWORD RetLen;
258 NULL, 0,
259 NumberBuffers, sizeof(ULONG),
260 &RetLen, NULL) != 0;
261}
#define IOCTL_GET_NUM_DEVICE_INPUT_BUFFERS
Definition: hidclass.h:65

◆ HidD_GetPhysicalDescriptor()

HIDAPI BOOLEAN WINAPI HidD_GetPhysicalDescriptor ( IN HANDLE  HidDeviceObject,
OUT PVOID  Buffer,
IN ULONG  BufferLength 
)

Definition at line 271 of file hid.c.

274{
275 DWORD RetLen;
276 return DeviceIoControl(HidDeviceObject, IOCTL_GET_PHYSICAL_DESCRIPTOR,
277 NULL, 0,
279 &RetLen, NULL) != 0;
280}
#define IOCTL_GET_PHYSICAL_DESCRIPTOR
Definition: hidclass.h:56

◆ HidD_GetPreparsedData()

HIDAPI BOOLEAN WINAPI HidD_GetPreparsedData ( IN HANDLE  HidDeviceObject,
OUT PHIDP_PREPARSED_DATA PreparsedData 
)

Definition at line 290 of file hid.c.

292{
294 DWORD RetLen;
295 BOOLEAN Ret;
296
297 if(PreparsedData == NULL)
298 {
299 return FALSE;
300 }
301
303 NULL, 0,
304 &hci, sizeof(HID_COLLECTION_INFORMATION),
305 &RetLen, NULL))
306 {
307 return FALSE;
308 }
309
311 if(*PreparsedData == NULL)
312 {
314 return FALSE;
315 }
316
318 NULL, 0,
320 &RetLen, NULL) != 0;
321
322 if(!Ret)
323 {
324 /* FIXME - Free the buffer in case we failed to get the descriptor? */
326 }
327#if 0
328 else
329 {
330 /* should we truncate the memory in case RetLen < hci.DescriptorSize? */
331 }
332#endif
333
334 return Ret;
335}
unsigned char BOOLEAN
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define SetLastError(x)
Definition: compat.h:752
#define IOCTL_HID_GET_COLLECTION_DESCRIPTOR
Definition: hidclass.h:58

Referenced by get_device(), test_device_info(), test_get_input_report(), and test_read_device().

◆ HidD_GetProductString()

HIDAPI BOOLEAN WINAPI HidD_GetProductString ( IN HANDLE  HidDeviceObject,
OUT PVOID  Buffer,
IN ULONG  BufferLength 
)

Definition at line 345 of file hid.c.

348{
349 DWORD RetLen;
350 return DeviceIoControl(HidDeviceObject, IOCTL_HID_GET_PRODUCT_STRING,
351 NULL, 0,
353 &RetLen, NULL) != 0;
354}
#define IOCTL_HID_GET_PRODUCT_STRING
Definition: hidclass.h:67

Referenced by test_device_info(), test_get_input_report(), and test_read_device().

◆ HidD_GetSerialNumberString()

HIDAPI BOOLEAN WINAPI HidD_GetSerialNumberString ( IN HANDLE  HidDeviceObject,
OUT PVOID  Buffer,
IN ULONG  BufferLength 
)

Definition at line 364 of file hid.c.

367{
368 DWORD RetLen;
370 NULL, 0,
372 &RetLen, NULL) != 0;
373}
#define IOCTL_HID_GET_SERIALNUMBER_STRING
Definition: hidclass.h:68

◆ HidD_Hello()

HIDAPI ULONG WINAPI HidD_Hello ( OUT PCHAR  Buffer,
IN ULONG  BufferLength 
)

Definition at line 389 of file hid.c.

391{
392 const CHAR HelloString[] = "Hello\n";
393
394 if(BufferLength > 0)
395 {
396 memcpy(Buffer, HelloString, min(sizeof(HelloString), BufferLength));
397 }
398
399 return sizeof(HelloString);
400}
#define min(a, b)
Definition: monoChain.cc:55
char CHAR
Definition: xmlstorage.h:175

◆ HidD_SetConfiguration()

HIDAPI BOOLEAN WINAPI HidD_SetConfiguration ( IN HANDLE  HidDeviceObject,
IN PHIDD_CONFIGURATION  Configuration,
IN ULONG  ConfigurationLength 
)

Definition at line 523 of file hid.c.

526{
527 BOOLEAN Ret = FALSE;
528
530 {
531 Ret = DeviceIoControl(HidDeviceObject, IOCTL_HID_SET_DRIVER_CONFIG,
532 0, 0,
533 (PVOID)&Configuration->size, ConfigurationLength - sizeof(ULONG),
534 (PULONG)&Configuration->cookie, NULL) != 0;
535 }
536 else
537 {
539 }
540
541 return Ret;
542}
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define IOCTL_HID_SET_DRIVER_CONFIG
Definition: hidclass.h:75

◆ HidD_SetFeature()

HIDAPI BOOLEAN WINAPI HidD_SetFeature ( IN HANDLE  HidDeviceObject,
IN PVOID  ReportBuffer,
IN ULONG  ReportBufferLength 
)

Definition at line 410 of file hid.c.

413{
414 DWORD RetLen;
415 return DeviceIoControl(HidDeviceObject, IOCTL_HID_SET_FEATURE,
416 ReportBuffer, ReportBufferLength,
417 NULL, 0,
418 &RetLen, NULL) != 0;
419}
#define IOCTL_HID_SET_FEATURE
Definition: hidclass.h:69

◆ HidD_SetNumInputBuffers()

HIDAPI BOOLEAN WINAPI HidD_SetNumInputBuffers ( IN HANDLE  HidDeviceObject,
IN ULONG  NumberBuffers 
)

Definition at line 429 of file hid.c.

431{
432 DWORD RetLen;
434 &NumberBuffers, sizeof(ULONG),
435 NULL, 0,
436 &RetLen, NULL) != 0;
437}
#define IOCTL_SET_NUM_DEVICE_INPUT_BUFFERS
Definition: hidclass.h:70

◆ HidD_SetOutputReport()

HIDAPI BOOLEAN WINAPI HidD_SetOutputReport ( IN HANDLE  HidDeviceObject,
IN PVOID  ReportBuffer,
IN ULONG  ReportBufferLength 
)

Definition at line 447 of file hid.c.

450{
451 DWORD RetLen;
452 return DeviceIoControl(HidDeviceObject, IOCTL_HID_SET_OUTPUT_REPORT,
453 ReportBuffer, ReportBufferLength,
454 NULL, 0,
455 &RetLen, NULL) != 0;
456}
#define IOCTL_HID_SET_OUTPUT_REPORT
Definition: hidclass.h:71

◆ ZeroFunction()

VOID NTAPI ZeroFunction ( IN PVOID  Item,
IN ULONG  ItemSize 
)

Variable Documentation

◆ hDllInstance

HINSTANCE hDllInstance

Definition at line 38 of file hid.c.

Referenced by DllMain().

◆ HidClassGuid

const GUID HidClassGuid = {0x4D1E55B2, 0xF16F, 0x11CF, {0x88,0xCB,0x00,0x11,0x11,0x00,0x00,0x30}}

Definition at line 41 of file hid.c.

Referenced by HidD_GetHidGuid().