Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
swan-amazon committed May 7, 2024
1 parent 108c6a3 commit ecb5109
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,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 @@ -254,6 +255,23 @@ bool emberAfGeneralCommissioningClusterCommissioningCompleteCallback(
response.errorCode = CommissioningErrorEnum::kInvalidAuthentication;
ChipLogError(FailSafe, "GeneralCommissioning: Got commissioning complete in invalid security context");
}
else if (!termsAndConditionsManager.HasRequiredTermsAndConditionsBeenAcknowledged())
{
ChipLogError(AppServer, "Required terms and conditions have not been accepted");

/*
* 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);

Breadcrumb::Set(commandPath.mEndpointId, 0);
response.errorCode = CommissioningErrorEnum::kRequiredTCNotAccepted;
}
else
{
if (failSafe.NocCommandHasBeenInvoked())
Expand Down
4 changes: 4 additions & 0 deletions src/app/server/Server.h
Original file line number Diff line number Diff line change
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 @@ -357,6 +358,8 @@ class Server

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

app::TermsAndConditionsManager & GetTermsAndConditionsManager() const { return mTermsAndConditionsManager; }

TestEventTriggerDelegate * GetTestEventTriggerDelegate() { return mTestEventTriggerDelegate; }

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

bool mIsDnssdReady = false;
uint16_t mOperationalServicePort;
Expand Down
20 changes: 20 additions & 0 deletions src/app/server/TermsAndConditionsManager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "TermsAndConditionsManager.h"

CHIP_ERROR chip::app::TermsAndConditionsManager::SetTCAcknowledgements(uint16_t tcVersion, uint16_t tcUserResponse)
{
CHIP_ERROR err = CHIP_NO_ERROR;

err = ConfigurationMgr().StoreTCAcknowledgements(tcVersion, tcUserResponse);
SuccessOrExit(err);

exit:
if (err != CHIP_NO_ERROR)
{
ChipLogError(DeviceLayer, "SetTCAcknowledgements failed with error: %s", ErrorStr(err));
}
return err;
}

bool chip::app::TermsAndConditionsManager::HasRequiredTermsAndConditionsBeenAcknowledged() {
return false;
}
15 changes: 15 additions & 0 deletions src/app/server/TermsAndConditionsManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#include <stdint.h>

namespace chip {
namespace app {

class TermsAndConditionsManager {
public:
CHIP_ERROR SetTCAcknowledgements(uint16_t tcVersion, uint16_t tcUserResponse);
virtual bool HasRequiredTermsAndConditionsBeenAcknowledged() = 0;
};

}; // namespace app
}; // namespace chip
1 change: 0 additions & 1 deletion src/include/platform/DeviceControlServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class DeviceControlServer final

CHIP_ERROR PostCommissioningCompleteEvent(NodeId peerNodeId, FabricIndex accessingFabricIndex);
CHIP_ERROR SetRegulatoryConfig(uint8_t location, const CharSpan & countryCode);
CHIP_ERROR SetTCAcknowledgements(uint16_t tcVersion, uint16_t tcUserResponse);
CHIP_ERROR PostConnectedToOperationalNetworkEvent(ByteSpan networkID);
CHIP_ERROR PostCloseAllBLEConnectionsToOperationalNetworkEvent();
CHIP_ERROR PostWiFiDeviceAvailableNetworkEvent();
Expand Down

0 comments on commit ecb5109

Please sign in to comment.