Skip to content

Commit c720118

Browse files
alexsvenkoffes
authored andcommitted
[nrf fromtree] tests: bluetooth: Recycle ext_adv_sets when stopping adv
- We want to reuse ext_advs when first stopped and restarted - This ensures SID is the same - Fixes CAP/CL/ADV/BV-03-C Signed-off-by: Alexander Svensen <alexander.svensen@nordicsemi.no> (cherry picked from commit 4896194)
1 parent f29cbf9 commit c720118

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

tests/bluetooth/tester/src/btp/btp_gap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,7 @@ struct bt_le_adv_param;
585585
struct bt_data;
586586
struct bt_le_ext_adv *tester_gap_ext_adv_get(uint8_t ext_adv_idx);
587587
struct bt_le_per_adv_sync *tester_gap_padv_get(void);
588+
int tester_gap_clear_adv_instance(struct bt_le_ext_adv *ext_adv);
588589
int tester_gap_create_adv_instance(struct bt_le_adv_param *param, uint8_t own_addr_type,
589590
const struct bt_data *ad, size_t ad_len,
590591
const struct bt_data *sd, size_t sd_len,

tests/bluetooth/tester/src/btp_gap.c

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,21 @@ static int tester_gap_ext_adv_idx_free_get(void)
600600
return -ENOMEM;
601601
}
602602

603+
static int tester_gap_ext_adv_idx_get(struct bt_le_ext_adv *ext_adv)
604+
{
605+
if (!IS_ENABLED(CONFIG_BT_EXT_ADV)) {
606+
return -ENOTSUP;
607+
}
608+
609+
for (int i = 0; i < ARRAY_SIZE(ext_adv_sets); i++) {
610+
if (ext_adv_sets[i] == ext_adv) {
611+
return i;
612+
}
613+
}
614+
615+
return -EINVAL;
616+
}
617+
603618
int tester_gap_start_ext_adv(struct bt_le_ext_adv *ext_adv)
604619
{
605620
if (!IS_ENABLED(CONFIG_BT_EXT_ADV)) {
@@ -644,6 +659,8 @@ int tester_gap_stop_ext_adv(struct bt_le_ext_adv *ext_adv)
644659
return -EINVAL;
645660
}
646661

662+
tester_gap_clear_adv_instance(ext_adv);
663+
647664
atomic_clear_bit(&current_settings, BTP_GAP_SETTINGS_ADVERTISING);
648665

649666
return 0;
@@ -750,6 +767,29 @@ static uint8_t set_bondable(const void *cmd, uint16_t cmd_len,
750767
return BTP_STATUS_SUCCESS;
751768
}
752769

770+
int tester_gap_clear_adv_instance(struct bt_le_ext_adv *ext_adv)
771+
{
772+
if (!IS_ENABLED(CONFIG_BT_EXT_ADV)) {
773+
return -ENOTSUP;
774+
}
775+
776+
if (ext_adv == NULL) {
777+
LOG_ERR("Invalid ext_adv");
778+
return -EINVAL;
779+
}
780+
781+
int index = tester_gap_ext_adv_idx_get(ext_adv);
782+
783+
if (index < 0) {
784+
LOG_ERR("Failed to get ext_adv index");
785+
return -EINVAL;
786+
}
787+
788+
ext_adv_sets[index] = NULL;
789+
790+
return 0;
791+
}
792+
753793
int tester_gap_create_adv_instance(struct bt_le_adv_param *param,
754794
uint8_t own_addr_type, const struct bt_data *ad, size_t ad_len,
755795
const struct bt_data *sd, size_t sd_len, uint32_t *settings,
@@ -973,7 +1013,7 @@ static uint8_t stop_advertising(const void *cmd, uint16_t cmd_len,
9731013

9741014
if (IS_ENABLED(CONFIG_BT_EXT_ADV) &&
9751015
atomic_test_bit(&current_settings, BTP_GAP_SETTINGS_EXTENDED_ADVERTISING)) {
976-
err = bt_le_ext_adv_stop(gap_ext_adv);
1016+
err = tester_gap_stop_ext_adv(gap_ext_adv);
9771017
} else {
9781018
err = bt_le_adv_stop();
9791019
}

0 commit comments

Comments
 (0)