Skip to content

Commit a902838

Browse files
[FabricAdmin] Refactor FS specific attribute handlings out of general HandleAttributeData function (#35080)
* [FabricAdmin] Refactor attribute Data handling * Use reference to pass chip::TLV::TLVReader * Update examples/fabric-admin/device_manager/DeviceManager.h Co-authored-by: Terence Hampson <thampson@google.com> * Update function name --------- Co-authored-by: Terence Hampson <thampson@google.com>
1 parent 20caa91 commit a902838

File tree

4 files changed

+94
-85
lines changed

4 files changed

+94
-85
lines changed

examples/fabric-admin/commands/clusters/ClusterCommand.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class ClusterCommand : public InteractionModelCommands, public ModelCommand, pub
8484
if (data != nullptr)
8585
{
8686
LogErrorOnFailure(RemoteDataModelLogger::LogCommandAsJSON(path, data));
87-
DeviceMgr().HandleCommandResponse(path, data);
87+
DeviceMgr().HandleCommandResponse(path, *data);
8888
}
8989
}
9090

examples/fabric-admin/commands/clusters/ReportCommand.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void ReportCommand::OnAttributeData(const app::ConcreteDataAttributePath & path,
4646

4747
LogErrorOnFailure(RemoteDataModelLogger::LogAttributeAsJSON(path, data));
4848

49-
DeviceMgr().HandleAttributeData(path, data);
49+
DeviceMgr().HandleAttributeData(path, *data);
5050
}
5151

5252
void ReportCommand::OnEventData(const app::EventHeader & eventHeader, TLV::TLVReader * data, const app::StatusIB * status)
@@ -73,5 +73,5 @@ void ReportCommand::OnEventData(const app::EventHeader & eventHeader, TLV::TLVRe
7373

7474
LogErrorOnFailure(RemoteDataModelLogger::LogEventAsJSON(eventHeader, data));
7575

76-
DeviceMgr().HandleEventData(eventHeader, data);
76+
DeviceMgr().HandleEventData(eventHeader, *data);
7777
}

examples/fabric-admin/device_manager/DeviceManager.cpp

+82-77
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,25 @@ void DeviceManager::ReadSupportedDeviceCategories()
237237
PushCommand(commandBuilder.c_str());
238238
}
239239

240+
void DeviceManager::HandleReadSupportedDeviceCategories(chip::TLV::TLVReader & data)
241+
{
242+
ChipLogProgress(NotSpecified, "Attribute SupportedDeviceCategories detected.");
243+
244+
BitMask<CommissionerControl::SupportedDeviceCategoryBitmap> value;
245+
CHIP_ERROR error = app::DataModel::Decode(data, value);
246+
if (error != CHIP_NO_ERROR)
247+
{
248+
ChipLogError(NotSpecified, "Failed to decode attribute value. Error: %" CHIP_ERROR_FORMAT, error.Format());
249+
return;
250+
}
251+
252+
if (value.Has(CommissionerControl::SupportedDeviceCategoryBitmap::kFabricSynchronization))
253+
{
254+
ChipLogProgress(NotSpecified, "Remote Fabric-Bridge supports Fabric Synchronization, start reverse commissioning.");
255+
RequestCommissioningApproval();
256+
}
257+
}
258+
240259
void DeviceManager::RequestCommissioningApproval()
241260
{
242261
ChipLogProgress(NotSpecified, "Starting reverse commissioning for bridge device: NodeId: " ChipLogFormatX64,
@@ -254,12 +273,12 @@ void DeviceManager::RequestCommissioningApproval()
254273
PushCommand(commandBuilder.c_str());
255274
}
256275

257-
void DeviceManager::HandleCommissioningRequestResult(TLV::TLVReader * data)
276+
void DeviceManager::HandleCommissioningRequestResult(TLV::TLVReader & data)
258277
{
259278
ChipLogProgress(NotSpecified, "CommissioningRequestResult event received.");
260279

261280
CommissionerControl::Events::CommissioningRequestResult::DecodableType value;
262-
CHIP_ERROR error = app::DataModel::Decode(*data, value);
281+
CHIP_ERROR error = app::DataModel::Decode(data, value);
263282
if (error != CHIP_NO_ERROR)
264283
{
265284
ChipLogError(NotSpecified, "Failed to decode event value. Error: %" CHIP_ERROR_FORMAT, error.Format());
@@ -283,82 +302,12 @@ void DeviceManager::HandleCommissioningRequestResult(TLV::TLVReader * data)
283302
SendCommissionNodeRequest(value.requestId, kResponseTimeoutSeconds);
284303
}
285304

286-
void DeviceManager::SendCommissionNodeRequest(uint64_t requestId, uint16_t responseTimeoutSeconds)
287-
{
288-
ChipLogProgress(NotSpecified, "Request the Commissioner Control Server to begin commissioning a previously approved request.");
289-
290-
StringBuilder<kMaxCommandSize> commandBuilder;
291-
commandBuilder.Add("commissionercontrol commission-node ");
292-
commandBuilder.AddFormat("%lu %u %lu %d", requestId, responseTimeoutSeconds, mRemoteBridgeNodeId, kRootEndpointId);
293-
294-
PushCommand(commandBuilder.c_str());
295-
}
296-
297-
void DeviceManager::HandleReverseOpenCommissioningWindow(TLV::TLVReader * data)
305+
void DeviceManager::HandleAttributePartsListUpdate(chip::TLV::TLVReader & data)
298306
{
299-
CommissionerControl::Commands::ReverseOpenCommissioningWindow::DecodableType value;
300-
CHIP_ERROR error = app::DataModel::Decode(*data, value);
301-
if (error != CHIP_NO_ERROR)
302-
{
303-
ChipLogError(NotSpecified, "Failed to decode command response value. Error: %" CHIP_ERROR_FORMAT, error.Format());
304-
return;
305-
}
306-
307-
// Log all fields
308-
ChipLogProgress(NotSpecified, "DecodableType fields:");
309-
ChipLogProgress(NotSpecified, " commissioningTimeout: %u", value.commissioningTimeout);
310-
ChipLogProgress(NotSpecified, " discriminator: %u", value.discriminator);
311-
ChipLogProgress(NotSpecified, " iterations: %u", value.iterations);
312-
313-
char verifierHex[Crypto::kSpake2p_VerifierSerialized_Length * 2 + 1];
314-
Encoding::BytesToHex(value.PAKEPasscodeVerifier.data(), value.PAKEPasscodeVerifier.size(), verifierHex, sizeof(verifierHex),
315-
Encoding::HexFlags::kNullTerminate);
316-
ChipLogProgress(NotSpecified, " PAKEPasscodeVerifier: %s", verifierHex);
317-
318-
char saltHex[Crypto::kSpake2p_Max_PBKDF_Salt_Length * 2 + 1];
319-
Encoding::BytesToHex(value.salt.data(), value.salt.size(), saltHex, sizeof(saltHex), Encoding::HexFlags::kNullTerminate);
320-
ChipLogProgress(NotSpecified, " salt: %s", saltHex);
321-
322-
OpenDeviceCommissioningWindow(mLocalBridgeNodeId, value.commissioningTimeout, value.iterations, value.discriminator, saltHex,
323-
verifierHex);
324-
}
325-
326-
void DeviceManager::HandleAttributeData(const app::ConcreteDataAttributePath & path, TLV::TLVReader * data)
327-
{
328-
if (path.mClusterId == CommissionerControl::Id &&
329-
path.mAttributeId == CommissionerControl::Attributes::SupportedDeviceCategories::Id)
330-
{
331-
ChipLogProgress(NotSpecified, "Attribute SupportedDeviceCategories detected.");
332-
333-
BitMask<CommissionerControl::SupportedDeviceCategoryBitmap> value;
334-
CHIP_ERROR error = app::DataModel::Decode(*data, value);
335-
if (error != CHIP_NO_ERROR)
336-
{
337-
ChipLogError(NotSpecified, "Failed to decode attribute value. Error: %" CHIP_ERROR_FORMAT, error.Format());
338-
return;
339-
}
340-
341-
if (value.Has(CommissionerControl::SupportedDeviceCategoryBitmap::kFabricSynchronization))
342-
{
343-
ChipLogProgress(NotSpecified, "Remote Fabric-Bridge supports Fabric Synchronization, start reverse commissioning.");
344-
RequestCommissioningApproval();
345-
}
346-
347-
return;
348-
}
349-
350-
if (path.mClusterId != Descriptor::Id || path.mAttributeId != Descriptor::Attributes::PartsList::Id)
351-
{
352-
return;
353-
}
354-
355-
ChipLogProgress(NotSpecified, "Attribute change detected:");
356-
ChipLogProgress(
357-
NotSpecified, "Endpoint: %u, Cluster: " ChipLogFormatMEI ", Attribute: " ChipLogFormatMEI ", DataVersion: %" PRIu32,
358-
path.mEndpointId, ChipLogValueMEI(path.mClusterId), ChipLogValueMEI(path.mAttributeId), path.mDataVersion.ValueOr(0));
307+
ChipLogProgress(NotSpecified, "Attribute PartsList change detected:");
359308

360309
app::DataModel::DecodableList<EndpointId> value;
361-
CHIP_ERROR error = app::DataModel::Decode(*data, value);
310+
CHIP_ERROR error = app::DataModel::Decode(data, value);
362311
if (error != CHIP_NO_ERROR)
363312
{
364313
ChipLogError(NotSpecified, "Failed to decode attribute value. Error: %" CHIP_ERROR_FORMAT, error.Format());
@@ -456,7 +405,63 @@ void DeviceManager::HandleAttributeData(const app::ConcreteDataAttributePath & p
456405
}
457406
}
458407

459-
void DeviceManager::HandleEventData(const app::EventHeader & header, TLV::TLVReader * data)
408+
void DeviceManager::SendCommissionNodeRequest(uint64_t requestId, uint16_t responseTimeoutSeconds)
409+
{
410+
ChipLogProgress(NotSpecified, "Request the Commissioner Control Server to begin commissioning a previously approved request.");
411+
412+
StringBuilder<kMaxCommandSize> commandBuilder;
413+
commandBuilder.Add("commissionercontrol commission-node ");
414+
commandBuilder.AddFormat("%lu %u %lu %d", requestId, responseTimeoutSeconds, mRemoteBridgeNodeId, kRootEndpointId);
415+
416+
PushCommand(commandBuilder.c_str());
417+
}
418+
419+
void DeviceManager::HandleReverseOpenCommissioningWindow(TLV::TLVReader & data)
420+
{
421+
CommissionerControl::Commands::ReverseOpenCommissioningWindow::DecodableType value;
422+
CHIP_ERROR error = app::DataModel::Decode(data, value);
423+
if (error != CHIP_NO_ERROR)
424+
{
425+
ChipLogError(NotSpecified, "Failed to decode command response value. Error: %" CHIP_ERROR_FORMAT, error.Format());
426+
return;
427+
}
428+
429+
// Log all fields
430+
ChipLogProgress(NotSpecified, "DecodableType fields:");
431+
ChipLogProgress(NotSpecified, " commissioningTimeout: %u", value.commissioningTimeout);
432+
ChipLogProgress(NotSpecified, " discriminator: %u", value.discriminator);
433+
ChipLogProgress(NotSpecified, " iterations: %u", value.iterations);
434+
435+
char verifierHex[Crypto::kSpake2p_VerifierSerialized_Length * 2 + 1];
436+
Encoding::BytesToHex(value.PAKEPasscodeVerifier.data(), value.PAKEPasscodeVerifier.size(), verifierHex, sizeof(verifierHex),
437+
Encoding::HexFlags::kNullTerminate);
438+
ChipLogProgress(NotSpecified, " PAKEPasscodeVerifier: %s", verifierHex);
439+
440+
char saltHex[Crypto::kSpake2p_Max_PBKDF_Salt_Length * 2 + 1];
441+
Encoding::BytesToHex(value.salt.data(), value.salt.size(), saltHex, sizeof(saltHex), Encoding::HexFlags::kNullTerminate);
442+
ChipLogProgress(NotSpecified, " salt: %s", saltHex);
443+
444+
OpenDeviceCommissioningWindow(mLocalBridgeNodeId, value.commissioningTimeout, value.iterations, value.discriminator, saltHex,
445+
verifierHex);
446+
}
447+
448+
void DeviceManager::HandleAttributeData(const app::ConcreteDataAttributePath & path, TLV::TLVReader & data)
449+
{
450+
if (path.mClusterId == CommissionerControl::Id &&
451+
path.mAttributeId == CommissionerControl::Attributes::SupportedDeviceCategories::Id)
452+
{
453+
HandleReadSupportedDeviceCategories(data);
454+
return;
455+
}
456+
457+
if (path.mClusterId == Descriptor::Id && path.mAttributeId == Descriptor::Attributes::PartsList::Id)
458+
{
459+
HandleAttributePartsListUpdate(data);
460+
return;
461+
}
462+
}
463+
464+
void DeviceManager::HandleEventData(const app::EventHeader & header, TLV::TLVReader & data)
460465
{
461466
if (header.mPath.mClusterId == CommissionerControl::Id &&
462467
header.mPath.mEventId == CommissionerControl::Events::CommissioningRequestResult::Id)
@@ -465,7 +470,7 @@ void DeviceManager::HandleEventData(const app::EventHeader & header, TLV::TLVRea
465470
}
466471
}
467472

468-
void DeviceManager::HandleCommandResponse(const app::ConcreteCommandPath & path, TLV::TLVReader * data)
473+
void DeviceManager::HandleCommandResponse(const app::ConcreteCommandPath & path, TLV::TLVReader & data)
469474
{
470475
ChipLogProgress(NotSpecified, "Command Response received.");
471476

examples/fabric-admin/device_manager/DeviceManager.h

+9-5
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,11 @@ class DeviceManager : public PairingDelegate
150150

151151
void ReadSupportedDeviceCategories();
152152

153-
void HandleAttributeData(const chip::app::ConcreteDataAttributePath & path, chip::TLV::TLVReader * data);
153+
void HandleAttributeData(const chip::app::ConcreteDataAttributePath & path, chip::TLV::TLVReader & data);
154154

155-
void HandleEventData(const chip::app::EventHeader & header, chip::TLV::TLVReader * data);
155+
void HandleEventData(const chip::app::EventHeader & header, chip::TLV::TLVReader & data);
156156

157-
void HandleCommandResponse(const chip::app::ConcreteCommandPath & path, chip::TLV::TLVReader * data);
157+
void HandleCommandResponse(const chip::app::ConcreteCommandPath & path, chip::TLV::TLVReader & data);
158158

159159
void OnDeviceRemoved(chip::NodeId deviceId, CHIP_ERROR err) override;
160160

@@ -163,11 +163,15 @@ class DeviceManager : public PairingDelegate
163163

164164
void RequestCommissioningApproval();
165165

166-
void HandleCommissioningRequestResult(chip::TLV::TLVReader * data);
166+
void HandleReadSupportedDeviceCategories(chip::TLV::TLVReader & data);
167+
168+
void HandleCommissioningRequestResult(chip::TLV::TLVReader & data);
169+
170+
void HandleAttributePartsListUpdate(chip::TLV::TLVReader & data);
167171

168172
void SendCommissionNodeRequest(uint64_t requestId, uint16_t responseTimeoutSeconds);
169173

170-
void HandleReverseOpenCommissioningWindow(chip::TLV::TLVReader * data);
174+
void HandleReverseOpenCommissioningWindow(chip::TLV::TLVReader & data);
171175

172176
static DeviceManager sInstance;
173177

0 commit comments

Comments
 (0)