Skip to content
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

Add support for commisionable advertisement #4337

Merged

Conversation

arunbharadwaj
Copy link
Contributor

Problem

We need support for "commisionable" discovery advertisement according to Discovery spec for CHIP

Summary of Changes

This adds support for "commisionable" discovery advertisement.

This builds on top of PR #4200 which adds "commisioning" and "operational" discovery advertisements
This adds the Advertise() function in lib/mdns/Advertiser_ImplMinimalMdns.cpp to advertise service as _chipd._udp while running in commisionable mode.
This also adds the class CommisionableAdvertisingParameters which additionally contains pairingInstr and pairingHint
Finally, this adds some test code in the example/minimal-mdns/advertiser.cpp to test this mode.

Copy link
Contributor

@chrisdecenzo chrisdecenzo left a comment

Choose a reason for hiding this comment

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

please make the enablement/disablement of this feature driven by a member variable whose default value can be changed by the device/application using the SDK.

@andy31415
Copy link
Contributor

andy31415 commented Jan 13, 2021

please make the enablement/disablement of this feature driven by a member variable whose default value can be changed by the device/application using the SDK.

@chrisdecenzo - could you elaborate a bit? This is chip spec requirement (we have commisioning, commisionable and operational advertisement) and generally moving into each mode is app/library controlled.

What is the concern? I believe currently this is enabled by a 'has mdns' flag which is designed to be used for on/off on thread devices (which may use other dns-sd methods than mdns to save battery). Are there additional flags required?

uint8_t shortDiscriminator = 52;
uint16_t longDiscriminator = 840;
Optional<uint16_t> vendorId;
Optional<uint16_t> productId;
Optional<const char *> pairingInstr;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this required for commisionable as well? if not, I think we should add a comment that these 2 are for commisionable only.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only required for commisionable. Will add a comment.

@@ -61,6 +64,8 @@ constexpr uint16_t kOptionCommisioningShordDiscriminator = 's';
constexpr uint16_t kOptionCommisioningLongDiscriminaotr = 'l';
constexpr uint16_t kOptionCommisioningVendorId = 0x100; // v is used by 'version'
constexpr uint16_t kOptionCommisioningProductId = 'p';
constexpr uint16_t kOptionCommisioningPairingInstr = 'I';
constexpr uint16_t kOptionCommisioningPairingHint = 'H';
Copy link
Contributor

Choose a reason for hiding this comment

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

using uppercase seems a bit different than existing flags. I imagine 'H' is to not conflict with 'h'. I would either then update vendorId to use 'V' (and maybe make all others uppercase too) or make the conflicting ones only have a long version like '--pairing-hint'.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think sticking to the long version for conflicting ones is more readable. Will do that.

@@ -81,6 +86,10 @@ bool HandleOptions(const char * aProgram, OptionSet * aOptions, int aIdentifier,
{
gOptions.advertisingMode = AdvertisingMode::kCommisioning;
}
else if ((strcmp(aValue, "commisionable") == 0) || (strcmp(aValue, "d") == 0))
Copy link
Contributor

Choose a reason for hiding this comment

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

the 'd' is awkward. Please remove 'c' from above instead since 'c' seems ambigous for commisiong/commisionable

Copy link
Contributor Author

@arunbharadwaj arunbharadwaj Jan 13, 2021

Choose a reason for hiding this comment

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

I used 'd' because for commisionable we advertise as _chipd while for commisioning we advertise as _chipc and hence 'c' was used.

char txtPairingInstrHint[128];
if (params.GetPairingHint().HasValue())
{
// sprintf(txtPairingInstrHint, "P=%d", params.GetPairingHint().Value());
Copy link
Contributor

Choose a reason for hiding this comment

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

remove commented out code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do

if (params.GetPairingHint().HasValue())
{
// sprintf(txtPairingInstrHint, "P=%d", params.GetPairingHint().Value());
sprintf(txtPairingInstrHint, "P=%s+%d", params.GetPairingInstr().Value(), params.GetPairingHint().Value());
Copy link
Contributor

Choose a reason for hiding this comment

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

Need to ensure that GetPairingInstr() HasValue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do

@chrisdecenzo
Copy link
Contributor

please make the enablement/disablement of this feature driven by a member variable whose default value can be changed by the device/application using the SDK.

@chrisdecenzo - could you elaborate a bit? This is chip spec requirement (we have commisioning, commisionable and operational advertisement) and generally moving into each mode is app/library controlled.

What is the concern? I believe currently this is enabled by a 'has mdns' flag which is designed to be used for on/off on thread devices (which may use other dns-sd methods than mdns to save battery). Are there additional flags required?

This is an optional feature. Some devices will want to turn it off.

@arunbharadwaj
Copy link
Contributor Author

please make the enablement/disablement of this feature driven by a member variable whose default value can be changed by the device/application using the SDK.

Addressed this in the follow-up patch

arunbharadwaj and others added 2 commits January 13, 2021 14:50

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@github-actions
Copy link

Size increase report for "esp32-example-build" from 872015b

File Section File VM
chip-all-clusters-app.elf .flash.text 1092 1092
chip-all-clusters-app.elf .flash.rodata 72 72
Full report output
BLOAT REPORT

Files found only in the build output:
    report.csv

Comparing ./master_artifact/chip-all-clusters-app.elf and ./pull_artifact/chip-all-clusters-app.elf:

sections,vmsize,filesize
.debug_info,0,11600
.debug_str,0,3338
.debug_line,0,3011
.debug_loc,0,1893
.strtab,0,1382
.flash.text,1092,1092
.debug_ranges,0,600
.symtab,0,176
.debug_frame,0,168
.flash.rodata,72,72
.debug_aranges,0,56
.debug_abbrev,0,7
.shstrtab,0,2
.xt.prop._ZTVN4chip11DeviceLayer37DeviceNetworkProvisioningDelegateImplE,0,-1
[Unmapped],0,-72


@github-actions
Copy link

Size increase report for "nrfconnect-example-build" from 872015b

File Section File VM
chip-lighting.elf text 1008 1008
chip-lighting.elf rodata 72 72
chip-lock.elf text 1008 1008
chip-lock.elf rodata 72 76
Full report output
BLOAT REPORT

Files found only in the build output:
    report.csv

Comparing ./master_artifact/chip-shell.elf and ./pull_artifact/chip-shell.elf:

sections,vmsize,filesize

Comparing ./master_artifact/chip-lighting.elf and ./pull_artifact/chip-lighting.elf:

sections,vmsize,filesize
.debug_info,0,8302
.debug_str,0,3338
.debug_loc,0,2486
.debug_line,0,1572
.strtab,0,1159
text,1008,1008
.debug_ranges,0,464
.symtab,0,400
.debug_frame,0,200
rodata,72,72
.debug_aranges,0,48
.shstrtab,0,1
.debug_abbrev,0,-2

Comparing ./master_artifact/chip-lock.elf and ./pull_artifact/chip-lock.elf:

sections,vmsize,filesize
.debug_info,0,8302
.debug_str,0,3338
.debug_loc,0,2486
.debug_line,0,1572
.strtab,0,1159
text,1008,1008
.debug_ranges,0,464
.symtab,0,400
.debug_frame,0,200
rodata,76,72
.debug_aranges,0,48
.shstrtab,0,1
.debug_abbrev,0,-2


@andy31415

This comment has been minimized.

@@ -33,19 +33,28 @@ enum class AdvertisingMode
{
kCommisioning,
kOperational,
#if CHIP_ENABLE_COMMISIONABLE_DISCOVERY
Copy link
Contributor

Choose a reason for hiding this comment

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

No need for an ifdef in example code. Please remove - this conditional occurs in too many places of the code.

src/platform/BUILD.gn Outdated Show resolved Hide resolved
Copy link
Contributor

@chrisdecenzo chrisdecenzo left a comment

Choose a reason for hiding this comment

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

after discussion with Andrei, we agreed not to incur the complexity overhead of a compile-time flag for this feature, thanks

@@ -129,6 +183,9 @@ class ServiceAdvertiser
/// Advertises the CHIP node as a commisioning node
virtual CHIP_ERROR Advertise(const CommisioningAdvertisingParameters & params) = 0;

/// Advertises the CHIP node as a commisionable node
virtual CHIP_ERROR Advertise(const CommisionableAdvertisingParameters & params) = 0;

Copy link
Contributor

Choose a reason for hiding this comment

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

is there a method to stop this advertisement?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not currently - we assume that 'once a chip device, always a chip device and we advertise'. Having a 'StopAdvertising' seems possible though.

arunbharadwaj and others added 2 commits January 14, 2021 08:58
After discussions with the group, it was decided that we don't need
a compile time option to enable/disable the commisionable mode, but
instead have some kind of a stop advertising command to do this.
Copy link
Contributor

@chrisdecenzo chrisdecenzo left a comment

Choose a reason for hiding this comment

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

approving changes. Arun will create a separate issue for disabling commissionable discovery

@chrisdecenzo chrisdecenzo merged commit be3279a into project-chip:master Jan 14, 2021
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.

None yet

5 participants