Skip to content

Commit e186985

Browse files
addressing PR review: added documentation, moved code and renamed vars
1 parent fc01cff commit e186985

File tree

15 files changed

+464
-419
lines changed

15 files changed

+464
-419
lines changed

features/FEATURE_BLE/ble/BLETypes.h

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,10 @@ static inline attribute_handle_range_t attribute_handle_range(
120120
}
121121

122122
/**
123-
* Type that describes link's encryption state..
123+
* Type that describes link's encryption state.
124124
*/
125125
struct link_encryption_t : SafeEnum<link_encryption_t, uint8_t> {
126+
/** struct scoped enum wrapped by the class */
126127
enum type {
127128
NOT_ENCRYPTED, /**< The link is not secured. */
128129
ENCRYPTION_IN_PROGRESS, /**< Link security is being established. */
@@ -140,6 +141,7 @@ struct link_encryption_t : SafeEnum<link_encryption_t, uint8_t> {
140141
* Type that describe a pairing failure.
141142
*/
142143
struct pairing_failure_t : SafeEnum<pairing_failure_t, uint8_t> {
144+
/** struct scoped enum wrapped by the class */
143145
enum type {
144146
PASSKEY_ENTRY_FAILED = 0x01,
145147
OOB_NOT_AVAILABLE = 0x02,
@@ -259,12 +261,12 @@ class PasskeyAscii {
259261
uint8_t ascii[PASSKEY_LEN];
260262
};
261263

262-
template <size_t octet_size>
263-
struct octet_type_t {
264+
template <size_t array_size>
265+
struct byte_array_t {
264266
/**
265267
* Default to all zeroes
266268
*/
267-
octet_type_t() {
269+
byte_array_t() {
268270
memset(_value, 0x00, sizeof(_value));
269271
}
270272

@@ -273,7 +275,7 @@ struct octet_type_t {
273275
*
274276
* @param input_value value of the data.
275277
*/
276-
octet_type_t(const uint8_t *input_value) {
278+
byte_array_t(const uint8_t *input_value) {
277279
memcpy(_value, input_value, sizeof(_value));
278280
}
279281

@@ -283,21 +285,21 @@ struct octet_type_t {
283285
* @param input_value pointer to buffer.
284286
* @param size buffer size
285287
*/
286-
octet_type_t(const uint8_t* input_value, size_t size) {
288+
byte_array_t(const uint8_t* input_value, size_t size) {
287289
memcpy(_value, input_value, size);
288290
}
289291

290292
/**
291293
* Equal operator between two octet types.
292294
*/
293-
friend bool operator==(const octet_type_t& lhs, const octet_type_t& rhs) {
295+
friend bool operator==(const byte_array_t& lhs, const byte_array_t& rhs) {
294296
return memcmp(lhs._value, rhs._value, sizeof(lhs._value)) == 0;
295297
}
296298

297299
/**
298300
* Non equal operator between two octet types.
299301
*/
300-
friend bool operator!=(const octet_type_t& lhs, const octet_type_t& rhs) {
302+
friend bool operator!=(const byte_array_t& lhs, const byte_array_t& rhs) {
301303
return !(lhs == rhs);
302304
}
303305

@@ -326,36 +328,40 @@ struct octet_type_t {
326328
* Size in byte of a data.
327329
*/
328330
static size_t size() {
329-
return octet_size;
331+
return array_size;
330332
}
331333

332334
protected:
333-
uint8_t _value[octet_size];
335+
uint8_t _value[array_size];
334336
};
335337

336338
/** 128 bit keys used by paired devices */
337-
typedef octet_type_t<16> irk_t;
338-
typedef octet_type_t<16> csrk_t;
339-
typedef octet_type_t<16> ltk_t;
339+
typedef byte_array_t<16> irk_t;
340+
typedef byte_array_t<16> csrk_t;
341+
typedef byte_array_t<16> ltk_t;
340342

341343
/** Used to identify LTK for legacy pairing connections */
342-
typedef octet_type_t<2> ediv_t;
343-
typedef octet_type_t<8> rand_t;
344+
typedef byte_array_t<2> ediv_t;
345+
typedef byte_array_t<8> rand_t;
344346

345347
/** Out of band data exchanged during pairing */
346-
typedef octet_type_t<16> oob_tk_t; /**< legacy pairing TK */
347-
typedef octet_type_t<16> oob_lesc_value_t; /**< secure connections oob random 128 value */
348-
typedef octet_type_t<16> oob_confirm_t; /**< secure connections oob confirmation value */
348+
typedef byte_array_t<16> oob_tk_t; /**< legacy pairing TK */
349+
typedef byte_array_t<16> oob_lesc_value_t; /**< secure connections oob random 128 value */
350+
typedef byte_array_t<16> oob_confirm_t; /**< secure connections oob confirmation value */
349351

350352
/** data to be encrypted */
351-
typedef octet_type_t<16> encryption_block_t;
352-
typedef octet_type_t<32> public_key_coord_t;
353-
typedef octet_type_t<32> dhkey_t;
353+
typedef byte_array_t<16> encryption_block_t;
354+
355+
/** public key coordinate, two of which define the public key */
356+
typedef byte_array_t<32> public_key_coord_t;
357+
358+
/** Diffie-Hellman key */
359+
typedef byte_array_t<32> dhkey_t;
354360

355361
/**
356362
* MAC address data type.
357363
*/
358-
struct address_t : public octet_type_t<6> {
364+
struct address_t : public byte_array_t<6> {
359365
/**
360366
* Create an invalid mac address, equal to FF:FF:FF:FF:FF:FF
361367
*/

features/FEATURE_BLE/ble/Gap.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2322,7 +2322,7 @@ class Gap {
23222322
* @param[in] handle Handle of the terminated connection.
23232323
* @param[in] reason Reason of the disconnection.
23242324
*/
2325-
virtual void processDisconnectionEvent(Handle_t handle, DisconnectionReason_t reason)
2325+
void processDisconnectionEvent(Handle_t handle, DisconnectionReason_t reason)
23262326
{
23272327
/* Update Gap state */
23282328
--connectionCount;
@@ -2348,6 +2348,7 @@ class Gap {
23482348
* @param[in] type Advertising type of the packet.
23492349
* @param[in] advertisingDataLen Length of the advertisement data received.
23502350
* @param[in] advertisingData Pointer to the advertisement packet's data.
2351+
* @param[in] addressType address type of the peer
23512352
*/
23522353
void processAdvertisementReport(
23532354
const BLEProtocol::AddressBytes_t peerAddr,

features/FEATURE_BLE/ble/SecurityManager.h

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,18 @@
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

2222
#include "Gap.h"
2323
#include "CallChainOfFunctionPointersWithContext.h"
2424
#include "ble/BLETypes.h"
2525

26-
class SecurityManagerEventHandler;
27-
class LegacySecurityManagerEventHandler;
28-
2926
class SecurityManager {
3027
public:
28+
/** events sent and received when passkey is being entered */
3129
enum Keypress_t {
3230
KEYPRESS_STARTED, /**< Passkey entry started */
3331
KEYPRESS_ENTERED, /**< Passkey digit entered */
@@ -36,6 +34,7 @@ class SecurityManager {
3634
KEYPRESS_COMPLETED, /**< Passkey entry completed */
3735
};
3836

37+
/** level of security required from the link by the application */
3938
enum SecurityMode_t {
4039
SECURITY_MODE_NO_ACCESS,
4140
SECURITY_MODE_ENCRYPTION_OPEN_LINK, /**< Require no protection, open link. */
@@ -56,6 +55,7 @@ class SecurityManager {
5655
ENCRYPTED /**< The link is secure.*/
5756
};
5857

58+
/** Input/output capability of the device and application */
5959
enum SecurityIOCapabilities_t {
6060
IO_CAPS_DISPLAY_ONLY = 0x00, /**< Display only. */
6161
IO_CAPS_DISPLAY_YESNO = 0x01, /**< Display and yes/no entry. */
@@ -64,6 +64,7 @@ class SecurityManager {
6464
IO_CAPS_KEYBOARD_DISPLAY = 0x04, /**< Keyboard and display. */
6565
};
6666

67+
/** Result of security requests */
6768
enum SecurityCompletionStatus_t {
6869
SEC_STATUS_SUCCESS = 0x00, /**< Procedure completed with success. */
6970
SEC_STATUS_TIMEOUT = 0x01, /**< Procedure timed out. */
@@ -103,10 +104,10 @@ class SecurityManager {
103104
/** The stack will use these functions to signal events to the application,
104105
* subclass to override handlers. Use SecurityManager::setSecurityManagerEventHandler
105106
* to set the interface implementation to be used. */
106-
class SecurityManagerEventHandler {
107+
class EventHandler {
107108
public:
108-
SecurityManagerEventHandler() {};
109-
virtual ~SecurityManagerEventHandler() {};
109+
EventHandler() {};
110+
virtual ~EventHandler() {};
110111

111112
////////////////////////////////////////////////////////////////////////////
112113
// Pairing
@@ -243,7 +244,6 @@ class SecurityManager {
243244
/**
244245
* Indicate that the application needs to send OOB data to the peer.
245246
*
246-
* @param[in] connectionHandle connection connectionHandle
247247
* @param[in] address address that will be used in the pairing
248248
* @param[in] random random number used to generate the confirmation
249249
* @param[in] confirm confirmation value to be use for authentication
@@ -703,7 +703,6 @@ class SecurityManager {
703703
/**
704704
* Supply the stack with the OOB data for legacy connections.
705705
*
706-
* @param[in] connectionHandle Handle to identify the connection.
707706
* @param[in] address address of the peer device this data comes from
708707
* @param[in] tk pointer to out of band data received containing the temporary key.
709708
* @return BLE_ERROR_NONE or appropriate error code indicating the failure reason.
@@ -717,7 +716,6 @@ class SecurityManager {
717716
/**
718717
* Supply the stack with the OOB data for secure connections.
719718
*
720-
* @param[in] connectionHandle Handle to identify the connection.
721719
* @param[in] address address of the peer device this data comes from
722720
* @param[in] random random number used to generate the confirmation
723721
* @param[in] confirm confirmation value to be use for authentication
@@ -793,7 +791,7 @@ class SecurityManager {
793791
*
794792
* @param[in] handler Event Handler interface implementation.
795793
*/
796-
virtual void setSecurityManagerEventHandler(SecurityManagerEventHandler* handler) {
794+
virtual void setSecurityManagerEventHandler(EventHandler* handler) {
797795
if (handler) {
798796
eventHandler = handler;
799797
} else {
@@ -934,9 +932,9 @@ class SecurityManager {
934932
private:
935933
/* Legacy compatibility with old callbacks (from both sides so any
936934
* combination of new and old works) */
937-
class LegacySecurityManagerEventHandler : public SecurityManagerEventHandler {
935+
class LegacyEventHandler : public EventHandler {
938936
public:
939-
LegacySecurityManagerEventHandler() :
937+
LegacyEventHandler() :
940938
securitySetupInitiatedCallback(),
941939
securitySetupCompletedCallback(),
942940
linkSecuredCallback(),
@@ -980,8 +978,8 @@ class SecurityManager {
980978
SecurityManagerShutdownCallbackChain_t shutdownCallChain;
981979

982980
protected:
983-
SecurityManagerEventHandler* eventHandler;
984-
LegacySecurityManagerEventHandler defaultEventHandler;
981+
EventHandler* eventHandler;
982+
LegacyEventHandler defaultEventHandler;
985983
};
986984

987-
#endif /*__SECURITY_MANAGER_H__*/
985+
#endif /*_SECURITY_MANAGER_H_*/

features/FEATURE_BLE/ble/generic/GenericGap.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ class GenericGap : public ::Gap,
254254
/**
255255
* @copydoc ::Gap::processConnectionEvent
256256
*/
257-
virtual void processConnectionEvent(
257+
void processConnectionEvent(
258258
Handle_t handle,
259259
Role_t role,
260260
BLEProtocol::AddressType_t peerAddrType,
@@ -267,17 +267,17 @@ class GenericGap : public ::Gap,
267267
/**
268268
* @copydoc ::Gap::processDisconnectionEvent
269269
*/
270-
virtual void processDisconnectionEvent(
270+
void processDisconnectionEvent(
271271
Handle_t handle,
272272
DisconnectionReason_t reason
273273
);
274274

275+
private:
275276
/** @note Implements ConnectionEventMonitor.
276277
* @copydoc ConnectionEventMonitor::set_connection_event_handler
277278
*/
278279
void set_connection_event_handler(pal::ConnectionEventHandler *_connection_event_handler);
279280

280-
private:
281281
void on_scan_timeout();
282282

283283
void process_scan_timeout();

0 commit comments

Comments
 (0)