Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
swan-amazon committed Aug 4, 2024
1 parent ec54446 commit 2a708b7
Show file tree
Hide file tree
Showing 15 changed files with 190 additions and 253 deletions.
13 changes: 1 addition & 12 deletions examples/chip-tool/commands/pairing/PairingCommand.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2024 Project CHIP Authors
* Copyright (c) 2020 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -129,17 +129,6 @@ CommissioningParameters PairingCommand::GetCommissioningParameters()
params.SetCountryCode(CharSpan::fromCharString(mCountryCode.Value()));
}

// mTCAcknowledgements and mTCAcknowledgementVersion are optional, but related. When one is missing, default the value to 0, to
// increase the test tools ability to test the applications.
if (mTCAcknowledgements.HasValue() || mTCAcknowledgementVersion.HasValue())
{
TermsAndConditionsAcknowledgement termsAndConditionsAcknowledgement = {
.acceptedTermsAndConditions = mTCAcknowledgements.ValueOr(0),
.acceptedTermsAndConditionsVersion = mTCAcknowledgementVersion.ValueOr(0),
};
params.SetTermsAndConditionsAcknowledgement(termsAndConditionsAcknowledgement);
}

// mTimeZoneList is an optional argument managed by TypedComplexArgument mComplex_TimeZones.
// Since optional Complex arguments are not currently supported via the <chip::Optional> class,
// we will use mTimeZoneList.data() value to determine if the argument was provided.
Expand Down
12 changes: 1 addition & 11 deletions examples/chip-tool/commands/pairing/PairingCommand.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2024 Project CHIP Authors
* Copyright (c) 2020 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -202,14 +202,6 @@ class PairingCommand : public CHIPCommand,
AddArgument("dst-offset", &mComplex_DSTOffsets,
"DSTOffset list to use when setting Time Synchronization cluster's DSTOffset attribute",
Argument::kOptional);

AddArgument("tc-acknowledgements", 0, UINT16_MAX, &mTCAcknowledgements,
"Terms and Conditions acknowledgements to use to set the General Commissioning cluster's TC "
"Acknowledgements bit-field");

AddArgument("tc-acknowledgements-version", 0, UINT16_MAX, &mTCAcknowledgementVersion,
"Terms and Conditions acknowledgement version to use to set the General Commissioning cluster's TC "
"Acknowledgement version");
}

AddArgument("timeout", 0, UINT16_MAX, &mTimeout);
Expand Down Expand Up @@ -267,8 +259,6 @@ class PairingCommand : public CHIPCommand,
chip::Optional<uint64_t> mICDMonitoredSubject;
chip::Optional<chip::app::Clusters::IcdManagement::ClientTypeEnum> mICDClientType;
chip::Optional<uint32_t> mICDStayActiveDurationMsec;
chip::Optional<uint16_t> mTCAcknowledgements;
chip::Optional<uint16_t> mTCAcknowledgementVersion;
chip::app::DataModel::List<chip::app::Clusters::TimeSynchronization::Structs::TimeZoneStruct::Type> mTimeZoneList;
TypedComplexArgument<chip::app::DataModel::List<chip::app::Clusters::TimeSynchronization::Structs::TimeZoneStruct::Type>>
mComplex_TimeZones;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ static CHIP_ERROR ReadIfSupported(Provider * const provider, CHIP_ERROR (Provide
return ReadIfSupported(provider, nonConstGetter, aEncoder);
}

class _ : public AttributeAccessInterface
class GeneralCommissioningAttrAccess : public AttributeAccessInterface
{
public:
_() : AttributeAccessInterface(Optional<EndpointId>::Missing(), GeneralCommissioning::Id) {}
GeneralCommissioningAttrAccess() : AttributeAccessInterface(Optional<EndpointId>::Missing(), GeneralCommissioning::Id) {}

CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder)
{
Expand Down Expand Up @@ -157,7 +157,9 @@ class _ : public AttributeAccessInterface
}
return CHIP_NO_ERROR;
}
} gAttributeAccessInstance;
};

GeneralCommissioningAttrAccess gAttributeAccessInstance;

} // anonymous namespace

Expand Down Expand Up @@ -279,7 +281,6 @@ bool emberAfGeneralCommissioningClusterCommissioningCompleteCallback(
if (!hasRequiredTermAccepted)
{
ChipLogProgress(AppServer, "Required terms and conditions have not been accepted");
Breadcrumb::Set(commandPath.mEndpointId, 0);
response.errorCode = (0 == termsAndConditionsAcceptedAcknowledgements)
? CommissioningErrorEnum::kTCAcknowledgementsNotReceived
: CommissioningErrorEnum::kRequiredTCNotAccepted;
Expand All @@ -288,7 +289,6 @@ bool emberAfGeneralCommissioningClusterCommissioningCompleteCallback(
else if (!hasRequiredTermVersionAccepted)
{
ChipLogProgress(AppServer, "Minimum terms and conditions version has not been accepted");
Breadcrumb::Set(commandPath.mEndpointId, 0);
response.errorCode = CommissioningErrorEnum::kTCMinVersionNotMet;
}

Expand Down Expand Up @@ -400,6 +400,9 @@ void OnPlatformEventHandler(const DeviceLayer::ChipDeviceEvent * event, intptr_t
{
// Spec says to reset Breadcrumb attribute to 0.
Breadcrumb::Set(0, 0);

// Clear terms and conditions acceptance on failsafe timer expiration
Server::GetInstance().GetEnhancedSetupFlowProvider()->ClearTermsAndConditionsAcceptance();
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/app/server/DefaultEnhancedSetupFlowProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
* limitations under the License.
*/

#include <system/SystemConfig.h>

#include "DefaultEnhancedSetupFlowProvider.h"

#include <lib/core/CHIPConfig.h>
Expand Down
33 changes: 4 additions & 29 deletions src/app/server/DefaultEnhancedSetupFlowProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@

#pragma once

#include <system/SystemConfig.h>

#include "EnhancedSetupFlowProvider.h"

#include <stdint.h>

#include <lib/core/CHIPConfig.h>
#include <lib/core/CHIPError.h>

#include "TermsAndConditionsProvider.h"
Expand All @@ -40,49 +39,25 @@ class DefaultEnhancedSetupFlowProvider : public EnhancedSetupFlowProvider
*/
CHIP_ERROR Init(TermsAndConditionsProvider * const inTermsAndConditionsProvider);

/**
* @copydoc EnhancedSetupFlowProvider::HasTermsAndConditionsRequiredAcknowledgementsBeenAccepted
*/
CHIP_ERROR HasTermsAndConditionsRequiredAcknowledgementsBeenAccepted(bool & outAccepted) const override;

/**
* @copydoc EnhancedSetupFlowProvider::HasTermsAndConditionsRequiredAcknowledgementsVersionBeenAccepted
*/
CHIP_ERROR HasTermsAndConditionsRequiredAcknowledgementsVersionBeenAccepted(bool & outAccepted) const override;

/**
* @copydoc EnhancedSetupFlowProvider::GetTermsAndConditionsRequiredAcknowledgements
*/
CHIP_ERROR GetTermsAndConditionsRequiredAcknowledgements(uint16_t & outValue) const override;

/**
* @copydoc EnhancedSetupFlowProvider::GetTermsAndConditionsRequiredAcknowledgementsVersion
*/
CHIP_ERROR GetTermsAndConditionsRequiredAcknowledgementsVersion(uint16_t & outValue) const override;

/**
* @copydoc EnhancedSetupFlowProvider::GetTermsAndConditionsAcceptedAcknowledgements
*/
CHIP_ERROR GetTermsAndConditionsAcceptedAcknowledgements(uint16_t & outValue) const override;

/**
* @copydoc EnhancedSetupFlowProvider::GetTermsAndConditionsAcceptedAcknowledgementsVersion
*/
CHIP_ERROR GetTermsAndConditionsAcceptedAcknowledgementsVersion(uint16_t & outValue) const override;

/**
* @copydoc EnhancedSetupFlowProvider::SetTermsAndConditionsAcceptance
*/
CHIP_ERROR SetTermsAndConditionsAcceptance(uint16_t aTCAcknowledgements, uint16_t inTCAcknowledgementsVersionValue) override;

/**
* @copydoc EnhancedSetupFlowProvider::ClearTermsAndConditionsAcceptance
*/
CHIP_ERROR ClearTermsAndConditionsAcceptance() override;

private:
TermsAndConditionsProvider * mTermsAndConditionsProvider; /**< TermsAndConditionsProvider instance. */
TermsAndConditionsProvider * mTermsAndConditionsProvider;
};

}; // namespace app
}; // namespace chip
} // namespace app
} // namespace chip
9 changes: 7 additions & 2 deletions src/app/server/DefaultTermsAndConditionsProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@ constexpr chip::TLV::Tag kSerializationVersionTag = chip::TLV::Contex
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

constexpr size_t kEstimatedTlvBufferSize = chip::TLV::EstimateStructOverhead(sizeof(uint8_t), // SerializationVersion
sizeof(uint16_t), // AcceptedAcknowledgements
sizeof(uint16_t) // AcceptedAcknowledgementsVersion
) *
2; // Extra space for rollback compatibility
} // namespace

CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::Init(chip::PersistentStorageDelegate * const inPersistentStorageDelegate,
uint16_t inRequiredAcknowledgementsValue,
Expand Down
19 changes: 3 additions & 16 deletions src/app/server/DefaultTermsAndConditionsProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@

#pragma once

#include <system/SystemConfig.h>

#include "TermsAndConditionsProvider.h"

#include <stdint.h>

#include <lib/core/CHIPConfig.h>
#include <lib/core/CHIPError.h>
#include <lib/core/CHIPPersistentStorageDelegate.h>

Expand All @@ -42,24 +41,12 @@ class DefaultTermsAndConditionsProvider : public TermsAndConditionsProvider
CHIP_ERROR Init(PersistentStorageDelegate * const inPersistentStorageDelegate, uint16_t inRequiredAcknowledgementsValue,
uint16_t inRequiredAcknowledgementsVersionValue);

/**
* @copydoc TermsAndConditionsProvider::ClearAcceptance
*/
CHIP_ERROR ClearAcceptance() override;

/**
* @copydoc TermsAndConditionsProvider::GetAcceptance
*/
CHIP_ERROR GetAcceptance(uint16_t & outAcknowledgementsValue, uint16_t & outAcknowledgementsVersionValue) const override;

/**
* @copydoc TermsAndConditionsProvider::GetRequirements
*/
CHIP_ERROR GetRequirements(uint16_t & outAcknowledgementsValue, uint16_t & outAcknowledgementsVersionValue) const override;

/**
* @copydoc TermsAndConditionsProvider::SetAcceptance
*/
CHIP_ERROR SetAcceptance(uint16_t inAcknowledgementsValue, uint16_t inAcknowledgementsVersionValue) override;

private:
Expand All @@ -68,5 +55,5 @@ class DefaultTermsAndConditionsProvider : public TermsAndConditionsProvider
uint16_t mRequiredAcknowledgementsVersionValue;
};

}; // namespace app
}; // namespace chip
} // namespace app
} // namespace chip
30 changes: 5 additions & 25 deletions src/app/server/EnhancedSetupFlowProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,85 +18,65 @@

#pragma once

#include <system/SystemConfig.h>

#include <stdint.h>

#include <lib/core/CHIPConfig.h>
#include <lib/core/CHIPError.h>

namespace chip {
namespace app {

/**
* @brief Feature state access layer for the EnhancedSetupFlowProvider.
*
* This class provides access to the state of the Enhanced Setup Flow feature.
*/
class EnhancedSetupFlowProvider
{
public:
/**
* @brief Destructor.
*/
virtual ~EnhancedSetupFlowProvider() = default;

/**
* @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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
virtual CHIP_ERROR GetTermsAndConditionsAcceptedAcknowledgementsVersion(uint16_t & outValue) const = 0;

/**
* @brief Sets the acceptance status of the terms and conditions.
*
* @param[in] inTCAcknowledgements The acknowledgements to accept.
* @param[in] inTCAcknowledgementsVersionValue The version of the acknowledgements to accept.
*/
virtual CHIP_ERROR SetTermsAndConditionsAcceptance(uint16_t inTCAcknowledgementsValue,
uint16_t inTCAcknowledgementsVersionValue) = 0;

/**
* @brief Clears the acceptance status of the terms and conditions.
*
* Reset the terms and conditions acceptance. The terms and conditions should be cleared on factory reset or if failure occurs
* during a failsafe context.
*/
virtual CHIP_ERROR ClearTermsAndConditionsAcceptance() = 0;
};

}; // namespace app
}; // namespace chip
} // namespace app
} // namespace chip
1 change: 1 addition & 0 deletions src/app/server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,7 @@ void Server::ScheduleFactoryReset()
GetInstance().GetFabricTable().DeleteAllFabrics();
PlatformMgr().HandleServerShuttingDown();
ConfigurationMgr().InitiateFactoryReset();
// Clear accepted terms and conditions
});
}

Expand Down
10 changes: 3 additions & 7 deletions src/app/server/TermsAndConditionsProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@

#pragma once

#include <system/SystemConfig.h>

#include <stdint.h>

#include <lib/core/CHIPConfig.h>
#include <lib/core/CHIPError.h>

namespace chip {
Expand All @@ -33,9 +32,6 @@ namespace app {
class TermsAndConditionsProvider
{
public:
/**
* @brief Destructor.
*/
virtual ~TermsAndConditionsProvider() = default;

/**
Expand Down Expand Up @@ -68,5 +64,5 @@ class TermsAndConditionsProvider
virtual CHIP_ERROR SetAcceptance(uint16_t inAcknowledgementsValue, uint16_t inAcknowledgementsVersionValue) = 0;
};

}; // namespace app
}; // namespace chip
} // namespace app
} // namespace chip
Loading

0 comments on commit 2a708b7

Please sign in to comment.