quic_stream_send(), ACK compaction, and loss recovery retransmits
can race on stream tx_buf state. Add stream->tx_lock, protect the
ACK advance, send, and retransmit paths, and document the
lock-aware internal API.
Assisted-by: Cursor:Auto
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Track per-stream out-of-order ACKed TX ranges and only advance the
contiguous ACK frontier when earlier gaps are filled.
Previously, later ACKs could move bytes_acked forward even when older
stream data was still unacked. That allowed the TX retransmit buffer to
release bytes that were still needed for loss recovery, which could
leave retransmissions stuck and cause the QUIC retransmission test to
time out under packet loss.
Keep out-of-order ACKed ranges queued per stream and merge them only
when they extend the current contiguous frontier. This preserves
retransmit data until it is truly safe to discard.
Assisted-by: Copilot:gpt-5.4
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Recovery metadata wiring now annotates stream frames by exact sent
packet number instead of “last sent” slot, to avoid cross-thread
mis-tagging. This helps debugging.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Fix OOO segment replay in quic_stream_receive_data() to avoid partial
copies when contiguous RX buffer space is tight.
Previously, replay used MIN(seg->len, avail), copied only part of the
segment, then removed that segment from the OOO queue. This could drop
tail bytes and leave the stream stalled waiting for data that was
already received.
Compact unread data first when possible. If the segment still does not
fit, keep it queued and retry later. Only remove an OOO segment after
copying the full segment into the RX buffer.
Assisted-by: Copilot:gpt-5.3-codex
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Multiple threads can send on the same endpoint (app quic_stream_send,
recovery retransmits, TLS crypto callback, DPLPMTUD probes). Without
serialization:
1. Thread A encrypts into tx_buffer and calls sendmsg
2. Thread B overwrites tx_buffer before A’s send finishes copying
iov data
Zephyr’s sendmsg path copies iov data into a net_pkt synchronously
via net_pkt_write() before returning, so sendmsg is safe once tx_buffer
is protected for the encrypt send window.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
The Datagram Packetization Layer Path MTU Discovery (DPLPMTUD) is
described in RFC 9000 section 14.3.
Keep the peer's max_udp_payload_size transport parameter separate
from the currently validated send limit. Add endpoint and sent-packet
state for DPLPMTUD so QUIC can track validated payload size, pending
probes, and probe retries.
Teach the QUIC/TLS send path to build exact-size PING+PADDING probe
datagrams, send them with don't-fragment enabled, and raise the
active TX payload limit only after probe ACKs. Repeated probe loss
now clamps the search range instead of folding the peer limit into
the current send cap.
Assisted-by: Copilot:gpt-5.4
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Allow user to mark IPv4/IPv6 socket as "do not fragment"
in which case IP fragmentation is not done even when trying
to send larger packet.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
the ``void *user_data`` in port_phylink_change contains the
dsa port device. make this more explicit, so that we no longer
need to cast this.
This is now possible as this function
is no longer directly passed to phy_link_callback_set.
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
handle changing the carrier inside the dsa
subsystem and make implementing
port_phylink_change optional.
This way the dsa port driver only has to do the
device specific actions.
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
Implement the close operation for ipc_icbmsg
Signed-off-by: Mike J. Chen <mjchen@google.com>
Co-Authored-by: Wojciech Sipak <wsipak@antmicro.com>
Signed-off-by: Wojciech Sipak <wsipak@antmicro.com>
Add support for the Cortex-A32 processor. The Cortex-A32 processor
is built on the ARMv8-A architecture and supports only the AArch32
execution state.
Signed-off-by: Silesh C V <silesh@alifsemi.com>
Log messages arriving during shell_readline corrupt the input line
because the log backend does not account for the different line
layout in readline mode (no shell prompt, optional readline prompt).
Fix by checking readline_state in process_log_msg (immediate mode)
and shell_log_process (deferred mode) to properly erase and restore
the readline input line. Process deferred logs inside the readline
loop so they appear in real-time.
Introduce shell_readline_prompt_set() so command handlers can
register a prompt string that is printed at readline start and
restored after log output.
Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@verkada.com>
Fix four bugs in shell UART async backend when using
SMP (mcumgr) transport:
1. Use CONFIG_SHELL_BACKEND_SERIAL_ASYNC_RX_TIMEOUT
Kconfig value instead of hardcoded 10000 in
rx_enable().
2. Consume all claimed bytes (blen) in
uart_async_rx_data_consume(), not just shell
bytes (sh_cnt). SMP-consumed bytes also need to
be released from the async RX buffer.
3-4. Loop in async_read() to keep claiming data when
SMP consumes all bytes, preventing data from
getting stuck in the buffer until the next
UART_RX_RDY event.
Fixes#98597
Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@verkada.com>
Add calculations to set the cig->c_latency and cig->p_latency
so that the CIS established event contains valid values.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
There was a missing check in le_ecred_reconf_req() that the provided CIDs
are dynamic (only those can be reconfigured). Add proper handling in case
a non-dynamic CID is encountered in the PDU.
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
The HCI LE LTK Request event parameters for `rand` and `ediv` should be
byte arrays, not integer types, to match the HCI specification and avoid
unaligned structure member access.
- Change `rand` from uint64_t to uint8_t[8]
- Change `ediv` from uint16_t to uint8_t[2]
- Add local variables in le_ltk_request() to convert byte arrays to
integer types before passing to bt_smp_request_ltk()
Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
The HCI LE Start Encryption command parameters for `rand` and `ediv`
should be byte arrays, not integer types, to match the HCI specification
and avoid unaligned structure member access warnings.
- Change `rand` from uint64_t to uint8_t[8]
- Change `ediv` from uint16_t to uint8_t[2]
- Update memcpy calls to remove unnecessary address-of operators
Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
Replace the two-line pattern:
net_buf_unref(buf);
buf = NULL;
with net_buf_drop(&buf) which performs both operations
atomically in a single step.
Assisted-by: GitHub Copilot:claude-sonnet-4.6
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
In bt_set_adv_param() and bt_br_init(), response buffers were
unreferenced but the pointer left live for significant amounts of
subsequent code. Use net_buf_drop() to make the intent explicit and
guard against accidental use-after-free.
Assisted-by: GitHub Copilot:claude-sonnet-4.6
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
Replace the two-line pattern:
net_buf_unref(buf);
buf = NULL;
with net_buf_drop(&buf) which performs both operations
atomically in a single step.
Assisted-by: GitHub Copilot:claude-sonnet-4.6
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
Replace the two-line pattern:
net_buf_unref(buf);
buf = NULL;
with net_buf_drop(&buf) which performs both operations
atomically in a single step.
Assisted-by: GitHub Copilot:claude-sonnet-4.6
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
g_pbap_app->tx_buf is a global struct member. On the error paths
the buffer was unconditionally unreferenced and cleared to NULL via
two separate statements with intervening code. Replace with
net_buf_drop() to combine both into a single atomic step.
Assisted-by: GitHub Copilot:claude-sonnet-4.6
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
Replace the two-line pattern:
net_buf_unref(br_chan->_sdu);
br_chan->_sdu = NULL;
with net_buf_drop(&br_chan->_sdu) which performs both operations
atomically in a single step.
Assisted-by: GitHub Copilot:claude-opus-4.7
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
Replace the if-guarded two-line pattern:
if (avctp->reassembly_buf != NULL) {
net_buf_unref(avctp->reassembly_buf);
avctp->reassembly_buf = NULL;
}
with net_buf_drop(&avctp->reassembly_buf) which performs both operations
atomically in a single step. The guard is unnecessary when there is no
other logic conditional on the pointer being non-NULL, because
net_buf_drop() handles a NULL pointer internally. Where the if-body
contains additional logging, the guard is kept.
Assisted-by: GitHub Copilot:claude-opus-4.7
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
Replace the if-guarded two-line pattern:
if (session->reasm_buf != NULL) {
net_buf_unref(session->reasm_buf);
session->reasm_buf = NULL;
}
with net_buf_drop(&session->reasm_buf) which performs both operations
atomically in a single step. The guard is unnecessary when there is no
other logic conditional on the pointer being non-NULL, because
net_buf_drop() handles a NULL pointer internally. Where the if-body
contains additional logging, the guard is kept.
Assisted-by: GitHub Copilot:claude-opus-4.7
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
Replace the if-guarded two-line pattern:
if (session->rec_buf != NULL) {
net_buf_unref(session->rec_buf);
session->rec_buf = NULL;
}
with net_buf_drop(&session->rec_buf) which performs both operations
atomically in a single step. The guard is unnecessary because
net_buf_drop() handles a NULL pointer internally.
Assisted-by: GitHub Copilot:claude-opus-4.7
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
Replace the two-line pattern:
net_buf_unref(*buf);
*buf = NULL;
with net_buf_drop(buf) which performs both operations atomically in a
single step.
Assisted-by: GitHub Copilot:claude-opus-4.7
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
Replace the if-guarded two-line pattern:
if (*buf) {
net_buf_unref(*buf);
*buf = NULL;
}
with net_buf_drop(buf) which performs both operations atomically in a
single step. The guard is unnecessary because net_buf_drop() handles a
NULL pointer internally.
Assisted-by: GitHub Copilot:claude-opus-4.7
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
Replace the two-line pattern:
net_buf_unref(buf);
buf = NULL;
(and equivalent if-guarded variants) with net_buf_drop(&buf) which
performs both operations atomically in a single step. The guard is
unnecessary because net_buf_drop() handles a NULL pointer internally.
Assisted-by: GitHub Copilot:claude-opus-4.7
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
Replace the two-line pattern:
net_buf_unref(buf);
buf = NULL;
with net_buf_drop(&buf) which performs both operations
atomically in a single step.
Assisted-by: GitHub Copilot:claude-sonnet-4.6
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
- This is less repetitive.
- This is more resilient against changes to the buffer size.
Signed-off-by: Michael Zimmermann <michael.zimmermann@sevenlab.de>
This allows checking if it was initialized already and prevent leaking or
double-freeing it.
I don't think it can happen the way the code is used right now, but I ran
into this issue while experimenting with tests.
Signed-off-by: Michael Zimmermann <michael.zimmermann@sevenlab.de>
Don't allow bringing a iface up, that doesn't have a
valid mac address. This way net_if_up() will fail.
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
use asserts for checks that would only be effective
if for example a ethernet driver was implemented wrong.
We don't need these checks in production.
For example a ethernet driver that doesn't implement the
send function is simply wrong, we don't need to test that
everytime we send a ethernet packet in production.
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
When the peer disconnects mid-transfer, the bt_att and bt_att_chan are
freed (att_chan_detach()/att_reset(), then bt_att_released()) while a
deferred unenhanced-ATT "sent" callback is still queued on the system
workqueue: the ATT TX buffer destroy work runs att_on_sent_cb() ->
bt_att_sent(), which dereferences the freed context and bus-faults in
sys_slist_get(&att->reqs).
att_on_sent_cb() already guards against a detached bearer, but it does
so by dereferencing meta->att_chan, which by then is a dangling pointer
(and faults once the channel slab slot has been reused).
Null any pending ATT TX metadata referencing the channel in
bt_att_released(), before the channel is freed, so the guard drops the
deferred callback instead of dereferencing freed memory. Teardown and
the destroy work both run on the cooperative system workqueue, so this
is serialized and needs no lock.
Assisted-by: Claude:claude-opus-4.8
Signed-off-by: Hayden Ball <hayden@playerdata.com>
Add an option to let users provide a lookup cache buffer for each ZMS
instance with zms_set_lookup_cache().
Keep the existing static cache behavior when manual cache setup is not
enabled.
Signed-off-by: Lucas Hutchinson <lucas.hutchinson@gmail.com>
When the application already uses an event fd, and does not increase
CONFIG_ZVFS_EVENTFD_MAX, zvfs_eventfd silently fails, setting
the fd to -1. This causes the ptp thread to get stuck at
ptp_clock_poll_sockets, without any clear signal to the user.
Signed-off-by: Jaro Van Landschoot <jaro.vanlandschoot@basalte.be>
Add shell commands to retrieve and clear LPN friendship timing
statistics. Available as mesh stat lpn_get and mesh stat lpn_clear
when CONFIG_BT_MESH_LOW_POWER is enabled. Rename existing frame
statistic commands to mesh stat adv_get and mesh stat adv_clear.
Assisted-by: Claude:claude-opus-4.6
Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
Add timestamp-based measurement of LPN friendship timing parameters
(ReceiveDelay and ReceiveWindow) to the statistic module. Timestamps
are captured at poll TX end, scanner enable, and response RX/timeout
using k_uptime_ticks(). Measured values are stored in microseconds.
Instrument the LPN state machine in lpn.c to call the statistic
update functions at each protocol event.
Assisted-by: Claude:claude-opus-4.6
Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
Add a PTP message parser regression test which exercises UDP/IPv4
PTP packets with CONFIG_NET_VLAN enabled.
The test covers both untagged and VLAN-tagged packets where the Ethernet
header is stored in the first fragment and the IPv4/UDP/PTP payload is
stored in the following fragment.
Signed-off-by: Tomas Choat <trc@ixys.no>
When CONFIG_NET_VLAN is enabled, msg_from_udp_pkt() used the VLAN
Ethernet header length for all packets. This caused the header length
comparison to fail for untagged packets, making the function inspect the
UDP header from the wrong packet layout and return NULL.
Check the packet VLAN tag at runtime and use the VLAN Ethernet header
length only for tagged packets. Keep the regular Ethernet header length
for untagged packets so both packet types are handled correctly.
Signed-off-by: Tomas Choat <trc@ixys.no>
Allow the notification callback to be set as long as USB is not enabled,
and permit users to change the callback.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Most HCI drivers have never handled the return value from the
driver-to-host receive path in any way, and they haven't really needed to
either since the buffer was always consumed regardless of success or
failure.
To be aligned with Zephyr coding guidelines without having to add
minimal value code to every driver, change bt_hci_recv() to return void
instead. A new bt_hci_recv_err() API is also added for any use case where
access to the error is needed.
There's also a related semantic change to the recv callback (passed to
bt_hci_open()) in that it's now expected to *not* consume the buffer in
case of error. There was only a single place in the host that needed an
update for this, while e.g. HCI raw always returned success.
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
There's no point in having driver specific data structs if the only thing
they contain is the common data struct. Just declare the common data struct
directly as dev->data.
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
Now that we have a common data struct, we can take advantage of it and
move the recv callback into it. This way the common layer takes care of
assigning, dispatching and clearing the callback. Drivers now have to use
the new bt_hci_recv() API to pass data to the layer above them (typically
a host stack). Additionally, the drivers no longer get a recv parameter as
part of their open() callback, since that's all handled by the common
layer.
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
Make these static (no need to export them) and also name them in a way that
doesn't class with the HCI driver API prefix.
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>