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>
Include my own public key, used for 1.0.25/1.0.26/1.0.27 already.
The KEYS file is inspired by the Apache project:
https://infra.apache.org/release-signing#keys-policy
References #1469
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
The C langugage reserves various identifiers for itself that user code
must not use.
Fixes all clang-tidy bugprone-reserved-identifier warnings
Also, 4 of 5 file extension tests were case insensitive, and 1 was not.
Changed it to be insensitive too.
References #1479
The first iteration of this loop was safe because the beginning of the
function checked that `size` is at least LIBUSB_DT_CONFIG_SIZE (9) bytes
long.
But for subsequent iterations, it could advance the pointer too far
(which is undefined behaviour) depending on the content of the buffer
itself.
Closes#1460
All the right hand side is `dev_cap`, change one outlier to match.
Also clarify the relationships between some magic numbers.
No change in behaviour here.
This was checking that `size` is at least `LIBUSB_DT_CONFIG_SIZE` (9)
bytes long, but then increments the pointer with `buf +=
header.bLength`. That could end up pointing past of the end of the
buffer. There is a subsequent check that would prevent dereferencing it,
but it's still undefined behaviour to even create such a pointer.
Add a check with a similar pattern as elsewhere in this file.
This function had a few problems:
- it takes two buffers as parameters but knows nothing about their
length, making it easy to overrun them.
- callers make unwarranted assumptions about the alignment of
structures that are passed to it (it assumes there's no padding)
- it has tricky pointer arithmetic and masking
With this new formulation, it's easier to see what's being read/written,
especially the destination. It's now very clear that the destination is
not being overrun because we are simply assigning to struct fields.
Also convert byte swapping macros to inline functions for more type
safety.
References #1460
Except for the Windows, Emscripten, and Haiku backends we use C-style
comments markers and not double-slash. Get rid of a few inconsistent
// instances.
Note the doxygen code examples have // comments because they are inside
proper /* */ comments.
Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
Ideally it should be a warning only for composite devices but it is
difficult to discern that case. The message is too invasive and
confusing for the non-composite case, so make it debug instead.
Follow-up of commit f9ae36bCloses#1394
Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
- Fix typos.
- Use SuperSpeedPlus naming consistently.
- Remove C++ style comment in favor of C style.
Fixup of commit f00f06e9
References #1499Closes#1502
The second argument to open() is an int carrying flags (including
"access modes"). A third, optional argument has type mode_t, carrying
"file mode bits" for file permissions.
Also rename the variable to access_mode to make it more clear.
The type mismatch was caught by building with -Wconversion.
References #1497
Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
Previously when getting the device list, a malformed device GUID would
be explicitly ignored and skipped, allowing the operation to complete. A
recent change to winusb_get_device_list() in commit fdab67b accidentally
changed this behaviour, so this scenario instead caused an early exit
with error code LIBUSB_ERROR_NO_MEM.
Closes#1475
No real change.
- rearrange elements to be initialized in the same order as they appear
in the struct declaration
- explicitly set values to NULL so that global searches for things like
`wrap_sys_device` easily reveal that the function is NULL on Darwin
Closes#1439
This function has different implementations on every OS, but for some,
like macOS, it was truncating from 64 to 32 bit by casting to int. So
increase its size from int to long.
(The function is currently only used for debug output.)
Closes#1423
The clang static analyzer doesn't see that the pointer will always be
non-NULL if the return value is success. Just assert this fact so that
it can see this, and then it won't warn:
Access to field 'can_enumerate' results in a dereference of a null
pointer (loaded from variable 'cached_device')
References #1414