Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions subsys/bluetooth/host/hci_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -4662,6 +4662,10 @@ int bt_disable(void)
bt_periodic_sync_disable();
#endif /* CONFIG_BT_PER_ADV_SYNC */

if (IS_ENABLED(CONFIG_BT_ISO)) {
bt_iso_reset();
}

#if defined(CONFIG_BT_CONN)
if (IS_ENABLED(CONFIG_BT_SMP)) {
bt_pub_key_hci_disrupted();
Expand Down Expand Up @@ -4716,10 +4720,6 @@ int bt_disable(void)
/* If random address was set up - clear it */
bt_addr_le_copy(&bt_dev.random_addr, BT_ADDR_LE_ANY);

if (IS_ENABLED(CONFIG_BT_ISO)) {
bt_iso_reset();
}

bt_monitor_send(BT_MONITOR_CLOSE_INDEX, NULL, 0);

/* Clear BT_DEV_ENABLE here to prevent early bt_enable() calls, before disable is
Expand Down
4 changes: 4 additions & 0 deletions tests/bsim/bluetooth/host/iso/bis/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ target_sources(app PRIVATE
src/bis_broadcaster.c
src/bis_receiver.c
src/main.c

${ZEPHYR_BASE}/tests/bsim/bluetooth/host/iso/common/iso_tx.c
)

zephyr_include_directories(
${BSIM_COMPONENTS_PATH}/libUtilv1/src/
${BSIM_COMPONENTS_PATH}/libPhyComv1/src/

${ZEPHYR_BASE}/tests/bsim/bluetooth/host/iso/common
)
97 changes: 14 additions & 83 deletions tests/bsim/bluetooth/host/iso/bis/src/bis_broadcaster.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "babblekit/testcase.h"
#include "bstests.h"
#include "common.h"
#include "iso_tx.h"

LOG_MODULE_REGISTER(bis_broadcaster, LOG_LEVEL_INF);

Expand All @@ -34,10 +35,6 @@ LOG_MODULE_REGISTER(bis_broadcaster, LOG_LEVEL_INF);
extern enum bst_result_t bst_result;
static struct bt_iso_chan iso_chans[CONFIG_BT_ISO_MAX_CHAN];
static struct bt_iso_chan *default_chan = &iso_chans[0];
static uint16_t seq_num;
NET_BUF_POOL_FIXED_DEFINE(tx_pool, CONFIG_BT_ISO_TX_BUF_COUNT,
BT_ISO_SDU_BUF_SIZE(ARRAY_SIZE(mock_iso_data)),
CONFIG_BT_CONN_TX_USER_DATA_SIZE, NULL);

static struct bt_iso_chan_io_qos iso_tx = {
.sdu = 0U,
Expand All @@ -52,54 +49,6 @@ static struct bt_iso_chan_qos iso_qos = {

DEFINE_FLAG_STATIC(flag_iso_connected);

static void send_data_cb(struct k_work *work);
K_WORK_DELAYABLE_DEFINE(iso_send_work, send_data_cb);

static void send_data(struct bt_iso_chan *chan)
{
static size_t len_to_send = 1U;
struct net_buf *buf;
int ret;

if (!IS_FLAG_SET(flag_iso_connected)) {
/* TX has been aborted */
return;
}

buf = net_buf_alloc(&tx_pool, K_NO_WAIT);
TEST_ASSERT(buf != NULL, "Failed to allocate buffer");

net_buf_reserve(buf, BT_ISO_CHAN_SEND_RESERVE);

net_buf_add_mem(buf, mock_iso_data, len_to_send);

ret = bt_iso_chan_send(default_chan, buf, seq_num++);
if (ret < 0) {
LOG_DBG("Failed to send ISO data: %d", ret);
net_buf_unref(buf);

/* Reschedule for next interval */
k_work_reschedule(&iso_send_work, K_USEC(SDU_INTERVAL_US));

return;
}

len_to_send++;
if (len_to_send > chan->qos->tx->sdu) {
len_to_send = 1;
}
}

static void send_data_cb(struct k_work *work)
{
const uint16_t tx_pool_cnt = tx_pool.uninit_count;

/* Send/enqueue as many as we can */
for (uint16_t i = 0U; i < tx_pool_cnt; i++) {
send_data(default_chan);
}
}

static void iso_connected_cb(struct bt_iso_chan *chan)
{
const struct bt_iso_chan_path hci_path = {
Expand Down Expand Up @@ -151,43 +100,38 @@ static void iso_connected_cb(struct bt_iso_chan *chan)
IN_RANGE(info.broadcaster.bis_number, BT_ISO_BIS_INDEX_MIN, BT_ISO_BIS_INDEX_MAX),
"Invalid BIS number 0x%02x", info.broadcaster.bis_number);

err = bt_iso_setup_data_path(chan, BT_HCI_DATAPATH_DIR_HOST_TO_CTLR, &hci_path);
TEST_ASSERT(err == 0, "Failed to set ISO data path: %d", err);

if (chan == default_chan) {
seq_num = 0U;
/* Register for TX to start sending */
err = iso_tx_register(chan);
TEST_ASSERT(err == 0, "Failed to register chan for TX: %d", err);

SET_FLAG(flag_iso_connected);
}

err = bt_iso_setup_data_path(chan, BT_HCI_DATAPATH_DIR_HOST_TO_CTLR, &hci_path);
TEST_ASSERT(err == 0, "Failed to set ISO data path: %d", err);
}

static void iso_disconnected_cb(struct bt_iso_chan *chan, uint8_t reason)
{
LOG_INF("ISO Channel %p disconnected (reason 0x%02x)", chan, reason);

if (chan == default_chan) {
k_work_cancel_delayable(&iso_send_work);
int err;

UNSET_FLAG(flag_iso_connected);
}
}
err = iso_tx_unregister(chan);
TEST_ASSERT(err == 0, "Failed to unregister chan for TX: %d", err);

static void sdu_sent_cb(struct bt_iso_chan *chan)
{
if (!IS_FLAG_SET(flag_iso_connected)) {
/* TX has been aborted */
return;
UNSET_FLAG(flag_iso_connected);
}

send_data(chan);
}

static void init(void)
{
static struct bt_iso_chan_ops iso_ops = {
.disconnected = iso_disconnected_cb,
.connected = iso_connected_cb,
.sent = sdu_sent_cb,
.sent = iso_tx_sent_cb,
};
struct bt_le_local_features local_features;
int err;
Expand All @@ -212,6 +156,8 @@ static void init(void)
}

bk_sync_init();

iso_tx_init();
}

static void create_ext_adv(struct bt_le_ext_adv **adv)
Expand Down Expand Up @@ -277,18 +223,6 @@ static void create_big(struct bt_le_ext_adv *adv, size_t cnt, struct bt_iso_big
WAIT_FOR_FLAG(flag_iso_connected);
}

static void start_tx(void)
{
const uint16_t tx_pool_cnt = tx_pool.uninit_count;

LOG_INF("Starting TX");

/* Send/enqueue as many as we can */
for (uint16_t i = 0U; i < tx_pool_cnt; i++) {
send_data(default_chan);
}
}

static void terminate_big(struct bt_iso_big *big)
{
int err;
Expand Down Expand Up @@ -325,7 +259,6 @@ static void test_main(void)
create_ext_adv(&adv);
create_big(adv, 1U, &big);
start_ext_adv(adv);
start_tx();

/* Wait for receiver to tell us to terminate */
bk_sync_wait();
Expand Down Expand Up @@ -358,7 +291,6 @@ static void test_main_disable(void)
create_ext_adv(&adv);
create_big(adv, ARRAY_SIZE(iso_chans), &big);
start_ext_adv(adv);
start_tx();

/* Wait for receiver to tell us to terminate */
bk_sync_wait();
Expand Down Expand Up @@ -400,7 +332,6 @@ static void test_main_fragment(void)
create_ext_adv(&adv);
create_big(adv, 1U, &big);
start_ext_adv(adv);
start_tx();

/* Wait for receiver to tell us to terminate */
bk_sync_wait();
Expand Down
9 changes: 6 additions & 3 deletions tests/bsim/bluetooth/host/iso/bis/src/bis_receiver.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "babblekit/testcase.h"

#include "common.h"
#include "iso_tx.h"

LOG_MODULE_REGISTER(bis_receiver, LOG_LEVEL_INF);

Expand Down Expand Up @@ -89,20 +90,22 @@ static void iso_recv(struct bt_iso_chan *chan, const struct bt_iso_recv_info *in
if (info->flags & BT_ISO_FLAGS_VALID) {
static uint16_t last_buf_len;
static uint32_t last_ts;
static size_t pass_cnt;
static size_t rx_cnt;

LOG_DBG("Incoming data channel %p len %u", chan, buf->len);
rx_cnt++;
LOG_DBG("[%zu]: Incoming data channel %p len %u", rx_cnt, chan, buf->len);
iso_log_data(buf->data, buf->len);

if (memcmp(buf->data, mock_iso_data, buf->len) != 0) {
TEST_FAIL("Unexpected data received");
} else if (last_buf_len != 0U && buf->len != 1U && buf->len != last_buf_len + 1) {
TEST_FAIL("Unexpected data length (%u) received (expected 1 or %u)",
buf->len, last_buf_len);
buf->len, last_buf_len + 1);
} else if (last_ts != 0U && info->ts > last_ts + 2 * SDU_INTERVAL_US) {
TEST_FAIL("Unexpected timestamp (%u) received (expected %u)", info->ts,
last_ts + SDU_INTERVAL_US);
} else if (rx_cnt++ > RX_CNT_TO_PASS) {
} else if (pass_cnt++ > RX_CNT_TO_PASS) {
LOG_INF("Data received");
SET_FLAG(flag_data_received);
}
Expand Down
8 changes: 1 addition & 7 deletions tests/bsim/bluetooth/host/iso/bis/src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <stdint.h>

#include <zephyr/sys/util_macro.h>
#include <zephyr/sys/clock.h>

#include "bs_types.h"

Expand All @@ -18,9 +18,3 @@ void test_init(void);
void test_tick(bs_time_t HW_device_time);

#define SDU_INTERVAL_US 10U * USEC_PER_MSEC /* 10 ms */

/* Generate 1 KiB of mock data going 0x00, 0x01, ..., 0xff, 0x00, 0x01, ..., 0xff, etc */
#define ISO_DATA_GEN(_i, _) (uint8_t)_i
static const uint8_t mock_iso_data[] = {
LISTIFY(1024, ISO_DATA_GEN, (,)),
};
10 changes: 6 additions & 4 deletions tests/bsim/bluetooth/host/iso/cis/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,24 @@ cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(bsim_test_iso_cis)

add_subdirectory(${ZEPHYR_BASE}/tests/bsim/babblekit babblekit)
target_link_libraries(app PRIVATE babblekit)

target_sources(app PRIVATE
src/common.c
src/cis_central.c
src/cis_peripheral.c
src/main.c

${ZEPHYR_BASE}/tests/bsim/bluetooth/host/iso/common/iso_tx.c
)

zephyr_include_directories(
${BSIM_COMPONENTS_PATH}/libUtilv1/src/
${BSIM_COMPONENTS_PATH}/libPhyComv1/src/
)

${ZEPHYR_BASE}/tests/bsim/bluetooth/host/iso/common
)

add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/common/testlib testlib)
add_subdirectory(${ZEPHYR_BASE}/tests/bsim/babblekit babblekit)

target_link_libraries(app PRIVATE
testlib
Expand Down
12 changes: 6 additions & 6 deletions tests/bsim/bluetooth/host/iso/cis/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ CONFIG_BT_DEVICE_NAME="CIS test"

CONFIG_BT_ISO_CENTRAL=y
CONFIG_BT_ISO_PERIPHERAL=y
CONFIG_BT_ISO_TX_BUF_COUNT=4
CONFIG_BT_ISO_MAX_CHAN=4
CONFIG_BT_ISO_TX_BUF_COUNT=6
CONFIG_BT_ISO_MAX_CHAN=3
CONFIG_BT_ISO_TX_MTU=200
CONFIG_BT_ISO_RX_MTU=200

Expand All @@ -23,7 +23,7 @@ CONFIG_BT_CTLR_CENTRAL_ISO=y
CONFIG_BT_CTLR_PERIPHERAL_ISO=y
CONFIG_BT_CTLR_ISO_TX_BUFFER_SIZE=208
CONFIG_BT_CTLR_ISO_TX_SDU_LEN_MAX=200
CONFIG_BT_CTLR_ISO_TX_BUFFERS=4
CONFIG_BT_CTLR_ISOAL_SOURCES=2
CONFIG_BT_CTLR_ISOAL_SINKS=2
CONFIG_BT_CTLR_CONN_ISO_STREAMS_PER_GROUP=4
CONFIG_BT_CTLR_ISO_TX_BUFFERS=6
CONFIG_BT_CTLR_ISOAL_SOURCES=3
CONFIG_BT_CTLR_ISOAL_SINKS=3
CONFIG_BT_CTLR_CONN_ISO_STREAMS_PER_GROUP=3
Loading