Skip to content

Commit 9d4cc4b

Browse files
Thalleykartben
authored andcommitted
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. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
1 parent f960194 commit 9d4cc4b

File tree

44 files changed

+297
-233
lines changed

Some content is hidden

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

44 files changed

+297
-233
lines changed

doc/releases/release-notes-4.2.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,18 @@ New APIs and options
6565
6666
* Bluetooth
6767

68+
* Audio
69+
70+
* :c:macro:`BT_BAP_ADV_PARAM_CONN_QUICK`
71+
* :c:macro:`BT_BAP_ADV_PARAM_CONN_REDUCED`
72+
* :c:macro:`BT_BAP_CONN_PARAM_SHORT_7_5`
73+
* :c:macro:`BT_BAP_CONN_PARAM_SHORT_10`
74+
* :c:macro:`BT_BAP_CONN_PARAM_RELAXED`
75+
* :c:macro:`BT_BAP_ADV_PARAM_BROADCAST_FAST`
76+
* :c:macro:`BT_BAP_ADV_PARAM_BROADCAST_SLOW`
77+
* :c:macro:`BT_BAP_PER_ADV_PARAM_BROADCAST_FAST`
78+
* :c:macro:`BT_BAP_PER_ADV_PARAM_BROADCAST_SLOW`
79+
6880
* Host
6981

7082
* :c:func:`bt_le_get_local_features`

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>
@@ -51,6 +52,100 @@ extern "C" {
5152
/** An invalid Broadcast ID */
5253
#define BT_BAP_INVALID_BROADCAST_ID 0xFFFFFFFFU
5354

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

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
@@ -964,7 +964,7 @@ static int start_adv(void)
964964
int err;
965965

966966
/* Create a connectable advertising set */
967-
err = bt_le_ext_adv_create(BT_LE_EXT_ADV_CONN, NULL, &ext_adv);
967+
err = bt_le_ext_adv_create(BT_BAP_ADV_PARAM_CONN_REDUCED, NULL, &ext_adv);
968968
if (err != 0) {
969969
printk("Failed to create advertising set (err %d)\n", err);
970970

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_DYNAMIC_DB=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

0 commit comments

Comments
 (0)