Skip to content

Commit a74b4ce

Browse files
Add checks for OffWithEffect command parameters contraints
1 parent 1da085d commit a74b4ce

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/app/clusters/on-off-server/on-off-server.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ void UpdateModeBaseCurrentModeToOnMode(EndpointId endpoint)
8989

9090
#endif // MATTER_DM_PLUGIN_MODE_BASE
9191

92+
template <typename EnumType>
93+
bool isKnownEnumValue(EnumType value)
94+
{
95+
return (EnsureKnownEnumValue(value) == EnumType::kUnknownEnumValue) ? false : true;
96+
}
97+
9298
} // namespace
9399

94100
#ifdef MATTER_DM_PLUGIN_LEVEL_CONTROL
@@ -609,6 +615,30 @@ bool OnOffServer::offWithEffectCommand(app::CommandHandler * commandObj, const a
609615
chip::EndpointId endpoint = commandPath.mEndpointId;
610616
Status status = Status::Success;
611617

618+
if (isKnownEnumValue(effectId))
619+
{
620+
// Depending on effectId value, effectVariant enum type varies.
621+
// The following check validates that effectVariant value is valid in relation to the applicable enum type.
622+
// DelayedAllOffEffectVariantEnum or DyingLightEffectVariantEnum
623+
if ((effectId == EffectIdentifierEnum::kDelayedAllOff &&
624+
!isKnownEnumValue(static_cast<DelayedAllOffEffectVariantEnum>(effectVariant))) ||
625+
(effectId == EffectIdentifierEnum::kDyingLight &&
626+
!isKnownEnumValue(static_cast<DyingLightEffectVariantEnum>(effectVariant))))
627+
{
628+
status = Status::ConstraintError;
629+
}
630+
}
631+
else
632+
{
633+
status = Status::ConstraintError;
634+
}
635+
636+
if (status != Status::Success)
637+
{
638+
commandObj->AddStatus(commandPath, status);
639+
return true;
640+
}
641+
612642
if (SupportsLightingApplications(endpoint))
613643
{
614644
#ifdef MATTER_DM_PLUGIN_SCENES_MANAGEMENT

0 commit comments

Comments
 (0)