usb 1.7.2 → 1.8.0-libusb.2

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 (188) hide show
  1. package/.gitmodules +1 -1
  2. package/Readme.md +2 -2
  3. package/binding.gyp +2 -2
  4. package/libusb/.private/pre-commit.sh +7 -1
  5. package/libusb/.travis.yml +49 -0
  6. package/libusb/AUTHORS +44 -3
  7. package/libusb/Brewfile +4 -0
  8. package/libusb/ChangeLog +74 -2
  9. package/libusb/README.md +32 -0
  10. package/libusb/TODO +1 -1
  11. package/libusb/Xcode/common.xcconfig +12 -0
  12. package/libusb/Xcode/config.h +25 -0
  13. package/libusb/Xcode/libusb.xcodeproj/project.pbxproj +959 -1
  14. package/libusb/android/README +4 -2
  15. package/libusb/android/config.h +75 -0
  16. package/libusb/appveyor.yml +41 -0
  17. package/libusb/appveyor_cygwin.bat +11 -0
  18. package/libusb/appveyor_minGW.bat +19 -0
  19. package/libusb/autogen.sh +1 -1
  20. package/libusb/bootstrap.sh +3 -16
  21. package/libusb/configure.ac +108 -80
  22. package/libusb/doc/doxygen.cfg.in +1785 -739
  23. package/libusb/examples/Makefile.am +1 -1
  24. package/libusb/examples/dpfp.c +3 -1
  25. package/libusb/examples/dpfp_threaded.c +23 -10
  26. package/libusb/examples/ezusb.c +3 -3
  27. package/libusb/examples/ezusb.h +2 -2
  28. package/libusb/examples/fxload.c +31 -9
  29. package/libusb/examples/hotplugtest.c +35 -7
  30. package/libusb/examples/listdevs.c +3 -1
  31. package/libusb/examples/sam3u_benchmark.c +3 -3
  32. package/libusb/examples/testlibusb.c +277 -0
  33. package/libusb/examples/xusb.c +40 -34
  34. package/libusb/libusb/Makefile.am +49 -23
  35. package/libusb/libusb/core.c +855 -457
  36. package/libusb/libusb/descriptor.c +72 -78
  37. package/libusb/libusb/hotplug.c +122 -76
  38. package/libusb/libusb/hotplug.h +42 -25
  39. package/libusb/libusb/io.c +625 -390
  40. package/libusb/libusb/libusb-1.0.def +12 -0
  41. package/libusb/libusb/libusb.h +218 -150
  42. package/libusb/libusb/libusbi.h +346 -176
  43. package/libusb/libusb/os/darwin_usb.c +604 -319
  44. package/libusb/libusb/os/darwin_usb.h +61 -20
  45. package/libusb/libusb/os/haiku_pollfs.cpp +367 -0
  46. package/libusb/libusb/os/haiku_usb.h +113 -0
  47. package/libusb/libusb/os/haiku_usb_backend.cpp +533 -0
  48. package/libusb/libusb/os/haiku_usb_raw.cpp +267 -0
  49. package/libusb/libusb/os/haiku_usb_raw.h +188 -0
  50. package/libusb/libusb/os/linux_netlink.c +186 -146
  51. package/libusb/libusb/os/linux_udev.c +36 -14
  52. package/libusb/libusb/os/linux_usbfs.c +426 -225
  53. package/libusb/libusb/os/linux_usbfs.h +5 -3
  54. package/libusb/libusb/os/netbsd_usb.c +21 -77
  55. package/libusb/libusb/os/openbsd_usb.c +32 -115
  56. package/libusb/libusb/os/poll_posix.c +38 -5
  57. package/libusb/libusb/os/poll_posix.h +3 -0
  58. package/libusb/libusb/os/poll_windows.c +277 -626
  59. package/libusb/libusb/os/poll_windows.h +11 -44
  60. package/libusb/libusb/os/sunos_usb.c +1695 -0
  61. package/libusb/libusb/os/sunos_usb.h +80 -0
  62. package/libusb/libusb/os/threads_posix.c +24 -26
  63. package/libusb/libusb/os/threads_posix.h +73 -21
  64. package/libusb/libusb/os/threads_windows.c +71 -157
  65. package/libusb/libusb/os/threads_windows.h +68 -44
  66. package/libusb/libusb/os/wince_usb.c +276 -420
  67. package/libusb/libusb/os/wince_usb.h +23 -28
  68. package/libusb/libusb/os/windows_common.h +78 -58
  69. package/libusb/libusb/os/windows_nt_common.c +1010 -0
  70. package/libusb/libusb/os/windows_nt_common.h +110 -0
  71. package/libusb/libusb/os/windows_nt_shared_types.h +147 -0
  72. package/libusb/libusb/os/windows_usbdk.c +830 -0
  73. package/libusb/libusb/os/windows_usbdk.h +103 -0
  74. package/libusb/libusb/os/windows_winusb.c +4391 -0
  75. package/libusb/libusb/os/windows_winusb.h +783 -0
  76. package/libusb/libusb/strerror.c +41 -7
  77. package/libusb/libusb/sync.c +41 -13
  78. package/libusb/libusb/version.h +1 -1
  79. package/libusb/libusb/version_nano.h +1 -1
  80. package/libusb/libusb-1.0.pc.in +1 -1
  81. package/libusb/msvc/appveyor.bat +27 -0
  82. package/libusb/msvc/config.h +5 -4
  83. package/libusb/msvc/ddk_build.cmd +87 -43
  84. package/libusb/msvc/fxload_2010.vcxproj +24 -104
  85. package/libusb/msvc/fxload_2012.vcxproj +24 -107
  86. package/libusb/msvc/fxload_2013.vcxproj +24 -107
  87. package/libusb/msvc/fxload_2015.vcxproj +91 -0
  88. package/libusb/msvc/fxload_2017.vcxproj +114 -0
  89. package/libusb/msvc/fxload_sources +1 -1
  90. package/libusb/msvc/getopt_2010.vcxproj +16 -75
  91. package/libusb/msvc/getopt_2012.vcxproj +16 -79
  92. package/libusb/msvc/getopt_2013.vcxproj +16 -79
  93. package/libusb/msvc/getopt_2015.vcxproj +73 -0
  94. package/libusb/msvc/getopt_2017.vcxproj +98 -0
  95. package/libusb/msvc/getopt_sources +6 -2
  96. package/libusb/msvc/hotplugtest_2010.vcxproj +18 -99
  97. package/libusb/msvc/hotplugtest_2012.vcxproj +18 -102
  98. package/libusb/msvc/hotplugtest_2013.vcxproj +18 -102
  99. package/libusb/msvc/hotplugtest_2015.vcxproj +83 -0
  100. package/libusb/msvc/hotplugtest_2017.vcxproj +106 -0
  101. package/libusb/msvc/hotplugtest_sources +1 -1
  102. package/libusb/msvc/libusb_2005.sln +20 -20
  103. package/libusb/msvc/libusb_2010.sln +57 -46
  104. package/libusb/msvc/libusb_2012.sln +57 -46
  105. package/libusb/msvc/libusb_2013.sln +57 -50
  106. package/libusb/msvc/libusb_2015.sln +59 -52
  107. package/libusb/msvc/libusb_2017.sln +186 -0
  108. package/libusb/msvc/libusb_dll.dsp +2 -2
  109. package/libusb/msvc/libusb_dll_2005.vcproj +30 -2
  110. package/libusb/msvc/libusb_dll_2010.vcxproj +26 -90
  111. package/libusb/msvc/libusb_dll_2012.vcxproj +28 -96
  112. package/libusb/msvc/libusb_dll_2013.vcxproj +28 -96
  113. package/libusb/msvc/libusb_dll_2015.vcxproj +107 -0
  114. package/libusb/msvc/libusb_dll_2017.vcxproj +134 -0
  115. package/libusb/msvc/libusb_dll_wince.vcproj +9 -1
  116. package/libusb/msvc/libusb_sources +10 -5
  117. package/libusb/msvc/libusb_static.dsp +2 -2
  118. package/libusb/msvc/libusb_static_2005.vcproj +32 -4
  119. package/libusb/msvc/libusb_static_2010.vcxproj +24 -83
  120. package/libusb/msvc/libusb_static_2012.vcxproj +25 -87
  121. package/libusb/msvc/libusb_static_2013.vcxproj +25 -87
  122. package/libusb/msvc/libusb_static_2015.vcxproj +98 -0
  123. package/libusb/msvc/libusb_static_2017.vcxproj +117 -0
  124. package/libusb/msvc/libusb_static_wince.vcproj +20 -26
  125. package/libusb/msvc/libusb_wince.sln +88 -88
  126. package/libusb/msvc/listdevs_2010.vcxproj +16 -99
  127. package/libusb/msvc/listdevs_2012.vcxproj +16 -102
  128. package/libusb/msvc/listdevs_2013.vcxproj +16 -102
  129. package/libusb/msvc/listdevs_2015.vcxproj +83 -0
  130. package/libusb/msvc/listdevs_2017.vcxproj +106 -0
  131. package/libusb/msvc/listdevs_sources +2 -1
  132. package/libusb/msvc/stress_2010.vcxproj +20 -101
  133. package/libusb/msvc/stress_2012.vcxproj +20 -104
  134. package/libusb/msvc/stress_2013.vcxproj +20 -104
  135. package/libusb/msvc/stress_2015.vcxproj +87 -0
  136. package/libusb/msvc/stress_2017.vcxproj +110 -0
  137. package/libusb/msvc/stress_sources +21 -0
  138. package/libusb/msvc/testlibusb_2010.vcxproj +82 -0
  139. package/libusb/msvc/testlibusb_2012.vcxproj +83 -0
  140. package/libusb/msvc/testlibusb_2013.vcxproj +83 -0
  141. package/libusb/msvc/testlibusb_2015.vcxproj +83 -0
  142. package/libusb/msvc/testlibusb_2017.vcxproj +106 -0
  143. package/libusb/msvc/testlibusb_sources +20 -0
  144. package/libusb/msvc/xusb_2010.vcxproj +17 -98
  145. package/libusb/msvc/xusb_2012.vcxproj +17 -101
  146. package/libusb/msvc/xusb_2013.vcxproj +17 -101
  147. package/libusb/msvc/xusb_2015.vcxproj +83 -0
  148. package/libusb/msvc/xusb_2017.vcxproj +106 -0
  149. package/libusb/msvc/xusb_sources +1 -1
  150. package/libusb/tests/stress.c +2 -2
  151. package/libusb/tests/testlib.c +0 -4
  152. package/libusb/travis-autogen.sh +39 -0
  153. package/libusb.gypi +13 -2
  154. package/package.json +20 -11
  155. package/prebuilds/android-arm/node.napi.armv7.node +0 -0
  156. package/prebuilds/android-arm64/node.napi.armv8.node +0 -0
  157. package/prebuilds/darwin-x64+arm64/node.napi.node +0 -0
  158. package/prebuilds/linux-arm/node.napi.armv6.node +0 -0
  159. package/prebuilds/linux-arm/node.napi.armv7.node +0 -0
  160. package/prebuilds/linux-arm64/node.napi.armv8.node +0 -0
  161. package/prebuilds/linux-ia32/node.napi.node +0 -0
  162. package/prebuilds/linux-x64/node.napi.glibc.node +0 -0
  163. package/prebuilds/linux-x64/node.napi.musl.node +0 -0
  164. package/prebuilds/win32-ia32/node.napi.node +0 -0
  165. package/prebuilds/win32-x64/node.napi.node +0 -0
  166. package/src/device.cc +1 -1
  167. package/usb.js +1 -1
  168. package/.github/workflows/prebuild.yml +0 -49
  169. package/libusb/INSTALL +0 -234
  170. package/libusb/README +0 -28
  171. package/libusb/libusb/os/windows_usb.c +0 -5347
  172. package/libusb/libusb/os/windows_usb.h +0 -971
  173. package/libusb/msvc/fxload_2010.vcxproj.filters +0 -25
  174. package/libusb/msvc/fxload_2012.vcxproj.filters +0 -25
  175. package/libusb/msvc/getopt_2010.vcxproj.filters +0 -26
  176. package/libusb/msvc/getopt_2012.vcxproj.filters +0 -26
  177. package/libusb/msvc/hotplugtest_2010.vcxproj.filters +0 -14
  178. package/libusb/msvc/hotplugtest_2012.vcxproj.filters +0 -14
  179. package/libusb/msvc/libusb_dll_2010.vcxproj.filters +0 -81
  180. package/libusb/msvc/libusb_dll_2012.vcxproj.filters +0 -84
  181. package/libusb/msvc/libusb_static_2010.vcxproj.filters +0 -74
  182. package/libusb/msvc/libusb_static_2012.vcxproj.filters +0 -74
  183. package/libusb/msvc/listdevs_2010.vcxproj.filters +0 -14
  184. package/libusb/msvc/listdevs_2012.vcxproj.filters +0 -14
  185. package/libusb/msvc/stress_2010.vcxproj.filters +0 -25
  186. package/libusb/msvc/stress_2012.vcxproj.filters +0 -25
  187. package/libusb/msvc/xusb_2010.vcxproj.filters +0 -14
  188. package/libusb/msvc/xusb_2012.vcxproj.filters +0 -14
@@ -1,6 +1,7 @@
1
1
  /*
2
2
  * darwin backend for libusb 1.0
3
- * Copyright © 2008-2013 Nathan Hjelm <hjelmn@users.sourceforge.net>
3
+ * Copyright © 2008-2019 Nathan Hjelm <hjelmn@users.sourceforge.net>
4
+ * Copyright © 2019 Google LLC. All rights reserved.
4
5
  *
5
6
  * This library is free software; you can redistribute it and/or
6
7
  * modify it under the terms of the GNU Lesser General Public
@@ -20,6 +21,8 @@
20
21
  #if !defined(LIBUSB_DARWIN_H)
21
22
  #define LIBUSB_DARWIN_H
22
23
 
24
+ #include <stdbool.h>
25
+
23
26
  #include "libusbi.h"
24
27
 
25
28
  #include <IOKit/IOTypes.h>
@@ -28,31 +31,58 @@
28
31
  #include <IOKit/IOCFPlugIn.h>
29
32
 
30
33
  /* IOUSBInterfaceInferface */
31
- #if defined (kIOUSBInterfaceInterfaceID550)
34
+
35
+ /* New in OS 10.12.0. */
36
+ #if defined (kIOUSBInterfaceInterfaceID800) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 101200)
37
+
38
+ #define usb_interface_t IOUSBInterfaceInterface800
39
+ #define InterfaceInterfaceID kIOUSBInterfaceInterfaceID800
40
+ #define InterfaceVersion 800
41
+
42
+ /* New in OS 10.10.0. */
43
+ #elif defined (kIOUSBInterfaceInterfaceID700) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 101000)
44
+
45
+ #define usb_interface_t IOUSBInterfaceInterface700
46
+ #define InterfaceInterfaceID kIOUSBInterfaceInterfaceID700
47
+ #define InterfaceVersion 700
48
+
49
+ /* New in OS 10.9.0. */
50
+ #elif defined (kIOUSBInterfaceInterfaceID650) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1090)
51
+
52
+ #define usb_interface_t IOUSBInterfaceInterface650
53
+ #define InterfaceInterfaceID kIOUSBInterfaceInterfaceID650
54
+ #define InterfaceVersion 650
55
+
56
+ /* New in OS 10.8.2 but can't test deployment target to that granularity, so round up. */
57
+ #elif defined (kIOUSBInterfaceInterfaceID550) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1090)
32
58
 
33
59
  #define usb_interface_t IOUSBInterfaceInterface550
34
60
  #define InterfaceInterfaceID kIOUSBInterfaceInterfaceID550
35
61
  #define InterfaceVersion 550
36
62
 
37
- #elif defined (kIOUSBInterfaceInterfaceID500)
63
+ /* New in OS 10.7.3 but can't test deployment target to that granularity, so round up. */
64
+ #elif defined (kIOUSBInterfaceInterfaceID500) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1080)
38
65
 
39
66
  #define usb_interface_t IOUSBInterfaceInterface500
40
67
  #define InterfaceInterfaceID kIOUSBInterfaceInterfaceID500
41
68
  #define InterfaceVersion 500
42
69
 
43
- #elif defined (kIOUSBInterfaceInterfaceID300)
70
+ /* New in OS 10.5.0. */
71
+ #elif defined (kIOUSBInterfaceInterfaceID300) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1050)
44
72
 
45
73
  #define usb_interface_t IOUSBInterfaceInterface300
46
74
  #define InterfaceInterfaceID kIOUSBInterfaceInterfaceID300
47
75
  #define InterfaceVersion 300
48
76
 
49
- #elif defined (kIOUSBInterfaceInterfaceID245)
77
+ /* New in OS 10.4.5 (or 10.4.6?) but can't test deployment target to that granularity, so round up. */
78
+ #elif defined (kIOUSBInterfaceInterfaceID245) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1050)
50
79
 
51
80
  #define usb_interface_t IOUSBInterfaceInterface245
52
81
  #define InterfaceInterfaceID kIOUSBInterfaceInterfaceID245
53
82
  #define InterfaceVersion 245
54
83
 
55
- #elif defined (kIOUSBInterfaceInterfaceID220)
84
+ /* New in OS 10.4.0. */
85
+ #elif defined (kIOUSBInterfaceInterfaceID220) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1040)
56
86
 
57
87
  #define usb_interface_t IOUSBInterfaceInterface220
58
88
  #define InterfaceInterfaceID kIOUSBInterfaceInterfaceID220
@@ -60,43 +90,57 @@
60
90
 
61
91
  #else
62
92
 
63
- #error "IOUSBFamily is too old. Please upgrade your OS"
93
+ #error "IOUSBFamily is too old. Please upgrade your SDK and/or deployment target"
64
94
 
65
95
  #endif
66
96
 
67
97
  /* IOUSBDeviceInterface */
68
- #if defined (kIOUSBDeviceInterfaceID500)
98
+
99
+ /* New in OS 10.9.0. */
100
+ #if defined (kIOUSBDeviceInterfaceID650) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1090)
101
+
102
+ #define usb_device_t IOUSBDeviceInterface650
103
+ #define DeviceInterfaceID kIOUSBDeviceInterfaceID650
104
+ #define DeviceVersion 650
105
+
106
+ /* New in OS 10.7.3 but can't test deployment target to that granularity, so round up. */
107
+ #elif defined (kIOUSBDeviceInterfaceID500) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1080)
69
108
 
70
109
  #define usb_device_t IOUSBDeviceInterface500
71
110
  #define DeviceInterfaceID kIOUSBDeviceInterfaceID500
72
111
  #define DeviceVersion 500
73
112
 
74
- #elif defined (kIOUSBDeviceInterfaceID320)
113
+ /* New in OS 10.5.4 but can't test deployment target to that granularity, so round up. */
114
+ #elif defined (kIOUSBDeviceInterfaceID320) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1060)
75
115
 
76
116
  #define usb_device_t IOUSBDeviceInterface320
77
117
  #define DeviceInterfaceID kIOUSBDeviceInterfaceID320
78
118
  #define DeviceVersion 320
79
119
 
80
- #elif defined (kIOUSBDeviceInterfaceID300)
120
+ /* New in OS 10.5.0. */
121
+ #elif defined (kIOUSBDeviceInterfaceID300) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1050)
81
122
 
82
123
  #define usb_device_t IOUSBDeviceInterface300
83
124
  #define DeviceInterfaceID kIOUSBDeviceInterfaceID300
84
125
  #define DeviceVersion 300
85
126
 
86
- #elif defined (kIOUSBDeviceInterfaceID245)
127
+ /* New in OS 10.4.5 (or 10.4.6?) but can't test deployment target to that granularity, so round up. */
128
+ #elif defined (kIOUSBDeviceInterfaceID245) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1050)
87
129
 
88
130
  #define usb_device_t IOUSBDeviceInterface245
89
131
  #define DeviceInterfaceID kIOUSBDeviceInterfaceID245
90
132
  #define DeviceVersion 245
91
133
 
92
- #elif defined (kIOUSBDeviceInterfaceID220)
134
+ /* New in OS 10.2.3 but can't test deployment target to that granularity, so round up. */
135
+ #elif defined (kIOUSBDeviceInterfaceID197) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1030)
136
+
93
137
  #define usb_device_t IOUSBDeviceInterface197
94
138
  #define DeviceInterfaceID kIOUSBDeviceInterfaceID197
95
139
  #define DeviceVersion 197
96
140
 
97
141
  #else
98
142
 
99
- #error "IOUSBFamily is too old. Please upgrade your OS"
143
+ #error "IOUSBFamily is too old. Please upgrade your SDK and/or deployment target"
100
144
 
101
145
  #endif
102
146
 
@@ -114,13 +158,14 @@ struct darwin_cached_device {
114
158
  UInt32 location;
115
159
  UInt64 parent_session;
116
160
  UInt64 session;
117
- UInt16 address;
161
+ USBDeviceAddress address;
118
162
  char sys_path[21];
119
163
  usb_device_t **device;
120
164
  int open_count;
121
165
  UInt8 first_config, active_config, port;
122
166
  int can_enumerate;
123
167
  int refcount;
168
+ bool in_reenumerate;
124
169
  };
125
170
 
126
171
  struct darwin_device_priv {
@@ -128,9 +173,8 @@ struct darwin_device_priv {
128
173
  };
129
174
 
130
175
  struct darwin_device_handle_priv {
131
- int is_open;
176
+ bool is_open;
132
177
  CFRunLoopSourceRef cfSource;
133
- int fds[2];
134
178
 
135
179
  struct darwin_interface {
136
180
  usb_interface_t **interface;
@@ -150,11 +194,8 @@ struct darwin_transfer_priv {
150
194
  IOUSBDevRequestTO req;
151
195
 
152
196
  /* Bulk */
153
- };
154
197
 
155
- /* structure for signaling io completion */
156
- struct darwin_msg_async_io_complete {
157
- struct usbi_transfer *itransfer;
198
+ /* Completion status */
158
199
  IOReturn result;
159
200
  UInt32 size;
160
201
  };
@@ -0,0 +1,367 @@
1
+ /*
2
+ * Copyright 2007-2008, Haiku Inc. All rights reserved.
3
+ * Distributed under the terms of the MIT License.
4
+ *
5
+ * Authors:
6
+ * Michael Lotz <mmlr@mlotz.ch>
7
+ */
8
+
9
+ #include "haiku_usb.h"
10
+ #include <cstdio>
11
+ #include <Directory.h>
12
+ #include <Entry.h>
13
+ #include <Looper.h>
14
+ #include <Messenger.h>
15
+ #include <Node.h>
16
+ #include <NodeMonitor.h>
17
+ #include <Path.h>
18
+ #include <cstring>
19
+
20
+ class WatchedEntry {
21
+ public:
22
+ WatchedEntry(BMessenger *, entry_ref *);
23
+ ~WatchedEntry();
24
+ bool EntryCreated(entry_ref *ref);
25
+ bool EntryRemoved(ino_t node);
26
+ bool InitCheck();
27
+
28
+ private:
29
+ BMessenger* fMessenger;
30
+ node_ref fNode;
31
+ bool fIsDirectory;
32
+ USBDevice* fDevice;
33
+ WatchedEntry* fEntries;
34
+ WatchedEntry* fLink;
35
+ bool fInitCheck;
36
+ };
37
+
38
+
39
+ class RosterLooper : public BLooper {
40
+ public:
41
+ RosterLooper(USBRoster *);
42
+ void Stop();
43
+ virtual void MessageReceived(BMessage *);
44
+ bool InitCheck();
45
+
46
+ private:
47
+ USBRoster* fRoster;
48
+ WatchedEntry* fRoot;
49
+ BMessenger* fMessenger;
50
+ bool fInitCheck;
51
+ };
52
+
53
+
54
+ WatchedEntry::WatchedEntry(BMessenger *messenger, entry_ref *ref)
55
+ : fMessenger(messenger),
56
+ fIsDirectory(false),
57
+ fDevice(NULL),
58
+ fEntries(NULL),
59
+ fLink(NULL),
60
+ fInitCheck(false)
61
+ {
62
+ BEntry entry(ref);
63
+ entry.GetNodeRef(&fNode);
64
+
65
+ BDirectory directory;
66
+ if (entry.IsDirectory() && directory.SetTo(ref) >= B_OK) {
67
+ fIsDirectory = true;
68
+
69
+ while (directory.GetNextEntry(&entry) >= B_OK) {
70
+ if (entry.GetRef(ref) < B_OK)
71
+ continue;
72
+
73
+ WatchedEntry *child = new(std::nothrow) WatchedEntry(fMessenger, ref);
74
+ if (child == NULL)
75
+ continue;
76
+ if (child->InitCheck() == false) {
77
+ delete child;
78
+ continue;
79
+ }
80
+
81
+ child->fLink = fEntries;
82
+ fEntries = child;
83
+ }
84
+
85
+ watch_node(&fNode, B_WATCH_DIRECTORY, *fMessenger);
86
+ }
87
+ else {
88
+ if (strncmp(ref->name, "raw", 3) == 0)
89
+ return;
90
+
91
+ BPath path, parent_path;
92
+ entry.GetPath(&path);
93
+ fDevice = new(std::nothrow) USBDevice(path.Path());
94
+ if (fDevice != NULL && fDevice->InitCheck() == true) {
95
+ // Add this new device to each active context's device list
96
+ struct libusb_context *ctx;
97
+ unsigned long session_id = (unsigned long)&fDevice;
98
+
99
+ usbi_mutex_lock(&active_contexts_lock);
100
+ list_for_each_entry(ctx, &active_contexts_list, list, struct libusb_context) {
101
+ struct libusb_device *dev = usbi_get_device_by_session_id(ctx, session_id);
102
+ if (dev) {
103
+ usbi_dbg("using previously allocated device with location %lu", session_id);
104
+ libusb_unref_device(dev);
105
+ continue;
106
+ }
107
+ usbi_dbg("allocating new device with location %lu", session_id);
108
+ dev = usbi_alloc_device(ctx, session_id);
109
+ if (!dev) {
110
+ usbi_dbg("device allocation failed");
111
+ continue;
112
+ }
113
+ *((USBDevice **)dev->os_priv) = fDevice;
114
+
115
+ // Calculate pseudo-device-address
116
+ int addr, tmp;
117
+ if (strcmp(path.Leaf(), "hub") == 0)
118
+ tmp = 100; //Random Number
119
+ else
120
+ sscanf(path.Leaf(), "%d", &tmp);
121
+ addr = tmp + 1;
122
+ path.GetParent(&parent_path);
123
+ while (strcmp(parent_path.Leaf(), "usb") != 0) {
124
+ sscanf(parent_path.Leaf(), "%d", &tmp);
125
+ addr += tmp + 1;
126
+ parent_path.GetParent(&parent_path);
127
+ }
128
+ sscanf(path.Path(), "/dev/bus/usb/%d", &dev->bus_number);
129
+ dev->device_address = addr - (dev->bus_number + 1);
130
+
131
+ if (usbi_sanitize_device(dev) < 0) {
132
+ usbi_dbg("device sanitization failed");
133
+ libusb_unref_device(dev);
134
+ continue;
135
+ }
136
+ usbi_connect_device(dev);
137
+ }
138
+ usbi_mutex_unlock(&active_contexts_lock);
139
+ }
140
+ else if (fDevice) {
141
+ delete fDevice;
142
+ fDevice = NULL;
143
+ return;
144
+ }
145
+ }
146
+ fInitCheck = true;
147
+ }
148
+
149
+
150
+ WatchedEntry::~WatchedEntry()
151
+ {
152
+ if (fIsDirectory) {
153
+ watch_node(&fNode, B_STOP_WATCHING, *fMessenger);
154
+
155
+ WatchedEntry *child = fEntries;
156
+ while (child) {
157
+ WatchedEntry *next = child->fLink;
158
+ delete child;
159
+ child = next;
160
+ }
161
+ }
162
+
163
+ if (fDevice) {
164
+ // Remove this device from each active context's device list
165
+ struct libusb_context *ctx;
166
+ struct libusb_device *dev;
167
+ unsigned long session_id = (unsigned long)&fDevice;
168
+
169
+ usbi_mutex_lock(&active_contexts_lock);
170
+ list_for_each_entry(ctx, &active_contexts_list, list, struct libusb_context) {
171
+ dev = usbi_get_device_by_session_id(ctx, session_id);
172
+ if (dev != NULL) {
173
+ usbi_disconnect_device(dev);
174
+ libusb_unref_device(dev);
175
+ } else {
176
+ usbi_dbg("device with location %lu not found", session_id);
177
+ }
178
+ }
179
+ usbi_mutex_static_unlock(&active_contexts_lock);
180
+ delete fDevice;
181
+ }
182
+ }
183
+
184
+
185
+ bool
186
+ WatchedEntry::EntryCreated(entry_ref *ref)
187
+ {
188
+ if (!fIsDirectory)
189
+ return false;
190
+
191
+ if (ref->directory != fNode.node) {
192
+ WatchedEntry *child = fEntries;
193
+ while (child) {
194
+ if (child->EntryCreated(ref))
195
+ return true;
196
+ child = child->fLink;
197
+ }
198
+ return false;
199
+ }
200
+
201
+ WatchedEntry *child = new(std::nothrow) WatchedEntry(fMessenger, ref);
202
+ if (child == NULL)
203
+ return false;
204
+ child->fLink = fEntries;
205
+ fEntries = child;
206
+ return true;
207
+ }
208
+
209
+
210
+ bool
211
+ WatchedEntry::EntryRemoved(ino_t node)
212
+ {
213
+ if (!fIsDirectory)
214
+ return false;
215
+
216
+ WatchedEntry *child = fEntries;
217
+ WatchedEntry *lastChild = NULL;
218
+ while (child) {
219
+ if (child->fNode.node == node) {
220
+ if (lastChild)
221
+ lastChild->fLink = child->fLink;
222
+ else
223
+ fEntries = child->fLink;
224
+ delete child;
225
+ return true;
226
+ }
227
+
228
+ if (child->EntryRemoved(node))
229
+ return true;
230
+
231
+ lastChild = child;
232
+ child = child->fLink;
233
+ }
234
+ return false;
235
+ }
236
+
237
+
238
+ bool
239
+ WatchedEntry::InitCheck()
240
+ {
241
+ return fInitCheck;
242
+ }
243
+
244
+
245
+ RosterLooper::RosterLooper(USBRoster *roster)
246
+ : BLooper("LibusbRoster Looper"),
247
+ fRoster(roster),
248
+ fRoot(NULL),
249
+ fMessenger(NULL),
250
+ fInitCheck(false)
251
+ {
252
+ BEntry entry("/dev/bus/usb");
253
+ if (!entry.Exists()) {
254
+ usbi_err(NULL, "usb_raw not published");
255
+ return;
256
+ }
257
+
258
+ Run();
259
+ fMessenger = new(std::nothrow) BMessenger(this);
260
+ if (fMessenger == NULL) {
261
+ usbi_err(NULL, "error creating BMessenger object");
262
+ return;
263
+ }
264
+
265
+ if (Lock()) {
266
+ entry_ref ref;
267
+ entry.GetRef(&ref);
268
+ fRoot = new(std::nothrow) WatchedEntry(fMessenger, &ref);
269
+ Unlock();
270
+ if (fRoot == NULL)
271
+ return;
272
+ if (fRoot->InitCheck() == false) {
273
+ delete fRoot;
274
+ fRoot = NULL;
275
+ return;
276
+ }
277
+ }
278
+ fInitCheck = true;
279
+ }
280
+
281
+
282
+ void
283
+ RosterLooper::Stop()
284
+ {
285
+ Lock();
286
+ delete fRoot;
287
+ delete fMessenger;
288
+ Quit();
289
+ }
290
+
291
+
292
+ void
293
+ RosterLooper::MessageReceived(BMessage *message)
294
+ {
295
+ int32 opcode;
296
+ if (message->FindInt32("opcode", &opcode) < B_OK)
297
+ return;
298
+
299
+ switch (opcode) {
300
+ case B_ENTRY_CREATED:
301
+ {
302
+ dev_t device;
303
+ ino_t directory;
304
+ const char *name;
305
+ if (message->FindInt32("device", &device) < B_OK ||
306
+ message->FindInt64("directory", &directory) < B_OK ||
307
+ message->FindString("name", &name) < B_OK)
308
+ break;
309
+
310
+ entry_ref ref(device, directory, name);
311
+ fRoot->EntryCreated(&ref);
312
+ break;
313
+ }
314
+ case B_ENTRY_REMOVED:
315
+ {
316
+ ino_t node;
317
+ if (message->FindInt64("node", &node) < B_OK)
318
+ break;
319
+ fRoot->EntryRemoved(node);
320
+ break;
321
+ }
322
+ }
323
+ }
324
+
325
+
326
+ bool
327
+ RosterLooper::InitCheck()
328
+ {
329
+ return fInitCheck;
330
+ }
331
+
332
+
333
+ USBRoster::USBRoster()
334
+ : fLooper(NULL)
335
+ {
336
+ }
337
+
338
+
339
+ USBRoster::~USBRoster()
340
+ {
341
+ Stop();
342
+ }
343
+
344
+
345
+ int
346
+ USBRoster::Start()
347
+ {
348
+ if (fLooper == NULL) {
349
+ fLooper = new(std::nothrow) RosterLooper(this);
350
+ if (fLooper == NULL || ((RosterLooper *)fLooper)->InitCheck() == false) {
351
+ if (fLooper)
352
+ fLooper = NULL;
353
+ return LIBUSB_ERROR_OTHER;
354
+ }
355
+ }
356
+ return LIBUSB_SUCCESS;
357
+ }
358
+
359
+
360
+ void
361
+ USBRoster::Stop()
362
+ {
363
+ if (fLooper) {
364
+ ((RosterLooper *)fLooper)->Stop();
365
+ fLooper = NULL;
366
+ }
367
+ }
@@ -0,0 +1,113 @@
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
+ #include <List.h>
21
+ #include <Locker.h>
22
+ #include <Autolock.h>
23
+ #include <USBKit.h>
24
+ #include <map>
25
+ #include "libusbi.h"
26
+ #include "haiku_usb_raw.h"
27
+
28
+ using namespace std;
29
+
30
+ class USBDevice;
31
+ class USBDeviceHandle;
32
+ class USBTransfer;
33
+
34
+ class USBDevice {
35
+ public:
36
+ USBDevice(const char *);
37
+ virtual ~USBDevice();
38
+ const char* Location() const;
39
+ uint8 CountConfigurations() const;
40
+ const usb_device_descriptor* Descriptor() const;
41
+ const usb_configuration_descriptor* ConfigurationDescriptor(uint32) const;
42
+ const usb_configuration_descriptor* ActiveConfiguration() const;
43
+ uint8 EndpointToIndex(uint8) const;
44
+ uint8 EndpointToInterface(uint8) const;
45
+ int ClaimInterface(int);
46
+ int ReleaseInterface(int);
47
+ int CheckInterfacesFree(int);
48
+ int SetActiveConfiguration(int);
49
+ int ActiveConfigurationIndex() const;
50
+ bool InitCheck();
51
+ private:
52
+ int Initialise();
53
+ unsigned int fClaimedInterfaces; // Max Interfaces can be 32. Using a bitmask
54
+ usb_device_descriptor fDeviceDescriptor;
55
+ unsigned char** fConfigurationDescriptors;
56
+ int fActiveConfiguration;
57
+ char* fPath;
58
+ map<uint8,uint8> fConfigToIndex;
59
+ map<uint8,uint8>* fEndpointToIndex;
60
+ map<uint8,uint8>* fEndpointToInterface;
61
+ bool fInitCheck;
62
+ };
63
+
64
+ class USBDeviceHandle {
65
+ public:
66
+ USBDeviceHandle(USBDevice *dev);
67
+ virtual ~USBDeviceHandle();
68
+ int ClaimInterface(int);
69
+ int ReleaseInterface(int);
70
+ int SetConfiguration(int);
71
+ int SetAltSetting(int, int);
72
+ int ClearHalt(int);
73
+ status_t SubmitTransfer(struct usbi_transfer *);
74
+ status_t CancelTransfer(USBTransfer *);
75
+ bool InitCheck();
76
+ private:
77
+ int fRawFD;
78
+ static status_t TransfersThread(void *);
79
+ void TransfersWorker();
80
+ USBDevice* fUSBDevice;
81
+ unsigned int fClaimedInterfaces;
82
+ BList fTransfers;
83
+ BLocker fTransfersLock;
84
+ sem_id fTransfersSem;
85
+ thread_id fTransfersThread;
86
+ bool fInitCheck;
87
+ };
88
+
89
+ class USBTransfer {
90
+ public:
91
+ USBTransfer(struct usbi_transfer *, USBDevice *);
92
+ virtual ~USBTransfer();
93
+ void Do(int);
94
+ struct usbi_transfer* UsbiTransfer();
95
+ void SetCancelled();
96
+ bool IsCancelled();
97
+ private:
98
+ struct usbi_transfer* fUsbiTransfer;
99
+ struct libusb_transfer* fLibusbTransfer;
100
+ USBDevice* fUSBDevice;
101
+ BLocker fStatusLock;
102
+ bool fCancelled;
103
+ };
104
+
105
+ class USBRoster {
106
+ public:
107
+ USBRoster();
108
+ virtual ~USBRoster();
109
+ int Start();
110
+ void Stop();
111
+ private:
112
+ void* fLooper;
113
+ };