diff --git a/features/FEATURE_BLE/ble/pal/PalGap.h b/features/FEATURE_BLE/ble/pal/PalGap.h index 5f7865d8f2..aec629a587 100644 --- a/features/FEATURE_BLE/ble/pal/PalGap.h +++ b/features/FEATURE_BLE/ble/pal/PalGap.h @@ -649,17 +649,13 @@ struct Gap { disconnection_reason_t disconnection_reason ) = 0; - /** Enable or disable privacy feature - * @param enable whether to enable privacy feature + /** Check if privacy feature is supported by implementation * - * @return BLE_ERROR_NONE if the request has been successfully sent or the - * appropriate error otherwise. + * @return true if privacy is supported, false otherwise. * * @note: See Bluetooth 5 Vol 3 Part C: 10.7 Privacy feature. */ - virtual ble_error_t set_privacy( - bool enable - ) = 0; + virtual bool is_privacy_supported() = 0; /** Enable or disable private addresses resolution * diff --git a/features/FEATURE_BLE/source/generic/GenericGap.cpp b/features/FEATURE_BLE/source/generic/GenericGap.cpp index b00ad941ab..c1f47f0f8d 100644 --- a/features/FEATURE_BLE/source/generic/GenericGap.cpp +++ b/features/FEATURE_BLE/source/generic/GenericGap.cpp @@ -881,9 +881,18 @@ ble_error_t GenericGap::initRadioNotification(void) ble_error_t GenericGap::enablePrivacy(bool enable) { - _privacy_enabled = enable; + if(enable == _privacy_enabled) { + // No change + return BLE_ERROR_NONE; + } - _pal_gap.set_privacy(enable); + if(enable && !_pal_gap.is_privacy_supported()) + { + // Privacy is not supported by the implementation + return BLE_ERROR_NOT_IMPLEMENTED; + } + + _privacy_enabled = enable; update_address_resolution_setting(); diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalGap.h b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalGap.h index bb41b19b2c..ee2c4f2f57 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalGap.h +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalGap.h @@ -308,13 +308,9 @@ public: return BLE_ERROR_NONE; } - virtual ble_error_t set_privacy( - bool enable - ) { - // - - - return BLE_ERROR_NONE; + virtual bool is_privacy_supported() { + // We only support controller-based privacy, so return whether the controller supports it + return HciLlPrivacySupported(); } virtual ble_error_t set_address_resolution( @@ -481,7 +477,6 @@ private: }; private: - address_t device_random_static_identity_address; address_t device_random_address; bool use_active_scanning; };