rename save/load BondKey

This commit is contained in:
hathach committed 2020-03-18 10:55:05 +07:00
1 parent 1210b3e7c0
commit d0e5946974
4 files changed
+22 -14

No files matched your search

@@ -93,6 +93,11 @@ bool BLEConnection::bonded(void)
return _bonded;
}
bool BLEConnection::secured(void)
{
return _secured;
}
uint8_t BLEConnection::getRole (void)
{
return _role;
@@ -237,16 +242,15 @@ bool BLEConnection::loadCccd(void)
return bond_load_cccd(_role, _conn_hdl, &_bond_id_addr);
}
bool BLEConnection::saveLongTermKey(bond_keys_t const* ltkey)
bool BLEConnection::saveBondKey(bond_keys_t const* ltkey)
{
bond_save_keys(_role, _conn_hdl, ltkey);
_bond_id_addr = ltkey->peer_id.id_addr_info;
_secured = true; // paired with new device
_bonded = true;
return true;
}
bool BLEConnection::loadLongTermKey(bond_keys_t* ltkey)
bool BLEConnection::loadBondKey(bond_keys_t* ltkey)
{
_bonded = bond_load_keys(_role, &_peer_addr, ltkey);
VERIFY(_bonded);
@@ -267,7 +271,7 @@ bool BLEConnection::requestPairing(void)
// bond_keys_t ltkey;
//
// if ( loadLongTermKey(&ltkey) ) // central only
// if ( loadBondKey(&ltkey) ) // central only
// {
// // We already bonded with this peer previously
// // Encrypt the connection using stored Longterm Key
+5 -3
View File
@@ -74,8 +74,9 @@ class BLEConnection
uint16_t handle(void);
bool connected(void);
bool paired(void);
bool paired(void); // todo removed
bool bonded(void);
bool secured(void);
uint8_t getRole(void);
uint16_t getMtu (void);
@@ -105,8 +106,9 @@ class BLEConnection
bool getWriteCmdPacket(void);
bool waitForIndicateConfirm(void);
bool saveLongTermKey(bond_keys_t const* ltkey);
bool loadLongTermKey(bond_keys_t* ltkey);
bool saveBondKey(bond_keys_t const* ltkey);
bool loadBondKey(bond_keys_t* ltkey);
bool removeBondKey(void);
bool saveCccd(void);
bool loadCccd(void);
+8 -6
View File
@@ -349,7 +349,7 @@ void BLEPairing::_eventHandler(ble_evt_t* evt)
// Pairing succeeded --> save encryption keys ( Bonding )
if (BLE_GAP_SEC_STATUS_SUCCESS == status->auth_status)
{
conn->saveLongTermKey(&_bond_keys);
conn->saveBondKey(&_bond_keys);
}
// Invoke callback
@@ -364,17 +364,19 @@ void BLEPairing::_eventHandler(ble_evt_t* evt)
// - Else return NULL --> Initiate key exchange
ble_gap_evt_sec_info_request_t* sec_info = (ble_gap_evt_sec_info_request_t*) &evt->evt.gap_evt.params.sec_info_request;
LOG_LV2("PAIR", "Addr ID = %d, Addr Type = 0x%02X", sec_info->peer_addr.addr_id_peer, sec_info->peer_addr.addr_type);
LOG_LV2_BUFFER("Address", sec_info->peer_addr.addr, 6);
LOG_LV2("PAIR", "Address: ID = %d, Type = 0x%02X, %02X:%02X:%02X:%02X:%02X:%02X",
sec_info->peer_addr.addr_id_peer, sec_info->peer_addr.addr_type,
sec_info->peer_addr.addr[0], sec_info->peer_addr.addr[1], sec_info->peer_addr.addr[2],
sec_info->peer_addr.addr[3], sec_info->peer_addr.addr[4], sec_info->peer_addr.addr[5]);
bond_keys_t bkeys;
if ( conn->loadLongTermKey(&bkeys) )
if ( conn->loadBondKey(&bkeys) )
{
sd_ble_gap_sec_info_reply(conn_hdl, &bkeys.own_enc.enc_info, &bkeys.peer_id.id_info, NULL);
VERIFY_STATUS(sd_ble_gap_sec_info_reply(conn_hdl, &bkeys.own_enc.enc_info, &bkeys.peer_id.id_info, NULL), );
} else
{
sd_ble_gap_sec_info_reply(conn_hdl, NULL, NULL, NULL);
VERIFY_STATUS(sd_ble_gap_sec_info_reply(conn_hdl, NULL, NULL, NULL), );
}
}
break;
@@ -140,7 +140,7 @@ static void bledfu_control_wr_authorize_cb(uint16_t conn_hdl, BLECharacteristic*
if ( conn->paired() )
{
bond_keys_t bkeys;
if ( conn->loadLongTermKey(&bkeys) )
if ( conn->loadBondKey(&bkeys) )
{
peer_data->addr = bkeys.peer_id.id_addr_info;
peer_data->irk = bkeys.peer_id.id_info;