Skip to content

Commit 3526298

Browse files
committed
central auto use stored keys if bonded previously
1 parent ddded48 commit 3526298

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

libraries/Bluefruit52Lib/src/BLECentral.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,22 @@ void BLECentral::_eventHandler(ble_evt_t* evt)
133133
{
134134
// conn handle has fixed offset regardless of event type
135135
const uint16_t conn_hdl = evt->evt.common_evt.conn_handle;
136+
BLEConnection* conn = Bluefruit.Connection(conn_hdl);
136137

137138
/* PrPh handle connection is already filtered. Only handle Central events or
138139
* connection handle is BLE_CONN_HANDLE_INVALID (e.g BLE_GAP_EVT_ADV_REPORT) */
139140
switch ( evt->header.evt_id )
140141
{
141142
case BLE_GAP_EVT_CONNECTED:
143+
{
144+
// Try to secure connection if we bonded previously
145+
static bond_keys_t ltkey;
146+
if ( conn->loadLongTermKey(&ltkey) )
147+
{
148+
BLEPairing* secure = &Bluefruit.Pairing;
149+
secure->_encrypt(conn_hdl, &ltkey);
150+
}
151+
}
142152
break;
143153

144154
case BLE_GAP_EVT_DISCONNECTED:

0 commit comments

Comments
 (0)