10000 Add checks for OffWithEffect command parameters contraints by jmartinez-silabs · Pull Request #34396 · project-chip/connectedhomeip · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add checks for OffWithEffect command parameters contraints #34396

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading
0