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>
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>
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>
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>
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>
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>
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>
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>
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>
Introduce development and fatal assertion classification
in the Controller implementation.
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
Fix additional space in active receive states.
Add additional information when logging duplicate
broadcasts.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
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>
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>
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>
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>
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>
add static for functions and variables.
Signed-off-by: Mark Wang <yichang.wang@nxp.com>
(cherry picked from commit 1282bf7b8d814ef7a217c6f0c424aa4b2f34d363)
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)
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)