From 35262982c45c6da64d65c8511d9568be5c785bfd Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 18 Mar 2020 00:34:29 +0700 Subject: [PATCH] central auto use stored keys if bonded previously --- libraries/Bluefruit52Lib/src/BLECentral.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libraries/Bluefruit52Lib/src/BLECentral.cpp b/libraries/Bluefruit52Lib/src/BLECentral.cpp index 467e2325..83400851 100644 --- a/libraries/Bluefruit52Lib/src/BLECentral.cpp +++ b/libraries/Bluefruit52Lib/src/BLECentral.cpp @@ -133,12 +133,22 @@ void BLECentral::_eventHandler(ble_evt_t* evt) { // conn handle has fixed offset regardless of event type const uint16_t conn_hdl = evt->evt.common_evt.conn_handle; + BLEConnection* conn = Bluefruit.Connection(conn_hdl); /* PrPh handle connection is already filtered. Only handle Central events or * connection handle is BLE_CONN_HANDLE_INVALID (e.g BLE_GAP_EVT_ADV_REPORT) */ switch ( evt->header.evt_id ) { case BLE_GAP_EVT_CONNECTED: + { + // Try to secure connection if we bonded previously + static bond_keys_t ltkey; + if ( conn->loadLongTermKey(<key) ) + { + BLEPairing* secure = &Bluefruit.Pairing; + secure->_encrypt(conn_hdl, <key); + } + } break; case BLE_GAP_EVT_DISCONNECTED: