From 07d73d5e20a94f0002d52bd555795a31d270016b Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Thu, 15 Nov 2018 12:17:26 +0000 Subject: [PATCH] BLE: merge ble::scanning_policy_mode_t and gap::scanning_filter_policy_t This change set also introduce ble::initiator_filter_policy_t and fix a type issue ble::ConnectionParameters. --- features/FEATURE_BLE/ble/Gap.h | 25 ++++-- .../ble/gap/ConnectionParameters.h | 14 ++- features/FEATURE_BLE/ble/gap/ScanParameters.h | 8 +- features/FEATURE_BLE/ble/gap/Types.h | 86 +++++++++++++------ features/FEATURE_BLE/ble/pal/GapTypes.h | 49 +---------- .../FEATURE_BLE/source/generic/GenericGap.cpp | 6 +- 6 files changed, 90 insertions(+), 98 deletions(-) diff --git a/features/FEATURE_BLE/ble/Gap.h b/features/FEATURE_BLE/ble/Gap.h index f784c7eb8d..99ec5adac3 100644 --- a/features/FEATURE_BLE/ble/Gap.h +++ b/features/FEATURE_BLE/ble/Gap.h @@ -548,6 +548,23 @@ public: ADV_POLICY_FILTER_ALL_REQS = 3, }; + /** + * Scanning policy filter mode. + * + * @see Bluetooth Core Specification 4.2 (Vol. 6), Part B, Section 4.3.3. + */ + enum ScanningPolicyMode_t { + /** + * The whitelist is not used for scanning operations. + */ + SCAN_POLICY_IGNORE_WHITELIST = 0, + + /** + * The whitelist is used to filter incoming advertising. + */ + SCAN_POLICY_FILTER_ALL_ADV = 1, + }; + /** * Connection initiation policy filter mode. * @@ -635,14 +652,6 @@ public: */ typedef ble::target_peer_address_type_t TargetPeerAddressType_t; - /** - * Scanning filter policy based on the whitelist - */ - typedef ble::scanning_policy_mode_t ScanningPolicyMode_t; - - static const ScanningPolicyMode_t SCAN_POLICY_IGNORE_WHITELIST = ble::SCAN_POLICY_IGNORE_WHITELIST; - static const ScanningPolicyMode_t SCAN_POLICY_FILTER_ALL_ADV = ble::SCAN_POLICY_FILTER_ALL_ADV; - /** * Enumeration of BLE PHY */ diff --git a/features/FEATURE_BLE/ble/gap/ConnectionParameters.h b/features/FEATURE_BLE/ble/gap/ConnectionParameters.h index b097dd6696..f9a6811758 100644 --- a/features/FEATURE_BLE/ble/gap/ConnectionParameters.h +++ b/features/FEATURE_BLE/ble/gap/ConnectionParameters.h @@ -33,7 +33,7 @@ class ConnectionParameters { static const uint8_t MAX_PARAM_PHYS = 3; public: ConnectionParameters() : - _filterPolicy(ble::SCAN_POLICY_IGNORE_WHITELIST), + _filterPolicy(initiator_filter_policy_t::NO_FILTER), _ownAddressType(ble::own_address_type_t::PUBLIC) { for (uint8_t i = 0; i < MAX_PARAM_PHYS; ++i) { @@ -104,9 +104,7 @@ public: return *this; } - ConnectionParameters &setFilterPolicy( - ble::scanning_policy_mode_t filterPolicy - ) + ConnectionParameters &setFilterPolicy(initiator_filter_policy_t filterPolicy) { _filterPolicy = filterPolicy; @@ -151,7 +149,7 @@ public: return _ownAddressType; } - ble::scanning_policy_mode_t getFilterPolicy() const + initiator_filter_policy_t getFilterPolicy() const { return _filterPolicy; } @@ -160,8 +158,8 @@ public: { return ( _enabledPhy[ble::phy_t::LE_1M] * 1 + - _enabledPhy[ble::phy_t::LE_2M] * 1 + - _enabledPhy[ble::phy_t::LE_CODED] * 1 + _enabledPhy[ble::phy_t::LE_2M] * 1 + + _enabledPhy[ble::phy_t::LE_CODED] * 1 ); } @@ -309,7 +307,7 @@ private: } private: - ble::scanning_policy_mode_t _filterPolicy; + initiator_filter_policy_t _filterPolicy; ble::own_address_type_t _ownAddressType; uint16_t _scanInterval[MAX_PARAM_PHYS]; /* 0.625 ms */ diff --git a/features/FEATURE_BLE/ble/gap/ScanParameters.h b/features/FEATURE_BLE/ble/gap/ScanParameters.h index f6928db7b0..770926605a 100644 --- a/features/FEATURE_BLE/ble/gap/ScanParameters.h +++ b/features/FEATURE_BLE/ble/gap/ScanParameters.h @@ -56,7 +56,7 @@ public: ScanParameters() : own_address_type(own_address_type_t::PUBLIC), - scanning_filter_policy(ble::SCAN_POLICY_IGNORE_WHITELIST), + scanning_filter_policy(scanning_filter_policy_t::NO_FILTER), phys(ble::phy_set_t::PHY_SET_1M), phy_1m_configuration( scan_interval_t::min(), scan_window_t::min(), true @@ -77,13 +77,13 @@ public: return own_address_type; } - ScanParameters& set_scanning_filter_policy(ble::scanning_policy_mode_t filter_policy) + ScanParameters& set_scanning_filter_policy(ble::scanning_filter_policy_t filter_policy) { scanning_filter_policy = filter_policy; return *this; } - ble::scanning_policy_mode_t get_scanning_filter_policy() const + ble::scanning_filter_policy_t get_scanning_filter_policy() const { return scanning_filter_policy; } @@ -138,7 +138,7 @@ public: private: own_address_type_t own_address_type; - ble::scanning_policy_mode_t scanning_filter_policy; + ble::scanning_filter_policy_t scanning_filter_policy; ble::phy_set_t phys; diff --git a/features/FEATURE_BLE/ble/gap/Types.h b/features/FEATURE_BLE/ble/gap/Types.h index b3717540ca..cdae5e8e6e 100644 --- a/features/FEATURE_BLE/ble/gap/Types.h +++ b/features/FEATURE_BLE/ble/gap/Types.h @@ -285,39 +285,69 @@ struct advertising_filter_policy_t : SafeEnum { + enum type { + /** + * Accept all advertising packets except directed advertising packet not + * addressed to this device. + */ + NO_FILTER = 0x00, + + /** + * Accept only advertising packets from devices in the whitelist except + * directed advertising packet not addressed to this device. + */ + FILTER_ADVERTISING = 0x01, + + + /** + * Accept all advertising packets except directed advertising packets + * where the initiator's identity address does not address this device. + * + * @note Directed advertising packets where the initiator's address is a + * resolvable private address that cannot be resolved are also accepted. + */ + NO_FILTER_INCLUDE_UNRESOLVABLE_DIRECTED = 2, + + /** + * Accept all advertising packets except: + * - advertising packets where the advertiser's + * identity address is not in the White List, + * - directed advertising packets where the initiator's identity address + * does not address this device. + * + * @note Directed advertising packets where the initiator's address is a + * resolvable private address that cannot be resolved are also accepted. + */ + FILTER_ADVERTISING_INCLUDE_UNRESOLVABLE_DIRECTED = 3 + }; /** - * The whitelist is used to filter incoming advertising. + * Construct a new instance of scanning_filter_policy_t. */ - SCAN_POLICY_FILTER_ALL_ADV = 1, - - /** - * Accept all advertising packets except directed advertising packets - * where the initiator's identity address does not address this device. - * - * @note Directed advertising packets where the initiator's address is a - * resolvable private address that cannot be resolved are also accepted. - */ - SCAN_POLICY_IGNORE_WHITELIST_INCLUDE_UNRESOLVABLE = 2, - - /** - * Accept all advertising packets except: - * - advertising packets where the advertiser's - * identity address is not in the White List, - * - directed advertising packets where the initiator's identity address - * does not address this device. - * - * @note Directed advertising packets where the initiator's address is a - * resolvable private address that cannot be resolved are also accepted. - */ - SCAN_POLICY_FILTER_ALL_ADV_INCLUDE_UNRESOLVABLE = 3 + scanning_filter_policy_t(type value) : SafeEnum(value) { } }; +/** + * Filter policy which can be used during connection initiation. + */ +struct initiator_filter_policy_t : SafeEnum { + enum type { + /** + * The whitelist is not used to determine which advertiser to connect to. + */ + NO_FILTER, + + /** + * Whitelist is used to determine which advertiser to connect to. + */ + USE_WHITE_LIST + }; + + initiator_filter_policy_t(type value) : SafeEnum(value) { } +}; + + /** * Scanning policy filter mode. * diff --git a/features/FEATURE_BLE/ble/pal/GapTypes.h b/features/FEATURE_BLE/ble/pal/GapTypes.h index 4f320ea2a5..90d8fbb0dd 100644 --- a/features/FEATURE_BLE/ble/pal/GapTypes.h +++ b/features/FEATURE_BLE/ble/pal/GapTypes.h @@ -299,54 +299,9 @@ struct disconnection_reason_t : SafeEnum { typedef ble::advertising_filter_policy_t advertising_filter_policy_t; -/** - * Filter policy which can be used during a scan. - */ -struct scanning_filter_policy_t : SafeEnum { - enum type { - /** - * Accept all advertising packets except directed advertising packet not - * addressed to this device. - */ - NO_FILTER = 0x00, +typedef ble::scanning_filter_policy_t scanning_filter_policy_t; - /** - * Accept only advertising packets from devices in the whitelist except - * directed advertising packet not addressed to this device. - */ - FILTER_ADVERTISING = 0x01 - - // EXTENDED ADVERTISING FILTER POLICY (accept private resolvable direct advertising) - }; - - /** - * Construct a new instance of scanning_filter_policy_t. - */ - scanning_filter_policy_t(type value) : - SafeEnum(value) { } - -}; - - -/** - * Filter policy which can be used during connection initiation. - */ -struct initiator_policy_t : SafeEnum { - enum type { - /** - * The whitelist is not used to determine which advertiser to connect to. - */ - NO_FILTER, - - /** - * Whitelist is used to determine which advertiser to connect to. - */ - USE_WHITE_LIST - }; - - initiator_policy_t(type value) : - SafeEnum(value) { } -}; +typedef ble::initiator_filter_policy_t initiator_policy_t; /** * Hold advertising data. diff --git a/features/FEATURE_BLE/source/generic/GenericGap.cpp b/features/FEATURE_BLE/source/generic/GenericGap.cpp index b0c3ab9a8e..4f4ee03a1b 100644 --- a/features/FEATURE_BLE/source/generic/GenericGap.cpp +++ b/features/FEATURE_BLE/source/generic/GenericGap.cpp @@ -630,7 +630,7 @@ ble_error_t GenericGap::connect( } return _pal_gap.extended_create_connection( - (ble::pal::initiator_policy_t::type)connectionParams.getFilterPolicy(), + connectionParams.getFilterPolicy(), (ble::pal::own_address_type_t::type)connectionParams.getOwnAddressType().value(), (ble::peer_address_type_t::type)peerAddressType.value(), peerAddress, @@ -2387,7 +2387,7 @@ ble_error_t GenericGap::setScanParameters(const ScanParameters ¶ms) return _pal_gap.set_extended_scan_parameters( (pal::own_address_type_t::type) params.get_own_address_type().value(), - (pal::scanning_filter_policy_t::type) params.get_scanning_filter_policy(), + params.get_scanning_filter_policy(), params.get_scanning_phys(), active_scanning, scan_interval, @@ -2406,7 +2406,7 @@ ble_error_t GenericGap::setScanParameters(const ScanParameters ¶ms) legacy_configuration.interval.value(), legacy_configuration.window.value(), (pal::own_address_type_t::type) params.get_own_address_type().value(), - (pal::scanning_filter_policy_t::type) params.get_scanning_filter_policy() + params.get_scanning_filter_policy() ); } }