Commit graph

21541 commits

Author SHA1 Message Date
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
Flavio Ceolin
5bc6446dcc doc: releases: 4.1: Document removed PM symbol
The deprecated PM_DEVICE_RUNTIME_EXCLUSIVE option is been removed
in this release.

Signed-off-by: Flavio Ceolin <flavio.ceolin@gmail.com>
2025-01-31 07:50:17 +01:00
Cla Mattia Galliard
ed1ebb337d net: tc: Add statistics about dropped packets
Add statistics about packets dropped in net_tc.

Signed-off-by: Cla Mattia Galliard <cla-mattia.galliard@zuehlke.com>
2025-01-30 20:27:33 +01:00
Cla Mattia Galliard
84f6e7a313 net: tc: Limit the max amount of packets in the traffic-class-fifo
To avoid starvation of a traffic class by another, limit the maximum amount
of packets, that can sit in a single traffic-class-fifo to a fraction of
the maximum amount of available packets. In the tx-case also reserve
packets for direct sending, in the case, where
CONFIG_NET_TC_SKIP_FOR_HIGH_PRIO is enabled.

Signed-off-by: Cla Mattia Galliard <cla-mattia.galliard@zuehlke.com>
2025-01-30 20:27:33 +01:00
Jukka Rissanen
4195130214 net: shell: events: Print more details for L4 events
Print IP address information for L4 DNS server add and remove
events.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-01-30 18:29:45 +01:00
Jukka Rissanen
6edcf445ab net: shell: events: IPv4 mcast join and leave were missing
The event monitor did not handled IPv4 multicast join/leave
event information.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-01-30 18:29:45 +01:00
Jukka Rissanen
ef9b3d4dbf net: shell: events: IPv4 mcast addr add and del were missing
The event monitor did not handled IPv4 multicast address
addition or deletion information.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-01-30 18:29:45 +01:00
Jukka Rissanen
b83f86a1d2 net: shell: events: Add admin up and down events
The "admin up/down" event was not being decoded.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-01-30 18:29:45 +01:00
Jukka Rissanen
e109a27c99 net: shell: events: Print event id for unknown events
To simplify debugging what event code is missing from the
events shell module, print also event id for the for unknown
events. This way it is a bit easier to figure out what the
unknown event is.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-01-30 18:29:45 +01:00
Jukka Rissanen
b2dcaa8f9e net: shell: events: Add Ethernet L2 support
Print Ethernet carrier on/off and VLAN tag enabled/disabled
status when monitoring events.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-01-30 18:29:45 +01:00
Daniel DeGrasse
598f343385 shell: handle reprint correctly when output crosses line boundary
When reprinting the shell command buffer with long user inputs, the
reprinted buffer may cross a line boundary, and require a newline to be
printed. For these cases, print the command buffer character by
character, inserting newlines as appropriate.

Fixes #82155

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2025-01-30 16:21:53 +01:00
Benjamin Cabé
7c6d3a6f93 fs: ext2: Fix potential integer overflow in disk access size calculation
Cast sector_count and sector_size to uint64_t to prevent potential
integer overflow when calculating total device size in
disk_access_device_size().

Fixes Coverity issue CID-322647

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-01-30 16:20:58 +01:00
Dominik Ermel
5c40ee3958 storage/stream_flash: Switch to stream_flash_erase_to_append
Switches flash_sync to use stream_flash_erase_to_append
instead of stream_flash_erase_page in preparation of deprecating
the later and reming control on erase from API user.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2025-01-30 14:13:42 +01:00
Robert Lubos
6677db21ce net: sockets: Make sure recvmsg() doesn't modify buffer configuration
The recvmsg() function should not modify the buffer configuration
provided in struct msghdr, such behavior is not specified in the POSIX
function description, nor is it consistent with well-known behavior of
this function in Linux.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-01-30 14:09:35 +01:00
Emil Gydesen
8ed24ae3a0 usb: device_next: Make buf ownership consistent for usbd_uac2_send
The usbd_uac2_send function sometimes took ownership of the
provided buffer in error cases, and sometimes not.

The commit modifies the function so that ownership is never
taken in case a non-0 return value.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-01-30 14:08:53 +01:00