I am working on a BLE peripheral (nRF52840 & SDK 15.3), which uses the Peer Manager to handle encryption and bonding to an iOS central device.
Requirements call for the device to advertise its presence every 180 seconds such that the central device can connect and query for any available data. Once all data has been transferred, the BLE peripheral closes the connection to conserve power. When establishing the connection, central negotiates for notifications on three data channels (custom Characteristics) to expedite data transfer. This action changes the CCCD definitions for these Characteristics and triggers an update to the data that Peer Manager saves in flash storage.
After approximately 18 hours of operation, pairing fails between the peripheral and the iOS central device. I have traced the issue to an encryption failure in security_dispatcher, line 388 where the function sec_info_request_process() detects a null ble_gap_enc_info_t object for the valid device handle 0, indicating the security key is missing locally. I have confirmed that the security descriptor is being saved to flash; valid connections can still be created following a power cycle on an nRF52840-DK with no battery.
Does garbage collection in the Peer Manager properly preserve security descriptors when there is only one peer device? I am currently only ever bonding with a single iOS central device but have found that in pm_handler_flash_clean() the PM_EVT_STORAGE_FULL event is calling pm_peer_delete(); even when there is only one peer bonded with the peripheral.
The PM_PEER_RANKS_ENABLED is enabled to support connections to a second central device at some point, does disabling this functionality also disable deletion of the lowest ranked peer during garbage collection? Is there documentation that explains Peer Ranking functionality? I have disabled this and enabled re-bonding functionality in the pm call back in hopes that iOS honors the request. I do not consider re-bonding to be a solution because of its security risks.
These two changes were just implemented and their results will be known in about 18 hours. In the interim, I am asking for assistance in better understanding the garbage collection process and the peer ranking process in your Peer Manager implementation.