From 5237c3ec40506d8cbe7a8f325680ac10b741325e Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Wed, 13 Jun 2018 15:11:13 +0100 Subject: [PATCH] Nordic BLE: Cancel pairing if the device fail to allocate the resources necessary for the pairing operation. --- .../TARGET_NRF51/source/nRF5xPalSecurityManager.cpp | 3 +++ .../TARGET_NRF52/source/nRF5xPalSecurityManager.cpp | 3 +++ 2 files changed, 6 insertions(+) diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF51/source/nRF5xPalSecurityManager.cpp b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF51/source/nRF5xPalSecurityManager.cpp index 3725a639f0..9a4a15fac8 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF51/source/nRF5xPalSecurityManager.cpp +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF51/source/nRF5xPalSecurityManager.cpp @@ -300,6 +300,9 @@ ble_error_t nRF5xSecurityManager::send_pairing_response( ) { pairing_control_block_t* pairing_cb = allocate_pairing_cb(connection); if (!pairing_cb) { + // not enough memory; try to reject the pairing request instead of + // waiting for timeout. + cancel_pairing(connection, pairing_failure_t::UNSPECIFIED_REASON); return BLE_ERROR_NO_MEM; } pairing_cb->role = PAIRING_RESPONDER; diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF52/source/nRF5xPalSecurityManager.cpp b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF52/source/nRF5xPalSecurityManager.cpp index 3842057a38..7894b367c7 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF52/source/nRF5xPalSecurityManager.cpp +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF52/source/nRF5xPalSecurityManager.cpp @@ -277,6 +277,9 @@ ble_error_t nRF5xSecurityManager::send_pairing_response( ) { pairing_control_block_t* pairing_cb = allocate_pairing_cb(connection); if (!pairing_cb) { + // not enough memory; try to reject the pairing request instead of + // waiting for timeout. + cancel_pairing(connection, pairing_failure_t::UNSPECIFIED_REASON); return BLE_ERROR_NO_MEM; } pairing_cb->role = PAIRING_RESPONDER;