Skip to content

Commit 379c86d

Browse files
Merge pull request ARMmbed#11 from pan-/palsm-orig
Cordio update
2 parents e91ab46 + 7b16999 commit 379c86d

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "mbed_assert.h"
3636

3737
#include "CordioPalAttClient.h"
38+
#include "CordioPalSecurityManager.h"
3839

3940
/*! WSF handler ID */
4041
wsfHandlerId_t stack_handler_id;
@@ -238,6 +239,10 @@ void BLE::processEvents()
238239
return;
239240
}
240241

242+
if (ble::pal::vendor::cordio::CordioSecurityManager::get_security_manager().sm_handler(msg)) {
243+
return;
244+
}
245+
241246
switch(msg->event) {
242247
case DM_RESET_CMPL_IND: {
243248
::BLE::InitializationCompleteCallbackContext context = {
@@ -362,11 +367,10 @@ void BLE::stack_setup()
362367
SecInit();
363368

364369
// Note: enable once security is supported
365-
#if 0
370+
SecRandInit();
366371
SecAesInit();
367372
SecCmacInit();
368373
SecEccInit();
369-
#endif
370374

371375
handlerId = WsfOsSetNextHandler(HciHandler);
372376
HciHandlerInit(handlerId);
@@ -400,8 +404,10 @@ void BLE::stack_setup()
400404

401405
handlerId = WsfOsSetNextHandler(SmpHandler);
402406
SmpHandlerInit(handlerId);
407+
SmprInit();
403408
SmprScInit();
404409
SmpiInit();
410+
SmpiScInit();
405411

406412
stack_handler_id = WsfOsSetNextHandler(&BLE::stack_handler);
407413

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

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,13 @@ ble_error_t CordioSecurityManager::set_private_address_timeout(
168168
ble_error_t CordioSecurityManager::set_ltk(
169169
connection_handle_t connection, const ltk_t ltk
170170
) {
171+
// FIXME: get access to the security level of a key
172+
DmSecLtkRsp(
173+
connection,
174+
/* key found */ true,
175+
/* sec level ??? */ DM_SEC_LEVEL_ENC_AUTH,
176+
const_cast<uint8_t*>(ltk)
177+
);
171178
return BLE_ERROR_NOT_IMPLEMENTED;
172179
}
173180

@@ -241,6 +248,9 @@ ble_error_t CordioSecurityManager::send_pairing_request(
241248
KeyDistribution initiator_dist,
242249
KeyDistribution responder_dist
243250
) {
251+
//FIXME: understand if this is required
252+
pSmpCfg->auth = authentication_requirements.value();
253+
244254
DmSecPairReq(
245255
connection,
246256
oob_data_flag,
@@ -428,14 +438,29 @@ bool CordioSecurityManager::sm_handler(const wsfMsgHdr_t* msg) {
428438

429439
switch(evt->type) {
430440
case DM_KEY_LOCAL_LTK:
431-
// TODO: usefull ???
441+
// FIXME: forward local ltk
442+
#if 0
443+
printf("local ltk: ");
444+
for (size_t i = 0; i < sizeof(ltk_t); ++i) {
445+
printf("%02X ", evt->keyData.ltk.key[i]);
446+
}
447+
printf("\r\n");
448+
449+
printf("local ediv: %04X\r\n", evt->keyData.ltk.ediv);
450+
printf("local rand: ");
451+
for (size_t i = 0; i < sizeof(rand_t); ++i) {
452+
printf("%02X ", evt->keyData.ltk.rand[i]);
453+
}
454+
printf("\r\n");
455+
memcpy(local_ltk, evt->keyData.ltk.key, sizeof(local_ltk));
456+
#endif
432457
break;
433458

434459
case DM_KEY_PEER_LTK:
435460
handler->on_keys_distributed_ltk(connection, evt->keyData.ltk.key);
436461
handler->on_keys_distributed_ediv_rand(
437462
connection,
438-
reinterpret_cast<uint8_t*>(evt->keyData.ltk.ediv),
463+
reinterpret_cast<uint8_t*>(&(evt->keyData.ltk.ediv)),
439464
evt->keyData.ltk.rand
440465
);
441466
break;

0 commit comments

Comments
 (0)