From 09f71d278d1b37e45ab798e3039c8563b81d2f99 Mon Sep 17 00:00:00 2001 From: paul-szczepanek-arm <33840200+paul-szczepanek-arm@users.noreply.github.com> Date: Wed, 14 Nov 2018 16:54:17 +0000 Subject: [PATCH] move feature support into user api --- features/FEATURE_BLE/ble/BLETypes.h | 29 +++++++++++++++++++ features/FEATURE_BLE/ble/Gap.h | 9 ++++++ features/FEATURE_BLE/ble/generic/GenericGap.h | 6 ++++ features/FEATURE_BLE/ble/pal/PalGap.h | 27 ----------------- .../FEATURE_BLE/source/generic/GenericGap.cpp | 10 +++++-- .../targets/TARGET_CORDIO/CordioPalGap.h | 2 +- .../TARGET_CORDIO/source/CordioPalGap.cpp | 2 +- 7 files changed, 54 insertions(+), 31 deletions(-) diff --git a/features/FEATURE_BLE/ble/BLETypes.h b/features/FEATURE_BLE/ble/BLETypes.h index da93755239..5ca26aab15 100644 --- a/features/FEATURE_BLE/ble/BLETypes.h +++ b/features/FEATURE_BLE/ble/BLETypes.h @@ -44,6 +44,7 @@ void clamp(T& value, const R& min, const R& max) { } } +/* BLE units, using microseconds as the common denominator */ typedef Duration > adv_interval_t; typedef Duration > adv_duration_t; typedef Duration > scan_duration_t; @@ -61,6 +62,34 @@ typedef Duration us_t; typedef Bounded slave_latency_t; +/** Features supported by the controller. + * @see BLUETOOTH SPECIFICATION Version 5.0 | Vol 6, Part B - 4.6 */ +struct ControllerSupportedFeatures_t : SafeEnum { + enum type { + LE_ENCRYPTION = 0, + CONNECTION_PARAMETERS_REQUEST_PROCEDURE, + EXTENDED_REJECT_INDICATION, + SLAVE_INITIATED_FEATURES_EXCHANGE, + LE_PING, + LE_DATA_PACKET_LENGTH_EXTENSION, + LL_PRIVACY, + EXTENDED_SCANNER_FILTER_POLICIES, + LE_2M_PHY, + STABLE_MODULATION_INDEX_TRANSMITTER, + STABLE_MODULATION_INDEX_RECEIVER, + LE_CODED_PHY, + LE_EXTENDED_ADVERTISING, + LE_PERIODIC_ADVERTISING, + CHANNEL_SELECTION_ALGORITHM_2, + LE_POWER_CLASS + }; + + /** + * Construct a new instance of ControllerSupportedFeatures_t. + */ + ControllerSupportedFeatures_t(type value) : SafeEnum(value) { } +}; + /** * Opaque reference to a connection. * diff --git a/features/FEATURE_BLE/ble/Gap.h b/features/FEATURE_BLE/ble/Gap.h index f259399898..319c291ca7 100644 --- a/features/FEATURE_BLE/ble/Gap.h +++ b/features/FEATURE_BLE/ble/Gap.h @@ -1768,6 +1768,15 @@ public: return BLE_ERROR_NOT_IMPLEMENTED; } + /** Check controller support for a specific feature. + * + * @param feature Feature to check. + * @return True if feature is supported. + */ + bool IsFeatureSupported( + ble::ControllerSupportedFeatures_t feature + ); + /* advertising */ /** Return currently available number of supported advertising sets. diff --git a/features/FEATURE_BLE/ble/generic/GenericGap.h b/features/FEATURE_BLE/ble/generic/GenericGap.h index b0d96c122d..faabfdf785 100644 --- a/features/FEATURE_BLE/ble/generic/GenericGap.h +++ b/features/FEATURE_BLE/ble/generic/GenericGap.h @@ -76,6 +76,12 @@ public: */ virtual ~GenericGap(); + /** @copydoc Gap::IsFeatureSupported + */ + bool IsFeatureSupported( + ble::ControllerSupportedFeatures_t feature + ); + /** @copydoc Gap::getMaxAdvertisingSetNumber */ uint8_t getMaxAdvertisingSetNumber(); diff --git a/features/FEATURE_BLE/ble/pal/PalGap.h b/features/FEATURE_BLE/ble/pal/PalGap.h index 9c397f48d3..60fe77162d 100644 --- a/features/FEATURE_BLE/ble/pal/PalGap.h +++ b/features/FEATURE_BLE/ble/pal/PalGap.h @@ -33,33 +33,6 @@ namespace pal { * by that layer. */ struct Gap { - /** @see BLUETOOTH SPECIFICATION Version 5.0 | Vol 6, Part B - 4.6 */ - struct ControllerSupportedFeatures_t : SafeEnum { - enum type { - LE_ENCRYPTION = 0, - CONNECTION_PARAMETERS_REQUEST_PROCEDURE, - EXTENDED_REJECT_INDICATION, - SLAVE_INITIATED_FEATURES_EXCHANGE, - LE_PING, - LE_DATA_PACKET_LENGTH_EXTENSION, - LL_PRIVACY, - EXTENDED_SCANNER_FILTER_POLICIES, - LE_2M_PHY, - STABLE_MODULATION_INDEX_TRANSMITTER, - STABLE_MODULATION_INDEX_RECEIVER, - LE_CODED_PHY, - LE_EXTENDED_ADVERTISING, - LE_PERIODIC_ADVERTISING, - CHANNEL_SELECTION_ALGORITHM_2, - LE_POWER_CLASS - }; - - /** - * Construct a new instance of ControllerSupportedFeatures_t. - */ - ControllerSupportedFeatures_t(type value) : SafeEnum(value) { } - }; - struct EventHandler { /** * @copydoc Gap::EventHandler::onReadPhy diff --git a/features/FEATURE_BLE/source/generic/GenericGap.cpp b/features/FEATURE_BLE/source/generic/GenericGap.cpp index 496af15110..b14fa93c7a 100644 --- a/features/FEATURE_BLE/source/generic/GenericGap.cpp +++ b/features/FEATURE_BLE/source/generic/GenericGap.cpp @@ -444,6 +444,12 @@ GenericGap::~GenericGap() { } +bool GenericGap::IsFeatureSupported( + ble::ControllerSupportedFeatures_t feature +) { + return _pal_gap.is_feature_supported(feature); +} + ble_error_t GenericGap::setAddress( LegacyAddressType_t type, const Address_t address @@ -2601,8 +2607,8 @@ void GenericGap::use_non_deprecated_scan_api() const bool GenericGap::is_extended_advertising_available() { - return _pal_gap.is_feature_supported( - pal::Gap::ControllerSupportedFeatures_t::LE_EXTENDED_ADVERTISING + return IsFeatureSupported( + ble::ControllerSupportedFeatures_t::LE_EXTENDED_ADVERTISING ); } diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalGap.h b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalGap.h index 1b7013ae37..cd6c433e53 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalGap.h +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalGap.h @@ -15,7 +15,7 @@ namespace cordio { class Gap : public ::ble::pal::Gap { public: virtual bool is_feature_supported( - Gap::ControllerSupportedFeatures_t feature + ble::ControllerSupportedFeatures_t feature ); virtual ble_error_t initialize(); diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioPalGap.cpp b/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioPalGap.cpp index b27c81f581..461a6cf914 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioPalGap.cpp +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioPalGap.cpp @@ -24,7 +24,7 @@ namespace vendor { namespace cordio { bool Gap::is_feature_supported( - Gap::ControllerSupportedFeatures_t feature + ble::ControllerSupportedFeatures_t feature ) { return (HciGetLeSupFeat() & (1 << feature.value())); }