diff --git a/nimble/host/src/ble_gap.c b/nimble/host/src/ble_gap.c index e212e0d46..242fc53ca 100644 --- a/nimble/host/src/ble_gap.c +++ b/nimble/host/src/ble_gap.c @@ -4941,7 +4941,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; } @@ -5157,6 +5161,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