libusb 0.5.1 → 0.6.0

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