@@ -2392,11 +2392,19 @@ ble_error_t Gap::startAdvertising(
2392
2392
_pal_gap.set_advertising_set_random_address (handle, *random_address);
2393
2393
}
2394
2394
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 */
2396
2396
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
+ }
2398
2405
}
2399
2406
2407
+ /* remember the parameters that will be enabled in the delayed processing */
2400
2408
const uint8_t i = _advertising_enable_command_params.number_of_handles ;
2401
2409
_advertising_enable_command_params.handles [i] = handle;
2402
2410
_advertising_enable_command_params.max_durations [i] = maxDuration;
@@ -2442,9 +2450,9 @@ ble_error_t Gap::startAdvertising(
2442
2450
}
2443
2451
2444
2452
_interruptible_sets.set (LEGACY_ADVERTISING_HANDLE);
2445
- }
2446
2453
2447
- _pending_sets.set (handle);
2454
+ _pending_sets.set (handle);
2455
+ }
2448
2456
2449
2457
return error;
2450
2458
}
@@ -2456,12 +2464,14 @@ void Gap::process_enable_queue()
2456
2464
tr_info (" Evaluating pending advertising sets to be started" );
2457
2465
if (!_advertising_enable_command_params.number_of_handles ) {
2458
2466
/* no set pending to be enabled */
2467
+ tr_debug (" No sets to be enabled" );
2459
2468
return ;
2460
2469
}
2461
2470
2462
2471
for (size_t i = 0 ; i < BLE_GAP_MAX_ADVERTISING_SETS; ++i) {
2463
2472
if (_pending_sets.get (i)) {
2464
2473
/* we have to wait until nothing is pending */
2474
+ tr_debug (" Cannot enable sets as pending sets present" );
2465
2475
return ;
2466
2476
}
2467
2477
}
@@ -2491,6 +2501,7 @@ void Gap::process_enable_queue()
2491
2501
} else {
2492
2502
_interruptible_sets.set (_advertising_enable_command_params.handles [i]);
2493
2503
}
2504
+ _pending_sets.set (_advertising_enable_command_params.handles [i]);
2494
2505
}
2495
2506
}
2496
2507
@@ -2553,9 +2564,9 @@ ble_error_t Gap::stopAdvertising(advertising_handle_t handle)
2553
2564
}
2554
2565
2555
2566
_advertising_timeout.detach ();
2556
- }
2557
2567
2558
- _pending_sets.set (handle);
2568
+ _pending_sets.set (handle);
2569
+ }
2559
2570
2560
2571
return status;
2561
2572
}
@@ -2575,25 +2586,30 @@ void Gap::process_disable_queue()
2575
2586
}
2576
2587
2577
2588
if (number_of_handles) {
2578
- ble_error_t status = _pal_gap.extended_advertising_enable (
2589
+ ble_error_t error = _pal_gap.extended_advertising_enable (
2579
2590
/* enable */ false ,
2580
2591
number_of_handles,
2581
2592
(advertising_handle_t *)&sets,
2582
2593
nullptr ,
2583
2594
nullptr
2584
2595
);
2585
- if (status) {
2596
+
2597
+ if (error) {
2586
2598
for (size_t i = 0 ; i < number_of_handles; ++i) {
2587
2599
_event_handler->onAdvertisingEnd (
2588
2600
AdvertisingEndEvent (
2589
2601
(advertising_handle_t )sets[i],
2590
2602
0 /* connection*/ ,
2591
2603
0 /* completed_events*/ ,
2592
2604
false /* connected*/ ,
2593
- status
2605
+ error
2594
2606
)
2595
2607
);
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]);
2597
2613
}
2598
2614
}
2599
2615
}
0 commit comments