Skip to content

Commit 08b4bf5

Browse files
committed
tests: Bluetooth: ISO: Add validation of broadcast info
Add validation of the info the application can retrieve by calling bt_iso_chan_get_info. Signed-off-by: Emil Gydesen <[email protected]>
1 parent df53184 commit 08b4bf5

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

include/zephyr/bluetooth/hci_types.h

+7
Original file line numberDiff line numberDiff line change
@@ -3397,6 +3397,13 @@ struct bt_hci_evt_le_cis_req {
33973397
uint8_t cis_id;
33983398
} __packed;
33993399

3400+
#define BT_HCI_LE_BIG_HANDLE_MIN 0x00U
3401+
#define BT_HCI_LE_BIG_HANDLE_MAX 0xEFU
3402+
#define BT_HCI_LE_BIG_SYNC_DELAY_MIN 0x000030U
3403+
#define BT_HCI_LE_BIG_SYNC_DELAY_MAX 0x7FFFFFU
3404+
#define BT_HCI_LE_TRANSPORT_LATENCY_BIG_MIN 0x000030U
3405+
#define BT_HCI_LE_TRANSPORT_LATENCY_BIG_MAX 0x7FFFFFU
3406+
34003407
#define BT_HCI_EVT_LE_BIG_COMPLETE 0x1b
34013408
struct bt_hci_evt_le_big_complete {
34023409
uint8_t status;

tests/bsim/bluetooth/host/iso/bis/src/bis_broadcaster.c

+41
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66
#include <zephyr/bluetooth/bluetooth.h>
7+
#include <zephyr/bluetooth/gap.h>
8+
#include <zephyr/bluetooth/hci_types.h>
79
#include <zephyr/bluetooth/iso.h>
810
#include <zephyr/logging/log.h>
11+
#include <zephyr/sys/util.h>
912

1013
#include "babblekit/flags.h"
1114
#include "babblekit/sync.h"
@@ -86,8 +89,46 @@ static void send_data_cb(struct k_work *work)
8689

8790
static void iso_connected_cb(struct bt_iso_chan *chan)
8891
{
92+
struct bt_iso_info info;
93+
int err;
94+
8995
LOG_INF("ISO Channel %p connected", chan);
9096

97+
err = bt_iso_chan_get_info(chan, &info);
98+
TEST_ASSERT(err == 0, "Failed to get BIS info: %d", err);
99+
100+
TEST_ASSERT(!info.can_recv);
101+
TEST_ASSERT(info.can_send);
102+
TEST_ASSERT(info.type == BT_ISO_CHAN_TYPE_BROADCASTER);
103+
TEST_ASSERT((BT_GAP_ISO_INTERVAL_TO_US(info.iso_interval) % SDU_INTERVAL_US) == 0U,
104+
"ISO interval %u (%u) shall be a multiple of the SDU interval %u",
105+
BT_GAP_ISO_INTERVAL_TO_US(info.iso_interval), info.iso_interval,
106+
SDU_INTERVAL_US);
107+
TEST_ASSERT(IN_RANGE(info.iso_interval, BT_ISO_ISO_INTERVAL_MIN, BT_ISO_ISO_INTERVAL_MAX),
108+
"Invalid ISO interval 0x%04x", info.iso_interval);
109+
TEST_ASSERT(IN_RANGE(info.max_subevent, BT_ISO_NSE_MIN, BT_ISO_NSE_MAX),
110+
"Invalid subevent number 0x%02x", info.max_subevent);
111+
TEST_ASSERT(IN_RANGE(info.broadcaster.sync_delay, BT_HCI_LE_BIG_SYNC_DELAY_MIN,
112+
BT_HCI_LE_BIG_SYNC_DELAY_MAX),
113+
"Invalid sync delay 0x%06x", info.broadcaster.sync_delay);
114+
TEST_ASSERT(IN_RANGE(info.broadcaster.latency, BT_HCI_LE_TRANSPORT_LATENCY_BIG_MIN,
115+
BT_HCI_LE_TRANSPORT_LATENCY_BIG_MAX),
116+
"Invalid transport latency 0x%06x", info.broadcaster.latency);
117+
TEST_ASSERT((info.broadcaster.pto % info.iso_interval) == 0U,
118+
"PTO in ms %u shall be a multiple of the ISO interval %u", info.broadcaster.pto,
119+
info.iso_interval);
120+
TEST_ASSERT(IN_RANGE((info.broadcaster.pto / info.iso_interval), BT_ISO_PTO_MIN,
121+
BT_ISO_PTO_MAX),
122+
"Invalid PTO 0x%x", (info.broadcaster.pto / info.iso_interval));
123+
TEST_ASSERT(info.broadcaster.phy == BT_GAP_LE_PHY_1M ||
124+
info.broadcaster.phy == BT_GAP_LE_PHY_2M ||
125+
info.broadcaster.phy == BT_GAP_LE_PHY_CODED,
126+
"Invalid PHY 0x%02x", info.broadcaster.phy);
127+
TEST_ASSERT(IN_RANGE(info.broadcaster.bn, BT_ISO_BN_MIN, BT_ISO_BN_MAX),
128+
"Invalid BN 0x%02x", info.broadcaster.bn);
129+
TEST_ASSERT(IN_RANGE(info.broadcaster.irc, BT_ISO_IRC_MIN, BT_ISO_IRC_MAX),
130+
"Invalid IRC 0x%02x", info.broadcaster.irc);
131+
91132
if (chan == default_chan) {
92133
seq_num = 0U;
93134

tests/bsim/bluetooth/host/iso/bis/src/bis_receiver.c

+28
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <zephyr/bluetooth/bluetooth.h>
1010
#include <zephyr/bluetooth/gap.h>
11+
#include <zephyr/bluetooth/hci_types.h>
1112
#include <zephyr/bluetooth/iso.h>
1213
#include <zephyr/logging/log.h>
1314
#include <zephyr/sys/util.h>
@@ -82,8 +83,35 @@ static void iso_recv(struct bt_iso_chan *chan, const struct bt_iso_recv_info *in
8283

8384
static void iso_connected(struct bt_iso_chan *chan)
8485
{
86+
struct bt_iso_info info;
87+
int err;
88+
8589
LOG_INF("ISO Channel %p connected", chan);
8690

91+
err = bt_iso_chan_get_info(chan, &info);
92+
TEST_ASSERT(err == 0, "Failed to get BIS info: %d", err);
93+
94+
TEST_ASSERT(info.can_recv);
95+
TEST_ASSERT(!info.can_send);
96+
TEST_ASSERT(info.type == BT_ISO_CHAN_TYPE_SYNC_RECEIVER);
97+
TEST_ASSERT(IN_RANGE(info.iso_interval, BT_ISO_ISO_INTERVAL_MIN, BT_ISO_ISO_INTERVAL_MAX),
98+
"Invalid ISO interval 0x%04x", info.iso_interval);
99+
TEST_ASSERT(IN_RANGE(info.max_subevent, BT_ISO_NSE_MIN, BT_ISO_NSE_MAX),
100+
"Invalid subevent number 0x%02x", info.max_subevent);
101+
TEST_ASSERT(IN_RANGE(info.sync_receiver.latency, BT_HCI_LE_TRANSPORT_LATENCY_BIG_MIN,
102+
BT_HCI_LE_TRANSPORT_LATENCY_BIG_MAX),
103+
"Invalid transport latency 0x%06x", info.sync_receiver.latency);
104+
TEST_ASSERT((info.sync_receiver.pto % info.iso_interval) == 0U,
105+
"PTO in ms %u shall be a multiple of the ISO interval %u",
106+
info.sync_receiver.pto, info.iso_interval);
107+
TEST_ASSERT(IN_RANGE((info.sync_receiver.pto / info.iso_interval), BT_ISO_PTO_MIN,
108+
BT_ISO_PTO_MAX),
109+
"Invalid PTO 0x%x", (info.sync_receiver.pto / info.iso_interval));
110+
TEST_ASSERT(IN_RANGE(info.sync_receiver.bn, BT_ISO_BN_MIN, BT_ISO_BN_MAX),
111+
"Invalid BN 0x%02x", info.sync_receiver.bn);
112+
TEST_ASSERT(IN_RANGE(info.sync_receiver.irc, BT_ISO_IRC_MIN, BT_ISO_IRC_MAX),
113+
"Invalid IRC 0x%02x", info.sync_receiver.irc);
114+
87115
SET_FLAG(flag_iso_connected);
88116
}
89117

0 commit comments

Comments
 (0)