rootcause: The dynamic L2CAP channel rx.cid is not reset, it
will be intercepted by the judgment condition of the fixed channel,
directly using the last alloced cid may cause cid conflict.
Co-authored-by: zhenwei fang <fangzhenwei@bytedance.com>
Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
When limited advertising is enabled there is pending deleyable work
for timing it out. If in such case struct bt_le_ext_adv is cleared by
memset system will crash on next tick.
Fix this by ensuring work is cancelled before clearing struct
bt_le_ext_adv. Using bt_le_ext_adv_foreach() ensures that this will
be correctly handled with and without extended advertising enabled.
Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
When creating the audio connection, the SCO connection request will be
sent before the response "OK" to AT command "AT+BCS" is issued.
It causes the issue that the HFP HF cannot response the SCO connection
request with the correct codec. Then the SCO connection cannot be
established properly.
Put all processing into the same context, thus avoiding non-sequential
execution caused by the different priorities of different threads.
Add a flag `BT_HFP_AG_AT_PROCESS` to flag the AT command is being
processed.
When the flag `BT_HFP_AG_AT_PROCESS` is set, put the pending
executions into temp list `tx_submit_pending`. After the AT response
`OK` or `ERROR` has been sent, move the pending executions from
`tx_submit_pending` to `tx_pending`.
Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
Fix use-after-release in lll_scan/lll_scan_aux when using
mayfly_enqueue to defer execution of the offset calculation
using ull_sched_mfy_after_cen_offset_get().
Apply suggestion from @Copilot
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
If the CIG and ACL overlap each other when the CIS is starting
zephyr will assert on negative time, so fit this special case.
Signed-off-by: Lars Segerlund <lrsu@demant.com>
When multiple relay adv sets are used, the bt_mesh_adv_send function
calls bt_mesh_adv_relay_ready which should distribute relayed
advertisements across all relay adv sets.
Until the submitted relay adv set work is started, the ADV_FLAG_ACTIVE
is not set. Therefore, next call to bt_mesh_adv_send will try to
re-submit the same relay adv set work, instead of picking up another
relay set which is actually free and ready to send an advertisement.
This commit adds a check that checks if the adv set work is already
pending to be executed. And if so, schedule_send returns false to make
bt_mesh_adv_relay_ready pick next relay adv set.
This shouldn't brake advertising because once adv set is done
transmitting advertisment, it will pick up a next one.
The ADV_FLAG_PROXY check is added to do re-submit for adv set which was
used for proxy advertisement since we need to prioritize mesh messages
over proxy advertisements when those are running on the same adv set.
Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
The `bt_le_ext_adv_update_param` will set new random address when option
not select `BT_LE_ADV_OPT_USE_IDENTITY`, But `bt_le_ext_adv_start` will
also set random address again.
This will be affect bluetooth mesh, after this change, will ensure address
only change once for every advertising.
Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
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>