diff --git a/nimble/host/src/ble_hs.c b/nimble/host/src/ble_hs.c index c4ffd949c..c96bf2be7 100644 --- a/nimble/host/src/ble_hs.c +++ b/nimble/host/src/ble_hs.c @@ -376,6 +376,9 @@ ble_hs_reset(void) ble_gap_conn_broken(conn_handle, ble_hs_reset_reason); } + /* Clear configured addresses. */ + ble_hs_id_reset(); + if (ble_hs_cfg.reset_cb != NULL && ble_hs_reset_reason != 0) { ble_hs_cfg.reset_cb(ble_hs_reset_reason); } diff --git a/nimble/host/src/ble_hs_id.c b/nimble/host/src/ble_hs_id.c index 33ef50f93..14641535b 100644 --- a/nimble/host/src/ble_hs_id.c +++ b/nimble/host/src/ble_hs_id.c @@ -272,3 +272,14 @@ done: ble_hs_unlock(); return rc; } + +/** + * Clears both the public and random addresses. This function is necessary + * when the controller loses its random address (e.g., on a stack reset). + */ +void +ble_hs_id_reset(void) +{ + memset(ble_hs_id_pub, 0, sizeof ble_hs_id_pub); + memset(ble_hs_id_rnd, 0, sizeof ble_hs_id_pub); +} diff --git a/nimble/host/src/ble_hs_id_priv.h b/nimble/host/src/ble_hs_id_priv.h index 1db5483fb..7aa956f49 100644 --- a/nimble/host/src/ble_hs_id_priv.h +++ b/nimble/host/src/ble_hs_id_priv.h @@ -30,6 +30,7 @@ void ble_hs_id_set_pub(const uint8_t *pub_addr); int ble_hs_id_addr(uint8_t id_addr_type, const uint8_t **out_id_addr, int *out_is_nrpa); int ble_hs_id_use_addr(uint8_t addr_type); +void ble_hs_id_reset(void); #ifdef __cplusplus }