We want to keep only one device open for simplicity, but instead of
closing the last opened device already before /trying/ to open a new
one, close it only if the new one was opened successfully. This way
we may keep the device open longer, and in the simple case where no
later arriving devices could be opened, until it is detached again.
Closes#1550
Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
If no device ID is specified, and for instance a hub is plugged, many
devices will be attached (and later detached) at the same time. The old
code counting only 2 events would then exit prematurely.
By counting attach and detach events separately, we preserve the old
behaviour in the single-device case, but also allow more complex
sequences to be handled in a way that mostly appears intuitive.
This is not fool-proof, and we can still end up leaving after a surprise
detachment of a "pre-existing" device while we have one of the "new"
devices open. In this case print a warning.
References #1455
Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
There was a mixup of "ret" and "r", so use "r" consistently as
in the rest of the function.
Closes#1636
Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
Commit 00454ab0 accidently botched error checking when replacing
rewind() with fseek().
Thanks to GitHub user "anotheruserofgithub" for noticing.
Closes#1539
Consider different scenario to return from main, we have to choose the
proper return value. In this way, we can easily check the return code
directly like `echo $?` in Linux to know whether the execution of xusb
is failed.
Closes#1507
Signed-off-by: Yiwei Lin <s921975628@gmail.com>
These multiplication could indeed have overflowed, but now they are
performed with a bigger type, matching the type they are ultimately
stored in.
Fixes all clang-tidy bugprone-implicit-widening-of-multiplication-result
warnings
References #1479
The C langugage reserves various identifiers for itself that user code
must not use.
Fixes all clang-tidy bugprone-reserved-identifier warnings
Also, 4 of 5 file extension tests were case insensitive, and 1 was not.
Changed it to be insensitive too.
References #1479
- Fix typos.
- Use SuperSpeedPlus naming consistently.
- Remove C++ style comment in favor of C style.
Fixup of commit f00f06e9
References #1499Closes#1502
- Sometimes just change a type to match where it's coming from
- Sometimes add an explicit cast (but only if it's guaranteed correct,
like a previous check that a signed value is positive before casting to
unsigned)
- For libusb_bulk_transfer() add an assert to be certain that the signed
return value is never negative.
Update API documentation to underline this fact.
Add similar assert in usbi_handle_transfer_completion().
- darwin: For parsing OS version, change scanf to use %u instead of %i
- xusb: Add additional range checks before casting
- xusb: Reverse some backwards count and size arguments to calloc, not
that it really matters
Closes#1414
- Replace some uses of the soft-deprecated libusb_init() and
libusb_set_debug() with their updates.
- Updated various comments to favour use of the new functions.
- Notably remove \deprecated doxygen statement, since it causes
-Wdocumentation compiler warnings.
- Notably update the xusb example to pass debug options to
libusb_init_context() instead of setting environment variable.
- Also improve comments related to LIBUSB_API_VERSION and
LIBUSBX_API_VERSION.
Closes#1408
[Tormod: Fix Doxygen formatting and references]
Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
I spent some time trying to figure out why, when I run this example,
it's not showing any events, until I looked into the code and saw it has
some hardcoded VID:PID.
Most people probably don't have the specific device hardcoded here, and
it seems better to default to showing events for any device unless
overridden.
While at it, also updated device detached message to match the attached
one to show VID:PID.
Closes#1350
[Tormod: Print error strings on failures]
Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
Do not show an uninitialized Max LUN value if the pipe stalled.
As suggested by the code comment (but not the old code), set a default
zero value only on pipe stall. On other errors simply error out.
References #1181Closes#1239
Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
This commit updates all test and example code to use the newer
libusb_init_context() function instead of libusb_init().
Signed-off-by: Nathan Hjelm <hjelmn@google.com>
[Tormod: Update umockdev.c as well]
Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
Some functions were returning e.g. -ENOMEM and the caller would check
for negative return values. However, on Haiku, contrary to modern
standards, these macros are negative, so this logic would fail. In any
case, change the function to return -1 instead. For good measure also
set errno to the appropriate value, although it is not used in the
current code.
This was discovered on Haiku builds because the value for ENOMEM is
INT_MIN which cannot be negated without overflow.
Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
This commit adds a call to libusb_kernel_driver_active and prints out the result. This
provides a way to quickly check the result when testing.
Signed-off-by: Nathan Hjelm <hjelmn@google.com>
There are certain games played in the examples and tests source to
account for differences in build environments and target platforms. This
can be simplified by including config.h and using the definitions there.
To that end, move the printf function attribute definition from
libusbi.h to config.h and leverage it where it is used in the examples
and tests.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Commit f69548c3b3 ("examples: Enable all examples to build on all
platforms") modified dpfp and sam3u_benchmark to be buildable on any
platform, however there were some oversights and regressions introduced
for Android and Xcode.
Update the Android and Xcode build files to account for the removal of
dpfp_threaded.c as well as the inclusion of config.h from examples
and/or tests source.
Additionally switch the threaded version of dpfp to use sem_open()
instead of sem_init() as the latter is in fact deprecated on MacOS.
Closes#808
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Prior to this change, the dpfp and sam3u_benchmark examples were only
built on POSIX platforms due to a dependency on sigaction(). Furthermore
the dpfp_threaded example only worked with POSIX threads.
Lift this limitation by breaking the dependence on sigaction(). Also
provide a minimal threading abstraction so that dpfp_threaded can be
built on Windows as well.
Also merge the sources for dpfp and dpfp_threaded. The only difference
between the two is how libusb's event handling functions are called and
this can be easily handled within a single source file.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* [-Wpointer-arith] arithmetic on a pointer to void is a GNU extension
* [-Wswitch-enum] enumeration values 'E1, ...' not explicitly handled in switch
* [-Wunused-parameter] unused parameter 'p'
For '-Wswitch-enum', the switch statements in the individual backends'
set_option() function has been removed. It is not expected that backends
will need to handle or be aware of all the options.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Sometimes it is useful to be able to test libusb_wrap_sys_device(),
add support for this to the testlibusb example
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
The split between events and threads abstractions is unnecessary.
Simplify the library by merging the two into a "platform" abstraction.
The only meaningful change is that Cygwin builds will no longer use the
POSIX threads abstraction but will instead use the native Windows one.
The downside to doing this is that the dpfp_threaded example program
will no longer be available on Cygwin builds. This should be fine, and
future work will make dpfp_threaded available for all forms of Windows
build systems.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
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>
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>
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>
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>
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>
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>
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>