Guard the websocket shell backend's internal state with a mutex.
The disconnect callback executes on a different thread than the shell
and can interleave with sends, leading to writes on an invalid fd or
a disconnected socket.
Signed-off-by: Arthur Gay <arthur.gay@marshmallow.kids>
Preallocate and keep reusing the same buffer for SETUP data. This
ensures that USB stack will always be able to handle SETUP stage
regardless of UDC memory pool usage.
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
Allocating buffer in response to control transfer is part of processing
and therefore should not be done in UDC driver but rather in the stack.
Simplify UDC driver design by moving all control transfer buffer
allocations and processing to USB stack.
New control transfer handling flow is as follows:
1. USB stack allocates and queues buffer for Setup stage. This informs
UDC driver that USB stack is ready to process new transfer.
2. UDC driver completes enqueued Setup buffer. SETUP data may have
been received by device before Setup buffer was enqueued.
If multiple SETUP data was received, UDC driver must complete
request using last received SETUP data.
3. USB stack processes request. USB stack is responsible for:
* Stalling control endpoint when request cannot be processed
* Allocating and enqueueing Data stage buffer if necessary
- Depending on enqueued endpoint (IN/OUT), UDC driver is
expected to complete the transfer. If host sends new SETUP
data for any reason (e.g. timeout), then Data stage buffer
must be completed with -ECONNRESET code.
- UDC driver may postpone processing Data IN until USB stack
enqueues new Setup stage buffer.
* Handling status stage if applicable
- If Data IN was enqueued, stack immediately allocates and
enqueues Status OUT stage buffer.
- If Data OUT was enqueued, stack waits for Data OUT buffer
completion before doing any further processing.
- If control transfer handling fails, stack is expected to
STALL control endpoint.
* Allocating and enqueuing Setup buffer.
- This informs UDC driver that stack has finished processing
control transfer. UDC driver may choose to start processing
Data IN and/or Status OUT only after new Setup buffer is
enqueued.
4. UDC driver must fail (complete with -ECONNRESET) any enqueued and
not completed Data and Status buffers if host sends new SETUP data.
UDC driver must be able to buffer last received SETUP data until
USB stack is ready (enqueues Setup buffer).
5. UDC driver must complete all Data and Status buffers before it
completes Setup buffer.
6. UDC driver may keep ownership of Setup, Data and/or Status buffers
across USB bus resets. USB stack does not attempt to dequeue any
control transfer buffer it enqueued.
This approach implicitly synchronizes UDC driver against USB stack,
which ensures that only one set of Setup/Data/Status buffers is
allocated at a time.
Another advantage of the rework is drawing a clear line on buffer
ownership. The buffer responsibilities are as follows:
* USB stack is the only entity that both allocates and frees the
buffers. Only USB stack is allowed to set "setup", "data" and
"status" fields in struct udc_buf_info.
* UDC takes ownership of buffers handed to it in udc_ep_enqueue().
* UDC releases buffer ownership by calling udc_submit_ep_event().
Because there is just a single place where the buffer ownership changes,
and all buffers must go USB stack (alloc) -> UDC (perform requests on
the bus) -> USB stack (free) route it would be possible in the future to
implement a "tap" similar to Linux usbmon that would ease debugging.
This commit significantly changes how USB stack communicates with UDC
drivers. It was decided that supporting both the old and new model
simultaneously would require way too much effort. Therefore all UDC
drivers were reworked. Following people worked on driver rework:
* Tomasz Moń - ambiq, dwc2, kinetis, mcux ip3511, nrf, numaker,
renesas ra, rpi pico, smartbond, virtual
* Mathieu Choplain - stm32
* Mark Wang - mcux ehci
* Johann Fischer - sam0, stm32
* Ren Chen - it82xx2
* Brandon Hurst - max32
* Gerson Fernando Budke - sam udp, sam usbc, sam usbhs
Co-authored-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
Co-authored-by: Johann Fischer <johann.fischer@nordicsemi.no>
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Co-authored-by: Mark Wang <yichang.wang@nxp.com>
Signed-off-by: Mark Wang <yichang.wang@nxp.com>
Co-authored-by: Ren Chen <Ren.Chen@ite.com.tw>
Signed-off-by: Ren Chen <Ren.Chen@ite.com.tw>
Co-authored-by: Brandon Hurst <brandon.hurst@analog.com>
Signed-off-by: Brandon Hurst <brandon.hurst@analog.com>
Co-authored-by: Gerson Fernando Budke <nandojve@gmail.com>
Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
The usage of CHECKIF has been replaced with a regular
if. The reason for this is that higher layer may depend
on some of the checks defined by the API, and the higher
layers cannot do that properly if the checks can be
removed via a Kconfig option.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Add bt_uuid_compress() to compact a 128-bit Bluetooth UUID into its
16-bit or 32-bit short form when it matches the Bluetooth Base UUID.
If the UUID does not match the Base UUID pattern the 128-bit value is
copied unchanged and -ENOTSUP is returned, allowing callers to
distinguish compressible from non-compressible UUIDs.
16-bit and 32-bit source UUIDs are copied as-is.
Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
Implement bt_uuid_from_str() function to convert string representations
to Bluetooth UUID structures. This provides bidirectional conversion
between UUID structures and their string representations, complementing
the existing bt_uuid_to_str() function.
Features:
- Supports 16-bit UUID format (4 hex characters, e.g., "180d")
- Supports 32-bit UUID format (8 hex characters, e.g., "abcdef12")
- Supports 128-bit UUID standard format (with hyphens)
- Comprehensive input validation and error handling
- Automatic UUID type detection based on string length
Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
Refactor the Bluetooth UUID module to use the generic UUID library
(lib/uuid) instead of hand-rolled byte manipulation.
Changes:
- Replace bt_uuid_128-based base UUID with struct uuid (RFC 9562 order)
- Replace uuid_to_uuid128() with bt_uuid_to_uuid() for BT-to-generic
UUID conversion using proper big-endian / byte-swap operations
- Simplify bt_uuid_to_str() 128-bit case via uuid_to_string()
- Add Kconfig 'select UUID' dependency for BT_HCI_HOST
Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
This is useful if the application may wish to reject an address.
This works well alongside the address_provider callback, this way
you can enforce static leases based on the client id (MAC address).
Signed-off-by: Andreas Ålgård <aal@ixys.no>
Fix three command handlers that were incorrectly returning the result
of callback functions with void return type:
- avrcp_unit_info_cmd_handler
- avrcp_subunit_info_cmd_handler
- avrcp_pass_through_cmd_handler
Split the callback invocation and return statement to properly handle
the void return type, avoiding potential compiler warnings or errors.
Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
The MQTT logging backend can cause the logging thread
to take over idle time when the used client disconnects/fails
to send the log messages.
Fixed by always returning the length of the log in every case.
Signed-off-by: Roland Lux <roland.lux@blue-zone.at>
- NET_EVENT_IF_UP can fire between the net_if_is_up() check and
net_mgmt_add_event_callback() in check_interface(). When this
happens (e.g. with CONFIG_SHELL_BACKEND_TELNET=y which starts a
same-priority thread that brings the interface up concurrently),
the event is missed and net_config_init_by_iface() blocks forever.
- Fix by always registering the callback first, then checking
net_if_is_up() after registration. If the interface came up in
the race window, remove the callback and signal the semaphore
immediately. Move the NET_INFO print to only fire when we are
genuinely going to wait.
Signed-off-by: Jjateen Gundesha <jjateen97@gmail.com>
The espressif toolchain variant (ZEPHYR_TOOLCHAIN_VARIANT=espressif)
has not been used for years. Espressif targets are now built using the
Zephyr SDK, which bundles the required Xtensa and RISC-V toolchains.
Remove the cmake/toolchain/espressif/ directory containing generic.cmake,
target.cmake, and Kconfig files that implemented this variant. Also
clean up references in the coredump xtensa gdb stubs, removing the
ESPRESSIF toolchain enum value and related handling code.
Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
The bt_hci_cmd_create() function was deprecated several releases ago (in
Zephyr 4.2) and can therefore now be removed.
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
The 3GPP TS 27.010 section 5.3.4 specifies:
"DISC command sent at DLCI 0 have the same meaning as the
Multiplexer Close Down command"
Add a handler for this and do the same operation as in
modem_cmux_on_cld_command().
Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
Add a check of the URI scheme length before comparing it
to any instance's supported URI schemes. If the incoming
URI scheme is longer than what we support, then there's
no point in checking if we support it, as we cannot.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
The BT_GATT_INCLUDE_SERVICE is always included in
BT_MCS_SERVICE_DEFINITION even when CONFIG_BT_OTS=n,
this fixes it such that it is only included when OTS is enabled.
Fixes zephyrproject-rtos#105345
Signed-off-by: Vedant Malkar <vedantitsme@gmail.com>
When the controller supports BR/EDR and CONFIG_BT_CLASSIC is
enabled, call bt_br_init() to perform the full BR/EDR Classic
initialization (SSP mode, inquiry mode, local name, Class of
Device, etc.).
For non-Classic builds that still need BR/EDR buffer sizes,
gate the hci_read_buffer_size() fallback with
IS_ENABLED(CONFIG_BT_CONN) to make the build-time condition
explicit at the call site.
Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
When CONFIG_BT_CLASSIC is enabled and the controller is ready,
push the updated device name to the BR/EDR controller via
bt_br_write_local_name() inside bt_set_name(). This ensures
runtime name changes are properly synchronized to the BR/EDR
transport.
Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
When CONFIG_BT_DEVICE_NAME_DYNAMIC is enabled, write the device name
(restored from flash or the compile-time default) to the BR/EDR
controller during commit_settings().
Replace the bt_set_name() call with a direct strncpy into bt_dev.name
to avoid an unnecessary flash write, then explicitly push the name to
the BR/EDR controller via bt_br_write_local_name().
Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
Extract the HCI Write Local Name command into a reusable
bt_br_write_local_name() helper and use it in bt_br_init().
When CONFIG_BT_DEVICE_NAME_DYNAMIC and CONFIG_BT_SETTINGS are
both enabled, skip writing the compile-time default here since
the settings commit callback will push the correct name (either
restored from flash or the default) to the controller.
Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
Replaces usage of these deprecated macros with ones that support
fixed and mapped partition compatibles. Also includes an update to
hal_espressif which also (rightly or wrongly) has zephyr specific
code in it
Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
Adds support for this new binding with new macros, also introduces
a new PARTITION_* macro scheme which allows for using either
storage method without needing to pick one or the other, and
deprecates the previous FIXED_PARTITION_* macros
Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
The net logging helper macros are now in a separate header.
Let's have all net users to include this new header.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
These macros are private to the net subsystem, let's not use them in
other subsystems.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
as there is now a 1:1 relationship beween
struct ethernet_context and struct net_if
we can simplify the logic here,.
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
use `NET_IF_OPER_UP` to check if the iface is
already up, this is also the state that corespondes with
NET_EVENT_IF_UP.
Also move `net_if_foreach(iface_cb, NULL);`
after `net_mgmt_add_event_callback()`, so we won't
miss any up event.
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
Fix error-checking bug in Zephyr `coredump_shell.c` for
`coredump_cmd(COREDUMP_CMD_COPY_STORED_DUMP, ...)`. The function
returns the number of bytes copied (≥ 0) on success and a negative
errno on failure, but the existing checks used `ret != 0` which
incorrectly treated a successful non-zero byte count as an error.
This bug prevented the coredump printing shell commands from working.
signed-off-by: Glenn Andrews <andrewsglenn@meta.com>
Combine toolchains provided by the host into one variant. This includes
both gcc and llvm installation typically coming from the distribution
(on Linux).
Both gcc and llvm are now part of the 'host' variant, the default is the
gnu compiler, so setting
ZEPHYR_TOOLCHAIN_VARIANT=host
Will select the gnu compiler. To select llvm or any other compuler
provided in this variant, use the follwoing format:
ZEPHYR_TOOLCHAIN_VARIANT=<variant>/<compiler>
The following will select llvm:
ZEPHYR_TOOLCHAIN_VARIANT=host/llvm
Although gnu is the default, it can also be selected using the above
syntax:
ZEPHYR_TOOLCHAIN_VARIANT=host/gnu
This commit removes the llvm variant for now, it should be deperecated
in another commit to follow.
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
Fix `error: label followed by a declaration is a C23 extension`
warning.
Issue introduced 0d3883516f
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
The attach and detach flow was previously scattered across bus event
handlers and class code, causing duplicated enumeration and class
probe/remove logic. Root-device state was also manipulated directly in
the host context, which made lifecycle handling implicit and limited
the ability to support devices behind a hub.
This update introduces common helpers for device attach and detach and
replaces direct root access with simple accessor functions. By unifying
enumeration and teardown into a single path, the control flow becomes
clearer and more consistent, and the host stack is no longer tied to a
single-root assumption. These changes form the basis for supporting
multiple devices attached through a hub in future updates.
Signed-off-by: Aiden Hu <weiwei.hu@nxp.com>
The random_linkaddr() function may generate MAC addresses with the
multicast bit set. Source MAC addresses must not be multicast, and
randomly generated virtual interface addresses should have the
locally administered (LAA) bit set.
Force the LAA bit and clear the multicast bit after generating the
random address.
Signed-off-by: Tharaka Jayasena <9dmpires2k17.tuj@gmail.com>
Remove double buffering that was using a separate work_buffer.
Receive and parse frames directly into receive_buffer instead.
This saves MODEM_CMUX_WORK_BUFFER_SIZE of RAM and avoids
one copy from work_buffer to receive_buffer.
Driver already asserts if the receive buffer does not fit
maximum frame, so it should be properly sized.
Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
Use resource table when CONFIG_OPENAMP_RSC_TABLE is enabled.
Tested with PocketBeagle 2 (M4 core running Zephyr)
Signed-off-by: Ayush Singh <ayush@beagleboard.org>