Skip to content

Commit

Permalink
WORK IN PROGRESS.
Browse files Browse the repository at this point in the history
  • Loading branch information
rcasallas-silabs committed Aug 16, 2024
1 parent 4fa24ba commit 9cdcd7c
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/credentials/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ static_library("credentials") {
"GroupDataProviderBase.h",
"GroupDataProviderImpl.cpp",
"GroupDataProviderImpl.h",
"GroupDataProviderMigration.cpp",
"GroupDataProviderV2.cpp",
"GroupDataProviderV2.h",
"LastKnownGoodTime.cpp",
Expand Down
4 changes: 3 additions & 1 deletion src/credentials/GroupDataProviderBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ class GroupDataProviderBase : public GroupDataProvider
GroupDataProviderBase(uint16_t maxGroupsPerFabric, uint16_t maxGroupKeysPerFabric) :
GroupDataProvider(maxGroupsPerFabric, maxGroupKeysPerFabric)
{}
// ~GroupDataProviderBase() override {}

virtual CHIP_ERROR GetFabricCount(size_t &count) = 0;
virtual CHIP_ERROR GetFabricAt(size_t index, FabricIndex &fabric_index) = 0;

/**
* @brief Set the storage implementation used for non-volatile storage of configuration data.
Expand Down
10 changes: 10 additions & 0 deletions src/credentials/GroupDataProviderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,16 @@ void GroupDataProviderImpl::Finish()
mGroupKeyContexPool.ReleaseAll();
}

CHIP_ERROR GroupDataProviderImpl::GetFabricCount(size_t &count)
{
return CHIP_NO_ERROR;
}

CHIP_ERROR GroupDataProviderImpl::GetFabricAt(size_t index, FabricIndex &fabric_index)
{
return CHIP_NO_ERROR;
}

//
// Group Info
//
Expand Down
2 changes: 2 additions & 0 deletions src/credentials/GroupDataProviderImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class GroupDataProviderImpl : public GroupDataProviderBase

CHIP_ERROR Init() override;
void Finish() override;
CHIP_ERROR GetFabricCount(size_t &count) override;
CHIP_ERROR GetFabricAt(size_t index, FabricIndex &fabric_index) override;

//
// Group Info
Expand Down
75 changes: 75 additions & 0 deletions src/credentials/GroupDataProviderMigration.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include <platform/silabs/MigrationManager.h>
#include <credentials/GroupDataProviderImpl.h>
#include <credentials/GroupDataProviderV2.h>
#include <app/server/Server.h>

namespace chip {
namespace DeviceLayer {
namespace Silabs {

using namespace chip::Credentials;

void MigrateGroupKVS(void)
{
GroupDataProviderImpl provider1;
GroupDataProviderV2 provider2;

ChipLogProgress(Zcl, "~~~ FABRICS(%u)", (unsigned) Server::GetInstance().GetFabricTable().FabricCount());

for (auto & fabric : Server::GetInstance().GetFabricTable())
{
auto fabric_index = fabric.GetFabricIndex();
ChipLogProgress(Zcl, "~~~ FABRIC[%u]", (unsigned) fabric_index);

// GroupInfo
size_t index = 0;
GroupDataProvider::GroupInfo group;
auto it = provider1.IterateGroupInfo(fabric_index);
while (it->Next(group))
{
ChipLogProgress(Zcl, "~~~ GROUP(%u)", (unsigned) group.group_id);
provider2.SetGroupInfoAt(fabric_index, index++, group);
}
it->Release();

// Endpoints
GroupDataProvider::GroupEndpoint endpoint;
auto it2 = provider1.IterateEndpoints(fabric_index);
while (it2->Next(endpoint))
{
ChipLogProgress(Zcl, "~~~ END(%u)", (unsigned) endpoint.endpoint_id);
provider2.AddEndpoint(fabric_index, endpoint.group_id, endpoint.endpoint_id);
}
it2->Release();

// GroupKeys
index = 0;
GroupDataProvider::GroupKey pair;
auto it3 = provider1.IterateGroupKeys(fabric_index);
while (it3->Next(pair))
{
ChipLogProgress(Zcl, "~~~ KEYS(%u)", (unsigned) pair.keyset_id);
provider2.SetGroupKeyAt(fabric_index, index++, pair);
}
it3->Release();

// KeySet
index = 0;
GroupDataProvider::KeySet keyset;
auto it4 = provider1.IterateKeySets(fabric_index);
while (it4->Next(keyset))
{
ChipLogProgress(Zcl, "~~~ KEYS(%u)", (unsigned) keyset.keyset_id);
// FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME
auto compressedFabric = ByteSpan();
provider2.SetKeySet(fabric_index, compressedFabric, keyset);
}
it4->Release();
}


}

} // namespace Silabs
} // namespace DeviceLayer
} // namespace chip
10 changes: 10 additions & 0 deletions src/credentials/GroupDataProviderV2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,16 @@ void GroupDataProviderV2::Finish()
mGroupKeyContexPool.ReleaseAll();
}

CHIP_ERROR GroupDataProviderV2::GetFabricCount(size_t &count)
{
return CHIP_NO_ERROR;
}

CHIP_ERROR GroupDataProviderV2::GetFabricAt(size_t index, FabricIndex &fabric_index)
{
return CHIP_NO_ERROR;
}

//
// Group Info
//
Expand Down
2 changes: 2 additions & 0 deletions src/credentials/GroupDataProviderV2.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class GroupDataProviderV2 : public GroupDataProviderBase

CHIP_ERROR Init() override;
void Finish() override;
CHIP_ERROR GetFabricCount(size_t &count) override;
CHIP_ERROR GetFabricAt(size_t index, FabricIndex &fabric_index) override;

//
// Group Info
Expand Down
1 change: 1 addition & 0 deletions src/platform/silabs/MigrationManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ static migrationData_t migrationTable[] = {
{ .migrationGroup = 1, .migrationFunc = MigrateKvsMap },
{ .migrationGroup = 2, .migrationFunc = MigrateDacProvider },
{ .migrationGroup = 3, .migrationFunc = MigrateCounterConfigs },
{ .migrationGroup = 4, .migrationFunc = MigrateGroupKVS },
// add any additional migration neccesary. migrationGroup should stay equal if done in the same commit or increment by 1 for
// each new entry.
};
Expand Down
1 change: 1 addition & 0 deletions src/platform/silabs/MigrationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class MigrationManager
void MigrateKvsMap(void);
void MigrateDacProvider(void);
void MigrateCounterConfigs(void);
void MigrateGroupKVS(void);

} // namespace Silabs
} // namespace DeviceLayer
Expand Down

0 comments on commit 9cdcd7c

Please sign in to comment.