aboutsummaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2024-03-08Merge "Add sanglardf to OWNERS" into mainHEADmastermainTreehugger Robot
2024-03-08Add sanglardf to OWNERSFabien Sanglard
Test: NA Bug: NA Change-Id: Idb99926a50e262a6cfdf19637827ff17f81b8ef5
2024-02-09Merge "Upgrade libusb to v1.0.27" into main am: 9e9370211cTreehugger Robot
Original change: https://android-review.googlesource.com/c/platform/external/libusb/+/2954501 Change-Id: I2b079c8109b34320d54c36a52f2eef69359455da Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-02-09Merge "Upgrade libusb to v1.0.27" into mainTreehugger Robot
2024-02-09Upgrade libusb to v1.0.27Shaju Mathew
This project was upgraded with external_updater. Usage: tools/external_updater/updater.sh update libusb For more info, check https://cs.android.com/android/platform/superproject/+/main:tools/external_updater/README.md Test: TreeHugger Change-Id: Ifb65673bd9d1a8653475e1396110447114685d4a
2024-01-31libusb 1.0.27Tormod Volden
Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2024-01-31configure.ac: Bump libtool library versionTormod Volden
Programs using the previous version may use the new version as drop-in replacement, but programs using the new version may use APIs not present in the previous one. Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2024-01-31examples/hotplugtest: Tone down message about failed openTormod Volden
References #1425 Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2024-01-31configure.ac: Do not build umockdev if --enable-debug-log is usedTormod Volden
umockdev relies on the per-context log callbacks to do its checks properly, and these are not called if ENABLE_DEBUG_LOGGING is defined (configure --enable-debug-log). Fixes #1449 Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2024-01-28libusb 1.0.27-rc2Tormod Volden
Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2024-01-27docs: Add more references in libusb_option sectionTormod Volden
Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2024-01-27core: Allow setting global log callback after first libusb_init()Lars Kanis
When setting LIBUSB_OPTION_LOG_CB before the first libusb_init(), the global callback is set. However, after the first libusb_init() there is a default context, and setting LIBUSB_OPTION_LOG_CB would only set this default context, and not the global callback. There would be no way to set the global callback through libusb_set_option(). Change this so that the global log callback is set in addition to the default context (when libusb_set_option is called with NULL context). Closes #1397
2024-01-27core: Don't overwrite the log callback on every global libusb_set_option()Lars Kanis
But set it only on option LIBUSB_OPTION_LOG_CB. Otherwise the following second call resets the callback to the default one: libusb_set_option(NULL, LIBUSB_OPTION_LOG_CB, cb_func); libusb_set_option(NULL, LIBUSB_OPTION_LOG_LEVEL, LIBUSB_LOG_LEVEL_DEBUG); References #1397
2024-01-20docs: Prefer use of libusb_init_context() over old libusb_init()Sean McBride
- Replace some uses of the soft-deprecated libusb_init() and libusb_set_debug() with their updates. - Updated various comments to favour use of the new functions. - Notably remove \deprecated doxygen statement, since it causes -Wdocumentation compiler warnings. - Notably update the xusb example to pass debug options to libusb_init_context() instead of setting environment variable. - Also improve comments related to LIBUSB_API_VERSION and LIBUSBX_API_VERSION. Closes #1408 [Tormod: Fix Doxygen formatting and references] Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2024-01-20xcode: Add files from other backends into the Xcode projectSean McBride
They aren't included in any target, so they are never compiled. But having them in the project allows doing global searches that also look in these files. Closes #1421
2024-01-20xcode: Move some options from Xcode project to xcconfig fileSean McBride
project.pbxproj is not so human-readable, and xcconfig files are preferable because you can add comments about the build settings. References #1421
2024-01-20Correct some spelling and add codespell config fileSean McBride
In one case, renamed a variable from `larg` which codespell thought was a typo for `large`. Closes #1411
2024-01-19darwin: locationID is 32-bit, not 64-bitSean McBride
Also zero-initialize locationID since otherwise it could be used uninitialized. Also change the return variable to bool, matching what the function actually returns. Fortunately, this only affected log messages. Closes #1412 [Tormod: Use PRIx32 for printing the 32-bit locationID] Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2024-01-19Replace all http://libusb.info/ with httpsSean McBride
The libusb.info website, like most sites these days, auto-redirects to the https version anyway. Also replaced a couple of other http links to https, after verifying that they autoredirect to https. Note this changes the "describe" field in the version info returned by libusb_get_version(). This field is only there for ABI compatibility and contains the website URL. Closes #1407
2024-01-19Document backend functions that already lock dev_handle->lockSean McBride
Closes #1410
2024-01-19Fix docs about backend functions that lock itransfer->lockSean McBride
In 2013, commit 858b794c added a comment saying "This function gets called with the flying_transfers_lock locked". That appears to have changed with 138b661f. Commit 88778414 improved some stale comments, but missed these. It is clear in the code that the comment is no longer true. The function is *not* called with flying_transfers_lock locked, but it does lock itransfer->lock. References #1410
2024-01-19io: Change remove_from_flying_list() to not lock flying_transfers_lock itselfSean McBride
This is now symmetric with add_to_flying_list(), which was already requiring that *callers* lock flying_transfers_lock. Updated the only 2 callers. This also makes the code correspond better to the big comment about locking made in 138b661f. Also documented at the top of several functions when they require that flying_transfers_lock already be held. Verified by code review that it's actually the case. This should not change any behaviour at all. References #1410
2024-01-19windows: Downgrade get_guid DeviceInterfaceGUID warning to infoTormod Volden
Closes #1394 Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2024-01-19libusb.h: Rename ZERO_SIZED_ARRAY to LIBUSB_FLEXIBLE_ARRAYSean McBride
This reflects the C99 terminology, instead of the old hack of using a zero sized array. Also adds the LIBUSB prefix to avoid namespace colisions, as this is present in a public header. References #1409
2024-01-19core: Add missing mutex acquisition when manipulating active_contexts_listSean McBride
The `active_contexts_list` is supposed to be protected by the `active_contexts_lock` mutex. Upon code review, found one place where the mutex was not acquired. Closes #1413
2024-01-19Change libusb_init_option to fix libusb_set_option() on big-endianTormod Volden
libusb_set_option() is a variadic function, so the type of the arguments is not clearly defined. When called with LIBUSB_OPTION_LOG_LEVEL, the argument is read with va_arg() as an int, which matches the type used when passing constants, and also most of the internal calls and the calls in the examples. However the internal call site in libusb_init_context() passes the ival element of the libusb_init_option struct directly, which is of type int64_t. This breaks on big-endian architectures like PowerPC, as detected by tests/set_option. Therefore change the libusb_init_option struct to use int here as well. Thanks to Aurelien Jarno for reporting and initial patch. Closes #1416 Closes #1436 Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2024-01-19io: Fix incorrect alignment in allocation in libusb_alloc_transferSean McBride
After being suspicous of some code I was browsing, I tried changing PTR_ALIGN to align to 4096 bytes instead of just to pointer size (8 bytes), then enabled ASan then ran the xusb example, and it crashed. What ensued was a big code review of that function and related code. - reviewed use of macros like USBI_TRANSFER_TO_LIBUSB_TRANSFER - introduced new macros TRANSFER_PRIV_TO_USBI_TRANSFER and USBI_TRANSFER_TO_TRANSFER_PRIV to do pointer offset conversions - introduced some temporary variables, especially for USBI_TRANSFER_TO_LIBUSB_TRANSFER results - move some variable assignment and declaration together - replaced a few uses of PTR_ALIGN to instead use the alignment macros In particular, libusb_alloc_transfer() was not using PTR_ALIGN() on struct usbi_transfer and could allocate a wrong size. Closes #1418
2024-01-19descriptor: Prevent string descriptor buffer overreadSean McBride
Calculate the correct size of both the source and destination buffers, then determine which is shorter, and iterate only that many times. The original code would read one byte beyond the descriptor buffer if a device returned a broken string descriptor of byte length 255. Closes #1432
2024-01-19darwin: Avoid error checking regressionSean McBride
Commit 13a69533 slightly/subtly made an incorrect change to error checking. Before that commit, we had if (kIOReturnSuccess != kresult || !plugInInterface) { return NULL; } which was correct. The commit changed the function signature. Instead of returning the pointer directly, it now returns an error code directly, and the pointer by reference. The above block became: if (kIOReturnSuccess != kresult || !plugInInterface) { return darwin_to_libusb(kresult); } But if kresult is somehow kIOReturnSuccess but plugInInterface is NULL (probably impossible), then we'd return LIBUSB_SUCCESS but a NULL pointer, which is a nonsense combination. Closes #1430
2024-01-19darwin: Revert seemingly harmless introduction of temporary variableSean McBride
Commit 13a69533 introduced a temporary variable for the device structure (that originally was meant to be reverted, it turns out). Here is a follow-up to revert this part, to avoid threading issues and reported crashes. The temporary variable would be harmless if there was no multithreading happening, but there is: On the hotplug background thread, darwin_devices_detached() is called, which in turn calls Release() on the device, which frees the memory, and then sets old_device->device to NULL. Shortly after, darwin_devices_attached() is called (because the kernel driver is reattaching?) and this calls darwin_get_cached_device(), which sets ->device to something new (and not NULL). Meanwhile, back on the main thread, darwin_reenumerate_device() is running and had cached ->device in the seemingly harmless temporary variable. But that thing was already deallocated on the other thread! Re-reading it from the structure makes it more likely you get the value you want. There might still be unfixed multithreading issues here, but this at least avoids an obvious regression. Fixes #1386 Closes #1427
2024-01-05core: Fix -Wswitch warnings by including all enum values in switchSean McBride
No change in behaviour. References #1426
2024-01-04ChangeLog updatesTormod Volden
Thanks to Lars Kanis and Sean McBride for noticing errors and omissions. Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2023-12-19msvc: Add tests/init_context project to MSVCIngvar Stepanyan
2023-12-19tests/stress_mt: Ignore device descriptor mismatch for Windows HIDTormod Volden
Some device descriptor fields are hard-coded by the HID backend, so they will often not match. It is complicated to narrow this down to HID devices, so we simply ignore these fields on Windows wholesale. Hopefully we will fix the HID backend later, and this workaround can then be reverted. References #1360 References #1378 Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2023-12-19tests/stress_mt: Ignore some unavailable devices on WindowsTormod Volden
Depending on the devices or drivers, open() may return LIBUSB_ERROR_ACCESS LIBUSB_ERROR_NOT_FOUND LIBUSB_ERROR_NOT_SUPPORTED for devices "out of reach" to libusb. References #1360 Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2023-12-19tests/set_option: Allow no devices in test_no_discoveryIngvar Stepanyan
Instead of assuming there will always be some devices detected (when not using LIBUSB_OPTION_NO_DEVICE_DISCOVERY), let the test pass but print a warning to the user if there is none. This is to allow automated build tests on restricted build environments without USB devices. References #1374 Closes #1379
2023-12-19libusb.h: Avoid UNREFERENCED_PARAMETER macro on GCC/clangTormod Volden
The UNREFERENCED_PARAMETER macro is provided by MinGW headers but interferes with -Wuninitialized on recent clang. So instead fall back to the same UNUSED macro already used elsewhere with GCC. Relevant discussion: https://discourse.llvm.org/t/rfc-winnt-hs-unreferenced-parameter-vs-clangs-wunused-value/38526 Fixes #1381 Closes #1382 Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2023-12-12tests/stress_mt: Stop early if any device failsIngvar Stepanyan
Previously the loop would continue even if error has already occured since `goto close` alone doesn't stop early. References #1360
2023-12-11tests/set_option: Avoid use-after-free in case of test failureAurelien Jarno
In case num_devices equals 0, LIBUSB_EXPECT() calls LIBUSB_TEST_CLEAN_EXIT(), which calls libusb_exit() on test_ctx which has just been freed a few lines above by a call to libusb_exit(). This might cause a SEGFAULT or SIGBUS depending on the system. Fixes that by assigning NULL to test_ctx just after calling libusb_exit() like it is done elsewhere in the file. Closes #1374
2023-12-10libusb 1.0.27-rc1Tormod Volden
Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2023-12-10tests: Use AM_LDFLAGS for -static flag to allow LDFLAGS overrideTormod Volden
Fixes the following warning from automake: tests/Makefile.am:3: warning: 'LDFLAGS' is a user variable, you should not override it; tests/Makefile.am:3: use 'AM_LDFLAGS' instead Also, since stress_mt_LDFLAGS is set (even in a conditional), AM_LDFLAGS will not be applied for stress_mt unless added explicitly. Closes #1371 Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2023-12-09.gitignore: Ignore test binaries and logsTormod Volden
Closes #1370 Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2023-12-09tests/umockdev: Avoid unknown warning option on older gccTormod Volden
According to https://gcc.gnu.org/wiki/StaticAnalyzer the -Wanalyzer-malloc-leak and -Wanalyzer-file-leak options came in GCC 10. When building with GCC 9 there would be warnings: CC umockdev-umockdev.o ../../libusb-git/tests/umockdev.c:37:32: error: unknown option after ‘#pragma GCC diagnostic’ kind [-Werror=pragmas] 37 | #pragma GCC diagnostic ignored "-Wanalyzer-malloc-leak" | ^~~~~~~~~~~~~~~~~~~~~~~~ ../../libusb-git/tests/umockdev.c:38:32: error: unknown option after ‘#pragma GCC diagnostic’ kind [-Werror=pragmas] 38 | #pragma GCC diagnostic ignored "-Wanalyzer-file-leak" | ^~~~~~~~~~~~~~~~~~~~~~ Closes #1369 Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2023-12-09Revert "windows: Add option for WinUSB RAW_IO endpoint policy"Martin Ling
This reverts commit 9e4bb9cbe59050d29f7662363c0a7bfc5cf35550. References: #1297
2023-12-08webusb: Wasm+WebUSB backend fixes and improvementsIngvar Stepanyan
- Added long-awaited support for multithreading. Since WebUSB still doesn't support accessing same device from multiple threads, this works by proxying I/O operations to the main thread as discussed on the original issue. For applications that run on the main thread nothing changes and they will continue to access WebUSB via Asyncify like before, while other threads will use blocking mechanism until an asynchronous response is available from the main thread. - Rewrote notification mechanism to use atomic waiting via sync Wasm instructions or `Atomics.waitAsync` depending on the thread. This results in simpler and faster notifications than the previous `postMessage`-based approach (which was used because `Atomics.waitAsync` wasn't yet available), as well as allows to send notifications across threads for multithreading scenario described above. - Fixed notification access to only wait/notify on the event we're interested instead of using a global lock. - Rewrote descriptor reading to query device for raw device & configuration descriptors instead of re-serializing them from JavaScript object representation. This incurs slight extra cost for the initial device opening, but fixes number of issues with information that is not yet exposed via WebUSB and allows to read supplementary descriptors such as string and BOS which were previously not supported. - Fixed listing only one alternate instead of all the available ones. - Fixed device closing & re-opening which could previously error out with "device busy" error. - Added mandatory Emscripten-specific linking flags to the generated pkgconfig. - Added device speed inference. This is not yet exposed via WebUSB, but we can at least make a best effort guess based on USB version and packet size, like some other backends already do. - Simplified & fixed device session ID generation which is now guaranteed to be truly unique, whereas previously it could clash with other devices of the same type. - Prepare code to support building for the Web without mandatory multithreading (which is costly on the Web) in the future. For now those `#ifdef`s are defunct as libusb is always compiled with `-pthread`, but some upcoming changes on the Emscripten side will allow to leverage those codepaths for smaller Wasm binaries. - Require explicit `--host=wasm32-unknown-emscripten` as we might want to add non-Emscripten WebAssembly backends in the future. - Various smaller fixes and improvements. Note that this requires Emscripten 3.1.48 or newer to build for some of the features used here, namely `co_await` support for JavaScript values (without it code would be both more complex and slower) and some proxying APIs. It shouldn't be a big deal in practice as most users retrieve Emscripten via the official emsdk installer or Docker images. Closes #1339
2023-12-07darwin: add testing for IOKit version fallbacksNathan Hjelm
This commit adds a new unit test that verifies that the interface interface and device interface versions are as expected. The unit test relies on new testonly symbols to get details about the implementation. The commit also adds a sanity check on the versions to ensure that libusb_init fails if a supported version can not be found. In addition to the new tests this commit also updates the tests to use the static version of libusb. This provides them access to any hidden symbol including testonly symbols (which should never be exported in the shared library). Signed-off-by: Nathan Hjelm <hjelmn@google.com>
2023-12-07darwin: add abstraction for IOUSBDeviceInterfaceNathan Hjelm
The IOUSBDeviceInterface object is used by libusb to interact with USB devices macOS (Darwin, MacOS X, iOS, etc). For as long as libusb has existed it has always used the highest available version (at compile time) of this interface. This change breaks that by using the higest version available between the compile environment and the version of macOS running at execution time. This allows the same libusb build to run on older and newer versions of macOS without disabling newer features. This change relies heavily on the fact that each new version of the IOUSBDeviceInterface object builds on prior versions. This means that libusb can use the oldest version of the interface that has a specific function without needing to use the specific version specified at open time which greatly simplifies the code. Signed-off-by: Nathan Hjelm <hjelmn@google.com>
2023-12-07darwin: add abstraction for IOUSBInterfaceInterfaceNathan Hjelm
The IOUSBInterfaceInterface object is how libusb interfaces with the interfaces of USB devices on macOS (Darwin, MacOS X, iOS, etc). For as long as libusb has existed it has always used the highest available version of the interface. This change breaks that by using the higest version available for the current running version of macOS. This allows the same libusb build to run on older and newer versions of macOS without disabling newer features. This change relies heavily on the fact that each new version of the IOUSBInterfaceInterface object builds on prior versions. This means that libusb can use the oldest version of the interface that has a specific function without needing to use the specific version specified at open time which greatly simplifies the code. This commit update IOUSBInterfaceInterface only and leave the IOUSBDeviceInterface as-is. A follow-on change will update the device interface. Signed-off-by: Nathan Hjelm <hjelmn@google.com>
2023-12-07darwin: add get_running_version helperNathan Hjelm
This helper returns an integer representation of the currently running OS from 100000 (10.0) on. This allows the Darwin backend to make decisions base on the running version without using the __builtin_available() feature. This builtin is only available in Clang and not gcc. For newer versions of macOS the helper uses the kern.osproductversion sysctl and falls back to kern.osrelease and a mapping of Darwin -> OS X/macOS versions. Signed-off-by: Nathan Hjelm <hjelmn@google.com>
2023-12-06ci: ensure testsuite log is dumped on failureNathan Hjelm
Move make check into the if conditional to ensure that the failure does not force the script to immediately exit. Signed-off-by: Nathan Hjelm <hjelmn@google.com>