Skip to content

Commit 2113125

Browse files
committed
Move BLE whitelist APIs from LegacyGap to ble::Gap
1 parent 909b5b3 commit 2113125

File tree

7 files changed

+90
-109
lines changed

7 files changed

+90
-109
lines changed

features/FEATURE_BLE/ble/BLETypes.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <stdint.h>
2222
#include <string.h>
2323
#include "ble/SafeEnum.h"
24+
#include "ble/BLEProtocol.h"
2425
#include "platform/Span.h"
2526
#include "ble/gap/Types.h"
2627

@@ -831,6 +832,27 @@ struct coded_symbol_per_bit_t :SafeEnum<coded_symbol_per_bit_t, uint8_t> {
831832
SafeEnum<coded_symbol_per_bit_t, uint8_t>(value) { }
832833
};
833834

835+
836+
/**
837+
* Representation of a whitelist of addresses.
838+
*/
839+
struct whitelist_t {
840+
/**
841+
* Pointer to the array of the addresses composing the whitelist.
842+
*/
843+
BLEProtocol::Address_t *addresses;
844+
845+
/**
846+
* Number addresses in this whitelist.
847+
*/
848+
uint8_t size;
849+
850+
/**
851+
* Capacity of the array holding the addresses.
852+
*/
853+
uint8_t capacity;
854+
};
855+
834856
} // namespace ble
835857

836858
/**

features/FEATURE_BLE/ble/Gap.h

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -221,26 +221,6 @@ class LegacyGap :
221221
INIT_POLICY_FILTER_ALL_ADV = 1,
222222
};
223223

224-
/**
225-
* Representation of a whitelist of addresses.
226-
*/
227-
struct Whitelist_t {
228-
/**
229-
* Pointer to the array of the addresses composing the whitelist.
230-
*/
231-
BLEProtocol::Address_t *addresses;
232-
233-
/**
234-
* Number addresses in this whitelist.
235-
*/
236-
uint8_t size;
237-
238-
/**
239-
* Capacity of the array holding the addresses.
240-
*/
241-
uint8_t capacity;
242-
};
243-
244224
/**
245225
* Description of the states of the device.
246226
*/
@@ -804,51 +784,6 @@ class LegacyGap :
804784
ble_error_t getAppearance(GapAdvertisingData::Appearance *appearanceP);
805785
#endif // BLE_FEATURE_GATT_SERVER
806786

807-
#if BLE_FEATURE_WHITELIST
808-
/**
809-
* Get the maximum size of the whitelist.
810-
*
811-
* @return Maximum size of the whitelist.
812-
*
813-
* @note If using Mbed OS, you can configure the size of the whitelist by
814-
* setting the YOTTA_CFG_WHITELIST_MAX_SIZE macro in your yotta config file.
815-
*/
816-
uint8_t getMaxWhitelistSize(void) const;
817-
818-
/**
819-
* Get the Link Layer to use the internal whitelist when scanning,
820-
* advertising or initiating a connection depending on the filter policies.
821-
*
822-
* @param[in,out] whitelist Define the whitelist instance which is used
823-
* to store the whitelist requested. In input, the caller provisions memory.
824-
*
825-
* @return BLE_ERROR_NONE if the implementation's whitelist was successfully
826-
* copied into the supplied reference.
827-
*/
828-
ble_error_t getWhitelist(Whitelist_t &whitelist) const;
829-
830-
/**
831-
* Set the value of the whitelist to be used during GAP procedures.
832-
*
833-
* @param[in] whitelist A reference to a whitelist containing the addresses
834-
* to be copied to the internal whitelist.
835-
*
836-
* @return BLE_ERROR_NONE if the implementation's whitelist was successfully
837-
* populated with the addresses in the given whitelist.
838-
*
839-
* @note The whitelist must not contain addresses of type @ref
840-
* BLEProtocol::AddressType::RANDOM_PRIVATE_NON_RESOLVABLE. This
841-
* results in a @ref BLE_ERROR_INVALID_PARAM because the remote peer might
842-
* change its private address at any time, and it is not possible to resolve
843-
* it.
844-
*
845-
* @note If the input whitelist is larger than @ref getMaxWhitelistSize(),
846-
* then @ref BLE_ERROR_PARAM_OUT_OF_RANGE is returned.
847-
*/
848-
ble_error_t setWhitelist(const Whitelist_t &whitelist);
849-
850-
#endif // BLE_FEATURE_WHITELIST
851-
852787
/*
853788
* APIs with nonvirtual implementations.
854789
*/
@@ -1130,12 +1065,6 @@ class LegacyGap :
11301065

11311066
/* --- Abstract calls to override --- */
11321067

1133-
uint8_t getMaxWhitelistSize_(void) const;
1134-
1135-
ble_error_t getWhitelist_(Whitelist_t &whitelist) const;
1136-
1137-
ble_error_t setWhitelist_(const Whitelist_t &whitelist);
1138-
11391068
ble_error_t getAddress_(
11401069
BLEProtocol::AddressType_t *typeP,
11411070
BLEProtocol::AddressBytes_t address

features/FEATURE_BLE/ble/gap/Gap.h

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "BLERoles.h"
2121
#include "ble/common/StaticInterface.h"
2222
#include "ble/BLETypes.h"
23-
#include "ble/BLEProtocol.h"
2423
#include "ble/gap/AdvertisingDataBuilder.h"
2524
#include "ble/gap/AdvertisingDataSimpleBuilder.h"
2625
#include "ble/gap/ConnectionParameters.h"
@@ -1256,6 +1255,48 @@ class Gap : public StaticInterface<Impl, Gap> {
12561255
#endif // BLE_ROLE_OBSERVER
12571256
#endif // BLE_FEATURE_PRIVACY
12581257

1258+
#if BLE_FEATURE_WHITELIST
1259+
/**
1260+
* Get the maximum size of the whitelist.
1261+
*
1262+
* @return Maximum size of the whitelist.
1263+
*/
1264+
uint8_t getMaxWhitelistSize(void) const;
1265+
1266+
/**
1267+
* Get the Link Layer to use the internal whitelist when scanning,
1268+
* advertising or initiating a connection depending on the filter policies.
1269+
*
1270+
* @param[in,out] whitelist Define the whitelist instance which is used
1271+
* to store the whitelist requested. In input, the caller provisions memory.
1272+
*
1273+
* @return BLE_ERROR_NONE if the implementation's whitelist was successfully
1274+
* copied into the supplied reference.
1275+
*/
1276+
ble_error_t getWhitelist(whitelist_t &whitelist) const;
1277+
1278+
/**
1279+
* Set the value of the whitelist to be used during GAP procedures.
1280+
*
1281+
* @param[in] whitelist A reference to a whitelist containing the addresses
1282+
* to be copied to the internal whitelist.
1283+
*
1284+
* @return BLE_ERROR_NONE if the implementation's whitelist was successfully
1285+
* populated with the addresses in the given whitelist.
1286+
*
1287+
* @note The whitelist must not contain addresses of type @ref
1288+
* BLEProtocol::AddressType::RANDOM_PRIVATE_NON_RESOLVABLE. This
1289+
* results in a @ref BLE_ERROR_INVALID_PARAM because the remote peer might
1290+
* change its private address at any time, and it is not possible to resolve
1291+
* it.
1292+
*
1293+
* @note If the input whitelist is larger than @ref getMaxWhitelistSize(),
1294+
* then @ref BLE_ERROR_PARAM_OUT_OF_RANGE is returned.
1295+
*/
1296+
ble_error_t setWhitelist(const whitelist_t &whitelist);
1297+
1298+
#endif // BLE_FEATURE_WHITELIST
1299+
12591300
#if !defined(DOXYGEN_ONLY)
12601301
/*
12611302
* API reserved for the controller driver to set the random static address.
@@ -1406,6 +1447,9 @@ class Gap : public StaticInterface<Impl, Gap> {
14061447
central_privay_configuration_t *configuration
14071448
);
14081449
ble_error_t setRandomStaticAddress_(const ble::address_t& address);
1450+
uint8_t getMaxWhitelistSize_(void) const;
1451+
ble_error_t getWhitelist_(whitelist_t &whitelist) const;
1452+
ble_error_t setWhitelist_(const whitelist_t &whitelist);
14091453

14101454
protected:
14111455
/**

features/FEATURE_BLE/source/LegacyGap.tpp

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,6 @@
1919
namespace ble {
2020
namespace interface {
2121

22-
#if BLE_FEATURE_WHITELIST
23-
template<class Impl>
24-
uint8_t LegacyGap<Impl>::getMaxWhitelistSize(void) const {
25-
return impl()->getMaxWhitelistSize_();
26-
}
27-
28-
template<class Impl>
29-
ble_error_t LegacyGap<Impl>::getWhitelist(Whitelist_t &whitelist) const {
30-
return impl()->getWhitelist_(whitelist);
31-
}
32-
33-
template<class Impl>
34-
ble_error_t LegacyGap<Impl>::setWhitelist(const Whitelist_t &whitelist) {
35-
return impl()->setWhitelist_(whitelist);
36-
}
37-
#endif // BLE_FEATURE_WHITELIST
38-
3922
template<class Impl>
4023
void LegacyGap<Impl>::processConnectionEvent(
4124
Handle_t handle,
@@ -358,21 +341,6 @@ ble_error_t LegacyGap<Impl>::reset_(void)
358341
/* ------------------------- Default implementations ------------------------ */
359342
// -----------------------------------------------------------------------------
360343

361-
template<class Impl>
362-
uint8_t LegacyGap<Impl>::getMaxWhitelistSize_(void) const {
363-
return 0;
364-
}
365-
366-
template<class Impl>
367-
ble_error_t LegacyGap<Impl>::getWhitelist_(Whitelist_t &whitelist) const {
368-
return BLE_ERROR_NOT_IMPLEMENTED;
369-
}
370-
371-
template<class Impl>
372-
ble_error_t LegacyGap<Impl>::setWhitelist_(const Whitelist_t &whitelist) {
373-
return BLE_ERROR_NOT_IMPLEMENTED;
374-
}
375-
376344
template<class Impl>
377345
ble_error_t LegacyGap<Impl>::getAddress_(
378346
BLEProtocol::AddressType_t *typeP,

features/FEATURE_BLE/source/gap/Gap.tpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,24 @@ ble_error_t Gap<Impl>::setRandomStaticAddress(const ble::address_t& address)
488488
return impl()->setRandomStaticAddress_(address);
489489
}
490490

491+
492+
#if BLE_FEATURE_WHITELIST
493+
template<class Impl>
494+
uint8_t Gap<Impl>::getMaxWhitelistSize(void) const {
495+
return impl()->getMaxWhitelistSize_();
496+
}
497+
498+
template<class Impl>
499+
ble_error_t Gap<Impl>::getWhitelist(whitelist_t &whitelist) const {
500+
return impl()->getWhitelist_(whitelist);
501+
}
502+
503+
template<class Impl>
504+
ble_error_t Gap<Impl>::setWhitelist(const whitelist_t &whitelist) {
505+
return impl()->setWhitelist_(whitelist);
506+
}
507+
#endif // BLE_FEATURE_WHITELIST
508+
491509
// -----------------------------------------------------------------------------
492510
/* ------------------------- Default implementations ------------------------ */
493511
// -----------------------------------------------------------------------------

features/FEATURE_BLE/source/generic/GenericGap.tpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ static bool is_disconnection_reason_valid(::Gap::DisconnectionReason_t reason)
320320
/*
321321
* Return true if the whitelist in input is valid or false otherwise.
322322
*/
323-
static bool is_whitelist_valid(const ::Gap::Whitelist_t &whitelist)
323+
static bool is_whitelist_valid(const ::ble::whitelist_t &whitelist)
324324
{
325325
if (whitelist.size > whitelist.capacity) {
326326
return false;
@@ -347,7 +347,7 @@ static bool is_whitelist_valid(const ::Gap::Whitelist_t &whitelist)
347347
* Return true if device is present in the whitelist.
348348
*/
349349
static bool is_in_whitelist(
350-
const BLEProtocol::Address_t &device, const ::Gap::Whitelist_t &whitelist
350+
const BLEProtocol::Address_t &device, const ::ble::whitelist_t &whitelist
351351
)
352352
{
353353
for (size_t i = 0; i < whitelist.size; ++i) {
@@ -890,7 +890,7 @@ uint8_t GenericGap<PalGapImpl, PalSecurityManager, ConnectionEventMonitorEventHa
890890
}
891891

892892
template <template<class> class PalGapImpl, class PalSecurityManager, class ConnectionEventMonitorEventHandler>
893-
ble_error_t GenericGap<PalGapImpl, PalSecurityManager, ConnectionEventMonitorEventHandler>::getWhitelist_(Whitelist_t &whitelist) const
893+
ble_error_t GenericGap<PalGapImpl, PalSecurityManager, ConnectionEventMonitorEventHandler>::getWhitelist_(whitelist_t &whitelist) const
894894
{
895895
if (initialize_whitelist() == false) {
896896
return BLE_ERROR_INVALID_STATE;
@@ -909,7 +909,7 @@ ble_error_t GenericGap<PalGapImpl, PalSecurityManager, ConnectionEventMonitorEve
909909
}
910910

911911
template <template<class> class PalGapImpl, class PalSecurityManager, class ConnectionEventMonitorEventHandler>
912-
ble_error_t GenericGap<PalGapImpl, PalSecurityManager, ConnectionEventMonitorEventHandler>::setWhitelist_(const Whitelist_t &whitelist)
912+
ble_error_t GenericGap<PalGapImpl, PalSecurityManager, ConnectionEventMonitorEventHandler>::setWhitelist_(const whitelist_t &whitelist)
913913
{
914914
if (is_whitelist_valid(whitelist) == false) {
915915
return BLE_ERROR_INVALID_PARAM;

features/FEATURE_BLE/source/generic/GenericSecurityManager.tpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ ble_error_t GenericSecurityManager<TPalSecurityManager, SigningMonitor>::purgeAl
165165
}
166166

167167
template<template<class> class TPalSecurityManager, template<class> class SigningMonitor>
168-
ble_error_t GenericSecurityManager<TPalSecurityManager, SigningMonitor>::generateWhitelistFromBondTable_(::Gap::Whitelist_t *whitelist) const {
168+
ble_error_t GenericSecurityManager<TPalSecurityManager, SigningMonitor>::generateWhitelistFromBondTable_(::ble::whitelist_t *whitelist) const {
169169
if (!_db) return BLE_ERROR_INITIALIZATION_INCOMPLETE;
170170
if (eventHandler) {
171171
if (!whitelist) {

0 commit comments

Comments
 (0)