Skip to content

Commit

Permalink
EFR32 Window Covering sample: Missing Basic and Network Commissioning…
Browse files Browse the repository at this point in the history
… clusters added. (#6467)
  • Loading branch information
rcasallas-silabs authored and pull[bot] committed Aug 4, 2021
1 parent 35cb18a commit 5919617
Show file tree
Hide file tree
Showing 8 changed files with 2,227 additions and 220 deletions.
955 changes: 955 additions & 0 deletions examples/window-app/common/gen/IMClusterCommandHandler.cpp

Large diffs are not rendered by default.

302 changes: 302 additions & 0 deletions examples/window-app/common/gen/call-command-handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

using namespace chip;

EmberAfStatus emberAfBasicClusterServerCommandParse(EmberAfClusterCommand * cmd);
EmberAfStatus emberAfNetworkCommissioningClusterServerCommandParse(EmberAfClusterCommand * cmd);
EmberAfStatus emberAfWindowCoveringClusterServerCommandParse(EmberAfClusterCommand * cmd);

static EmberAfStatus status(bool wasHandled, bool clusterExists, bool mfgSpecific)
Expand Down Expand Up @@ -69,6 +71,13 @@ EmberAfStatus emberAfClusterSpecificCommandParse(EmberAfClusterCommand * cmd)
{
switch (cmd->apsFrame->clusterId)
{
case ZCL_BASIC_CLUSTER_ID:
// No commands are enabled for cluster Basic
result = status(false, true, cmd->mfgSpecific);
break;
case ZCL_NETWORK_COMMISSIONING_CLUSTER_ID:
result = emberAfNetworkCommissioningClusterServerCommandParse(cmd);
break;
case ZCL_WINDOW_COVERING_CLUSTER_ID:
result = emberAfWindowCoveringClusterServerCommandParse(cmd);
break;
Expand All @@ -82,6 +91,299 @@ EmberAfStatus emberAfClusterSpecificCommandParse(EmberAfClusterCommand * cmd)

// Cluster specific command parsing

EmberAfStatus emberAfNetworkCommissioningClusterServerCommandParse(EmberAfClusterCommand * cmd)
{
bool wasHandled = false;

if (!cmd->mfgSpecific)
{
switch (cmd->commandId)
{
case ZCL_ADD_THREAD_NETWORK_COMMAND_ID: {
uint16_t payloadOffset = cmd->payloadStartIndex;
chip::ByteSpan operationalDataset;
uint64_t breadcrumb;
uint32_t timeoutMs;

if (cmd->bufLen < payloadOffset + 1u)
{
return EMBER_ZCL_STATUS_MALFORMED_COMMAND;
}
{
uint8_t * rawData = emberAfGetString(cmd->buffer, payloadOffset, cmd->bufLen);
operationalDataset = chip::ByteSpan(rawData + 1u, emberAfStringLength(rawData));
}
payloadOffset = static_cast<uint16_t>(payloadOffset + operationalDataset.size() + 1u);
if (cmd->bufLen < payloadOffset + 8)
{
return EMBER_ZCL_STATUS_MALFORMED_COMMAND;
}
breadcrumb = emberAfGetInt64u(cmd->buffer, payloadOffset, cmd->bufLen);
payloadOffset = static_cast<uint16_t>(payloadOffset + 8);
if (cmd->bufLen < payloadOffset + 4)
{
return EMBER_ZCL_STATUS_MALFORMED_COMMAND;
}
timeoutMs = emberAfGetInt32u(cmd->buffer, payloadOffset, cmd->bufLen);

wasHandled =
emberAfNetworkCommissioningClusterAddThreadNetworkCallback(nullptr, operationalDataset, breadcrumb, timeoutMs);
break;
}
case ZCL_ADD_WI_FI_NETWORK_COMMAND_ID: {
uint16_t payloadOffset = cmd->payloadStartIndex;
chip::ByteSpan ssid;
chip::ByteSpan credentials;
uint64_t breadcrumb;
uint32_t timeoutMs;

if (cmd->bufLen < payloadOffset + 1u)
{
return EMBER_ZCL_STATUS_MALFORMED_COMMAND;
}
{
uint8_t * rawData = emberAfGetString(cmd->buffer, payloadOffset, cmd->bufLen);
ssid = chip::ByteSpan(rawData + 1u, emberAfStringLength(rawData));
}
payloadOffset = static_cast<uint16_t>(payloadOffset + ssid.size() + 1u);
if (cmd->bufLen < payloadOffset + 1u)
{
return EMBER_ZCL_STATUS_MALFORMED_COMMAND;
}
{
uint8_t * rawData = emberAfGetString(cmd->buffer, payloadOffset, cmd->bufLen);
credentials = chip::ByteSpan(rawData + 1u, emberAfStringLength(rawData));
}
payloadOffset = static_cast<uint16_t>(payloadOffset + credentials.size() + 1u);
if (cmd->bufLen < payloadOffset + 8)
{
return EMBER_ZCL_STATUS_MALFORMED_COMMAND;
}
breadcrumb = emberAfGetInt64u(cmd->buffer, payloadOffset, cmd->bufLen);
payloadOffset = static_cast<uint16_t>(payloadOffset + 8);
if (cmd->bufLen < payloadOffset + 4)
{
return EMBER_ZCL_STATUS_MALFORMED_COMMAND;
}
timeoutMs = emberAfGetInt32u(cmd->buffer, payloadOffset, cmd->bufLen);

wasHandled =
emberAfNetworkCommissioningClusterAddWiFiNetworkCallback(nullptr, ssid, credentials, breadcrumb, timeoutMs);
break;
}
case ZCL_DISABLE_NETWORK_COMMAND_ID: {
uint16_t payloadOffset = cmd->payloadStartIndex;
chip::ByteSpan networkID;
uint64_t breadcrumb;
uint32_t timeoutMs;

if (cmd->bufLen < payloadOffset + 1u)
{
return EMBER_ZCL_STATUS_MALFORMED_COMMAND;
}
{
uint8_t * rawData = emberAfGetString(cmd->buffer, payloadOffset, cmd->bufLen);
networkID = chip::ByteSpan(rawData + 1u, emberAfStringLength(rawData));
}
payloadOffset = static_cast<uint16_t>(payloadOffset + networkID.size() + 1u);
if (cmd->bufLen < payloadOffset + 8)
{
return EMBER_ZCL_STATUS_MALFORMED_COMMAND;
}
breadcrumb = emberAfGetInt64u(cmd->buffer, payloadOffset, cmd->bufLen);
payloadOffset = static_cast<uint16_t>(payloadOffset + 8);
if (cmd->bufLen < payloadOffset + 4)
{
return EMBER_ZCL_STATUS_MALFORMED_COMMAND;
}
timeoutMs = emberAfGetInt32u(cmd->buffer, payloadOffset, cmd->bufLen);

wasHandled = emberAfNetworkCommissioningClusterDisableNetworkCallback(nullptr, networkID, breadcrumb, timeoutMs);
break;
}
case ZCL_ENABLE_NETWORK_COMMAND_ID: {
uint16_t payloadOffset = cmd->payloadStartIndex;
chip::ByteSpan networkID;
uint64_t breadcrumb;
uint32_t timeoutMs;

if (cmd->bufLen < payloadOffset + 1u)
{
return EMBER_ZCL_STATUS_MALFORMED_COMMAND;
}
{
uint8_t * rawData = emberAfGetString(cmd->buffer, payloadOffset, cmd->bufLen);
networkID = chip::ByteSpan(rawData + 1u, emberAfStringLength(rawData));
}
payloadOffset = static_cast<uint16_t>(payloadOffset + networkID.size() + 1u);
if (cmd->bufLen < payloadOffset + 8)
{
return EMBER_ZCL_STATUS_MALFORMED_COMMAND;
}
breadcrumb = emberAfGetInt64u(cmd->buffer, payloadOffset, cmd->bufLen);
payloadOffset = static_cast<uint16_t>(payloadOffset + 8);
if (cmd->bufLen < payloadOffset + 4)
{
return EMBER_ZCL_STATUS_MALFORMED_COMMAND;
}
timeoutMs = emberAfGetInt32u(cmd->buffer, payloadOffset, cmd->bufLen);

wasHandled = emberAfNetworkCommissioningClusterEnableNetworkCallback(nullptr, networkID, breadcrumb, timeoutMs);
break;
}
case ZCL_GET_LAST_NETWORK_COMMISSIONING_RESULT_COMMAND_ID: {
uint16_t payloadOffset = cmd->payloadStartIndex;
uint32_t timeoutMs;

if (cmd->bufLen < payloadOffset + 4)
{
return EMBER_ZCL_STATUS_MALFORMED_COMMAND;
}
timeoutMs = emberAfGetInt32u(cmd->buffer, payloadOffset, cmd->bufLen);

wasHandled = emberAfNetworkCommissioningClusterGetLastNetworkCommissioningResultCallback(nullptr, timeoutMs);
break;
}
case ZCL_REMOVE_NETWORK_COMMAND_ID: {
uint16_t payloadOffset = cmd->payloadStartIndex;
chip::ByteSpan NetworkID;
uint64_t Breadcrumb;
uint32_t TimeoutMs;

if (cmd->bufLen < payloadOffset + 1u)
{
return EMBER_ZCL_STATUS_MALFORMED_COMMAND;
}
{
uint8_t * rawData = emberAfGetString(cmd->buffer, payloadOffset, cmd->bufLen);
NetworkID = chip::ByteSpan(rawData + 1u, emberAfStringLength(rawData));
}
payloadOffset = static_cast<uint16_t>(payloadOffset + NetworkID.size() + 1u);
if (cmd->bufLen < payloadOffset + 8)
{
return EMBER_ZCL_STATUS_MALFORMED_COMMAND;
}
Breadcrumb = emberAfGetInt64u(cmd->buffer, payloadOffset, cmd->bufLen);
payloadOffset = static_cast<uint16_t>(payloadOffset + 8);
if (cmd->bufLen < payloadOffset + 4)
{
return EMBER_ZCL_STATUS_MALFORMED_COMMAND;
}
TimeoutMs = emberAfGetInt32u(cmd->buffer, payloadOffset, cmd->bufLen);

wasHandled = emberAfNetworkCommissioningClusterRemoveNetworkCallback(nullptr, NetworkID, Breadcrumb, TimeoutMs);
break;
}
case ZCL_SCAN_NETWORKS_COMMAND_ID: {
uint16_t payloadOffset = cmd->payloadStartIndex;
chip::ByteSpan ssid;
uint64_t breadcrumb;
uint32_t timeoutMs;

if (cmd->bufLen < payloadOffset + 1u)
{
return EMBER_ZCL_STATUS_MALFORMED_COMMAND;
}
{
uint8_t * rawData = emberAfGetString(cmd->buffer, payloadOffset, cmd->bufLen);
ssid = chip::ByteSpan(rawData + 1u, emberAfStringLength(rawData));
}
payloadOffset = static_cast<uint16_t>(payloadOffset + ssid.size() + 1u);
if (cmd->bufLen < payloadOffset + 8)
{
return EMBER_ZCL_STATUS_MALFORMED_COMMAND;
}
breadcrumb = emberAfGetInt64u(cmd->buffer, payloadOffset, cmd->bufLen);
payloadOffset = static_cast<uint16_t>(payloadOffset + 8);
if (cmd->bufLen < payloadOffset + 4)
{
return EMBER_ZCL_STATUS_MALFORMED_COMMAND;
}
timeoutMs = emberAfGetInt32u(cmd->buffer, payloadOffset, cmd->bufLen);

wasHandled = emberAfNetworkCommissioningClusterScanNetworksCallback(nullptr, ssid, breadcrumb, timeoutMs);
break;
}
case ZCL_UPDATE_THREAD_NETWORK_COMMAND_ID: {
uint16_t payloadOffset = cmd->payloadStartIndex;
chip::ByteSpan operationalDataset;
uint64_t breadcrumb;
uint32_t timeoutMs;

if (cmd->bufLen < payloadOffset + 1u)
{
return EMBER_ZCL_STATUS_MALFORMED_COMMAND;
}
{
uint8_t * rawData = emberAfGetString(cmd->buffer, payloadOffset, cmd->bufLen);
operationalDataset = chip::ByteSpan(rawData + 1u, emberAfStringLength(rawData));
}
payloadOffset = static_cast<uint16_t>(payloadOffset + operationalDataset.size() + 1u);
if (cmd->bufLen < payloadOffset + 8)
{
return EMBER_ZCL_STATUS_MALFORMED_COMMAND;
}
breadcrumb = emberAfGetInt64u(cmd->buffer, payloadOffset, cmd->bufLen);
payloadOffset = static_cast<uint16_t>(payloadOffset + 8);
if (cmd->bufLen < payloadOffset + 4)
{
return EMBER_ZCL_STATUS_MALFORMED_COMMAND;
}
timeoutMs = emberAfGetInt32u(cmd->buffer, payloadOffset, cmd->bufLen);

wasHandled =
emberAfNetworkCommissioningClusterUpdateThreadNetworkCallback(nullptr, operationalDataset, breadcrumb, timeoutMs);
break;
}
case ZCL_UPDATE_WI_FI_NETWORK_COMMAND_ID: {
uint16_t payloadOffset = cmd->payloadStartIndex;
chip::ByteSpan ssid;
chip::ByteSpan credentials;
uint64_t breadcrumb;
uint32_t timeoutMs;

if (cmd->bufLen < payloadOffset + 1u)
{
return EMBER_ZCL_STATUS_MALFORMED_COMMAND;
}
{
uint8_t * rawData = emberAfGetString(cmd->buffer, payloadOffset, cmd->bufLen);
ssid = chip::ByteSpan(rawData + 1u, emberAfStringLength(rawData));
}
payloadOffset = static_cast<uint16_t>(payloadOffset + ssid.size() + 1u);
if (cmd->bufLen < payloadOffset + 1u)
{
return EMBER_ZCL_STATUS_MALFORMED_COMMAND;
}
{
uint8_t * rawData = emberAfGetString(cmd->buffer, payloadOffset, cmd->bufLen);
credentials = chip::ByteSpan(rawData + 1u, emberAfStringLength(rawData));
}
payloadOffset = static_cast<uint16_t>(payloadOffset + credentials.size() + 1u);
if (cmd->bufLen < payloadOffset + 8)
{
return EMBER_ZCL_STATUS_MALFORMED_COMMAND;
}
breadcrumb = emberAfGetInt64u(cmd->buffer, payloadOffset, cmd->bufLen);
payloadOffset = static_cast<uint16_t>(payloadOffset + 8);
if (cmd->bufLen < payloadOffset + 4)
{
return EMBER_ZCL_STATUS_MALFORMED_COMMAND;
}
timeoutMs = emberAfGetInt32u(cmd->buffer, payloadOffset, cmd->bufLen);

wasHandled =
emberAfNetworkCommissioningClusterUpdateWiFiNetworkCallback(nullptr, ssid, credentials, breadcrumb, timeoutMs);
break;
}
default: {
// Unrecognized command ID, error status will apply.
break;
}
}
}
return status(wasHandled, true, cmd->mfgSpecific);
}
EmberAfStatus emberAfWindowCoveringClusterServerCommandParse(EmberAfClusterCommand * cmd)
{
bool wasHandled = false;
Expand Down
16 changes: 16 additions & 0 deletions examples/window-app/common/gen/callback-stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ void emberAfClusterInitCallback(EndpointId endpoint, ClusterId clusterId)
{
switch (clusterId)
{
case ZCL_BASIC_CLUSTER_ID:
emberAfBasicClusterInitCallback(endpoint);
break;
case ZCL_NETWORK_COMMISSIONING_CLUSTER_ID:
emberAfNetworkCommissioningClusterInitCallback(endpoint);
break;
case ZCL_WINDOW_COVERING_CLUSTER_ID:
emberAfWindowCoveringClusterInitCallback(endpoint);
break;
Expand All @@ -38,6 +44,16 @@ void emberAfClusterInitCallback(EndpointId endpoint, ClusterId clusterId)
}
}

void __attribute__((weak)) emberAfBasicClusterInitCallback(EndpointId endpoint)
{
// To prevent warning
(void) endpoint;
}
void __attribute__((weak)) emberAfNetworkCommissioningClusterInitCallback(EndpointId endpoint)
{
// To prevent warning
(void) endpoint;
}
void __attribute__((weak)) emberAfWindowCoveringClusterInitCallback(EndpointId endpoint)
{
// To prevent warning
Expand Down
Loading

0 comments on commit 5919617

Please sign in to comment.