Skip to content

Commit

Permalink
Fix CommissioneeDeviceProxy state
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cecille committed Jan 11, 2022
1 parent 19f61eb commit f9d7657
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -975,10 +975,9 @@ void DeviceCommissioner::OnSessionEstablished()

// TODO: the session should know which peer we are trying to connect to when started
pairing->SetPeerNodeId(mDeviceBeingCommissioned->GetDeviceId());
mDeviceBeingCommissioned->SetConnected();

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
7 changes: 7 additions & 0 deletions src/controller/CommissioneeDeviceProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@ CHIP_ERROR CommissioneeDeviceProxy::UpdateDeviceData(const Transport::PeerAddres
return CHIP_NO_ERROR;
}

CHIP_ERROR CommissioneeDeviceProxy::SetConnected()
{
mState = ConnectionState::SecureConnected;
bool didLoad;
return LoadSecureSessionParametersIfNeeded(didLoad);
}

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
* Should be called when the pairing completes.
*
* 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 f9d7657

Please sign in to comment.