aboutsummaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2022-03-16linux_usbfs: Fix maybe-uninitialized error with -O3Yegor Yefremov
Initialize active_config to an invalid value to avoid the following compilation error: os/linux_usbfs.c: In function ‘op_get_configuration’: os/linux_usbfs.c:1452:12: error: ‘active_config’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 1452 | *config = (uint8_t)active_config; Closes #1062 Closes #1063 Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
2022-03-16configure.ac: link with -latomic if neededFabrice Fontaine
libusb unconditionally uses atomic_fetch_add since version 1.0.25 and commit 1a08aa8 and commit eed8a37 but some architectures (e.g. sparc) needs to link with -latomic to be able to use it. So check if -latomic is needed and update libusb-1.0.pc accordingly to avoid the following build failure with openocd: /home/buildroot/autobuild/instance-0/output-1/host/opt/ext-toolchain/bin/../lib/gcc/sparc-buildroot-linux-uclibc/10.3.0/../../../../sparc-buildroot-linux-uclibc/bin/ld: /home/buildroot/autobuild/instance-0/output-1/host/sparc-buildroot-linux-uclibc/sysroot/usr/lib/libusb-1.0.so: undefined reference to `__atomic_fetch_add_4' collect2: error: ld returned 1 exit status Full build log: http://autobuild.buildroot.org/results/4a27a769bb3cdf78643c3049b87d792178d6512c Closes #1064 Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
2022-03-16core: Suppress hotplug events during initial enumerationBenjamin Berg
The initial enumeration should not result in hotplug events to be fired. This is just a convenience though, API users still need to be prepared to be notified a second time for a device that was plugged in between libusb_init and libusb_hotplug_register_callback. This regressed with commit 6929b82 ("Fix segmentation fault in libusb_init() if usbi_backend.init() fails"). This commit avoids the mentioned segmentation fault by avoiding to clean up the hotplug code if it was not yet initialised. Fixes #1082 Closes #1090 References #989
2022-03-16io: Track device in usbi_transferBenjamin Berg
transfer->dev_handle currently has the behaviour that it will be unset if the device is closed. The sync API uses this fact to catch an error case. In other cases, transfer->dev_handle will keep its value, which means that if the transfer lives longer than the device handle, the pointer becomes invalid. The transfer does however keep a reference to the device, which owns the pointer to the context. As such, we can track this reference internal to the transfer, and it is set while the transfer is in-flight. With this, switch the logging infrastructure to use itransfer->dev->ctx while checking that itransfer->dev is non-NULL. Note that this was a regression caused by 6cae9c6 ("core: update usbi_dbg to take the context as an argument"), specifically when resolving the context while freeing a transfer after closing a device. Note that the transfer will now keep a reference to the device until it is free'ed. This allows it to use the correct context for logging even in libusb_free_transfer. The alternative to all this would be to just explicitly pass NULL to the log handler in libusb_free_transfer. Fixes #1038 Closes #1073
2022-03-15Merge "Tweak linux_glibc properties for musl builds in external/libusb" am: ↵Colin Cross
596772ba2a am: 87c8958af7 am: 499ca85135 am: 5304cf842b am: 5f77e509fc Original change: https://android-review.googlesource.com/c/platform/external/libusb/+/2018607 Change-Id: Icf13992b767e6506601a902bf17353f3544427f5
2022-03-15Merge "Tweak linux_glibc properties for musl builds in external/libusb" am: ↵aml_tz4_332714070aml_tz4_332714050aml_tz4_332714010aml_tz4_331910000aml_tz4_331314030aml_tz4_331314020aml_tz4_331314010aml_tz4_331012050aml_tz4_331012040aml_tz4_331012000aml_ase_331311020aml_ase_331112000aml_ase_331011020android13-mainline-tzdata4-releaseandroid13-mainline-appsearch-releaseaml_tz4_332714010Colin Cross
596772ba2a am: 87c8958af7 am: 499ca85135 am: 5304cf842b Original change: https://android-review.googlesource.com/c/platform/external/libusb/+/2018607 Change-Id: I97f3bb06876d25386f278b9de756a27631619a4b
2022-03-15Merge "Tweak linux_glibc properties for musl builds in external/libusb" am: ↵Colin Cross
596772ba2a am: 87c8958af7 am: 499ca85135 am: 5304cf842b Original change: https://android-review.googlesource.com/c/platform/external/libusb/+/2018607 Change-Id: Id518ad52938c1726c6dfccaf965c4ad81efc8beb
2022-03-15Merge "Tweak linux_glibc properties for musl builds in external/libusb" am: ↵t_frc_odp_330442040t_frc_odp_330442000t_frc_ase_330444010android-t-qpr3-beta-3-gplandroid-t-qpr3-beta-1-gplandroid-t-qpr2-beta-3-gplandroid-t-qpr2-beta-2-gplandroid-13.0.0_r83android-13.0.0_r82android-13.0.0_r81android-13.0.0_r80android-13.0.0_r79android-13.0.0_r78android-13.0.0_r77android-13.0.0_r76android-13.0.0_r75android-13.0.0_r74android-13.0.0_r73android-13.0.0_r72android-13.0.0_r71android-13.0.0_r70android-13.0.0_r69android-13.0.0_r68android-13.0.0_r67android-13.0.0_r66android-13.0.0_r65android-13.0.0_r64android-13.0.0_r63android-13.0.0_r62android-13.0.0_r61android-13.0.0_r60android-13.0.0_r59android-13.0.0_r58android-13.0.0_r57android-13.0.0_r56android-13.0.0_r54android-13.0.0_r53android-13.0.0_r52android-13.0.0_r51android-13.0.0_r50android-13.0.0_r49android-13.0.0_r48android-13.0.0_r47android-13.0.0_r46android-13.0.0_r45android-13.0.0_r44android-13.0.0_r43android-13.0.0_r42android-13.0.0_r41android-13.0.0_r40android-13.0.0_r39android-13.0.0_r38android-13.0.0_r37android-13.0.0_r36android-13.0.0_r35android-13.0.0_r34android-13.0.0_r33android-13.0.0_r32aml_go_odp_330912000aml_go_ads_330915100aml_go_ads_330915000aml_go_ads_330913000android13-qpr3-s9-releaseandroid13-qpr3-s8-releaseandroid13-qpr3-s7-releaseandroid13-qpr3-s6-releaseandroid13-qpr3-s5-releaseandroid13-qpr3-s4-releaseandroid13-qpr3-s3-releaseandroid13-qpr3-s2-releaseandroid13-qpr3-s14-releaseandroid13-qpr3-s13-releaseandroid13-qpr3-s12-releaseandroid13-qpr3-s11-releaseandroid13-qpr3-s10-releaseandroid13-qpr3-s1-releaseandroid13-qpr3-releaseandroid13-qpr3-c-s8-releaseandroid13-qpr3-c-s7-releaseandroid13-qpr3-c-s6-releaseandroid13-qpr3-c-s5-releaseandroid13-qpr3-c-s4-releaseandroid13-qpr3-c-s3-releaseandroid13-qpr3-c-s2-releaseandroid13-qpr3-c-s12-releaseandroid13-qpr3-c-s11-releaseandroid13-qpr3-c-s10-releaseandroid13-qpr3-c-s1-releaseandroid13-qpr2-s9-releaseandroid13-qpr2-s8-releaseandroid13-qpr2-s7-releaseandroid13-qpr2-s6-releaseandroid13-qpr2-s5-releaseandroid13-qpr2-s3-releaseandroid13-qpr2-s2-releaseandroid13-qpr2-s12-releaseandroid13-qpr2-s11-releaseandroid13-qpr2-s10-releaseandroid13-qpr2-s1-releaseandroid13-qpr2-releaseandroid13-qpr2-b-s1-releaseandroid13-mainline-go-adservices-releaseandroid13-frc-odp-releaseandroid13-devandroid13-d4-s2-releaseandroid13-d4-s1-releaseandroid13-d4-releaseandroid13-d3-s1-releaseColin Cross
596772ba2a am: 87c8958af7 am: 499ca85135 Original change: https://android-review.googlesource.com/c/platform/external/libusb/+/2018607 Change-Id: Id68d6afa6caf43c780522ffc601ed9177a6feffd
2022-03-15Merge "Tweak linux_glibc properties for musl builds in external/libusb" am: ↵Colin Cross
596772ba2a am: 87c8958af7 Original change: https://android-review.googlesource.com/c/platform/external/libusb/+/2018607 Change-Id: I0b12f29b01fc1b633b337944c36bbcdcf62f57d7
2022-03-15Merge "Tweak linux_glibc properties for musl builds in external/libusb" am: ↵Colin Cross
596772ba2a Original change: https://android-review.googlesource.com/c/platform/external/libusb/+/2018607 Change-Id: I2a3fc5291eccc81317fa6486987d2339142476af
2022-03-15Merge "Tweak linux_glibc properties for musl builds in external/libusb"Colin Cross
2022-03-15core: Unset device ctx if it has been destroyedBenjamin Berg
Devices can outlive their context in some cases (in particular with python garbage collection). Guard against this by clearing the ctx pointer so that it is not pointing to uninitialized memory. Closes #1058
2022-03-08Tweak linux_glibc properties for musl builds in external/libusbColin Cross
For convenience, builds against musl libc currently use the linux_glibc properties because they are almost always linux-specific and not glibc-specific. In preparation for removing this hack, tweak the linux_glibc properties by either moving them to host_linux, which will apply to linux_glibc, linux_musl and linux_bionic, or by setting appropriate musl or linux_musl properties. Properties that must not be repeated while musl uses linux_musl and also still uses the linux_glibc properties are moved to glibc properties, which don't apply to musl. Whether these stay as glibc properties or get moved back to linux_glibc later once the musl hack is removed is TBD. Bug: 223257095 Test: m checkbuild Test: m USE_HOST_MUSL=true host-native Change-Id: Ifc78a0294bd34146aa352064e071c8a7e0322e42
2022-01-31libusb 1.0.25Tormod Volden
Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2022-01-30appveyor: Retain selected build artifactsTormod Volden
Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2022-01-22examples: Do not assume positive errno macrosTormod Volden
Some functions were returning e.g. -ENOMEM and the caller would check for negative return values. However, on Haiku, contrary to modern standards, these macros are negative, so this logic would fail. In any case, change the function to return -1 instead. For good measure also set errno to the appropriate value, although it is not used in the current code. This was discovered on Haiku builds because the value for ENOMEM is INT_MIN which cannot be negated without overflow. Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2022-01-22netbsd: Fix typo preventing buildTormod Volden
Fixup of commit 6cae9c6 Tested-by: Xiaofan Chen <xiaofanc@gmail.com> Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2022-01-21libusb 1.0.25-rc1Tormod Volden
Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2022-01-21Add libusb_set_option to libusb-1.0.def manuallyTormod Volden
Since libusb_set_option() is variadic, there is no symbol for it with @ appended in the DLL, and the automatic generation of libusb-1.0.def misses it. Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2022-01-21Update AUTHORSTormod Volden
Based on `git shortlog -s | cut -c8-` and a lot of manual fixups. Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2022-01-21Update libusb-1.0.defTormod Volden
Updated by running the following on a libusb-1.0 DLL generated by MinGW32: echo -e "LIBRARY \"libusb-1.0.dll\"\nEXPORTS" > libusb-1.0.def strings libusb-1.0.dll | grep ^libusb | grep @ | LC_ALL=C sort | uniq | \ sed -e "s/\(.*\)@\([0-9]*\)/ \1\n \1@\2 = \1/" | LC_ALL=C sort >> libusb-1.0.def Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2022-01-20Add github action for macOSLudovic Rousseau
Signed-off-by: Ludovic Rousseau <ludovic.rousseau@free.fr>
2022-01-20Add github action for GNU/LinuxLudovic Rousseau
Signed-off-by: Ludovic Rousseau <ludovic.rousseau@free.fr>
2022-01-18The current code for calculating the timeout in ↵Andrew Goodney
darwin_reenumerate_device_timeout() doesn't calculate elapsed microseconds, it counts the number of times the loop runs. This results in very long timeouts. This PR uses clock_gettime(CLOCK_MONOTONIC, ...) to calculate the elapsed time Closes #1035 Signed-off-by: Nathan Hjelm <hjelmn@google.com>
2021-12-01darwin: Minor tidy up in darwin_set_interface_altsetting()Tormod Volden
Closes #1032 Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2021-12-01darwin: fix behavior of libusb_set_interface_alt_setting when it stalls the pipeNathan Hjelm
In some versions of macOS a pipe stall returned when setting the alternate interface causes the interface to become unusable. To handle this case the backend was always re-claiming the interface before clearing the pipe stall. In macOS Monterey unconditionally re-claiming the interface leads to an error due to the process already having exclusive access. To resolve this issue we attempt to clear the halt and only re-claim the interface if clearing the pipe stall returns kIOUSBUnknownPipeErr. Tested with 12.0.1 and 10.13 and get the expected results in both cases with a custom USB device that has this behavior. Fixes #1011 Closes #1031 Signed-off-by: Nathan Hjelm <hjelmn@google.com>
2021-11-27Bump LIBUSB_API_VERSIONTormod Volden
LIBUSB_OPTION_NO_DEVICE_DISCOVERY is new. Closes #1004 Signed-off-by: Tormod Volden <debian.tormod@gmail.com> Signed-off-by: Nathan Hjelm <hjelmn@me.com>
2021-11-27Keep LIBUSB_OPTION_WEAK_AUTHORITY as a macro with same valueTormod Volden
If the value is always the same we retain binary compatibility. References #935 Signed-off-by: Tormod Volden <debian.tormod@gmail.com> Signed-off-by: Nathan Hjelm <hjelmn@me.com>
2021-11-27Fuzzing: Add CIFuzzAdamKorcz
2021-11-23core: Unlock and clear default ctx in all error paths in libusb_initMatthias Bolte
Commit 32a22069428cda9d63aa666e92fb8882a83d4515 reordered and refactored libusb_init. This resulted in moving code outside the default ctx lock that was unrelated to it. But this resulted in broken error path cleanup logic that leaves the default ctx as locked, half initialized and freed in case a libusb_set_option or the usbi_io_init call fails. Undo part of the previous reordering to unlock and clear the default ctx in all error paths in libusb_init. Closes #995 Signed-off-by: Nathan Hjelm <hjelmn@google.com>
2021-11-09core: Minor code cleanup in libusb_init (NOP)Tormod Volden
After commit f7084fe the if clause would always be true, so remove it. Thanks to "xloem" for reporting. References #942 Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2021-11-09Windows: Allow synchronous control transfers (for libusb0)Tormod Volden
Some of the changes in commit 9c28ad2 rely on all transfers having (or appearing to have) asynchronous completion. However, the libusb0.sys backend of libusbk.dll performs all control transfers synchronously and ignores any "overlapped" structure handed to it. Our asynchronous handling will in this case be pending and eventually time out although the USB request itself was successful. Therefore restore the possibility of synchronous completion of control transfers, by forcing the completion handling on a successful return from request submission. This brings the code closer to how it was established in commit ce95f65. Fixes #94 Tested-by: Xiaofan Chen <xiaofanc@gmail.com> Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2021-11-07Windows: Fix timeouts if only endpoint 0 existsJulian Scheel
The default timeouts of 5 seconds used by WinUSB are cleared in configure_endpoints(). This was not called if not at least one extra endpoint apart from endpoint 0 existed, so that in those cases the default timeout of 5 seconds remained in place. Fix this by calling configure_endpoints, even if no interface specific endpoints were found, so that it can configure endpoint 0. Closes #963 Signed-off-by: Julian Scheel <julian@jusst.de> [Tormod: Refactored to reduce duplicated code] Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2021-11-07Windows: Ignore any device interface GUIDs beyond the firstTormod Volden
The NZXT Kraken Z73 device has been reported to brokenly have two identical device interface GUIDs registered. Accept such cases by treating the ERROR_MORE_DATA return value as success and processing the first returned GUID as if it would be the only one. If one day we see legitimate cases of multiple GUIDs we will need to deal with them properly. References jdkvision/libusb#1 Closes #1010 Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2021-11-07darwin: Fix compilation on macOS 10.9 and earlierEvan Miller
kUSBReEnumerateCaptureDeviceMask was introduced in the 10.10 SDK, so compiling on 10.9 and earlier will fail with: os/darwin_usb.c: In function 'darwin_reenumerate_device': os/darwin_usb.c:1749:18: error: 'kUSBReEnumerateCaptureDeviceMask' undeclared (first use in this function); did you mean 'USBReEnumerateOptions'? options |= kUSBReEnumerateCaptureDeviceMask; ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ USBReEnumerateOptions os/darwin_usb.c:1749:18: note: each undeclared identifier is reported only once for each function it appears in Downstream report: https://trac.macports.org/ticket/63668 Closes #1023
2021-11-02examples: Add example for unrooted AndroidPeter-St
Closes #830
2021-11-01descriptor: Provide more detailed warning if suspicious bLengthTormod Volden
Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2021-11-01doc: Explain default options in libusb_set_option documentationTormod Volden
References #942 Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2021-11-01core: Apply default options to all new contextsBruno Harbulot
The default options configured with libusb_set_option(NULL, ...) were only applied when the default context was created, and were ignored when calling libusb_init() with a non-null context pointer. Make sure the default options will be applied to all new contexts. This is important when using LIBUSB_OPTION_NO_DEVICE_DISCOVERY which must be respected during the context initialization in order to work. Closes #942 [Tormod: amend comments] Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2021-10-31xusb: Print total length of configuration descriptorTormod Volden
Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2021-10-31Fix various typos in docs/commentsluz paz
Found via `codespell -q 3` Closes #1015
2021-10-31xusb: Print configuration descriptor lengthTormod Volden
Also inform about reading OS string descriptor. Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2021-10-30darwin: After last CFRelease of struct field, set it to NULLSean McBride
Other code checks this field for being NULL or not, so NULLing it upon last release seems the right thing to do. I noticed this during code review, I never actually reproduced any problem. Closes #981
2021-10-30doc: Improve comments related to device discovery and hotplugSean McBride
Closes #1013
2021-10-30doc: Update note about LIBUSB_TRANSFER_ADD_ZERO_PACKET availabilityTormod Volden
Closes #1005 Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2021-10-30Windows: Fix ssize_t unconditionally definedPaul Cercueil
The standard procedure to define ssize_t on Windows is to wrap it around a check for the _SSIZE_T_DEFINED macro. If not done, it makes it impossible to use the libusb.h header along with other headers (from other libraries) that also attempt to define ssize_t. Closes #1007 Signed-off-by: Paul Cercueil <paul@crapouillou.net>
2021-10-30Windows: Partial fix for data race in composite_copy_transfer_dataBohdan Tymkiv
This only fixes issue (A): libusb: error [composite_copy_transfer_data] program assertion failed - no function to copy transfer data References #966 Closes #967
2021-10-28darwin: fix deprecation warning about kIOMasterPortDefaultNathan Hjelm
The kIOMasterPortDefault constant has been replaced by kIOMainPortDefault. Both are synonmys for 0. To avoid extra checks on the target macOS release just go ahead and use 0. Signed-off-by: Nathan Hjelm <hjelmn@google.com>
2021-10-28darwin: add support for handling new error code (kUSBHostReturnPipeStalled)Nathan Hjelm
With macOS Monterey Apple started using a new error code to indicate a pipe stall. This new error code needs to be handled both in translation to libusb error codes and when handling errors setting the alt setting. References #1011 Signed-off-by: Nathan Hjelm <hjelmn@google.com>
2021-09-23git hooks: Remove "source" bashismTormod Volden
"source" is not supported in Bourne shell Closes #997 Signed-off-by: Tormod Volden <debian.tormod@gmail.com>