ReactOS  0.4.15-dev-1070-ge1a01de
device.c File Reference
#include <stdio.h>
#include "ntstatus.h"
#include "windows.h"
#include "setupapi.h"
#include "hidusage.h"
#include "ddk/hidsdi.h"
#include "wine/test.h"
Include dependency graph for device.c:

Go to the source code of this file.

Macros

#define WIN32_NO_STATUS
 
#define READ_MAX_TIME   5000
 

Typedefs

typedef void() device_test(HANDLE device)
 

Functions

static void test_device_info (HANDLE device)
 
static void run_for_each_device (device_test *test)
 
static HANDLE get_device (USHORT page, USHORT usages[], UINT usage_count, DWORD access)
 
static void process_data (HIDP_CAPS Caps, PHIDP_PREPARSED_DATA ppd, CHAR *data, DWORD data_length)
 
static void test_read_device (void)
 
static void test_get_input_report (void)
 
 START_TEST (device)
 

Macro Definition Documentation

◆ READ_MAX_TIME

#define READ_MAX_TIME   5000

Definition at line 29 of file device.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 21 of file device.c.

Typedef Documentation

◆ device_test

typedef void() device_test(HANDLE device)

Definition at line 31 of file device.c.

Function Documentation

◆ get_device()

static HANDLE get_device ( USHORT  page,
USHORT  usages[],
UINT  usage_count,
DWORD  access 
)
static

Definition at line 106 of file device.c.

107 {
108  GUID hid_guid;
109  HDEVINFO info_set;
110  DWORD index = 0;
111  SP_DEVICE_INTERFACE_DATA interface_data;
112  DWORD detail_size = MAX_PATH * sizeof(WCHAR);
115  BOOL rc;
116 
117  HidD_GetHidGuid(&hid_guid);
118 
119  ZeroMemory(&interface_data, sizeof(interface_data));
120  interface_data.cbSize = sizeof(interface_data);
121 
122  data = HeapAlloc(GetProcessHeap(), 0 , sizeof(*data) + detail_size);
123  data->cbSize = sizeof(*data);
124 
126  while (SetupDiEnumDeviceInterfaces(info_set, NULL, &hid_guid, index, &interface_data))
127  {
128  index ++;
129 
130  if (SetupDiGetDeviceInterfaceDetailW(info_set, &interface_data, data, sizeof(*data) + detail_size, NULL, NULL))
131  {
133  HIDP_CAPS Caps;
136  {
137  trace("Not enough permissions to read device %s.\n", wine_dbgstr_w(data->DevicePath));
138  continue;
139  }
140  ok(file != INVALID_HANDLE_VALUE, "got error %u\n", GetLastError());
141 
142  rc = HidD_GetPreparsedData(file, &ppd);
143  ok(rc, "Failed to get preparsed data(0x%x)\n", GetLastError());
144  status = HidP_GetCaps(ppd, &Caps);
145  ok(status == HIDP_STATUS_SUCCESS, "Failed to get Caps(0x%x)\n", status);
146  rc = HidD_FreePreparsedData(ppd);
147  ok(rc, "Failed to free preparsed data(0x%x)\n", GetLastError());
148  if (!page || page == Caps.UsagePage)
149  {
150  int j;
151  if (!usage_count)
152  {
155  return file;
156  }
157  for (j = 0; j < usage_count; j++)
158  if (!usages[j] || usages[j] == Caps.Usage)
159  {
162  return file;
163  }
164  }
165  CloseHandle(file);
166  }
167  }
170  return NULL;
171 }
#define CloseHandle
Definition: compat.h:487
HDEVINFO WINAPI SetupDiGetClassDevsW(CONST GUID *class, LPCWSTR enumstr, HWND parent, DWORD flags)
Definition: devinst.c:2297
char * wine_dbgstr_w(const wchar_t *wstr)
Definition: atltest.h:87
BOOL WINAPI SetupDiGetDeviceInterfaceDetailW(HDEVINFO DeviceInfoSet, PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData, PSP_DEVICE_INTERFACE_DETAIL_DATA_W DeviceInterfaceDetailData, DWORD DeviceInterfaceDetailDataSize, PDWORD RequiredSize, PSP_DEVINFO_DATA DeviceInfoData)
Definition: devinst.c:3016
LONG NTSTATUS
Definition: precomp.h:26
HIDAPI BOOLEAN WINAPI HidD_GetPreparsedData(IN HANDLE HidDeviceObject, OUT PHIDP_PREPARSED_DATA *PreparsedData)
Definition: hid.c:290
#define INVALID_HANDLE_VALUE
Definition: compat.h:479
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
#define ZeroMemory
Definition: winbase.h:1648
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_SHARE_READ
Definition: compat.h:136
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
Definition: module.h:566
GLuint index
Definition: glext.h:6031
#define OPEN_EXISTING
Definition: compat.h:523
HIDAPI NTSTATUS NTAPI HidP_GetCaps(IN PHIDP_PREPARSED_DATA PreparsedData, OUT PHIDP_CAPS Capabilities)
Definition: hidp.c:26
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 GLint GLint j
Definition: glfuncs.h:250
HIDAPI BOOLEAN WINAPI HidD_FreePreparsedData(IN PHIDP_PREPARSED_DATA PreparsedData)
Definition: hid.c:139
#define GetProcessHeap()
Definition: compat.h:484
#define trace
Definition: atltest.h:70
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
USAGE UsagePage
Definition: hidpi.h:151
struct _HIDP_PREPARSED_DATA * PHIDP_PREPARSED_DATA
Definition: hidpi.h:39
BOOL WINAPI SetupDiDestroyDeviceInfoList(HDEVINFO devinfo)
Definition: devinst.c:2898
#define MAX_PATH
Definition: compat.h:34
const char file[]
Definition: icontest.c:11
unsigned long DWORD
Definition: ntddk_ex.h:95
HIDAPI VOID WINAPI HidD_GetHidGuid(OUT LPGUID HidGuid)
Definition: hid.c:202
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
USAGE Usage
Definition: hidpi.h:150
GLuint GLint GLboolean GLint GLenum access
Definition: glext.h:7866
#define ok(value,...)
Definition: atltest.h:57
BOOL WINAPI SetupDiEnumDeviceInterfaces(HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData, CONST GUID *InterfaceClassGuid, DWORD MemberIndex, PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData)
Definition: devinst.c:2785
#define CreateFileW
Definition: compat.h:489
#define DIGCF_DEVICEINTERFACE
Definition: setupapi.h:174
#define HIDP_STATUS_SUCCESS
Definition: hidpi.h:248
static PCCRYPT_OID_INFO ** usages
Definition: softpub.c:81
#define FILE_FLAG_OVERLAPPED
Definition: disk.h:46
static SERVICE_STATUS status
Definition: service.c:31
#define HeapFree(x, y, z)
Definition: compat.h:483
#define DIGCF_PRESENT
Definition: setupapi.h:171
Definition: fci.c:126
Definition: ps.c:97

Referenced by test_get_input_report(), and test_read_device().

◆ process_data()

static void process_data ( HIDP_CAPS  Caps,
PHIDP_PREPARSED_DATA  ppd,
CHAR data,
DWORD  data_length 
)
static

Definition at line 173 of file device.c.

174 {
175  INT i;
177 
178  if (Caps.NumberInputButtonCaps)
179  {
180  USAGE button_pages[100];
181 
182  for (i = 1; i < 0xff; i++)
183  {
184  ULONG usage_length = 100;
185  status = HidP_GetUsages(HidP_Input, i, 0, button_pages, &usage_length, ppd, data, data_length);
186  ok (status == HIDP_STATUS_SUCCESS || usage_length == 0,
187  "HidP_GetUsages failed (%x) but usage length still %i\n", status, usage_length);
188  if (usage_length)
189  {
190  CHAR report[50];
191  int count;
192  int j;
193 
194  count = usage_length;
195  j = 0;
196  report[0] = 0;
197  trace("\tButtons [0x%x: %i buttons]:\n", i, usage_length);
198  for (count = 0; count < usage_length; count += 15)
199  {
200  for (j=count; j < count+15 && j < usage_length; j++)
201  {
202  CHAR btn[7];
203  sprintf(btn, "%i ", button_pages[j]);
204  strcat(report, btn);
205  }
206  trace("\t\t%s\n", report);
207  }
208  }
209  }
210  }
211 
212  if (Caps.NumberInputValueCaps)
213  {
214  ULONG value;
215  USHORT length;
217 
221  ok(status == HIDP_STATUS_SUCCESS, "Failed to get value caps (%x)\n",status);
222 
223  trace("\tValues:\n");
224  for (i = 0; i < length; i++)
225  {
227  values[i].Range.UsageMin, &value, ppd, data, data_length);
228  ok(status == HIDP_STATUS_SUCCESS, "Failed to get value [%i,%i] (%x)\n",
229  values[i].UsagePage, values[i].Range.UsageMin, status);
230  trace("[%02x, %02x]: %u\n",values[i].UsagePage, values[i].Range.UsageMin, value);
231  }
232 
234  }
235 }
USHORT NumberInputButtonCaps
Definition: hidpi.h:157
USHORT NumberInputValueCaps
Definition: hidpi.h:158
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
GLuint GLuint GLsizei count
Definition: gl.h:1545
char CHAR
Definition: xmlstorage.h:175
_Must_inspect_result_ HIDAPI NTSTATUS NTAPI HidP_GetUsageValue(_In_ HIDP_REPORT_TYPE ReportType, _In_ USAGE UsagePage, _In_ USHORT LinkCollection, _In_ USAGE Usage, _Out_ PULONG UsageValue, _In_ PHIDP_PREPARSED_DATA PreparsedData, _In_reads_bytes_(ReportLength) PCHAR Report, _In_ ULONG ReportLength)
LONG NTSTATUS
Definition: precomp.h:26
GLboolean GLenum GLenum GLvoid * values
Definition: glext.h:5666
int32_t INT
Definition: typedefs.h:58
#define sprintf(buf, format,...)
Definition: sprintf.c:55
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
smooth NULL
Definition: ftsmooth.c:416
static void report(const DATA_BLOB *pDataIn, const DATA_BLOB *pOptionalEntropy, CRYPTPROTECT_PROMPTSTRUCT *pPromptStruct, DWORD dwFlags)
Definition: protectdata.c:769
_Must_inspect_result_ _In_ USAGE UsagePage
Definition: hidpi.h:382
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 GLint GLint j
Definition: glfuncs.h:250
#define GetProcessHeap()
Definition: compat.h:484
#define trace
Definition: atltest.h:70
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
USHORT USAGE
Definition: hidusage.h:30
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
_Must_inspect_result_ HIDAPI NTSTATUS NTAPI HidP_GetUsages(_In_ HIDP_REPORT_TYPE ReportType, _In_ USAGE UsagePage, _In_ USHORT LinkCollection, _Out_writes_to_(*UsageLength, *UsageLength) USAGE *UsageList, _Inout_ ULONG *UsageLength, _In_ PHIDP_PREPARSED_DATA PreparsedData, _Out_writes_bytes_(ReportLength) PCHAR Report, _In_ ULONG ReportLength)
Definition: range.c:39
GLsizei const GLfloat * value
Definition: glext.h:6069
HIDAPI NTSTATUS NTAPI HidP_GetValueCaps(HIDP_REPORT_TYPE ReportType, PHIDP_VALUE_CAPS ValueCaps, PUSHORT ValueCapsLength, PHIDP_PREPARSED_DATA PreparsedData)
Definition: hidp.c:524
unsigned short USHORT
Definition: pedump.c:61
#define ok(value,...)
Definition: atltest.h:57
unsigned int ULONG
Definition: retypes.h:1
#define HIDP_STATUS_SUCCESS
Definition: hidpi.h:248
static SERVICE_STATUS status
Definition: service.c:31
#define HeapFree(x, y, z)
Definition: compat.h:483
Definition: ps.c:97

Referenced by test_get_input_report(), and test_read_device().

◆ run_for_each_device()

static void run_for_each_device ( device_test test)
static

Definition at line 57 of file device.c.

58 {
59  GUID hid_guid;
60  HDEVINFO info_set;
61  DWORD index = 0;
62  SP_DEVICE_INTERFACE_DATA interface_data;
63  DWORD detail_size = MAX_PATH * sizeof(WCHAR);
65 
66  HidD_GetHidGuid(&hid_guid);
67 
68  ZeroMemory(&interface_data, sizeof(interface_data));
69  interface_data.cbSize = sizeof(interface_data);
70 
71  data = HeapAlloc(GetProcessHeap(), 0, sizeof(*data) + detail_size);
72  data->cbSize = sizeof(*data);
73 
75  while (SetupDiEnumDeviceInterfaces(info_set, NULL, &hid_guid, index, &interface_data))
76  {
77  index ++;
78 
79  if (SetupDiGetDeviceInterfaceDetailW(info_set, &interface_data, data, sizeof(*data) + detail_size, NULL, NULL))
80  {
83  {
84  trace("Not enough permissions to read device %s.\n", wine_dbgstr_w(data->DevicePath));
85  continue;
86  }
88  {
89  trace("Device is busy: %s.\n", wine_dbgstr_w(data->DevicePath));
90  continue;
91  }
92 
93  ok(file != INVALID_HANDLE_VALUE, "Failed to open %s, error %u.\n",
94  wine_dbgstr_w(data->DevicePath), GetLastError());
95 
97  test(file);
98 
100  }
101  }
104 }
#define CloseHandle
Definition: compat.h:487
HDEVINFO WINAPI SetupDiGetClassDevsW(CONST GUID *class, LPCWSTR enumstr, HWND parent, DWORD flags)
Definition: devinst.c:2297
char * wine_dbgstr_w(const wchar_t *wstr)
Definition: atltest.h:87
BOOL WINAPI SetupDiGetDeviceInterfaceDetailW(HDEVINFO DeviceInfoSet, PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData, PSP_DEVICE_INTERFACE_DETAIL_DATA_W DeviceInterfaceDetailData, DWORD DeviceInterfaceDetailDataSize, PDWORD RequiredSize, PSP_DEVINFO_DATA DeviceInfoData)
Definition: devinst.c:3016
#define INVALID_HANDLE_VALUE
Definition: compat.h:479
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
#define ZeroMemory
Definition: winbase.h:1648
#define test
Definition: rosglue.h:37
#define FILE_SHARE_READ
Definition: compat.h:136
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
smooth NULL
Definition: ftsmooth.c:416
GLuint index
Definition: glext.h:6031
#define OPEN_EXISTING
Definition: compat.h:523
#define GetProcessHeap()
Definition: compat.h:484
#define trace
Definition: atltest.h:70
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
BOOL WINAPI SetupDiDestroyDeviceInfoList(HDEVINFO devinfo)
Definition: devinst.c:2898
#define MAX_PATH
Definition: compat.h:34
unsigned long DWORD
Definition: ntddk_ex.h:95
HIDAPI VOID WINAPI HidD_GetHidGuid(OUT LPGUID HidGuid)
Definition: hid.c:202
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define GENERIC_READ
Definition: compat.h:135
#define ERROR_SHARING_VIOLATION
Definition: winerror.h:135
#define ok(value,...)
Definition: atltest.h:57
BOOL WINAPI SetupDiEnumDeviceInterfaces(HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData, CONST GUID *InterfaceClassGuid, DWORD MemberIndex, PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData)
Definition: devinst.c:2785
#define CreateFileW
Definition: compat.h:489
#define DIGCF_DEVICEINTERFACE
Definition: setupapi.h:174
#define HeapFree(x, y, z)
Definition: compat.h:483
#define DIGCF_PRESENT
Definition: setupapi.h:171
Definition: fci.c:126

Referenced by START_TEST().

◆ START_TEST()

START_TEST ( device  )

Definition at line 400 of file device.c.

401 {
405 }
static void test_device_info(HANDLE device)
Definition: device.c:33
static void test_get_input_report(void)
Definition: device.c:324
static void run_for_each_device(device_test *test)
Definition: device.c:57
static void test_read_device(void)
Definition: device.c:237

◆ test_device_info()

static void test_device_info ( HANDLE  device)
static

Definition at line 33 of file device.c.

34 {
36  HIDP_CAPS Caps;
37  HIDD_ATTRIBUTES attributes;
39  BOOL rc;
40  WCHAR device_name[128];
41 
42  rc = HidD_GetPreparsedData(device, &ppd);
43  ok(rc, "Failed to get preparsed data(0x%x)\n", GetLastError());
44  status = HidP_GetCaps(ppd, &Caps);
45  ok(status == HIDP_STATUS_SUCCESS, "Failed to get Caps(0x%x)\n", status);
47  ok(rc, "Failed to get product string(0x%x)\n", GetLastError());
48  trace("Found device %s (%02x, %02x)\n", wine_dbgstr_w(device_name), Caps.UsagePage, Caps.Usage);
49  rc = HidD_FreePreparsedData(ppd);
50  ok(rc, "Failed to free preparsed data(0x%x)\n", GetLastError());
51  rc = HidD_GetAttributes(device, &attributes);
52  ok(rc, "Failed to get device attributes (0x%x)\n", GetLastError());
53  ok(attributes.Size == sizeof(attributes), "Unexpected HIDD_ATTRIBUTES size: %d\n", attributes.Size);
54  trace("Device attributes: vid:%04x pid:%04x ver:%04x\n", attributes.VendorID, attributes.ProductID, attributes.VersionNumber);
55 }
char * wine_dbgstr_w(const wchar_t *wstr)
Definition: atltest.h:87
LONG NTSTATUS
Definition: precomp.h:26
static const WCHAR device_name[]
Definition: btrfs.c:63
HIDAPI BOOLEAN WINAPI HidD_GetPreparsedData(IN HANDLE HidDeviceObject, OUT PHIDP_PREPARSED_DATA *PreparsedData)
Definition: hid.c:290
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
ULONG Size
Definition: hidpi.h:84
USHORT VersionNumber
Definition: hidpi.h:87
HIDAPI BOOLEAN WINAPI HidD_GetAttributes(IN HANDLE HidDeviceObject, OUT PHIDD_ATTRIBUTES Attributes)
Definition: hid.c:152
USHORT VendorID
Definition: hidpi.h:85
unsigned int BOOL
Definition: ntddk_ex.h:94
Definition: devices.h:37
HIDAPI NTSTATUS NTAPI HidP_GetCaps(IN PHIDP_PREPARSED_DATA PreparsedData, OUT PHIDP_CAPS Capabilities)
Definition: hidp.c:26
HIDAPI BOOLEAN WINAPI HidD_FreePreparsedData(IN PHIDP_PREPARSED_DATA PreparsedData)
Definition: hid.c:139
USHORT ProductID
Definition: hidpi.h:86
#define trace
Definition: atltest.h:70
__wchar_t WCHAR
Definition: xmlstorage.h:180
USAGE UsagePage
Definition: hidpi.h:151
struct _HIDP_PREPARSED_DATA * PHIDP_PREPARSED_DATA
Definition: hidpi.h:39
HIDAPI BOOLEAN WINAPI HidD_GetProductString(IN HANDLE HidDeviceObject, OUT PVOID Buffer, IN ULONG BufferLength)
Definition: hid.c:345
USAGE Usage
Definition: hidpi.h:150
#define ok(value,...)
Definition: atltest.h:57
#define HIDP_STATUS_SUCCESS
Definition: hidpi.h:248
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

Referenced by START_TEST().

◆ test_get_input_report()

static void test_get_input_report ( void  )
static

Definition at line 324 of file device.c.

325 {
327  HIDP_CAPS Caps;
328  WCHAR device_name[128];
329  CHAR *data = NULL;
330  DWORD tick, spent, max_time;
331  char *report;
332  BOOL rc;
334 
337 
338  if (!device)
340 
341  if (!device)
342  {
343  trace("No device found for testing\n");
344  return;
345  }
347  ok(rc, "Failed to get product string(0x%x)\n", GetLastError());
348  trace("HidD_GetInputRpeort tests on device :%s\n",wine_dbgstr_w(device_name));
349 
350  rc = HidD_GetPreparsedData(device, &ppd);
351  ok(rc, "Failed to get preparsed data(0x%x)\n", GetLastError());
352  status = HidP_GetCaps(ppd, &Caps);
353  ok(status == HIDP_STATUS_SUCCESS, "Failed to get Caps(0x%x)\n", status);
355 
357  max_time = READ_MAX_TIME;
358  else
359  max_time = 100;
361  trace("Test your device for the next %i seconds\n", max_time/1000);
363  tick = GetTickCount();
364  spent = 0;
365  do
366  {
367  int i;
368 
369  data[0] = 0; /* Just testing report ID 0 for now, That will catch most devices */
371  spent = GetTickCount() - tick;
372 
373  if (rc)
374  {
375  ok(data[0] == 0, "Report ID (0) is not the first byte of the data\n");
376  report[0] = 0;
377  for (i = 0; i < Caps.InputReportByteLength; i++)
378  {
379  char bytestr[5];
380  sprintf(bytestr, "%x ", (BYTE)data[i]);
381  strcat(report, bytestr);
382  }
383  trace("Input report (%i): %s\n", Caps.InputReportByteLength, report);
384 
385  process_data(Caps, ppd, data, Caps.InputReportByteLength);
386  }
387  else
388  trace("Failed to get Input Report, (%x)\n", rc);
389  trace("REMAINING: %d ms\n", max_time - spent);
390  Sleep(500);
391  } while(spent < max_time);
392 
393  rc = HidD_FreePreparsedData(ppd);
394  ok(rc, "Failed to free preparsed data(0x%x)\n", GetLastError());
398 }
#define CloseHandle
Definition: compat.h:487
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
GLint x0
Definition: linetemp.h:95
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
char * wine_dbgstr_w(const wchar_t *wstr)
Definition: atltest.h:87
char CHAR
Definition: xmlstorage.h:175
LONG NTSTATUS
Definition: precomp.h:26
static const WCHAR device_name[]
Definition: btrfs.c:63
DWORD WINAPI GetTickCount(VOID)
Definition: time.c:455
HIDAPI BOOLEAN WINAPI HidD_GetPreparsedData(IN HANDLE HidDeviceObject, OUT PHIDP_PREPARSED_DATA *PreparsedData)
Definition: hid.c:290
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
int winetest_interactive
HIDAPI BOOLEAN WINAPI HidD_GetInputReport(IN HANDLE HidDeviceObject, IN OUT PVOID ReportBuffer, IN ULONG ReportBufferLength)
Definition: hid.c:215
#define sprintf(buf, format,...)
Definition: sprintf.c:55
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
unsigned int BOOL
Definition: ntddk_ex.h:94
Definition: devices.h:37
smooth NULL
Definition: ftsmooth.c:416
static void report(const DATA_BLOB *pDataIn, const DATA_BLOB *pOptionalEntropy, CRYPTPROTECT_PROMPTSTRUCT *pPromptStruct, DWORD dwFlags)
Definition: protectdata.c:769
HIDAPI NTSTATUS NTAPI HidP_GetCaps(IN PHIDP_PREPARSED_DATA PreparsedData, OUT PHIDP_CAPS Capabilities)
Definition: hidp.c:26
HIDAPI BOOLEAN WINAPI HidD_FreePreparsedData(IN PHIDP_PREPARSED_DATA PreparsedData)
Definition: hid.c:139
#define HID_USAGE_PAGE_GENERIC
Definition: hidusage.h:176
#define GetProcessHeap()
Definition: compat.h:484
static HANDLE get_device(USHORT page, USHORT usages[], UINT usage_count, DWORD access)
Definition: device.c:106
#define trace
Definition: atltest.h:70
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
struct _HIDP_PREPARSED_DATA * PHIDP_PREPARSED_DATA
Definition: hidpi.h:39
unsigned long DWORD
Definition: ntddk_ex.h:95
HIDAPI BOOLEAN WINAPI HidD_GetProductString(IN HANDLE HidDeviceObject, OUT PVOID Buffer, IN ULONG BufferLength)
Definition: hid.c:345
USHORT USAGE
Definition: hidusage.h:30
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define HID_USAGE_GENERIC_JOYSTICK
Definition: hidusage.h:34
#define READ_MAX_TIME
Definition: device.c:29
static void process_data(HIDP_CAPS Caps, PHIDP_PREPARSED_DATA ppd, CHAR *data, DWORD data_length)
Definition: device.c:173
#define GENERIC_READ
Definition: compat.h:135
unsigned char BYTE
Definition: xxhash.c:193
#define ok(value,...)
Definition: atltest.h:57
#define HIDP_STATUS_SUCCESS
Definition: hidpi.h:248
static SERVICE_STATUS status
Definition: service.c:31
#define HeapFree(x, y, z)
Definition: compat.h:483
USHORT InputReportByteLength
Definition: hidpi.h:152
#define HID_USAGE_GENERIC_GAMEPAD
Definition: hidusage.h:35
Definition: ps.c:97

Referenced by START_TEST().

◆ test_read_device()

static void test_read_device ( void  )
static

Definition at line 237 of file device.c.

238 {
240  HIDP_CAPS Caps;
242  WCHAR device_name[128];
243  CHAR *data = NULL;
244  DWORD read;
245  BOOL rc;
247  DWORD timeout, tick, spent, max_time;
248  char *report;
249 
252 
253  if (!device)
255 
256  if (!device)
257  {
258  trace("No device found for reading\n");
259  return;
260  }
262  ok(rc, "Failed to get product string(0x%x)\n", GetLastError());
263  trace("Read tests on device :%s\n",wine_dbgstr_w(device_name));
264 
265  rc = HidD_GetPreparsedData(device, &ppd);
266  ok(rc, "Failed to get preparsed data(0x%x)\n", GetLastError());
267  status = HidP_GetCaps(ppd, &Caps);
268  ok(status == HIDP_STATUS_SUCCESS, "Failed to get Caps(0x%x)\n", status);
270 
271  memset(&overlapped, 0, sizeof(overlapped));
274  {
275  max_time = READ_MAX_TIME;
276  timeout = 1000;
277  }
278  else
279  max_time = timeout = 100;
281  trace("Test your device for the next %i seconds\n", max_time/1000);
283  tick = GetTickCount();
284  spent = 0;
285  do
286  {
289  {
290  ResetEvent(overlapped.hEvent);
291  spent = GetTickCount() - tick;
292  trace("REMAINING: %d ms\n", max_time - spent);
293  continue;
294  }
295  ResetEvent(overlapped.hEvent);
296  spent = GetTickCount() - tick;
298  if (read)
299  {
300  int i;
301 
302  report[0] = 0;
303  for (i = 0; i < read && i < Caps.InputReportByteLength; i++)
304  {
305  char bytestr[5];
306  sprintf(bytestr, "%x ", (BYTE)data[i]);
307  strcat(report, bytestr);
308  }
309  trace("Input report (%i): %s\n", read, report);
310 
311  process_data(Caps, ppd, data, read);
312  }
313  trace("REMAINING: %d ms\n", max_time - spent);
314  } while(spent < max_time);
315 
316  CloseHandle(overlapped.hEvent);
317  rc = HidD_FreePreparsedData(ppd);
318  ok(rc, "Failed to free preparsed data(0x%x)\n", GetLastError());
322 }
#define CloseHandle
Definition: compat.h:487
GLint x0
Definition: linetemp.h:95
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
BOOL WINAPI GetOverlappedResult(IN HANDLE hFile, IN LPOVERLAPPED lpOverlapped, OUT LPDWORD lpNumberOfBytesTransferred, IN BOOL bWait)
Definition: iocompl.c:204
char * wine_dbgstr_w(const wchar_t *wstr)
Definition: atltest.h:87
char CHAR
Definition: xmlstorage.h:175
LONG NTSTATUS
Definition: precomp.h:26
static const WCHAR device_name[]
Definition: btrfs.c:63
DWORD WINAPI GetTickCount(VOID)
Definition: time.c:455
HIDAPI BOOLEAN WINAPI HidD_GetPreparsedData(IN HANDLE HidDeviceObject, OUT PHIDP_PREPARSED_DATA *PreparsedData)
Definition: hid.c:290
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
Definition: dhcpd.h:245
int winetest_interactive
GLbitfield GLuint64 timeout
Definition: glext.h:7164
#define sprintf(buf, format,...)
Definition: sprintf.c:55
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
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
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
Definition: devices.h:37
smooth NULL
Definition: ftsmooth.c:416
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventA(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCSTR lpName OPTIONAL)
Definition: synch.c:637
static void report(const DATA_BLOB *pDataIn, const DATA_BLOB *pOptionalEntropy, CRYPTPROTECT_PROMPTSTRUCT *pPromptStruct, DWORD dwFlags)
Definition: protectdata.c:769
HIDAPI NTSTATUS NTAPI HidP_GetCaps(IN PHIDP_PREPARSED_DATA PreparsedData, OUT PHIDP_CAPS Capabilities)
Definition: hidp.c:26
HIDAPI BOOLEAN WINAPI HidD_FreePreparsedData(IN PHIDP_PREPARSED_DATA PreparsedData)
Definition: hid.c:139
#define HID_USAGE_PAGE_GENERIC
Definition: hidusage.h:176
#define WAIT_OBJECT_0
Definition: winbase.h:387
#define GetProcessHeap()
Definition: compat.h:484
static HANDLE get_device(USHORT page, USHORT usages[], UINT usage_count, DWORD access)
Definition: device.c:106
#define trace
Definition: atltest.h:70
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
struct _HIDP_PREPARSED_DATA * PHIDP_PREPARSED_DATA
Definition: hidpi.h:39
unsigned long DWORD
Definition: ntddk_ex.h:95
HIDAPI BOOLEAN WINAPI HidD_GetProductString(IN HANDLE HidDeviceObject, OUT PVOID Buffer, IN ULONG BufferLength)
Definition: hid.c:345
USHORT USAGE
Definition: hidusage.h:30
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define HID_USAGE_GENERIC_JOYSTICK
Definition: hidusage.h:34
#define READ_MAX_TIME
Definition: device.c:29
static void process_data(HIDP_CAPS Caps, PHIDP_PREPARSED_DATA ppd, CHAR *data, DWORD data_length)
Definition: device.c:173
#define GENERIC_READ
Definition: compat.h:135
unsigned char BYTE
Definition: xxhash.c:193
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED * overlapped
Definition: sock.c:82
#define ok(value,...)
Definition: atltest.h:57
#define ReadFile(a, b, c, d, e)
Definition: compat.h:490
BOOL WINAPI DECLSPEC_HOTPATCH ResetEvent(IN HANDLE hEvent)
Definition: synch.c:714
#define HIDP_STATUS_SUCCESS
Definition: hidpi.h:248
#define memset(x, y, z)
Definition: compat.h:39
static SERVICE_STATUS status
Definition: service.c:31
#define HeapFree(x, y, z)
Definition: compat.h:483
USHORT InputReportByteLength
Definition: hidpi.h:152
_CRTIMP int __cdecl read(_In_ int _FileHandle, _Out_writes_bytes_(_MaxCharCount) void *_DstBuf, _In_ unsigned int _MaxCharCount)
#define HID_USAGE_GENERIC_GAMEPAD
Definition: hidusage.h:35
Definition: ps.c:97

Referenced by START_TEST().