Commit graph

9,920 commits

Author SHA1 Message Date
Emil Gydesen
02d0e96bf1 Bluetooth: BAP: Add bt_bap_unicast_client_unregister_cb
Add bt_bap_unicast_client_unregister_cb to unregister BAP
unicast client callbacks. This is required for unittests
to clean up between runs.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-10-25 15:59:40 +03:00
Vinayak Kariappa Chettimada
4428c1a868 Bluetooth: Controller: nRF54Lx: Enable Controller Privacy Support
Enable Controller Privacy support for nRF54Lx as default.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-10-24 08:50:49 -07:00
Vinayak Kariappa Chettimada
6d79d52118 Bluetooth: Controller: nRF54Lx: Add Controller Privacy Support
Add Controller Privacy support for nRF54Lx by porting to
use NRF_AAR00 h/w peripheral.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-10-24 08:50:49 -07:00
Kai Cheng
038523c63b Bluetooth: Conn: add connection type helper functions
Introduce dedicated helper functions for connection type checking:
- bt_conn_is_br() for BR/EDR connections
- bt_conn_is_le() for LE connections
- bt_conn_is_iso() for ISO connections
- bt_conn_is_sco() for SCO connections

Replace direct conn->type comparisons with these new helper functions
throughout the connection management code. This improves code readability,
maintainability, and provides proper configuration checks for each
connection type.

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2025-10-24 11:34:41 +02:00
Lyle Zhu
74e94fd8e9 Bluetooth: SDP: Optimize functions bt_sdp_get_XXX()
Use a combination of multiple helper functions to implement the
functionality of existing interfaces starting with `bt_sdp_get_`.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-10-24 11:34:32 +02:00
Lyle Zhu
922da6cc4d Bluetooth: classic: shell: Support attribute parsing helper
Update the command `sdp-find` to support attribute parsing helper.
If the argument count is 1, the general SDP discovery will be used
to discover the protocol `L2CAP`.

In the SDP record discovered callback, call attribute parsing helper
functions to parse the SDP record and SDP attributes. And print all
parsed attribute values.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-10-24 11:34:32 +02:00
Lyle Zhu
7f04884eab Bluetooth: SDP: Add helper functions to parse discovered record
The current implementation does not support multiple attributes with
the same attribute identifier in a discovered SDP record.

Add function `bt_sdp_record_parse()` to parse the received SDP record.

Add function `bt_sdp_has_attr()` to check if the specified attribute
identifier has been discovered.

Add function `bt_sdp_get_attr()` to get the attribute of specified
attribute identifier.

Add function `bt_sdp_attr_value_parse()` to parse the attribute value.

Add function `bt_sdp_attr_has_uuid()` to check if the attribute
contains the specified UUID.

Add function `bt_sdp_attr_read()` to read the value of the attribute.

Add function `bt_sdp_attr_addl_proto_parse()` to parse the protocol
descriptor from the additional protocol descriptor list.

Add function `bt_sdp_attr_addl_proto_count()` to get the protocol
descriptor count of the additional protocol descriptor list.

Add function `bt_sdp_attr_addl_proto_read()` to read the attribute
value from the additional protocol descriptor list for specific index
and UUID.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-10-24 11:34:32 +02:00
Lyle Zhu
8365ed718e Bluetooth: Classic: SDP: Add protocol identifier codes
Add all protocol identifier codes defined in Assigned Numbers
specification.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-10-24 11:34:32 +02:00
Ricardo Cañuelo Navarro
61e177f521 Bluetooth: Host: remove unnecessary assignment in bt_conn_unref()
This local pointer assignment does nothing and readers may get a wrong
interpretation of the intention of the function.

Signed-off-by: Ricardo Cañuelo Navarro <rcn@igalia.com>
2025-10-23 18:04:18 +02:00
Vinayak Kariappa Chettimada
d737e285e5 Bluetooth: Controller: Add code comments related to short prepare
Add code comments explaining the handling of short prepare
that can be enqueued out of order and present in use of FIFO
for prepare pipeline.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-10-23 17:56:05 +02:00
Emil Gydesen
f487439fbc Bluetooth: ISO: Fix issue with CIG being terminated
In the case of a CIG having multiple CIS, and all CIS has been
requested to being disconnected (i.e. they all enter the
BT_ISO_STATE_DISCONNECTING state), then when the first disconnect
complete is handled in bt_iso_chan_disconnected, then the
cig->state was prematurely set to BT_ISO_CIG_STATE_INACTIVE.
This meant that if the application called bt_iso_cig_terminate
when the 2nd CIS entered bt_iso_chan_disconnected and called
chan->ops->disconnected(chan, reason) then the CIG would be
removed. When the CIS then entered bt_iso_cleanup_acl, it
would access removed data from cleanup_cig.

Change bt_iso_chan_disconnected to not allow the termination
of the CIG until all CIS have entered the BT_ISO_STATE_DISCONNECTED
state.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-10-23 17:51:18 +02:00
Vinayak Kariappa Chettimada
29cf367568 samples: Bluetooth: hci_ipc: Enable HCI vendor-specific h/w error event
Enable HCI vendor-specific h/w error event generation in
samples and tests.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-10-23 11:43:10 +03:00
Vinayak Kariappa Chettimada
5db80f0d57 Bluetooth: Controller: Reduce assertion check code size
Reduce Controller assertion check code size for ARM Cortex-M
CPUs by using the undefined instruction exception.

`arm-none-eabi-addr2line` commandline can be used to get the
source file and line number.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-10-23 11:43:10 +03:00
Vinayak Kariappa Chettimada
796c0002f8 Bluetooth: Controller: Introduce LL_ASSERT_DBG/ERR
Introduce development and fatal assertion classification
in the Controller implementation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-10-23 11:43:10 +03:00
Vinayak Kariappa Chettimada
625f3052f5 Bluetooth: Controller: nRF54L: Fix PPIB interface include cond compile
Fix trivial PPIB interface include conditional compile.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-10-23 11:41:25 +03:00
Kai Cheng
1de17dcf0a Bluetooth: shell: add sniff mode control command
Add shell command for testing BR/EDR power mode control. Supports
entering sniff mode with configurable parameters (min/max interval,
attempt, timeout) and exiting back to active mode. Provides real-time
feedback on mode change requests and status.

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2025-10-22 18:34:33 +03:00
Kai Cheng
e2f962137f Bluetooth: Classic: add mode change notification for sniff mode
Implement mode change event handling and callback notification for
BR/EDR power mode transitions. Adds br_mode_changed callback to
notify applications when connection switches between active and
sniff modes. Handles HCI mode change events and propagates mode
and interval information to registered callbacks.

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2025-10-22 18:34:33 +03:00
Kai Cheng
84abd9351f Bluetooth: Classic: add power mode control for sniff mode
Implement BR/EDR power mode control with sniff mode functionality.
Adds APIs bt_conn_br_enter_sniff_mode() and bt_conn_br_exit_sniff_mode()
to manage power saving modes. Includes parameter validation and HCI
command handling for sniff mode configuration with min/max intervals,
attempt count, and timeout parameters.

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2025-10-22 18:34:33 +03:00
Håvard Reierstad
b6252b57aa Bluetooth: Host: shell: Don't use BT_FIXED_PASSKEY
Updates the bt shell API to use the new Kconfig option
BT_APP_PASSKEY instead of BT_FIXED_PASSKEY as this is being
deprecated.

Signed-off-by: Håvard Reierstad <haavard.reierstad@nordicsemi.no>
2025-10-22 16:01:08 +03:00
Håvard Reierstad
82cfb5a056 Bluetooth: Host: Deprecate BT_FIXED_PASSKEY
The BT_FIXED_PASSKEY Kconfig option is being deprecated, and is replaced
by BT_APP_PASSKEY. The reason for the deprecation is an upcoming
errata, ES-24489, which mandates that a new passkey shall be generated
for each pairing procedure.

Signed-off-by: Håvard Reierstad <haavard.reierstad@nordicsemi.no>
2025-10-22 16:01:08 +03:00
Håvard Reierstad
6c64054d6e Bluetooth: Host: Add BT_APP_PASSKEY Kconfig option
Adds the BT_APP_PASSKEY Kconfig, which allows the application to provide
passkeys for pairing using the new `app_passkey()` callback.
This is an alternative to BT_FIXED_PASSKEY, which will be deprecated in
a later commit.

Signed-off-by: Håvard Reierstad <haavard.reierstad@nordicsemi.no>
2025-10-22 16:01:08 +03:00
Emil Gydesen
fad9f4d612 Bluetooth: BAP: BASE: Split bt_bap_base_get_base_from_ad
Split the subgroup validation from
bt_bap_base_get_base_from_ad into a new function
base_pull_subgroup to make the function simpler and
make Sonarcloud happy.

The new function, base_pull_subgroup, is also used
in the bt_bap_base_foreach_subgroup to reduce
code duplication.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-10-22 16:00:17 +03:00
Johan Hedberg
0fd8af97fb Bluetooth: Host: Make use of common array helper macros
There's a bunch of convenience macros in sys/util.h that are intended to
help out with translating array indices and determining if an element is
part of an array or not. Use those instead of custom code.

Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2025-10-22 15:54:48 +03:00
Lyle Zhu
99f26b02bd Bluetooth: Classic: HF: Fix invalid query current calls list issue
The current calls list should not be queried if the SLC is not
connected. Or the error `-ENOTCONN` will be returned by function
`hf_query_current_calls()`.

Check the connection status of HF before submitting a delay-able
worker. Only the SLC is established, submit the delay-able worker.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-10-21 11:42:28 +03:00
Lyle Zhu
c8a38806d2 Bluetooth: classic: shell: Add command query_calls for HFP HF
Add the command `query_calls` to query the current calls list.

The received current calls list will be printed in callback
`hf_query_call()`.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-10-21 11:42:28 +03:00
Lyle Zhu
e55bea247b Bluetooth: Classic: HFP_HF: Support users to query current call list
Add the function `bt_hfp_hf_query_list_of_current_calls()` to support
users to query current call list.

Add the callback `bt_hfp_hf_cb::query_call` to notify the received
current calls.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-10-21 11:42:28 +03:00
Ludvig Jordet
cc8ac6bdee Bluetooth: Mesh: Filter duplicates in brg subnets list
This commit adds functionality to filter out duplicate entries in the
Bridged Subnets List message.

This is done by iterating through the part of the table we have already
processed, to check if this is the first time we see a given key pair or
not.

Signed-off-by: Ludvig Jordet <ludvig.jordet@nordicsemi.no>
2025-10-21 11:40:39 +03:00
Mark Wang
5c62e60d6c bluetooth: avdtp: fix the pointer check
should check codec_info_element not *codec_info_element.

Signed-off-by: Mark Wang <yichang.wang@nxp.com>
2025-10-20 11:27:55 -04:00
Cheng Chang
f5dd765e88 bluetooth: shell: a2dp: fix warning when enable sink or source only
add #if defined() to control unused codes.

Signed-off-by: Cheng Chang <cheng.chang@nxp.com>
2025-10-20 11:57:53 +02:00
Lyle Zhu
cf7ab6985f Bluetooth: Classic: HFP: Fix fixed MTU issue
The MTU of HFP HF or AG is fixed value. It cannot be configured.

Fix the issue to make the MTU of RFCOMM is consistency with the MTU
of L2CAP.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-10-20 11:57:26 +02:00
Aleksander Wasaznik
27b56955d6 Bluetooth: Host: Invoke tx callbacks when channel is deleted
When bt_l2cap_send_pdu() succeeds, it transfers buffer ownership to the
stack, which must eventually invoke the provided callback. This contract
is honored in all paths where transmission becomes impossible:

- Normal transmission: callback invoked with err=0 after HCI Number of
  Completed Packets event (tx_notify_process)
- Send errors (after tx allocated): callback invoked with err=-ESHUTDOWN
  via conn_tx_destroy
- Send errors (before tx allocated): callback invoked with the specific
  error code in send_buf error_return path
- Connection disconnect: callbacks invoked with err=-ESHUTDOWN via
  process_unack_tx -> conn_tx_destroy for all PDUs in tx_pending

However, when a channel is deleted (l2cap_chan_del), PDUs remaining in
the tx_queue are dropped without invoking their callbacks, violating the
ownership contract.

Fix this by extracting and invoking any non-NULL callbacks from the
closure stored in buf->user_data before releasing the buffers. The
callback is invoked with err=-ESHUTDOWN, making this path analogous to
process_unack_tx: both drain queues of unsent PDUs when transmission
becomes impossible due to external events (channel deletion vs connection
disconnect). The only difference is the buffer lifecycle stage - in
l2cap_chan_del, PDUs are still in tx_queue (closure in buf->user_data),
while in process_unack_tx, they've progressed to tx_pending (callback in
bt_conn_tx struct).

Note: conn_tx_destroy() cannot be used here because no bt_conn_tx struct
has been allocated yet - the closure is still in buf->user_data.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2025-10-20 11:54:42 +02:00
Aleksander Wasaznik
70dd38a9b4 Bluetooth: Host: Add documentation for L2CAP tx buffer callbacks
Document the ownership contract and callback semantics for L2CAP
transmission buffers:

- Extend tx_queue documentation in bt_l2cap_le_chan to explain SDU/PDU
  storage, callback handling, and transmission order semantics
- Document bt_l2cap_create_frag responsibilities regarding callback
  invocation after HCI Number of Completed Packets or on disconnect
- Document bt_l2cap_send_pdu callback contract: invoked exactly once
  after transmission completes or with -ESHUTDOWN on disconnect

These documentation additions clarify the requirements for proper
buffer lifecycle management and callback invocation throughout the
L2CAP transmission path.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2025-10-20 11:54:42 +02:00
Pavel Vasilyev
a360ff7cc3 bluetooth: mesh: Fix build without settings under asan
When Mesh is built without CONFIG_BT_SETTINGS and with CONFIG_ASAN
(and CONFIG_NO_OPTIMIZATION), the call to bt_mesh_settings_set is not
optimized out. Since settings.c isn’t compiled when CONFIG_BT_SETTINGS
is disabled, the linker reports an undefined reference.

Guard the call with !IS_ENABLED(CONFIG_BT_SETTINGS) so the call and the
subsequent code is compiled out when settings are disabled.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2025-10-17 17:03:06 +03:00
Valerio Setti
019e26aecf bluetooth: mesh: use new Kconfig CONFIG_PSA_CRYPTO
Remove previous Kconfig choices CONFIG_BT_MESH_USES_MBEDTLS_PSA and
CONFIG_BT_MESH_USES_TFM_PSA and use CONFIG_PSA_CRYPTO instead.
This commit also updates test code accordingly.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2025-10-17 11:16:25 +02:00
Valerio Setti
1bc2db575f modules: mbedtls: add new helper Kconfig symbol PSA_CRYPTO
The goal of new Kconfig PSA_CRYPTO_PROVIDER is to automatically enable
any of the PSA Crypto API provider available for the platform without
having the user to manually pick the proper one. This provider can be
either TF-M, if that's enabled in the build, or Mbed TLS otherwise.

PSA_CRYPTO_PROVIDER simplifies also modules/subsystem Kconfigs removing
blocks as:
	select MBEDTLS if !BUILD_WITH_TFM
	select MBEDTLS_PSA_CRYPTO_C if !BUILD_WITH_TFM

Kconfig PSA_CRYPTO_PROVIDER_CUSTOM is also added to allow the end user
to add a custom implementation of PSA Crypto API instead of TF-M or
Mbed TLS ones.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2025-10-17 11:16:25 +02:00
Mark Wang
a713aedb53 bluetooth: a2dp: check the reject response's error code
If the reject response's error codes is success, change as FORMAT ERROR.

Signed-off-by: Mark Wang <yichang.wang@nxp.com>
2025-10-16 17:16:53 +03:00
Mark Wang
60c7ec6915 bluetooth: a2dp: set req->status as 0
create internal bt_a2dp_init_req and bt_a2dp_init_ctrl_req to init `req`,
then the `req->status` will not be forgotten to be cleared as 0.

Signed-off-by: Mark Wang <yichang.wang@nxp.com>
2025-10-16 17:16:53 +03:00
Mark Wang
c994c9e02e bluetooth: a2dp set right endpoint state for start and abort cmd
If the start cmd fail, need set back as OPEN state.

Signed-off-by: Mark Wang <yichang.wang@nxp.com>
2025-10-16 17:16:53 +03:00
Lyle Zhu
40bba4057f Bluetooth: Classic: HFP_HF: Fix AT+CLCC can not be sent issue
Due to the flag `BT_HFP_HF_FLAG_CLCC_PENDING` is set when receiving
the +CIEV or +CIND notification, the command `AT+CLCC` will be
pending due to the flag is not cleared.

Add a flag `BT_HFP_HF_FLAG_INITIATING` to indicate the HF
initialization is ongoing.

Add a flag `BT_HFP_HF_FLAG_QUERY_CALLS` to indicate the current calls
list needs to be queried.

Set the flag `BT_HFP_HF_FLAG_INITIATING` at the beginning of the HF
initialization. Set the flag `BT_HFP_HF_FLAG_QUERY_CALLS` instead of
setting the flag `BT_HFP_HF_FLAG_CLCC_PENDING` if the current calls
list needs to be queried and the flag `BT_HFP_HF_FLAG_INITIATING` is
set.

After the HF initialization is done, query list of the current calls
by calling the function `hf_query_current_calls()` if the flag
`BT_HFP_HF_FLAG_QUERY_CALLS` is set.

Set the flag `BT_HFP_HF_FLAG_CLCC_PENDING` if it is not set in the
function `hf_query_current_calls()`.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-10-16 17:15:51 +03:00
Emil Gydesen
572d4d438b Bluetooth: BAP: BA: Improve some logging
Fix additional space in active receive states.
Add additional information when logging duplicate
broadcasts.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-10-16 17:14:20 +03:00
Emil Gydesen
cb9c64947f Bluetooth: CAP: Add missing failed_conn for reception_start
When cap_commander_broadcast_reception_start is called during the
handover, the failed_conn was not correctly.
It is now being set by cap_commander_broadcast_reception_start
and if that is called via handover, it will be correctly set.
If it is called via bt_cap_commander_broadcast_reception_start
then it will be cleared in case of error.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-10-16 17:14:08 +03:00
Flavio Ceolin
dabe815663 bt: host/classic: Fix possible integer overflow
Invalid header length and cause an integer overflow in
bt_br_acl_recv leading to undesired behavior.

Signed-off-by: Flavio Ceolin <flavio@hubblenetwork.com>
2025-10-15 11:46:13 -04:00
Ludvig Jordet
f998357015 Bluetooth: Mesh: Minor cleanup of prov link close on success
Changes the link close upon success to use the `prov_link_close` helper
function instead of doing it manually, as minor cleanup.

Signed-off-by: Ludvig Jordet <ludvig.jordet@nordicsemi.no>
2025-10-15 11:43:00 -04:00
Ludvig Jordet
1c6f98aaf2 Bluetooth: Mesh: Provisioner closes link on failed
According to MshPrt 5.4.4, The Provisioner, upon receiving the
Provisioning Failed PDU, shall assume that the provisioning failed and
immediately disconnect the provisioning bearer.

Signed-off-by: Ludvig Jordet <ludvig.jordet@nordicsemi.no>
2025-10-15 11:43:00 -04:00
Emil Gydesen
0ebe84cc5a Bluetooth: Host: bt_iso_reset before bt_conn_cleanup_all
Move the call to bt_iso_reset to before bt_conn_cleanup_all.
The reason for this is that bt_conn_cleanup_all will disconnect
all the ACL connections, which will put the CIS in a disconnecting
state, without finalizing them.
This means that if we get a num_completed_packet event between
the call to bt_conn_cleanup_all and before the BT_HCI_OP_RESET
request has been completed, we will trigger an assert in the
hci_num_completed_packets function as the CIS still exists,
but where we would already have cleaned up the pending TX
without telling the controller.

Moving the call to bt_iso_reset means that the CIS will have
been fully terminated at this point, which will prevent
the assert from happening. Since CIS depends on ACLs, this
is also the logical order for resetting them.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-10-15 15:37:21 +03:00
Mark Wang
b3d56349a1 bluetooth: shell: a2dp: use static for functions
add static for functions and variables.

Signed-off-by: Mark Wang <yichang.wang@nxp.com>
(cherry picked from commit 1282bf7b8d814ef7a217c6f0c424aa4b2f34d363)
2025-10-15 12:06:56 +03:00
Mark Wang
a1cbaf77a6 bluetooth: shell: a2dp: remove unused function
remove app_configured

Signed-off-by: Mark Wang <yichang.wang@nxp.com>
(cherry picked from commit c0be42f10341ea4a6ed1df152375335a5f514c92)
2025-10-15 12:06:56 +03:00
Mark Wang
e468dd3371 bluetooth: avdtp: add copyright
add copyright to avdtp.c

Signed-off-by: Mark Wang <yichang.wang@nxp.com>
(cherry picked from commit 8761b2884726ccc33f953e4679a3d9c86b17da84)
2025-10-15 12:06:56 +03:00
Mark Wang
ef1b4463aa bluetooth: a2dp: remove the digital hardcode
use the sizeof of struct or variable; use macro to do the data shift.

Signed-off-by: Mark Wang <yichang.wang@nxp.com>
(cherry picked from commit d6d567355d08cefd1e11d88563fc300928af4972)
2025-10-15 12:06:56 +03:00
Mark Wang
642dc278d1 bluetooth: a2dp: save configuration when cmd success
In the cmd result callback, save the configuration to stream if result is
success.

Signed-off-by: Mark Wang <yichang.wang@nxp.com>
(cherry picked from commit 9a9477fa0214f245a66e24a2edd90132293d5086)
2025-10-15 12:06:56 +03:00