Skip to content

Commit f79eeb0

Browse files
committed
Cordio: Update stack and pal to support LE security mode 2 level 2.
1 parent 01e3a00 commit f79eeb0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+52
-3
lines changed

features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalSecurityManager.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "wsf_os.h"
2323
#include "sec_api.h"
2424
#include "smp_defs.h"
25+
#include "cfg_stack.h"
2526

2627
namespace ble {
2728
namespace pal {
@@ -252,6 +253,8 @@ class CordioSecurityManager : public ::ble::pal::SecurityManager {
252253
sign_count_t sign_counter
253254
);
254255

256+
virtual ble_error_t remove_peer_csrk(connection_handle_t connection);
257+
255258
////////////////////////////////////////////////////////////////////////////
256259
// Authentication
257260
//
@@ -322,12 +325,15 @@ class CordioSecurityManager : public ::ble::pal::SecurityManager {
322325
static bool sm_handler(const wsfMsgHdr_t* msg);
323326

324327
private:
328+
void cleanup_peer_csrks();
329+
325330
bool _use_default_passkey;
326331
passkey_num_t _default_passkey;
327332
bool _lesc_keys_generated;
328333
uint8_t _public_key_x[SEC_ECC_KEY_LEN];
329334
irk_t _irk;
330335
csrk_t _csrk;
336+
csrk_t* _peer_csrks[DM_CONN_MAX];
331337
};
332338

333339
} // cordio

features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioPalSecurityManager.cpp

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ CordioSecurityManager::CordioSecurityManager() :
3333
_use_default_passkey(false),
3434
_default_passkey(0),
3535
_lesc_keys_generated(false),
36-
_public_key_x()
36+
_public_key_x(),
37+
_peer_csrks()
3738
{
3839

3940
}
@@ -53,6 +54,7 @@ ble_error_t CordioSecurityManager::initialize()
5354
_use_default_passkey = false;
5455
_default_passkey = 0;
5556
_lesc_keys_generated = false;
57+
memset(_peer_csrks, 0, sizeof(_peer_csrks));
5658

5759
#if 0
5860
// FIXME: need help from the stack or local calculation
@@ -65,11 +67,13 @@ ble_error_t CordioSecurityManager::initialize()
6567

6668
ble_error_t CordioSecurityManager::terminate()
6769
{
70+
cleanup_peer_csrks();
6871
return BLE_ERROR_NONE;
6972
}
7073

7174
ble_error_t CordioSecurityManager::reset()
7275
{
76+
cleanup_peer_csrks();
7377
initialize();
7478
return BLE_ERROR_NONE;
7579
}
@@ -287,9 +291,40 @@ ble_error_t CordioSecurityManager::set_peer_csrk(
287291
bool authenticated,
288292
sign_count_t sign_counter
289293
) {
290-
AttsSetCsrk(connection, const_cast<uint8_t*>(csrk.data()));
294+
if (connection == 0 || connection > DM_CONN_MAX) {
295+
return BLE_ERROR_INVALID_PARAM;
296+
}
297+
298+
size_t connection_index = connection - 1;
299+
300+
if (_peer_csrks[connection_index]) {
301+
*_peer_csrks[connection_index] = csrk;
302+
} else {
303+
_peer_csrks[connection_index] = new (std::nothrow) csrk_t(csrk);
304+
if (_peer_csrks[connection_index] == NULL) {
305+
return BLE_ERROR_NO_MEM;
306+
}
307+
}
308+
309+
AttsSetCsrk(connection, _peer_csrks[connection_index]->data(), authenticated);
291310
AttsSetSignCounter(connection, sign_counter);
311+
return BLE_ERROR_NONE;
312+
}
292313

314+
ble_error_t CordioSecurityManager::remove_peer_csrk(connection_handle_t connection)
315+
{
316+
if (connection == 0 || connection > DM_CONN_MAX) {
317+
return BLE_ERROR_INVALID_PARAM;
318+
}
319+
320+
size_t connection_index = connection - 1;
321+
322+
if (_peer_csrks[connection_index]) {
323+
delete _peer_csrks[connection_index];
324+
_peer_csrks[connection_index] = NULL;
325+
}
326+
327+
AttsSetCsrk(connection, NULL, false);
293328
return BLE_ERROR_NONE;
294329
}
295330

@@ -695,6 +730,14 @@ bool CordioSecurityManager::sm_handler(const wsfMsgHdr_t* msg) {
695730
}
696731
}
697732

733+
void CordioSecurityManager::cleanup_peer_csrks() {
734+
for (size_t i = 0; i < DM_CONN_MAX; ++i) {
735+
if (_peer_csrks[i]) {
736+
delete _peer_csrks[i];
737+
_peer_csrks[i] = NULL;
738+
}
739+
}
740+
}
698741

699742
} // cordio
700743
} // vendor

features/FEATURE_BLE/targets/TARGET_CORDIO/stack/cordio_stack/sw/stack/include/att_api.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ uint16_t AttsCccEnabled(dmConnId_t connId, uint8_t idx);
565565
* \return None.
566566
*/
567567
/*************************************************************************************************/
568-
void AttsSetCsrk(dmConnId_t connId, uint8_t *pCsrk);
568+
void AttsSetCsrk(dmConnId_t connId, uint8_t *pCsrk, bool_t authenticated);
569569

570570
/*************************************************************************************************/
571571
/*!

0 commit comments

Comments
 (0)