windows: fix USB 3.0 speed detection on Windows 8 or later
[platform/upstream/libusb.git] / libusb / os / windows_usb.h
1 /*
2  * Windows backend for libusb 1.0
3  * Copyright © 2009-2012 Pete Batard <pete@akeo.ie>
4  * With contributions from Michael Plante, Orin Eman et al.
5  * Parts of this code adapted from libusb-win32-v1 by Stephan Meyer
6  * Major code testing contribution by Xiaofan Chen
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22
23 #pragma once
24
25 #include "windows_common.h"
26
27 #if defined(_MSC_VER)
28 // disable /W4 MSVC warnings that are benign
29 #pragma warning(disable:4127) // conditional expression is constant
30 #pragma warning(disable:4100) // unreferenced formal parameter
31 #pragma warning(disable:4214) // bit field types other than int
32 #pragma warning(disable:4201) // nameless struct/union
33 #endif
34
35 // Missing from MSVC6 setupapi.h
36 #if !defined(SPDRP_ADDRESS)
37 #define SPDRP_ADDRESS   28
38 #endif
39 #if !defined(SPDRP_INSTALL_STATE)
40 #define SPDRP_INSTALL_STATE     34
41 #endif
42
43 // Missing from MinGW
44 #if !defined(FACILITY_SETUPAPI)
45 #define FACILITY_SETUPAPI       15
46 #endif
47
48 #if defined(__CYGWIN__ )
49 #define _stricmp stricmp
50 // cygwin produces a warning unless these prototypes are defined
51 extern int _snprintf(char *buffer, size_t count, const char *format, ...);
52 extern char *_strdup(const char *strSource);
53 // _beginthreadex is MSVCRT => unavailable for cygwin. Fallback to using CreateThread
54 #define _beginthreadex(a, b, c, d, e, f) CreateThread(a, b, (LPTHREAD_START_ROUTINE)c, d, e, f)
55 #endif
56
57 #define MAX_CTRL_BUFFER_LENGTH      4096
58 #define MAX_USB_DEVICES             256
59 #define MAX_USB_STRING_LENGTH       128
60 #define MAX_HID_REPORT_SIZE         1024
61 #define MAX_HID_DESCRIPTOR_SIZE     256
62 #define MAX_GUID_STRING_LENGTH      40
63 #define MAX_PATH_LENGTH             128
64 #define MAX_KEY_LENGTH              256
65 #define LIST_SEPARATOR              ';'
66 #define HTAB_SIZE                   1021
67
68 // Handle code for HID interface that have been claimed ("dibs")
69 #define INTERFACE_CLAIMED           ((HANDLE)(intptr_t)0xD1B5)
70 // Additional return code for HID operations that completed synchronously
71 #define LIBUSB_COMPLETED            (LIBUSB_SUCCESS + 1)
72
73 // http://msdn.microsoft.com/en-us/library/ff545978.aspx
74 // http://msdn.microsoft.com/en-us/library/ff545972.aspx
75 // http://msdn.microsoft.com/en-us/library/ff545982.aspx
76 #if !defined(GUID_DEVINTERFACE_USB_HOST_CONTROLLER)
77 const GUID GUID_DEVINTERFACE_USB_HOST_CONTROLLER = { 0x3ABF6F2D, 0x71C4, 0x462A, {0x8A, 0x92, 0x1E, 0x68, 0x61, 0xE6, 0xAF, 0x27} };
78 #endif
79 #if !defined(GUID_DEVINTERFACE_USB_DEVICE)
80 const GUID GUID_DEVINTERFACE_USB_DEVICE = { 0xA5DCBF10, 0x6530, 0x11D2, {0x90, 0x1F, 0x00, 0xC0, 0x4F, 0xB9, 0x51, 0xED} };
81 #endif
82 #if !defined(GUID_DEVINTERFACE_USB_HUB)
83 const GUID GUID_DEVINTERFACE_USB_HUB = { 0xF18A0E88, 0xC30C, 0x11D0, {0x88, 0x15, 0x00, 0xA0, 0xC9, 0x06, 0xBE, 0xD8} };
84 #endif
85 #if !defined(GUID_DEVINTERFACE_LIBUSB0_FILTER)
86 const GUID GUID_DEVINTERFACE_LIBUSB0_FILTER = { 0xF9F3FF14, 0xAE21, 0x48A0, {0x8A, 0x25, 0x80, 0x11, 0xA7, 0xA9, 0x31, 0xD9} };
87 #endif
88
89
90 /*
91  * Multiple USB API backend support
92  */
93 #define USB_API_UNSUPPORTED 0
94 #define USB_API_HUB         1
95 #define USB_API_COMPOSITE   2
96 #define USB_API_WINUSBX     3
97 #define USB_API_HID         4
98 #define USB_API_MAX         5
99 // The following is used to indicate if the HID or composite extra props have already been set.
100 #define USB_API_SET         (1<<USB_API_MAX) 
101
102 // Sub-APIs for WinUSB-like driver APIs (WinUSB, libusbK, libusb-win32 through the libusbK DLL)
103 // Must have the same values as the KUSB_DRVID enum from libusbk.h
104 #define SUB_API_NOTSET      -1
105 #define SUB_API_LIBUSBK     0
106 #define SUB_API_LIBUSB0     1
107 #define SUB_API_WINUSB      2
108 #define SUB_API_MAX         3
109
110 #define WINUSBX_DRV_NAMES   { "libusbK", "libusb0", "WinUSB"}
111
112 struct windows_usb_api_backend {
113         const uint8_t id;
114         const char* designation;
115         const char **driver_name_list; // Driver name, without .sys, e.g. "usbccgp"
116         const uint8_t nb_driver_names;
117         int (*init)(int sub_api, struct libusb_context *ctx);
118         int (*exit)(int sub_api);
119         int (*open)(int sub_api, struct libusb_device_handle *dev_handle);
120         void (*close)(int sub_api, struct libusb_device_handle *dev_handle);
121         int (*configure_endpoints)(int sub_api, struct libusb_device_handle *dev_handle, int iface);
122         int (*claim_interface)(int sub_api, struct libusb_device_handle *dev_handle, int iface);
123         int (*set_interface_altsetting)(int sub_api, struct libusb_device_handle *dev_handle, int iface, int altsetting);
124         int (*release_interface)(int sub_api, struct libusb_device_handle *dev_handle, int iface);
125         int (*clear_halt)(int sub_api, struct libusb_device_handle *dev_handle, unsigned char endpoint);
126         int (*reset_device)(int sub_api, struct libusb_device_handle *dev_handle);
127         int (*submit_bulk_transfer)(int sub_api, struct usbi_transfer *itransfer);
128         int (*submit_iso_transfer)(int sub_api, struct usbi_transfer *itransfer);
129         int (*submit_control_transfer)(int sub_api, struct usbi_transfer *itransfer);
130         int (*abort_control)(int sub_api, struct usbi_transfer *itransfer);
131         int (*abort_transfers)(int sub_api, struct usbi_transfer *itransfer);
132         int (*copy_transfer_data)(int sub_api, struct usbi_transfer *itransfer, uint32_t io_size);
133 };
134
135 extern const struct windows_usb_api_backend usb_api_backend[USB_API_MAX];
136
137 #define PRINT_UNSUPPORTED_API(fname)              \
138         usbi_dbg("unsupported API call for '"         \
139                 #fname "' (unrecognized device driver)"); \
140         return LIBUSB_ERROR_NOT_SUPPORTED;
141
142 /*
143  * private structures definition
144  * with inline pseudo constructors/destructors
145  */
146
147 // TODO (v2+): move hid desc to libusb.h?
148 struct libusb_hid_descriptor {
149         uint8_t  bLength;
150         uint8_t  bDescriptorType;
151         uint16_t bcdHID;
152         uint8_t  bCountryCode;
153         uint8_t  bNumDescriptors;
154         uint8_t  bClassDescriptorType;
155         uint16_t wClassDescriptorLength;
156 };
157 #define LIBUSB_DT_HID_SIZE              9
158 #define HID_MAX_CONFIG_DESC_SIZE (LIBUSB_DT_CONFIG_SIZE + LIBUSB_DT_INTERFACE_SIZE \
159         + LIBUSB_DT_HID_SIZE + 2 * LIBUSB_DT_ENDPOINT_SIZE)
160 #define HID_MAX_REPORT_SIZE             1024
161 #define HID_IN_EP                       0x81
162 #define HID_OUT_EP                      0x02
163 #define LIBUSB_REQ_RECIPIENT(request_type) ((request_type) & 0x1F)
164 #define LIBUSB_REQ_TYPE(request_type) ((request_type) & (0x03 << 5))
165 #define LIBUSB_REQ_IN(request_type) ((request_type) & LIBUSB_ENDPOINT_IN)
166 #define LIBUSB_REQ_OUT(request_type) (!LIBUSB_REQ_IN(request_type))
167
168 // The following are used for HID reports IOCTLs
169 #define HID_CTL_CODE(id) \
170   CTL_CODE (FILE_DEVICE_KEYBOARD, (id), METHOD_NEITHER, FILE_ANY_ACCESS)
171 #define HID_BUFFER_CTL_CODE(id) \
172   CTL_CODE (FILE_DEVICE_KEYBOARD, (id), METHOD_BUFFERED, FILE_ANY_ACCESS)
173 #define HID_IN_CTL_CODE(id) \
174   CTL_CODE (FILE_DEVICE_KEYBOARD, (id), METHOD_IN_DIRECT, FILE_ANY_ACCESS)
175 #define HID_OUT_CTL_CODE(id) \
176   CTL_CODE (FILE_DEVICE_KEYBOARD, (id), METHOD_OUT_DIRECT, FILE_ANY_ACCESS)
177
178 #define IOCTL_HID_GET_FEATURE                 HID_OUT_CTL_CODE(100)
179 #define IOCTL_HID_GET_INPUT_REPORT            HID_OUT_CTL_CODE(104)
180 #define IOCTL_HID_SET_FEATURE                 HID_IN_CTL_CODE(100)
181 #define IOCTL_HID_SET_OUTPUT_REPORT           HID_IN_CTL_CODE(101)
182
183 enum libusb_hid_request_type {
184         HID_REQ_GET_REPORT = 0x01,
185         HID_REQ_GET_IDLE = 0x02,
186         HID_REQ_GET_PROTOCOL = 0x03,
187         HID_REQ_SET_REPORT = 0x09,
188         HID_REQ_SET_IDLE = 0x0A,
189         HID_REQ_SET_PROTOCOL = 0x0B
190 };
191
192 enum libusb_hid_report_type {
193         HID_REPORT_TYPE_INPUT = 0x01,
194         HID_REPORT_TYPE_OUTPUT = 0x02,
195         HID_REPORT_TYPE_FEATURE = 0x03
196 };
197
198 struct hid_device_priv {
199         uint16_t vid;
200         uint16_t pid;
201         uint8_t config;
202         uint8_t nb_interfaces;
203         bool uses_report_ids[3];        // input, ouptput, feature
204         uint16_t input_report_size;
205         uint16_t output_report_size;
206         uint16_t feature_report_size;
207         WCHAR string[3][MAX_USB_STRING_LENGTH];
208         uint8_t string_index[3];        // man, prod, ser
209 };
210
211 typedef struct libusb_device_descriptor USB_DEVICE_DESCRIPTOR, *PUSB_DEVICE_DESCRIPTOR;
212 struct windows_device_priv {
213         uint8_t depth;                                          // distance to HCD
214         uint8_t port;                                           // port number on the hub
215         uint8_t active_config;
216         struct libusb_device *parent_dev;       // access to parent is required for usermode ops
217         struct windows_usb_api_backend const *apib;
218         char *path;                                                     // device interface path
219         int sub_api;                                            // for WinUSB-like APIs
220         struct {
221                 char *path;                                             // each interface needs a device interface path,
222                 struct windows_usb_api_backend const *apib; // an API backend (multiple drivers support),
223                 int sub_api;
224                 int8_t nb_endpoints;                    // and a set of endpoint addresses (USB_MAXENDPOINTS)
225                 uint8_t *endpoint;
226                 bool restricted_functionality;  // indicates if the interface functionality is restricted
227                                                                                 // by Windows (eg. HID keyboards or mice cannot do R/W)
228         } usb_interface[USB_MAXINTERFACES];
229         struct hid_device_priv *hid;
230         USB_DEVICE_DESCRIPTOR dev_descriptor;
231         unsigned char **config_descriptor;      // list of pointers to the cached config descriptors
232 };
233
234 static inline struct windows_device_priv *_device_priv(struct libusb_device *dev) {
235         return (struct windows_device_priv *)dev->os_priv;
236 }
237
238 static inline void windows_device_priv_init(libusb_device* dev) {
239         struct windows_device_priv* p = _device_priv(dev);
240         int i;
241         p->depth = 0;
242         p->port = 0;
243         p->parent_dev = NULL;
244         p->path = NULL;
245         p->apib = &usb_api_backend[USB_API_UNSUPPORTED];
246         p->sub_api = SUB_API_NOTSET;
247         p->hid = NULL;
248         p->active_config = 0;
249         p->config_descriptor = NULL;
250         memset(&(p->dev_descriptor), 0, sizeof(USB_DEVICE_DESCRIPTOR));
251         for (i=0; i<USB_MAXINTERFACES; i++) {
252                 p->usb_interface[i].path = NULL;
253                 p->usb_interface[i].apib = &usb_api_backend[USB_API_UNSUPPORTED];
254                 p->usb_interface[i].sub_api = SUB_API_NOTSET;
255                 p->usb_interface[i].nb_endpoints = 0;
256                 p->usb_interface[i].endpoint = NULL;
257                 p->usb_interface[i].restricted_functionality = false;
258         }
259 }
260
261 static inline void windows_device_priv_release(libusb_device* dev) {
262         struct windows_device_priv* p = _device_priv(dev);
263         int i;
264         safe_free(p->path);
265         if ((dev->num_configurations > 0) && (p->config_descriptor != NULL)) {
266                 for (i=0; i < dev->num_configurations; i++)
267                         safe_free(p->config_descriptor[i]);
268         }
269         safe_free(p->config_descriptor);
270         safe_free(p->hid);
271         for (i=0; i<USB_MAXINTERFACES; i++) {
272                 safe_free(p->usb_interface[i].path);
273                 safe_free(p->usb_interface[i].endpoint);
274         }
275 }
276
277 struct interface_handle_t {
278         HANDLE dev_handle; // WinUSB needs an extra handle for the file
279         HANDLE api_handle; // used by the API to communicate with the device
280 };
281
282 struct windows_device_handle_priv {
283         int active_interface;
284         struct interface_handle_t interface_handle[USB_MAXINTERFACES];
285         int autoclaim_count[USB_MAXINTERFACES]; // For auto-release
286 };
287
288 static inline struct windows_device_handle_priv *_device_handle_priv(
289         struct libusb_device_handle *handle)
290 {
291         return (struct windows_device_handle_priv *) handle->os_priv;
292 }
293
294 // used for async polling functions
295 struct windows_transfer_priv {
296         struct winfd pollable_fd;
297         uint8_t interface_number;
298         uint8_t *hid_buffer; // 1 byte extended data buffer, required for HID
299         uint8_t *hid_dest;   // transfer buffer destination, required for HID
300         size_t hid_expected_size;
301 };
302
303 // used to match a device driver (including filter drivers) against a supported API
304 struct driver_lookup {
305         char list[MAX_KEY_LENGTH+1];// REG_MULTI_SZ list of services (driver) names
306         const DWORD reg_prop;           // SPDRP registry key to use to retreive list
307         const char* designation;        // internal designation (for debug output)
308 };
309
310 /* OLE32 dependency */
311 DLL_DECLARE_PREFIXED(WINAPI, HRESULT, p, CLSIDFromString, (LPCOLESTR, LPCLSID));
312
313 /* This call is only available from XP SP2 */
314 DLL_DECLARE_PREFIXED(WINAPI, BOOL, p, IsWow64Process, (HANDLE, PBOOL));
315
316 /* SetupAPI dependencies */
317 DLL_DECLARE_PREFIXED(WINAPI, HDEVINFO, p, SetupDiGetClassDevsA, (const GUID*, PCSTR, HWND, DWORD));
318 DLL_DECLARE_PREFIXED(WINAPI, BOOL, p, SetupDiEnumDeviceInfo, (HDEVINFO, DWORD, PSP_DEVINFO_DATA));
319 DLL_DECLARE_PREFIXED(WINAPI, BOOL, p, SetupDiEnumDeviceInterfaces, (HDEVINFO, PSP_DEVINFO_DATA,
320                         const GUID*, DWORD, PSP_DEVICE_INTERFACE_DATA));
321 DLL_DECLARE_PREFIXED(WINAPI, BOOL, p, SetupDiGetDeviceInterfaceDetailA, (HDEVINFO, PSP_DEVICE_INTERFACE_DATA,
322                         PSP_DEVICE_INTERFACE_DETAIL_DATA_A, DWORD, PDWORD, PSP_DEVINFO_DATA));
323 DLL_DECLARE_PREFIXED(WINAPI, BOOL, p, SetupDiDestroyDeviceInfoList, (HDEVINFO));
324 DLL_DECLARE_PREFIXED(WINAPI, HKEY, p, SetupDiOpenDevRegKey, (HDEVINFO, PSP_DEVINFO_DATA, DWORD, DWORD, DWORD, REGSAM));
325 DLL_DECLARE_PREFIXED(WINAPI, BOOL, p, SetupDiGetDeviceRegistryPropertyA, (HDEVINFO,
326                         PSP_DEVINFO_DATA, DWORD, PDWORD, PBYTE, DWORD, PDWORD));
327 DLL_DECLARE_PREFIXED(WINAPI, HKEY, p, SetupDiOpenDeviceInterfaceRegKey, (HDEVINFO, PSP_DEVICE_INTERFACE_DATA, DWORD, DWORD));
328 DLL_DECLARE_PREFIXED(WINAPI, LONG, p, RegQueryValueExW, (HKEY, LPCWSTR, LPDWORD, LPDWORD, LPBYTE, LPDWORD));
329 DLL_DECLARE_PREFIXED(WINAPI, LONG, p, RegCloseKey, (HKEY));
330
331 /*
332  * Windows DDK API definitions. Most of it copied from MinGW's includes
333  */
334 typedef DWORD DEVNODE, DEVINST;
335 typedef DEVNODE *PDEVNODE, *PDEVINST;
336 typedef DWORD RETURN_TYPE;
337 typedef RETURN_TYPE CONFIGRET;
338
339 #define CR_SUCCESS                              0x00000000
340 #define CR_NO_SUCH_DEVNODE                      0x0000000D
341
342 #define USB_DEVICE_DESCRIPTOR_TYPE              LIBUSB_DT_DEVICE
343 #define USB_CONFIGURATION_DESCRIPTOR_TYPE       LIBUSB_DT_CONFIG
344 #define USB_STRING_DESCRIPTOR_TYPE              LIBUSB_DT_STRING
345 #define USB_INTERFACE_DESCRIPTOR_TYPE           LIBUSB_DT_INTERFACE
346 #define USB_ENDPOINT_DESCRIPTOR_TYPE            LIBUSB_DT_ENDPOINT
347
348 #define USB_REQUEST_GET_STATUS                  LIBUSB_REQUEST_GET_STATUS
349 #define USB_REQUEST_CLEAR_FEATURE               LIBUSB_REQUEST_CLEAR_FEATURE
350 #define USB_REQUEST_SET_FEATURE                 LIBUSB_REQUEST_SET_FEATURE
351 #define USB_REQUEST_SET_ADDRESS                 LIBUSB_REQUEST_SET_ADDRESS
352 #define USB_REQUEST_GET_DESCRIPTOR              LIBUSB_REQUEST_GET_DESCRIPTOR
353 #define USB_REQUEST_SET_DESCRIPTOR              LIBUSB_REQUEST_SET_DESCRIPTOR
354 #define USB_REQUEST_GET_CONFIGURATION           LIBUSB_REQUEST_GET_CONFIGURATION
355 #define USB_REQUEST_SET_CONFIGURATION           LIBUSB_REQUEST_SET_CONFIGURATION
356 #define USB_REQUEST_GET_INTERFACE               LIBUSB_REQUEST_GET_INTERFACE
357 #define USB_REQUEST_SET_INTERFACE               LIBUSB_REQUEST_SET_INTERFACE
358 #define USB_REQUEST_SYNC_FRAME                  LIBUSB_REQUEST_SYNCH_FRAME
359
360 #define USB_GET_NODE_INFORMATION                258
361 #define USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION 260
362 #define USB_GET_NODE_CONNECTION_NAME            261
363 #define USB_GET_HUB_CAPABILITIES                271
364 #if !defined(USB_GET_NODE_CONNECTION_INFORMATION_EX)
365 #define USB_GET_NODE_CONNECTION_INFORMATION_EX  274
366 #endif
367 #if !defined(USB_GET_HUB_CAPABILITIES_EX)
368 #define USB_GET_HUB_CAPABILITIES_EX             276
369 #endif
370 #if !defined(USB_GET_NODE_CONNECTION_INFORMATION_EX_V2)
371 #define USB_GET_NODE_CONNECTION_INFORMATION_EX_V2 279
372 #endif
373
374 #ifndef METHOD_BUFFERED
375 #define METHOD_BUFFERED                         0
376 #endif
377 #ifndef FILE_ANY_ACCESS
378 #define FILE_ANY_ACCESS                         0x00000000
379 #endif
380 #ifndef FILE_DEVICE_UNKNOWN
381 #define FILE_DEVICE_UNKNOWN                     0x00000022
382 #endif
383 #ifndef FILE_DEVICE_USB
384 #define FILE_DEVICE_USB                         FILE_DEVICE_UNKNOWN
385 #endif
386
387 #ifndef CTL_CODE
388 #define CTL_CODE(DeviceType, Function, Method, Access)( \
389   ((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method))
390 #endif
391
392 typedef enum USB_CONNECTION_STATUS {
393         NoDeviceConnected,
394         DeviceConnected,
395         DeviceFailedEnumeration,
396         DeviceGeneralFailure,
397         DeviceCausedOvercurrent,
398         DeviceNotEnoughPower,
399         DeviceNotEnoughBandwidth,
400         DeviceHubNestedTooDeeply,
401         DeviceInLegacyHub
402 } USB_CONNECTION_STATUS, *PUSB_CONNECTION_STATUS;
403
404 typedef enum USB_HUB_NODE {
405         UsbHub,
406         UsbMIParent
407 } USB_HUB_NODE;
408
409 /* Cfgmgr32.dll interface */
410 DLL_DECLARE(WINAPI, CONFIGRET, CM_Get_Parent, (PDEVINST, DEVINST, ULONG));
411 DLL_DECLARE(WINAPI, CONFIGRET, CM_Get_Child, (PDEVINST, DEVINST, ULONG));
412 DLL_DECLARE(WINAPI, CONFIGRET, CM_Get_Sibling, (PDEVINST, DEVINST, ULONG));
413 DLL_DECLARE(WINAPI, CONFIGRET, CM_Get_Device_IDA, (DEVINST, PCHAR, ULONG, ULONG));
414
415 #define IOCTL_USB_GET_HUB_CAPABILITIES_EX \
416   CTL_CODE( FILE_DEVICE_USB, USB_GET_HUB_CAPABILITIES_EX, METHOD_BUFFERED, FILE_ANY_ACCESS)
417
418 #define IOCTL_USB_GET_HUB_CAPABILITIES \
419   CTL_CODE(FILE_DEVICE_USB, USB_GET_HUB_CAPABILITIES, METHOD_BUFFERED, FILE_ANY_ACCESS)
420
421 #define IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION \
422   CTL_CODE(FILE_DEVICE_USB, USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION, METHOD_BUFFERED, FILE_ANY_ACCESS)
423
424 #define IOCTL_USB_GET_ROOT_HUB_NAME \
425   CTL_CODE(FILE_DEVICE_USB, HCD_GET_ROOT_HUB_NAME, METHOD_BUFFERED, FILE_ANY_ACCESS)
426
427 #define IOCTL_USB_GET_NODE_INFORMATION \
428   CTL_CODE(FILE_DEVICE_USB, USB_GET_NODE_INFORMATION, METHOD_BUFFERED, FILE_ANY_ACCESS)
429
430 #define IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX \
431   CTL_CODE(FILE_DEVICE_USB, USB_GET_NODE_CONNECTION_INFORMATION_EX, METHOD_BUFFERED, FILE_ANY_ACCESS)
432
433 #define IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX_V2 \
434   CTL_CODE(FILE_DEVICE_USB, USB_GET_NODE_CONNECTION_INFORMATION_EX_V2, METHOD_BUFFERED, FILE_ANY_ACCESS)
435
436 #define IOCTL_USB_GET_NODE_CONNECTION_ATTRIBUTES \
437   CTL_CODE(FILE_DEVICE_USB, USB_GET_NODE_CONNECTION_ATTRIBUTES, METHOD_BUFFERED, FILE_ANY_ACCESS)
438
439 #define IOCTL_USB_GET_NODE_CONNECTION_NAME \
440   CTL_CODE(FILE_DEVICE_USB, USB_GET_NODE_CONNECTION_NAME, METHOD_BUFFERED, FILE_ANY_ACCESS)
441
442 // Most of the structures below need to be packed
443 #pragma pack(push, 1)
444
445 typedef struct USB_INTERFACE_DESCRIPTOR {
446   UCHAR  bLength;
447   UCHAR  bDescriptorType;
448   UCHAR  bInterfaceNumber;
449   UCHAR  bAlternateSetting;
450   UCHAR  bNumEndpoints;
451   UCHAR  bInterfaceClass;
452   UCHAR  bInterfaceSubClass;
453   UCHAR  bInterfaceProtocol;
454   UCHAR  iInterface;
455 } USB_INTERFACE_DESCRIPTOR, *PUSB_INTERFACE_DESCRIPTOR;
456
457 typedef struct USB_CONFIGURATION_DESCRIPTOR {
458   UCHAR  bLength;
459   UCHAR  bDescriptorType;
460   USHORT wTotalLength;
461   UCHAR  bNumInterfaces;
462   UCHAR  bConfigurationValue;
463   UCHAR  iConfiguration;
464   UCHAR  bmAttributes;
465   UCHAR  MaxPower;
466 } USB_CONFIGURATION_DESCRIPTOR, *PUSB_CONFIGURATION_DESCRIPTOR;
467
468 typedef struct USB_CONFIGURATION_DESCRIPTOR_SHORT {
469         struct {
470                 ULONG ConnectionIndex;
471                 struct {
472                         UCHAR bmRequest;
473                         UCHAR bRequest;
474                         USHORT wValue;
475                         USHORT wIndex;
476                         USHORT wLength;
477                 } SetupPacket;
478         } req;
479         USB_CONFIGURATION_DESCRIPTOR data;
480 } USB_CONFIGURATION_DESCRIPTOR_SHORT;
481
482 typedef struct USB_ENDPOINT_DESCRIPTOR {
483   UCHAR  bLength;
484   UCHAR  bDescriptorType;
485   UCHAR  bEndpointAddress;
486   UCHAR  bmAttributes;
487   USHORT  wMaxPacketSize;
488   UCHAR  bInterval;
489 } USB_ENDPOINT_DESCRIPTOR, *PUSB_ENDPOINT_DESCRIPTOR;
490
491 typedef struct USB_DESCRIPTOR_REQUEST {
492         ULONG  ConnectionIndex;
493         struct {
494                 UCHAR  bmRequest;
495                 UCHAR  bRequest;
496                 USHORT  wValue;
497                 USHORT  wIndex;
498                 USHORT  wLength;
499         } SetupPacket;
500 //      UCHAR  Data[0];
501 } USB_DESCRIPTOR_REQUEST, *PUSB_DESCRIPTOR_REQUEST;
502
503 typedef struct USB_HUB_DESCRIPTOR {
504         UCHAR  bDescriptorLength;
505         UCHAR  bDescriptorType;
506         UCHAR  bNumberOfPorts;
507         USHORT  wHubCharacteristics;
508         UCHAR  bPowerOnToPowerGood;
509         UCHAR  bHubControlCurrent;
510         UCHAR  bRemoveAndPowerMask[64];
511 } USB_HUB_DESCRIPTOR, *PUSB_HUB_DESCRIPTOR;
512
513 typedef struct USB_ROOT_HUB_NAME {
514         ULONG  ActualLength;
515         WCHAR  RootHubName[1];
516 } USB_ROOT_HUB_NAME, *PUSB_ROOT_HUB_NAME;
517
518 typedef struct USB_ROOT_HUB_NAME_FIXED {
519         ULONG ActualLength;
520         WCHAR RootHubName[MAX_PATH_LENGTH];
521 } USB_ROOT_HUB_NAME_FIXED;
522
523 typedef struct USB_NODE_CONNECTION_NAME {
524         ULONG  ConnectionIndex;
525         ULONG  ActualLength;
526         WCHAR  NodeName[1];
527 } USB_NODE_CONNECTION_NAME, *PUSB_NODE_CONNECTION_NAME;
528
529 typedef struct USB_NODE_CONNECTION_NAME_FIXED {
530         ULONG ConnectionIndex;
531         ULONG ActualLength;
532         WCHAR NodeName[MAX_PATH_LENGTH];
533 } USB_NODE_CONNECTION_NAME_FIXED;
534
535 typedef struct USB_HUB_NAME_FIXED {
536         union {
537                 USB_ROOT_HUB_NAME_FIXED root;
538                 USB_NODE_CONNECTION_NAME_FIXED node;
539         } u;
540 } USB_HUB_NAME_FIXED;
541
542 typedef struct USB_HUB_INFORMATION {
543         USB_HUB_DESCRIPTOR  HubDescriptor;
544         BOOLEAN  HubIsBusPowered;
545 } USB_HUB_INFORMATION, *PUSB_HUB_INFORMATION;
546
547 typedef struct USB_MI_PARENT_INFORMATION {
548   ULONG  NumberOfInterfaces;
549 } USB_MI_PARENT_INFORMATION, *PUSB_MI_PARENT_INFORMATION;
550
551 typedef struct USB_NODE_INFORMATION {
552         USB_HUB_NODE  NodeType;
553         union {
554                 USB_HUB_INFORMATION  HubInformation;
555                 USB_MI_PARENT_INFORMATION  MiParentInformation;
556         } u;
557 } USB_NODE_INFORMATION, *PUSB_NODE_INFORMATION;
558
559 typedef struct USB_PIPE_INFO {
560         USB_ENDPOINT_DESCRIPTOR  EndpointDescriptor;
561         ULONG  ScheduleOffset;
562 } USB_PIPE_INFO, *PUSB_PIPE_INFO;
563
564 typedef struct USB_NODE_CONNECTION_INFORMATION_EX {
565         ULONG  ConnectionIndex;
566         USB_DEVICE_DESCRIPTOR  DeviceDescriptor;
567         UCHAR  CurrentConfigurationValue;
568         UCHAR  Speed;
569         BOOLEAN  DeviceIsHub;
570         USHORT  DeviceAddress;
571         ULONG  NumberOfOpenPipes;
572         USB_CONNECTION_STATUS  ConnectionStatus;
573 //      USB_PIPE_INFO  PipeList[0];
574 } USB_NODE_CONNECTION_INFORMATION_EX, *PUSB_NODE_CONNECTION_INFORMATION_EX;
575
576 typedef union _USB_PROTOCOLS {
577         ULONG  ul;
578         struct {
579                 ULONG Usb110:1;
580                 ULONG Usb200:1;
581                 ULONG Usb300:1;
582                 ULONG ReservedMBZ:29;
583         };
584 } USB_PROTOCOLS, *PUSB_PROTOCOLS;
585
586 typedef union _USB_NODE_CONNECTION_INFORMATION_EX_V2_FLAGS {
587         ULONG ul;
588         struct {
589                 ULONG DeviceIsOperatingAtSuperSpeedOrHigher:1;
590                 ULONG DeviceIsSuperSpeedCapableOrHigher:1;
591                 ULONG ReservedMBZ:30;
592         };
593 } USB_NODE_CONNECTION_INFORMATION_EX_V2_FLAGS, *PUSB_NODE_CONNECTION_INFORMATION_EX_V2_FLAGS;
594
595 typedef struct _USB_NODE_CONNECTION_INFORMATION_EX_V2 {
596         ULONG ConnectionIndex;
597         ULONG Length;
598         USB_PROTOCOLS SupportedUsbProtocols;
599         USB_NODE_CONNECTION_INFORMATION_EX_V2_FLAGS Flags;
600 } USB_NODE_CONNECTION_INFORMATION_EX_V2, *PUSB_NODE_CONNECTION_INFORMATION_EX_V2;
601
602 typedef struct USB_HUB_CAP_FLAGS {
603         ULONG HubIsHighSpeedCapable:1;
604         ULONG HubIsHighSpeed:1;
605         ULONG HubIsMultiTtCapable:1;
606         ULONG HubIsMultiTt:1;
607         ULONG HubIsRoot:1;
608         ULONG HubIsArmedWakeOnConnect:1;
609         ULONG ReservedMBZ:26;
610 } USB_HUB_CAP_FLAGS, *PUSB_HUB_CAP_FLAGS;
611
612 typedef struct USB_HUB_CAPABILITIES {
613   ULONG  HubIs2xCapable : 1;
614 } USB_HUB_CAPABILITIES, *PUSB_HUB_CAPABILITIES;
615
616 typedef struct USB_HUB_CAPABILITIES_EX {
617         USB_HUB_CAP_FLAGS CapabilityFlags;
618 } USB_HUB_CAPABILITIES_EX, *PUSB_HUB_CAPABILITIES_EX;
619
620 #pragma pack(pop)
621
622 /* winusb.dll interface */
623
624 #define SHORT_PACKET_TERMINATE  0x01
625 #define AUTO_CLEAR_STALL        0x02
626 #define PIPE_TRANSFER_TIMEOUT   0x03
627 #define IGNORE_SHORT_PACKETS    0x04
628 #define ALLOW_PARTIAL_READS     0x05
629 #define AUTO_FLUSH              0x06
630 #define RAW_IO                  0x07
631 #define MAXIMUM_TRANSFER_SIZE   0x08
632 #define AUTO_SUSPEND            0x81
633 #define SUSPEND_DELAY           0x83
634 #define DEVICE_SPEED            0x01
635 #define LowSpeed                0x01
636 #define FullSpeed               0x02
637 #define HighSpeed               0x03
638
639 typedef enum USBD_PIPE_TYPE {
640         UsbdPipeTypeControl,
641         UsbdPipeTypeIsochronous,
642         UsbdPipeTypeBulk,
643         UsbdPipeTypeInterrupt
644 } USBD_PIPE_TYPE;
645
646 typedef struct {
647   USBD_PIPE_TYPE PipeType;
648   UCHAR          PipeId;
649   USHORT         MaximumPacketSize;
650   UCHAR          Interval;
651 } WINUSB_PIPE_INFORMATION, *PWINUSB_PIPE_INFORMATION;
652
653 #pragma pack(1)
654 typedef struct {
655   UCHAR  request_type;
656   UCHAR  request;
657   USHORT value;
658   USHORT index;
659   USHORT length;
660 } WINUSB_SETUP_PACKET, *PWINUSB_SETUP_PACKET;
661 #pragma pack()
662
663 typedef void *WINUSB_INTERFACE_HANDLE, *PWINUSB_INTERFACE_HANDLE;
664
665 typedef BOOL (WINAPI *WinUsb_AbortPipe_t)(
666         WINUSB_INTERFACE_HANDLE InterfaceHandle,
667         UCHAR PipeID
668 );
669 typedef BOOL (WINAPI *WinUsb_ControlTransfer_t)(
670         WINUSB_INTERFACE_HANDLE InterfaceHandle,
671         WINUSB_SETUP_PACKET SetupPacket,
672         PUCHAR Buffer,
673         ULONG BufferLength,
674         PULONG LengthTransferred,
675         LPOVERLAPPED Overlapped
676 );
677 typedef BOOL (WINAPI *WinUsb_FlushPipe_t)(
678         WINUSB_INTERFACE_HANDLE InterfaceHandle,
679         UCHAR PipeID
680 );
681 typedef BOOL (WINAPI *WinUsb_Free_t)(
682         WINUSB_INTERFACE_HANDLE InterfaceHandle
683 );
684 typedef BOOL (WINAPI *WinUsb_GetAssociatedInterface_t)(
685         WINUSB_INTERFACE_HANDLE InterfaceHandle,
686         UCHAR AssociatedInterfaceIndex,
687         PWINUSB_INTERFACE_HANDLE AssociatedInterfaceHandle
688 );
689 typedef BOOL (WINAPI *WinUsb_GetCurrentAlternateSetting_t)(
690         WINUSB_INTERFACE_HANDLE InterfaceHandle,
691         PUCHAR AlternateSetting
692 );
693 typedef BOOL (WINAPI *WinUsb_GetDescriptor_t)(
694         WINUSB_INTERFACE_HANDLE InterfaceHandle,
695         UCHAR DescriptorType,
696         UCHAR Index,
697         USHORT LanguageID,
698         PUCHAR Buffer,
699         ULONG BufferLength,
700         PULONG LengthTransferred
701 );
702 typedef BOOL (WINAPI *WinUsb_GetOverlappedResult_t)(
703         WINUSB_INTERFACE_HANDLE InterfaceHandle,
704         LPOVERLAPPED lpOverlapped,
705         LPDWORD lpNumberOfBytesTransferred,
706         BOOL bWait
707 );
708 typedef BOOL (WINAPI *WinUsb_GetPipePolicy_t)(
709         WINUSB_INTERFACE_HANDLE InterfaceHandle,
710         UCHAR PipeID,
711         ULONG PolicyType,
712         PULONG ValueLength,
713         PVOID Value
714 );
715 typedef BOOL (WINAPI *WinUsb_GetPowerPolicy_t)(
716         WINUSB_INTERFACE_HANDLE InterfaceHandle,
717         ULONG PolicyType,
718         PULONG ValueLength,
719         PVOID Value
720 );
721 typedef BOOL (WINAPI *WinUsb_Initialize_t)(
722         HANDLE DeviceHandle,
723         PWINUSB_INTERFACE_HANDLE InterfaceHandle
724 );
725 typedef BOOL (WINAPI *WinUsb_QueryDeviceInformation_t)(
726         WINUSB_INTERFACE_HANDLE InterfaceHandle,
727         ULONG InformationType,
728         PULONG BufferLength,
729         PVOID Buffer
730 );
731 typedef BOOL (WINAPI *WinUsb_QueryInterfaceSettings_t)(
732         WINUSB_INTERFACE_HANDLE InterfaceHandle,
733         UCHAR AlternateSettingNumber,
734         PUSB_INTERFACE_DESCRIPTOR UsbAltInterfaceDescriptor
735 );
736 typedef BOOL (WINAPI *WinUsb_QueryPipe_t)(
737         WINUSB_INTERFACE_HANDLE InterfaceHandle,
738         UCHAR AlternateInterfaceNumber,
739         UCHAR PipeIndex,
740         PWINUSB_PIPE_INFORMATION PipeInformation
741 );
742 typedef BOOL (WINAPI *WinUsb_ReadPipe_t)(
743         WINUSB_INTERFACE_HANDLE InterfaceHandle,
744         UCHAR PipeID,
745         PUCHAR Buffer,
746         ULONG BufferLength,
747         PULONG LengthTransferred,
748         LPOVERLAPPED Overlapped
749 );
750 typedef BOOL (WINAPI *WinUsb_ResetPipe_t)(
751         WINUSB_INTERFACE_HANDLE InterfaceHandle,
752         UCHAR PipeID
753 );
754 typedef BOOL (WINAPI *WinUsb_SetCurrentAlternateSetting_t)(
755         WINUSB_INTERFACE_HANDLE InterfaceHandle,
756         UCHAR AlternateSetting
757 );
758 typedef BOOL (WINAPI *WinUsb_SetPipePolicy_t)(
759         WINUSB_INTERFACE_HANDLE InterfaceHandle,
760         UCHAR PipeID,
761         ULONG PolicyType,
762         ULONG ValueLength,
763         PVOID Value
764 );
765 typedef BOOL (WINAPI *WinUsb_SetPowerPolicy_t)(
766         WINUSB_INTERFACE_HANDLE InterfaceHandle,
767         ULONG PolicyType,
768         ULONG ValueLength,
769         PVOID Value
770 );
771 typedef BOOL (WINAPI *WinUsb_WritePipe_t)(
772         WINUSB_INTERFACE_HANDLE InterfaceHandle,
773         UCHAR PipeID,
774         PUCHAR Buffer,
775         ULONG BufferLength,
776         PULONG LengthTransferred,
777         LPOVERLAPPED Overlapped
778 );
779 typedef BOOL (WINAPI *WinUsb_ResetDevice_t)(
780         WINUSB_INTERFACE_HANDLE InterfaceHandle
781 );
782
783 /* /!\ These must match the ones from the official libusbk.h */
784 typedef enum _KUSB_FNID
785 {
786         KUSB_FNID_Init,
787         KUSB_FNID_Free,
788         KUSB_FNID_ClaimInterface,
789         KUSB_FNID_ReleaseInterface,
790         KUSB_FNID_SetAltInterface,
791         KUSB_FNID_GetAltInterface,
792         KUSB_FNID_GetDescriptor,
793         KUSB_FNID_ControlTransfer,
794         KUSB_FNID_SetPowerPolicy,
795         KUSB_FNID_GetPowerPolicy,
796         KUSB_FNID_SetConfiguration,
797         KUSB_FNID_GetConfiguration,
798         KUSB_FNID_ResetDevice,
799         KUSB_FNID_Initialize,
800         KUSB_FNID_SelectInterface,
801         KUSB_FNID_GetAssociatedInterface,
802         KUSB_FNID_Clone,
803         KUSB_FNID_QueryInterfaceSettings,
804         KUSB_FNID_QueryDeviceInformation,
805         KUSB_FNID_SetCurrentAlternateSetting,
806         KUSB_FNID_GetCurrentAlternateSetting,
807         KUSB_FNID_QueryPipe,
808         KUSB_FNID_SetPipePolicy,
809         KUSB_FNID_GetPipePolicy,
810         KUSB_FNID_ReadPipe,
811         KUSB_FNID_WritePipe,
812         KUSB_FNID_ResetPipe,
813         KUSB_FNID_AbortPipe,
814         KUSB_FNID_FlushPipe,
815         KUSB_FNID_IsoReadPipe,
816         KUSB_FNID_IsoWritePipe,
817         KUSB_FNID_GetCurrentFrameNumber,
818         KUSB_FNID_GetOverlappedResult,
819         KUSB_FNID_GetProperty,
820         KUSB_FNID_COUNT,
821 } KUSB_FNID; 
822
823 typedef struct _KLIB_VERSION {
824         INT Major;
825         INT Minor;
826         INT Micro;
827         INT Nano;
828 } KLIB_VERSION;
829 typedef KLIB_VERSION* PKLIB_VERSION;
830
831 typedef BOOL (WINAPI *LibK_GetProcAddress_t)(
832         PVOID* ProcAddress,
833         ULONG DriverID,
834         ULONG FunctionID
835 );
836
837 typedef VOID (WINAPI *LibK_GetVersion_t)(
838         PKLIB_VERSION Version
839 );
840
841 struct winusb_interface {
842         bool initialized;
843         WinUsb_AbortPipe_t AbortPipe;
844         WinUsb_ControlTransfer_t ControlTransfer;
845         WinUsb_FlushPipe_t FlushPipe;
846         WinUsb_Free_t Free;
847         WinUsb_GetAssociatedInterface_t GetAssociatedInterface;
848         WinUsb_GetCurrentAlternateSetting_t GetCurrentAlternateSetting;
849         WinUsb_GetDescriptor_t GetDescriptor;
850         WinUsb_GetOverlappedResult_t GetOverlappedResult;
851         WinUsb_GetPipePolicy_t GetPipePolicy;
852         WinUsb_GetPowerPolicy_t GetPowerPolicy;
853         WinUsb_Initialize_t Initialize;
854         WinUsb_QueryDeviceInformation_t QueryDeviceInformation;
855         WinUsb_QueryInterfaceSettings_t QueryInterfaceSettings;
856         WinUsb_QueryPipe_t QueryPipe;
857         WinUsb_ReadPipe_t ReadPipe;
858         WinUsb_ResetPipe_t ResetPipe;
859         WinUsb_SetCurrentAlternateSetting_t SetCurrentAlternateSetting;
860         WinUsb_SetPipePolicy_t SetPipePolicy;
861         WinUsb_SetPowerPolicy_t SetPowerPolicy;
862         WinUsb_WritePipe_t WritePipe;
863         WinUsb_ResetDevice_t ResetDevice;
864 };
865
866 /* hid.dll interface */
867
868 #define HIDP_STATUS_SUCCESS  0x110000
869 typedef void* PHIDP_PREPARSED_DATA;
870
871 #pragma pack(1)
872 typedef struct {
873         ULONG Size;
874         USHORT VendorID;
875         USHORT ProductID;
876         USHORT VersionNumber;
877 } HIDD_ATTRIBUTES, *PHIDD_ATTRIBUTES;
878 #pragma pack()
879
880 typedef USHORT USAGE;
881 typedef struct {
882   USAGE Usage;
883   USAGE UsagePage;
884   USHORT InputReportByteLength;
885   USHORT OutputReportByteLength;
886   USHORT FeatureReportByteLength;
887   USHORT Reserved[17];
888   USHORT NumberLinkCollectionNodes;
889   USHORT NumberInputButtonCaps;
890   USHORT NumberInputValueCaps;
891   USHORT NumberInputDataIndices;
892   USHORT NumberOutputButtonCaps;
893   USHORT NumberOutputValueCaps;
894   USHORT NumberOutputDataIndices;
895   USHORT NumberFeatureButtonCaps;
896   USHORT NumberFeatureValueCaps;
897   USHORT NumberFeatureDataIndices;
898 } HIDP_CAPS, *PHIDP_CAPS;
899
900 typedef enum _HIDP_REPORT_TYPE {
901   HidP_Input,
902   HidP_Output,
903   HidP_Feature
904 } HIDP_REPORT_TYPE;
905
906 typedef struct _HIDP_VALUE_CAPS {
907   USAGE  UsagePage;
908   UCHAR  ReportID;
909   BOOLEAN  IsAlias;
910   USHORT  BitField;
911   USHORT  LinkCollection;
912   USAGE  LinkUsage;
913   USAGE  LinkUsagePage;
914   BOOLEAN  IsRange;
915   BOOLEAN  IsStringRange;
916   BOOLEAN  IsDesignatorRange;
917   BOOLEAN  IsAbsolute;
918   BOOLEAN  HasNull;
919   UCHAR  Reserved;
920   USHORT  BitSize;
921   USHORT  ReportCount;
922   USHORT  Reserved2[5];
923   ULONG  UnitsExp;
924   ULONG  Units;
925   LONG  LogicalMin, LogicalMax;
926   LONG  PhysicalMin, PhysicalMax;
927         union {
928           struct {
929                 USAGE  UsageMin, UsageMax;
930                 USHORT  StringMin, StringMax;
931                 USHORT  DesignatorMin, DesignatorMax;
932                 USHORT  DataIndexMin, DataIndexMax;
933           } Range;
934           struct {
935                 USAGE  Usage, Reserved1;
936                 USHORT  StringIndex, Reserved2;
937                 USHORT  DesignatorIndex, Reserved3;
938                 USHORT  DataIndex, Reserved4;
939           } NotRange;
940         } u;
941 } HIDP_VALUE_CAPS, *PHIDP_VALUE_CAPS;
942
943 DLL_DECLARE(WINAPI, BOOL, HidD_GetAttributes, (HANDLE, PHIDD_ATTRIBUTES));
944 DLL_DECLARE(WINAPI, VOID, HidD_GetHidGuid, (LPGUID));
945 DLL_DECLARE(WINAPI, BOOL, HidD_GetPreparsedData, (HANDLE, PHIDP_PREPARSED_DATA *));
946 DLL_DECLARE(WINAPI, BOOL, HidD_FreePreparsedData, (PHIDP_PREPARSED_DATA));
947 DLL_DECLARE(WINAPI, BOOL, HidD_GetManufacturerString, (HANDLE, PVOID, ULONG));
948 DLL_DECLARE(WINAPI, BOOL, HidD_GetProductString, (HANDLE, PVOID, ULONG));
949 DLL_DECLARE(WINAPI, BOOL, HidD_GetSerialNumberString, (HANDLE, PVOID, ULONG));
950 DLL_DECLARE(WINAPI, LONG, HidP_GetCaps, (PHIDP_PREPARSED_DATA, PHIDP_CAPS));
951 DLL_DECLARE(WINAPI, BOOL, HidD_SetNumInputBuffers, (HANDLE, ULONG));
952 DLL_DECLARE(WINAPI, BOOL, HidD_SetFeature, (HANDLE, PVOID, ULONG));
953 DLL_DECLARE(WINAPI, BOOL, HidD_GetFeature, (HANDLE, PVOID, ULONG));
954 DLL_DECLARE(WINAPI, BOOL, HidD_GetPhysicalDescriptor, (HANDLE, PVOID, ULONG));
955 DLL_DECLARE(WINAPI, BOOL, HidD_GetInputReport, (HANDLE, PVOID, ULONG));
956 DLL_DECLARE(WINAPI, BOOL, HidD_SetOutputReport, (HANDLE, PVOID, ULONG));
957 DLL_DECLARE(WINAPI, BOOL, HidD_FlushQueue, (HANDLE));
958 DLL_DECLARE(WINAPI, BOOL, HidP_GetValueCaps, (HIDP_REPORT_TYPE, PHIDP_VALUE_CAPS, PULONG, PHIDP_PREPARSED_DATA));