Commit graph

22,555 commits

Author SHA1 Message Date
Tom Hughes
eff76caa17 ztest: mock: Fix typo
"Return value no used by mock" should be
"Return value not used by mock".

Signed-off-by: Tom Hughes <tomhughes@chromium.org>
2025-02-07 14:34:39 +01:00
Ingar Kulbrandstad
0330ff1ac0 Bluetooth: Host: Updated Kconfig description
Added warning to the BT_RECV_WORKQ_SYS description
to explain the dangers by using this option.

Signed-off-by: Ingar Kulbrandstad <ingar.kulbrandstad@nordicsemi.no>
2025-02-07 14:34:23 +01:00
Kamil Krzyzanowski
cd281ab40b logging: fs backend: simplify checking if file exists
In order to check if the desired log file exists, the backend would open
the directory, then go through all the files seeing if one of them matches
the correct filename. Simplify to just `fs_stat` the file instead.

This has the added side effect of lowering the time spent checking if the
file exists after every log. Some quick testing revealed the time spent
checking went down from ~150-300ms to ~10ms (on my specific board, with a
nRF9160 writing to a LittleFS on external flash).

Signed-off-by: Kamil Krzyzanowski <kamnxt@kamnxt.com>
2025-02-07 14:33:35 +01:00
Kamil Krzyzanowski
41f2c64e97 logging: fs backend: only fs_sync when done with a batch of logs
The previous behavior was to call `fs_sync` on the file after every log
item written. In many cases, log messages come in bursts, and `log_core`
already operates in batches, configurable using
`CONFIG_LOG_PROCESS_THREAD_SLEEP_MS` and
`CONFIG_LOG_PROCESS_TRIGGER_THRESHOLD`. Once the batch is done, the
backends get notified with `LOG_BACKEND_EVT_PROCESS_THREAD_DONE` if any
logs were processed. This is a nice time to `fs_sync` the written changes.

This change both speeds up the time spent writing logs and reduces the
amount of block erases done on the flash, as the previous implementation
erased blocks after each individual log message.

Signed-off-by: Kamil Krzyzanowski <kamnxt@kamnxt.com>
2025-02-07 14:32:06 +01:00
Joakim Andersson
dc97cc0cd5 tests: logging: Convert unit test to include the full FS backend
Convert testing of the logging backend for file-system to include the
full implementation.
Need to disable logging and just include the unit under test to make
this simpler.
The API functions for the backend can then be called on the backend
object.

Signed-off-by: Joakim Andersson <joerchan@gmail.com>
2025-02-07 14:32:06 +01:00
Jeremy Bettis
e1cfd098a2 shell: Fix Kconfig dependencies
PR #84651 introduced new shell commands that don't compile if
CONFIG_THREAD_MONITOR=n

Add THREAD_MONITOR to new shell commands.

Signed-off-by: Jeremy Bettis <jbettis@google.com>
2025-02-06 21:14:01 +01:00
Aleksandr Khromykh
a09fa5f7f3 Bluetooth: Mesh: remove deprecated field in cdb subnet
Commit removes deprecated filed in cdb subnetwork.

Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
2025-02-06 21:13:31 +01:00
Ludvig Jordet
5facb50fe9 Bluetooth: Mesh: add missing device key candidate PSA support
Commit adds PSA key support for device key candidate.

Signed-off-by: Ludvig Jordet <ludvig.jordet@nordicsemi.no>
2025-02-06 21:13:31 +01:00
Emil Gydesen
8e53592da8 Bluetooth: BAP: Fix issue with sink recv state notifications
There was a bug in pa_decode_base that would would spent time
parsing incoming BASEs and also update the receive
states, which caused some tests to fail.

This commit adds a simply check to verify that the BASE is
different before spending parsing the content and updating
the receive states.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-02-06 21:13:15 +01:00
Dave Lacerte
d9aab69fbf net: coap: Fix uninitialized variable warning
The variable block_len in function coap_next_block_for_option()
can be used uninitialized in case of empty packet in
coap_packet_get_payload(). Mute the compiler warning with
default value of 0.

Signed-off-by: Dave Lacerte <lacerte.dave@hydroquebec.com>
2025-02-06 17:49:42 +01:00
Chaitanya Tata
4cd6654b21 net: l2: Add a config option to allow mismatched L3/L2 address packets
The RFC1122 section 3.3.6 says we SHOULD drop the packets if L2 address
is brodcast but L3 address is unicast, but we had seen some Wi-Fi access
points in the field not conforming to that, and DHCP offer is dropped
due to this and causes Wi-Fi connectivity issues.

As the RFC saus it's SHOULD and not a MUST, add a config option to allow
such packets, disabled by default.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2025-02-06 17:48:37 +01:00
Seppo Takalo
ac01879330 net: lwm2m: Tickless does not depend on SOCKETPAIR
Tickless mode is refactored to use zvfs_eventfd,
but the Kconfig dependencies were not updated.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2025-02-06 14:46:55 +01:00
Emil Gydesen
a9279eef35 Bluetooth: Controller: Fix coverity issue for cis == NULL
Coverity was unhappy that
`struct ll_conn_iso_stream *cis = NULL;` was never assigned to
a non-NULL value, which is due to the assignment being
guarded by `#if defined(CONFIG_BT_CTLR_CONN_ISO)`.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-02-06 14:46:31 +01:00
Dominic Moffat
8519fa1627 net: socket service resets its restart flag
The socket service restarts whenever a new socket is registered.
This is triggered via zvfs_eventfd_write(ctx.events[0].fd, 1),
but the restart flag (ctx.events[0].revents) is not properly cleared,
causing unintended repeated restarts and skipped socket processing.

Detecting socket restart is done after the socket fd has processed its
data, so the socket doesn't lose its data. Ensure the socket service
clears its restart flag (ctx.events[0].revents = 0) immediately after
detecting a restart event, preventing unnecessary restarts.

Fixes #81813

Signed-off-by: Dominic Moffat <dom@illysky.com>
2025-02-05 23:49:28 +01:00
Noah Olson
37a924be6a net: dns: Fix DNS caching bug
The current DNS caching logic is not aware of the IP address version.
If there is a cached address for a query, the caller of
dns_get_addr_info() will receive that address, even if it is not the
same version as the caller requested. For example:

- dns_get_addr_info() is called to resolve an IPv4 address
- the DNS client caches the IPv4 address that was received
- dns_get_addr_info() is called to resolve an IPv6 address
- the DNS client sees that there is a cached IPv4 address for the
  given query
- the DNS client does not check that the cached address is of the
  requested version (IPv6)
- the cached IPv4 address is returned from dns_get_addr_info()

This changes the DNS client to check IP address version when searching
cached addresses.

Signed-off-by: Noah Olson <noah@wavelynx.com>
2025-02-05 23:49:17 +01:00
Dave Lacerte
31ec42a33c net: lwm2m: Fix offset for post-write callback
The offset in post-write callback is incorrect for TLV format as
the first data block contain TLV header. This fix is replacing
reamaning for offset in opaque context struct and passing it to
post-write and validation callback.

The fix also corrects the offset in pull context as it was pointing
at the end of the block processed data and not on the block context
prior to processing.

Signed-off-by: Dave Lacerte <lacerte.dave@hydroquebec.com>
2025-02-05 23:48:38 +01:00
Emil Gydesen
82cda0ea18 Bluetooth: Audio: Shell: Fix ad data returning -1
Several advertising data function could return -1 in case of
errors, which could mess up the advertising data since they are
intended to increment a counter.

Instead of returning an error we use bt_shell_error to inform
the user and then just return with no data changes, so that if
any of them fails, the failing data is just omitted rather
than causing major issues.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-02-05 21:02:14 +01:00
Vinayak Kariappa Chettimada
be91cfedfb Bluetooth: Controller: Fix incorrect event_count when CIG overlaps
Fix incorrect event_count use in CIG events when the next
CIG interval's prepare overlaps with the current CIG event.
Use separate event_count_prepare variable in ULL and copy
the value in LLL event.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-02-05 17:50:28 +01:00
Vinayak Kariappa Chettimada
3bf330855e Bluetooth: Controller: Fix Connected ISO to use accumulated latency
Fix Connected ISO to use accumulated latency to update the
payload count.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-02-05 17:50:28 +01:00
Vinayak Kariappa Chettimada
1c86636a7f Bluetooth: Controller: Fix Central ISO related to elapsed events value
Fix incorrect elapsed events value when event prepare are
aborted in the pipeline. This can caused premature
supervision timeouts.

Relates to commit 247037bd3e ("Bluetooth: Controller: Fix
incorrect elapsed events value").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-02-05 17:50:28 +01:00
Emil Gydesen
28e188b56a Bluetooth: PACS: Add verification of bt_bap_pacs_register_param
Add verification of the parameter struct, so that it returns
-EINVAL if the values are invalid.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-02-05 14:57:30 +01:00
Emil Gydesen
b72b33a8bc Bluetooth: Audio: Add dependency for BT_SMP
Add dependency for BT_SMP for the services and
service clients that require encryption.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-02-05 14:57:20 +01:00
Emil Gydesen
3e9b45440f Bluetooth: PACS: Do not use conn struct directly
Instead of using the bt_conn struct directly, only
access the field via the public API. This ensures that
changes to the struct won't affect PACS, unless it also
affects the public API.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-02-05 14:57:14 +01:00
Emil Gydesen
72b94f0d05 usb: device_next: Document if callbacks are mandatory
Adds additional documentation to the callbacks of uac2_ops
to describe if/when they are mandatory to register.

Additionally add asserts before calling them to help debugging
if the user did not register the required ones.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-02-05 14:56:47 +01:00
Robert Lubos
b7cfa54c18 net: tc: Deprecate CONFIG_NET_TC_SKIP_FOR_HIGH_PRIO
Since a separate CONFIG_NET_TC_RX_SKIP_FOR_HIGH_PRIO was introduced for
RX TC queues, CONFIG_NET_TC_SKIP_FOR_HIGH_PRIO became ambiguous,
rename it to CONFIG_NET_TC_TX_SKIP_FOR_HIGH_PRIO and deprecate the old
config.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-02-05 12:37:01 +01:00
Robert Lubos
e430dfb00f net: arp: Set family and proto type for all ARP packets
The family and proto type was not set for the IPv4 autoconf ARP packets.
Since those should be set for all ARP packets, just move the code
outside of the if block.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-02-05 12:36:25 +01:00
Vinayak Kariappa Chettimada
e8da981711 Bluetooth: Controller: Workaround HCTO for BabbleSIM
Workaround HCTO calculation for BabbleSIM due to need of
addition timeout value required to have anchor point sync.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-02-05 08:16:30 +01:00
Vinayak Kariappa Chettimada
13fa3a0290 Bluetooth: Controller: Fix incorrect drift comp on PHY update
Fix incorrect peripheral drift compensation when connection
events are overlapping and a PHY update causes the currently
used PHY to change.

Incorrect preamble to address that is calculated using
updated PHY was used causing supervision timeout.

Fixed by storing the PHY used in the current connection
event and using that for drift compensation calculation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-02-05 08:16:30 +01:00
Vinayak Kariappa Chettimada
745810c4ce Bluetooth: Controller: Fix connection event busy check
Fix connection event busy check when peripheral role is
using minimal time reservation.

Peripheral and Central have a anchor point sync if the
Peripheral has successfully transmitted once to the Central.

Fixes commit cadef5a64f ("Bluetooth: Controller: Introduce
BT_CTLR_PERIPHERAL_RESERVE_MAX")'.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-02-05 08:16:30 +01:00
Sean Madigan
8cff70a95d bluetooth: host: Add PSA returns to debug prints
Recently I have had to debug issues with PSA and having
the returns values from PSA is very useful in order to
find the root cause of the issue.

Signed-off-by: Sean Madigan <sean.madigan@nordicsemi.no>
2025-02-04 15:05:50 +00:00
Sean Madigan
706938d7b2 bluetooth: controller: Only BT_CTLR_ECDH default y if BT_HCI_RAW
In https://github.com/zephyrproject-rtos/zephyr/pull/84268
the ability to use the controller for ECDH was removed from
the host.

This means that BT_CTLR_ECDH is now only useful when using
BT_HCI_RAW.

Signed-off-by: Sean Madigan <sean.madigan@nordicsemi.no>
2025-02-04 15:01:22 +01:00
Yong Cong Sin
f840a35be3 logging: log_cmds: init uninitialized backend on log_go()
For backends that do not autostart themselves, initialize
& enable them on `log backend <log_backend_*> go`, so
that they function properly.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2025-02-04 15:00:58 +01:00
Yong Cong Sin
8dd9d924fe logging: init backend id regardless of autostart
The `id` is basically a compile-time constant. Setting it every
time the backend is enabled is unnecessary. Instead, set it on
`z_log_init()` regardless of whether or not it requires to be
`autostart`ed.

Fixes an issue where the `filter_get`/`filter_set`
accessed the wrong index and displayed the wrong log level when
user accesses the status of an uninitialized backend via:
`log backend <uninitialized_backend> status`.

Also fixes an issue when user tries to list the backends via:
`log list_backends`, where all uninitialized backends will have
ID = 0.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2025-02-04 15:00:58 +01:00
Emil Gydesen
48aedc98da Bluetooth: Audio: Spring cleanup for audio source files
Add missing and remove unused includes. Fix spelling mistakes.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-02-04 12:03:04 +01:00
Jamie McCrae
f3e2e7dc06 mgmt: mcumgr: grp: img_mgmt: Add image number to confirmed callback
Adds the image number to the confirmed callback

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2025-02-04 11:56:31 +01:00
S Swetha
8f647ef46b [shell]: Add thread control features through shell
This commit extends the shell command functionality by
adding three new operations for thread management.
kernel thread suspend <thread_id>:
Suspends any thread based on its identifier.
kernel thread resume <thread_id>:
Resumes the thread that was previously suspended.
kernel thread kill <thread_id>:
Terminates any thread based on its identifier
These extended commands are useful for controlling
any threads through Zephyr Shell.

Signed-off-by: S Swetha <s.swetha@intel.com>
2025-02-04 11:56:22 +01:00
Johann Fischer
712bc1678a usb: device_next: add USB DFU flash backend
Add a simpler flash backend, similar to what we have in the legacy USB
DFU implementation. Support slot-0 and slot-1 flash partitions, but
allow them to be enabled/disabled via Kconfig options.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2025-02-04 11:55:25 +01:00
Johann Fischer
8b0bdb563f usb: device_next: implement USB DFU class for the new device support
This new implementation is written from scratch and is not tied to the
image manager and MCUboot. It allows the user to define their own
backend and use a simple macro to instantiate an image. On the USB side
this is represented by an interface. The number of possible images is
configurable using the Kconfig option, and is a fairly inexpensive
approach since it only changes the size of the pointer array. The number
of images is only limited by the number of possible interfaces in a
configuration. The class implementation does not support multiple
instances, as there is no real use for it. However, it does provide two
class instances, one for runtime mode and one for DFU mode. The switch
from runtime to DFU mode can only be performed by the user application,
i.e. the application receives a notification when the host wants to
switch to DFU mode, and then the application can disable the runtime
configuration and enable the DFU configuration. This implementation does
not support switching to the DFU mode by bus reset issued by the
host.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2025-02-04 11:55:25 +01:00
Johann Fischer
3bfe163811 usb: device_next: implement blocklist for classes
In the usbd_register_all_classes(), we may need to skip some instances
as they may have very specific function like USB DFU "DFU mode" which
should not be available by default.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2025-02-04 11:55:25 +01:00
Marcin Niestroj
a984187c96 mgmt: mcumgr: rework create_socket() to use single sockaddr storage
Allocate only one 'struct sockaddr_storage', instead of two separate
'struct sockaddr_in' and 'struct sockaddr_in6'. This saves some space in
case both IPv4 and IPv6 are used. Additionally it reduced preprocessor
ifdef statements, resulting in more readable code.

This also solves '-Warray-bounds=' GCC warning (reproducible with
'native_sim' and GCC version 14.2.1 on Arch Linux):

  In function ‘create_socket’,
      inlined from ‘smp_udp_receive_thread’ at \
          subsys/mgmt/mcumgr/transport/src/smp_udp.c:242:7:
  subsys/mgmt/mcumgr/transport/src/smp_udp.c:205:37: warning: \
      array subscript ‘struct sockaddr[0]’ is partly outside array \
      bounds of ‘struct sockaddr_in[1]’ [-Warray-bounds=]
    205 |         tmp_sock = zsock_socket(addr->sa_family, SOCK_DGRAM, \
        |                                 ~~~~^~~~~~~~~~~
                                                        IPPROTO_UDP);
  subsys/mgmt/mcumgr/transport/src/smp_udp.c: In function \
      ‘smp_udp_receive_thread’:
  subsys/mgmt/mcumgr/transport/src/smp_udp.c:170:28: note: \
      object ‘addr4’ of size 8
    170 |         struct sockaddr_in addr4;
        |                            ^~~~~

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2025-02-03 19:53:13 +01:00
Lyle Zhu
790006f875 Bluetooth: L2CAP_BR: Support dynamic PSM allocation
In the function `bt_l2cap_br_server_register()`, the PSM cannot be
dynamic allocated. And only pre-set PSM is supported.

Improve the function `bt_l2cap_br_server_register()` to support the
dynamic PSM allocation if the passed PSM is zero.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-02-03 19:50:56 +01:00
Cla Mattia Galliard
2153e34e14 net: ethernet: cleanup net-stats calls
There is no need to if-def away the net-stats function since there is a
shim available now.

Signed-off-by: Cla Mattia Galliard <cla-mattia.galliard@zuehlke.com>
2025-02-03 16:59:53 +01:00
Jordan Yates
bb6cb0f1dd lorawan: clock_sync: assert instead of error code
Assert that the size provided to `clock_sync_serialize_device_time` is
sufficient, instead of returning an error code. The condition is already
enforced by the calling code, and returning an error code is incorrect
when the return code is unconditionally being used to increment the
buffer offset by callers.

Fixes #84720.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2025-02-03 16:59:29 +01:00
Jamie McCrae
98d5aa3792 mgmt: mcumgr: grp: img_mgmt: Fix calling confirm
Fixes calling the registered callbacks for image being confirmed
if the confirmation was not successful

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2025-02-03 11:18:25 +01:00
Robert Lubos
57189b410e net: lwm2m: gateway: Prevent underflow when processing URI options
lwm2m_gw_handle_req() function logic expects that at least one URI
option was found, therefore add an extra check to return the function
early if that isn't the case.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-01-31 19:51:17 +01:00
Titouan Christophe
c525e7a0a5 usb: device_next: add new MIDI 2.0 device class
This adds a new USB device class (based on usb/device_next) that implements
revision 2.0 of the MIDIStreaming interface, a sub-class of the USB audio
device class. In practice, the MIDI interface is much more simple and has
little in common with Audio, so it makes sense to have it as a separate
class driver.

MIDI inputs and outputs are configured through the device tree, under a
node `compatible = "zephyr,usb-midi"`. As per the USB-MIDI2.0 spec,
a single usb-midi interface can convey up to 16 Universal MIDI groups,
comprising 16 channels each. Data is carried from/to the host via
so-called Group Terminals, that are organized in Group Terminal Blocks.
They are represented as children of the usb-midi interface in the device
tree.

From the Zephyr application programmer perspective, MIDI data is exchanged
with the host through the device associated with the `zephyr,usb-midi`
interface, using the following API:

* Send a Universal MIDI Packet to the host: `usb_midi_send(device, pkt)`
* Universal MIDI Packets from the host are delivered to the function passed
  in `usb_midi_set_ops(device, &{.rx_packet_cb = handler})`

Compliant USB-MIDI 2.0 devices are required to expose a USB-MIDI1.0
interface as alt setting 0, and the 2.0 interface on alt setting 1.
To avoid the extra complexity of generating backward compatible USB
descriptors and translating Universal MIDI Packets from/to the old
USB-MIDI1.0 format, this driver generates an empty MIDI1.0 interface
(without any input/output); and therefore will only be able to exchange
MIDI data when the host has explicitely enabled MIDI2.0 (alt setting 1).

This implementation is based on the following documents, which are referred
to in the inline comments:

* `midi20`:
    Universal Serial Bus Device Class Definition for MIDI Devices
    Release 2.0
    https://www.usb.org/sites/default/files/USB%20MIDI%20v2_0.pdf
* `ump112`:
    Universal MIDI Packet (UMP) Format and MIDI 2.0 Protocol
      With MIDI 1.0 Protocol in UMP Format
    Document Version 1.1.2
    https://midi.org/universal-midi-packet-ump-and-midi-2-0-protocol-specification

Signed-off-by: Titouan Christophe <moiandme@gmail.com>
2025-01-31 19:50:26 +01:00
Jukka Rissanen
9c24578cc4 net: vlan: Allow VLAN count to be set to 0
If VLAN count is set to 0, then only priority tagged VLAN frames
that have tag value 0 can be received. Also this means that VLAN
interfaces are not created which can save memory if you do not need
to receive any other VLAN frames than those tagged with value 0.

Fixes #84023

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-01-31 16:12:50 +01:00
Cla Mattia Galliard
586bec760d net: ethernet: Ensure packet is not touched after consumed by l3
Ensure that all packets are no longer used by ethernet_recv after it was
consumed by the l3-handler.

Signed-off-by: Cla Mattia Galliard <cla-mattia.galliard@zuehlke.com>
2025-01-31 16:09:47 +01:00
Marc Lasch
dd16bc5153 net: lwm2m: Check result when sending messages
`lwm2m_send_message_async` returns critical errors which are not handled in
many cases. The function can return -ENOMEM, -EPERM or other error codes
from functions called.

Signed-off-by: Marc Lasch <marc.lasch@husqvarnagroup.com>
2025-01-31 16:09:33 +01:00
Cla Mattia Galliard
bb3ac84bce net: tc: Add a skip for rx-queues
Add a configuration option to skip the rx-queues for high priority packets
analogously to the tx-side.

Signed-off-by: Cla Mattia Galliard <cla-mattia.galliard@zuehlke.com>
2025-01-31 11:49:50 +01:00