Commit Graph

169 Commits

Author SHA1 Message Date
Hans Petter Selasky
d94d94e2c0 libusb(3): Ignore SIGPIPE when initializing the LibUSB v1.0 API.
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
2022-03-02 12:33:40 +01:00
Brooks Davis
8010f4ad21 libusb: remove use of COMPAT_32BIT
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)
2021-12-17 21:28:14 +00:00
Hans Petter Selasky
6847ea5019 Improve handling of USB device re-open in the LibUSB v1.x API.
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
2021-06-11 17:06:44 +02:00
Emmanuel Vadot
500f4659d7 Convert libs with pc files to use PCFILES
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
2021-03-16 07:13:07 +01:00
Hans Petter Selasky
1055793115 Be bug compatible with other operating systems by allowing non-sequential
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
2020-12-14 11:56:16 +00:00
Gordon Bergling
3d265fce43 Fix a few mandoc issues
- skipping paragraph macro: Pp after Sh
- sections out of conventional order: Sh EXAMPLES
- whitespace at end of input line
- normalizing date format
2020-10-09 19:12:44 +00:00
Kyle Evans
04391da364 libusb: improve compatibility
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
2020-06-09 17:17:43 +00:00
Hans Petter Selasky
f6428705d8 Fix for building libusb under Linux.
MFC after:	3 days
Sponsored by:	Mellanox Technologies
2020-03-10 15:59:20 +00:00
Hans Petter Selasky
cca46c5e69 Add missing mutex unlock in failure case.
Differential Revision:	https://reviews.freebsd.org/D23430
Submitted by:	cem
Reported by:	Coverity
Coverity CID:	1368773
MFC after:	3 days
Sponsored by:	Mellanox Technologies
2020-01-30 17:30:04 +00:00
Hans Petter Selasky
34b0ca243f Implement new libusb v2.0 API function, libusb20_dev_get_stats().
This function is useful when debugging USB device issues.

MFC after:	1 week
Sponsored by:	Mellanox Technologies
2019-12-27 20:35:12 +00:00
Simon J. Gerraty
2c9a9dfc18 Update Makefile.depend files
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
2019-12-11 17:37:53 +00:00
Kyle Evans
8495fa081b libusb: LIBUSB_DEBUG environment variable override of libusb_set_debug
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
2019-10-02 15:19:39 +00:00
Emmanuel Vadot
4c1a82cea5 pkgbase: Create a FreeBSD-utilities package and make it the default one
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
2019-09-05 14:15:47 +00:00
Hans Petter Selasky
a5b24a2b65 Only call libusb_hotplug_enumerate() once from 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
2019-06-26 12:04:54 +00:00
Hans Petter Selasky
a41b0ec143 Fix support for LIBUSB_HOTPLUG_ENUMERATE in libusb. Currently all
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
2019-06-26 11:28:08 +00:00
Hans Petter Selasky
08216d1854 Fix for reading the configuration descriptor in libusb. Catch invalid
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
2019-06-08 09:34:02 +00:00
Hans Petter Selasky
1efeb40d1d Fix typos in libusb.
Found by:		Denis Ahrens <denis@h3q.com>
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2019-03-05 14:47:15 +00:00
Mateusz Piotrowski
882764c164 libusb(3): Update the link to the libusb homepage.
While here, pet mandoc & igor.

Reviewed by:	bcr, hselasky
Approved by:	re (kib), krion (mentor, implicit), mat (mentor, implicit)
Differential Revision:	https://reviews.freebsd.org/D17516
2018-10-11 13:58:51 +00:00
Hans Petter Selasky
2682992483 When multiple threads are involved receiving completion events in LibUSB
make sure there is always a master polling thread, by setting the "ctx_handler"
field in the context. Else the reception of completion events can stop.
This happens if event threads are created and destroyed during runtime.

Found by:		Ludovic Rousseau <ludovic.rousseau+freebsd@gmail.com>
PR:			231742
MFC after:		1 week
Approved by:		re (kib)
Sponsored by:		Mellanox Technologies
2018-09-28 10:28:22 +00:00
Hans Petter Selasky
5b21ba5c5d Improve LibUSB debugging by simultaneously allowing both function
and transfer prints. Make sure the debug level comes from the
correct USB context.

Found by:		Ludovic Rousseau <ludovic.rousseau+freebsd@gmail.com>
PR:			231264
MFC after:		1 week
Approved by:		re (kib)
Sponsored by:		Mellanox Technologies
2018-09-14 13:41:37 +00:00
Hans Petter Selasky
540c72297d Fix issues about cancelling USB transfers in LibUSB when the USB device has
been detached. When a USB device has been detached the kernel file handle
stops responding to commands. USB applications which continue to run after
the USB device has been detached, depend on LibUSB generated events to tear
down its pending USB transfers. Add code to handle the needed cleanup when
processing the USB transfer(s) fails and prevent new USB transfer(s) from
being submitted.

Found by:		Ludovic Rousseau <ludovic.rousseau+freebsd@gmail.com>
PR:			231076
MFC after:		1 week
Approved by:		re (gjb)
Sponsored by:		Mellanox Technologies
2018-09-12 15:06:30 +00:00
Hans Petter Selasky
dfd30b26a9 Improve the userspace USB string reading function in LibUSB.
Some USB devices does not allow a partial descriptor readout.

Found by:		bz @
MFC after:		1 week
Sponsored by:		Mellanox Technologies
2018-06-26 16:00:16 +00:00
Hans Petter Selasky
fd2ef04fdb Allow the libusb20_dev_get_port_path() function to be called when the
USB device is closed. This fixes a compatibility issue with upstream
libusb.

Found by:	romain@
MFC after:	1 week
2018-03-23 09:40:41 +00:00
Pedro F. Giffuni
5e53a4f90f lib: further adoption of SPDX licensing ID tags.
Mainly focus on files that use BSD 2-Clause license, however the tool I
was using mis-identified many licenses so this was mostly a manual - error
prone - task.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.
2017-11-26 02:00:33 +00:00
Bryan Drewery
ea825d0274 DIRDEPS_BUILD: Update dependencies.
Sponsored by:	Dell EMC Isilon
2017-10-31 00:07:04 +00:00
Eitan Adler
a2aef24aa3 Update several more URLs
- Primarily http -> https
- Primarily FreeBSD project URLs
2017-10-29 08:17:03 +00:00
Kyle Evans
f75f5a355e libusb(3): Expose device caps as libusb_bos_descriptor::dev_capability
Some libusb consumers in Linux-land (in this case, libusb4java) expect a
dev_capability member that they can use to enumerate the device
capabilities.

No particular layout is expected of this, just that it can be traversed
using the bLength member until bNumDeviceCapabilities are read and that the
consumer may then use one of the libusb_get_*_descriptor methods to extract
specific (usb 2.0 vs. ss) capability information.

In collaboration with:	hselasky
Reviewed by:	hselasky
Approved by:	emaste (mentor)
Differential Revision:	https://reviews.freebsd.org/D11494
2017-08-09 18:06:27 +00:00
Edward Tomasz Napierala
0b9cf9729b Fix libusb20_dev_get_desc(3) to use the "vendor product" order, not
"product vendor". This is consistent with how it's generally done.
The ordering is visible eg in usbconfig(8) output.

Note to self: MFC this to 9 and 8.

Reviewed by:	hselasky@
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D8258
2016-10-22 14:37:13 +00:00
Hans Petter Selasky
5f51814803 Fix array size issue when using the pre-scaling feature for
ISOCHRONOUS USB transfers. Make sure enough length and buffer pointers
are allocated when setting up the libusb transfer structure to support
the maximum number of frames the kernel can handle.

MFC after:	1 week
2016-09-02 08:44:14 +00:00
Hans Petter Selasky
56c926d077 Resolve issue with libusb C++ header file inclusion.
Approved by:	re (marius)
PR:		210509
MFC after:	1 week
2016-06-24 10:55:14 +00:00
Hans Petter Selasky
a0c93fa361 Add support for USB streams to the LibUSB v1.0 API and update the
libusb(3) manual page.

Approved by:	re (gjb)
Requested by:	swills
MFC after:	1 week
2016-06-23 07:12:22 +00:00
Hans Petter Selasky
7bdc064b0b Implement libusb_hotplug_register_callback() and
libusb_hotplug_deregister_callback() for the LibUSB v1.0 API and
update the libusb(3) manual page.

Approved by:	re (kib)
Requested by:	swills
MFC after:	1 week
2016-06-22 10:38:41 +00:00
Hans Petter Selasky
a3d81a8a8a Add missing return statement.
Approved by:	re (gjb)
MFC after:	1 week
2016-06-16 16:26:16 +00:00
Hans Petter Selasky
37d0636aac Add multiple missing descriptor parsing functions to the LibUSB v1.0 API.
Approved by:	re (kib)
Requested by:	swills
MFC after:	1 week
2016-06-16 16:17:29 +00:00
Hans Petter Selasky
5b40d9601c Add support for libusb_set_auto_detach_kernel_driver() to the LibUSB v1.0 API.
Approved by:	re (kostikbel)
Requested by:	swills
MFC after:	1 week
2016-06-16 14:26:04 +00:00
Hans Petter Selasky
0f2c706643 Add support for libusb_get_port_number() to the LibUSB v1.0 API.
Approved by:	re (kostikbel)
Requested by:	swills
MFC after:	1 week
2016-06-16 12:14:19 +00:00
Hans Petter Selasky
fa6ef1c45f Define LIBUSB_API_VERSION.
Approved by:	re (kostikbel)
Requested by:	swills
MFC after:	1 week
2016-06-16 11:51:20 +00:00
Hans Petter Selasky
14b896ce80 Implement libusb_get_version() and update libusb manual page.
Approved by:	re (glebius)
Requested by:	swills
MFC after:	1 week
2016-06-16 07:48:21 +00:00
Hans Petter Selasky
f357b4f65d Fix compile warning.
Approved by:	re (delphij)
MFC after:	1 week
2016-06-13 01:33:02 +00:00
Hans Petter Selasky
90988efdc5 Implement code to stop all USB endpoints before executing a USB device
reset command, alternate setting command or set configuration
command. Else LibUSB v1.0 will not re-open the endpoints which the
kernel closes and the USB application might wait infinitely for
transfers to complete.

Approved by:	re (hrs)
MFC after:	3 days
2016-06-12 23:26:38 +00:00
Pedro F. Giffuni
75f46cf6c8 lib: minor spelling fixes in comments.
No functional change.
2016-05-01 19:37:33 +00:00
Glen Barber
876d357fa7 MFH
Sponsored by:	The FreeBSD Foundation
2016-04-11 15:24:59 +00:00
Pedro F. Giffuni
2bf493863f USB: replace 0 with NULL for pointers.
Found with devel/coccinelle.

Reviewed by:	hselasky
2016-04-09 20:36:07 +00:00
Glen Barber
a70cba9582 First pass through library packaging.
Sponsored by:	The FreeBSD Foundation
2016-02-04 21:16:35 +00:00
Bryan Drewery
7b3ea376a2 META MODE: Prefer INSTALL=tools/install.sh to lessen the need for xinstall.host.
This both avoids some dependencies on xinstall.host and allows
bootstrapping on older releases to work due to lack of at least 'install -l'
support.

Sponsored by:	EMC / Isilon Storage Division
2015-11-25 19:10:28 +00:00
Bryan Drewery
43fa36d52c Remove redundant COMPAT_32BIT guard on pkgconfig files. This is already handled
by the LIBRARIES_ONLY mechanism protecting FILES.

Sponsored by:	EMC / Isilon Storage Division
2015-10-03 16:34:21 +00:00
Bryan Drewery
de0e3997d9 Replace beforeinstall: handling with FILES.
This actually fixes some cases to respect LIBRARIES_ONLY.

Sponsored by:	EMC / Isilon Storage Division
2015-09-18 23:49:32 +00:00
Antoine Brodin
84d5c498b5 bsd.lib.mk has to be included after MLINKS assignment 2015-08-15 19:00:38 +00:00
Pedro F. Giffuni
5a5c6e994c libusb: Fix minor cast-qual warning.
Fix a warning triggered by the gcc + FORTIFY_SOURCE patches:

In function 'libusb20_parse_config_desc': lib/libusb/libusb20_desc.c:141:
warning: passing argument 1 of 'memcpy' discards qualifiers from pointer
target type

Submitted by:	hselansky
2015-07-20 16:15:56 +00:00
Marcelo Araujo
721d6da7ef Remove unused variables to silence CLANG warnings.
Remove some BLANK lines and unnecessary TABS.

Differential Revision:	D2687
Reviewed by:		rodrigc, hselasky
2015-06-24 01:34:35 +00:00