Chris Dickens [Thu, 16 Apr 2020 19:40:49 +0000 (12:40 -0700)]
libusb.h: Move BOS descriptor enumerations
The location of the enumerations for the various bits in the BOS
descriptors is not consistent with the other enumerations, so move it up
to group it with the rest. In addition, fix the Doxygen documentation to
put these in the descriptors group rather than the devices group.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Thu, 16 Apr 2020 19:20:16 +0000 (12:20 -0700)]
core: Fix definition and use of enum libusb_transfer_type
Since the beginning of the libusb-1.0, the libusb_transfer_type enum had
a 1:1 mapping to the endpoint transfer type (bits 1:0 of the endpoint
descriptor's bmAttributes). This was broken with the addition of bulk
stream support because the value of LIBUSB_TRANSFER_TYPE_BULK_STREAM
does not map to a valid value for an endpoint's transfer type.
Fix this by splitting the endpoint's transfer type for its descriptor
and the library's transfer type for its logical transfers into different
enumerations. None of the values are altered, so applications testing
an endpoint descriptor's bmAttributes field against the
libusb_transfer_type enum values will still work.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
nia [Fri, 3 Apr 2020 21:15:02 +0000 (22:15 +0100)]
netbsd: Recognize device timeouts.
Closes #710
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Thu, 9 Apr 2020 19:30:57 +0000 (12:30 -0700)]
Makefiles: Remove target-specific variables
Improve portability with non-GNU make by using standard variables.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Thu, 9 Apr 2020 19:05:16 +0000 (12:05 -0700)]
configure.ac: Enhance compiler checks for pthreads
There apparently exist some compiler ports (e.g Haiku's GCC) that do not
support the ubiquitous '-pthread' compiler option. Add a check for this
and only use the option if supported.
Also tweak the check for the pthread library to check for the
pthread_create() function. Even though libusb does not use this function,
it seems to be sufficiently distinct such that the standard C library
would not provide this directly if the pthread implementation resided in
a separate library. Also explicitly check whether no additional library
linkage is required.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Thu, 9 Apr 2020 18:46:03 +0000 (11:46 -0700)]
configure.ac: Simplify detection of Windows compilation
There are a few parts within the library where code is conditionally
compiled based on whether or not the target OS is Windows. Prior to
commit
8b09dd490d ("core: Kill the OS_* definitions and use in the
source code"), the OS_WINDOWS definition was used. With that definition
gone, the checks were replaced with _WIN32. Unfortunately the different
cross-platform toolchains do not universally define this, so add this to
AM_CPPFLAGS when building for Windows.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Thu, 9 Apr 2020 18:30:19 +0000 (11:30 -0700)]
configure.ac: Fix compilation of Haiku's C++ convenience library
Commit
9a1bc8cafb ("build: Require C11 to build and clean up
autoconfig/automake files") added the language standard compiler option
to the AM_CFLAGS and AM_CXXFLAGS. Placing it in the latter is incorrect
as compiling C++ source with the C11 language standard does not make
sense.
Fix this by determining which C11 dialect (GNU or C) the compiler
supports and then constructing the compiler option from that.
Also restrict LT_LDFLAGS to the final libusb library (as was done
previously) since libtool complains about versioning options for
convenience libraries.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Thu, 2 Apr 2020 03:54:09 +0000 (20:54 -0700)]
automake: Add extra Makefile to handle unknown automake targets
Automake does not know how to compile Windows Resource files, so we have
manually told automake how to do this. One particular short-coming is
that dependencies are not automatically generated and tracked as they
are with other known automake targets. Address this by creating an extra
makefile that contains the automake rules needed for building source for
Windows targets. This also includes outputting more accurate tags during
compilation instead of using the generic "GEN" tag.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Wed, 1 Apr 2020 02:57:28 +0000 (19:57 -0700)]
Windows: Improve the get_interface_details_filter() function
The sole caller of this function only cares about the device interface
path, so change the calling convention to be like that of the
get_interface_details() function. This also adds more precise error
reporting.
Since this function is specific to the libusb0 filter driver, do not
require the caller to provide the GUID for the libusb0 filter driver.
Remove the use of strtok() on the result of this function. The strtok()
function is not reentrant and is less-than-optimal for locating the
start of the GUID component in the device interface path.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Wed, 1 Apr 2020 01:23:43 +0000 (18:23 -0700)]
Windows: Replace the sanitize_path() function with normalize_path()
Once upon a time the sanitize_path() function was needed to generate a
consistent path format in order to hash the resulting string for use as
session IDs. Since commit
71a779d078 ("Windows: Rework WinUSB
enumeration process to fix issues on Win8+"), this hashing method is no
longer used for session IDs, thus the sanitize_path() function was no
longer explicitly needed.
User lo1ol also reports in issue #633 that the function actually causes
issues with devices where there is a path component following the device
interface GUID. Rather than patching the function to fix this specific
behavior, just replace it with a simpler function that returns an
uppercased duplicate of the input string.
Closes #633, Closes #662
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Tue, 31 Mar 2020 22:47:31 +0000 (15:47 -0700)]
Move CI-related files into .private directory and add unified build script
The files needed for Continuous Integration (AppVeyor, Travis) are not
meant for public consumption, so clean up the root directory by moving
these files underneath .private.
Create a single build script that is leveraged by both AppVeyor and
Travis. This script replaces the previous 'travis-autogen.sh' file and
enables additional compiler warnings that should provide additional
coverage for all build environments.
Update the Travis configuration file to absorb the Brewfile and update
the Xcode images. Per warnings from Travis, Xcode6.4 is obsolete, thus
replace it with Xcode7.3. Additionally remove the "gcc" variants for the
macOS builds. The builds never used gcc to begin with and actually using
gcc causes build errors due to Clang-specific pragmas in the IOKit
header files.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Mon, 30 Mar 2020 23:53:43 +0000 (16:53 -0700)]
Xcode: Update project file
Add '-fvisibility=hidden' to the additional compiler flags of the libusb
target so that internal library symbols are hidden.
Add '-pthread' to the additional compiler flags of the targets that
directly use pthread functionality
Add the 'sam3u_benchmark' and 'testlibusb' targets so that all examples
are now built and fix build warnings that occur when building
'sam3u_benchmark'.
Fix target dependencies so that all targets are able to build without
issues.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Mon, 30 Mar 2020 20:21:04 +0000 (13:21 -0700)]
android: Update makefiles to include recent autobuild changes
Add C11, thread and visibility compiler flags. Enable additional
warnings and errors. Unify spacing amongst the makefiles.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Mon, 30 Mar 2020 19:38:47 +0000 (12:38 -0700)]
build: Enable additional build errors and warnings
Help catch more errors by enabling additional build errors and warnings.
Address some of the warnings seen with these new flags, including moving
the libusb_transfer structure back out of the usbi_transfer structure to
address 'warning: invalid use of structure with flexible array member'.
Apparently a structure ending with a flexible array member is not okay
with the compiler as the last member within another structure.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Mon, 30 Mar 2020 19:28:11 +0000 (12:28 -0700)]
build: Require C11 to build and clean up autoconfig/automake files
C11 compiler support has been available for many years now. It is not
unreasonable to require this now, and doing so allows some cleanup to
the configure script. It is no longer necessary to check for compiler
support of the '-fvibility' flag because any compiler that supports C11
will support this flag as well.
Fix up the way that compiler and linker flags are passed down to the
various makefiles. The compiler flags should be shared by all, but the
linker flags and libraries should be separated between the library and
the examples/tests. The visibility flag is only relevant for the
library and the thread flags are only relevant for sources using thread
constructs, so provide them as needed.
Rearrange configure.ac to group similar functionality and consolidate
where possible.
Based on these changes, update the Travis configuration file to include
newer versions of test platforms to ensure proper C11 compiler support.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Sat, 28 Mar 2020 02:48:15 +0000 (19:48 -0700)]
libusb/Makefile.am: Remove unnecessary assignments
Remove the unnecessary assignment of EXTRA_DIST. Anything that could end
up in SOURCES is automatically included in the distribution.
Remove the unnecessary assignment of libusb_1_0_la_CFLAGS. AM_CFLAGS is
already the default value, but assigning to the variable makes automake
think that custom CFLAGS are needed and therefore causes a bunch of
pointless additional rules to be generated. As a reference, the
generated Makefile shed 21,560 bytes (from 52,029 bytes to 30,469).
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Sat, 28 Mar 2020 01:23:16 +0000 (18:23 -0700)]
core: Kill the OS_* definitions and use in the source code
These symbols are no longer necessary for the source code since commit
cad7d0edd9 ("core: Kill usbi_os_backend structure definition madness").
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Fri, 27 Mar 2020 07:03:41 +0000 (00:03 -0700)]
threads_posix: Improve usbi_get_tid() for various platforms
Add support for real thread IDs on macOS 10.6 and later using the new
pthread_threadid_np() function.
Add support for thread IDs on Haiku, NetBSD and Solaris.
Provide a fallback value other than -1 when direct support is not
available. This should suffice as a unique identifier since pthread_t,
while opaque, is still distinct amongst active threads.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Fri, 27 Mar 2020 04:38:45 +0000 (21:38 -0700)]
strerror: Micro-optimize implementation and remove use of strncasecmp()
When comparing the user-provided locale string in libusb_setlocale(), we
only care about the first two characters. The lookup strings within
libusb are always lowercase, so simplify the comparison by directly
comparing the result of tolower(). This removes the need for
strncasecmp() which was not able to be cleanly included in the first
place.
Rather than storing an index into the array of localized strings, store
a pointer to the selected sub-array instead. This trims the generated
code of libusb_strerror() by nearly half as loads can be dropped.
Also constify the arrays of strings as they should not be mutable.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Thu, 26 Mar 2020 22:50:04 +0000 (15:50 -0700)]
darwin: Explicitly cleanup cached devices during the last libusb_exit()
Deferring the cached devices cleanup until the "destructor" function is
called makes it appear as though libusb is leaking memory, especially if
heap allocations are analyzed after calling libusb_exit(). It can also
lead to devices staying on the list longer than they should, as seen by
the following sequence of events:
libusb_init() <-- init_count is 0, async thread is started
devices_scan_devices() <-- enumerates devices
libusb_exit() <-- init_count is 0, async thread is stopped
[one or more devices disconnected]
Because the async thread is stopped when device(s) are disconnected in
the above sequence, the disconnection event(s) will not be processed and
thus darwin_devices_detached() will not be called and the list will have
one or more stale entries until the "destructor" function is finally
called.
Address both of these shortcomings by cleaning up the cached devices
list after stopping the async thread.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Thu, 26 Mar 2020 22:40:23 +0000 (15:40 -0700)]
appveyor: Increase build coverage to all VS solutions
Using the 'for' construct allows the specification of a more complex
build matrix. This additionally simplifies the builds using MinGW and
Cygwin because the build script can be unified and does not require
checking for the 'Release' configuration.
This change also extends the MinGW builds to cover both 32-bit and
64-bit builds using GCC versions 6.3.0 and 8.1.0, respectively. The
Cygwin builds were similarly extended to include 64-bit build coverage.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Wed, 25 Mar 2020 07:41:32 +0000 (00:41 -0700)]
libusb/Makefile.am: Fix out-of-tree builds on Windows
The prerequisite $< includes the path when not building in-tree, thus
the use of $(srcdir) as a prefix is incorrect.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Wed, 25 Mar 2020 07:27:11 +0000 (00:27 -0700)]
msvc: Update include path for getopt in fxload projects
Commit
07d6d3a2a5 ("msvc: Reorder solution projects and add project
filter files") moved the getopt source into the msvc directory but did
not include updating the include paths for the project that needs the
header files.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Wed, 25 Mar 2020 07:09:26 +0000 (00:09 -0700)]
autotools: Fix a number of issues
Change the name of the project to be what it actually is called
everywhere: libusb-1.0. This allows the public libusb.h header file to
be tracked by automake through pkginclude_HEADERS.
Decouple the doc directory from automake. There aren't any targets that
automake understands, so the build uselessly recurses into the directory.
Update the makefile targets with the correct dependencies so that the
docs aren't regenerated unnecessarily. Update the doxygen config file to
include the version, exclude irrelevant source files and create the
output into 'api-1.0' instead of 'html'. Also fix a deprecation tag for
the libusb_get_port_path() function and add Solaris to the list of
supported platforms.
Fix the 'dist' target. Clean up the README file to remote the GitHub
Markdown and remove the .gitattributes file from the msvc directory.
Add doc/libusb.png to EXTRA_DIST.
Enhance the {dist,doc}-upload targets to look at the SF_USER environment
variable to get the SourceForge username. This allows maintainers (like
me!) to have a local username that is different from their SourceForge
username. Switch the docs-upload recipe to use rsync with --delete to
clean up obsolete files.
Fix the Windows shared library (DLL) targets. The dependencies for the
RC file were incorrect, leading to cases of missed recompilation. The
'all' rule should not be overridden, so define an 'all-local' rule when
necessary. Fix the rule for running dlltool on the just generated DLL so
that it only fires when the correct dependencies change and do not
bother to run the rule when not building a DLL.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Mon, 23 Mar 2020 22:17:50 +0000 (15:17 -0700)]
msvc: Reorder solution projects and add project filter files
Since Visual Studio picks the first project as the default startup
project, move the library projects back to the top of the list. This use
to be the order but was changed in commit
9843b689df.
Add the project filter files to help organize the source files within
the Solution Explorer window pane.
Additionally move the getopt source underneath the msvc directory since
it is only used for Visual Studio builds.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Tue, 17 Mar 2020 03:14:24 +0000 (20:14 -0700)]
Haiku: Fix some issues in the backend
Since commit
8cfcc63f4f ("haiku_usb_raw: Add missing wrap_sys_device
field to usbi_os_backend"), compilation of the Haiku backend has been
broken. Since the code is C++, named initializers are not supported. Fix
this by going back to the original style of initializing
usbi_os_backend.
Additionally, commit
db99ef3451 ("Various fixes for the Haiku port")
further broken some things. The ClearHalt() function was defined as a
member of the USBDevice class but is declared and needed as a member of
the USBDeviceHandle class. The ioctl command code also contained a typo.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Mon, 16 Mar 2020 08:15:29 +0000 (01:15 -0700)]
core: Make the 'reset_device' function of the backend optional
The majority of backends do not have support for resetting a device, so
simplify them all by making the function optional and having the core
return the appropriate error when the function is not implemented.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Mon, 16 Mar 2020 08:06:27 +0000 (01:06 -0700)]
core: Fix return value of usbi_clock_gettime()
In most cases, usbi_clock_gettime() will map to the standard library's
clock_gettime() function. The semantics of this function are that it
returns -1 upon failure with the error code available in the errno
variable. The backends that need to implement this function should
follow the same semantics, and the return value of usbi_clock_gettime()
should not be directly propagated upwards.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Mon, 16 Mar 2020 08:01:51 +0000 (01:01 -0700)]
core: Move parameter validation from backend to core
Some functions (e.g. libusb_set_interface_alt_setting()) do not perform
sufficient parameter validation, leaving the burden on the backend to
catch invalid user input. Much of this validation is common across all
backends, yet not every backend implemented it. Fix this by moving
parameter validation to the core library functions.
This is also a good opportunity to remove the redundant
'num_configurations' field from the libusb_device structure. The value
of this field is already contained in the 'device_descriptor' member.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Mon, 27 Jan 2020 06:43:28 +0000 (22:43 -0800)]
core: Kill usbi_backend.clock_gettime() function
Out of all the backends supported by libusb, only two need to provide an
implementation of the clock_gettime() function. Windows completely lacks
such a function and versions of Mac OS prior to 10.12 do not provide it.
In all other cases the backend simply ends up calling the C library's
clock_gettime() function.
Let's optimize for the common case and check for the availability of
clock_gettime() during configure. If available, we will just call it
directly from any part of the library that needs it. If not available,
the backend is required to provide an implementation of
usbi_clock_gettime() that matches the current requirements.
Closes #685
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Tue, 10 Mar 2020 06:06:17 +0000 (23:06 -0700)]
Windows: Fix some harmless build warnings
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Fri, 6 Mar 2020 07:19:55 +0000 (23:19 -0800)]
core: Switch usbi_transfer to store timeout as timespec
The transfer timeout is structured around time values provided by the
clock_gettime() function. This function uses a timespec structure, but
the usbi_transfer structure was storing its calculated timeout in a
timeval structure. This mismatch introduces extra work when checking for
transfer timeouts as there must be a conversion between these two
structures. Eliminate this by storing the calculated timeout as a
timespec, thus allowing direct comparison.
Note that a conversion to a timeval is still necessary in the
libusb_get_next_timeout() function because the public API uses a timeval
structure, but this is now the only place where such a conversion is
done.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Tue, 3 Mar 2020 00:23:45 +0000 (16:23 -0800)]
darwin: Fix race condition that results in segmentation fault
Commit
763668cc92 ("darwin: fix occasional dead-lock on libusb_exit")
resolved the deadlock situation observed in #112, but unfortunately
there is a very rare race condition that can occur when the asynchronous
event thread exits the run loop before CFRunLoopWakeUp() is called. This
can occur when the shutdown source signal is processed as part of other
events in the run loop, in which case the thread was already "awake".
Prior to this change I was able to consistently trigger a segmentation
fault within 10,000 iterations of a libusb_init()/libusb_exit() loop.
With this change I reached over 4 million iterations without issue.
Closes #701
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Wed, 26 Feb 2020 23:55:10 +0000 (15:55 -0800)]
core: Introduce accessor functions for structure private data
The backend private data for the internal library structures has been
accessed through a zero-length os_priv array of type unsigned char.
This approach had two particular disadvantages:
1) A special attribute was needed on the 'os_priv' member to ensure
that the field was properly aligned to a natural pointer alignment.
The support needed for this is not available in every compiler.
2) Each access to the private data areas required an explicit cast
from unsigned char to the type required by the backend.
This change reworks the way the private data is accessed by the
backends. New accessor functions return the private data as a void
pointer type, removing the need for an explicit cast (except for Haiku,
which is C++). The special alignment attribute trickery is also replaced
by simple pointer arithmetic.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Wed, 26 Feb 2020 23:14:56 +0000 (15:14 -0800)]
core: Optimize the memory layout of the transfer structure
Prior to this commit, the memory layout of the transfer structure was as
follows:
------------------------------------------------------
| usbi_transfer | libusb_transfer [variable] | os_priv |
------------------------------------------------------
With this layout, accessing the os_priv area requires calculating the
size of the area used by the libusb_transfer, which varies based on the
number of iso packets allocated for the transfer.
This commit changes the memory layout of the transfer structure to the
following:
------------------------------------------------------
| os_priv | usbi_transfer | libusb_transfer [variable] |
------------------------------------------------------
Having the os_priv in a fixed position relative to the usbi_transfer
allows for constant-time access with the added benefit of not allowing
the user to corrupt the data by accessing elements of the
libusb_transfer structure that are out-of-bounds.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Wed, 26 Feb 2020 17:18:02 +0000 (09:18 -0800)]
core: Use a consistent variable name for usbi_transfer structures
Most places in the library use the name 'itransfer' when referring to a
usbi_transfer structure. This is helpful to distinguish between the
public libusb_transfer structure and the internal structure. Fix up the
few places that don't follow this convention so that it is consistent
across the entire library.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
a1exdandy [Sat, 22 Feb 2020 22:43:09 +0000 (01:43 +0300)]
Windows: fix MAX_PATH_LENGTH
The MAX_PATH_LENGTH in libusb Windows backend is used as size of
dev_id buffer. This buffer used for retreiving Device Instance Id
by SetupDiGetDeviceInstanceIdA function. Acording to Microsoft,
Device Instance Id must be less than MAX_DEVICE_ID_LEN = 200.
So, value of 128 maybe not enough.
Closes #699
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Alexander Stein [Wed, 5 Feb 2020 20:41:07 +0000 (21:41 +0100)]
linux: provide an event thread name
Instead of having just the application name as thread name, provide a more
descriptive one, which can e.g. read by htop.
If setting the name fails, the thread will still work as intended, just
raise a warning in this case.
Closes #689
Signed-off-by: Alexander Stein <alexander.stein@mailbox.org>
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Fri, 24 Jan 2020 19:51:55 +0000 (11:51 -0800)]
threads_posix: Use thread-local storage to cache thread ID
Trying to capture debug logs that reproduce a problem can be tricky.
Turning up the debug level will automatically make the program a bit
slower. This alone cane make timing-sensitive bugs "disappear" when
capturing logs. One of the hot paths for debug messages is fetching the
thread ID, which is immeasurably helpful in understanding thread
interactions within the library. Unfortunately most implementations
require a system call to fetch the executing thread's ID, which isn't
exactly going to help in the way of execution time.
Add a check for thread-local storage support when configuring the
library to build. If the toolchain provides this support, only one
system call will be required per thread. This check is only done for
non-Windows systems because thread-local storage is inefficiently
implemented on MinGW.
Closes #682
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Fri, 7 Feb 2020 23:47:55 +0000 (15:47 -0800)]
Windows: Refactoring to consolidate and simplify common code
Both the UsbDk and WinUSB backends perform common steps when handling
transfers in order to interact with the poll abstraction, both during
submission and when processing transfer completion. With some
rearranging of shared structures, this can be yanked from the individual
backends and placed in the common area. This allows for several
functions to be removed outright from each backend.
The cancellation logic can also be simplified by attempting CancelIoEx()
at the highest level and delegating to the backend if there are
alternatives to try should CancelIoEx() fail.
After some analysis of how Windows processes asychronous (OVERLAPPED)
requests that the underlying driver completes synchronously, it is now
evident that such requests need not be handled in any special fashion.
Each function that called a driver function that was expected to
complete asynchronously had logic to handle the case of a synchronous
completion, so this has all been killed off. This significantly cleans
up these call sites as now they must only check for an error condition.
Finally, the initialization code for the WinUSB backend has been
reworked to load the WinUSB DLL independent of the libusbK DLL.
Previously when the libusbK DLL was present, all requests to devices
using WinUSB would first be sent through the libusbK DLL where
they would then be forwarded to the WinUSB DLL. This is slightly
inefficient but is also limiting when using Windows 8.1 or later because
support for isochronous transfers through WinUSB will be lost.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Fri, 31 Jan 2020 04:48:56 +0000 (20:48 -0800)]
Windows: Fix poll implementation for NDEBUG (Release) builds
The refactoring in commit
df61c0c3a3 ("Windows: improve poll
abstraction") introduced a bug in builds where NDEBUG is defined because
of a statement with side-effects that was put inside an assertion. When
this statement is not evaluated, the file descriptor table gets corrupt.
Fix this by moving the statement outside of the assertion.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Tue, 28 Jan 2020 18:24:14 +0000 (10:24 -0800)]
Windows: Fix reported length of synchronous control transfers
WinUSB control transfers that complete synchronously are incorrectly
having the actual transfer length set to the size of the transfer
buffer. If the control transfer is a read, the device may return less
data than the transfer buffer size. Fix this by reporting the actual
bytes transferred.
Closes #667
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Mon, 27 Jan 2020 06:01:50 +0000 (22:01 -0800)]
linux_usbfs: Drop support for kernel versions earlier than 2.6.32
The Linux backend plays lots of games to try and work with older
versions of the kernel that do not have certain features. Lets simplify
the backend by requiring at least 2.6.32 to use libusb. The only thing
remaining that still requires explicit version checking is the maximum
iso frame packet size.
Anything running 2.6.32 or later is sure to have a functional monotonic
clock, so this change also allows the removal of the get_timerfd_clock()
function from the backend as well as the check for a functional
monotonic clock during initialization.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Sun, 26 Jan 2020 22:31:35 +0000 (14:31 -0800)]
Windows: Fix GCC printf format warnings due to DWORD/ULONG types
The Visual Studio compiler considers a long to always be 32-bits, so the
official Windows API headers define the DWORD and ULONG types as
unsigned long proper. GCC (and possibly other compilers) vary the width
of a long to match the build target, so this complicates printf format
strings for these two types because the underlying type is inconsistent.
Address this mess by introducing a macro that casts as necessary for the
compiler.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Sun, 26 Jan 2020 22:29:48 +0000 (14:29 -0800)]
autobuild: Fix two issues
The test for defining the automake conditional for the poll
implementation was keying off of the threads variable, producing
incorrect results for Cygwin.
A simple typo in the Makefile causes a build failure when
cross-compiling for Windows.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
root [Sun, 26 Jan 2020 13:01:09 +0000 (15:01 +0200)]
core: Fix build on linux
Commit 7bc0ff3 left a parenthesis over which prevents succesful build.
Signed-off-by: Andrey Perevortkin <asavah@avh.od.ua>
Chris Dickens [Sat, 25 Jan 2020 20:10:04 +0000 (12:10 -0800)]
core: Convert internal macros to static inline functions
Older versions of the Visual Studio compiler are picky about macros
constructed with the 'do { ... } while (0)' construct. Convert these
internal ones to static inline functions. The result is functionally
equivalent but gets us type checking and a bit more readability.
Also address some compiler warnings due to some header files that are
being included in a different order than before.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
winterrace [Fri, 24 Jan 2020 21:59:52 +0000 (22:59 +0100)]
Fix msvc 2019 project files (internal linkage)
Closes #683
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Fri, 24 Jan 2020 00:18:24 +0000 (16:18 -0800)]
linux_usbfs: Clean up inconsistencies and optimize memory usage
The formatting and coding style varied across the whole file. Adopt the
following consistent style:
- Align function arguments to the opening parenthesis
- Do not check for NULL before calling free()
- Reduce indentation where possible in loops by continuing in the
success case
- Remove space between function name and opening parenthesis
- Remove pointless pointer casts from void *
- Replace comparisons with NULL or 0 by a negation operator
- When comparing against rvalues, place the rvalue on the right side
of the expression
- Where possible, have the debug message string on the same line as
the usbi_* call. This makes it easier to grep for specific strings.
Also update the definitions in linux_usbfs.h to exactly match that of
the kernel and remove definitions that are not needed.
A number of functions declared stack buffers of size PATH_MAX. This is
generally 4K, which is very much overkill for a lot of the strings and
is not friendly for embedded environments. Replace many of these buffers
with reasonably-sized ones, in many cases using exactly the size needed.
When reading the descriptors during device enumeration, we were starting
with a 1K buffer and doubling as needed. The vast majority of devices
will not have a large set of descriptors, so change the allocation logic
to grow the buffer in steps of 256 bytes.
Introduce a new parsing function for reading sysfs attributes. Using the
fdopen() function to use fscanf() results in excessive memory
allocation, one for the FILE object and another for the buffer into
which the C library will read the data. The sysfs attributes of interest
are generally just a few characters, so use a small stack buffer and
some rigorous parsing to read these attributes. This also consolidates
error checking (e.g. negative values or larger than expected values).
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Thu, 23 Jan 2020 01:39:14 +0000 (17:39 -0800)]
configure.ac: Cleanup and refactoring
Make the formatting consistent across the entire file. In particular:
- Always quote strings whose values are derived
- Use tabs consistently
- Wrap all arguments with square brackets
Replace the use of '-a' with '&&' to be more portable.
Rearrange some of the feature checks to be conditional upon the platform
or backend. For example, there is no need to check for nfds_t on Windows
because poll() doesn't exist there. Similarly we now only check for
timerfd on Linux and Solaris. This translates into slightly faster
configure times.
Explicitly define tokens for both the poll and thread implementations.
This makes the preprocessor conditionals much nicer since it is not
necessary to enumerate all possible OS_* tokens. Also replace
POLL_NFDS_TYPE with a proper typedef that is based on the availability
of the nfds_t type.
Migrate to config definition names that are more consistent with
autoconf. The check for timerfd actually verifies the presence of the
library function instead of just the header definitions, and the token
USBI_TIMERFD_AVAILABLE is now HAVE_TIMERFD. Similarly the check for
syslog results in a definition of HAVE_SYSLOG.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Thu, 23 Jan 2020 01:02:20 +0000 (17:02 -0800)]
Misc: Clean up zero-length strings and recursion in clock_gettime()
Commit
0bf84e4d51 ("core: fix build warning on newer versions of gcc")
addressed compiler warnings for zero-length printf format strings in the
core library files, but there are some additional remaining in some of
the backends. Address these remaining ones in the same manner.
Also remove the usbi_dbg() call in netbsd_clock_gettime(). This causes
infinite recursion since usbi_dbg() calls the backend's clock_gettime()
function. This was similarly addressed for the OpenBSD backend in commit
6acbd8b405 ("Remove infinite recursion in OpenBSD backend").
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Thu, 23 Jan 2020 00:59:25 +0000 (16:59 -0800)]
Misc: Cleanup across multiple backends
Remove the clear_transfer_priv() function from all backends besides
Linux. This function is only needed if the backend calls
usbi_handle_disconnect(), which only Linux does.
Remove the {attach,detach}_kernel_driver() functions from the Darwin
backend. They return LIBUSB_ERROR_NOT_SUPPORTED, but the same result is
achieved by having those functions be NULL.
Remove the init() and exit() functions from the SunOS backend. They are
optional and as no-ops are pointless.
Remove NULL and 0 initializers from usbi_backend structures.
Use named initializers in the NetBSD backend.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Wed, 22 Jan 2020 23:53:17 +0000 (15:53 -0800)]
Misc: Trim and consolidate header file usage
Refactor libusbi.h to include the set of common header files needed by
every main source file in the library and change these source files to
include libusbi.h first, followed by any non-common headers. Including
libusbi.h first ensures that the config definitions are pulled in and
will eliminate redundant includes in the individual sources files.
Also clean up some whitespace errors and remove unnecessary definitions
in the manually generated config.h files.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Wed, 22 Jan 2020 23:05:34 +0000 (15:05 -0800)]
core: Make style of debug messages with errno consistent across library
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Fri, 24 Jan 2020 02:17:25 +0000 (18:17 -0800)]
appveyor.yml: Revert back to Visual Studio 2015 image
Apparently AppVeyor dropped support for some compilation environments in
the 2017 image, so fall back to the 2015 image and forego compilation
with the newer tools.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Wed, 22 Jan 2020 19:45:24 +0000 (11:45 -0800)]
Misc: Use the UNREFERENCED_PARAMETER macro for UNUSED when available
This will squelch compiler warnings if platform headers provide this.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Wed, 22 Jan 2020 19:06:29 +0000 (11:06 -0800)]
Windows: Improve poll abstraction
Commit
395e5a8a6f ("windows: remove total fds (256) limitations") and
commit
c730a8410c ("windows: workaround WaitForMultipleObjects max 64
events limitation.") lifted some hard-coded limits in the number of
HANDLEs that can be used within the library. This change improves on
these changes to make them more efficient.
A bitmap has been added to provide an efficient lookup mechanism for
located unused file descriptor indices. This avoids the O(n) lookup time
for traversing the entire fd_table. This bitmap is dynamically resized
along with the fd_table.
The incremental size of the fd_table has been reduced from 256 to 64.
The vast majority of applications won't need to use 256 HANDLEs, so we
can optimize memory usage a bit.
Commit
fb864b7cde ("fix windows crash when multi-thread do sync
transfer") added usbi_inc_fds_ref() and usbi_dec_fds_ref() functions to
work around a reference count issue. Remove these functions and change
the implementation of usbi_poll() to take a reference to each file
descriptor upon entry and drop the references when returning. If the
application experiences any kind of crash, there is a problem elsewhere.
Finally, make the thread executing usbi_poll() take part in the waiting.
The original implementation had this thread simply waiting on a single
event while separate threads waited on the HANDLEs. Now this thread will
wait on MAXIMUM_WAIT_OBJECTS - 1 HANDLEs, thereby reducing the number of
threads that are created. Additionally there is now only a single event
object that is shared amongst all waiting threads.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Wed, 22 Jan 2020 18:30:08 +0000 (10:30 -0800)]
Windows: Add missing '%' character for printf format specifier
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Wed, 22 Jan 2020 17:43:37 +0000 (09:43 -0800)]
Windows: Kill the dedicated thread for monotonic clock_gettime()
According to Microsoft, anything prior to Vista could provide
inconsistent results for the value of QueryPerformanceCounter() across
different cores. Now that XP is no longer supported, we can drop the
significant overhead of using a dedicated thread pinned to a single core
just to read a timestamp.
The C++11 steady_clock implementation directly wraps
QueryPerformanceCounter(), so if it is good enough for that then it is
good enough for our purposes.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Wed, 22 Jan 2020 00:43:32 +0000 (16:43 -0800)]
Windows: Fix some MinGW build warnings and printf format specifiers
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Wed, 22 Jan 2020 00:13:07 +0000 (16:13 -0800)]
Windows: Drop support for Windows XP
XP is nearly 20 years old and there are hoops we jump through to keep
supporting it. Time to say goodbye and simplify some things.
Closes #267
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Tue, 21 Jan 2020 23:40:45 +0000 (15:40 -0800)]
Windows: Add Visual Studio 2019 support
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Tue, 21 Jan 2020 23:39:34 +0000 (15:39 -0800)]
Misc: Remove obsolete Windows DDK build files
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Tue, 21 Jan 2020 23:38:56 +0000 (15:38 -0800)]
Misc: Clean up Visual Studio project files
Commit
a9b34d170a ("Adding support for ARM & ARM64 Windows Platform")
introduced a dependency on a particular version of the Windows 10 SDK
for *all* platforms. This is particularly annoying for most users who
will only be building for Windows. Fix this by specifying the SDK
dependency only for the ARM/ARM64 platforms and bump to the latest.
Commit
77037c4dd6 ("Adds /utf-8 to compile options") added this compiler
option to all versions of the Visual Studio project files. This results
in a number of warnings with the older versions that don't recognize
this option. Fix this by keeping this option only for 2015 and newer.
Explicitly specify library dependencies for non-static targets. With a
small change in the UsbDk backend we can completely remove all
depenencies other than kernel32.lib.
Lastly, remove the 'MinimalRebuild' option for 2015 and newer project
files as this option is now deprecated and results in a warning for each
project.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Tue, 21 Jan 2020 02:02:19 +0000 (18:02 -0800)]
Windows: Remove support for WinCE and Visual Studio older than 2013
There appears to be no need for the WinCE backend anymore, and it is
increasingly difficult to keep healthy as the rest of the library
changes.
Require at least Visual Studio 2013 to compile. This simplifies matters
as there is some semblance of C99 support there.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Thu, 16 Jan 2020 22:17:12 +0000 (14:17 -0800)]
linux_usbfs: Wait until all URBs have been reaped before freeing them
Prior to this change, the URBs allocated for an individual transfer were
freed when the last URB in the transfer was reaped. Normally this causes
no issues because URBs are reaped in the order they were submitted. If
the device is disconnected while multiple URBs are queued, these URBs
may be reaped in an order that does not match that of submission.
Change the logic to free the URBs when all the URBs of a transfer have
been reaped rather than the last one. While in here, improve some debug
messages.
Closes #607
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Mon, 13 Jan 2020 23:05:00 +0000 (15:05 -0800)]
core: Do not attempt to destroy a default context that doesn't exist
Calling libusb_exit(NULL) when a successful call to libusb_init(NULL)
has not been made results in a segmentation violation. This is
definitely a user error, but we can easily guard against it.
Closes #511
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Mon, 13 Jan 2020 22:07:31 +0000 (14:07 -0800)]
core: Fix libusb_get_max_iso_packet_size() for superspeed plus
The current logic fails to consider superspeed plus devices properly.
Fix this by checking for superspeed or greater instead of matching
against superspeed.
Closes #553
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
gudenau [Mon, 22 Jan 2018 03:21:46 +0000 (21:21 -0600)]
hotplug: Added libusb_hotplug_get_user_data()
Closes #380
[dickens] Fixed up API version in doxygen, whitespace issues, function
visibility annotation (can't use API_EXPORTED for pointer values) and
added new function to libusb-1.0.defs
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Mon, 13 Jan 2020 21:12:40 +0000 (13:12 -0800)]
Increment LIBUSB_API_VERSION for next release
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Mon, 13 Jan 2020 20:50:40 +0000 (12:50 -0800)]
examples: testlibusb: Always print VID and PID in addition to strings
Previously the program would only print the VID when the manufacturer
string is unavailable and the PID when the product string is
unavailable. Change this to print the VID and PID unconditionally and
print the manufacturer and product strings similar to how the serial
number string is being printed. In addition, line up the string values
with the rest of the output.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Chris Dickens [Mon, 13 Jan 2020 20:23:02 +0000 (12:23 -0800)]
examples: testlibusb: Formatting, whitespace and functional cleanup
Make the coding style and whitespace consistent with the rest of the
library source code.
In the print_device() function, the 'level' argument is unnecessary, so
remove it and the associated space padding. Switch to use printf()
directly instead of formatting the description into a single buffer.
This not only simplifies the code but avoids truncating the description
for devices with larger descriptor strings.
Make the output formatting consistent by lining up all the printed
values and using the same notation for all hexadecimal values.
Inspired by PR #452, enable printing all available BOS device
capability descriptors, not just the first one.
Closes #452
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Greg Kroah-Hartman [Fri, 10 Jan 2020 19:04:52 +0000 (20:04 +0100)]
core: fix build warning on newer versions of gcc
When building libusb on a "newer" version of gcc (9.2), a lot of
warnings are thrown about zero-length messages as being part of a format
string.
An example of this is:
descriptor.c:546:11: warning: zero-length gnu_printf format string [-Wformat-zero-length]
546 | usbi_dbg("");
| ^~
Fix this up by replacing all calls of:
usbi_dbg("");
with
usbi_dbg(" ");
as obviously we still want to keep the implicit tracing message in the
log.
Closes #674
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Jie Zhang [Mon, 8 Oct 2018 18:53:13 +0000 (14:53 -0400)]
windows: relax HCD root hub enumeration errors
Enumeration errors happen on one HCD root hub should not prevent
enumerating other hubs. This will fix an issue seen on some Windows 7
hosts with USB 3.0 host controller.
Closes #441, Closes #483
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
VladimirTechMan [Sun, 11 Aug 2019 11:10:54 +0000 (14:10 +0300)]
Change the errcode argument in libusb_strerror to be of type int
It would be more convenient in practice if the type of error code
argument in libusb_strerror was declared as "int", rather than
enum libusb_error: In practice, the value for the argument almost
always comes from a value returned by libusb function, thus its
type is "int" at that point. In which case, depending on the
checks enabled when compiling the C or C++ code of applications
using libusb's API, every call to libusb_strerror often requires
explicit type casting – while not a biggie, it gets inconvenient
as the number of logging calls using libusb_strerror grows.
It is worth of noting that the "peer" function libusb_error_name
already takes the int-type argument, thus eliminating the need in
extra value casting. Aligning the signature of libusb_strerror
to be the same would also improve the consistency between those
two parts of the libusb API.
Given that libusb_strerror does a range validation of its argument
value, there should not be any real drawbacks or negative effects
from "relaxing" the type declaration from enumeration to integer.
The existing application code that already does explicit casting
to enum, will keep compiling and running like before.
Closes #606
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Matthias Bolte [Fri, 13 Dec 2019 17:05:08 +0000 (18:05 +0100)]
windows: Translate ERROR_DEVICE_NOT_CONNECTED to LIBUSB_TRANSFER_NO_DEVICE
Windows 7 reports error code ERROR_DEVICE_NOT_CONNECTED if transters fail
due to unplugging the device.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Matthias Bolte [Mon, 16 Dec 2019 12:38:35 +0000 (13:38 +0100)]
windows: Fix USBD_STATUS to LIBUSB_TRANSFER_STATUS translation
The MSDN documentaion says that the most significant 4 bits of the
USBD_STATUS value indicate success/pending/error state, but then gives
them as 2 bit values.
The broken translations code assumes these to be the lower 2 bits:
0b0000 for success
0b0001 for pending
0b0010 for error
0b0011 for error
But actually it's the higher 2 bits:
0b0000 for success
0b0100 for pending
0b1000 for error
0b1100 for error
The USBDK code already deals with USBD_STATUS and gets it correct.
Another problem is that the broken translations code then masks off
the most significant 4 bits of the USBD_STATUS value, but then compares
it to the full 32 bit error codes to figure out the actual error. This
switch will always jump to the default case, because all checked error
codes have their most significant 2 bits set, but the values they are
compared against have those bits masked off.
Move the working code from the USBDK backend to the shared header and
reuse it in the WinUSB backend too.
[dickens] Fixed whitespace, removed unused definitions, add ifdef guard,
and retained name as USBD_SUCCESS to match w32api header.
Closes #665
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Pino Toscano [Fri, 27 Dec 2019 17:50:27 +0000 (18:50 +0100)]
core: include sys/time.h on any GNU libc OS
GNU libc provides sys/time.h, so unconditionally include it when using
that libc.
Since sys/time.h is already included on a number of OSes, include it to
minimize the differences between OSes when using libusb. Arguably,
sources using functions from sys/time.h (such as gettimeofday) ought to
already include it on their own; OTOH, let's avoid making such issues
OS-specific.
Pino Toscano [Fri, 27 Dec 2019 17:41:28 +0000 (18:41 +0100)]
Add Null POSIX backend
Add a simple null backend for POSIX platforms that reports no available
devices, and provides no capabilities. Make use of this new backend on
all the OSes without an existing backend, so libusb can be built even on
OSes without USB support.
Aleksandr Mezin [Sun, 22 Dec 2019 03:39:11 +0000 (09:39 +0600)]
Set project name for doxygen
Currently, generated documentation shows `My Project` as the title: see http://libusb.sourceforge.net/api-1.0/index.html
Set it to `libusb`.
Signed-off-by: Aleksandr Mezin <mezin.alexander@gmail.com>
John Keeping [Tue, 12 Nov 2019 14:01:40 +0000 (14:01 +0000)]
linux_udev: silently ignore "bind" action
When a driver is bound to a device, udev emits a "bind" action that
causes libusb to log an error message:
libusb: error [udev_hotplug_event] ignoring udev action bind
Since we know this action is not relevant for libusb, silently ignore it
to avoid people thinking there is something wrong.
There is already a debug log entry for the action, so there is no need
to add a duplicate here.
Signed-off-by: John Keeping <john@metanate.com>
Slash Gordon [Tue, 3 Dec 2019 11:47:38 +0000 (12:47 +0100)]
Linux: Improved system out of memory handling
Maps ENOMEM system error to LIBUSB_ERROR_NO_MEM.
Ludovic Rousseau [Fri, 1 Nov 2019 15:04:02 +0000 (16:04 +0100)]
Linux backend: fix ressource leak
Issue detected by Coverity:
22. leaked_handle: Handle variable fd going out of scope leaks the handle.
Signed-off-by: Ludovic Rousseau <ludovic.rousseau@free.fr>
Ludovic Rousseau [Fri, 1 Nov 2019 15:29:38 +0000 (16:29 +0100)]
Xcode: add tests/stress target
Also build tests/stress
Ludovic Rousseau [Fri, 1 Nov 2019 15:13:09 +0000 (16:13 +0100)]
Xcode: apply suggested changes from Xcode 11.2
Enable code signing.
Frank Li [Thu, 15 Aug 2019 15:21:17 +0000 (10:21 -0500)]
windows: workaround WaitForMultipleObjects max 64 events limitation.
WaitForMultiObjects have limiation. Only can wait max 64 events.
but usbi_poll may pass more than 64 fds. In previous implement,
only wait for first 64 events. if previous 64 events were not trigger
usbi_poll will wait for about 10s timemout eventhough other event triggered.
This patch workaround this limitation.
If max events less than 64, call WaitforMultiObjects directly.
If max events more than 64, group every 63 events into one work thread.
This thread call waitformulitobjects wait for this groug events and one
addtional thread exit events.
If any events trigger, this thread will trigger main notify events.
The main usbi_poll thread call waitforsingleobject wait for notify
events. If this events trigger, that means any of work threads get events.
Then call exit notify events let all working thread exit safely.
Return value changed, 0 means timeout. 1 - N means which event
triggered.
Closes #612
Signed-off-by: Frank Li <Frank.Li@nxp.com>
Signed-off-by: Nathan Hjelm <hjelmn@google.com>
Vinicius Tinti [Mon, 7 Oct 2019 11:24:17 +0000 (08:24 -0300)]
Fix linux_scan_devices() in Android
Use linux_default_scan_devices() in Android platform.
When building for Android the USE_UDEV is false and __ANDROID__ is true
resulting in no implementation for linux_scan_devices(). This commit fix
it by using linux_default_scan_devices() for Android.
Closes #637
Signed-off-by: Vinicius Tinti <vinicius.tinti@almg.gov.br>
Signed-off-by: Nathan Hjelm <hjelmn@google.com>
Kenjiro Tsuji [Fri, 11 Oct 2019 02:46:28 +0000 (19:46 -0700)]
Solaris: format mismatch in some usbi_dbg()
In sunos_usb.c, some usbi_dbg() calls have format mismatch. For example, "%d"
is specified for a size_t variable and "%llx" is specified for a uint64_t
variable. In LP64 mode, they are format mismatch. For those specifications
that are incompatible between ILP32 and LP64, format macros defined in
<inttypes.h>, such as PRIuPTR and PRIx64 should be used.
Closes #640
Closes #638
Signed-off-by: Nathan Hjelm <hjelmn@google.com>
Ludovic Rousseau [Wed, 30 Oct 2019 12:03:36 +0000 (13:03 +0100)]
Doxygen: do not hardcode the sourceforge.net username
The username to use to login to web.sourceforge.net should be configured
in ~/.ssh/config so that different developers (with different login
names) can update the documentation.
Ludovic Rousseau [Wed, 30 Oct 2019 11:56:47 +0000 (12:56 +0100)]
Doxygen: add libusb_wrap_sys_device() in the API list
Ludovic Rousseau [Wed, 30 Oct 2019 11:49:08 +0000 (12:49 +0100)]
Doxygen: update config file from 1.8.8 to 1.8.16
Kenjiro Tsuji [Wed, 25 Sep 2019 23:40:11 +0000 (16:40 -0700)]
Solaris backend depends on Solaris private symbols
Solaris backend depends on the following double-linked list operation functions
from libcmdutils:
list_insert_tail, list_create, list_remote_head, list_head, list_next
However, they are private symbols in libcmdutils library and moreover libcmdutils
library is also a private library. libusb should not directly refer those symbols.
Due to this issue, linking a program with libusb fails on the SPARC platform.
This issue has been reported as #586.
Since the code using those functions is just to build the argument list for execv,
the double-linked list operation functions do not need to be used.
Closes #627
Signed-off-by: Nathan Hjelm <hjelmn@google.com>
Kenjiro Tsuji [Thu, 26 Sep 2019 00:11:12 +0000 (17:11 -0700)]
Solaris: fails to find USB devices on SPARC platform
On SPARC platform, libusb fails to find USB devices. sunos_fill_in_dev_info()
reads the usb-dev-descriptor property and stores idVendor and idProduct to
the dev_sesc structure in little endian. However, when creating a device name
for 'match_str' to be specified to sunos_physpath_to_devlink(), it's using the
idVendor and idProduct in dev_descr as is without converting them to the host
endian, that is big endian for SPARC. As a result, 'match_str' has a wrong
device name and sunos_physpath_to_devlink() fails to find the device path
corresponding to the USB device. idVendor and idProduct need to be converted
to the host endian when creating 'match_str'.
This is a fix for #587.
Closes #628
Signed-off-by: Nathan Hjelm <hjelmn@google.com>
Kenjiro Tsuji [Thu, 26 Sep 2019 00:51:43 +0000 (17:51 -0700)]
Solaris backend is not correctly setting the one transfer mode for Interrupt-In pipe
In sunos_check_device_and_status_open() function, if the target is an Interrupt-In
pipe, it opens the status endpoint first and writes USB_EP_INTR_ONE_XFER control
to the status endpoint to enable the one transfer mode. And it then closes the
status endpoint. After that, it opens the xfer endpoint and re-opens the status
endpoint. This is not correct, because closing the status endpoint is implicitly
disables the one tranfer mode. As a result, an event notification won't be
delivered to the client in timely manner. According to the comment in the source,
closing the status endpoint first and opening the xfer endpoint and status endpoint
in this order is intentional to avoit an issue that may happen if the USB device
has multiple configurations, which may be due to a ugen driver issue. To address
both issues, it can open the xfer endpoint first and immediately close it, which
will take care of the switch of configurations, if necessary. Then, it can open
the status endpoint, enable the one transfer mode, and re-open the xfer endpoint.
This is a fix of libusb#620.
Closes #629
Signed-off-by: Nathan Hjelm <hjelmn@google.com>
mrstock [Fri, 20 Sep 2019 12:36:07 +0000 (14:36 +0200)]
fix constant not in range of enumerated type
fix "Integer constant not in range of enumerated type 'enum libusb_transfer_status'"
LIBUSB_ERROR_NO_DEVICE doesn't exist on enum libusb_transfer_status
Ludovic Rousseau [Sun, 15 Sep 2019 15:50:37 +0000 (17:50 +0200)]
Xcode: apply suggested changes from Xcode 10.3
Nathan Hjelm [Wed, 28 Aug 2019 20:56:18 +0000 (13:56 -0700)]
on to 1.0.23
Signed-off-by: Nathan Hjelm <hjelmn@google.com>
winterrace [Wed, 21 Aug 2019 05:59:11 +0000 (07:59 +0200)]
Update poll_windows.c
Set fd_size to 0 when freeing the fd_table array.
Closes #614
Signed-off-by: Nathan Hjelm <hjelmn@google.com>
winterrace [Tue, 20 Aug 2019 21:34:00 +0000 (23:34 +0200)]
Fix NULL pointer dereference crashes
Signed-off-by: Nathan Hjelm <hjelmn@google.com>
Nathan Hjelm [Wed, 14 Aug 2019 23:20:57 +0000 (16:20 -0700)]
move on to 1.0.23-rc3
Signed-off-by: Nathan Hjelm <hjelmn@google.com>