BLE - Devirtualization of the Cordio port.

pull/9727/head
Vincent Coubard 2019-02-25 19:23:42 +00:00
parent 04d26f7ab5
commit 536443b1f8
13 changed files with 760 additions and 298 deletions

View File

@ -0,0 +1,165 @@
/* 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 MBED_OS_EXAMPLE_BLINKY_BLEIMPLEMENTATIONFORWARD_H
#define MBED_OS_EXAMPLE_BLINKY_BLEIMPLEMENTATIONFORWARD_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
namespace generic {
template<
template<class> class TGapImpl,
class PalSecurityManager,
class ConnectionEventMonitorEventHandler
>
class GenericGap;
template <
template<class> class TPalSecurityManager,
template<class> class SigningMonitor
>
class GenericSecurityManager;
template<template<class> class TPalGattClient, class SigningMonitorEventHandler>
class GenericGattClient;
} // namespace generic
namespace pal {
template<class Impl, class EventHandler>
class SecurityManager;
template<class AttClient, class EventHandler>
class AttClientToGattClientAdapter;
namespace vendor {
namespace cordio {
template <class EventHandler>
class CordioSecurityManager;
template<class EventHandler>
class Gap;
template<class EventHandler>
class CordioGattClient;
} // cordio
} // vendor
} // pal
namespace vendor {
namespace cordio {
template<class EventHandler>
class SigningEventMonitor;
class GattServer;
} // cordio
} // vendor
} // ble
// implementation assembly
namespace ble {
namespace impl {
// SECURITY MANAGER
typedef generic::GenericSecurityManager<
pal::vendor::cordio::CordioSecurityManager,
vendor::cordio::SigningEventMonitor
> GenericSecurityManagerImpl;
typedef interface::SecurityManager<GenericSecurityManagerImpl> SecurityManager;
typedef GenericSecurityManagerImpl SigningEventHandler;
typedef pal::vendor::cordio::CordioSecurityManager<
GenericSecurityManagerImpl
> PalSecurityManagerImpl;
typedef ::ble::pal::SecurityManager<
PalSecurityManagerImpl,
GenericSecurityManagerImpl
> PalSecurityManager;
// GAP
typedef generic::GenericGap<
pal::vendor::cordio::Gap,
PalSecurityManager,
GenericSecurityManagerImpl
> GenericGapImpl;
typedef pal::vendor::cordio::Gap<impl::GenericGapImpl> PalGapImpl;
typedef interface::LegacyGap<GenericGapImpl> LegacyGap;
typedef interface::Gap<GenericGapImpl> Gap;
// GATT CLIENT
using pal::AttClientToGattClientAdapter;
using pal::vendor::cordio::CordioGattClient;
using generic::GenericGattClient;
// construct the pal::GattClient
typedef GenericGattClient<
CordioGattClient,
SigningEventHandler
> GenericGattClientImpl;
typedef CordioGattClient<GenericGattClientImpl> PalGattClientImpl;
// construct the final GattClient type
typedef interface::GattClient<
GenericGattClientImpl
> GattClient;
// GATT SERVER
typedef ble::vendor::cordio::GattServer GattServerImpl;
typedef ble::interface::GattServer<
GattServerImpl
> GattServer;
} // impl
} // ble
#endif //MBED_OS_EXAMPLE_BLINKY_BLEIMPLEMENTATIONFORWARD_H

View File

@ -32,6 +32,9 @@
#include "ble/generic/GenericSecurityManager.h" #include "ble/generic/GenericSecurityManager.h"
#include "SimpleEventQueue.h" #include "SimpleEventQueue.h"
#include "Timer.h" #include "Timer.h"
#include "SigningMonitorProxy.h"
#include "CordioPalSecurityManager.h"
#include "BleImplementationForward.h"
namespace ble { namespace ble {
namespace vendor { namespace vendor {
@ -85,12 +88,12 @@ public:
/** /**
* @see BLEInstanceBase::getGap * @see BLEInstanceBase::getGap
*/ */
virtual generic::GenericGap& getGap(); virtual impl::GenericGapImpl& getGap();
/** /**
* @see BLEInstanceBase::getGap * @see BLEInstanceBase::getGap
*/ */
virtual const generic::GenericGap& getGap() const; virtual const impl::GenericGapImpl& getGap() const;
/** /**
* @see BLEInstanceBase::getGattServer * @see BLEInstanceBase::getGattServer
@ -105,14 +108,14 @@ public:
/** /**
* @see BLEInstanceBase::getGattClient * @see BLEInstanceBase::getGattClient
*/ */
virtual generic::GenericGattClient &getGattClient(); virtual impl::GenericGattClientImpl &getGattClient();
/** /**
* Get the PAL Gatt Client. * Get the PAL Gatt Client.
* *
* @return PAL Gatt Client. * @return PAL Gatt Client.
*/ */
pal::AttClientToGattClientAdapter &getPalGattClient(); impl::PalGattClientImpl &getPalGattClient();
/** /**
* @see BLEInstanceBase::getSecurityManager * @see BLEInstanceBase::getSecurityManager
@ -139,7 +142,7 @@ private:
* Return singleton. * Return singleton.
* @return GenericGap instance. * @return GenericGap instance.
*/ */
const generic::GenericGap& getGenericGap() const; const impl::GenericGapImpl& getGenericGap() const;
static void stack_handler(wsfEventMask_t event, wsfMsgHdr_t* msg); static void stack_handler(wsfEventMask_t event, wsfMsgHdr_t* msg);
static void device_manager_cb(dmEvt_t* dm_event); static void device_manager_cb(dmEvt_t* dm_event);
@ -163,17 +166,6 @@ private:
mutable SimpleEventQueue _event_queue; mutable SimpleEventQueue _event_queue;
mbed::Timer _timer; mbed::Timer _timer;
uint64_t _last_update_us; uint64_t _last_update_us;
class SigningEventMonitorProxy : public pal::SigningEventMonitor {
public:
SigningEventMonitorProxy(BLE &ble) : _ble(ble) { }
virtual void set_signing_event_handler(pal::SigningEventMonitor::EventHandler *handler) {
_ble.getGattClient().set_signing_event_handler(handler);
_ble.getGattServer().set_signing_event_handler(handler);
}
private:
BLE &_ble;
};
}; };
} // namespace cordio } // namespace cordio

View File

@ -24,6 +24,7 @@
#include "ble/Gap.h" #include "ble/Gap.h"
#include "wsf_types.h" #include "wsf_types.h"
#include "att_api.h" #include "att_api.h"
#include "SecurityManager.h"
/*! Maximum count of characteristics that can be stored for authorisation purposes */ /*! Maximum count of characteristics that can be stored for authorisation purposes */
#define MAX_CHARACTERISTIC_AUTHORIZATION_CNT 20 #define MAX_CHARACTERISTIC_AUTHORIZATION_CNT 20
@ -50,12 +51,14 @@ class BLE;
/** /**
* Cordio implementation of ::GattServer * Cordio implementation of ::GattServer
*/ */
class GattServer : public ::GattServer, class GattServer : public ::ble::interface::GattServer<GattServer>,
public pal::SigningEventMonitor public pal::SigningEventMonitor<GattServer, impl::SigningEventHandler>
{ {
friend ble::vendor::cordio::BLE; friend ble::vendor::cordio::BLE;
friend ble::pal::vendor::cordio::CordioAttClient; friend ble::pal::vendor::cordio::CordioAttClient;
typedef ::ble::interface::GattServer<GattServer> Base;
public: public:
/** /**
* Return the singleton of the Cordio implementation of ::GattServer. * Return the singleton of the Cordio implementation of ::GattServer.
@ -75,12 +78,12 @@ public:
/** /**
* @see ::GattServer::addService * @see ::GattServer::addService
*/ */
virtual ble_error_t addService(GattService &); ble_error_t addService_(GattService &);
/** /**
* @see ::GattServer::read * @see ::GattServer::read
*/ */
virtual ble_error_t read( ble_error_t read_(
GattAttribute::Handle_t attributeHandle, GattAttribute::Handle_t attributeHandle,
uint8_t buffer[], uint8_t buffer[],
uint16_t *lengthP uint16_t *lengthP
@ -89,7 +92,7 @@ public:
/** /**
* @see ::GattServer::read * @see ::GattServer::read
*/ */
virtual ble_error_t read( ble_error_t read_(
connection_handle_t connectionHandle, connection_handle_t connectionHandle,
GattAttribute::Handle_t attributeHandle, GattAttribute::Handle_t attributeHandle,
uint8_t buffer[], uint16_t *lengthP uint8_t buffer[], uint16_t *lengthP
@ -98,7 +101,7 @@ public:
/** /**
* @see ::GattServer::write * @see ::GattServer::write
*/ */
virtual ble_error_t write( ble_error_t write_(
GattAttribute::Handle_t, GattAttribute::Handle_t,
const uint8_t[], uint16_t, const uint8_t[], uint16_t,
bool localOnly = false bool localOnly = false
@ -107,7 +110,7 @@ public:
/** /**
* @see ::GattServer::write * @see ::GattServer::write
*/ */
virtual ble_error_t write( ble_error_t write_(
connection_handle_t connectionHandle, connection_handle_t connectionHandle,
GattAttribute::Handle_t, GattAttribute::Handle_t,
const uint8_t[], const uint8_t[],
@ -118,14 +121,14 @@ public:
/** /**
* @see ::GattServer::areUpdatesEnabled * @see ::GattServer::areUpdatesEnabled
*/ */
virtual ble_error_t areUpdatesEnabled( ble_error_t areUpdatesEnabled_(
const GattCharacteristic &characteristic, bool *enabledP const GattCharacteristic &characteristic, bool *enabledP
); );
/** /**
* @see ::GattServer::areUpdatesEnabled * @see ::GattServer::areUpdatesEnabled
*/ */
virtual ble_error_t areUpdatesEnabled( ble_error_t areUpdatesEnabled_(
connection_handle_t connectionHandle, connection_handle_t connectionHandle,
const GattCharacteristic &characteristic, const GattCharacteristic &characteristic,
bool *enabledP bool *enabledP
@ -134,52 +137,53 @@ public:
/** /**
* @see ::GattServer::isOnDataReadAvailable * @see ::GattServer::isOnDataReadAvailable
*/ */
virtual bool isOnDataReadAvailable() const; bool isOnDataReadAvailable_() const;
/** /**
* @see ::GattServer::getPreferredConnectionParams * @see ::GattServer::getPreferredConnectionParams
*/ */
virtual ::Gap::ConnectionParams_t getPreferredConnectionParams(); ::Gap::ConnectionParams_t getPreferredConnectionParams();
/** /**
* @see ::GattServer::setPreferredConnectionParams * @see ::GattServer::setPreferredConnectionParams
*/ */
virtual void setPreferredConnectionParams(const ::Gap::ConnectionParams_t& params); void setPreferredConnectionParams(const ::Gap::ConnectionParams_t& params);
/** /**
* @see ::GattServer::setDeviceName * @see ::GattServer::setDeviceName
*/ */
virtual ble_error_t setDeviceName(const uint8_t *deviceName); ble_error_t setDeviceName(const uint8_t *deviceName);
/** /**
* @see ::GattServer::getDeviceName * @see ::GattServer::getDeviceName
*/ */
virtual void getDeviceName(const uint8_t*& name, uint16_t& length); void getDeviceName(const uint8_t*& name, uint16_t& length);
/** /**
* @see ::GattServer::setAppearance * @see ::GattServer::setAppearance
*/ */
virtual void setAppearance(GapAdvertisingData::Appearance appearance); void setAppearance(GapAdvertisingData::Appearance appearance);
/** /**
* @see ::GattServer::getAppearance * @see ::GattServer::getAppearance
*/ */
virtual GapAdvertisingData::Appearance getAppearance(); GapAdvertisingData::Appearance getAppearance();
/** /**
* @see ::GattServer::reset * @see ::GattServer::reset
*/ */
virtual ble_error_t reset(void); ble_error_t reset_(void);
/** /**
* @see pal::SigningEventMonitor::set_signing_event_handler * @see pal::SigningEventMonitor::set_signing_event_handler
*/ */
virtual void set_signing_event_handler( void set_signing_event_handler_(
pal::SigningEventMonitor::EventHandler *signing_event_handler impl::SigningEventHandler *signing_event_handler
) { ) {
_signing_event_handler = signing_event_handler; _signing_event_handler = signing_event_handler;
} }
private: private:
static uint16_t compute_attributes_count(GattService& service); static uint16_t compute_attributes_count(GattService& service);
@ -240,7 +244,7 @@ private:
internal_service_t *next; internal_service_t *next;
}; };
pal::SigningEventMonitor::EventHandler *_signing_event_handler; impl::SigningEventHandler *_signing_event_handler;
attsCccSet_t cccds[MAX_CCCD_CNT]; attsCccSet_t cccds[MAX_CCCD_CNT];
uint16_t cccd_values[MAX_CCCD_CNT]; uint16_t cccd_values[MAX_CCCD_CNT];

View File

@ -19,6 +19,7 @@
#include "CordioGattServer.h" #include "CordioGattServer.h"
#include "ble/pal/AttClient.h" #include "ble/pal/AttClient.h"
#include "ble/pal/AttClientToGattClientAdapter.h"
#include "ble/pal/SimpleAttServerMessage.h" #include "ble/pal/SimpleAttServerMessage.h"
#include "att_api.h" #include "att_api.h"
#include "att_defs.h" #include "att_defs.h"
@ -32,17 +33,17 @@ namespace pal {
namespace vendor { namespace vendor {
namespace cordio { namespace cordio {
class CordioAttClient : public ::ble::pal::AttClient { class CordioAttClient : public ::ble::pal::AttClient<CordioAttClient> {
public: public:
CordioAttClient() : ::ble::pal::AttClient(), _local_sign_counter(0) { } CordioAttClient() : ::ble::pal::AttClient<CordioAttClient>(), _local_sign_counter(0) { }
virtual ~CordioAttClient() { } ~CordioAttClient() { }
/** /**
* @see ble::pal::AttClient::exchange_mtu_request * @see ble::pal::AttClient::exchange_mtu_request
*/ */
virtual ble_error_t exchange_mtu_request(connection_handle_t connection) ble_error_t exchange_mtu_request_(connection_handle_t connection)
{ {
AttcMtuReq(connection, pAttCfg->mtu); AttcMtuReq(connection, pAttCfg->mtu);
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
@ -51,7 +52,7 @@ public:
/** /**
* @see ble::pal::GattClient::get_mtu_size * @see ble::pal::GattClient::get_mtu_size
*/ */
virtual ble_error_t get_mtu_size( ble_error_t get_mtu_size_(
connection_handle_t connection_handle, connection_handle_t connection_handle,
uint16_t& mtu_size uint16_t& mtu_size
) { ) {
@ -62,7 +63,7 @@ public:
/** /**
* @see ble::pal::AttClient::find_information_request * @see ble::pal::AttClient::find_information_request
*/ */
virtual ble_error_t find_information_request( ble_error_t find_information_request_(
connection_handle_t connection_handle, connection_handle_t connection_handle,
attribute_handle_range_t discovery_range attribute_handle_range_t discovery_range
) { ) {
@ -78,7 +79,7 @@ public:
/** /**
* @see ble::pal::AttClient::find_by_type_value_request * @see ble::pal::AttClient::find_by_type_value_request
*/ */
virtual ble_error_t find_by_type_value_request( ble_error_t find_by_type_value_request_(
connection_handle_t connection_handle, connection_handle_t connection_handle,
attribute_handle_range_t discovery_range, attribute_handle_range_t discovery_range,
uint16_t type, uint16_t type,
@ -99,7 +100,7 @@ public:
/** /**
* @see ble::pal::AttClient::read_by_type_request * @see ble::pal::AttClient::read_by_type_request
*/ */
virtual ble_error_t read_by_type_request( ble_error_t read_by_type_request_(
connection_handle_t connection_handle, connection_handle_t connection_handle,
attribute_handle_range_t read_range, attribute_handle_range_t read_range,
const UUID& type const UUID& type
@ -118,7 +119,7 @@ public:
/** /**
* @see ble::pal::AttClient::read_request * @see ble::pal::AttClient::read_request
*/ */
virtual ble_error_t read_request( ble_error_t read_request_(
connection_handle_t connection_handle, connection_handle_t connection_handle,
attribute_handle_t attribute_handle attribute_handle_t attribute_handle
) { ) {
@ -129,7 +130,7 @@ public:
/** /**
* @see ble::pal::AttClient::read_blob_request * @see ble::pal::AttClient::read_blob_request
*/ */
virtual ble_error_t read_blob_request( ble_error_t read_blob_request_(
connection_handle_t connection_handle, connection_handle_t connection_handle,
attribute_handle_t attribute_handle, attribute_handle_t attribute_handle,
uint16_t offset uint16_t offset
@ -146,7 +147,7 @@ public:
/** /**
* @see ble::pal::AttClient::read_multiple_request * @see ble::pal::AttClient::read_multiple_request
*/ */
virtual ble_error_t read_multiple_request( ble_error_t read_multiple_request_(
connection_handle_t connection_handle, connection_handle_t connection_handle,
const ArrayView<const attribute_handle_t>& attribute_handles const ArrayView<const attribute_handle_t>& attribute_handles
) { ) {
@ -161,7 +162,7 @@ public:
/** /**
* @see ble::pal::AttClient::read_by_group_type_request * @see ble::pal::AttClient::read_by_group_type_request
*/ */
virtual ble_error_t read_by_group_type_request( ble_error_t read_by_group_type_request_(
connection_handle_t connection_handle, connection_handle_t connection_handle,
attribute_handle_range_t read_range, attribute_handle_range_t read_range,
const UUID& group_type const UUID& group_type
@ -180,7 +181,7 @@ public:
/** /**
* @see ble::pal::AttClient::write_request * @see ble::pal::AttClient::write_request
*/ */
virtual ble_error_t write_request( ble_error_t write_request_(
connection_handle_t connection_handle, connection_handle_t connection_handle,
attribute_handle_t attribute_handle, attribute_handle_t attribute_handle,
const ArrayView<const uint8_t>& value const ArrayView<const uint8_t>& value
@ -197,7 +198,7 @@ public:
/** /**
* @see ble::pal::AttClient::write_command * @see ble::pal::AttClient::write_command
*/ */
virtual ble_error_t write_command( ble_error_t write_command_(
connection_handle_t connection_handle, connection_handle_t connection_handle,
attribute_handle_t attribute_handle, attribute_handle_t attribute_handle,
const ArrayView<const uint8_t>& value const ArrayView<const uint8_t>& value
@ -214,7 +215,7 @@ public:
/** /**
* @see ble::pal::AttClient::signed_write_command * @see ble::pal::AttClient::signed_write_command
*/ */
virtual ble_error_t signed_write_command( ble_error_t signed_write_command_(
connection_handle_t connection_handle, connection_handle_t connection_handle,
attribute_handle_t attribute_handle, attribute_handle_t attribute_handle,
const ArrayView<const uint8_t>& value const ArrayView<const uint8_t>& value
@ -236,7 +237,7 @@ public:
* *
* @param sign_counter initialise the signing counter to this value * @param sign_counter initialise the signing counter to this value
*/ */
virtual void set_sign_counter( void set_sign_counter_(
sign_count_t sign_counter sign_count_t sign_counter
) { ) {
_local_sign_counter = sign_counter; _local_sign_counter = sign_counter;
@ -245,7 +246,7 @@ public:
/** /**
* @see ble::pal::AttClient::prepare_write_request * @see ble::pal::AttClient::prepare_write_request
*/ */
virtual ble_error_t prepare_write_request( ble_error_t prepare_write_request_(
connection_handle_t connection_handle, connection_handle_t connection_handle,
attribute_handle_t attribute_handle, attribute_handle_t attribute_handle,
uint16_t offset, uint16_t offset,
@ -266,7 +267,7 @@ public:
/** /**
* @see ble::pal::AttClient::execute_write_request * @see ble::pal::AttClient::execute_write_request
*/ */
virtual ble_error_t execute_write_request( ble_error_t execute_write_request_(
connection_handle_t connection_handle, connection_handle_t connection_handle,
bool execute bool execute
) { ) {
@ -280,7 +281,7 @@ public:
/** /**
* @see ble::pal::AttClient::initialize * @see ble::pal::AttClient::initialize
*/ */
virtual ble_error_t initialize() ble_error_t initialize_()
{ {
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
@ -288,7 +289,7 @@ public:
/** /**
* @see ble::pal::AttClient::terminate * @see ble::pal::AttClient::terminate
*/ */
virtual ble_error_t terminate() ble_error_t terminate_()
{ {
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
@ -582,6 +583,15 @@ private:
sign_count_t _local_sign_counter; sign_count_t _local_sign_counter;
}; };
template<class EH>
struct CordioGattClient : pal::AttClientToGattClientAdapter<CordioAttClient, EH> {
CordioGattClient(CordioAttClient& att_client) :
pal::AttClientToGattClientAdapter<CordioAttClient, EH>(att_client)
{ }
typedef EH EventHandler;
};
} // cordio } // cordio
} // vendor } // vendor
} // pal } // pal

View File

@ -12,23 +12,27 @@ namespace cordio {
/** /**
* Implementation of ble::pal::Gap for the Cordio stack. * Implementation of ble::pal::Gap for the Cordio stack.
*/ */
class Gap : public ::ble::pal::Gap { template<class EH>
class Gap : public ::ble::pal::Gap<Gap<EH>, EH> {
typedef ::ble::pal::Gap<Gap<EH>, EH> Base;
public: public:
virtual bool is_feature_supported( typedef EH EventHandler;
bool is_feature_supported_(
ble::controller_supported_features_t feature ble::controller_supported_features_t feature
); );
virtual ble_error_t initialize(); ble_error_t initialize_();
virtual ble_error_t terminate(); ble_error_t terminate_();
virtual address_t get_device_address(); address_t get_device_address_();
virtual address_t get_random_address(); address_t get_random_address_();
virtual ble_error_t set_random_address(const address_t& address); ble_error_t set_random_address_(const address_t& address);
virtual ble_error_t set_advertising_parameters( ble_error_t set_advertising_parameters_(
uint16_t advertising_interval_min, uint16_t advertising_interval_min,
uint16_t advertising_interval_max, uint16_t advertising_interval_max,
advertising_type_t advertising_type, advertising_type_t advertising_type,
@ -39,19 +43,19 @@ public:
advertising_filter_policy_t advertising_filter_policy advertising_filter_policy_t advertising_filter_policy
); );
virtual ble_error_t set_advertising_data( ble_error_t set_advertising_data_(
uint8_t advertising_data_length, uint8_t advertising_data_length,
const advertising_data_t& advertising_data const advertising_data_t& advertising_data
); );
virtual ble_error_t set_scan_response_data( ble_error_t set_scan_response_data_(
uint8_t scan_response_data_length, uint8_t scan_response_data_length,
const advertising_data_t& scan_response_data const advertising_data_t& scan_response_data
); );
virtual ble_error_t advertising_enable(bool enable); ble_error_t advertising_enable_(bool enable);
virtual ble_error_t set_scan_parameters( ble_error_t set_scan_parameters_(
bool active_scanning, bool active_scanning,
uint16_t scan_interval, uint16_t scan_interval,
uint16_t scan_window, uint16_t scan_window,
@ -59,12 +63,12 @@ public:
scanning_filter_policy_t filter_policy scanning_filter_policy_t filter_policy
); );
virtual ble_error_t scan_enable( ble_error_t scan_enable_(
bool enable, bool enable,
bool filter_duplicates bool filter_duplicates
); );
virtual ble_error_t create_connection( ble_error_t create_connection_(
uint16_t scan_interval, uint16_t scan_interval,
uint16_t scan_window, uint16_t scan_window,
initiator_policy_t initiator_policy, initiator_policy_t initiator_policy,
@ -79,23 +83,23 @@ public:
uint16_t maximum_connection_event_length uint16_t maximum_connection_event_length
); );
virtual ble_error_t cancel_connection_creation(); ble_error_t cancel_connection_creation_();
virtual uint8_t read_white_list_capacity(); uint8_t read_white_list_capacity_();
virtual ble_error_t clear_whitelist(); ble_error_t clear_whitelist_();
virtual ble_error_t add_device_to_whitelist( ble_error_t add_device_to_whitelist_(
whitelist_address_type_t address_type, whitelist_address_type_t address_type,
address_t address address_t address
); );
virtual ble_error_t remove_device_from_whitelist( ble_error_t remove_device_from_whitelist_(
whitelist_address_type_t address_type, whitelist_address_type_t address_type,
address_t address address_t address
); );
virtual ble_error_t connection_parameters_update( ble_error_t connection_parameters_update_(
connection_handle_t connection, connection_handle_t connection,
uint16_t connection_interval_min, uint16_t connection_interval_min,
uint16_t connection_interval_max, uint16_t connection_interval_max,
@ -105,7 +109,7 @@ public:
uint16_t maximum_connection_event_length uint16_t maximum_connection_event_length
); );
virtual ble_error_t accept_connection_parameter_request( ble_error_t accept_connection_parameter_request_(
connection_handle_t connection_handle, connection_handle_t connection_handle,
uint16_t interval_min, uint16_t interval_min,
uint16_t interval_max, uint16_t interval_max,
@ -115,30 +119,30 @@ public:
uint16_t maximum_connection_event_length uint16_t maximum_connection_event_length
); );
virtual ble_error_t reject_connection_parameter_request( ble_error_t reject_connection_parameter_request_(
connection_handle_t connection_handle, connection_handle_t connection_handle,
hci_error_code_t rejection_reason hci_error_code_t rejection_reason
); );
virtual ble_error_t disconnect( ble_error_t disconnect_(
connection_handle_t connection, connection_handle_t connection,
disconnection_reason_t disconnection_reason disconnection_reason_t disconnection_reason
); );
virtual bool is_privacy_supported(); bool is_privacy_supported_();
virtual ble_error_t set_address_resolution( ble_error_t set_address_resolution_(
bool enable bool enable
); );
virtual ble_error_t read_phy(connection_handle_t connection); ble_error_t read_phy_(connection_handle_t connection);
virtual ble_error_t set_preferred_phys( ble_error_t set_preferred_phys_(
const phy_set_t& tx_phys, const phy_set_t& tx_phys,
const phy_set_t& rx_phys const phy_set_t& rx_phys
); );
virtual ble_error_t set_phy( ble_error_t set_phy_(
connection_handle_t connection, connection_handle_t connection,
const phy_set_t& tx_phys, const phy_set_t& tx_phys,
const phy_set_t& rx_phys, const phy_set_t& rx_phys,
@ -153,12 +157,12 @@ public:
*/ */
static void gap_handler(const wsfMsgHdr_t* msg); static void gap_handler(const wsfMsgHdr_t* msg);
virtual ble_error_t set_advertising_set_random_address( ble_error_t set_advertising_set_random_address_(
advertising_handle_t advertising_handle, advertising_handle_t advertising_handle,
const address_t &address const address_t &address
); );
virtual ble_error_t set_extended_advertising_parameters( ble_error_t set_extended_advertising_parameters_(
advertising_handle_t advertising_handle, advertising_handle_t advertising_handle,
advertising_event_properties_t event_properties, advertising_event_properties_t event_properties,
advertising_interval_t primary_advertising_interval_min, advertising_interval_t primary_advertising_interval_min,
@ -176,14 +180,14 @@ public:
bool scan_request_notification bool scan_request_notification
); );
virtual ble_error_t set_periodic_advertising_parameters( ble_error_t set_periodic_advertising_parameters_(
advertising_handle_t advertising_handle, advertising_handle_t advertising_handle,
periodic_advertising_interval_t periodic_advertising_min, periodic_advertising_interval_t periodic_advertising_min,
periodic_advertising_interval_t periodic_advertising_max, periodic_advertising_interval_t periodic_advertising_max,
bool advertise_power bool advertise_power
); );
virtual ble_error_t set_extended_advertising_data( ble_error_t set_extended_advertising_data_(
advertising_handle_t advertising_handle, advertising_handle_t advertising_handle,
advertising_fragment_description_t operation, advertising_fragment_description_t operation,
bool minimize_fragmentation, bool minimize_fragmentation,
@ -191,14 +195,14 @@ public:
const uint8_t *advertising_data const uint8_t *advertising_data
); );
virtual ble_error_t set_periodic_advertising_data( ble_error_t set_periodic_advertising_data_(
advertising_handle_t advertising_handle, advertising_handle_t advertising_handle,
advertising_fragment_description_t fragment_description, advertising_fragment_description_t fragment_description,
uint8_t advertising_data_size, uint8_t advertising_data_size,
const uint8_t *advertising_data const uint8_t *advertising_data
); );
virtual ble_error_t set_extended_scan_response_data( ble_error_t set_extended_scan_response_data_(
advertising_handle_t advertising_handle, advertising_handle_t advertising_handle,
advertising_fragment_description_t operation, advertising_fragment_description_t operation,
bool minimize_fragmentation, bool minimize_fragmentation,
@ -206,7 +210,7 @@ public:
const uint8_t *scan_response_data const uint8_t *scan_response_data
); );
virtual ble_error_t extended_advertising_enable( ble_error_t extended_advertising_enable_(
bool enable, bool enable,
uint8_t number_of_sets, uint8_t number_of_sets,
const advertising_handle_t *handles, const advertising_handle_t *handles,
@ -214,26 +218,26 @@ public:
const uint8_t *max_extended_advertising_events const uint8_t *max_extended_advertising_events
); );
virtual ble_error_t periodic_advertising_enable( ble_error_t periodic_advertising_enable_(
bool enable, bool enable,
advertising_handle_t advertising_handle advertising_handle_t advertising_handle
); );
virtual uint16_t get_maximum_advertising_data_length(); uint16_t get_maximum_advertising_data_length_();
virtual uint16_t get_maximum_connectable_advertising_data_length(); uint16_t get_maximum_connectable_advertising_data_length_();
virtual uint8_t get_maximum_hci_advertising_data_length(); uint8_t get_maximum_hci_advertising_data_length_();
virtual uint8_t get_max_number_of_advertising_sets(); uint8_t get_max_number_of_advertising_sets_();
virtual ble_error_t remove_advertising_set( ble_error_t remove_advertising_set_(
advertising_handle_t advertising_handle advertising_handle_t advertising_handle
); );
virtual ble_error_t clear_advertising_sets(); ble_error_t clear_advertising_sets_();
virtual ble_error_t set_extended_scan_parameters( ble_error_t set_extended_scan_parameters_(
own_address_type_t own_address_type, own_address_type_t own_address_type,
scanning_filter_policy_t filter_policy, scanning_filter_policy_t filter_policy,
phy_set_t scanning_phys, phy_set_t scanning_phys,
@ -242,14 +246,14 @@ public:
const uint16_t *scan_window const uint16_t *scan_window
); );
virtual ble_error_t extended_scan_enable( ble_error_t extended_scan_enable_(
bool enable, bool enable,
duplicates_filter_t filter_duplicates, duplicates_filter_t filter_duplicates,
uint16_t duration, uint16_t duration,
uint16_t period uint16_t period
); );
virtual ble_error_t periodic_advertising_create_sync( ble_error_t periodic_advertising_create_sync_(
bool use_periodic_advertiser_list, bool use_periodic_advertiser_list,
uint8_t advertising_sid, uint8_t advertising_sid,
peer_address_type_t peer_address_type, peer_address_type_t peer_address_type,
@ -258,29 +262,29 @@ public:
uint16_t sync_timeout uint16_t sync_timeout
); );
virtual ble_error_t cancel_periodic_advertising_create_sync(); ble_error_t cancel_periodic_advertising_create_sync_();
virtual ble_error_t periodic_advertising_terminate_sync( ble_error_t periodic_advertising_terminate_sync_(
sync_handle_t sync_handle sync_handle_t sync_handle
); );
virtual ble_error_t add_device_to_periodic_advertiser_list( ble_error_t add_device_to_periodic_advertiser_list_(
advertising_peer_address_type_t advertiser_address_type, advertising_peer_address_type_t advertiser_address_type,
const address_t &advertiser_address, const address_t &advertiser_address,
uint8_t advertising_sid uint8_t advertising_sid
); );
virtual ble_error_t remove_device_from_periodic_advertiser_list( ble_error_t remove_device_from_periodic_advertiser_list_(
advertising_peer_address_type_t advertiser_address_type, advertising_peer_address_type_t advertiser_address_type,
const address_t &advertiser_address, const address_t &advertiser_address,
uint8_t advertising_sid uint8_t advertising_sid
); );
virtual ble_error_t clear_periodic_advertiser_list(); ble_error_t clear_periodic_advertiser_list_();
virtual uint8_t read_periodic_advertiser_list_size(); uint8_t read_periodic_advertiser_list_size_();
virtual ble_error_t extended_create_connection( ble_error_t extended_create_connection_(
initiator_policy_t initiator_policy, initiator_policy_t initiator_policy,
own_address_type_t own_address_type, own_address_type_t own_address_type,
peer_address_type_t peer_address_type, peer_address_type_t peer_address_type,

View File

@ -29,11 +29,14 @@ namespace pal {
namespace vendor { namespace vendor {
namespace cordio { namespace cordio {
class CordioSecurityManager : public ::ble::pal::SecurityManager { template <class EventHandler>
class CordioSecurityManager : public ::ble::pal::SecurityManager<CordioSecurityManager<EventHandler>, EventHandler> {
public: public:
typedef ::ble::pal::SecurityManager<CordioSecurityManager<EventHandler>, EventHandler> Base;
CordioSecurityManager(); CordioSecurityManager();
virtual ~CordioSecurityManager(); ~CordioSecurityManager();
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// SM lifecycle management // SM lifecycle management
@ -42,17 +45,17 @@ public:
/** /**
* @see ::ble::pal::SecurityManager::initialize * @see ::ble::pal::SecurityManager::initialize
*/ */
virtual ble_error_t initialize(); ble_error_t initialize_();
/** /**
* @see ::ble::pal::SecurityManager::terminate * @see ::ble::pal::SecurityManager::terminate
*/ */
virtual ble_error_t terminate(); ble_error_t terminate_();
/** /**
* @see ::ble::pal::SecurityManager::reset * @see ::ble::pal::SecurityManager::reset
*/ */
virtual ble_error_t reset() ; ble_error_t reset_();
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Resolving list management // Resolving list management
@ -61,12 +64,12 @@ public:
/** /**
* @see ::ble::pal::SecurityManager::read_resolving_list_capacity * @see ::ble::pal::SecurityManager::read_resolving_list_capacity
*/ */
virtual uint8_t read_resolving_list_capacity(); uint8_t read_resolving_list_capacity_();
/** /**
* @see ::ble::pal::SecurityManager::add_device_to_resolving_list * @see ::ble::pal::SecurityManager::add_device_to_resolving_list
*/ */
virtual ble_error_t add_device_to_resolving_list( ble_error_t add_device_to_resolving_list_(
advertising_peer_address_type_t peer_identity_address_type, advertising_peer_address_type_t peer_identity_address_type,
const address_t &peer_identity_address, const address_t &peer_identity_address,
const irk_t &peer_irk const irk_t &peer_irk
@ -75,7 +78,7 @@ public:
/** /**
* @see ::ble::pal::SecurityManager::remove_device_from_resolving_list * @see ::ble::pal::SecurityManager::remove_device_from_resolving_list
*/ */
virtual ble_error_t remove_device_from_resolving_list( ble_error_t remove_device_from_resolving_list_(
advertising_peer_address_type_t peer_identity_address_type, advertising_peer_address_type_t peer_identity_address_type,
const address_t &peer_identity_address const address_t &peer_identity_address
); );
@ -83,7 +86,7 @@ public:
/** /**
* @see ::ble::pal::SecurityManager::clear_resolving_list * @see ::ble::pal::SecurityManager::clear_resolving_list
*/ */
virtual ble_error_t clear_resolving_list(); ble_error_t clear_resolving_list_();
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Pairing // Pairing
@ -92,7 +95,7 @@ public:
/** /**
* @see ::ble::pal::SecurityManager::send_pairing_request * @see ::ble::pal::SecurityManager::send_pairing_request
*/ */
virtual ble_error_t send_pairing_request( ble_error_t send_pairing_request_(
connection_handle_t connection, connection_handle_t connection,
bool oob_data_flag, bool oob_data_flag,
AuthenticationMask authentication_requirements, AuthenticationMask authentication_requirements,
@ -103,7 +106,7 @@ public:
/** /**
* @see ::ble::pal::SecurityManager::send_pairing_response * @see ::ble::pal::SecurityManager::send_pairing_response
*/ */
virtual ble_error_t send_pairing_response( ble_error_t send_pairing_response_(
connection_handle_t connection, connection_handle_t connection,
bool oob_data_flag, bool oob_data_flag,
AuthenticationMask authentication_requirements, AuthenticationMask authentication_requirements,
@ -114,7 +117,7 @@ public:
/** /**
* @see ::ble::pal::SecurityManager::cancel_pairing * @see ::ble::pal::SecurityManager::cancel_pairing
*/ */
virtual ble_error_t cancel_pairing( ble_error_t cancel_pairing_(
connection_handle_t connection, pairing_failure_t reason connection_handle_t connection, pairing_failure_t reason
); );
@ -125,14 +128,14 @@ public:
/** /**
* @see ::ble::pal::SecurityManager::get_secure_connections_support * @see ::ble::pal::SecurityManager::get_secure_connections_support
*/ */
virtual ble_error_t get_secure_connections_support( ble_error_t get_secure_connections_support_(
bool &enabled bool &enabled
); );
/** /**
* @see ::ble::pal::SecurityManager::set_io_capability * @see ::ble::pal::SecurityManager::set_io_capability
*/ */
virtual ble_error_t set_io_capability(io_capability_t io_capability); ble_error_t set_io_capability_(io_capability_t io_capability);
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Security settings // Security settings
@ -141,21 +144,21 @@ public:
/** /**
* @see ::ble::pal::SecurityManager::set_authentication_timeout * @see ::ble::pal::SecurityManager::set_authentication_timeout
*/ */
virtual ble_error_t set_authentication_timeout( ble_error_t set_authentication_timeout_(
connection_handle_t, uint16_t timeout_in_10ms connection_handle_t, uint16_t timeout_in_10ms
); );
/** /**
* @see ::ble::pal::SecurityManager::get_authentication_timeout * @see ::ble::pal::SecurityManager::get_authentication_timeout
*/ */
virtual ble_error_t get_authentication_timeout( ble_error_t get_authentication_timeout_(
connection_handle_t, uint16_t &timeout_in_10ms connection_handle_t, uint16_t &timeout_in_10ms
); );
/** /**
* @see ::ble::pal::SecurityManager::set_encryption_key_requirements * @see ::ble::pal::SecurityManager::set_encryption_key_requirements
*/ */
virtual ble_error_t set_encryption_key_requirements( ble_error_t set_encryption_key_requirements_(
uint8_t min_encryption_key_size, uint8_t min_encryption_key_size,
uint8_t max_encryption_key_size uint8_t max_encryption_key_size
); );
@ -163,7 +166,7 @@ public:
/** /**
* @see ::ble::pal::SecurityManager::slave_security_request * @see ::ble::pal::SecurityManager::slave_security_request
*/ */
virtual ble_error_t slave_security_request( ble_error_t slave_security_request_(
connection_handle_t connection, connection_handle_t connection,
AuthenticationMask authentication AuthenticationMask authentication
); );
@ -175,7 +178,7 @@ public:
/** /**
* @see ::ble::pal::SecurityManager::enable_encryption * @see ::ble::pal::SecurityManager::enable_encryption
*/ */
virtual ble_error_t enable_encryption( ble_error_t enable_encryption_(
connection_handle_t connection, connection_handle_t connection,
const ltk_t &ltk, const ltk_t &ltk,
const rand_t &rand, const rand_t &rand,
@ -186,7 +189,7 @@ public:
/** /**
* @see ::ble::pal::SecurityManager::enable_encryption * @see ::ble::pal::SecurityManager::enable_encryption
*/ */
virtual ble_error_t enable_encryption( ble_error_t enable_encryption_(
connection_handle_t connection, connection_handle_t connection,
const ltk_t &ltk, const ltk_t &ltk,
bool mitm bool mitm
@ -195,7 +198,7 @@ public:
/** /**
* @see ::ble::pal::SecurityManager::encrypt_data * @see ::ble::pal::SecurityManager::encrypt_data
*/ */
virtual ble_error_t encrypt_data( ble_error_t encrypt_data_(
const byte_array_t<16> &key, const byte_array_t<16> &key,
encryption_block_t &data encryption_block_t &data
); );
@ -207,7 +210,7 @@ public:
/** /**
* @see ::ble::pal::SecurityManager::set_private_address_timeout * @see ::ble::pal::SecurityManager::set_private_address_timeout
*/ */
virtual ble_error_t set_private_address_timeout(uint16_t timeout_in_seconds); ble_error_t set_private_address_timeout_(uint16_t timeout_in_seconds);
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Keys // Keys
@ -216,7 +219,7 @@ public:
/** /**
* @see ::ble::pal::SecurityManager::set_ltk * @see ::ble::pal::SecurityManager::set_ltk
*/ */
virtual ble_error_t set_ltk( ble_error_t set_ltk_(
connection_handle_t connection, connection_handle_t connection,
const ltk_t &ltk, const ltk_t &ltk,
bool mitm, bool mitm,
@ -226,19 +229,19 @@ public:
/** /**
* @see ::ble::pal::SecurityManager::set_ltk_not_found * @see ::ble::pal::SecurityManager::set_ltk_not_found
*/ */
virtual ble_error_t set_ltk_not_found( ble_error_t set_ltk_not_found_(
connection_handle_t connection connection_handle_t connection
); );
/** /**
* @see ::ble::pal::SecurityManager::set_irk * @see ::ble::pal::SecurityManager::set_irk
*/ */
virtual ble_error_t set_irk(const irk_t &irk); ble_error_t set_irk_(const irk_t &irk);
/** /**
* @see ::ble::pal::SecurityManager::set_csrk * @see ::ble::pal::SecurityManager::set_csrk
*/ */
virtual ble_error_t set_csrk( ble_error_t set_csrk_(
const csrk_t &csrk, const csrk_t &csrk,
sign_count_t sign_counter sign_count_t sign_counter
); );
@ -246,14 +249,14 @@ public:
/** /**
* @see ::ble::pal::SecurityManager::set_peer_csrk * @see ::ble::pal::SecurityManager::set_peer_csrk
*/ */
virtual ble_error_t set_peer_csrk( ble_error_t set_peer_csrk_(
connection_handle_t connection, connection_handle_t connection,
const csrk_t &csrk, const csrk_t &csrk,
bool authenticated, bool authenticated,
sign_count_t sign_counter sign_count_t sign_counter
); );
virtual ble_error_t remove_peer_csrk(connection_handle_t connection); ble_error_t remove_peer_csrk_(connection_handle_t connection);
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Authentication // Authentication
@ -262,7 +265,7 @@ public:
/** /**
* @see ::ble::pal::SecurityManager::get_random_data * @see ::ble::pal::SecurityManager::get_random_data
*/ */
virtual ble_error_t get_random_data(byte_array_t<8> &random_data); ble_error_t get_random_data_(byte_array_t<8> &random_data);
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// MITM // MITM
@ -271,12 +274,12 @@ public:
/** /**
* @see ::ble::pal::SecurityManager::set_display_passkey * @see ::ble::pal::SecurityManager::set_display_passkey
*/ */
virtual ble_error_t set_display_passkey(passkey_num_t passkey); ble_error_t set_display_passkey_(passkey_num_t passkey);
/** /**
* @see ::ble::pal::SecurityManager::passkey_request_reply * @see ::ble::pal::SecurityManager::passkey_request_reply
*/ */
virtual ble_error_t passkey_request_reply( ble_error_t passkey_request_reply_(
connection_handle_t connection, connection_handle_t connection,
passkey_num_t passkey passkey_num_t passkey
); );
@ -284,7 +287,7 @@ public:
/** /**
* @see ::ble::pal::SecurityManager::secure_connections_oob_request_reply * @see ::ble::pal::SecurityManager::secure_connections_oob_request_reply
*/ */
virtual ble_error_t secure_connections_oob_request_reply( ble_error_t secure_connections_oob_request_reply_(
connection_handle_t connection, connection_handle_t connection,
const oob_lesc_value_t &local_random, const oob_lesc_value_t &local_random,
const oob_lesc_value_t &peer_random, const oob_lesc_value_t &peer_random,
@ -294,7 +297,7 @@ public:
/** /**
* @see ::ble::pal::SecurityManager::legacy_pairing_oob_request_reply * @see ::ble::pal::SecurityManager::legacy_pairing_oob_request_reply
*/ */
virtual ble_error_t legacy_pairing_oob_request_reply( ble_error_t legacy_pairing_oob_request_reply_(
connection_handle_t connection, connection_handle_t connection,
const oob_tk_t &oob_data const oob_tk_t &oob_data
); );
@ -302,21 +305,21 @@ public:
/** /**
* @see ::ble::pal::SecurityManager::confirmation_entered * @see ::ble::pal::SecurityManager::confirmation_entered
*/ */
virtual ble_error_t confirmation_entered( ble_error_t confirmation_entered_(
connection_handle_t connection, bool confirmation connection_handle_t connection, bool confirmation
); );
/** /**
* @see ::ble::pal::SecurityManager::send_keypress_notification * @see ::ble::pal::SecurityManager::send_keypress_notification
*/ */
virtual ble_error_t send_keypress_notification( ble_error_t send_keypress_notification_(
connection_handle_t connection, Keypress_t keypress connection_handle_t connection, Keypress_t keypress
); );
/** /**
* @see ::ble::pal::SecurityManager::generate_secure_connections_oob * @see ::ble::pal::SecurityManager::generate_secure_connections_oob
*/ */
virtual ble_error_t generate_secure_connections_oob(); ble_error_t generate_secure_connections_oob_();
// singleton of the ARM Cordio Security Manager // singleton of the ARM Cordio Security Manager
static CordioSecurityManager &get_security_manager(); static CordioSecurityManager &get_security_manager();
@ -325,6 +328,9 @@ public:
static bool sm_handler(const wsfMsgHdr_t* msg); static bool sm_handler(const wsfMsgHdr_t* msg);
private: private:
using Base::initialize;
using Base::read_resolving_list_capacity;
struct PrivacyControlBlock; struct PrivacyControlBlock;
struct PrivacyClearResListControlBlock; struct PrivacyClearResListControlBlock;
struct PrivacyAddDevToResListControlBlock; struct PrivacyAddDevToResListControlBlock;

View File

@ -0,0 +1,37 @@
/* 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 MBED_OS_EXAMPLE_BLINKY_SIGNINGMONITORPROXY_H
#define MBED_OS_EXAMPLE_BLINKY_SIGNINGMONITORPROXY_H
#include "ble/pal/SigningEventMonitor.h"
namespace ble {
namespace vendor {
namespace cordio {
template<class EventHandler>
struct SigningEventMonitor : pal::SigningEventMonitor<SigningEventMonitor<EventHandler>, EventHandler> {
void set_signing_event_handler_(EventHandler *signing_event_handler);
};
}
}
}
#endif //MBED_OS_EXAMPLE_BLINKY_SIGNINGMONITORPROXY_H

View File

@ -169,23 +169,23 @@ const char* BLE::getVersion()
return version; return version;
} }
generic::GenericGap& BLE::getGap() impl::GenericGapImpl& BLE::getGap()
{ {
static pal::vendor::cordio::GenericAccessService cordio_gap_service; static pal::vendor::cordio::GenericAccessService cordio_gap_service;
static ble::generic::GenericGap gap( static impl::GenericGapImpl gap(
_event_queue, _event_queue,
pal::vendor::cordio::Gap::get_gap(), impl::PalGapImpl::get_gap(),
cordio_gap_service, cordio_gap_service,
pal::vendor::cordio::CordioSecurityManager::get_security_manager() impl::PalSecurityManagerImpl::get_security_manager()
); );
return gap; return gap;
} }
const generic::GenericGap& BLE::getGap() const const impl::GenericGapImpl& BLE::getGap() const
{ {
BLE &self = const_cast<BLE&>(*this); BLE &self = const_cast<BLE&>(*this);
return const_cast<const generic::GenericGap&>(self.getGap()); return const_cast<const impl::GenericGapImpl&>(self.getGap());
}; };
GattServer& BLE::getGattServer() GattServer& BLE::getGattServer()
@ -198,16 +198,16 @@ const GattServer& BLE::getGattServer() const
return cordio::GattServer::getInstance(); return cordio::GattServer::getInstance();
} }
generic::GenericGattClient& BLE::getGattClient() impl::GenericGattClientImpl& BLE::getGattClient()
{ {
static generic::GenericGattClient gatt_client(&getPalGattClient()); static impl::GenericGattClientImpl gatt_client(&getPalGattClient());
return gatt_client; return gatt_client;
} }
pal::AttClientToGattClientAdapter& BLE::getPalGattClient() impl::PalGattClientImpl& BLE::getPalGattClient()
{ {
static pal::AttClientToGattClientAdapter pal_client( static impl::PalGattClientImpl pal_client(
pal::vendor::cordio::CordioAttClient::get_client() pal::vendor::cordio::CordioAttClient::get_client()
); );
@ -216,9 +216,9 @@ pal::AttClientToGattClientAdapter& BLE::getPalGattClient()
SecurityManager& BLE::getSecurityManager() SecurityManager& BLE::getSecurityManager()
{ {
static SigningEventMonitorProxy signing_event_monitor(*this); static vendor::cordio::SigningEventMonitor<impl::GenericSecurityManagerImpl> signing_event_monitor;
static generic::GenericSecurityManager m_instance( static impl::GenericSecurityManagerImpl m_instance(
pal::vendor::cordio::CordioSecurityManager::get_security_manager(), impl::PalSecurityManagerImpl::get_security_manager(),
getGap(), getGap(),
signing_event_monitor signing_event_monitor
); );
@ -260,7 +260,7 @@ void BLE::processEvents()
return; return;
} }
if (ble::pal::vendor::cordio::CordioSecurityManager::get_security_manager().sm_handler(msg)) { if (impl::PalSecurityManagerImpl::get_security_manager().sm_handler(msg)) {
return; return;
} }
@ -285,7 +285,7 @@ void BLE::processEvents()
} break; } break;
default: default:
ble::pal::vendor::cordio::Gap::gap_handler(msg); impl::PalGapImpl::gap_handler(msg);
break; break;
} }
} }
@ -294,8 +294,8 @@ void BLE::device_manager_cb(dmEvt_t* dm_event)
{ {
if (dm_event->hdr.status == HCI_SUCCESS && dm_event->hdr.event == DM_CONN_DATA_LEN_CHANGE_IND) { if (dm_event->hdr.status == HCI_SUCCESS && dm_event->hdr.event == DM_CONN_DATA_LEN_CHANGE_IND) {
// this event can only happen after a connection has been established therefore gap is present // this event can only happen after a connection has been established therefore gap is present
ble::pal::Gap::EventHandler *handler; impl::PalGapImpl::EventHandler *handler;
handler = ble::pal::vendor::cordio::Gap::get_gap().get_event_handler(); handler = impl::PalGapImpl::get_gap().get_event_handler();
if (handler) { if (handler) {
handler->on_data_length_change( handler->on_data_length_change(
dm_event->hdr.param, dm_event->hdr.param,
@ -460,6 +460,12 @@ CordioHCIDriver* BLE::_hci_driver = NULL;
FunctionPointerWithContext< ::BLE::InitializationCompleteCallbackContext*> BLE::_init_callback; FunctionPointerWithContext< ::BLE::InitializationCompleteCallbackContext*> BLE::_init_callback;
template<>
void SigningEventMonitor<impl::GenericSecurityManagerImpl>::set_signing_event_handler_(impl::GenericSecurityManagerImpl *handler) {
BLE::deviceInstance().getGattClient().set_signing_event_handler(handler);
BLE::deviceInstance().getGattServer().set_signing_event_handler(handler);
}
} // namespace cordio } // namespace cordio
} // namespace vendor } // namespace vendor
} // namespace ble } // namespace ble

View File

@ -17,10 +17,13 @@
#include <algorithm> #include <algorithm>
#include "CordioBLE.h" #include "CordioBLE.h"
#include "CordioGattServer.h" #include "CordioGattServer.h"
#include "source/GattServer.tpp"
#include "mbed.h" #include "mbed.h"
#include "wsf_types.h" #include "wsf_types.h"
#include "att_api.h" #include "att_api.h"
template class ble::interface::GattServer<ble::vendor::cordio::GattServer>;
namespace ble { namespace ble {
namespace vendor { namespace vendor {
namespace cordio { namespace cordio {
@ -69,7 +72,7 @@ void GattServer::initialize()
add_generic_attribute_service(); add_generic_attribute_service();
} }
ble_error_t GattServer::addService(GattService &service) ble_error_t GattServer::addService_(GattService &service)
{ {
// create and fill the service structure // create and fill the service structure
internal_service_t *att_service = new internal_service_t; internal_service_t *att_service = new internal_service_t;
@ -531,7 +534,7 @@ ble_error_t GattServer::insert_cccd(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t GattServer::read( ble_error_t GattServer::read_(
GattAttribute::Handle_t att_handle, GattAttribute::Handle_t att_handle,
uint8_t buffer[], uint8_t buffer[],
uint16_t * buffer_length uint16_t * buffer_length
@ -552,7 +555,7 @@ ble_error_t GattServer::read(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t GattServer::read( ble_error_t GattServer::read_(
connection_handle_t connection, connection_handle_t connection,
GattAttribute::Handle_t att_handle, GattAttribute::Handle_t att_handle,
uint8_t buffer[], uint8_t buffer[],
@ -579,7 +582,7 @@ ble_error_t GattServer::read(
return read(att_handle, buffer, buffer_length); return read(att_handle, buffer, buffer_length);
} }
ble_error_t GattServer::write( ble_error_t GattServer::write_(
GattAttribute::Handle_t att_handle, GattAttribute::Handle_t att_handle,
const uint8_t buffer[], const uint8_t buffer[],
uint16_t len, uint16_t len,
@ -643,7 +646,7 @@ ble_error_t GattServer::write(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t GattServer::write( ble_error_t GattServer::write_(
connection_handle_t connection, connection_handle_t connection,
GattAttribute::Handle_t att_handle, GattAttribute::Handle_t att_handle,
const uint8_t buffer[], const uint8_t buffer[],
@ -695,7 +698,7 @@ ble_error_t GattServer::write(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t GattServer::areUpdatesEnabled( ble_error_t GattServer::areUpdatesEnabled_(
const GattCharacteristic &characteristic, const GattCharacteristic &characteristic,
bool *enabled bool *enabled
) { ) {
@ -719,7 +722,7 @@ ble_error_t GattServer::areUpdatesEnabled(
return BLE_ERROR_PARAM_OUT_OF_RANGE; return BLE_ERROR_PARAM_OUT_OF_RANGE;
} }
ble_error_t GattServer::areUpdatesEnabled( ble_error_t GattServer::areUpdatesEnabled_(
connection_handle_t connectionHandle, connection_handle_t connectionHandle,
const GattCharacteristic &characteristic, const GattCharacteristic &characteristic,
bool *enabled bool *enabled
@ -742,7 +745,7 @@ ble_error_t GattServer::areUpdatesEnabled(
return BLE_ERROR_PARAM_OUT_OF_RANGE; return BLE_ERROR_PARAM_OUT_OF_RANGE;
} }
bool GattServer::isOnDataReadAvailable() const bool GattServer::isOnDataReadAvailable_() const
{ {
return true; return true;
} }
@ -806,9 +809,9 @@ GapAdvertisingData::Appearance GattServer::getAppearance()
return (GapAdvertisingData::Appearance) generic_access_service.appearance; return (GapAdvertisingData::Appearance) generic_access_service.appearance;
} }
ble_error_t GattServer::reset(void) ble_error_t GattServer::reset_(void)
{ {
this->::GattServer::reset(); Base::reset_();
while (registered_service) { while (registered_service) {
internal_service_t* s = registered_service; internal_service_t* s = registered_service;
@ -1271,7 +1274,6 @@ bool GattServer::is_update_authorized(
} }
GattServer::GattServer() : GattServer::GattServer() :
::GattServer(),
_signing_event_handler(NULL), _signing_event_handler(NULL),
cccds(), cccds(),
cccd_values(), cccd_values(),

View File

@ -0,0 +1,134 @@
/* 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 "ble/Gap.h"
#include "ble/GattClient.h"
#include "ble/SecurityManager.h"
#include "ble/generic/GenericGap.h"
#include "ble/generic/GenericSecurityManager.h"
#include "ble/pal/PalSecurityManager.h"
#include "ble/pal/AttClientToGattClientAdapter.h"
#include "ble/pal/PalGap.h"
#include "source/LegacyGap.tpp"
#include "source/gap/Gap.tpp"
#include "source/GattClient.tpp"
#include "source/SecurityManager.tpp"
#include "source/generic/GenericGap.tpp"
#include "source/generic/GenericGattClient.tpp"
#include "source/generic/GenericSecurityManager.tpp"
#include "CordioPalGap.h"
#include "CordioPalSecurityManager.h"
#include "SigningMonitorProxy.h"
#include "CordioPalAttClient.h"
#include "source/CordioPalSecurityManager.tpp"
#include "source/CordioPalGap.tpp"
// Generic GattClient
template class ble::generic::GenericGattClient<
ble::pal::vendor::cordio::CordioGattClient,
ble::generic::GenericSecurityManager<
ble::pal::vendor::cordio::CordioSecurityManager,
ble::vendor::cordio::SigningEventMonitor
>
>;
typedef ble::generic::GenericGattClient<
ble::pal::vendor::cordio::CordioGattClient,
ble::generic::GenericSecurityManager<
ble::pal::vendor::cordio::CordioSecurityManager,
ble::vendor::cordio::SigningEventMonitor
>
> GenericGattClientImpl;
// construct the pal::GattClient
template class ble::pal::vendor::cordio::CordioGattClient<
GenericGattClientImpl
>;
// construct the final GattClient type
template class ble::interface::GattClient<
GenericGattClientImpl
>;
// ---------------------------- SecurityManager --------------------------------
template class ble::pal::vendor::cordio::CordioSecurityManager<
ble::generic::GenericSecurityManager<
ble::pal::vendor::cordio::CordioSecurityManager,
ble::vendor::cordio::SigningEventMonitor
>
>;
template class ble::generic::GenericSecurityManager<
ble::pal::vendor::cordio::CordioSecurityManager,
ble::vendor::cordio::SigningEventMonitor
>;
template class ble::interface::SecurityManager<
ble::generic::GenericSecurityManager<
ble::pal::vendor::cordio::CordioSecurityManager,
ble::vendor::cordio::SigningEventMonitor
>
>;
// --------------------------------- Gap ---------------------------------------
typedef ble::generic::GenericSecurityManager<
ble::pal::vendor::cordio::CordioSecurityManager,
ble::vendor::cordio::SigningEventMonitor
> SecurityManagerImpl;
template class ble::pal::vendor::cordio::Gap<
ble::generic::GenericGap<
ble::pal::vendor::cordio::Gap,
SecurityManagerImpl::PalSecurityManager,
SecurityManagerImpl
>
>;
template class ble::generic::GenericGap<
ble::pal::vendor::cordio::Gap,
SecurityManagerImpl::PalSecurityManager,
SecurityManagerImpl
>;
template class ble::interface::Gap<
ble::generic::GenericGap<
ble::pal::vendor::cordio::Gap,
SecurityManagerImpl::PalSecurityManager,
SecurityManagerImpl
>
>;
template class ble::interface::LegacyGap<
ble::generic::GenericGap<
ble::pal::vendor::cordio::Gap,
SecurityManagerImpl::PalSecurityManager,
SecurityManagerImpl
>
>;

View File

@ -27,7 +27,7 @@ void CordioAttClient::att_client_handler(const attEvt_t* event)
{ {
if (event->hdr.status == ATT_SUCCESS && event->hdr.event == ATT_MTU_UPDATE_IND) { if (event->hdr.status == ATT_SUCCESS && event->hdr.event == ATT_MTU_UPDATE_IND) {
ble::vendor::cordio::BLE& ble = ble::vendor::cordio::BLE::deviceInstance(); ble::vendor::cordio::BLE& ble = ble::vendor::cordio::BLE::deviceInstance();
ble::pal::GattClient::EventHandler *handler = ble.getPalGattClient().get_event_handler(); impl::PalGattClientImpl::EventHandler *handler = ble.getPalGattClient().get_event_handler();
if (handler) { if (handler) {
handler->on_att_mtu_change(event->hdr.param, event->mtu); handler->on_att_mtu_change(event->hdr.param, event->mtu);
} }

View File

@ -23,41 +23,48 @@ namespace pal {
namespace vendor { namespace vendor {
namespace cordio { namespace cordio {
bool Gap::is_feature_supported( template<class EventHandler>
bool Gap<EventHandler>::is_feature_supported_(
ble::controller_supported_features_t feature ble::controller_supported_features_t feature
) )
{ {
return (HciGetLeSupFeat() & (1 << feature.value())); return (HciGetLeSupFeat() & (1 << feature.value()));
} }
ble_error_t Gap::initialize() template<class EventHandler>
ble_error_t Gap<EventHandler>::initialize_()
{ {
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t Gap::terminate() template<class EventHandler>
ble_error_t Gap<EventHandler>::terminate_()
{ {
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
address_t Gap::get_device_address() template<class EventHandler>
address_t Gap<EventHandler>::get_device_address_()
{ {
return address_t(HciGetBdAddr()); return address_t(HciGetBdAddr());
} }
address_t Gap::get_random_address() template<class EventHandler>
address_t Gap<EventHandler>::get_random_address_()
{ {
return device_random_address; return device_random_address;
} }
ble_error_t Gap::set_random_address(const address_t &address) template<class EventHandler>
ble_error_t Gap<EventHandler>::set_random_address_(const address_t &address)
{ {
device_random_address = address; device_random_address = address;
DmDevSetRandAddr(const_cast<uint8_t *>(address.data())); DmDevSetRandAddr(const_cast<uint8_t *>(address.data()));
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t Gap::set_advertising_parameters( template<class EventHandler>
ble_error_t Gap<EventHandler>::set_advertising_parameters_(
uint16_t advertising_interval_min, uint16_t advertising_interval_min,
uint16_t advertising_interval_max, uint16_t advertising_interval_max,
advertising_type_t advertising_type, advertising_type_t advertising_type,
@ -96,7 +103,8 @@ ble_error_t Gap::set_advertising_parameters(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t Gap::set_advertising_data( template<class EventHandler>
ble_error_t Gap<EventHandler>::set_advertising_data_(
uint8_t advertising_data_length, uint8_t advertising_data_length,
const advertising_data_t &advertising_data const advertising_data_t &advertising_data
) )
@ -111,7 +119,8 @@ ble_error_t Gap::set_advertising_data(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t Gap::set_scan_response_data( template<class EventHandler>
ble_error_t Gap<EventHandler>::set_scan_response_data_(
uint8_t scan_response_data_length, uint8_t scan_response_data_length,
const advertising_data_t &scan_response_data const advertising_data_t &scan_response_data
) )
@ -126,7 +135,8 @@ ble_error_t Gap::set_scan_response_data(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t Gap::advertising_enable(bool enable) template<class EventHandler>
ble_error_t Gap<EventHandler>::advertising_enable_(bool enable)
{ {
if (enable) { if (enable) {
uint8_t adv_handles[] = {DM_ADV_HANDLE_DEFAULT}; uint8_t adv_handles[] = {DM_ADV_HANDLE_DEFAULT};
@ -140,7 +150,8 @@ ble_error_t Gap::advertising_enable(bool enable)
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t Gap::set_scan_parameters( template<class EventHandler>
ble_error_t Gap<EventHandler>::set_scan_parameters_(
bool active_scanning, bool active_scanning,
uint16_t scan_interval, uint16_t scan_interval,
uint16_t scan_window, uint16_t scan_window,
@ -158,7 +169,8 @@ ble_error_t Gap::set_scan_parameters(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t Gap::scan_enable( template<class EventHandler>
ble_error_t Gap<EventHandler>::scan_enable_(
bool enable, bool enable,
bool filter_duplicates bool filter_duplicates
) )
@ -179,7 +191,8 @@ ble_error_t Gap::scan_enable(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t Gap::create_connection( template<class EventHandler>
ble_error_t Gap<EventHandler>::create_connection_(
uint16_t scan_interval, uint16_t scan_interval,
uint16_t scan_window, uint16_t scan_window,
initiator_policy_t initiator_policy, initiator_policy_t initiator_policy,
@ -222,7 +235,8 @@ ble_error_t Gap::create_connection(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t Gap::cancel_connection_creation() template<class EventHandler>
ble_error_t Gap<EventHandler>::cancel_connection_creation_()
{ {
DmConnClose( DmConnClose(
DM_CLIENT_ID_APP, DM_CLIENT_ID_APP,
@ -232,18 +246,21 @@ ble_error_t Gap::cancel_connection_creation()
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
uint8_t Gap::read_white_list_capacity() template<class EventHandler>
uint8_t Gap<EventHandler>::read_white_list_capacity_()
{ {
return HciGetWhiteListSize(); return HciGetWhiteListSize();
} }
ble_error_t Gap::clear_whitelist() template<class EventHandler>
ble_error_t Gap<EventHandler>::clear_whitelist_()
{ {
DmDevWhiteListClear(); DmDevWhiteListClear();
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t Gap::add_device_to_whitelist( template<class EventHandler>
ble_error_t Gap<EventHandler>::add_device_to_whitelist_(
whitelist_address_type_t address_type, whitelist_address_type_t address_type,
address_t address address_t address
) )
@ -255,7 +272,8 @@ ble_error_t Gap::add_device_to_whitelist(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t Gap::remove_device_from_whitelist( template<class EventHandler>
ble_error_t Gap<EventHandler>::remove_device_from_whitelist_(
whitelist_address_type_t address_type, whitelist_address_type_t address_type,
address_t address address_t address
) )
@ -267,7 +285,8 @@ ble_error_t Gap::remove_device_from_whitelist(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t Gap::connection_parameters_update( template<class EventHandler>
ble_error_t Gap<EventHandler>::connection_parameters_update_(
connection_handle_t connection, connection_handle_t connection,
uint16_t connection_interval_min, uint16_t connection_interval_min,
uint16_t connection_interval_max, uint16_t connection_interval_max,
@ -297,7 +316,8 @@ ble_error_t Gap::connection_parameters_update(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t Gap::accept_connection_parameter_request( template<class EventHandler>
ble_error_t Gap<EventHandler>::accept_connection_parameter_request_(
connection_handle_t connection_handle, connection_handle_t connection_handle,
uint16_t interval_min, uint16_t interval_min,
uint16_t interval_max, uint16_t interval_max,
@ -319,7 +339,8 @@ ble_error_t Gap::accept_connection_parameter_request(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t Gap::reject_connection_parameter_request( template<class EventHandler>
ble_error_t Gap<EventHandler>::reject_connection_parameter_request_(
connection_handle_t connection_handle, connection_handle_t connection_handle,
hci_error_code_t rejection_reason hci_error_code_t rejection_reason
) )
@ -331,7 +352,8 @@ ble_error_t Gap::reject_connection_parameter_request(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t Gap::disconnect( template<class EventHandler>
ble_error_t Gap<EventHandler>::disconnect_(
connection_handle_t connection, connection_handle_t connection,
disconnection_reason_t disconnection_reason disconnection_reason_t disconnection_reason
) )
@ -344,13 +366,15 @@ ble_error_t Gap::disconnect(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
bool Gap::is_privacy_supported() template<class EventHandler>
bool Gap<EventHandler>::is_privacy_supported_()
{ {
// We only support controller-based privacy, so return whether the controller supports it // We only support controller-based privacy, so return whether the controller supports it
return HciLlPrivacySupported(); return HciLlPrivacySupported();
} }
ble_error_t Gap::set_address_resolution( template<class EventHandler>
ble_error_t Gap<EventHandler>::set_address_resolution_(
bool enable bool enable
) )
{ {
@ -358,23 +382,25 @@ ble_error_t Gap::set_address_resolution(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t Gap::read_phy(connection_handle_t connection) template<class EventHandler>
ble_error_t Gap<EventHandler>::read_phy_(connection_handle_t connection)
{ {
if (is_feature_supported(controller_supported_features_t::LE_2M_PHY) if (Base::is_feature_supported(controller_supported_features_t::LE_2M_PHY)
|| is_feature_supported(controller_supported_features_t::LE_CODED_PHY)) { || Base::is_feature_supported(controller_supported_features_t::LE_CODED_PHY)) {
DmReadPhy(connection); DmReadPhy(connection);
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
return BLE_ERROR_NOT_IMPLEMENTED; return BLE_ERROR_NOT_IMPLEMENTED;
} }
ble_error_t Gap::set_preferred_phys( template<class EventHandler>
ble_error_t Gap<EventHandler>::set_preferred_phys_(
const phy_set_t &tx_phys, const phy_set_t &tx_phys,
const phy_set_t &rx_phys const phy_set_t &rx_phys
) )
{ {
DmSetDefaultPhy( DmSetDefaultPhy(
create_all_phys_value(tx_phys, rx_phys), Base::create_all_phys_value(tx_phys, rx_phys),
tx_phys.value(), tx_phys.value(),
rx_phys.value() rx_phys.value()
); );
@ -382,7 +408,8 @@ ble_error_t Gap::set_preferred_phys(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t Gap::set_phy( template<class EventHandler>
ble_error_t Gap<EventHandler>::set_phy_(
connection_handle_t connection, connection_handle_t connection,
const phy_set_t &tx_phys, const phy_set_t &tx_phys,
const phy_set_t &rx_phys, const phy_set_t &rx_phys,
@ -400,7 +427,7 @@ ble_error_t Gap::set_phy(
DmSetPhy( DmSetPhy(
connection, connection,
create_all_phys_value(tx_phys, rx_phys), Base::create_all_phys_value(tx_phys, rx_phys),
tx_phys.value(), tx_phys.value(),
rx_phys.value(), rx_phys.value(),
coded_symbol.value() coded_symbol.value()
@ -410,7 +437,8 @@ ble_error_t Gap::set_phy(
} }
// singleton of the ARM Cordio client // singleton of the ARM Cordio client
Gap &Gap::get_gap() template<class EventHandler>
Gap<EventHandler> &Gap<EventHandler>::get_gap()
{ {
static Gap _gap; static Gap _gap;
return _gap; return _gap;
@ -419,7 +447,8 @@ Gap &Gap::get_gap()
/** /**
* Callback which handle wsfMsgHdr_t and forward them to emit_gap_event. * Callback which handle wsfMsgHdr_t and forward them to emit_gap_event.
*/ */
void Gap::gap_handler(const wsfMsgHdr_t *msg) template<class EventHandler>
void Gap<EventHandler>::gap_handler(const wsfMsgHdr_t *msg)
{ {
typedef bool (*event_handler_t)(const wsfMsgHdr_t *msg); typedef bool (*event_handler_t)(const wsfMsgHdr_t *msg);
@ -538,14 +567,14 @@ void Gap::gap_handler(const wsfMsgHdr_t *msg)
evt->numComplEvts evt->numComplEvts
); );
} }
break; break;
case DM_EXT_SCAN_STOP_IND: { case DM_EXT_SCAN_STOP_IND: {
if (!handler) { if (!handler) {
break; break;
} }
const hciLeScanTimeoutEvt_t *evt = (const hciLeScanTimeoutEvt_t *) msg; //const hciLeScanTimeoutEvt_t *evt = (const hciLeScanTimeoutEvt_t *) msg;
handler->on_scan_timeout(); handler->on_scan_timeout();
} }
break; break;
@ -633,8 +662,9 @@ void Gap::gap_handler(const wsfMsgHdr_t *msg)
/** /**
* T shall define a can_convert and convert function and a type * T shall define a can_convert and convert function and a type
*/ */
template<class EventHandler>
template<typename T> template<typename T>
bool Gap::event_handler(const wsfMsgHdr_t *msg) bool Gap<EventHandler>::event_handler(const wsfMsgHdr_t *msg)
{ {
if (T::can_convert(msg)) { if (T::can_convert(msg)) {
get_gap().emit_gap_event(T::convert((const typename T::type *) msg)); get_gap().emit_gap_event(T::convert((const typename T::type *) msg));
@ -643,7 +673,8 @@ bool Gap::event_handler(const wsfMsgHdr_t *msg)
return false; return false;
} }
ble_error_t Gap::set_advertising_set_random_address( template<class EventHandler>
ble_error_t Gap<EventHandler>::set_advertising_set_random_address_(
advertising_handle_t advertising_handle, advertising_handle_t advertising_handle,
const address_t &address const address_t &address
) )
@ -652,7 +683,8 @@ ble_error_t Gap::set_advertising_set_random_address(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t Gap::set_extended_advertising_parameters( template<class EventHandler>
ble_error_t Gap<EventHandler>::set_extended_advertising_parameters_(
advertising_handle_t advertising_handle, advertising_handle_t advertising_handle,
advertising_event_properties_t event_properties, advertising_event_properties_t event_properties,
advertising_interval_t primary_advertising_interval_min, advertising_interval_t primary_advertising_interval_min,
@ -787,7 +819,8 @@ ble_error_t Gap::set_extended_advertising_parameters(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t Gap::set_periodic_advertising_parameters( template<class EventHandler>
ble_error_t Gap<EventHandler>::set_periodic_advertising_parameters_(
advertising_handle_t advertising_handle, advertising_handle_t advertising_handle,
periodic_advertising_interval_t periodic_advertising_min, periodic_advertising_interval_t periodic_advertising_min,
periodic_advertising_interval_t periodic_advertising_max, periodic_advertising_interval_t periodic_advertising_max,
@ -805,7 +838,8 @@ ble_error_t Gap::set_periodic_advertising_parameters(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t Gap::set_extended_advertising_data( template<class EventHandler>
ble_error_t Gap<EventHandler>::set_extended_advertising_data_(
advertising_handle_t advertising_handle, advertising_handle_t advertising_handle,
advertising_fragment_description_t operation, advertising_fragment_description_t operation,
bool minimize_fragmentation, bool minimize_fragmentation,
@ -829,7 +863,8 @@ ble_error_t Gap::set_extended_advertising_data(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t Gap::set_periodic_advertising_data( template<class EventHandler>
ble_error_t Gap<EventHandler>::set_periodic_advertising_data_(
advertising_handle_t advertising_handle, advertising_handle_t advertising_handle,
advertising_fragment_description_t fragment_description, advertising_fragment_description_t fragment_description,
uint8_t advertising_data_size, uint8_t advertising_data_size,
@ -845,7 +880,8 @@ ble_error_t Gap::set_periodic_advertising_data(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t Gap::set_extended_scan_response_data( template<class EventHandler>
ble_error_t Gap<EventHandler>::set_extended_scan_response_data_(
advertising_handle_t advertising_handle, advertising_handle_t advertising_handle,
advertising_fragment_description_t operation, advertising_fragment_description_t operation,
bool minimize_fragmentation, bool minimize_fragmentation,
@ -869,7 +905,8 @@ ble_error_t Gap::set_extended_scan_response_data(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t Gap::extended_advertising_enable( template<class EventHandler>
ble_error_t Gap<EventHandler>::extended_advertising_enable_(
bool enable, bool enable,
uint8_t number_of_sets, uint8_t number_of_sets,
const advertising_handle_t *handles, const advertising_handle_t *handles,
@ -902,7 +939,8 @@ ble_error_t Gap::extended_advertising_enable(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t Gap::periodic_advertising_enable( template<class EventHandler>
ble_error_t Gap<EventHandler>::periodic_advertising_enable_(
bool enable, bool enable,
advertising_handle_t advertising_handle advertising_handle_t advertising_handle
) )
@ -916,39 +954,46 @@ ble_error_t Gap::periodic_advertising_enable(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
uint16_t Gap::get_maximum_advertising_data_length() template<class EventHandler>
uint16_t Gap<EventHandler>::get_maximum_advertising_data_length_()
{ {
return HciGetMaxAdvDataLen(); return HciGetMaxAdvDataLen();
} }
uint16_t Gap::get_maximum_connectable_advertising_data_length() template<class EventHandler>
uint16_t Gap<EventHandler>::get_maximum_connectable_advertising_data_length_()
{ {
return HCI_EXT_ADV_CONN_DATA_LEN; return HCI_EXT_ADV_CONN_DATA_LEN;
} }
uint8_t Gap::get_maximum_hci_advertising_data_length() template<class EventHandler>
uint8_t Gap<EventHandler>::get_maximum_hci_advertising_data_length_()
{ {
return HCI_EXT_ADV_DATA_LEN; return HCI_EXT_ADV_DATA_LEN;
} }
uint8_t Gap::get_max_number_of_advertising_sets() template<class EventHandler>
uint8_t Gap<EventHandler>::get_max_number_of_advertising_sets_()
{ {
return std::min(HciGetNumSupAdvSets(), (uint8_t) DM_NUM_ADV_SETS); return std::min(HciGetNumSupAdvSets(), (uint8_t) DM_NUM_ADV_SETS);
} }
ble_error_t Gap::remove_advertising_set(advertising_handle_t advertising_handle) template<class EventHandler>
ble_error_t Gap<EventHandler>::remove_advertising_set_(advertising_handle_t advertising_handle)
{ {
DmAdvRemoveAdvSet(advertising_handle); DmAdvRemoveAdvSet(advertising_handle);
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t Gap::clear_advertising_sets() template<class EventHandler>
ble_error_t Gap<EventHandler>::clear_advertising_sets_()
{ {
DmAdvClearAdvSets(); DmAdvClearAdvSets();
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t Gap::set_extended_scan_parameters( template<class EventHandler>
ble_error_t Gap<EventHandler>::set_extended_scan_parameters_(
own_address_type_t own_address_type, own_address_type_t own_address_type,
scanning_filter_policy_t filter_policy, scanning_filter_policy_t filter_policy,
phy_set_t scanning_phys, phy_set_t scanning_phys,
@ -981,7 +1026,8 @@ ble_error_t Gap::set_extended_scan_parameters(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t Gap::extended_scan_enable( template<class EventHandler>
ble_error_t Gap<EventHandler>::extended_scan_enable_(
bool enable, bool enable,
duplicates_filter_t filter_duplicates, duplicates_filter_t filter_duplicates,
uint16_t duration, uint16_t duration,
@ -1006,7 +1052,8 @@ ble_error_t Gap::extended_scan_enable(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t Gap::periodic_advertising_create_sync( template<class EventHandler>
ble_error_t Gap<EventHandler>::periodic_advertising_create_sync_(
bool use_periodic_advertiser_list, bool use_periodic_advertiser_list,
uint8_t advertising_sid, uint8_t advertising_sid,
peer_address_type_t peer_address_type, peer_address_type_t peer_address_type,
@ -1036,20 +1083,23 @@ ble_error_t Gap::periodic_advertising_create_sync(
} }
} }
ble_error_t Gap::cancel_periodic_advertising_create_sync() template<class EventHandler>
ble_error_t Gap<EventHandler>::cancel_periodic_advertising_create_sync_()
{ {
// FIXME: Find a way to use it! // FIXME: Find a way to use it!
// Function not directly exposed by the cordio stack. // Function not directly exposed by the cordio stack.
return BLE_ERROR_NOT_IMPLEMENTED; return BLE_ERROR_NOT_IMPLEMENTED;
} }
ble_error_t Gap::periodic_advertising_terminate_sync(sync_handle_t sync_handle) template<class EventHandler>
ble_error_t Gap<EventHandler>::periodic_advertising_terminate_sync_(sync_handle_t sync_handle)
{ {
DmSyncStop(sync_handle); DmSyncStop(sync_handle);
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t Gap::add_device_to_periodic_advertiser_list( template<class EventHandler>
ble_error_t Gap<EventHandler>::add_device_to_periodic_advertiser_list_(
advertising_peer_address_type_t advertiser_address_type, advertising_peer_address_type_t advertiser_address_type,
const address_t &advertiser_address, const address_t &advertiser_address,
uint8_t advertising_sid uint8_t advertising_sid
@ -1063,7 +1113,8 @@ ble_error_t Gap::add_device_to_periodic_advertiser_list(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t Gap::remove_device_from_periodic_advertiser_list( template<class EventHandler>
ble_error_t Gap<EventHandler>::remove_device_from_periodic_advertiser_list_(
advertising_peer_address_type_t advertiser_address_type, advertising_peer_address_type_t advertiser_address_type,
const address_t &advertiser_address, const address_t &advertiser_address,
uint8_t advertising_sid uint8_t advertising_sid
@ -1077,18 +1128,21 @@ ble_error_t Gap::remove_device_from_periodic_advertiser_list(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t Gap::clear_periodic_advertiser_list() template<class EventHandler>
ble_error_t Gap<EventHandler>::clear_periodic_advertiser_list_()
{ {
DmClearPerAdvList(); DmClearPerAdvList();
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
uint8_t Gap::read_periodic_advertiser_list_size() template<class EventHandler>
uint8_t Gap<EventHandler>::read_periodic_advertiser_list_size_()
{ {
return HciGetPerAdvListSize(); return HciGetPerAdvListSize();
} }
ble_error_t Gap::extended_create_connection( template<class EventHandler>
ble_error_t Gap<EventHandler>::extended_create_connection_(
initiator_policy_t initiator_policy, initiator_policy_t initiator_policy,
own_address_type_t own_address_type, own_address_type_t own_address_type,
peer_address_type_t peer_address_type, peer_address_type_t peer_address_type,

View File

@ -17,7 +17,6 @@
#include <string.h> #include <string.h>
#include "CordioPalSecurityManager.h" #include "CordioPalSecurityManager.h"
#include "CordioBLE.h"
#include "dm_api.h" #include "dm_api.h"
#include "att_api.h" #include "att_api.h"
#include "smp_api.h" #include "smp_api.h"
@ -29,8 +28,8 @@ namespace pal {
namespace vendor { namespace vendor {
namespace cordio { namespace cordio {
CordioSecurityManager::CordioSecurityManager() : template <class EventHandler>
::ble::pal::SecurityManager(), CordioSecurityManager<EventHandler>::CordioSecurityManager() :
_use_default_passkey(false), _use_default_passkey(false),
_default_passkey(0), _default_passkey(0),
_lesc_keys_generated(false), _lesc_keys_generated(false),
@ -42,7 +41,8 @@ CordioSecurityManager::CordioSecurityManager() :
} }
CordioSecurityManager::~CordioSecurityManager() template <class EventHandler>
CordioSecurityManager<EventHandler>::~CordioSecurityManager()
{ {
clear_privacy_control_blocks(); clear_privacy_control_blocks();
} }
@ -51,7 +51,8 @@ CordioSecurityManager::~CordioSecurityManager()
// SM lifecycle management // SM lifecycle management
// //
ble_error_t CordioSecurityManager::initialize() template <class EventHandler>
ble_error_t CordioSecurityManager<EventHandler>::initialize_()
{ {
// reset local state // reset local state
_use_default_passkey = false; _use_default_passkey = false;
@ -68,13 +69,15 @@ ble_error_t CordioSecurityManager::initialize()
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t CordioSecurityManager::terminate() template <class EventHandler>
ble_error_t CordioSecurityManager<EventHandler>::terminate_()
{ {
cleanup_peer_csrks(); cleanup_peer_csrks();
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t CordioSecurityManager::reset() template <class EventHandler>
ble_error_t CordioSecurityManager<EventHandler>::reset_()
{ {
cleanup_peer_csrks(); cleanup_peer_csrks();
initialize(); initialize();
@ -85,7 +88,8 @@ ble_error_t CordioSecurityManager::reset()
// Resolving list management // Resolving list management
// //
uint8_t CordioSecurityManager::read_resolving_list_capacity() template <class EventHandler>
uint8_t CordioSecurityManager<EventHandler>::read_resolving_list_capacity_()
{ {
// The Cordio stack requests this from the controller during initialization // The Cordio stack requests this from the controller during initialization
return hciCoreCb.resListSize; return hciCoreCb.resListSize;
@ -93,7 +97,8 @@ uint8_t CordioSecurityManager::read_resolving_list_capacity()
// As the Cordio stack can only handle one of these methods at a time, we need to create a list of control blocks // As the Cordio stack can only handle one of these methods at a time, we need to create a list of control blocks
// that are dequeued one after the other on completion of the previous one // that are dequeued one after the other on completion of the previous one
ble_error_t CordioSecurityManager::add_device_to_resolving_list( template <class EventHandler>
ble_error_t CordioSecurityManager<EventHandler>::add_device_to_resolving_list_(
advertising_peer_address_type_t peer_identity_address_type, advertising_peer_address_type_t peer_identity_address_type,
const address_t &peer_identity_address, const address_t &peer_identity_address,
const irk_t &peer_irk const irk_t &peer_irk
@ -110,7 +115,8 @@ ble_error_t CordioSecurityManager::add_device_to_resolving_list(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t CordioSecurityManager::remove_device_from_resolving_list( template <class EventHandler>
ble_error_t CordioSecurityManager<EventHandler>::remove_device_from_resolving_list_(
advertising_peer_address_type_t peer_identity_address_type, advertising_peer_address_type_t peer_identity_address_type,
const address_t& peer_identity_address const address_t& peer_identity_address
) { ) {
@ -126,7 +132,8 @@ ble_error_t CordioSecurityManager::remove_device_from_resolving_list(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t CordioSecurityManager::clear_resolving_list() template <class EventHandler>
ble_error_t CordioSecurityManager<EventHandler>::clear_resolving_list_()
{ {
if( read_resolving_list_capacity() == 0 ) if( read_resolving_list_capacity() == 0 )
{ {
@ -146,7 +153,8 @@ ble_error_t CordioSecurityManager::clear_resolving_list()
// FIXME: Enable when new function available in the pal. // FIXME: Enable when new function available in the pal.
#if 0 #if 0
ble_error_t CordioSecurityManager::set_secure_connections_support( template <class EventHandler>
ble_error_t CordioSecurityManager<EventHandler>::set_secure_connections_support(
bool enabled, bool secure_connections_only bool enabled, bool secure_connections_only
) { ) {
// secure connection support is enabled automatically at the stack level. // secure connection support is enabled automatically at the stack level.
@ -159,7 +167,8 @@ ble_error_t CordioSecurityManager::set_secure_connections_support(
} }
#endif #endif
ble_error_t CordioSecurityManager::get_secure_connections_support( template <class EventHandler>
ble_error_t CordioSecurityManager<EventHandler>::get_secure_connections_support_(
bool &enabled bool &enabled
) { ) {
// FIXME: should depend of the controller // FIXME: should depend of the controller
@ -171,21 +180,24 @@ ble_error_t CordioSecurityManager::get_secure_connections_support(
// Security settings // Security settings
// //
ble_error_t CordioSecurityManager::set_authentication_timeout( template <class EventHandler>
ble_error_t CordioSecurityManager<EventHandler>::set_authentication_timeout_(
connection_handle_t connection, uint16_t timeout_in_10ms connection_handle_t connection, uint16_t timeout_in_10ms
) { ) {
DmWriteAuthPayloadTimeout(connection, timeout_in_10ms); DmWriteAuthPayloadTimeout(connection, timeout_in_10ms);
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t CordioSecurityManager::get_authentication_timeout( template <class EventHandler>
ble_error_t CordioSecurityManager<EventHandler>::get_authentication_timeout_(
connection_handle_t connection, uint16_t &timeout_in_10ms connection_handle_t connection, uint16_t &timeout_in_10ms
) { ) {
// FIXME: Is it usefull to add dynamic timeout management for all connections ? // FIXME: Is it usefull to add dynamic timeout management for all connections ?
return BLE_ERROR_NOT_IMPLEMENTED; return BLE_ERROR_NOT_IMPLEMENTED;
} }
ble_error_t CordioSecurityManager::slave_security_request( template <class EventHandler>
ble_error_t CordioSecurityManager<EventHandler>::slave_security_request_(
connection_handle_t connection, connection_handle_t connection,
AuthenticationMask authentication AuthenticationMask authentication
) { ) {
@ -197,7 +209,8 @@ ble_error_t CordioSecurityManager::slave_security_request(
// Encryption // Encryption
// //
ble_error_t CordioSecurityManager::enable_encryption( template <class EventHandler>
ble_error_t CordioSecurityManager<EventHandler>::enable_encryption_(
connection_handle_t connection, connection_handle_t connection,
const ltk_t &ltk, const ltk_t &ltk,
const rand_t &rand, const rand_t &rand,
@ -218,7 +231,8 @@ ble_error_t CordioSecurityManager::enable_encryption(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t CordioSecurityManager::enable_encryption( template <class EventHandler>
ble_error_t CordioSecurityManager<EventHandler>::enable_encryption_(
connection_handle_t connection, connection_handle_t connection,
const ltk_t &ltk, const ltk_t &ltk,
bool mitm bool mitm
@ -236,7 +250,8 @@ ble_error_t CordioSecurityManager::enable_encryption(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t CordioSecurityManager::encrypt_data( template <class EventHandler>
ble_error_t CordioSecurityManager<EventHandler>::encrypt_data_(
const byte_array_t<16> &key, const byte_array_t<16> &key,
encryption_block_t &data encryption_block_t &data
) { ) {
@ -247,7 +262,8 @@ ble_error_t CordioSecurityManager::encrypt_data(
// Privacy // Privacy
// //
ble_error_t CordioSecurityManager::set_private_address_timeout( template <class EventHandler>
ble_error_t CordioSecurityManager<EventHandler>::set_private_address_timeout_(
uint16_t timeout_in_seconds uint16_t timeout_in_seconds
) { ) {
DmPrivSetResolvablePrivateAddrTimeout(timeout_in_seconds); DmPrivSetResolvablePrivateAddrTimeout(timeout_in_seconds);
@ -258,7 +274,8 @@ ble_error_t CordioSecurityManager::set_private_address_timeout(
// Keys // Keys
// //
ble_error_t CordioSecurityManager::set_ltk( template <class EventHandler>
ble_error_t CordioSecurityManager<EventHandler>::set_ltk_(
connection_handle_t connection, connection_handle_t connection,
const ltk_t& ltk, const ltk_t& ltk,
bool mitm, bool mitm,
@ -282,7 +299,8 @@ ble_error_t CordioSecurityManager::set_ltk(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t CordioSecurityManager::set_ltk_not_found( template <class EventHandler>
ble_error_t CordioSecurityManager<EventHandler>::set_ltk_not_found_(
connection_handle_t connection connection_handle_t connection
) { ) {
DmSecLtkRsp( DmSecLtkRsp(
@ -295,26 +313,29 @@ ble_error_t CordioSecurityManager::set_ltk_not_found(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t CordioSecurityManager::set_irk(const irk_t& irk) template <class EventHandler>
ble_error_t CordioSecurityManager<EventHandler>::set_irk_(const irk_t& irk)
{ {
_irk = irk; _irk = irk;
DmSecSetLocalIrk(_irk.data()); DmSecSetLocalIrk(_irk.data());
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t CordioSecurityManager::set_csrk( template <class EventHandler>
ble_error_t CordioSecurityManager<EventHandler>::set_csrk_(
const csrk_t& csrk, const csrk_t& csrk,
sign_count_t sign_counter sign_count_t sign_counter
) { ) {
_csrk = csrk; _csrk = csrk;
DmSecSetLocalCsrk(_csrk.data()); DmSecSetLocalCsrk(_csrk.data());
// extra set the sign counter used by the client // extra set the sign counter used by the client
CordioAttClient::get_client().set_sign_counter(sign_counter); CordioAttClient::get_client().set_sign_counter_(sign_counter);
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t CordioSecurityManager::set_peer_csrk( template <class EventHandler>
ble_error_t CordioSecurityManager<EventHandler>::set_peer_csrk_(
connection_handle_t connection, connection_handle_t connection,
const csrk_t &csrk, const csrk_t &csrk,
bool authenticated, bool authenticated,
@ -340,7 +361,8 @@ ble_error_t CordioSecurityManager::set_peer_csrk(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t CordioSecurityManager::remove_peer_csrk(connection_handle_t connection) template <class EventHandler>
ble_error_t CordioSecurityManager<EventHandler>::remove_peer_csrk_(connection_handle_t connection)
{ {
if (connection == 0 || connection > DM_CONN_MAX) { if (connection == 0 || connection > DM_CONN_MAX) {
return BLE_ERROR_INVALID_PARAM; return BLE_ERROR_INVALID_PARAM;
@ -361,7 +383,8 @@ ble_error_t CordioSecurityManager::remove_peer_csrk(connection_handle_t connecti
// Global parameters // Global parameters
// //
ble_error_t CordioSecurityManager::set_display_passkey(passkey_num_t passkey) template <class EventHandler>
ble_error_t CordioSecurityManager<EventHandler>::set_display_passkey_(passkey_num_t passkey)
{ {
if (passkey) { if (passkey) {
_use_default_passkey = true; _use_default_passkey = true;
@ -372,13 +395,15 @@ ble_error_t CordioSecurityManager::set_display_passkey(passkey_num_t passkey)
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t CordioSecurityManager::set_io_capability(io_capability_t io_capability) template <class EventHandler>
ble_error_t CordioSecurityManager<EventHandler>::set_io_capability_(io_capability_t io_capability)
{ {
pSmpCfg->ioCap = io_capability.value(); pSmpCfg->ioCap = io_capability.value();
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t CordioSecurityManager::set_encryption_key_requirements( template <class EventHandler>
ble_error_t CordioSecurityManager<EventHandler>::set_encryption_key_requirements_(
uint8_t min_encryption_key_size, uint8_t min_encryption_key_size,
uint8_t max_encryption_key_size uint8_t max_encryption_key_size
) { ) {
@ -397,7 +422,8 @@ ble_error_t CordioSecurityManager::set_encryption_key_requirements(
// Authentication // Authentication
// //
ble_error_t CordioSecurityManager::send_pairing_request( template <class EventHandler>
ble_error_t CordioSecurityManager<EventHandler>::send_pairing_request_(
connection_handle_t connection, connection_handle_t connection,
bool oob_data_flag, bool oob_data_flag,
AuthenticationMask authentication_requirements, AuthenticationMask authentication_requirements,
@ -415,7 +441,8 @@ ble_error_t CordioSecurityManager::send_pairing_request(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t CordioSecurityManager::send_pairing_response( template <class EventHandler>
ble_error_t CordioSecurityManager<EventHandler>::send_pairing_response_(
connection_handle_t connection, connection_handle_t connection,
bool oob_data_flag, bool oob_data_flag,
AuthenticationMask authentication_requirements, AuthenticationMask authentication_requirements,
@ -433,14 +460,16 @@ ble_error_t CordioSecurityManager::send_pairing_response(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t CordioSecurityManager::cancel_pairing( template <class EventHandler>
ble_error_t CordioSecurityManager<EventHandler>::cancel_pairing_(
connection_handle_t connection, pairing_failure_t reason connection_handle_t connection, pairing_failure_t reason
) { ) {
DmSecCancelReq(connection, reason.value()); DmSecCancelReq(connection, reason.value());
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t CordioSecurityManager::get_random_data(byte_array_t<8> &random_data) template <class EventHandler>
ble_error_t CordioSecurityManager<EventHandler>::get_random_data_(byte_array_t<8> &random_data)
{ {
SecRand(random_data.data(), random_data.size()); SecRand(random_data.data(), random_data.size());
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
@ -450,7 +479,8 @@ ble_error_t CordioSecurityManager::get_random_data(byte_array_t<8> &random_data)
// MITM // MITM
// //
ble_error_t CordioSecurityManager::passkey_request_reply( template <class EventHandler>
ble_error_t CordioSecurityManager<EventHandler>::passkey_request_reply_(
connection_handle_t connection, passkey_num_t passkey connection_handle_t connection, passkey_num_t passkey
) { ) {
DmSecAuthRsp( DmSecAuthRsp(
@ -462,7 +492,8 @@ ble_error_t CordioSecurityManager::passkey_request_reply(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t CordioSecurityManager::legacy_pairing_oob_request_reply( template <class EventHandler>
ble_error_t CordioSecurityManager<EventHandler>::legacy_pairing_oob_request_reply_(
connection_handle_t connection, connection_handle_t connection,
const oob_tk_t &oob_data const oob_tk_t &oob_data
) { ) {
@ -475,7 +506,8 @@ ble_error_t CordioSecurityManager::legacy_pairing_oob_request_reply(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t CordioSecurityManager::confirmation_entered( template <class EventHandler>
ble_error_t CordioSecurityManager<EventHandler>::confirmation_entered_(
connection_handle_t connection, bool confirmation connection_handle_t connection, bool confirmation
) { ) {
DmSecCompareRsp(connection, confirmation); DmSecCompareRsp(connection, confirmation);
@ -485,7 +517,8 @@ ble_error_t CordioSecurityManager::confirmation_entered(
// FIXME: remove when declaration from the stack is available // FIXME: remove when declaration from the stack is available
extern "C" void DmSecKeypressReq(dmConnId_t connId, uint8_t keypressType); extern "C" void DmSecKeypressReq(dmConnId_t connId, uint8_t keypressType);
ble_error_t CordioSecurityManager::send_keypress_notification( template <class EventHandler>
ble_error_t CordioSecurityManager<EventHandler>::send_keypress_notification_(
connection_handle_t connection, Keypress_t keypress connection_handle_t connection, Keypress_t keypress
) { ) {
DmSecKeypressReq(connection, keypress); DmSecKeypressReq(connection, keypress);
@ -493,14 +526,16 @@ ble_error_t CordioSecurityManager::send_keypress_notification(
} }
ble_error_t CordioSecurityManager::generate_secure_connections_oob() { template <class EventHandler>
ble_error_t CordioSecurityManager<EventHandler>::generate_secure_connections_oob_() {
uint8_t oobLocalRandom[SMP_RAND_LEN]; uint8_t oobLocalRandom[SMP_RAND_LEN];
SecRand(oobLocalRandom, SMP_RAND_LEN); SecRand(oobLocalRandom, SMP_RAND_LEN);
DmSecCalcOobReq(oobLocalRandom, _public_key_x); DmSecCalcOobReq(oobLocalRandom, _public_key_x);
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t CordioSecurityManager::secure_connections_oob_request_reply( template <class EventHandler>
ble_error_t CordioSecurityManager<EventHandler>::secure_connections_oob_request_reply_(
connection_handle_t connection, connection_handle_t connection,
const oob_lesc_value_t &local_random, const oob_lesc_value_t &local_random,
const oob_lesc_value_t &peer_random, const oob_lesc_value_t &peer_random,
@ -520,15 +555,17 @@ ble_error_t CordioSecurityManager::secure_connections_oob_request_reply(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
CordioSecurityManager& CordioSecurityManager::get_security_manager() template <class EventHandler>
CordioSecurityManager<EventHandler>& CordioSecurityManager<EventHandler>::get_security_manager()
{ {
static CordioSecurityManager _security_manager; static CordioSecurityManager<EventHandler> _security_manager;
return _security_manager; return _security_manager;
} }
bool CordioSecurityManager::sm_handler(const wsfMsgHdr_t* msg) { template <class EventHandler>
bool CordioSecurityManager<EventHandler>::sm_handler(const wsfMsgHdr_t* msg) {
CordioSecurityManager& self = get_security_manager(); CordioSecurityManager& self = get_security_manager();
SecurityManager::EventHandler* handler = self.get_event_handler(); EventHandler* handler = self.get_event_handler();
if ((msg == NULL) || (handler == NULL)) { if ((msg == NULL) || (handler == NULL)) {
return false; return false;
@ -768,7 +805,8 @@ bool CordioSecurityManager::sm_handler(const wsfMsgHdr_t* msg) {
} }
} }
struct CordioSecurityManager::PrivacyControlBlock template <class EventHandler>
struct CordioSecurityManager<EventHandler>::PrivacyControlBlock
{ {
PrivacyControlBlock() : _next(NULL) {} PrivacyControlBlock() : _next(NULL) {}
@ -788,7 +826,8 @@ private:
PrivacyControlBlock* _next; PrivacyControlBlock* _next;
}; };
struct CordioSecurityManager::PrivacyClearResListControlBlock : CordioSecurityManager::PrivacyControlBlock template <class EventHandler>
struct CordioSecurityManager<EventHandler>::PrivacyClearResListControlBlock : CordioSecurityManager::PrivacyControlBlock
{ {
PrivacyClearResListControlBlock() : PrivacyControlBlock() PrivacyClearResListControlBlock() : PrivacyControlBlock()
{} {}
@ -801,16 +840,17 @@ struct CordioSecurityManager::PrivacyClearResListControlBlock : CordioSecurityMa
} }
}; };
struct CordioSecurityManager::PrivacyAddDevToResListControlBlock : CordioSecurityManager::PrivacyControlBlock template <class EventHandler>
struct CordioSecurityManager<EventHandler>::PrivacyAddDevToResListControlBlock : CordioSecurityManager::PrivacyControlBlock
{ {
PrivacyAddDevToResListControlBlock( PrivacyAddDevToResListControlBlock(
advertising_peer_address_type_t peer_identity_address_type, advertising_peer_address_type_t peer_identity_address_type,
const address_t &peer_identity_address, const address_t &peer_identity_address,
const irk_t &peer_irk const irk_t &peer_irk
) : PrivacyControlBlock(), ) : PrivacyControlBlock(),
_peer_identity_address_type(peer_identity_address_type), _peer_identity_address_type(peer_identity_address_type),
_peer_identity_address(peer_identity_address), _peer_identity_address(peer_identity_address),
_peer_irk(peer_irk) _peer_irk(peer_irk)
{} {}
virtual ~PrivacyAddDevToResListControlBlock() {} virtual ~PrivacyAddDevToResListControlBlock() {}
@ -826,14 +866,15 @@ private:
irk_t _peer_irk; irk_t _peer_irk;
}; };
struct CordioSecurityManager::PrivacyRemoveDevFromResListControlBlock : CordioSecurityManager::PrivacyControlBlock template <class EventHandler>
struct CordioSecurityManager<EventHandler>::PrivacyRemoveDevFromResListControlBlock : CordioSecurityManager::PrivacyControlBlock
{ {
PrivacyRemoveDevFromResListControlBlock( PrivacyRemoveDevFromResListControlBlock(
advertising_peer_address_type_t peer_identity_address_type, advertising_peer_address_type_t peer_identity_address_type,
const address_t &peer_identity_address const address_t &peer_identity_address
) : PrivacyControlBlock(), ) : PrivacyControlBlock(),
_peer_identity_address_type(peer_identity_address_type), _peer_identity_address_type(peer_identity_address_type),
_peer_identity_address(peer_identity_address) _peer_identity_address(peer_identity_address)
{ {
} }
@ -851,7 +892,8 @@ private:
}; };
// Helper functions for privacy // Helper functions for privacy
void CordioSecurityManager::queue_add_device_to_resolving_list( template <class EventHandler>
void CordioSecurityManager<EventHandler>::queue_add_device_to_resolving_list(
advertising_peer_address_type_t peer_identity_address_type, advertising_peer_address_type_t peer_identity_address_type,
const address_t &peer_identity_address, const address_t &peer_identity_address,
const irk_t &peer_irk const irk_t &peer_irk
@ -868,7 +910,8 @@ void CordioSecurityManager::queue_add_device_to_resolving_list(
queue_privacy_control_block(cb); queue_privacy_control_block(cb);
} }
void CordioSecurityManager::queue_remove_device_from_resolving_list( template <class EventHandler>
void CordioSecurityManager<EventHandler>::queue_remove_device_from_resolving_list(
advertising_peer_address_type_t peer_identity_address_type, advertising_peer_address_type_t peer_identity_address_type,
const address_t &peer_identity_address const address_t &peer_identity_address
) )
@ -884,7 +927,8 @@ void CordioSecurityManager::queue_remove_device_from_resolving_list(
queue_privacy_control_block(cb); queue_privacy_control_block(cb);
} }
void CordioSecurityManager::queue_clear_resolving_list() { template <class EventHandler>
void CordioSecurityManager<EventHandler>::queue_clear_resolving_list() {
// Remove any pending control blocks, there's no point executing them as we're about to queue the list // Remove any pending control blocks, there's no point executing them as we're about to queue the list
clear_privacy_control_blocks(); clear_privacy_control_blocks();
@ -899,7 +943,8 @@ void CordioSecurityManager::queue_clear_resolving_list() {
queue_privacy_control_block(cb); queue_privacy_control_block(cb);
} }
void CordioSecurityManager::clear_privacy_control_blocks() { template <class EventHandler>
void CordioSecurityManager<EventHandler>::clear_privacy_control_blocks() {
while(_pending_privacy_control_blocks != NULL) while(_pending_privacy_control_blocks != NULL)
{ {
PrivacyControlBlock* next = _pending_privacy_control_blocks->next(); PrivacyControlBlock* next = _pending_privacy_control_blocks->next();
@ -908,7 +953,8 @@ void CordioSecurityManager::clear_privacy_control_blocks() {
} }
} }
void CordioSecurityManager::queue_privacy_control_block(PrivacyControlBlock* block) template <class EventHandler>
void CordioSecurityManager<EventHandler>::queue_privacy_control_block(PrivacyControlBlock* block)
{ {
if( _pending_privacy_control_blocks == NULL ) { if( _pending_privacy_control_blocks == NULL ) {
_pending_privacy_control_blocks = block; _pending_privacy_control_blocks = block;
@ -925,7 +971,8 @@ void CordioSecurityManager::queue_privacy_control_block(PrivacyControlBlock* blo
} }
// If cb_completed is set to true, it means the previous control block has completed // If cb_completed is set to true, it means the previous control block has completed
void CordioSecurityManager::process_privacy_control_blocks(bool cb_completed) template <class EventHandler>
void CordioSecurityManager<EventHandler>::process_privacy_control_blocks(bool cb_completed)
{ {
if( (_processing_privacy_control_block == true) && !cb_completed ) if( (_processing_privacy_control_block == true) && !cb_completed )
{ {
@ -949,7 +996,8 @@ void CordioSecurityManager::process_privacy_control_blocks(bool cb_completed)
_pending_privacy_control_blocks = next; _pending_privacy_control_blocks = next;
} }
void CordioSecurityManager::cleanup_peer_csrks() { template <class EventHandler>
void CordioSecurityManager<EventHandler>::cleanup_peer_csrks() {
for (size_t i = 0; i < DM_CONN_MAX; ++i) { for (size_t i = 0; i < DM_CONN_MAX; ++i) {
if (_peer_csrks[i]) { if (_peer_csrks[i]) {
delete _peer_csrks[i]; delete _peer_csrks[i];