Skip to content

Commit

Permalink
Fix CommissioneeDeviceProxy state (project-chip#13466)
Browse files Browse the repository at this point in the history
* Fix CommissioneeDeviceProxy state

The pairing call was moved to external so the commissionee
device proxy never gets set to connected. LoadSecureSessionParameters
will take care of setting up the pairing in the session manager
so added a new function that gets called when the pairing is complete
to set the state and setup the pairing in the session manager.

* Address review comments.
  • Loading branch information
cecille authored and selissia committed Jan 28, 2022
1 parent b649116 commit 5ec6074
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
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

0 comments on commit 5ec6074

Please sign in to comment.