Commit graph

9787 commits

Author SHA1 Message Date
Vinayak Kariappa Chettimada
8ebc4f3384 Bluetooth: Controller: Fix sync_delay and latency in LE BIG Complete
Fix missing sync_delay and transport_latency information in HCI
LE BIG Complete event.

Relates to commit 1a640e4711 ("Bluetooth: controller:
Included transport latency in LE_Big_Established").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-02-12 12:23:51 +01:00
Vinayak Kariappa Chettimada
83e2ec3c9b Bluetooth: Controller: Fix device address in Periodic Adv Sync
Fix incorrect device address reported in the LE Periodic
Advertising Sync Established event when using Periodic
Advertiser List.

During Extended Scanning there can be an ADV_EXT_IND PDU
received between currently being received ADV_EXT_IND PDU
and AUX_ADV_IND PDU; if the one received between has an
address match then incorrectly the Periodic Synchronization
was established to the device whos AUX_ADV_IND PDU is being
received. Fix by storing the auxiliary context that has the
address match and compare with it when matching the SID in
SyncInfo of AUX_ADV_IND PDU being received prior to creating
the synchronization.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-02-12 12:22:52 +01:00
Vinayak Kariappa Chettimada
5119896c7d Bluetooth: Controller: Fix BT_CTLR_LOW_LAT_ULL conditional code
Fix BT_CTLR_LOW_LAT_ULL conditional compilation code by
decoupling it from BT_CTLR_LOW_LAT code.

BT_CTLR_LOW_LAT_ULL makes ULL execution context to tailchain
in comparison to continuously process in a while loop.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-02-12 12:22:18 +01:00
Emil Gydesen
49d9b4cb69 Bluetooth: PACS: Remove BAP infix for pacs_register_param
Since the PACS service is not part of the bt_bap API it should
not use the bt_bap prefix, and instead just be bt_pacs like the
rest of the PACS API.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-02-12 09:41:49 +01:00
Johan Hedberg
90367c8dd1 Bluetooth: Host: Classic: Fix allocated PSM comparison
The code for checking for allocated BR/EDR PSMs was potentially resulting
in an integer overflow, due to doing a <= UINT16_MAX (0xffff) comparison
on a uint16_t variable. To avoid this, use a uint32_t variable internally.

Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2025-02-12 02:26:57 +01:00
Emil Gydesen
b67d291207 Bluetooth: Host: Add type check for bt_conn API
Added a new function, bt_conn_is_type, that returns whether
the provided conn object is of the provided type.

This check is then used to ensure that the conn objects
supplied to other bt_conn function are of the right type.
The right type has also been documented for these functions.

This is an initial commit for a larger change in the BT Host,
as similar checks should be added to the L2CAP, GATT, ISO,
Audio and possibly Mesh APIs.

The type check could have been implemented by using the
bt_conn_get_info function, but that requires additional
function calls as well as memory allocation and copy.
Since bt_conn_is_type is designed to be widely used, it
was suited for its own function.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-02-11 22:04:51 +01:00
Aleksandr Khromykh
4bb595718d Bluetooth: Mesh: remove double cdb node storing
Commit removes the double cdb node entry storing
into the settings if device was reprovisioned over
nppi interface.

Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
2025-02-11 18:56:37 +01:00
Emil Gydesen
788486b972 Bluetooth: ISO: Add range to BT_ISO_MAX_BIG
If BT_ISO_BROADCAST is enabled, then we shall support
at least 1 BIG and at most BT_EXT_ADV_MAX_ADV_SET since
each BIG requires its own advertising set.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-02-11 15:42:03 +01:00
Lingao Meng
f5bd2170d1 tests: bsim: Add testcase for bluetooth mesh extended advertiser
Add some configuration for test adv_ext.c

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2025-02-11 15:38:35 +01:00
Lingao Meng
2ebdcfa963 Bluetooth: Mesh: Remove START_PENDING flags
Remove START_PENDING flag, and replace with
bt_mesh_adv_is_empty_by_tag

not only make adv_ext.c more readable, but also enhancement

In previous implementation, after proxy started, will check
this flag, and when the flag is true, will direct stop proxy
and re-enter schedule, but has one problem, this flag set true,
but buf will be empty, such as when sending mesh relay messages
will for-each every sets, until find not-active, but also set
previous set START_PENDING flags, so will cause proxy advertising
started->stop->started.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2025-02-11 15:38:35 +01:00
Lingao Meng
bcac572ab4 Bluetooth: Mesh: Remove ADV_FLAG_PROXY_START, due to meanless
The first why introduce ADV_FLAG_PROXY_START
see here(https://github.com/zephyrproject-rtos/zephyr/pull/58826)

The main core change is to mark ADV_FLAG_PROXY as moving to the last
enabled proxy instead of before.

But introducing the ADV_FLAG_PROXY_START flag seems meaningless.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2025-02-11 15:38:35 +01:00
Tom Hughes
8218bf6b0a Bluetooth: TBS: Fix -Wsometimes-uninitialized warning
Building bluetooth.shell.audio.only_gtbs with clang warns:

subsys/bluetooth/audio/tbs.c:1646:6: error: variable 'ret' is used
uninitialized whenever 'if' condition is false
[-Werror,-Wsometimes-uninitialized]
        if (param->gtbs) {
            ^~~~~~~~~~~
subsys/bluetooth/audio/tbs.c:1667:9: note: uninitialized use occurs here
        return ret;
               ^~~
subsys/bluetooth/audio/tbs.c:1646:2: note: remove the 'if' if its
condition is always true
        if (param->gtbs) {
        ^~~~~~~~~~~~~~~~~
subsys/bluetooth/audio/tbs.c:1626:9: note: initialize the variable 'ret'
to silence this warning
        int ret;
               ^
                = 0

Signed-off-by: Tom Hughes <tomhughes@chromium.org>
2025-02-11 03:07:39 +01:00
Emil Gydesen
9fca7ee3a5 Bluetooth: Controller: Fix casting in radio_aa_set for BASE0
We have previously fixed an issue with shifting and
assigning the value without a cast, but coverity
is still complaining about aa[1] and aa[0] with:

"Casting narrower unsigned aa[1] to wider signed type
int effectively tests its lower bound."

Using the common function, sys_get_le24, should fix this issue.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-02-11 03:07:27 +01:00
Pavel Vasilyev
b7f16f1041 bluetooth: mesh: delayable_msg: cast to avoid truncation issue
Explicitly cast Kconfig option value to avoid truncation issue reported
by Coverity.

Fixes #84697
Coverity-CID: 487737

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2025-02-10 22:26:31 +01:00
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