clean up
This commit is contained in:
1 parent
b487db9603
commit
7b432602aa
3 files changed
+23
-16
No files matched your search
@@ -252,23 +252,19 @@ bool BLEConnection::requestPairing(void)
|
||||
// skip if already paired
|
||||
if ( _paired ) return true;
|
||||
|
||||
ble_gap_sec_params_t sec_param = Bluefruit.Pairing.getSecureParam();
|
||||
BLEPairing* secure = &Bluefruit.Pairing;
|
||||
|
||||
// on-the-fly semaphore
|
||||
_pair_sem = xSemaphoreCreateBinary();
|
||||
VERIFY(_pair_sem);
|
||||
|
||||
bond_keys_t ltkeys;
|
||||
uint32_t err;
|
||||
bond_keys_t ltkey;
|
||||
|
||||
if ( loadLongTermKey(<keys) )
|
||||
if ( loadLongTermKey(<key) )
|
||||
{
|
||||
// We already bonded with this peer previously
|
||||
// Encrypt the connection using stored Longterm Key
|
||||
err = sd_ble_gap_encrypt(_conn_hdl, <keys.peer_enc.master_id, <keys.peer_enc.enc_info);
|
||||
PRINT_STATUS(err);
|
||||
|
||||
if ( err == NRF_SUCCESS )
|
||||
if ( secure->_encrypt(_conn_hdl, <key) )
|
||||
{
|
||||
xSemaphoreTake(_pair_sem, portMAX_DELAY);
|
||||
|
||||
@@ -276,21 +272,17 @@ bool BLEConnection::requestPairing(void)
|
||||
// delete bonds while we did not --> let's remove the obsolete keyfile and retry
|
||||
if ( !_paired )
|
||||
{
|
||||
bond_remove_key(_role, <keys.peer_id.id_addr_info);
|
||||
bond_remove_key(_role, <key.peer_id.id_addr_info);
|
||||
|
||||
// Re-try with a fresh session
|
||||
err = sd_ble_gap_authenticate(_conn_hdl, &sec_param );
|
||||
PRINT_STATUS(err);
|
||||
|
||||
secure->_authenticate(_conn_hdl);
|
||||
xSemaphoreTake(_pair_sem, portMAX_DELAY);
|
||||
}
|
||||
}
|
||||
}else
|
||||
{
|
||||
// start a fresh new authentication process
|
||||
err = sd_ble_gap_authenticate(_conn_hdl, &sec_param );
|
||||
PRINT_STATUS(err);
|
||||
|
||||
secure->_authenticate(_conn_hdl);
|
||||
xSemaphoreTake(_pair_sem, portMAX_DELAY);
|
||||
}
|
||||
|
||||
|
||||
@@ -195,6 +195,18 @@ void BLEPairing::setCompleteCallback(pair_complete_cb_t fp)
|
||||
_complete_cb = fp;
|
||||
}
|
||||
|
||||
bool BLEPairing::_authenticate(uint16_t conn_hdl)
|
||||
{
|
||||
VERIFY_STATUS(sd_ble_gap_authenticate(conn_hdl, &_sec_param ), false);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BLEPairing::_encrypt(uint16_t conn_hdl, bond_keys_t const* ltkey)
|
||||
{
|
||||
VERIFY_STATUS(sd_ble_gap_encrypt(conn_hdl, <key->peer_enc.master_id, <key->peer_enc.enc_info), false);
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
/* First-time Pairing
|
||||
*
|
||||
|
||||
@@ -42,7 +42,7 @@ class BLEPairing
|
||||
|
||||
bool begin(void);
|
||||
|
||||
// Static Passkey
|
||||
// Use static Passkey (Legacy SC)
|
||||
bool setPIN(const char* pin);
|
||||
|
||||
// resolve address with IRK to see if it matches
|
||||
@@ -60,6 +60,9 @@ class BLEPairing
|
||||
ble_gap_sec_params_t getSecureParam(void) { return _sec_param; }
|
||||
void _eventHandler(ble_evt_t* evt);
|
||||
|
||||
bool _authenticate(uint16_t conn_hdl);
|
||||
bool _encrypt(uint16_t conn_hdl, bond_keys_t const* ltkey);
|
||||
|
||||
private:
|
||||
ble_gap_sec_params_t _sec_param;
|
||||
|
||||
|
||||
Reference in new issue
Block a user