Move z_shell_backend_rx_buffer_flush() before state_set() in
shell_start() to prevent a race condition where incoming shell
commands could be lost.
Previously, the sequence was:
1. state_set() - prints the prompt
2. z_shell_backend_rx_buffer_flush() - flushes RX buffer
If the shell thread was preempted after printing the prompt,
the host could see the prompt and send commands. When the
thread resumed, z_shell_backend_rx_buffer_flush() would discard
those commands.
By flushing the RX buffer before printing the prompt, any
commands received after the prompt is visible will not be
affected by the flush operation.
Fixes#99674
Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@verkada.com>
Do direct resource path comparison on all registered resources before
falling back to fnmatch() so that exact path matches get always
preference.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Make USBD_HWINFO_DEVID_LENGTH prompt optional so that the code compiles
even if HWINFO is disabled.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Both cases use a large static buffer, we can optimize here and use a
single mutex-protected buffer for both.
sendmsg() test case needed adjustments, as it was also testing a buffer
overflow scenario. This can only be properly tested however if CID
feature is disabled, as otherwise the common helper buffer size is
increased for the CID use case, preventing the overflow from taking
place.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
For options that return the handshake status, make sure they work in
multi-client DTLS server case, by returning the status for the session
that completed handshake most recently. For TLS and DTLS client cases
that should make no difference, as there should only be one session per
context.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
With support for multiple client sessions for DTLS server socket, the
session timeout can no longer rely on built-in mbed TLS timing out
mechanism, as this only works for the session that is currently active.
Background sessions would never time out if the client just went silent.
Therefore, allocate a per-session timestamp, that keeps track of the
last activity on the session. Then, whenever poll() or recv() is called
loop over all sessions to identify those that timed and should be
released.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
In case a client address changes, but a session uses Connection ID
extension, the server should verify if the packet belongs to any of the
established sessions based on the CID value.
Therefore, before attempting to allocate a new session in such case,
loop over sessions and try to match the packet to one of the existing
sessions based on CID. In case of success, update the corresponding peer
address.
If no session is found based on CID, only then try to allocate a new
one.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
In case of errors on an active session (in most cases peer closing the
session), the session should be freed. Note, that as mbed TLS needs some
session context to work with, the last session on a socket is not freed,
but only reset instead.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
For TX, the DTLS server needs to check the peer address before passing
the packet to mbed TLS. In case the peer address doesn't match the
active session, it needs to switch sessions.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Refactor RX side for DTLS server to allow session switching when a
datagram from a peer that does not match current session. The server
needs to loop over established sessions, and in case no session is
found allocate a new one.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Split DTLS BIO RX functions for client and server case, given the
functionality will differ heavily. DTLS server needs to peek packet
before passing it to mbed TLS to allow to switch DTLS sessions in case
peer address doesn't match.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Separate TLS session context from the TLS socket context so that a
single DTLS server socket can support multiple client sessions.
Other socket types will only have a single session per TLS socket.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Modbus is failing to turn on RX when using serial ASYNC mode. This
causes modbus to never receive inbound requests, leaving it inoperable.
Additionally, modbus also enables RX when in client mode, leading to
issues when running as a client. These have been fixed by enabling rx
only when serial init is successful and modbus is in server mode during
initialisation.
Signed-off-by: Ryan Wiebe <ryan.wiebe@analog.com>
Correct the minimum MTU calculation for GOEP over L2CAP to account
for the L2CAP I-frame overhead.
- Update BT_BUF_ACL_RX_SIZE default from 264 to 265 bytes for GOEP
- Update BT_GOEP_L2CAP_MTU minimum range from 259 to 265 bytes
- Add detailed comment explaining L2CAP I-frame field length (6 bytes):
* 4 bytes for extended control field
* 2 bytes for FCS field
The previous calculation only accounted for the L2CAP header (4 bytes)
but missed the 6-byte L2CAP I-frame overhead (extended control field
and FCS), resulting in an incorrect minimum of 264 bytes instead
of the correct 265 bytes. And it causes the minimum MTU of L2CAP
to be incorrectly set to 254. The MTU cannot meet the minimum
requirement of GOEP MOPL.
The correct calculation for GOEP over L2CAP is:
255 bytes (GOEP minimum MTU) + 4 bytes (L2CAP header) + 6 bytes
(L2CAP I-frame) = 265 bytes total.
Set the default value of CONFIG_BT_BUF_ACL_RX_SIZE to 265 if GOEP is
enabled.
Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
When the USB Bus is reset, the USBD stack will disable and re-enable
all Classes. If this occurs while streaming audio with UAC2, the
terminals remain active when re-enabled, yet the endpoints have
yet to be enabled (resulting in -ENODEV logspam). This change
disables all active terminals when the class is disabled.
Signed-off-by: Victor Brzeski <vbrzeski@gmail.com>
Add early len check, remove use of strcpy, strncpy and
strncmp.
Co-authored-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Fix truncation detection after strncpy, as strlen cannot be
used if the src was truncated due to insufficient size of
dst.
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Rework settings implementation for not reusing the OS
snprintk implementation with CONFIG_PRINTK=n and to return
error if path buffer is insufficient.
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Rework settings implementation for not reusing the OS
snprintk implementation with CONFIG_PRINTK=n.
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Update settings implementation for not reusing the OS
snprintk implementation with CONFIG_PRINTK=n.
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Enforce the minimum TLS version on mbed TLS, based on the protocol
version provided by the application when creating socket. This ensures
that when application creates a TLS 1.3 socket, mbed TLS won't downgrade
the session to TLS 1.2 for instance.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
In pm_system_suspend there is a possible invalid type promotion
in sys_clock_set_timeout(MAX(0, ticks - exit_latency_ticks), true);
ticks is int32_t and exit_latency_ticks is uint32_t consequently
ticks is promoted to uint32_t resulting in a possible underflow and
setting a wrong value in sys_clock_set_timeout().
Fixes#100005
Coverity CID: 535628
Signed-off-by: Flavio Ceolin <flavio@hubblenetwork.com>
In NVS, allocation table entries (ATEs) are written backwards within
each sector. Under delete-only or delete-heavy workloads, a sector may
contain only delete ATEs, causing the ATE write pointer to approach the
sector boundary.
Without an explicit boundary check, ATE writes may occur at offset 0 of
the current sector, allowing the write pointer to underflow into the
previous sector and corrupt unrelated data or metadata.
Fix this by disallowing ATE writes when the write pointer is at the
sector boundary. This ensures that ATE writes remain confined to the
current sector and prevents pointer underflow across sectors.
Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
Introduce Kconfig option to enfore LLL prepare at margin
irrespective of whether there is an overlapping state/role.
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Use PPI/DPPI to start s/w switch timer to reduce current
consumption.
Explicitly starting the s/w switch timer at prepare meant
current being consumed in the prepare margin duration. Use
of PPI/DPPI ensure s/w switch timer is start when event
timer is started after the prepare margin.
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Fix the missing use of remainder value in the sync_offset_us
calculations. Also, Periodic Sync reception is relative to
Peripheral event hence ticks_anchor does not require the
ticker margin and event jitter to be subtracted.
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Remove Kconfig and code related to legacy Mbed TLS crypto for SHA-256.
This was used for the integrity check functionality as alternative to
PSA Crypto API. This support was already deprecated and now it's removed
in order to prepare for the next Mbed TLS 4.0 release where legacy crypto
won't be available anymore.
Signed-off-by: Valerio Setti <vsetti@baylibre.com>
Moved dsa_tag.h to include folder as common header file.
And we will support iterable section for vendor dsa tag
protocol drivers registering.
Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
Add error code parameter to all A2DP shell error messages to provide
more detailed diagnostic information when operations fail. This applies
to configure, establish, release, start, suspend, delay report, and
abort response handlers.
Signed-off-by: Mark Wang <yichang.wang@nxp.com>
Replace bt_shell_print() calls with bt_shell_error() for all error
conditions and failure cases in the A2DP shell implementation to
properly distinguish error messages from informational output.
Signed-off-by: Mark Wang <yichang.wang@nxp.com>
Replace all shell_print() and shell_error() calls with bt_shell_print()
and bt_shell_error() respectively to use the common Bluetooth shell
printing functions throughout the A2DP shell implementation.
Signed-off-by: Mark Wang <yichang.wang@nxp.com>
add abort req and rsp callbacks, improve register_ep cmd to support delay
report, check buf tailroom for sending media, add get_conn cmd to test
bt_a2dp_get_conn.
Signed-off-by: Mark Wang <yichang.wang@nxp.com>
The backoff timeout calculation in z_log_msg_claim_oldest() was
incorrectly using K_TICK macro. Changed to K_CYC to properly convert
cycle-based timing differences to kernel timeouts for accurate backoff
in multi-domain message processing.
Signed-off-by: Supper Thomas <78900636@qq.com>
The existing documentation link pointed to a non-existent page.
Update the link to use the current documentation URL.
Signed-off-by: Tahsin Mutlugun <Tahsin.Mutlugun@analog.com>
The SenML-JSON specification mentions base64-encoded data with the
URL-safe alphabet and padding omitted.
For sending data, zephyr used normal base64 with padding. Change the
base64 data to use the URL-safe format without padding when sending opaque
data via SenML-JSON.
Fixes#102390
Signed-off-by: Jeroen Broersen <jeroen.broersen@wioniq.com>
There was a Kconfig option defined to limit the number of additional DNS
queries sent for aliases received in CNAME records (to avoid potential
query loops), however it was not implemented. This commit implements the
feature - the resolver will now only send up to
CONFIG_DNS_RESOLVER_ADDITIONAL_QUERIES follow-up queries after
receiving CNAME record with an alias w/o any IP addresses.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
In case CNAME record is received with no IP addresses, DNS resolver will
attempt to re-send the query for the name indicated by the CNAME record.
The logic for scheduling the new query was inconsistent though:
dispatcher_cb() assumes that it'll reuse the query context with the same
query id, while dns_read() cancelled the query, which shouldn't really
happen, as that would cause an error to be reported to the application
via callback.
Fix that by skipping the query cancel in case of DNS_EAI_AGAIN result.
The query context will be properly reused then, and freed either when
reply for another query arrives, or the query times out.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Don't report CNAME records via application callback (as it used to be
done). They don't carry any data in the info struct and are only used
internally to redirect DNS queries.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The original implementation used a single global parameter structure for
GATT operations, preventing concurrent operations on different bearers. By
introducing a per-bearer context pool, each bearer can maintain its own
operation state, enabling simultaneous GATT operations.
Signed-off-by: Evgenii Kosenko <Evgenii.Kosenko@silabs.com>
Changes CONFIG_MCUMGR_TRANSPORT_UART from selecting
CONFIG_UART_MCUMGR to instead of depending upon it, as it should
never have selected a driver Kconfig and instead always depended
upon it, and is needed for supporting different UART transports
Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
When building the bluetooth.general.tester_le_audio test with clang and
-Winitializer-overrides, it warns:
subsys/bluetooth/audio/mpl.c:318:2: error: initializer overrides prior
initialization of this subobject [-Werror,-Winitializer-overrides]
318 | .add_group = NULL,
| ^~~~~~~~~~~~~~~~~
subsys/bluetooth/audio/mpl.c:317:15: note: previous initialization is here
317 | .add_track = NULL,
| ^~~~
Remove redundant initializer for add_group which overlaps with add_track
in an anonymous union.
Signed-off-by: Tom Hughes <tomhughes@chromium.org>