From db130aca5f569307b672e5349ea8ce74179b3e4a Mon Sep 17 00:00:00 2001 From: James Swan <122404367+swan-amazon@users.noreply.github.com> Date: Sat, 17 Aug 2024 00:10:35 +0000 Subject: [PATCH] Terms and Conditions kTCAcknowledgementsNotReceived fix --- .../general-commissioning-server.cpp | 9 +++++++++ src/app/server/DefaultEnhancedSetupFlowProvider.cpp | 7 +++++++ src/app/server/DefaultEnhancedSetupFlowProvider.h | 2 ++ src/app/server/DefaultTermsAndConditionsProvider.cpp | 8 ++++++++ src/app/server/DefaultTermsAndConditionsProvider.h | 2 ++ src/app/server/EnhancedSetupFlowProvider.h | 2 ++ src/app/server/TermsAndConditionsProvider.h | 7 +++++++ src/controller/CommissioningDelegate.h | 4 ++-- 8 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/app/clusters/general-commissioning-server/general-commissioning-server.cpp b/src/app/clusters/general-commissioning-server/general-commissioning-server.cpp index 16b62f1fab9207..6c1465873de433 100644 --- a/src/app/clusters/general-commissioning-server/general-commissioning-server.cpp +++ b/src/app/clusters/general-commissioning-server/general-commissioning-server.cpp @@ -200,9 +200,18 @@ CHIP_ERROR checkTermsAndConditionsAcknowledgementsState(CommissioningErrorEnum & CHIP_ERROR err; uint16_t termsAndConditionsAcceptedAcknowledgements; + bool hasAnyAcknowledgements; bool hasRequiredTermAccepted; bool hasRequiredTermVersionAccepted; + err = enhancedSetupFlowProvider->HasReceivedTermsAndConditionscknowledgements(hasAnyAcknowledgements); + if (!::chip::ChipError::IsSuccess(err)) + { + ChipLogError(AppServer, "Failed to HasReceivedTermsAndConditionscknowledgements"); + errorCode = CommissioningErrorEnum::kTCAcknowledgementsNotReceived; + return err; + } + err = enhancedSetupFlowProvider->GetTermsAndConditionsAcceptedAcknowledgements(termsAndConditionsAcceptedAcknowledgements); if (!::chip::ChipError::IsSuccess(err)) { diff --git a/src/app/server/DefaultEnhancedSetupFlowProvider.cpp b/src/app/server/DefaultEnhancedSetupFlowProvider.cpp index 1ce01c398f1a04..9bcd0e4dc1acbc 100644 --- a/src/app/server/DefaultEnhancedSetupFlowProvider.cpp +++ b/src/app/server/DefaultEnhancedSetupFlowProvider.cpp @@ -30,6 +30,13 @@ CHIP_ERROR chip::app::DefaultEnhancedSetupFlowProvider::Init(TermsAndConditionsP return CHIP_NO_ERROR; } +CHIP_ERROR chip::app::DefaultEnhancedSetupFlowProvider::HasReceivedTermsAndConditionscknowledgements(bool & outReceived) const +{ + VerifyOrReturnError(nullptr != mTermsAndConditionsProvider, CHIP_ERROR_UNINITIALIZED); + ReturnErrorOnFailure(mTermsAndConditionsProvider->HasAcceptance(outReceived)); + return CHIP_NO_ERROR; +} + CHIP_ERROR chip::app::DefaultEnhancedSetupFlowProvider::HasTermsAndConditionsRequiredAcknowledgementsBeenAccepted(bool & outAccepted) const { diff --git a/src/app/server/DefaultEnhancedSetupFlowProvider.h b/src/app/server/DefaultEnhancedSetupFlowProvider.h index 3da5266078f15e..01a04269723b79 100644 --- a/src/app/server/DefaultEnhancedSetupFlowProvider.h +++ b/src/app/server/DefaultEnhancedSetupFlowProvider.h @@ -39,6 +39,8 @@ class DefaultEnhancedSetupFlowProvider : public EnhancedSetupFlowProvider */ CHIP_ERROR Init(TermsAndConditionsProvider * const inTermsAndConditionsProvider); + CHIP_ERROR HasReceivedTermsAndConditionscknowledgements(bool & outReceived) const override; + CHIP_ERROR HasTermsAndConditionsRequiredAcknowledgementsBeenAccepted(bool & outAccepted) const override; CHIP_ERROR HasTermsAndConditionsRequiredAcknowledgementsVersionBeenAccepted(bool & outAccepted) const override; diff --git a/src/app/server/DefaultTermsAndConditionsProvider.cpp b/src/app/server/DefaultTermsAndConditionsProvider.cpp index 0d49f41c893ff9..b32a507b3c52fa 100644 --- a/src/app/server/DefaultTermsAndConditionsProvider.cpp +++ b/src/app/server/DefaultTermsAndConditionsProvider.cpp @@ -115,6 +115,14 @@ CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::GetRequirements(uint16_ return CHIP_NO_ERROR; } +CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::HasAcceptance(bool & outHasAcceptance) const +{ + outHasAcceptance = + mTemporaryAcknowledgementsAcceptanceValue.HasValue() && mTemporaryAcknowledgementsAcceptanceVersionValue.HasValue(); + + return CHIP_NO_ERROR; +} + CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::ResetAcceptance() { VerifyOrReturnError(nullptr != mPersistentStorageDelegate, CHIP_ERROR_UNINITIALIZED); diff --git a/src/app/server/DefaultTermsAndConditionsProvider.h b/src/app/server/DefaultTermsAndConditionsProvider.h index ee941216757976..c68293d5143642 100644 --- a/src/app/server/DefaultTermsAndConditionsProvider.h +++ b/src/app/server/DefaultTermsAndConditionsProvider.h @@ -47,6 +47,8 @@ class DefaultTermsAndConditionsProvider : public TermsAndConditionsProvider CHIP_ERROR GetRequirements(uint16_t & outAcknowledgementsValue, uint16_t & outAcknowledgementsVersionValue) const override; + CHIP_ERROR HasAcceptance(bool & outHasAcceptance) const override; + CHIP_ERROR ResetAcceptance() override; CHIP_ERROR RevertAcceptance() override; diff --git a/src/app/server/EnhancedSetupFlowProvider.h b/src/app/server/EnhancedSetupFlowProvider.h index af1d054e273b8d..fd9862fd69ef2c 100644 --- a/src/app/server/EnhancedSetupFlowProvider.h +++ b/src/app/server/EnhancedSetupFlowProvider.h @@ -33,6 +33,8 @@ class EnhancedSetupFlowProvider public: virtual ~EnhancedSetupFlowProvider() = default; + virtual CHIP_ERROR HasReceivedTermsAndConditionscknowledgements(bool & outReceived) const = 0; + /** * @param[out] outAccepted true if the required acknowledgements have been accepted, false otherwise. */ diff --git a/src/app/server/TermsAndConditionsProvider.h b/src/app/server/TermsAndConditionsProvider.h index 4fe0fe7769b47c..45268d78baf23f 100644 --- a/src/app/server/TermsAndConditionsProvider.h +++ b/src/app/server/TermsAndConditionsProvider.h @@ -60,6 +60,13 @@ class TermsAndConditionsProvider */ virtual CHIP_ERROR GetRequirements(uint16_t & outAcknowledgementsValue, uint16_t & outAcknowledgementsVersionValue) const = 0; + /** + * @brief Retrieve if any terms and conditions has been set. + * + * @param[out] outHasAcceptance True if any acceptance has been set. + */ + virtual CHIP_ERROR HasAcceptance(bool & outHasAcceptance) const = 0; + /** * @brief Reset the persisted acceptance status of the required terms and conditions. */ diff --git a/src/controller/CommissioningDelegate.h b/src/controller/CommissioningDelegate.h index eac351aebe9e22..a707b05f873385 100644 --- a/src/controller/CommissioningDelegate.h +++ b/src/controller/CommissioningDelegate.h @@ -82,8 +82,8 @@ enum CommissioningStage : uint8_t kPrimaryOperationalNetworkFailed, ///< Indicate that the primary operational network (on root endpoint) failed, should disable ///< the primary network interface later. kDisablePrimaryNetworkInterface, ///< Send InterfaceEnabled write request to the device to disable network interface. - kGetTCAcknowledgments, ///< Waiting for the higher layer to provide terms and conditions acknowledgements. - kConfigureTCAcknowledgments, ///< Send SetTCAcknowledgements (0x30:6) command to the device + kGetTCAcknowledgments, ///< Waiting for the higher layer to provide terms and conditions acknowledgements. + kConfigureTCAcknowledgments, ///< Send SetTCAcknowledgements (0x30:6) command to the device }; enum class ICDRegistrationStrategy : uint8_t