usb 2.1.1 → 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 (287) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +4 -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/dist/usb/interface.d.ts +1 -1
  10. package/dist/usb/interface.js +1 -5
  11. package/dist/usb/interface.js.map +1 -1
  12. package/dist/webusb/webusb-device.d.ts +2 -1
  13. package/dist/webusb/webusb-device.js +21 -14
  14. package/dist/webusb/webusb-device.js.map +1 -1
  15. package/libusb/.gitattributes +2 -6
  16. package/libusb/.private/appveyor_build.sh +22 -0
  17. package/libusb/.private/bm.sh +1 -1
  18. package/libusb/.private/ci-build.sh +67 -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 +76 -3
  24. package/libusb/ChangeLog +41 -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 +301 -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 +69 -30
  42. package/libusb/autogen.sh +5 -3
  43. package/libusb/bootstrap.sh +6 -2
  44. package/libusb/configure.ac +302 -228
  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 +420 -423
  59. package/libusb/libusb/descriptor.c +365 -419
  60. package/libusb/libusb/hotplug.c +197 -104
  61. package/libusb/libusb/io.c +491 -528
  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 +295 -226
  65. package/libusb/libusb/libusbi.h +587 -314
  66. package/libusb/libusb/os/darwin_usb.c +634 -317
  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 +904 -0
  90. package/libusb/libusb/os/windows_common.h +329 -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 +1326 -1190
  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 +1 -0
  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.gypi +10 -11
  209. package/package.json +2 -2
  210. package/prebuilds/android-arm/node.napi.armv7.node +0 -0
  211. package/prebuilds/android-arm64/node.napi.armv8.node +0 -0
  212. package/prebuilds/darwin-x64+arm64/node.napi.node +0 -0
  213. package/prebuilds/linux-arm/node.napi.armv6.node +0 -0
  214. package/prebuilds/linux-arm/node.napi.armv7.node +0 -0
  215. package/prebuilds/linux-arm64/node.napi.armv8.node +0 -0
  216. package/prebuilds/linux-ia32/node.napi.node +0 -0
  217. package/prebuilds/linux-x64/node.napi.glibc.node +0 -0
  218. package/prebuilds/linux-x64/node.napi.musl.node +0 -0
  219. package/prebuilds/win32-ia32/node.napi.node +0 -0
  220. package/prebuilds/win32-x64/node.napi.node +0 -0
  221. package/src/device.cc +12 -7
  222. package/src/node_usb.cc +10 -0
  223. package/test/usb.coffee +6 -0
  224. package/tsc/index.ts +2 -0
  225. package/tsc/usb/bindings.ts +5 -0
  226. package/tsc/usb/device.ts +6 -0
  227. package/tsc/usb/interface.ts +2 -7
  228. package/tsc/webusb/webusb-device.ts +12 -8
  229. package/libusb/.private/bd.cmd +0 -89
  230. package/libusb/.private/bwince.cmd +0 -57
  231. package/libusb/.private/wbs_wince.txt +0 -42
  232. package/libusb/Brewfile +0 -4
  233. package/libusb/appveyor_cygwin.bat +0 -11
  234. package/libusb/appveyor_minGW.bat +0 -19
  235. package/libusb/doc/Makefile.am +0 -9
  236. package/libusb/examples/dpfp_threaded.c +0 -557
  237. package/libusb/libusb/hotplug.h +0 -99
  238. package/libusb/libusb/os/poll_posix.c +0 -84
  239. package/libusb/libusb/os/poll_posix.h +0 -14
  240. package/libusb/libusb/os/poll_windows.c +0 -447
  241. package/libusb/libusb/os/poll_windows.h +0 -98
  242. package/libusb/libusb/os/wince_usb.c +0 -888
  243. package/libusb/libusb/os/wince_usb.h +0 -126
  244. package/libusb/libusb/os/windows_nt_common.c +0 -1010
  245. package/libusb/libusb/os/windows_nt_common.h +0 -110
  246. package/libusb/libusb/os/windows_nt_shared_types.h +0 -147
  247. package/libusb/msvc/appveyor.bat +0 -27
  248. package/libusb/msvc/ddk_build.cmd +0 -219
  249. package/libusb/msvc/errno.h +0 -102
  250. package/libusb/msvc/fxload_sources +0 -23
  251. package/libusb/msvc/getopt_2005.vcproj +0 -288
  252. package/libusb/msvc/getopt_2010.vcxproj +0 -72
  253. package/libusb/msvc/getopt_sources +0 -24
  254. package/libusb/msvc/hotplugtest_sources +0 -20
  255. package/libusb/msvc/inttypes.h +0 -295
  256. package/libusb/msvc/libusb.dsw +0 -71
  257. package/libusb/msvc/libusb_2005.sln +0 -95
  258. package/libusb/msvc/libusb_2010.sln +0 -105
  259. package/libusb/msvc/libusb_2012.sln +0 -105
  260. package/libusb/msvc/libusb_dll.dsp +0 -194
  261. package/libusb/msvc/libusb_dll_2005.vcproj +0 -464
  262. package/libusb/msvc/libusb_dll_2012.vcxproj +0 -107
  263. package/libusb/msvc/libusb_dll_wince.vcproj +0 -1251
  264. package/libusb/msvc/libusb_sources +0 -43
  265. package/libusb/msvc/libusb_static.dsp +0 -174
  266. package/libusb/msvc/libusb_static_2005.vcproj +0 -390
  267. package/libusb/msvc/libusb_static_2012.vcxproj +0 -98
  268. package/libusb/msvc/libusb_static_wince.vcproj +0 -1179
  269. package/libusb/msvc/libusb_wince.sln +0 -246
  270. package/libusb/msvc/listdevs.dsp +0 -103
  271. package/libusb/msvc/listdevs_2005.vcproj +0 -360
  272. package/libusb/msvc/listdevs_sources +0 -20
  273. package/libusb/msvc/listdevs_wince.vcproj +0 -1120
  274. package/libusb/msvc/missing.c +0 -80
  275. package/libusb/msvc/stdint.h +0 -256
  276. package/libusb/msvc/stress_2005.vcproj +0 -390
  277. package/libusb/msvc/stress_2012.vcxproj +0 -87
  278. package/libusb/msvc/stress_sources +0 -21
  279. package/libusb/msvc/stress_wince.vcproj +0 -1128
  280. package/libusb/msvc/testlibusb_2012.vcxproj +0 -83
  281. package/libusb/msvc/testlibusb_sources +0 -20
  282. package/libusb/msvc/xusb.dsp +0 -102
  283. package/libusb/msvc/xusb_2005.vcproj +0 -344
  284. package/libusb/msvc/xusb_2012.vcxproj +0 -83
  285. package/libusb/msvc/xusb_sources +0 -20
  286. package/libusb/msvc/xusb_wince.vcproj +0 -1120
  287. 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.1",
5
+ "version": "2.2.0",
6
6
  "main": "dist/index.js",
7
7
  "engines": {
8
8
  "node": ">=10.16.0"
@@ -52,7 +52,7 @@
52
52
  "prebuild-download": "prebuildify-ci download"
53
53
  },
54
54
  "dependencies": {
55
- "@types/w3c-web-usb": "^1.0.4",
55
+ "@types/w3c-web-usb": "1.0.6",
56
56
  "node-addon-api": "^4.2.0",
57
57
  "node-gyp-build": "^4.3.0"
58
58
  },
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(
@@ -161,12 +161,7 @@ export class Interface {
161
161
  * The device must be open to use this method.
162
162
  * @param addr
163
163
  */
164
- public endpoint(addr: number): Endpoint {
165
- const endpoint = this.endpoints.find(item => item.address === addr);
166
- if (!endpoint) {
167
- throw new Error(`Endpoint not found for address: ${addr}`);
168
- }
169
-
170
- return endpoint;
164
+ public endpoint(addr: number): Endpoint | undefined {
165
+ return this.endpoints.find(item => item.address === addr);
171
166
  }
172
167
  }
@@ -368,14 +368,6 @@ export class WebUSBDevice implements USBDevice {
368
368
  }
369
369
  }
370
370
 
371
- public async isochronousTransferIn(_endpointNumber: number, _packetLengths: number[]): Promise<USBIsochronousInTransferResult> {
372
- throw new Error('isochronousTransferIn error: method not implemented');
373
- }
374
-
375
- public async isochronousTransferOut(_endpointNumber: number, _data: BufferSource, _packetLengths: number[]): Promise<USBIsochronousOutTransferResult> {
376
- throw new Error('isochronousTransferOut error: method not implemented');
377
- }
378
-
379
371
  public async reset(): Promise<void> {
380
372
  try {
381
373
  await this.deviceMutex.lock();
@@ -388,6 +380,18 @@ export class WebUSBDevice implements USBDevice {
388
380
  }
389
381
  }
390
382
 
383
+ public async isochronousTransferIn(_endpointNumber: number, _packetLengths: number[]): Promise<USBIsochronousInTransferResult> {
384
+ throw new Error('isochronousTransferIn error: method not implemented');
385
+ }
386
+
387
+ public async isochronousTransferOut(_endpointNumber: number, _data: BufferSource, _packetLengths: number[]): Promise<USBIsochronousOutTransferResult> {
388
+ throw new Error('isochronousTransferOut error: method not implemented');
389
+ }
390
+
391
+ public async forget(): Promise<void> {
392
+ throw new Error('forget error: method not implemented');
393
+ }
394
+
391
395
  private async initialize(): Promise<void> {
392
396
  try {
393
397
  await this.deviceMutex.lock();