From e1885a83fa895ed5e8fe9e0cdc3d77d893253f3a Mon Sep 17 00:00:00 2001 From: Rahul Tank Date: Thu, 28 Mar 2024 14:20:30 +0530 Subject: [PATCH] Expose API to set RPA Timeout --- nimble/host/include/host/ble_hs_pvcy.h | 2 ++ nimble/host/src/ble_hs_pvcy.c | 29 +++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/nimble/host/include/host/ble_hs_pvcy.h b/nimble/host/include/host/ble_hs_pvcy.h index 4b6c39d8f..ddac47cef 100644 --- a/nimble/host/include/host/ble_hs_pvcy.h +++ b/nimble/host/include/host/ble_hs_pvcy.h @@ -70,6 +70,8 @@ void ble_hs_resolv_deinit(void); int ble_hs_pvcy_set_resolve_enabled(int enable); +void ble_hs_set_rpa_timeout(uint16_t timeout); + #ifdef __cplusplus } #endif diff --git a/nimble/host/src/ble_hs_pvcy.c b/nimble/host/src/ble_hs_pvcy.c index 158da9b60..eea662647 100644 --- a/nimble/host/src/ble_hs_pvcy.c +++ b/nimble/host/src/ble_hs_pvcy.c @@ -32,6 +32,7 @@ const uint8_t ble_hs_pvcy_default_irk[16] = { 0xef, 0x8d, 0xe2, 0x16, 0x4f, 0xec, 0x43, 0x0d, 0xbf, 0x5b, 0xdd, 0x34, 0xc0, 0x53, 0x1e, 0xb8, }; +uint16_t rpa_timeout; static int ble_hs_pvcy_set_addr_timeout(uint16_t timeout) @@ -53,6 +54,23 @@ ble_hs_pvcy_set_addr_timeout(uint16_t timeout) &cmd, sizeof(cmd), NULL, 0); } +void ble_hs_set_rpa_timeout (uint16_t timeout) +{ + rpa_timeout = timeout; + + ble_hs_pvcy_set_addr_timeout(rpa_timeout); +} + +uint16_t ble_hs_get_rpa_timeout(void) +{ + return rpa_timeout; +} + +void ble_hs_reset_rpa_timeout(void) +{ + rpa_timeout = 0 ; +} + #if (!MYNEWT_VAL(BLE_HOST_BASED_PRIVACY)) int ble_hs_pvcy_set_resolve_enabled(int enable) @@ -182,6 +200,7 @@ int ble_hs_pvcy_ensure_started(void) { int rc; + uint16_t rpa_timeout; if (ble_hs_pvcy_started) { return 0; @@ -192,8 +211,16 @@ ble_hs_pvcy_ensure_started(void) ble_hs_resolv_init(); #endif + /* Check if user has already set any timeout. If yes, use it */ + rpa_timeout = ble_hs_get_rpa_timeout(); + /* Set up the periodic change of our RPA. */ - rc = ble_hs_pvcy_set_addr_timeout(MYNEWT_VAL(BLE_RPA_TIMEOUT)); + if (rpa_timeout) { + rc = ble_hs_pvcy_set_addr_timeout(rpa_timeout); + } else { + rc = ble_hs_pvcy_set_addr_timeout(MYNEWT_VAL(BLE_RPA_TIMEOUT)); + } + if (rc != 0) { return rc; }