diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/BleImplementation.cpp b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/BleImplementation.cpp new file mode 100644 index 0000000000..6a9c1818d8 --- /dev/null +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/BleImplementation.cpp @@ -0,0 +1,89 @@ +/* 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 "nRF5xPalGattClient.tpp" + +#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 "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; + +// GAP + +// Instantiated in nRF5xGap.cpp as a workaround for ARMCC5 +//template class ble::interface::LegacyGap; +//template class ble::interface::Gap; diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/BleImplementationForward.h b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/BleImplementationForward.h new file mode 100644 index 0000000000..ed637d7a29 --- /dev/null +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/BleImplementationForward.h @@ -0,0 +1,151 @@ +/* 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 LegacyGap; + + template + class Gap; + + template + class GattClient; + + template + class SecurityManager; + + template + class GattServer; + + } // namespace interface + + + namespace generic { + + template < + template class TPalSecurityManager, + template class SigningMonitor + > + class GenericSecurityManager; + + template< + template class TPalGattClient, + class SigningMonitorEventHandler + > + class GenericGattClient; + + } // namespace generic + + + namespace pal { + + template + class SecurityManager; + + template + class SigningMonitorEventHandler; + + template + class ConnectionEventMonitorEventHandler; + + namespace vendor { + namespace nordic { + + template + class nRF5xSecurityManager; + + template + class nRF5xGattClient; + + } // nordic + } // vendor + } // pal + + namespace vendor { + namespace nordic { + + template + 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 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 LegacyGap; + + typedef interface::Gap Gap; + + // GATT CLIENT + + typedef generic::GenericGattClient< + ble::pal::vendor::nordic::nRF5xGattClient, + SigningEventHandler + > GenericGattClientImpl; + + typedef ble::pal::vendor::nordic::nRF5xGattClient< + GenericGattClientImpl + > PalGattClientImpl; + + // construct the final GattClient type + typedef interface::GattClient GattClient; + + + // GATT SERVER + typedef ble::interface::GattServer GattServer; + } // impl +} // ble + + +#endif //BLE_IMPLEMENTATION_FORWARD_H_ diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/DummySigningEventMonitor.h b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/DummySigningEventMonitor.h new file mode 100644 index 0000000000..224b28c5ce --- /dev/null +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/DummySigningEventMonitor.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 +struct DummySigningEventMonitor : + public ble::pal::SigningEventMonitor, Handler > +{ + void set_signing_event_handler_(Handler *signing_event_handler) + { + } +}; + +} // nordic +} // vendor +} // ble + + +#endif //NRF5X_DUMMYSIGNINGEVENTMONITOR_H diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/btle/btle.cpp b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/btle/btle.cpp index 7fc6bba930..eb52252635 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/btle/btle.cpp +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/btle/btle.cpp @@ -281,13 +281,14 @@ void btle_handler(const 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::PalGattClientImpl::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) { @@ -324,7 +325,7 @@ void btle_handler(const 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::PalGattClientImpl::handle_connection_termination(handle); #endif gap.processDisconnectionEvent(handle, reason); @@ -417,7 +418,7 @@ void btle_handler(const ble_evt_t *p_ble_evt) const ble_gattc_evt_exchange_mtu_rsp_t &update = p_ble_evt->evt.gattc_evt.params.exchange_mtu_rsp; - nRF5xGattClient &gatt_client = (nRF5xGattClient&) ble.getGattClient(); + ble::impl::PalGattClientImpl &gatt_client = (ble::impl::PalGattClientImpl&) ble.getGattClient(); if (gatt_client.get_event_handler()) { gatt_client.get_event_handler()->on_att_mtu_change( connection, diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xGap.cpp b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xGap.cpp index 9b2ef6ee4a..0e0d604ac1 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xGap.cpp +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xGap.cpp @@ -26,8 +26,19 @@ #include "headers/ble_hci.h" #include "ble/pal/ConnectionEventMonitor.h" #include "nRF5xPalSecurityManager.h" +#include "BleImplementationForward.h" #include +// 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 them here. + +#include "source/gap/Gap.tpp" +#include "source/LegacyGap.tpp" + +template class ble::interface::LegacyGap; +template class ble::interface::Gap; + using ble::pal::vendor::nordic::nRF5xSecurityManager; using ble::ArrayView; using ble::pal::advertising_peer_address_type_t; @@ -38,8 +49,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() { @@ -144,14 +155,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), @@ -199,7 +209,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) { @@ -264,7 +274,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}; @@ -387,7 +397,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; @@ -447,7 +457,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; } @@ -472,7 +482,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); @@ -482,7 +492,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, @@ -534,7 +544,7 @@ ble_error_t nRF5xGap::connect( } -ble_error_t nRF5xGap::connect( +ble_error_t nRF5xGap::connect_( const Address_t peerAddr, LegacyAddressType_t peerAddrType, const ConnectionParams_t *connectionParams, @@ -553,7 +563,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) { @@ -678,7 +688,7 @@ ble_error_t nRF5xGap::connect( } } -ble_error_t nRF5xGap::readPhy(Handle_t connection) { +ble_error_t nRF5xGap::readPhy_(Handle_t connection) { /* * This function is not implemented as it is not possible with current * nordic API to know which phy was used to establish the connection. @@ -688,7 +698,7 @@ ble_error_t nRF5xGap::readPhy(Handle_t connection) { return BLE_ERROR_NOT_IMPLEMENTED; } -ble_error_t nRF5xGap::setPreferredPhys( +ble_error_t nRF5xGap::setPreferredPhys_( const ble::phy_set_t* txPhys, const ble::phy_set_t* rxPhys ) { @@ -725,7 +735,7 @@ ble_error_t nRF5xGap::setPreferredPhys( return BLE_ERROR_NONE; } -ble_error_t nRF5xGap::setPhy( +ble_error_t nRF5xGap::setPhy_( Handle_t connection, const ble::phy_set_t* txPhys, const ble::phy_set_t* rxPhys, @@ -759,7 +769,7 @@ ble_error_t nRF5xGap::setPhy( #endif } -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) { @@ -787,12 +797,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(params)), @@ -801,7 +811,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(params)), @@ -810,7 +820,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; @@ -832,10 +842,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::reset_() != BLE_ERROR_NONE) { return BLE_ERROR_INVALID_STATE; } @@ -843,8 +853,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; @@ -891,7 +901,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 @@ -933,7 +943,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) { // FIXME: check if privacy is enabled ? if (typeP == NULL || address == NULL) { @@ -966,7 +976,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 @@ -978,7 +988,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; @@ -987,7 +997,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; @@ -996,7 +1006,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(appearanceP)) == NRF_SUCCESS)) { return BLE_ERROR_NONE; @@ -1006,7 +1016,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) { @@ -1022,7 +1032,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[] = { @@ -1064,7 +1074,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; } @@ -1089,7 +1099,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) { @@ -1133,7 +1143,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; @@ -1199,7 +1209,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; return BLE_ERROR_NONE; @@ -1225,7 +1235,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; @@ -1252,7 +1262,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; } @@ -1270,7 +1280,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; } @@ -1288,7 +1298,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; } @@ -1309,12 +1319,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; @@ -1349,40 +1359,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 @@ -1433,7 +1437,7 @@ ble_error_t nRF5xGap::update_identities_list(bool resolution_enabled) return err ? BLE_ERROR_INVALID_STATE : BLE_ERROR_NONE; } -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) { // set the new connection handle as the _default_ handle in gap setConnectionHandle(handle); @@ -1591,7 +1595,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; } diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xGap.h b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xGap.h index 19273e815c..963c0282c6 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xGap.h +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xGap.h @@ -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,18 +63,23 @@ void radioNotificationStaticCallback(bool param); */ /**************************************************************************/ -class nRF5xGap : public ::Gap, public ble::pal::ConnectionEventMonitor { +class nRF5xGap : + public ble::interface::LegacyGap, + public ble::pal::ConnectionEventMonitor { + 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 { + uint16_t getMinAdvertisingInterval_(void) const { + return GapAdvertisingParams::ADVERTISEMENT_DURATION_UNITS_TO_MS(BLE_GAP_ADV_INTERVAL_MIN); + } + uint16_t getMinNonConnectableAdvertisingInterval_(void) const { #if (NRF_SD_BLE_API_VERSION >= 5) // In SD v5+, non connectable advertising interval is the same as connectable advertising interval // The Mbed infrastructure expects 100ms+ - so for now return that // return getMinAdvertisingInterval(); @@ -82,62 +89,64 @@ public: return GapAdvertisingParams::ADVERTISEMENT_DURATION_UNITS_TO_MS(BLE_GAP_ADV_NONCON_INTERVAL_MIN); #endif } - virtual uint16_t getMaxAdvertisingInterval(void) const {return GapAdvertisingParams::ADVERTISEMENT_DURATION_UNITS_TO_MS(BLE_GAP_ADV_INTERVAL_MAX);} + 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 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); ble_error_t connect(const Address_t, BLEProtocol::AddressType_t peerAddrType, const ConnectionParams_t *connectionParams, const GapScanningParams *scanParams, bool identity); - virtual ble_error_t readPhy(Handle_t connection); - virtual ble_error_t setPreferredPhys( + ble_error_t readPhy_(Handle_t connection); + ble_error_t setPreferredPhys_( const ble::phy_set_t* txPhys, const ble::phy_set_t* rxPhys ); - virtual ble_error_t setPhy( + ble_error_t setPhy_( Handle_t connection, const ble::phy_set_t* txPhys, const ble::phy_set_t* rxPhys, CodedSymbolPerBit_t codedSymbol ); - virtual ble_error_t disconnect(Handle_t connectionHandle, DisconnectionReason_t reason); - virtual ble_error_t disconnect(DisconnectionReason_t reason); + 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; } @@ -145,27 +154,27 @@ 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: @@ -174,8 +183,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; @@ -263,12 +272,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 @@ -288,6 +291,15 @@ public: */ ble_error_t get_role(ble::connection_handle_t connection, Role_t& role); +protected: + // import from Gap + friend ble::interface::Gap; + + using ble::interface::Gap::startAdvertising_; + using ble::interface::Gap::stopAdvertising_; + using ble::interface::Gap::connect_; + using ble::interface::Gap::disconnect_; + private: friend void btle_handler(const ble_evt_t *p_ble_evt); friend void btle_handler(const ble_evt_t *p_ble_evt, void *p_context); @@ -307,7 +319,6 @@ private: #endif uint16_t m_connectionHandle; - ConnectionEventMonitor::EventHandler* _connection_event_handler; bool _privacy_enabled; PeripheralPrivacyConfiguration_t _peripheral_privacy_configuration; diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xGattServer.cpp b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xGattServer.cpp index 821ee59e54..12b013c9f0 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xGattServer.cpp +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xGattServer.cpp @@ -107,7 +107,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 */ @@ -258,12 +258,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, @@ -298,12 +298,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; @@ -395,14 +395,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); } @@ -444,10 +444,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::reset_() != BLE_ERROR_NONE) { return BLE_ERROR_INVALID_STATE; } diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xGattServer.h b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xGattServer.h index 270a211ac2..bc40356f6e 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xGattServer.h +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xGattServer.h @@ -24,18 +24,18 @@ #include "ble/Gap.h" #include "ble/GattServer.h" -class nRF5xGattServer : public GattServer +class nRF5xGattServer : public ble::interface::GattServer { 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); diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xPalGattClient.h b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xPalGattClient.h index 6c298aa3e3..aae819f60d 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xPalGattClient.h +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xPalGattClient.h @@ -34,39 +34,40 @@ namespace nordic { /** * Implementation of pal::GattClient for the Nordic stack. */ -class nRF5xGattClient : public ble::pal::GattClient { +template +class nRF5xGattClient : public ble::pal::GattClient, 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& 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& 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& 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& 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& 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 ); diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xPalGattClient.cpp b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xPalGattClient.tpp similarity index 86% rename from features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xPalGattClient.cpp rename to features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xPalGattClient.tpp index 1778a102f1..fcd5d01b3a 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xPalGattClient.cpp +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xPalGattClient.tpp @@ -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: @@ -135,7 +135,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(); @@ -161,30 +161,34 @@ static const size_t characteristic_declaration_length = 1 + 2 + 16; } // end of anonymous namespace -nRF5xGattClient::nRF5xGattClient() : - ble::pal::GattClient(), +template +nRF5xGattClient::nRF5xGattClient() : _procedures() { } -nRF5xGattClient::~nRF5xGattClient() +template +nRF5xGattClient::~nRF5xGattClient() { - terminate(); + this->terminate(); } -ble_error_t nRF5xGattClient::initialize() +template +ble_error_t nRF5xGattClient::initialize_() { return BLE_ERROR_NONE; } -ble_error_t nRF5xGattClient::exchange_mtu(connection_handle_t connection) +template +ble_error_t nRF5xGattClient::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 +ble_error_t nRF5xGattClient::get_mtu_size_( connection_handle_t connection_handle, uint16_t& mtu_size ) { #if (NRF_SD_BLE_API_VERSION >= 3) @@ -197,7 +201,8 @@ ble_error_t nRF5xGattClient::get_mtu_size( return BLE_ERROR_NONE; } -ble_error_t nRF5xGattClient::discover_primary_service( +template +ble_error_t nRF5xGattClient::discover_primary_service_( connection_handle_t connection, attribute_handle_t discovery_range_begining ) { @@ -206,7 +211,8 @@ ble_error_t nRF5xGattClient::discover_primary_service( ); } -ble_error_t nRF5xGattClient::discover_primary_service_by_service_uuid( +template +ble_error_t nRF5xGattClient::discover_primary_service_by_service_uuid_( connection_handle_t connection_handle, attribute_handle_t discovery_range_beginning, const UUID& uuid @@ -216,7 +222,8 @@ ble_error_t nRF5xGattClient::discover_primary_service_by_service_uuid( ); } -ble_error_t nRF5xGattClient::find_included_service( +template +ble_error_t nRF5xGattClient::find_included_service_( connection_handle_t connection_handle, attribute_handle_range_t service_range ) { @@ -225,7 +232,8 @@ ble_error_t nRF5xGattClient::find_included_service( ); } -ble_error_t nRF5xGattClient::discover_characteristics_of_a_service( +template +ble_error_t nRF5xGattClient::discover_characteristics_of_a_service_( connection_handle_t connection_handle, attribute_handle_range_t discovery_range ) { @@ -234,7 +242,8 @@ ble_error_t nRF5xGattClient::discover_characteristics_of_a_service( ); } -ble_error_t nRF5xGattClient::discover_characteristics_descriptors( +template +ble_error_t nRF5xGattClient::discover_characteristics_descriptors_( connection_handle_t connection_handle, attribute_handle_range_t descriptors_discovery_range ) { @@ -243,7 +252,8 @@ ble_error_t nRF5xGattClient::discover_characteristics_descriptors( ); } -ble_error_t nRF5xGattClient::read_attribute_value( +template +ble_error_t nRF5xGattClient::read_attribute_value_( connection_handle_t connection_handle, attribute_handle_t attribute_handle ) { @@ -252,7 +262,8 @@ ble_error_t nRF5xGattClient::read_attribute_value( ); } -ble_error_t nRF5xGattClient::read_using_characteristic_uuid( +template +ble_error_t nRF5xGattClient::read_using_characteristic_uuid_( connection_handle_t connection_handle, attribute_handle_range_t read_range, const UUID& uuid @@ -262,7 +273,8 @@ ble_error_t nRF5xGattClient::read_using_characteristic_uuid( ); } -ble_error_t nRF5xGattClient::read_attribute_blob( +template +ble_error_t nRF5xGattClient::read_attribute_blob_( connection_handle_t connection, attribute_handle_t attribute_handle, uint16_t offset @@ -272,7 +284,8 @@ ble_error_t nRF5xGattClient::read_attribute_blob( ); } -ble_error_t nRF5xGattClient::read_multiple_characteristic_values( +template +ble_error_t nRF5xGattClient::read_multiple_characteristic_values_( connection_handle_t connection, const ArrayView& characteristic_handles ) { @@ -281,7 +294,8 @@ ble_error_t nRF5xGattClient::read_multiple_characteristic_values( ); } -ble_error_t nRF5xGattClient::write_without_response( +template +ble_error_t nRF5xGattClient::write_without_response_( connection_handle_t connection_handle, attribute_handle_t characteristic_value_handle, const ArrayView& value @@ -296,10 +310,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 +ble_error_t nRF5xGattClient::signed_write_without_response_( connection_handle_t connection_handle, attribute_handle_t characteristic_value_handle, const ArrayView& value @@ -314,10 +329,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 +ble_error_t nRF5xGattClient::write_attribute_( connection_handle_t connection_handle, attribute_handle_t attribute_handle, const ArrayView& value @@ -327,7 +343,8 @@ ble_error_t nRF5xGattClient::write_attribute( ); } -ble_error_t nRF5xGattClient::queue_prepare_write( +template +ble_error_t nRF5xGattClient::queue_prepare_write_( connection_handle_t connection_handle, attribute_handle_t characteristic_value_handle, const ArrayView& value, @@ -338,7 +355,8 @@ ble_error_t nRF5xGattClient::queue_prepare_write( ); } -ble_error_t nRF5xGattClient::execute_write_queue( +template +ble_error_t nRF5xGattClient::execute_write_queue_( connection_handle_t connection_handle, bool execute ) { @@ -369,7 +387,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 +struct nRF5xGattClient::GattProcedure { /** * Initialize the procedure. * @@ -426,7 +445,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 +struct nRF5xGattClient::RegularGattProcedure : GattProcedure { + + using GattProcedure::procedure_opcode; + using GattProcedure::connection_handle; + using GattProcedure::terminate; /** * Construct a RegularGattProcedure. @@ -485,8 +509,12 @@ protected: * In such case a read request is issued for each service attribute handle * to extract that information. */ -struct nRF5xGattClient::DiscoverPrimaryServiceProcedure : GattProcedure { +template +struct nRF5xGattClient::DiscoverPrimaryServiceProcedure : GattProcedure { + using GattProcedure::procedure_opcode; + using GattProcedure::connection_handle; + using GattProcedure::terminate; typedef ArrayView services_array_t; DiscoverPrimaryServiceProcedure(connection_handle_t connection) : @@ -505,7 +533,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); } /** @@ -694,8 +722,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 +struct nRF5xGattClient::DiscoverPrimaryServiceByUUIDProcedure : RegularGattProcedure { + using GattProcedure::procedure_opcode; + using GattProcedure::connection_handle; + using GattProcedure::terminate; typedef ArrayView services_array_t; DiscoverPrimaryServiceByUUIDProcedure(connection_handle_t connection) : @@ -721,7 +753,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) @@ -768,8 +800,12 @@ struct nRF5xGattClient::DiscoverPrimaryServiceByUUIDProcedure : RegularGattProce /** * Procedure that manage Find Included Services transactions. */ -struct nRF5xGattClient::FindIncludedServicesProcedure : RegularGattProcedure { +template +struct nRF5xGattClient::FindIncludedServicesProcedure : RegularGattProcedure { + using GattProcedure::procedure_opcode; + using GattProcedure::connection_handle; + using GattProcedure::terminate; typedef ArrayView services_array_t; FindIncludedServicesProcedure(connection_handle_t connection) : @@ -786,7 +822,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) @@ -843,7 +879,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 +struct nRF5xGattClient::DiscoverCharacteristicsProcedure : GattProcedure { + + using GattProcedure::procedure_opcode; + using GattProcedure::connection_handle; + using GattProcedure::terminate; /** * Data structure returned by the function flatten_response. */ @@ -872,7 +913,7 @@ struct nRF5xGattClient::DiscoverCharacteristicsProcedure : GattProcedure { &range ); - return convert_sd_error(err); + return client_convert_sd_error(err); } /** @@ -1062,7 +1103,13 @@ struct nRF5xGattClient::DiscoverCharacteristicsProcedure : GattProcedure { /** * Procedure that handle discovery of characteristic descriptors. */ -struct nRF5xGattClient::DiscoverDescriptorsProcedure : RegularGattProcedure { +template +struct nRF5xGattClient::DiscoverDescriptorsProcedure : RegularGattProcedure { + + using GattProcedure::procedure_opcode; + using GattProcedure::connection_handle; + using GattProcedure::terminate; + DiscoverDescriptorsProcedure(connection_handle_t connection) : RegularGattProcedure( connection, @@ -1079,7 +1126,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) @@ -1153,7 +1200,13 @@ struct nRF5xGattClient::DiscoverDescriptorsProcedure : RegularGattProcedure { /** * Procedure that handle read of attribute handles. */ -struct nRF5xGattClient::ReadAttributeProcedure : RegularGattProcedure { +template +struct nRF5xGattClient::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 @@ -1162,7 +1215,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) @@ -1180,7 +1233,13 @@ struct nRF5xGattClient::ReadAttributeProcedure : RegularGattProcedure { /** * Procedure that handle read of characteristic using characteristic UUID. */ -struct nRF5xGattClient::ReadUsingCharacteristicUUIDProcedure : RegularGattProcedure { +template +struct nRF5xGattClient::ReadUsingCharacteristicUUIDProcedure : RegularGattProcedure { + + using GattProcedure::procedure_opcode; + using GattProcedure::connection_handle; + using GattProcedure::terminate; + ReadUsingCharacteristicUUIDProcedure(connection_handle_t connection) : RegularGattProcedure( connection, @@ -1206,7 +1265,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) @@ -1267,7 +1326,13 @@ struct nRF5xGattClient::ReadUsingCharacteristicUUIDProcedure : RegularGattProced /** * Procedure that handles read blob transactions. */ -struct nRF5xGattClient::ReadAttributeBlobProcedure : RegularGattProcedure { +template +struct nRF5xGattClient::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 @@ -1278,7 +1343,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) @@ -1293,7 +1358,13 @@ struct nRF5xGattClient::ReadAttributeBlobProcedure : RegularGattProcedure { /** * Procedure that handles Read Multiple Characteristic Values transactions. */ -struct nRF5xGattClient::ReadMultipleCharacteristicsProcedure : RegularGattProcedure { +template +struct nRF5xGattClient::ReadMultipleCharacteristicsProcedure : RegularGattProcedure { + + using GattProcedure::procedure_opcode; + using GattProcedure::connection_handle; + using GattProcedure::terminate; + ReadMultipleCharacteristicsProcedure(connection_handle_t connection) : RegularGattProcedure( connection, @@ -1308,7 +1379,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) @@ -1323,7 +1394,13 @@ struct nRF5xGattClient::ReadMultipleCharacteristicsProcedure : RegularGattProced /** * Procedure that handles Write transactions. */ -struct nRF5xGattClient::WriteAttributeProcedure : RegularGattProcedure { +template +struct nRF5xGattClient::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 @@ -1342,7 +1419,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) @@ -1354,7 +1431,13 @@ struct nRF5xGattClient::WriteAttributeProcedure : RegularGattProcedure { /** * Procedure that handles Prepare Write transactions. */ -struct nRF5xGattClient::QueuePrepareWriteProcedure : RegularGattProcedure { +template +struct nRF5xGattClient::QueuePrepareWriteProcedure : RegularGattProcedure { + + using GattProcedure::procedure_opcode; + using GattProcedure::connection_handle; + using GattProcedure::terminate; + QueuePrepareWriteProcedure(connection_handle_t connection) : RegularGattProcedure( connection, @@ -1377,7 +1460,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) @@ -1400,7 +1483,13 @@ struct nRF5xGattClient::QueuePrepareWriteProcedure : RegularGattProcedure { /** * Procedure that handles Execute Write transactions. */ -struct nRF5xGattClient::ExecuteWriteQueueProcedure : RegularGattProcedure { +template +struct nRF5xGattClient::ExecuteWriteQueueProcedure : RegularGattProcedure { + + using GattProcedure::procedure_opcode; + using GattProcedure::connection_handle; + using GattProcedure::terminate; + ExecuteWriteQueueProcedure(connection_handle_t connection) : RegularGattProcedure( connection, @@ -1423,7 +1512,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) @@ -1439,7 +1528,8 @@ struct nRF5xGattClient::ExecuteWriteQueueProcedure : RegularGattProcedure { }; // NOTE: position after declaration of GattProcedure on purpose. -ble_error_t nRF5xGattClient::terminate() +template +ble_error_t nRF5xGattClient::terminate_() { for (size_t i = 0; i < max_procedures_count; ++i) { if (_procedures[i]) { @@ -1451,8 +1541,9 @@ ble_error_t nRF5xGattClient::terminate() return BLE_ERROR_NONE; } +template template -ble_error_t nRF5xGattClient::launch_procedure( +ble_error_t nRF5xGattClient::launch_procedure( connection_handle_t connection, const A0& a0 ) { ProcType* p = new(std::nothrow) ProcType(connection); @@ -1474,8 +1565,9 @@ ble_error_t nRF5xGattClient::launch_procedure( return err; } +template template -ble_error_t nRF5xGattClient::launch_procedure( +ble_error_t nRF5xGattClient::launch_procedure( connection_handle_t connection, const A0& a0, const A1& a1 ) { ProcType* p = new(std::nothrow) ProcType(connection); @@ -1497,8 +1589,9 @@ ble_error_t nRF5xGattClient::launch_procedure( return err; } +template template -ble_error_t nRF5xGattClient::launch_procedure( +ble_error_t nRF5xGattClient::launch_procedure( connection_handle_t connection, const A0& a0, const A1& a1, const A2& a2 ) { @@ -1521,8 +1614,9 @@ ble_error_t nRF5xGattClient::launch_procedure( return err; } +template template -ble_error_t nRF5xGattClient::launch_procedure( +ble_error_t nRF5xGattClient::launch_procedure( connection_handle_t connection, const A0& a0, const A1& a1, const A2& a2, const A3& a3 ) { @@ -1545,7 +1639,8 @@ ble_error_t nRF5xGattClient::launch_procedure( return err; } -nRF5xGattClient::GattProcedure* nRF5xGattClient::get_procedure( +template +typename nRF5xGattClient::GattProcedure* nRF5xGattClient::get_procedure( connection_handle_t connection ) const { for (size_t i = 0; i < max_procedures_count; ++i) { @@ -1556,7 +1651,8 @@ nRF5xGattClient::GattProcedure* nRF5xGattClient::get_procedure( return NULL; } -bool nRF5xGattClient::register_procedure(GattProcedure *p) +template +bool nRF5xGattClient::register_procedure(GattProcedure *p) { if (get_procedure(p->connection_handle)) { return false; @@ -1572,7 +1668,8 @@ bool nRF5xGattClient::register_procedure(GattProcedure *p) return false; } -bool nRF5xGattClient::remove_procedure(nRF5xGattClient::GattProcedure* p) +template +bool nRF5xGattClient::remove_procedure(nRF5xGattClient::GattProcedure* p) { for (size_t i = 0; i < max_procedures_count; ++i) { if (_procedures[i] == p) { @@ -1585,13 +1682,15 @@ bool nRF5xGattClient::remove_procedure(nRF5xGattClient::GattProcedure* p) } // singleton of the ARM Cordio client -nRF5xGattClient& nRF5xGattClient::get_client() +template +nRF5xGattClient& nRF5xGattClient::get_client() { static nRF5xGattClient _client; return _client; } -void nRF5xGattClient::handle_events(const ble_evt_t *evt) { +template +void nRF5xGattClient::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: @@ -1613,7 +1712,8 @@ void nRF5xGattClient::handle_events(const ble_evt_t *evt) { } } -void nRF5xGattClient::handle_procedure_event(const ble_evt_t &evt) +template +void nRF5xGattClient::handle_procedure_event(const ble_evt_t &evt) { GattProcedure* p = get_procedure(evt.evt.gattc_evt.conn_handle); if (p) { @@ -1621,14 +1721,15 @@ void nRF5xGattClient::handle_procedure_event(const ble_evt_t &evt) } } -void nRF5xGattClient::handle_hvx_event(const ble_evt_t &evt) +template +void nRF5xGattClient::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, @@ -1639,7 +1740,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, @@ -1652,7 +1753,8 @@ void nRF5xGattClient::handle_hvx_event(const ble_evt_t &evt) } } -void nRF5xGattClient::handle_timeout_event(const ble_evt_t &evt) +template +void nRF5xGattClient::handle_timeout_event(const ble_evt_t &evt) { connection_handle_t connection = evt.evt.gattc_evt.conn_handle; GattProcedure* p = get_procedure(connection); @@ -1660,10 +1762,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 +void nRF5xGattClient::handle_connection_termination(connection_handle_t connection) { GattProcedure* p = get_client().get_procedure(connection); if (p) { diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xPalSecurityManager.h b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xPalSecurityManager.h index b5a55d9dc0..4a31345b85 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xPalSecurityManager.h +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xPalSecurityManager.h @@ -28,11 +28,17 @@ namespace pal { namespace vendor { namespace nordic { -class nRF5xSecurityManager : public ::ble::pal::SecurityManager { +template +class nRF5xSecurityManager : public ::ble::pal::SecurityManager, EventHandler> { public: + typedef ::ble::pal::SecurityManager< + nRF5xSecurityManager, + 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_(); /** * Return the IRKs present in the resolving list @@ -98,7 +104,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, @@ -109,7 +115,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, @@ -120,7 +126,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 ); @@ -132,14 +138,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 @@ -148,21 +154,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 ); @@ -170,7 +176,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 ); @@ -182,7 +188,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, @@ -193,7 +199,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 @@ -202,7 +208,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 ); @@ -214,7 +220,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 @@ -223,7 +229,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, @@ -233,24 +239,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, @@ -260,7 +266,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 @@ -269,7 +275,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 @@ -278,12 +284,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 ); @@ -291,7 +297,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, @@ -301,7 +307,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 ); @@ -309,21 +315,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(); diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xPalSecurityManager.cpp b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xPalSecurityManager.tpp similarity index 86% rename from features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xPalSecurityManager.cpp rename to features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xPalSecurityManager.tpp index 78904d3312..9a0eb7433a 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xPalSecurityManager.cpp +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xPalSecurityManager.tpp @@ -61,7 +61,8 @@ enum pairing_role_t { PAIRING_RESPONDER }; -struct nRF5xSecurityManager::pairing_control_block_t { +template +struct nRF5xSecurityManager::pairing_control_block_t { pairing_control_block_t* next; connection_handle_t connection; pairing_role_t role; @@ -83,8 +84,8 @@ struct nRF5xSecurityManager::pairing_control_block_t { ble_gap_lesc_p256_pk_t peer_pk; }; -nRF5xSecurityManager::nRF5xSecurityManager() - : ::ble::pal::SecurityManager(), +template +nRF5xSecurityManager::nRF5xSecurityManager() : _sign_counter(), _io_capability(io_capability_t::NO_INPUT_NO_OUTPUT), _min_encryption_key_size(7), @@ -95,7 +96,8 @@ nRF5xSecurityManager::nRF5xSecurityManager() } -nRF5xSecurityManager::~nRF5xSecurityManager() +template +nRF5xSecurityManager::~nRF5xSecurityManager() { terminate(); } @@ -104,7 +106,8 @@ nRF5xSecurityManager::~nRF5xSecurityManager() // SM lifecycle management // -ble_error_t nRF5xSecurityManager::initialize() +template +ble_error_t nRF5xSecurityManager::initialize_() { #if defined(MBEDTLS_ECDH_C) // Note: we do not use the object on the stack as the CryptoToolbox is quite large @@ -122,20 +125,22 @@ ble_error_t nRF5xSecurityManager::initialize() return BLE_ERROR_NONE; } -ble_error_t nRF5xSecurityManager::terminate() +template +ble_error_t nRF5xSecurityManager::terminate_() { release_all_pairing_cb(); return BLE_ERROR_NONE; } -ble_error_t nRF5xSecurityManager::reset() +template +ble_error_t nRF5xSecurityManager::reset_() { - ble_error_t err = terminate(); + ble_error_t err = this->terminate(); if (err) { return err; } - return initialize(); + return this->initialize(); } //////////////////////////////////////////////////////////////////////////// @@ -145,12 +150,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 +uint8_t nRF5xSecurityManager::read_resolving_list_capacity_() { return MAX_RESOLVING_LIST_ENTRIES; } -ble_error_t nRF5xSecurityManager::add_device_to_resolving_list( +template +ble_error_t nRF5xSecurityManager::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 @@ -177,7 +184,8 @@ ble_error_t nRF5xSecurityManager::add_device_to_resolving_list( return BLE_ERROR_NONE; } -ble_error_t nRF5xSecurityManager::remove_device_from_resolving_list( +template +ble_error_t nRF5xSecurityManager::remove_device_from_resolving_list_( advertising_peer_address_type_t peer_identity_address_type, const address_t &peer_identity_address ) { @@ -207,13 +215,15 @@ ble_error_t nRF5xSecurityManager::remove_device_from_resolving_list( return BLE_ERROR_NONE; } -ble_error_t nRF5xSecurityManager::clear_resolving_list() +template +ble_error_t nRF5xSecurityManager::clear_resolving_list_() { resolving_list_entry_count = 0; return BLE_ERROR_NONE; } -ArrayView nRF5xSecurityManager::get_resolving_list() { +template +ArrayView nRF5xSecurityManager::get_resolving_list() { return ArrayView( resolving_list, resolving_list_entry_count @@ -224,8 +234,8 @@ ArrayView nRF5xSecurityManager::get_resolving_list() { // Pairing // - -ble_error_t nRF5xSecurityManager::send_pairing_request( +template +ble_error_t nRF5xSecurityManager::send_pairing_request_( connection_handle_t connection, bool oob_data_flag, AuthenticationMask authentication_requirements, @@ -266,7 +276,8 @@ ble_error_t nRF5xSecurityManager::send_pairing_request( return convert_sd_error(err); } -ble_error_t nRF5xSecurityManager::send_pairing_response( +template +ble_error_t nRF5xSecurityManager::send_pairing_response_( connection_handle_t connection, bool oob_data_flag, AuthenticationMask authentication_requirements, @@ -277,7 +288,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; @@ -317,7 +328,8 @@ ble_error_t nRF5xSecurityManager::send_pairing_response( return convert_sd_error(err); } -ble_error_t nRF5xSecurityManager::cancel_pairing( +template +ble_error_t nRF5xSecurityManager::cancel_pairing_( connection_handle_t connection, pairing_failure_t reason ) { uint32_t err = 0; @@ -361,14 +373,16 @@ ble_error_t nRF5xSecurityManager::cancel_pairing( // Feature support // -ble_error_t nRF5xSecurityManager::get_secure_connections_support( +template +ble_error_t nRF5xSecurityManager::get_secure_connections_support_( bool &enabled ) { enabled = true; return BLE_ERROR_NONE; } -ble_error_t nRF5xSecurityManager::set_io_capability(io_capability_t io_capability) +template +ble_error_t nRF5xSecurityManager::set_io_capability_(io_capability_t io_capability) { _io_capability = io_capability; return BLE_ERROR_NONE; @@ -378,7 +392,8 @@ ble_error_t nRF5xSecurityManager::set_io_capability(io_capability_t io_capabilit // Security settings // -ble_error_t nRF5xSecurityManager::set_authentication_timeout( +template +ble_error_t nRF5xSecurityManager::set_authentication_timeout_( connection_handle_t connection, uint16_t timeout_in_10ms ) { ble_opt_t opt; @@ -388,7 +403,8 @@ ble_error_t nRF5xSecurityManager::set_authentication_timeout( return convert_sd_error(err); } -ble_error_t nRF5xSecurityManager::get_authentication_timeout( +template +ble_error_t nRF5xSecurityManager::get_authentication_timeout_( connection_handle_t connection, uint16_t &timeout_in_10ms ) { ble_opt_t opt; @@ -403,7 +419,8 @@ ble_error_t nRF5xSecurityManager::get_authentication_timeout( return BLE_ERROR_NONE; } -ble_error_t nRF5xSecurityManager::set_encryption_key_requirements( +template +ble_error_t nRF5xSecurityManager::set_encryption_key_requirements_( uint8_t min_encryption_key_size, uint8_t max_encryption_key_size ) { @@ -418,7 +435,8 @@ ble_error_t nRF5xSecurityManager::set_encryption_key_requirements( return BLE_ERROR_NONE; } -ble_error_t nRF5xSecurityManager::slave_security_request( +template +ble_error_t nRF5xSecurityManager::slave_security_request_( connection_handle_t connection, AuthenticationMask authentication ) { @@ -444,7 +462,8 @@ ble_error_t nRF5xSecurityManager::slave_security_request( // Encryption // -ble_error_t nRF5xSecurityManager::enable_encryption( +template +ble_error_t nRF5xSecurityManager::enable_encryption_( connection_handle_t connection, const ltk_t <k, const rand_t &rand, @@ -472,7 +491,8 @@ ble_error_t nRF5xSecurityManager::enable_encryption( return convert_sd_error(err); } -ble_error_t nRF5xSecurityManager::enable_encryption( +template +ble_error_t nRF5xSecurityManager::enable_encryption_( connection_handle_t connection, const ltk_t <k, bool mitm @@ -494,7 +514,8 @@ ble_error_t nRF5xSecurityManager::enable_encryption( return convert_sd_error(err); } -ble_error_t nRF5xSecurityManager::encrypt_data( +template +ble_error_t nRF5xSecurityManager::encrypt_data_( const byte_array_t<16> &key, encryption_block_t &data ) { @@ -515,7 +536,8 @@ ble_error_t nRF5xSecurityManager::encrypt_data( // Privacy // -ble_error_t nRF5xSecurityManager::set_private_address_timeout( +template +ble_error_t nRF5xSecurityManager::set_private_address_timeout_( uint16_t timeout_in_seconds ) { ble_gap_privacy_params_t privacy_config; @@ -535,7 +557,8 @@ ble_error_t nRF5xSecurityManager::set_private_address_timeout( // Keys // -ble_error_t nRF5xSecurityManager::set_ltk( +template +ble_error_t nRF5xSecurityManager::set_ltk_( connection_handle_t connection, const ltk_t& ltk, bool mitm, @@ -558,7 +581,8 @@ ble_error_t nRF5xSecurityManager::set_ltk( return convert_sd_error(err); } -ble_error_t nRF5xSecurityManager::set_ltk_not_found( +template +ble_error_t nRF5xSecurityManager::set_ltk_not_found_( connection_handle_t connection ) { uint32_t err = sd_ble_gap_sec_info_reply( @@ -571,7 +595,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 +ble_error_t nRF5xSecurityManager::set_irk_(const irk_t& irk) { ble_gap_privacy_params_t privacy_config; @@ -588,7 +613,8 @@ ble_error_t nRF5xSecurityManager::set_irk(const irk_t& irk) return convert_sd_error(err); } -ble_error_t nRF5xSecurityManager::set_csrk( +template +ble_error_t nRF5xSecurityManager::set_csrk_( const csrk_t& csrk, sign_count_t sign_counter ) { @@ -597,7 +623,8 @@ ble_error_t nRF5xSecurityManager::set_csrk( return BLE_ERROR_NONE; } -ble_error_t nRF5xSecurityManager::set_peer_csrk( +template +ble_error_t nRF5xSecurityManager::set_peer_csrk_( connection_handle_t connection, const csrk_t &csrk, bool authenticated, @@ -606,7 +633,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 +ble_error_t nRF5xSecurityManager::remove_peer_csrk_(connection_handle_t connection) { return BLE_ERROR_NOT_IMPLEMENTED; } @@ -614,7 +642,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 +ble_error_t nRF5xSecurityManager::get_random_data_(byte_array_t<8> &random_data) { uint32_t err = sd_rand_application_vector_get( random_data.data(), random_data.size() @@ -626,7 +655,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 +ble_error_t nRF5xSecurityManager::set_display_passkey_(passkey_num_t passkey) { PasskeyAscii passkey_ascii(passkey); ble_opt_t sd_passkey; @@ -635,8 +665,8 @@ ble_error_t nRF5xSecurityManager::set_display_passkey(passkey_num_t passkey) return convert_sd_error(err); } - -ble_error_t nRF5xSecurityManager::passkey_request_reply( +template +ble_error_t nRF5xSecurityManager::passkey_request_reply_( connection_handle_t connection, const passkey_num_t passkey ) { pairing_control_block_t* pairing_cb = get_pairing_cb(connection); @@ -654,7 +684,8 @@ ble_error_t nRF5xSecurityManager::passkey_request_reply( return convert_sd_error(err); } -ble_error_t nRF5xSecurityManager::secure_connections_oob_request_reply( +template +ble_error_t nRF5xSecurityManager::secure_connections_oob_request_reply_( connection_handle_t connection, const oob_lesc_value_t &local_random, const oob_lesc_value_t &peer_random, @@ -696,7 +727,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 +ble_error_t nRF5xSecurityManager::legacy_pairing_oob_request_reply_( connection_handle_t connection, const oob_tk_t& oob_data ) { @@ -709,7 +741,8 @@ ble_error_t nRF5xSecurityManager::legacy_pairing_oob_request_reply( return convert_sd_error(err); } -ble_error_t nRF5xSecurityManager::confirmation_entered( +template +ble_error_t nRF5xSecurityManager::confirmation_entered_( connection_handle_t connection, bool confirmation ) { pairing_control_block_t* pairing_cb = get_pairing_cb(connection); @@ -726,7 +759,8 @@ ble_error_t nRF5xSecurityManager::confirmation_entered( return convert_sd_error(err); } -ble_error_t nRF5xSecurityManager::send_keypress_notification( +template +ble_error_t nRF5xSecurityManager::send_keypress_notification_( connection_handle_t connection, Keypress_t keypress ) { uint32_t err = sd_ble_gap_keypress_notify( @@ -736,8 +770,8 @@ ble_error_t nRF5xSecurityManager::send_keypress_notification( return convert_sd_error(err); } - -ble_error_t nRF5xSecurityManager::generate_secure_connections_oob() +template +ble_error_t nRF5xSecurityManager::generate_secure_connections_oob_() { #if defined(MBEDTLS_ECDH_C) ble_gap_lesc_p256_pk_t own_secret; @@ -754,7 +788,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,7 +799,8 @@ ble_error_t nRF5xSecurityManager::generate_secure_connections_oob() return BLE_ERROR_NOT_IMPLEMENTED; } -nRF5xSecurityManager& nRF5xSecurityManager::get_security_manager() +template +nRF5xSecurityManager& nRF5xSecurityManager::get_security_manager() { static nRF5xSecurityManager _security_manager; return _security_manager; @@ -789,10 +824,11 @@ bool is_ediv_rand_valid(const uint16_t ediv, const uint8_t* rand) return false; } -bool nRF5xSecurityManager::sm_handler(const ble_evt_t *evt) +template +bool nRF5xSecurityManager::sm_handler(const ble_evt_t *evt) { - nRF5xSecurityManager& self = nRF5xSecurityManager::get_security_manager(); - SecurityManager::EventHandler* handler = self.get_event_handler(); + nRF5xSecurityManager& self = nRF5xSecurityManager::get_security_manager(); + EventHandler* handler = self.get_event_handler(); if ((evt == NULL) || (handler == NULL)) { return false; @@ -1145,7 +1181,8 @@ bool nRF5xSecurityManager::sm_handler(const ble_evt_t *evt) } } -ble_gap_sec_params_t nRF5xSecurityManager::make_security_params( +template +ble_gap_sec_params_t nRF5xSecurityManager::make_security_params( bool oob_data_flag, AuthenticationMask authentication_requirements, KeyDistribution initiator_dist, @@ -1176,7 +1213,8 @@ ble_gap_sec_params_t nRF5xSecurityManager::make_security_params( return security_params; } -ble_gap_sec_keyset_t nRF5xSecurityManager::make_keyset( +template +ble_gap_sec_keyset_t nRF5xSecurityManager::make_keyset( pairing_control_block_t& pairing_cb, KeyDistribution initiator_dist, KeyDistribution responder_dist @@ -1212,8 +1250,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 +typename nRF5xSecurityManager::pairing_control_block_t* +nRF5xSecurityManager::allocate_pairing_cb(connection_handle_t connection) { pairing_control_block_t* pairing_cb = new (std::nothrow) pairing_control_block_t(); @@ -1224,7 +1263,8 @@ nRF5xSecurityManager::allocate_pairing_cb(connection_handle_t connection) return pairing_cb; } -void nRF5xSecurityManager::release_pairing_cb(pairing_control_block_t* pairing_cb) +template +void nRF5xSecurityManager::release_pairing_cb(pairing_control_block_t* pairing_cb) { if (pairing_cb == _control_blocks) { _control_blocks = _control_blocks->next; @@ -1242,8 +1282,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 +typename nRF5xSecurityManager::pairing_control_block_t* +nRF5xSecurityManager::get_pairing_cb(connection_handle_t connection) { pairing_control_block_t* pcb = _control_blocks; while (pcb) { @@ -1256,7 +1297,8 @@ nRF5xSecurityManager::get_pairing_cb(connection_handle_t connection) return NULL; } -void nRF5xSecurityManager::release_all_pairing_cb() +template +void nRF5xSecurityManager::release_all_pairing_cb() { while(_control_blocks) { release_pairing_cb(_control_blocks); diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xn.cpp b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xn.cpp index e8e463a0c5..b98e23e45d 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xn.cpp +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xn.cpp @@ -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::PalGattClientImpl::get_client())) { } @@ -214,13 +215,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(getGap()), dummy_signing_event_monitor diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xn.h b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xn.h index 088944faa6..5c395139bc 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xn.h +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xn.h @@ -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; };