usb 2.12.1 → 2.13.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 +8 -0
- package/README.md +1 -1
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/dist/usb/bindings.js +1 -1
- package/dist/usb/bindings.js.map +1 -1
- package/dist/usb/capability.js.map +1 -1
- package/dist/usb/device.js.map +1 -1
- package/dist/usb/endpoint.d.ts +1 -0
- package/dist/usb/endpoint.js +2 -2
- package/dist/usb/endpoint.js.map +1 -1
- package/dist/usb/index.js.map +1 -1
- package/dist/usb/interface.js +2 -2
- package/dist/usb/interface.js.map +1 -1
- package/dist/webusb/index.d.ts +2 -2
- package/dist/webusb/index.js.map +1 -1
- package/dist/webusb/webusb-device.js +10 -10
- package/dist/webusb/webusb-device.js.map +1 -1
- package/libusb/.codespellrc +3 -0
- package/libusb/.private/appveyor_build.sh +5 -1
- package/libusb/.private/ci-build.sh +26 -1
- package/libusb/.private/ci-container-build.sh +2 -5
- package/libusb/.private/wbs.txt +5 -8
- package/libusb/AUTHORS +22 -0
- package/libusb/ChangeLog +19 -2
- package/libusb/HACKING +25 -0
- package/libusb/INSTALL_WIN.txt +11 -10
- package/libusb/NEWS +2 -2
- package/libusb/README +3 -2
- package/libusb/README.git +1 -1
- package/libusb/Xcode/common.xcconfig +8 -1
- package/libusb/Xcode/config.h +0 -6
- package/libusb/Xcode/debug.xcconfig +4 -1
- package/libusb/Xcode/libusb.xcconfig +1 -1
- package/libusb/Xcode/libusb.xcodeproj/project.pbxproj +60 -30
- package/libusb/Xcode/libusb_debug.xcconfig +1 -1
- package/libusb/Xcode/libusb_release.xcconfig +1 -1
- package/libusb/Xcode/release.xcconfig +1 -1
- package/libusb/appveyor.yml +33 -9
- package/libusb/configure.ac +68 -37
- package/libusb/examples/dpfp.c +2 -2
- package/libusb/examples/fxload.c +2 -2
- package/libusb/examples/hotplugtest.c +28 -13
- package/libusb/examples/listdevs.c +1 -1
- package/libusb/examples/sam3u_benchmark.c +1 -1
- package/libusb/examples/testlibusb.c +1 -1
- package/libusb/examples/xusb.c +74 -19
- package/libusb/libusb/Makefile.am +11 -1
- package/libusb/libusb/core.c +364 -186
- package/libusb/libusb/descriptor.c +276 -16
- package/libusb/libusb/hotplug.c +5 -4
- package/libusb/libusb/io.c +72 -61
- package/libusb/libusb/libusb-1.0.def +14 -1
- package/libusb/libusb/libusb.h +245 -76
- package/libusb/libusb/libusbi.h +35 -13
- package/libusb/libusb/os/darwin_usb.c +542 -279
- package/libusb/libusb/os/darwin_usb.h +44 -115
- package/libusb/libusb/os/emscripten_webusb.cpp +870 -0
- package/libusb/libusb/os/events_posix.c +40 -0
- package/libusb/libusb/os/events_posix.h +3 -0
- package/libusb/libusb/os/linux_usbfs.c +27 -16
- package/libusb/libusb/os/netbsd_usb.c +36 -36
- package/libusb/libusb/os/openbsd_usb.c +34 -34
- package/libusb/libusb/os/sunos_usb.c +25 -15
- package/libusb/libusb/os/threads_posix.c +1 -5
- package/libusb/libusb/os/windows_common.c +13 -5
- package/libusb/libusb/os/windows_common.h +8 -0
- package/libusb/libusb/os/windows_winusb.c +366 -174
- package/libusb/libusb/os/windows_winusb.h +13 -9
- package/libusb/libusb/strerror.c +5 -5
- package/libusb/libusb/sync.c +24 -19
- package/libusb/libusb/version.h +1 -1
- package/libusb/libusb/version_nano.h +1 -1
- package/libusb/msvc/Base.props +60 -0
- package/libusb/msvc/Configuration.Application.props +7 -0
- package/libusb/msvc/Configuration.Base.props +47 -0
- package/libusb/msvc/Configuration.DynamicLibrary.props +21 -0
- package/libusb/msvc/Configuration.StaticLibrary.props +7 -0
- package/libusb/msvc/ProjectConfigurations.Base.props +69 -0
- package/libusb/msvc/build_all.ps1 +17 -0
- package/libusb/msvc/config.h +2 -2
- package/libusb/msvc/dpfp.vcxproj +33 -0
- package/libusb/msvc/dpfp_threaded.vcxproj +38 -0
- package/libusb/msvc/fxload.vcxproj +46 -0
- package/libusb/msvc/getopt.vcxproj +33 -0
- package/libusb/msvc/hotplugtest.vcxproj +32 -0
- package/libusb/msvc/init_context.vcxproj +35 -0
- package/libusb/msvc/libusb.sln +542 -0
- package/libusb/msvc/libusb_dll.vcxproj +61 -0
- package/libusb/msvc/libusb_static.vcxproj +49 -0
- package/libusb/msvc/listdevs.vcxproj +32 -0
- package/libusb/msvc/sam3u_benchmark.vcxproj +33 -0
- package/libusb/msvc/set_option.vcxproj +35 -0
- package/libusb/msvc/stress.vcxproj +35 -0
- package/libusb/msvc/stress_mt.vcxproj +33 -0
- package/libusb/msvc/testlibusb.vcxproj +32 -0
- package/libusb/msvc/xusb.vcxproj +38 -0
- package/libusb/tests/Makefile.am +25 -3
- package/libusb/tests/init_context.c +153 -0
- package/libusb/tests/macos.c +130 -0
- package/libusb/tests/set_option.c +253 -0
- package/libusb/tests/stress.c +17 -14
- package/libusb/tests/stress_mt.c +265 -0
- package/libusb/tests/testlib.c +1 -1
- package/libusb/tests/umockdev.c +9 -9
- package/libusb/tests/webusb-test-shim/index.js +12 -0
- package/libusb/tests/webusb-test-shim/package-lock.json +50 -0
- package/libusb/tests/webusb-test-shim/package.json +10 -0
- package/package.json +7 -7
- 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 +15 -5
- package/libusb/msvc/dpfp_2013.vcxproj +0 -87
- package/libusb/msvc/dpfp_2013.vcxproj.filters +0 -26
- package/libusb/msvc/dpfp_2015.vcxproj +0 -87
- package/libusb/msvc/dpfp_2015.vcxproj.filters +0 -26
- package/libusb/msvc/dpfp_2017.vcxproj +0 -106
- package/libusb/msvc/dpfp_2017.vcxproj.filters +0 -26
- package/libusb/msvc/dpfp_2019.vcxproj +0 -106
- package/libusb/msvc/dpfp_2019.vcxproj.filters +0 -26
- package/libusb/msvc/dpfp_threaded_2013.vcxproj +0 -87
- package/libusb/msvc/dpfp_threaded_2013.vcxproj.filters +0 -26
- package/libusb/msvc/dpfp_threaded_2015.vcxproj +0 -87
- package/libusb/msvc/dpfp_threaded_2015.vcxproj.filters +0 -26
- package/libusb/msvc/dpfp_threaded_2017.vcxproj +0 -106
- package/libusb/msvc/dpfp_threaded_2017.vcxproj.filters +0 -26
- package/libusb/msvc/dpfp_threaded_2019.vcxproj +0 -106
- package/libusb/msvc/dpfp_threaded_2019.vcxproj.filters +0 -26
- package/libusb/msvc/fxload_2013.vcxproj +0 -94
- package/libusb/msvc/fxload_2013.vcxproj.filters +0 -35
- package/libusb/msvc/fxload_2015.vcxproj +0 -94
- package/libusb/msvc/fxload_2015.vcxproj.filters +0 -35
- package/libusb/msvc/fxload_2017.vcxproj +0 -113
- package/libusb/msvc/fxload_2017.vcxproj.filters +0 -35
- package/libusb/msvc/fxload_2019.vcxproj +0 -113
- package/libusb/msvc/fxload_2019.vcxproj.filters +0 -35
- package/libusb/msvc/getopt_2013.vcxproj +0 -72
- package/libusb/msvc/getopt_2013.vcxproj.filters +0 -26
- package/libusb/msvc/getopt_2015.vcxproj +0 -73
- package/libusb/msvc/getopt_2015.vcxproj.filters +0 -26
- package/libusb/msvc/getopt_2017.vcxproj +0 -92
- package/libusb/msvc/getopt_2017.vcxproj.filters +0 -26
- package/libusb/msvc/getopt_2019.vcxproj +0 -92
- package/libusb/msvc/getopt_2019.vcxproj.filters +0 -26
- package/libusb/msvc/hotplugtest_2013.vcxproj +0 -86
- package/libusb/msvc/hotplugtest_2013.vcxproj.filters +0 -23
- package/libusb/msvc/hotplugtest_2015.vcxproj +0 -86
- package/libusb/msvc/hotplugtest_2015.vcxproj.filters +0 -23
- package/libusb/msvc/hotplugtest_2017.vcxproj +0 -105
- package/libusb/msvc/hotplugtest_2017.vcxproj.filters +0 -23
- package/libusb/msvc/hotplugtest_2019.vcxproj +0 -105
- package/libusb/msvc/hotplugtest_2019.vcxproj.filters +0 -23
- package/libusb/msvc/libusb_2013.sln +0 -137
- package/libusb/msvc/libusb_2015.sln +0 -137
- package/libusb/msvc/libusb_2017.sln +0 -240
- package/libusb/msvc/libusb_2019.sln +0 -240
- package/libusb/msvc/libusb_dll_2013.vcxproj +0 -104
- package/libusb/msvc/libusb_dll_2013.vcxproj.filters +0 -94
- package/libusb/msvc/libusb_dll_2015.vcxproj +0 -105
- package/libusb/msvc/libusb_dll_2015.vcxproj.filters +0 -94
- package/libusb/msvc/libusb_dll_2017.vcxproj +0 -124
- package/libusb/msvc/libusb_dll_2017.vcxproj.filters +0 -94
- package/libusb/msvc/libusb_dll_2019.vcxproj +0 -124
- package/libusb/msvc/libusb_dll_2019.vcxproj.filters +0 -94
- package/libusb/msvc/libusb_static_2013.vcxproj +0 -94
- package/libusb/msvc/libusb_static_2013.vcxproj.filters +0 -80
- package/libusb/msvc/libusb_static_2015.vcxproj +0 -95
- package/libusb/msvc/libusb_static_2015.vcxproj.filters +0 -80
- package/libusb/msvc/libusb_static_2017.vcxproj +0 -114
- package/libusb/msvc/libusb_static_2017.vcxproj.filters +0 -80
- package/libusb/msvc/libusb_static_2019.vcxproj +0 -114
- package/libusb/msvc/libusb_static_2019.vcxproj.filters +0 -80
- package/libusb/msvc/listdevs_2013.vcxproj +0 -86
- package/libusb/msvc/listdevs_2013.vcxproj.filters +0 -23
- package/libusb/msvc/listdevs_2015.vcxproj +0 -86
- package/libusb/msvc/listdevs_2015.vcxproj.filters +0 -23
- package/libusb/msvc/listdevs_2017.vcxproj +0 -105
- package/libusb/msvc/listdevs_2017.vcxproj.filters +0 -23
- package/libusb/msvc/listdevs_2019.vcxproj +0 -105
- package/libusb/msvc/listdevs_2019.vcxproj.filters +0 -23
- package/libusb/msvc/sam3u_benchmark_2013.vcxproj +0 -87
- package/libusb/msvc/sam3u_benchmark_2013.vcxproj.filters +0 -26
- package/libusb/msvc/sam3u_benchmark_2015.vcxproj +0 -87
- package/libusb/msvc/sam3u_benchmark_2015.vcxproj.filters +0 -26
- package/libusb/msvc/sam3u_benchmark_2017.vcxproj +0 -106
- package/libusb/msvc/sam3u_benchmark_2017.vcxproj.filters +0 -26
- package/libusb/msvc/sam3u_benchmark_2019.vcxproj +0 -106
- package/libusb/msvc/sam3u_benchmark_2019.vcxproj.filters +0 -26
- package/libusb/msvc/stress_2013.vcxproj +0 -89
- package/libusb/msvc/stress_2013.vcxproj.filters +0 -32
- package/libusb/msvc/stress_2015.vcxproj +0 -89
- package/libusb/msvc/stress_2015.vcxproj.filters +0 -32
- package/libusb/msvc/stress_2017.vcxproj +0 -108
- package/libusb/msvc/stress_2017.vcxproj.filters +0 -32
- package/libusb/msvc/stress_2019.vcxproj +0 -108
- package/libusb/msvc/stress_2019.vcxproj.filters +0 -32
- package/libusb/msvc/testlibusb_2013.vcxproj +0 -86
- package/libusb/msvc/testlibusb_2013.vcxproj.filters +0 -23
- package/libusb/msvc/testlibusb_2015.vcxproj +0 -86
- package/libusb/msvc/testlibusb_2015.vcxproj.filters +0 -23
- package/libusb/msvc/testlibusb_2017.vcxproj +0 -105
- package/libusb/msvc/testlibusb_2017.vcxproj.filters +0 -23
- package/libusb/msvc/testlibusb_2019.vcxproj +0 -105
- package/libusb/msvc/testlibusb_2019.vcxproj.filters +0 -23
- package/libusb/msvc/xusb_2013.vcxproj +0 -86
- package/libusb/msvc/xusb_2013.vcxproj.filters +0 -23
- package/libusb/msvc/xusb_2015.vcxproj +0 -86
- package/libusb/msvc/xusb_2015.vcxproj.filters +0 -23
- package/libusb/msvc/xusb_2017.vcxproj +0 -105
- package/libusb/msvc/xusb_2017.vcxproj.filters +0 -23
- package/libusb/msvc/xusb_2019.vcxproj +0 -105
- package/libusb/msvc/xusb_2019.vcxproj.filters +0 -23
|
@@ -521,7 +521,7 @@ static int get_config_descriptor(struct libusb_device *dev, uint8_t config_idx,
|
|
|
521
521
|
*
|
|
522
522
|
* This is a non-blocking function; the device descriptor is cached in memory.
|
|
523
523
|
*
|
|
524
|
-
* Note since libusb-1.0.16, \ref
|
|
524
|
+
* Note since libusb-1.0.16, \ref LIBUSBX_API_VERSION >= 0x01000102, this
|
|
525
525
|
* function always succeeds.
|
|
526
526
|
*
|
|
527
527
|
* \param dev the device
|
|
@@ -548,7 +548,7 @@ int API_EXPORTED libusb_get_device_descriptor(libusb_device *dev,
|
|
|
548
548
|
* valid if 0 was returned. Must be freed with libusb_free_config_descriptor()
|
|
549
549
|
* after use.
|
|
550
550
|
* \returns 0 on success
|
|
551
|
-
* \returns LIBUSB_ERROR_NOT_FOUND if the device is in unconfigured state
|
|
551
|
+
* \returns \ref LIBUSB_ERROR_NOT_FOUND if the device is in unconfigured state
|
|
552
552
|
* \returns another LIBUSB_ERROR code on error
|
|
553
553
|
* \see libusb_get_config_descriptor
|
|
554
554
|
*/
|
|
@@ -588,7 +588,7 @@ int API_EXPORTED libusb_get_active_config_descriptor(libusb_device *dev,
|
|
|
588
588
|
* valid if 0 was returned. Must be freed with libusb_free_config_descriptor()
|
|
589
589
|
* after use.
|
|
590
590
|
* \returns 0 on success
|
|
591
|
-
* \returns LIBUSB_ERROR_NOT_FOUND if the configuration does not exist
|
|
591
|
+
* \returns \ref LIBUSB_ERROR_NOT_FOUND if the configuration does not exist
|
|
592
592
|
* \returns another LIBUSB_ERROR code on error
|
|
593
593
|
* \see libusb_get_active_config_descriptor()
|
|
594
594
|
* \see libusb_get_config_descriptor_by_value()
|
|
@@ -634,7 +634,7 @@ int API_EXPORTED libusb_get_config_descriptor(libusb_device *dev,
|
|
|
634
634
|
* valid if 0 was returned. Must be freed with libusb_free_config_descriptor()
|
|
635
635
|
* after use.
|
|
636
636
|
* \returns 0 on success
|
|
637
|
-
* \returns LIBUSB_ERROR_NOT_FOUND if the configuration does not exist
|
|
637
|
+
* \returns \ref LIBUSB_ERROR_NOT_FOUND if the configuration does not exist
|
|
638
638
|
* \returns another LIBUSB_ERROR code on error
|
|
639
639
|
* \see libusb_get_active_config_descriptor()
|
|
640
640
|
* \see libusb_get_config_descriptor()
|
|
@@ -699,7 +699,7 @@ void API_EXPORTED libusb_free_config_descriptor(
|
|
|
699
699
|
* descriptor. Only valid if 0 was returned. Must be freed with
|
|
700
700
|
* libusb_free_ss_endpoint_companion_descriptor() after use.
|
|
701
701
|
* \returns 0 on success
|
|
702
|
-
* \returns LIBUSB_ERROR_NOT_FOUND if the configuration does not exist
|
|
702
|
+
* \returns \ref LIBUSB_ERROR_NOT_FOUND if the configuration does not exist
|
|
703
703
|
* \returns another LIBUSB_ERROR code on error
|
|
704
704
|
*/
|
|
705
705
|
int API_EXPORTED libusb_get_ss_endpoint_companion_descriptor(
|
|
@@ -840,7 +840,7 @@ static int parse_bos(struct libusb_context *ctx,
|
|
|
840
840
|
* \param bos output location for the BOS descriptor. Only valid if 0 was returned.
|
|
841
841
|
* Must be freed with \ref libusb_free_bos_descriptor() after use.
|
|
842
842
|
* \returns 0 on success
|
|
843
|
-
* \returns LIBUSB_ERROR_NOT_FOUND if the device doesn't have a BOS descriptor
|
|
843
|
+
* \returns \ref LIBUSB_ERROR_NOT_FOUND if the device doesn't have a BOS descriptor
|
|
844
844
|
* \returns another LIBUSB_ERROR code on error
|
|
845
845
|
*/
|
|
846
846
|
int API_EXPORTED libusb_get_bos_descriptor(libusb_device_handle *dev_handle,
|
|
@@ -1070,6 +1070,70 @@ void API_EXPORTED libusb_free_container_id_descriptor(
|
|
|
1070
1070
|
free(container_id);
|
|
1071
1071
|
}
|
|
1072
1072
|
|
|
1073
|
+
/** \ingroup libusb_desc
|
|
1074
|
+
* Get a platform descriptor
|
|
1075
|
+
*
|
|
1076
|
+
* Since version 1.0.27, \ref LIBUSB_API_VERSION >= 0x0100010A
|
|
1077
|
+
*
|
|
1078
|
+
* \param ctx the context to operate on, or NULL for the default context
|
|
1079
|
+
* \param dev_cap Device Capability descriptor with a bDevCapabilityType of
|
|
1080
|
+
* \ref libusb_capability_type::LIBUSB_BT_PLATFORM_DESCRIPTOR
|
|
1081
|
+
* LIBUSB_BT_PLATFORM_DESCRIPTOR
|
|
1082
|
+
* \param platform_descriptor output location for the Platform descriptor.
|
|
1083
|
+
* Only valid if 0 was returned. Must be freed with
|
|
1084
|
+
* libusb_free_platform_descriptor() after use.
|
|
1085
|
+
* \returns 0 on success
|
|
1086
|
+
* \returns a LIBUSB_ERROR code on error
|
|
1087
|
+
*/
|
|
1088
|
+
int API_EXPORTED libusb_get_platform_descriptor(libusb_context *ctx,
|
|
1089
|
+
struct libusb_bos_dev_capability_descriptor *dev_cap,
|
|
1090
|
+
struct libusb_platform_descriptor **platform_descriptor)
|
|
1091
|
+
{
|
|
1092
|
+
struct libusb_platform_descriptor *_platform_descriptor;
|
|
1093
|
+
|
|
1094
|
+
if (dev_cap->bDevCapabilityType != LIBUSB_BT_PLATFORM_DESCRIPTOR) {
|
|
1095
|
+
usbi_err(ctx, "unexpected bDevCapabilityType 0x%x (expected 0x%x)",
|
|
1096
|
+
dev_cap->bDevCapabilityType,
|
|
1097
|
+
LIBUSB_BT_PLATFORM_DESCRIPTOR);
|
|
1098
|
+
return LIBUSB_ERROR_INVALID_PARAM;
|
|
1099
|
+
} else if (dev_cap->bLength < LIBUSB_BT_PLATFORM_DESCRIPTOR_MIN_SIZE) {
|
|
1100
|
+
usbi_err(ctx, "short dev-cap descriptor read %u/%d",
|
|
1101
|
+
dev_cap->bLength, LIBUSB_BT_PLATFORM_DESCRIPTOR_MIN_SIZE);
|
|
1102
|
+
return LIBUSB_ERROR_IO;
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
_platform_descriptor = malloc(dev_cap->bLength);
|
|
1106
|
+
if (!_platform_descriptor)
|
|
1107
|
+
return LIBUSB_ERROR_NO_MEM;
|
|
1108
|
+
|
|
1109
|
+
parse_descriptor(dev_cap, "bbbbu", _platform_descriptor);
|
|
1110
|
+
|
|
1111
|
+
/* Capability data is located after reserved byte and 128-bit UUID */
|
|
1112
|
+
uint8_t* capability_data = dev_cap->dev_capability_data + 1 + 16;
|
|
1113
|
+
|
|
1114
|
+
/* Capability data length is total descriptor length minus initial fields */
|
|
1115
|
+
size_t capability_data_length = _platform_descriptor->bLength - (16 + 4);
|
|
1116
|
+
|
|
1117
|
+
memcpy(_platform_descriptor->CapabilityData, capability_data, capability_data_length);
|
|
1118
|
+
|
|
1119
|
+
*platform_descriptor = _platform_descriptor;
|
|
1120
|
+
return LIBUSB_SUCCESS;
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
/** \ingroup libusb_desc
|
|
1124
|
+
* Free a platform descriptor obtained from
|
|
1125
|
+
* libusb_get_platform_descriptor().
|
|
1126
|
+
* It is safe to call this function with a NULL platform_descriptor parameter,
|
|
1127
|
+
* in which case the function simply returns.
|
|
1128
|
+
*
|
|
1129
|
+
* \param platform_descriptor the Platform descriptor to free
|
|
1130
|
+
*/
|
|
1131
|
+
void API_EXPORTED libusb_free_platform_descriptor(
|
|
1132
|
+
struct libusb_platform_descriptor *platform_descriptor)
|
|
1133
|
+
{
|
|
1134
|
+
free(platform_descriptor);
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1073
1137
|
/** \ingroup libusb_desc
|
|
1074
1138
|
* Retrieve a string descriptor in C style ASCII.
|
|
1075
1139
|
*
|
|
@@ -1086,7 +1150,7 @@ int API_EXPORTED libusb_get_string_descriptor_ascii(libusb_device_handle *dev_ha
|
|
|
1086
1150
|
uint8_t desc_index, unsigned char *data, int length)
|
|
1087
1151
|
{
|
|
1088
1152
|
union usbi_string_desc_buf str;
|
|
1089
|
-
int r
|
|
1153
|
+
int r;
|
|
1090
1154
|
uint16_t langid, wdata;
|
|
1091
1155
|
|
|
1092
1156
|
/* Asking for the zero'th index is special - it returns a string
|
|
@@ -1122,18 +1186,214 @@ int API_EXPORTED libusb_get_string_descriptor_ascii(libusb_device_handle *dev_ha
|
|
|
1122
1186
|
else if ((str.desc.bLength & 1) || str.desc.bLength != r)
|
|
1123
1187
|
usbi_warn(HANDLE_CTX(dev_handle), "suspicious bLength %u for string descriptor (read %d)", str.desc.bLength, r);
|
|
1124
1188
|
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1189
|
+
/* Stop one byte before the end to leave room for null termination. */
|
|
1190
|
+
int dest_max = length - 1;
|
|
1191
|
+
|
|
1192
|
+
/* The descriptor has this number of wide characters */
|
|
1193
|
+
int src_max = (str.desc.bLength - 1 - 1) / 2;
|
|
1129
1194
|
|
|
1130
|
-
|
|
1195
|
+
/* Neither read nor write more than the smallest buffer */
|
|
1196
|
+
int idx_max = MIN(dest_max, src_max);
|
|
1197
|
+
|
|
1198
|
+
int idx;
|
|
1199
|
+
for (idx = 0; idx < idx_max; ++idx) {
|
|
1200
|
+
wdata = libusb_le16_to_cpu(str.desc.wData[idx]);
|
|
1131
1201
|
if (wdata < 0x80)
|
|
1132
|
-
data[
|
|
1202
|
+
data[idx] = (unsigned char)wdata;
|
|
1133
1203
|
else
|
|
1134
|
-
data[
|
|
1204
|
+
data[idx] = '?'; /* non-ASCII */
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1207
|
+
data[idx] = 0; /* null-terminate string */
|
|
1208
|
+
return idx;
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
static int parse_iad_array(struct libusb_context *ctx,
|
|
1212
|
+
struct libusb_interface_association_descriptor_array *iad_array,
|
|
1213
|
+
const uint8_t *buffer, int size)
|
|
1214
|
+
{
|
|
1215
|
+
uint8_t i;
|
|
1216
|
+
struct usbi_descriptor_header header;
|
|
1217
|
+
int consumed = 0;
|
|
1218
|
+
const uint8_t *buf = buffer;
|
|
1219
|
+
struct libusb_interface_association_descriptor *iad;
|
|
1220
|
+
|
|
1221
|
+
if (size < LIBUSB_DT_CONFIG_SIZE) {
|
|
1222
|
+
usbi_err(ctx, "short config descriptor read %d/%d",
|
|
1223
|
+
size, LIBUSB_DT_CONFIG_SIZE);
|
|
1224
|
+
return LIBUSB_ERROR_IO;
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
// First pass: Iterate through desc list, count number of IADs
|
|
1228
|
+
iad_array->length = 0;
|
|
1229
|
+
while (consumed < size) {
|
|
1230
|
+
parse_descriptor(buf, "bb", &header);
|
|
1231
|
+
if (header.bLength < 2) {
|
|
1232
|
+
usbi_err(ctx, "invalid descriptor bLength %d",
|
|
1233
|
+
header.bLength);
|
|
1234
|
+
return LIBUSB_ERROR_IO;
|
|
1235
|
+
}
|
|
1236
|
+
if (header.bDescriptorType == LIBUSB_DT_INTERFACE_ASSOCIATION)
|
|
1237
|
+
iad_array->length++;
|
|
1238
|
+
buf += header.bLength;
|
|
1239
|
+
consumed += header.bLength;
|
|
1240
|
+
}
|
|
1241
|
+
|
|
1242
|
+
iad_array->iad = NULL;
|
|
1243
|
+
if (iad_array->length > 0) {
|
|
1244
|
+
iad = calloc(iad_array->length, sizeof(*iad));
|
|
1245
|
+
if (!iad)
|
|
1246
|
+
return LIBUSB_ERROR_NO_MEM;
|
|
1247
|
+
|
|
1248
|
+
iad_array->iad = iad;
|
|
1249
|
+
|
|
1250
|
+
// Second pass: Iterate through desc list, fill IAD structures
|
|
1251
|
+
consumed = 0;
|
|
1252
|
+
i = 0;
|
|
1253
|
+
while (consumed < size) {
|
|
1254
|
+
parse_descriptor(buffer, "bb", &header);
|
|
1255
|
+
if (header.bDescriptorType == LIBUSB_DT_INTERFACE_ASSOCIATION)
|
|
1256
|
+
parse_descriptor(buffer, "bbbbbbbb", &iad[i++]);
|
|
1257
|
+
buffer += header.bLength;
|
|
1258
|
+
consumed += header.bLength;
|
|
1259
|
+
}
|
|
1135
1260
|
}
|
|
1136
1261
|
|
|
1137
|
-
|
|
1138
|
-
|
|
1262
|
+
return LIBUSB_SUCCESS;
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1265
|
+
static int raw_desc_to_iad_array(struct libusb_context *ctx, const uint8_t *buf,
|
|
1266
|
+
int size, struct libusb_interface_association_descriptor_array **iad_array)
|
|
1267
|
+
{
|
|
1268
|
+
struct libusb_interface_association_descriptor_array *_iad_array
|
|
1269
|
+
= calloc(1, sizeof(*_iad_array));
|
|
1270
|
+
int r;
|
|
1271
|
+
|
|
1272
|
+
if (!_iad_array)
|
|
1273
|
+
return LIBUSB_ERROR_NO_MEM;
|
|
1274
|
+
|
|
1275
|
+
r = parse_iad_array(ctx, _iad_array, buf, size);
|
|
1276
|
+
if (r < 0) {
|
|
1277
|
+
usbi_err(ctx, "parse_iad_array failed with error %d", r);
|
|
1278
|
+
free(_iad_array);
|
|
1279
|
+
return r;
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
*iad_array = _iad_array;
|
|
1283
|
+
return LIBUSB_SUCCESS;
|
|
1284
|
+
}
|
|
1285
|
+
|
|
1286
|
+
/** \ingroup libusb_desc
|
|
1287
|
+
* Get an array of interface association descriptors (IAD) for a given
|
|
1288
|
+
* configuration.
|
|
1289
|
+
* This is a non-blocking function which does not involve any requests being
|
|
1290
|
+
* sent to the device.
|
|
1291
|
+
*
|
|
1292
|
+
* \param dev a device
|
|
1293
|
+
* \param config_index the index of the configuration you wish to retrieve the
|
|
1294
|
+
* IADs for.
|
|
1295
|
+
* \param iad_array output location for the array of IADs. Only valid if 0 was
|
|
1296
|
+
* returned. Must be freed with libusb_free_interface_association_descriptors()
|
|
1297
|
+
* after use. It's possible that a given configuration contains no IADs. In this
|
|
1298
|
+
* case the iad_array is still output, but will have 'length' field set to 0, and
|
|
1299
|
+
* iad field set to NULL.
|
|
1300
|
+
* \returns 0 on success
|
|
1301
|
+
* \returns LIBUSB_ERROR_NOT_FOUND if the configuration does not exist
|
|
1302
|
+
* \returns another LIBUSB_ERROR code on error
|
|
1303
|
+
* \see libusb_get_active_interface_association_descriptors()
|
|
1304
|
+
*/
|
|
1305
|
+
int API_EXPORTED libusb_get_interface_association_descriptors(libusb_device *dev,
|
|
1306
|
+
uint8_t config_index, struct libusb_interface_association_descriptor_array **iad_array)
|
|
1307
|
+
{
|
|
1308
|
+
union usbi_config_desc_buf _config;
|
|
1309
|
+
uint16_t config_len;
|
|
1310
|
+
uint8_t *buf;
|
|
1311
|
+
int r;
|
|
1312
|
+
|
|
1313
|
+
if (!iad_array)
|
|
1314
|
+
return LIBUSB_ERROR_INVALID_PARAM;
|
|
1315
|
+
|
|
1316
|
+
usbi_dbg(DEVICE_CTX(dev), "IADs for config index %u", config_index);
|
|
1317
|
+
if (config_index >= dev->device_descriptor.bNumConfigurations)
|
|
1318
|
+
return LIBUSB_ERROR_NOT_FOUND;
|
|
1319
|
+
|
|
1320
|
+
r = get_config_descriptor(dev, config_index, _config.buf, sizeof(_config.buf));
|
|
1321
|
+
if (r < 0)
|
|
1322
|
+
return r;
|
|
1323
|
+
|
|
1324
|
+
config_len = libusb_le16_to_cpu(_config.desc.wTotalLength);
|
|
1325
|
+
buf = malloc(config_len);
|
|
1326
|
+
if (!buf)
|
|
1327
|
+
return LIBUSB_ERROR_NO_MEM;
|
|
1328
|
+
|
|
1329
|
+
r = get_config_descriptor(dev, config_index, buf, config_len);
|
|
1330
|
+
if (r >= 0)
|
|
1331
|
+
r = raw_desc_to_iad_array(DEVICE_CTX(dev), buf, r, iad_array);
|
|
1332
|
+
|
|
1333
|
+
free(buf);
|
|
1334
|
+
return r;
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
/** \ingroup libusb_desc
|
|
1338
|
+
* Get an array of interface association descriptors (IAD) for the currently
|
|
1339
|
+
* active configuration.
|
|
1340
|
+
* This is a non-blocking function which does not involve any requests being
|
|
1341
|
+
* sent to the device.
|
|
1342
|
+
*
|
|
1343
|
+
* \param dev a device
|
|
1344
|
+
* \param iad_array output location for the array of IADs. Only valid if 0 was
|
|
1345
|
+
* returned. Must be freed with libusb_free_interface_association_descriptors()
|
|
1346
|
+
* after use. It's possible that a given configuration contains no IADs. In this
|
|
1347
|
+
* case the iad_array is still output, but will have 'length' field set to 0, and
|
|
1348
|
+
* iad field set to NULL.
|
|
1349
|
+
* \returns 0 on success
|
|
1350
|
+
* \returns LIBUSB_ERROR_NOT_FOUND if the device is in unconfigured state
|
|
1351
|
+
* \returns another LIBUSB_ERROR code on error
|
|
1352
|
+
* \see libusb_get_interface_association_descriptors
|
|
1353
|
+
*/
|
|
1354
|
+
int API_EXPORTED libusb_get_active_interface_association_descriptors(libusb_device *dev,
|
|
1355
|
+
struct libusb_interface_association_descriptor_array **iad_array)
|
|
1356
|
+
{
|
|
1357
|
+
union usbi_config_desc_buf _config;
|
|
1358
|
+
uint16_t config_len;
|
|
1359
|
+
uint8_t *buf;
|
|
1360
|
+
int r;
|
|
1361
|
+
|
|
1362
|
+
if (!iad_array)
|
|
1363
|
+
return LIBUSB_ERROR_INVALID_PARAM;
|
|
1364
|
+
|
|
1365
|
+
r = get_active_config_descriptor(dev, _config.buf, sizeof(_config.buf));
|
|
1366
|
+
if (r < 0)
|
|
1367
|
+
return r;
|
|
1368
|
+
|
|
1369
|
+
config_len = libusb_le16_to_cpu(_config.desc.wTotalLength);
|
|
1370
|
+
buf = malloc(config_len);
|
|
1371
|
+
if (!buf)
|
|
1372
|
+
return LIBUSB_ERROR_NO_MEM;
|
|
1373
|
+
|
|
1374
|
+
r = get_active_config_descriptor(dev, buf, config_len);
|
|
1375
|
+
if (r >= 0)
|
|
1376
|
+
r = raw_desc_to_iad_array(DEVICE_CTX(dev), buf, r, iad_array);
|
|
1377
|
+
free(buf);
|
|
1378
|
+
return r;
|
|
1379
|
+
}
|
|
1380
|
+
|
|
1381
|
+
/** \ingroup libusb_desc
|
|
1382
|
+
* Free an array of interface association descriptors (IADs) obtained from
|
|
1383
|
+
* libusb_get_interface_association_descriptors() or
|
|
1384
|
+
* libusb_get_active_interface_association_descriptors().
|
|
1385
|
+
* It is safe to call this function with a NULL iad_array parameter, in which
|
|
1386
|
+
* case the function simply returns.
|
|
1387
|
+
*
|
|
1388
|
+
* \param iad_array the IAD array to free
|
|
1389
|
+
*/
|
|
1390
|
+
void API_EXPORTED libusb_free_interface_association_descriptors(
|
|
1391
|
+
struct libusb_interface_association_descriptor_array *iad_array)
|
|
1392
|
+
{
|
|
1393
|
+
if (!iad_array)
|
|
1394
|
+
return;
|
|
1395
|
+
|
|
1396
|
+
if (iad_array->iad)
|
|
1397
|
+
free((void*)iad_array->iad);
|
|
1398
|
+
free(iad_array);
|
|
1139
1399
|
}
|
package/libusb/libusb/hotplug.c
CHANGED
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
*
|
|
34
34
|
* \section hotplug_intro Introduction
|
|
35
35
|
*
|
|
36
|
-
* Version 1.0.16, \ref
|
|
36
|
+
* Version 1.0.16, \ref LIBUSBX_API_VERSION >= 0x01000102, has added support
|
|
37
37
|
* for hotplug events on <b>some</b> platforms (you should test if your platform
|
|
38
38
|
* supports hotplug notification by calling \ref libusb_has_capability() with
|
|
39
39
|
* parameter \ref LIBUSB_CAP_HAS_HOTPLUG).
|
|
@@ -117,7 +117,7 @@ int main (void) {
|
|
|
117
117
|
libusb_hotplug_callback_handle callback_handle;
|
|
118
118
|
int rc;
|
|
119
119
|
|
|
120
|
-
|
|
120
|
+
libusb_init_context(NULL, NULL, 0);
|
|
121
121
|
|
|
122
122
|
rc = libusb_hotplug_register_callback(NULL, LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED |
|
|
123
123
|
LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT, 0, 0x045a, 0x5005,
|
|
@@ -311,7 +311,7 @@ void usbi_hotplug_process(struct libusb_context *ctx, struct list_head *hotplug_
|
|
|
311
311
|
for_each_hotplug_cb_safe(ctx, hotplug_cb, next_cb) {
|
|
312
312
|
if (hotplug_cb->flags & USBI_HOTPLUG_NEEDS_FREE) {
|
|
313
313
|
usbi_dbg(ctx, "freeing hotplug cb %p with handle %d",
|
|
314
|
-
|
|
314
|
+
(void *) hotplug_cb, hotplug_cb->handle);
|
|
315
315
|
list_del(&hotplug_cb->list);
|
|
316
316
|
free(hotplug_cb);
|
|
317
317
|
}
|
|
@@ -377,7 +377,8 @@ int API_EXPORTED libusb_hotplug_register_callback(libusb_context *ctx,
|
|
|
377
377
|
|
|
378
378
|
usbi_mutex_unlock(&ctx->hotplug_cbs_lock);
|
|
379
379
|
|
|
380
|
-
usbi_dbg(ctx, "new hotplug cb %p with handle %d",
|
|
380
|
+
usbi_dbg(ctx, "new hotplug cb %p with handle %d",
|
|
381
|
+
(void *) hotplug_cb, hotplug_cb->handle);
|
|
381
382
|
|
|
382
383
|
if ((flags & LIBUSB_HOTPLUG_ENUMERATE) && (events & LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED)) {
|
|
383
384
|
ssize_t i, len;
|