Skip to content

Commit f6525a7

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 fd4cc0e commit f6525a7

File tree

3 files changed

+161
-42
lines changed

3 files changed

+161
-42
lines changed

include/zephyr/bluetooth/hci_types.h

+9
Original file line numberDiff line numberDiff line change
@@ -3375,6 +3375,15 @@ struct bt_hci_evt_le_past_received {
33753375
uint8_t clock_accuracy;
33763376
} __packed;
33773377

3378+
#define BT_HCI_LE_CIG_SYNC_DELAY_MIN 0x0000F2U
3379+
#define BT_HCI_LE_CIG_SYNC_DELAY_MAX 0x7FFFFFU
3380+
#define BT_HCI_LE_CIS_SYNC_DELAY_MIN 0x0000F2U
3381+
#define BT_HCI_LE_CIS_SYNC_DELAY_MAX 0x7FFFFFU
3382+
#define BT_HCI_LE_TRANSPORT_LATENCY_C_TO_P_MIN 0x0000F2U
3383+
#define BT_HCI_LE_TRANSPORT_LATENCY_C_TO_P_MAX 0x7FFFFFU
3384+
#define BT_HCI_LE_TRANSPORT_LATENCY_P_TO_C_MIN 0x0000F2U
3385+
#define BT_HCI_LE_TRANSPORT_LATENCY_P_TO_C_MAX 0x7FFFFFU
3386+
33783387
#define BT_HCI_EVT_LE_CIS_ESTABLISHED 0x19
33793388
struct bt_hci_evt_le_cis_established {
33803389
uint8_t status;

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

+99-42
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));
@@ -207,68 +267,66 @@ static void init(void)
207267
}
208268
}
209269

210-
static void set_cig_defaults(struct bt_iso_cig_param *param)
270+
static void set_cig_defaults(void)
211271
{
212-
param->cis_channels = &default_chan;
213-
param->num_cis = 1U;
214-
param->sca = BT_GAP_SCA_UNKNOWN;
215-
param->packing = BT_ISO_PACKING_SEQUENTIAL;
216-
param->framing = BT_ISO_FRAMING_UNFRAMED;
217-
param->c_to_p_latency = latency_ms; /* ms */
218-
param->p_to_c_latency = latency_ms; /* ms */
219-
param->c_to_p_interval = interval_us; /* us */
220-
param->p_to_c_interval = interval_us; /* us */
221-
272+
cig_param.cis_channels = &default_chan;
273+
cig_param.num_cis = 1U;
274+
cig_param.sca = BT_GAP_SCA_UNKNOWN;
275+
cig_param.packing = BT_ISO_PACKING_SEQUENTIAL;
276+
cig_param.framing = BT_ISO_FRAMING_UNFRAMED;
277+
cig_param.c_to_p_latency = latency_ms; /* ms */
278+
cig_param.p_to_c_latency = latency_ms; /* ms */
279+
cig_param.c_to_p_interval = interval_us; /* us */
280+
cig_param.p_to_c_interval = interval_us; /* us */
222281
}
223282

224283
static void create_cig(size_t iso_channels)
225284
{
226285
struct bt_iso_chan *channels[ARRAY_SIZE(iso_chans)];
227-
struct bt_iso_cig_param param;
228286
int err;
229287

230288
for (size_t i = 0U; i < iso_channels; i++) {
231289
channels[i] = &iso_chans[i];
232290
}
233291

234-
set_cig_defaults(&param);
235-
param.num_cis = iso_channels;
236-
param.cis_channels = channels;
292+
set_cig_defaults();
293+
cig_param.num_cis = iso_channels;
294+
cig_param.cis_channels = channels;
237295

238-
err = bt_iso_cig_create(&param, &cig);
296+
err = bt_iso_cig_create(&cig_param, &cig);
239297
if (err != 0) {
240298
TEST_FAIL("Failed to create CIG (%d)", err);
241299

242300
return;
243301
}
244302
}
245303

246-
static int reconfigure_cig_interval(struct bt_iso_cig_param *param)
304+
static int reconfigure_cig_interval(void)
247305
{
248306
int err;
249307

250308
/* Test modifying CIG parameter without any CIS */
251-
param->num_cis = 0U;
252-
param->c_to_p_interval = 7500; /* us */
253-
param->p_to_c_interval = param->c_to_p_interval;
254-
err = bt_iso_cig_reconfigure(cig, param);
309+
cig_param.num_cis = 0U;
310+
cig_param.c_to_p_interval = 7500; /* us */
311+
cig_param.p_to_c_interval = cig_param.c_to_p_interval;
312+
err = bt_iso_cig_reconfigure(cig, &cig_param);
255313
if (err != 0) {
256314
TEST_FAIL("Failed to reconfigure CIG to new interval (%d)", err);
257315

258316
return err;
259317
}
260318

261-
err = bt_iso_cig_reconfigure(cig, param);
319+
err = bt_iso_cig_reconfigure(cig, &cig_param);
262320
if (err != 0) {
263321
TEST_FAIL("Failed to reconfigure CIG to same interval (%d)", err);
264322

265323
return err;
266324
}
267325

268326
/* Test modifying to different values for both intervals */
269-
param->c_to_p_interval = 5000; /* us */
270-
param->p_to_c_interval = 2500; /* us */
271-
err = bt_iso_cig_reconfigure(cig, param);
327+
cig_param.c_to_p_interval = 5000; /* us */
328+
cig_param.p_to_c_interval = 2500; /* us */
329+
err = bt_iso_cig_reconfigure(cig, &cig_param);
272330
if (err != 0) {
273331
TEST_FAIL("Failed to reconfigure CIG to new interval (%d)", err);
274332

@@ -278,24 +336,24 @@ static int reconfigure_cig_interval(struct bt_iso_cig_param *param)
278336
return 0;
279337
}
280338

281-
static int reconfigure_cig_latency(struct bt_iso_cig_param *param)
339+
static int reconfigure_cig_latency(void)
282340
{
283341
int err;
284342

285343
/* Test modifying CIG latency without any CIS */
286-
param->num_cis = 0U;
287-
param->c_to_p_latency = 20; /* ms */
288-
param->p_to_c_latency = param->c_to_p_latency;
289-
err = bt_iso_cig_reconfigure(cig, param);
344+
cig_param.num_cis = 0U;
345+
cig_param.c_to_p_latency = 20; /* ms */
346+
cig_param.p_to_c_latency = cig_param.c_to_p_latency;
347+
err = bt_iso_cig_reconfigure(cig, &cig_param);
290348
if (err != 0) {
291349
TEST_FAIL("Failed to reconfigure CIG latency (%d)", err);
292350

293351
return err;
294352
}
295353

296-
param->c_to_p_latency = 30; /* ms */
297-
param->p_to_c_latency = 40; /* ms */
298-
err = bt_iso_cig_reconfigure(cig, param);
354+
cig_param.c_to_p_latency = 30; /* ms */
355+
cig_param.p_to_c_latency = 40; /* ms */
356+
err = bt_iso_cig_reconfigure(cig, &cig_param);
299357
if (err != 0) {
300358
TEST_FAIL("Failed to reconfigure CIG for different latencies (%d)", err);
301359

@@ -308,42 +366,41 @@ static int reconfigure_cig_latency(struct bt_iso_cig_param *param)
308366
static void reconfigure_cig(void)
309367
{
310368
struct bt_iso_chan *channels[2];
311-
struct bt_iso_cig_param param;
312369
int err;
313370

314371
for (size_t i = 0U; i < ARRAY_SIZE(channels); i++) {
315372
channels[i] = &iso_chans[i];
316373
}
317374

318-
set_cig_defaults(&param);
375+
set_cig_defaults();
319376

320377
/* Test modifying existing CIS */
321378
default_chan->qos->tx->rtn++;
322379

323-
err = bt_iso_cig_reconfigure(cig, &param);
380+
err = bt_iso_cig_reconfigure(cig, &cig_param);
324381
if (err != 0) {
325382
TEST_FAIL("Failed to reconfigure CIS to new RTN (%d)", err);
326383

327384
return;
328385
}
329386

330387
/* Test modifying interval parameter */
331-
err = reconfigure_cig_interval(&param);
388+
err = reconfigure_cig_interval();
332389
if (err != 0) {
333390
return;
334391
}
335392

336393
/* Test modifying latency parameter */
337-
err = reconfigure_cig_latency(&param);
394+
err = reconfigure_cig_latency();
338395
if (err != 0) {
339396
return;
340397
}
341398

342399
/* Add CIS to the CIG and restore all other parameters */
343-
set_cig_defaults(&param);
344-
param.cis_channels = &channels[1];
400+
set_cig_defaults();
401+
cig_param.cis_channels = &channels[1];
345402

346-
err = bt_iso_cig_reconfigure(cig, &param);
403+
err = bt_iso_cig_reconfigure(cig, &cig_param);
347404
if (err != 0) {
348405
TEST_FAIL("Failed to reconfigure CIG with new CIS and original parameters (%d)",
349406
err);

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

+53
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,65 @@ static void iso_connected(struct bt_iso_chan *chan)
8888
.pid = BT_ISO_DATA_PATH_HCI,
8989
.format = BT_HCI_CODING_FORMAT_TRANSPARENT,
9090
};
91+
struct bt_iso_info info;
9192
int err;
9293

9394
printk("ISO Channel %p connected\n", chan);
9495

9596
err = bt_iso_setup_data_path(chan, BT_HCI_DATAPATH_DIR_CTLR_TO_HOST, &hci_path);
9697
TEST_ASSERT(err == 0, "Failed to set ISO data path: %d", err);
98+
99+
err = bt_iso_chan_get_info(chan, &info);
100+
TEST_ASSERT(err == 0, "Failed to get CIS info: %d", err);
101+
102+
TEST_ASSERT(info.type == BT_ISO_CHAN_TYPE_PERIPHERAL);
103+
TEST_ASSERT(IN_RANGE(info.iso_interval, BT_ISO_ISO_INTERVAL_MIN, BT_ISO_ISO_INTERVAL_MAX),
104+
"Invalid ISO interval 0x%04x", info.iso_interval);
105+
TEST_ASSERT(IN_RANGE(info.max_subevent, BT_ISO_NSE_MIN, BT_ISO_NSE_MAX),
106+
"Invalid subevent number 0x%02x", info.max_subevent);
107+
TEST_ASSERT(IN_RANGE(info.unicast.cig_sync_delay, BT_HCI_LE_CIG_SYNC_DELAY_MIN,
108+
BT_HCI_LE_CIG_SYNC_DELAY_MAX),
109+
"Invalid CIG sync delay 0x%06x", info.unicast.cig_sync_delay);
110+
TEST_ASSERT(IN_RANGE(info.unicast.cis_sync_delay, BT_HCI_LE_CIS_SYNC_DELAY_MIN,
111+
BT_HCI_LE_CIS_SYNC_DELAY_MAX),
112+
"Invalid CIS sync delay 0x%06x", info.unicast.cis_sync_delay);
113+
114+
if (info.can_send) {
115+
const struct bt_iso_unicast_tx_info *peripheral = &info.unicast.peripheral;
116+
117+
TEST_ASSERT(IN_RANGE(peripheral->latency, BT_HCI_LE_TRANSPORT_LATENCY_P_TO_C_MIN,
118+
BT_HCI_LE_TRANSPORT_LATENCY_P_TO_C_MAX),
119+
"Invalid transport latency 0x%06x", peripheral->latency);
120+
TEST_ASSERT((peripheral->flush_timeout % info.iso_interval) == 0U,
121+
"Flush timeout in ms %u shall be a multiple of the ISO interval %u",
122+
peripheral->flush_timeout, info.iso_interval);
123+
TEST_ASSERT(IN_RANGE(peripheral->max_pdu, BT_ISO_CONNECTED_PDU_MIN, BT_ISO_PDU_MAX),
124+
"Invalid max PDU 0x%04x", peripheral->max_pdu);
125+
TEST_ASSERT(peripheral->phy == BT_GAP_LE_PHY_1M ||
126+
peripheral->phy == BT_GAP_LE_PHY_2M ||
127+
peripheral->phy == BT_GAP_LE_PHY_CODED,
128+
"Invalid PHY 0x%02x", peripheral->phy);
129+
TEST_ASSERT(IN_RANGE(peripheral->bn, BT_ISO_BN_MIN, BT_ISO_BN_MAX),
130+
"Invalid BN 0x%02x", peripheral->bn);
131+
}
132+
133+
if (info.can_recv) {
134+
const struct bt_iso_unicast_tx_info *central = &info.unicast.central;
135+
136+
TEST_ASSERT(IN_RANGE(central->latency, BT_HCI_LE_TRANSPORT_LATENCY_C_TO_P_MIN,
137+
BT_HCI_LE_TRANSPORT_LATENCY_C_TO_P_MAX),
138+
"Invalid transport latency 0x%06x", central->latency);
139+
TEST_ASSERT((central->flush_timeout % info.iso_interval) == 0U,
140+
"Flush timeout in ms %u shall be a multiple of the ISO interval %u",
141+
central->flush_timeout, info.iso_interval);
142+
TEST_ASSERT(IN_RANGE(central->max_pdu, BT_ISO_CONNECTED_PDU_MIN, BT_ISO_PDU_MAX),
143+
"Invalid max PDU 0x%04x", central->max_pdu);
144+
TEST_ASSERT(central->phy == BT_GAP_LE_PHY_1M || central->phy == BT_GAP_LE_PHY_2M ||
145+
central->phy == BT_GAP_LE_PHY_CODED,
146+
"Invalid PHY 0x%02x", central->phy);
147+
TEST_ASSERT(IN_RANGE(central->bn, BT_ISO_BN_MIN, BT_ISO_BN_MAX),
148+
"Invalid BN 0x%02x", central->bn);
149+
}
97150
}
98151

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

0 commit comments

Comments
 (0)