Skip to content

Commit

Permalink
Examples: Window Covering: Cluster configuration updated. (#7743)
Browse files Browse the repository at this point in the history
  • Loading branch information
rcasallas-silabs authored and pull[bot] committed Jul 27, 2021
1 parent fcdb3e7 commit 1361776
Show file tree
Hide file tree
Showing 10 changed files with 3,877 additions and 385 deletions.
199 changes: 199 additions & 0 deletions examples/window-app/common/gen/IMClusterCommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,202 @@ namespace app {

namespace clusters {

namespace GeneralCommissioning {

void DispatchServerCommand(app::Command * apCommandObj, CommandId aCommandId, EndpointId aEndpointId, TLV::TLVReader & aDataTlv)
{
// We are using TLVUnpackError and TLVError here since both of them can be CHIP_END_OF_TLV
// When TLVError is CHIP_END_OF_TLV, it means we have iterated all of the items, which is not a real error.
// Any error value TLVUnpackError means we have received an illegal value.
// The following variables are used for all commands to save code size.
CHIP_ERROR TLVError = CHIP_NO_ERROR;
CHIP_ERROR TLVUnpackError = CHIP_NO_ERROR;
uint32_t validArgumentCount = 0;
uint32_t expectArgumentCount = 0;
uint32_t currentDecodeTagId = 0;
bool wasHandled = false;
{
switch (aCommandId)
{
case ZCL_ARM_FAIL_SAFE_COMMAND_ID: {
expectArgumentCount = 3;
uint16_t expiryLengthSeconds;
uint64_t breadcrumb;
uint32_t timeoutMs;
bool argExists[3];

memset(argExists, 0, sizeof argExists);

while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR)
{
// Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element.
// Skip this element if it is not a ContextTag, not consider it as an error if other values are valid.
if (!TLV::IsContextTag(aDataTlv.GetTag()))
{
continue;
}
currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag());
if (currentDecodeTagId < 3)
{
if (argExists[currentDecodeTagId])
{
ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag()));
TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT;
break;
}
else
{
argExists[currentDecodeTagId] = true;
validArgumentCount++;
}
}
switch (currentDecodeTagId)
{
case 0:
TLVUnpackError = aDataTlv.Get(expiryLengthSeconds);
break;
case 1:
TLVUnpackError = aDataTlv.Get(breadcrumb);
break;
case 2:
TLVUnpackError = aDataTlv.Get(timeoutMs);
break;
default:
// Unsupported tag, ignore it.
ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
break;
}
if (CHIP_NO_ERROR != TLVUnpackError)
{
break;
}
}

if (CHIP_END_OF_TLV == TLVError)
{
// CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error.
TLVError = CHIP_NO_ERROR;
}

if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 3 == validArgumentCount)
{
// TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
wasHandled =
emberAfGeneralCommissioningClusterArmFailSafeCallback(apCommandObj, expiryLengthSeconds, breadcrumb, timeoutMs);
}
break;
}
case ZCL_COMMISSIONING_COMPLETE_COMMAND_ID: {

// TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
wasHandled = emberAfGeneralCommissioningClusterCommissioningCompleteCallback(apCommandObj);
break;
}
case ZCL_SET_REGULATORY_CONFIG_COMMAND_ID: {
expectArgumentCount = 4;
uint8_t location;
const uint8_t * countryCode;
uint64_t breadcrumb;
uint32_t timeoutMs;
bool argExists[4];

memset(argExists, 0, sizeof argExists);

while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR)
{
// Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element.
// Skip this element if it is not a ContextTag, not consider it as an error if other values are valid.
if (!TLV::IsContextTag(aDataTlv.GetTag()))
{
continue;
}
currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag());
if (currentDecodeTagId < 4)
{
if (argExists[currentDecodeTagId])
{
ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag()));
TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT;
break;
}
else
{
argExists[currentDecodeTagId] = true;
validArgumentCount++;
}
}
switch (currentDecodeTagId)
{
case 0:
TLVUnpackError = aDataTlv.Get(location);
break;
case 1:
// TODO(#5542): The cluster handlers should accept a ByteSpan for all string types.
TLVUnpackError = aDataTlv.GetDataPtr(countryCode);
break;
case 2:
TLVUnpackError = aDataTlv.Get(breadcrumb);
break;
case 3:
TLVUnpackError = aDataTlv.Get(timeoutMs);
break;
default:
// Unsupported tag, ignore it.
ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
break;
}
if (CHIP_NO_ERROR != TLVUnpackError)
{
break;
}
}

if (CHIP_END_OF_TLV == TLVError)
{
// CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error.
TLVError = CHIP_NO_ERROR;
}

if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 4 == validArgumentCount)
{
// TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
wasHandled = emberAfGeneralCommissioningClusterSetRegulatoryConfigCallback(
apCommandObj, location, const_cast<uint8_t *>(countryCode), breadcrumb, timeoutMs);
}
break;
}
default: {
// Unrecognized command ID, error status will apply.
chip::app::CommandPathParams returnStatusParam = { aEndpointId,
0, // GroupId
ZCL_GENERAL_COMMISSIONING_CLUSTER_ID, aCommandId,
(chip::app::CommandPathFlags::kEndpointIdValid) };
apCommandObj->AddStatusCode(returnStatusParam, Protocols::SecureChannel::GeneralStatusCode::kNotFound,
Protocols::SecureChannel::Id,
Protocols::InteractionModel::ProtocolCode::UnsupportedCommand);
ChipLogError(Zcl, "Unknown command %" PRIx16 " for cluster %" PRIx16, aCommandId, ZCL_GENERAL_COMMISSIONING_CLUSTER_ID);
return;
}
}
}

if (CHIP_NO_ERROR != TLVError || CHIP_NO_ERROR != TLVUnpackError || expectArgumentCount != validArgumentCount || !wasHandled)
{
chip::app::CommandPathParams returnStatusParam = { aEndpointId,
0, // GroupId
ZCL_GENERAL_COMMISSIONING_CLUSTER_ID, aCommandId,
(chip::app::CommandPathFlags::kEndpointIdValid) };
apCommandObj->AddStatusCode(returnStatusParam, Protocols::SecureChannel::GeneralStatusCode::kBadRequest,
Protocols::SecureChannel::Id, Protocols::InteractionModel::ProtocolCode::InvalidCommand);
ChipLogProgress(Zcl,
"Failed to dispatch command, %" PRIu32 "/%" PRIu32 " arguments parsed, TLVError=%" PRIu32
", UnpackError=%" PRIu32 " (last decoded tag = %" PRIu32,
validArgumentCount, expectArgumentCount, TLVError, TLVUnpackError, currentDecodeTagId);
}
}

} // namespace GeneralCommissioning

namespace NetworkCommissioning {

void DispatchServerCommand(app::Command * apCommandObj, CommandId aCommandId, EndpointId aEndpointId, TLV::TLVReader & aDataTlv)
Expand Down Expand Up @@ -1552,6 +1748,9 @@ void DispatchSingleClusterCommand(chip::ClusterId aClusterId, chip::CommandId aC
SuccessOrExit(aReader.EnterContainer(dataTlvType));
switch (aClusterId)
{
case ZCL_GENERAL_COMMISSIONING_CLUSTER_ID:
clusters::GeneralCommissioning::DispatchServerCommand(apCommandObj, aCommandId, aEndPointId, aReader);
break;
case ZCL_NETWORK_COMMISSIONING_CLUSTER_ID:
clusters::NetworkCommissioning::DispatchServerCommand(apCommandObj, aCommandId, aEndPointId, aReader);
break;
Expand Down
50 changes: 50 additions & 0 deletions examples/window-app/common/gen/attribute-size.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,47 @@ uint16_t emberAfCopyList(ClusterId clusterId, EmberAfAttributeMetadata * am, boo
uint16_t entryLength = 0;
switch (clusterId)
{
case 0x0033: // General Diagnostics Cluster
{
uint16_t entryOffset = kSizeLengthInBytes;
switch (am->attributeId)
{
case 0x0000: // NetworkInterfaces
{
entryLength = 46;
if (((index - 1) * entryLength) > (am->size - entryLength))
{
ChipLogError(Zcl, "Index %" PRId32 " is invalid.", index);
return 0;
}
entryOffset = static_cast<uint16_t>(entryOffset + ((index - 1) * entryLength));
// Struct _NetworkInterfaceType
_NetworkInterfaceType * entry = reinterpret_cast<_NetworkInterfaceType *>(write ? src : dest);
chip::ByteSpan * NameSpan = &entry->Name; // OCTET_STRING
if (CHIP_NO_ERROR !=
(write ? WriteByteSpan(dest + entryOffset, 34, NameSpan) : ReadByteSpan(src + entryOffset, 34, NameSpan)))
{
ChipLogError(Zcl, "Index %" PRId32 " is invalid. Not enough remaining space", index);
return 0;
}
entryOffset = static_cast<uint16_t>(entryOffset + 34);
copyListMember(write ? dest : (uint8_t *) &entry->FabricConnected, write ? (uint8_t *) &entry->FabricConnected : src,
write, &entryOffset, sizeof(entry->FabricConnected)); // BOOLEAN
copyListMember(write ? dest : (uint8_t *) &entry->OffPremiseServicesReachableIPv4,
write ? (uint8_t *) &entry->OffPremiseServicesReachableIPv4 : src, write, &entryOffset,
sizeof(entry->OffPremiseServicesReachableIPv4)); // BOOLEAN
copyListMember(write ? dest : (uint8_t *) &entry->OffPremiseServicesReachableIPv6,
write ? (uint8_t *) &entry->OffPremiseServicesReachableIPv6 : src, write, &entryOffset,
sizeof(entry->OffPremiseServicesReachableIPv6)); // BOOLEAN
copyListMember(write ? dest : (uint8_t *) &entry->HardwareAddress, write ? (uint8_t *) &entry->HardwareAddress : src,
write, &entryOffset, sizeof(entry->HardwareAddress)); // IEEE_ADDRESS
copyListMember(write ? dest : (uint8_t *) &entry->Type, write ? (uint8_t *) &entry->Type : src, write, &entryOffset,
sizeof(entry->Type)); // ENUM8
break;
}
}
break;
}
case 0x003E: // Operational Credentials Cluster
{
uint16_t entryOffset = kSizeLengthInBytes;
Expand Down Expand Up @@ -287,6 +328,15 @@ uint16_t emberAfAttributeValueListSize(ClusterId clusterId, AttributeId attribut
uint16_t entryLength = 0;
switch (clusterId)
{
case 0x0033: // General Diagnostics Cluster
switch (attributeId)
{
case 0x0000: // NetworkInterfaces
// Struct _NetworkInterfaceType
entryLength = 46;
break;
}
break;
case 0x003E: // Operational Credentials Cluster
switch (attributeId)
{
Expand Down
40 changes: 40 additions & 0 deletions examples/window-app/common/gen/callback-stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,30 @@ void emberAfClusterInitCallback(EndpointId endpoint, ClusterId clusterId)
case ZCL_BASIC_CLUSTER_ID:
emberAfBasicClusterInitCallback(endpoint);
break;
case ZCL_ETHERNET_NETWORK_DIAGNOSTICS_CLUSTER_ID:
emberAfEthernetNetworkDiagnosticsClusterInitCallback(endpoint);
break;
case ZCL_GENERAL_COMMISSIONING_CLUSTER_ID:
emberAfGeneralCommissioningClusterInitCallback(endpoint);
break;
case ZCL_GENERAL_DIAGNOSTICS_CLUSTER_ID:
emberAfGeneralDiagnosticsClusterInitCallback(endpoint);
break;
case ZCL_NETWORK_COMMISSIONING_CLUSTER_ID:
emberAfNetworkCommissioningClusterInitCallback(endpoint);
break;
case ZCL_OPERATIONAL_CREDENTIALS_CLUSTER_ID:
emberAfOperationalCredentialsClusterInitCallback(endpoint);
break;
case ZCL_SOFTWARE_DIAGNOSTICS_CLUSTER_ID:
emberAfSoftwareDiagnosticsClusterInitCallback(endpoint);
break;
case ZCL_THREAD_NETWORK_DIAGNOSTICS_CLUSTER_ID:
emberAfThreadNetworkDiagnosticsClusterInitCallback(endpoint);
break;
case ZCL_WIFI_NETWORK_DIAGNOSTICS_CLUSTER_ID:
emberAfWiFiNetworkDiagnosticsClusterInitCallback(endpoint);
break;
case ZCL_WINDOW_COVERING_CLUSTER_ID:
emberAfWindowCoveringClusterInitCallback(endpoint);
break;
Expand All @@ -55,6 +70,21 @@ void __attribute__((weak)) emberAfBasicClusterInitCallback(EndpointId endpoint)
// To prevent warning
(void) endpoint;
}
void __attribute__((weak)) emberAfEthernetNetworkDiagnosticsClusterInitCallback(EndpointId endpoint)
{
// To prevent warning
(void) endpoint;
}
void __attribute__((weak)) emberAfGeneralCommissioningClusterInitCallback(EndpointId endpoint)
{
// To prevent warning
(void) endpoint;
}
void __attribute__((weak)) emberAfGeneralDiagnosticsClusterInitCallback(EndpointId endpoint)
{
// To prevent warning
(void) endpoint;
}
void __attribute__((weak)) emberAfNetworkCommissioningClusterInitCallback(EndpointId endpoint)
{
// To prevent warning
Expand All @@ -65,11 +95,21 @@ void __attribute__((weak)) emberAfOperationalCredentialsClusterInitCallback(Endp
// To prevent warning
(void) endpoint;
}
void __attribute__((weak)) emberAfSoftwareDiagnosticsClusterInitCallback(EndpointId endpoint)
{
// To prevent warning
(void) endpoint;
}
void __attribute__((weak)) emberAfThreadNetworkDiagnosticsClusterInitCallback(EndpointId endpoint)
{
// To prevent warning
(void) endpoint;
}
void __attribute__((weak)) emberAfWiFiNetworkDiagnosticsClusterInitCallback(EndpointId endpoint)
{
// To prevent warning
(void) endpoint;
}
void __attribute__((weak)) emberAfWindowCoveringClusterInitCallback(EndpointId endpoint)
{
// To prevent warning
Expand Down
Loading

0 comments on commit 1361776

Please sign in to comment.