diff --git a/src/controller/AutoCommissioner.cpp b/src/controller/AutoCommissioner.cpp index c5cab14f32868c..78daa9e8218966 100644 --- a/src/controller/AutoCommissioner.cpp +++ b/src/controller/AutoCommissioner.cpp @@ -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: @@ -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; } @@ -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); } diff --git a/src/controller/AutoCommissioner.h b/src/controller/AutoCommissioner.h index 5b65674709a150..18f751dfe2f935 100644 --- a/src/controller/AutoCommissioner.h +++ b/src/controller/AutoCommissioner.h @@ -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; diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index f660a40bd73ee9..792df14307744c 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -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; diff --git a/src/controller/CommissioningDelegate.h b/src/controller/CommissioningDelegate.h index 3a48eded46068b..86133b9782e248 100644 --- a/src/controller/CommissioningDelegate.h +++ b/src/controller/CommissioningDelegate.h @@ -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 mCSRNonce; ///< CSR Nonce passed by the commissioner Optional mAttestationNonce; ///< Attestation Nonce passed by the commissioner Optional mWiFiCreds; Optional mThreadOperationalDataset; + CHIP_ERROR completionStatus = CHIP_NO_ERROR; }; class CommissioningDelegate