I'm working on a project that requires my device to be able to identify when a phone connects that has been previously bonded and placed in the white list. I need to be able to identify this whether or not the phone still has bond information stored. Is this possible? If so how would I achieve this? I've played some with using central_find_in_db(..) in the on_connect() function (both are part of ble_bondmanager.c), but haven't had any success.
I'm currently using ble_bondmanager from nRF51f SDK 5.2.0 to handle the bonding process and information.
In short: I want to detect if my device has ever seen the phone previously regardless of whether or not the phone has any of the bond information stored. How would I achieve this if possible?
Update 1: I can insert the following lines of code inside on_connect() in ble_bondmanager.c and this works for most scenarios. However in testing I found that this will run into a problem if on iOS the bond information is removed from the phone and Bluetooth is disabled and re-enabled. After disabling and re-enabling the phone is always viewed as a new phone upon re-connection. I'm still investigating how to work around that.
device_state.new_phone = true;
// For each whitelisted device
for (int i = 0; i < m_centrals_in_db_count; i++)
{
// check each byte of the device address
for (int j = 0; j < BLE_GAP_ADDR_LEN; j++)
{
// if bytes don't match break
if (m_central.bond.central_addr.addr[j] != m_centrals_db[i].bond.central_addr.addr[j])
break;
// If they all match, then this isn't a new phone
if (j == BLE_GAP_ADDR_LEN-1)
device_state.new_phone = false;
}
// If we've determined this isn't a new phone break
if (!device_state.new_phone)
break;
}