Skip to content

Commit 6b930d6

Browse files
translate adv set error codes and only act on successful stop
1 parent 4fae828 commit 6b930d6

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

connectivity/FEATURE_BLE/source/generic/GapImpl.cpp

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3481,16 +3481,34 @@ void Gap::on_advertising_set_terminated(
34813481
to_string(status),
34823482
number_of_completed_extended_advertising_events);
34833483

3484-
_active_sets.clear(advertising_handle);
3485-
_pending_sets.clear(advertising_handle);
3486-
3487-
// If this is part of the address refresh start advertising again.
3488-
if (_address_refresh_sets.get(advertising_handle) && !connection_handle) {
3489-
_address_refresh_sets.clear(advertising_handle);
3490-
tr_info("Part of the address refresh, restarting advertising");
3491-
startAdvertising(advertising_handle);
3492-
_adv_started_from_refresh.set(advertising_handle);
3493-
return;
3484+
ble_error_t error_code = BLE_ERROR_UNSPECIFIED;
3485+
bool connected = false;
3486+
3487+
/* translate HCI error into BLE API error code */
3488+
if (status == hci_error_code_t::SUCCESS) {
3489+
error_code = BLE_ERROR_NONE;
3490+
/* self cancelled set will have the handle set to invalid value */
3491+
if (connection_handle != DM_CONN_ID_NONE) {
3492+
connected = true;
3493+
}
3494+
} else if (status == hci_error_code_t::ADVERTISING_TIMEOUT) {
3495+
error_code = BLE_ERROR_TIMEOUT;
3496+
} else if (status == hci_error_code_t::LIMIT_REACHED) {
3497+
error_code = BLE_ERROR_LIMIT_REACHED;
3498+
}
3499+
3500+
if (error_code != BLE_ERROR_UNSPECIFIED) {
3501+
_active_sets.clear(advertising_handle);
3502+
_pending_sets.clear(advertising_handle);
3503+
3504+
// If this is part of the address refresh start advertising again.
3505+
if (_address_refresh_sets.get(advertising_handle) && !connection_handle) {
3506+
_address_refresh_sets.clear(advertising_handle);
3507+
tr_info("Part of the address refresh, restarting advertising");
3508+
startAdvertising(advertising_handle);
3509+
_adv_started_from_refresh.set(advertising_handle);
3510+
return;
3511+
}
34943512
}
34953513

34963514
/* postpone as other events may still be pending */
@@ -3509,7 +3527,8 @@ void Gap::on_advertising_set_terminated(
35093527
advertising_handle,
35103528
connection_handle,
35113529
number_of_completed_extended_advertising_events,
3512-
status == hci_error_code_t::SUCCESS
3530+
connected,
3531+
error_code
35133532
)
35143533
);
35153534
}

0 commit comments

Comments
 (0)