BLE - Devirtualization of the legacy NRF51822 port.

pull/9727/head
Vincent Coubard 2019-02-25 19:25:07 +00:00
parent 0323d91f04
commit b86049d1e7
9 changed files with 260 additions and 123 deletions

View File

@ -0,0 +1,42 @@
/* mbed Microcontroller Library
* Copyright (c) 2019 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ble/GattServer.h"
#include "source/GattServer.tpp"
#include "nRF5xGattServer.h"
#include "ble/GattClient.h"
#include "source/GattClient.tpp"
#include "nRF5xGattClient.h"
#include "ble/gap/Gap.h"
#include "ble/Gap.h"
#include "source/gap/Gap.tpp"
#include "source/LegacyGap.tpp"
#include "nRF5xGap.h"
#include "ble/SecurityManager.h"
#include "source/SecurityManager.tpp"
#include "nRF5xSecurityManager.h"
template class ble::interface::GattServer<nRF5xGattServer>;
template class ble::interface::GattClient<nRF5xGattClient>;
template class ble::interface::LegacyGap<nRF5xGap>;
template class ble::interface::Gap<nRF5xGap>;
template class ble::interface::SecurityManager<nRF5xSecurityManager>;

View File

@ -0,0 +1,70 @@
/* mbed Microcontroller Library
* Copyright (c) 2019 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef BLE_IMPLEMENTATION_FORWARD_H_
#define BLE_IMPLEMENTATION_FORWARD_H_
////////////////////////////////////////////////////////////////////////////////
// Forward declarations of the implementation types
//
namespace ble {
namespace interface {
template<class Impl>
class LegacyGap;
template<class Impl>
class Gap;
template<class Impl>
class GattClient;
template<class Impl>
class SecurityManager;
template<class Impl>
class GattServer;
} // namespace interface
} // ble
class nRF5xGap;
class nRF5xGattClient;
class nRF5xGattServer;
class nRF5xSecurityManager;
// implementation assembly
namespace ble {
namespace impl {
// SECURITY MANAGER
typedef interface::SecurityManager<nRF5xSecurityManager> SecurityManager;
// GAP
typedef interface::LegacyGap<nRF5xGap> LegacyGap;
typedef interface::Gap<nRF5xGap> Gap;
// GATT CLIENT
typedef interface::GattClient<nRF5xGattClient> GattClient;
// GATT SERVER
typedef ble::interface::GattServer<nRF5xGattServer> GattServer;
} // impl
} // ble
#endif //BLE_IMPLEMENTATION_FORWARD_H_

View File

@ -68,7 +68,7 @@ void radioNotificationStaticCallback(bool param) {
@endcode
*/
/**************************************************************************/
ble_error_t nRF5xGap::setAdvertisingData(const GapAdvertisingData &advData, const GapAdvertisingData &scanResponse)
ble_error_t nRF5xGap::setAdvertisingData_(const GapAdvertisingData &advData, const GapAdvertisingData &scanResponse)
{
/* Make sure we don't exceed the advertising payload length */
if (advData.getPayloadLen() > GAP_ADVERTISING_DATA_MAX_PAYLOAD) {
@ -133,7 +133,7 @@ ble_error_t nRF5xGap::setAdvertisingData(const GapAdvertisingData &advData, cons
@endcode
*/
/**************************************************************************/
ble_error_t nRF5xGap::startAdvertising(const GapAdvertisingParams &params)
ble_error_t nRF5xGap::startAdvertising_(const GapAdvertisingParams &params)
{
/* Make sure we support the advertising type */
if (params.getAdvertisingType() == GapAdvertisingParams::ADV_CONNECTABLE_DIRECTED) {
@ -179,7 +179,7 @@ ble_error_t nRF5xGap::startAdvertising(const GapAdvertisingParams &params)
whitelist.irk_count = 0;
/* Add missing IRKs to whitelist from the bond table held by the SoftDevice */
if (advertisingPolicyMode != Gap::ADV_POLICY_IGNORE_WHITELIST) {
if (advertisingPolicyMode != ADV_POLICY_IGNORE_WHITELIST) {
ble_error_t error = generateStackWhitelist(whitelist);
if (error != BLE_ERROR_NONE) {
return error;
@ -203,7 +203,7 @@ ble_error_t nRF5xGap::startAdvertising(const GapAdvertisingParams &params)
/* Observer role is not supported by S110, return BLE_ERROR_NOT_IMPLEMENTED */
#if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110)
ble_error_t nRF5xGap::startRadioScan(const GapScanningParams &scanningParams)
ble_error_t nRF5xGap::startRadioScan_(const GapScanningParams &scanningParams)
{
/* Allocate the stack's whitelist statically */
ble_gap_whitelist_t whitelist;
@ -216,7 +216,7 @@ ble_error_t nRF5xGap::startRadioScan(const GapScanningParams &scanningParams)
whitelist.irk_count = 0;
/* Add missing IRKs to whitelist from the bond table held by the SoftDevice */
if (scanningPolicyMode != Gap::SCAN_POLICY_IGNORE_WHITELIST) {
if (scanningPolicyMode != SCAN_POLICY_IGNORE_WHITELIST) {
ble_error_t error = generateStackWhitelist(whitelist);
if (error != BLE_ERROR_NONE) {
return error;
@ -239,7 +239,7 @@ ble_error_t nRF5xGap::startRadioScan(const GapScanningParams &scanningParams)
return BLE_ERROR_NONE;
}
ble_error_t nRF5xGap::stopScan(void) {
ble_error_t nRF5xGap::stopScan_(void) {
if (sd_ble_gap_scan_stop() == NRF_SUCCESS) {
return BLE_ERROR_NONE;
}
@ -264,7 +264,7 @@ ble_error_t nRF5xGap::stopScan(void) {
@endcode
*/
/**************************************************************************/
ble_error_t nRF5xGap::stopAdvertising(void)
ble_error_t nRF5xGap::stopAdvertising_(void)
{
/* Stop Advertising */
ASSERT_TRUE(ERROR_NONE == sd_ble_gap_adv_stop(), BLE_ERROR_PARAM_OUT_OF_RANGE);
@ -274,14 +274,14 @@ ble_error_t nRF5xGap::stopAdvertising(void)
return BLE_ERROR_NONE;
}
ble_error_t nRF5xGap::connect(const Address_t peerAddr,
ble_error_t nRF5xGap::connect_(const Address_t peerAddr,
BLEProtocol::AddressType_t peerAddrType,
const ConnectionParams_t *connectionParams,
const GapScanningParams *scanParamsIn)
{
ble_gap_addr_t addr;
addr.addr_type = peerAddrType;
memcpy(addr.addr, peerAddr, Gap::ADDR_LEN);
memcpy(addr.addr, peerAddr, ADDR_LEN);
ble_gap_conn_params_t connParams;
if (connectionParams != NULL) {
@ -307,7 +307,7 @@ ble_error_t nRF5xGap::connect(const Address_t peerAddr,
whitelist.irk_count = 0;
/* Add missing IRKs to whitelist from the bond table held by the SoftDevice */
if (scanningPolicyMode != Gap::SCAN_POLICY_IGNORE_WHITELIST) {
if (scanningPolicyMode != SCAN_POLICY_IGNORE_WHITELIST) {
ble_error_t error = generateStackWhitelist(whitelist);
if (error != BLE_ERROR_NONE) {
return error;
@ -352,7 +352,7 @@ ble_error_t nRF5xGap::connect(const Address_t peerAddr,
}
}
ble_error_t nRF5xGap::disconnect(Handle_t connectionHandle, DisconnectionReason_t reason)
ble_error_t nRF5xGap::disconnect_(Handle_t connectionHandle, DisconnectionReason_t reason)
{
uint8_t code = BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION;
switch (reason) {
@ -380,12 +380,12 @@ ble_error_t nRF5xGap::disconnect(Handle_t connectionHandle, DisconnectionReason_
@retval BLE_ERROR_NONE
Everything executed properly
*/
ble_error_t nRF5xGap::disconnect(DisconnectionReason_t reason)
ble_error_t nRF5xGap::disconnect_(DisconnectionReason_t reason)
{
return disconnect(m_connectionHandle, reason);
return this->disconnect(m_connectionHandle, reason);
}
ble_error_t nRF5xGap::getPreferredConnectionParams(ConnectionParams_t *params)
ble_error_t nRF5xGap::getPreferredConnectionParams_(ConnectionParams_t *params)
{
ASSERT_INT(NRF_SUCCESS,
sd_ble_gap_ppcp_get(reinterpret_cast<ble_gap_conn_params_t *>(params)),
@ -394,7 +394,7 @@ ble_error_t nRF5xGap::getPreferredConnectionParams(ConnectionParams_t *params)
return BLE_ERROR_NONE;
}
ble_error_t nRF5xGap::setPreferredConnectionParams(const ConnectionParams_t *params)
ble_error_t nRF5xGap::setPreferredConnectionParams_(const ConnectionParams_t *params)
{
ASSERT_INT(NRF_SUCCESS,
sd_ble_gap_ppcp_set(reinterpret_cast<const ble_gap_conn_params_t *>(params)),
@ -403,7 +403,7 @@ ble_error_t nRF5xGap::setPreferredConnectionParams(const ConnectionParams_t *par
return BLE_ERROR_NONE;
}
ble_error_t nRF5xGap::updateConnectionParams(Handle_t handle, const ConnectionParams_t *newParams)
ble_error_t nRF5xGap::updateConnectionParams_(Handle_t handle, const ConnectionParams_t *newParams)
{
uint32_t rc;
@ -425,10 +425,10 @@ ble_error_t nRF5xGap::updateConnectionParams(Handle_t handle, const ConnectionPa
Everything executed properly
*/
/**************************************************************************/
ble_error_t nRF5xGap::reset(void)
ble_error_t nRF5xGap::reset_(void)
{
/* Clear all state that is from the parent, including private members */
if (Gap::reset() != BLE_ERROR_NONE) {
if (ble::interface::LegacyGap<nRF5xGap>::reset_() != BLE_ERROR_NONE) {
return BLE_ERROR_INVALID_STATE;
}
@ -436,8 +436,8 @@ ble_error_t nRF5xGap::reset(void)
m_connectionHandle = BLE_CONN_HANDLE_INVALID;
/* Set the whitelist policy filter modes to IGNORE_WHITELIST */
advertisingPolicyMode = Gap::ADV_POLICY_IGNORE_WHITELIST;
scanningPolicyMode = Gap::SCAN_POLICY_IGNORE_WHITELIST;
advertisingPolicyMode = ADV_POLICY_IGNORE_WHITELIST;
scanningPolicyMode = SCAN_POLICY_IGNORE_WHITELIST;
/* Clear the internal whitelist */
whitelistAddressesSize = 0;
@ -481,7 +481,7 @@ uint16_t nRF5xGap::getConnectionHandle(void)
@endcode
*/
/**************************************************************************/
ble_error_t nRF5xGap::setAddress(AddressType_t type, const Address_t address)
ble_error_t nRF5xGap::setAddress_(AddressType_t type, const Address_t address)
{
uint8_t cycle_mode;
ble_gap_addr_t dev_addr;
@ -511,7 +511,7 @@ ble_error_t nRF5xGap::setAddress(AddressType_t type, const Address_t address)
return BLE_ERROR_NONE;
}
ble_error_t nRF5xGap::getAddress(AddressType_t *typeP, Address_t address)
ble_error_t nRF5xGap::getAddress_(AddressType_t *typeP, Address_t address)
{
ble_gap_addr_t dev_addr;
if (sd_ble_gap_address_get(&dev_addr) != NRF_SUCCESS) {
@ -527,7 +527,7 @@ ble_error_t nRF5xGap::getAddress(AddressType_t *typeP, Address_t address)
return BLE_ERROR_NONE;
}
ble_error_t nRF5xGap::setDeviceName(const uint8_t *deviceName)
ble_error_t nRF5xGap::setDeviceName_(const uint8_t *deviceName)
{
ble_gap_conn_sec_mode_t sec_mode;
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode); // no security is needed
@ -539,7 +539,7 @@ ble_error_t nRF5xGap::setDeviceName(const uint8_t *deviceName)
}
}
ble_error_t nRF5xGap::getDeviceName(uint8_t *deviceName, unsigned *lengthP)
ble_error_t nRF5xGap::getDeviceName_(uint8_t *deviceName, unsigned *lengthP)
{
if (sd_ble_gap_device_name_get(deviceName, (uint16_t *)lengthP) == NRF_SUCCESS) {
return BLE_ERROR_NONE;
@ -548,7 +548,7 @@ ble_error_t nRF5xGap::getDeviceName(uint8_t *deviceName, unsigned *lengthP)
}
}
ble_error_t nRF5xGap::setAppearance(GapAdvertisingData::Appearance appearance)
ble_error_t nRF5xGap::setAppearance_(GapAdvertisingData::Appearance appearance)
{
if (sd_ble_gap_appearance_set(appearance) == NRF_SUCCESS) {
return BLE_ERROR_NONE;
@ -557,7 +557,7 @@ ble_error_t nRF5xGap::setAppearance(GapAdvertisingData::Appearance appearance)
}
}
ble_error_t nRF5xGap::getAppearance(GapAdvertisingData::Appearance *appearanceP)
ble_error_t nRF5xGap::getAppearance_(GapAdvertisingData::Appearance *appearanceP)
{
if ((sd_ble_gap_appearance_get(reinterpret_cast<uint16_t *>(appearanceP)) == NRF_SUCCESS)) {
return BLE_ERROR_NONE;
@ -567,7 +567,7 @@ ble_error_t nRF5xGap::getAppearance(GapAdvertisingData::Appearance *appearanceP)
}
/* (Valid values are -40, -20, -16, -12, -8, -4, 0, 4) */
ble_error_t nRF5xGap::setTxPower(int8_t txPower)
ble_error_t nRF5xGap::setTxPower_(int8_t txPower)
{
unsigned rc;
if ((rc = sd_ble_gap_tx_power_set(txPower)) != NRF_SUCCESS) {
@ -583,7 +583,7 @@ ble_error_t nRF5xGap::setTxPower(int8_t txPower)
return BLE_ERROR_NONE;
}
void nRF5xGap::getPermittedTxPowerValues(const int8_t **valueArrayPP, size_t *countP)
void nRF5xGap::getPermittedTxPowerValues_(const int8_t **valueArrayPP, size_t *countP)
{
static const int8_t permittedTxValues[] = {
-40, -30, -20, -16, -12, -8, -4, 0, 4
@ -607,7 +607,7 @@ void nRF5xGap::getPermittedTxPowerValues(const int8_t **valueArrayPP, size_t *co
@endcode
*/
/**************************************************************************/
uint8_t nRF5xGap::getMaxWhitelistSize(void) const
uint8_t nRF5xGap::getMaxWhitelistSize_(void) const
{
return YOTTA_CFG_WHITELIST_MAX_SIZE;
}
@ -632,7 +632,7 @@ uint8_t nRF5xGap::getMaxWhitelistSize(void) const
@endcode
*/
/**************************************************************************/
ble_error_t nRF5xGap::getWhitelist(Gap::Whitelist_t &whitelistOut) const
ble_error_t nRF5xGap::getWhitelist_(Whitelist_t &whitelistOut) const
{
uint8_t i;
for (i = 0; i < whitelistAddressesSize && i < whitelistOut.capacity; ++i) {
@ -673,9 +673,9 @@ ble_error_t nRF5xGap::getWhitelist(Gap::Whitelist_t &whitelistOut) const
@endcode
*/
/**************************************************************************/
ble_error_t nRF5xGap::setWhitelist(const Gap::Whitelist_t &whitelistIn)
ble_error_t nRF5xGap::setWhitelist_(const Whitelist_t &whitelistIn)
{
if (whitelistIn.size > getMaxWhitelistSize()) {
if (whitelistIn.size > this->getMaxWhitelistSize()) {
return BLE_ERROR_PARAM_OUT_OF_RANGE;
}
@ -716,7 +716,7 @@ ble_error_t nRF5xGap::setWhitelist(const Gap::Whitelist_t &whitelistIn)
@endcode
*/
/**************************************************************************/
ble_error_t nRF5xGap::setAdvertisingPolicyMode(Gap::AdvertisingPolicyMode_t mode)
ble_error_t nRF5xGap::setAdvertisingPolicyMode_(AdvertisingPolicyMode_t mode)
{
advertisingPolicyMode = mode;
@ -743,7 +743,7 @@ ble_error_t nRF5xGap::setAdvertisingPolicyMode(Gap::AdvertisingPolicyMode_t mode
@endcode
*/
/**************************************************************************/
ble_error_t nRF5xGap::setScanningPolicyMode(Gap::ScanningPolicyMode_t mode)
ble_error_t nRF5xGap::setScanningPolicyMode_(ScanningPolicyMode_t mode)
{
scanningPolicyMode = mode;
@ -770,7 +770,7 @@ ble_error_t nRF5xGap::setScanningPolicyMode(Gap::ScanningPolicyMode_t mode)
@endcode
*/
/**************************************************************************/
ble_error_t nRF5xGap::setInitiatorPolicyMode(Gap::InitiatorPolicyMode_t mode)
ble_error_t nRF5xGap::setInitiatorPolicyMode_(InitiatorPolicyMode_t mode)
{
return BLE_ERROR_NOT_IMPLEMENTED;
}
@ -788,7 +788,7 @@ ble_error_t nRF5xGap::setInitiatorPolicyMode(Gap::InitiatorPolicyMode_t mode)
@endcode
*/
/**************************************************************************/
Gap::AdvertisingPolicyMode_t nRF5xGap::getAdvertisingPolicyMode(void) const
Gap::AdvertisingPolicyMode_t nRF5xGap::getAdvertisingPolicyMode_(void) const
{
return advertisingPolicyMode;
}
@ -806,7 +806,7 @@ Gap::AdvertisingPolicyMode_t nRF5xGap::getAdvertisingPolicyMode(void) const
@endcode
*/
/**************************************************************************/
Gap::ScanningPolicyMode_t nRF5xGap::getScanningPolicyMode(void) const
Gap::ScanningPolicyMode_t nRF5xGap::getScanningPolicyMode_(void) const
{
return scanningPolicyMode;
}
@ -827,9 +827,9 @@ Gap::ScanningPolicyMode_t nRF5xGap::getScanningPolicyMode(void) const
@endcode
*/
/**************************************************************************/
Gap::InitiatorPolicyMode_t nRF5xGap::getInitiatorPolicyMode(void) const
Gap::InitiatorPolicyMode_t nRF5xGap::getInitiatorPolicyMode_(void) const
{
return Gap::INIT_POLICY_IGNORE_WHITELIST;
return INIT_POLICY_IGNORE_WHITELIST;
}
/**************************************************************************/

View File

@ -57,57 +57,63 @@ void radioNotificationStaticCallback(bool param);
*/
/**************************************************************************/
class nRF5xGap : public Gap
class nRF5xGap : public ble::interface::LegacyGap<nRF5xGap>
{
public:
/* Functions that must be implemented from Gap */
virtual ble_error_t setAddress(AddressType_t type, const Address_t address);
virtual ble_error_t getAddress(AddressType_t *typeP, Address_t address);
virtual ble_error_t setAdvertisingData(const GapAdvertisingData &, const GapAdvertisingData &);
ble_error_t setAddress_(AddressType_t type, const Address_t address);
ble_error_t getAddress_(AddressType_t *typeP, Address_t address);
ble_error_t setAdvertisingData_(const GapAdvertisingData &, const GapAdvertisingData &);
virtual uint16_t getMinAdvertisingInterval(void) const {return GapAdvertisingParams::ADVERTISEMENT_DURATION_UNITS_TO_MS(BLE_GAP_ADV_INTERVAL_MIN);}
virtual uint16_t getMinNonConnectableAdvertisingInterval(void) const {return GapAdvertisingParams::ADVERTISEMENT_DURATION_UNITS_TO_MS(BLE_GAP_ADV_NONCON_INTERVAL_MIN);}
virtual uint16_t getMaxAdvertisingInterval(void) const {return GapAdvertisingParams::ADVERTISEMENT_DURATION_UNITS_TO_MS(BLE_GAP_ADV_INTERVAL_MAX);}
uint16_t getMinAdvertisingInterval_(void) const {
return GapAdvertisingParams::ADVERTISEMENT_DURATION_UNITS_TO_MS(BLE_GAP_ADV_INTERVAL_MIN);
}
uint16_t getMinNonConnectableAdvertisingInterval_(void) const {
return GapAdvertisingParams::ADVERTISEMENT_DURATION_UNITS_TO_MS(BLE_GAP_ADV_NONCON_INTERVAL_MIN);
}
uint16_t getMaxAdvertisingInterval_(void) const {
return GapAdvertisingParams::ADVERTISEMENT_DURATION_UNITS_TO_MS(BLE_GAP_ADV_INTERVAL_MAX);
}
virtual ble_error_t startAdvertising(const GapAdvertisingParams &);
virtual ble_error_t stopAdvertising(void);
virtual ble_error_t connect(const Address_t, BLEProtocol::AddressType_t peerAddrType, const ConnectionParams_t *connectionParams, const GapScanningParams *scanParams);
virtual ble_error_t disconnect(Handle_t connectionHandle, DisconnectionReason_t reason);
virtual ble_error_t disconnect(DisconnectionReason_t reason);
ble_error_t startAdvertising_(const GapAdvertisingParams &);
ble_error_t stopAdvertising_(void);
ble_error_t connect_(const Address_t, BLEProtocol::AddressType_t peerAddrType, const ConnectionParams_t *connectionParams, const GapScanningParams *scanParams);
ble_error_t disconnect_(Handle_t connectionHandle, DisconnectionReason_t reason);
ble_error_t disconnect_(DisconnectionReason_t reason);
virtual ble_error_t setDeviceName(const uint8_t *deviceName);
virtual ble_error_t getDeviceName(uint8_t *deviceName, unsigned *lengthP);
virtual ble_error_t setAppearance(GapAdvertisingData::Appearance appearance);
virtual ble_error_t getAppearance(GapAdvertisingData::Appearance *appearanceP);
ble_error_t setDeviceName_(const uint8_t *deviceName);
ble_error_t getDeviceName_(uint8_t *deviceName, unsigned *lengthP);
ble_error_t setAppearance_(GapAdvertisingData::Appearance appearance);
ble_error_t getAppearance_(GapAdvertisingData::Appearance *appearanceP);
virtual ble_error_t setTxPower(int8_t txPower);
virtual void getPermittedTxPowerValues(const int8_t **valueArrayPP, size_t *countP);
ble_error_t setTxPower_(int8_t txPower);
void getPermittedTxPowerValues_(const int8_t **valueArrayPP, size_t *countP);
void setConnectionHandle(uint16_t con_handle);
uint16_t getConnectionHandle(void);
virtual ble_error_t getPreferredConnectionParams(ConnectionParams_t *params);
virtual ble_error_t setPreferredConnectionParams(const ConnectionParams_t *params);
virtual ble_error_t updateConnectionParams(Handle_t handle, const ConnectionParams_t *params);
ble_error_t getPreferredConnectionParams_(ConnectionParams_t *params);
ble_error_t setPreferredConnectionParams_(const ConnectionParams_t *params);
ble_error_t updateConnectionParams_(Handle_t handle, const ConnectionParams_t *params);
virtual ble_error_t reset(void);
ble_error_t reset_(void);
/*
* The following functions are part of the whitelisting experimental API.
* Therefore, this functionality can change in the near future.
*/
virtual uint8_t getMaxWhitelistSize(void) const;
virtual ble_error_t getWhitelist(Gap::Whitelist_t &whitelistOut) const;
virtual ble_error_t setWhitelist(const Gap::Whitelist_t &whitelistIn);
uint8_t getMaxWhitelistSize_(void) const;
ble_error_t getWhitelist_(Whitelist_t &whitelistOut) const;
ble_error_t setWhitelist_(const Whitelist_t &whitelistIn);
virtual ble_error_t setAdvertisingPolicyMode(AdvertisingPolicyMode_t mode);
virtual ble_error_t setScanningPolicyMode(ScanningPolicyMode_t mode);
virtual ble_error_t setInitiatorPolicyMode(InitiatorPolicyMode_t mode);
virtual Gap::AdvertisingPolicyMode_t getAdvertisingPolicyMode(void) const;
virtual Gap::ScanningPolicyMode_t getScanningPolicyMode(void) const;
virtual Gap::InitiatorPolicyMode_t getInitiatorPolicyMode(void) const;
ble_error_t setAdvertisingPolicyMode_(AdvertisingPolicyMode_t mode);
ble_error_t setScanningPolicyMode_(ScanningPolicyMode_t mode);
ble_error_t setInitiatorPolicyMode_(InitiatorPolicyMode_t mode);
AdvertisingPolicyMode_t getAdvertisingPolicyMode_(void) const;
ScanningPolicyMode_t getScanningPolicyMode_(void) const;
InitiatorPolicyMode_t getInitiatorPolicyMode_(void) const;
virtual ble_error_t initRadioNotification(void) {
ble_error_t initRadioNotification_(void) {
if (ble_radio_notification_init(NRF_APP_PRIORITY_HIGH, NRF_RADIO_NOTIFICATION_DISTANCE_800US, radioNotificationStaticCallback) == NRF_SUCCESS) {
return BLE_ERROR_NONE;
}
@ -117,18 +123,35 @@ public:
/* Observer role is not supported by S110, return BLE_ERROR_NOT_IMPLEMENTED */
#if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110)
virtual ble_error_t startRadioScan(const GapScanningParams &scanningParams);
virtual ble_error_t stopScan(void);
ble_error_t startRadioScan_(const GapScanningParams &scanningParams);
ble_error_t stopScan_(void);
#endif
protected:
// import from Gap
friend ble::interface::Gap<nRF5xGap>;
using ble::interface::Gap<nRF5xGap>::startAdvertising_;
using ble::interface::Gap<nRF5xGap>::stopAdvertising_;
using ble::interface::Gap<nRF5xGap>::connect_;
using ble::interface::Gap<nRF5xGap>::disconnect_;
// import from LegacyGap
friend ble::interface::LegacyGap<nRF5xGap>;
using ble::interface::LegacyGap<nRF5xGap>::startAdvertising_;
using ble::interface::LegacyGap<nRF5xGap>::stopAdvertising_;
using ble::interface::LegacyGap<nRF5xGap>::connect_;
using ble::interface::LegacyGap<nRF5xGap>::disconnect_;
private:
/*
* Whitelisting API related structures and helper functions.
*/
/* Policy modes set by the user. By default these are set to ignore the whitelist */
Gap::AdvertisingPolicyMode_t advertisingPolicyMode;
Gap::ScanningPolicyMode_t scanningPolicyMode;
AdvertisingPolicyMode_t advertisingPolicyMode;
ScanningPolicyMode_t scanningPolicyMode;
/* Internal representation of a whitelist */
uint8_t whitelistAddressesSize;
@ -233,8 +256,8 @@ private:
friend class nRF5xn;
nRF5xGap() :
advertisingPolicyMode(Gap::ADV_POLICY_IGNORE_WHITELIST),
scanningPolicyMode(Gap::SCAN_POLICY_IGNORE_WHITELIST),
advertisingPolicyMode(ADV_POLICY_IGNORE_WHITELIST),
scanningPolicyMode(SCAN_POLICY_IGNORE_WHITELIST),
whitelistAddressesSize(0) {
m_connectionHandle = BLE_CONN_HANDLE_INVALID;
}

View File

@ -18,7 +18,7 @@
#if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110)
ble_error_t
nRF5xGattClient::launchServiceDiscovery(Gap::Handle_t connectionHandle,
nRF5xGattClient::launchServiceDiscovery_(Gap::Handle_t connectionHandle,
ServiceDiscovery::ServiceCallback_t sc,
ServiceDiscovery::CharacteristicCallback_t cc,
const UUID &matchingServiceUUIDIn,
@ -27,7 +27,7 @@ nRF5xGattClient::launchServiceDiscovery(Gap::Handle_t
return _discovery.launch(connectionHandle, sc, cc, matchingServiceUUIDIn, matchingCharacteristicUUIDIn);
}
ble_error_t nRF5xGattClient::discoverCharacteristicDescriptors(
ble_error_t nRF5xGattClient::discoverCharacteristicDescriptors_(
const DiscoveredCharacteristic& characteristic,
const CharacteristicDescriptorDiscovery::DiscoveryCallback_t& discoveryCallback,
const CharacteristicDescriptorDiscovery::TerminationCallback_t& terminationCallback)
@ -39,11 +39,11 @@ ble_error_t nRF5xGattClient::discoverCharacteristicDescriptors(
);
}
bool nRF5xGattClient::isCharacteristicDescriptorsDiscoveryActive(const DiscoveredCharacteristic& characteristic) const {
bool nRF5xGattClient::isCharacteristicDescriptorsDiscoveryActive_(const DiscoveredCharacteristic& characteristic) const {
return _characteristicDescriptorDiscoverer.isActive(characteristic);
}
void nRF5xGattClient::terminateCharacteristicDescriptorsDiscovery(const DiscoveredCharacteristic& characteristic) {
void nRF5xGattClient::terminateCharacteristicDescriptorsDiscovery_(const DiscoveredCharacteristic& characteristic) {
return _characteristicDescriptorDiscoverer.requestTerminate(characteristic);
}

View File

@ -21,7 +21,7 @@
#include "nRF5xServiceDiscovery.h"
#include "nRF5xCharacteristicDescriptorDiscoverer.h"
class nRF5xGattClient : public GattClient
class nRF5xGattClient : public ble::interface::GattClient<nRF5xGattClient>
{
public:
/**
@ -79,20 +79,20 @@ public:
* @return
* BLE_ERROR_NONE if service discovery is launched successfully; else an appropriate error.
*/
virtual ble_error_t launchServiceDiscovery(Gap::Handle_t connectionHandle,
ble_error_t launchServiceDiscovery_(Gap::Handle_t connectionHandle,
ServiceDiscovery::ServiceCallback_t sc = NULL,
ServiceDiscovery::CharacteristicCallback_t cc = NULL,
const UUID &matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN),
const UUID &matchingCharacteristicUUIDIn = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN));
virtual void onServiceDiscoveryTermination(ServiceDiscovery::TerminationCallback_t callback) {
void onServiceDiscoveryTermination_(ServiceDiscovery::TerminationCallback_t callback) {
_discovery.onTermination(callback);
}
/**
* Is service-discovery currently active?
*/
virtual bool isServiceDiscoveryActive(void) const {
bool isServiceDiscoveryActive_(void) const {
return _discovery.isActive();
}
@ -100,7 +100,7 @@ public:
* Terminate an ongoing service-discovery. This should result in an
* invocation of the TerminationCallback if service-discovery is active.
*/
virtual void terminateServiceDiscovery(void) {
void terminateServiceDiscovery_(void) {
_discovery.terminate();
}
@ -108,7 +108,7 @@ public:
* @brief Implementation of GattClient::discoverCharacteristicDescriptors
* @see GattClient::discoverCharacteristicDescriptors
*/
virtual ble_error_t discoverCharacteristicDescriptors(
ble_error_t discoverCharacteristicDescriptors_(
const DiscoveredCharacteristic& characteristic,
const CharacteristicDescriptorDiscovery::DiscoveryCallback_t& discoveryCallback,
const CharacteristicDescriptorDiscovery::TerminationCallback_t& terminationCallback
@ -118,15 +118,15 @@ public:
* @brief Implementation of GattClient::isCharacteristicDiscoveryActive
* @see GattClient::isCharacteristicDiscoveryActive
*/
virtual bool isCharacteristicDescriptorsDiscoveryActive(const DiscoveredCharacteristic& characteristic) const;
bool isCharacteristicDescriptorsDiscoveryActive_(const DiscoveredCharacteristic& characteristic) const;
/**
* @brief Implementation of GattClient::terminateCharacteristicDiscovery
* @see GattClient::terminateCharacteristicDiscovery
*/
virtual void terminateCharacteristicDescriptorsDiscovery(const DiscoveredCharacteristic& characteristic);
void terminateCharacteristicDescriptorsDiscovery_(const DiscoveredCharacteristic& characteristic);
virtual ble_error_t read(Gap::Handle_t connHandle, GattAttribute::Handle_t attributeHandle, uint16_t offset) const {
ble_error_t read_(Gap::Handle_t connHandle, GattAttribute::Handle_t attributeHandle, uint16_t offset) const {
uint32_t rc = sd_ble_gattc_read(connHandle, attributeHandle, offset);
if (rc == NRF_SUCCESS) {
return BLE_ERROR_NONE;
@ -142,7 +142,7 @@ public:
}
}
virtual ble_error_t write(GattClient::WriteOp_t cmd, Gap::Handle_t connHandle, GattAttribute::Handle_t attributeHandle, size_t length, const uint8_t *value) const {
ble_error_t write_(GattClient::WriteOp_t cmd, Gap::Handle_t connHandle, GattAttribute::Handle_t attributeHandle, size_t length, const uint8_t *value) const {
ble_gattc_write_params_t writeParams;
writeParams.write_op = cmd;
writeParams.flags = 0; /* this is inconsequential */
@ -174,9 +174,9 @@ public:
* @return
* BLE_ERROR_NONE if successful.
*/
virtual ble_error_t reset(void) {
ble_error_t reset_(void) {
/* Clear all state that is from the parent, including private members */
if (GattClient::reset() != BLE_ERROR_NONE) {
if (ble::interface::GattClient<nRF5xGattClient>::reset_() != BLE_ERROR_NONE) {
return BLE_ERROR_INVALID_STATE;
}

View File

@ -70,7 +70,7 @@ static ble_error_t set_attribute_value(
@endcode
*/
/**************************************************************************/
ble_error_t nRF5xGattServer::addService(GattService &service)
ble_error_t nRF5xGattServer::addService_(GattService &service)
{
/* ToDo: Make sure this service UUID doesn't already exist (?) */
/* ToDo: Basic validation */
@ -199,12 +199,12 @@ ble_error_t nRF5xGattServer::addService(GattService &service)
Everything executed properly
*/
/**************************************************************************/
ble_error_t nRF5xGattServer::read(GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP)
ble_error_t nRF5xGattServer::read_(GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP)
{
return read(BLE_CONN_HANDLE_INVALID, attributeHandle, buffer, lengthP);
}
ble_error_t nRF5xGattServer::read(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP)
ble_error_t nRF5xGattServer::read_(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP)
{
ble_gatts_value_t value = {
.len = *lengthP,
@ -239,12 +239,12 @@ ble_error_t nRF5xGattServer::read(Gap::Handle_t connectionHandle, GattAttribute:
Everything executed properly
*/
/**************************************************************************/
ble_error_t nRF5xGattServer::write(GattAttribute::Handle_t attributeHandle, const uint8_t buffer[], uint16_t len, bool localOnly)
ble_error_t nRF5xGattServer::write_(GattAttribute::Handle_t attributeHandle, const uint8_t buffer[], uint16_t len, bool localOnly)
{
return write(BLE_CONN_HANDLE_INVALID, attributeHandle, buffer, len, localOnly);
}
ble_error_t nRF5xGattServer::write(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, const uint8_t buffer[], uint16_t len, bool localOnly)
ble_error_t nRF5xGattServer::write_(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, const uint8_t buffer[], uint16_t len, bool localOnly)
{
ble_error_t returnValue = BLE_ERROR_NONE;
@ -330,14 +330,14 @@ ble_error_t nRF5xGattServer::write(Gap::Handle_t connectionHandle, GattAttribute
return returnValue;
}
ble_error_t nRF5xGattServer::areUpdatesEnabled(const GattCharacteristic &characteristic, bool *enabledP)
ble_error_t nRF5xGattServer::areUpdatesEnabled_(const GattCharacteristic &characteristic, bool *enabledP)
{
/* Forward the call with the default connection handle. */
nRF5xGap &gap = (nRF5xGap &) nRF5xn::Instance(BLE::DEFAULT_INSTANCE).getGap();
return areUpdatesEnabled(gap.getConnectionHandle(), characteristic, enabledP);
return areUpdatesEnabled_(gap.getConnectionHandle(), characteristic, enabledP);
}
ble_error_t nRF5xGattServer::areUpdatesEnabled(Gap::Handle_t connectionHandle, const GattCharacteristic &characteristic, bool *enabledP)
ble_error_t nRF5xGattServer::areUpdatesEnabled_(Gap::Handle_t connectionHandle, const GattCharacteristic &characteristic, bool *enabledP)
{
return areUpdatesEnabled(connectionHandle, characteristic.getValueHandle(), enabledP);
}
@ -379,10 +379,10 @@ ble_error_t nRF5xGattServer::areUpdatesEnabled(Gap::Handle_t connectionHandle, G
Everything executed properly
*/
/**************************************************************************/
ble_error_t nRF5xGattServer::reset(void)
ble_error_t nRF5xGattServer::reset_(void)
{
/* Clear all state that is from the parent, including private members */
if (GattServer::reset() != BLE_ERROR_NONE) {
if (ble::interface::GattServer<nRF5xGattServer>::reset() != BLE_ERROR_NONE) {
return BLE_ERROR_INVALID_STATE;
}

View File

@ -24,18 +24,18 @@
#include "ble/Gap.h"
#include "ble/GattServer.h"
class nRF5xGattServer : public GattServer
class nRF5xGattServer : public ble::interface::GattServer<nRF5xGattServer>
{
public:
/* Functions that must be implemented from GattServer */
virtual ble_error_t addService(GattService &);
virtual ble_error_t read(GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP);
virtual ble_error_t read(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP);
virtual ble_error_t write(GattAttribute::Handle_t, const uint8_t[], uint16_t, bool localOnly = false);
virtual ble_error_t write(Gap::Handle_t connectionHandle, GattAttribute::Handle_t, const uint8_t[], uint16_t, bool localOnly = false);
virtual ble_error_t areUpdatesEnabled(const GattCharacteristic &characteristic, bool *enabledP);
virtual ble_error_t areUpdatesEnabled(Gap::Handle_t connectionHandle, const GattCharacteristic &characteristic, bool *enabledP);
virtual ble_error_t reset(void);
ble_error_t addService_(GattService &);
ble_error_t read_(GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP);
ble_error_t read_(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP);
ble_error_t write_(GattAttribute::Handle_t, const uint8_t[], uint16_t, bool localOnly = false);
ble_error_t write_(Gap::Handle_t connectionHandle, GattAttribute::Handle_t, const uint8_t[], uint16_t, bool localOnly = false);
ble_error_t areUpdatesEnabled_(const GattCharacteristic &characteristic, bool *enabledP);
ble_error_t areUpdatesEnabled_(Gap::Handle_t connectionHandle, const GattCharacteristic &characteristic, bool *enabledP);
ble_error_t reset_(void);
/* nRF51 Functions */
void eventCallback(void);

View File

@ -23,26 +23,28 @@
#include "ble/SecurityManager.h"
#include "btle_security.h"
class nRF5xSecurityManager : public SecurityManager
class nRF5xSecurityManager : public ble::interface::SecurityManager<nRF5xSecurityManager>
{
public:
/* Functions that must be implemented from SecurityManager */
virtual ble_error_t init(bool enableBonding,
bool requireMITM,
SecurityIOCapabilities_t iocaps,
const Passkey_t passkey) {
ble_error_t init_(bool enableBonding,
bool requireMITM,
SecurityIOCapabilities_t iocaps,
const Passkey_t passkey,
bool signing,
const char *dbFilepath) {
return btle_initializeSecurity(enableBonding, requireMITM, iocaps, passkey);
}
virtual ble_error_t getLinkSecurity(Gap::Handle_t connectionHandle, LinkSecurityStatus_t *securityStatusP) {
ble_error_t getLinkSecurity_(Gap::Handle_t connectionHandle, LinkSecurityStatus_t *securityStatusP) {
return btle_getLinkSecurity(connectionHandle, securityStatusP);
}
virtual ble_error_t setLinkSecurity(Gap::Handle_t connectionHandle, SecurityMode_t securityMode) {
ble_error_t setLinkSecurity_(Gap::Handle_t connectionHandle, SecurityMode_t securityMode) {
return btle_setLinkSecurity(connectionHandle, securityMode);
}
virtual ble_error_t purgeAllBondingState(void) {
ble_error_t purgeAllBondingState_(void) {
return btle_purgeAllBondingState();
}
@ -58,7 +60,7 @@ public:
* @return
* BLE_ERROR_NONE if successful.
*/
virtual ble_error_t getAddressesFromBondTable(Gap::Whitelist_t &addresses) const {
ble_error_t getAddressesFromBondTable_(Gap::Whitelist_t &addresses) const {
uint8_t i;
ble_gap_whitelist_t whitelistFromBondTable;
@ -119,9 +121,9 @@ public:
* @return
* BLE_ERROR_NONE if successful.
*/
virtual ble_error_t reset(void)
ble_error_t reset_(void)
{
if (SecurityManager::reset() != BLE_ERROR_NONE) {
if (ble::interface::SecurityManager<nRF5xSecurityManager>::reset_() != BLE_ERROR_NONE) {
return BLE_ERROR_INVALID_STATE;
}