138 Commits

Author SHA1 Message Date
RipleyTom
2e41930f74 CMake implementation based on https://github.com/nonolith/libusb and updated 2019-02-07 04:04:29 +03:00
Chris Dickens
f69255217c examples: testlibusb: Fix DDK build warning
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
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 <christopher.a.dickens@gmail.com>
2017-12-28 22:40:30 -08:00
Sean McBride
f66c63e9f0 examples: xusb: replaced insecure sprintf with snprintf
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2017-12-28 22:40:30 -08:00
Sean McBride
830a9cb27d Fix unused parameter warnings
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
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 <christopher.a.dickens@gmail.com>
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 <christopher.a.dickens@gmail.com>
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 <christopher.a.dickens@gmail.com>
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 <christopher.a.dickens@gmail.com>
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 <christopher.a.dickens@gmail.com>
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 <christopher.a.dickens@gmail.com>
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 <hjelmn@me.com>
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 <hjelmn@me.com>
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 <hjelmn@me.com>
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 <hjelmn@me.com>
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 <stefan.tauner@gmx.at>
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 <ludovic.rousseau@free.fr>
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 <ludovic.rousseau@free.fr>
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 <ludovic.rousseau@free.fr>
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 <christopher.a.dickens@gmail.com>
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 <christopher.a.dickens@gmail.com>
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 <christopher.a.dickens@gmail.com>
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
hjelmn@cs.unm.edu
1eff220474 Misc: Revert all references to libusb/libusb.info 2014-01-08 23:51:01 +00:00
Ludovic Rousseau
3d84bba0a7 examples: check value returned by ftell()
Problem detected by the Coverity tool
CID 1042546 (#1 of 1): Argument cannot be negative (NEGATIVE_RETURNS)3.
negative_returns: "initial_pos" is passed to a parameter that cannot be
negative.

fseek(3) can't be called with a negative offset with SEEK_SET
2013-10-06 14:26:25 +02:00
Pete Batard
16692c825e examples: add an option to force a device request for WCID descriptors
* Add option 'w' to force the use of a Device Request rather than an
  Interface Request when querying the WCID OS Extended Properties descriptor.
* This is due to a WinUSB limitation where all Interface Requests have the
  wIndex set to the interface number.
* This assumes that the WCID firmware answers both Device and Interface requests
  equally.
2013-09-29 21:39:26 +01:00
Ludovic Rousseau
28d5514e61 examples: fix warning
ezusb.c: In function 'ezusb_load_ram':
ezusb.c:719:6: warning: 'ret' may be used uninitialized in this function
[-Wmaybe-uninitialized]
  int ret;
2013-09-28 13:14:17 +02:00
Ludovic Rousseau
c393574a01 examples: check value returned by libusb_bulk_transfer()
Problem detected by the Coverity tool
CID 1042540 (#1 of 1): Unchecked return value (CHECKED_RETURN)1.
check_return: Calling function "libusb_bulk_transfer(struct
libusb_device_handle *, unsigned char, unsigned char *, int, int *,
unsigned int)" without checking return value (as is done elsewhere 4 out
of 5 times).
2013-09-28 12:17:58 +02:00
Ludovic Rousseau
d4dabfd14e examples: check the value returned by libusb_handle_events()
Problem detected by the Coverity tool
CID 1042539 (#1 of 1): Unchecked return value (CHECKED_RETURN)8.
check_return: Calling function "libusb_handle_events(libusb_context *)"
without checking return value (as is done elsewhere 6 out of 7 times).
2013-09-28 12:16:13 +02:00
Ludovic Rousseau
aa00030b78 examples: check the value returned by libusb_init()
Problem detected by the Coverity tool
CID 1042538 (#1 of 1): Unchecked return value (CHECKED_RETURN)4.
check_return: Calling function "libusb_init(libusb_context **)" without
checking return value (as is done elsewhere 11 out of 12 times).
2013-09-28 12:14:13 +02:00
Ludovic Rousseau
e2babf7ec2 examples: Fix a memory leak
Close the image file before exiting the function

Problem detected by the Coverity tool
CID 1042549 (#2 of 3): Resource leak (RESOURCE_LEAK)9. leaked_storage:
Variable "image" going out of scope leaks the storage it points to.
2013-09-20 14:08:30 +02:00
Ludovic Rousseau
3c2e79cacf examples: Fix a memory leak
Close the image file before exiting the function

Problem detected by the Coverity tool
CID 1042550 (#1 of 15): Resource leak (RESOURCE_LEAK)7. leaked_storage:
Variable "image" going out of scope leaks the storage it points to.
2013-09-20 14:07:57 +02:00
Sean McBride
ce8da723b4 made some globals static to fix warnings 2013-07-30 10:44:13 -06:00
Hans de Goede
02281fda6e examples: use libusb_set_auto_detach_kernel_driver()
What better way to show how useful libusb_set_auto_detach_kernel_driver() is,
then to use it in our examples?

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2013-06-19 11:04:15 +02:00
Ludovic Rousseau
cf8a313b2c Examples: add a missing \n at end of error messages 2013-06-11 17:35:11 +02:00
Hans de Goede
511ed18228 Core: Add a libusb_strerror() function
This patch adds the much requested libusb_strerror() function, taking into
account all issues people raised wrt previous attempts.

Criteria / Decisions underlying this implementation:
- Must support translated messages
- Must not use gettext as that does not work well in combination with Windows
 (when building with Visual C, or for Windows CE)
- API compatible with FreeBSD and various patched libusb-s floating around
- KISS:
 - Do not add any (other) library dependencies
 - Do not try to deal with message encodings (iconv), simply always return UTF-8
   making encoding the problem of the application using libusb_strerror.
 - Defaults to English, so apps which don't want translated messages,
   don't need to do anything special
 - Defaults to English (with pure ASCII messages), so apps which don't
   call libusb_setlocale() don't need to worry about encoding
2013-06-10 00:16:36 +01:00
Peter Stuge
f51b19db34 examples: Add sam3u_benchmark isochronous example by Harald Welte
Copied with the author's permission under LGPL-2.1 from
usb-benchmark-project/host/benchmark.c in
git://git.gnumonks.org/sam3u-tests.git commit
74959f7ee88f1597286cd435f312a8ff52c56b7e

http://git.gnumonks.org/cgi-bin/gitweb.cgi?p=sam3u-tests.git;a=blob;f=usb-benchmark-project/host/benchmark.c;h=74959f7ee88f1597286cd435f312a8ff52c56b7e

An Atmel SAM3U test firmware is also available in the above repository.

Conflicts:
	.gitignore

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2013-05-30 14:21:00 +02:00
Hans de Goede
d7b796f1fe Add BOS descriptor support
Based on earlier work done on this by Maya Erez <merez@codeaurora.org>,
Nathan Hjelm <hjelmn@me.com> and Pete Batard <pete@akeo.ie>.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2013-05-30 14:20:51 +02:00
Hans de Goede
ef698c633d Add superspeed endpoint companion descriptor support
Based on earlier work done on this by Maya Erez <merez@codeaurora.org>,
Nathan Hjelm <hjelmn@me.com> and Pete Batard <pete@akeo.ie>.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2013-05-30 14:20:44 +02:00
Hans de Goede
f3fcf84026 Examples: Fix use of deprecated libusb_get_port_path
While at it also simplify the path printing in listdevs

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2013-05-17 10:42:47 +02:00
Hans de Goede
ebac6ac1b3 listdevs: Also print portpath for non root hubs
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2013-05-16 22:36:26 +02:00
Peter Stuge
a1b0ae5e59 examples: Only check for HAVE_SIGACTION once in Makefile.am
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2013-05-15 20:43:35 +02:00
Nathan Hjelm
57256dd159 Add some editor meta-comments for proper tab usage
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2013-05-15 20:43:35 +02:00
Nathan Hjelm
7801ff94fa Add hotplug support.
The internal API is changing as follows:
 - Adding two new functions. usbi_connect_device, and usbi_disconnect_device.
   Backends must call these functions to add them to the context's device list
   at one of two places: initial enumeration (done at init), and on device
   attach and removal. These functions need to be called once per context.
 - Backends that support hotplug should not provide a get_device_list funtion.
   This function is now deprecated and will likely be removed once all backends
   support hotplug.

The external API is changing as follows:
 - Two new functions have been added to register and deregister callbacks for
   hotplug notification: libusb_hotplug_register_callback(),
   libusb_hotplug_deregister_callback(). Hotplug callbacks are called by
   libusb_handle_events(). Details of the new API can be found in libusb.h.
 - A new capability check has been added to check for hotplug support. See
   LIBUSB_CAP_HAS_HOTPLUG.

Aa suggested by Xiaofan add new example has been added to show how to use
the new external hotplug API. See examples/hotplugtest.c.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2013-05-15 17:28:06 +02:00