Skip to content

Commit 2543887

Browse files
committed
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.
1 parent b5d713d commit 2543887

File tree

1 file changed

+67
-18
lines changed

1 file changed

+67
-18
lines changed

features/FEATURE_BLE/source/generic/GenericGap.tpp

Lines changed: 67 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2921,28 +2921,77 @@ void GenericGap<PalGapImpl, PalSecurityManager, ConnectionEventMonitorEventHandl
29212921
const uint8_t *data
29222922
)
29232923
{
2924-
if (!_eventHandler) {
2924+
#if BLE_FEATURE_PRIVACY
2925+
// Check if the address hasn't been resolved
2926+
if (_privacy_enabled &&
2927+
_central_privacy_configuration.resolution_strategy == CentralPrivacyConfiguration_t::RESOLVE_AND_FILTER &&
2928+
address_type != NULL &&
2929+
*address_type == pal::connection_peer_address_type_t::RANDOM_ADDRESS &&
2930+
is_random_private_resolvable_address(address.data())
2931+
) {
29252932
return;
29262933
}
2934+
#endif // BLE_FEATURE_PRIVACY
29272935

2928-
_eventHandler->onAdvertisingReport(
2929-
AdvertisingReportEvent(
2930-
event_type,
2931-
address_type ?
2932-
(peer_address_type_t::type) address_type->value() :
2933-
peer_address_type_t::ANONYMOUS,
2934-
(BLEProtocol::AddressBytes_t &) address,
2935-
primary_phy,
2936-
secondary_phy ? *secondary_phy : phy_t::NONE,
2937-
advertising_sid,
2938-
tx_power,
2936+
if (_deprecated_scan_api_used == false) {
2937+
// report in new event handler
2938+
if (!_eventHandler) {
2939+
return;
2940+
}
2941+
_eventHandler->onAdvertisingReport(
2942+
AdvertisingReportEvent(
2943+
event_type,
2944+
address_type ?
2945+
(peer_address_type_t::type) address_type->value() :
2946+
peer_address_type_t::ANONYMOUS,
2947+
(BLEProtocol::AddressBytes_t &) address,
2948+
primary_phy,
2949+
secondary_phy ? *secondary_phy : phy_t::NONE,
2950+
advertising_sid,
2951+
tx_power,
2952+
rssi,
2953+
periodic_advertising_interval,
2954+
(ble::peer_address_type_t::type) direct_address_type.value(),
2955+
(BLEProtocol::AddressBytes_t &) direct_address,
2956+
mbed::make_Span(data, data_length)
2957+
)
2958+
);
2959+
} else {
2960+
if (event_type.legacy_advertising() == false) {
2961+
return;
2962+
}
2963+
2964+
GapAdvertisingParams::AdvertisingType_t advertising_type;
2965+
2966+
if (event_type.connectable() == false) {
2967+
if (event_type.scannable_advertising()) {
2968+
advertising_type = GapAdvertisingParams::ADV_SCANNABLE_UNDIRECTED;
2969+
} else {
2970+
advertising_type = GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED;
2971+
}
2972+
} else {
2973+
if (event_type.directed_advertising()) {
2974+
advertising_type = GapAdvertisingParams::ADV_CONNECTABLE_DIRECTED;
2975+
} else {
2976+
advertising_type = GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED;
2977+
}
2978+
}
2979+
2980+
// This handler is not supposed to be called with V1 API as the extended
2981+
// scan is not called. However the Cordio LL stack doesn't act that way
2982+
// and use extended scan with V1 API.
2983+
BLE_DEPRECATED_API_USE_BEGIN()
2984+
LegacyGap::processAdvertisementReport(
2985+
address.data(),
29392986
rssi,
2940-
periodic_advertising_interval,
2941-
(ble::peer_address_type_t::type) direct_address_type.value(),
2942-
(BLEProtocol::AddressBytes_t &) direct_address,
2943-
mbed::make_Span(data, data_length)
2944-
)
2945-
);
2987+
event_type.scan_response(),
2988+
advertising_type,
2989+
data_length,
2990+
data,
2991+
(peer_address_type_t::type) address_type->value()
2992+
);
2993+
BLE_DEPRECATED_API_USE_END()
2994+
}
29462995
}
29472996

29482997
template <template<class> class PalGapImpl, class PalSecurityManager, class ConnectionEventMonitorEventHandler>

0 commit comments

Comments
 (0)