Commit graph zephyr/subsys
Author SHA1 Message Date
Emil Gydesen
3bb0a55fcb Bluetooth: BAP: UC: Unify callback order for sink and source
The BAP stream callbacks does not mirror the ASCS states 1:1
so there are a few cases where the callbacks are called without
matching the ASCS state.

BAP stream ops are intended to be the same for sink and source
ASEs, even though they have different state machine,
but sink streams did
stopped()
disabled()
qos_configured()

when exiting the streaming state (without a release), and source
streams did
disabled()
stopped()
qos_configured()

Refactor unicast_client_ep_notify_app a bit to have the same
callbacks in the same order for sinks and sources:
disabled()
stopped()
qos_configured()

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-08-26 15:57:35 +01:00
Johan Hedberg
a345efb003 Bluetooth: Host: Report the real advertising address from get_info
bt_le_ext_adv_get_info() handed out a pointer to the advertising set's
random_addr, which is only written when a per-set random address is
programmed. When the set advertises with a public identity address the
reported address was never populated, and with a controller without the
extended advertising feature it was never written at all.

Instead of adding a second address field alongside random_addr, widen
the meaning of the existing one: rename it to adv_addr, the address the
set advertises with regardless of type. The per-set random address
cases keep being updated in bt_id_set_adv_random_addr(), so the
reported address stays correct across RPA and NRPA rotation, and
le_update_private_addr() refreshes the legacy advertiser, which
advertises with the device-wide random address.

The cases that do not program a per-set address - a public identity
address, and the device-wide random address on controllers without the
extended advertising feature, e.g. an RPA set through
bt_id_set_private_addr() when privacy is enabled - are saved by a new
bt_id_save_adv_addr(), which the advertising parameter setting calls
once the controller has accepted the parameters. Saving only at that
point ensures a failed parameter update does not overwrite the reported
address with one the controller never took into use.

Widening the field is safe for the existing readers: the connection
responder address and OOB paths that read it only execute in
configurations where the set advertises with a random address, in which
case the value is unchanged, and a pending random address is programmed
from the field before bt_id_save_adv_addr() runs.

For the BT_HCI_OWN_ADDR_RPA_OR_* types the controller substitutes a
locally generated RPA whenever the peer is in the resolving list, which
the host cannot observe; the configured fallback address is reported in
that case, as documented on the info struct.

Fixes: #112667

Assisted-by: Claude:claude-fable-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-08-26 15:50:35 +01:00
Cheng Chang
9b9230207d bluetooth: host: bip: fix role validation in client connect
Move the responder role check outside the is_bip_primary_connect()
conditional so it applies to all connection types. Remove the
initiator role check from the secondary path since a responder role
is valid for secondary connections initiated by the remote device.

This ensures that a BIP instance configured as responder cannot
initiate any client connections, regardless of connection type.

Signed-off-by: Cheng Chang <cheng.chang@nxp.com>
2026-08-26 15:50:15 +01:00
Emil Gydesen
3940f96187 Bluetooth: BAP: UC: Add missing ISO_TEST_PARAM for reconfig
bt_bap_unicast_group_reconfig did not properly set the fields
related to CONFIG_BT_ISO_TEST_PARAMS nor packing.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-08-26 15:49:46 +01:00
Emil Gydesen
71dd77264c Bluetooth: Audio: expand bt_bap_unicast_group_info
Add the CIG parameters of the unicast group (SDU intervals, transport
latencies, framing, packing and, when CONFIG_BT_ISO_TEST_PARAMS is
enabled, the flush timeouts and the ISO interval) as well as the
has_been_connected state to struct bt_bap_unicast_group_info, so that
applications can retrieve all relevant information about a group.

The framing is stored internally using the ISO values, and is converted
back to the BAP QoS configuration values when reported.

The existing bsim tests for bt_bap_unicast_group_get_info have been
expanded to verify the new values, including for a group with
asymmetric parameters and for a reconfigured group.

Assisted-by: Copilot coding agent

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-08-26 15:49:46 +01:00
Emil Gydesen
e7264055cb Bluetooth: BAP: Remove bt_bap_ep group references
Remove the unused references to the unicast group
and broadcast source.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-08-26 15:49:46 +01:00
Emil Gydesen
813355d830 Bluetooth: BAP: UC: Fix group->has_been_connected
The ep->unicast_group was never assigned and thus
has_been_connected was never set for the BAP unicast groups.
Change to use the stream->group instead.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-08-26 15:49:46 +01:00
Måns Ansgariusson
42087db7de net: ssh: Update ring_buf usage to new zero-copy API
Migrate the SSH transport TX path off the deprecated claim/finish API to
the new _ptr/commit/consume pattern.

Signed-off-by: Måns Ansgariusson <mansgariusson@gmail.com>
2026-08-26 15:49:20 +01:00
Måns Ansgariusson
457ca4ab0a instrumentation: Update ring_buf usage to new zero-copy API
This commit updates the usage of ring_buf to utilize the new
put_ptr/commit/get_ptr/consume pattern instead of the traditional
claim/finish approach. This change is part of a larger refactor aimed at
streamlining the ring_buf API and improving its efficiency.

Signed-off-by: Måns Ansgariusson <mansgariusson@gmail.com>
2026-08-26 15:49:07 +01:00
Johan Hedberg
81eb5db08f Bluetooth: Host: Remove deprecated CONFIG_BT_FIXED_PASSKEY
CONFIG_BT_FIXED_PASSKEY, bt_passkey_set() and BT_PASSKEY_INVALID were
deprecated in commit 82cfb5a056 ("Bluetooth: Host: Deprecate
BT_FIXED_PASSKEY"), released in Zephyr 4.3, in favour of the app_passkey
callback gated on CONFIG_BT_APP_PASSKEY. Two releases have passed, so
remove them.

The replacement covers what the option did: an application that returns a
constant from bt_conn_auth_cb.app_passkey gets a fixed passkey, and one
that returns BT_PASSKEY_RAND gets a Host generated one, which is what
BT_PASSKEY_INVALID was used to fall back to.

DISPLAY_FIXED() could only ever be true with a fixed passkey configured,
so the four conditions using it reduce to the JUST_WORKS test they were
already OR'd with. Likewise the two branches in get_io_capa() that
upgraded the reported capability when a fixed passkey was set collapse to
the values they already returned otherwise; the CONFIG_BT_APP_PASSKEY
block above them covers that case for the replacement API. Behaviour is
therefore unchanged for anyone not enabling the removed option.

Drop the accompanying build warning and the hardened.csv entry, both of
which existed only to steer users away from the option.

Fixes: #36005

Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
Assisted-by: Claude:claude-opus-5
2026-08-26 15:48:41 +01:00
Emil Gydesen
9ba91cec66 Bluetooth: MPL: Implement playing speed
The playback_speed_param value was not used to correct
adjust the position while in the playing or state.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-08-26 15:47:33 +01:00
Al Semjonovs
e291aa1b94 ec_host_cmd: initialize thread field in context
Update struct ec_host_cmd to unconditionally store the k_tid_t of the
thread executing host commands. When running with a dedicated thread,
store the k_tid_t returned by k_thread_create. When running via
ec_host_cmd_task, record k_current_get() upon entry.

This allows consumers to consistently query the host command thread via
the ec_host_cmd context regardless of the threading configuration.

Signed-off-by: Al Semjonovs <asemjonovs@google.com>
2026-08-26 07:57:23 +02:00
Jordan Yates
40a0246860 pm: device_runtime: fix put_async with power domains
Fix a race condition that leads to a device being in `STATE_ACTIVE`
while its power domain is not enabled. The race occurs when an
asynchronous put is running and a `get` request arrives.

Assisted-by: GPT-5.5
Signed-off-by: Jordan Yates <jordan@embeint.com>
2026-08-26 07:55:20 +02:00
Arkadiusz Grzelka
e76f53a3d6 net: http: fix a signed overflow decoding an HPACK integer
hpack_integer_decode() accumulates the continuation octets of an HPACK
variable-length integer with

	*value += (*buf & ~HPACK_INTEGER_CONTINUATION_FLAG) * (1 << m);

Both operands are int, so the multiplication is done in int. The guard
above it stops at m > 32, which lets m reach 28, and an octet with any
value above 7 then overflows the multiplication: for the last octet of
ff 80 80 80 80 7f the product is 127 * 268435456, which does not fit in
an int. That is undefined behaviour on bytes a peer chooses: the integer
is decoded from a HEADERS frame, which an HTTP/2 client sends before
anything has authenticated it.

It can be watched happening with the decoder's own test suite. Add

	CONFIG_UBSAN=y
	CONFIG_UBSAN_TRAP=y

to tests/net/lib/http_server/hpack/prj.conf, and a case that calls the
decoder on those bytes, which the table-driven cases there cannot
express because the block is refused rather than decoded:

	ZTEST(http2_hpack, test_integer_overflow)
	{
		static const uint8_t buf[] = {
			0xff, 0x80, 0x80, 0x80, 0x80, 0x7f, 0x00 };
		struct http_hpack_header_buf hdr = { 0 };

		zassert_equal(http_hpack_decode_header(buf, sizeof(buf),
						       &hdr), -EBADMSG);
	}

Built for native_sim/native/64 with ZEPHYR_TOOLCHAIN_VARIANT=host/llvm,
an unmodified tree dies in that case,

	START - test_integer_overflow
	Illegal instruction (core dumped)

and with this commit applied the suite passes, the new case included.
The toolchain matters: gcc does not diagnose this multiplication at -O2,
and the sanitizer runtime that CONFIG_UBSAN selects without
CONFIG_UBSAN_TRAP does not come up on native_sim here, so clang in trap
mode is what makes it visible.

Do the arithmetic in the type the result is stored in, and reject the
exponent at the first value that no longer fits in it rather than one
step past. The reachable values of m are 0, 7, 14, 21, 28 and 35, so the
guard refuses the same octet as before; what changes is that the shift
that is performed is now defined.

The decoded value can still wrap, which is defined for an unsigned type,
and none of the three places that consume it accepts a wrapped one: an
index that is not in the table is rejected by http_hpack_table_get(), a
string length larger than the data left returns -EAGAIN from
hpack_string_decode(), so the server waits for more data instead of
reading past the buffer, and the size a dynamic table size update
carries is discarded. That leaves a conformance gap this commit does not
close: RFC 7541 section 5.1 says integer encodings that exceed
implementation limits, in value or in octet length, MUST be treated as
decoding errors. The octet-length half is already refused by the guard
above; the value half is not, and rejecting a wrapped value is a
behaviour change worth making on its own rather than inside a fix for
undefined behaviour.

No test is added. The old and the new code compute the same value on
every toolchain this was tried with, and the decoder returns -EBADMSG
for the input above either way, so the difference is visible only to a
sanitizer and a ztest asserting the return value passes before the fix
as well. The regression anchor is a libFuzzer harness for this decoder,
which reaches this input in seconds; it is a separate contribution and
is not in the tree yet, so until it lands this fix ships without one.

Signed-off-by: Arkadiusz Grzelka <devitwise@gmail.com>
Assisted-by: Claude:claude-opus-5 Claude-Code
2026-08-26 07:54:14 +02:00
Johan Hedberg
20937051d6 Bluetooth: Host: Monitor: add interrupt-driven UART output
The UART monitor backend sends every byte with uart_poll_out(). At
common UART rates this blocks the Bluetooth host while HCI traffic
and logs are serialized.

Add an opt-in interrupt-driven mode that buffers complete monitor
records and drains them from the UART interrupt handler. Record
fragments are copied in with ring_buf_put_ptr() and published with a
single ring_buf_commit(), so a record is either fully present in the
buffer or absent. This matters on panic: the panic handler flushes
only complete records before switching to polling, keeping the
stream parseable. Only the header-inline zero-copy ring buffer API
is used, so the option does not need to select RING_BUFFER.

A record that does not fit is dropped whole and reported through the
existing drop counters. Counts already consumed into a dropped
record's header are restored, keeping the accounting exact across
consecutive drops, and counts exceeding the 8-bit header field carry
over to the next record. Both kinds of loss previously also affected
the RTT backend, which shares this code.

Polling output remains the default and the panic-mode fallback,
since interrupts may no longer run during panic handling. It is also
the runtime fallback when the monitor UART driver lacks interrupt
support, since SERIAL_SUPPORT_INTERRUPT only guarantees that some
driver has it. The option depends on !LOG_MODE_MINIMAL because
minimal logging has no panic hook to flush buffered output.

Measured on nrf52dk/nrf52832 and xg24_rb4186c with a peripheral
flooding GATT notifications and the monitor sharing the 115200 baud
console UART: polling caps throughput at 5.9-6.6 KB/s, slows a paced
25 notifications/s workload to 15/s and blocks the producing context
~6 ms per large record (10-line printk burst: 58-65 ms). The
interrupt-driven mode restores radio-limited throughput (41 KB/s)
and the nominal paced rate, with the same burst at 0.8-1.3 ms. The
trade-off is load shedding: under sustained overload ~87% of
full-size ACL records are dropped (and accounted), while small
records such as Number of Completed Packets events keep flowing.

Unit tests cover contiguous and wrapped records, failed
reservations, zero-length fragments and exact-fit records; an
integration test runs the real producer/ISR path against the
emulated serial-test UART, covering drain, buffer-full drops with
accounting, and wrap-around consistency. The Bluetooth init test
builds the interrupt-driven path with the deferred log backend,
since tests default to minimal logging. Builds also pass with
polling UART and RTT.

Assisted-by: Claude:claude-fable-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-08-26 07:53:22 +02:00
Mark Wang
094f781949 bluetooth: classic: avdtp: register L2CAP server in bt_avdtp_register
The L2CAP server is now registered when the upper layer registers AVDTP
callback, which is a more appropriate time since AVDTP cannot function
when the upper layer doesn't register callback to enable the AVDTP
function.

Signed-off-by: Mark Wang <yichang.wang@nxp.com>
2026-08-26 07:51:32 +02:00
Mark Wang
3e5b6ace93 bluetooth: classic: a2dp: register AVDTP cb in bt_a2dp_register_cb
The AVDTP event handlers are now registered when the application
registers its A2DP callback, which is a more appropriate time since
A2DP cannot function when the application doesn't register a callback
to enable the A2DP functionality.

Signed-off-by: Mark Wang <yichang.wang@nxp.com>
2026-08-26 07:51:32 +02:00
Benjamin Cabé
27739525f3 bluetooth: mesh: remove deprecated BLOB IO flash erase options
Remove CONFIG_BT_MESH_BLOB_IO_FLASH_WITH_ERASE and
CONFIG_BT_MESH_BLOB_IO_FLASH_WITHOUT_ERASE. There is no replacement: the
BLOB IO Flash module stopped reading them in Zephyr 4.3 and instead
queries the erase capability at runtime through
flash_params_get_erase_cap(), so both options have been no-ops since
then. The enclosing "if BT_MESH_BLOB_IO_FLASH" block is kept for
BT_MESH_BLOB_IO_FLASH_WRITE_BLOCK_SIZE_MAX.

Deprecated in Zephyr 4.3.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Assisted-by: Claude:opus-5
2026-08-25 14:47:29 -07:00
Benjamin Cabé
dcc7db008e bluetooth: controller: remove deprecated BT_CTRL_ADV_ADI_IN_SCAN_RSP
Remove the CONFIG_BT_CTRL_ADV_ADI_IN_SCAN_RSP compatibility symbol,
which only selected the renamed CONFIG_BT_CTLR_ADV_ADI_IN_SCAN_RSP. The
CTLR-spelled option and its users in ull_adv_aux.c are untouched.

Deprecated in Zephyr 4.3.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Assisted-by: Claude:opus-5
2026-08-25 14:47:29 -07:00
Benjamin Cabé
ce65ad9e81 bluetooth: host: remove deprecated BT_CONN_TX_MAX
Remove the CONFIG_BT_CONN_TX_MAX Kconfig option and its only in-tree
user, the SiWx91x SoC configdefault. No C code has read the symbol since
it was deprecated, so it had no effect on any build; the number of
pending TX buffers with a callback follows CONFIG_BT_BUF_ACL_TX_COUNT,
which was already both the default and the range floor of the removed
option. The SiWx91x default of 15 matched that SoC's
BT_BUF_ACL_TX_COUNT default, so behaviour is unchanged there too.

Deprecated in Zephyr 4.2.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Assisted-by: Claude:opus-5
2026-08-25 14:47:29 -07:00
Benjamin Cabé
55efdc9fb1 bluetooth: dis: remove deprecated BT_DIS_MANUF and BT_DIS_MODEL
Remove the CONFIG_BT_DIS_MANUF and CONFIG_BT_DIS_MODEL string options,
together with the BT_DIS_MANUF_DEPRECATED_USED and
BT_DIS_MODEL_DEPRECATED_USED helper symbols whose only purpose was to
detect their use. Use CONFIG_BT_DIS_MANUF_NAME /
CONFIG_BT_DIS_MANUF_NAME_STR and CONFIG_BT_DIS_MODEL_NUMBER /
CONFIG_BT_DIS_MODEL_NUMBER_STR instead.

With the helper symbols gone, the two characteristic bools no longer
need their "depends on !*_DEPRECATED_USED" guards and are
unconditionally default y again, and the #if/#elif ladders in dis.c
collapse to the non-deprecated branch.

Deprecated in Zephyr 4.1.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Assisted-by: Claude:opus-5
2026-08-25 14:47:29 -07:00
Kyra Lengfeld
b6a5e6e8aa Bluetooth: Host: Fix bt_conn reservation leak for extended advertising
This fixes a leak for the following scenario:
A bonded peer connects via undirected adv set while directed connectable
extended advertisement runs on the same identity.
The enhanced connection complete is cached, not yet processed and the
undirected set is terminated, which clears the `BT_ADV_ENABLED` flag.
During processing of the cached enhanced connection complete event, the
`find_pending_connect()` function then finds the directed set instead of
the undirected set (as until now there was no distinction of the
advertising set type in the lookup function). This leads to a
reservation leak, as the directed set is not terminated (but the
`BT_ADV_ENABLED` flag is cleared).

This commits adds the advertising set context to the
`bt_hci_le_enh_conn_complete()` and `find_pending_connect()` functions,
so that the correct advertising set is used for the lookup.

Note: This change has been locally tested with a test case created by AI
that reproduces the above scenario.

Signed-off-by: Kyra Lengfeld <kyra.lengfeld@nordicsemi.no>
2026-08-25 08:05:30 -07:00
Jonathan E. Peace
78fff367ce llext: clean dcache before icache invalidate on exec regions
Invalidating before the clean lets the ifetch refill stale data.

Signed-off-by: Jonathan E. Peace <jep@alphabetiq.com>
2026-08-25 13:18:06 +02:00
Flavio Ceolin
9e7d607a39 Bluetooth: OTS: Decode Checksum only if it is supported
oacp_command_decode() accepted the op code unconditionally while
oacp_proc_validate() handles it under a Kconfig guard. Both answer Op
Code Not Supported, so guard the decode arm to match, the way Create,
Delete and Write already are.

Signed-off-by: Flavio Ceolin <flavio@hubble.com>
2026-08-25 11:24:35 +02:00
Flavio Ceolin
36145a6f11 Bluetooth: OTS: encode a checksum when one was calculated
oacp_ind_send() appended the Checksum Value based on the requested op
code alone, but validation only fills the response buffer on success.
Every error path therefore pulled four bytes from an empty buffer,
panicking with assertions enabled and reading stale stack without them.

Signed-off-by: Flavio Ceolin <flavio@hubble.com>
2026-08-25 11:24:35 +02:00
Jordan Yates
489328f78f net: lib: dns: dispatcher: ensure debug output on RX
Ensure that there is some form of logging from the DNS dispatcher module
at `LOG_LEVEL_DBG` when a DNS message is received and processed. Failure
to do so can lead to the misleading impression that no response was
received at all.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2026-08-25 11:24:27 +02:00
Jukka Rissanen
3f5a761db6 net: tcp: Take the packet length as an argument when pulling
tcp_pkt_pull() worked out the packet's length itself, which walks the
whole buffer chain, purely to reject a pull that is longer than the
packet. All three callers already knew the answer.

The one that matters is the acknowledgement path, which pulls the acked
bytes off the send queue. That queue holds the whole unacked window, so
the walk is proportional to the window and it runs on every ACK that
covers new data. The caller had already compared the same pull length
against conn->send_data_total on the line above, so the walk was
establishing something it had just been told.

The other two callers hold the length in a local because they needed it
to work out the header size in the first place.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-08-25 11:24:01 +02:00
Jukka Rissanen
8a4eb71fe0 net: tcp: Reject a short or missing header in the length helpers
tcp_data_len() works out the option length as (th_off - 5) * 4 without
first checking that th_off is at least 5. A segment carrying a smaller
offset makes that underflow to a very large size_t, and the payload
length derived from it is then whatever the subtraction happens to wrap
to.

tcp_recv() rejects such a segment at ingress, but that is not the only
way in. connection.c calls net_tcp_reply_rst() for a segment that
matched no connection, which is the path a segment addressed to a closed
port takes when CONFIG_NET_TCP_REJECT_CONN_WITH_RST is set. That path
checks the header only for NULL, so a remote peer can reach the
underflow and steer the acknowledgment number of the RST sent back to
it.

Check the offset where it is used instead, and treat a header that is
absent or too short as carrying no data. Give tcp_th() the same
tolerance for a NULL header: it takes the header from its caller now,
and net_tcp_reply_rst() hands it one straight from th_get() without
looking at it.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-08-25 11:24:01 +02:00
Jukka Rissanen
fbac9c55c1 net: tcp: Refresh the TCP header after trimming a segment
tcp_pkt_trim_data() drops the part of a segment that was already
received, and it does so by building a replacement buffer chain and
swapping it into the packet. Any pointer into the old chain is stale
afterwards, including the TCP header the state machine is holding.

Today that is harmless: the jump to the receive path does not touch the
header again. It stops being harmless the moment anything on that path
does, and nothing in the code said so.

Re-derive the header after a successful trim, and describe the lifetime
rule where the pointer is produced, listing the operations that end it.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-08-25 11:24:01 +02:00
Jukka Rissanen
e93271581a net: tcp: Pass the TCP header to the debug helpers
tcp_th() derived the TCP header itself, and tcp_conn_state() reaches it
for every received segment through the log statement in tcp_in(). Since
tcp_th() also calls tcp_data_len(), which used to derive the header too,
a debug build walked the packet twice more per segment than a normal one.

Pass the header down instead. Callers that log without a packet pass NULL
for both, as they already did for the packet.

Log arguments are not evaluated below their level, so this costs nothing
in a default build; the point is that a build with TCP debugging turned on
no longer pays for two extra walks per segment on top of everything else
it pays for.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-08-25 11:24:01 +02:00
Jukka Rissanen
66381eedb5 net: tcp: Pass the TCP header to tcp_data_len()
tcp_data_len() derived the TCP header only to read its offset field, so
every call rewound the packet cursor and walked the IP header again.
tcp_in() calls it for each received segment and already holds the header;
net_tcp_reply_rst() holds it too.

Take it as an argument. The packet is still needed for the length and the
IP header sizes, so only the derivation goes away.

The debug string builder and the test protocol hook keep deriving their
own, since neither has a header to hand.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-08-25 11:24:01 +02:00
Jukka Rissanen
28e97db922 net: tcp: Reuse the received TCP header in tcp_in()
tcp_recv() derives the TCP header to validate the segment and to find
its connection, then throws the pointer away. tcp_in(), called
immediately afterwards on the same packet, derives it again and gets an
identical result. Each derivation rewinds the packet cursor to the head
of the buffer chain and walks the IP header again.

Pass the header from tcp_recv() instead, and fold its NULL check into
the parameter check tcp_in() already performs.

Holding the pointer across the call is not a new practice here: tcp_in()
already keeps it for the whole state machine, through tcp_options_check(),
tcp_data_get() and tcp_pkt_trim_data(). This extends that lifetime by one
frame, over tcp_conn_search() and tcp_conn_new(), neither of which alters
the buffer chain.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-08-25 11:24:01 +02:00
Jukka Rissanen
3467596989 net: tcp: Derive the TCP header once per connection lookup
Looking up the connection for a received segment cost two full TCP
header derivations for every connection examined, not two in total.
tcp_conn_cmp() called tcp_endpoint_cmp() twice, each of which built a
temporary endpoint from the packet with tcp_endpoint_set(), and each of
those derived the header again. th_get() rewinds the packet cursor to
the head of the buffer chain, walks the IP header and checks the TCP
header is contiguous, so this was O(connections) walks of the same
packet just to find its owner.

The temporary endpoint was rebuilt just as often, and it is the same
value every time: it depends only on the packet.

Build both of the packet's endpoints once, before the loop, and reduce
tcp_endpoint_cmp() to the comparison it is named after. The comparison
still takes its length from the connection's endpoint, so a connection of
one family still cannot match a packet of another. tcp_conn_cmp() had no
purpose left and is folded into the loop.

A run with an empty connection list now builds two endpoints where it
previously built none. That list always holds at least the listener in
practice, and the two fills replace a pair of buffer walks per entry.

The two endpoints live on tcp_conn_search()'s stack rather than in the
deeper tcp_endpoint_cmp() frame, so peak usage on the receive thread
grows by roughly the size of one union tcp_endpoint.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-08-25 11:24:01 +02:00
Jukka Rissanen
bfa86d7af6 net: tcp: Pass the TCP header to tcp_endpoint_set()
tcp_endpoint_set() derived the TCP header itself, once in each of its two
address-family branches. Every caller already has the header in hand, or
is one step away from a caller that does, so the derivation is redundant.

Deriving it is not free: th_get() rewinds the packet cursor to the head
of the buffer chain and walks the IP header again on every call, then
checks that the TCP header is contiguous. On the SYN path
tcp_conn_new() paid for that twice.

Take the header as an argument instead and move the NULL check to the
top of the function, where it covers both families. tcp_conn_new() takes
it as well, since its only caller has already derived and checked it.

The remaining caller, tcp_endpoint_cmp(), keeps deriving its own for now
so that this commit changes no behaviour on the receive path; the
connection lookup is dealt with separately.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-08-25 11:24:01 +02:00
Måns Ansgariusson
96cd0a8d69 usb: cdc_acm: Update ring_buf usage to new zero-copy API
This commit updates the usage of ring_buf to utilize the new
put_ptr/commit/get_ptr/consume pattern instead of the traditional
claim/finish approach. This change is part of a larger refactor aimed at
streamlining the ring_buf API and improving its efficiency.

Signed-off-by: Måns Ansgariusson <mansgariusson@gmail.com>
2026-08-25 09:00:03 +02:00
Måns Ansgariusson
8c9ad65a52 shell: backends: Update ring_buf usage to new zero-copy API
This commit updates the usage of ring_buf to utilize the new
put_ptr/commit/get_ptr/consume pattern instead of the traditional
claim/finish approach. This change is part of a larger refactor aimed at
streamlining the ring_buf API and improving its efficiency.

Signed-off-by: Måns Ansgariusson <mansgariusson@gmail.com>
2026-08-25 09:00:03 +02:00
Måns Ansgariusson
537908a304 console: Move to new ring_buffer zero-copy API
This commit updates the usage of ring_buf to utilize the new
put_ptr/commit/get_ptr/consume pattern instead of the traditional
claim/finish approach. This change is part of a larger refactor aimed at
streamlining the ring_buf API and improving its efficiency.

Signed-off-by: Måns Ansgariusson <mansgariusson@gmail.com>
2026-08-25 09:00:03 +02:00
Benjamin Cabé
15770dbc7d bluetooth: host: remove deprecated CONFIG_BT_AUTO_PHY_UPDATE
CONFIG_BT_AUTO_PHY_UPDATE was deprecated in Zephyr 4.3 in favour of the
role-specific BT_AUTO_PHY_CENTRAL and BT_AUTO_PHY_PERIPHERAL Kconfig
choices, which also allow picking which PHY is preferred. Remove it as
part of the 4.5 deprecation removal cycle.

All C code and all in-tree samples and tests were already migrated to
the role-specific options when the deprecation was introduced, so only
the remaining Kconfig references need dropping. Since the deprecated
symbol lost its "default y if !BT_USER_PHY_UPDATE" in 4.3, it has been
unset in every in-tree configuration ever since, which makes each of
these references dead code today:

- The BT_AUTO_PHY_PERIPHERAL choice loses its "default
  BT_AUTO_PHY_PERIPHERAL_2M if BT_AUTO_PHY_UPDATE" entry and keeps
  falling through to _NONE, as it already did.

- BT_CTLR_LLCP_LOCAL_PROC_CTX_BUF_NUM loses the always-false
  "BT_AUTO_PHY_UPDATE=y" disjunct of its "default 6" condition, which
  now reads exactly as it already evaluated: BT_AUTO_DATA_LEN_UPDATE=y
  && BT_CTLR_LLCP_CONN < 4.

- The STM32WB0 SoC defconfig set BT_AUTO_PHY_UPDATE=n, which had no
  effect on either role, and is simply dropped.

This keeps the change behaviour-neutral. Two pre-existing quirks are
deliberately left alone rather than fixed here, since they are policy
changes for their respective maintainers and not part of removing a
deprecated symbol: the local procedure context count no longer reaches
6 via automatic PHY update, and the STM32WB0 series follows the
BT_AUTO_PHY_CENTRAL default of _2M for central-role connections.

The BT_BUF_CMD_TX_COUNT help text is updated to name the replacement
choices.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Assisted-by: Claude:opus-5
2026-08-25 08:59:41 +02:00
Emil Gydesen
b88d7dfd98 Bluetooth: CCP: Client: Modify how TBS callbacks are registered
Instead of assigning the individual callbacks at read time,
they are now all assigned at once. The main reason for this
is to be able to handle notifications that come, that use the
same callbacks, before any reads have been done. Notifications
would otherwise have been missed, if the application did not
perform a read first.

The CONN_CB functions were just moved to avoid needing function
prototypes.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-08-25 08:58:52 +02:00
Emil Gydesen
21e609b847 Bluetooth: CCP: Client: Add support for get bearer tech
Add support for getting the remote bearer tech.

Also slightly modified the test of the CCP samples
to properly catch issues (e.g. we disconnect on error,
and now we check for disconnect as the samples may reconnect
and thus have false positives).

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-08-25 08:58:52 +02:00
Flavio Ceolin
24dd24f023 net: lwm2m: Don't act on partial Package URI writes
lwm2m_write_handler() declared last_block as true and never assigned it,
so every non-opaque post-write callback was told the write had completed
on every block of a block-wise transfer. Neither package_uri_write_cb()
checked the flag anyway, so a Package URI written block-wise started a
firmware download from the first non-empty block, using whatever fragment
sat in the resource buffer instead of the intended URI.

Signed-off-by: Flavio Ceolin <flavio@hubble.com>
2026-08-24 14:15:34 -07:00
Fin Maaß
2d589ed69e net: if: validate multicast address before locking interface
Check multicast ip address before locking interface.

Signed-off-by: Fin Maaß <info@finmaass.de>
2026-08-24 14:12:41 -07:00
Fin Maaß
7b86cd9036 net: sockets: handle interface down case in multicast group join
when the iface is down, the group will
be joined on up, so don't treat that as
a error.

Signed-off-by: Fin Maaß <info@finmaass.de>
2026-08-24 14:12:02 -07:00
Dimitri Varpusvuori
4fa63783b0 logging: align stack packages when stack alignment is insufficient
The m68k port proposed in RFC #114672 permits 2-byte stack
alignment while pointers are 4 bytes. This is ABI-compliant, but
alloca() can consequently return an address at 2 mod 4.

cbvprintf_package() explicitly comments that its buffer must be
aligned at least to the size of a pointer, and returns -EFAULT
otherwise. Runtime logging then asserts because packaging failed.

Keep plain alloca() when ARCH_STACK_PTR_ALIGN guarantees pointer
alignment. Otherwise reserve alignment slack and round the allocation
to Z_LOG_MSG_ALIGNMENT. Apply this to the user, frontend fallback, and
immediate paths.

Although pointer alignment is enough to pass cbvprintf_package()'s
initial buffer check, use Z_LOG_MSG_ALIGNMENT for the fallback to
preserve the alignment assumed by logging's package-size calculation.

The condition is constant at compile time, so generated code remains
unchanged on architectures whose stack alignment is sufficient.

This is a prerequisite for the m68k port proposed in:
https://github.com/zephyrproject-rtos/zephyr/issues/114672

Assisted-by: OpenAI Codex
Signed-off-by: Dimitri Varpusvuori <dimitri.varpusvuori@gmail.com>
2026-08-24 14:07:59 -07:00
Lauren Murphy
e200f33b4a llext: remove unused variable in llext struct
Remove unused variable left in llext struct by #11409
due to CI error causing test failure.

Signed-off-by: Lauren Murphy <lauren.murphy@intel.com>
2026-08-24 14:06:32 -07:00
Siratul Islam
13c6f34320 authentication: fido2: implement changePIN
Implement changePIN subprotocol for clientPIN

Signed-off-by: Siratul Islam <siratul.islam@linux.dev>
2026-08-24 14:04:30 -07:00
Reto Schneider
4ad7e440ac crc: prevent implicit declaration
This change prevents the following compile warning:

> implicit declaration of function ‘crc32_mpeg2_update’; did you mean
> ‘crc32_ieee_update’? [-Wimplicit-function-declaration]

I have encountered this warning because downstream unit tests providing
their own, minimalistic replacement for zephyr/sys/crc.h and that
minimalistic header does not declare "crc32_mpeg2_update()".

Certainly not something that absolutely has to be upstream, but since
crc_hardware.c already uses this code ordering, having this change
upstream actually simplifies the code a bit for everyone.

Signed-off-by: Reto Schneider <reto.schneider@siemens.com>
2026-08-24 18:47:45 +02:00
Jukka Rissanen
289c14b910 net: dns: Use a fresh source port for each query
RFC 5452 9.2 asks a resolver to vary the source port of its queries as
well as the identifier. Both together are what an off path attacker has
to guess to forge an answer to a query it cannot see. The identifier was
already drawn afresh each time; the port was chosen once, when the
socket was opened, and reused for the life of the resolver, so a single
observed query gave it away for good and halved what an attacker had to
guess.

Give the socket a new port before a query goes to a server that has
nothing outstanding. It is closed and opened again rather than rebound,
because a bound UDP socket cannot be rebound, and the port is left to
the system exactly as it is at startup: binding to zero, with the
dispatcher reading back what was chosen.

One socket per server is kept, so the poll arrays, the descriptor budget
and the build assertions that size them are all as they were. What that
costs is that queries which overlap on one server share a port; only a
server with nothing in flight gets a new one. With the default of one
query at a time that is every query.

Multicast DNS and LLMNR are left alone. Both are spoken from a fixed
port, and the dispatcher paths a resolver to a responder by that port.

The old socket is given up before the replacement is asked for, so that
its descriptor is free when the new one is opened. Systems that size the
descriptor budget for exactly the sockets the resolver holds have no
spare one to lend.

CONFIG_DNS_RESOLVER_RANDOMIZE_SOURCE_PORT turns this off where the churn
matters more than the hardening.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-08-24 18:46:08 +02:00
Jukka Rissanen
41fe8752c5 net: mdns: Answer a legacy unicast query the way RFC 6762 asks
A query that did not come from port 5353 is not another multicast DNS
responder but something making a one-off lookup: a resolver library, or
a command line tool. RFC 6762 6.7 calls that a legacy unicast query and
asks for an answer such a querier can understand.

The responder already sent those answers back to the querier alone, and
the test that decides so has sat in setup_dst_addr() all along. It was
simply never passed to the code that builds the answer, so the answer
itself stayed in multicast form: identifier zero, no question section,
the cache flush bit set, and the full ten minute time to live.

For a querier that speaks multicast DNS none of that matters, because
RFC 6762 18.1 has it ignore the identifier and it knows what it asked.
For anything else all four matter. A conventional resolver matches an
answer to its question by the identifier and the question coming back,
and has neither here. Bit 15 of the class means "flush your cache" only
to a multicast DNS cache; to anything else it is part of the class, and
the answer is for a class nobody uses. And a ten minute lifetime is far
too long to hand to a cache that will not hear the announcements that
would correct it.

So propagate the test, and give an answer to such a query the shape a
conventional one has. Answers to a querier on port 5353 are unchanged,
identifier included: 18.1 requires that one to be zero.

The DNS-SD side of the responder builds its own messages in dns_sd.c and
still answers in multicast form. Doing the same there means reworking
the compression offsets those encoders compute from a fixed header size,
and is left for its own change.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-08-24 18:45:44 +02:00
Jukka Rissanen
6a96770a1e net: dhcpv4: Use one transaction identifier per transaction
RFC 2131 4.1 asks a client to use the same 'xid' for every message of a
transaction. The client counted it up by one on each message instead, so
a retransmitted discover carried a different identifier from the one it
was repeating.

Two things follow from that. A server cannot tell a retransmission from
a second client asking, and may offer twice. And an identifier that
counts up is one an off path attacker can guess, which is the whole
reason for having a random one.

It also lost answers: an offer to the first discover was dropped by the
identifier check in net_dhcpv4_input() once a retransmission had moved
the identifier on. A slow server is now heard.

Draw the identifier where a transaction begins instead: entering
SELECTING, RENEWING and REBINDING, and at the INIT-REBOOT entry taken
when an interface with a lease goes down. Not when entering REQUESTING,
because RFC 2131 4.4.1 has the request carry the identifier of the offer
it accepts, which already worked. A decline belongs to the exchange that
offered the address, so it no longer takes a new one either.

This is what the DHCPv6 client already does, in dhcpv6_generate_tid().

The discover path used the identifier as a source of randomness for the
backoff it returns when a packet cannot be allocated; with the
identifier no longer changing within a transaction, that would have
returned a constant, so it draws its own.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-08-24 18:45:32 +02:00