Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
swan-amazon committed Aug 8, 2024
1 parent 3b55d21 commit 6d889cf
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 26 deletions.
1 change: 0 additions & 1 deletion src/app/server/DefaultEnhancedSetupFlowProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class DefaultEnhancedSetupFlowProvider : public EnhancedSetupFlowProvider
* @brief Initializes the EnhancedSetupFlowProvider.
*
* @param[in] inTermsAndConditionsProvider The terms and conditions provide dependency.
* @return CHIP_ERROR On success returns CHIP_NO_ERROR, otherwise returns an error code.
*/
CHIP_ERROR Init(TermsAndConditionsProvider * const inTermsAndConditionsProvider);

Expand Down
16 changes: 14 additions & 2 deletions src/app/server/DefaultTermsAndConditionsProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <lib/core/TLVTypes.h>
#include <lib/support/CodeUtils.h>
#include <lib/support/DefaultStorageKeyAllocator.h>
#include <lib/support/SafeInt.h>

namespace {
constexpr chip::TLV::Tag kSerializationVersionTag = chip::TLV::ContextTag(1);
Expand Down Expand Up @@ -58,6 +59,7 @@ CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::ClearAcceptance()
CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::GetAcceptance(uint16_t & outAcknowledgementsValue,
uint16_t & outAcknowledgementsVersionValue) const
{
uint8_t serializationVersion = 0;
uint16_t acknowledgements = 0;
uint16_t acknowledgementsVersion = 0;

Expand All @@ -81,15 +83,22 @@ CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::GetAcceptance(uint16_t

VerifyOrReturnError(CHIP_NO_ERROR == err, err);

tlvReader.Init(buffer);
tlvReader.Init(buffer, bufferSize);
ReturnErrorOnFailure(tlvReader.Next(chip::TLV::kTLVType_Structure, chip::TLV::AnonymousTag()));
ReturnErrorOnFailure(tlvReader.EnterContainer(tlvContainer));
ReturnErrorOnFailure(tlvReader.Next(kSerializationVersionTag));
ReturnErrorOnFailure(tlvReader.Get(serializationVersion));
ReturnErrorOnFailure(tlvReader.Next(kAcceptedAcknowledgementsTag));
ReturnErrorOnFailure(tlvReader.Get(acknowledgements));
ReturnErrorOnFailure(tlvReader.Next(kAcceptedAcknowledgementsVersionTag));
ReturnErrorOnFailure(tlvReader.Get(acknowledgementsVersion));
ReturnErrorOnFailure(tlvReader.ExitContainer(tlvContainer));

if (kSerializationVersion != serializationVersion)
{
return CHIP_ERROR_VERSION_MISMATCH;
}

outAcknowledgementsValue = acknowledgements;
outAcknowledgementsVersionValue = acknowledgementsVersion;

Expand Down Expand Up @@ -121,9 +130,12 @@ CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::SetAcceptance(uint16_t
ReturnErrorOnFailure(tlvWriter.Put(kAcceptedAcknowledgementsVersionTag, inAcceptedAcknowledgementsVersionValue));
ReturnErrorOnFailure(tlvWriter.EndContainer(tlvContainer));
ReturnErrorOnFailure(tlvWriter.Finalize());
uint32_t lengthWritten = tlvWriter.GetLengthWritten();
VerifyOrReturnError(CanCastTo<uint16_t>(lengthWritten), CHIP_ERROR_BUFFER_TOO_SMALL);

const chip::StorageKeyName storageKey = DefaultStorageKeyAllocator::TermsAndConditionsAcceptance();
ReturnErrorOnFailure(mPersistentStorageDelegate->SyncSetKeyValue(storageKey.KeyName(), buffer, sizeof(buffer)));
ReturnErrorOnFailure(
mPersistentStorageDelegate->SyncSetKeyValue(storageKey.KeyName(), buffer, static_cast<uint16_t>(lengthWritten)));

return CHIP_NO_ERROR;
}
1 change: 0 additions & 1 deletion src/app/server/DefaultTermsAndConditionsProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class DefaultTermsAndConditionsProvider : public TermsAndConditionsProvider
* @param[in] inPersistentStorageDelegate Persistent storage delegate dependency.
* @param[in] inRequiredAcknowledgementsValue The bitmask of required acknowledgements.
* @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(PersistentStorageDelegate * const inPersistentStorageDelegate, uint16_t inRequiredAcknowledgementsValue,
uint16_t inRequiredAcknowledgementsVersionValue);
Expand Down
10 changes: 1 addition & 9 deletions src/app/server/EnhancedSetupFlowProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace app {
/**
* @brief Feature state access layer for the EnhancedSetupFlowProvider.
*
* This class provides access to the state of the feature through the TermsAndConditionsProvider.
* This class provides access to the state of the Enhanced Setup Flow feature.
*/
class EnhancedSetupFlowProvider
{
Expand All @@ -44,47 +44,41 @@ class EnhancedSetupFlowProvider
* @brief Checks if the required terms and conditions acknowledgements have been accepted.
*
* @param[out] outAccepted true if the required acknowledgements have been accepted, false otherwise.
* @return CHIP_ERROR On success returns CHIP_NO_ERROR, otherwise returns an error code.
*/
virtual CHIP_ERROR HasTermsAndConditionsRequiredAcknowledgementsBeenAccepted(bool & outAccepted) const = 0;

/**
* @brief Checks if the required terms and conditions acknowledgements version has been accepted.
*
* @param[out] outAccepted true if the required acknowledgements version has been accepted, false otherwise.
* @return CHIP_ERROR On success returns CHIP_NO_ERROR, otherwise returns an error code.
*/
virtual CHIP_ERROR HasTermsAndConditionsRequiredAcknowledgementsVersionBeenAccepted(bool & outAccepted) const = 0;

/**
* @brief Retrieves the required terms and conditions acknowledgements.
*
* @param[out] outValue The version of the required acknowledgements.
* @return CHIP_ERROR On success returns CHIP_NO_ERROR, otherwise returns an error code.
*/
virtual CHIP_ERROR GetTermsAndConditionsRequiredAcknowledgements(uint16_t & outValue) const = 0;

/**
* @brief Retrieves the required terms and conditions acknowledgements version.
*
* @param[out] outValue The outValue of the required acknowledgements version.
* @return CHIP_ERROR On success returns CHIP_NO_ERROR, otherwise returns an error code.
*/
virtual CHIP_ERROR GetTermsAndConditionsRequiredAcknowledgementsVersion(uint16_t & outValue) const = 0;

/**
* @brief Retrieves the accepted terms and conditions acknowledgements.
*
* @param[out] outValue The outValue of the accepted acknowledgements.
* @return CHIP_ERROR On success returns CHIP_NO_ERROR, otherwise returns an error code.
*/
virtual CHIP_ERROR GetTermsAndConditionsAcceptedAcknowledgements(uint16_t & outValue) const = 0;

/**
* @brief Retrieves the accepted terms and conditions acknowledgements version.
*
* @param[out] outValue The outValue of the accepted acknowledgements version.
* @return CHIP_ERROR On success returns CHIP_NO_ERROR, otherwise returns an error code.
*/
virtual CHIP_ERROR GetTermsAndConditionsAcceptedAcknowledgementsVersion(uint16_t & outValue) const = 0;

Expand All @@ -93,15 +87,13 @@ class EnhancedSetupFlowProvider
*
* @param[in] inTCAcknowledgements 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 inTCAcknowledgementsVersionValue) = 0;

/**
* @brief Clears the acceptance status of the terms and conditions.
*
* @return CHIP_ERROR On success returns CHIP_NO_ERROR, otherwise returns an error code.
*/
virtual CHIP_ERROR ClearTermsAndConditionsAcceptance() = 0;
};
Expand Down
8 changes: 4 additions & 4 deletions src/app/server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ static ::chip::PersistedCounter<chip::EventNumber> 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 CHIP_CONFIG_TC_REQUIRED
app::DefaultEnhancedSetupFlowProvider sDefaultEnhancedSetupFlowProviderInstance;
app::EnhancedSetupFlowProvider * CommonCaseDeviceServerInitParams::sDefaultEnhancedSetupFlowProvider =
&sDefaultEnhancedSetupFlowProviderInstance;
Expand Down Expand Up @@ -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 CHIP_CONFIG_TC_REQUIRED
if (this->termsAndConditionsProvider == nullptr)
{
ReturnErrorOnFailure(sDefaultTermsAndConditionsProviderInstance.Init(this->persistentStorageDelegate,
Expand Down Expand Up @@ -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 CHIP_CONFIG_TC_REQUIRED
VerifyOrExit(initParams.enhancedSetupFlowProvider != nullptr, err = CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrExit(initParams.termsAndConditionsProvider != nullptr, err = CHIP_ERROR_INVALID_ARGUMENT);
#endif
Expand Down Expand Up @@ -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 CHIP_CONFIG_TC_REQUIRED
mTermsAndConditionsProvider = initParams.termsAndConditionsProvider;
mEnhancedSetupFlowProvider = initParams.enhancedSetupFlowProvider;
#endif
Expand Down
8 changes: 4 additions & 4 deletions src/app/server/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 CHIP_CONFIG_TC_REQUIRED
// 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.
Expand Down Expand Up @@ -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 CHIP_CONFIG_TC_REQUIRED
static app::EnhancedSetupFlowProvider * sDefaultEnhancedSetupFlowProvider;
static app::TermsAndConditionsProvider * sDefaultTermsAndConditionsProvider;
#endif
Expand Down Expand Up @@ -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 CHIP_CONFIG_TC_REQUIRED
app::EnhancedSetupFlowProvider * GetEnhancedSetupFlowProvider() { return mEnhancedSetupFlowProvider; }
#endif

Expand Down Expand Up @@ -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 CHIP_CONFIG_TC_REQUIRED
app::EnhancedSetupFlowProvider * mEnhancedSetupFlowProvider;
app::TermsAndConditionsProvider * mTermsAndConditionsProvider;
#endif
Expand Down
5 changes: 0 additions & 5 deletions src/app/server/TermsAndConditionsProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ class TermsAndConditionsProvider

/**
* @brief Sets the acceptance status of the required terms and conditions.
*
* @return CHIP_ERROR On success returns CHIP_NO_ERROR, otherwise returns an error code.
*/
virtual CHIP_ERROR ClearAcceptance() = 0;

Expand All @@ -50,7 +48,6 @@ class TermsAndConditionsProvider
*
* @param[out] outAcknowledgementsValue The bitmask of acknowledgements accepted.
* @param[out] outAcknowledgementsVersionValue The version of the accepted acknowledgements.
* @return CHIP_ERROR On success returns CHIP_NO_ERROR, otherwise returns an error code.
*/
virtual CHIP_ERROR GetAcceptance(uint16_t & outAcknowledgementsValue, uint16_t & outAcknowledgementsVersionValue) const = 0;

Expand All @@ -59,7 +56,6 @@ class TermsAndConditionsProvider
*
* @param[out] outAcknowledgementsValue The bitmask of required acknowledgements.
* @param[out] outAcknowledgementsVersionValue The version of the required acknowledgements.
* @return CHIP_ERROR On success returns CHIP_NO_ERROR, otherwise returns an error code.
*/
virtual CHIP_ERROR GetRequirements(uint16_t & outAcknowledgementsValue, uint16_t & outAcknowledgementsVersionValue) const = 0;

Expand All @@ -68,7 +64,6 @@ class TermsAndConditionsProvider
*
* @param[in] inAcknowledgementsValue The bitmask of acknowledgements that was accepted.
* @param[in] inAcknowledgementsVersionValue The version of the acknowledgements that was accepted.
* @return CHIP_ERROR On success returns CHIP_NO_ERROR, otherwise returns an error code.
*/
virtual CHIP_ERROR SetAcceptance(uint16_t inAcknowledgementsValue, uint16_t inAcknowledgementsVersionValue) = 0;
};
Expand Down
54 changes: 54 additions & 0 deletions src/system/SystemConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -808,3 +808,57 @@ struct LwIPEvent;
#ifndef CHIP_SYSTEM_CONFIG_MAX_LARGE_BUFFER_SIZE_BYTES
#define CHIP_SYSTEM_CONFIG_MAX_LARGE_BUFFER_SIZE_BYTES (64000)
#endif

/**
* @file
* Configuration settings for Terms and Conditions (TC) acknowledgements during device commissioning.
*/

/**
* @def CHIP_CONFIG_TC_REQUIRED
*
* @brief Indicates whether terms and conditions are required during commissioning.
*
* This macro defines whether the device commissioning process requires the user to acknowledge terms and conditions.
* - 1: Terms and conditions are required.
* - 0: Terms and conditions are not required.
*
* If this is set to 1, both CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS and
* CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION must be defined.
*/
#ifndef CHIP_CONFIG_TC_REQUIRED
#define CHIP_CONFIG_TC_REQUIRED (0)
#endif

#if CHIP_CONFIG_TC_REQUIRED

/**
* @def CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS
*
* @brief Configures the required terms and conditions acknowledgements bitmask.
*
* This macro defines the required terms and conditions acknowledgements bitmask. The bit-field is 16 bits long, so the possible
* value range is [0, 65535). This setting can be used to require that terms and conditions are presented to the user during
* commissioning.
*/
#ifndef CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS
#error "CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS must be defined when CHIP_CONFIG_TC_REQUIRED is enabled."
#endif

/**
* @def CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION
*
* @brief Configures the latest known version of the terms and conditions.
*
* This macro defines the version number of the latest terms and conditions. It allows the application to iterate on revisions of
* the terms and conditions. A value of 0 indicates that no specific version is required. This setting can be used to enforce
* version-specific terms and conditions acknowledgements in the application. When the set of terms and conditions needs to be
* changed, the version number should be monotonically increased. If the latest terms and conditions version is updated (most
* likely during an OTA), then this may signal to the Administrator that updated terms and conditions should be presented to the
* user.
*/
#ifndef CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION
#error "CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION must be defined when CHIP_CONFIG_TC_REQUIRED is enabled."
#endif

#endif // CHIP_CONFIG_TC_REQUIRED

0 comments on commit 6d889cf

Please sign in to comment.