platform/upstream/libusb.git
5 years agowindows_winusb: Set policy ISO_ALWAYS_START_ASAP for libusbK
Léo Lam [Sat, 4 May 2019 17:53:56 +0000 (19:53 +0200)]
windows_winusb: Set policy ISO_ALWAYS_START_ASAP for libusbK

In some cases, this is required to avoid eventually getting a
USBD_STATUS_BAD_START_FRAME error back from the Windows USB stack.

This makes the libusbK code match the behaviour of the Linux backend.

It appears that the libusbK backend tried to get this behaviour by
setting StartFrame to 0. However, libusbK docs state that:

"Specifing 0 for KISO_CONTEXT::StartFrame (start transfer ASAP) is
restricted to the first transaction on a newly opened or reset pipe."

Closes #569

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
5 years agowindows_winusb: Bounds check interface for check_valid_interface
Léo Lam [Fri, 3 May 2019 10:57:43 +0000 (12:57 +0200)]
windows_winusb: Bounds check interface for check_valid_interface

This prevents a nasty out-of-bounds read and a likely crash when
the interface number is invalid.

Closes #568

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
5 years agowindows_winusb: Mask wIndex correctly when checking interfaces
Léo Lam [Fri, 3 May 2019 10:49:00 +0000 (12:49 +0200)]
windows_winusb: Mask wIndex correctly when checking interfaces

According to the USB 3.0 spec (9.3.4), the interface number is in the
lower 8 bits of wIndex.

Note that wIndex must not be modified because some (non-compliant?)
devices actually use the higher 8 bits for custom data with
recipient-interface requests.

Closes #567

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
5 years agowindows: fix return type of usbi_{inc,dec}_fds_ref.
Josh Gao [Wed, 17 Apr 2019 23:02:18 +0000 (16:02 -0700)]
windows: fix return type of usbi_{inc,dec}_fds_ref.

These functions were declared as returning int, but failed to actually
return anything, and no one was using their return values anyway.

Closes #562

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
5 years agoTypo fixes in comments
follower [Sun, 21 Apr 2019 04:52:28 +0000 (16:52 +1200)]
Typo fixes in comments

Closes #563

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
5 years agomingw fix
RipleyTom [Thu, 2 May 2019 16:19:42 +0000 (18:19 +0200)]
mingw fix

Closes #566

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
5 years agoAdds /utf-8 to compile options
RipleyTom [Thu, 2 May 2019 15:43:36 +0000 (17:43 +0200)]
Adds /utf-8 to compile options

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
5 years agoChange all $(SolutionDir) to $(ProjectDir)
RipleyTom [Thu, 2 May 2019 14:13:20 +0000 (16:13 +0200)]
Change all $(SolutionDir) to $(ProjectDir)

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
5 years agoAddress issue 554: Default context is erase before backend exits in libusb_exit
mac Wang [Mon, 8 Apr 2019 20:45:14 +0000 (13:45 -0700)]
Address issue 554: Default context is erase before backend exits in libusb_exit

Closes #554
Closes #556

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
5 years agoIssue 555: Memory passed to ioctl is not initialized in reap_for_handle
mac Wang [Mon, 8 Apr 2019 21:03:36 +0000 (14:03 -0700)]
Issue 555: Memory passed to ioctl is not initialized in reap_for_handle

Closes #557
Closes #555

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
5 years agoupdate to 1.0.23-rc1
Nathan Hjelm [Fri, 5 Apr 2019 18:15:48 +0000 (12:15 -0600)]
update to 1.0.23-rc1

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
5 years agoAdd support for isochronous transfers with WinUSB.
philemonf [Fri, 5 Apr 2019 07:27:39 +0000 (00:27 -0700)]
Add support for isochronous transfers with WinUSB.

Closes #284

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
5 years agowindows: get usb device until usb configuration is set
haidong.zheng [Wed, 12 Dec 2018 03:07:18 +0000 (11:07 +0800)]
windows: get usb device until usb configuration is set

There are low possiblity to open device before windows complete usb
configuration. Then claim interface will be always failure.
this patch workaround this problem, make sure return device until
windows finish usb configuration.

Closes #505

Signed-off-by: Frank Li <Frank.Li@nxp.com>
Signed-off-by: Tom Zheng <haidong.zheng@nxp.com>
Signed-off-by: Nathan Hjelm <hjelmn@me.com>
5 years agodarwin: Retry IOCreatePlugInInterfaceForService on failure
Juan Cruz Viotti [Wed, 20 Mar 2019 11:34:41 +0000 (11:34 +0000)]
darwin: Retry IOCreatePlugInInterfaceForService on failure

We have a case where a device might not be detected by libusb if we plug
it after initializing the library. We were able to reproduce this issue
pretty consistently on a Mac Mini and several MacBook Pros running very
recent macOS versions (Mojave) using the Balena Fin board
(https://www.balena.io/fin/). I don't know if this happens with other
USB devices.

Enabling debug output revealed the following:

```
[ 7.901582] [00004f07] libusb: debug [darwin_get_cached_device] finding cached device for sessionID 0x2a9b5279f04
[ 7.901764] [00004f07] libusb: debug [darwin_get_cached_device] matching sessionID 0x2a9b5279f04 against cached device with sessionID 0x17dbd029b6a
[ 7.901798] [00004f07] libusb: debug [darwin_get_cached_device] matching sessionID 0x2a9b5279f04 against cached device with sessionID 0x1688763269f
[ 7.901818] [00004f07] libusb: debug [darwin_get_cached_device] matching sessionID 0x2a9b5279f04 against cached device with sessionID 0x4c0aefaa
[ 7.901831] [00004f07] libusb: debug [darwin_get_cached_device] matching sessionID 0x2a9b5279f04 against cached device with sessionID 0x0
[ 7.901845] [00004f07] libusb: debug [darwin_get_cached_device] caching new device with sessionID 0x2a9b5279f04
[ 7.903377] [00004f07] libusb: debug [darwin_device_from_service] could not set up plugin for service: out of resources
[ 8.029152] [00000307] libusb: debug [libusb_get_device_list]
```

The "out of resources" error comes from
`IOCreatePlugInInterfaceForService` which will apparently return this
error if the `Start` method of the interface is not success (see
https://github.com/opensource-apple/IOKitUser/blob/b80a5cbc0ebfb5c4954ef6d757918db0e4dc4b7f/IOCFPlugIn.c#L232).

Retrying `IOCreatePlugInInterfaceForService` makes it work for me.

Closes #542

Signed-off-by: Juan Cruz Viotti <juan@balena.io>
Signed-off-by: Nathan Hjelm <hjelmn@me.com>
5 years agoxusb: Report SuperSpeedPlus
Harry Mallon [Thu, 7 Feb 2019 15:02:59 +0000 (15:02 +0000)]
xusb: Report SuperSpeedPlus

Closes #530

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
5 years agosolaris: Fix crash on closing libusb handle
Alexander Pyhalov [Thu, 24 May 2018 11:57:04 +0000 (14:57 +0300)]
solaris: Fix crash on closing libusb handle

libusb_close() can interrupt transfer to device,
setting dev_handle to NULL.
In this case all async requests should exit gracefully.

Also usbi_signal_transfer_completion() can dereference dev_handle
in this case.

Closes #434

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
5 years agowindows: Improved log message output to MSVC
dmitrykos [Thu, 31 Jan 2019 21:17:06 +0000 (23:17 +0200)]
windows: Improved log message output to MSVC

Improved log message output to MSVC handling by converting multi-byte
string (assumed to be UTF-8) to WCHAR string if UNICODE is defined, if
UNICODE is not defined then multi-byte string is sent to MSVC (Windows
CE defines UNICODE always, so it will use UNICODE case), added check
for 0 to avoid sending trash to MSVC (and possibly crash the process)
if conversion to WCHAR string fails.

Closes #504

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
5 years agoFixed log message incorrect data format sent to MSVC if Unicode defined.
Dmitry Kostjuchenko [Tue, 11 Dec 2018 11:41:24 +0000 (13:41 +0200)]
Fixed log message incorrect data format sent to MSVC if Unicode defined.

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
5 years agoAllow set configuration control requests when using libusb0.sys
Frederik Carlier [Tue, 18 Sep 2018 13:27:14 +0000 (15:27 +0200)]
Allow set configuration control requests when using libusb0.sys

Closes #473

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
5 years agoFix control transfer interface selection
kuro68k [Mon, 26 Feb 2018 15:46:11 +0000 (15:46 +0000)]
Fix control transfer interface selection

When bmRequestType indicates the recipient is an interface, get
interface number from wIndex.

Closes #398

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
5 years agoUse more portable di_prop_lookup_ints() interface
Alexander Pyhalov [Thu, 24 May 2018 11:54:02 +0000 (14:54 +0300)]
Use more portable di_prop_lookup_ints() interface

Closes #433

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
5 years agotransfer_lock should be released before usbi_handle_transfer_completion() call
Alexander Pyhalov [Thu, 24 May 2018 12:06:46 +0000 (15:06 +0300)]
transfer_lock should be released before usbi_handle_transfer_completion() call

Closes #430

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
5 years agoAdding support for ARM & ARM64 Windows Platform
Dj Art [Fri, 27 Apr 2018 10:04:14 +0000 (18:04 +0800)]
Adding support for ARM & ARM64 Windows Platform

Closes #423

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
5 years agofix windows crash when multi-thread do sync transfer
Frank Li [Fri, 11 Jan 2019 19:09:51 +0000 (13:09 -0600)]
fix windows crash when multi-thread do sync transfer

fun()
{
    libusb_open()
    ... sync transfer
    libusb_close()
}

two thread call fun infininately.

to speed up crash, enable application verifier

below 20 cycle, assert(fd!=NULL) happen at check_pollfds
below 100 cycle, crash at pollable_fd->overlappend in
winusb_get_overlapped result

with this fix, success fun over 1000 cycles

in handle_events

usbi_mutex_lock()
fds = ctx->pollfds
nfds = ctx->pollfds_cnt;
usbi_mutex_unclock()

usbi_poll()
callback.

usbi poll is not in mutex. pollfds may be change by usbi_add_pollfd
and usbi_remove_pollfd.

Although usbi_add_pollfd and usbi_remove_pollfd hold mutex, but
usbi_poll and callback is not in protext of mutex.

windows use fd as index of fb_table. fb_table may changed by
usbi_remove_pollfd.  the map between fd and internal file_descriptor may
be wrong.

this patch added ref count for file_descriptor, only free file_desciptor
and remove it from fb_table when ref count is 0.

ref count will be increase when fds copy with mutex lock.
so fd always index validate file_descriptor.

ref count will be descress before return from handle_events.
the file_descriptor can be free safely at this time.

Closes #521

Signed-off-by: Frank Li <Frank.Li@nxp.com>
Signed-off-by: Nathan Hjelm <hjelmn@me.com>
5 years agoFix copy paste error in libusb_free_* docs
Harry Mallon [Tue, 12 Feb 2019 13:18:56 +0000 (13:18 +0000)]
Fix copy paste error in libusb_free_* docs

Closes #535

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
5 years agoFixed Xcode 10.1 warning by setting project setting 'ALWAYS_SEARCH_USER_PATHS = NO'
Sean McBride [Thu, 7 Feb 2019 20:11:56 +0000 (15:11 -0500)]
Fixed Xcode 10.1 warning by setting project setting 'ALWAYS_SEARCH_USER_PATHS = NO'

The warning was: "Traditional headermap style is no longer supported; please migrate to using separate headermaps and set 'ALWAYS_SEARCH_USER_PATHS' to NO."

Also made sure all targets are referencing the xcconfig files.

Closes #532

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
5 years agoInitialize the non-control endpoint fds in netbsd_open()
Aymeric Vincent [Thu, 28 Feb 2019 21:38:21 +0000 (22:38 +0100)]
Initialize the non-control endpoint fds in netbsd_open()

Not all users of libusb use libusb_claim_interface(), and in that
case, the NetBSD backend fails to open() the necessary /dev/ugenX.Y
and will try to send ioctl()s to fd 0, which fortunately fails.

This unbreaks e.g. openocd on NetBSD.

Closes #539

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
5 years agodarwin: fix reset device
Nathan Hjelm [Thu, 4 Apr 2019 18:02:25 +0000 (12:02 -0600)]
darwin: fix reset device

This commit fixes the backend of reset device to restore the state
of the device if possible. This fixes a bug introduced in
c14ab5fc4d22749aab9e3534d56012718a0b0f67. The previous commit
was necessary due to changes in the system USB stack that
essentially turned the ResetDevice function into a no-op. This
required libusb to move to USBDevuceReEnumerate to effectively
reset the device. The problem is that both the device handle and
libusb devices became invalid. This commit fixes the bug by
waiting for the re-enumeration to complete then 1) checking
whether the descriptors changed, 2) restoring the active
configuration, and 3) restoring claimed interfaces.

Closes #523

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
5 years agoFixed -Wformat warnings by casting intptr_t to void*
Sean McBride [Thu, 17 Jan 2019 22:28:59 +0000 (17:28 -0500)]
Fixed -Wformat warnings by casting intptr_t to void*

%p is for pointers, not integers; therefore added a cast.

Fixes the following warnings:
libusb/core.c:1252:33: Format specifies type 'void *' but the argument has type 'intptr_t' (aka 'long')
libusb/core.c:1276:45: Format specifies type 'void *' but the argument has type 'intptr_t' (aka 'long')

Signed-off-by: Ludovic Rousseau <ludovic.rousseau@free.fr>
5 years agohaiku_usb_raw: Add missing wrap_sys_device field to usbi_os_backend
Andrew Aldridge [Fri, 25 Jan 2019 02:59:38 +0000 (21:59 -0500)]
haiku_usb_raw: Add missing wrap_sys_device field to usbi_os_backend

Closes #527

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
5 years agohaiku_usb_raw: return written length instead of LIBUSB_SUCCESS
Andrew Aldridge [Thu, 24 Jan 2019 16:51:45 +0000 (11:51 -0500)]
haiku_usb_raw: return written length instead of LIBUSB_SUCCESS

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
5 years agoFixed many compiler warnings about sign and size mismatch
Sean McBride [Sat, 15 Dec 2018 22:08:34 +0000 (17:08 -0500)]
Fixed many compiler warnings about sign and size mismatch

- added various casts
- added some asserts where the casts made assumptions
- enabled additional warnings in Xcode project (especially -Wshorten-64-to-32)

Closes #509

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
5 years agofix race condition at event_handles
Frank Li [Fri, 11 Jan 2019 17:56:47 +0000 (11:56 -0600)]
fix race condition at event_handles

event_handles supposed just run at a thread.

There are re-entry check at begin.

1: if (usbi_handling_events(ctx))
2: return LIBUSB_ERROR_BUSY;

3: usbi_stat_event_handle(ctx);

this code is hold any lock

it is possible two thread check 1 at the same time, then
go through to 3. So two threads will run event_handles.

above 3 line code should hold event_data_lock to avoid above
race condition.

1: usbi_mutex_lock($ctx->event_data_lock);
2: r = 0;
3: if (usbi_handling_events(ctx))
4:  r = LIBUSB_ERROR_BUSY;
5: else
6:  usbi_start_event_handling(ctx);
7: usbi_mutex_unlock($ctx->event_data_lock);

8: if(r)
9: return r;

check and set in an atomic operations.

Closes #520

Signed-off-by: Frank Li <Frank.Li@nxp.com>
Signed-off-by: Nathan Hjelm <hjelmn@me.com>
5 years agoAdd missing structure entry to avoid erroneous shift of following items
winterrace [Sat, 26 Jan 2019 21:59:29 +0000 (22:59 +0100)]
Add missing structure entry to avoid erroneous shift of following items

Closes #526

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
5 years agodarwin: use internal define when querying plugin interface
Nathan Hjelm [Thu, 17 Jan 2019 04:08:07 +0000 (21:08 -0700)]
darwin: use internal define when querying plugin interface

Apple changed the definition of kIOUSBInterfaceInterfaceID in the SDK
for macOS 10.14. This looks like it breaks support for building for
older macOS versions when running 10.14. I don't know if the change
was intentional or a mistake but in order to guarantee libusb
builds as it has in the past we can no longer rely on
kIOUSBInterfaceInterfaceID.

Closes #519

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
5 years agodarwin: shorten hotplug poll timeout
Nathan Hjelm [Wed, 9 Jan 2019 01:26:48 +0000 (18:26 -0700)]
darwin: shorten hotplug poll timeout

Looks like 5 seconds was indeed too long. Shortened the timeout to
1ms instead.

Closes #516

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
5 years agolinux_usbfs: Disable hotplug events and scanning on Android
Vianney le Clément de Saint-Marcq [Tue, 13 Dec 2016 14:04:11 +0000 (15:04 +0100)]
linux_usbfs: Disable hotplug events and scanning on Android

On Android, the platform API should be used to scan for and open devices
and pass file descriptors to libusb.  Newer devices (Android 5+) even
prohibit listening for hotplug events, resulting in libusb failing to
initialize without this patch.

Note that this patch effectively renders libusb useless on older devices
that do not have USB support in the platform API (anything before
Android 5).

Closes #242

Signed-off-by: Vianney le Clément de Saint-Marcq <code@quartic.eu>
Signed-off-by: Nathan Hjelm <hjelmn@me.com>
5 years agolinux_usbfs: Use fallback usbfs path on Android
Vianney le Clément de Saint-Marcq [Tue, 15 Mar 2016 14:04:02 +0000 (15:04 +0100)]
linux_usbfs: Use fallback usbfs path on Android

On newer Android devices (5+), SELinux policies block normal processes
from reading /dev.  The consequence is that the usbfs path cannot be
found.  Rather than failing to initialize libusb in such case, fall back
to /dev/bus/usb.  This path will actually not be used, as USB devices
should be opened through the Android API, passing the file descriptor to
libusb_wrap_sys_device.

Signed-off-by: Vianney le Clément de Saint-Marcq <code@quartic.eu>
Signed-off-by: Nathan Hjelm <hjelmn@me.com>
5 years agolinux_usbfs: Implement libusb_wrap_sys_device()
Vianney le Clément de Saint-Marcq [Tue, 13 Dec 2016 14:59:23 +0000 (15:59 +0100)]
linux_usbfs: Implement libusb_wrap_sys_device()

Add support for the libusb_wrap_sys_device() API on Linux.  Because
sysfs_dir is set to NULL, only the provided file descriptor will be
used.  This is needed on some platforms (e.g., Android) where sysfs
might not be available.

Signed-off-by: Vianney le Clément de Saint-Marcq <code@quartic.eu>
Signed-off-by: Nathan Hjelm <hjelmn@me.com>
5 years agocore: Add libusb_wrap_sys_device() API
Vianney le Clément de Saint-Marcq [Tue, 13 Dec 2016 14:45:56 +0000 (15:45 +0100)]
core: Add libusb_wrap_sys_device() API

Introduce a new API function for wrapping an existing platform-specific
device handle as a libusb_device_handle.

Signed-off-by: Vianney le Clément de Saint-Marcq <code@quartic.eu>
Signed-off-by: Nathan Hjelm <hjelmn@me.com>
5 years agolinux_usbfs: Get device address from file descriptor
Vianney le Clément de Saint-Marcq [Tue, 13 Dec 2016 15:30:56 +0000 (16:30 +0100)]
linux_usbfs: Get device address from file descriptor

Extend linux_get_device_address() to try to read the device address from
a file descriptor as a last resort, if provided.

Additionally, linux_get_device_address() will now return an error if the
path could not be parsed.

Signed-off-by: Vianney le Clément de Saint-Marcq <code@quartic.eu>
Signed-off-by: Nathan Hjelm <hjelmn@me.com>
5 years agolinux_usbfs: Extract device handle initialization from op_open()
Vianney le Clément de Saint-Marcq [Tue, 13 Dec 2016 14:32:39 +0000 (15:32 +0100)]
linux_usbfs: Extract device handle initialization from op_open()

Slightly refactor op_open() to extract the device handle initialization
code into a new initialize_handle() function, similar to the
initialize_device() function.

Signed-off-by: Vianney le Clément de Saint-Marcq <code@quartic.eu>
Signed-off-by: Nathan Hjelm <hjelmn@me.com>
5 years agolinux_usbfs: Fallback to usbfs if device has no sysfs_dir
Vianney le Clément de Saint-Marcq [Tue, 13 Dec 2016 12:57:25 +0000 (13:57 +0100)]
linux_usbfs: Fallback to usbfs if device has no sysfs_dir

Handle devices that are initialized with NULL as sysfs_dir.  For such
devices, the usbfs functions should be used instead of their sysfs
counterparts.

Signed-off-by: Vianney le Clément de Saint-Marcq <code@quartic.eu>
Signed-off-by: Nathan Hjelm <hjelmn@me.com>
5 years agoTried to untangle mixing of int, enum libusb_error, kern_return_t, and IOReturn.
Sean McBride [Sat, 15 Dec 2018 21:26:14 +0000 (16:26 -0500)]
Tried to untangle mixing of int, enum libusb_error, kern_return_t, and IOReturn.

- Replace all kern_return_t with IOReturn, they are basically the same, but IOReturn is more common in IOUSBLib
- improve consistency by using the name 'kresult' for all IOReturn-type results, and not using that name for libusb_error return values.
- changed a few functions to use real 'bool' (this file already uses C99)
- replaced some raw '0's with LIBUSB_SUCCESS or kIOReturnSuccess.
- replaced some raw 'int's with either IOReturn or enum libusb_error.
- replaced ambiguous "if (kresult)" with more explicit "if (kresult != kIOReturnSuccess)"
- replaced incorrect use of darwin_to_libusb with darwin_transfer_status

Most of these were found by increasing the compiler warning level.

Closes #510

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
5 years agoRemoved unneeded checks for passing null to free()
Sean McBride [Sat, 15 Dec 2018 21:12:07 +0000 (16:12 -0500)]
Removed unneeded checks for passing null to free()

Closes #507

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
5 years agoAdded USBI_PRINTFLIKE to allow finding printf format string mistakes
Sean McBride [Sat, 15 Dec 2018 21:03:17 +0000 (16:03 -0500)]
Added USBI_PRINTFLIKE to allow finding printf format string mistakes

Fixed one such misktake

Closes #506

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
5 years agouse travis homebrew addon for reliability
Stephen [Mon, 17 Dec 2018 19:42:33 +0000 (11:42 -0800)]
use travis homebrew addon for reliability

Closes #513

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
5 years agoBump libusb API version for next release
Nathan Hjelm [Wed, 5 Dec 2018 17:52:08 +0000 (10:52 -0700)]
Bump libusb API version for next release

Signed-off-by: Nathan Hjelm <hjelmn@lanl.gov>
5 years agoconfigure.ac: bump .so version for next release
Nathan Hjelm [Wed, 5 Dec 2018 17:36:50 +0000 (10:36 -0700)]
configure.ac: bump .so version for next release

Signed-off-by: Nathan Hjelm <hjelmn@lanl.gov>
5 years agoUpdate ChangeLog
Nathan Hjelm [Wed, 5 Dec 2018 17:36:20 +0000 (10:36 -0700)]
Update ChangeLog

Signed-off-by: Nathan Hjelm <hjelmn@lanl.gov>
5 years agousbi_dbg() uses backend's clock_gettime(), break recursion in sunos backend
Alexander Pyhalov [Thu, 24 May 2018 12:03:45 +0000 (15:03 +0300)]
usbi_dbg() uses backend's clock_gettime(), break recursion in sunos backend

Closes #431

Signed-off-by: Nathan Hjelm <hjelmn@lanl.gov>
5 years agoexamples: Fix format-truncation on debug
Victor Toso [Tue, 7 Aug 2018 07:45:58 +0000 (09:45 +0200)]
examples: Fix format-truncation on debug

As description is used only for debug, we can extend it to be sure to
fit 256 from string variable plus 3 chars from " - " as described in
gcc warning below

 | testlibusb.c: In function ‘print_device.constprop’:
 | testlibusb.c:188:51: warning: ‘ - ’ directive output may be truncated writing 3 bytes into a region of size between 1 and 256 [-Wformat-truncation=]
 |      snprintf(description, sizeof(description), "%s - ", string);
 |                                                    ^~~
 | testlibusb.c:188:5: note: ‘snprintf’ output between 4 and 259 bytes into a destination of size 256
 |      snprintf(description, sizeof(description), "%s - ", string);
 |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Closes #460

Signed-off-by: Victor Toso <victortoso@redhat.com>
Signed-off-by: Nathan Hjelm <hjelmn@lanl.gov>
5 years agoEnable timerfd on sunos when available
Alexander Pyhalov [Thu, 24 May 2018 11:55:20 +0000 (14:55 +0300)]
Enable timerfd on sunos when available

Closes #432

Signed-off-by: Nathan Hjelm <hjelmn@lanl.gov>
5 years agoAdd missing libusb_exit on an error condition
gudenau [Wed, 20 Jun 2018 01:12:52 +0000 (20:12 -0500)]
Add missing libusb_exit on an error condition

Closes #448

Signed-off-by: Nathan Hjelm <hjelmn@lanl.gov>
5 years agoHungarian translation
Bence Cs [Wed, 7 Nov 2018 12:17:40 +0000 (13:17 +0100)]
Hungarian translation

Closes #493

Signed-off-by: Nathan Hjelm <hjelmn@lanl.gov>
5 years agoFixed typo in the documentation
saur0n [Tue, 27 Nov 2018 17:52:12 +0000 (20:52 +0300)]
Fixed typo in the documentation

Closes #496

Signed-off-by: Nathan Hjelm <hjelmn@lanl.gov>
5 years agocore: new API libusb_set_log_cb() to redirect global and per context log messages...
dmitrykos [Tue, 23 Oct 2018 18:05:25 +0000 (21:05 +0300)]
core: new API libusb_set_log_cb() to redirect global and per context log messages to the provided log handling function

Closes #486

Signed-off-by: Nathan Hjelm <hjelmn@lanl.gov>
5 years agoupdate nano
Nathan Hjelm [Mon, 22 Oct 2018 20:04:04 +0000 (14:04 -0600)]
update nano

Signed-off-by: Nathan Hjelm <hjelmn@lanl.gov>
5 years agoAdd German translation
Alexander Schlarb [Mon, 18 Jun 2018 13:11:40 +0000 (15:11 +0200)]
Add German translation

Most strings were copied from the german `strerror` output on equivallent `errno` values and then adapted as necessary.

Closes #446

Signed-off-by: Nathan Hjelm <hjelmn@lanl.gov>
5 years agoconfigure.ac: fix detection of clock_gettime library
Baruch Siach [Tue, 5 Jun 2018 11:22:21 +0000 (14:22 +0300)]
configure.ac: fix detection of clock_gettime library

glibc before 2.17 requires link with librt for clock_gettime(). The
AC_SEARCH_LIBS check in configure.ac should detect this dependency.
Unfortunately commit cb77a25e51 (configure.ac: Remove obsolete AC_ERROR
and make formatting consistent) inadvertently renamed to clock_gettime2,
thus breaking librt detection.

Restore the correct clock_gettime() name.

Closes #439

Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Signed-off-by: Nathan Hjelm <hjelmn@lanl.gov>
5 years agoos/darwin: remove code that changed the device class used
Nathan Hjelm [Wed, 17 Oct 2018 18:02:14 +0000 (12:02 -0600)]
os/darwin: remove code that changed the device class used

To support macOS El Capitan I added some code to change from using the
IOUSBDevice class to using IOUSBHostDevice. This looked necessary as
Apple had re-writed IOUSBFamily and IOUSBHostDevice was the new base
class name. The problem is that using the new class misses some
devices in more recent versions of macOS. Apple is still including the
IOClassNameOverride property (as of macOS Mojave) so it is still safe
to search using the IOUSBDevice class. We will need to find a
different class if Apple ever removes the IOClassNameOverride
property from USB devices.

Closes #428

Signed-off-by: Nathan Hjelm <hjelmn@mac.com>
5 years agoos/darwin: switch from using ResetDevice to USBDeviceReEnumerate
Nathan Hjelm [Thu, 26 Jul 2018 18:48:07 +0000 (12:48 -0600)]
os/darwin: switch from using ResetDevice to USBDeviceReEnumerate

In newer versions of macOS the ResetDevice function does nothing. For
these systems we have to use USBDeviceReEnumerate. This should also
work for older versions os MacOS X.

Fixes #455

Signed-off-by: Nathan Hjelm <hjelmn@lanl.gov>
6 years agoMove to brew bundle
Stephen [Fri, 30 Mar 2018 14:09:09 +0000 (07:09 -0700)]
Move to brew bundle

improved dependency management with brew bundle

6 years agolibusb 1.0.22 upstream/1.0.22
Chris Dickens [Sun, 25 Mar 2018 00:43:43 +0000 (17:43 -0700)]
libusb 1.0.22

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
6 years agoexamples: testlibusb: Fix DDK build warning
Chris Dickens [Sun, 25 Mar 2018 00:42:46 +0000 (17:42 -0700)]
examples: testlibusb: Fix DDK build warning

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
6 years agoWindows: Add back resource and definition files to VS DLL projects
Chris Dickens [Tue, 20 Mar 2018 17:01:48 +0000 (10:01 -0700)]
Windows: Add back resource and definition files to VS DLL projects

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
6 years agolibusb 1.0.22-rc4
Chris Dickens [Sat, 17 Mar 2018 07:21:14 +0000 (00:21 -0700)]
libusb 1.0.22-rc4

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
6 years agoWindows: WinUSB: Allow caching config descriptors to fail
Chris Dickens [Sat, 17 Mar 2018 07:15:20 +0000 (00:15 -0700)]
Windows: WinUSB: Allow caching config descriptors to fail

Certain buggy devices may not provide all the advertised configuration
descriptors. Prior to this commit, failure to cache any one of the
descriptors would result in all of the descriptors being freed and the
device being inaccessible. Work around this by continuing on if fetching
a configuration descriptor fails. The device may still be usable if the
descriptor for the current configuration was successfully retrieved.

Closes #390

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
6 years agoWindows: Restructure DDK/MSVC project files
Chris Dickens [Mon, 12 Mar 2018 17:39:26 +0000 (10:39 -0700)]
Windows: Restructure DDK/MSVC project files

For simplicity and to address some build warnings, this commit reworks
the project files to eliminate duplication and consolidate common build
flags and options. Also adds the stress and testlibusb projects to the
DDK build script.

Closes #402

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
6 years agoWindows: WinUSB: Guard against erroneous reporting of devices
Chris Dickens [Mon, 12 Mar 2018 17:28:40 +0000 (10:28 -0700)]
Windows: WinUSB: Guard against erroneous reporting of devices

During enumeration, obtaining the port number via SPDRP_ADDRESS might
return a bogus value for some third-party HCD drivers. If this occurs,
we might end up reporting the device as having the VID/PID from the last
successful enumeration. Guard against this particular situation by
clearing the USB_NODE_CONNECTION_INFORMATION_EX structure before issuing
the DeviceIoControl() call.

References #403

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
6 years agoWindows: UsbDk: Fix potential buffer overflow
Chris Dickens [Mon, 12 Mar 2018 17:25:02 +0000 (10:25 -0700)]
Windows: UsbDk: Fix potential buffer overflow

Closes #397

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
6 years agoWindows: WinUSB: Do not assume that driver implements CancelIoEx()
Chris Dickens [Mon, 12 Mar 2018 17:24:04 +0000 (10:24 -0700)]
Windows: WinUSB: Do not assume that driver implements CancelIoEx()

Cancelling an individual OVERLAPPED I/O operation is something that a
driver can optionally implement. It appears that the native WinUSB
driver supports this but libusbK does not. Therefore we will attempt
to use it and fall back to the AbortPipe() call if an error occurs.

Closes #400

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
6 years agoWindows: Plug HANDLE leak
Chris Dickens [Mon, 12 Mar 2018 16:54:33 +0000 (09:54 -0700)]
Windows: Plug HANDLE leak

Restore a CloseHandle() call that was mistakenly removed during a merge
conflict resolution.

Closes #404

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
6 years agolibusb 1.0.22-rc3
Chris Dickens [Sat, 24 Feb 2018 10:02:34 +0000 (02:02 -0800)]
libusb 1.0.22-rc3

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
6 years agoWindows: UsbDk: Implement get_config_descriptor_by_value()
Chris Dickens [Sat, 24 Feb 2018 10:02:03 +0000 (02:02 -0800)]
Windows: UsbDk: Implement get_config_descriptor_by_value()

This fixes a NULL pointer dereference when the user selects the UsbDk
backend and subsequently calls libusb_get_config_descriptor_by_value().

Closes #395

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
6 years agoWindows: Fix hid_abort_transfers blocking
zachary [Sat, 10 Feb 2018 08:59:49 +0000 (16:59 +0800)]
Windows: Fix hid_abort_transfers blocking

Closes #392

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
6 years agoWindows: Fix race condition between submit and handle events
Patrick Stewart [Wed, 31 Jan 2018 15:18:06 +0000 (15:18 +0000)]
Windows: Fix race condition between submit and handle events

Check the event object for completion in poll instead of using
HasOverlappedIoCompleted. When we submit a transfer on Windows the fd is
added to the poll list before the read/write begins, so
HasOverlappedIoCompleted can be called before overlapped.Internal is set
to ERROR_IO_PENDING if events are being being handled concurrently, so
the fd will be marked as completed before it has actually started.

[dickens] Instead of replacing HasOverlappedIoCompleted, supplement it
so that it can provide a fast path to avoid WaitForSingleObject() in
the general case

Closes #386, Closes #387

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
6 years agoWindows: Always search for "USB" PnP enumerator class
Chris Dickens [Fri, 2 Feb 2018 07:31:18 +0000 (23:31 -0800)]
Windows: Always search for "USB" PnP enumerator class

On systems running Windows 7 and earlier that only have a USB 3.0 host
controller, devices may not be listed correctly if the root hub PnP
enumerator is anything other than "USB". This regression was introduced
in the recent enumeration refactoring (commit 71a779d07).

Closes #385

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
6 years agolibusb 1.0.22-rc2
Chris Dickens [Sun, 28 Jan 2018 01:29:46 +0000 (17:29 -0800)]
libusb 1.0.22-rc2

6 years agoWindows: Regenerate libusb-1.0.def file from latest DLL
Chris Dickens [Sun, 28 Jan 2018 01:27:53 +0000 (17:27 -0800)]
Windows: Regenerate libusb-1.0.def file from latest DLL

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
6 years agoWindows: Check composite interfaces before calling functions
Chris Dickens [Sun, 28 Jan 2018 00:22:10 +0000 (16:22 -0800)]
Windows: Check composite interfaces before calling functions

Commit c4438b3c introduced a regression by failing to check for the
presence of a function in the backend when called on a composite device.
Fix this by introducing a new helper macro and checking for function
pointers at all necessary locations.

Closes #383

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
6 years agolibusb 1.0.22-rc1
Chris Dickens [Tue, 9 Jan 2018 07:08:47 +0000 (23:08 -0800)]
libusb 1.0.22-rc1

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
6 years agodarwin: Improve error checking to prevent (very unlikely) null dereference
Sean McBride [Fri, 5 Jan 2018 03:17:24 +0000 (22:17 -0500)]
darwin: Improve error checking to prevent (very unlikely) null dereference

Defend against the very unlikely possibility of CFNumberCreate() returning null.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
6 years agodarwin: Suppress deprecation warning when building against 10.13 SDK
Sean McBride [Fri, 5 Jan 2018 03:16:03 +0000 (22:16 -0500)]
darwin: Suppress deprecation warning when building against 10.13 SDK

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
6 years agodarwin: Test use of kUSBDeviceSpeedSuper against SDK version
Sean McBride [Mon, 8 Jan 2018 21:57:50 +0000 (16:57 -0500)]
darwin: Test use of kUSBDeviceSpeedSuper against SDK version

Closes #362

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
6 years agodarwin: extend enum libusb_speed for 10000MBit/s case
Sean McBride [Sat, 30 Dec 2017 01:31:56 +0000 (20:31 -0500)]
darwin: extend enum libusb_speed for 10000MBit/s case

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
6 years agolinux_usbfs: Add support for reporting super speed plus devices
Chris Dickens [Tue, 9 Jan 2018 06:04:56 +0000 (22:04 -0800)]
linux_usbfs: Add support for reporting super speed plus devices

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
6 years agocore: Add definition for LIBUSB_SUPER_SPEED_PLUS (10Gb/s)
Chris Dickens [Tue, 9 Jan 2018 06:03:49 +0000 (22:03 -0800)]
core: Add definition for LIBUSB_SUPER_SPEED_PLUS (10Gb/s)

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
6 years agoWindows: Added isochronous support via libusbk
Joshua Blake [Sat, 30 Nov 2013 11:18:29 +0000 (06:18 -0500)]
Windows: Added isochronous support via libusbk

[dickens] Rebased against latest changes and fixed some styling issues

Closes #246

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
6 years agoFix appveyor scripts for Cygwin and MinGW to build as intended
Chris Dickens [Tue, 9 Jan 2018 04:41:50 +0000 (20:41 -0800)]
Fix appveyor scripts for Cygwin and MinGW to build as intended

The sub-directory created to store the generated files and build objects
was not being used as intended, because each invocation of the bash
starts in the home directory. Fix this by changing to the intended
directory prior to each command invocation.

Also replace the invocation of autogen.sh with bootstrap.sh, since using
autogen.sh calls ./configure and we weren't using the results of that
work. Instead we call configure directly from the sub-directory while
enabling the examples and test builds (for Cygwin) as autogen.sh would do.

Also fix the invalid value for the --build option provided to the x64
build of MinGW.

Finally, propagate errors from each script command so that failures are
caught and reported.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
6 years agoWindows: Fix MinGW build warnings/errors
Chris Dickens [Mon, 8 Jan 2018 20:31:55 +0000 (12:31 -0800)]
Windows: Fix MinGW build warnings/errors

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
6 years agocore: Fixed clang -Wcomma warning
Sean McBride [Fri, 29 Dec 2017 18:30:24 +0000 (13:30 -0500)]
core: Fixed clang -Wcomma warning

Fixes:

descriptor.c:1179:13: Possible misuse of comma operator here

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
6 years agodarwin: Changed weirdo fixed-sized typedefs with the usual IOUSBLib.h ones
Sean McBride [Fri, 29 Dec 2017 18:25:42 +0000 (13:25 -0500)]
darwin: Changed weirdo fixed-sized typedefs with the usual IOUSBLib.h ones

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
6 years agodarwin: Untangle clock_* API tests from atomics tests
Sean McBride [Fri, 29 Dec 2017 18:23:51 +0000 (13:23 -0500)]
darwin: Untangle clock_* API tests from atomics tests

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
6 years agodarwin: Replaced low-level mach API with pthread API
Sean McBride [Fri, 29 Dec 2017 18:23:00 +0000 (13:23 -0500)]
darwin: Replaced low-level mach API with pthread API

Found this because clang was warning that the return value was being
converted from unsigned to signed.

The need for a mach API surprised me, and I found this alternative
formulation in a Chromium bug:

https://groups.google.com/forum/#!topic/native-client-reviews/z---hlHbQNc

which describes: "mach_thread_self() needs to be balanced by mach_port_deallocate(),
which is two system calls. pthread_mach_thread_np(pthread_self()) is two libc
function calls and no system calls, because pthread caches the Mach port."

Fixed the conversion warning too, with a cast.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
6 years agodarwin: Cleanup and fixes related to Mac OS IOUSBLib interface checks
Sean McBride [Fri, 29 Dec 2017 18:15:07 +0000 (13:15 -0500)]
darwin: Cleanup and fixes related to Mac OS IOUSBLib interface checks

- revisited fix to issue #48:
  - guard kIOUSBDeviceInterfaceID500 with 10.8 deployment (not 10.9).
    I believe a typo in the bug report caused this to be guarded too
    strictly.
  - added deployment target tests to every interface check. Necessary
    because merely checking for a macro definition tells us nothing
    about what features are available at runtime. It is common to build
    against new SDKs but deploy to older OSes.
- properly guard kIOUSBInterfaceInterfaceID700 against 10.10 deployment
  (not 10.9).  It was added in 10.10.  Probably a copy-pasto.
- changed non-existent kIOUSBDeviceInterfaceID220 to
  kIOUSBDeviceInterfaceID197.  Probably a copy-pasto.
- don't use defines like MAC_OS_X_VERSION_10_9 since they don't exist in
  older SDKs and would fail to compile, use raw numbers instead.
- added tests for newer interfaces: kIOUSBInterfaceInterfaceID800,
  kIOUSBInterfaceInterfaceID650, kIOUSBDeviceInterfaceID650.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
6 years agoAdded some Xcode-related items to .gitignore
Sean McBride [Fri, 29 Dec 2017 18:02:05 +0000 (13:02 -0500)]
Added some Xcode-related items to .gitignore

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
6 years agodarwin: Configure Xcode project to specify tab/space, indent amount
Sean McBride [Fri, 29 Dec 2017 17:57:26 +0000 (12:57 -0500)]
darwin: Configure Xcode project to specify tab/space, indent amount

All source files are now tagged as using tabs of 4 spaces, except
darwin_usb.c and darwin_usb.h which use spaces of 2 spaces. This allows
editing files in Xcode without it messing up any particular files.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
6 years agoMisc: Replace "Mac OS X" with "macOS", its current name
Sean McBride [Fri, 29 Dec 2017 17:50:15 +0000 (12:50 -0500)]
Misc: Replace "Mac OS X" with "macOS", its current name

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
6 years agoWindows: Ditch UsbDk build configuration
Sameeh Jubran [Sun, 15 Jan 2017 09:40:57 +0000 (11:40 +0200)]
Windows: Ditch UsbDk build configuration

Previous patch introduced run-time UsbDk backend activation,
therefore separate build configuration is not needed anymore.

Signed-off-by: Sameeh Jubran <sameeh@daynix.com>