From 5a97706aab051c76c71d03efd5e79ccba363152a Mon Sep 17 00:00:00 2001 From: paul-szczepanek-arm <33840200+paul-szczepanek-arm@users.noreply.github.com> Date: Thu, 7 Feb 2019 15:50:36 +0000 Subject: [PATCH] added #if guards to cordio ble --- features/FEATURE_BLE/ble/BLE.h | 4 +--- .../ble/DiscoveredCharacteristic.h | 4 ---- .../ble/DiscoveredCharacteristicDescriptor.h | 4 ---- features/FEATURE_BLE/ble/Gap.h | 9 -------- features/FEATURE_BLE/ble/GattClient.h | 4 ---- features/FEATURE_BLE/ble/gap/Gap.h | 3 --- features/FEATURE_BLE/ble/generic/GenericGap.h | 10 ++++---- .../ble/generic/GenericGattClient.h | 10 ++++---- .../ble/generic/GenericSecurityManager.h | 8 +++++-- .../FEATURE_BLE/ble/services/UARTService.h | 4 ---- .../ble/services/URIBeaconConfigService.h | 4 ---- features/FEATURE_BLE/source/BLE.cpp | 4 ---- .../source/DiscoveredCharacteristic.cpp | 4 ---- features/FEATURE_BLE/source/LegacyGap.tpp | 4 ---- features/FEATURE_BLE/source/gap/Gap.tpp | 4 ---- .../FEATURE_BLE/source/generic/GenericGap.tpp | 23 ++++++++----------- .../source/generic/GenericGattClient.tpp | 12 +++++++--- .../source/generic/GenericSecurityManager.tpp | 2 ++ .../source/services/UARTService.cpp | 3 --- .../services/URIBeaconConfigService.cpp | 4 ---- .../targets/TARGET_CORDIO/CordioGattServer.h | 10 ++++++-- .../TARGET_CORDIO/CordioPalAttClient.h | 6 ++++- .../TARGET_CORDIO/CordioPalSecurityManager.h | 7 ++++++ .../TARGET_CORDIO/source/CordioBLE.cpp | 12 ++++++---- .../TARGET_CORDIO/source/CordioGattServer.cpp | 10 +++++--- .../source/CordioPalSecurityManager.tpp | 23 +++++++++++++++---- 26 files changed, 93 insertions(+), 99 deletions(-) diff --git a/features/FEATURE_BLE/ble/BLE.h b/features/FEATURE_BLE/ble/BLE.h index 2e02fc2df8..860bf0850f 100644 --- a/features/FEATURE_BLE/ble/BLE.h +++ b/features/FEATURE_BLE/ble/BLE.h @@ -17,7 +17,7 @@ #ifndef MBED_BLE_H__ #define MBED_BLE_H__ -#include "BLERoles.h +#include "BLERoles.h" #include "blecommon.h" #include "ble/Gap.h" @@ -844,7 +844,6 @@ public: MBED_DEPRECATED("Use ble.gap().stopAdvertising(...)") ble_error_t stopAdvertising(void); -#if BLE_ROLE_OBSERVER /** * Set up parameters for GAP scanning (observer mode). * @@ -1042,7 +1041,6 @@ public: { return gap().stopScan(); } -#endif // BLE_ROLE_OBSERVER /** * Create a connection (GAP Link Establishment). diff --git a/features/FEATURE_BLE/ble/DiscoveredCharacteristic.h b/features/FEATURE_BLE/ble/DiscoveredCharacteristic.h index 98cdbd6712..5e1e71bfd5 100644 --- a/features/FEATURE_BLE/ble/DiscoveredCharacteristic.h +++ b/features/FEATURE_BLE/ble/DiscoveredCharacteristic.h @@ -17,8 +17,6 @@ #ifndef MBED_DISCOVERED_CHARACTERISTIC_H__ #define MBED_DISCOVERED_CHARACTERISTIC_H__ -#if BLE_FEATURE_GATT_CLIENT - #include "UUID.h" #include "ble/Gap.h" #include "GattAttribute.h" @@ -636,6 +634,4 @@ protected: * @} */ -#endif // BLE_FEATURE_GATT_CLIENT - #endif /*MBED_DISCOVERED_CHARACTERISTIC_H__*/ diff --git a/features/FEATURE_BLE/ble/DiscoveredCharacteristicDescriptor.h b/features/FEATURE_BLE/ble/DiscoveredCharacteristicDescriptor.h index dd0b460abe..f5260d7b9f 100644 --- a/features/FEATURE_BLE/ble/DiscoveredCharacteristicDescriptor.h +++ b/features/FEATURE_BLE/ble/DiscoveredCharacteristicDescriptor.h @@ -17,8 +17,6 @@ #ifndef MBED_DISCOVERED_CHARACTERISTIC_DESCRIPTOR_H__ #define MBED_DISCOVERED_CHARACTERISTIC_DESCRIPTOR_H__ -#if BLE_FEATURE_GATT_CLIENT - #include "UUID.h" #include "ble/Gap.h" #include "GattAttribute.h" @@ -152,6 +150,4 @@ private: * @} */ -#endif // BLE_FEATURE_GATT_CLIENT - #endif /* MBED_DISCOVERED_CHARACTERISTIC_DESCRIPTOR_H__ */ diff --git a/features/FEATURE_BLE/ble/Gap.h b/features/FEATURE_BLE/ble/Gap.h index f035de0cdd..4d7350551b 100644 --- a/features/FEATURE_BLE/ble/Gap.h +++ b/features/FEATURE_BLE/ble/Gap.h @@ -66,9 +66,7 @@ public: using ble::interface::Gap::stopAdvertising; using ble::interface::Gap::connect; using ble::interface::Gap::disconnect; -#if BLE_ROLE_OBSERVER using ble::interface::Gap::startScan; -#endif // BLE_ROLE_OBSERVER /** * Address-type for BLEProtocol addresses. @@ -1657,7 +1655,6 @@ public: ) void clearScanResponse(void); -#if BLE_ROLE_OBSERVER /** * Set the parameters used during a scan procedure. * @@ -1868,8 +1865,6 @@ public: void (T::*callbackMember)(const AdvertisementCallbackParams_t *params) ); -#endif // BLE_ROLE_OBSERVER - /** * Enable radio-notification events. * @@ -2624,8 +2619,6 @@ protected: #pragma diag_suppress 1361 #endif -#if BLE_ROLE_OBSERVER - template template ble_error_t LegacyGap::startScan( @@ -2644,8 +2637,6 @@ ble_error_t LegacyGap::startScan( return err; } -#endif // BLE_ROLE_OBSERVER - template template void LegacyGap::onConnection(T *tptr, void (T::*mptr)(const ConnectionCallbackParams_t *)) diff --git a/features/FEATURE_BLE/ble/GattClient.h b/features/FEATURE_BLE/ble/GattClient.h index 09f6eaf6d3..79f214a5c5 100644 --- a/features/FEATURE_BLE/ble/GattClient.h +++ b/features/FEATURE_BLE/ble/GattClient.h @@ -17,8 +17,6 @@ #ifndef MBED_GATT_CLIENT_H__ #define MBED_GATT_CLIENT_H__ -#if BLE_FEATURE_GATT_CLIENT - #include "ble/common/StaticInterface.h" #include "ble/GattAttribute.h" #include "ble/ServiceDiscovery.h" @@ -880,6 +878,4 @@ private: using ble::impl::GattClient; #endif -#endif // BLE_FEATURE_GATT_CLIENT - #endif /* ifndef MBED_GATT_CLIENT_H__ */ diff --git a/features/FEATURE_BLE/ble/gap/Gap.h b/features/FEATURE_BLE/ble/gap/Gap.h index 2422a35cb8..8cfb7698b8 100644 --- a/features/FEATURE_BLE/ble/gap/Gap.h +++ b/features/FEATURE_BLE/ble/gap/Gap.h @@ -757,7 +757,6 @@ public: /* scanning */ -#if BLE_ROLE_OBSERVER /** Set new scan parameters. * * @param params Scan parameters, @see GapScanParameters for details. @@ -796,8 +795,6 @@ public: */ ble_error_t stopScan(); -#endif // BLE_ROLE_OBSERVER - /** Synchronize with periodic advertising from an advertiser and begin receiving periodic * advertising packets. * diff --git a/features/FEATURE_BLE/ble/generic/GenericGap.h b/features/FEATURE_BLE/ble/generic/GenericGap.h index 13894f0e39..3ddfa572be 100644 --- a/features/FEATURE_BLE/ble/generic/GenericGap.h +++ b/features/FEATURE_BLE/ble/generic/GenericGap.h @@ -127,8 +127,10 @@ public: GenericGap( pal::EventQueue &event_queue, PalGap &pal_gap, - pal::GenericAccessService &generic_access_service, + pal::GenericAccessService &generic_access_service +#if BLE_FEATURE_SECURITY PalSecurityManager &pal_sm +#endif ); /** @@ -234,7 +236,6 @@ public: */ bool isPeriodicAdvertisingActive_(advertising_handle_t handle); -#if BLE_ROLE_OBSERVER /** @copydoc Gap::setScanParameters */ ble_error_t setScanParameters_(const ScanParameters ¶ms); @@ -246,7 +247,6 @@ public: duplicates_filter_t filtering, scan_period_t period ); -#endif // BLE_ROLE_OBSERVER /** @copydoc Gap::createSync */ @@ -333,12 +333,10 @@ public: */ ble_error_t stopAdvertising_(); -#if BLE_ROLE_OBSERVER /** * @see Gap::stopScan */ ble_error_t stopScan_(); -#endif // BLE_ROLE_OBSERVER /** * @see Gap::connect @@ -789,7 +787,9 @@ private: pal::EventQueue &_event_queue; PalGap &_pal_gap; pal::GenericAccessService &_gap_service; +#if BLE_FEATURE_SECURITY PalSecurityManager &_pal_sm; +#endif BLEProtocol::AddressType_t _address_type; ble::address_t _address; pal::initiator_policy_t _initiator_policy_mode; diff --git a/features/FEATURE_BLE/ble/generic/GenericGattClient.h b/features/FEATURE_BLE/ble/generic/GenericGattClient.h index bcb38e3c55..230bddc03a 100644 --- a/features/FEATURE_BLE/ble/generic/GenericGattClient.h +++ b/features/FEATURE_BLE/ble/generic/GenericGattClient.h @@ -17,8 +17,6 @@ #ifndef MBED_BLE_GENERIC_GATT_CLIENT #define MBED_BLE_GENERIC_GATT_CLIENT -#if BLE_FEATURE_GATT_CLIENT - #include #include "ble/GattClient.h" #include "ble/pal/PalGattClient.h" @@ -37,7 +35,9 @@ namespace generic { template class TPalGattClient, class SigningMonitorEventHandler> class GenericGattClient : public interface::GattClient >, +#if BLE_FEATURE_SIGNING public pal::SigningEventMonitor, SigningMonitorEventHandler>, +#endif // BLE_FEATURE_SIGNING public pal::GattClientEventHandler > { using interface::GattClient >::eventHandler; @@ -136,10 +136,12 @@ public: */ ble_error_t reset_(void); +#if BLE_FEATURE_SIGNING /** * @see ble::pal::SigningEventMonitor::set_signing_event_handler */ void set_signing_event_handler_(SigningMonitorEventHandler *signing_event_handler); +#endif // BLE_FEATURE_SIGNING /** * @see pal::GattClient::EventHandler::on_att_mtu_change @@ -171,7 +173,9 @@ private: PalGattClient* const _pal_client; ServiceDiscovery::TerminationCallback_t _termination_callback; +#if BLE_FEATURE_SIGNING SigningMonitorEventHandler* _signing_event_handler; +#endif mutable ProcedureControlBlock* control_blocks; bool _is_reseting; }; @@ -179,6 +183,4 @@ private: } // generic } // ble -#endif // BLE_FEATURE_GATT_CLIENT - #endif /* MBED_BLE_GENERIC_GATT_CLIENT */ diff --git a/features/FEATURE_BLE/ble/generic/GenericSecurityManager.h b/features/FEATURE_BLE/ble/generic/GenericSecurityManager.h index 7f5f7be783..89fed596ef 100644 --- a/features/FEATURE_BLE/ble/generic/GenericSecurityManager.h +++ b/features/FEATURE_BLE/ble/generic/GenericSecurityManager.h @@ -35,8 +35,10 @@ template class TPalSecurityManager, template class Signi class GenericSecurityManager : public interface::SecurityManager >, // SecurityManager public pal::SecurityManagerEventHandler >, // PalSmEventHandler - public pal::ConnectionEventMonitorEventHandler >, // ConnectionObserver - public pal::SigningMonitorEventHandler > //SigningObserver + public pal::ConnectionEventMonitorEventHandler > // ConnectionObserver +#if BLE_FEATURE_SIGNING + , public pal::SigningMonitorEventHandler > //SigningObserver +#endif // BLE_FEATURE_SIGNING { // typedefs typedef interface::SecurityManager SecurityManager; @@ -594,6 +596,7 @@ public: connection_handle_t connection ); +#if BLE_FEATURE_SIGNING /** @copydoc ble::pal::SecurityManager::on_signed_write_received */ void on_signed_write_received_( @@ -610,6 +613,7 @@ public: /** @copydoc ble::pal::SecurityManager::on_signed_write */ void on_signed_write_(); +#endif // BLE_FEATURE_SIGNING /** @copydoc ble::pal::SecurityManager::on_slave_security_request */ diff --git a/features/FEATURE_BLE/ble/services/UARTService.h b/features/FEATURE_BLE/ble/services/UARTService.h index eb17c874a5..241db763b4 100644 --- a/features/FEATURE_BLE/ble/services/UARTService.h +++ b/features/FEATURE_BLE/ble/services/UARTService.h @@ -17,8 +17,6 @@ #ifndef __BLE_UART_SERVICE_H__ #define __BLE_UART_SERVICE_H__ -#if BLE_FEATURE_GATT_SERVER - #ifdef YOTTA_CFG_MBED_OS #include "mbed-drivers/mbed.h" #include "mbed-drivers/Stream.h" @@ -217,6 +215,4 @@ protected: * application. */ }; -#endif // BLE_FEATURE_GATT_SERVER - #endif /* #ifndef __BLE_UART_SERVICE_H__*/ diff --git a/features/FEATURE_BLE/ble/services/URIBeaconConfigService.h b/features/FEATURE_BLE/ble/services/URIBeaconConfigService.h index fdb6ca16f4..6a6a583431 100644 --- a/features/FEATURE_BLE/ble/services/URIBeaconConfigService.h +++ b/features/FEATURE_BLE/ble/services/URIBeaconConfigService.h @@ -17,8 +17,6 @@ #ifndef SERVICES_URIBEACONCONFIGSERVICE_H_ #define SERVICES_URIBEACONCONFIGSERVICE_H_ -#if BLE_FEATURE_GATT_SERVER - #include "ble/BLE.h" #ifdef YOTTA_CFG_MBED_OS @@ -482,6 +480,4 @@ public: } }; -#endif // BLE_FEATURE_GATT_SERVER - #endif // SERVICES_URIBEACONCONFIGSERVICE_H_ diff --git a/features/FEATURE_BLE/source/BLE.cpp b/features/FEATURE_BLE/source/BLE.cpp index c4b0496b61..cb529d39fc 100644 --- a/features/FEATURE_BLE/source/BLE.cpp +++ b/features/FEATURE_BLE/source/BLE.cpp @@ -454,8 +454,6 @@ ble_error_t BLE::stopAdvertising(void) { return gap().stopAdvertising(); } -#if BLE_ROLE_OBSERVER - ble_error_t BLE::setScanParams(uint16_t interval, uint16_t window, uint16_t timeout, @@ -483,8 +481,6 @@ ble_error_t BLE::startScan(void (*callback)(const Gap::AdvertisementCallbackPara return gap().startScan(callback); } -#endif // BLE_ROLE_OBSERVER - ble_error_t BLE::disconnect(Gap::Handle_t connectionHandle, Gap::DisconnectionReason_t reason) { return gap().disconnect(connectionHandle, reason); } diff --git a/features/FEATURE_BLE/source/DiscoveredCharacteristic.cpp b/features/FEATURE_BLE/source/DiscoveredCharacteristic.cpp index 0b3b730c30..402fe6868b 100644 --- a/features/FEATURE_BLE/source/DiscoveredCharacteristic.cpp +++ b/features/FEATURE_BLE/source/DiscoveredCharacteristic.cpp @@ -17,8 +17,6 @@ #include "ble/DiscoveredCharacteristic.h" #include "ble/GattClient.h" -#if BLE_FEATURE_GATT_CLIENT - ble_error_t DiscoveredCharacteristic::read(uint16_t offset) const { @@ -167,5 +165,3 @@ ble_error_t DiscoveredCharacteristic::discoverDescriptors( return err; } - -#endif // BLE_FEATURE_GATT_CLIENT diff --git a/features/FEATURE_BLE/source/LegacyGap.tpp b/features/FEATURE_BLE/source/LegacyGap.tpp index 9958a875a0..772eb03d62 100644 --- a/features/FEATURE_BLE/source/LegacyGap.tpp +++ b/features/FEATURE_BLE/source/LegacyGap.tpp @@ -426,8 +426,6 @@ ble_error_t LegacyGap::accumulateScanResponse( return rc; } -#if BLE_ROLE_OBSERVER - template void LegacyGap::clearScanResponse(void) { @@ -529,8 +527,6 @@ ble_error_t LegacyGap::startScan( return err; } -#endif // BLE_ROLE_OBSERVER - template GapAdvertisingParams &LegacyGap::getAdvertisingParams(void) { diff --git a/features/FEATURE_BLE/source/gap/Gap.tpp b/features/FEATURE_BLE/source/gap/Gap.tpp index 4bda636fc2..09e3d832b8 100644 --- a/features/FEATURE_BLE/source/gap/Gap.tpp +++ b/features/FEATURE_BLE/source/gap/Gap.tpp @@ -156,8 +156,6 @@ bool Gap::isPeriodicAdvertisingActive(advertising_handle_t handle) return impl()->isPeriodicAdvertisingActive_(handle); } -#if BLE_ROLE_OBSERVER - template ble_error_t Gap::setScanParameters(const ScanParameters ¶ms) { @@ -180,8 +178,6 @@ ble_error_t Gap::stopScan() return impl()->stopScan_(); } -#endif // BLE_ROLE_OBSERVER - template ble_error_t Gap::createSync( peer_address_type_t peerAddressType, diff --git a/features/FEATURE_BLE/source/generic/GenericGap.tpp b/features/FEATURE_BLE/source/generic/GenericGap.tpp index 0caa682708..df6619c16e 100644 --- a/features/FEATURE_BLE/source/generic/GenericGap.tpp +++ b/features/FEATURE_BLE/source/generic/GenericGap.tpp @@ -425,12 +425,16 @@ template class PalGapImpl, class PalSecurityManager, class Conn GenericGap::GenericGap( pal::EventQueue &event_queue, PalGapImpl &pal_gap, - pal::GenericAccessService &generic_access_service, - PalSecurityManager &pal_sm + pal::GenericAccessService &generic_access_service +#if BLE_FEATURE_SECURITY + , PalSecurityManager &pal_sm +#endif ) : _event_queue(event_queue), _pal_gap(pal_gap), _gap_service(generic_access_service), +#if BLE_FEATURE_SECURITY _pal_sm(pal_sm), +#endif _address_type(LegacyAddressType::PUBLIC), _initiator_policy_mode(pal::initiator_policy_t::NO_FILTER), _scanning_filter_policy(pal::scanning_filter_policy_t::NO_FILTER), @@ -574,8 +578,6 @@ ble_error_t GenericGap class PalGapImpl, class PalSecurityManager, class ConnectionEventMonitorEventHandler> ble_error_t GenericGap::stopScan_() { @@ -606,8 +608,6 @@ ble_error_t GenericGap class PalGapImpl, class PalSecurityManager, class ConnectionEventMonitorEventHandler> ble_error_t GenericGap::connect_( const BLEProtocol::AddressBytes_t peerAddr, @@ -633,10 +633,8 @@ ble_error_t GenericGapgetInterval(), @@ -2082,8 +2080,11 @@ bool GenericGap random_data; - +#if BLE_FEATURE_SECURITY ble_error_t ret = _pal_sm.get_random_data(random_data); +#else + ble_error_t ret = BLE_ERROR_NOT_IMPLEMENTED; +#endif // BLE_FEATURE_SECURITY if (ret != BLE_ERROR_NONE) { // Abort return false; @@ -3035,8 +3036,6 @@ void GenericGap class PalGapImpl, class PalSecurityManager, class ConnectionEventMonitorEventHandler> ble_error_t GenericGap::setScanParameters_(const ScanParameters ¶ms) { @@ -3136,8 +3135,6 @@ ble_error_t GenericGap class PalGapImpl, class PalSecurityManager, class ConnectionEventMonitorEventHandler> ble_error_t GenericGap::createSync_( peer_address_type_t peerAddressType, diff --git a/features/FEATURE_BLE/source/generic/GenericGattClient.tpp b/features/FEATURE_BLE/source/generic/GenericGattClient.tpp index 5b18459c0d..d686068be1 100644 --- a/features/FEATURE_BLE/source/generic/GenericGattClient.tpp +++ b/features/FEATURE_BLE/source/generic/GenericGattClient.tpp @@ -14,8 +14,6 @@ * limitations under the License. */ -#if BLE_FEATURE_GATT_CLIENT - #include #include @@ -953,7 +951,9 @@ template class TPalGattClient, class SigningMonitorEventHandler> GenericGattClient::GenericGattClient(PalGattClient* pal_client) : _pal_client(pal_client), _termination_callback(), +#if BLE_FEATURE_SIGNING _signing_event_handler(NULL), +#endif control_blocks(NULL), _is_reseting(false) { _pal_client->when_server_message_received( @@ -1106,6 +1106,7 @@ ble_error_t GenericGattClient::write uint16_t mtu = get_mtu(connection_handle); +#if BLE_FEATURE_SIGNING /* if link is encrypted signed writes should be normal writes */ if (cmd == Base::GATT_OP_SIGNED_WRITE_CMD) { ble::link_encryption_t encryption(ble::link_encryption_t::NOT_ENCRYPTED); @@ -1120,6 +1121,7 @@ ble_error_t GenericGattClient::write cmd = Base::GATT_OP_WRITE_CMD; } } +#endif // BLE_FEATURE_SIGNING if (cmd == Base::GATT_OP_WRITE_CMD) { if (length > (uint16_t) (mtu - WRITE_HEADER_LENGTH)) { @@ -1131,6 +1133,7 @@ ble_error_t GenericGattClient::write make_const_ArrayView(value, length) ); } else if (cmd == Base::GATT_OP_SIGNED_WRITE_CMD) { +#if BLE_FEATURE_SIGNING if (length > (uint16_t) (mtu - WRITE_HEADER_LENGTH - CMAC_LENGTH - MAC_COUNTER_LENGTH)) { return BLE_ERROR_PARAM_OUT_OF_RANGE; } @@ -1139,10 +1142,12 @@ ble_error_t GenericGattClient::write attribute_handle, make_const_ArrayView(value, length) ); + if (_signing_event_handler && (status == BLE_ERROR_NONE)) { _signing_event_handler->on_signed_write(); } return status; +#endif // BLE_FEATURE_SIGNING } else { uint8_t* data = NULL; @@ -1309,12 +1314,14 @@ ble_error_t GenericGattClient::reset return BLE_ERROR_NONE; } +#if BLE_FEATURE_SIGNING template class TPalGattClient, class SigningMonitorEventHandler> void GenericGattClient::set_signing_event_handler_( SigningMonitorEventHandler *signing_event_handler ) { _signing_event_handler = signing_event_handler; } +#endif // BLE_FEATURE_SIGNING template class TPalGattClient, class SigningMonitorEventHandler> void GenericGattClient::on_att_mtu_change_( @@ -1491,4 +1498,3 @@ uint16_t GenericGattClient::get_mtu( } // namespace pal } // namespace ble -#endif // BLE_FEATURE_GATT_CLIENT diff --git a/features/FEATURE_BLE/source/generic/GenericSecurityManager.tpp b/features/FEATURE_BLE/source/generic/GenericSecurityManager.tpp index d72b4089a5..f9ab75bfc5 100644 --- a/features/FEATURE_BLE/source/generic/GenericSecurityManager.tpp +++ b/features/FEATURE_BLE/source/generic/GenericSecurityManager.tpp @@ -1280,6 +1280,7 @@ void GenericSecurityManager::on_valid_mic_t (void)connection; } +#if BLE_FEATURE_SIGNING template class TPalSecurityManager, template class SigningMonitor> void GenericSecurityManager::on_signed_write_received_( connection_handle_t connection, @@ -1324,6 +1325,7 @@ void GenericSecurityManager::on_signed_writ MBED_ASSERT(_db); _db->set_local_sign_counter(_db->get_local_sign_counter() + 1); } +#endif // BLE_FEATURE_SIGNING template class TPalSecurityManager, template class SigningMonitor> void GenericSecurityManager::on_slave_security_request_( diff --git a/features/FEATURE_BLE/source/services/UARTService.cpp b/features/FEATURE_BLE/source/services/UARTService.cpp index e10d41affe..62fd77beb8 100644 --- a/features/FEATURE_BLE/source/services/UARTService.cpp +++ b/features/FEATURE_BLE/source/services/UARTService.cpp @@ -16,8 +16,6 @@ #include "ble/services/UARTService.h" -#if BLE_FEATURE_GATT_SERVER - const uint8_t UARTServiceBaseUUID[UUID::LENGTH_OF_LONG_UUID] = { 0x6E, 0x40, 0x00, 0x00, 0xB5, 0xA3, 0xF3, 0x93, 0xE0, 0xA9, 0xE5, 0x0E, 0x24, 0xDC, 0xCA, 0x9E, @@ -42,4 +40,3 @@ const uint8_t UARTServiceRXCharacteristicUUID[UUID::LENGTH_OF_LONG_UUID] = { 0xE0, 0xA9, 0xE5, 0x0E, 0x24, 0xDC, 0xCA, 0x9E, }; -#endif // BLE_FEATURE_GATT_SERVER diff --git a/features/FEATURE_BLE/source/services/URIBeaconConfigService.cpp b/features/FEATURE_BLE/source/services/URIBeaconConfigService.cpp index 4d8e75cb94..bcdcbb0e3b 100644 --- a/features/FEATURE_BLE/source/services/URIBeaconConfigService.cpp +++ b/features/FEATURE_BLE/source/services/URIBeaconConfigService.cpp @@ -16,8 +16,6 @@ #include "ble/services/URIBeaconConfigService.h" -#if BLE_FEATURE_GATT_SERVER - #define UUID_URI_BEACON(FIRST, SECOND) { \ 0xee, 0x0c, FIRST, SECOND, 0x87, 0x86, 0x40, 0xba, \ 0xab, 0x96, 0x99, 0xb9, 0x1a, 0xc9, 0x81, 0xd8, \ @@ -35,5 +33,3 @@ const uint8_t UUID_BEACON_PERIOD_CHAR[UUID::LENGTH_OF_LONG_UUID] = UUID_URI_B const uint8_t UUID_RESET_CHAR[UUID::LENGTH_OF_LONG_UUID] = UUID_URI_BEACON(0x20, 0x89); const uint8_t BEACON_UUID[sizeof(UUID::ShortUUIDBytes_t)] = {0xD8, 0xFE}; - -#endif // BLE_FEATURE_GATT_SERVER diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioGattServer.h b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioGattServer.h index 34ec308445..8d22ab37bd 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioGattServer.h +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioGattServer.h @@ -53,8 +53,10 @@ class BLE; /** * Cordio implementation of ::GattServer */ -class GattServer : public ::ble::interface::GattServer, - public pal::SigningEventMonitor +class GattServer : public ::ble::interface::GattServer +#if BLE_FEATURE_SIGNING + , public pal::SigningEventMonitor +#endif { friend ble::vendor::cordio::BLE; friend ble::pal::vendor::cordio::CordioAttClient; @@ -176,6 +178,7 @@ public: */ ble_error_t reset_(void); +#if BLE_FEATURE_SIGNING /** * @see pal::SigningEventMonitor::set_signing_event_handler */ @@ -184,6 +187,7 @@ public: ) { _signing_event_handler = signing_event_handler; } +#endif // BLE_FEATURE_SIGNING private: @@ -246,7 +250,9 @@ private: internal_service_t *next; }; +#if BLE_FEATURE_SIGNING impl::SigningEventHandler *_signing_event_handler; +#endif attsCccSet_t cccds[MAX_CCCD_CNT]; uint16_t cccd_values[MAX_CCCD_CNT]; diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalAttClient.h b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalAttClient.h index a16d747efa..346ae75edc 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalAttClient.h +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalAttClient.h @@ -36,7 +36,11 @@ namespace cordio { class CordioAttClient : public ::ble::pal::AttClient { public: - CordioAttClient() : ::ble::pal::AttClient(), _local_sign_counter(0) { } + CordioAttClient() : ::ble::pal::AttClient(), _local_sign_counter(0) { +#if !(BLE_FEATURE_ATT) +#error "Both GattClient and GattSever disabled in config file." +#endif + } ~CordioAttClient() { } diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalSecurityManager.h b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalSecurityManager.h index b7bb0bb7d7..41e1ca97d0 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalSecurityManager.h +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalSecurityManager.h @@ -238,6 +238,7 @@ public: */ ble_error_t set_irk_(const irk_t &irk); +#if BLE_FEATURE_SIGNING /** * @see ::ble::pal::SecurityManager::set_csrk */ @@ -257,6 +258,7 @@ public: ); ble_error_t remove_peer_csrk_(connection_handle_t connection); +#endif // BLE_FEATURE_SIGNING //////////////////////////////////////////////////////////////////////////// // Authentication @@ -362,7 +364,9 @@ private: // cb_completed is set when the previous block has completed void process_privacy_control_blocks(bool cb_completed); +#if BLE_FEATURE_SIGNING void cleanup_peer_csrks(); +#endif bool _use_default_passkey; passkey_num_t _default_passkey; @@ -372,8 +376,11 @@ private: PrivacyControlBlock* _pending_privacy_control_blocks; bool _processing_privacy_control_block; irk_t _irk; + +#if BLE_FEATURE_SIGNING csrk_t _csrk; csrk_t* _peer_csrks[DM_CONN_MAX]; +#endif // BLE_FEATURE_SIGNING }; } // cordio diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioBLE.cpp b/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioBLE.cpp index 45974ebecb..81125a7fc8 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioBLE.cpp +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioBLE.cpp @@ -36,7 +36,9 @@ #include "mbed_assert.h" #include "CordioPalAttClient.h" +#if BLE_FEATURE_SECURITY #include "CordioPalSecurityManager.h" +#endif BLE_FEATURE_SECURITY /*! WSF handler ID */ wsfHandlerId_t stack_handler_id; @@ -181,8 +183,10 @@ impl::GenericGapImpl& BLE::getGap() static impl::GenericGapImpl gap( _event_queue, impl::PalGapImpl::get_gap(), - cordio_gap_service, - impl::PalSecurityManagerImpl::get_security_manager() + cordio_gap_service +#if BLE_FEATURE_SECURITY + , impl::PalSecurityManagerImpl::get_security_manager() +#endif ); return gap; @@ -225,7 +229,6 @@ impl::PalGattClientImpl& BLE::getPalGattClient() #endif // BLE_FEATURE_GATT_CLIENT #if BLE_FEATURE_SECURITY - SecurityManager& BLE::getSecurityManager() { static vendor::cordio::SigningEventMonitor signing_event_monitor; @@ -243,7 +246,6 @@ const SecurityManager& BLE::getSecurityManager() const const BLE &self = const_cast(*this); return const_cast(self.getSecurityManager()); } - #endif // BLE_FEATURE_SECURITY void BLE::waitForEvent() @@ -274,9 +276,11 @@ void BLE::processEvents() return; } +#if BLE_FEATURE_SECURITY if (impl::PalSecurityManagerImpl::get_security_manager().sm_handler(msg)) { return; } +#endif // BLE_FEATURE_SECURITY switch(msg->event) { case DM_RESET_CMPL_IND: { diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioGattServer.cpp b/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioGattServer.cpp index edfc435d14..939fae08a5 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioGattServer.cpp +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioGattServer.cpp @@ -14,8 +14,6 @@ * limitations under the License. */ -#if BLE_FEATURE_GATT_SERVER - #include #include "CordioBLE.h" #include "CordioGattServer.h" @@ -928,6 +926,7 @@ uint8_t GattServer::atts_write_cb( case ATT_PDU_WRITE_CMD: writeOp = GattWriteCallbackParams::OP_WRITE_CMD; break; +#if BLE_FEATURE_SIGNING case ATT_PDU_SIGNED_WRITE_CMD: if (getInstance()._signing_event_handler) { getInstance()._signing_event_handler->on_signed_write_received( @@ -937,6 +936,7 @@ uint8_t GattServer::atts_write_cb( } writeOp = GattWriteCallbackParams::OP_SIGN_WRITE_CMD; break; +#endif // BLE_FEATURE_SIGNING case ATT_PDU_PREP_WRITE_REQ: writeOp = GattWriteCallbackParams::OP_PREP_WRITE_REQ; break; @@ -1276,7 +1276,9 @@ bool GattServer::is_update_authorized( } GattServer::GattServer() : +#if BLE_FEATURE_SIGNING _signing_event_handler(NULL), +#endif cccds(), cccd_values(), cccd_handles(), @@ -1289,10 +1291,12 @@ GattServer::GattServer() : allocated_blocks(NULL), currentHandle(0) { +#if !(BLE_FEATURE_GATT_SERVER) +#error "GattSever disabled in config file." +#endif } } // namespace cordio } // namespace vendor } // namespace ble -#endif // BLE_FEATURE_GATT_SERVER diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioPalSecurityManager.tpp b/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioPalSecurityManager.tpp index d9f0ebb074..4d8336b9d2 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioPalSecurityManager.tpp +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioPalSecurityManager.tpp @@ -35,10 +35,14 @@ CordioSecurityManager::CordioSecurityManager() : _lesc_keys_generated(false), _public_key_x(), _pending_privacy_control_blocks(NULL), - _processing_privacy_control_block(false), - _peer_csrks() + _processing_privacy_control_block(false) +#if BLE_FEATURE_SIGNING + , _peer_csrks() +#endif { - +#if !(BLE_FEATURE_SECURITY) +#error "Security Manager feature disabledin the config file" +#endif } template @@ -58,7 +62,9 @@ ble_error_t CordioSecurityManager::initialize_() _use_default_passkey = false; _default_passkey = 0; _lesc_keys_generated = false; +#if BLE_FEATURE_SIGNING memset(_peer_csrks, 0, sizeof(_peer_csrks)); +#endif #if 0 // FIXME: need help from the stack or local calculation @@ -72,14 +78,18 @@ ble_error_t CordioSecurityManager::initialize_() template ble_error_t CordioSecurityManager::terminate_() { +#if BLE_FEATURE_SIGNING cleanup_peer_csrks(); +#endif // BLE_FEATURE_SIGNING return BLE_ERROR_NONE; } template ble_error_t CordioSecurityManager::reset_() { +#if BLE_FEATURE_SIGNING cleanup_peer_csrks(); +#endif // BLE_FEATURE_SIGNING initialize(); return BLE_ERROR_NONE; } @@ -321,6 +331,7 @@ ble_error_t CordioSecurityManager::set_irk_(const irk_t& irk) return BLE_ERROR_NONE; } +#if BLE_FEATURE_SIGNING template ble_error_t CordioSecurityManager::set_csrk_( const csrk_t& csrk, @@ -378,6 +389,7 @@ ble_error_t CordioSecurityManager::remove_peer_csrk_(connection_ha AttsSetCsrk(connection, NULL, false); return BLE_ERROR_NONE; } +#endif // BLE_FEATURE_SIGNING //////////////////////////////////////////////////////////////////////////// // Global parameters @@ -704,12 +716,13 @@ bool CordioSecurityManager::sm_handler(const wsfMsgHdr_t* msg) { irk_t(reinterpret_cast(evt->keyData.irk.key)) ); break; - +#if BLE_FEATURE_SIGNING case DM_KEY_CSRK: handler->on_keys_distributed_csrk( connection, evt->keyData.csrk.key ); break; +#endif // BLE_FEATURE_SIGNING } return true; @@ -996,6 +1009,7 @@ void CordioSecurityManager::process_privacy_control_blocks(bool cb _pending_privacy_control_blocks = next; } +#if BLE_FEATURE_SIGNING template void CordioSecurityManager::cleanup_peer_csrks() { for (size_t i = 0; i < DM_CONN_MAX; ++i) { @@ -1005,6 +1019,7 @@ void CordioSecurityManager::cleanup_peer_csrks() { } } } +#endif // BLE_FEATURE_SIGNING } // cordio } // vendor