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
@@ -0,0 +1,214 @@
1
+ /*
2
+ * libusb event abstraction on Microsoft Windows
3
+ *
4
+ * Copyright © 2020 Chris Dickens <christopher.a.dickens@gmail.com>
5
+ *
6
+ * This library is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License as published by the Free Software Foundation; either
9
+ * version 2.1 of the License, or (at your option) any later version.
10
+ *
11
+ * This library is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with this library; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
+ */
20
+
21
+ #include <config.h>
22
+
23
+ #include "libusbi.h"
24
+ #include "windows_common.h"
25
+
26
+ int usbi_create_event(usbi_event_t *event)
27
+ {
28
+ event->hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
29
+ if (event->hEvent == NULL) {
30
+ usbi_err(NULL, "CreateEvent failed: %s", windows_error_str(0));
31
+ return LIBUSB_ERROR_OTHER;
32
+ }
33
+
34
+ return 0;
35
+ }
36
+
37
+ void usbi_destroy_event(usbi_event_t *event)
38
+ {
39
+ if (!CloseHandle(event->hEvent))
40
+ usbi_warn(NULL, "CloseHandle failed: %s", windows_error_str(0));
41
+ }
42
+
43
+ void usbi_signal_event(usbi_event_t *event)
44
+ {
45
+ if (!SetEvent(event->hEvent))
46
+ usbi_warn(NULL, "SetEvent failed: %s", windows_error_str(0));
47
+ }
48
+
49
+ void usbi_clear_event(usbi_event_t *event)
50
+ {
51
+ if (!ResetEvent(event->hEvent))
52
+ usbi_warn(NULL, "ResetEvent failed: %s", windows_error_str(0));
53
+ }
54
+
55
+ #ifdef HAVE_OS_TIMER
56
+ int usbi_create_timer(usbi_timer_t *timer)
57
+ {
58
+ timer->hTimer = CreateWaitableTimer(NULL, TRUE, NULL);
59
+ if (timer->hTimer == NULL) {
60
+ usbi_warn(NULL, "CreateWaitableTimer failed: %s", windows_error_str(0));
61
+ return LIBUSB_ERROR_OTHER;
62
+ }
63
+
64
+ return 0;
65
+ }
66
+
67
+ void usbi_destroy_timer(usbi_timer_t *timer)
68
+ {
69
+ if (!CloseHandle(timer->hTimer))
70
+ usbi_warn(NULL, "CloseHandle failed: %s", windows_error_str(0));
71
+ }
72
+
73
+ int usbi_arm_timer(usbi_timer_t *timer, const struct timespec *timeout)
74
+ {
75
+ struct timespec systime, remaining;
76
+ FILETIME filetime;
77
+ LARGE_INTEGER dueTime;
78
+
79
+ /* Transfer timeouts are based on the monotonic clock and the waitable
80
+ * timers on the system clock. This requires a conversion between the
81
+ * two, so we calculate the remaining time relative to the monotonic
82
+ * clock and calculate an absolute system time for the timer expiration.
83
+ * Note that if the timeout has already passed, the remaining time will
84
+ * be negative and thus an absolute system time in the past will be set.
85
+ * This works just as intended because the timer becomes signalled
86
+ * immediately. */
87
+ usbi_get_monotonic_time(&systime);
88
+
89
+ TIMESPEC_SUB(timeout, &systime, &remaining);
90
+
91
+ GetSystemTimeAsFileTime(&filetime);
92
+ dueTime.LowPart = filetime.dwLowDateTime;
93
+ dueTime.HighPart = filetime.dwHighDateTime;
94
+ dueTime.QuadPart += (remaining.tv_sec * 10000000LL) + (remaining.tv_nsec / 100LL);
95
+
96
+ if (!SetWaitableTimer(timer->hTimer, &dueTime, 0, NULL, NULL, FALSE)) {
97
+ usbi_warn(NULL, "SetWaitableTimer failed: %s", windows_error_str(0));
98
+ return LIBUSB_ERROR_OTHER;
99
+ }
100
+
101
+ return 0;
102
+ }
103
+
104
+ int usbi_disarm_timer(usbi_timer_t *timer)
105
+ {
106
+ LARGE_INTEGER dueTime;
107
+
108
+ /* A manual-reset waitable timer will stay in the signalled state until
109
+ * another call to SetWaitableTimer() is made. It is possible that the
110
+ * timer has already expired by the time we come in to disarm it, so to
111
+ * be entirely sure the timer is disarmed and not in the signalled state,
112
+ * we will set it with an impossibly large expiration and immediately
113
+ * cancel. */
114
+ dueTime.QuadPart = LLONG_MAX;
115
+ if (!SetWaitableTimer(timer->hTimer, &dueTime, 0, NULL, NULL, FALSE)) {
116
+ usbi_warn(NULL, "SetWaitableTimer failed: %s", windows_error_str(0));
117
+ return LIBUSB_ERROR_OTHER;
118
+ }
119
+
120
+ if (!CancelWaitableTimer(timer->hTimer)) {
121
+ usbi_warn(NULL, "SetWaitableTimer failed: %s", windows_error_str(0));
122
+ return LIBUSB_ERROR_OTHER;
123
+ }
124
+
125
+ return 0;
126
+ }
127
+ #endif
128
+
129
+ int usbi_alloc_event_data(struct libusb_context *ctx)
130
+ {
131
+ struct usbi_event_source *ievent_source;
132
+ HANDLE *handles;
133
+ size_t i = 0;
134
+
135
+ /* Event sources are only added during usbi_io_init(). We should not
136
+ * be running this function again if the event data has already been
137
+ * allocated. */
138
+ if (ctx->event_data) {
139
+ usbi_warn(ctx, "program assertion failed - event data already allocated");
140
+ return LIBUSB_ERROR_OTHER;
141
+ }
142
+
143
+ ctx->event_data_cnt = 0;
144
+ for_each_event_source(ctx, ievent_source)
145
+ ctx->event_data_cnt++;
146
+
147
+ /* We only expect up to two HANDLEs to wait on, one for the internal
148
+ * signalling event and the other for the timer. */
149
+ if (ctx->event_data_cnt != 1 && ctx->event_data_cnt != 2) {
150
+ usbi_err(ctx, "program assertion failed - expected exactly 1 or 2 HANDLEs");
151
+ return LIBUSB_ERROR_OTHER;
152
+ }
153
+
154
+ handles = calloc(ctx->event_data_cnt, sizeof(HANDLE));
155
+ if (!handles)
156
+ return LIBUSB_ERROR_NO_MEM;
157
+
158
+ for_each_event_source(ctx, ievent_source) {
159
+ handles[i] = ievent_source->data.os_handle;
160
+ i++;
161
+ }
162
+
163
+ ctx->event_data = handles;
164
+ return 0;
165
+ }
166
+
167
+ int usbi_wait_for_events(struct libusb_context *ctx,
168
+ struct usbi_reported_events *reported_events, int timeout_ms)
169
+ {
170
+ HANDLE *handles = ctx->event_data;
171
+ DWORD num_handles = (DWORD)ctx->event_data_cnt;
172
+ DWORD result;
173
+
174
+ usbi_dbg(ctx, "WaitForMultipleObjects() for %lu HANDLEs with timeout in %dms", ULONG_CAST(num_handles), timeout_ms);
175
+ result = WaitForMultipleObjects(num_handles, handles, FALSE, (DWORD)timeout_ms);
176
+ usbi_dbg(ctx, "WaitForMultipleObjects() returned %lu", ULONG_CAST(result));
177
+ if (result == WAIT_TIMEOUT) {
178
+ if (usbi_using_timer(ctx))
179
+ goto done;
180
+ return LIBUSB_ERROR_TIMEOUT;
181
+ } else if (result == WAIT_FAILED) {
182
+ usbi_err(ctx, "WaitForMultipleObjects() failed: %s", windows_error_str(0));
183
+ return LIBUSB_ERROR_IO;
184
+ }
185
+
186
+ result -= WAIT_OBJECT_0;
187
+
188
+ /* handles[0] is always the internal signalling event */
189
+ if (result == 0)
190
+ reported_events->event_triggered = 1;
191
+ else
192
+ reported_events->event_triggered = 0;
193
+
194
+ #ifdef HAVE_OS_TIMER
195
+ /* on timer configurations, handles[1] is the timer */
196
+ if (usbi_using_timer(ctx)) {
197
+ /* The WaitForMultipleObjects() function reports the index of
198
+ * the first object that became signalled. If the internal
199
+ * signalling event was reported, we need to also check and
200
+ * report whether the timer is in the signalled state. */
201
+ if (result == 1 || WaitForSingleObject(handles[1], 0) == WAIT_OBJECT_0)
202
+ reported_events->timer_triggered = 1;
203
+ else
204
+ reported_events->timer_triggered = 0;
205
+ } else {
206
+ reported_events->timer_triggered = 0;
207
+ }
208
+ #endif
209
+
210
+ done:
211
+ /* no events are ever reported to the backend */
212
+ reported_events->num_ready = 0;
213
+ return LIBUSB_SUCCESS;
214
+ }
@@ -1,6 +1,7 @@
1
1
  /*
2
- * Header file for missing WinCE functionality
3
- * Copyright © 2012-2013 RealVNC Ltd.
2
+ * libusb event abstraction on Microsoft Windows
3
+ *
4
+ * Copyright © 2020 Chris Dickens <christopher.a.dickens@gmail.com>
4
5
  *
5
6
  * This library is free software; you can redistribute it and/or
6
7
  * modify it under the terms of the GNU Lesser General Public
@@ -17,16 +18,29 @@
17
18
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
19
  */
19
20
 
20
- #ifndef MISSING_H
21
- #define MISSING_H
21
+ #ifndef LIBUSB_EVENTS_WINDOWS_H
22
+ #define LIBUSB_EVENTS_WINDOWS_H
22
23
 
23
- /* Windows CE doesn't have SleepEx() - Fallback to Sleep() */
24
- #define SleepEx(m, a) Sleep(m)
24
+ typedef HANDLE usbi_os_handle_t;
25
+ #define USBI_OS_HANDLE_FORMAT_STRING "HANDLE %p"
25
26
 
26
- /* Windows CE doesn't have any APIs to query environment variables.
27
- *
28
- * This contains a registry based implementation of getenv.
29
- */
30
- char *getenv(const char *name);
27
+ typedef struct usbi_event {
28
+ HANDLE hEvent;
29
+ } usbi_event_t;
30
+ #define USBI_EVENT_OS_HANDLE(e) ((e)->hEvent)
31
+ #define USBI_EVENT_POLL_EVENTS 0
32
+ #define USBI_INVALID_EVENT { INVALID_HANDLE_VALUE }
33
+
34
+ #define HAVE_OS_TIMER 1
35
+ typedef struct usbi_timer {
36
+ HANDLE hTimer;
37
+ } usbi_timer_t;
38
+ #define USBI_TIMER_OS_HANDLE(t) ((t)->hTimer)
39
+ #define USBI_TIMER_POLL_EVENTS 0
40
+
41
+ static inline int usbi_timer_valid(usbi_timer_t *timer)
42
+ {
43
+ return timer->hTimer != NULL;
44
+ }
31
45
 
32
46
  #endif
@@ -97,20 +97,20 @@ WatchedEntry::WatchedEntry(BMessenger *messenger, entry_ref *ref)
97
97
  unsigned long session_id = (unsigned long)&fDevice;
98
98
 
99
99
  usbi_mutex_lock(&active_contexts_lock);
100
- list_for_each_entry(ctx, &active_contexts_list, list, struct libusb_context) {
100
+ for_each_context(ctx) {
101
101
  struct libusb_device *dev = usbi_get_device_by_session_id(ctx, session_id);
102
102
  if (dev) {
103
- usbi_dbg("using previously allocated device with location %lu", session_id);
103
+ usbi_dbg(NULL, "using previously allocated device with location %lu", session_id);
104
104
  libusb_unref_device(dev);
105
105
  continue;
106
106
  }
107
- usbi_dbg("allocating new device with location %lu", session_id);
107
+ usbi_dbg(NULL, "allocating new device with location %lu", session_id);
108
108
  dev = usbi_alloc_device(ctx, session_id);
109
109
  if (!dev) {
110
- usbi_dbg("device allocation failed");
110
+ usbi_dbg(NULL, "device allocation failed");
111
111
  continue;
112
112
  }
113
- *((USBDevice **)dev->os_priv) = fDevice;
113
+ *((USBDevice **)usbi_get_device_priv(dev)) = fDevice;
114
114
 
115
115
  // Calculate pseudo-device-address
116
116
  int addr, tmp;
@@ -125,11 +125,16 @@ WatchedEntry::WatchedEntry(BMessenger *messenger, entry_ref *ref)
125
125
  addr += tmp + 1;
126
126
  parent_path.GetParent(&parent_path);
127
127
  }
128
- sscanf(path.Path(), "/dev/bus/usb/%d", &dev->bus_number);
128
+ sscanf(path.Path(), "/dev/bus/usb/%hhu", &dev->bus_number);
129
129
  dev->device_address = addr - (dev->bus_number + 1);
130
130
 
131
+ static_assert(sizeof(dev->device_descriptor) == sizeof(usb_device_descriptor),
132
+ "mismatch between libusb and OS device descriptor sizes");
133
+ memcpy(&dev->device_descriptor, fDevice->Descriptor(), LIBUSB_DT_DEVICE_SIZE);
134
+ usbi_localize_device_descriptor(&dev->device_descriptor);
135
+
131
136
  if (usbi_sanitize_device(dev) < 0) {
132
- usbi_dbg("device sanitization failed");
137
+ usbi_dbg(NULL, "device sanitization failed");
133
138
  libusb_unref_device(dev);
134
139
  continue;
135
140
  }
@@ -167,13 +172,13 @@ WatchedEntry::~WatchedEntry()
167
172
  unsigned long session_id = (unsigned long)&fDevice;
168
173
 
169
174
  usbi_mutex_lock(&active_contexts_lock);
170
- list_for_each_entry(ctx, &active_contexts_list, list, struct libusb_context) {
175
+ for_each_context(ctx) {
171
176
  dev = usbi_get_device_by_session_id(ctx, session_id);
172
177
  if (dev != NULL) {
173
178
  usbi_disconnect_device(dev);
174
179
  libusb_unref_device(dev);
175
180
  } else {
176
- usbi_dbg("device with location %lu not found", session_id);
181
+ usbi_dbg(ctx, "device with location %lu not found", session_id);
177
182
  }
178
183
  }
179
184
  usbi_mutex_static_unlock(&active_contexts_lock);
@@ -38,22 +38,22 @@ public:
38
38
  const char* Location() const;
39
39
  uint8 CountConfigurations() const;
40
40
  const usb_device_descriptor* Descriptor() const;
41
- const usb_configuration_descriptor* ConfigurationDescriptor(uint32) const;
41
+ const usb_configuration_descriptor* ConfigurationDescriptor(uint8) const;
42
42
  const usb_configuration_descriptor* ActiveConfiguration() const;
43
43
  uint8 EndpointToIndex(uint8) const;
44
44
  uint8 EndpointToInterface(uint8) const;
45
- int ClaimInterface(int);
46
- int ReleaseInterface(int);
47
- int CheckInterfacesFree(int);
48
- int SetActiveConfiguration(int);
49
- int ActiveConfigurationIndex() const;
45
+ int ClaimInterface(uint8);
46
+ int ReleaseInterface(uint8);
47
+ int CheckInterfacesFree(uint8);
48
+ void SetActiveConfiguration(uint8);
49
+ uint8 ActiveConfigurationIndex() const;
50
50
  bool InitCheck();
51
51
  private:
52
52
  int Initialise();
53
53
  unsigned int fClaimedInterfaces; // Max Interfaces can be 32. Using a bitmask
54
54
  usb_device_descriptor fDeviceDescriptor;
55
55
  unsigned char** fConfigurationDescriptors;
56
- int fActiveConfiguration;
56
+ uint8 fActiveConfiguration;
57
57
  char* fPath;
58
58
  map<uint8,uint8> fConfigToIndex;
59
59
  map<uint8,uint8>* fEndpointToIndex;
@@ -65,11 +65,11 @@ class USBDeviceHandle {
65
65
  public:
66
66
  USBDeviceHandle(USBDevice *dev);
67
67
  virtual ~USBDeviceHandle();
68
- int ClaimInterface(int);
69
- int ReleaseInterface(int);
70
- int SetConfiguration(int);
71
- int SetAltSetting(int, int);
72
- int ClearHalt(int);
68
+ int ClaimInterface(uint8);
69
+ int ReleaseInterface(uint8);
70
+ int SetConfiguration(uint8);
71
+ int SetAltSetting(uint8, uint8);
72
+ int ClearHalt(uint8);
73
73
  status_t SubmitTransfer(struct usbi_transfer *);
74
74
  status_t CancelTransfer(USBTransfer *);
75
75
  bool InitCheck();
@@ -26,7 +26,7 @@
26
26
 
27
27
  #include "haiku_usb.h"
28
28
 
29
- int _errno_to_libusb(int status)
29
+ static int _errno_to_libusb(int status)
30
30
  {
31
31
  return status;
32
32
  }
@@ -127,7 +127,7 @@ USBTransfer::Do(int fRawFD)
127
127
  int i;
128
128
  usb_iso_packet_descriptor *packetDescriptors = new usb_iso_packet_descriptor[fLibusbTransfer->num_iso_packets];
129
129
  for (i = 0; i < fLibusbTransfer->num_iso_packets; i++) {
130
- if ((int16)(fLibusbTransfer->iso_packet_desc[i]).length != (fLibusbTransfer->iso_packet_desc[i]).length) {
130
+ if ((fLibusbTransfer->iso_packet_desc[i]).length > (unsigned int)INT16_MAX) {
131
131
  fUsbiTransfer->transferred = -1;
132
132
  usbi_err(TRANSFER_CTX(fLibusbTransfer), "failed isochronous transfer");
133
133
  break;
@@ -201,7 +201,7 @@ status_t
201
201
  USBDeviceHandle::SubmitTransfer(struct usbi_transfer *itransfer)
202
202
  {
203
203
  USBTransfer *transfer = new USBTransfer(itransfer, fUSBDevice);
204
- *((USBTransfer **)usbi_transfer_get_os_priv(itransfer)) = transfer;
204
+ *((USBTransfer **)usbi_get_transfer_priv(itransfer)) = transfer;
205
205
  BAutolock locker(fTransfersLock);
206
206
  fTransfers.AddItem(transfer);
207
207
  release_sem(fTransfersSem);
@@ -215,16 +215,16 @@ USBDeviceHandle::CancelTransfer(USBTransfer *transfer)
215
215
  fTransfersLock.Lock();
216
216
  bool removed = fTransfers.RemoveItem(transfer);
217
217
  fTransfersLock.Unlock();
218
- if(removed)
218
+ if (removed)
219
219
  usbi_signal_transfer_completion(transfer->UsbiTransfer());
220
220
  return LIBUSB_SUCCESS;
221
221
  }
222
222
 
223
223
  USBDeviceHandle::USBDeviceHandle(USBDevice *dev)
224
224
  :
225
- fTransfersThread(-1),
226
225
  fUSBDevice(dev),
227
226
  fClaimedInterfaces(0),
227
+ fTransfersThread(-1),
228
228
  fInitCheck(false)
229
229
  {
230
230
  fRawFD = open(dev->Location(), O_RDWR | O_CLOEXEC);
@@ -242,7 +242,7 @@ USBDeviceHandle::~USBDeviceHandle()
242
242
  {
243
243
  if (fRawFD > 0)
244
244
  close(fRawFD);
245
- for(int i = 0; i < 32; i++) {
245
+ for (int i = 0; i < 32; i++) {
246
246
  if (fClaimedInterfaces & (1U << i))
247
247
  ReleaseInterface(i);
248
248
  }
@@ -252,7 +252,7 @@ USBDeviceHandle::~USBDeviceHandle()
252
252
  }
253
253
 
254
254
  int
255
- USBDeviceHandle::ClaimInterface(int inumber)
255
+ USBDeviceHandle::ClaimInterface(uint8 inumber)
256
256
  {
257
257
  int status = fUSBDevice->ClaimInterface(inumber);
258
258
  if (status == LIBUSB_SUCCESS)
@@ -261,7 +261,7 @@ USBDeviceHandle::ClaimInterface(int inumber)
261
261
  }
262
262
 
263
263
  int
264
- USBDeviceHandle::ReleaseInterface(int inumber)
264
+ USBDeviceHandle::ReleaseInterface(uint8 inumber)
265
265
  {
266
266
  fUSBDevice->ReleaseInterface(inumber);
267
267
  fClaimedInterfaces &= ~(1U << inumber);
@@ -269,10 +269,10 @@ USBDeviceHandle::ReleaseInterface(int inumber)
269
269
  }
270
270
 
271
271
  int
272
- USBDeviceHandle::SetConfiguration(int config)
272
+ USBDeviceHandle::SetConfiguration(uint8 config)
273
273
  {
274
274
  int config_index = fUSBDevice->CheckInterfacesFree(config);
275
- if(config_index == LIBUSB_ERROR_BUSY || config_index == LIBUSB_ERROR_NOT_FOUND)
275
+ if (config_index == LIBUSB_ERROR_BUSY || config_index == LIBUSB_ERROR_NOT_FOUND)
276
276
  return config_index;
277
277
  usb_raw_command command;
278
278
  command.config.config_index = config_index;
@@ -280,12 +280,12 @@ USBDeviceHandle::SetConfiguration(int config)
280
280
  command.config.status != B_USB_RAW_STATUS_SUCCESS) {
281
281
  return _errno_to_libusb(command.config.status);
282
282
  }
283
- fUSBDevice->SetActiveConfiguration(config_index);
283
+ fUSBDevice->SetActiveConfiguration((uint8)config_index);
284
284
  return LIBUSB_SUCCESS;
285
285
  }
286
286
 
287
287
  int
288
- USBDeviceHandle::SetAltSetting(int inumber, int alt)
288
+ USBDeviceHandle::SetAltSetting(uint8 inumber, uint8 alt)
289
289
  {
290
290
  usb_raw_command command;
291
291
  command.alternate.config_index = fUSBDevice->ActiveConfigurationIndex();
@@ -295,23 +295,22 @@ USBDeviceHandle::SetAltSetting(int inumber, int alt)
295
295
  usbi_err(NULL, "Error retrieving active alternate interface");
296
296
  return _errno_to_libusb(command.alternate.status);
297
297
  }
298
- if (command.alternate.alternate_info == alt) {
299
- usbi_dbg("Setting alternate interface successful");
298
+ if (command.alternate.alternate_info == (uint32)alt) {
299
+ usbi_dbg(NULL, "Setting alternate interface successful");
300
300
  return LIBUSB_SUCCESS;
301
301
  }
302
302
  command.alternate.alternate_info = alt;
303
303
  if (ioctl(fRawFD, B_USB_RAW_COMMAND_SET_ALT_INTERFACE, &command, sizeof(command)) ||
304
- command.alternate.status != B_USB_RAW_STATUS_SUCCESS) { //IF IOCTL FAILS DEVICE DISONNECTED PROBABLY
304
+ command.alternate.status != B_USB_RAW_STATUS_SUCCESS) { //IF IOCTL FAILS DEVICE DISCONNECTED PROBABLY
305
305
  usbi_err(NULL, "Error setting alternate interface");
306
306
  return _errno_to_libusb(command.alternate.status);
307
307
  }
308
- usbi_dbg("Setting alternate interface successful");
308
+ usbi_dbg(NULL, "Setting alternate interface successful");
309
309
  return LIBUSB_SUCCESS;
310
310
  }
311
311
 
312
-
313
312
  int
314
- USBDevice::ClearHalt(int endpoint)
313
+ USBDeviceHandle::ClearHalt(uint8 endpoint)
315
314
  {
316
315
  usb_raw_command command;
317
316
  command.control.request_type = USB_REQTYPE_ENDPOINT_OUT;
@@ -324,15 +323,16 @@ USBDevice::ClearHalt(int endpoint)
324
323
  command.control.status != B_USB_RAW_STATUS_SUCCESS) {
325
324
  return _errno_to_libusb(command.control.status);
326
325
  }
326
+ return LIBUSB_SUCCESS;
327
327
  }
328
328
 
329
329
 
330
330
  USBDevice::USBDevice(const char *path)
331
331
  :
332
- fPath(NULL),
333
- fActiveConfiguration(0), //0?
334
- fConfigurationDescriptors(NULL),
335
332
  fClaimedInterfaces(0),
333
+ fConfigurationDescriptors(NULL),
334
+ fActiveConfiguration(0), //0?
335
+ fPath(NULL),
336
336
  fEndpointToIndex(NULL),
337
337
  fEndpointToInterface(NULL),
338
338
  fInitCheck(false)
@@ -345,7 +345,7 @@ USBDevice::~USBDevice()
345
345
  {
346
346
  free(fPath);
347
347
  if (fConfigurationDescriptors) {
348
- for(int i = 0; i < fDeviceDescriptor.num_configurations; i++) {
348
+ for (uint8 i = 0; i < fDeviceDescriptor.num_configurations; i++) {
349
349
  if (fConfigurationDescriptors[i])
350
350
  delete fConfigurationDescriptors[i];
351
351
  }
@@ -382,7 +382,7 @@ USBDevice::Descriptor() const
382
382
  }
383
383
 
384
384
  const usb_configuration_descriptor *
385
- USBDevice::ConfigurationDescriptor(uint32 index) const
385
+ USBDevice::ConfigurationDescriptor(uint8 index) const
386
386
  {
387
387
  if (index > CountConfigurations())
388
388
  return NULL;
@@ -395,13 +395,13 @@ USBDevice::ActiveConfiguration() const
395
395
  return (usb_configuration_descriptor *) fConfigurationDescriptors[fActiveConfiguration];
396
396
  }
397
397
 
398
- int
398
+ uint8
399
399
  USBDevice::ActiveConfigurationIndex() const
400
400
  {
401
401
  return fActiveConfiguration;
402
402
  }
403
403
 
404
- int USBDevice::ClaimInterface(int interface)
404
+ int USBDevice::ClaimInterface(uint8 interface)
405
405
  {
406
406
  if (interface > ActiveConfiguration()->number_interfaces)
407
407
  return LIBUSB_ERROR_NOT_FOUND;
@@ -411,27 +411,26 @@ int USBDevice::ClaimInterface(int interface)
411
411
  return LIBUSB_SUCCESS;
412
412
  }
413
413
 
414
- int USBDevice::ReleaseInterface(int interface)
414
+ int USBDevice::ReleaseInterface(uint8 interface)
415
415
  {
416
416
  fClaimedInterfaces &= ~(1U << interface);
417
417
  return LIBUSB_SUCCESS;
418
418
  }
419
419
 
420
420
  int
421
- USBDevice::CheckInterfacesFree(int config)
421
+ USBDevice::CheckInterfacesFree(uint8 config)
422
422
  {
423
423
  if (fConfigToIndex.count(config) == 0)
424
424
  return LIBUSB_ERROR_NOT_FOUND;
425
425
  if (fClaimedInterfaces == 0)
426
- return fConfigToIndex[(uint8)config];
426
+ return fConfigToIndex[config];
427
427
  return LIBUSB_ERROR_BUSY;
428
428
  }
429
429
 
430
- int
431
- USBDevice::SetActiveConfiguration(int config_index)
430
+ void
431
+ USBDevice::SetActiveConfiguration(uint8 config_index)
432
432
  {
433
433
  fActiveConfiguration = config_index;
434
- return LIBUSB_SUCCESS;
435
434
  }
436
435
 
437
436
  uint8
@@ -463,7 +462,7 @@ USBDevice::Initialise() //Do we need more error checking, etc? How to report?
463
462
  fConfigurationDescriptors = new(std::nothrow) unsigned char *[fDeviceDescriptor.num_configurations];
464
463
  fEndpointToIndex = new(std::nothrow) map<uint8,uint8> [fDeviceDescriptor.num_configurations];
465
464
  fEndpointToInterface = new(std::nothrow) map<uint8,uint8> [fDeviceDescriptor.num_configurations];
466
- for (int i = 0; i < fDeviceDescriptor.num_configurations; i++) {
465
+ for (uint8 i = 0; i < fDeviceDescriptor.num_configurations; i++) {
467
466
  usb_configuration_descriptor tmp_config;
468
467
  command.config.descriptor = &tmp_config;
469
468
  command.config.config_index = i;
@@ -479,14 +478,14 @@ USBDevice::Initialise() //Do we need more error checking, etc? How to report?
479
478
  command.config_etc.descriptor = (usb_configuration_descriptor*)fConfigurationDescriptors[i];
480
479
  command.config_etc.length = tmp_config.total_length;
481
480
  command.config_etc.config_index = i;
482
- if (ioctl(fRawFD, B_USB_COMMAND_GET_CONFIGURATION_DESCRIPTOR_ETC, &command, sizeof(command)) ||
481
+ if (ioctl(fRawFD, B_USB_RAW_COMMAND_GET_CONFIGURATION_DESCRIPTOR_ETC, &command, sizeof(command)) ||
483
482
  command.config_etc.status != B_USB_RAW_STATUS_SUCCESS) {
484
483
  usbi_err(NULL, "failed retrieving full configuration descriptor");
485
484
  close(fRawFD);
486
485
  return B_ERROR;
487
486
  }
488
487
 
489
- for (int j = 0; j < tmp_config.number_interfaces; j++) {
488
+ for (uint8 j = 0; j < tmp_config.number_interfaces; j++) {
490
489
  command.alternate.config_index = i;
491
490
  command.alternate.interface_index = j;
492
491
  if (ioctl(fRawFD, B_USB_RAW_COMMAND_GET_ALT_INTERFACE_COUNT, &command, sizeof(command)) ||
@@ -495,8 +494,8 @@ USBDevice::Initialise() //Do we need more error checking, etc? How to report?
495
494
  close(fRawFD);
496
495
  return B_ERROR;
497
496
  }
498
- int num_alternate = command.alternate.alternate_info;
499
- for (int k = 0; k < num_alternate; k++) {
497
+ uint8 num_alternate = (uint8)command.alternate.alternate_info;
498
+ for (uint8 k = 0; k < num_alternate; k++) {
500
499
  usb_interface_descriptor tmp_interface;
501
500
  command.interface_etc.config_index = i;
502
501
  command.interface_etc.interface_index = j;
@@ -508,7 +507,7 @@ USBDevice::Initialise() //Do we need more error checking, etc? How to report?
508
507
  close(fRawFD);
509
508
  return B_ERROR;
510
509
  }
511
- for (int l = 0; l < tmp_interface.num_endpoints; l++) {
510
+ for (uint8 l = 0; l < tmp_interface.num_endpoints; l++) {
512
511
  usb_endpoint_descriptor tmp_endpoint;
513
512
  command.endpoint_etc.config_index = i;
514
513
  command.endpoint_etc.interface_index = j;