From 4fff20583df80a8c35a3265000c4e8079dc975aa Mon Sep 17 00:00:00 2001 From: paul-szczepanek-arm <33840200+paul-szczepanek-arm@users.noreply.github.com> Date: Mon, 9 Apr 2018 17:49:54 +0100 Subject: [PATCH] sign counter kept track by the class using it --- .../targets/TARGET_CORDIO/CordioPalAttClient.h | 17 ++++++++++++++++- .../TARGET_CORDIO/CordioPalSecurityManager.h | 1 - .../source/CordioPalSecurityManager.cpp | 4 ++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalAttClient.h b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalAttClient.h index eb64bafaee..3d536aff52 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalAttClient.h +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalAttClient.h @@ -216,13 +216,26 @@ public: AttcSignedWriteCmd( connection_handle, attribute_handle, - /*TODO: get sign counter from cordio sm */0, + _local_sign_counter, value.size(), const_cast(value.data()) ); + _local_sign_counter++; return BLE_ERROR_NONE; } + /** + * Initialises the counter used to sign messages. Counter will be incremented every + * time a message is signed. + * + * @param sign_counter initialise the signing counter to this value + */ + virtual void set_sign_counter( + sign_count_t sign_counter + ) { + _local_sign_counter = sign_counter; + } + /** * @see ble::pal::AttClient::prepare_write_request */ @@ -612,6 +625,8 @@ private: ); } }; +private: + sign_count_t _local_sign_counter; }; } // cordio diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalSecurityManager.h b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalSecurityManager.h index 9a6cb9ffe1..d7a0a21cd9 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalSecurityManager.h +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalSecurityManager.h @@ -324,7 +324,6 @@ public: private: bool _use_default_passkey; passkey_num_t _default_passkey; - sign_count_t _local_sign_counter; bool _lesc_keys_generated; uint8_t _public_key_x[SEC_ECC_KEY_LEN]; }; diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioPalSecurityManager.cpp b/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioPalSecurityManager.cpp index eb2ac8da37..3143dc1a1b 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioPalSecurityManager.cpp +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioPalSecurityManager.cpp @@ -17,6 +17,7 @@ #include #include "CordioPalSecurityManager.h" +#include "CordioBLE.h" #include "dm_api.h" #include "att_api.h" #include "smp_api.h" @@ -31,7 +32,6 @@ CordioSecurityManager::CordioSecurityManager() : ::ble::pal::SecurityManager(), _use_default_passkey(false), _default_passkey(0), - _local_sign_counter(0), _lesc_keys_generated(false), _public_key_x() { @@ -272,7 +272,7 @@ ble_error_t CordioSecurityManager::set_csrk( const csrk_t& csrk, sign_count_t sign_counter ) { - _local_sign_counter = sign_counter; + CordioAttClient::get_client().set_sign_counter(sign_counter); DmSecSetLocalCsrk(const_cast(csrk.data())); return BLE_ERROR_NONE; }