Commit Graph

1222 Commits

Author SHA1 Message Date
Victor Toso 21540e494f linux_usbfs: Remove old comment
This comment was introduced in 737ba04ea4 together with
a few locking calls usbi_mutex_lock() which were removed by
a886bb02c8.

Signed-off-by: Victor Toso <victortoso@redhat.com>
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2017-12-22 11:47:02 -08:00
Victor Toso e5ec22e6ad linux_udev: Initialize pointer before calling external API
udev_list_entry_foreach() sets the entry variable for each device but
initializing the pointer to NULL to avoid warnings.

Found by Coverity:

libusb-1.0.21/libusb/os/linux_udev.c:273:
error[uninitvar]: Uninitialized variable: entry
>   271|    devices = udev_enumerate_get_list_entry(enumerator);
>   272|
>   273|->  udev_list_entry_foreach(entry, devices) {
>   274|        const char *path = udev_list_entry_get_name(entry);
>   275|        uint8_t busnum = 0, devaddr = 0;

Signed-off-by: Victor Toso <victortoso@redhat.com>
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2017-12-22 11:46:42 -08:00
Jakub Klama bb172b4356 linux_usbfs: Set urb->buffer_length for isochronous transfers
Linux 4.13 expects buffer_length to match sum of iso descriptor lengths.

Closes #365

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2017-12-22 11:37:52 -08:00
Roman Kalashnikov 4d9fc62643 linux_usbfs: Fixed excessive check
Closes #358

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2017-12-22 11:34:12 -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 2cefbc80f2 io: Clear transfer timeout struct when transfer has no timeout
Prior to this commit, a transfer that was submitted with a non-zero
timeout would retain this timeout if the transfer was resubmitted with
a zero (unlimited) timeout. This commit corrects this by clearing the
transfer's timeout if the desired timeout is zero.

Closes #332

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2017-08-18 18:21:19 -07:00
Ludovic Rousseau 1fe3db7919 darwnin: fix compilation warning
os/darwin_usb.c:81:14: warning: initializing 'char *' with an expression of type
      'const char [12]' discards qualifiers
      [-Wincompatible-pointer-types-discards-qualifiers]
static char *darwin_device_class = kIOUSBDeviceClassName;
             ^                     ~~~~~~~~~~~~~~~~~~~~~
2017-07-28 11:44:59 +02:00
jonner 140a4cbaa4 Fix typo in exit() function signature
This typo caused a bunch of compile warnings about incompatible pointer types.

Closes #327

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2017-07-27 14:29:09 -07:00
Chris Dickens 468d864806 core: Preparation for handling backend-specific options
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2017-07-16 14:41:55 -07:00
Chris Dickens 86b162c335 core: Pass context to backend when calling exit() function
Providing the context to the exit() function will allow backends to
perform context-specific teardown, if needed.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2017-07-16 14:18:30 -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
Chris Dickens 34987d005e core: Slightly refactor and improve logging code
This change refactors the code that reads the LIBUSB_DEBUG environment
variable into a function to avoid code duplication and ensure that the
value is coerced into a valid libusb_log_level value.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2017-07-12 11:29:37 -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
Chris Dickens 32ef4335d4 core: Fix --disable-log option to remove logging functionality
Prior to this commit, building the library with the '--disable-log'
option would compile out the debug messages, but the logging functions
remained and would never be used. This commit brings the logging
functions themselves into consideration when building the library.

Additionally, the logging code has been optimized to compile away
unnecessary checks when the '--enable-debug-log' is used and to remove
the debug variables from the context if the library is compiled in such
a way that the debug level is not configurable.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2017-07-09 21:28:57 -07:00
Chris Dickens fc49cc10ba core: Add provisions for per-context private backend data
This functionality will be useful for backends that need to maintain
data specific to a context.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2017-07-06 14:26:46 -07:00
Chris Dickens cad7d0edd9 core: Kill usbi_os_backend structure definition madness
Prior to this commit, each backend provided its own uniquely named
usbi_os_backend structure and a massive pile of #ifdefs assigned the
global usbi_backend pointer to the correct one. This commit kills off
all this code and instead has each backend provide the usbi_backend
symbol directly. The linker can inform of any issues that might arise
with symbols.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2017-07-06 14:26:46 -07:00
Chris Dickens ef8776ddea Misc: Ensure the 'os_priv' member of structures is pointer aligned
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2017-07-06 14:26:46 -07:00
Chris Dickens cb216b4c96 Misc: Refactor zero-length array declarations
Instead of checking for __STDC_VERSION__ at every instance, define a
ZERO_SIZED_ARRAY macro that has the appropriate definition and use that
everywhere it is needed.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2017-07-06 14:26:46 -07:00
Adrian Bunk e59e437a1f libusb.h: use __linux__ instead of __linux
The check was added since sys/time.h is not available on Windows,
but breaks on PowerPC where __linux is not defined by GCC in strict
standards modes.

Signed-off-by: Adrian Bunk <bunk@debian.org>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2017-06-19 18:25:21 +02:00
Chris Dickens 448eb4e38e Empty commit to resync nano
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2017-06-05 23:24:21 -07:00
l_proger 625b180945 Windows: Fixed USB_CONFIGURATION_DESCRIPTOR struct alignment issue (10 bytes size instead of 9)
Closes #293

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2017-06-05 23:18:19 -07:00
Chris Dickens 0ccf7eaaae Windows: Header file cleanup
This commit removes unused or redundant definitions from the
windows_winusb.h header file and leverages existing definitions
within the core library headers. The definitions of structures
related to the Windows API are also modified to match official
headers.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2017-06-05 23:18:13 -07:00
Sameeh Jubran 00c7a1625e Align error code handling with WinUsb
WinUsb uses ERROR_GEN_FAILURE instead of ERROR_FUNCTION_FAILED,
this diffrence was observed while using Libusb's xusb example
application while alternating backends.

Signed-off-by: Sameeh Jubran <sameeh@daynix.com>
Reviewed-by: Dmitry Fleytman <dmitry@daynix.com>
2017-05-17 16:05:18 +03:00
Chris Dickens fc9962027f Windows: Fix regression introduced by 05b0b55b
Closes #298, Closes #300

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2017-05-11 21:33:04 -07:00
Andy McFadden b06b4d101b git: Don't ignore platform config.h
The android and Xcode config.h headers were being ignored.
2017-03-31 08:54:21 +02:00
Chris Dickens 05b0b55b75 Windows: Fix possible memory leak when caching descriptors fails
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2017-03-26 20:37:41 -07:00
Chris Dickens beb0d61b92 linux: Apply v2 version of patch for CLOEXEC changes
Somehow I managed to push v1 of the patch, which didn't handle older
versions of the kernel or C library that don't support the O_CLOEXEC
flag (suggested by Tim Roberts). This commit amends the original
changes in aa73b2ec and provides this backwards compatibility.

Closes #286

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2017-03-26 20:25:27 -07:00
tich 871eb299b9 macOS Sierra: Fix detection of parent devices.
This fixes the output of libusb_get_port_numbers(), where it used to merely return the port number of the device itself.
Now that libusb properly detects parent devices, we get the entire port path of the device.
For reference, here's the output of the 'listdevs' example before my changes:

tich-mbp:libusb-1.0.21 tich$ ./examples/listdevs
0409:005a (bus 29, device 6) path: 1
05ac:8509 (bus 26, device 2) path: 1
05ac:821d (bus 29, device 7) path: 3
05ac:0252 (bus 29, device 5) path: 3
05ac:8242 (bus 29, device 4) path: 2
0a5c:4500 (bus 29, device 3) path: 1
0424:2513 (bus 29, device 2) path: 8
8087:0024 (bus 29, device 1) path: 1
8087:0024 (bus 26, device 1) path: 1

And here's the output after my changes:

tich-mbp:libusb-1.0.21 tich$ ./examples/listdevs
0409:005a (bus 29, device 6) path: 1.1
05ac:8509 (bus 26, device 2) path: 1.1
05ac:821d (bus 29, device 7) path: 1.8.1.3
05ac:0252 (bus 29, device 5) path: 1.8.3
05ac:8242 (bus 29, device 4) path: 1.8.2
0a5c:4500 (bus 29, device 3) path: 1.8.1
0424:2513 (bus 29, device 2) path: 1.8
8087:0024 (bus 29, device 1) path: 1
8087:0024 (bus 26, device 1) path: 1

Since we're now using "IOUSBHostDevice" as the matching service (starting with El Capitan), we need to walk up the IOService plane to look for parents.
You can manually walk up the IOService plane by executing "ioreg -p IOService -l -w 0 -x | less" and looking for your device. Notice that the parent device is always a parent in the tree, but it's not always the _immediate_ parent of the device.
2017-03-16 19:35:44 -06:00
Nathan Hjelm 2756874a93 darwin: use clock_gettime() on 10.12+
Apple implemented the POSIX.2 clock_gettime () call in macOS
10.12. This commit updates the darwin backend to not use the mach
clock if clock_gettime() is available.

Signed-off-by: Nathan Hjelm <hjelmn@mac.com>
2017-03-16 15:08:35 -06:00
Stefan Agner 18a1452ee8 Windows: Allow HID reports up to 1024 + report id
HID reports can contain up to 1024 bytes. When using a report id
the complete buffer will be 1025 bytes. Do not return an error
if the user supplies a report id and a buffer of 1025 bytes size.

Closes #222
Closes #226

Signed-off-by: Stefan Agner <stefan.agner@toradex.com>
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2017-02-28 23:26:52 -08:00
Chris Dickens ecc87bba6e core: Improve robustness of event handling
Prior to this commit, it was possible on Linux to poll a file descriptor
that was not valid for libusb. This could happen given the following
sequence of events:

  1) Application registers hotplug callback
  2) Application calls into libusb to handle events
  3) USB device is unplugged, triggering hotplug event
  4) Event handling thread calls registered hotplug callback
  5) Hotplug callback calls libusb_close(), which closes the fd
  6) Event handling code retries the poll() call before returning

At this point, the file descriptor that is being passed to poll() may be
invalid or worse may not belong to libusb at all.

This commit fixes this by removing the code that restarted the poll() call.
It was originally added to allow the processing of multiple hotplug messages
when these messages were delivered across a pipe, but with a linked list now
holding the hotplug messages this is no longer a concern. If any hotplug
messages are present on the list, they are all processed in one pass.

Closes #238

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2017-02-28 23:06:39 -08:00
Josh Gao b08b1993a8 core: Silence 'unhandled case in switch' warning.
linux_usbfs: silence -Wsign-compare.

Closes #274

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2017-02-28 21:46:26 -08:00
Chris Dickens 93f0feb1e7 Windows: Remove initialization of calloc'ed memory
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2017-02-28 21:37:20 -08:00
Doug Johnston 92093a5924 Windows: return proper status
currently always returning `LIBUSB_SUCCESS` even if error was found

Closes #183

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2017-02-28 21:33:55 -08:00
Chris Dickens 24117d54ed travis: Pass on arguments given to travis_autogen.sh
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2017-02-28 21:29:04 -08:00
Chris Dickens aa73b2ecb8 linux: Mark internal file descriptors as CLOEXEC
As a library, libusb should take care to be as friendly as possible
with various use cases. One such way is to ensure that internal file
descriptors have the CLOEXEC flag set, thus allowing processes to do
a fork() + exec() without leaking libusb's file descriptors to the
child process.

References #268

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2017-02-28 21:25:25 -08:00
Chris Dickens 02e142f432 linux_netlink: Retry poll() on EINTR
This commit applies the same fix as commit 0a02d121 did for udev.
I've also removed usbi_ from the read()/write() function calls as
it is pointless.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2017-02-20 00:51:14 -08:00
Chris Dickens 9462d1561d .gitignore: Add some new entries
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2017-02-20 00:24:51 -08:00
Chris Dickens cb77a25e51 configure.ac: Remove obsolete AC_ERROR and make formatting consistent
Remove unnecessary quotes around simple string values.
Replace AC_ERROR with AC_MSG_ERROR.
Use [] around arguments to macros.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2017-02-20 00:22:35 -08:00
Pete Batard ffdf3c0beb misc: update active developers list
* Removing myself, since I am no longer involved in libusb
2017-01-18 14:17:38 +00:00
Chris Dickens 140ff1b635 Windows: Remove unused safe_* macro definitions
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2017-01-12 15:26:41 -08:00
Chris Dickens 5ffd4e9cc1 Windows: Slightly optimize the sanitize_path() function
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2017-01-12 15:26:40 -08:00
Chris Dickens 461babf104 Windows: Switch to snprintf() in windows_get_version()
Also remove "Windows" from the constructed string since that will
always be there and just complicates the logic.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2017-01-12 15:26:40 -08:00
Chris Dickens a7a84d2690 Windows: Fix memory and handle leaks in winusbx_claim_interface()
When using the libusb0 filter driver, the loop could potentially leak the
memory for dev_interface_details. In that same loop, if the dev path
without the GUID matches the interface path, the new file handle would
be leaked.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2017-01-12 15:26:40 -08:00
Chris Dickens a2b31bc0ac Windows: Fix some minor styling issues
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2017-01-12 15:26:40 -08:00
Chris Dickens 6a504b5da5 Windows: Clean up unnecessary variable initialization
Don't zero out variables that already are zero (calloc'ed) and
don't set variables that aren't read before being set again.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2017-01-12 15:26:40 -08:00
Chris Dickens e89983a6b5 Windows/WinCE: Remove uses of safe_* macros where not useful
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2017-01-12 15:26:40 -08:00
Chris Dickens d113986615 Windows/WinCE: Improvements to windows_error_str() function
1) Add FORMAT_MESSAGE_IGNORE_INSERTS to flags for security.
2) Optimize removal of CR/LF terminators
3) Switch to use snprintf()

Windows-specific:
  1) Don't waste time converting debug messages to unicode

WinCE-specific:
  1) Get rid of TCHAR code

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2017-01-12 15:26:40 -08:00
Chris Dickens e379622952 Windows: Provide C99 compliant implementations of (v)snprintf()
The Microsoft implementations of _snprintf() and vsnprintf() do not
guarantee that the output buffer is NULL-terminated, and they do not
return the number of bytes that *would* have been written if truncation
were to occur. This commit adds implementations that do just that.

Note that VS2015 and above provide C99 compliant versions of these
functions, so those will be used when available.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2017-01-12 15:26:21 -08:00
Chris Dickens cf1db52fbd Windows: Hash table improvements
1) The current implementation was not entirely thread-safe. The hash
   table was read outside of the mutex, which in some cases could lead
   to improper hashing.
2) The hash creation function accepted a size parameter that was
   hard-coded. Eliminating this saves time because we can ensure that
   the pre-defined size is a prime number instead of requiring code to
   calculate a prime number.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2017-01-12 15:03:37 -08:00