platform/upstream/libusb.git
2 years agocore: update usbi_dbg to take the context as an argument
Nathan Hjelm [Tue, 20 Jul 2021 15:31:06 +0000 (09:31 -0600)]
core: update usbi_dbg to take the context as an argument

This commit fixes a performance issue caused by the disconnection of the first context
allocated from the default context. usbi_dbg now takes the explicit context instead of
relying on the default context (which may not exist) in most cases. All call sites have
been updated to pass the context or explicitly pass NULL if the context is not
available. We should actively discourage using NULL as the context in the future and
patch all call sites to always pass the context.

Fixes #951

Signed-off-by: Nathan Hjelm <hjelmn@google.com>
2 years agodarwin: downgrade error message on failure to open interface to info
Nathan Hjelm [Tue, 20 Jul 2021 21:48:27 +0000 (15:48 -0600)]
darwin: downgrade error message on failure to open interface to info

This resolves an issue introduced by the implementation of the kernel detach code. This
code used claim_interface to detect if a kernel driver is attached. The issue is that if
a driver is attached or the interface is not available and an error message was printed
out. Since this is not an error the info level is more appropriate.

Also downgrading a number of warnings to clean up the output.

Closes #955

Signed-off-by: Nathan Hjelm <hjelmn@google.com>
2 years agodarwin: add a comment on how the bus number is calculated
Nathan Hjelm [Tue, 20 Jul 2021 21:44:59 +0000 (15:44 -0600)]
darwin: add a comment on how the bus number is calculated

This commit adds a comment about the bus number calculation to indicate how the
location ID is constructed and why libusb is using the top byte for the bus
number. It also indicates that the bus number starts at 0.

Signed-off-by: Nathan Hjelm <hjelmn@google.com>
2 years agodarwin: update the list of endpoints after successfull SetAlternateInterface()
Dmitry Zakablukov [Tue, 13 Jul 2021 14:50:28 +0000 (17:50 +0300)]
darwin: update the list of endpoints after successfull SetAlternateInterface()

Closes #950

Signed-off-by: Nathan Hjelm <hjelmn@google.com>
2 years agowinusb: Ignore missing DeviceInterfaceGUID
Tormod Volden [Sun, 11 Jul 2021 12:40:01 +0000 (14:40 +0200)]
winusb: Ignore missing DeviceInterfaceGUID

Closes #948

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
Signed-off-by: Nathan Hjelm <hjelmn@google.com>
2 years agodarwin: improve support for auto-detaching a kernel driver
Nathan Hjelm [Fri, 9 Jul 2021 15:17:33 +0000 (09:17 -0600)]
darwin: improve support for auto-detaching a kernel driver

This commit improves the code around auto attach/detach of a kernel driver:

 - Log a warning when a driver can not be auto-detached and continue when claiming an
   interface. It could be the case that the interface has no driver attached or that
   the claim will still succeed.

 - Log a warning if the driver can not be auto-attached and return success when
   releasing an interface. The operation did complete successfully but the
   re-enumeration may have failed. This can be discovered on the next device
   access.

Signed-off-by: Nathan Hjelm <hjelmn@google.com>
2 years agodarwin: fix SEGV on libusb_close after failed re-enumeration
Nathan Hjelm [Fri, 9 Jul 2021 04:43:28 +0000 (22:43 -0600)]
darwin: fix SEGV on libusb_close after failed re-enumeration

This commit fixes an issue that can occur if the user calls libusb_close after a failed attempt
of libusb_reset (re-enumerate). This can lead to an attempt to dereference dpriv->device which
was set to NULL during the re-enumeration.

Signed-off-by: Nathan Hjelm <hjelmn@google.com>
2 years ago[Issue-912] Lock open_devs_lock in context to avoid access violation
Dmitry Zakablukov [Wed, 30 Jun 2021 16:45:53 +0000 (19:45 +0300)]
[Issue-912] Lock open_devs_lock in context to avoid access violation

Closes #943

Signed-off-by: Nathan Hjelm <hjelmn@google.com>
2 years agoNew NO_DEVICE_DISCOVERY option to replace WEAK_AUTHORITY option
Tormod Volden [Tue, 15 Jun 2021 20:33:45 +0000 (22:33 +0200)]
New NO_DEVICE_DISCOVERY option to replace WEAK_AUTHORITY option

The option disables device enumeration (and hotplug, which depends on
enumeration). Since this has a much broader usage scope than "weak
authority", give the option a name reflecting what it does.

For now, keep the old option name working as an alias.

Closes #935

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
Signed-off-by: Nathan Hjelm <hjelmn@google.com>
2 years agowindows: Allow GUID with and without trailing zeroes
Craig Hutchinson [Tue, 8 Jun 2021 18:03:43 +0000 (20:03 +0200)]
windows: Allow GUID with and without trailing zeroes

Improve the GUID length check to accommodate the cases where the GUID
string fetched from registry does not have a trailing zero, or if a
multi-string entry, one or two trailing zeroes.

Closes #927

Signed-off-by: Craig Hutchinson <54269136+CraigHutchinson@users.noreply.github.com>
[Tormod: Use correct types and simplify comparisons]
Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
Signed-off-by: Nathan Hjelm <hjelmn@google.com>
2 years agoFix build failure on Mac OS X 10.7
Ryan Schmidt [Sat, 12 Jun 2021 03:19:49 +0000 (22:19 -0500)]
Fix build failure on Mac OS X 10.7

Apple documentation says kUSBDeviceSpeedSuper is available in 10.7 and
later but in fact it is only defined in the 10.8 SDK and later.

Closes #410
Closes #929

Signed-off-by: Nathan Hjelm <hjelmn@google.com>
2 years agodarwin: release device parent reference when re-enumerating device
Nathan Hjelm [Sat, 12 Jun 2021 04:27:19 +0000 (22:27 -0600)]
darwin: release device parent reference when re-enumerating device

This commit fixes a dangling device reference that can occur when a device is
being re-enumerated. The problem is the code was unconditionally re-caching the
parent device which then takes a reference on the parent device. If the field
was already populated this reference was not needed. To ensure the code works
even if the parent device also changes during the re-enumeration the code
release the parent reference and grabs a fresh reference.

Fixes #924

Signed-off-by: Nathan Hjelm <hjelmn@google.com>
2 years agoDo not restrict "weak authority" option to Android
Tormod Volden [Mon, 7 Jun 2021 16:19:41 +0000 (18:19 +0200)]
Do not restrict "weak authority" option to Android

libusb_wrap_sys_device() is an often needed feature on Android, but can
also be very convenient on other Linux platforms.

In many cases the initial device scanning is not needed and
LIBUSB_OPTION_WEAK_AUTHORITY thus provides a performance enhancement.

Closes #925

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
Signed-off-by: Nathan Hjelm <hjelmn@google.com>
2 years agocore: really fix dangling devices
Nathan Hjelm [Fri, 11 Jun 2021 13:59:23 +0000 (07:59 -0600)]
core: really fix dangling devices

The prior fix made an incorrect assumption about the reference counting of
parent devices. This CL fixes the issue by checking if the parent device
should be removed from the list as well. This is needed as when the child
device is released the parent may also be released.

Closes #924

Signed-off-by: Nathan Hjelm <hjelmn@google.com>
2 years agodarwin_set_interface_altsetting: Avoid device reset on pipe error
Tormod Volden [Thu, 14 Jan 2021 19:59:56 +0000 (20:59 +0100)]
darwin_set_interface_altsetting: Avoid device reset on pipe error

If the device doesn't support the SET_INTERFACE request (which is
allowed if there are no alternate interfaces) it should stall the pipe.
A successful device request would clear all endpoints of the interface.
We therefore plaster over the failed request by clearing the endpoints
and returning success, effectively replacing the missing device request
support.

Up to now this was done by resetting the device, but this would affect
other interfaces as well. So only clear the endpoints of the selected
interface.

Only do this in the case the request tried setting the already
selected setting. Otherwise return the pipe error to the caller.

For any other error than pipe error return with failure.

Note that we need to reclaim the interface after the pipe error.
This is maybe papering over a bug in libusb or darwin: The interface
becomes inaccessible after the failed SetAlternateInterface() call. The
reclaim recovers from it, without device side-effects. The need to
recover was maybe the reason for the original reset "hammer".

Closes #852

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
Signed-off-by: Nathan Hjelm <hjelmn@google.com>
2 years agowinusb: Check for ClassGuid changes on re-enumeration
Tormod Volden [Thu, 25 Mar 2021 22:47:27 +0000 (23:47 +0100)]
winusb: Check for ClassGuid changes on re-enumeration

Previously only the dev_id (VID/PID/serial) was checked, but if the
bcdDevice has changed, Windows will have re-enumerated the device and
possibly attributed another ClassGuid to it.

Fixes issue #897.
Closes #900

Thanks to Craig Hutchinson for reporting, suggestion and testing.

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
Signed-off-by: Nathan Hjelm <hjelmn@google.com>
2 years agocore: only increment devices_released when a device is destroyed
Nathan Hjelm [Fri, 11 Jun 2021 03:02:05 +0000 (21:02 -0600)]
core: only increment devices_released when a device is destroyed

Fix a typo in the last commit to ensure the loop does exit when there is
a dangling reference.

Signed-off-by: Nathan Hjelm <hjelmn@google.com>
2 years agocore: ensure that all devices are properly cleaned up on libusb_exit
Nathan Hjelm [Fri, 11 Jun 2021 02:51:44 +0000 (20:51 -0600)]
core: ensure that all devices are properly cleaned up on libusb_exit

When cleaning up the context on libusb_exit the last step is to to call
hotplug_exit. This function took one pass over the devices and released any
devices where the reference count had reached 0. All remaining devices
were assumed to have leaked references and a warning message was printed
out. Unfortunately, this cleanup was too simplistic. It ignored the
references created when a device was the parent of another device (which
takes a reference). This reference is released when the child device is
released.

To ensure that we do not erroneously warn about devices with leftover
references the code now loops over the device list until no more devices
have a single reference. This ensures that we will eventually remove
all devices with no external references.

Fixes #924

Signed-off-by: Nathan Hjelm <hjelmn@google.com>
2 years agocore: allow libusb_set_option on the default context before libusb_init
Nathan Hjelm [Sun, 6 Jun 2021 18:19:05 +0000 (12:19 -0600)]
core: allow libusb_set_option on the default context before libusb_init

This commit updates libusb_set_option to save the options if setting them on the default
context. This ensures the options 1) can be set before libusb_init(NULL, ...), and 2)
are honored even if the default context is destroyed and re-created.

Signed-off-by: Nathan Hjelm <hjelmn@google.com>
2 years agoWindows: Try alternative methods to query port number
Jim Chen [Wed, 3 Feb 2021 18:13:55 +0000 (13:13 -0500)]
Windows: Try alternative methods to query port number

This commit is similar to #634 but I think it offers a better approach. The commit adds two more methods for querying the port number, in addition to the existing SPDRP_ADDRESS method, which may not actually return the port number when using USB drivers other than the Microsoft driver.

The first method uses SPDRP_LOCATION_INFORMATION, which may return a port in a format similar to "Port_#0002.Hub_#000D".

The second method uses SPDRP_LOCATION_PATHS, which returns the device location in a format similar to "PCIROOT(B2)#PCI(0300)#PCI(0000)#USBROOT(0)#USB(1)#USB(2)#USBMI(3)", where the port number is the number within the last "#USB()" token.

If both methods fail, SPDRP_ADDRESS is still used as a fallback.

Closes #867

Signed-off-by: Nathan Hjelm <hjelmn@google.com>
2 years agoWindows: Support LIBUSB_TRANSFER_ADD_ZERO_PACKET on winusb
Patrick Stewart [Fri, 9 Jun 2017 19:54:45 +0000 (20:54 +0100)]
Windows: Support LIBUSB_TRANSFER_ADD_ZERO_PACKET on winusb

Closes #312

Signed-off-by: Nathan Hjelm <hjelmn@google.com>
2 years agodoc: Add since version tag to libusb_wrap_sys_device()
Ihor Dutchak [Mon, 17 May 2021 20:56:34 +0000 (23:56 +0300)]
doc: Add since version tag to libusb_wrap_sys_device()

Closes #914

Signed-off-by: Nathan Hjelm <hjelmn@google.com>
2 years agodoc: correction of LIBUSB_OPTION_WEAK_AUTHORITY availability
Ihor Dutchak [Fri, 21 May 2021 12:32:24 +0000 (15:32 +0300)]
doc: correction of LIBUSB_OPTION_WEAK_AUTHORITY availability

Even though its implementation is in linux/usbfs,
in fact it is under `ifdef` and only used by Android builds.

Closes #916

Signed-off-by: Nathan Hjelm <hjelmn@google.com>
2 years agodarwin: do not reset darwin_cached_devices on last call to libusb_exit
Nathan Hjelm [Sun, 6 Jun 2021 15:29:41 +0000 (09:29 -0600)]
darwin: do not reset darwin_cached_devices on last call to libusb_exit

This fixes a bug in the change that removed the library destructor function. We should not
be setting the darwin_cached_devices next and prev pointers to NULL as other parts of
libusb may still have references to the devices (hotplug for example). When those references
are release it may modify darwin_cached_devices. This commit fixes the issue by only
initializing darwin_cached_devices on the very first call to libusb_init and not modifying
darwin_cached_devices in libusb_exit (beyond unrefing the devices).

Signed-off-by: Nathan Hjelm <hjelmn@google.com>
2 years agocore: Refactor initialization and how the default context is handled
Chris Dickens [Wed, 20 Jan 2021 19:18:35 +0000 (11:18 -0800)]
core: Refactor initialization and how the default context is handled

Highlights for this change:

 - usbi_default_context is only set if libusb_init() is called with NULL.
 - All hotplug related functionality (e.g. initialization, processing) has been
   moved to hotplug.c
 - Backends are simplified by removing initialization mutexes. Mutual exclusion
   between init()/exit() is provided by default_context_lock.
 - Make hotplug types and functions part of libusbi.h with the common usbi_
   prefixes (removes hotplug.h).

Addresses issue highlighted in #855

Closes #856

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Signed-off-by: Nathan Hjelm <hjelmn@google.com>
3 years agomake libusb.h usable with Watcom
Ozkan Sezer [Sun, 4 Apr 2021 08:11:10 +0000 (11:11 +0300)]
make libusb.h usable with Watcom

Closes #904

Signed-off-by: Nathan Hjelm <hjelmn@google.com>
3 years agoUpdate ChangeLog in preparation for 1.0.25
Nathan Hjelm [Sun, 16 May 2021 21:18:06 +0000 (15:18 -0600)]
Update ChangeLog in preparation for 1.0.25

Signed-off-by: Nathan Hjelm <hjelmn@google.com>
3 years agodarwin: remove redundant macOS version checks
osy [Wed, 12 May 2021 04:01:11 +0000 (21:01 -0700)]
darwin: remove redundant macOS version checks

The InterfaceVersion is what we want and there is no reason to also check
that the InterfaceVersion matches the macOS version it was introduced in.
This check inadvertently disables features for other Apple platforms that
use IOKit.

Closes #911

Signed-off-by: Nathan Hjelm <hjelmn@google.com>
3 years agodarwin: add authorization for device capture
osy [Wed, 12 May 2021 03:58:59 +0000 (20:58 -0700)]
darwin: add authorization for device capture

To use USBDeviceReEnumerate with kUSBReEnumerateCaptureDeviceMask your app
either needs to be running as root OR have the 'com.apple.vm.device-access'
entitlement AND have the user authorization requested via
IOServiceAuthorize().

We can use the capture re-enumerate APIs if either 1) the process is running
as root or 2) the 'com.apple.vm.device-access' entitlement is used AND
IOServiceAuthorize() is called. We assume that if the entitlement is not
there then we are running as root--if this is not true, then
darwin_detach_kernel_driver will fail anyways.

The authorization status is cached in the device's start() so we have to
stop() and start() the device by destroying the plugin and recreating it
again.

Signed-off-by: Nathan Hjelm <hjelmn@google.com>
3 years agodarwin: use detach kernel APIs for capture
osy [Wed, 12 May 2021 03:56:27 +0000 (20:56 -0700)]
darwin: use detach kernel APIs for capture

When libusb_detach_kernel_driver() is called on the first interface, we use
the capture re-enumerate APIs to force kernel drivers to detach. On
subsequent calls, a counter is incremented to keep track of the number of
detach calls. When libusb_attach_kernel_driver() is called for the same
number of times, then we re-enumerate (reset) and let kernel drivers
re-attach.

darwin_kernel_driver_active() is changed to attempt to claim an interface
and return 1 only if a kIOReturnExclusiveAccess status is returned. The old
implementation which looks for a CFBundleID in the IORegistryEntry does not
seem to work in all cases.

darwin_reset_device() is aware of the capture status and will re-set twice
if capture mode is enabled: once to do a USB reset and again to re-capture.

Signed-off-by: Nathan Hjelm <hjelmn@google.com>
3 years agodarwin: rename darwin_reset_device
osy [Wed, 12 May 2021 03:45:44 +0000 (20:45 -0700)]
darwin: rename darwin_reset_device

Since it calls USBDeviceReEnumerate() and not USBDeviceReset(), we name
it accordingly.

Signed-off-by: Nathan Hjelm <hjelmn@google.com>
3 years agodarwin: add timeout for reset reenumerate
osy [Wed, 12 May 2021 03:36:31 +0000 (20:36 -0700)]
darwin: add timeout for reset reenumerate

USBDeviceReEnumerate() does not return an error code (bug?) so if it fails
we could be stuck waiting forever. Set a sane timeout to 10s.

Signed-off-by: Nathan Hjelm <hjelmn@google.com>
3 years agoautogen: Support being called from external build dir
Marco Trevisan (Treviño) [Tue, 13 Apr 2021 17:07:46 +0000 (19:07 +0200)]
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 <ludovic.rousseau@free.fr>
3 years agoDoxygen: fix warning about PAPER_TYPE
Ludovic Rousseau [Mon, 22 Feb 2021 20:34:10 +0000 (21:34 +0100)]
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 <ludovic.rousseau@free.fr>
3 years agoDoxygen: update config file from 1.8.16 to 1.9.0
Ludovic Rousseau [Mon, 22 Feb 2021 16:58:00 +0000 (17:58 +0100)]
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 <ludovic.rousseau@free.fr>
3 years agodarwin: Don't drop partial data on timeout
Vegard Storheil Eriksen [Mon, 15 Feb 2021 21:57:06 +0000 (22:57 +0100)]
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 <hjelmn@cs.unm.edu>
3 years agodoc: Add since version tag to libusb_set_log_cb()
Victor Toso [Thu, 11 Feb 2021 11:06:00 +0000 (12:06 +0100)]
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 <victortoso@redhat.com>
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
3 years agolinux_usbfs: Gracefully handle buggy devices with a configuration 0
Chris Dickens [Mon, 8 Feb 2021 19:56:13 +0000 (11:56 -0800)]
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 <christopher.a.dickens@gmail.com>
3 years agolinux_usbfs: Accept sysfs attributes not terminated with newline
Chris Dickens [Mon, 8 Feb 2021 17:27:20 +0000 (09:27 -0800)]
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 <christopher.a.dickens@gmail.com>
3 years agolinux_netlink: Change order of header includes per netlink(7)
Chris Dickens [Mon, 8 Feb 2021 17:06:42 +0000 (09:06 -0800)]
linux_netlink: Change order of header includes per netlink(7)

Closes #869

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
3 years agodarwin: fix const array size to work with GCC compilers
Michael Dickens [Wed, 30 Dec 2020 02:32:45 +0000 (21:32 -0500)]
darwin: fix const array size to work with GCC compilers

Closes #833

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
3 years agoWindows: Fix HID and synchronous transfer completion
Chris Dickens [Mon, 1 Feb 2021 23:12:17 +0000 (15:12 -0800)]
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 <christopher.a.dickens@gmail.com>
3 years agoWindows: Filter out non-libusb I/O completions
Chris Dickens [Sat, 16 Jan 2021 01:18:34 +0000 (17:18 -0800)]
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 <christopher.a.dickens@gmail.com>
3 years agoconfigure.ac: Consider Mac OS X target version for clock_gettime()
Chris Dickens [Fri, 15 Jan 2021 20:42:35 +0000 (12:42 -0800)]
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 <christopher.a.dickens@gmail.com>
3 years agolinux_usbfs: Fix exit crash on Android
Mark Kuo [Sun, 10 Jan 2021 05:58:26 +0000 (16:58 +1100)]
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 <starryalley@gmail.com>
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
3 years agowindows: Update link about control transfer size limits
Tormod Volden [Tue, 5 Jan 2021 18:46:39 +0000 (19:46 +0100)]
windows: Update link about control transfer size limits

Closes #839

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
3 years agolibusb/core.c: bump DISCOVERED_DEVICES_SIZE_STEP to 16
Mikolaj Kucharski [Fri, 1 Jan 2021 15:43:29 +0000 (15:43 +0000)]
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 <kili@openbsd.org>
on Tue Jun 19 21:10:59 2012 UTC

Closes #835

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
3 years agoPrefix hex values with 0x in core.c and os/openbsd_usb.c
Mikolaj Kucharski [Sun, 27 Dec 2020 14:02:49 +0000 (14:02 +0000)]
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 <christopher.a.dickens@gmail.com>
3 years agoUpdate changelog in preperation for rolling 1.0.25
Nathan Hjelm [Wed, 13 Jan 2021 22:59:33 +0000 (15:59 -0700)]
Update changelog in preperation for rolling 1.0.25

Signed-off-by: Nathan Hjelm <hjelmn@google.com>
3 years agoMacOS: Silence pipe error in set_interface_alt_setting()
Freek Dijkstra [Mon, 11 Jan 2021 00:49:42 +0000 (01:49 +0100)]
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 <hjelmn@google.com>
3 years agoWindows: Break dependency on OLE32
Chris Dickens [Sat, 19 Dec 2020 23:33:56 +0000 (15:33 -0800)]
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 <christopher.a.dickens@gmail.com>
3 years agoWindows: Cleanup header includes and definiions
Chris Dickens [Sat, 19 Dec 2020 21:30:23 +0000 (13:30 -0800)]
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 <christopher.a.dickens@gmail.com>
3 years agotravis: Turn off Homebrew updates
Chris Dickens [Sat, 19 Dec 2020 21:29:38 +0000 (13:29 -0800)]
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 <christopher.a.dickens@gmail.com>
3 years agoUse stdatomic instead of gcc-internal atomics
Nathan Hjelm [Thu, 17 Dec 2020 03:57:57 +0000 (20:57 -0700)]
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 <hjelmn@google.com>
3 years agocore: Introduce atomic type and operations
Chris Dickens [Wed, 16 Dec 2020 18:35:45 +0000 (10:35 -0800)]
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 <christopher.a.dickens@gmail.com>
3 years agolinux_usbfs: Fix parsing of descriptors for multi-configuration devices
Chris Dickens [Sun, 13 Dec 2020 23:49:19 +0000 (15:49 -0800)]
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 <christopher.a.dickens@gmail.com>
3 years agoCorrect a typo in the Changelog and clean up a stray file
Chris Dickens [Sun, 13 Dec 2020 23:46:27 +0000 (15:46 -0800)]
Correct a typo in the Changelog and clean up a stray file

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
3 years agolibusb 1.0.24 upstream/1.0.24
Chris Dickens [Thu, 10 Dec 2020 18:53:59 +0000 (10:53 -0800)]
libusb 1.0.24

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
3 years agoautotools: fix out-of-tree building of documentation
Aurelien Jarno [Wed, 2 Dec 2020 22:46:40 +0000 (23:46 +0100)]
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 4a5540a925e4 ("autotools: Fix a number of
issues"). This patch fixes that by prefixing libusb.png with @top_srcdir@/doc.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
3 years agofix eol of msvc/*.vcxproj and msvc/*.vcxproj.filters files
Mikolaj Kucharski [Mon, 30 Nov 2020 15:51:34 +0000 (15:51 +0000)]
fix eol of msvc/*.vcxproj and msvc/*.vcxproj.filters files

Closes #812
Closes #813

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
3 years agolibusb 1.0.24-rc1
Chris Dickens [Sat, 28 Nov 2020 05:56:30 +0000 (21:56 -0800)]
libusb 1.0.24-rc1

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
3 years agoWindows: Fix a few more benign compiler warnings
Chris Dickens [Sat, 28 Nov 2020 02:42:52 +0000 (18:42 -0800)]
Windows: Fix a few more benign compiler warnings

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
3 years agoWindows: Support building dpfp and sam3u_benchmark with MSVC
Chris Dickens [Sat, 28 Nov 2020 02:39:53 +0000 (18:39 -0800)]
Windows: Support building dpfp and sam3u_benchmark with MSVC

Closes #151

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
3 years agoWindows: Add missing header files to MSVC projects
Chris Dickens [Fri, 27 Nov 2020 23:56:02 +0000 (15:56 -0800)]
Windows: Add missing header files to MSVC projects

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
3 years agobuild: Prepare config.h for inclusion in examples/tests
Chris Dickens [Fri, 27 Nov 2020 23:22:29 +0000 (15:22 -0800)]
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 <christopher.a.dickens@gmail.com>
3 years agobuild: Fix Android and Xcode compilation errors/warnings
Chris Dickens [Mon, 16 Nov 2020 21:03:52 +0000 (13:03 -0800)]
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 <christopher.a.dickens@gmail.com>
3 years agoexamples: Enable all examples to build on all platforms
Chris Dickens [Tue, 15 Sep 2020 21:15:00 +0000 (14:15 -0700)]
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 <christopher.a.dickens@gmail.com>
3 years agoWindows: ignore all broken devices during enumeration
Ihor Dutchak [Mon, 9 Nov 2020 23:39:28 +0000 (01:39 +0200)]
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 <christopher.a.dickens@gmail.com>
3 years agoFix various CI build warnings
Chris Dickens [Mon, 9 Nov 2020 23:51:44 +0000 (15:51 -0800)]
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 <christopher.a.dickens@gmail.com>
3 years agotravis: Update build environments
Chris Dickens [Mon, 9 Nov 2020 19:01:10 +0000 (11:01 -0800)]
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 <christopher.a.dickens@gmail.com>
3 years agotests: Refactor testlib to simplify and fix Cygwin build
Chris Dickens [Sun, 13 Sep 2020 22:30:04 +0000 (15:30 -0700)]
tests: Refactor testlib to simplify and fix Cygwin build

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
3 years agolibusb.h: Base Class EFh (Miscellaneous) was missing in class definition.
Uwe Bonnes [Sun, 25 Oct 2020 11:50:06 +0000 (12:50 +0100)]
libusb.h: Base Class EFh (Miscellaneous) was missing in class definition.

Closes #802

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
3 years agoWindows: Restrict path for dynamic library loading
Chris Dickens [Wed, 21 Oct 2020 06:08:50 +0000 (23:08 -0700)]
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 <christopher.a.dickens@gmail.com>
3 years agocore: Iterate over completed transfers using the correct list node
Chris Dickens [Fri, 16 Oct 2020 04:40:19 +0000 (21:40 -0700)]
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 <christopher.a.dickens@gmail.com>
3 years agocore: Fix the newly added list_splice_front() function
Chris Dickens [Sun, 13 Sep 2020 22:28:16 +0000 (15:28 -0700)]
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 <christopher.a.dickens@gmail.com>
3 years agocore: Fix unused variable warnings on release builds
Chris Dickens [Tue, 29 Sep 2020 00:10:04 +0000 (17:10 -0700)]
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 <christopher.a.dickens@gmail.com>
3 years agodarwin: code cleanup in darwin_handle_transfer_completion
Nathan Hjelm [Tue, 15 Sep 2020 04:09:55 +0000 (22:09 -0600)]
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 <hjelmn@google.com>
3 years agolibusbi.h: fix warning about redefined macros
Nathan Hjelm [Tue, 15 Sep 2020 04:06:14 +0000 (22:06 -0600)]
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 <hjelmn@google.com>
3 years agoexamples/testlibusb: Print speed of devices
Hans de Goede [Mon, 7 Sep 2020 09:25:54 +0000 (11:25 +0200)]
examples/testlibusb: Print speed of devices

Print the speed of devices to exercise libusb_get_device_speed().

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
3 years agoexamples/testlibusb: Add support for testing libusb_wrap_sys_device()
Hans de Goede [Mon, 7 Sep 2020 09:12:16 +0000 (11:12 +0200)]
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 <hdegoede@redhat.com>
3 years agolinux: Fix libusb_get_device_speed() not working on wrapped devices
Hans de Goede [Mon, 7 Sep 2020 08:30:54 +0000 (10:30 +0200)]
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 <kraxel@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
3 years agoDoxygen: Fix warnings about undocumented compounds
Chris Dickens [Fri, 28 Aug 2020 22:42:41 +0000 (15:42 -0700)]
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 <christopher.a.dickens@gmail.com>
3 years agothreads_posix: Use monotonic clock for condition variables where possible
Chris Dickens [Thu, 27 Aug 2020 20:54:21 +0000 (13:54 -0700)]
threads_posix: Use monotonic clock for condition variables where possible

The pthread_condattr_setclock() function allows one to specify that the
condition variable use CLOCK_MONOTONIC as the base for timed waits. This
is desirable to avoid premature timeouts if the system time is adjusted
while a timed wait is occurring. Add a check for the availability of
this function and use it where possible.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
3 years agocore: Split usbi_clock_gettime() into two separate functions
Chris Dickens [Thu, 27 Aug 2020 20:46:32 +0000 (13:46 -0700)]
core: Split usbi_clock_gettime() into two separate functions

Most of the library only uses the monotonic clock. In fact, the only use
of the realtime clock is to implement the POSIX version of
usbi_cond_timedwait(). Now that Windows can no longer use the POSIX
thread abstraction, there is no need for Windows to implement a means of
reading the realtime clock.

This change replaces usbi_clock_gettime() with usbi_get_monotonic_time()
and usbi_get_real_time(). When clock_gettime() is available, both
functions are implemented as simple inline calls, otherwise the backend
must provide a definition for usbi_get_monotonic_time() *AND*
usbi_get_real_time() iff the platform is POSIX.

Reading the clocks is also never expected to fail. In practice, if it
ever did there would be much more than libusb that would not function
correctly. The new functions therefore have no return value, thus
allowing the callers to assume success and remove a bunch of error
handling code. The clock_gettime() wrappers have a simple error check
that is only enforced in debug builds.

This change also makes it unnecessary to check for and use
clock_gettime() on Windows, so remove it and always provide
usbi_get_monotonic_time().

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
3 years agocore: Add validation to timeval parameters
Chris Dickens [Thu, 27 Aug 2020 18:05:11 +0000 (11:05 -0700)]
core: Add validation to timeval parameters

Prior to this change, the timeval structures provided by users did not
go through any type of validation, therefore an invalid timeval would
result in potentially unclear or confusing errors when used later on.
Add checks to the core API functions that accept timevals and return
LIBUSB_ERROR_INVALID_PARAM if the timeval is not valid.

While at it, add some macro definitions to avoid magic numbers.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
3 years agocore: Miscellaneous internal logging cleanup
Chris Dickens [Thu, 27 Aug 2020 17:58:10 +0000 (10:58 -0700)]
core: Miscellaneous internal logging cleanup

  * Correct comments for usbi_{sn,vsn}printf(); strings are terminated
    with a NUL byte (ASCII value), not NULL (pointer value)
  * Make usbi_log_v() static; it is not used anywhere else in the
    library
  * Remove an unnecessary NUL-termination
  * Remove check for LIBUSB_LOG_LEVEL_NONE in log_str()
  * Remove UNICODE case for system logging on Windows; it was only used
    for WinCE
  * Remove 'usbi_' prefix from static functions
  * Simplify check for whether the logging level is sufficiently high to
    allow the message to be printed
  * Avoid calling usbi_clock_gettime() unless the timestamp will
    actually be used
  * Use the monotonic clock for logging timestamps; this prevents jumps
    in the timestamps if the system clock is changed
  * Use TIMESPEC_SUB() macro to get relative timestamp instead of
    open-coding the calculation
  * Use PRIxPTR to print sys_dev in libusb_wrap_sys_device() instead of
    casting to a void pointer

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
3 years agocore: Simplify thread abstractions and add debug checks
Chris Dickens [Thu, 27 Aug 2020 00:42:59 +0000 (17:42 -0700)]
core: Simplify thread abstractions and add debug checks

The POSIX thread mutex initialization function can potentially fail, but
in practice this is unlikely to occur. There is also inconsistent use of
the result of the mutex initialization within the library. The result is
only checked for mutexes in the libusb_device and libusb_device_handle
structures but is ignored in all other cases.

Simplify the mutex initialization function by changing the abstraction's
wrapper to a void function, much like all the other functions that
already exist. To that end, introduce macros for the abstractions that
will check the return value on debug builds.

Also remove the dependence on the core library needing errno.h to
translate errors from usbi_cond_timedwait(). The abstraction will
convert the implementation-specific error codes to LIBUSB_ERROR values.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
3 years agobuild: Merge events and threads into single platform abstraction
Chris Dickens [Wed, 26 Aug 2020 22:42:39 +0000 (15:42 -0700)]
build: Merge events and threads into single platform abstraction

The split between events and threads abstractions is unnecessary.
Simplify the library by merging the two into a "platform" abstraction.
The only meaningful change is that Cygwin builds will no longer use the
POSIX threads abstraction but will instead use the native Windows one.

The downside to doing this is that the dpfp_threaded example program
will no longer be available on Cygwin builds. This should be fine, and
future work will make dpfp_threaded available for all forms of Windows
build systems.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
3 years agoGuard against getting stuck while handling events
Chris Dickens [Sun, 13 Sep 2020 01:39:28 +0000 (18:39 -0700)]
Guard against getting stuck while handling events

Alba Mendez (user mildsunrise) reports that a thread can get stuck at a
specific point while handling events, thus preventing other events from
being handled. This change addresses two such points in the code:

  1) When processing completed transfers in handle_event_trigger(), the
     function wll loop for as long as the completed_transfers list is
     not empty. Since the event data lock is released and reacquired for
     each completed transfer, it is possible for the completed_transfers
     list to never be emptied. Address this by cutting the list and only
     process the transfers that have completed at that point in time.

  2) When processing events, the Linux backend will reap transfers for
     each device that indicates activity until the reap fails (either
     because there are no completed transfers or some other error
     occurs). It is possible for transfers to be reaped at a rate slower
     than that at which they are completing, thus preventing the loop
     from exiting. Address this by limiting the number of transfers
     reaped for each device to 25 for every call to the Linux backend's
     handle_events() function.

Closes #780

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
3 years agoAndroid: Add option LIBUSB_OPTION_WEAK_AUTHORITY to support used in apk
chris [Mon, 17 Aug 2020 02:39:18 +0000 (10:39 +0800)]
Android: Add option LIBUSB_OPTION_WEAK_AUTHORITY to support used in apk

Closes #760

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
3 years agoevents_posix: Remove unnecessary and incorrect assertion
Chris Dickens [Tue, 25 Aug 2020 16:57:06 +0000 (09:57 -0700)]
events_posix: Remove unnecessary and incorrect assertion

Thomas Chiantia reports that the POSIX events abstraction is failing
periodically because of incorrect assertion logic. Remove it as there is
another (correct) check further into the function that will serve check
the intended condition.

Closes #775

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
3 years agocore: Ensure that reported event bits are initialized
Chris Dickens [Mon, 24 Aug 2020 18:23:09 +0000 (11:23 -0700)]
core: Ensure that reported event bits are initialized

Closes #774

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
3 years agoExchange README.md and README
Ludovic Rousseau [Sun, 23 Aug 2020 15:25:17 +0000 (17:25 +0200)]
Exchange README.md and README

Make README the real file and README.md the symbolic link to fix an
installation issue with npm packaging tool.

Fixes https://github.com/libusb/libusb/issues/772
" README file not included with npm packaging tools #772 "

Signed-off-by: Ludovic Rousseau <ludovic.rousseau@free.fr>
3 years agoFix typos detected by codespell and manual inspection
Chris Dickens [Tue, 18 Aug 2020 22:49:22 +0000 (15:49 -0700)]
Fix typos detected by codespell and manual inspection

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
3 years agoDocumentation: Specify the constraint of the 'completed' parameter
Chris Dickens [Tue, 18 Aug 2020 22:03:32 +0000 (15:03 -0700)]
Documentation: Specify the constraint of the 'completed' parameter

Closes #482

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
3 years agoDocumentation: Update the Windows binary snapshot README regarding UsbDk
Chris Dickens [Tue, 18 Aug 2020 21:39:11 +0000 (14:39 -0700)]
Documentation: Update the Windows binary snapshot README regarding UsbDk

Closes #443

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
3 years agoDocumentation: Add details regarding thread-safety
Chris Dickens [Tue, 18 Aug 2020 21:25:59 +0000 (14:25 -0700)]
Documentation: Add details regarding thread-safety

Closes #352

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
3 years agoDocumentation: Improve details of libusb_transfer's 'user_data' field
Chris Dickens [Tue, 18 Aug 2020 20:16:52 +0000 (13:16 -0700)]
Documentation: Improve details of libusb_transfer's 'user_data' field

Closes #351

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
3 years agoDocumentation: Add a note regarding the execution context of callbacks
Chris Dickens [Tue, 18 Aug 2020 19:58:57 +0000 (12:58 -0700)]
Documentation: Add a note regarding the execution context of callbacks

Make it more clear that callbacks are only called when
libusb_handle_events() is called and that all callbacks will be called
on the same thread calling that function.

Closes #349

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
3 years agoDocumentation: Add details regarding timeouts and partial transfer of data
Chris Dickens [Tue, 18 Aug 2020 19:25:11 +0000 (12:25 -0700)]
Documentation: Add details regarding timeouts and partial transfer of data

Closes #348

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>