The const in the libusb_cpu_to_le16() function declaration was useless.
The consts in the libusb_version struct did have an effect, but were
overly restrictive.
Closes#1540
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>
1.0.28 shipped with new SuperSpeed+ functions, but the
LIBUSB_API_VERSION macro had unfortunately not been changed.
Fixes#1642
Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
Programs using the previous version may use the new version as drop-in
replacement, but programs using the new version may use APIs not present
in the previous one.
Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
Silently ignore invalid values, since we cannot use logging inside
the get_env_debug_level() function.
Fixes#1619
Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
Introducing the ANDROID_OS macro that is supposed to be set by clients
of libusb that are running on Android at the OS level.
If Android_OS is set (and HAVE_LIBUDEV is not) then linux netlink event
monitoring (and consequently hotplug functionality) is enabled. This
works for Android services or simple binaries running at the OS level as
they have the necessary permissions, in contrast to usual Android apps
(see commit 2f3bc98).
Note: the __ANDROID__ macro is set by GCC for all targets running on
Android (both OS-level services and apps).
Closes#1577
Signed-off-by: Nathan Hjelm <hjelmn@google.com>
Summary of problem:
The LIBUSB_TRANSFER_ADD_ZERO_PACKET flag does not work as expected on
Darwin. On my USB 3 device, with maxPacketSize = 1024, I see libusb
sending ZLP for packets multiple of 5120 instead of 1024.
The ZLPs are not being sent when they should because
darwin_get_pipe_properties() retrieve the "full" wMaxPacketSize via
GetPipePropertiesV3(), which includes bandwidth multipliers.
Summary of solution:
GetEndpointPropertiesV3() does retrieve unaltered wMaxPacketSize,
without multipliers. To call it, we first use GetPipePropertiesV3() to
set the fields required.
Fixes#1581Closes#1582
Fix recent regression introduced in commit 9d595d4.
get_dev_port_number() was always returning port number 0 for any port,
due to the incorrect assumption that strtoll's 'end' pointer will point
to a null terminator on success. This was causing
winusb_get_device_list() to always fail. Since we actually know the
expected values of *end for both the SPDRP_LOCATION_INFORMATION and the
SPDRP_LOCATION_PATHS case, check for those instead.
Additionally, document why a return value of 0 is treated as a failure
in this particular function, for valid but somewhat coincidental reasons
that may not be immediately obvious.
Closes#1544
For the 16-bit case especially, the result of the `or` is implicitly
promoted to `int`, then when returned was warning:
warning: implicit conversion loses integer precision: 'int' to 'uint16_t' (aka 'unsigned short') [-Wimplicit-int-conversion]
Add more casts to shut it up.
Closes#1541
Commit 00454ab0 accidently botched error checking when replacing
rewind() with fseek().
Thanks to GitHub user "anotheruserofgithub" for noticing.
Closes#1539
Instead of filling in the blanks with hard-coded made-up values that are
sometimes correct, use the cached descriptor values retrieved during
enumeration, which should be a better fallback.
References #1360Closes#1378
Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
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>
The addition could overflow, the upcast needs to be performed before,
not after.
Fixes all clang-tidy bugprone-misplaced-widening-cast warnings
References #1479
Copy-pasting can often result in mistakes like:
```
if (test_value(x)) {
y++;
do_something(x, y);
} else {
y++;
do_something(x, y);
}
```
Thus it is preferable that branch bodies be unique.
Fixes all clang-tidy bugprone-branch-clone warnings
References #1479
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
Depending on the font, an l suffix can look like a 1. Consider "231l".
Thus prefer uppercase.
Fixes all clang-tidy readability-uppercase-literal-suffix warnings
References #1479