From 25438875c9e10f7d081cd72cc977fb82c7c5bf69 Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Sun, 3 Mar 2019 19:30:42 +0000 Subject: [PATCH] BLE - Report extended advertising in legacy handler if legacy API in use. Workaround for the Cordio stack as extended advertising can be reported for a legacy advertising command. --- .../FEATURE_BLE/source/generic/GenericGap.tpp | 85 +++++++++++++++---- 1 file changed, 67 insertions(+), 18 deletions(-) diff --git a/features/FEATURE_BLE/source/generic/GenericGap.tpp b/features/FEATURE_BLE/source/generic/GenericGap.tpp index 6c1329aa32..3ae4a170f4 100644 --- a/features/FEATURE_BLE/source/generic/GenericGap.tpp +++ b/features/FEATURE_BLE/source/generic/GenericGap.tpp @@ -2921,28 +2921,77 @@ void GenericGaponAdvertisingReport( - AdvertisingReportEvent( - event_type, - address_type ? - (peer_address_type_t::type) address_type->value() : - peer_address_type_t::ANONYMOUS, - (BLEProtocol::AddressBytes_t &) address, - primary_phy, - secondary_phy ? *secondary_phy : phy_t::NONE, - advertising_sid, - tx_power, + if (_deprecated_scan_api_used == false) { + // report in new event handler + if (!_eventHandler) { + return; + } + _eventHandler->onAdvertisingReport( + AdvertisingReportEvent( + event_type, + address_type ? + (peer_address_type_t::type) address_type->value() : + peer_address_type_t::ANONYMOUS, + (BLEProtocol::AddressBytes_t &) address, + primary_phy, + secondary_phy ? *secondary_phy : phy_t::NONE, + advertising_sid, + tx_power, + rssi, + periodic_advertising_interval, + (ble::peer_address_type_t::type) direct_address_type.value(), + (BLEProtocol::AddressBytes_t &) direct_address, + mbed::make_Span(data, data_length) + ) + ); + } else { + if (event_type.legacy_advertising() == false) { + return; + } + + GapAdvertisingParams::AdvertisingType_t advertising_type; + + if (event_type.connectable() == false) { + if (event_type.scannable_advertising()) { + advertising_type = GapAdvertisingParams::ADV_SCANNABLE_UNDIRECTED; + } else { + advertising_type = GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED; + } + } else { + if (event_type.directed_advertising()) { + advertising_type = GapAdvertisingParams::ADV_CONNECTABLE_DIRECTED; + } else { + advertising_type = GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED; + } + } + + // This handler is not supposed to be called with V1 API as the extended + // scan is not called. However the Cordio LL stack doesn't act that way + // and use extended scan with V1 API. + BLE_DEPRECATED_API_USE_BEGIN() + LegacyGap::processAdvertisementReport( + address.data(), rssi, - periodic_advertising_interval, - (ble::peer_address_type_t::type) direct_address_type.value(), - (BLEProtocol::AddressBytes_t &) direct_address, - mbed::make_Span(data, data_length) - ) - ); + event_type.scan_response(), + advertising_type, + data_length, + data, + (peer_address_type_t::type) address_type->value() + ); + BLE_DEPRECATED_API_USE_END() + } } template class PalGapImpl, class PalSecurityManager, class ConnectionEventMonitorEventHandler>