Hi,
I'm working on a legacy program (Peripheral) using nRF52833 and nRF5 SDK using SoftDevice S113.
One of the requirements of my peripheral application is that it should automatically reconnect (whenever in range) to only one Central device (the latest Central that it Bonded with). The reconnection should be automatic (on major OSs, like iOS/Android/ChromeOS).
While connected, the Peripheral should also allow incoming connections from other Centrals that may then Bond to it (if they pass an encrypted data exchange at the App layer), in which case the Peripheral will now become associated with this latest device and only allow automatic reconnection (on power cycles, reboots, etc...) from this Central. The peripheral also needs to use Resolvable Private Addresses for privacy.
The approach I was thinking of following to achieve this was the following:
- 1. Peripheral boots, fetches curr_IRK from persistent storage and applies it with pm_privacy_set()
- 2. Starts connectable advertising and rotates address every 30s (BLE stack will generate addresses resolvable by Centrals using curr_IRK)
- 3. CentralA (bonded) resolves the address and connects. App data is now exchanged while user is interacting with the Peripheral/CentralA
- 4. Peripheral immediately re-enables connectable advertising to allow other Centrals to connect/bond
- 5. CentralB connects and starts bonding/auth
- 6. On Auth start App generates a new IRK, (new_IRK) and sets it via pm_privacy_set() with the goal of completing Bonding with CentralB with new_IRK
- 7a. On Auth success, new_IRK is stored in persistent storage, curr_IRK = new_IRK, then Peripheral disconnects from CentralA and deletes its bonding peer data from persistent storage (CentralA will now fail to scan/connect to Peripheral due to IRK change)
- 7b. On Auth failure, new_IRK is discarded and (previous) curr_IRK is set with pm_privacy_set()
My two questions are:
1. Is the above approach feasible to meet my requirement (would changing the IRK when attempting bonding with CentralB while CentralA is connected cause any problems with either
- a) CentralA (whose connection is still using the previous IRK)
- b) CentralB connected to Peripheral which at the time of connection was advertising an RPA resolvable with curr_IRK, but the IRK changes during the connection, right before Auth (before keys exchanged)?
2. If the above approach sounds possible, what's the latest valid AUTH/BLE event that I can use to change the IRK via pm_security_set() before the change is rejected by the SoftDevice? Should it be PM_EVT_CONN_SEC_START, SD_BLE_GAP_AUTHENTICATE, BLE_GAP_EVT_SEC_PARAMS_REQUEST (or other)?
Thanks,
Marco