From 68522b8d81544db6b80b2cb72ab59507ba605a83 Mon Sep 17 00:00:00 2001 From: Rahul Tank Date: Fri, 24 Jul 2026 11:49:26 +0530 Subject: [PATCH] fix(nimble): Added change to stop adv before starting new adv --- nimble/host/src/ble_gap.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/nimble/host/src/ble_gap.c b/nimble/host/src/ble_gap.c index 062923c77..1cf9265d8 100644 --- a/nimble/host/src/ble_gap.c +++ b/nimble/host/src/ble_gap.c @@ -3815,7 +3815,11 @@ ble_gap_adv_validate(uint8_t own_addr_type, const ble_addr_t *peer_addr, return BLE_HS_EINVAL; } - if (ble_gap_slave[0].op != BLE_GAP_OP_NULL) { + if (ble_gap_slave[0].op != BLE_GAP_OP_NULL +#if MYNEWT_VAL(BLE_GAP_ALLOW_ADV_RESTART) + && ble_gap_slave[0].op != BLE_GAP_OP_S_ADV +#endif + ) { return BLE_HS_EALREADY; } @@ -3916,6 +3920,15 @@ ble_gap_adv_start(uint8_t own_addr_type, const ble_addr_t *direct_addr, goto done; } +#if MYNEWT_VAL(BLE_GAP_ALLOW_ADV_RESTART) + if (ble_gap_slave[0].op == BLE_GAP_OP_S_ADV) { + rc = ble_gap_adv_stop_no_lock(); + if (rc != 0) { + goto done; + } + } +#endif + #if MYNEWT_VAL(BLE_ENABLE_CONN_REATTEMPT) && NIMBLE_BLE_CONNECT } #endif