1 // SPDX-License-Identifier: LGPL-2.1-or-later
4 * BlueZ - Bluetooth protocol stack for Linux
6 * Copyright (C) 2022 Intel Corporation.
23 #include "lib/bluetooth.h"
27 #include "monitor/bt.h"
28 #include "emulator/vhci.h"
29 #include "emulator/bthost.h"
30 #include "emulator/hciemu.h"
32 #include "src/shared/tester.h"
33 #include "src/shared/mgmt.h"
34 #include "src/shared/util.h"
36 #define QOS_IO(_interval, _latency, _sdu, _phy, _rtn) \
38 .interval = _interval, \
39 .latency = _latency, \
45 #define QOS_FULL(_cig, _cis, _in, _out) \
58 #define QOS(_interval, _latency, _sdu, _phy, _rtn) \
59 QOS_FULL(BT_ISO_QOS_CIG_UNSET, BT_ISO_QOS_CIS_UNSET, \
60 QOS_IO(_interval, _latency, _sdu, _phy, _rtn), \
61 QOS_IO(_interval, _latency, _sdu, _phy, _rtn))
63 #define QOS_1(_interval, _latency, _sdu, _phy, _rtn) \
64 QOS_FULL(0x01, BT_ISO_QOS_CIS_UNSET, \
65 QOS_IO(_interval, _latency, _sdu, _phy, _rtn), \
66 QOS_IO(_interval, _latency, _sdu, _phy, _rtn))
68 #define QOS_2(_interval, _latency, _sdu, _phy, _rtn) \
69 QOS_FULL(0x02, BT_ISO_QOS_CIS_UNSET, \
70 QOS_IO(_interval, _latency, _sdu, _phy, _rtn), \
71 QOS_IO(_interval, _latency, _sdu, _phy, _rtn))
73 #define QOS_1_1(_interval, _latency, _sdu, _phy, _rtn) \
74 QOS_FULL(0x01, 0x01, \
75 QOS_IO(_interval, _latency, _sdu, _phy, _rtn), \
76 QOS_IO(_interval, _latency, _sdu, _phy, _rtn))
78 #define QOS_1_2(_interval, _latency, _sdu, _phy, _rtn) \
79 QOS_FULL(0x01, 0x02, \
80 QOS_IO(_interval, _latency, _sdu, _phy, _rtn), \
81 QOS_IO(_interval, _latency, _sdu, _phy, _rtn))
83 #define QOS_OUT(_interval, _latency, _sdu, _phy, _rtn) \
84 QOS_FULL(BT_ISO_QOS_CIG_UNSET, BT_ISO_QOS_CIS_UNSET, \
85 {}, QOS_IO(_interval, _latency, _sdu, _phy, _rtn))
87 #define QOS_OUT_1(_interval, _latency, _sdu, _phy, _rtn) \
88 QOS_FULL(0x01, BT_ISO_QOS_CIS_UNSET, \
89 {}, QOS_IO(_interval, _latency, _sdu, _phy, _rtn))
91 #define QOS_OUT_1_1(_interval, _latency, _sdu, _phy, _rtn) \
92 QOS_FULL(0x01, 0x01, \
93 {}, QOS_IO(_interval, _latency, _sdu, _phy, _rtn))
95 #define QOS_OUT_1_2(_interval, _latency, _sdu, _phy, _rtn) \
96 QOS_FULL(0x01, 0x02, \
97 {}, QOS_IO(_interval, _latency, _sdu, _phy, _rtn))
99 #define QOS_OUT_1_EF(_interval, _latency, _sdu, _phy, _rtn) \
100 QOS_FULL(0x01, 0xEF, \
101 {}, QOS_IO(_interval, _latency, _sdu, _phy, _rtn))
103 #define QOS_IN(_interval, _latency, _sdu, _phy, _rtn) \
104 QOS_FULL(BT_ISO_QOS_CIG_UNSET, BT_ISO_QOS_CIS_UNSET, \
105 QOS_IO(_interval, _latency, _sdu, _phy, _rtn), {})
106 #define QOS_IN_1(_interval, _latency, _sdu, _phy, _rtn) \
107 QOS_FULL(0x01, BT_ISO_QOS_CIS_UNSET, \
108 QOS_IO(_interval, _latency, _sdu, _phy, _rtn), {})
109 #define QOS_IN_2(_interval, _latency, _sdu, _phy, _rtn) \
110 QOS_FULL(0x02, BT_ISO_QOS_CIS_UNSET, \
111 QOS_IO(_interval, _latency, _sdu, _phy, _rtn), {})
112 #define QOS_IN_1_1(_interval, _latency, _sdu, _phy, _rtn) \
113 QOS_FULL(0x01, 0x01, \
114 QOS_IO(_interval, _latency, _sdu, _phy, _rtn), {})
115 #define QOS_IN_1_2(_interval, _latency, _sdu, _phy, _rtn) \
116 QOS_FULL(0x01, 0x02, \
117 QOS_IO(_interval, _latency, _sdu, _phy, _rtn), {})
119 /* QoS Configuration settings for low latency audio data */
120 #define QOS_8_1_1 QOS(7500, 8, 26, 0x02, 2)
121 #define QOS_8_2_1 QOS(10000, 10, 30, 0x02, 2)
122 #define QOS_16_1_1 QOS(7500, 8, 30, 0x02, 2)
123 #define QOS_16_2_1 QOS(10000, 10, 40, 0x02, 2)
124 #define QOS_1_16_2_1 QOS_1(10000, 10, 40, 0x02, 2)
125 #define QOS_2_16_2_1 QOS_2(10000, 10, 40, 0x02, 2)
126 #define QOS_1_1_16_2_1 QOS_1_1(10000, 10, 40, 0x02, 2)
127 #define QOS_24_1_1 QOS(7500, 8, 45, 0x02, 2)
128 #define QOS_24_2_1 QOS(10000, 10, 60, 0x02, 2)
129 #define QOS_32_1_1 QOS(7500, 8, 60, 0x02, 2)
130 #define QOS_32_2_1 QOS(10000, 10, 80, 0x02, 2)
131 #define QOS_44_1_1 QOS_OUT(8163, 24, 98, 0x02, 5)
132 #define QOS_44_2_1 QOS_OUT(10884, 31, 130, 0x02, 5)
133 #define QOS_48_1_1 QOS_OUT(7500, 15, 75, 0x02, 5)
134 #define QOS_48_2_1 QOS_OUT(10000, 20, 100, 0x02, 5)
135 #define QOS_48_3_1 QOS_OUT(7500, 15, 90, 0x02, 5)
136 #define QOS_48_4_1 QOS_OUT(10000, 20, 120, 0x02, 5)
137 #define QOS_48_5_1 QOS_OUT(7500, 15, 117, 0x02, 5)
138 #define QOS_48_6_1 QOS_OUT(10000, 20, 155, 0x02, 5)
139 /* QoS Configuration settings for high reliability audio data */
140 #define QOS_8_1_2 QOS(7500, 75, 26, 0x02, 13)
141 #define QOS_8_2_2 QOS(10000, 95, 30, 0x02, 13)
142 #define QOS_16_1_2 QOS(7500, 75, 30, 0x02, 13)
143 #define QOS_16_2_2 QOS(10000, 95, 40, 0x02, 13)
144 #define QOS_24_1_2 QOS(7500, 75, 45, 0x02, 13)
145 #define QOS_24_2_2 QOS(10000, 95, 60, 0x02, 13)
146 #define QOS_32_1_2 QOS(7500, 65, 60, 0x02, 13)
147 #define QOS_32_2_2 QOS(10000, 95, 80, 0x02, 13)
148 #define QOS_44_1_2 QOS_OUT(8163, 80, 98, 0x02, 13)
149 #define QOS_44_2_2 QOS_OUT(10884, 85, 130, 0x02, 13)
150 #define QOS_48_1_2 QOS_OUT(7500, 75, 75, 0x02, 13)
151 #define QOS_48_2_2 QOS_OUT(10000, 95, 100, 0x02, 13)
152 #define QOS_48_3_2 QOS_OUT(7500, 75, 90, 0x02, 13)
153 #define QOS_48_4_2 QOS_OUT(10000, 100, 120, 0x02, 13)
154 #define QOS_48_5_2 QOS_OUT(7500, 75, 117, 0x02, 13)
155 #define QOS_48_6_2 QOS_OUT(10000, 100, 155, 0x02, 13)
157 /* One unidirectional CIS. Unicast Server is Audio Sink */
158 #define AC_1_4 QOS_OUT(10000, 10, 40, 0x02, 2)
159 /* One unidirectional CIS. Unicast Server is Audio Sink CIG 0x01 */
160 #define AC_1_4_1 QOS_OUT_1(10000, 10, 40, 0x02, 2)
161 /* One unidirectional CIS. Unicast Server is Audio Source. */
162 #define AC_2_10 QOS_IN(10000, 10, 40, 0x02, 2)
163 /* One unidirectional CIS. Unicast Server is Audio Source CIG 0x02 */
164 #define AC_2_10_2 QOS_IN_2(10000, 10, 40, 0x02, 2)
165 /* One bidirectional CIS. Unicast Server is Audio Sink and Audio Source. */
166 #define AC_3_5 QOS(10000, 10, 40, 0x02, 2)
167 /* Two unidirectional CISes. Unicast Server is Audio Sink.
168 * #1 - CIG 1 CIS 1 (output)
169 * #2 - CIG 1 CIS 2 (output)
171 #define AC_6i_1 QOS_OUT_1_1(10000, 10, 40, 0x02, 2)
172 #define AC_6i_2 QOS_OUT_1_2(10000, 10, 40, 0x02, 2)
173 /* Two Unicast Servers. Unicast Server 1 is Audio Sink. Unicast Server 2 is
175 * #1 - CIG 1 CIS auto (output)
176 * #2 - CIG 1 CIS auto (output)
178 #define AC_6ii_1 QOS_OUT_1(10000, 10, 40, 0x02, 2)
179 #define AC_6ii_2 QOS_OUT_1(10000, 10, 40, 0x02, 2)
180 #define AC_6ii_1_EF QOS_OUT_1_EF(10000, 10, 40, 0x02, 2) /* different CIS ID */
181 /* Two unidirectional CISes. Unicast Server is Audio Sink and Audio Source.
182 * #1 - CIG 1 CIS 1 (input)
183 * #2 - CIG 1 CIS 2 (output)
185 #define AC_7i_1 QOS_OUT_1_1(10000, 10, 40, 0x02, 2)
186 #define AC_7i_2 QOS_IN_1_2(10000, 10, 40, 0x02, 2)
187 /* Two Unidirectional CISes. Two Unicast Servers. Unicast Server 1 is Audio
188 * Sink. Unicast Server 2 is Audio Source.
189 * #1 - CIG 1 CIS auto (output)
190 * #2 - CIG 1 CIS auto (output)
192 #define AC_7ii_1 QOS_OUT_1(10000, 10, 40, 0x02, 2)
193 #define AC_7ii_2 QOS_IN_1(10000, 10, 40, 0x02, 2)
194 /* One bidirectional CIS and one unidirectional CIS. Unicast Server is Audio
195 * Sink and Audio Source.
196 * #1 - CIG 1 CIS 1 (output)
197 * #2 - CIG 1 CIS 2 (input/output)
199 #define AC_8i_1 QOS_OUT_1_1(10000, 10, 40, 0x02, 2)
200 #define AC_8i_2 QOS_1_2(10000, 10, 40, 0x02, 2)
201 /* One bidirectional CIS and one unidirectional CIS. Two Unicast Servers.
202 * Unicast Server 1 is Audio Sink and Audio Source. Unicast Server 2 is
204 * #1 - CIG 1 CIS auto (input/output)
205 * #2 - CIG 1 CIS auto (output)
207 #define AC_8ii_1 QOS_1(10000, 10, 40, 0x02, 2)
208 #define AC_8ii_2 QOS_OUT_1(10000, 10, 40, 0x02, 2)
209 /* Two unidirectional CISes. Unicast Server is Audio Source.
210 * #1 - CIG 1 CIS 1 (input)
211 * #2 - CIG 1 CIS 2 (input)
213 #define AC_9i_1 QOS_IN_1_1(10000, 10, 40, 0x02, 2)
214 #define AC_9i_2 QOS_IN_1_2(10000, 10, 40, 0x02, 2)
215 /* Two unidirectional CISes. Two Unicast Servers. Unicast Server 1 is Audio
216 * Source. Unicast Server 2 is Audio Source.
217 * #1 - CIG 1 CIS auto (input)
218 * #2 - CIG 1 CIS auto (input)
220 #define AC_9ii_1 QOS_IN_1(10000, 10, 40, 0x02, 2)
221 #define AC_9ii_2 QOS_IN_1(10000, 10, 40, 0x02, 2)
222 /* Two bidirectional CISes. Unicast Server is Audio Sink and Audio Source.
223 * #1 - CIG 1 CIS 1 (input/output)
224 * #2 - CIG 1 CIS 2 (input/output)
226 #define AC_11i_1 QOS_1_1(10000, 10, 40, 0x02, 2)
227 #define AC_11i_2 QOS_1_2(10000, 10, 40, 0x02, 2)
228 /* Two bidirectional CISes. Two Unicast Servers. Unicast Server 1 is Audio Sink
229 * and Audio Source. Unicast Server 2 is Audio Sink and Audio Source.
230 * #1 - CIG 1 CIS auto (input/output)
231 * #2 - CIG 1 CIS auto (input/output)
233 #define AC_11ii_1 QOS_1(10000, 10, 40, 0x02, 2)
234 #define AC_11ii_2 QOS_1(10000, 10, 40, 0x02, 2)
236 #define BCODE {0x01, 0x02, 0x68, 0x05, 0x53, 0xf1, 0x41, 0x5a, \
237 0xa2, 0x65, 0xbb, 0xaf, 0xc6, 0xea, 0x03, 0xb8}
239 #define QOS_BCAST_FULL(_big, _bis, _encryption, _bcode, _in, _out) \
244 .sync_interval = 0x07, \
249 .encryption = _encryption, \
253 .sync_timeout = 0x4000, \
254 .sync_cte_type = 0x00, \
260 #define BCAST_QOS_OUT(_interval, _latency, _sdu, _phy, _rtn) \
261 QOS_BCAST_FULL(BT_ISO_QOS_BIG_UNSET, BT_ISO_QOS_BIS_UNSET, \
263 QOS_IO(_interval, _latency, _sdu, _phy, _rtn))
265 #define BCAST_QOS_OUT_ENC(_interval, _latency, _sdu, _phy, _rtn) \
266 QOS_BCAST_FULL(BT_ISO_QOS_BIG_UNSET, BT_ISO_QOS_BIS_UNSET, \
268 QOS_IO(_interval, _latency, _sdu, _phy, _rtn))
270 #define BCAST_QOS_OUT_1(_interval, _latency, _sdu, _phy, _rtn) \
271 QOS_BCAST_FULL(0x01, BT_ISO_QOS_BIS_UNSET, \
273 QOS_IO(_interval, _latency, _sdu, _phy, _rtn))
275 #define BCAST_QOS_OUT_1_1(_interval, _latency, _sdu, _phy, _rtn) \
276 QOS_BCAST_FULL(0x01, 0x01, \
278 QOS_IO(_interval, _latency, _sdu, _phy, _rtn))
280 #define BCAST_QOS_IN(_interval, _latency, _sdu, _phy, _rtn) \
281 QOS_BCAST_FULL(BT_ISO_QOS_BIG_UNSET, BT_ISO_QOS_BIS_UNSET, \
283 QOS_IO(_interval, _latency, _sdu, _phy, _rtn), {})
285 #define BCAST_QOS_IN_ENC(_interval, _latency, _sdu, _phy, _rtn) \
286 QOS_BCAST_FULL(BT_ISO_QOS_BIG_UNSET, BT_ISO_QOS_BIS_UNSET, \
288 QOS_IO(_interval, _latency, _sdu, _phy, _rtn), {})
290 #define QOS_OUT_16_2_1 BCAST_QOS_OUT(10000, 10, 40, 0x02, 2)
291 #define QOS_OUT_ENC_16_2_1 BCAST_QOS_OUT_ENC(10000, 10, 40, 0x02, 2)
292 #define QOS_OUT_1_16_2_1 BCAST_QOS_OUT_1(10000, 10, 40, 0x02, 2)
293 #define QOS_OUT_1_1_16_2_1 BCAST_QOS_OUT_1_1(10000, 10, 40, 0x02, 2)
294 #define QOS_IN_16_2_1 BCAST_QOS_IN(10000, 10, 40, 0x02, 2)
295 #define QOS_IN_ENC_16_2_1 BCAST_QOS_IN_ENC(10000, 10, 40, 0x02, 2)
297 static const uint8_t base_lc3_16_2_1[] = {
298 0x28, 0x00, 0x00, /* Presentation Delay */
299 0x01, /* Number of Subgroups */
300 0x01, /* Number of BIS */
301 0x06, 0x00, 0x00, 0x00, 0x00, /* Code ID = LC3 (0x06) */
302 0x11, /* Codec Specific Configuration */
303 0x02, 0x01, 0x03, /* 16 KHZ */
304 0x02, 0x02, 0x01, /* 10 ms */
305 0x05, 0x03, 0x01, 0x00, 0x00, 0x00, /* Front Left */
306 0x03, 0x04, 0x28, 0x00, /* Frame Length 40 bytes */
308 0x03, 0x02, 0x02, 0x00, /* Audio Context: Convertional */
310 0x00, /* Codec Specific Configuration */
313 /* Single Audio Channel. One BIS. */
314 #define BCAST_AC_12 BCAST_QOS_OUT_1_1(10000, 10, 40, 0x02, 2)
316 static const uint8_t base_lc3_ac_12[] = {
317 0x28, 0x00, 0x00, /* Presentation Delay */
318 0x01, /* Number of Subgroups */
319 0x01, /* Number of BIS */
320 0x06, 0x00, 0x00, 0x00, 0x00, /* Code ID = LC3 (0x06) */
321 0x11, /* Codec Specific Configuration */
322 0x02, 0x01, 0x03, /* 16 KHZ */
323 0x02, 0x02, 0x01, /* 10 ms */
324 0x05, 0x03, 0x01, 0x00, 0x00, 0x00, /* Front Left */
325 0x03, 0x04, 0x28, 0x00, /* Frame Length 40 bytes */
327 0x03, 0x02, 0x02, 0x00, /* Audio Context: Convertional */
329 0x00, /* Codec Specific Configuration */
332 /* Multiple Audio Channels. Two BISes. */
333 #define BCAST_AC_13 BCAST_QOS_OUT_1_1(10000, 10, 40, 0x02, 2)
335 static const uint8_t base_lc3_ac_13[] = {
336 0x28, 0x00, 0x00, /* Presentation Delay */
337 0x01, /* Number of Subgroups */
338 0x02, /* Number of BIS */
339 0x06, 0x00, 0x00, 0x00, 0x00, /* Code ID = LC3 (0x06) */
340 0x11, /* Codec Specific Configuration */
341 0x02, 0x01, 0x03, /* 16 KHZ */
342 0x02, 0x02, 0x01, /* 10 ms */
343 0x05, 0x03, 0x01, 0x00, 0x00, 0x00, /* Front Left */
344 0x03, 0x04, 0x28, 0x00, /* Frame Length 40 bytes */
346 0x03, 0x02, 0x02, 0x00, /* Audio Context: Convertional */
348 0x06, /* Codec Specific Configuration */
349 0x05, 0x03, 0x01, 0x00, 0x00, 0x00, /* Audio_Channel_Allocation:
353 0x06, /* Codec Specific Configuration */
354 0x05, 0x03, 0x02, 0x00, 0x00, 0x00, /* Audio_Channel_Allocation:
359 /* Multiple Audio Channels. One BIS. */
360 #define BCAST_AC_14 BCAST_QOS_OUT_1_1(10000, 10, 40, 0x02, 2)
362 static const uint8_t base_lc3_ac_14[] = {
363 0x28, 0x00, 0x00, /* Presentation Delay */
364 0x01, /* Number of Subgroups */
365 0x01, /* Number of BIS */
366 0x06, 0x00, 0x00, 0x00, 0x00, /* Code ID = LC3 (0x06) */
367 0x11, /* Codec Specific Configuration */
368 0x02, 0x01, 0x03, /* 16 KHZ */
369 0x02, 0x02, 0x01, /* 10 ms */
370 0x05, 0x03, 0x01, 0x00, 0x00, 0x00, /* Front Left */
371 0x03, 0x04, 0x28, 0x00, /* Frame Length 40 bytes */
373 0x03, 0x02, 0x02, 0x00, /* Audio Context: Convertional */
375 0x06, /* Codec Specific Configuration */
376 0x05, 0x03, 0x03, 0x00, 0x00, 0x00, /* Audio_Channel_Allocation:
377 * Front left, Front right
382 const void *test_data;
385 struct hciemu *hciemu;
386 enum hciemu_type hciemu_type;
387 uint8_t accept_reason;
391 unsigned int io_id[2];
398 struct iso_client_data {
399 struct bt_iso_qos qos;
400 struct bt_iso_qos qos_2;
402 const struct iovec *send;
403 const struct iovec *recv;
416 static void mgmt_debug(const char *str, void *user_data)
418 const char *prefix = user_data;
420 tester_print("%s%s", prefix, str);
423 static void read_info_callback(uint8_t status, uint16_t length,
424 const void *param, void *user_data)
426 struct test_data *data = tester_get_data();
427 const struct mgmt_rp_read_info *rp = param;
429 uint16_t manufacturer;
430 uint32_t supported_settings, current_settings;
432 tester_print("Read Info callback");
433 tester_print(" Status: 0x%02x", status);
435 if (status || !param) {
436 tester_pre_setup_failed();
440 ba2str(&rp->bdaddr, addr);
441 manufacturer = btohs(rp->manufacturer);
442 supported_settings = btohl(rp->supported_settings);
443 current_settings = btohl(rp->current_settings);
445 tester_print(" Address: %s", addr);
446 tester_print(" Version: 0x%02x", rp->version);
447 tester_print(" Manufacturer: 0x%04x", manufacturer);
448 tester_print(" Supported settings: 0x%08x", supported_settings);
449 tester_print(" Current settings: 0x%08x", current_settings);
450 tester_print(" Class: 0x%02x%02x%02x",
451 rp->dev_class[2], rp->dev_class[1], rp->dev_class[0]);
452 tester_print(" Name: %s", rp->name);
453 tester_print(" Short name: %s", rp->short_name);
455 if (strcmp(hciemu_get_address(data->hciemu), addr)) {
456 tester_pre_setup_failed();
460 tester_pre_setup_complete();
463 static void index_added_callback(uint16_t index, uint16_t length,
464 const void *param, void *user_data)
466 struct test_data *data = tester_get_data();
468 tester_print("Index Added callback");
469 tester_print(" Index: 0x%04x", index);
471 data->mgmt_index = index;
473 mgmt_send(data->mgmt, MGMT_OP_READ_INFO, data->mgmt_index, 0, NULL,
474 read_info_callback, NULL, NULL);
477 static void index_removed_callback(uint16_t index, uint16_t length,
478 const void *param, void *user_data)
480 struct test_data *data = tester_get_data();
482 tester_print("Index Removed callback");
483 tester_print(" Index: 0x%04x", index);
485 if (index != data->mgmt_index)
488 mgmt_unregister_index(data->mgmt, data->mgmt_index);
490 mgmt_unref(data->mgmt);
493 tester_post_teardown_complete();
496 static void hciemu_debug(const char *str, void *user_data)
498 const char *prefix = user_data;
500 tester_print("%s%s", prefix, str);
503 static void read_index_list_callback(uint8_t status, uint16_t length,
504 const void *param, void *user_data)
506 struct test_data *data = tester_get_data();
508 tester_print("Read Index List callback");
509 tester_print(" Status: 0x%02x", status);
511 if (status || !param) {
512 tester_pre_setup_failed();
516 mgmt_register(data->mgmt, MGMT_EV_INDEX_ADDED, MGMT_INDEX_NONE,
517 index_added_callback, NULL, NULL);
519 mgmt_register(data->mgmt, MGMT_EV_INDEX_REMOVED, MGMT_INDEX_NONE,
520 index_removed_callback, NULL, NULL);
522 data->hciemu = hciemu_new_num(HCIEMU_TYPE_BREDRLE52, data->client_num);
524 tester_warn("Failed to setup HCI emulation");
525 tester_pre_setup_failed();
529 if (tester_use_debug())
530 hciemu_set_debug(data->hciemu, hciemu_debug, "hciemu: ", NULL);
532 tester_print("New hciemu instance created");
535 static const uint8_t set_iso_socket_param[] = {
536 0x3e, 0xe0, 0xb4, 0xfd, 0xdd, 0xd6, 0x85, 0x98, /* UUID - ISO Socket */
537 0x6a, 0x49, 0xe0, 0x05, 0x88, 0xf1, 0xba, 0x6f,
538 0x01, /* Action - enable */
541 static const uint8_t reset_iso_socket_param[] = {
542 0x3e, 0xe0, 0xb4, 0xfd, 0xdd, 0xd6, 0x85, 0x98, /* UUID - ISO Socket */
543 0x6a, 0x49, 0xe0, 0x05, 0x88, 0xf1, 0xba, 0x6f,
544 0x00, /* Action - disable */
547 static void set_iso_socket_callback(uint8_t status, uint16_t length,
548 const void *param, void *user_data)
550 if (status != MGMT_STATUS_SUCCESS) {
551 tester_print("ISO socket feature could not be enabled");
555 tester_print("ISO socket feature is enabled");
558 static void test_pre_setup(const void *test_data)
560 struct test_data *data = tester_get_data();
562 data->mgmt = mgmt_new_default();
564 tester_warn("Failed to setup management interface");
565 tester_pre_setup_failed();
569 if (tester_use_debug())
570 mgmt_set_debug(data->mgmt, mgmt_debug, "mgmt: ", NULL);
572 mgmt_send(data->mgmt, MGMT_OP_SET_EXP_FEATURE, MGMT_INDEX_NONE,
573 sizeof(set_iso_socket_param), set_iso_socket_param,
574 set_iso_socket_callback, NULL, NULL);
576 mgmt_send(data->mgmt, MGMT_OP_READ_INDEX_LIST, MGMT_INDEX_NONE, 0, NULL,
577 read_index_list_callback, NULL, NULL);
580 static void test_post_teardown(const void *test_data)
582 struct test_data *data = tester_get_data();
584 mgmt_send(data->mgmt, MGMT_OP_SET_EXP_FEATURE, MGMT_INDEX_NONE,
585 sizeof(reset_iso_socket_param), reset_iso_socket_param,
588 hciemu_unref(data->hciemu);
592 static void test_data_free(void *test_data)
594 struct test_data *data = test_data;
597 g_io_channel_unref(data->io);
599 if (data->io_id[0] > 0)
600 g_source_remove(data->io_id[0]);
602 if (data->io_id[1] > 0)
603 g_source_remove(data->io_id[1]);
608 #define test_iso_full(name, data, setup, func, num, reason) \
610 struct test_data *user; \
611 user = new0(struct test_data, 1); \
614 user->hciemu_type = HCIEMU_TYPE_BREDRLE; \
615 user->test_data = data; \
616 user->client_num = num; \
617 user->accept_reason = reason; \
618 tester_add_full(name, data, \
619 test_pre_setup, setup, func, NULL, \
620 test_post_teardown, 2, user, test_data_free); \
623 #define test_iso(name, data, setup, func) \
624 test_iso_full(name, data, setup, func, 1, 0x00)
626 #define test_iso2(name, data, setup, func) \
627 test_iso_full(name, data, setup, func, 2, 0x00)
629 #define test_iso_rej(name, data, setup, func, reason) \
630 test_iso_full(name, data, setup, func, 1, reason)
632 static const struct iso_client_data connect_8_1_1 = {
637 static const struct iso_client_data connect_8_2_1 = {
642 static const struct iso_client_data connect_16_1_1 = {
647 static const struct iso_client_data connect_16_2_1 = {
652 static const struct iso_client_data connect_1_16_2_1 = {
657 static const struct iso_client_data connect_1_1_16_2_1 = {
658 .qos = QOS_1_1_16_2_1,
662 static const struct iso_client_data connect_24_1_1 = {
667 static const struct iso_client_data connect_24_2_1 = {
672 static const struct iso_client_data connect_32_1_1 = {
677 static const struct iso_client_data connect_32_2_1 = {
682 static const struct iso_client_data connect_44_1_1 = {
687 static const struct iso_client_data connect_44_2_1 = {
692 static const struct iso_client_data connect_48_1_1 = {
697 static const struct iso_client_data connect_48_2_1 = {
702 static const struct iso_client_data connect_48_3_1 = {
707 static const struct iso_client_data connect_48_4_1 = {
712 static const struct iso_client_data connect_48_5_1 = {
717 static const struct iso_client_data connect_48_6_1 = {
722 static const struct iso_client_data connect_8_1_2 = {
727 static const struct iso_client_data connect_8_2_2 = {
732 static const struct iso_client_data connect_16_1_2 = {
737 static const struct iso_client_data connect_16_2_2 = {
742 static const struct iso_client_data connect_24_1_2 = {
747 static const struct iso_client_data connect_24_2_2 = {
752 static const struct iso_client_data connect_32_1_2 = {
757 static const struct iso_client_data connect_32_2_2 = {
762 static const struct iso_client_data connect_44_1_2 = {
767 static const struct iso_client_data connect_44_2_2 = {
772 static const struct iso_client_data connect_48_1_2 = {
777 static const struct iso_client_data connect_48_2_2 = {
782 static const struct iso_client_data connect_48_3_2 = {
787 static const struct iso_client_data connect_48_4_2 = {
792 static const struct iso_client_data connect_48_5_2 = {
797 static const struct iso_client_data connect_48_6_2 = {
802 static const struct iso_client_data connect_invalid = {
803 .qos = QOS(0, 0, 0, 0, 0),
804 .expect_err = -EINVAL
807 static const struct iso_client_data connect_reject = {
809 .expect_err = -ENOSYS
812 static const struct iso_client_data connect_suspend = {
814 .expect_err = -ECONNRESET
817 static const struct iso_client_data connect_cig_f0_invalid = {
818 .qos = QOS_FULL(0xF0, 0x00, {}, QOS_IO(10000, 10, 40, 0x02, 2)),
819 .expect_err = -EINVAL
822 static const struct iso_client_data connect_cis_f0_invalid = {
823 .qos = QOS_FULL(0x00, 0xF0, {}, QOS_IO(10000, 10, 40, 0x02, 2)),
824 .expect_err = -EINVAL
827 static const uint8_t data_16_2_1[40] = { [0 ... 39] = 0xff };
828 static const struct iovec send_16_2_1 = {
829 .iov_base = (void *)data_16_2_1,
830 .iov_len = sizeof(data_16_2_1),
833 static const uint8_t data_48_2_1[100] = { [0 ... 99] = 0xff };
834 static const struct iovec send_48_2_1 = {
835 .iov_base = (void *)data_48_2_1,
836 .iov_len = sizeof(data_48_2_1),
839 static const struct iso_client_data connect_16_2_1_send = {
842 .send = &send_16_2_1,
845 static const struct iso_client_data listen_16_2_1_recv = {
848 .recv = &send_16_2_1,
852 static const struct iso_client_data listen_16_2_1_recv_ts = {
855 .recv = &send_16_2_1,
860 static const struct iso_client_data listen_16_2_1_recv_pkt_status = {
863 .recv = &send_16_2_1,
868 static const struct iso_client_data defer_16_2_1 = {
874 static const struct iso_client_data defer_1_16_2_1 = {
880 static const struct iso_client_data connect_16_2_1_defer_send = {
883 .send = &send_16_2_1,
887 static const struct iso_client_data connect_48_2_1_defer_send = {
890 .send = &send_16_2_1,
894 static const struct iso_client_data listen_16_2_1_defer_recv = {
897 .recv = &send_16_2_1,
902 static const struct iso_client_data listen_48_2_1_defer_recv = {
905 .recv = &send_48_2_1,
910 static const struct iso_client_data listen_16_2_1_defer_reject = {
913 .recv = &send_16_2_1,
918 static const struct iso_client_data connect_16_2_1_send_recv = {
921 .send = &send_16_2_1,
922 .recv = &send_16_2_1,
925 static const struct iso_client_data disconnect_16_2_1 = {
931 static const struct iso_client_data suspend_16_2_1 = {
936 static const struct iso_client_data reconnect_16_2_1 = {
942 static const struct iso_client_data connect_ac_1_4 = {
947 static const struct iso_client_data connect_ac_2_10 = {
952 static const struct iso_client_data connect_ac_3_5 = {
957 static const struct iso_client_data connect_ac_6i = {
965 static const struct iso_client_data reconnect_ac_6i = {
974 static const struct iso_client_data connect_ac_6ii = {
982 static const struct iso_client_data reconnect_ac_6ii = {
991 static const struct iso_client_data connect_ac_6ii_cis_ef_auto = {
999 static const struct iso_client_data connect_ac_6ii_cis_ef_ef = {
1001 .qos_2 = AC_6ii_1_EF,
1002 .expect_err = -EINVAL,
1007 static const struct iso_client_data connect_ac_7i = {
1015 static const struct iso_client_data connect_ac_7ii = {
1023 static const struct iso_client_data connect_ac_8i = {
1031 static const struct iso_client_data connect_ac_8ii = {
1039 static const struct iso_client_data connect_ac_9i = {
1047 static const struct iso_client_data connect_ac_9ii = {
1055 static const struct iso_client_data connect_ac_11i = {
1063 static const struct iso_client_data connect_ac_11ii = {
1071 static const struct iso_client_data connect_ac_1_2 = {
1078 static const struct iso_client_data connect_ac_1_2_cig_1_2 = {
1085 static const struct iso_client_data bcast_16_2_1_send = {
1086 .qos = QOS_OUT_16_2_1,
1088 .send = &send_16_2_1,
1090 .base = base_lc3_16_2_1,
1091 .base_len = sizeof(base_lc3_16_2_1),
1094 static const struct iso_client_data bcast_enc_16_2_1_send = {
1095 .qos = QOS_OUT_ENC_16_2_1,
1097 .send = &send_16_2_1,
1099 .base = base_lc3_16_2_1,
1100 .base_len = sizeof(base_lc3_16_2_1),
1103 static const struct iso_client_data bcast_1_16_2_1_send = {
1104 .qos = QOS_OUT_1_16_2_1,
1106 .send = &send_16_2_1,
1108 .base = base_lc3_16_2_1,
1109 .base_len = sizeof(base_lc3_16_2_1),
1112 static const struct iso_client_data bcast_1_1_16_2_1_send = {
1113 .qos = QOS_OUT_1_1_16_2_1,
1115 .send = &send_16_2_1,
1117 .base = base_lc3_16_2_1,
1118 .base_len = sizeof(base_lc3_16_2_1),
1121 static const struct iso_client_data bcast_16_2_1_recv = {
1122 .qos = QOS_IN_16_2_1,
1124 .recv = &send_16_2_1,
1129 static const struct iso_client_data bcast_enc_16_2_1_recv = {
1130 .qos = QOS_IN_ENC_16_2_1,
1132 .recv = &send_16_2_1,
1137 static const struct iso_client_data bcast_16_2_1_recv_defer = {
1138 .qos = QOS_IN_16_2_1,
1141 .recv = &send_16_2_1,
1146 static const struct iso_client_data bcast_ac_12 = {
1150 .base = base_lc3_ac_12,
1151 .base_len = sizeof(base_lc3_ac_12),
1154 static const struct iso_client_data bcast_ac_13 = {
1159 .base = base_lc3_ac_13,
1160 .base_len = sizeof(base_lc3_ac_13),
1163 static const struct iso_client_data bcast_ac_14 = {
1167 .base = base_lc3_ac_14,
1168 .base_len = sizeof(base_lc3_ac_14),
1171 static void client_connectable_complete(uint16_t opcode, uint8_t status,
1172 const void *param, uint8_t len,
1175 struct test_data *data = user_data;
1176 static uint8_t client_num;
1178 if (opcode != BT_HCI_CMD_LE_SET_EXT_ADV_ENABLE)
1181 tester_print("Client %u set connectable status 0x%02x", client_num,
1187 tester_setup_failed();
1188 else if (data->client_num == client_num) {
1189 tester_setup_complete();
1194 static void bthost_recv_data(const void *buf, uint16_t len, void *user_data)
1196 struct test_data *data = user_data;
1197 const struct iso_client_data *isodata = data->test_data;
1199 tester_print("Client received %u bytes of data", len);
1201 if (isodata->send && (isodata->send->iov_len != len ||
1202 memcmp(isodata->send->iov_base, buf, len))) {
1203 if (!isodata->recv->iov_base)
1204 tester_test_failed();
1206 tester_test_passed();
1209 static void bthost_iso_disconnected(void *user_data)
1211 struct test_data *data = user_data;
1213 tester_print("ISO handle 0x%04x disconnected", data->handle);
1215 data->handle = 0x0000;
1218 static void iso_new_conn(uint16_t handle, void *user_data)
1220 struct test_data *data = user_data;
1221 struct bthost *host;
1223 tester_print("New client connection with handle 0x%04x", handle);
1225 data->handle = handle;
1227 host = hciemu_client_get_host(data->hciemu);
1228 bthost_add_iso_hook(host, data->handle, bthost_recv_data, data,
1229 bthost_iso_disconnected);
1232 static uint8_t iso_accept_conn(uint16_t handle, void *user_data)
1234 struct test_data *data = user_data;
1236 tester_print("Accept client connection with handle 0x%04x: 0x%02x",
1237 handle, data->accept_reason);
1239 return data->accept_reason;
1242 static void acl_new_conn(uint16_t handle, void *user_data)
1244 struct test_data *data = user_data;
1246 tester_print("New ACL connection with handle 0x%04x", handle);
1248 data->acl_handle = handle;
1251 static void setup_powered_callback(uint8_t status, uint16_t length,
1252 const void *param, void *user_data)
1254 struct test_data *data = tester_get_data();
1255 const struct iso_client_data *isodata = data->test_data;
1258 if (status != MGMT_STATUS_SUCCESS) {
1259 tester_setup_failed();
1263 tester_print("Controller powered on");
1265 for (i = 0; i < data->client_num; i++) {
1266 struct hciemu_client *client;
1267 struct bthost *host;
1269 client = hciemu_get_client(data->hciemu, i);
1270 host = hciemu_client_host(client);
1271 bthost_set_cmd_complete_cb(host, client_connectable_complete,
1273 bthost_set_ext_adv_params(host);
1274 bthost_set_ext_adv_enable(host, 0x01);
1279 if (isodata->send || isodata->recv || isodata->disconnect ||
1280 isodata->suspend || data->accept_reason)
1281 bthost_set_iso_cb(host, iso_accept_conn, iso_new_conn,
1284 if (isodata->bcast) {
1285 bthost_set_pa_params(host);
1286 bthost_set_pa_enable(host, 0x01);
1287 bthost_create_big(host, 1,
1288 isodata->qos.bcast.encryption,
1289 isodata->qos.bcast.bcode);
1290 } else if (!isodata->send && isodata->recv) {
1291 const uint8_t *bdaddr;
1293 bdaddr = hciemu_get_central_bdaddr(data->hciemu);
1294 bthost_set_connect_cb(host, acl_new_conn, data);
1295 bthost_hci_connect(host, bdaddr, BDADDR_LE_PUBLIC);
1300 static void setup_powered(const void *test_data)
1302 struct test_data *data = tester_get_data();
1303 const struct iso_client_data *isodata = data->test_data;
1304 unsigned char param[] = { 0x01 };
1306 tester_print("Powering on controller");
1308 if (!isodata || !isodata->bcast)
1309 mgmt_send(data->mgmt, MGMT_OP_SET_CONNECTABLE, data->mgmt_index,
1310 sizeof(param), param,
1313 mgmt_send(data->mgmt, MGMT_OP_SET_SSP, data->mgmt_index,
1314 sizeof(param), param, NULL, NULL, NULL);
1316 mgmt_send(data->mgmt, MGMT_OP_SET_LE, data->mgmt_index,
1317 sizeof(param), param, NULL, NULL, NULL);
1319 if (isodata && isodata->server && !isodata->bcast)
1320 mgmt_send(data->mgmt, MGMT_OP_SET_ADVERTISING,
1321 data->mgmt_index, sizeof(param), param, NULL,
1324 mgmt_send(data->mgmt, MGMT_OP_SET_POWERED, data->mgmt_index,
1325 sizeof(param), param,
1326 setup_powered_callback, NULL, NULL);
1329 static void test_framework(const void *test_data)
1331 tester_test_passed();
1334 static void test_socket(const void *test_data)
1338 sk = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_ISO);
1340 tester_warn("Can't create socket: %s (%d)", strerror(errno),
1342 tester_test_abort();
1348 tester_test_passed();
1351 static void test_getsockopt(const void *test_data)
1355 struct bt_iso_qos qos;
1357 sk = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_ISO);
1359 tester_warn("Can't create socket: %s (%d)", strerror(errno),
1361 tester_test_abort();
1366 memset(&qos, 0, len);
1368 err = getsockopt(sk, SOL_BLUETOOTH, BT_ISO_QOS, &qos, &len);
1370 tester_warn("Can't get socket option : %s (%d)",
1371 strerror(errno), errno);
1372 tester_test_failed();
1376 tester_test_passed();
1382 static void test_setsockopt(const void *test_data)
1386 struct bt_iso_qos qos = QOS_16_1_2;
1389 sk = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_ISO);
1391 tester_warn("Can't create socket: %s (%d)", strerror(errno),
1393 tester_test_abort();
1397 err = setsockopt(sk, SOL_BLUETOOTH, BT_ISO_QOS, &qos, sizeof(qos));
1399 tester_warn("Can't set socket option : %s (%d)",
1400 strerror(errno), errno);
1401 tester_test_failed();
1406 memset(&qos, 0, len);
1408 err = getsockopt(sk, SOL_BLUETOOTH, BT_ISO_QOS, &qos, &len);
1410 tester_warn("Can't get socket option : %s (%d)",
1411 strerror(errno), errno);
1412 tester_test_failed();
1416 err = setsockopt(sk, SOL_BLUETOOTH, BT_PKT_STATUS, &pkt_status,
1417 sizeof(pkt_status));
1419 tester_warn("Can't set socket BT_PKT_STATUS option: "
1420 "%s (%d)", strerror(errno), errno);
1421 tester_test_failed();
1425 len = sizeof(pkt_status);
1426 memset(&pkt_status, 0, len);
1428 err = getsockopt(sk, SOL_BLUETOOTH, BT_PKT_STATUS, &pkt_status, &len);
1430 tester_warn("Can't get socket option : %s (%d)",
1431 strerror(errno), errno);
1432 tester_test_failed();
1436 tester_test_passed();
1442 static int create_iso_sock(struct test_data *data)
1444 const uint8_t *master_bdaddr;
1445 struct sockaddr_iso addr;
1448 sk = socket(PF_BLUETOOTH, SOCK_SEQPACKET | SOCK_NONBLOCK, BTPROTO_ISO);
1451 tester_warn("Can't create socket: %s (%d)", strerror(errno),
1456 master_bdaddr = hciemu_get_central_bdaddr(data->hciemu);
1457 if (!master_bdaddr) {
1458 tester_warn("No master bdaddr");
1462 memset(&addr, 0, sizeof(addr));
1463 addr.iso_family = AF_BLUETOOTH;
1464 bacpy(&addr.iso_bdaddr, (void *) master_bdaddr);
1465 addr.iso_bdaddr_type = BDADDR_LE_PUBLIC;
1467 if (bind(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
1469 tester_warn("Can't bind socket: %s (%d)", strerror(errno),
1478 static int connect_iso_sock(struct test_data *data, uint8_t num, int sk)
1480 const struct iso_client_data *isodata = data->test_data;
1481 struct hciemu_client *client;
1482 const uint8_t *client_bdaddr = NULL;
1483 const struct bt_iso_qos *qos = &isodata->qos;
1484 struct sockaddr_iso addr;
1488 client = hciemu_get_client(data->hciemu, num);
1490 if (!isodata->mconn) {
1491 tester_warn("No client");
1495 client = hciemu_get_client(data->hciemu, 0);
1497 tester_warn("No client");
1502 if (!isodata->bcast && num && isodata->mconn)
1503 qos = &isodata->qos_2;
1505 if (!isodata->bcast) {
1506 client_bdaddr = hciemu_client_bdaddr(client);
1507 if (!client_bdaddr) {
1508 tester_warn("No client bdaddr");
1511 } else if (!isodata->server) {
1512 err = setsockopt(sk, SOL_BLUETOOTH, BT_ISO_BASE,
1513 isodata->base, isodata->base_len);
1515 tester_warn("Can't set socket BT_ISO_BASE option: "
1516 "%s (%d)", strerror(errno), errno);
1517 tester_test_failed();
1522 err = setsockopt(sk, SOL_BLUETOOTH, BT_ISO_QOS, qos, sizeof(*qos));
1524 tester_warn("Can't set socket BT_ISO_QOS option : %s (%d)",
1525 strerror(errno), errno);
1526 tester_test_failed();
1530 if (isodata->defer || (isodata->bcast && isodata->mconn && !num)) {
1533 if (setsockopt(sk, SOL_BLUETOOTH, BT_DEFER_SETUP, &opt,
1535 tester_print("Can't enable deferred setup: %s (%d)",
1536 strerror(errno), errno);
1537 tester_test_failed();
1542 memset(&addr, 0, sizeof(addr));
1543 addr.iso_family = AF_BLUETOOTH;
1544 bacpy(&addr.iso_bdaddr, client_bdaddr ? (void *) client_bdaddr :
1546 addr.iso_bdaddr_type = BDADDR_LE_PUBLIC;
1548 ba2str(&addr.iso_bdaddr, str);
1550 tester_print("Connecting to %s...", str);
1552 err = connect(sk, (struct sockaddr *) &addr, sizeof(addr));
1553 if (err < 0 && !(errno == EAGAIN || errno == EINPROGRESS)) {
1555 tester_warn("Can't connect socket: %s (%d)", strerror(errno),
1563 static bool check_io_qos(const struct bt_iso_io_qos *io1,
1564 const struct bt_iso_io_qos *io2)
1566 if (io1->interval && io2->interval && io1->interval > io2->interval) {
1567 tester_warn("Unexpected IO interval: %u > %u",
1568 io1->interval, io2->interval);
1572 if (io1->latency && io2->latency && io1->latency > io2->latency) {
1573 tester_warn("Unexpected IO latency: %u > %u",
1574 io1->latency, io2->latency);
1578 if (io1->sdu && io2->sdu && io1->sdu != io2->sdu) {
1579 tester_warn("Unexpected IO SDU: %u != %u", io1->sdu, io2->sdu);
1583 if (io1->phy && io2->phy && io1->phy != io2->phy) {
1584 tester_warn("Unexpected IO PHY: 0x%02x != 0x%02x",
1585 io1->phy, io2->phy);
1589 if (io1->rtn && io2->rtn && io1->rtn != io2->rtn) {
1590 tester_warn("Unexpected IO RTN: %u != %u", io1->rtn, io2->rtn);
1597 static bool check_ucast_qos(const struct bt_iso_qos *qos1,
1598 const struct bt_iso_qos *qos2,
1599 const struct bt_iso_qos *qos2_2)
1601 if (qos1->ucast.cig != BT_ISO_QOS_CIG_UNSET &&
1602 qos2->ucast.cig != BT_ISO_QOS_CIG_UNSET &&
1603 qos1->ucast.cig != qos2->ucast.cig) {
1605 return check_ucast_qos(qos1, qos2_2, NULL);
1607 tester_warn("Unexpected CIG ID: 0x%02x != 0x%02x",
1608 qos1->ucast.cig, qos2->ucast.cig);
1612 if (qos1->ucast.cis != BT_ISO_QOS_CIS_UNSET &&
1613 qos2->ucast.cis != BT_ISO_QOS_CIS_UNSET &&
1614 qos1->ucast.cis != qos2->ucast.cis) {
1616 return check_ucast_qos(qos1, qos2_2, NULL);
1618 tester_warn("Unexpected CIS ID: 0x%02x != 0x%02x",
1619 qos1->ucast.cis, qos2->ucast.cis);
1623 if (qos1->ucast.packing != qos2->ucast.packing) {
1625 return check_ucast_qos(qos1, qos2_2, NULL);
1627 tester_warn("Unexpected QoS packing: 0x%02x != 0x%02x",
1628 qos1->ucast.packing, qos2->ucast.packing);
1632 if (qos1->ucast.framing != qos2->ucast.framing) {
1634 return check_ucast_qos(qos1, qos2_2, NULL);
1636 tester_warn("Unexpected QoS framing: 0x%02x != 0x%02x",
1637 qos1->ucast.framing, qos2->ucast.framing);
1641 if (!check_io_qos(&qos1->ucast.in, &qos2->ucast.in)) {
1643 return check_ucast_qos(qos1, qos2_2, NULL);
1645 tester_warn("Unexpected Input QoS");
1649 if (!check_io_qos(&qos1->ucast.out, &qos2->ucast.out)) {
1651 return check_ucast_qos(qos1, qos2_2, NULL);
1653 tester_warn("Unexpected Output QoS");
1660 static bool check_bcast_qos(const struct bt_iso_qos *qos1,
1661 const struct bt_iso_qos *qos2)
1663 if (qos1->bcast.big != BT_ISO_QOS_BIG_UNSET &&
1664 qos2->bcast.big != BT_ISO_QOS_BIG_UNSET &&
1665 qos1->bcast.big != qos2->bcast.big) {
1666 tester_warn("Unexpected BIG ID: 0x%02x != 0x%02x",
1667 qos1->bcast.big, qos2->bcast.big);
1671 if (qos1->bcast.bis != BT_ISO_QOS_BIS_UNSET &&
1672 qos2->bcast.bis != BT_ISO_QOS_BIS_UNSET &&
1673 qos1->bcast.bis != qos2->bcast.bis) {
1674 tester_warn("Unexpected BIS ID: 0x%02x != 0x%02x",
1675 qos1->bcast.bis, qos2->bcast.bis);
1679 if (qos1->bcast.sync_interval != qos2->bcast.sync_interval) {
1680 tester_warn("Unexpected QoS sync interval: 0x%02x != 0x%02x",
1681 qos1->bcast.sync_interval, qos2->bcast.sync_interval);
1685 if (qos1->bcast.packing != qos2->bcast.packing) {
1686 tester_warn("Unexpected QoS packing: 0x%02x != 0x%02x",
1687 qos1->bcast.packing, qos2->bcast.packing);
1691 if (qos1->bcast.framing != qos2->bcast.framing) {
1692 tester_warn("Unexpected QoS framing: 0x%02x != 0x%02x",
1693 qos1->bcast.framing, qos2->bcast.framing);
1697 if (!check_io_qos(&qos1->ucast.in, &qos2->ucast.in)) {
1698 tester_warn("Unexpected Input QoS");
1702 if (!check_io_qos(&qos1->ucast.out, &qos2->ucast.out)) {
1703 tester_warn("Unexpected Output QoS");
1707 if (qos1->bcast.encryption != qos2->bcast.encryption) {
1708 tester_warn("Unexpected QoS encryption: 0x%02x != 0x%02x",
1709 qos1->bcast.encryption, qos2->bcast.encryption);
1713 if (memcmp(qos1->bcast.bcode, qos2->bcast.bcode,
1714 sizeof(qos1->bcast.bcode))) {
1715 tester_warn("Unexpected QoS Broadcast Code");
1719 if (qos1->bcast.options != qos2->bcast.options) {
1720 tester_warn("Unexpected QoS options: 0x%02x != 0x%02x",
1721 qos1->bcast.options, qos2->bcast.options);
1725 if (qos1->bcast.skip != qos2->bcast.skip) {
1726 tester_warn("Unexpected QoS skip: 0x%04x != 0x%04x",
1727 qos1->bcast.skip, qos2->bcast.skip);
1731 if (qos1->bcast.sync_timeout != qos2->bcast.sync_timeout) {
1732 tester_warn("Unexpected QoS sync timeout: 0x%04x != 0x%04x",
1733 qos1->bcast.sync_timeout, qos2->bcast.sync_timeout);
1737 if (qos1->bcast.sync_cte_type != qos2->bcast.sync_cte_type) {
1738 tester_warn("Unexpected QoS sync cte type: 0x%02x != 0x%02x",
1739 qos1->bcast.sync_cte_type, qos2->bcast.sync_cte_type);
1743 if (qos1->bcast.mse != qos2->bcast.mse) {
1744 tester_warn("Unexpected QoS MSE: 0x%02x != 0x%02x",
1745 qos1->bcast.mse, qos2->bcast.mse);
1749 if (qos1->bcast.timeout != qos2->bcast.timeout) {
1750 tester_warn("Unexpected QoS MSE: 0x%04x != 0x%04x",
1751 qos1->bcast.timeout, qos2->bcast.timeout);
1758 static gboolean iso_recv_data(GIOChannel *io, GIOCondition cond,
1761 struct test_data *data = user_data;
1762 const struct iso_client_data *isodata = data->test_data;
1763 int sk = g_io_channel_unix_get_fd(io);
1764 unsigned char control[64];
1773 iov.iov_len = isodata->recv->iov_len;
1775 memset(&msg, 0, sizeof(msg));
1778 msg.msg_control = control;
1779 msg.msg_controllen = sizeof(control);
1781 ret = recvmsg(sk, &msg, MSG_DONTWAIT);
1782 if (ret < 0 || isodata->recv->iov_len != (size_t) ret) {
1783 tester_warn("Failed to read %zu bytes: %s (%d)",
1784 isodata->recv->iov_len, strerror(errno), errno);
1785 tester_test_failed();
1789 if (isodata->pkt_status) {
1790 struct cmsghdr *cmsg;
1791 uint8_t pkt_status = 0;
1793 for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL;
1794 cmsg = CMSG_NXTHDR(&msg, cmsg)) {
1795 if (cmsg->cmsg_level != SOL_BLUETOOTH)
1798 if (cmsg->cmsg_type == BT_SCM_PKT_STATUS) {
1799 memcpy(&pkt_status, CMSG_DATA(cmsg),
1800 sizeof(pkt_status));
1801 tester_debug("BT_SCM_PKT_STATUS = 0x%2.2x",
1807 if (isodata->pkt_status != pkt_status) {
1808 tester_warn("isodata->pkt_status 0x%2.2x != 0x%2.2x "
1809 "pkt_status", isodata->pkt_status,
1811 tester_test_failed();
1813 tester_test_passed();
1818 if (memcmp(buf, isodata->recv->iov_base, ret))
1819 tester_test_failed();
1821 tester_test_passed();
1826 static void iso_recv(struct test_data *data, GIOChannel *io)
1828 const struct iso_client_data *isodata = data->test_data;
1829 struct bthost *host;
1832 tester_print("Receive %zu bytes of data", isodata->recv->iov_len);
1834 if (!data->handle) {
1835 tester_warn("ISO handle not set");
1836 tester_test_failed();
1840 host = hciemu_client_get_host(data->hciemu);
1841 bthost_send_iso(host, data->handle, isodata->ts, sn++, 0,
1842 isodata->pkt_status, isodata->recv, 1);
1844 data->io_id[0] = g_io_add_watch(io, G_IO_IN, iso_recv_data, data);
1847 static void iso_send(struct test_data *data, GIOChannel *io)
1849 const struct iso_client_data *isodata = data->test_data;
1853 sk = g_io_channel_unix_get_fd(io);
1855 tester_print("Writing %zu bytes of data", isodata->send->iov_len);
1857 ret = writev(sk, isodata->send, 1);
1858 if (ret < 0 || isodata->send->iov_len != (size_t) ret) {
1859 tester_warn("Failed to write %zu bytes: %s (%d)",
1860 isodata->send->iov_len, strerror(errno), errno);
1861 tester_test_failed();
1865 if (isodata->bcast) {
1866 tester_test_passed();
1874 static void test_connect(const void *test_data);
1875 static gboolean iso_connect_cb(GIOChannel *io, GIOCondition cond,
1876 gpointer user_data);
1877 static gboolean iso_accept_cb(GIOChannel *io, GIOCondition cond,
1878 gpointer user_data);
1880 static gboolean iso_disconnected(GIOChannel *io, GIOCondition cond,
1883 struct test_data *data = user_data;
1887 if ((cond & G_IO_HUP) && !data->handle) {
1888 tester_print("Successfully disconnected");
1890 if (data->reconnect) {
1891 data->reconnect = false;
1892 test_connect(data->test_data);
1896 tester_test_passed();
1898 tester_test_failed();
1903 static void iso_shutdown(struct test_data *data, GIOChannel *io)
1907 sk = g_io_channel_unix_get_fd(io);
1909 data->io_id[0] = g_io_add_watch(io, G_IO_HUP, iso_disconnected, data);
1911 /* Shutdown using SHUT_WR as SHUT_RDWR cause the socket to HUP
1912 * immediately instead of waiting for Disconnect Complete event.
1914 shutdown(sk, SHUT_WR);
1916 tester_print("Disconnecting...");
1919 static bool hook_set_event_mask(const void *msg, uint16_t len, void *user_data)
1921 struct test_data *data = user_data;
1923 tester_print("Set Event Mask");
1927 tester_test_passed();
1932 static void trigger_force_suspend(void *user_data)
1934 struct test_data *data = tester_get_data();
1935 struct vhci *vhci = hciemu_get_vhci(data->hciemu);
1938 /* Make sure suspend is only triggered once */
1939 if (data->suspending)
1942 data->suspending = true;
1944 /* Triggers the suspend */
1945 tester_print("Set the system into Suspend via force_suspend");
1946 err = vhci_set_force_suspend(vhci, true);
1948 tester_warn("Unable to enable the force_suspend");
1954 hciemu_add_hook(data->hciemu, HCIEMU_HOOK_PRE_CMD,
1955 BT_HCI_CMD_SET_EVENT_MASK,
1956 hook_set_event_mask, data);
1959 static gboolean iso_connect(GIOChannel *io, GIOCondition cond,
1962 struct test_data *data = tester_get_data();
1963 const struct iso_client_data *isodata = data->test_data;
1964 int err, sk_err, sk;
1966 struct bt_iso_qos qos;
1969 sk = g_io_channel_unix_get_fd(io);
1972 memset(&qos, 0, len);
1974 err = getsockopt(sk, SOL_BLUETOOTH, BT_ISO_QOS, &qos, &len);
1976 tester_warn("Can't get socket option : %s (%d)",
1977 strerror(errno), errno);
1978 tester_test_failed();
1982 if (!isodata->bcast) {
1983 ret = check_ucast_qos(&qos, &isodata->qos,
1984 isodata->mconn ? &isodata->qos_2 : NULL);
1985 } else if (!isodata->server)
1986 ret = check_bcast_qos(&qos, &isodata->qos);
1989 tester_warn("Unexpected QoS parameter");
1990 tester_test_failed();
1994 len = sizeof(sk_err);
1996 if (getsockopt(sk, SOL_SOCKET, SO_ERROR, &sk_err, &len) < 0)
2002 tester_warn("Connect failed: %s (%d)", strerror(-err), -err);
2004 tester_print("Successfully connected");
2006 if (err != isodata->expect_err) {
2007 tester_warn("Expect error: %s (%d) != %s (%d)",
2008 strerror(-isodata->expect_err),
2009 -isodata->expect_err, strerror(-err), -err);
2010 tester_test_failed();
2014 tester_print("Step %u", data->step);
2015 else if (isodata->send)
2017 else if (isodata->recv)
2019 else if (isodata->disconnect)
2020 iso_shutdown(data, io);
2021 else if (isodata->suspend)
2022 trigger_force_suspend(data);
2024 tester_test_passed();
2030 static gboolean iso_connect_cb(GIOChannel *io, GIOCondition cond,
2033 struct test_data *data = tester_get_data();
2037 return iso_connect(io, cond, user_data);
2040 static gboolean iso_connect2_cb(GIOChannel *io, GIOCondition cond,
2043 struct test_data *data = tester_get_data();
2047 return iso_connect(io, cond, user_data);
2050 static int setup_sock(struct test_data *data, uint8_t num)
2054 sk = create_iso_sock(data);
2056 if (sk == -EPROTONOSUPPORT)
2057 tester_test_abort();
2059 tester_test_failed();
2064 err = connect_iso_sock(data, num, sk);
2066 const struct iso_client_data *isodata = data->test_data;
2070 if (isodata->expect_err == err)
2071 tester_test_passed();
2073 tester_test_failed();
2081 static int connect_deferred(int sk)
2088 /* Check if socket has DEFER_SETUP set */
2089 len = sizeof(defer);
2090 if (getsockopt(sk, SOL_BLUETOOTH, BT_DEFER_SETUP, &defer,
2092 tester_warn("getsockopt: %s (%d)", strerror(errno),
2094 tester_test_failed();
2098 memset(&pfd, 0, sizeof(pfd));
2100 pfd.events = POLLOUT;
2102 if (poll(&pfd, 1, 0) < 0) {
2103 tester_warn("poll: %s (%d)", strerror(errno), errno);
2104 tester_test_failed();
2108 if (!(pfd.revents & POLLOUT)) {
2109 if (read(sk, &c, 1) < 0) {
2110 tester_warn("read: %s (%d)", strerror(errno),
2112 tester_test_failed();
2120 static void setup_connect_many(struct test_data *data, uint8_t n, uint8_t *num,
2123 const struct iso_client_data *isodata = data->test_data;
2128 for (i = 0; i < n; ++i) {
2129 sk[i] = setup_sock(data, num[i]);
2134 if (isodata->defer) {
2135 for (i = 0; i < n; ++i)
2136 if (connect_deferred(sk[i]) < 0)
2140 for (i = 0; i < n; ++i) {
2141 io = g_io_channel_unix_new(sk[i]);
2142 g_io_channel_set_close_on_unref(io, TRUE);
2144 data->io_id[num[i]] = g_io_add_watch(io, G_IO_OUT, func[i],
2147 g_io_channel_unref(io);
2149 tester_print("Connect %d in progress", num[i]);
2155 static void setup_connect(struct test_data *data, uint8_t num, GIOFunc func)
2157 return setup_connect_many(data, 1, &num, &func);
2160 static void test_connect(const void *test_data)
2162 struct test_data *data = tester_get_data();
2163 const struct iso_client_data *isodata = test_data;
2166 uint8_t num[2] = {0, 1};
2168 func[n++] = iso_connect_cb;
2170 /* Check if configuration requires multiple CIS setup */
2171 if (!isodata->bcast && isodata->mconn)
2172 func[n++] = iso_connect2_cb;
2174 setup_connect_many(data, n, num, func);
2177 static void test_reconnect(const void *test_data)
2179 struct test_data *data = tester_get_data();
2181 data->reconnect = true;
2182 test_connect(test_data);
2185 static void test_defer(const void *test_data)
2187 struct test_data *data = tester_get_data();
2188 const struct iso_client_data *isodata = data->test_data;
2191 sk = create_iso_sock(data);
2193 if (sk == -EPROTONOSUPPORT)
2194 tester_test_abort();
2196 tester_test_failed();
2200 err = connect_iso_sock(data, 0, sk);
2204 if (isodata->expect_err == err)
2205 tester_test_passed();
2207 tester_test_failed();
2214 if (isodata->expect_err == err)
2215 tester_test_passed();
2217 tester_test_failed();
2220 static int listen_iso_sock(struct test_data *data)
2222 const struct iso_client_data *isodata = data->test_data;
2223 const uint8_t *src, *dst;
2224 struct sockaddr_iso *addr = NULL;
2227 sk = socket(PF_BLUETOOTH, SOCK_SEQPACKET | SOCK_NONBLOCK, BTPROTO_ISO);
2230 tester_warn("Can't create socket: %s (%d)", strerror(errno),
2235 src = hciemu_get_central_bdaddr(data->hciemu);
2237 tester_warn("No source bdaddr");
2242 /* Bind to local address */
2243 addr = malloc(sizeof(*addr) + sizeof(*addr->iso_bc));
2244 memset(addr, 0, sizeof(*addr) + sizeof(*addr->iso_bc));
2245 addr->iso_family = AF_BLUETOOTH;
2246 bacpy(&addr->iso_bdaddr, (void *) src);
2247 addr->iso_bdaddr_type = BDADDR_LE_PUBLIC;
2249 if (isodata->bcast) {
2250 /* Bind to destination address in case of broadcast */
2251 dst = hciemu_get_client_bdaddr(data->hciemu);
2253 tester_warn("No source bdaddr");
2258 bacpy(&addr->iso_bc->bc_bdaddr, (void *) dst);
2259 addr->iso_bc->bc_bdaddr_type = BDADDR_LE_PUBLIC;
2260 addr->iso_bc->bc_num_bis = 1;
2261 addr->iso_bc->bc_bis[0] = 1;
2263 err = bind(sk, (struct sockaddr *) addr, sizeof(*addr) +
2264 sizeof(*addr->iso_bc));
2266 err = bind(sk, (struct sockaddr *) addr, sizeof(*addr));
2271 tester_warn("Can't bind socket: %s (%d)", strerror(errno),
2276 if (isodata->defer) {
2279 if (setsockopt(sk, SOL_BLUETOOTH, BT_DEFER_SETUP, &opt,
2281 tester_print("Can't enable deferred setup: %s (%d)",
2282 strerror(errno), errno);
2287 if (setsockopt(sk, SOL_BLUETOOTH, BT_ISO_QOS, &isodata->qos,
2288 sizeof(isodata->qos)) < 0) {
2289 tester_print("Can't set socket BT_ISO_QOS option: %s (%d)",
2290 strerror(errno), errno);
2294 if (listen(sk, 10)) {
2296 tester_warn("Can't listen socket: %s (%d)", strerror(errno),
2311 static void setup_listen(struct test_data *data, uint8_t num, GIOFunc func)
2313 const struct iso_client_data *isodata = data->test_data;
2317 sk = listen_iso_sock(data);
2319 if (sk == -EPROTONOSUPPORT)
2320 tester_test_abort();
2322 tester_test_failed();
2326 io = g_io_channel_unix_new(sk);
2327 g_io_channel_set_close_on_unref(io, TRUE);
2329 data->io_id[num] = g_io_add_watch(io, G_IO_IN, func, NULL);
2331 g_io_channel_unref(io);
2333 tester_print("Listen in progress");
2337 if (!isodata->bcast) {
2338 struct hciemu_client *client;
2339 struct bthost *host;
2341 if (!data->acl_handle) {
2342 tester_print("ACL handle not set");
2343 tester_test_failed();
2347 client = hciemu_get_client(data->hciemu, 0);
2348 host = hciemu_client_host(client);
2350 bthost_set_cig_params(host, 0x01, 0x01, &isodata->qos);
2351 bthost_create_cis(host, 257, data->acl_handle);
2355 static bool iso_defer_accept(struct test_data *data, GIOChannel *io)
2360 const struct iso_client_data *isodata = data->test_data;
2362 sk = g_io_channel_unix_get_fd(io);
2364 memset(&pfd, 0, sizeof(pfd));
2366 pfd.events = POLLOUT;
2368 if (poll(&pfd, 1, 0) < 0) {
2369 tester_warn("poll: %s (%d)", strerror(errno), errno);
2373 if (!(pfd.revents & POLLOUT)) {
2374 if (read(sk, &c, 1) < 0) {
2375 tester_warn("read: %s (%d)", strerror(errno), errno);
2380 tester_print("Accept deferred setup");
2384 if (isodata->bcast) {
2385 data->io_id[0] = g_io_add_watch(io, G_IO_IN,
2386 iso_accept_cb, NULL);
2389 data->io_id[0] = g_io_add_watch(io, G_IO_OUT,
2390 iso_connect_cb, NULL);
2396 static gboolean iso_accept_cb(GIOChannel *io, GIOCondition cond,
2399 struct test_data *data = tester_get_data();
2400 const struct iso_client_data *isodata = data->test_data;
2405 sk = g_io_channel_unix_get_fd(io);
2407 new_sk = accept(sk, NULL, NULL);
2409 tester_test_failed();
2413 io = g_io_channel_unix_new(new_sk);
2414 g_io_channel_set_close_on_unref(io, TRUE);
2416 if (isodata->defer) {
2417 if (isodata->expect_err < 0) {
2418 g_io_channel_unref(io);
2419 tester_test_passed();
2423 if (isodata->bcast && data->step > 1) {
2428 if (!iso_defer_accept(data, io)) {
2429 tester_warn("Unable to accept deferred setup");
2430 tester_test_failed();
2435 if (isodata->pkt_status) {
2438 if (setsockopt(new_sk, SOL_BLUETOOTH, BT_PKT_STATUS, &opt,
2440 tester_print("Can't set socket BT_PKT_STATUS option: "
2441 "%s (%d)", strerror(errno), errno);
2442 tester_test_failed();
2448 return iso_connect(io, cond, user_data);
2451 static void test_listen(const void *test_data)
2453 struct test_data *data = tester_get_data();
2455 setup_listen(data, 0, iso_accept_cb);
2458 static void test_connect2(const void *test_data)
2460 struct test_data *data = tester_get_data();
2461 uint8_t num[2] = {0, 1};
2462 GIOFunc funcs[2] = {iso_connect_cb, iso_connect2_cb};
2464 setup_connect_many(data, 2, num, funcs);
2467 static gboolean iso_connect2_seq_cb(GIOChannel *io, GIOCondition cond,
2470 struct test_data *data = tester_get_data();
2474 setup_connect(data, 1, iso_connect2_cb);
2476 return iso_connect(io, cond, user_data);
2479 static void test_connect2_seq(const void *test_data)
2481 struct test_data *data = tester_get_data();
2483 setup_connect(data, 0, iso_connect2_seq_cb);
2486 static gboolean test_connect2_busy_done(gpointer user_data)
2488 struct test_data *data = tester_get_data();
2490 if (data->io_id[0] > 0) {
2491 /* First connection still exists */
2492 g_source_remove(data->io_id[0]);
2494 tester_test_passed();
2496 tester_test_failed();
2502 static gboolean iso_connect_cb_busy_disc(GIOChannel *io, GIOCondition cond,
2505 struct test_data *data = tester_get_data();
2509 tester_print("Disconnected 1");
2510 tester_test_failed();
2514 static gboolean iso_connect_cb_busy_2(GIOChannel *io, GIOCondition cond,
2517 struct test_data *data = tester_get_data();
2518 int err, sk_err, sk;
2523 sk = g_io_channel_unix_get_fd(io);
2525 len = sizeof(sk_err);
2527 if (getsockopt(sk, SOL_SOCKET, SO_ERROR, &sk_err, &len) < 0)
2532 tester_print("Connected 2: %d", err);
2534 if (err == -EBUSY && data->io_id[0] > 0) {
2535 /* Wait in case first connection still gets disconnected */
2536 data->io_id[1] = g_timeout_add(250, test_connect2_busy_done,
2539 tester_test_failed();
2545 static gboolean iso_connect_cb_busy(GIOChannel *io, GIOCondition cond,
2548 struct test_data *data = tester_get_data();
2550 /* First connection shall not be disconnected */
2551 data->io_id[0] = g_io_add_watch(io, G_IO_ERR | G_IO_HUP,
2552 iso_connect_cb_busy_disc, data);
2554 /* Second connect shall fail since CIG is now busy */
2555 setup_connect(data, 1, iso_connect_cb_busy_2);
2557 return iso_connect(io, cond, user_data);
2560 static void test_connect2_busy(const void *test_data)
2562 struct test_data *data = tester_get_data();
2564 setup_connect(data, 0, iso_connect_cb_busy);
2567 static gboolean iso_connect_close_cb(GIOChannel *io, GIOCondition cond,
2570 struct test_data *data = user_data;
2574 tester_print("Disconnected");
2578 tester_test_passed();
2583 static bool hook_remove_cig(const void *msg, uint16_t len, void *user_data)
2585 struct test_data *data = user_data;
2587 tester_print("Remove CIG");
2591 tester_test_passed();
2596 static void test_connect_close(const void *test_data)
2598 struct test_data *data = tester_get_data();
2604 hciemu_add_hook(data->hciemu, HCIEMU_HOOK_PRE_CMD,
2605 BT_HCI_CMD_LE_REMOVE_CIG,
2606 hook_remove_cig, data);
2608 sk = setup_sock(data, 0);
2612 io = g_io_channel_unix_new(sk);
2613 g_io_channel_set_close_on_unref(io, TRUE);
2614 data->io_id[0] = g_io_add_watch(io, G_IO_HUP, iso_connect_close_cb,
2617 shutdown(sk, SHUT_RDWR);
2620 static gboolean iso_connect_wait_close_cb(GIOChannel *io, GIOCondition cond,
2623 struct test_data *data = tester_get_data();
2626 tester_print("Connected");
2628 sk = g_io_channel_unix_get_fd(io);
2630 data->io_id[0] = g_io_add_watch(io, G_IO_HUP, iso_connect_close_cb,
2633 shutdown(sk, SHUT_RDWR);
2638 static void test_connect_wait_close(const void *test_data)
2640 struct test_data *data = tester_get_data();
2644 hciemu_add_hook(data->hciemu, HCIEMU_HOOK_PRE_CMD,
2645 BT_HCI_CMD_LE_REMOVE_CIG,
2646 hook_remove_cig, data);
2648 setup_connect(data, 0, iso_connect_wait_close_cb);
2651 static void test_connect_suspend(const void *test_data)
2653 test_connect(test_data);
2654 trigger_force_suspend((void *)test_data);
2657 static bool hook_acl_disc(const void *msg, uint16_t len, void *user_data)
2659 const uint8_t *msg_data = msg;
2660 const struct bt_hci_evt_le_enhanced_conn_complete *ev;
2661 struct test_data *data = tester_get_data();
2662 struct bthost *bthost;
2664 if (msg_data[0] != BT_HCI_EVT_LE_ENHANCED_CONN_COMPLETE)
2667 ev = (void *) &msg_data[1];
2669 tester_print("Disconnect ACL");
2671 bthost = hciemu_client_get_host(data->hciemu);
2672 bthost_hci_disconnect(bthost, le16_to_cpu(ev->handle), 0x13);
2674 hciemu_flush_client_events(data->hciemu);
2679 static void test_connect_acl_disc(const void *test_data)
2681 struct test_data *data = tester_get_data();
2683 /* ACL disconnected before ISO is created */
2684 hciemu_add_hook(data->hciemu, HCIEMU_HOOK_POST_EVT,
2685 BT_HCI_EVT_LE_META_EVENT,
2686 hook_acl_disc, NULL);
2688 test_connect(test_data);
2691 static void test_bcast(const void *test_data)
2693 struct test_data *data = tester_get_data();
2695 setup_connect(data, 0, iso_connect_cb);
2698 static void test_bcast2(const void *test_data)
2700 struct test_data *data = tester_get_data();
2701 uint8_t num[2] = {0, 1};
2702 GIOFunc funcs[2] = {iso_connect_cb, iso_connect2_cb};
2704 setup_connect_many(data, 2, num, funcs);
2707 static void test_bcast_recv(const void *test_data)
2709 struct test_data *data = tester_get_data();
2711 setup_listen(data, 0, iso_accept_cb);
2714 static void test_connect2_suspend(const void *test_data)
2716 test_connect2(test_data);
2717 trigger_force_suspend((void *)test_data);
2720 int main(int argc, char *argv[])
2722 tester_init(&argc, &argv);
2724 test_iso("Basic Framework - Success", NULL, setup_powered,
2727 test_iso("Basic ISO Socket - Success", NULL, setup_powered,
2730 test_iso("Basic ISO Get Socket Option - Success", NULL, setup_powered,
2733 test_iso("Basic ISO Set Socket Option - Success", NULL, setup_powered,
2736 test_iso("ISO QoS 8_1_1 - Success", &connect_8_1_1, setup_powered,
2739 test_iso("ISO QoS 8_2_1 - Success", &connect_8_2_1, setup_powered,
2742 test_iso("ISO QoS 16_1_1 - Success", &connect_16_1_1, setup_powered,
2745 test_iso("ISO QoS 16_2_1 - Success", &connect_16_2_1, setup_powered,
2748 test_iso("ISO QoS 16_2_1 CIG 0x01 - Success", &connect_1_16_2_1,
2752 test_iso("ISO QoS 16_2_1 CIG 0x01 CIS 0x01 - Success",
2753 &connect_1_1_16_2_1,
2757 test_iso("ISO QoS 24_1_1 - Success", &connect_24_1_1, setup_powered,
2760 test_iso("ISO QoS 24_2_1 - Success", &connect_24_2_1, setup_powered,
2763 test_iso("ISO QoS 32_1_1 - Success", &connect_32_1_1, setup_powered,
2766 test_iso("ISO QoS 32_2_1 - Success", &connect_32_2_1, setup_powered,
2769 test_iso("ISO QoS 44_1_1 - Success", &connect_44_1_1, setup_powered,
2772 test_iso("ISO QoS 44_2_1 - Success", &connect_44_2_1, setup_powered,
2775 test_iso("ISO QoS 48_1_1 - Success", &connect_48_1_1, setup_powered,
2778 test_iso("ISO QoS 48_2_1 - Success", &connect_48_2_1, setup_powered,
2781 test_iso("ISO QoS 48_3_1 - Success", &connect_48_3_1, setup_powered,
2784 test_iso("ISO QoS 48_4_1 - Success", &connect_48_4_1, setup_powered,
2787 test_iso("ISO QoS 48_5_1 - Success", &connect_48_5_1, setup_powered,
2790 test_iso("ISO QoS 48_6_1 - Success", &connect_48_6_1, setup_powered,
2793 test_iso("ISO QoS 8_1_2 - Success", &connect_8_1_2, setup_powered,
2796 test_iso("ISO QoS 8_2_2 - Success", &connect_8_2_2, setup_powered,
2799 test_iso("ISO QoS 16_1_2 - Success", &connect_16_1_2, setup_powered,
2802 test_iso("ISO QoS 16_2_2 - Success", &connect_16_2_2, setup_powered,
2805 test_iso("ISO QoS 24_1_2 - Success", &connect_24_1_2, setup_powered,
2808 test_iso("ISO QoS 24_2_2 - Success", &connect_24_2_2, setup_powered,
2811 test_iso("ISO QoS 32_1_2 - Success", &connect_32_1_2, setup_powered,
2814 test_iso("ISO QoS 32_2_2 - Success", &connect_32_2_2, setup_powered,
2817 test_iso("ISO QoS 44_1_2 - Success", &connect_44_1_2, setup_powered,
2820 test_iso("ISO QoS 44_2_2 - Success", &connect_44_2_2, setup_powered,
2823 test_iso("ISO QoS 48_1_2 - Success", &connect_48_1_2, setup_powered,
2826 test_iso("ISO QoS 48_2_2 - Success", &connect_48_2_2, setup_powered,
2829 test_iso("ISO QoS 48_3_2 - Success", &connect_48_3_2, setup_powered,
2832 test_iso("ISO QoS 48_4_2 - Success", &connect_48_4_2, setup_powered,
2835 test_iso("ISO QoS 48_5_2 - Success", &connect_48_5_2, setup_powered,
2838 test_iso("ISO QoS 48_6_2 - Success", &connect_48_6_2, setup_powered,
2841 test_iso("ISO QoS - Invalid", &connect_invalid, setup_powered,
2844 test_iso("ISO QoS CIG 0xF0 - Invalid", &connect_cig_f0_invalid,
2845 setup_powered, test_connect);
2847 test_iso("ISO QoS CIS 0xF0 - Invalid", &connect_cis_f0_invalid,
2848 setup_powered, test_connect);
2850 test_iso_rej("ISO Connect - Reject", &connect_reject, setup_powered,
2851 test_connect, BT_HCI_ERR_CONN_FAILED_TO_ESTABLISH);
2853 test_iso("ISO Send - Success", &connect_16_2_1_send, setup_powered,
2856 test_iso("ISO Receive - Success", &listen_16_2_1_recv, setup_powered,
2859 test_iso("ISO Receive Timestamped - Success", &listen_16_2_1_recv_ts,
2863 test_iso("ISO Receive Packet Status - Success",
2864 &listen_16_2_1_recv_pkt_status,
2865 setup_powered, test_listen);
2867 test_iso("ISO Defer - Success", &defer_16_2_1, setup_powered,
2870 test_iso("ISO Defer Connect - Success", &defer_16_2_1, setup_powered,
2873 test_iso("ISO Defer Close - Success", &defer_16_2_1, setup_powered,
2874 test_connect_close);
2876 test_iso("ISO Connect Close - Success", &connect_16_2_1, setup_powered,
2877 test_connect_close);
2879 test_iso("ISO Defer Wait Close - Success", &defer_16_2_1,
2880 setup_powered, test_connect_wait_close);
2882 test_iso("ISO Connect Wait Close - Success", &connect_16_2_1,
2883 setup_powered, test_connect_wait_close);
2885 test_iso("ISO Connect Suspend - Success", &connect_suspend,
2887 test_connect_suspend);
2889 test_iso("ISO Connected Suspend - Success", &suspend_16_2_1,
2893 test_iso2("ISO Connect2 CIG 0x01 - Success", &connect_1_16_2_1,
2897 test_iso2("ISO Connect2 Busy CIG 0x01 - Success/Invalid",
2898 &connect_1_16_2_1, setup_powered,
2899 test_connect2_busy);
2901 test_iso2("ISO Defer Connect2 CIG 0x01 - Success", &defer_1_16_2_1,
2905 test_iso2("ISO Connect2 Suspend - Success", &connect_suspend,
2907 test_connect2_suspend);
2909 test_iso2("ISO Connected2 Suspend - Success", &suspend_16_2_1,
2913 test_iso("ISO Connect ACL Disconnect - Failure", &connect_suspend,
2915 test_connect_acl_disc);
2917 test_iso("ISO Defer Send - Success", &connect_16_2_1_defer_send,
2921 test_iso("ISO 48_2_1 Defer Send - Success", &connect_48_2_1_defer_send,
2925 test_iso("ISO Defer Receive - Success", &listen_16_2_1_defer_recv,
2926 setup_powered, test_listen);
2928 test_iso("ISO 48_2_1 Defer Receive - Success",
2929 &listen_48_2_1_defer_recv,
2930 setup_powered, test_listen);
2932 test_iso("ISO Defer Reject - Success", &listen_16_2_1_defer_reject,
2933 setup_powered, test_listen);
2935 test_iso("ISO Send and Receive - Success", &connect_16_2_1_send_recv,
2939 test_iso("ISO Disconnect - Success", &disconnect_16_2_1,
2943 test_iso("ISO Reconnect - Success", &reconnect_16_2_1,
2947 test_iso("ISO AC 1 & 4 - Success", &connect_ac_1_4, setup_powered,
2950 test_iso("ISO AC 2 & 10 - Success", &connect_ac_2_10, setup_powered,
2953 test_iso("ISO AC 3 & 5 - Success", &connect_ac_3_5, setup_powered,
2956 test_iso("ISO AC 6(i) - Success", &connect_ac_6i, setup_powered,
2959 test_iso2("ISO AC 6(ii) - Success", &connect_ac_6ii, setup_powered,
2962 test_iso("ISO AC 7(i) - Success", &connect_ac_7i, setup_powered,
2965 test_iso2("ISO AC 7(ii) - Success", &connect_ac_7ii, setup_powered,
2968 test_iso("ISO AC 8(i) - Success", &connect_ac_8i, setup_powered,
2971 test_iso2("ISO AC 8(ii) - Success", &connect_ac_8ii, setup_powered,
2974 test_iso("ISO AC 9(i) - Success", &connect_ac_9i, setup_powered,
2977 test_iso2("ISO AC 9(ii) - Success", &connect_ac_9ii, setup_powered,
2980 test_iso("ISO AC 11(i) - Success", &connect_ac_11i, setup_powered,
2983 test_iso2("ISO AC 11(ii) - Success", &connect_ac_11ii, setup_powered,
2986 test_iso2("ISO AC 1 + 2 - Success", &connect_ac_1_2, setup_powered,
2989 test_iso2("ISO AC 1 + 2 CIG 0x01/0x02 - Success",
2990 &connect_ac_1_2_cig_1_2,
2994 test_iso2("ISO Reconnect AC 6(i) - Success", &reconnect_ac_6i,
2998 test_iso2("ISO Reconnect AC 6(ii) - Success", &reconnect_ac_6ii,
3002 test_iso2("ISO AC 6(ii) CIS 0xEF/auto - Success",
3003 &connect_ac_6ii_cis_ef_auto,
3004 setup_powered, test_connect);
3006 test_iso2("ISO AC 6(ii) CIS 0xEF/0xEF - Invalid",
3007 &connect_ac_6ii_cis_ef_ef,
3008 setup_powered, test_connect);
3010 test_iso("ISO Broadcaster - Success", &bcast_16_2_1_send, setup_powered,
3012 test_iso("ISO Broadcaster Encrypted - Success", &bcast_enc_16_2_1_send,
3015 test_iso("ISO Broadcaster BIG 0x01 - Success", &bcast_1_16_2_1_send,
3018 test_iso("ISO Broadcaster BIG 0x01 BIS 0x01 - Success",
3019 &bcast_1_1_16_2_1_send,
3023 test_iso("ISO Broadcaster Receiver - Success", &bcast_16_2_1_recv,
3026 test_iso("ISO Broadcaster Receiver Encrypted - Success",
3027 &bcast_enc_16_2_1_recv,
3030 test_iso("ISO Broadcaster Receiver Defer - Success",
3031 &bcast_16_2_1_recv_defer,
3035 test_iso("ISO Broadcaster AC 12 - Success", &bcast_ac_12, setup_powered,
3038 test_iso("ISO Broadcaster AC 13 - Success", &bcast_ac_13, setup_powered,
3041 test_iso("ISO Broadcaster AC 14 - Success", &bcast_ac_14, setup_powered,
3044 return tester_run();