Skip to content

Commit a99a4b8

Browse files
Merge pull request ARMmbed#33 from pan-/fix-cordio-addresses-type
BLE: Handle new addresses type in GenericGap.
2 parents f56f57b + 169e579 commit a99a4b8

File tree

1 file changed

+23
-26
lines changed

1 file changed

+23
-26
lines changed

features/FEATURE_BLE/source/generic/GenericGap.cpp

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,9 @@ static bool is_whitelist_valid(const Gap::Whitelist_t& whitelist)
314314

315315
for (size_t i = 0; i < whitelist.size; ++i) {
316316
const BLEProtocol::Address_t& address = whitelist.addresses[i];
317-
if (address.type > BLEProtocol::AddressType::RANDOM_PRIVATE_NON_RESOLVABLE) {
317+
if (address.type != BLEProtocol::AddressType::PUBLIC &&
318+
address.type != BLEProtocol::AddressType::RANDOM
319+
) {
318320
return false;
319321
}
320322

@@ -354,8 +356,8 @@ static pal::whitelist_address_type_t to_device_address_type(
354356
BLEProtocol::AddressType_t address_type
355357
) {
356358
return (address_type == BLEProtocol::AddressType::PUBLIC) ?
357-
pal::whitelist_address_type_t::PUBLIC_DEVICE_ADDRESS :
358-
pal::whitelist_address_type_t::RANDOM_DEVICE_ADDRESS;
359+
pal::whitelist_address_type_t::PUBLIC_DEVICE_ADDRESS :
360+
pal::whitelist_address_type_t::RANDOM_DEVICE_ADDRESS;
359361
}
360362

361363
/*
@@ -411,6 +413,7 @@ ble_error_t GenericGap::setAddress(
411413
_address_type = type;
412414
return BLE_ERROR_NONE;
413415

416+
case BLEProtocol::AddressType::RANDOM:
414417
case BLEProtocol::AddressType::RANDOM_STATIC: {
415418
if (is_random_static_address(address) == false) {
416419
return BLE_ERROR_INVALID_PARAM;
@@ -423,22 +426,13 @@ ble_error_t GenericGap::setAddress(
423426
return err;
424427
}
425428

426-
_address_type = type;
429+
_address_type = BLEProtocol::AddressType::RANDOM;
427430
_address = ble::address_t(address);
428431
return BLE_ERROR_NONE;
429432
}
430433

431-
case BLEProtocol::AddressType::RANDOM_PRIVATE_RESOLVABLE:
432-
// TODO: Fix with the privacy/security rework
433-
return BLE_ERROR_NOT_IMPLEMENTED;
434-
435-
case BLEProtocol::AddressType::RANDOM_PRIVATE_NON_RESOLVABLE:
436-
// TODO: add process to set the random private non resolvable
437-
// address (privacy/security work)
438-
return BLE_ERROR_NOT_IMPLEMENTED;
439-
440434
default:
441-
return BLE_ERROR_PARAM_OUT_OF_RANGE;
435+
return BLE_ERROR_INVALID_PARAM;
442436
}
443437
}
444438

@@ -448,10 +442,18 @@ ble_error_t GenericGap::getAddress(
448442
) {
449443
*type = _address_type;
450444
ble::address_t address_value;
451-
if (_address_type == BLEProtocol::AddressType::PUBLIC) {
452-
address_value = _pal_gap.get_device_address();
453-
} else {
454-
address_value = _pal_gap.get_random_address();
445+
446+
switch (_address_type) {
447+
case BLEProtocol::AddressType::PUBLIC:
448+
address_value = _pal_gap.get_device_address();
449+
break;
450+
451+
case BLEProtocol::AddressType::RANDOM:
452+
address_value = _pal_gap.get_random_address();
453+
break;
454+
455+
default:
456+
return BLE_ERROR_INVALID_PARAM;
455457
}
456458

457459
memcpy(address, address_value.data(), address_value.size());
@@ -528,7 +530,7 @@ ble_error_t GenericGap::connect(
528530
_initiator_policy_mode,
529531
(pal::connection_peer_address_type_t::type) peerAddrType,
530532
ble::address_t(peerAddr),
531-
(pal::own_address_type_t::type) _address_type,
533+
get_own_address_type(),
532534
connectionParams->minConnectionInterval,
533535
connectionParams->maxConnectionInterval,
534536
connectionParams->slaveLatency,
@@ -1135,14 +1137,9 @@ pal::own_address_type_t GenericGap::get_own_address_type()
11351137
switch (_address_type) {
11361138
case BLEProtocol::AddressType::PUBLIC:
11371139
return pal::own_address_type_t::PUBLIC_ADDRESS;
1138-
case BLEProtocol::AddressType::RANDOM_STATIC:
1139-
case BLEProtocol::AddressType::RANDOM_PRIVATE_NON_RESOLVABLE:
1140-
return pal::own_address_type_t::RANDOM_ADDRESS;
1141-
case BLEProtocol::AddressType::RANDOM_PRIVATE_RESOLVABLE:
1142-
return pal::own_address_type_t::RESOLVABLE_PRIVATE_ADDRESS_PUBLIC_FALLBACK;
11431140
default:
1144-
// not reachable
1145-
return pal::own_address_type_t::PUBLIC_ADDRESS;
1141+
return pal::own_address_type_t::RANDOM_ADDRESS;
1142+
// FIXME: Handle case when privacy is used.
11461143
}
11471144
}
11481145

0 commit comments

Comments
 (0)