From 73112f9b4068ef7dc541c88c555ff829bebb9f8f Mon Sep 17 00:00:00 2001 From: Rahul Tank Date: Mon, 17 Jun 2024 14:09:00 +0530 Subject: [PATCH] fix(nimble): Clear resource before starting advertising --- nimble/host/src/ble_gap.c | 14 +++++++------- nimble/host/src/ble_hs_hci_evt.c | 13 +++++++++++++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/nimble/host/src/ble_gap.c b/nimble/host/src/ble_gap.c index b668b7443..d896565e9 100644 --- a/nimble/host/src/ble_gap.c +++ b/nimble/host/src/ble_gap.c @@ -3036,6 +3036,13 @@ ble_gap_adv_start(uint8_t own_addr_type, const ble_addr_t *direct_addr, return BLE_HS_EDISABLED; } + ble_hs_lock(); + + rc = ble_gap_adv_validate(own_addr_type, direct_addr, adv_params); + if (rc != 0) { + goto done; + } + #if MYNEWT_VAL(BLE_ENABLE_CONN_REATTEMPT) ble_adv_reattempt.type = 0; ble_adv_reattempt.own_addr_type = own_addr_type; @@ -3053,13 +3060,6 @@ ble_gap_adv_start(uint8_t own_addr_type, const ble_addr_t *direct_addr, ble_adv_reattempt.cb_arg = cb_arg; #endif - ble_hs_lock(); - - rc = ble_gap_adv_validate(own_addr_type, direct_addr, adv_params); - if (rc != 0) { - goto done; - } - if (duration_ms != BLE_HS_FOREVER) { rc = ble_npl_time_ms_to_ticks(duration_ms, &duration_ticks); if (rc != 0) { diff --git a/nimble/host/src/ble_hs_hci_evt.c b/nimble/host/src/ble_hs_hci_evt.c index 9b9386436..64b37f018 100644 --- a/nimble/host/src/ble_hs_hci_evt.c +++ b/nimble/host/src/ble_hs_hci_evt.c @@ -238,6 +238,19 @@ ble_hs_hci_evt_disconn_complete(uint8_t event_code, const void *data, BLE_HS_LOG(INFO, "Reattempt advertising; reason: 0x%x, status = %x", ev->reason, ev->status); + ble_l2cap_sig_conn_broken(ev->conn_handle, BLE_ERR_CONN_ESTABLISHMENT); + ble_sm_connection_broken(ev->conn_handle); + ble_gatts_connection_broken(ev->conn_handle); + ble_gattc_connection_broken(ev->conn_handle); + ble_hs_flow_connection_broken(ev->conn_handle);; +#if MYNEWT_VAL(BLE_GATT_CACHING) + ble_gattc_cache_conn_broken(ev->conn_handle); +#endif + rc = ble_hs_atomic_conn_delete(ev->conn_handle); + if (rc != 0) { + return rc; + } + rc = ble_gap_slave_adv_reattempt(); if (rc != 0) { BLE_HS_LOG(INFO, "Adv reattempt failed; rc= %d ", rc);