Skip to content

Commit 20a4412

Browse files
author
Cruz Monrreal
authored
Merge pull request #7089 from paul-szczepanek-arm/fix-master
BLE fixes (SM whitelist creation, Nordic scatter file fix, missing TLS initialisation)
2 parents 0e7561f + 4d01268 commit 20a4412

File tree

7 files changed

+32
-12
lines changed

7 files changed

+32
-12
lines changed

features/FEATURE_BLE/ble/generic/SecurityDb.h

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -584,28 +584,32 @@ class SecurityDb {
584584
WhitelistDbCb_t cb,
585585
::Gap::Whitelist_t *whitelist
586586
) {
587-
for (size_t i = 0; i < get_entry_count() && i < whitelist->capacity; i++) {
587+
for (size_t i = 0; i < get_entry_count() && whitelist->size < whitelist->capacity; i++) {
588588
entry_handle_t db_handle = get_entry_handle_by_index(i);
589589
SecurityDistributionFlags_t* flags = get_distribution_flags(db_handle);
590590

591591
if (!flags) {
592592
continue;
593593
}
594594

595+
SecurityEntryIdentity_t* identity = read_in_entry_peer_identity(db_handle);
596+
if (!identity) {
597+
continue;
598+
}
599+
600+
memcpy(
601+
whitelist->addresses[whitelist->size].address,
602+
identity->identity_address.data(),
603+
sizeof(BLEProtocol::AddressBytes_t)
604+
);
605+
595606
if (flags->peer_address_is_public) {
596-
whitelist->addresses[i].type = BLEProtocol::AddressType::PUBLIC;
607+
whitelist->addresses[whitelist->size].type = BLEProtocol::AddressType::PUBLIC;
597608
} else {
598-
whitelist->addresses[i].type = BLEProtocol::AddressType::RANDOM_STATIC;
609+
whitelist->addresses[whitelist->size].type = BLEProtocol::AddressType::RANDOM_STATIC;
599610
}
600611

601-
SecurityEntryIdentity_t* identity = read_in_entry_peer_identity(db_handle);
602-
if (identity) {
603-
memcpy(
604-
whitelist->addresses[i].address,
605-
identity->identity_address.data(),
606-
sizeof(BLEProtocol::AddressBytes_t)
607-
);
608-
}
612+
whitelist->size++;
609613
}
610614

611615
cb(whitelist);

features/FEATURE_BLE/source/generic/GenericSecurityManager.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ ble_error_t GenericSecurityManager::purgeAllBondingState(void) {
142142
ble_error_t GenericSecurityManager::generateWhitelistFromBondTable(Gap::Whitelist_t *whitelist) const {
143143
if (!_db) return BLE_ERROR_INITIALIZATION_INCOMPLETE;
144144
if (eventHandler) {
145+
if (!whitelist) {
146+
return BLE_ERROR_INVALID_PARAM;
147+
}
145148
_db->generate_whitelist_from_bond_table(
146149
mbed::callback(eventHandler, &::SecurityManager::EventHandler::whitelistFromBondTable),
147150
whitelist

features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF51/source/nRF5xGap.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1266,7 +1266,7 @@ void nRF5xGap::on_connection(Gap::Handle_t handle, const ble_gap_evt_connected_t
12661266
const resolving_list_entry_t* entry = get_sm().resolve_address(
12671267
evt.peer_addr.addr
12681268
);
1269-
MBED_ASSERT(entry == NULL);
1269+
MBED_ASSERT(entry != NULL);
12701270

12711271
peer_addr_type = convert_identity_address(entry->peer_identity_address_type);
12721272
peer_address = entry->peer_identity_address.data();

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ namespace vendor {
4747
namespace nordic {
4848

4949
CryptoToolbox::CryptoToolbox() : _initialized(false) {
50+
mbedtls_platform_setup(&_platform_context);
5051
mbedtls_entropy_init(&_entropy_context);
5152
mbedtls_ecp_group_init(&_group);
5253
int err = mbedtls_ecp_group_load(
@@ -59,6 +60,7 @@ CryptoToolbox::CryptoToolbox() : _initialized(false) {
5960
CryptoToolbox::~CryptoToolbox() {
6061
mbedtls_ecp_group_free(&_group);
6162
mbedtls_entropy_free(&_entropy_context);
63+
mbedtls_platform_teardown(&_platform_context);
6264
}
6365

6466
bool CryptoToolbox::generate_keys(

features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF52/source/nRF5xCrypto.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ class CryptoToolbox : mbed::NonCopyable<CryptoToolbox> {
132132
void swap_endian(uint8_t* buf, size_t len);
133133

134134
bool _initialized;
135+
mbedtls_platform_context _platform_context;
135136
mbedtls_entropy_context _entropy_context;
136137
mbedtls_ecp_group _group;
137138
};

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52832/device/TOOLCHAIN_ARM_STD/nRF52832.sct

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ LR_IROM1 MBED_APP_START MBED_APP_SIZE {
2727
ER_IROM1 MBED_APP_START MBED_APP_SIZE {
2828
*.o (RESET, +First)
2929
*(InRoot$$Sections)
30+
__start_sdh_soc_observers *(sdh_soc_observers) __stop_sdh_soc_observers
31+
__start_sdh_stack_observers *(sdh_stack_observers) __stop_sdh_stack_observers
32+
__start_sdh_req_observers *(sdh_req_observers) __stop_sdh_req_observers
33+
__start_sdh_state_observers *(sdh_state_observers) __stop_sdh_state_observers
34+
__start_sdh_ble_observers *(sdh_ble_observers) __stop_sdh_ble_observers
3035
.ANY (+RO)
3136
}
3237
RW_IRAM0 MBED_RAM0_START UNINIT MBED_RAM0_SIZE { ;no init section

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/device/TOOLCHAIN_ARM_STD/nRF52840.sct

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ LR_IROM1 MBED_APP_START MBED_APP_SIZE {
2727
ER_IROM1 MBED_APP_START MBED_APP_SIZE {
2828
*.o (RESET, +First)
2929
*(InRoot$$Sections)
30+
__start_sdh_soc_observers *(sdh_soc_observers) __stop_sdh_soc_observers
31+
__start_sdh_stack_observers *(sdh_stack_observers) __stop_sdh_stack_observers
32+
__start_sdh_req_observers *(sdh_req_observers) __stop_sdh_req_observers
33+
__start_sdh_state_observers *(sdh_state_observers) __stop_sdh_state_observers
34+
__start_sdh_ble_observers *(sdh_ble_observers) __stop_sdh_ble_observers
3035
.ANY (+RO)
3136
}
3237
RW_IRAM0 MBED_RAM0_START UNINIT MBED_RAM0_SIZE { ;no init section

0 commit comments

Comments
 (0)