Skip to content

Commit 06529e5

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 80be486 commit 06529e5

File tree

3 files changed

+161
-42
lines changed

3 files changed

+161
-42
lines changed

include/zephyr/bluetooth/hci_types.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3499,6 +3499,15 @@ struct bt_hci_evt_le_past_received {
34993499
uint8_t clock_accuracy;
35003500
} __packed;
35013501

3502+
#define BT_HCI_LE_CIG_SYNC_DELAY_MIN 0x0000F2U
3503+
#define BT_HCI_LE_CIG_SYNC_DELAY_MAX 0x7FFFFFU
3504+
#define BT_HCI_LE_CIS_SYNC_DELAY_MIN 0x0000F2U
3505+
#define BT_HCI_LE_CIS_SYNC_DELAY_MAX 0x7FFFFFU
3506+
#define BT_HCI_LE_TRANSPORT_LATENCY_C_TO_P_MIN 0x0000F2U
3507+
#define BT_HCI_LE_TRANSPORT_LATENCY_C_TO_P_MAX 0x7FFFFFU
3508+
#define BT_HCI_LE_TRANSPORT_LATENCY_P_TO_C_MIN 0x0000F2U
3509+
#define BT_HCI_LE_TRANSPORT_LATENCY_P_TO_C_MAX 0x7FFFFFU
3510+
35023511
#define BT_HCI_EVT_LE_CIS_ESTABLISHED 0x19
35033512
struct bt_hci_evt_le_cis_established {
35043513
uint8_t status;

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

Lines changed: 99 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@
3131
extern enum bst_result_t bst_result;
3232
static struct bt_iso_chan iso_chans[CONFIG_BT_ISO_MAX_CHAN];
3333
static struct bt_iso_chan *default_chan = &iso_chans[0];
34+
static struct bt_iso_cig_param cig_param;
3435
static struct bt_iso_cig *cig;
3536
static uint16_t seq_num;
3637
static volatile size_t enqueue_cnt;
37-
static uint32_t latency_ms = 10U; /* 10ms */
38+
static uint32_t latency_ms = 10U; /* 10ms */
3839
static uint32_t interval_us = 10U * USEC_PER_MSEC; /* 10 ms */
3940
NET_BUF_POOL_FIXED_DEFINE(tx_pool, ENQUEUE_COUNT, BT_ISO_SDU_BUF_SIZE(CONFIG_BT_ISO_TX_MTU),
4041
CONFIG_BT_CONN_TX_USER_DATA_SIZE, NULL);
@@ -122,13 +123,72 @@ static void iso_connected(struct bt_iso_chan *chan)
122123
.pid = BT_ISO_DATA_PATH_HCI,
123124
.format = BT_HCI_CODING_FORMAT_TRANSPARENT,
124125
};
126+
struct bt_iso_info info;
125127
int err;
126128

127129
printk("ISO Channel %p connected\n", chan);
128130

129131
seq_num = 0U;
130132
enqueue_cnt = ENQUEUE_COUNT;
131133

134+
err = bt_iso_chan_get_info(chan, &info);
135+
TEST_ASSERT(err == 0, "Failed to get CIS info: %d", err);
136+
137+
TEST_ASSERT(info.type == BT_ISO_CHAN_TYPE_CENTRAL);
138+
TEST_ASSERT(info.can_send || info.can_recv);
139+
TEST_ASSERT(IN_RANGE(info.iso_interval, BT_ISO_ISO_INTERVAL_MIN, BT_ISO_ISO_INTERVAL_MAX),
140+
"Invalid ISO interval 0x%04x", info.iso_interval);
141+
TEST_ASSERT(IN_RANGE(info.max_subevent, BT_ISO_NSE_MIN, BT_ISO_NSE_MAX),
142+
"Invalid subevent number 0x%02x", info.max_subevent);
143+
TEST_ASSERT(IN_RANGE(info.unicast.cig_sync_delay, BT_HCI_LE_CIG_SYNC_DELAY_MIN,
144+
BT_HCI_LE_CIG_SYNC_DELAY_MAX),
145+
"Invalid CIG sync delay 0x%06x", info.unicast.cig_sync_delay);
146+
TEST_ASSERT(IN_RANGE(info.unicast.cis_sync_delay, BT_HCI_LE_CIS_SYNC_DELAY_MIN,
147+
BT_HCI_LE_CIS_SYNC_DELAY_MAX),
148+
"Invalid CIS sync delay 0x%06x", info.unicast.cis_sync_delay);
149+
150+
if (info.can_send) {
151+
const struct bt_iso_unicast_tx_info *central = &info.unicast.central;
152+
153+
TEST_ASSERT((info.iso_interval % cig_param.c_to_p_interval) == 0U,
154+
"ISO interval %u shall be a multiple of the SDU interval %u",
155+
info.iso_interval, cig_param.c_to_p_interval);
156+
TEST_ASSERT(IN_RANGE(central->latency, BT_HCI_LE_TRANSPORT_LATENCY_C_TO_P_MIN,
157+
BT_HCI_LE_TRANSPORT_LATENCY_C_TO_P_MAX),
158+
"Invalid transport latency 0x%06x", central->latency);
159+
TEST_ASSERT((central->flush_timeout % info.iso_interval) == 0U,
160+
"Flush timeout in ms %u shall be a multiple of the ISO interval %u",
161+
central->flush_timeout, info.iso_interval);
162+
TEST_ASSERT(IN_RANGE(central->max_pdu, BT_ISO_CONNECTED_PDU_MIN, BT_ISO_PDU_MAX),
163+
"Invalid max PDU 0x%04x", central->max_pdu);
164+
TEST_ASSERT(central->phy == BT_GAP_LE_PHY_1M || central->phy == BT_GAP_LE_PHY_2M ||
165+
central->phy == BT_GAP_LE_PHY_CODED,
166+
"Invalid PHY 0x%02x", central->phy);
167+
TEST_ASSERT(IN_RANGE(central->bn, BT_ISO_BN_MIN, BT_ISO_BN_MAX),
168+
"Invalid BN 0x%02x", central->bn);
169+
}
170+
if (info.can_recv) {
171+
const struct bt_iso_unicast_tx_info *peripheral = &info.unicast.peripheral;
172+
173+
TEST_ASSERT((info.iso_interval % cig_param.p_to_c_interval) == 0U,
174+
"ISO interval %u shall be a multiple of the SDU interval %u",
175+
info.iso_interval, cig_param.p_to_c_interval);
176+
TEST_ASSERT(IN_RANGE(peripheral->latency, BT_HCI_LE_TRANSPORT_LATENCY_P_TO_C_MIN,
177+
BT_HCI_LE_TRANSPORT_LATENCY_P_TO_C_MAX),
178+
"Invalid transport latency 0x%06x", peripheral->latency);
179+
TEST_ASSERT((peripheral->flush_timeout % info.iso_interval) == 0U,
180+
"Flush timeout in ms %u shall be a multiple of the ISO interval %u",
181+
peripheral->flush_timeout, info.iso_interval);
182+
TEST_ASSERT(IN_RANGE(peripheral->max_pdu, BT_ISO_CONNECTED_PDU_MIN, BT_ISO_PDU_MAX),
183+
"Invalid max PDU 0x%04x", peripheral->max_pdu);
184+
TEST_ASSERT(peripheral->phy == BT_GAP_LE_PHY_1M ||
185+
peripheral->phy == BT_GAP_LE_PHY_2M ||
186+
peripheral->phy == BT_GAP_LE_PHY_CODED,
187+
"Invalid PHY 0x%02x", peripheral->phy);
188+
TEST_ASSERT(IN_RANGE(peripheral->bn, BT_ISO_BN_MIN, BT_ISO_BN_MAX),
189+
"Invalid BN 0x%02x", peripheral->bn);
190+
}
191+
132192
if (chan == default_chan) {
133193
/* Start send timer */
134194
k_work_schedule(&iso_send_work, K_MSEC(0));
@@ -212,68 +272,66 @@ static void init(void)
212272
}
213273
}
214274

215-
static void set_cig_defaults(struct bt_iso_cig_param *param)
275+
static void set_cig_defaults(void)
216276
{
217-
param->cis_channels = &default_chan;
218-
param->num_cis = 1U;
219-
param->sca = BT_GAP_SCA_UNKNOWN;
220-
param->packing = BT_ISO_PACKING_SEQUENTIAL;
221-
param->framing = BT_ISO_FRAMING_UNFRAMED;
222-
param->c_to_p_latency = latency_ms; /* ms */
223-
param->p_to_c_latency = latency_ms; /* ms */
224-
param->c_to_p_interval = interval_us; /* us */
225-
param->p_to_c_interval = interval_us; /* us */
226-
277+
cig_param.cis_channels = &default_chan;
278+
cig_param.num_cis = 1U;
279+
cig_param.sca = BT_GAP_SCA_UNKNOWN;
280+
cig_param.packing = BT_ISO_PACKING_SEQUENTIAL;
281+
cig_param.framing = BT_ISO_FRAMING_UNFRAMED;
282+
cig_param.c_to_p_latency = latency_ms; /* ms */
283+
cig_param.p_to_c_latency = latency_ms; /* ms */
284+
cig_param.c_to_p_interval = interval_us; /* us */
285+
cig_param.p_to_c_interval = interval_us; /* us */
227286
}
228287

229288
static void create_cig(size_t iso_channels)
230289
{
231290
struct bt_iso_chan *channels[ARRAY_SIZE(iso_chans)];
232-
struct bt_iso_cig_param param;
233291
int err;
234292

235293
for (size_t i = 0U; i < iso_channels; i++) {
236294
channels[i] = &iso_chans[i];
237295
}
238296

239-
set_cig_defaults(&param);
240-
param.num_cis = iso_channels;
241-
param.cis_channels = channels;
297+
set_cig_defaults();
298+
cig_param.num_cis = iso_channels;
299+
cig_param.cis_channels = channels;
242300

243-
err = bt_iso_cig_create(&param, &cig);
301+
err = bt_iso_cig_create(&cig_param, &cig);
244302
if (err != 0) {
245303
TEST_FAIL("Failed to create CIG (%d)", err);
246304

247305
return;
248306
}
249307
}
250308

251-
static int reconfigure_cig_interval(struct bt_iso_cig_param *param)
309+
static int reconfigure_cig_interval(void)
252310
{
253311
int err;
254312

255313
/* Test modifying CIG parameter without any CIS */
256-
param->num_cis = 0U;
257-
param->c_to_p_interval = 7500; /* us */
258-
param->p_to_c_interval = param->c_to_p_interval;
259-
err = bt_iso_cig_reconfigure(cig, param);
314+
cig_param.num_cis = 0U;
315+
cig_param.c_to_p_interval = 7500; /* us */
316+
cig_param.p_to_c_interval = cig_param.c_to_p_interval;
317+
err = bt_iso_cig_reconfigure(cig, &cig_param);
260318
if (err != 0) {
261319
TEST_FAIL("Failed to reconfigure CIG to new interval (%d)", err);
262320

263321
return err;
264322
}
265323

266-
err = bt_iso_cig_reconfigure(cig, param);
324+
err = bt_iso_cig_reconfigure(cig, &cig_param);
267325
if (err != 0) {
268326
TEST_FAIL("Failed to reconfigure CIG to same interval (%d)", err);
269327

270328
return err;
271329
}
272330

273331
/* Test modifying to different values for both intervals */
274-
param->c_to_p_interval = 5000; /* us */
275-
param->p_to_c_interval = 2500; /* us */
276-
err = bt_iso_cig_reconfigure(cig, param);
332+
cig_param.c_to_p_interval = 5000; /* us */
333+
cig_param.p_to_c_interval = 2500; /* us */
334+
err = bt_iso_cig_reconfigure(cig, &cig_param);
277335
if (err != 0) {
278336
TEST_FAIL("Failed to reconfigure CIG to new interval (%d)", err);
279337

@@ -283,24 +341,24 @@ static int reconfigure_cig_interval(struct bt_iso_cig_param *param)
283341
return 0;
284342
}
285343

286-
static int reconfigure_cig_latency(struct bt_iso_cig_param *param)
344+
static int reconfigure_cig_latency(void)
287345
{
288346
int err;
289347

290348
/* Test modifying CIG latency without any CIS */
291-
param->num_cis = 0U;
292-
param->c_to_p_latency = 20; /* ms */
293-
param->p_to_c_latency = param->c_to_p_latency;
294-
err = bt_iso_cig_reconfigure(cig, param);
349+
cig_param.num_cis = 0U;
350+
cig_param.c_to_p_latency = 20; /* ms */
351+
cig_param.p_to_c_latency = cig_param.c_to_p_latency;
352+
err = bt_iso_cig_reconfigure(cig, &cig_param);
295353
if (err != 0) {
296354
TEST_FAIL("Failed to reconfigure CIG latency (%d)", err);
297355

298356
return err;
299357
}
300358

301-
param->c_to_p_latency = 30; /* ms */
302-
param->p_to_c_latency = 40; /* ms */
303-
err = bt_iso_cig_reconfigure(cig, param);
359+
cig_param.c_to_p_latency = 30; /* ms */
360+
cig_param.p_to_c_latency = 40; /* ms */
361+
err = bt_iso_cig_reconfigure(cig, &cig_param);
304362
if (err != 0) {
305363
TEST_FAIL("Failed to reconfigure CIG for different latencies (%d)", err);
306364

@@ -313,42 +371,41 @@ static int reconfigure_cig_latency(struct bt_iso_cig_param *param)
313371
static void reconfigure_cig(void)
314372
{
315373
struct bt_iso_chan *channels[2];
316-
struct bt_iso_cig_param param;
317374
int err;
318375

319376
for (size_t i = 0U; i < ARRAY_SIZE(channels); i++) {
320377
channels[i] = &iso_chans[i];
321378
}
322379

323-
set_cig_defaults(&param);
380+
set_cig_defaults();
324381

325382
/* Test modifying existing CIS */
326383
default_chan->qos->tx->rtn++;
327384

328-
err = bt_iso_cig_reconfigure(cig, &param);
385+
err = bt_iso_cig_reconfigure(cig, &cig_param);
329386
if (err != 0) {
330387
TEST_FAIL("Failed to reconfigure CIS to new RTN (%d)", err);
331388

332389
return;
333390
}
334391

335392
/* Test modifying interval parameter */
336-
err = reconfigure_cig_interval(&param);
393+
err = reconfigure_cig_interval();
337394
if (err != 0) {
338395
return;
339396
}
340397

341398
/* Test modifying latency parameter */
342-
err = reconfigure_cig_latency(&param);
399+
err = reconfigure_cig_latency();
343400
if (err != 0) {
344401
return;
345402
}
346403

347404
/* Add CIS to the CIG and restore all other parameters */
348-
set_cig_defaults(&param);
349-
param.cis_channels = &channels[1];
405+
set_cig_defaults();
406+
cig_param.cis_channels = &channels[1];
350407

351-
err = bt_iso_cig_reconfigure(cig, &param);
408+
err = bt_iso_cig_reconfigure(cig, &cig_param);
352409
if (err != 0) {
353410
TEST_FAIL("Failed to reconfigure CIG with new CIS and original parameters (%d)",
354411
err);

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

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,65 @@ static void iso_connected(struct bt_iso_chan *chan)
103103
.pid = BT_ISO_DATA_PATH_HCI,
104104
.format = BT_HCI_CODING_FORMAT_TRANSPARENT,
105105
};
106+
struct bt_iso_info info;
106107
int err;
107108

108109
printk("ISO Channel %p connected\n", chan);
109110

110111
err = bt_iso_setup_data_path(chan, BT_HCI_DATAPATH_DIR_CTLR_TO_HOST, &hci_path);
111112
TEST_ASSERT(err == 0, "Failed to set ISO data path: %d", err);
113+
114+
err = bt_iso_chan_get_info(chan, &info);
115+
TEST_ASSERT(err == 0, "Failed to get CIS info: %d", err);
116+
117+
TEST_ASSERT(info.type == BT_ISO_CHAN_TYPE_PERIPHERAL);
118+
TEST_ASSERT(IN_RANGE(info.iso_interval, BT_ISO_ISO_INTERVAL_MIN, BT_ISO_ISO_INTERVAL_MAX),
119+
"Invalid ISO interval 0x%04x", info.iso_interval);
120+
TEST_ASSERT(IN_RANGE(info.max_subevent, BT_ISO_NSE_MIN, BT_ISO_NSE_MAX),
121+
"Invalid subevent number 0x%02x", info.max_subevent);
122+
TEST_ASSERT(IN_RANGE(info.unicast.cig_sync_delay, BT_HCI_LE_CIG_SYNC_DELAY_MIN,
123+
BT_HCI_LE_CIG_SYNC_DELAY_MAX),
124+
"Invalid CIG sync delay 0x%06x", info.unicast.cig_sync_delay);
125+
TEST_ASSERT(IN_RANGE(info.unicast.cis_sync_delay, BT_HCI_LE_CIS_SYNC_DELAY_MIN,
126+
BT_HCI_LE_CIS_SYNC_DELAY_MAX),
127+
"Invalid CIS sync delay 0x%06x", info.unicast.cis_sync_delay);
128+
129+
if (info.can_send) {
130+
const struct bt_iso_unicast_tx_info *peripheral = &info.unicast.peripheral;
131+
132+
TEST_ASSERT(IN_RANGE(peripheral->latency, BT_HCI_LE_TRANSPORT_LATENCY_P_TO_C_MIN,
133+
BT_HCI_LE_TRANSPORT_LATENCY_P_TO_C_MAX),
134+
"Invalid transport latency 0x%06x", peripheral->latency);
135+
TEST_ASSERT((peripheral->flush_timeout % info.iso_interval) == 0U,
136+
"Flush timeout in ms %u shall be a multiple of the ISO interval %u",
137+
peripheral->flush_timeout, info.iso_interval);
138+
TEST_ASSERT(IN_RANGE(peripheral->max_pdu, BT_ISO_CONNECTED_PDU_MIN, BT_ISO_PDU_MAX),
139+
"Invalid max PDU 0x%04x", peripheral->max_pdu);
140+
TEST_ASSERT(peripheral->phy == BT_GAP_LE_PHY_1M ||
141+
peripheral->phy == BT_GAP_LE_PHY_2M ||
142+
peripheral->phy == BT_GAP_LE_PHY_CODED,
143+
"Invalid PHY 0x%02x", peripheral->phy);
144+
TEST_ASSERT(IN_RANGE(peripheral->bn, BT_ISO_BN_MIN, BT_ISO_BN_MAX),
145+
"Invalid BN 0x%02x", peripheral->bn);
146+
}
147+
148+
if (info.can_recv) {
149+
const struct bt_iso_unicast_tx_info *central = &info.unicast.central;
150+
151+
TEST_ASSERT(IN_RANGE(central->latency, BT_HCI_LE_TRANSPORT_LATENCY_C_TO_P_MIN,
152+
BT_HCI_LE_TRANSPORT_LATENCY_C_TO_P_MAX),
153+
"Invalid transport latency 0x%06x", central->latency);
154+
TEST_ASSERT((central->flush_timeout % info.iso_interval) == 0U,
155+
"Flush timeout in ms %u shall be a multiple of the ISO interval %u",
156+
central->flush_timeout, info.iso_interval);
157+
TEST_ASSERT(IN_RANGE(central->max_pdu, BT_ISO_CONNECTED_PDU_MIN, BT_ISO_PDU_MAX),
158+
"Invalid max PDU 0x%04x", central->max_pdu);
159+
TEST_ASSERT(central->phy == BT_GAP_LE_PHY_1M || central->phy == BT_GAP_LE_PHY_2M ||
160+
central->phy == BT_GAP_LE_PHY_CODED,
161+
"Invalid PHY 0x%02x", central->phy);
162+
TEST_ASSERT(IN_RANGE(central->bn, BT_ISO_BN_MIN, BT_ISO_BN_MAX),
163+
"Invalid BN 0x%02x", central->bn);
164+
}
112165
}
113166

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

0 commit comments

Comments
 (0)