@@ -316,7 +316,7 @@ static bool is_whitelist_valid(const Gap::Whitelist_t& whitelist)
316
316
for (size_t i = 0 ; i < whitelist.size ; ++i) {
317
317
const BLEProtocol::Address_t& address = whitelist.addresses [i];
318
318
if (address.type != BLEProtocol::AddressType::PUBLIC &&
319
- address.type != BLEProtocol::AddressType::RANDOM
319
+ address.type != BLEProtocol::AddressType::RANDOM_STATIC
320
320
) {
321
321
return false ;
322
322
}
@@ -423,7 +423,6 @@ ble_error_t GenericGap::setAddress(
423
423
_address_type = type;
424
424
return BLE_ERROR_NONE;
425
425
426
- case BLEProtocol::AddressType::RANDOM:
427
426
case BLEProtocol::AddressType::RANDOM_STATIC: {
428
427
if (is_random_static_address (address) == false ) {
429
428
return BLE_ERROR_INVALID_PARAM;
@@ -436,12 +435,18 @@ ble_error_t GenericGap::setAddress(
436
435
return err;
437
436
}
438
437
439
- _address_type = BLEProtocol::AddressType::RANDOM ;
438
+ _address_type = type ;
440
439
_address = ble::address_t (address);
441
440
_random_static_identity_address = ble::address_t (address);
442
441
return BLE_ERROR_NONE;
443
442
}
444
443
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
+
445
450
default :
446
451
return BLE_ERROR_INVALID_PARAM;
447
452
}
@@ -454,17 +459,10 @@ ble_error_t GenericGap::getAddress(
454
459
*type = _address_type;
455
460
ble::address_t address_value;
456
461
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 ();
468
466
}
469
467
470
468
memcpy (address, address_value.data (), address_value.size ());
@@ -879,10 +877,10 @@ ble_error_t GenericGap::initRadioNotification(void)
879
877
return BLE_ERROR_NOT_IMPLEMENTED;
880
878
}
881
879
882
- ble_error_t GenericGap::enablePrivacy (bool enable)
880
+ ble_error_t GenericGap::enablePrivacy (bool enable)
883
881
{
884
- if (enable == _privacy_enabled) {
885
- // No change
882
+ if (enable == _privacy_enabled) {
883
+ // No change
886
884
return BLE_ERROR_NONE;
887
885
}
888
886
@@ -901,7 +899,7 @@ ble_error_t GenericGap::enablePrivacy(bool enable)
901
899
902
900
ble_error_t GenericGap::setPeripheralPrivacyConfiguration (
903
901
const PeripheralPrivacyConfiguration_t *configuration
904
- )
902
+ )
905
903
{
906
904
_peripheral_privacy_configuration = *configuration;
907
905
@@ -912,7 +910,7 @@ ble_error_t GenericGap::setPeripheralPrivacyConfiguration(
912
910
913
911
ble_error_t GenericGap::getPeripheralPrivacyConfiguration (
914
912
PeripheralPrivacyConfiguration_t *configuration
915
- )
913
+ )
916
914
{
917
915
*configuration = _peripheral_privacy_configuration;
918
916
@@ -921,7 +919,7 @@ ble_error_t GenericGap::getPeripheralPrivacyConfiguration(
921
919
922
920
ble_error_t GenericGap::setCentralPrivacyConfiguration (
923
921
const CentralPrivacyConfiguration_t *configuration
924
- )
922
+ )
925
923
{
926
924
_central_privacy_configuration = *configuration;
927
925
@@ -932,7 +930,7 @@ ble_error_t GenericGap::setCentralPrivacyConfiguration(
932
930
933
931
ble_error_t GenericGap::getCentralPrivacyConfiguration (
934
932
CentralPrivacyConfiguration_t *configuration
935
- )
933
+ )
936
934
{
937
935
*configuration = _central_privacy_configuration;
938
936
@@ -962,9 +960,9 @@ ble_error_t GenericGap::startAdvertising(const GapAdvertisingParams& params)
962
960
}
963
961
964
962
// 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 =
966
964
((params.getAdvertisingType () == GapAdvertisingParams::ADV_SCANNABLE_UNDIRECTED)
967
- || (params.getAdvertisingType () == GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED))
965
+ || (params.getAdvertisingType () == GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED))
968
966
? PERIPHERAL_NON_CONNECTABLE : PERIPHERAL_CONNECTABLE;
969
967
pal::own_address_type_t own_address_type = get_own_address_type (address_use_type);
970
968
@@ -1175,7 +1173,7 @@ void GenericGap::on_connection_complete(const pal::GapConnectionCompleteEvent& e
1175
1173
// Apply privacy policy if in peripheral mode for non-resolved addresses
1176
1174
RandomAddressType_t random_address_type (RandomAddressType_t::RESOLVABLE_PRIVATE);
1177
1175
ble_error_t ret = getRandomAddressType (e.peer_address .data (), &random_address_type);
1178
- if ((ret != BLE_ERROR_NONE)
1176
+ if ((ret != BLE_ERROR_NONE)
1179
1177
|| (random_address_type == RandomAddressType_t::RESOLVABLE_PRIVATE))
1180
1178
{
1181
1179
switch (_peripheral_privacy_configuration.resolution_strategy )
@@ -1242,7 +1240,7 @@ void GenericGap::on_connection_complete(const pal::GapConnectionCompleteEvent& e
1242
1240
// TODO: GAP Authentication != Security Manager authentication
1243
1241
// Needs to be implemented
1244
1242
}
1245
- } else {
1243
+ } else {
1246
1244
// for now notify user that the connection failled by issuing a timeout
1247
1245
// event
1248
1246
@@ -1369,7 +1367,7 @@ void GenericGap::set_random_address_rotation(bool enable)
1369
1367
_random_address_rotating = enable;
1370
1368
1371
1369
if (enable) {
1372
- // Set first address
1370
+ // Set first address
1373
1371
update_random_address ();
1374
1372
1375
1373
// Schedule rotations every 15 minutes as recomended by the spec
0 commit comments