diff options
| author | 2013-09-26 10:41:13 +0200 | |
|---|---|---|
| committer | 2013-09-26 10:41:13 +0200 | |
| commit | 07391edbf2ca1feaf4357259fd9e477ec53e6d81 (patch) | |
| tree | 09bc0ab7de21b994dcb039a3e652ccfe173c310d /include/libusb-1.0/os/windows_usb.h | |
| parent | afb8735176869db20219c35a341e89158651bffe (diff) | |
| download | libirecovery-07391edbf2ca1feaf4357259fd9e477ec53e6d81.tar.gz libirecovery-07391edbf2ca1feaf4357259fd9e477ec53e6d81.tar.bz2 | |
Remove obsolete "in-tree" copy of libusb-1.0
Diffstat (limited to 'include/libusb-1.0/os/windows_usb.h')
| -rw-r--r-- | include/libusb-1.0/os/windows_usb.h | 784 |
1 files changed, 0 insertions, 784 deletions
diff --git a/include/libusb-1.0/os/windows_usb.h b/include/libusb-1.0/os/windows_usb.h deleted file mode 100644 index dc90a64..0000000 --- a/include/libusb-1.0/os/windows_usb.h +++ /dev/null | |||
| @@ -1,784 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Windows backend for libusb 1.0 | ||
| 3 | * Copyright (C) 2009-2010 Pete Batard <pbatard@gmail.com> | ||
| 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 | #if defined(_MSC_VER) | ||
| 26 | // disable /W4 MSVC warnings that are benign | ||
| 27 | #pragma warning(disable:4127) // conditional expression is constant | ||
| 28 | #pragma warning(disable:4100) // unreferenced formal parameter | ||
| 29 | #pragma warning(disable:4214) // bit field types other than int | ||
| 30 | #pragma warning(disable:4201) // nameless struct/union | ||
| 31 | #endif | ||
| 32 | |||
| 33 | // Windows API default is uppercase - ugh! | ||
| 34 | #if !defined(bool) | ||
| 35 | #define bool BOOL | ||
| 36 | #endif | ||
| 37 | #if !defined(true) | ||
| 38 | #define true TRUE | ||
| 39 | #endif | ||
| 40 | #if !defined(false) | ||
| 41 | #define false FALSE | ||
| 42 | #endif | ||
| 43 | |||
| 44 | #if !defined(libusb_bus_t) | ||
| 45 | #define libusb_bus_t uint8_t | ||
| 46 | #define LIBUSB_BUS_MAX UINT8_MAX | ||
| 47 | #endif | ||
| 48 | #if !defined(libusb_devaddr_t) | ||
| 49 | #define libusb_devaddr_t uint8_t | ||
| 50 | #define LIBUSB_DEVADDR_MAX UINT8_MAX | ||
| 51 | #endif | ||
| 52 | |||
| 53 | // Missing from MSVC6 setupapi.h | ||
| 54 | #if !defined(SPDRP_ADDRESS) | ||
| 55 | #define SPDRP_ADDRESS 28 | ||
| 56 | #endif | ||
| 57 | #if !defined(SPDRP_INSTALL_STATE) | ||
| 58 | #define SPDRP_INSTALL_STATE 34 | ||
| 59 | #endif | ||
| 60 | |||
| 61 | #if defined(__CYGWIN__ ) | ||
| 62 | // cygwin produces a warning unless these prototypes are defined | ||
| 63 | extern int _snprintf(char *buffer, size_t count, const char *format, ...); | ||
| 64 | extern char *_strdup(const char *strSource); | ||
| 65 | // _beginthreadex is MSVCRT => unavailable for cygwin. Fallback to using CreateThread | ||
| 66 | #define _beginthreadex(a, b, c, d, e, f) CreateThread(a, b, (LPTHREAD_START_ROUTINE)c, d, e, f) | ||
| 67 | #endif | ||
| 68 | #define safe_free(p) do {if (p != NULL) {free((void*)p); p = NULL;}} while(0) | ||
| 69 | #define safe_closehandle(h) do {if (h != INVALID_HANDLE_VALUE) {CloseHandle(h); h = INVALID_HANDLE_VALUE;}} while(0) | ||
| 70 | #define safe_min(a, b) min((size_t)(a), (size_t)(b)) | ||
| 71 | #define safe_strcp(dst, dst_max, src, count) do {memcpy(dst, src, safe_min(count, dst_max)); \ | ||
| 72 | ((char*)dst)[safe_min(count, dst_max)-1] = 0;} while(0) | ||
| 73 | #define safe_strcpy(dst, dst_max, src) safe_strcp(dst, dst_max, src, safe_strlen(src)+1) | ||
| 74 | #define safe_strncat(dst, dst_max, src, count) strncat(dst, src, safe_min(count, dst_max - safe_strlen(dst) - 1)) | ||
| 75 | #define safe_strcat(dst, dst_max, src) safe_strncat(dst, dst_max, src, safe_strlen(src)+1) | ||
| 76 | #define safe_strcmp(str1, str2) strcmp(((str1==NULL)?"<NULL>":str1), ((str2==NULL)?"<NULL>":str2)) | ||
| 77 | #define safe_strncmp(str1, str2, count) strncmp(((str1==NULL)?"<NULL>":str1), ((str2==NULL)?"<NULL>":str2), count) | ||
| 78 | #define safe_strlen(str) ((str==NULL)?0:strlen(str)) | ||
| 79 | #define safe_sprintf _snprintf | ||
| 80 | #define safe_unref_device(dev) do {if (dev != NULL) {libusb_unref_device(dev); dev = NULL;}} while(0) | ||
| 81 | #define wchar_to_utf8_ms(wstr, str, strlen) WideCharToMultiByte(CP_UTF8, 0, wstr, -1, str, strlen, NULL, NULL) | ||
| 82 | inline void upperize(char* str) { | ||
| 83 | size_t i; | ||
| 84 | if (str == NULL) return; | ||
| 85 | for (i=0; i<safe_strlen(str); i++) | ||
| 86 | str[i] = (char)toupper((int)str[i]); | ||
| 87 | } | ||
| 88 | |||
| 89 | #define MAX_CTRL_BUFFER_LENGTH 4096 | ||
| 90 | #define MAX_USB_DEVICES 256 | ||
| 91 | #define MAX_USB_STRING_LENGTH 128 | ||
| 92 | #define MAX_HID_REPORT_SIZE 1024 | ||
| 93 | #define MAX_HID_DESCRIPTOR_SIZE 256 | ||
| 94 | #define MAX_GUID_STRING_LENGTH 40 | ||
| 95 | #define MAX_PATH_LENGTH 128 | ||
| 96 | #define MAX_KEY_LENGTH 256 | ||
| 97 | #define MAX_TIMER_SEMAPHORES 128 | ||
| 98 | #define TIMER_REQUEST_RETRY_MS 100 | ||
| 99 | #define ERR_BUFFER_SIZE 256 | ||
| 100 | #define LIST_SEPARATOR ';' | ||
| 101 | |||
| 102 | // Handle code for HID interface that have been claimed ("dibs") | ||
| 103 | #define INTERFACE_CLAIMED ((HANDLE)(intptr_t)0xD1B5) | ||
| 104 | // Additional return code for HID operations that completed synchronously | ||
| 105 | #define LIBUSB_COMPLETED (LIBUSB_SUCCESS + 1) | ||
| 106 | |||
| 107 | // http://msdn.microsoft.com/en-us/library/bb663109.aspx | ||
| 108 | // http://msdn.microsoft.com/en-us/library/bb663093.aspx | ||
| 109 | #if !defined(GUID_DEVINTERFACE_USB_HOST_CONTROLLER) | ||
| 110 | const GUID GUID_DEVINTERFACE_USB_HOST_CONTROLLER = { 0x3ABF6F2D, 0x71C4, 0x462A, {0x8A, 0x92, 0x1E, 0x68, 0x61, 0xE6, 0xAF, 0x27} }; | ||
| 111 | #endif | ||
| 112 | #if !defined(GUID_DEVINTERFACE_USB_DEVICE) | ||
| 113 | const GUID GUID_DEVINTERFACE_USB_DEVICE = { 0xA5DCBF10, 0x6530, 0x11D2, {0x90, 0x1F, 0x00, 0xC0, 0x4F, 0xB9, 0x51, 0xED} }; | ||
| 114 | #endif | ||
| 115 | |||
| 116 | |||
| 117 | /* | ||
| 118 | * Multiple USB API backend support | ||
| 119 | */ | ||
| 120 | #define USB_API_UNSUPPORTED 0 | ||
| 121 | #define USB_API_COMPOSITE 1 | ||
| 122 | #define USB_API_WINUSB 2 | ||
| 123 | #define USB_API_HID 3 | ||
| 124 | #define USB_API_MAX 4 | ||
| 125 | |||
| 126 | const GUID CLASS_GUID_UNSUPPORTED = { 0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x57, 0xDA} }; | ||
| 127 | const GUID CLASS_GUID_HID = { 0x745A17A0, 0x74D3, 0x11D0, {0xB6, 0xFE, 0x00, 0xA0, 0xC9, 0x0F, 0x57, 0xDA} }; | ||
| 128 | const GUID CLASS_GUID_LIBUSB_WINUSB = { 0x78A1C341, 0x4539, 0x11D3, {0xB8, 0x8D, 0x00, 0xC0, 0x4F, 0xAD, 0x51, 0x71} }; | ||
| 129 | const GUID CLASS_GUID_COMPOSITE = { 0x36FC9E60, 0xC465, 0x11cF, {0x80, 0x56, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00} }; | ||
| 130 | |||
| 131 | struct windows_usb_api_backend { | ||
| 132 | const uint8_t id; | ||
| 133 | const char* designation; | ||
| 134 | const GUID *class_guid; // The Class GUID (for fallback in case the driver name cannot be read) | ||
| 135 | const char **driver_name_list; // Driver name, without .sys, e.g. "usbccgp" | ||
| 136 | const uint8_t nb_driver_names; | ||
| 137 | int (*init)(struct libusb_context *ctx); | ||
| 138 | int (*exit)(void); | ||
| 139 | int (*open)(struct libusb_device_handle *dev_handle); | ||
| 140 | void (*close)(struct libusb_device_handle *dev_handle); | ||
| 141 | int (*claim_interface)(struct libusb_device_handle *dev_handle, int iface); | ||
| 142 | int (*set_interface_altsetting)(struct libusb_device_handle *dev_handle, int iface, int altsetting); | ||
| 143 | int (*release_interface)(struct libusb_device_handle *dev_handle, int iface); | ||
| 144 | int (*clear_halt)(struct libusb_device_handle *dev_handle, unsigned char endpoint); | ||
| 145 | int (*reset_device)(struct libusb_device_handle *dev_handle); | ||
| 146 | int (*submit_bulk_transfer)(struct usbi_transfer *itransfer); | ||
| 147 | int (*submit_iso_transfer)(struct usbi_transfer *itransfer); | ||
| 148 | int (*submit_control_transfer)(struct usbi_transfer *itransfer); | ||
| 149 | int (*abort_control)(struct usbi_transfer *itransfer); | ||
| 150 | int (*abort_transfers)(struct usbi_transfer *itransfer); | ||
| 151 | int (*copy_transfer_data)(struct usbi_transfer *itransfer, uint32_t io_size); | ||
| 152 | }; | ||
| 153 | |||
| 154 | extern const struct windows_usb_api_backend usb_api_backend[USB_API_MAX]; | ||
| 155 | |||
| 156 | #define PRINT_UNSUPPORTED_API(fname) \ | ||
| 157 | usbi_dbg("unsupported API call for '" \ | ||
| 158 | #fname "' (unrecognized device driver)"); \ | ||
| 159 | return LIBUSB_ERROR_NOT_SUPPORTED; | ||
| 160 | |||
| 161 | /* | ||
| 162 | * private structures definition | ||
| 163 | * with inline pseudo constructors/destructors | ||
| 164 | */ | ||
| 165 | |||
| 166 | // HCDs | ||
| 167 | struct windows_hcd_priv { | ||
| 168 | char *path; | ||
| 169 | struct windows_hcd_priv *next; | ||
| 170 | }; | ||
| 171 | |||
| 172 | static inline void windows_hcd_priv_init(struct windows_hcd_priv* p) { | ||
| 173 | p->path = NULL; | ||
| 174 | p->next = NULL; | ||
| 175 | } | ||
| 176 | |||
| 177 | static inline void windows_hcd_priv_release(struct windows_hcd_priv* p) { | ||
| 178 | safe_free(p->path); | ||
| 179 | } | ||
| 180 | |||
| 181 | // TODO (v2+): move hid desc to libusb.h? | ||
| 182 | struct libusb_hid_descriptor { | ||
| 183 | uint8_t bLength; | ||
| 184 | uint8_t bDescriptorType; | ||
| 185 | uint16_t bcdHID; | ||
| 186 | uint8_t bCountryCode; | ||
| 187 | uint8_t bNumDescriptors; | ||
| 188 | uint8_t bClassDescriptorType; | ||
| 189 | uint16_t wClassDescriptorLength; | ||
| 190 | }; | ||
| 191 | #define LIBUSB_DT_HID_SIZE 9 | ||
| 192 | #define HID_MAX_CONFIG_DESC_SIZE (LIBUSB_DT_CONFIG_SIZE + LIBUSB_DT_INTERFACE_SIZE \ | ||
| 193 | + LIBUSB_DT_HID_SIZE + 2 * LIBUSB_DT_ENDPOINT_SIZE) | ||
| 194 | #define HID_MAX_REPORT_SIZE 1024 | ||
| 195 | #define HID_IN_EP 0x81 | ||
| 196 | #define HID_OUT_EP 0x02 | ||
| 197 | #define LIBUSB_REQ_RECIPIENT(request_type) ((request_type) & 0x1F) | ||
| 198 | #define LIBUSB_REQ_TYPE(request_type) ((request_type) & (0x03 << 5)) | ||
| 199 | #define LIBUSB_REQ_IN(request_type) ((request_type) & LIBUSB_ENDPOINT_IN) | ||
| 200 | #define LIBUSB_REQ_OUT(request_type) (!LIBUSB_REQ_IN(request_type)) | ||
| 201 | |||
| 202 | // The following are used for HID reports IOCTLs | ||
| 203 | #define HID_CTL_CODE(id) \ | ||
| 204 | CTL_CODE (FILE_DEVICE_KEYBOARD, (id), METHOD_NEITHER, FILE_ANY_ACCESS) | ||
| 205 | #define HID_BUFFER_CTL_CODE(id) \ | ||
| 206 | CTL_CODE (FILE_DEVICE_KEYBOARD, (id), METHOD_BUFFERED, FILE_ANY_ACCESS) | ||
| 207 | #define HID_IN_CTL_CODE(id) \ | ||
| 208 | CTL_CODE (FILE_DEVICE_KEYBOARD, (id), METHOD_IN_DIRECT, FILE_ANY_ACCESS) | ||
| 209 | #define HID_OUT_CTL_CODE(id) \ | ||
| 210 | CTL_CODE (FILE_DEVICE_KEYBOARD, (id), METHOD_OUT_DIRECT, FILE_ANY_ACCESS) | ||
| 211 | |||
| 212 | #define IOCTL_HID_GET_FEATURE HID_OUT_CTL_CODE(100) | ||
| 213 | #define IOCTL_HID_GET_INPUT_REPORT HID_OUT_CTL_CODE(104) | ||
| 214 | #define IOCTL_HID_SET_FEATURE HID_IN_CTL_CODE(100) | ||
| 215 | #define IOCTL_HID_SET_OUTPUT_REPORT HID_IN_CTL_CODE(101) | ||
| 216 | |||
| 217 | enum libusb_hid_request_type { | ||
| 218 | HID_REQ_GET_REPORT = 0x01, | ||
| 219 | HID_REQ_GET_IDLE = 0x02, | ||
| 220 | HID_REQ_GET_PROTOCOL = 0x03, | ||
| 221 | HID_REQ_SET_REPORT = 0x09, | ||
| 222 | HID_REQ_SET_IDLE = 0x0A, | ||
| 223 | HID_REQ_SET_PROTOCOL = 0x0B | ||
| 224 | }; | ||
| 225 | |||
| 226 | enum libusb_hid_report_type { | ||
| 227 | HID_REPORT_TYPE_INPUT = 0x01, | ||
| 228 | HID_REPORT_TYPE_OUTPUT = 0x02, | ||
| 229 | HID_REPORT_TYPE_FEATURE = 0x03 | ||
| 230 | }; | ||
| 231 | |||
| 232 | struct hid_device_priv { | ||
| 233 | uint16_t vid; | ||
| 234 | uint16_t pid; | ||
| 235 | uint8_t config; | ||
| 236 | bool uses_report_ids[3]; // input, ouptput, feature | ||
| 237 | uint16_t input_report_size; | ||
| 238 | uint16_t output_report_size; | ||
| 239 | uint16_t feature_report_size; | ||
| 240 | WCHAR string[3][MAX_USB_STRING_LENGTH]; | ||
| 241 | uint8_t string_index[3]; // man, prod, ser | ||
| 242 | }; | ||
| 243 | |||
| 244 | typedef struct libusb_device_descriptor USB_DEVICE_DESCRIPTOR, *PUSB_DEVICE_DESCRIPTOR; | ||
| 245 | struct windows_device_priv { | ||
| 246 | struct libusb_device *parent_dev; // access to parent is required for usermode ops | ||
| 247 | ULONG connection_index; // also required for some usermode ops | ||
| 248 | char *path; // path used by Windows to reference the USB node | ||
| 249 | struct windows_usb_api_backend const *apib; | ||
| 250 | struct { | ||
| 251 | char *path; // each interface needs a Windows device interface path, | ||
| 252 | struct windows_usb_api_backend const *apib; // an API backend (multiple drivers support), | ||
| 253 | int8_t nb_endpoints; // and a set of endpoint addresses (USB_MAXENDPOINTS) | ||
| 254 | uint8_t *endpoint; | ||
| 255 | bool restricted_functionality; // indicates if the interface functionality is restricted | ||
| 256 | // by Windows (eg. HID keyboards or mice cannot do R/W) | ||
| 257 | } usb_interface[USB_MAXINTERFACES]; | ||
| 258 | uint8_t composite_api_flags; // HID and composite devices require additional data | ||
| 259 | struct hid_device_priv *hid; | ||
| 260 | uint8_t active_config; | ||
| 261 | USB_DEVICE_DESCRIPTOR dev_descriptor; | ||
| 262 | unsigned char **config_descriptor; // list of pointers to the cached config descriptors | ||
| 263 | }; | ||
| 264 | |||
| 265 | static inline void windows_device_priv_init(struct windows_device_priv* p) { | ||
| 266 | int i; | ||
| 267 | p->parent_dev = NULL; | ||
| 268 | p->connection_index = 0; | ||
| 269 | p->path = NULL; | ||
| 270 | p->apib = &usb_api_backend[USB_API_UNSUPPORTED]; | ||
| 271 | p->composite_api_flags = 0; | ||
| 272 | p->hid = NULL; | ||
| 273 | p->active_config = 0; | ||
| 274 | p->config_descriptor = NULL; | ||
| 275 | memset(&(p->dev_descriptor), 0, sizeof(USB_DEVICE_DESCRIPTOR)); | ||
| 276 | for (i=0; i<USB_MAXINTERFACES; i++) { | ||
| 277 | p->usb_interface[i].path = NULL; | ||
| 278 | p->usb_interface[i].apib = &usb_api_backend[USB_API_UNSUPPORTED]; | ||
| 279 | p->usb_interface[i].nb_endpoints = 0; | ||
| 280 | p->usb_interface[i].endpoint = NULL; | ||
| 281 | p->usb_interface[i].restricted_functionality = false; | ||
| 282 | } | ||
| 283 | } | ||
| 284 | |||
| 285 | static inline void windows_device_priv_release(struct windows_device_priv* p, int num_configurations) { | ||
| 286 | int i; | ||
| 287 | safe_free(p->path); | ||
| 288 | if ((num_configurations > 0) && (p->config_descriptor != NULL)) { | ||
| 289 | for (i=0; i < num_configurations; i++) | ||
| 290 | safe_free(p->config_descriptor[i]); | ||
| 291 | } | ||
| 292 | safe_free(p->config_descriptor); | ||
| 293 | safe_free(p->hid); | ||
| 294 | for (i=0; i<USB_MAXINTERFACES; i++) { | ||
| 295 | safe_free(p->usb_interface[i].path); | ||
| 296 | safe_free(p->usb_interface[i].endpoint); | ||
| 297 | } | ||
| 298 | } | ||
| 299 | |||
| 300 | static inline struct windows_device_priv *__device_priv(struct libusb_device *dev) { | ||
| 301 | return (struct windows_device_priv *)dev->os_priv; | ||
| 302 | } | ||
| 303 | |||
| 304 | struct interface_handle_t { | ||
| 305 | HANDLE dev_handle; // WinUSB needs an extra handle for the file | ||
| 306 | HANDLE api_handle; // used by the API to communicate with the device | ||
| 307 | }; | ||
| 308 | |||
| 309 | struct windows_device_handle_priv { | ||
| 310 | int active_interface; | ||
| 311 | struct interface_handle_t interface_handle[USB_MAXINTERFACES]; | ||
| 312 | #if defined(AUTO_CLAIM) | ||
| 313 | int autoclaim_count[USB_MAXINTERFACES]; // For auto-release | ||
| 314 | #endif | ||
| 315 | }; | ||
| 316 | |||
| 317 | static inline struct windows_device_handle_priv *__device_handle_priv( | ||
| 318 | struct libusb_device_handle *handle) | ||
| 319 | { | ||
| 320 | return (struct windows_device_handle_priv *) handle->os_priv; | ||
| 321 | } | ||
| 322 | |||
| 323 | // used for async polling functions | ||
| 324 | struct windows_transfer_priv { | ||
| 325 | struct winfd pollable_fd; | ||
| 326 | uint8_t interface_number; | ||
| 327 | uint8_t *hid_buffer; // 1 byte extended data buffer, required for HID | ||
| 328 | uint8_t *hid_dest; // transfer buffer destination, required for HID | ||
| 329 | size_t hid_expected_size; | ||
| 330 | }; | ||
| 331 | |||
| 332 | // used to match a device driver (including filter drivers) against a supported API | ||
| 333 | struct driver_lookup { | ||
| 334 | char list[MAX_KEY_LENGTH+1];// REG_MULTI_SZ list of services (driver) names | ||
| 335 | const DWORD reg_prop; // SPDRP registry key to use to retreive list | ||
| 336 | const char* designation; // internal designation (for debug output) | ||
| 337 | }; | ||
| 338 | |||
| 339 | /* | ||
| 340 | * API macros - from libusb-win32 1.x | ||
| 341 | */ | ||
| 342 | #define DLL_DECLARE(api, ret, name, args) \ | ||
| 343 | typedef ret (api * __dll_##name##_t)args; __dll_##name##_t name = NULL | ||
| 344 | |||
| 345 | #define DLL_LOAD(dll, name, ret_on_failure) \ | ||
| 346 | do { \ | ||
| 347 | HMODULE h = GetModuleHandle(#dll); \ | ||
| 348 | if (!h) \ | ||
| 349 | h = LoadLibrary(#dll); \ | ||
| 350 | if (!h) { \ | ||
| 351 | if (ret_on_failure) { return LIBUSB_ERROR_NOT_FOUND; }\ | ||
| 352 | else { break; } \ | ||
| 353 | } \ | ||
| 354 | name = (__dll_##name##_t)GetProcAddress(h, #name); \ | ||
| 355 | if (name) break; \ | ||
| 356 | name = (__dll_##name##_t)GetProcAddress(h, #name "A"); \ | ||
| 357 | if (name) break; \ | ||
| 358 | name = (__dll_##name##_t)GetProcAddress(h, #name "W"); \ | ||
| 359 | if (name) break; \ | ||
| 360 | if(ret_on_failure) \ | ||
| 361 | return LIBUSB_ERROR_NOT_FOUND; \ | ||
| 362 | } while(0) | ||
| 363 | |||
| 364 | |||
| 365 | /* | ||
| 366 | * Windows DDK API definitions. Most of it copied from MinGW's includes | ||
| 367 | */ | ||
| 368 | typedef DWORD DEVNODE, DEVINST; | ||
| 369 | typedef DEVNODE *PDEVNODE, *PDEVINST; | ||
| 370 | typedef DWORD RETURN_TYPE; | ||
| 371 | typedef RETURN_TYPE CONFIGRET; | ||
| 372 | |||
| 373 | #define CR_SUCCESS 0x00000000 | ||
| 374 | #define CR_NO_SUCH_DEVNODE 0x0000000D | ||
| 375 | |||
| 376 | #define USB_DEVICE_DESCRIPTOR_TYPE LIBUSB_DT_DEVICE | ||
| 377 | #define USB_CONFIGURATION_DESCRIPTOR_TYPE LIBUSB_DT_CONFIG | ||
| 378 | #define USB_STRING_DESCRIPTOR_TYPE LIBUSB_DT_STRING | ||
| 379 | #define USB_INTERFACE_DESCRIPTOR_TYPE LIBUSB_DT_INTERFACE | ||
| 380 | #define USB_ENDPOINT_DESCRIPTOR_TYPE LIBUSB_DT_ENDPOINT | ||
| 381 | |||
| 382 | #define USB_REQUEST_GET_STATUS LIBUSB_REQUEST_GET_STATUS | ||
| 383 | #define USB_REQUEST_CLEAR_FEATURE LIBUSB_REQUEST_CLEAR_FEATURE | ||
| 384 | #define USB_REQUEST_SET_FEATURE LIBUSB_REQUEST_SET_FEATURE | ||
| 385 | #define USB_REQUEST_SET_ADDRESS LIBUSB_REQUEST_SET_ADDRESS | ||
| 386 | #define USB_REQUEST_GET_DESCRIPTOR LIBUSB_REQUEST_GET_DESCRIPTOR | ||
| 387 | #define USB_REQUEST_SET_DESCRIPTOR LIBUSB_REQUEST_SET_DESCRIPTOR | ||
| 388 | #define USB_REQUEST_GET_CONFIGURATION LIBUSB_REQUEST_GET_CONFIGURATION | ||
| 389 | #define USB_REQUEST_SET_CONFIGURATION LIBUSB_REQUEST_SET_CONFIGURATION | ||
| 390 | #define USB_REQUEST_GET_INTERFACE LIBUSB_REQUEST_GET_INTERFACE | ||
| 391 | #define USB_REQUEST_SET_INTERFACE LIBUSB_REQUEST_SET_INTERFACE | ||
| 392 | #define USB_REQUEST_SYNC_FRAME LIBUSB_REQUEST_SYNCH_FRAME | ||
| 393 | |||
| 394 | #define HCD_GET_ROOT_HUB_NAME 258 | ||
| 395 | #define USB_GET_NODE_INFORMATION 258 | ||
| 396 | #define USB_GET_NODE_CONNECTION_INFORMATION 259 | ||
| 397 | #define USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION 260 | ||
| 398 | #define USB_GET_NODE_CONNECTION_NAME 261 | ||
| 399 | #define USB_GET_HUB_CAPABILITIES 271 | ||
| 400 | #if !defined(USB_GET_HUB_CAPABILITIES_EX) | ||
| 401 | #define USB_GET_HUB_CAPABILITIES_EX 276 | ||
| 402 | #endif | ||
| 403 | |||
| 404 | #ifndef METHOD_BUFFERED | ||
| 405 | #define METHOD_BUFFERED 0 | ||
| 406 | #endif | ||
| 407 | #ifndef FILE_ANY_ACCESS | ||
| 408 | #define FILE_ANY_ACCESS 0x00000000 | ||
| 409 | #endif | ||
| 410 | #ifndef FILE_DEVICE_UNKNOWN | ||
| 411 | #define FILE_DEVICE_UNKNOWN 0x00000022 | ||
| 412 | #endif | ||
| 413 | #ifndef FILE_DEVICE_USB | ||
| 414 | #define FILE_DEVICE_USB FILE_DEVICE_UNKNOWN | ||
| 415 | #endif | ||
| 416 | |||
| 417 | #ifndef CTL_CODE | ||
| 418 | #define CTL_CODE(DeviceType, Function, Method, Access)( \ | ||
| 419 | ((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method)) | ||
| 420 | #endif | ||
| 421 | |||
| 422 | typedef enum _USB_CONNECTION_STATUS { | ||
| 423 | NoDeviceConnected, | ||
| 424 | DeviceConnected, | ||
| 425 | DeviceFailedEnumeration, | ||
| 426 | DeviceGeneralFailure, | ||
| 427 | DeviceCausedOvercurrent, | ||
| 428 | DeviceNotEnoughPower, | ||
| 429 | DeviceNotEnoughBandwidth, | ||
| 430 | DeviceHubNestedTooDeeply, | ||
| 431 | DeviceInLegacyHub | ||
| 432 | } USB_CONNECTION_STATUS, *PUSB_CONNECTION_STATUS; | ||
| 433 | |||
| 434 | typedef enum _USB_HUB_NODE { | ||
| 435 | UsbHub, | ||
| 436 | UsbMIParent | ||
| 437 | } USB_HUB_NODE; | ||
| 438 | |||
| 439 | /* Cfgmgr32.dll interface */ | ||
| 440 | DLL_DECLARE(WINAPI, CONFIGRET, CM_Get_Parent, (PDEVINST, DEVINST, ULONG)); | ||
| 441 | DLL_DECLARE(WINAPI, CONFIGRET, CM_Get_Child, (PDEVINST, DEVINST, ULONG)); | ||
| 442 | DLL_DECLARE(WINAPI, CONFIGRET, CM_Get_Sibling, (PDEVINST, DEVINST, ULONG)); | ||
| 443 | DLL_DECLARE(WINAPI, CONFIGRET, CM_Get_Device_IDA, (DEVINST, PCHAR, ULONG, ULONG)); | ||
| 444 | DLL_DECLARE(WINAPI, CONFIGRET, CM_Get_Device_IDW, (DEVINST, PWCHAR, ULONG, ULONG)); | ||
| 445 | |||
| 446 | #ifdef UNICODE | ||
| 447 | #define CM_Get_Device_ID CM_Get_Device_IDW | ||
| 448 | #else | ||
| 449 | #define CM_Get_Device_ID CM_Get_Device_IDA | ||
| 450 | #endif /* UNICODE */ | ||
| 451 | |||
| 452 | #define IOCTL_USB_GET_HUB_CAPABILITIES_EX \ | ||
| 453 | CTL_CODE( FILE_DEVICE_USB, USB_GET_HUB_CAPABILITIES_EX, METHOD_BUFFERED, FILE_ANY_ACCESS) | ||
| 454 | |||
| 455 | #define IOCTL_USB_GET_HUB_CAPABILITIES \ | ||
| 456 | CTL_CODE(FILE_DEVICE_USB, USB_GET_HUB_CAPABILITIES, METHOD_BUFFERED, FILE_ANY_ACCESS) | ||
| 457 | |||
| 458 | #define IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION \ | ||
| 459 | CTL_CODE(FILE_DEVICE_USB, USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION, METHOD_BUFFERED, FILE_ANY_ACCESS) | ||
| 460 | |||
| 461 | #define IOCTL_USB_GET_ROOT_HUB_NAME \ | ||
| 462 | CTL_CODE(FILE_DEVICE_USB, HCD_GET_ROOT_HUB_NAME, METHOD_BUFFERED, FILE_ANY_ACCESS) | ||
| 463 | |||
| 464 | #define IOCTL_USB_GET_NODE_INFORMATION \ | ||
| 465 | CTL_CODE(FILE_DEVICE_USB, USB_GET_NODE_INFORMATION, METHOD_BUFFERED, FILE_ANY_ACCESS) | ||
| 466 | |||
| 467 | #define IOCTL_USB_GET_NODE_CONNECTION_INFORMATION \ | ||
| 468 | CTL_CODE(FILE_DEVICE_USB, USB_GET_NODE_CONNECTION_INFORMATION, METHOD_BUFFERED, FILE_ANY_ACCESS) | ||
| 469 | |||
| 470 | #define IOCTL_USB_GET_NODE_CONNECTION_ATTRIBUTES \ | ||
| 471 | CTL_CODE(FILE_DEVICE_USB, USB_GET_NODE_CONNECTION_ATTRIBUTES, METHOD_BUFFERED, FILE_ANY_ACCESS) | ||
| 472 | |||
| 473 | #define IOCTL_USB_GET_NODE_CONNECTION_NAME \ | ||
| 474 | CTL_CODE(FILE_DEVICE_USB, USB_GET_NODE_CONNECTION_NAME, METHOD_BUFFERED, FILE_ANY_ACCESS) | ||
| 475 | |||
| 476 | // Most of the structures below need to be packed | ||
| 477 | #pragma pack(push, 1) | ||
| 478 | |||
| 479 | typedef struct _USB_INTERFACE_DESCRIPTOR { | ||
| 480 | UCHAR bLength; | ||
| 481 | UCHAR bDescriptorType; | ||
| 482 | UCHAR bInterfaceNumber; | ||
| 483 | UCHAR bAlternateSetting; | ||
| 484 | UCHAR bNumEndpoints; | ||
| 485 | UCHAR bInterfaceClass; | ||
| 486 | UCHAR bInterfaceSubClass; | ||
| 487 | UCHAR bInterfaceProtocol; | ||
| 488 | UCHAR iInterface; | ||
| 489 | } USB_INTERFACE_DESCRIPTOR, *PUSB_INTERFACE_DESCRIPTOR; | ||
| 490 | |||
| 491 | typedef struct _USB_CONFIGURATION_DESCRIPTOR { | ||
| 492 | UCHAR bLength; | ||
| 493 | UCHAR bDescriptorType; | ||
| 494 | USHORT wTotalLength; | ||
| 495 | UCHAR bNumInterfaces; | ||
| 496 | UCHAR bConfigurationValue; | ||
| 497 | UCHAR iConfiguration; | ||
| 498 | UCHAR bmAttributes; | ||
| 499 | UCHAR MaxPower; | ||
| 500 | } USB_CONFIGURATION_DESCRIPTOR, *PUSB_CONFIGURATION_DESCRIPTOR; | ||
| 501 | |||
| 502 | typedef struct _USB_CONFIGURATION_DESCRIPTOR_SHORT { | ||
| 503 | struct { | ||
| 504 | ULONG ConnectionIndex; | ||
| 505 | struct { | ||
| 506 | UCHAR bmRequest; | ||
| 507 | UCHAR bRequest; | ||
| 508 | USHORT wValue; | ||
| 509 | USHORT wIndex; | ||
| 510 | USHORT wLength; | ||
| 511 | } SetupPacket; | ||
| 512 | } req; | ||
| 513 | USB_CONFIGURATION_DESCRIPTOR data; | ||
| 514 | } USB_CONFIGURATION_DESCRIPTOR_SHORT; | ||
| 515 | |||
| 516 | typedef struct _USB_ENDPOINT_DESCRIPTOR { | ||
| 517 | UCHAR bLength; | ||
| 518 | UCHAR bDescriptorType; | ||
| 519 | UCHAR bEndpointAddress; | ||
| 520 | UCHAR bmAttributes; | ||
| 521 | USHORT wMaxPacketSize; | ||
| 522 | UCHAR bInterval; | ||
| 523 | } USB_ENDPOINT_DESCRIPTOR, *PUSB_ENDPOINT_DESCRIPTOR; | ||
| 524 | |||
| 525 | typedef struct _USB_DESCRIPTOR_REQUEST { | ||
| 526 | ULONG ConnectionIndex; | ||
| 527 | struct { | ||
| 528 | UCHAR bmRequest; | ||
| 529 | UCHAR bRequest; | ||
| 530 | USHORT wValue; | ||
| 531 | USHORT wIndex; | ||
| 532 | USHORT wLength; | ||
| 533 | } SetupPacket; | ||
| 534 | // UCHAR Data[0]; | ||
| 535 | } USB_DESCRIPTOR_REQUEST, *PUSB_DESCRIPTOR_REQUEST; | ||
| 536 | |||
| 537 | typedef struct _USB_HUB_DESCRIPTOR { | ||
| 538 | UCHAR bDescriptorLength; | ||
| 539 | UCHAR bDescriptorType; | ||
| 540 | UCHAR bNumberOfPorts; | ||
| 541 | USHORT wHubCharacteristics; | ||
| 542 | UCHAR bPowerOnToPowerGood; | ||
| 543 | UCHAR bHubControlCurrent; | ||
| 544 | UCHAR bRemoveAndPowerMask[64]; | ||
| 545 | } USB_HUB_DESCRIPTOR, *PUSB_HUB_DESCRIPTOR; | ||
| 546 | |||
| 547 | typedef struct _USB_ROOT_HUB_NAME { | ||
| 548 | ULONG ActualLength; | ||
| 549 | WCHAR RootHubName[1]; | ||
| 550 | } USB_ROOT_HUB_NAME, *PUSB_ROOT_HUB_NAME; | ||
| 551 | |||
| 552 | typedef struct _USB_ROOT_HUB_NAME_FIXED { | ||
| 553 | ULONG ActualLength; | ||
| 554 | WCHAR RootHubName[MAX_PATH_LENGTH]; | ||
| 555 | } USB_ROOT_HUB_NAME_FIXED; | ||
| 556 | |||
| 557 | typedef struct _USB_NODE_CONNECTION_NAME { | ||
| 558 | ULONG ConnectionIndex; | ||
| 559 | ULONG ActualLength; | ||
| 560 | WCHAR NodeName[1]; | ||
| 561 | } USB_NODE_CONNECTION_NAME, *PUSB_NODE_CONNECTION_NAME; | ||
| 562 | |||
| 563 | typedef struct _USB_NODE_CONNECTION_NAME_FIXED { | ||
| 564 | ULONG ConnectionIndex; | ||
| 565 | ULONG ActualLength; | ||
| 566 | WCHAR NodeName[MAX_PATH_LENGTH]; | ||
| 567 | } USB_NODE_CONNECTION_NAME_FIXED; | ||
| 568 | |||
| 569 | typedef struct _USB_HUB_NAME_FIXED { | ||
| 570 | union { | ||
| 571 | USB_ROOT_HUB_NAME_FIXED root; | ||
| 572 | USB_NODE_CONNECTION_NAME_FIXED node; | ||
| 573 | } u; | ||
| 574 | } USB_HUB_NAME_FIXED; | ||
| 575 | |||
| 576 | |||
| 577 | typedef struct _USB_HUB_INFORMATION { | ||
| 578 | USB_HUB_DESCRIPTOR HubDescriptor; | ||
| 579 | BOOLEAN HubIsBusPowered; | ||
| 580 | } USB_HUB_INFORMATION, *PUSB_HUB_INFORMATION; | ||
| 581 | |||
| 582 | typedef struct _USB_MI_PARENT_INFORMATION { | ||
| 583 | ULONG NumberOfInterfaces; | ||
| 584 | } USB_MI_PARENT_INFORMATION, *PUSB_MI_PARENT_INFORMATION; | ||
| 585 | |||
| 586 | typedef struct _USB_NODE_INFORMATION { | ||
| 587 | USB_HUB_NODE NodeType; | ||
| 588 | union { | ||
| 589 | USB_HUB_INFORMATION HubInformation; | ||
| 590 | USB_MI_PARENT_INFORMATION MiParentInformation; | ||
| 591 | } u; | ||
| 592 | } USB_NODE_INFORMATION, *PUSB_NODE_INFORMATION; | ||
| 593 | |||
| 594 | typedef struct _USB_PIPE_INFO { | ||
| 595 | USB_ENDPOINT_DESCRIPTOR EndpointDescriptor; | ||
| 596 | ULONG ScheduleOffset; | ||
| 597 | } USB_PIPE_INFO, *PUSB_PIPE_INFO; | ||
| 598 | |||
| 599 | typedef struct _USB_NODE_CONNECTION_INFORMATION { | ||
| 600 | ULONG ConnectionIndex; | ||
| 601 | USB_DEVICE_DESCRIPTOR DeviceDescriptor; | ||
| 602 | UCHAR CurrentConfigurationValue; | ||
| 603 | BOOLEAN LowSpeed; | ||
| 604 | BOOLEAN DeviceIsHub; | ||
| 605 | USHORT DeviceAddress; | ||
| 606 | ULONG NumberOfOpenPipes; | ||
| 607 | USB_CONNECTION_STATUS ConnectionStatus; | ||
| 608 | // USB_PIPE_INFO PipeList[0]; | ||
| 609 | } USB_NODE_CONNECTION_INFORMATION, *PUSB_NODE_CONNECTION_INFORMATION; | ||
| 610 | |||
| 611 | typedef struct _USB_HUB_CAP_FLAGS { | ||
| 612 | ULONG HubIsHighSpeedCapable:1; | ||
| 613 | ULONG HubIsHighSpeed:1; | ||
| 614 | ULONG HubIsMultiTtCapable:1; | ||
| 615 | ULONG HubIsMultiTt:1; | ||
| 616 | ULONG HubIsRoot:1; | ||
| 617 | ULONG HubIsArmedWakeOnConnect:1; | ||
| 618 | ULONG ReservedMBZ:26; | ||
| 619 | } USB_HUB_CAP_FLAGS, *PUSB_HUB_CAP_FLAGS; | ||
| 620 | |||
| 621 | typedef struct _USB_HUB_CAPABILITIES { | ||
| 622 | ULONG HubIs2xCapable : 1; | ||
| 623 | } USB_HUB_CAPABILITIES, *PUSB_HUB_CAPABILITIES; | ||
| 624 | |||
| 625 | typedef struct _USB_HUB_CAPABILITIES_EX { | ||
| 626 | USB_HUB_CAP_FLAGS CapabilityFlags; | ||
| 627 | } USB_HUB_CAPABILITIES_EX, *PUSB_HUB_CAPABILITIES_EX; | ||
| 628 | |||
| 629 | #pragma pack(pop) | ||
| 630 | |||
| 631 | /* winusb.dll interface */ | ||
| 632 | |||
| 633 | #define SHORT_PACKET_TERMINATE 0x01 | ||
| 634 | #define AUTO_CLEAR_STALL 0x02 | ||
| 635 | #define PIPE_TRANSFER_TIMEOUT 0x03 | ||
| 636 | #define IGNORE_SHORT_PACKETS 0x04 | ||
| 637 | #define ALLOW_PARTIAL_READS 0x05 | ||
| 638 | #define AUTO_FLUSH 0x06 | ||
| 639 | #define RAW_IO 0x07 | ||
| 640 | #define MAXIMUM_TRANSFER_SIZE 0x08 | ||
| 641 | #define AUTO_SUSPEND 0x81 | ||
| 642 | #define SUSPEND_DELAY 0x83 | ||
| 643 | #define DEVICE_SPEED 0x01 | ||
| 644 | #define LowSpeed 0x01 | ||
| 645 | #define FullSpeed 0x02 | ||
| 646 | #define HighSpeed 0x03 | ||
| 647 | |||
| 648 | typedef enum _USBD_PIPE_TYPE { | ||
| 649 | UsbdPipeTypeControl, | ||
| 650 | UsbdPipeTypeIsochronous, | ||
| 651 | UsbdPipeTypeBulk, | ||
| 652 | UsbdPipeTypeInterrupt | ||
| 653 | } USBD_PIPE_TYPE; | ||
| 654 | |||
| 655 | typedef struct { | ||
| 656 | USBD_PIPE_TYPE PipeType; | ||
| 657 | UCHAR PipeId; | ||
| 658 | USHORT MaximumPacketSize; | ||
| 659 | UCHAR Interval; | ||
| 660 | } WINUSB_PIPE_INFORMATION, *PWINUSB_PIPE_INFORMATION; | ||
| 661 | |||
| 662 | #pragma pack(1) | ||
| 663 | typedef struct { | ||
| 664 | UCHAR request_type; | ||
| 665 | UCHAR request; | ||
| 666 | USHORT value; | ||
| 667 | USHORT index; | ||
| 668 | USHORT length; | ||
| 669 | } WINUSB_SETUP_PACKET, *PWINUSB_SETUP_PACKET; | ||
| 670 | #pragma pack() | ||
| 671 | |||
| 672 | typedef void *WINUSB_INTERFACE_HANDLE, *PWINUSB_INTERFACE_HANDLE; | ||
| 673 | |||
| 674 | DLL_DECLARE(WINAPI, BOOL, WinUsb_Initialize, (HANDLE, PWINUSB_INTERFACE_HANDLE)); | ||
| 675 | DLL_DECLARE(WINAPI, BOOL, WinUsb_Free, (WINUSB_INTERFACE_HANDLE)); | ||
| 676 | DLL_DECLARE(WINAPI, BOOL, WinUsb_GetAssociatedInterface, (WINUSB_INTERFACE_HANDLE, UCHAR, PWINUSB_INTERFACE_HANDLE)); | ||
| 677 | DLL_DECLARE(WINAPI, BOOL, WinUsb_GetDescriptor, (WINUSB_INTERFACE_HANDLE, UCHAR, UCHAR, USHORT, PUCHAR, ULONG, PULONG)); | ||
| 678 | DLL_DECLARE(WINAPI, BOOL, WinUsb_QueryInterfaceSettings, (WINUSB_INTERFACE_HANDLE, UCHAR, PUSB_INTERFACE_DESCRIPTOR)); | ||
| 679 | DLL_DECLARE(WINAPI, BOOL, WinUsb_QueryDeviceInformation, (WINUSB_INTERFACE_HANDLE, ULONG, PULONG, PVOID)); | ||
| 680 | DLL_DECLARE(WINAPI, BOOL, WinUsb_SetCurrentAlternateSetting, (WINUSB_INTERFACE_HANDLE, UCHAR)); | ||
| 681 | DLL_DECLARE(WINAPI, BOOL, WinUsb_GetCurrentAlternateSetting, (WINUSB_INTERFACE_HANDLE, PUCHAR)); | ||
| 682 | DLL_DECLARE(WINAPI, BOOL, WinUsb_QueryPipe, (WINUSB_INTERFACE_HANDLE, UCHAR, UCHAR, PWINUSB_PIPE_INFORMATION)); | ||
| 683 | DLL_DECLARE(WINAPI, BOOL, WinUsb_SetPipePolicy, (WINUSB_INTERFACE_HANDLE, UCHAR, ULONG, ULONG, PVOID)); | ||
| 684 | DLL_DECLARE(WINAPI, BOOL, WinUsb_GetPipePolicy, (WINUSB_INTERFACE_HANDLE, UCHAR, ULONG, PULONG, PVOID)); | ||
| 685 | DLL_DECLARE(WINAPI, BOOL, WinUsb_ReadPipe, (WINUSB_INTERFACE_HANDLE, UCHAR, PUCHAR, ULONG, PULONG, LPOVERLAPPED)); | ||
| 686 | DLL_DECLARE(WINAPI, BOOL, WinUsb_WritePipe, (WINUSB_INTERFACE_HANDLE, UCHAR, PUCHAR, ULONG, PULONG, LPOVERLAPPED)); | ||
| 687 | DLL_DECLARE(WINAPI, BOOL, WinUsb_ControlTransfer, (WINUSB_INTERFACE_HANDLE, WINUSB_SETUP_PACKET, PUCHAR, ULONG, PULONG, LPOVERLAPPED)); | ||
| 688 | DLL_DECLARE(WINAPI, BOOL, WinUsb_ResetPipe, (WINUSB_INTERFACE_HANDLE, UCHAR)); | ||
| 689 | DLL_DECLARE(WINAPI, BOOL, WinUsb_AbortPipe, (WINUSB_INTERFACE_HANDLE, UCHAR)); | ||
| 690 | DLL_DECLARE(WINAPI, BOOL, WinUsb_FlushPipe, (WINUSB_INTERFACE_HANDLE, UCHAR)); | ||
| 691 | |||
| 692 | /* hid.dll interface */ | ||
| 693 | |||
| 694 | #define HIDP_STATUS_SUCCESS 0x110000 | ||
| 695 | typedef void* PHIDP_PREPARSED_DATA; | ||
| 696 | |||
| 697 | #pragma pack(1) | ||
| 698 | typedef struct { | ||
| 699 | ULONG Size; | ||
| 700 | USHORT VendorID; | ||
| 701 | USHORT ProductID; | ||
| 702 | USHORT VersionNumber; | ||
| 703 | } HIDD_ATTRIBUTES, *PHIDD_ATTRIBUTES; | ||
| 704 | #pragma pack() | ||
| 705 | |||
| 706 | typedef USHORT USAGE; | ||
| 707 | typedef struct { | ||
| 708 | USAGE Usage; | ||
| 709 | USAGE UsagePage; | ||
| 710 | USHORT InputReportByteLength; | ||
| 711 | USHORT OutputReportByteLength; | ||
| 712 | USHORT FeatureReportByteLength; | ||
| 713 | USHORT Reserved[17]; | ||
| 714 | USHORT NumberLinkCollectionNodes; | ||
| 715 | USHORT NumberInputButtonCaps; | ||
| 716 | USHORT NumberInputValueCaps; | ||
| 717 | USHORT NumberInputDataIndices; | ||
| 718 | USHORT NumberOutputButtonCaps; | ||
| 719 | USHORT NumberOutputValueCaps; | ||
| 720 | USHORT NumberOutputDataIndices; | ||
| 721 | USHORT NumberFeatureButtonCaps; | ||
| 722 | USHORT NumberFeatureValueCaps; | ||
| 723 | USHORT NumberFeatureDataIndices; | ||
| 724 | } HIDP_CAPS, *PHIDP_CAPS; | ||
| 725 | |||
| 726 | typedef enum _HIDP_REPORT_TYPE { | ||
| 727 | HidP_Input, | ||
| 728 | HidP_Output, | ||
| 729 | HidP_Feature | ||
| 730 | } HIDP_REPORT_TYPE; | ||
| 731 | |||
| 732 | typedef struct _HIDP_VALUE_CAPS { | ||
| 733 | USAGE UsagePage; | ||
| 734 | UCHAR ReportID; | ||
| 735 | BOOLEAN IsAlias; | ||
| 736 | USHORT BitField; | ||
| 737 | USHORT LinkCollection; | ||
| 738 | USAGE LinkUsage; | ||
| 739 | USAGE LinkUsagePage; | ||
| 740 | BOOLEAN IsRange; | ||
| 741 | BOOLEAN IsStringRange; | ||
| 742 | BOOLEAN IsDesignatorRange; | ||
| 743 | BOOLEAN IsAbsolute; | ||
| 744 | BOOLEAN HasNull; | ||
| 745 | UCHAR Reserved; | ||
| 746 | USHORT BitSize; | ||
| 747 | USHORT ReportCount; | ||
| 748 | USHORT Reserved2[5]; | ||
| 749 | ULONG UnitsExp; | ||
| 750 | ULONG Units; | ||
| 751 | LONG LogicalMin, LogicalMax; | ||
| 752 | LONG PhysicalMin, PhysicalMax; | ||
| 753 | union { | ||
| 754 | struct { | ||
| 755 | USAGE UsageMin, UsageMax; | ||
| 756 | USHORT StringMin, StringMax; | ||
| 757 | USHORT DesignatorMin, DesignatorMax; | ||
| 758 | USHORT DataIndexMin, DataIndexMax; | ||
| 759 | } Range; | ||
| 760 | struct { | ||
| 761 | USAGE Usage, Reserved1; | ||
| 762 | USHORT StringIndex, Reserved2; | ||
| 763 | USHORT DesignatorIndex, Reserved3; | ||
| 764 | USHORT DataIndex, Reserved4; | ||
| 765 | } NotRange; | ||
| 766 | } u; | ||
| 767 | } HIDP_VALUE_CAPS, *PHIDP_VALUE_CAPS; | ||
| 768 | |||
| 769 | DLL_DECLARE(WINAPI, BOOL, HidD_GetAttributes, (HANDLE, PHIDD_ATTRIBUTES)); | ||
| 770 | DLL_DECLARE(WINAPI, VOID, HidD_GetHidGuid, (LPGUID)); | ||
| 771 | DLL_DECLARE(WINAPI, BOOL, HidD_GetPreparsedData, (HANDLE, PHIDP_PREPARSED_DATA *)); | ||
| 772 | DLL_DECLARE(WINAPI, BOOL, HidD_FreePreparsedData, (PHIDP_PREPARSED_DATA)); | ||
| 773 | DLL_DECLARE(WINAPI, BOOL, HidD_GetManufacturerString, (HANDLE, PVOID, ULONG)); | ||
| 774 | DLL_DECLARE(WINAPI, BOOL, HidD_GetProductString, (HANDLE, PVOID, ULONG)); | ||
| 775 | DLL_DECLARE(WINAPI, BOOL, HidD_GetSerialNumberString, (HANDLE, PVOID, ULONG)); | ||
| 776 | DLL_DECLARE(WINAPI, LONG, HidP_GetCaps, (PHIDP_PREPARSED_DATA, PHIDP_CAPS)); | ||
| 777 | DLL_DECLARE(WINAPI, BOOL, HidD_SetNumInputBuffers, (HANDLE, ULONG)); | ||
| 778 | DLL_DECLARE(WINAPI, BOOL, HidD_SetFeature, (HANDLE, PVOID, ULONG)); | ||
| 779 | DLL_DECLARE(WINAPI, BOOL, HidD_GetFeature, (HANDLE, PVOID, ULONG)); | ||
| 780 | DLL_DECLARE(WINAPI, BOOL, HidD_GetPhysicalDescriptor, (HANDLE, PVOID, ULONG)); | ||
| 781 | DLL_DECLARE(WINAPI, BOOL, HidD_GetInputReport, (HANDLE, PVOID, ULONG)); | ||
| 782 | DLL_DECLARE(WINAPI, BOOL, HidD_SetOutputReport, (HANDLE, PVOID, ULONG)); | ||
| 783 | DLL_DECLARE(WINAPI, BOOL, HidD_FlushQueue, (HANDLE)); | ||
| 784 | DLL_DECLARE(WINAPI, BOOL, HidP_GetValueCaps, (HIDP_REPORT_TYPE, PHIDP_VALUE_CAPS, PULONG, PHIDP_PREPARSED_DATA)); | ||
