Commit graph

9523 commits

Author SHA1 Message Date
Pavel Vasilyev
038173acda bluetooth: mesh: proxy_msg: check that att mtu is big enough
This commit checks that ATT MTU value returned by `bt_gatt_get_mtu` is
greater or equal to 3 to prevent integer overflow.

Fixes #84693
Coverity-CID: 487743

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2025-02-10 22:26:31 +01:00
Pavel Vasilyev
fcf09dd0ad bluetooth: mesh: pb_adv: ensure that bitwise NOT doesn't result in 0
Ensure that ~(link.rx.seg) & SEG_NVAL doesn't result in 0.

Fixes #84804
Coverity-CID: 393090

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2025-02-10 22:26:31 +01:00
Emil Gydesen
446ad0948d Bluetooth: PACS: Test and fix PACS Kconfig combinations
Add unit tests for all possible PACS combinations and
fix issues found.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-02-10 22:25:47 +01:00
Emil Gydesen
e7b6fd0b4b Bluetooth: PACS: Fix several issues with pacs_register
Fixed the following issues:
1) Missing guard before accessing parameters
2) Fixed bad sizeof when resetting
3) Fixed several bad offsets when removing attributes

Added tests to verify that it works now.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-02-10 22:25:47 +01:00
Emil Gydesen
09fb5338f8 Bluetooth: ATT: Disconnect ATT and ACL when receiving inval rsp
When we receive a response from a server we do not have an
outstanding request with, we disconnect the connection
rather than just ignoring it.

The reason for this is that the remote server is
not ensuring correct ATT flow control, which means
that we cannot trust future responses from the
server.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-02-10 15:56:34 +00:00
alperen sener
22de0b3732 bluetooth: host/crypto: fix the psa crypto init for host
psa_crypto_init was bounded to CONFIG_BT_HOST_CRYPTO_PRNG and
used to be called under prng_init. Updating the ifdef condition
and appropriating the function name for crypto init.

Also it is better to make sure psa_crypto_init called by host.

Signed-off-by: alperen sener <alperen.sener@nordicsemi.no>
2025-02-10 14:33:24 +01:00
Mariusz Skamra
6723625336 Bluetooth: Controller: Fix LE Create BIG Complete event parameter
This fixes uninitialized iso_interval parameter in
bt_hci_evt_le_big_complete.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2025-02-10 14:33:12 +01:00
Mariusz Skamra
27c18adf28 Bluetooth: monitor: Fix SEGGER RTT compilation error
This fixes out of scope IRQ lock key by using SEGGER_RTT_Write
version that locks the IRQ by itself.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2025-02-10 14:33:01 +01:00
Jordan Yates
7365bcf133 bluetooth: host: hci_core: add missing NULL check
Add check that the command buffer claimed in `bt_le_create_conn_cancel`
is not `NULL`. Fixes a fault caused by providing the `NULL` buffer to
`bt_hci_cmd_state_set_init`.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2025-02-10 03:41:16 +01:00
Thomas Deppe
f3bdd2bc8c Bluetooth: Host: Add support for Advertising Coding Selection
Adds API for Advertising Coding Selection.

Introduces two new advertising options to configure the advertiser's
requirement concerning coding scheme when LE Coded PHY is configured.
While the Bluetooth v6.0 specification makes a distinction betweeen
preferred and required advertising PHY options, a simplification is
made to only expose the required PHY options. Inline with how LE Coded
PHY is implemented; this API will set both the primary and secondary
advertising PHY's to the same coding scheme.

The support is enabled by CONFIG_BT_EXT_ADV_CODING_SELECTION, and requires
a controller that selects CONFIG_BT_CTLR_ADV_EXT_CODING_SELECTION_SUPPORT.

Signed-off-by: Thomas Deppe <thomas.deppe@nordicsemi.no>
2025-02-08 10:09:41 +01:00
Emil Gydesen
4451cee955 Bluetooth: ISO: Shell: Fix underflow of count for TX
The cmd_broadcast and cmd_send both should not take a
count value less than 1.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-02-08 10:08:52 +01:00
Tom Hughes
14fe06e453 Bluetooth: ISO: Fix -Wsometimes-uninitialized warning
Building sample.bluetooth.tmap_central with clang warns:

subsys/bluetooth/host/iso.c:2194:6: error: variable 'rsp' is used
uninitialized whenever 'if' condition is false
[-Werror,-Wsometimes-uninitialized]
        if (!advanced) {
            ^~~~~~~~~
subsys/bluetooth/host/iso.c:2202:6: note: uninitialized use occurs here
        if (rsp == NULL) {
            ^~~
subsys/bluetooth/host/iso.c:2194:2: note: remove the 'if' if its
condition is always true
        if (!advanced) {
        ^~~~~~~~~~~~~~~
subsys/bluetooth/host/iso.c:2137:21: note: initialize the variable 'rsp'
to silence this warning
        struct net_buf *rsp;
                           ^
                            = NULL
subsys/bluetooth/host/iso.c:2295:6: error: variable 'rsp' is used
uninitialized whenever 'if' condition is false
[-Werror,-Wsometimes-uninitialized]
        if (!advanced) {
            ^~~~~~~~~
subsys/bluetooth/host/iso.c:2303:6: note: uninitialized use occurs here
        if (rsp == NULL) {
            ^~~
subsys/bluetooth/host/iso.c:2295:2: note: remove the 'if' if its
condition is always true
        if (!advanced) {
        ^~~~~~~~~~~~~~~
subsys/bluetooth/host/iso.c:2258:21: note: initialize the variable 'rsp'
to silence this warning
        struct net_buf *rsp;
                           ^
                            = NULL

Signed-off-by: Tom Hughes <tomhughes@chromium.org>
2025-02-08 08:14:26 +01:00
Emil Gydesen
4fc6f127e6 Bluetooth: TBS: Fix return value of handle_string_long_read
The function may return a BT_GATT_ERR which is a negative
value that cannot be returned as uint8_t. Change the function
to use int instead and document the return values.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-02-08 08:13:28 +01:00
Emil Gydesen
f53c4db874 Bluetooth: CSIP: Update documentation for CSIP crypto functions
The encryption functions should document the expect byte order of
inputs and the byte order of the outputs.

The sef and sdf functions were also using an older, and incorrect,
description of the input, as it only takes the LTK as per CSIP 1.0.0

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-02-08 08:13:17 +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
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
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
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
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
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
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
Andrzej Głąbek
dff78b4813 bluetooth: host: Add select PSA_WANT_ALG_ECB_NO_PADDING
This is a follow-up to commit 12eee61533.

Explicitly enable "PSA_WANT_ALG_ECB_NO_PADDING" to select the AES ECB
mode that it is used in CMAC operation.

This is done because CMAC uses AES-ECB, so both AES and ECB must
be explicitly enabled. Previously it worked because Mbed TLS is
not currently performing any check internally on this and it's
just enabling ECB automatically.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2025-01-30 11:15:24 +01:00
Théo Battrel
972d4c7369 Bluetooth: Host: GAP Device Name write now add null char at the end
The function used to write the value of the GAP Device Name
characteristic now ensure that the string passed to `bt_set_name` is
null terminated.

Also fix a wrong offset calculation.

The function used to write the value of the GAP Device Name
characteristic was returning an error when the offset + the length of
data to write was superior **or equal** to the maximum size of the
device name.

This caused the actual maximum device name size to be reduced by 1 byte.

Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
2025-01-30 11:15:03 +01:00
Emil Gydesen
21be69f172 Bluetooth: PACS: Fix issue with PACS flags
The PACS flags were incorrectly defined without
ATOMIC_DEFINE and then it treated the atomit_t as an
array with the atomic functions.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-01-29 15:13:29 +01:00
Tim Sørensen
ff2605d23e Bluetooth: CTS: Incorrect assert in bt_cts_init()
Fixup for incorrect assert in CTS service
initialization function bt_cts_init().

Signed-off-by: Tim Sørensen <tims@demant.com>
2025-01-29 12:51:30 +01:00
Emil Gydesen
9688c2d43f Bluetooth: CCP: Initial CCP Client implemenation
Added initial CCP client implementation that simply
does discovery of TBS on a remote CCP server.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-01-28 09:46:39 +01:00
Johan Hedberg
8b356fd9fb Bluetooth: Host: Fix overwriting ECC error value
Jump straight to the exit portion of the function in the case that
psa_destroy_key() failed and we set err to a non-zero value. This also
fixes Coverity CID 487701 "Code maintainability issues  (UNUSED_VALUE)".

Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2025-01-28 00:06:06 +01:00
Johan Hedberg
3ae8a9cfe1 Bluetooth: Host: Remove leftover HCI ECC command checks
The code shouldn't be checking for HCI command support anymore, rather in
the case of debug keys we can just start immediately using them.

Fixes commit 09e86f3b69.

Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2025-01-27 13:26:40 +01:00
Valerio Setti
222f8d87b5 Bluetooth: Host: add PSA_WANT_xxx_IMPORT/EXPORT to BT_ECC
The BT Host module also uses import/export PSA functions alongside the
generate one, so these PSA_WANT should be added as well.

Previously it happened to work only because Mbed TLS is enabling
IMPORT/EXPORT internally whenever GENERATE/DERIVE is set. However the
same might not be true for all PSA Crypto providers.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2025-01-27 11:07:07 +01:00
Dominik Ermel
49f5598835 Bluetooth: Mesh: Improve logic for serving devices erase capabilities
The commit fixes issue where flash_area_flatten has been used where
code was only supposed to erase devices by hardware requirement prior
to write, by replacing the call with flash_area_erase and supporting
logic to select proper path.
There have been following Kconfig options added:
 - CONFIG_BT_MESH_BLOB_IO_FLASH_WITHOUT_ERASE
 - CONFIG_BT_MESH_BLOB_IO_FLASH_WITH_ERASE
that are available for user depending on devices in the system and allow
to turn off paths that are not used by BLOB IO; for example if user
never writes to device with erase CONFIG_BT_MESH_BLOB_IO_FLASH_WITH_ERASE
will disable the path.
Both Kconfig options are y by default and enable all paths.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2025-01-23 19:25:27 +01:00
Johan Hedberg
d3c8cb4b79 Bluetooth: Host: Remove prompt from BT_ECC
This option only exposes internal APIs, so there should be no need to allow
applications to set an explicit value. Instead, users of the API should
select it through Kconfig.

Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2025-01-23 10:14:46 +01:00
Johan Hedberg
09e86f3b69 Bluetooth: Host: Remove HCI ECC emulation
Remove the HCI command & event emulation layer for ECDH commands and
events. This means that we always do the necessary operations in the host.
The existing BT_ECC Kconfig option stays, but now gets automatically
enabled when necessary (e.g. based on the BT_SMP option), which is why this
commit removes so many explicit assignments in prj.conf files.

Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2025-01-23 10:14:46 +01:00
Vinayak Kariappa Chettimada
7573ac521d Bluetooth: Controller: Fix regression in Code PHY S2 Rx to any PHY Tx
Fix regression in Coded PHY S2 reception to any other PHY Tx
in the s/w switch implementation.

Regression in commit 55b7dba8ec ("Bluetooth: Controller:
Refactor sw_switch hal interface use").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-01-23 05:23:39 +01:00
Aleksandr Khromykh
a8e540c371 Bluetooth: Mesh: remove experimental flag from mbedtls support
Commit removes experimental flag from mbedtls psa
crypto library support.

Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
2025-01-22 18:32:51 +01:00
Alberto Escolar Piedras
196062580f Bluetooth: Controller: Use cracen entropy driver for 54L devices
Use the new entropy driver for 54L devices and therefore
claim BT_CTLR_ENTROPY_SUPPORT is always supported
(note 54H remains unsuported)

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-01-22 18:32:35 +01:00
Alberto Escolar Piedras
f4cdb0f07e boards nrf54l15bsim: Default to new cracen rng driver
Let's default to this new driver.
And therefore change the conditions in the BT controller kconfig
which were selecting the native_posix fake entropy driver

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-01-22 18:32:35 +01:00
Fredrik Danebjer
21b5f0c4fe Bluetooth: pacs: Add dynamic PACS registration
Added option to set the PACS Characteristics through the bap API,
making PACS configuration runtime available. Source and Sink PAC, as
well as Source/Sink PAC Location is can be set through a register
function in the PACS api.

Signed-off-by: Fredrik Danebjer <frdn@demant.com>
2025-01-22 15:49:50 +01:00
Alberto Escolar Piedras
0c32349722 Bluetooth: Controller: Correct nrf54l15bsim timings
Correct the timings in the radio HAL for the simulated nRF54L15

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-01-22 10:40:17 +01:00