9
9
#include "common.h"
10
10
11
11
#include <zephyr/bluetooth/bluetooth.h>
12
+ #include <zephyr/bluetooth/gap.h>
13
+ #include <zephyr/bluetooth/hci_types.h>
12
14
#include <zephyr/bluetooth/iso.h>
13
15
#include <zephyr/sys/printk.h>
16
+ #include <zephyr/sys/util.h>
17
+
18
+ #include <babblekit/testcase.h>
14
19
15
20
#define ENQUEUE_COUNT 2
16
21
17
22
extern enum bst_result_t bst_result ;
18
23
static struct bt_iso_chan iso_chans [CONFIG_BT_ISO_MAX_CHAN ];
19
24
static struct bt_iso_chan * default_chan = & iso_chans [0 ];
25
+ static struct bt_iso_cig_param cig_param ;
20
26
static struct bt_iso_cig * cig ;
21
27
static uint16_t seq_num ;
22
28
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,
104
110
105
111
static void iso_connected (struct bt_iso_chan * chan )
106
112
{
113
+ struct bt_iso_info info ;
114
+ int err ;
115
+
107
116
printk ("ISO Channel %p connected\n" , chan );
108
117
109
118
seq_num = 0U ;
110
119
enqueue_cnt = ENQUEUE_COUNT ;
111
120
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
+
112
179
if (chan == default_chan ) {
113
180
/* Start send timer */
114
181
k_work_schedule (& iso_send_work , K_MSEC (0 ));
@@ -180,68 +247,66 @@ static void init(void)
180
247
}
181
248
}
182
249
183
- static void set_cig_defaults (struct bt_iso_cig_param * param )
250
+ static void set_cig_defaults (void )
184
251
{
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 */
195
261
}
196
262
197
263
static void create_cig (size_t iso_channels )
198
264
{
199
265
struct bt_iso_chan * channels [ARRAY_SIZE (iso_chans )];
200
- struct bt_iso_cig_param param ;
201
266
int err ;
202
267
203
268
for (size_t i = 0U ; i < iso_channels ; i ++ ) {
204
269
channels [i ] = & iso_chans [i ];
205
270
}
206
271
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 ;
210
275
211
- err = bt_iso_cig_create (& param , & cig );
276
+ err = bt_iso_cig_create (& cig_param , & cig );
212
277
if (err != 0 ) {
213
278
TEST_FAIL ("Failed to create CIG (%d)" , err );
214
279
215
280
return ;
216
281
}
217
282
}
218
283
219
- static int reconfigure_cig_interval (struct bt_iso_cig_param * param )
284
+ static int reconfigure_cig_interval (void )
220
285
{
221
286
int err ;
222
287
223
288
/* 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 );
228
293
if (err != 0 ) {
229
294
TEST_FAIL ("Failed to reconfigure CIG to new interval (%d)" , err );
230
295
231
296
return err ;
232
297
}
233
298
234
- err = bt_iso_cig_reconfigure (cig , param );
299
+ err = bt_iso_cig_reconfigure (cig , & cig_param );
235
300
if (err != 0 ) {
236
301
TEST_FAIL ("Failed to reconfigure CIG to same interval (%d)" , err );
237
302
238
303
return err ;
239
304
}
240
305
241
306
/* 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 );
245
310
if (err != 0 ) {
246
311
TEST_FAIL ("Failed to reconfigure CIG to new interval (%d)" , err );
247
312
@@ -251,24 +316,24 @@ static int reconfigure_cig_interval(struct bt_iso_cig_param *param)
251
316
return 0 ;
252
317
}
253
318
254
- static int reconfigure_cig_latency (struct bt_iso_cig_param * param )
319
+ static int reconfigure_cig_latency (void )
255
320
{
256
321
int err ;
257
322
258
323
/* 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 );
263
328
if (err != 0 ) {
264
329
TEST_FAIL ("Failed to reconfigure CIG latency (%d)" , err );
265
330
266
331
return err ;
267
332
}
268
333
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 );
272
337
if (err != 0 ) {
273
338
TEST_FAIL ("Failed to reconfigure CIG for different latencies (%d)" , err );
274
339
@@ -281,42 +346,41 @@ static int reconfigure_cig_latency(struct bt_iso_cig_param *param)
281
346
static void reconfigure_cig (void )
282
347
{
283
348
struct bt_iso_chan * channels [2 ];
284
- struct bt_iso_cig_param param ;
285
349
int err ;
286
350
287
351
for (size_t i = 0U ; i < ARRAY_SIZE (channels ); i ++ ) {
288
352
channels [i ] = & iso_chans [i ];
289
353
}
290
354
291
- set_cig_defaults (& param );
355
+ set_cig_defaults ();
292
356
293
357
/* Test modifying existing CIS */
294
358
default_chan -> qos -> tx -> rtn ++ ;
295
359
296
- err = bt_iso_cig_reconfigure (cig , & param );
360
+ err = bt_iso_cig_reconfigure (cig , & cig_param );
297
361
if (err != 0 ) {
298
362
TEST_FAIL ("Failed to reconfigure CIS to new RTN (%d)" , err );
299
363
300
364
return ;
301
365
}
302
366
303
367
/* Test modifying interval parameter */
304
- err = reconfigure_cig_interval (& param );
368
+ err = reconfigure_cig_interval ();
305
369
if (err != 0 ) {
306
370
return ;
307
371
}
308
372
309
373
/* Test modifying latency parameter */
310
- err = reconfigure_cig_latency (& param );
374
+ err = reconfigure_cig_latency ();
311
375
if (err != 0 ) {
312
376
return ;
313
377
}
314
378
315
379
/* 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 ];
318
382
319
- err = bt_iso_cig_reconfigure (cig , & param );
383
+ err = bt_iso_cig_reconfigure (cig , & cig_param );
320
384
if (err != 0 ) {
321
385
TEST_FAIL ("Failed to reconfigure CIG with new CIS and original parameters (%d)" ,
322
386
err );
0 commit comments