mirror of https://github.com/ARMmbed/mbed-os.git
Move BLE whitelist APIs from LegacyGap to ble::Gap
parent
eee3b687c4
commit
e97582bd23
|
@ -21,6 +21,7 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "ble/SafeEnum.h"
|
#include "ble/SafeEnum.h"
|
||||||
|
#include "ble/BLEProtocol.h"
|
||||||
#include "platform/Span.h"
|
#include "platform/Span.h"
|
||||||
#include "ble/gap/Types.h"
|
#include "ble/gap/Types.h"
|
||||||
|
|
||||||
|
@ -831,6 +832,27 @@ struct coded_symbol_per_bit_t :SafeEnum<coded_symbol_per_bit_t, uint8_t> {
|
||||||
SafeEnum<coded_symbol_per_bit_t, uint8_t>(value) { }
|
SafeEnum<coded_symbol_per_bit_t, uint8_t>(value) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Representation of a whitelist of addresses.
|
||||||
|
*/
|
||||||
|
struct whitelist_t {
|
||||||
|
/**
|
||||||
|
* Pointer to the array of the addresses composing the whitelist.
|
||||||
|
*/
|
||||||
|
BLEProtocol::Address_t *addresses;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Number addresses in this whitelist.
|
||||||
|
*/
|
||||||
|
uint8_t size;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Capacity of the array holding the addresses.
|
||||||
|
*/
|
||||||
|
uint8_t capacity;
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace ble
|
} // namespace ble
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -221,26 +221,6 @@ public:
|
||||||
INIT_POLICY_FILTER_ALL_ADV = 1,
|
INIT_POLICY_FILTER_ALL_ADV = 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Representation of a whitelist of addresses.
|
|
||||||
*/
|
|
||||||
struct Whitelist_t {
|
|
||||||
/**
|
|
||||||
* Pointer to the array of the addresses composing the whitelist.
|
|
||||||
*/
|
|
||||||
BLEProtocol::Address_t *addresses;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Number addresses in this whitelist.
|
|
||||||
*/
|
|
||||||
uint8_t size;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Capacity of the array holding the addresses.
|
|
||||||
*/
|
|
||||||
uint8_t capacity;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description of the states of the device.
|
* Description of the states of the device.
|
||||||
*/
|
*/
|
||||||
|
@ -804,51 +784,6 @@ public:
|
||||||
ble_error_t getAppearance(GapAdvertisingData::Appearance *appearanceP);
|
ble_error_t getAppearance(GapAdvertisingData::Appearance *appearanceP);
|
||||||
#endif // BLE_FEATURE_GATT_SERVER
|
#endif // BLE_FEATURE_GATT_SERVER
|
||||||
|
|
||||||
#if BLE_FEATURE_WHITELIST
|
|
||||||
/**
|
|
||||||
* Get the maximum size of the whitelist.
|
|
||||||
*
|
|
||||||
* @return Maximum size of the whitelist.
|
|
||||||
*
|
|
||||||
* @note If using Mbed OS, you can configure the size of the whitelist by
|
|
||||||
* setting the YOTTA_CFG_WHITELIST_MAX_SIZE macro in your yotta config file.
|
|
||||||
*/
|
|
||||||
uint8_t getMaxWhitelistSize(void) const;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the Link Layer to use the internal whitelist when scanning,
|
|
||||||
* advertising or initiating a connection depending on the filter policies.
|
|
||||||
*
|
|
||||||
* @param[in,out] whitelist Define the whitelist instance which is used
|
|
||||||
* to store the whitelist requested. In input, the caller provisions memory.
|
|
||||||
*
|
|
||||||
* @return BLE_ERROR_NONE if the implementation's whitelist was successfully
|
|
||||||
* copied into the supplied reference.
|
|
||||||
*/
|
|
||||||
ble_error_t getWhitelist(Whitelist_t &whitelist) const;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the value of the whitelist to be used during GAP procedures.
|
|
||||||
*
|
|
||||||
* @param[in] whitelist A reference to a whitelist containing the addresses
|
|
||||||
* to be copied to the internal whitelist.
|
|
||||||
*
|
|
||||||
* @return BLE_ERROR_NONE if the implementation's whitelist was successfully
|
|
||||||
* populated with the addresses in the given whitelist.
|
|
||||||
*
|
|
||||||
* @note The whitelist must not contain addresses of type @ref
|
|
||||||
* BLEProtocol::AddressType::RANDOM_PRIVATE_NON_RESOLVABLE. This
|
|
||||||
* results in a @ref BLE_ERROR_INVALID_PARAM because the remote peer might
|
|
||||||
* change its private address at any time, and it is not possible to resolve
|
|
||||||
* it.
|
|
||||||
*
|
|
||||||
* @note If the input whitelist is larger than @ref getMaxWhitelistSize(),
|
|
||||||
* then @ref BLE_ERROR_PARAM_OUT_OF_RANGE is returned.
|
|
||||||
*/
|
|
||||||
ble_error_t setWhitelist(const Whitelist_t &whitelist);
|
|
||||||
|
|
||||||
#endif // BLE_FEATURE_WHITELIST
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* APIs with nonvirtual implementations.
|
* APIs with nonvirtual implementations.
|
||||||
*/
|
*/
|
||||||
|
@ -1130,12 +1065,6 @@ protected:
|
||||||
|
|
||||||
/* --- Abstract calls to override --- */
|
/* --- Abstract calls to override --- */
|
||||||
|
|
||||||
uint8_t getMaxWhitelistSize_(void) const;
|
|
||||||
|
|
||||||
ble_error_t getWhitelist_(Whitelist_t &whitelist) const;
|
|
||||||
|
|
||||||
ble_error_t setWhitelist_(const Whitelist_t &whitelist);
|
|
||||||
|
|
||||||
ble_error_t getAddress_(
|
ble_error_t getAddress_(
|
||||||
BLEProtocol::AddressType_t *typeP,
|
BLEProtocol::AddressType_t *typeP,
|
||||||
BLEProtocol::AddressBytes_t address
|
BLEProtocol::AddressBytes_t address
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
#include "BLERoles.h"
|
#include "BLERoles.h"
|
||||||
#include "ble/common/StaticInterface.h"
|
#include "ble/common/StaticInterface.h"
|
||||||
#include "ble/BLETypes.h"
|
#include "ble/BLETypes.h"
|
||||||
#include "ble/BLEProtocol.h"
|
|
||||||
#include "ble/gap/AdvertisingDataBuilder.h"
|
#include "ble/gap/AdvertisingDataBuilder.h"
|
||||||
#include "ble/gap/AdvertisingDataSimpleBuilder.h"
|
#include "ble/gap/AdvertisingDataSimpleBuilder.h"
|
||||||
#include "ble/gap/ConnectionParameters.h"
|
#include "ble/gap/ConnectionParameters.h"
|
||||||
|
@ -1256,6 +1255,48 @@ public:
|
||||||
#endif // BLE_ROLE_OBSERVER
|
#endif // BLE_ROLE_OBSERVER
|
||||||
#endif // BLE_FEATURE_PRIVACY
|
#endif // BLE_FEATURE_PRIVACY
|
||||||
|
|
||||||
|
#if BLE_FEATURE_WHITELIST
|
||||||
|
/**
|
||||||
|
* Get the maximum size of the whitelist.
|
||||||
|
*
|
||||||
|
* @return Maximum size of the whitelist.
|
||||||
|
*/
|
||||||
|
uint8_t getMaxWhitelistSize(void) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Link Layer to use the internal whitelist when scanning,
|
||||||
|
* advertising or initiating a connection depending on the filter policies.
|
||||||
|
*
|
||||||
|
* @param[in,out] whitelist Define the whitelist instance which is used
|
||||||
|
* to store the whitelist requested. In input, the caller provisions memory.
|
||||||
|
*
|
||||||
|
* @return BLE_ERROR_NONE if the implementation's whitelist was successfully
|
||||||
|
* copied into the supplied reference.
|
||||||
|
*/
|
||||||
|
ble_error_t getWhitelist(whitelist_t &whitelist) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the value of the whitelist to be used during GAP procedures.
|
||||||
|
*
|
||||||
|
* @param[in] whitelist A reference to a whitelist containing the addresses
|
||||||
|
* to be copied to the internal whitelist.
|
||||||
|
*
|
||||||
|
* @return BLE_ERROR_NONE if the implementation's whitelist was successfully
|
||||||
|
* populated with the addresses in the given whitelist.
|
||||||
|
*
|
||||||
|
* @note The whitelist must not contain addresses of type @ref
|
||||||
|
* BLEProtocol::AddressType::RANDOM_PRIVATE_NON_RESOLVABLE. This
|
||||||
|
* results in a @ref BLE_ERROR_INVALID_PARAM because the remote peer might
|
||||||
|
* change its private address at any time, and it is not possible to resolve
|
||||||
|
* it.
|
||||||
|
*
|
||||||
|
* @note If the input whitelist is larger than @ref getMaxWhitelistSize(),
|
||||||
|
* then @ref BLE_ERROR_PARAM_OUT_OF_RANGE is returned.
|
||||||
|
*/
|
||||||
|
ble_error_t setWhitelist(const whitelist_t &whitelist);
|
||||||
|
|
||||||
|
#endif // BLE_FEATURE_WHITELIST
|
||||||
|
|
||||||
#if !defined(DOXYGEN_ONLY)
|
#if !defined(DOXYGEN_ONLY)
|
||||||
/*
|
/*
|
||||||
* API reserved for the controller driver to set the random static address.
|
* API reserved for the controller driver to set the random static address.
|
||||||
|
@ -1406,6 +1447,9 @@ protected:
|
||||||
central_privay_configuration_t *configuration
|
central_privay_configuration_t *configuration
|
||||||
);
|
);
|
||||||
ble_error_t setRandomStaticAddress_(const ble::address_t& address);
|
ble_error_t setRandomStaticAddress_(const ble::address_t& address);
|
||||||
|
uint8_t getMaxWhitelistSize_(void) const;
|
||||||
|
ble_error_t getWhitelist_(whitelist_t &whitelist) const;
|
||||||
|
ble_error_t setWhitelist_(const whitelist_t &whitelist);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -19,23 +19,6 @@
|
||||||
namespace ble {
|
namespace ble {
|
||||||
namespace interface {
|
namespace interface {
|
||||||
|
|
||||||
#if BLE_FEATURE_WHITELIST
|
|
||||||
template<class Impl>
|
|
||||||
uint8_t LegacyGap<Impl>::getMaxWhitelistSize(void) const {
|
|
||||||
return impl()->getMaxWhitelistSize_();
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class Impl>
|
|
||||||
ble_error_t LegacyGap<Impl>::getWhitelist(Whitelist_t &whitelist) const {
|
|
||||||
return impl()->getWhitelist_(whitelist);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class Impl>
|
|
||||||
ble_error_t LegacyGap<Impl>::setWhitelist(const Whitelist_t &whitelist) {
|
|
||||||
return impl()->setWhitelist_(whitelist);
|
|
||||||
}
|
|
||||||
#endif // BLE_FEATURE_WHITELIST
|
|
||||||
|
|
||||||
template<class Impl>
|
template<class Impl>
|
||||||
void LegacyGap<Impl>::processConnectionEvent(
|
void LegacyGap<Impl>::processConnectionEvent(
|
||||||
Handle_t handle,
|
Handle_t handle,
|
||||||
|
@ -358,21 +341,6 @@ ble_error_t LegacyGap<Impl>::reset_(void)
|
||||||
/* ------------------------- Default implementations ------------------------ */
|
/* ------------------------- Default implementations ------------------------ */
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
template<class Impl>
|
|
||||||
uint8_t LegacyGap<Impl>::getMaxWhitelistSize_(void) const {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class Impl>
|
|
||||||
ble_error_t LegacyGap<Impl>::getWhitelist_(Whitelist_t &whitelist) const {
|
|
||||||
return BLE_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class Impl>
|
|
||||||
ble_error_t LegacyGap<Impl>::setWhitelist_(const Whitelist_t &whitelist) {
|
|
||||||
return BLE_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class Impl>
|
template<class Impl>
|
||||||
ble_error_t LegacyGap<Impl>::getAddress_(
|
ble_error_t LegacyGap<Impl>::getAddress_(
|
||||||
BLEProtocol::AddressType_t *typeP,
|
BLEProtocol::AddressType_t *typeP,
|
||||||
|
|
|
@ -488,6 +488,24 @@ ble_error_t Gap<Impl>::setRandomStaticAddress(const ble::address_t& address)
|
||||||
return impl()->setRandomStaticAddress_(address);
|
return impl()->setRandomStaticAddress_(address);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if BLE_FEATURE_WHITELIST
|
||||||
|
template<class Impl>
|
||||||
|
uint8_t Gap<Impl>::getMaxWhitelistSize(void) const {
|
||||||
|
return impl()->getMaxWhitelistSize_();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class Impl>
|
||||||
|
ble_error_t Gap<Impl>::getWhitelist(whitelist_t &whitelist) const {
|
||||||
|
return impl()->getWhitelist_(whitelist);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class Impl>
|
||||||
|
ble_error_t Gap<Impl>::setWhitelist(const whitelist_t &whitelist) {
|
||||||
|
return impl()->setWhitelist_(whitelist);
|
||||||
|
}
|
||||||
|
#endif // BLE_FEATURE_WHITELIST
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
/* ------------------------- Default implementations ------------------------ */
|
/* ------------------------- Default implementations ------------------------ */
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
|
@ -320,7 +320,7 @@ static bool is_disconnection_reason_valid(::Gap::DisconnectionReason_t reason)
|
||||||
/*
|
/*
|
||||||
* Return true if the whitelist in input is valid or false otherwise.
|
* Return true if the whitelist in input is valid or false otherwise.
|
||||||
*/
|
*/
|
||||||
static bool is_whitelist_valid(const ::Gap::Whitelist_t &whitelist)
|
static bool is_whitelist_valid(const ::ble::whitelist_t &whitelist)
|
||||||
{
|
{
|
||||||
if (whitelist.size > whitelist.capacity) {
|
if (whitelist.size > whitelist.capacity) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -347,7 +347,7 @@ static bool is_whitelist_valid(const ::Gap::Whitelist_t &whitelist)
|
||||||
* Return true if device is present in the whitelist.
|
* Return true if device is present in the whitelist.
|
||||||
*/
|
*/
|
||||||
static bool is_in_whitelist(
|
static bool is_in_whitelist(
|
||||||
const BLEProtocol::Address_t &device, const ::Gap::Whitelist_t &whitelist
|
const BLEProtocol::Address_t &device, const ::ble::whitelist_t &whitelist
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < whitelist.size; ++i) {
|
for (size_t i = 0; i < whitelist.size; ++i) {
|
||||||
|
@ -890,7 +890,7 @@ uint8_t GenericGap<PalGapImpl, PalSecurityManager, ConnectionEventMonitorEventHa
|
||||||
}
|
}
|
||||||
|
|
||||||
template <template<class> class PalGapImpl, class PalSecurityManager, class ConnectionEventMonitorEventHandler>
|
template <template<class> class PalGapImpl, class PalSecurityManager, class ConnectionEventMonitorEventHandler>
|
||||||
ble_error_t GenericGap<PalGapImpl, PalSecurityManager, ConnectionEventMonitorEventHandler>::getWhitelist_(Whitelist_t &whitelist) const
|
ble_error_t GenericGap<PalGapImpl, PalSecurityManager, ConnectionEventMonitorEventHandler>::getWhitelist_(whitelist_t &whitelist) const
|
||||||
{
|
{
|
||||||
if (initialize_whitelist() == false) {
|
if (initialize_whitelist() == false) {
|
||||||
return BLE_ERROR_INVALID_STATE;
|
return BLE_ERROR_INVALID_STATE;
|
||||||
|
@ -909,7 +909,7 @@ ble_error_t GenericGap<PalGapImpl, PalSecurityManager, ConnectionEventMonitorEve
|
||||||
}
|
}
|
||||||
|
|
||||||
template <template<class> class PalGapImpl, class PalSecurityManager, class ConnectionEventMonitorEventHandler>
|
template <template<class> class PalGapImpl, class PalSecurityManager, class ConnectionEventMonitorEventHandler>
|
||||||
ble_error_t GenericGap<PalGapImpl, PalSecurityManager, ConnectionEventMonitorEventHandler>::setWhitelist_(const Whitelist_t &whitelist)
|
ble_error_t GenericGap<PalGapImpl, PalSecurityManager, ConnectionEventMonitorEventHandler>::setWhitelist_(const whitelist_t &whitelist)
|
||||||
{
|
{
|
||||||
if (is_whitelist_valid(whitelist) == false) {
|
if (is_whitelist_valid(whitelist) == false) {
|
||||||
return BLE_ERROR_INVALID_PARAM;
|
return BLE_ERROR_INVALID_PARAM;
|
||||||
|
|
|
@ -165,7 +165,7 @@ ble_error_t GenericSecurityManager<TPalSecurityManager, SigningMonitor>::purgeAl
|
||||||
}
|
}
|
||||||
|
|
||||||
template<template<class> class TPalSecurityManager, template<class> class SigningMonitor>
|
template<template<class> class TPalSecurityManager, template<class> class SigningMonitor>
|
||||||
ble_error_t GenericSecurityManager<TPalSecurityManager, SigningMonitor>::generateWhitelistFromBondTable_(::Gap::Whitelist_t *whitelist) const {
|
ble_error_t GenericSecurityManager<TPalSecurityManager, SigningMonitor>::generateWhitelistFromBondTable_(::ble::whitelist_t *whitelist) const {
|
||||||
if (!_db) return BLE_ERROR_INITIALIZATION_INCOMPLETE;
|
if (!_db) return BLE_ERROR_INITIALIZATION_INCOMPLETE;
|
||||||
if (eventHandler) {
|
if (eventHandler) {
|
||||||
if (!whitelist) {
|
if (!whitelist) {
|
||||||
|
|
Loading…
Reference in New Issue