Skip to content

Ble extended advertising #8738

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 361 commits into from
Nov 28, 2018
Merged

Ble extended advertising #8738

merged 361 commits into from
Nov 28, 2018

Conversation

pan-
Copy link
Member

@pan- pan- commented Nov 14, 2018

Description

This PR introduce extended and periodic advertising management in mbed-os BLE API. These two features have been introduced in Bluetooth 5 and greatly improve advertisement capabilities of compatible devices.

Extended Advertising

With extended advertising, devices are not limited to a single payload advertised and a single scan response. Devices can manage multiple concurrent advertisement data called advertising sets as they contain their own data and operate according to their own parameters.

Other noticeable improvement of extended advertising are:

  • Advertising on Coded PHY for long range advertisement on the main channel. All phys are available to the secondary channel.
  • Increased payload size: from 31 byte to 251 in a single packet and up to 1560 byte when fragmentation is used.
  • Control of TX power.

Periodic Advertising

Periodic advertising is a new kind of advertising that allows a device to stream data at a fixed rate. Peers can sync on the data stream and listen to it. Internally it is very similar to a unidirectional connection.

Integration

On many aspects it wasn't possible to add this new feature on the top of the previous GAP advertisement API. Defects such as (incorrect) global address type, global filter policies, state bookkeeping and global scanning/advertisement parameters mutable in a non atomic way would have make it memory heavy and not very usable as it would have been full of corner cases (it already is!) due to the global state held in it if we wanted to preserve backward compatibility.

The new API introduced is basically a version two of the GAP Advertisement/Scanning/Connection API. It is not compatible with the old subsystem. You have to use one or the other but it is forbidden to use both concurrently. That way we preserve complete backward compatibility and prepare a clean ground to build upcoming Bluetooth features.

TODO

  • Review
  • Add deprecated notices where relevant
  • Improve documentation
  • Move deprecated code around (nice to have)

Pull request type

[ ] Fix
[ ] Refactor
[ ] Target update
[X] Functionality change
[ ] Docs update
[ ] Test update
[ ] Breaking change

}

if (is_extended_advertising_available()) {
return _pal_gap.extended_scan_enable(
Copy link
Member

@paul-szczepanek-arm paul-szczepanek-arm Nov 14, 2018

Choose a reason for hiding this comment

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

we allow the user to set scanning parameters that are then ignored

for example the user may set coded phy scanning but because it is not supported this will run a normal scan but return success

we can't reject it in the settings either because we use chaining in the sets that are incapable of returning error codes

this needs to check the settings and report an error if any of the extended scan params have been set

Copy link
Member Author

@pan- pan- Nov 14, 2018

Choose a reason for hiding this comment

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

Parameters are rejected on legacy controllers if they include phy parameters:

https://github.com/ARMmbed/mbed-os/blob/3a2fb280f07770d6f5fa17f0465c716203665d22/features/FEATURE_BLE/source/generic/GenericGap.cpp#L2383-L2385

However we need to check scan and connection parameter; please do not resolve the conversation.

Copy link
Contributor

@donatieng donatieng left a comment

Choose a reason for hiding this comment

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

Haven't looked at the PAL yet but the API looks great. really good work there. Some notes/questions.

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 15, 2018

@pan- All comments addressed? And ready for another round of review (helps reviewers if you add a comment after rebase/adding more commits - "whats new").

@cmonr cmonr dismissed donatieng’s stale review November 15, 2018 18:11

Comments addressed.

@cmonr
Copy link
Contributor

cmonr commented Nov 15, 2018

@donatieng Mind re-reviewing? Looks like your comments were addressed.

@cmonr
Copy link
Contributor

cmonr commented Nov 15, 2018

And @paul-szczepanek-arm, although it seems like you're involved in the PR itself 😄

@pan-
Copy link
Member Author

pan- commented Nov 15, 2018

@cmonr That's a collective effort 😉 .

Copy link
Member Author

@pan- pan- left a comment

Choose a reason for hiding this comment

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

AdvDataBuilder review:

It would be good if we add new helpers functions:

setFlags(adv_flags_t);
setName(const char*, bool complete);
setTxPowerLevel(int8_t);
setAppearance(adv_appearance_t);
setManufacturerSpecificData(Span<const uint8_t>);
setLocalServiceList(Span<const UUID>, bool complete);
setConnectionIntervalPreference(conn_interval_t min, conn_interval_t max);
setServiceData(UUID serviceUUID, Span<const uint8_t> serviceData);
setAdvertisingInterval(adv_interval_t); // note: serialized to a uint16_t!
setRequestedServices(Span<const UUID>); 

@paul-szczepanek-arm
Copy link
Member

what's new

AdvertisingDataBuilder updated with helper functions (but not complete, will post when done)

@NirSonnenschein
Copy link
Contributor

@pan- : this needs a rebase

Copy link
Contributor

@donatieng donatieng left a comment

Choose a reason for hiding this comment

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

A few more notes, thanks for addressing my comments so far

* @note The maximum size of data depends on the controller and its support for
* extended advertising however even if the controller supports larger data lengths if
* you wish to be compatible with older devices you may wish to use legacy
* advertising and should not use payloads larger than LEGACY_ADVERTISING_MAX_SIZE.
*
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be worth mentioning that this feature was introduced in Bluetooth 5 and that 5 support from the controller's standpoint is necessary but not sufficient.

Copy link
Member Author

Choose a reason for hiding this comment

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

@donatieng I thin I addressed your comment.

* Subsequently you may disable extended advertising and the periodic advertising
* will continue. If you start periodic advertising while extended advertising is
* inactive, periodic advertising will not start until you start extended advertising
* at a later time.
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be worth adding a quick word on why that's required (background from spec)

Copy link
Member Author

Choose a reason for hiding this comment

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

@donatieng I thin I addressed your comment.

Copy link
Member

@bulislaw bulislaw left a comment

Choose a reason for hiding this comment

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

The "not mixing" new and old APIs sounds reasonable to me. Someone else needs to review the code.

@paul-szczepanek-arm
Copy link
Member

paul-szczepanek-arm commented Nov 20, 2018

gap/ConnectionParameters.h fixed (as in needs re-review)

@cmonr
Copy link
Contributor

cmonr commented Nov 21, 2018

Me thinks this needs a rebase.

@pan- pan- force-pushed the ble-extended-advertising branch from 2107d69 to 524b9a7 Compare November 22, 2018 10:31
@0xc0170
Copy link
Contributor

0xc0170 commented Nov 22, 2018

@ARMmbed/mbed-os-pan When is this completed ?

It still needs work and review

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 22, 2018

While we are reviewing, I'll run this through CI

@mbed-ci
Copy link

mbed-ci commented Nov 23, 2018

Test run: SUCCESS

Summary: 4 of 4 test jobs passed
Build number : 5
Build artifacts
Build logs

Amanda Butler added 3 commits November 26, 2018 19:15
Edit file for active voice and comma use.
Edit file, mostly to fix typos.
Edit file.
Copy link
Contributor

@AnotherButler AnotherButler left a comment

Choose a reason for hiding this comment

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

I left a few queries and requests for changes.

/**
* Construct a Duration from an integer value.
*
* @param v The value of the duration in TN units.
Copy link
Contributor

Choose a reason for hiding this comment

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

Query: What are TN units?

Copy link
Member Author

Choose a reason for hiding this comment

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

That is a typo, it should be TB or TIME_BASE.

/**
* Construct a Duration from another Duration.
*
* @note The operation fail at compile time of there is a loss of precision.
Copy link
Contributor

Choose a reason for hiding this comment

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

Query: What does this mean? The operation fails at compile time if there's a loss of precision? Or something else?

Copy link
Member Author

Choose a reason for hiding this comment

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

Type: of -> if

}

/**
* Return the duration in milliseconds.
Copy link
Contributor

Choose a reason for hiding this comment

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

Global note throughout the file: Sometimes we use "milliseconds", and sometimes we abbreviate. Please standardize.

};

/**
* Type that represents micro seconds.
Copy link
Contributor

Choose a reason for hiding this comment

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

Global note throughout the file: Sometimes we use "us", and sometimes we spell it out. Please standardize. (Please do not include a space in "microseconds" if we choose to spell it out.)

* @tparam RangeIn The range of duration.
* @tparam FIn The Forever value of duration.
* @param duration The duration to convert.
* @return The converted duration. It is rounded up if precision is loss.
Copy link
Contributor

Choose a reason for hiding this comment

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

Query: Should this be "... if precision is lost."?

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 .

UNKNOWN = 0,

/**
* Generic Phone.
Copy link
Contributor

Choose a reason for hiding this comment

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

Most of these descriptions repeat the name. Is there a way to provide more information?

Copy link
Member Author

Choose a reason for hiding this comment

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

The specification doesn't offer more precision for these values. We document the entities to make sure they get rendered in Doxygen but the name is already self descriptive.

@cmonr
Copy link
Contributor

cmonr commented Nov 27, 2018

CI started!

@AnotherButler
Copy link
Contributor

I can deal with my queries being addressed in a patch release, but please be sure they are addressed. I don't want them to fall through the cracks.

@cmonr cmonr added risk: G and removed risk: A labels Nov 27, 2018
@cmonr
Copy link
Contributor

cmonr commented Nov 27, 2018

@ARMmbed/mbed-os-maintainers Please be sure that @AnotherButler comments get ack'd in some way before merging this PR.

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 27, 2018

@ARMmbed/mbed-os-maintainers Please be sure that @AnotherButler comments get ack'd in some way before merging this PR.

The new PR would be the best to address them (as this is already in the CI).

@mbed-ci
Copy link

mbed-ci commented Nov 27, 2018

Test run: SUCCESS

Summary: 4 of 4 test jobs passed
Build number : 8
Build artifacts
Build logs

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 27, 2018

Exporters failed (the rest of CI pipeline looks good), investigating

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 27, 2018

Restarted exporter (IAR failed due to multiple writes to a file, will be investigated).

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 27, 2018

Reviewed again, found the issue , two Gap.cpp files (IAR can't handle files if you run with compile multiple files - I experienced this before).

@pan-
Copy link
Member Author

pan- commented Nov 27, 2018

@0xc0170 I pushed a fix.

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 27, 2018

New Ci job started

@mbed-ci
Copy link

mbed-ci commented Nov 27, 2018

Test run: SUCCESS

Summary: 4 of 4 test jobs passed
Build number : 9
Build artifacts
Build logs

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 27, 2018

Only exporters failed,

There's colorama import failure @OPpuolitaival Please review this job

12:04:21 [WIZWIKI_W7500:iar] + aws s3 cp xxxx/xxx.log s3://xx-os-ci/xxxx-ci/xxxx/8738/9/iar/PASS/WIZWIKI_W7500/exporter_build_log_WIZWIKI_W7500_iar.log
12:04:21 [WIZWIKI_W7500:iar] Traceback (most recent call last):
12:04:21 [WIZWIKI_W7500:iar]   File "C:/mbed_tools/Python27/Scripts/aws", line 19, in <module>
12:04:21 [WIZWIKI_W7500:iar]     import awscli.clidriver
12:04:21 [WIZWIKI_W7500:iar]   File "C:\mbed_tools\python27\lib\site-packages\awscli\clidriver.py", line 27, in <module>
12:04:21 [WIZWIKI_W7500:iar]     from awscli.formatter import get_formatter
12:04:21 [WIZWIKI_W7500:iar]   File "C:\mbed_tools\python27\lib\site-packages\awscli\formatter.py", line 20, in <module>
12:04:21 [WIZWIKI_W7500:iar]     from awscli.table import MultiTable, Styler, ColorizedStyler
12:04:21 [WIZWIKI_W7500:iar]   File "C:\mbed_tools\python27\lib\site-packages\awscli\table.py", line 18, in <module>
12:04:21 [WIZWIKI_W7500:iar]     import colorama
12:04:21 [WIZWIKI_W7500:iar] ImportError: No module named colorama

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 27, 2018

Exporters restarted

@OPpuolitaival
Copy link
Contributor

@0xc0170 that is CI internal problem, not related to this change

@cmonr cmonr added risk: A and removed risk: G labels Nov 27, 2018
@cmonr
Copy link
Contributor

cmonr commented Nov 28, 2018

Restarting exporter CI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.