The A2DP code used a hardcoded `BT_A2DP_MAX_IE_LENGTH` of 8 bytes for
codec information elements. For the case that the received IE length
exceeds `BT_A2DP_MAX_IE_LENGTH`, the received data will be truncated
while the IE length is not reduced accordingly. It leads to the IE
length is inconsistency with the codec information elements. It may
lead to problems such as data accessing outside of bounds.
Replace the hardcoded constant with a new Kconfig option
`CONFIG_BT_A2DP_CODEC_MAX_IE_LEN` (default 8 bytes) that allows users
to configure the maximum codec IE length based on their needs. The
valid range is 4-253 bytes, where 4 is the minimum for mandatory SBC
codec and 253 is the maximum allowed by the LOSC length field.
Add validation checks to reject codec IEs that exceed the configured
maximum length, preventing buffer overflows. Remove the previous silent
truncation behavior that could lead to incorrect codec configurations.
Add assertions in `bt_a2dp_set_config_cb()` and
`bt_a2dp_stream_config_set_param()` to catch invalid IE lengths during
development. Add parameter validation in `bt_a2dp_stream_config()` and
`bt_a2dp_stream_reconfig()` to reject invalid configurations at
runtime.
Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
start_announce() (fired on NET_EVENT_IPV4_DHCP_BOUND) set do_announce =
true unconditionally, before the RFC 6762 probe (0-250ms scheduling
delay, then a 1.75-3s window) had a chance to complete. do_init_listener()
branches on do_announce to decide whether to call init_listener() at all
-- since DHCP binding always races ahead of the probe, init_listener()
never ran on any boot with CONFIG_NET_DHCPV4 + CONFIG_MDNS_RESPONDER_PROBE
both enabled.
Gate start_announce() on init_listener_done: the very first successful
init_listener() call already announces via its own trailing call to
announce_start(), so this DHCP-bound path is only needed for re-announces
after the listener is already up (lease renewal, etc), not the first boot.
Test: tests/net/lib/mdns_responder_probe/ reproduces the exact race
(net_if_ipv4_addr_add() immediately followed by a NET_EVENT_IPV4_DHCP_BOUND
notification, no delay in between, mirroring dhcpv4_handle_msg_ack()'s real
sequence) and confirms the responder is reachable afterward. Reverting this
fix reproduces the exact -ENOMEM-unrelated failure (responder never becomes
reachable).
Depends on the v4_svc/v6_svc probe-sizing fix in this branch's parent
commit: without it, CONFIG_MDNS_RESPONDER_PROBE fails independently of this
bug (probing itself can't complete), which would make this test fail for
an unrelated reason.
Assisted-by: Claude:claude-sonnet-5
Signed-off-by: Robert Rozelle <rwrozelle@gmail.com>
send_sd_response() always parsed the raw query bytes starting from the
message header, so it only ever matched the first Question in a packet.
avahi and other real-world clients batch several PTR questions into one
mDNS packet, so anything after the first was silently never answered.
Even fixing the offset wasn't enough: those later questions almost
always use DNS name compression pointers (RFC 1035 4.1.4) to reference
earlier questions' labels, and dns_sd_query_extract() has no
compression support at all.
Add dns_sd_query_extract_name(), which parses the already-decompressed,
dot-separated name that dns_unpack_query() produces for each question in
turn (dns_unpack_query() already follows compression pointers via
dns_unpack_name()). send_sd_response() now uses that instead of
re-parsing raw wire bytes from the start of the message, so every
question in a batched, compressed query gets a chance to match. Shared
label-validation logic between the old wire-format extractor and the new
text extractor is factored into a dns_sd_validate_and_assign() static
helper. dns_sd_query_extract() itself is kept (not removed) since it's
still directly exercised by tests/net/lib/dns_sd/.
Tests:
- tests/net/lib/dns_sd/: 6 new unit tests for dns_sd_query_extract_name()
-- basic 3-label, 4-label with instance, too-few-labels, empty-label
(consecutive dots), and two ENOBUFS variants (too many labels, a label
that doesn't fit its buffer).
- tests/net/lib/mdns_responder/:
test_multi_question_compressed_dns_sd_query sends a real 2-question
wire-format packet, where question 2 uses a DNS name-compression
pointer back into question 1's "local" label (mirroring real avahi
traffic), and confirms both questions get separately answered.
Verified as genuine regression tests: reverting this change reproduces a
failure in exactly test_multi_question_compressed_dns_sd_query and no
other test.
Assisted-by: Claude:claude-sonnet-5
Signed-off-by: Robert Rozelle <rwrozelle@gmail.com>
Implement the HID Device profile core:
- L2CAP server registration for CTRL (PSM 0x0011) and
INTR (PSM 0x0013)
- Connection state machine
(DISCONNECTED -> CTRL -> INTR -> CONNECTED)
- Control channel message dispatch (GET_REPORT, SET_REPORT,
GET_PROTOCOL, SET_PROTOCOL, HID_CONTROL)
- Interrupt channel output report handling
- Handshake response generation based on handler return codes
- Virtual Cable Unplug, disconnecting once the PDU has been sent
- Buffer ownership: callee never frees caller-provided buf
- unregister returns -EBUSY if still connected
Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
Assisted-by: Claude Opus 4.6 (1M context)
Add internal header with HID protocol constants, message types,
handshake codes, header encoding macros, and session/device structures
per HID Profile v1.1.2.
Add HID-specific SDP attribute definitions (0x0200-0x0210) to the
public SDP header.
Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
Assisted-by: Claude Opus 4.6 (1M context)
When a TCP upload is started with a report interval but a zero total
duration, "rounds" evaluates to 0, the upload loop never executes and
"periodic_result" is left uninitialized. Its packet_size member is then
copied into the final result.
Reported by the GCC static analyzer
(-Wanalyzer-use-of-uninitialized-value).
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Assisted-by: Claude:claude-opus-5
Use #include <> instead of #include "" to include a header file which path
is not relative to the directory path of the file emitting the #include
directive.
This change was made running scripts/check_quoted_includes.py script
proposed in https://github.com/zephyrproject-rtos/zephyr/pull/112135
with the Linux shell command below and manually selecting the applicable
changes:
$ find subsys/testsuite/ -type f -exec \
./scripts/check_quoted_includes.py -w {} \;
Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
The mutex may not have been initialized when the
disconnected callback was called which would attempt to use it,
if bt_bap_scan_delegator_register was not called first.
Changed to use SYS_INIT to initialize the mutex and k_work.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
The mutex may not have been initialized when the
disconnected callback was called which would attempt to use it,
if bt_mcs_init was not called first.
Changed to use SYS_INIT to initialize the mutex.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
when the socket is shared with resolver and responder, the dns_dispatch()
forwards the arriving message to correct callback depending on whether it
is a query or response message but it was passing the wrong context
when it was forwarding to the paired callback.
Pass the paired context when calling the paired callback instead of the
base dispatcher.
Signed-off-by: Yasas Kahawala <yasasravinda@hotmail.com>
rndis_bulk_out() treats any single 0x00 byte received on the bulk OUT
endpoint as a frame delimiter and skips it unconditionally. When the
total length of an RNDIS data frame is not a multiple of the bulk
endpoint packet size and the last USB packet carries a single 0x00
payload byte, that genuine payload byte is dropped.
Dropping the byte leaves the in-progress packet one byte short, so the
frame is never completed. The next transfer is then written into the
still-open packet, the RNDIS header of the following frame is
misparsed, and the receive path desynchronises (observed as repeated
"Error parsing RNDIS header" / "Too small packet len" errors).
Only treat a single 0x00 byte as a frame delimiter when no packet is
currently being assembled (rndis.in_pkt == NULL). While a packet is in
progress the byte is written normally, completing the frame and
keeping the receive stream in sync.
Assisted-by: GitHub Copilot: Claude Opus 4.8
Signed-off-by: Ram Pingle <RamPingle@eaton.com>
Rename the `configured` and `qos_set` callbacks of
`struct bt_bap_stream_ops` to `codec_configured` and `qos_configured`
respectively, so that the names align with the ASE state machine names
defined by the ASCS specification.
All in-tree users (host implementation, shell, samples and tests) have
been updated accordingly, including the local callback function names
that mirror the operation names.
Assisted-by: Copilot:claude-opus-4.8
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
INIT-REBOOT and REQUESTING shared a single retransmit arm in
dhcpv4_manage_timers() capped at DHCPV4_MAX_NUMBER_OF_ATTEMPTS (3) with
4/8/16 s backoff, so an unanswered INIT-REBOOT took ~28 s to revert to
DISCOVER. On a network change the interface commonly re-enters
INIT-REBOOT for the previous lease, and many access points silently
drop the foreign-subnet REQUEST rather than NAKing it, leaving the
client stuck for the full schedule before it can bind on the new
network.
RFC2131 3.2 frames INIT-REBOOT as an optimistic abbreviated probe.
Give it its own tighter cap, configurable via
CONFIG_NET_DHCPV4_INIT_REBOOT_ATTEMPTS (default 1), and split it into a
dedicated arm so it falls back to DISCOVER quickly. Combined with the
attempts reset and the removal of the initial random delay, a network
change now recovers in a few seconds instead of 25-35 s. To turn the
optimistic probe off entirely, disable CONFIG_NET_DHCPV4_INIT_REBOOT.
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
The RFC2131 4.4.1 random 1-10 second startup delay exists to
desynchronize the initial DHCPDISCOVER of many clients booting at once.
dhcpv4_start_internal() applied it unconditionally, including when
entering INIT-REBOOT. An INIT-REBOOT re-REQUEST of a previously leased
address is an optimistic fast probe (RFC2131 3.2) with no desync
concern, so the delay is pure dead time; on a network change it just
postpones the eventual fall-back to DISCOVER by up to 10 seconds.
Restrict the random delay to the INIT state so INIT-REBOOT sends its
first REQUEST immediately.
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
dhcpv4_start_internal() moves the client into INIT or INIT-REBOOT and
picks a fresh XID, but never resets the retransmit counter, unlike the
dhcpv4_enter_*() helpers. A normal DISCOVER/REQUEST/ACK cycle leaves
attempts at 1, and an aborted INIT-REBOOT can leave it at the cap, both
of which survive net_dhcpv4_stop()/net_dhcpv4_start(). On the next start
this makes the retransmission backoff begin at 8 s instead of 4 s, or
makes the client fall straight through to DISCOVER on the first timeout.
Reset attempts to zero when (re)entering INIT/INIT-REBOOT so every start
begins with the full, correct retransmission schedule.
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
A Border Router may also act as a Thread-only device when no AIL connection
is present. In that case, the packet forwarding logic is bypassed,
since only a single interface — the Thread interface — is active.
Signed-off-by: Cristian Bulacu <cristian.bulacu@nxp.com>
Use #include <> instead of #include "" to include a header file which path
is not relative to the directory path of the file emitting the #include
directive.
This change was made running scripts/check_quoted_includes.py script
proposed in https://github.com/zephyrproject-rtos/zephyr/pull/112135
with the Linux shell command below and manually selecting the applicable
changes:
$ find subsys/shell/ -type f -exec \
./scripts/check_quoted_includes.py -w {} \;
Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
If RX buffers are not provided on time it may be possible that device
enters disabling phase. Code was attempting to re-enable the UART
immediately when that is detected but it fails if UART is not yet
disabled. If providing next buffer fails then just release that
buffer and wait for UART_RX_DISABLED event. Re-enable UART from
that event.
Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
When assigning incoming packets to the proper interface
or selecting an interface for outgoing packets,
search only among interfaces that are up.
Signed-off-by: Daniel Nejezchleb <dnejezchleb@hwg.cz>
This driver needs the nsi_errno conversion component.
Let's make sure we build it by selecting it.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
The function accessed the instance without taking the mutex.
This also fixes the reporting time in the log from ticks to ms.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
as the iface is in most cases not operational
at that point and we also have ifaces without
autostart, no net init part should require that
the iface is up and therefore we should do that
at the end.
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
send_message() called k_msgq_num_used_get() twice on every mq_send()
only to detect the empty->non-empty edge that fires a registered
notification. Gate both calls on a notification actually being
registered so the common no-notify send path avoids them.
Assisted-by: Claude:opus-4.8
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
stat() called fs_statvfs() before fs_stat(), so every lookup paid a
filesystem-wide free-space scan (O(fs size) on littlefs/FatFs) even for
a path that does not exist. The scan result is only used for the
block-size hint, so run fs_stat() first and return early on failure,
leaving the successful-stat output unchanged.
Also assert in the stat test that the block-size hint stays populated.
Assisted-by: Claude:opus-4.8
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
atomic_set is used to access tx_busy in the irq_write function (in order to
get atomic exchange behavior) so we should also access it atomically here
(even though we don't need atomic exchange behavior here).
Signed-off-by: Phil Hindman <phindman@xes-inc.com>
node is NULL if shell history is empty.
Applying a zero offset to NULL is undefined behavior.
Signed-off-by: Sandro Scherer <sandro.scherer@siemens.com>
In most usage scenarios, the thread id parameter is useful for unwind
subcommand. For example, use the 'kernel thread list' command to
locate the <thread id> of the target thread, then check the call trace
with 'kernel thread unwind <thread id>'.
At least, users should be reminded that this command accepts the
<thread id> parameter to check the call trace of any thread.
Signed-off-by: Chingbin Li <liqb365@163.com>
Use #include <> instead of #include "" to include a header file which path
is not relative to the directory path of the file emitting the #include
directive.
This change was made running scripts/check_quoted_includes.py script
proposed in https://github.com/zephyrproject-rtos/zephyr/pull/112135
with the Linux shell command below and manually selecting the applicable
changes:
$ find subsys/tracing/ -type f -exec \
./scripts/check_quoted_includes.py -w {} \;
Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
cmd.arg's block-count field is 9 bits (bits [8:0]). In block mode
(SDIO CMD53 Block Mode = 1) the field encodes counts 1..511
directly; per spec count = 0 has special meaning ("transfer until
I/O-abort"), not 512 blocks, and 512 itself has no valid encoding.
The previous `cmd.arg |= ... | blocks` had no upper bound, so a
caller passing blocks = 512 (= 0x200) set bit 9 of arg -- the LSB
of the register-address field -- and silently corrupted the target
register. A naive 9-bit mask alone would swap that for a different
silent failure: blocks = 512 would encode as 0 in block mode and
the chip would interpret it as "transfer until aborted".
Reject blocks > 511 with -EINVAL instead. Byte mode (blocks == 0)
is unchanged: in that mode count = 0 correctly encodes 512 bytes.
Callers needing more than 511 blocks must issue multiple CMD53s.
Part of the rpi_zero_2w board enablement series (RFC #109880).
Related parallel work: #110379 (Pi Zero W / BCM2835 / ARMv6).
Signed-off-by: Jonathan E. Peace <jep@alphabetiq.com>
parse_write_op() stored the server selected block size into the block1
context right after calling init_block_ctx(), before inspecting its
return code. init_block_ctx() leaves the caller's pointer set to NULL
and returns -ENOMEM when the block1 context pool (default 3 entries) has
no free or timed out slot, so that store dereferences a NULL pointer.
Move the store below the guard, and validate the context pointer itself
instead of the return code, so the context is only touched once it is
known to be valid regardless of how the helpers report failure.
Signed-off-by: Flavio Ceolin <flavio@hubble.com>
make sure that the checksum field is set to 0, when checksum offloading
is used. In tcp, icmpv4 and icmpv6 it is already done that way.
It is also already done at the openthread border router, if the ethernet
iface supports offloading.
Signed-off-by: Fin Maaß <info@finmaass.de>
The log process thread is what activates multidomain log
links, but if all backends were already initialized,
it would enter a mode where it would block until new
local logs were ready to be processed, even if links
were not yet completed in activation. Change the logic
for computing the timeout used to block the processing
thread so that it stays in periodic polling mode if there
are still log links that haven't finished activating.
Signed-off-by: Mike J. Chen <mjchen@google.com>
Co-authored-by: Wojciech Sipak <wsipak@antmicro.com>
Signed-off-by: Wojciech Sipak <wsipak@antmicro.com>
coap_find_options() bounded its option scan with cpkt->max_len. That
field has two different meanings depending on how the packet was
produced: coap_packet_parse() sets max_len to the actual message
length, but coap_packet_init() sets it to the underlying buffer
capacity. For a packet that was built (rather than parsed), scanning
up to max_len therefore runs past the encoded options and into
uninitialized buffer memory, since a freshly built packet has no
payload marker to stop the walk.
Fixed this by using hdr_len + opt_len, and adding an explicit
"offset < end" loop guard.
Signed-off-by: Carlo Kirchmeier <carlo.kirchmeier.ext@siemens.com>
Adjust coap server behaviour to handle missing OSCORE support
according to specification.
Co-authored-by: Martin Schröder <info@swedishembedded.com>
Signed-off-by: Carlo Kirchmeier <carlo.kirchmeier.ext@siemens.com>
Add RFC 8613 OSCORE support to CoAP server processing.
Introduce OSCORE option handling, public context init/free APIs,
and server integration for request verify/decrypt plus response
protection. Add per-service context provider support, OSCORE-required
service mode (reject unprotected requests with 4.01), and exchange
tracking for deferred response protection.
Add Kconfig/CMake wiring and OSCORE documentation updates.
Co-authored-by: Martin Schröder <info@swedishembedded.com>
Signed-off-by: Carlo Kirchmeier <carlo.kirchmeier.ext@siemens.com>
Header file include/zephyr/sys_clock.h is deprecated and will be removed
someday. Update the whole file tree to include zephyr/sys/clock.h
straight instead of zephyr/sys_clock.h.
This change was made running the sed shell command below:
$ sed -i 's/zephyr\/sys_clock\.h/zephyr\/sys\/clock\.h/' \
`grep -rsl "zephyr/sys_clock\.h" subsys/sensing/`
Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
Header file include/zephyr/sys_clock.h is deprecated and will be removed
someday. Update the whole file tree to include zephyr/sys/clock.h
straight instead of zephyr/sys_clock.h.
This change was made running the sed shell command below:
$ sed -i 's/zephyr\/sys_clock\.h/zephyr\/sys\/clock\.h/' \
`grep -rsl "zephyr/sys_clock\.h" subsys/portability/`
Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
Header file include/zephyr/sys_clock.h is deprecated and will be removed
someday. Update the whole file tree to include zephyr/sys/clock.h
straight instead of zephyr/sys_clock.h.
This change was made running the sed shell command below:
$ sed -i 's/zephyr\/sys_clock\.h/zephyr\/sys\/clock\.h/' \
`grep -rsl "zephyr/sys_clock\.h" subsys/pm/`
Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
Header file include/zephyr/sys_clock.h is deprecated and will be removed
someday. Update the whole file tree to include zephyr/sys/clock.h
straight instead of zephyr/sys_clock.h.
This change was made running the sed shell command below:
$ sed -i 's/zephyr\/sys_clock\.h/zephyr\/sys\/clock\.h/' \
`grep -rsl "zephyr/sys_clock\.h" subsys/net/`
Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
Header file include/zephyr/sys_clock.h is deprecated and will be removed
someday. Update the whole file tree to include zephyr/sys/clock.h
straight instead of zephyr/sys_clock.h.
This change was made running the sed shell command below:
$ sed -i 's/zephyr\/sys_clock\.h/zephyr\/sys\/clock\.h/' \
`grep -rsl "zephyr/sys_clock\.h" subsys/logging/`
Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
Header file include/zephyr/sys_clock.h is deprecated and will be removed
someday. Update the whole file tree to include zephyr/sys/clock.h
straight instead of zephyr/sys_clock.h.
This change was made running the sed shell command below:
$ sed -i 's/zephyr\/sys_clock\.h/zephyr\/sys\/clock\.h/' \
`grep -rsl "zephyr/sys_clock\.h" subsys/bluetooth/`
Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
Remove the !SMP dependency from DEBUG_COREDUMP_MEMORY_DUMP_THREADS and
DEBUG_COREDUMP_THREADS_METADATA so THREADS mode is available on SMP
platforms.
On non-SMP builds DEBUG_THREAD_INFO is still selected, preserving
_kernel_thread_info_offsets for offline GDB thread enumeration. On SMP
THREAD_MONITOR is selected instead: DEBUG_THREAD_INFO is not SMP-safe as
thread_info.c exports K_CURR_THREAD reflecting only cpus[0].current, which
misleads live RTOS debugger plugins on multi-core systems. Document this
limitation in the DEBUG_THREAD_INFO Kconfig help text.
Hold z_thread_monitor_lock while walking _kernel.threads so the list is
stable against concurrent k_thread_create/exit on other CPUs. On
uniprocessor IRQs are already locked, making this a no-op.
Extend the ISR stack dump to all CONFIG_MP_MAX_NUM_CPUS cores instead of
only cpus[0], since a crash can occur in an interrupt handler on any core.
Signed-off-by: Appana Durga Kedareswara rao <appana.durga.kedareswara.rao@amd.com>
zsock_*_cb() stashed the asynchronous error code in net_context.user_data
via INT_TO_POINTER() and read it back with POINTER_TO_INT(). That field is
also used by the stack to carry the parent context pointer passed to the
accept callback, so a failed accept left a small integer where a pointer
was expected. A subsequent interface-down forwarded that stale integer to
zsock_accepted_cb(), which dereferenced it as the parent context,
causing a wild pointer access and kernel fatal error.
Store the pending error in a dedicated net_context.sock_error field
instead, leaving user_data untouched. sock_set_error() now takes the errno
value and sock_get_error() retrieves it, replacing the user_data punning
at all read and write sites.
Assisted-by: Claude:opus-4-8
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
coap_server_retransmit() logs a zsock_sendto() failure and then
unconditionally asserts that the full packet was sent. A failed send is
a legitimate runtime condition, e.g. -ENETDOWN when the network
interface went down while a confirmable message was awaiting ACK;
with CONFIG_ASSERT=y this results in a kernel panic (observed
on an STM32H743-based board right after "PHY (0) is down").
A guard is added so it keeps catching partial sends but tolerates
send errors; the pending entry stays queued and retransmission
resumes on the next cycle until the retry budget is exhausted.
Signed-off-by: Ralph Rooding <ralph@ralphrooding.com>
xoshiro128++ has a fixed point at state = {0,0,0,0} and outputs
zero forever if seeded that way. If an entropy driver reports
success with a zero buffer, sys_rand_get() is poisoned for the
rest of boot.
Accept the seed only if the entropy read succeeded AND the state
is non-zero. On rejection leave initialized=false so the next
sys_rand_get() retries the entropy source.
Signed-off-by: Ofir Shemesh <ofirshemesh777@gmail.com>