Use a consistent nil_desc name for the descriptor that
terminates a class (function) descriptor.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Changed incrementing `for` loop counters to `size_t` from `int` to
eliminate warning, "warning: comparison of integer expressions of
different signedness: 'uint32_t' {aka 'unsigned int'} and 'int'
[-Wsign-compare]"
Signed-off-by: Zachary J. Fields <zachary_fields@yahoo.com>
Add USB device class API to notify class instances that an endpoint
has been halted or cleared due to a feature request.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Use proper format for size_t type eliminating warnings of type:
...
error: format '%u' expects argument of type 'unsigned int', but
argument 2 has type 'size_t' {aka 'long unsigned int'}
[-Werror=format=]
...
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Any Power Delivery message state that expects a reply must
start a sender response timer. This change addes a super
state that implements the Sender Response Timer
functionality, from which Power Deleiver messages states
can inherit from.
Signed-off-by: Sam Hurst <sbh1187@gmail.com>
Allows receive packets that are bigger than
CONFIG_RNDIS_BULK_EP_MPS.
Considering:
* MaxPacketsPerTransfer is 1
* MaxTransferSize is 1558
* PacketAlignmentFactor is 0 (20=1)
The rndis_bulk_out shall be able to receive transfer
up to 1558 bytes (inclusive).
Signed-off-by: Georgij Cernysiov <geo.cgv@gmail.com>
Add Bluetooth HCI USB transport layer implementation for the new
experimental USB device support based on the existing implementation
subsys/usb/device/class/bluetooth.c.
This implementation, unlike existing one, contains the interface
descriptors for isochronous endpoints. Since we do not support voice
channels, these are just there to avoid issues with Linux kernel btusb
driver when this implementation is part of a composite configuration.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
USB stack did leak memory on every SET ADDRESS request. UDC control
allocator could cope with up to 13 leaked allocations. Therefore,
issuing bus reset 13 times in a row (in addition to automatic reset
after connecting the USB cable) was enough to exhaust memory and
thus drive USB stack inoperable.
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
Cancelling transfers on suspend contradicts Universal Serial Bus
Specification Revision 2.0, 9.1.1.6 Suspended:
* When suspended, the USB device maintains any internal status,
including its address and configuration.
The internal status definitely includes any pending USB transfers.
If there is a class that wants to cancel transfer on suspend, then the
cancel should be initiated by the class, not the device stack itself.
Update hal_nordic to a version that does not abort all endpoints at
suspend. It seems that aborting endpoints on suspend in nrfx driver was
the actual reason why transfers were canceled on suspend.
Remove transfer retriggering on resume from CDC ACM and Bluetooth class
implementations because transfers are no longer cancelled on suspend.
Other classes do not have any suspend related workarounds implemented.
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
Use a flag to report a protocol error to the states. This keeps
state specific actions in the state. Currently, those state
specific actions are handled in the pe_report_error function.
Signed-off-by: Sam Hurst <sbh1187@gmail.com>
The name and wording used in template can be misleading.
Use more accurate word instance instead of device since
an implementation does not necessarily have to implement
a device (in the sense of Zephyr device model), and if it
does then devicetree should be used to describe number of
instances as in the case of CDC ACM implementation.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
USB_TRANS_NO_ZLP flag has no meaning for usb_transfer() in
host-to-device direction (USB_TRANS_READ).
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
From 8.3.3.4.2.1 PE_SNK_Send_Soft_Reset State, Error Recovery
should be performed if a Protocol Error happens during a Data
Role Swap.
Signed-off-by: Sam Hurst <sbh1187@gmail.com>
Build time check that the number of states initialized
in the state machine array matches the number of enums
used to index said array.
Signed-off-by: Sam Hurst <sbh1187@gmail.com>
Use k_work_delayable instead of k_timer in order to execute timeout in
USB workqueue context instead of ISR context. This fixes Will-Detach on
targets where usb_dc_detach() uses functions not allowed in ISR context,
e.g. nrfx usb_dc_detach() acquires mutex.
Fixes: c27d48c89a ("usb: dfu: Support DFU with WinUSB on Windows")
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
bcdHID is intended for the spec version of USB HID. It was pointing to the
v1.1 bcdUSB define which happens to be the same value for the v1.10 hid
spec version. This corrects it to use the v1.11 HID spec.
Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
Clean up occurrences of "#if IS_ENABLED(CONFIG_FOO)" an replace
with classical "#if defined(CONFIG_FOO)".
Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
This is initial support. Necessary to test the UHC driver API,
for the USB support test implementations, and upcoming USBIP support.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Allow enabling CDC ACM logging only if CDC ACM is not used as logging
backend. This prevents endless recursive logging loop, especially
visible when minimal footprint logging is enabled.
Fixes: #52981
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
Schedule CDC ACM tx work to happen 1 ms after first unprocessed data
write. This gives enough leeway for the task writing to the queue to
write more than 1 byte before USB workqueue preempts and schedules IN
transfer. Sending more than 1 byte at a time increases data throughput
because transaction overhead remains the same regardless of packet size.
Prior to this change, virtually every IN transaction carried only one
character when CDC ACM was used as a console.
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
Generates XML file containing VIF policies by reading the device tree
using EDT.pickle generated during build
This script writes a subset of general and sink-pdo VIF policies in
output file
This script gets invoked during build if enabled through kconfig
The generated XML containing USB-C VIF policies could be used by
USB PD/Type-C analysers/testers to understand USB-C properties and
perform tests accordingly
Signed-off-by: Madhurima Paruchuri <mparuchuri@google.com>
Add experimental CDC ACM implementation for new USB device stack.
It currently implements only UART IRQ API support and is WIP.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
The device supprt brings support for multiple stack instances,
multiple configuration, asynchronous transfer model, ability to
change most of the properties of a device at runtime and
the composition of configuration and classes at runtime.
The stack requires new UDC driver API and is not compatible
with old driver API (usb_dc_). The classes (functions) of old
(current) USB device stack cannot be used with new ones and must
be ported.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
When switching between alternate settings of an interface, it is
currently possible to call set_endpoint() multiple times on an endpoint
without first calling reset_endpoint(). For these situations, it is
beneficial to track endpoints for which set_endpoint() has previously
been called, and then reset them to properly terminate any transfers,
and to return the HAL to the correct state
Signed-off-by: Milind Paranjpe <mparanjpe@yahoo.com>
Remove Kconfig file samples/subsys/usb/usb_pid.Kconfig added in
the commit e5cbe6a9e7 ("usb: cdc: Add unique PIDs for each sample")
with the motivation to have a separate ID for each sample supposedly
to be recognizable by the host.
The new USB support does not use the options, VID/PID is set
directly in the application. As a note, it is not necessary to have
unique PID for each sample, especially for the well known USB classes.
Replace the individual Kconfig options in the documentation
by a table with the references to the samples and PIDs.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
The bwPollTimeout name is somewhat confusing as it refers to minimum
polling period. The bwPollTImeout is essentially a mechanism allowing
device to ratelimit DFU_GETSTATUS requests from host.
Setting bwPollTimeout to relatively high values effectively slows down
DFU download process. The slowdown is not observed if the time between
DFU_DNLOAD and DFU_GETSTATUS is enough for the device to process the
write. That is, the bwPollTimeout does not effect DFU download if the
first DFU_GETSTATUS after DFU_DNLOAD reports dfuDNLOAD-IDLE state.
Otherwise the host must wait bwPollTimeout ms before issuing next
DFU_GETSTATUS, which slows the communicaiton to not more than 1 download
block (CONFIG_USB_REQUEST_BUFFER_SIZE) every bwPollTimeout ms.
The bwPollTimeout ideally should report an estimate how much longer the
download operation will take. Zephyr does not have such estimate and
therefore defaults to using fixed value. Reduce default bwPollTimeout
from 256 to 8 ms to allow significantly faster DFU downloads on devices
where the time between DFU_DNLOAD and DFU_GETSTATUS is too short to
process download block at the expense of unnecessary bus traffic if
processing download block takes longer than 8 ms.
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
Pass result of usb_transfer() as return value to the user,
and allow user to react accordingly, e.g. release net_buf on error.
Signed-off-by: Chun-Chieh Li <ccli8@nuvoton.com>
When operating in PD2.x mode, PD_CTRL_REJECT should be
transmitted to the port partner when an unsupported message
is received.
Signed-off-by: Sam Hurst <sbh1187@gmail.com>
Align netusb driver with interface state handling update. Instead of
bringing the interface up/down from the driver level, use carrier on/off
notification to update the inteface state.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
DFU on Windows with WinUSB driver failed with "Lost device after RESET?"
error because WinUSB does not support host initiated resets. USB Device
Firmware Upgrade Specification Revision 1.1 attribute bitWillDetach can
be used to overcome WinUSB reset limitation. When bitWillDetach is set,
it is the device responsibility to detach and reattach itself to the bus
after receiving DFU_DETACH request.
Add and enable by default USB_DFU_WILL_DETACH configuration option,
because it is the only way to support WinUSB driver. WinUSB driver is
preferable because it can be automatically installed on Windows 8 and
later if USB device implements WCID descriptors.
Fixes: #49821
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
The commit switches flash area access from FLASH_AREA_ macros
to FIXED_PARTITION_ macros and to usage of DTS node labels,
to identify partitions, instead of label property.
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
As of today <zephyr/zephyr.h> is 100% equivalent to <zephyr/kernel.h>.
This patch proposes to then include <zephyr/kernel.h> instead of
<zephyr/zephyr.h> since it is more clear that you are including the
Kernel APIs and (probably) nothing else. <zephyr/zephyr.h> sounds like a
catch-all header that may be confusing. Most applications need to
include a bunch of other things to compile, e.g. driver headers or
subsystem headers like BT, logging, etc.
The idea of a catch-all header in Zephyr is probably not feasible
anyway. Reason is that Zephyr is not a library, like it could be for
example `libpython`. Zephyr provides many utilities nowadays: a kernel,
drivers, subsystems, etc and things will likely grow. A catch-all header
would be massive, difficult to keep up-to-date. It is also likely that
an application will only build a small subset. Note that subsystem-level
headers may use a catch-all approach to make things easier, though.
NOTE: This patch is **NOT** removing the header, just removing its usage
in-tree. I'd advocate for its deprecation (add a #warning on it), but I
understand many people will have concerns.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
SD stack requires a larger stack size than the default value for the
mass storage stack thread. Increase the default stack size to 768 when
the SD stack is enabled.
Fixes#49057
Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
We cannot implement configure API because there is
no notification of configuration changes provided
for the Abstract Control Model and the UART controller
is only emulated.
However, it allows us to use CDC ACM UART together with
subsystems like Modbus which require configure API for
real controllers.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Implement the uart_config_get() API by converting the existing
line coding structure to the struct uart_config format.
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
In the function tx_work_handler, a pointer to ring buffer data is given
to usb_transfer then the ring_buf_get_finish is called. So, the data is
mark as read (by ring_buf_get_finish) while the data are not yet
transferred to usb. If later a user send data, the pointer hold by usb
stack could be rewrite.
Signed-off-by: Julien D'Ascenzio <julien.dascenzio@paratronic.fr>
idle_rate is uint8_t, sof_cnt is uint32_t. The result is uint32_t, which
is the wrong type for 'abs'. Explicitly cast idle_rate to uint32_t,
subtract sof_cnt and then explicitly cast to int32_t and then use abs,
storing the result in another int32_t which matches the return type for
abs.
This quiets clang warnings about passing unsigned values to abs.
Signed-off-by: Keith Packard <keithp@keithp.com>
Devices using the MCUX FlexSPI flash driver erase their flash too
slowly, causing the usb stack to freeze, and USB DFU utilities to
report a timeout. Enable IMG_ERASE_PROGRESSIVELY for SOCs using the
MCUX FlexSPI driver to prevent this error.
Fixes#45359
Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
In order to bring consistency in-tree, migrate all subsystems code to
the new prefix <zephyr/...>. Note that the conversion has been scripted,
refer to zephyrproject-rtos#45388 for more details.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
Move include paths and add new target_include_directories to support
backwards compatibility:
* /include -> /include/zephyr
example: <irq.h> -> <zephyr/irq.h>
Issue #41543
Signed-off-by: Yuval Peress <peress@google.com>
Until now the whole USB device stack code is located
in the top subsys/usb directory. Move it to own directory
in preparation for upcoming extension and rework of USB support.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
This commit adds the USB_DFU_PERMANENT_DOWNLOAD and USB_DFU_REBOOT and
symbols.When the permanent download symbol is enabled, slot 1 will be
marked as confirmed. With the reboot symbol enabled, the devices
automatically reboots after the download is completed.
The functionality is split into two symbols to allow the automatic
reboot without confirming the image. This enables image confirmation via
another channel. For example via the shell’s Mcuboot commands.
This functionality allows downloading an image to the device without the
user having to interact with the device. It is useful in cases where
ease of use is more important then safety. For example when using USB
download for daily development. This is especially applicable for
devices with a closed case.
The changes were tested on an nrf52840dk. The following line can be used
to build the USB DFU example with the symbols enabled.
west build -b nrf52840dk_nrf52840 zephyr/samples/subsys/usb/dfu \
-d build-dfu -- -DCONFIG_BOOTLOADER_MCUBOOT=y \
-DOVERLAY_CONFIG=overlay-reboot-permanent.conf \
-DCONFIG_MCUBOOT_SIGNATURE_KEY_FILE\
=\"bootloader/mcuboot/root-rsa-2048.pem\"
Fixes#41921
Signed-off-by: Martijn Stommels <martijn@martijnpc.nl>
According to Kconfig guidelines, boolean prompts must not start with
"Enable...". The following command has been used to automate the changes
in this patch:
sed -i "s/bool \"[Ee]nables\? \(\w\)/bool \"\U\1/g" **/Kconfig*
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
Firmware uploading to the host may not always be desired,
disable it by default.
Enable it for existing USB DFU sample to keep
the usual behavior, add note about new option to README.rst.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Rename confusing UPLOAD_FLASH_AREA_ID to DOWNLOAD_FLASH_AREA_ID
as it is area where firmware image is downloaded.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
It is possible that the actual data stage length of
the control transfer is zero, in that case we do not
need an additional ZLP packet.
This fixes a problem with USB DFU, where after an upload
the device is no longer responsive if upload size is
multiple of control endpoint MPS.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Possibility to initialize USB device support is useful when
only CDC ACM class is enabled and CDC ACM UART is used as
backend for console, shell, or logging.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
This patch fixes an issue where mcux usb devices may stop
functioning after a reset event, because they do not
provide a USB_DC_DISCONNECTED event and USB_DC_RESET
events were not handled by the forward status callback.
Signed-off-by: Jacob Caughfield <mlsvrts@protonmail.com>
The new macro USBD_STRING_DESCR_USER_DEFINE works like
USBD_STRING_DESCR_DEFINE with the exception of being
ordered strictly after it. The new macro is needed to
ensures that user defined string descriptors can be added
without disturbing the order of string descriptors
defined by the usb subsystem.
Signed-off-by: Alexander Mihajlovic <a@abxy.se>
If HCI packet length is greater than endpoint MPS or currently
received data block (over USB), next block could be larger
than allocated net_buf buffer.
Check buffer tailroom before copying data using net_buf_add_mem().
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Function bt_buf_get_tx(), which is used to allocate buffer from
fixed-size pool, does not check size argument before copying
the data with the length size into fixed-size buffer, wich may
not be large enough.
Check immediately before copying if the tailroom of the buffer
is large enough.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Stop using redundant DEV_DATA/DEV_CFG macros and use dev->data and
dev->config instead.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
For functions returning nothing, there is no need to document
with @return, as Doxgen complains about "documented empty
return type of ...".
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
Rework suspended to be a shared atomic variable between
bluetooth_status_cb() and hci_tx_thread().
If the bus is suspended, initiate remote-wakeup and
wait until the bus is operational.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Replace deprecated macro USBD_CFG_DATA_DEFINE by
USBD_DEFINE_CFG_DATA which places usb_cfg_data structures
in specific iterable section.
Replace __usb_data_start, __usb_data_end usage patterns
size_t size = (__usb_data_end - __usb_data_start);
for (size_t i = 0; i < size; i++) {...}
by
STRUCT_SECTION_FOREACH(usb_cfg_data, ...) {...}
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Update the macro prototype to explicitly require the length of the
desired user data. Update all in-tree usage of this macro.
Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
In the current USB device support, the sizes of bulk endpoint
are mostly configure through Kconfig and do not care if a device
is high-speed capable. The information if a USB device controller
supports high-speed comes from devicetree. Add a Kconfig option to
map this information and configure bulk endpoint sizes
accordingly.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Use same init level and priority as serial drivers.
Align priority to the changes in
commit ad1450510a ("drivers: serial: Refactor drivers
to use shared init priority Kconfig")
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
The print specifier for `atomic_t` should be updated
to `%ld`, `%lu`, or `%lx` to account for the type
change of `atomic_t` to `long`.
Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
Add a macro to retrieve the iso data load length (the
length stored in the iso header) with a bit mask that
ensures that we only take the first 14 bits.
This is to remove any RFU bits that may have been set.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
There were a few cases where bt_hci_iso_data_hdr was used
instead of the proper struct bt_hci_iso_hdr.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Kconfig USB_DEVICE_REMOTE_WAKEUP option depends only on
USB device controller capability, but is not controlled
by the USB device controller drivers configuration.
Move USB_DEVICE_REMOTE_WAKEUP option to drivers and
make it promptless.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
USB_SCD_ATTRIBUTES is a configuration dependent macro
that does not map any part of the spec and does not
belong to usb_ch9 header.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Just always prove interface association descriptor for RNDIS
function instead of forcing it via Kconfig USB_COMPOSITE_DEVICE
option.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Set reasonable range for the request buffer in case RNDIS
function is used. Align net_buf size from rndis_cmd_pool to
request buffer size since request is copied there before
it is queued.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
When we build tests/kernel/common/kernel.common.misra on
bl654_usb we get the following error:
subsys/usb/usb_descriptor.c:313:2: error: ISO C90 forbids array
'hwid' whose size cannot be evaluated [-Werror=vla]
Fix by removing use of usblen variable in array.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
cdc_acm_irq_tx_ready was not checking if its interrupt was enabled.
This causes spurious tx irq handler calls.
Signed-off-by: Eric Johnson <eric@liveathos.com>
Prefix ringbuffers with cdc_acm because it is not possible
to use static specifier with RING_BUF_*_DECLARE_* macros
to avoid conflicts.
Fixes: #36608
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Before commit 4f2682bd79
("usb: cdc_acm: avoid spurious interrupt on configured or resume
events") spurious rx-interrupt provided start to read shell tx ring
buffer by CDC ACM UART. Now shell log backend not transmit data,
until CDC ACM UART received data from host.
This PR added invoking interrupt callback if tx interrupt is enable,
when CDC ACM class go to configured state, and flag tx_ready go to true.
Signed-off-by: Grixa Yrev <GrixaYrev@yandex.ru>
Add hidden Kconfig option to Kconfig.cdc and allow
to configure CDC ACM UART device from devicetree.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
After the modules are adapted for the revised
USB device stack configuration, and it seems that
it was only necessary for MCUboot, we can finally
remove Kconfig option CONFIG_USB.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Change cdc_acm_poll_out to do the best to mimic behavior
of a hardware UART controller without flow control.
With this patch, if the USB subsystem is not ready,
no data is transfered to the buffer, that is, new character
is dropped. If the USB subsystem is ready and the buffer is full,
the first character from the tx_ringbuf is removed to
make room for the new character.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
With the last changes in USB device stack it was unfortunately
not considered that an interface can have no endpoints.
This caused the USB DFU class to stop working in DFU mode.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Cleanup standard device request handler.
Pass pointer to setup packet as argument where
it is reasonable.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Cleanup standard device request handler.
Pass pointer to setup packet as argument where
it is reasonable.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
This class does not handle any vendor request,
therefore just return -ENOTSUP on any vendor request.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
HCI commands are always directed to controller and should be
host-to-device class control requests.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Return ENOTSUP if request is unsupported and pass on the error
from encapsulated command/response functions.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Control request handler from CDC ECM implementation does not
care at all about returning errors when a request is not supported.
Return EINVAL/ENOTSUP if request is incorrect/unsupported.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Set data stage length variable to zero as a precaution
so that no trouble happens if control request handler
does not check the request values sufficiently.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
The USB configuration option is actually a global switch
to enable USB drivers in general, but currently only
the device controller drivers are meant.
USB device controller drivers also have USB_DEVICE_DRIVER option.
Thus the option USB is actually redundant and can be replaced
by the self-explanatory option USB_DEVICE_DRIVER.
The name USB itself is not unique and should not be used as an
configuration option.
With these changes the option USB_DEVICE_DRIVER generally
enables USB device controller drivers. The option USB_DEVICE_STACK
enables USB device support. It is sufficient to enable only option
USB_DEVICE_STACK because it selects USB_DEVICE_DRIVER.
CONFIG_USB Kconfig option is temporary added to subsys/usb/Kconfig.
This is necessary to pass CI and will be removed again
when the USB configuration has been adapted in modules.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
When the Hardware Information Driver (HWINFO) provides a device ID
longer than the configured USB serial number, truncate the most
significant part instead of the least significant part. The lower part
is usually having more entropy, e.g. on STM32.
Fixes#34550
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
The len argument always has the same value as
usb_dev.setup.wLength, which is also the last received
USB device request.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Because it is not always possible to determine whether
a request is for Audio class or not, all requests are passed
to it. This can lead to the requests, to e.g. HID interface,
being hijacked by Audio class.
Ignore return value of Audio custom handler as it is not relevant here.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Since the settings are stored in the core now,
we can remove REQ_GET_INTERFACE part from custom handler
and simplify the code. Return value is no longer relevant
since custom callback does not need to interfere with the
request handling process.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Store alternate interface settings and
return alternate on GetInterface request.
Fixes: #24200
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
The USB HID class API offers the possibility to register callbacks
for Get/SetIdle, Get/SetProtocol to the application.
Rules for these callbacks are neither obvious nor documented.
This patch remove this possibility to register Get/SetProtocol
and Get/SetIdle callbacks for the following reasons:
The possibility to call unknown application code while processing
control requests should be avoided or reduced to a minimum.
The Get/SetProtocol callbacks are redundant and do not provide any
additional value since the way to inform the application
about the change of the protocol exists via the callback
hid_protocol_cb_t protocol_change.
The core provides implementation to handle Get/SetIdle requests and
on idle reports. If this is not suitable in any way then the application
should implement everything itself.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Refactor and simplify the bluetooth buffer configurations to improve the
easy of configurations and eliminate invalid ones.
By moving configurations out of host and controller specific
configurations and into a common one it becomes easier to configure
the host and controller separately as the same configurations can be
used as would be for a combined build.
All HCI configurations are now given exluding the matching HCI header,
which eases the configuration as the application don't have to know the
different header sizes.
The BT_RX_BUF_LEN is split into ACL and Event, as well as the suprising
use of Command size.
BT_L2CAP_RX_MTU is removed as the stack does not support reassembling of
HCI ACL data to larger L2CAP PDUs. The application will have to set
ACL RX size and account for the L2CAP PDU header itself.
BT_EATT_RX_MTU was removed as it is only used for setting a different
default value for another option which leads to the stuck kconfig symbol
problem.
The configurations can be updated according to the table below:
** New configuration | ** Old configuration
All configurations
BT_BUF_ACL_RX_SIZE | BT_L2CAP_RX_MTU + 4
BT_BUF_ACL_RX_SIZE | BT_RX_BUF_LEN - 4
BT_BUF_EVT_RX_SIZE | BT_RX_BUF_LEN - 2
BT_BUF_CMD_TX_SIZE | BT_RX_BUF_LEN - 3
BT_BUF_CMD_TX_COUNT | BT_HCI_CMD_COUNT
BT_BUF_EVT_RX_COUNT | BT_RX_BUF_COUNT
BT_BUF_ACL_RX_COUNT | BT_RX_BUF_COUNT
BT_BUF_ACL_RX_COUNT | BT_ACL_RX_COUNT
BT_BUF_EVT_DISCARDABLE_SIZE | BT_DISCARDABLE_BUF_SIZE - 2
BT_BUF_EVT_DISCARDABLE_COUNT | BT_DISCARDABLE_BUF_COUNT
Controller-build
BT_BUF_ACL_TX_SIZE | BT_CTLR_TX_BUFFERS_SIZE
BT_BUF_ACL_TX_COUNT | BT_CTLR_TX_BUFFER
HCI-bridge
BT_BUF_ACL_TX_SIZE | BT_HCI_ACL_DATA_SIZE
BT_BUF_ACL_TX_COUNT | 6
Fixed invalid configurations setting either BT_L2CAP_RX_MTU or
BT_CTLR_DATA_LENGTH_MAX larger than BT_RX_BUF_LEN could lead to buffer
overruns.
Fix advertising report max data length calculation.
This always used the BT_DISCARDABLE_BUF_SIZE macro but this feature
can be turned off and advertising reports will be allocated from the RX
buffer in that case. Also controller-build does not have this buffer
(in hci_raw.c). Also the wrong HCI header was used in the calculation,
HCI event header should have been used instead of HCI ACL header.
Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
set_endpoint() and reset_endpoint() were missing final
else statement in the if else if construct. This commit
adds a final else {} with assert to comply with coding
guideline 15.7.
Signed-off-by: Jennifer Williams <jennifer.m.williams@intel.com>
The z_timeout_end_calc function was replaced by
sys_clock_timeout_end_calc in #33302. A reference to the old function
snuck into master through #30015.
Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
Replace all existing deprecated API with the recommended alternative.
Be aware that this does not address architectural errors in the use
of the work API.
Fixes#34092
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Instead of defining the string, that will be reported by DFU
as a name for DFU target, in code, pick it from the DTS label that
will be the DFU target.
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
Alternative settings are determined by number of flash partitions
available for DFU from DTS.
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
Zephyr already has a directory for storage API relevant headers.
Move disk_access.h header to include/storage where it fits better
structurally.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Allow callers to wait for an arbitrary amount of time, instead of always
waiting for a compile-time fixed period.
Signed-off-by: Josh Gao <josh@jmgao.dev>
Kconfig option USB_HID_PROTOCOL_CODE does not allow to set
boot interface protocol code for specific HID device but
only to set the same value for all device.
Add new API function to allow the application to set
Protocol Code per device. Deprecate USB_HID_PROTOCOL_CODE option.
Fixes: #32778
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
HID core implementation has support for Get/Set Idle requests and
on idle report processing. Basically it has little use.
Also, it has no users in the tree except samples/subsys/usb/hid,
which does not have it turned on.
There are several issues with the idle report implementation:
- Core calls hid_ops.on_idle callback with Report ID 0,
but this ID is reserved and should not be used.
Report descriptors do not use Report ID index zero.
- Calling hid_ops.on_idle with Report ID 0 cann only
be turned off by calling SetIdle(Duration = 0, Report ID = 0),
but not by SetIdle with Report ID not equal zero.
- GetIdle with Report Id not equal zero returns wrong
value after SetIdle(Duration = n, Report ID = 0)
- It may happen that hid_ops.on_idle is called for
different Report ID during one and the same SoF event.
But there can be only one hid_int_ep_write() during a frame.
This patch fixes listed issues and revises Get/Set Idle request,
and hid_sof_handler() implementation.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>