From 9d4cc4b49b96edf82269c5c7f15448c24190d06c Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Thu, 7 Nov 2024 18:43:13 +0100 Subject: [PATCH] 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 --- doc/releases/release-notes-4.2.rst | 12 +++ include/zephyr/bluetooth/audio/bap.h | 95 +++++++++++++++++++ .../bap_broadcast_assistant/src/main.c | 3 +- samples/bluetooth/bap_broadcast_sink/prj.conf | 6 ++ .../bluetooth/bap_broadcast_sink/src/main.c | 2 +- .../bluetooth/bap_broadcast_source/src/main.c | 18 +--- .../bluetooth/bap_unicast_client/src/main.c | 3 +- samples/bluetooth/bap_unicast_server/prj.conf | 6 ++ .../bluetooth/bap_unicast_server/src/main.c | 2 +- samples/bluetooth/cap_acceptor/prj.conf | 6 ++ samples/bluetooth/cap_acceptor/src/main.c | 3 +- .../src/cap_initiator_broadcast.c | 6 +- .../cap_initiator/src/cap_initiator_unicast.c | 3 +- samples/bluetooth/hap_ha/prj.conf | 6 ++ samples/bluetooth/hap_ha/src/main.c | 2 +- .../pbp_public_broadcast_source/src/main.c | 4 +- .../bluetooth/tmap_bms/src/cap_initiator.c | 4 +- samples/bluetooth/tmap_central/src/main.c | 3 +- samples/bluetooth/tmap_peripheral/prj.conf | 6 ++ samples/bluetooth/tmap_peripheral/src/main.c | 2 +- subsys/bluetooth/host/shell/bt.c | 12 ++- tests/bluetooth/shell/audio.conf | 8 +- tests/bluetooth/tester/overlay-le-audio.conf | 6 ++ .../tester/src/audio/btp_bap_broadcast.c | 22 ++--- tests/bluetooth/tester/src/btp_gap.c | 21 ++-- tests/bsim/bluetooth/audio/prj.conf | 5 + .../audio/src/bap_bass_broadcaster_test.c | 18 +--- .../audio/src/bap_broadcast_assistant_test.c | 37 +++++--- .../audio/src/bap_broadcast_source_test.c | 20 +--- tests/bsim/bluetooth/audio/src/bap_common.h | 4 + .../audio/src/bap_unicast_client_test.c | 20 ++-- .../bluetooth/audio/src/cap_acceptor_test.c | 11 --- .../bluetooth/audio/src/cap_commander_test.c | 4 +- .../audio/src/cap_initiator_broadcast_test.c | 36 +------ .../audio/src/cap_initiator_unicast_test.c | 4 +- tests/bsim/bluetooth/audio/src/common.c | 33 ++++++- tests/bsim/bluetooth/audio/src/common.h | 1 + .../audio/src/csip_set_coordinator_test.c | 5 +- .../bsim/bluetooth/audio/src/gmap_ugg_test.c | 33 +------ .../src/pbp_public_broadcast_source_test.c | 29 +----- .../bluetooth/audio/src/tmap_client_test.c | 4 +- .../bluetooth/audio/src/tmap_server_test.c | 1 + .../bap_broadcast_audio_assistant.sh | 2 +- .../src/unicast_client_sample_test.c | 2 +- 44 files changed, 297 insertions(+), 233 deletions(-) diff --git a/doc/releases/release-notes-4.2.rst b/doc/releases/release-notes-4.2.rst index 67c5919cd96..d4b4fc02dc9 100644 --- a/doc/releases/release-notes-4.2.rst +++ b/doc/releases/release-notes-4.2.rst @@ -65,6 +65,18 @@ New APIs and options * Bluetooth + * Audio + + * :c:macro:`BT_BAP_ADV_PARAM_CONN_QUICK` + * :c:macro:`BT_BAP_ADV_PARAM_CONN_REDUCED` + * :c:macro:`BT_BAP_CONN_PARAM_SHORT_7_5` + * :c:macro:`BT_BAP_CONN_PARAM_SHORT_10` + * :c:macro:`BT_BAP_CONN_PARAM_RELAXED` + * :c:macro:`BT_BAP_ADV_PARAM_BROADCAST_FAST` + * :c:macro:`BT_BAP_ADV_PARAM_BROADCAST_SLOW` + * :c:macro:`BT_BAP_PER_ADV_PARAM_BROADCAST_FAST` + * :c:macro:`BT_BAP_PER_ADV_PARAM_BROADCAST_SLOW` + * Host * :c:func:`bt_le_get_local_features` diff --git a/include/zephyr/bluetooth/audio/bap.h b/include/zephyr/bluetooth/audio/bap.h index 1ad0047e2f5..ad452bf9188 100644 --- a/include/zephyr/bluetooth/audio/bap.h +++ b/include/zephyr/bluetooth/audio/bap.h @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -51,6 +52,100 @@ extern "C" { /** An invalid Broadcast ID */ #define BT_BAP_INVALID_BROADCAST_ID 0xFFFFFFFFU +/** + * @brief Recommended connectable advertising parameters + * + * If connection has not been established after 30 seconds, the device should switch to + * @ref BT_BAP_ADV_PARAM_CONN_REDUCED + * + * Defined by Table 8.1 in BAP 1.0.2 + */ +#define BT_BAP_ADV_PARAM_CONN_QUICK \ + BT_LE_ADV_PARAM(BT_LE_ADV_OPT_CONN | BT_LE_ADV_OPT_EXT_ADV, BT_GAP_MS_TO_ADV_INTERVAL(20), \ + BT_GAP_MS_TO_ADV_INTERVAL(30), NULL) + +/** + * @brief Reduced connectable advertising parameters + * + * Defined by Table 8.1 in BAP 1.0.2 + */ +#define BT_BAP_ADV_PARAM_CONN_REDUCED \ + BT_LE_ADV_PARAM(BT_LE_ADV_OPT_CONN | BT_LE_ADV_OPT_EXT_ADV, \ + BT_GAP_MS_TO_ADV_INTERVAL(150), BT_GAP_MS_TO_ADV_INTERVAL(150), NULL) + +/** + * @brief Recommended connection parameters for initial connection request for 7.5 ms SDU interval + * + * Once service discovery has completed and a stream is setup, it is recommended to switch to + * @ref BT_BAP_CONN_PARAM_RELAXED + * + * Defined by Table 8.3 in BAP 1.0.2 + */ +#define BT_BAP_CONN_PARAM_SHORT_7_5 \ + BT_LE_CONN_PARAM(BT_GAP_US_TO_CONN_INTERVAL(7500), BT_GAP_MS_TO_CONN_INTERVAL(30), 0, \ + BT_GAP_MS_TO_CONN_TIMEOUT(4000)) + +/** + * @brief Recommended connection parameters for initial connection request for 10 ms SDU interval + * + * Once service discovery has completed and a stream is setup, it is recommended to switch to + * @ref BT_BAP_CONN_PARAM_RELAXED + * + * Defined by Table 8.3 in BAP 1.0.2 + */ +#define BT_BAP_CONN_PARAM_SHORT_10 \ + BT_LE_CONN_PARAM(BT_GAP_MS_TO_CONN_INTERVAL(10), BT_GAP_MS_TO_CONN_INTERVAL(30), 0, \ + BT_GAP_MS_TO_CONN_TIMEOUT(4000)) + +/** + * @brief Recommended connection parameters for coexistence of ACL and ISO + * + * Defined by Table 8.3 in BAP 1.0.2 + */ +#define BT_BAP_CONN_PARAM_RELAXED \ + BT_LE_CONN_PARAM(BT_GAP_MS_TO_CONN_INTERVAL(50), BT_GAP_MS_TO_CONN_INTERVAL(70), 0, \ + BT_GAP_MS_TO_CONN_TIMEOUT(4000)) + +/** + * @brief Fast advertising parameters for broadcast audio + * + * This is suitable for both 7.5 ms and 10 ms SDU intervals, but prioritizes lower time to + * synchronize over coexistence with ISO and power consumption. + */ +#define BT_BAP_ADV_PARAM_BROADCAST_FAST \ + BT_LE_ADV_PARAM(BT_LE_ADV_OPT_EXT_ADV, BT_GAP_MS_TO_ADV_INTERVAL(60), \ + BT_GAP_MS_TO_ADV_INTERVAL(60), NULL) + +/** + * @brief Slow advertising parameters for broadcast audio + * + * This is suitable for both 7.5 ms and 10 ms SDU intervals, but prioritizes coexistence with ISO + * and power consumption over lower time to synchronize. + */ +#define BT_BAP_ADV_PARAM_BROADCAST_SLOW \ + BT_LE_ADV_PARAM(BT_LE_ADV_OPT_EXT_ADV, BT_GAP_MS_TO_ADV_INTERVAL(150), \ + BT_GAP_MS_TO_ADV_INTERVAL(150), NULL) + +/** + * @brief Fast advertising parameters for broadcast audio + * + * This is suitable for both 7.5 ms and 10 ms SDU intervals, but prioritizes lower time to + * synchronize over coexistence with ISO and power consumption. + */ +#define BT_BAP_PER_ADV_PARAM_BROADCAST_FAST \ + BT_LE_PER_ADV_PARAM(BT_GAP_MS_TO_PER_ADV_INTERVAL(60), BT_GAP_MS_TO_PER_ADV_INTERVAL(60), \ + BT_LE_PER_ADV_OPT_NONE) + +/** + * @brief Slow advertising parameters for broadcast audio + * + * This is suitable for both 7.5 ms and 10 ms SDU intervals, but prioritizes coexistence with ISO + * and power consumption over lower time to synchronize. + */ +#define BT_BAP_PER_ADV_PARAM_BROADCAST_SLOW \ + BT_LE_PER_ADV_PARAM(BT_GAP_MS_TO_PER_ADV_INTERVAL(150), \ + BT_GAP_MS_TO_PER_ADV_INTERVAL(150), BT_LE_PER_ADV_OPT_NONE) + /** * @brief Check if a BAP BASS BIS_Sync bitfield is valid * diff --git a/samples/bluetooth/bap_broadcast_assistant/src/main.c b/samples/bluetooth/bap_broadcast_assistant/src/main.c index 49b630d1dbb..a0471f2ee6f 100644 --- a/samples/bluetooth/bap_broadcast_assistant/src/main.c +++ b/samples/bluetooth/bap_broadcast_assistant/src/main.c @@ -383,8 +383,7 @@ static void scan_recv_cb(const struct bt_le_scan_recv_info *info, printk("Connecting to Broadcast Sink: %s\n", sr_info.bt_name); err = bt_conn_le_create(info->addr, BT_CONN_LE_CREATE_CONN, - BT_LE_CONN_PARAM_DEFAULT, - &broadcast_sink_conn); + BT_BAP_CONN_PARAM_RELAXED, &broadcast_sink_conn); if (err != 0) { printk("Failed creating connection (err=%u)\n", err); scan_for_broadcast_sink(); diff --git a/samples/bluetooth/bap_broadcast_sink/prj.conf b/samples/bluetooth/bap_broadcast_sink/prj.conf index 7c4c9595bab..c3780e12539 100644 --- a/samples/bluetooth/bap_broadcast_sink/prj.conf +++ b/samples/bluetooth/bap_broadcast_sink/prj.conf @@ -4,6 +4,12 @@ CONFIG_BT_AUDIO=y CONFIG_BT_SMP=y CONFIG_BT_PAC_SNK=y CONFIG_BT_PERIPHERAL=y +CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS=n +# Set preferred values based on BT_BAP_CONN_PARAM_RELAXED +CONFIG_BT_PERIPHERAL_PREF_MIN_INT=50 +CONFIG_BT_PERIPHERAL_PREF_MAX_INT=70 +CONFIG_BT_PERIPHERAL_PREF_LATENCY=0 +CONFIG_BT_PERIPHERAL_PREF_TIMEOUT=400 CONFIG_BT_OBSERVER=y CONFIG_BT_GATT_DYNAMIC_DB=y CONFIG_BT_EXT_ADV=y diff --git a/samples/bluetooth/bap_broadcast_sink/src/main.c b/samples/bluetooth/bap_broadcast_sink/src/main.c index e80da73d465..4c712703d3e 100644 --- a/samples/bluetooth/bap_broadcast_sink/src/main.c +++ b/samples/bluetooth/bap_broadcast_sink/src/main.c @@ -964,7 +964,7 @@ static int start_adv(void) int err; /* Create a connectable advertising set */ - err = bt_le_ext_adv_create(BT_LE_EXT_ADV_CONN, NULL, &ext_adv); + err = bt_le_ext_adv_create(BT_BAP_ADV_PARAM_CONN_REDUCED, NULL, &ext_adv); if (err != 0) { printk("Failed to create advertising set (err %d)\n", err); diff --git a/samples/bluetooth/bap_broadcast_source/src/main.c b/samples/bluetooth/bap_broadcast_source/src/main.c index ee8c0461307..fb2a1646410 100644 --- a/samples/bluetooth/bap_broadcast_source/src/main.c +++ b/samples/bluetooth/bap_broadcast_source/src/main.c @@ -34,20 +34,6 @@ BUILD_ASSERT(strlen(CONFIG_BROADCAST_CODE) <= BT_ISO_BROADCAST_CODE_SIZE, "Invalid broadcast code"); -/* Zephyr Controller works best while Extended Advertising interval to be a multiple - * of the ISO Interval minus 10 ms (max. advertising random delay). This is - * required to place the AUX_ADV_IND PDUs in a non-overlapping interval with the - * Broadcast ISO radio events. - * - * I.e. for a 7.5 ms ISO interval use 90 ms minus 10 ms ==> 80 ms advertising - * interval. - * And, for 10 ms ISO interval, can use 90 ms minus 10 ms ==> 80 ms advertising - * interval. - */ -#define BT_LE_EXT_ADV_CUSTOM \ - BT_LE_ADV_PARAM(BT_LE_ADV_OPT_EXT_ADV, BT_GAP_MS_TO_ADV_INTERVAL(80), \ - BT_GAP_MS_TO_ADV_INTERVAL(80), NULL) - /* When BROADCAST_ENQUEUE_COUNT > 1 we can enqueue enough buffers to ensure that * the controller is never idle */ @@ -576,14 +562,14 @@ int main(void) uint32_t broadcast_id; /* Create a connectable advertising set */ - err = bt_le_ext_adv_create(BT_LE_EXT_ADV_CUSTOM, NULL, &adv); + err = bt_le_ext_adv_create(BT_BAP_ADV_PARAM_BROADCAST_FAST, NULL, &adv); if (err != 0) { printk("Unable to create extended advertising set: %d\n", err); return 0; } /* Set periodic advertising parameters */ - err = bt_le_per_adv_set_param(adv, BT_LE_PER_ADV_DEFAULT); + err = bt_le_per_adv_set_param(adv, BT_BAP_PER_ADV_PARAM_BROADCAST_FAST); if (err) { printk("Failed to set periodic advertising parameters (err %d)\n", err); return 0; diff --git a/samples/bluetooth/bap_unicast_client/src/main.c b/samples/bluetooth/bap_unicast_client/src/main.c index 082b9fe7d52..fdc0ed249ff 100644 --- a/samples/bluetooth/bap_unicast_client/src/main.c +++ b/samples/bluetooth/bap_unicast_client/src/main.c @@ -162,8 +162,7 @@ static bool check_audio_support_and_connect(struct bt_data *data, printk("Audio server found with type %u, contexts 0x%08x and meta_len %u; connecting\n", announcement_type, audio_contexts, meta_len); - err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN, - BT_LE_CONN_PARAM_DEFAULT, + err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN, BT_BAP_CONN_PARAM_RELAXED, &default_conn); if (err != 0) { printk("Create conn to failed (%u)\n", err); diff --git a/samples/bluetooth/bap_unicast_server/prj.conf b/samples/bluetooth/bap_unicast_server/prj.conf index a102747bf04..103858af574 100644 --- a/samples/bluetooth/bap_unicast_server/prj.conf +++ b/samples/bluetooth/bap_unicast_server/prj.conf @@ -2,6 +2,12 @@ CONFIG_BT=y CONFIG_LOG=y CONFIG_BT_SMP=y CONFIG_BT_PERIPHERAL=y +CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS=n +# Set preferred values based on BT_BAP_CONN_PARAM_RELAXED +CONFIG_BT_PERIPHERAL_PREF_MIN_INT=50 +CONFIG_BT_PERIPHERAL_PREF_MAX_INT=70 +CONFIG_BT_PERIPHERAL_PREF_LATENCY=0 +CONFIG_BT_PERIPHERAL_PREF_TIMEOUT=400 CONFIG_BT_ISO_PERIPHERAL=y CONFIG_BT_AUDIO=y CONFIG_BT_GATT_DYNAMIC_DB=y diff --git a/samples/bluetooth/bap_unicast_server/src/main.c b/samples/bluetooth/bap_unicast_server/src/main.c index cc13491a77d..bdc56a1e4a7 100644 --- a/samples/bluetooth/bap_unicast_server/src/main.c +++ b/samples/bluetooth/bap_unicast_server/src/main.c @@ -778,7 +778,7 @@ int main(void) } /* Create a connectable advertising set */ - err = bt_le_ext_adv_create(BT_LE_EXT_ADV_CONN, NULL, &adv); + err = bt_le_ext_adv_create(BT_BAP_ADV_PARAM_CONN_QUICK, NULL, &adv); if (err) { printk("Failed to create advertising set (err %d)\n", err); return 0; diff --git a/samples/bluetooth/cap_acceptor/prj.conf b/samples/bluetooth/cap_acceptor/prj.conf index 816ed1dcc9a..b2f6b49d671 100644 --- a/samples/bluetooth/cap_acceptor/prj.conf +++ b/samples/bluetooth/cap_acceptor/prj.conf @@ -1,6 +1,12 @@ CONFIG_BT=y CONFIG_LOG=y CONFIG_BT_PERIPHERAL=y +CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS=n +# Set preferred values based on BT_BAP_CONN_PARAM_RELAXED +CONFIG_BT_PERIPHERAL_PREF_MIN_INT=50 +CONFIG_BT_PERIPHERAL_PREF_MAX_INT=70 +CONFIG_BT_PERIPHERAL_PREF_LATENCY=0 +CONFIG_BT_PERIPHERAL_PREF_TIMEOUT=400 CONFIG_BT_GATT_DYNAMIC_DB=y CONFIG_BT_GATT_CLIENT=y CONFIG_BT_EXT_ADV=y diff --git a/samples/bluetooth/cap_acceptor/src/main.c b/samples/bluetooth/cap_acceptor/src/main.c index d0bc49cd630..702bd074b32 100644 --- a/samples/bluetooth/cap_acceptor/src/main.c +++ b/samples/bluetooth/cap_acceptor/src/main.c @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -104,7 +105,7 @@ static int advertise(void) { int err; - err = bt_le_ext_adv_create(BT_LE_EXT_ADV_CONN, NULL, &adv); + err = bt_le_ext_adv_create(BT_BAP_ADV_PARAM_CONN_QUICK, NULL, &adv); if (err) { LOG_ERR("Failed to create advertising set: %d", err); diff --git a/samples/bluetooth/cap_initiator/src/cap_initiator_broadcast.c b/samples/bluetooth/cap_initiator/src/cap_initiator_broadcast.c index 7f2cbb1305a..55898056e75 100644 --- a/samples/bluetooth/cap_initiator/src/cap_initiator_broadcast.c +++ b/samples/bluetooth/cap_initiator/src/cap_initiator_broadcast.c @@ -73,16 +73,14 @@ static int setup_extended_adv(struct bt_le_ext_adv **adv) int err; /* Create a non-connectable non-scannable advertising set */ - err = bt_le_ext_adv_create(BT_LE_EXT_ADV_NCONN, NULL, adv); + err = bt_le_ext_adv_create(BT_BAP_ADV_PARAM_BROADCAST_FAST, NULL, adv); if (err != 0) { LOG_ERR("Unable to create extended advertising set: %d", err); return err; } /* Set periodic advertising parameters */ - err = bt_le_per_adv_set_param(*adv, BT_LE_PER_ADV_PARAM(BT_GAP_PER_ADV_FAST_INT_MIN_2, - BT_GAP_PER_ADV_FAST_INT_MAX_2, - BT_LE_PER_ADV_OPT_NONE)); + err = bt_le_per_adv_set_param(*adv, BT_BAP_PER_ADV_PARAM_BROADCAST_FAST); if (err != 0) { LOG_ERR("Failed to set periodic advertising parameters: %d", err); return err; diff --git a/samples/bluetooth/cap_initiator/src/cap_initiator_unicast.c b/samples/bluetooth/cap_initiator/src/cap_initiator_unicast.c index 25dba8cc16d..df45dfcadaa 100644 --- a/samples/bluetooth/cap_initiator/src/cap_initiator_unicast.c +++ b/samples/bluetooth/cap_initiator/src/cap_initiator_unicast.c @@ -599,7 +599,8 @@ static bool check_audio_support_and_connect_cb(struct bt_data *data, void *user_ return false; } - err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN, BT_LE_CONN_PARAM_DEFAULT, &peer.conn); + err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN, BT_BAP_CONN_PARAM_RELAXED, + &peer.conn); if (err != 0) { LOG_WRN("Create conn to failed: %d, restarting scan", err); start_scan(); diff --git a/samples/bluetooth/hap_ha/prj.conf b/samples/bluetooth/hap_ha/prj.conf index 8260f2cb12a..964280e8d94 100644 --- a/samples/bluetooth/hap_ha/prj.conf +++ b/samples/bluetooth/hap_ha/prj.conf @@ -1,5 +1,11 @@ CONFIG_BT=y CONFIG_BT_PERIPHERAL=y +CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS=n +# Set preferred values based on BT_BAP_CONN_PARAM_RELAXED +CONFIG_BT_PERIPHERAL_PREF_MIN_INT=50 +CONFIG_BT_PERIPHERAL_PREF_MAX_INT=70 +CONFIG_BT_PERIPHERAL_PREF_LATENCY=0 +CONFIG_BT_PERIPHERAL_PREF_TIMEOUT=400 CONFIG_BT_ISO_PERIPHERAL=y CONFIG_BT_PRIVACY=y CONFIG_BT_GATT_DYNAMIC_DB=y diff --git a/samples/bluetooth/hap_ha/src/main.c b/samples/bluetooth/hap_ha/src/main.c index 6053ccf0d6d..0822ef95abd 100644 --- a/samples/bluetooth/hap_ha/src/main.c +++ b/samples/bluetooth/hap_ha/src/main.c @@ -107,7 +107,7 @@ static void adv_work_handler(struct k_work *work) if (ext_adv == NULL) { /* Create a connectable advertising set */ - err = bt_le_ext_adv_create(BT_LE_EXT_ADV_CONN, &adv_cb, &ext_adv); + err = bt_le_ext_adv_create(BT_BAP_ADV_PARAM_CONN_QUICK, &adv_cb, &ext_adv); if (err) { printk("Failed to create advertising set (err %d)\n", err); } diff --git a/samples/bluetooth/pbp_public_broadcast_source/src/main.c b/samples/bluetooth/pbp_public_broadcast_source/src/main.c index b996889190c..2f97db69220 100644 --- a/samples/bluetooth/pbp_public_broadcast_source/src/main.c +++ b/samples/bluetooth/pbp_public_broadcast_source/src/main.c @@ -150,7 +150,7 @@ static int setup_extended_adv(struct bt_le_ext_adv **adv) int err; /* Create a non-connectable advertising set */ - err = bt_le_ext_adv_create(BT_LE_EXT_ADV_NCONN, NULL, adv); + err = bt_le_ext_adv_create(BT_BAP_ADV_PARAM_BROADCAST_FAST, NULL, adv); if (err != 0) { printk("Unable to create extended advertising set: %d\n", err); @@ -166,7 +166,7 @@ static int setup_extended_adv(struct bt_le_ext_adv **adv) } /* Set periodic advertising parameters */ - err = bt_le_per_adv_set_param(*adv, BT_LE_PER_ADV_DEFAULT); + err = bt_le_per_adv_set_param(*adv, BT_BAP_PER_ADV_PARAM_BROADCAST_FAST); if (err) { printk("Failed to set periodic advertising parameters: %d\n", err); diff --git a/samples/bluetooth/tmap_bms/src/cap_initiator.c b/samples/bluetooth/tmap_bms/src/cap_initiator.c index 0a81a3026cd..c8b701d62a7 100644 --- a/samples/bluetooth/tmap_bms/src/cap_initiator.c +++ b/samples/bluetooth/tmap_bms/src/cap_initiator.c @@ -137,7 +137,7 @@ static int setup_extended_adv(struct bt_le_ext_adv **adv) int err; /* Create a non-connectable advertising set */ - err = bt_le_ext_adv_create(BT_LE_EXT_ADV_NCONN, NULL, adv); + err = bt_le_ext_adv_create(BT_BAP_ADV_PARAM_BROADCAST_FAST, NULL, adv); if (err != 0) { printk("Unable to create extended advertising set: %d\n", err); return err; @@ -151,7 +151,7 @@ static int setup_extended_adv(struct bt_le_ext_adv **adv) } /* Set periodic advertising parameters */ - err = bt_le_per_adv_set_param(*adv, BT_LE_PER_ADV_DEFAULT); + err = bt_le_per_adv_set_param(*adv, BT_BAP_PER_ADV_PARAM_BROADCAST_FAST); if (err) { printk("Failed to set periodic advertising parameters: %d\n", err); diff --git a/samples/bluetooth/tmap_central/src/main.c b/samples/bluetooth/tmap_central/src/main.c index 4c47e232bc0..a4f426f9276 100644 --- a/samples/bluetooth/tmap_central/src/main.c +++ b/samples/bluetooth/tmap_central/src/main.c @@ -188,8 +188,7 @@ static bool check_audio_support_and_connect(struct bt_data *data, void *user_dat return false; } - err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN, - BT_LE_CONN_PARAM_DEFAULT, + err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN, BT_BAP_CONN_PARAM_RELAXED, &default_conn); if (err != 0) { printk("Create conn to failed (%u)\n", err); diff --git a/samples/bluetooth/tmap_peripheral/prj.conf b/samples/bluetooth/tmap_peripheral/prj.conf index cf40172576a..837e3d4807f 100644 --- a/samples/bluetooth/tmap_peripheral/prj.conf +++ b/samples/bluetooth/tmap_peripheral/prj.conf @@ -1,6 +1,12 @@ CONFIG_BT=y CONFIG_LOG=y CONFIG_BT_PERIPHERAL=y +CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS=n +# Set preferred values based on BT_BAP_CONN_PARAM_RELAXED +CONFIG_BT_PERIPHERAL_PREF_MIN_INT=50 +CONFIG_BT_PERIPHERAL_PREF_MAX_INT=70 +CONFIG_BT_PERIPHERAL_PREF_LATENCY=0 +CONFIG_BT_PERIPHERAL_PREF_TIMEOUT=400 CONFIG_BT_ISO_PERIPHERAL=y CONFIG_BT_GATT_CLIENT=y CONFIG_BT_GATT_AUTO_DISCOVER_CCC=y diff --git a/samples/bluetooth/tmap_peripheral/src/main.c b/samples/bluetooth/tmap_peripheral/src/main.c index 30a1855493f..f26d65767f9 100644 --- a/samples/bluetooth/tmap_peripheral/src/main.c +++ b/samples/bluetooth/tmap_peripheral/src/main.c @@ -252,7 +252,7 @@ int main(void) } printk("BAP initialized\n"); - err = bt_le_ext_adv_create(BT_LE_EXT_ADV_CONN, &adv_cb, &adv); + err = bt_le_ext_adv_create(BT_BAP_ADV_PARAM_CONN_QUICK, &adv_cb, &adv); if (err) { printk("Failed to create advertising set (err %d)\n", err); return err; diff --git a/subsys/bluetooth/host/shell/bt.c b/subsys/bluetooth/host/shell/bt.c index 858d999ff95..97ca1e0344d 100644 --- a/subsys/bluetooth/host/shell/bt.c +++ b/subsys/bluetooth/host/shell/bt.c @@ -12,6 +12,9 @@ */ #include +#include +#include +#include #include #include #include @@ -3238,11 +3241,18 @@ static int cmd_subrate_request(const struct shell *sh, size_t argc, char *argv[] #if defined(CONFIG_BT_CENTRAL) static int bt_do_connect_le(int *ercd, size_t argc, char *argv[]) { + struct bt_le_conn_param conn_param; int err; bt_addr_le_t addr; struct bt_conn *conn = NULL; uint32_t options = 0; + if (IS_ENABLED(CONFIG_BT_BAP_UNICAST) || IS_ENABLED(CONFIG_BT_BAP_BROADCAST_ASSISTANT)) { + conn_param = *BT_BAP_CONN_PARAM_RELAXED; + } else { + conn_param = *BT_LE_CONN_PARAM_DEFAULT; + } + *ercd = 0; /* When no arguments are specified, connect to the last scanned device. */ @@ -3279,7 +3289,7 @@ static int bt_do_connect_le(int *ercd, size_t argc, char *argv[]) BT_GAP_SCAN_FAST_INTERVAL, BT_GAP_SCAN_FAST_INTERVAL); - err = bt_conn_le_create(&addr, create_params, BT_LE_CONN_PARAM_DEFAULT, &conn); + err = bt_conn_le_create(&addr, create_params, &conn_param, &conn); if (err) { *ercd = err; return -ENOEXEC; diff --git a/tests/bluetooth/shell/audio.conf b/tests/bluetooth/shell/audio.conf index 219653cdd28..013ab6a0ad1 100644 --- a/tests/bluetooth/shell/audio.conf +++ b/tests/bluetooth/shell/audio.conf @@ -40,7 +40,6 @@ CONFIG_BT_KEYS_OVERWRITE_OLDEST=y CONFIG_BT_L2CAP_TX_MTU=128 CONFIG_BT_BUF_ACL_RX_SIZE=255 CONFIG_BT_BUF_ACL_TX_SIZE=251 - CONFIG_BT_SETTINGS=y CONFIG_FLASH=y CONFIG_FLASH_MAP=y @@ -53,6 +52,13 @@ CONFIG_BT_AUTO_DATA_LEN_UPDATE=y CONFIG_BT_USER_PHY_UPDATE=y CONFIG_BT_AUTO_PHY_UPDATE=y +CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS=n +# Set preferred values based on BT_BAP_CONN_PARAM_RELAXED +CONFIG_BT_PERIPHERAL_PREF_MIN_INT=50 +CONFIG_BT_PERIPHERAL_PREF_MAX_INT=70 +CONFIG_BT_PERIPHERAL_PREF_LATENCY=0 +CONFIG_BT_PERIPHERAL_PREF_TIMEOUT=400 + CONFIG_BT_PER_ADV_SYNC_TRANSFER_RECEIVER=y CONFIG_BT_PER_ADV_SYNC_TRANSFER_SENDER=y diff --git a/tests/bluetooth/tester/overlay-le-audio.conf b/tests/bluetooth/tester/overlay-le-audio.conf index be5004d49e4..4b18c651be2 100644 --- a/tests/bluetooth/tester/overlay-le-audio.conf +++ b/tests/bluetooth/tester/overlay-le-audio.conf @@ -1,5 +1,11 @@ CONFIG_BT_AUDIO=y CONFIG_BT_PERIPHERAL=y +CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS=n +# Set preferred values based on BT_BAP_CONN_PARAM_RELAXED +CONFIG_BT_PERIPHERAL_PREF_MIN_INT=50 +CONFIG_BT_PERIPHERAL_PREF_MAX_INT=70 +CONFIG_BT_PERIPHERAL_PREF_LATENCY=0 +CONFIG_BT_PERIPHERAL_PREF_TIMEOUT=400 CONFIG_BT_CENTRAL=y CONFIG_BT_GATT_CLIENT=y CONFIG_BT_GATT_DYNAMIC_DB=y diff --git a/tests/bluetooth/tester/src/audio/btp_bap_broadcast.c b/tests/bluetooth/tester/src/audio/btp_bap_broadcast.c index e0e942b17b5..37881fb697c 100644 --- a/tests/bluetooth/tester/src/audio/btp_bap_broadcast.c +++ b/tests/bluetooth/tester/src/audio/btp_bap_broadcast.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include "bap_endpoint.h" @@ -368,17 +369,8 @@ static int setup_broadcast_source(uint8_t streams_per_subgroup, uint8_t subgroup uint8_t btp_bap_broadcast_source_setup(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { - struct bt_le_per_adv_param per_adv_param = - *BT_LE_PER_ADV_PARAM(BT_GAP_MS_TO_PER_ADV_INTERVAL(150), - BT_GAP_MS_TO_PER_ADV_INTERVAL(150), BT_LE_PER_ADV_OPT_NONE); - /* Zephyr Controller works best while Extended Advertising interval is a multiple - * of the ISO Interval minus 10 ms (max. advertising random delay). This is - * required to place the AUX_ADV_IND PDUs in a non-overlapping interval with the - * Broadcast ISO radio events. - */ - struct bt_le_adv_param ext_adv_param = - *BT_LE_ADV_PARAM(BT_LE_ADV_OPT_EXT_ADV, BT_GAP_MS_TO_ADV_INTERVAL(140), - BT_GAP_MS_TO_ADV_INTERVAL(140), NULL); + struct bt_le_per_adv_param per_adv_param = *BT_BAP_PER_ADV_PARAM_BROADCAST_SLOW; + struct bt_le_adv_param ext_adv_param = *BT_BAP_ADV_PARAM_BROADCAST_SLOW; int err; struct bt_audio_codec_cfg codec_cfg; const struct btp_bap_broadcast_source_setup_cmd *cp = cmd; @@ -405,6 +397,14 @@ uint8_t btp_bap_broadcast_source_setup(const void *cmd, uint16_t cmd_len, LOG_DBG(""); + /* Zephyr Controller works best while Extended Advertising interval is a multiple + * of the ISO Interval minus 10 ms (max. advertising random delay). This is + * required to place the AUX_ADV_IND PDUs in a non-overlapping interval with the + * Broadcast ISO radio events. + */ + ext_adv_param.interval_min -= BT_GAP_MS_TO_ADV_INTERVAL(10U); + ext_adv_param.interval_max -= BT_GAP_MS_TO_ADV_INTERVAL(10U); + memset(&codec_cfg, 0, sizeof(codec_cfg)); codec_cfg.id = cp->coding_format; codec_cfg.vid = cp->vid; diff --git a/tests/bluetooth/tester/src/btp_gap.c b/tests/bluetooth/tester/src/btp_gap.c index 547400d912c..bbd41e91092 100644 --- a/tests/bluetooth/tester/src/btp_gap.c +++ b/tests/bluetooth/tester/src/btp_gap.c @@ -7,9 +7,11 @@ */ #include +#include #include #include #include +#include #include #include @@ -1060,20 +1062,21 @@ static uint8_t stop_discovery(const void *cmd, uint16_t cmd_len, static uint8_t connect(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { - /* The conn interval is set to 60ms (0x30). This is to better support test cases where we - * need to connect to multiple peripherals (up to 3). The connection interval should also be - * a multiple of 30ms, as that is ideal to support both 7.5ms and 10ms ISO intervals - */ - const uint16_t interval = BT_GAP_MS_TO_CONN_INTERVAL(60U); - const struct bt_le_conn_param *conn_param = - BT_LE_CONN_PARAM(interval, interval, 0U, BT_GAP_MS_TO_CONN_TIMEOUT(4000U)); + struct bt_le_conn_param conn_param; + + if (IS_ENABLED(CONFIG_BT_BAP_UNICAST) || IS_ENABLED(CONFIG_BT_BAP_BROADCAST_ASSISTANT)) { + conn_param = *BT_BAP_CONN_PARAM_RELAXED; + } else { + conn_param = *BT_LE_CONN_PARAM_DEFAULT; + } + const struct btp_gap_connect_cmd *cp = cmd; int err; if (!bt_addr_le_eq(&cp->address, BT_ADDR_LE_ANY)) { struct bt_conn *conn = NULL; - err = bt_conn_le_create(&cp->address, BT_CONN_LE_CREATE_CONN, conn_param, &conn); + err = bt_conn_le_create(&cp->address, BT_CONN_LE_CREATE_CONN, &conn_param, &conn); if (err) { LOG_ERR("Failed to create connection (%d)", err); return BTP_STATUS_FAILED; @@ -1081,7 +1084,7 @@ static uint8_t connect(const void *cmd, uint16_t cmd_len, bt_conn_unref(conn); } else { - err = bt_conn_le_create_auto(BT_CONN_LE_CREATE_CONN, conn_param); + err = bt_conn_le_create_auto(BT_CONN_LE_CREATE_CONN, &conn_param); if (err) { LOG_ERR("Failed to create auto connection (%d)", err); return BTP_STATUS_FAILED; diff --git a/tests/bsim/bluetooth/audio/prj.conf b/tests/bsim/bluetooth/audio/prj.conf index 3a54daf157f..db010240a66 100644 --- a/tests/bsim/bluetooth/audio/prj.conf +++ b/tests/bsim/bluetooth/audio/prj.conf @@ -54,6 +54,11 @@ CONFIG_BT_ISO_RX_MTU=310 CONFIG_BT_ISO_RX_BUF_COUNT=4 CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS=n +# Set preferred values based on BT_BAP_CONN_PARAM_RELAXED +CONFIG_BT_PERIPHERAL_PREF_MIN_INT=50 +CONFIG_BT_PERIPHERAL_PREF_MAX_INT=70 +CONFIG_BT_PERIPHERAL_PREF_LATENCY=0 +CONFIG_BT_PERIPHERAL_PREF_TIMEOUT=400 # Needed for Periodic Advertising Sync Transfer CONFIG_BT_PER_ADV_SYNC_TRANSFER_RECEIVER=y diff --git a/tests/bsim/bluetooth/audio/src/bap_bass_broadcaster_test.c b/tests/bsim/bluetooth/audio/src/bap_bass_broadcaster_test.c index 68894d7a320..fb1da4e6904 100644 --- a/tests/bsim/bluetooth/audio/src/bap_bass_broadcaster_test.c +++ b/tests/bsim/bluetooth/audio/src/bap_bass_broadcaster_test.c @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -29,8 +30,7 @@ static void test_main(void) struct bt_le_ext_adv *adv; struct bt_data ad[2] = { BT_DATA_BYTES(BT_DATA_FLAGS, BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR), - BT_DATA_BYTES(BT_DATA_SVC_DATA16, - BT_UUID_16_ENCODE(BT_UUID_BROADCAST_AUDIO_VAL), + BT_DATA_BYTES(BT_DATA_SVC_DATA16, BT_UUID_16_ENCODE(BT_UUID_BROADCAST_AUDIO_VAL), BT_BYTES_LIST_LE24(broadcast_id)), }; @@ -42,19 +42,7 @@ static void test_main(void) printk("Bluetooth initialized\n"); - /* Create a non-connectable advertising set */ - err = bt_le_ext_adv_create(BT_LE_EXT_ADV_NCONN, NULL, &adv); - if (err) { - FAIL("Failed to create advertising set (err %d)\n", err); - return; - } - - /* Set periodic advertising parameters */ - err = bt_le_per_adv_set_param(adv, BT_LE_PER_ADV_DEFAULT); - if (err) { - FAIL("Failed to set periodic advertising parameters (err %d)\n", err); - return; - } + setup_broadcast_adv(&adv); /* Set adv data */ err = bt_le_ext_adv_set_data(adv, ad, ARRAY_SIZE(ad), NULL, 0); diff --git a/tests/bsim/bluetooth/audio/src/bap_broadcast_assistant_test.c b/tests/bsim/bluetooth/audio/src/bap_broadcast_assistant_test.c index 430ab7f950a..bb8f44c5b90 100644 --- a/tests/bsim/bluetooth/audio/src/bap_broadcast_assistant_test.c +++ b/tests/bsim/bluetooth/audio/src/bap_broadcast_assistant_test.c @@ -4,6 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include #include #include #include @@ -27,6 +28,7 @@ #include "common.h" #include "bap_common.h" #include "bstests.h" +#include "syscalls/kernel.h" #ifdef CONFIG_BT_BAP_BROADCAST_ASSISTANT @@ -517,9 +519,12 @@ static void test_bass_mod_source(uint32_t bis_sync) FAIL("Could not modify source (err %d)\n", err); return; } - printk("Source modified, waiting for server to PA sync\n"); - WAIT_FOR_AND_CLEAR_FLAG(flag_recv_state_updated); + if (recv_state.pa_sync_state == BT_BAP_PA_STATE_NOT_SYNCED) { + printk("Source modified, waiting for server to PA sync\n"); + + WAIT_FOR_AND_CLEAR_FLAG(flag_recv_state_updated); + } if (recv_state.pa_sync_state == BT_BAP_PA_STATE_INFO_REQ) { /* Wait for PAST to finish and then a new receive state */ @@ -579,10 +584,13 @@ static void test_bass_mod_source(uint32_t bis_sync) FAIL("Unexpected BIS sync value: %u", remote_bis_sync); return; } - } else if (remote_bis_sync != subgroup.bis_sync) { - FAIL("Unexpected BIS sync value: %u != %u\n", remote_bis_sync, - subgroup.bis_sync); - return; + } else { + WAIT_FOR_FLAG(flag_recv_state_updated_with_bis_sync); + if (remote_bis_sync != subgroup.bis_sync) { + FAIL("Unexpected BIS sync value: %u != %u\n", remote_bis_sync, + subgroup.bis_sync); + return; + } } } @@ -659,12 +667,17 @@ static void test_bass_broadcast_code(const uint8_t broadcast_code[BT_ISO_BROADCA printk("Adding broadcast code\n"); UNSET_FLAG(flag_write_complete); - err = bt_bap_broadcast_assistant_set_broadcast_code(default_conn, recv_state.src_id, - broadcast_code); - if (err != 0) { - FAIL("Could not add broadcast code (err %d)\n", err); - return; - } + + do { + err = bt_bap_broadcast_assistant_set_broadcast_code(default_conn, recv_state.src_id, + broadcast_code); + if (err == -EBUSY) { + k_sleep(BAP_RETRY_WAIT); + } else if (err != 0) { + FAIL("Could not add broadcast code (err %d)\n", err); + return; + } + } while (err == -EBUSY); WAIT_FOR_FLAG(flag_write_complete); printk("Broadcast code added\n"); diff --git a/tests/bsim/bluetooth/audio/src/bap_broadcast_source_test.c b/tests/bsim/bluetooth/audio/src/bap_broadcast_source_test.c index 4880271aa53..792161bdadb 100644 --- a/tests/bsim/bluetooth/audio/src/bap_broadcast_source_test.c +++ b/tests/bsim/bluetooth/audio/src/bap_broadcast_source_test.c @@ -336,30 +336,14 @@ static void test_broadcast_source_get_base(struct bt_bap_broadcast_source *sourc static int setup_extended_adv(struct bt_bap_broadcast_source *source, struct bt_le_ext_adv **adv) { /* Broadcast Audio Streaming Endpoint advertising data */ - NET_BUF_SIMPLE_DEFINE(ad_buf, - BT_UUID_SIZE_16 + BT_AUDIO_BROADCAST_ID_SIZE); - struct bt_le_adv_param adv_param = BT_LE_ADV_PARAM_INIT( - BT_LE_ADV_OPT_EXT_ADV, 0x80, 0x80, NULL); + NET_BUF_SIMPLE_DEFINE(ad_buf, BT_UUID_SIZE_16 + BT_AUDIO_BROADCAST_ID_SIZE); NET_BUF_SIMPLE_DEFINE(base_buf, 128); struct bt_data ext_ad; struct bt_data per_ad; uint32_t broadcast_id; int err; - /* Create a non-connectable advertising set */ - err = bt_le_ext_adv_create(&adv_param, NULL, adv); - if (err != 0) { - printk("Unable to create extended advertising set: %d\n", err); - return err; - } - - /* Set periodic advertising parameters */ - err = bt_le_per_adv_set_param(*adv, BT_LE_PER_ADV_DEFAULT); - if (err) { - printk("Failed to set periodic advertising parameters: %d\n", - err); - return err; - } + setup_broadcast_adv(adv); err = bt_rand(&broadcast_id, BT_AUDIO_BROADCAST_ID_SIZE); if (err) { diff --git a/tests/bsim/bluetooth/audio/src/bap_common.h b/tests/bsim/bluetooth/audio/src/bap_common.h index 01316dcf3e2..3c250e3cef7 100644 --- a/tests/bsim/bluetooth/audio/src/bap_common.h +++ b/tests/bsim/bluetooth/audio/src/bap_common.h @@ -18,6 +18,7 @@ #include #include #include +#include #define LONG_META 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, \ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, \ @@ -45,6 +46,9 @@ #define INCORRECT_BROADCAST_CODE \ ((uint8_t[]){0xDE, 0xAD, 0xBE, 0xEF, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, \ 0xdd, 0xee, 0xff}) + +#define BAP_RETRY_WAIT K_MSEC(100) + struct unicast_stream { struct bt_cap_stream stream; struct bt_audio_codec_cfg codec_cfg; diff --git a/tests/bsim/bluetooth/audio/src/bap_unicast_client_test.c b/tests/bsim/bluetooth/audio/src/bap_unicast_client_test.c index 6563185249e..a00dff69e4b 100644 --- a/tests/bsim/bluetooth/audio/src/bap_unicast_client_test.c +++ b/tests/bsim/bluetooth/audio/src/bap_unicast_client_test.c @@ -37,8 +37,6 @@ #if defined(CONFIG_BT_BAP_UNICAST_CLIENT) -#define BAP_STREAM_RETRY_WAIT K_MSEC(100) - extern enum bst_result_t bst_result; static struct audio_test_stream test_streams[CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT]; @@ -426,7 +424,7 @@ static bool parse_ascs_ad_data(struct bt_data *data, void *user_data) return false; } - err = bt_conn_le_create(info->addr, BT_CONN_LE_CREATE_CONN, BT_LE_CONN_PARAM_DEFAULT, + err = bt_conn_le_create(info->addr, BT_CONN_LE_CREATE_CONN, BT_BAP_CONN_PARAM_RELAXED, &default_conn); if (err) { FAIL("Could not connect to peer: %d", err); @@ -582,7 +580,7 @@ static int codec_configure_stream(struct bt_bap_stream *stream, struct bt_bap_ep err = bt_bap_stream_config(default_conn, stream, ep, codec_cfg); if (err == -EBUSY) { - k_sleep(BAP_STREAM_RETRY_WAIT); + k_sleep(BAP_RETRY_WAIT); } else if (err != 0) { FAIL("Could not configure stream %p: %d\n", stream, err); return err; @@ -632,7 +630,7 @@ static void qos_configure_streams(struct bt_bap_unicast_group *unicast_group, do { err = bt_bap_stream_qos(default_conn, unicast_group); if (err == -EBUSY) { - k_sleep(BAP_STREAM_RETRY_WAIT); + k_sleep(BAP_RETRY_WAIT); } else if (err != 0) { FAIL("Unable to QoS configure streams: %d\n", err); return; @@ -653,7 +651,7 @@ static int enable_stream(struct bt_bap_stream *stream) do { err = bt_bap_stream_enable(stream, NULL, 0); if (err == -EBUSY) { - k_sleep(BAP_STREAM_RETRY_WAIT); + k_sleep(BAP_RETRY_WAIT); } else if (err != 0) { FAIL("Could not enable stream %p: %d\n", stream, err); return err; @@ -692,7 +690,7 @@ static int metadata_update_stream(struct bt_bap_stream *stream) do { err = bt_bap_stream_metadata(stream, new_meta, ARRAY_SIZE(new_meta)); if (err == -EBUSY) { - k_sleep(BAP_STREAM_RETRY_WAIT); + k_sleep(BAP_RETRY_WAIT); } else if (err != 0) { FAIL("Could not metadata update stream %p: %d\n", stream, err); return err; @@ -786,7 +784,7 @@ static int start_stream(struct bt_bap_stream *stream) do { err = bt_bap_stream_start(stream); if (err == -EBUSY) { - k_sleep(BAP_STREAM_RETRY_WAIT); + k_sleep(BAP_RETRY_WAIT); } else if (err != 0) { FAIL("Could not start stream %p: %d\n", stream, err); return err; @@ -851,7 +849,7 @@ static void disable_streams(size_t stream_cnt) err = bt_bap_stream_disable( bap_stream_from_audio_test_stream(&test_streams[i])); if (err == -EBUSY) { - k_sleep(BAP_STREAM_RETRY_WAIT); + k_sleep(BAP_RETRY_WAIT); } else if (err != 0) { FAIL("Could not disable stream: %d\n", err); return; @@ -885,7 +883,7 @@ static void stop_streams(size_t stream_cnt) do { err = bt_bap_stream_stop(source_stream); if (err == -EBUSY) { - k_sleep(BAP_STREAM_RETRY_WAIT); + k_sleep(BAP_RETRY_WAIT); } else if (err != 0) { FAIL("Could not stop stream: %d\n", err); return; @@ -911,7 +909,7 @@ static void release_streams(size_t stream_cnt) err = bt_bap_stream_release( bap_stream_from_audio_test_stream(&test_streams[i])); if (err == -EBUSY) { - k_sleep(BAP_STREAM_RETRY_WAIT); + k_sleep(BAP_RETRY_WAIT); } else if (err != 0) { FAIL("Could not release stream: %d\n", err); return; diff --git a/tests/bsim/bluetooth/audio/src/cap_acceptor_test.c b/tests/bsim/bluetooth/audio/src/cap_acceptor_test.c index cc9a50aa6cb..b2126c340d0 100644 --- a/tests/bsim/bluetooth/audio/src/cap_acceptor_test.c +++ b/tests/bsim/bluetooth/audio/src/cap_acceptor_test.c @@ -40,17 +40,6 @@ #include "bap_common.h" #if defined(CONFIG_BT_CAP_ACCEPTOR) -/* Zephyr Controller works best while Extended Advertising interval to be a multiple - * of the ISO Interval minus 10 ms (max. advertising random delay). This is - * required to place the AUX_ADV_IND PDUs in a non-overlapping interval with the - * Broadcast ISO radio events. - */ -#define BT_LE_EXT_ADV_CONN_CUSTOM \ - BT_LE_ADV_PARAM(BT_LE_ADV_OPT_EXT_ADV | BT_LE_ADV_OPT_CONN, \ - BT_GAP_MS_TO_ADV_INTERVAL(140), \ - BT_GAP_MS_TO_ADV_INTERVAL(140), \ - NULL) - extern enum bst_result_t bst_result; CREATE_FLAG(flag_broadcaster_found); diff --git a/tests/bsim/bluetooth/audio/src/cap_commander_test.c b/tests/bsim/bluetooth/audio/src/cap_commander_test.c index 2fb1ff20097..b4c6d8c167c 100644 --- a/tests/bsim/bluetooth/audio/src/cap_commander_test.c +++ b/tests/bsim/bluetooth/audio/src/cap_commander_test.c @@ -586,9 +586,7 @@ static bool check_audio_support_and_connect_cb(struct bt_data *data, void *user_ return false; } - err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN, - BT_LE_CONN_PARAM(BT_GAP_INIT_CONN_INT_MIN, BT_GAP_INIT_CONN_INT_MIN, - 0, BT_GAP_MS_TO_CONN_TIMEOUT(4000)), + err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN, BT_BAP_CONN_PARAM_RELAXED, &connected_conns[connected_conn_cnt]); if (err != 0) { FAIL("Could not connect to peer: %d", err); diff --git a/tests/bsim/bluetooth/audio/src/cap_initiator_broadcast_test.c b/tests/bsim/bluetooth/audio/src/cap_initiator_broadcast_test.c index e2cc727a44d..4231110ae4d 100644 --- a/tests/bsim/bluetooth/audio/src/cap_initiator_broadcast_test.c +++ b/tests/bsim/bluetooth/audio/src/cap_initiator_broadcast_test.c @@ -37,19 +37,6 @@ #if defined(CONFIG_BT_CAP_INITIATOR) && defined(CONFIG_BT_BAP_BROADCAST_SOURCE) CREATE_FLAG(flag_source_started); -/* Zephyr Controller works best while Extended Advertising interval to be a multiple - * of the ISO Interval minus 10 ms (max. advertising random delay). This is - * required to place the AUX_ADV_IND PDUs in a non-overlapping interval with the - * Broadcast ISO radio events. - */ -#define BT_LE_EXT_ADV_CUSTOM \ - BT_LE_ADV_PARAM(BT_LE_ADV_OPT_EXT_ADV, BT_GAP_MS_TO_ADV_INTERVAL(140), \ - BT_GAP_MS_TO_ADV_INTERVAL(140), NULL) - -#define BT_LE_PER_ADV_CUSTOM \ - BT_LE_PER_ADV_PARAM(BT_GAP_MS_TO_PER_ADV_INTERVAL(150), \ - BT_GAP_MS_TO_PER_ADV_INTERVAL(150), BT_LE_PER_ADV_OPT_NONE) - #define BROADCAST_STREMT_CNT CONFIG_BT_BAP_BROADCAST_SRC_STREAM_COUNT #define CAP_AC_MAX_STREAM 2 #define LOCATION (BT_AUDIO_LOCATION_FRONT_LEFT | BT_AUDIO_LOCATION_FRONT_RIGHT) @@ -215,25 +202,6 @@ static void init(void) } } -static void setup_extended_adv(struct bt_le_ext_adv **adv) -{ - int err; - - /* Create a non-connectable advertising set */ - err = bt_le_ext_adv_create(BT_LE_EXT_ADV_CUSTOM, NULL, adv); - if (err != 0) { - FAIL("Unable to create extended advertising set: %d\n", err); - return; - } - - /* Set periodic advertising parameters */ - err = bt_le_per_adv_set_param(*adv, BT_LE_PER_ADV_CUSTOM); - if (err) { - FAIL("Failed to set periodic advertising parameters: %d\n", err); - return; - } -} - static void setup_extended_adv_data(struct bt_cap_broadcast_source *source, struct bt_le_ext_adv *adv) { @@ -654,7 +622,7 @@ static void test_main_cap_initiator_broadcast(void) init(); - setup_extended_adv(&adv); + setup_broadcast_adv(&adv); test_broadcast_audio_create_inval(); test_broadcast_audio_create(&broadcast_source); @@ -744,7 +712,7 @@ static int test_cap_initiator_ac(const struct cap_initiator_ac_param *param) create_param.qos = &qos; init(); - setup_extended_adv(&adv); + setup_broadcast_adv(&adv); err = bt_cap_initiator_broadcast_audio_create(&create_param, &broadcast_source); if (err != 0) { diff --git a/tests/bsim/bluetooth/audio/src/cap_initiator_unicast_test.c b/tests/bsim/bluetooth/audio/src/cap_initiator_unicast_test.c index 1c6b44e80ba..fdf6eb909ab 100644 --- a/tests/bsim/bluetooth/audio/src/cap_initiator_unicast_test.c +++ b/tests/bsim/bluetooth/audio/src/cap_initiator_unicast_test.c @@ -402,9 +402,7 @@ static bool check_audio_support_and_connect_cb(struct bt_data *data, void *user_ return false; } - err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN, - BT_LE_CONN_PARAM(BT_GAP_INIT_CONN_INT_MIN, BT_GAP_INIT_CONN_INT_MIN, - 0, BT_GAP_MS_TO_CONN_TIMEOUT(4000)), + err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN, BT_BAP_CONN_PARAM_RELAXED, &connected_conns[connected_conn_cnt]); if (err != 0) { FAIL("Could not connect to peer: %d", err); diff --git a/tests/bsim/bluetooth/audio/src/common.c b/tests/bsim/bluetooth/audio/src/common.c index c5781576bc7..2c23a083624 100644 --- a/tests/bsim/bluetooth/audio/src/common.c +++ b/tests/bsim/bluetooth/audio/src/common.c @@ -107,7 +107,7 @@ static void device_found(const struct bt_le_scan_recv_info *info, struct net_buf return; } - err = bt_conn_le_create(info->addr, BT_CONN_LE_CREATE_CONN, BT_LE_CONN_PARAM_DEFAULT, + err = bt_conn_le_create(info->addr, BT_CONN_LE_CREATE_CONN, BT_BAP_CONN_PARAM_RELAXED, &default_conn); if (err) { FAIL("Could not connect to peer: %d", err); @@ -186,12 +186,13 @@ BT_CONN_CB_DEFINE(conn_callbacks) = { .security_changed = security_changed_cb, }; + void setup_connectable_adv(struct bt_le_ext_adv **ext_adv) { int err; /* Create a non-connectable advertising set */ - err = bt_le_ext_adv_create(BT_LE_EXT_ADV_CONN, NULL, ext_adv); + err = bt_le_ext_adv_create(BT_BAP_ADV_PARAM_CONN_QUICK, NULL, ext_adv); if (err != 0) { FAIL("Unable to create extended advertising set: %d\n", err); return; @@ -218,6 +219,34 @@ void setup_connectable_adv(struct bt_le_ext_adv **ext_adv) printk("Advertising started\n"); } +void setup_broadcast_adv(struct bt_le_ext_adv **adv) +{ + struct bt_le_adv_param ext_adv_param = *BT_BAP_ADV_PARAM_BROADCAST_SLOW; + int err; + + /* Zephyr Controller works best while Extended Advertising interval is a multiple + * of the ISO Interval minus 10 ms (max. advertising random delay). This is + * required to place the AUX_ADV_IND PDUs in a non-overlapping interval with the + * Broadcast ISO radio events. + */ + ext_adv_param.interval_min -= BT_GAP_MS_TO_ADV_INTERVAL(10U); + ext_adv_param.interval_max -= BT_GAP_MS_TO_ADV_INTERVAL(10U); + + /* Create a non-connectable advertising set */ + err = bt_le_ext_adv_create(&ext_adv_param, NULL, adv); + if (err != 0) { + FAIL("Unable to create extended advertising set: %d\n", err); + return; + } + + /* Set periodic advertising parameters */ + err = bt_le_per_adv_set_param(*adv, BT_BAP_PER_ADV_PARAM_BROADCAST_SLOW); + if (err) { + FAIL("Failed to set periodic advertising parameters: %d\n", err); + return; + } +} + void test_tick(bs_time_t HW_device_time) { if (bst_result != Passed) { diff --git a/tests/bsim/bluetooth/audio/src/common.h b/tests/bsim/bluetooth/audio/src/common.h index dff8597ae48..8584b7ea91a 100644 --- a/tests/bsim/bluetooth/audio/src/common.h +++ b/tests/bsim/bluetooth/audio/src/common.h @@ -139,6 +139,7 @@ extern uint8_t csip_rsi[BT_CSIP_RSI_SIZE]; void disconnected(struct bt_conn *conn, uint8_t reason); void setup_connectable_adv(struct bt_le_ext_adv **ext_adv); +void setup_broadcast_adv(struct bt_le_ext_adv **adv); void test_tick(bs_time_t HW_device_time); void test_init(void); uint16_t get_dev_cnt(void); diff --git a/tests/bsim/bluetooth/audio/src/csip_set_coordinator_test.c b/tests/bsim/bluetooth/audio/src/csip_set_coordinator_test.c index fc07b2e681e..44121ef6bdb 100644 --- a/tests/bsim/bluetooth/audio/src/csip_set_coordinator_test.c +++ b/tests/bsim/bluetooth/audio/src/csip_set_coordinator_test.c @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -328,8 +329,8 @@ static void connect_set(void) } bt_addr_le_to_str(&addr_found[0], addr, sizeof(addr)); - err = bt_conn_le_create(&addr_found[0], BT_CONN_LE_CREATE_CONN, - BT_LE_CONN_PARAM_DEFAULT, &conns[0]); + err = bt_conn_le_create(&addr_found[0], BT_CONN_LE_CREATE_CONN, BT_BAP_CONN_PARAM_RELAXED, + &conns[0]); if (err != 0) { FAIL("Failed to connect to %s: %d\n", err); diff --git a/tests/bsim/bluetooth/audio/src/gmap_ugg_test.c b/tests/bsim/bluetooth/audio/src/gmap_ugg_test.c index 744930b76d3..0e048416a13 100644 --- a/tests/bsim/bluetooth/audio/src/gmap_ugg_test.c +++ b/tests/bsim/bluetooth/audio/src/gmap_ugg_test.c @@ -41,18 +41,6 @@ #include "bap_common.h" #if defined(CONFIG_BT_GMAP) -/* Zephyr Controller works best while Extended Advertising interval to be a multiple - * of the ISO Interval minus 10 ms (max. advertising random delay). This is - * required to place the AUX_ADV_IND PDUs in a non-overlapping interval with the - * Broadcast ISO radio events. - */ -#define BT_LE_EXT_ADV_CUSTOM \ - BT_LE_ADV_PARAM(BT_LE_ADV_OPT_EXT_ADV, BT_GAP_MS_TO_ADV_INTERVAL(80), \ - BT_GAP_MS_TO_ADV_INTERVAL(80), NULL) - -#define BT_LE_PER_ADV_CUSTOM \ - BT_LE_PER_ADV_PARAM(BT_GAP_MS_TO_PER_ADV_INTERVAL(90), BT_GAP_MS_TO_PER_ADV_INTERVAL(90), \ - BT_LE_PER_ADV_OPT_NONE) #define UNICAST_SINK_SUPPORTED (CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT > 0) #define UNICAST_SRC_SUPPORTED (CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SRC_COUNT > 0) @@ -1002,25 +990,6 @@ static void test_gmap_ugg_unicast_ac(const struct gmap_unicast_ac_param *param) param->src_named_preset != NULL ? param->src_named_preset->name : "None"); } -static void setup_extended_adv(struct bt_le_ext_adv **adv) -{ - int err; - - /* Create a non-connectable advertising set */ - err = bt_le_ext_adv_create(BT_LE_EXT_ADV_CUSTOM, NULL, adv); - if (err != 0) { - FAIL("Unable to create extended advertising set: %d\n", err); - return; - } - - /* Set periodic advertising parameters */ - err = bt_le_per_adv_set_param(*adv, BT_LE_PER_ADV_CUSTOM); - if (err) { - FAIL("Failed to set periodic advertising parameters: %d\n", err); - return; - } -} - static void setup_extended_adv_data(struct bt_cap_broadcast_source *source, struct bt_le_ext_adv *adv) { @@ -1207,7 +1176,7 @@ static int test_gmap_ugg_broadcast_ac(const struct gmap_broadcast_ac_param *para create_param.qos = &qos; init(); - setup_extended_adv(&adv); + setup_broadcast_adv(&adv); err = bt_cap_initiator_broadcast_audio_create(&create_param, &broadcast_source); if (err != 0) { diff --git a/tests/bsim/bluetooth/audio/src/pbp_public_broadcast_source_test.c b/tests/bsim/bluetooth/audio/src/pbp_public_broadcast_source_test.c index 4d010c60d92..eb2e789f24a 100644 --- a/tests/bsim/bluetooth/audio/src/pbp_public_broadcast_source_test.c +++ b/tests/bsim/bluetooth/audio/src/pbp_public_broadcast_source_test.c @@ -198,29 +198,6 @@ static int start_extended_adv(struct bt_le_ext_adv *adv) return 0; } -static int setup_extended_adv(struct bt_le_ext_adv **adv) -{ - int err; - - /* Create a non-connectable advertising set */ - err = bt_le_ext_adv_create(BT_LE_EXT_ADV_NCONN, NULL, adv); - if (err != 0) { - printk("Unable to create extended advertising set: %d\n", err); - - return err; - } - - /* Set periodic advertising parameters */ - err = bt_le_per_adv_set_param(*adv, BT_LE_PER_ADV_DEFAULT); - if (err) { - printk("Failed to set periodic advertising parameters: %d\n", err); - - return err; - } - - return 0; -} - static int stop_extended_adv(struct bt_le_ext_adv *adv) { int err; @@ -292,11 +269,7 @@ static void test_main(void) k_sem_reset(&sem_started); k_sem_reset(&sem_stopped); - err = setup_extended_adv(&adv); - if (err != 0) { - printk("Unable to setup extended advertiser: %d\n", err); - FAIL("Public Broadcast source failed\n"); - } + setup_broadcast_adv(&adv); err = bt_cap_initiator_broadcast_audio_create(&create_param, &broadcast_source); if (err != 0) { diff --git a/tests/bsim/bluetooth/audio/src/tmap_client_test.c b/tests/bsim/bluetooth/audio/src/tmap_client_test.c index 8332d534580..572abc9f019 100644 --- a/tests/bsim/bluetooth/audio/src/tmap_client_test.c +++ b/tests/bsim/bluetooth/audio/src/tmap_client_test.c @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -87,8 +88,7 @@ static bool check_audio_support_and_connect(struct bt_data *data, void *user_dat return false; } - err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN, - BT_LE_CONN_PARAM_DEFAULT, + err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN, BT_BAP_CONN_PARAM_RELAXED, &default_conn); if (err != 0) { printk("Create conn to failed (%u)\n", err); diff --git a/tests/bsim/bluetooth/audio/src/tmap_server_test.c b/tests/bsim/bluetooth/audio/src/tmap_server_test.c index 37da4201942..afb031ce167 100644 --- a/tests/bsim/bluetooth/audio/src/tmap_server_test.c +++ b/tests/bsim/bluetooth/audio/src/tmap_server_test.c @@ -7,6 +7,7 @@ #include #include +#include #include #include #include diff --git a/tests/bsim/bluetooth/audio/test_scripts/bap_broadcast_audio_assistant.sh b/tests/bsim/bluetooth/audio/test_scripts/bap_broadcast_audio_assistant.sh index 4b2bc395429..45bbba49f3f 100755 --- a/tests/bsim/bluetooth/audio/test_scripts/bap_broadcast_audio_assistant.sh +++ b/tests/bsim/bluetooth/audio/test_scripts/bap_broadcast_audio_assistant.sh @@ -25,7 +25,7 @@ Execute ./bs_${BOARD_TS}_tests_bsim_bluetooth_audio_prj_conf \ Execute ./bs_${BOARD_TS}_tests_bsim_bluetooth_audio_prj_conf \ -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=2 \ -testid=broadcast_source -RealEncryption=1 -rs=69 -D=3 \ - -start_offset=5e3 -argstest subgroup_cnt 1 streams_per_subgroup_cnt 2 + -start_offset=2e3 -argstest subgroup_cnt 1 streams_per_subgroup_cnt 2 # Simulation time should be larger than the WAIT_TIME in common.h Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -D=3 -sim_length=60e6 $@ diff --git a/tests/bsim/bluetooth/audio_samples/bap_unicast_client/src/unicast_client_sample_test.c b/tests/bsim/bluetooth/audio_samples/bap_unicast_client/src/unicast_client_sample_test.c index 603fd10f024..ef743e9b9f9 100644 --- a/tests/bsim/bluetooth/audio_samples/bap_unicast_client/src/unicast_client_sample_test.c +++ b/tests/bsim/bluetooth/audio_samples/bap_unicast_client/src/unicast_client_sample_test.c @@ -12,7 +12,7 @@ #include "bs_utils.h" #include "bstests.h" -#define WAIT_TIME 10 /* Seconds */ +#define WAIT_TIME 20 /* Seconds */ #define PASS_THRESHOLD 100 /* Audio packets */