Commit graph

21541 commits

Author SHA1 Message Date
Tomi Fontanilles
703e5258eb mgmt: updatehub: replace TinyCrypt by PSA
As part of ongoing work to move away from TinyCrypt and towards PSA
(#43712), introduce a PSA option and remove the TinyCrypt one for the
SHA-256 implementation.

The Mbed TLS implementation is modified to use `mbedtls_sha256`
directly for smaller code size.

The reliance of mgmt/updatehub on storage/flash_map's configuration
(`FLASH_AREA_CHECK_INTEGRITY_BACKEND`) is removed.
The choice of which implementation to use is made automatically,
based on whether a PSA API provider is present (`PSA_CRYPTO_CLIENT`).

This commit also add a test case with PSA (based on Mbed TLS)
in samples/subsys/mgmt/updatehub/sample.yaml.

Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2024-06-14 14:02:08 -04:00
Rubin Gerritsen
bfba19dc41 Bluetooth: Host: Add the API bt_hci_err_to_str()
This API converts a HCI error code to a string.
This can be useful if application developers want to print them
in the applications.

Later we can also use them in the host to improve debuggability.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2024-06-14 19:17:48 +02:00
Johann Fischer
4191602f11 usb: device_next: add helper to register all available class instances
Add helper to register/unregister all available class instances.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2024-06-14 19:17:13 +02:00
Nicolas Pitre
b148178bd2 demand_paging: eviction/nru: fix pathological behavior
Currently, the NRU algorithm always picks the lowest (and very often the
same) clean unaccessed page over and over when e.g. doing large anonymous
memory mappings. Spread the eviction selection more uniformly by by
starting the search right after the last victim instead of always
restarting from 0.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2024-06-14 19:15:59 +02:00
Tom Burdick
3b94af2b5c sensors: Submit call returns void
The integer return of sensor_submit should be void as the call is
asynchronous and the response is meant to be delivered using RTIO APIs
signaling that the submission completed with error or success.

Change the function signature to void and fix all uses of the submit
API, fixing some bugs in the process.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2024-06-14 19:13:02 +02:00
Valerio Setti
32b43564df bt: hci_ecc: add option to use PSA APIs instead of TinyCrypt
This commit adds CONFIG_BT_USE_PSA_API to allow the end
user to prefer PSA APIs over TinyCrypt for crypto operations
in bluetooth. Of course, this is possible only if
a PSA provider is available on the system, i.e.
CONFIG_PSA_CRYPTO_CLIENT is set.

This commit also extends
tests/bluetooth/mesh/basic/bluetooth.mesh.gatt adding a specific
case using PSA.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2024-06-14 15:41:34 +02:00
Valerio Setti
814b2ed457 bt-host: add option to use PSA APIs instead of TinyCrypt
By enabling CONFIG_BT_USE_PSA_API the user can specify to use
PSA APIs instead of TinyCrypt for crypto operations in bluetooth
host module.

This commit also extends tests/bluetooth/gatt in order to
add a PSA test.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2024-06-14 15:41:34 +02:00
Valerio Setti
9032f8d791 bt-crypto: add option to use PSA APIs instead of TinyCrypt
This commit adds CONFIG_BT_USE_PSA_API to allow the end
user to prefer PSA APIs over TinyCrypt for crypto operations
in bluetooth. Of course, this is possible only if
a PSA provider is available on the system, i.e.
CONFIG_PSA_CRYPTO_CLIENT is set.

This commit also extends tests/bluetooth/bt_crypto adding
a test case for PSA.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2024-06-14 15:41:34 +02:00
Seppo Takalo
35cc774aa5 net: lwm2m: Retry DTLS handshake before dropping to bootstrap
Allow DTLS handshake to be retried before the engine
drops into bootstrap. Otherwise any termporary failure,
for example DNS failure might drop us into bootstrap
without retrying.

Now all the retry logic should be in sm_do_network_error().
sm_do_registration() should only fall back to bootstrap
if there is configuration error.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-06-14 15:34:39 +02:00
Jens Rehhoff Thomsen
ab9fd0b5c9 Bluetooth: BAP: Add bt_bap_base_get_size function
bt_bap_base_get_size function returns the size of the BASE.

Fixes #73847

Signed-off-by: Jens Rehhoff Thomsen <jthm@demant.com>
2024-06-14 15:34:23 +02:00
Rubin Gerritsen
768c45a11d Bluetooth: Controller: Clarify that it can be overridden out of tree
Nordic devices are commonly used with the nRF Connect SDK.
There the SoftDevice Controller is set as the default
Bluetooth Controller. To avoid confusion when reading DTS
and Kconfig files, clarify this by adding a note.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2024-06-14 15:33:59 +02:00
Maximilian Deubel
05a45a19e3 dap: fix timeout handling
Use k_timepoint_t for timeout handling in the swj_pins function.

Signed-off-by: Maximilian Deubel <maximilian.deubel@nordicsemi.no>
2024-06-14 11:14:17 +02:00
Johann Fischer
9a9afb0b54 dap: implement DAP SWD sequence command
DAP SWD sequence command is a requirement to support CMSIS-DAPv2.
Raise supported version to "2.1.0".

Signed-off-by: Maximilian Deubel <maximilian.deubel@nordicsemi.no>
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2024-06-14 11:14:17 +02:00
Johann Fischer
e31cdc00a0 dap: react properly to unsupported UART commands
Add ID_DAP_UART_* command definitions and react properly to
unsupported UART commands.

Signed-off-by: Maximilian Deubel <maximilian.deubel@nordicsemi.no>
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2024-06-14 11:14:17 +02:00
Maximilian Deubel
58d9d889aa dap: add support for DAP_INFO string elements
Add support for DAP_INFO string elements.

Signed-off-by: Maximilian Deubel <maximilian.deubel@nordicsemi.no>
2024-06-14 11:14:17 +02:00
Maximilian Deubel
6522dd7f53 dap: implement wait for SWJ pins command
Implement wait for SWJ pins command.

Signed-off-by: Maximilian Deubel <maximilian.deubel@nordicsemi.no>
2024-06-14 11:14:17 +02:00
Johann Fischer
3e8f9fb7df drivers: swdp_bitbang: add SW output sequence
Add API to read count bits from SWDIO into data LSB first.

Signed-off-by: Maximilian Deubel <maximilian.deubel@nordicsemi.no>
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2024-06-14 11:14:17 +02:00
Johan Carlsson
f5ccc3c82c dap: do not return error in DAP connect command
If a host client crashes or fails to disconnect, the probe will
hang. Allow a new connection without raising errors.

Signed-off-by: Johan Carlsson <johan.carlsson@teenage.engineering>
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2024-06-14 11:14:17 +02:00
Johan Carlsson
e46e72320e dap: add Konfig option to set maximum packet size
This also fixes a bug where the packet size returned was only 17 byte.

Signed-off-by: Johan Carlsson <johan.carlsson@teenage.engineering>
2024-06-14 11:14:17 +02:00
Johann Fischer
7c9259abbc dap: add CMSIS-DAP compatible controller
Add CMSIS-DAP compatible controller which is a handler between
the host interface and SWD driver. The controller follows CMSIS-DAP
reference implementation. It expects a request buffer from the host
interface, splits it to simple transfers and forwards to the DP driver,
and finally returns a response buffer to the host.
Interface to the host can be implemented with USB HID device support.

Controller implements only SW-DP support and is tested
with pyOCD and ADIv5.x.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2024-06-14 11:14:17 +02:00
Luca Burelli
08eb314c35 llext: refactor: use cached section headers
The section headers are now available in the loader structure, so we can
use those directly instead of reading them from the ELF file every time.

This commit contains no logic changes; it removes all copies of the
header loading code and replaces them with direct access to the cached
section headers.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2024-06-14 11:13:44 +02:00
Luca Burelli
817bbda5cc llext: read all section headers at once
This change reads all section headers at once, instead of reading them
one by one. This is more efficient and allows to further simplify the
code downstream.

The section headers are directly accessed from the file buffer if the
llext_peek() function is supported by the loader. Otherwise, they are
read into a buffer allocated on the heap and used only during the
llext_load() function.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2024-06-14 11:13:44 +02:00
Luca Burelli
a976a1a25c llext: llext_load: document memory management policy
The do_llext_load function is responsible for loading an extension from a
file, and for this purpose it calls a number of functions that a) allocate
memory, and b) can fail. This creates the opportunity for memory leaks if
the error paths are not handled correctly.

This commit adds a comment at the beginning of the function to document
the memory management policy that has to be followed in this file:
cleanup is not performed in the error paths, and all memory is freed at
the end of the do_llext_load() function, both in the case of error and of
successful loading.

As an improvement, the symbol table is not freed if the LLEXT log level
is set to debug, so that it can be used, for example, to inspect the
symbols of the loaded extension.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2024-06-14 11:13:44 +02:00
Luca Burelli
89e27b9312 llext: improve debug messages
The recent llext_map_sections() rework changed the way debug messages
are output so that the names of most skipped sections are not printed
at all. This makes debugging harder since the section names are useful
to identify the contents at a glance.

Also print a few additional fields from the section header, and use 0x
prefixes for hex numbers.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2024-06-14 11:13:44 +02:00
Nicolas Pitre
13660dd7b9 demand_paging/backing_store/ram.c: misc fixups
First, do align the buffer. The slab code puts pointers in there and it
does not like it if those are not properly aligned.

And return the actual error code from k_mem_slab_alloc() even if errors
shouldn't happen (it did happen to me because of the above ... with
assertions disabled).

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2024-06-13 20:12:23 -04:00
Björn Stenberg
1e3fd5361f modbus_serial: Disable rx interrupt if buffer fills up
Disable rx interrupt if the buffer fills up so that rtu_timer can fire and
process the buffer.

Signed-off-by: Björn Stenberg <bjorn@haxx.se>
2024-06-13 16:48:05 -04:00
Yong Cong Sin
b98a60773b shell: kernel: add command to unwind a thread
Add a shell command to unwind a thread using its thread id.

uart:~$ kernel threads
Scheduler: 11 since last call
Threads:
*0x80017138 shell_uart
        options: 0x0, priority: 14 timeout: 0
        state: queued, entry: 0x800029ac
        stack size 3072, unused 1316, usage 1756 / 3072 (57 %)

 0x80017ca8 sysworkq
        options: 0x1, priority: -1 timeout: 0
        state: pending, entry: 0x80006842
        stack size 1024, unused 644, usage 380 / 1024 (37 %)

 0x800177e0 idle
        options: 0x1, priority: 15 timeout: 0
        state: , entry: 0x800065ae
        stack size 512, unused 180, usage 332 / 512 (64 %)

 0x80017950 main
        options: 0x1, priority: 0 timeout: 13
        state: suspended, entry: 0x80006326
        stack size 4096, unused 3604, usage 492 / 4096 (12 %)

uart:~$ kernel unwind 0x80017ca8
Unwinding 0x80017ca8 sysworkq
ra: 0x80007114 [z_swap+0x58]
ra: 0x80007ae8 [z_sched_wait+0x10]
ra: 0x8000689a [work_queue_main+0x58]
ra: 0x800006de [z_thread_entry+0x2e]

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-06-13 16:46:48 -04:00
Yong Cong Sin
5121de6e73 arch: introduce arch_stack_walk()
An architecture can indicate that it has an implementation for
the `arch_stack_walk()` function by selecting
`ARCH_HAS_STACKWALK`.

Set the default value of `EXCEPTION_STACK_TRACE_MAX_FRAMES` to
`ARCH_STACKWALK_MAX_FRAMES` if the latter is available.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-06-13 16:46:48 -04:00
Bjarki Arge Andreasen
5c24c79a90 modem: pipe: simplify synchronization
The design of the pipe is overly complicated compared to the
in-tree and planned future use of the pipe module.

The pipe is currently designed to protect against multiple
threads calling any API simultaineously. This is not neccesary
as only one thread ever calls open/close/transmit/receive at
once, while the notification APIs are potentially called by a
different thread.

This commit removes the synchronization of calls to the open/
close/receive/transmit APIs. It also uses a k_event for thread
safe event and state handling instead of a k_mutex and k_condvar.

The callback is proteced by a k_sem as it modified using the
attach/release APIs, which can be called simultaneously to a
thread invoking the callback.

Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
2024-06-13 16:43:49 -04:00
Vinayak Kariappa Chettimada
a568acbfea Bluetooth: Controller: Fix regression due to use of TMR_START_DELAY_US
Fix regression due to use of HAL_RADIO_TMR_START_DELAY_US
introduced in commit 11bae5cfa9 ("Bluetooth: Controller:
Fix missing radio timer comp and range delay").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2024-06-13 12:01:22 -04:00
Ping Wang
57be858846 Bluetooth: audio: BAP Broadcast Assistant support for multiple connections
The current implementation of the BAP Broadcast Assistant only supports a
single connection. This PR makes broadcast assistant support multiple BAP
scan delegators.

Fixes: #67523

Signed-off-by: Ping Wang <pinw@demant.com>
2024-06-13 17:53:47 +02:00
Robert Lubos
0d3a021379 net: dhcpv4: Reset Renewal/Rebinding times on ACK
In case no Renewal/Rebinding times have been provided the server via
DHCP options, we should reset their values on ACK, so that the client
can recalculate the defaults. This is important, as the lease time may
change, so we should recalculate default T1/T2 timeout based on the new
lease time value.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-06-13 17:50:52 +02:00
Robert Lubos
4d4391bf1c net: dhcpv4: Reimplement RENEW/REBIND logic according to RFC2131
DHCP Request retransmission in RENEW and REBIND states was not
compliant with RFC2131.

The retransmission interval should not be calculated as in REQUESTING
state in such case, but rather calculated based on the remaining T2
or lease time (depending on current state).

RFC doesn't also mention any retransmission count limit for those
states. The client should retransmit the REQUEST until T2 or lease
expiry time are reached.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-06-13 17:50:52 +02:00
Bjarki Arge Andreasen
494fab8ea4 modem: chat: patch unintended behavior in modem_chat_run_script()
Trying to start a chat script using either modem_chat_run_script()
or modem_chat_run_script_async() should result in returning -EBUSY
without affecting the currently running script and thread waiting
on the current script to stop.

The current behavior causes the thread waiting for the current
script to stop to return with error -EAGAIN, and the thread trying
to start the new script to return with error -EBUSY.

This commit moves the reset of the sem the current thread is
waiting on, to after the check of whether a script is currently
running, leaving the current thread unaffected as is intended.

Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
2024-06-13 17:49:23 +02:00
Timothy Keys
570c86d1ef Bluetooth: Controller: Add Kconfigs to enable Connection Subrating
Add Kconfigs to enable experimental subrating HCI commands.

Signed-off-by: Timothy Keys <timothy.keys@nordicsemi.no>
2024-06-13 08:06:11 -04:00
Rubin Gerritsen
9984adf24e Bluetooth: Host: Support concurrent initiating and scanning
The HCI command LE Read Supported States command returns
if the controller supports running the scanner and initiator
roles in parallel.

This commit utilizes this information in the host:
- It does not prevent initiating a connection when the scanner is
  running
- It does not prevent the host from restarting the background
  scanner when there the host wants to auto-initiate a connection.
- It does not stop the scanner when the host wants to auto-initiate
  a connection.

To support this feature, the scanner and initiator
always have to use the same address.
This because the HCI command LE Set Random Address
cannot be issued after the initiator or scanner has started.
1. When privacy is disabled, the scanner has to use its identity
   address to ensure it uses the same address as the initiator.
2. Only one identity is supported.

To simplify the implementation, it is a requirement to use
extended advertising commands to avoid interfering with
the random address used by the advertiser(s).

Also, it is a requirement to never use time-limited scanning,
as RPA this feature does not work when privacy is being used.
See https://github.com/zephyrproject-rtos/zephyr/issues/73634.

The changes in this commit will be tested out of tree as the
Zephyr Bluetooth Controller does not support this functionality.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2024-06-13 08:04:42 -04:00
Nithin Ramesh Myliattil
df45858d0f Bluetooth: BAP: Broadcast Source: Update stream codec config data
When creating a BAP broadcast source with bt_bap_broadcast_source_create
only the subgroup information is stored in the streams and the remaining
BIS specific information is not stored in the stream->codec_cfg,
which it should.
Fix is to store bis specific information also in stream codec config.
Updated broadcast source BSIM test to verify above usecase.

Signed-off-by: Nithin Ramesh Myliattil <niym@demant.com>
2024-06-13 08:04:27 -04:00
Fabio Baltieri
2c5b09cbda usb: device_next: rename the rate properties to use the correct unit
The polling properties are a period in us but are named as "-rate" right
now, which would imply that that's a frequency. Rename them to
"period-us" to make that unambiguous.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2024-06-13 08:03:49 -04:00
Rubin Gerritsen
5098bf3539 Bluetooth: Host: Callback registering functions to return status
Returning a status code will allow the application developer
to detect logic issues.

We consider this as not breaking the API.
If `-Werror -Wunused-result` is enabled, the application developer needs
to validate the return code.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2024-06-13 08:03:28 -04:00
Rubin Gerritsen
3eb975deb2 Bluetooth: Host: Rename callback_list -> conn_cbs
This improves consistency with other callback lists like
scan_cbs and pa_sync_cbs.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2024-06-13 08:03:28 -04:00
Rubin Gerritsen
2ec3cd307c Bluetooth: Host: Avoid registering callback twice
Callbacks can only be registered once. Otherwise the slist
will become circular.

In this commit we have choosen to ignore the second registration
call if the callback has already been registed. The alternative
is to trigger an assertion. That doesn't work if the assertions
are turned off.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2024-06-13 08:03:28 -04:00
Rubin Gerritsen
6e6bb26107 Bluetooth: Host: Conn callback list to use slist
This allows us to use functionality provided by slist.
First use case: Avoid adding an element twice.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2024-06-13 08:03:28 -04:00
Adrien Ricciardi
b76d630682 fs: nvs: Add CRC-32 to protect data
Allow to protect the data part of each NVS item with a 32-bit CRC.
This uses 4 more bytes per NVS item.

Signed-off-by: Adrien Ricciardi <aricciardi@baylibre.com>
2024-06-13 05:51:56 -04:00
Konrad Derda
cb3c087350 net: ipv6: mcast_routing: hop limit handling
While forwarding a multicast packet decrement hop limit in a common net
buffer. Also, packets with hop limit equal to 0 should not be forwarded.

Signed-off-by: Konrad Derda <konrad.derda@nordicsemi.no>
2024-06-13 05:44:30 -04:00
Emil Gydesen
db4d4cfda2 Bluetooth: Audio: Add fallback to cfg_meta_get_pref_context
Added a fallback parameter to
bt_audio_codec_cfg_meta_get_pref_context
as absence of pref context in BAP implicitly means a unspecified
for LC3.

In the case that it is absent BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED
is the returned value.

While the metadata for codec cfg and codec cap are similar,
this only applies for codec cfg as per BAP.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-06-13 05:41:47 -04:00
Emil Gydesen
c4b3b72b07 Bluetooth: Audio: Add fallback to max_codec_frames_per_sdu
Added a fallback parameter to
bt_audio_codec_cap_get_max_codec_frames_per_sdu
as absence of max codec frames per SDU in BAP implicitly
means a single frame for LC3.

In the case that it is absent 1 is the returned value.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-06-13 05:41:47 -04:00
Emil Gydesen
579b4f7e37 Bluetooth: Audio: Add fallback to supported_audio_chan_counts
Added a fallback parameter to
bt_audio_codec_cap_get_supported_audio_chan_counts
as absence of channel count in BAP implicitly means a single channel
for Lc3.

In the case that it is absent 1 is the returned value.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-06-13 05:41:47 -04:00
Emil Gydesen
c6cc034b5c Bluetooth: Audio: Add fallback to get_chan_allocation
Added a fallback parameter to
bt_audio_codec_cfg_get_chan_allocation as absence of
channel allocation in BAP implicitly means Mono.
In the case that it is absent,
BT_AUDIO_LOCATION_MONO_AUDIO is the returned value.

This commit also fixes the implementation of
bt_audio_codec_cfg_get_frame_blocks_per_sdu as it only applies to
LC3 (as per the BAP spec). It also adds additional testing of it

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-06-13 05:41:47 -04:00
Adam Wojasinski
08689e1a20 net: ptp: Network interface status check in PTP thread
Adding network interface status monitor function. Depending
on the interface operation state and change of the state
events are generated and handled by the function.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski
28111ba254 net: ptp: Implement PTP thread
This commit adds implementation of the PTP thread that will
poll sockets descriptors and PTP Port's timeres for timeouts,
generate events and handle them and trigger STATE_DECISION_EVENT
handling when needed.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00