Skip to content

Commit c51dc2f

Browse files
set to pending only after issuing command
1 parent b21ee6b commit c51dc2f

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

connectivity/FEATURE_BLE/source/generic/GapImpl.cpp

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2392,11 +2392,19 @@ ble_error_t Gap::startAdvertising(
23922392
_pal_gap.set_advertising_set_random_address(handle, *random_address);
23932393
}
23942394

2395-
/* remember the parameters that will be enabled when the last command completes */
2395+
/* check we hanve't run out of space to remember parameters */
23962396
if (_advertising_enable_command_params.number_of_handles == BLE_GAP_HOST_MAX_OUTSTANDING_ADVERTISING_START_COMMANDS) {
2397-
return BLE_ERROR_NO_MEM;
2397+
/* try to process early */
2398+
tr_debug("Processing enable queue early as run out of queue space");
2399+
process_enable_queue();
2400+
/* if the processing didn't clear the handles we cannot continue */
2401+
if (_advertising_enable_command_params.number_of_handles) {
2402+
tr_debug("Cannot enable set as no memory to record the parameters");
2403+
return BLE_ERROR_NO_MEM;
2404+
}
23982405
}
23992406

2407+
/* remember the parameters that will be enabled in the delayed processing */
24002408
const uint8_t i = _advertising_enable_command_params.number_of_handles;
24012409
_advertising_enable_command_params.handles[i] = handle;
24022410
_advertising_enable_command_params.max_durations[i] = maxDuration;
@@ -2442,9 +2450,9 @@ ble_error_t Gap::startAdvertising(
24422450
}
24432451

24442452
_interruptible_sets.set(LEGACY_ADVERTISING_HANDLE);
2445-
}
24462453

2447-
_pending_sets.set(handle);
2454+
_pending_sets.set(handle);
2455+
}
24482456

24492457
return error;
24502458
}
@@ -2456,12 +2464,14 @@ void Gap::process_enable_queue()
24562464
tr_info("Evaluating pending advertising sets to be started");
24572465
if (!_advertising_enable_command_params.number_of_handles) {
24582466
/* no set pending to be enabled */
2467+
tr_debug("No sets to be enabled");
24592468
return;
24602469
}
24612470

24622471
for (size_t i = 0; i < BLE_GAP_MAX_ADVERTISING_SETS; ++i) {
24632472
if (_pending_sets.get(i)) {
24642473
/* we have to wait until nothing is pending */
2474+
tr_debug("Cannot enable sets as pending sets present");
24652475
return;
24662476
}
24672477
}
@@ -2491,6 +2501,7 @@ void Gap::process_enable_queue()
24912501
} else {
24922502
_interruptible_sets.set(_advertising_enable_command_params.handles[i]);
24932503
}
2504+
_pending_sets.set(_advertising_enable_command_params.handles[i]);
24942505
}
24952506
}
24962507

@@ -2553,9 +2564,9 @@ ble_error_t Gap::stopAdvertising(advertising_handle_t handle)
25532564
}
25542565

25552566
_advertising_timeout.detach();
2556-
}
25572567

2558-
_pending_sets.set(handle);
2568+
_pending_sets.set(handle);
2569+
}
25592570

25602571
return status;
25612572
}
@@ -2575,25 +2586,30 @@ void Gap::process_disable_queue()
25752586
}
25762587

25772588
if (number_of_handles) {
2578-
ble_error_t status = _pal_gap.extended_advertising_enable(
2589+
ble_error_t error = _pal_gap.extended_advertising_enable(
25792590
/* enable */ false,
25802591
number_of_handles,
25812592
(advertising_handle_t*)&sets,
25822593
nullptr,
25832594
nullptr
25842595
);
2585-
if (status) {
2596+
2597+
if (error) {
25862598
for (size_t i = 0; i < number_of_handles; ++i) {
25872599
_event_handler->onAdvertisingEnd(
25882600
AdvertisingEndEvent(
25892601
(advertising_handle_t)sets[i],
25902602
0/*connection*/,
25912603
0/*completed_events*/,
25922604
false/*connected*/,
2593-
status
2605+
error
25942606
)
25952607
);
2596-
tr_error("Could not stop advertising set %u, error: %s", i, to_string(status));
2608+
tr_error("Could not stop advertising set %u, error: %s", i, to_string(error));
2609+
}
2610+
} else {
2611+
for (size_t i = 0; i < number_of_handles; ++i) {
2612+
_pending_sets.set(sets[i]);
25972613
}
25982614
}
25992615
}

0 commit comments

Comments
 (0)