From 0e74a76c0a961c19d76702dd4b757b29138eca63 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 22 Feb 2018 23:47:41 +0700 Subject: [PATCH] more clean up --- libraries/Bluefruit52Lib/src/BLEGap.h | 2 +- libraries/Bluefruit52Lib/src/BLEGatt.cpp | 2 +- libraries/Bluefruit52Lib/src/bluefruit.cpp | 107 --------------------- libraries/Bluefruit52Lib/src/bluefruit.h | 4 - 4 files changed, 2 insertions(+), 113 deletions(-) diff --git a/libraries/Bluefruit52Lib/src/BLEGap.h b/libraries/Bluefruit52Lib/src/BLEGap.h index 456c1c6f..37f7d82b 100644 --- a/libraries/Bluefruit52Lib/src/BLEGap.h +++ b/libraries/Bluefruit52Lib/src/BLEGap.h @@ -100,7 +100,7 @@ class BLEGap ble_gap_addr_t addr; uint16_t ediv; - bond_data_t* bond_data; + bond_data_t* bond_data; // Shared keys with bonded device, size ~ 80 bytes SemaphoreHandle_t hvn_tx_sem; SemaphoreHandle_t wrcmd_tx_sem; diff --git a/libraries/Bluefruit52Lib/src/BLEGatt.cpp b/libraries/Bluefruit52Lib/src/BLEGatt.cpp index 61695f19..69dcfef6 100644 --- a/libraries/Bluefruit52Lib/src/BLEGatt.cpp +++ b/libraries/Bluefruit52Lib/src/BLEGatt.cpp @@ -146,7 +146,7 @@ void BLEGatt::_eventHandler(ble_evt_t* evt) // Save CCCD if paired if ( Bluefruit.connPaired() && (evt_id == BLE_GATTS_EVT_WRITE) && (req_handle == chr->handles().cccd_handle) ) { - bond_save_cccd(evt_conn_hdl, Bluefruit._bond_data.own_enc.master_id.ediv); + bond_save_cccd(evt_conn_hdl, Bluefruit.Gap._get_peer(evt_conn_hdl)->ediv); } } } diff --git a/libraries/Bluefruit52Lib/src/bluefruit.cpp b/libraries/Bluefruit52Lib/src/bluefruit.cpp index 7956b05e..0f67e1d5 100644 --- a/libraries/Bluefruit52Lib/src/bluefruit.cpp +++ b/libraries/Bluefruit52Lib/src/bluefruit.cpp @@ -121,9 +121,6 @@ COMMENT_OUT( _auth_type = BLE_GAP_AUTH_KEY_TYPE_NONE; varclr(_pin); ) - - varclr(&_bond_data); - _bond_data.own_enc.master_id.ediv = 0xFFFF; // invalid value for ediv } void AdafruitBluefruit::configServiceChanged(bool changed) @@ -930,93 +927,6 @@ void AdafruitBluefruit::_ble_handler(ble_evt_t* evt) _conn_hdl = BLE_CONN_HANDLE_INVALID; break; -// case BLE_GAP_EVT_SEC_PARAMS_REQUEST: -// // Pairing in progress -// varclr(&_bond_data); -// _bond_data.own_enc.master_id.ediv = 0xFFFF; // invalid value for ediv -// -// /* Step 1: Pairing/Bonding -// * - Central supplies its parameters -// * - We replies with our security parameters -// */ -// // ble_gap_sec_params_t* peer = &evt->evt.gap_evt.params.sec_params_request.peer_params; -// COMMENT_OUT( -// // Change security parameter according to authentication type -// if ( _auth_type == BLE_GAP_AUTH_KEY_TYPE_PASSKEY) -// { -// sec_para.mitm = 1; -// sec_para.io_caps = BLE_GAP_IO_CAPS_DISPLAY_ONLY; -// } -// ) -// -// ble_gap_sec_keyset_t keyset = -// { -// .keys_own = { -// .p_enc_key = &_bond_data.own_enc, -// .p_id_key = NULL, -// .p_sign_key = NULL, -// .p_pk = NULL -// }, -// -// .keys_peer = { -// .p_enc_key = &_bond_data.peer_enc, -// .p_id_key = &_bond_data.peer_id, -// .p_sign_key = NULL, -// .p_pk = NULL -// } -// }; -// -// VERIFY_STATUS(sd_ble_gap_sec_params_reply(evt->evt.gap_evt.conn_handle, BLE_GAP_SEC_STATUS_SUCCESS, &_sec_param, &keyset), RETURN_VOID); -// break; - -// case BLE_GAP_EVT_SEC_INFO_REQUEST: -// { -// // Reconnection. If bonded previously, Central will ask for stored keys. -// // return security information. Otherwise NULL -// ble_gap_evt_sec_info_request_t* sec_request = (ble_gap_evt_sec_info_request_t*) &evt->evt.gap_evt.params.sec_info_request; -// -// if ( bond_load_keys(sec_request->master_id.ediv, &_bond_data) ) -// { -// sd_ble_gap_sec_info_reply(evt->evt.gap_evt.conn_handle, &_bond_data.own_enc.enc_info, &_bond_data.peer_id.id_info, NULL); -// } else -// { -// sd_ble_gap_sec_info_reply(evt->evt.gap_evt.conn_handle, NULL, NULL, NULL); -// } -// } -// break; - -// case BLE_GAP_EVT_CONN_SEC_UPDATE: -// { -// // Connection is secured aka Paired -// COMMENT_OUT( ble_gap_conn_sec_t* conn_sec = (ble_gap_conn_sec_t*) &evt->evt.gap_evt.params.conn_sec_update.conn_sec; ) -// -// // Previously bonded --> secure by re-connection process -// // --> Load & Set Sys Attr (Apply Service Context) -// // Else Init Sys Attr -// bond_load_cccd(evt_conn_hdl, _bond_data.own_enc.master_id.ediv); -// -// // Consider Paired as Bonded -// _bonded = true; -// } -// break; -// -// case BLE_GAP_EVT_AUTH_STATUS: -// { -// // Bonding process completed -// ble_gap_evt_auth_status_t* status = &evt->evt.gap_evt.params.auth_status; -// -// // Pairing/Bonding succeeded --> save encryption keys -// if (BLE_GAP_SEC_STATUS_SUCCESS == status->auth_status) -// { -// _bonded = true; -// bond_save_keys(evt_conn_hdl, &_bond_data); -// }else -// { -// PRINT_HEX(status->auth_status); -// } -// } -// break; - case BLE_GATTS_EVT_SYS_ATTR_MISSING: sd_ble_gatts_sys_attr_set(_conn_hdl, NULL, 0, 0); break; @@ -1077,20 +987,3 @@ void AdafruitBluefruit::clearBonds(void) bond_clear(); } -void AdafruitBluefruit::_bledfu_get_bond_data(ble_gap_addr_t* addr, ble_gap_irk_t* irk, ble_gap_enc_key_t* enc_key) -{ - (*addr) = getPeerAddr(); - - if ( connPaired() ) - { - bond_data_t bdata; - - if ( bond_load_keys( Gap._get_peer(_conn_hdl)->ediv, &bdata ) ) - { - (*addr) = _bond_data.peer_id.id_addr_info; - (*irk) = _bond_data.peer_id.id_info; - - (*enc_key) = _bond_data.own_enc; - } - } -} diff --git a/libraries/Bluefruit52Lib/src/bluefruit.h b/libraries/Bluefruit52Lib/src/bluefruit.h index 2414bc49..3a697792 100644 --- a/libraries/Bluefruit52Lib/src/bluefruit.h +++ b/libraries/Bluefruit52Lib/src/bluefruit.h @@ -192,10 +192,6 @@ class AdafruitBluefruit void _startConnLed (void); void _stopConnLed (void); void _setConnLed (bool on_off); - void _bledfu_get_bond_data(ble_gap_addr_t* addr, ble_gap_irk_t* irk, ble_gap_enc_key_t* enc_key); - - // Shared keys with bonded device, size = 80 bytes - bond_data_t _bond_data; private: /*------------- SoftDevice Configuration -------------*/