From 60fb78795b700d01514c63c2b9e1c7da40a50806 Mon Sep 17 00:00:00 2001 From: paul-szczepanek-arm <33840200+paul-szczepanek-arm@users.noreply.github.com> Date: Fri, 9 Nov 2018 10:48:18 +0000 Subject: [PATCH] fix adv and scan types --- features/FEATURE_BLE/ble/BLETypes.h | 12 +++++- features/FEATURE_BLE/ble/Gap.h | 9 ++-- features/FEATURE_BLE/ble/GapAdvertisingData.h | 2 +- .../FEATURE_BLE/ble/GapAdvertisingParams.h | 42 +++++++++++++++---- features/FEATURE_BLE/ble/GapScanningParams.h | 20 --------- features/FEATURE_BLE/ble/pal/GapTypes.h | 1 + .../FEATURE_BLE/source/GapScanningParams.cpp | 4 +- .../FEATURE_BLE/source/generic/GenericGap.cpp | 11 ++--- 8 files changed, 55 insertions(+), 46 deletions(-) diff --git a/features/FEATURE_BLE/ble/BLETypes.h b/features/FEATURE_BLE/ble/BLETypes.h index 21e4602b08..9e294f7576 100644 --- a/features/FEATURE_BLE/ble/BLETypes.h +++ b/features/FEATURE_BLE/ble/BLETypes.h @@ -143,7 +143,7 @@ enum advertising_type_t { /** * Device is connectable and expects connection from a specific peer. - * + * (3.75 ms or smaller Advertising Interval) * @see Vol 3, Part C, Section 9.3.3 and Vol 6, Part B, Section 2.3.1.2. */ ADV_CONNECTABLE_DIRECTED, @@ -160,7 +160,12 @@ enum advertising_type_t { * * @see Vol 3, Part C, Section 9.3.2 and Vol 6, Part B, Section 2.3.1.3. */ - ADV_NON_CONNECTABLE_UNDIRECTED + ADV_NON_CONNECTABLE_UNDIRECTED, + + /** + * Device is connectable and expects connection from a specific peer (sent at long user set intervals). + */ + ADV_CONNECTABLE_DIRECTED_LOW_DUTY }; struct advertising_data_status_t : SafeEnum{ @@ -204,6 +209,9 @@ struct advertising_event_t { case ADV_NON_CONNECTABLE_UNDIRECTED: value = 0x20; break; + case ADV_CONNECTABLE_DIRECTED_LOW_DUTY: + value = 0x2D; + break; } } diff --git a/features/FEATURE_BLE/ble/Gap.h b/features/FEATURE_BLE/ble/Gap.h index b677bbc64d..c953f0a5fd 100644 --- a/features/FEATURE_BLE/ble/Gap.h +++ b/features/FEATURE_BLE/ble/Gap.h @@ -1284,15 +1284,14 @@ public: /* scanning */ ble_error_t setScanParameters( - const GapScanningParams* params = NULL, - const GapScanningParams* params = NULL, - const GapScanningParams* params = NULL + const GapScanningParams* params ) { - return startRadioScan(params); + /* Requesting action from porter(s): override this API if this capability is supported. */ + return BLE_ERROR_NOT_IMPLEMENTED; }; ble_error_t startScan( - ble::scanning_filter_duplicates_t filtering = SCAN_FILTER_DUPLICATES_DISABLED, + ble::scanning_filter_duplicates_t filtering = ble::SCAN_FILTER_DUPLICATES_DISABLED, uint32_t duration = 0, uint32_t period = 0 ) { diff --git a/features/FEATURE_BLE/ble/GapAdvertisingData.h b/features/FEATURE_BLE/ble/GapAdvertisingData.h index 52aa7e991d..aaaac71909 100644 --- a/features/FEATURE_BLE/ble/GapAdvertisingData.h +++ b/features/FEATURE_BLE/ble/GapAdvertisingData.h @@ -722,7 +722,7 @@ public: uint16_t appearance = GENERIC_TAG; const uint8_t *field = findField(AdvertisingData::APPEARANCE); if (field) { - memcpy((uint8_t*)appearance, field, 2); + memcpy((uint8_t*)&appearance, field, 2); } return appearance; } diff --git a/features/FEATURE_BLE/ble/GapAdvertisingParams.h b/features/FEATURE_BLE/ble/GapAdvertisingParams.h index e8b28698f4..f1499b5402 100644 --- a/features/FEATURE_BLE/ble/GapAdvertisingParams.h +++ b/features/FEATURE_BLE/ble/GapAdvertisingParams.h @@ -271,21 +271,24 @@ public: the local IRK from the resolving list. If the resolving list contains no matching entry, use previously set random address. */ }; + own_address_type_t(type value) : ble::SafeEnum(value) { } }; + struct peer_address_type_t : ble::SafeEnum { enum type { PUBLIC = 0, /**< Public Device Address or Public Identity Address. */ RANDOM /**< Random Device Address or Random (static) Identity Address. */ }; + peer_address_type_t(type value) : ble::SafeEnum(value) { } }; public: GapExtendedAdvertisingParams() : - _advType(ble::advertising_event_t().connectable(true).scannable_advertising(true)), + _advType(ble::ADV_CONNECTABLE_UNDIRECTED), _minInterval(0), _maxInterval(0), - _peerAddressType(), - _ownAddressType(), + _peerAddressType(peer_address_type_t::PUBLIC), + _ownAddressType(own_address_type_t::PUBLIC), _policy(ble::ADV_POLICY_IGNORE_WHITELIST), _primaryPhy(ble::phy_t::LE_1M), _secondaryPhy(ble::phy_t::LE_1M), @@ -296,7 +299,9 @@ public: _channel38(1), _channel39(1), _anonymous(0), - _notifyOnScan(1) { } + _notifyOnScan(1), + _legacyPDU(0), + _includeHeaderTxPower(0) { } /** * Update the advertising type. @@ -314,7 +319,7 @@ public: * * @return Advertising type. */ - ble::advertising_event_t getType() const { + ble::advertising_type_t getType() const { return _advType; } @@ -372,7 +377,6 @@ public: _channel39 = channel39; } - //TODO new type in params own_address_type_t getOwnAddressType() const { return _ownAddressType; } @@ -463,6 +467,26 @@ public: return _notifyOnScan; } + void setUseLegacyPDU( + bool enable = true + ) { + _legacyPDU = enable; + } + + bool getUseLegacyPDU() const { + return _legacyPDU; + } + + void includeTxPowerInHeader( + bool enable = true + ) { + _includeHeaderTxPower = enable; + } + + bool getTxPowerInHeader() const { + return _includeHeaderTxPower; + } + /* helper get functions */ uint32_t getMinPrimaryInterval() const { @@ -502,11 +526,11 @@ public: } private: - ble::advertising_event_t _advType; + ble::advertising_type_t _advType; uint32_t _minInterval; uint32_t _maxInterval; peer_address_type_t _peerAddressType; - BLEProtocol::AddressType_t _ownAddressType; + own_address_type_t _ownAddressType; ble::advertising_policy_mode_t _policy; ble::phy_t _primaryPhy; ble::phy_t _secondaryPhy; @@ -518,6 +542,8 @@ private: uint8_t _channel39:1; uint8_t _anonymous:1; uint8_t _notifyOnScan:1; + uint8_t _legacyPDU:1; + uint8_t _includeHeaderTxPower:1; }; /** diff --git a/features/FEATURE_BLE/ble/GapScanningParams.h b/features/FEATURE_BLE/ble/GapScanningParams.h index b929c6a27e..1aeef8a0f2 100644 --- a/features/FEATURE_BLE/ble/GapScanningParams.h +++ b/features/FEATURE_BLE/ble/GapScanningParams.h @@ -206,26 +206,6 @@ public: return _activeScanning; } - /** - * - * @param phy LE_2m is illegal - */ - void setScanningPhy(ble::phy_t phy) { - _phy = phy; - } - - ble::phy_t getScanningPhy() { - return _phy; - } - - ble::scanning_policy_mode_t getScanningPolicy() { - return _mode; - } - - void setScanningPolicy(ble::scanning_policy_mode_t mode) { - _mode = mode; - } - private: /** * Scan interval in units of 625us (between 2.5ms and 10.24s). diff --git a/features/FEATURE_BLE/ble/pal/GapTypes.h b/features/FEATURE_BLE/ble/pal/GapTypes.h index 74e2a18329..42593141a9 100644 --- a/features/FEATURE_BLE/ble/pal/GapTypes.h +++ b/features/FEATURE_BLE/ble/pal/GapTypes.h @@ -651,6 +651,7 @@ struct advertising_event_properties_t { scannable = true; break; case ADV_CONNECTABLE_DIRECTED: + case ADV_CONNECTABLE_DIRECTED_LOW_DUTY: connectable = true; directed = true; break; diff --git a/features/FEATURE_BLE/source/GapScanningParams.cpp b/features/FEATURE_BLE/source/GapScanningParams.cpp index d0ca1acc58..1d9f1cb26f 100644 --- a/features/FEATURE_BLE/source/GapScanningParams.cpp +++ b/features/FEATURE_BLE/source/GapScanningParams.cpp @@ -21,9 +21,7 @@ GapScanningParams::GapScanningParams(uint16_t interval, uint16_t window, uint16_ _interval(MSEC_TO_SCAN_DURATION_UNITS(interval)), _window(MSEC_TO_SCAN_DURATION_UNITS(window)), _timeout(timeout), - _activeScanning(activeScanning), - _phy(ble::phy_t::LE_1M), - _mode(ble::SCAN_POLICY_IGNORE_WHITELIST) { + _activeScanning(activeScanning) { /* stay within limits */ if (_interval < SCAN_INTERVAL_MIN) { _interval = SCAN_INTERVAL_MIN; diff --git a/features/FEATURE_BLE/source/generic/GenericGap.cpp b/features/FEATURE_BLE/source/generic/GenericGap.cpp index 74a2ab5dd6..7215c3f55f 100644 --- a/features/FEATURE_BLE/source/generic/GenericGap.cpp +++ b/features/FEATURE_BLE/source/generic/GenericGap.cpp @@ -1633,7 +1633,7 @@ ble_error_t GenericGap::setAdvertisingParams(AdvHandle_t handle, const GapAdvert address_t dummy_peer_address; - pal::advertising_event_properties_t event_properties(adv_type); + pal::advertising_event_properties_t event_properties((pal::advertising_type_t::type)adv_type); return _pal_gap.set_extended_advertising_parameters( Gap::LEGACY_ADVERTISING_HANDLE, @@ -1660,8 +1660,7 @@ ble_error_t GenericGap::setAdvertisingParams(AdvHandle_t handle, const GapExtend } pal::advertising_channel_map_t channel_map(params->getChannel37(), params->getChannel38(), params->getChannel39()); - pal::advertising_event_properties_t event_properties;//TODO - //params->getAdvertisingType() + pal::advertising_event_properties_t event_properties((pal::advertising_type_t::type)params->getType()); return _pal_gap.set_extended_advertising_parameters( handle, @@ -1669,10 +1668,8 @@ ble_error_t GenericGap::setAdvertisingParams(AdvHandle_t handle, const GapExtend (pal::advertising_interval_t)params->getMinPrimaryInterval(), (pal::advertising_interval_t)params->getMaxPrimaryInterval(), channel_map, - params->getOwnAddressType(), - pal::own_address_type_t::PUBLIC_ADDRESS, - params->getPeerAddressType(), - pal::advertising_peer_address_type_t::PUBLIC_ADDRESS, + (pal::own_address_type_t::type)params->getOwnAddressType().value(), + (pal::advertising_peer_address_type_t::type)params->getPeerAddressType().value(), params->getPeerAddress(), (pal::advertising_filter_policy_t::type) params->getPolicyMode(), (pal::advertising_power_t) params->getTxPower(),