usb 2.17.0 → 3.0.0-alpha.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 (207) hide show
  1. package/LICENSE +18 -4
  2. package/README.md +25 -516
  3. package/dist/index.d.ts +67 -13
  4. package/dist/index.js +333 -64
  5. package/index.d.ts +89 -0
  6. package/index.js +583 -0
  7. package/package.json +53 -33
  8. package/CHANGELOG.md +0 -294
  9. package/binding.gyp +0 -128
  10. package/dist/index.js.map +0 -1
  11. package/dist/usb/bindings.d.ts +0 -266
  12. package/dist/usb/bindings.js +0 -10
  13. package/dist/usb/bindings.js.map +0 -1
  14. package/dist/usb/capability.d.ts +0 -13
  15. package/dist/usb/capability.js +0 -17
  16. package/dist/usb/capability.js.map +0 -1
  17. package/dist/usb/descriptors.d.ts +0 -128
  18. package/dist/usb/descriptors.js +0 -3
  19. package/dist/usb/descriptors.js.map +0 -1
  20. package/dist/usb/device.d.ts +0 -100
  21. package/dist/usb/device.js +0 -297
  22. package/dist/usb/device.js.map +0 -1
  23. package/dist/usb/endpoint.d.ts +0 -94
  24. package/dist/usb/endpoint.js +0 -219
  25. package/dist/usb/endpoint.js.map +0 -1
  26. package/dist/usb/index.d.ts +0 -31
  27. package/dist/usb/index.js +0 -116
  28. package/dist/usb/index.js.map +0 -1
  29. package/dist/usb/interface.d.ts +0 -80
  30. package/dist/usb/interface.js +0 -133
  31. package/dist/usb/interface.js.map +0 -1
  32. package/dist/webusb/index.d.ts +0 -64
  33. package/dist/webusb/index.js +0 -295
  34. package/dist/webusb/index.js.map +0 -1
  35. package/dist/webusb/webusb-device.d.ts +0 -54
  36. package/dist/webusb/webusb-device.js +0 -434
  37. package/dist/webusb/webusb-device.js.map +0 -1
  38. package/libusb/.clang-tidy +0 -34
  39. package/libusb/.codespellrc +0 -3
  40. package/libusb/.private/README.txt +0 -5
  41. package/libusb/.private/appveyor_build.sh +0 -26
  42. package/libusb/.private/bm.sh +0 -54
  43. package/libusb/.private/ci-build.sh +0 -92
  44. package/libusb/.private/ci-container-build.sh +0 -67
  45. package/libusb/.private/post-rewrite.sh +0 -32
  46. package/libusb/.private/pre-commit.sh +0 -52
  47. package/libusb/.private/wbs.txt +0 -43
  48. package/libusb/.travis.yml +0 -58
  49. package/libusb/AUTHORS +0 -231
  50. package/libusb/COPYING +0 -504
  51. package/libusb/ChangeLog +0 -365
  52. package/libusb/HACKING +0 -25
  53. package/libusb/INSTALL_WIN.txt +0 -52
  54. package/libusb/KEYS +0 -123
  55. package/libusb/Makefile.am +0 -50
  56. package/libusb/NEWS +0 -2
  57. package/libusb/PORTING +0 -94
  58. package/libusb/README +0 -29
  59. package/libusb/README.git +0 -41
  60. package/libusb/TODO +0 -2
  61. package/libusb/Xcode/common.xcconfig +0 -92
  62. package/libusb/Xcode/config.h +0 -31
  63. package/libusb/Xcode/debug.xcconfig +0 -32
  64. package/libusb/Xcode/libusb.xcconfig +0 -21
  65. package/libusb/Xcode/libusb.xcodeproj/project.pbxproj +0 -1391
  66. package/libusb/Xcode/libusb_debug.xcconfig +0 -21
  67. package/libusb/Xcode/libusb_release.xcconfig +0 -21
  68. package/libusb/Xcode/release.xcconfig +0 -30
  69. package/libusb/android/README +0 -152
  70. package/libusb/android/config.h +0 -55
  71. package/libusb/android/examples/unrooted_android.c +0 -301
  72. package/libusb/android/examples/unrooted_android.h +0 -36
  73. package/libusb/android/jni/Android.mk +0 -23
  74. package/libusb/android/jni/Application.mk +0 -40
  75. package/libusb/android/jni/examples.mk +0 -168
  76. package/libusb/android/jni/libusb.mk +0 -60
  77. package/libusb/android/jni/tests.mk +0 -45
  78. package/libusb/appveyor.yml +0 -108
  79. package/libusb/autogen.sh +0 -10
  80. package/libusb/bootstrap.sh +0 -10
  81. package/libusb/configure.ac +0 -450
  82. package/libusb/doc/Makefile.in +0 -22
  83. package/libusb/doc/doxygen.cfg.in +0 -2571
  84. package/libusb/doc/libusb.png +0 -0
  85. package/libusb/examples/Makefile.am +0 -12
  86. package/libusb/examples/dpfp.c +0 -711
  87. package/libusb/examples/ezusb.c +0 -846
  88. package/libusb/examples/ezusb.h +0 -109
  89. package/libusb/examples/fxload.c +0 -310
  90. package/libusb/examples/hotplugtest.c +0 -147
  91. package/libusb/examples/listdevs.c +0 -73
  92. package/libusb/examples/sam3u_benchmark.c +0 -228
  93. package/libusb/examples/testlibusb.c +0 -312
  94. package/libusb/examples/xusb.c +0 -1254
  95. package/libusb/libusb/Makefile.am +0 -98
  96. package/libusb/libusb/Makefile.am.extra +0 -26
  97. package/libusb/libusb/core.c +0 -2925
  98. package/libusb/libusb/descriptor.c +0 -1558
  99. package/libusb/libusb/hotplug.c +0 -489
  100. package/libusb/libusb/io.c +0 -2865
  101. package/libusb/libusb/libusb-1.0.def +0 -199
  102. package/libusb/libusb/libusb-1.0.rc +0 -53
  103. package/libusb/libusb/libusb.h +0 -2421
  104. package/libusb/libusb/libusbi.h +0 -1535
  105. package/libusb/libusb/os/darwin_usb.c +0 -2977
  106. package/libusb/libusb/os/darwin_usb.h +0 -156
  107. package/libusb/libusb/os/emscripten_webusb.cpp +0 -875
  108. package/libusb/libusb/os/events_posix.c +0 -340
  109. package/libusb/libusb/os/events_posix.h +0 -62
  110. package/libusb/libusb/os/events_windows.c +0 -214
  111. package/libusb/libusb/os/events_windows.h +0 -46
  112. package/libusb/libusb/os/haiku_pollfs.cpp +0 -372
  113. package/libusb/libusb/os/haiku_usb.h +0 -113
  114. package/libusb/libusb/os/haiku_usb_backend.cpp +0 -532
  115. package/libusb/libusb/os/haiku_usb_raw.cpp +0 -231
  116. package/libusb/libusb/os/haiku_usb_raw.h +0 -188
  117. package/libusb/libusb/os/linux_netlink.c +0 -401
  118. package/libusb/libusb/os/linux_udev.c +0 -321
  119. package/libusb/libusb/os/linux_usbfs.c +0 -2829
  120. package/libusb/libusb/os/linux_usbfs.h +0 -221
  121. package/libusb/libusb/os/netbsd_usb.c +0 -617
  122. package/libusb/libusb/os/null_usb.c +0 -111
  123. package/libusb/libusb/os/openbsd_usb.c +0 -700
  124. package/libusb/libusb/os/sunos_usb.c +0 -1619
  125. package/libusb/libusb/os/sunos_usb.h +0 -79
  126. package/libusb/libusb/os/threads_posix.c +0 -126
  127. package/libusb/libusb/os/threads_posix.h +0 -98
  128. package/libusb/libusb/os/threads_windows.c +0 -40
  129. package/libusb/libusb/os/threads_windows.h +0 -113
  130. package/libusb/libusb/os/windows_common.c +0 -923
  131. package/libusb/libusb/os/windows_common.h +0 -424
  132. package/libusb/libusb/os/windows_usbdk.c +0 -724
  133. package/libusb/libusb/os/windows_usbdk.h +0 -106
  134. package/libusb/libusb/os/windows_winusb.c +0 -4766
  135. package/libusb/libusb/os/windows_winusb.h +0 -787
  136. package/libusb/libusb/strerror.c +0 -223
  137. package/libusb/libusb/sync.c +0 -342
  138. package/libusb/libusb/version.h +0 -18
  139. package/libusb/libusb/version_nano.h +0 -1
  140. package/libusb/libusb-1.0.pc.in +0 -11
  141. package/libusb/msvc/Base.props +0 -60
  142. package/libusb/msvc/Configuration.Application.props +0 -7
  143. package/libusb/msvc/Configuration.Base.props +0 -47
  144. package/libusb/msvc/Configuration.DynamicLibrary.props +0 -21
  145. package/libusb/msvc/Configuration.StaticLibrary.props +0 -7
  146. package/libusb/msvc/ProjectConfigurations.Base.props +0 -69
  147. package/libusb/msvc/build_all.ps1 +0 -17
  148. package/libusb/msvc/config.h +0 -58
  149. package/libusb/msvc/dpfp.vcxproj +0 -33
  150. package/libusb/msvc/dpfp_threaded.vcxproj +0 -38
  151. package/libusb/msvc/fxload.vcxproj +0 -46
  152. package/libusb/msvc/getopt/getopt.c +0 -1060
  153. package/libusb/msvc/getopt/getopt.h +0 -180
  154. package/libusb/msvc/getopt/getopt1.c +0 -188
  155. package/libusb/msvc/getopt.vcxproj +0 -33
  156. package/libusb/msvc/hotplugtest.vcxproj +0 -32
  157. package/libusb/msvc/init_context.vcxproj +0 -35
  158. package/libusb/msvc/libusb.sln +0 -542
  159. package/libusb/msvc/libusb_dll.vcxproj +0 -61
  160. package/libusb/msvc/libusb_static.vcxproj +0 -49
  161. package/libusb/msvc/listdevs.vcxproj +0 -32
  162. package/libusb/msvc/sam3u_benchmark.vcxproj +0 -33
  163. package/libusb/msvc/set_option.vcxproj +0 -35
  164. package/libusb/msvc/stress.vcxproj +0 -35
  165. package/libusb/msvc/stress_mt.vcxproj +0 -33
  166. package/libusb/msvc/testlibusb.vcxproj +0 -32
  167. package/libusb/msvc/xusb.vcxproj +0 -38
  168. package/libusb/tests/Makefile.am +0 -40
  169. package/libusb/tests/init_context.c +0 -153
  170. package/libusb/tests/libusb_testlib.h +0 -76
  171. package/libusb/tests/macos.c +0 -130
  172. package/libusb/tests/set_option.c +0 -253
  173. package/libusb/tests/stress.c +0 -172
  174. package/libusb/tests/stress_mt.c +0 -267
  175. package/libusb/tests/testlib.c +0 -184
  176. package/libusb/tests/umockdev.c +0 -1175
  177. package/libusb/tests/webusb-test-shim/index.js +0 -12
  178. package/libusb/tests/webusb-test-shim/package-lock.json +0 -50
  179. package/libusb/tests/webusb-test-shim/package.json +0 -10
  180. package/libusb.gypi +0 -154
  181. package/libusb_config/config.h +0 -1
  182. package/prebuilds/android-arm/node.napi.armv7.node +0 -0
  183. package/prebuilds/android-arm64/node.napi.armv8.node +0 -0
  184. package/prebuilds/darwin-x64+arm64/node.napi.node +0 -0
  185. package/prebuilds/linux-arm/node.napi.armv6.node +0 -0
  186. package/prebuilds/linux-arm/node.napi.armv7.node +0 -0
  187. package/prebuilds/linux-arm64/node.napi.armv8.node +0 -0
  188. package/prebuilds/linux-ia32/node.napi.node +0 -0
  189. package/prebuilds/linux-x64/node.napi.glibc.node +0 -0
  190. package/prebuilds/linux-x64/node.napi.musl.node +0 -0
  191. package/prebuilds/win32-arm64/node.napi.node +0 -0
  192. package/prebuilds/win32-ia32/node.napi.node +0 -0
  193. package/prebuilds/win32-x64/node.napi.node +0 -0
  194. package/src/device.cc +0 -439
  195. package/src/helpers.h +0 -64
  196. package/src/hotplug/hotplug.h +0 -22
  197. package/src/hotplug/libusb.cc +0 -90
  198. package/src/hotplug/windows.cc +0 -168
  199. package/src/node_usb.cc +0 -314
  200. package/src/node_usb.h +0 -131
  201. package/src/thread_name.cc +0 -79
  202. package/src/thread_name.h +0 -11
  203. package/src/transfer.cc +0 -143
  204. package/src/uv_async_queue.h +0 -41
  205. package/test/usb.coffee +0 -250
  206. package/test/webusb.coffee +0 -227
  207. package/test/worker.cjs +0 -13
@@ -1,532 +0,0 @@
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
- static int _errno_to_libusb(int status)
30
- {
31
- return status;
32
- }
33
-
34
- USBTransfer::USBTransfer(struct usbi_transfer *itransfer, USBDevice *device)
35
- {
36
- fUsbiTransfer = itransfer;
37
- fLibusbTransfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
38
- fUSBDevice = device;
39
- fCancelled = false;
40
- }
41
-
42
- USBTransfer::~USBTransfer()
43
- {
44
- }
45
-
46
- struct usbi_transfer *
47
- USBTransfer::UsbiTransfer()
48
- {
49
- return fUsbiTransfer;
50
- }
51
-
52
- void
53
- USBTransfer::SetCancelled()
54
- {
55
- fCancelled = true;
56
- }
57
-
58
- bool
59
- USBTransfer::IsCancelled()
60
- {
61
- return fCancelled;
62
- }
63
-
64
- void
65
- USBTransfer::Do(int fRawFD)
66
- {
67
- switch (fLibusbTransfer->type) {
68
- case LIBUSB_TRANSFER_TYPE_CONTROL:
69
- {
70
- struct libusb_control_setup *setup = (struct libusb_control_setup *)fLibusbTransfer->buffer;
71
- usb_raw_command command;
72
- command.control.request_type = setup->bmRequestType;
73
- command.control.request = setup->bRequest;
74
- command.control.value = setup->wValue;
75
- command.control.index = setup->wIndex;
76
- command.control.length = setup->wLength;
77
- command.control.data = fLibusbTransfer->buffer + LIBUSB_CONTROL_SETUP_SIZE;
78
- if (fCancelled)
79
- break;
80
- if (ioctl(fRawFD, B_USB_RAW_COMMAND_CONTROL_TRANSFER, &command, sizeof(command)) ||
81
- command.control.status != B_USB_RAW_STATUS_SUCCESS) {
82
- fUsbiTransfer->transferred = -1;
83
- usbi_err(TRANSFER_CTX(fLibusbTransfer), "failed control transfer");
84
- break;
85
- }
86
- fUsbiTransfer->transferred = command.control.length;
87
- }
88
- break;
89
- case LIBUSB_TRANSFER_TYPE_BULK:
90
- case LIBUSB_TRANSFER_TYPE_INTERRUPT:
91
- {
92
- usb_raw_command command;
93
- command.transfer.interface = fUSBDevice->EndpointToInterface(fLibusbTransfer->endpoint);
94
- command.transfer.endpoint = fUSBDevice->EndpointToIndex(fLibusbTransfer->endpoint);
95
- command.transfer.data = fLibusbTransfer->buffer;
96
- command.transfer.length = fLibusbTransfer->length;
97
- if (fCancelled)
98
- break;
99
- if (fLibusbTransfer->type == LIBUSB_TRANSFER_TYPE_BULK) {
100
- if (ioctl(fRawFD, B_USB_RAW_COMMAND_BULK_TRANSFER, &command, sizeof(command)) ||
101
- command.transfer.status != B_USB_RAW_STATUS_SUCCESS) {
102
- fUsbiTransfer->transferred = -1;
103
- usbi_err(TRANSFER_CTX(fLibusbTransfer), "failed bulk transfer");
104
- break;
105
- }
106
- }
107
- else {
108
- if (ioctl(fRawFD, B_USB_RAW_COMMAND_INTERRUPT_TRANSFER, &command, sizeof(command)) ||
109
- command.transfer.status != B_USB_RAW_STATUS_SUCCESS) {
110
- fUsbiTransfer->transferred = -1;
111
- usbi_err(TRANSFER_CTX(fLibusbTransfer), "failed interrupt transfer");
112
- break;
113
- }
114
- }
115
- fUsbiTransfer->transferred = command.transfer.length;
116
- }
117
- break;
118
- // IsochronousTransfers not tested
119
- case LIBUSB_TRANSFER_TYPE_ISOCHRONOUS:
120
- {
121
- usb_raw_command command;
122
- command.isochronous.interface = fUSBDevice->EndpointToInterface(fLibusbTransfer->endpoint);
123
- command.isochronous.endpoint = fUSBDevice->EndpointToIndex(fLibusbTransfer->endpoint);
124
- command.isochronous.data = fLibusbTransfer->buffer;
125
- command.isochronous.length = fLibusbTransfer->length;
126
- command.isochronous.packet_count = fLibusbTransfer->num_iso_packets;
127
- int i;
128
- usb_iso_packet_descriptor *packetDescriptors = new usb_iso_packet_descriptor[fLibusbTransfer->num_iso_packets];
129
- for (i = 0; i < fLibusbTransfer->num_iso_packets; i++) {
130
- if ((fLibusbTransfer->iso_packet_desc[i]).length > (unsigned int)INT16_MAX) {
131
- fUsbiTransfer->transferred = -1;
132
- usbi_err(TRANSFER_CTX(fLibusbTransfer), "failed isochronous transfer");
133
- break;
134
- }
135
- packetDescriptors[i].request_length = (int16)(fLibusbTransfer->iso_packet_desc[i]).length;
136
- }
137
- if (i < fLibusbTransfer->num_iso_packets)
138
- break; // TODO Handle this error
139
- command.isochronous.packet_descriptors = packetDescriptors;
140
- if (fCancelled)
141
- break;
142
- if (ioctl(fRawFD, B_USB_RAW_COMMAND_ISOCHRONOUS_TRANSFER, &command, sizeof(command)) ||
143
- command.isochronous.status != B_USB_RAW_STATUS_SUCCESS) {
144
- fUsbiTransfer->transferred = -1;
145
- usbi_err(TRANSFER_CTX(fLibusbTransfer), "failed isochronous transfer");
146
- break;
147
- }
148
- for (i = 0; i < fLibusbTransfer->num_iso_packets; i++) {
149
- (fLibusbTransfer->iso_packet_desc[i]).actual_length = packetDescriptors[i].actual_length;
150
- switch (packetDescriptors[i].status) {
151
- case B_OK:
152
- (fLibusbTransfer->iso_packet_desc[i]).status = LIBUSB_TRANSFER_COMPLETED;
153
- break;
154
- default:
155
- (fLibusbTransfer->iso_packet_desc[i]).status = LIBUSB_TRANSFER_ERROR;
156
- break;
157
- }
158
- }
159
- delete[] packetDescriptors;
160
- // Do we put the length of transfer here, for isochronous transfers?
161
- fUsbiTransfer->transferred = command.transfer.length;
162
- }
163
- break;
164
- default:
165
- usbi_err(TRANSFER_CTX(fLibusbTransfer), "Unknown type of transfer");
166
- }
167
- }
168
-
169
- bool
170
- USBDeviceHandle::InitCheck()
171
- {
172
- return fInitCheck;
173
- }
174
-
175
- status_t
176
- USBDeviceHandle::TransfersThread(void *self)
177
- {
178
- USBDeviceHandle *handle = (USBDeviceHandle *)self;
179
- handle->TransfersWorker();
180
- return B_OK;
181
- }
182
-
183
- void
184
- USBDeviceHandle::TransfersWorker()
185
- {
186
- while (true) {
187
- status_t status = acquire_sem(fTransfersSem);
188
- if (status == B_BAD_SEM_ID)
189
- break;
190
- if (status == B_INTERRUPTED)
191
- continue;
192
- fTransfersLock.Lock();
193
- USBTransfer *fPendingTransfer = (USBTransfer *) fTransfers.RemoveItem((int32)0);
194
- fTransfersLock.Unlock();
195
- fPendingTransfer->Do(fRawFD);
196
- usbi_signal_transfer_completion(fPendingTransfer->UsbiTransfer());
197
- }
198
- }
199
-
200
- status_t
201
- USBDeviceHandle::SubmitTransfer(struct usbi_transfer *itransfer)
202
- {
203
- USBTransfer *transfer = new USBTransfer(itransfer, fUSBDevice);
204
- *((USBTransfer **)usbi_get_transfer_priv(itransfer)) = transfer;
205
- BAutolock locker(fTransfersLock);
206
- fTransfers.AddItem(transfer);
207
- release_sem(fTransfersSem);
208
- return LIBUSB_SUCCESS;
209
- }
210
-
211
- status_t
212
- USBDeviceHandle::CancelTransfer(USBTransfer *transfer)
213
- {
214
- transfer->SetCancelled();
215
- fTransfersLock.Lock();
216
- bool removed = fTransfers.RemoveItem(transfer);
217
- fTransfersLock.Unlock();
218
- if (removed)
219
- usbi_signal_transfer_completion(transfer->UsbiTransfer());
220
- return LIBUSB_SUCCESS;
221
- }
222
-
223
- USBDeviceHandle::USBDeviceHandle(USBDevice *dev)
224
- :
225
- fUSBDevice(dev),
226
- fClaimedInterfaces(0),
227
- fTransfersThread(-1),
228
- fInitCheck(false)
229
- {
230
- fRawFD = open(dev->Location(), O_RDWR | O_CLOEXEC);
231
- if (fRawFD < 0) {
232
- usbi_err(NULL,"failed to open device");
233
- return;
234
- }
235
- fTransfersSem = create_sem(0, "Transfers Queue Sem");
236
- fTransfersThread = spawn_thread(TransfersThread, "Transfer Worker", B_NORMAL_PRIORITY, this);
237
- resume_thread(fTransfersThread);
238
- fInitCheck = true;
239
- }
240
-
241
- USBDeviceHandle::~USBDeviceHandle()
242
- {
243
- if (fRawFD > 0)
244
- close(fRawFD);
245
- for (int i = 0; i < 32; i++) {
246
- if (fClaimedInterfaces & (1U << i))
247
- ReleaseInterface(i);
248
- }
249
- delete_sem(fTransfersSem);
250
- if (fTransfersThread > 0)
251
- wait_for_thread(fTransfersThread, NULL);
252
- }
253
-
254
- int
255
- USBDeviceHandle::ClaimInterface(uint8 inumber)
256
- {
257
- int status = fUSBDevice->ClaimInterface(inumber);
258
- if (status == LIBUSB_SUCCESS)
259
- fClaimedInterfaces |= (1U << inumber);
260
- return status;
261
- }
262
-
263
- int
264
- USBDeviceHandle::ReleaseInterface(uint8 inumber)
265
- {
266
- fUSBDevice->ReleaseInterface(inumber);
267
- fClaimedInterfaces &= ~(1U << inumber);
268
- return LIBUSB_SUCCESS;
269
- }
270
-
271
- int
272
- USBDeviceHandle::SetConfiguration(uint8 config)
273
- {
274
- int config_index = fUSBDevice->CheckInterfacesFree(config);
275
- if (config_index == LIBUSB_ERROR_BUSY || config_index == LIBUSB_ERROR_NOT_FOUND)
276
- return config_index;
277
- usb_raw_command command;
278
- command.config.config_index = config_index;
279
- if (ioctl(fRawFD, B_USB_RAW_COMMAND_SET_CONFIGURATION, &command, sizeof(command)) ||
280
- command.config.status != B_USB_RAW_STATUS_SUCCESS) {
281
- return _errno_to_libusb(command.config.status);
282
- }
283
- fUSBDevice->SetActiveConfiguration((uint8)config_index);
284
- return LIBUSB_SUCCESS;
285
- }
286
-
287
- int
288
- USBDeviceHandle::SetAltSetting(uint8 inumber, uint8 alt)
289
- {
290
- usb_raw_command command;
291
- command.alternate.config_index = fUSBDevice->ActiveConfigurationIndex();
292
- command.alternate.interface_index = inumber;
293
- if (ioctl(fRawFD, B_USB_RAW_COMMAND_GET_ACTIVE_ALT_INTERFACE_INDEX, &command, sizeof(command)) ||
294
- command.alternate.status != B_USB_RAW_STATUS_SUCCESS) {
295
- usbi_err(NULL, "Error retrieving active alternate interface");
296
- return _errno_to_libusb(command.alternate.status);
297
- }
298
- if (command.alternate.alternate_info == (uint32)alt) {
299
- usbi_dbg(NULL, "Setting alternate interface successful");
300
- return LIBUSB_SUCCESS;
301
- }
302
- command.alternate.alternate_info = alt;
303
- if (ioctl(fRawFD, B_USB_RAW_COMMAND_SET_ALT_INTERFACE, &command, sizeof(command)) ||
304
- command.alternate.status != B_USB_RAW_STATUS_SUCCESS) { //IF IOCTL FAILS DEVICE DISCONNECTED PROBABLY
305
- usbi_err(NULL, "Error setting alternate interface");
306
- return _errno_to_libusb(command.alternate.status);
307
- }
308
- usbi_dbg(NULL, "Setting alternate interface successful");
309
- return LIBUSB_SUCCESS;
310
- }
311
-
312
- int
313
- USBDeviceHandle::ClearHalt(uint8 endpoint)
314
- {
315
- usb_raw_command command;
316
- command.control.request_type = USB_REQTYPE_ENDPOINT_OUT;
317
- command.control.request = USB_REQUEST_CLEAR_FEATURE;
318
- command.control.value = USB_FEATURE_ENDPOINT_HALT;
319
- command.control.index = endpoint;
320
- command.control.length = 0;
321
-
322
- if (ioctl(fRawFD, B_USB_RAW_COMMAND_CONTROL_TRANSFER, &command, sizeof(command)) ||
323
- command.control.status != B_USB_RAW_STATUS_SUCCESS) {
324
- return _errno_to_libusb(command.control.status);
325
- }
326
- return LIBUSB_SUCCESS;
327
- }
328
-
329
-
330
- USBDevice::USBDevice(const char *path)
331
- :
332
- fClaimedInterfaces(0),
333
- fConfigurationDescriptors(NULL),
334
- fActiveConfiguration(0), //0?
335
- fPath(NULL),
336
- fEndpointToIndex(NULL),
337
- fEndpointToInterface(NULL),
338
- fInitCheck(false)
339
- {
340
- fPath=strdup(path);
341
- Initialise();
342
- }
343
-
344
- USBDevice::~USBDevice()
345
- {
346
- free(fPath);
347
- if (fConfigurationDescriptors) {
348
- for (uint8 i = 0; i < fDeviceDescriptor.num_configurations; i++) {
349
- if (fConfigurationDescriptors[i])
350
- delete fConfigurationDescriptors[i];
351
- }
352
- delete[] fConfigurationDescriptors;
353
- }
354
- if (fEndpointToIndex)
355
- delete[] fEndpointToIndex;
356
- if (fEndpointToInterface)
357
- delete[] fEndpointToInterface;
358
- }
359
-
360
- bool
361
- USBDevice::InitCheck()
362
- {
363
- return fInitCheck;
364
- }
365
-
366
- const char *
367
- USBDevice::Location() const
368
- {
369
- return fPath;
370
- }
371
-
372
- uint8
373
- USBDevice::CountConfigurations() const
374
- {
375
- return fDeviceDescriptor.num_configurations;
376
- }
377
-
378
- const usb_device_descriptor *
379
- USBDevice::Descriptor() const
380
- {
381
- return &fDeviceDescriptor;
382
- }
383
-
384
- const usb_configuration_descriptor *
385
- USBDevice::ConfigurationDescriptor(uint8 index) const
386
- {
387
- if (index > CountConfigurations())
388
- return NULL;
389
- return (usb_configuration_descriptor *) fConfigurationDescriptors[index];
390
- }
391
-
392
- const usb_configuration_descriptor *
393
- USBDevice::ActiveConfiguration() const
394
- {
395
- return (usb_configuration_descriptor *) fConfigurationDescriptors[fActiveConfiguration];
396
- }
397
-
398
- uint8
399
- USBDevice::ActiveConfigurationIndex() const
400
- {
401
- return fActiveConfiguration;
402
- }
403
-
404
- int USBDevice::ClaimInterface(uint8 interface)
405
- {
406
- if (interface > ActiveConfiguration()->number_interfaces)
407
- return LIBUSB_ERROR_NOT_FOUND;
408
- if (fClaimedInterfaces & (1U << interface))
409
- return LIBUSB_ERROR_BUSY;
410
- fClaimedInterfaces |= (1U << interface);
411
- return LIBUSB_SUCCESS;
412
- }
413
-
414
- int USBDevice::ReleaseInterface(uint8 interface)
415
- {
416
- fClaimedInterfaces &= ~(1U << interface);
417
- return LIBUSB_SUCCESS;
418
- }
419
-
420
- int
421
- USBDevice::CheckInterfacesFree(uint8 config)
422
- {
423
- if (fConfigToIndex.count(config) == 0)
424
- return LIBUSB_ERROR_NOT_FOUND;
425
- if (fClaimedInterfaces == 0)
426
- return fConfigToIndex[config];
427
- return LIBUSB_ERROR_BUSY;
428
- }
429
-
430
- void
431
- USBDevice::SetActiveConfiguration(uint8 config_index)
432
- {
433
- fActiveConfiguration = config_index;
434
- }
435
-
436
- uint8
437
- USBDevice::EndpointToIndex(uint8 address) const
438
- {
439
- return fEndpointToIndex[fActiveConfiguration][address];
440
- }
441
-
442
- uint8
443
- USBDevice::EndpointToInterface(uint8 address) const
444
- {
445
- return fEndpointToInterface[fActiveConfiguration][address];
446
- }
447
-
448
- int
449
- USBDevice::Initialise() //Do we need more error checking, etc? How to report?
450
- {
451
- int fRawFD = open(fPath, O_RDWR | O_CLOEXEC);
452
- if (fRawFD < 0)
453
- return B_ERROR;
454
- usb_raw_command command;
455
- command.device.descriptor = &fDeviceDescriptor;
456
- if (ioctl(fRawFD, B_USB_RAW_COMMAND_GET_DEVICE_DESCRIPTOR, &command, sizeof(command)) ||
457
- command.device.status != B_USB_RAW_STATUS_SUCCESS) {
458
- close(fRawFD);
459
- return B_ERROR;
460
- }
461
-
462
- fConfigurationDescriptors = new(std::nothrow) unsigned char *[fDeviceDescriptor.num_configurations];
463
- fEndpointToIndex = new(std::nothrow) map<uint8,uint8> [fDeviceDescriptor.num_configurations];
464
- fEndpointToInterface = new(std::nothrow) map<uint8,uint8> [fDeviceDescriptor.num_configurations];
465
- for (uint8 i = 0; i < fDeviceDescriptor.num_configurations; i++) {
466
- usb_configuration_descriptor tmp_config;
467
- command.config.descriptor = &tmp_config;
468
- command.config.config_index = i;
469
- if (ioctl(fRawFD, B_USB_RAW_COMMAND_GET_CONFIGURATION_DESCRIPTOR, &command, sizeof(command)) ||
470
- command.config.status != B_USB_RAW_STATUS_SUCCESS) {
471
- usbi_err(NULL, "failed retrieving configuration descriptor");
472
- close(fRawFD);
473
- return B_ERROR;
474
- }
475
- fConfigToIndex[tmp_config.configuration_value] = i;
476
- fConfigurationDescriptors[i] = new(std::nothrow) unsigned char[tmp_config.total_length];
477
-
478
- command.config_etc.descriptor = (usb_configuration_descriptor*)fConfigurationDescriptors[i];
479
- command.config_etc.length = tmp_config.total_length;
480
- command.config_etc.config_index = i;
481
- if (ioctl(fRawFD, B_USB_RAW_COMMAND_GET_CONFIGURATION_DESCRIPTOR_ETC, &command, sizeof(command)) ||
482
- command.config_etc.status != B_USB_RAW_STATUS_SUCCESS) {
483
- usbi_err(NULL, "failed retrieving full configuration descriptor");
484
- close(fRawFD);
485
- return B_ERROR;
486
- }
487
-
488
- for (uint8 j = 0; j < tmp_config.number_interfaces; j++) {
489
- command.alternate.config_index = i;
490
- command.alternate.interface_index = j;
491
- if (ioctl(fRawFD, B_USB_RAW_COMMAND_GET_ALT_INTERFACE_COUNT, &command, sizeof(command)) ||
492
- command.config.status != B_USB_RAW_STATUS_SUCCESS) {
493
- usbi_err(NULL, "failed retrieving number of alternate interfaces");
494
- close(fRawFD);
495
- return B_ERROR;
496
- }
497
- uint8 num_alternate = (uint8)command.alternate.alternate_info;
498
- for (uint8 k = 0; k < num_alternate; k++) {
499
- usb_interface_descriptor tmp_interface;
500
- command.interface_etc.config_index = i;
501
- command.interface_etc.interface_index = j;
502
- command.interface_etc.alternate_index = k;
503
- command.interface_etc.descriptor = &tmp_interface;
504
- if (ioctl(fRawFD, B_USB_RAW_COMMAND_GET_INTERFACE_DESCRIPTOR_ETC, &command, sizeof(command)) ||
505
- command.config.status != B_USB_RAW_STATUS_SUCCESS) {
506
- usbi_err(NULL, "failed retrieving interface descriptor");
507
- close(fRawFD);
508
- return B_ERROR;
509
- }
510
- for (uint8 l = 0; l < tmp_interface.num_endpoints; l++) {
511
- usb_endpoint_descriptor tmp_endpoint;
512
- command.endpoint_etc.config_index = i;
513
- command.endpoint_etc.interface_index = j;
514
- command.endpoint_etc.alternate_index = k;
515
- command.endpoint_etc.endpoint_index = l;
516
- command.endpoint_etc.descriptor = &tmp_endpoint;
517
- if (ioctl(fRawFD, B_USB_RAW_COMMAND_GET_ENDPOINT_DESCRIPTOR_ETC, &command, sizeof(command)) ||
518
- command.config.status != B_USB_RAW_STATUS_SUCCESS) {
519
- usbi_err(NULL, "failed retrieving endpoint descriptor");
520
- close(fRawFD);
521
- return B_ERROR;
522
- }
523
- fEndpointToIndex[i][tmp_endpoint.endpoint_address] = l;
524
- fEndpointToInterface[i][tmp_endpoint.endpoint_address] = j;
525
- }
526
- }
527
- }
528
- }
529
- close(fRawFD);
530
- fInitCheck = true;
531
- return B_OK;
532
- }