Skip to content

Commit 288c395

Browse files
author
Donatien Garnier
committed
Address Paul's comments
1 parent 6c6af1b commit 288c395

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

features/FEATURE_BLE/ble/generic/GenericGap.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,14 @@ class GenericGap : public ::Gap,
340340

341341
void on_unexpected_error(const pal::GapUnexpectedErrorEvent &e);
342342

343-
pal::own_address_type_t get_own_address_type(bool central_not_peripheral, bool non_connectable_or_scan_request);
343+
enum AddressUseType_t {
344+
CENTRAL_CONNECTION,
345+
CENTRAL_SCAN,
346+
PERIPHERAL_CONNECTABLE,
347+
PERIPHERAL_NON_CONNECTABLE
348+
};
349+
350+
pal::own_address_type_t get_own_address_type(AddressUseType_t address_use_type);
344351

345352
bool initialize_whitelist() const;
346353

features/FEATURE_BLE/source/generic/GenericGap.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ ble_error_t GenericGap::connect(
548548
_initiator_policy_mode,
549549
(pal::connection_peer_address_type_t::type) peerAddrType,
550550
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 */),
552552
connectionParams->minConnectionInterval,
553553
connectionParams->maxConnectionInterval,
554554
connectionParams->slaveLatency,
@@ -836,7 +836,7 @@ ble_error_t GenericGap::startRadioScan(const GapScanningParams &scanningParams)
836836
return BLE_ERROR_INVALID_STATE;
837837
}
838838

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 */);
840840

841841
if(_privacy_enabled && (own_address_type == pal::own_address_type_t::RANDOM_ADDRESS))
842842
{
@@ -952,8 +952,12 @@ ble_error_t GenericGap::startAdvertising(const GapAdvertisingParams& params)
952952
return BLE_ERROR_INVALID_PARAM;
953953
}
954954

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);
957961

958962
if(_privacy_enabled && (own_address_type == pal::own_address_type_t::RANDOM_ADDRESS))
959963
{
@@ -1276,18 +1280,18 @@ void GenericGap::on_unexpected_error(const pal::GapUnexpectedErrorEvent& e)
12761280
// has been updated.
12771281
}
12781282

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)
12801284
{
12811285
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;
12871291
}
12881292

12891293
// 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) {
12911295
return pal::own_address_type_t::RANDOM_ADDRESS;
12921296
}
12931297

0 commit comments

Comments
 (0)