Skip to content

Commit 5e86f37

Browse files
committed
Added implementations for the JF Administrator and Datastore Servers
1 parent f4d171a commit 5e86f37

File tree

7 files changed

+697
-22
lines changed

7 files changed

+697
-22
lines changed

scripts/tools/check_includes_config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,4 +198,8 @@
198198
'src/access/AccessRestrictionProvider.h': {'vector', 'map'},
199199
# nrfconnect test runner
200200
'src/test_driver/nrfconnect/main/runner.cpp': {'vector'},
201+
202+
# Not intended for embedded clients
203+
'src/app/server/JointFabricDatastore.cpp': {'vector'},
204+
'src/app/server/JointFabricDatastore.h': {'vector'},
201205
}

src/app/clusters/joint-fabric-administrator-server/joint-fabric-administrator-server.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,9 @@ CHIP_ERROR JointFabricAdministratorAttrAccess::Read(const ConcreteReadAttributeP
9191
return CHIP_NO_ERROR;
9292
}
9393

94-
// TODO
9594
CHIP_ERROR JointFabricAdministratorAttrAccess::ReadAdministratorFabricIndex(AttributeValueEncoder & aEncoder)
9695
{
97-
return CHIP_ERROR_NOT_IMPLEMENTED;
96+
return aEncoder.Encode(Server::GetInstance().GetJointFabricDatastore().GetAdministratorFabricIndex());
9897
}
9998

10099
void MatterJointFabricAdministratorPluginServerInitCallback()

src/app/clusters/joint-fabric-datastore-server/joint-fabric-datastore-server.cpp

Lines changed: 203 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@ using chip::Protocols::InteractionModel::Status;
3535

3636
namespace JointFabricDatastoreCluster = chip::app::Clusters::JointFabricDatastore;
3737

38-
class JointFabricDatastoreAttrAccess : public AttributeAccessInterface
38+
class JointFabricDatastoreAttrAccess : public AttributeAccessInterface, public app::JointFabricDatastore::Listener
3939
{
4040
public:
4141
JointFabricDatastoreAttrAccess() : AttributeAccessInterface(Optional<EndpointId>::Missing(), JointFabricDatastoreCluster::Id) {}
4242

4343
CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override;
4444

45+
void MarkNodeListChanged() override;
46+
4547
private:
4648
CHIP_ERROR ReadAnchorNodeId(AttributeValueEncoder & aEncoder);
4749
CHIP_ERROR ReadAnchorVendorId(AttributeValueEncoder & aEncoder);
@@ -81,41 +83,94 @@ CHIP_ERROR JointFabricDatastoreAttrAccess::Read(const ConcreteReadAttributePath
8183
return CHIP_NO_ERROR;
8284
}
8385

84-
// TODO
8586
CHIP_ERROR JointFabricDatastoreAttrAccess::ReadAnchorNodeId(AttributeValueEncoder & aEncoder)
8687
{
87-
return CHIP_ERROR_NOT_IMPLEMENTED;
88+
NodeId anchorNodeId = Server::GetInstance().GetJointFabricDatastore().GetAnchorNodeId();
89+
ReturnErrorOnFailure(aEncoder.Encode(anchorNodeId));
90+
return CHIP_NO_ERROR;
8891
}
8992

90-
// TODO
9193
CHIP_ERROR JointFabricDatastoreAttrAccess::ReadAnchorVendorId(AttributeValueEncoder & aEncoder)
9294
{
93-
return CHIP_ERROR_NOT_IMPLEMENTED;
95+
VendorId anchorVendorId = Server::GetInstance().GetJointFabricDatastore().GetAnchorVendorId();
96+
ReturnErrorOnFailure(aEncoder.Encode(anchorVendorId));
97+
return CHIP_NO_ERROR;
9498
}
9599

96-
// TODO
97100
CHIP_ERROR JointFabricDatastoreAttrAccess::ReadGroupKeySetList(AttributeValueEncoder & aEncoder)
98101
{
99-
return CHIP_ERROR_NOT_IMPLEMENTED;
102+
return aEncoder.EncodeList([&](const auto & encoder) -> CHIP_ERROR {
103+
auto entries = Server::GetInstance().GetJointFabricDatastore().GetGroupKeySetList();
104+
105+
for (auto & entry : entries)
106+
{
107+
ReturnErrorOnFailure(encoder.Encode(entry));
108+
}
109+
return CHIP_NO_ERROR;
110+
});
100111
}
101112

102-
// TODO
103113
CHIP_ERROR JointFabricDatastoreAttrAccess::ReadAdminList(AttributeValueEncoder & aEncoder)
104114
{
105-
return CHIP_ERROR_NOT_IMPLEMENTED;
115+
return aEncoder.EncodeList([&](const auto & encoder) -> CHIP_ERROR {
116+
auto entries = Server::GetInstance().GetJointFabricDatastore().GetAdminEntries();
117+
118+
for (auto & entry : entries)
119+
{
120+
ReturnErrorOnFailure(encoder.Encode(entry));
121+
}
122+
return CHIP_NO_ERROR;
123+
});
106124
}
107125

108-
// TODO
109126
CHIP_ERROR JointFabricDatastoreAttrAccess::ReadNodeList(AttributeValueEncoder & aEncoder)
110127
{
111-
return CHIP_ERROR_NOT_IMPLEMENTED;
128+
return aEncoder.EncodeList([&](const auto & encoder) -> CHIP_ERROR {
129+
auto entries = Server::GetInstance().GetJointFabricDatastore().GetNodeInformationEntries();
130+
131+
for (auto & entry : entries)
132+
{
133+
ReturnErrorOnFailure(encoder.Encode(entry));
134+
}
135+
return CHIP_NO_ERROR;
136+
});
137+
}
138+
139+
void JointFabricDatastoreAttrAccess::MarkNodeListChanged()
140+
{
141+
MatterReportingAttributeChangeCallback(kRootEndpointId, JointFabricDatastoreCluster::Id,
142+
JointFabricDatastoreCluster::Attributes::NodeList::Id);
112143
}
113144

114-
// TODO
115145
bool emberAfJointFabricDatastoreClusterAddAdminCallback(
116146
CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
117147
const JointFabricDatastoreCluster::Commands::AddAdmin::DecodableType & commandData)
118148
{
149+
CHIP_ERROR err = CHIP_NO_ERROR;
150+
app::JointFabricDatastore & jointFabricDatastore = Server::GetInstance().GetJointFabricDatastore();
151+
152+
auto nodeID = commandData.nodeID;
153+
auto friendlyName = commandData.friendlyName;
154+
auto vendorID = commandData.vendorID;
155+
auto icac = commandData.icac;
156+
157+
JointFabricDatastoreCluster::Structs::DatastoreAdministratorInformationEntryStruct::DecodableType adminInformationEntry = {
158+
.nodeID = nodeID, .friendlyName = friendlyName, .vendorID = vendorID, .icac = icac
159+
};
160+
161+
SuccessOrExit(err = jointFabricDatastore.AddAdmin(adminInformationEntry));
162+
163+
exit:
164+
if (err == CHIP_NO_ERROR)
165+
{
166+
commandObj->AddStatus(commandPath, Protocols::InteractionModel::Status::Success);
167+
}
168+
else
169+
{
170+
ChipLogError(DataManagement, "JointFabricDatastoreCluster: failed with error: %" CHIP_ERROR_FORMAT, err.Format());
171+
commandObj->AddStatus(commandPath, Protocols::InteractionModel::ClusterStatusCode(err));
172+
}
173+
119174
return true;
120175
}
121176

@@ -127,43 +182,121 @@ bool emberAfJointFabricDatastoreClusterAddGroupCallback(
127182
return true;
128183
}
129184

130-
// TODO
131185
bool emberAfJointFabricDatastoreClusterAddKeySetCallback(
132186
CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
133187
const JointFabricDatastoreCluster::Commands::AddKeySet::DecodableType & commandData)
134188
{
189+
CHIP_ERROR err = CHIP_NO_ERROR;
190+
JointFabricDatastoreCluster::Structs::DatastoreGroupKeySetStruct::DecodableType groupKeySet = commandData.groupKeySet;
191+
app::JointFabricDatastore & jointFabricDatastore = Server::GetInstance().GetJointFabricDatastore();
192+
193+
VerifyOrExit(jointFabricDatastore.IsGroupKeySetEntryPresent(groupKeySet.groupKeySetID) == false,
194+
err = CHIP_ERROR_INVALID_ARGUMENT);
195+
SuccessOrExit(err = jointFabricDatastore.AddGroupKeySetEntry(groupKeySet));
196+
197+
exit:
198+
if (err == CHIP_NO_ERROR)
199+
{
200+
commandObj->AddStatus(commandPath, Protocols::InteractionModel::Status::Success);
201+
}
202+
else
203+
{
204+
ChipLogError(DataManagement, "JointFabricDatastoreCluster: failed with error: %" CHIP_ERROR_FORMAT, err.Format());
205+
commandObj->AddStatus(commandPath, Protocols::InteractionModel::ClusterStatusCode(err));
206+
}
207+
135208
return true;
136209
}
137210

138-
// TODO
139211
bool emberAfJointFabricDatastoreClusterRemoveNodeCallback(
140212
CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
141213
const JointFabricDatastoreCluster::Commands::RemoveNode::DecodableType & commandData)
142214
{
215+
NodeId nodeId = commandData.nodeID;
216+
217+
CHIP_ERROR err = Server::GetInstance().GetJointFabricDatastore().RemoveNode(nodeId);
218+
219+
if (err == CHIP_NO_ERROR)
220+
{
221+
commandObj->AddStatus(commandPath, Protocols::InteractionModel::Status::Success);
222+
}
223+
else
224+
{
225+
ChipLogError(DataManagement, "JointFabricDatastoreCluster: failed with error: %" CHIP_ERROR_FORMAT, err.Format());
226+
commandObj->AddStatus(commandPath, Protocols::InteractionModel::ClusterStatusCode(err));
227+
}
228+
143229
return true;
144230
}
145231

146-
// TODO
147232
bool emberAfJointFabricDatastoreClusterUpdateNodeCallback(
148233
CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
149234
const JointFabricDatastoreCluster::Commands::UpdateNode::DecodableType & commandData)
150235
{
236+
NodeId nodeId = commandData.nodeID;
237+
const CharSpan & friendlyName = commandData.friendlyName;
238+
239+
CHIP_ERROR err = Server::GetInstance().GetJointFabricDatastore().UpdateNode(nodeId, friendlyName);
240+
241+
if (err == CHIP_NO_ERROR)
242+
{
243+
commandObj->AddStatus(commandPath, Protocols::InteractionModel::Status::Success);
244+
}
245+
else
246+
{
247+
ChipLogError(DataManagement, "JointFabricDatastoreCluster: failed with error: %" CHIP_ERROR_FORMAT, err.Format());
248+
commandObj->AddStatus(commandPath, Protocols::InteractionModel::ClusterStatusCode(err));
249+
}
250+
151251
return true;
152252
}
153253

154-
// TODO
155254
bool emberAfJointFabricDatastoreClusterRefreshNodeCallback(
156255
CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
157256
const JointFabricDatastoreCluster::Commands::RefreshNode::DecodableType & commandData)
158257
{
258+
CHIP_ERROR err = CHIP_NO_ERROR;
259+
NodeId nodeId = commandData.nodeID;
260+
261+
app::JointFabricDatastore & jointFabricDatastore = Server::GetInstance().GetJointFabricDatastore();
262+
263+
SuccessOrExit(err = jointFabricDatastore.RefreshNode(nodeId));
264+
265+
exit:
266+
if (err == CHIP_NO_ERROR)
267+
{
268+
commandObj->AddStatus(commandPath, Protocols::InteractionModel::Status::Success);
269+
}
270+
else
271+
{
272+
ChipLogError(DataManagement, "JointFabricDatastoreCluster: failed with error: %" CHIP_ERROR_FORMAT, err.Format());
273+
commandObj->AddStatus(commandPath, Protocols::InteractionModel::ClusterStatusCode(err));
274+
}
275+
159276
return true;
160277
}
161278

162-
// TODO
163279
bool emberAfJointFabricDatastoreClusterRemoveAdminCallback(
164280
CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
165281
const JointFabricDatastoreCluster::Commands::RemoveAdmin::DecodableType & commandData)
166282
{
283+
CHIP_ERROR err = CHIP_NO_ERROR;
284+
auto nodeId = commandData.nodeID;
285+
app::JointFabricDatastore & jointFabricDatastore = Server::GetInstance().GetJointFabricDatastore();
286+
287+
SuccessOrExit(err = jointFabricDatastore.RemoveAdmin(nodeId));
288+
289+
exit:
290+
if (err == CHIP_NO_ERROR)
291+
{
292+
commandObj->AddStatus(commandPath, Protocols::InteractionModel::Status::Success);
293+
}
294+
else
295+
{
296+
ChipLogError(DataManagement, "JointFabricDatastoreCluster: failed with error: %" CHIP_ERROR_FORMAT, err.Format());
297+
commandObj->AddStatus(commandPath, Protocols::InteractionModel::ClusterStatusCode(err));
298+
}
299+
167300
return true;
168301
}
169302

@@ -175,11 +308,29 @@ bool emberAfJointFabricDatastoreClusterRemoveGroupCallback(
175308
return true;
176309
}
177310

178-
// TODO
179311
bool emberAfJointFabricDatastoreClusterUpdateAdminCallback(
180312
CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
181313
const JointFabricDatastoreCluster::Commands::UpdateAdmin::DecodableType & commandData)
182314
{
315+
CHIP_ERROR err = CHIP_NO_ERROR;
316+
auto nodeId = commandData.nodeID.Value();
317+
auto friendlyName = commandData.friendlyName.Value();
318+
auto icac = commandData.icac.Value();
319+
app::JointFabricDatastore & jointFabricDatastore = Server::GetInstance().GetJointFabricDatastore();
320+
321+
SuccessOrExit(err = jointFabricDatastore.UpdateAdmin(nodeId, friendlyName, icac));
322+
323+
exit:
324+
if (err == CHIP_NO_ERROR)
325+
{
326+
commandObj->AddStatus(commandPath, Protocols::InteractionModel::Status::Success);
327+
}
328+
else
329+
{
330+
ChipLogError(DataManagement, "JointFabricDatastoreCluster: failed with error: %" CHIP_ERROR_FORMAT, err.Format());
331+
commandObj->AddStatus(commandPath, Protocols::InteractionModel::ClusterStatusCode(err));
332+
}
333+
183334
return true;
184335
}
185336

@@ -199,11 +350,27 @@ bool emberAfJointFabricDatastoreClusterAddACLToNodeCallback(
199350
return true;
200351
}
201352

202-
// TODO
203353
bool emberAfJointFabricDatastoreClusterRemoveKeySetCallback(
204354
CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
205355
const JointFabricDatastoreCluster::Commands::RemoveKeySet::DecodableType & commandData)
206356
{
357+
CHIP_ERROR err = CHIP_NO_ERROR;
358+
uint16_t groupKeySetId = commandData.groupKeySetID;
359+
app::JointFabricDatastore & jointFabricDatastore = Server::GetInstance().GetJointFabricDatastore();
360+
361+
SuccessOrExit(err = jointFabricDatastore.RemoveGroupKeySetEntry(groupKeySetId));
362+
363+
exit:
364+
if (err == CHIP_NO_ERROR)
365+
{
366+
commandObj->AddStatus(commandPath, Protocols::InteractionModel::Status::Success);
367+
}
368+
else
369+
{
370+
ChipLogError(DataManagement, "JointFabricDatastoreCluster: failed with error: %" CHIP_ERROR_FORMAT, err.Format());
371+
commandObj->AddStatus(commandPath, Protocols::InteractionModel::ClusterStatusCode(err));
372+
}
373+
207374
return true;
208375
}
209376

@@ -215,11 +382,25 @@ bool emberAfJointFabricDatastoreClusterUpdateKeySetCallback(
215382
return true;
216383
}
217384

218-
// TODO
219385
bool emberAfJointFabricDatastoreClusterAddPendingNodeCallback(
220386
CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
221387
const JointFabricDatastoreCluster::Commands::AddPendingNode::DecodableType & commandData)
222388
{
389+
NodeId nodeId = commandData.nodeID;
390+
const CharSpan & friendlyName = commandData.friendlyName;
391+
392+
CHIP_ERROR err = Server::GetInstance().GetJointFabricDatastore().AddPendingNode(nodeId, friendlyName);
393+
394+
if (err == CHIP_NO_ERROR)
395+
{
396+
commandObj->AddStatus(commandPath, Protocols::InteractionModel::Status::Success);
397+
}
398+
else
399+
{
400+
ChipLogError(DataManagement, "JointFabricDatastoreCluster: failed with error: %" CHIP_ERROR_FORMAT, err.Format());
401+
commandObj->AddStatus(commandPath, Protocols::InteractionModel::ClusterStatusCode(err));
402+
}
403+
223404
return true;
224405
}
225406

@@ -275,4 +456,6 @@ void MatterJointFabricDatastorePluginServerInitCallback()
275456
{
276457
ChipLogProgress(Zcl, "Initiating Joint Fabric Datastore cluster.");
277458
AttributeAccessInterfaceRegistry::Instance().Register(&gJointFabricDatastoreAttrAccess);
459+
460+
Server::GetInstance().GetJointFabricDatastore().AddListener(gJointFabricDatastoreAttrAccess);
278461
}

src/app/server/BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ static_library("server") {
5757
"Dnssd.h",
5858
"EchoHandler.cpp",
5959
"EchoHandler.h",
60+
"JointFabricDatastore.cpp",
61+
"JointFabricDatastore.h",
6062
"Server.cpp",
6163
"Server.h",
6264
]

0 commit comments

Comments
 (0)