@@ -3481,16 +3481,34 @@ void Gap::on_advertising_set_terminated(
3481
3481
to_string (status),
3482
3482
number_of_completed_extended_advertising_events);
3483
3483
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
+ }
3494
3512
}
3495
3513
3496
3514
/* postpone as other events may still be pending */
@@ -3509,7 +3527,8 @@ void Gap::on_advertising_set_terminated(
3509
3527
advertising_handle,
3510
3528
connection_handle,
3511
3529
number_of_completed_extended_advertising_events,
3512
- status == hci_error_code_t ::SUCCESS
3530
+ connected,
3531
+ error_code
3513
3532
)
3514
3533
);
3515
3534
}
0 commit comments