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

Enable pairing for multiple devices #3630

Merged
merged 26 commits into from
Nov 11, 2020

Conversation

pan-apple
Copy link
Contributor

Problem

CHIP Controller API doesn't support pairing of multiple devices. The controller class stores information of one paired device.

Summary of Changes

  • Refactor Controller API to squeeze out device specific information to CHIPDevice class.
  • Split the API into Controller and Commissioner interfaces
  • Rewrite old controller class using new APIs, to keep backward compatibility for time being (until all controller apps move to the new interface).

Fixes #2795

@pan-apple
Copy link
Contributor Author

rebased

@pan-apple
Copy link
Contributor Author

rebased

@boring-cyborg boring-cyborg bot added the lib label Nov 9, 2020
src/controller/CHIPDevice.cpp Outdated Show resolved Hide resolved
src/controller/CHIPDevice.cpp Outdated Show resolved Hide resolved
src/controller/CHIPDevice.h Outdated Show resolved Hide resolved
src/controller/CHIPDevice.h Outdated Show resolved Hide resolved
src/controller/CHIPDevice.h Outdated Show resolved Hide resolved
src/controller/CHIPDeviceController.cpp Show resolved Hide resolved
src/controller/CHIPDeviceController.cpp Outdated Show resolved Hide resolved
src/controller/CHIPDeviceController.cpp Outdated Show resolved Hide resolved
src/controller/CHIPDeviceController.cpp Outdated Show resolved Hide resolved
@pan-apple pan-apple requested a review from andy31415 November 9, 2020 19:46
examples/chip-tool/commands/common/Commands.h Show resolved Hide resolved
src/controller/CHIPDevice.cpp Show resolved Hide resolved
src/controller/CHIPDevice.h Outdated Show resolved Hide resolved
src/controller/CHIPDevice.h Outdated Show resolved Hide resolved
src/controller/CHIPDevice.h Show resolved Hide resolved
src/transport/SecurePairingSession.cpp Outdated Show resolved Hide resolved
src/transport/SecurePairingSession.h Outdated Show resolved Hide resolved
src/transport/SecurePairingSession.h Outdated Show resolved Hide resolved
src/controller/CHIPPersistentStorageDelegate.h Outdated Show resolved Hide resolved
src/controller/CHIPPersistentStorageDelegate.h Outdated Show resolved Hide resolved
* @brief
* Set the delegate object which will be called when a message is received.
* The user of this Device object must reset the delegate (by calling
* SetDelegate(nullptr)) before releasing their delegate object.
Copy link
Contributor

Choose a reason for hiding this comment

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

This implies they control the lifetime of the Device somehow, right? That is, that the device can't go away on them?

Please file a followup to either document ownership here better or add more callbacks to allow a variety of ownership models to be implemented.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Issue: #3763

* interface etc) are part of the serialized device, so those are not required to be
* initialized.
*
* Note: The lifetime of session manager, and inet layer objects must be longer than
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Note: The lifetime of session manager, and inet layer objects must be longer than
* Note: The lifetime of session manager and inet layer objects must be longer than


/**
* @brief
* Return if the current device object is actively associated with a paired CHIP
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Return if the current device object is actively associated with a paired CHIP
* Return whether the current device object is actively associated with a paired CHIP

/* IP Address of the CHIP device */
Inet::IPAddress mDeviceAddr;

/* Port on which the CHIP device is receiving message. Typically it is CHIP_PORT */
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/* Port on which the CHIP device is receiving message. Typically it is CHIP_PORT */
/* Port on which the CHIP device is receiving messages. Typically it is CHIP_PORT */

Comment on lines +106 to +119
serializable.mDeviceId = Encoding::LittleEndian::HostSwap64(mDeviceId);
serializable.mDevicePort = Encoding::LittleEndian::HostSwap16(mDevicePort);
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, separate PR is fine, but we should make sure it happens....

src/controller/CHIPDevice.cpp Show resolved Hide resolved
VerifyOrExit(deserializedLen > 0, error = CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrExit(deserializedLen <= sizeof(serializable), error = CHIP_ERROR_INVALID_ARGUMENT);

// The second paramter to FromString takes the strlen value. We are subtracting 1
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// The second paramter to FromString takes the strlen value. We are subtracting 1
// The second parameter to FromString takes the strlen value. We are subtracting 1

Comment on lines +380 to +383
mPairingDelegate = nullptr;
mRendezvousSession = nullptr;
mDeviceBeingPaired = kNumMaxActiveDevices;
mPairedDevicesUpdated = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

I vaguely do, but it's not that big a deal.

{
mOnComplete.Response(this, mAppReqState, msgBuf);
// Let's release the device that's being paired.
// If pairing was successful, it's information is
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// If pairing was successful, it's information is
// If pairing was successful, its information is

mOnNewConnection(this, nullptr, mAppReqState);
}
ChipLogDetail(Controller, "Remote device completed SPAKE2+ handshake\n");
mRendezvousSession->GetPairingSession().Serializable(device->GetPairing());
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, ToSerializable would be better.

public PersistentStorageResultDelegate
/**
* @brief
* The controller applications can use this class to commuicate with already paired CHIP devices. The
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* The controller applications can use this class to commuicate with already paired CHIP devices. The
* Controller applications can use this class to communicate with already paired CHIP devices. The

/**
* @brief
* Connect to a CHIP device with the provided Rendezvous connection parameters
* This function derserializes the provided deviceInfo object, and initialzes and output the
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* This function derserializes the provided deviceInfo object, and initialzes and output the
* This function deserializes the provided deviceInfo object, and initializes and outputs the

* Connect to a CHIP device with the provided Rendezvous connection parameters
* This function derserializes the provided deviceInfo object, and initialzes and output the
* corresponding Device object. The lifetime of the output object is tied to that of DeviceController
* object. The caller must not use the Device object If they free the DeviceController object.
Copy link
Contributor

Choose a reason for hiding this comment

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

Or after calling ReleaseDevice in the returned Device?


State mState;

/* A list of device objects that can be used for commincating with corresponding
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/* A list of device objects that can be used for commincating with corresponding
/* A list of device objects that can be used for communicating with corresponding

State mState;

/* A list of device objects that can be used for commincating with corresponding
CHIP device. The list does not contain all the paired devices, but only the ones
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
CHIP device. The list does not contain all the paired devices, but only the ones
CHIP devices. The list does not contain all the paired devices, but only the ones

void ClearRequestState();
void ClearOpState();
/* This field is an index in mActiveDevices list. The object at this index in the list
contains the device object that's tracking the state of the device that's being paired */
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
contains the device object that's tracking the state of the device that's being paired */
contains the device object that's tracking the state of the device that's being paired.
If no device is currently being paired, this value will be kNumMaxPairedDevices. */

Right?

return error;
}

CHIP_ERROR SecurePairingSession::Serializable(SecurePairingSessionSerializable & serializable)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer ToSerializable, yes.

@github-actions
Copy link

Size increase report for "nrfconnect-example-build" from 81f0566

File Section File VM
chip-lighting.elf text 72 72
chip-lighting.elf rodata 64 64
chip-lighting.elf shell_root_cmds_sections 8 8
chip-lock.elf text 76 76
chip-lock.elf rodata 72 68
chip-lock.elf shell_root_cmds_sections 4 4
Full report output
BLOAT REPORT

Files found only in the build output:
    report.csv

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

sections,vmsize,filesize
.debug_loc,0,324
.debug_line,0,229
.debug_str,0,188
.debug_info,0,126
.debug_frame,0,80
text,72,72
rodata,64,64
.debug_aranges,0,32
.symtab,0,32
shell_root_cmds_sections,8,8
.shstrtab,0,1
.strtab,0,-21
.debug_ranges,0,-32
.debug_abbrev,0,-43

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

sections,vmsize,filesize
.debug_loc,0,316
.debug_line,0,229
.debug_str,0,188
.debug_info,0,126
.debug_frame,0,80
text,76,76
rodata,68,72
.debug_aranges,0,32
.symtab,0,32
shell_root_cmds_sections,4,4
.shstrtab,0,1
.strtab,0,-21
.debug_ranges,0,-32
.debug_abbrev,0,-43

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

sections,vmsize,filesize


@github-actions
Copy link

Size increase report for "esp32-example-build" from 81f0566

File Section File VM
chip-all-clusters-app.elf .flash.text 96 96
chip-all-clusters-app.elf .flash.rodata 64 64
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_line,0,446
.debug_str,0,187
.flash.text,96,96
.debug_ranges,0,88
.xt.lit._ZN4chip28SecurePairingUsingTestSecretD5Ev,0,80
.xt.prop._ZN4chip9Transport4Base5CloseEv,0,76
.debug_frame,0,72
.flash.rodata,64,64
.debug_loc,0,52
.debug_aranges,0,24
.xt.prop._ZN4chip8Encoding12LittleEndian7Write32ERPhj,0,-1
.strtab,0,-22
[Unmapped],0,-64
.debug_abbrev,0,-72
.xt.prop._ZN4chip28SecurePairingUsingTestSecret19DeriveSecureSessionEPKhjRNS_13SecureSessionE,0,-88
.xt.lit._ZN4chip28SecurePairingUsingTestSecret19DeriveSecureSessionEPKhjRNS_13SecureSessionE,0,-128
.shstrtab,0,-146
.debug_info,0,-1140


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.

Device Controller changes to support multiple device pairings
6 participants