215 Commits

Author SHA1 Message Date
squidbus
c4d237a580 More ABI fixes 2025-09-07 13:56:12 -07:00
squidbus
d3e6a718b1 Apply SysV ABI attribute more broadly. 2025-09-07 13:39:44 -07:00
Sean McBride
3dbfa16f0c core: Remove some unnecessary consts
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
2025-06-09 23:18:54 +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
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
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
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
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
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
Fabien Sanglard
b00332d34e SuperSpeedPlus: Fix typo mantisa -> mantissa in struct field
Fixup of commit f00f06e9

Closes #1499
2024-05-26 10:44:02 +02:00
Harry Mallon
5b17c383f8 Add API support for LIBUSB_SPEED_SUPER_PLUS_X2 20Gbps USB 3.2 gen 2x2
Implement detection on darwin and linux_usbfs, and report it in xusb.

Closes #1477
2024-05-07 19:44:28 +02:00
Fabien Sanglard
f00f06e9eb Add support for SuperSpeed+ Capability Descriptors
See specs in USB 3.1 specs in section:

9.6.2.5 SuperSpeedPlus USB Device Capability

Closes #1428
Fixes #1429
2024-05-07 19:32:50 +02:00
Tormod Volden
6558778833 docs: Add more references in libusb_option section
Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2024-01-27 10:52:30 +01:00
Sean McBride
0929a2b1d1 docs: Prefer use of libusb_init_context() over old libusb_init()
- Replace some uses of the soft-deprecated libusb_init() and
  libusb_set_debug() with their updates.

- Updated various comments to favour use of the new functions.

- Notably remove \deprecated doxygen statement, since it causes
  -Wdocumentation compiler warnings.

- Notably update the xusb example to pass debug options to
  libusb_init_context() instead of setting environment variable.

- Also improve comments related to LIBUSB_API_VERSION and
  LIBUSBX_API_VERSION.

Closes #1408

[Tormod: Fix Doxygen formatting and references]
Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2024-01-20 13:27:06 +01:00
Sean McBride
66e63d68eb Correct some spelling and add codespell config file
In one case, renamed a variable from `larg` which codespell thought was
a typo for `large`.

Closes #1411
2024-01-20 12:09:35 +01:00
Sean McBride
5e4b389f74 Replace all http://libusb.info/ with https
The libusb.info website, like most sites these days, auto-redirects to
the https version anyway.

Also replaced a couple of other http links to https, after verifying
that they autoredirect to https.

Note this changes the "describe" field in the version info returned by
libusb_get_version(). This field is only there for ABI compatibility and
contains the website URL.

Closes #1407
2024-01-19 21:53:20 +01:00
Sean McBride
7b53ee1d73 libusb.h: Rename ZERO_SIZED_ARRAY to LIBUSB_FLEXIBLE_ARRAY
This reflects the C99 terminology, instead of the old hack of using a
zero sized array.

Also adds the LIBUSB prefix to avoid namespace colisions, as this is
present in a public header.

References #1409
2024-01-19 19:51:45 +01:00
Tormod Volden
a8fba21b7f Change libusb_init_option to fix libusb_set_option() on big-endian
libusb_set_option() is a variadic function, so the type of the arguments
is not clearly defined. When called with LIBUSB_OPTION_LOG_LEVEL, the
argument is read with va_arg() as an int, which matches the type used
when passing constants, and also most of the internal calls and the
calls in the examples.

However the internal call site in libusb_init_context() passes the ival
element of the libusb_init_option struct directly, which is of type
int64_t. This breaks on big-endian architectures like PowerPC, as
detected by tests/set_option.

Therefore change the libusb_init_option struct to use int here as well.

Thanks to Aurelien Jarno for reporting and initial patch.

Closes #1416
Closes #1436

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2024-01-19 19:39:26 +01:00
Martin Ling
dac541dc75 Revert "windows: Add option for WinUSB RAW_IO endpoint policy"
This reverts commit 9e4bb9cbe5.

References: #1297
2023-12-09 09:06:32 +01:00
Nathan Hjelm
84ac0b0f60 Add support for setting the log callback with libusb_set_option/libusb_init_context
This commit effectively deprecates libusb_set_log_cb by adding support for
setting the callback in either libusb_set_option or libusb_init_context. Since
the libusb_set_log_cb is already in use we can not easily deprecate it without
first incrementing the major version. We may do that in the future.

Closes #1265

Signed-off-by: Nathan Hjelm <hjelmn@google.com>
2023-04-12 13:02:35 -06:00
Xiaofan Chen
fcf0c710ef Do not deprecate libusb_set_debug and libusb_init
These functions are used in a lot of existing downstream code
and the deprecation makes -Werror builds fail.

It seems reasonable to keep these functions supported at least until a
major API overhaul.

Closes #990
Closes #1236
2023-03-12 14:52:23 +01:00
Tormod Volden
54350bd83f Bump LIBUSB_API_VERSION to 0x0100010A
Several API changes targeted for 1.0.27

New API functions:
- libusb_init_context
- libusb_get_max_alt_packet_size
- libusb_get_interface_association_descriptors
- libusb_get_active_interface_association_descriptors
- libusb_free_interface_association_descriptors
- libusb_get_platform_descriptor
- libusb_free_platform_descriptor
(and their associated structures)

New option LIBUSB_OPTION_WINUSB_RAW_IO

NetBSD bus/address changes (not strictly part of API)

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2023-01-26 12:51:50 +01:00
Orhan aib Kavrakoglu
9b42fdd787 core: Add libusb_get_max_alt_packet_size()
Closes #1167
2023-01-21 11:26:11 +01:00
Martin Ling
9e4bb9cbe5 windows: Add option for WinUSB RAW_IO endpoint policy
Add support for enabling or disabling the WinUSB RAW_IO pipe policy for
a given endpoint, which is documented here:

https://learn.microsoft.com/en-us/windows-hardware/drivers/usbcon/winusb-functions-for-pipe-policy-modification

This is necessary to increase performance. Without this option the
WinUSB backend will only queue one inbound operation at a time, even if
the libusb async API is used to submit multiple transfers.

For real-time sampling devices with high sample rates and small buffers,
the use of RAW_IO combined with queued async transfers is essential to
maintaining the necessary throughput and avoiding lost samples or buffer
overruns.

Examples of devices affected include Cypress FX2 based logic analyzers
accessed using Sigrok, and the HackRF software defined radio.

The new option must be set by calling libusb_set_option with the arguments:

libusb_set_option(ctx, LIBUSB_OPTION_WINUSB_RAW_IO, dev_handle,
                  endpoint_address, enable, max_transfer_size_ptr)

where the types of the variadic arguments are:

libusb_device_handle *dev_handle;
unsigned int endpoint_address;
unsigned int enable;
unsigned int *max_transfer_size_ptr;

The dev_handle and endpoint_address parameters must identify a valid IN
endpoint on an open device. If enable is nonzero, RAW_IO is enabled,
otherwise it is disabled. Unless max_transfer_size_ptr is NULL, then on
a successful call to enable RAW_IO, the pointer destination will be
written with the MAXIMUM_TRANSFER_SIZE value for the endpoint.

Whilst RAW_IO is enabled for an endpoint, all transfers on that endpoint
must meet the following two requirements:

- The buffer length must be a multiple of the maximum endpoint packet size.
- The length must be less than or equal to the MAXIMUM_TRANSFER_SIZE value.

This option should not be changed when any transfer is in progress on
the specified endpoint.

This option only affects the WinUSB backend. On other backends it is
ignored and returns LIBUSB_ERROR_NOT_SUPPORTED, without modifying the
value pointed to by max_transfer_size_ptr.

A great deal of credit is due to Petteri Aimonen and Patrick Stewart for
previous work, and to everyone else who participated in discussions.

Fixes #490
Closes #1208
2023-01-20 11:05:01 +01:00
Nathan Hjelm
6622f386f5 core: Add libusb_init_context() setting options at context creation
The new initialization function addresses some shortcomings of the
libusb_set_option() interface. Namely, it allows setting the
no-enumeration option (and others) on only the contexts where it is
requested. The old initialization function (libusb_init()) is deprecated
and will be removed in a future release. For now it translates to a call
to libusb_init_context() with no options specified.

Closes #1026

Signed-off-by: Nathan Hjelm <hjelmn@google.com>
[Tormod: Doxygen description of libusb_init_option structure]
Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2023-01-20 10:16:43 +01:00
Dominik Boehi
82d912307f descriptor: Add support for BOS platform descriptor parsing
Also add BOS platform descriptor dump to xusb example.

Closes #1133

[Tormod: Fixed copy-pasto in Doxygen comment]
Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2023-01-19 15:04:48 +01:00
Ryan Metcalfe
809a6df614 descriptor: Introduce interface association descriptors (IAD)
Types:
  struct libusb_interface_association_descriptor
  struct libusb_interface_association_descriptor_array

Accessor / cleanup functions:
  libusb_get_interface_association_descriptors
  libusb_get_active_interface_association_descriptors
  libusb_free_interface_association_descriptors

Signed-off-by: Ryan Metcalfe <ryan.metcalfe@novanta.com>
[Tormod: Fixed Doxygen comment]
Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2023-01-19 15:01:22 +01:00
Rosen Penev
5c27abd59e windows: Mark libusb_set_option as WINAPIV
WINAPI evaluates to __stdcall, which does not work with variadic
functions. MSVC and MinGW implicitly demote this to __cdecl (clang does
too and also warns about it). Instead of having this implicit, make it
explicit.

Closes #1160

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2022-09-04 21:10:40 +02:00
Shawn Hoffman
0ff79bc2ad msvc: Implement LIBUSB_DEPRECATED_FOR
Closes #1113
2022-06-26 17:09:14 +02:00
Ludovic Rousseau
69a0145d6f Doxygen: Add references to LIBUSB_ERROR codes
Signed-off-by: Ludovic Rousseau <ludovic.rousseau@free.fr>
2022-06-26 17:09:14 +02:00
Shawn Hoffman
32f3c6db95 windows: Silence zero-sized array warning in libusb.h for msvc
Silence "nonstandard extension used : zero-sized array in struct/union"
(C4200) warning caused by use of ZERO_SIZED_ARRAY in structures defined
in libusb.h when compiling with msvc.

A libusb user including the header from a c++ file is more likely to be
annoyed by the warning because it is activated at level 2 as opposed to
being included from a C file, where it's not activated until level 4.
(on msvc, level 4 is the last step before -Wall).

This causes problems when you also enable -Werror for your own source,
since the libusb header just gets merged into the compilation unit.

9>hotplugtest.c
9>C:\src\libusb\libusb\libusb.h(786,11): error C2220: the following warning is treated as an error
9>C:\src\libusb\libusb\libusb.h(786,11): error C2220: 	uint8_t  dev_capability_data[ZERO_SIZED_ARRAY];
9>C:\src\libusb\libusb\libusb.h(786,11): error C2220: 	         ^
9>C:\src\libusb\libusb\libusb.h(786,11): warning C4200: nonstandard extension used: zero-sized array in struct/union
9>C:\src\libusb\libusb\libusb.h(786,11): warning C4200: 	uint8_t  dev_capability_data[ZERO_SIZED_ARRAY];
9>C:\src\libusb\libusb\libusb.h(786,11): warning C4200: 	         ^
9>C:\src\libusb\libusb\libusb.h(811,47): warning C4200: nonstandard extension used: zero-sized array in struct/union
5>C:\src\libusb\libusb\libusb.h(811,47): warning C4200: 	struct libusb_bos_dev_capability_descriptor *dev_capability[ZERO_SIZED_ARRAY];
5>C:\src\libusb\libusb\libusb.h(811,47): warning C4200: 	                                             ^
9>C:\src\libusb\libusb\libusb.h(1284,38): warning C4200: nonstandard extension used: zero-sized array in struct/union
9>C:\src\libusb\libusb\libusb.h(1284,38): warning C4200: 	struct libusb_iso_packet_descriptor iso_packet_desc[ZERO_SIZED_ARRAY];
9>C:\src\libusb\libusb\libusb.h(1284,38): warning C4200: 	                                    ^
9>Done building project "hotplugtest.vcxproj" -- FAILED.

Closes #1112
2022-04-06 21:42:07 +02:00
Tormod Volden
1170db79bd Bump LIBUSB_API_VERSION
LIBUSB_OPTION_NO_DEVICE_DISCOVERY is new.

Closes #1004

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
Signed-off-by: Nathan Hjelm <hjelmn@me.com>
2021-11-27 10:05:00 -07:00
Tormod Volden
33d9949921 Keep LIBUSB_OPTION_WEAK_AUTHORITY as a macro with same value
If the value is always the same we retain binary compatibility.

References #935

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
Signed-off-by: Nathan Hjelm <hjelmn@me.com>
2021-11-27 10:04:05 -07:00
Tormod Volden
1d1411b606 doc: Explain default options in libusb_set_option documentation
References #942

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
2021-11-01 23:22:56 +01:00
Sean McBride
35b23a047e doc: Improve comments related to device discovery and hotplug
Closes #1013
2021-10-30 15:23:15 +02:00
Paul Cercueil
619c28f37e Windows: Fix ssize_t unconditionally defined
The standard procedure to define ssize_t on Windows is to wrap it around
a check for the _SSIZE_T_DEFINED macro.

If not done, it makes it impossible to use the libusb.h header along
with other headers (from other libraries) that also attempt to define
ssize_t.

Closes #1007

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
2021-10-30 15:21:56 +02:00
Tormod Volden
5c89594f64 New NO_DEVICE_DISCOVERY option to replace WEAK_AUTHORITY option
The option disables device enumeration (and hotplug, which depends on
enumeration). Since this has a much broader usage scope than "weak
authority", give the option a name reflecting what it does.

For now, keep the old option name working as an alias.

Closes #935

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
Signed-off-by: Nathan Hjelm <hjelmn@google.com>
2021-07-08 21:53:46 -06:00
Tormod Volden
5360a17ce7 Do not restrict "weak authority" option to Android
libusb_wrap_sys_device() is an often needed feature on Android, but can
also be very convenient on other Linux platforms.

In many cases the initial device scanning is not needed and
LIBUSB_OPTION_WEAK_AUTHORITY thus provides a performance enhancement.

Closes #925

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
Signed-off-by: Nathan Hjelm <hjelmn@google.com>
2021-06-11 09:43:04 -06:00
Nathan Hjelm
a524555c98 core: allow libusb_set_option on the default context before libusb_init
This commit updates libusb_set_option to save the options if setting them on the default
context. This ensures the options 1) can be set before libusb_init(NULL, ...), and 2)
are honored even if the default context is destroyed and re-created.

Signed-off-by: Nathan Hjelm <hjelmn@google.com>
2021-06-07 21:28:44 -06:00
Ihor Dutchak
e4e9c6de5e doc: correction of LIBUSB_OPTION_WEAK_AUTHORITY availability
Even though its implementation is in linux/usbfs,
in fact it is under `ifdef` and only used by Android builds.

Closes #916

Signed-off-by: Nathan Hjelm <hjelmn@google.com>
2021-06-06 12:25:02 -06:00
Ozkan Sezer
a2b81aeff1 make libusb.h usable with Watcom
Closes #904

Signed-off-by: Nathan Hjelm <hjelmn@google.com>
2021-05-16 15:21:46 -06:00
Victor Toso
28a11d1163 doc: Add since version tag to libusb_set_log_cb()
The commit f74c7f5 "core: new API libusb_set_log_cb() to redirect
global and per context log messages to the provided log handling
function" in 2018-12-05 is present from 1.0.23 onwards.

This commit just adds this to the docs.

Closes #872

Signed-off-by: Victor Toso <victortoso@redhat.com>
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2021-02-15 09:55:12 -08:00
Uwe Bonnes
84e860cfb9 libusb.h: Base Class EFh (Miscellaneous) was missing in class definition.
Closes #802

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2020-11-07 20:18:41 -08:00
chris
89b810ec9b Android: Add option LIBUSB_OPTION_WEAK_AUTHORITY to support used in apk
Closes #760

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2020-09-12 17:19:57 -07:00
Chris Dickens
0abebc57a5 Fix typos detected by codespell and manual inspection
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2020-08-18 15:49:22 -07:00
Chris Dickens
666647fa31 Documentation: Improve details of libusb_transfer's 'user_data' field
Closes #351

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2020-08-18 13:16:52 -07:00
Chris Dickens
a157b55656 core: Fix some minor inconsistencies in API and coding
All of the API functions should take the typedef'ed versions of the
opaque libusb structures, but some recent additions to the API did not
follow this convention. Fix this by making the changes to the
declarations and definitions of the functions.

Make the placement of the asterisk in pointer variable declarations
consistent (always with the variable name, not the type).

Remove some unnecessary casts and initializations relating to
dynamically allocated memory. While at it, make casts within the core
library consistent in style with no space after the closing parenthesis
of the cast. Most of the core already used this style.

When using the 'sizeof' operator, dereference the pointer instead of
using the type.  Most of the core was already doing this, so fix up the
few places that weren't.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2020-04-27 18:43:42 -07:00
Chris Dickens
da87201f7a hotplug: Fix definition of libusb_hotplug_register_callback()
The signature of the libusb_hotplug_register_callback() is slightly
incorrect in two regards:

  1) The 'events' parameter is meant to represent a bitwise OR of
     libusb_hotplug_event values. By OR'ing multiple values together,
     the result is not something that is actually a libusb_hotplug_event
     enumeration.

  2) The 'flags' parameter is meant to represent a bitwise OR of
     libusb_hotplug_flag values. The same considerations as above apply,
     though this has not practically been the case as there is currently
     only one flag value defined. However, a special value was already
     defined to represent the absence of any flags, which hinted at the
     problem with how it is currently defined.

Address these two issues by changing the types of the 'events' and
'flags' parameter to plain integers. As enumerations should already be
promoted to integers, this change should not cause any ABI concerns.

Closes #714

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2020-04-23 11:10:31 -07:00
Chris Dickens
e83f39ba6e libusb.h: Ensure that struct libusb_control_transfer is not padded
There is nothing explicitly preventing the compiler from adding any sort
of padding to the libusb_control_transfer structure. It does not seem
that any sane compiler would do so, but there is library functionality
that depends on this not happening. Address this by explicitly
instructing the compiler to pack the structure.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2020-04-16 15:57:15 -07:00
Chris Dickens
61c457a699 libusb.h: Simplify condition governing the inclusion of sys/time.h
The expression for the condition grows each time a new backend is added,
but it can be simplified if changed to key off of the _MSC_VER macro.
The sys/time.h header is ubiquitous across all platforms and build
environments except Visual Studio, so change the condition to be based
on this. This fixes builds on BSD where the condition was not evaluating
to true.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2020-04-16 14:31:18 -07:00