Hide the mutex lock details inside a wrapper call, like done for the
device stack API. This is not used for the per-device lock of the host
stack which use a different mutex lock.
Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
In the while loop parsing descriptors, check that the descriptor is past
the end just before dereferencing it to check if it is seemingly valid.
Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
Make the struct name match the device naming for ease of use, although
slightly longer name. Propagate the change to the subsystem, includes,
tests and samples.
Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
Rate limit the get_recv_buf() callback from the application to
reduce system trash when buffer pressure gets high.
Signed-off-by: Victor Brzeski <vbrzeski@gmail.com>
The interface descriptor and its associated string descriptor are shared
between different speed configurations. Do not try to add a string
descriptor if it has already been added and the index is not zero.
Similar to commit ec851ba7c7
("usb: device_next: avoid false error logging in CDC ACM").
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Disable the data interface when the device is disconnected or when the
CDC-NCM and CDC-ECM instances are disabled for any reason.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Enable double buffering on isochronous feedback endpoint to avoid
sending ZLP instead of feedback information.
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
Enable double buffering on data OUT endpoints to allow USB stack to
enqueue next transfer as soon as possible. This is especially useful
when operating at High-Speed where there is significantly less time
between subsequent SOF packets.
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
Change the macros to have only one plus operator per term. This is
purely stylistic change, no functional changes.
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
This commit resolves a bug where the USB Endpoint
provided by the HID driver was incorrect when in
High Speed mode.
Signed-off-by: Victor Brzeski <vbrzeski@gmail.com>
Due to the alignment and granularity requirements of memory allocation,
setup->wLength is shorter than the allocated buffer size.
This lead to responses larger than what the host requested, which it
rejected. Fix it by using the minimum between the allocated size, the
struct size, and the wLength requested.
Signed-off-by: Josuah Demangeon <me@josuah.net>
Some OSes like MacOS use shorter UVC 1.1 probe/commit messages even when
UVC 1.5 is supported, without bUsage, bBitDepthLuma, bmSettings,
bMaxNumberOfRefFramesPlus1, bmRateControlModes bmLayoutPerStream.
Accept messages of arbitrary size to safely be processed, ignoring all
missing fields, improving standard compliance.
Signed-off-by: Josuah Demangeon <me@josuah.net>
This commit adds a device-tree prop for the audio streaming
terminals to specify the bInterval values for the Isochronous
endpoints.
Signed-off-by: Victor Brzeski <vbrzeski@gmail.com>
Introduce a new USB Video Class (UVC) implementation from scratch.
It exposes a native Zephyr Video driver interface, allowing to call the
video_enqueue()/video_dequeue() interface. It will query the attached
video device to learn about the video capabilities, and use this to
configure the USB descriptors. At runtime, this UVC implementation will
send this device all the control requests, which it will send to the
attached video device. The application can poll the format currently
selected by the host, but will not be alerted when the host configures
a new format, as there is no video.h API for it yet.
Signed-off-by: Josuah Demangeon <me@josuah.net>
UDC drivers use udc_buf_get_all() when dequeueing endpoint. On drivers
that require double buffering for isochronous IN endpoint, the dequeue
on interface disable will result in class request API called on net_buf
with frags set. Call release callback on the buffer pointed in frags
because it was passed in using usbd_uac2_send().
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
Allow optimization if high speed is not supported. Unify strings for
error logging. Allow the application to enable/disable the USB device.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
In both implementation, when comparing received data length take into
account that the buffer obtained from bt_buf_get_tx() stores the type at
the top. The buffer types are H:4 and in the TX path we need to check for
BT_HCI_H4_* types not BT_BUF_*.
In the legacy implementation, the hci_acl_pkt_len() function obtains the
length from the USB transaction buffer, which does not contain a buffer
type at the top.
In the new implementation, partially revert the changes and restore
hci_pkt_get_len(), this will be required for any further changes anyway.
Fixes commit f85d63a6cc ("Bluetooth: Remove USB H4 mode support").
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Add Kconfig option to limit the length requested from HWINFO to a
meaningful number of digits. Also, check the length returned by the
HWINFO driver and rename the variables to a more suitable name.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
See Discussion https://github.com/zephyrproject-rtos/zephyr/discussions/83659
for information about the purpose of this change.
Modifies run actions of hierarchical state machines
to return a value indicating if the event was handled
by the run action or should be propagated up to the
parent run action. Flat state machines are not affected,
and their run action returns void.
smf_set_handled() has been removed and replaced by
this return value. smf_set_state() will not propagate
events regardless of the return value as the transition
is considered to have occurred.
Documentation, tests, samples, has been updated.
USB-C and hawkBit use SMF and have been updated to use
the new return codes.
Signed-off-by: Glenn Andrews <glenn.andrews.42@gmail.com>
Apply clang-format to USB-C in preparation for code changes
No code is changed, only formatting.
Signed-off-by: Glenn Andrews <glenn.andrews.42@gmail.com>
With the commit fe3c001eeb ("usb: device_next: disable high-speed USB
device descriptor if not used") there is no high-speed device descriptor
by default.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
The intention was to use the "interface-name" string property in the
interface string descriptor, but using the label property is acceptable
again. Therefore, allow the use of the DT label property string in the
interface string descriptor.
Follow exactly the same approach as in the CDC ACM implementation
introduced in the commit b0791400f6
("usb: device_next: cdc_acm: allow setting the interface description").
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
The usbd_class_remove_all removes all registered classes from a
configuration. However, it previously left the uds_ctx back-pointer to the
usdb_context set, meaning that if the class is re-registered with the
usbd_register_class function, this fails with the error message "Class
registered to other context at different speed" due to uds_ctx being set to
another context.
This patch corrects the issue by clearing udc_ctx after usbd_class_shutdown
has been called.
Signed-off-by: Joel Holdsworth <jholdsworth@nvidia.com>
Disable the high-speed USB device descriptor if it is not in use.
Add checks to the code where the high-speed descriptor may be used.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
The required buffer is 128 bytes per instance on a full-speed device.
Use common (UDC) buffer, as this results in a smaller footprint.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Disable high-speed descriptors when they are not in use saves 64 bytes
in flash/RAM. It is unlikely that it will scale well enough to be used
in all class implementations or to support a different speed.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Add Kconfig option to use dedicated workqueue in CDC ACM but use the
system work queue in CDC ACM by default.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Allowing message callback execution from the USBD thread saves about 800
bytes. For small devices, the option can be useful to reduce flash/RAM
usage, those with enough resources should not bother about it.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
This non-standard feature never had any proper host side implementation
(e.g. it was never upstreamed to BlueZ), and since it comes with notable
maintenance overhead it's fair to just remove it.
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
This function is used for testing purposes only, there is no real use
for it in a user application. Remove in favor of implementation in new
device stack.
Also remove the part of the documentation that depends on loopback.
Documentation on how to implement your own USB device function using the
new USB device support will follow during the documentation rework.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
In my opinion, the user is supposed to configure the speed of the stack
and drivers ough to honor that choice. However current Zephyr USB
maintainer imposes that the dependency is the other way round, i.e.
that user first needs to disable High-Speed chirp at driver level and
only then can select Full-Speed only operation. Adhere to the
arbitrarily set up rule to allow this really necessary functionality to
enter Zephyr.
I consider this change to be harmful because it opens up a Kconfig trap
that allows configuring High-Speed capable stack with a device driver
limited to Full-Speed only operation.
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
Allow compiler optimizations to remove High-Speed handling code. Knowing
that maximum operating speed is Full-Speed allows to reduce bulk buffers
from 512 to 64 bytes. More RAM optimizations are possible but this
commit only gets the low hanging fruits.
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
Two main ideas behind setting maximum speed are:
* Allow code and RAM optimizations at compile time
* Allow High-Speed capable drivers to limit operating speed to user
choice.
This commit only introduces the necessary Kconfig options but does not
implement any code or RAM optimizations and does not modify any driver.
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>