Skip to content

Commit

Permalink
Remove GroupKeyCodec.
Browse files Browse the repository at this point in the history
It's not needed; all that code already exists in Structs::GroupKey.

The XML change is to fix a compile issue due to the type being wrong,
but pretty much all the XML is wrong there.
project-chip#13176 tracks
addressing that.
  • Loading branch information
bzbarsky-apple committed Dec 21, 2021
1 parent 1d06bb2 commit e2d02e5
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 66 deletions.
67 changes: 9 additions & 58 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 @@ -40,59 +40,6 @@ using namespace chip::app::Clusters;

namespace {

struct GroupKeyCodec
{
static const TLV::Tag kTagFabric = TLV::ContextTag(to_underlying(GroupKeyManagement::Structs::GroupKey::Fields::kFabricIndex));
static const TLV::Tag kTagGroup = TLV::ContextTag(to_underlying(GroupKeyManagement::Structs::GroupKey::Fields::kGroupId));
static const TLV::Tag kTagKeyset =
TLV::ContextTag(to_underlying(GroupKeyManagement::Structs::GroupKey::Fields::kGroupKeySetID));

chip::FabricIndex mFabric = 0;
GroupDataProvider::GroupKey mMapping;

GroupKeyCodec() = default;
GroupKeyCodec(chip::FabricIndex fabric_index, const GroupDataProvider::GroupKey & mapping) :
mFabric(fabric_index), mMapping(mapping)
{}

CHIP_ERROR Encode(TLV::TLVWriter & writer, TLV::Tag tag) const
{
TLV::TLVType outer;
ReturnErrorOnFailure(writer.StartContainer(tag, TLV::kTLVType_Structure, outer));

// FabricIndex
ReturnErrorOnFailure(DataModel::Encode(writer, kTagFabric, mFabric));
// GroupId
ReturnErrorOnFailure(DataModel::Encode(writer, kTagGroup, mMapping.group_id));
// GroupKeySetID
ReturnErrorOnFailure(DataModel::Encode(writer, kTagKeyset, mMapping.keyset_id));

ReturnErrorOnFailure(writer.EndContainer(outer));
return CHIP_NO_ERROR;
}

CHIP_ERROR Decode(TLV::TLVReader & reader)
{
TLV::TLVType outer;

VerifyOrReturnError(TLV::kTLVType_Structure == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE);
ReturnErrorOnFailure(reader.EnterContainer(outer));

// FabricIndex
ReturnErrorOnFailure(reader.Next(kTagFabric));
ReturnErrorOnFailure(reader.Get(mFabric));
// GroupId
ReturnErrorOnFailure(reader.Next(kTagGroup));
ReturnErrorOnFailure(reader.Get(mMapping.group_id));
// GroupKeySetID
ReturnErrorOnFailure(reader.Next(kTagKeyset));
ReturnErrorOnFailure(reader.Get(mMapping.keyset_id));

ReturnErrorOnFailure(reader.ExitContainer(outer));
return CHIP_NO_ERROR;
}
};

struct GroupTableCodec
{
static const TLV::Tag kTagFabric = TLV::ContextTag(to_underlying(GroupKeyManagement::Structs::GroupInfo::Fields::kFabricIndex));
Expand Down Expand Up @@ -203,7 +150,10 @@ class GroupKeyManagementAttributeAccess : public AttributeAccessInterface
GroupDataProvider::GroupKey mapping;
while (iter->Next(mapping))
{
encoder.Encode(GroupKeyCodec(fabric_index, mapping));
GroupKeyManagement::Structs::GroupKey::Type key = { .fabricIndex = fabric_index,
.groupId = mapping.group_id,
.groupKeySetID = mapping.keyset_id };
encoder.Encode(key);
}
iter->Release();
return CHIP_NO_ERROR;
Expand All @@ -215,7 +165,7 @@ class GroupKeyManagementAttributeAccess : public AttributeAccessInterface
{
auto fabric_index = aDecoder.AccessingFabricIndex();
auto provider = GetGroupDataProvider();
DataModel::DecodableList<GroupKeyCodec> list;
GroupKeyManagement::Attributes::GroupKeyMap::TypeInfo::DecodableType list;
size_t new_count;

VerifyOrReturnError(nullptr != provider, CHIP_ERROR_INTERNAL);
Expand All @@ -230,9 +180,10 @@ class GroupKeyManagementAttributeAccess : public AttributeAccessInterface
size_t i = 0;
while (iter.Next())
{
const GroupKeyCodec & value = iter.GetValue();
VerifyOrReturnError(fabric_index == value.mFabric, CHIP_ERROR_INVALID_FABRIC_ID);
ReturnErrorOnFailure(provider->SetGroupKeyAt(value.mFabric, i++, value.mMapping));
const auto & value = iter.GetValue();
VerifyOrReturnError(fabric_index == value.fabricIndex, CHIP_ERROR_INVALID_FABRIC_ID);
ReturnErrorOnFailure(
provider->SetGroupKeyAt(value.fabricIndex, i++, GroupDataProvider::GroupKey(value.groupId, value.groupKeySetID)));
}
ReturnErrorOnFailure(iter.GetStatus());
return CHIP_NO_ERROR;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ limitations under the License.

<struct name="GroupKey">
<cluster code="0x003F"/>
<item fieldId="0" name="fabricIndex" type="INT16U"/>
<item fieldId="0" name="fabricIndex" type="fabric_idx"/>
<item fieldId="1" name="groupId" type="INT16U"/>
<item fieldId="2" name="groupKeySetID" type="INT16U"/>
</struct>
Expand Down Expand Up @@ -96,4 +96,4 @@ limitations under the License.
</command>

</cluster>
</configurator>
</configurator>
2 changes: 1 addition & 1 deletion src/controller/java/zap-generated/CHIPReadCallbacks.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e2d02e5

Please sign in to comment.