Add BT_MESH_LPN_OFFER_WAIT_TIMEOUT to configure how long the Low
Power node listens for Friend Offer messages after sending a Friend
Request. The Mesh Protocol specification section 3.6.6.4.1
recommends up to 1 second, but the optimal value depends on the
deployment, so keep 1000 ms as the default and allow tuning it.
Also introduce a separate FRIEND_CLEAR_TIMEOUT for the Friend Clear
Confirm wait. The specification defines no timeout for it, so it
must not change when the Friend Offer window is tuned.
Assisted-by: GitHub Copilot:claude-opus-5
Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
If the broadcast source was created and started but the handover
still failed, then we should stop and delete the broadcast source.
However bt_cap_initiator_broadcast_audio_stop is not a synchronous
function, and we cannot just stop it directly in the callback.
Instead of offloading that to another thread, we simply instruct
the shell user to manually stop and delete the source (if they
want to).
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
If int bt_cap_unicast_group_create failed then the out
group should not be assigned, but it was.
This commit ensures that on failure, the out group will
point to NULL.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Modify a few places to print the string and numeric values,
instead of just the numeric value.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Add function to convert a bt_audio_dir to a str, similar to
the other _to_str functions audio.h has.
Replaces the internal bt_audio_dir_str function.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
The bt_bap_scan_delegator_set_bis_sync_state did not allow setting
the BIS sync value when the PA sync was not there.
This only makes sense when any of the bis_synced values
are non-zero, and should allow setting it to 0 without
a PA.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
When there is a cp (or search cp) write and we already have
one pending, we should not attempt to send a notification.
If we do, then that notification may arrive at the client
before the notification of the first write request, so the
only thing we can really do is to reject the write.
If the opcode is invalid, we send the notification to the
system workqueue similar to all the other notifications,
which ensures that it is sent, even if we are out of ATT
TX buffers.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
bt_conn_iso.txq is only used for TX; guard with CONFIG_BT_ISO_TX
to optimize memory for RX only builds.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
The socket-service thread temporarily disables a ready poll entry while
running its callback, then re-arms it afterward. The callback may
unregister the service, request deferred close, or change its registration.
Restoring stale poll state can then discard a close request, restore an old
event mask, or poll an unregistered fd again.
Skip ready entries changed by an earlier callback. Re-arm the current entry
only if its registered fd and event mask remain unchanged. The pending
control event rebuilds the poll set for changed entries.
Signed-off-by: Egill Sigurdur <egill@egill.xyz>
Add CONFIG_WIFI_NAN_MAX_SSI_LEN Kconfig option to configure the
maximum NAN Service Specific Info (SSI) payload length. The value
is stored inline in NAN structures; default is 128 bytes to preserve
existing footprint.
Widen ssi_len fields in NAN parameter structures from uint8_t to
uint16_t to support SSI payloads larger than 255 bytes.
Fix wifi_shell.c hex2bin() check: hex2bin() returns size_t and
signals failure with 0, not a negative value.
Signed-off-by: Qingling Wu <qingling.wu@nxp.com>
Some controllers advertise the controller to host flow control
commands in the supported commands mask but reject them, which
fails initialisation when host flow control is enabled. Add a
no-flow-control device tree quirk that makes the host skip the
flow control commands and treat the feature as not supported.
The quirk is a build time constant, so the unreachable flow
control paths are compiled out.
Assisted-by: Claude:opus-4-8
Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
Not all I3C targets support TARGET_BUFFER_MODE
implement support for this mode by providing implenentations
for the byte-by-byte callbacks.
Signed-off-by: James Growden <jgrowden@tenstorrent.com>
Add support for polling mode to perform endpoint
reads for mctp. This allows targets without
IBI support to operate in an MCTP link
Signed-off-by: James Growden <jgrowden@tenstorrent.com>
Enables use of read-only storage for Xtensa by
adjusting linker calculation of relocation address
to work when one or more regions are on the heap.
Remove default to writable storage for Xtensa.
Fixes#75341
Signed-off-by: Lauren Murphy <lauren.murphy@intel.com>
In some contexts, the number of init/fini functions may not be known at
compile time. Allocating a function table is not even needed since it is
only ever used to call the functions in order.
Replace the llext_get_fn_table() syscall with llext_get_fn_table_entry(),
which returns a single function pointer at a time. This allows the caller
to iterate over the functions without needing to allocate a table, and
removes the limit on the number of init/fini functions that can be defined
by an extension.
Also remove the CONFIG_LLEXT_MAX_INIT_FINI_FUNCTION_TABLE_ENTRIES Kconfig
option, since it is no longer needed. This was introduced after 4.4 and
therefore needs no deprecation notice.
Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
cp_decode_response() copies REPLY_KEYPPAD and REPLY_RAW payloads into
64 byte arrays of a stack allocated osdp_event, checking only that the
declared length matches the frame. Bound it by OSDP_EVENT_MAX_DATALEN.
Signed-off-by: Flavio Ceolin <flavio@hubble.com>
Before initializing the metadata update procedure, we perform
a check to see if there are any streams to update.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
If sending the HCI Accept Synchronous Connection Request command fails
in accept_sco_conn(), bt_esco_conn_req() releases the SCO connection
object with bt_sco_cleanup(), but the channel that was attached by
sco_accept() is left with chan->sco pointing to the released
connection object and with its state stuck at BT_SCO_STATE_CONNECTING.
For HFP AG this means that bt_hfp_ag_sco_accept() rejects all
subsequent incoming SCO connections for the session, since
ag->sco_chan.sco is never cleared, and hfp_ag_close_sco() may call
bt_conn_disconnect() with a stale pointer which can alias an unrelated
connection once the object is recycled.
Detach the channel and reset its state before releasing the connection
object. The disconnected callback is intentionally not called since
the connection was never established and the connected callback never
ran.
Assisted-by: Claude:claude-fable-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
The tools/call "arguments" object is tool-specific and cannot be described
statically, so it was pulled from the request with a strstr() search for
"arguments" and a byte-level brace counter. Both are structure-blind: the
search matches the literal text inside any string value, and the counter
balances braces that appear inside string values, so an argument such as
{"filter":"a}b"} is truncated at the in-string '}'.
Walk the params object with json_obj_separate_parse_init() /
json_obj_next_key_value() and hand the tool the raw "arguments" value span
instead. The walker is string- and depth-aware, so braces in string values
no longer break extraction, and the hand-rolled scanner is removed.
Signed-off-by: Paulo Santos <pauloxrms@gmail.com>
The event monitor did not print anything when a packet socket joined or
left a L2 multicast group. A callback only receives an event if the
layer and the layer code of its mask match the ones of the event
exactly, and the mask used for the L2 events only covers the interface
layer code. The packet events have their own layer code, so they were
never delivered and could not be described.
Register a second L2 callback for the packet layer code and print the
multicast address the event carries next to the description.
Assisted-by: Claude:Opus-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
A packet socket could join a L2 multicast group but nothing remembered
that it had. Closing the socket left the group joined, and joining the
same group twice took a reference to it twice.
Keep the memberships in a table of entries owned by the socket that
joined the group. The size of the table is set by the new
NET_SOCKETS_PACKET_MCAST_MEMBERSHIP_COUNT option, no memory is
allocated dynamically. A socket holds one reference to a group in the
L2 no matter how many times it joined it, and joining the same group
several times from one socket needs as many leaves. How many users a
group has in total is counted by the L2, which needs the count for the
receive filter of the device anyway.
The memberships that a socket still holds are dropped when it is closed.
Dropping a group that was not joined fails with EADDRNOTAVAIL and
running out of table entries fails with ENOBUFS.
If the L2 cannot join the group, the entry is given back and the error
is returned to the caller of setsockopt(), so that a group that does not
fit into the receive filter of the interface fails with ENOMEM instead
of looking like it was joined. The L2 is told to leave the group as
well, as it takes the address into use before it programs it and keeps
it if the device refuses.
Assisted-by: Claude:Opus-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
A packet socket can be used to add or drop a multicast group
membership in L2 level. This means that application can ask
the network device to start to listen extra multicast L2 addresses.
This uses PACKET_ADD_MEMBERSHIP and PACKET_DROP_MEMBERSHIP
socket options which can be set using setsockopt() API.
As the same link layer address can be needed by several users at once,
the Ethernet L2 keeps track of the multicast addresses that an
interface listens to and tells the driver to change its receive filter
only when a group is joined by its first user or left by its last one.
The IP level joins, the packet socket memberships and the filters that
an application sets with net_eth_mac_filter() all share this count.
Previously they were given to the driver separately, so leaving one
group could stop the device from listening to another one that needs
the same link layer address. That happens easily as IPv4 multicast
addresses map 32:1 to link layer addresses.
The membership change is given straight to net_eth_mcast_addr_add() and
net_eth_mcast_addr_rm(), so that setsockopt() can tell the application
when the interface cannot serve the group. There is no interface level
callback list in between, as a callback cannot report back that the
address did not fit.
The addresses can be read back with net_eth_mcast_addr_foreach(), so a
driver may also treat ETHERNET_CONFIG_TYPE_FILTER as a hint that the
set of addresses changed and reprogram its filter from scratch. That
suits devices that filter by a hash of the address.
How many addresses an interface can track is the sum of what the
enabled subsystems ask for with their own
NET_L2_ETHERNET_MCAST_FILTER_ADD_COUNT_ options, summed at build time
the same way as the system heap size is. The new
NET_L2_ETHERNET_MCAST_FILTER_COUNT option raises the result if an
application needs more addresses than the subsystems asked for. A
group that does not fit is not joined at all, as programming it
without tracking it would break the drivers that read the addresses
back and the group would be lost as soon as another user of the same
address left.
A device that cannot filter passes the group up anyway, so the group is
joined and tracked also when the driver has no receive filter. The
address is then ready for a filter that the device programs later, and
setsockopt() does not fail on a device that receives the group without
being told to.
A VLAN interface has no receive filter of its own, so a group joined
on one is programmed to the Ethernet interface it is attached to.
Note that a multicast destination address given to net_eth_mac_filter()
is now counted like any other user of the group, so each such filter
that an application sets must also be unset by it, and unsetting one
that was never set fails with -ENOENT.
Assisted-by: Claude:Opus-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
The retransmission and monitor timeout handlers start with an early
return whose comment says "ACL connection is broken". The wording
suggests some sort of failure that would need to be logged or
investigated, whereas the check simply covers the benign race where the
work item runs after the ACL connection has been disconnected. Reword
the comments to describe what is actually going on.
Assisted-by: Claude:claude-fable-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
The BT_HCI_RAW_H4 and BT_HCI_RAW_H4_ENABLE Kconfig options lost their
last code references in commit 26d97164be ("Bluetooth: HCI: Use H:4
encoding for buffers"), which made the HCI raw layer use H:4 packet
encoding for all buffers unconditionally. Since then setting these
options has had no effect.
Remove the option definitions, the stale references in the sample
configurations, as well as a dead conditional default in the
BT_DRV_RX_STACK_SIZE option. Document the removal in the release
notes; since the options have been no-ops for several releases and
were never part of a deprecation cycle, there is no migration to
describe beyond dropping them.
Assisted-by: Claude:claude-fable-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
RFC 1122 ch 3.3.6 says that a frame sent to the broadcast link layer
address must not carry a unicast IPv4 destination address, and
ethernet_check_ipv4_bcast_addr() is supposed to drop such a frame. The
check stopped working when the IPv4 handling was moved behind the
NET_L3_REGISTER() mechanism in commit "net: Extend the protocol handling
in Ethernet".
Before that change the check ran in ethernet_recv() and used the header
pointer that was taken before the Ethernet header was pulled off the
packet. It now runs in ethernet_ip_recv(), which the L3 handler loop
calls after the pull, and which takes the pointer again with
NET_ETH_HDR(). That pointer is the start of the IPv4 header, so the
"destination MAC" compared against ff:ff:ff:ff:ff:ff is really the first
six bytes of the IPv4 header. Those are never all ones for a well formed
packet, so the check never fires and a broadcast frame carrying a unicast
IPv4 destination address is accepted.
Read the destination address from the link address that ethernet_recv()
stored in the packet before the pull instead.
The IPv4 destination address was read with NET_IPV4_HDR() straight out of
the first net_buf, without checking that the header is actually there.
With the MAC check working again that read becomes reachable from the
wire, so fetch the header with net_pkt_get_data() the way
net_ipv4_input() does and drop the frame if it is not available.
Assisted-by: Claude:claude-opus-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
struct dns_resolve_context has a nested struct tagged dns_server whose
first member is also called dns_server. C++ does not allow a member to
share the name of the class that encloses it, as the name collides with
the injected-class-name, so every C++ translation unit that pulls in
<zephyr/net/dns_resolve.h> fails to compile:
error: 'dns_resolve_context::dns_server::<unnamed union>::dns_server'
has the same name as the class in which it is declared
The struct used to be anonymous and therefore had no injected-class-name
to collide with. It was given the dns_server tag in commit
1eb4a709e8 ("net: dns: Allow using resolver and responder at the same
time") so that the reply handler could recover the server entry with
CONTAINER_OF(), which is the only thing the tag is used for.
Rename the tag to dns_server_info rather than the member. The member is
what applications actually reference, and the anonymous union it sits in
exists precisely to keep those references working, whereas the tag was
never meant to be part of the API. Nothing else in the struct changes,
so ctx->servers[i].dns_server and ctx->servers[i].dns_server_addr are
untouched.
Assisted-by: Claude:claude-opus-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
send_data() logs the packet length, which is a size_t, using %u. That
is only correct where size_t is unsigned int, so building for a 64 bit
target warns, and the warning is fatal in CI:
format '%u' expects argument of type 'unsigned int', but argument 3
has type 'size_t' {aka 'long unsigned int'}
This went unnoticed because nothing in tree builds the TFTP library for
a 64 bit target. The two users of CONFIG_TFTP_LIB, the tftp_client
sample and tests/net/all, both restrict themselves to 32 bit platforms.
Assisted-by: Claude:claude-opus-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
MISRA C:2012 Rule 8.2 requires every parameter in a function type to be
named, including the parameters of function pointer parameters.
scandir(), pthread_create() and pthread_key_create() declared their
callback parameters with bare types, in both the headers and the
implementation.
Name them after the arguments the documentation or the
definitions already use. No functional change.
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
There was a missing check for when both of them were NULL,
and passing NULL to both would have resulted in an ASSERT.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Add LOG_DBG for missing CIG param checks to make it easier
to see exactly what check may reject the parameters.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
ztest_test_fail() does not necessarily terminate the caller: the
multithreading implementation just records the result and returns for
some test phases. Both z_ztest_check_expected_value() and
z_ztest_get_return_value() then dereferenced the NULL parameter they had
just failed to find. Return early, as z_ztest_check_expected_data()
already does.
Reported by the GCC static analyzer (-Wanalyzer-null-dereference).
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Assisted-by: Claude:claude-opus-5
Commit 22896cb8d6 ("Bluetooth: Host: Route LE host work items to the
Bluetooth workqueue") moved conn->deferred_work to the dedicated
Bluetooth workqueue, but two producers were missed and still schedule
it with plain k_work_schedule(), which targets the system workqueue:
the peripheral connection parameter update retry path in hci_core.c,
and the ISO path that retriggers the deferred work to finalize an ACL
disconnection once the last CIS reference is gone.
When either of these fires, the deferred work handler - including
disconnected() callback delivery and the connection teardown chain -
runs on the system workqueue, contradicting the documented v4.5
context change and breaking the same-queue property that makes the
non-blocking cancellations of this work item safe.
Use bt_work_schedule() in both places so that every producer of
conn->deferred_work targets the Bluetooth workqueue.
Assisted-by: Claude:claude-fable-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
wifi_nm_unregister_mgd_iface() cleared mgd_ifaces[].iface but left
mgd_ifaces[].type set. wifi_nm_register_mgd_iface() claims a free slot
without assigning type, so an interface registered through that API
into a recycled slot inherited the previous interface's role bits, and
wifi_nm_iface_is_sta() or wifi_nm_iface_is_sap() could report a role
that interface never declared.
Signed-off-by: Hui Bai <hui.bai@nxp.com>
filter_get() and filter_set() bounded source_id with __ASSERT_NO_MSG alone,
which compiles out at CONFIG_ASSERT=n. The multidomain backend passes a
source_id straight out of an IPC message from another domain, which then
indexes the dynamic filter table.
Assisted-by: Claude:claude-opus-5
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
sha256sum is an optional JSON string field on a zero-initialised struct, so
a server response omitting it left the pointer NULL and strlen()
dereferenced it before the length check. Both metadata branches.
Assisted-by: Claude:claude-opus-5
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
The ethernet packet filter tests parse the link layer header straight
out of the packet buffer. They run from net_pkt_filter_recv_ok(), which
net_recv_data() calls before handing the packet to L2, and the only
length check performed by then rejects a completely empty packet. A
short frame therefore makes the tests read past buf->len: the address
tests read offsets 6..11, the ethertype test 12..13 and the VLAN
ethertype test 16..17, out of a buffer that may hold a single byte.
Check that the header a test parses is fully present and treat a frame
too short to hold it as not matching.
Signed-off-by: Flavio Ceolin <flavio@hubble.com>
Assisted-by: Claude:claude-opus-5
ethernet_recv() validates that the first net_buf holds a plain
14 byte Ethernet header, but when the ethertype is 0x8100 it
reinterprets the same buffer as an 18 byte net_eth_vlan_hdr without
re-checking the length. The VLAN TCI and the inner ethertype are then
read from offsets 14..17, past buf->len, and hdr_len is raised to 18
so that the later net_buf_pull() removes more bytes than the buffer
holds.
A frame of 14 to 17 bytes carrying the VLAN ethertype therefore either
trips the assertion in net_buf_simple_pull(), which panics the node, or
with assertions compiled out underflows the uint16_t buffer length to
65534 and advances buf->data, leaving every later parser reading far
outside the buffer.
Check that the VLAN header is fully present before reading the tag out
of it. This also makes the subsequent pull safe, as hdr_len is now
either 14 or 18 with both sizes validated.
Add a regression test feeding truncated VLAN frames to the interface
and verifying that the buffer is neither pulled nor advanced.
Signed-off-by: Flavio Ceolin <flavio@hubble.com>
Assisted-by: Claude:claude-opus-5
monitor_ts_get() divided the cycle counter by
sys_clock_hw_cycles_per_sec() / MONITOR_TS_FREQ, truncating the
divisor to an integer. With a 32768 Hz cycle counter, common on
Bluetooth LE SoCs (both nRF52 and EFR32 use it by default), the
divisor becomes 3 instead of 3.2768, making all monitor timestamps
run 9.2% fast: one real minute displays as roughly 65.5 seconds in
btmon, and the same skew applies to the log core timestamps since
monitor_ts_get() is also registered via log_set_timestamp_func().
Convert through microseconds with k_cyc_to_us_floor64() instead,
which uses overflow-safe scaled arithmetic for any cycle rate.
Measured on nrf52dk/nrf52832 against k_uptime_get() reported in the
same monitor record: before, a record stamped at 54.9 s carried an
uptime of 50.3 s (ratio 1.0923); after, records at 16.683 s and
48.811 s carry uptimes of 16683 ms and 48810 ms (ratio 1.0000).
Assisted-by: Claude:claude-fable-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
The packet is not allocated for TCP sockets, and the send path relies on
that by dispatching on the socket protocol again. The GCC static analyzer
could not correlate the two protocol reads and followed the UDP path with
the unallocated packet, which it reported as NULL dereferences in
net_pkt_iface() and net_pkt_set_ip_dscp(). Read the protocol into a local
variable, so that the allocation and the dispatch are guaranteed to agree
on it.
Assisted-by: Cursor:claude-opus-5
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
add support to print the ptp timestamp
in a formatted way with year month days ... and not just
seconds and nanoseconds. Similar to the formatted printing of the
logging timestamp when CONFIG_LOG_OUTPUT_FORMAT_DATE_TIMESTAMP is enabled.
Signed-off-by: Fin Maaß <info@finmaass.de>
net_if_get_device(), net_if_l2() and net_if_get_link_addr() return NULL
when passed a NULL interface, so static analysis reports every unchecked
dereference of their result as a possible NULL dereference. These
pointers are never NULL for an initialized interface, so assert on them
instead of adding runtime checks for a case that cannot happen.
While at it, fetch the L2 pointer once instead of calling net_if_l2()
repeatedly in the same function.
Assisted-by: Cursor:claude-opus-5
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
bind_default() left the padding and the fields it does not use, such as
sin6_scope_id, uninitialized in the socket address it passes to
net_context_bind(), which static analysis reports as a read of an
uninitialized value.
Assisted-by: Cursor:claude-opus-5
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
net_pkt_lladdr_if() returns NULL when the packet has no interface set,
so static analysis reports each of the three dereferences of its result
as a possible NULL dereference. The interface is assigned at the top of
the function, so assert on the link address once and reuse the pointer.
Assisted-by: Cursor:claude-opus-5
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
net_if_get_link_addr() returns NULL when passed a NULL interface, so
static analysis reports the unchecked dereferences in get_llao_len() and
set_llao() as possible NULL dereferences. The link address is never NULL
for an initialized interface, so assert on it instead of adding a
runtime check for a case that cannot happen.
Assisted-by: Cursor:claude-opus-5
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>