aboutsummaryrefslogtreecommitdiff
path: root/lib/libusb
Commit message (Collapse)AuthorAgeFilesLines
* libusb: dequeue next transfer on completion to prevent stallsBaptiste Daroussin9 days1-0/+18
| | | | | | | | | | | | | | | | | | | | | | The transfer proxy callbacks (bulk/interrupt, control, isochronous) only called libusb10_submit_transfer_sub() in the START path to pipeline the second kernel transfer slot. On completion or error, no attempt was made to dequeue the next pending transfer from tr_head onto the now-free slot. When more than two async transfers were submitted on the same endpoint, the third (and subsequent) transfers would remain stuck on tr_head indefinitely, since no completion ever triggered their submission. This caused a protocol-level deadlock in applications like adb that submit header + payload + zero-length terminator as three separate bulk transfers in sequence. Fix by calling libusb10_submit_transfer_sub() after every libusb10_complete_transfer() in all three proxy callbacks. MFC After: 2 weeks Reviewed by: adrian Differential Revision: https://reviews.freebsd.org/D55289
* libusb: make libusb_hotplug_get_user_data actually return user_dataBaptiste Daroussin9 days1-1/+3
| | | | | | MFC After: 2 days Reviewed by: adrian Differential Revision: https://reviews.freebsd.org/D55291
* libusb20: Add dev_open + be_device_foreach manualsRick Parrish10 days3-4/+127
| | | | | | | | | Manual pages for libusb20_open(3) and libusb20_be_device_foreach(3). PR: 291675 MFC after: 3 days Reviewed by: adrian (usb), ziaee (manpages) Differential Revision: https://reviews.freebsd.org/D54231
* libusb: implement libusb_get_platform_descriptorShengYi Hung2025-08-063-1/+78
| | | | | | | | | This adds a function introduced in libusb 1.0.27 to parse platform-specific USB descriptors, enabling access to vendor- or OS-specific information. Approved by: lwhsu (mentor) Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D51242
* libusb: Add missing misc class in LIBUSB_CLASSShengYi Hung2025-08-061-0/+1
| | | | | | | | Reviewed by: emaste Approved by: markj (mentor), lwhsu (mentor) Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D51738
* libusb: implement libusb_wrap_sys_deviceShengYi Hung2025-08-063-0/+16
| | | | | | | | | | | | | | | | The libusb_wrap_sys_device function can wrap an opened fd from the system into a libusb handler. However, in FreeBSD's libusb implementation, a USB device contains two fds: one for control transfers and another for normal (bulk, interrupt, isochronous) transfers. This design makes it impossible for FreeBSD to implement this function without exposing a different structure in libusb.h to provide two fds. Therefore, we return LIBUSB_ERROR_NOT_SUPPORTED to maintain API compatibility. Approved by: makrj (mentor), lwhsu (mentor) Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D51739
* libusb: implement libusb_pollfds_handle_timeoutsShengYi Hung2025-08-063-0/+15
| | | | | | | | | | | | This function tells applications who maintain the pollfds themselves if they should handle the timeout for each xfer themselves. In FreeBSD, the timeout for each xfer is handled by kernel and doesn't need a special timer to do so. Therefore, we return 1 to indicate that it is handled by libusb internally. Approved by: lwhsu (mentor), markj (mentor) Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D51742
* libusb: add libusb_supported_speed enumShengYi Hung2025-08-061-0/+7
| | | | | | Approved by: lwhsu (mentor), markj (mentor) Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D51743
* libusb: add libusb_usb_2_0_extension_attributesShengYi Hung2025-08-061-0/+4
| | | | | | Approved by: lwhsu (mentor), markj (mentor) Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D51745
* libusb: add missing function signature to headerShengYi Hung2025-08-061-0/+1
| | | | | | | Approved by: markj (mentor), lwhsu (mentor) Fixes: 3eda34934097 ("libusb: implement libusb_fill_bulk_stream_transfer") Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D51754
* libusb: implement libusb_fill_bulk_stream_transferShengYi Hung2025-07-213-0/+15
| | | | | | | | | Bulk streams are essentially bulk transfers with a stream ID. All requirements from both libusb20 and the kernel are already handled; we just need to set the stream ID. Approved by: markj (mentor), lwhsu(mentor) Differential Revision: https://reviews.freebsd.org/D51226
* libusb: implement libusb_dev_mem_{alloc,free}ShengYi Hung2025-07-213-1/+34
| | | | | | | | | | | libusb provides an API to create DMA buffers for USB packets from the kernel. However, this feature is only available on Linux. On unsupported platforms, the allocation function returns NULL, and the free function returns 'not supported'. Approved by: markj (mentor), lwhsu(mentor) Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D51222
* libusb: implement libusb_hotplug_get_user_dataShengYi Hung2025-07-213-0/+25
| | | | | | | | | | libusb provides a function to get the callback userdata for a given callback since this structure is opaque to libusb user. Approved by: markj (mentor), lwhsu (mentor) Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D51223
* libusb: implement libusb_free_pollfdsShengYi Hung2025-07-213-1/+17
| | | | | | | | | | | libusb provides an API that frees the storage for pollfds regardless of their contents. It does not check whether the file descriptors inside are already closed. Approved by: markj (mentor), lwhsu(mentor) MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D51221
* libusb: implement libusb_setlocale to support different locale of error messageShengYi Hung2025-07-114-33/+117
| | | | | | | | | | | | | | | Upstream libusb identifies languages using only the first two characters of the language code. We adopt the same approach to maintain API compatibility. Currently, only English and Mandarin are supported, as other languages are not yet implemented. Reviewed by: kevans Approved by: markj (mentor) MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D50820
* libusb: replace LOG_LEVEL with DEBUG_LEVELShengYi Hung2025-07-094-47/+55
| | | | | | | | | | | | | | | | | | | | | The libusb set debug level by libusb_log_level instead of libusb_debug_level. We switch to libusb_log_level for better compatibility with the upstream libusb. Additionally, The upstream libusb has an option allows user to override the log function with a user-defined callback. To support the callback function with a single string without va_arg, we refactor the log facility as a function instead of a macro and parse all va_args inside. The legacy debug_level enum has been removed to enforce maintainer migrate from their deprecated source code. Reviewed by: kevans Approved by: markj (mentor), lwhsu (mentor) MFC after: 2 weeks Sponsored by: FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D50680
* libusb: rename bNumDeviceCapabilities to bNumDeviceCaps for compatibility ↵ShengYi Hung2025-07-083-7/+15
| | | | | | | | | | | | | | | | | | | | with libusb THe member bNumDeviceCapabilities is referred to as bNumDeviceCaps in the upstream libusb project. To improve compatibility, we are renaming the member accordingly. For backward compatibility, a mocro will be defined to map bNumDeviceCapabilities to bNumDeviceCaps. See: https://github.com/libusb/libusb/commit/02ebafc85d3f219842cbabaf78abc8100b6656e5 Reviewed by: kevans Approved by: markj (mentor) MFC after: 2 weeks Sponsored by: FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D50740
* libusb: consider bad fd as a broken eventSHENGYI HUNG2025-06-251-0/+2
| | | | | | | | | | | Application can use libusb_get_pollfds to get pollfds from libusb then close the fd themselves. This cause the hotplug thread unable to leave because it will be consider as a invalid event then loop forever instead of a broken event that should be quit immediately. Reviewed by: bapt Sponsored by: FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D50959
* libusb: Fix netlink sysevent multicast group nameSHENGYI HUNG2025-06-121-1/+1
| | | | | Reviewed by: hrs Differential Revision: https://reviews.freebsd.org/D50739
* libusb: implement `libusb_get_parent`Aymeric Wibo2025-06-124-4/+41
| | | | | | | | | | | Newer versions of drivers such as libwacom (graphics tablets) or libfprint (fingerprint scanners) call g_usb_device_get_parent. This in turn calls libusb_get_parent on platforms which implement it, and returns NULL on platforms that don't. This patch implements this function on FreeBSD. Reviewed by: bapt, kevans Differential Revision: https://reviews.freebsd.org/D46992
* libusb: add SUPER_PLUS in speed enum.SHENGYI HUNG2025-05-156-1/+11
| | | | | | | | | | | Summary: Some application(like usbmuxd) start to use LIBUSB_SPEED_SUPER_PLUS now. Though we don't have the corresponding infra in kernel right now, it is harmless to have this enum value in userspace to prevent the compile error Reviewed By: bapt Sponsored By: FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D50359
* libusb: use eventfdBaptiste Daroussin2025-05-153-17/+10
| | | | | | | | | Simplify libusb code by replacing pipe(2) inter thread event mecanism with eventfd(2). MFC After: 3 weeks Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D50360
* libusb: Emit event after deregistering hotplug handlerSHENGYI HUNG2025-05-082-0/+2
| | | | | | | | | | | | | | | | | | The original implementation did not emit an event when a hotplug handler was deregistered. This omission causes issues for programs that follow the best practices recommended by libusb—particularly those that use `libusb_hotplug_register_callback()` or similar functions in a loop while managing hotplug handlers dynamically. Without emitting an event after deregistration, these programs can become stuck waiting indefinitely for an event that will never come, as the condition to break out of the wait loop is never satisfied. See: https://github.com/libusb/libusb/blob/6c0ae1ab456da49e7805115e77ce0428ace4ea41/libusb/hotplug.c#L459 Reviewed by: bapt Sponsored By: FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D50170
* libusb: use the new snl_get_genl_mcast_groupBaptiste Daroussin2025-01-161-15/+5
|
* libusb: hotplug, use events instead of a timer when possibleBaptiste Daroussin2025-01-163-1/+196
| | | | | | | | | | | | | Try to fetch events from nlsysevent or devd to determine when to scan the usb bus for devices addition or removal. if none are available fallback on the regular timer based (4s) scanner if devd socket or netlink socket is closed or error fallback on the timer based method. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D48300
* libusb: fix hotplug sigbusBaptiste Daroussin2025-01-041-9/+12
| | | | | | | | | | | | | | | | | When a hotplug callback has been registered, and the program using libusb is calling libusb_exit then the thread handler is set to NO_THREAD which result in the variable controlling the loop the be set to 0, it does a last pass through device available without having done a scan, which result in a sigbus after it tried to unregister all the devices. directly break the loop instead and cleanup the list of devices this fixes the tests with LGPLed libusb's hotplugtest program MFC After: 3 days Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D48298
* manuals: Fix datesGraham Percival2024-10-281-1/+1
| | | | | | | | | | These were reported by `mandoc -T lint ...` as warnings. Signed-off-by: Graham Percival <gperciva@tarsnap.com> Reviewed by: mhorne MFC after: 3 days Sponsored by: Tarsnap Backup Inc. Pull Request: https://github.com/freebsd/freebsd-src/pull/1475
* libusb: claim to be version 1.0.16Ed Maste2024-06-281-1/+1
| | | | | | | | | | | We are not 100% compatible with 1.0.16, but implement some functionality from that version that is required by certain ports. PR: 277799 PR: 279555 (exp-run) Event: Kitchener-Waterloo Hackathon 202406 Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D45514
* libusb(3): Fix link in commentTing-Hsuan Huang2024-02-131-1/+1
| | | | | Event: Advanced UNIX Programming Course (Fall’23) at NTHU. Pull Request: https://github.com/freebsd/freebsd-src/pull/1042
* Remove $FreeBSD$: two-line nroff patternWarner Losh2023-08-162-4/+0
| | | | Remove /^\.\\"\n\.\\"\s*\$FreeBSD\$$\n/
* Remove $FreeBSD$: one-line sh patternWarner Losh2023-08-165-5/+0
| | | | Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
* Remove $FreeBSD$: one-line .c comment patternWarner Losh2023-08-1615-15/+0
| | | | Remove /^/[*/]\s*\$FreeBSD\$.*\n/
* spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSDWarner Losh2023-05-1214-14/+14
| | | | | | | | | The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch up to that fact and revert to their recommended match of BSD-2-Clause. Discussed with: pfg MFC After: 3 days Sponsored by: Netflix
* libusb(3): Implement libusb_init_context() and the needed structures and ↵Hans Petter Selasky2023-03-304-9/+69
| | | | | | | | definitions. Differential Revision: https://reviews.freebsd.org/D38212 MFC after: 1 week Sponsored by: NVIDIA Networking
* libusb(3): Implement libusb_interrupt_event_handler() by exposing existing ↵Hans Petter Selasky2022-10-024-12/+25
| | | | | | | function. MFC after: 1 week Sponsored by: NVIDIA Networking
* Install working pkgconfig .pc files for compat librariesAlex Richardson2022-08-114-6/+15
| | | | | | | | | The default ones are install them to /usr/libdata/pkgconfig, and we can't use this path for compat libraries, so we use /usr/lib<suffix>/pkgconfigi here. Test Plan: grep -rn libdir= ./usr/lib32/pkgconfig/*.pc MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D34939
* libusb(3): Ignore SIGPIPE when initializing the LibUSB v1.0 API.Hans Petter Selasky2022-03-022-0/+4
| | | | | | | | | | The LibUSB v1.0 emulation layer uses pipes internally to signal between threads. When USB devices are reset, as part of loading firmware, SIGPIPE may happen, and that is expected and should be ignored. PR: 261891 MFC after: 1 week Sponsored by: NVIDIA Networking
* libusb: remove use of COMPAT_32BITBrooks Davis2021-12-174-30/+16
| | | | | | | | This codepath used uint64_t's in place of pointers in structs and arrays to allow 32-bit code to use 64-bit version of ioctls. Now that we support 32-bit compat natively this is no longer needed. Reviewed by: hselasky, jrtc27 (prior version)
* Improve handling of USB device re-open in the LibUSB v1.x API.Hans Petter Selasky2021-06-113-2/+24
| | | | | | | | | | Make sure the "device_is_gone" flag is cleared after every successful open, so that the "device_is_gone" flag doesn't persist forever. Found by: sergii.dmytruk@3mdeb.com PR: 256296 MFC after: 1 week Sponsored by: Mellanox Technologies // NVIDIA Networking
* Convert libs with pc files to use PCFILESEmmanuel Vadot2021-03-161-2/+1
| | | | | | | | Now the .pc ends up in the correct package (-dev) Reviewed by: bapt, emaste Differential Revision: https://reviews.freebsd.org/D29172 MFC after: 2 weeks
* Be bug compatible with other operating systems by allowing non-sequentialHans Petter Selasky2020-12-141-8/+12
| | | | | | | | | | | | | | | | | interface numbering for USB descriptors in userspace. Else certain USB control requests using the interface number, won't be recognized by the USB firmware. Refer to section 9.2.3 in the USB 2.0 specification: Interfaces are numbered from zero to one less than the number of concurrent interfaces supported by the configuration. PR: 251784 MFC after: 1 week Sponsored by: Mellanox Technologies // NVIDIA Networking Notes: svn path=/head/; revision=368632
* Fix a few mandoc issuesGordon Bergling2020-10-091-16/+19
| | | | | | | | | | - skipping paragraph macro: Pp after Sh - sections out of conventional order: Sh EXAMPLES - whitespace at end of input line - normalizing date format Notes: svn path=/head/; revision=366583
* libusb: improve compatibilityKyle Evans2020-06-094-1/+61
| | | | | | | | | | | | | | | | | | | Specifically, add LIBUSB_CLASS_PHYSICAL and the libusb_has_capability API. Descriptions and functionality for these derived from the documentation at [0]. The current set of capabilities are all supported by libusb. These were detected as missing after updating net/freerdp to 2.1.1, which attempted to use both. [0] http://libusb.sourceforge.net/api-1.0/group__libusb__misc.html Reviewed by: hselasky MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D25194 Notes: svn path=/head/; revision=361977
* Fix for building libusb under Linux.Hans Petter Selasky2020-03-101-0/+7
| | | | | | | | MFC after: 3 days Sponsored by: Mellanox Technologies Notes: svn path=/head/; revision=358841
* Add missing mutex unlock in failure case.Hans Petter Selasky2020-01-301-1/+3
| | | | | | | | | | | | Differential Revision: https://reviews.freebsd.org/D23430 Submitted by: cem Reported by: Coverity Coverity CID: 1368773 MFC after: 3 days Sponsored by: Mellanox Technologies Notes: svn path=/head/; revision=357298
* Implement new libusb v2.0 API function, libusb20_dev_get_stats().Hans Petter Selasky2019-12-276-2/+73
| | | | | | | | | | This function is useful when debugging USB device issues. MFC after: 1 week Sponsored by: Mellanox Technologies Notes: svn path=/head/; revision=356136
* Update Makefile.depend filesSimon J. Gerraty2019-12-111-1/+0
| | | | | | | | | | | | | Update a bunch of Makefile.depend files as a result of adding Makefile.depend.options files Reviewed by: bdrewery MFC after: 1 week Sponsored by: Juniper Networks Differential Revision: https://reviews.freebsd.org/D22494 Notes: svn path=/head/; revision=355617
* libusb: LIBUSB_DEBUG environment variable override of libusb_set_debugKyle Evans2019-10-021-4/+19
| | | | | | | | | | | | | | | | | | | | | The debug level generally just controls verbosity of libusb for debugging libusb devices/usage. We allow the environment to set the debug level independent of the application, but the application will always override this if it explicitly sets the debug level. Changing the environment is easy, but patching the software to change the debug level isn't necessarily easy or possible. Further, there's this write-only debug_fixed variable that would seem to imply that the debug level should be fixed, but it isn't currently used. Change the logic to use strtol() so we can detect real 0 vs. conversion failure, then honor debug_fixed in libusb_set_debug. Reviewed by: hselasky MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D21877 Notes: svn path=/head/; revision=353009
* pkgbase: Create a FreeBSD-utilities package and make it the default oneEmmanuel Vadot2019-09-051-1/+0
| | | | | | | | | | | | | The default package use to be FreeBSD-runtime but it should only contain binaries and libs enough to boot to single user and repair the system, it is also very handy to have a package that can be tranform to a small mfsroot. So create a new package named FreeBSD-utilities and make it the default one. Also move a few binaries and lib into this package when it make sense. Reviewed by: bapt, gjb Differential Revision: https://reviews.freebsd.org/D21506 Notes: svn path=/head/; revision=351858
* Only call libusb_hotplug_enumerate() once from ↵Hans Petter Selasky2019-06-261-3/+3
| | | | | | | | | | | | | libusb_hotplug_register_callback(). Else when registering multiple filters the same USB device may appear twice in the list. MFC after: 3 days Sponsored by: Mellanox Technologies Notes: svn path=/head/; revision=349410