Skip to content

Commit c4a25e6

Browse files
jmartinez-silabsandy31415bzbarsky-apple
authored
Add checks for OffWithEffect command parameters contraints (project-chip#34396)
* Add checks for OffWithEffect command parameters contraints * Update src/app/clusters/on-off-server/on-off-server.cpp Co-authored-by: Andrei Litvin <andy314@gmail.com> * address comment * For unknownd effect variant, Default to the respective 0 value enum variant * Update src/app/clusters/on-off-server/on-off-server.cpp Co-authored-by: Boris Zbarsky <bzbarsky@apple.com> * fix up rename --------- Co-authored-by: Andrei Litvin <andy314@gmail.com> Co-authored-by: Boris Zbarsky <bzbarsky@apple.com>
1 parent 6a98248 commit c4a25e6

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

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

+35
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);
96+
}
97+
9298
} // namespace
9399

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

618+
if (effectId != EffectIdentifierEnum::kUnknownEnumValue)
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+
{
626+
// The server does not support the given variant, it SHALL use the default variant.
627+
effectVariant = to_underlying(DelayedAllOffEffectVariantEnum::kDelayedOffFastFade);
628+
}
629+
else if (effectId == EffectIdentifierEnum::kDyingLight &&
630+
!IsKnownEnumValue(static_cast<DyingLightEffectVariantEnum>(effectVariant)))
631+
{
632+
// The server does not support the given variant, it SHALL use the default variant.
633+
effectVariant = to_underlying(DyingLightEffectVariantEnum::kDyingLightFadeOff);
634+
}
635+
}
636+
else
637+
{
638+
status = Status::ConstraintError;
639+
}
640+
641+
if (status != Status::Success)
642+
{
643+
commandObj->AddStatus(commandPath, status);
644+
return true;
645+
}
646+
612647
if (SupportsLightingApplications(endpoint))
613648
{
614649
#ifdef MATTER_DM_PLUGIN_SCENES_MANAGEMENT

0 commit comments

Comments
 (0)