Skip to content

Ble extended advertising fixes #8904

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Dec 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion features/FEATURE_BLE/ble/gap/AdvertisingDataParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class AdvertisingDataParser {
element_t next()
{
element_t element = {
(ble::adv_data_type_t::type) data[TYPE_INDEX],
(ble::adv_data_type_t::type) data[position + TYPE_INDEX],
data.subspan(position + VALUE_INDEX, current_length() - (TYPE_SIZE))
};

Expand Down
2 changes: 1 addition & 1 deletion features/FEATURE_BLE/ble/gap/AdvertisingParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class AdvertisingParameters {
_minInterval(minInterval),
_maxInterval(maxInterval),
_peerAddressType(target_peer_address_type_t::PUBLIC),
_ownAddressType(own_address_type_t::PUBLIC),
_ownAddressType(own_address_type_t::RANDOM),
_policy(advertising_filter_policy_t::NO_FILTER),
_primaryPhy(phy_t::LE_1M),
_secondaryPhy(phy_t::LE_1M),
Expand Down
10 changes: 5 additions & 5 deletions features/FEATURE_BLE/ble/gap/ConnectionParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ class ConnectionParameters {
phy_t phy = phy_t::LE_1M,
scan_interval_t scanInterval = scan_interval_t::min(),
scan_window_t scanWindow = scan_window_t::min(),
conn_interval_t minConnectionInterval = conn_interval_t::min(),
conn_interval_t maxConnectionInterval = conn_interval_t::max(),
conn_interval_t minConnectionInterval = conn_interval_t(50),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason for these particular values?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, they are more balanced with common use cases than the previous one (62 to 124 ms for the connection interval instead of 7.5 to 4 seconds).

conn_interval_t maxConnectionInterval = conn_interval_t(100),
slave_latency_t slaveLatency = slave_latency_t::min(),
supervision_timeout_t connectionSupervisionTimeout = supervision_timeout_t::max(),
supervision_timeout_t connectionSupervisionTimeout = supervision_timeout_t(100),
conn_event_length_t minEventLength = conn_event_length_t::min(),
conn_event_length_t maxEventLength = conn_event_length_t::max()
);
Expand Down Expand Up @@ -215,7 +215,7 @@ class ConnectionParameters {
*
* @return A reference to this.
*/
ConnectionParameters &setFilterPolicy(initiator_filter_policy_t filterPolicy)
ConnectionParameters &setFilter(initiator_filter_policy_t filterPolicy)
{
_filterPolicy = filterPolicy;

Expand Down Expand Up @@ -282,7 +282,7 @@ class ConnectionParameters {
*
* @return The initiator policy.
*/
initiator_filter_policy_t getFilterPolicy() const
initiator_filter_policy_t getFilter() const
{
return _filterPolicy;
}
Expand Down
6 changes: 3 additions & 3 deletions features/FEATURE_BLE/ble/gap/Events.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ struct AdvertisingReportEvent {
}

/** Get payload. */
const mbed::Span<const uint8_t> &getAdvertisingData() const
const mbed::Span<const uint8_t> &getPayload() const
{
return advertisingData;
}
Expand Down Expand Up @@ -630,10 +630,10 @@ struct ScanRequestEvent {
*
* @see ble::Gap::EventHandler::onDisconnectionComplete().
*/
struct DisconnectionEvent {
struct DisconnectionCompleteEvent {
#if !defined(DOXYGEN_ONLY)

DisconnectionEvent(
DisconnectionCompleteEvent(
connection_handle_t connectionHandle,
const disconnection_reason_t &reason
) :
Expand Down
8 changes: 4 additions & 4 deletions features/FEATURE_BLE/ble/gap/Gap.h
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ class Gap {
*
* @see disconnect()
*/
virtual void onDisconnectionComplete(const DisconnectionEvent &event)
virtual void onDisconnectionComplete(const DisconnectionCompleteEvent &event)
{
}

Expand Down Expand Up @@ -536,7 +536,7 @@ class Gap {
*
* @return Maximum advertising data length supported.
*/
virtual uint8_t getMaxAdvertisingDataLength();
virtual uint16_t getMaxAdvertisingDataLength();

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

/** Start scanning.
*
* @param filtering Filtering policy.
* @param duration How long to scan for. Special value 0 means scan forever.
* @param filtering Filtering policy.
* @param period How long to scan for in single period. If the period is 0 and duration
* is nonzero the scan will last for single duration.
*
Expand All @@ -726,8 +726,8 @@ class Gap {
* @see EventHandler::onScanTimeout when scanning timeout.
*/
virtual ble_error_t startScan(
duplicates_filter_t filtering = duplicates_filter_t::DISABLE,
scan_duration_t duration = scan_duration_t::forever(),
duplicates_filter_t filtering = duplicates_filter_t::DISABLE,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs doxygen update

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

scan_period_t period = scan_period_t(0)
);

Expand Down
2 changes: 1 addition & 1 deletion features/FEATURE_BLE/ble/gap/ScanParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class ScanParameters {
scan_window_t scan_interval = scan_interval_t::min(),
scan_interval_t scan_window = scan_window_t::min(),
bool active_scanning = false,
own_address_type_t own_address_type = own_address_type_t::PUBLIC,
own_address_type_t own_address_type = own_address_type_t::RANDOM,
scanning_filter_policy_t scanning_filter_policy = scanning_filter_policy_t::NO_FILTER
) :
own_address_type(own_address_type),
Expand Down
6 changes: 6 additions & 0 deletions features/FEATURE_BLE/ble/gap/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,9 @@ struct peripheral_privacy_configuration_t {
PERFORM_AUTHENTICATION_PROCEDURE
};

MBED_DEPRECATED_SINCE("mbed-os-5.11", "Use resolution_strategy_t instead.")
typedef resolution_strategy_t ResolutionStrategy;

/**
* Connection strategy to use when a connection request contains a
* private resolvable address.
Expand Down Expand Up @@ -941,6 +944,9 @@ struct central_privay_configuration_t {
RESOLVE_AND_FILTER
};

MBED_DEPRECATED_SINCE("mbed-os-5.11", "Use resolution_strategy_t instead.")
typedef resolution_strategy_t ResolutionStrategy;

/**
* Resolution strategy applied to advertising packets received by the
* local device.
Expand Down
4 changes: 2 additions & 2 deletions features/FEATURE_BLE/ble/generic/GenericGap.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class GenericGap :

/** @copydoc Gap::getMaxAdvertisingDataLength
*/
virtual uint8_t getMaxAdvertisingDataLength();
virtual uint16_t getMaxAdvertisingDataLength();

/** @copydoc Gap::createAdvertisingSet
*/
Expand Down Expand Up @@ -175,8 +175,8 @@ class GenericGap :
/** @copydoc Gap::startScan
*/
virtual ble_error_t startScan(
duplicates_filter_t filtering,
scan_duration_t duration,
duplicates_filter_t filtering,
scan_period_t period
);

Expand Down
11 changes: 9 additions & 2 deletions features/FEATURE_BLE/source/BLE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <stdio.h>
#include "ble/BLE.h"
#include "ble/BLEInstanceBase.h"
#include "platform/mbed_critical.h"

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

void BLE::processEvents()
{
core_util_critical_section_enter();
if (event_signaled == false) {
core_util_critical_section_exit();
return;
}

event_signaled = false;
core_util_critical_section_exit();

if (!transport) {
MBED_ERROR(MBED_MAKE_ERROR(MBED_MODULE_BLE, MBED_ERROR_CODE_BLE_BACKEND_NOT_INITIALIZED), "bad handle to underlying transport");
}

event_signaled = false;

transport->processEvents();
}

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

void BLE::signalEventsToProcess()
{
core_util_critical_section_enter();
if (event_signaled == true) {
core_util_critical_section_exit();
return;
}

event_signaled = true;
core_util_critical_section_exit();

if (whenEventsToProcess) {
OnEventsToProcessCallbackContext params = {
Expand Down
2 changes: 1 addition & 1 deletion features/FEATURE_BLE/source/gap/ConnectionParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ ConnectionParameters::ConnectionParameters(
conn_event_length_t maxEventLength
) :
_filterPolicy(initiator_filter_policy_t::NO_FILTER),
_ownAddressType(own_address_type_t::PUBLIC)
_ownAddressType(own_address_type_t::RANDOM)
{
for (uint8_t i = 0; i < MAX_PARAM_PHYS; ++i) {
_enabledPhy[i] = false;
Expand Down
4 changes: 2 additions & 2 deletions features/FEATURE_BLE/source/gap/Gap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ uint8_t Gap::getMaxAdvertisingSetNumber()
return 1;
}

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

ble_error_t Gap::startScan(
duplicates_filter_t filtering,
scan_duration_t duration,
duplicates_filter_t filtering,
scan_period_t period
)
{
Expand Down
32 changes: 21 additions & 11 deletions features/FEATURE_BLE/source/generic/GenericGap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,10 +675,13 @@ ble_error_t GenericGap::connect(
return BLE_ERROR_INVALID_PARAM;
}

// ensure scan is stopped.
_pal_gap.scan_enable(false, false);

return _pal_gap.create_connection(
connectionParams.getScanIntervalArray()[0],
connectionParams.getScanWindowArray()[0],
connectionParams.getFilterPolicy(),
connectionParams.getFilter(),
(pal::connection_peer_address_type_t::type) peerAddressType.value(),
peerAddress,
connectionParams.getOwnAddressType(),
Expand All @@ -691,6 +694,9 @@ ble_error_t GenericGap::connect(
);
}

// ensure scan is stopped.
_pal_gap.extended_scan_enable(false, pal::duplicates_filter_t::DISABLE, 0, 0);

// reduce the address type to public or random
peer_address_type_t adjusted_address_type(peer_address_type_t::PUBLIC);

Expand All @@ -701,7 +707,7 @@ ble_error_t GenericGap::connect(
}

return _pal_gap.extended_create_connection(
connectionParams.getFilterPolicy(),
connectionParams.getFilter(),
connectionParams.getOwnAddressType(),
adjusted_address_type,
peerAddress,
Expand Down Expand Up @@ -1442,7 +1448,7 @@ void GenericGap::processDisconnectionEvent(

if (_eventHandler) {
_eventHandler->onDisconnectionComplete(
DisconnectionEvent(
DisconnectionCompleteEvent(
handle,
(disconnection_reason_t::type) reason
)
Expand Down Expand Up @@ -1997,7 +2003,7 @@ uint8_t GenericGap::getMaxAdvertisingSetNumber()
}
}

uint8_t GenericGap::getMaxAdvertisingDataLength()
uint16_t GenericGap::getMaxAdvertisingDataLength()
{
useVersionTwoAPI();
return _pal_gap.get_maximum_advertising_data_length();
Expand Down Expand Up @@ -2053,7 +2059,7 @@ ble_error_t GenericGap::destroyAdvertisingSet(advertising_handle_t handle)
return BLE_ERROR_INVALID_PARAM;
}

if (_existing_sets.get(handle) == false) {
if (!_existing_sets.get(handle)) {
return BLE_ERROR_INVALID_PARAM;
}

Expand Down Expand Up @@ -2357,10 +2363,14 @@ ble_error_t GenericGap::stopAdvertising(advertising_handle_t handle)
return BLE_ERROR_INVALID_PARAM;
}

if (_existing_sets.get(handle)) {
if (!_existing_sets.get(handle)) {
return BLE_ERROR_INVALID_PARAM;
}

if (!_active_sets.get(handle)) {
return BLE_ERROR_INVALID_STATE;
}

ble_error_t status;

if (is_extended_advertising_available()) {
Expand Down Expand Up @@ -2427,7 +2437,7 @@ ble_error_t GenericGap::setPeriodicAdvertisingParameters(
}

if (!_existing_sets.get(handle)) {
return BLE_ERROR_INVALID_STATE;
return BLE_ERROR_INVALID_PARAM;
}

return _pal_gap.set_periodic_advertising_parameters(
Expand All @@ -2454,7 +2464,7 @@ ble_error_t GenericGap::setPeriodicAdvertisingPayload(
}

if (!_existing_sets.get(handle)) {
return BLE_ERROR_INVALID_STATE;
return BLE_ERROR_INVALID_PARAM;
}

if (payload.size() > getMaxAdvertisingDataLength()) {
Expand Down Expand Up @@ -2511,7 +2521,7 @@ ble_error_t GenericGap::startPeriodicAdvertising(advertising_handle_t handle)
}

if (!_existing_sets.get(handle)) {
return BLE_ERROR_INVALID_STATE;
return BLE_ERROR_INVALID_PARAM;
}

if (_active_sets.get(handle) == false) {
Expand Down Expand Up @@ -2544,7 +2554,7 @@ ble_error_t GenericGap::stopPeriodicAdvertising(advertising_handle_t handle)
}

if (!_existing_sets.get(handle)) {
return BLE_ERROR_INVALID_STATE;
return BLE_ERROR_INVALID_PARAM;
}

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

ble_error_t GenericGap::startScan(
duplicates_filter_t filtering,
scan_duration_t duration,
duplicates_filter_t filtering,
scan_period_t period
)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,30 +510,7 @@ void Gap::gap_handler(const wsfMsgHdr_t *msg)
handler->on_periodic_advertising_sync_loss(evt->syncHandle);
}
break;

case DM_CONN_OPEN_IND: {
if (!handler) {
break;
}

// TODO: filter with old event ...
const hciLeConnCmplEvt_t *evt = (const hciLeConnCmplEvt_t *) msg;
handler->on_enhanced_connection_complete(
hci_error_code_t(evt->status),
evt->handle,
connection_role_t(evt->role),
connection_peer_address_type_t(evt->addrType),
evt->peerAddr,
evt->localRpa,
evt->peerRpa,
evt->connInterval,
evt->connLatency,
evt->supTimeout,
clock_accuracy_t(evt->clockAccuracy)
);
}
break;


case DM_SCAN_REQ_RCVD_IND: {
if (!handler) {
break;
Expand Down