From a17e345dd46636d8d0f3fbc6358afbb38a197b8b Mon Sep 17 00:00:00 2001 From: Cecille Freeman Date: Thu, 3 Feb 2022 11:45:24 -0500 Subject: [PATCH] Use the recommended value to arm failsafe. --- src/controller/AutoCommissioner.cpp | 4 ++++ src/controller/CHIPDeviceController.cpp | 5 ++--- src/controller/CommissioningDelegate.h | 13 +++++++------ 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/controller/AutoCommissioner.cpp b/src/controller/AutoCommissioner.cpp index 978d6e7d02f4f5..e00284d01e9a6e 100644 --- a/src/controller/AutoCommissioner.cpp +++ b/src/controller/AutoCommissioner.cpp @@ -309,6 +309,10 @@ CHIP_ERROR AutoCommissioner::CommissioningStepFinished(CHIP_ERROR err, Commissio { case CommissioningStage::kReadCommissioningInfo: mDeviceCommissioingInfo = report.Get(); + if (!mParams.GetFailsafeTimerSeconds().HasValue() && mDeviceCommissioingInfo.general.recommendedFailsafe > 0) + { + mParams.SetFailsafeTimerSeconds(mDeviceCommissioingInfo.general.recommendedFailsafe); + } break; case CommissioningStage::kSendPAICertificateRequest: SetPAI(report.Get().certificate); diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index a9ecaa01e2f314..6f0808c413495b 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -1757,12 +1757,11 @@ void DeviceCommissioner::PerformCommissioningStep(DeviceProxy * proxy, Commissio switch (step) { case CommissioningStage::kArmFailsafe: { - ChipLogProgress(Controller, "Arming failsafe"); - // TODO: should get the endpoint information from the descriptor cluster. GeneralCommissioning::Commands::ArmFailSafe::Type request; - request.expiryLengthSeconds = params.GetFailsafeTimerSeconds(); + request.expiryLengthSeconds = params.GetFailsafeTimerSeconds().ValueOr(params.kDefaultFailsafeTimeout); request.breadcrumb = breadcrumb; request.timeoutMs = kCommandTimeoutMs; + ChipLogProgress(Controller, "Arming failsafe (%u seconds)", request.expiryLengthSeconds); SendCommand(proxy, request, OnArmFailSafe, OnBasicFailure, endpoint, timeout); } break; diff --git a/src/controller/CommissioningDelegate.h b/src/controller/CommissioningDelegate.h index 84f2432e1ea0e7..08ab56f218bf25 100644 --- a/src/controller/CommissioningDelegate.h +++ b/src/controller/CommissioningDelegate.h @@ -73,10 +73,11 @@ struct NOCerts class CommissioningParameters { public: - static constexpr size_t kMaxThreadDatasetLen = 254; - static constexpr size_t kMaxSsidLen = 32; - static constexpr size_t kMaxCredentialsLen = 64; - uint16_t GetFailsafeTimerSeconds() const { return mFailsafeTimerSeconds; } + static constexpr size_t kMaxThreadDatasetLen = 254; + static constexpr size_t kMaxSsidLen = 32; + static constexpr size_t kMaxCredentialsLen = 64; + static constexpr uint16_t kDefaultFailsafeTimeout = 60; + const Optional GetFailsafeTimerSeconds() const { return mFailsafeTimerSeconds; } const Optional GetCSRNonce() const { return mCSRNonce; } const Optional GetAttestationNonce() const { return mAttestationNonce; } const Optional GetWiFiCredentials() const { return mWiFiCreds; } @@ -98,7 +99,7 @@ class CommissioningParameters CommissioningParameters & SetFailsafeTimerSeconds(uint16_t seconds) { - mFailsafeTimerSeconds = seconds; + mFailsafeTimerSeconds.SetValue(seconds); return *this; } @@ -185,7 +186,7 @@ class CommissioningParameters void SetCompletionStatus(CHIP_ERROR err) { completionStatus = err; } private: - uint16_t mFailsafeTimerSeconds = 60; + Optional mFailsafeTimerSeconds; Optional mCSRNonce; ///< CSR Nonce passed by the commissioner Optional mAttestationNonce; ///< Attestation Nonce passed by the commissioner Optional mWiFiCreds;