Skip to content

Commit

Permalink
Bluetooth: Audio: Modifed PAST checks to use public API
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Thalley committed Feb 21, 2025
1 parent 0e063a1 commit cb40744
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 34 deletions.
46 changes: 32 additions & 14 deletions include/zephyr/bluetooth/bluetooth.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
};

Expand Down
32 changes: 24 additions & 8 deletions subsys/bluetooth/audio/bap_broadcast_assistant.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
40 changes: 30 additions & 10 deletions subsys/bluetooth/audio/bap_scan_delegator.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
7 changes: 5 additions & 2 deletions subsys/bluetooth/host/hci_core.h
Original file line number Diff line number Diff line change
@@ -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 <stdint.h>

#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/devicetree.h>

/* LL connection parameters */
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit cb40744

Please sign in to comment.