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
@@ -258,6 +258,13 @@ bool BLEConnection::loadBondKey(bond_keys_t* ltkey)
return true;
}
bool BLEConnection::removeBondKey(void)
{
VERIFY(_bonded);
bond_remove_key(_role, &_bond_id_addr);
return true;
}
bool BLEConnection::requestPairing(void)
{
// skip if already paired
@@ -356,4 +356,6 @@ void bond_remove_key(uint8_t role, ble_gap_addr_t const* id_addr)
get_fname(filename, role, id_addr->addr);
InternalFS.remove(filename);
BOND_LOG("Removed keys from file %s", filename);
}