1610 Commits
Author SHA1 Message Date
Marco Trevisan (Treviño) 1001cb5558 autogen: Support being called from external build dir
Building libusb from another build directory doesn't properly work right
now, as calling autogen.sh from there won't work.

An example is when using jhbuild to build it.

So always use absolute paths to call configure and bootstrap scripts

Signed-off-by: Ludovic Rousseau <[email protected]>
2021-04-14 16:51:09 +02:00
Ludovic Rousseau bda2344f5e Doxygen: fix warning about PAPER_TYPE
warning: argument 'a4wide' for option PAPER_TYPE is not a valid enum value
Using the default: a4!

Signed-off-by: Ludovic Rousseau <[email protected]>
2021-02-22 21:34:10 +01:00
Ludovic Rousseau 90273023db Doxygen: update config file from 1.8.16 to 1.9.0
warning: Tag 'TCL_SUBST' at line 255 of file 'doxygen.cfg.in' has become obsolete.
         This tag has been removed.
warning: Tag 'COLS_IN_ALPHA_INDEX' at line 1056 of file 'doxygen.cfg.in' has become obsolete.
         This tag has been removed.

Signed-off-by: Ludovic Rousseau <[email protected]>
2021-02-22 18:01:13 +01:00
Vegard Storheil Eriksen d97e85ef4a darwin: Don't drop partial data on timeout
A timed out transfer might have been partially filled. Propagate
tpriv->size to avoid dropping this data.

Closes #876

Signed-off-by: Nathan Hjelm <[email protected]>
2021-02-15 21:05:42 -07:00
Victor Toso 28a11d1163 doc: Add since version tag to libusb_set_log_cb()
The commit f74c7f5 "core: new API libusb_set_log_cb() to redirect
global and per context log messages to the provided log handling
function" in 2018-12-05 is present from 1.0.23 onwards.

This commit just adds this to the docs.

Closes #872

Signed-off-by: Victor Toso <[email protected]>
Signed-off-by: Chris Dickens <[email protected]>
2021-02-15 09:55:12 -08:00
Chris Dickens f38f09da98 linux_usbfs: Gracefully handle buggy devices with a configuration 0
The USB spec states that a configuration value of 0 is reserved and is
used to indicate the device in not configured (e.g. is in the address
state). Unfortunately some devices do exist that violate this and use 0
as the bConfigurationValue of the configuration descriptor.

Improve how the Linux backend handles such non-conformant devices by
adding special handling around the configuration value 0. Most devices
will not require this special handling, but for those that do there is
no way to distinguish between the device being unconfigured and using
configuration 0.

Closes #850

Signed-off-by: Chris Dickens <[email protected]>
2021-02-08 11:56:13 -08:00
Chris Dickens c486d01297 linux_usbfs: Accept sysfs attributes not terminated with newline
Benjamin Berg reports that some CI systems that simulate sysfs devices
are causing libusb to report errors because such systems are not
conforming to the sysfs pattern of terminating attribute values with a
newline character. Reduce the severity of encountering such
non-conforming attibute values from an error that prevents enumeration
to a warning message.

Closes #857

Signed-off-by: Chris Dickens <[email protected]>
2021-02-08 09:27:20 -08:00
Chris Dickens 6a3945116a linux_netlink: Change order of header includes per netlink(7)
Closes #869

Signed-off-by: Chris Dickens <[email protected]>
2021-02-08 09:06:42 -08:00
Michael Dickens a247f1696e darwin: fix const array size to work with GCC compilers
Closes #833

Signed-off-by: Chris Dickens <[email protected]>
2021-02-08 09:04:22 -08:00
Chris Dickens a108bb8e18 Windows: Fix HID and synchronous transfer completion
Commit b51c743e42 ("Windows: Filter out non-libusb I/O completions")
causes problems with the HID backend functions and synchronous transfer
completions. Address these by fetching the correct pointer in the HID
functions and posting an I/O completion for synchronous transfers.

Closes #863

Signed-off-by: Chris Dickens <[email protected]>
2021-02-01 15:12:17 -08:00
Chris Dickens b51c743e42 Windows: Filter out non-libusb I/O completions
The I/O completion port thread gets notified of every I/O operation that
completes for a given HANDLE, but not all I/O operations originate from
within libusb. For example, libusbK performs a number of I/O control
calls during initialization and specific device operations, such as
setting an interface alternate setting. These non-libusb operations need
to be ignored as the OVERLAPPED associated with such operations is not
tied to a libusb_transfer structure.

Resolve this situation by using the libusb device handle as the I/O
completion port's unique key and keeping a list of active transfers for
each device handle. When the I/O competion port thread is notified of an
I/O completion, it will first match the OVERLAPPED to an outstanding
transfer before acting on it.

Closes #844

Signed-off-by: Chris Dickens <[email protected]>
2021-01-15 17:18:34 -08:00
Chris Dickens 08e0029f10 configure.ac: Consider Mac OS X target version for clock_gettime()
The AC_CHECK_FUNCS() macro checks whether a program compiled on the host
will link against the function, but it does not help when targeting
older systems where that function is not available. Additionally, the
way that autoconf compiles the program ignores any attributes or
preprocessor guards that installed headers might have applied to that
function.

Resolve this by verifying that the OS X target version is 10.12 or newer
before checking for clock_gettime().

Closes #836

Signed-off-by: Chris Dickens <[email protected]>
2021-01-15 12:42:35 -08:00
Mark Kuo e78cafbaa2 linux_usbfs: Fix exit crash on Android
In commit "89b810ec Android: Add option LIBUSB_OPTION_WEAK_AUTHORITY
to support used in apk", we should also check weak_authority when
exiting the backend.

[dickens] Fixed whitespace

Closes #842

Signed-off-by: Mark Kuo <[email protected]>
Signed-off-by: Chris Dickens <[email protected]>
2021-01-15 08:07:56 -08:00
Tormod Volden 62c0594175 windows: Update link about control transfer size limits
Closes #839

Signed-off-by: Tormod Volden <[email protected]>
Signed-off-by: Chris Dickens <[email protected]>
2021-01-15 08:03:36 -08:00
Mikolaj Kucharski 1f25bb7ff0 libusb/core.c: bump DISCOVERED_DEVICES_SIZE_STEP to 16
On OpenBSD USB controllers are shown as normal devices, making the
initial limit too small. On a recent machine this value is almost
always exceeded, so bump it.

Change committed to OpenBSD ports tree by Matthias Kilian <[email protected]>
on Tue Jun 19 21:10:59 2012 UTC

Closes #835

Signed-off-by: Chris Dickens <[email protected]>
2021-01-15 08:01:53 -08:00
Mikolaj Kucharski 2c7f4aa887 Prefix hex values with 0x in core.c and os/openbsd_usb.c
It makes it clear from debug logs, that values are in hex,
without a need to check the source code.

Closes #832

Signed-off-by: Chris Dickens <[email protected]>
2021-01-15 08:00:28 -08:00
Nathan Hjelm b31217fabe Update changelog in preperation for rolling 1.0.25
Signed-off-by: Nathan Hjelm <[email protected]>
2021-01-13 15:59:33 -07:00
Freek Dijkstra bf943bce82 MacOS: Silence pipe error in set_interface_alt_setting()
darwin_set_interface_altsetting() no longer returns the status of the underlying SetAlternateInterface(), but instead the result of a subsequent GetNumEndpoints() call. This reverts to the behaviour prior to commit 065e586.

Since darwin_set_interface_altsetting() resets the interface after SetAlternateInterface(), one of the consequences is that if SetAlternateInterface() returns a kIOUSBPipeStalled error, and the interface is successfully reset, darwin_set_interface_altsetting() now returns LIBUSB_SUCCESS instead of LIBUSB_ERROR_PIPE.

Closes: #838

Signed-off-by: Freek Dijkstra
Signed-off-by: Nathan Hjelm <[email protected]>
2021-01-13 15:57:15 -07:00
Chris Dickens 073f229fd1 Windows: Break dependency on OLE32
The OLE32 library provides the IIDFromString() function to parse a
string to a GUID, but we can implement a simple GUID parsing function
and remove this dependence. Doing so also avoids fetching the Unicode
form of the "DeviceInterfaceGUIDs" property.

Signed-off-by: Chris Dickens <[email protected]>
2020-12-19 15:33:56 -08:00
Chris Dickens 9cb2e5c111 Windows: Cleanup header includes and definiions
Now that a sufficiently recent toolchain is required to build, we can
drop a bunch of redundant definitions and get the definitions from the
Windows headers instead. We can also remove a number of '#ifndef'
guards because no header included by the source would have defined the
symbols being protected.

Signed-off-by: Chris Dickens <[email protected]>
2020-12-19 13:30:23 -08:00
Chris Dickens 40644b4622 travis: Turn off Homebrew updates
The builds no longer succeed on the xcode9.4 image because updating
Homebrew takes too much time. The packages we need from Homebrew are not
frequently updated, so using the latest formulae that the image provides
should be sufficient.

Signed-off-by: Chris Dickens <[email protected]>
2020-12-19 13:29:38 -08:00
Nathan Hjelm eed8a371ea Use stdatomic instead of gcc-internal atomics
The __atomic operations are internal to gcc and not necessarily supported
by all c11 compilers. Use the atomics in stdatomic instead.

Signed-off-by: Nathan Hjelm <[email protected]>
2020-12-16 20:57:57 -07:00
Chris Dickens 1a08aa84d9 core: Introduce atomic type and operations
An atomic variable is useful for reference counting and is much less
overhead than accessing such a variable while holding a lock. To that
end, replace the libusb_device 'refcnt' variable with an atomic and use
the atomic operations to manipulate it. This removes the need for the
mutex in the libusb_device.

Also convert the 'attached' variable to an atomic as well. This variable
was previously accessed both while holding the libusb_device mutex and
not.

Signed-off-by: Chris Dickens <[email protected]>
2020-12-16 10:35:45 -08:00
Chris Dickens f6d2cb5614 linux_usbfs: Fix parsing of descriptors for multi-configuration devices
Commit e2be556bd2 ("linux_usbfs: Parse config descriptors during device
initialization") introduced a regression for devices with multiple
configurations. The logic that verifies the reported length of the
configuration descriptors failed to count the length of the
configuration descriptor itself and would truncate the actual length by
9 bytes, leading to a parsing error for subsequent descriptors.

Closes #825

Signed-off-by: Chris Dickens <[email protected]>
2020-12-13 15:49:19 -08:00
Chris Dickens 369af149e3 Correct a typo in the Changelog and clean up a stray file
Signed-off-by: Chris Dickens <[email protected]>
2020-12-13 15:46:27 -08:00
Chris Dickens c6a35c5601 libusb 1.0.24
Signed-off-by: Chris Dickens <[email protected]>
v1.0.24
2020-12-10 10:53:59 -08:00
Aurelien Jarno 442305ec3d autotools: fix out-of-tree building of documentation
When building libusb out-of-tree, ie when running configure from another
directory, building the documentation fails with:

  $ make -C doc
  make: Entering directory '/tmp/build/doc'
  make: *** No rule to make target 'libusb.png', needed by 'api-1.0'.  Stop.
  make: Leaving directory '/tmp/build/doc'

This has likely been broken by commit 4a5540a925 ("autotools: Fix a number of
issues"). This patch fixes that by prefixing libusb.png with @top_srcdir@/doc.

Signed-off-by: Aurelien Jarno <[email protected]>
2020-12-03 18:51:45 +01:00
Mikolaj Kucharski cd431859fa fix eol of msvc/*.vcxproj and msvc/*.vcxproj.filters files
Closes #812
Closes #813

Signed-off-by: Chris Dickens <[email protected]>
2020-11-30 11:17:34 -08:00
Chris Dickens 42ad1d1d8a libusb 1.0.24-rc1
Signed-off-by: Chris Dickens <[email protected]>
v1.0.24-rc1
2020-11-27 21:56:30 -08:00
Chris Dickens 0e6161d3b6 Windows: Fix a few more benign compiler warnings
Signed-off-by: Chris Dickens <[email protected]>
2020-11-27 19:21:24 -08:00
Chris Dickens a2f1e2d5fd Windows: Support building dpfp and sam3u_benchmark with MSVC
Closes #151

Signed-off-by: Chris Dickens <[email protected]>
2020-11-27 18:39:53 -08:00
Chris Dickens 1be2ed9f14 Windows: Add missing header files to MSVC projects
Signed-off-by: Chris Dickens <[email protected]>
2020-11-27 15:56:02 -08:00
Chris Dickens f2e551a5ff build: Prepare config.h for inclusion in examples/tests
There are certain games played in the examples and tests source to
account for differences in build environments and target platforms. This
can be simplified by including config.h and using the definitions there.

To that end, move the printf function attribute definition from
libusbi.h to config.h and leverage it where it is used in the examples
and tests.

Signed-off-by: Chris Dickens <[email protected]>
2020-11-27 15:22:29 -08:00
Chris Dickens 9d23ed25b4 build: Fix Android and Xcode compilation errors/warnings
Commit f69548c3b3 ("examples: Enable all examples to build on all
platforms") modified dpfp and sam3u_benchmark to be buildable on any
platform, however there were some oversights and regressions introduced
for Android and Xcode.

Update the Android and Xcode build files to account for the removal of
dpfp_threaded.c as well as the inclusion of config.h from examples
and/or tests source.

Additionally switch the threaded version of dpfp to use sem_open()
instead of sem_init() as the latter is in fact deprecated on MacOS.

Closes #808

Signed-off-by: Chris Dickens <[email protected]>
2020-11-16 13:03:52 -08:00
Chris Dickens f69548c3b3 examples: Enable all examples to build on all platforms
Prior to this change, the dpfp and sam3u_benchmark examples were only
built on POSIX platforms due to a dependency on sigaction(). Furthermore
the dpfp_threaded example only worked with POSIX threads.

Lift this limitation by breaking the dependence on sigaction(). Also
provide a minimal threading abstraction so that dpfp_threaded can be
built on Windows as well.

Also merge the sources for dpfp and dpfp_threaded. The only difference
between the two is how libusb's event handling functions are called and
this can be easily handled within a single source file.

Signed-off-by: Chris Dickens <[email protected]>
2020-11-10 14:13:12 -08:00
Ihor Dutchak 851ff40400 Windows: ignore all broken devices during enumeration
- explicitly check/log info, when a device has broken descriptor;

Closes #791
Closes #806

Signed-off-by: Chris Dickens <[email protected]>
2020-11-09 18:54:44 -08:00
Chris Dickens 15668087a7 Fix various CI build warnings
* [-Wpointer-arith] arithmetic on a pointer to void is a GNU extension
  * [-Wswitch-enum] enumeration values 'E1, ...' not explicitly handled in switch
  * [-Wunused-parameter] unused parameter 'p'

For '-Wswitch-enum', the switch statements in the individual backends'
set_option() function has been removed. It is not expected that backends
will need to handle or be aware of all the options.

Signed-off-by: Chris Dickens <[email protected]>
2020-11-09 15:51:44 -08:00
Chris Dickens ab5dcf4f44 travis: Update build environments
Add Ubuntu's Focal distribution to get the latest Linux toolchain.

Add Xcode 12.2 to get the latest MacOS toolchain.

Remove Xcode 7.3 as it is now obsolete and will not successfully build.

Signed-off-by: Chris Dickens <[email protected]>
2020-11-09 11:01:10 -08:00
Chris Dickens a016a082a8 tests: Refactor testlib to simplify and fix Cygwin build
Signed-off-by: Chris Dickens <[email protected]>
2020-11-07 21:11:33 -08:00
Uwe Bonnes 84e860cfb9 libusb.h: Base Class EFh (Miscellaneous) was missing in class definition.
Closes #802

Signed-off-by: Chris Dickens <[email protected]>
2020-11-07 20:18:41 -08:00
Chris Dickens c3deb6dd64 Windows: Restrict path for dynamic library loading
The LoadLibraryA() function performs a search through various paths when
provided a library name that does not include a path element. All of the
libraries that libusb needs to dynamically load are installed in the
Windows system directory, thus it is not necessary to search any paths.

To harden the security of libusb and prevent loading libraries from
outside of the system directory should an attacker be able to alter the
environment or place an identically named library somewhere in the
search paths that occur before the Windows system directory, introduce a
function that calls LoadLibraryA() with a full path to the requested
library witin the Windows system directory. Note that we cannot call
SetDllDirectoryA() because as a library we should not alter the DLL
search path of the application. We also cannot use LoadLibraryExA() with
the LOAD_LIBRARY_SEARCH_* flags because those flags require a specific
security update to be installed on Vista and 7.

Signed-off-by: Chris Dickens <[email protected]>
2020-10-20 23:08:50 -07:00
Chris Dickens c33990a300 core: Iterate over completed transfers using the correct list node
Commit 006ca0fbaa ("Guard against getting stuck while handling events")
caused a regression using the wrong list node when iterating a list. Fix
this by introducing and using an alternate for_each iterator.

Closes #796

Signed-off-by: Chris Dickens <[email protected]>
2020-10-15 21:40:19 -07:00
Chris Dickens c71c991003 core: Fix the newly added list_splice_front() function
One statement was missing to preserve the consistency of the list.

Signed-off-by: Chris Dickens <[email protected]>
2020-10-15 21:18:49 -07:00
Chris Dickens eee6998395 core: Fix unused variable warnings on release builds
The recently introduced PTHREAD_CHECK and WINAPI_CHECK macros cause a
large number of compiler warnings for unused variables on release
builds. Fix this by implementing those macros in terms of some new
macros that are defined based on the definition of NDEBUG.

Closes #788

Signed-off-by: Chris Dickens <[email protected]>
2020-09-28 17:10:04 -07:00
Nathan Hjelm 70c0a51ba3 darwin: code cleanup in darwin_handle_transfer_completion
This commit adds an extra parameter check to darwin_handle_transfer_completion
and cleans the code up a bit.

Signed-off-by: Nathan Hjelm <[email protected]>
2020-09-14 22:09:55 -06:00
Nathan Hjelm a1855022a0 libusbi.h: fix warning about redefined macros
In macOS 11.x the USEC_PER_SEC and NSEC_PER_SEC are defined by a system
header. The values are the same so use the system defines if they are
available.

Signed-off-by: Nathan Hjelm <[email protected]>
2020-09-14 22:09:07 -06:00
Hans de Goede 1be063f7bf examples/testlibusb: Print speed of devices
Print the speed of devices to exercise libusb_get_device_speed().

Signed-off-by: Hans de Goede <[email protected]>
2020-09-14 09:48:14 +02:00
Hans de Goede dca3e7ea36 examples/testlibusb: Add support for testing libusb_wrap_sys_device()
Sometimes it is useful to be able to test libusb_wrap_sys_device(),
add support for this to the testlibusb example

Signed-off-by: Hans de Goede <[email protected]>
2020-09-14 09:48:14 +02:00
Hans de Goede f6068e83c4 linux: Fix libusb_get_device_speed() not working on wrapped devices
We don't have a sysfs_dir for wrapped devices, so we cannot read the speed
from sysfs.

The Linux kernel has supported a new ioctl to get the speed directly from
the fd for a while now, use that when we don't have sysfs access.

Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=1871818
Reported-by: Gerd Hoffmann <[email protected]>
Signed-off-by: Hans de Goede <[email protected]>
2020-09-14 09:48:14 +02:00
Chris Dickens a6bfd45dea Doxygen: Fix warnings about undocumented compounds
Commit fa3f91e7c4 ("descriptor: Miscellaneous improvements to the
overall source") introduced some union types, however since descriptor.c
is parsed by Doxygen it will complain with the following warnings:

  libusb/descriptor.c:49: warning: Compound string_desc_buf is not documented.
  libusb/descriptor.c:55: warning: Compound bos_desc_buf is not documented.
  libusb/descriptor.c:43: warning: Compound config_desc_buf is not documented.

Fix this by moving the union definitions into libusbi.h.

Signed-off-by: Chris Dickens <[email protected]>
2020-09-13 00:09:32 -07:00