Skip to content

Commit

Permalink
Group Key Management cluster XML naming and types updated according t…
Browse files Browse the repository at this point in the history
…o spec.
  • Loading branch information
rcasallas-silabs committed Feb 4, 2022
1 parent a7d7d8d commit 49fbca4
Show file tree
Hide file tree
Showing 36 changed files with 56,873 additions and 540 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1499,35 +1499,35 @@ server cluster GroupKeyManagement = 63 {
kLowLatency = 1;
}

struct GroupKey {
struct GroupKeyMapStruct {
fabric_idx fabricIndex = 0;
INT16U groupId = 1;
group_id groupId = 1;
INT16U groupKeySetID = 2;
}

struct GroupInfo {
INT16U fabricIndex = 0;
INT16U groupId = 1;
INT16U endpoints[] = 2;
CHAR_STRING<16> groupName = 3;
struct GroupInfoMapStruct {
fabric_idx fabricIndex = 0;
group_id groupId = 1;
endpoint_no endpoints[] = 2;
CHAR_STRING groupName = 3;
}

struct GroupKeySet {
struct GroupKeySetStruct {
INT16U groupKeySetID = 0;
GroupKeySecurityPolicy securityPolicy = 1;
OCTET_STRING<16> epochKey0 = 2;
INT64U epochStartTime0 = 3;
OCTET_STRING<16> epochKey1 = 4;
INT64U epochStartTime1 = 5;
OCTET_STRING<16> epochKey2 = 6;
INT64U epochStartTime2 = 7;
}

attribute GroupKey groupKeyMap[] = 0;
readonly attribute GroupInfo groupTable[] = 1;
readonly attribute int16u maxGroupsPerFabric = 2;
readonly attribute int16u maxGroupKeysPerFabric = 3;
readonly global attribute int16u clusterRevision = 65533;
GroupKeySecurityPolicy groupKeySecurityPolicy = 1;
OCTET_STRING epochKey0 = 2;
epoch_us epochStartTime0 = 3;
OCTET_STRING epochKey1 = 4;
epoch_us epochStartTime1 = 5;
OCTET_STRING epochKey2 = 6;
epoch_us epochStartTime2 = 7;
}

attribute(writable) GroupKeyMapStruct groupKeyMap[] = 0;
attribute(readonly) GroupInfoMapStruct groupTable[] = 1;
attribute(readonly) int16u maxGroupsPerFabric = 2;
attribute(readonly) int16u maxGroupKeysPerFabric = 3;
attribute(readonly) int16u clusterRevision = 65533;

request struct KeySetReadRequest {
INT16U groupKeySetID = 0;
Expand All @@ -1542,15 +1542,15 @@ server cluster GroupKeyManagement = 63 {
}

request struct KeySetWriteRequest {
GroupKeySet groupKeySet = 0;
GroupKeySetStruct groupKeySetStruct = 0;
}

response struct KeySetReadAllIndicesResponse {
INT16U groupKeySetIDs[] = 0;
}

response struct KeySetReadResponse {
GroupKeySet groupKeySet = 0;
GroupKeySetStruct groupKeySetStruct = 0;
}

command KeySetRead(KeySetReadRequest): KeySetReadResponse = 1;
Expand Down
20 changes: 10 additions & 10 deletions examples/thermostat/thermostat-common/thermostat.matter
Original file line number Diff line number Diff line change
Expand Up @@ -390,22 +390,22 @@ server cluster GroupKeyManagement = 63 {
kLowLatency = 1;
}

struct GroupKey {
struct GroupKeyMapStruct {
fabric_idx fabricIndex = 0;
INT16U groupId = 1;
group_id groupId = 1;
INT16U groupKeySetID = 2;
}

struct GroupInfo {
INT16U fabricIndex = 0;
INT16U groupId = 1;
INT16U endpoints[] = 2;
CHAR_STRING<16> groupName = 3;
struct GroupInfoMapStruct {
fabric_idx fabricIndex = 0;
group_id groupId = 1;
endpoint_no endpoints[] = 2;
CHAR_STRING groupName = 3;
}

attribute GroupKey groupKeyMap[] = 0;
readonly attribute GroupInfo groupTable[] = 1;
readonly global attribute int16u clusterRevision = 65533;
attribute(writable) GroupKeyMapStruct groupKeyMap[] = 0;
attribute(readonly) GroupInfoMapStruct groupTable[] = 1;
attribute(readonly) int16u clusterRevision = 65533;
}

server cluster Groups = 4 {
Expand Down
20 changes: 10 additions & 10 deletions examples/tv-app/tv-common/tv-app.matter
Original file line number Diff line number Diff line change
Expand Up @@ -756,22 +756,22 @@ server cluster GroupKeyManagement = 63 {
kLowLatency = 1;
}

struct GroupKey {
struct GroupKeyMapStruct {
fabric_idx fabricIndex = 0;
INT16U groupId = 1;
group_id groupId = 1;
INT16U groupKeySetID = 2;
}

struct GroupInfo {
INT16U fabricIndex = 0;
INT16U groupId = 1;
INT16U endpoints[] = 2;
CHAR_STRING<16> groupName = 3;
struct GroupInfoMapStruct {
fabric_idx fabricIndex = 0;
group_id groupId = 1;
endpoint_no endpoints[] = 2;
CHAR_STRING groupName = 3;
}

attribute GroupKey groupKeyMap[] = 0;
readonly attribute GroupInfo groupTable[] = 1;
readonly global attribute int16u clusterRevision = 65533;
attribute(writable) GroupKeyMapStruct groupKeyMap[] = 0;
attribute(readonly) GroupInfoMapStruct groupTable[] = 1;
attribute(readonly) int16u clusterRevision = 65533;
}

server cluster KeypadInput = 1289 {
Expand Down
20 changes: 10 additions & 10 deletions examples/tv-casting-app/tv-casting-common/tv-casting-app.matter
Original file line number Diff line number Diff line change
Expand Up @@ -1422,22 +1422,22 @@ server cluster GroupKeyManagement = 63 {
kLowLatency = 1;
}

struct GroupKey {
struct GroupKeyMapStruct {
fabric_idx fabricIndex = 0;
INT16U groupId = 1;
group_id groupId = 1;
INT16U groupKeySetID = 2;
}

struct GroupInfo {
INT16U fabricIndex = 0;
INT16U groupId = 1;
INT16U endpoints[] = 2;
CHAR_STRING<16> groupName = 3;
struct GroupInfoMapStruct {
fabric_idx fabricIndex = 0;
group_id groupId = 1;
endpoint_no endpoints[] = 2;
CHAR_STRING groupName = 3;
}

attribute GroupKey groupKeyMap[] = 0;
readonly attribute GroupInfo groupTable[] = 1;
readonly global attribute int16u clusterRevision = 65533;
attribute(writable) GroupKeyMapStruct groupKeyMap[] = 0;
attribute(readonly) GroupInfoMapStruct groupTable[] = 1;
attribute(readonly) int16u clusterRevision = 65533;
}

server cluster Groups = 4 {
Expand Down
65 changes: 35 additions & 30 deletions src/app/clusters/group-key-mgmt-server/group-key-mgmt-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@ struct GroupTableCodec
{
static constexpr TLV::Tag TagFabric()
{
return TLV::ContextTag(to_underlying(GroupKeyManagement::Structs::GroupInfo::Fields::kFabricIndex));
return TLV::ContextTag(to_underlying(GroupKeyManagement::Structs::GroupInfoMapStruct::Fields::kFabricIndex));
}
static constexpr TLV::Tag TagGroup()
{
return TLV::ContextTag(to_underlying(GroupKeyManagement::Structs::GroupInfo::Fields::kGroupId));
return TLV::ContextTag(to_underlying(GroupKeyManagement::Structs::GroupInfoMapStruct::Fields::kGroupId));
}
static constexpr TLV::Tag TagEndpoints()
{
return TLV::ContextTag(to_underlying(GroupKeyManagement::Structs::GroupInfo::Fields::kEndpoints));
return TLV::ContextTag(to_underlying(GroupKeyManagement::Structs::GroupInfoMapStruct::Fields::kEndpoints));
}
static constexpr TLV::Tag TagGroupName()
{
return TLV::ContextTag(to_underlying(GroupKeyManagement::Structs::GroupInfo::Fields::kGroupName));
return TLV::ContextTag(to_underlying(GroupKeyManagement::Structs::GroupInfoMapStruct::Fields::kGroupName));
}

GroupDataProvider * mProvider = nullptr;
Expand Down Expand Up @@ -164,9 +164,9 @@ class GroupKeyManagementAttributeAccess : public AttributeAccessInterface
GroupDataProvider::GroupKey mapping;
while (iter->Next(mapping))
{
GroupKeyManagement::Structs::GroupKey::Type key = { .fabricIndex = fabric_index,
.groupId = mapping.group_id,
.groupKeySetID = mapping.keyset_id };
GroupKeyManagement::Structs::GroupKeyMapStruct::Type key = { .fabricIndex = fabric_index,
.groupId = mapping.group_id,
.groupKeySetID = mapping.keyset_id };
encoder.Encode(key);
}
iter->Release();
Expand Down Expand Up @@ -267,42 +267,42 @@ bool emberAfGroupKeyManagementClusterKeySetWriteCallback(
return true;
}

if (commandData.groupKeySet.epochKey0.empty() || 0 == commandData.groupKeySet.epochStartTime0)
if (commandData.groupKeySetStruct.epochKey0.empty() || (0 == commandData.groupKeySetStruct.epochStartTime0))
{
// If the EpochKey0 field is null or its associated EpochStartTime0 field is null,
// then this command SHALL fail with an INVALID_COMMAND
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_INVALID_COMMAND);
return true;
}

GroupDataProvider::KeySet keyset(commandData.groupKeySet.groupKeySetID, commandData.groupKeySet.securityPolicy, 0);
GroupDataProvider::KeySet keyset(commandData.groupKeySetStruct.groupKeySetID,
commandData.groupKeySetStruct.groupKeySecurityPolicy, 0);

// Epoch Key 0
keyset.epoch_keys[0].start_time = commandData.groupKeySet.epochStartTime0;
memcpy(keyset.epoch_keys[0].key, commandData.groupKeySet.epochKey0.data(), GroupDataProvider::EpochKey::kLengthBytes);
keyset.epoch_keys[0].start_time = commandData.groupKeySetStruct.epochStartTime0;
memcpy(keyset.epoch_keys[0].key, commandData.groupKeySetStruct.epochKey0.data(), GroupDataProvider::EpochKey::kLengthBytes);
keyset.num_keys_used++;

// Epoch Key 1
if (!commandData.groupKeySet.epochKey1.empty())
if (!commandData.groupKeySetStruct.epochKey1.empty())
{
if (0 == commandData.groupKeySet.epochStartTime1 ||
commandData.groupKeySet.epochStartTime1 <= commandData.groupKeySet.epochStartTime0)
if (commandData.groupKeySetStruct.epochStartTime1 <= commandData.groupKeySetStruct.epochStartTime0)
{
// If the EpochKey1 field is not null, its associated EpochStartTime1 field SHALL contain
// a later epoch start time than the epoch start time found in the EpochStartTime0 field.
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_INVALID_COMMAND);
return true;
}
keyset.epoch_keys[1].start_time = commandData.groupKeySet.epochStartTime1;
memcpy(keyset.epoch_keys[1].key, commandData.groupKeySet.epochKey1.data(), GroupDataProvider::EpochKey::kLengthBytes);
keyset.epoch_keys[1].start_time = commandData.groupKeySetStruct.epochStartTime1;
memcpy(keyset.epoch_keys[1].key, commandData.groupKeySetStruct.epochKey1.data(), GroupDataProvider::EpochKey::kLengthBytes);
keyset.num_keys_used++;
}

// Epoch Key 2
if (!commandData.groupKeySet.epochKey2.empty())
if (!commandData.groupKeySetStruct.epochKey2.empty())
{
if (commandData.groupKeySet.epochKey1.empty() || 0 == commandData.groupKeySet.epochStartTime2 ||
commandData.groupKeySet.epochStartTime2 <= commandData.groupKeySet.epochStartTime1)
keyset.num_keys_used++;
if (commandData.groupKeySetStruct.epochStartTime2 <= commandData.groupKeySetStruct.epochStartTime1)
{
// If the EpochKey2 field is not null then:
// * The EpochKey1 field SHALL NOT be null
Expand All @@ -311,8 +311,8 @@ bool emberAfGroupKeyManagementClusterKeySetWriteCallback(
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_INVALID_COMMAND);
return true;
}
keyset.epoch_keys[2].start_time = commandData.groupKeySet.epochStartTime2;
memcpy(keyset.epoch_keys[2].key, commandData.groupKeySet.epochKey2.data(), GroupDataProvider::EpochKey::kLengthBytes);
keyset.epoch_keys[2].start_time = commandData.groupKeySetStruct.epochStartTime2;
memcpy(keyset.epoch_keys[2].key, commandData.groupKeySetStruct.epochKey2.data(), GroupDataProvider::EpochKey::kLengthBytes);
keyset.num_keys_used++;
}

Expand Down Expand Up @@ -360,39 +360,44 @@ bool emberAfGroupKeyManagementClusterKeySetReadCallback(

// In KeySetReadResponse, EpochKey0, EpochKey1 and EpochKey2 key contents shall be null
GroupKeyManagement::Commands::KeySetReadResponse::Type response;
response.groupKeySet.groupKeySetID = keyset.keyset_id;
response.groupKeySet.securityPolicy = keyset.policy;

response.groupKeySetStruct.groupKeySetID = keyset.keyset_id;
response.groupKeySetStruct.groupKeySecurityPolicy = keyset.policy;
// Keyset 0
if (keyset.num_keys_used > 0)
{
response.groupKeySet.epochStartTime0 = keyset.epoch_keys[0].start_time;
response.groupKeySetStruct.epochStartTime0 = keyset.epoch_keys[0].start_time;
response.groupKeySetStruct.epochKey0 = chip::ByteSpan(keyset.epoch_keys[0].key, GroupDataProvider::EpochKey::kLengthBytes);
}
else
{
response.groupKeySet.epochStartTime0 = 0;
response.groupKeySetStruct.epochStartTime0 = 0;
response.groupKeySetStruct.epochKey0 = chip::ByteSpan(nullptr, 0);
}
response.groupKeySet.epochKey0 = ByteSpan();

// Keyset 1
if (keyset.num_keys_used > 1)
{
response.groupKeySet.epochStartTime1 = keyset.epoch_keys[1].start_time;
response.groupKeySetStruct.epochStartTime1 = keyset.epoch_keys[1].start_time;
response.groupKeySetStruct.epochKey1 = chip::ByteSpan(keyset.epoch_keys[1].key, GroupDataProvider::EpochKey::kLengthBytes);
}
else
{
response.groupKeySet.epochStartTime1 = 0;
response.groupKeySetStruct.epochStartTime1 = 0;
response.groupKeySetStruct.epochKey1 = chip::ByteSpan(nullptr, 0);
}
response.groupKeySet.epochKey1 = ByteSpan();

// Keyset 2
if (keyset.num_keys_used > 2)
{
response.groupKeySet.epochStartTime2 = keyset.epoch_keys[2].start_time;
response.groupKeySetStruct.epochStartTime2 = keyset.epoch_keys[2].start_time;
response.groupKeySetStruct.epochKey2 = chip::ByteSpan(keyset.epoch_keys[2].key, GroupDataProvider::EpochKey::kLengthBytes);
}
else
{
response.groupKeySet.epochStartTime2 = 0;
response.groupKeySetStruct.epochStartTime2 = 0;
response.groupKeySetStruct.epochKey2 = chip::ByteSpan(nullptr, 0);
}
response.groupKeySet.epochKey2 = ByteSpan();

Expand Down
Loading

0 comments on commit 49fbca4

Please sign in to comment.