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
This commit is contained in:
Krzysztof Kopyściński
2023-12-04 09:27:13 +01:00
committed by Krzysztof Kopyściński
parent a621805349
commit ca7aeaad9e
2 changed files with 22 additions and 0 deletions
+8
View File
@@ -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 */
+14
View File
@@ -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
/**