summaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
...
* linux_usbfs: Fix maybe-uninitialized error with -O3Yegor Yefremov2022-03-162-2/+2
| | | | | | | | | | | | | | 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>
* configure.ac: link with -latomic if neededFabrice Fontaine2022-03-162-1/+2
| | | | | | | | | | | | | | | | | | 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>
* core: Suppress hotplug events during initial enumerationBenjamin Berg2022-03-163-3/+7
| | | | | | | | | | | | | | | | 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
* io: Track device in usbi_transferBenjamin Berg2022-03-163-12/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* core: Unset device ctx if it has been destroyedBenjamin Berg2022-03-152-1/+2
| | | | | | | | 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
* libusb 1.0.25v1.0.25Tormod Volden2022-01-313-3/+4
| | | | Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* appveyor: Retain selected build artifactsTormod Volden2022-01-302-1/+9
| | | | Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* examples: Do not assume positive errno macrosTormod Volden2022-01-224-15/+38
| | | | | | | | | | | | | | 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>
* netbsd: Fix typo preventing buildTormod Volden2022-01-222-2/+2
| | | | | | | Fixup of commit 6cae9c6 Tested-by: Xiaofan Chen <xiaofanc@gmail.com> Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* libusb 1.0.25-rc1v1.0.25-rc1Tormod Volden2022-01-213-4/+12
| | | | Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* Add libusb_set_option to libusb-1.0.def manuallyTormod Volden2022-01-212-1/+3
| | | | | | | | 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>
* Update AUTHORSTormod Volden2022-01-212-4/+27
| | | | | | Based on `git shortlog -s | cut -c8-` and a lot of manual fixups. Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* Update libusb-1.0.defTormod Volden2022-01-211-4/+2
| | | | | | | | | | 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>
* Add github action for macOSLudovic Rousseau2022-01-202-1/+37
| | | | Signed-off-by: Ludovic Rousseau <ludovic.rousseau@free.fr>
* Add github action for GNU/LinuxLudovic Rousseau2022-01-202-1/+37
| | | | Signed-off-by: Ludovic Rousseau <ludovic.rousseau@free.fr>
* The current code for calculating the timeout in ↵Andrew Goodney2022-01-182-4/+10
| | | | | | | | | | | | 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>
* darwin: Minor tidy up in darwin_set_interface_altsetting()Tormod Volden2021-12-012-4/+4
| | | | | | Closes #1032 Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* darwin: fix behavior of libusb_set_interface_alt_setting when it stalls the pipeNathan Hjelm2021-12-012-21/+39
| | | | | | | | | | | | | | | | 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>
* Bump LIBUSB_API_VERSIONTormod Volden2021-11-272-2/+2
| | | | | | | | | 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>
* Keep LIBUSB_OPTION_WEAK_AUTHORITY as a macro with same valueTormod Volden2021-11-274-10/+6
| | | | | | | | | 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>
* Fuzzing: Add CIFuzzAdamKorcz2021-11-271-0/+26
|
* core: Unlock and clear default ctx in all error paths in libusb_initMatthias Bolte2021-11-232-10/+9
| | | | | | | | | | | | | | | | 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>
* core: Minor code cleanup in libusb_init (NOP)Tormod Volden2021-11-092-10/+8
| | | | | | | | | | 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>
* Windows: Allow synchronous control transfers (for libusb0)Tormod Volden2021-11-092-3/+5
| | | | | | | | | | | | | | | | | | | | 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>
* Windows: Fix timeouts if only endpoint 0 existsJulian Scheel2021-11-072-16/+12
| | | | | | | | | | | | | | | 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>
* Windows: Ignore any device interface GUIDs beyond the firstTormod Volden2021-11-072-2/+3
| | | | | | | | | | | | | | | 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>
* darwin: Fix compilation on macOS 10.9 and earlierEvan Miller2021-11-072-1/+3
| | | | | | | | | | | | | | | | 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
* examples: Add example for unrooted AndroidPeter-St2021-11-024-1/+357
| | | | Closes #830
* descriptor: Provide more detailed warning if suspicious bLengthTormod Volden2021-11-012-3/+3
| | | | Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* doc: Explain default options in libusb_set_option documentationTormod Volden2021-11-013-3/+7
| | | | | | References #942 Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* core: Apply default options to all new contextsBruno Harbulot2021-11-012-8/+10
| | | | | | | | | | | | | | | 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>
* xusb: Print total length of configuration descriptorTormod Volden2021-10-312-1/+2
| | | | Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* Fix various typos in docs/commentsluz paz2021-10-318-10/+10
| | | | | | Found via `codespell -q 3` Closes #1015
* xusb: Print configuration descriptor lengthTormod Volden2021-10-312-2/+7
| | | | | | Also inform about reading OS string descriptor. Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* darwin: After last CFRelease of struct field, set it to NULLSean McBride2021-10-302-1/+2
| | | | | | | | 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
* doc: Improve comments related to device discovery and hotplugSean McBride2021-10-304-5/+7
| | | | Closes #1013
* doc: Update note about LIBUSB_TRANSFER_ADD_ZERO_PACKET availabilityTormod Volden2021-10-302-2/+3
| | | | | | Closes #1005 Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* Windows: Fix ssize_t unconditionally definedPaul Cercueil2021-10-302-1/+4
| | | | | | | | | | | | | 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>
* Windows: Partial fix for data race in composite_copy_transfer_dataBohdan Tymkiv2021-10-302-13/+6
| | | | | | | | This only fixes issue (A): libusb: error [composite_copy_transfer_data] program assertion failed - no function to copy transfer data References #966 Closes #967
* darwin: fix deprecation warning about kIOMasterPortDefaultNathan Hjelm2021-10-282-5/+8
| | | | | | | | 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>
* darwin: add support for handling new error code (kUSBHostReturnPipeStalled)Nathan Hjelm2021-10-282-2/+10
| | | | | | | | | | 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>
* git hooks: Remove "source" bashismTormod Volden2021-09-233-3/+3
| | | | | | | | "source" is not supported in Bourne shell Closes #997 Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* Update Android ReadmePeter-St2021-09-232-55/+91
| | | | | | | Add another approach for connecting USB devices on Android. References #830 Closes #996
* Fix segmentation fault in libusb_init() if usbi_backend.init() failsAnkur Verma2021-09-232-2/+3
| | | | | | | | | If the backend init fails, the control goes to err_io_exit which tries to clean up hotplug related lists that aren't initialized. Moving hotplug_init before makes sure the lists are valid so if backend init fails they get cleaned up without errors. Closes #989
* Fix comment typosSean McBride2021-09-233-3/+3
| | | | References #981
* Android build name correctionxloem2021-09-234-10/+29
| | | | | | | | Fixes #31 See #143 and #596 for solutions to the whole build system. Closes #971
* Fix Windows HID backend missing bytemcuee2021-09-232-3/+1
| | | | | | | | | | | | | | When the report id is zero, we should indeed skip the first byte of transfer_priv->hid_buffer, since it is not part of the actual report. But the report size should not change. Thanks to Jonas Malaco who has done the investigation in this issue. Reference: Jonas Malaco's comments https://github.com/libusb/libusb/issues/902#issuecomment-810726897 Fixes #902 Fixes #977 Closes #986
* darwin: fix typoNathan Hjelm2021-08-082-2/+2
| | | | Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* darwin: improve the error message on kernel driver detach failureNathan Hjelm2021-08-082-1/+5
| | | | | | | | | | Detaching a kernel driver in macOS requires that either the binary has the com.apple.vm.device-access entitlement or is run with effective UID 0 (root). This commit adds an effective UID check before attempting to capture a device and prints a warning that neither is the user root nor does the binary have the correct entitlement. Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* darwin: fix USB capture for rootNathan Hjelm2021-08-072-16/+15
| | | | | | This commit restores the ability to capture-open a USB device when running as root. Signed-off-by: Nathan Hjelm <hjelmn@google.com>