Skip to content

Commit a3383c1

Browse files
author
Donatien Garnier
committed
Addressed Vincent's comments
1 parent ded1403 commit a3383c1

File tree

8 files changed

+82
-149
lines changed

8 files changed

+82
-149
lines changed

features/FEATURE_BLE/ble/SecurityManager.h

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17-
#ifndef _SECURITY_MANAGER_H_
18-
#define _SECURITY_MANAGER_H_
17+
#ifndef SECURITY_MANAGER_H_
18+
#define SECURITY_MANAGER_H_
1919

2020
#include <stdint.h>
2121

@@ -57,7 +57,7 @@
5757
* it. If either side doesn't support it Legacy Pairing will be used. This is an older standard of pairing.
5858
* If higher security is required legacy pairing can be disabled by calling allowLegacyPairing(false);
5959
*
60-
* How to use
60+
* \par How to use
6161
*
6262
* First thing you need to do is to initialise the manager by calling init() with your chosen settings.
6363
*
@@ -87,9 +87,11 @@
8787
* accetPairing() or cancelPairing(). The result will be communicated on both peers through an event calling
8888
* pairingResult() in the EventHandler.
8989
*
90+
* \par Sequence diagrams
9091
*
9192
* Sequence diagram "Just Works" pairing
9293
*
94+
* \verbatim
9395
* /----------- Device 1 --------------\ *------ BLE link ------* /-------------- Device 2 -------------\
9496
*
9597
* App EventHandler SecurityManager SecurityManager EventHandler App
@@ -101,14 +103,16 @@
101103
* | | |<---[pairing complete]----->| | |
102104
* |<- pairingResult() <---------------| |----------------> pairingResult() -->|
103105
* | | | | | |
104-
*
106+
* \endverbatim
107+
*
105108
* @note the requestPairing() call isn't required to trigger pairing. Pairing will also be triggered
106109
* if you request encryption and authentication and no bonding information is available. The sequence will
107110
* be the same save for the lack of explicit requestPairing() call.
108111
*
109112
*
110113
* Sequence diagram Encryption request when bonding information is available
111114
*
115+
* \verbatim
112116
* /----------- Device 1 --------------\ *------ BLE link ------* /-------------- Device 2 -------------\
113117
*
114118
* App EventHandler SecurityManager SecurityManager EventHandler App
@@ -117,13 +121,15 @@
117121
* | | |<-[encryption established]->| | |
118122
* |<- linkEncryptionResult() <--------| |---------> linkEncryptionResult() -->|
119123
* | | | | | |
120-
*
124+
* \endverbatim
125+
*
121126
* @note if bonding information is not available, pairing will be triggered
122127
*
123128
*
124129
* Sequence diagram for Secure Connections passkey entry pairing with one device having a display only
125130
* and other a keyboard
126131
*
132+
* \verbatim
127133
* /----------- Device 1 (keyboard) ---\ *------ BLE link ------* /-------------- Device 2 (display) ---\
128134
*
129135
* App EventHandler SecurityManager SecurityManager EventHandler App
@@ -143,7 +149,8 @@
143149
* | | |<---[pairing complete]----->| | |
144150
* |<- pairingResult() <---------------| |----------------> pairingResult() -->|
145151
* | | | | | |
146-
*
152+
* \endverbatim
153+
*
147154
*/
148155

149156
class SecurityManager {
@@ -267,9 +274,7 @@ class SecurityManager {
267274
* @param[in] whitelist pointer to the whitelist filled with entries based on bonding information
268275
*/
269276
virtual void whitelistFromBondTable(Gap::Whitelist_t* whitelist) {
270-
if (whitelist) {
271-
delete whitelist;
272-
}
277+
(void)whitelist;
273278
}
274279

275280
////////////////////////////////////////////////////////////////////////////
@@ -1070,4 +1075,4 @@ class SecurityManager {
10701075
LegacyEventHandler defaultEventHandler;
10711076
};
10721077

1073-
#endif /*_SECURITY_MANAGER_H_*/
1078+
#endif /*SECURITY_MANAGER_H_*/

features/FEATURE_BLE/ble/generic/GenericGap.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ class GenericGap : public ::Gap,
276276
/** @note Implements ConnectionEventMonitor.
277277
* @copydoc ConnectionEventMonitor::set_connection_event_handler
278278
*/
279-
void set_connection_event_handler(pal::ConnectionEventHandler *_connection_event_handler);
279+
void set_connection_event_handler(pal::ConnectionEventMonitor::EventHandler *_connection_event_handler);
280280

281281
void on_scan_timeout();
282282

@@ -317,7 +317,7 @@ class GenericGap : public ::Gap,
317317
mutable Whitelist_t _whitelist;
318318
mbed::Timeout _advertising_timeout;
319319
mbed::Timeout _scan_timeout;
320-
pal::ConnectionEventHandler *_connection_event_handler;
320+
pal::ConnectionEventMonitor::EventHandler *_connection_event_handler;
321321
};
322322

323323
}

features/FEATURE_BLE/ble/generic/GenericSecurityManager.h

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,11 @@
2828
namespace ble {
2929
namespace generic {
3030

31-
using pal::advertising_peer_address_type_t;
32-
using pal::AuthenticationMask;
33-
using pal::KeyDistribution;
34-
using pal::connection_peer_address_type_t;
35-
3631
typedef SecurityManager::SecurityIOCapabilities_t SecurityIOCapabilities_t;
3732

3833
class GenericSecurityManager : public SecurityManager,
3934
public pal::SecurityManager::EventHandler,
40-
public pal::ConnectionEventHandler {
35+
public pal::ConnectionEventMonitor::EventHandler {
4136
public:
4237
typedef ble::pal::SecurityDistributionFlags_t SecurityDistributionFlags_t;
4338
typedef ble::pal::SecurityEntryKeys_t SecurityEntryKeys_t;
@@ -240,7 +235,7 @@ class GenericSecurityManager : public SecurityManager,
240235
_db(dbImpl),
241236
_connection_monitor(connMonitorImpl),
242237
_default_authentication(0),
243-
_default_key_distribution(KeyDistribution::KEY_DISTRIBUTION_ALL),
238+
_default_key_distribution(pal::KeyDistribution::KEY_DISTRIBUTION_ALL),
244239
_pairing_authorisation_required(false),
245240
_legacy_pairing_allowed(true),
246241
_master_sends_keys(false),
@@ -432,16 +427,16 @@ class GenericSecurityManager : public SecurityManager,
432427
struct ControlBlock_t : public pal::SecurityDistributionFlags_t {
433428
ControlBlock_t();
434429

435-
KeyDistribution get_initiator_key_distribution() {
436-
return KeyDistribution(initiator_key_distribution);
430+
pal::KeyDistribution get_initiator_key_distribution() {
431+
return pal::KeyDistribution(initiator_key_distribution);
437432
};
438-
KeyDistribution get_responder_key_distribution() {
439-
return KeyDistribution(responder_key_distribution);
433+
pal::KeyDistribution get_responder_key_distribution() {
434+
return pal::KeyDistribution(responder_key_distribution);
440435
};
441-
void set_initiator_key_distribution(KeyDistribution mask) {
436+
void set_initiator_key_distribution(pal::KeyDistribution mask) {
442437
initiator_key_distribution = mask.value();
443438
};
444-
void set_responder_key_distribution(KeyDistribution mask) {
439+
void set_responder_key_distribution(pal::KeyDistribution mask) {
445440
responder_key_distribution = mask.value();
446441
};
447442

@@ -476,8 +471,8 @@ class GenericSecurityManager : public SecurityManager,
476471
pal::SecurityDb &_db;
477472
pal::ConnectionEventMonitor &_connection_monitor;
478473

479-
AuthenticationMask _default_authentication;
480-
KeyDistribution _default_key_distribution;
474+
pal::AuthenticationMask _default_authentication;
475+
pal::KeyDistribution _default_key_distribution;
481476

482477
bool _pairing_authorisation_required;
483478
bool _legacy_pairing_allowed;
@@ -504,9 +499,9 @@ class GenericSecurityManager : public SecurityManager,
504499
virtual void on_pairing_request(
505500
connection_handle_t connection,
506501
bool use_oob,
507-
AuthenticationMask authentication,
508-
KeyDistribution initiator_dist,
509-
KeyDistribution responder_dist
502+
pal::AuthenticationMask authentication,
503+
pal::KeyDistribution initiator_dist,
504+
pal::KeyDistribution responder_dist
510505
);
511506

512507
/** @copydoc ble::pal::SecurityManager::on_pairing_error
@@ -542,7 +537,7 @@ class GenericSecurityManager : public SecurityManager,
542537
*/
543538
virtual void on_slave_security_request(
544539
connection_handle_t connection,
545-
AuthenticationMask authentication
540+
pal::AuthenticationMask authentication
546541
);
547542

548543
////////////////////////////////////////////////////////////////////////////
@@ -665,7 +660,7 @@ class GenericSecurityManager : public SecurityManager,
665660
*/
666661
virtual void on_keys_distributed_bdaddr(
667662
connection_handle_t connection,
668-
advertising_peer_address_type_t peer_address_type,
663+
pal::advertising_peer_address_type_t peer_address_type,
669664
const address_t &peer_identity_address
670665
);
671666

features/FEATURE_BLE/ble/pal/ConnectionEventMonitor.h

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -25,58 +25,58 @@ namespace ble {
2525
namespace pal {
2626

2727
/**
28-
* Implemented by classes that are reacting to connection changes.
29-
* @see ConnectionEventMonitor
28+
* Implemented by classes that need to be notified of connection changes.
29+
* Notification is done by calling functions in the passed in event handler
3030
*/
31-
class ConnectionEventHandler {
31+
class ConnectionEventMonitor {
3232
public:
3333
/**
34-
* Inform the Security manager of a new connection. This will create
35-
* or retrieve an existing security manager entry for the connected device.
36-
* Called by GAP.
37-
*
38-
* @param[in] connection Handle to identify the connection.
39-
* @param[in] role indicate if the device is central or peripheral.
40-
* @param[in] peer_address_type type of address.
41-
* @param[in] peer_address Address of the connected device.
42-
* @param[in] local_address_type type of address of the local device.
43-
* @param[in] local_address Address of the local device that was used during connection.
44-
* @param[in] connection_params connection parameters like interval, latency and timeout.
34+
* Implemented by classes that are reacting to connection changes.
35+
* @see ConnectionEventMonitor
4536
*/
46-
virtual void on_connected(
47-
connection_handle_t connection,
48-
::Gap::Role_t role,
49-
BLEProtocol::AddressType_t peer_address_type,
50-
const BLEProtocol::AddressBytes_t peer_address,
51-
BLEProtocol::AddressType_t local_address_type,
52-
const BLEProtocol::AddressBytes_t local_address,
53-
const ::Gap::ConnectionParams_t *connection_params
54-
) = 0;
37+
class EventHandler {
38+
public:
39+
/**
40+
* Inform the Security manager of a new connection. This will create
41+
* or retrieve an existing security manager entry for the connected device.
42+
* Called by GAP.
43+
*
44+
* @param[in] connection Handle to identify the connection.
45+
* @param[in] role indicate if the device is central or peripheral.
46+
* @param[in] peer_address_type type of address.
47+
* @param[in] peer_address Address of the connected device.
48+
* @param[in] local_address_type type of address of the local device.
49+
* @param[in] local_address Address of the local device that was used during connection.
50+
* @param[in] connection_params connection parameters like interval, latency and timeout.
51+
*/
52+
virtual void on_connected(
53+
connection_handle_t connection,
54+
::Gap::Role_t role,
55+
BLEProtocol::AddressType_t peer_address_type,
56+
const BLEProtocol::AddressBytes_t peer_address,
57+
BLEProtocol::AddressType_t local_address_type,
58+
const BLEProtocol::AddressBytes_t local_address,
59+
const ::Gap::ConnectionParams_t *connection_params
60+
) = 0;
5561

56-
/**
57-
* Inform the monitor about a disconnection.
58-
*
59-
* @param[in] connectionHandle Handle to identify the connection.
60-
* @param[in] reason Reason for the disconnection.
61-
*/
62-
virtual void on_disconnected(
63-
connection_handle_t connection,
64-
::Gap::DisconnectionReason_t reason
65-
) = 0;
66-
};
62+
/**
63+
* Inform the monitor about a disconnection.
64+
*
65+
* @param[in] connectionHandle Handle to identify the connection.
66+
* @param[in] reason Reason for the disconnection.
67+
*/
68+
virtual void on_disconnected(
69+
connection_handle_t connection,
70+
::Gap::DisconnectionReason_t reason
71+
) = 0;
72+
};
6773

68-
/**
69-
* Implemented by classes that need to be notified of connection changes.
70-
* Notification is done by calling functions in the passed in event handler
71-
*/
72-
class ConnectionEventMonitor {
73-
public:
7474
/**
7575
* Register a handler for connection events to be used internally and serviced first.
7676
*
7777
* @param[in] connection_event_handler Event handler being registered.
7878
*/
79-
virtual void set_connection_event_handler(ConnectionEventHandler *connection_event_handler) = 0;
79+
virtual void set_connection_event_handler(EventHandler *connection_event_handler) = 0;
8080
};
8181

8282
} // namespace pal

features/FEATURE_BLE/ble/pal/MemorySecurityDB.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17-
#ifndef _PAL_MEMORY_SECURITY_DB_H_
18-
#define _PAL_MEMORY_SECURITY_DB_H_
17+
#ifndef PAL_MEMORY_SECURITY_DB_H_
18+
#define PAL_MEMORY_SECURITY_DB_H_
1919

2020
#include "SecurityDB.h"
2121

@@ -369,4 +369,4 @@ class MemorySecurityDb : public SecurityDb {
369369
} /* namespace pal */
370370
} /* namespace ble */
371371

372-
#endif /*_PAL_MEMORY_SECURITY_DB_H_*/
372+
#endif /*PAL_MEMORY_SECURITY_DB_H_*/

features/FEATURE_BLE/source/generic/GenericGap.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,7 @@ bool GenericGap::initialize_whitelist() const
11691169
return true;
11701170
}
11711171

1172-
void GenericGap::set_connection_event_handler(pal::ConnectionEventHandler *connection_event_handler)
1172+
void GenericGap::set_connection_event_handler(pal::ConnectionEventMonitor::EventHandler *connection_event_handler)
11731173
{
11741174
_connection_event_handler = connection_event_handler;
11751175
}

features/FEATURE_BLE/source/generic/GenericSecurityManager.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
#include "mbedtls/cmac.h"
2222
#endif
2323

24+
using ble::pal::advertising_peer_address_type_t;
25+
using ble::pal::AuthenticationMask;
26+
using ble::pal::KeyDistribution;
27+
using ble::pal::connection_peer_address_type_t;
28+
2429
namespace ble {
2530
namespace generic {
2631

0 commit comments

Comments
 (0)