Skip to content

Commit

Permalink
RemoveEndpoint(fabric, endpoint) now removes the group when it has no…
Browse files Browse the repository at this point in the history
… more endpoints. (#19768)
  • Loading branch information
rcasallas-silabs authored and pull[bot] committed Jul 20, 2023
1 parent 5f65a6b commit 1121776
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 43 deletions.
6 changes: 6 additions & 0 deletions src/app/tests/suites/TestGroupKeyManagementCluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,12 @@ tests:
endpoint: 1
command: "RemoveAllGroups"

- label: "Read GroupTable 3"
command: "readAttribute"
attribute: "GroupTable"
response:
value: []

- label: "KeySet Remove 2"
command: "KeySetRemove"
arguments:
Expand Down
39 changes: 7 additions & 32 deletions src/credentials/GroupDataProviderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,8 @@ CHIP_ERROR GroupDataProviderImpl::SetGroupInfoAt(chip::FabricIndex fabric_index,
bool found = group.Find(mStorage, fabric, info.group_id);
VerifyOrReturnError(!found || (group.index == index), CHIP_ERROR_DUPLICATE_KEY_ID);

group.group_id = info.group_id;
group.group_id = info.group_id;
group.endpoint_count = 0;
group.SetName(info.name);

if (found)
Expand Down Expand Up @@ -1208,6 +1209,7 @@ CHIP_ERROR GroupDataProviderImpl::RemoveEndpoint(chip::FabricIndex fabric_index,

GroupData group(fabric_index, fabric.first_group);
size_t group_index = 0;
EndpointData endpoint;

// Loop through all the groups
while (group_index < fabric.group_count)
Expand All @@ -1216,39 +1218,12 @@ CHIP_ERROR GroupDataProviderImpl::RemoveEndpoint(chip::FabricIndex fabric_index,
{
break;
}
EndpointData endpoint(fabric_index, group.group_id, group.first_endpoint);
EndpointData prev_endpoint;
size_t endpoint_index = 0;
while (endpoint_index < group.endpoint_count)
if (endpoint.Find(mStorage, fabric, group, endpoint_id))
{
if (CHIP_NO_ERROR != endpoint.Load(mStorage))
{
break;
}
if (endpoint.endpoint_id == endpoint_id)
{
// Remove endpoint from curent group
if (0 == endpoint_index)
{
// Remove first
group.first_endpoint = endpoint.next;
}
else
{
prev_endpoint.next = endpoint.next;
ReturnErrorOnFailure(prev_endpoint.Save(mStorage));
}
endpoint.Delete(mStorage);
if (group.endpoint_count > 0)
{
group.endpoint_count--;
}
ReturnErrorOnFailure(group.Save(mStorage));
}
prev_endpoint = endpoint;
endpoint.endpoint_id = endpoint.next;
endpoint_index++;
// Endpoint found in group
ReturnErrorOnFailure(RemoveEndpoint(fabric_index, group.group_id, endpoint_id));
}

group.group_id = group.next;
group_index++;
}
Expand Down
26 changes: 22 additions & 4 deletions zzz_generated/chip-tool/zap-generated/test/Commands.h

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

48 changes: 41 additions & 7 deletions zzz_generated/darwin-framework-tool/zap-generated/test/Commands.h

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

0 comments on commit 1121776

Please sign in to comment.