Commit graph zephyr/subsys
Author SHA1 Message Date
Pieter De Gendt
aa8171c704 net: lib: coap: client: support observe re-registration
Add coap_client_reregister_observe(), the refresh counterpart to
coap_client_deregister_observe(): it re-sends an ongoing observation's
GET with the Observe option set to 0 (register) and the same token and
options as the original request, per RFC 7641 re-registration. This lets
a client refresh a server's observation entry - before a Max-Age or a
server-side idle timeout drops it - without tearing the observation down
and re-registering under a new token (which would momentarily create a
second observation and lose notifications in the gap).

A refresh is refused with -EBUSY while a request is still awaiting its
response on the slot (the registration, an earlier confirmable refresh or
a Block2 retrieval of a notification) and from within the slot's response
callback, after which a Block2 continuation may be sent, so it cannot
clobber that request's retransmission state. A refresh that matches no
ongoing observation returns -ENOENT rather than pretending success. A
refresh that cannot be sent leaves the observation intact and disarms the
retransmission it set up. A confirmable refresh whose retries are
exhausted ends the observation with -ETIMEDOUT like any other confirmable
request.

Notifications keep arriving on the observation's token while a
confirmable refresh awaits its ACK. They no longer stop its
retransmission: only the ACK carrying the refresh's message ID does, or
any response once an empty ACK announced a separate response. A
non-confirmable request is never retransmitted and is answered by a NON,
so any response still settles it.

Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2026-09-29 13:36:13 +02:00
Pieter De Gendt
7a35bdf3dd net: lib: coap: client: Repeat request options on observe deregister
coap_client_deregister_observe() sent a GET carrying only Uri-Path and
Observe=1. RFC 7641 section 3.6 requires all options of a deregister,
except ETag, to be identical to those of the registration request. The
server processes the deregister GET as usual, so one that lacks the
registration's Uri-Query or Accept option is answered for a different
resource, or with 4.04, instead of the observed resource's final state.

Re-add the application's options after the path, skipping only Observe,
which is set to 1. The deregister tests register with a Uri-Query and
check that the deregister carries it.

Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2026-09-29 13:36:13 +02:00
Benjamin Cabé
c01afe6ee3 net: ip: ipv4_nat: don't translate traffic to local addresses
A rule whose destination mask matches any address, as a masquerade rule
does, also matched packets addressed to the NAT host itself, so a ping
or a DHCP renewal to the gateway was translated instead of being
delivered locally. Skip new connections to a local address; replies of
tracked connections are still matched first.

Assisted-by: Claude:opus-5.5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-09-29 13:35:08 +02:00
Arkadiusz Grzelka
34436da64b fs: add fs_normalize_path to resolve . and .. textually
Every caller that needs a path in canonical form writes its own logic
for it, because the file system subsystem has no such helper.
Requested in #115895, which notes #81888 as an earlier report of the
same gap.

Add fs_normalize_path(path, buf, len): it collapses repeated and
trailing separators and resolves "." and ".." into buf. Zephyr has no
symbolic links, so nothing is resolved through the file system.

The mount table is not consulted, so the result depends on the string
alone. A ".." that would climb above the leading "/" resolves to "/",
as on a POSIX system. Anchoring it at the mount point instead would
depend on what happens to be mounted: mount points may nest and
fs_get_mnt_point() takes the longest prefix, so with /NAND: and
/NAND:/sub both mounted, /NAND:/sub/../x would have been rejected.

path and buf may be the same buffer: the pass never writes ahead of
what it has read. A buf too small for the result, or for a prefix a
later ".." pops, yields -ENAMETOOLONG.

Fixes #115895

Signed-off-by: Arkadiusz Grzelka <devitwise@gmail.com>
Assisted-by: Claude:claude-opus-5
2026-09-29 13:32:19 +02:00
Jamie McCrae
838ed6c9c1 mgmt: mcumgr: transport: Check network buffer tailroom
Checks how much free space is left in the buffer to prevent
processing invalid packets further

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2026-09-29 10:44:12 +02:00
Kuldeep Dhaka
640cddef06 smp_shell: route SMP responses to the receiving shell backend
The SMP shell transport hardcodes UART backend lookup in TX path,
causing mcumgr responses to always go to UART regardless of which
backend received the request.

Store a pointer to the shell_uart_common context in smp_shell_data
during init and use it in smp_shell_process() to set the TX target.
This allows SMP responses to route back to the correct backend
(UART, CDC-ACM, etc.).

Co-Developed-by: qwen3.6:27b via llama.cpp <assistant@opencode.ai>
Signed-off-by: Kuldeep Dhaka <kuldeepdhaka9@gmail.com>
Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2026-09-29 10:43:32 +02:00
Benjamin Cabé
4cdf3dee3c shell: zyclictest: require a 64-bit cycle counter
It uses k_cycle_get_64() exclusively, which returns 0 when the platform has
none, so it silently reports every sample as an overflow.

Assisted-by: Claude:opus-5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-09-29 10:42:21 +02:00
Pisit Sawangvonganan
d316afe82d shell: use NULL-safe string length helper
Use `z_shell_strlen()` where shell code accepts optional strings or
treats NULL and empty names equivalently.
This removes duplicated NULL checks while preserving explicit pointer
guards before later dereferences.

Assisted-by: Copilot:GPT-5.6 Terra
Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2026-09-29 10:41:27 +02:00
Pisit Sawangvonganan
5d4a592979 shell: apply clang-format to shell_device_internal
Format the device-selection condition in shell_device_internal() with
the repository clang-format configuration so subsequent changes pass
the compliance check.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2026-09-29 10:41:27 +02:00
Aleksandr Khromykh
389797aeb2 bluetooth: mesh: fix rpl store timeout being overridden
CONFIG_BT_MESH_RPL_STORE_TIMEOUT was only honored while no other
storage flag was pending. As soon as a generic flag such as model
data, keys or config was scheduled alongside a replay protection
list flag, the shared work item was rescheduled to the shorter
CONFIG_BT_MESH_STORE_TIMEOUT deadline, and the replay lists got
stored on that shorter deadline too, causing extra flash wear.

Give the replay protection list and solicitation replay list
their own work item so they are always stored on
CONFIG_BT_MESH_RPL_STORE_TIMEOUT regardless of what else is
pending. The replay list invalidated by an IV Index update or
cleared keeps using CONFIG_BT_MESH_STORE_TIMEOUT, as intended.
bt_mesh_rpl_reset() also no longer schedules that store when an
IV Index update leaves the replay list empty.

Assisted-by: Copilot:claude-opus-5
Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
2026-09-29 10:41:11 +02:00
Piter Zhang
372088eb8d logging: fix lost wakeup when attaching the first backend
backend_attached was a plain bool set after giving the wakeup
semaphore. On SMP the log thread can run on another core, observe a
stale backend_attached == false, and park again without processing
the buffered boot messages. The semaphore limit is 1, so no further
wakeup follows, and messages stay unflushed until
CONFIG_LOG_PROCESS_TRIGGER_THRESHOLD is reached.

Make backend_attached an atomic_t and set it before giving the
semaphore, so the woken thread always observes it as attached.

Verified on a quad-core rk3588 board: without the fix boot logs
appeared late or not at all; with it, 100 consecutive boots flushed
all boot logs before the first prompt.

Fixes #118927

Assisted-by: Claude:claude-sonnet-5
Signed-off-by: Piter Zhang <zhangtdvip@163.com>
2026-09-29 10:40:57 +02:00
Yuheng Li
7e2cead6b7 Bluetooth: Classic: AVDTP: skip unknown capabilities when parsing caps
bt_avdtp_parse_capability_codec() left an unrecognised category's LOSC and
content in the buffer, so the next iteration misparsed those bytes and
bailed with -EINVAL, stopping the discover walk.

Skip unknown category content instead, as AVDTP requires receivers to
ignore capabilities they do not recognise.

Found during PTS AVDTP/SRC/INT/SIG/SMG/BI-30-C and BI-36-C (ignore
reserved capabilities) qualification runs.

Assisted-by: DeepSeek:deepseek-flash
Signed-off-by: Yuheng Li <liyuheng@xiaomi.com>
2026-09-29 10:40:47 +02:00
Benjamin Cabé
3484454ac8 scripts: kconfig: hardenconfig: switch to YAML hardening database
Replace scripts/kconfig/hardened.csv with a distributed YAML database.
The CSV format could not carry any explanation for its recommendations,
had no validation (a malformed line was silently dropped), no notion of
profiles, no ownership story, and no way to extend it out of tree.

The database now lives where the code lives: the central
scripts/kconfig/hardening.yaml defines the hardening profiles (plus
rules for top-level Kconfig symbols), and per-subsystem hardening.yaml
fragments next to the relevant Kconfig files carry the rules, so each
rule is reviewed by the maintainers of the code it hardens. Every rule
has a required rationale and optional references, supports exact-value
and integer min/max recommendations (STACK_POINTER_RANDOM is now
'>=100' instead of '==100'), and belongs to a profile: 'base' (memory
protection and inherently insecure features) or 'strict' (extends base
with debug/observability feature removal). The default profile is
'strict', matching the rule set the CSV checked.

hardenconfig is restructured around a serializable HardeningReport
model so results can be consumed programmatically, and gains:

- a Rationale column in the report
- profile selection:
  west build -t hardenconfig -- -DHARDENCONFIG_PROFILE=base
- HARDENCONFIG_SHOW_ALL to also list PASS/NA results
- HARDENCONFIG_STRICT to exit non-zero on failures, for CI use
- HARDENCONFIG_JSON to write machine-readable results, including which
  database file each rule came from
- HARDENCONFIG_EXTRA_SOURCES to layer out-of-tree database files that
  may add profiles/rules and override in-tree ones

The EXPERIMENTAL/DEPRECATED/NOT_SECURE marker symbol detection is
preserved unchanged.

Three CSV entries are intentionally not carried over because they were
redundant: BT_CONN_DISABLE_SECURITY and BT_OOB_DATA_FIXED can only be
enabled together with BT_TESTING, and TIMER_RANDOM_GENERATOR together
with TEST_RANDOM_GENERATOR, all of which the database already
recommends disabling for the same profiles.

Behavioral fix: the CSV's DEBUG_COREDUMP line used '=' instead of ','
and was silently ignored, so CONFIG_DEBUG_COREDUMP was never actually
checked; it now is.

Also add tabulate to requirements-base.txt: hardenconfig has always
imported it, but it was only pulled in via other requirements files.

Assisted-by: Claude:fable-5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-09-29 10:40:32 +02:00
Anu Chandran Lakshmanan
cd3ff38dfe net: wifi: add NAN control operations
Add Wi-Fi NAN control operations for starting and stopping NAN,
setting NAN parameters, updating NAN configuration, and querying NAN
status.

Expose the operations through the Wi-Fi shell and wire them through the
hostap supplicant API used by Zephyr.

Signed-off-by: Anu Chandran Lakshmanan <anuchand@qti.qualcomm.com>
2026-09-28 14:32:23 -04:00
Johann Fischer
470e0dd2c6 usb: device_next: add isochronous transfers to loopback function
Similar to interrupt endpoints, the Linux kernel usbtest driver expects
isochronous endpoints to be in the same interface as the bulk endpoint
by default. This is very experimental and is disabled by default.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2026-09-28 14:32:16 -04:00
Johann Fischer
ccf5ee4a14 usb: device_next: add interrupt transfers to loopback function
Add interrupt transfer support to allow broader testing of Zephyr USB
support. The Linux kernel usbtest driver expects interrupt endpoints to
be in the same interface as the bulk endpoint by default. Move the
interrupt endpoints to first interface and drop everything else.

Rework how the transfers are submitted, and add interrupt transfer
handling.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2026-09-28 14:32:16 -04:00
Johann Fischer
2ca13f90a7 usb: device_next: loopback: lower log level in control request handler
Lower log level in control request handler to LOG_DBG().

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2026-09-28 14:32:16 -04:00
Arkadiusz Grzelka
0652f668c3 net: tftp: reject a filename or mode too long for a request
make_request() copies remote_file and mode with strncpy() bounded to
TFTP_MAX_FILENAME_SIZE and TFTP_MAX_MODE_SIZE, but advanced by their
full strlen(). A long enough name wrote past client->tftp_buf and sent
adjacent memory.

tftp_get() and tftp_put() now return -EINVAL for a remote_file or mode
over those limits, before a socket is opened, so nothing is sent. At
the limit the request goes out unchanged. make_request() also advances
by strnlen() bounded to the strncpy() budget, so it cannot overrun
tftp_buf. strnlen() needs _POSIX_C_SOURCE 200809L.

Tests: make_request() sizes at budget-1 and budget, both at budget and
a short name. At budget+1 tftp_get() and tftp_put() return -EINVAL and
a listener on the server address receives nothing; with both at budget
the whole request arrives. make_request() is made ZTESTABLE_STATIC and
declared in tftp_client.h for the tests.

Suggested-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Assisted-by: Claude:claude-opus-5
Signed-off-by: Arkadiusz Grzelka <devitwise@gmail.com>
2026-09-28 14:31:16 -04:00
Fin Maaß
be77780000 net: if: ethernet: inform iface about new ip address on add/rm
when a IP address is added to a
iface, inform the driver of the iface,
and not only after a join has been send.

The Ethernet L2 no longer registers a multicast monitor for this,
the IP level tells it directly when a multicast address is added
to or removed from an interface. If the device refuses the address,
the L2 group is left again so that a retry reaches the driver, and
the address is not added to the interface.

The helper is only built when the L2 tracks the multicast addresses,
a stub is used otherwise so that builds without native IP still link.

The af_packet tests that drove the multicast monitor by hand are
changed to add and remove the IP multicast addresses instead.

Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Fin Maaß <info@finmaass.de>
2026-09-28 14:31:06 -04:00
Seppo Takalo
52d6c4048d net: l2: ppp: LCP Terminate-Req should produce PPP_DEAD
When remote peer sends LCP Terminate-Req, it should cause PPP
to drop into PPP_DEAD instead of PPP_ESTABLISH.

Since PR #108940 when receiving LCP Terminate-Req, the
state is transitioned to PPP_ESTABLISH.
PPP_DEAD phase is only triggered after CONFIG_NET_L2_PPP_TIMEOUT.
If the carrier is dropped or net_if_down() happens before the timeout,
there is no NET_EVENT_PPP_PHASE_DEAD event at all.

This issue is visible mostly on the PPP modem side, which receives the
LCP Terminate-Req from the client.

Fix the state transitions so that lcp_down() changes phase to PPP_DEAD
if we are terminating or lost the carrier.
This triggers NET_EVENT_PPP_PHASE_DEAD properly from LCP termination.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2026-09-28 10:54:11 -04:00
Seppo Takalo
1e4fafb0bb net: l2: ppp: Restart LCP from the STOPPED state
Allow PPP to restart from STOPPED state as indicated in RFC 1661
See https://www.rfc-editor.org/info/rfc1661/#section-4

The flag is set for all protocols, but effectively only LCP needs it.
When PPP is terminated by the peer, LCP receives Terminate-Request which
transitions it to STOPPING --> STOPPED.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2026-09-28 10:54:11 -04:00
Sylvio Alves
9d6fad5a8a mgmt: add fota_http firmware update over http library
Add a library that downloads a signed image from any HTTP server
and streams it into the MCUboot secondary slot, then lets the
application request the swap, confirm or erase it. Unlike hawkBit
or UpdateHub no management protocol or update server is needed.

Downloads run either on the caller thread or, optionally, on a
library work queue with a completion callback, and can be
cancelled. Redirects are followed, interrupted transfers can
resume with a Range request, and the MCUboot header is checked
after the download with optional SHA-256 and downgrade checks.
Multi-image layouts and https with TLS 1.2 or 1.3 are supported.
A shell command exposes the whole cycle from the console.

Assisted-by: Claude:opus-5
Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2026-09-28 10:53:32 -04:00
Holt Sun
9af1613fc6 pm: fix truncation of the next event tick count
pm_policy_next_event_ticks() and pm_policy_next_custom_ticks() both
report int64_t tick counts, but pm_system_suspend() stored them in
int32_t locals and ticks_expiring_sooner() took int32_t parameters. An
event further out than INT32_MAX ticks therefore truncated, and could
truncate negative: at a 32768 Hz tick rate that is only ~18.2 hours
(INT32_MAX / 32768 = 65536 s) of lead time.

A negative value then either trips the __ASSERT() guards in
ticks_expiring_sooner() or, in a build without assertions, wins the
MIN() and discards the real kernel deadline. In the latter case
pm_policy_next_state() receives a negative tick count, which the
default policy compares against an unsigned min_residency_ticks, so the
loop never breaks and the deepest state is selected while a much nearer
wakeup is still pending.

Widen ticks_expiring_sooner() to int64_t and clamp its result to the
[-1, SYS_CLOCK_MAX_WAIT] range that pm_policy_next_state() accepts, so
the policy hook keeps its int32_t tick parameter while a far future
event can no longer wrap negative and be read as "nothing pending".
kernel/idle.c already relies on the same upper bound when it narrows
z_get_next_timeout_expiry() into _kernel.idle.

Detect "nothing pending" by testing the sign rather than by comparing
against K_TICKS_FOREVER. K_TICKS_FOREVER is ((k_ticks_t)-1) and
k_ticks_t is uint32_t when CONFIG_TIMEOUT_64BIT=n, so at int64_t width
that sentinel promotes to 4294967295 and never compares equal to the -1
the callers actually pass. The same asymmetry is already documented on
SYS_CLOCK_IDLE_FOREVER.

The mismatch dates back to commit 59779ebe4b ("pm: policy: event: use
uptime ticks"), which widened pm_policy_next_event_ticks() to int64_t
without updating its caller.

Signed-off-by: Holt Sun <holt.sun@nxp.com>
2026-09-28 09:38:27 -04:00
Simon Duquennoy
50a1257c04 net: lib: dns: Fix post-CNAME query cancellation
Fix a bug where a device failing DNS resolution get a runtime fault.

The issue is that dns_resolve_cancel_with_name() finds a query
by `query_hash` for cancellation. But internally, the resolve module
updates query_hash as the resolution follows CNAME aliases. As a
result, after one CNAME hop or more, the caller becomes unable to
cancel its own query.

The failure to cancel a DNS query results is serious and leads to
a **use-after-return bug**.

This is because zsock_getaddrinfo() does this:
1. Calls resolve module with a callback user data set to runtime
stack variable ai_state.
2. On timeout, tries to cancels the query then returns. If
cancellation failed, the query is still present in the resolve
module and when it eventually times out, will run the user callback
with data pointed at a now stale stack frame.

This fix keeps track of the original query hash in addition to
the current one, allowing the caller to cancel reliably.

Signed-off-by: Simon Duquennoy <simon.duquennoy@nordicsemi.no>
2026-09-28 07:38:34 -04:00
Jukka Rissanen
825049f2d1 net: sntp: Widen the round trip time to the range it is measured in
rtt_us is int32_t but holds the difference of two microsecond values
that are int64_t, so it overflows once roughly 36 minutes pass between
the request and the response. sntp_recv_response() bounds that with its
poll timeout, but sntp_read_async() has no timeout of its own and takes
whatever the socket service delivers.

The value feeds the single sided path delay, so the truncation lands in
rsp_delay_us. Make it int64_t, matching both the timestamps it is
computed from and the d_us that the same difference is recomputed into
a few lines further down.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-09-28 07:38:21 -04:00
Jukka Rissanen
e81bde63ed net: sntp: Clamp the delay and uncertainty to their result types
sntp_time.rsp_delay_us and uncertainty_us are uint32_t, but are assigned
from signed expressions built out of timestamps the server chose. A
server whose reported turnaround exceeds the round trip the client
measured makes both negative, and the caller gets the wraparound: one
second between the server's receive and transmit stamps reports about
71 minutes of delay and of uncertainty. The upper end is unbounded in
the same way, since root delay and root dispersion reach well past what
a 32-bit field holds.

Clamp both to what the fields can express. A negative result is not
proof of a hostile server, since a system clock too coarse to measure
the round trip produces one for an honest server as well, so clamp
rather than reject the exchange.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-09-28 07:38:21 -04:00
Benjamin Cabé
e2d1337779 net: lib: mcp: take buffer ownership in mock transport
Free sent messages in the mock transport as the send() contract
requires, so tests catch callers that also free them. Run the test
suite with the heap allocator too, which detects such double frees.

Assisted-by: Claude:opus-5.5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-09-28 07:38:09 -04:00
Benjamin Cabé
d8ff5e75c6 net: lib: mcp: fix double free of cancel notifications
The transport send() op takes ownership of the message buffer on
success, but the health monitor freed it anyway after sending a
cancel notification, leading to a double free with the HTTP transport.
Only free the buffer when send() fails, like the other callers do.

Assisted-by: Claude:opus-5.5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-09-28 07:38:09 -04:00
Tom Burdick
15cb1c9b27 tracing: add an ITM backend
Adds a tracing backend that writes trace data to an ITM stimulus port
on Cortex-M mainline parts, where a debug probe can capture it over
SWO or parallel trace. Writes poll the stimulus port and drop data if
it stays full, so a slow or absent trace sink cannot stall the core.
A marker word in the ELF tells a host tool ITM tracing is present and
which payload format it carries.

Signed-off-by: Tom Burdick <thomas.burdick@infineon.com>
2026-09-28 07:37:58 -04:00
Chris Friedt
690caf5800 posix: add a network appliance subprofile
Networked applications typically need the networking interfaces of
PSE53 but not its multi-process, pipe, spawn or sporadic server
interfaces. Add CONFIG_POSIX_AEP_CHOICE_NETAPP, a Zephyr-specific
subprofile that selects PSE52 plus POSIX_NETWORKING, POSIX_RAW_SOCKETS,
POSIX_CPUTIME and POSIX_PRIORITY_SCHEDULING, so that such applications
do not have to pull in the whole of PSE53.

Signed-off-by: Chris Friedt <chris@fr4.co>
2026-09-28 07:37:49 -04:00
Benjamin Cabé
6441676ad5 debug: coredump: do not re-enter coredump() from a nested fatal error
A fatal error raised while a dump is in progress, such as an assertion
in the backend, calls coredump() again and re-enters the backend in the
middle of the dump. On Cortex-M this ends in a lockup. Skip the dump in
that case, and let only one CPU dump at a time.

Assisted-by: Claude:opus-5.5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-09-28 07:37:43 -04:00
Benjamin Cabé
8d41c1c685 debug: coredump: udp: initialize bind address at declaration
GCC warns that bind_storage may be used uninitialized, as its address
is taken before the memset(), which breaks coverage builds using
-Werror. Zero-initialize it at declaration instead.

Assisted-by: Claude:opus-5.5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-09-28 07:37:36 -04:00
Jeff Welder
7b68698aeb mgmt: mcumgr: smp_client: match responses on transport, group and id
smp_client_response_discover() matched a response to a pending command
on the sequence number and operation only. Sequence numbers are eight
bits, kept per client object and wrap, and all clients share one list
of pending commands, so a response could complete an unrelated command:
one from another client object, for another group or command id, or
one sent on another transport. On a device that is both an SMP server
and an SMP client, a peer on the server transport could complete a
client command, for example acknowledge an image upload offset that was
never written.

Only match a pending command that was sent on the transport the response
was received on and that carries the same group and command id. The
Zephyr SMP server and MCUboot serial recovery echo both in every
response, including error responses.

smp_client_single_response() takes the receiving transport as a new
first argument. Its only in-tree caller, smp_process_request_packet(),
passes streamer->smpt.

Tested with the mgmt.mcumgr.smp.client and mgmt.mcumgr.mcumgr.client
scenarios on qemu_x86.

Assisted-by: Claude:claude-opus-5.5
Signed-off-by: Jeff Welder <Jeff.Welder@ellenbytech.com>
2026-09-28 07:36:35 -04:00
Philipp Steiner
dfcd9b5185 net: ptp: rate limit PTP and gPTP clock warnings
Rate limit recurring synchronization diagnostics and clock-operation
failures in PTP and gPTP so persistent timestamp or hardware errors cannot
flood the logs. Keep successful state transitions and bounded outlier
messages unchanged.

Signed-off-by: Philipp Steiner <philipp.steiner1987@gmail.com>
2026-09-28 07:35:33 -04:00
Philipp Steiner
b3f6ce50fb net: gptp: use shared precision timing mechanisms
Use an instance-based common PI controller and initialize precision clock
adapters once during port setup. Leave IEEE 802.1AS state machines,
synchronization timers, source selection, and clock update policy in gPTP.

Signed-off-by: Philipp Steiner <philipp.steiner1987@gmail.com>
2026-09-28 07:35:33 -04:00
Philipp Steiner
a6c9b4430a net: ptp: use shared precision timing mechanisms
Replace the private PI calculation and direct PTP clock operations with the
common PI controller and precision clock adapter. Keep acquisition and step
policy, lock detection, outlier handling, and source policy in PTP.

Signed-off-by: Philipp Steiner <philipp.steiner1987@gmail.com>
2026-09-28 07:35:33 -04:00
Philipp Steiner
bcf2abe20e precision_timing: add reusable timing mechanisms
Add signed nanosecond arithmetic, protocol-neutral clock operations, a PTP
clock adapter, and an instance-based generic PI controller. Keep
synchronization policy in protocol consumers.

Signed-off-by: Philipp Steiner <philipp.steiner1987@gmail.com>
2026-09-28 07:35:33 -04:00
Anas Nashif
c12cbf41a4 ztest: fix Z_ZTEST_IS_NULL for pre-C++11 standards
The C++ overloads of z_ztest_is_null() use nullptr, decltype and a
trailing return type, all of which require C++11. Building with
CONFIG_STD_CPP98 fails, e.g. the cpp.main.cpp98 scenario of
tests/lib/cpp/cxx.

Only use the overloads from C++11 on and fall back to the C
implementation otherwise. Smart pointers comparable against nullptr do
not exist before C++11, so the (void *) cast covers all arguments there.

Fixes commit 89c0f5e8bf ("ztest: use is_null_no_warn() in NULL pointer
assertions").

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-09-28 10:46:42 +02:00
Artem Voinov
be29d083c0 tracing: ctf: guard socket address arguments against NULL
Add NULL checks for sockaddr and addrlen in four CTF socket
hooks, matching the pattern used by accept_exit and recvfrom_exit.

Fixes #117635

Signed-off-by: Artem Voinov <voinov.artem.job@gmail.com>
2026-09-27 09:09:10 -04:00
Anas Nashif
89c0f5e8bf ztest: use is_null_no_warn() in NULL pointer assertions
zassert_not_null() and friends compare the argument against NULL
directly. Once GCC stops suppressing warnings inside macro expansions
this triggers -Waddress whenever the argument is the address of a static
object, an array or a function.

Route the check through is_null_no_warn(), as log_msg.h and the driver
init macros already do. In C++ the (void *) cast does not work for
smart pointer arguments, so use overloaded function templates instead:
raw pointers, arrays and functions decay to a pointer parameter, anything
else comparable against nullptr such as a smart pointer takes a reference
overload, and a literal nullptr or NULL has its own overload. Comparing
inside a function avoids -Waddress the same way, and a non-pointer
argument fails to compile.

Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-09-27 08:54:58 -04:00
Benjamin Cabé
3b3883a8ed net: shell: iptables: select getopt support with NAT
The iptable add command parses its options with sys_getopt_long(), but
nothing enabled SHELL_GETOPT and GETOPT_LONG, so the network shell
failed to build with NET_IPV4_NAT unless an application set them.

Assisted-by: Claude:opus-5.5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-09-27 08:54:21 -04:00
Benjamin Cabé
b6f23d45ac video: frmival: fix overflow in video_closest_frmival_stepwise()
The common denominator was the product of all four denominators in 32
bits, which wraps for values like 1/60, 1/1000 and 1/1000000 and gives
a wrong interval. Use their least common multiple and reduce the result
instead, which gives the same values without overflowing.

Document the -EINVAL and -ERANGE return values, and have
video_closest_frmival() skip the stepwise ranges for which
video_closest_frmival_stepwise() fails.

Assisted-by: Claude:opus-5.5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-09-27 08:54:17 -04:00
Jukka Rissanen
ccfbd018cd net: zperf: shell: Default to the iperf3 port in an iperf3 build
iperf3 uses port 5201 where iperf2 uses 5001. Default to the port of
the protocol the build speaks, also in the help examples, and have
"zperf version" name the protocol.

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
c78f15bde0 net: zperf: Add an iperf3 client
Implement the zperf uploads for iperf3, so that a device can run a test
against a host running "iperf3 -s".

An upload is a whole iperf3 test, and the results the server sends
back fill the server side of the report. For UDP, datagrams lost after
the last one the server received are counted as lost, as in the iperf2
report. iperf3 does not report reordering.

The UDP stream uses the shared rate control, with a wait never running
past the end of the test: at a 100 Hz tick one wait was seen to last
2.7 s of a 1 s test. One upload runs at a time, and multicast and
per-thread sessions remain iperf2 features. With an interface name
given, the control connection and the data stream are both bound to it.

Tested with iperf 3.16 against native_sim with offloaded sockets, TCP
and UDP over IPv4 and IPv6.

Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-09-27 08:54:01 -04:00
Jukka Rissanen
d504923a60 net: zperf: Let the upload socket helper bind to an interface
zperf_prepare_upload_sock() connects the socket it creates, which for
TCP is when the route is chosen, so binding to an interface afterwards
is too late. Give it an optional interface name that is applied before
connecting.

The existing callers pass NULL and are not changed: the UDP uploader
keeps binding its socket itself, and the TCP uploader does not bind.

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
daf8537da1 net: zperf: Add an iperf3 server
Offer iperf3 as an experimental protocol choice, and implement
zperf_tcp_download() and zperf_udp_download() for it, so that a host
running "iperf3 -c" can measure a device. The API entry points call
the iperf3 functions when that protocol is chosen.

An iperf3 client picks TCP or UDP per test and uses one port for both,
so the two download functions share the listening sockets. Each enables
its own protocol, a test for one that is not enabled is refused, and
both must ask for the same port, bind address and interface.

One test runs at a time over one stream. A second client gets
ACCESS_DENIED. Reverse, bidirectional, parallel and omitted-start tests
and SCTP are refused with the error iperf3 prints for an unsupported
option.

The server runs on the socket service thread without blocking it, so
that thread gets a larger default stack: it peaks at 1292 bytes on
qemu_x86. Connections are left for the client to close first, as the
network stack will not bind a new listener over connections still
closing on its port. A test whose client is silent for
NET_ZPERF_IPERF3_IDLE_TIMEOUT seconds is dropped.

The iperf2 session table is not built for iperf3. Uploads return
-ENOTSUP for now.

Tested with iperf 3.16 against native_sim with offloaded sockets, TCP
and UDP over IPv4 and IPv6.

Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-09-27 08:54:01 -04:00
Jukka Rissanen
b004ca828c net: zperf: Add the iperf3 protocol encoding
Add what an iperf3 client and server share: the control channel states
and error values, the test cookie, the JSON parameter and results
messages, the UDP datagram header, and the receive side loss and jitter
accounting, which follows the rules of an iperf3 receiver.

Only the parameters zperf acts on are decoded. When encoding them, a
flag that is not set is left out rather than sent as false, because
iperf3 servers up to at least 3.16 take a flag to be set whenever its
key is present.

Fractional numbers in the results are handled as number text with
integer arithmetic, so no floating point support is needed.

Nothing builds this yet.

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
c19437c149 net: zperf: Move the UDP rate control into its own file
The UDP uploader's rate control is interleaved with the iperf2 header
handling, so another UDP sender would have to copy it. Move it into
zperf_udp_pacing.c and have the uploader call it. The NXP Wi-Fi driver
relocates the compensation helper by file name, so it relocates the
new file instead.

The logic is unchanged. In the icount loopback scenario on qemu_x86 the
two calls per packet cost 0.2% of the UDP throughput, and TCP is within
0.02%.

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
a11b60bbd2 net: zperf: Make the iperf protocol version a Kconfig choice
zperf implements the iperf2 protocol. Put that behind a choice of
protocol version with iperf2 as its only option, so that another
version can be offered without the iperf2 files knowing about it.

The iperf2 upload and receive sources are built only when iperf2 is
chosen, and the legacy UDP header option depends on it. Nothing changes
for existing configurations.

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
c25be98f87 net: zperf: Give the upload and download API one entry point
The public upload and download functions are defined in the files that
implement them, so another implementation of the protocol would have to
define them a second time. Define them once, in zperf_api.c, where they
check their arguments and call the iperf2 client and server, whose
functions get a zperf_iperf2_ prefix.

No functional change.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-09-27 08:54:01 -04:00