Commit Graph

1951 Commits

Author SHA1 Message Date
Oleksand Radovenchyk
083f0cbfe4 chore: Remove broken or stale build badges from README
Closes #1640
2025-05-16 00:35:38 +02:00
Tormod Volden
94e0d8c2aa Bump LIBUSB_API_VERSION
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>
2025-05-16 00:33:40 +02:00
Zeng Guang
9cef804b24 darwin: Fix regression causing re-enumeration timeout
Fix time calculation for negative nanosecond deltas to resolve
re-enumerate timeout. Fixup of commit a07ecfe02.

Fixes #1637
References #1610
2025-05-03 12:08:40 +02:00
Tormod Volden
c6c45b8e8c docs: Refer to Topics instead of Modules
doxygen generates a "Topics" instead of "Modules" button these days.

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2025-05-03 11:31:07 +02:00
Tormod Volden
a61afe5f75 libusb 1.0.28
Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2025-03-18 23:07:26 +01:00
Tormod Volden
20f6f37164 configure.ac: Bump libtool library version
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>
2025-03-18 23:04:49 +01:00
Tormod Volden
1496324291 core: Avoid infinite recursion on invalid LIBUSB_DEBUG value
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>
2025-03-18 09:54:55 +01:00
Tormod Volden
12bd342473 libusb 1.0.28-rc1
Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2025-03-06 21:47:29 +01:00
Jesse Taube
0e0a072220 CI: Remove build job for MSYS clang32
Upstream dropped support for clang32, and our CI build already
fails on it, so remove the build job.

https://github.com/msys2/setup-msys2/pull/458

Closes #1607

Signed-off-by: Jesse Taube <Mr.Bossman075@gmail.com>
2025-03-02 20:43:44 +01:00
Radu Vele
de38189e80 Enable linux netlink event monitoring for Android OS platform services
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>
2024-11-13 21:16:58 -07:00
Fabien Sanglard
7bc88c0f08 macos: Fix Zero-Length Packet for multiple packets per frame
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 #1581
Closes #1582
2024-11-13 19:33:24 +01:00
Tormod Volden
7adb2913ce docs: Fix broken doxygen references
Fixup of commit d7b796f1

References #1549

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2024-11-13 11:07:55 +01:00
Tormod Volden
0b4eda697f docs: Hide internal descriptor.c structure from doxygen
Follow-up of commit f00f06e9

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2024-11-13 10:57:56 +01:00
Fabien Sanglard
28a6afb690 docs: Document internal_ssplus_capability_descriptor
Also include SSP documentation fixups of commit f00f06e9
that had introduced Doxygen errors.

Closes #1545
2024-11-13 10:57:49 +01:00
Matthijs Lavrijsen
467b6a8896 winusb: Fix winusb_get_device_list() failing to find port numbers
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
2024-07-31 00:05:01 +02:00
Sean McBride
8776b8021a descriptor: Fix clang -Wimplicit-int-conversion warnings
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
2024-07-30 00:57:06 +02:00
Sean McBride
a3199696e2 xcode: Adjust file indentation settings
Change tab vs space and 2 vs 8 intent in Xcode project to match the
emacs metadata at the top of the files.

Closes #1543
2024-07-30 00:54:21 +02:00
Sean McBride
30ec25f738 examples/ezusb: Fix error checking regression in recent commit
Commit 00454ab0 accidently botched error checking when replacing
rewind() with fseek().

Thanks to GitHub user "anotheruserofgithub" for noticing.

Closes #1539
2024-07-29 19:55:01 +02:00
Tormod Volden
4528752cbe windows: Base HID device descriptor on cached values
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 #1360
Closes #1378

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2024-07-28 14:25:22 +02:00
Tormod Volden
d04fc0e60b openbsd: Use default clause in _errno_to_libusb()
Same as for NetBSD.

Closes #1295

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2024-07-28 14:22:20 +02:00
Tormod Volden
bc12cda784 netbsd: Debug print all errors
Same as for OpenBSD.

References #1295

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2024-07-28 14:21:32 +02:00
Sean McBride
9d595d4e4a Replace atoi() with strtol() which allows error checking
atoi() gives no opportunity for error checking, strtol() does. Improved
error checking.

Closes #1422
2024-07-28 14:12:07 +02:00
Tormod Volden
bd0fcdb4c2 Add KEYS file for release files verification
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>
2024-07-28 14:04:37 +02:00
Yiwei Lin
c3873d5c2c xusb: Define proper exit status
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>
2024-07-28 13:52:17 +02:00
Sean McBride
e8d76b1a12 clang-tidy: Stop suppressing readability-misleading-indentation warnings
All such warnings are already fixed in master.

Closes #1479
2024-07-28 13:27:06 +02:00
Sean McBride
197e3052cd libusb.h: Match parameter names in declaration and definition
Took the name from the .c file.

Fixes all clang-tidy readability-inconsistent-declaration-parameter-name
warnings

References #1479
2024-07-28 13:27:06 +02:00
Sean McBride
55f8c95551 descriptor: Fix addition overflow by correcting casts
The addition could overflow, the upcast needs to be performed before,
not after.

Fixes all clang-tidy bugprone-misplaced-widening-cast warnings

References #1479
2024-07-28 13:27:06 +02:00
Sean McBride
e3ccc46b6e descriptor: Eliminate all duplicate branch bodies, as they are bug-prone
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
2024-07-28 13:27:06 +02:00
Sean McBride
9cf84577ce Avoid assignments within if statements
Fixes all clang-tidy bugprone-assignment-in-if-condition warnings

References #1479
2024-07-28 13:27:05 +02:00
Sean McBride
a18a964aba darwin: Fix multiplication overflow by better matching type sizes
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
2024-07-28 13:27:05 +02:00
Sean McBride
6883f84f93 darwin: Explicitly compare string compare function results to -1, 0, or 1
Fixes all clang-tidy bugprone-suspicious-string-compare warnings

References #1479
2024-07-28 13:27:05 +02:00
Sean McBride
418aadc0f9 darwin: Always use uppercase literal suffixes for improved readability
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
2024-07-28 13:27:05 +02:00
Sean McBride
3616e751b1 examples/xusb: Match size of loop index to what is iterated
Fixes all clang-tidy bugprone-too-small-loop-variable warnings

References #1479
2024-07-28 13:27:05 +02:00
Sean McBride
a7e471dd48 examples/xusb: Make some parameters const where possible
Fixes all clang-tidy readability-non-const-parameter warnings

References #1479
2024-07-28 13:27:05 +02:00
Sean McBride
85055a412b examples/xusb: Make all macro replacement lists parenthesized
To protect any lower-precedence operators from the surrounding
expression.

Fixes all clang-tidy bugprone-macro-parentheses warnings

References #1479
2024-07-28 13:27:05 +02:00
Sean McBride
9ffdb7fe6e examples/fxload: Eliminate all reserved C identifiers (leading underscores)
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
2024-07-28 13:27:05 +02:00
Sean McBride
00454ab087 examples/ezusb: Replace rewind with fseek, to check for errors
Replace rewind, which gives no error result, with fseek, which does.

Fixes all clang-tidy bugprone-unsafe-functions warnings

References #1479
2024-07-28 13:27:05 +02:00
Jon Beniston
e678b3fad5 Emscripten: Avoid uncaught TypeError on browsers without USB support
Check if navigator.usb exists before trying to call one of its methods,
to avoid unhandled exception, e.g. on current Firefox.

Closes #1500
2024-05-28 22:35:13 +02:00
Sean McBride
916c740076 descriptor: Avoid buffer over-increment in parse_iad_array function
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
2024-05-28 22:07:45 +02:00
Sean McBride
678c81271b descriptor: Small clarifications with no behaviour change
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.
2024-05-28 22:07:45 +02:00
Sean McBride
016a0de33a descriptor: Fix potential offsetting of pointer by too much
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.
2024-05-28 22:07:45 +02:00
Sean McBride
5144b1c7b3 descriptor: Restore implicitly casted-away const 2024-05-28 22:07:45 +02:00
Sean McBride
d795c0b821 descriptor: Defer potentially truncating cast to last minute 2024-05-28 22:07:45 +02:00
Sean McBride
2c32efa20e descriptor: Replace parse_descriptor() function
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
2024-05-28 22:07:29 +02:00
Tormod Volden
2a138c6f12 Consistent use of C-style comment markers
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>
2024-05-26 23:10:24 +02:00
Tormod Volden
de1398db35 windows: Downgrade get_guid DeviceInterfaceGUID message to debug level
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 f9ae36b

Closes #1394

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2024-05-26 22:31:09 +02:00
Fabien Sanglard
48c6bdea80 Cosmetic cleanup of SuperSpeedPlus comments
- Fix typos.
- Use SuperSpeedPlus naming consistently.
- Remove C++ style comment in favor of C style.

Fixup of commit f00f06e9

References #1499
Closes #1502
2024-05-26 22:25:26 +02:00
Tormod Volden
34d2ca5c63 xusb: Only retrieve BOS descriptor for bcdUSB 0x0201 or higher
The "Binary device Object Store" (BOS) descriptor was introduced with
bcdUSB revision 0x0201.

References #1492

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2024-05-26 17:19:37 +02:00
Tormod Volden
42e8a9ff2c linux: ioctl() request number is unsigned long
The type mismatch was caught by building with -Wconversion.

References #1497

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2024-05-26 16:40:59 +02:00
Tormod Volden
8b507434fa linux: Fix type of open() flags argument
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>
2024-05-26 16:40:29 +02:00