Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature ble host privacy #13717

Merged
merged 65 commits into from
Oct 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
f7dfc5c
BLE: Update ble::Duration to support default values
pan- Sep 3, 2020
bc860db
ble: Add privacy mode to the pal
pan- Sep 3, 2020
7423561
BLE: Add resolvable_address_timeout_t datatype.
pan- Sep 4, 2020
f1dbc89
BLE: Introduce PalPrivateAddressController
pan- Sep 4, 2020
7dacae7
BLE: Add cordio implementation of PalPrivateAddressController
pan- Sep 4, 2020
44681ee
BLE: Add PrivateAddressController module.
pan- Sep 4, 2020
237278b
BLE: Update security manager to use the PrivateAddressController
pan- Sep 4, 2020
23f7a18
BLE: Pal event queue pop before execution.
pan- Sep 4, 2020
313676a
BLE: Add gap handlers to be informed when advertising as started or b…
pan- Sep 7, 2020
7e16ee4
BLE: Bind address controller with Gap
pan- Sep 7, 2020
13771b8
BLE: Remove address resolution from GAP pal
pan- Sep 7, 2020
f810ec4
BLE: Add initiating flag into gap to track if the local device tries …
pan- Sep 7, 2020
4b85395
BLE: Add resolvable and non resolvable private address rotation with …
pan- Sep 7, 2020
b8549ec
BLE: rename address resolution handler.
pan- Sep 9, 2020
d8c6820
BLE: Add callback for scan started and stoped.
pan- Sep 9, 2020
924f8b1
BLE: Update state when scan started/stopped callback received.
pan- Sep 9, 2020
e512868
BLE: Fix random static address storage
pan- Sep 9, 2020
559640c
BLE: check LL resolution availability before enabling it.
pan- Sep 9, 2020
4685322
BLE: Add routine that computes the random address to use depending on…
pan- Sep 9, 2020
c39d03a
BLE: Implement private address rotation for initiating.
pan- Sep 9, 2020
19d8936
BLE: Private address when initiating connection
pan- Sep 9, 2020
3c22f8a
BLE: privacy tracing cleanup
pan- Sep 9, 2020
48f4cfb
BLE: return stack busy instead of invalid state when applicable
pan- Sep 10, 2020
9df7fc9
BLE: Fix state update when event handler not present
pan- Sep 10, 2020
9eac368
BLE: improve scan state bookkeeping
pan- Sep 10, 2020
f897729
Cordio: Add API to set the local identity address.
pan- Sep 10, 2020
5cb0595
BLE: Add function to get the device random static address.
pan- Sep 16, 2020
0b98682
BLE: Add function to set the identity address used by the controller/…
pan- Sep 16, 2020
4859dbe
BLE: Set identity address to random static.
pan- Sep 16, 2020
685af00
split resolve addres into cache and not cache
paul-szczepanek-arm Sep 16, 2020
0a3cd69
event handler should not affect internal state
paul-szczepanek-arm Sep 17, 2020
df17942
remove unused enhanced conn complete
paul-szczepanek-arm Sep 17, 2020
44b2e73
Add setters to events
paul-szczepanek-arm Sep 22, 2020
593c177
add EventList class for storing pending events
paul-szczepanek-arm Sep 22, 2020
f126793
Add host reolustion for advertising and connections
paul-szczepanek-arm Sep 22, 2020
dee20fe
BLE: Check if extended advertising is available to clear advertising …
pan- Sep 23, 2020
1daee23
BLE: Queue address resolution in event queue to avoid synchronous exe…
pan- Sep 23, 2020
3a632a3
BLE: Check if the resolving list item is populated instead of IRK val…
pan- Sep 23, 2020
0266738
BLE: Fix insertion to host resolving list.
pan- Sep 23, 2020
7c8a754
BLE: Remove set advertising timeout from SM pal
pan- Sep 23, 2020
4c1afe8
BLE: Update identity address when retrieved from the DB
pan- Sep 23, 2020
8716298
BLE: Update DB entry if current entry doesn't match requested EDIV an…
pan- Sep 23, 2020
8fe2d7e
BLE: Report connection internally when address resolution has completed.
pan- Sep 23, 2020
e4b317c
BLE: Add workaround for cordio use of global random address
pan- Sep 25, 2020
76f89f6
BLE: Factorize peripheral privacy applied when connected
pan- Sep 25, 2020
03cc0f9
host privacy config option to enable it
paul-szczepanek-arm Sep 24, 2020
4572688
add nrf override for host resolution
paul-szczepanek-arm Sep 28, 2020
ec2808b
filter based on resolving list size
paul-szczepanek-arm Sep 28, 2020
b67230c
apply peripheral policy on ll privacy
paul-szczepanek-arm Sep 28, 2020
d436038
do not reject conn if no bond
paul-szczepanek-arm Sep 28, 2020
5216a9a
only apply policy if privacy enabled
paul-szczepanek-arm Sep 28, 2020
bb35cba
BLE: Add function to signal privacy initialization.
pan- Sep 29, 2020
4744c87
Set privacy mode to device mode in LL.
pan- Sep 30, 2020
18c218b
allow host resolved address to be used for connection
paul-szczepanek-arm Sep 30, 2020
b008691
scan forever and allow cancellation
paul-szczepanek-arm Sep 30, 2020
f0bbc4c
use enum for state
paul-szczepanek-arm Oct 1, 2020
6ee5740
use _initiating to block scan manipulation
paul-szczepanek-arm Oct 1, 2020
f32141a
BLE: Notify application when advertising start or stop
pan- Oct 2, 2020
e1842cc
BLE: Workaround for WB55 connection event
pan- Oct 13, 2020
2a4a097
BLE: Take advantage of controller based address resolution on WB55
pan- Oct 13, 2020
3f9798b
Fix conditional compilation based on config
paul-szczepanek-arm Oct 13, 2020
9f09bb4
rename private address controller to match security manager
paul-szczepanek-arm Oct 13, 2020
665e453
Merge pull request #13759 from pan-/privacy-workaround-wb55
pan- Oct 14, 2020
119d459
fix removed friend function
paul-szczepanek-arm Oct 14, 2020
5f1b716
Merge pull request #13760 from paul-szczepanek-arm/privacy-fix-ifdef
pan- Oct 14, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions connectivity/FEATURE_BLE/include/ble/Gap.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,17 @@ class Gap {
{
}

/**
* Called when advertising starts.
*
* @param event Advertising start event.
*
* @see startAdvertising()
*/
virtual void onAdvertisingStart(const AdvertisingStartEvent &event)
{
}

/**
* Called when advertising ends.
*
Expand Down Expand Up @@ -538,6 +549,14 @@ class Gap {
)
{
}

/**
* Function invoked when the privacy subsystem has been enabled and is
* ready to be used.
*/
virtual void onPrivacyEnabled()
{
}
protected:
/**
* Prevent polymorphic deletion and avoid unnecessary virtual destructor
Expand Down Expand Up @@ -724,6 +743,7 @@ class Gap {
* @param maxEvents Max number of events produced during advertising - 0 means no limit.
* @return BLE_ERROR_NONE on success.
*
* @see EventHandler::onAdvertisingStart when the advertising starts.
* @see EventHandler::onScanRequestReceived when a scan request is received.
* @see EventHandler::onAdvertisingEnd when the advertising ends.
* @see EventHandler::onConnectionComplete when the device gets connected
Expand Down Expand Up @@ -1244,6 +1264,14 @@ class Gap {
* resolved and advertisement packets are forwarded to the application
* even if the advertiser private address is unknown.
*
* @par Initialization of the privacy subsystem
*
* When privacy is enabled, the system generates new resolvable and non
* resolvable private addresses. Scan, Advertising and Connecting to a peer
* won't be available until the generation process completes. When addresses
* have been generated, the application is notified that privacy
* initialisation as completed with a call to EventHandler::onPrivacyEnabled .
*
* @param[in] enable Should be set to true to enable the privacy mode and
* false to disable it.
*
Expand Down Expand Up @@ -1448,6 +1476,8 @@ class Gap {
* forbidden by the Bluetooth specification.
*/
ble_error_t setRandomStaticAddress(const ble::address_t& address);

ble::address_t getRandomStaticAddress();
#endif // !defined(DOXYGEN_ONLY)

private:
Expand Down
2 changes: 2 additions & 0 deletions connectivity/FEATURE_BLE/include/ble/SecurityManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,7 @@ class SecurityManager
// Privacy
//

#if BLE_FEATURE_PRIVACY
/**
* Sets how often the address is rotated when privacy is enabled.
*
Expand All @@ -845,6 +846,7 @@ class SecurityManager
ble_error_t setPrivateAddressTimeout(
uint16_t timeout_in_seconds
);
#endif // BLE_FEATURE_PRIVACY

/* Event callback handlers. */
public:
Expand Down
16 changes: 10 additions & 6 deletions connectivity/FEATURE_BLE/include/ble/common/Duration.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ namespace ble {
* @tparam Min left-bound
* @tparam Max right-bound
*/
template<uint32_t Min, uint32_t Max>
template<uint32_t Min, uint32_t Max, uint32_t Default = Min>
struct Range {
static const uint32_t MIN = Min;
static const uint32_t MAX = Max;
static const uint32_t DEFAULT = Default;
};

/**
Expand Down Expand Up @@ -111,7 +112,7 @@ struct Duration {
*
* It is initialized with the minimum value acceptable.
*/
Duration() : duration(Range::MIN)
Duration() : duration(Range::DEFAULT)
{
}

Expand Down Expand Up @@ -598,11 +599,14 @@ bool operator>(Duration<Rep, Us, Range, F> lhs, Duration<Rep, Us, Range, F> rhs)

#if !defined(DOXYGEN_ONLY)

template<uint32_t Min, uint32_t Max>
const uint32_t Range<Min, Max>::MIN;
template<uint32_t Min, uint32_t Max, uint32_t Default>
const uint32_t Range<Min, Max, Default>::MIN;

template<uint32_t Min, uint32_t Max>
const uint32_t Range<Min, Max>::MAX;
template<uint32_t Min, uint32_t Max, uint32_t Default>
const uint32_t Range<Min, Max, Default>::MAX;

template<uint32_t Min, uint32_t Max, uint32_t Default>
const uint32_t Range<Min, Max, Default>::DEFAULT;

template<typename T, T V>
const T Value<T, V>::VALUE;
Expand Down
137 changes: 124 additions & 13 deletions connectivity/FEATURE_BLE/include/ble/gap/Events.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,22 @@ struct AdvertisingReportEvent {
const address_t &directAddress,
const mbed::Span<const uint8_t> &advertisingData
) :
peerAddress(peerAddress),
type(type),
peerAddressType(peerAddressType),
peerAddress(peerAddress),
primaryPhy(primaryPhy),
secondaryPhy(secondaryPhy),
SID(SID),
txPower(txPower),
rssi(rssi),
periodicInterval(periodicInterval),
rssi(rssi),
directAddressType(directAddressType),
directAddress(directAddress),
advertisingData(advertisingData)
{
}

#endif

/** Get event type. */
const advertising_event_t &getType() const
{
Expand Down Expand Up @@ -163,18 +162,44 @@ struct AdvertisingReportEvent {
return advertisingData;
}

/** Set peer address. */
void setPeerAddress(
const address_t &newPeerAddress
)
{
peerAddress = newPeerAddress;
}


/** Set peer address type. */
void setPeerAddressType(
const peer_address_type_t &newPeerAddressType
)
{
peerAddressType = newPeerAddressType;
}

/** Set new advertising payload. */
void setAdvertisingData(
const mbed::Span<const uint8_t> &newAdvertisingData
)
{
advertisingData = newAdvertisingData;
}

private:
address_t peerAddress;
advertising_event_t type;
peer_address_type_t peerAddressType;
address_t const &peerAddress;
phy_t primaryPhy;
phy_t secondaryPhy;
advertising_sid_t SID;
advertising_power_t txPower;
rssi_t rssi;
uint16_t periodicInterval;
rssi_t rssi;
peer_address_type_t directAddressType;
const address_t &directAddress;
address_t directAddress;
ble_error_t status;
mbed::Span<const uint8_t> advertisingData;
};

Expand Down Expand Up @@ -215,12 +240,12 @@ struct ConnectionCompleteEvent {
) :
status(status),
connectionHandle(connectionHandle),
peerAddress(peerAddress),
ownRole(ownRole),
peerAddressType(peerAddressType),
peerAddress(peerAddress),
localResolvablePrivateAddress(localResolvablePrivateAddress),
peerResolvablePrivateAddress(peerResolvablePrivateAddress),
connectionInterval(connectionInterval),
peerResolvablePrivateAddress(peerResolvablePrivateAddress),
connectionLatency(connectionLatency),
supervisionTimeout(supervisionTimeout),
masterClockAccuracy(masterClockAccuracy)
Expand Down Expand Up @@ -295,15 +320,46 @@ struct ConnectionCompleteEvent {
return masterClockAccuracy;
}


/** Set connection complete event status. */
void setStatus(ble_error_t new_status)
{
status = new_status;
}

/** Set peer address type. */
void setPeerAddressType(const peer_address_type_t& address_type)
{
peerAddressType = address_type;
}

/** Set peer address. */
void setPeerAddress(const address_t &address)
{
peerAddress = address;
}

/** Set get local resolvable random address if privacy is used. */
void setLocalResolvablePrivateAddress(const address_t &address)
{
localResolvablePrivateAddress = address;
}

/** Set peer resolvable private address if privacy is used. */
void setPeerResolvablePrivateAddress(const address_t &address)
{
peerResolvablePrivateAddress = address;
}

private:
ble_error_t status;
connection_handle_t connectionHandle;
address_t peerAddress;
connection_role_t ownRole;
peer_address_type_t peerAddressType;
const address_t &peerAddress;
const address_t &localResolvablePrivateAddress;
const address_t &peerResolvablePrivateAddress;
address_t localResolvablePrivateAddress;
conn_interval_t connectionInterval;
address_t peerResolvablePrivateAddress;
slave_latency_t connectionLatency;
supervision_timeout_t supervisionTimeout;
uint16_t masterClockAccuracy;
Expand Down Expand Up @@ -519,15 +575,47 @@ struct PeriodicAdvertisingSyncLoss {
*/
struct ScanTimeoutEvent { };

/**
* Event produced when advertising start.
*
* @see ble::Gap::EventHandler::onAdvertisingStart().
*/
struct AdvertisingStartEvent {
#if !defined(DOXYGEN_ONLY)

/** Create an advertising start event.
*
* @param advHandle Advertising set handle.
*/
AdvertisingStartEvent(advertising_handle_t advHandle) :
advHandle(advHandle)
{
}

#endif

/** Get advertising handle. */
advertising_handle_t getAdvHandle() const
{
return advHandle;
}

private:
advertising_handle_t advHandle;
};

/**
* Event produced when advertising ends.
*
* @see ble::Gap::EventHandler::onAdvertisingEnd().
*
* @note The connection handle, connected flag and completed_event fields are
* valid if the flag legacy is not set to true.
*/
struct AdvertisingEndEvent {
#if !defined(DOXYGEN_ONLY)

/** Create advertising end event.
/** Create an extended advertising end event.
*
* @param advHandle Advertising set handle.
* @param connection Connection handle.
Expand All @@ -543,7 +631,19 @@ struct AdvertisingEndEvent {
advHandle(advHandle),
connection(connection),
completed_events(completed_events),
connected(connected)
connected(connected),
legacy(false)
{
}

/** Create a legacy advertising end event.
*/
AdvertisingEndEvent() :
advHandle(LEGACY_ADVERTISING_HANDLE),
connection(),
completed_events(0),
connected(false),
legacy(true)
{
}

Expand Down Expand Up @@ -573,11 +673,22 @@ struct AdvertisingEndEvent {
return connected;
}

/** Is the end of legacy advertising.
*
* If it is the return of getConnection() getCompleted_events() and isConnected()
* must be discarded
*/
bool isLegacy() const
{
return legacy;
}

private:
advertising_handle_t advHandle;
connection_handle_t connection;
uint8_t completed_events;
bool connected;
bool legacy;
};

/**
Expand Down
14 changes: 12 additions & 2 deletions connectivity/FEATURE_BLE/include/ble/gap/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ typedef Duration<uint16_t, 10000, Range<0x0A, 0x4000> > sync_timeout_t;
*/
typedef Duration<uint16_t, 1250, Range<0x06, 0xFFFF> > periodic_interval_t;

/**
* Resolvable address timeout.
*
* The duration is in seconds and ranges from 1 to 0xA1B8. The default value is
* 900 seconds.
*/
using resolvable_address_timeout_t = Duration<
uint16_t, second_t::TIME_BASE, Range<1, 0xA1B8, 0x0384>
>;

/**
* Number of connection events that can be skipped by the slave.
*
Expand Down Expand Up @@ -445,8 +455,8 @@ struct scanning_filter_policy_t : SafeEnum<scanning_filter_policy_t, uint8_t> {
NO_FILTER = 0x00,

/**
* Accept only advertising packets from devices in the whitelist except
* directed advertising packets not addressed to this device.
* Accept only advertising packets from devices in the whitelist.
* Directed advertising packets not addressed to this device will be ignored.
*/
FILTER_ADVERTISING = 0x01,

Expand Down
Loading