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
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>
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
- Fix typos.
- Use SuperSpeedPlus naming consistently.
- Remove C++ style comment in favor of C style.
Fixup of commit f00f06e9
References #1499Closes#1502
- 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>
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
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
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#1416Closes#1436
Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
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>
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#990Closes#1236
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>
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#490Closes#1208
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>
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>
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
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>