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
#13625)

* Group Key Management cluster XML naming and types updated according to spec.

* Group Key Management XML: Review comments applied.

* Group Key Management cluster XML: YAML tests enabled.

* Group Key Management cluster XML: Bugs fixed.
  • Loading branch information
rcasallas-silabs authored Feb 4, 2022
1 parent 6dd3122 commit 5db4015
Show file tree
Hide file tree
Showing 47 changed files with 2,050 additions and 735 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1499,32 +1499,32 @@ 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;
optional CHAR_STRING<16> 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;
GroupKeySecurityPolicy groupKeySecurityPolicy = 1;
nullable OCTET_STRING<16> epochKey0 = 2;
nullable epoch_us epochStartTime0 = 3;
nullable OCTET_STRING<16> epochKey1 = 4;
nullable epoch_us epochStartTime1 = 5;
nullable OCTET_STRING<16> epochKey2 = 6;
nullable epoch_us epochStartTime2 = 7;
}

attribute GroupKey groupKeyMap[] = 0;
readonly attribute GroupInfo groupTable[] = 1;
attribute GroupKeyMapStruct groupKeyMap[] = 0;
readonly attribute GroupInfoMapStruct groupTable[] = 1;
readonly attribute int16u maxGroupsPerFabric = 2;
readonly attribute int16u maxGroupKeysPerFabric = 3;
readonly global attribute int16u clusterRevision = 65533;
Expand All @@ -1542,15 +1542,15 @@ server cluster GroupKeyManagement = 63 {
}

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

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

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

command KeySetRead(KeySetReadRequest): KeySetReadResponse = 1;
Expand Down
18 changes: 9 additions & 9 deletions examples/thermostat/thermostat-common/thermostat.matter
Original file line number Diff line number Diff line change
Expand Up @@ -390,21 +390,21 @@ 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;
optional CHAR_STRING<16> groupName = 3;
}

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

Expand Down
18 changes: 9 additions & 9 deletions examples/tv-app/tv-common/tv-app.matter
Original file line number Diff line number Diff line change
Expand Up @@ -756,21 +756,21 @@ 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;
optional CHAR_STRING<16> groupName = 3;
}

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

Expand Down
18 changes: 9 additions & 9 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,21 +1422,21 @@ 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;
optional CHAR_STRING<16> groupName = 3;
}

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

Expand Down
67 changes: 35 additions & 32 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,44 @@ bool emberAfGroupKeyManagementClusterKeySetWriteCallback(
return true;
}

if (commandData.groupKeySet.epochKey0.empty() || 0 == commandData.groupKeySet.epochStartTime0)
if (commandData.groupKeySet.epochKey0.IsNull() || commandData.groupKeySet.epochStartTime0.IsNull() ||
commandData.groupKeySet.epochKey0.Value().empty() || (0 == commandData.groupKeySet.epochStartTime0.Value()))
{
// 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.groupKeySet.groupKeySetID, commandData.groupKeySet.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.groupKeySet.epochStartTime0.Value();
memcpy(keyset.epoch_keys[0].key, commandData.groupKeySet.epochKey0.Value().data(), GroupDataProvider::EpochKey::kLengthBytes);
keyset.num_keys_used++;

// Epoch Key 1
if (!commandData.groupKeySet.epochKey1.empty())
if (!commandData.groupKeySet.epochKey1.IsNull())
{
if (0 == commandData.groupKeySet.epochStartTime1 ||
commandData.groupKeySet.epochStartTime1 <= commandData.groupKeySet.epochStartTime0)
if (commandData.groupKeySet.epochStartTime1.IsNull() ||
commandData.groupKeySet.epochStartTime1.Value() <= commandData.groupKeySet.epochStartTime0.Value())
{
// 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.groupKeySet.epochStartTime1.Value();
memcpy(keyset.epoch_keys[1].key, commandData.groupKeySet.epochKey1.Value().data(),
GroupDataProvider::EpochKey::kLengthBytes);
keyset.num_keys_used++;
}

// Epoch Key 2
if (!commandData.groupKeySet.epochKey2.empty())
if (!commandData.groupKeySet.epochKey2.IsNull())
{
if (commandData.groupKeySet.epochKey1.empty() || 0 == commandData.groupKeySet.epochStartTime2 ||
commandData.groupKeySet.epochStartTime2 <= commandData.groupKeySet.epochStartTime1)
if (commandData.groupKeySet.epochKey1.IsNull() || commandData.groupKeySet.epochStartTime2.IsNull() ||
commandData.groupKeySet.epochStartTime2.Value() <= commandData.groupKeySet.epochStartTime1.Value())
{
// If the EpochKey2 field is not null then:
// * The EpochKey1 field SHALL NOT be null
Expand All @@ -311,8 +313,9 @@ 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.groupKeySet.epochStartTime2.Value();
memcpy(keyset.epoch_keys[2].key, commandData.groupKeySet.epochKey2.Value().data(),
GroupDataProvider::EpochKey::kLengthBytes);
keyset.num_keys_used++;
}

Expand Down Expand Up @@ -360,41 +363,41 @@ 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.groupKeySet.groupKeySetID = keyset.keyset_id;
response.groupKeySet.groupKeySecurityPolicy = keyset.policy;

// Keyset 0
if (keyset.num_keys_used > 0)
{
response.groupKeySet.epochStartTime0 = keyset.epoch_keys[0].start_time;
response.groupKeySet.epochStartTime0.SetNonNull(keyset.epoch_keys[0].start_time);
}
else
{
response.groupKeySet.epochStartTime0 = 0;
response.groupKeySet.epochStartTime0.SetNull();
}
response.groupKeySet.epochKey0 = ByteSpan();
response.groupKeySet.epochKey0.SetNull();

// Keyset 1
if (keyset.num_keys_used > 1)
{
response.groupKeySet.epochStartTime1 = keyset.epoch_keys[1].start_time;
response.groupKeySet.epochStartTime1.SetNonNull(keyset.epoch_keys[1].start_time);
}
else
{
response.groupKeySet.epochStartTime1 = 0;
response.groupKeySet.epochStartTime1.SetNull();
}
response.groupKeySet.epochKey1 = ByteSpan();
response.groupKeySet.epochKey1.SetNull();

// Keyset 2
if (keyset.num_keys_used > 2)
{
response.groupKeySet.epochStartTime2 = keyset.epoch_keys[2].start_time;
response.groupKeySet.epochStartTime2.SetNonNull(keyset.epoch_keys[2].start_time);
}
else
{
response.groupKeySet.epochStartTime2 = 0;
response.groupKeySet.epochStartTime2.SetNull();
}
response.groupKeySet.epochKey2 = ByteSpan();
response.groupKeySet.epochKey2.SetNull();

CHIP_ERROR err = commandObj->AddResponseData(commandPath, response);
if (CHIP_NO_ERROR != err)
Expand Down
Loading

0 comments on commit 5db4015

Please sign in to comment.