This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Peer Manager stale connection handles and pm_peers_delete()

1) With SDK14 and SDK15, we're seeing that the connection handle for the last bonded connection is kept indefinitely until reset. The connection handle does not get set to invalid when the corresponding peer has disconnected. I am definitely seeing the BLE_GAP_EVT_DISCONNECTED, which I would assume should invalidate the handle.

I'm not sure if this is by design.

2) This means that pm_peers_delete() will not delete all bonds, because it stops when it encounters a valid connection handle for a bond.

It (1) is by design, then it would be useful for pm_peers_delete() to check if it the handle corresponds to an active connection, perhaps with

get_connection_by_conn_handle()and delete it if not actually connected.

If that is not a reliable test, it would still be useful to skip the peer that has a valid handle, and continue deleting the rest.

We're considering this alternate implementation of im_peer_free(). 

static ret_code_t my_im_peer_free(pm_peer_id_t peer_id)
{
uint16_t conn_handle;
ret_code_t ret = NRF_SUCCESS;

conn_handle = im_conn_handle_get(peer_id);

if ((conn_handle != BLE_CONN_HANDLE_INVALID))
{
ret = pdb_peer_free(peer_id);
if (NRF_SUCCESS = ret)
{
peer_id_set(conn_handle, PM_PEER_ID_INVALID);
}
}
return ret;
}
 
Related