Skip to content

Commit

Permalink
Enable operational credentials and trusted root clusters on all examp…
Browse files Browse the repository at this point in the history
…les (#6842)

* Enable operational credentials and trusted root clusters on all example apps

* update zap files for examples and regen code
  • Loading branch information
pan-apple authored and pull[bot] committed May 20, 2021
1 parent 5ee838d commit 4c8e0c5
Show file tree
Hide file tree
Showing 47 changed files with 6,640 additions and 46 deletions.
569 changes: 569 additions & 0 deletions examples/lighting-app/lighting-common/gen/IMClusterCommandHandler.cpp

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions examples/lighting-app/lighting-common/gen/attribute-size.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,33 @@ uint16_t emberAfCopyList(ClusterId clusterId, EmberAfAttributeMetadata * am, boo
}
break;
}
case 0x003E: // Operational Credentials Cluster
{
uint16_t entryOffset = kSizeLengthInBytes;
switch (am->attributeId)
{
case 0x0001: // fabrics list
{
entryLength = 18;
if (((index - 1) * entryLength) > (am->size - entryLength))
{
ChipLogError(Zcl, "Index %l is invalid.", index);
return 0;
}
entryOffset = static_cast<uint16_t>(entryOffset + ((index - 1) * entryLength));
// Struct _FabricDescriptor
_FabricDescriptor * entry = reinterpret_cast<_FabricDescriptor *>(write ? src : dest);
copyListMember(write ? dest : (uint8_t *) &entry->FabricId, write ? (uint8_t *) &entry->FabricId : src, write,
&entryOffset, sizeof(entry->FabricId)); // FABRIC_ID
copyListMember(write ? dest : (uint8_t *) &entry->VendorId, write ? (uint8_t *) &entry->VendorId : src, write,
&entryOffset, sizeof(entry->VendorId)); // INT16U
copyListMember(write ? dest : (uint8_t *) &entry->NodeId, write ? (uint8_t *) &entry->NodeId : src, write, &entryOffset,
sizeof(entry->NodeId)); // NODE_ID
break;
}
}
break;
}
case 0x0035: // Thread Network Diagnostics Cluster
{
uint16_t entryOffset = kSizeLengthInBytes;
Expand Down Expand Up @@ -303,6 +330,15 @@ uint16_t emberAfAttributeValueListSize(ClusterId clusterId, AttributeId attribut
break;
}
break;
case 0x003E: // Operational Credentials Cluster
switch (attributeId)
{
case 0x0001: // fabrics list
// Struct _FabricDescriptor
entryLength = 18;
break;
}
break;
case 0x0035: // Thread Network Diagnostics Cluster
switch (attributeId)
{
Expand Down
196 changes: 196 additions & 0 deletions examples/lighting-app/lighting-common/gen/call-command-handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ EmberAfStatus emberAfGeneralDiagnosticsClusterServerCommandParse(EmberAfClusterC
EmberAfStatus emberAfLevelControlClusterServerCommandParse(EmberAfClusterCommand * cmd);
EmberAfStatus emberAfNetworkCommissioningClusterServerCommandParse(EmberAfClusterCommand * cmd);
EmberAfStatus emberAfOnOffClusterServerCommandParse(EmberAfClusterCommand * cmd);
EmberAfStatus emberAfOperationalCredentialsClusterServerCommandParse(EmberAfClusterCommand * cmd);
EmberAfStatus emberAfThreadNetworkDiagnosticsClusterServerCommandParse(EmberAfClusterCommand * cmd);
EmberAfStatus emberAfTrustedRootCertificatesClusterServerCommandParse(EmberAfClusterCommand * cmd);
EmberAfStatus emberAfWiFiNetworkDiagnosticsClusterServerCommandParse(EmberAfClusterCommand * cmd);

static EmberAfStatus status(bool wasHandled, bool clusterExists, bool mfgSpecific)
Expand Down Expand Up @@ -96,10 +98,16 @@ EmberAfStatus emberAfClusterSpecificCommandParse(EmberAfClusterCommand * cmd)
case ZCL_ON_OFF_CLUSTER_ID:
result = emberAfOnOffClusterServerCommandParse(cmd);
break;
case ZCL_OPERATIONAL_CREDENTIALS_CLUSTER_ID:
result = emberAfOperationalCredentialsClusterServerCommandParse(cmd);
break;
case ZCL_THREAD_NETWORK_DIAGNOSTICS_CLUSTER_ID:
// No commands are enabled for cluster Thread Network Diagnostics
result = status(false, true, cmd->mfgSpecific);
break;
case ZCL_TRUSTED_ROOT_CERTIFICATES_CLUSTER_ID:
result = emberAfTrustedRootCertificatesClusterServerCommandParse(cmd);
break;
case ZCL_WIFI_NETWORK_DIAGNOSTICS_CLUSTER_ID:
// No commands are enabled for cluster WiFi Network Diagnostics
result = status(false, true, cmd->mfgSpecific);
Expand Down Expand Up @@ -734,3 +742,191 @@ EmberAfStatus emberAfOnOffClusterServerCommandParse(EmberAfClusterCommand * cmd)
}
return status(wasHandled, true, cmd->mfgSpecific);
}
EmberAfStatus emberAfOperationalCredentialsClusterServerCommandParse(EmberAfClusterCommand * cmd)
{
bool wasHandled = false;

if (!cmd->mfgSpecific)
{
switch (cmd->commandId)
{
case ZCL_ADD_OP_CERT_COMMAND_ID: {
uint16_t payloadOffset = cmd->payloadStartIndex;
chip::ByteSpan NOC;
chip::ByteSpan ICACertificate;
chip::ByteSpan IPKValue;
chip::NodeId CaseAdminNode;
uint16_t AdminVendorId;

if (cmd->bufLen < payloadOffset + 1u)
{
return EMBER_ZCL_STATUS_MALFORMED_COMMAND;
}
{
uint8_t * rawData = emberAfGetString(cmd->buffer, payloadOffset, cmd->bufLen);
NOC = chip::ByteSpan(rawData + 1u, emberAfStringLength(rawData));
}
payloadOffset = static_cast<uint16_t>(payloadOffset + NOC.size() + 1u);
if (cmd->bufLen < payloadOffset + 1u)
{
return EMBER_ZCL_STATUS_MALFORMED_COMMAND;
}
{
uint8_t * rawData = emberAfGetString(cmd->buffer, payloadOffset, cmd->bufLen);
ICACertificate = chip::ByteSpan(rawData + 1u, emberAfStringLength(rawData));
}
payloadOffset = static_cast<uint16_t>(payloadOffset + ICACertificate.size() + 1u);
if (cmd->bufLen < payloadOffset + 1u)
{
return EMBER_ZCL_STATUS_MALFORMED_COMMAND;
}
{
uint8_t * rawData = emberAfGetString(cmd->buffer, payloadOffset, cmd->bufLen);
IPKValue = chip::ByteSpan(rawData + 1u, emberAfStringLength(rawData));
}
payloadOffset = static_cast<uint16_t>(payloadOffset + IPKValue.size() + 1u);
if (cmd->bufLen < payloadOffset + 8)
{
return EMBER_ZCL_STATUS_MALFORMED_COMMAND;
}
CaseAdminNode = emberAfGetInt64u(cmd->buffer, payloadOffset, cmd->bufLen);
payloadOffset = static_cast<uint16_t>(payloadOffset + 8);
if (cmd->bufLen < payloadOffset + 2)
{
return EMBER_ZCL_STATUS_MALFORMED_COMMAND;
}
AdminVendorId = emberAfGetInt16u(cmd->buffer, payloadOffset, cmd->bufLen);

wasHandled = emberAfOperationalCredentialsClusterAddOpCertCallback(nullptr, NOC, ICACertificate, IPKValue,
CaseAdminNode, AdminVendorId);
break;
}
case ZCL_OP_CSR_REQUEST_COMMAND_ID: {
uint16_t payloadOffset = cmd->payloadStartIndex;
chip::ByteSpan CSRNonce;

if (cmd->bufLen < payloadOffset + 1u)
{
return EMBER_ZCL_STATUS_MALFORMED_COMMAND;
}
{
uint8_t * rawData = emberAfGetString(cmd->buffer, payloadOffset, cmd->bufLen);
CSRNonce = chip::ByteSpan(rawData + 1u, emberAfStringLength(rawData));
}

wasHandled = emberAfOperationalCredentialsClusterOpCSRRequestCallback(nullptr, CSRNonce);
break;
}
case ZCL_REMOVE_ALL_FABRICS_COMMAND_ID: {
wasHandled = emberAfOperationalCredentialsClusterRemoveAllFabricsCallback(nullptr);
break;
}
case ZCL_REMOVE_FABRIC_COMMAND_ID: {
uint16_t payloadOffset = cmd->payloadStartIndex;
chip::FabricId FabricId;
chip::NodeId NodeId;
uint16_t VendorId;

if (cmd->bufLen < payloadOffset + 8)
{
return EMBER_ZCL_STATUS_MALFORMED_COMMAND;
}
FabricId = emberAfGetInt64u(cmd->buffer, payloadOffset, cmd->bufLen);
payloadOffset = static_cast<uint16_t>(payloadOffset + 8);
if (cmd->bufLen < payloadOffset + 8)
{
return EMBER_ZCL_STATUS_MALFORMED_COMMAND;
}
NodeId = emberAfGetInt64u(cmd->buffer, payloadOffset, cmd->bufLen);
payloadOffset = static_cast<uint16_t>(payloadOffset + 8);
if (cmd->bufLen < payloadOffset + 2)
{
return EMBER_ZCL_STATUS_MALFORMED_COMMAND;
}
VendorId = emberAfGetInt16u(cmd->buffer, payloadOffset, cmd->bufLen);

wasHandled = emberAfOperationalCredentialsClusterRemoveFabricCallback(nullptr, FabricId, NodeId, VendorId);
break;
}
case ZCL_SET_FABRIC_COMMAND_ID: {
uint16_t payloadOffset = cmd->payloadStartIndex;
uint16_t VendorId;

if (cmd->bufLen < payloadOffset + 2)
{
return EMBER_ZCL_STATUS_MALFORMED_COMMAND;
}
VendorId = emberAfGetInt16u(cmd->buffer, payloadOffset, cmd->bufLen);

wasHandled = emberAfOperationalCredentialsClusterSetFabricCallback(nullptr, VendorId);
break;
}
case ZCL_UPDATE_FABRIC_LABEL_COMMAND_ID: {
uint16_t payloadOffset = cmd->payloadStartIndex;
uint8_t * Label;

if (cmd->bufLen < payloadOffset + 1u)
{
return EMBER_ZCL_STATUS_MALFORMED_COMMAND;
}
Label = emberAfGetString(cmd->buffer, payloadOffset, cmd->bufLen);

wasHandled = emberAfOperationalCredentialsClusterUpdateFabricLabelCallback(nullptr, Label);
break;
}
default: {
// Unrecognized command ID, error status will apply.
break;
}
}
}
return status(wasHandled, true, cmd->mfgSpecific);
}
EmberAfStatus emberAfTrustedRootCertificatesClusterServerCommandParse(EmberAfClusterCommand * cmd)
{
bool wasHandled = false;

if (!cmd->mfgSpecific)
{
switch (cmd->commandId)
{
case ZCL_ADD_TRUSTED_ROOT_CERTIFICATE_COMMAND_ID: {
uint16_t payloadOffset = cmd->payloadStartIndex;
chip::ByteSpan RootCertificate;

if (cmd->bufLen < payloadOffset + 1u)
{
return EMBER_ZCL_STATUS_MALFORMED_COMMAND;
}
{
uint8_t * rawData = emberAfGetString(cmd->buffer, payloadOffset, cmd->bufLen);
RootCertificate = chip::ByteSpan(rawData + 1u, emberAfStringLength(rawData));
}

wasHandled = emberAfTrustedRootCertificatesClusterAddTrustedRootCertificateCallback(nullptr, RootCertificate);
break;
}
case ZCL_REMOVE_TRUSTED_ROOT_CERTIFICATE_COMMAND_ID: {
uint16_t payloadOffset = cmd->payloadStartIndex;
chip::ByteSpan TrustedRootIdentifier;

if (cmd->bufLen < payloadOffset + 1u)
{
return EMBER_ZCL_STATUS_MALFORMED_COMMAND;
}
{
uint8_t * rawData = emberAfGetString(cmd->buffer, payloadOffset, cmd->bufLen);
TrustedRootIdentifier = chip::ByteSpan(rawData + 1u, emberAfStringLength(rawData));
}

wasHandled = emberAfTrustedRootCertificatesClusterRemoveTrustedRootCertificateCallback(nullptr, TrustedRootIdentifier);
break;
}
default: {
// Unrecognized command ID, error status will apply.
break;
}
}
}
return status(wasHandled, true, cmd->mfgSpecific);
}
16 changes: 16 additions & 0 deletions examples/lighting-app/lighting-common/gen/callback-stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,15 @@ void emberAfClusterInitCallback(EndpointId endpoint, ClusterId clusterId)
case ZCL_ON_OFF_CLUSTER_ID:
emberAfOnOffClusterInitCallback(endpoint);
break;
case ZCL_OPERATIONAL_CREDENTIALS_CLUSTER_ID:
emberAfOperationalCredentialsClusterInitCallback(endpoint);
break;
case ZCL_THREAD_NETWORK_DIAGNOSTICS_CLUSTER_ID:
emberAfThreadNetworkDiagnosticsClusterInitCallback(endpoint);
break;
case ZCL_TRUSTED_ROOT_CERTIFICATES_CLUSTER_ID:
emberAfTrustedRootCertificatesClusterInitCallback(endpoint);
break;
case ZCL_WIFI_NETWORK_DIAGNOSTICS_CLUSTER_ID:
emberAfWiFiNetworkDiagnosticsClusterInitCallback(endpoint);
break;
Expand Down Expand Up @@ -89,11 +95,21 @@ void __attribute__((weak)) emberAfOnOffClusterInitCallback(EndpointId endpoint)
// To prevent warning
(void) endpoint;
}
void __attribute__((weak)) emberAfOperationalCredentialsClusterInitCallback(EndpointId endpoint)
{
// To prevent warning
(void) endpoint;
}
void __attribute__((weak)) emberAfThreadNetworkDiagnosticsClusterInitCallback(EndpointId endpoint)
{
// To prevent warning
(void) endpoint;
}
void __attribute__((weak)) emberAfTrustedRootCertificatesClusterInitCallback(EndpointId endpoint)
{
// To prevent warning
(void) endpoint;
}
void __attribute__((weak)) emberAfWiFiNetworkDiagnosticsClusterInitCallback(EndpointId endpoint)
{
// To prevent warning
Expand Down
Loading

0 comments on commit 4c8e0c5

Please sign in to comment.