usb 2.1.2 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (288) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +20 -2
  3. package/dist/index.d.ts +2 -1
  4. package/dist/index.js +3 -1
  5. package/dist/index.js.map +1 -1
  6. package/dist/usb/bindings.d.ts +4 -0
  7. package/dist/usb/device.js +5 -0
  8. package/dist/usb/device.js.map +1 -1
  9. package/dist/usb/index.js +7 -16
  10. package/dist/usb/index.js.map +1 -1
  11. package/dist/webusb/webusb-device.d.ts +2 -1
  12. package/dist/webusb/webusb-device.js +21 -14
  13. package/dist/webusb/webusb-device.js.map +1 -1
  14. package/libusb/.gitattributes +2 -6
  15. package/libusb/.private/appveyor_build.sh +22 -0
  16. package/libusb/.private/bm.sh +1 -1
  17. package/libusb/.private/ci-build.sh +67 -0
  18. package/libusb/.private/ci-container-build.sh +70 -0
  19. package/libusb/.private/post-rewrite.sh +5 -1
  20. package/libusb/.private/pre-commit.sh +5 -1
  21. package/libusb/.private/wbs.txt +4 -19
  22. package/libusb/.travis.yml +32 -23
  23. package/libusb/AUTHORS +86 -3
  24. package/libusb/ChangeLog +54 -3
  25. package/libusb/INSTALL_WIN.txt +22 -44
  26. package/libusb/Makefile.am +32 -10
  27. package/libusb/{README.md → README} +2 -2
  28. package/libusb/README.git +3 -3
  29. package/libusb/Xcode/common.xcconfig +23 -19
  30. package/libusb/Xcode/config.h +25 -13
  31. package/libusb/Xcode/libusb.xcodeproj/project.pbxproj +511 -109
  32. package/libusb/android/README +90 -54
  33. package/libusb/android/config.h +23 -43
  34. package/libusb/android/examples/unrooted_android.c +300 -0
  35. package/libusb/android/examples/unrooted_android.h +36 -0
  36. package/libusb/android/jni/Android.mk +1 -1
  37. package/libusb/android/jni/Application.mk +16 -0
  38. package/libusb/android/jni/examples.mk +63 -29
  39. package/libusb/android/jni/libusb.mk +14 -8
  40. package/libusb/android/jni/tests.mk +13 -24
  41. package/libusb/appveyor.yml +73 -30
  42. package/libusb/autogen.sh +5 -3
  43. package/libusb/bootstrap.sh +6 -2
  44. package/libusb/configure.ac +314 -227
  45. package/libusb/doc/Makefile.in +22 -0
  46. package/libusb/doc/doxygen.cfg.in +460 -223
  47. package/libusb/examples/Makefile.am +6 -13
  48. package/libusb/examples/dpfp.c +276 -73
  49. package/libusb/examples/ezusb.c +18 -8
  50. package/libusb/examples/ezusb.h +6 -17
  51. package/libusb/examples/fxload.c +4 -5
  52. package/libusb/examples/hotplugtest.c +1 -1
  53. package/libusb/examples/sam3u_benchmark.c +59 -24
  54. package/libusb/examples/testlibusb.c +138 -104
  55. package/libusb/examples/xusb.c +26 -22
  56. package/libusb/libusb/Makefile.am +57 -70
  57. package/libusb/libusb/Makefile.am.extra +26 -0
  58. package/libusb/libusb/core.c +432 -423
  59. package/libusb/libusb/descriptor.c +365 -419
  60. package/libusb/libusb/hotplug.c +200 -104
  61. package/libusb/libusb/io.c +522 -535
  62. package/libusb/libusb/libusb-1.0.def +7 -3
  63. package/libusb/libusb/libusb-1.0.rc +1 -9
  64. package/libusb/libusb/libusb.h +302 -226
  65. package/libusb/libusb/libusbi.h +607 -316
  66. package/libusb/libusb/os/darwin_usb.c +703 -329
  67. package/libusb/libusb/os/darwin_usb.h +39 -15
  68. package/libusb/libusb/os/events_posix.c +300 -0
  69. package/libusb/libusb/os/events_posix.h +59 -0
  70. package/libusb/libusb/os/events_windows.c +214 -0
  71. package/libusb/{msvc/missing.h → libusb/os/events_windows.h} +25 -11
  72. package/libusb/libusb/os/haiku_pollfs.cpp +14 -9
  73. package/libusb/libusb/os/haiku_usb.h +12 -12
  74. package/libusb/libusb/os/haiku_usb_backend.cpp +36 -37
  75. package/libusb/libusb/os/haiku_usb_raw.cpp +80 -116
  76. package/libusb/libusb/os/linux_netlink.c +55 -63
  77. package/libusb/libusb/os/linux_udev.c +61 -69
  78. package/libusb/libusb/os/linux_usbfs.c +926 -1015
  79. package/libusb/libusb/os/linux_usbfs.h +74 -57
  80. package/libusb/libusb/os/netbsd_usb.c +103 -168
  81. package/libusb/libusb/os/null_usb.c +111 -0
  82. package/libusb/libusb/os/openbsd_usb.c +71 -120
  83. package/libusb/libusb/os/sunos_usb.c +289 -375
  84. package/libusb/libusb/os/sunos_usb.h +0 -1
  85. package/libusb/libusb/os/threads_posix.c +81 -32
  86. package/libusb/libusb/os/threads_posix.h +19 -23
  87. package/libusb/libusb/os/threads_windows.c +9 -95
  88. package/libusb/libusb/os/threads_windows.h +33 -31
  89. package/libusb/libusb/os/windows_common.c +915 -0
  90. package/libusb/libusb/os/windows_common.h +330 -42
  91. package/libusb/libusb/os/windows_usbdk.c +161 -267
  92. package/libusb/libusb/os/windows_usbdk.h +5 -2
  93. package/libusb/libusb/os/windows_winusb.c +1355 -1192
  94. package/libusb/libusb/os/windows_winusb.h +167 -167
  95. package/libusb/libusb/strerror.c +20 -30
  96. package/libusb/libusb/sync.c +20 -21
  97. package/libusb/libusb/version.h +1 -1
  98. package/libusb/libusb/version_nano.h +1 -1
  99. package/libusb/msvc/.gitattributes +3 -0
  100. package/libusb/msvc/config.h +27 -20
  101. package/libusb/msvc/{hotplugtest_2012.vcxproj → dpfp_2013.vcxproj} +14 -10
  102. package/libusb/msvc/dpfp_2013.vcxproj.filters +26 -0
  103. package/libusb/msvc/{listdevs_2010.vcxproj → dpfp_2015.vcxproj} +14 -9
  104. package/libusb/msvc/dpfp_2015.vcxproj.filters +26 -0
  105. package/libusb/msvc/dpfp_2017.vcxproj +106 -0
  106. package/libusb/msvc/dpfp_2017.vcxproj.filters +26 -0
  107. package/libusb/msvc/dpfp_2019.vcxproj +106 -0
  108. package/libusb/msvc/dpfp_2019.vcxproj.filters +26 -0
  109. package/libusb/msvc/dpfp_threaded_2013.vcxproj +87 -0
  110. package/libusb/msvc/dpfp_threaded_2013.vcxproj.filters +26 -0
  111. package/libusb/msvc/dpfp_threaded_2015.vcxproj +87 -0
  112. package/libusb/msvc/dpfp_threaded_2015.vcxproj.filters +26 -0
  113. package/libusb/msvc/dpfp_threaded_2017.vcxproj +106 -0
  114. package/libusb/msvc/dpfp_threaded_2017.vcxproj.filters +26 -0
  115. package/libusb/msvc/{fxload_2012.vcxproj → dpfp_threaded_2019.vcxproj} +32 -17
  116. package/libusb/msvc/dpfp_threaded_2019.vcxproj.filters +26 -0
  117. package/libusb/msvc/fxload_2013.vcxproj +6 -3
  118. package/libusb/msvc/fxload_2013.vcxproj.filters +35 -0
  119. package/libusb/msvc/fxload_2015.vcxproj +6 -3
  120. package/libusb/msvc/fxload_2015.vcxproj.filters +35 -0
  121. package/libusb/msvc/fxload_2017.vcxproj +6 -7
  122. package/libusb/msvc/fxload_2017.vcxproj.filters +35 -0
  123. package/libusb/msvc/{fxload_2010.vcxproj → fxload_2019.vcxproj} +29 -6
  124. package/libusb/msvc/fxload_2019.vcxproj.filters +35 -0
  125. package/libusb/{examples → msvc}/getopt/getopt.c +0 -0
  126. package/libusb/{examples → msvc}/getopt/getopt.h +0 -0
  127. package/libusb/{examples → msvc}/getopt/getopt1.c +0 -0
  128. package/libusb/msvc/getopt_2013.vcxproj +4 -5
  129. package/libusb/msvc/getopt_2013.vcxproj.filters +26 -0
  130. package/libusb/msvc/getopt_2015.vcxproj +4 -4
  131. package/libusb/msvc/getopt_2015.vcxproj.filters +26 -0
  132. package/libusb/msvc/getopt_2017.vcxproj +4 -10
  133. package/libusb/msvc/getopt_2017.vcxproj.filters +26 -0
  134. package/libusb/msvc/{getopt_2012.vcxproj → getopt_2019.vcxproj} +25 -6
  135. package/libusb/msvc/getopt_2019.vcxproj.filters +26 -0
  136. package/libusb/msvc/hotplugtest_2013.vcxproj +6 -3
  137. package/libusb/msvc/hotplugtest_2013.vcxproj.filters +23 -0
  138. package/libusb/msvc/hotplugtest_2015.vcxproj +6 -3
  139. package/libusb/msvc/hotplugtest_2015.vcxproj.filters +23 -0
  140. package/libusb/msvc/hotplugtest_2017.vcxproj +6 -7
  141. package/libusb/msvc/hotplugtest_2017.vcxproj.filters +23 -0
  142. package/libusb/msvc/hotplugtest_2019.vcxproj +105 -0
  143. package/libusb/msvc/hotplugtest_2019.vcxproj.filters +23 -0
  144. package/libusb/msvc/libusb_2013.sln +50 -20
  145. package/libusb/msvc/libusb_2015.sln +51 -21
  146. package/libusb/msvc/libusb_2017.sln +90 -36
  147. package/libusb/msvc/libusb_2019.sln +240 -0
  148. package/libusb/msvc/libusb_dll_2013.vcxproj +6 -9
  149. package/libusb/msvc/libusb_dll_2013.vcxproj.filters +94 -0
  150. package/libusb/msvc/libusb_dll_2015.vcxproj +6 -8
  151. package/libusb/msvc/libusb_dll_2015.vcxproj.filters +94 -0
  152. package/libusb/msvc/libusb_dll_2017.vcxproj +6 -16
  153. package/libusb/msvc/libusb_dll_2017.vcxproj.filters +94 -0
  154. package/libusb/msvc/{libusb_dll_2010.vcxproj → libusb_dll_2019.vcxproj} +27 -9
  155. package/libusb/msvc/libusb_dll_2019.vcxproj.filters +94 -0
  156. package/libusb/msvc/libusb_static_2013.vcxproj +5 -9
  157. package/libusb/msvc/libusb_static_2013.vcxproj.filters +80 -0
  158. package/libusb/msvc/libusb_static_2015.vcxproj +5 -8
  159. package/libusb/msvc/libusb_static_2015.vcxproj.filters +80 -0
  160. package/libusb/msvc/libusb_static_2017.vcxproj +5 -8
  161. package/libusb/msvc/libusb_static_2017.vcxproj.filters +80 -0
  162. package/libusb/msvc/{libusb_static_2010.vcxproj → libusb_static_2019.vcxproj} +26 -9
  163. package/libusb/msvc/libusb_static_2019.vcxproj.filters +80 -0
  164. package/libusb/msvc/listdevs_2013.vcxproj +6 -3
  165. package/libusb/msvc/listdevs_2013.vcxproj.filters +23 -0
  166. package/libusb/msvc/listdevs_2015.vcxproj +6 -3
  167. package/libusb/msvc/listdevs_2015.vcxproj.filters +23 -0
  168. package/libusb/msvc/listdevs_2017.vcxproj +6 -7
  169. package/libusb/msvc/listdevs_2017.vcxproj.filters +23 -0
  170. package/libusb/msvc/listdevs_2019.vcxproj +105 -0
  171. package/libusb/msvc/listdevs_2019.vcxproj.filters +23 -0
  172. package/libusb/msvc/{listdevs_2012.vcxproj → sam3u_benchmark_2013.vcxproj} +13 -9
  173. package/libusb/msvc/sam3u_benchmark_2013.vcxproj.filters +26 -0
  174. package/libusb/msvc/{hotplugtest_2010.vcxproj → sam3u_benchmark_2015.vcxproj} +13 -8
  175. package/libusb/msvc/sam3u_benchmark_2015.vcxproj.filters +26 -0
  176. package/libusb/msvc/sam3u_benchmark_2017.vcxproj +106 -0
  177. package/libusb/msvc/sam3u_benchmark_2017.vcxproj.filters +26 -0
  178. package/libusb/msvc/sam3u_benchmark_2019.vcxproj +106 -0
  179. package/libusb/msvc/sam3u_benchmark_2019.vcxproj.filters +26 -0
  180. package/libusb/msvc/stress_2013.vcxproj +4 -2
  181. package/libusb/msvc/stress_2013.vcxproj.filters +32 -0
  182. package/libusb/msvc/stress_2015.vcxproj +4 -2
  183. package/libusb/msvc/stress_2015.vcxproj.filters +32 -0
  184. package/libusb/msvc/stress_2017.vcxproj +4 -6
  185. package/libusb/msvc/stress_2017.vcxproj.filters +32 -0
  186. package/libusb/msvc/{stress_2010.vcxproj → stress_2019.vcxproj} +26 -4
  187. package/libusb/msvc/stress_2019.vcxproj.filters +32 -0
  188. package/libusb/msvc/testlibusb_2013.vcxproj +6 -3
  189. package/libusb/msvc/testlibusb_2013.vcxproj.filters +23 -0
  190. package/libusb/msvc/testlibusb_2015.vcxproj +6 -3
  191. package/libusb/msvc/testlibusb_2015.vcxproj.filters +23 -0
  192. package/libusb/msvc/testlibusb_2017.vcxproj +6 -7
  193. package/libusb/msvc/testlibusb_2017.vcxproj.filters +23 -0
  194. package/libusb/msvc/{testlibusb_2010.vcxproj → testlibusb_2019.vcxproj} +28 -5
  195. package/libusb/msvc/testlibusb_2019.vcxproj.filters +23 -0
  196. package/libusb/msvc/xusb_2013.vcxproj +6 -3
  197. package/libusb/msvc/xusb_2013.vcxproj.filters +23 -0
  198. package/libusb/msvc/xusb_2015.vcxproj +6 -3
  199. package/libusb/msvc/xusb_2015.vcxproj.filters +23 -0
  200. package/libusb/msvc/xusb_2017.vcxproj +6 -7
  201. package/libusb/msvc/xusb_2017.vcxproj.filters +23 -0
  202. package/libusb/msvc/{xusb_2010.vcxproj → xusb_2019.vcxproj} +28 -5
  203. package/libusb/msvc/xusb_2019.vcxproj.filters +23 -0
  204. package/libusb/tests/Makefile.am +13 -1
  205. package/libusb/tests/libusb_testlib.h +12 -43
  206. package/libusb/tests/stress.c +59 -50
  207. package/libusb/tests/testlib.c +78 -171
  208. package/libusb/tests/umockdev.c +1175 -0
  209. package/libusb.gypi +10 -11
  210. package/package.json +2 -2
  211. package/prebuilds/android-arm/node.napi.armv7.node +0 -0
  212. package/prebuilds/android-arm64/node.napi.armv8.node +0 -0
  213. package/prebuilds/darwin-x64+arm64/node.napi.node +0 -0
  214. package/prebuilds/linux-arm/node.napi.armv6.node +0 -0
  215. package/prebuilds/linux-arm/node.napi.armv7.node +0 -0
  216. package/prebuilds/linux-arm64/node.napi.armv8.node +0 -0
  217. package/prebuilds/linux-ia32/node.napi.node +0 -0
  218. package/prebuilds/linux-x64/node.napi.glibc.node +0 -0
  219. package/prebuilds/linux-x64/node.napi.musl.node +0 -0
  220. package/prebuilds/win32-ia32/node.napi.node +0 -0
  221. package/prebuilds/win32-x64/node.napi.node +0 -0
  222. package/src/device.cc +12 -7
  223. package/src/node_usb.cc +10 -0
  224. package/test/usb.coffee +6 -0
  225. package/tsc/index.ts +2 -0
  226. package/tsc/usb/bindings.ts +5 -0
  227. package/tsc/usb/device.ts +6 -0
  228. package/tsc/usb/index.ts +5 -8
  229. package/tsc/webusb/webusb-device.ts +12 -8
  230. package/libusb/.private/bd.cmd +0 -89
  231. package/libusb/.private/bwince.cmd +0 -57
  232. package/libusb/.private/wbs_wince.txt +0 -42
  233. package/libusb/Brewfile +0 -4
  234. package/libusb/appveyor_cygwin.bat +0 -11
  235. package/libusb/appveyor_minGW.bat +0 -19
  236. package/libusb/doc/Makefile.am +0 -9
  237. package/libusb/examples/dpfp_threaded.c +0 -557
  238. package/libusb/libusb/hotplug.h +0 -99
  239. package/libusb/libusb/os/poll_posix.c +0 -84
  240. package/libusb/libusb/os/poll_posix.h +0 -14
  241. package/libusb/libusb/os/poll_windows.c +0 -447
  242. package/libusb/libusb/os/poll_windows.h +0 -98
  243. package/libusb/libusb/os/wince_usb.c +0 -888
  244. package/libusb/libusb/os/wince_usb.h +0 -126
  245. package/libusb/libusb/os/windows_nt_common.c +0 -1010
  246. package/libusb/libusb/os/windows_nt_common.h +0 -110
  247. package/libusb/libusb/os/windows_nt_shared_types.h +0 -147
  248. package/libusb/msvc/appveyor.bat +0 -27
  249. package/libusb/msvc/ddk_build.cmd +0 -219
  250. package/libusb/msvc/errno.h +0 -102
  251. package/libusb/msvc/fxload_sources +0 -23
  252. package/libusb/msvc/getopt_2005.vcproj +0 -288
  253. package/libusb/msvc/getopt_2010.vcxproj +0 -72
  254. package/libusb/msvc/getopt_sources +0 -24
  255. package/libusb/msvc/hotplugtest_sources +0 -20
  256. package/libusb/msvc/inttypes.h +0 -295
  257. package/libusb/msvc/libusb.dsw +0 -71
  258. package/libusb/msvc/libusb_2005.sln +0 -95
  259. package/libusb/msvc/libusb_2010.sln +0 -105
  260. package/libusb/msvc/libusb_2012.sln +0 -105
  261. package/libusb/msvc/libusb_dll.dsp +0 -194
  262. package/libusb/msvc/libusb_dll_2005.vcproj +0 -464
  263. package/libusb/msvc/libusb_dll_2012.vcxproj +0 -107
  264. package/libusb/msvc/libusb_dll_wince.vcproj +0 -1251
  265. package/libusb/msvc/libusb_sources +0 -43
  266. package/libusb/msvc/libusb_static.dsp +0 -174
  267. package/libusb/msvc/libusb_static_2005.vcproj +0 -390
  268. package/libusb/msvc/libusb_static_2012.vcxproj +0 -98
  269. package/libusb/msvc/libusb_static_wince.vcproj +0 -1179
  270. package/libusb/msvc/libusb_wince.sln +0 -246
  271. package/libusb/msvc/listdevs.dsp +0 -103
  272. package/libusb/msvc/listdevs_2005.vcproj +0 -360
  273. package/libusb/msvc/listdevs_sources +0 -20
  274. package/libusb/msvc/listdevs_wince.vcproj +0 -1120
  275. package/libusb/msvc/missing.c +0 -80
  276. package/libusb/msvc/stdint.h +0 -256
  277. package/libusb/msvc/stress_2005.vcproj +0 -390
  278. package/libusb/msvc/stress_2012.vcxproj +0 -87
  279. package/libusb/msvc/stress_sources +0 -21
  280. package/libusb/msvc/stress_wince.vcproj +0 -1128
  281. package/libusb/msvc/testlibusb_2012.vcxproj +0 -83
  282. package/libusb/msvc/testlibusb_sources +0 -20
  283. package/libusb/msvc/xusb.dsp +0 -102
  284. package/libusb/msvc/xusb_2005.vcproj +0 -344
  285. package/libusb/msvc/xusb_2012.vcxproj +0 -83
  286. package/libusb/msvc/xusb_sources +0 -20
  287. package/libusb/msvc/xusb_wince.vcproj +0 -1120
  288. package/libusb/travis-autogen.sh +0 -39
@@ -20,35 +20,20 @@
20
20
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
21
  */
22
22
 
23
- #pragma once
23
+ #ifndef LIBUSB_WINDOWS_WINUSB_H
24
+ #define LIBUSB_WINDOWS_WINUSB_H
24
25
 
25
- #include "windows_common.h"
26
- #include "windows_nt_common.h"
26
+ #include <devioctl.h>
27
+ #include <guiddef.h>
27
28
 
28
- #if defined(_MSC_VER)
29
- // disable /W4 MSVC warnings that are benign
30
- #pragma warning(disable:4100) // unreferenced formal parameter
31
- #pragma warning(disable:4127) // conditional expression is constant
32
- #pragma warning(disable:4201) // nameless struct/union
33
- #pragma warning(disable:4214) // bit field types other than int
34
- #pragma warning(disable:4996) // deprecated API calls
35
- #pragma warning(disable:28159) // more deprecated API calls
36
- #endif
37
-
38
- // Missing from MSVC6 setupapi.h
39
- #ifndef SPDRP_ADDRESS
40
- #define SPDRP_ADDRESS 28
41
- #endif
42
- #ifndef SPDRP_INSTALL_STATE
43
- #define SPDRP_INSTALL_STATE 34
44
- #endif
29
+ #include "windows_common.h"
45
30
 
46
31
  #define MAX_CTRL_BUFFER_LENGTH 4096
47
32
  #define MAX_USB_STRING_LENGTH 128
48
33
  #define MAX_HID_REPORT_SIZE 1024
49
34
  #define MAX_HID_DESCRIPTOR_SIZE 256
50
35
  #define MAX_GUID_STRING_LENGTH 40
51
- #define MAX_PATH_LENGTH 128
36
+ #define MAX_PATH_LENGTH 256
52
37
  #define MAX_KEY_LENGTH 256
53
38
  #define LIST_SEPARATOR ';'
54
39
 
@@ -60,19 +45,13 @@
60
45
  // http://msdn.microsoft.com/en-us/library/ff545978.aspx
61
46
  // http://msdn.microsoft.com/en-us/library/ff545972.aspx
62
47
  // http://msdn.microsoft.com/en-us/library/ff545982.aspx
63
- #ifndef GUID_DEVINTERFACE_USB_HOST_CONTROLLER
64
- const GUID GUID_DEVINTERFACE_USB_HOST_CONTROLLER = {0x3ABF6F2D, 0x71C4, 0x462A, {0x8A, 0x92, 0x1E, 0x68, 0x61, 0xE6, 0xAF, 0x27}};
65
- #endif
66
- #ifndef GUID_DEVINTERFACE_USB_DEVICE
67
- const GUID GUID_DEVINTERFACE_USB_DEVICE = {0xA5DCBF10, 0x6530, 0x11D2, {0x90, 0x1F, 0x00, 0xC0, 0x4F, 0xB9, 0x51, 0xED}};
68
- #endif
69
- #ifndef GUID_DEVINTERFACE_USB_HUB
70
- const GUID GUID_DEVINTERFACE_USB_HUB = {0xF18A0E88, 0xC30C, 0x11D0, {0x88, 0x15, 0x00, 0xA0, 0xC9, 0x06, 0xBE, 0xD8}};
71
- #endif
72
- #ifndef GUID_DEVINTERFACE_LIBUSB0_FILTER
73
- const GUID GUID_DEVINTERFACE_LIBUSB0_FILTER = {0xF9F3FF14, 0xAE21, 0x48A0, {0x8A, 0x25, 0x80, 0x11, 0xA7, 0xA9, 0x31, 0xD9}};
74
- #endif
48
+ static const GUID GUID_DEVINTERFACE_USB_HOST_CONTROLLER = {0x3ABF6F2D, 0x71C4, 0x462A, {0x8A, 0x92, 0x1E, 0x68, 0x61, 0xE6, 0xAF, 0x27}};
49
+ static const GUID GUID_DEVINTERFACE_USB_HUB = {0xF18A0E88, 0xC30C, 0x11D0, {0x88, 0x15, 0x00, 0xA0, 0xC9, 0x06, 0xBE, 0xD8}};
50
+ static const GUID GUID_DEVINTERFACE_USB_DEVICE = {0xA5DCBF10, 0x6530, 0x11D2, {0x90, 0x1F, 0x00, 0xC0, 0x4F, 0xB9, 0x51, 0xED}};
51
+ static const GUID GUID_DEVINTERFACE_LIBUSB0_FILTER = {0xF9F3FF14, 0xAE21, 0x48A0, {0x8A, 0x25, 0x80, 0x11, 0xA7, 0xA9, 0x31, 0xD9}};
75
52
 
53
+ // The following define MUST be == sizeof(USB_DESCRIPTOR_REQUEST)
54
+ #define USB_DESCRIPTOR_REQUEST_SIZE 12U
76
55
 
77
56
  /*
78
57
  * Multiple USB API backend support
@@ -97,28 +76,27 @@ struct windows_usb_api_backend {
97
76
  const char * const designation;
98
77
  const char * const * const driver_name_list; // Driver name, without .sys, e.g. "usbccgp"
99
78
  const uint8_t nb_driver_names;
100
- int (*init)(struct libusb_context *ctx);
79
+ bool (*init)(struct libusb_context *ctx);
101
80
  void (*exit)(void);
102
81
  int (*open)(int sub_api, struct libusb_device_handle *dev_handle);
103
82
  void (*close)(int sub_api, struct libusb_device_handle *dev_handle);
104
- int (*configure_endpoints)(int sub_api, struct libusb_device_handle *dev_handle, int iface);
105
- int (*claim_interface)(int sub_api, struct libusb_device_handle *dev_handle, int iface);
106
- int (*set_interface_altsetting)(int sub_api, struct libusb_device_handle *dev_handle, int iface, int altsetting);
107
- int (*release_interface)(int sub_api, struct libusb_device_handle *dev_handle, int iface);
83
+ int (*configure_endpoints)(int sub_api, struct libusb_device_handle *dev_handle, uint8_t iface);
84
+ int (*claim_interface)(int sub_api, struct libusb_device_handle *dev_handle, uint8_t iface);
85
+ int (*set_interface_altsetting)(int sub_api, struct libusb_device_handle *dev_handle, uint8_t iface, uint8_t altsetting);
86
+ int (*release_interface)(int sub_api, struct libusb_device_handle *dev_handle, uint8_t iface);
108
87
  int (*clear_halt)(int sub_api, struct libusb_device_handle *dev_handle, unsigned char endpoint);
109
88
  int (*reset_device)(int sub_api, struct libusb_device_handle *dev_handle);
110
89
  int (*submit_bulk_transfer)(int sub_api, struct usbi_transfer *itransfer);
111
90
  int (*submit_iso_transfer)(int sub_api, struct usbi_transfer *itransfer);
112
91
  int (*submit_control_transfer)(int sub_api, struct usbi_transfer *itransfer);
113
- int (*abort_control)(int sub_api, struct usbi_transfer *itransfer);
114
- int (*abort_transfers)(int sub_api, struct usbi_transfer *itransfer);
115
- int (*copy_transfer_data)(int sub_api, struct usbi_transfer *itransfer, uint32_t io_size);
92
+ int (*cancel_transfer)(int sub_api, struct usbi_transfer *itransfer);
93
+ enum libusb_transfer_status (*copy_transfer_data)(int sub_api, struct usbi_transfer *itransfer, DWORD length);
116
94
  };
117
95
 
118
96
  extern const struct windows_usb_api_backend usb_api_backend[USB_API_MAX];
119
97
 
120
98
  #define PRINT_UNSUPPORTED_API(fname) \
121
- usbi_dbg("unsupported API call for '%s' " \
99
+ usbi_dbg(NULL, "unsupported API call for '%s' " \
122
100
  "(unrecognized device driver)", #fname)
123
101
 
124
102
  #define CHECK_SUPPORTED_API(apip, fname) \
@@ -156,11 +134,6 @@ struct libusb_hid_descriptor {
156
134
  #define LIBUSB_REQ_IN(request_type) ((request_type) & LIBUSB_ENDPOINT_IN)
157
135
  #define LIBUSB_REQ_OUT(request_type) (!LIBUSB_REQ_IN(request_type))
158
136
 
159
- #ifndef CTL_CODE
160
- #define CTL_CODE(DeviceType, Function, Method, Access) \
161
- (((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method))
162
- #endif
163
-
164
137
  // The following are used for HID reports IOCTLs
165
138
  #define HID_IN_CTL_CODE(id) \
166
139
  CTL_CODE(FILE_DEVICE_KEYBOARD, (id), METHOD_IN_DIRECT, FILE_ANY_ACCESS)
@@ -202,56 +175,48 @@ struct hid_device_priv {
202
175
  uint8_t string_index[3]; // man, prod, ser
203
176
  };
204
177
 
205
- static inline struct winusb_device_priv *_device_priv(struct libusb_device *dev)
206
- {
207
- return (struct winusb_device_priv *)dev->os_priv;
208
- }
209
-
210
178
  static inline struct winusb_device_priv *winusb_device_priv_init(struct libusb_device *dev)
211
179
  {
212
- struct winusb_device_priv *p = _device_priv(dev);
180
+ struct winusb_device_priv *priv = usbi_get_device_priv(dev);
213
181
  int i;
214
182
 
215
- p->apib = &usb_api_backend[USB_API_UNSUPPORTED];
216
- p->sub_api = SUB_API_NOTSET;
183
+ priv->apib = &usb_api_backend[USB_API_UNSUPPORTED];
184
+ priv->sub_api = SUB_API_NOTSET;
217
185
  for (i = 0; i < USB_MAXINTERFACES; i++) {
218
- p->usb_interface[i].apib = &usb_api_backend[USB_API_UNSUPPORTED];
219
- p->usb_interface[i].sub_api = SUB_API_NOTSET;
186
+ priv->usb_interface[i].apib = &usb_api_backend[USB_API_UNSUPPORTED];
187
+ priv->usb_interface[i].sub_api = SUB_API_NOTSET;
220
188
  }
221
189
 
222
- return p;
190
+ return priv;
223
191
  }
224
192
 
225
193
  static inline void winusb_device_priv_release(struct libusb_device *dev)
226
194
  {
227
- struct winusb_device_priv *p = _device_priv(dev);
195
+ struct winusb_device_priv *priv = usbi_get_device_priv(dev);
228
196
  int i;
229
197
 
230
- free(p->dev_id);
231
- free(p->path);
232
- if ((dev->num_configurations > 0) && (p->config_descriptor != NULL)) {
233
- for (i = 0; i < dev->num_configurations; i++)
234
- free(p->config_descriptor[i]);
198
+ free(priv->dev_id);
199
+ free(priv->path);
200
+ if ((dev->device_descriptor.bNumConfigurations > 0) && (priv->config_descriptor != NULL)) {
201
+ for (i = 0; i < dev->device_descriptor.bNumConfigurations; i++) {
202
+ if (priv->config_descriptor[i] == NULL)
203
+ continue;
204
+ free((UCHAR *)priv->config_descriptor[i] - USB_DESCRIPTOR_REQUEST_SIZE);
205
+ }
235
206
  }
236
- free(p->config_descriptor);
237
- free(p->hid);
207
+ free(priv->config_descriptor);
208
+ free(priv->hid);
238
209
  for (i = 0; i < USB_MAXINTERFACES; i++) {
239
- free(p->usb_interface[i].path);
240
- free(p->usb_interface[i].endpoint);
210
+ free(priv->usb_interface[i].path);
211
+ free(priv->usb_interface[i].endpoint);
241
212
  }
242
213
  }
243
214
 
244
- static inline struct winusb_device_handle_priv *_device_handle_priv(
245
- struct libusb_device_handle *handle)
246
- {
247
- return (struct winusb_device_handle_priv *)handle->os_priv;
248
- }
249
-
250
215
  // used to match a device driver (including filter drivers) against a supported API
251
216
  struct driver_lookup {
252
217
  char list[MAX_KEY_LENGTH + 1]; // REG_MULTI_SZ list of services (driver) names
253
218
  const DWORD reg_prop; // SPDRP registry key to use to retrieve list
254
- const char* designation; // internal designation (for debug output)
219
+ const char *designation; // internal designation (for debug output)
255
220
  };
256
221
 
257
222
  /*
@@ -271,13 +236,9 @@ DLL_DECLARE_FUNC(WINAPI, CONFIGRET, CM_Get_Child, (PDEVINST, DEVINST, ULONG));
271
236
 
272
237
  /* AdvAPI32 dependencies */
273
238
  DLL_DECLARE_HANDLE(AdvAPI32);
274
- DLL_DECLARE_FUNC_PREFIXED(WINAPI, LONG, p, RegQueryValueExW, (HKEY, LPCWSTR, LPDWORD, LPDWORD, LPBYTE, LPDWORD));
239
+ DLL_DECLARE_FUNC_PREFIXED(WINAPI, LONG, p, RegQueryValueExA, (HKEY, LPCSTR, LPDWORD, LPDWORD, LPBYTE, LPDWORD));
275
240
  DLL_DECLARE_FUNC_PREFIXED(WINAPI, LONG, p, RegCloseKey, (HKEY));
276
241
 
277
- /* OLE32 dependency */
278
- DLL_DECLARE_HANDLE(OLE32);
279
- DLL_DECLARE_FUNC_PREFIXED(WINAPI, HRESULT, p, IIDFromString, (LPCOLESTR, LPIID));
280
-
281
242
  /* SetupAPI dependencies */
282
243
  DLL_DECLARE_HANDLE(SetupAPI);
283
244
  DLL_DECLARE_FUNC_PREFIXED(WINAPI, HDEVINFO, p, SetupDiGetClassDevsA, (LPCGUID, PCSTR, HWND, DWORD));
@@ -294,24 +255,19 @@ DLL_DECLARE_FUNC_PREFIXED(WINAPI, BOOL, p, SetupDiDestroyDeviceInfoList, (HDEVIN
294
255
  DLL_DECLARE_FUNC_PREFIXED(WINAPI, HKEY, p, SetupDiOpenDevRegKey, (HDEVINFO, PSP_DEVINFO_DATA, DWORD, DWORD, DWORD, REGSAM));
295
256
  DLL_DECLARE_FUNC_PREFIXED(WINAPI, HKEY, p, SetupDiOpenDeviceInterfaceRegKey, (HDEVINFO, PSP_DEVICE_INTERFACE_DATA, DWORD, DWORD));
296
257
 
258
+ #define FILE_DEVICE_USB FILE_DEVICE_UNKNOWN
297
259
 
298
- #ifndef USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION
260
+ #define USB_GET_NODE_INFORMATION 258
299
261
  #define USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION 260
300
- #endif
301
- #ifndef USB_GET_NODE_CONNECTION_INFORMATION_EX
302
262
  #define USB_GET_NODE_CONNECTION_INFORMATION_EX 274
303
- #endif
304
- #ifndef USB_GET_NODE_CONNECTION_INFORMATION_EX_V2
305
263
  #define USB_GET_NODE_CONNECTION_INFORMATION_EX_V2 279
306
- #endif
307
-
308
- #ifndef FILE_DEVICE_USB
309
- #define FILE_DEVICE_USB FILE_DEVICE_UNKNOWN
310
- #endif
311
264
 
312
265
  #define USB_CTL_CODE(id) \
313
266
  CTL_CODE(FILE_DEVICE_USB, (id), METHOD_BUFFERED, FILE_ANY_ACCESS)
314
267
 
268
+ #define IOCTL_USB_GET_NODE_INFORMATION \
269
+ USB_CTL_CODE(USB_GET_NODE_INFORMATION)
270
+
315
271
  #define IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION \
316
272
  USB_CTL_CODE(USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION)
317
273
 
@@ -321,7 +277,7 @@ DLL_DECLARE_FUNC_PREFIXED(WINAPI, HKEY, p, SetupDiOpenDeviceInterfaceRegKey, (HD
321
277
  #define IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX_V2 \
322
278
  USB_CTL_CODE(USB_GET_NODE_CONNECTION_INFORMATION_EX_V2)
323
279
 
324
- typedef enum USB_CONNECTION_STATUS {
280
+ typedef enum _USB_CONNECTION_STATUS {
325
281
  NoDeviceConnected,
326
282
  DeviceConnected,
327
283
  DeviceFailedEnumeration,
@@ -330,17 +286,56 @@ typedef enum USB_CONNECTION_STATUS {
330
286
  DeviceNotEnoughPower,
331
287
  DeviceNotEnoughBandwidth,
332
288
  DeviceHubNestedTooDeeply,
333
- DeviceInLegacyHub
334
- } USB_CONNECTION_STATUS, *PUSB_CONNECTION_STATUS;
335
-
336
- typedef enum USB_HUB_NODE {
289
+ DeviceInLegacyHub,
290
+ DeviceEnumerating,
291
+ DeviceReset
292
+ } USB_CONNECTION_STATUS;
293
+
294
+ typedef enum _USB_DEVICE_SPEED {
295
+ UsbLowSpeed = 0,
296
+ UsbFullSpeed,
297
+ UsbHighSpeed,
298
+ UsbSuperSpeed,
299
+ UsbSuperSpeedPlus // Not in Microsoft headers
300
+ } USB_DEVICE_SPEED;
301
+
302
+ typedef enum _USB_HUB_NODE {
337
303
  UsbHub,
338
304
  UsbMIParent
339
305
  } USB_HUB_NODE;
340
306
 
307
+ #if defined(_MSC_VER)
308
+ // disable /W4 MSVC warnings that are benign
309
+ #pragma warning(push)
310
+ #pragma warning(disable:4214) // bit field types other than int
311
+ #endif
312
+
341
313
  // Most of the structures below need to be packed
342
314
  #include <pshpack1.h>
343
315
 
316
+ typedef struct _USB_HUB_DESCRIPTOR {
317
+ UCHAR bDescriptorLength;
318
+ UCHAR bDescriptorType;
319
+ UCHAR bNumberOfPorts;
320
+ USHORT wHubCharacteristics;
321
+ UCHAR bPowerOnToPowerGood;
322
+ UCHAR bHubControlCurrent;
323
+ UCHAR bRemoveAndPowerMask[64];
324
+ } USB_HUB_DESCRIPTOR, *PUSB_HUB_DESCRIPTOR;
325
+
326
+ typedef struct _USB_HUB_INFORMATION {
327
+ USB_HUB_DESCRIPTOR HubDescriptor;
328
+ BOOLEAN HubIsBusPowered;
329
+ } USB_HUB_INFORMATION, *PUSB_HUB_INFORMATION;
330
+
331
+ typedef struct _USB_NODE_INFORMATION {
332
+ USB_HUB_NODE NodeType;
333
+ union {
334
+ USB_HUB_INFORMATION HubInformation;
335
+ // USB_MI_PARENT_INFORMATION MiParentInformation;
336
+ } u;
337
+ } USB_NODE_INFORMATION, *PUSB_NODE_INFORMATION;
338
+
344
339
  typedef struct _USB_DESCRIPTOR_REQUEST {
345
340
  ULONG ConnectionIndex;
346
341
  struct {
@@ -412,6 +407,11 @@ typedef struct _USB_NODE_CONNECTION_INFORMATION_EX_V2 {
412
407
 
413
408
  #include <poppack.h>
414
409
 
410
+ #if defined(_MSC_VER)
411
+ // Restore original warnings
412
+ #pragma warning(pop)
413
+ #endif
414
+
415
415
  /* winusb.dll interface */
416
416
 
417
417
  /* pipe policies */
@@ -426,6 +426,12 @@ typedef struct _USB_NODE_CONNECTION_INFORMATION_EX_V2 {
426
426
  /* libusbK */
427
427
  #define ISO_ALWAYS_START_ASAP 0x21
428
428
 
429
+ typedef struct _USBD_ISO_PACKET_DESCRIPTOR {
430
+ ULONG Offset;
431
+ ULONG Length;
432
+ USBD_STATUS Status;
433
+ } USBD_ISO_PACKET_DESCRIPTOR, *PUSBD_ISO_PACKET_DESCRIPTOR;
434
+
429
435
  typedef enum _USBD_PIPE_TYPE {
430
436
  UsbdPipeTypeControl,
431
437
  UsbdPipeTypeIsochronous,
@@ -433,6 +439,14 @@ typedef enum _USBD_PIPE_TYPE {
433
439
  UsbdPipeTypeInterrupt
434
440
  } USBD_PIPE_TYPE;
435
441
 
442
+ typedef struct {
443
+ USBD_PIPE_TYPE PipeType;
444
+ UCHAR PipeId;
445
+ USHORT MaximumPacketSize;
446
+ UCHAR Interval;
447
+ ULONG MaximumBytesPerInterval;
448
+ } WINUSB_PIPE_INFORMATION_EX, *PWINUSB_PIPE_INFORMATION_EX;
449
+
436
450
  #include <pshpack1.h>
437
451
 
438
452
  typedef struct _WINUSB_SETUP_PACKET {
@@ -445,7 +459,8 @@ typedef struct _WINUSB_SETUP_PACKET {
445
459
 
446
460
  #include <poppack.h>
447
461
 
448
- typedef void *WINUSB_INTERFACE_HANDLE, *PWINUSB_INTERFACE_HANDLE;
462
+ typedef PVOID WINUSB_INTERFACE_HANDLE, *PWINUSB_INTERFACE_HANDLE;
463
+ typedef PVOID WINUSB_ISOCH_BUFFER_HANDLE, *PWINUSB_ISOCH_BUFFER_HANDLE;
449
464
 
450
465
  typedef BOOL (WINAPI *WinUsb_AbortPipe_t)(
451
466
  WINUSB_INTERFACE_HANDLE InterfaceHandle,
@@ -475,6 +490,21 @@ typedef BOOL (WINAPI *WinUsb_Initialize_t)(
475
490
  HANDLE DeviceHandle,
476
491
  PWINUSB_INTERFACE_HANDLE InterfaceHandle
477
492
  );
493
+ typedef BOOL (WINAPI *WinUsb_QueryPipeEx_t)(
494
+ WINUSB_INTERFACE_HANDLE InterfaceHandle,
495
+ UCHAR AlternateInterfaceHandle,
496
+ UCHAR PipeIndex,
497
+ PWINUSB_PIPE_INFORMATION_EX PipeInformationEx
498
+ );
499
+ typedef BOOL (WINAPI *WinUsb_ReadIsochPipeAsap_t)(
500
+ PWINUSB_ISOCH_BUFFER_HANDLE BufferHandle,
501
+ ULONG Offset,
502
+ ULONG Length,
503
+ BOOL ContinueStream,
504
+ ULONG NumberOfPackets,
505
+ PUSBD_ISO_PACKET_DESCRIPTOR IsoPacketDescriptors,
506
+ LPOVERLAPPED Overlapped
507
+ );
478
508
  typedef BOOL (WINAPI *WinUsb_ReadPipe_t)(
479
509
  WINUSB_INTERFACE_HANDLE InterfaceHandle,
480
510
  UCHAR PipeID,
@@ -483,8 +513,12 @@ typedef BOOL (WINAPI *WinUsb_ReadPipe_t)(
483
513
  PULONG LengthTransferred,
484
514
  LPOVERLAPPED Overlapped
485
515
  );
486
- typedef BOOL (WINAPI *WinUsb_ResetDevice_t)(
487
- WINUSB_INTERFACE_HANDLE InterfaceHandle
516
+ typedef BOOL (WINAPI *WinUsb_RegisterIsochBuffer_t)(
517
+ WINUSB_INTERFACE_HANDLE InterfaceHandle,
518
+ UCHAR PipeID,
519
+ PVOID Buffer,
520
+ ULONG BufferLength,
521
+ PWINUSB_ISOCH_BUFFER_HANDLE BufferHandle
488
522
  );
489
523
  typedef BOOL (WINAPI *WinUsb_ResetPipe_t)(
490
524
  WINUSB_INTERFACE_HANDLE InterfaceHandle,
@@ -501,29 +535,9 @@ typedef BOOL (WINAPI *WinUsb_SetPipePolicy_t)(
501
535
  ULONG ValueLength,
502
536
  PVOID Value
503
537
  );
504
- typedef BOOL (WINAPI *WinUsb_WritePipe_t)(
505
- WINUSB_INTERFACE_HANDLE InterfaceHandle,
506
- UCHAR PipeID,
507
- PUCHAR Buffer,
508
- ULONG BufferLength,
509
- PULONG LengthTransferred,
510
- LPOVERLAPPED Overlapped
511
- );
512
-
513
- typedef PVOID WINUSB_ISOCH_BUFFER_HANDLE, *PWINUSB_ISOCH_BUFFER_HANDLE;
514
-
515
- typedef BOOL (WINAPI *WinUsb_RegisterIsochBuffer_t)(
516
- WINUSB_INTERFACE_HANDLE InterfaceHandle,
517
- UCHAR PipeID,
518
- PVOID Buffer,
519
- ULONG BufferLength,
520
- PWINUSB_ISOCH_BUFFER_HANDLE BufferHandle
521
- );
522
-
523
538
  typedef BOOL (WINAPI *WinUsb_UnregisterIsochBuffer_t)(
524
539
  WINUSB_ISOCH_BUFFER_HANDLE BufferHandle
525
540
  );
526
-
527
541
  typedef BOOL (WINAPI *WinUsb_WriteIsochPipeAsap_t)(
528
542
  WINUSB_ISOCH_BUFFER_HANDLE BufferHandle,
529
543
  ULONG Offset,
@@ -531,37 +545,13 @@ typedef BOOL (WINAPI *WinUsb_WriteIsochPipeAsap_t)(
531
545
  BOOL ContinueStream,
532
546
  LPOVERLAPPED Overlapped
533
547
  );
534
-
535
- typedef LONG USBD_STATUS;
536
- typedef struct {
537
- ULONG Offset;
538
- ULONG Length;
539
- USBD_STATUS Status;
540
- } USBD_ISO_PACKET_DESCRIPTOR, *PUSBD_ISO_PACKET_DESCRIPTOR;
541
-
542
- typedef BOOL (WINAPI *WinUsb_ReadIsochPipeAsap_t)(
543
- PWINUSB_ISOCH_BUFFER_HANDLE BufferHandle,
544
- ULONG Offset,
545
- ULONG Length,
546
- BOOL ContinueStream,
547
- ULONG NumberOfPackets,
548
- PUSBD_ISO_PACKET_DESCRIPTOR IsoPacketDescriptors,
549
- LPOVERLAPPED Overlapped
550
- );
551
-
552
- typedef struct {
553
- USBD_PIPE_TYPE PipeType;
554
- UCHAR PipeId;
555
- USHORT MaximumPacketSize;
556
- UCHAR Interval;
557
- ULONG MaximumBytesPerInterval;
558
- } WINUSB_PIPE_INFORMATION_EX, *PWINUSB_PIPE_INFORMATION_EX;
559
-
560
- typedef BOOL (WINAPI *WinUsb_QueryPipeEx_t)(
548
+ typedef BOOL (WINAPI *WinUsb_WritePipe_t)(
561
549
  WINUSB_INTERFACE_HANDLE InterfaceHandle,
562
- UCHAR AlternateInterfaceHandle,
563
- UCHAR PipeIndex,
564
- PWINUSB_PIPE_INFORMATION_EX PipeInformationEx
550
+ UCHAR PipeID,
551
+ PUCHAR Buffer,
552
+ ULONG BufferLength,
553
+ PULONG LengthTransferred,
554
+ LPOVERLAPPED Overlapped
565
555
  );
566
556
 
567
557
  /* /!\ These must match the ones from the official libusbk.h */
@@ -611,15 +601,19 @@ typedef struct _KLIB_VERSION {
611
601
  } KLIB_VERSION, *PKLIB_VERSION;
612
602
 
613
603
  typedef BOOL (WINAPI *LibK_GetProcAddress_t)(
614
- PVOID *ProcAddress,
615
- ULONG DriverID,
616
- ULONG FunctionID
604
+ PVOID ProcAddress,
605
+ INT DriverID,
606
+ INT FunctionID
617
607
  );
618
608
 
619
609
  typedef VOID (WINAPI *LibK_GetVersion_t)(
620
610
  PKLIB_VERSION Version
621
611
  );
622
612
 
613
+ typedef BOOL (WINAPI *LibK_ResetDevice_t)(
614
+ WINUSB_INTERFACE_HANDLE InterfaceHandle
615
+ );
616
+
623
617
  //KISO_PACKET is equivalent of libusb_iso_packet_descriptor except uses absolute "offset" field instead of sequential Lengths
624
618
  typedef struct _KISO_PACKET {
625
619
  UINT offset;
@@ -642,7 +636,7 @@ typedef struct _KISO_CONTEXT {
642
636
  KISO_PACKET IsoPackets[0];
643
637
  } KISO_CONTEXT, *PKISO_CONTEXT;
644
638
 
645
- typedef BOOL(WINAPI *WinUsb_IsoReadPipe_t)(
639
+ typedef BOOL(WINAPI *LibK_IsoReadPipe_t)(
646
640
  WINUSB_INTERFACE_HANDLE InterfaceHandle,
647
641
  UCHAR PipeID,
648
642
  PUCHAR Buffer,
@@ -651,7 +645,7 @@ typedef BOOL(WINAPI *WinUsb_IsoReadPipe_t)(
651
645
  PKISO_CONTEXT IsoContext
652
646
  );
653
647
 
654
- typedef BOOL(WINAPI *WinUsb_IsoWritePipe_t)(
648
+ typedef BOOL(WINAPI *LibK_IsoWritePipe_t)(
655
649
  WINUSB_INTERFACE_HANDLE InterfaceHandle,
656
650
  UCHAR PipeID,
657
651
  PUCHAR Buffer,
@@ -661,8 +655,7 @@ typedef BOOL(WINAPI *WinUsb_IsoWritePipe_t)(
661
655
  );
662
656
 
663
657
  struct winusb_interface {
664
- bool initialized;
665
- bool CancelIoEx_supported;
658
+ HMODULE hDll;
666
659
  WinUsb_AbortPipe_t AbortPipe;
667
660
  WinUsb_ControlTransfer_t ControlTransfer;
668
661
  WinUsb_FlushPipe_t FlushPipe;
@@ -670,22 +663,27 @@ struct winusb_interface {
670
663
  WinUsb_GetAssociatedInterface_t GetAssociatedInterface;
671
664
  WinUsb_Initialize_t Initialize;
672
665
  WinUsb_ReadPipe_t ReadPipe;
673
- WinUsb_ResetDevice_t ResetDevice;
674
666
  WinUsb_ResetPipe_t ResetPipe;
675
667
  WinUsb_SetCurrentAlternateSetting_t SetCurrentAlternateSetting;
676
668
  WinUsb_SetPipePolicy_t SetPipePolicy;
677
669
  WinUsb_WritePipe_t WritePipe;
678
-
679
- // Isochoronous functions for LibUSBk sub api:
680
- WinUsb_IsoReadPipe_t IsoReadPipe;
681
- WinUsb_IsoWritePipe_t IsoWritePipe;
682
-
683
- // Isochronous functions for Microsoft WinUSB sub api (native WinUSB):
684
- WinUsb_RegisterIsochBuffer_t RegisterIsochBuffer;
685
- WinUsb_UnregisterIsochBuffer_t UnregisterIsochBuffer;
686
- WinUsb_WriteIsochPipeAsap_t WriteIsochPipeAsap;
687
- WinUsb_ReadIsochPipeAsap_t ReadIsochPipeAsap;
688
- WinUsb_QueryPipeEx_t QueryPipeEx;
670
+ union {
671
+ struct {
672
+ // Isochoronous functions for libusbK sub api:
673
+ LibK_IsoReadPipe_t IsoReadPipe;
674
+ LibK_IsoWritePipe_t IsoWritePipe;
675
+ // Reset device function for libusbK sub api:
676
+ LibK_ResetDevice_t ResetDevice;
677
+ };
678
+ struct {
679
+ // Isochronous functions for WinUSB sub api:
680
+ WinUsb_QueryPipeEx_t QueryPipeEx;
681
+ WinUsb_ReadIsochPipeAsap_t ReadIsochPipeAsap;
682
+ WinUsb_RegisterIsochBuffer_t RegisterIsochBuffer;
683
+ WinUsb_UnregisterIsochBuffer_t UnregisterIsochBuffer;
684
+ WinUsb_WriteIsochPipeAsap_t WriteIsochPipeAsap;
685
+ };
686
+ };
689
687
  };
690
688
 
691
689
  /* hid.dll interface */
@@ -781,3 +779,5 @@ DLL_DECLARE_FUNC(WINAPI, BOOL, HidD_SetNumInputBuffers, (HANDLE, ULONG));
781
779
  DLL_DECLARE_FUNC(WINAPI, BOOL, HidD_GetPhysicalDescriptor, (HANDLE, PVOID, ULONG));
782
780
  DLL_DECLARE_FUNC(WINAPI, BOOL, HidD_FlushQueue, (HANDLE));
783
781
  DLL_DECLARE_FUNC(WINAPI, BOOL, HidP_GetValueCaps, (HIDP_REPORT_TYPE, PHIDP_VALUE_CAPS, PULONG, PHIDP_PREPARSED_DATA));
782
+
783
+ #endif
@@ -17,22 +17,10 @@
17
17
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
18
  */
19
19
 
20
- #include <config.h>
21
-
22
- #include <locale.h>
23
- #include <stdlib.h>
24
- #include <string.h>
25
- #if defined(HAVE_STRINGS_H)
26
- #include <strings.h>
27
- #endif
28
-
29
20
  #include "libusbi.h"
30
21
 
31
- #if defined(_MSC_VER)
32
- #define strncasecmp _strnicmp
33
- #endif
34
-
35
- static size_t usbi_locale = 0;
22
+ #include <ctype.h>
23
+ #include <string.h>
36
24
 
37
25
  /** \ingroup libusb_misc
38
26
  * How to add a new \ref libusb_strerror() translation:
@@ -53,15 +41,15 @@ static size_t usbi_locale = 0;
53
41
  * "Success",
54
42
  * ...
55
43
  * "Other error",
56
- * }
44
+ * },
57
45
  * };\endcode </li>
58
46
  * <li> Translate each of the English messages from the section you copied into your language </li>
59
47
  * <li> Save the file (in UTF-8 format) and send it to \c libusb-devel\@lists.sourceforge.net </li>
60
48
  * </ol>
61
49
  */
62
50
 
63
- static const char* usbi_locale_supported[] = { "en", "nl", "fr", "ru", "de", "hu" };
64
- static const char* usbi_localized_errors[ARRAYSIZE(usbi_locale_supported)][LIBUSB_ERROR_COUNT] = {
51
+ static const char * const usbi_locale_supported[] = { "en", "nl", "fr", "ru", "de", "hu" };
52
+ static const char * const usbi_localized_errors[ARRAYSIZE(usbi_locale_supported)][LIBUSB_ERROR_COUNT] = {
65
53
  { /* English (en) */
66
54
  "Success",
67
55
  "Input/Output Error",
@@ -122,7 +110,6 @@ static const char* usbi_localized_errors[ARRAYSIZE(usbi_locale_supported)][LIBUS
122
110
  "Память исчерпана",
123
111
  "Операция не поддерживается данной платформой",
124
112
  "Неизвестная ошибка"
125
-
126
113
  }, { /* German (de) */
127
114
  "Erfolgreich",
128
115
  "Eingabe-/Ausgabefehler",
@@ -153,9 +140,11 @@ static const char* usbi_localized_errors[ARRAYSIZE(usbi_locale_supported)][LIBUS
153
140
  "Nincs elég memória",
154
141
  "A művelet nem támogatott ezen a rendszeren",
155
142
  "Általános hiba",
156
- }
143
+ },
157
144
  };
158
145
 
146
+ static const char * const (*usbi_error_strings)[LIBUSB_ERROR_COUNT] = &usbi_localized_errors[0];
147
+
159
148
  /** \ingroup libusb_misc
160
149
  * Set the language, and only the language, not the encoding! used for
161
150
  * translatable libusb messages.
@@ -165,7 +154,7 @@ static const char* usbi_localized_errors[ARRAYSIZE(usbi_locale_supported)][LIBUS
165
154
  * used, and only 2 letter ISO 639-1 codes are accepted for it, such as "de".
166
155
  * The optional region, country_region or codeset parts are ignored. This
167
156
  * means that functions which return translatable strings will NOT honor the
168
- * specified encoding.
157
+ * specified encoding.
169
158
  * All strings returned are encoded as UTF-8 strings.
170
159
  *
171
160
  * If libusb_setlocale() is not called, all messages will be in English.
@@ -190,19 +179,20 @@ int API_EXPORTED libusb_setlocale(const char *locale)
190
179
  {
191
180
  size_t i;
192
181
 
193
- if ( (locale == NULL) || (strlen(locale) < 2)
194
- || ((strlen(locale) > 2) && (locale[2] != '-') && (locale[2] != '_') && (locale[2] != '.')) )
182
+ if (!locale || strlen(locale) < 2
183
+ || (locale[2] != '\0' && locale[2] != '-' && locale[2] != '_' && locale[2] != '.'))
195
184
  return LIBUSB_ERROR_INVALID_PARAM;
196
185
 
197
- for (i=0; i<ARRAYSIZE(usbi_locale_supported); i++) {
198
- if (strncasecmp(usbi_locale_supported[i], locale, 2) == 0)
186
+ for (i = 0; i < ARRAYSIZE(usbi_locale_supported); i++) {
187
+ if (usbi_locale_supported[i][0] == tolower((unsigned char)locale[0])
188
+ && usbi_locale_supported[i][1] == tolower((unsigned char)locale[1]))
199
189
  break;
200
190
  }
201
- if (i >= ARRAYSIZE(usbi_locale_supported)) {
191
+
192
+ if (i == ARRAYSIZE(usbi_locale_supported))
202
193
  return LIBUSB_ERROR_NOT_FOUND;
203
- }
204
194
 
205
- usbi_locale = i;
195
+ usbi_error_strings = &usbi_localized_errors[i];
206
196
 
207
197
  return LIBUSB_SUCCESS;
208
198
  }
@@ -220,14 +210,14 @@ int API_EXPORTED libusb_setlocale(const char *locale)
220
210
  * \param errcode the error code whose description is desired
221
211
  * \returns a short description of the error code in UTF-8 encoding
222
212
  */
223
- DEFAULT_VISIBILITY const char* LIBUSB_CALL libusb_strerror(enum libusb_error errcode)
213
+ DEFAULT_VISIBILITY const char * LIBUSB_CALL libusb_strerror(int errcode)
224
214
  {
225
215
  int errcode_index = -errcode;
226
216
 
227
- if ((errcode_index < 0) || (errcode_index >= LIBUSB_ERROR_COUNT)) {
217
+ if (errcode_index < 0 || errcode_index >= LIBUSB_ERROR_COUNT) {
228
218
  /* "Other Error", which should always be our last message, is returned */
229
219
  errcode_index = LIBUSB_ERROR_COUNT - 1;
230
220
  }
231
221
 
232
- return usbi_localized_errors[usbi_locale][errcode_index];
222
+ return (*usbi_error_strings)[errcode_index];
233
223
  }