Commit graph zephyr/subsys
Author SHA1 Message Date
Jukka Rissanen
6c85d7465a net: zperf: Merge the iperf2 sources into a client and a server file
zperf has a source file per transport and role: a UDP and a TCP
uploader, and a UDP and a TCP receiver. Put the uploaders into
zperf_iperf2_client.c and the receivers into zperf_iperf2_server.c, so
that the file names say which protocol and which end they implement.

The code is unchanged apart from the names the two halves had in
common: the send buffers, the poll arrays and the socket index macros
get a udp_ or tcp_ prefix. Each half is built under the transport it
needs, as the separate files were.

Update the paths in the NXP Wi-Fi driver's code relocation. The
functions it names keep their names.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-09-27 08:54:01 -04:00
Jukka Rissanen
318eafacba net: zperf: Rename receiver locals that clash with a tag and libc
The UDP and TCP receivers hold the session in a local named session,
the same as the struct tag, and the receive time in a local named
time, which the C library reserves. Both are flagged by the coding
guideline checks (MISRA C:2012 rules 5.7 and 21.2). Call them ses, as
the rest of the file does, and now.

Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-09-27 08:54:01 -04:00
Marek Czerski
6f1ab6c070 input: input_double_tap: add optional single tap codes
An application that needs both a single and a double tap from the same
button currently has to use the raw key events to implement that in the
application code. The double tap device does not consume its input, so
a double tap still delivers both of its raw presses, and the
application has to defer acting on a raw press until the double tap
delay has expired, duplicating logic the driver already has.

Add a single-tap-codes property, similar to the optional short-codes
property of input-longpress. When set, a key event is emitted once the
double tap delay expires without a second press.
The event is only emitted if the key has been released before the delay
expired, so that holding a key down does not report a single tap.

Behavior is unchanged for nodes that do not set the new property.

Tested with tests/subsys/input/double_tap on native_sim, and on
nrf52840 hardware with a four button gpio-keys setup feeding both
input-longpress and input-double-tap from the same buttons.

Signed-off-by: Marek Czerski <ma.czerski@gmail.com>
2026-09-26 10:35:14 -05:00
JP Hutchins
c923f3f55b mgmt: mcumgr: transport: smp_udp: bound UDP MTU to the net_buf size
The UDP SMP receive thread copied a received datagram into the SMP
net_buf with net_buf_add_mem() without checking that it fits. When
CONFIG_MCUMGR_TRANSPORT_NETBUF_SIZE is smaller than
CONFIG_MCUMGR_TRANSPORT_UDP_MTU a datagram larger than the net_buf
writes past it; without CONFIG_ASSERT or CONFIG_NET_BUF_HARDENING the
write is silent. The relation was only stated in help text, and that
text was wrong: it allowed the MTU to exceed the net_buf size.

Constrain it in two layers:

- Kconfig: give MCUMGR_TRANSPORT_UDP_MTU a range of
  1..MCUMGR_TRANSPORT_NETBUF_SIZE, matching the SPI transport, and
  default it to the net_buf size when that is below 1500. A build that
  explicitly sets the MTU above the net_buf fails at configuration
  time; a build that only lowered the net_buf keeps building with a
  matching MTU. Fix the help text.

- Runtime: check net_buf_tailroom() before the copy and drop oversized
  frames, matching the Bluetooth transport (smp_bt.c). len is bounded
  by the UDP MTU on every receive path, so this cannot trigger while
  those invariants hold, but it keeps the copy safe if the socket
  layer or net_buf headroom assumptions change.

The default UDP build (net_buf 2048, MTU 1500) is unchanged. Document
the new constraint in the 4.5 migration guide.

Assisted-by: Claude:claude-opus-5-5
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: JP Hutchins <jp@intercreate.io>
2026-09-26 08:40:51 +02:00
Benjamin Cabé
80b30c078d testsuite: capture: guard capture_append on its callers
Every call site sits under CONFIG_PRINTK or the log backend, but the
function itself was unconditional, so a build with neither fails on
-Werror=unused-function. Guard the definition the same way.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Assisted-by: Claude:opus-5
2026-09-26 08:40:06 +02:00
Keith Packard
493601857f subsys/debug: Cast off_t to long in coredump log messages
When logging offsets in the in-memory coredump backend, place explicit
casts to long so that the existing %lu formatting directives work.

Signed-off-by: Keith Packard <keithp@keithp.com>
2026-09-26 08:39:58 +02:00
Yishai Jaffe
db55168d2e net: http: support configuring the max header size
Added HTTP_MAX_HEADER_SIZE to Kconfig so that it's configurable.

Signed-off-by: Yishai Jaffe <yishai1999@gmail.com>
2026-09-26 08:39:49 +02:00
Ugur Sayar
e7a69a1fe7 usb: device: uvc: fix frame interval sort element size
uvc_add_vs_frame_desc() sorts the discrete frame intervals with
qsort(dwFrameInterval, *bFrameIntervalType, sizeof(*dwFrameInterval),
uvc_compare_frmival_desc).

dwFrameInterval is a uint8_t *, so sizeof(*dwFrameInterval) is 1 while
each interval is a packed 4-byte (le32) value. qsort therefore reorders
individual bytes instead of whole intervals, corrupting every entry and
producing an unsorted dwFrameInterval array.

A frame descriptor that enumerates two or more frame intervals then
carries a malformed list. Hosts that require the intervals to be sorted
(e.g. Windows) fail to start the stream: the camera enumerates but
cannot be opened. A camera exposing a single frame interval is
unaffected, which is why this has gone unnoticed.

Pass sizeof(uint32_t) so qsort sorts whole intervals.

Signed-off-by: Ugur Sayar <ugursayar@gmail.com>
Assigned-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-26 08:39:09 +02:00
Erik Bérceš
b5e4f9c29f net: lib: mqtt_sn: don't drop a pinned gateway on ping timeout
process_ping()'s retries-exhausted path dropped any gateway, including
a manually pinned one (adv_timer == -1), leaving a static-gateway
client with no address to ever reconnect to. Only drop discovered
gateways (bounded adv_timer) there; a pinned one can't be re-learned.

Update test_mqtt_sn_ping_timeout to expect the pinned gateway to
survive instead of being removed.

Signed-off-by: Erik Bérceš <erik.berces@nordicsemi.no>
2026-09-26 01:14:10 +02:00
Erik Bérceš
577bac9350 net: lib: mqtt_sn: retry CONNECT if the CONNACK is lost
mqtt_sn_connect() sent CONNECT exactly once with no timeout, so a
single lost CONNACK hung the client forever - no retry, no error,
nothing. Give it the same T_RETRY/N_RETRY handling every other
confirmable message already has, via a new process_connect()
mirroring process_will_topic_update().

The first CONNECT is still sent synchronously, so client->connect is
only touched from one thread at a time; connect.in_progress is
atomic_t, and mqtt_sn_connect() claims it with atomic_cas() before
touching any other state, returning -EALREADY if a CONNECT is
already under way.

Signed-off-by: Erik Bérceš <erik.berces@nordicsemi.no>
2026-09-26 01:14:10 +02:00
Erik Bérceš
631a8ec97e net: coap_server: reply from the correct local address
The CoAP server socket binds to the wildcard address, and replies went
out with the OS picking the source address. On a device with more than
one active address, the OS could pick a different one than the request
was sent to, so a standards-compliant client never matched the reply
and timed out, even though the server had answered correctly.

The server now learns which local address each request arrived on and
replies from that same address, using sendmsg() and IPV6_PKTINFO/
IP_PKTINFO on the socket the request came in on.

DTLS is handled in the mbedtls transport callbacks (dtls_server_rx()/
dtls_tx()) instead of in coap_server_process(). The CoAP thread keeps
using recvfrom() for decrypted records, while the TLS layer captures
the request's local address from PKTINFO on the underlying socket and
attaches it again on sendmsg() so CoAPS replies leave from the same
address the client used.

Offloaded sockets that accept recvfrom() but not recvmsg() now fall
back to recvfrom() instead of failing (coap_service_start() records
whether the PKTINFO sockopt was accepted). NET_CONTEXT_RECV_PKTINFO is
now selected only if NET_UDP.

UDP PKTINFO handling increases stack usage in the socket servicet hread.
Raise the mDNS-specific stack size to prevent an overflow. A 1440-byte
stack covers the measured 24-byte increase, while 1536 provides
additional safety margin for compiler and call-path variation.

Signed-off-by: Erik Bérceš <erik.berces@nordicsemi.no>
2026-09-26 01:13:55 +02:00
James Smith
bcc22a8e3a dfu: img_util: handle RAM load with revert when picking upload slot
flash_img_init() and flash_img_get_upload_slot() only ask the bootloader
for the running slot when CONFIG_MCUBOOT_BOOTLOADER_MODE_RAM_LOAD is set.
With CONFIG_MCUBOOT_BOOTLOADER_MODE_RAM_LOAD_WITH_REVERT they use the slot
fixed at build time, so a device running from slot 1 writes its update
over the running image.

This commit checks both RAM load modes, matching the behavior in
subsys/dfu/boot/mcuboot.c and MCUmgr.

Tested on a pico2 with MCUboot configured with
CONFIG_MCUBOOT_BOOTLOADER_MODE_RAM_LOAD_WITH_REVERT.

Fixes #120157

Signed-off-by: James Smith <james@loopj.com>
2026-09-26 01:12:32 +02:00
Johan Hedberg
8aa1eb1abb Bluetooth: GATT: Ignore Reserved CCC bits in the value cfg_changed gets
The value passed to a CCC's cfg_changed callback is the highest value
any connected peer wrote, Reserved bits included. A peer that sets one
next to the notify bit (0x0005) is then reported as not subscribed by
every callback that compares the value with BT_GATT_CCC_NOTIFY, such as
the Current Time Service's, although a receiver shall ignore Reserved
bits (Core 6.3, Vol 1, Part E, Section 2.4.1). Mask them before taking
the highest value, which leaves the value unchanged for peers that set
none.

The Reserved bit scenario added to the GATT notify bsim test in the
next commit fails without this change.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-26 01:06:31 +02:00
Johan Hedberg
eceb34cd47 Bluetooth: GATT: Track Service Changed when the indicate bit is set
The Service Changed CCC keeps the per-peer entry that records database
changes made while a bonded peer is disconnected only when the peer
wrote exactly 0x0002. A peer that also sets a Reserved bit, which a
receiver shall ignore (Core 6.3, Vol 1, Part E, Section 2.4.1), gets no
entry, so a change made while it is disconnected is never indicated
when it reconnects. Test the indicate bit instead.

The Reserved bit scenario added to the sc_indicate bsim test in the
next commit fails without this change.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-26 01:06:31 +02:00
Johan Hedberg
ed22337558 Bluetooth: GATT: Match the CCC bit when broadcasting
A notification or indication sent to all peers skips every peer whose
stored CCC value is not exactly that procedure's bit. The value is a bit
field: a client may enable both procedures (Core 6.3, Vol 3, Part G,
Section 3.3.3.3), and a Reserved bit that a client sets anyway is to be
ignored (Vol 1, Part E, Section 2.4.1). Such a peer gets no broadcast at
all, while a notification addressed to its connection reaches it, as the
subscription check on that path, bt_gatt_is_subscribed(), tests the bit.
Test the bit here too.

The broadcast scenario added to the GATT notify bsim test in the next
commit fails without this change.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-26 01:06:31 +02:00
Jordan Yates
21f1158d15 net: event: per interface connectivity events
Add variants of `NET_EVENT_L4_CONNECTED` and `NET_EVENT_L4_DISCONNECTED`
that fire for each interface that gains or loses connectivity, instead
of only the first and last.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2026-09-26 01:01:34 +02:00
Benjamin Cabé
378803728c net: lib: mcp: log worker thread ID as a pointer
The health monitor casts the worker's k_tid_t to uint32_t for logging,
which breaks the build on 64-bit targets with -Wpointer-to-int-cast.
Print it with %p instead, like the client pointer next to it.

Assisted-by: Claude:opus-5.5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-09-26 01:00:04 +02:00
Benjamin Cabé
dbe5e34495 cmake: emu: qemu: use -nic for on-board ethernet NICs
QEMU rejects -device for NICs built into the emulated machine (lan9118,
stellaris, cadence_gem), so QEMU failed to start on those boards with
networking enabled. Let these drivers select ETH_NIC_MODEL_ONBOARD and
configure such NICs with -nic instead.

Assisted-by: Claude:opus-5.5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-09-26 00:59:45 +02:00
Benjamin Cabé
060d63f8c8 net: shell: ssh: fix build without CONFIG_SETTINGS
The ssh_key save and load commands use the settings API, but nothing
enables CONFIG_SETTINGS, so NET_SHELL with SSH fails to link. Make
these two commands return -ENOTSUP when settings are disabled, keeping
key generation, import and export usable.

Assisted-by: Claude:opus-5.5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-09-26 00:59:32 +02:00
Jamie McCrae
315b1f0c78 mgmt: mcumgr: grp: os_mgmt: Fix MPSTAT command missing group
Fixes the missing `mpools` map grouping from the output cbor data

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2026-09-26 00:56:35 +02:00
Szymon Janc
fc09be87de Bluetooth: Host: Call bond_delete callback only if bond was deleted
bond_delete callback should only be called if actual bond was present
and deleted. Currently it is being called unconditionally when
bt_unpair is called. Bond present is check by validating if any
key was present, this matches bt_foreach_bond() and also handles
paired, but not bonded connected peers.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2026-09-26 00:49:01 +02:00
Benjamin Cabé
49b63ef0fa net: lib: mcp: only count queued HTTP responses
A response that failed to be queued was still counted in
available_responses, so the counter never returned to zero and every
POST poll kept searching the response queues for nothing.

Assisted-by: Claude:opus-5.5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-09-26 00:47:53 +02:00
Benjamin Cabé
d4518c8e04 net: lib: mcp: accept concurrent HTTP connections
The HTTP_SERVICE_DEFINE() arguments were shifted, limiting the service
to one connection and passing 10 as the service detail. MCP clients
keep their POST connection open while opening a GET stream on another
one, which then stalled. Use the same arguments as other HTTP services.

Assisted-by: Claude:opus-5.5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-09-26 00:47:53 +02:00
Benjamin Cabé
c0e5ac359a net: ssh: Fix SSH shell backend Kconfig dependencies
SSH_SERVER_SHELL_COUNT is used by the SSH shell backend but depended on
SSH_SHELL, so the backend failed to build without NET_SHELL and
DNS_RESOLVER. Make it depend on SHELL_BACKEND_SSH instead, make
SSH_SHELL depend on the backend it calls into, and drop its unneeded
DNS_RESOLVER dependency.

Assisted-by: Claude:opus-5.5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-09-26 00:47:02 +02:00
Antoni Duda
6d69698de7 usb: device_next: cdc_acm: tx throughput improvements
Implements tx throughput improvements by storing data in net_bufs
allocated from per instance buf pool instead of copying the data through
ringbuf.

Signed-off-by: Antoni Duda <antoni.duda@nordicsemi.no>
2026-09-26 00:46:41 +02:00
Benjamin Cabé
0404e3cc00 net: ip: nat: Return rule index from net_ipv4_table_rule_add()
The API documents a non-negative rule index on success, which is what
net_ipv4_table_rule_del() takes, but 0 was always returned. Return the
allocated index, fix the shell error check and test deleting by it.

Assisted-by: Claude:opus-5.5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-09-26 00:42:25 +02:00
Benjamin Cabé
8ff046d5e5 net: lib: mcp: don't clean up a completed tool call twice
A tool that sends its final response and then returns an error had its
request cleaned up by both paths, wrapping active_request_count and
rejecting every later tools/call from that client. Only release what is
still pending.

Assisted-by: Claude:opus-5.5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-09-26 00:40:24 +02:00
Benjamin Cabé
f46e23cb21 net: lib: mcp: support HTTP DELETE to terminate sessions
Let clients end their session with DELETE, as the streamable HTTP
transport recommends, instead of holding a client slot until the idle
timeout. Pending tool executions now keep a client reference, so a
session terminated while a tool runs is only released once it completes.

Assisted-by: Claude:opus-5.5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-09-26 00:40:24 +02:00
Benjamin Cabé
817c55d919 net: lib: mcp: return 404 for unknown HTTP session IDs
The streamable HTTP transport requires a 404 for requests carrying an
unknown or terminated Mcp-Session-Id, which tells clients to start a new
session. Return 404 instead of 400 there, and keep 400 for requests that
lack the header.

Assisted-by: Claude:opus-5.5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-09-26 00:40:24 +02:00
Aiden Hu
16057e0364 usb: host: hub: implement usb host hub class
Add usbh_hub to enable connecting USB hubs and managing
downstream devices through multi-tier hub topology.

The host hub implements two state machines for hub lifecycle.
The hub state machine handles hub enumeration, descriptor
retrieval, and port power configuration. The port state machine
manages device connection detection, port reset sequences, device
enumeration coordination, and disconnection handling.

Hub status changes are monitored through interrupt endpoint with
automatic transfer resubmission. The implementation supports recursive
hub topology with configurable chain depth limits. When a hub is
removed, all downstream devices and child hubs are recursively
disconnected to maintain topology consistency.

This builds upon Chapter 11 control requests to provide complete
hub class driver functionality in usbh_hub.c and usbh_hub.h.

Co-authored-by: Mark Wang <yichang.wang@nxp.com>
Signed-off-by: Aiden Hu <weiwei.hu@nxp.com>
2026-09-25 11:02:01 -05:00
Aiden Hu
ce6a4a5cb5 usb: host: return int from usbh_device_connect()
Change usbh_device_connect() return type from void to int so callers
can detect enumeration failure. The function already frees udev on
failure; callers can now act on the error code instead of using a
freed pointer.

Signed-off-by: Aiden Hu <weiwei.hu@nxp.com>
2026-09-25 11:02:01 -05:00
Aiden Hu
7881496933 usb: host: introduce chapter 11 hub control requests
Move hub control requests from usbh_ch9 to new usbh_ch11 files
to align with USB 2.0 specification structure. Chapter 11 defines
hub-specific requests which are distinct from the general USB
device requests in Chapter 9.

The new implementation provides all hub and port control requests
defined in the specification, including feature control, status
queries, and descriptor retrieval. This provides the foundation
for the hub class driver implementation.

Signed-off-by: Aiden Hu <weiwei.hu@nxp.com>
2026-09-25 11:02:01 -05:00
Aiden Hu
6911c20aa0 usb: host: set level value for the first USB device
when the first device is attached, its level should be
set as 1.

Signed-off-by: Aiden Hu <weiwei.hu@nxp.com>
2026-09-25 11:02:01 -05:00
Benjamin Cabé
e62525f56e usb: device_next: simplify the endpoint bitmap helpers
The bitmap maps OUT endpoints to bits 0 to 15 and IN endpoints to bits
16 to 31, but every helper rediscovered that mapping, and both walks
over a whole bitmap iterated indices 1 to 15 testing the IN and the OUT
bit separately.

Add usbd_ep_bm_bit() and usbd_ep_bm_get_first() and build on them.
unassign_eps() becomes three bitmask operations and no longer needs
uds_ctx. usbd_interface_shutdown() loops over the lowest set bit, as
usbd_ep_disable() clears the bit whenever it succeeds.

Both walks now cover the control endpoint bits that the index-ordered
loops skipped, but assign_ep_addr() only hands out indices 1 to 15, so
those bits are never set. Endpoints are disabled in ascending bit order
rather than interleaved per index, and unassign_eps() reports the
lowest offending endpoint without partially clearing what it already
processed. That error path is unreachable, as assign_ep_addr() always
sets the class and the configuration bit together.

Saves 96 bytes of ROM in a cdc_acm build for nrf52840dk/nrf52840.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Assisted-by: Claude:opus-5
2026-09-25 10:02:23 +02:00
Måns Ansgariusson
e6161ef3ad debug: add granular per-file assertions (ZASSERT)
Introduce ZASSERT, a self-contained assertion facility configured per
source file through a named module rather than the single global
CONFIG_ASSERT switch.

A file selects its module with ZASSERT_MODULE(); the level is resolved
from CONFIG_ASSERT_MODULE_<MODULE>_LEVEL and may be overridden per file.
Modules are defined with the Kconfig.template.assert template, which takes
module/module-str inputs following the logging template convention.
The four levels are:
- Off (compiled out)
- Terse (check only)
- On (check + location only)
- Verbose (Check, location, condition and message)

Since the level is known at compile time, disabled assertions are folded
away by the compiler, and below Verbose the optional message and its
arguments are as well.

zassert provides a set of __weak overridable hooks:
- zassert_fail() - called when an assertion fails
- zassert_vprint() - called to print the assertion failure message
- zassert_post_action() - the terminal action after an assertion failure

CONFIG_ASSERT remains the master switch. The assert Kconfig moves from
subsys/debug to lib/os/zassert, the legacy CONFIG_ASSERT_* symbols are kept
but deprecated (mapped onto the DEFAULT module), and lib/os/assert.c is
removed. The __ASSERT() family is preserved as a thin compatibility shim
over the DEFAULT module, so existing call sites keep working unchanged.

Signed-off-by: Måns Ansgariusson <mansgariusson@gmail.com>
2026-09-25 10:01:43 +02:00
Måns Ansgariusson
5d970607e6 sys: assert: remove the experimental CONFIG_ASSERT_CUSTOM_HEADER
CONFIG_ASSERT_CUSTOM_HEADER let an application inject a
"zephyr_custom_assert.h" at the end of <zephyr/sys/__assert.h> to extend
the assert macros at the preprocessor level. It has always been
experimental and explicitly warned that the internal assert API may change,
so it is removed without a deprecation period, per the experimental API
policy.

Applications that need to customize assertion handling should override the
weak assert hooks instead.

Remove the Kconfig option, the __assert.h include hook and the
assert_custom_header test.

Signed-off-by: Måns Ansgariusson <mansgariusson@gmail.com>
2026-09-25 10:01:43 +02:00
Hsiu-Chi Tsai
8c2bb86f15 net: dns: add dns_resolve_is_active()
Code outside the resolver that needs to know whether a context is usable
compares ctx->state against DNS_RESOLVE_CONTEXT_ACTIVE, an enum the
header keeps in an INTERNAL_HIDDEN block. Add an accessor for it, and
bump the API version for the addition.

It reads the state under ctx->lock, the way the rest of the file does,
so like the other calls here it wants a context that dns_resolve_init()
has been called on.

Signed-off-by: Hsiu-Chi Tsai <hctsai@linux.com>
2026-09-24 15:46:55 -07:00
Taha Zarif
af4b150047 Bluetooth: Host: reject invalid identity in OOB lookup
Reject identity handles that are outside the current identity set or refer
to an empty deleted slot before producing local LE OOB data.

Add native_sim coverage for the first unused handle and a deleted non-tail
identity.

Assisted-by: ChatGPT:gpt-5.6-sol
Signed-off-by: Taha Zarif <tahazarif380@gmail.com>
2026-09-24 17:14:58 +02:00
Chris Friedt
2e03a4ac05 posix: profiles: remove duplicate Kconfig option
Remove the duplicate Kconfig option `CONFIG_POSIX_SYSTEM_INTERFACES` in
`subsys/portability/posix/Kconfig.profile` that shadows the option in
`subsys/portability/posix/Kconfig`.

Signed-off-by: Chris Friedt <chris@fr4.co>
2026-09-24 17:13:54 +02:00
Pieter De Gendt
6b95334c1d net: coap_client: Deregister observe with the original request method
coap_client_deregister_observe() hardcoded GET for the deregistration.
That is conformant for observations registered with GET (RFC 7641 is
written entirely in terms of GET) cancellation included, because GET was
the only observable method when it was written. But this client also
allows registering an observation with FETCH, which RFC 8132 permits
("The Observe option can be used with a FETCH request as it can be used
with a GET request"), and there the literal-GET reading breaks RFC 7641
section 3.6's own rules: the deregister request's options MUST be
identical to the registration's (a GET can never match a FETCH
registration), and the server is to "process the GET request as usual";
impossible on a resource that only serves FETCH. Such servers correctly
answer 4.05 Method Not Allowed before ever looking at the Observe
option, and the observation lives on until it times out.

Reuse the stored request's method instead, which degenerates to GET for
GET-registered observations and mirrors the registration for everything
else.

Assisted-by: Claude:fable-5
Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2026-09-24 13:47:56 +02:00
Pieter De Gendt
76b1f3f556 net: lib: coap: client: Recover from truncated responses block-wise
A response too large for the receive buffer initializes the block-wise
receive context so the request is retried with a smaller block size.
The retry only carried a block2 option while the context position was
beyond zero, but after a truncated plain response coap_next_block()
cannot advance the position, as the response holds no block2 option.
The client therefore re-sent the identical request, received the same
truncated response and looped until the exchange lifetime expired.

The context position cannot distinguish an ongoing block-wise receive
from one that has not started, as it is zero in both cases, so track
that state on the request: set it when a response starts or continues
a block-wise receive, clear it when a response ends it, and let the
request builder decide from it whether the request is a continuation
retrieval. The retry after a truncated response then requests block 0
with the configured block size and the server switches to a block-wise
response.

Assisted-by: Claude:claude-fable-5
Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2026-09-24 13:47:46 +02:00
Pieter De Gendt
21da53124b net: lib: coap: client: Verify ETag consistency in block-wise transfers
RFC 7959, sections 2.4 and 2.6, require a client reassembling a
representation from a Block2 transfer to compare the ETag option of
each block when the server provides one. Neither the UDP nor the TCP
CoAP client did so, silently stitching together blocks of different
representations when the resource changed mid-transfer.

Record the ETag option (or its absence) on the first block of a
transfer and compare it on every subsequent block, aborting the
transfer with -EBADMSG through the response callback on a mismatch.
Aborting when the ETag appears or disappears mid-transfer is stricter
than the RFC's minimum, which only mandates comparing ETags that are
present; a transfer mixing tagged and untagged blocks cannot be
verified and is not delivered either. An ETag with a length outside
the valid 1 to 8 byte range is silently ignored: RFC 7252, section
5.4.3, maps an out-of-range option length to an unrecognized option,
stated for requests and applied to responses alike, and section 5.4.1
ignores unrecognized elective options on reception regardless of
direction. The check lives in a new internal header shared by both
clients.

Assisted-by: Claude:claude-fable-5
Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2026-09-24 13:45:13 +02:00
Johan Hedberg
4b61c6b928 Bluetooth: Host: Monitor: fix timestamps of early boot log messages
The monitor log backend registered monitor_ts_get() as the logging
core's timestamp source from its init callback and then passed message
timestamps on to encode_hdr() unconverted, assuming they were already
in the monitor's 1/10th millisecond unit. Backends are however only
initialized once the logging subsystem starts up, which with the
default CONFIG_LOG_PROCESS_THREAD means when the logging thread first
gets to run. Everything logged before that point is stamped by the
logging core's default clock, i.e. the raw cycle counter (or uptime in
milliseconds for cycle counters above 1 MHz), and ends up in btmon in
the wrong unit.

With samples/bluetooth/observer on nrf52dk/nrf52832, where the cycle
counter runs at 32768 Hz, the logging thread does not run before main()
has returned, so the boot banner and all of the Bluetooth
initialization messages are affected and show up 3.2768 times too late:
the banner, logged at 0.3233 s right before bt_enable() sent the New
Index record, carried the timestamp 10595 (its cycle count) and was
displayed at 1.0595 s, 0.74 s after the HCI initialization that
followed it.

Fix this by leaving the logging core's clock alone and converting the
message timestamp through log_output_timestamp_to_us(), which knows
the rate of whatever clock the logging core is using, in
monitor_log_process(). HCI packets keep being stamped by
monitor_ts_get(), which by default derives from the same system timer
as the logging core's clock, so log messages and packets stay on a
common time base. With the fix the banner is displayed at 0.3046 s
against the New Index record at 0.3047 s, and the HW Platform message
falls between the Zephyr Read Version Info command complete event that
produces it and the next command. Also verified on xg24_rb4186c (32768 Hz
cycle counter as well) and on siwx917_rb4338a, whose 180 MHz SysTick makes
the logging core default to uptime in milliseconds: on all three boards
each "Device found" message is stamped within a millisecond of the
advertising report it is logged for. A side effect is that enabling the
monitor no longer changes the timestamp rate seen by all other log
backends, nor overrides a timestamp source registered by the
application.

For the packet timestamps to stay comparable with the converted message
timestamps in every configuration, monitor_ts_get() now follows the
logging core's choice of clock: the real-time clock with
CONFIG_LOG_TIMESTAMP_USE_REALTIME, and the (64-bit) tick counter where a
32-bit cycle counter runs above 1 MHz, since such a counter wraps within
minutes while the messages, stamped with uptime by the logging core, do
not. Verified on siwx917_rb4338a with its 64-bit cycle counter disabled
(CONFIG_CORTEX_M_SYSTICK_64BIT_CYCLE_COUNTER=n, the 180 MHz counter then
wraps every 24 s): a 60 s capture stays monotonic and the messages stay
within a millisecond of their advertising reports throughout. Also
verified with CONFIG_LOG_TIMESTAMP_USE_REALTIME on nrf52dk.

monitor_ts_get() is no longer a log_timestamp_get_t, so it and
encode_hdr() now use a plain uint64_t; the truncation to the 32-bit
wire format stays in encode_hdr().

Assisted-by: Claude:claude-fable-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-24 13:44:48 +02:00
Jukka Rissanen
99b0292822 net: coap: Accept an observer with an empty token
The server keys its observers on the client endpoint and the token of
the registering request, as RFC 7641 section 4.1 says, but it refused to
register one whose token was empty: coap_resource_parse_observe()
returned -EINVAL, and coap_find_observer() would not have found the
observer anyway. RFC 7252 section 5.3.1 makes an empty token a token
like any other, and a client that sends its requests one at a time has
every reason to use one. Such a client got a plain response without an
Observe option, which the RFC permits a server that is unwilling to
observe to send, and was never notified.

Take the empty token as the key it is. coap_find_observer() matches an
observer with no token against an endpoint and an empty token, while a
lookup by token alone still needs a token that says something. Callers
inside the server now pass a NULL token where the token is not known,
rather than a length of zero, which used to mean the same thing: a
reset answering a pending notification is an empty message, so it names
the observer by its address, as before.

Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-09-24 12:07:53 +02:00
Johan Hedberg
709a1b354b Bluetooth: Host: Do not claim to be ready after a failed disable
bt_disable() resets the advertiser pool, stops RX processing, resets
the controller, tears down all connections and purges the command
queue before it asks the HCI driver to close its transport. When that
fails it set BT_DEV_READY again, "to avoid inconsistent stack state",
which is exactly what it produced: a Host that says it is ready on top
of a controller that has just been reset, whose event masks are back at
their defaults, and with its connection bookkeeping gone.

Six in-tree HCI drivers have no close() op at all (h5, psoc6_bless,
sf32lb, siwx91x, stm32wb0 and the generic SPI one), so for them every
bt_disable() took that path and returned -ENOSYS having done all of the
above.

Ask bt_hci_can_close() before anything is torn down, and return
-ENOSYS with Bluetooth left exactly as it was. When a driver that has
the op fails to close, leave the stack not ready: the transport is
still open, so BT_DEV_OPEN is kept, and the only thing left to do is to
call bt_disable() again, which the documentation now says.

Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-24 12:05:28 +02:00
Robert Lubos
0525146735 net: dhcpv4: Pace the restart after a NAK or a decline
A NAK to a renewal entered SELECTING without touching the timer, so the
discover waited for the retransmit the renewal had armed: half of the
time left to T2 or to the end of the lease. The address is already gone
by then, so the client sat without one for that long. Force the timeout
there, as the INIT-REBOOT path already does.

The two restarts a server can drive in a loop wait instead: a NAK to the
request that follows an offer, and a decline of the address the server
just handed out. Both now restart after the ten seconds of RFC 2131 3.1,
where the decline fell straight through to a discover with no wait. The
wait carries up to two seconds of jitter on top, so that a segment of
clients refused at once does not come back in lockstep. Only the request
that follows an offer waits: a NAK in the other two states leaves the
discover the client already has in flight to its own schedule.

Each of these restarts enters SELECTING first, and arms nothing when a
callback on what that raised has taken the client elsewhere.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2026-09-24 12:05:07 +02:00
Robert Lubos
a21e221087 net: dhcpv4: Drop the lease's DNS servers and gateway with the address
Stopping the client and an interface going down removed the DNS servers
learned from the lease, but a NAK to a renewal and an expired lease did
not, so the old network's resolvers stayed configured until a later ACK
happened to carry new ones. Remove them wherever a lease is given up.

The gateway from the router option was not taken back on any of those
paths, and an interface that had left DHCP behind kept routing through
the old lease's router. Give it up too, by putting back whatever the
interface carried before: a gateway set by hand is not DHCP's to take,
and until now an offer without a router option took it anyway. Someone
who replaces the gateway while the lease is held keeps it, and a router
option naming no router installs nothing.

Only an offer the client acts on describes the network it is joining, so
the gateway is given up for an offer that arrives in SELECTING and not
for one a second server sends after the first has been taken.

A reply configures both before the lease is granted, so both go whether
or not one was. A client stopped between the offer and the ACK would
otherwise leave them behind.

Entering SELECTING happens from the packet receive path on a NAK and
from the timer work on expiry, so the teardown now runs there too.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2026-09-24 12:05:07 +02:00
Robert Lubos
ef665b623f net: dhcpv4: Ignore replies while stopped
The UDP receive callback matches any interface, and a reply for a
stopped client still had its options applied, putting back configuration
that stopping had removed, and a NAK entered SELECTING: a state
net_dhcpv4_start() does not act on, on an interface no timer serves. A
NAK for the exchange a restart had just abandoned was enough to leave
DHCP dead on the interface. Drop replies for a stopped client before
their options are applied, and treat a NAK as nothing to restart.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2026-09-24 12:05:07 +02:00
Robert Lubos
a69b5bb44a net: dhcpv4: Remove the leased address on every lease-abandoning path
The client removed the bound address in some of the paths that give a
lease up and not in others. net_dhcpv4_stop() in REBINDING and an
interface going down in RENEWING or REBINDING left it on the interface,
and the following dhcpv4_enter_selecting() then cleared requested_ip,
so nothing referred to the address any more. It stayed preferred with
no lifetime, was picked as source for new connections after a subnet
change, and with a single IPv4 address slot blocked every later lease.

The address is on the interface while the client is in BOUND, RENEWING
or REBINDING, so derive ownership from the state and give up a lease in
one helper. It is called when entering SELECTING, which covers NAK,
lease expiry and every fallback to discover, from net_dhcpv4_stop(), and
when the interface goes down. The removal follows the state change, so
that a callback on it sees the new state, and nothing of the old
exchange is left by then either, so a handler that starts the client
gets one that works.

A callback is free to stop or restart the client from there, so nothing
that has run the teardown carries on by itself. net_dhcpv4_stop() takes
the interface off its list, releases the timer and the event callbacks
shared with it, and announces the stop, all ahead of the teardown, so
that a callback restarting the client finds them the way a client
starting from cold does, and does not have its start announced before
the stop that caused it. The timer work, the NAK paths and the address
conflict carry on only while the client is still where their own
teardown left it. An ACK binds only while the exchange it arrived for is
still the one in progress, and takes back the address it had already
added when it is not. The address the teardown removes is read before
the state change publishes it.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2026-09-24 12:05:07 +02:00
Johan Hedberg
f113b791b2 Bluetooth: ATT: Guard the request retry state with its own option
The retry state in struct bt_att_req and the retry path in
bt_att_encrypt_change() are built whenever CONFIG_BT_SMP is enabled,
although only CONFIG_BT_ATT_RETRY_ON_SEC_ERR ever sets req->retrying.
commit c3c7b54ccf ("Bluetooth: Host: Option for disabling of ATT
auto retry") narrowed the security elevation and that assignment to
the new option but left the fields and the retry code behind the
CONFIG_BT_SMP guard, so a CONFIG_BT_SMP=y
CONFIG_BT_ATT_RETRY_ON_SEC_ERR=n build carries a retry path that can
never run: a flag that is always false and three request fields
nothing ever reads.

Guard them with CONFIG_BT_ATT_RETRY_ON_SEC_ERR, and make retrying a
bool since the bit-field shared its storage unit with nothing.

No functional change: bt_att_req_alloc() zeroes the request, so
retrying was already always false with the option disabled. On
samples/bluetooth/central_hr for nrf52840dk/nrf52840 the disabled
build loses 176 bytes of flash and 36 bytes of RAM, the enabled build
16 bytes of flash.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-24 12:04:48 +02:00