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,228 +0,0 @@
1
- /*
2
- * libusb example program to measure Atmel SAM3U isochronous performance
3
- * Copyright (C) 2012 Harald Welte <laforge@gnumonks.org>
4
- *
5
- * Copied with the author's permission under LGPL-2.1 from
6
- * http://git.gnumonks.org/cgi-bin/gitweb.cgi?p=sam3u-tests.git;a=blob;f=usb-benchmark-project/host/benchmark.c;h=74959f7ee88f1597286cd435f312a8ff52c56b7e
7
- *
8
- * An Atmel SAM3U test firmware is also available in the above repository.
9
- *
10
- * This library is free software; you can redistribute it and/or
11
- * modify it under the terms of the GNU Lesser General Public
12
- * License as published by the Free Software Foundation; either
13
- * version 2.1 of the License, or (at your option) any later version.
14
- *
15
- * This library is distributed in the hope that it will be useful,
16
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18
- * Lesser General Public License for more details.
19
- *
20
- * You should have received a copy of the GNU Lesser General Public
21
- * License along with this library; if not, write to the Free Software
22
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23
- */
24
-
25
- #include <config.h>
26
-
27
- #include <errno.h>
28
- #include <signal.h>
29
- #include <stdio.h>
30
- #include <stdlib.h>
31
- #ifdef HAVE_SYS_TIME_H
32
- #include <sys/time.h>
33
- #endif
34
- #include <time.h>
35
-
36
- #include "libusb.h"
37
-
38
- #define EP_DATA_IN 0x82
39
- #define EP_ISO_IN 0x86
40
-
41
- static volatile sig_atomic_t do_exit = 0;
42
- static struct libusb_device_handle *devh = NULL;
43
-
44
- static unsigned long num_bytes = 0, num_xfer = 0;
45
- static struct timeval tv_start;
46
-
47
- static void get_timestamp(struct timeval *tv)
48
- {
49
- #if defined(PLATFORM_WINDOWS)
50
- static LARGE_INTEGER frequency;
51
- LARGE_INTEGER counter;
52
-
53
- if (!frequency.QuadPart)
54
- QueryPerformanceFrequency(&frequency);
55
-
56
- QueryPerformanceCounter(&counter);
57
- counter.QuadPart *= 1000000;
58
- counter.QuadPart /= frequency.QuadPart;
59
-
60
- tv->tv_sec = (long)(counter.QuadPart / 1000000ULL);
61
- tv->tv_usec = (long)(counter.QuadPart % 1000000ULL);
62
- #elif defined(HAVE_CLOCK_GETTIME)
63
- struct timespec ts;
64
-
65
- (void)clock_gettime(CLOCK_MONOTONIC, &ts);
66
- tv->tv_sec = ts.tv_sec;
67
- tv->tv_usec = (int)(ts.tv_nsec / 1000L);
68
- #else
69
- gettimeofday(tv, NULL);
70
- #endif
71
- }
72
-
73
- static void LIBUSB_CALL cb_xfr(struct libusb_transfer *xfr)
74
- {
75
- int i;
76
-
77
- if (xfr->status != LIBUSB_TRANSFER_COMPLETED) {
78
- fprintf(stderr, "transfer status %d\n", xfr->status);
79
- libusb_free_transfer(xfr);
80
- exit(3);
81
- }
82
-
83
- if (xfr->type == LIBUSB_TRANSFER_TYPE_ISOCHRONOUS) {
84
- for (i = 0; i < xfr->num_iso_packets; i++) {
85
- struct libusb_iso_packet_descriptor *pack = &xfr->iso_packet_desc[i];
86
-
87
- if (pack->status != LIBUSB_TRANSFER_COMPLETED) {
88
- fprintf(stderr, "Error: pack %d status %d\n", i, pack->status);
89
- exit(5);
90
- }
91
-
92
- printf("pack%d length:%u, actual_length:%u\n", i, pack->length, pack->actual_length);
93
- }
94
- }
95
-
96
- printf("length:%u, actual_length:%u\n", xfr->length, xfr->actual_length);
97
- for (i = 0; i < xfr->actual_length; i++) {
98
- printf("%02x", xfr->buffer[i]);
99
- if (i % 16)
100
- printf("\n");
101
- else if (i % 8)
102
- printf(" ");
103
- else
104
- printf(" ");
105
- }
106
- num_bytes += xfr->actual_length;
107
- num_xfer++;
108
-
109
- if (libusb_submit_transfer(xfr) < 0) {
110
- fprintf(stderr, "error re-submitting URB\n");
111
- exit(1);
112
- }
113
- }
114
-
115
- static int benchmark_in(uint8_t ep)
116
- {
117
- static uint8_t buf[2048];
118
- static struct libusb_transfer *xfr;
119
- int num_iso_pack = 0;
120
-
121
- if (ep == EP_ISO_IN)
122
- num_iso_pack = 16;
123
-
124
- xfr = libusb_alloc_transfer(num_iso_pack);
125
- if (!xfr) {
126
- errno = ENOMEM;
127
- return -1;
128
- }
129
-
130
- if (ep == EP_ISO_IN) {
131
- libusb_fill_iso_transfer(xfr, devh, ep, buf,
132
- sizeof(buf), num_iso_pack, cb_xfr, NULL, 0);
133
- libusb_set_iso_packet_lengths(xfr, sizeof(buf)/num_iso_pack);
134
- } else
135
- libusb_fill_bulk_transfer(xfr, devh, ep, buf,
136
- sizeof(buf), cb_xfr, NULL, 0);
137
-
138
- get_timestamp(&tv_start);
139
-
140
- /* NOTE: To reach maximum possible performance the program must
141
- * submit *multiple* transfers here, not just one.
142
- *
143
- * When only one transfer is submitted there is a gap in the bus
144
- * schedule from when the transfer completes until a new transfer
145
- * is submitted by the callback. This causes some jitter for
146
- * isochronous transfers and loss of throughput for bulk transfers.
147
- *
148
- * This is avoided by queueing multiple transfers in advance, so
149
- * that the host controller is always kept busy, and will schedule
150
- * more transfers on the bus while the callback is running for
151
- * transfers which have completed on the bus.
152
- */
153
-
154
- return libusb_submit_transfer(xfr);
155
- }
156
-
157
- static void measure(void)
158
- {
159
- struct timeval tv_stop;
160
- unsigned long diff_msec;
161
-
162
- get_timestamp(&tv_stop);
163
-
164
- diff_msec = (tv_stop.tv_sec - tv_start.tv_sec) * 1000L;
165
- diff_msec += (tv_stop.tv_usec - tv_start.tv_usec) / 1000L;
166
-
167
- printf("%lu transfers (total %lu bytes) in %lu milliseconds => %lu bytes/sec\n",
168
- num_xfer, num_bytes, diff_msec, (num_bytes * 1000L) / diff_msec);
169
- }
170
-
171
- static void sig_hdlr(int signum)
172
- {
173
- (void)signum;
174
-
175
- measure();
176
- do_exit = 1;
177
- }
178
-
179
- int main(void)
180
- {
181
- int rc;
182
-
183
- #if defined(PLATFORM_POSIX)
184
- struct sigaction sigact;
185
-
186
- sigact.sa_handler = sig_hdlr;
187
- sigemptyset(&sigact.sa_mask);
188
- sigact.sa_flags = 0;
189
- (void)sigaction(SIGINT, &sigact, NULL);
190
- #else
191
- (void)signal(SIGINT, sig_hdlr);
192
- #endif
193
-
194
- rc = libusb_init_context(/*ctx=*/NULL, /*options=*/NULL, /*num_options=*/0);
195
- if (rc < 0) {
196
- fprintf(stderr, "Error initializing libusb: %s\n", libusb_error_name(rc));
197
- exit(1);
198
- }
199
-
200
- devh = libusb_open_device_with_vid_pid(NULL, 0x16c0, 0x0763);
201
- if (!devh) {
202
- fprintf(stderr, "Error finding USB device\n");
203
- goto out;
204
- }
205
-
206
- rc = libusb_claim_interface(devh, 2);
207
- if (rc < 0) {
208
- fprintf(stderr, "Error claiming interface: %s\n", libusb_error_name(rc));
209
- goto out;
210
- }
211
-
212
- benchmark_in(EP_ISO_IN);
213
-
214
- while (!do_exit) {
215
- rc = libusb_handle_events(NULL);
216
- if (rc != LIBUSB_SUCCESS)
217
- break;
218
- }
219
-
220
- /* Measurement has already been done by the signal handler. */
221
-
222
- libusb_release_interface(devh, 2);
223
- out:
224
- if (devh)
225
- libusb_close(devh);
226
- libusb_exit(NULL);
227
- return rc;
228
- }
@@ -1,312 +0,0 @@
1
- /*
2
- * Test suite program based of libusb-0.1-compat testlibusb
3
- * Copyright (c) 2013 Nathan Hjelm <hjelmn@mac.ccom>
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 <stdio.h>
21
- #include <string.h>
22
- #include "libusb.h"
23
-
24
- int verbose = 0;
25
-
26
- static void print_endpoint_comp(const struct libusb_ss_endpoint_companion_descriptor *ep_comp)
27
- {
28
- printf(" USB 3.0 Endpoint Companion:\n");
29
- printf(" bMaxBurst: %u\n", ep_comp->bMaxBurst);
30
- printf(" bmAttributes: %02xh\n", ep_comp->bmAttributes);
31
- printf(" wBytesPerInterval: %u\n", ep_comp->wBytesPerInterval);
32
- }
33
-
34
- static void print_endpoint(const struct libusb_endpoint_descriptor *endpoint)
35
- {
36
- int i, ret;
37
-
38
- printf(" Endpoint:\n");
39
- printf(" bEndpointAddress: %02xh\n", endpoint->bEndpointAddress);
40
- printf(" bmAttributes: %02xh\n", endpoint->bmAttributes);
41
- printf(" wMaxPacketSize: %u\n", endpoint->wMaxPacketSize);
42
- printf(" bInterval: %u\n", endpoint->bInterval);
43
- printf(" bRefresh: %u\n", endpoint->bRefresh);
44
- printf(" bSynchAddress: %u\n", endpoint->bSynchAddress);
45
-
46
- for (i = 0; i < endpoint->extra_length;) {
47
- if (LIBUSB_DT_SS_ENDPOINT_COMPANION == endpoint->extra[i + 1]) {
48
- struct libusb_ss_endpoint_companion_descriptor *ep_comp;
49
-
50
- ret = libusb_get_ss_endpoint_companion_descriptor(NULL, endpoint, &ep_comp);
51
- if (LIBUSB_SUCCESS != ret)
52
- continue;
53
-
54
- print_endpoint_comp(ep_comp);
55
-
56
- libusb_free_ss_endpoint_companion_descriptor(ep_comp);
57
- }
58
-
59
- i += endpoint->extra[i];
60
- }
61
- }
62
-
63
- static void print_altsetting(const struct libusb_interface_descriptor *interface)
64
- {
65
- uint8_t i;
66
-
67
- printf(" Interface:\n");
68
- printf(" bInterfaceNumber: %u\n", interface->bInterfaceNumber);
69
- printf(" bAlternateSetting: %u\n", interface->bAlternateSetting);
70
- printf(" bNumEndpoints: %u\n", interface->bNumEndpoints);
71
- printf(" bInterfaceClass: %u\n", interface->bInterfaceClass);
72
- printf(" bInterfaceSubClass: %u\n", interface->bInterfaceSubClass);
73
- printf(" bInterfaceProtocol: %u\n", interface->bInterfaceProtocol);
74
- printf(" iInterface: %u\n", interface->iInterface);
75
-
76
- for (i = 0; i < interface->bNumEndpoints; i++)
77
- print_endpoint(&interface->endpoint[i]);
78
- }
79
-
80
- static void print_2_0_ext_cap(struct libusb_usb_2_0_extension_descriptor *usb_2_0_ext_cap)
81
- {
82
- printf(" USB 2.0 Extension Capabilities:\n");
83
- printf(" bDevCapabilityType: %u\n", usb_2_0_ext_cap->bDevCapabilityType);
84
- printf(" bmAttributes: %08xh\n", usb_2_0_ext_cap->bmAttributes);
85
- }
86
-
87
- static void print_ss_usb_cap(struct libusb_ss_usb_device_capability_descriptor *ss_usb_cap)
88
- {
89
- printf(" USB 3.0 Capabilities:\n");
90
- printf(" bDevCapabilityType: %u\n", ss_usb_cap->bDevCapabilityType);
91
- printf(" bmAttributes: %02xh\n", ss_usb_cap->bmAttributes);
92
- printf(" wSpeedSupported: %u\n", ss_usb_cap->wSpeedSupported);
93
- printf(" bFunctionalitySupport: %u\n", ss_usb_cap->bFunctionalitySupport);
94
- printf(" bU1devExitLat: %u\n", ss_usb_cap->bU1DevExitLat);
95
- printf(" bU2devExitLat: %u\n", ss_usb_cap->bU2DevExitLat);
96
- }
97
-
98
- static void print_bos(libusb_device_handle *handle)
99
- {
100
- struct libusb_bos_descriptor *bos;
101
- uint8_t i;
102
- int ret;
103
-
104
- ret = libusb_get_bos_descriptor(handle, &bos);
105
- if (ret < 0)
106
- return;
107
-
108
- printf(" Binary Object Store (BOS):\n");
109
- printf(" wTotalLength: %u\n", bos->wTotalLength);
110
- printf(" bNumDeviceCaps: %u\n", bos->bNumDeviceCaps);
111
-
112
- for (i = 0; i < bos->bNumDeviceCaps; i++) {
113
- struct libusb_bos_dev_capability_descriptor *dev_cap = bos->dev_capability[i];
114
-
115
- if (dev_cap->bDevCapabilityType == LIBUSB_BT_USB_2_0_EXTENSION) {
116
- struct libusb_usb_2_0_extension_descriptor *usb_2_0_extension;
117
-
118
- ret = libusb_get_usb_2_0_extension_descriptor(NULL, dev_cap, &usb_2_0_extension);
119
- if (ret < 0)
120
- return;
121
-
122
- print_2_0_ext_cap(usb_2_0_extension);
123
- libusb_free_usb_2_0_extension_descriptor(usb_2_0_extension);
124
- } else if (dev_cap->bDevCapabilityType == LIBUSB_BT_SS_USB_DEVICE_CAPABILITY) {
125
- struct libusb_ss_usb_device_capability_descriptor *ss_dev_cap;
126
-
127
- ret = libusb_get_ss_usb_device_capability_descriptor(NULL, dev_cap, &ss_dev_cap);
128
- if (ret < 0)
129
- return;
130
-
131
- print_ss_usb_cap(ss_dev_cap);
132
- libusb_free_ss_usb_device_capability_descriptor(ss_dev_cap);
133
- }
134
- }
135
-
136
- libusb_free_bos_descriptor(bos);
137
- }
138
-
139
- static void print_interface(const struct libusb_interface *interface)
140
- {
141
- int i;
142
-
143
- for (i = 0; i < interface->num_altsetting; i++)
144
- print_altsetting(&interface->altsetting[i]);
145
- }
146
-
147
- static void print_configuration(struct libusb_config_descriptor *config)
148
- {
149
- uint8_t i;
150
-
151
- printf(" Configuration:\n");
152
- printf(" wTotalLength: %u\n", config->wTotalLength);
153
- printf(" bNumInterfaces: %u\n", config->bNumInterfaces);
154
- printf(" bConfigurationValue: %u\n", config->bConfigurationValue);
155
- printf(" iConfiguration: %u\n", config->iConfiguration);
156
- printf(" bmAttributes: %02xh\n", config->bmAttributes);
157
- printf(" MaxPower: %u\n", config->MaxPower);
158
-
159
- for (i = 0; i < config->bNumInterfaces; i++)
160
- print_interface(&config->interface[i]);
161
- }
162
-
163
- static void print_device(libusb_device *dev, libusb_device_handle *handle)
164
- {
165
- struct libusb_device_descriptor desc;
166
- unsigned char string[256];
167
- const char *speed;
168
- int ret;
169
- uint8_t i;
170
-
171
- switch (libusb_get_device_speed(dev)) {
172
- case LIBUSB_SPEED_LOW: speed = "1.5M"; break;
173
- case LIBUSB_SPEED_FULL: speed = "12M"; break;
174
- case LIBUSB_SPEED_HIGH: speed = "480M"; break;
175
- case LIBUSB_SPEED_SUPER: speed = "5G"; break;
176
- case LIBUSB_SPEED_SUPER_PLUS: speed = "10G"; break;
177
- case LIBUSB_SPEED_SUPER_PLUS_X2: speed = "20G"; break;
178
- default: speed = "Unknown";
179
- }
180
-
181
- ret = libusb_get_device_descriptor(dev, &desc);
182
- if (ret < 0) {
183
- fprintf(stderr, "failed to get device descriptor");
184
- return;
185
- }
186
-
187
- printf("Dev (bus %u, device %u): %04X - %04X speed: %s\n",
188
- libusb_get_bus_number(dev), libusb_get_device_address(dev),
189
- desc.idVendor, desc.idProduct, speed);
190
-
191
- if (!handle)
192
- libusb_open(dev, &handle);
193
-
194
- if (handle) {
195
- if (desc.iManufacturer) {
196
- ret = libusb_get_string_descriptor_ascii(handle, desc.iManufacturer, string, sizeof(string));
197
- if (ret > 0)
198
- printf(" Manufacturer: %s\n", (char *)string);
199
- }
200
-
201
- if (desc.iProduct) {
202
- ret = libusb_get_string_descriptor_ascii(handle, desc.iProduct, string, sizeof(string));
203
- if (ret > 0)
204
- printf(" Product: %s\n", (char *)string);
205
- }
206
-
207
- if (desc.iSerialNumber && verbose) {
208
- ret = libusb_get_string_descriptor_ascii(handle, desc.iSerialNumber, string, sizeof(string));
209
- if (ret > 0)
210
- printf(" Serial Number: %s\n", (char *)string);
211
- }
212
- }
213
-
214
- if (verbose) {
215
- for (i = 0; i < desc.bNumConfigurations; i++) {
216
- struct libusb_config_descriptor *config;
217
-
218
- ret = libusb_get_config_descriptor(dev, i, &config);
219
- if (LIBUSB_SUCCESS != ret) {
220
- printf(" Couldn't retrieve descriptors\n");
221
- continue;
222
- }
223
-
224
- print_configuration(config);
225
-
226
- libusb_free_config_descriptor(config);
227
- }
228
-
229
- if (handle && desc.bcdUSB >= 0x0201)
230
- print_bos(handle);
231
- }
232
-
233
- if (handle)
234
- libusb_close(handle);
235
- }
236
-
237
- #ifdef __linux__
238
- #include <errno.h>
239
- #include <fcntl.h>
240
- #include <unistd.h>
241
-
242
- static int test_wrapped_device(const char *device_name)
243
- {
244
- libusb_device_handle *handle;
245
- int r, fd;
246
-
247
- fd = open(device_name, O_RDWR);
248
- if (fd < 0) {
249
- printf("Error could not open %s: %s\n", device_name, strerror(errno));
250
- return 1;
251
- }
252
- r = libusb_wrap_sys_device(NULL, fd, &handle);
253
- if (r) {
254
- printf("Error wrapping device: %s: %s\n", device_name, libusb_strerror(r));
255
- close(fd);
256
- return 1;
257
- }
258
- print_device(libusb_get_device(handle), handle);
259
- close(fd);
260
- return 0;
261
- }
262
- #else
263
- static int test_wrapped_device(const char *device_name)
264
- {
265
- (void)device_name;
266
- printf("Testing wrapped devices is not supported on your platform\n");
267
- return 1;
268
- }
269
- #endif
270
-
271
- int main(int argc, char *argv[])
272
- {
273
- const char *device_name = NULL;
274
- libusb_device **devs;
275
- ssize_t cnt;
276
- int r, i;
277
-
278
- for (i = 1; i < argc; i++) {
279
- if (!strcmp(argv[i], "-v")) {
280
- verbose = 1;
281
- } else if (!strcmp(argv[i], "-d") && (i + 1) < argc) {
282
- i++;
283
- device_name = argv[i];
284
- } else {
285
- printf("Usage %s [-v] [-d </dev/bus/usb/...>]\n", argv[0]);
286
- printf("Note use -d to test libusb_wrap_sys_device()\n");
287
- return 1;
288
- }
289
- }
290
-
291
- r = libusb_init_context(/*ctx=*/NULL, /*options=*/NULL, /*num_options=*/0);
292
- if (r < 0)
293
- return r;
294
-
295
- if (device_name) {
296
- r = test_wrapped_device(device_name);
297
- } else {
298
- cnt = libusb_get_device_list(NULL, &devs);
299
- if (cnt < 0) {
300
- libusb_exit(NULL);
301
- return 1;
302
- }
303
-
304
- for (i = 0; devs[i]; i++)
305
- print_device(devs[i], NULL);
306
-
307
- libusb_free_device_list(devs, 1);
308
- }
309
-
310
- libusb_exit(NULL);
311
- return r;
312
- }