When using sysfs to scan for devices, libusb_init() will fail if there
are no USB devices present. There is no reason for this behavior, so
this commit modifies the logic to only return an error if one or more
devices are present but none could be successfully enumerated.
Closes#301
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
This commit shrinks the size of the internal hotplug callback structure
by removing unused fields, using the correctly sized types for matching
fields, and adding a new flags field whose bits control how the callback
structure should behave.
The hotplug callback handle ID counter has also been moved to the
context structure instead of being a global variable shared amongst all
contexts. This lets each context independently manage handle IDs and use
the maximum range of possible IDs.
Finally, the hotplug callback deregistration mechanism has been improved
to signal to the event handler that an explicit deregistration needs to
be handled. This removes the need to send a dummy hotplug message, which
was using an invalid libusb_hotplug_event value anyway that was causing
some compilers to complain.
Closes#373
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
The Linux kernel has changed the maximum allowed packet length per
isochronous packet numerous times, which can create difficulties in
trying to report appropriate errors back to the user when submitting too
large of a packet on older kernels.
In an attempt to improve this situation, this commit adds logic that
will use different per-packet limits based on the detected kernel
version. Additionally, the logic has been improved to split URBs based
on the number of isochronous packets per URB, which is currently (and
has been forever) limited to 128.
Finally, the error reporting during URB submission has been improved to
catch and report errors relating to the transfer length being too large.
Closes#118
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Inspired by PR #201 (commit fa19c152), this commit adds the same project
files for the other supported versions of Visual Studio.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
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>
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>
When querying vendor-defined string descriptors, use GetIndexedString
of the HID library.
Closes#279, Closes#280
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
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>
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>
This typo caused a bunch of compile warnings about incompatible pointer types.
Closes#327
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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.
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>
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#222Closes#226
Signed-off-by: Stefan Agner <stefan.agner@toradex.com>
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
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>
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>
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>