usb 2.1.3 → 2.2.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 (279) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +3 -0
  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/libusb/.gitattributes +2 -6
  10. package/libusb/.private/appveyor_build.sh +22 -0
  11. package/libusb/.private/bm.sh +1 -1
  12. package/libusb/.private/ci-build.sh +67 -0
  13. package/libusb/.private/post-rewrite.sh +5 -1
  14. package/libusb/.private/pre-commit.sh +5 -1
  15. package/libusb/.private/wbs.txt +4 -19
  16. package/libusb/.travis.yml +32 -23
  17. package/libusb/AUTHORS +76 -3
  18. package/libusb/ChangeLog +41 -3
  19. package/libusb/INSTALL_WIN.txt +22 -44
  20. package/libusb/Makefile.am +32 -10
  21. package/libusb/{README.md → README} +2 -2
  22. package/libusb/README.git +3 -3
  23. package/libusb/Xcode/common.xcconfig +23 -19
  24. package/libusb/Xcode/config.h +25 -13
  25. package/libusb/Xcode/libusb.xcodeproj/project.pbxproj +511 -109
  26. package/libusb/android/README +90 -54
  27. package/libusb/android/config.h +23 -43
  28. package/libusb/android/examples/unrooted_android.c +301 -0
  29. package/libusb/android/examples/unrooted_android.h +36 -0
  30. package/libusb/android/jni/Android.mk +1 -1
  31. package/libusb/android/jni/Application.mk +16 -0
  32. package/libusb/android/jni/examples.mk +63 -29
  33. package/libusb/android/jni/libusb.mk +14 -8
  34. package/libusb/android/jni/tests.mk +13 -24
  35. package/libusb/appveyor.yml +69 -30
  36. package/libusb/autogen.sh +5 -3
  37. package/libusb/bootstrap.sh +6 -2
  38. package/libusb/configure.ac +302 -228
  39. package/libusb/doc/Makefile.in +22 -0
  40. package/libusb/doc/doxygen.cfg.in +460 -223
  41. package/libusb/examples/Makefile.am +6 -13
  42. package/libusb/examples/dpfp.c +276 -73
  43. package/libusb/examples/ezusb.c +18 -8
  44. package/libusb/examples/ezusb.h +6 -17
  45. package/libusb/examples/fxload.c +4 -5
  46. package/libusb/examples/hotplugtest.c +1 -1
  47. package/libusb/examples/sam3u_benchmark.c +59 -24
  48. package/libusb/examples/testlibusb.c +138 -104
  49. package/libusb/examples/xusb.c +26 -22
  50. package/libusb/libusb/Makefile.am +57 -70
  51. package/libusb/libusb/Makefile.am.extra +26 -0
  52. package/libusb/libusb/core.c +420 -423
  53. package/libusb/libusb/descriptor.c +365 -419
  54. package/libusb/libusb/hotplug.c +197 -104
  55. package/libusb/libusb/io.c +491 -528
  56. package/libusb/libusb/libusb-1.0.def +7 -3
  57. package/libusb/libusb/libusb-1.0.rc +1 -9
  58. package/libusb/libusb/libusb.h +295 -226
  59. package/libusb/libusb/libusbi.h +587 -314
  60. package/libusb/libusb/os/darwin_usb.c +634 -317
  61. package/libusb/libusb/os/darwin_usb.h +39 -15
  62. package/libusb/libusb/os/events_posix.c +300 -0
  63. package/libusb/libusb/os/events_posix.h +59 -0
  64. package/libusb/libusb/os/events_windows.c +214 -0
  65. package/libusb/{msvc/missing.h → libusb/os/events_windows.h} +25 -11
  66. package/libusb/libusb/os/haiku_pollfs.cpp +14 -9
  67. package/libusb/libusb/os/haiku_usb.h +12 -12
  68. package/libusb/libusb/os/haiku_usb_backend.cpp +36 -37
  69. package/libusb/libusb/os/haiku_usb_raw.cpp +80 -116
  70. package/libusb/libusb/os/linux_netlink.c +55 -63
  71. package/libusb/libusb/os/linux_udev.c +61 -69
  72. package/libusb/libusb/os/linux_usbfs.c +926 -1015
  73. package/libusb/libusb/os/linux_usbfs.h +74 -57
  74. package/libusb/libusb/os/netbsd_usb.c +103 -168
  75. package/libusb/libusb/os/null_usb.c +111 -0
  76. package/libusb/libusb/os/openbsd_usb.c +71 -120
  77. package/libusb/libusb/os/sunos_usb.c +289 -375
  78. package/libusb/libusb/os/sunos_usb.h +0 -1
  79. package/libusb/libusb/os/threads_posix.c +81 -32
  80. package/libusb/libusb/os/threads_posix.h +19 -23
  81. package/libusb/libusb/os/threads_windows.c +9 -95
  82. package/libusb/libusb/os/threads_windows.h +33 -31
  83. package/libusb/libusb/os/windows_common.c +904 -0
  84. package/libusb/libusb/os/windows_common.h +329 -42
  85. package/libusb/libusb/os/windows_usbdk.c +161 -267
  86. package/libusb/libusb/os/windows_usbdk.h +5 -2
  87. package/libusb/libusb/os/windows_winusb.c +1326 -1190
  88. package/libusb/libusb/os/windows_winusb.h +167 -167
  89. package/libusb/libusb/strerror.c +20 -30
  90. package/libusb/libusb/sync.c +20 -21
  91. package/libusb/libusb/version.h +1 -1
  92. package/libusb/libusb/version_nano.h +1 -1
  93. package/libusb/msvc/.gitattributes +3 -0
  94. package/libusb/msvc/config.h +27 -20
  95. package/libusb/msvc/{hotplugtest_2012.vcxproj → dpfp_2013.vcxproj} +14 -10
  96. package/libusb/msvc/dpfp_2013.vcxproj.filters +26 -0
  97. package/libusb/msvc/{listdevs_2010.vcxproj → dpfp_2015.vcxproj} +14 -9
  98. package/libusb/msvc/dpfp_2015.vcxproj.filters +26 -0
  99. package/libusb/msvc/dpfp_2017.vcxproj +106 -0
  100. package/libusb/msvc/dpfp_2017.vcxproj.filters +26 -0
  101. package/libusb/msvc/dpfp_2019.vcxproj +106 -0
  102. package/libusb/msvc/dpfp_2019.vcxproj.filters +26 -0
  103. package/libusb/msvc/dpfp_threaded_2013.vcxproj +87 -0
  104. package/libusb/msvc/dpfp_threaded_2013.vcxproj.filters +26 -0
  105. package/libusb/msvc/dpfp_threaded_2015.vcxproj +87 -0
  106. package/libusb/msvc/dpfp_threaded_2015.vcxproj.filters +26 -0
  107. package/libusb/msvc/dpfp_threaded_2017.vcxproj +106 -0
  108. package/libusb/msvc/dpfp_threaded_2017.vcxproj.filters +26 -0
  109. package/libusb/msvc/{fxload_2012.vcxproj → dpfp_threaded_2019.vcxproj} +32 -17
  110. package/libusb/msvc/dpfp_threaded_2019.vcxproj.filters +26 -0
  111. package/libusb/msvc/fxload_2013.vcxproj +6 -3
  112. package/libusb/msvc/fxload_2013.vcxproj.filters +35 -0
  113. package/libusb/msvc/fxload_2015.vcxproj +6 -3
  114. package/libusb/msvc/fxload_2015.vcxproj.filters +35 -0
  115. package/libusb/msvc/fxload_2017.vcxproj +6 -7
  116. package/libusb/msvc/fxload_2017.vcxproj.filters +35 -0
  117. package/libusb/msvc/{fxload_2010.vcxproj → fxload_2019.vcxproj} +29 -6
  118. package/libusb/msvc/fxload_2019.vcxproj.filters +35 -0
  119. package/libusb/{examples → msvc}/getopt/getopt.c +0 -0
  120. package/libusb/{examples → msvc}/getopt/getopt.h +0 -0
  121. package/libusb/{examples → msvc}/getopt/getopt1.c +0 -0
  122. package/libusb/msvc/getopt_2013.vcxproj +4 -5
  123. package/libusb/msvc/getopt_2013.vcxproj.filters +26 -0
  124. package/libusb/msvc/getopt_2015.vcxproj +4 -4
  125. package/libusb/msvc/getopt_2015.vcxproj.filters +26 -0
  126. package/libusb/msvc/getopt_2017.vcxproj +4 -10
  127. package/libusb/msvc/getopt_2017.vcxproj.filters +26 -0
  128. package/libusb/msvc/{getopt_2012.vcxproj → getopt_2019.vcxproj} +25 -6
  129. package/libusb/msvc/getopt_2019.vcxproj.filters +26 -0
  130. package/libusb/msvc/hotplugtest_2013.vcxproj +6 -3
  131. package/libusb/msvc/hotplugtest_2013.vcxproj.filters +23 -0
  132. package/libusb/msvc/hotplugtest_2015.vcxproj +6 -3
  133. package/libusb/msvc/hotplugtest_2015.vcxproj.filters +23 -0
  134. package/libusb/msvc/hotplugtest_2017.vcxproj +6 -7
  135. package/libusb/msvc/hotplugtest_2017.vcxproj.filters +23 -0
  136. package/libusb/msvc/hotplugtest_2019.vcxproj +105 -0
  137. package/libusb/msvc/hotplugtest_2019.vcxproj.filters +23 -0
  138. package/libusb/msvc/libusb_2013.sln +50 -20
  139. package/libusb/msvc/libusb_2015.sln +51 -21
  140. package/libusb/msvc/libusb_2017.sln +90 -36
  141. package/libusb/msvc/libusb_2019.sln +240 -0
  142. package/libusb/msvc/libusb_dll_2013.vcxproj +6 -9
  143. package/libusb/msvc/libusb_dll_2013.vcxproj.filters +94 -0
  144. package/libusb/msvc/libusb_dll_2015.vcxproj +6 -8
  145. package/libusb/msvc/libusb_dll_2015.vcxproj.filters +94 -0
  146. package/libusb/msvc/libusb_dll_2017.vcxproj +6 -16
  147. package/libusb/msvc/libusb_dll_2017.vcxproj.filters +94 -0
  148. package/libusb/msvc/{libusb_dll_2010.vcxproj → libusb_dll_2019.vcxproj} +27 -9
  149. package/libusb/msvc/libusb_dll_2019.vcxproj.filters +94 -0
  150. package/libusb/msvc/libusb_static_2013.vcxproj +5 -9
  151. package/libusb/msvc/libusb_static_2013.vcxproj.filters +80 -0
  152. package/libusb/msvc/libusb_static_2015.vcxproj +5 -8
  153. package/libusb/msvc/libusb_static_2015.vcxproj.filters +80 -0
  154. package/libusb/msvc/libusb_static_2017.vcxproj +5 -8
  155. package/libusb/msvc/libusb_static_2017.vcxproj.filters +80 -0
  156. package/libusb/msvc/{libusb_static_2010.vcxproj → libusb_static_2019.vcxproj} +26 -9
  157. package/libusb/msvc/libusb_static_2019.vcxproj.filters +80 -0
  158. package/libusb/msvc/listdevs_2013.vcxproj +6 -3
  159. package/libusb/msvc/listdevs_2013.vcxproj.filters +23 -0
  160. package/libusb/msvc/listdevs_2015.vcxproj +6 -3
  161. package/libusb/msvc/listdevs_2015.vcxproj.filters +23 -0
  162. package/libusb/msvc/listdevs_2017.vcxproj +6 -7
  163. package/libusb/msvc/listdevs_2017.vcxproj.filters +23 -0
  164. package/libusb/msvc/listdevs_2019.vcxproj +105 -0
  165. package/libusb/msvc/listdevs_2019.vcxproj.filters +23 -0
  166. package/libusb/msvc/{listdevs_2012.vcxproj → sam3u_benchmark_2013.vcxproj} +13 -9
  167. package/libusb/msvc/sam3u_benchmark_2013.vcxproj.filters +26 -0
  168. package/libusb/msvc/{hotplugtest_2010.vcxproj → sam3u_benchmark_2015.vcxproj} +13 -8
  169. package/libusb/msvc/sam3u_benchmark_2015.vcxproj.filters +26 -0
  170. package/libusb/msvc/sam3u_benchmark_2017.vcxproj +106 -0
  171. package/libusb/msvc/sam3u_benchmark_2017.vcxproj.filters +26 -0
  172. package/libusb/msvc/sam3u_benchmark_2019.vcxproj +106 -0
  173. package/libusb/msvc/sam3u_benchmark_2019.vcxproj.filters +26 -0
  174. package/libusb/msvc/stress_2013.vcxproj +4 -2
  175. package/libusb/msvc/stress_2013.vcxproj.filters +32 -0
  176. package/libusb/msvc/stress_2015.vcxproj +4 -2
  177. package/libusb/msvc/stress_2015.vcxproj.filters +32 -0
  178. package/libusb/msvc/stress_2017.vcxproj +4 -6
  179. package/libusb/msvc/stress_2017.vcxproj.filters +32 -0
  180. package/libusb/msvc/{stress_2010.vcxproj → stress_2019.vcxproj} +26 -4
  181. package/libusb/msvc/stress_2019.vcxproj.filters +32 -0
  182. package/libusb/msvc/testlibusb_2013.vcxproj +6 -3
  183. package/libusb/msvc/testlibusb_2013.vcxproj.filters +23 -0
  184. package/libusb/msvc/testlibusb_2015.vcxproj +6 -3
  185. package/libusb/msvc/testlibusb_2015.vcxproj.filters +23 -0
  186. package/libusb/msvc/testlibusb_2017.vcxproj +6 -7
  187. package/libusb/msvc/testlibusb_2017.vcxproj.filters +23 -0
  188. package/libusb/msvc/{testlibusb_2010.vcxproj → testlibusb_2019.vcxproj} +28 -5
  189. package/libusb/msvc/testlibusb_2019.vcxproj.filters +23 -0
  190. package/libusb/msvc/xusb_2013.vcxproj +6 -3
  191. package/libusb/msvc/xusb_2013.vcxproj.filters +23 -0
  192. package/libusb/msvc/xusb_2015.vcxproj +6 -3
  193. package/libusb/msvc/xusb_2015.vcxproj.filters +23 -0
  194. package/libusb/msvc/xusb_2017.vcxproj +6 -7
  195. package/libusb/msvc/xusb_2017.vcxproj.filters +23 -0
  196. package/libusb/msvc/{xusb_2010.vcxproj → xusb_2019.vcxproj} +28 -5
  197. package/libusb/msvc/xusb_2019.vcxproj.filters +23 -0
  198. package/libusb/tests/Makefile.am +1 -0
  199. package/libusb/tests/libusb_testlib.h +12 -43
  200. package/libusb/tests/stress.c +59 -50
  201. package/libusb/tests/testlib.c +78 -171
  202. package/libusb.gypi +10 -11
  203. package/package.json +1 -1
  204. package/prebuilds/android-arm/node.napi.armv7.node +0 -0
  205. package/prebuilds/android-arm64/node.napi.armv8.node +0 -0
  206. package/prebuilds/darwin-x64+arm64/node.napi.node +0 -0
  207. package/prebuilds/linux-arm/node.napi.armv6.node +0 -0
  208. package/prebuilds/linux-arm/node.napi.armv7.node +0 -0
  209. package/prebuilds/linux-arm64/node.napi.armv8.node +0 -0
  210. package/prebuilds/linux-ia32/node.napi.node +0 -0
  211. package/prebuilds/linux-x64/node.napi.glibc.node +0 -0
  212. package/prebuilds/linux-x64/node.napi.musl.node +0 -0
  213. package/prebuilds/win32-ia32/node.napi.node +0 -0
  214. package/prebuilds/win32-x64/node.napi.node +0 -0
  215. package/src/device.cc +12 -7
  216. package/src/node_usb.cc +10 -0
  217. package/test/usb.coffee +6 -0
  218. package/tsc/index.ts +2 -0
  219. package/tsc/usb/bindings.ts +5 -0
  220. package/tsc/usb/device.ts +6 -0
  221. package/libusb/.private/bd.cmd +0 -89
  222. package/libusb/.private/bwince.cmd +0 -57
  223. package/libusb/.private/wbs_wince.txt +0 -42
  224. package/libusb/Brewfile +0 -4
  225. package/libusb/appveyor_cygwin.bat +0 -11
  226. package/libusb/appveyor_minGW.bat +0 -19
  227. package/libusb/doc/Makefile.am +0 -9
  228. package/libusb/examples/dpfp_threaded.c +0 -557
  229. package/libusb/libusb/hotplug.h +0 -99
  230. package/libusb/libusb/os/poll_posix.c +0 -84
  231. package/libusb/libusb/os/poll_posix.h +0 -14
  232. package/libusb/libusb/os/poll_windows.c +0 -447
  233. package/libusb/libusb/os/poll_windows.h +0 -98
  234. package/libusb/libusb/os/wince_usb.c +0 -888
  235. package/libusb/libusb/os/wince_usb.h +0 -126
  236. package/libusb/libusb/os/windows_nt_common.c +0 -1010
  237. package/libusb/libusb/os/windows_nt_common.h +0 -110
  238. package/libusb/libusb/os/windows_nt_shared_types.h +0 -147
  239. package/libusb/msvc/appveyor.bat +0 -27
  240. package/libusb/msvc/ddk_build.cmd +0 -219
  241. package/libusb/msvc/errno.h +0 -102
  242. package/libusb/msvc/fxload_sources +0 -23
  243. package/libusb/msvc/getopt_2005.vcproj +0 -288
  244. package/libusb/msvc/getopt_2010.vcxproj +0 -72
  245. package/libusb/msvc/getopt_sources +0 -24
  246. package/libusb/msvc/hotplugtest_sources +0 -20
  247. package/libusb/msvc/inttypes.h +0 -295
  248. package/libusb/msvc/libusb.dsw +0 -71
  249. package/libusb/msvc/libusb_2005.sln +0 -95
  250. package/libusb/msvc/libusb_2010.sln +0 -105
  251. package/libusb/msvc/libusb_2012.sln +0 -105
  252. package/libusb/msvc/libusb_dll.dsp +0 -194
  253. package/libusb/msvc/libusb_dll_2005.vcproj +0 -464
  254. package/libusb/msvc/libusb_dll_2012.vcxproj +0 -107
  255. package/libusb/msvc/libusb_dll_wince.vcproj +0 -1251
  256. package/libusb/msvc/libusb_sources +0 -43
  257. package/libusb/msvc/libusb_static.dsp +0 -174
  258. package/libusb/msvc/libusb_static_2005.vcproj +0 -390
  259. package/libusb/msvc/libusb_static_2012.vcxproj +0 -98
  260. package/libusb/msvc/libusb_static_wince.vcproj +0 -1179
  261. package/libusb/msvc/libusb_wince.sln +0 -246
  262. package/libusb/msvc/listdevs.dsp +0 -103
  263. package/libusb/msvc/listdevs_2005.vcproj +0 -360
  264. package/libusb/msvc/listdevs_sources +0 -20
  265. package/libusb/msvc/listdevs_wince.vcproj +0 -1120
  266. package/libusb/msvc/missing.c +0 -80
  267. package/libusb/msvc/stdint.h +0 -256
  268. package/libusb/msvc/stress_2005.vcproj +0 -390
  269. package/libusb/msvc/stress_2012.vcxproj +0 -87
  270. package/libusb/msvc/stress_sources +0 -21
  271. package/libusb/msvc/stress_wince.vcproj +0 -1128
  272. package/libusb/msvc/testlibusb_2012.vcxproj +0 -83
  273. package/libusb/msvc/testlibusb_sources +0 -20
  274. package/libusb/msvc/xusb.dsp +0 -102
  275. package/libusb/msvc/xusb_2005.vcproj +0 -344
  276. package/libusb/msvc/xusb_2012.vcxproj +0 -83
  277. package/libusb/msvc/xusb_sources +0 -20
  278. package/libusb/msvc/xusb_wince.vcproj +0 -1120
  279. package/libusb/travis-autogen.sh +0 -39
@@ -17,43 +17,26 @@
17
17
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
18
  */
19
19
 
20
- #include "libusb_testlib.h"
20
+ #include <config.h>
21
21
 
22
- #include <stdio.h>
22
+ #include <errno.h>
23
23
  #include <stdarg.h>
24
+ #include <stdbool.h>
25
+ #include <stdio.h>
24
26
  #include <string.h>
25
- #include <errno.h>
26
- #if !defined(_WIN32_WCE)
27
- #include <sys/types.h>
28
- #include <sys/stat.h>
29
- #include <fcntl.h>
30
- #endif
31
27
 
32
- #if defined(_WIN32_WCE)
33
- // No support for selective redirection of STDOUT on WinCE.
34
- #define DISABLE_STDOUT_REDIRECTION
35
- #define STDOUT_FILENO 1
36
- #elif defined(_WIN32)
37
- #include <io.h>
38
- #define dup _dup
39
- #define dup2 _dup2
40
- #define open _open
41
- #define close _close
42
- #define fdopen _fdopen
43
- #define NULL_PATH "nul"
44
- #define STDOUT_FILENO 1
45
- #define STDERR_FILENO 2
46
- #else
47
- #include <unistd.h>
28
+ #include "libusb_testlib.h"
29
+
30
+ #if defined(PLATFORM_POSIX)
48
31
  #define NULL_PATH "/dev/null"
32
+ #elif defined(PLATFORM_WINDOWS)
33
+ #define NULL_PATH "nul"
49
34
  #endif
50
- #define INVALID_FD -1
51
- #define IGNORE_RETVAL(expr) do { (void)(expr); } while(0)
52
35
 
53
36
  /**
54
37
  * Converts a test result code into a human readable string.
55
38
  */
56
- static const char* test_result_to_str(libusb_testlib_result result)
39
+ static const char *test_result_to_str(libusb_testlib_result result)
57
40
  {
58
41
  switch (result) {
59
42
  case TEST_STATUS_SUCCESS:
@@ -69,100 +52,27 @@ static const char* test_result_to_str(libusb_testlib_result result)
69
52
  }
70
53
  }
71
54
 
72
- static void print_usage(int argc, char ** argv)
55
+ static void print_usage(const char *progname)
73
56
  {
74
- printf("Usage: %s [-l] [-v] [<test_name> ...]\n",
75
- argc > 0 ? argv[0] : "test_*");
57
+ printf("Usage: %s [-l] [-v] [<test_name> ...]\n", progname);
76
58
  printf(" -l List available tests\n");
77
- printf(" -v Don't redirect STDERR/STDOUT during tests\n");
59
+ printf(" -v Don't redirect STDERR before running tests\n");
60
+ printf(" -h Display this help and exit\n");
78
61
  }
79
62
 
80
- static void cleanup_test_output(libusb_testlib_ctx * ctx)
81
- {
82
- #ifndef DISABLE_STDOUT_REDIRECTION
83
- if (!ctx->verbose) {
84
- if (ctx->old_stdout != INVALID_FD) {
85
- IGNORE_RETVAL(dup2(ctx->old_stdout, STDOUT_FILENO));
86
- ctx->old_stdout = INVALID_FD;
87
- }
88
- if (ctx->old_stderr != INVALID_FD) {
89
- IGNORE_RETVAL(dup2(ctx->old_stderr, STDERR_FILENO));
90
- ctx->old_stderr = INVALID_FD;
91
- }
92
- if (ctx->null_fd != INVALID_FD) {
93
- close(ctx->null_fd);
94
- ctx->null_fd = INVALID_FD;
95
- }
96
- if (ctx->output_file != stdout) {
97
- fclose(ctx->output_file);
98
- ctx->output_file = stdout;
99
- }
100
- }
101
- #endif
102
- }
103
-
104
- /**
105
- * Setup test output handles
106
- * \return zero on success, non-zero on failure
107
- */
108
- static int setup_test_output(libusb_testlib_ctx * ctx)
109
- {
110
- #ifndef DISABLE_STDOUT_REDIRECTION
111
- /* Stop output to stdout and stderr from being displayed if using non-verbose output */
112
- if (!ctx->verbose) {
113
- /* Keep a copy of STDOUT and STDERR */
114
- ctx->old_stdout = dup(STDOUT_FILENO);
115
- if (ctx->old_stdout < 0) {
116
- ctx->old_stdout = INVALID_FD;
117
- printf("Failed to duplicate stdout handle: %d\n", errno);
118
- return 1;
119
- }
120
- ctx->old_stderr = dup(STDERR_FILENO);
121
- if (ctx->old_stderr < 0) {
122
- ctx->old_stderr = INVALID_FD;
123
- cleanup_test_output(ctx);
124
- printf("Failed to duplicate stderr handle: %d\n", errno);
125
- return 1;
126
- }
127
- /* Redirect STDOUT_FILENO and STDERR_FILENO to /dev/null or "nul"*/
128
- ctx->null_fd = open(NULL_PATH, O_WRONLY);
129
- if (ctx->null_fd < 0) {
130
- ctx->null_fd = INVALID_FD;
131
- cleanup_test_output(ctx);
132
- printf("Failed to open null handle: %d\n", errno);
133
- return 1;
134
- }
135
- if ((dup2(ctx->null_fd, STDOUT_FILENO) < 0) ||
136
- (dup2(ctx->null_fd, STDERR_FILENO) < 0)) {
137
- cleanup_test_output(ctx);
138
- return 1;
139
- }
140
- ctx->output_file = fdopen(ctx->old_stdout, "w");
141
- if (!ctx->output_file) {
142
- ctx->output_file = stdout;
143
- cleanup_test_output(ctx);
144
- printf("Failed to open FILE for output handle: %d\n", errno);
145
- return 1;
146
- }
147
- }
148
- #endif
149
- return 0;
150
- }
151
-
152
- void libusb_testlib_logf(libusb_testlib_ctx * ctx,
153
- const char* fmt, ...)
63
+ void libusb_testlib_logf(const char *fmt, ...)
154
64
  {
155
65
  va_list va;
66
+
156
67
  va_start(va, fmt);
157
- vfprintf(ctx->output_file, fmt, va);
68
+ vfprintf(stdout, fmt, va);
158
69
  va_end(va);
159
- fprintf(ctx->output_file, "\n");
160
- fflush(ctx->output_file);
70
+ fputc('\n', stdout);
71
+ fflush(stdout);
161
72
  }
162
73
 
163
- int libusb_testlib_run_tests(int argc,
164
- char ** argv,
165
- const libusb_testlib_test * tests)
74
+ int libusb_testlib_run_tests(int argc, char *argv[],
75
+ const libusb_testlib_test *tests)
166
76
  {
167
77
  int run_count = 0;
168
78
  int idx = 0;
@@ -170,108 +80,105 @@ int libusb_testlib_run_tests(int argc,
170
80
  int fail_count = 0;
171
81
  int error_count = 0;
172
82
  int skip_count = 0;
173
- int r, j;
174
- size_t arglen;
175
- libusb_testlib_result test_result;
176
- libusb_testlib_ctx ctx;
177
83
 
178
84
  /* Setup default mode of operation */
179
- ctx.test_names = NULL;
180
- ctx.test_count = 0;
181
- ctx.list_tests = false;
182
- ctx.verbose = false;
183
- ctx.old_stdout = INVALID_FD;
184
- ctx.old_stderr = INVALID_FD;
185
- ctx.output_file = stdout;
186
- ctx.null_fd = INVALID_FD;
85
+ char **test_names = NULL;
86
+ int test_count = 0;
87
+ bool list_tests = false;
88
+ bool verbose = false;
187
89
 
188
90
  /* Parse command line options */
189
91
  if (argc >= 2) {
190
- for (j = 1; j < argc; j++) {
191
- arglen = strlen(argv[j]);
192
- if ( ((argv[j][0] == '-') || (argv[j][0] == '/')) &&
193
- arglen >=2 ) {
194
- switch (argv[j][1]) {
92
+ for (int j = 1; j < argc; j++) {
93
+ const char *argstr = argv[j];
94
+ size_t arglen = strlen(argstr);
95
+
96
+ if (argstr[0] == '-' || argstr[0] == '/') {
97
+ if (arglen == 2) {
98
+ switch (argstr[1]) {
195
99
  case 'l':
196
- ctx.list_tests = true;
197
- break;
100
+ list_tests = true;
101
+ continue;
198
102
  case 'v':
199
- ctx.verbose = true;
200
- break;
201
- default:
202
- printf("Unknown option: '%s'\n", argv[j]);
203
- print_usage(argc, argv);
204
- return 1;
103
+ verbose = true;
104
+ continue;
105
+ case 'h':
106
+ print_usage(argv[0]);
107
+ return 0;
205
108
  }
109
+ }
110
+
111
+ fprintf(stderr, "Unknown option: '%s'\n", argstr);
112
+ print_usage(argv[0]);
113
+ return 1;
206
114
  } else {
207
115
  /* End of command line options, remaining must be list of tests to run */
208
- ctx.test_names = argv + j;
209
- ctx.test_count = argc - j;
116
+ test_names = argv + j;
117
+ test_count = argc - j;
210
118
  break;
211
119
  }
212
120
  }
213
121
  }
214
122
 
215
123
  /* Validate command line options */
216
- if (ctx.test_names && ctx.list_tests) {
217
- printf("List of tests requested but test list provided\n");
218
- print_usage(argc, argv);
124
+ if (test_names && list_tests) {
125
+ fprintf(stderr, "List of tests requested but test list provided\n");
126
+ print_usage(argv[0]);
219
127
  return 1;
220
128
  }
221
129
 
222
130
  /* Setup test log output */
223
- r = setup_test_output(&ctx);
224
- if (r != 0)
225
- return r;
131
+ if (!verbose) {
132
+ if (!freopen(NULL_PATH, "w", stderr)) {
133
+ printf("Failed to open null handle: %d\n", errno);
134
+ return 1;
135
+ }
136
+ }
226
137
 
227
138
  /* Act on any options not related to running tests */
228
- if (ctx.list_tests) {
229
- while (tests[idx].function != NULL) {
230
- libusb_testlib_logf(&ctx, tests[idx].name);
231
- ++idx;
232
- }
233
- cleanup_test_output(&ctx);
139
+ if (list_tests) {
140
+ while (tests[idx].function)
141
+ libusb_testlib_logf("%s", tests[idx++].name);
234
142
  return 0;
235
143
  }
236
144
 
237
145
  /* Run any requested tests */
238
- while (tests[idx].function != NULL) {
239
- const libusb_testlib_test * test = &tests[idx];
240
- ++idx;
241
- if (ctx.test_count > 0) {
146
+ while (tests[idx].function) {
147
+ const libusb_testlib_test *test = &tests[idx++];
148
+ libusb_testlib_result test_result;
149
+
150
+ if (test_count > 0) {
242
151
  /* Filtering tests to run, check if this is one of them */
243
152
  int i;
244
- for (i = 0; i < ctx.test_count; ++i) {
245
- if (strcmp(ctx.test_names[i], test->name) == 0)
153
+
154
+ for (i = 0; i < test_count; i++) {
155
+ if (!strcmp(test_names[i], test->name))
246
156
  /* Matches a requested test name */
247
157
  break;
248
158
  }
249
- if (i >= ctx.test_count) {
159
+ if (i == test_count) {
250
160
  /* Failed to find a test match, so do the next loop iteration */
251
161
  continue;
252
162
  }
253
163
  }
254
- libusb_testlib_logf(&ctx,
255
- "Starting test run: %s...", test->name);
256
- test_result = test->function(&ctx);
257
- libusb_testlib_logf(&ctx,
258
- "%s (%d)",
259
- test_result_to_str(test_result), test_result);
164
+ libusb_testlib_logf("Starting test run: %s...", test->name);
165
+ test_result = test->function();
166
+ libusb_testlib_logf("%s (%d)", test_result_to_str(test_result), test_result);
260
167
  switch (test_result) {
261
168
  case TEST_STATUS_SUCCESS: pass_count++; break;
262
169
  case TEST_STATUS_FAILURE: fail_count++; break;
263
170
  case TEST_STATUS_ERROR: error_count++; break;
264
171
  case TEST_STATUS_SKIP: skip_count++; break;
265
172
  }
266
- ++run_count;
173
+ run_count++;
267
174
  }
268
- libusb_testlib_logf(&ctx, "---");
269
- libusb_testlib_logf(&ctx, "Ran %d tests", run_count);
270
- libusb_testlib_logf(&ctx, "Passed %d tests", pass_count);
271
- libusb_testlib_logf(&ctx, "Failed %d tests", fail_count);
272
- libusb_testlib_logf(&ctx, "Error in %d tests", error_count);
273
- libusb_testlib_logf(&ctx, "Skipped %d tests", skip_count);
274
175
 
275
- cleanup_test_output(&ctx);
176
+ libusb_testlib_logf("---");
177
+ libusb_testlib_logf("Ran %d tests", run_count);
178
+ libusb_testlib_logf("Passed %d tests", pass_count);
179
+ libusb_testlib_logf("Failed %d tests", fail_count);
180
+ libusb_testlib_logf("Error in %d tests", error_count);
181
+ libusb_testlib_logf("Skipped %d tests", skip_count);
182
+
276
183
  return pass_count != run_count;
277
184
  }
package/libusb.gypi CHANGED
@@ -15,14 +15,13 @@
15
15
  'libusb/libusb/core.c',
16
16
  'libusb/libusb/descriptor.c',
17
17
  'libusb/libusb/hotplug.c',
18
- 'libusb/libusb/hotplug.h',
19
18
  'libusb/libusb/io.c',
20
19
  'libusb/libusb/libusb.h',
21
20
  'libusb/libusb/libusbi.h',
22
21
  'libusb/libusb/strerror.c',
23
22
  'libusb/libusb/sync.c',
24
- 'libusb/libusb/version.h',
25
23
  'libusb/libusb/version_nano.h',
24
+ 'libusb/libusb/version.h',
26
25
  ],
27
26
  'include_dirs': [
28
27
  'libusb_config',
@@ -43,8 +42,8 @@
43
42
  'conditions': [
44
43
  [ 'OS == "linux" or OS == "android" or OS == "mac"', {
45
44
  'sources': [
46
- 'libusb/libusb/os/poll_posix.c',
47
- 'libusb/libusb/os/poll_posix.h',
45
+ 'libusb/libusb/os/events_posix.c',
46
+ 'libusb/libusb/os/events_posix.h',
48
47
  'libusb/libusb/os/threads_posix.c',
49
48
  'libusb/libusb/os/threads_posix.h',
50
49
  ],
@@ -105,6 +104,10 @@
105
104
  'sources': [
106
105
  'libusb/libusb/os/darwin_usb.c',
107
106
  'libusb/libusb/os/darwin_usb.h',
107
+ 'libusb/Xcode/config.h',
108
+ ],
109
+ 'include_dirs': [
110
+ 'libusb/Xcode',
108
111
  ],
109
112
  'defines': [
110
113
  'OS_DARWIN=1',
@@ -120,21 +123,17 @@
120
123
  }],
121
124
  [ 'OS == "win"', {
122
125
  'sources': [
123
- 'libusb/libusb/os/poll_windows.c',
124
- 'libusb/libusb/os/poll_windows.h',
126
+ 'libusb/libusb/os/events_windows.c',
127
+ 'libusb/libusb/os/events_windows.h',
125
128
  'libusb/libusb/os/threads_windows.c',
126
129
  'libusb/libusb/os/threads_windows.h',
130
+ 'libusb/libusb/os/windows_common.c',
127
131
  'libusb/libusb/os/windows_common.h',
128
- 'libusb/libusb/os/windows_nt_common.c',
129
- 'libusb/libusb/os/windows_nt_common.h',
130
- 'libusb/libusb/os/windows_nt_shared_types.h',
131
132
  'libusb/libusb/os/windows_usbdk.c',
132
133
  'libusb/libusb/os/windows_usbdk.h',
133
134
  'libusb/libusb/os/windows_winusb.c',
134
135
  'libusb/libusb/os/windows_winusb.h',
135
136
  'libusb/msvc/config.h',
136
- 'libusb/msvc/inttypes.h',
137
- 'libusb/msvc/stdint.h',
138
137
  ],
139
138
  'include_dirs!': [
140
139
  'libusb_config',
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "usb",
3
3
  "description": "Library to access USB devices",
4
4
  "license": "MIT",
5
- "version": "2.1.3",
5
+ "version": "2.2.0",
6
6
  "main": "dist/index.js",
7
7
  "engines": {
8
8
  "node": ">=10.16.0"
Binary file
Binary file
Binary file
package/src/device.cc CHANGED
@@ -18,14 +18,16 @@ Device::Device(const Napi::CallbackInfo & info) : Napi::ObjectWrap<Device>(info)
18
18
  {
19
19
  device = info[0].As<Napi::External<libusb_device>>().Data();
20
20
  libusb_ref_device(device);
21
- byPtr.insert(std::make_pair(device, this));
21
+ byPtr[device] = this;
22
22
  DEBUG_LOG("Created device %p", this);
23
23
  Constructor(info);
24
24
  }
25
25
 
26
26
  Device::~Device(){
27
27
  DEBUG_LOG("Freed device %p", this);
28
- byPtr.erase(device);
28
+ auto it = byPtr.find(device);
29
+ if (it != byPtr.end() && it->second == this)
30
+ byPtr.erase(it);
29
31
  libusb_close(device_handle);
30
32
  libusb_unref_device(device);
31
33
  }
@@ -37,12 +39,15 @@ std::map<libusb_device*, Device*> Device::byPtr;
37
39
  // or create a new one and add it to the map.
38
40
  Napi::Object Device::get(napi_env env, libusb_device* dev){
39
41
  auto it = byPtr.find(dev);
40
- if (it != byPtr.end()){
41
- return it->second->Value();
42
- } else {
43
- Napi::Object obj = Device::constructor.New({ Napi::External<libusb_device>::New(env, dev) });
44
- return obj;
42
+ if (it != byPtr.end()) {
43
+ auto value = it->second->Value();
44
+ // JS object may have already been garbage collected
45
+ if (!value.IsEmpty())
46
+ return value;
45
47
  }
48
+
49
+ Napi::Object obj = Device::constructor.New({ Napi::External<libusb_device>::New(env, dev) });
50
+ return obj;
46
51
  }
47
52
 
48
53
  Napi::Value Device::Constructor(const Napi::CallbackInfo& info) {
package/src/node_usb.cc CHANGED
@@ -3,6 +3,7 @@
3
3
  #include <thread>
4
4
 
5
5
  Napi::Value SetDebugLevel(const Napi::CallbackInfo& info);
6
+ Napi::Value UseUsbDkBackend(const Napi::CallbackInfo& info);
6
7
  Napi::Value GetDeviceList(const Napi::CallbackInfo& info);
7
8
  Napi::Value GetLibusbCapability(const Napi::CallbackInfo& info);
8
9
  Napi::Value EnableHotplugEvents(const Napi::CallbackInfo& info);
@@ -97,6 +98,7 @@ Napi::Object Init(Napi::Env env, Napi::Object exports) {
97
98
  Transfer::Init(env, exports);
98
99
 
99
100
  exports.Set("setDebugLevel", Napi::Function::New(env, SetDebugLevel));
101
+ exports.Set("useUsbDkBackend", Napi::Function::New(env, UseUsbDkBackend));
100
102
  exports.Set("getDeviceList", Napi::Function::New(env, GetDeviceList));
101
103
  exports.Set("_getLibusbCapability", Napi::Function::New(env, GetLibusbCapability));
102
104
  exports.Set("_enableHotplugEvents", Napi::Function::New(env, EnableHotplugEvents));
@@ -119,6 +121,14 @@ Napi::Value SetDebugLevel(const Napi::CallbackInfo& info) {
119
121
  return env.Undefined();
120
122
  }
121
123
 
124
+ Napi::Value UseUsbDkBackend(const Napi::CallbackInfo& info) {
125
+ Napi::Env env = info.Env();
126
+ Napi::HandleScope scope(env);
127
+
128
+ libusb_set_option(usb_context, LIBUSB_OPTION_USE_USBDK);
129
+ return env.Undefined();
130
+ }
131
+
122
132
  Napi::Value GetDeviceList(const Napi::CallbackInfo& info) {
123
133
  Napi::Env env = info.Env();
124
134
  Napi::HandleScope scope(env);
package/test/usb.coffee CHANGED
@@ -70,6 +70,12 @@ describe 'Device', ->
70
70
  assert.equal(s, 'Nonolith Labs')
71
71
  done()
72
72
 
73
+ it 'supports null string descriptors', (done) ->
74
+ device.getStringDescriptor device.configDescriptor.iConfiguration, (e, s) ->
75
+ assert.ok(e == undefined, e)
76
+ assert.equal(s, undefined)
77
+ done()
78
+
73
79
  describe 'control transfer', ->
74
80
  b = Buffer.from([0x30...0x40])
75
81
  it 'should OUT transfer when the IN bit is not set', (done) ->
package/tsc/index.ts CHANGED
@@ -5,6 +5,7 @@ import * as usb from './usb';
5
5
 
6
6
  const webusb = new WebUSB();
7
7
  const getDeviceList = usb.getDeviceList;
8
+ const useUsbDkBackend = usb.useUsbDkBackend;
8
9
 
9
10
  /**
10
11
  * Convenience method to get the first device with the specified VID and PID, or `undefined` if no such device is present.
@@ -57,6 +58,7 @@ export {
57
58
  usb,
58
59
 
59
60
  // Convenience methods
61
+ useUsbDkBackend,
60
62
  getDeviceList,
61
63
  findByIds,
62
64
  findBySerialNumber,
@@ -26,6 +26,11 @@ export declare class LibUSBException extends Error {
26
26
  */
27
27
  export declare function setDebugLevel(level: number): void;
28
28
 
29
+ /**
30
+ * Use USBDK Backend (Windows only)
31
+ */
32
+ export declare function useUsbDkBackend(): void;
33
+
29
34
  export declare function _enableHotplugEvents(): void;
30
35
  export declare function _disableHotplugEvents(): void;
31
36
  export declare function _getLibusbCapability(capability: number): number;
package/tsc/usb/device.ts CHANGED
@@ -203,6 +203,12 @@ export class ExtendedDevice {
203
203
  * @param callback
204
204
  */
205
205
  public getStringDescriptor(this: usb.Device, desc_index: number, callback: (error?: usb.LibUSBException, value?: string) => void): void {
206
+ // Index 0 indicates null
207
+ if (desc_index === 0) {
208
+ callback();
209
+ return;
210
+ }
211
+
206
212
  const langid = 0x0409;
207
213
  const length = 255;
208
214
  this.controlTransfer(
@@ -1,89 +0,0 @@
1
- @echo off
2
- rem produce the DDK binary files for snapshots
3
- rem !!!THIS SCRIPT IS FOR INTERNAL DEVELOPER USE ONLY!!!
4
-
5
- if NOT x%DDK_TARGET_OS%==xWinXP goto usage
6
-
7
- set IWD=%~dp0
8
- cd ..
9
- mkdir E:\dailies\%DATE%
10
- for %%A in (MS32 MS64) do mkdir E:\dailies\%DATE%\%%A
11
- for %%A in (MS32 MS64) do mkdir E:\dailies\%DATE%\%%A\static
12
- for %%A in (MS32 MS64) do mkdir E:\dailies\%DATE%\%%A\dll
13
- for %%A in (source bin32 bin64) do mkdir E:\dailies\%DATE%\examples\%%A
14
- copy examples\listdevs.c E:\dailies\%DATE%\examples\source
15
- copy examples\xusb.c E:\dailies\%DATE%\examples\source
16
- copy examples\ezusb.? E:\dailies\%DATE%\examples\source
17
- copy examples\fxload.c E:\dailies\%DATE%\examples\source
18
- copy msvc\stdint.h E:\dailies\%DATE%\examples\source
19
- copy .private\wbs.txt E:\dailies\%DATE%\README.txt
20
-
21
- set ORG_BUILD_ALT_DIR=%BUILD_ALT_DIR%
22
- set ORG_BUILDARCH=%_BUILDARCH%
23
- set ORG_PATH=%PATH%
24
- set ORG_BUILD_DEFAULT_TARGETS=%BUILD_DEFAULT_TARGETS%
25
-
26
- set 386=1
27
- set AMD64=
28
- set BUILD_DEFAULT_TARGETS=-386
29
- set _AMD64bit=
30
- set _BUILDARCH=x86
31
- set PATH=%BASEDIR%\bin\x86;%BASEDIR%\bin\x86\x86
32
-
33
- cd msvc
34
- call ddk_build
35
- cd ..
36
-
37
- @echo off
38
- copy Win32\Release\lib\libusb-1.0.lib E:\dailies\%DATE%\MS32\static
39
- copy Win32\Release\examples\listdevs.exe E:\dailies\%DATE%\examples\bin32
40
- copy Win32\Release\examples\xusb.exe E:\dailies\%DATE%\examples\bin32
41
- copy Win32\Release\examples\fxload.exe E:\dailies\%DATE%\examples\bin32
42
-
43
- cd msvc
44
- call ddk_build DLL
45
- cd ..
46
-
47
- @echo off
48
- copy Win32\Release\lib\libusb-1.0.lib E:\dailies\%DATE%\MS32\dll
49
- copy Win32\Release\dll\libusb-1.0.dll E:\dailies\%DATE%\MS32\dll
50
- copy Win32\Release\dll\libusb-1.0.pdb E:\dailies\%DATE%\MS32\dll
51
-
52
- set 386=
53
- set AMD64=1
54
- set BUILD_DEFAULT_TARGETS=-amd64
55
- set _AMD64bit=true
56
- set _BUILDARCH=AMD64
57
- set PATH=%BASEDIR%\bin\x86\amd64;%BASEDIR%\bin\x86
58
-
59
- cd msvc
60
- call ddk_build
61
- cd ..
62
-
63
- @echo off
64
- copy x64\Release\lib\libusb-1.0.lib E:\dailies\%DATE%\MS64\static
65
- copy x64\Release\examples\listdevs.exe E:\dailies\%DATE%\examples\bin64
66
- copy x64\Release\examples\xusb.exe E:\dailies\%DATE%\examples\bin64
67
- copy x64\Release\examples\fxload.exe E:\dailies\%DATE%\examples\bin64
68
-
69
- cd msvc
70
- call ddk_build DLL
71
- cd ..
72
-
73
- @echo off
74
- copy x64\Release\lib\libusb-1.0.lib E:\dailies\%DATE%\MS64\dll
75
- copy x64\Release\dll\libusb-1.0.dll E:\dailies\%DATE%\MS64\dll
76
- copy x64\Release\dll\libusb-1.0.pdb E:\dailies\%DATE%\MS64\dll
77
-
78
- set BUILD_ALT_DIR=%ORG_BUILD_ALT_DIR%
79
- set _BUILDARCH=%ORG_BUILDARCH%
80
- set PATH=%ORG_PATH%
81
- set BUILD_DEFAULT_TARGETS=%ORG_BUILD_DEFAULT_TARGETS%
82
-
83
- goto done
84
-
85
- :usage
86
- echo must be run in a WXP build environment!
87
-
88
- :done
89
- cd %IWD%