Bluetooth: audio: Add possibility to use static broadcast id

Removed the generation of broadcast id inside the stack. It is now up
to the application to generate this by itself. The CAP sample has
been modified to allow either a static broadcast, or a random one.
All of this is handled in the application.

Signed-off-by: Fredrik Danebjer <frdn@demant.com>
This commit is contained in:
Fredrik Danebjer 2024-10-22 14:45:25 +02:00 committed by Alberto Escolar
commit f970b066d2
25 changed files with 112 additions and 232 deletions

View file

@ -1163,79 +1163,6 @@ ZTEST_F(bap_broadcast_source_test_suite, test_broadcast_source_delete_inval_doub
zassert_not_equal(0, err, "Did not fail with deleting already deleting source");
}
ZTEST_F(bap_broadcast_source_test_suite, test_broadcast_source_get_id)
{
struct bt_bap_broadcast_source_param *create_param = fixture->param;
uint32_t broadcast_id;
int err;
printk("Creating broadcast source with %zu subgroups with %zu streams\n",
create_param->params_count, fixture->stream_cnt);
err = bt_bap_broadcast_source_create(create_param, &fixture->source);
zassert_equal(0, err, "Unable to create broadcast source: err %d", err);
err = bt_bap_broadcast_source_get_id(fixture->source, &broadcast_id);
zassert_equal(0, err, "Unable to get broadcast ID: err %d", err);
err = bt_bap_broadcast_source_delete(fixture->source);
zassert_equal(0, err, "Unable to delete broadcast source: err %d", err);
fixture->source = NULL;
}
ZTEST_F(bap_broadcast_source_test_suite, test_broadcast_source_get_id_inval_source_null)
{
uint32_t broadcast_id;
int err;
err = bt_bap_broadcast_source_get_id(NULL, &broadcast_id);
zassert_not_equal(0, err, "Did not fail with null source");
}
ZTEST_F(bap_broadcast_source_test_suite, test_broadcast_source_get_id_inval_id_null)
{
struct bt_bap_broadcast_source_param *create_param = fixture->param;
int err;
printk("Creating broadcast source with %zu subgroups with %zu streams\n",
create_param->params_count, fixture->stream_cnt);
err = bt_bap_broadcast_source_create(create_param, &fixture->source);
zassert_equal(0, err, "Unable to create broadcast source: err %d", err);
err = bt_bap_broadcast_source_get_id(fixture->source, NULL);
zassert_not_equal(0, err, "Did not fail with null ID");
err = bt_bap_broadcast_source_delete(fixture->source);
zassert_equal(0, err, "Unable to delete broadcast source: err %d", err);
fixture->source = NULL;
}
ZTEST_F(bap_broadcast_source_test_suite, test_broadcast_source_get_id_inval_state)
{
struct bt_bap_broadcast_source_param *create_param = fixture->param;
struct bt_bap_broadcast_source *source;
uint32_t broadcast_id;
int err;
printk("Creating broadcast source with %zu subgroups with %zu streams\n",
create_param->params_count, fixture->stream_cnt);
err = bt_bap_broadcast_source_create(create_param, &fixture->source);
zassert_equal(0, err, "Unable to create broadcast source: err %d", err);
source = fixture->source;
err = bt_bap_broadcast_source_delete(fixture->source);
zassert_equal(0, err, "Unable to delete broadcast source: err %d", err);
fixture->source = NULL;
err = bt_bap_broadcast_source_get_id(source, &broadcast_id);
zassert_not_equal(0, err, "Did not fail with deleted broadcast source");
}
ZTEST_F(bap_broadcast_source_test_suite, test_broadcast_source_get_base_single_bis)
{
struct bt_bap_broadcast_source_param *create_param = fixture->param;

View file

@ -298,6 +298,7 @@ uint8_t btp_bap_broadcast_source_setup(const void *cmd, uint16_t cmd_len,
const struct btp_bap_broadcast_source_setup_cmd *cp = cmd;
struct btp_bap_broadcast_source_setup_rp *rp = rsp;
struct bt_le_adv_param param = *BT_LE_EXT_ADV_NCONN;
uint32_t broadcast_id;
/* Only one local source/BIG supported for now */
struct btp_bap_broadcast_local_source *source = &local_source;
@ -338,16 +339,16 @@ uint8_t btp_bap_broadcast_source_setup(const void *cmd, uint16_t cmd_len,
return BTP_STATUS_FAILED;
}
err = bt_bap_broadcast_source_get_id(source->bap_broadcast, &source->broadcast_id);
if (err != 0) {
LOG_DBG("Unable to get broadcast ID: %d", err);
err = bt_rand(&broadcast_id, BT_AUDIO_BROADCAST_ID_SIZE);
if (err) {
LOG_DBG("Unable to generate broadcast ID: %d\n", err);
return BTP_STATUS_FAILED;
}
/* Setup extended advertising data */
net_buf_simple_add_le16(&ad_buf, BT_UUID_BROADCAST_AUDIO_VAL);
net_buf_simple_add_le24(&ad_buf, source->broadcast_id);
net_buf_simple_add_le24(&ad_buf, broadcast_id);
base_ad[0].type = BT_DATA_SVC_DATA16;
base_ad[0].data_len = ad_buf.len;
base_ad[0].data = ad_buf.data;
@ -387,7 +388,7 @@ uint8_t btp_bap_broadcast_source_setup(const void *cmd, uint16_t cmd_len,
}
rp->gap_settings = gap_settings;
sys_put_le24(source->broadcast_id, rp->broadcast_id);
sys_put_le24(broadcast_id, rp->broadcast_id);
*rsp_len = sizeof(*rp) + 1;
return BTP_STATUS_SUCCESS;

View file

@ -534,6 +534,7 @@ static int cap_broadcast_source_adv_setup(struct btp_bap_broadcast_local_source
{
int err;
struct bt_le_adv_param param = *BT_LE_EXT_ADV_NCONN;
uint32_t broadcast_id;
NET_BUF_SIMPLE_DEFINE(ad_buf, BT_UUID_SIZE_16 + BT_AUDIO_BROADCAST_ID_SIZE);
NET_BUF_SIMPLE_DEFINE(base_buf, 128);
@ -542,9 +543,9 @@ static int cap_broadcast_source_adv_setup(struct btp_bap_broadcast_local_source
struct bt_data base_ad[2];
struct bt_data per_ad;
err = bt_cap_initiator_broadcast_get_id(source->cap_broadcast, &source->broadcast_id);
if (err != 0) {
LOG_DBG("Unable to get broadcast ID: %d", err);
err = bt_rand(&broadcast_id, BT_AUDIO_BROADCAST_ID_SIZE);
if (err) {
printk("Unable to generate broadcast ID: %d\n", err);
return -EINVAL;
}

View file

@ -321,18 +321,6 @@ static int setup_broadcast_source(struct bt_bap_broadcast_source **source, bool
return 0;
}
static void test_broadcast_source_get_id(struct bt_bap_broadcast_source *source,
uint32_t *broadcast_id_out)
{
int err;
err = bt_bap_broadcast_source_get_id(source, broadcast_id_out);
if (err != 0) {
FAIL("Unable to get broadcast ID: %d\n", err);
return;
}
}
static void test_broadcast_source_get_base(struct bt_bap_broadcast_source *source,
struct net_buf_simple *base_buf)
{
@ -373,7 +361,11 @@ static int setup_extended_adv(struct bt_bap_broadcast_source *source, struct bt_
return err;
}
test_broadcast_source_get_id(source, &broadcast_id);
err = bt_rand(&broadcast_id, BT_AUDIO_BROADCAST_ID_SIZE);
if (err) {
printk("Unable to generate broadcast ID: %d\n", err);
return err;
}
/* Setup extended advertising data */
net_buf_simple_add_le16(&ad_buf, BT_UUID_BROADCAST_AUDIO_VAL);

View file

@ -249,9 +249,9 @@ static void setup_extended_adv_data(struct bt_cap_broadcast_source *source,
uint32_t broadcast_id;
int err;
err = bt_cap_initiator_broadcast_get_id(source, &broadcast_id);
if (err != 0) {
FAIL("Unable to get broadcast ID: %d\n", err);
err = bt_rand(&broadcast_id, BT_AUDIO_BROADCAST_ID_SIZE);
if (err) {
FAIL("Unable to generate broadcast ID: %d\n", err);
return;
}

View file

@ -1055,9 +1055,9 @@ static void setup_extended_adv_data(struct bt_cap_broadcast_source *source,
uint32_t broadcast_id;
int err;
err = bt_cap_initiator_broadcast_get_id(source, &broadcast_id);
if (err != 0) {
FAIL("Unable to get broadcast ID: %d\n", err);
err = bt_rand(&broadcast_id, BT_AUDIO_BROADCAST_ID_SIZE);
if (err) {
FAIL("Unable to generate broadcast ID: %d\n", err);
return;
}

View file

@ -135,10 +135,9 @@ static int setup_extended_adv_data(struct bt_cap_broadcast_source *source,
uint32_t broadcast_id;
int err;
err = bt_cap_initiator_broadcast_get_id(source, &broadcast_id);
if (err != 0) {
printk("Unable to get broadcast ID: %d\n", err);
err = bt_rand(&broadcast_id, BT_AUDIO_BROADCAST_ID_SIZE);
if (err) {
FAIL("Unable to generate broadcast ID: %d\n", err);
return err;
}