158 Commits
Author SHA1 Message Date
Chris Dickens a2f1e2d5fd Windows: Support building dpfp and sam3u_benchmark with MSVC
Closes #151

Signed-off-by: Chris Dickens <[email protected]>
2020-11-27 18:39:53 -08:00
Chris Dickens f2e551a5ff build: Prepare config.h for inclusion in examples/tests
There are certain games played in the examples and tests source to
account for differences in build environments and target platforms. This
can be simplified by including config.h and using the definitions there.

To that end, move the printf function attribute definition from
libusbi.h to config.h and leverage it where it is used in the examples
and tests.

Signed-off-by: Chris Dickens <[email protected]>
2020-11-27 15:22:29 -08:00
Chris Dickens 9d23ed25b4 build: Fix Android and Xcode compilation errors/warnings
Commit f69548c3b3 ("examples: Enable all examples to build on all
platforms") modified dpfp and sam3u_benchmark to be buildable on any
platform, however there were some oversights and regressions introduced
for Android and Xcode.

Update the Android and Xcode build files to account for the removal of
dpfp_threaded.c as well as the inclusion of config.h from examples
and/or tests source.

Additionally switch the threaded version of dpfp to use sem_open()
instead of sem_init() as the latter is in fact deprecated on MacOS.

Closes #808

Signed-off-by: Chris Dickens <[email protected]>
2020-11-16 13:03:52 -08:00
Chris Dickens f69548c3b3 examples: Enable all examples to build on all platforms
Prior to this change, the dpfp and sam3u_benchmark examples were only
built on POSIX platforms due to a dependency on sigaction(). Furthermore
the dpfp_threaded example only worked with POSIX threads.

Lift this limitation by breaking the dependence on sigaction(). Also
provide a minimal threading abstraction so that dpfp_threaded can be
built on Windows as well.

Also merge the sources for dpfp and dpfp_threaded. The only difference
between the two is how libusb's event handling functions are called and
this can be easily handled within a single source file.

Signed-off-by: Chris Dickens <[email protected]>
2020-11-10 14:13:12 -08:00
Chris Dickens 15668087a7 Fix various CI build warnings
* [-Wpointer-arith] arithmetic on a pointer to void is a GNU extension
  * [-Wswitch-enum] enumeration values 'E1, ...' not explicitly handled in switch
  * [-Wunused-parameter] unused parameter 'p'

For '-Wswitch-enum', the switch statements in the individual backends'
set_option() function has been removed. It is not expected that backends
will need to handle or be aware of all the options.

Signed-off-by: Chris Dickens <[email protected]>
2020-11-09 15:51:44 -08:00
Hans de Goede 1be063f7bf examples/testlibusb: Print speed of devices
Print the speed of devices to exercise libusb_get_device_speed().

Signed-off-by: Hans de Goede <[email protected]>
2020-09-14 09:48:14 +02:00
Hans de Goede dca3e7ea36 examples/testlibusb: Add support for testing libusb_wrap_sys_device()
Sometimes it is useful to be able to test libusb_wrap_sys_device(),
add support for this to the testlibusb example

Signed-off-by: Hans de Goede <[email protected]>
2020-09-14 09:48:14 +02:00
Chris Dickens da5df37c4d build: Merge events and threads into single platform abstraction
The split between events and threads abstractions is unnecessary.
Simplify the library by merging the two into a "platform" abstraction.
The only meaningful change is that Cygwin builds will no longer use the
POSIX threads abstraction but will instead use the native Windows one.

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

Signed-off-by: Chris Dickens <[email protected]>
2020-09-12 22:44:28 -07:00
Chris Dickens 0abebc57a5 Fix typos detected by codespell and manual inspection
Signed-off-by: Chris Dickens <[email protected]>
2020-08-18 15:49:22 -07:00
Chris Dickens 6f0330c784 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 <[email protected]>
2020-04-09 11:46:03 -07:00
Chris Dickens 09d0312fbb 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 <[email protected]>
2020-03-30 16:53:43 -07:00
Chris Dickens 95bbfb6023 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 <[email protected]>
2020-03-30 12:38:47 -07:00
Chris Dickens 9a1bc8cafb 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 <[email protected]>
2020-03-30 12:28:11 -07:00
Chris Dickens 07d6d3a2a5 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 <[email protected]>
2020-03-23 15:17:50 -07:00
Chris Dickens f90d07613c 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 <[email protected]>
2020-01-20 18:02:19 -08:00
Chris Dickens cb95e3ad35 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 <[email protected]>
2020-01-13 12:50:40 -08:00
Chris Dickens 88ded79caa 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 <[email protected]>
2020-01-13 12:36:59 -08:00
Harry Mallon 7997e322ab xusb: Report SuperSpeedPlus
Closes #530

Signed-off-by: Nathan Hjelm <[email protected]>
2019-04-04 22:39:07 -06:00
Sean McBride 8a05a3f4e7 Fixed many compiler warnings about sign and size mismatch
- added various casts
- added some asserts where the casts made assumptions
- enabled additional warnings in Xcode project (especially -Wshorten-64-to-32)

Closes #509

Signed-off-by: Nathan Hjelm <[email protected]>
2019-01-30 22:39:23 -07:00
Victor Toso fcf9a53595 examples: Fix format-truncation on debug
As description is used only for debug, we can extend it to be sure to
fit 256 from string variable plus 3 chars from " - " as described in
gcc warning below

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

Closes #460

Signed-off-by: Victor Toso <[email protected]>

Signed-off-by: Nathan Hjelm <[email protected]>
2018-12-05 10:13:08 -07:00
gudenau 18a5f99ad3 Add missing libusb_exit on an error condition
Closes #448

Signed-off-by: Nathan Hjelm <[email protected]>
2018-12-05 10:09:12 -07:00
Chris Dickens f69255217c examples: testlibusb: Fix DDK build warning
Signed-off-by: Chris Dickens <[email protected]>
2018-03-24 17:42:46 -07:00
Sean McBride 0b3d4c68d8 Fixed various trivial cppcheck 1.80 warnings
Specifically:

redundantAssignment,examples/dpfp.c:422,style,Variable 'r' is reassigned a value before the old one has been used.
redundantAssignment,libusb/os/threads_posix.c:64,style,Variable 'ret' is reassigned a value before the old one has been used.
unreadVariable,libusb/os/netbsd_usb.c:217,style,Variable 'hpriv' is assigned a value that is never used.
unreadVariable,libusb/os/netbsd_usb.c:235,style,Variable 'hpriv' is assigned a value that is never used.
unreadVariable,libusb/os/openbsd_usb.c:251,style,Variable 'hpriv' is assigned a value that is never used.
unreadVariable,libusb/os/openbsd_usb.c:275,style,Variable 'hpriv' is assigned a value that is never used.
unsignedLessThanZero,libusb/os/windows_winusb.c:259,style,Checking if unsigned variable '_index' is less than zero.
unsignedLessThanZero,libusb/os/windows_winusb.c:298,style,Checking if unsigned variable '_index' is less than zero.
unsignedLessThanZero,libusb/os/windows_winusb.c:367,style,Checking if unsigned variable '_index' is less than zero.
invalidPrintfArgType_sint,examples/xusb.c:534,warning,%d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'.

Signed-off-by: Chris Dickens <[email protected]>
2017-12-28 22:40:30 -08:00
Sean McBride f66c63e9f0 examples: xusb: replaced insecure sprintf with snprintf
Signed-off-by: Chris Dickens <[email protected]>
2017-12-28 22:40:30 -08:00
Sean McBride 830a9cb27d Fix unused parameter warnings
Signed-off-by: Chris Dickens <[email protected]>
2017-12-28 22:40:30 -08:00
Sean McBride 8e1a282583 examples: ezusb: Renamed header guard variable to not use reserved identifier
Fixes clang -Wreserved-id-macro warning.

Signed-off-by: Chris Dickens <[email protected]>
2017-12-28 22:40:26 -08:00
Chris Dickens 539a3230cf Misc: Fix testlibusb build on VS2013 and earlier and suppress warnings
Signed-off-by: Chris Dickens <[email protected]>
2017-12-26 23:58:00 -08:00
Chris Dickens 0fece89591 Examples: Misc. cleanup to xusb
Make data that is unchanged const, remove an unused return value, and
add a missing newline to an error message.

Signed-off-by: Chris Dickens <[email protected]>
2017-12-26 16:37:34 -08:00
Chris Dickens d8c1f7caa9 Examples: Improvements to xusb's support for Microsoft OS descriptors
As noted in issue #269, the current xusb implementation does not handle
Microsoft OS descriptors from devices whose vendor code is greater than
0x7F. This commit addresses this limitation by using
libusb_get_string_descriptor() instead of the ASCII variant and parsing
the descriptor separately. Note that this issue was addressed in PR #276,
but that approach was too cryptic to read.

Closes #269, Closes #276

Signed-off-by: Chris Dickens <[email protected]>
2017-12-26 16:37:22 -08:00
Chris Dickens b4c9b4272d examples: Fix device handle leak in xusb
The CALL_CHECK macro returns from the current function, so in the
test_device() function the device handle was being leaked when one of
the functions failed. This commit adds a new CALL_CHECK_CLOSE macro that
does the same as CALL_CHECK but also closes the device handle before
returning. In addition, the macros are changed to declare their needed
variable rather than relying on the variable to already exist within the
scope of the function.

Signed-off-by: Chris Dickens <[email protected]>
2017-08-24 15:52:39 -07:00
Chris Dickens 539f22e2fd core: Introduce libusb_set_option() API function
This new function allows more flexibility in extending the library to
support more user-configurable options. It is intended to provide a
single API that can support a wide variety of needs and eliminates the
need for new API functions to set future options.

The function is introduced with a single option (LIBUSB_OPTION_LOG_LEVEL)
that replaces the libusb_set_debug() function. Documentation relating to
libusb_set_debug() and the uses of this function in the examples and
tests have been updated accordingly.

Signed-off-by: Chris Dickens <[email protected]>
2017-07-16 14:02:05 -07:00
Ludovic Rousseau a1cf206218 examples: reformat testlibusb.c
convert from DOS to Unix text format
remove extra spaces at end of line
2017-07-12 17:10:55 +02:00
Nathan Hjelm 9afb5c0caf examples: add missing include to dpfp_threaded
Signed-off-by: Nathan Hjelm <[email protected]>
2016-07-21 22:38:32 -06:00
Nathan Hjelm 7dff2d35ca examples: make dpfp_threaded work on OS X
OS X does not support unnamed semaphores so the example has been
updated to use a named semaphore instead.

Signed-off-by: Nathan Hjelm <[email protected]>
2016-07-21 22:26:19 -06:00
Anil Nair bcac08d60f Examples: Ported testlibusb from libus-0.1 to libusb-1.0
This commit is based on Nathan's branch
https://github.com/hjelmn/libusb-darwin/blob/master/examples/testlibusb1.c

Closes #178

Signed-off-by: Nathan Hjelm <[email protected]>
2016-07-21 22:08:44 -06:00
Ludovic Rousseau 964cff46cc examples: fix 3 compiler warnings
examples/hotplugtest.c:76:28: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
        vendor_id  = (argc > 1) ? strtol (argv[1], NULL, 0) : 0x045a;
                   ~              ^~~~~~~~~~~~~~~~~~~~~~~~~
examples/hotplugtest.c:77:28: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
        product_id = (argc > 2) ? strtol (argv[2], NULL, 0) : 0x5005;
                   ~              ^~~~~~~~~~~~~~~~~~~~~~~~~
examples/hotplugtest.c:78:28: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
        class_id   = (argc > 3) ? strtol (argv[3], NULL, 0) : LIBUSB_HOTPLUG_MATCH_ANY;
                   ~              ^~~~~~~~~~~~~~~~~~~~~~~~~
2016-03-06 13:42:13 +01:00
Nathan Hjelm a499ef20a1 xusb: fix typo
Signed-off-by: Nathan Hjelm <[email protected]>
2016-03-05 08:02:58 -07:00
Stefan Tauner 1fd08a1513 Replace obsolete usleep with nanosleep
This fixes compiling libusb with uclibc.

Closes #141, #165

Signed-off-by: Stefan Tauner <[email protected]>
2016-03-05 07:55:25 -07:00
Ludovic Rousseau 686ccc284b examples: fix 3 compiler warnings
fxload.c:202:17: warning: comparison of integers of different signs: 'int' and
      'unsigned long' [-Wsign-compare]
  ...for (j=0; j<ARRAYSIZE(known_device); j++) {
               ~^~~~~~~~~~~~~~~~~~~~~~~~
fxload.c:222:12: warning: comparison of integers of different signs: 'int' and
      'unsigned long' [-Wsign-compare]
                                        if (j < ARRAYSIZE(known_device)) {
                                            ~ ^ ~~~~~~~~~~~~~~~~~~~~~~~
fxload.c:263:13: warning: comparison of integers of different signs: 'int' and
      'unsigned long' [-Wsign-compare]
        for (i=0; i<ARRAYSIZE(path); i++) {
                  ~^~~~~~~~~~~~~~~~

Signed-off-by: Ludovic Rousseau <[email protected]>
2016-03-02 16:07:00 +01:00
Ludovic Rousseau 2e78f9525f examples: fix 2 compiler warnings
sam3u_benchmark.c:54:17: warning: comparison of integers of different signs:
      'unsigned int' and 'int' [-Wsign-compare]
                for (i = 0; i < xfr->num_iso_packets; i++) {
                            ~ ^ ~~~~~~~~~~~~~~~~~~~~
sam3u_benchmark.c:67:16: warning: comparison of integers of different signs:
      'unsigned int' and 'int' [-Wsign-compare]
        for (i = 0; i < xfr->actual_length; i++) {
                    ~ ^ ~~~~~~~~~~~~~~~~~~

Signed-off-by: Ludovic Rousseau <[email protected]>
2016-03-02 16:06:15 +01:00
Ludovic Rousseau 3661588fe6 examples: fix 2 compiler warnings
ezusb.c:136:13: warning: comparison of integers of different signs: 'int' and
      'size_t' (aka 'unsigned long') [-Wsign-compare]
        if (status != len) {
            ~~~~~~ ^  ~~~
ezusb.c:159:13: warning: comparison of integers of different signs: 'int' and
      'size_t' (aka 'unsigned long') [-Wsign-compare]
        if (status != len) {
            ~~~~~~ ^  ~~~

Signed-off-by: Ludovic Rousseau <[email protected]>
2016-03-02 16:05:31 +01:00
Ludovic Rousseau e10a652b4b Examples: fix typo in Nathan Hjelm email 2016-01-06 10:20:24 +01:00
Chris Dickens 8c24a1b930 Examples: fxload improvements
* Add two-stage load support
* Fix leaks in error-handling paths
* Closes #12

Signed-off-by: Chris Dickens <[email protected]>
2015-08-04 23:51:12 -07:00
Chris Dickens a1c9895543 examples: Address issues reported by Markus Elfring
* Use sig_atomic_t as data type for variable do_exit
  * Use async-safe function within signal handler

Closes #34

Signed-off-by: Chris Dickens <[email protected]>
2015-04-28 14:56:00 -07:00
Chris Dickens 30376161e5 Examples: Fix device leak in hotplugtest
Device leak occurred if either of the following occured:
  1) Detach followed by attach
  2) Two consecutive attach

Signed-off-by: Chris Dickens <[email protected]>
2015-01-12 00:12:02 -08:00
Pete Batard ada59db186 Windows: Silence VS2013 code analysis warnings
* Also update Windows version report for Windows 10
2014-11-13 22:03:30 +00:00
Pete Batard c0f5e58acb samples: set xusb to also produce debug output during init when -d is specified
* This can be quite useful for troubleshooting user issues
2014-05-18 19:49:51 +01:00
Pete Batard bcc4e517d5 core: fix/silence issues reported by Coverity
* libusb has been added to Coverity at https://scan.coverity.com/projects/2180
* Use "// coverity[keyword]" to silence the issues we don't care about
* All other issues from the Windows build have been fixed, apart from the closing of the DLLs.
2014-05-16 23:01:57 +01:00
Carl Karsten b38ac3fbb1 examples: fix incorrect error message in fxload
* Closes #3
2014-04-07 22:00:19 +01:00
[email protected] 1eff220474 Misc: Revert all references to libusb/libusb.info 2014-01-08 23:51:01 +00:00