@@ -548,7 +548,7 @@ ble_error_t GenericGap::connect(
548
548
_initiator_policy_mode,
549
549
(pal::connection_peer_address_type_t ::type) peerAddrType,
550
550
ble::address_t (peerAddr),
551
- get_own_address_type (true /* central */ , false /* requires resolvable address */ ),
551
+ get_own_address_type (CENTRAL_CONNECTION /* requires resolvable address */ ),
552
552
connectionParams->minConnectionInterval ,
553
553
connectionParams->maxConnectionInterval ,
554
554
connectionParams->slaveLatency ,
@@ -836,7 +836,7 @@ ble_error_t GenericGap::startRadioScan(const GapScanningParams &scanningParams)
836
836
return BLE_ERROR_INVALID_STATE;
837
837
}
838
838
839
- pal::own_address_type_t own_address_type = get_own_address_type (true /* central */ , true /* can use non resolvable address for scan requests */ );
839
+ pal::own_address_type_t own_address_type = get_own_address_type (CENTRAL_SCAN /* central, can use non resolvable address for scan requests */ );
840
840
841
841
if (_privacy_enabled && (own_address_type == pal::own_address_type_t ::RANDOM_ADDRESS))
842
842
{
@@ -952,8 +952,12 @@ ble_error_t GenericGap::startAdvertising(const GapAdvertisingParams& params)
952
952
return BLE_ERROR_INVALID_PARAM;
953
953
}
954
954
955
- pal::own_address_type_t own_address_type = get_own_address_type (false /* peripheral */ ,
956
- params.getAdvertisingType () == GapAdvertisingParams::ADV_SCANNABLE_UNDIRECTED /* we can only use non resolvable addresses int this case */ );
955
+ // We can only use non resolvable addresses if the device is non connectable
956
+ AddressUseType_t address_use_type =
957
+ ((params.getAdvertisingType () == GapAdvertisingParams::ADV_SCANNABLE_UNDIRECTED)
958
+ || (params.getAdvertisingType () == GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED))
959
+ ? PERIPHERAL_NON_CONNECTABLE : PERIPHERAL_CONNECTABLE;
960
+ pal::own_address_type_t own_address_type = get_own_address_type (address_use_type);
957
961
958
962
if (_privacy_enabled && (own_address_type == pal::own_address_type_t ::RANDOM_ADDRESS))
959
963
{
@@ -1276,18 +1280,18 @@ void GenericGap::on_unexpected_error(const pal::GapUnexpectedErrorEvent& e)
1276
1280
// has been updated.
1277
1281
}
1278
1282
1279
- pal::own_address_type_t GenericGap::get_own_address_type (bool central_not_peripheral, bool non_connectable_or_scan_request )
1283
+ pal::own_address_type_t GenericGap::get_own_address_type (AddressUseType_t address_use_type )
1280
1284
{
1281
1285
if (_privacy_enabled) {
1282
- bool can_use_non_resolvable_address = false ;
1283
- if (central_not_peripheral ) {
1284
- can_use_non_resolvable_address = _central_privacy_configuration.use_non_resolvable_random_address ;
1285
- } else {
1286
- can_use_non_resolvable_address = _peripheral_privacy_configuration.use_non_resolvable_random_address ;
1286
+ bool use_non_resolvable_address = false ;
1287
+ if (address_use_type == CENTRAL_SCAN ) {
1288
+ use_non_resolvable_address = _central_privacy_configuration.use_non_resolvable_random_address ;
1289
+ } else if (address_use_type == PERIPHERAL_NON_CONNECTABLE) {
1290
+ use_non_resolvable_address = _peripheral_privacy_configuration.use_non_resolvable_random_address ;
1287
1291
}
1288
1292
1289
1293
// An non resolvable private address should be generated
1290
- if (non_connectable_or_scan_request && can_use_non_resolvable_address ) {
1294
+ if (use_non_resolvable_address ) {
1291
1295
return pal::own_address_type_t ::RANDOM_ADDRESS;
1292
1296
}
1293
1297
0 commit comments