Skip to content

Commit

Permalink
Add support for terms and conditions check and enhanced setup flow
Browse files Browse the repository at this point in the history
This commit adds support for terms and conditions (TC) check and
enhances the setup flow as part of the Connected Home over IP (CHIP)
Specification 1.4.

Changes include:

- Extended support for terms and conditions check and enhanced setup
  flow feature as part of the connectedhomeip spec 1.4.
- Added functionality to retrieve and store Terms and Conditions (TC)
  information, including accepted version, minimum required version,
  acknowledgements, and required acknowledgements.
- Implemented methods in `TermsAndConditionsManager` to handle TC
  versioning and acknowledgements.
- Updated `GeneralCommissioningAttrAccess` to include support for
  reading TC-related attributes.
- Added callback functions in `emberAfGeneralCommissioningCluster` to
  handle TC acknowledgements during commissioning.
- Integrated `TermsAndConditionsManager` into the server context for
  managing TC-related information.
- Enhanced error handling and logging for TC-related operations.
- Adjusted build configuration to include default values for TC
  versioning and acknowledgements.
- Expanded configuration management in `ConfigurationManagerImpl` to
  handle TC-related configuration keys.
- Updated `PosixConfig` to include configuration keys for TC-related
  information.
- Implemented default values for TC versioning and acknowledgements in
  `ConfigurationManagerImpl`.
  • Loading branch information
swan-amazon committed May 7, 2024
1 parent 5a7421f commit 322f3c1
Show file tree
Hide file tree
Showing 14 changed files with 454 additions and 72 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright (c) 2021 Project CHIP Authors
* Copyright (c) 2021-2024 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -66,7 +66,8 @@ class GeneralCommissioningAttrAccess : public AttributeAccessInterface
CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override;

private:
CHIP_ERROR ReadIfSupported(CHIP_ERROR (ConfigurationManager::*getter)(uint8_t &), AttributeValueEncoder & aEncoder);
template <typename T>
CHIP_ERROR ReadIfSupported(CHIP_ERROR (ConfigurationManager::*getter)(T &), AttributeValueEncoder & aEncoder);
CHIP_ERROR ReadBasicCommissioningInfo(AttributeValueEncoder & aEncoder);
CHIP_ERROR ReadSupportsConcurrentConnection(AttributeValueEncoder & aEncoder);
};
Expand Down Expand Up @@ -95,17 +96,29 @@ CHIP_ERROR GeneralCommissioningAttrAccess::Read(const ConcreteReadAttributePath
case SupportsConcurrentConnection::Id: {
return ReadSupportsConcurrentConnection(aEncoder);
}
default: {
break;
case TCAcceptedVersion::Id: {
return ReadIfSupported(&ConfigurationManager::GetTCAcceptedVersion, aEncoder);
}
case TCMinRequiredVersion::Id: {
return ReadIfSupported(&ConfigurationManager::GetTCMinRequiredVersion, aEncoder);
}
case TCAcknowledgements::Id: {
return ReadIfSupported(&ConfigurationManager::GetTCAcknowledgements, aEncoder);
}
case TCAcknowledgementsRequired::Id: {
return ReadIfSupported(&ConfigurationManager::GetTCAcknowledgementsRequired, aEncoder);
}
default:
break;
}
return CHIP_NO_ERROR;
}

CHIP_ERROR GeneralCommissioningAttrAccess::ReadIfSupported(CHIP_ERROR (ConfigurationManager::*getter)(uint8_t &),
template <typename T>
CHIP_ERROR GeneralCommissioningAttrAccess::ReadIfSupported(CHIP_ERROR (ConfigurationManager::*getter)(T &),
AttributeValueEncoder & aEncoder)
{
uint8_t data;
T data;
CHIP_ERROR err = (DeviceLayer::ConfigurationMgr().*getter)(data);
if (err == CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE)
{
Expand Down Expand Up @@ -214,9 +227,10 @@ bool emberAfGeneralCommissioningClusterCommissioningCompleteCallback(
{
MATTER_TRACE_SCOPE("CommissioningComplete", "GeneralCommissioning");

DeviceControlServer * devCtrl = &DeviceLayer::DeviceControlServer::DeviceControlSvr();
auto & failSafe = Server::GetInstance().GetFailSafeContext();
auto & fabricTable = Server::GetInstance().GetFabricTable();
DeviceControlServer * devCtrl = &DeviceLayer::DeviceControlServer::DeviceControlSvr();
auto & failSafe = Server::GetInstance().GetFailSafeContext();
auto & fabricTable = Server::GetInstance().GetFabricTable();
auto & termsAndConditionsManager = Server::GetInstance().GetTermsAndConditionsManager();

ChipLogProgress(FailSafe, "GeneralCommissioning: Received CommissioningComplete");

Expand All @@ -239,34 +253,58 @@ bool emberAfGeneralCommissioningClusterCommissioningCompleteCallback(
}
else
{
if (failSafe.NocCommandHasBeenInvoked())
CHIP_ERROR err;

// Fetch the terms and conditions acknowledgements for verification
uint16_t tcAcceptedVersion = 0U, tcMinRequiredVersion = 0U, tcAcknowledgements = 0U, tcAcknowledgementsRequired = 0U;

err = termsAndConditionsManager.GetTCAcceptedVersion(tcAcceptedVersion);
CheckSuccess(err, Failure);

err = termsAndConditionsManager.GetTCMinRequiredVersion(tcMinRequiredVersion);
CheckSuccess(err, Failure);

err = termsAndConditionsManager.GetTCAcknowledgements(tcAcknowledgements);
CheckSuccess(err, Failure);

err = termsAndConditionsManager.GetTCAcknowledgementsRequired(tcAcknowledgementsRequired);
CheckSuccess(err, Failure);

if (tcAcknowledgementsRequired != (tcAcknowledgementsRequired & tcAcknowledgements))
{
CHIP_ERROR err = fabricTable.CommitPendingFabricData();
if (err != CHIP_NO_ERROR)
{
// No need to revert on error: CommitPendingFabricData always reverts if not fully successful.
ChipLogError(FailSafe, "GeneralCommissioning: Failed to commit pending fabric data: %" CHIP_ERROR_FORMAT,
err.Format());
}
else
ChipLogError(AppServer, "Required terms and conditions have not been accepted");
Breadcrumb::Set(commandPath.mEndpointId, 0);
response.errorCode = CommissioningErrorEnum::kRequiredTCNotAccepted;
}

else if (tcAcceptedVersion < tcMinRequiredVersion)
{
ChipLogError(AppServer, "Minimium terms and conditions version has not been accepted");
Breadcrumb::Set(commandPath.mEndpointId, 0);
response.errorCode = CommissioningErrorEnum::kTCMinVersionNotMet;
}

else
{
if (failSafe.NocCommandHasBeenInvoked())
{
err = fabricTable.CommitPendingFabricData();
CheckSuccess(err, Failure);
ChipLogProgress(FailSafe, "GeneralCommissioning: Successfully commited pending fabric data");
}
CheckSuccess(err, Failure);
}

/*
* 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();
CheckSuccess(
devCtrl->PostCommissioningCompleteEvent(handle->AsSecureSession()->GetPeerNodeId(), handle->GetFabricIndex()),
Failure);
/*
* 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;
}
}
}

Expand Down Expand Up @@ -328,6 +366,22 @@ bool emberAfGeneralCommissioningClusterSetRegulatoryConfigCallback(app::CommandH
return true;
}

bool emberAfGeneralCommissioningClusterSetTCAcknowledgementsCallback(
chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath,
const chip::app::Clusters::GeneralCommissioning::Commands::SetTCAcknowledgements::DecodableType & commandData)
{
MATTER_TRACE_SCOPE("SetTCAcknowledgements", "GeneralCommissioning");
auto & termsAndConditionsManager = Server::GetInstance().GetTermsAndConditionsManager();

Commands::SetTCAcknowledgementsResponse::Type response;

CheckSuccess(termsAndConditionsManager.SetTCAcknowledgements(commandData.TCVersion, commandData.TCUserResponse), Failure);
response.errorCode = CommissioningErrorEnum::kOk;

commandObj->AddResponse(commandPath, response);
return true;
}

namespace {
void OnPlatformEventHandler(const DeviceLayer::ChipDeviceEvent * event, intptr_t arg)
{
Expand Down
4 changes: 3 additions & 1 deletion src/app/server/BUILD.gn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2020 Project CHIP Authors
# Copyright (c) 2020-2024 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -44,6 +44,8 @@ static_library("server") {
"OnboardingCodesUtil.h",
"Server.cpp",
"Server.h",
"TermsAndConditionsManager.cpp",
"TermsAndConditionsManager.h",
]

public_configs = [ ":server_config" ]
Expand Down
109 changes: 88 additions & 21 deletions src/app/server/Server.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (c) 2020 Project CHIP Authors
* Copyright (c) 2020-2024 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -33,6 +33,7 @@
#include <app/server/AppDelegate.h>
#include <app/server/CommissioningWindowManager.h>
#include <app/server/DefaultAclStorage.h>
#include <app/server/TermsAndConditionsManager.h>
#include <credentials/CertificateValidityPolicy.h>
#include <credentials/FabricTable.h>
#include <credentials/GroupDataProvider.h>
Expand Down Expand Up @@ -329,46 +330,108 @@ class Server
*/
void RejoinExistingMulticastGroups();

FabricTable & GetFabricTable() { return mFabrics; }
FabricTable & GetFabricTable()
{
return mFabrics;
}

CASESessionManager * GetCASESessionManager() { return &mCASESessionManager; }
CASESessionManager * GetCASESessionManager()
{
return &mCASESessionManager;
}

Messaging::ExchangeManager & GetExchangeManager() { return mExchangeMgr; }
Messaging::ExchangeManager & GetExchangeManager()
{
return mExchangeMgr;
}

SessionManager & GetSecureSessionManager() { return mSessions; }
SessionManager & GetSecureSessionManager()
{
return mSessions;
}

SessionResumptionStorage * GetSessionResumptionStorage() { return mSessionResumptionStorage; }
SessionResumptionStorage * GetSessionResumptionStorage()
{
return mSessionResumptionStorage;
}

app::SubscriptionResumptionStorage * GetSubscriptionResumptionStorage() { return mSubscriptionResumptionStorage; }
app::SubscriptionResumptionStorage * GetSubscriptionResumptionStorage()
{
return mSubscriptionResumptionStorage;
}

TransportMgrBase & GetTransportManager() { return mTransports; }
TransportMgrBase & GetTransportManager()
{
return mTransports;
}

Credentials::GroupDataProvider * GetGroupDataProvider() { return mGroupsProvider; }
Credentials::GroupDataProvider * GetGroupDataProvider()
{
return mGroupsProvider;
}

Crypto::SessionKeystore * GetSessionKeystore() const { return mSessionKeystore; }
Crypto::SessionKeystore * GetSessionKeystore() const
{
return mSessionKeystore;
}

#if CONFIG_NETWORK_LAYER_BLE
Ble::BleLayer * GetBleLayerObject() { return mBleLayer; }
Ble::BleLayer * GetBleLayerObject()
{
return mBleLayer;
}
#endif

CommissioningWindowManager & GetCommissioningWindowManager() { return mCommissioningWindowManager; }
CommissioningWindowManager & GetCommissioningWindowManager()
{
return mCommissioningWindowManager;
}

PersistentStorageDelegate & GetPersistentStorage() { return *mDeviceStorage; }
PersistentStorageDelegate & GetPersistentStorage()
{
return *mDeviceStorage;
}

app::FailSafeContext & GetFailSafeContext() { return mFailSafeContext; }
app::FailSafeContext & GetFailSafeContext()
{
return mFailSafeContext;
}

TestEventTriggerDelegate * GetTestEventTriggerDelegate() { return mTestEventTriggerDelegate; }
app::TermsAndConditionsManager & GetTermsAndConditionsManager()
{
return mTermsAndConditionsManager;
}

Crypto::OperationalKeystore * GetOperationalKeystore() { return mOperationalKeystore; }
TestEventTriggerDelegate * GetTestEventTriggerDelegate()
{
return mTestEventTriggerDelegate;
}

Credentials::OperationalCertificateStore * GetOpCertStore() { return mOpCertStore; }
Crypto::OperationalKeystore * GetOperationalKeystore()
{
return mOperationalKeystore;
}

app::DefaultAttributePersistenceProvider & GetDefaultAttributePersister() { return mAttributePersister; }
Credentials::OperationalCertificateStore * GetOpCertStore()
{
return mOpCertStore;
}

app::reporting::ReportScheduler * GetReportScheduler() { return mReportScheduler; }
app::DefaultAttributePersistenceProvider & GetDefaultAttributePersister()
{
return mAttributePersister;
}

app::reporting::ReportScheduler * GetReportScheduler()
{
return mReportScheduler;
}

#if CHIP_CONFIG_ENABLE_ICD_SERVER
app::ICDManager & GetICDManager() { return mICDManager; }
app::ICDManager & GetICDManager()
{
return mICDManager;
}
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER

/**
Expand All @@ -386,7 +449,10 @@ class Server
return System::SystemClock().GetMonotonicMicroseconds64() - mInitTimestamp;
}

static Server & GetInstance() { return sServer; }
static Server & GetInstance()
{
return sServer;
}

private:
Server() {}
Expand Down Expand Up @@ -636,6 +702,7 @@ class Server
Crypto::OperationalKeystore * mOperationalKeystore;
Credentials::OperationalCertificateStore * mOpCertStore;
app::FailSafeContext mFailSafeContext;
app::TermsAndConditionsManager mTermsAndConditionsManager;

bool mIsDnssdReady = false;
uint16_t mOperationalServicePort;
Expand Down
Loading

0 comments on commit 322f3c1

Please sign in to comment.