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

Fix CommissioneeDeviceProxy state #13466

Merged
merged 2 commits into from
Jan 11, 2022
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
4 changes: 1 addition & 3 deletions src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -976,9 +976,7 @@ void DeviceCommissioner::OnSessionEstablished()
// TODO: the session should know which peer we are trying to connect to when started
pairing->SetPeerNodeId(mDeviceBeingCommissioned->GetDeviceId());

CHIP_ERROR err = mSystemState->SessionMgr()->NewPairing(
mDeviceBeingCommissioned->GetSecureSessionHolder(), Optional<Transport::PeerAddress>::Value(pairing->GetPeerAddress()),
pairing->GetPeerNodeId(), pairing, CryptoContext::SessionRole::kInitiator, mFabricIndex);
CHIP_ERROR err = mDeviceBeingCommissioned->SetConnected();
if (err != CHIP_NO_ERROR)
{
ChipLogError(Controller, "Failed in setting up secure channel: err %s", ErrorStr(err));
Expand Down
15 changes: 15 additions & 0 deletions src/controller/CommissioneeDeviceProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,21 @@ CHIP_ERROR CommissioneeDeviceProxy::UpdateDeviceData(const Transport::PeerAddres
return CHIP_NO_ERROR;
}

CHIP_ERROR CommissioneeDeviceProxy::SetConnected()
{
if (mState != ConnectionState::Connecting)
{
return CHIP_ERROR_INCORRECT_STATE;
}
bool _didLoad;
CHIP_ERROR err = LoadSecureSessionParametersIfNeeded(_didLoad);
if (err == CHIP_NO_ERROR)
{
mState = ConnectionState::SecureConnected;
}
return err;
}

void CommissioneeDeviceProxy::Reset()
{
SetActive(false);
Expand Down
8 changes: 8 additions & 0 deletions src/controller/CommissioneeDeviceProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,14 @@ class CommissioneeDeviceProxy : public DeviceProxy, public SessionReleaseDelegat

void SetActive(bool active) { mActive = active; }

/**
* @brief
* Called to indicate this proxy has been paired successfully.
*
* This causes the secure session parameters to be loaded and stores the session details in the session manager.
*/
CHIP_ERROR SetConnected();

bool IsSecureConnected() const override { return IsActive() && mState == ConnectionState::SecureConnected; }

bool IsSessionSetupInProgress() const { return IsActive() && mState == ConnectionState::Connecting; }
Expand Down