Commit graph

9523 commits

Author SHA1 Message Date
Kyra Lengfeld
64d8713683 Bluetooth: Mesh: use settings priority feature
By using `SETTINGS_STATIC_HANDLER_DEFINE_WITH_CPRIO` we can ensure that
BT subsystems always get loaded after BT, and BT Mesh after both of
them.

This solves the host having to register a GATT service in a delayed
manner, as we are sure to now register the GATT service after sc_commit
sets `SC_LOAD`.

Signed-off-by: Kyra Lengfeld <kyra.lengfeld@nordicsemi.no>
2025-01-14 00:00:56 +01:00
alperen sener
37cdfe818b bluetooth: mesh: fix mesh pb gatt cli uuid usage
uuid needs to be keept in pb_gatt_cli server context until the client
is connected to server, otherwise, since we only kept the pointer from
the net_buffer, any incoming unprovisioned beacon before the connection
is established may overwrite uuid.

Signed-off-by: alperen sener <alperen.sener@nordicsemi.no>
2025-01-14 00:00:44 +01:00
Yago Fontoura do Rosario
9f7736259f Bluetooth: Host: Ensure conn_ready access is thread safe
* The `bt_dev.le.conn_ready` list is accessed by the tx_processor
which runs in a workqueue, but `bt_conn_data_ready` can be called
from different threads so we need to make sure that nothing will
trigger a context switch while we are manipulating the list since
sys_slist_*() functions are not thread safe.
* This only happens if call to `bt_conn_data_ready` is performed
from a preemptive task which can happen depending on the
application.

Signed-off-by: Yago Fontoura do Rosario <yafo@demant.com>
2025-01-13 10:08:55 +01:00
Lyle Zhu
132a24d21c Bluetooth: LE: BAP: Check buf len before using it
Check whether the length of buf is consistent with the valid data
received for op code BT_BAP_BASS_OP_ADD_SRC and BT_BAP_BASS_OP_MOD_SRC.

If the length of buf is inconsistent with the valid data received, the
response is error code BT_ATT_ERR_WRITE_REQ_REJECTED instead of other
errors.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-01-10 14:47:54 +01:00
Emil Gydesen
48ac31c7a2 Bluetooth: TMAP: Remove double definitions of TMAP roles support
Both the TMAP kconfig file and public header file defined
which roles were supported.

The Kconfig file options were recently added and were more
up to date (and correct), and allows for other Kconfig files
to use these values, thus allowing for more flexibility when
implementing applications.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-01-09 15:49:10 +01:00
Emil Gydesen
cc042a6a70 Bluetooth: Host: Refactor provacative comment
There is no reason to call people who disable
asserts for animals.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-01-08 07:51:17 +01:00
Emil Gydesen
e45830893f Bluetooth: CCP: Introduce new CCP API
The CCP API for the Call Control Profile works on top of the
TBS API, and will eventually replace parts of the TBS API.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-01-08 07:50:32 +01:00
Emil Gydesen
a0b1e75268 Bluetooth: MPL: Fix build issues with the MPL shell
If logging (CONFIG_LOGGING) was disabled, then the shell
could not build. Ideally the (test) functions should not
depend on logging, but rather only CONFIG_BT_TESTING.

The shell commands were also properly guarded.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-01-07 00:27:17 +01:00
Vinayak Kariappa Chettimada
9678ff2041 Bluetooth: Controller: Include mem and ecb in-system tests
Include mem and ecb implementation in-system tests.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-01-01 02:04:33 +01:00
Vinayak Kariappa Chettimada
17846ed1f4 Bluetooth: Controller: nRF54L: Fix ecb tag name should be unique
Fix ecb tag name for violation to rule 5.7 (Tag name should
be unique) tag: ecb.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-01-01 02:04:33 +01:00
Vinayak Kariappa Chettimada
de13d36865 Bluetooth: Controller: Refactor isr_ecb and unit testing
Refactor the NRF_ECB isr_ecb function to reduce redundant
common code.

Updated the unit tests to use Bluetooth Specification
defined test vectors.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-01-01 02:04:33 +01:00
Vinayak Kariappa Chettimada
1dfebd6c1a Bluetooth: Controller: Add NRF_ECB crypto support in nRF54L15 SoC
Add NRF_ECB crypto support in nRF54L15 SoCs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-01-01 02:04:33 +01:00
Emil Gydesen
8c38d1b9a3 Bluetooth: TMAP: Add role validation for bt_tmap_register
Add validation that the device supports the role
set by bt_tmap_register.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-12-27 14:09:13 +01:00
Emil Gydesen
abe2e0df57 Bluetooth: BAP: BA: Add validation of add/mod src
The functions did not verify the provided parameters before
sending it as a control point operation.

This also fixes a bug where BT_BAP_BIS_SYNC_NO_PREF was not
allowed when pa_sync=0.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-12-27 14:08:57 +01:00
Emil Gydesen
2b197aff02 Bluetooth: BAP: Modify range of BT_BAP_BROADCAST_SNK_SUBGROUP_COUNT
The range of BT_BAP_BROADCAST_SNK_SUBGROUP_COUNT should be relative to
BT_BAP_BASS_MAX_SUBGROUPS. The broadcast sink depends on the scan
delegator, and thus it does not make sense for the broadcast sink
to support more subgroups than what the scan delegator supports.

Since this no longer relates to the number of streams, there
may be new runtime errors if applications attempt
to sync to more subgroups than the number of ISO channels
supported.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-12-27 12:36:40 +01:00
Théo Battrel
18c2ea2336 Tests: Bluetooth: Check GATT settings cleanup
Check that the GATT settings added when bonding to a peer and
subscribing to a CCC are correctly deleted when calling `bt_unpair`.

Testing hooks have been added in the Bluetooth settings abstraction
layer to know which key are being added/deleted.

Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
2024-12-24 16:07:32 +01:00
Théo Battrel
65334e0104 Bluetooth: Host: Clear settings CF instead of CCC
`bt_gatt_clear_cf` was calling `bt_settings_delete_ccc` instead of
`bt_settings_delete_cf`. This was causing some settings to be left over.

Fix the issue by using the correct function.

Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
2024-12-24 16:07:32 +01:00
Make Shi
3f4ff78c1b Bluetooth: classic: Kconfig: set BT_RFCOMM_DLC_STACK_SIZE default 512
For the shell RFCOMM case, these is a stack overflow problem when do
disconnect, so need to increase the CONFIG_BT_RFCOMM_DLC_STACK_SIZE.
Set CONFIG_BT_RFCOMM_DLC_STACK_SIZE default 512.

Signed-off-by: Make Shi <make.shi@nxp.com>
2024-12-24 04:22:37 +01:00
Szymon Janc
eccd8adc68 Bluetooth: Host: Fix not sending Service Changed indication
gatt_unregister() clears handles if those were auto-assigned by host.
This resulted in Service Changed indication not beding sent since
call to sc_indicate() pass already cleared handles.

This was affecting GATT/SR/GAS/BV-01-C and GATT/SR/GAS/BV-07-C test
cases.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2024-12-23 17:10:28 +01:00
Emil Gydesen
1f4ca01c86 Bluetooth: BAP: Fix BIS_Sync value in update_recv_state_base
The BASE doesn't affect the BIS sync value, and should thus not
change it.

This fixes a bug where the broadcast sink may prematurely
set the BIS sync value to e.g. 1 before actually
syncing to the BIG.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-12-23 13:23:47 +01:00
Mark Wang
19dee0e937 tests: bluetooth: shell: add a2dp new features test
add test for reconfigure, release, suspend, abort and disconnect.
app_config_req and app_reconfig_req always accept the req,
so don't need to handle reject case.

Signed-off-by: Mark Wang <yichang.wang@nxp.com>
2024-12-23 09:15:35 +01:00
Mark Wang
70c73aa317 Bluetooth: A2DP: implement close, suspend and abort
implement avdtp close, suspend and abort and the a2dp
interfaces.

Signed-off-by: Mark Wang <yichang.wang@nxp.com>
2024-12-23 09:15:35 +01:00
Mark Wang
6a6f2c2fca Bluetooth: A2DP: implement reconfig and optimize codes
Implement the bt_a2dp_stream_reconfig: Modify reconfig_req callback to
pass codec_cfg to application. Remove reconfig_rsp callback,
config_rsp is used. Remove reconfigured callback,
configured callback is used.

move the status to common struct bt_avdtp_req,
use same bt_avdtp_ctrl_params to process control-like avdtp
cmds (start, open etc), use the same a2dp_ctrl_ind to process
control-like cmds (start, open etc), use the same
bt_a2dp_ctrl_cb to process control-like cmds (start, open etc),
use the same bt_avdtp_ctrl to process control-like cmds
(start, open etc), optimize getting a2dp conn by index,
use sem to replace mutex and optimze the lock codes to be
based on context/instance.

Signed-off-by: Mark Wang <yichang.wang@nxp.com>
2024-12-23 09:15:35 +01:00
Mark Wang
b8399c31a2 Bluetooth: A2DP: clang-format the codes
run clang-format

Signed-off-by: Mark Wang <yichang.wang@nxp.com>
2024-12-23 09:15:35 +01:00
Aleksander Wasaznik
e8c5405609 Bluetooth: Controller: Fix headroom reservation for ISO
Calling `net_buf_reserve` removed any previous reservation, which
includes the reservation by hci_ipc to hold the H4 type byte. This
resulted in a out-of-bounds net_buf_push in hci_ipc.

This commit also enables asserts in hci_ipc in the audio bsim test,
which reveal the out-of-bounds write.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2024-12-21 05:52:37 +01:00
Make Shi
14e9840a4b Bluetooth: Shell: BR: channel is not used in register command
Cmd_register uses a fixed channel as the rfcomm channel. Cmd_register
doesn't require parameters for channels.

Signed-off-by: Make Shi <make.shi@nxp.com>
2024-12-20 16:06:26 +01:00
Emil Gydesen
6bcfdaf37a Bluetooth: ISO: Add support for cis_established_v2 in host
Add support for the bt_hci_evt_le_cis_established_v2 event in
the host.

This provided additional information to the host and application
about the CIS paramters. Especially the peripheral gets new an
important information such as the SDU size and interval.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-12-20 10:19:23 +01:00
Stine Akredalen
8df332714b bluetooth: mesh: health_cli: Add callback to pull msg for periodic pub
The Health Client model supports periodic publication and thus requires
the update callback to be initialized.

This commit implements a callback inside the health client model and
adds a wrapper to it so that the user can fill up the msg buffer.
This way, the Config Server will always accept
Config Model Publication Set message with periodic publication
parameters. If the users callback returns an error or is not
implemented, the periodic publication will be aborted.

Signed-off-by: Stine Åkredalen <stine.akredalen@nordicsemi.no>
2024-12-20 10:18:54 +01:00
Kyra Lengfeld
b65f53dd76 Bluetooth: Mesh: enable scanner before enabling proxy gatt
Once proxy gatt is enabled, due to the nature of gatt advertisements
being continuous, the controller will reject starting the scanner after
enabling proxy gatt. As such we should start the scanner first.

Currently the order works as we are using k_work to postpone the proxy
gatt service registration, because services can't be registered between
initializing BT and loading the settings.
Once we start using the new settings priority feature, we are sure to
envoke enabling proxy gatt after loading the settings, so the delayed
enabling can and should be removed.

This preventetive fix has been tested by running relevant bsim tests
after rearranging in which order the settings of the subsystems are
loaded via `h_commit`.

Signed-off-by: Kyra Lengfeld <kyra.lengfeld@nordicsemi.no>
2024-12-19 12:37:54 +01:00
Lyle Zhu
830c1f8134 Bluetooth: AVDTP: Check buffer length before pulling it
Check the remaining data length of net buffer before pulling data from
it.

Fixes https://github.com/zephyrproject-rtos/zephyr/issues/83024

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2024-12-18 10:17:45 +01:00
Chang Kim
98928c0a4f bluetooth: host: Add conditions to ATT_READ_BY_TYPE_REQ handler
Core spec V5.4 Vol. 3 Part G 2.5.2.1 Robust Caching specifies
the conditions where Database Out Of Sync (0x12) error needs to
be returned as follows:

If a client that has indicated support for robust caching (by
setting the Robust Caching bit in the Client Supported Features
characteristic) is change-unaware then the server shall send an
ATT_ERROR_RSP PDU with the Error Code parameter set to Database
Out Of Sync (0x12) when either of the following happen:
• That client requests an operation at any Attribute Handle or
list of Attribute Handles by sending an ATT request.
• That client sends an ATT_READ_BY_TYPE_REQ PDU with Attribute
Type other than «Include» or «Characteristic» and an Attribute
Handle range other than 0x0001 to 0xFFFF.

Add the conditions to ATT_READ_BY_TYPE_REQ handler.

Signed-off-by: Chang Kim <changshik@meta.com>
2024-12-17 11:37:27 +00:00
Vinayak Kariappa Chettimada
da792a9e17 Bluetooth: Controller: Fix interleaved extended scanning assert
Fix interleaved extended scanning assert.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2024-12-16 10:53:30 +01:00
Make Shi
7349c8572d Bluetooth: Shell: BR: Set user data size for rfcomm tx pool
The user data size of the RFCOMM tx pool is zero. There is not enough
space to put the tx_meta data. Use CONFIG_BT_CONN_TX_USER_DATA_SIZE to
set the data size for the RFCOMM tx pool.

Signed-off-by: Make Shi <make.shi@nxp.com>
2024-12-16 08:35:10 +01:00
Make Shi
232ecfd880 Bluetooth: L2CAP_BR: Use LOG_WRN for not enough room in user_data
Using LOG_WRN could indicate that something about the user
configuration needs to be changed.

Signed-off-by: Make Shi <make.shi@nxp.com>
2024-12-16 08:34:58 +01:00
Pisit Sawangvonganan
865152fbe2 bluetooth: host: gatt: consolidate net_buf_add call
Consolidate `net_buf_add` calls using known `param->len`
to streamline the codebase.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-12-16 08:34:42 +01:00
Make Shi
345c3f17eb Bluetooth: Shell: BR: Add NULL pointer check for result->resp_buf
In case the peer device has NO SDP record, the result is valid,
but the result->resp_buf is NULL, it would introduce a hardfault.
Therefore, also add a NULL pointer check for result->resp_buf.

Signed-off-by: Make Shi <make.shi@nxp.com>
2024-12-13 09:13:17 +01:00
Abe Kohandel
858ed0e2c3 bt: services: ots: l2cap close handling for read
Ensure OTS current object is returned to idle state when an L2CAP
connection is closed.

Signed-off-by: Abe Kohandel <abe.kohandel@gmail.com>
2024-12-13 04:24:32 +01:00
Andries Kruithof
86ab272286 Bluetooth: Audio: add shell command for distribute broadcast code
Adds a shell command for the distribute broadcast code CAP procedure

Signed-off-by: Andries Kruithof <andries.kruithof@nordicsemi.no>
2024-12-12 16:23:22 +01:00
Sebastian Panceac
f7bae12cef bluetooth: smp: Fix build warnings for central with OOB legacy only
Currently, there are build warnings that are triggered when building
for BT central and legacy OOB pairing only:
CONFIG_BT_SMP_OOB_LEGACY_PAIR_ONLY=y
CONFIG_BT_CENTRAL=y

There was a PR that handled this issue in the past https://github.com/zephyrproject-rtos/zephyr/pull/74400.
Unfortunately, this PR even though it fixed the warnings it also
broke the BT peripheral and legacy OOB pairing only build:
CONFIG_BT_SMP_OOB_LEGACY_PAIR_ONLY=y
CONFIG_BT_PERIPHERAL=y

https://github.com/zephyrproject-rtos/zephyr/pull/82552 was merged in
order to fix the issue with the peripheral build configuration.
Unfortunately, this PR reintroduced the warnings for BT central and
legacy OOB pairing.

This commit brings changes to make sure that both the BT central and
peripheral builds with OOB legacy pairing are buildable and
warnings free.

Also in this commit, a new build test case is added for the BT central
and legacy OOB pairing along the existing BT peripheral test case

Signed-off-by: Sebastian Panceac <sebastian.panceac@ext.grandcentrix.net>
2024-12-12 11:05:38 +01:00
Johan Hedberg
880384a20e Bluetooth: Host: SMP: Verify public key before usage
Add a separate test for public key validity. This needs to be done
synchronously so that we can respond with an early failure message to the
peer device.

Fixes #80218

Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2024-12-11 21:29:08 +01:00
Pisit Sawangvonganan
23b6ab4699 bluetooth: shell: code formatting cleanup in host/shell
Re-ran `clang-format` for consistent styling, simplified
multi-line statements, and consolidated string concatenations
where applicable.
This is a non-functional change focused on code formatting.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-12-11 07:59:30 +01:00
Lyle Zhu
bb417dad1c Bluetooth: SDP: Notify result if error rsp is received.
In current implementation, the SDP response packet will be ignored if
the operation code is `BT_SDP_ERROR_RSP`. And the SDP transaction
request is done, but the application is not notified. And the pending
SDP transaction cannot be processed.

Notify application with empty buffer if the operation code is
`BT_SDP_ERROR_RSP`. And process the pending SDP transaction.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2024-12-10 20:38:30 +01:00
Lyle Zhu
f279f61551 Bluetooth: SDP: Correct record length of service att rsp
The discovered SDP record of service attribute transaction response
cannot notified correctly. There is an error returned from function
`get_record_len()`.

For service attribute transaction response, only one attribute list
is returned. So the total record length is the buffer length. Return
buffer length directly from `get_record_len()` to fix the issue.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2024-12-10 20:38:20 +01:00
Jilay Pandya
1d7826c2ad bluetooth: host: conn.c fix Constant variable guards dead code issue
This commit replaces the assignment of IS_ENABLED(x) macros to
various variables with direct condition checking. This should fix the
coverity issue and also promotes more uniformity in code.

Signed-off-by: Jilay Pandya <jilay.pandya@outlook.com>
2024-12-10 20:38:12 +01:00
Kyra Lengfeld
519f888942 Bluetooth: Mesh: Fix gatt advertiser start in bt_mesh_resume
To signal to the mesh extended advertiser that a proxy advertisement is
started, `bt_mesh_adv_gatt_send()` is called in combination with
setting the `ADV_FLAG_PROXY` flag in adv_ext.c. This ensures that it
won't try to start the advertiser again, which would result in the
controller rejecting it.

Setting this flag outside adv_ext.c is not viable, and as such calling
`bt_mesh_adv_gatt_send()` should also be limited to the advertising
source code.

As it stand now, once we utilize the new commit priority for `h_commit`
calls such a recall of `bt_mesh_adv_gatt_send()` with following
rejection by the controller will happen.

Within the `bt_mesh_resume()` function we can confidently assume the
extended advertiser has already been started. As such we can call
`bt_mesh_adv_gatt_update()` instead of `bt_mesh_adv_gatt_send()`.

This change has been tested with both running relevant bsim tests after
rearranging in which order the settings of the subsystems are loaded via
`h_commit`, as well as a modified light switch sample, adding
`bt_mesh_resume/suspend` calls on buttons.

Signed-off-by: Kyra Lengfeld <kyra.lengfeld@nordicsemi.no>
2024-12-10 16:22:45 +01:00
Pavel Vasilyev
c2488fdd30 bluetooth: buf: Add a callback for freed buffer in rx pool
The Bluetooth data buffer API currently lacks a mechanism to notify when
a buffer is freed in the RX pool. This limitation forces HCI drivers to
adopt inefficient workarounds to manage buffer allocation.

HCI drivers face two suboptimal options:

- Blocking calls: Use bt_buf_get_rx with K_FOREVER, which blocks the
  execution context until a buffer becomes available.
- Polling: Repeatedly call bt_buf_get_rx with K_NO_WAIT, which increases
  CPU load and reduces efficiency.

This commit introduces a callback mechanism that is triggered each time
a buffer is freed in the RX pool. With this feature, HCI drivers can:

- Call bt_buf_get_rx with K_NO_WAIT.
- Wait for the callback notification if a NULL buffer is returned,
  avoiding unnecessary polling.

The new callback improves efficiency by enabling event-driven behavior
for buffer management, reducing CPU overhead while maintaining
responsiveness.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2024-12-10 11:09:36 +01:00
Pisit Sawangvonganan
0156a322b1 bluetooth: host: hci_core: fix num_handles assignment
Replaced `sys_cpu_to_le16(1)` with a direct `1` assignment to the
`cp->num_handles` (uint8_t) field to avoid truncation to `0x00` on
big-endian architectures.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-12-10 11:08:15 +01:00
Lyle Zhu
69d415c9ce Bluetooth: SSP: Improve BR SC only mode
Actively disconnect the connection with error code `BT_HCI_ERR_AUTH_FAIL`
when the notified link key type is not `BT_LK_AUTH_COMBINATION_P256` in
BR SC only mode.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2024-12-10 05:39:10 +01:00
Lyle Zhu
2424bfd869 Bluetooth: BR: improve br_sufficient_key_size
Currently, the minimum value of encryption key size is
`BT_HCI_ENCRYPTION_KEY_SIZE_MIN`.

Add a new Kconfig `BT_BR_MIN_ENC_KEY_SIZE`. It is used to set the
specific minimum encryption key size.
The default value is `BT_SMP_MIN_ENC_KEY_SIZE`. And it can be
configured if `BT_SMP_SC_ONLY` is not enabled.

Use `CONFIG_BT_BR_MIN_ENC_KEY_SIZE` as minimum encryption key size in
`br_sufficient_key_size`.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2024-12-09 15:11:52 +01:00
Andries Kruithof
dd75fc39c3 Bluetooth: Audio: add bt_ prefix when registering logging module
Add the bt_ prefix when registering logging for the media_proxy module,
to be consistent with what the other modules in bluetooth/audio do
Note that the bap_usb module shall not have the bt_ prefix

Signed-off-by: Andries Kruithof <andries.kruithof@nordicsemi.no>
2024-12-09 15:10:57 +01:00