Commit graph

9523 commits

Author SHA1 Message Date
Emil Gydesen
3e0c08caec Bluetooth: CAP: Fix log warning for meta pointer
Fixes the following warning:
<wrn> cbprintf_package: cbprintf_package_convert:
  (unsigned) char * used for %p argument. It's recommended
  to cast it to void * because it may cause misbehavior in
  certain configurations. String:"%s: meta %p len %zu" argument:1

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-12-09 09:50:12 +01:00
Théo Battrel
30928c21f0 Bluetooth: Host: Remove unnecessary #ifndef
The functions `le_sc_oob_config_set`, `generate_dhkey` and
`display_passkey` in `smp.c` were only defined when
`CONFIG_BT_SMP_OOB_LEGACY_PAIR_ONLY` was not defined. This created
issues at build time.

Remove the guard as the code calling those functions is not guarded
itself.

Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
2024-12-06 18:20:21 +01:00
Emil Gydesen
56e7b7708e Bluetooth: Host: Add adv == NULL checks in adv.c
Added null checks for adv pointer in the extended and
periodic advertising functions.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-12-06 15:17:41 +01:00
Emil Gydesen
829519dd6f Bluetooth: BAP: Add broadcast sink callback structs
These callbacks are trigger for changes that affect the entire
broadcast sink, such as the BIG synced and terminated events.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-12-06 15:17:06 +01:00
Emil Gydesen
0ae976166f Bluetooth: CAP: Add broadcast source callback structs
These callbacks are trigger for changes that affect the entire
broadcast source, such as the BIG started and terminated events.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-12-06 15:17:06 +01:00
Emil Gydesen
ab9ee0817d Bluetooth: BAP: Add broadcast source callback structs
These callbacks are trigger for changes that affect the entire
broadcast source, such as the BIG started and terminated events.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-12-06 15:17:06 +01:00
Emil Gydesen
e8bcb29f3f Bluetooth: ISO: Add BIG callbacks
Add callbacks that is called for the entire BIG.
The BIG state is from an HCI perspective a single state change
that we previously only propagated as a state change for each
channel.

However it may be simpler for applications and higher layers
to use BIG changes to trigger their behavior.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-12-06 15:17:06 +01:00
Timothy Keys
b3ffaf4441 Bluetooth: Host: Cancel pending deferred work on disconnect
This fixes an issue that occurred if deferred_work is queued by another
procedure before we run bt_conn_set_state(BT_CONN_DISCONNECTED).
bt_conn_set_state yields to the system work queue in bt_conn_tx_notify,
and then deferred_work runs and handles the disconnected callbacks.
bt_conn_set_state then enqueues another deferred_work which calls the
disconnected callbacks again and causes an assert. k_work_cancel_delayable
will clear queued deferred work when we call
bt_conn_set_state(BT_CONN_DISCONNECTED), guaranteeing that the disconnect
callbacks will only be called once.

Signed-off-by: Timothy Keys <timothy.keys@nordicsemi.no>
2024-12-06 15:16:43 +01:00
Lyle Zhu
d37402f447 Bluetooth: Shell: BR: Update command sdp-find
Since the function `bt_sdp_discover` has been updated, the caller of
function needs to be updated to avoid the building and functionality
fault.

Add set the parameter `type` to value
`BT_SDP_DISCOVER_SERVICE_SEARCH_ATTR`.

Update the SDP discovery callback function. Make it align with
`bt_sdp_discover_func_t`.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2024-12-06 12:14:29 +01:00
Lyle Zhu
a047113556 Bluetooth: Classic: SDP: Improve SDP discover
Extend the function `bt_sdp_discover` to support service search
transaction and service attribute transaction.

Improve the `session->rec_buf`. If the net buffer cannot be allocated
from the channel, disconnect the SDP session.

Set the `MaximumAttributeByteCount` of the request
`SDP_SERVICE_SEARCH_ATTR_REQ` with the tail room of `session->rec_buf`.

Set the `MaximumAttributeByteCount` of the request `SDP_SERVICE_ATTR_REQ`
with the tail room of `session->rec_buf`.

Set the `MaximumServiceRecordCount` of the request
`SDP_SERVICE_SEARCH_REQ` according to the tail room of
`session->rec_buf`.

Handle the response code `SDP_SERVICE_SEARCH_RSP`, and
`SDP_SERVICE_ATTR_RSP`.

Handle the error `SDP_ERROR_RSP`. Start the next SDP discovery if the
error received.

If there no more request, disconnect the session.

If the request cannot be sent, start the next SDP discovery.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2024-12-06 12:14:29 +01:00
Pisit Sawangvonganan
aa1a38e2aa bluetooth: shell: refactor shell print to eliminate ctx_shell usage
This change aims to eliminate the dependency on `ctx_shell` in
the Bluetooth `host/shell/*`, making the code more maintainable.
Replaced `shell_*` functions that depended on `ctx_shell` with
the appropriate `bt_shell_*` functions.

The shell-less functions `bt_do_scan_filter_clear_name`, `bt_do_scan_off`,
and `bt_do_connect_le` were added so they can be called without `sh`.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-12-05 22:10:54 +01:00
Pisit Sawangvonganan
471feb2094 bluetooth: shell: replace ctx_shell with sh where applicable
Limit the usage of `ctx_shell` to cases where printing requires it
and `sh` is not available.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-12-05 22:10:54 +01:00
Pisit Sawangvonganan
28ca65de1c bluetooth: shell: add bt_shell_private.c and bt_shell_private.h
Introduced `bt_shell_private.c` and `bt_shell_private.h` to provide
common functions for the Bluetooth `shell_wall_print`.
These functions are equivalent to `shell_fprintf`, `shell_info`,
`shell_print`, `shell_warn`, `shell_error` and `shell_hexdump`
but without requiring the `sh` parameter.

The cost of the newly added `bt_shell_fprintf_info` ... `_error` functions
will be negligible when there are many individual calls that need to pass
both the `sh` and `color` parameters each time.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-12-05 22:10:54 +01:00
Vinayak Kariappa Chettimada
643ad148f1 Bluetooth: Controller: Fix reschedule for ticker that yield
Fix reschedule for ticker that yield such that reduce the
slot window after intersection to include required
ticks_slot, and we do not take the interval of the
colliding ticker provided every expiry increments the
interval by random amount of ticks. This is the case for
primary channel advertising.

Fixes commit e1cd5ba77f59 ("Bluetooth: Controller: Fix to
reschedule after overlap when yielding").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2024-12-05 15:18:11 +01:00
Olivier Lesage
3feb1378d6 bluetooth: host: simplify enums for SNR control
It works the same on both sides, so there's no point having two of
these.

Signed-off-by: Olivier Lesage <olivier.lesage@nordicsemi.no>
2024-12-05 12:30:09 +01:00
Sergey Korotkov
2ee0e38929 Bluetooth: Host: more secure defaults for key size and legacy pairing
Default the Minimum encryption key size to 16.
Key with reduced size is easier to brut force.
Disable LE legacy pairing by default since it's not secure.

These defaults should suite majority of newly developed applications.
It's better to use sensible more secure defaults,
so applications that really need less secure option consciously change it,
not the other way around.
This may help to prevent downgrade attacks.

Signed-off-by: Sergey Korotkov <sergey.korotkov@nordicsemi.no>
2024-12-04 12:10:54 +01:00
Stine Akredalen
6c0306622e Bluetooth: fix GATT service reregistering
* Fixed issue with reregistering of GATT services.
* Added unit tests covering the GATT reregistering scenario.

Signed-off-by: Stine Åkredalen <stine.akredalen@nordicsemi.no>
2024-12-04 12:10:22 +01:00
Emil Gydesen
a3f4ab6b5e Bluetooth: ISO: Add dbg of create BIG params
Log the create BIG params for debugging purposes.
Also slightly modifies the `qos` struct to use a more
suitable struct to avoid always doing `qos->tx->` and
can now just be `qos->`.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-12-04 12:09:29 +01:00
alperen sener
e653a39ed7 Bluetooth: Mesh: Check that required models exists on the same element
Referring to MshDFU_v1.0 Sections 6.1.1, 6.2.1 and  7.1.1 model
descriptions: DFU/DFD server/clients extend BLOB Transfer root models
and DFD server requires Firmware Update Client on the same element. For
this reason we need to make sure that those main models or root models
exist on the same element. And also firmware update client can not be
forced to be in the first element.

For all model extention call return the error code in case of an error.

Signed-off-by: alperen sener <alperen.sener@nordicsemi.no>
2024-12-04 09:23:44 +01:00
Zihao Gao
4557b2f06c Bluetooth: AVRCP: add buffer length protections.
Add sanity checks for AVRCP responses received.

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2024-12-03 10:17:09 +01:00
Zihao Gao
cb0b472ccc Bluetooth: AVRCP: fix AVRCP timeout handler.
It is recommended to record the subunit type itself instead of the
subunit ID when validating the transaction. This approach is more
meaningful and less prone to misinterpretation.

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2024-12-03 10:17:09 +01:00
Zihao Gao
17897071c1 Bluetooth: AVRCP: implementation for subunit info command.
This patch alllows to acquire the subunit info from the remote device.

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2024-12-03 10:17:09 +01:00
Johan Hedberg
8b02141ca7 Bluetooth: Controller: Replace BT_CTLR with HAS_BT_CTLR
Deprecate BT_CTLR, and add a new HAS_BT_CTLR as a virtual option which
specific users (like BT_LL_SW_SPLIT) select. This also means that we can
remove all places that were forcefully enabling the BT_CTLR option, and
instead we now depend on devicetree to get some local LL HCI driver
enabled which in turn also enables the HAS_BT_CTLR option.

Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2024-12-03 10:16:44 +01:00
Håvard Reierstad
5a02aaa47e Bluetooth: Mesh: Trim _USES_MBEDTLS_PSA selects
Removes legacy configuration options. The same coverage is provided by
existing PSA_WANT_... selects.

Signed-off-by: Håvard Reierstad <haavard.reierstad@nordicsemi.no>
2024-12-02 09:42:45 +01:00
Pieter De Gendt
e9e64bab35 drivers: bluetooth: hci: Place API into iterable section
Add wrapper DEVICE_API macro to all bt_hci_driver_api instances.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2024-11-29 14:49:53 +01:00
Ludvig Jordet
88f62a1a5e Bluetooth: Mesh: Fix cfg_cli KRP not working for key_net_idx != 0
Initializes the `net_idx` field of the ack context properly for KRP
functions in the Config Client.

This fixes a problem where `bt_mesh_cfg_cli_krp_get` and
`bt_mesh_cfg_cli_krp_set` would always fail the ack ctx comparison if
`key_net_idx` was != 0.

Signed-off-by: Ludvig Jordet <ludvig.jordet@nordicsemi.no>
2024-11-29 14:49:34 +01:00
Valerio Setti
3bf9a14f98 Bluetooth: Host: increase BT_LONG_WQ stack size when using ECC emulation
After the switch from TinyCrypt to PSA Crypto API as crypto
backend, runtime crashes might happen on some platform due
to BT_LONG_WQ's stack size not being large enough. This
commit fixes this issue.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2024-11-28 15:38:57 +00:00
Valerio Setti
5790de6d6a Bluetooth: Host: use P256-M in ECC emulation
When BT_SEND_ECC_EMULATION and the platform uses Mbed TLS as PSA
Crypto provider, we select the Cortex-M software optimized
implementation of the secp256r1 curve algorithms. This is much
faster than the standard support provided by Mbed TLS and it
also reduces ROM footprint.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2024-11-28 15:38:57 +00:00
Pavel Vasilyev
1eeee010bd bluetooth: mesh: cfg_cli: Update logs when pulling out CDP0 and 1
This commits puts in order log messages when unpacking CDP0 and CDP1 so
that it a bit more clear where the error happens.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2024-11-28 12:50:58 +01:00
Pavel Vasilyev
e2a0fafe42 bluetooth: mesh: cfg_cli: Check buf len when pulling out data
This commit checks that config client doesn't pull out data outside of
the buffer.

Fixes #80012

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2024-11-28 12:50:58 +01:00
Pavel Vasilyev
2041682900 bluetooth: mesh: brg_cfg_cli: Initialize prohibited value
Coverity complains about uninitialized prohibited fields. Even though it
is not used because it is "prohibited", it is simpler to just
initialized it with the value received from a server.

Fixes #81939
Coverity-CID: 434649

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2024-11-28 09:43:48 +01:00
Pavel Vasilyev
f5409bd3de bluetooth: mesh: proxy_msg: Fix extracting role from k_work
Fix extracting role from k_work.
Hot fix for #78914

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2024-11-27 22:51:40 -05:00
Pavel Vasilyev
684c94e469 bluetooth: mesh: gatt: Move generic GATT related defines to gatt.h
This moves GATT releated defines that are used by both Mesh Proxy
Service and Mesh Provisioning Service implementations to a common
header file.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2024-11-27 22:51:29 -05:00
Pavel Vasilyev
ab346a1dd0 bluetooth: mesh: Use bt_get_name to get device name
By default if CONFIG_BT_MESH_PROXY_USE_DEVICE_NAME
or CONFIG_BT_MESH_PB_GATT_USE_DEVICE_NAME is enabled, the mesh stack
will add BT_DATA_NAME_COMPLETE AD Type along with the Mesh Proxy Service
or Mesh Provisioning Service advertisements accordingly.

When BT_LE_ADV_OPT_USE_NAME was present and
CONFIG_BT_DEVICE_NAME_DYNAMIC is enabled, the advertised name was
automatically updated by the host. This turned out to be a side-effect
rather than expected behavior and after #71700 this behavior waa
changed.

But customers use dynamic name feature.

This commit makes the mesh stack use bt_get_name to get the device name,
which returns runtime name if CONFIG_BT_DEVICE_NAME_DYNAMIC is enabled.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2024-11-27 22:51:29 -05:00
Valerio Setti
1b672491f1 bt: change dependencies for BT_RPA
Since the TinyCrypt library is being deprecated in Zephyr, this
commit modified the dependencies of BT_RPA. Instead of selecting
TinyCrypt, it relies on BT_HOST_CRYPTO or BT_CTLR_CRYPTO. This
helps both in the deprecation process of TinyCrypt, but also this
is more correct dependency since these 2 symbols are extensively
used in the rpa.c source code.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2024-11-27 16:40:47 -05:00
Valerio Setti
0f4875b7d0 bt-mesh: deprecate BT_MESH_USES_TINYCRYPT
Since the TinyCrypt library is being deprecated in Zephyr, this
commit set TinyCrypt usage in BT mesh as deprecated and it sets
Mbed TLS PSA Crypto API as the default option (when TF-M is not
available).
Tests are also updated in this commit.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2024-11-27 16:40:47 -05:00
Valerio Setti
f4592382bb bt: use PSA for HCI ECC and rename BT_TINYCRYPT_ECC
This commit sets PSA Crypto API as the default library to perform
ECC-DH in HCI, replacing TinyCrypt (which is being deprecated).
Therefore the symbol BT_TINYCRYPT_ECC is renamed as BT_SEND_ECC_EMULATION.
References in samples/tests are also fixed.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2024-11-27 16:40:47 -05:00
Valerio Setti
da9ab6f593 bt: crypto/host: remove CONFIG_BT_USE_PSA_API symbol
CONFIG_BT_USE_PSA_API was used in BT crypto/host modules to select
PSA crypto API over TinyCrypt (which was the default until now).
Since TinyCrypt is being deprecated and PSA crypto API is the new
standard library for crypto operations, CONFIG_BT_USE_PSA_API is
no more needed.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2024-11-27 16:40:47 -05:00
Rubin Gerritsen
56a22cbccb Bluetooth: Host: Log when connecting while scanning may give bad params
The API documentation already states that the controller may require
the scan interval and window used for scanning and connection
establishment to be equal to obtain the best performance.

This commit prints out a warning when this is not the case. The code
size is unchanged when `CONFIG_BT_SCAN_AND_INITIATE_IN_PARALLEL=n`.

This makes application developers aware that using the parameters
`BT_LE_SCAN_ACTIVE_CONTINUOUS` with `BT_CONN_LE_CREATE_CONN` may not
give the best performance.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2024-11-27 10:38:27 -05:00
Olivier Lesage
480f8aa887 bluetooth: host: Use LOG_WRN for failed CS procedures
These can indicate that something about the user configuration needs to
be changed.

Signed-off-by: Olivier Lesage <olivier.lesage@nordicsemi.no>
2024-11-27 10:31:25 +01:00
Théo Battrel
66ff97e69b Bluetooth: Host: Deprecate BT_BUF_ACL_RX_COUNT symbol
Because the number of ACL RX buffers must be at least the number of
maximum connections plus one, increasing `CONFIG_BT_MAX_CONN` could
inadvertently lead to a build failure if the number of ACL RX buffers is
not also increased. This dependency may not be obvious to users.

To address this issue, this commit deprecates the
`CONFIG_BT_BUF_RX_COUNT` Kconfig symbol and computes the value in
`buf.h` using the new `BT_BUF_RX_COUNT` define. Note that the default
value and the minimum range value have been changed to 0 to "disable"
the option.

Additionally, to allow users to increase the number of ACL RX buffers,
this commit introduces the new `CONFIG_BT_BUF_RX_COUNT_EXTRA` Kconfig
symbol. The value of this symbol will be added to the computed value of
`BT_BUF_RX_COUNT`.

The configurations of tests and samples have been updated to reflect
these changes.

Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
2024-11-27 10:30:59 +01:00
Mark Wang
fb811f1599 bluetooth: ssp: support pairing_accept for ssp
when receiving the io cap request from controller, call
pairing_accept to check whether application accept the
pairing. If no, reply BT_HCI_OP_IO_CAPABILITY_NEG_REPLY.

Signed-off-by: Mark Wang <yichang.wang@nxp.com>
2024-11-27 10:29:36 +01:00
Vinayak Kariappa Chettimada
478cace022 Bluetooth: Controller: Fix minimum offset for subsequent CISes
Fix CIS offset calculation by Central for subsequent CISes
such that when compensating for dissimilar ACL and ISO
intervals, ensure that minimum offset does not cause a
collision between the ACL and the CIS event at the instant.

Fixes commit 3b3d53f09e ("Bluetooth: Controller: Fix CIS
offset_min for dissimilar interval").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2024-11-27 08:17:50 +01:00
Aleksander Wasaznik
5a8daffc32 Bluetooth: Tester: Use BT_L2CAP_SEG_RECV for L2CAP tests
This API gives better control on L2CAP COC credits and suits better
for Upper Tester implementation.

Co-authored-by: Szymon Janc <szymon.janc@codecoup.pl>
Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2024-11-27 08:16:18 +01:00
Szymon Janc
c002b1dc9e Bluetooth: Host: L2CAP: Fix seg_recv call on SDU overflow
This fix calling seg_recv() callback being called even though channel
is being disconnected due to SDU overflow.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2024-11-27 08:16:18 +01:00
Vinayak Kariappa Chettimada
7e74a046a1 Bluetooth: Controller: Fix ISO Sync Receiver is_abort_cb
Fix ISO Sync Receiver implementation to correctly prevent
subevent from pre-empted in the unreserve time space.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2024-11-27 08:15:32 +01:00
Vinayak Kariappa Chettimada
396692c723 Bluetooth: Controller: Fix ISO Sync Receiver time reservations
Fix ISO Sync Receiver time reservation calculation to use
peer broadcasted bis_spacing and sub_interval, instead of
incorrectly calculating using local implementation used
tMSS value.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2024-11-27 08:15:32 +01:00
Vinayak Kariappa Chettimada
a7a199d6de Bluetooth: Controller: Fix ISO Sync Receiver skipped ISO SDU
Fix ISO Sync Receiver implementation to correctly reflect
the payload number and timestamp for the skipped SDU.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2024-11-27 08:15:32 +01:00
Emil Gydesen
e73bfb92c7 tests: Bluetooth: ASCS: Fix various issues in ASCS unit tests
The ASCS unit tests had various errors after adding support for
dynamic registration.
Several tests did not properly clean up after failure, causing other
tests to fail when they shouldn't.

Moved the register tests to their own file as they should not
do the register in the "before" function.

The test_ascs_unregister_with_ases_in_config_state test was also
removed, as it had both issues and the state that it wants to test
cannot be reached with the current API - It is not possible to
put an ASE in the configured state without callbacks,
and registered callbacks prevents us from calling
bt_bap_unicast_server_unregister to trigger the case as that can
only be done if callbacks are unregistered. Since unregistering
callbacks also puts all ASEs to the idle state, it is not possible
to call bt_bap_unicast_server_unregister for a non-idle ASE.

The testcase.yaml was also missing some Kconfig options to
properly enable the client tests.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-11-26 15:43:13 -05:00
Ivan Iushkov
75fc0a0776 Bluetooth: Host: deprecate bt_le_set_auto_conn()
bt_le_set_auto_conn() function is not working as
expected. Also, it doesn't have any test coverage
and any usage in sample applications.
The function is deprecated
Fixes #81597

Signed-off-by: Ivan Iushkov <ivan.iushkov@nordicsemi.no>
2024-11-26 10:37:12 +00:00