Skip to content

Commit ab7faed

Browse files
committed
Bluetooth: BAP: Add a set of suggested intervals to use with BAP
Add a selection of interval values that are suitable for BAP, which will allow better coexistence between ISO and ACL, for both broadcast and unicast. Some of these are defined by the BAP spec, and some are defined by Zephyr, since they do have a suggested value from BAP. Samples and tests have been updated to use these new values. Peripheral samples have also been updated with CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS so that the connection parameters from the centrals aren't updated to something else shortly after. The shell has also been updated to use the LE Audio (BAP) values if audio is enabled, and the audio.conf file has disabled automatic updating of the connection parameters as the peripheral, as we rarely (if ever) want to do that. Due to the connection interval change, CI hit an issue with test_bass_broadcast_code in test_main_client_sync, where the reading of the long receive state did not finish before we attempted to do another procedure, so the function was updated to have a retry. Finally some tests were disabled as they are no longer passing. They should be reenabled once issues in the controller have been resolved. Signed-off-by: Emil Gydesen <[email protected]>
1 parent 1a18f4b commit ab7faed

File tree

42 files changed

+284
-232
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+284
-232
lines changed

include/zephyr/bluetooth/audio/bap.h

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <zephyr/bluetooth/addr.h>
3333
#include <zephyr/bluetooth/bluetooth.h>
3434
#include <zephyr/bluetooth/conn.h>
35+
#include <zephyr/bluetooth/gap.h>
3536
#include <zephyr/bluetooth/iso.h>
3637
#include <zephyr/net_buf.h>
3738
#include <zephyr/sys/slist.h>
@@ -53,6 +54,100 @@ extern "C" {
5354
/** An invalid Broadcast ID */
5455
#define BT_BAP_INVALID_BROADCAST_ID 0xFFFFFFFFU
5556

57+
/**
58+
* @brief Recommended connectable advertising parameters
59+
*
60+
* If connection has not been established after 30 seconds, the device should switch to
61+
* @ref BT_BAP_ADV_PARAM_CONN_REDUCED
62+
*
63+
* Defined by Table 8.1 in BAP 1.0.2
64+
*/
65+
#define BT_BAP_ADV_PARAM_CONN_QUICK \
66+
BT_LE_ADV_PARAM(BT_LE_ADV_OPT_CONN | BT_LE_ADV_OPT_EXT_ADV, BT_GAP_MS_TO_ADV_INTERVAL(20), \
67+
BT_GAP_MS_TO_ADV_INTERVAL(30), NULL)
68+
69+
/**
70+
* @brief Reduced connectable advertising parameters
71+
*
72+
* Defined by Table 8.1 in BAP 1.0.2
73+
*/
74+
#define BT_BAP_ADV_PARAM_CONN_REDUCED \
75+
BT_LE_ADV_PARAM(BT_LE_ADV_OPT_CONN | BT_LE_ADV_OPT_EXT_ADV, \
76+
BT_GAP_MS_TO_ADV_INTERVAL(150), BT_GAP_MS_TO_ADV_INTERVAL(150), NULL)
77+
78+
/**
79+
* @brief Recommended connection parameters for initial connection request for 7.5 ms SDU interval
80+
*
81+
* Once service discovery has completed and a stream is setup, it is recommended to switch to
82+
* @ref BT_BAP_CONN_PARAM_RELAXED
83+
*
84+
* Defined by Table 8.3 in BAP 1.0.2
85+
*/
86+
#define BT_BAP_CONN_PARAM_SHORT_7_5 \
87+
BT_LE_CONN_PARAM(BT_GAP_US_TO_CONN_INTERVAL(7500), BT_GAP_MS_TO_CONN_INTERVAL(30), 0, \
88+
BT_GAP_MS_TO_CONN_TIMEOUT(4000))
89+
90+
/**
91+
* @brief Recommended connection parameters for initial connection request for 10 ms SDU interval
92+
*
93+
* Once service discovery has completed and a stream is setup, it is recommended to switch to
94+
* @ref BT_BAP_CONN_PARAM_RELAXED
95+
*
96+
* Defined by Table 8.3 in BAP 1.0.2
97+
*/
98+
#define BT_BAP_CONN_PARAM_SHORT_10 \
99+
BT_LE_CONN_PARAM(BT_GAP_MS_TO_CONN_INTERVAL(10), BT_GAP_MS_TO_CONN_INTERVAL(30), 0, \
100+
BT_GAP_MS_TO_CONN_TIMEOUT(4000))
101+
102+
/**
103+
* @brief Recommended connection parameters for coexistence of ACL and ISO
104+
*
105+
* Defined by Table 8.3 in BAP 1.0.2
106+
*/
107+
#define BT_BAP_CONN_PARAM_RELAXED \
108+
BT_LE_CONN_PARAM(BT_GAP_MS_TO_CONN_INTERVAL(50), BT_GAP_MS_TO_CONN_INTERVAL(70), 0, \
109+
BT_GAP_MS_TO_CONN_TIMEOUT(4000))
110+
111+
/**
112+
* @brief Fast advertising parameters for broadcast audio
113+
*
114+
* This is suitable for both 7.5 ms and 10 ms SDU intervals, but prioritizes lower time to
115+
* synchronize over coexistence with ISO and power consumption.
116+
*/
117+
#define BT_BAP_ADV_PARAM_BROADCAST_FAST \
118+
BT_LE_ADV_PARAM(BT_LE_ADV_OPT_EXT_ADV, BT_GAP_MS_TO_ADV_INTERVAL(60), \
119+
BT_GAP_MS_TO_ADV_INTERVAL(60), NULL)
120+
121+
/**
122+
* @brief Slow advertising parameters for broadcast audio
123+
*
124+
* This is suitable for both 7.5 ms and 10 ms SDU intervals, but prioritizes coexistence with ISO
125+
* and power consumption over lower time to synchronize.
126+
*/
127+
#define BT_BAP_ADV_PARAM_BROADCAST_SLOW \
128+
BT_LE_ADV_PARAM(BT_LE_ADV_OPT_EXT_ADV, BT_GAP_MS_TO_ADV_INTERVAL(150), \
129+
BT_GAP_MS_TO_ADV_INTERVAL(150), NULL)
130+
131+
/**
132+
* @brief Fast advertising parameters for broadcast audio
133+
*
134+
* This is suitable for both 7.5 ms and 10 ms SDU intervals, but prioritizes lower time to
135+
* synchronize over coexistence with ISO and power consumption.
136+
*/
137+
#define BT_BAP_PER_ADV_PARAM_BROADCAST_FAST \
138+
BT_LE_PER_ADV_PARAM(BT_GAP_MS_TO_PER_ADV_INTERVAL(60), BT_GAP_MS_TO_PER_ADV_INTERVAL(60), \
139+
BT_LE_PER_ADV_OPT_NONE)
140+
141+
/**
142+
* @brief Slow advertising parameters for broadcast audio
143+
*
144+
* This is suitable for both 7.5 ms and 10 ms SDU intervals, but prioritizes coexistence with ISO
145+
* and power consumption over lower time to synchronize.
146+
*/
147+
#define BT_BAP_PER_ADV_PARAM_BROADCAST_SLOW \
148+
BT_LE_PER_ADV_PARAM(BT_GAP_MS_TO_PER_ADV_INTERVAL(150), \
149+
BT_GAP_MS_TO_PER_ADV_INTERVAL(150), BT_LE_PER_ADV_OPT_NONE)
150+
56151
/**
57152
* @brief Check if a BAP BASS BIS_Sync bitfield is valid
58153
*

samples/bluetooth/bap_broadcast_assistant/src/main.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,7 @@ static void scan_recv_cb(const struct bt_le_scan_recv_info *info,
383383
printk("Connecting to Broadcast Sink: %s\n", sr_info.bt_name);
384384

385385
err = bt_conn_le_create(info->addr, BT_CONN_LE_CREATE_CONN,
386-
BT_LE_CONN_PARAM_DEFAULT,
387-
&broadcast_sink_conn);
386+
BT_BAP_CONN_PARAM_RELAXED, &broadcast_sink_conn);
388387
if (err != 0) {
389388
printk("Failed creating connection (err=%u)\n", err);
390389
scan_for_broadcast_sink();

samples/bluetooth/bap_broadcast_sink/prj.conf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ CONFIG_BT_AUDIO=y
44
CONFIG_BT_SMP=y
55
CONFIG_BT_PAC_SNK=y
66
CONFIG_BT_PERIPHERAL=y
7+
CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS=n
8+
# Set preferred values based on BT_BAP_CONN_PARAM_RELAXED
9+
CONFIG_BT_PERIPHERAL_PREF_MIN_INT=50
10+
CONFIG_BT_PERIPHERAL_PREF_MAX_INT=70
11+
CONFIG_BT_PERIPHERAL_PREF_LATENCY=0
12+
CONFIG_BT_PERIPHERAL_PREF_TIMEOUT=400
713
CONFIG_BT_OBSERVER=y
814
CONFIG_BT_GATT_DYNAMIC_DB=y
915
CONFIG_BT_EXT_ADV=y

samples/bluetooth/bap_broadcast_sink/src/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1406,7 +1406,7 @@ static int start_adv(void)
14061406
int err;
14071407

14081408
/* Create a connectable advertising set */
1409-
err = bt_le_ext_adv_create(BT_LE_EXT_ADV_CONN, NULL, &ext_adv);
1409+
err = bt_le_ext_adv_create(BT_BAP_ADV_PARAM_CONN_REDUCED, NULL, &ext_adv);
14101410
if (err != 0) {
14111411
printk("Failed to create advertising set (err %d)\n", err);
14121412

samples/bluetooth/bap_broadcast_source/src/main.c

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,6 @@
3434

3535
BUILD_ASSERT(strlen(CONFIG_BROADCAST_CODE) <= BT_ISO_BROADCAST_CODE_SIZE, "Invalid broadcast code");
3636

37-
/* Zephyr Controller works best while Extended Advertising interval to be a multiple
38-
* of the ISO Interval minus 10 ms (max. advertising random delay). This is
39-
* required to place the AUX_ADV_IND PDUs in a non-overlapping interval with the
40-
* Broadcast ISO radio events.
41-
*
42-
* I.e. for a 7.5 ms ISO interval use 90 ms minus 10 ms ==> 80 ms advertising
43-
* interval.
44-
* And, for 10 ms ISO interval, can use 90 ms minus 10 ms ==> 80 ms advertising
45-
* interval.
46-
*/
47-
#define BT_LE_EXT_ADV_CUSTOM \
48-
BT_LE_ADV_PARAM(BT_LE_ADV_OPT_EXT_ADV, BT_GAP_MS_TO_ADV_INTERVAL(80), \
49-
BT_GAP_MS_TO_ADV_INTERVAL(80), NULL)
50-
5137
/* When BROADCAST_ENQUEUE_COUNT > 1 we can enqueue enough buffers to ensure that
5238
* the controller is never idle
5339
*/
@@ -576,14 +562,14 @@ int main(void)
576562
uint32_t broadcast_id;
577563

578564
/* Create a connectable advertising set */
579-
err = bt_le_ext_adv_create(BT_LE_EXT_ADV_CUSTOM, NULL, &adv);
565+
err = bt_le_ext_adv_create(BT_BAP_ADV_PARAM_BROADCAST_FAST, NULL, &adv);
580566
if (err != 0) {
581567
printk("Unable to create extended advertising set: %d\n", err);
582568
return 0;
583569
}
584570

585571
/* Set periodic advertising parameters */
586-
err = bt_le_per_adv_set_param(adv, BT_LE_PER_ADV_DEFAULT);
572+
err = bt_le_per_adv_set_param(adv, BT_BAP_PER_ADV_PARAM_BROADCAST_FAST);
587573
if (err) {
588574
printk("Failed to set periodic advertising parameters (err %d)\n", err);
589575
return 0;

samples/bluetooth/bap_unicast_client/src/main.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,7 @@ static bool check_audio_support_and_connect(struct bt_data *data,
162162
printk("Audio server found with type %u, contexts 0x%08x and meta_len %u; connecting\n",
163163
announcement_type, audio_contexts, meta_len);
164164

165-
err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN,
166-
BT_LE_CONN_PARAM_DEFAULT,
165+
err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN, BT_BAP_CONN_PARAM_RELAXED,
167166
&default_conn);
168167
if (err != 0) {
169168
printk("Create conn to failed (%u)\n", err);

samples/bluetooth/bap_unicast_server/prj.conf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ CONFIG_BT=y
22
CONFIG_LOG=y
33
CONFIG_BT_SMP=y
44
CONFIG_BT_PERIPHERAL=y
5+
CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS=n
6+
# Set preferred values based on BT_BAP_CONN_PARAM_RELAXED
7+
CONFIG_BT_PERIPHERAL_PREF_MIN_INT=50
8+
CONFIG_BT_PERIPHERAL_PREF_MAX_INT=70
9+
CONFIG_BT_PERIPHERAL_PREF_LATENCY=0
10+
CONFIG_BT_PERIPHERAL_PREF_TIMEOUT=400
511
CONFIG_BT_ISO_PERIPHERAL=y
612
CONFIG_BT_AUDIO=y
713
CONFIG_BT_GATT_CACHING=y

samples/bluetooth/bap_unicast_server/src/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ int main(void)
778778
}
779779

780780
/* Create a connectable advertising set */
781-
err = bt_le_ext_adv_create(BT_LE_EXT_ADV_CONN, NULL, &adv);
781+
err = bt_le_ext_adv_create(BT_BAP_ADV_PARAM_CONN_QUICK, NULL, &adv);
782782
if (err) {
783783
printk("Failed to create advertising set (err %d)\n", err);
784784
return 0;

samples/bluetooth/cap_acceptor/prj.conf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
CONFIG_BT=y
22
CONFIG_LOG=y
33
CONFIG_BT_PERIPHERAL=y
4+
CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS=n
5+
# Set preferred values based on BT_BAP_CONN_PARAM_RELAXED
6+
CONFIG_BT_PERIPHERAL_PREF_MIN_INT=50
7+
CONFIG_BT_PERIPHERAL_PREF_MAX_INT=70
8+
CONFIG_BT_PERIPHERAL_PREF_LATENCY=0
9+
CONFIG_BT_PERIPHERAL_PREF_TIMEOUT=400
410
CONFIG_BT_GATT_DYNAMIC_DB=y
511
CONFIG_BT_GATT_CLIENT=y
612
CONFIG_BT_EXT_ADV=y

samples/bluetooth/cap_acceptor/src/main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include <zephyr/bluetooth/addr.h>
1414
#include <zephyr/bluetooth/audio/audio.h>
15+
#include <zephyr/bluetooth/audio/bap.h>
1516
#include <zephyr/bluetooth/audio/cap.h>
1617
#include <zephyr/bluetooth/audio/lc3.h>
1718
#include <zephyr/bluetooth/audio/pacs.h>
@@ -104,7 +105,7 @@ static int advertise(void)
104105
{
105106
int err;
106107

107-
err = bt_le_ext_adv_create(BT_LE_EXT_ADV_CONN, NULL, &adv);
108+
err = bt_le_ext_adv_create(BT_BAP_ADV_PARAM_CONN_QUICK, NULL, &adv);
108109
if (err) {
109110
LOG_ERR("Failed to create advertising set: %d", err);
110111

0 commit comments

Comments
 (0)