From 92417967cfc5dd998e42083bd4aa8b201470c156 Mon Sep 17 00:00:00 2001 From: Nithin Ramesh Myliattil Date: Tue, 23 Apr 2024 08:32:30 +0200 Subject: [PATCH] Bluetooth: BAP: Shell: Add BASS service data to ext-adv As per the BAP spec, the scan delegator device should add the BASS service data in the extended advertising data when it requests a broadcast assistant to scan for it. For testing purposes that's usually the case with the shell, extended advertising data shall be populated with the BASS service data. Signed-off-by: Nithin Ramesh Myliattil --- subsys/bluetooth/audio/shell/audio.h | 1 + subsys/bluetooth/audio/shell/bap.c | 5 +++++ subsys/bluetooth/audio/shell/bap_scan_delegator.c | 14 ++++++++++++++ 3 files changed, 20 insertions(+) diff --git a/subsys/bluetooth/audio/shell/audio.h b/subsys/bluetooth/audio/shell/audio.h index 9e777337e7eb2c..45161667e83f07 100644 --- a/subsys/bluetooth/audio/shell/audio.h +++ b/subsys/bluetooth/audio/shell/audio.h @@ -31,6 +31,7 @@ ssize_t audio_ad_data_add(struct bt_data *data, const size_t data_size, const bo ssize_t audio_pa_data_add(struct bt_data *data_array, const size_t data_array_size); ssize_t csis_ad_data_add(struct bt_data *data, const size_t data_size, const bool discoverable); size_t cap_acceptor_ad_data_add(struct bt_data data[], size_t data_size, bool discoverable); +size_t bap_scan_delegator_ad_data_add(struct bt_data data[], size_t data_size); size_t gmap_ad_data_add(struct bt_data data[], size_t data_size); size_t pbp_ad_data_add(struct bt_data data[], size_t data_size); ssize_t cap_initiator_ad_data_add(struct bt_data *data_array, const size_t data_array_size, diff --git a/subsys/bluetooth/audio/shell/bap.c b/subsys/bluetooth/audio/shell/bap.c index 723afd38374876..8e18abe17da019 100644 --- a/subsys/bluetooth/audio/shell/bap.c +++ b/subsys/bluetooth/audio/shell/bap.c @@ -3914,6 +3914,11 @@ static ssize_t connectable_ad_data_add(struct bt_data *data_array, ad_len++; } + if (IS_ENABLED(CONFIG_BT_BAP_SCAN_DELEGATOR)) { + ad_len += bap_scan_delegator_ad_data_add(&data_array[ad_len], + data_array_size - ad_len); + } + if (IS_ENABLED(CONFIG_BT_CAP_ACCEPTOR)) { ad_len += cap_acceptor_ad_data_add(&data_array[ad_len], data_array_size - ad_len, true); diff --git a/subsys/bluetooth/audio/shell/bap_scan_delegator.c b/subsys/bluetooth/audio/shell/bap_scan_delegator.c index a2067301c8db12..9c0789eabb184e 100644 --- a/subsys/bluetooth/audio/shell/bap_scan_delegator.c +++ b/subsys/bluetooth/audio/shell/bap_scan_delegator.c @@ -36,6 +36,20 @@ struct sync_state { static bool past_preference = true; +size_t bap_scan_delegator_ad_data_add(struct bt_data data[], size_t data_size) +{ + static uint8_t ad_bap_scan_delegator[2] = { + BT_UUID_16_ENCODE(BT_UUID_BASS_VAL), + }; + + __ASSERT(data_size > 0, "No space for ad_bap_scan_delegator"); + data[0].type = BT_DATA_SVC_DATA16; + data[0].data_len = ARRAY_SIZE(ad_bap_scan_delegator); + data[0].data = &ad_bap_scan_delegator[0]; + + return 1U; +} + static struct sync_state *sync_state_get(const struct bt_bap_scan_delegator_recv_state *recv_state) { for (size_t i = 0U; i < ARRAY_SIZE(sync_states); i++) {