Skip to content

Commit

Permalink
Update gen/ folder
Browse files Browse the repository at this point in the history
  • Loading branch information
vivien-apple committed Apr 9, 2021
1 parent b2204cb commit 98dddbe
Show file tree
Hide file tree
Showing 60 changed files with 7,827 additions and 526 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@
*/

// THIS FILE IS GENERATED BY ZAP

// List specific responses
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,15 @@ typedef struct _GroupInformationRecord
uint8_t groupType;
} EmberAfGroupInformationRecord;

// Struct for GroupKeys
typedef struct _GroupKeys
// Struct for GroupKey
typedef struct _GroupKey
{
uint16_t VendorId;
uint16_t GroupKeyIndex;
/* TYPE WARNING: array array defaults to */ uint8_t * GroupKeyRoot;
uint8_t * GroupKeyRoot;
uint64_t GroupKeyEpochStartTime;
uint8_t GroupKeySecurityPolicy;
} EmberAfGroupKeys;
} EmberAfGroupKey;

// Struct for GroupState
typedef struct _GroupState
Expand Down
256 changes: 256 additions & 0 deletions examples/all-clusters-app/all-clusters-common/gen/attribute-size.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,256 @@
/*
*
* Copyright (c) 2021 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// THIS FILE IS GENERATED BY ZAP

#include <app/util/af.h>
#include <app/util/basic-types.h>
#include <support/SafeInt.h>
#include <support/logging/CHIPLogging.h>

#include "gen/af-structs.h"

using namespace chip;

// The first 2 bytes specify the number of entries. A value of 0xFFFF means the list in invalid
// and data is undefined.
constexpr uint16_t kSizeLengthInBytes = 2u;

void copyListMember(uint8_t * dest, uint8_t * src, bool write, uint16_t * offset, uint16_t length)
{
if (write)
{
memmove(dest + *offset, src, length);
}
else
{
memmove(dest, src + *offset, length);
}

*offset = static_cast<uint16_t>(*offset + length);
}

uint16_t emberAfCopyList(ClusterId clusterId, EmberAfAttributeMetadata * am, bool write, uint8_t * dest, uint8_t * src,
int32_t index)
{
if (index == -1)
{
memmove(dest, src, am->size);
return am->size;
}

if (index == 0)
{
if (write)
{
// src is a pointer to native-endian uint16_t, dst is pointer to buffer that should hold little-endian value
emberAfCopyInt16u(dest, 0, *reinterpret_cast<uint16_t *>(src));
}
else
{
// src is pointer to buffer holding little-endian value, dst is a pointer to native-endian uint16_t
*reinterpret_cast<uint16_t *>(dest) = emberAfGetInt16u(src, 0, kSizeLengthInBytes);
}
return kSizeLengthInBytes;
}

if (!chip::CanCastTo<uint16_t>(index))
{
ChipLogError(Zcl, "Index %l is invalid. Should be between 1 and 65534", index);
return 0;
}

uint16_t entryLength = 0;
switch (clusterId)
{
case 0x001D: // Descriptor Cluster
{
uint16_t entryOffset = kSizeLengthInBytes;
switch (am->attributeId)
{
case 0x0000: // device list
{
entryLength = 6;
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 _DeviceType
_DeviceType * entry = reinterpret_cast<_DeviceType *>(write ? src : dest);
copyListMember(write ? dest : (uint8_t *) &entry->type, write ? (uint8_t *) &entry->type : src, write, &entryOffset,
sizeof(entry->type)); // DEVICE_TYPE_ID
copyListMember(write ? dest : (uint8_t *) &entry->revision, write ? (uint8_t *) &entry->revision : src, write,
&entryOffset, sizeof(entry->revision)); // INT16U
break;
}
case 0x0001: // server list
{
entryLength = 2;
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));
copyListMember(dest, src, write, &entryOffset, entryLength); // CLUSTER_ID
break;
}
case 0x0002: // client list
{
entryLength = 2;
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));
copyListMember(dest, src, write, &entryOffset, entryLength); // CLUSTER_ID
break;
}
case 0x0003: // parts list
{
entryLength = 1;
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));
copyListMember(dest, src, write, &entryOffset, entryLength); // ENDPOINT_ID
break;
}
}
break;
}
case 0xF004: // Group Key Management Cluster
{
uint16_t entryOffset = kSizeLengthInBytes;
switch (am->attributeId)
{
case 0x0000: // groups
{
entryLength = 6;
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 _GroupState
_GroupState * entry = reinterpret_cast<_GroupState *>(write ? src : dest);
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->VendorGroupId, write ? (uint8_t *) &entry->VendorGroupId : src, write,
&entryOffset, sizeof(entry->VendorGroupId)); // INT16U
copyListMember(write ? dest : (uint8_t *) &entry->GroupKeySetIndex, write ? (uint8_t *) &entry->GroupKeySetIndex : src,
write, &entryOffset, sizeof(entry->GroupKeySetIndex)); // INT16U
break;
}
case 0x0001: // group keys
{
entryLength = 29;
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 _GroupKey
_GroupKey * entry = reinterpret_cast<_GroupKey *>(write ? src : dest);
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->GroupKeyIndex, write ? (uint8_t *) &entry->GroupKeyIndex : src, write,
&entryOffset, sizeof(entry->GroupKeyIndex)); // INT16U
copyListMember(write ? dest : (uint8_t *) &entry->GroupKeyRoot, write ? (uint8_t *) &entry->GroupKeyRoot : src, write,
&entryOffset, 16); // OCTET_STRING
copyListMember(write ? dest : (uint8_t *) &entry->GroupKeyEpochStartTime,
write ? (uint8_t *) &entry->GroupKeyEpochStartTime : src, write, &entryOffset,
sizeof(entry->GroupKeyEpochStartTime)); // INT64U
copyListMember(write ? dest : (uint8_t *) &entry->GroupKeySecurityPolicy,
write ? (uint8_t *) &entry->GroupKeySecurityPolicy : src, write, &entryOffset,
sizeof(entry->GroupKeySecurityPolicy)); // GroupKeySecurityPolicy
break;
}
}
break;
}
}

return entryLength;
}

// A list is a collection of entries of the same data type. The data type may be any defined data type.
uint16_t emberAfAttributeValueListSize(ClusterId clusterId, AttributeId attributeId, const uint8_t * buffer)
{
// The first 2 bytes specify the number of entries. A value of 0xFFFF means the list in invalid
// and data is undefined.
uint16_t entryCount = emberAfGetInt16u(buffer, 0, kSizeLengthInBytes);
if (entryCount == 0xFFFF)
{
return 0;
}

uint16_t entryLength = 0;
switch (clusterId)
{
case 0x001D: // Descriptor Cluster
switch (attributeId)
{
case 0x0000: // device list
// Struct _DeviceType
entryLength = 6;
break;
case 0x0001: // server list
// chip::ClusterId
entryLength = 2;
break;
case 0x0002: // client list
// chip::ClusterId
entryLength = 2;
break;
case 0x0003: // parts list
// chip::EndpointId
entryLength = 1;
break;
}
break;
case 0xF004: // Group Key Management Cluster
switch (attributeId)
{
case 0x0000: // groups
// Struct _GroupState
entryLength = 6;
break;
case 0x0001: // group keys
// Struct _GroupKey
entryLength = 29;
break;
}
break;
}

uint32_t totalSize = kSizeLengthInBytes + (entryCount * entryLength);
if (!chip::CanCastTo<uint16_t>(totalSize))
{
ChipLogError(Zcl, "Cluster 0x%04x: Size of attribute 0x%02x is too large.", clusterId, attributeId);
return 0;
}

return static_cast<uint16_t>(totalSize);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ EmberAfStatus emberAfBarrierControlClusterServerCommandParse(EmberAfClusterComma
EmberAfStatus emberAfBasicClusterServerCommandParse(EmberAfClusterCommand * cmd);
EmberAfStatus emberAfBindingClusterServerCommandParse(EmberAfClusterCommand * cmd);
EmberAfStatus emberAfColorControlClusterServerCommandParse(EmberAfClusterCommand * cmd);
EmberAfStatus emberAfDescriptorClusterServerCommandParse(EmberAfClusterCommand * cmd);
EmberAfStatus emberAfDoorLockClusterServerCommandParse(EmberAfClusterCommand * cmd);
EmberAfStatus emberAfGeneralCommissioningClusterServerCommandParse(EmberAfClusterCommand * cmd);
EmberAfStatus emberAfGroupKeyManagementClusterServerCommandParse(EmberAfClusterCommand * cmd);
Expand Down Expand Up @@ -101,6 +102,10 @@ EmberAfStatus emberAfClusterSpecificCommandParse(EmberAfClusterCommand * cmd)
case ZCL_COLOR_CONTROL_CLUSTER_ID:
result = emberAfColorControlClusterServerCommandParse(cmd);
break;
case ZCL_DESCRIPTOR_CLUSTER_ID:
// No commands are enabled for cluster Descriptor
result = status(false, true, cmd->mfgSpecific);
break;
case ZCL_DOOR_LOCK_CLUSTER_ID:
result = emberAfDoorLockClusterServerCommandParse(cmd);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ void emberAfClusterInitCallback(EndpointId endpoint, ClusterId clusterId)
case ZCL_COLOR_CONTROL_CLUSTER_ID:
emberAfColorControlClusterInitCallback(endpoint);
break;
case ZCL_DESCRIPTOR_CLUSTER_ID:
emberAfDescriptorClusterInitCallback(endpoint);
break;
case ZCL_DOOR_LOCK_CLUSTER_ID:
emberAfDoorLockClusterInitCallback(endpoint);
break;
Expand Down Expand Up @@ -111,6 +114,11 @@ void __attribute__((weak)) emberAfColorControlClusterInitCallback(EndpointId end
// To prevent warning
(void) endpoint;
}
void __attribute__((weak)) emberAfDescriptorClusterInitCallback(EndpointId endpoint)
{
// To prevent warning
(void) endpoint;
}
void __attribute__((weak)) emberAfDoorLockClusterInitCallback(EndpointId endpoint)
{
// To prevent warning
Expand Down
Loading

0 comments on commit 98dddbe

Please sign in to comment.