Commit Graph

21691 Commits

Author SHA1 Message Date
Anas Nashif
1a7ce3f45e Revert "init: Make entry init-function less and introduce service objects"
This reverts commit 175da6bdb0.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-07-16 16:39:36 -05:00
Gaetan Perrot
dd180c2789 ipc_service: ipc_icbmsg: fix unchecked error in icmsg_open()
Coverity (CID 516253) reported that the return value of
initialize_tx_with_sid_disabled() was set but not used, leading to
potential silent failures.

Check if the return value is negative and propagate the error through the
existing cleanup path.

Fixes: CID 516253

Signed-off-by: Gaetan Perrot <gaetan.perrot@spacecubics.com>
2025-07-11 13:15:04 -10:00
Robert Lubos
151295f98e net: sockets: Move socket vtable definition
Offloaded socket implementations need to create the socket operations
vtable, therefore need access to struct socket_op_vtable. So far this
has been defined in a private header, so implementations needed to add
the header location to the include path in CMake.

Therefore, move struct socket_op_vtable definition to the internal part
of the public socket header, so it's no longer needed to include a
private header. This is also more consistent with the rest of the public
header content, as for example macros needed to register a socket
implementation are already there.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-07-11 16:32:49 -05:00
Hake Huang
fb9783d880 tests: ztest: add test hold status in DEVICE_PM
for DEVICE_PM and DEVICE_PM_RUNTIME, ztest need
hold status like CONFIG_PM, otherwise the following
flash will be blocked for some SOC

Signed-off-by: Hake Huang <hake.huang@nxp.com>
2025-07-11 13:44:16 -05:00
Szymon Janc
d699e8ccf0 Bluetooth: Host: Make error messages unique
Both bt_le_adv_stop() and bt_le_adv_resume() were logging same
error message. Add aditional context to it so that logs are
distinguishable.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2025-07-11 08:25:53 -10:00
Andrey Dodonov
1c0608dc02 net: http: service: check for uncompressed file correctly
Correct not resetting compression extension,
when checking for an uncompressed file,
in case if compression is enabled, but no compressed file found.

Signed-off-by: Andrey Dodonov <Andrey.Dodonov@endress.com>
2025-07-10 16:01:47 -05:00
Robert Lubos
4872527605 net: coap_client: Don't send RST on unrecognized ACK response
According to CoAP RFC (7252, ch. 4.2), Reset cannot be sent in a
response for an ACK reply, rejected ACKs should be silently ignored
instead. Therefore, in case an unrecognized response is received, verify
the response type before sending Reset.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-07-10 16:01:03 -05:00
Simon Piriou
932005abf2 net: l2: ieee802154: mgmt: fix net_pkt leaks
The ieee802154_radio_send() function does not decrease reference counter
of the net_pkt, it's instead done one layer above in ieee802154_send().
This commit updates the mgmt functions using ieee802154_radio_send() to
always free the used net_pkt afterward.

Signed-off-by: Simon Piriou <spiriou31@gmail.com>
2025-07-10 10:13:35 -05:00
Lyle Zhu
e4569c434a Bluetooth: Classic: L2CAP: Fix retransmission timer restarting
When received the valid S frame, the retransmission timer should not
be restarted if unacknowledged I-frames have been sent but the
retransmission timer has not elapsed.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-07-09 09:43:12 -05:00
Vinayak Kariappa Chettimada
f6495d8b43 Bluetooth: Controller: Fix Tx Ack FIFO index corruption under race
Fix Tx Ack FIFO's first index being advanced beyond a
recorded ack_last value in a node_rx when under race
between ll_rx_get() being pre-empted while executing the
`tx_cmplt_get()` and a call to `ll_rx_put()` in an
interrupt service routine.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-07-09 09:42:58 -05:00
Simon Piriou
732a3a5c66 net: l2: ieee802154: shell: fix scan argc validation
Bump the argc check from 3 to 4 as the shell scan command has 3 required
parameters, the last being the scan duration:
- argv[0]
- passive|active
- channels
- per-channel duration in ms

Signed-off-by: Simon Piriou <spiriou31@gmail.com>
2025-07-09 00:26:29 -05:00
Luis Ubieda
b0caaed43b rtio: workq: Restructure workqueue as a threads pool with a queue
Based on a discussion around P4WQ limitations for our application, it
was determined that the RTIO workqueue required the ability to use
additional threads from the pool in spite of work items blocked.
Since this is not covered, nor desired for the P4WQ, then remove this
dependency and re-implement it in a way that covers also this use-case.

Signed-off-by: Luis Ubieda <luisf@croxel.com>
2025-07-08 18:35:26 -05:00
Loic Domaigne
a0a47a4b6d Bluetooth: ASCS: fix uninitialized pointer read
Fix uninitialized pointer read reported by Coverity.
Coverity CID: 529879

Signed-off-by: Loic Domaigne <tech@domaigne.com>
2025-07-08 13:44:37 -05:00
Lyle Zhu
d48e2bb4f4 Bluetooth: Classic: L2CAP: Fix issue that pending chan cannot be sent
When the returned buffer is a `NULL` of the pull function, it means
there is not any data needs to be sent. However maybe there is any
frame pending on other L2CAP channel needs to be sent over the same
ACL connection.

Re-trigger the TX processor. It will call the pull function again
and the pending buffer will be pulled from following L2CAP.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-07-08 13:41:39 -05:00
Jukka Rissanen
69fddf8f0b net: dns: Check interfaces to be NULL before use
Make sure interfaces variable is not NULL before using it.

Coverity-CID: 529857

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-07-08 13:41:11 -05:00
Cheng Chang
80602f32c6 bluetooth: AVDTP:in set config_rej_rsp,LOSC can't be added.
The current logic will result in rsp always being accept because LOSC
added is 0. and according to the spec, LOSC should not be added to the
Set Configuration Reject response.

Signed-off-by: Cheng Chang <cheng.chang@nxp.com>
2025-07-08 13:37:37 -05:00
Olivier Lesage
aa4e6ac0dd bluetooth: host: Handle failure to disable scan when updating own_addr
It wasn't taken into account that bt_le_scan_set_enable()
has a return value. It's not likely that the controller
rejects the command when BT_DEV_SCANNING is set, however.

Signed-off-by: Olivier Lesage <olivier.lesage@nordicsemi.no>
2025-07-08 13:37:26 -05:00
Olivier Lesage
ef7ede64cc bluetooth: host: Do not try to set NRPA when scanning with identity
Attempting this would fail (assuming the controller is implemented
correctly) because when using legacy commands it is not allowed to
change the device address while scanning.

It also did not make sense. If we have configured the scanner to use
the identity address as own_addr, because the advertiser and scanner
addresses are shared when using legacy commands, setting the adv NRPA
here would overwrite the identity address used by the scanner, which
I assume is not the intention.

Signed-off-by: Olivier Lesage <olivier.lesage@nordicsemi.no>
2025-07-08 13:37:26 -05:00
Olivier Lesage
11782dbbc0 bluetooth: host: rename bool scan_enabled -> scan_disabled
It represents whether scanning was disabled as part of this flow.

Signed-off-by: Olivier Lesage <olivier.lesage@nordicsemi.no>
2025-07-08 13:37:26 -05:00
Olivier Lesage
43223a1661 bluetooth: host: Fix uninitialized own_addr_type for legacy scan+adv
In 25c993e5b7 a new case was introduced
where own_addr_type is not set by bt_id_set_scan_own_addr properly.

This led to issues for users where increasing their zephyr version
led to failures to start scanning after advertising in the case where
CONFIG_BT_SCAN_WITH_IDENTITY=n and legacy advertising commands are used.

Signed-off-by: Olivier Lesage <olivier.lesage@nordicsemi.no>
2025-07-08 13:37:26 -05:00
Cheng Kai
ec0865cb4a Bluetooth: SDP: fix attr value len 32 invalid
fix sdp attr value len 32, which was not supported.

Signed-off-by: Cheng Kai <chengkai@xiaomi.com>
2025-07-07 10:13:47 -05:00
Make Shi
9104e941f9 Bluetooth: Classic: L2CAP: Set default value for BR timer timeout
When peer monitor and retransmission timeout are zero, set them to the
default values. This ensures that the monitor timeout is always a valid
value to avoid the L2CAP BR timer work queue hang.

Signed-off-by: Make Shi <make.shi@nxp.com>
2025-07-07 10:07:10 -05:00
Robert Lubos
8f983ccda5 net: lib: http_client: Fix end of message detection
HTTP 1.1 server has two ways of indicating the message body length -
either by providing the Content Length header, or by closing the
connection when the entire body has been transmitted.

The second method didn't work with Zephyr's HTTP client implementation,
as EOF on a socket was treated as an error condition. Therefore, if no
Content Length was provided by the server, such transfers would always
end up with ECONNRESET error.

In order to fix this, we need to notify the parser about the EOF on a
socket when connection is closed. It is the parser role to determine
whether the EOF was expected in current state (by marking end of message
flag) or not (by setting an error).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-07-07 10:04:17 -05:00
Gaetan Perrot
1610aa0e9f bluetooth: host: a2dp: remove redundant null check
Remove duplicated check for 'ep->stream == NULL' to clean up conditionals
and avoid unnecessary repeated evaluations.

This cleans up the code and avoids unnecessary repeated condition
evaluation.

Signed-off-by: Gaetan Perrot <gaetan.perrot@spacecubics.com>
2025-07-04 14:21:47 -10:00
Tim Pambor
6226bb1264 net: sockets_service: Fix function signature
Update the socket_service_thread function signature to match the expected
k_thread_entry_t type:
typedef void (*k_thread_entry_t)(void *p1, void *p2, void *p3);

Signed-off-by: Tim Pambor <tim.pambor@codewrights.de>
2025-07-04 14:21:23 -10:00
Jan Tore Guggedal
a7ce6055b7 zbus: Fix NULL pointer use in zbus_chan_rm_obs()
Fix a bug in zbus_chan_rm_obs() where removing the first observer in a
channel's observer list would cause undefined behavior due to accessing
a member of a NULL pointer.

The issue occurred when prev_obs_nd was NULL (indicating the first node
in the list) and the code attempted to pass &prev_obs_nd->node to
sys_slist_remove(). This resulted in accessing the 'node' member of a
NULL pointer, which is undefined behavior even when taking its address.

The sys_slist_remove() function is designed to handle a NULL prev_node
parameter correctly for removing the first element in a list. The fix
ensures we pass NULL directly instead of attempting to compute the
address of a member within a NULL pointer.

This was detected by Undefined Behavior Sanitizer as "member access
within null pointer".

Signed-off-by: Jan Tore Guggedal <jantore.guggedal@nordicsemi.no>
2025-07-04 15:49:32 -05:00
Gaetan Perrot
80df24e3b2 net: lib: coap: fix potential null pointer
In coap_well_known_core_get(), move the null check for 'resource' before
applying pointer arithmetic ('resource + 1') to avoid undefined behavior
when 'resource == NULL'.

Signed-off-by: Gaetan Perrot <gaetan.perrot@spacecubics.com>
2025-07-04 15:48:40 -05:00
Robert Lubos
aa4a8789d5 net: sockets: socket_dispatcher: Fix close function type
Socket dispatcher (and offloaded implementations in tests) register
fd as ZVFS_MODE_IFSOCK therefore they should register a  close2(
function instead of close().

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-07-04 13:16:32 -05:00
Robert Lubos
a4fdd2c266 net: sockets: socketpair: Fix close function type
socketpair fd regsiters ZVFS_MODE_IFSOCK therefore it should register a
close2() function instead of close().

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-07-04 13:16:32 -05:00
Robert Lubos
82945a7f52 net: l2: ieee802154: Prevent NULL pointer access
In case address mode in a packet is none, the address pointer within mhr
struct will not be set. Therefore, the pointer should not be used before
address mode is verified inside ieee802154_check_dst_addr().

This was reported by UBSAN:

  subsys/net/l2/ieee802154ieee802154.c:296:41: runtime error: member
  access within null pointer of type 'struct ieee802154_address_field'

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-07-04 13:16:32 -05:00
Robert Lubos
31b79a93af net: pkt: Add explicit casts to uint32_t when bitshifting uint8_t val
Cast uint8_t variable to uint32_t explicitly to avoid implicit cast to
int, and thus potentially undefined behavior, reported by UBSAN:

  net_pkt.c:1946:17: runtime error: left shift of 239 by 24 places
  cannot be represented in type 'int'

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-07-04 13:16:32 -05:00
Robert Lubos
7949789ce8 net: ip: utils: Avoid casting to in(6)_addr struct in net_addr_ntop()
In order to avoid alignment issues when casting void pointers to
in(6)_addr structures, create a properly aligned copy of the ip(v6)
address on stack.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-07-04 13:16:32 -05:00
Robert Lubos
bd96b5dd83 net: lib: websocket: Avoid bitshift overflow warning
In order to prevent an overflow warning from UBSAN when bitshifting,
cast to uint64_t first before shifting, and then back to uint32_t.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-07-04 13:16:32 -05:00
Robert Lubos
62a5260e01 net: Fix alignment error with net_ipaddr_copy()
As struct sockaddr have now alignment of 4 bytes, net_ipaddr_copy()
gives the following error if used for sockaddr:

  error: alignment 1 of ‘struct <anonymous>’ is less than 4
  [-Werror=packed-not-aligned]

Just use memcpy() instead, net_ipaddr_copy() was intended to use with IP
addresses, not socket related structs.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-07-04 13:16:32 -05:00
Robert Lubos
8124032cbb net: ipv4: Avoid casting unaligned address to struct in_addr
Rework the IPv4-related code to avoid casting. Use raw variants of
IPv4-related functions whenever possible (especially on the critical
data path).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-07-04 13:16:32 -05:00
Robert Lubos
f549bfcfeb net: ipv4: Add raw variants of various IPv4 functions
To address the misaligned access issues reported by UBSAN, introduce raw
variant of certain IPv4 functions used in the critical data path of the
network stack, operating on plain uint8_t buffers in stead of IPv4
address struct.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-07-04 13:16:32 -05:00
Robert Lubos
0f6dcb37d7 net: ipv6: Avoid casting unaligned address to struct in6_addr
Rework the rest of the IPv6-related code to avoid casting. Use raw
variants of IPv6-related functions whenever possible (especially on the
critical data path). For the routing case, use a copy of the address to
avoid massive rework of the routing module.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-07-04 13:16:32 -05:00
Robert Lubos
edf5319ca6 net: ipv6: nbr: Avoid casting unaligned address to struct in6_addr
IPv6 Neighbor Discovery interfaces modules like neighbor or routing
tables - converting them to raw variants seems futile. Therefore, for
IPv6 ND case, copy the raw IP address from the packet into the in6_addr
structure, and then pass it to respective functions. Performance
overhead should not be a big problem in such case as those actions are
only performed if a respective ND packet is received.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-07-04 13:16:32 -05:00
Robert Lubos
f5455e66e3 net: ipv6: 6lo: Avoid casting unaligned address to struct in6_addr
Refactor local functions to work with byte buffers instead of struct
in6_addr and use switch to use raw variants of functions operating on
IPv6 addresses.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-07-04 13:16:32 -05:00
Robert Lubos
74ccd5fdaa net: ipv6: Add raw variants of various IPv6 functions
To address the misaligned access issues reported by UBSAN, introduce raw
variant of certain IPv6 functions used in the critical data path of the
network stack, operating on plain uint8_t buffers in stead of IPv6
address struct.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-07-04 13:16:32 -05:00
Mark Wang
80c1e6929a bluetooth: smp: add todo comments for ctkd
need to consider corner cases of ctkd as the added code comments.

Signed-off-by: Mark Wang <yichang.wang@nxp.com>
2025-07-04 13:10:21 -05:00
Mark Wang
81d938606d bluetooth: smp: CTKD issue when cross br and ble connections and security
The peer uses the RPA address.
A BR connection is created firstly, a subsequent BLE connection is
created secondly, the BR SMP CTKD occur thirdly (The BLE LTK is
derived from BR and the BR SMP distribute peer's IRK and identity address
here), but the BLE LTK is saved to key pool that is not
matched with the previous BLE connection because the derived LTK is saved
with identity address and BLE connection uses RPA. Fix it by: Resolve the
BLE connections' RPA with the derived IRK to find the previous BLE
connections and match the connections with derived LTK key.

Signed-off-by: Mark Wang <yichang.wang@nxp.com>
2025-07-04 13:10:21 -05:00
Shrek Wang
6a27fd2255 net: tcp: Add TCP ACK validation
According to RFC 793, ch 3.9 Event Processing,
after the connection is sync-ed with seqnum of both sides then,
        1. drop any received segment if the ACK bit is off.
        2. validate the acknum like this:
        SND.UNA =< SEG.ACK =< SND.NXT

The ACK validation is done before entering the state-machine, so
remove the flags <ACK> check in the state-machine processing.

Signed-off-by: Shrek Wang <inet_eman@outlook.com>
2025-07-04 13:08:57 -05:00
Christoph Mair
f64358fcdb pm: fix typo in KConfig
Workqueue is missing a "k".

Signed-off-by: Christoph Mair <christoph.mair@husqvarnagroup.com>
2025-07-04 13:05:56 -05:00
Mike J. Chen
a392c33c60 bluetooth: fix bug when destroying tx queue buffers on disconnect
Channel tx_queue purging on disconnect was inconsistently handled
by the different channels: iso, l2cap, l2cap_br.

iso channels handled purging in the tx_data_pull hook.

l2cap and l2cap_br did the purging in channel delete functions
and did not expect tx_data_pull to be called for a disconnected
channel. Their data_pull functions could return a ptr to a
net_buf that was still on the tx_queue, which is problematic
when the conn tx_processor unrefs the returned buffer resulting
in multiple calls to the buf destroy function.

To make things consistent and correct, remove the code that tries
to purge tx_queues in the tx_processor and only do purging in
the channels themselves when they are deleted/disconnected.

Also refactor and clarify referencing of the net_buf returned
by tx_data_pull. It was confusing who had a reference and
when, which could vary depending on the length of the original
buffer. There are three cases: the buffer length is less
than the tx.mps, greater the mps but less than the mtu so
requiring segementation but not fragmentation, or greater than
both mps and mtu so requiring both segmentation and fragmentation.
The conn layer would increase the refcnt if the length was
greater than the mtu, but not have any awareness of whether
the net_buf was still on the tx_queue or not.

Now it is the tx_data_pull callbacks responsibitity to increment
the reference count if it is returning a pointer to a net_buf
that it is still keeping on the tx_queue for segmentation purposes.
The conn layer will now always transfer that reference into a
fragment view and not conditional it on the length relative to
the mtu, and always decrement the reference to the parent when
the fragment is destroyed.

So there is no risk of decrementing a reference to a net buf
that might still be on a tx_queue, which simplifies error
handling in particular.

Also add error handling paths for when asserts are not enabled.

Signed-off-by: Mike J. Chen <mjchen@google.com>
2025-07-03 11:59:02 -05:00
Vinayak Kariappa Chettimada
3eee7c5325 Bluetooth: Controller: Fix peripheral role assertion on conn update
Fix peripheral role assertion during connection update and
simultaneous flash operations.

prepare_cb: Actual EVENT_OVERHEAD_START_US = 6149

This happens due to instant latency at connection update
where the ticks_at_expire was in the past.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-07-03 11:56:59 -05:00
Vinayak Kariappa Chettimada
6935a4bf90 Bluetooth: Controller: nRF54Lx: Flash sync restrict to one iteration
Write operations are not constant time on nRF54Lx SoCs and
depend on the previous value present versus new value to be
written. Hence, perform no more than one iteration.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-07-03 11:56:59 -05:00
Jiawei Yang
89d54b6f48 Bluetooth: HFP: Fail to get Bluetooth Profile Descriptor List
In HFP PTS, cases run fail with the log 'Bluetooth Profile Descriptor
List UUID (0x111E) is missing'.

With this patch, the affected cases can pass correctly.

Signed-off-by: Jiawei Yang <jiawei.yang_1@nxp.com>
2025-07-03 11:54:40 -05:00
Jun Lin
aa3db8e5bb mgmt: ec_host_cmd: backend: shi_npcx: fix log message
This commit fixes the content of the log messages that appear when an
error occurs while applying the pinctrl.

Signed-off-by: Jun Lin <CHLin56@nuvoton.com>
2025-07-02 17:58:20 -05:00
Tim Pambor
e6f179d180 tests: net: dns-sd: Fix undefined behavior reported by UBSAN
htons() takes uint16_t as argument. Add the 'u' suffix to the
TTL constants to ensure the correct unsigned type is used and to avoid
undefined behavior if these functions are implemented as macros using
bit shifts.

Signed-off-by: Tim Pambor <tim.pambor@codewrights.de>
2025-07-02 03:55:06 -10:00