central auto removes failed bond keys
This commit is contained in:
1 parent
d0e5946974
commit
7cc1307517
3 files changed
+20
-2
No files matched your search
@@ -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(<key) )
|
||||
bond_keys_t ltkey;
|
||||
if ( conn->loadBondKey(<key) )
|
||||
{
|
||||
BLEPairing* secure = &Bluefruit.Pairing;
|
||||
secure->_encrypt(conn_hdl, <key);
|
||||
@@ -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);
|
||||
}
|
||||
Reference in new issue
Block a user