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

Persisting Group Data Provider implemented. #12047

Merged
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
50 changes: 22 additions & 28 deletions src/app/clusters/groups-server/groups-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,28 +85,6 @@ static bool GroupExists(FabricIndex fabricIndex, EndpointId endpointId, GroupId
return provider->GroupMappingExists(fabricIndex, mapping);
}

static bool GroupFind(FabricIndex fabricIndex, EndpointId endpointId, GroupId groupId, CharSpan & name)
{
GroupDataProvider * provider = GetGroupDataProvider();
VerifyOrReturnError(nullptr != provider, false);

auto * groupIt = provider->IterateGroupMappings(fabricIndex, endpointId);
VerifyOrReturnError(nullptr != groupIt, false);

GroupDataProvider::GroupMapping mapping;
bool found = false;
while (!found && groupIt->Next(mapping))
{
if (mapping.group == groupId)
{
name = mapping.name;
found = true;
}
}
groupIt->Release();
return found;
}

static EmberAfStatus GroupAdd(FabricIndex fabricIndex, EndpointId endpointId, GroupId groupId, const CharSpan & groupName)
{
VerifyOrReturnError(IsFabricGroupId(groupId), EMBER_ZCL_STATUS_INVALID_VALUE);
Expand Down Expand Up @@ -217,22 +195,38 @@ bool emberAfGroupsClusterViewGroupCallback(app::CommandHandler * commandObj, con
auto groupId = commandData.groupId;
auto endpointId = commandPath.mEndpointId;

GroupDataProvider::GroupMapping mapping;
EmberAfStatus status = EMBER_ZCL_STATUS_NOT_FOUND;
CHIP_ERROR err = CHIP_NO_ERROR;
CharSpan groupName;
size_t nameSize = 0;

if (emberAfCurrentCommand()->type != EMBER_INCOMING_UNICAST && emberAfCurrentCommand()->type != EMBER_INCOMING_UNICAST_REPLY)
{
return true;
}

if (!IsFabricGroupId(groupId))
if (IsFabricGroupId(groupId))
{
status = EMBER_ZCL_STATUS_INVALID_VALUE;
GroupDataProvider * provider = GetGroupDataProvider();
VerifyOrReturnError(nullptr != provider, false);
rcasallas-silabs marked this conversation as resolved.
Show resolved Hide resolved

auto * groupIt = provider->IterateGroupMappings(fabricIndex, endpointId);
VerifyOrReturnError(nullptr != groupIt, false);

while (groupIt->Next(mapping))
{
if (mapping.group == groupId)
{
nameSize = strnlen(mapping.name, GroupDataProvider::GroupMapping::kGroupNameMax);
status = EMBER_ZCL_STATUS_SUCCESS;
break;
}
}
groupIt->Release();
}
else if (GroupFind(fabricIndex, endpointId, groupId, groupName))
else
{
status = EMBER_ZCL_STATUS_SUCCESS;
status = EMBER_ZCL_STATUS_INVALID_VALUE;
}

{
Expand All @@ -243,7 +237,7 @@ bool emberAfGroupsClusterViewGroupCallback(app::CommandHandler * commandObj, con
VerifyOrExit((writer = commandObj->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
SuccessOrExit(err = writer->Put(TLV::ContextTag(0), status));
SuccessOrExit(err = writer->Put(TLV::ContextTag(1), groupId));
SuccessOrExit(err = writer->PutString(TLV::ContextTag(2), groupName.data(), static_cast<uint32_t>(groupName.size())));
SuccessOrExit(err = writer->PutString(TLV::ContextTag(2), mapping.name, static_cast<uint32_t>(nameSize)));
rcasallas-silabs marked this conversation as resolved.
Show resolved Hide resolved
SuccessOrExit(err = commandObj->FinishCommand());
}
exit:
Expand Down
5 changes: 5 additions & 0 deletions src/app/server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ CHIP_ERROR Server::Init(AppDelegate * delegate, uint16_t secureServicePort, uint
err = mFabrics.Init(&mServerStorage);
SuccessOrExit(err);

// Group data provider must be initialized after mServerStorage
err = mGroupsProvider.Init();
rcasallas-silabs marked this conversation as resolved.
Show resolved Hide resolved
SuccessOrExit(err);
SetGroupDataProvider(&mGroupsProvider);

// Init transport before operations with secure session mgr.
err = mTransports.Init(
UdpListenParameters(&DeviceLayer::InetLayer()).SetAddressType(IPAddressType::kIPv6).SetListenPort(mSecuredServicePort)
Expand Down
12 changes: 10 additions & 2 deletions src/app/server/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
#include <app/server/AppDelegate.h>
#include <app/server/CommissioningWindowManager.h>
#include <credentials/FabricTable.h>
#include <credentials/GroupDataProviderImpl.h>
#include <inet/InetConfig.h>
#include <lib/support/TestPersistentStorageDelegate.h>
#include <messaging/ExchangeMgr.h>
#include <platform/KeyValueStoreManager.h>
#include <protocols/secure_channel/CASEServer.h>
Expand Down Expand Up @@ -90,7 +92,7 @@ class Server
static Server & GetInstance() { return sServer; }

private:
Server() : mCommissioningWindowManager(this) {}
Server() : mCommissioningWindowManager(this), mGroupsProvider(mGroupsStorage) {}

static Server sServer;

Expand Down Expand Up @@ -145,9 +147,15 @@ class Server
chip::Protocols::UserDirectedCommissioning::UserDirectedCommissioningClient gUDCClient;
#endif // CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY_CLIENT
SecurePairingUsingTestSecret mTestPairing;
CommissioningWindowManager mCommissioningWindowManager;

// Both PersistentStorageDelegate, and GroupDataProvider should be injected by the applications
// See: https://github.com/project-chip/connectedhomeip/issues/12276
ServerStorageDelegate mServerStorage;
CommissioningWindowManager mCommissioningWindowManager;
// Currently, the GroupDataProvider cannot use KeyValueStoreMgr() due to
// (https://github.com/project-chip/connectedhomeip/issues/12174)
TestPersistentStorageDelegate mGroupsStorage;
Credentials::GroupDataProviderImpl mGroupsProvider;

chip::OperationalDeviceProxy * mOperationalDeviceProxy = nullptr;

Expand Down
56 changes: 17 additions & 39 deletions src/app/tests/suites/TestGroupsCluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,20 @@ tests:
- name: "groupId"
value: 0x1111

- label: "Get Group Membership 1 (all)"
command: "GetGroupMembership"
arguments:
values:
- name: "groupList"
value: []
response:
values:
- name: "capacity"
value: 0xff
- name: "groupList"
value: [0x01]

- label: "Add Group 2 (new)"
# https://github.com/project-chip/connectedhomeip/issues/11312
disabled: true
command: "AddGroup"
arguments:
values:
Expand All @@ -110,8 +121,6 @@ tests:
value: 0x1111

- label: "View Group 2 (new)"
# https://github.com/project-chip/connectedhomeip/issues/11312
disabled: true
command: "ViewGroup"
arguments:
values:
Expand Down Expand Up @@ -140,8 +149,6 @@ tests:
value: 0x7fff

- label: "Add Group 3 (new)"
# https://github.com/project-chip/connectedhomeip/issues/11312
disabled: true
command: "AddGroup"
arguments:
values:
Expand Down Expand Up @@ -172,8 +179,6 @@ tests:
value: "Group #1"

- label: "View Group 2 (existing)"
# https://github.com/project-chip/connectedhomeip/issues/11312
disabled: true
command: "ViewGroup"
arguments:
values:
Expand All @@ -188,39 +193,20 @@ tests:
- name: "groupName"
value: "Group #2"

- label: "Get Group Membership 1"
# https://github.com/project-chip/connectedhomeip/issues/11312
disabled: true
command: "GetGroupMembership"
arguments:
values:
- name: "groupList"
value: [0x01, 0x02, 0x03, 0x7fff]
response:
values:
- name: "capacity"
value: 0xff
- name: "groupList"
value: [0x01, 0x7fff]

- label: "Get Group Membership 2"
# https://github.com/project-chip/connectedhomeip/issues/11312
disabled: true
command: "GetGroupMembership"
arguments:
values:
- name: "groupList"
value: []
value: [0x02, 0x03, 0x7fff]
response:
values:
- name: "capacity"
value: 0xff
- name: "groupList"
value: [0x01, 0x1111, 0x7fff]
value: [0x7fff]

- label: "View Group 3 (new)"
# https://github.com/project-chip/connectedhomeip/issues/11312
disabled: true
command: "ViewGroup"
arguments:
values:
Expand Down Expand Up @@ -262,8 +248,6 @@ tests:
value: 0x04

- label: "Remove Group 2 (existing)"
# https://github.com/project-chip/connectedhomeip/issues/11312
disabled: true
command: "RemoveGroup"
arguments:
values:
Expand Down Expand Up @@ -305,8 +289,6 @@ tests:
value: 0x1111

- label: "View Group 3 (not removed)"
# https://github.com/project-chip/connectedhomeip/issues/11312
disabled: true
command: "ViewGroup"
arguments:
values:
Expand All @@ -322,19 +304,17 @@ tests:
value: "Group #3"

- label: "Get Group Membership 3"
# https://github.com/project-chip/connectedhomeip/issues/11312
disabled: true
command: "GetGroupMembership"
arguments:
values:
- name: "groupList"
value: [0x01, 0x02, 0x1111, 0x03, 0x7fff]
value: [0x01, 0x02, 0x1111, 0x03]
response:
values:
- name: "capacity"
value: 0xff
- name: "groupList"
value: [0x01, 0x7fff]
value: [0x01]

- label: "Remove All"
command: "RemoveAllGroups"
Expand Down Expand Up @@ -379,8 +359,6 @@ tests:
value: 0x7fff

- label: "Get Group Membership 4"
# https://github.com/project-chip/connectedhomeip/issues/11495
disabled: true
command: "GetGroupMembership"
arguments:
values:
Expand Down
2 changes: 1 addition & 1 deletion src/credentials/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ static_library("credentials") {
"FabricTable.h",
"GenerateChipX509Cert.cpp",
"GroupDataProvider.h",
"GroupDataProviderImpl.cpp",
rcasallas-silabs marked this conversation as resolved.
Show resolved Hide resolved
"examples/DefaultDeviceAttestationVerifier.cpp",
"examples/DefaultDeviceAttestationVerifier.h",
"examples/DeviceAttestationCredsExample.cpp",
"examples/DeviceAttestationCredsExample.h",
"examples/GroupDataProviderExample.cpp",
]

if (chip_with_se05x == 1) {
Expand Down
Loading