From 3b995662267e8a0b1ccd601c4fdfe36d4af4bc37 Mon Sep 17 00:00:00 2001 From: Nic Costa Date: Tue, 8 Jan 2019 12:45:39 -0600 Subject: [PATCH] Remove own_oob and peer_oob flags from Nordic PAL the own_oob and peer_oob flags were not being set to 1 even though an OOB pairing request was in progress, which therefore prevented OOB data from being passed down to the softdevice during a OOB pairing operation, thus causing the OOB pairing process to fail. --- .../source/nRF5xPalSecurityManager.cpp | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xPalSecurityManager.cpp b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xPalSecurityManager.cpp index 61c26d3688..01126720b4 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xPalSecurityManager.cpp +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xPalSecurityManager.cpp @@ -81,11 +81,6 @@ struct nRF5xSecurityManager::pairing_control_block_t { ble_gap_id_key_t peer_id_key; ble_gap_sign_info_t peer_sign_key; ble_gap_lesc_p256_pk_t peer_pk; - - // flag required to help DHKey computation/process; should be removed with - // later versions of the softdevice - uint8_t own_oob:1; - uint8_t peer_oob:1; }; nRF5xSecurityManager::nRF5xSecurityManager() @@ -663,26 +658,37 @@ ble_error_t nRF5xSecurityManager::secure_connections_oob_request_reply( const oob_lesc_value_t &peer_random, const oob_confirm_t &peer_confirm ) { + bool have_oob_own; + bool have_oob_peer; + const oob_lesc_value_t zerokey; + ble_gap_lesc_oob_data_t oob_own; + ble_gap_lesc_oob_data_t oob_peer; + pairing_control_block_t* pairing_cb = get_pairing_cb(connection); if (!pairing_cb) { return BLE_ERROR_INVALID_STATE; } - ble_gap_lesc_oob_data_t oob_own; - ble_gap_lesc_oob_data_t oob_peer; + have_oob_own = false; + if (local_random != zerokey) { + have_oob_own = true; + // is own address important ? + memcpy(oob_own.r, local_random.data(), local_random.size()); + // FIXME: What to do with local confirm ??? + } - // is own address important ? - memcpy(oob_own.r, local_random.data(), local_random.size()); - // FIXME: What to do with local confirm ??? - - // is peer address important ? - memcpy(oob_peer.r, peer_random.data(), peer_random.size()); - memcpy(oob_peer.c, peer_confirm.data(), peer_confirm.size()); + have_oob_peer = false; + if (peer_random != zerokey && peer_confirm != zerokey) { + have_oob_peer = true; + // is peer address important ? + memcpy(oob_peer.r, peer_random.data(), peer_random.size()); + memcpy(oob_peer.c, peer_confirm.data(), peer_confirm.size()); + } uint32_t err = sd_ble_gap_lesc_oob_data_set( connection, - pairing_cb->own_oob ? &oob_own : NULL, - pairing_cb->peer_oob ? &oob_peer : NULL + have_oob_own ? &oob_own : NULL, + have_oob_peer ? &oob_peer : NULL ); return convert_sd_error(err);