|
28 | 28 | #include "nRF5xPalSecurityManager.h"
|
29 | 29 |
|
30 | 30 | using ble::pal::vendor::nordic::nRF5xSecurityManager;
|
31 |
| -typedef nRF5xSecurityManager::resolving_list_entry_t resolving_list_entry_t; |
32 | 31 | using ble::ArrayView;
|
33 | 32 | using ble::pal::advertising_peer_address_type_t;
|
34 | 33 |
|
@@ -316,6 +315,20 @@ ble_error_t nRF5xGap::startAdvertising(const GapAdvertisingParams ¶ms)
|
316 | 315 | }
|
317 | 316 | }
|
318 | 317 | adv_para.p_whitelist = &whitelist;
|
| 318 | +#else |
| 319 | + if (_privacy_enabled) { |
| 320 | + bool enable_resolution = |
| 321 | + _peripheral_privacy_configuration.resolution_strategy != PeripheralPrivacyConfiguration_t::DO_NOT_RESOLVE; |
| 322 | + update_identities_list(enable_resolution); |
| 323 | + |
| 324 | + if (_peripheral_privacy_configuration.use_non_resolvable_random_address && |
| 325 | + is_advertising_non_connectable(params) |
| 326 | + ) { |
| 327 | + set_private_non_resolvable_address(); |
| 328 | + } else { |
| 329 | + set_private_resolvable_address(); |
| 330 | + } |
| 331 | + } |
319 | 332 | #endif
|
320 | 333 | /* For NRF_SD_BLE_API_VERSION >= 3 nRF5xGap::setWhitelist setups the whitelist. */
|
321 | 334 |
|
@@ -384,7 +397,13 @@ ble_error_t nRF5xGap::startRadioScan(const GapScanningParams &scanningParams)
|
384 | 397 | scanParams.interval = scanningParams.getInterval(); /**< Scan interval between 0x0004 and 0x4000 in 0.625ms units (2.5ms to 10.24s). */
|
385 | 398 | scanParams.window = scanningParams.getWindow(); /**< Scan window between 0x0004 and 0x4000 in 0.625ms units (2.5ms to 10.24s). */
|
386 | 399 | scanParams.timeout = scanningParams.getTimeout(); /**< Scan timeout between 0x0001 and 0xFFFF in seconds, 0x0000 disables timeout. */
|
| 400 | + |
387 | 401 | if (_privacy_enabled) {
|
| 402 | + bool enable_resolution = |
| 403 | + _central_privacy_configuration.resolution_strategy != CentralPrivacyConfiguration_t::DO_NOT_RESOLVE; |
| 404 | + |
| 405 | + update_identities_list(enable_resolution); |
| 406 | + |
388 | 407 | if (_central_privacy_configuration.use_non_resolvable_random_address) {
|
389 | 408 | set_private_non_resolvable_address();
|
390 | 409 | } else {
|
@@ -524,7 +543,15 @@ ble_error_t nRF5xGap::connect(const Address_t peerAddr,
|
524 | 543 | } else {
|
525 | 544 | addr.addr_id_peer = 0;
|
526 | 545 | }
|
527 |
| - |
| 546 | + |
| 547 | + if (_privacy_enabled) { |
| 548 | + bool enable_resolution = |
| 549 | + _central_privacy_configuration.resolution_strategy != CentralPrivacyConfiguration_t::DO_NOT_RESOLVE; |
| 550 | + |
| 551 | + update_identities_list(enable_resolution); |
| 552 | + set_private_resolvable_address(); |
| 553 | + } |
| 554 | + |
528 | 555 | #endif
|
529 | 556 |
|
530 | 557 | if (scanParamsIn != NULL) {
|
@@ -1201,6 +1228,37 @@ void nRF5xGap::processDisconnectionEvent(
|
1201 | 1228 | );
|
1202 | 1229 | }
|
1203 | 1230 |
|
| 1231 | +ble_error_t nRF5xGap::update_identities_list(bool resolution_enabled) |
| 1232 | +{ |
| 1233 | + uint32_t err; |
| 1234 | + |
| 1235 | + if (resolution_enabled) { |
| 1236 | + ArrayView<ble_gap_id_key_t> entries = get_sm().get_resolving_list(); |
| 1237 | + size_t limit = std::min( |
| 1238 | + entries.size(), (size_t) YOTTA_CFG_IRK_TABLE_MAX_SIZE |
| 1239 | + ); |
| 1240 | + ble_gap_id_key_t* id_keys_pp[YOTTA_CFG_IRK_TABLE_MAX_SIZE]; |
| 1241 | + |
| 1242 | + for (size_t i = 0; i < limit; ++i) { |
| 1243 | + id_keys_pp[i] = &entries[i]; |
| 1244 | + } |
| 1245 | + |
| 1246 | + err = sd_ble_gap_device_identities_set( |
| 1247 | + limit ? id_keys_pp : NULL, |
| 1248 | + /* use the local IRK for all devices */ NULL, |
| 1249 | + limit |
| 1250 | + ); |
| 1251 | + } else { |
| 1252 | + err = sd_ble_gap_device_identities_set( |
| 1253 | + NULL, |
| 1254 | + /* use the local IRK for all devices */ NULL, |
| 1255 | + 0 |
| 1256 | + ); |
| 1257 | + } |
| 1258 | + |
| 1259 | + return err ? BLE_ERROR_INVALID_STATE : BLE_ERROR_NONE; |
| 1260 | +} |
| 1261 | + |
1204 | 1262 | void nRF5xGap::on_connection(Gap::Handle_t handle, const ble_gap_evt_connected_t& evt) {
|
1205 | 1263 | using BLEProtocol::AddressType;
|
1206 | 1264 |
|
@@ -1246,14 +1304,8 @@ void nRF5xGap::on_connection(Gap::Handle_t handle, const ble_gap_evt_connected_t
|
1246 | 1304 |
|
1247 | 1305 |
|
1248 | 1306 | if (private_peer_known) {
|
1249 |
| - // FIXME: Is this correct for SD > 2 ? |
1250 |
| - const resolving_list_entry_t* entry = get_sm().resolve_address( |
1251 |
| - evt.peer_addr.addr |
1252 |
| - ); |
1253 |
| - MBED_ASSERT(entry == NULL); |
1254 |
| - |
1255 |
| - peer_addr_type = convert_identity_address(entry->peer_identity_address_type); |
1256 |
| - peer_address = entry->peer_identity_address.data(); |
| 1307 | + peer_addr_type = convert_nordic_address(evt.peer_addr.addr_type);; |
| 1308 | + peer_address = evt.peer_addr.addr; |
1257 | 1309 | peer_resolvable_address = evt.peer_addr.addr;
|
1258 | 1310 | } else {
|
1259 | 1311 | if (_privacy_enabled &&
|
@@ -1294,7 +1346,7 @@ void nRF5xGap::on_connection(Gap::Handle_t handle, const ble_gap_evt_connected_t
|
1294 | 1346 | ) {
|
1295 | 1347 | switch (_peripheral_privacy_configuration.resolution_strategy) {
|
1296 | 1348 | case PeripheralPrivacyConfiguration_t::PERFORM_PAIRING_PROCEDURE:
|
1297 |
| - nRF5xn::Instance(BLE::DEFAULT_INSTANCE).getSecurityManager().requestPairing(handle); |
| 1349 | + nRF5xn::Instance(BLE::DEFAULT_INSTANCE).getSecurityManager().requestAuthentication(handle); |
1298 | 1350 | break;
|
1299 | 1351 |
|
1300 | 1352 | case PeripheralPrivacyConfiguration_t::PERFORM_AUTHENTICATION_PROCEDURE:
|
@@ -1322,32 +1374,16 @@ void nRF5xGap::on_connection(Gap::Handle_t handle, const ble_gap_evt_connected_t
|
1322 | 1374 | void nRF5xGap::on_advertising_packet(const ble_gap_evt_adv_report_t &evt) {
|
1323 | 1375 | using BLEProtocol::AddressType;
|
1324 | 1376 |
|
1325 |
| - AddressType_t peer_addr_type; |
1326 |
| - const uint8_t* peer_address = evt.peer_addr.addr; |
1327 |
| - |
1328 | 1377 | if (_privacy_enabled &&
|
1329 |
| - evt.peer_addr.addr_type == BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE && |
1330 |
| - _central_privacy_configuration.resolution_strategy != CentralPrivacyConfiguration_t::DO_NOT_RESOLVE |
| 1378 | + evt.peer_addr.addr_id_peer == 0 && |
| 1379 | + _central_privacy_configuration.resolution_strategy == CentralPrivacyConfiguration_t::RESOLVE_AND_FILTER |
1331 | 1380 | ) {
|
1332 |
| - using ble::pal::vendor::nordic::nRF5xSecurityManager; |
1333 |
| - |
1334 |
| - const resolving_list_entry_t* entry = get_sm().resolve_address( |
1335 |
| - peer_address |
1336 |
| - ); |
1337 |
| - |
1338 |
| - if (entry) { |
1339 |
| - peer_address = entry->peer_identity_address.data(); |
1340 |
| - peer_addr_type = convert_identity_address(entry->peer_identity_address_type); |
1341 |
| - } else if (_central_privacy_configuration.resolution_strategy != CentralPrivacyConfiguration_t::RESOLVE_AND_FORWARD) { |
1342 |
| - peer_addr_type = convert_nordic_address(evt.peer_addr.addr_type); |
1343 |
| - } else { |
1344 |
| - // filter out the packet. |
1345 |
| - return; |
1346 |
| - } |
1347 |
| - } else { |
1348 |
| - peer_addr_type = convert_nordic_address(evt.peer_addr.addr_type); |
| 1381 | + return; |
1349 | 1382 | }
|
1350 | 1383 |
|
| 1384 | + AddressType_t peer_addr_type = convert_nordic_address(evt.peer_addr.addr_type); |
| 1385 | + const uint8_t* peer_address = evt.peer_addr.addr; |
| 1386 | + |
1351 | 1387 | processAdvertisementReport(
|
1352 | 1388 | peer_address,
|
1353 | 1389 | evt.rssi,
|
|
0 commit comments