mirror of https://github.com/ARMmbed/mbed-os.git
BLE - Devirtualization of the NRF51 port.
parent
b86049d1e7
commit
ddbb177e33
|
|
@ -0,0 +1,88 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2019 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ble/GattServer.h"
|
||||
#include "source/GattServer.tpp"
|
||||
#include "nRF5xGattServer.h"
|
||||
|
||||
#include "ble/GattClient.h"
|
||||
#include "source/GattClient.tpp"
|
||||
#include "ble/generic/GenericGattClient.h"
|
||||
#include "source/generic/GenericGattClient.tpp"
|
||||
#include "nRF5xPalGattClient.h"
|
||||
|
||||
#include "ble/gap/Gap.h"
|
||||
#include "ble/Gap.h"
|
||||
#include "source/gap/Gap.tpp"
|
||||
#include "source/LegacyGap.tpp"
|
||||
#include "nRF5xGap.h"
|
||||
|
||||
#include "ble/SecurityManager.h"
|
||||
#include "source/SecurityManager.tpp"
|
||||
#include "generic/GenericSecurityManager.h"
|
||||
#include "source/generic/GenericSecurityManager.tpp"
|
||||
#include "nRF5xPalSecurityManager.h"
|
||||
#include "nRF5xPalSecurityManager.tpp"
|
||||
#include "nRF5xPalGattClient.tpp"
|
||||
|
||||
#include "DummySigningEventMonitor.h"
|
||||
|
||||
// SECURITY MANAGER
|
||||
|
||||
template class ble::generic::GenericSecurityManager<
|
||||
ble::pal::vendor::nordic::nRF5xSecurityManager,
|
||||
ble::vendor::nordic::DummySigningEventMonitor
|
||||
>;
|
||||
|
||||
template class ::ble::pal::SecurityManager<
|
||||
ble::impl::PalSecurityManagerImpl,
|
||||
ble::impl::GenericSecurityManagerImpl
|
||||
>;
|
||||
|
||||
template class ble::pal::vendor::nordic::nRF5xSecurityManager<
|
||||
ble::generic::GenericSecurityManager<
|
||||
ble::pal::vendor::nordic::nRF5xSecurityManager,
|
||||
ble::vendor::nordic::DummySigningEventMonitor
|
||||
>
|
||||
>;
|
||||
|
||||
template class ble::interface::SecurityManager<
|
||||
ble::impl::GenericSecurityManagerImpl
|
||||
>;
|
||||
|
||||
// GATT CLIENT
|
||||
|
||||
template class ble::generic::GenericGattClient<
|
||||
ble::pal::vendor::nordic::nRF5xGattClient,
|
||||
ble::impl::SigningEventHandler
|
||||
>;
|
||||
|
||||
template class ble::pal::vendor::nordic::nRF5xGattClient<
|
||||
ble::impl::GenericGattClientImpl
|
||||
>;
|
||||
|
||||
template class ble::interface::GattClient<
|
||||
ble::impl::GenericGattClientImpl
|
||||
>;
|
||||
|
||||
// GATT SERVER
|
||||
|
||||
template class ble::interface::GattServer<nRF5xGattServer>;
|
||||
|
||||
// GAP
|
||||
|
||||
// see nRF5xGap.cpp (work around for armcc5)
|
||||
|
||||
|
|
@ -0,0 +1,148 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2019 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef BLE_IMPLEMENTATION_FORWARD_H_
|
||||
#define BLE_IMPLEMENTATION_FORWARD_H_
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Forward declarations of the implementation types
|
||||
//
|
||||
namespace ble {
|
||||
|
||||
namespace interface {
|
||||
|
||||
template<class Impl>
|
||||
class LegacyGap;
|
||||
|
||||
template<class Impl>
|
||||
class Gap;
|
||||
|
||||
template<class Impl>
|
||||
class GattClient;
|
||||
|
||||
template<class Impl>
|
||||
class SecurityManager;
|
||||
|
||||
template<class Impl>
|
||||
class GattServer;
|
||||
|
||||
} // namespace interface
|
||||
|
||||
|
||||
namespace generic {
|
||||
|
||||
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 Impl>
|
||||
class SigningMonitorEventHandler;
|
||||
|
||||
template<class Impl>
|
||||
class ConnectionEventMonitorEventHandler;
|
||||
|
||||
namespace vendor {
|
||||
namespace nordic {
|
||||
|
||||
template <class EventHandler>
|
||||
class nRF5xSecurityManager;
|
||||
|
||||
template<class EventHandler>
|
||||
class nRF5xGattClient;
|
||||
|
||||
} // nordic
|
||||
} // vendor
|
||||
} // pal
|
||||
|
||||
namespace vendor {
|
||||
namespace nordic {
|
||||
|
||||
template<class>
|
||||
class DummySigningEventMonitor;
|
||||
|
||||
} // nordic
|
||||
} // vendor
|
||||
|
||||
|
||||
} // ble
|
||||
|
||||
class nRF5xGap;
|
||||
class nRF5xGattServer;
|
||||
|
||||
// implementation assembly
|
||||
namespace ble {
|
||||
namespace impl {
|
||||
// SECURITY MANAGER
|
||||
typedef generic::GenericSecurityManager<
|
||||
pal::vendor::nordic::nRF5xSecurityManager,
|
||||
vendor::nordic::DummySigningEventMonitor
|
||||
> GenericSecurityManagerImpl;
|
||||
|
||||
typedef interface::SecurityManager<GenericSecurityManagerImpl> SecurityManager;
|
||||
|
||||
typedef GenericSecurityManagerImpl SigningEventHandler;
|
||||
|
||||
typedef GenericSecurityManagerImpl ConnectionEventHandler;
|
||||
|
||||
typedef pal::vendor::nordic::nRF5xSecurityManager<
|
||||
GenericSecurityManagerImpl
|
||||
> PalSecurityManagerImpl;
|
||||
|
||||
typedef ::ble::pal::SecurityManager<
|
||||
PalSecurityManagerImpl,
|
||||
GenericSecurityManagerImpl
|
||||
> PalSecurityManager;
|
||||
|
||||
// GAP
|
||||
typedef interface::LegacyGap<nRF5xGap> LegacyGap;
|
||||
|
||||
typedef interface::Gap<nRF5xGap> Gap;
|
||||
|
||||
// GATT CLIENT
|
||||
|
||||
typedef generic::GenericGattClient<
|
||||
ble::pal::vendor::nordic::nRF5xGattClient,
|
||||
SigningEventHandler
|
||||
> GenericGattClientImpl;
|
||||
|
||||
typedef ble::pal::vendor::nordic::nRF5xGattClient<
|
||||
GenericGattClientImpl
|
||||
> PalGattClient;
|
||||
|
||||
// construct the final GattClient type
|
||||
typedef interface::GattClient<GenericGattClientImpl> GattClient;
|
||||
|
||||
|
||||
// GATT SERVER
|
||||
typedef ble::interface::GattServer<nRF5xGattServer> GattServer;
|
||||
} // impl
|
||||
} // ble
|
||||
|
||||
|
||||
#endif //BLE_IMPLEMENTATION_FORWARD_H_
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
/* 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 NRF5X_DUMMYSIGNINGEVENTMONITOR_H
|
||||
#define NRF5X_DUMMYSIGNINGEVENTMONITOR_H
|
||||
|
||||
#include "ble/pal/SigningEventMonitor.h"
|
||||
|
||||
namespace ble {
|
||||
namespace vendor {
|
||||
namespace nordic {
|
||||
|
||||
template<class Handler>
|
||||
struct DummySigningEventMonitor :
|
||||
public ble::pal::SigningEventMonitor<DummySigningEventMonitor<Handler>, Handler >
|
||||
{
|
||||
void set_signing_event_handler_(Handler *signing_event_handler)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
} // nordic
|
||||
} // vendor
|
||||
} // ble
|
||||
|
||||
|
||||
#endif //NRF5X_DUMMYSIGNINGEVENTMONITOR_H
|
||||
|
|
@ -165,13 +165,14 @@ void btle_handler(ble_evt_t *p_ble_evt)
|
|||
#endif
|
||||
|
||||
#if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110)
|
||||
nRF5xGattClient::handle_events(p_ble_evt);
|
||||
ble::impl::PalGattClient::handle_events(p_ble_evt);
|
||||
#endif
|
||||
|
||||
nRF5xn &ble = nRF5xn::Instance(BLE::DEFAULT_INSTANCE);
|
||||
nRF5xGap &gap = (nRF5xGap &) ble.getGap();
|
||||
nRF5xGattServer &gattServer = (nRF5xGattServer &) ble.getGattServer();
|
||||
nRF5xSecurityManager &securityManager = nRF5xSecurityManager::get_security_manager();
|
||||
ble::impl::PalSecurityManagerImpl &securityManager =
|
||||
ble::impl::PalSecurityManagerImpl::get_security_manager();
|
||||
|
||||
/* Custom event handler */
|
||||
switch (p_ble_evt->header.evt_id) {
|
||||
|
|
@ -208,7 +209,7 @@ void btle_handler(ble_evt_t *p_ble_evt)
|
|||
|
||||
#if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110)
|
||||
// Close all pending discoveries for this connection
|
||||
nRF5xGattClient::handle_connection_termination(handle);
|
||||
ble::impl::PalGattClient::handle_connection_termination(handle);
|
||||
#endif
|
||||
|
||||
gap.processDisconnectionEvent(handle, reason);
|
||||
|
|
|
|||
|
|
@ -27,9 +27,21 @@
|
|||
#include "headers/nrf_ble_hci.h"
|
||||
#include "ble/pal/ConnectionEventMonitor.h"
|
||||
#include "nRF5xPalSecurityManager.h"
|
||||
#include "BleImplementationForward.h"
|
||||
#include <algorithm>
|
||||
|
||||
// ARMCC5 is not able to export static variable of explicitly instantiated class
|
||||
// template if not used immediately. The default privacy configurations are used
|
||||
// in this file so we instantiate here.
|
||||
|
||||
#include "source/gap/Gap.tpp"
|
||||
#include "source/LegacyGap.tpp"
|
||||
|
||||
template class ble::interface::LegacyGap<nRF5xGap>;
|
||||
template class ble::interface::Gap<nRF5xGap>;
|
||||
|
||||
using ble::pal::vendor::nordic::nRF5xSecurityManager;
|
||||
typedef nRF5xSecurityManager::resolving_list_entry_t resolving_list_entry_t;
|
||||
typedef ble::impl::PalSecurityManagerImpl::resolving_list_entry_t resolving_list_entry_t;
|
||||
using ble::ArrayView;
|
||||
using ble::pal::advertising_peer_address_type_t;
|
||||
using ble::peer_address_type_t;
|
||||
|
|
@ -39,8 +51,8 @@ typedef BLEProtocol::AddressType_t LegacyAddressType_t;
|
|||
|
||||
namespace {
|
||||
|
||||
nRF5xSecurityManager& get_sm() {
|
||||
return nRF5xSecurityManager::get_security_manager();
|
||||
ble::impl::PalSecurityManagerImpl& get_sm() {
|
||||
return ble::impl::PalSecurityManagerImpl::get_security_manager();
|
||||
}
|
||||
|
||||
ble_error_t set_private_resolvable_address() {
|
||||
|
|
@ -93,14 +105,13 @@ void radioNotificationStaticCallback(bool param) {
|
|||
gap.processRadioNotificationEvent(param);
|
||||
}
|
||||
|
||||
nRF5xGap::nRF5xGap() : Gap(),
|
||||
advertisingPolicyMode(Gap::ADV_POLICY_IGNORE_WHITELIST),
|
||||
scanningPolicyMode(Gap::SCAN_POLICY_IGNORE_WHITELIST),
|
||||
nRF5xGap::nRF5xGap() :
|
||||
advertisingPolicyMode(ADV_POLICY_IGNORE_WHITELIST),
|
||||
scanningPolicyMode(SCAN_POLICY_IGNORE_WHITELIST),
|
||||
whitelistAddressesSize(0),
|
||||
whitelistAddresses(),
|
||||
radioNotificationCallbackParam(false),
|
||||
radioNotificationTimeout(),
|
||||
_connection_event_handler(NULL),
|
||||
_privacy_enabled(false),
|
||||
_peripheral_privacy_configuration(default_peripheral_privacy_configuration),
|
||||
_central_privacy_configuration(default_central_privacy_configuration),
|
||||
|
|
@ -147,7 +158,7 @@ nRF5xGap::nRF5xGap() : Gap(),
|
|||
@endcode
|
||||
*/
|
||||
/**************************************************************************/
|
||||
ble_error_t nRF5xGap::setAdvertisingData(const GapAdvertisingData &advData, const GapAdvertisingData &scanResponse)
|
||||
ble_error_t nRF5xGap::setAdvertisingData_(const GapAdvertisingData &advData, const GapAdvertisingData &scanResponse)
|
||||
{
|
||||
/* Make sure we don't exceed the advertising payload length */
|
||||
if (advData.getPayloadLen() > GAP_ADVERTISING_DATA_MAX_PAYLOAD) {
|
||||
|
|
@ -212,7 +223,7 @@ ble_error_t nRF5xGap::setAdvertisingData(const GapAdvertisingData &advData, cons
|
|||
@endcode
|
||||
*/
|
||||
/**************************************************************************/
|
||||
ble_error_t nRF5xGap::startAdvertising(const GapAdvertisingParams ¶ms)
|
||||
ble_error_t nRF5xGap::startAdvertising_(const GapAdvertisingParams ¶ms)
|
||||
{
|
||||
uint32_t err;
|
||||
ble_gap_adv_params_t adv_para = {0};
|
||||
|
|
@ -314,7 +325,7 @@ ble_error_t nRF5xGap::startAdvertising(const GapAdvertisingParams ¶ms)
|
|||
|
||||
/* Observer role is not supported by S110, return BLE_ERROR_NOT_IMPLEMENTED */
|
||||
#if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110)
|
||||
ble_error_t nRF5xGap::startRadioScan(const GapScanningParams &scanningParams)
|
||||
ble_error_t nRF5xGap::startRadioScan_(const GapScanningParams &scanningParams)
|
||||
{
|
||||
ble_gap_scan_params_t scanParams;
|
||||
|
||||
|
|
@ -380,7 +391,7 @@ ble_error_t nRF5xGap::startRadioScan(const GapScanningParams &scanningParams)
|
|||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
||||
ble_error_t nRF5xGap::stopScan(void) {
|
||||
ble_error_t nRF5xGap::stopScan_(void) {
|
||||
if (sd_ble_gap_scan_stop() == NRF_SUCCESS) {
|
||||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
|
@ -405,7 +416,7 @@ ble_error_t nRF5xGap::stopScan(void) {
|
|||
@endcode
|
||||
*/
|
||||
/**************************************************************************/
|
||||
ble_error_t nRF5xGap::stopAdvertising(void)
|
||||
ble_error_t nRF5xGap::stopAdvertising_(void)
|
||||
{
|
||||
/* Stop Advertising */
|
||||
ASSERT_TRUE(ERROR_NONE == sd_ble_gap_adv_stop(), BLE_ERROR_PARAM_OUT_OF_RANGE);
|
||||
|
|
@ -415,7 +426,7 @@ ble_error_t nRF5xGap::stopAdvertising(void)
|
|||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
||||
ble_error_t nRF5xGap::connect(
|
||||
ble_error_t nRF5xGap::connect_(
|
||||
const Address_t peerAddr,
|
||||
peer_address_type_t peerAddrType,
|
||||
const ConnectionParams_t *connectionParams,
|
||||
|
|
@ -466,7 +477,7 @@ ble_error_t nRF5xGap::connect(
|
|||
return connect(peerAddr, legacy_address, connectionParams, scanParamsIn, identity);
|
||||
}
|
||||
|
||||
ble_error_t nRF5xGap::connect(
|
||||
ble_error_t nRF5xGap::connect_(
|
||||
const Address_t peerAddr,
|
||||
LegacyAddressType_t peerAddrType,
|
||||
const ConnectionParams_t *connectionParams,
|
||||
|
|
@ -487,7 +498,7 @@ ble_error_t nRF5xGap::connect(
|
|||
ble_gap_addr_t addr;
|
||||
ble_gap_addr_t* addr_ptr = &addr;
|
||||
addr.addr_type = peerAddrType;
|
||||
memcpy(addr.addr, peerAddr, Gap::ADDR_LEN);
|
||||
memcpy(addr.addr, peerAddr, ADDR_LEN);
|
||||
|
||||
ble_gap_conn_params_t connParams;
|
||||
if (connectionParams != NULL) {
|
||||
|
|
@ -593,7 +604,7 @@ ble_error_t nRF5xGap::connect(
|
|||
}
|
||||
}
|
||||
|
||||
ble_error_t nRF5xGap::disconnect(Handle_t connectionHandle, DisconnectionReason_t reason)
|
||||
ble_error_t nRF5xGap::disconnect_(Handle_t connectionHandle, DisconnectionReason_t reason)
|
||||
{
|
||||
uint8_t code = BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION;
|
||||
switch (reason) {
|
||||
|
|
@ -621,12 +632,12 @@ ble_error_t nRF5xGap::disconnect(Handle_t connectionHandle, DisconnectionReason_
|
|||
@retval BLE_ERROR_NONE
|
||||
Everything executed properly
|
||||
*/
|
||||
ble_error_t nRF5xGap::disconnect(DisconnectionReason_t reason)
|
||||
ble_error_t nRF5xGap::disconnect_(DisconnectionReason_t reason)
|
||||
{
|
||||
return disconnect(m_connectionHandle, reason);
|
||||
}
|
||||
|
||||
ble_error_t nRF5xGap::getPreferredConnectionParams(ConnectionParams_t *params)
|
||||
ble_error_t nRF5xGap::getPreferredConnectionParams_(ConnectionParams_t *params)
|
||||
{
|
||||
ASSERT_INT(NRF_SUCCESS,
|
||||
sd_ble_gap_ppcp_get(reinterpret_cast<ble_gap_conn_params_t *>(params)),
|
||||
|
|
@ -635,7 +646,7 @@ ble_error_t nRF5xGap::getPreferredConnectionParams(ConnectionParams_t *params)
|
|||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
||||
ble_error_t nRF5xGap::setPreferredConnectionParams(const ConnectionParams_t *params)
|
||||
ble_error_t nRF5xGap::setPreferredConnectionParams_(const ConnectionParams_t *params)
|
||||
{
|
||||
ASSERT_INT(NRF_SUCCESS,
|
||||
sd_ble_gap_ppcp_set(reinterpret_cast<const ble_gap_conn_params_t *>(params)),
|
||||
|
|
@ -644,7 +655,7 @@ ble_error_t nRF5xGap::setPreferredConnectionParams(const ConnectionParams_t *par
|
|||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
||||
ble_error_t nRF5xGap::updateConnectionParams(Handle_t handle, const ConnectionParams_t *newParams)
|
||||
ble_error_t nRF5xGap::updateConnectionParams_(Handle_t handle, const ConnectionParams_t *newParams)
|
||||
{
|
||||
uint32_t rc;
|
||||
|
||||
|
|
@ -666,10 +677,10 @@ ble_error_t nRF5xGap::updateConnectionParams(Handle_t handle, const ConnectionPa
|
|||
Everything executed properly
|
||||
*/
|
||||
/**************************************************************************/
|
||||
ble_error_t nRF5xGap::reset(void)
|
||||
ble_error_t nRF5xGap::reset_(void)
|
||||
{
|
||||
/* Clear all state that is from the parent, including private members */
|
||||
if (Gap::reset() != BLE_ERROR_NONE) {
|
||||
if (ble::interface::LegacyGap<nRF5xGap>::reset_() != BLE_ERROR_NONE) {
|
||||
return BLE_ERROR_INVALID_STATE;
|
||||
}
|
||||
|
||||
|
|
@ -677,8 +688,8 @@ ble_error_t nRF5xGap::reset(void)
|
|||
m_connectionHandle = BLE_CONN_HANDLE_INVALID;
|
||||
|
||||
/* Set the whitelist policy filter modes to IGNORE_WHITELIST */
|
||||
advertisingPolicyMode = Gap::ADV_POLICY_IGNORE_WHITELIST;
|
||||
scanningPolicyMode = Gap::SCAN_POLICY_IGNORE_WHITELIST;
|
||||
advertisingPolicyMode = ADV_POLICY_IGNORE_WHITELIST;
|
||||
scanningPolicyMode = SCAN_POLICY_IGNORE_WHITELIST;
|
||||
|
||||
/* Clear the internal whitelist */
|
||||
whitelistAddressesSize = 0;
|
||||
|
|
@ -725,7 +736,7 @@ uint16_t nRF5xGap::getConnectionHandle(void)
|
|||
@endcode
|
||||
*/
|
||||
/**************************************************************************/
|
||||
ble_error_t nRF5xGap::setAddress(LegacyAddressType_t type, const Address_t address)
|
||||
ble_error_t nRF5xGap::setAddress_(LegacyAddressType_t type, const Address_t address)
|
||||
{
|
||||
if (type != LegacyAddressType::PUBLIC &&
|
||||
type != LegacyAddressType::RANDOM_STATIC
|
||||
|
|
@ -767,7 +778,7 @@ ble_error_t nRF5xGap::setAddress(LegacyAddressType_t type, const Address_t addre
|
|||
}
|
||||
}
|
||||
|
||||
ble_error_t nRF5xGap::getAddress(AddressType_t *typeP, Address_t address)
|
||||
ble_error_t nRF5xGap::getAddress_(AddressType_t *typeP, Address_t address)
|
||||
{
|
||||
if (typeP == NULL || address == NULL) {
|
||||
return BLE_ERROR_INVALID_PARAM;
|
||||
|
|
@ -800,7 +811,7 @@ ble_error_t nRF5xGap::getAddress(AddressType_t *typeP, Address_t address)
|
|||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
||||
ble_error_t nRF5xGap::setDeviceName(const uint8_t *deviceName)
|
||||
ble_error_t nRF5xGap::setDeviceName_(const uint8_t *deviceName)
|
||||
{
|
||||
ble_gap_conn_sec_mode_t sec_mode;
|
||||
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode); // no security is needed
|
||||
|
|
@ -812,7 +823,7 @@ ble_error_t nRF5xGap::setDeviceName(const uint8_t *deviceName)
|
|||
}
|
||||
}
|
||||
|
||||
ble_error_t nRF5xGap::getDeviceName(uint8_t *deviceName, unsigned *lengthP)
|
||||
ble_error_t nRF5xGap::getDeviceName_(uint8_t *deviceName, unsigned *lengthP)
|
||||
{
|
||||
if (sd_ble_gap_device_name_get(deviceName, (uint16_t *)lengthP) == NRF_SUCCESS) {
|
||||
return BLE_ERROR_NONE;
|
||||
|
|
@ -821,7 +832,7 @@ ble_error_t nRF5xGap::getDeviceName(uint8_t *deviceName, unsigned *lengthP)
|
|||
}
|
||||
}
|
||||
|
||||
ble_error_t nRF5xGap::setAppearance(GapAdvertisingData::Appearance appearance)
|
||||
ble_error_t nRF5xGap::setAppearance_(GapAdvertisingData::Appearance appearance)
|
||||
{
|
||||
if (sd_ble_gap_appearance_set(appearance) == NRF_SUCCESS) {
|
||||
return BLE_ERROR_NONE;
|
||||
|
|
@ -830,7 +841,7 @@ ble_error_t nRF5xGap::setAppearance(GapAdvertisingData::Appearance appearance)
|
|||
}
|
||||
}
|
||||
|
||||
ble_error_t nRF5xGap::getAppearance(GapAdvertisingData::Appearance *appearanceP)
|
||||
ble_error_t nRF5xGap::getAppearance_(GapAdvertisingData::Appearance *appearanceP)
|
||||
{
|
||||
if ((sd_ble_gap_appearance_get(reinterpret_cast<uint16_t *>(appearanceP)) == NRF_SUCCESS)) {
|
||||
return BLE_ERROR_NONE;
|
||||
|
|
@ -840,7 +851,7 @@ ble_error_t nRF5xGap::getAppearance(GapAdvertisingData::Appearance *appearanceP)
|
|||
}
|
||||
|
||||
/* (Valid values are -40, -20, -16, -12, -8, -4, 0, 4) */
|
||||
ble_error_t nRF5xGap::setTxPower(int8_t txPower)
|
||||
ble_error_t nRF5xGap::setTxPower_(int8_t txPower)
|
||||
{
|
||||
unsigned rc;
|
||||
if ((rc = sd_ble_gap_tx_power_set(txPower)) != NRF_SUCCESS) {
|
||||
|
|
@ -856,7 +867,7 @@ ble_error_t nRF5xGap::setTxPower(int8_t txPower)
|
|||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
||||
void nRF5xGap::getPermittedTxPowerValues(const int8_t **valueArrayPP, size_t *countP)
|
||||
void nRF5xGap::getPermittedTxPowerValues_(const int8_t **valueArrayPP, size_t *countP)
|
||||
{
|
||||
#if defined(NRF51)
|
||||
static const int8_t permittedTxValues[] = {
|
||||
|
|
@ -892,7 +903,7 @@ void nRF5xGap::getPermittedTxPowerValues(const int8_t **valueArrayPP, size_t *co
|
|||
@endcode
|
||||
*/
|
||||
/**************************************************************************/
|
||||
uint8_t nRF5xGap::getMaxWhitelistSize(void) const
|
||||
uint8_t nRF5xGap::getMaxWhitelistSize_(void) const
|
||||
{
|
||||
return YOTTA_CFG_WHITELIST_MAX_SIZE;
|
||||
}
|
||||
|
|
@ -917,7 +928,7 @@ uint8_t nRF5xGap::getMaxWhitelistSize(void) const
|
|||
@endcode
|
||||
*/
|
||||
/**************************************************************************/
|
||||
ble_error_t nRF5xGap::getWhitelist(Gap::Whitelist_t &whitelistOut) const
|
||||
ble_error_t nRF5xGap::getWhitelist_(Whitelist_t &whitelistOut) const
|
||||
{
|
||||
uint32_t i;
|
||||
for (i = 0; i < whitelistAddressesSize && i < whitelistOut.capacity; ++i) {
|
||||
|
|
@ -959,7 +970,7 @@ ble_error_t nRF5xGap::getWhitelist(Gap::Whitelist_t &whitelistOut) const
|
|||
@endcode
|
||||
*/
|
||||
/**************************************************************************/
|
||||
ble_error_t nRF5xGap::setWhitelist(const Gap::Whitelist_t &whitelistIn)
|
||||
ble_error_t nRF5xGap::setWhitelist_(const Whitelist_t &whitelistIn)
|
||||
{
|
||||
if (whitelistIn.size > getMaxWhitelistSize()) {
|
||||
return BLE_ERROR_PARAM_OUT_OF_RANGE;
|
||||
|
|
@ -1009,7 +1020,7 @@ ble_error_t nRF5xGap::setWhitelist(const Gap::Whitelist_t &whitelistIn)
|
|||
@endcode
|
||||
*/
|
||||
/**************************************************************************/
|
||||
ble_error_t nRF5xGap::setAdvertisingPolicyMode(Gap::AdvertisingPolicyMode_t mode)
|
||||
ble_error_t nRF5xGap::setAdvertisingPolicyMode_(AdvertisingPolicyMode_t mode)
|
||||
{
|
||||
advertisingPolicyMode = mode;
|
||||
|
||||
|
|
@ -1036,7 +1047,7 @@ ble_error_t nRF5xGap::setAdvertisingPolicyMode(Gap::AdvertisingPolicyMode_t mode
|
|||
@endcode
|
||||
*/
|
||||
/**************************************************************************/
|
||||
ble_error_t nRF5xGap::setScanningPolicyMode(Gap::ScanningPolicyMode_t mode)
|
||||
ble_error_t nRF5xGap::setScanningPolicyMode_(ScanningPolicyMode_t mode)
|
||||
{
|
||||
scanningPolicyMode = mode;
|
||||
|
||||
|
|
@ -1063,7 +1074,7 @@ ble_error_t nRF5xGap::setScanningPolicyMode(Gap::ScanningPolicyMode_t mode)
|
|||
@endcode
|
||||
*/
|
||||
/**************************************************************************/
|
||||
ble_error_t nRF5xGap::setInitiatorPolicyMode(Gap::InitiatorPolicyMode_t mode)
|
||||
ble_error_t nRF5xGap::setInitiatorPolicyMode_(InitiatorPolicyMode_t mode)
|
||||
{
|
||||
return BLE_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
|
@ -1081,7 +1092,7 @@ ble_error_t nRF5xGap::setInitiatorPolicyMode(Gap::InitiatorPolicyMode_t mode)
|
|||
@endcode
|
||||
*/
|
||||
/**************************************************************************/
|
||||
Gap::AdvertisingPolicyMode_t nRF5xGap::getAdvertisingPolicyMode(void) const
|
||||
Gap::AdvertisingPolicyMode_t nRF5xGap::getAdvertisingPolicyMode_(void) const
|
||||
{
|
||||
return advertisingPolicyMode;
|
||||
}
|
||||
|
|
@ -1099,7 +1110,7 @@ Gap::AdvertisingPolicyMode_t nRF5xGap::getAdvertisingPolicyMode(void) const
|
|||
@endcode
|
||||
*/
|
||||
/**************************************************************************/
|
||||
Gap::ScanningPolicyMode_t nRF5xGap::getScanningPolicyMode(void) const
|
||||
Gap::ScanningPolicyMode_t nRF5xGap::getScanningPolicyMode_(void) const
|
||||
{
|
||||
return scanningPolicyMode;
|
||||
}
|
||||
|
|
@ -1120,12 +1131,12 @@ Gap::ScanningPolicyMode_t nRF5xGap::getScanningPolicyMode(void) const
|
|||
@endcode
|
||||
*/
|
||||
/**************************************************************************/
|
||||
Gap::InitiatorPolicyMode_t nRF5xGap::getInitiatorPolicyMode(void) const
|
||||
Gap::InitiatorPolicyMode_t nRF5xGap::getInitiatorPolicyMode_(void) const
|
||||
{
|
||||
return Gap::INIT_POLICY_IGNORE_WHITELIST;
|
||||
return INIT_POLICY_IGNORE_WHITELIST;
|
||||
}
|
||||
|
||||
ble_error_t nRF5xGap::enablePrivacy(bool enable_privacy)
|
||||
ble_error_t nRF5xGap::enablePrivacy_(bool enable_privacy)
|
||||
{
|
||||
if (enable_privacy == _privacy_enabled) {
|
||||
return BLE_ERROR_NONE;
|
||||
|
|
@ -1160,40 +1171,34 @@ ble_error_t nRF5xGap::enablePrivacy(bool enable_privacy)
|
|||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
||||
ble_error_t nRF5xGap::setPeripheralPrivacyConfiguration(
|
||||
ble_error_t nRF5xGap::setPeripheralPrivacyConfiguration_(
|
||||
const PeripheralPrivacyConfiguration_t *configuration
|
||||
) {
|
||||
_peripheral_privacy_configuration = *configuration;
|
||||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
||||
ble_error_t nRF5xGap::getPeripheralPrivacyConfiguration(
|
||||
ble_error_t nRF5xGap::getPeripheralPrivacyConfiguration_(
|
||||
PeripheralPrivacyConfiguration_t *configuration
|
||||
) {
|
||||
*configuration = _peripheral_privacy_configuration;
|
||||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
||||
ble_error_t nRF5xGap::setCentralPrivacyConfiguration(
|
||||
ble_error_t nRF5xGap::setCentralPrivacyConfiguration_(
|
||||
const CentralPrivacyConfiguration_t *configuration
|
||||
) {
|
||||
_central_privacy_configuration = *configuration;
|
||||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
||||
ble_error_t nRF5xGap::getCentralPrivacyConfiguration(
|
||||
ble_error_t nRF5xGap::getCentralPrivacyConfiguration_(
|
||||
CentralPrivacyConfiguration_t *configuration
|
||||
) {
|
||||
*configuration = _central_privacy_configuration;
|
||||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
||||
void nRF5xGap::set_connection_event_handler(
|
||||
ConnectionEventMonitor::EventHandler* connection_event_handler
|
||||
) {
|
||||
_connection_event_handler = connection_event_handler;
|
||||
}
|
||||
|
||||
void nRF5xGap::processDisconnectionEvent(
|
||||
Handle_t handle,
|
||||
DisconnectionReason_t reason
|
||||
|
|
@ -1213,7 +1218,7 @@ void nRF5xGap::processDisconnectionEvent(
|
|||
);
|
||||
}
|
||||
|
||||
void nRF5xGap::on_connection(Gap::Handle_t handle, const ble_gap_evt_connected_t& evt) {
|
||||
void nRF5xGap::on_connection(Handle_t handle, const ble_gap_evt_connected_t& evt) {
|
||||
using BLEProtocol::AddressType;
|
||||
|
||||
// set the new connection handle as the _default_ handle in gap
|
||||
|
|
@ -1403,7 +1408,7 @@ void nRF5xGap::allocate_connection_role(
|
|||
connection_role_t& c = _connections_role[i];
|
||||
if (c.is_allocated == false) {
|
||||
c.connection = connection;
|
||||
c.is_peripheral = (role == Gap::PERIPHERAL);
|
||||
c.is_peripheral = (role == PERIPHERAL);
|
||||
c.is_allocated = true;
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@
|
|||
#ifndef __NRF5x_GAP_H__
|
||||
#define __NRF5x_GAP_H__
|
||||
|
||||
#include "ble/Gap.h"
|
||||
|
||||
#ifdef YOTTA_CFG_MBED_OS
|
||||
#include "mbed-drivers/mbed.h"
|
||||
#else
|
||||
|
|
@ -61,62 +63,71 @@ void radioNotificationStaticCallback(bool param);
|
|||
|
||||
*/
|
||||
/**************************************************************************/
|
||||
class nRF5xGap : public ::Gap, public ble::pal::ConnectionEventMonitor {
|
||||
class nRF5xGap :
|
||||
public ble::interface::LegacyGap<nRF5xGap>,
|
||||
public ble::pal::ConnectionEventMonitor<ble::impl::ConnectionEventHandler> {
|
||||
|
||||
public:
|
||||
nRF5xGap();
|
||||
|
||||
virtual ~nRF5xGap() { }
|
||||
~nRF5xGap() { }
|
||||
|
||||
/* Functions that must be implemented from Gap */
|
||||
virtual ble_error_t setAddress(AddressType_t type, const Address_t address);
|
||||
virtual ble_error_t getAddress(AddressType_t *typeP, Address_t address);
|
||||
virtual ble_error_t setAdvertisingData(const GapAdvertisingData &, const GapAdvertisingData &);
|
||||
ble_error_t setAddress_(AddressType_t type, const Address_t address);
|
||||
ble_error_t getAddress_(AddressType_t *typeP, Address_t address);
|
||||
ble_error_t setAdvertisingData_(const GapAdvertisingData &, const GapAdvertisingData &);
|
||||
|
||||
virtual uint16_t getMinAdvertisingInterval(void) const {return GapAdvertisingParams::ADVERTISEMENT_DURATION_UNITS_TO_MS(BLE_GAP_ADV_INTERVAL_MIN);}
|
||||
virtual uint16_t getMinNonConnectableAdvertisingInterval(void) const {return GapAdvertisingParams::ADVERTISEMENT_DURATION_UNITS_TO_MS(BLE_GAP_ADV_NONCON_INTERVAL_MIN);}
|
||||
virtual uint16_t getMaxAdvertisingInterval(void) const {return GapAdvertisingParams::ADVERTISEMENT_DURATION_UNITS_TO_MS(BLE_GAP_ADV_INTERVAL_MAX);}
|
||||
uint16_t getMinAdvertisingInterval_(void) const {
|
||||
return GapAdvertisingParams::ADVERTISEMENT_DURATION_UNITS_TO_MS(BLE_GAP_ADV_INTERVAL_MIN);
|
||||
}
|
||||
uint16_t getMinNonConnectableAdvertisingInterval_(void) const {
|
||||
return GapAdvertisingParams::ADVERTISEMENT_DURATION_UNITS_TO_MS(BLE_GAP_ADV_NONCON_INTERVAL_MIN);
|
||||
}
|
||||
uint16_t getMaxAdvertisingInterval_(void) const {
|
||||
return GapAdvertisingParams::ADVERTISEMENT_DURATION_UNITS_TO_MS(BLE_GAP_ADV_INTERVAL_MAX);
|
||||
}
|
||||
|
||||
virtual ble_error_t startAdvertising(const GapAdvertisingParams &);
|
||||
virtual ble_error_t stopAdvertising(void);
|
||||
virtual ble_error_t connect(const Address_t, ble::peer_address_type_t peerAddrType, const ConnectionParams_t *connectionParams, const GapScanningParams *scanParams);
|
||||
virtual ble_error_t connect(const Address_t, BLEProtocol::AddressType_t peerAddrType, const ConnectionParams_t *connectionParams, const GapScanningParams *scanParams);
|
||||
ble_error_t connect(const Address_t, BLEProtocol::AddressType_t peerAddrType, const ConnectionParams_t *connectionParams, const GapScanningParams *scanParams, bool identity);
|
||||
virtual ble_error_t disconnect(Handle_t connectionHandle, DisconnectionReason_t reason);
|
||||
virtual ble_error_t disconnect(DisconnectionReason_t reason);
|
||||
ble_error_t startAdvertising_(const GapAdvertisingParams &);
|
||||
ble_error_t stopAdvertising_(void);
|
||||
ble_error_t connect_(const Address_t, ble::peer_address_type_t peerAddrType, const ConnectionParams_t *connectionParams, const GapScanningParams *scanParams);
|
||||
ble_error_t connect_(const Address_t, BLEProtocol::AddressType_t peerAddrType, const ConnectionParams_t *connectionParams, const GapScanningParams *scanParams);
|
||||
/* non virtual */ ble_error_t connect(const Address_t, BLEProtocol::AddressType_t peerAddrType, const ConnectionParams_t *connectionParams, const GapScanningParams *scanParams, bool identity);
|
||||
ble_error_t disconnect_(Handle_t connectionHandle, DisconnectionReason_t reason);
|
||||
ble_error_t disconnect_(DisconnectionReason_t reason);
|
||||
|
||||
virtual ble_error_t setDeviceName(const uint8_t *deviceName);
|
||||
virtual ble_error_t getDeviceName(uint8_t *deviceName, unsigned *lengthP);
|
||||
virtual ble_error_t setAppearance(GapAdvertisingData::Appearance appearance);
|
||||
virtual ble_error_t getAppearance(GapAdvertisingData::Appearance *appearanceP);
|
||||
ble_error_t setDeviceName_(const uint8_t *deviceName);
|
||||
ble_error_t getDeviceName_(uint8_t *deviceName, unsigned *lengthP);
|
||||
ble_error_t setAppearance_(GapAdvertisingData::Appearance appearance);
|
||||
ble_error_t getAppearance_(GapAdvertisingData::Appearance *appearanceP);
|
||||
|
||||
virtual ble_error_t setTxPower(int8_t txPower);
|
||||
virtual void getPermittedTxPowerValues(const int8_t **valueArrayPP, size_t *countP);
|
||||
ble_error_t setTxPower_(int8_t txPower);
|
||||
void getPermittedTxPowerValues_(const int8_t **valueArrayPP, size_t *countP);
|
||||
|
||||
void setConnectionHandle(uint16_t con_handle);
|
||||
uint16_t getConnectionHandle(void);
|
||||
|
||||
virtual ble_error_t getPreferredConnectionParams(ConnectionParams_t *params);
|
||||
virtual ble_error_t setPreferredConnectionParams(const ConnectionParams_t *params);
|
||||
virtual ble_error_t updateConnectionParams(Handle_t handle, const ConnectionParams_t *params);
|
||||
ble_error_t getPreferredConnectionParams_(ConnectionParams_t *params);
|
||||
ble_error_t setPreferredConnectionParams_(const ConnectionParams_t *params);
|
||||
ble_error_t updateConnectionParams_(Handle_t handle, const ConnectionParams_t *params);
|
||||
|
||||
virtual ble_error_t reset(void);
|
||||
ble_error_t reset_(void);
|
||||
|
||||
/*
|
||||
* The following functions are part of the whitelisting experimental API.
|
||||
* Therefore, this functionality can change in the near future.
|
||||
*/
|
||||
virtual uint8_t getMaxWhitelistSize(void) const;
|
||||
virtual ble_error_t getWhitelist(Gap::Whitelist_t &whitelistOut) const;
|
||||
virtual ble_error_t setWhitelist(const Gap::Whitelist_t &whitelistIn);
|
||||
uint8_t getMaxWhitelistSize_(void) const;
|
||||
ble_error_t getWhitelist_(Whitelist_t &whitelistOut) const;
|
||||
ble_error_t setWhitelist_(const Whitelist_t &whitelistIn);
|
||||
|
||||
virtual ble_error_t setAdvertisingPolicyMode(AdvertisingPolicyMode_t mode);
|
||||
virtual ble_error_t setScanningPolicyMode(ScanningPolicyMode_t mode);
|
||||
virtual ble_error_t setInitiatorPolicyMode(InitiatorPolicyMode_t mode);
|
||||
virtual Gap::AdvertisingPolicyMode_t getAdvertisingPolicyMode(void) const;
|
||||
virtual Gap::ScanningPolicyMode_t getScanningPolicyMode(void) const;
|
||||
virtual Gap::InitiatorPolicyMode_t getInitiatorPolicyMode(void) const;
|
||||
ble_error_t setAdvertisingPolicyMode_(AdvertisingPolicyMode_t mode);
|
||||
ble_error_t setScanningPolicyMode_(ScanningPolicyMode_t mode);
|
||||
ble_error_t setInitiatorPolicyMode_(InitiatorPolicyMode_t mode);
|
||||
AdvertisingPolicyMode_t getAdvertisingPolicyMode_(void) const;
|
||||
ScanningPolicyMode_t getScanningPolicyMode_(void) const;
|
||||
InitiatorPolicyMode_t getInitiatorPolicyMode_(void) const;
|
||||
|
||||
virtual ble_error_t initRadioNotification(void) {
|
||||
ble_error_t initRadioNotification_(void) {
|
||||
if (ble_radio_notification_init(APP_IRQ_PRIORITY_HIGH /*MID*/, NRF_RADIO_NOTIFICATION_DISTANCE_800US, radioNotificationStaticCallback) == NRF_SUCCESS) {
|
||||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
|
@ -124,28 +135,28 @@ public:
|
|||
return BLE_ERROR_UNSPECIFIED;
|
||||
}
|
||||
|
||||
virtual ble_error_t enablePrivacy(bool enable);
|
||||
ble_error_t enablePrivacy_(bool enable);
|
||||
|
||||
virtual ble_error_t setPeripheralPrivacyConfiguration(
|
||||
ble_error_t setPeripheralPrivacyConfiguration_(
|
||||
const PeripheralPrivacyConfiguration_t *configuration
|
||||
);
|
||||
|
||||
virtual ble_error_t getPeripheralPrivacyConfiguration(
|
||||
ble_error_t getPeripheralPrivacyConfiguration_(
|
||||
PeripheralPrivacyConfiguration_t *configuration
|
||||
);
|
||||
|
||||
virtual ble_error_t setCentralPrivacyConfiguration(
|
||||
ble_error_t setCentralPrivacyConfiguration_(
|
||||
const CentralPrivacyConfiguration_t *configuration
|
||||
);
|
||||
|
||||
virtual ble_error_t getCentralPrivacyConfiguration(
|
||||
ble_error_t getCentralPrivacyConfiguration_(
|
||||
CentralPrivacyConfiguration_t *configuration
|
||||
);
|
||||
|
||||
/* Observer role is not supported by S110, return BLE_ERROR_NOT_IMPLEMENTED */
|
||||
#if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110)
|
||||
virtual ble_error_t startRadioScan(const GapScanningParams &scanningParams);
|
||||
virtual ble_error_t stopScan(void);
|
||||
ble_error_t startRadioScan_(const GapScanningParams &scanningParams);
|
||||
ble_error_t stopScan_(void);
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
|
@ -154,8 +165,8 @@ private:
|
|||
*/
|
||||
|
||||
/* Policy modes set by the user. By default these are set to ignore the whitelist */
|
||||
Gap::AdvertisingPolicyMode_t advertisingPolicyMode;
|
||||
Gap::ScanningPolicyMode_t scanningPolicyMode;
|
||||
AdvertisingPolicyMode_t advertisingPolicyMode;
|
||||
ScanningPolicyMode_t scanningPolicyMode;
|
||||
|
||||
/* Internal representation of a whitelist */
|
||||
uint8_t whitelistAddressesSize;
|
||||
|
|
@ -244,13 +255,6 @@ private:
|
|||
friend void radioNotificationStaticCallback(bool param); /* allow invocations of processRadioNotificationEvent() */
|
||||
|
||||
public:
|
||||
/** @note Implements ConnectionEventMonitor.
|
||||
* @copydoc ConnectionEventMonitor::set_connection_event_handler
|
||||
*/
|
||||
virtual void set_connection_event_handler(
|
||||
ConnectionEventMonitor::EventHandler* connection_event_handler
|
||||
);
|
||||
|
||||
/**
|
||||
* @copydoc ::Gap::processDisconnectionEvent
|
||||
*/
|
||||
|
|
@ -269,6 +273,15 @@ public:
|
|||
*/
|
||||
ble_error_t get_role(ble::connection_handle_t connection, Role_t& role);
|
||||
|
||||
protected:
|
||||
// import from Gap
|
||||
friend ble::interface::Gap<nRF5xGap>;
|
||||
|
||||
using ble::interface::Gap<nRF5xGap>::startAdvertising_;
|
||||
using ble::interface::Gap<nRF5xGap>::stopAdvertising_;
|
||||
using ble::interface::Gap<nRF5xGap>::connect_;
|
||||
using ble::interface::Gap<nRF5xGap>::disconnect_;
|
||||
|
||||
private:
|
||||
friend void btle_handler(ble_evt_t *p_ble_evt);
|
||||
|
||||
|
|
@ -281,8 +294,6 @@ private:
|
|||
|
||||
uint16_t m_connectionHandle;
|
||||
|
||||
ConnectionEventMonitor::EventHandler* _connection_event_handler;
|
||||
|
||||
bool _privacy_enabled;
|
||||
PeripheralPrivacyConfiguration_t _peripheral_privacy_configuration;
|
||||
CentralPrivacyConfiguration_t _central_privacy_configuration;
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ static ble_error_t set_attribute_value(
|
|||
@endcode
|
||||
*/
|
||||
/**************************************************************************/
|
||||
ble_error_t nRF5xGattServer::addService(GattService &service)
|
||||
ble_error_t nRF5xGattServer::addService_(GattService &service)
|
||||
{
|
||||
/* ToDo: Make sure this service UUID doesn't already exist (?) */
|
||||
/* ToDo: Basic validation */
|
||||
|
|
@ -259,12 +259,12 @@ ble_error_t nRF5xGattServer::addService(GattService &service)
|
|||
Everything executed properly
|
||||
*/
|
||||
/**************************************************************************/
|
||||
ble_error_t nRF5xGattServer::read(GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP)
|
||||
ble_error_t nRF5xGattServer::read_(GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP)
|
||||
{
|
||||
return read(BLE_CONN_HANDLE_INVALID, attributeHandle, buffer, lengthP);
|
||||
}
|
||||
|
||||
ble_error_t nRF5xGattServer::read(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP)
|
||||
ble_error_t nRF5xGattServer::read_(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP)
|
||||
{
|
||||
ble_gatts_value_t value = {
|
||||
/* .len = */ *lengthP,
|
||||
|
|
@ -299,12 +299,12 @@ ble_error_t nRF5xGattServer::read(Gap::Handle_t connectionHandle, GattAttribute:
|
|||
Everything executed properly
|
||||
*/
|
||||
/**************************************************************************/
|
||||
ble_error_t nRF5xGattServer::write(GattAttribute::Handle_t attributeHandle, const uint8_t buffer[], uint16_t len, bool localOnly)
|
||||
ble_error_t nRF5xGattServer::write_(GattAttribute::Handle_t attributeHandle, const uint8_t buffer[], uint16_t len, bool localOnly)
|
||||
{
|
||||
return write(BLE_CONN_HANDLE_INVALID, attributeHandle, buffer, len, localOnly);
|
||||
}
|
||||
|
||||
ble_error_t nRF5xGattServer::write(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, const uint8_t buffer[], uint16_t len, bool localOnly)
|
||||
ble_error_t nRF5xGattServer::write_(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, const uint8_t buffer[], uint16_t len, bool localOnly)
|
||||
{
|
||||
ble_error_t returnValue = BLE_ERROR_NONE;
|
||||
|
||||
|
|
@ -396,14 +396,14 @@ ble_error_t nRF5xGattServer::write(Gap::Handle_t connectionHandle, GattAttribute
|
|||
return returnValue;
|
||||
}
|
||||
|
||||
ble_error_t nRF5xGattServer::areUpdatesEnabled(const GattCharacteristic &characteristic, bool *enabledP)
|
||||
ble_error_t nRF5xGattServer::areUpdatesEnabled_(const GattCharacteristic &characteristic, bool *enabledP)
|
||||
{
|
||||
/* Forward the call with the default connection handle. */
|
||||
nRF5xGap &gap = (nRF5xGap &) nRF5xn::Instance(BLE::DEFAULT_INSTANCE).getGap();
|
||||
return areUpdatesEnabled(gap.getConnectionHandle(), characteristic, enabledP);
|
||||
return areUpdatesEnabled_(gap.getConnectionHandle(), characteristic, enabledP);
|
||||
}
|
||||
|
||||
ble_error_t nRF5xGattServer::areUpdatesEnabled(Gap::Handle_t connectionHandle, const GattCharacteristic &characteristic, bool *enabledP)
|
||||
ble_error_t nRF5xGattServer::areUpdatesEnabled_(Gap::Handle_t connectionHandle, const GattCharacteristic &characteristic, bool *enabledP)
|
||||
{
|
||||
return areUpdatesEnabled(connectionHandle, characteristic.getValueHandle(), enabledP);
|
||||
}
|
||||
|
|
@ -445,10 +445,10 @@ ble_error_t nRF5xGattServer::areUpdatesEnabled(Gap::Handle_t connectionHandle, G
|
|||
Everything executed properly
|
||||
*/
|
||||
/**************************************************************************/
|
||||
ble_error_t nRF5xGattServer::reset(void)
|
||||
ble_error_t nRF5xGattServer::reset_(void)
|
||||
{
|
||||
/* Clear all state that is from the parent, including private members */
|
||||
if (GattServer::reset() != BLE_ERROR_NONE) {
|
||||
if (ble::interface::GattServer<nRF5xGattServer>::reset_() != BLE_ERROR_NONE) {
|
||||
return BLE_ERROR_INVALID_STATE;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,18 +24,18 @@
|
|||
#include "ble/Gap.h"
|
||||
#include "ble/GattServer.h"
|
||||
|
||||
class nRF5xGattServer : public GattServer
|
||||
class nRF5xGattServer : public ble::interface::GattServer<nRF5xGattServer>
|
||||
{
|
||||
public:
|
||||
/* Functions that must be implemented from GattServer */
|
||||
virtual ble_error_t addService(GattService &);
|
||||
virtual ble_error_t read(GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP);
|
||||
virtual ble_error_t read(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP);
|
||||
virtual ble_error_t write(GattAttribute::Handle_t, const uint8_t[], uint16_t, bool localOnly = false);
|
||||
virtual ble_error_t write(Gap::Handle_t connectionHandle, GattAttribute::Handle_t, const uint8_t[], uint16_t, bool localOnly = false);
|
||||
virtual ble_error_t areUpdatesEnabled(const GattCharacteristic &characteristic, bool *enabledP);
|
||||
virtual ble_error_t areUpdatesEnabled(Gap::Handle_t connectionHandle, const GattCharacteristic &characteristic, bool *enabledP);
|
||||
virtual ble_error_t reset(void);
|
||||
ble_error_t addService_(GattService &);
|
||||
ble_error_t read_(GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP);
|
||||
ble_error_t read_(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP);
|
||||
ble_error_t write_(GattAttribute::Handle_t, const uint8_t[], uint16_t, bool localOnly = false);
|
||||
ble_error_t write_(Gap::Handle_t connectionHandle, GattAttribute::Handle_t, const uint8_t[], uint16_t, bool localOnly = false);
|
||||
ble_error_t areUpdatesEnabled_(const GattCharacteristic &characteristic, bool *enabledP);
|
||||
ble_error_t areUpdatesEnabled_(Gap::Handle_t connectionHandle, const GattCharacteristic &characteristic, bool *enabledP);
|
||||
ble_error_t reset_(void);
|
||||
|
||||
/* nRF51 Functions */
|
||||
void eventCallback(void);
|
||||
|
|
|
|||
|
|
@ -34,39 +34,40 @@ namespace nordic {
|
|||
/**
|
||||
* Implementation of pal::GattClient for the Nordic stack.
|
||||
*/
|
||||
class nRF5xGattClient : public ble::pal::GattClient {
|
||||
template<class EventHandler>
|
||||
class nRF5xGattClient : public ble::pal::GattClient<nRF5xGattClient<EventHandler>, EventHandler> {
|
||||
|
||||
public:
|
||||
nRF5xGattClient();
|
||||
|
||||
virtual ~nRF5xGattClient();
|
||||
~nRF5xGattClient();
|
||||
|
||||
/**
|
||||
* see pal::GattClient::initialize .
|
||||
*/
|
||||
virtual ble_error_t initialize();
|
||||
ble_error_t initialize_();
|
||||
|
||||
/**
|
||||
* see pal::GattClient::terminate .
|
||||
*/
|
||||
virtual ble_error_t terminate();
|
||||
ble_error_t terminate_();
|
||||
|
||||
/**
|
||||
* see pal::GattClient::exchange_mtu .
|
||||
*/
|
||||
virtual ble_error_t exchange_mtu(connection_handle_t connection);
|
||||
ble_error_t exchange_mtu_(connection_handle_t connection);
|
||||
|
||||
/**
|
||||
* see pal::GattClient::get_mtu_size .
|
||||
*/
|
||||
virtual ble_error_t get_mtu_size(
|
||||
ble_error_t get_mtu_size_(
|
||||
connection_handle_t connection_handle, uint16_t& mtu_size
|
||||
);
|
||||
|
||||
/**
|
||||
* see pal::GattClient::discover_primary_service .
|
||||
*/
|
||||
virtual ble_error_t discover_primary_service(
|
||||
ble_error_t discover_primary_service_(
|
||||
connection_handle_t connection,
|
||||
attribute_handle_t discovery_range_begining
|
||||
);
|
||||
|
|
@ -74,7 +75,7 @@ public:
|
|||
/**
|
||||
* see pal::GattClient::discover_primary_service_by_service_uuid .
|
||||
*/
|
||||
virtual ble_error_t discover_primary_service_by_service_uuid(
|
||||
ble_error_t discover_primary_service_by_service_uuid_(
|
||||
connection_handle_t connection_handle,
|
||||
attribute_handle_t discovery_range_beginning,
|
||||
const UUID& uuid
|
||||
|
|
@ -83,7 +84,7 @@ public:
|
|||
/**
|
||||
* see pal::GattClient::find_included_service .
|
||||
*/
|
||||
virtual ble_error_t find_included_service(
|
||||
ble_error_t find_included_service_(
|
||||
connection_handle_t connection_handle,
|
||||
attribute_handle_range_t service_range
|
||||
);
|
||||
|
|
@ -91,7 +92,7 @@ public:
|
|||
/**
|
||||
* see pal::GattClient::discover_characteristics_of_a_service .
|
||||
*/
|
||||
virtual ble_error_t discover_characteristics_of_a_service(
|
||||
ble_error_t discover_characteristics_of_a_service_(
|
||||
connection_handle_t connection_handle,
|
||||
attribute_handle_range_t discovery_range
|
||||
);
|
||||
|
|
@ -99,7 +100,7 @@ public:
|
|||
/**
|
||||
* see pal::GattClient::discover_characteristics_descriptors .
|
||||
*/
|
||||
virtual ble_error_t discover_characteristics_descriptors(
|
||||
ble_error_t discover_characteristics_descriptors_(
|
||||
connection_handle_t connection_handle,
|
||||
attribute_handle_range_t descriptors_discovery_range
|
||||
);
|
||||
|
|
@ -107,7 +108,7 @@ public:
|
|||
/**
|
||||
* see pal::GattClient::read_attribute_value .
|
||||
*/
|
||||
virtual ble_error_t read_attribute_value(
|
||||
ble_error_t read_attribute_value_(
|
||||
connection_handle_t connection_handle,
|
||||
attribute_handle_t attribute_handle
|
||||
);
|
||||
|
|
@ -115,7 +116,7 @@ public:
|
|||
/**
|
||||
* see pal::GattClient::read_using_characteristic_uuid .
|
||||
*/
|
||||
virtual ble_error_t read_using_characteristic_uuid(
|
||||
ble_error_t read_using_characteristic_uuid_(
|
||||
connection_handle_t connection_handle,
|
||||
attribute_handle_range_t read_range,
|
||||
const UUID& uuid
|
||||
|
|
@ -124,7 +125,7 @@ public:
|
|||
/**
|
||||
* see pal::GattClient::read_attribute_blob .
|
||||
*/
|
||||
virtual ble_error_t read_attribute_blob(
|
||||
ble_error_t read_attribute_blob_(
|
||||
connection_handle_t connection,
|
||||
attribute_handle_t attribute_handle,
|
||||
uint16_t offset
|
||||
|
|
@ -133,7 +134,7 @@ public:
|
|||
/**
|
||||
* see pal::GattClient::read_multiple_characteristic_values .
|
||||
*/
|
||||
virtual ble_error_t read_multiple_characteristic_values(
|
||||
ble_error_t read_multiple_characteristic_values_(
|
||||
connection_handle_t connection,
|
||||
const ArrayView<const attribute_handle_t>& characteristic_handles
|
||||
);
|
||||
|
|
@ -141,7 +142,7 @@ public:
|
|||
/**
|
||||
* see pal::GattClient::write_without_response .
|
||||
*/
|
||||
virtual ble_error_t write_without_response(
|
||||
ble_error_t write_without_response_(
|
||||
connection_handle_t connection_handle,
|
||||
attribute_handle_t characteristic_value_handle,
|
||||
const ArrayView<const uint8_t>& value
|
||||
|
|
@ -150,7 +151,7 @@ public:
|
|||
/**
|
||||
* see pal::GattClient::signed_write_without_response .
|
||||
*/
|
||||
virtual ble_error_t signed_write_without_response(
|
||||
ble_error_t signed_write_without_response_(
|
||||
connection_handle_t connection_handle,
|
||||
attribute_handle_t characteristic_value_handle,
|
||||
const ArrayView<const uint8_t>& value
|
||||
|
|
@ -159,7 +160,7 @@ public:
|
|||
/**
|
||||
* see pal::GattClient::write_attribute .
|
||||
*/
|
||||
virtual ble_error_t write_attribute(
|
||||
ble_error_t write_attribute_(
|
||||
connection_handle_t connection_handle,
|
||||
attribute_handle_t attribute_handle,
|
||||
const ArrayView<const uint8_t>& value
|
||||
|
|
@ -168,7 +169,7 @@ public:
|
|||
/**
|
||||
* see pal::GattClient::queue_prepare_write .
|
||||
*/
|
||||
virtual ble_error_t queue_prepare_write(
|
||||
ble_error_t queue_prepare_write_(
|
||||
connection_handle_t connection_handle,
|
||||
attribute_handle_t characteristic_value_handle,
|
||||
const ArrayView<const uint8_t>& value,
|
||||
|
|
@ -178,7 +179,7 @@ public:
|
|||
/**
|
||||
* see pal::GattClient::execute_write_queue .
|
||||
*/
|
||||
virtual ble_error_t execute_write_queue(
|
||||
ble_error_t execute_write_queue_(
|
||||
connection_handle_t connection_handle,
|
||||
bool execute
|
||||
);
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ static attribute_handle_range_t to_ble_handle_range(const ble_gattc_handle_range
|
|||
/**
|
||||
* Convert an error from the softdevice into a ble_error_t
|
||||
*/
|
||||
static ble_error_t convert_sd_error(uint32_t err)
|
||||
static ble_error_t client_convert_sd_error(uint32_t err)
|
||||
{
|
||||
switch (err) {
|
||||
case NRF_SUCCESS:
|
||||
|
|
@ -133,7 +133,7 @@ static ble_error_t to_nordic_uuid(const UUID &uuid, ble_uuid_t &nordic_uuid)
|
|||
nordic_uuid.uuid = bytes_to_u16(uuid.getBaseUUID() + 12);
|
||||
}
|
||||
|
||||
return convert_sd_error(err);
|
||||
return client_convert_sd_error(err);
|
||||
} else {
|
||||
nordic_uuid.type = BLE_UUID_TYPE_BLE;
|
||||
nordic_uuid.uuid = uuid.getShortUUID();
|
||||
|
|
@ -159,30 +159,34 @@ static const size_t characteristic_declaration_length = 1 + 2 + 16;
|
|||
|
||||
} // end of anonymous namespace
|
||||
|
||||
nRF5xGattClient::nRF5xGattClient() :
|
||||
ble::pal::GattClient(),
|
||||
template<class EventHandler>
|
||||
nRF5xGattClient<EventHandler>::nRF5xGattClient() :
|
||||
_procedures()
|
||||
{
|
||||
}
|
||||
|
||||
nRF5xGattClient::~nRF5xGattClient()
|
||||
template<class EventHandler>
|
||||
nRF5xGattClient<EventHandler>::~nRF5xGattClient()
|
||||
{
|
||||
terminate();
|
||||
}
|
||||
|
||||
ble_error_t nRF5xGattClient::initialize()
|
||||
template<class EventHandler>
|
||||
ble_error_t nRF5xGattClient<EventHandler>::initialize_()
|
||||
{
|
||||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
||||
ble_error_t nRF5xGattClient::exchange_mtu(connection_handle_t connection)
|
||||
template<class EventHandler>
|
||||
ble_error_t nRF5xGattClient<EventHandler>::exchange_mtu_(connection_handle_t connection)
|
||||
{
|
||||
// FIXME: implement when SD 140 5.x.x is present
|
||||
// (see sd_ble_gatts_exchange_mtu_reply)
|
||||
return BLE_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
ble_error_t nRF5xGattClient::get_mtu_size(
|
||||
template<class EventHandler>
|
||||
ble_error_t nRF5xGattClient<EventHandler>::get_mtu_size_(
|
||||
connection_handle_t connection_handle, uint16_t& mtu_size
|
||||
) {
|
||||
#if (NRF_SD_BLE_API_VERSION >= 3)
|
||||
|
|
@ -195,7 +199,8 @@ ble_error_t nRF5xGattClient::get_mtu_size(
|
|||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
||||
ble_error_t nRF5xGattClient::discover_primary_service(
|
||||
template<class EventHandler>
|
||||
ble_error_t nRF5xGattClient<EventHandler>::discover_primary_service_(
|
||||
connection_handle_t connection,
|
||||
attribute_handle_t discovery_range_begining
|
||||
) {
|
||||
|
|
@ -204,7 +209,8 @@ ble_error_t nRF5xGattClient::discover_primary_service(
|
|||
);
|
||||
}
|
||||
|
||||
ble_error_t nRF5xGattClient::discover_primary_service_by_service_uuid(
|
||||
template<class EventHandler>
|
||||
ble_error_t nRF5xGattClient<EventHandler>::discover_primary_service_by_service_uuid_(
|
||||
connection_handle_t connection_handle,
|
||||
attribute_handle_t discovery_range_beginning,
|
||||
const UUID& uuid
|
||||
|
|
@ -214,7 +220,8 @@ ble_error_t nRF5xGattClient::discover_primary_service_by_service_uuid(
|
|||
);
|
||||
}
|
||||
|
||||
ble_error_t nRF5xGattClient::find_included_service(
|
||||
template<class EventHandler>
|
||||
ble_error_t nRF5xGattClient<EventHandler>::find_included_service_(
|
||||
connection_handle_t connection_handle,
|
||||
attribute_handle_range_t service_range
|
||||
) {
|
||||
|
|
@ -223,7 +230,8 @@ ble_error_t nRF5xGattClient::find_included_service(
|
|||
);
|
||||
}
|
||||
|
||||
ble_error_t nRF5xGattClient::discover_characteristics_of_a_service(
|
||||
template<class EventHandler>
|
||||
ble_error_t nRF5xGattClient<EventHandler>::discover_characteristics_of_a_service_(
|
||||
connection_handle_t connection_handle,
|
||||
attribute_handle_range_t discovery_range
|
||||
) {
|
||||
|
|
@ -232,7 +240,8 @@ ble_error_t nRF5xGattClient::discover_characteristics_of_a_service(
|
|||
);
|
||||
}
|
||||
|
||||
ble_error_t nRF5xGattClient::discover_characteristics_descriptors(
|
||||
template<class EventHandler>
|
||||
ble_error_t nRF5xGattClient<EventHandler>::discover_characteristics_descriptors_(
|
||||
connection_handle_t connection_handle,
|
||||
attribute_handle_range_t descriptors_discovery_range
|
||||
) {
|
||||
|
|
@ -241,7 +250,8 @@ ble_error_t nRF5xGattClient::discover_characteristics_descriptors(
|
|||
);
|
||||
}
|
||||
|
||||
ble_error_t nRF5xGattClient::read_attribute_value(
|
||||
template<class EventHandler>
|
||||
ble_error_t nRF5xGattClient<EventHandler>::read_attribute_value_(
|
||||
connection_handle_t connection_handle,
|
||||
attribute_handle_t attribute_handle
|
||||
) {
|
||||
|
|
@ -250,7 +260,8 @@ ble_error_t nRF5xGattClient::read_attribute_value(
|
|||
);
|
||||
}
|
||||
|
||||
ble_error_t nRF5xGattClient::read_using_characteristic_uuid(
|
||||
template<class EventHandler>
|
||||
ble_error_t nRF5xGattClient<EventHandler>::read_using_characteristic_uuid_(
|
||||
connection_handle_t connection_handle,
|
||||
attribute_handle_range_t read_range,
|
||||
const UUID& uuid
|
||||
|
|
@ -260,7 +271,8 @@ ble_error_t nRF5xGattClient::read_using_characteristic_uuid(
|
|||
);
|
||||
}
|
||||
|
||||
ble_error_t nRF5xGattClient::read_attribute_blob(
|
||||
template<class EventHandler>
|
||||
ble_error_t nRF5xGattClient<EventHandler>::read_attribute_blob_(
|
||||
connection_handle_t connection,
|
||||
attribute_handle_t attribute_handle,
|
||||
uint16_t offset
|
||||
|
|
@ -270,7 +282,8 @@ ble_error_t nRF5xGattClient::read_attribute_blob(
|
|||
);
|
||||
}
|
||||
|
||||
ble_error_t nRF5xGattClient::read_multiple_characteristic_values(
|
||||
template<class EventHandler>
|
||||
ble_error_t nRF5xGattClient<EventHandler>::read_multiple_characteristic_values_(
|
||||
connection_handle_t connection,
|
||||
const ArrayView<const attribute_handle_t>& characteristic_handles
|
||||
) {
|
||||
|
|
@ -279,7 +292,8 @@ ble_error_t nRF5xGattClient::read_multiple_characteristic_values(
|
|||
);
|
||||
}
|
||||
|
||||
ble_error_t nRF5xGattClient::write_without_response(
|
||||
template<class EventHandler>
|
||||
ble_error_t nRF5xGattClient<EventHandler>::write_without_response_(
|
||||
connection_handle_t connection_handle,
|
||||
attribute_handle_t characteristic_value_handle,
|
||||
const ArrayView<const uint8_t>& value
|
||||
|
|
@ -294,10 +308,11 @@ ble_error_t nRF5xGattClient::write_without_response(
|
|||
};
|
||||
|
||||
uint32_t err = sd_ble_gattc_write(connection_handle, &write_params);
|
||||
return convert_sd_error(err);
|
||||
return client_convert_sd_error(err);
|
||||
}
|
||||
|
||||
ble_error_t nRF5xGattClient::signed_write_without_response(
|
||||
template<class EventHandler>
|
||||
ble_error_t nRF5xGattClient<EventHandler>::signed_write_without_response_(
|
||||
connection_handle_t connection_handle,
|
||||
attribute_handle_t characteristic_value_handle,
|
||||
const ArrayView<const uint8_t>& value
|
||||
|
|
@ -312,10 +327,11 @@ ble_error_t nRF5xGattClient::signed_write_without_response(
|
|||
};
|
||||
|
||||
uint32_t err = sd_ble_gattc_write(connection_handle, &write_params);
|
||||
return convert_sd_error(err);
|
||||
return client_convert_sd_error(err);
|
||||
}
|
||||
|
||||
ble_error_t nRF5xGattClient::write_attribute(
|
||||
template<class EventHandler>
|
||||
ble_error_t nRF5xGattClient<EventHandler>::write_attribute_(
|
||||
connection_handle_t connection_handle,
|
||||
attribute_handle_t attribute_handle,
|
||||
const ArrayView<const uint8_t>& value
|
||||
|
|
@ -325,7 +341,8 @@ ble_error_t nRF5xGattClient::write_attribute(
|
|||
);
|
||||
}
|
||||
|
||||
ble_error_t nRF5xGattClient::queue_prepare_write(
|
||||
template<class EventHandler>
|
||||
ble_error_t nRF5xGattClient<EventHandler>::queue_prepare_write_(
|
||||
connection_handle_t connection_handle,
|
||||
attribute_handle_t characteristic_value_handle,
|
||||
const ArrayView<const uint8_t>& value,
|
||||
|
|
@ -336,7 +353,8 @@ ble_error_t nRF5xGattClient::queue_prepare_write(
|
|||
);
|
||||
}
|
||||
|
||||
ble_error_t nRF5xGattClient::execute_write_queue(
|
||||
template<class EventHandler>
|
||||
ble_error_t nRF5xGattClient<EventHandler>::execute_write_queue_(
|
||||
connection_handle_t connection_handle,
|
||||
bool execute
|
||||
) {
|
||||
|
|
@ -367,7 +385,8 @@ ble_error_t nRF5xGattClient::execute_write_queue(
|
|||
* @note Commands such as write without response or signed write without response
|
||||
* are not procedures.
|
||||
*/
|
||||
struct nRF5xGattClient::GattProcedure {
|
||||
template<class EventHandler>
|
||||
struct nRF5xGattClient<EventHandler>::GattProcedure {
|
||||
/**
|
||||
* Initialize the procedure.
|
||||
*
|
||||
|
|
@ -424,7 +443,12 @@ struct nRF5xGattClient::GattProcedure {
|
|||
* Given that such procedure expects a single event type from the soft device,
|
||||
* error handling can be generalized.
|
||||
*/
|
||||
struct nRF5xGattClient::RegularGattProcedure : GattProcedure {
|
||||
template<class EventHandler>
|
||||
struct nRF5xGattClient<EventHandler>::RegularGattProcedure : GattProcedure {
|
||||
|
||||
using GattProcedure::procedure_opcode;
|
||||
using GattProcedure::connection_handle;
|
||||
using GattProcedure::terminate;
|
||||
|
||||
/**
|
||||
* Construct a RegularGattProcedure.
|
||||
|
|
@ -483,8 +507,12 @@ protected:
|
|||
* In such case a read request is issued for each service attribute handle
|
||||
* to extract that information.
|
||||
*/
|
||||
struct nRF5xGattClient::DiscoverPrimaryServiceProcedure : GattProcedure {
|
||||
template<class EventHandler>
|
||||
struct nRF5xGattClient<EventHandler>::DiscoverPrimaryServiceProcedure : GattProcedure {
|
||||
|
||||
using GattProcedure::procedure_opcode;
|
||||
using GattProcedure::connection_handle;
|
||||
using GattProcedure::terminate;
|
||||
typedef ArrayView<const ble_gattc_service_t> services_array_t;
|
||||
|
||||
DiscoverPrimaryServiceProcedure(connection_handle_t connection) :
|
||||
|
|
@ -503,7 +531,7 @@ struct nRF5xGattClient::DiscoverPrimaryServiceProcedure : GattProcedure {
|
|||
uint32_t err = sd_ble_gattc_primary_services_discover(
|
||||
connection_handle, begining, /* p_srvc_uuid */ NULL
|
||||
);
|
||||
return convert_sd_error(err);
|
||||
return client_convert_sd_error(err);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -692,8 +720,12 @@ struct nRF5xGattClient::DiscoverPrimaryServiceProcedure : GattProcedure {
|
|||
* response it is possible to reconstruct it by keeping a copy of the UUID to
|
||||
* find.
|
||||
*/
|
||||
struct nRF5xGattClient::DiscoverPrimaryServiceByUUIDProcedure : RegularGattProcedure {
|
||||
template<class EventHandler>
|
||||
struct nRF5xGattClient<EventHandler>::DiscoverPrimaryServiceByUUIDProcedure : RegularGattProcedure {
|
||||
|
||||
using GattProcedure::procedure_opcode;
|
||||
using GattProcedure::connection_handle;
|
||||
using GattProcedure::terminate;
|
||||
typedef ArrayView<const ble_gattc_service_t> services_array_t;
|
||||
|
||||
DiscoverPrimaryServiceByUUIDProcedure(connection_handle_t connection) :
|
||||
|
|
@ -719,7 +751,7 @@ struct nRF5xGattClient::DiscoverPrimaryServiceByUUIDProcedure : RegularGattProce
|
|||
_service_uuid = uuid;
|
||||
}
|
||||
|
||||
return convert_sd_error(err);
|
||||
return client_convert_sd_error(err);
|
||||
}
|
||||
|
||||
virtual void do_handle(const ble_gattc_evt_t &evt)
|
||||
|
|
@ -766,8 +798,12 @@ struct nRF5xGattClient::DiscoverPrimaryServiceByUUIDProcedure : RegularGattProce
|
|||
/**
|
||||
* Procedure that manage Find Included Services transactions.
|
||||
*/
|
||||
struct nRF5xGattClient::FindIncludedServicesProcedure : RegularGattProcedure {
|
||||
template<class EventHandler>
|
||||
struct nRF5xGattClient<EventHandler>::FindIncludedServicesProcedure : RegularGattProcedure {
|
||||
|
||||
using GattProcedure::procedure_opcode;
|
||||
using GattProcedure::connection_handle;
|
||||
using GattProcedure::terminate;
|
||||
typedef ArrayView<const ble_gattc_service_t> services_array_t;
|
||||
|
||||
FindIncludedServicesProcedure(connection_handle_t connection) :
|
||||
|
|
@ -784,7 +820,7 @@ struct nRF5xGattClient::FindIncludedServicesProcedure : RegularGattProcedure {
|
|||
connection_handle, &range
|
||||
);
|
||||
|
||||
return convert_sd_error(err);
|
||||
return client_convert_sd_error(err);
|
||||
}
|
||||
|
||||
virtual void do_handle(const ble_gattc_evt_t &evt)
|
||||
|
|
@ -841,7 +877,12 @@ struct nRF5xGattClient::FindIncludedServicesProcedure : RegularGattProcedure {
|
|||
* In such case a read request is issued for each attribute handle of
|
||||
* characteristics that exposes a long UUID.
|
||||
*/
|
||||
struct nRF5xGattClient::DiscoverCharacteristicsProcedure : GattProcedure {
|
||||
template<class EventHandler>
|
||||
struct nRF5xGattClient<EventHandler>::DiscoverCharacteristicsProcedure : GattProcedure {
|
||||
|
||||
using GattProcedure::procedure_opcode;
|
||||
using GattProcedure::connection_handle;
|
||||
using GattProcedure::terminate;
|
||||
/**
|
||||
* Data structure returned by the function flatten_response.
|
||||
*/
|
||||
|
|
@ -870,7 +911,7 @@ struct nRF5xGattClient::DiscoverCharacteristicsProcedure : GattProcedure {
|
|||
&range
|
||||
);
|
||||
|
||||
return convert_sd_error(err);
|
||||
return client_convert_sd_error(err);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1060,7 +1101,12 @@ struct nRF5xGattClient::DiscoverCharacteristicsProcedure : GattProcedure {
|
|||
/**
|
||||
* Procedure that handle discovery of characteristic descriptors.
|
||||
*/
|
||||
struct nRF5xGattClient::DiscoverDescriptorsProcedure : RegularGattProcedure {
|
||||
template<class EventHandler>
|
||||
struct nRF5xGattClient<EventHandler>::DiscoverDescriptorsProcedure : RegularGattProcedure {
|
||||
using GattProcedure::procedure_opcode;
|
||||
using GattProcedure::connection_handle;
|
||||
using GattProcedure::terminate;
|
||||
|
||||
DiscoverDescriptorsProcedure(connection_handle_t connection) :
|
||||
RegularGattProcedure(
|
||||
connection,
|
||||
|
|
@ -1077,7 +1123,7 @@ struct nRF5xGattClient::DiscoverDescriptorsProcedure : RegularGattProcedure {
|
|||
&range
|
||||
);
|
||||
|
||||
return convert_sd_error(err);
|
||||
return client_convert_sd_error(err);
|
||||
}
|
||||
|
||||
virtual void do_handle(const ble_gattc_evt_t &evt)
|
||||
|
|
@ -1151,7 +1197,13 @@ struct nRF5xGattClient::DiscoverDescriptorsProcedure : RegularGattProcedure {
|
|||
/**
|
||||
* Procedure that handle read of attribute handles.
|
||||
*/
|
||||
struct nRF5xGattClient::ReadAttributeProcedure : RegularGattProcedure {
|
||||
template<class EventHandler>
|
||||
struct nRF5xGattClient<EventHandler>::ReadAttributeProcedure : RegularGattProcedure {
|
||||
|
||||
using GattProcedure::procedure_opcode;
|
||||
using GattProcedure::connection_handle;
|
||||
using GattProcedure::terminate;
|
||||
|
||||
ReadAttributeProcedure(connection_handle_t connection) :
|
||||
RegularGattProcedure(
|
||||
connection, AttributeOpcode::READ_REQUEST, BLE_GATTC_EVT_READ_RSP
|
||||
|
|
@ -1160,7 +1212,7 @@ struct nRF5xGattClient::ReadAttributeProcedure : RegularGattProcedure {
|
|||
ble_error_t start(attribute_handle_t attribute_handle)
|
||||
{
|
||||
uint32_t err = sd_ble_gattc_read(connection_handle, attribute_handle, 0);
|
||||
return convert_sd_error(err);
|
||||
return client_convert_sd_error(err);
|
||||
}
|
||||
|
||||
virtual void do_handle(const ble_gattc_evt_t &evt)
|
||||
|
|
@ -1178,7 +1230,13 @@ struct nRF5xGattClient::ReadAttributeProcedure : RegularGattProcedure {
|
|||
/**
|
||||
* Procedure that handle read of characteristic using characteristic UUID.
|
||||
*/
|
||||
struct nRF5xGattClient::ReadUsingCharacteristicUUIDProcedure : RegularGattProcedure {
|
||||
template<class EventHandler>
|
||||
struct nRF5xGattClient<EventHandler>::ReadUsingCharacteristicUUIDProcedure : RegularGattProcedure {
|
||||
|
||||
using GattProcedure::procedure_opcode;
|
||||
using GattProcedure::connection_handle;
|
||||
using GattProcedure::terminate;
|
||||
|
||||
ReadUsingCharacteristicUUIDProcedure(connection_handle_t connection) :
|
||||
RegularGattProcedure(
|
||||
connection,
|
||||
|
|
@ -1204,7 +1262,7 @@ struct nRF5xGattClient::ReadUsingCharacteristicUUIDProcedure : RegularGattProced
|
|||
&nordic_uuid,
|
||||
&range
|
||||
);
|
||||
return convert_sd_error(err);
|
||||
return client_convert_sd_error(err);
|
||||
}
|
||||
|
||||
#if (NRF_SD_BLE_API_VERSION >= 3)
|
||||
|
|
@ -1265,7 +1323,13 @@ struct nRF5xGattClient::ReadUsingCharacteristicUUIDProcedure : RegularGattProced
|
|||
/**
|
||||
* Procedure that handles read blob transactions.
|
||||
*/
|
||||
struct nRF5xGattClient::ReadAttributeBlobProcedure : RegularGattProcedure {
|
||||
template<class EventHandler>
|
||||
struct nRF5xGattClient<EventHandler>::ReadAttributeBlobProcedure : RegularGattProcedure {
|
||||
|
||||
using GattProcedure::procedure_opcode;
|
||||
using GattProcedure::connection_handle;
|
||||
using GattProcedure::terminate;
|
||||
|
||||
ReadAttributeBlobProcedure(connection_handle_t connection) :
|
||||
RegularGattProcedure(
|
||||
connection, AttributeOpcode::READ_BLOB_REQUEST, BLE_GATTC_EVT_READ_RSP
|
||||
|
|
@ -1276,7 +1340,7 @@ struct nRF5xGattClient::ReadAttributeBlobProcedure : RegularGattProcedure {
|
|||
uint32_t err = sd_ble_gattc_read(
|
||||
connection_handle, attribute_handle, offset
|
||||
);
|
||||
return convert_sd_error(err);
|
||||
return client_convert_sd_error(err);
|
||||
}
|
||||
|
||||
virtual void do_handle(const ble_gattc_evt_t &evt)
|
||||
|
|
@ -1291,7 +1355,13 @@ struct nRF5xGattClient::ReadAttributeBlobProcedure : RegularGattProcedure {
|
|||
/**
|
||||
* Procedure that handles Read Multiple Characteristic Values transactions.
|
||||
*/
|
||||
struct nRF5xGattClient::ReadMultipleCharacteristicsProcedure : RegularGattProcedure {
|
||||
template<class EventHandler>
|
||||
struct nRF5xGattClient<EventHandler>::ReadMultipleCharacteristicsProcedure : RegularGattProcedure {
|
||||
|
||||
using GattProcedure::procedure_opcode;
|
||||
using GattProcedure::connection_handle;
|
||||
using GattProcedure::terminate;
|
||||
|
||||
ReadMultipleCharacteristicsProcedure(connection_handle_t connection) :
|
||||
RegularGattProcedure(
|
||||
connection,
|
||||
|
|
@ -1306,7 +1376,7 @@ struct nRF5xGattClient::ReadMultipleCharacteristicsProcedure : RegularGattProced
|
|||
characteristic_handles.data(),
|
||||
characteristic_handles.size()
|
||||
);
|
||||
return convert_sd_error(err);
|
||||
return client_convert_sd_error(err);
|
||||
}
|
||||
|
||||
virtual void do_handle(const ble_gattc_evt_t &evt)
|
||||
|
|
@ -1321,7 +1391,13 @@ struct nRF5xGattClient::ReadMultipleCharacteristicsProcedure : RegularGattProced
|
|||
/**
|
||||
* Procedure that handles Write transactions.
|
||||
*/
|
||||
struct nRF5xGattClient::WriteAttributeProcedure : RegularGattProcedure {
|
||||
template<class EventHandler>
|
||||
struct nRF5xGattClient<EventHandler>::WriteAttributeProcedure : RegularGattProcedure {
|
||||
|
||||
using GattProcedure::procedure_opcode;
|
||||
using GattProcedure::connection_handle;
|
||||
using GattProcedure::terminate;
|
||||
|
||||
WriteAttributeProcedure(connection_handle_t connection) :
|
||||
RegularGattProcedure(
|
||||
connection, AttributeOpcode::WRITE_REQUEST, BLE_GATTC_EVT_WRITE_RSP
|
||||
|
|
@ -1340,7 +1416,7 @@ struct nRF5xGattClient::WriteAttributeProcedure : RegularGattProcedure {
|
|||
};
|
||||
|
||||
uint32_t err = sd_ble_gattc_write(connection_handle, &write_params);
|
||||
return convert_sd_error(err);
|
||||
return client_convert_sd_error(err);
|
||||
}
|
||||
|
||||
virtual void do_handle(const ble_gattc_evt_t &evt)
|
||||
|
|
@ -1352,7 +1428,13 @@ struct nRF5xGattClient::WriteAttributeProcedure : RegularGattProcedure {
|
|||
/**
|
||||
* Procedure that handles Prepare Write transactions.
|
||||
*/
|
||||
struct nRF5xGattClient::QueuePrepareWriteProcedure : RegularGattProcedure {
|
||||
template<class EventHandler>
|
||||
struct nRF5xGattClient<EventHandler>::QueuePrepareWriteProcedure : RegularGattProcedure {
|
||||
|
||||
using GattProcedure::procedure_opcode;
|
||||
using GattProcedure::connection_handle;
|
||||
using GattProcedure::terminate;
|
||||
|
||||
QueuePrepareWriteProcedure(connection_handle_t connection) :
|
||||
RegularGattProcedure(
|
||||
connection,
|
||||
|
|
@ -1375,7 +1457,7 @@ struct nRF5xGattClient::QueuePrepareWriteProcedure : RegularGattProcedure {
|
|||
};
|
||||
|
||||
uint32_t err = sd_ble_gattc_write(connection_handle, &write_params);
|
||||
return convert_sd_error(err);
|
||||
return client_convert_sd_error(err);
|
||||
}
|
||||
|
||||
virtual void do_handle(const ble_gattc_evt_t &evt)
|
||||
|
|
@ -1398,7 +1480,13 @@ struct nRF5xGattClient::QueuePrepareWriteProcedure : RegularGattProcedure {
|
|||
/**
|
||||
* Procedure that handles Execute Write transactions.
|
||||
*/
|
||||
struct nRF5xGattClient::ExecuteWriteQueueProcedure : RegularGattProcedure {
|
||||
template<class EventHandler>
|
||||
struct nRF5xGattClient<EventHandler>::ExecuteWriteQueueProcedure : RegularGattProcedure {
|
||||
|
||||
using GattProcedure::procedure_opcode;
|
||||
using GattProcedure::connection_handle;
|
||||
using GattProcedure::terminate;
|
||||
|
||||
ExecuteWriteQueueProcedure(connection_handle_t connection) :
|
||||
RegularGattProcedure(
|
||||
connection,
|
||||
|
|
@ -1421,7 +1509,7 @@ struct nRF5xGattClient::ExecuteWriteQueueProcedure : RegularGattProcedure {
|
|||
};
|
||||
|
||||
uint32_t err = sd_ble_gattc_write(connection_handle, &write_params);
|
||||
return convert_sd_error(err);
|
||||
return client_convert_sd_error(err);
|
||||
}
|
||||
|
||||
virtual void do_handle(const ble_gattc_evt_t &evt)
|
||||
|
|
@ -1437,7 +1525,8 @@ struct nRF5xGattClient::ExecuteWriteQueueProcedure : RegularGattProcedure {
|
|||
};
|
||||
|
||||
// NOTE: position after declaration of GattProcedure on purpose.
|
||||
ble_error_t nRF5xGattClient::terminate()
|
||||
template<class EventHandler>
|
||||
ble_error_t nRF5xGattClient<EventHandler>::terminate_()
|
||||
{
|
||||
for (size_t i = 0; i < max_procedures_count; ++i) {
|
||||
if (_procedures[i]) {
|
||||
|
|
@ -1449,8 +1538,9 @@ ble_error_t nRF5xGattClient::terminate()
|
|||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
||||
template<class EventHandler>
|
||||
template<typename ProcType, typename A0>
|
||||
ble_error_t nRF5xGattClient::launch_procedure(
|
||||
ble_error_t nRF5xGattClient<EventHandler>::launch_procedure(
|
||||
connection_handle_t connection, const A0& a0
|
||||
) {
|
||||
ProcType* p = new(std::nothrow) ProcType(connection);
|
||||
|
|
@ -1472,8 +1562,9 @@ ble_error_t nRF5xGattClient::launch_procedure(
|
|||
return err;
|
||||
}
|
||||
|
||||
template<class EventHandler>
|
||||
template<typename ProcType, typename A0, typename A1>
|
||||
ble_error_t nRF5xGattClient::launch_procedure(
|
||||
ble_error_t nRF5xGattClient<EventHandler>::launch_procedure(
|
||||
connection_handle_t connection, const A0& a0, const A1& a1
|
||||
) {
|
||||
ProcType* p = new(std::nothrow) ProcType(connection);
|
||||
|
|
@ -1495,8 +1586,9 @@ ble_error_t nRF5xGattClient::launch_procedure(
|
|||
return err;
|
||||
}
|
||||
|
||||
template<class EventHandler>
|
||||
template<typename ProcType, typename A0, typename A1, typename A2>
|
||||
ble_error_t nRF5xGattClient::launch_procedure(
|
||||
ble_error_t nRF5xGattClient<EventHandler>::launch_procedure(
|
||||
connection_handle_t connection,
|
||||
const A0& a0, const A1& a1, const A2& a2
|
||||
) {
|
||||
|
|
@ -1519,8 +1611,9 @@ ble_error_t nRF5xGattClient::launch_procedure(
|
|||
return err;
|
||||
}
|
||||
|
||||
template<class EventHandler>
|
||||
template<typename ProcType, typename A0, typename A1, typename A2, typename A3>
|
||||
ble_error_t nRF5xGattClient::launch_procedure(
|
||||
ble_error_t nRF5xGattClient<EventHandler>::launch_procedure(
|
||||
connection_handle_t connection,
|
||||
const A0& a0, const A1& a1, const A2& a2, const A3& a3
|
||||
) {
|
||||
|
|
@ -1543,7 +1636,8 @@ ble_error_t nRF5xGattClient::launch_procedure(
|
|||
return err;
|
||||
}
|
||||
|
||||
nRF5xGattClient::GattProcedure* nRF5xGattClient::get_procedure(
|
||||
template<class EventHandler>
|
||||
typename nRF5xGattClient<EventHandler>::GattProcedure* nRF5xGattClient<EventHandler>::get_procedure(
|
||||
connection_handle_t connection
|
||||
) const {
|
||||
for (size_t i = 0; i < max_procedures_count; ++i) {
|
||||
|
|
@ -1554,7 +1648,8 @@ nRF5xGattClient::GattProcedure* nRF5xGattClient::get_procedure(
|
|||
return NULL;
|
||||
}
|
||||
|
||||
bool nRF5xGattClient::register_procedure(GattProcedure *p)
|
||||
template<class EventHandler>
|
||||
bool nRF5xGattClient<EventHandler>::register_procedure(GattProcedure *p)
|
||||
{
|
||||
if (get_procedure(p->connection_handle)) {
|
||||
return false;
|
||||
|
|
@ -1570,7 +1665,8 @@ bool nRF5xGattClient::register_procedure(GattProcedure *p)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool nRF5xGattClient::remove_procedure(nRF5xGattClient::GattProcedure* p)
|
||||
template<class EventHandler>
|
||||
bool nRF5xGattClient<EventHandler>::remove_procedure(nRF5xGattClient<EventHandler>::GattProcedure* p)
|
||||
{
|
||||
for (size_t i = 0; i < max_procedures_count; ++i) {
|
||||
if (_procedures[i] == p) {
|
||||
|
|
@ -1583,13 +1679,15 @@ bool nRF5xGattClient::remove_procedure(nRF5xGattClient::GattProcedure* p)
|
|||
}
|
||||
|
||||
// singleton of the ARM Cordio client
|
||||
nRF5xGattClient& nRF5xGattClient::get_client()
|
||||
template<class EventHandler>
|
||||
nRF5xGattClient<EventHandler>& nRF5xGattClient<EventHandler>::get_client()
|
||||
{
|
||||
static nRF5xGattClient _client;
|
||||
return _client;
|
||||
}
|
||||
|
||||
void nRF5xGattClient::handle_events(const ble_evt_t *evt) {
|
||||
template<class EventHandler>
|
||||
void nRF5xGattClient<EventHandler>::handle_events(const ble_evt_t *evt) {
|
||||
switch (evt->header.evt_id) {
|
||||
case BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP:
|
||||
case BLE_GATTC_EVT_REL_DISC_RSP:
|
||||
|
|
@ -1611,7 +1709,8 @@ void nRF5xGattClient::handle_events(const ble_evt_t *evt) {
|
|||
}
|
||||
}
|
||||
|
||||
void nRF5xGattClient::handle_procedure_event(const ble_evt_t &evt)
|
||||
template<class EventHandler>
|
||||
void nRF5xGattClient<EventHandler>::handle_procedure_event(const ble_evt_t &evt)
|
||||
{
|
||||
GattProcedure* p = get_procedure(evt.evt.gattc_evt.conn_handle);
|
||||
if (p) {
|
||||
|
|
@ -1619,14 +1718,15 @@ void nRF5xGattClient::handle_procedure_event(const ble_evt_t &evt)
|
|||
}
|
||||
}
|
||||
|
||||
void nRF5xGattClient::handle_hvx_event(const ble_evt_t &evt)
|
||||
template<class EventHandler>
|
||||
void nRF5xGattClient<EventHandler>::handle_hvx_event(const ble_evt_t &evt)
|
||||
{
|
||||
connection_handle_t connection = evt.evt.gattc_evt.conn_handle;
|
||||
const ble_gattc_evt_hvx_t &hvx_evt = evt.evt.gattc_evt.params.hvx;
|
||||
|
||||
switch (hvx_evt.type) {
|
||||
case BLE_GATT_HVX_NOTIFICATION:
|
||||
on_server_event(
|
||||
this->on_server_event(
|
||||
connection,
|
||||
AttHandleValueNotification(
|
||||
hvx_evt.handle,
|
||||
|
|
@ -1637,7 +1737,7 @@ void nRF5xGattClient::handle_hvx_event(const ble_evt_t &evt)
|
|||
case BLE_GATT_HVX_INDICATION:
|
||||
// send confirmation first then process the event
|
||||
sd_ble_gattc_hv_confirm(connection, hvx_evt.handle);
|
||||
on_server_event(
|
||||
this->on_server_event(
|
||||
connection,
|
||||
AttHandleValueIndication(
|
||||
hvx_evt.handle,
|
||||
|
|
@ -1650,7 +1750,8 @@ void nRF5xGattClient::handle_hvx_event(const ble_evt_t &evt)
|
|||
}
|
||||
}
|
||||
|
||||
void nRF5xGattClient::handle_timeout_event(const ble_evt_t &evt)
|
||||
template<class EventHandler>
|
||||
void nRF5xGattClient<EventHandler>::handle_timeout_event(const ble_evt_t &evt)
|
||||
{
|
||||
connection_handle_t connection = evt.evt.gattc_evt.conn_handle;
|
||||
GattProcedure* p = get_procedure(connection);
|
||||
|
|
@ -1658,10 +1759,11 @@ void nRF5xGattClient::handle_timeout_event(const ble_evt_t &evt)
|
|||
p->abort();
|
||||
}
|
||||
|
||||
on_transaction_timeout(connection);
|
||||
this->on_transaction_timeout(connection);
|
||||
}
|
||||
|
||||
void nRF5xGattClient::handle_connection_termination(connection_handle_t connection)
|
||||
template<class EventHandler>
|
||||
void nRF5xGattClient<EventHandler>::handle_connection_termination(connection_handle_t connection)
|
||||
{
|
||||
GattProcedure* p = get_client().get_procedure(connection);
|
||||
if (p) {
|
||||
|
|
@ -28,11 +28,17 @@ namespace pal {
|
|||
namespace vendor {
|
||||
namespace nordic {
|
||||
|
||||
class nRF5xSecurityManager : public ::ble::pal::SecurityManager {
|
||||
template <class EventHandler>
|
||||
class nRF5xSecurityManager : public ::ble::pal::SecurityManager<nRF5xSecurityManager<EventHandler>, EventHandler> {
|
||||
public:
|
||||
typedef ::ble::pal::SecurityManager<
|
||||
nRF5xSecurityManager<EventHandler>,
|
||||
EventHandler
|
||||
> Base;
|
||||
|
||||
nRF5xSecurityManager();
|
||||
|
||||
virtual ~nRF5xSecurityManager();
|
||||
~nRF5xSecurityManager();
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// SM lifecycle management
|
||||
|
|
@ -41,17 +47,17 @@ public:
|
|||
/**
|
||||
* @see ::ble::pal::SecurityManager::initialize
|
||||
*/
|
||||
virtual ble_error_t initialize();
|
||||
ble_error_t initialize_();
|
||||
|
||||
/**
|
||||
* @see ::ble::pal::SecurityManager::terminate
|
||||
*/
|
||||
virtual ble_error_t terminate();
|
||||
ble_error_t terminate_();
|
||||
|
||||
/**
|
||||
* @see ::ble::pal::SecurityManager::reset
|
||||
*/
|
||||
virtual ble_error_t reset() ;
|
||||
ble_error_t reset_() ;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// Resolving list management
|
||||
|
|
@ -60,12 +66,12 @@ public:
|
|||
/**
|
||||
* @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
|
||||
*/
|
||||
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,
|
||||
const address_t &peer_identity_address,
|
||||
const irk_t &peer_irk
|
||||
|
|
@ -74,7 +80,7 @@ public:
|
|||
/**
|
||||
* @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,
|
||||
const address_t &peer_identity_address
|
||||
);
|
||||
|
|
@ -82,7 +88,7 @@ public:
|
|||
/**
|
||||
* @see ::ble::pal::SecurityManager::clear_resolving_list
|
||||
*/
|
||||
virtual ble_error_t clear_resolving_list();
|
||||
ble_error_t clear_resolving_list_();
|
||||
|
||||
/**
|
||||
* An entry of the resolving list stored in the SecurityManager.
|
||||
|
|
@ -125,7 +131,7 @@ public:
|
|||
/**
|
||||
* @see ::ble::pal::SecurityManager::send_pairing_request
|
||||
*/
|
||||
virtual ble_error_t send_pairing_request(
|
||||
ble_error_t send_pairing_request_(
|
||||
connection_handle_t connection,
|
||||
bool oob_data_flag,
|
||||
AuthenticationMask authentication_requirements,
|
||||
|
|
@ -136,7 +142,7 @@ public:
|
|||
/**
|
||||
* @see ::ble::pal::SecurityManager::send_pairing_response
|
||||
*/
|
||||
virtual ble_error_t send_pairing_response(
|
||||
ble_error_t send_pairing_response_(
|
||||
connection_handle_t connection,
|
||||
bool oob_data_flag,
|
||||
AuthenticationMask authentication_requirements,
|
||||
|
|
@ -147,7 +153,7 @@ public:
|
|||
/**
|
||||
* @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
|
||||
);
|
||||
|
||||
|
|
@ -159,14 +165,14 @@ public:
|
|||
/**
|
||||
* @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
|
||||
);
|
||||
|
||||
/**
|
||||
* @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
|
||||
|
|
@ -175,21 +181,21 @@ public:
|
|||
/**
|
||||
* @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
|
||||
);
|
||||
|
||||
/**
|
||||
* @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
|
||||
);
|
||||
|
||||
/**
|
||||
* @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 max_encryption_key_size
|
||||
);
|
||||
|
|
@ -197,7 +203,7 @@ public:
|
|||
/**
|
||||
* @see ::ble::pal::SecurityManager::slave_security_request
|
||||
*/
|
||||
virtual ble_error_t slave_security_request(
|
||||
ble_error_t slave_security_request_(
|
||||
connection_handle_t connection,
|
||||
AuthenticationMask authentication
|
||||
);
|
||||
|
|
@ -209,7 +215,7 @@ public:
|
|||
/**
|
||||
* @see ::ble::pal::SecurityManager::enable_encryption
|
||||
*/
|
||||
virtual ble_error_t enable_encryption(
|
||||
ble_error_t enable_encryption_(
|
||||
connection_handle_t connection,
|
||||
const ltk_t <k,
|
||||
const rand_t &rand,
|
||||
|
|
@ -220,7 +226,7 @@ public:
|
|||
/**
|
||||
* @see ::ble::pal::SecurityManager::enable_encryption
|
||||
*/
|
||||
virtual ble_error_t enable_encryption(
|
||||
ble_error_t enable_encryption_(
|
||||
connection_handle_t connection,
|
||||
const ltk_t <k,
|
||||
bool mitm
|
||||
|
|
@ -229,7 +235,7 @@ public:
|
|||
/**
|
||||
* @see ::ble::pal::SecurityManager::encrypt_data
|
||||
*/
|
||||
virtual ble_error_t encrypt_data(
|
||||
ble_error_t encrypt_data_(
|
||||
const byte_array_t<16> &key,
|
||||
encryption_block_t &data
|
||||
);
|
||||
|
|
@ -241,7 +247,7 @@ public:
|
|||
/**
|
||||
* @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
|
||||
|
|
@ -250,7 +256,7 @@ public:
|
|||
/**
|
||||
* @see ::ble::pal::SecurityManager::set_ltk
|
||||
*/
|
||||
virtual ble_error_t set_ltk(
|
||||
ble_error_t set_ltk_(
|
||||
connection_handle_t connection,
|
||||
const ltk_t <k,
|
||||
bool mitm,
|
||||
|
|
@ -260,24 +266,24 @@ public:
|
|||
/**
|
||||
* @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
|
||||
);
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
virtual ble_error_t set_csrk(const csrk_t &csrk, sign_count_t sign_counter);
|
||||
ble_error_t set_csrk_(const csrk_t &csrk, sign_count_t sign_counter);
|
||||
|
||||
/**
|
||||
* @see ::ble::pal::SecurityManager::set_peer_csrk
|
||||
*/
|
||||
virtual ble_error_t set_peer_csrk(
|
||||
ble_error_t set_peer_csrk_(
|
||||
connection_handle_t connection,
|
||||
const csrk_t &csrk,
|
||||
bool authenticated,
|
||||
|
|
@ -287,8 +293,7 @@ public:
|
|||
/**
|
||||
* @see ::ble::pal::SecurityManager::remove_peer_csrk
|
||||
*/
|
||||
virtual ble_error_t remove_peer_csrk(connection_handle_t connection);
|
||||
|
||||
ble_error_t remove_peer_csrk_(connection_handle_t connection);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// Authentication
|
||||
|
|
@ -297,7 +302,7 @@ public:
|
|||
/**
|
||||
* @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
|
||||
|
|
@ -306,12 +311,12 @@ public:
|
|||
/**
|
||||
* @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
|
||||
*/
|
||||
virtual ble_error_t passkey_request_reply(
|
||||
ble_error_t passkey_request_reply_(
|
||||
connection_handle_t connection,
|
||||
passkey_num_t passkey
|
||||
);
|
||||
|
|
@ -319,7 +324,7 @@ public:
|
|||
/**
|
||||
* @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,
|
||||
const oob_lesc_value_t &local_random,
|
||||
const oob_lesc_value_t &peer_random,
|
||||
|
|
@ -329,7 +334,7 @@ public:
|
|||
/**
|
||||
* @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,
|
||||
const oob_tk_t &oob_data
|
||||
);
|
||||
|
|
@ -337,21 +342,21 @@ public:
|
|||
/**
|
||||
* @see ::ble::pal::SecurityManager::confirmation_entered
|
||||
*/
|
||||
virtual ble_error_t confirmation_entered(
|
||||
ble_error_t confirmation_entered_(
|
||||
connection_handle_t connection, bool confirmation
|
||||
);
|
||||
|
||||
/**
|
||||
* @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
|
||||
);
|
||||
|
||||
/**
|
||||
* @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 nordic Security Manager
|
||||
static nRF5xSecurityManager& get_security_manager();
|
||||
|
|
|
|||
|
|
@ -59,7 +59,8 @@ enum pairing_role_t {
|
|||
PAIRING_RESPONDER
|
||||
};
|
||||
|
||||
struct nRF5xSecurityManager::pairing_control_block_t {
|
||||
template <class EventHandler>
|
||||
struct nRF5xSecurityManager<EventHandler>::pairing_control_block_t {
|
||||
pairing_control_block_t* next;
|
||||
connection_handle_t connection;
|
||||
pairing_role_t role;
|
||||
|
|
@ -86,8 +87,8 @@ struct nRF5xSecurityManager::pairing_control_block_t {
|
|||
uint8_t peer_oob:1;
|
||||
};
|
||||
|
||||
nRF5xSecurityManager::nRF5xSecurityManager()
|
||||
: ::ble::pal::SecurityManager(),
|
||||
template <class EventHandler>
|
||||
nRF5xSecurityManager<EventHandler>::nRF5xSecurityManager() :
|
||||
_sign_counter(),
|
||||
_io_capability(io_capability_t::NO_INPUT_NO_OUTPUT),
|
||||
_min_encryption_key_size(7),
|
||||
|
|
@ -98,7 +99,8 @@ nRF5xSecurityManager::nRF5xSecurityManager()
|
|||
|
||||
}
|
||||
|
||||
nRF5xSecurityManager::~nRF5xSecurityManager()
|
||||
template <class EventHandler>
|
||||
nRF5xSecurityManager<EventHandler>::~nRF5xSecurityManager()
|
||||
{
|
||||
terminate();
|
||||
}
|
||||
|
|
@ -107,7 +109,8 @@ nRF5xSecurityManager::~nRF5xSecurityManager()
|
|||
// SM lifecycle management
|
||||
//
|
||||
|
||||
ble_error_t nRF5xSecurityManager::initialize()
|
||||
template <class EventHandler>
|
||||
ble_error_t nRF5xSecurityManager<EventHandler>::initialize_()
|
||||
{
|
||||
#if defined(MBEDTLS_ECDH_C)
|
||||
if (_crypto.generate_keys(
|
||||
|
|
@ -123,20 +126,22 @@ ble_error_t nRF5xSecurityManager::initialize()
|
|||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
||||
ble_error_t nRF5xSecurityManager::terminate()
|
||||
template <class EventHandler>
|
||||
ble_error_t nRF5xSecurityManager<EventHandler>::terminate_()
|
||||
{
|
||||
release_all_pairing_cb();
|
||||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
||||
ble_error_t nRF5xSecurityManager::reset()
|
||||
template <class EventHandler>
|
||||
ble_error_t nRF5xSecurityManager<EventHandler>::reset_()
|
||||
{
|
||||
ble_error_t err = terminate();
|
||||
ble_error_t err = this->terminate();
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
return initialize();
|
||||
return this->initialize();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -146,12 +151,14 @@ ble_error_t nRF5xSecurityManager::reset()
|
|||
// FIXME: on nordic, the irk is passed in sd_ble_gap_scan_start where whitelist
|
||||
// and resolving list are all mixed up.
|
||||
|
||||
uint8_t nRF5xSecurityManager::read_resolving_list_capacity()
|
||||
template <class EventHandler>
|
||||
uint8_t nRF5xSecurityManager<EventHandler>::read_resolving_list_capacity_()
|
||||
{
|
||||
return MAX_RESOLVING_LIST_ENTRIES;
|
||||
}
|
||||
|
||||
ble_error_t nRF5xSecurityManager::add_device_to_resolving_list(
|
||||
template <class EventHandler>
|
||||
ble_error_t nRF5xSecurityManager<EventHandler>::add_device_to_resolving_list_(
|
||||
advertising_peer_address_type_t peer_identity_address_type,
|
||||
const address_t &peer_identity_address,
|
||||
const irk_t &peer_irk
|
||||
|
|
@ -170,7 +177,8 @@ ble_error_t nRF5xSecurityManager::add_device_to_resolving_list(
|
|||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
||||
ble_error_t nRF5xSecurityManager::remove_device_from_resolving_list(
|
||||
template <class EventHandler>
|
||||
ble_error_t nRF5xSecurityManager<EventHandler>::remove_device_from_resolving_list_(
|
||||
advertising_peer_address_type_t peer_identity_address_type,
|
||||
const address_t &peer_identity_address
|
||||
) {
|
||||
|
|
@ -200,22 +208,25 @@ ble_error_t nRF5xSecurityManager::remove_device_from_resolving_list(
|
|||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
||||
ble_error_t nRF5xSecurityManager::clear_resolving_list()
|
||||
template <class EventHandler>
|
||||
ble_error_t nRF5xSecurityManager<EventHandler>::clear_resolving_list_()
|
||||
{
|
||||
resolving_list_entry_count = 0;
|
||||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
||||
ArrayView<nRF5xSecurityManager::resolving_list_entry_t>
|
||||
nRF5xSecurityManager::get_resolving_list() {
|
||||
return ArrayView<nRF5xSecurityManager::resolving_list_entry_t>(
|
||||
template<class EventHandler>
|
||||
ArrayView<typename nRF5xSecurityManager<EventHandler>::resolving_list_entry_t>
|
||||
nRF5xSecurityManager<EventHandler>::get_resolving_list() {
|
||||
return ArrayView<resolving_list_entry_t>(
|
||||
resolving_list,
|
||||
resolving_list_entry_count
|
||||
);
|
||||
}
|
||||
|
||||
const nRF5xSecurityManager::resolving_list_entry_t*
|
||||
nRF5xSecurityManager::resolve_address(const address_t& resolvable_address) {
|
||||
template<class EventHandler>
|
||||
const typename nRF5xSecurityManager<EventHandler>::resolving_list_entry_t*
|
||||
nRF5xSecurityManager<EventHandler>::resolve_address(const address_t& resolvable_address) {
|
||||
typedef byte_array_t<CryptoToolbox::hash_size_> hash_t;
|
||||
|
||||
for (size_t i = 0; i < resolving_list_entry_count; ++i) {
|
||||
|
|
@ -250,7 +261,8 @@ nRF5xSecurityManager::resolve_address(const address_t& resolvable_address) {
|
|||
//
|
||||
|
||||
|
||||
ble_error_t nRF5xSecurityManager::send_pairing_request(
|
||||
template <class EventHandler>
|
||||
ble_error_t nRF5xSecurityManager<EventHandler>::send_pairing_request_(
|
||||
connection_handle_t connection,
|
||||
bool oob_data_flag,
|
||||
AuthenticationMask authentication_requirements,
|
||||
|
|
@ -291,7 +303,8 @@ ble_error_t nRF5xSecurityManager::send_pairing_request(
|
|||
return convert_sd_error(err);
|
||||
}
|
||||
|
||||
ble_error_t nRF5xSecurityManager::send_pairing_response(
|
||||
template <class EventHandler>
|
||||
ble_error_t nRF5xSecurityManager<EventHandler>::send_pairing_response_(
|
||||
connection_handle_t connection,
|
||||
bool oob_data_flag,
|
||||
AuthenticationMask authentication_requirements,
|
||||
|
|
@ -302,7 +315,7 @@ ble_error_t nRF5xSecurityManager::send_pairing_response(
|
|||
if (!pairing_cb) {
|
||||
// not enough memory; try to reject the pairing request instead of
|
||||
// waiting for timeout.
|
||||
cancel_pairing(connection, pairing_failure_t::UNSPECIFIED_REASON);
|
||||
this->cancel_pairing(connection, pairing_failure_t::UNSPECIFIED_REASON);
|
||||
return BLE_ERROR_NO_MEM;
|
||||
}
|
||||
pairing_cb->role = PAIRING_RESPONDER;
|
||||
|
|
@ -342,7 +355,8 @@ ble_error_t nRF5xSecurityManager::send_pairing_response(
|
|||
return convert_sd_error(err);
|
||||
}
|
||||
|
||||
ble_error_t nRF5xSecurityManager::cancel_pairing(
|
||||
template <class EventHandler>
|
||||
ble_error_t nRF5xSecurityManager<EventHandler>::cancel_pairing_(
|
||||
connection_handle_t connection, pairing_failure_t reason
|
||||
) {
|
||||
uint32_t err = 0;
|
||||
|
|
@ -386,14 +400,16 @@ ble_error_t nRF5xSecurityManager::cancel_pairing(
|
|||
// Feature support
|
||||
//
|
||||
|
||||
ble_error_t nRF5xSecurityManager::get_secure_connections_support(
|
||||
template <class EventHandler>
|
||||
ble_error_t nRF5xSecurityManager<EventHandler>::get_secure_connections_support_(
|
||||
bool &enabled
|
||||
) {
|
||||
enabled = false;
|
||||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
||||
ble_error_t nRF5xSecurityManager::set_io_capability(io_capability_t io_capability)
|
||||
template <class EventHandler>
|
||||
ble_error_t nRF5xSecurityManager<EventHandler>::set_io_capability_(io_capability_t io_capability)
|
||||
{
|
||||
_io_capability = io_capability;
|
||||
return BLE_ERROR_NONE;
|
||||
|
|
@ -403,7 +419,8 @@ ble_error_t nRF5xSecurityManager::set_io_capability(io_capability_t io_capabilit
|
|||
// Security settings
|
||||
//
|
||||
|
||||
ble_error_t nRF5xSecurityManager::set_authentication_timeout(
|
||||
template <class EventHandler>
|
||||
ble_error_t nRF5xSecurityManager<EventHandler>::set_authentication_timeout_(
|
||||
connection_handle_t connection, uint16_t timeout_in_10ms
|
||||
) {
|
||||
// FIXME: Use sd_ble_opt_set(BLE_GAP_OPT_AUTH_PAYLOAD_TIMEOUT, ...) when
|
||||
|
|
@ -411,7 +428,8 @@ ble_error_t nRF5xSecurityManager::set_authentication_timeout(
|
|||
return BLE_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
ble_error_t nRF5xSecurityManager::get_authentication_timeout(
|
||||
template <class EventHandler>
|
||||
ble_error_t nRF5xSecurityManager<EventHandler>::get_authentication_timeout_(
|
||||
connection_handle_t connection, uint16_t &timeout_in_10ms
|
||||
) {
|
||||
// Return default value for now (30s)
|
||||
|
|
@ -419,7 +437,8 @@ ble_error_t nRF5xSecurityManager::get_authentication_timeout(
|
|||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
||||
ble_error_t nRF5xSecurityManager::set_encryption_key_requirements(
|
||||
template <class EventHandler>
|
||||
ble_error_t nRF5xSecurityManager<EventHandler>::set_encryption_key_requirements_(
|
||||
uint8_t min_encryption_key_size,
|
||||
uint8_t max_encryption_key_size
|
||||
) {
|
||||
|
|
@ -434,7 +453,8 @@ ble_error_t nRF5xSecurityManager::set_encryption_key_requirements(
|
|||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
||||
ble_error_t nRF5xSecurityManager::slave_security_request(
|
||||
template <class EventHandler>
|
||||
ble_error_t nRF5xSecurityManager<EventHandler>::slave_security_request_(
|
||||
connection_handle_t connection,
|
||||
AuthenticationMask authentication
|
||||
) {
|
||||
|
|
@ -460,7 +480,8 @@ ble_error_t nRF5xSecurityManager::slave_security_request(
|
|||
// Encryption
|
||||
//
|
||||
|
||||
ble_error_t nRF5xSecurityManager::enable_encryption(
|
||||
template <class EventHandler>
|
||||
ble_error_t nRF5xSecurityManager<EventHandler>::enable_encryption_(
|
||||
connection_handle_t connection,
|
||||
const ltk_t <k,
|
||||
const rand_t &rand,
|
||||
|
|
@ -488,7 +509,8 @@ ble_error_t nRF5xSecurityManager::enable_encryption(
|
|||
return convert_sd_error(err);
|
||||
}
|
||||
|
||||
ble_error_t nRF5xSecurityManager::enable_encryption(
|
||||
template <class EventHandler>
|
||||
ble_error_t nRF5xSecurityManager<EventHandler>::enable_encryption_(
|
||||
connection_handle_t connection,
|
||||
const ltk_t <k,
|
||||
bool mitm
|
||||
|
|
@ -510,7 +532,8 @@ ble_error_t nRF5xSecurityManager::enable_encryption(
|
|||
return convert_sd_error(err);
|
||||
}
|
||||
|
||||
ble_error_t nRF5xSecurityManager::encrypt_data(
|
||||
template <class EventHandler>
|
||||
ble_error_t nRF5xSecurityManager<EventHandler>::encrypt_data_(
|
||||
const byte_array_t<16> &key,
|
||||
encryption_block_t &data
|
||||
) {
|
||||
|
|
@ -522,7 +545,8 @@ ble_error_t nRF5xSecurityManager::encrypt_data(
|
|||
// Privacy
|
||||
//
|
||||
|
||||
ble_error_t nRF5xSecurityManager::set_private_address_timeout(
|
||||
template <class EventHandler>
|
||||
ble_error_t nRF5xSecurityManager<EventHandler>::set_private_address_timeout_(
|
||||
uint16_t timeout_in_seconds
|
||||
) {
|
||||
// get the previous config
|
||||
|
|
@ -545,7 +569,8 @@ ble_error_t nRF5xSecurityManager::set_private_address_timeout(
|
|||
// Keys
|
||||
//
|
||||
|
||||
ble_error_t nRF5xSecurityManager::set_ltk(
|
||||
template <class EventHandler>
|
||||
ble_error_t nRF5xSecurityManager<EventHandler>::set_ltk_(
|
||||
connection_handle_t connection,
|
||||
const ltk_t& ltk,
|
||||
bool mitm,
|
||||
|
|
@ -568,7 +593,8 @@ ble_error_t nRF5xSecurityManager::set_ltk(
|
|||
return convert_sd_error(err);
|
||||
}
|
||||
|
||||
ble_error_t nRF5xSecurityManager::set_ltk_not_found(
|
||||
template <class EventHandler>
|
||||
ble_error_t nRF5xSecurityManager<EventHandler>::set_ltk_not_found_(
|
||||
connection_handle_t connection
|
||||
) {
|
||||
uint32_t err = sd_ble_gap_sec_info_reply(
|
||||
|
|
@ -581,7 +607,8 @@ ble_error_t nRF5xSecurityManager::set_ltk_not_found(
|
|||
return convert_sd_error(err);
|
||||
}
|
||||
|
||||
ble_error_t nRF5xSecurityManager::set_irk(const irk_t& irk)
|
||||
template <class EventHandler>
|
||||
ble_error_t nRF5xSecurityManager<EventHandler>::set_irk_(const irk_t& irk)
|
||||
{
|
||||
// get the previous config
|
||||
ble_gap_irk_t sd_irk;
|
||||
|
|
@ -600,7 +627,8 @@ ble_error_t nRF5xSecurityManager::set_irk(const irk_t& irk)
|
|||
return convert_sd_error(err);
|
||||
}
|
||||
|
||||
ble_error_t nRF5xSecurityManager::set_csrk(
|
||||
template <class EventHandler>
|
||||
ble_error_t nRF5xSecurityManager<EventHandler>::set_csrk_(
|
||||
const csrk_t& csrk,
|
||||
sign_count_t sign_counter
|
||||
) {
|
||||
|
|
@ -609,7 +637,8 @@ ble_error_t nRF5xSecurityManager::set_csrk(
|
|||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
||||
ble_error_t nRF5xSecurityManager::set_peer_csrk(
|
||||
template <class EventHandler>
|
||||
ble_error_t nRF5xSecurityManager<EventHandler>::set_peer_csrk_(
|
||||
connection_handle_t connection,
|
||||
const csrk_t &csrk,
|
||||
bool authenticated,
|
||||
|
|
@ -618,7 +647,8 @@ ble_error_t nRF5xSecurityManager::set_peer_csrk(
|
|||
return BLE_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
ble_error_t nRF5xSecurityManager::remove_peer_csrk(connection_handle_t connection)
|
||||
template <class EventHandler>
|
||||
ble_error_t nRF5xSecurityManager<EventHandler>::remove_peer_csrk_(connection_handle_t connection)
|
||||
{
|
||||
return BLE_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
|
@ -627,7 +657,8 @@ ble_error_t nRF5xSecurityManager::remove_peer_csrk(connection_handle_t connectio
|
|||
// Authentication
|
||||
//
|
||||
|
||||
ble_error_t nRF5xSecurityManager::get_random_data(byte_array_t<8> &random_data)
|
||||
template <class EventHandler>
|
||||
ble_error_t nRF5xSecurityManager<EventHandler>::get_random_data_(byte_array_t<8> &random_data)
|
||||
{
|
||||
uint32_t err = sd_rand_application_vector_get(
|
||||
random_data.data(), random_data.size()
|
||||
|
|
@ -639,7 +670,8 @@ ble_error_t nRF5xSecurityManager::get_random_data(byte_array_t<8> &random_data)
|
|||
// MITM
|
||||
//
|
||||
|
||||
ble_error_t nRF5xSecurityManager::set_display_passkey(passkey_num_t passkey)
|
||||
template <class EventHandler>
|
||||
ble_error_t nRF5xSecurityManager<EventHandler>::set_display_passkey_(passkey_num_t passkey)
|
||||
{
|
||||
PasskeyAscii passkey_ascii(passkey);
|
||||
ble_opt_t sd_passkey;
|
||||
|
|
@ -649,7 +681,8 @@ ble_error_t nRF5xSecurityManager::set_display_passkey(passkey_num_t passkey)
|
|||
}
|
||||
|
||||
|
||||
ble_error_t nRF5xSecurityManager::passkey_request_reply(
|
||||
template <class EventHandler>
|
||||
ble_error_t nRF5xSecurityManager<EventHandler>::passkey_request_reply_(
|
||||
connection_handle_t connection, const passkey_num_t passkey
|
||||
) {
|
||||
pairing_control_block_t* pairing_cb = get_pairing_cb(connection);
|
||||
|
|
@ -667,7 +700,8 @@ ble_error_t nRF5xSecurityManager::passkey_request_reply(
|
|||
return convert_sd_error(err);
|
||||
}
|
||||
|
||||
ble_error_t nRF5xSecurityManager::secure_connections_oob_request_reply(
|
||||
template <class EventHandler>
|
||||
ble_error_t nRF5xSecurityManager<EventHandler>::secure_connections_oob_request_reply_(
|
||||
connection_handle_t connection,
|
||||
const oob_lesc_value_t &local_random,
|
||||
const oob_lesc_value_t &peer_random,
|
||||
|
|
@ -698,7 +732,8 @@ ble_error_t nRF5xSecurityManager::secure_connections_oob_request_reply(
|
|||
return convert_sd_error(err);
|
||||
}
|
||||
|
||||
ble_error_t nRF5xSecurityManager::legacy_pairing_oob_request_reply(
|
||||
template <class EventHandler>
|
||||
ble_error_t nRF5xSecurityManager<EventHandler>::legacy_pairing_oob_request_reply_(
|
||||
connection_handle_t connection,
|
||||
const oob_tk_t& oob_data
|
||||
) {
|
||||
|
|
@ -711,7 +746,8 @@ ble_error_t nRF5xSecurityManager::legacy_pairing_oob_request_reply(
|
|||
return convert_sd_error(err);
|
||||
}
|
||||
|
||||
ble_error_t nRF5xSecurityManager::confirmation_entered(
|
||||
template <class EventHandler>
|
||||
ble_error_t nRF5xSecurityManager<EventHandler>::confirmation_entered_(
|
||||
connection_handle_t connection, bool confirmation
|
||||
) {
|
||||
pairing_control_block_t* pairing_cb = get_pairing_cb(connection);
|
||||
|
|
@ -728,7 +764,8 @@ ble_error_t nRF5xSecurityManager::confirmation_entered(
|
|||
return convert_sd_error(err);
|
||||
}
|
||||
|
||||
ble_error_t nRF5xSecurityManager::send_keypress_notification(
|
||||
template <class EventHandler>
|
||||
ble_error_t nRF5xSecurityManager<EventHandler>::send_keypress_notification_(
|
||||
connection_handle_t connection, Keypress_t keypress
|
||||
) {
|
||||
uint32_t err = sd_ble_gap_keypress_notify(
|
||||
|
|
@ -738,8 +775,8 @@ ble_error_t nRF5xSecurityManager::send_keypress_notification(
|
|||
return convert_sd_error(err);
|
||||
}
|
||||
|
||||
|
||||
ble_error_t nRF5xSecurityManager::generate_secure_connections_oob()
|
||||
template <class EventHandler>
|
||||
ble_error_t nRF5xSecurityManager<EventHandler>::generate_secure_connections_oob_()
|
||||
{
|
||||
#if defined(MBEDTLS_ECDH_C)
|
||||
ble_gap_lesc_p256_pk_t own_secret;
|
||||
|
|
@ -754,7 +791,7 @@ ble_error_t nRF5xSecurityManager::generate_secure_connections_oob()
|
|||
);
|
||||
|
||||
if (!err) {
|
||||
get_event_handler()->on_secure_connections_oob_generated(
|
||||
this->get_event_handler()->on_secure_connections_oob_generated(
|
||||
oob_data.r,
|
||||
oob_data.c
|
||||
);
|
||||
|
|
@ -765,16 +802,18 @@ ble_error_t nRF5xSecurityManager::generate_secure_connections_oob()
|
|||
return BLE_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nRF5xSecurityManager& nRF5xSecurityManager::get_security_manager()
|
||||
template <class EventHandler>
|
||||
nRF5xSecurityManager<EventHandler>& nRF5xSecurityManager<EventHandler>::get_security_manager()
|
||||
{
|
||||
static nRF5xSecurityManager _security_manager;
|
||||
return _security_manager;
|
||||
}
|
||||
|
||||
bool nRF5xSecurityManager::sm_handler(const ble_evt_t *evt)
|
||||
template<class EventHandler>
|
||||
bool nRF5xSecurityManager<EventHandler>::sm_handler(const ble_evt_t *evt)
|
||||
{
|
||||
nRF5xSecurityManager& self = nRF5xSecurityManager::get_security_manager();
|
||||
SecurityManager::EventHandler* handler = self.get_event_handler();
|
||||
EventHandler* handler = self.get_event_handler();
|
||||
|
||||
if ((evt == NULL) || (handler == NULL)) {
|
||||
return false;
|
||||
|
|
@ -1097,7 +1136,8 @@ bool nRF5xSecurityManager::sm_handler(const ble_evt_t *evt)
|
|||
}
|
||||
}
|
||||
|
||||
ble_gap_sec_params_t nRF5xSecurityManager::make_security_params(
|
||||
template<class EventHandler>
|
||||
ble_gap_sec_params_t nRF5xSecurityManager<EventHandler>::make_security_params(
|
||||
bool oob_data_flag,
|
||||
AuthenticationMask authentication_requirements,
|
||||
KeyDistribution initiator_dist,
|
||||
|
|
@ -1128,7 +1168,8 @@ ble_gap_sec_params_t nRF5xSecurityManager::make_security_params(
|
|||
return security_params;
|
||||
}
|
||||
|
||||
ble_gap_sec_keyset_t nRF5xSecurityManager::make_keyset(
|
||||
template<class EventHandler>
|
||||
ble_gap_sec_keyset_t nRF5xSecurityManager<EventHandler>::make_keyset(
|
||||
pairing_control_block_t& pairing_cb,
|
||||
KeyDistribution initiator_dist,
|
||||
KeyDistribution responder_dist
|
||||
|
|
@ -1175,8 +1216,9 @@ ble_gap_sec_keyset_t nRF5xSecurityManager::make_keyset(
|
|||
return keyset;
|
||||
}
|
||||
|
||||
nRF5xSecurityManager::pairing_control_block_t*
|
||||
nRF5xSecurityManager::allocate_pairing_cb(connection_handle_t connection)
|
||||
template <class EventHandler>
|
||||
typename nRF5xSecurityManager<EventHandler>::pairing_control_block_t*
|
||||
nRF5xSecurityManager<EventHandler>::allocate_pairing_cb(connection_handle_t connection)
|
||||
{
|
||||
pairing_control_block_t* pairing_cb =
|
||||
new (std::nothrow) pairing_control_block_t();
|
||||
|
|
@ -1187,7 +1229,8 @@ nRF5xSecurityManager::allocate_pairing_cb(connection_handle_t connection)
|
|||
return pairing_cb;
|
||||
}
|
||||
|
||||
void nRF5xSecurityManager::release_pairing_cb(pairing_control_block_t* pairing_cb)
|
||||
template <class EventHandler>
|
||||
void nRF5xSecurityManager<EventHandler>::release_pairing_cb(pairing_control_block_t* pairing_cb)
|
||||
{
|
||||
if (pairing_cb == _control_blocks) {
|
||||
_control_blocks = _control_blocks->next;
|
||||
|
|
@ -1205,8 +1248,9 @@ void nRF5xSecurityManager::release_pairing_cb(pairing_control_block_t* pairing_c
|
|||
}
|
||||
}
|
||||
|
||||
nRF5xSecurityManager::pairing_control_block_t*
|
||||
nRF5xSecurityManager::get_pairing_cb(connection_handle_t connection)
|
||||
template <class EventHandler>
|
||||
typename nRF5xSecurityManager<EventHandler>::pairing_control_block_t*
|
||||
nRF5xSecurityManager<EventHandler>::get_pairing_cb(connection_handle_t connection)
|
||||
{
|
||||
pairing_control_block_t* pcb = _control_blocks;
|
||||
while (pcb) {
|
||||
|
|
@ -1219,7 +1263,8 @@ nRF5xSecurityManager::get_pairing_cb(connection_handle_t connection)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void nRF5xSecurityManager::release_all_pairing_cb()
|
||||
template <class EventHandler>
|
||||
void nRF5xSecurityManager<EventHandler>::release_all_pairing_cb()
|
||||
{
|
||||
while(_control_blocks) {
|
||||
release_pairing_cb(_control_blocks);
|
||||
|
|
@ -32,6 +32,7 @@ extern "C" {
|
|||
}
|
||||
|
||||
#include "nRF5xPalGattClient.h"
|
||||
#include "DummySigningEventMonitor.h"
|
||||
|
||||
/**
|
||||
* The singleton which represents the nRF51822 transport for the BLE.
|
||||
|
|
@ -62,7 +63,7 @@ nRF5xn::nRF5xn(void) :
|
|||
instanceID(BLE::DEFAULT_INSTANCE),
|
||||
gapInstance(),
|
||||
gattServerInstance(NULL),
|
||||
gattClient(&(ble::pal::vendor::nordic::nRF5xGattClient::get_client()))
|
||||
gattClient(&(ble::impl::PalGattClient::get_client()))
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -208,13 +209,14 @@ SecurityManager& nRF5xn::getSecurityManager()
|
|||
|
||||
const SecurityManager& nRF5xn::getSecurityManager() const
|
||||
{
|
||||
ble::pal::vendor::nordic::nRF5xSecurityManager &m_pal =
|
||||
ble::pal::vendor::nordic::nRF5xSecurityManager::get_security_manager();
|
||||
static struct : ble::pal::SigningEventMonitor {
|
||||
virtual void set_signing_event_handler(EventHandler *signing_event_handler) { }
|
||||
} dummy_signing_event_monitor;
|
||||
ble::impl::PalSecurityManagerImpl &m_pal =
|
||||
ble::impl::PalSecurityManagerImpl::get_security_manager();
|
||||
|
||||
static ble::generic::GenericSecurityManager m_instance(
|
||||
static ble::vendor::nordic::DummySigningEventMonitor<
|
||||
ble::impl::GenericSecurityManagerImpl
|
||||
> dummy_signing_event_monitor;
|
||||
|
||||
static ble::impl::GenericSecurityManagerImpl m_instance(
|
||||
m_pal,
|
||||
const_cast<nRF5xGap&>(getGap()),
|
||||
dummy_signing_event_monitor
|
||||
|
|
|
|||
|
|
@ -148,8 +148,7 @@ private:
|
|||
* If NULL, then GattServer has not been initialized.
|
||||
* The pointer has been declared as 'mutable' so that
|
||||
* it can be assigned inside a 'const' function. */
|
||||
ble::generic::GenericGattClient gattClient;
|
||||
|
||||
ble::impl::GenericGattClientImpl gattClient;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue