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
@@ -20,23 +20,10 @@
20
20
  * along with this program; if not, write to the Free Software
21
21
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
22
22
  */
23
- #if !defined(_MSC_VER)
23
+
24
+ #include <config.h>
25
+
24
26
  #include <stdbool.h>
25
- #else
26
- #define __attribute__(x)
27
- #if !defined(bool)
28
- #define bool int
29
- #endif
30
- #if !defined(true)
31
- #define true (1 == 1)
32
- #endif
33
- #if !defined(false)
34
- #define false (!true)
35
- #endif
36
- #if defined(_PREFAST_)
37
- #pragma warning(disable:28193)
38
- #endif
39
- #endif
40
27
 
41
28
  #define FX_TYPE_UNDEFINED -1
42
29
  #define FX_TYPE_AN21 0 /* Original AnchorChips parts */
@@ -59,7 +46,7 @@
59
46
  extern "C" {
60
47
  #endif
61
48
 
62
- /*
49
+ /*
63
50
  * Automatically identified devices (VID, PID, type, designation).
64
51
  * TODO: Could use some validation. Also where's the FX2?
65
52
  */
@@ -113,6 +100,8 @@ extern int ezusb_load_eeprom(libusb_device_handle *device,
113
100
  /* Verbosity level (default 1). Can be increased or decreased with options v/q */
114
101
  extern int verbose;
115
102
 
103
+ extern void logerror(const char *format, ...) PRINTF_FORMAT(1, 2);
104
+
116
105
  #ifdef __cplusplus
117
106
  }
118
107
  #endif
@@ -21,6 +21,8 @@
21
21
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
22
22
  */
23
23
 
24
+ #include <config.h>
25
+
24
26
  #include <stdlib.h>
25
27
  #include <stdio.h>
26
28
  #include <string.h>
@@ -32,7 +34,7 @@
32
34
  #include "libusb.h"
33
35
  #include "ezusb.h"
34
36
 
35
- #if !defined(_WIN32) || defined(__CYGWIN__ )
37
+ #if !defined(_WIN32) || defined(__CYGWIN__)
36
38
  #include <syslog.h>
37
39
  static bool dosyslog = false;
38
40
  #include <strings.h>
@@ -47,15 +49,12 @@ static bool dosyslog = false;
47
49
  #define ARRAYSIZE(A) (sizeof(A)/sizeof((A)[0]))
48
50
  #endif
49
51
 
50
- void logerror(const char *format, ...)
51
- __attribute__ ((format (__printf__, 1, 2)));
52
-
53
52
  void logerror(const char *format, ...)
54
53
  {
55
54
  va_list ap;
56
55
  va_start(ap, format);
57
56
 
58
- #if !defined(_WIN32) || defined(__CYGWIN__ )
57
+ #if !defined(_WIN32) || defined(__CYGWIN__)
59
58
  if (dosyslog)
60
59
  vsyslog(LOG_ERR, format, ap);
61
60
  else
@@ -95,7 +95,7 @@ int main(int argc, char *argv[])
95
95
  }
96
96
 
97
97
  if (!libusb_has_capability (LIBUSB_CAP_HAS_HOTPLUG)) {
98
- printf ("Hotplug capabilites are not supported on this platform\n");
98
+ printf ("Hotplug capabilities are not supported on this platform\n");
99
99
  libusb_exit (NULL);
100
100
  return EXIT_FAILURE;
101
101
  }
@@ -22,24 +22,54 @@
22
22
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23
23
  */
24
24
 
25
- #include <unistd.h>
26
- #include <stdlib.h>
27
- #include <stdio.h>
25
+ #include <config.h>
26
+
28
27
  #include <errno.h>
29
28
  #include <signal.h>
29
+ #include <stdio.h>
30
+ #include <stdlib.h>
31
+ #ifdef HAVE_SYS_TIME_H
32
+ #include <sys/time.h>
33
+ #endif
34
+ #include <time.h>
30
35
 
31
- #include <libusb.h>
32
-
36
+ #include "libusb.h"
33
37
 
34
38
  #define EP_DATA_IN 0x82
35
39
  #define EP_ISO_IN 0x86
36
40
 
37
- static int do_exit = 0;
41
+ static volatile sig_atomic_t do_exit = 0;
38
42
  static struct libusb_device_handle *devh = NULL;
39
43
 
40
44
  static unsigned long num_bytes = 0, num_xfer = 0;
41
45
  static struct timeval tv_start;
42
46
 
47
+ static void get_timestamp(struct timeval *tv)
48
+ {
49
+ #if defined(PLATFORM_WINDOWS)
50
+ static LARGE_INTEGER frequency;
51
+ LARGE_INTEGER counter;
52
+
53
+ if (!frequency.QuadPart)
54
+ QueryPerformanceFrequency(&frequency);
55
+
56
+ QueryPerformanceCounter(&counter);
57
+ counter.QuadPart *= 1000000;
58
+ counter.QuadPart /= frequency.QuadPart;
59
+
60
+ tv->tv_sec = (long)(counter.QuadPart / 1000000ULL);
61
+ tv->tv_usec = (long)(counter.QuadPart % 1000000ULL);
62
+ #elif defined(HAVE_CLOCK_GETTIME)
63
+ struct timespec ts;
64
+
65
+ (void)clock_gettime(CLOCK_MONOTONIC, &ts);
66
+ tv->tv_sec = ts.tv_sec;
67
+ tv->tv_usec = (int)(ts.tv_nsec / 1000L);
68
+ #else
69
+ gettimeofday(tv, NULL);
70
+ #endif
71
+ }
72
+
43
73
  static void LIBUSB_CALL cb_xfr(struct libusb_transfer *xfr)
44
74
  {
45
75
  int i;
@@ -92,8 +122,10 @@ static int benchmark_in(uint8_t ep)
92
122
  num_iso_pack = 16;
93
123
 
94
124
  xfr = libusb_alloc_transfer(num_iso_pack);
95
- if (!xfr)
96
- return -ENOMEM;
125
+ if (!xfr) {
126
+ errno = ENOMEM;
127
+ return -1;
128
+ }
97
129
 
98
130
  if (ep == EP_ISO_IN) {
99
131
  libusb_fill_iso_transfer(xfr, devh, ep, buf,
@@ -103,7 +135,7 @@ static int benchmark_in(uint8_t ep)
103
135
  libusb_fill_bulk_transfer(xfr, devh, ep, buf,
104
136
  sizeof(buf), cb_xfr, NULL, 0);
105
137
 
106
- gettimeofday(&tv_start, NULL);
138
+ get_timestamp(&tv_start);
107
139
 
108
140
  /* NOTE: To reach maximum possible performance the program must
109
141
  * submit *multiple* transfers here, not just one.
@@ -125,36 +157,39 @@ static int benchmark_in(uint8_t ep)
125
157
  static void measure(void)
126
158
  {
127
159
  struct timeval tv_stop;
128
- unsigned int diff_msec;
160
+ unsigned long diff_msec;
129
161
 
130
- gettimeofday(&tv_stop, NULL);
162
+ get_timestamp(&tv_stop);
131
163
 
132
- diff_msec = (tv_stop.tv_sec - tv_start.tv_sec)*1000;
133
- diff_msec += (tv_stop.tv_usec - tv_start.tv_usec)/1000;
164
+ diff_msec = (tv_stop.tv_sec - tv_start.tv_sec) * 1000L;
165
+ diff_msec += (tv_stop.tv_usec - tv_start.tv_usec) / 1000L;
134
166
 
135
- printf("%lu transfers (total %lu bytes) in %u miliseconds => %lu bytes/sec\n",
136
- num_xfer, num_bytes, diff_msec, (num_bytes*1000)/diff_msec);
167
+ printf("%lu transfers (total %lu bytes) in %lu milliseconds => %lu bytes/sec\n",
168
+ num_xfer, num_bytes, diff_msec, (num_bytes * 1000L) / diff_msec);
137
169
  }
138
170
 
139
171
  static void sig_hdlr(int signum)
140
172
  {
141
- switch (signum) {
142
- case SIGINT:
143
- measure();
144
- do_exit = 1;
145
- break;
146
- }
173
+ (void)signum;
174
+
175
+ measure();
176
+ do_exit = 1;
147
177
  }
148
178
 
149
- int main(int argc, char **argv)
179
+ int main(void)
150
180
  {
151
181
  int rc;
182
+
183
+ #if defined(PLATFORM_POSIX)
152
184
  struct sigaction sigact;
153
185
 
154
186
  sigact.sa_handler = sig_hdlr;
155
187
  sigemptyset(&sigact.sa_mask);
156
188
  sigact.sa_flags = 0;
157
- sigaction(SIGINT, &sigact, NULL);
189
+ (void)sigaction(SIGINT, &sigact, NULL);
190
+ #else
191
+ (void)signal(SIGINT, sig_hdlr);
192
+ #endif
158
193
 
159
194
  rc = libusb_init(NULL);
160
195
  if (rc < 0) {
@@ -184,7 +219,7 @@ int main(int argc, char **argv)
184
219
 
185
220
  /* Measurement has already been done by the signal handler. */
186
221
 
187
- libusb_release_interface(devh, 0);
222
+ libusb_release_interface(devh, 2);
188
223
  out:
189
224
  if (devh)
190
225
  libusb_close(devh);
@@ -21,18 +21,14 @@
21
21
  #include <string.h>
22
22
  #include "libusb.h"
23
23
 
24
- #if defined(_MSC_VER) && (_MSC_VER < 1900)
25
- #define snprintf _snprintf
26
- #endif
27
-
28
24
  int verbose = 0;
29
25
 
30
26
  static void print_endpoint_comp(const struct libusb_ss_endpoint_companion_descriptor *ep_comp)
31
27
  {
32
28
  printf(" USB 3.0 Endpoint Companion:\n");
33
- printf(" bMaxBurst: %d\n", ep_comp->bMaxBurst);
34
- printf(" bmAttributes: 0x%02x\n", ep_comp->bmAttributes);
35
- printf(" wBytesPerInterval: %d\n", ep_comp->wBytesPerInterval);
29
+ printf(" bMaxBurst: %u\n", ep_comp->bMaxBurst);
30
+ printf(" bmAttributes: %02xh\n", ep_comp->bmAttributes);
31
+ printf(" wBytesPerInterval: %u\n", ep_comp->wBytesPerInterval);
36
32
  }
37
33
 
38
34
  static void print_endpoint(const struct libusb_endpoint_descriptor *endpoint)
@@ -40,21 +36,20 @@ static void print_endpoint(const struct libusb_endpoint_descriptor *endpoint)
40
36
  int i, ret;
41
37
 
42
38
  printf(" Endpoint:\n");
43
- printf(" bEndpointAddress: %02xh\n", endpoint->bEndpointAddress);
44
- printf(" bmAttributes: %02xh\n", endpoint->bmAttributes);
45
- printf(" wMaxPacketSize: %d\n", endpoint->wMaxPacketSize);
46
- printf(" bInterval: %d\n", endpoint->bInterval);
47
- printf(" bRefresh: %d\n", endpoint->bRefresh);
48
- printf(" bSynchAddress: %d\n", endpoint->bSynchAddress);
39
+ printf(" bEndpointAddress: %02xh\n", endpoint->bEndpointAddress);
40
+ printf(" bmAttributes: %02xh\n", endpoint->bmAttributes);
41
+ printf(" wMaxPacketSize: %u\n", endpoint->wMaxPacketSize);
42
+ printf(" bInterval: %u\n", endpoint->bInterval);
43
+ printf(" bRefresh: %u\n", endpoint->bRefresh);
44
+ printf(" bSynchAddress: %u\n", endpoint->bSynchAddress);
49
45
 
50
46
  for (i = 0; i < endpoint->extra_length;) {
51
47
  if (LIBUSB_DT_SS_ENDPOINT_COMPANION == endpoint->extra[i + 1]) {
52
48
  struct libusb_ss_endpoint_companion_descriptor *ep_comp;
53
49
 
54
50
  ret = libusb_get_ss_endpoint_companion_descriptor(NULL, endpoint, &ep_comp);
55
- if (LIBUSB_SUCCESS != ret) {
51
+ if (LIBUSB_SUCCESS != ret)
56
52
  continue;
57
- }
58
53
 
59
54
  print_endpoint_comp(ep_comp);
60
55
 
@@ -70,13 +65,13 @@ static void print_altsetting(const struct libusb_interface_descriptor *interface
70
65
  uint8_t i;
71
66
 
72
67
  printf(" Interface:\n");
73
- printf(" bInterfaceNumber: %d\n", interface->bInterfaceNumber);
74
- printf(" bAlternateSetting: %d\n", interface->bAlternateSetting);
75
- printf(" bNumEndpoints: %d\n", interface->bNumEndpoints);
76
- printf(" bInterfaceClass: %d\n", interface->bInterfaceClass);
77
- printf(" bInterfaceSubClass: %d\n", interface->bInterfaceSubClass);
78
- printf(" bInterfaceProtocol: %d\n", interface->bInterfaceProtocol);
79
- printf(" iInterface: %d\n", interface->iInterface);
68
+ printf(" bInterfaceNumber: %u\n", interface->bInterfaceNumber);
69
+ printf(" bAlternateSetting: %u\n", interface->bAlternateSetting);
70
+ printf(" bNumEndpoints: %u\n", interface->bNumEndpoints);
71
+ printf(" bInterfaceClass: %u\n", interface->bInterfaceClass);
72
+ printf(" bInterfaceSubClass: %u\n", interface->bInterfaceSubClass);
73
+ printf(" bInterfaceProtocol: %u\n", interface->bInterfaceProtocol);
74
+ printf(" iInterface: %u\n", interface->iInterface);
80
75
 
81
76
  for (i = 0; i < interface->bNumEndpoints; i++)
82
77
  print_endpoint(&interface->endpoint[i]);
@@ -85,58 +80,58 @@ static void print_altsetting(const struct libusb_interface_descriptor *interface
85
80
  static void print_2_0_ext_cap(struct libusb_usb_2_0_extension_descriptor *usb_2_0_ext_cap)
86
81
  {
87
82
  printf(" USB 2.0 Extension Capabilities:\n");
88
- printf(" bDevCapabilityType: %d\n", usb_2_0_ext_cap->bDevCapabilityType);
89
- printf(" bmAttributes: 0x%x\n", usb_2_0_ext_cap->bmAttributes);
83
+ printf(" bDevCapabilityType: %u\n", usb_2_0_ext_cap->bDevCapabilityType);
84
+ printf(" bmAttributes: %08xh\n", usb_2_0_ext_cap->bmAttributes);
90
85
  }
91
86
 
92
87
  static void print_ss_usb_cap(struct libusb_ss_usb_device_capability_descriptor *ss_usb_cap)
93
88
  {
94
89
  printf(" USB 3.0 Capabilities:\n");
95
- printf(" bDevCapabilityType: %d\n", ss_usb_cap->bDevCapabilityType);
96
- printf(" bmAttributes: 0x%x\n", ss_usb_cap->bmAttributes);
97
- printf(" wSpeedSupported: 0x%x\n", ss_usb_cap->wSpeedSupported);
98
- printf(" bFunctionalitySupport: %d\n", ss_usb_cap->bFunctionalitySupport);
99
- printf(" bU1devExitLat: %d\n", ss_usb_cap->bU1DevExitLat);
100
- printf(" bU2devExitLat: %d\n", ss_usb_cap->bU2DevExitLat);
90
+ printf(" bDevCapabilityType: %u\n", ss_usb_cap->bDevCapabilityType);
91
+ printf(" bmAttributes: %02xh\n", ss_usb_cap->bmAttributes);
92
+ printf(" wSpeedSupported: %u\n", ss_usb_cap->wSpeedSupported);
93
+ printf(" bFunctionalitySupport: %u\n", ss_usb_cap->bFunctionalitySupport);
94
+ printf(" bU1devExitLat: %u\n", ss_usb_cap->bU1DevExitLat);
95
+ printf(" bU2devExitLat: %u\n", ss_usb_cap->bU2DevExitLat);
101
96
  }
102
97
 
103
98
  static void print_bos(libusb_device_handle *handle)
104
99
  {
105
100
  struct libusb_bos_descriptor *bos;
101
+ uint8_t i;
106
102
  int ret;
107
103
 
108
104
  ret = libusb_get_bos_descriptor(handle, &bos);
109
- if (0 > ret) {
105
+ if (ret < 0)
110
106
  return;
111
- }
112
107
 
113
108
  printf(" Binary Object Store (BOS):\n");
114
- printf(" wTotalLength: %d\n", bos->wTotalLength);
115
- printf(" bNumDeviceCaps: %d\n", bos->bNumDeviceCaps);
109
+ printf(" wTotalLength: %u\n", bos->wTotalLength);
110
+ printf(" bNumDeviceCaps: %u\n", bos->bNumDeviceCaps);
116
111
 
117
- if(bos->dev_capability[0]->bDevCapabilityType == LIBUSB_BT_USB_2_0_EXTENSION) {
112
+ for (i = 0; i < bos->bNumDeviceCaps; i++) {
113
+ struct libusb_bos_dev_capability_descriptor *dev_cap = bos->dev_capability[i];
118
114
 
119
- struct libusb_usb_2_0_extension_descriptor *usb_2_0_extension;
120
- ret = libusb_get_usb_2_0_extension_descriptor(NULL, bos->dev_capability[0],&usb_2_0_extension);
121
- if (0 > ret) {
122
- return;
123
- }
115
+ if (dev_cap->bDevCapabilityType == LIBUSB_BT_USB_2_0_EXTENSION) {
116
+ struct libusb_usb_2_0_extension_descriptor *usb_2_0_extension;
124
117
 
125
- print_2_0_ext_cap(usb_2_0_extension);
126
- libusb_free_usb_2_0_extension_descriptor(usb_2_0_extension);
127
- }
118
+ ret = libusb_get_usb_2_0_extension_descriptor(NULL, dev_cap, &usb_2_0_extension);
119
+ if (ret < 0)
120
+ return;
128
121
 
129
- if(bos->dev_capability[0]->bDevCapabilityType == LIBUSB_BT_SS_USB_DEVICE_CAPABILITY) {
122
+ print_2_0_ext_cap(usb_2_0_extension);
123
+ libusb_free_usb_2_0_extension_descriptor(usb_2_0_extension);
124
+ } else if (dev_cap->bDevCapabilityType == LIBUSB_BT_SS_USB_DEVICE_CAPABILITY) {
125
+ struct libusb_ss_usb_device_capability_descriptor *ss_dev_cap;
130
126
 
131
- struct libusb_ss_usb_device_capability_descriptor *dev_cap;
132
- ret = libusb_get_ss_usb_device_capability_descriptor(NULL, bos->dev_capability[0],&dev_cap);
133
- if (0 > ret) {
134
- return;
135
- }
127
+ ret = libusb_get_ss_usb_device_capability_descriptor(NULL, dev_cap, &ss_dev_cap);
128
+ if (ret < 0)
129
+ return;
136
130
 
137
- print_ss_usb_cap(dev_cap);
138
- libusb_free_ss_usb_device_capability_descriptor(dev_cap);
139
- }
131
+ print_ss_usb_cap(ss_dev_cap);
132
+ libusb_free_ss_usb_device_capability_descriptor(ss_dev_cap);
133
+ }
134
+ }
140
135
 
141
136
  libusb_free_bos_descriptor(bos);
142
137
  }
@@ -154,79 +149,71 @@ static void print_configuration(struct libusb_config_descriptor *config)
154
149
  uint8_t i;
155
150
 
156
151
  printf(" Configuration:\n");
157
- printf(" wTotalLength: %d\n", config->wTotalLength);
158
- printf(" bNumInterfaces: %d\n", config->bNumInterfaces);
159
- printf(" bConfigurationValue: %d\n", config->bConfigurationValue);
160
- printf(" iConfiguration: %d\n", config->iConfiguration);
161
- printf(" bmAttributes: %02xh\n", config->bmAttributes);
162
- printf(" MaxPower: %d\n", config->MaxPower);
152
+ printf(" wTotalLength: %u\n", config->wTotalLength);
153
+ printf(" bNumInterfaces: %u\n", config->bNumInterfaces);
154
+ printf(" bConfigurationValue: %u\n", config->bConfigurationValue);
155
+ printf(" iConfiguration: %u\n", config->iConfiguration);
156
+ printf(" bmAttributes: %02xh\n", config->bmAttributes);
157
+ printf(" MaxPower: %u\n", config->MaxPower);
163
158
 
164
159
  for (i = 0; i < config->bNumInterfaces; i++)
165
160
  print_interface(&config->interface[i]);
166
161
  }
167
162
 
168
- static int print_device(libusb_device *dev, int level)
163
+ static void print_device(libusb_device *dev, libusb_device_handle *handle)
169
164
  {
170
165
  struct libusb_device_descriptor desc;
171
- libusb_device_handle *handle = NULL;
172
- char description[260];
173
- char string[256];
166
+ unsigned char string[256];
167
+ const char *speed;
174
168
  int ret;
175
169
  uint8_t i;
176
170
 
171
+ switch (libusb_get_device_speed(dev)) {
172
+ case LIBUSB_SPEED_LOW: speed = "1.5M"; break;
173
+ case LIBUSB_SPEED_FULL: speed = "12M"; break;
174
+ case LIBUSB_SPEED_HIGH: speed = "480M"; break;
175
+ case LIBUSB_SPEED_SUPER: speed = "5G"; break;
176
+ case LIBUSB_SPEED_SUPER_PLUS: speed = "10G"; break;
177
+ default: speed = "Unknown";
178
+ }
179
+
177
180
  ret = libusb_get_device_descriptor(dev, &desc);
178
181
  if (ret < 0) {
179
182
  fprintf(stderr, "failed to get device descriptor");
180
- return -1;
183
+ return;
181
184
  }
182
185
 
183
- ret = libusb_open(dev, &handle);
184
- if (LIBUSB_SUCCESS == ret) {
186
+ printf("Dev (bus %u, device %u): %04X - %04X speed: %s\n",
187
+ libusb_get_bus_number(dev), libusb_get_device_address(dev),
188
+ desc.idVendor, desc.idProduct, speed);
189
+
190
+ if (!handle)
191
+ libusb_open(dev, &handle);
192
+
193
+ if (handle) {
185
194
  if (desc.iManufacturer) {
186
195
  ret = libusb_get_string_descriptor_ascii(handle, desc.iManufacturer, string, sizeof(string));
187
196
  if (ret > 0)
188
- snprintf(description, sizeof(description), "%s - ", string);
189
- else
190
- snprintf(description, sizeof(description), "%04X - ",
191
- desc.idVendor);
197
+ printf(" Manufacturer: %s\n", (char *)string);
192
198
  }
193
- else
194
- snprintf(description, sizeof(description), "%04X - ",
195
- desc.idVendor);
196
199
 
197
200
  if (desc.iProduct) {
198
201
  ret = libusb_get_string_descriptor_ascii(handle, desc.iProduct, string, sizeof(string));
199
202
  if (ret > 0)
200
- snprintf(description + strlen(description), sizeof(description) -
201
- strlen(description), "%s", string);
202
- else
203
- snprintf(description + strlen(description), sizeof(description) -
204
- strlen(description), "%04X", desc.idProduct);
203
+ printf(" Product: %s\n", (char *)string);
205
204
  }
206
- else
207
- snprintf(description + strlen(description), sizeof(description) -
208
- strlen(description), "%04X", desc.idProduct);
209
- }
210
- else {
211
- snprintf(description, sizeof(description), "%04X - %04X",
212
- desc.idVendor, desc.idProduct);
213
- }
214
205
 
215
- printf("%.*sDev (bus %d, device %d): %s\n", level * 2, " ",
216
- libusb_get_bus_number(dev), libusb_get_device_address(dev), description);
217
-
218
- if (handle && verbose) {
219
- if (desc.iSerialNumber) {
206
+ if (desc.iSerialNumber && verbose) {
220
207
  ret = libusb_get_string_descriptor_ascii(handle, desc.iSerialNumber, string, sizeof(string));
221
208
  if (ret > 0)
222
- printf("%.*s - Serial Number: %s\n", level * 2,
223
- " ", string);
209
+ printf(" Serial Number: %s\n", (char *)string);
224
210
  }
225
211
  }
226
212
 
227
213
  if (verbose) {
228
214
  for (i = 0; i < desc.bNumConfigurations; i++) {
229
215
  struct libusb_config_descriptor *config;
216
+
230
217
  ret = libusb_get_config_descriptor(dev, i, &config);
231
218
  if (LIBUSB_SUCCESS != ret) {
232
219
  printf(" Couldn't retrieve descriptors\n");
@@ -238,40 +225,87 @@ static int print_device(libusb_device *dev, int level)
238
225
  libusb_free_config_descriptor(config);
239
226
  }
240
227
 
241
- if (handle && desc.bcdUSB >= 0x0201) {
228
+ if (handle && desc.bcdUSB >= 0x0201)
242
229
  print_bos(handle);
243
- }
244
230
  }
245
231
 
246
232
  if (handle)
247
233
  libusb_close(handle);
234
+ }
235
+
236
+ #ifdef __linux__
237
+ #include <errno.h>
238
+ #include <fcntl.h>
239
+ #include <unistd.h>
240
+
241
+ static int test_wrapped_device(const char *device_name)
242
+ {
243
+ libusb_device_handle *handle;
244
+ int r, fd;
248
245
 
246
+ fd = open(device_name, O_RDWR);
247
+ if (fd < 0) {
248
+ printf("Error could not open %s: %s\n", device_name, strerror(errno));
249
+ return 1;
250
+ }
251
+ r = libusb_wrap_sys_device(NULL, fd, &handle);
252
+ if (r) {
253
+ printf("Error wrapping device: %s: %s\n", device_name, libusb_strerror(r));
254
+ close(fd);
255
+ return 1;
256
+ }
257
+ print_device(libusb_get_device(handle), handle);
258
+ close(fd);
249
259
  return 0;
250
260
  }
261
+ #else
262
+ static int test_wrapped_device(const char *device_name)
263
+ {
264
+ (void)device_name;
265
+ printf("Testing wrapped devices is not supported on your platform\n");
266
+ return 1;
267
+ }
268
+ #endif
251
269
 
252
270
  int main(int argc, char *argv[])
253
271
  {
272
+ const char *device_name = NULL;
254
273
  libusb_device **devs;
255
274
  ssize_t cnt;
256
275
  int r, i;
257
276
 
258
- if (argc > 1 && !strcmp(argv[1], "-v"))
259
- verbose = 1;
277
+ for (i = 1; i < argc; i++) {
278
+ if (!strcmp(argv[i], "-v")) {
279
+ verbose = 1;
280
+ } else if (!strcmp(argv[i], "-d") && (i + 1) < argc) {
281
+ i++;
282
+ device_name = argv[i];
283
+ } else {
284
+ printf("Usage %s [-v] [-d </dev/bus/usb/...>]\n", argv[0]);
285
+ printf("Note use -d to test libusb_wrap_sys_device()\n");
286
+ return 1;
287
+ }
288
+ }
260
289
 
261
290
  r = libusb_init(NULL);
262
291
  if (r < 0)
263
292
  return r;
264
293
 
265
- cnt = libusb_get_device_list(NULL, &devs);
266
- if (cnt < 0)
267
- return (int)cnt;
294
+ if (device_name) {
295
+ r = test_wrapped_device(device_name);
296
+ } else {
297
+ cnt = libusb_get_device_list(NULL, &devs);
298
+ if (cnt < 0) {
299
+ libusb_exit(NULL);
300
+ return 1;
301
+ }
268
302
 
269
- for (i = 0; devs[i]; ++i) {
270
- print_device(devs[i], 0);
271
- }
303
+ for (i = 0; devs[i]; i++)
304
+ print_device(devs[i], NULL);
272
305
 
273
- libusb_free_device_list(devs, 1);
306
+ libusb_free_device_list(devs, 1);
307
+ }
274
308
 
275
309
  libusb_exit(NULL);
276
- return 0;
310
+ return r;
277
311
  }