usb 2.16.0 → 2.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/README.md +14 -0
- package/binding.gyp +2 -9
- package/dist/usb/bindings.d.ts +27 -2
- package/dist/usb/bindings.js.map +1 -1
- package/dist/usb/endpoint.js +1 -1
- package/dist/usb/endpoint.js.map +1 -1
- package/dist/usb/index.d.ts +0 -29
- package/dist/usb/index.js +4 -18
- package/dist/usb/index.js.map +1 -1
- package/dist/webusb/index.d.ts +1 -1
- package/dist/webusb/index.js +1 -1
- package/dist/webusb/index.js.map +1 -1
- package/dist/webusb/webusb-device.d.ts +4 -4
- package/dist/webusb/webusb-device.js +5 -2
- package/dist/webusb/webusb-device.js.map +1 -1
- package/libusb/.clang-tidy +36 -0
- package/libusb/.private/ci-build.sh +5 -1
- package/libusb/AUTHORS +21 -0
- package/libusb/ChangeLog +29 -2
- package/libusb/KEYS +123 -0
- package/libusb/README +8 -9
- package/libusb/Xcode/common.xcconfig +20 -0
- package/libusb/Xcode/libusb.xcodeproj/project.pbxproj +16 -12
- package/libusb/android/examples/unrooted_android.c +1 -0
- package/libusb/configure.ac +12 -2
- package/libusb/examples/dpfp.c +1 -1
- package/libusb/examples/ezusb.c +6 -1
- package/libusb/examples/fxload.c +7 -5
- package/libusb/examples/hotplugtest.c +19 -11
- package/libusb/examples/listdevs.c +41 -3
- package/libusb/examples/testlibusb.c +1 -0
- package/libusb/examples/xusb.c +142 -77
- package/libusb/libusb/Makefile.am +4 -0
- package/libusb/libusb/core.c +183 -24
- package/libusb/libusb/descriptor.c +404 -96
- package/libusb/libusb/hotplug.c +27 -8
- package/libusb/libusb/io.c +10 -5
- package/libusb/libusb/libusb-1.0.def +14 -0
- package/libusb/libusb/libusb.h +179 -19
- package/libusb/libusb/libusbi.h +101 -25
- package/libusb/libusb/os/darwin_usb.c +216 -90
- package/libusb/libusb/os/darwin_usb.h +10 -8
- package/libusb/libusb/os/emscripten_webusb.cpp +38 -12
- package/libusb/libusb/os/events_posix.c +4 -4
- package/libusb/libusb/os/haiku_usb_raw.cpp +4 -0
- package/libusb/libusb/os/linux_usbfs.c +92 -33
- package/libusb/libusb/os/linux_usbfs.h +13 -3
- package/libusb/libusb/os/netbsd_usb.c +6 -4
- package/libusb/libusb/os/openbsd_usb.c +4 -2
- package/libusb/libusb/os/sunos_usb.c +7 -5
- package/libusb/libusb/os/threads_posix.c +20 -19
- package/libusb/libusb/os/threads_posix.h +9 -3
- package/libusb/libusb/os/threads_windows.h +4 -3
- package/libusb/libusb/os/windows_common.c +86 -1
- package/libusb/libusb/os/windows_common.h +20 -1
- package/libusb/libusb/os/windows_hotplug.c +321 -0
- package/libusb/libusb/os/windows_hotplug.h +28 -0
- package/libusb/libusb/os/windows_usbdk.c +16 -8
- package/libusb/libusb/os/windows_winusb.c +788 -56
- package/libusb/libusb/os/windows_winusb.h +11 -6
- package/libusb/libusb/sync.c +8 -5
- package/libusb/libusb/version.h +1 -1
- package/libusb/libusb/version_nano.h +1 -1
- package/libusb/msvc/Base.props +1 -1
- package/libusb/msvc/Configuration.Base.props +2 -1
- package/libusb/msvc/Configuration.DynamicLibrary.props +12 -0
- package/libusb/msvc/ProjectConfigurations.Base.props +69 -16
- package/libusb/msvc/build_all.ps1 +2 -2
- package/libusb/msvc/config.h +4 -0
- package/libusb/msvc/getopt/bits/getopt_core.h +96 -0
- package/libusb/msvc/getopt/bits/getopt_ext.h +77 -0
- package/libusb/msvc/getopt/features.h +21 -0
- package/libusb/msvc/getopt/getopt.c +456 -705
- package/libusb/msvc/getopt/getopt.h +16 -158
- package/libusb/msvc/getopt/getopt1.c +40 -69
- package/libusb/msvc/getopt/getopt_int.h +118 -0
- package/libusb/msvc/getopt/gettext.h +7 -0
- package/libusb/msvc/getopt/unistd.h +5 -0
- package/libusb/msvc/getopt.vcxproj +11 -4
- package/libusb/msvc/libusb.sln +515 -268
- package/libusb/msvc/libusb_dll.vcxproj +2 -0
- package/libusb/msvc/libusb_static.vcxproj +2 -0
- package/libusb/msvc/xusb.vcxproj +1 -1
- package/libusb/tests/Makefile.am +10 -1
- package/libusb/tests/fuzz/corpus/bos/min.bos +0 -0
- package/libusb/tests/fuzz/corpus/descriptor_parsers/min_valid_config.bin +0 -0
- package/libusb/tests/fuzz/corpus/descriptor_parsers/regression_bug_a_endpoint_null.bin +0 -0
- package/libusb/tests/fuzz/corpus/descriptor_parsers/regression_bug_b_iad_oob.bin +0 -0
- package/libusb/tests/fuzz/fuzz_bos_descriptor.c +49 -0
- package/libusb/tests/fuzz/fuzz_descriptor_parsers.c +83 -0
- package/libusb/tests/macos.c +2 -2
- package/libusb/tests/stress_mt.c +6 -3
- package/libusb/tests/webusb-test-shim/index.js +6 -5
- package/libusb.gypi +5 -0
- package/package.json +3 -3
- 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/{hotplug/libusb.cc → hotplug.cc} +2 -3
- package/src/{hotplug/hotplug.h → hotplug.h} +2 -6
- package/src/node_usb.cc +3 -3
- package/test/usb.coffee +4 -4
- package/test/webusb.coffee +22 -12
- package/src/hotplug/windows.cc +0 -168
package/libusb/examples/xusb.c
CHANGED
|
@@ -31,12 +31,21 @@
|
|
|
31
31
|
#if defined(_MSC_VER)
|
|
32
32
|
#define snprintf _snprintf
|
|
33
33
|
#define putenv _putenv
|
|
34
|
+
/* Disable: warning C5287: operands are different enum types */
|
|
35
|
+
#if (_MSC_VER > 1800)
|
|
36
|
+
/* Disable: warning C5287: operands are different enum types, supported after Visual Studio 2013 */
|
|
37
|
+
#pragma warning(disable:5287)
|
|
38
|
+
#endif
|
|
34
39
|
#endif
|
|
35
40
|
|
|
36
41
|
// Future versions of libusb will use usb_interface instead of interface
|
|
37
42
|
// in libusb_config_descriptor => catter for that
|
|
38
43
|
#define usb_interface interface
|
|
39
44
|
|
|
45
|
+
#ifndef ARRAYSIZE
|
|
46
|
+
#define ARRAYSIZE(array) (sizeof(array) / sizeof(array[0]))
|
|
47
|
+
#endif
|
|
48
|
+
|
|
40
49
|
// Global variables
|
|
41
50
|
static bool binary_dump = false;
|
|
42
51
|
static bool extra_info = false;
|
|
@@ -62,7 +71,7 @@ static void perr(char const *format, ...)
|
|
|
62
71
|
va_end(args);
|
|
63
72
|
}
|
|
64
73
|
|
|
65
|
-
#define ERR_EXIT(errcode) do { perr(" %s\n", libusb_strerror((enum libusb_error)errcode)); return -1; } while (0)
|
|
74
|
+
#define ERR_EXIT(errcode) do { perr(" %s\n", libusb_strerror((enum libusb_error)(errcode))); return -1; } while (0)
|
|
66
75
|
#define CALL_CHECK(fcall) do { int _r=fcall; if (_r < 0) ERR_EXIT(_r); } while (0)
|
|
67
76
|
#define CALL_CHECK_CLOSE(fcall, hdl) do { int _r=fcall; if (_r < 0) { libusb_close(hdl); ERR_EXIT(_r); } } while (0)
|
|
68
77
|
#define B(x) (((x)!=0)?1:0)
|
|
@@ -461,7 +470,7 @@ static int test_mass_storage(libusb_device_handle *handle, uint8_t endpoint_in,
|
|
|
461
470
|
double device_size;
|
|
462
471
|
uint8_t cdb[16]; // SCSI Command Descriptor Block
|
|
463
472
|
uint8_t buffer[64];
|
|
464
|
-
char vid[9], pid[9], rev[5];
|
|
473
|
+
unsigned char vid[9], pid[9], rev[5];
|
|
465
474
|
unsigned char *data;
|
|
466
475
|
FILE *fd;
|
|
467
476
|
|
|
@@ -494,7 +503,7 @@ static int test_mass_storage(libusb_device_handle *handle, uint8_t endpoint_in,
|
|
|
494
503
|
for (i=0; i<8; i++) {
|
|
495
504
|
vid[i] = buffer[8+i];
|
|
496
505
|
pid[i] = buffer[16+i];
|
|
497
|
-
rev[i/2] = buffer[32+i/2]; // instead of another loop
|
|
506
|
+
rev[i/2] = buffer[32+(i/2)]; // instead of another loop
|
|
498
507
|
}
|
|
499
508
|
vid[8] = 0;
|
|
500
509
|
pid[8] = 0;
|
|
@@ -542,11 +551,14 @@ static int test_mass_storage(libusb_device_handle *handle, uint8_t endpoint_in,
|
|
|
542
551
|
get_sense(handle, endpoint_in, endpoint_out);
|
|
543
552
|
} else {
|
|
544
553
|
display_buffer_hex(data, size);
|
|
545
|
-
if (
|
|
546
|
-
|
|
547
|
-
|
|
554
|
+
if (binary_dump) {
|
|
555
|
+
fd = fopen(binary_name, "w");
|
|
556
|
+
if (fd != NULL) {
|
|
557
|
+
if (fwrite(data, 1, (size_t)size, fd) != (unsigned int)size) {
|
|
558
|
+
perr(" unable to write binary data\n");
|
|
559
|
+
}
|
|
560
|
+
fclose(fd);
|
|
548
561
|
}
|
|
549
|
-
fclose(fd);
|
|
550
562
|
}
|
|
551
563
|
}
|
|
552
564
|
free(data);
|
|
@@ -555,16 +567,16 @@ static int test_mass_storage(libusb_device_handle *handle, uint8_t endpoint_in,
|
|
|
555
567
|
}
|
|
556
568
|
|
|
557
569
|
// HID
|
|
558
|
-
static int get_hid_record_size(uint8_t *hid_report_descriptor, int size, int type)
|
|
570
|
+
static int get_hid_record_size(const uint8_t *hid_report_descriptor, int size, int type)
|
|
559
571
|
{
|
|
560
|
-
uint8_t
|
|
572
|
+
uint8_t j = 0;
|
|
561
573
|
uint8_t offset;
|
|
562
574
|
int record_size[3] = {0, 0, 0};
|
|
563
|
-
int nb_bits = 0, nb_items = 0;
|
|
575
|
+
unsigned int nb_bits = 0, nb_items = 0;
|
|
564
576
|
bool found_record_marker;
|
|
565
577
|
|
|
566
578
|
found_record_marker = false;
|
|
567
|
-
for (i = hid_report_descriptor[0]+1; i < size; i += offset) {
|
|
579
|
+
for (int i = hid_report_descriptor[0]+1; i < size; i += offset) {
|
|
568
580
|
offset = (hid_report_descriptor[i]&0x03) + 1;
|
|
569
581
|
if (offset == 4)
|
|
570
582
|
offset = 5;
|
|
@@ -575,7 +587,7 @@ static int get_hid_record_size(uint8_t *hid_report_descriptor, int size, int typ
|
|
|
575
587
|
case 0x94: // count
|
|
576
588
|
nb_items = 0;
|
|
577
589
|
for (j=1; j<offset; j++) {
|
|
578
|
-
nb_items = ((
|
|
590
|
+
nb_items = ((unsigned int)hid_report_descriptor[i+j]) << (8U*(j-1U));
|
|
579
591
|
}
|
|
580
592
|
break;
|
|
581
593
|
case 0x80: // input
|
|
@@ -623,19 +635,24 @@ static int test_hid(libusb_device_handle *handle, uint8_t endpoint_in)
|
|
|
623
635
|
printf(" Failed\n");
|
|
624
636
|
return -1;
|
|
625
637
|
}
|
|
626
|
-
display_buffer_hex(hid_report_descriptor, descriptor_size);
|
|
627
|
-
if (
|
|
628
|
-
|
|
629
|
-
|
|
638
|
+
display_buffer_hex(hid_report_descriptor, (unsigned int)descriptor_size);
|
|
639
|
+
if (binary_dump) {
|
|
640
|
+
fd = fopen(binary_name, "w");
|
|
641
|
+
if (fd != NULL) {
|
|
642
|
+
if (fwrite(hid_report_descriptor, 1, (size_t)descriptor_size, fd) != (size_t)descriptor_size) {
|
|
643
|
+
printf(" Error writing descriptor to file\n");
|
|
644
|
+
}
|
|
645
|
+
fclose(fd);
|
|
630
646
|
}
|
|
631
|
-
fclose(fd);
|
|
632
647
|
}
|
|
633
648
|
|
|
634
649
|
size = get_hid_record_size(hid_report_descriptor, descriptor_size, HID_REPORT_TYPE_FEATURE);
|
|
635
650
|
if (size <= 0) {
|
|
636
651
|
printf("\nSkipping Feature Report readout (None detected)\n");
|
|
652
|
+
} else if (size > UINT16_MAX) {
|
|
653
|
+
printf("\nSkipping Feature Report readout (bigger than UINT16_MAX)\n");
|
|
637
654
|
} else {
|
|
638
|
-
report_buffer = (uint8_t*) calloc(
|
|
655
|
+
report_buffer = (uint8_t*) calloc(1, (size_t)size);
|
|
639
656
|
if (report_buffer == NULL) {
|
|
640
657
|
return -1;
|
|
641
658
|
}
|
|
@@ -644,7 +661,7 @@ static int test_hid(libusb_device_handle *handle, uint8_t endpoint_in)
|
|
|
644
661
|
r = libusb_control_transfer(handle, LIBUSB_ENDPOINT_IN|LIBUSB_REQUEST_TYPE_CLASS|LIBUSB_RECIPIENT_INTERFACE,
|
|
645
662
|
HID_GET_REPORT, (HID_REPORT_TYPE_FEATURE<<8)|0, 0, report_buffer, (uint16_t)size, 5000);
|
|
646
663
|
if (r >= 0) {
|
|
647
|
-
display_buffer_hex(report_buffer, size);
|
|
664
|
+
display_buffer_hex(report_buffer, (unsigned int)size);
|
|
648
665
|
} else {
|
|
649
666
|
switch(r) {
|
|
650
667
|
case LIBUSB_ERROR_NOT_FOUND:
|
|
@@ -665,8 +682,10 @@ static int test_hid(libusb_device_handle *handle, uint8_t endpoint_in)
|
|
|
665
682
|
size = get_hid_record_size(hid_report_descriptor, descriptor_size, HID_REPORT_TYPE_INPUT);
|
|
666
683
|
if (size <= 0) {
|
|
667
684
|
printf("\nSkipping Input Report readout (None detected)\n");
|
|
685
|
+
} else if (size > UINT16_MAX) {
|
|
686
|
+
printf("\nSkipping Input Report readout (bigger than UINT16_MAX)\n");
|
|
668
687
|
} else {
|
|
669
|
-
report_buffer = (uint8_t*) calloc(
|
|
688
|
+
report_buffer = (uint8_t*) calloc(1, (size_t)size);
|
|
670
689
|
if (report_buffer == NULL) {
|
|
671
690
|
return -1;
|
|
672
691
|
}
|
|
@@ -675,7 +694,7 @@ static int test_hid(libusb_device_handle *handle, uint8_t endpoint_in)
|
|
|
675
694
|
r = libusb_control_transfer(handle, LIBUSB_ENDPOINT_IN|LIBUSB_REQUEST_TYPE_CLASS|LIBUSB_RECIPIENT_INTERFACE,
|
|
676
695
|
HID_GET_REPORT, (HID_REPORT_TYPE_INPUT<<8)|0x00, 0, report_buffer, (uint16_t)size, 5000);
|
|
677
696
|
if (r >= 0) {
|
|
678
|
-
display_buffer_hex(report_buffer, size);
|
|
697
|
+
display_buffer_hex(report_buffer, (unsigned int)size);
|
|
679
698
|
} else {
|
|
680
699
|
switch(r) {
|
|
681
700
|
case LIBUSB_ERROR_TIMEOUT:
|
|
@@ -695,7 +714,7 @@ static int test_hid(libusb_device_handle *handle, uint8_t endpoint_in)
|
|
|
695
714
|
printf("\nTesting interrupt read using endpoint %02X...\n", endpoint_in);
|
|
696
715
|
r = libusb_interrupt_transfer(handle, endpoint_in, report_buffer, size, &size, 5000);
|
|
697
716
|
if (r >= 0) {
|
|
698
|
-
display_buffer_hex(report_buffer, size);
|
|
717
|
+
display_buffer_hex(report_buffer, (unsigned int)size);
|
|
699
718
|
} else {
|
|
700
719
|
printf(" %s\n", libusb_strerror((enum libusb_error)r));
|
|
701
720
|
}
|
|
@@ -753,11 +772,22 @@ static void read_ms_winsub_feature_descriptors(libusb_device_handle *handle, uin
|
|
|
753
772
|
perr(" Failed: %s", libusb_strerror((enum libusb_error)r));
|
|
754
773
|
return;
|
|
755
774
|
} else {
|
|
756
|
-
display_buffer_hex(os_desc, r);
|
|
775
|
+
display_buffer_hex(os_desc, (unsigned int)r);
|
|
757
776
|
}
|
|
758
777
|
}
|
|
759
778
|
}
|
|
760
779
|
|
|
780
|
+
static void print_sublink_speed_attribute(struct libusb_ssplus_sublink_attribute* ss_attr) {
|
|
781
|
+
static const char exponent[] = " KMG";
|
|
782
|
+
printf(" id=%u speed=%u%cbs %s %s SuperSpeed%s",
|
|
783
|
+
ss_attr->ssid,
|
|
784
|
+
ss_attr->mantissa,
|
|
785
|
+
(exponent[ss_attr->exponent]),
|
|
786
|
+
(ss_attr->type == LIBUSB_SSPLUS_ATTR_TYPE_ASYM)? "Asym" : "Sym",
|
|
787
|
+
(ss_attr->direction == LIBUSB_SSPLUS_ATTR_DIR_TX)? "TX" : "RX",
|
|
788
|
+
(ss_attr->protocol == LIBUSB_SSPLUS_ATTR_PROT_SSPLUS)? "Plus": "" );
|
|
789
|
+
}
|
|
790
|
+
|
|
761
791
|
static void print_device_cap(struct libusb_bos_dev_capability_descriptor *dev_cap)
|
|
762
792
|
{
|
|
763
793
|
switch(dev_cap->bDevCapabilityType) {
|
|
@@ -806,6 +836,25 @@ static void print_device_cap(struct libusb_bos_dev_capability_descriptor *dev_ca
|
|
|
806
836
|
break;
|
|
807
837
|
|
|
808
838
|
}
|
|
839
|
+
case LIBUSB_BT_SUPERSPEED_PLUS_CAPABILITY: {
|
|
840
|
+
struct libusb_ssplus_usb_device_capability_descriptor *ssplus_usb_device_cap = NULL;
|
|
841
|
+
libusb_get_ssplus_usb_device_capability_descriptor(NULL, dev_cap, &ssplus_usb_device_cap);
|
|
842
|
+
if (ssplus_usb_device_cap) {
|
|
843
|
+
printf(" USB 3.1 capabilities:\n");
|
|
844
|
+
printf(" num speed IDs: %d\n", ssplus_usb_device_cap->numSublinkSpeedIDs);
|
|
845
|
+
printf(" minLaneSpeed: %d\n", ssplus_usb_device_cap->ssid);
|
|
846
|
+
printf(" minRXLanes: %d\n", ssplus_usb_device_cap->minRxLaneCount);
|
|
847
|
+
printf(" minTXLanes: %d\n", ssplus_usb_device_cap->minTxLaneCount);
|
|
848
|
+
|
|
849
|
+
printf(" num speed attribute IDs: %d\n", ssplus_usb_device_cap->numSublinkSpeedAttributes);
|
|
850
|
+
for(uint8_t i=0 ; i < ssplus_usb_device_cap->numSublinkSpeedAttributes ; i++) {
|
|
851
|
+
print_sublink_speed_attribute(&ssplus_usb_device_cap->sublinkSpeedAttributes[i]);
|
|
852
|
+
printf("\n");
|
|
853
|
+
}
|
|
854
|
+
libusb_free_ssplus_usb_device_capability_descriptor(ssplus_usb_device_cap);
|
|
855
|
+
}
|
|
856
|
+
break;
|
|
857
|
+
}
|
|
809
858
|
default:
|
|
810
859
|
printf(" Unknown BOS device capability %02x:\n", dev_cap->bDevCapabilityType);
|
|
811
860
|
}
|
|
@@ -816,15 +865,15 @@ static int test_device(uint16_t vid, uint16_t pid)
|
|
|
816
865
|
libusb_device_handle *handle;
|
|
817
866
|
libusb_device *dev;
|
|
818
867
|
uint8_t bus, port_path[8];
|
|
819
|
-
struct libusb_bos_descriptor *bos_desc;
|
|
820
868
|
struct libusb_config_descriptor *conf_desc;
|
|
821
869
|
const struct libusb_endpoint_descriptor *endpoint;
|
|
822
870
|
int i, j, k, r;
|
|
823
871
|
int iface, nb_ifaces, first_iface = -1;
|
|
824
872
|
struct libusb_device_descriptor dev_desc;
|
|
825
|
-
const char* const speed_name[
|
|
826
|
-
"480 Mbit/s (USB HighSpeed)", "5000 Mbit/s (USB SuperSpeed)", "10000 Mbit/s (USB SuperSpeedPlus)"
|
|
827
|
-
|
|
873
|
+
const char* const speed_name[] = { "Unknown", "1.5 Mbit/s (USB LowSpeed)", "12 Mbit/s (USB FullSpeed)",
|
|
874
|
+
"480 Mbit/s (USB HighSpeed)", "5000 Mbit/s (USB SuperSpeed)", "10000 Mbit/s (USB SuperSpeedPlus)",
|
|
875
|
+
"20000 Mbit/s (USB SuperSpeedPlus x2)" };
|
|
876
|
+
unsigned char string[128];
|
|
828
877
|
uint8_t string_index[3]; // indexes of the string descriptors
|
|
829
878
|
uint8_t endpoint_in = 0, endpoint_out = 0; // default IN and OUT endpoints
|
|
830
879
|
|
|
@@ -850,7 +899,8 @@ static int test_device(uint16_t vid, uint16_t pid)
|
|
|
850
899
|
printf(" (from root hub)\n");
|
|
851
900
|
}
|
|
852
901
|
r = libusb_get_device_speed(dev);
|
|
853
|
-
if ((r<0) || (r
|
|
902
|
+
if ((r < 0) || ((size_t)r >= ARRAYSIZE(speed_name)))
|
|
903
|
+
r = 0;
|
|
854
904
|
printf(" speed: %s\n", speed_name[r]);
|
|
855
905
|
}
|
|
856
906
|
|
|
@@ -868,14 +918,18 @@ static int test_device(uint16_t vid, uint16_t pid)
|
|
|
868
918
|
string_index[1] = dev_desc.iProduct;
|
|
869
919
|
string_index[2] = dev_desc.iSerialNumber;
|
|
870
920
|
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
921
|
+
if (dev_desc.bcdUSB >= 0x0201) {
|
|
922
|
+
struct libusb_bos_descriptor *bos_desc;
|
|
923
|
+
|
|
924
|
+
printf("\nReading BOS descriptor: ");
|
|
925
|
+
if (libusb_get_bos_descriptor(handle, &bos_desc) == LIBUSB_SUCCESS) {
|
|
926
|
+
printf("%d caps\n", bos_desc->bNumDeviceCaps);
|
|
927
|
+
for (i = 0; i < bos_desc->bNumDeviceCaps; i++)
|
|
928
|
+
print_device_cap(bos_desc->dev_capability[i]);
|
|
929
|
+
libusb_free_bos_descriptor(bos_desc);
|
|
930
|
+
} else {
|
|
931
|
+
printf("no descriptor\n");
|
|
932
|
+
}
|
|
879
933
|
}
|
|
880
934
|
|
|
881
935
|
printf("\nReading first configuration descriptor:\n");
|
|
@@ -933,25 +987,23 @@ static int test_device(uint16_t vid, uint16_t pid)
|
|
|
933
987
|
libusb_set_auto_detach_kernel_driver(handle, 1);
|
|
934
988
|
for (iface = 0; iface < nb_ifaces; iface++)
|
|
935
989
|
{
|
|
936
|
-
int ret;
|
|
937
|
-
|
|
938
990
|
printf("\nKernel driver attached for interface %d: ", iface);
|
|
939
|
-
|
|
940
|
-
if (
|
|
991
|
+
r = libusb_kernel_driver_active(handle, iface);
|
|
992
|
+
if (r == 0)
|
|
941
993
|
printf("none\n");
|
|
942
|
-
else if (
|
|
994
|
+
else if (r == 1)
|
|
943
995
|
printf("yes\n");
|
|
944
|
-
else if (
|
|
996
|
+
else if (r == LIBUSB_ERROR_NOT_SUPPORTED)
|
|
945
997
|
printf("(not supported)\n");
|
|
946
998
|
else
|
|
947
|
-
perr("\n Failed (error %d) %s\n",
|
|
948
|
-
libusb_strerror((enum libusb_error)
|
|
999
|
+
perr("\n Failed (error %d) %s\n", r,
|
|
1000
|
+
libusb_strerror((enum libusb_error) r));
|
|
949
1001
|
|
|
950
1002
|
printf("\nClaiming interface %d...\n", iface);
|
|
951
1003
|
r = libusb_claim_interface(handle, iface);
|
|
952
1004
|
if (r != LIBUSB_SUCCESS) {
|
|
953
|
-
perr(" Failed (error %d) %s\n",
|
|
954
|
-
libusb_strerror((enum libusb_error)
|
|
1005
|
+
perr(" Failed (error %d) %s\n", r,
|
|
1006
|
+
libusb_strerror((enum libusb_error) r));
|
|
955
1007
|
}
|
|
956
1008
|
}
|
|
957
1009
|
|
|
@@ -960,13 +1012,13 @@ static int test_device(uint16_t vid, uint16_t pid)
|
|
|
960
1012
|
if (string_index[i] == 0) {
|
|
961
1013
|
continue;
|
|
962
1014
|
}
|
|
963
|
-
if (libusb_get_string_descriptor_ascii(handle, string_index[i],
|
|
1015
|
+
if (libusb_get_string_descriptor_ascii(handle, string_index[i], string, sizeof(string)) > 0) {
|
|
964
1016
|
printf(" String (0x%02X): \"%s\"\n", string_index[i], string);
|
|
965
1017
|
}
|
|
966
1018
|
}
|
|
967
1019
|
|
|
968
1020
|
printf("\nReading OS string descriptor:");
|
|
969
|
-
r = libusb_get_string_descriptor(handle, MS_OS_DESC_STRING_INDEX, 0,
|
|
1021
|
+
r = libusb_get_string_descriptor(handle, MS_OS_DESC_STRING_INDEX, 0, string, MS_OS_DESC_STRING_LENGTH);
|
|
970
1022
|
if (r == MS_OS_DESC_STRING_LENGTH && memcmp(ms_os_desc_string, string, sizeof(ms_os_desc_string)) == 0) {
|
|
971
1023
|
// If this is a Microsoft OS String Descriptor,
|
|
972
1024
|
// attempt to read the WinUSB extended Feature Descriptors
|
|
@@ -991,7 +1043,7 @@ static int test_device(uint16_t vid, uint16_t pid)
|
|
|
991
1043
|
printf(" bFunctionSubClass: %02X\n", iad->bFunctionSubClass);
|
|
992
1044
|
printf(" bFunctionProtocol: %02X\n", iad->bFunctionProtocol);
|
|
993
1045
|
if (iad->iFunction) {
|
|
994
|
-
if (libusb_get_string_descriptor_ascii(handle, iad->iFunction,
|
|
1046
|
+
if (libusb_get_string_descriptor_ascii(handle, iad->iFunction, string, sizeof(string)) > 0)
|
|
995
1047
|
printf(" iFunction: %u (%s)\n", iad->iFunction, string);
|
|
996
1048
|
else
|
|
997
1049
|
printf(" iFunction: %u (libusb_get_string_descriptor_ascii failed!)\n", iad->iFunction);
|
|
@@ -1017,6 +1069,7 @@ static int test_device(uint16_t vid, uint16_t pid)
|
|
|
1017
1069
|
break;
|
|
1018
1070
|
case USE_SCSI:
|
|
1019
1071
|
CALL_CHECK_CLOSE(test_mass_storage(handle, endpoint_in, endpoint_out), handle);
|
|
1072
|
+
break;
|
|
1020
1073
|
case USE_GENERIC:
|
|
1021
1074
|
break;
|
|
1022
1075
|
}
|
|
@@ -1033,9 +1086,25 @@ static int test_device(uint16_t vid, uint16_t pid)
|
|
|
1033
1086
|
return 0;
|
|
1034
1087
|
}
|
|
1035
1088
|
|
|
1089
|
+
static void display_help(const char *progname)
|
|
1090
|
+
{
|
|
1091
|
+
printf("usage: %s [-h] [-d] [-i] [-k] [-b file] [-l lang] [-j] [-x] [-s] [-p] [-w] [vid:pid]\n", progname);
|
|
1092
|
+
printf(" -h : display usage\n");
|
|
1093
|
+
printf(" -d : enable debug output\n");
|
|
1094
|
+
printf(" -i : print topology and speed info\n");
|
|
1095
|
+
printf(" -j : test composite FTDI based JTAG device\n");
|
|
1096
|
+
printf(" -k : test Mass Storage device\n");
|
|
1097
|
+
printf(" -b file : dump Mass Storage data to file 'file'\n");
|
|
1098
|
+
printf(" -p : test Sony PS3 SixAxis controller\n");
|
|
1099
|
+
printf(" -s : test Microsoft Sidewinder Precision Pro (HID)\n");
|
|
1100
|
+
printf(" -x : test Microsoft XBox Controller Type S\n");
|
|
1101
|
+
printf(" -l lang : language to report errors in (ISO 639-1)\n");
|
|
1102
|
+
printf(" -w : force the use of device requests when querying WCID descriptors\n");
|
|
1103
|
+
printf("If only the vid:pid is provided, xusb attempts to run the most appropriate test\n");
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1036
1106
|
int main(int argc, char** argv)
|
|
1037
1107
|
{
|
|
1038
|
-
bool show_help = false;
|
|
1039
1108
|
bool debug_mode = false;
|
|
1040
1109
|
const struct libusb_version* version;
|
|
1041
1110
|
int j, r;
|
|
@@ -1052,7 +1121,12 @@ int main(int argc, char** argv)
|
|
|
1052
1121
|
if (((uint8_t*)&endian_test)[0] == 0xBE) {
|
|
1053
1122
|
printf("Despite their natural superiority for end users, big endian\n"
|
|
1054
1123
|
"CPUs are not supported with this program, sorry.\n");
|
|
1055
|
-
return
|
|
1124
|
+
return EXIT_FAILURE;
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
if ((argc == 1) || (argc > 7)) {
|
|
1128
|
+
display_help(argv[0]);
|
|
1129
|
+
return EXIT_FAILURE;
|
|
1056
1130
|
}
|
|
1057
1131
|
|
|
1058
1132
|
if (argc >= 2) {
|
|
@@ -1073,7 +1147,7 @@ int main(int argc, char** argv)
|
|
|
1073
1147
|
case 'b':
|
|
1074
1148
|
if ((j+1 >= argc) || (argv[j+1][0] == '-') || (argv[j+1][0] == '/')) {
|
|
1075
1149
|
printf(" Option -b requires a file name\n");
|
|
1076
|
-
return
|
|
1150
|
+
return EXIT_FAILURE;
|
|
1077
1151
|
}
|
|
1078
1152
|
binary_name = argv[++j];
|
|
1079
1153
|
binary_dump = true;
|
|
@@ -1081,7 +1155,7 @@ int main(int argc, char** argv)
|
|
|
1081
1155
|
case 'l':
|
|
1082
1156
|
if ((j+1 >= argc) || (argv[j+1][0] == '-') || (argv[j+1][0] == '/')) {
|
|
1083
1157
|
printf(" Option -l requires an ISO 639-1 language parameter\n");
|
|
1084
|
-
return
|
|
1158
|
+
return EXIT_FAILURE;
|
|
1085
1159
|
}
|
|
1086
1160
|
error_lang = argv[++j];
|
|
1087
1161
|
break;
|
|
@@ -1118,9 +1192,12 @@ int main(int argc, char** argv)
|
|
|
1118
1192
|
PID = 0x0289;
|
|
1119
1193
|
test_mode = USE_XBOX;
|
|
1120
1194
|
break;
|
|
1195
|
+
case 'h':
|
|
1196
|
+
display_help(argv[0]);
|
|
1197
|
+
return EXIT_SUCCESS;
|
|
1121
1198
|
default:
|
|
1122
|
-
|
|
1123
|
-
|
|
1199
|
+
display_help(argv[0]);
|
|
1200
|
+
return EXIT_FAILURE;
|
|
1124
1201
|
}
|
|
1125
1202
|
} else {
|
|
1126
1203
|
for (i=0; i<arglen; i++) {
|
|
@@ -1130,34 +1207,18 @@ int main(int argc, char** argv)
|
|
|
1130
1207
|
if (i != arglen) {
|
|
1131
1208
|
if (sscanf(argv[j], "%x:%x" , &tmp_vid, &tmp_pid) != 2) {
|
|
1132
1209
|
printf(" Please specify VID & PID as \"vid:pid\" in hexadecimal format\n");
|
|
1133
|
-
return
|
|
1210
|
+
return EXIT_FAILURE;
|
|
1134
1211
|
}
|
|
1135
1212
|
VID = (uint16_t)tmp_vid;
|
|
1136
1213
|
PID = (uint16_t)tmp_pid;
|
|
1137
1214
|
} else {
|
|
1138
|
-
|
|
1215
|
+
display_help(argv[0]);
|
|
1216
|
+
return EXIT_FAILURE;
|
|
1139
1217
|
}
|
|
1140
1218
|
}
|
|
1141
1219
|
}
|
|
1142
1220
|
}
|
|
1143
1221
|
|
|
1144
|
-
if ((show_help) || (argc == 1) || (argc > 7)) {
|
|
1145
|
-
printf("usage: %s [-h] [-d] [-i] [-k] [-b file] [-l lang] [-j] [-x] [-s] [-p] [-w] [vid:pid]\n", argv[0]);
|
|
1146
|
-
printf(" -h : display usage\n");
|
|
1147
|
-
printf(" -d : enable debug output\n");
|
|
1148
|
-
printf(" -i : print topology and speed info\n");
|
|
1149
|
-
printf(" -j : test composite FTDI based JTAG device\n");
|
|
1150
|
-
printf(" -k : test Mass Storage device\n");
|
|
1151
|
-
printf(" -b file : dump Mass Storage data to file 'file'\n");
|
|
1152
|
-
printf(" -p : test Sony PS3 SixAxis controller\n");
|
|
1153
|
-
printf(" -s : test Microsoft Sidewinder Precision Pro (HID)\n");
|
|
1154
|
-
printf(" -x : test Microsoft XBox Controller Type S\n");
|
|
1155
|
-
printf(" -l lang : language to report errors in (ISO 639-1)\n");
|
|
1156
|
-
printf(" -w : force the use of device requests when querying WCID descriptors\n");
|
|
1157
|
-
printf("If only the vid:pid is provided, xusb attempts to run the most appropriate test\n");
|
|
1158
|
-
return 0;
|
|
1159
|
-
}
|
|
1160
|
-
|
|
1161
1222
|
version = libusb_get_version();
|
|
1162
1223
|
printf("Using libusb v%d.%d.%d.%d\n\n", version->major, version->minor, version->micro, version->nano);
|
|
1163
1224
|
|
|
@@ -1170,7 +1231,7 @@ int main(int argc, char** argv)
|
|
|
1170
1231
|
}
|
|
1171
1232
|
|
|
1172
1233
|
if (r < 0)
|
|
1173
|
-
return
|
|
1234
|
+
return EXIT_FAILURE;
|
|
1174
1235
|
|
|
1175
1236
|
// If not set externally, and no debug option was given, use info log level
|
|
1176
1237
|
if ((old_dbg_str == NULL) && (!debug_mode))
|
|
@@ -1181,14 +1242,18 @@ int main(int argc, char** argv)
|
|
|
1181
1242
|
printf("Invalid or unsupported locale '%s': %s\n", error_lang, libusb_strerror((enum libusb_error)r));
|
|
1182
1243
|
}
|
|
1183
1244
|
|
|
1184
|
-
test_device(VID, PID);
|
|
1245
|
+
r = test_device(VID, PID);
|
|
1185
1246
|
|
|
1186
1247
|
libusb_exit(NULL);
|
|
1187
1248
|
|
|
1249
|
+
if (r < 0)
|
|
1250
|
+
return EXIT_FAILURE;
|
|
1251
|
+
|
|
1252
|
+
|
|
1188
1253
|
if (debug_mode) {
|
|
1189
1254
|
snprintf(str, sizeof(str), "LIBUSB_DEBUG=%s", (old_dbg_str == NULL)?"":old_dbg_str);
|
|
1190
1255
|
str[sizeof(str) - 1] = 0; // Windows may not NUL terminate the string
|
|
1191
1256
|
}
|
|
1192
1257
|
|
|
1193
|
-
return
|
|
1258
|
+
return EXIT_SUCCESS;
|
|
1194
1259
|
}
|
|
@@ -30,6 +30,10 @@ OS_WINDOWS_SRC = libusb-1.0.def libusb-1.0.rc \
|
|
|
30
30
|
os/windows_usbdk.h os/windows_usbdk.c \
|
|
31
31
|
os/windows_winusb.h os/windows_winusb.c
|
|
32
32
|
|
|
33
|
+
if LIBUSB_WINDOWS_HOTPLUG
|
|
34
|
+
OS_WINDOWS_SRC += os/windows_hotplug.h os/windows_hotplug.c
|
|
35
|
+
endif
|
|
36
|
+
|
|
33
37
|
if OS_DARWIN
|
|
34
38
|
OS_SRC = $(OS_DARWIN_SRC)
|
|
35
39
|
endif
|