Skip to content
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

[IM] Encode error status code during command dispatch. #5943

Merged
merged 2 commits into from
Apr 14, 2021
Merged
Show file tree
Hide file tree
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
2,011 changes: 1,118 additions & 893 deletions examples/all-clusters-app/all-clusters-common/gen/IMClusterCommandHandler.cpp

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,8 @@
{ 0x0000, ZAP_TYPE(ARRAY), 254, 0, ZAP_LONG_DEFAULTS_INDEX(0) }, /* Descriptor (server): device list */ \
{ 0x0001, ZAP_TYPE(ARRAY), 254, 0, ZAP_LONG_DEFAULTS_INDEX(254) }, /* Descriptor (server): server list */ \
{ 0x0002, ZAP_TYPE(ARRAY), 254, 0, ZAP_LONG_DEFAULTS_INDEX(508) }, /* Descriptor (server): client list */ \
{ 0x0003, ZAP_TYPE(ARRAY), 254, 0, ZAP_LONG_DEFAULTS_INDEX(762) }, /* Descriptor (server): parts list */ \
{ 0xFFFD, ZAP_TYPE(INT16U), 2, 0, ZAP_SIMPLE_DEFAULT(0x0001) }, /* Descriptor (server): cluster revision */ \
{ 0x0003, ZAP_TYPE(ARRAY), 254, 0, ZAP_LONG_DEFAULTS_INDEX(762) }, /* Descriptor (server): parts list */ \
{ 0xFFFD, ZAP_TYPE(INT16U), 2, ZAP_ATTRIBUTE_MASK(SINGLETON), \
ZAP_SIMPLE_DEFAULT(3) }, /* Basic (server): cluster revision */ \
{ 0x0000, ZAP_TYPE(INT16U), 2, ZAP_ATTRIBUTE_MASK(SINGLETON), \
Expand Down
486 changes: 269 additions & 217 deletions examples/bridge-app/bridge-common/gen/IMClusterCommandHandler.cpp

Large diffs are not rendered by default.

1,164 changes: 653 additions & 511 deletions examples/chip-tool/gen/IMClusterCommandHandler.cpp

Large diffs are not rendered by default.

486 changes: 269 additions & 217 deletions examples/lighting-app/lighting-common/gen/IMClusterCommandHandler.cpp

Large diffs are not rendered by default.

284 changes: 157 additions & 127 deletions examples/lock-app/lock-common/gen/IMClusterCommandHandler.cpp

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1,907 changes: 1,062 additions & 845 deletions examples/tv-app/tv-common/gen/IMClusterCommandHandler.cpp

Large diffs are not rendered by default.

88 changes: 51 additions & 37 deletions examples/window-app/common/gen/IMClusterCommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ namespace clusters {

namespace WindowCovering {

void DispatchServerCommand(app::Command * command, CommandId commandId, EndpointId endpointId, TLV::TLVReader & dataTlv)
void DispatchServerCommand(app::Command * apCommandObj, CommandId aCommandId, EndpointId aEndpointId, TLV::TLVReader & aDataTlv)
{
{
switch (commandId)
switch (aCommandId)
{
case ZCL_WINDOW_COVERING_DOWN_CLOSE_COMMAND_ID: {

Expand All @@ -62,18 +62,18 @@ void DispatchServerCommand(app::Command * command, CommandId commandId, Endpoint
bool percentageLiftValueExists = false;
uint32_t validArgumentCount = 0;

while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR)
{
switch (TLV::TagNumFromTag(dataTlv.GetTag()))
switch (TLV::TagNumFromTag(aDataTlv.GetTag()))
{
case 0:
if (percentageLiftValueExists)
{
ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(dataTlv.GetTag()));
ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag()));
TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT;
break;
}
TLVUnpackError = dataTlv.Get(percentageLiftValue);
TLVUnpackError = aDataTlv.Get(percentageLiftValue);
if (CHIP_NO_ERROR == TLVUnpackError)
{
percentageLiftValueExists = true;
Expand All @@ -88,7 +88,7 @@ void DispatchServerCommand(app::Command * command, CommandId commandId, Endpoint
if (TLVUnpackError != CHIP_NO_ERROR)
{
ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
TLV::TagNumFromTag(dataTlv.GetTag()), TLVUnpackError);
TLV::TagNumFromTag(aDataTlv.GetTag()), TLVUnpackError);
break;
}
}
Expand All @@ -109,10 +109,13 @@ void DispatchServerCommand(app::Command * command, CommandId commandId, Endpoint
// TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
emberAfWindowCoveringClusterWindowCoveringGoToLiftPercentageCallback(percentageLiftValue);
}
else if (1 != validArgumentCount)
else
{
ChipLogProgress(Zcl, "Missing command arguments in TLV data, command requires %d, given %" PRIu32, 1,
validArgumentCount);
apCommandObj->AddStatusCode(nullptr, Protocols::SecureChannel::GeneralStatusCode::kBadRequest,
Protocols::SecureChannel::Id, Protocols::SecureChannel::kProtocolCodeGeneralFailure);
ChipLogProgress(
Zcl, "Failed to dispatch command, %d/%" PRIu32 " arguments parsed, TLVError=%" PRIu32 ", UnpackError=%" PRIu32,
1, validArgumentCount, TLVError, TLVUnpackError);
}
break;
}
Expand All @@ -126,18 +129,18 @@ void DispatchServerCommand(app::Command * command, CommandId commandId, Endpoint
bool liftValueExists = false;
uint32_t validArgumentCount = 0;

while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR)
{
switch (TLV::TagNumFromTag(dataTlv.GetTag()))
switch (TLV::TagNumFromTag(aDataTlv.GetTag()))
{
case 0:
if (liftValueExists)
{
ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(dataTlv.GetTag()));
ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag()));
TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT;
break;
}
TLVUnpackError = dataTlv.Get(liftValue);
TLVUnpackError = aDataTlv.Get(liftValue);
if (CHIP_NO_ERROR == TLVUnpackError)
{
liftValueExists = true;
Expand All @@ -152,7 +155,7 @@ void DispatchServerCommand(app::Command * command, CommandId commandId, Endpoint
if (TLVUnpackError != CHIP_NO_ERROR)
{
ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
TLV::TagNumFromTag(dataTlv.GetTag()), TLVUnpackError);
TLV::TagNumFromTag(aDataTlv.GetTag()), TLVUnpackError);
break;
}
}
Expand All @@ -173,10 +176,13 @@ void DispatchServerCommand(app::Command * command, CommandId commandId, Endpoint
// TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
emberAfWindowCoveringClusterWindowCoveringGoToLiftValueCallback(liftValue);
}
else if (1 != validArgumentCount)
else
{
ChipLogProgress(Zcl, "Missing command arguments in TLV data, command requires %d, given %" PRIu32, 1,
validArgumentCount);
apCommandObj->AddStatusCode(nullptr, Protocols::SecureChannel::GeneralStatusCode::kBadRequest,
Protocols::SecureChannel::Id, Protocols::SecureChannel::kProtocolCodeGeneralFailure);
ChipLogProgress(
Zcl, "Failed to dispatch command, %d/%" PRIu32 " arguments parsed, TLVError=%" PRIu32 ", UnpackError=%" PRIu32,
1, validArgumentCount, TLVError, TLVUnpackError);
}
break;
}
Expand All @@ -190,18 +196,18 @@ void DispatchServerCommand(app::Command * command, CommandId commandId, Endpoint
bool percentageTiltValueExists = false;
uint32_t validArgumentCount = 0;

while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR)
{
switch (TLV::TagNumFromTag(dataTlv.GetTag()))
switch (TLV::TagNumFromTag(aDataTlv.GetTag()))
{
case 0:
if (percentageTiltValueExists)
{
ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(dataTlv.GetTag()));
ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag()));
TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT;
break;
}
TLVUnpackError = dataTlv.Get(percentageTiltValue);
TLVUnpackError = aDataTlv.Get(percentageTiltValue);
if (CHIP_NO_ERROR == TLVUnpackError)
{
percentageTiltValueExists = true;
Expand All @@ -216,7 +222,7 @@ void DispatchServerCommand(app::Command * command, CommandId commandId, Endpoint
if (TLVUnpackError != CHIP_NO_ERROR)
{
ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
TLV::TagNumFromTag(dataTlv.GetTag()), TLVUnpackError);
TLV::TagNumFromTag(aDataTlv.GetTag()), TLVUnpackError);
break;
}
}
Expand All @@ -237,10 +243,13 @@ void DispatchServerCommand(app::Command * command, CommandId commandId, Endpoint
// TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
emberAfWindowCoveringClusterWindowCoveringGoToTiltPercentageCallback(percentageTiltValue);
}
else if (1 != validArgumentCount)
else
{
ChipLogProgress(Zcl, "Missing command arguments in TLV data, command requires %d, given %" PRIu32, 1,
validArgumentCount);
apCommandObj->AddStatusCode(nullptr, Protocols::SecureChannel::GeneralStatusCode::kBadRequest,
Protocols::SecureChannel::Id, Protocols::SecureChannel::kProtocolCodeGeneralFailure);
ChipLogProgress(
Zcl, "Failed to dispatch command, %d/%" PRIu32 " arguments parsed, TLVError=%" PRIu32 ", UnpackError=%" PRIu32,
1, validArgumentCount, TLVError, TLVUnpackError);
}
break;
}
Expand All @@ -254,18 +263,18 @@ void DispatchServerCommand(app::Command * command, CommandId commandId, Endpoint
bool tiltValueExists = false;
uint32_t validArgumentCount = 0;

while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR)
{
switch (TLV::TagNumFromTag(dataTlv.GetTag()))
switch (TLV::TagNumFromTag(aDataTlv.GetTag()))
{
case 0:
if (tiltValueExists)
{
ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(dataTlv.GetTag()));
ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag()));
TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT;
break;
}
TLVUnpackError = dataTlv.Get(tiltValue);
TLVUnpackError = aDataTlv.Get(tiltValue);
if (CHIP_NO_ERROR == TLVUnpackError)
{
tiltValueExists = true;
Expand All @@ -280,7 +289,7 @@ void DispatchServerCommand(app::Command * command, CommandId commandId, Endpoint
if (TLVUnpackError != CHIP_NO_ERROR)
{
ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
TLV::TagNumFromTag(dataTlv.GetTag()), TLVUnpackError);
TLV::TagNumFromTag(aDataTlv.GetTag()), TLVUnpackError);
break;
}
}
Expand All @@ -301,10 +310,13 @@ void DispatchServerCommand(app::Command * command, CommandId commandId, Endpoint
// TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
emberAfWindowCoveringClusterWindowCoveringGoToTiltValueCallback(tiltValue);
}
else if (1 != validArgumentCount)
else
{
ChipLogProgress(Zcl, "Missing command arguments in TLV data, command requires %d, given %" PRIu32, 1,
validArgumentCount);
apCommandObj->AddStatusCode(nullptr, Protocols::SecureChannel::GeneralStatusCode::kBadRequest,
Protocols::SecureChannel::Id, Protocols::SecureChannel::kProtocolCodeGeneralFailure);
ChipLogProgress(
Zcl, "Failed to dispatch command, %d/%" PRIu32 " arguments parsed, TLVError=%" PRIu32 ", UnpackError=%" PRIu32,
1, validArgumentCount, TLVError, TLVUnpackError);
}
break;
}
Expand All @@ -322,8 +334,9 @@ void DispatchServerCommand(app::Command * command, CommandId commandId, Endpoint
}
default: {
// Unrecognized command ID, error status will apply.
// TODO: Encode response for command not found
ChipLogError(Zcl, "Unknown command %" PRIx16 " for cluster %" PRIx16, commandId, ZCL_WINDOW_COVERING_CLUSTER_ID);
apCommandObj->AddStatusCode(nullptr, Protocols::SecureChannel::GeneralStatusCode::kNotFound,
Protocols::SecureChannel::Id, Protocols::SecureChannel::kProtocolCodeGeneralFailure);
ChipLogError(Zcl, "Unknown command %" PRIx16 " for cluster %" PRIx16, aCommandId, ZCL_WINDOW_COVERING_CLUSTER_ID);
break;
}
}
Expand All @@ -347,7 +360,8 @@ void DispatchSingleClusterCommand(chip::ClusterId aClusterId, chip::CommandId aC
break;
default:
// Unrecognized cluster ID, error status will apply.
// TODO: Encode response for Cluster not found
apCommandObj->AddStatusCode(nullptr, Protocols::SecureChannel::GeneralStatusCode::kNotFound, Protocols::SecureChannel::Id,
Protocols::SecureChannel::kProtocolCodeGeneralFailure);
ChipLogError(Zcl, "Unknown cluster %" PRIx16, aClusterId);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,32 @@ bool {{asSymbol label}}Exists = false;
{{/zcl_command_arguments}}
uint32_t validArgumentCount = 0;

while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR)
{
switch (TLV::TagNumFromTag(dataTlv.GetTag()))
switch (TLV::TagNumFromTag(aDataTlv.GetTag()))
{
{{#zcl_command_arguments}}
case {{index}}:
if ({{asSymbol label}}Exists)
{
ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(dataTlv.GetTag()));
ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag()));
TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT;
break;
}
{{#if (isOctetString type)}}
{
const uint8_t * data = nullptr;
TLVUnpackError = dataTlv.GetDataPtr(data);
{{asSymbol label}} = chip::ByteSpan(data, dataTlv.GetLength());
TLVUnpackError = aDataTlv.GetDataPtr(data);
{{asSymbol label}} = chip::ByteSpan(data, aDataTlv.GetLength());
}
{{else if (isString type)}}
// TODO(#5542): The cluster handlers should accept a ByteSpan for all string types.
TLVUnpackError = dataTlv.GetDataPtr({{asSymbol label}});
TLVUnpackError = aDataTlv.GetDataPtr({{asSymbol label}});
{{else if isArray}}
// Just for compatibility, we will add array type support in IM later.
TLVUnpackError = dataTlv.GetDataPtr(const_cast<const uint8_t *&>({{asSymbol label}}));
TLVUnpackError = aDataTlv.GetDataPtr(const_cast<const uint8_t *&>({{asSymbol label}}));
{{else}}
TLVUnpackError = dataTlv.Get({{asSymbol label}});
TLVUnpackError = aDataTlv.Get({{asSymbol label}});
{{/if}}
if (CHIP_NO_ERROR == TLVUnpackError)
{
Expand All @@ -57,7 +57,7 @@ while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
}
if (TLVUnpackError != CHIP_NO_ERROR)
{
ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32, TLV::TagNumFromTag(dataTlv.GetTag()), TLVUnpackError);
ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32, TLV::TagNumFromTag(aDataTlv.GetTag()), TLVUnpackError);
break;
}
}
Expand All @@ -82,8 +82,10 @@ if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && {{zcl_comman
emberAf{{asCamelCased parent.name false}}Cluster{{asCamelCased name false}}Callback({{#zcl_command_arguments}}{{#if (isCharString type)}}const_cast<uint8_t*>({{asSymbol label}}){{else}}{{asSymbol label}}{{/if}}{{#unless (isLastElement index count)}}, {{/unless}}{{/zcl_command_arguments}});
{{#if (zcl_command_arguments_count this.id)}}
}
else if ({{zcl_command_arguments_count this.id}} != validArgumentCount)
else
{
ChipLogProgress(Zcl, "Missing command arguments in TLV data, command requires %d, given %" PRIu32, {{zcl_command_arguments_count this.id}}, validArgumentCount);
apCommandObj->AddStatusCode(nullptr, Protocols::SecureChannel::GeneralStatusCode::kBadRequest, Protocols::SecureChannel::Id,
Protocols::SecureChannel::kProtocolCodeGeneralFailure);
ChipLogProgress(Zcl, "Failed to dispatch command, %d/%" PRIu32 " arguments parsed, TLVError=%" PRIu32 ", UnpackError=%" PRIu32, {{zcl_command_arguments_count this.id}}, validArgumentCount, TLVError, TLVUnpackError);
}
{{/if}}
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ namespace clusters {
{{#if (user_cluster_has_enabled_command name side)}}
namespace {{asCamelCased name false}} {

void Dispatch{{asCamelCased side false}}Command(app::Command * command, CommandId commandId, EndpointId endpointId, TLV::TLVReader & dataTlv)
void Dispatch{{asCamelCased side false}}Command(app::Command * apCommandObj, CommandId aCommandId, EndpointId aEndpointId, TLV::TLVReader & aDataTlv)
{
{{#if (user_cluster_has_enabled_manufacturer_command name side)}}
{{else}}
{{/if}}
{
switch (commandId)
switch (aCommandId)
{
{{#all_user_cluster_commands}}
{{#unless mfgCode}}
Expand All @@ -48,8 +48,9 @@ void Dispatch{{asCamelCased side false}}Command(app::Command * command, CommandI
{{/all_user_cluster_commands}}
default: {
// Unrecognized command ID, error status will apply.
// TODO: Encode response for command not found
ChipLogError(Zcl, "Unknown command %" PRIx16 " for cluster %" PRIx16, commandId, ZCL_{{asDelimitedMacro define}}_ID);
apCommandObj->AddStatusCode(nullptr, Protocols::SecureChannel::GeneralStatusCode::kNotFound, Protocols::SecureChannel::Id,
Protocols::SecureChannel::kProtocolCodeGeneralFailure);
ChipLogError(Zcl, "Unknown command %" PRIx16 " for cluster %" PRIx16, aCommandId, ZCL_{{asDelimitedMacro define}}_ID);
break;
}
}
Expand Down Expand Up @@ -82,7 +83,8 @@ void DispatchSingleClusterCommand(chip::ClusterId aClusterId, chip::CommandId aC
{{/all_user_clusters}}
default:
// Unrecognized cluster ID, error status will apply.
// TODO: Encode response for Cluster not found
apCommandObj->AddStatusCode(nullptr, Protocols::SecureChannel::GeneralStatusCode::kNotFound, Protocols::SecureChannel::Id,
Protocols::SecureChannel::kProtocolCodeGeneralFailure);
ChipLogError(Zcl, "Unknown cluster %" PRIx16, aClusterId);
break;
}
Expand Down
Loading