usb 2.0.0-alpha.2 → 2.1.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 (258) hide show
  1. package/.gitmodules +1 -1
  2. package/CHANGELOG.md +100 -0
  3. package/README.md +573 -0
  4. package/binding.gyp +12 -2
  5. package/dist/index.d.ts +4 -4
  6. package/dist/index.js +14 -8
  7. package/dist/index.js.map +1 -1
  8. package/dist/usb/bindings.d.ts +13 -0
  9. package/dist/usb/bindings.js +2 -1
  10. package/dist/usb/bindings.js.map +1 -1
  11. package/dist/usb/index.js +86 -2
  12. package/dist/usb/index.js.map +1 -1
  13. package/dist/usb/interface.js.map +1 -1
  14. package/dist/webusb/index.d.ts +32 -19
  15. package/dist/webusb/index.js +163 -67
  16. package/dist/webusb/index.js.map +1 -1
  17. package/dist/webusb/webusb-device.d.ts +1 -1
  18. package/dist/webusb/webusb-device.js +27 -15
  19. package/dist/webusb/webusb-device.js.map +1 -1
  20. package/libusb/.private/pre-commit.sh +7 -1
  21. package/libusb/.travis.yml +49 -0
  22. package/libusb/AUTHORS +44 -3
  23. package/libusb/Brewfile +4 -0
  24. package/libusb/ChangeLog +74 -2
  25. package/libusb/README.md +32 -0
  26. package/libusb/TODO +1 -1
  27. package/libusb/Xcode/common.xcconfig +12 -0
  28. package/libusb/Xcode/config.h +25 -0
  29. package/libusb/Xcode/libusb.xcodeproj/project.pbxproj +959 -1
  30. package/libusb/android/README +4 -2
  31. package/libusb/android/config.h +75 -0
  32. package/libusb/appveyor.yml +41 -0
  33. package/libusb/appveyor_cygwin.bat +11 -0
  34. package/libusb/appveyor_minGW.bat +19 -0
  35. package/libusb/autogen.sh +1 -1
  36. package/libusb/bootstrap.sh +3 -16
  37. package/libusb/configure.ac +108 -80
  38. package/libusb/doc/doxygen.cfg.in +1785 -739
  39. package/libusb/examples/Makefile.am +1 -1
  40. package/libusb/examples/dpfp.c +3 -1
  41. package/libusb/examples/dpfp_threaded.c +23 -10
  42. package/libusb/examples/ezusb.c +3 -3
  43. package/libusb/examples/ezusb.h +2 -2
  44. package/libusb/examples/fxload.c +31 -9
  45. package/libusb/examples/hotplugtest.c +35 -7
  46. package/libusb/examples/listdevs.c +3 -1
  47. package/libusb/examples/sam3u_benchmark.c +3 -3
  48. package/libusb/examples/testlibusb.c +277 -0
  49. package/libusb/examples/xusb.c +40 -34
  50. package/libusb/libusb/Makefile.am +49 -23
  51. package/libusb/libusb/core.c +855 -457
  52. package/libusb/libusb/descriptor.c +72 -78
  53. package/libusb/libusb/hotplug.c +122 -76
  54. package/libusb/libusb/hotplug.h +42 -25
  55. package/libusb/libusb/io.c +625 -390
  56. package/libusb/libusb/libusb-1.0.def +12 -0
  57. package/libusb/libusb/libusb.h +218 -150
  58. package/libusb/libusb/libusbi.h +346 -176
  59. package/libusb/libusb/os/darwin_usb.c +604 -319
  60. package/libusb/libusb/os/darwin_usb.h +61 -20
  61. package/libusb/libusb/os/haiku_pollfs.cpp +367 -0
  62. package/libusb/libusb/os/haiku_usb.h +113 -0
  63. package/libusb/libusb/os/haiku_usb_backend.cpp +533 -0
  64. package/libusb/libusb/os/haiku_usb_raw.cpp +267 -0
  65. package/libusb/libusb/os/haiku_usb_raw.h +188 -0
  66. package/libusb/libusb/os/linux_netlink.c +186 -146
  67. package/libusb/libusb/os/linux_udev.c +36 -14
  68. package/libusb/libusb/os/linux_usbfs.c +426 -225
  69. package/libusb/libusb/os/linux_usbfs.h +5 -3
  70. package/libusb/libusb/os/netbsd_usb.c +21 -77
  71. package/libusb/libusb/os/openbsd_usb.c +32 -115
  72. package/libusb/libusb/os/poll_posix.c +38 -5
  73. package/libusb/libusb/os/poll_posix.h +3 -0
  74. package/libusb/libusb/os/poll_windows.c +277 -626
  75. package/libusb/libusb/os/poll_windows.h +11 -44
  76. package/libusb/libusb/os/sunos_usb.c +1695 -0
  77. package/libusb/libusb/os/sunos_usb.h +80 -0
  78. package/libusb/libusb/os/threads_posix.c +24 -26
  79. package/libusb/libusb/os/threads_posix.h +73 -21
  80. package/libusb/libusb/os/threads_windows.c +71 -157
  81. package/libusb/libusb/os/threads_windows.h +68 -44
  82. package/libusb/libusb/os/wince_usb.c +276 -420
  83. package/libusb/libusb/os/wince_usb.h +23 -28
  84. package/libusb/libusb/os/windows_common.h +78 -58
  85. package/libusb/libusb/os/windows_nt_common.c +1010 -0
  86. package/libusb/libusb/os/windows_nt_common.h +110 -0
  87. package/libusb/libusb/os/windows_nt_shared_types.h +147 -0
  88. package/libusb/libusb/os/windows_usbdk.c +830 -0
  89. package/libusb/libusb/os/windows_usbdk.h +103 -0
  90. package/libusb/libusb/os/windows_winusb.c +4391 -0
  91. package/libusb/libusb/os/windows_winusb.h +783 -0
  92. package/libusb/libusb/strerror.c +41 -7
  93. package/libusb/libusb/sync.c +41 -13
  94. package/libusb/libusb/version.h +1 -1
  95. package/libusb/libusb/version_nano.h +1 -1
  96. package/libusb/libusb-1.0.pc.in +1 -1
  97. package/libusb/msvc/appveyor.bat +27 -0
  98. package/libusb/msvc/config.h +5 -4
  99. package/libusb/msvc/ddk_build.cmd +87 -43
  100. package/libusb/msvc/fxload_2010.vcxproj +24 -104
  101. package/libusb/msvc/fxload_2012.vcxproj +24 -107
  102. package/libusb/msvc/fxload_2013.vcxproj +24 -107
  103. package/libusb/msvc/fxload_2015.vcxproj +91 -0
  104. package/libusb/msvc/fxload_2017.vcxproj +114 -0
  105. package/libusb/msvc/fxload_sources +1 -1
  106. package/libusb/msvc/getopt_2010.vcxproj +16 -75
  107. package/libusb/msvc/getopt_2012.vcxproj +16 -79
  108. package/libusb/msvc/getopt_2013.vcxproj +16 -79
  109. package/libusb/msvc/getopt_2015.vcxproj +73 -0
  110. package/libusb/msvc/getopt_2017.vcxproj +98 -0
  111. package/libusb/msvc/getopt_sources +6 -2
  112. package/libusb/msvc/hotplugtest_2010.vcxproj +18 -99
  113. package/libusb/msvc/hotplugtest_2012.vcxproj +18 -102
  114. package/libusb/msvc/hotplugtest_2013.vcxproj +18 -102
  115. package/libusb/msvc/hotplugtest_2015.vcxproj +83 -0
  116. package/libusb/msvc/hotplugtest_2017.vcxproj +106 -0
  117. package/libusb/msvc/hotplugtest_sources +1 -1
  118. package/libusb/msvc/libusb_2005.sln +20 -20
  119. package/libusb/msvc/libusb_2010.sln +57 -46
  120. package/libusb/msvc/libusb_2012.sln +57 -46
  121. package/libusb/msvc/libusb_2013.sln +57 -50
  122. package/libusb/msvc/libusb_2015.sln +59 -52
  123. package/libusb/msvc/libusb_2017.sln +186 -0
  124. package/libusb/msvc/libusb_dll.dsp +2 -2
  125. package/libusb/msvc/libusb_dll_2005.vcproj +30 -2
  126. package/libusb/msvc/libusb_dll_2010.vcxproj +26 -90
  127. package/libusb/msvc/libusb_dll_2012.vcxproj +28 -96
  128. package/libusb/msvc/libusb_dll_2013.vcxproj +28 -96
  129. package/libusb/msvc/libusb_dll_2015.vcxproj +107 -0
  130. package/libusb/msvc/libusb_dll_2017.vcxproj +134 -0
  131. package/libusb/msvc/libusb_dll_wince.vcproj +9 -1
  132. package/libusb/msvc/libusb_sources +10 -5
  133. package/libusb/msvc/libusb_static.dsp +2 -2
  134. package/libusb/msvc/libusb_static_2005.vcproj +32 -4
  135. package/libusb/msvc/libusb_static_2010.vcxproj +24 -83
  136. package/libusb/msvc/libusb_static_2012.vcxproj +25 -87
  137. package/libusb/msvc/libusb_static_2013.vcxproj +25 -87
  138. package/libusb/msvc/libusb_static_2015.vcxproj +98 -0
  139. package/libusb/msvc/libusb_static_2017.vcxproj +117 -0
  140. package/libusb/msvc/libusb_static_wince.vcproj +20 -26
  141. package/libusb/msvc/libusb_wince.sln +88 -88
  142. package/libusb/msvc/listdevs_2010.vcxproj +16 -99
  143. package/libusb/msvc/listdevs_2012.vcxproj +16 -102
  144. package/libusb/msvc/listdevs_2013.vcxproj +16 -102
  145. package/libusb/msvc/listdevs_2015.vcxproj +83 -0
  146. package/libusb/msvc/listdevs_2017.vcxproj +106 -0
  147. package/libusb/msvc/listdevs_sources +2 -1
  148. package/libusb/msvc/stress_2010.vcxproj +20 -101
  149. package/libusb/msvc/stress_2012.vcxproj +20 -104
  150. package/libusb/msvc/stress_2013.vcxproj +20 -104
  151. package/libusb/msvc/stress_2015.vcxproj +87 -0
  152. package/libusb/msvc/stress_2017.vcxproj +110 -0
  153. package/libusb/msvc/stress_sources +21 -0
  154. package/libusb/msvc/testlibusb_2010.vcxproj +82 -0
  155. package/libusb/msvc/testlibusb_2012.vcxproj +83 -0
  156. package/libusb/msvc/testlibusb_2013.vcxproj +83 -0
  157. package/libusb/msvc/testlibusb_2015.vcxproj +83 -0
  158. package/libusb/msvc/testlibusb_2017.vcxproj +106 -0
  159. package/libusb/msvc/testlibusb_sources +20 -0
  160. package/libusb/msvc/xusb_2010.vcxproj +17 -98
  161. package/libusb/msvc/xusb_2012.vcxproj +17 -101
  162. package/libusb/msvc/xusb_2013.vcxproj +17 -101
  163. package/libusb/msvc/xusb_2015.vcxproj +83 -0
  164. package/libusb/msvc/xusb_2017.vcxproj +106 -0
  165. package/libusb/msvc/xusb_sources +1 -1
  166. package/libusb/tests/stress.c +2 -2
  167. package/libusb/tests/testlib.c +0 -4
  168. package/libusb/travis-autogen.sh +39 -0
  169. package/libusb.gypi +21 -2
  170. package/package.json +18 -13
  171. package/prebuilds/android-arm/node.napi.node +0 -0
  172. package/prebuilds/android-arm64/node.napi.node +0 -0
  173. package/prebuilds/darwin-x64+arm64/node.napi.node +0 -0
  174. package/prebuilds/linux-arm/node.napi.node +0 -0
  175. package/prebuilds/linux-arm64/node.napi.node +0 -0
  176. package/prebuilds/linux-ia32/node.napi.node +0 -0
  177. package/prebuilds/linux-x64/node.napi.node +0 -0
  178. package/prebuilds/win32-ia32/node.napi.node +0 -0
  179. package/prebuilds/win32-x64/node.napi.node +0 -0
  180. package/src/device.cc +7 -7
  181. package/src/node_usb.cc +43 -1
  182. package/src/node_usb.h +1 -0
  183. package/src/uv_async_queue.h +33 -25
  184. package/test/usb.coffee +6 -0
  185. package/tsc/index.ts +13 -7
  186. package/tsc/usb/bindings.ts +19 -1
  187. package/tsc/usb/index.ts +67 -19
  188. package/tsc/usb/interface.ts +2 -2
  189. package/tsc/webusb/index.ts +197 -74
  190. package/tsc/webusb/webusb-device.ts +30 -17
  191. package/.github/workflows/prebuild.yml +0 -48
  192. package/Readme.md +0 -339
  193. package/dist/webusb/typed-event-target.d.ts +0 -11
  194. package/dist/webusb/typed-event-target.js +0 -21
  195. package/dist/webusb/typed-event-target.js.map +0 -1
  196. package/docs/assets/css/main.css +0 -2660
  197. package/docs/assets/images/icons.png +0 -0
  198. package/docs/assets/images/icons@2x.png +0 -0
  199. package/docs/assets/images/widgets.png +0 -0
  200. package/docs/assets/images/widgets@2x.png +0 -0
  201. package/docs/assets/js/main.js +0 -248
  202. package/docs/assets/js/search.js +0 -1
  203. package/docs/classes/usb_bindings.device.html +0 -1338
  204. package/docs/classes/usb_bindings.libusbexception.html +0 -234
  205. package/docs/classes/usb_bindings.transfer.html +0 -344
  206. package/docs/classes/usb_capability.capability.html +0 -297
  207. package/docs/classes/usb_device.extendeddevice.html +0 -766
  208. package/docs/classes/usb_endpoint.endpoint.html +0 -472
  209. package/docs/classes/usb_endpoint.inendpoint.html +0 -766
  210. package/docs/classes/usb_endpoint.outendpoint.html +0 -582
  211. package/docs/classes/usb_interface.interface.html +0 -648
  212. package/docs/classes/webusb.webusb-1.html +0 -615
  213. package/docs/classes/webusb_mutex.mutex.html +0 -270
  214. package/docs/classes/webusb_typed_event_target.typedeventtarget.html +0 -443
  215. package/docs/classes/webusb_webusb_device.webusbdevice.html +0 -904
  216. package/docs/index.html +0 -500
  217. package/docs/interfaces/usb.deviceevents.html +0 -242
  218. package/docs/interfaces/usb_descriptors.bosdescriptor.html +0 -293
  219. package/docs/interfaces/usb_descriptors.capabilitydescriptor.html +0 -274
  220. package/docs/interfaces/usb_descriptors.configdescriptor.html +0 -388
  221. package/docs/interfaces/usb_descriptors.devicedescriptor.html +0 -464
  222. package/docs/interfaces/usb_descriptors.endpointdescriptor.html +0 -370
  223. package/docs/interfaces/usb_descriptors.interfacedescriptor.html +0 -407
  224. package/docs/interfaces/webusb.usboptions.html +0 -226
  225. package/docs/modules/index.html +0 -304
  226. package/docs/modules/usb.html +0 -173
  227. package/docs/modules/usb_bindings.html +0 -2248
  228. package/docs/modules/usb_capability.html +0 -156
  229. package/docs/modules/usb_descriptors.html +0 -176
  230. package/docs/modules/usb_device.html +0 -156
  231. package/docs/modules/usb_endpoint.html +0 -164
  232. package/docs/modules/usb_interface.html +0 -156
  233. package/docs/modules/webusb.html +0 -165
  234. package/docs/modules/webusb_mutex.html +0 -156
  235. package/docs/modules/webusb_typed_event_target.html +0 -156
  236. package/docs/modules/webusb_webusb_device.html +0 -156
  237. package/docs/modules.html +0 -156
  238. package/libusb/INSTALL +0 -234
  239. package/libusb/README +0 -28
  240. package/libusb/libusb/os/windows_usb.c +0 -5347
  241. package/libusb/libusb/os/windows_usb.h +0 -971
  242. package/libusb/msvc/fxload_2010.vcxproj.filters +0 -25
  243. package/libusb/msvc/fxload_2012.vcxproj.filters +0 -25
  244. package/libusb/msvc/getopt_2010.vcxproj.filters +0 -26
  245. package/libusb/msvc/getopt_2012.vcxproj.filters +0 -26
  246. package/libusb/msvc/hotplugtest_2010.vcxproj.filters +0 -14
  247. package/libusb/msvc/hotplugtest_2012.vcxproj.filters +0 -14
  248. package/libusb/msvc/libusb_dll_2010.vcxproj.filters +0 -81
  249. package/libusb/msvc/libusb_dll_2012.vcxproj.filters +0 -84
  250. package/libusb/msvc/libusb_static_2010.vcxproj.filters +0 -74
  251. package/libusb/msvc/libusb_static_2012.vcxproj.filters +0 -74
  252. package/libusb/msvc/listdevs_2010.vcxproj.filters +0 -14
  253. package/libusb/msvc/listdevs_2012.vcxproj.filters +0 -14
  254. package/libusb/msvc/stress_2010.vcxproj.filters +0 -25
  255. package/libusb/msvc/stress_2012.vcxproj.filters +0 -25
  256. package/libusb/msvc/xusb_2010.vcxproj.filters +0 -14
  257. package/libusb/msvc/xusb_2012.vcxproj.filters +0 -14
  258. package/tsc/webusb/typed-event-target.ts +0 -23
@@ -0,0 +1,267 @@
1
+ /*
2
+ * Haiku Backend for libusb
3
+ * Copyright © 2014 Akshay Jaggi <akshay1994.leo@gmail.com>
4
+ *
5
+ * This library is free software; you can redistribute it and/or
6
+ * modify it under the terms of the GNU Lesser General Public
7
+ * License as published by the Free Software Foundation; either
8
+ * version 2.1 of the License, or (at your option) any later version.
9
+ *
10
+ * This library is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ * Lesser General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Lesser General Public
16
+ * License along with this library; if not, write to the Free Software
17
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+ */
19
+
20
+
21
+ #include <unistd.h>
22
+ #include <string.h>
23
+ #include <stdlib.h>
24
+ #include <new>
25
+ #include <vector>
26
+
27
+ #include "haiku_usb.h"
28
+
29
+ USBRoster gUsbRoster;
30
+ int32 gInitCount = 0;
31
+
32
+ static int haiku_get_config_descriptor(struct libusb_device *, uint8_t,
33
+ unsigned char *, size_t, int *);
34
+
35
+ static int
36
+ haiku_init(struct libusb_context *ctx)
37
+ {
38
+ if (atomic_add(&gInitCount, 1) == 0)
39
+ return gUsbRoster.Start();
40
+ return LIBUSB_SUCCESS;
41
+ }
42
+
43
+ static void
44
+ haiku_exit(struct libusb_context *ctx)
45
+ {
46
+ UNUSED(ctx);
47
+ if (atomic_add(&gInitCount, -1) == 1)
48
+ gUsbRoster.Stop();
49
+ }
50
+
51
+ static int
52
+ haiku_open(struct libusb_device_handle *dev_handle)
53
+ {
54
+ USBDevice *dev = *((USBDevice **)dev_handle->dev->os_priv);
55
+ USBDeviceHandle *handle = new(std::nothrow) USBDeviceHandle(dev);
56
+ if (handle == NULL)
57
+ return LIBUSB_ERROR_NO_MEM;
58
+ if (handle->InitCheck() == false) {
59
+ delete handle;
60
+ return LIBUSB_ERROR_NO_DEVICE;
61
+ }
62
+ *((USBDeviceHandle **)dev_handle->os_priv) = handle;
63
+ return LIBUSB_SUCCESS;
64
+ }
65
+
66
+ static void
67
+ haiku_close(struct libusb_device_handle *dev_handle)
68
+ {
69
+ USBDeviceHandle *handle = *((USBDeviceHandle **)dev_handle->os_priv);
70
+ if (handle == NULL)
71
+ return;
72
+ delete handle;
73
+ *((USBDeviceHandle **)dev_handle->os_priv) = NULL;
74
+ }
75
+
76
+ static int
77
+ haiku_get_device_descriptor(struct libusb_device *device, unsigned char *buffer, int *host_endian)
78
+ {
79
+ USBDevice *dev = *((USBDevice **)device->os_priv);
80
+ memcpy(buffer, dev->Descriptor(), DEVICE_DESC_LENGTH);
81
+ *host_endian = 0;
82
+ return LIBUSB_SUCCESS;
83
+ }
84
+
85
+ static int
86
+ haiku_get_active_config_descriptor(struct libusb_device *device, unsigned char *buffer, size_t len, int *host_endian)
87
+ {
88
+ USBDevice *dev = *((USBDevice **)device->os_priv);
89
+ return haiku_get_config_descriptor(device, dev->ActiveConfigurationIndex(), buffer, len, host_endian);
90
+ }
91
+
92
+ static int
93
+ haiku_get_config_descriptor(struct libusb_device *device, uint8_t config_index, unsigned char *buffer, size_t len, int *host_endian)
94
+ {
95
+ USBDevice *dev = *((USBDevice **)device->os_priv);
96
+ const usb_configuration_descriptor *config = dev->ConfigurationDescriptor(config_index);
97
+ if (config == NULL) {
98
+ usbi_err(DEVICE_CTX(device), "failed getting configuration descriptor");
99
+ return LIBUSB_ERROR_INVALID_PARAM;
100
+ }
101
+ if (len > config->total_length) {
102
+ len = config->total_length;
103
+ }
104
+ memcpy(buffer, config, len);
105
+ *host_endian = 0;
106
+ return len;
107
+ }
108
+
109
+ static int
110
+ haiku_set_configuration(struct libusb_device_handle *dev_handle, int config)
111
+ {
112
+ USBDeviceHandle *handle= *((USBDeviceHandle **)dev_handle->os_priv);
113
+ return handle->SetConfiguration(config);
114
+ }
115
+
116
+ static int
117
+ haiku_claim_interface(struct libusb_device_handle *dev_handle, int interface_number)
118
+ {
119
+ USBDeviceHandle *handle = *((USBDeviceHandle **)dev_handle->os_priv);
120
+ return handle->ClaimInterface(interface_number);
121
+ }
122
+
123
+ static int
124
+ haiku_set_altsetting(struct libusb_device_handle *dev_handle, int interface_number, int altsetting)
125
+ {
126
+ USBDeviceHandle *handle = *((USBDeviceHandle **)dev_handle->os_priv);
127
+ return handle->SetAltSetting(interface_number, altsetting);
128
+ }
129
+
130
+ static int
131
+ haiku_clear_halt(struct libusb_device_handle *dev_handle, unsigned char endpoint)
132
+ {
133
+ USBDeviceHandle *handle = *((USBDeviceHandle **)dev_handle->os_priv);
134
+ return handle->ClearHalt(endpoint);
135
+ }
136
+
137
+ static int
138
+ haiku_reset_device(struct libusb_device_handle *dev_handle)
139
+ {
140
+ /* TODO */
141
+ return LIBUSB_ERROR_NOT_SUPPORTED;
142
+ }
143
+
144
+ static int
145
+ haiku_release_interface(struct libusb_device_handle *dev_handle, int interface_number)
146
+ {
147
+ USBDeviceHandle *handle = *((USBDeviceHandle **)dev_handle->os_priv);
148
+ haiku_set_altsetting(dev_handle,interface_number, 0);
149
+ return handle->ReleaseInterface(interface_number);
150
+ }
151
+
152
+ static int
153
+ haiku_submit_transfer(struct usbi_transfer *itransfer)
154
+ {
155
+ struct libusb_transfer *fLibusbTransfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
156
+ USBDeviceHandle *fDeviceHandle = *((USBDeviceHandle **)fLibusbTransfer->dev_handle->os_priv);
157
+ return fDeviceHandle->SubmitTransfer(itransfer);
158
+ }
159
+
160
+ static int
161
+ haiku_cancel_transfer(struct usbi_transfer *itransfer)
162
+ {
163
+ struct libusb_transfer *fLibusbTransfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
164
+ USBDeviceHandle *fDeviceHandle = *((USBDeviceHandle **)fLibusbTransfer->dev_handle->os_priv);
165
+ return fDeviceHandle->CancelTransfer(*((USBTransfer **)usbi_transfer_get_os_priv(itransfer)));
166
+ }
167
+
168
+ static void
169
+ haiku_clear_transfer_priv(struct usbi_transfer *itransfer)
170
+ {
171
+ USBTransfer *transfer = *((USBTransfer **)usbi_transfer_get_os_priv(itransfer));
172
+ delete transfer;
173
+ *((USBTransfer **)usbi_transfer_get_os_priv(itransfer)) = NULL;
174
+ }
175
+
176
+ static int
177
+ haiku_handle_transfer_completion(struct usbi_transfer *itransfer)
178
+ {
179
+ USBTransfer *transfer = *((USBTransfer **)usbi_transfer_get_os_priv(itransfer));
180
+
181
+ usbi_mutex_lock(&itransfer->lock);
182
+ if (transfer->IsCancelled()) {
183
+ delete transfer;
184
+ *((USBTransfer **)usbi_transfer_get_os_priv(itransfer)) = NULL;
185
+ usbi_mutex_unlock(&itransfer->lock);
186
+ if (itransfer->transferred < 0)
187
+ itransfer->transferred = 0;
188
+ return usbi_handle_transfer_cancellation(itransfer);
189
+ }
190
+ libusb_transfer_status status = LIBUSB_TRANSFER_COMPLETED;
191
+ if (itransfer->transferred < 0) {
192
+ usbi_err(ITRANSFER_CTX(itransfer), "error in transfer");
193
+ status = LIBUSB_TRANSFER_ERROR;
194
+ itransfer->transferred = 0;
195
+ }
196
+ delete transfer;
197
+ *((USBTransfer **)usbi_transfer_get_os_priv(itransfer)) = NULL;
198
+ usbi_mutex_unlock(&itransfer->lock);
199
+ return usbi_handle_transfer_completion(itransfer, status);
200
+ }
201
+
202
+ static int
203
+ haiku_clock_gettime(int clkid, struct timespec *tp)
204
+ {
205
+ if (clkid == USBI_CLOCK_REALTIME)
206
+ return clock_gettime(CLOCK_REALTIME, tp);
207
+ if (clkid == USBI_CLOCK_MONOTONIC)
208
+ return clock_gettime(CLOCK_MONOTONIC, tp);
209
+ return LIBUSB_ERROR_INVALID_PARAM;
210
+ }
211
+
212
+ const struct usbi_os_backend usbi_backend = {
213
+ .name = "Haiku usbfs",
214
+ .caps = 0,
215
+ .init = haiku_init,
216
+ .exit = haiku_exit,
217
+ .set_option = NULL,
218
+ .get_device_list = NULL,
219
+ .hotplug_poll = NULL,
220
+ .wrap_sys_device = NULL,
221
+ .open = haiku_open,
222
+ .close = haiku_close,
223
+ .get_device_descriptor = haiku_get_device_descriptor,
224
+ .get_active_config_descriptor = haiku_get_active_config_descriptor,
225
+ .get_config_descriptor = haiku_get_config_descriptor,
226
+ .get_config_descriptor_by_value = NULL,
227
+
228
+
229
+ .get_configuration = NULL,
230
+ .set_configuration = haiku_set_configuration,
231
+ .claim_interface = haiku_claim_interface,
232
+ .release_interface = haiku_release_interface,
233
+
234
+ .set_interface_altsetting = haiku_set_altsetting,
235
+ .clear_halt = haiku_clear_halt,
236
+ .reset_device = haiku_reset_device,
237
+
238
+ .alloc_streams = NULL,
239
+ .free_streams = NULL,
240
+
241
+ .dev_mem_alloc = NULL,
242
+ .dev_mem_free = NULL,
243
+
244
+ .kernel_driver_active = NULL,
245
+ .detach_kernel_driver = NULL,
246
+ .attach_kernel_driver = NULL,
247
+
248
+ .destroy_device = NULL,
249
+
250
+ .submit_transfer = haiku_submit_transfer,
251
+ .cancel_transfer = haiku_cancel_transfer,
252
+ .clear_transfer_priv = haiku_clear_transfer_priv,
253
+
254
+ .handle_events = NULL,
255
+ .handle_transfer_completion = haiku_handle_transfer_completion,
256
+
257
+ .clock_gettime = haiku_clock_gettime,
258
+
259
+ #ifdef USBI_TIMERFD_AVAILABLE
260
+ .get_timerfd_clockid = NULL,
261
+ #endif
262
+
263
+ .context_priv_size = 0,
264
+ .device_priv_size = sizeof(USBDevice *),
265
+ .device_handle_priv_size = sizeof(USBDeviceHandle *),
266
+ .transfer_priv_size = sizeof(USBTransfer *),
267
+ };
@@ -0,0 +1,188 @@
1
+ /*
2
+ * Copyright 2006-2008, Haiku Inc. All rights reserved.
3
+ * Distributed under the terms of the MIT License.
4
+ */
5
+
6
+ #ifndef _USB_RAW_H_
7
+ #define _USB_RAW_H_
8
+
9
+ #include <USB3.h>
10
+
11
+ #define B_USB_RAW_PROTOCOL_VERSION 0x0015
12
+ #define B_USB_RAW_ACTIVE_ALTERNATE 0xffffffff
13
+
14
+ typedef enum {
15
+ B_USB_RAW_COMMAND_GET_VERSION = 0x1000,
16
+
17
+ B_USB_RAW_COMMAND_GET_DEVICE_DESCRIPTOR = 0x2000,
18
+ B_USB_RAW_COMMAND_GET_CONFIGURATION_DESCRIPTOR,
19
+ B_USB_RAW_COMMAND_GET_INTERFACE_DESCRIPTOR,
20
+ B_USB_RAW_COMMAND_GET_ENDPOINT_DESCRIPTOR,
21
+ B_USB_RAW_COMMAND_GET_STRING_DESCRIPTOR,
22
+ B_USB_RAW_COMMAND_GET_GENERIC_DESCRIPTOR,
23
+ B_USB_RAW_COMMAND_GET_ALT_INTERFACE_COUNT,
24
+ B_USB_RAW_COMMAND_GET_ACTIVE_ALT_INTERFACE_INDEX,
25
+ B_USB_RAW_COMMAND_GET_INTERFACE_DESCRIPTOR_ETC,
26
+ B_USB_RAW_COMMAND_GET_ENDPOINT_DESCRIPTOR_ETC,
27
+ B_USB_RAW_COMMAND_GET_GENERIC_DESCRIPTOR_ETC,
28
+ B_USB_RAW_COMMAND_GET_CONFIGURATION_DESCRIPTOR_ETC,
29
+
30
+ B_USB_RAW_COMMAND_SET_CONFIGURATION = 0x3000,
31
+ B_USB_RAW_COMMAND_SET_FEATURE,
32
+ B_USB_RAW_COMMAND_CLEAR_FEATURE,
33
+ B_USB_RAW_COMMAND_GET_STATUS,
34
+ B_USB_RAW_COMMAND_GET_DESCRIPTOR,
35
+ B_USB_RAW_COMMAND_SET_ALT_INTERFACE,
36
+
37
+ B_USB_RAW_COMMAND_CONTROL_TRANSFER = 0x4000,
38
+ B_USB_RAW_COMMAND_INTERRUPT_TRANSFER,
39
+ B_USB_RAW_COMMAND_BULK_TRANSFER,
40
+ B_USB_RAW_COMMAND_ISOCHRONOUS_TRANSFER
41
+ } usb_raw_command_id;
42
+
43
+
44
+ typedef enum {
45
+ B_USB_RAW_STATUS_SUCCESS = 0,
46
+
47
+ B_USB_RAW_STATUS_FAILED,
48
+ B_USB_RAW_STATUS_ABORTED,
49
+ B_USB_RAW_STATUS_STALLED,
50
+ B_USB_RAW_STATUS_CRC_ERROR,
51
+ B_USB_RAW_STATUS_TIMEOUT,
52
+
53
+ B_USB_RAW_STATUS_INVALID_CONFIGURATION,
54
+ B_USB_RAW_STATUS_INVALID_INTERFACE,
55
+ B_USB_RAW_STATUS_INVALID_ENDPOINT,
56
+ B_USB_RAW_STATUS_INVALID_STRING,
57
+
58
+ B_USB_RAW_STATUS_NO_MEMORY
59
+ } usb_raw_command_status;
60
+
61
+
62
+ typedef union {
63
+ struct {
64
+ status_t status;
65
+ } version;
66
+
67
+ struct {
68
+ status_t status;
69
+ usb_device_descriptor *descriptor;
70
+ } device;
71
+
72
+ struct {
73
+ status_t status;
74
+ usb_configuration_descriptor *descriptor;
75
+ uint32 config_index;
76
+ } config;
77
+
78
+ struct {
79
+ status_t status;
80
+ usb_configuration_descriptor *descriptor;
81
+ uint32 config_index;
82
+ size_t length;
83
+ } config_etc;
84
+
85
+ struct {
86
+ status_t status;
87
+ uint32 alternate_info;
88
+ uint32 config_index;
89
+ uint32 interface_index;
90
+ } alternate;
91
+
92
+ struct {
93
+ status_t status;
94
+ usb_interface_descriptor *descriptor;
95
+ uint32 config_index;
96
+ uint32 interface_index;
97
+ } interface;
98
+
99
+ struct {
100
+ status_t status;
101
+ usb_interface_descriptor *descriptor;
102
+ uint32 config_index;
103
+ uint32 interface_index;
104
+ uint32 alternate_index;
105
+ } interface_etc;
106
+
107
+ struct {
108
+ status_t status;
109
+ usb_endpoint_descriptor *descriptor;
110
+ uint32 config_index;
111
+ uint32 interface_index;
112
+ uint32 endpoint_index;
113
+ } endpoint;
114
+
115
+ struct {
116
+ status_t status;
117
+ usb_endpoint_descriptor *descriptor;
118
+ uint32 config_index;
119
+ uint32 interface_index;
120
+ uint32 alternate_index;
121
+ uint32 endpoint_index;
122
+ } endpoint_etc;
123
+
124
+ struct {
125
+ status_t status;
126
+ usb_descriptor *descriptor;
127
+ uint32 config_index;
128
+ uint32 interface_index;
129
+ uint32 generic_index;
130
+ size_t length;
131
+ } generic;
132
+
133
+ struct {
134
+ status_t status;
135
+ usb_descriptor *descriptor;
136
+ uint32 config_index;
137
+ uint32 interface_index;
138
+ uint32 alternate_index;
139
+ uint32 generic_index;
140
+ size_t length;
141
+ } generic_etc;
142
+
143
+ struct {
144
+ status_t status;
145
+ usb_string_descriptor *descriptor;
146
+ uint32 string_index;
147
+ size_t length;
148
+ } string;
149
+
150
+ struct {
151
+ status_t status;
152
+ uint8 type;
153
+ uint8 index;
154
+ uint16 language_id;
155
+ void *data;
156
+ size_t length;
157
+ } descriptor;
158
+
159
+ struct {
160
+ status_t status;
161
+ uint8 request_type;
162
+ uint8 request;
163
+ uint16 value;
164
+ uint16 index;
165
+ uint16 length;
166
+ void *data;
167
+ } control;
168
+
169
+ struct {
170
+ status_t status;
171
+ uint32 interface;
172
+ uint32 endpoint;
173
+ void *data;
174
+ size_t length;
175
+ } transfer;
176
+
177
+ struct {
178
+ status_t status;
179
+ uint32 interface;
180
+ uint32 endpoint;
181
+ void *data;
182
+ size_t length;
183
+ usb_iso_packet_descriptor *packet_descriptors;
184
+ uint32 packet_count;
185
+ } isochronous;
186
+ } usb_raw_command;
187
+
188
+ #endif // _USB_RAW_H_