Skip to content

Commit 0eb680a

Browse files
committed
GenericGap: Revert changes introduced to accomodate privacy.
1 parent 7f05fc0 commit 0eb680a

File tree

1 file changed

+24
-26
lines changed

1 file changed

+24
-26
lines changed

features/FEATURE_BLE/source/generic/GenericGap.cpp

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ static bool is_whitelist_valid(const Gap::Whitelist_t& whitelist)
316316
for (size_t i = 0; i < whitelist.size; ++i) {
317317
const BLEProtocol::Address_t& address = whitelist.addresses[i];
318318
if (address.type != BLEProtocol::AddressType::PUBLIC &&
319-
address.type != BLEProtocol::AddressType::RANDOM
319+
address.type != BLEProtocol::AddressType::RANDOM_STATIC
320320
) {
321321
return false;
322322
}
@@ -423,7 +423,6 @@ ble_error_t GenericGap::setAddress(
423423
_address_type = type;
424424
return BLE_ERROR_NONE;
425425

426-
case BLEProtocol::AddressType::RANDOM:
427426
case BLEProtocol::AddressType::RANDOM_STATIC: {
428427
if (is_random_static_address(address) == false) {
429428
return BLE_ERROR_INVALID_PARAM;
@@ -436,12 +435,18 @@ ble_error_t GenericGap::setAddress(
436435
return err;
437436
}
438437

439-
_address_type = BLEProtocol::AddressType::RANDOM;
438+
_address_type = type;
440439
_address = ble::address_t(address);
441440
_random_static_identity_address = ble::address_t(address);
442441
return BLE_ERROR_NONE;
443442
}
444443

444+
case BLEProtocol::AddressType::RANDOM_PRIVATE_RESOLVABLE:
445+
case BLEProtocol::AddressType::RANDOM_PRIVATE_NON_RESOLVABLE:
446+
// Note: it is not allowed to set directly these addresses
447+
// privacy management handled it for users.
448+
return BLE_ERROR_INVALID_PARAM;
449+
445450
default:
446451
return BLE_ERROR_INVALID_PARAM;
447452
}
@@ -454,17 +459,10 @@ ble_error_t GenericGap::getAddress(
454459
*type = _address_type;
455460
ble::address_t address_value;
456461

457-
switch (_address_type) {
458-
case BLEProtocol::AddressType::PUBLIC:
459-
address_value = _pal_gap.get_device_address();
460-
break;
461-
462-
case BLEProtocol::AddressType::RANDOM:
463-
address_value = _pal_gap.get_random_address();
464-
break;
465-
466-
default:
467-
return BLE_ERROR_INVALID_PARAM;
462+
if (_address_type == BLEProtocol::AddressType::PUBLIC) {
463+
address_value = _pal_gap.get_device_address();
464+
} else {
465+
address_value = _pal_gap.get_random_address();
468466
}
469467

470468
memcpy(address, address_value.data(), address_value.size());
@@ -879,10 +877,10 @@ ble_error_t GenericGap::initRadioNotification(void)
879877
return BLE_ERROR_NOT_IMPLEMENTED;
880878
}
881879

882-
ble_error_t GenericGap::enablePrivacy(bool enable)
880+
ble_error_t GenericGap::enablePrivacy(bool enable)
883881
{
884-
if(enable == _privacy_enabled) {
885-
// No change
882+
if(enable == _privacy_enabled) {
883+
// No change
886884
return BLE_ERROR_NONE;
887885
}
888886

@@ -901,7 +899,7 @@ ble_error_t GenericGap::enablePrivacy(bool enable)
901899

902900
ble_error_t GenericGap::setPeripheralPrivacyConfiguration(
903901
const PeripheralPrivacyConfiguration_t *configuration
904-
)
902+
)
905903
{
906904
_peripheral_privacy_configuration = *configuration;
907905

@@ -912,7 +910,7 @@ ble_error_t GenericGap::setPeripheralPrivacyConfiguration(
912910

913911
ble_error_t GenericGap::getPeripheralPrivacyConfiguration(
914912
PeripheralPrivacyConfiguration_t *configuration
915-
)
913+
)
916914
{
917915
*configuration = _peripheral_privacy_configuration;
918916

@@ -921,7 +919,7 @@ ble_error_t GenericGap::getPeripheralPrivacyConfiguration(
921919

922920
ble_error_t GenericGap::setCentralPrivacyConfiguration(
923921
const CentralPrivacyConfiguration_t *configuration
924-
)
922+
)
925923
{
926924
_central_privacy_configuration = *configuration;
927925

@@ -932,7 +930,7 @@ ble_error_t GenericGap::setCentralPrivacyConfiguration(
932930

933931
ble_error_t GenericGap::getCentralPrivacyConfiguration(
934932
CentralPrivacyConfiguration_t *configuration
935-
)
933+
)
936934
{
937935
*configuration = _central_privacy_configuration;
938936

@@ -962,9 +960,9 @@ ble_error_t GenericGap::startAdvertising(const GapAdvertisingParams& params)
962960
}
963961

964962
// We can only use non resolvable addresses if the device is non connectable
965-
AddressUseType_t address_use_type =
963+
AddressUseType_t address_use_type =
966964
((params.getAdvertisingType() == GapAdvertisingParams::ADV_SCANNABLE_UNDIRECTED)
967-
|| (params.getAdvertisingType() == GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED))
965+
|| (params.getAdvertisingType() == GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED))
968966
? PERIPHERAL_NON_CONNECTABLE : PERIPHERAL_CONNECTABLE;
969967
pal::own_address_type_t own_address_type = get_own_address_type(address_use_type);
970968

@@ -1175,7 +1173,7 @@ void GenericGap::on_connection_complete(const pal::GapConnectionCompleteEvent& e
11751173
// Apply privacy policy if in peripheral mode for non-resolved addresses
11761174
RandomAddressType_t random_address_type(RandomAddressType_t::RESOLVABLE_PRIVATE);
11771175
ble_error_t ret = getRandomAddressType(e.peer_address.data(), &random_address_type);
1178-
if((ret != BLE_ERROR_NONE)
1176+
if((ret != BLE_ERROR_NONE)
11791177
|| (random_address_type == RandomAddressType_t::RESOLVABLE_PRIVATE))
11801178
{
11811179
switch(_peripheral_privacy_configuration.resolution_strategy)
@@ -1242,7 +1240,7 @@ void GenericGap::on_connection_complete(const pal::GapConnectionCompleteEvent& e
12421240
// TODO: GAP Authentication != Security Manager authentication
12431241
// Needs to be implemented
12441242
}
1245-
} else {
1243+
} else {
12461244
// for now notify user that the connection failled by issuing a timeout
12471245
// event
12481246

@@ -1369,7 +1367,7 @@ void GenericGap::set_random_address_rotation(bool enable)
13691367
_random_address_rotating = enable;
13701368

13711369
if(enable) {
1372-
// Set first address
1370+
// Set first address
13731371
update_random_address();
13741372

13751373
// Schedule rotations every 15 minutes as recomended by the spec

0 commit comments

Comments
 (0)