Skip to content

Commit 63c688a

Browse files
committed
tests: Bluetooth: ISO: Add validation of unicast 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 059e86f commit 63c688a

File tree

4 files changed

+178
-42
lines changed

4 files changed

+178
-42
lines changed

include/zephyr/bluetooth/hci_types.h

+9
Original file line numberDiff line numberDiff line change
@@ -3351,6 +3351,15 @@ struct bt_hci_evt_le_past_received {
33513351
uint8_t clock_accuracy;
33523352
} __packed;
33533353

3354+
#define BT_HCI_LE_CIG_SYNC_DELAY_MIN 0x0000F2U
3355+
#define BT_HCI_LE_CIG_SYNC_DELAY_MAX 0x7FFFFFU
3356+
#define BT_HCI_LE_CIS_SYNC_DELAY_MIN 0x0000F2U
3357+
#define BT_HCI_LE_CIS_SYNC_DELAY_MAX 0x7FFFFFU
3358+
#define BT_HCI_LE_TRANSPORT_LATENCY_C_TO_P_MIN 0x0000F2U
3359+
#define BT_HCI_LE_TRANSPORT_LATENCY_C_TO_P_MAX 0x7FFFFFU
3360+
#define BT_HCI_LE_TRANSPORT_LATENCY_P_TO_C_MIN 0x0000F2U
3361+
#define BT_HCI_LE_TRANSPORT_LATENCY_P_TO_C_MAX 0x7FFFFFU
3362+
33543363
#define BT_HCI_EVT_LE_CIS_ESTABLISHED 0x19
33553364
struct bt_hci_evt_le_cis_established {
33563365
uint8_t status;

tests/bsim/bluetooth/host/iso/cis/CMakeLists.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
cmake_minimum_required(VERSION 3.20.0)
44

55
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
6-
project(bsim_test_l2cap_send_on_connect)
6+
7+
project(bsim_test_iso_cis)
8+
9+
add_subdirectory(${ZEPHYR_BASE}/tests/bsim/babblekit babblekit)
10+
target_link_libraries(app PRIVATE babblekit)
711

812
target_sources(app PRIVATE
913
src/common.c

tests/bsim/bluetooth/host/iso/cis/src/cis_central.c

+105-41
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,20 @@
99
#include "common.h"
1010

1111
#include <zephyr/bluetooth/bluetooth.h>
12+
#include <zephyr/bluetooth/gap.h>
13+
#include <zephyr/bluetooth/hci_types.h>
1214
#include <zephyr/bluetooth/iso.h>
1315
#include <zephyr/sys/printk.h>
16+
#include <zephyr/sys/util.h>
17+
18+
#include <babblekit/testcase.h>
1419

1520
#define ENQUEUE_COUNT 2
1621

1722
extern enum bst_result_t bst_result;
1823
static struct bt_iso_chan iso_chans[CONFIG_BT_ISO_MAX_CHAN];
1924
static struct bt_iso_chan *default_chan = &iso_chans[0];
25+
static struct bt_iso_cig_param cig_param;
2026
static struct bt_iso_cig *cig;
2127
static uint16_t seq_num;
2228
static volatile size_t enqueue_cnt;
@@ -104,11 +110,72 @@ static void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type,
104110

105111
static void iso_connected(struct bt_iso_chan *chan)
106112
{
113+
struct bt_iso_info info;
114+
int err;
115+
107116
printk("ISO Channel %p connected\n", chan);
108117

109118
seq_num = 0U;
110119
enqueue_cnt = ENQUEUE_COUNT;
111120

121+
err = bt_iso_chan_get_info(chan, &info);
122+
TEST_ASSERT(err == 0, "Failed to get CIS info: %d", err);
123+
124+
TEST_ASSERT(info.type == BT_ISO_CHAN_TYPE_CONNECTED);
125+
TEST_ASSERT(info.can_send || info.can_recv);
126+
TEST_ASSERT(IN_RANGE(info.iso_interval, BT_ISO_ISO_INTERVAL_MIN, BT_ISO_ISO_INTERVAL_MAX),
127+
"Invalid ISO interval 0x%04x", info.iso_interval);
128+
TEST_ASSERT(IN_RANGE(info.max_subevent, BT_ISO_NSE_MIN, BT_ISO_NSE_MAX),
129+
"Invalid subevent number 0x%02x", info.max_subevent);
130+
TEST_ASSERT(IN_RANGE(info.unicast.cig_sync_delay, BT_HCI_LE_CIG_SYNC_DELAY_MIN,
131+
BT_HCI_LE_CIG_SYNC_DELAY_MAX),
132+
"Invalid CIG sync delay 0x%06x", info.unicast.cig_sync_delay);
133+
TEST_ASSERT(IN_RANGE(info.unicast.cis_sync_delay, BT_HCI_LE_CIS_SYNC_DELAY_MIN,
134+
BT_HCI_LE_CIS_SYNC_DELAY_MAX),
135+
"Invalid CIS sync delay 0x%06x", info.unicast.cis_sync_delay);
136+
137+
if (info.can_send) {
138+
const struct bt_iso_unicast_tx_info *central = &info.unicast.central;
139+
140+
TEST_ASSERT((info.iso_interval % cig_param.c_to_p_interval) == 0U,
141+
"ISO interval %u shall be a multiple of the SDU interval %u",
142+
info.iso_interval, cig_param.c_to_p_interval);
143+
TEST_ASSERT(IN_RANGE(central->latency, BT_HCI_LE_TRANSPORT_LATENCY_C_TO_P_MIN,
144+
BT_HCI_LE_TRANSPORT_LATENCY_C_TO_P_MAX),
145+
"Invalid transport latency 0x%06x", central->latency);
146+
TEST_ASSERT((central->flush_timeout % info.iso_interval) == 0U,
147+
"Flush timeout in ms %u shall be a multiple of the ISO interval %u",
148+
central->flush_timeout, info.iso_interval);
149+
TEST_ASSERT(IN_RANGE(central->max_pdu, BT_ISO_CONNECTED_PDU_MIN, BT_ISO_PDU_MAX),
150+
"Invalid max PDU 0x%04x", central->max_pdu);
151+
TEST_ASSERT(central->phy == BT_GAP_LE_PHY_1M || central->phy == BT_GAP_LE_PHY_2M ||
152+
central->phy == BT_GAP_LE_PHY_CODED,
153+
"Invalid PHY 0x%02x", central->phy);
154+
TEST_ASSERT(IN_RANGE(central->bn, BT_ISO_BN_MIN, BT_ISO_BN_MAX),
155+
"Invalid BN 0x%02x", central->bn);
156+
}
157+
if (info.can_recv) {
158+
const struct bt_iso_unicast_tx_info *peripheral = &info.unicast.peripheral;
159+
160+
TEST_ASSERT((info.iso_interval % cig_param.p_to_c_interval) == 0U,
161+
"ISO interval %u shall be a multiple of the SDU interval %u",
162+
info.iso_interval, cig_param.p_to_c_interval);
163+
TEST_ASSERT(IN_RANGE(peripheral->latency, BT_HCI_LE_TRANSPORT_LATENCY_P_TO_C_MIN,
164+
BT_HCI_LE_TRANSPORT_LATENCY_P_TO_C_MAX),
165+
"Invalid transport latency 0x%06x", peripheral->latency);
166+
TEST_ASSERT((peripheral->flush_timeout % info.iso_interval) == 0U,
167+
"Flush timeout in ms %u shall be a multiple of the ISO interval %u",
168+
peripheral->flush_timeout, info.iso_interval);
169+
TEST_ASSERT(IN_RANGE(peripheral->max_pdu, BT_ISO_CONNECTED_PDU_MIN, BT_ISO_PDU_MAX),
170+
"Invalid max PDU 0x%04x", peripheral->max_pdu);
171+
TEST_ASSERT(peripheral->phy == BT_GAP_LE_PHY_1M ||
172+
peripheral->phy == BT_GAP_LE_PHY_2M ||
173+
peripheral->phy == BT_GAP_LE_PHY_CODED,
174+
"Invalid PHY 0x%02x", peripheral->phy);
175+
TEST_ASSERT(IN_RANGE(peripheral->bn, BT_ISO_BN_MIN, BT_ISO_BN_MAX),
176+
"Invalid BN 0x%02x", peripheral->bn);
177+
}
178+
112179
if (chan == default_chan) {
113180
/* Start send timer */
114181
k_work_schedule(&iso_send_work, K_MSEC(0));
@@ -180,68 +247,66 @@ static void init(void)
180247
}
181248
}
182249

183-
static void set_cig_defaults(struct bt_iso_cig_param *param)
250+
static void set_cig_defaults(void)
184251
{
185-
param->cis_channels = &default_chan;
186-
param->num_cis = 1U;
187-
param->sca = BT_GAP_SCA_UNKNOWN;
188-
param->packing = BT_ISO_PACKING_SEQUENTIAL;
189-
param->framing = BT_ISO_FRAMING_UNFRAMED;
190-
param->c_to_p_latency = latency_ms; /* ms */
191-
param->p_to_c_latency = latency_ms; /* ms */
192-
param->c_to_p_interval = interval_us; /* us */
193-
param->p_to_c_interval = interval_us; /* us */
194-
252+
cig_param.cis_channels = &default_chan;
253+
cig_param.num_cis = 1U;
254+
cig_param.sca = BT_GAP_SCA_UNKNOWN;
255+
cig_param.packing = BT_ISO_PACKING_SEQUENTIAL;
256+
cig_param.framing = BT_ISO_FRAMING_UNFRAMED;
257+
cig_param.c_to_p_latency = latency_ms; /* ms */
258+
cig_param.p_to_c_latency = latency_ms; /* ms */
259+
cig_param.c_to_p_interval = interval_us; /* us */
260+
cig_param.p_to_c_interval = interval_us; /* us */
195261
}
196262

197263
static void create_cig(size_t iso_channels)
198264
{
199265
struct bt_iso_chan *channels[ARRAY_SIZE(iso_chans)];
200-
struct bt_iso_cig_param param;
201266
int err;
202267

203268
for (size_t i = 0U; i < iso_channels; i++) {
204269
channels[i] = &iso_chans[i];
205270
}
206271

207-
set_cig_defaults(&param);
208-
param.num_cis = iso_channels;
209-
param.cis_channels = channels;
272+
set_cig_defaults();
273+
cig_param.num_cis = iso_channels;
274+
cig_param.cis_channels = channels;
210275

211-
err = bt_iso_cig_create(&param, &cig);
276+
err = bt_iso_cig_create(&cig_param, &cig);
212277
if (err != 0) {
213278
TEST_FAIL("Failed to create CIG (%d)", err);
214279

215280
return;
216281
}
217282
}
218283

219-
static int reconfigure_cig_interval(struct bt_iso_cig_param *param)
284+
static int reconfigure_cig_interval(void)
220285
{
221286
int err;
222287

223288
/* Test modifying CIG parameter without any CIS */
224-
param->num_cis = 0U;
225-
param->c_to_p_interval = 7500; /* us */
226-
param->p_to_c_interval = param->c_to_p_interval;
227-
err = bt_iso_cig_reconfigure(cig, param);
289+
cig_param.num_cis = 0U;
290+
cig_param.c_to_p_interval = 7500; /* us */
291+
cig_param.p_to_c_interval = cig_param.c_to_p_interval;
292+
err = bt_iso_cig_reconfigure(cig, &cig_param);
228293
if (err != 0) {
229294
TEST_FAIL("Failed to reconfigure CIG to new interval (%d)", err);
230295

231296
return err;
232297
}
233298

234-
err = bt_iso_cig_reconfigure(cig, param);
299+
err = bt_iso_cig_reconfigure(cig, &cig_param);
235300
if (err != 0) {
236301
TEST_FAIL("Failed to reconfigure CIG to same interval (%d)", err);
237302

238303
return err;
239304
}
240305

241306
/* Test modifying to different values for both intervals */
242-
param->c_to_p_interval = 5000; /* us */
243-
param->p_to_c_interval = 2500; /* us */
244-
err = bt_iso_cig_reconfigure(cig, param);
307+
cig_param.c_to_p_interval = 5000; /* us */
308+
cig_param.p_to_c_interval = 2500; /* us */
309+
err = bt_iso_cig_reconfigure(cig, &cig_param);
245310
if (err != 0) {
246311
TEST_FAIL("Failed to reconfigure CIG to new interval (%d)", err);
247312

@@ -251,24 +316,24 @@ static int reconfigure_cig_interval(struct bt_iso_cig_param *param)
251316
return 0;
252317
}
253318

254-
static int reconfigure_cig_latency(struct bt_iso_cig_param *param)
319+
static int reconfigure_cig_latency(void)
255320
{
256321
int err;
257322

258323
/* Test modifying CIG latency without any CIS */
259-
param->num_cis = 0U;
260-
param->c_to_p_latency = 20; /* ms */
261-
param->p_to_c_latency = param->c_to_p_latency;
262-
err = bt_iso_cig_reconfigure(cig, param);
324+
cig_param.num_cis = 0U;
325+
cig_param.c_to_p_latency = 20; /* ms */
326+
cig_param.p_to_c_latency = cig_param.c_to_p_latency;
327+
err = bt_iso_cig_reconfigure(cig, &cig_param);
263328
if (err != 0) {
264329
TEST_FAIL("Failed to reconfigure CIG latency (%d)", err);
265330

266331
return err;
267332
}
268333

269-
param->c_to_p_latency = 30; /* ms */
270-
param->p_to_c_latency = 40; /* ms */
271-
err = bt_iso_cig_reconfigure(cig, param);
334+
cig_param.c_to_p_latency = 30; /* ms */
335+
cig_param.p_to_c_latency = 40; /* ms */
336+
err = bt_iso_cig_reconfigure(cig, &cig_param);
272337
if (err != 0) {
273338
TEST_FAIL("Failed to reconfigure CIG for different latencies (%d)", err);
274339

@@ -281,42 +346,41 @@ static int reconfigure_cig_latency(struct bt_iso_cig_param *param)
281346
static void reconfigure_cig(void)
282347
{
283348
struct bt_iso_chan *channels[2];
284-
struct bt_iso_cig_param param;
285349
int err;
286350

287351
for (size_t i = 0U; i < ARRAY_SIZE(channels); i++) {
288352
channels[i] = &iso_chans[i];
289353
}
290354

291-
set_cig_defaults(&param);
355+
set_cig_defaults();
292356

293357
/* Test modifying existing CIS */
294358
default_chan->qos->tx->rtn++;
295359

296-
err = bt_iso_cig_reconfigure(cig, &param);
360+
err = bt_iso_cig_reconfigure(cig, &cig_param);
297361
if (err != 0) {
298362
TEST_FAIL("Failed to reconfigure CIS to new RTN (%d)", err);
299363

300364
return;
301365
}
302366

303367
/* Test modifying interval parameter */
304-
err = reconfigure_cig_interval(&param);
368+
err = reconfigure_cig_interval();
305369
if (err != 0) {
306370
return;
307371
}
308372

309373
/* Test modifying latency parameter */
310-
err = reconfigure_cig_latency(&param);
374+
err = reconfigure_cig_latency();
311375
if (err != 0) {
312376
return;
313377
}
314378

315379
/* Add CIS to the CIG and restore all other parameters */
316-
set_cig_defaults(&param);
317-
param.cis_channels = &channels[1];
380+
set_cig_defaults();
381+
cig_param.cis_channels = &channels[1];
318382

319-
err = bt_iso_cig_reconfigure(cig, &param);
383+
err = bt_iso_cig_reconfigure(cig, &cig_param);
320384
if (err != 0) {
321385
TEST_FAIL("Failed to reconfigure CIG with new CIS and original parameters (%d)",
322386
err);

tests/bsim/bluetooth/host/iso/cis/src/cis_peripheral.c

+59
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@
1111
#include "common.h"
1212

1313
#include <zephyr/bluetooth/bluetooth.h>
14+
#include <zephyr/bluetooth/gap.h>
15+
#include <zephyr/bluetooth/hci_types.h>
1416
#include <zephyr/bluetooth/iso.h>
1517
#include <zephyr/sys/printk.h>
18+
#include <zephyr/sys/util.h>
1619

20+
#include <babblekit/testcase.h>
1721
#include <testlib/conn.h>
1822

1923
extern enum bst_result_t bst_result;
@@ -74,7 +78,62 @@ static void iso_recv(struct bt_iso_chan *chan, const struct bt_iso_recv_info *in
7478

7579
static void iso_connected(struct bt_iso_chan *chan)
7680
{
81+
struct bt_iso_info info;
82+
int err;
83+
7784
printk("ISO Channel %p connected\n", chan);
85+
86+
err = bt_iso_chan_get_info(chan, &info);
87+
TEST_ASSERT(err == 0, "Failed to get CIS info: %d", err);
88+
89+
TEST_ASSERT(info.type == BT_ISO_CHAN_TYPE_CONNECTED);
90+
TEST_ASSERT(IN_RANGE(info.iso_interval, BT_ISO_ISO_INTERVAL_MIN, BT_ISO_ISO_INTERVAL_MAX),
91+
"Invalid ISO interval 0x%04x", info.iso_interval);
92+
TEST_ASSERT(IN_RANGE(info.max_subevent, BT_ISO_NSE_MIN, BT_ISO_NSE_MAX),
93+
"Invalid subevent number 0x%02x", info.max_subevent);
94+
TEST_ASSERT(IN_RANGE(info.unicast.cig_sync_delay, BT_HCI_LE_CIG_SYNC_DELAY_MIN,
95+
BT_HCI_LE_CIG_SYNC_DELAY_MAX),
96+
"Invalid CIG sync delay 0x%06x", info.unicast.cig_sync_delay);
97+
TEST_ASSERT(IN_RANGE(info.unicast.cis_sync_delay, BT_HCI_LE_CIS_SYNC_DELAY_MIN,
98+
BT_HCI_LE_CIS_SYNC_DELAY_MAX),
99+
"Invalid CIS sync delay 0x%06x", info.unicast.cis_sync_delay);
100+
101+
if (info.can_send) {
102+
const struct bt_iso_unicast_tx_info *peripheral = &info.unicast.peripheral;
103+
104+
TEST_ASSERT(IN_RANGE(peripheral->latency, BT_HCI_LE_TRANSPORT_LATENCY_P_TO_C_MIN,
105+
BT_HCI_LE_TRANSPORT_LATENCY_P_TO_C_MAX),
106+
"Invalid transport latency 0x%06x", peripheral->latency);
107+
TEST_ASSERT((peripheral->flush_timeout % info.iso_interval) == 0U,
108+
"Flush timeout in ms %u shall be a multiple of the ISO interval %u",
109+
peripheral->flush_timeout, info.iso_interval);
110+
TEST_ASSERT(IN_RANGE(peripheral->max_pdu, BT_ISO_CONNECTED_PDU_MIN, BT_ISO_PDU_MAX),
111+
"Invalid max PDU 0x%04x", peripheral->max_pdu);
112+
TEST_ASSERT(peripheral->phy == BT_GAP_LE_PHY_1M ||
113+
peripheral->phy == BT_GAP_LE_PHY_2M ||
114+
peripheral->phy == BT_GAP_LE_PHY_CODED,
115+
"Invalid PHY 0x%02x", peripheral->phy);
116+
TEST_ASSERT(IN_RANGE(peripheral->bn, BT_ISO_BN_MIN, BT_ISO_BN_MAX),
117+
"Invalid BN 0x%02x", peripheral->bn);
118+
}
119+
120+
if (info.can_recv) {
121+
const struct bt_iso_unicast_tx_info *central = &info.unicast.central;
122+
123+
TEST_ASSERT(IN_RANGE(central->latency, BT_HCI_LE_TRANSPORT_LATENCY_C_TO_P_MIN,
124+
BT_HCI_LE_TRANSPORT_LATENCY_C_TO_P_MAX),
125+
"Invalid transport latency 0x%06x", central->latency);
126+
TEST_ASSERT((central->flush_timeout % info.iso_interval) == 0U,
127+
"Flush timeout in ms %u shall be a multiple of the ISO interval %u",
128+
central->flush_timeout, info.iso_interval);
129+
TEST_ASSERT(IN_RANGE(central->max_pdu, BT_ISO_CONNECTED_PDU_MIN, BT_ISO_PDU_MAX),
130+
"Invalid max PDU 0x%04x", central->max_pdu);
131+
TEST_ASSERT(central->phy == BT_GAP_LE_PHY_1M || central->phy == BT_GAP_LE_PHY_2M ||
132+
central->phy == BT_GAP_LE_PHY_CODED,
133+
"Invalid PHY 0x%02x", central->phy);
134+
TEST_ASSERT(IN_RANGE(central->bn, BT_ISO_BN_MIN, BT_ISO_BN_MAX),
135+
"Invalid BN 0x%02x", central->bn);
136+
}
78137
}
79138

80139
static void iso_disconnected(struct bt_iso_chan *chan, uint8_t reason)

0 commit comments

Comments
 (0)