Skip to content

Commit

Permalink
Flag SetTCAcknowledgements command
Browse files Browse the repository at this point in the history
  • Loading branch information
yufengwangca committed Dec 18, 2024
1 parent 9ba0d4b commit 90de8a1
Showing 1 changed file with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ class GeneralCommissioningGlobalInstance : public AttributeAccessInterface, publ
void HandleArmFailSafe(HandlerContext & ctx, const Commands::ArmFailSafe::DecodableType & commandData);
void HandleCommissioningComplete(HandlerContext & ctx, const Commands::CommissioningComplete::DecodableType & commandData);
void HandleSetRegulatoryConfig(HandlerContext & ctx, const Commands::SetRegulatoryConfig::DecodableType & commandData);
#if CHIP_CONFIG_TERMS_AND_CONDITIONS_REQUIRED
void HandleSetTCAcknowledgements(HandlerContext & ctx, const Commands::SetTCAcknowledgements::DecodableType & commandData);
#endif
};

GeneralCommissioningGlobalInstance gGeneralCommissioningInstance;
Expand Down Expand Up @@ -194,16 +196,16 @@ CHIP_ERROR GeneralCommissioningGlobalInstance::ReadIfSupported(CHIP_ERROR (Confi

CHIP_ERROR GeneralCommissioningGlobalInstance::ReadBasicCommissioningInfo(AttributeValueEncoder & aEncoder)
{
BasicCommissioningInfo::TypeInfo::Type basicCommissioningInfo;
BasicCommissioningInfo::TypeInfo::Type info;

// 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;
info.failSafeExpiryLengthSeconds = CHIP_DEVICE_CONFIG_FAILSAFE_EXPIRY_LENGTH_SEC;
info.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);
return aEncoder.Encode(info);
}

CHIP_ERROR GeneralCommissioningGlobalInstance::ReadSupportsConcurrentConnection(AttributeValueEncoder & aEncoder)
Expand Down Expand Up @@ -238,11 +240,13 @@ void GeneralCommissioningGlobalInstance::InvokeCommand(HandlerContext & handlerC
[this](HandlerContext & ctx, const auto & commandData) { HandleSetRegulatoryConfig(ctx, commandData); });
break;

#if CHIP_CONFIG_TERMS_AND_CONDITIONS_REQUIRED
case Commands::SetTCAcknowledgements::Id:
CommandHandlerInterface::HandleCommand<Commands::SetTCAcknowledgements::DecodableType>(
handlerContext,
[this](HandlerContext & ctx, const auto & commandData) { HandleSetTCAcknowledgements(ctx, commandData); });
break;
#endif
}
}

Expand Down Expand Up @@ -320,9 +324,6 @@ void GeneralCommissioningGlobalInstance::HandleArmFailSafe(HandlerContext & ctx,
auto & failSafeContext = Server::GetInstance().GetFailSafeContext();
Commands::ArmFailSafeResponse::Type response;

ChipLogProgress(FailSafe, "GeneralCommissioning: Received ArmFailSafe (%us)",
static_cast<unsigned>(commandData.expiryLengthSeconds));

/*
* If the fail-safe timer is not fully disarmed, don't allow arming a new fail-safe.
* If the fail-safe timer was not currently armed, then the fail-safe timer SHALL be armed.
Expand Down Expand Up @@ -530,12 +531,12 @@ void GeneralCommissioningGlobalInstance::HandleSetRegulatoryConfig(HandlerContex
ctx.mCommandHandler.AddResponse(ctx.mRequestPath, response);
}

#if CHIP_CONFIG_TERMS_AND_CONDITIONS_REQUIRED
void GeneralCommissioningGlobalInstance::HandleSetTCAcknowledgements(
HandlerContext & ctx, const Commands::SetTCAcknowledgements::DecodableType & commandData)
{
MATTER_TRACE_SCOPE("SetTCAcknowledgements", "GeneralCommissioning");

#if CHIP_CONFIG_TERMS_AND_CONDITIONS_REQUIRED
auto & failSafeContext = Server::GetInstance().GetFailSafeContext();
TermsAndConditionsProvider * tcProvider = TermsAndConditionsManager::GetInstance();

Expand Down Expand Up @@ -594,8 +595,8 @@ void GeneralCommissioningGlobalInstance::HandleSetTCAcknowledgements(

response.errorCode = CommissioningErrorEnum::kOk;
ctx.mCommandHandler.AddResponse(ctx.mRequestPath, response);
#endif // CHIP_CONFIG_TERMS_AND_CONDITIONS_REQUIRED
}
#endif // CHIP_CONFIG_TERMS_AND_CONDITIONS_REQUIRED

void OnPlatformEventHandler(const DeviceLayer::ChipDeviceEvent * event, intptr_t)
{
Expand Down Expand Up @@ -628,23 +629,23 @@ class GeneralCommissioningFabricTableDelegate : public chip::FabricTable::Delega
// Gets called when a fabric is deleted
void OnFabricRemoved(const FabricTable & fabricTable, FabricIndex fabricIndex) override
{
#if CHIP_CONFIG_TERMS_AND_CONDITIONS_REQUIRED
// If the FabricIndex matches the last remaining entry in the Fabrics list, then the device SHALL delete all Matter
// related data on the node which was created since it was commissioned.
if (Server::GetInstance().GetFabricTable().FabricCount() == 0)
{
ChipLogProgress(Zcl, "general-commissioning-server: Last Fabric index 0x%x was removed",
static_cast<unsigned>(fabricIndex));

#if CHIP_CONFIG_TERMS_AND_CONDITIONS_REQUIRED
TermsAndConditionsProvider * tcProvider = TermsAndConditionsManager::GetInstance();
TermsAndConditionsState initialState, updatedState;
VerifyOrReturn(nullptr != tcProvider);
VerifyOrReturn(CHIP_NO_ERROR == GetTermsAndConditionsAttributeState(tcProvider, initialState));
VerifyOrReturn(CHIP_NO_ERROR == tcProvider->ResetAcceptance());
VerifyOrReturn(CHIP_NO_ERROR == GetTermsAndConditionsAttributeState(tcProvider, updatedState));
NotifyTermsAndConditionsAttributeChangeIfRequired(initialState, updatedState);
#endif // CHIP_CONFIG_TERMS_AND_CONDITIONS_REQUIRED
}
#endif // CHIP_CONFIG_TERMS_AND_CONDITIONS_REQUIRED
}
};

Expand Down

0 comments on commit 90de8a1

Please sign in to comment.