Commit graph

9787 commits

Author SHA1 Message Date
Michał Stasiak
32a4c9cb79 bluetooth: controller: remove select of ENTROPY_NRF_CRACEN_CTR_DRBG
ENTROPY_NRF_CRACEN_CTR_DRBG symbol is based on devicetree
node with compatible nordic,nrf-cracen-ctrdrbg. It does not
have to be selected explicitly.

Signed-off-by: Michał Stasiak <michal.stasiak@nordicsemi.no>
2025-03-19 10:57:18 +01:00
Emil Gydesen
065dca7e92 Bluetooth: ISO: Make setting ISO data explicit
The stack will no longer implicitly set the data path
for ISO channel, and the responsibility for doing that is
now for the upper layers/applications.

This provides additional flexibility for the higher layers
as they can better control the values and timing of the data
path, as well as support removing and even reconfiguring the
data path at will.
This also removes some complexity from the stack.

This commit also fixed a inconsistency in the disconnected
handler. CIS for centrals as well as BIS were still valid
bt_iso_chan channels in the disconnected callback,
but CIS for peripherals were completely cleaned up at this
point. This issue is fixed by moving the disconnected callback
handling to before the code to cleanup the channel for
peripherals.

Since there is a difference in how you remove data paths
depending on the GAP role (central/peripheral), the
iso_info struct type has been expanded to be more
concise of which type of CIS it is.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-03-19 10:56:57 +01:00
Troels Nilsson
48fd8874e9 Bluetooth: Host: Fix missing endianness conversion for ISO ts
The timestamp was missing an endianness conversion

Signed-off-by: Troels Nilsson <trnn@demant.com>
2025-03-18 19:54:24 +01:00
Johan Hedberg
81e7569fa1 Bluetooth: Host: Fix format specifier warnings
Use %zu for size_t and %zd for ssize_t, and don't use those specifiers for
any other type. Also make sure that field width specifiers get typecast to
the expected int type.

Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2025-03-18 16:45:29 +01:00
Emil Gydesen
fb68b4be7e Revert "Bluetooth: Audio: Use generic count_bits to count bits"
This reverts commit ee335399c1.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-03-18 16:39:47 +01:00
Emil Gydesen
ee335399c1 Bluetooth: Audio: Use generic count_bits to count bits
Instead of re-implementing or assuming that POPCOUNT is available
we now use the generic function from Zephyr.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-03-17 21:03:56 -04:00
Vinayak Kariappa Chettimada
0a4480ce61 Bluetooth: Controller: Fix connection update interval_us variables
Fix connection update microsecond interval variable data
type, to use 32-bit so that a value upto 2000 seconds, i.e.
4 seconds interval and 499 peripheral latency can be stored.

Regression in commit abfe5f17a9 ("Bluetooth: Controller:
1 ms connection").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-03-17 20:00:42 +01:00
Alberto Escolar Piedras
1dab77b49f Bluetooth: Host: ATT: Fix build warning with clang
Fix the following warning
att.c:734:3: warning: label followed by a declaration is a C23 extension
[-Wc23-extensions]
  734 |                 k_tid_t current_thread = k_current_get();
      |                 ^
By wrapping that code as a compound statement

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-03-17 16:25:33 +01:00
Vinayak Kariappa Chettimada
374d41a9c1 Bluetooth: Controller: ISO Receive interleaved packing support
Add ISO Receive interleaved packing support in Lower Link
Layer implementation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-03-17 16:24:33 +01:00
Vinayak Kariappa Chettimada
5b74950857 Bluetooth: Controller: ISO Broadcast interleaved packing support
Add ISO Broadcast interleaved packing support in Lower Link
Layer implementation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-03-17 16:24:33 +01:00
Vinayak Kariappa Chettimada
4243cb5df6 Bluetooth: Controller: Fix BIS interleaved packing sub_interval calc
Fix BIS sub_interval calculation for interleaved packing.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-03-17 16:24:33 +01:00
Lyle Zhu
1708574d0a Bluetooth: BR: Add a function bt_br_bond_exists()
Add a function `bt_br_bond_exists()` to check if the address of the
classic device has been bonded.

Update release-notes-4.2.rst

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-03-17 14:08:04 +01:00
Timothy Keys
7ef8116969 bluetooth: host: Remove experimental flag from LE Connection Subrating
The API has not changed since it was introduced so should no longer be
considered experimental.

Signed-off-by: Timothy Keys <timothy.keys@nordicsemi.no>
2025-03-17 13:57:03 +01:00
Lyle Zhu
d42294d809 Bluetooth: SMP_BR: Use macros instead of hard code
Define macros for encryption value,
#define BT_HCI_ENCRYPTION_OFF           0x00
#define BT_HCI_ENCRYPTION_ON_LE_AES_CCM 0x01
#define BT_HCI_ENCRYPTION_ON_BR_E0      0x01
#define BT_HCI_ENCRYPTION_ON_BR_AES_CCM 0x02

Use the macros to replace the hard code.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-03-17 07:04:58 +01:00
Lyle Zhu
af86a35b61 Bluetooth: SMP_BR: Avoid to derive LTK from invalid BR LK
The LTK should not be generated from BR link key if there is a LTK
exists and BR LK is weaker.

Do not drive LTK from BR LK in the case.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-03-17 07:04:58 +01:00
Herman Berget
8b909b4403 Bluetooth: Host: Remove experimental label from PAwR
The api has not changed since its introduction some time ago,
mark it as stable.

Signed-off-by: Herman Berget <herman.berget@nordicsemi.no>
2025-03-14 17:56:18 +01:00
Pavel Vasilyev
886fabaf87 bluetooth: host: ecc: Change log level debug
This commit changes log level for already registered callback from
warning to debug as this is cause unnecessary noise and doesn't indicate
actual issue. Caller gets a certain error code for this case which can
be handled properly.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2025-03-14 14:40:34 +01:00
Lyle Zhu
218de8dc67 Bluetooth: L2CAP_BR: Code format
Change ```#if defined(CONFIG_BT_L2CAP_DYNAMIC_CHANNEL)
#if defined(CONFIG_BT_L2CAP_LOG_LEVEL_DBG)```
to `#if defined(CONFIG_BT_L2CAP_DYNAMIC_CHANNEL) &&
defined(CONFIG_BT_L2CAP_LOG_LEVEL_DBG)`.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-03-14 05:47:48 +01:00
Lyle Zhu
d82844695e Bluetooth: L2CAP_BR: CID of data sending is invalid
There is a corner case that the channel is in disconnecting status,
due to there is a disconnect request sent from peer.
At this time, the channel is status is `BT_L2CAP_CONNECTED`. But it
has been removed from `conn->channels` by calling the function
`l2cap_br_remove_tx_cid`.
And the disconnect event is notified upper layer via the callback
`ops->disconnected`. The thread of the callback context is blocked
due to the the calling of `printk` in the callback function.

Then the pending lower priority thread, sending the data in this
l2cap channel, is activated. Then in the function
`bt_l2cap_br_send_cb`, a NULL pointer will be got according to the
given CID. And unexpected behavior happens when accessing a NULL
pointer, since the invalid channel pointer is not checked in
function `bt_l2cap_br_send_cb`.

Check the channel pointer after function `bt_l2cap_br_lookup_tx_cid`
called. If the channel pointer is invalid, return error code
`-ESHUTDOWN` directly.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-03-14 05:47:36 +01:00
Emil Gydesen
501b95ff9b Bluetooth: CSIP: Rename BT_CSIP_SET_MEMBER_NOTIFIABLE
Renamed BT_CSIP_SET_MEMBER_NOTIFIABLE to
BT_CSIP_SET_MEMBER_SIRK_NOTIFIABLE to be more specific.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-03-13 16:56:14 +00:00
Lyle Zhu
2ac116ea71 Bluetooth: SMP_BR: Derive LTK after LK refreshed
When the link key of BR is upgraded, the encrypt key refresh event
will be notified. The link key is upgraded from weak to strong.
The LTK of LE should be derived from strong link key.

Start SMP pairing procedure to try to derive LTK from LK.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-03-13 10:49:58 +01:00
Pavel Vasilyev
d3997c6eb0 bluetooth: mesh: set subscription address on response
This fixes an issue where a subsequent Config Model Subscription Add
message with the same virtual address UUID would result in a Config
Model Subscription Status message with the Address field incorrectly set
to 0.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2025-03-13 10:49:48 +01:00
Emil Gydesen
5918427278 Bluetooth: Host: Make bt_le_addr_is_bonded public
Some GATT services and profiles define specific behavior
based on whether the remote device is bonded or not.
The internal function, bt_addr_le_is_bonded, is the
only function to do this, but it was kept internal,
and could thus not be used for those services
without including hci_core.h.

The function has been moved to the public API
so that application can determine if a remote
address is bonded or not, and has been renamed
to not use the bt_addr namespace, but rather the
bt_le.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-03-13 10:48:19 +01:00
Emil Gydesen
1f26899229 Bluetooth: TBS: Ensure sending notifications
The existing implemented only attempted to send all notifications,
but if host was out of ATT TX buffers the notifications would fail
and the client may miss out on important information, and would be
a spec violation.

This commit refactors notificatios in TBS so that they are always
sent.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-03-13 10:27:59 +01:00
Lyle Zhu
9a04dfd85e Bluetooth: l2CAP_BR: Fix the response cannot be sent out issue
There is an issue that the L2CAP connect response function
`l2cap_br_conn_req_reply()` is called first. And then the ACL
disconnect function `bt_conn_disconnect()` is called following. But
the packet of `bt_conn_disconnect()` appears on the HCI bus first.

Add a flag `L2CAP_FLAG_DISCONNECT_ACL` to flag whether it is needed to
disconnect ACL connection.

Set the flag `L2CAP_FLAG_DISCONNECT_ACL` when result of the L2CAP
channel conn rsp is `BT_L2CAP_BR_ERR_SEC_BLOCK`.

Add a l2cap packet sent out callback `l2cap_br_conn_rsp_sent_cb()`.
When the callback triggered, disconnect the ACL connect with
`BT_HCI_ERR_AUTH_FAIL` if the flag `L2CAP_FLAG_DISCONNECT_ACL` has
been set.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-03-12 19:03:05 +01:00
Nirav Agrawal
438701fdd5 bluetooth: host: perform hci-reset in bt_disable()
- added HCI command to send hci-reset in bt_disable() func, and
  remove its call from the driver close() call.
- remove rsp buf pass to 'hci_reset_complete()' func as status is
  already checked under 'bt_hci_cmd_send_sync()'.

Signed-off-by: Nirav Agrawal <nirav.agrawal@nxp.com>
2025-03-12 19:02:35 +01:00
Lyle Zhu
f349976937 Bluetooth: SSP: Fix MITM flag incorrect issue in pairing
There is a case that if the local is a peripheral and a L2CAP server
with the security level 3,the mitm should be set to make sure the
security level can reach level 3.

But in current implementation, the MITM is not set because the MITM
of `Authentication_Requirements` parameter of remote is not set. And
the security level will be level 2 after the security pairing
procedure complete.

Add a function `bt_l2cap_br_get_max_sec_level` to
get the max level of the registered servers.
`
Force set the MITM bit if the max level is bigger than level 2 and
pairing method is not `just works`.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-03-12 07:14:25 +01:00
Alberto Escolar Piedras
c1a40abc6d subsys/bluetooth: Misc native_posix cleanup
Remove a kconfig dependency on BOARD_NATIVE_POSIX which
does not really exist anymore.
Replace a comment mention of native_posix with native_posix.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-03-12 02:27:36 +01:00
Lyle Zhu
d811f6921c Bluetooth: L2CAP_BR: Reject the conn req if sec levels do not match
If the ACL link has been encrypted and it has a authenticated link key,
it means the pairing procedure has been done. And the security level of
the link key can not be upgraded. In this case, if `conn->sec_level` is
less than the required security level of the L2CAP channel, reject the
L2CAP conn request.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-03-11 18:53:50 +01:00
Olivier Lesage
6f33793b41 bluetooth: Host: Rename CS tone antenna configurations
Improves readability by removing the need to check the table
to figure out how many antennas devices A and B are using.

Signed-off-by: Olivier Lesage <olivier.lesage@nordicsemi.no>
2025-03-11 08:59:19 +01:00
Emil Gydesen
9d4cc4b49b Bluetooth: BAP: Add a set of suggested intervals to use with BAP
Add a selection of interval values that are suitable for BAP,
which will allow better coexistence between ISO and ACL,
for both broadcast and unicast. Some of these are defined
by the BAP spec, and some are defined by Zephyr, since they
do have a suggested value from BAP.

Samples and tests have been updated to use these new values.
Peripheral samples have also been updated with
CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS so that the connection
parameters from the centrals aren't updated to something else
shortly after.

The shell has also been updated to use the LE Audio (BAP) values
if audio is enabled, and the audio.conf file has disabled automatic
updating of the connection parameters as the peripheral, as we rarely
(if ever) want to do that.

Due to the connection interval change, CI hit an issue
with test_bass_broadcast_code in test_main_client_sync, where
the reading of the long receive state did not finish before we
attempted to do another procedure, so the function was updated to have
a retry.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-03-11 08:58:51 +01:00
Lyle Zhu
1cfd624b3d Bluetooth: SDP: Notify upper layer if the response data len is 0
In current implementation, the SDP discovery complete event is not
notified when the response data length is 0.

Notify the discovery complete event if the response length is 0.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-03-10 21:49:41 +01:00
Thomas Deppe
4161ba2103 Bluetooth: Host: Fix Advertising Coding Selection as peripheral
Fix mistake in host implementation of Advertising Coding Selection.

The host should only try set the BT_LE_FEAT_BIT_ADV_CODING_SEL_HOST
when the observer role is enabled. If a broadcaster enables the
CONFIG_BT_EXT_ADV_CODING_SELECTION Kconfig option bluetooth will
fail to initialise.

Signed-off-by: Thomas Deppe <thomas.deppe@nordicsemi.no>
2025-03-10 21:31:12 +01:00
Lyle Zhu
ed45960870 Bluetooth: SDP: Fix the issue of not handling the next discovery req
The pending discovery request will not be handled in some cases.
The cases include,
- The received data length is not aligned with frame length
- The continuation status length is more than maximum value
- Total length of the response is less than the frame length
- Unknown operation code is received

There is also a case where the current discovery result was not
notified when processing the pending discovery request.
The cases include,
- Fail to send SDP request
- No tail room of received buffer to save the response data

Fix the issue by using the following steps,
- Notify the application that the discovery is done
- Process the pending discovery request

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-03-10 15:20:40 +01:00
Lyle Zhu
dcd8bcb88d Bluetooth: SSP: Reply a negative rsp if binding flags are mismatched
If the remote is in bondable mode, but the local is in non-bondable
mode, the local host shall respond to an IO capability request with
a negative response.

In current implementation, it does not check the bonding flags of the
both sides are consistent.

Fix the issue by checking the consistency of bonding flags of the both
sides. If they are not consistent, send a negative IO capability
response with the reason pairing not allowed.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-03-10 15:03:04 +01:00
Lyle Zhu
1408614fd2 Bluetooth: SSP: bt_conn_unref is missing if pairing is not accepted
The `conn` is found by using function `bt_conn_lookup_addr_br()`, it
should be released by calling `bt_conn_unref()`. But `bt_conn_unref()`
is missing in the case that the pairing is not accepted.

Release the `conn` by calling `bt_conn_unref()` before exiting the
function `bt_hci_io_capa_req`.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-03-10 15:02:48 +01:00
Lyle Zhu
0d36361b5d Bluetooth: SDP: Check data len consistency between total and received
Add fields `total_len` and `recv_len` to `struct bt_sdp_client`.

Save the total length of the response to `total_len`.
Save the received data length of the response to the `recv_len`.

Check the consistency between `total_len` and `recv_len` after all of
the response packets are received.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-03-10 08:58:38 +01:00
Rubin Gerritsen
65c7f1f269 Bluetooth: Controller: Kconfig: Add dependencies to ISO configs
The ISO configs set defaults based upon BT_ISO_MAX_CHAN and other
configs defined in `bluetooth/Kconfig.iso`.

By adding these dependencies the error messages resulting from
adding `CONFIG_BT_CTLR_PERIPHERAL_ISO=y` to a project configuration
file will become less confusing.

Now the build will output:
```
warning: BT_CTLR_PERIPHERAL_ISO (
defined at subsys/bluetooth/controller/Kconfig:976,
subsys/bluetooth/controller/Kconfig:984) was assigned the value 'y' but
got the value 'n'. See ...
```

Previously we would get:
```
warning: default value 0 on BT_CTLR_CONN_ISO_STREAMS
(defined at subsys/bluetooth/controller/Kconfig:993)
clamped to 1 due to being outside the active range ([1, 64])
```

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2025-03-07 20:35:45 +01:00
Lyle Zhu
1aa88f86b8 Bluetooth: SDP: Ignore the unexpected response
The response should not be handled if there is not a request has been
sent.

Ignore the response if the `session->param` is `NULL`.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-03-07 20:18:51 +01:00
Lyle Zhu
86b765c0a9 Bluetooth: SDP: Ignore unsupported UUID
In current implementation, if the UUID of request is unknown, the
local variable `u` will not be updated, and the unknown UUID `u`
is used as the target to search it in the SDP record list. It may
result in irrelevant record being replied to the requester.

Ignore the unsupported UUID to fix the issue.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-03-07 20:18:31 +01:00
Lyle Zhu
7ec9f58b66 Bluetooth: SDP: Fix the error if continuation length is not 0
When the continuation length is not 0, there is a reported error.

In current implementation, the total length is only valid only when
the frame is the first block of the SDP response. For following
continuous frame, the total length is 0.

So, change the condition to `(total != 0 && frame_len > total)`.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-03-07 20:16:38 +01:00
Troels Nilsson
8373f19bc2 Bluetooth: Controller: Add tests covering ticker without remainder support
Update Kconfig to not select BT_TICKER_REMAINDER_SUPPORT for nrf54L

Add BSim tests to cover using a ticker without BT_TICKER_REMAINDER_SUPPORT
and expire info enabled

Signed-off-by: Troels Nilsson <trnn@demant.com>
2025-03-07 20:02:49 +01:00
Troels Nilsson
df67f4ec13 Bluetooth: Controller: Fix building ticker without remainder support
A few things were not flagged by CONFIG_BT_TICKER_REMAINDER_SUPPORT
that should have been; This caused building without it to fail

Initialize remainder to 0 where used with ticker_next_slot_get_ext(),
since it may not get set if remainder support is off

Signed-off-by: Troels Nilsson <trnn@demant.com>
2025-03-07 20:02:49 +01:00
Théo Battrel
158870ec64 Bluetooth: Host: Use memset to initialize psa_mac_operation_t
In `db_hash_setup()` the state object for MAC operations was initialized
using `psa_mac_operation_init()`. This function was not always optimized
or inlined.

A way to reduce stack usage is to use `memset()` and set the object to
0. This is one of the option documented to initialize
`psa_mac_operation_t` object.

Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
2025-03-07 19:59:24 +01:00
Emil Gydesen
1a6af2bfa6 Bluetooth: Audio: Modifed PAST checks to use public API
Use the recently added bt_le_get_local_features function as well
as bt_conn_get_remote_info to avoid using internal APIs to
check for PAST supported.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-03-07 19:58:23 +01:00
Emil Gydesen
4619611326 Bluetooth: Conn: Add const for conn in bt_conn_get_remote_info
The connection object is, and should not, be modified by the function.
Making it const makes it possible to do this simple operation
in functions that also won't change the conn object (i.e.
that uses `const`).

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-03-07 19:58:23 +01:00
Emil Gydesen
44c5c1da3d Bluetooth: Host: Add API for reading LE controller features
The function supports reading multiple controller-based values.
It is effectively a copy of struct bt_dev_le but in a more
application-oriented definition.

It was chosen to keep the features as an array rather than a
64-bit value, as the comparison macros work on arrays and that
there already exists new bits > 64 in the core spec which is not
yet supported by Zephyr.

It is being smoke tested in a generic GATT client test,
as the individual values may depend on several Kconfig options.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-03-07 19:58:23 +01:00
Aleksandr Khromykh
e075e08195 Bluetooth: Mesh: remove api prefix for static functions
Commit removes api prefix for static functions
in crypto psa.

Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
2025-03-07 19:58:10 +01:00
Lyle Zhu
c0f7aefe55 Bluetooth: BR: Support limited discoverable mode
Add a Kconfig BT_LIMITED_DISCOVERABLE_DURATION to set the timeout for
limited discoverable mode.

Add a argument `limited` to function `bt_br_set_discoverable()` to
support the limited discoverable mode.
When enabling discoverable mode with `limited` is true, both write
LIAC and GIAC to controller and set the bit 13 of COD in function
`bt_br_set_discoverable()`. And start a delay worker with the timeout
CONFIG_BT_LIMITED_DISCOVERABLE_DURATION to disable the discoverable
mode.
When disabling discoverable mode, only set GIAC to controller and
clear bit 13 of COD.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-03-07 19:46:53 +01:00
Mark Wang
37ae587b64 bluetooth: avdtp: move the buf as callback parameter
if saving buf to another variable, usually the ref/unref
needs to be used. change to pass the buf as one parameter
of callback

Signed-off-by: Mark Wang <yichang.wang@nxp.com>
2025-03-07 19:45:20 +01:00