central auto removes failed bond keys

This commit is contained in:
hathach committed 2020-03-18 11:00:06 +07:00
1 parent d0e5946974
commit 7cc1307517
3 files changed
+20 -2

No files matched your search

+11 -2
View File
@@ -142,8 +142,8 @@ void BLECentral::_eventHandler(ble_evt_t* evt)
case BLE_GAP_EVT_CONNECTED:
{
// Try to secure connection if we bonded previously
static bond_keys_t ltkey;
if ( conn->loadLongTermKey(&ltkey) )
bond_keys_t ltkey;
if ( conn->loadBondKey(&ltkey) )
{
BLEPairing* secure = &Bluefruit.Pairing;
secure->_encrypt(conn_hdl, &ltkey);
@@ -154,6 +154,15 @@ void BLECentral::_eventHandler(ble_evt_t* evt)
case BLE_GAP_EVT_DISCONNECTED:
break;
case BLE_GAP_EVT_CONN_SEC_UPDATE:
if ( conn->bonded() && !conn->secured() )
{
// Bonded but failed to secure connection
// Peer must have removed LTKey, we should remove ours as well
conn->removeBondKey();
}
break;
case BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST:
{
// Peripheral request to change connection parameter