| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
| |
Commit 7bc0ff3 left a parenthesis over which prevents succesful build.
Signed-off-by: Andrey Perevortkin <asavah@avh.od.ua>
|
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
| |
Closes #683
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
| |
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
| |
This will squelch compiler warnings if platform headers provide this.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
| |
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
| |
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
| |
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
|
|
|
|
| |
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
| |
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
| |
Maps ENOMEM system error to LIBUSB_ERROR_NO_MEM.
|
|
|
|
|
|
|
| |
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>
|
|
|
|
| |
Also build tests/stress
|
|
|
|
| |
Enable code signing.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
| |
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.
|