Skip to content

Commit

Permalink
Have commissioner call cleanup on error. (#13518)
Browse files Browse the repository at this point in the history
  • Loading branch information
cecille authored and pull[bot] committed Jul 19, 2023
1 parent 84356c9 commit 1382386
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
13 changes: 9 additions & 4 deletions src/controller/AutoCommissioner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,12 @@ CHIP_ERROR AutoCommissioner::SetCommissioningParameters(const CommissioningParam
return CHIP_NO_ERROR;
}

CommissioningStage AutoCommissioner::GetNextCommissioningStage(CommissioningStage currentStage)
CommissioningStage AutoCommissioner::GetNextCommissioningStage(CommissioningStage currentStage, CHIP_ERROR lastErr)
{
if (lastErr != CHIP_NO_ERROR)
{
return CommissioningStage::kCleanup;
}
switch (currentStage)
{
case CommissioningStage::kSecurePairing:
Expand Down Expand Up @@ -138,14 +142,14 @@ void AutoCommissioner::StartCommissioning(CommissioneeDeviceProxy * proxy)

void AutoCommissioner::CommissioningStepFinished(CHIP_ERROR err, CommissioningDelegate::CommissioningReport report)
{

if (report.stageCompleted == CommissioningStage::kFindOperational)
{
mOperationalDeviceProxy = report.OperationalNodeFoundData.operationalProxy;
}
CommissioningStage nextStage = GetNextCommissioningStage(report.stageCompleted);
CommissioningStage nextStage = GetNextCommissioningStage(report.stageCompleted, err);
DeviceProxy * proxy = mCommissioneeDeviceProxy;
if (nextStage == CommissioningStage::kSendComplete || nextStage == CommissioningStage::kCleanup)
if (nextStage == CommissioningStage::kSendComplete ||
(nextStage == CommissioningStage::kCleanup && mOperationalDeviceProxy != nullptr))
{
proxy = mOperationalDeviceProxy;
}
Expand All @@ -155,6 +159,7 @@ void AutoCommissioner::CommissioningStepFinished(CHIP_ERROR err, CommissioningDe
ChipLogError(Controller, "Invalid device for commissioning");
return;
}
mParams.SetCompletionStatus(err);
mCommissioner->PerformCommissioningStep(proxy, nextStage, mParams, this);
}

Expand Down
2 changes: 1 addition & 1 deletion src/controller/AutoCommissioner.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class AutoCommissioner : public CommissioningDelegate
void CommissioningStepFinished(CHIP_ERROR err, CommissioningDelegate::CommissioningReport report) override;

private:
CommissioningStage GetNextCommissioningStage(CommissioningStage currentStage);
CommissioningStage GetNextCommissioningStage(CommissioningStage currentStage, CHIP_ERROR lastErr);
DeviceCommissioner * mCommissioner;
CommissioneeDeviceProxy * mCommissioneeDeviceProxy = nullptr;
OperationalDeviceProxy * mOperationalDeviceProxy = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1875,7 +1875,7 @@ void DeviceCommissioner::PerformCommissioningStep(DeviceProxy * proxy, Commissio
ChipLogProgress(Controller, "Rendezvous cleanup");
if (mPairingDelegate != nullptr)
{
mPairingDelegate->OnCommissioningComplete(proxy->GetDeviceId(), CHIP_NO_ERROR);
mPairingDelegate->OnCommissioningComplete(proxy->GetDeviceId(), params.GetCompletionStatus());
}
mCommissioningStage = CommissioningStage::kSecurePairing;
break;
Expand Down
3 changes: 3 additions & 0 deletions src/controller/CommissioningDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,15 @@ class CommissioningParameters
mThreadOperationalDataset.SetValue(threadOperationalDataset);
return *this;
}
void SetCompletionStatus(CHIP_ERROR err) { completionStatus = err; }
CHIP_ERROR GetCompletionStatus() { return completionStatus; }

private:
Optional<ByteSpan> mCSRNonce; ///< CSR Nonce passed by the commissioner
Optional<ByteSpan> mAttestationNonce; ///< Attestation Nonce passed by the commissioner
Optional<WiFiCredentials> mWiFiCreds;
Optional<ByteSpan> mThreadOperationalDataset;
CHIP_ERROR completionStatus = CHIP_NO_ERROR;
};

class CommissioningDelegate
Expand Down

0 comments on commit 1382386

Please sign in to comment.