BLE - Devirtualization of the Maxim port .

pull/9727/head
Vincent Coubard 2019-02-25 19:24:07 +00:00
parent 536443b1f8
commit 0323d91f04
8 changed files with 188 additions and 59 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 "MaximGattServer.h"
#include "ble/GattClient.h"
#include "source/GattClient.tpp"
#include "MaximGattClient.h"
#include "ble/gap/Gap.h"
#include "ble/Gap.h"
#include "source/gap/Gap.tpp"
#include "source/LegacyGap.tpp"
#include "MaximGap.h"
#include "ble/SecurityManager.h"
#include "source/SecurityManager.tpp"
#include "MaximSecurityManager.h"
template class ble::interface::GattServer<MaximGattServer>;
template class ble::interface::GattClient<MaximGattClient>;
template class ble::interface::LegacyGap<MaximGap>;
template class ble::interface::Gap<MaximGap>;
template class ble::interface::SecurityManager<MaximSecurityManager>;

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 MaximGap;
class MaximGattClient;
class MaximGattServer;
class MaximSecurityManager;
// implementation assembly
namespace ble {
namespace impl {
// SECURITY MANAGER
typedef interface::SecurityManager<MaximSecurityManager> SecurityManager;
// GAP
typedef interface::LegacyGap<MaximGap> LegacyGap;
typedef interface::Gap<MaximGap> Gap;
// GATT CLIENT
typedef interface::GattClient<MaximGattClient> GattClient;
// GATT SERVER
typedef ble::interface::GattServer<MaximGattServer> GattServer;
} // impl
} // ble
#endif //BLE_IMPLEMENTATION_FORWARD_H_

View File

@ -40,7 +40,7 @@ MaximGap &MaximGap::getInstance() {
return m_instance;
}
ble_error_t MaximGap::setAdvertisingData(const GapAdvertisingData &advData, const GapAdvertisingData &scanResponse)
ble_error_t MaximGap::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) {
@ -61,7 +61,7 @@ ble_error_t MaximGap::setAdvertisingData(const GapAdvertisingData &advData, cons
return BLE_ERROR_NONE;
}
ble_error_t MaximGap::startAdvertising(const GapAdvertisingParams &params)
ble_error_t MaximGap::startAdvertising_(const GapAdvertisingParams &params)
{
/* Make sure we support the advertising type */
if (params.getAdvertisingType() == GapAdvertisingParams::ADV_CONNECTABLE_DIRECTED) {
@ -108,7 +108,7 @@ ble_error_t MaximGap::startAdvertising(const GapAdvertisingParams &params)
return BLE_ERROR_NONE;
}
ble_error_t MaximGap::stopAdvertising(void)
ble_error_t MaximGap::stopAdvertising_(void)
{
DmAdvStop();
@ -123,11 +123,11 @@ void MaximGap::advertisingStopped(void)
* be '0.' Otherwise, advertising must have stopped due to a timeout
*/
if (state.advertising) {
processTimeoutEvent(Gap::TIMEOUT_SRC_ADVERTISING);
processTimeoutEvent(TIMEOUT_SRC_ADVERTISING);
}
}
ble_error_t MaximGap::disconnect(DisconnectionReason_t reason)
ble_error_t MaximGap::disconnect_(DisconnectionReason_t reason)
{
DmConnClose(DM_CLIENT_ID_APP, m_connectionHandle, reason);
@ -137,7 +137,7 @@ ble_error_t MaximGap::disconnect(DisconnectionReason_t reason)
return BLE_ERROR_NONE;
}
ble_error_t MaximGap::disconnect(Handle_t connectionHandle, DisconnectionReason_t reason)
ble_error_t MaximGap::disconnect_(Handle_t connectionHandle, DisconnectionReason_t reason)
{
DmConnClose(DM_CLIENT_ID_APP, connectionHandle, reason);
@ -147,17 +147,17 @@ ble_error_t MaximGap::disconnect(Handle_t connectionHandle, DisconnectionReason_
return BLE_ERROR_NONE;
}
ble_error_t MaximGap::getPreferredConnectionParams(ConnectionParams_t *params)
ble_error_t MaximGap::getPreferredConnectionParams_(ConnectionParams_t *params)
{
return BLE_ERROR_NOT_IMPLEMENTED;
}
ble_error_t MaximGap::setPreferredConnectionParams(const ConnectionParams_t *params)
ble_error_t MaximGap::setPreferredConnectionParams_(const ConnectionParams_t *params)
{
return BLE_ERROR_NOT_IMPLEMENTED;
}
ble_error_t MaximGap::updateConnectionParams(Handle_t handle, const ConnectionParams_t *newParams)
ble_error_t MaximGap::updateConnectionParams_(Handle_t handle, const ConnectionParams_t *newParams)
{
if (DmConnCheckIdle(handle) != 0) {
return BLE_STACK_BUSY;
@ -173,7 +173,7 @@ ble_error_t MaximGap::updateConnectionParams(Handle_t handle, const ConnectionPa
return BLE_ERROR_NONE;
}
ble_error_t MaximGap::startRadioScan(const GapScanningParams &scanningParams)
ble_error_t MaximGap::startRadioScan_(const GapScanningParams &scanningParams)
{
DmScanSetInterval(scanningParams.getInterval(), scanningParams.getWindow());
@ -189,7 +189,7 @@ ble_error_t MaximGap::startRadioScan(const GapScanningParams &scanningParams)
return BLE_ERROR_NONE;
}
ble_error_t MaximGap::stopScan(void)
ble_error_t MaximGap::stopScan_(void)
{
DmScanStop();
return BLE_ERROR_NONE;
@ -205,7 +205,7 @@ uint16_t MaximGap::getConnectionHandle(void)
return m_connectionHandle;
}
ble_error_t MaximGap::setAddress(AddressType_t type, const Address_t address)
ble_error_t MaximGap::setAddress_(AddressType_t type, const Address_t address)
{
if ((type != BLEProtocol::AddressType::PUBLIC) && (type != BLEProtocol::AddressType::RANDOM_STATIC)) {
return BLE_ERROR_PARAM_OUT_OF_RANGE;
@ -217,40 +217,40 @@ ble_error_t MaximGap::setAddress(AddressType_t type, const Address_t address)
return BLE_ERROR_NONE;
}
ble_error_t MaximGap::getAddress(AddressType_t *typeP, Address_t address)
ble_error_t MaximGap::getAddress_(AddressType_t *typeP, Address_t address)
{
*typeP = m_type;
BdaCpy(address, HciGetBdAddr());
return BLE_ERROR_NONE;
}
ble_error_t MaximGap::setDeviceName(const uint8_t *deviceName)
ble_error_t MaximGap::setDeviceName_(const uint8_t *deviceName)
{
return BLE_ERROR_NOT_IMPLEMENTED;
}
ble_error_t MaximGap::getDeviceName(uint8_t *deviceName, unsigned *lengthP)
ble_error_t MaximGap::getDeviceName_(uint8_t *deviceName, unsigned *lengthP)
{
return BLE_ERROR_NOT_IMPLEMENTED;
}
ble_error_t MaximGap::setAppearance(GapAdvertisingData::Appearance appearance)
ble_error_t MaximGap::setAppearance_(GapAdvertisingData::Appearance appearance)
{
return BLE_ERROR_NOT_IMPLEMENTED;
}
ble_error_t MaximGap::getAppearance(GapAdvertisingData::Appearance *appearanceP)
ble_error_t MaximGap::getAppearance_(GapAdvertisingData::Appearance *appearanceP)
{
return BLE_ERROR_NOT_IMPLEMENTED;
}
ble_error_t MaximGap::setTxPower(int8_t txPower)
ble_error_t MaximGap::setTxPower_(int8_t txPower)
{
HciVsSetTxPower(txPower);
return BLE_ERROR_NONE;
}
void MaximGap::getPermittedTxPowerValues(const int8_t **valueArrayPP, size_t *countP)
void MaximGap::getPermittedTxPowerValues_(const int8_t **valueArrayPP, size_t *countP)
{
static const int8_t permittedTxValues[] = {
-18, -15, -12, -9, -6, -3, 0, 3

View File

@ -49,49 +49,66 @@
*/
/**************************************************************************/
class MaximGap : public Gap
class MaximGap : public ble::interface::LegacyGap<MaximGap>
{
public:
static MaximGap &getInstance();
/* 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 &);
#define BLE_GAP_ADV_INTERVAL_MIN 0x0020 /**< Minimum Advertising interval in 625 us units, i.e. 20 ms. */
#define BLE_GAP_ADV_NONCON_INTERVAL_MIN 0x00A0 /**< Minimum Advertising interval in 625 us units for non connectable mode, i.e. 100 ms. */
#define BLE_GAP_ADV_INTERVAL_MAX 0x4000 /**< Maximum Advertising interval in 625 us units, i.e. 10.24 s. */
virtual uint16_t getMinAdvertisingInterval(void) const { return BLE_GAP_ADV_INTERVAL_MIN; }
virtual uint16_t getMinNonConnectableAdvertisingInterval(void) const { return BLE_GAP_ADV_NONCON_INTERVAL_MIN; }
virtual uint16_t getMaxAdvertisingInterval(void) const { return BLE_GAP_ADV_INTERVAL_MAX; }
uint16_t getMinAdvertisingInterval_(void) const { return BLE_GAP_ADV_INTERVAL_MIN; }
uint16_t getMinNonConnectableAdvertisingInterval_(void) const { return BLE_GAP_ADV_NONCON_INTERVAL_MIN; }
uint16_t getMaxAdvertisingInterval_(void) const { return BLE_GAP_ADV_INTERVAL_MAX; }
virtual ble_error_t startAdvertising(const GapAdvertisingParams &);
virtual ble_error_t stopAdvertising(void);
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 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 m_connectionHandle);
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 startRadioScan(const GapScanningParams &scanningParams);
virtual ble_error_t stopScan(void);
ble_error_t startRadioScan_(const GapScanningParams &scanningParams);
ble_error_t stopScan_(void);
void advertisingStopped(void);
protected:
// import from Gap
friend ble::interface::Gap<MaximGap>;
using ble::interface::Gap<MaximGap>::startAdvertising_;
using ble::interface::Gap<MaximGap>::stopAdvertising_;
using ble::interface::Gap<MaximGap>::connect_;
using ble::interface::Gap<MaximGap>::disconnect_;
// import from LegacyGap
friend ble::interface::LegacyGap<MaximGap>;
using ble::interface::LegacyGap<MaximGap>::startAdvertising_;
using ble::interface::LegacyGap<MaximGap>::stopAdvertising_;
using ble::interface::LegacyGap<MaximGap>::connect_;
using ble::interface::LegacyGap<MaximGap>::disconnect_;
private:
uint16_t m_connectionHandle;
addr_type_t m_type;

View File

@ -38,7 +38,7 @@
#include "ble/GattClient.h"
class MaximGattClient : public GattClient
class MaximGattClient : public ble::interface::GattClient<MaximGattClient>
{
public:
static MaximGattClient &getInstance() {

View File

@ -61,7 +61,7 @@ MaximGattServer &MaximGattServer::getInstance() {
return m_instance;
}
ble_error_t MaximGattServer::addService(GattService &service)
ble_error_t MaximGattServer::addService_(GattService &service)
{
currentHandle = (currentHandle + 0xF) & ~0xF;
uint16_t startHandle = currentHandle;
@ -242,7 +242,7 @@ ble_error_t MaximGattServer::addService(GattService &service)
return BLE_ERROR_NONE;
}
ble_error_t MaximGattServer::read(GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *const lengthP)
ble_error_t MaximGattServer::read_(GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *const lengthP)
{
if (AttsGetAttr(attributeHandle, lengthP, &buffer) != ATT_SUCCESS) {
return BLE_ERROR_PARAM_OUT_OF_RANGE;
@ -251,7 +251,7 @@ ble_error_t MaximGattServer::read(GattAttribute::Handle_t attributeHandle, uint8
return BLE_ERROR_NONE;
}
ble_error_t MaximGattServer::read(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP)
ble_error_t MaximGattServer::read_(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP)
{
// Check to see if this is a CCCD
uint8_t idx;
@ -270,7 +270,7 @@ ble_error_t MaximGattServer::read(Gap::Handle_t connectionHandle, GattAttribute:
return read(attributeHandle, buffer, lengthP);
}
ble_error_t MaximGattServer::write(GattAttribute::Handle_t attributeHandle, const uint8_t buffer[], uint16_t len, bool localOnly)
ble_error_t MaximGattServer::write_(GattAttribute::Handle_t attributeHandle, const uint8_t buffer[], uint16_t len, bool localOnly)
{
uint16_t connectionHandle = MaximGap::getInstance().getConnectionHandle();
@ -304,7 +304,7 @@ ble_error_t MaximGattServer::write(GattAttribute::Handle_t attributeHandle, cons
return BLE_ERROR_NONE;
}
ble_error_t MaximGattServer::write(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, const uint8_t buffer[], uint16_t len, bool localOnly)
ble_error_t MaximGattServer::write_(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, const uint8_t buffer[], uint16_t len, bool localOnly)
{
// Check to see if this is a CCCD
uint8_t idx;
@ -322,7 +322,7 @@ ble_error_t MaximGattServer::write(Gap::Handle_t connectionHandle, GattAttribute
return write(attributeHandle, buffer, len, localOnly);
}
ble_error_t MaximGattServer::areUpdatesEnabled(const GattCharacteristic &characteristic, bool *enabledP)
ble_error_t MaximGattServer::areUpdatesEnabled_(const GattCharacteristic &characteristic, bool *enabledP)
{
uint16_t connectionHandle = MaximGap::getInstance().getConnectionHandle();
@ -344,7 +344,7 @@ ble_error_t MaximGattServer::areUpdatesEnabled(const GattCharacteristic &charact
return BLE_ERROR_PARAM_OUT_OF_RANGE;
}
ble_error_t MaximGattServer::areUpdatesEnabled(Gap::Handle_t connectionHandle, const GattCharacteristic &characteristic, bool *enabledP)
ble_error_t MaximGattServer::areUpdatesEnabled_(Gap::Handle_t connectionHandle, const GattCharacteristic &characteristic, bool *enabledP)
{
if (connectionHandle != DM_CONN_ID_NONE) {
uint8_t idx;

View File

@ -41,23 +41,23 @@
#include "wsf_types.h"
#include "att_api.h"
class MaximGattServer : public GattServer
class MaximGattServer : public ble::interface::GattServer<MaximGattServer>
{
public:
static MaximGattServer &getInstance();
/* Functions that must be implemented from GattServer */
virtual ble_error_t addService(GattService &);
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);
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);
virtual ble_error_t areUpdatesEnabled(const GattCharacteristic &characteristic, bool *enabledP);
virtual ble_error_t areUpdatesEnabled(Gap::Handle_t connectionHandle, const GattCharacteristic &characteristic, bool *enabledP);
ble_error_t areUpdatesEnabled_(const GattCharacteristic &characteristic, bool *enabledP);
ble_error_t areUpdatesEnabled_(Gap::Handle_t connectionHandle, const GattCharacteristic &characteristic, bool *enabledP);
virtual bool isOnDataReadAvailable() const { return true; }
bool isOnDataReadAvailable_() const { return true; }
private:
static void cccCback(attsCccEvt_t *pEvt);

View File

@ -38,7 +38,7 @@
#include "ble/SecurityManager.h"
class MaximSecurityManager : public SecurityManager
class MaximSecurityManager : public ble::interface::SecurityManager<MaximSecurityManager>
{
public:
static MaximSecurityManager &getInstance() {