Bluetooth: ISO/BAP: Refactor BIS bitfield

Refactors teh BIS bitfield values used for ISO
and BAP.

Previously BIT(1) meant BIS index 1, which was a Zephyr choice
in the early days of ISO, as the BT Core spec did not use
a bitfield for BIS indexes.

Later the BASS specification came along and defined that
BIT(0) meant BIS index 1, which meant that we had to shift BIS
bitfields between BAP and ISO.

This commit refactors the ISO layer to use BIT(0) for Index 1 now,
which means that there is no longer a need for conversion
between the BAP and ISO layers, and that we can use a value
range defined by a BT Core spec (BASS).

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
This commit is contained in:
Emil Gydesen 2024-07-09 15:28:46 +02:00 committed by Anas Nashif
commit 8be6db67fc
21 changed files with 48 additions and 57 deletions

View file

@ -221,7 +221,7 @@ ZTEST_F(bap_base_test_suite, test_base_get_bis_indexes)
ret = bt_bap_base_get_bis_indexes(base, &bis_indexes);
zassert_equal(ret, 0, "Unexpected return value: %d", ret);
zassert_equal(bis_indexes, 0x00000006 /* Bit 1 and 2 */,
zassert_equal(bis_indexes, 0x00000003 /* Bit 1 and 2 */,
"Unexpected BIS index value: 0x%08X", bis_indexes);
}

View file

@ -92,7 +92,7 @@ static void test_start_param_init(void *f)
fixture->start_param.count = ARRAY_SIZE(fixture->start_member_params);
for (size_t i = 0; i < ARRAY_SIZE(fixture->start_subgroups); i++) {
fixture->start_subgroups[i].bis_sync = 1 << i;
fixture->start_subgroups[i].bis_sync = i;
fixture->start_subgroups[i].metadata_len = 0;
}

View file

@ -609,7 +609,7 @@ static bool base_subgroup_bis_cb(const struct bt_bap_base_subgroup_bis *bis, voi
struct bt_audio_codec_cfg *codec_cfg = &parse_data->codec_cfg;
struct btp_bap_broadcast_remote_source *broadcaster = parse_data->broadcaster;
parse_data->bis_bitfield |= BIT(bis->index);
parse_data->bis_bitfield |= BT_ISO_BIS_INDEX_BIT(bis->index);
if (parse_data->stream_cnt < ARRAY_SIZE(broadcaster->streams)) {
struct btp_bap_broadcast_stream *stream =

View file

@ -452,7 +452,7 @@ static void test_bass_mod_source(void)
mod_src_param.pa_sync = true;
mod_src_param.subgroups = &subgroup;
mod_src_param.pa_interval = g_broadcaster_info.interval;
subgroup.bis_sync = BIT(1) | BIT(2); /* Indexes 1 and 2 */
subgroup.bis_sync = BT_ISO_BIS_INDEX_BIT(1) | BT_ISO_BIS_INDEX_BIT(2); /* Indexes 1 and 2 */
subgroup.metadata_len = 0;
err = bt_bap_broadcast_assistant_mod_src(default_conn, &mod_src_param);
@ -482,7 +482,7 @@ static void test_bass_mod_source_long_meta(void)
mod_src_param.pa_sync = true;
mod_src_param.subgroups = &subgroup;
mod_src_param.pa_interval = g_broadcaster_info.interval;
subgroup.bis_sync = BIT(1) | BIT(2);
subgroup.bis_sync = BT_ISO_BIS_INDEX_BIT(1) | BT_ISO_BIS_INDEX_BIT(2);
subgroup.metadata_len = sizeof(metadata);
memcpy(subgroup.metadata, metadata, sizeof(metadata));

View file

@ -804,7 +804,7 @@ static void test_broadcast_sync_inval(void)
return;
}
bis_index = BIT(0);
bis_index = BT_ISO_BIS_INDEX_BIT(BT_ISO_BIS_INDEX_MAX + 1);
err = bt_bap_broadcast_sink_sync(g_sink, bis_index, streams, NULL);
if (err == 0) {
FAIL("bt_bap_broadcast_sink_sync did not fail with invalid BIS indexes: 0x%08X\n",
@ -821,7 +821,7 @@ static void test_broadcast_sync_inval(void)
memcpy(tmp_streams, streams, sizeof(streams));
bis_index = 0U;
for (size_t i = 0U; i < ARRAY_SIZE(tmp_streams); i++) {
bis_index |= BIT(i + BT_ISO_BIS_INDEX_MIN);
bis_index |= BT_ISO_BIS_INDEX_BIT(i);
}
err = bt_bap_broadcast_sink_sync(g_sink, bis_index, tmp_streams, NULL);
@ -833,7 +833,7 @@ static void test_broadcast_sync_inval(void)
bis_index = 0U;
for (size_t i = 0U; i < CONFIG_BT_BAP_BROADCAST_SNK_STREAM_COUNT + 1; i++) {
bis_index |= BIT(i + BT_ISO_BIS_INDEX_MIN);
bis_index |= BT_ISO_BIS_INDEX_BIT(i);
}
err = bt_bap_broadcast_sink_sync(g_sink, bis_index, tmp_streams, NULL);

View file

@ -16,6 +16,7 @@
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/byteorder.h>
#include <zephyr/bluetooth/gap.h>
#include <zephyr/bluetooth/iso.h>
#include <zephyr/bluetooth/uuid.h>
#include <zephyr/kernel.h>
#include <zephyr/net/buf.h>
@ -650,7 +651,7 @@ static int sync_broadcast(struct sync_state *state)
/* We don't actually need to sync to the BIG/BISes */
err = bt_bap_scan_delegator_set_bis_sync_state(state->src_id,
(uint32_t []){ BIT(1) });
(uint32_t[]){BT_ISO_BIS_INDEX_BIT(1)});
if (err) {
return err;
}

View file

@ -223,7 +223,7 @@ static void sync_big(struct bt_le_per_adv_sync *sync, uint8_t cnt, struct bt_iso
struct bt_iso_chan *bis_channels[CONFIG_BT_ISO_MAX_CHAN];
struct bt_iso_big_sync_param param = {
.sync_timeout = interval_to_sync_timeout(broadcaster_info.interval),
.bis_bitfield = BIT_MASK(cnt) << 1U, /* BIS indexes start from 1, thus shift by 1 */
.bis_bitfield = BIT_MASK(cnt),
.bis_channels = bis_channels,
.mse = BT_ISO_SYNC_MSE_MIN,
.encryption = false,

View file

@ -907,7 +907,7 @@ static void test_iso_recv_main(void)
bis_iso_qos.rx = &iso_rx_qos;
big_param.bis_channels = bis_channels;
big_param.num_bis = BIS_ISO_CHAN_COUNT;
big_param.bis_bitfield = BIT(1); /* BIS 1 selected */
big_param.bis_bitfield = BT_ISO_BIS_INDEX_BIT(1); /* BIS 1 selected */
big_param.mse = 1;
big_param.sync_timeout = 100; /* 1000 ms */
big_param.encryption = false;
@ -1124,7 +1124,7 @@ static void test_iso_recv_vs_dp_main(void)
bis_iso_qos.rx = &iso_rx_qos;
big_param.bis_channels = bis_channels;
big_param.num_bis = BIS_ISO_CHAN_COUNT;
big_param.bis_bitfield = BIT(1); /* BIS 1 selected */
big_param.bis_bitfield = BT_ISO_BIS_INDEX_BIT(1); /* BIS 1 selected */
big_param.mse = 1;
big_param.sync_timeout = 100; /* 1000 ms */
big_param.encryption = false;