From cb4074438531ef24deb386b301941000ec5920d4 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Thu, 20 Feb 2025 15:03:12 +0100 Subject: [PATCH] Bluetooth: Audio: Modifed PAST checks to use public API Use the recently added bt_le_get_local_features function as well as bt_conn_get_remote_info to avoid using internal APIs to check for PAST supported. Signed-off-by: Emil Gydesen --- include/zephyr/bluetooth/bluetooth.h | 46 +++++++++++++------ .../bluetooth/audio/bap_broadcast_assistant.c | 32 +++++++++---- subsys/bluetooth/audio/bap_scan_delegator.c | 40 ++++++++++++---- subsys/bluetooth/host/hci_core.h | 7 ++- 4 files changed, 91 insertions(+), 34 deletions(-) diff --git a/include/zephyr/bluetooth/bluetooth.h b/include/zephyr/bluetooth/bluetooth.h index 764e2923b72d..1a7888182f4f 100644 --- a/include/zephyr/bluetooth/bluetooth.h +++ b/include/zephyr/bluetooth/bluetooth.h @@ -50,11 +50,11 @@ extern "C" { #define BT_ID_DEFAULT 0 /** - * @brief Number of octets for local supporte + * @brief Number of octets for local supported * * The value of 8 correspond to page 0 in the LE Controller supported features */ -#define BT_LE_LOCAL_SUPPOTRED_FEATURES_SIZE 8 +#define BT_LE_LOCAL_SUPPORTED_FEATURES_SIZE 8 /** Opaque type representing an advertiser. */ struct bt_le_ext_adv; @@ -531,38 +531,56 @@ struct bt_le_local_features { * * Refer to BT_LE_FEAT_BIT_* for values. * Refer to the BT_FEAT_LE_* macros for value comparionson. - * See Bluetooth Core Specification 6.0, Vol 6, Part B, Section 4.6 table 4.10 + * See Bluetooth Core Specification, Vol 6, Part B, Section 4.6. */ - uint8_t features[BT_LE_LOCAL_SUPPOTRED_FEATURES_SIZE]; + uint8_t features[BT_LE_LOCAL_SUPPORTED_FEATURES_SIZE]; - /** Local LE controller supported states + /** + * @brief Local LE controller supported states * * Refer to BT_LE_STATES_* for values. * See Bluetooth Core Specification 6.0, Vol 4, Part E, Section 7.8.27 */ uint64_t states; - /** ACL data packet length */ + /** + * @brief ACL data packet length + * + * This represents the maximum ACL HCI Data packet which can be sent from the Host to the + * Controller. + * The Host may support L2CAP and ATT MTUs larger than this value. + * See Bluetooth Core Specification, Vol 6, Part E, Section 7.8.2. + */ uint16_t acl_mtu; /** Total number of ACL data packets */ uint8_t acl_pkts; - /** ISO data packet length */ + /** + * @brief ISO data packet length + * + * This represents the maximum ISO HCI Data packet which can be sent from the Host to the + * Controller. + * ISO SDUs above this size can be fragmented assuming that the number of + * @ref bt_le_local_features.iso_pkts support the maximum size. + */ uint16_t iso_mtu; /** Total number of ISO data packets */ uint8_t iso_pkts; - /** Size of the controller resolving list */ + /** + * @brief Maximum size of the controller resolving list. + * + * See Bluetooth Core Specification, Vol 6, Part E, Section 7.8.41. + */ uint8_t rl_size; - /** Number of entries in the resolving list. + /** + * @brief Maximum advertising data length + * + * @note The maximum advertising data length also depends on advertising type. * - * @ref bt_le_local_features.rl_entries > @ref bt_le_local_features.rl_size means that - * host-side resolving is used. + * See Bluetooth Core Specification, Vol 6, Part E, Section 7.8.57. */ - uint8_t rl_entries; - - /** Maximum advertising data length */ uint16_t max_adv_data_len; }; diff --git a/subsys/bluetooth/audio/bap_broadcast_assistant.c b/subsys/bluetooth/audio/bap_broadcast_assistant.c index db2b78df3ad1..6eb1b5313c14 100644 --- a/subsys/bluetooth/audio/bap_broadcast_assistant.c +++ b/subsys/bluetooth/audio/bap_broadcast_assistant.c @@ -50,8 +50,6 @@ LOG_MODULE_REGISTER(bt_bap_broadcast_assistant, CONFIG_BT_BAP_BROADCAST_ASSISTAN #include "audio_internal.h" #include "bap_internal.h" -#include "../host/conn_internal.h" -#include "../host/hci_core.h" #define MINIMUM_RECV_STATE_LEN 15 @@ -210,12 +208,30 @@ static bool past_available(const struct bt_conn *conn, uint8_t sid) { if (IS_ENABLED(CONFIG_BT_PER_ADV_SYNC_TRANSFER_SENDER)) { + struct bt_le_local_features local_features; + struct bt_conn_remote_info remote_info; + int err; + + err = bt_le_get_local_features(&local_features); + if (err != 0) { + LOG_DBG("Failed to get local features: %d", err); + return false; + } + + err = bt_conn_get_remote_info(conn, &remote_info); + if (err != 0) { + LOG_DBG("Failed to get remote info: %d", err); + return false; + } + LOG_DBG("%p remote %s PAST, local %s PAST", (void *)conn, - BT_FEAT_LE_PAST_RECV(conn->le.features) ? "supports" : "does not support", - BT_FEAT_LE_PAST_SEND(bt_dev.le.features) ? "supports" : "does not support"); + BT_FEAT_LE_PAST_RECV(remote_info.le.features) ? "supports" + : "does not support", + BT_FEAT_LE_PAST_SEND(local_features.features) ? "supports" + : "does not support"); - return BT_FEAT_LE_PAST_RECV(conn->le.features) && - BT_FEAT_LE_PAST_SEND(bt_dev.le.features) && + return BT_FEAT_LE_PAST_RECV(remote_info.le.features) && + BT_FEAT_LE_PAST_SEND(local_features.features) && bt_le_per_adv_sync_lookup_addr(adv_addr, sid) != NULL; } else { return false; @@ -379,7 +395,7 @@ static uint8_t broadcast_assistant_bap_ntf_read_func(struct bt_conn *conn, uint8 return BT_GATT_ITER_STOP; } - LOG_DBG("conn %p err 0x%02x len %u", conn, err, length); + LOG_DBG("conn %p err 0x%02x len %u", (void *)conn, err, length); if (err) { LOG_DBG("Failed to read: %u", err); @@ -428,7 +444,7 @@ static void long_bap_read(struct bt_conn *conn, uint16_t handle) } if (atomic_test_and_set_bit(inst->flags, BAP_BA_FLAG_BUSY)) { - LOG_DBG("conn %p", conn); + LOG_DBG("conn %p", (void *)conn); /* If the client is busy reading reschedule the long read */ struct bt_conn_info conn_info; diff --git a/subsys/bluetooth/audio/bap_scan_delegator.c b/subsys/bluetooth/audio/bap_scan_delegator.c index bb6b54b039be..9d833cda4046 100644 --- a/subsys/bluetooth/audio/bap_scan_delegator.c +++ b/subsys/bluetooth/audio/bap_scan_delegator.c @@ -419,14 +419,32 @@ static struct bt_le_per_adv_sync_cb pa_sync_cb = { static bool supports_past(struct bt_conn *conn, uint8_t pa_sync_val) { if (IS_ENABLED(CONFIG_BT_PER_ADV_SYNC_TRANSFER_RECEIVER)) { + struct bt_le_local_features local_features; + struct bt_conn_remote_info remote_info; + int err; + + err = bt_le_get_local_features(&local_features); + if (err != 0) { + LOG_DBG("Failed to get local features: %d", err); + return false; + } + + err = bt_conn_get_remote_info(conn, &remote_info); + if (err != 0) { + LOG_DBG("Failed to get remote info: %d", err); + return false; + } + LOG_DBG("%p remote %s PAST, local %s PAST (req %u)", (void *)conn, - BT_FEAT_LE_PAST_SEND(conn->le.features) ? "supports" : "does not support", - BT_FEAT_LE_PAST_RECV(bt_dev.le.features) ? "supports" : "does not support", + BT_FEAT_LE_PAST_SEND(remote_info.le.features) ? "supports" + : "does not support", + BT_FEAT_LE_PAST_RECV(local_features.features) ? "supports" + : "does not support", pa_sync_val); return pa_sync_val == BT_BAP_BASS_PA_REQ_SYNC_PAST && - BT_FEAT_LE_PAST_SEND(conn->le.features) && - BT_FEAT_LE_PAST_RECV(bt_dev.le.features); + BT_FEAT_LE_PAST_SEND(remote_info.le.features) && + BT_FEAT_LE_PAST_RECV(local_features.features); } else { return false; } @@ -659,8 +677,8 @@ static int scan_delegator_add_source(struct bt_conn *conn, (void)memset(state, 0, sizeof(*state)); internal_state->active = false; - LOG_DBG("PA sync %u from %p was rejected with reason %d", pa_sync, conn, - err); + LOG_DBG("PA sync %u from %p was rejected with reason %d", pa_sync, + (void *)conn, err); return BT_GATT_ERR(BT_ATT_ERR_WRITE_REQ_REJECTED); } @@ -866,8 +884,8 @@ static int scan_delegator_mod_src(struct bt_conn *conn, (void)memcpy(state, &backup_state, sizeof(backup_state)); - LOG_DBG("PA sync %u from %p was rejected with reason %d", pa_sync, conn, - err); + LOG_DBG("PA sync %u from %p was rejected with reason %d", pa_sync, + (void *)conn, err); return BT_GATT_ERR(BT_ATT_ERR_WRITE_REQ_REJECTED); } else if (pa_sync_state != state->pa_sync_state) { @@ -884,7 +902,8 @@ static int scan_delegator_mod_src(struct bt_conn *conn, const int err = pa_sync_term_request(conn, &internal_state->state); if (err != 0) { - LOG_DBG("PA sync term from %p was rejected with reason %d", conn, err); + LOG_DBG("PA sync term from %p was rejected with reason %d", (void *)conn, + err); return BT_GATT_ERR(BT_ATT_ERR_WRITE_REQ_REJECTED); } @@ -979,7 +998,8 @@ static int scan_delegator_rem_src(struct bt_conn *conn, /* Terminate PA sync */ err = pa_sync_term_request(conn, &internal_state->state); if (err != 0) { - LOG_DBG("PA sync term from %p was rejected with reason %d", conn, err); + LOG_DBG("PA sync term from %p was rejected with reason %d", (void *)conn, + err); return BT_GATT_ERR(BT_ATT_ERR_WRITE_REQ_REJECTED); } diff --git a/subsys/bluetooth/host/hci_core.h b/subsys/bluetooth/host/hci_core.h index e501ae1d5fe3..6d62be6197bb 100644 --- a/subsys/bluetooth/host/hci_core.h +++ b/subsys/bluetooth/host/hci_core.h @@ -1,12 +1,15 @@ /* hci_core.h - Bluetooth HCI core access */ /* - * Copyright (c) 2021 Nordic Semiconductor ASA + * Copyright (c) 2021-2025 Nordic Semiconductor ASA * Copyright (c) 2015-2016 Intel Corporation * * SPDX-License-Identifier: Apache-2.0 */ +#include + +#include #include /* LL connection parameters */ @@ -271,7 +274,7 @@ struct bt_le_per_adv_sync { struct bt_dev_le { /* LE features */ - uint8_t features[8]; + uint8_t features[BT_LE_LOCAL_SUPPORTED_FEATURES_SIZE]; /* LE states */ uint64_t states;