Skip to content

Commit c1c94c8

Browse files
authored
Merge pull request #8904 from pan-/ble-extended-advertising-fixes
Ble extended advertising fixes
2 parents 992bcba + 472c572 commit c1c94c8

File tree

13 files changed

+57
-57
lines changed

13 files changed

+57
-57
lines changed

features/FEATURE_BLE/ble/gap/AdvertisingDataParser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class AdvertisingDataParser {
8787
element_t next()
8888
{
8989
element_t element = {
90-
(ble::adv_data_type_t::type) data[TYPE_INDEX],
90+
(ble::adv_data_type_t::type) data[position + TYPE_INDEX],
9191
data.subspan(position + VALUE_INDEX, current_length() - (TYPE_SIZE))
9292
};
9393

features/FEATURE_BLE/ble/gap/AdvertisingParameters.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class AdvertisingParameters {
135135
_minInterval(minInterval),
136136
_maxInterval(maxInterval),
137137
_peerAddressType(target_peer_address_type_t::PUBLIC),
138-
_ownAddressType(own_address_type_t::PUBLIC),
138+
_ownAddressType(own_address_type_t::RANDOM),
139139
_policy(advertising_filter_policy_t::NO_FILTER),
140140
_primaryPhy(phy_t::LE_1M),
141141
_secondaryPhy(phy_t::LE_1M),

features/FEATURE_BLE/ble/gap/ConnectionParameters.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,10 @@ class ConnectionParameters {
145145
phy_t phy = phy_t::LE_1M,
146146
scan_interval_t scanInterval = scan_interval_t::min(),
147147
scan_window_t scanWindow = scan_window_t::min(),
148-
conn_interval_t minConnectionInterval = conn_interval_t::min(),
149-
conn_interval_t maxConnectionInterval = conn_interval_t::max(),
148+
conn_interval_t minConnectionInterval = conn_interval_t(50),
149+
conn_interval_t maxConnectionInterval = conn_interval_t(100),
150150
slave_latency_t slaveLatency = slave_latency_t::min(),
151-
supervision_timeout_t connectionSupervisionTimeout = supervision_timeout_t::max(),
151+
supervision_timeout_t connectionSupervisionTimeout = supervision_timeout_t(100),
152152
conn_event_length_t minEventLength = conn_event_length_t::min(),
153153
conn_event_length_t maxEventLength = conn_event_length_t::max()
154154
);
@@ -215,7 +215,7 @@ class ConnectionParameters {
215215
*
216216
* @return A reference to this.
217217
*/
218-
ConnectionParameters &setFilterPolicy(initiator_filter_policy_t filterPolicy)
218+
ConnectionParameters &setFilter(initiator_filter_policy_t filterPolicy)
219219
{
220220
_filterPolicy = filterPolicy;
221221

@@ -282,7 +282,7 @@ class ConnectionParameters {
282282
*
283283
* @return The initiator policy.
284284
*/
285-
initiator_filter_policy_t getFilterPolicy() const
285+
initiator_filter_policy_t getFilter() const
286286
{
287287
return _filterPolicy;
288288
}

features/FEATURE_BLE/ble/gap/Events.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ struct AdvertisingReportEvent {
152152
}
153153

154154
/** Get payload. */
155-
const mbed::Span<const uint8_t> &getAdvertisingData() const
155+
const mbed::Span<const uint8_t> &getPayload() const
156156
{
157157
return advertisingData;
158158
}
@@ -630,10 +630,10 @@ struct ScanRequestEvent {
630630
*
631631
* @see ble::Gap::EventHandler::onDisconnectionComplete().
632632
*/
633-
struct DisconnectionEvent {
633+
struct DisconnectionCompleteEvent {
634634
#if !defined(DOXYGEN_ONLY)
635635

636-
DisconnectionEvent(
636+
DisconnectionCompleteEvent(
637637
connection_handle_t connectionHandle,
638638
const disconnection_reason_t &reason
639639
) :

features/FEATURE_BLE/ble/gap/Gap.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ class Gap {
427427
*
428428
* @see disconnect()
429429
*/
430-
virtual void onDisconnectionComplete(const DisconnectionEvent &event)
430+
virtual void onDisconnectionComplete(const DisconnectionCompleteEvent &event)
431431
{
432432
}
433433

@@ -536,7 +536,7 @@ class Gap {
536536
*
537537
* @return Maximum advertising data length supported.
538538
*/
539-
virtual uint8_t getMaxAdvertisingDataLength();
539+
virtual uint16_t getMaxAdvertisingDataLength();
540540

541541
/** Create an advertising set and apply the passed in parameters. The handle returned
542542
* by this function must be used for all other calls that accept an advertising handle.
@@ -711,8 +711,8 @@ class Gap {
711711

712712
/** Start scanning.
713713
*
714-
* @param filtering Filtering policy.
715714
* @param duration How long to scan for. Special value 0 means scan forever.
715+
* @param filtering Filtering policy.
716716
* @param period How long to scan for in single period. If the period is 0 and duration
717717
* is nonzero the scan will last for single duration.
718718
*
@@ -726,8 +726,8 @@ class Gap {
726726
* @see EventHandler::onScanTimeout when scanning timeout.
727727
*/
728728
virtual ble_error_t startScan(
729-
duplicates_filter_t filtering = duplicates_filter_t::DISABLE,
730729
scan_duration_t duration = scan_duration_t::forever(),
730+
duplicates_filter_t filtering = duplicates_filter_t::DISABLE,
731731
scan_period_t period = scan_period_t(0)
732732
);
733733

features/FEATURE_BLE/ble/gap/ScanParameters.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class ScanParameters {
121121
scan_window_t scan_interval = scan_interval_t::min(),
122122
scan_interval_t scan_window = scan_window_t::min(),
123123
bool active_scanning = false,
124-
own_address_type_t own_address_type = own_address_type_t::PUBLIC,
124+
own_address_type_t own_address_type = own_address_type_t::RANDOM,
125125
scanning_filter_policy_t scanning_filter_policy = scanning_filter_policy_t::NO_FILTER
126126
) :
127127
own_address_type(own_address_type),

features/FEATURE_BLE/ble/gap/Types.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,9 @@ struct peripheral_privacy_configuration_t {
891891
PERFORM_AUTHENTICATION_PROCEDURE
892892
};
893893

894+
MBED_DEPRECATED_SINCE("mbed-os-5.11", "Use resolution_strategy_t instead.")
895+
typedef resolution_strategy_t ResolutionStrategy;
896+
894897
/**
895898
* Connection strategy to use when a connection request contains a
896899
* private resolvable address.
@@ -941,6 +944,9 @@ struct central_privay_configuration_t {
941944
RESOLVE_AND_FILTER
942945
};
943946

947+
MBED_DEPRECATED_SINCE("mbed-os-5.11", "Use resolution_strategy_t instead.")
948+
typedef resolution_strategy_t ResolutionStrategy;
949+
944950
/**
945951
* Resolution strategy applied to advertising packets received by the
946952
* local device.

features/FEATURE_BLE/ble/generic/GenericGap.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class GenericGap :
9090

9191
/** @copydoc Gap::getMaxAdvertisingDataLength
9292
*/
93-
virtual uint8_t getMaxAdvertisingDataLength();
93+
virtual uint16_t getMaxAdvertisingDataLength();
9494

9595
/** @copydoc Gap::createAdvertisingSet
9696
*/
@@ -175,8 +175,8 @@ class GenericGap :
175175
/** @copydoc Gap::startScan
176176
*/
177177
virtual ble_error_t startScan(
178-
duplicates_filter_t filtering,
179178
scan_duration_t duration,
179+
duplicates_filter_t filtering,
180180
scan_period_t period
181181
);
182182

features/FEATURE_BLE/source/BLE.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <stdio.h>
1818
#include "ble/BLE.h"
1919
#include "ble/BLEInstanceBase.h"
20+
#include "platform/mbed_critical.h"
2021

2122
#if defined(TARGET_OTA_ENABLED)
2223
#include "ble/services/DFUService.h"
@@ -299,16 +300,19 @@ void BLE::waitForEvent(void)
299300

300301
void BLE::processEvents()
301302
{
303+
core_util_critical_section_enter();
302304
if (event_signaled == false) {
305+
core_util_critical_section_exit();
303306
return;
304307
}
305308

309+
event_signaled = false;
310+
core_util_critical_section_exit();
311+
306312
if (!transport) {
307313
MBED_ERROR(MBED_MAKE_ERROR(MBED_MODULE_BLE, MBED_ERROR_CODE_BLE_BACKEND_NOT_INITIALIZED), "bad handle to underlying transport");
308314
}
309315

310-
event_signaled = false;
311-
312316
transport->processEvents();
313317
}
314318

@@ -328,11 +332,14 @@ void BLE::onEventsToProcess(const BLE::OnEventsToProcessCallback_t& callback)
328332

329333
void BLE::signalEventsToProcess()
330334
{
335+
core_util_critical_section_enter();
331336
if (event_signaled == true) {
337+
core_util_critical_section_exit();
332338
return;
333339
}
334340

335341
event_signaled = true;
342+
core_util_critical_section_exit();
336343

337344
if (whenEventsToProcess) {
338345
OnEventsToProcessCallbackContext params = {

features/FEATURE_BLE/source/gap/ConnectionParameters.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ ConnectionParameters::ConnectionParameters(
3030
conn_event_length_t maxEventLength
3131
) :
3232
_filterPolicy(initiator_filter_policy_t::NO_FILTER),
33-
_ownAddressType(own_address_type_t::PUBLIC)
33+
_ownAddressType(own_address_type_t::RANDOM)
3434
{
3535
for (uint8_t i = 0; i < MAX_PARAM_PHYS; ++i) {
3636
_enabledPhy[i] = false;

features/FEATURE_BLE/source/gap/Gap.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ uint8_t Gap::getMaxAdvertisingSetNumber()
3030
return 1;
3131
}
3232

33-
uint8_t Gap::getMaxAdvertisingDataLength()
33+
uint16_t Gap::getMaxAdvertisingDataLength()
3434
{
3535
/* Requesting action from porter(s): override this API if this capability is supported. */
3636
return LEGACY_ADVERTISING_MAX_SIZE;
@@ -145,8 +145,8 @@ ble_error_t Gap::setScanParameters(const ScanParameters &params)
145145
};
146146

147147
ble_error_t Gap::startScan(
148-
duplicates_filter_t filtering,
149148
scan_duration_t duration,
149+
duplicates_filter_t filtering,
150150
scan_period_t period
151151
)
152152
{

features/FEATURE_BLE/source/generic/GenericGap.cpp

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -675,10 +675,13 @@ ble_error_t GenericGap::connect(
675675
return BLE_ERROR_INVALID_PARAM;
676676
}
677677

678+
// ensure scan is stopped.
679+
_pal_gap.scan_enable(false, false);
680+
678681
return _pal_gap.create_connection(
679682
connectionParams.getScanIntervalArray()[0],
680683
connectionParams.getScanWindowArray()[0],
681-
connectionParams.getFilterPolicy(),
684+
connectionParams.getFilter(),
682685
(pal::connection_peer_address_type_t::type) peerAddressType.value(),
683686
peerAddress,
684687
connectionParams.getOwnAddressType(),
@@ -691,6 +694,9 @@ ble_error_t GenericGap::connect(
691694
);
692695
}
693696

697+
// ensure scan is stopped.
698+
_pal_gap.extended_scan_enable(false, pal::duplicates_filter_t::DISABLE, 0, 0);
699+
694700
// reduce the address type to public or random
695701
peer_address_type_t adjusted_address_type(peer_address_type_t::PUBLIC);
696702

@@ -701,7 +707,7 @@ ble_error_t GenericGap::connect(
701707
}
702708

703709
return _pal_gap.extended_create_connection(
704-
connectionParams.getFilterPolicy(),
710+
connectionParams.getFilter(),
705711
connectionParams.getOwnAddressType(),
706712
adjusted_address_type,
707713
peerAddress,
@@ -1442,7 +1448,7 @@ void GenericGap::processDisconnectionEvent(
14421448

14431449
if (_eventHandler) {
14441450
_eventHandler->onDisconnectionComplete(
1445-
DisconnectionEvent(
1451+
DisconnectionCompleteEvent(
14461452
handle,
14471453
(disconnection_reason_t::type) reason
14481454
)
@@ -1997,7 +2003,7 @@ uint8_t GenericGap::getMaxAdvertisingSetNumber()
19972003
}
19982004
}
19992005

2000-
uint8_t GenericGap::getMaxAdvertisingDataLength()
2006+
uint16_t GenericGap::getMaxAdvertisingDataLength()
20012007
{
20022008
useVersionTwoAPI();
20032009
return _pal_gap.get_maximum_advertising_data_length();
@@ -2053,7 +2059,7 @@ ble_error_t GenericGap::destroyAdvertisingSet(advertising_handle_t handle)
20532059
return BLE_ERROR_INVALID_PARAM;
20542060
}
20552061

2056-
if (_existing_sets.get(handle) == false) {
2062+
if (!_existing_sets.get(handle)) {
20572063
return BLE_ERROR_INVALID_PARAM;
20582064
}
20592065

@@ -2357,10 +2363,14 @@ ble_error_t GenericGap::stopAdvertising(advertising_handle_t handle)
23572363
return BLE_ERROR_INVALID_PARAM;
23582364
}
23592365

2360-
if (_existing_sets.get(handle)) {
2366+
if (!_existing_sets.get(handle)) {
23612367
return BLE_ERROR_INVALID_PARAM;
23622368
}
23632369

2370+
if (!_active_sets.get(handle)) {
2371+
return BLE_ERROR_INVALID_STATE;
2372+
}
2373+
23642374
ble_error_t status;
23652375

23662376
if (is_extended_advertising_available()) {
@@ -2427,7 +2437,7 @@ ble_error_t GenericGap::setPeriodicAdvertisingParameters(
24272437
}
24282438

24292439
if (!_existing_sets.get(handle)) {
2430-
return BLE_ERROR_INVALID_STATE;
2440+
return BLE_ERROR_INVALID_PARAM;
24312441
}
24322442

24332443
return _pal_gap.set_periodic_advertising_parameters(
@@ -2454,7 +2464,7 @@ ble_error_t GenericGap::setPeriodicAdvertisingPayload(
24542464
}
24552465

24562466
if (!_existing_sets.get(handle)) {
2457-
return BLE_ERROR_INVALID_STATE;
2467+
return BLE_ERROR_INVALID_PARAM;
24582468
}
24592469

24602470
if (payload.size() > getMaxAdvertisingDataLength()) {
@@ -2511,7 +2521,7 @@ ble_error_t GenericGap::startPeriodicAdvertising(advertising_handle_t handle)
25112521
}
25122522

25132523
if (!_existing_sets.get(handle)) {
2514-
return BLE_ERROR_INVALID_STATE;
2524+
return BLE_ERROR_INVALID_PARAM;
25152525
}
25162526

25172527
if (_active_sets.get(handle) == false) {
@@ -2544,7 +2554,7 @@ ble_error_t GenericGap::stopPeriodicAdvertising(advertising_handle_t handle)
25442554
}
25452555

25462556
if (!_existing_sets.get(handle)) {
2547-
return BLE_ERROR_INVALID_STATE;
2557+
return BLE_ERROR_INVALID_PARAM;
25482558
}
25492559

25502560
if (_active_periodic_sets.get(handle) == false) {
@@ -2859,8 +2869,8 @@ ble_error_t GenericGap::setScanParameters(const ScanParameters &params)
28592869
}
28602870

28612871
ble_error_t GenericGap::startScan(
2862-
duplicates_filter_t filtering,
28632872
scan_duration_t duration,
2873+
duplicates_filter_t filtering,
28642874
scan_period_t period
28652875
)
28662876
{

features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioPalGap.cpp

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -510,30 +510,7 @@ void Gap::gap_handler(const wsfMsgHdr_t *msg)
510510
handler->on_periodic_advertising_sync_loss(evt->syncHandle);
511511
}
512512
break;
513-
514-
case DM_CONN_OPEN_IND: {
515-
if (!handler) {
516-
break;
517-
}
518-
519-
// TODO: filter with old event ...
520-
const hciLeConnCmplEvt_t *evt = (const hciLeConnCmplEvt_t *) msg;
521-
handler->on_enhanced_connection_complete(
522-
hci_error_code_t(evt->status),
523-
evt->handle,
524-
connection_role_t(evt->role),
525-
connection_peer_address_type_t(evt->addrType),
526-
evt->peerAddr,
527-
evt->localRpa,
528-
evt->peerRpa,
529-
evt->connInterval,
530-
evt->connLatency,
531-
evt->supTimeout,
532-
clock_accuracy_t(evt->clockAccuracy)
533-
);
534-
}
535-
break;
536-
513+
537514
case DM_SCAN_REQ_RCVD_IND: {
538515
if (!handler) {
539516
break;

0 commit comments

Comments
 (0)