BLE: Add initiating flag into gap to track if the local device tries to connect to a peer.

pull/13759/head
Vincent Coubard 2020-09-07 10:02:41 +01:00
parent 13771b8172
commit f810ec4c2a
2 changed files with 18 additions and 1 deletions

View File

@ -646,7 +646,15 @@ ble_error_t Gap::rejectConnectionParametersUpdate(
#if BLE_ROLE_CENTRAL
ble_error_t Gap::cancelConnect()
{
return _pal_gap.cancel_connection_creation();
if (!_initiating) {
return BLE_ERROR_NONE;
}
auto ret = _pal_gap.cancel_connection_creation();
if (ret) {
_initiating = false;
}
return ret;
}
#endif
@ -1192,6 +1200,10 @@ void Gap::on_advertising_report(const GapAdvertisingReportEvent &e)
void Gap::on_connection_complete(const GapConnectionCompleteEvent &e)
{
if (e.role == connection_role_t::CENTRAL) {
_initiating = false;
}
if (e.status != hci_error_code_t::SUCCESS) {
if (_event_handler) {
_event_handler->onConnectionComplete(
@ -2332,6 +2344,10 @@ void Gap::on_enhanced_connection_complete(
return;
}
if (own_role == connection_role_t::CENTRAL) {
_initiating = false;
}
_event_handler->onConnectionComplete(
ConnectionCompleteEvent(
(status == hci_error_code_t::SUCCESS) ? BLE_ERROR_NONE : BLE_ERROR_INTERNAL_STACK_FAILURE,

View File

@ -586,6 +586,7 @@ private:
mbed::LowPowerTimeout _scan_timeout;
mbed::LowPowerTicker _address_rotation_ticker;
bool _initiating = false;
template<size_t bit_size>
struct BitArray {
BitArray() : data()