@@ -2365,6 +2365,9 @@ void Gap::signal_connection_complete(
2365
2365
2366
2366
/* if successful then proceed to call the handler immediately same as for when privacy is disabled */
2367
2367
if (address_resolved) {
2368
+ if (!apply_peripheral_privacy_connection_policy (event)) {
2369
+ return ;
2370
+ }
2368
2371
report_internal_connection_complete (event);
2369
2372
_event_handler->onConnectionComplete (event);
2370
2373
} else {
@@ -2398,15 +2401,64 @@ void Gap::signal_connection_complete(
2398
2401
}
2399
2402
2400
2403
#if BLE_FEATURE_PRIVACY
2404
+
2405
+ bool Gap::apply_peripheral_privacy_connection_policy (
2406
+ const ConnectionCompleteEvent &event
2407
+ )
2408
+ {
2409
+ #if BLE_ROLE_PERIPHERAL
2410
+ if (event.getOwnRole () != connection_role_t ::PERIPHERAL) {
2411
+ return true ;
2412
+ }
2413
+
2414
+ if (event.getPeerAddressType () != peer_address_type_t ::RANDOM) {
2415
+ return true ;
2416
+ }
2417
+
2418
+ if (!is_random_private_resolvable_address (event.getPeerAddress ())) {
2419
+ return true ;
2420
+ }
2421
+
2422
+ auto connection_handle = event.getConnectionHandle ();
2423
+
2424
+ switch (_peripheral_privacy_configuration.resolution_strategy ) {
2425
+ case peripheral_privacy_configuration_t ::REJECT_NON_RESOLVED_ADDRESS:
2426
+ _pal_gap.disconnect (
2427
+ connection_handle,
2428
+ local_disconnection_reason_t ::AUTHENTICATION_FAILURE
2429
+ );
2430
+ return false ;
2431
+
2432
+ case peripheral_privacy_configuration_t ::PERFORM_PAIRING_PROCEDURE:
2433
+ _event_queue.post ([connection_handle] {
2434
+ BLE::Instance ().securityManager ().requestAuthentication (connection_handle);
2435
+ });
2436
+ return true ;
2437
+
2438
+ case peripheral_privacy_configuration_t ::PERFORM_AUTHENTICATION_PROCEDURE:
2439
+ _event_queue.post ([connection_handle] {
2440
+ BLE::Instance ().securityManager ().setLinkSecurity (
2441
+ connection_handle,
2442
+ ble::SecurityManager::SecurityMode_t::SECURITY_MODE_ENCRYPTION_WITH_MITM
2443
+ );
2444
+ });
2445
+ return true ;
2446
+
2447
+ default :
2448
+ return true ;
2449
+ }
2450
+ #else
2451
+ return true ;
2452
+ #endif
2453
+ }
2454
+
2455
+
2401
2456
void Gap::conclude_signal_connection_complete_after_address_resolution (
2402
2457
ConnectionCompleteEvent &event,
2403
2458
target_peer_address_type_t identity_address_type,
2404
2459
const address_t *identity_address
2405
2460
)
2406
2461
{
2407
- #if BLE_ROLE_PERIPHERAL
2408
- bool resolvable_address_not_known = false ;
2409
- #endif // BLE_ROLE_PERIPHERAL
2410
2462
/* fix the event addresses */
2411
2463
if (identity_address) {
2412
2464
/* move old address to resolvable address */
@@ -2418,42 +2470,13 @@ void Gap::conclude_signal_connection_complete_after_address_resolution(
2418
2470
peer_address_type_t ::RANDOM_STATIC_IDENTITY
2419
2471
: peer_address_type_t ::PUBLIC_IDENTITY);
2420
2472
}
2421
- #if BLE_ROLE_PERIPHERAL
2422
- if (!identity_address) {
2423
- if (_peripheral_privacy_configuration.resolution_strategy ==
2424
- peripheral_privacy_configuration_t ::REJECT_NON_RESOLVED_ADDRESS) {
2425
- // Reject connection request - the user will get notified through a callback
2426
- _pal_gap.disconnect (
2427
- event.getConnectionHandle (),
2428
- local_disconnection_reason_t ::AUTHENTICATION_FAILURE
2429
- );
2430
- return ;
2431
- }
2432
- resolvable_address_not_known = true ;
2473
+
2474
+ if (!apply_peripheral_privacy_connection_policy (event)) {
2475
+ return ;
2433
2476
}
2434
- #endif // BLE_ROLE_PERIPHERAL
2435
2477
2436
2478
report_internal_connection_complete (event);
2437
2479
_event_handler->onConnectionComplete (event);
2438
- #if BLE_ROLE_PERIPHERAL
2439
- #if BLE_FEATURE_SECURITY
2440
- if (resolvable_address_not_known) {
2441
- ble::SecurityManager &sm = BLE::Instance ().securityManager ();
2442
- if (_peripheral_privacy_configuration.resolution_strategy ==
2443
- peripheral_privacy_configuration_t ::PERFORM_PAIRING_PROCEDURE) {
2444
-
2445
- // Request authentication to start pairing procedure
2446
- sm.requestAuthentication (event.getConnectionHandle ());
2447
- } else if (_peripheral_privacy_configuration.resolution_strategy ==
2448
- peripheral_privacy_configuration_t ::PERFORM_AUTHENTICATION_PROCEDURE) {
2449
- sm.setLinkSecurity (
2450
- event.getConnectionHandle (),
2451
- ble::SecurityManager::SecurityMode_t::SECURITY_MODE_ENCRYPTION_WITH_MITM
2452
- );
2453
- }
2454
- }
2455
- #endif // BLE_FEATURE_SECURITY
2456
- #endif // BLE_ROLE_PERIPHERAL
2457
2480
}
2458
2481
#endif // BLE_FEATURE_PRIVACY
2459
2482
#endif // BLE_FEATURE_CONNECTABLE
0 commit comments