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.
- package/LICENSE +18 -4
- package/README.md +25 -516
- package/dist/index.d.ts +67 -13
- package/dist/index.js +333 -64
- package/index.d.ts +89 -0
- package/index.js +583 -0
- package/package.json +53 -33
- package/CHANGELOG.md +0 -294
- package/binding.gyp +0 -128
- package/dist/index.js.map +0 -1
- package/dist/usb/bindings.d.ts +0 -266
- package/dist/usb/bindings.js +0 -10
- package/dist/usb/bindings.js.map +0 -1
- package/dist/usb/capability.d.ts +0 -13
- package/dist/usb/capability.js +0 -17
- package/dist/usb/capability.js.map +0 -1
- package/dist/usb/descriptors.d.ts +0 -128
- package/dist/usb/descriptors.js +0 -3
- package/dist/usb/descriptors.js.map +0 -1
- package/dist/usb/device.d.ts +0 -100
- package/dist/usb/device.js +0 -297
- package/dist/usb/device.js.map +0 -1
- package/dist/usb/endpoint.d.ts +0 -94
- package/dist/usb/endpoint.js +0 -219
- package/dist/usb/endpoint.js.map +0 -1
- package/dist/usb/index.d.ts +0 -31
- package/dist/usb/index.js +0 -116
- package/dist/usb/index.js.map +0 -1
- package/dist/usb/interface.d.ts +0 -80
- package/dist/usb/interface.js +0 -133
- package/dist/usb/interface.js.map +0 -1
- package/dist/webusb/index.d.ts +0 -64
- package/dist/webusb/index.js +0 -295
- package/dist/webusb/index.js.map +0 -1
- package/dist/webusb/webusb-device.d.ts +0 -54
- package/dist/webusb/webusb-device.js +0 -434
- package/dist/webusb/webusb-device.js.map +0 -1
- package/libusb/.clang-tidy +0 -34
- package/libusb/.codespellrc +0 -3
- package/libusb/.private/README.txt +0 -5
- package/libusb/.private/appveyor_build.sh +0 -26
- package/libusb/.private/bm.sh +0 -54
- package/libusb/.private/ci-build.sh +0 -92
- package/libusb/.private/ci-container-build.sh +0 -67
- package/libusb/.private/post-rewrite.sh +0 -32
- package/libusb/.private/pre-commit.sh +0 -52
- package/libusb/.private/wbs.txt +0 -43
- package/libusb/.travis.yml +0 -58
- package/libusb/AUTHORS +0 -231
- package/libusb/COPYING +0 -504
- package/libusb/ChangeLog +0 -365
- package/libusb/HACKING +0 -25
- package/libusb/INSTALL_WIN.txt +0 -52
- package/libusb/KEYS +0 -123
- package/libusb/Makefile.am +0 -50
- package/libusb/NEWS +0 -2
- package/libusb/PORTING +0 -94
- package/libusb/README +0 -29
- package/libusb/README.git +0 -41
- package/libusb/TODO +0 -2
- package/libusb/Xcode/common.xcconfig +0 -92
- package/libusb/Xcode/config.h +0 -31
- package/libusb/Xcode/debug.xcconfig +0 -32
- package/libusb/Xcode/libusb.xcconfig +0 -21
- package/libusb/Xcode/libusb.xcodeproj/project.pbxproj +0 -1391
- package/libusb/Xcode/libusb_debug.xcconfig +0 -21
- package/libusb/Xcode/libusb_release.xcconfig +0 -21
- package/libusb/Xcode/release.xcconfig +0 -30
- package/libusb/android/README +0 -152
- package/libusb/android/config.h +0 -55
- package/libusb/android/examples/unrooted_android.c +0 -301
- package/libusb/android/examples/unrooted_android.h +0 -36
- package/libusb/android/jni/Android.mk +0 -23
- package/libusb/android/jni/Application.mk +0 -40
- package/libusb/android/jni/examples.mk +0 -168
- package/libusb/android/jni/libusb.mk +0 -60
- package/libusb/android/jni/tests.mk +0 -45
- package/libusb/appveyor.yml +0 -108
- package/libusb/autogen.sh +0 -10
- package/libusb/bootstrap.sh +0 -10
- package/libusb/configure.ac +0 -450
- package/libusb/doc/Makefile.in +0 -22
- package/libusb/doc/doxygen.cfg.in +0 -2571
- package/libusb/doc/libusb.png +0 -0
- package/libusb/examples/Makefile.am +0 -12
- package/libusb/examples/dpfp.c +0 -711
- package/libusb/examples/ezusb.c +0 -846
- package/libusb/examples/ezusb.h +0 -109
- package/libusb/examples/fxload.c +0 -310
- package/libusb/examples/hotplugtest.c +0 -147
- package/libusb/examples/listdevs.c +0 -73
- package/libusb/examples/sam3u_benchmark.c +0 -228
- package/libusb/examples/testlibusb.c +0 -312
- package/libusb/examples/xusb.c +0 -1254
- package/libusb/libusb/Makefile.am +0 -98
- package/libusb/libusb/Makefile.am.extra +0 -26
- package/libusb/libusb/core.c +0 -2925
- package/libusb/libusb/descriptor.c +0 -1558
- package/libusb/libusb/hotplug.c +0 -489
- package/libusb/libusb/io.c +0 -2865
- package/libusb/libusb/libusb-1.0.def +0 -199
- package/libusb/libusb/libusb-1.0.rc +0 -53
- package/libusb/libusb/libusb.h +0 -2421
- package/libusb/libusb/libusbi.h +0 -1535
- package/libusb/libusb/os/darwin_usb.c +0 -2977
- package/libusb/libusb/os/darwin_usb.h +0 -156
- package/libusb/libusb/os/emscripten_webusb.cpp +0 -875
- package/libusb/libusb/os/events_posix.c +0 -340
- package/libusb/libusb/os/events_posix.h +0 -62
- package/libusb/libusb/os/events_windows.c +0 -214
- package/libusb/libusb/os/events_windows.h +0 -46
- package/libusb/libusb/os/haiku_pollfs.cpp +0 -372
- package/libusb/libusb/os/haiku_usb.h +0 -113
- package/libusb/libusb/os/haiku_usb_backend.cpp +0 -532
- package/libusb/libusb/os/haiku_usb_raw.cpp +0 -231
- package/libusb/libusb/os/haiku_usb_raw.h +0 -188
- package/libusb/libusb/os/linux_netlink.c +0 -401
- package/libusb/libusb/os/linux_udev.c +0 -321
- package/libusb/libusb/os/linux_usbfs.c +0 -2829
- package/libusb/libusb/os/linux_usbfs.h +0 -221
- package/libusb/libusb/os/netbsd_usb.c +0 -617
- package/libusb/libusb/os/null_usb.c +0 -111
- package/libusb/libusb/os/openbsd_usb.c +0 -700
- package/libusb/libusb/os/sunos_usb.c +0 -1619
- package/libusb/libusb/os/sunos_usb.h +0 -79
- package/libusb/libusb/os/threads_posix.c +0 -126
- package/libusb/libusb/os/threads_posix.h +0 -98
- package/libusb/libusb/os/threads_windows.c +0 -40
- package/libusb/libusb/os/threads_windows.h +0 -113
- package/libusb/libusb/os/windows_common.c +0 -923
- package/libusb/libusb/os/windows_common.h +0 -424
- package/libusb/libusb/os/windows_usbdk.c +0 -724
- package/libusb/libusb/os/windows_usbdk.h +0 -106
- package/libusb/libusb/os/windows_winusb.c +0 -4766
- package/libusb/libusb/os/windows_winusb.h +0 -787
- package/libusb/libusb/strerror.c +0 -223
- package/libusb/libusb/sync.c +0 -342
- package/libusb/libusb/version.h +0 -18
- package/libusb/libusb/version_nano.h +0 -1
- package/libusb/libusb-1.0.pc.in +0 -11
- package/libusb/msvc/Base.props +0 -60
- package/libusb/msvc/Configuration.Application.props +0 -7
- package/libusb/msvc/Configuration.Base.props +0 -47
- package/libusb/msvc/Configuration.DynamicLibrary.props +0 -21
- package/libusb/msvc/Configuration.StaticLibrary.props +0 -7
- package/libusb/msvc/ProjectConfigurations.Base.props +0 -69
- package/libusb/msvc/build_all.ps1 +0 -17
- package/libusb/msvc/config.h +0 -58
- package/libusb/msvc/dpfp.vcxproj +0 -33
- package/libusb/msvc/dpfp_threaded.vcxproj +0 -38
- package/libusb/msvc/fxload.vcxproj +0 -46
- package/libusb/msvc/getopt/getopt.c +0 -1060
- package/libusb/msvc/getopt/getopt.h +0 -180
- package/libusb/msvc/getopt/getopt1.c +0 -188
- package/libusb/msvc/getopt.vcxproj +0 -33
- package/libusb/msvc/hotplugtest.vcxproj +0 -32
- package/libusb/msvc/init_context.vcxproj +0 -35
- package/libusb/msvc/libusb.sln +0 -542
- package/libusb/msvc/libusb_dll.vcxproj +0 -61
- package/libusb/msvc/libusb_static.vcxproj +0 -49
- package/libusb/msvc/listdevs.vcxproj +0 -32
- package/libusb/msvc/sam3u_benchmark.vcxproj +0 -33
- package/libusb/msvc/set_option.vcxproj +0 -35
- package/libusb/msvc/stress.vcxproj +0 -35
- package/libusb/msvc/stress_mt.vcxproj +0 -33
- package/libusb/msvc/testlibusb.vcxproj +0 -32
- package/libusb/msvc/xusb.vcxproj +0 -38
- package/libusb/tests/Makefile.am +0 -40
- package/libusb/tests/init_context.c +0 -153
- package/libusb/tests/libusb_testlib.h +0 -76
- package/libusb/tests/macos.c +0 -130
- package/libusb/tests/set_option.c +0 -253
- package/libusb/tests/stress.c +0 -172
- package/libusb/tests/stress_mt.c +0 -267
- package/libusb/tests/testlib.c +0 -184
- package/libusb/tests/umockdev.c +0 -1175
- package/libusb/tests/webusb-test-shim/index.js +0 -12
- package/libusb/tests/webusb-test-shim/package-lock.json +0 -50
- package/libusb/tests/webusb-test-shim/package.json +0 -10
- package/libusb.gypi +0 -154
- package/libusb_config/config.h +0 -1
- package/prebuilds/android-arm/node.napi.armv7.node +0 -0
- package/prebuilds/android-arm64/node.napi.armv8.node +0 -0
- package/prebuilds/darwin-x64+arm64/node.napi.node +0 -0
- package/prebuilds/linux-arm/node.napi.armv6.node +0 -0
- package/prebuilds/linux-arm/node.napi.armv7.node +0 -0
- package/prebuilds/linux-arm64/node.napi.armv8.node +0 -0
- package/prebuilds/linux-ia32/node.napi.node +0 -0
- package/prebuilds/linux-x64/node.napi.glibc.node +0 -0
- package/prebuilds/linux-x64/node.napi.musl.node +0 -0
- package/prebuilds/win32-arm64/node.napi.node +0 -0
- package/prebuilds/win32-ia32/node.napi.node +0 -0
- package/prebuilds/win32-x64/node.napi.node +0 -0
- package/src/device.cc +0 -439
- package/src/helpers.h +0 -64
- package/src/hotplug/hotplug.h +0 -22
- package/src/hotplug/libusb.cc +0 -90
- package/src/hotplug/windows.cc +0 -168
- package/src/node_usb.cc +0 -314
- package/src/node_usb.h +0 -131
- package/src/thread_name.cc +0 -79
- package/src/thread_name.h +0 -11
- package/src/transfer.cc +0 -143
- package/src/uv_async_queue.h +0 -41
- package/test/usb.coffee +0 -250
- package/test/webusb.coffee +0 -227
- 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
|
-
}
|