From ca7aeaad9e07be1c75cefca63521679e7f307573 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Kopy=C5=9Bci=C5=84ski?= Date: Fri, 17 Nov 2023 08:40:24 +0100 Subject: [PATCH] host/gap: add function that returns free advertising instance ble_gap_adv_get_free_instance browses through list of advertising instances and returns first that is not yet configured. Previously, user had to track which instance is used by themselves, and could only check if advertising is active, via ble_gap_ext_adv_active --- nimble/host/include/host/ble_gap.h | 8 ++++++++ nimble/host/src/ble_gap.c | 14 ++++++++++++++ 2 files changed, 22 insertions(+) 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 /**