Skip to content

Commit

Permalink
Add checks for OffWithEffect command parameters contraints (#34396)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
3 people authored and pull[bot] committed Jul 27, 2024
1 parent 51186d3 commit b0fa25a
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/app/clusters/on-off-server/on-off-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ void UpdateModeBaseCurrentModeToOnMode(EndpointId endpoint)

#endif // MATTER_DM_PLUGIN_MODE_BASE

template <typename EnumType>
bool IsKnownEnumValue(EnumType value)
{
return (EnsureKnownEnumValue(value) != EnumType::kUnknownEnumValue);
}

} // namespace

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

if (effectId != EffectIdentifierEnum::kUnknownEnumValue)
{
// Depending on effectId value, effectVariant enum type varies.
// The following check validates that effectVariant value is valid in relation to the applicable enum type.
// DelayedAllOffEffectVariantEnum or DyingLightEffectVariantEnum
if (effectId == EffectIdentifierEnum::kDelayedAllOff &&
!IsKnownEnumValue(static_cast<DelayedAllOffEffectVariantEnum>(effectVariant)))
{
// The server does not support the given variant, it SHALL use the default variant.
effectVariant = to_underlying(DelayedAllOffEffectVariantEnum::kDelayedOffFastFade);
}
else if (effectId == EffectIdentifierEnum::kDyingLight &&
!IsKnownEnumValue(static_cast<DyingLightEffectVariantEnum>(effectVariant)))
{
// The server does not support the given variant, it SHALL use the default variant.
effectVariant = to_underlying(DyingLightEffectVariantEnum::kDyingLightFadeOff);
}
}
else
{
status = Status::ConstraintError;
}

if (status != Status::Success)
{
commandObj->AddStatus(commandPath, status);
return true;
}

if (SupportsLightingApplications(endpoint))
{
#ifdef MATTER_DM_PLUGIN_SCENES_MANAGEMENT
Expand Down

0 comments on commit b0fa25a

Please sign in to comment.