diff --git a/nimble/host/include/host/ble_gap.h b/nimble/host/include/host/ble_gap.h index fd70b94af..d884596a6 100644 --- a/nimble/host/include/host/ble_gap.h +++ b/nimble/host/include/host/ble_gap.h @@ -1692,6 +1692,14 @@ int ble_gap_ext_adv_clear(void); * */ int ble_gap_ext_adv_active(uint8_t instance); + +/** + * Returns first not configured advertising instance. + * + * @return advertising instance if one was found, negative error code otherwise + * + */ +int ble_gap_adv_get_free_instance(void); #endif /* Periodic Advertising */ diff --git a/nimble/host/src/ble_gap.c b/nimble/host/src/ble_gap.c index 015a70d87..02e4f2888 100644 --- a/nimble/host/src/ble_gap.c +++ b/nimble/host/src/ble_gap.c @@ -1390,6 +1390,20 @@ int ble_gap_ext_adv_active(uint8_t instance) } return ble_gap_adv_active_instance(instance); } + +int +ble_gap_adv_get_free_instance(void) +{ + int i; + + for (i = 0; i < BLE_ADV_INSTANCES; i++) { + if (!ble_gap_slave[i].configured) { + return i; + } + } + + return -BLE_HS_ENOENT; +} #endif /**