From 3b55d2102dbf7cba6d8aec03bdccdcc5cee01c0c Mon Sep 17 00:00:00 2001 From: James Swan <122404367+swan-amazon@users.noreply.github.com> Date: Thu, 8 Aug 2024 00:55:54 +0000 Subject: [PATCH] wip --- .../general-commissioning-server.cpp | 330 ++++++++++-------- .../DefaultEnhancedSetupFlowProvider.cpp | 1 - .../server/DefaultEnhancedSetupFlowProvider.h | 2 +- .../DefaultTermsAndConditionsProvider.cpp | 16 +- .../DefaultTermsAndConditionsProvider.h | 4 +- src/app/server/EnhancedSetupFlowProvider.h | 4 +- src/app/server/Server.cpp | 16 +- src/app/server/Server.h | 8 +- 8 files changed, 202 insertions(+), 179 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 9174b2ae7a6d6a..f69d93a5343b23 100644 --- a/src/app/clusters/general-commissioning-server/general-commissioning-server.cpp +++ b/src/app/clusters/general-commissioning-server/general-commissioning-server.cpp @@ -27,7 +27,9 @@ #include #include #include +#if CHIP_CONFIG_TC_REQUIRED #include +#endif #include #include #include @@ -46,146 +48,194 @@ using namespace chip::DeviceLayer; using Transport::SecureSession; using Transport::Session; -#define CheckSuccess(expr, code) \ +// Function that calls the given callable if it is a function pointer and not nullptr +template +void CallIfFunction(T callable) +{ + if constexpr (std::is_pointer::value && std::is_function::type>::value) + { + if (nullptr != callable) + { + callable(); + } + } +} + +#define CheckSuccess(expr, code, onSuccess, onFailure) \ do \ { \ if (!::chip::ChipError::IsSuccess(expr)) \ { \ commandObj->AddStatus(commandPath, Protocols::InteractionModel::Status::code, #expr); \ + CallIfFunction(onFailure); \ return true; \ } \ + CallIfFunction(onSuccess); \ } while (false) namespace { template -static CHIP_ERROR ReadInternal(Provider* const provider, CHIP_ERROR (Provider::*const getter)(T&), AttributeValueEncoder& aEncoder) +CHIP_ERROR ReadIfSupported(Provider * const provider, CHIP_ERROR (Provider::*const nonConstGetter)(T &), + AttributeValueEncoder & aEncoder) { - T data; - if (nullptr == provider) { return CHIP_ERROR_PERSISTED_STORAGE_FAILED; } - CHIP_ERROR err = (provider->*getter)(data); - if (err == CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE) - { - data = 0; - } - else if (err != CHIP_NO_ERROR) + T value; + CHIP_ERROR err = (provider->*nonConstGetter)(value); + if (err != CHIP_NO_ERROR) { return err; } - return aEncoder.Encode(data); + return aEncoder.Encode(value); } template -static CHIP_ERROR ReadInternal(Provider* const provider, CHIP_ERROR (Provider::*const getter)(T&) const, AttributeValueEncoder& aEncoder) +CHIP_ERROR ReadIfSupported(Provider * const provider, CHIP_ERROR (Provider::*const getter)(T &) const, + AttributeValueEncoder & aEncoder) { - // Removing the const qualifier from the getter function pointer because there are a handful of getter functions that are not correctly marked as const. - using NonConstGetter = CHIP_ERROR (Provider::*)(T&); + // Removing the const qualifier from the getter function pointer because there are a handful of getter functions that are not + // correctly marked as const. + using NonConstGetter = CHIP_ERROR (Provider::*)(T &); NonConstGetter nonConstGetter = reinterpret_cast(getter); - - return ReadInternal(provider, nonConstGetter, aEncoder); -} - -template -static CHIP_ERROR ReadIfSupported(Args &&... args) -{ - return ReadInternal(std::forward(args)...); + return ReadIfSupported(provider, nonConstGetter, aEncoder); } class GeneralCommissioningAttrAccess : public AttributeAccessInterface { public: - // Register for the GeneralCommissioning cluster on all endpoints. GeneralCommissioningAttrAccess() : AttributeAccessInterface(Optional::Missing(), GeneralCommissioning::Id) {} - CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override; + CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) + { + if (aPath.mClusterId != GeneralCommissioning::Id) + { + // We shouldn't have been called at all. + return CHIP_ERROR_INVALID_ARGUMENT; + } + + switch (aPath.mAttributeId) + { + case RegulatoryConfig::Id: { + return ReadIfSupported(&DeviceLayer::ConfigurationMgr(), &ConfigurationManager::GetRegulatoryLocation, aEncoder); + } + case LocationCapability::Id: { + return ReadIfSupported(&DeviceLayer::ConfigurationMgr(), &ConfigurationManager::GetLocationCapability, aEncoder); + } + case BasicCommissioningInfo::Id: { + BasicCommissioningInfo::TypeInfo::Type basicCommissioningInfo; + + // TODO: The commissioner might use the critical parameters in BasicCommissioningInfo to initialize + // the CommissioningParameters at the beginning of commissioning flow. + basicCommissioningInfo.failSafeExpiryLengthSeconds = CHIP_DEVICE_CONFIG_FAILSAFE_EXPIRY_LENGTH_SEC; + basicCommissioningInfo.maxCumulativeFailsafeSeconds = CHIP_DEVICE_CONFIG_MAX_CUMULATIVE_FAILSAFE_SEC; + static_assert(CHIP_DEVICE_CONFIG_MAX_CUMULATIVE_FAILSAFE_SEC >= CHIP_DEVICE_CONFIG_FAILSAFE_EXPIRY_LENGTH_SEC, + "Max cumulative failsafe seconds must be larger than failsafe expiry length seconds"); + + return aEncoder.Encode(basicCommissioningInfo); + } + case SupportsConcurrentConnection::Id: { + SupportsConcurrentConnection::TypeInfo::Type supportsConcurrentConnection; + + // TODO: The commissioner might use the critical parameters in BasicCommissioningInfo to initialize + // the CommissioningParameters at the beginning of commissioning flow. + supportsConcurrentConnection = (CHIP_DEVICE_CONFIG_SUPPORTS_CONCURRENT_CONNECTION) != 0; -private: - CHIP_ERROR ReadBasicCommissioningInfo(AttributeValueEncoder & aEncoder); - CHIP_ERROR ReadSupportsConcurrentConnection(AttributeValueEncoder & aEncoder); + return aEncoder.Encode(supportsConcurrentConnection); + } +#if CHIP_CONFIG_TC_REQUIRED + case TCAcceptedVersion::Id: { + auto provider = Server::GetInstance().GetEnhancedSetupFlowProvider(); + auto getter = &EnhancedSetupFlowProvider::GetTermsAndConditionsAcceptedAcknowledgementsVersion; + return ReadIfSupported(provider, getter, aEncoder); + } + case TCMinRequiredVersion::Id: { + auto provider = Server::GetInstance().GetEnhancedSetupFlowProvider(); + auto getter = &EnhancedSetupFlowProvider::GetTermsAndConditionsRequiredAcknowledgementsVersion; + return ReadIfSupported(provider, getter, aEncoder); + } + case TCAcknowledgements::Id: { + auto provider = Server::GetInstance().GetEnhancedSetupFlowProvider(); + auto getter = &EnhancedSetupFlowProvider::GetTermsAndConditionsAcceptedAcknowledgements; + return ReadIfSupported(provider, getter, aEncoder); + } + case TCAcknowledgementsRequired::Id: { + auto provider = Server::GetInstance().GetEnhancedSetupFlowProvider(); + auto getter = &EnhancedSetupFlowProvider::GetTermsAndConditionsRequiredAcknowledgements; + return ReadIfSupported(provider, getter, aEncoder); + } +#endif + default: + break; + } + return CHIP_NO_ERROR; + } }; -GeneralCommissioningAttrAccess gAttrAccess; +GeneralCommissioningAttrAccess gAttributeAccessInstance; -CHIP_ERROR GeneralCommissioningAttrAccess::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) +#if CHIP_CONFIG_TC_REQUIRED +CHIP_ERROR checkTermsAndConditionsAcknowledgementsState(CommissioningErrorEnum & errorCode) { - if (aPath.mClusterId != GeneralCommissioning::Id) + EnhancedSetupFlowProvider * enhancedSetupFlowProvider = Server::GetInstance().GetEnhancedSetupFlowProvider(); + + CHIP_ERROR err; + + uint16_t termsAndConditionsAcceptedAcknowledgements; + bool hasRequiredTermAccepted; + bool hasRequiredTermVersionAccepted; + + err = enhancedSetupFlowProvider->GetTermsAndConditionsAcceptedAcknowledgements(termsAndConditionsAcceptedAcknowledgements); + if (!::chip::ChipError::IsSuccess(err)) { - // We shouldn't have been called at all. - return CHIP_ERROR_INVALID_ARGUMENT; + ChipLogError(AppServer, "Failed to GetTermsAndConditionsAcceptedAcknowledgements"); + return err; } - switch (aPath.mAttributeId) + err = enhancedSetupFlowProvider->HasTermsAndConditionsRequiredAcknowledgementsBeenAccepted(hasRequiredTermAccepted); + if (!::chip::ChipError::IsSuccess(err)) { - case RegulatoryConfig::Id: { - return ReadIfSupported(&DeviceLayer::ConfigurationMgr(), &ConfigurationManager::GetRegulatoryLocation, aEncoder); - } - case LocationCapability::Id: { - return ReadIfSupported(&DeviceLayer::ConfigurationMgr(), &ConfigurationManager::GetLocationCapability, aEncoder); - } - case BasicCommissioningInfo::Id: { - return ReadBasicCommissioningInfo(aEncoder); - } - case SupportsConcurrentConnection::Id: { - return ReadSupportsConcurrentConnection(aEncoder); - } -#if defined (CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS) && defined (CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION) - case TCAcceptedVersion::Id: { - app::EnhancedSetupFlowProvider * provider = Server::GetInstance().GetEnhancedSetupFlowProvider(); - auto getter = &EnhancedSetupFlowProvider::GetTermsAndConditionsAcceptedAcknowledgementsVersion; - return ReadIfSupported(provider, getter, aEncoder); - } - case TCMinRequiredVersion::Id: { - auto provider = Server::GetInstance().GetEnhancedSetupFlowProvider(); - auto getter = &EnhancedSetupFlowProvider::GetTermsAndConditionsRequiredAcknowledgementsVersion; - return ReadIfSupported(provider, getter, aEncoder); - } - case TCAcknowledgements::Id: { - auto provider = Server::GetInstance().GetEnhancedSetupFlowProvider(); - auto getter = &EnhancedSetupFlowProvider::GetTermsAndConditionsAcceptedAcknowledgements; - return ReadIfSupported(provider, getter, aEncoder); - } - case TCAcknowledgementsRequired::Id: { - auto provider = Server::GetInstance().GetEnhancedSetupFlowProvider(); - auto getter = &EnhancedSetupFlowProvider::GetTermsAndConditionsRequiredAcknowledgements; - return ReadIfSupported(provider, getter, aEncoder); - } -#endif - default: - break; + ChipLogError(AppServer, "Failed to HasTermsAndConditionsRequiredAcknowledgementsBeenAccepted"); + return err; } - return CHIP_NO_ERROR; -} - -CHIP_ERROR GeneralCommissioningAttrAccess::ReadBasicCommissioningInfo(AttributeValueEncoder & aEncoder) -{ - BasicCommissioningInfo::TypeInfo::Type basicCommissioningInfo; - // TODO: The commissioner might use the critical parameters in BasicCommissioningInfo to initialize - // the CommissioningParameters at the beginning of commissioning flow. - basicCommissioningInfo.failSafeExpiryLengthSeconds = CHIP_DEVICE_CONFIG_FAILSAFE_EXPIRY_LENGTH_SEC; - basicCommissioningInfo.maxCumulativeFailsafeSeconds = CHIP_DEVICE_CONFIG_MAX_CUMULATIVE_FAILSAFE_SEC; - static_assert(CHIP_DEVICE_CONFIG_MAX_CUMULATIVE_FAILSAFE_SEC >= CHIP_DEVICE_CONFIG_FAILSAFE_EXPIRY_LENGTH_SEC, - "Max cumulative failsafe seconds must be larger than failsafe expiry length seconds"); + err = + enhancedSetupFlowProvider->HasTermsAndConditionsRequiredAcknowledgementsVersionBeenAccepted(hasRequiredTermVersionAccepted); + if (!::chip::ChipError::IsSuccess(err)) + { + ChipLogError(AppServer, "Failed to HasTermsAndConditionsRequiredAcknowledgementsVersionBeenAccepted"); + return err; + } - return aEncoder.Encode(basicCommissioningInfo); -} + if (!hasRequiredTermAccepted) + { + uint16_t requiredAcknowledgements = 0; + (void) enhancedSetupFlowProvider->GetTermsAndConditionsRequiredAcknowledgements(requiredAcknowledgements); -CHIP_ERROR GeneralCommissioningAttrAccess::ReadSupportsConcurrentConnection(AttributeValueEncoder & aEncoder) -{ - SupportsConcurrentConnection::TypeInfo::Type supportsConcurrentConnection; + ChipLogProgress(AppServer, "Required terms and conditions, 0x%04x,have not been accepted", requiredAcknowledgements); + errorCode = (0 == termsAndConditionsAcceptedAcknowledgements) ? CommissioningErrorEnum::kTCAcknowledgementsNotReceived + : CommissioningErrorEnum::kRequiredTCNotAccepted; + return CHIP_NO_ERROR; + } - // TODO: The commissioner might use the critical parameters in BasicCommissioningInfo to initialize - // the CommissioningParameters at the beginning of commissioning flow. - supportsConcurrentConnection = (CHIP_DEVICE_CONFIG_SUPPORTS_CONCURRENT_CONNECTION) != 0; + if (!hasRequiredTermVersionAccepted) + { + uint16_t requiredAcknowledgementsVersion = 0; + (void) enhancedSetupFlowProvider->GetTermsAndConditionsRequiredAcknowledgementsVersion(requiredAcknowledgementsVersion); + ChipLogProgress(AppServer, "Minimum terms and conditions version, 0x%04x, has not been accepted", + requiredAcknowledgementsVersion); + errorCode = CommissioningErrorEnum::kTCMinVersionNotMet; + return CHIP_NO_ERROR; + } - return aEncoder.Encode(supportsConcurrentConnection); + errorCode = CommissioningErrorEnum::kOk; + return CHIP_NO_ERROR; } +#endif } // anonymous namespace @@ -236,7 +286,7 @@ bool emberAfGeneralCommissioningClusterArmFailSafeCallback(app::CommandHandler * { CheckSuccess( failSafeContext.ArmFailSafe(accessingFabricIndex, System::Clock::Seconds16(commandData.expiryLengthSeconds)), - Failure); + Failure, nullptr, nullptr); Breadcrumb::Set(commandPath.mEndpointId, commandData.breadcrumb); response.errorCode = CommissioningErrorEnum::kOk; commandObj->AddResponse(commandPath, response); @@ -257,9 +307,6 @@ bool emberAfGeneralCommissioningClusterCommissioningCompleteCallback( { MATTER_TRACE_SCOPE("CommissioningComplete", "GeneralCommissioning"); -#if defined (CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS) && defined (CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION) - EnhancedSetupFlowProvider * enhancedSetupFlowProvider = Server::GetInstance().GetEnhancedSetupFlowProvider(); -#endif DeviceControlServer * const devCtrl = &DeviceLayer::DeviceControlServer::DeviceControlSvr(); auto & failSafe = Server::GetInstance().GetFailSafeContext(); auto & fabricTable = Server::GetInstance().GetFabricTable(); @@ -287,62 +334,30 @@ bool emberAfGeneralCommissioningClusterCommissioningCompleteCallback( { CHIP_ERROR err; -#if defined (CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS) && defined (CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION) - - uint16_t termsAndConditionsAcceptedAcknowledgements; - bool hasRequiredTermAccepted; - bool hasRequiredTermVersionAccepted; - - err = enhancedSetupFlowProvider->GetTermsAndConditionsAcceptedAcknowledgements( - termsAndConditionsAcceptedAcknowledgements); - CheckSuccess(err, Failure); - - err = enhancedSetupFlowProvider->HasTermsAndConditionsRequiredAcknowledgementsBeenAccepted( - hasRequiredTermAccepted); - CheckSuccess(err, Failure); - - err = enhancedSetupFlowProvider->HasTermsAndConditionsRequiredAcknowledgementsVersionBeenAccepted( - hasRequiredTermVersionAccepted); - CheckSuccess(err, Failure); +#if CHIP_CONFIG_TC_REQUIRED + CheckSuccess(checkTermsAndConditionsAcknowledgementsState(response.errorCode), Failure, nullptr, nullptr); +#endif - if (!hasRequiredTermAccepted) + if (failSafe.NocCommandHasBeenInvoked()) { - ChipLogProgress(AppServer, "Required terms and conditions have not been accepted"); - Breadcrumb::Set(commandPath.mEndpointId, 0); - response.errorCode = (0 == termsAndConditionsAcceptedAcknowledgements) - ? CommissioningErrorEnum::kTCAcknowledgementsNotReceived - : CommissioningErrorEnum::kRequiredTCNotAccepted; + err = fabricTable.CommitPendingFabricData(); + CheckSuccess( + err, Failure, + []() { ChipLogProgress(FailSafe, "GeneralCommissioning: Successfully commited pending fabric data"); }, + []() { ChipLogError(FailSafe, "GeneralCommissioning: Failed to commit pending fabric data"); }); } - else if (!hasRequiredTermVersionAccepted) - { - ChipLogProgress(AppServer, "Minimum terms and conditions version has not been accepted"); - Breadcrumb::Set(commandPath.mEndpointId, 0); - response.errorCode = CommissioningErrorEnum::kTCMinVersionNotMet; - } + /* + * Pass fabric of commissioner to DeviceControlSvr. + * This allows device to send messages back to commissioner. + * Once bindings are implemented, this may no longer be needed. + */ + failSafe.DisarmFailSafe(); + err = devCtrl->PostCommissioningCompleteEvent(handle->AsSecureSession()->GetPeerNodeId(), handle->GetFabricIndex()); + CheckSuccess(err, Failure, nullptr, nullptr); - else -#endif - { - if (failSafe.NocCommandHasBeenInvoked()) - { - err = fabricTable.CommitPendingFabricData(); - CheckSuccess(err, Failure); - ChipLogProgress(FailSafe, "GeneralCommissioning: Successfully commited pending fabric data"); - } - - /* - * Pass fabric of commissioner to DeviceControlSvr. - * This allows device to send messages back to commissioner. - * Once bindings are implemented, this may no longer be needed. - */ - failSafe.DisarmFailSafe(); - err = devCtrl->PostCommissioningCompleteEvent(handle->AsSecureSession()->GetPeerNodeId(), handle->GetFabricIndex()); - CheckSuccess(err, Failure); - - Breadcrumb::Set(commandPath.mEndpointId, 0); - response.errorCode = CommissioningErrorEnum::kOk; - } + Breadcrumb::Set(commandPath.mEndpointId, 0); + response.errorCode = CommissioningErrorEnum::kOk; } } @@ -380,7 +395,7 @@ bool emberAfGeneralCommissioningClusterSetRegulatoryConfigCallback(app::CommandH uint8_t locationCapability; uint8_t location = to_underlying(commandData.newRegulatoryConfig); - CheckSuccess(ConfigurationMgr().GetLocationCapability(locationCapability), Failure); + CheckSuccess(ConfigurationMgr().GetLocationCapability(locationCapability), Failure, nullptr, nullptr); // If the LocationCapability attribute is not Indoor/Outdoor and the NewRegulatoryConfig value received does not match // either the Indoor or Outdoor fixed value in LocationCapability. @@ -393,7 +408,7 @@ bool emberAfGeneralCommissioningClusterSetRegulatoryConfigCallback(app::CommandH } else { - CheckSuccess(server->SetRegulatoryConfig(location, countryCode), Failure); + CheckSuccess(server->SetRegulatoryConfig(location, countryCode), Failure, nullptr, nullptr); Breadcrumb::Set(commandPath.mEndpointId, commandData.breadcrumb); response.errorCode = CommissioningErrorEnum::kOk; } @@ -408,18 +423,22 @@ bool emberAfGeneralCommissioningClusterSetTCAcknowledgementsCallback( chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, const chip::app::Clusters::GeneralCommissioning::Commands::SetTCAcknowledgements::DecodableType & commandData) { -#if defined (CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS) && defined (CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION) +#if !CHIP_CONFIG_TC_REQUIRED + return false; + +#else MATTER_TRACE_SCOPE("SetTCAcknowledgements", "GeneralCommissioning"); Commands::SetTCAcknowledgementsResponse::Type response; EnhancedSetupFlowProvider * const enhancedSetupFlowProvider = Server::GetInstance().GetEnhancedSetupFlowProvider(); uint16_t acknowledgements = commandData.TCUserResponse; uint16_t acknowledgementsVersion = commandData.TCVersion; - CheckSuccess(enhancedSetupFlowProvider->SetTermsAndConditionsAcceptance(acknowledgements, acknowledgementsVersion), Failure); - response.errorCode = CommissioningErrorEnum::kOk; - + CheckSuccess(enhancedSetupFlowProvider->SetTermsAndConditionsAcceptance(acknowledgements, acknowledgementsVersion), Failure, + nullptr, nullptr); + CheckSuccess(checkTermsAndConditionsAcknowledgementsState(response.errorCode), Failure, nullptr, nullptr); commandObj->AddResponse(commandPath, response); -#endif return true; + +#endif } namespace { @@ -429,6 +448,11 @@ void OnPlatformEventHandler(const DeviceLayer::ChipDeviceEvent * event, intptr_t { // Spec says to reset Breadcrumb attribute to 0. Breadcrumb::Set(0, 0); + +#if CHIP_CONFIG_TC_REQUIRED + // Clear terms and conditions acceptance on failsafe timer expiration + Server::GetInstance().GetEnhancedSetupFlowProvider()->ClearTermsAndConditionsAcceptance(); +#endif } } @@ -437,7 +461,7 @@ void OnPlatformEventHandler(const DeviceLayer::ChipDeviceEvent * event, intptr_t void MatterGeneralCommissioningPluginServerInitCallback() { Breadcrumb::Set(0, 0); - AttributeAccessInterfaceRegistry::Instance().Register(&gAttrAccess); + registerAttributeAccessOverride(&gAttributeAccessInstance); DeviceLayer::PlatformMgrImpl().AddEventHandler(OnPlatformEventHandler); } diff --git a/src/app/server/DefaultEnhancedSetupFlowProvider.cpp b/src/app/server/DefaultEnhancedSetupFlowProvider.cpp index b57c0381610e3c..821d247308b1c0 100644 --- a/src/app/server/DefaultEnhancedSetupFlowProvider.cpp +++ b/src/app/server/DefaultEnhancedSetupFlowProvider.cpp @@ -22,7 +22,6 @@ #include #include -#include CHIP_ERROR chip::app::DefaultEnhancedSetupFlowProvider::Init(TermsAndConditionsProvider * const inTermsAndConditionsProvider) { diff --git a/src/app/server/DefaultEnhancedSetupFlowProvider.h b/src/app/server/DefaultEnhancedSetupFlowProvider.h index fc209cb410c334..19cfa7f77791c8 100644 --- a/src/app/server/DefaultEnhancedSetupFlowProvider.h +++ b/src/app/server/DefaultEnhancedSetupFlowProvider.h @@ -74,7 +74,7 @@ class DefaultEnhancedSetupFlowProvider : public EnhancedSetupFlowProvider /** * @copydoc EnhancedSetupFlowProvider::SetTermsAndConditionsAcceptance */ - CHIP_ERROR SetTermsAndConditionsAcceptance(uint16_t aTCAcknowledgements, uint16_t aTCAcknowledgementsVersion) override; + CHIP_ERROR SetTermsAndConditionsAcceptance(uint16_t aTCAcknowledgements, uint16_t inTCAcknowledgementsVersionValue) override; /** * @copydoc EnhancedSetupFlowProvider::ClearTermsAndConditionsAcceptance diff --git a/src/app/server/DefaultTermsAndConditionsProvider.cpp b/src/app/server/DefaultTermsAndConditionsProvider.cpp index 564c80b16e783d..0ce37729b058ba 100644 --- a/src/app/server/DefaultTermsAndConditionsProvider.cpp +++ b/src/app/server/DefaultTermsAndConditionsProvider.cpp @@ -23,12 +23,13 @@ #include #include #include -#include namespace { -static constexpr chip::TLV::Tag kAcceptedAcknowledgementsTag = chip::TLV::ContextTag(1); -static constexpr chip::TLV::Tag kAcceptedAcknowledgementsVersionTag = chip::TLV::ContextTag(2); -static constexpr size_t kEstimatedTlvBufferSize = chip::TLV::EstimateStructOverhead(sizeof(uint16_t), sizeof(uint16_t)); +constexpr chip::TLV::Tag kSerializationVersionTag = chip::TLV::ContextTag(1); +constexpr chip::TLV::Tag kAcceptedAcknowledgementsTag = chip::TLV::ContextTag(2); +constexpr chip::TLV::Tag kAcceptedAcknowledgementsVersionTag = chip::TLV::ContextTag(3); +constexpr uint8_t kSerializationVersion = 1; +constexpr size_t kEstimatedTlvBufferSize = chip::TLV::EstimateStructOverhead(sizeof(uint8_t), sizeof(uint16_t), sizeof(uint16_t)); }; // namespace CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::Init(chip::PersistentStorageDelegate * const inPersistentStorageDelegate, @@ -83,11 +84,9 @@ CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::GetAcceptance(uint16_t tlvReader.Init(buffer); ReturnErrorOnFailure(tlvReader.Next(chip::TLV::kTLVType_Structure, chip::TLV::AnonymousTag())); ReturnErrorOnFailure(tlvReader.EnterContainer(tlvContainer)); - ReturnErrorOnFailure(tlvReader.Next()); - ReturnErrorOnFailure(tlvReader.Expect(kAcceptedAcknowledgementsTag)); + ReturnErrorOnFailure(tlvReader.Next(kAcceptedAcknowledgementsTag)); ReturnErrorOnFailure(tlvReader.Get(acknowledgements)); - ReturnErrorOnFailure(tlvReader.Next()); - ReturnErrorOnFailure(tlvReader.Expect(kAcceptedAcknowledgementsVersionTag)); + ReturnErrorOnFailure(tlvReader.Next(kAcceptedAcknowledgementsVersionTag)); ReturnErrorOnFailure(tlvReader.Get(acknowledgementsVersion)); ReturnErrorOnFailure(tlvReader.ExitContainer(tlvContainer)); @@ -117,6 +116,7 @@ CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::SetAcceptance(uint16_t tlvWriter.Init(buffer, sizeof(buffer)); ReturnErrorOnFailure(tlvWriter.StartContainer(chip::TLV::AnonymousTag(), chip::TLV::kTLVType_Structure, tlvContainer)); + ReturnErrorOnFailure(tlvWriter.Put(kSerializationVersionTag, kSerializationVersion)); ReturnErrorOnFailure(tlvWriter.Put(kAcceptedAcknowledgementsTag, inAcceptedAcknowledgementsValue)); ReturnErrorOnFailure(tlvWriter.Put(kAcceptedAcknowledgementsVersionTag, inAcceptedAcknowledgementsVersionValue)); ReturnErrorOnFailure(tlvWriter.EndContainer(tlvContainer)); diff --git a/src/app/server/DefaultTermsAndConditionsProvider.h b/src/app/server/DefaultTermsAndConditionsProvider.h index 3205f98e57948a..d70d0f124db6df 100644 --- a/src/app/server/DefaultTermsAndConditionsProvider.h +++ b/src/app/server/DefaultTermsAndConditionsProvider.h @@ -40,7 +40,7 @@ class DefaultTermsAndConditionsProvider : public TermsAndConditionsProvider * @param[in] inRequiredAcknowledgementsVersionValue The version of the required acknowledgements. * @return CHIP_ERROR On success returns CHIP_NO_ERROR, otherwise returns an error code. */ - CHIP_ERROR Init(chip::PersistentStorageDelegate * const inPersistentStorageDelegate, uint16_t inRequiredAcknowledgementsValue, + CHIP_ERROR Init(PersistentStorageDelegate * const inPersistentStorageDelegate, uint16_t inRequiredAcknowledgementsValue, uint16_t inRequiredAcknowledgementsVersionValue); /** @@ -64,7 +64,7 @@ class DefaultTermsAndConditionsProvider : public TermsAndConditionsProvider CHIP_ERROR SetAcceptance(uint16_t inAcknowledgementsValue, uint16_t inAcknowledgementsVersionValue) override; private: - chip::PersistentStorageDelegate * mPersistentStorageDelegate; + PersistentStorageDelegate * mPersistentStorageDelegate; uint16_t mRequiredAcknowledgementsValue; uint16_t mRequiredAcknowledgementsVersionValue; }; diff --git a/src/app/server/EnhancedSetupFlowProvider.h b/src/app/server/EnhancedSetupFlowProvider.h index 063b9352d18013..5e8d276a3d3cd7 100644 --- a/src/app/server/EnhancedSetupFlowProvider.h +++ b/src/app/server/EnhancedSetupFlowProvider.h @@ -92,11 +92,11 @@ class EnhancedSetupFlowProvider * @brief Sets the acceptance status of the terms and conditions. * * @param[in] inTCAcknowledgements The acknowledgements to accept. - * @param[in] inTCAcknowledgementsoutValue The version of the acknowledgements to accept. + * @param[in] inTCAcknowledgementsVersionValue The version of the acknowledgements to accept. * @return CHIP_ERROR On success returns CHIP_NO_ERROR, otherwise returns an error code. */ virtual CHIP_ERROR SetTermsAndConditionsAcceptance(uint16_t inTCAcknowledgementsValue, - uint16_t inTCAcknowledgementsoutValue) = 0; + uint16_t inTCAcknowledgementsVersionValue) = 0; /** * @brief Clears the acceptance status of the terms and conditions. diff --git a/src/app/server/Server.cpp b/src/app/server/Server.cpp index 94915381275e23..46d523a6757e0e 100644 --- a/src/app/server/Server.cpp +++ b/src/app/server/Server.cpp @@ -107,7 +107,7 @@ static ::chip::PersistedCounter sGlobalEventIdCounter; static ::chip::app::CircularEventBuffer sLoggingBuffer[CHIP_NUM_EVENT_LOGGING_BUFFERS]; #endif // CHIP_CONFIG_ENABLE_SERVER_IM_EVENT -#if defined (CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS) && defined (CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION) +#if defined(CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS) && defined(CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION) app::DefaultEnhancedSetupFlowProvider sDefaultEnhancedSetupFlowProviderInstance; app::EnhancedSetupFlowProvider * CommonCaseDeviceServerInitParams::sDefaultEnhancedSetupFlowProvider = &sDefaultEnhancedSetupFlowProviderInstance; @@ -155,7 +155,7 @@ CHIP_ERROR CommonCaseDeviceServerInitParams::InitializeStaticResourcesBeforeServ reportScheduler = &sReportScheduler; } -#if defined (CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS) && defined (CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION) +#if defined(CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS) && defined(CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION) if (this->termsAndConditionsProvider == nullptr) { ReturnErrorOnFailure(sDefaultTermsAndConditionsProviderInstance.Init(this->persistentStorageDelegate, @@ -202,10 +202,10 @@ CHIP_ERROR CommonCaseDeviceServerInitParams::InitializeStaticResourcesBeforeServ #endif #if CHIP_CONFIG_ENABLE_ICD_CIP - if (this->icdCheckInBackOffStrategy == nullptr) - { - this->icdCheckInBackOffStrategy = &sDefaultICDCheckInBackOffStrategy; - } + if (this->icdCheckInBackOffStrategy == nullptr) + { + this->icdCheckInBackOffStrategy = &sDefaultICDCheckInBackOffStrategy; + } #endif return CHIP_NO_ERROR; @@ -235,7 +235,7 @@ CHIP_ERROR Server::Init(const ServerInitParams & initParams) VerifyOrExit(initParams.operationalKeystore != nullptr, err = CHIP_ERROR_INVALID_ARGUMENT); VerifyOrExit(initParams.opCertStore != nullptr, err = CHIP_ERROR_INVALID_ARGUMENT); VerifyOrExit(initParams.reportScheduler != nullptr, err = CHIP_ERROR_INVALID_ARGUMENT); -#if defined (CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS) && defined (CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION) +#if defined(CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS) && defined(CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION) VerifyOrExit(initParams.enhancedSetupFlowProvider != nullptr, err = CHIP_ERROR_INVALID_ARGUMENT); VerifyOrExit(initParams.termsAndConditionsProvider != nullptr, err = CHIP_ERROR_INVALID_ARGUMENT); #endif @@ -295,7 +295,7 @@ CHIP_ERROR Server::Init(const ServerInitParams & initParams) mReportScheduler = initParams.reportScheduler; -#if defined (CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS) && defined (CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION) +#if defined(CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS) && defined(CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION) mTermsAndConditionsProvider = initParams.termsAndConditionsProvider; mEnhancedSetupFlowProvider = initParams.enhancedSetupFlowProvider; #endif diff --git a/src/app/server/Server.h b/src/app/server/Server.h index f9ef037df96c08..739cffcd445476 100644 --- a/src/app/server/Server.h +++ b/src/app/server/Server.h @@ -181,7 +181,7 @@ struct ServerInitParams // Optional. Support for the ICD Check-In BackOff strategy. Must be initialized before being provided. // If the ICD Check-In protocol use-case is supported and no strategy is provided, server will use the default strategy. app::ICDCheckInBackOffStrategy * icdCheckInBackOffStrategy = nullptr; -#if defined (CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS) && defined (CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION) +#if defined(CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS) && defined(CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION) // Optional. Enhanced setup flow provider to support terms and conditions acceptance check. app::EnhancedSetupFlowProvider * enhancedSetupFlowProvider = nullptr; // Optional. Terms and conditions provider to support enhanced setup flow feature. @@ -254,7 +254,7 @@ struct CommonCaseDeviceServerInitParams : public ServerInitParams #if CHIP_CONFIG_ENABLE_ICD_CIP static app::DefaultICDCheckInBackOffStrategy sDefaultICDCheckInBackOffStrategy; #endif -#if defined (CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS) && defined (CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION) +#if defined(CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS) && defined(CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION) static app::EnhancedSetupFlowProvider * sDefaultEnhancedSetupFlowProvider; static app::TermsAndConditionsProvider * sDefaultTermsAndConditionsProvider; #endif @@ -338,7 +338,7 @@ class Server app::reporting::ReportScheduler * GetReportScheduler() { return mReportScheduler; } -#if defined (CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS) && defined (CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION) +#if defined(CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS) && defined(CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION) app::EnhancedSetupFlowProvider * GetEnhancedSetupFlowProvider() { return mEnhancedSetupFlowProvider; } #endif @@ -615,7 +615,7 @@ class Server GroupDataProviderListener mListener; ServerFabricDelegate mFabricDelegate; app::reporting::ReportScheduler * mReportScheduler; -#if defined (CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS) && defined (CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION) +#if defined(CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS) && defined(CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION) app::EnhancedSetupFlowProvider * mEnhancedSetupFlowProvider; app::TermsAndConditionsProvider * mTermsAndConditionsProvider; #endif