Commit graph zephyr/subsys
Author SHA1 Message Date
Lyle Zhu
9cf8cd6513 Bluetooth: host: classic: Refactor SDP client session management
SDP clients use `sem_lock(k_sem_take(K_FOREVER))` to serialize access
to their request list and session state to avoid thread safety issues.
Because SDP client callbacks run on a shared, cooperative `bt_workq`,
blocking the semaphore from the `bt_workq` context could cause all
other items in the same work queue to stall, not just the SDP session
itself.

Replacing the semaphore-protected `sys_slist` pair (`reqs`/`reqs_next`)
with a single `k_queue reqs_pending` allows safe access from any
context without blocking. `bt_sdp_discover()` returns success
immediately after adding a new request to the `queue reqs_pending` and
submitting a new `sdp_client_worker`. Therefore, the original session
creation-related operations are moved to `sdp_client_work_handler()`
and its helper functions, which run only on `bt_workq`.

The `sdp_client_work_handler()` function iterates through all SDP
sessions after each request submission and performs one of the
following workflow:
- If a disconnection is in progress (`SDP_CLIENT_DISCONNECTING`),
  skip the session;
- If the channel is connected but idle (`SDP_CLIENT_CONNECTED`, with
  no active parameter, it means the `session->param` is `NULL`), resume
  iterating through pending requests;
- If the channel is disconnected (`SDP_CLIENT_DISCONNECTED`) and there
  are pending requests, start a new L2CAP session;
- If the backend ACL connection is no longer active, clear
  `reqs_pending` using `UUID_NOT_RESOLVED` and reset the session.

SDP Client session lifecycle changes:
- `SDP_CLIENT_RELEASED` has been removed; `SDP_CLIENT_DISCONNECTED` is
  used to cover the same "not connected" state. The L2CAP `.released`
  channel ops has also been removed because restarting after
  disconnection is now driven by `sdp_client_work_handler()` instead
  of the `.released` callback. Also, since the `sdp_client_discover()`
  function requests an accept buffer, the L2CAP `.alloc_buf` channel
  ops is no longer needed to simplify the process and avoid potential
  `session->param` overwriting issues.
- A `BT_CONN_CB.disconnected` callback has been added to monitor ACL
  disconnection events. When the ACL connection itself is disconnected,
  all pending requests are cleared and the session is reset (previously
  handled indirectly via `reqs_next` and `sdp_client_released()`).
- Take/release ACL conn reference by the function `bt_sdp_discover()`.
  when adding a request to the `queue reqs_pending`, `bt_sdp_discover()`
  takes the reference of the ACL connection and releases the reference
  after the request is dequeued (cleared by processing of pending
  request, `bt_sdp_discover_cancel()`, or when the ACL connection is
  closed).
- Handle receiving buffer allocation failures without disconnecting the
  session. Notify the SDP discovery result with the `NULL` response
  buffer if the receive buffer allocation failed. And go to the next SDP
  discovery procedure instead of disconnecting the session.
- Use the client worker to trigger the next SDP discovery procedure
  to avoid recursive calls in the functions `sdp_client_discover()` and
  `sdp_client_params_iterator()`.

Updated API doxygen comments for `bt_sdp_discover()` and
`bt_sdp_discover_cancel()` to reflect the new return semantics:
`bt_sdp_discover()` always returns 0 after the request is enqueued,
and the actual success/failure of the discovery is reported later via
`params->func()`.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2026-09-10 12:18:37 +02:00
Arkadiusz Grzelka
f295eecde8 mgmt: mcumgr: os: refuse an echo request that carries no data
os_mgmt_echo() decodes the request into

	struct zcbor_string data = { 0 };

with zcbor_map_decode_bulk(), which reports success when the map holds
none of the keys it was given: nothing matched is not an error. A
request whose payload is an empty map therefore reaches the encoder
with data still holding a NULL pointer and a length of zero, and the
reply is a successful echo of a string the peer never sent.

Handing that to zcbor_tstr_encode() is undefined behaviour rather than
a harmless no-op, because it reaches memmove(dst, NULL, 0) in
zcbor_encode.c. Ten bytes are enough, and MCUmgr parses them before
anything has authenticated the peer:

	02 00 00 02 00 00 01 00 bf ff

Require the key the command is defined around. The reply becomes
rc = MGMT_ERR_EINVAL, which is what this handler already answers when
the payload does not decode, and a request that carries "d" is
unaffected.

The regression test sends that request through the dummy SMP transport
and requires the error response. It fails on an unmodified tree, where
the reply is 0x03 0x00 0x00 0x05 0x00 0x00 0x01 0x00 bf 61 72 60 ff,
an echo of the empty string.

Under the address and undefined behaviour sanitizers an unmodified tree
also reports

	zcbor_encode.c:283:31: runtime error: null pointer passed as
	argument 2, which is declared to never be null

for the same request, and does not with this commit applied. Seeing
that report needs -fsanitize=function switched off, because the cast in
ZCBOR_MAP_DECODE_KEY_DECODER trips the function-type check first on
every mcumgr command that matches a key; that is a separate matter and
is reported on its own.

Signed-off-by: Arkadiusz Grzelka <devitwise@gmail.com>
2026-09-10 12:17:23 +02:00
Zhijie Zhong
06bf600ddd Bluetooth: conn: drop the unused user data on the fragment pool
The ACL fragment pool declares CONFIG_BT_CONN_TX_USER_DATA_SIZE bytes of
user data that nothing reads. The requirement came from bt_buf_set_type()
and went away with 26d97164be, so the TODO next to it is stale.

Size it zero and keep the view metadata in the side table: an HCI driver
may use a sent fragment's user data, so metadata that frag_destroy()
dereferences does not belong there.

Signed-off-by: Zhijie Zhong <zhongzhijie1@xiaomi.com>
Assisted-by: Kiro:claude-opus-5
2026-09-10 12:17:11 +02:00
Tomasz Moń
569a8b312e usb: device_next: hid: Add get report size callback
Add new optional callback that the HID class can use to determine buffer
size necessary for Get Report response. This allows applications to
bound the maximum memory usage to actual supported report size instead
of having it depend on host-supplied wLength.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2026-09-10 12:15:57 +02:00
BUDKE Gerson Fernando
373f661d76 usb: device_next: dfu: Report the state GET_STATUS is entering
The handle_get_status() sends data->state. The
dfu_mode_control_to_host() assigns data->state = data->next only after
the response has been built. In this case the host receives the state
the device is leaving instead the state is entering.

In the DFU 1.1 Table 6-2 bState is defined as "the state that the
device is going to enter immediately following transmission of this
response". The difference matters for exactly one case: an image
backend that answers false from its next_cb puts the device into
DFU_DNBUSY instead report DFU_DNLOAD_SYNC.

The dfu-util does not notice because it loop polls until the state
becomes DFU_DNLOAD_IDLE and the fwupd can wait only while the reported
state is DFU_DNBUSY. This means that the application can send the
next block into a busy device and the transfer dies on a stall:

  failed to write-firmware: failed to write chunk 1: cannot download data:
  USB error: Pipe error [-9]

In this fix the send data->next GET_STATE is unaffected once it reports
the current state by definition.

Signed-off-by: BUDKE Gerson Fernando <gerson.budke@leica-geosystems.com>
2026-09-09 18:14:17 -04:00
BUDKE Gerson Fernando
ab9cb022eb usb: device_next: dfu: Reuse string descriptor
The dfu_mode_init() runs once per configuration. A device that offers
multiple speeds may add each image's string descriptor multiple times.
In the current implementation in the second attempt and forward the
class answer with -EALREADY. This leads to usbd_add_descriptor() report
when the node is already linked, and the class logs it at error level
on every boot:

  <err> usbd_dfu: Failed to add string descriptor
  <err> usbd_dfu: Failed to add string descriptor

The descriptor registered on the first pass is the one the host reads
and usbd_str_desc_get_idx() returns its index either way. Fix the
miss-leading error message.

Signed-off-by: BUDKE Gerson Fernando <gerson.budke@leica-geosystems.com>
2026-09-09 18:14:17 -04:00
Sylvio Alves
0d8201a50f bluetooth: host: name the esp32c5 and esp32c61 hw variants
The espressif hardware variant table stopped at the esp32h2,
so the two ids defined after it were printed as "unknown".
Add both names.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2026-09-09 18:14:06 -04:00
Jordan Yates
41ec924850 modem: ppp: LOG_DBG for transmitting frames
Add debug logging when transmitting frames through PPP, equivalent to
the receive path. For both paths, the output length is the `net_pkt`
size, not the total size of the PPP frame with headers, escaping, etc.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2026-09-09 18:14:01 -04:00
Zhijie Zhong
7906aaef02 Bluetooth: SMP: make the CTKD directions configurable
Cross-Transport Key Derivation is unconditional today. With
CONFIG_BT_CLASSIC enabled, Secure Connections pairing over LE always
asks for a derived BR/EDR link key, and the Security Manager over
BR/EDR always accepts deriving the LE LTK from the link key. A device
that must not end up with a bond on the other transport as a side
effect of pairing has no way to say so. Both decisions are device
global: the responder negotiates the key distribution before
bt_conn_set_security() is ever reached, and the fixed channel mask is
built during ACL setup, so Kconfig rather than an API.

Add BT_SMP_DERIVE_LTK and BT_SMP_DERIVE_LK, both default y, so
behaviour is unchanged unless a build opts out.

Without BT_SMP_DERIVE_LK, LINK_DIST expands to 0. That keeps the
negotiated key distribution and what goes on air consistent in both
roles without touching the PDU construction sites, and
ltk_derive_link_key_allowed() refuses the derivation as well.

Without BT_SMP_DERIVE_LTK, smp_br_pairing_allowed() refuses the
procedure and the BR/EDR Security Manager fixed channel is left out of
the L2CAP information response, so a peer does not start one that would
then be rejected. The channel stays registered, so a Pairing Request
that arrives anyway still gets the 0x0E failure.

Signed-off-by: Zhijie Zhong <zhongzhijie1@xiaomi.com>
Assisted-by: Kiro:claude-opus-5
2026-09-09 18:13:56 -04:00
Jordan Yates
44b0571109 modem: cmux: allow DLCI channels to process data
When the CMUX byte handling has resulted in a valid CMUX frame, give
that frames handling a chance to run before continuing to process
additional pending bytes. This stops a large CMUX frame followed by a
smaller frame resulting in buffer overruns.

The above error case was always observed on a `nRF93M1dk` running
`samples/net/cellular_modem` when it attempted to perform a DNS query,
as the result was a 127 byte cmux frame followed immediately by a 20
byte cmux frame.
```
Performing DNS lookup of test-endpoint.com
[00:00:08.217,048] <err> modem_cmux: DLCI 2 receive buffer overrun
                         (dropped 14 out of 20 bytes)
```

Signed-off-by: Jordan Yates <jordan@embeint.com>
2026-09-09 18:13:52 -04:00
Fin Maaß
04e4284b4c usb: host: fail device init when the device has no configurations
The error was logged but the device initialization returned success,
so the device was probed against the class instances without a
configuration descriptor and the stack dereferenced a NULL pointer.

Assisted-by: Claude:claude-fable-5-1

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2026-09-09 12:58:35 -04:00
Jukka Rissanen
0b2d0c2609 net: http: Do not print a header slice as a C string
The HTTP parser hands its data callbacks a pointer and a length, and the
field it points at is not NUL terminated. print_header_field() passed
that pointer to a %s conversion:

	snprintk(output, len + 1, "%s", str);

The size argument bounds the destination, not how far the source is
walked. Both formatter implementations measure the whole string first,
cbprintf_complete.c with strlen() when no precision is given and
cbprintf_nano.c with strlen() unconditionally, so the read runs past the
end of the field and out of the receive buffer that holds it.

The in-tree tests/net/lib/http_client suite reproduces it on an ordinary
GET, no crafted response needed, once it is built with CONFIG_ASAN=y and
CONFIG_NET_HTTP_LOG_LEVEL_DBG=y:

	AddressSanitizer: global-buffer-overflow
	READ of size 48 at 0x08117480
	    #1 in z_cbvprintf_impl lib/os/cbprintf_complete.c:1627
	    #5 in print_header_field subsys/net/lib/http/http_client.c:172
	0x08117480 is located 0 bytes after global variable 'recv_buf'
	  (0x8117440) of size 64

Copy the bytes the parser actually offered and terminate them, rather
than reaching for a precision. A precision only bounds the read in
cbprintf_complete.c; with CONFIG_CBPRINTF_NANO=y the source is still
measured in full before the precision is applied.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-09-09 12:56:42 -04:00
Tomi Fontanilles
e0973bbef7 secure_storage: split aead_get.c into subfiles
Make one file per getter function to compile them only when they
are used.
The code is only moved and unchanged.

Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
2026-09-09 10:42:28 -04:00
Marcin Niestroj
9dbfe80b6a net: mdns: initialize sin6_scope_id
create_ipv6_addr() sets sin6_family, sin6_port and sin6_addr, but leaves
sin6_scope_id untouched. Most callers pass a stack allocated
struct net_sockaddr_in6, so the scope id ends up being whatever happened
to be on the stack.

The resulting address is handed to zsock_bind() when the responder sets
up its IPv6 listener. net_context_bind() only looks at sin6_scope_id for
link-local unicast addresses, so the native stack never notices. Socket
offloading stacks do forward the field though: with
CONFIG_NET_NATIVE_OFFLOADED_SOCKETS the indeterminate value reaches the
host bind(), which rejects it with ENODEV, and the IPv6 listener never
starts.

Set the field explicitly. The listener is not scoped to a single
interface by its address - the interface is selected separately with
SO_BINDTODEVICE - so zero is the correct value.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2026-09-09 10:42:11 -04:00
Jukka Rissanen
3e8c5df3bf net: arp: Drop the now unused gratuitous argument
Every accepted ARP message refreshes an existing cache entry now, so the
gratuitous flag no longer selects any behaviour of its own and only the
force flag is left to decide whether a missing entry is created. Remove
the argument from net_arp_update() and from its callers.

Gratuitous ARP itself is unaffected: the reception of a gratuitous ARP
request is still recognised and gated by CONFIG_NET_ARP_GRATUITOUS in
net_arp_input(), which is where that check belongs.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-09-09 10:41:22 -04:00
Jukka Rissanen
20057f7cdd net: arp: Update a known cache entry from any accepted ARP message
An ARP reply that we did not solicit was silently discarded. In
net_arp_update() the pending entry lookup fails for such a reply, and
with neither the gratuitous nor the force flag set the function returned
without touching the cache. A peer whose link address changed could
therefore announce itself with an ARP reply and we would keep sending to
the address we learnt earlier.

RFC 826 asks for the opposite: whenever we accept an ARP message and the
sender protocol address is already in our translation table, the hardware
address stored in it is to be updated, regardless of the operation code
of that message. Only the gratuitous ARP request path did that so far.

Make the refresh unconditional and reduce the force flag to its remaining
meaning of inserting an entry that does not exist yet. An unsolicited
reply from a peer we know nothing about still creates nothing, so a host
on the segment cannot use it to fill the cache.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-09-09 10:41:22 -04:00
Ahnaf Shahriar
7bc568e1aa net: l2: ppp: act on a received Protocol-Reject
ppp_fsm_recv_protocol_rej() only logged the current LCP state and
returned NET_DROP, so a Protocol-Reject was effectively ignored. This
has two consequences.

The rejected protocol never learns that the peer rejected it. RFC 1661
chapter 5.7 says that upon reception of a Protocol-Reject the
implementation MUST stop sending packets of the indicated protocol at
the earliest opportunity, but the rejected NCP keeps retransmitting its
Configure-Request until Max-Configure is reached. With the default
settings that is ten retransmissions three seconds apart, so bringing
up the link is delayed by half a minute for every protocol the peer
does not implement.

Returning NET_DROP also makes the generic dispatcher in ppp_fsm_input()
fall through to its default branch, which answers with a Code-Reject.
Code 8 is a perfectly valid LCP code, so we reject a packet we are
required to understand.

Read the Rejected-Protocol field and hand the event to the matching
FSM through its proto_reject callback. The callbacks were already
registered by IPCP, IPV6CP and PAP but nothing ever invoked them. As
described in RFC 1661 chapter 4.2, a Protocol-Reject of a network layer
protocol is an RXJ+ event which leaves LCP itself running, so LCP stays
up and the remaining protocols continue to negotiate. Per chapter 5.7 a
Protocol-Reject received outside the LCP Opened state is silently
discarded. Both paths now return NET_OK so that no Code-Reject is
emitted.

Assisted-by: Claude:claude-sonnet-5 Simantic
Signed-off-by: Ahnaf Shahriar <shahriarahnaf007@gmail.com>
2026-09-09 10:41:15 -04:00
Jani Hirsimäki
5fb5c9dcc2 net: dns: gate unscoped mDNS auto-add with Kconfig
Unscoped mDNS servers added by dns_resolve_init_default() collide
with per-interface scoped entries and the mDNS responder on
multi-interface systems (EADDRINUSE on UDP/5353).
Add CONFIG_MDNS_RESOLVER_AUTO_ADD_UNSCOPED (default y). Disable
when mDNS is configured per interface.

Signed-off-by: Jani Hirsimäki <jani.hirsimaki@nordicsemi.no>
2026-09-09 10:41:09 -04:00
Jani Hirsimäki
20daff755f net: dns: fix multi-interface dispatcher pairing on UDP/5353
Refuse resolver/responder pairing on UDP/5353 only when both sides are
scoped to different interfaces. Same ifindex still pairs; if either side
is unscoped (ifindex 0), pairing is kept.

Suggested-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Signed-off-by: Jani Hirsimäki <jani.hirsimaki@nordicsemi.no>
2026-09-09 10:41:09 -04:00
Benjamin Cabé
758d333c3e net: sockets: read snd/rcv timeout without taking the context mutex
Every blocking send and recv fetched SO_SNDTIMEO/SO_RCVTIMEO through
net_context_get_option(), which takes the per-context k_mutex and runs a
25-case switch just to load a single k_timeout_t that the sockets layer
owns.  The per-socket fd mutex already serializes these hot paths
against setsockopt(SO_SNDTIMEO/SO_RCVTIMEO), so the extra context lock
protects nothing for socket API users.

Read the timeout directly from the context options with small static
helpers instead.  getsockopt()/setsockopt() and external net_context
users keep going through the locked accessor.

Measured with callgrind on native_sim/native/64 (UDP loopback, 32-byte
datagrams): zsock_sendto_ctx() drops from 9955 to 9559 instructions per
call (-4.0%) and kernel mutex work per sendto+recvfrom round drops by
11.6%, i.e. two k_mutex lock/unlock pairs less per round trip.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Assisted-by: Claude:fable-5
2026-09-09 10:41:01 -04:00
Jukka Rissanen
d570d5a31e net: websocket: Select the SHA-1 algorithm the client uses
The Websocket client computes the Sec-WebSocket-Accept hash with
PSA_ALG_SHA_1, but WEBSOCKET_CLIENT asked PSA for SHA-256, which the
library never uses. In a build that enables the client and nothing else,
psa_hash_compute() then returns PSA_ERROR_NOT_SUPPORTED and
websocket_connect() fails with -EPROTO before the handshake is sent.
The websocket_client sample is affected as shipped.

The wrong algorithm came in when the client moved off the legacy Mbed
TLS crypto API and "select MBEDTLS_SHA1 if MBEDTLS_BUILTIN" was
replaced. HTTP_SERVER_WEBSOCKET selects SHA-1 itself, which is why
builds that pair the client with the server were unaffected.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-09-09 10:38:45 -04:00
Johan Hedberg
7bb94f0fa1 Bluetooth: host: Use the HCI packet helpers for commands
Build the HCI command packet prefix in bt_hci_cmd_send() with
bt_hci_pkt_push_cmd_hdr(), and decode Command Complete and Command
Status events in hci_cmd_complete() and hci_cmd_status() with the
corresponding pull helpers, instead of open-coding the same encoding
and decoding.

Besides removing the duplication, this exercises the helpers with the
Host's own command traffic, and it settles two edge cases. A Command
Complete whose return parameters lack the status they start with had
that status read from past the end of the event; the helper now reports
it with BT_HCI_ERR_UNSPECIFIED as the status, so the command fails and
its sender gets an error instead of the command timeout, while
Num_HCI_Command_Packets is still honoured and the command flow keeps
going. The Command Complete event with opcode 0x0000 (a
Num_HCI_Command_Packets update without return parameters) no longer has
a status byte read from past its parameters either.

bt_hci_cmd_send() now also releases the buffer when the header cannot
be pushed, as it does on its other failure paths; before, a buffer
rejected for insufficient headroom stayed referenced.

Assisted-by: Claude:claude-fable-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-09 10:38:37 -04:00
Johan Hedberg
8148680ac2 Bluetooth: Add HCI packet helpers
Add hci_pkt.h, stateless helpers for framing HCI command packets and
parsing the events that carry command responses, operating on
net_buf_simple buffers and on packet bytes, implemented in
subsys/bluetooth/common and built into every Bluetooth build (the
library is static, so unused helpers cost nothing).

The helpers are independent of the Bluetooth Host and of the HCI driver
interface, and usable in any build type. The intended users are the
Host itself and HCI drivers that need to exchange HCI commands with the
controller over their own transport, typically for vendor-specific
controller initialization. Today such drivers either call Host command
APIs like bt_hci_cmd_send_sync(), which are unavailable in
controller-only builds, or duplicate the command construction with raw
buffers.

The helpers keep the Host's encoding conventions: parameters are built
and decoded with the packed structures of hci_types.h and the
net_buf_simple API, the encoded length is the buffer length, and the
header push derives the parameter length from it. BT_HCI_PKT_CMD_DEFINE()
provides a command buffer with headroom for the packet prefix reserved.
A Command Complete for a command whose return parameters lack the
status they start with is reported as -ENODATA with the rest decoded
and BT_HCI_ERR_UNSPECIFIED as the status, so that callers can fail the
command instead of guessing.

Add a unit test covering framing and parsing, including the Command
Complete event with opcode 0x0000, which carries no return parameters,
the status-less Command Complete and malformed events, building the
implementation file directly so that it stays independent of the
Bluetooth stack, plus the documentation page and release notes entry.

Assisted-by: Claude:claude-fable-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-09 10:38:37 -04:00
Johan Hedberg
7f44a96268 Bluetooth: AVDTP: Do not block the workqueue on buffer allocation
The signalling response PDUs are allocated with K_FOREVER from the
AVDTP buffer pool. The command handlers run in the Bluetooth
workqueue, which is also the context that runs the AVDTP TX processing
that returns the buffers to that same pool, so waiting for a buffer
there cannot make progress. Most of the handlers wait with the
endpoint lock held, which additionally blocks any other user of the
endpoint.

The same applies to the reassembly buffer allocated on the receive
path, which already has an unreachable allocation failure path.

Allocate both without waiting. All the response allocations already
handle the failure by not responding, leaving the remote side to time
out, which is preferable to blocking the whole host.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-09 10:38:10 -04:00
Benjamin Cabé
db946b7f6e net: ethernet: provide ptp clock verifier when PTP_CLOCK=n
net_eth_get_ptp_clock_by_index() is declared __syscall unconditionally
and has an implementation in both arms of the CONFIG_PTP_CLOCK
conditional, but the CONFIG_USERSPACE verifier block sat inside the
PTP_CLOCK=y arm, so with PTP_CLOCK=n the syscall was not dispatched.

Move the verifier block below the conditional so one verifier covers
both arms. No line inside it changes.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Assisted-by: Claude:opus-5
2026-09-09 07:39:52 +02:00
Tyson Jones
8228017471 mgmt: hawkbit: Added TFM_BL2 to hawkbit dependencies Kconfig
If building with TF-M and BL2, BOOTLOADER_MCUBOOT is `n`.
But, TF-M's BL2 is just a wrapper around mcuboot.
Hawkbit should be allowed if BOOTLOADER_MCUBOOT or TFM_BL2 are `y`.

Signed-off-by: Tyson Jones <tyson.jones@lvt.com>
2026-09-09 07:39:28 +02:00
Flavio Ceolin
01613dd6e7 net: sockets: validate the getsockopt optlen pointer
z_vrfy_zsock_getsockopt() dereferenced the userspace optlen pointer
directly, giving a user thread an arbitrary kernel read or causing the
kernel to dereference a null pointer.

Signed-off-by: Flavio Ceolin <flavio@hubble.com>
2026-09-08 19:18:23 -04:00
Emil Gydesen
61e50d01a6 Bluetooth: BAP: Shell: Allow 0 for bap stats
Rename the command to `bap stats` instead of `bap bap_stats`
and allow the value 0 to disable reporting.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-09-08 19:18:05 -04:00
Emil Gydesen
1ff54a9bc1 Bluetooth: BAP: Shell: Change LC3 priority
Change the LC3 priority to be a higher value (lower priority).
The purpose of this is to prioritize the USB thread higher
as that is more sensitive to time than the LC3 thread.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-09-08 19:17:59 -04:00
Yuan Bian
9591898e7b debug: coredump: fix flash header ID validation logic
Header signature checks used &&, so a dump was rejected only when both
ID bytes were wrong. Partial matches such as "C\0" or "\0D" were treated
as valid and could make verify/find/print succeed on garbage data.

Require both 'C' and 'D' in process_stored_dump() and get_stored_dump().

Signed-off-by: Yuan Bian <bianyuan@kylinos.cn>
2026-09-08 19:17:36 -04:00
Jukka Rissanen
abfc798abd net: dhcpv4: Refuse a request from another subnet once
A client that has moved network asks to keep an address the server
cannot give it. RFC 2131 4.3.2 has the server answer that with a
DHCPNAK, and the server does, but it then carries on through the rest of
the handler and sends a second one: the client that is not recognised
gets the refusal it is already being sent.

One message in, two out. A client that reads the second refusal as the
answer to whatever it asked next is then a message behind for the rest
of the exchange.

Return after the refusal, in the init-reboot path where the address
asked for is out of the subnet, and in the renewing path where the
address the client says it holds is. Only the first is reachable today,
because an out of subnet address in the renewing path matches no slot in
the pool and the handler falls out of its own accord; the two are the
same omission and are worth closing together.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-09-08 19:17:08 -04:00
Jukka Rissanen
b5f5f9ad2e net: http: Bound the RX length against the client buffer
client->data_len is the number of unread bytes in client->buffer, but
nothing checks it before the buffer is addressed with it. A data_len
larger than the buffer makes the memmove() in handle_http_request()
copy out of bounds, and underflows sizeof(client->buffer) -
client->data_len so that the following recv() is handed a near SIZE_MAX
length at a destination past the end of the buffer.

handle_http_data() and handle_h3_bidi_stream() already drop the
connection when the buffer is full, but test for equality, which an
overshot length passes straight through. Compare with >= instead, and
reject an RX state that cannot describe the buffer before the memmove
acts on it.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-09-08 19:17:05 -04:00
Emil Gydesen
2a8d4eabdb Bluetooth: MCS: Clear pending notifications on unsub
If the client removes its subscription to any of the MCS
characteristics at any time, the pending appropriate flags
are now being cleared.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-09-08 16:06:52 +02:00
Jukka Rissanen
f9d512302a net: wifi: mgmt: Derive the neighbor report band from the channel
Building the candidate scan parameters from a neighbor report split the
band at channel 14, so a 6 GHz neighbor was requested as a 5 GHz scan.
Use the shared helper, which knows about the 6 GHz channel numbering.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-09-08 16:06:27 +02:00
Jukka Rissanen
34f24606b9 net: wifi: utils: Add a channel to band conversion helper
Several Wi-Fi drivers need to report which frequency band an interface is
operating on, but only know the channel number. Each one open codes the
conversion, and the copies do not agree: most compare the channel against
14, while one uses 11 and so misreports channels 12-14 as 5 GHz.

Add wifi_utils_chan_to_band(), built on the existing per band channel
validators, so there is one place to get this right. Channel numbers are
ambiguous between the 2.4 GHz and 6 GHz bands, and between 5 GHz and
6 GHz above channel 14, so the lowest matching band is returned. That is
what the open coded conversions already assume. A channel that is not
valid in any band, including 0, returns WIFI_FREQ_BAND_UNKNOWN.

The header did not include the definitions it was already using, and now
also needs the band enum, so pull in wifi.h and wifi_mgmt.h to make it
usable on its own.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-09-08 16:06:27 +02:00
Benjamin Cabé
86981bddd4 portability: posix: remove deprecated POSIX_READER_WRITER_LOCKS
The POSIX_READER_WRITER_LOCKS Kconfig option was deprecated in Zephyr
4.3 in favour of POSIX_RW_LOCKS. It was a plain alias that only did
"select POSIX_RW_LOCKS" (plus "select DEPRECATED") and carried no
semantics of its own, so remove it as part of the 4.5 deprecation
removal cycle.

Applications setting CONFIG_POSIX_READER_WRITER_LOCKS=y must now set
CONFIG_POSIX_RW_LOCKS=y instead; no source code change is required.

Note that only the Kconfig option is affected. The standard POSIX
feature test macro _POSIX_READER_WRITER_LOCKS (leading underscore) and
the _SC_READER_WRITER_LOCKS sysconf variable are untouched.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Assisted-by: Claude:opus-5
2026-09-08 16:06:16 +02:00
Arkadiusz Grzelka
b87b56ff1b net: sntp: reject a precision exponent that would shift past the type
The precision field of an SNTP response is a signed exponent taken
straight off the wire and used as a shift count on a 32-bit value.
Nothing constrains it before that use, so a malicious or simply broken
time server can send an exponent of -32 or below and make the client
shift by at least the width of the type, which is undefined. What the
client then reports as its uncertainty is whatever the compiler and the
target's shift instruction happen to produce.

The upper end of the same expression is already bounded. Bound the lower
end the same way, at the largest exponent that still shifts inside the
type. Nothing is lost by rejecting the rest: 1.5 s shifted right by 31
is already 0 us, so every exponent below that names a precision the
expression cannot represent anyway.

Found with an out-of-tree libFuzzer harness over the socket path that
reaches parse_response(); UBSan reports 'shift exponent 32 is too large
for 32-bit type' at the first shift.

Signed-off-by: Arkadiusz Grzelka <devitwise@gmail.com>
2026-09-08 16:05:55 +02:00
Jukka Rissanen
94d5f463a0 net: http: Advance the output when encoding an HPACK integer
hpack_integer_encode() writes the prefix octet with *buf++, but every
continuation octet with a plain *buf, so they all land on the same byte
and the final octet overwrites the last of them. The length the
function returns counts each one, so the caller moves past a byte that
was never written.

A value below the prefix limit plus 128 needs only one octet after the
prefix and comes out right, which is why this has not been noticed on
the headers a response usually carries. Above that - a response header
string of 255 bytes or more, which needs
CONFIG_HTTP_SERVER_HTTP2_MAX_HEADER_FRAME_LEN raised above its default
for one to fit in the frame at all - the length is encoded wrongly and
one byte of the stack buffer the header frame is built in goes out with
it. The header block is malformed from that field onwards, and in
HTTP/2 an HPACK error takes down the connection rather than the stream.

Encoding a 500 byte header value produced

	1f 10 7f 02 ??

where RFC7541 ch 5.1 asks for 7f f5 02 and ?? is the byte nothing
wrote, and the server's own decoder read the value back as 129 bytes.
Advance the pointer, and the octets are the ones the RFC describes.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-09-08 16:05:36 +02:00
Fin Maaß
c460bbff70 net: core: net_recv_data: check type before assuming it
When DSA is used we still have to check if the iface is
a ethernet one before casting ``net_if_l2_data(iface)``
to ``struct ethernet_context`` and using that.

Also a ethernet iface will always have a non NULL
``net_if_l2_data(iface)``, so change that check to a
assert.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2026-09-08 16:05:09 +02:00
Jamie McCrae
f2a1d086ae bluetooth: host: kconfig: Add missing deprecation text
Adds a missing [DEPRECATED] tag to the Kconfig prompt

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2026-09-08 16:04:16 +02:00
Emil Gydesen
00e55c5c75 Revert "Bluetooth: Host: Fix RPA expire issues for adv"
This reverts commit e55eaf1312ea55f1ad702f35e15a9935814482d0.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-09-08 16:04:02 +02:00
Philipp Steiner
68b7ff8daf net: ptp: report a transmitter change to the port state machine
ptp_clock_handle_state_decision_evt() declared a tt_changed flag but
never assigned it, so ptp_port_event_handle() always received false.
IEEE 1588-2019 9.2.6.11 requires a TIME_RECEIVER port to re-enter
UNCALIBRATED when the selected Time Transmitter changes, and that
transition was therefore unreachable.

Remember the selected transmitter identity and report a change only to
the TIME_RECEIVER port. Preserve the identity across temporary source
loss and local grandmaster operation so the same returning transmitter
does not cause a spurious transition.

Add coverage for changed, reappearing, and temporarily unselected
transmitters.

Signed-off-by: Philipp Steiner <philipp.steiner1987@gmail.com>
2026-09-08 13:39:52 +02:00
Zee Yudenko
65bbb660ac drivers: crc: consistently pass normal-form polynomials to the driver
CRC polynomials can be passed in either normal or reflected form.
Reflected form is only relevant to the software CRC implementation doing
reflected calculation. We pass polynomials given to `crc*` functions
as-is to the drivers, which is incorrect if the polynomial is reflected
(which is the case when the `reflected` argument is `true`, or always in
`crc16_reflect`). Fix this by reflecting the polynomial back before
passing it to the driver. Also, remove hacks in driver code for handling
reflected polynomials. This fix makes the previously-failing
`subsys.crc` test pass on STM platforms. Also, fix uninitialised usage
of `flag_reversed` in `crc4`.

Signed-off-by: Zee Yudenko <zyudenko@internships.antmicro.com>
2026-09-08 13:39:29 +02:00
Juha Ylinen
552c3f8644 net: coap_client: fix observation with blockwise notifications
When observing a resource whose notification body is large enough to be
transferred blockwise (RFC 7959), the client stopped receiving
notifications after the first one.

The registration is made with an observe token T0. To retrieve the
remaining blocks of a notification, coap_client issues Block2 GETs, and
coap_client_init_request() generates a fresh token for each of them,
overwriting internal_req->request_token. While a blockwise notification
is in progress, and again after it completes, request_token therefore
holds a block-retrieval token (T1, T2, ...), not T0. Server-pushed
notifications always use T0, so get_request_with_token() no longer found
the request: the notification was dropped and an RST was sent, which
cancels the observation on the server.

The same overwrite broke coap_client_deregister_observe(), which built
the unobserve GET from request_token and could send the continuation
token instead of T0.

Block2 continuation GETs also re-appended the application's Observe
option, violating RFC 7959 Section 3.4 (only the block-0 notification
may carry Observe).

Fix this by:
- Saving the registration token in observe_token/observe_tkl when the
  observe request is created (including Echo retries).
- Matching responses on either request_token (block-retrieval replies)
  or observe_token (new notifications) for active observations.
- Building unobserve packets from observe_token rather than
  request_token.
- Dropping the Observe option (in addition to the already-dropped
  Block2 option) from Block2 continuation retrievals.

Signed-off-by: Juha Ylinen <juha.ylinen@nordicsemi.no>
2026-09-08 13:38:53 +02:00
Jukka Rissanen
96f2f98a78 net: wifi: shell: Print the IEEE 802.11 status and reason codes
The connection and disconnection result events now carry the raw IEEE
802.11 codes when the driver knows them, so show them. They are what
tells apart an association denied because the access point is full from
one denied because the station is not allowed on it, and reading them
from the shell is the quickest way to find out which of the two is
happening.

Only print a code that is set, and only when the event carried a full
status structure, as not every producer fills them in.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-09-08 13:38:38 +02:00
Jukka Rissanen
5a3a06edfb net: wifi: Carry the IEEE 802.11 status and reason codes
The abstracted connection statuses only name the category of a failure.
For field diagnostics that is not enough: an association denied because
the AP is full and one denied because the station is not on the MAC
filter list both read as a rejected association, and the code that
distinguishes them is thrown away in the Wi-Fi management layer.

Give struct wifi_status somewhere to keep it. Status codes and reason
codes are separate IEEE 802.11 namespaces, carried by different frames,
so keep them in separate members rather than overloading one field with
a discriminator. Zero means the code is not available in both cases, as
reason code 0 is reserved and status code 0 is success.

Producing them needs a raiser that takes the whole struct, so add one
for the connect and the disconnect result event and express the
existing int taking functions in terms of it. Drivers that have no
IEEE 802.11 code to report keep using those and report zeroes.

The status value stays the first member, so receivers that read the
event payload as an int keep working.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-09-08 13:38:38 +02:00
Jukka Rissanen
61641189fe net: wifi: Add authentication and association reject connect statuses
An access point that refuses a station states why in the IEEE 802.11
status code it sends back, but enum wifi_conn_status has no way to say
"the AP said no". Everything that is not a timeout, a missing AP or a
guessed wrong passphrase currently arrives as the generic
WIFI_STATUS_CONN_FAIL, which leaves an application unable to tell a
transient failure worth retrying from a configuration error the user
has to fix.

Add the two categories that cover the frames an AP uses to reject a
station: the Authentication frame and the (Re)Association Response.
The exact IEEE 802.11 status code is left for a following change, so
these two say which frame carried the rejection.

The new values are appended after WIFI_STATUS_CONN_AP_NOT_FOUND, so
the existing ones keep their numbering.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-09-08 13:38:38 +02:00
Jukka Rissanen
e23dde0c52 net: wifi: Send the whole status struct in the AP result events
The AP enable and disable result events notify with a
struct wifi_status but declare the payload as sizeof(enum
wifi_ap_status), while every consumer casts the info pointer back to a
struct wifi_status. The two happen to be the same size today, so the
mismatch is invisible, but it stops being invisible the moment the
struct gains a member: the receiver would read the new fields from
whatever the event queue happened to hold.

Declare the size of what is actually sent.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-09-08 13:38:38 +02:00
Alex Ciascai
5c25ce6230 Bluetooth: MPL: add Media Player Name setter API
Add a proper Media Proxy API for setting the local
Media Player Name and expose it through the media
player callback interface.

Signed-off-by: Alex Ciascai <alexandru.ciascai@nordicsemi.no>
2026-09-08 11:12:35 +02:00
Jamie McCrae
504aea5551 dfu: img_util: flash_img: Allow non-secure slot upload
Allows uploading to slot1_partition when there is a non-secure
image running that is not built to support split updated

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2026-09-07 21:08:05 -04:00