Skip to content

Commit e1f9d06

Browse files
authored
Merge pull request #44 from donatieng/cordio-privacy
Security Manager PAL: Privacy implementation for Cordio
2 parents b43f27a + ad09ba0 commit e1f9d06

File tree

7 files changed

+650
-25
lines changed

7 files changed

+650
-25
lines changed

features/FEATURE_BLE/ble/generic/GenericGap.h

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "ble/BLEProtocol.h"
2424
#include "ble/Gap.h"
2525
#include "ble/pal/PalGap.h"
26+
#include "ble/pal/PalSecurityManager.h"
2627
#include "ble/pal/GapEvents.h"
2728
#include "ble/pal/GapTypes.h"
2829
#include "ble/BLETypes.h"
@@ -55,11 +56,15 @@ class GenericGap : public ::Gap,
5556
*
5657
* @param generic_access_service Platform abstraction instance managing
5758
* the GATT generic access service.
59+
*
60+
* @param pal_sm Security Manager Platform abstraction instance containing the base
61+
* Security Manager primitives.
5862
*/
5963
GenericGap(
6064
pal::EventQueue &event_queue,
6165
pal::Gap &pal_gap,
62-
pal::GenericAccessService &generic_access_service
66+
pal::GenericAccessService &generic_access_service,
67+
pal::SecurityManager &pal_sm
6368
);
6469

6570
/**
@@ -233,6 +238,39 @@ class GenericGap : public ::Gap,
233238
*/
234239
virtual ble_error_t initRadioNotification(void);
235240

241+
/**
242+
* @see Gap::enablePrivacy
243+
*/
244+
virtual ble_error_t enablePrivacy(bool enable);
245+
246+
/**
247+
* @see Gap::setPeripheralPrivacyConfiguration
248+
*/
249+
virtual ble_error_t setPeripheralPrivacyConfiguration(
250+
const PeripheralPrivacyConfiguration_t *configuration
251+
);
252+
253+
/**
254+
* @see Gap::getPeripheralPrivacyConfiguration
255+
*/
256+
virtual ble_error_t getPeripheralPrivacyConfiguration(
257+
PeripheralPrivacyConfiguration_t *configuration
258+
);
259+
260+
/**
261+
* @see Gap::setCentralPrivacyConfiguration
262+
*/
263+
virtual ble_error_t setCentralPrivacyConfiguration(
264+
const CentralPrivacyConfiguration_t *configuration
265+
);
266+
267+
/**
268+
* @see Gap::getCentralPrivacyConfiguration
269+
*/
270+
virtual ble_error_t getCentralPrivacyConfiguration(
271+
CentralPrivacyConfiguration_t *configuration
272+
);
273+
236274
/**
237275
* @see Gap::setAdvertisingData
238276
*/
@@ -302,21 +340,45 @@ class GenericGap : public ::Gap,
302340

303341
void on_unexpected_error(const pal::GapUnexpectedErrorEvent &e);
304342

305-
pal::own_address_type_t get_own_address_type();
343+
enum AddressUseType_t {
344+
CENTRAL_CONNECTION,
345+
CENTRAL_SCAN,
346+
PERIPHERAL_CONNECTABLE,
347+
PERIPHERAL_NON_CONNECTABLE
348+
};
349+
350+
pal::own_address_type_t get_own_address_type(AddressUseType_t address_use_type);
306351

307352
bool initialize_whitelist() const;
308353

354+
ble_error_t update_address_resolution_setting();
355+
356+
void set_random_address_rotation(bool enable);
357+
358+
void update_random_address();
359+
360+
void on_address_rotation_timeout();
361+
309362
pal::EventQueue& _event_queue;
310363
pal::Gap &_pal_gap;
311364
pal::GenericAccessService &_gap_service;
365+
pal::SecurityManager &_pal_sm;
312366
BLEProtocol::AddressType_t _address_type;
313367
ble::address_t _address;
314368
pal::initiator_policy_t _initiator_policy_mode;
315369
pal::scanning_filter_policy_t _scanning_filter_policy;
316370
pal::advertising_filter_policy_t _advertising_filter_policy;
317371
mutable Whitelist_t _whitelist;
372+
373+
bool _privacy_enabled;
374+
PeripheralPrivacyConfiguration_t _peripheral_privacy_configuration;
375+
CentralPrivacyConfiguration_t _central_privacy_configuration;
376+
ble::address_t _random_static_identity_address;
377+
bool _random_address_rotating;
378+
318379
mbed::Timeout _advertising_timeout;
319380
mbed::Timeout _scan_timeout;
381+
mbed::Ticker _address_rotation_ticker;
320382
pal::ConnectionEventMonitor::EventHandler *_connection_event_handler;
321383
};
322384

features/FEATURE_BLE/ble/pal/PalGap.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,27 @@ struct Gap {
649649
disconnection_reason_t disconnection_reason
650650
) = 0;
651651

652+
/** Check if privacy feature is supported by implementation
653+
*
654+
* @return true if privacy is supported, false otherwise.
655+
*
656+
* @note: See Bluetooth 5 Vol 3 Part C: 10.7 Privacy feature.
657+
*/
658+
virtual bool is_privacy_supported() = 0;
659+
660+
/** Enable or disable private addresses resolution
661+
*
662+
* @param enable whether to enable private addresses resolution
663+
*
664+
* @return BLE_ERROR_NONE if the request has been successfully sent or the
665+
* appropriate error otherwise.
666+
*
667+
* @note: See Bluetooth 5 Vol 2 PartE: 7.8.44 LE Set Address Resolution Enable command.
668+
*/
669+
virtual ble_error_t set_address_resolution(
670+
bool enable
671+
) = 0;
672+
652673
/**
653674
* Register a callback which will handle Gap events.
654675
*

0 commit comments

Comments
 (0)