usb 2.1.2 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (288) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +20 -2
  3. package/dist/index.d.ts +2 -1
  4. package/dist/index.js +3 -1
  5. package/dist/index.js.map +1 -1
  6. package/dist/usb/bindings.d.ts +4 -0
  7. package/dist/usb/device.js +5 -0
  8. package/dist/usb/device.js.map +1 -1
  9. package/dist/usb/index.js +7 -16
  10. package/dist/usb/index.js.map +1 -1
  11. package/dist/webusb/webusb-device.d.ts +2 -1
  12. package/dist/webusb/webusb-device.js +21 -14
  13. package/dist/webusb/webusb-device.js.map +1 -1
  14. package/libusb/.gitattributes +2 -6
  15. package/libusb/.private/appveyor_build.sh +22 -0
  16. package/libusb/.private/bm.sh +1 -1
  17. package/libusb/.private/ci-build.sh +67 -0
  18. package/libusb/.private/ci-container-build.sh +70 -0
  19. package/libusb/.private/post-rewrite.sh +5 -1
  20. package/libusb/.private/pre-commit.sh +5 -1
  21. package/libusb/.private/wbs.txt +4 -19
  22. package/libusb/.travis.yml +32 -23
  23. package/libusb/AUTHORS +86 -3
  24. package/libusb/ChangeLog +54 -3
  25. package/libusb/INSTALL_WIN.txt +22 -44
  26. package/libusb/Makefile.am +32 -10
  27. package/libusb/{README.md → README} +2 -2
  28. package/libusb/README.git +3 -3
  29. package/libusb/Xcode/common.xcconfig +23 -19
  30. package/libusb/Xcode/config.h +25 -13
  31. package/libusb/Xcode/libusb.xcodeproj/project.pbxproj +511 -109
  32. package/libusb/android/README +90 -54
  33. package/libusb/android/config.h +23 -43
  34. package/libusb/android/examples/unrooted_android.c +300 -0
  35. package/libusb/android/examples/unrooted_android.h +36 -0
  36. package/libusb/android/jni/Android.mk +1 -1
  37. package/libusb/android/jni/Application.mk +16 -0
  38. package/libusb/android/jni/examples.mk +63 -29
  39. package/libusb/android/jni/libusb.mk +14 -8
  40. package/libusb/android/jni/tests.mk +13 -24
  41. package/libusb/appveyor.yml +73 -30
  42. package/libusb/autogen.sh +5 -3
  43. package/libusb/bootstrap.sh +6 -2
  44. package/libusb/configure.ac +314 -227
  45. package/libusb/doc/Makefile.in +22 -0
  46. package/libusb/doc/doxygen.cfg.in +460 -223
  47. package/libusb/examples/Makefile.am +6 -13
  48. package/libusb/examples/dpfp.c +276 -73
  49. package/libusb/examples/ezusb.c +18 -8
  50. package/libusb/examples/ezusb.h +6 -17
  51. package/libusb/examples/fxload.c +4 -5
  52. package/libusb/examples/hotplugtest.c +1 -1
  53. package/libusb/examples/sam3u_benchmark.c +59 -24
  54. package/libusb/examples/testlibusb.c +138 -104
  55. package/libusb/examples/xusb.c +26 -22
  56. package/libusb/libusb/Makefile.am +57 -70
  57. package/libusb/libusb/Makefile.am.extra +26 -0
  58. package/libusb/libusb/core.c +432 -423
  59. package/libusb/libusb/descriptor.c +365 -419
  60. package/libusb/libusb/hotplug.c +200 -104
  61. package/libusb/libusb/io.c +522 -535
  62. package/libusb/libusb/libusb-1.0.def +7 -3
  63. package/libusb/libusb/libusb-1.0.rc +1 -9
  64. package/libusb/libusb/libusb.h +302 -226
  65. package/libusb/libusb/libusbi.h +607 -316
  66. package/libusb/libusb/os/darwin_usb.c +703 -329
  67. package/libusb/libusb/os/darwin_usb.h +39 -15
  68. package/libusb/libusb/os/events_posix.c +300 -0
  69. package/libusb/libusb/os/events_posix.h +59 -0
  70. package/libusb/libusb/os/events_windows.c +214 -0
  71. package/libusb/{msvc/missing.h → libusb/os/events_windows.h} +25 -11
  72. package/libusb/libusb/os/haiku_pollfs.cpp +14 -9
  73. package/libusb/libusb/os/haiku_usb.h +12 -12
  74. package/libusb/libusb/os/haiku_usb_backend.cpp +36 -37
  75. package/libusb/libusb/os/haiku_usb_raw.cpp +80 -116
  76. package/libusb/libusb/os/linux_netlink.c +55 -63
  77. package/libusb/libusb/os/linux_udev.c +61 -69
  78. package/libusb/libusb/os/linux_usbfs.c +926 -1015
  79. package/libusb/libusb/os/linux_usbfs.h +74 -57
  80. package/libusb/libusb/os/netbsd_usb.c +103 -168
  81. package/libusb/libusb/os/null_usb.c +111 -0
  82. package/libusb/libusb/os/openbsd_usb.c +71 -120
  83. package/libusb/libusb/os/sunos_usb.c +289 -375
  84. package/libusb/libusb/os/sunos_usb.h +0 -1
  85. package/libusb/libusb/os/threads_posix.c +81 -32
  86. package/libusb/libusb/os/threads_posix.h +19 -23
  87. package/libusb/libusb/os/threads_windows.c +9 -95
  88. package/libusb/libusb/os/threads_windows.h +33 -31
  89. package/libusb/libusb/os/windows_common.c +915 -0
  90. package/libusb/libusb/os/windows_common.h +330 -42
  91. package/libusb/libusb/os/windows_usbdk.c +161 -267
  92. package/libusb/libusb/os/windows_usbdk.h +5 -2
  93. package/libusb/libusb/os/windows_winusb.c +1355 -1192
  94. package/libusb/libusb/os/windows_winusb.h +167 -167
  95. package/libusb/libusb/strerror.c +20 -30
  96. package/libusb/libusb/sync.c +20 -21
  97. package/libusb/libusb/version.h +1 -1
  98. package/libusb/libusb/version_nano.h +1 -1
  99. package/libusb/msvc/.gitattributes +3 -0
  100. package/libusb/msvc/config.h +27 -20
  101. package/libusb/msvc/{hotplugtest_2012.vcxproj → dpfp_2013.vcxproj} +14 -10
  102. package/libusb/msvc/dpfp_2013.vcxproj.filters +26 -0
  103. package/libusb/msvc/{listdevs_2010.vcxproj → dpfp_2015.vcxproj} +14 -9
  104. package/libusb/msvc/dpfp_2015.vcxproj.filters +26 -0
  105. package/libusb/msvc/dpfp_2017.vcxproj +106 -0
  106. package/libusb/msvc/dpfp_2017.vcxproj.filters +26 -0
  107. package/libusb/msvc/dpfp_2019.vcxproj +106 -0
  108. package/libusb/msvc/dpfp_2019.vcxproj.filters +26 -0
  109. package/libusb/msvc/dpfp_threaded_2013.vcxproj +87 -0
  110. package/libusb/msvc/dpfp_threaded_2013.vcxproj.filters +26 -0
  111. package/libusb/msvc/dpfp_threaded_2015.vcxproj +87 -0
  112. package/libusb/msvc/dpfp_threaded_2015.vcxproj.filters +26 -0
  113. package/libusb/msvc/dpfp_threaded_2017.vcxproj +106 -0
  114. package/libusb/msvc/dpfp_threaded_2017.vcxproj.filters +26 -0
  115. package/libusb/msvc/{fxload_2012.vcxproj → dpfp_threaded_2019.vcxproj} +32 -17
  116. package/libusb/msvc/dpfp_threaded_2019.vcxproj.filters +26 -0
  117. package/libusb/msvc/fxload_2013.vcxproj +6 -3
  118. package/libusb/msvc/fxload_2013.vcxproj.filters +35 -0
  119. package/libusb/msvc/fxload_2015.vcxproj +6 -3
  120. package/libusb/msvc/fxload_2015.vcxproj.filters +35 -0
  121. package/libusb/msvc/fxload_2017.vcxproj +6 -7
  122. package/libusb/msvc/fxload_2017.vcxproj.filters +35 -0
  123. package/libusb/msvc/{fxload_2010.vcxproj → fxload_2019.vcxproj} +29 -6
  124. package/libusb/msvc/fxload_2019.vcxproj.filters +35 -0
  125. package/libusb/{examples → msvc}/getopt/getopt.c +0 -0
  126. package/libusb/{examples → msvc}/getopt/getopt.h +0 -0
  127. package/libusb/{examples → msvc}/getopt/getopt1.c +0 -0
  128. package/libusb/msvc/getopt_2013.vcxproj +4 -5
  129. package/libusb/msvc/getopt_2013.vcxproj.filters +26 -0
  130. package/libusb/msvc/getopt_2015.vcxproj +4 -4
  131. package/libusb/msvc/getopt_2015.vcxproj.filters +26 -0
  132. package/libusb/msvc/getopt_2017.vcxproj +4 -10
  133. package/libusb/msvc/getopt_2017.vcxproj.filters +26 -0
  134. package/libusb/msvc/{getopt_2012.vcxproj → getopt_2019.vcxproj} +25 -6
  135. package/libusb/msvc/getopt_2019.vcxproj.filters +26 -0
  136. package/libusb/msvc/hotplugtest_2013.vcxproj +6 -3
  137. package/libusb/msvc/hotplugtest_2013.vcxproj.filters +23 -0
  138. package/libusb/msvc/hotplugtest_2015.vcxproj +6 -3
  139. package/libusb/msvc/hotplugtest_2015.vcxproj.filters +23 -0
  140. package/libusb/msvc/hotplugtest_2017.vcxproj +6 -7
  141. package/libusb/msvc/hotplugtest_2017.vcxproj.filters +23 -0
  142. package/libusb/msvc/hotplugtest_2019.vcxproj +105 -0
  143. package/libusb/msvc/hotplugtest_2019.vcxproj.filters +23 -0
  144. package/libusb/msvc/libusb_2013.sln +50 -20
  145. package/libusb/msvc/libusb_2015.sln +51 -21
  146. package/libusb/msvc/libusb_2017.sln +90 -36
  147. package/libusb/msvc/libusb_2019.sln +240 -0
  148. package/libusb/msvc/libusb_dll_2013.vcxproj +6 -9
  149. package/libusb/msvc/libusb_dll_2013.vcxproj.filters +94 -0
  150. package/libusb/msvc/libusb_dll_2015.vcxproj +6 -8
  151. package/libusb/msvc/libusb_dll_2015.vcxproj.filters +94 -0
  152. package/libusb/msvc/libusb_dll_2017.vcxproj +6 -16
  153. package/libusb/msvc/libusb_dll_2017.vcxproj.filters +94 -0
  154. package/libusb/msvc/{libusb_dll_2010.vcxproj → libusb_dll_2019.vcxproj} +27 -9
  155. package/libusb/msvc/libusb_dll_2019.vcxproj.filters +94 -0
  156. package/libusb/msvc/libusb_static_2013.vcxproj +5 -9
  157. package/libusb/msvc/libusb_static_2013.vcxproj.filters +80 -0
  158. package/libusb/msvc/libusb_static_2015.vcxproj +5 -8
  159. package/libusb/msvc/libusb_static_2015.vcxproj.filters +80 -0
  160. package/libusb/msvc/libusb_static_2017.vcxproj +5 -8
  161. package/libusb/msvc/libusb_static_2017.vcxproj.filters +80 -0
  162. package/libusb/msvc/{libusb_static_2010.vcxproj → libusb_static_2019.vcxproj} +26 -9
  163. package/libusb/msvc/libusb_static_2019.vcxproj.filters +80 -0
  164. package/libusb/msvc/listdevs_2013.vcxproj +6 -3
  165. package/libusb/msvc/listdevs_2013.vcxproj.filters +23 -0
  166. package/libusb/msvc/listdevs_2015.vcxproj +6 -3
  167. package/libusb/msvc/listdevs_2015.vcxproj.filters +23 -0
  168. package/libusb/msvc/listdevs_2017.vcxproj +6 -7
  169. package/libusb/msvc/listdevs_2017.vcxproj.filters +23 -0
  170. package/libusb/msvc/listdevs_2019.vcxproj +105 -0
  171. package/libusb/msvc/listdevs_2019.vcxproj.filters +23 -0
  172. package/libusb/msvc/{listdevs_2012.vcxproj → sam3u_benchmark_2013.vcxproj} +13 -9
  173. package/libusb/msvc/sam3u_benchmark_2013.vcxproj.filters +26 -0
  174. package/libusb/msvc/{hotplugtest_2010.vcxproj → sam3u_benchmark_2015.vcxproj} +13 -8
  175. package/libusb/msvc/sam3u_benchmark_2015.vcxproj.filters +26 -0
  176. package/libusb/msvc/sam3u_benchmark_2017.vcxproj +106 -0
  177. package/libusb/msvc/sam3u_benchmark_2017.vcxproj.filters +26 -0
  178. package/libusb/msvc/sam3u_benchmark_2019.vcxproj +106 -0
  179. package/libusb/msvc/sam3u_benchmark_2019.vcxproj.filters +26 -0
  180. package/libusb/msvc/stress_2013.vcxproj +4 -2
  181. package/libusb/msvc/stress_2013.vcxproj.filters +32 -0
  182. package/libusb/msvc/stress_2015.vcxproj +4 -2
  183. package/libusb/msvc/stress_2015.vcxproj.filters +32 -0
  184. package/libusb/msvc/stress_2017.vcxproj +4 -6
  185. package/libusb/msvc/stress_2017.vcxproj.filters +32 -0
  186. package/libusb/msvc/{stress_2010.vcxproj → stress_2019.vcxproj} +26 -4
  187. package/libusb/msvc/stress_2019.vcxproj.filters +32 -0
  188. package/libusb/msvc/testlibusb_2013.vcxproj +6 -3
  189. package/libusb/msvc/testlibusb_2013.vcxproj.filters +23 -0
  190. package/libusb/msvc/testlibusb_2015.vcxproj +6 -3
  191. package/libusb/msvc/testlibusb_2015.vcxproj.filters +23 -0
  192. package/libusb/msvc/testlibusb_2017.vcxproj +6 -7
  193. package/libusb/msvc/testlibusb_2017.vcxproj.filters +23 -0
  194. package/libusb/msvc/{testlibusb_2010.vcxproj → testlibusb_2019.vcxproj} +28 -5
  195. package/libusb/msvc/testlibusb_2019.vcxproj.filters +23 -0
  196. package/libusb/msvc/xusb_2013.vcxproj +6 -3
  197. package/libusb/msvc/xusb_2013.vcxproj.filters +23 -0
  198. package/libusb/msvc/xusb_2015.vcxproj +6 -3
  199. package/libusb/msvc/xusb_2015.vcxproj.filters +23 -0
  200. package/libusb/msvc/xusb_2017.vcxproj +6 -7
  201. package/libusb/msvc/xusb_2017.vcxproj.filters +23 -0
  202. package/libusb/msvc/{xusb_2010.vcxproj → xusb_2019.vcxproj} +28 -5
  203. package/libusb/msvc/xusb_2019.vcxproj.filters +23 -0
  204. package/libusb/tests/Makefile.am +13 -1
  205. package/libusb/tests/libusb_testlib.h +12 -43
  206. package/libusb/tests/stress.c +59 -50
  207. package/libusb/tests/testlib.c +78 -171
  208. package/libusb/tests/umockdev.c +1175 -0
  209. package/libusb.gypi +10 -11
  210. package/package.json +2 -2
  211. package/prebuilds/android-arm/node.napi.armv7.node +0 -0
  212. package/prebuilds/android-arm64/node.napi.armv8.node +0 -0
  213. package/prebuilds/darwin-x64+arm64/node.napi.node +0 -0
  214. package/prebuilds/linux-arm/node.napi.armv6.node +0 -0
  215. package/prebuilds/linux-arm/node.napi.armv7.node +0 -0
  216. package/prebuilds/linux-arm64/node.napi.armv8.node +0 -0
  217. package/prebuilds/linux-ia32/node.napi.node +0 -0
  218. package/prebuilds/linux-x64/node.napi.glibc.node +0 -0
  219. package/prebuilds/linux-x64/node.napi.musl.node +0 -0
  220. package/prebuilds/win32-ia32/node.napi.node +0 -0
  221. package/prebuilds/win32-x64/node.napi.node +0 -0
  222. package/src/device.cc +12 -7
  223. package/src/node_usb.cc +10 -0
  224. package/test/usb.coffee +6 -0
  225. package/tsc/index.ts +2 -0
  226. package/tsc/usb/bindings.ts +5 -0
  227. package/tsc/usb/device.ts +6 -0
  228. package/tsc/usb/index.ts +5 -8
  229. package/tsc/webusb/webusb-device.ts +12 -8
  230. package/libusb/.private/bd.cmd +0 -89
  231. package/libusb/.private/bwince.cmd +0 -57
  232. package/libusb/.private/wbs_wince.txt +0 -42
  233. package/libusb/Brewfile +0 -4
  234. package/libusb/appveyor_cygwin.bat +0 -11
  235. package/libusb/appveyor_minGW.bat +0 -19
  236. package/libusb/doc/Makefile.am +0 -9
  237. package/libusb/examples/dpfp_threaded.c +0 -557
  238. package/libusb/libusb/hotplug.h +0 -99
  239. package/libusb/libusb/os/poll_posix.c +0 -84
  240. package/libusb/libusb/os/poll_posix.h +0 -14
  241. package/libusb/libusb/os/poll_windows.c +0 -447
  242. package/libusb/libusb/os/poll_windows.h +0 -98
  243. package/libusb/libusb/os/wince_usb.c +0 -888
  244. package/libusb/libusb/os/wince_usb.h +0 -126
  245. package/libusb/libusb/os/windows_nt_common.c +0 -1010
  246. package/libusb/libusb/os/windows_nt_common.h +0 -110
  247. package/libusb/libusb/os/windows_nt_shared_types.h +0 -147
  248. package/libusb/msvc/appveyor.bat +0 -27
  249. package/libusb/msvc/ddk_build.cmd +0 -219
  250. package/libusb/msvc/errno.h +0 -102
  251. package/libusb/msvc/fxload_sources +0 -23
  252. package/libusb/msvc/getopt_2005.vcproj +0 -288
  253. package/libusb/msvc/getopt_2010.vcxproj +0 -72
  254. package/libusb/msvc/getopt_sources +0 -24
  255. package/libusb/msvc/hotplugtest_sources +0 -20
  256. package/libusb/msvc/inttypes.h +0 -295
  257. package/libusb/msvc/libusb.dsw +0 -71
  258. package/libusb/msvc/libusb_2005.sln +0 -95
  259. package/libusb/msvc/libusb_2010.sln +0 -105
  260. package/libusb/msvc/libusb_2012.sln +0 -105
  261. package/libusb/msvc/libusb_dll.dsp +0 -194
  262. package/libusb/msvc/libusb_dll_2005.vcproj +0 -464
  263. package/libusb/msvc/libusb_dll_2012.vcxproj +0 -107
  264. package/libusb/msvc/libusb_dll_wince.vcproj +0 -1251
  265. package/libusb/msvc/libusb_sources +0 -43
  266. package/libusb/msvc/libusb_static.dsp +0 -174
  267. package/libusb/msvc/libusb_static_2005.vcproj +0 -390
  268. package/libusb/msvc/libusb_static_2012.vcxproj +0 -98
  269. package/libusb/msvc/libusb_static_wince.vcproj +0 -1179
  270. package/libusb/msvc/libusb_wince.sln +0 -246
  271. package/libusb/msvc/listdevs.dsp +0 -103
  272. package/libusb/msvc/listdevs_2005.vcproj +0 -360
  273. package/libusb/msvc/listdevs_sources +0 -20
  274. package/libusb/msvc/listdevs_wince.vcproj +0 -1120
  275. package/libusb/msvc/missing.c +0 -80
  276. package/libusb/msvc/stdint.h +0 -256
  277. package/libusb/msvc/stress_2005.vcproj +0 -390
  278. package/libusb/msvc/stress_2012.vcxproj +0 -87
  279. package/libusb/msvc/stress_sources +0 -21
  280. package/libusb/msvc/stress_wince.vcproj +0 -1128
  281. package/libusb/msvc/testlibusb_2012.vcxproj +0 -83
  282. package/libusb/msvc/testlibusb_sources +0 -20
  283. package/libusb/msvc/xusb.dsp +0 -102
  284. package/libusb/msvc/xusb_2005.vcproj +0 -344
  285. package/libusb/msvc/xusb_2012.vcxproj +0 -83
  286. package/libusb/msvc/xusb_sources +0 -20
  287. package/libusb/msvc/xusb_wince.vcproj +0 -1120
  288. package/libusb/travis-autogen.sh +0 -39
@@ -21,7 +21,6 @@
21
21
 
22
22
  #include <sys/time.h>
23
23
  #include <sys/types.h>
24
- #include <sys/list.h>
25
24
  #include <sys/stat.h>
26
25
  #include <strings.h>
27
26
  #include <errno.h>
@@ -36,7 +35,6 @@
36
35
  #include <sys/nvpair.h>
37
36
  #include <sys/devctl.h>
38
37
  #include <sys/usb/clients/ugen/usb_ugen.h>
39
- #include <errno.h>
40
38
  #include <sys/usb/usba.h>
41
39
  #include <sys/pci.h>
42
40
 
@@ -46,48 +44,42 @@
46
44
  #define UPDATEDRV_PATH "/usr/sbin/update_drv"
47
45
  #define UPDATEDRV "update_drv"
48
46
 
49
- typedef list_t string_list_t;
50
- typedef struct string_node {
51
- char *string;
52
- list_node_t link;
53
- } string_node_t;
47
+ #define DEFAULT_LISTSIZE 6
48
+
49
+ typedef struct {
50
+ int nargs;
51
+ int listsize;
52
+ char **string;
53
+ } string_list_t;
54
54
 
55
55
  /*
56
56
  * Backend functions
57
57
  */
58
- static int sunos_init(struct libusb_context *);
59
- static void sunos_exit(struct libusb_context *);
60
58
  static int sunos_get_device_list(struct libusb_context *,
61
59
  struct discovered_devs **);
62
60
  static int sunos_open(struct libusb_device_handle *);
63
61
  static void sunos_close(struct libusb_device_handle *);
64
- static int sunos_get_device_descriptor(struct libusb_device *,
65
- uint8_t*, int *);
66
62
  static int sunos_get_active_config_descriptor(struct libusb_device *,
67
- uint8_t*, size_t, int *);
63
+ void *, size_t);
68
64
  static int sunos_get_config_descriptor(struct libusb_device *, uint8_t,
69
- uint8_t*, size_t, int *);
70
- static int sunos_get_configuration(struct libusb_device_handle *, int *);
65
+ void *, size_t);
66
+ static int sunos_get_configuration(struct libusb_device_handle *, uint8_t *);
71
67
  static int sunos_set_configuration(struct libusb_device_handle *, int);
72
- static int sunos_claim_interface(struct libusb_device_handle *, int);
73
- static int sunos_release_interface(struct libusb_device_handle *, int);
68
+ static int sunos_claim_interface(struct libusb_device_handle *, uint8_t);
69
+ static int sunos_release_interface(struct libusb_device_handle *, uint8_t);
74
70
  static int sunos_set_interface_altsetting(struct libusb_device_handle *,
75
- int, int);
76
- static int sunos_clear_halt(struct libusb_device_handle *, uint8_t);
77
- static int sunos_reset_device(struct libusb_device_handle *);
71
+ uint8_t, uint8_t);
72
+ static int sunos_clear_halt(struct libusb_device_handle *, unsigned char);
78
73
  static void sunos_destroy_device(struct libusb_device *);
79
74
  static int sunos_submit_transfer(struct usbi_transfer *);
80
75
  static int sunos_cancel_transfer(struct usbi_transfer *);
81
- static void sunos_clear_transfer_priv(struct usbi_transfer *);
82
76
  static int sunos_handle_transfer_completion(struct usbi_transfer *);
83
- static int sunos_clock_gettime(int, struct timespec *);
84
- static int sunos_kernel_driver_active(struct libusb_device_handle *, int interface);
85
- static int sunos_detach_kernel_driver (struct libusb_device_handle *dev, int interface_number);
86
- static int sunos_attach_kernel_driver (struct libusb_device_handle *dev, int interface_number);
77
+ static int sunos_kernel_driver_active(struct libusb_device_handle *, uint8_t);
78
+ static int sunos_detach_kernel_driver(struct libusb_device_handle *, uint8_t);
79
+ static int sunos_attach_kernel_driver(struct libusb_device_handle *, uint8_t);
87
80
  static int sunos_usb_open_ep0(sunos_dev_handle_priv_t *hpriv, sunos_dev_priv_t *dpriv);
88
81
  static int sunos_usb_ioctl(struct libusb_device *dev, int cmd);
89
82
 
90
- static struct devctl_iocdata iocdata;
91
83
  static int sunos_get_link(di_devlink_t devlink, void *arg)
92
84
  {
93
85
  walk_link_t *larg = (walk_link_t *)arg;
@@ -98,7 +90,7 @@ static int sunos_get_link(di_devlink_t devlink, void *arg)
98
90
  char *content = (char *)di_devlink_content(devlink);
99
91
  char *start = strstr(content, "/devices/");
100
92
  start += strlen("/devices");
101
- usbi_dbg("%s", start);
93
+ usbi_dbg(NULL, "%s", start);
102
94
 
103
95
  /* line content must have minor node */
104
96
  if (start == NULL ||
@@ -109,7 +101,7 @@ static int sunos_get_link(di_devlink_t devlink, void *arg)
109
101
 
110
102
  p = di_devlink_path(devlink);
111
103
  q = strrchr(p, '/');
112
- usbi_dbg("%s", q);
104
+ usbi_dbg(NULL, "%s", q);
113
105
 
114
106
  *(larg->linkpp) = strndup(p, strlen(p) - strlen(q));
115
107
 
@@ -126,7 +118,7 @@ static int sunos_physpath_to_devlink(
126
118
  *link_path = NULL;
127
119
  larg.linkpp = link_path;
128
120
  if ((hdl = di_devlink_init(NULL, 0)) == NULL) {
129
- usbi_dbg("di_devlink_init failure");
121
+ usbi_dbg(NULL, "di_devlink_init failure");
130
122
  return (-1);
131
123
  }
132
124
 
@@ -139,7 +131,7 @@ static int sunos_physpath_to_devlink(
139
131
  (void) di_devlink_fini(&hdl);
140
132
 
141
133
  if (*link_path == NULL) {
142
- usbi_dbg("there is no devlink for this path");
134
+ usbi_dbg(NULL, "there is no devlink for this path");
143
135
  return (-1);
144
136
  }
145
137
 
@@ -157,8 +149,9 @@ sunos_usb_ioctl(struct libusb_device *dev, int cmd)
157
149
  char path_arg[PATH_MAX];
158
150
  sunos_dev_priv_t *dpriv;
159
151
  devctl_ap_state_t devctl_ap_state;
152
+ struct devctl_iocdata iocdata;
160
153
 
161
- dpriv = (sunos_dev_priv_t *)dev->os_priv;
154
+ dpriv = usbi_get_device_priv(dev);
162
155
  phypath = dpriv->phypath;
163
156
 
164
157
  end = strrchr(phypath, '/');
@@ -174,17 +167,17 @@ sunos_usb_ioctl(struct libusb_device *dev, int cmd)
174
167
  return (-1);
175
168
  }
176
169
  end++;
177
- usbi_dbg("unitaddr: %s", end);
170
+ usbi_dbg(DEVICE_CTX(dev), "unitaddr: %s", end);
178
171
 
179
172
  nvlist_alloc(&nvlist, NV_UNIQUE_NAME_TYPE, KM_NOSLEEP);
180
173
  nvlist_add_int32(nvlist, "port", dev->port_number);
181
174
  //find the hub path
182
175
  snprintf(path_arg, sizeof(path_arg), "/devices%s:hubd", hubpath);
183
- usbi_dbg("ioctl hub path: %s", path_arg);
176
+ usbi_dbg(DEVICE_CTX(dev), "ioctl hub path: %s", path_arg);
184
177
 
185
178
  fd = open(path_arg, O_RDONLY);
186
179
  if (fd < 0) {
187
- usbi_err(DEVICE_CTX(dev), "open failed: %d (%s)", errno, strerror(errno));
180
+ usbi_err(DEVICE_CTX(dev), "open failed: errno %d (%s)", errno, strerror(errno));
188
181
  nvlist_free(nvlist);
189
182
  free(hubpath);
190
183
  return (-1);
@@ -197,18 +190,18 @@ sunos_usb_ioctl(struct libusb_device *dev, int cmd)
197
190
 
198
191
  iocdata.cmd = DEVCTL_AP_GETSTATE;
199
192
  iocdata.flags = 0;
200
- iocdata.c_nodename = "hub";
193
+ iocdata.c_nodename = (char *)"hub";
201
194
  iocdata.c_unitaddr = end;
202
195
  iocdata.cpyout_buf = &devctl_ap_state;
203
- usbi_dbg("%p, %d", iocdata.nvl_user, iocdata.nvl_usersz);
196
+ usbi_dbg(DEVICE_CTX(dev), "%p, %" PRIuPTR, iocdata.nvl_user, iocdata.nvl_usersz);
204
197
 
205
198
  errno = 0;
206
199
  if (ioctl(fd, DEVCTL_AP_GETSTATE, &iocdata) == -1) {
207
200
  usbi_err(DEVICE_CTX(dev), "ioctl failed: fd %d, cmd %x, errno %d (%s)",
208
201
  fd, DEVCTL_AP_GETSTATE, errno, strerror(errno));
209
202
  } else {
210
- usbi_dbg("dev rstate: %d", devctl_ap_state.ap_rstate);
211
- usbi_dbg("dev ostate: %d", devctl_ap_state.ap_ostate);
203
+ usbi_dbg(DEVICE_CTX(dev), "dev rstate: %d", devctl_ap_state.ap_rstate);
204
+ usbi_dbg(DEVICE_CTX(dev), "dev ostate: %d", devctl_ap_state.ap_ostate);
212
205
  }
213
206
 
214
207
  errno = 0;
@@ -228,12 +221,13 @@ sunos_usb_ioctl(struct libusb_device *dev, int cmd)
228
221
  }
229
222
 
230
223
  static int
231
- sunos_kernel_driver_active(struct libusb_device_handle *dev, int interface)
224
+ sunos_kernel_driver_active(struct libusb_device_handle *dev_handle, uint8_t interface)
232
225
  {
233
- sunos_dev_priv_t *dpriv;
234
- dpriv = (sunos_dev_priv_t *)dev->dev->os_priv;
226
+ sunos_dev_priv_t *dpriv = usbi_get_device_priv(dev_handle->dev);
227
+
228
+ UNUSED(interface);
235
229
 
236
- usbi_dbg("%s", dpriv->ugenpath);
230
+ usbi_dbg(HANDLE_CTX(dev_handle), "%s", dpriv->ugenpath);
237
231
 
238
232
  return (dpriv->ugenpath == NULL);
239
233
  }
@@ -242,27 +236,23 @@ sunos_kernel_driver_active(struct libusb_device_handle *dev, int interface)
242
236
  * Private functions
243
237
  */
244
238
  static int _errno_to_libusb(int);
245
- static int sunos_usb_get_status(int fd);
246
-
247
- static int sunos_init(struct libusb_context *ctx)
248
- {
249
- return (LIBUSB_SUCCESS);
250
- }
251
-
252
- static void sunos_exit(struct libusb_context *ctx)
253
- {
254
- usbi_dbg("");
255
- }
239
+ static int sunos_usb_get_status(struct libusb_context *ctx, int fd);
256
240
 
257
241
  static string_list_t *
258
242
  sunos_new_string_list(void)
259
243
  {
260
244
  string_list_t *list;
261
245
 
262
- list = calloc(1, sizeof(*list));
263
- if (list != NULL)
264
- list_create(list, sizeof(string_node_t),
265
- offsetof(string_node_t, link));
246
+ list = calloc(1, sizeof(string_list_t));
247
+ if (list == NULL)
248
+ return (NULL);
249
+ list->string = calloc(DEFAULT_LISTSIZE, sizeof(char *));
250
+ if (list->string == NULL) {
251
+ free(list);
252
+ return (NULL);
253
+ }
254
+ list->nargs = 0;
255
+ list->listsize = DEFAULT_LISTSIZE;
266
256
 
267
257
  return (list);
268
258
  }
@@ -270,19 +260,22 @@ sunos_new_string_list(void)
270
260
  static int
271
261
  sunos_append_to_string_list(string_list_t *list, const char *arg)
272
262
  {
273
- string_node_t *np;
263
+ char *str = strdup(arg);
274
264
 
275
- np = calloc(1, sizeof(*np));
276
- if (!np)
265
+ if (str == NULL)
277
266
  return (-1);
278
267
 
279
- np->string = strdup(arg);
280
- if (!np->string) {
281
- free(np);
282
- return (-1);
268
+ if ((list->nargs + 1) == list->listsize) { /* +1 is for NULL */
269
+ char **tmp = realloc(list->string,
270
+ sizeof(char *) * (list->listsize + 1));
271
+ if (tmp == NULL) {
272
+ free(str);
273
+ return (-1);
274
+ }
275
+ list->string = tmp;
276
+ list->string[list->listsize++] = NULL;
283
277
  }
284
-
285
- list_insert_tail(list, np);
278
+ list->string[list->nargs++] = str;
286
279
 
287
280
  return (0);
288
281
  }
@@ -290,36 +283,20 @@ sunos_append_to_string_list(string_list_t *list, const char *arg)
290
283
  static void
291
284
  sunos_free_string_list(string_list_t *list)
292
285
  {
293
- string_node_t *np;
286
+ int i;
294
287
 
295
- while ((np = list_remove_head(list)) != NULL) {
296
- free(np->string);
297
- free(np);
288
+ for (i = 0; i < list->nargs; i++) {
289
+ free(list->string[i]);
298
290
  }
299
291
 
292
+ free(list->string);
300
293
  free(list);
301
294
  }
302
295
 
303
296
  static char **
304
297
  sunos_build_argv_list(string_list_t *list)
305
298
  {
306
- char **argv_list;
307
- string_node_t *np;
308
- int n;
309
-
310
- n = 1; /* Start at 1 for NULL terminator */
311
- for (np = list_head(list); np != NULL; np = list_next(list, np))
312
- n++;
313
-
314
- argv_list = calloc(n, sizeof(char *));
315
- if (argv_list == NULL)
316
- return NULL;
317
-
318
- n = 0;
319
- for (np = list_head(list); np != NULL; np = list_next(list, np))
320
- argv_list[n++] = np->string;
321
-
322
- return (argv_list);
299
+ return (list->string);
323
300
  }
324
301
 
325
302
 
@@ -364,14 +341,12 @@ sunos_exec_command(struct libusb_context *ctx, const char *path,
364
341
  exit_status = -1;
365
342
  }
366
343
 
367
- free(argv_list);
368
-
369
344
  return (exit_status);
370
345
  }
371
346
 
372
347
  static int
373
348
  sunos_detach_kernel_driver(struct libusb_device_handle *dev_handle,
374
- int interface_number)
349
+ uint8_t interface_number)
375
350
  {
376
351
  struct libusb_context *ctx = HANDLE_CTX(dev_handle);
377
352
  string_list_t *list;
@@ -379,9 +354,11 @@ sunos_detach_kernel_driver(struct libusb_device_handle *dev_handle,
379
354
  sunos_dev_priv_t *dpriv;
380
355
  int r;
381
356
 
382
- dpriv = (sunos_dev_priv_t *)dev_handle->dev->os_priv;
357
+ UNUSED(interface_number);
358
+
359
+ dpriv = usbi_get_device_priv(dev_handle->dev);
383
360
  snprintf(path_arg, sizeof(path_arg), "\'\"%s\"\'", dpriv->phypath);
384
- usbi_dbg("%s", path_arg);
361
+ usbi_dbg(HANDLE_CTX(dev_handle), "%s", path_arg);
385
362
 
386
363
  list = sunos_new_string_list();
387
364
  if (list == NULL)
@@ -411,8 +388,9 @@ sunos_detach_kernel_driver(struct libusb_device_handle *dev_handle,
411
388
  if (r)
412
389
  usbi_warn(HANDLE_CTX(dev_handle), "one or more ioctls failed");
413
390
 
414
- snprintf(path_arg, sizeof(path_arg), "^usb/%x.%x", dpriv->dev_descr.idVendor,
415
- dpriv->dev_descr.idProduct);
391
+ snprintf(path_arg, sizeof(path_arg), "^usb/%x.%x",
392
+ dev_handle->dev->device_descriptor.idVendor,
393
+ dev_handle->dev->device_descriptor.idProduct);
416
394
  sunos_physpath_to_devlink(dpriv->phypath, path_arg, &dpriv->ugenpath);
417
395
 
418
396
  if (access(dpriv->ugenpath, F_OK) == -1) {
@@ -420,12 +398,12 @@ sunos_detach_kernel_driver(struct libusb_device_handle *dev_handle,
420
398
  return (LIBUSB_ERROR_IO);
421
399
  }
422
400
 
423
- return sunos_usb_open_ep0((sunos_dev_handle_priv_t *)dev_handle->os_priv, dpriv);
401
+ return sunos_usb_open_ep0(usbi_get_device_handle_priv(dev_handle), dpriv);
424
402
  }
425
403
 
426
404
  static int
427
405
  sunos_attach_kernel_driver(struct libusb_device_handle *dev_handle,
428
- int interface_number)
406
+ uint8_t interface_number)
429
407
  {
430
408
  struct libusb_context *ctx = HANDLE_CTX(dev_handle);
431
409
  string_list_t *list;
@@ -433,12 +411,14 @@ sunos_attach_kernel_driver(struct libusb_device_handle *dev_handle,
433
411
  sunos_dev_priv_t *dpriv;
434
412
  int r;
435
413
 
414
+ UNUSED(interface_number);
415
+
436
416
  /* we open the dev in detach driver, so we need close it first. */
437
417
  sunos_close(dev_handle);
438
418
 
439
- dpriv = (sunos_dev_priv_t *)dev_handle->dev->os_priv;
419
+ dpriv = usbi_get_device_priv(dev_handle->dev);
440
420
  snprintf(path_arg, sizeof(path_arg), "\'\"%s\"\'", dpriv->phypath);
441
- usbi_dbg("%s", path_arg);
421
+ usbi_dbg(HANDLE_CTX(dev_handle), "%s", path_arg);
442
422
 
443
423
  list = sunos_new_string_list();
444
424
  if (list == NULL)
@@ -479,30 +459,22 @@ sunos_fill_in_dev_info(di_node_t node, struct libusb_device *dev)
479
459
  int *i, n, *addr, *port_prop;
480
460
  char *phypath;
481
461
  uint8_t *rdata;
482
- struct libusb_device_descriptor *descr;
483
- sunos_dev_priv_t *dpriv = (sunos_dev_priv_t *)dev->os_priv;
462
+ sunos_dev_priv_t *dpriv = usbi_get_device_priv(dev);
484
463
  char match_str[PATH_MAX];
485
464
 
486
465
  /* Device descriptors */
487
466
  proplen = di_prop_lookup_bytes(DDI_DEV_T_ANY, node,
488
467
  "usb-dev-descriptor", &rdata);
489
468
  if (proplen <= 0) {
490
-
491
469
  return (LIBUSB_ERROR_IO);
492
470
  }
493
-
494
- descr = (struct libusb_device_descriptor *)rdata;
495
- bcopy(descr, &dpriv->dev_descr, LIBUSB_DT_DEVICE_SIZE);
496
- dpriv->dev_descr.bcdUSB = libusb_cpu_to_le16(descr->bcdUSB);
497
- dpriv->dev_descr.idVendor = libusb_cpu_to_le16(descr->idVendor);
498
- dpriv->dev_descr.idProduct = libusb_cpu_to_le16(descr->idProduct);
499
- dpriv->dev_descr.bcdDevice = libusb_cpu_to_le16(descr->bcdDevice);
471
+ bcopy(rdata, &dev->device_descriptor, LIBUSB_DT_DEVICE_SIZE);
500
472
 
501
473
  /* Raw configuration descriptors */
502
474
  proplen = di_prop_lookup_bytes(DDI_DEV_T_ANY, node,
503
475
  "usb-raw-cfg-descriptors", &rdata);
504
476
  if (proplen <= 0) {
505
- usbi_dbg("can't find raw config descriptors");
477
+ usbi_dbg(DEVICE_CTX(dev), "can't find raw config descriptors");
506
478
 
507
479
  return (LIBUSB_ERROR_IO);
508
480
  }
@@ -526,8 +498,10 @@ sunos_fill_in_dev_info(di_node_t node, struct libusb_device *dev)
526
498
  phypath = di_devfs_path(node);
527
499
  if (phypath) {
528
500
  dpriv->phypath = strdup(phypath);
529
- snprintf(match_str, sizeof(match_str), "^usb/%x.%x", dpriv->dev_descr.idVendor, dpriv->dev_descr.idProduct);
530
- usbi_dbg("match is %s", match_str);
501
+ snprintf(match_str, sizeof(match_str), "^usb/%x.%x",
502
+ dev->device_descriptor.idVendor,
503
+ dev->device_descriptor.idProduct);
504
+ usbi_dbg(DEVICE_CTX(dev), "match is %s", match_str);
531
505
  sunos_physpath_to_devlink(dpriv->phypath, match_str, &dpriv->ugenpath);
532
506
  di_devfs_path_free(phypath);
533
507
 
@@ -540,7 +514,7 @@ sunos_fill_in_dev_info(di_node_t node, struct libusb_device *dev)
540
514
  /* address */
541
515
  n = di_prop_lookup_ints(DDI_DEV_T_ANY, node, "assigned-address", &addr);
542
516
  if (n != 1 || *addr == 0) {
543
- usbi_dbg("can't get address");
517
+ usbi_dbg(DEVICE_CTX(dev), "can't get address");
544
518
  } else {
545
519
  dev->device_address = *addr;
546
520
  }
@@ -556,8 +530,8 @@ sunos_fill_in_dev_info(di_node_t node, struct libusb_device *dev)
556
530
  dev->speed = LIBUSB_SPEED_SUPER;
557
531
  }
558
532
 
559
- usbi_dbg("vid=%x pid=%x, path=%s, bus_nmber=0x%x, port_number=%d, "
560
- "speed=%d", dpriv->dev_descr.idVendor, dpriv->dev_descr.idProduct,
533
+ usbi_dbg(DEVICE_CTX(dev), "vid=%x pid=%x, path=%s, bus_nmber=0x%x, port_number=%d, speed=%d",
534
+ dev->device_descriptor.idVendor, dev->device_descriptor.idProduct,
561
535
  dpriv->phypath, dev->bus_number, dev->port_number, dev->speed);
562
536
 
563
537
  return (LIBUSB_SUCCESS);
@@ -578,9 +552,11 @@ sunos_add_devices(di_devlink_t link, void *arg)
578
552
  int i = 0;
579
553
  int *addr_prop;
580
554
  uint8_t bus_number = 0;
581
- uint32_t * regbuf = NULL;
555
+ uint32_t * regbuf = NULL;
582
556
  uint32_t reg;
583
557
 
558
+ UNUSED(link);
559
+
584
560
  nargs = (struct node_args *)largs->nargs;
585
561
  myself = largs->myself;
586
562
 
@@ -595,7 +571,7 @@ sunos_add_devices(di_devlink_t link, void *arg)
595
571
  dn = myself;
596
572
  /* find the root hub */
597
573
  while (di_prop_lookup_ints(DDI_DEV_T_ANY, dn, "root-hub", &j) != 0) {
598
- usbi_dbg("find_root_hub:%s", di_devfs_path(dn));
574
+ usbi_dbg(NULL, "find_root_hub:%s", di_devfs_path(dn));
599
575
  n = di_prop_lookup_ints(DDI_DEV_T_ANY, dn,
600
576
  "assigned-address", &addr_prop);
601
577
  session_id |= ((addr_prop[0] & 0xff) << i++ * 8);
@@ -610,13 +586,13 @@ sunos_add_devices(di_devlink_t link, void *arg)
610
586
  session_id |= (bdf << i * 8);
611
587
  bus_number = (PCI_REG_DEV_G(reg) << 3) | PCI_REG_FUNC_G(reg);
612
588
 
613
- usbi_dbg("device bus address=%s:%x, name:%s",
589
+ usbi_dbg(NULL, "device bus address=%s:%x, name:%s",
614
590
  di_bus_addr(myself), bus_number, di_node_name(dn));
615
- usbi_dbg("session id org:%lx", session_id);
591
+ usbi_dbg(NULL, "session id org:%" PRIx64, session_id);
616
592
 
617
593
  /* dn is the usb device */
618
594
  for (dn = di_child_node(myself); dn != DI_NODE_NIL; dn = di_sibling_node(dn)) {
619
- usbi_dbg("device path:%s", di_devfs_path(dn));
595
+ usbi_dbg(NULL, "device path:%s", di_devfs_path(dn));
620
596
  /* skip hub devices, because its driver can not been unload */
621
597
  if (di_prop_lookup_ints(DDI_DEV_T_ANY, dn, "usb-port-count", &addr_prop) != -1)
622
598
  continue;
@@ -624,40 +600,40 @@ sunos_add_devices(di_devlink_t link, void *arg)
624
600
  n = di_prop_lookup_ints(DDI_DEV_T_ANY, dn,
625
601
  "assigned-address", &addr_prop);
626
602
  if ((n != 1) || (addr_prop[0] == 0)) {
627
- usbi_dbg("cannot get valid usb_addr");
603
+ usbi_dbg(NULL, "cannot get valid usb_addr");
628
604
  continue;
629
605
  }
630
606
 
631
607
  sid = (session_id << 8) | (addr_prop[0] & 0xff) ;
632
- usbi_dbg("session id %lx", sid);
608
+ usbi_dbg(NULL, "session id %" PRIX64, sid);
633
609
 
634
610
  dev = usbi_get_device_by_session_id(nargs->ctx, sid);
635
611
  if (dev == NULL) {
636
612
  dev = usbi_alloc_device(nargs->ctx, sid);
637
613
  if (dev == NULL) {
638
- usbi_dbg("can't alloc device");
614
+ usbi_dbg(NULL, "can't alloc device");
639
615
  continue;
640
616
  }
641
- devpriv = (sunos_dev_priv_t *)dev->os_priv;
617
+ devpriv = usbi_get_device_priv(dev);
642
618
  dev->bus_number = bus_number;
643
619
 
644
620
  if (sunos_fill_in_dev_info(dn, dev) != LIBUSB_SUCCESS) {
645
621
  libusb_unref_device(dev);
646
- usbi_dbg("get infomation fail");
622
+ usbi_dbg(NULL, "get information fail");
647
623
  continue;
648
624
  }
649
625
  if (usbi_sanitize_device(dev) < 0) {
650
626
  libusb_unref_device(dev);
651
- usbi_dbg("sanatize failed: ");
627
+ usbi_dbg(NULL, "sanatize failed: ");
652
628
  return (DI_WALK_TERMINATE);
653
629
  }
654
630
  } else {
655
- devpriv = (sunos_dev_priv_t *)dev->os_priv;
656
- usbi_dbg("Dev %s exists", devpriv->ugenpath);
631
+ devpriv = usbi_get_device_priv(dev);
632
+ usbi_dbg(NULL, "Dev %s exists", devpriv->ugenpath);
657
633
  }
658
634
 
659
635
  if (discovered_devs_append(*(nargs->discdevs), dev) == NULL) {
660
- usbi_dbg("cannot append device");
636
+ usbi_dbg(NULL, "cannot append device");
661
637
  }
662
638
 
663
639
  /*
@@ -666,7 +642,8 @@ sunos_add_devices(di_devlink_t link, void *arg)
666
642
  */
667
643
  libusb_unref_device(dev);
668
644
 
669
- usbi_dbg("Device %s %s id=0x%llx, devcount:%d, bdf=%x",
645
+ usbi_dbg(NULL, "Device %s %s id=0x%" PRIx64 ", devcount:%" PRIuPTR
646
+ ", bdf=%" PRIx64,
670
647
  devpriv->ugenpath, di_devfs_path(dn), (uint64_t)sid,
671
648
  (*nargs->discdevs)->len, bdf);
672
649
  }
@@ -713,13 +690,13 @@ sunos_get_device_list(struct libusb_context * ctx,
713
690
  args.discdevs = discdevs;
714
691
  args.last_ugenpath = NULL;
715
692
  if ((root_node = di_init("/", DINFOCPYALL)) == DI_NODE_NIL) {
716
- usbi_dbg("di_int() failed: %s", strerror(errno));
693
+ usbi_dbg(ctx, "di_int() failed: errno %d (%s)", errno, strerror(errno));
717
694
  return (LIBUSB_ERROR_IO);
718
695
  }
719
696
 
720
697
  if ((devlink_hdl = di_devlink_init(NULL, 0)) == NULL) {
721
698
  di_fini(root_node);
722
- usbi_dbg("di_devlink_init() failed: %s", strerror(errno));
699
+ usbi_dbg(ctx, "di_devlink_init() failed: errno %d (%s)", errno, strerror(errno));
723
700
 
724
701
  return (LIBUSB_ERROR_IO);
725
702
  }
@@ -728,7 +705,7 @@ sunos_get_device_list(struct libusb_context * ctx,
728
705
  /* walk each node to find USB devices */
729
706
  if (di_walk_node(root_node, DI_WALK_SIBFIRST, &args,
730
707
  sunos_walk_minor_node_link) == -1) {
731
- usbi_dbg("di_walk_node() failed: %s", strerror(errno));
708
+ usbi_dbg(ctx, "di_walk_node() failed: errno %d (%s)", errno, strerror(errno));
732
709
  di_fini(root_node);
733
710
 
734
711
  return (LIBUSB_ERROR_IO);
@@ -737,7 +714,7 @@ sunos_get_device_list(struct libusb_context * ctx,
737
714
  di_fini(root_node);
738
715
  di_devlink_fini(&devlink_hdl);
739
716
 
740
- usbi_dbg("%d devices", (*discdevs)->len);
717
+ usbi_dbg(ctx, "%zu devices", (*discdevs)->len);
741
718
 
742
719
  return ((*discdevs)->len);
743
720
  }
@@ -748,12 +725,11 @@ sunos_usb_open_ep0(sunos_dev_handle_priv_t *hpriv, sunos_dev_priv_t *dpriv)
748
725
  char filename[PATH_MAX + 1];
749
726
 
750
727
  if (hpriv->eps[0].datafd > 0) {
751
-
752
728
  return (LIBUSB_SUCCESS);
753
729
  }
754
730
  snprintf(filename, PATH_MAX, "%s/cntrl0", dpriv->ugenpath);
755
731
 
756
- usbi_dbg("opening %s", filename);
732
+ usbi_dbg(NULL, "opening %s", filename);
757
733
  hpriv->eps[0].datafd = open(filename, O_RDWR);
758
734
  if (hpriv->eps[0].datafd < 0) {
759
735
  return(_errno_to_libusb(errno));
@@ -790,7 +766,7 @@ sunos_usb_close_all_eps(sunos_dev_handle_priv_t *hdev)
790
766
  }
791
767
 
792
768
  static void
793
- sunos_usb_close_ep0(sunos_dev_handle_priv_t *hdev, sunos_dev_priv_t *dpriv)
769
+ sunos_usb_close_ep0(sunos_dev_handle_priv_t *hdev)
794
770
  {
795
771
  if (hdev->eps[0].datafd >= 0) {
796
772
  close(hdev->eps[0].datafd);
@@ -860,20 +836,20 @@ sunos_check_device_and_status_open(struct libusb_device_handle *hdl,
860
836
  uint8_t ep_index;
861
837
  sunos_dev_handle_priv_t *hpriv;
862
838
 
863
- usbi_dbg("open ep 0x%02x", ep_addr);
864
- hpriv = (sunos_dev_handle_priv_t *)hdl->os_priv;
839
+ usbi_dbg(HANDLE_CTX(hdl), "open ep 0x%02x", ep_addr);
840
+ hpriv = usbi_get_device_handle_priv(hdl);
865
841
  ep_index = sunos_usb_ep_index(ep_addr);
866
842
  /* ep already opened */
867
843
  if ((hpriv->eps[ep_index].datafd > 0) &&
868
844
  (hpriv->eps[ep_index].statfd > 0)) {
869
- usbi_dbg("ep 0x%02x already opened, return success",
845
+ usbi_dbg(HANDLE_CTX(hdl), "ep 0x%02x already opened, return success",
870
846
  ep_addr);
871
847
 
872
848
  return (0);
873
849
  }
874
850
 
875
851
  if (sunos_find_interface(hdl, ep_addr, &ifc) < 0) {
876
- usbi_dbg("can't find interface for endpoint 0x%02x",
852
+ usbi_dbg(HANDLE_CTX(hdl), "can't find interface for endpoint 0x%02x",
877
853
  ep_addr);
878
854
 
879
855
  return (EACCES);
@@ -881,17 +857,17 @@ sunos_check_device_and_status_open(struct libusb_device_handle *hdl,
881
857
 
882
858
  /* create filename */
883
859
  if (hpriv->config_index > 0) {
884
- (void) snprintf(cfg_num, sizeof (cfg_num), "cfg%d",
860
+ (void) snprintf(cfg_num, sizeof(cfg_num), "cfg%d",
885
861
  hpriv->config_index + 1);
886
862
  } else {
887
- bzero(cfg_num, sizeof (cfg_num));
863
+ bzero(cfg_num, sizeof(cfg_num));
888
864
  }
889
865
 
890
866
  if (hpriv->altsetting[ifc] > 0) {
891
- (void) snprintf(alt_num, sizeof (alt_num), ".%d",
867
+ (void) snprintf(alt_num, sizeof(alt_num), ".%d",
892
868
  hpriv->altsetting[ifc]);
893
869
  } else {
894
- bzero(alt_num, sizeof (alt_num));
870
+ bzero(alt_num, sizeof(alt_num));
895
871
  }
896
872
 
897
873
  (void) snprintf(filename, PATH_MAX, "%s/%sif%d%s%s%d",
@@ -901,66 +877,82 @@ sunos_check_device_and_status_open(struct libusb_device_handle *hdl,
901
877
  (void) snprintf(statfilename, PATH_MAX, "%sstat", filename);
902
878
 
903
879
  /*
904
- * for interrupt IN endpoints, we need to enable one xfer
905
- * mode before opening the endpoint
880
+ * In case configuration has been switched, the xfer endpoint needs
881
+ * to be opened before the status endpoint, due to a ugen issue.
882
+ * However, to enable the one transfer mode for an Interrupt-In pipe,
883
+ * the status endpoint needs to be opened before the xfer endpoint.
884
+ * So, open the xfer mode first and close it immediately
885
+ * as a workaround. This will handle the configuration switch.
886
+ * Then, open the status endpoint. If for an Interrupt-in pipe,
887
+ * write the USB_EP_INTR_ONE_XFER control to the status endpoint
888
+ * to enable the one transfer mode. Then, re-open the xfer mode.
889
+ */
890
+ if (ep_type == LIBUSB_TRANSFER_TYPE_ISOCHRONOUS) {
891
+ mode = O_RDWR;
892
+ } else if (ep_addr & LIBUSB_ENDPOINT_IN) {
893
+ mode = O_RDONLY;
894
+ } else {
895
+ mode = O_WRONLY;
896
+ }
897
+ /* Open the xfer endpoint first */
898
+ if ((fd = open(filename, mode)) == -1) {
899
+ usbi_dbg(HANDLE_CTX(hdl), "can't open %s: errno %d (%s)", filename, errno,
900
+ strerror(errno));
901
+
902
+ return (errno);
903
+ }
904
+ /* And immediately close the xfer endpoint */
905
+ (void) close(fd);
906
+
907
+ /*
908
+ * Open the status endpoint.
909
+ * If for an Interrupt-IN pipe, need to enable the one transfer mode
910
+ * by writing USB_EP_INTR_ONE_XFER control to the status endpoint
911
+ * before opening the xfer endpoint
906
912
  */
907
913
  if ((ep_type == LIBUSB_TRANSFER_TYPE_INTERRUPT) &&
908
914
  (ep_addr & LIBUSB_ENDPOINT_IN)) {
909
915
  char control = USB_EP_INTR_ONE_XFER;
910
- int count;
916
+ ssize_t count;
911
917
 
912
- /* open the status device node for the ep first RDWR */
918
+ /* Open the status endpoint with RDWR */
913
919
  if ((fdstat = open(statfilename, O_RDWR)) == -1) {
914
- usbi_dbg("can't open %s RDWR: %d",
915
- statfilename, errno);
920
+ usbi_dbg(HANDLE_CTX(hdl), "can't open %s RDWR: errno %d (%s)",
921
+ statfilename, errno, strerror(errno));
922
+
923
+ return (errno);
916
924
  } else {
917
- count = write(fdstat, &control, sizeof (control));
925
+ count = write(fdstat, &control, sizeof(control));
918
926
  if (count != 1) {
919
927
  /* this should have worked */
920
- usbi_dbg("can't write to %s: %d",
921
- statfilename, errno);
928
+ usbi_dbg(HANDLE_CTX(hdl), "can't write to %s: errno %d (%s)",
929
+ statfilename, errno, strerror(errno));
922
930
  (void) close(fdstat);
923
931
 
924
932
  return (errno);
925
933
  }
926
- /* close status node and open xfer node first */
927
- close (fdstat);
928
934
  }
929
- }
930
-
931
- /* open the xfer node first in case alt needs to be changed */
932
- if (ep_type == LIBUSB_TRANSFER_TYPE_ISOCHRONOUS) {
933
- mode = O_RDWR;
934
- } else if (ep_addr & LIBUSB_ENDPOINT_IN) {
935
- mode = O_RDONLY;
936
935
  } else {
937
- mode = O_WRONLY;
938
- }
936
+ if ((fdstat = open(statfilename, O_RDONLY)) == -1) {
937
+ usbi_dbg(HANDLE_CTX(hdl), "can't open %s: errno %d (%s)", statfilename, errno,
938
+ strerror(errno));
939
939
 
940
- /*
941
- * IMPORTANT: must open data xfer node first and then open stat node
942
- * Otherwise, it will fail on multi-config or multi-altsetting devices
943
- * with "Device Busy" error. See ugen_epxs_switch_cfg_alt() and
944
- * ugen_epxs_check_alt_switch() in ugen driver source code.
945
- */
946
- if ((fd = open(filename, mode)) == -1) {
947
- usbi_dbg("can't open %s: %d(%s)", filename, errno,
948
- strerror(errno));
949
-
950
- return (errno);
940
+ return (errno);
941
+ }
951
942
  }
952
- /* open the status node */
953
- if ((fdstat = open(statfilename, O_RDONLY)) == -1) {
954
- usbi_dbg("can't open %s: %d", statfilename, errno);
955
943
 
956
- (void) close(fd);
944
+ /* Re-open the xfer endpoint */
945
+ if ((fd = open(filename, mode)) == -1) {
946
+ usbi_dbg(HANDLE_CTX(hdl), "can't open %s: errno %d (%s)", filename, errno,
947
+ strerror(errno));
948
+ (void) close(fdstat);
957
949
 
958
950
  return (errno);
959
951
  }
960
952
 
961
953
  hpriv->eps[ep_index].datafd = fd;
962
954
  hpriv->eps[ep_index].statfd = fdstat;
963
- usbi_dbg("ep=0x%02x datafd=%d, statfd=%d", ep_addr, fd, fdstat);
955
+ usbi_dbg(HANDLE_CTX(hdl), "ep=0x%02x datafd=%d, statfd=%d", ep_addr, fd, fdstat);
964
956
 
965
957
  return (0);
966
958
  }
@@ -973,8 +965,8 @@ sunos_open(struct libusb_device_handle *handle)
973
965
  int i;
974
966
  int ret;
975
967
 
976
- hpriv = (sunos_dev_handle_priv_t *)handle->os_priv;
977
- dpriv = (sunos_dev_priv_t *)handle->dev->os_priv;
968
+ hpriv = usbi_get_device_handle_priv(handle);
969
+ dpriv = usbi_get_device_priv(handle->dev);
978
970
  hpriv->dpriv = dpriv;
979
971
 
980
972
  /* set all file descriptors to "closed" */
@@ -989,7 +981,7 @@ sunos_open(struct libusb_device_handle *handle)
989
981
  }
990
982
 
991
983
  if ((ret = sunos_usb_open_ep0(hpriv, dpriv)) != LIBUSB_SUCCESS) {
992
- usbi_dbg("fail: %d", ret);
984
+ usbi_dbg(HANDLE_CTX(handle), "fail: %d", ret);
993
985
  return (ret);
994
986
  }
995
987
 
@@ -1000,43 +992,20 @@ void
1000
992
  sunos_close(struct libusb_device_handle *handle)
1001
993
  {
1002
994
  sunos_dev_handle_priv_t *hpriv;
1003
- sunos_dev_priv_t *dpriv;
1004
995
 
1005
- usbi_dbg("");
1006
- if (!handle) {
1007
- return;
1008
- }
996
+ usbi_dbg(HANDLE_CTX(handle), " ");
1009
997
 
1010
- hpriv = (sunos_dev_handle_priv_t *)handle->os_priv;
1011
- if (!hpriv) {
1012
- return;
1013
- }
1014
- dpriv = (sunos_dev_priv_t *)handle->dev->os_priv;
1015
- if (!dpriv) {
1016
- return;
1017
- }
998
+ hpriv = usbi_get_device_handle_priv(handle);
1018
999
 
1019
1000
  sunos_usb_close_all_eps(hpriv);
1020
- sunos_usb_close_ep0(hpriv, dpriv);
1021
- }
1022
-
1023
- int
1024
- sunos_get_device_descriptor(struct libusb_device *dev, uint8_t *buf,
1025
- int *host_endian)
1026
- {
1027
- sunos_dev_priv_t *dpriv = (sunos_dev_priv_t *)dev->os_priv;
1028
-
1029
- memcpy(buf, &dpriv->dev_descr, LIBUSB_DT_DEVICE_SIZE);
1030
- *host_endian = 0;
1031
-
1032
- return (LIBUSB_SUCCESS);
1001
+ sunos_usb_close_ep0(hpriv);
1033
1002
  }
1034
1003
 
1035
1004
  int
1036
1005
  sunos_get_active_config_descriptor(struct libusb_device *dev,
1037
- uint8_t *buf, size_t len, int *host_endian)
1006
+ void *buf, size_t len)
1038
1007
  {
1039
- sunos_dev_priv_t *dpriv = (sunos_dev_priv_t *)dev->os_priv;
1008
+ sunos_dev_priv_t *dpriv = usbi_get_device_priv(dev);
1040
1009
  struct libusb_config_descriptor *cfg;
1041
1010
  int proplen;
1042
1011
  di_node_t node;
@@ -1047,13 +1016,14 @@ sunos_get_active_config_descriptor(struct libusb_device *dev,
1047
1016
  * has ever been changed through setCfg.
1048
1017
  */
1049
1018
  if ((node = di_init(dpriv->phypath, DINFOCPYALL)) == DI_NODE_NIL) {
1050
- usbi_dbg("di_int() failed: %s", strerror(errno));
1019
+ usbi_dbg(DEVICE_CTX(dev), "di_int() failed: errno %d (%s)", errno,
1020
+ strerror(errno));
1051
1021
  return (LIBUSB_ERROR_IO);
1052
1022
  }
1053
1023
  proplen = di_prop_lookup_bytes(DDI_DEV_T_ANY, node,
1054
1024
  "usb-raw-cfg-descriptors", &rdata);
1055
1025
  if (proplen <= 0) {
1056
- usbi_dbg("can't find raw config descriptors");
1026
+ usbi_dbg(DEVICE_CTX(dev), "can't find raw config descriptors");
1057
1027
 
1058
1028
  return (LIBUSB_ERROR_IO);
1059
1029
  }
@@ -1070,28 +1040,28 @@ sunos_get_active_config_descriptor(struct libusb_device *dev,
1070
1040
  cfg = (struct libusb_config_descriptor *)dpriv->raw_cfgdescr;
1071
1041
  len = MIN(len, libusb_le16_to_cpu(cfg->wTotalLength));
1072
1042
  memcpy(buf, dpriv->raw_cfgdescr, len);
1073
- *host_endian = 0;
1074
- usbi_dbg("path:%s len %d", dpriv->phypath, len);
1043
+ usbi_dbg(DEVICE_CTX(dev), "path:%s len %zu", dpriv->phypath, len);
1075
1044
 
1076
1045
  return (len);
1077
1046
  }
1078
1047
 
1079
1048
  int
1080
1049
  sunos_get_config_descriptor(struct libusb_device *dev, uint8_t idx,
1081
- uint8_t *buf, size_t len, int *host_endian)
1050
+ void *buf, size_t len)
1082
1051
  {
1052
+ UNUSED(idx);
1083
1053
  /* XXX */
1084
- return(sunos_get_active_config_descriptor(dev, buf, len, host_endian));
1054
+ return(sunos_get_active_config_descriptor(dev, buf, len));
1085
1055
  }
1086
1056
 
1087
1057
  int
1088
- sunos_get_configuration(struct libusb_device_handle *handle, int *config)
1058
+ sunos_get_configuration(struct libusb_device_handle *handle, uint8_t *config)
1089
1059
  {
1090
- sunos_dev_priv_t *dpriv = (sunos_dev_priv_t *)handle->dev->os_priv;
1060
+ sunos_dev_priv_t *dpriv = usbi_get_device_priv(handle->dev);
1091
1061
 
1092
1062
  *config = dpriv->cfgvalue;
1093
1063
 
1094
- usbi_dbg("bConfigurationValue %d", *config);
1064
+ usbi_dbg(HANDLE_CTX(handle), "bConfigurationValue %u", *config);
1095
1065
 
1096
1066
  return (LIBUSB_SUCCESS);
1097
1067
  }
@@ -1099,17 +1069,17 @@ sunos_get_configuration(struct libusb_device_handle *handle, int *config)
1099
1069
  int
1100
1070
  sunos_set_configuration(struct libusb_device_handle *handle, int config)
1101
1071
  {
1102
- sunos_dev_priv_t *dpriv = (sunos_dev_priv_t *)handle->dev->os_priv;
1072
+ sunos_dev_priv_t *dpriv = usbi_get_device_priv(handle->dev);
1103
1073
  sunos_dev_handle_priv_t *hpriv;
1104
1074
 
1105
- usbi_dbg("bConfigurationValue %d", config);
1106
- hpriv = (sunos_dev_handle_priv_t *)handle->os_priv;
1075
+ usbi_dbg(HANDLE_CTX(handle), "bConfigurationValue %d", config);
1076
+ hpriv = usbi_get_device_handle_priv(handle);
1107
1077
 
1108
1078
  if (dpriv->ugenpath == NULL)
1109
1079
  return (LIBUSB_ERROR_NOT_SUPPORTED);
1110
1080
 
1111
- if (config < 1 || config > dpriv->dev_descr.bNumConfigurations)
1112
- return (LIBUSB_ERROR_INVALID_PARAM);
1081
+ if (config < 1)
1082
+ return (LIBUSB_ERROR_NOT_SUPPORTED);
1113
1083
 
1114
1084
  dpriv->cfgvalue = config;
1115
1085
  hpriv->config_index = config - 1;
@@ -1118,26 +1088,21 @@ sunos_set_configuration(struct libusb_device_handle *handle, int config)
1118
1088
  }
1119
1089
 
1120
1090
  int
1121
- sunos_claim_interface(struct libusb_device_handle *handle, int iface)
1091
+ sunos_claim_interface(struct libusb_device_handle *handle, uint8_t iface)
1122
1092
  {
1123
- usbi_dbg("iface %d", iface);
1124
- if (iface < 0) {
1125
- return (LIBUSB_ERROR_INVALID_PARAM);
1126
- }
1093
+ UNUSED(handle);
1094
+
1095
+ usbi_dbg(HANDLE_CTX(handle), "iface %u", iface);
1127
1096
 
1128
1097
  return (LIBUSB_SUCCESS);
1129
1098
  }
1130
1099
 
1131
1100
  int
1132
- sunos_release_interface(struct libusb_device_handle *handle, int iface)
1101
+ sunos_release_interface(struct libusb_device_handle *handle, uint8_t iface)
1133
1102
  {
1134
- sunos_dev_handle_priv_t *hpriv =
1135
- (sunos_dev_handle_priv_t *)handle->os_priv;
1103
+ sunos_dev_handle_priv_t *hpriv = usbi_get_device_handle_priv(handle);
1136
1104
 
1137
- usbi_dbg("iface %d", iface);
1138
- if (iface < 0) {
1139
- return (LIBUSB_ERROR_INVALID_PARAM);
1140
- }
1105
+ usbi_dbg(HANDLE_CTX(handle), "iface %u", iface);
1141
1106
 
1142
1107
  /* XXX: can we release it? */
1143
1108
  hpriv->altsetting[iface] = 0;
@@ -1146,18 +1111,14 @@ sunos_release_interface(struct libusb_device_handle *handle, int iface)
1146
1111
  }
1147
1112
 
1148
1113
  int
1149
- sunos_set_interface_altsetting(struct libusb_device_handle *handle, int iface,
1150
- int altsetting)
1114
+ sunos_set_interface_altsetting(struct libusb_device_handle *handle, uint8_t iface,
1115
+ uint8_t altsetting)
1151
1116
  {
1152
- sunos_dev_priv_t *dpriv = (sunos_dev_priv_t *)handle->dev->os_priv;
1153
- sunos_dev_handle_priv_t *hpriv =
1154
- (sunos_dev_handle_priv_t *)handle->os_priv;
1117
+ sunos_dev_priv_t *dpriv = usbi_get_device_priv(handle->dev);
1118
+ sunos_dev_handle_priv_t *hpriv = usbi_get_device_handle_priv(handle);
1155
1119
 
1156
- usbi_dbg("iface %d, setting %d", iface, altsetting);
1120
+ usbi_dbg(HANDLE_CTX(handle), "iface %u, setting %u", iface, altsetting);
1157
1121
 
1158
- if (iface < 0 || altsetting < 0) {
1159
- return (LIBUSB_ERROR_INVALID_PARAM);
1160
- }
1161
1122
  if (dpriv->ugenpath == NULL)
1162
1123
  return (LIBUSB_ERROR_NOT_FOUND);
1163
1124
 
@@ -1168,9 +1129,10 @@ sunos_set_interface_altsetting(struct libusb_device_handle *handle, int iface,
1168
1129
  }
1169
1130
 
1170
1131
  static void
1171
- usb_dump_data(unsigned char *data, size_t size)
1132
+ usb_dump_data(const void *data, size_t size)
1172
1133
  {
1173
- int i;
1134
+ const uint8_t *p = data;
1135
+ size_t i;
1174
1136
 
1175
1137
  if (getenv("LIBUSB_DEBUG") == NULL) {
1176
1138
  return;
@@ -1179,9 +1141,9 @@ usb_dump_data(unsigned char *data, size_t size)
1179
1141
  (void) fprintf(stderr, "data dump:");
1180
1142
  for (i = 0; i < size; i++) {
1181
1143
  if (i % 16 == 0) {
1182
- (void) fprintf(stderr, "\n%08x ", i);
1144
+ (void) fprintf(stderr, "\n%08zx ", i);
1183
1145
  }
1184
- (void) fprintf(stderr, "%02x ", (uchar_t)data[i]);
1146
+ (void) fprintf(stderr, "%02x ", p[i]);
1185
1147
  }
1186
1148
  (void) fprintf(stderr, "\n");
1187
1149
  }
@@ -1202,12 +1164,12 @@ sunos_async_callback(union sigval arg)
1202
1164
 
1203
1165
  /* libusb can forcibly interrupt transfer in do_close() */
1204
1166
  if (dev_handle != NULL) {
1205
- hpriv = (sunos_dev_handle_priv_t *)dev_handle->os_priv;
1167
+ hpriv = usbi_get_device_handle_priv(dev_handle);
1206
1168
  ep = sunos_usb_ep_index(xfer->endpoint);
1207
1169
 
1208
1170
  ret = aio_error(aiocb);
1209
1171
  if (ret != 0) {
1210
- xfer->status = sunos_usb_get_status(hpriv->eps[ep].statfd);
1172
+ xfer->status = sunos_usb_get_status(TRANSFER_CTX(xfer), hpriv->eps[ep].statfd);
1211
1173
  } else {
1212
1174
  xfer->actual_length =
1213
1175
  LIBUSB_TRANSFER_TO_USBI_TRANSFER(xfer)->transferred =
@@ -1216,7 +1178,7 @@ sunos_async_callback(union sigval arg)
1216
1178
 
1217
1179
  usb_dump_data(xfer->buffer, xfer->actual_length);
1218
1180
 
1219
- usbi_dbg("ret=%d, len=%d, actual_len=%d", ret, xfer->length,
1181
+ usbi_dbg(TRANSFER_CTX(xfer), "ret=%d, len=%d, actual_len=%d", ret, xfer->length,
1220
1182
  xfer->actual_length);
1221
1183
 
1222
1184
  /* async notification */
@@ -1233,15 +1195,15 @@ sunos_do_async_io(struct libusb_transfer *transfer)
1233
1195
  uint8_t ep;
1234
1196
  struct sunos_transfer_priv *tpriv;
1235
1197
 
1236
- usbi_dbg("");
1198
+ usbi_dbg(TRANSFER_CTX(transfer), " ");
1237
1199
 
1238
- tpriv = usbi_transfer_get_os_priv(LIBUSB_TRANSFER_TO_USBI_TRANSFER(transfer));
1239
- hpriv = (sunos_dev_handle_priv_t *)transfer->dev_handle->os_priv;
1200
+ tpriv = usbi_get_transfer_priv(LIBUSB_TRANSFER_TO_USBI_TRANSFER(transfer));
1201
+ hpriv = usbi_get_device_handle_priv(transfer->dev_handle);
1240
1202
  ep = sunos_usb_ep_index(transfer->endpoint);
1241
1203
 
1242
1204
  tpriv->transfer = transfer;
1243
1205
  aiocb = &tpriv->aiocb;
1244
- bzero(aiocb, sizeof (*aiocb));
1206
+ bzero(aiocb, sizeof(*aiocb));
1245
1207
  aiocb->aio_fildes = hpriv->eps[ep].datafd;
1246
1208
  aiocb->aio_buf = transfer->buffer;
1247
1209
  aiocb->aio_nbytes = transfer->length;
@@ -1262,13 +1224,13 @@ sunos_do_async_io(struct libusb_transfer *transfer)
1262
1224
  }
1263
1225
 
1264
1226
  /* return the number of bytes read/written */
1265
- static int
1266
- usb_do_io(int fd, int stat_fd, char *data, size_t size, int flag, int *status)
1227
+ static ssize_t
1228
+ usb_do_io(struct libusb_context *ctx, int fd, int stat_fd, void *data, size_t size, int flag, int *status)
1267
1229
  {
1268
1230
  int error;
1269
- int ret = -1;
1231
+ ssize_t ret = -1;
1270
1232
 
1271
- usbi_dbg("usb_do_io(): datafd=%d statfd=%d size=0x%x flag=%s",
1233
+ usbi_dbg(ctx, "usb_do_io(): datafd=%d statfd=%d size=0x%zx flag=%s",
1272
1234
  fd, stat_fd, size, flag? "WRITE":"READ");
1273
1235
 
1274
1236
  switch (flag) {
@@ -1284,17 +1246,17 @@ usb_do_io(int fd, int stat_fd, char *data, size_t size, int flag, int *status)
1284
1246
  break;
1285
1247
  }
1286
1248
 
1287
- usbi_dbg("usb_do_io(): amount=%d", ret);
1249
+ usbi_dbg(ctx, "usb_do_io(): amount=%zd", ret);
1288
1250
 
1289
1251
  if (ret < 0) {
1290
1252
  int save_errno = errno;
1291
1253
 
1292
- usbi_dbg("TID=%x io %s errno=%d(%s) ret=%d", pthread_self(),
1293
- flag?"WRITE":"READ", errno, strerror(errno), ret);
1254
+ usbi_dbg(ctx, "TID=%x io %s errno %d (%s)", pthread_self(),
1255
+ flag?"WRITE":"READ", errno, strerror(errno));
1294
1256
 
1295
1257
  /* sunos_usb_get_status will do a read and overwrite errno */
1296
- error = sunos_usb_get_status(stat_fd);
1297
- usbi_dbg("io status=%d errno=%d(%s)", error,
1258
+ error = sunos_usb_get_status(ctx, stat_fd);
1259
+ usbi_dbg(ctx, "io status=%d errno %d (%s)", error,
1298
1260
  save_errno, strerror(save_errno));
1299
1261
 
1300
1262
  if (status) {
@@ -1313,37 +1275,37 @@ usb_do_io(int fd, int stat_fd, char *data, size_t size, int flag, int *status)
1313
1275
  static int
1314
1276
  solaris_submit_ctrl_on_default(struct libusb_transfer *transfer)
1315
1277
  {
1316
- int ret = -1, setup_ret;
1278
+ ssize_t ret = -1, setup_ret;
1317
1279
  int status;
1318
1280
  sunos_dev_handle_priv_t *hpriv;
1319
1281
  struct libusb_device_handle *hdl = transfer->dev_handle;
1320
1282
  uint16_t wLength;
1321
1283
  uint8_t *data = transfer->buffer;
1322
1284
 
1323
- hpriv = (sunos_dev_handle_priv_t *)hdl->os_priv;
1285
+ hpriv = usbi_get_device_handle_priv(hdl);
1324
1286
  wLength = transfer->length - LIBUSB_CONTROL_SETUP_SIZE;
1325
1287
 
1326
1288
  if (hpriv->eps[0].datafd == -1) {
1327
- usbi_dbg("ep0 not opened");
1289
+ usbi_dbg(TRANSFER_CTX(transfer), "ep0 not opened");
1328
1290
 
1329
1291
  return (LIBUSB_ERROR_NOT_FOUND);
1330
1292
  }
1331
1293
 
1332
1294
  if ((data[0] & LIBUSB_ENDPOINT_DIR_MASK) == LIBUSB_ENDPOINT_IN) {
1333
- usbi_dbg("IN request");
1334
- ret = usb_do_io(hpriv->eps[0].datafd,
1335
- hpriv->eps[0].statfd, (char *)data, LIBUSB_CONTROL_SETUP_SIZE,
1336
- WRITE, (int *)&status);
1295
+ usbi_dbg(TRANSFER_CTX(transfer), "IN request");
1296
+ ret = usb_do_io(TRANSFER_CTX(transfer), hpriv->eps[0].datafd,
1297
+ hpriv->eps[0].statfd, data, LIBUSB_CONTROL_SETUP_SIZE,
1298
+ WRITE, &status);
1337
1299
  } else {
1338
- usbi_dbg("OUT request");
1339
- ret = usb_do_io(hpriv->eps[0].datafd, hpriv->eps[0].statfd,
1300
+ usbi_dbg(TRANSFER_CTX(transfer), "OUT request");
1301
+ ret = usb_do_io(TRANSFER_CTX(transfer), hpriv->eps[0].datafd, hpriv->eps[0].statfd,
1340
1302
  transfer->buffer, transfer->length, WRITE,
1341
1303
  (int *)&transfer->status);
1342
1304
  }
1343
1305
 
1344
1306
  setup_ret = ret;
1345
- if (ret < LIBUSB_CONTROL_SETUP_SIZE) {
1346
- usbi_dbg("error sending control msg: %d", ret);
1307
+ if (ret < (ssize_t)LIBUSB_CONTROL_SETUP_SIZE) {
1308
+ usbi_dbg(TRANSFER_CTX(transfer), "error sending control msg: %zd", ret);
1347
1309
 
1348
1310
  return (LIBUSB_ERROR_IO);
1349
1311
  }
@@ -1353,18 +1315,17 @@ solaris_submit_ctrl_on_default(struct libusb_transfer *transfer)
1353
1315
  /* Read the remaining bytes for IN request */
1354
1316
  if ((wLength) && ((data[0] & LIBUSB_ENDPOINT_DIR_MASK) ==
1355
1317
  LIBUSB_ENDPOINT_IN)) {
1356
- usbi_dbg("DATA: %d", transfer->length - setup_ret);
1357
- ret = usb_do_io(hpriv->eps[0].datafd,
1318
+ usbi_dbg(TRANSFER_CTX(transfer), "DATA: %d", transfer->length - (int)setup_ret);
1319
+ ret = usb_do_io(TRANSFER_CTX(transfer), hpriv->eps[0].datafd,
1358
1320
  hpriv->eps[0].statfd,
1359
- (char *)transfer->buffer + LIBUSB_CONTROL_SETUP_SIZE,
1321
+ transfer->buffer + LIBUSB_CONTROL_SETUP_SIZE,
1360
1322
  wLength, READ, (int *)&transfer->status);
1361
1323
  }
1362
1324
 
1363
1325
  if (ret >= 0) {
1364
- transfer->actual_length = ret;
1365
1326
  LIBUSB_TRANSFER_TO_USBI_TRANSFER(transfer)->transferred = ret;
1366
1327
  }
1367
- usbi_dbg("Done: ctrl data bytes %d", ret);
1328
+ usbi_dbg(TRANSFER_CTX(transfer), "Done: ctrl data bytes %zd", ret);
1368
1329
 
1369
1330
  /**
1370
1331
  * Sync transfer handling.
@@ -1380,34 +1341,27 @@ solaris_submit_ctrl_on_default(struct libusb_transfer *transfer)
1380
1341
  }
1381
1342
 
1382
1343
  int
1383
- sunos_clear_halt(struct libusb_device_handle *handle, uint8_t endpoint)
1344
+ sunos_clear_halt(struct libusb_device_handle *handle, unsigned char endpoint)
1384
1345
  {
1385
1346
  int ret;
1386
1347
 
1387
- usbi_dbg("endpoint=0x%02x", endpoint);
1348
+ usbi_dbg(HANDLE_CTX(handle), "endpoint=0x%02x", endpoint);
1388
1349
 
1389
1350
  ret = libusb_control_transfer(handle, LIBUSB_ENDPOINT_OUT |
1390
1351
  LIBUSB_RECIPIENT_ENDPOINT | LIBUSB_REQUEST_TYPE_STANDARD,
1391
1352
  LIBUSB_REQUEST_CLEAR_FEATURE, 0, endpoint, NULL, 0, 1000);
1392
1353
 
1393
- usbi_dbg("ret=%d", ret);
1354
+ usbi_dbg(HANDLE_CTX(handle), "ret=%d", ret);
1394
1355
 
1395
1356
  return (ret);
1396
1357
  }
1397
1358
 
1398
- int
1399
- sunos_reset_device(struct libusb_device_handle *handle)
1400
- {
1401
- usbi_dbg("");
1402
-
1403
- return (LIBUSB_ERROR_NOT_SUPPORTED);
1404
- }
1405
-
1406
1359
  void
1407
1360
  sunos_destroy_device(struct libusb_device *dev)
1408
1361
  {
1409
- sunos_dev_priv_t *dpriv = (sunos_dev_priv_t *)dev->os_priv;
1410
- usbi_dbg("destroy everyting");
1362
+ sunos_dev_priv_t *dpriv = usbi_get_device_priv(dev);
1363
+
1364
+ usbi_dbg(DEVICE_CTX(dev), "destroy everything");
1411
1365
  free(dpriv->raw_cfgdescr);
1412
1366
  free(dpriv->ugenpath);
1413
1367
  free(dpriv->phypath);
@@ -1433,7 +1387,7 @@ sunos_submit_transfer(struct usbi_transfer *itransfer)
1433
1387
  switch (transfer->type) {
1434
1388
  case LIBUSB_TRANSFER_TYPE_CONTROL:
1435
1389
  /* sync transfer */
1436
- usbi_dbg("CTRL transfer: %d", transfer->length);
1390
+ usbi_dbg(ITRANSFER_CTX(itransfer), "CTRL transfer: %d", transfer->length);
1437
1391
  err = solaris_submit_ctrl_on_default(transfer);
1438
1392
  break;
1439
1393
 
@@ -1441,9 +1395,9 @@ sunos_submit_transfer(struct usbi_transfer *itransfer)
1441
1395
  /* fallthru */
1442
1396
  case LIBUSB_TRANSFER_TYPE_INTERRUPT:
1443
1397
  if (transfer->type == LIBUSB_TRANSFER_TYPE_BULK)
1444
- usbi_dbg("BULK transfer: %d", transfer->length);
1398
+ usbi_dbg(ITRANSFER_CTX(itransfer), "BULK transfer: %d", transfer->length);
1445
1399
  else
1446
- usbi_dbg("INTR transfer: %d", transfer->length);
1400
+ usbi_dbg(ITRANSFER_CTX(itransfer), "INTR transfer: %d", transfer->length);
1447
1401
  err = sunos_do_async_io(transfer);
1448
1402
  break;
1449
1403
 
@@ -1453,9 +1407,9 @@ sunos_submit_transfer(struct usbi_transfer *itransfer)
1453
1407
  /* fallthru */
1454
1408
  case LIBUSB_TRANSFER_TYPE_BULK_STREAM:
1455
1409
  if (transfer->type == LIBUSB_TRANSFER_TYPE_ISOCHRONOUS)
1456
- usbi_dbg("ISOC transfer: %d", transfer->length);
1410
+ usbi_dbg(ITRANSFER_CTX(itransfer), "ISOC transfer: %d", transfer->length);
1457
1411
  else
1458
- usbi_dbg("BULK STREAM transfer: %d", transfer->length);
1412
+ usbi_dbg(ITRANSFER_CTX(itransfer), "BULK STREAM transfer: %d", transfer->length);
1459
1413
  err = LIBUSB_ERROR_NOT_SUPPORTED;
1460
1414
  break;
1461
1415
  }
@@ -1473,15 +1427,15 @@ sunos_cancel_transfer(struct usbi_transfer *itransfer)
1473
1427
  uint8_t ep;
1474
1428
  int ret;
1475
1429
 
1476
- tpriv = usbi_transfer_get_os_priv(itransfer);
1430
+ tpriv = usbi_get_transfer_priv(itransfer);
1477
1431
  aiocb = &tpriv->aiocb;
1478
1432
  transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
1479
- hpriv = (sunos_dev_handle_priv_t *)transfer->dev_handle->os_priv;
1433
+ hpriv = usbi_get_device_handle_priv(transfer->dev_handle);
1480
1434
  ep = sunos_usb_ep_index(transfer->endpoint);
1481
1435
 
1482
1436
  ret = aio_cancel(hpriv->eps[ep].datafd, aiocb);
1483
1437
 
1484
- usbi_dbg("aio->fd=%d fd=%d ret = %d, %s", aiocb->aio_fildes,
1438
+ usbi_dbg(ITRANSFER_CTX(itransfer), "aio->fd=%d fd=%d ret = %d, %s", aiocb->aio_fildes,
1485
1439
  hpriv->eps[ep].datafd, ret, (ret == AIO_CANCELED)?
1486
1440
  strerror(0):strerror(errno));
1487
1441
 
@@ -1498,36 +1452,16 @@ sunos_cancel_transfer(struct usbi_transfer *itransfer)
1498
1452
  return (ret);
1499
1453
  }
1500
1454
 
1501
- void
1502
- sunos_clear_transfer_priv(struct usbi_transfer *itransfer)
1503
- {
1504
- usbi_dbg("");
1505
-
1506
- /* Nothing to do */
1507
- }
1508
-
1509
1455
  int
1510
1456
  sunos_handle_transfer_completion(struct usbi_transfer *itransfer)
1511
1457
  {
1512
1458
  return usbi_handle_transfer_completion(itransfer, LIBUSB_TRANSFER_COMPLETED);
1513
1459
  }
1514
1460
 
1515
- int
1516
- sunos_clock_gettime(int clkid, struct timespec *tp)
1517
- {
1518
- if (clkid == USBI_CLOCK_REALTIME)
1519
- return clock_gettime(CLOCK_REALTIME, tp);
1520
-
1521
- if (clkid == USBI_CLOCK_MONOTONIC)
1522
- return clock_gettime(CLOCK_MONOTONIC, tp);
1523
-
1524
- return (LIBUSB_ERROR_INVALID_PARAM);
1525
- }
1526
-
1527
1461
  int
1528
1462
  _errno_to_libusb(int err)
1529
1463
  {
1530
- usbi_dbg("error: %s (%d)", strerror(err), err);
1464
+ usbi_dbg(NULL, "error: %s (%d)", strerror(err), err);
1531
1465
 
1532
1466
  switch (err) {
1533
1467
  case EIO:
@@ -1552,143 +1486,123 @@ _errno_to_libusb(int err)
1552
1486
  * Returns: ugen's last cmd status
1553
1487
  */
1554
1488
  static int
1555
- sunos_usb_get_status(int fd)
1489
+ sunos_usb_get_status(struct libusb_context *ctx, int fd)
1556
1490
  {
1557
- int status, ret;
1491
+ int status;
1492
+ ssize_t ret;
1558
1493
 
1559
- usbi_dbg("sunos_usb_get_status(): fd=%d", fd);
1494
+ usbi_dbg(ctx, "sunos_usb_get_status(): fd=%d", fd);
1560
1495
 
1561
- ret = read(fd, &status, sizeof (status));
1562
- if (ret == sizeof (status)) {
1496
+ ret = read(fd, &status, sizeof(status));
1497
+ if (ret == sizeof(status)) {
1563
1498
  switch (status) {
1564
1499
  case USB_LC_STAT_NOERROR:
1565
- usbi_dbg("No Error");
1500
+ usbi_dbg(ctx, "No Error");
1566
1501
  break;
1567
1502
  case USB_LC_STAT_CRC:
1568
- usbi_dbg("CRC Timeout Detected\n");
1503
+ usbi_dbg(ctx, "CRC Timeout Detected\n");
1569
1504
  break;
1570
1505
  case USB_LC_STAT_BITSTUFFING:
1571
- usbi_dbg("Bit Stuffing Violation\n");
1506
+ usbi_dbg(ctx, "Bit Stuffing Violation\n");
1572
1507
  break;
1573
1508
  case USB_LC_STAT_DATA_TOGGLE_MM:
1574
- usbi_dbg("Data Toggle Mismatch\n");
1509
+ usbi_dbg(ctx, "Data Toggle Mismatch\n");
1575
1510
  break;
1576
1511
  case USB_LC_STAT_STALL:
1577
- usbi_dbg("End Point Stalled\n");
1512
+ usbi_dbg(ctx, "End Point Stalled\n");
1578
1513
  break;
1579
1514
  case USB_LC_STAT_DEV_NOT_RESP:
1580
- usbi_dbg("Device is Not Responding\n");
1515
+ usbi_dbg(ctx, "Device is Not Responding\n");
1581
1516
  break;
1582
1517
  case USB_LC_STAT_PID_CHECKFAILURE:
1583
- usbi_dbg("PID Check Failure\n");
1518
+ usbi_dbg(ctx, "PID Check Failure\n");
1584
1519
  break;
1585
1520
  case USB_LC_STAT_UNEXP_PID:
1586
- usbi_dbg("Unexpected PID\n");
1521
+ usbi_dbg(ctx, "Unexpected PID\n");
1587
1522
  break;
1588
1523
  case USB_LC_STAT_DATA_OVERRUN:
1589
- usbi_dbg("Data Exceeded Size\n");
1524
+ usbi_dbg(ctx, "Data Exceeded Size\n");
1590
1525
  break;
1591
1526
  case USB_LC_STAT_DATA_UNDERRUN:
1592
- usbi_dbg("Less data received\n");
1527
+ usbi_dbg(ctx, "Less data received\n");
1593
1528
  break;
1594
1529
  case USB_LC_STAT_BUFFER_OVERRUN:
1595
- usbi_dbg("Buffer Size Exceeded\n");
1530
+ usbi_dbg(ctx, "Buffer Size Exceeded\n");
1596
1531
  break;
1597
1532
  case USB_LC_STAT_BUFFER_UNDERRUN:
1598
- usbi_dbg("Buffer Underrun\n");
1533
+ usbi_dbg(ctx, "Buffer Underrun\n");
1599
1534
  break;
1600
1535
  case USB_LC_STAT_TIMEOUT:
1601
- usbi_dbg("Command Timed Out\n");
1536
+ usbi_dbg(ctx, "Command Timed Out\n");
1602
1537
  break;
1603
1538
  case USB_LC_STAT_NOT_ACCESSED:
1604
- usbi_dbg("Not Accessed by h/w\n");
1539
+ usbi_dbg(ctx, "Not Accessed by h/w\n");
1605
1540
  break;
1606
1541
  case USB_LC_STAT_UNSPECIFIED_ERR:
1607
- usbi_dbg("Unspecified Error\n");
1542
+ usbi_dbg(ctx, "Unspecified Error\n");
1608
1543
  break;
1609
1544
  case USB_LC_STAT_NO_BANDWIDTH:
1610
- usbi_dbg("No Bandwidth\n");
1545
+ usbi_dbg(ctx, "No Bandwidth\n");
1611
1546
  break;
1612
1547
  case USB_LC_STAT_HW_ERR:
1613
- usbi_dbg("Host Controller h/w Error\n");
1548
+ usbi_dbg(ctx, "Host Controller h/w Error\n");
1614
1549
  break;
1615
1550
  case USB_LC_STAT_SUSPENDED:
1616
- usbi_dbg("Device was Suspended\n");
1551
+ usbi_dbg(ctx, "Device was Suspended\n");
1617
1552
  break;
1618
1553
  case USB_LC_STAT_DISCONNECTED:
1619
- usbi_dbg("Device was Disconnected\n");
1554
+ usbi_dbg(ctx, "Device was Disconnected\n");
1620
1555
  break;
1621
1556
  case USB_LC_STAT_INTR_BUF_FULL:
1622
- usbi_dbg("Interrupt buffer was full\n");
1557
+ usbi_dbg(ctx, "Interrupt buffer was full\n");
1623
1558
  break;
1624
1559
  case USB_LC_STAT_INVALID_REQ:
1625
- usbi_dbg("Request was Invalid\n");
1560
+ usbi_dbg(ctx, "Request was Invalid\n");
1626
1561
  break;
1627
1562
  case USB_LC_STAT_INTERRUPTED:
1628
- usbi_dbg("Request was Interrupted\n");
1563
+ usbi_dbg(ctx, "Request was Interrupted\n");
1629
1564
  break;
1630
1565
  case USB_LC_STAT_NO_RESOURCES:
1631
- usbi_dbg("No resources available for "
1566
+ usbi_dbg(ctx, "No resources available for "
1632
1567
  "request\n");
1633
1568
  break;
1634
1569
  case USB_LC_STAT_INTR_POLLING_FAILED:
1635
- usbi_dbg("Failed to Restart Poll");
1570
+ usbi_dbg(ctx, "Failed to Restart Poll");
1636
1571
  break;
1637
1572
  default:
1638
- usbi_dbg("Error Not Determined %d\n",
1573
+ usbi_dbg(ctx, "Error Not Determined %d\n",
1639
1574
  status);
1640
1575
  break;
1641
1576
  }
1642
1577
  } else {
1643
- usbi_dbg("read stat error: %s",strerror(errno));
1578
+ usbi_dbg(ctx, "read stat error: %s",strerror(errno));
1644
1579
  status = -1;
1645
1580
  }
1646
1581
 
1647
1582
  return (status);
1648
1583
  }
1649
1584
 
1650
- #ifdef USBI_TIMERFD_AVAILABLE
1651
- static clockid_t op_get_timerfd_clockid(void)
1652
- {
1653
- return CLOCK_MONOTONIC;
1654
- }
1655
- #endif
1656
-
1657
1585
  const struct usbi_os_backend usbi_backend = {
1658
1586
  .name = "Solaris",
1659
1587
  .caps = 0,
1660
- .init = sunos_init,
1661
- .exit = sunos_exit,
1662
1588
  .get_device_list = sunos_get_device_list,
1663
- .get_device_descriptor = sunos_get_device_descriptor,
1664
1589
  .get_active_config_descriptor = sunos_get_active_config_descriptor,
1665
1590
  .get_config_descriptor = sunos_get_config_descriptor,
1666
- .hotplug_poll = NULL,
1667
1591
  .open = sunos_open,
1668
1592
  .close = sunos_close,
1669
1593
  .get_configuration = sunos_get_configuration,
1670
1594
  .set_configuration = sunos_set_configuration,
1671
-
1672
1595
  .claim_interface = sunos_claim_interface,
1673
1596
  .release_interface = sunos_release_interface,
1674
1597
  .set_interface_altsetting = sunos_set_interface_altsetting,
1675
1598
  .clear_halt = sunos_clear_halt,
1676
- .reset_device = sunos_reset_device, /* TODO */
1677
- .alloc_streams = NULL,
1678
- .free_streams = NULL,
1679
1599
  .kernel_driver_active = sunos_kernel_driver_active,
1680
1600
  .detach_kernel_driver = sunos_detach_kernel_driver,
1681
1601
  .attach_kernel_driver = sunos_attach_kernel_driver,
1682
1602
  .destroy_device = sunos_destroy_device,
1683
1603
  .submit_transfer = sunos_submit_transfer,
1684
1604
  .cancel_transfer = sunos_cancel_transfer,
1685
- .handle_events = NULL,
1686
- .clear_transfer_priv = sunos_clear_transfer_priv,
1687
1605
  .handle_transfer_completion = sunos_handle_transfer_completion,
1688
- .clock_gettime = sunos_clock_gettime,
1689
- #ifdef USBI_TIMERFD_AVAILABLE
1690
- .get_timerfd_clockid = op_get_timerfd_clockid,
1691
- #endif
1692
1606
  .device_priv_size = sizeof(sunos_dev_priv_t),
1693
1607
  .device_handle_priv_size = sizeof(sunos_dev_handle_priv_t),
1694
1608
  .transfer_priv_size = sizeof(sunos_xfer_priv_t),