Skip to content

Commit 3b90fed

Browse files
authored
[FS Example] Update the FS Example apps to support fabric sync setup process part I (#34906)
* [FS Example] Update the FS Example apps to support fabric sync setup process * Move all command handling to device manager using StringBuilder
1 parent 798b576 commit 3b90fed

File tree

11 files changed

+556
-56
lines changed

11 files changed

+556
-56
lines changed

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

+2-8
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().HandleAttributeChange(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,11 +73,5 @@ void ReportCommand::OnEventData(const app::EventHeader & eventHeader, TLV::TLVRe
7373

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

76-
CHIP_ERROR error = DataModelLogger::LogEvent(eventHeader, data);
77-
if (CHIP_NO_ERROR != error)
78-
{
79-
ChipLogError(NotSpecified, "Response Failure: Can not decode Data");
80-
mError = error;
81-
return;
82-
}
76+
DeviceMgr().HandleEventData(eventHeader, data);
8377
}

examples/fabric-admin/commands/common/CHIPCommand.h

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ inline constexpr char kIdentityGamma[] = "gamma";
5151
// (CASE) communcation.
5252
inline constexpr char kIdentityNull[] = "null-fabric-commissioner";
5353

54+
constexpr uint16_t kMaxCommandSize = 128;
55+
5456
class CHIPCommand : public Command
5557
{
5658
public:

examples/fabric-admin/commands/fabric-sync/FabricSyncCommand.cpp

+27-26
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,28 @@ namespace {
3535
// Constants
3636
constexpr uint32_t kCommissionPrepareTimeMs = 500;
3737
constexpr uint16_t kMaxManaulCodeLength = 21;
38-
constexpr uint16_t kSubscribeMinInterval = 0;
39-
constexpr uint16_t kSubscribeMaxInterval = 60;
40-
constexpr uint16_t kRemoteBridgePort = 5540;
38+
39+
void CheckFabricBridgeSynchronizationSupport(intptr_t ignored)
40+
{
41+
DeviceMgr().ReadSupportedDeviceCategories();
42+
}
4143

4244
} // namespace
4345

4446
void FabricSyncAddBridgeCommand::OnCommissioningComplete(chip::NodeId deviceId, CHIP_ERROR err)
4547
{
4648
if (mBridgeNodeId != deviceId)
4749
{
48-
ChipLogProgress(NotSpecified, "Commissioning complete for non-bridge device: NodeId: " ChipLogFormatX64,
49-
ChipLogValueX64(deviceId));
50+
if (err != CHIP_NO_ERROR)
51+
{
52+
ChipLogError(NotSpecified, "Failed to pair non-bridge device (0x:" ChipLogFormatX64 ") with error: %" CHIP_ERROR_FORMAT,
53+
ChipLogValueX64(deviceId), err.Format());
54+
}
55+
else
56+
{
57+
ChipLogProgress(NotSpecified, "Commissioning complete for non-bridge device: NodeId: " ChipLogFormatX64,
58+
ChipLogValueX64(deviceId));
59+
}
5060
return;
5161
}
5262

@@ -56,11 +66,15 @@ void FabricSyncAddBridgeCommand::OnCommissioningComplete(chip::NodeId deviceId,
5666
ChipLogProgress(NotSpecified, "Successfully paired bridge device: NodeId: " ChipLogFormatX64,
5767
ChipLogValueX64(mBridgeNodeId));
5868

59-
char command[kMaxCommandSize];
60-
snprintf(command, sizeof(command), "descriptor subscribe parts-list %d %d %ld %d", kSubscribeMinInterval,
61-
kSubscribeMaxInterval, mBridgeNodeId, kAggragatorEndpointId);
69+
DeviceMgr().SubscribeRemoteFabricBridge();
6270

63-
PushCommand(command);
71+
// After successful commissioning of the Commissionee, initiate Reverse Commissioning
72+
// via the Commissioner Control Cluster. However, we must first verify that the
73+
// remote Fabric-Bridge supports Fabric Synchronization.
74+
//
75+
// Note: The Fabric-Admin MUST NOT send the RequestCommissioningApproval command
76+
// if the remote Fabric-Bridge lacks Fabric Synchronization support.
77+
DeviceLayer::PlatformMgr().ScheduleWork(CheckFabricBridgeSynchronizationSupport, 0);
6478
}
6579
else
6680
{
@@ -80,10 +94,6 @@ CHIP_ERROR FabricSyncAddBridgeCommand::RunCommand(NodeId remoteId)
8094
return CHIP_NO_ERROR;
8195
}
8296

83-
char command[kMaxCommandSize];
84-
snprintf(command, sizeof(command), "pairing already-discovered %ld %d %s %d", remoteId, kSetupPinCode,
85-
reinterpret_cast<const char *>(mRemoteAddr.data()), kRemoteBridgePort);
86-
8797
PairingCommand * pairingCommand = static_cast<PairingCommand *>(CommandMgr().GetCommandByName("pairing", "already-discovered"));
8898

8999
if (pairingCommand == nullptr)
@@ -95,7 +105,7 @@ CHIP_ERROR FabricSyncAddBridgeCommand::RunCommand(NodeId remoteId)
95105
pairingCommand->RegisterCommissioningDelegate(this);
96106
mBridgeNodeId = remoteId;
97107

98-
PushCommand(command);
108+
DeviceMgr().PairRemoteFabricBridge(remoteId, reinterpret_cast<const char *>(mRemoteAddr.data()));
99109

100110
return CHIP_NO_ERROR;
101111
}
@@ -136,9 +146,6 @@ CHIP_ERROR FabricSyncRemoveBridgeCommand::RunCommand()
136146

137147
mBridgeNodeId = bridgeNodeId;
138148

139-
char command[kMaxCommandSize];
140-
snprintf(command, sizeof(command), "pairing unpair %ld", mBridgeNodeId);
141-
142149
PairingCommand * pairingCommand = static_cast<PairingCommand *>(CommandMgr().GetCommandByName("pairing", "unpair"));
143150

144151
if (pairingCommand == nullptr)
@@ -149,7 +156,7 @@ CHIP_ERROR FabricSyncRemoveBridgeCommand::RunCommand()
149156

150157
pairingCommand->RegisterPairingDelegate(this);
151158

152-
PushCommand(command);
159+
DeviceMgr().UnpairRemoteFabricBridge();
153160

154161
return CHIP_NO_ERROR;
155162
}
@@ -163,9 +170,7 @@ void FabricSyncDeviceCommand::OnCommissioningWindowOpened(NodeId deviceId, CHIP_
163170
CHIP_ERROR error = ManualSetupPayloadGenerator(payload).payloadDecimalStringRepresentation(manualCode);
164171
if (error == CHIP_NO_ERROR)
165172
{
166-
char command[kMaxCommandSize];
167173
NodeId nodeId = DeviceMgr().GetNextAvailableNodeId();
168-
snprintf(command, sizeof(command), "pairing code %ld %s", nodeId, payloadBuffer);
169174

170175
PairingCommand * pairingCommand = static_cast<PairingCommand *>(CommandMgr().GetCommandByName("pairing", "code"));
171176

@@ -180,7 +185,7 @@ void FabricSyncDeviceCommand::OnCommissioningWindowOpened(NodeId deviceId, CHIP_
180185

181186
usleep(kCommissionPrepareTimeMs * 1000);
182187

183-
PushCommand(command);
188+
DeviceMgr().PairRemoteDevice(nodeId, payloadBuffer);
184189
}
185190
else
186191
{
@@ -224,10 +229,6 @@ CHIP_ERROR FabricSyncDeviceCommand::RunCommand(EndpointId remoteId)
224229
return CHIP_NO_ERROR;
225230
}
226231

227-
char command[kMaxCommandSize];
228-
snprintf(command, sizeof(command), "pairing open-commissioning-window %ld %d %d %d %d %d", DeviceMgr().GetRemoteBridgeNodeId(),
229-
remoteId, kEnhancedCommissioningMethod, kWindowTimeout, kIteration, kDiscriminator);
230-
231232
OpenCommissioningWindowCommand * openCommand =
232233
static_cast<OpenCommissioningWindowCommand *>(CommandMgr().GetCommandByName("pairing", "open-commissioning-window"));
233234

@@ -238,7 +239,7 @@ CHIP_ERROR FabricSyncDeviceCommand::RunCommand(EndpointId remoteId)
238239

239240
openCommand->RegisterDelegate(this);
240241

241-
PushCommand(command);
242+
DeviceMgr().OpenRemoteDeviceCommissioningWindow(remoteId);
242243

243244
return CHIP_NO_ERROR;
244245
}

examples/fabric-admin/commands/fabric-sync/FabricSyncCommand.h

-8
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,6 @@
2222
#include <commands/pairing/OpenCommissioningWindowCommand.h>
2323
#include <commands/pairing/PairingCommand.h>
2424

25-
constexpr uint32_t kSetupPinCode = 20202021;
26-
constexpr uint16_t kMaxCommandSize = 64;
27-
constexpr uint16_t kDiscriminator = 3840;
28-
constexpr uint16_t kWindowTimeout = 300;
29-
constexpr uint16_t kIteration = 1000;
30-
constexpr uint16_t kAggragatorEndpointId = 1;
31-
constexpr uint8_t kEnhancedCommissioningMethod = 1;
32-
3325
class FabricSyncAddBridgeCommand : public CHIPCommand, public CommissioningDelegate
3426
{
3527
public:

0 commit comments

Comments
 (0)