Skip to content

Commit 9283e3e

Browse files
check set stopped before taking action
1 parent 5ec63e5 commit 9283e3e

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

connectivity/FEATURE_BLE/source/generic/GapImpl.cpp

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3479,17 +3479,31 @@ void Gap::on_advertising_set_terminated(
34793479
connection_handle,
34803480
to_string(status),
34813481
number_of_completed_extended_advertising_events);
3482+
3483+
ble_error_t error_code = BLE_ERROR_UNSPECIFIED;
3484+
bool connected = false;
3485+
3486+
if (status == hci_error_code_t::SUCCESS) {
3487+
/* hci code success means connection terminated it */
3488+
connected = true;
3489+
error_code = BLE_ERROR_NONE;
3490+
} else if (status == hci_error_code_t::OPERATION_CANCELLED_BY_HOST) {
3491+
/* if we stopped the set ourselves this is not an error */
3492+
error_code = BLE_ERROR_NONE;
3493+
}
34823494

3483-
_active_sets.clear(advertising_handle);
3484-
_pending_sets.clear(advertising_handle);
3495+
if (error_code == BLE_ERROR_NONE) {
3496+
_active_sets.clear(advertising_handle);
3497+
_pending_sets.clear(advertising_handle);
34853498

3486-
// If this is part of the address refresh start advertising again.
3487-
if (_address_refresh_sets.get(advertising_handle) && !connection_handle) {
3488-
_address_refresh_sets.clear(advertising_handle);
3489-
tr_info("Part of the address refresh, restarting advertising");
3490-
startAdvertising(advertising_handle);
3491-
_adv_started_from_refresh.set(advertising_handle);
3492-
return;
3499+
// If this is part of the address refresh start advertising again.
3500+
if (_address_refresh_sets.get(advertising_handle) && !connection_handle) {
3501+
_address_refresh_sets.clear(advertising_handle);
3502+
tr_info("Part of the address refresh, restarting advertising");
3503+
startAdvertising(advertising_handle);
3504+
_adv_started_from_refresh.set(advertising_handle);
3505+
return;
3506+
}
34933507
}
34943508

34953509
/* postpone as other events may still be pending */
@@ -3503,18 +3517,6 @@ void Gap::on_advertising_set_terminated(
35033517
return;
35043518
}
35053519

3506-
ble_error_t error_code = BLE_ERROR_UNSPECIFIED;
3507-
bool connected = false;
3508-
3509-
if (status == hci_error_code_t::SUCCESS) {
3510-
/* hci code success means connection terminated it */
3511-
connected = true;
3512-
error_code = BLE_ERROR_NONE;
3513-
} else if (status == hci_error_code_t::OPERATION_CANCELLED_BY_HOST) {
3514-
/* if we stopped the set ourselves this is not an error */
3515-
error_code = BLE_ERROR_NONE;
3516-
}
3517-
35183520
_event_handler->onAdvertisingEnd(
35193521
AdvertisingEndEvent(
35203522
advertising_handle,

0 commit comments

Comments
 (0)