Skip to content

Commit e377383

Browse files
authored
Merge pull request #14672 from paul-szczepanek-arm/fix-advertising-start
BLE: Fix advertising start and stop
2 parents 7c17693 + 2d9a781 commit e377383

File tree

6 files changed

+244
-74
lines changed

6 files changed

+244
-74
lines changed

connectivity/FEATURE_BLE/include/ble/Gap.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,9 @@ class Gap {
747747
* @param handle Advertising set handle.
748748
* @param maxDuration Max duration for advertising (in units of 10ms) - 0 means no limit.
749749
* @param maxEvents Max number of events produced during advertising - 0 means no limit.
750-
* @return BLE_ERROR_NONE on success.
750+
* @return BLE_ERROR_NONE on success. This does not guarantee the set has started if
751+
* extended advertising is enabled. Register an event handler and wait for onAdvertisingStart
752+
* event. An (unlikely) failed start the status of the event will contain an error.
751753
*
752754
* @see EventHandler::onAdvertisingStart when the advertising starts.
753755
* @see EventHandler::onScanRequestReceived when a scan request is received.
@@ -765,7 +767,9 @@ class Gap {
765767
* which will not be affected.
766768
*
767769
* @param handle Advertising set handle.
768-
* @return BLE_ERROR_NONE on success.
770+
* @return BLE_ERROR_NONE on success. For extented advertising this does not guarantee
771+
* the set is stopped if. Register an event handler and wait for onAdvertisingEnd event.
772+
* An (unlikely) failed stop the event status will contain the error code.
769773
*/
770774
ble_error_t stopAdvertising(advertising_handle_t handle);
771775

connectivity/FEATURE_BLE/include/ble/gap/Events.h

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -586,9 +586,10 @@ struct AdvertisingStartEvent {
586586
/** Create an advertising start event.
587587
*
588588
* @param advHandle Advertising set handle.
589+
* @param status Advertising set start command status.
589590
*/
590-
AdvertisingStartEvent(advertising_handle_t advHandle) :
591-
advHandle(advHandle)
591+
AdvertisingStartEvent(advertising_handle_t advHandle, ble_error_t status = BLE_ERROR_NONE) :
592+
advHandle(advHandle), status(status)
592593
{
593594
}
594595

@@ -600,8 +601,15 @@ struct AdvertisingStartEvent {
600601
return advHandle;
601602
}
602603

604+
/** Get status of operation. */
605+
ble_error_t getStatus() const
606+
{
607+
return status;
608+
}
609+
603610
private:
604611
advertising_handle_t advHandle;
612+
ble_error_t status;
605613
};
606614

607615
/**
@@ -610,7 +618,8 @@ struct AdvertisingStartEvent {
610618
* @see ble::Gap::EventHandler::onAdvertisingEnd().
611619
*
612620
* @note The connection handle, connected flag and completed_event fields are
613-
* valid if the flag legacy is not set to true.
621+
* valid if the flag legacy is not set to true. If status is different from BLE_ERROR_NONE
622+
* the completed_events field is not valid and the set may still be active.
614623
*/
615624
struct AdvertisingEndEvent {
616625
#if !defined(DOXYGEN_ONLY)
@@ -621,18 +630,21 @@ struct AdvertisingEndEvent {
621630
* @param connection Connection handle.
622631
* @param completed_events Number of events created during before advertising end.
623632
* @param connected True if connection has been established.
633+
* @param status Error code if stop command failed.
624634
*/
625635
AdvertisingEndEvent(
626636
advertising_handle_t advHandle,
627637
connection_handle_t connection,
628638
uint8_t completed_events,
629-
bool connected
639+
bool connected,
640+
ble_error_t status = BLE_ERROR_NONE
630641
) :
631642
advHandle(advHandle),
632643
connection(connection),
633644
completed_events(completed_events),
634645
connected(connected),
635-
legacy(false)
646+
legacy(false),
647+
status(status)
636648
{
637649
}
638650

@@ -643,7 +655,8 @@ struct AdvertisingEndEvent {
643655
connection(),
644656
completed_events(0),
645657
connected(false),
646-
legacy(true)
658+
legacy(true),
659+
status(BLE_ERROR_NONE)
647660
{
648661
}
649662

@@ -683,12 +696,20 @@ struct AdvertisingEndEvent {
683696
return legacy;
684697
}
685698

699+
/** Get the result of the stop advertising event. If the status is not BLE_ERROR_NONE the set
700+
* may still be active. */
701+
ble_error_t getStatus() const
702+
{
703+
return status;
704+
}
705+
686706
private:
687707
advertising_handle_t advHandle;
688708
connection_handle_t connection;
689709
uint8_t completed_events;
690710
bool connected;
691711
bool legacy;
712+
ble_error_t status;
692713
};
693714

694715
/**

connectivity/FEATURE_BLE/mbed_lib.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@
108108
"value": 16,
109109
"macro_name": "BLE_GAP_HOST_PRIVACY_RESOLVED_CACHE_SIZE"
110110
},
111+
"ble-gap-host-max-advertising-start-commands": {
112+
"help": "There can only be one outstanding advertising set command sent to the controller. This determines how many advertising set start commands can be queued on the host. Must be between 1 and BLE_GAP_MAX_ADVERTISING_SETS. If privacy is used, this must be at equal or higher than then number of simultaneously active sets with a private address.",
113+
"value": 4,
114+
"macro_name": "BLE_GAP_HOST_MAX_OUTSTANDING_ADVERTISING_START_COMMANDS"
115+
},
111116

112117
"ble-passkey-display-reversed-digits-deprecation": {
113118
"help": "This option is part of the deprecation process. Set this to false to remove the deprecation notice. When set to true, the digits in the SecurityManager passkeyDiplay event are reversed. When set to false the digits are in the correct order.",

0 commit comments

Comments
 (0)