Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove GroupKeyCodec. #13179

Merged
merged 3 commits into from
Jan 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 9 additions & 66 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,67 +40,6 @@ using namespace chip::app::Clusters;

namespace {

struct GroupKeyCodec
{
static constexpr TLV::Tag TagFabric()
{
return TLV::ContextTag(to_underlying(GroupKeyManagement::Structs::GroupKey::Fields::kFabricIndex));
}
static constexpr TLV::Tag TagGroup()
{
return TLV::ContextTag(to_underlying(GroupKeyManagement::Structs::GroupKey::Fields::kGroupId));
}
static constexpr TLV::Tag TagKeyset()
{
return 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, TagFabric(), mFabric));
// GroupId
ReturnErrorOnFailure(DataModel::Encode(writer, TagGroup(), mMapping.group_id));
// GroupKeySetID
ReturnErrorOnFailure(DataModel::Encode(writer, TagKeyset(), 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(TagFabric()));
ReturnErrorOnFailure(reader.Get(mFabric));
// GroupId
ReturnErrorOnFailure(reader.Next(TagGroup()));
ReturnErrorOnFailure(reader.Get(mMapping.group_id));
// GroupKeySetID
ReturnErrorOnFailure(reader.Next(TagKeyset()));
ReturnErrorOnFailure(reader.Get(mMapping.keyset_id));

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

struct GroupTableCodec
{
static constexpr TLV::Tag TagFabric()
Expand Down Expand Up @@ -221,7 +160,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 @@ -233,7 +175,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 @@ -248,9 +190,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.