summaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
* Fix github action warningsHEADmasterLudovic Rousseau2023-05-096-6/+6
| | | | | | | build Node.js 12 actions are deprecated. Please update the following actions to use Node.js 16: actions/checkout@v2. For more information see: https://github.blog/changelog/2022-09-22-github-actions-all-actions-will-begin-running-on-node16-instead-of-node12/. Signed-off-by: Ludovic Rousseau <ludovic.rousseau@free.fr>
* Fix build errors of tests with --enable-debug-logLudovic Rousseau2023-05-093-1/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The errors were: ../../tests/set_option.c:146:31: error: no member named 'debug' in 'struct libusb_context' LIBUSB_EXPECT(==, test_ctx->debug, 4); ~~~~~~~~ ^ ../../tests/set_option.c:74:40: note: expanded from macro 'LIBUSB_EXPECT' int64_t _lhs = (int64_t)(intptr_t)(lhs), _rhs = (int64_t)(intptr_t)(rhs); \ ^~~ ../../tests/set_option.c:152:31: error: no member named 'debug' in 'struct libusb_context' LIBUSB_EXPECT(==, test_ctx->debug, 4); ~~~~~~~~ ^ ../../tests/set_option.c:74:40: note: expanded from macro 'LIBUSB_EXPECT' int64_t _lhs = (int64_t)(intptr_t)(lhs), _rhs = (int64_t)(intptr_t)(rhs); \ ^~~ 2 errors generated. ../../tests/init_context.c:112:31: error: no member named 'debug' in 'struct libusb_context' LIBUSB_EXPECT(==, test_ctx->debug, LIBUSB_LOG_LEVEL_ERROR); ~~~~~~~~ ^ ../../tests/init_context.c:74:40: note: expanded from macro 'LIBUSB_EXPECT' int64_t _lhs = (int64_t)(intptr_t)(lhs), _rhs = (int64_t)(intptr_t)(rhs); \ ^~~ ../../tests/init_context.c:140:31: error: no member named 'log_handler' in 'struct libusb_context' LIBUSB_EXPECT(==, test_ctx->log_handler, test_log_cb); ~~~~~~~~ ^ ../../tests/init_context.c:74:40: note: expanded from macro 'LIBUSB_EXPECT' int64_t _lhs = (int64_t)(intptr_t)(lhs), _rhs = (int64_t)(intptr_t)(rhs); \ ^~~ 2 errors generated. Signed-off-by: Ludovic Rousseau <ludovic.rousseau@free.fr>
* Fix build error with --enable-debug-logLudovic Rousseau2023-05-092-2/+2
| | | | | | | | | The error is: core.c:2451:8: error: no member named 'debug' in 'struct libusb_context' _ctx->debug = LIBUSB_LOG_LEVEL_NONE; ~~~~ ^ Signed-off-by: Ludovic Rousseau <ludovic.rousseau@free.fr>
* Add github action build for --enable-debug-logLudovic Rousseau2023-05-092-1/+5
| | | | Signed-off-by: Ludovic Rousseau <ludovic.rousseau@free.fr>
* Fix #1263 by acquiring the waiters lock while calling transfer callbacks and ↵Niklas Gürtler2023-04-123-4/+12
| | | | | | | | swapping the order of operations in sync_transfer_cb Fixes #1267, #1263 Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* Add support for setting the log callback with ↵Nathan Hjelm2023-04-127-37/+273
| | | | | | | | | | | | | libusb_set_option/libusb_init_context This commit effectively deprecates libusb_set_log_cb by adding support for setting the callback in either libusb_set_option or libusb_init_context. Since the libusb_set_log_cb is already in use we can not easily deprecate it without first incrementing the major version. We may do that in the future. Closes #1265 Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* Do not deprecate libusb_set_debug and libusb_initXiaofan Chen2023-03-122-3/+1
| | | | | | | | | | | These functions are used in a lot of existing downstream code and the deprecation makes -Werror builds fail. It seems reasonable to keep these functions supported at least until a major API overhaul. Closes #990 Closes #1236
* windows: Add USBD_STATUS_STALL_PID to usbd_status translationZeng Guang2023-03-123-1/+3
| | | | | | | The value is returned if "The device returned a stall packet identifier", so translate it to LIBUSB_TRANSFER_STALL. Closes #1257
* threads_posix: Use proper getthrid() for thread ID on OpenBSDBrad Smith2023-03-122-6/+2
| | | | | | | OpenBSD no longer allows syscalls like this: https://lwn.net/Articles/806776/ Closes #1247
* tests/stress_mt: Also run with device enumerationTormod Volden2023-03-122-14/+68
| | | | Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* tests/stress_mt: Add Windows threads supportTormod Volden2023-03-125-16/+147
| | | | | | | | Build the test on all platforms. Closes #1128 Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* tests: Add unit test for libusb_set_optionNathan Hjelm2023-03-125-3/+275
| | | | | | | | | | | | | | | | The behavior of libusb_set_option was not matching the documentation when the log level was set in the environment. This has been fixed but a regression test is needed to ensure the behavior does not deviate. This commit adds a set of unit tests to cover some of the functionality of libusb_set_option. Closes #1245 Signed-off-by: Nathan Hjelm <hjelmn@google.com> [Xiaofan: Add Windows setenv/unsetenv wrappers] Signed-off-by: Xiaofan Chen <xiaofanc@gmail.com> [Tormod: Fix test_no_discovery() build on Linux, add msvc build] Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* libusb_set_options: Adjust semantics of libusb_set_option for log levelNathan Hjelm2023-03-122-7/+7
| | | | | | | | | | | | This commit updates the actual semantics of: libusb_set_option(_, LIBUSB_OPTION_LOG_LEVEL, _) to match the documentation. The documentation states that if the LIBUSB_DEBUG environment variable is set then that level overrides the value set by libusb_set_option. Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* xusb: Improve Max LUN retrieval stall handlingTormod Volden2023-01-282-4/+7
| | | | | | | | | | | | Do not show an uninitialized Max LUN value if the pipe stalled. As suggested by the code comment (but not the old code), set a default zero value only on pipe stall. On other errors simply error out. References #1181 Closes #1239 Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* xusb: Improve kernel driver probe messagesTormod Volden2023-01-282-4/+17
| | | | Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* CI: Add build jobs for MSYS clang32/64Xiaofan Chen2023-01-283-1/+43
| | | | | | References #1192 Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* windows: Only link with --add-stdcall-alias if supported by linkerTormod Volden2023-01-282-2/+14
| | | | | | | | | E.g. the LLVM LLD doesn't support this option. Closes #1192 References #944 Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* windows: Omit -mwin32 GCC option for MSYS/MinGWTormod Volden2023-01-282-2/+2
| | | | | | | | | | | | | | | | Only keep it for Cygwin. Clang doesn't support this option, and it seems only needed for Cygwin since MinGW predefines e.g. the _WIN32 macro anyway. From GCC documentation: -mwin32 This option is available for Cygwin and MinGW targets. It specifies that the typical Microsoft Windows predefined macros are to be set in the pre-processor, but does not influence the choice of runtime library/startup code. References #1192 Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* Bump LIBUSB_API_VERSION to 0x0100010ATormod Volden2023-01-262-2/+2
| | | | | | | | | | | | | | | | | | | | Several API changes targeted for 1.0.27 New API functions: - libusb_init_context - libusb_get_max_alt_packet_size - libusb_get_interface_association_descriptors - libusb_get_active_interface_association_descriptors - libusb_free_interface_association_descriptors - libusb_get_platform_descriptor - libusb_free_platform_descriptor (and their associated structures) New option LIBUSB_OPTION_WINUSB_RAW_IO NetBSD bus/address changes (not strictly part of API) Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* xusb: Add newlines in mass-storage test outputTormod Volden2023-01-212-5/+5
| | | | Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* Fix most -Wpedantic warningsTormod Volden2023-01-216-13/+16
| | | | | | On Linux and gcc 12.2 at least. Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* linux: Keep the no_device_discovery option per contextxloem2023-01-212-10/+15
| | | | | | | | Fixes #1003 Closes #1231 [Tormod: Adapted to current master] Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* core: Add libusb_get_max_alt_packet_size()Orhan aib Kavrakoglu2023-01-214-1/+71
| | | | Closes #1167
* core: Add helper find_alt_endpoint()Orhan aib Kavrakoglu2023-01-202-1/+28
|
* core: Factor out helper get_endpoint_max_packet_size()Orhan aib Kavrakoglu2023-01-202-24/+34
| | | | | [Tormod: Initialize r to please compilers] Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* netbsd: Map NetBSD's udi_bus/udi_addr to libusb's 1-based APIEdgar Fuß2023-01-202-3/+3
| | | | | | | | | | | | | | NetBSD's udi_bus/udi_addr values in struct usb_device_info start from 0. However, libusb's bus_number/device_address in struct libusb_device use 0 to represent a missing value and the libusb API states that a value of 0 returned by libusb_get_bus_number() or libusb_get_device_address() means "not available" so applications may refuse to match on zero values. Adjust between the two worlds by adding an offset of 1. Closes #1230
* windows: Add option for WinUSB RAW_IO endpoint policyMartin Ling2023-01-207-4/+150
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add support for enabling or disabling the WinUSB RAW_IO pipe policy for a given endpoint, which is documented here: https://learn.microsoft.com/en-us/windows-hardware/drivers/usbcon/winusb-functions-for-pipe-policy-modification This is necessary to increase performance. Without this option the WinUSB backend will only queue one inbound operation at a time, even if the libusb async API is used to submit multiple transfers. For real-time sampling devices with high sample rates and small buffers, the use of RAW_IO combined with queued async transfers is essential to maintaining the necessary throughput and avoiding lost samples or buffer overruns. Examples of devices affected include Cypress FX2 based logic analyzers accessed using Sigrok, and the HackRF software defined radio. The new option must be set by calling libusb_set_option with the arguments: libusb_set_option(ctx, LIBUSB_OPTION_WINUSB_RAW_IO, dev_handle, endpoint_address, enable, max_transfer_size_ptr) where the types of the variadic arguments are: libusb_device_handle *dev_handle; unsigned int endpoint_address; unsigned int enable; unsigned int *max_transfer_size_ptr; The dev_handle and endpoint_address parameters must identify a valid IN endpoint on an open device. If enable is nonzero, RAW_IO is enabled, otherwise it is disabled. Unless max_transfer_size_ptr is NULL, then on a successful call to enable RAW_IO, the pointer destination will be written with the MAXIMUM_TRANSFER_SIZE value for the endpoint. Whilst RAW_IO is enabled for an endpoint, all transfers on that endpoint must meet the following two requirements: - The buffer length must be a multiple of the maximum endpoint packet size. - The length must be less than or equal to the MAXIMUM_TRANSFER_SIZE value. This option should not be changed when any transfer is in progress on the specified endpoint. This option only affects the WinUSB backend. On other backends it is ignored and returns LIBUSB_ERROR_NOT_SUPPORTED, without modifying the value pointed to by max_transfer_size_ptr. A great deal of credit is due to Petteri Aimonen and Patrick Stewart for previous work, and to everyone else who participated in discussions. Fixes #490 Closes #1208
* windows: Add GetPipePolicy to struct winusb_interfaceMartin Ling2023-01-203-1/+10
|
* Update tests and example to use the new libusb_init_context() functionNathan Hjelm2023-01-2011-24/+27
| | | | | | | | | This commit updates all test and example code to use the newer libusb_init_context() function instead of libusb_init(). Signed-off-by: Nathan Hjelm <hjelmn@google.com> [Tormod: Update umockdev.c as well] Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* core: Add libusb_init_context() setting options at context creationNathan Hjelm2023-01-204-93/+139
| | | | | | | | | | | | | | | The new initialization function addresses some shortcomings of the libusb_set_option() interface. Namely, it allows setting the no-enumeration option (and others) on only the contexts where it is requested. The old initialization function (libusb_init()) is deprecated and will be removed in a future release. For now it translates to a call to libusb_init_context() with no options specified. Closes #1026 Signed-off-by: Nathan Hjelm <hjelmn@google.com> [Tormod: Doxygen description of libusb_init_option structure] Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* descriptor: Add support for BOS platform descriptor parsingDominik Boehi2023-01-195-2/+119
| | | | | | | | | Also add BOS platform descriptor dump to xusb example. Closes #1133 [Tormod: Fixed copy-pasto in Doxygen comment] Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* xusb: Print info from IAD descriptorsRyan Metcalfe2023-01-192-1/+27
| | | | Signed-off-by: Ryan Metcalfe <ryan.metcalfe@novanta.com>
* windows: Allow claiming all interfaces for a WINUSBX composite functionRyan Metcalfe2023-01-193-18/+91
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | On Windows 10, when a USB composite device is using usbccgp to manage the parent device, there can be problems when an application tries to claim multiple interfaces for a WINSBX-enabled subfunction. For example, a common scenario is that an application is able to claim the first interface of a given child function, but not the others. This commit attempts to resolve this issue by making use of (potentially) available interface association descriptors (IADs). Within set_composite_interface(), which is normally called for the first interface of a composite child function (Some MI_XX device, where XX is the first interface), the set of IADs for the current configuration is retrieved and, if the current interface matches the 'bFirstInterface' for one of the returned IADs then the API backend, sub_api is also set up for the other 'associated' interfaces. Subsequent calls to libusb_claim_interface for any of these 'associated' interfaces will get properly routed to winusbx_claim_interface. Two fields have been added to winusb_device_priv.usb_interface: num_associated_interfaces first_associated_interface These are made use of by winusbx_claim_interface() to decide whether Initialize() or GetAssociatedInterface() function calls are needed, as well as within winusbx_close() to perform proper cleanup for groups of associated functions. About composite functions in Windows (by Maciej T. Nowak): (1) Non-composite device: Single device is created with all interfaces grouped (associated) together. WinUSB_Initialize gives access to first interface and WinUSB_GetAssociatedInteface can be used to get access to remaining interfaces. (2) Composite device without IAD is presented by set of devices each containing single interface. As they are separate devices, separate WinUSB_Initialize calls are required to gain access to each interface. As there are no more interfaces in each device, WinUSB_GetAssociatedInterface has no use in this case. In other words: Each interface is grouped (associated) with itself. (3) When we add IAD to a composite device, interfaces specified in each IAD are grouped (associated) into single devices where WinUSB_Initialize is required to open the first interface in each association and WinUSB_GetAssociatedInterface for the remaining interfaces in each group. Effectively this case is a mix of (1) and (2). Closes #965 Signed-off-by: Ryan Metcalfe <ryan.metcalfe@novanta.com> [Tormod: Removed redundant is_associated_interface member] Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* descriptor: Introduce interface association descriptors (IAD)Ryan Metcalfe2023-01-194-1/+262
| | | | | | | | | | | | | | | Types: struct libusb_interface_association_descriptor struct libusb_interface_association_descriptor_array Accessor / cleanup functions: libusb_get_interface_association_descriptors libusb_get_active_interface_association_descriptors libusb_free_interface_association_descriptors Signed-off-by: Ryan Metcalfe <ryan.metcalfe@novanta.com> [Tormod: Fixed Doxygen comment] Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* netbsd: Add comment about udi_speed values matching libusb enumEdgar Fuß2023-01-182-2/+2
| | | | | | | | | Point out that only because NetBSD's #define's for USB speeds happen to match the corresponding libusb enum values, it's OK to assign struct usb_device_info's udi_speed field to the struct libusb_devices's speed field. References #1230
* msvc: Add configurations with /MT compilation flagSonatique2023-01-187-11/+250
| | | | | | | | | | | | | | | | | | | | Allows statically linking vc++ runtime dependencies inside libusb-1.0 Windows libraries. 'Release' and 'Debug' configurations produce /MD compiled binaries while the new 'Release-MT' and 'Debug-MT" configurations produce /MT compiled binaries. The /MT flag causes the application to include the multithread, static version of the vc++ run-time library, whereas the default flag /MD will cause the vc++ run-time library to be dynamically linked run-time. Using /MT thus builds a standalone libusb DLL that doesn't require a vc++ runtime DLL to be shipped along with it. For the official description of /MT see: https://docs.microsoft.com/en-us/cpp/build/reference/md-mt-ld-use-run-time-library Closes #1188
* Add tags and cscope.out to .gitignoreNathan Hjelm2023-01-091-0/+2
| | | | | | Fixes #1061 Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* git ignore "build" folderSylvain2023-01-092-1/+2
| | | | | | Fixed #1203 Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* Fix setting log level before libusb_init()Francis Hart2023-01-092-2/+2
| | | | | | | | | | | | | | | | | The header docs state its possible to set a default log level before calling libusb_init(), and that this log level will be used for all contexts created after (to quote): "Note that libusb_set_option(NULL, ...) is special, and adds an option to a list of default options for new contexts." This updates the logic inside libusb_init() to ensure this behaviour is followed. Fixes #1207 Signed-off-by: Francis Hart <francis@kuvacode.com> Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* windows: Define __func__ for vs2015Alexander Mot2023-01-072-3/+3
| | | | | | | | | | | The __func__ macro is defined by the C99 standard (but not C++99/03). The default C compiler in msvc implements C89, plus Microsoft extensions, some of which are part of C99. It appears that both vs2013 and vs2015 don't define __func__. Closes #1170
* docs: Clear endpoint halt issued after cancellation only for macOS < 10.5Martin Ling2023-01-062-16/+18
| | | | | | | | | | Also remove comment about possible endpoint halt, which seems not correct, as discussed in issue #1110. References #1110 Closes #1117 Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* darwin: Do not clear device data toggle on macOS 10.5 or newerNathan Hjelm2023-01-063-9/+15
| | | | | | | | | | | | Historically Mac OS X always cleared the data toggle on the host side. For consistency, libusb has been calling ClearPipeStallBothEnds to also clear the device side toggle. Newer versions of the IOUSBLib do not clear the host side toggle so there is no need to make this call. Additionally, some buggy devices may fail to correctly implement clearing the data toggle. Signed-off-by: Nathan Hjelm <hjelmn@google.com> [Tormod: Return result from AbortPipe] Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* windows: Remove __stdcall libusb_set_option from .def fileRosen Penev2022-12-202-2/+1
| | | | | | | | | | | | libusb_set_option uses variable arguments and therefore cannot use __stdcall. In practice, this does not get exported anyway. Verified under MinGW's objdump tool with 32 and 64-bit combinations. Closes #1197 Signed-off-by: Rosen Penev <rosenp@gmail.com>
* core: Do not warn about new context as implicit defaultTormod Volden2022-12-192-2/+2
| | | | | | | | Only leave a debug message. Fixes #1215 Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* CI: Run multithreaded stress test on LinuxTormod Volden2022-12-192-1/+2
| | | | Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* tests: Add multithreaded stress test for Posix platformsTormod Volden2022-12-193-1/+52
| | | | | | | | | | | | | | Thanks to Ilya Averyanov for initial version. This test detects issues like #1124. Adaptation to Windows threads is on the wishlist (#1128). References #1124 References #1128 Closes #1189 Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* windows: Fix off-by-one error in HID backend for devices without report IDsMario Kleiner2022-12-192-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When the windows HID backend is used for interrupt or bulk transfers on USB-HID compliant devices which don't use HID report IDs, the current code properly adds a zero prefix byte for report ID 0x00 before an OUT transfer, and properly strips the leading zero prefix byte from buffers received by IN transfers. Length of transmitted data is increased by +1 accordingly to account for the extra prefix byte. However, on transfer completion the length of sent or received data is not adjusted back again by one. This leads to misreporting of effective transfer length for both OUT and IN transfers, reporting one byte too much. It also causes a memcpy for IN transfers which copies one byte of data too much into the client provided target buffer transfer_priv->hid_dest, appending an extra zero byte at the end and thereby writing one byte past the size of the client target buffer. This could lead to memory corruption or a access violation if the client application is unlucky. This commit fixes the problem by detecting this type of HID transfers and adjusting the effective length of the transfer down one byte. The fix has been successfully tested with a Griffin PowerMate USB-HID device that doesn't support report IDs, performing interrupt transfers from/to the device. Closes #1217 Signed-off-by: Mario Kleiner <mario.kleiner.de@gmail.com>
* darwin/windows: Find interface descriptor by bInterfaceNumberIhor Dutchak2022-12-193-7/+36
| | | | | | | | | | | | | | For some (non USB-compliant) devices the interface number doesn't match its index in the list of interfaces in the configuration descriptor. For robustness and consistency across platforms, find the descriptor by iterating over the list to match the bInterfaceNumber. References #1093 References #1039 References #1175 Closes #1191 Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* core: Remove leftover usbi_mutex_unlock in libusb_set_interface_alt_settingPablo Prietz2022-12-192-2/+1
| | | | | | Fixup of commit 1a08aa8. Closes #1200
* windows: Silence warnings when building without loggingTormod Volden2022-09-043-1/+7
| | | | Signed-off-by: Tormod Volden <debian.tormod@gmail.com>