Skip to content

Commit 9a0a086

Browse files
Merge branch 'security-manager-dev' into sm-privacy-nordic
2 parents 214656a + a2f206f commit 9a0a086

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+45
-46
lines changed

features/FEATURE_BLE/ble/BLEProtocol.h

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -59,24 +59,6 @@ namespace BLEProtocol {
5959
*/
6060
PUBLIC = 0,
6161

62-
/**
63-
* Random address.
64-
*
65-
* Use Gap::getRandomAddressType to retrieve the type of the random
66-
* address.
67-
*/
68-
RANDOM,
69-
70-
/**
71-
* A Public address used as a device identity address.
72-
*/
73-
PUBLIC_IDENTITY,
74-
75-
/**
76-
* A Random static address used as a device identity address.
77-
*/
78-
RANDOM_STATIC_IDENTITY,
79-
8062
/**
8163
* Random static device address.
8264
*
@@ -105,7 +87,25 @@ namespace BLEProtocol {
10587
* on RANDOM instead. Use Gap::getRandomAddressType to retrieve the
10688
* type of the random address.
10789
*/
108-
RANDOM_PRIVATE_NON_RESOLVABLE
90+
RANDOM_PRIVATE_NON_RESOLVABLE,
91+
92+
/**
93+
* Random address.
94+
*
95+
* Use Gap::getRandomAddressType to retrieve the type of the random
96+
* address.
97+
*/
98+
RANDOM,
99+
100+
/**
101+
* A Public address used as a device identity address.
102+
*/
103+
PUBLIC_IDENTITY,
104+
105+
/**
106+
* A Random static address used as a device identity address.
107+
*/
108+
RANDOM_STATIC_IDENTITY
109109
};
110110
};
111111

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

features/FEATURE_BLE/source/generic/GenericSecurityManager.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,16 @@ ble_error_t GenericSecurityManager::acceptPairingRequest(connection_handle_t con
193193

194194
KeyDistribution initiator_distribution = cb->get_initiator_key_distribution();
195195

196+
bool master_signing = initiator_distribution.get_signing();
197+
196198
if (_master_sends_keys) {
197199
initiator_distribution &= _default_key_distribution;
198200
} else {
199201
initiator_distribution &= KeyDistribution(KeyDistribution::KEY_DISTRIBUTION_IDENTITY | KeyDistribution::KEY_DISTRIBUTION_LINK);
200202
}
201203

202204
/* signing has to be offered and enabled on the link */
203-
if (initiator_distribution.get_signing()) {
205+
if (master_signing) {
204206
initiator_distribution.set_signing(
205207
cb->signing_override_default ? cb->signing_requested : _default_key_distribution.get_signing()
206208
);

0 commit comments

Comments
 (0)