Signing event monitor proxy to bind both server and client

pull/6932/head
paul-szczepanek-arm 2018-04-10 14:58:29 +01:00
parent 4fff20583d
commit a2484b63b0
3 changed files with 36 additions and 4 deletions

View File

@ -20,6 +20,7 @@
#include <stddef.h>
#include "ble/blecommon.h"
#include "ble/GattServer.h"
#include "ble/pal/SigningEventMonitor.h"
#include "ble/Gap.h"
#include "wsf_types.h"
#include "att_api.h"
@ -34,7 +35,8 @@ namespace cordio {
/**
* Cordio implementation of ::GattServer
*/
class GattServer : public ::GattServer
class GattServer : public ::GattServer,
public pal::SigningEventMonitor
{
public:
/**
@ -147,6 +149,15 @@ public:
*/
virtual ble_error_t reset(void);
/**
* @see pal::SigningEventMonitor::set_signing_event_handler
*/
virtual void set_signing_event_handler(
pal::SigningEventMonitor::EventHandler *signing_event_handler
) {
_signing_event_handler = signing_event_handler;
}
private:
static void cccCback(attsCccEvt_t *pEvt);
static void attCback(attEvt_t *pEvt);
@ -172,6 +183,8 @@ private:
internal_service_t *next;
};
pal::SigningEventMonitor::EventHandler *_signing_event_handler;
attsCccSet_t cccSet[MAX_CCC_CNT];
uint16_t cccValues[MAX_CCC_CNT];
uint16_t cccHandles[MAX_CCC_CNT];

View File

@ -209,16 +209,29 @@ SecurityManager& BLE::getSecurityManager()
const SecurityManager& BLE::getSecurityManager() const
{
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;
};
static pal::MemorySecurityDb m_db;
pal::vendor::cordio::CordioSecurityManager &m_pal = pal::vendor::cordio::CordioSecurityManager::get_security_manager();
BLE *self = const_cast<BLE*>(this);
BLE &self = const_cast<BLE&>(*this);
static SigningEventMonitorProxy signing_event_monitor(self);
static generic::GenericSecurityManager m_instance(
m_pal,
m_db,
self->getGap(),
self->getGattClient()
self.getGap(),
signing_event_monitor
);
return m_instance;

View File

@ -585,6 +585,12 @@ uint8_t GattServer::attsWriteCback(dmConnId_t connId, uint16_t handle, uint8_t o
writeOp = GattWriteCallbackParams::OP_WRITE_CMD;
break;
case ATT_PDU_SIGNED_WRITE_CMD:
if (getInstance()._signing_event_handler) {
getInstance()._signing_event_handler->on_signed_write_received(
connId,
AttsGetSignCounter(connId)
);
}
writeOp = GattWriteCallbackParams::OP_SIGN_WRITE_CMD;
break;
case ATT_PDU_PREP_WRITE_REQ: