Skip to content

Commit fbb926d

Browse files
call the correct ltk function when SC is used
1 parent 8292aff commit fbb926d

File tree

1 file changed

+44
-29
lines changed

1 file changed

+44
-29
lines changed

features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF52/source/nRF5xPalSecurityManager.cpp

Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -846,11 +846,19 @@ bool nRF5xSecurityManager::sm_handler(const ble_evt_t *evt)
846846
const ble_gap_evt_sec_info_request_t& req =
847847
gap_evt.params.sec_info_request;
848848

849-
handler->on_ltk_request(
850-
connection,
851-
ediv_t((uint8_t*)(&req.master_id.ediv)),
852-
rand_t(req.master_id.rand)
853-
);
849+
uint8_t invalid_rand[BLE_GAP_SEC_RAND_LEN] = { 0 };
850+
if (req.master_id.ediv == 0 &&
851+
memcmp(req.master_id.rand, invalid_rand, sizeof(invalid_rand) == 0)
852+
) {
853+
// request ltk generated with secure connection
854+
handler->on_ltk_request(connection);
855+
} else {
856+
handler->on_ltk_request(
857+
connection,
858+
ediv_t((uint8_t*)(&req.master_id.ediv)),
859+
rand_t(req.master_id.rand)
860+
);
861+
}
854862

855863
return true;
856864
}
@@ -948,34 +956,41 @@ bool nRF5xSecurityManager::sm_handler(const ble_evt_t *evt)
948956
peer_dist = pairing_cb->initiator_dist;
949957
}
950958

951-
if (own_dist.get_encryption()) {
952-
handler->on_keys_distributed_local_ltk(
959+
if (status.lesc) {
960+
handler->on_secure_connections_ltk_generated(
953961
connection,
954962
ltk_t(pairing_cb->own_enc_key.enc_info.ltk)
955963
);
964+
} else {
965+
if (own_dist.get_encryption()) {
966+
handler->on_keys_distributed_local_ltk(
967+
connection,
968+
ltk_t(pairing_cb->own_enc_key.enc_info.ltk)
969+
);
970+
971+
handler->on_keys_distributed_local_ediv_rand(
972+
connection,
973+
ediv_t(reinterpret_cast<uint8_t*>(
974+
&pairing_cb->own_enc_key.master_id.ediv
975+
)),
976+
pairing_cb->own_enc_key.master_id.rand
977+
);
978+
}
956979

957-
handler->on_keys_distributed_local_ediv_rand(
958-
connection,
959-
ediv_t(reinterpret_cast<uint8_t*>(
960-
&pairing_cb->own_enc_key.master_id.ediv
961-
)),
962-
pairing_cb->own_enc_key.master_id.rand
963-
);
964-
}
965-
966-
if (peer_dist.get_encryption()) {
967-
handler->on_keys_distributed_ltk(
968-
connection,
969-
ltk_t(pairing_cb->peer_enc_key.enc_info.ltk)
970-
);
971-
972-
handler->on_keys_distributed_ediv_rand(
973-
connection,
974-
ediv_t(reinterpret_cast<uint8_t*>(
975-
&pairing_cb->peer_enc_key.master_id.ediv
976-
)),
977-
pairing_cb->peer_enc_key.master_id.rand
978-
);
980+
if (peer_dist.get_encryption()) {
981+
handler->on_keys_distributed_ltk(
982+
connection,
983+
ltk_t(pairing_cb->peer_enc_key.enc_info.ltk)
984+
);
985+
986+
handler->on_keys_distributed_ediv_rand(
987+
connection,
988+
ediv_t(reinterpret_cast<uint8_t*>(
989+
&pairing_cb->peer_enc_key.master_id.ediv
990+
)),
991+
pairing_cb->peer_enc_key.master_id.rand
992+
);
993+
}
979994
}
980995

981996
if (peer_dist.get_identity()) {

0 commit comments

Comments
 (0)