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
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
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
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 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 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 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
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
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
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
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
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
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
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
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
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
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
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
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
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
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)
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
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
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
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
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
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
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
devices are enumerated regardless of of the LIBUSB_HOTPLUG_ENUMERATE
flag. Make sure when the flag is not specified no arrival events are
generated for currently enumerated devices.
MFC after: 3 days
Sponsored by: Mellanox Technologies
configuration descriptor reads early on to avoid issues with devices
that don't check for a valid USB configuration read request.
Submitted by: takahiro.kurosawa@gmail.com
PR: 238412
MFC after: 3 days