@@ -32,18 +32,14 @@ using namespace ::chip;
32
32
33
33
namespace {
34
34
35
- // Constants
36
- constexpr uint32_t kCommissionPrepareTimeMs = 500 ;
37
- constexpr uint16_t kMaxManaulCodeLength = 21 ;
38
-
39
35
void CheckFabricBridgeSynchronizationSupport (intptr_t ignored)
40
36
{
41
37
DeviceMgr ().ReadSupportedDeviceCategories ();
42
38
}
43
39
44
40
} // namespace
45
41
46
- void FabricSyncAddBridgeCommand::OnCommissioningComplete (chip:: NodeId deviceId, CHIP_ERROR err)
42
+ void FabricSyncAddBridgeCommand::OnCommissioningComplete (NodeId deviceId, CHIP_ERROR err)
47
43
{
48
44
if (mBridgeNodeId != deviceId)
49
45
{
@@ -90,15 +86,15 @@ CHIP_ERROR FabricSyncAddBridgeCommand::RunCommand(NodeId remoteId)
90
86
if (DeviceMgr ().IsFabricSyncReady ())
91
87
{
92
88
// print to console
93
- fprintf (stderr, " Remote Fabric Bridge has been alread configured." );
89
+ fprintf (stderr, " Remote Fabric Bridge has already been configured." );
94
90
return CHIP_NO_ERROR;
95
91
}
96
92
97
93
PairingCommand * pairingCommand = static_cast <PairingCommand *>(CommandMgr ().GetCommandByName (" pairing" , " already-discovered" ));
98
94
99
95
if (pairingCommand == nullptr )
100
96
{
101
- ChipLogError (NotSpecified, " Pairing onnetwork command is not available" );
97
+ ChipLogError (NotSpecified, " Pairing already-discovered command is not available" );
102
98
return CHIP_ERROR_NOT_IMPLEMENTED;
103
99
}
104
100
@@ -110,7 +106,7 @@ CHIP_ERROR FabricSyncAddBridgeCommand::RunCommand(NodeId remoteId)
110
106
return CHIP_NO_ERROR;
111
107
}
112
108
113
- void FabricSyncRemoveBridgeCommand::OnDeviceRemoved (chip:: NodeId deviceId, CHIP_ERROR err)
109
+ void FabricSyncRemoveBridgeCommand::OnDeviceRemoved (NodeId deviceId, CHIP_ERROR err)
114
110
{
115
111
if (mBridgeNodeId != deviceId)
116
112
{
@@ -150,7 +146,7 @@ CHIP_ERROR FabricSyncRemoveBridgeCommand::RunCommand()
150
146
151
147
if (pairingCommand == nullptr )
152
148
{
153
- ChipLogError (NotSpecified, " Pairing code command is not available" );
149
+ ChipLogError (NotSpecified, " Pairing unpair command is not available" );
154
150
return CHIP_ERROR_NOT_IMPLEMENTED;
155
151
}
156
152
@@ -161,13 +157,116 @@ CHIP_ERROR FabricSyncRemoveBridgeCommand::RunCommand()
161
157
return CHIP_NO_ERROR;
162
158
}
163
159
160
+ void FabricSyncAddLocalBridgeCommand::OnCommissioningComplete (NodeId deviceId, CHIP_ERROR err)
161
+ {
162
+ if (mLocalBridgeNodeId != deviceId)
163
+ {
164
+ if (err != CHIP_NO_ERROR)
165
+ {
166
+ ChipLogError (NotSpecified, " Failed to pair non-bridge device (0x:" ChipLogFormatX64 " ) with error: %" CHIP_ERROR_FORMAT,
167
+ ChipLogValueX64 (deviceId), err.Format ());
168
+ }
169
+ else
170
+ {
171
+ ChipLogProgress (NotSpecified, " Commissioning complete for non-bridge device: NodeId: " ChipLogFormatX64,
172
+ ChipLogValueX64 (deviceId));
173
+ }
174
+ return ;
175
+ }
176
+
177
+ if (err == CHIP_NO_ERROR)
178
+ {
179
+ DeviceMgr ().SetLocalBridgeNodeId (mLocalBridgeNodeId );
180
+ ChipLogProgress (NotSpecified, " Successfully paired local bridge device: NodeId: " ChipLogFormatX64,
181
+ ChipLogValueX64 (mLocalBridgeNodeId ));
182
+ }
183
+ else
184
+ {
185
+ ChipLogError (NotSpecified, " Failed to pair local bridge device (0x:" ChipLogFormatX64 " ) with error: %" CHIP_ERROR_FORMAT,
186
+ ChipLogValueX64 (deviceId), err.Format ());
187
+ }
188
+
189
+ mLocalBridgeNodeId = kUndefinedNodeId ;
190
+ }
191
+
192
+ CHIP_ERROR FabricSyncAddLocalBridgeCommand::RunCommand (NodeId deviceId)
193
+ {
194
+ if (DeviceMgr ().IsLocalBridgeReady ())
195
+ {
196
+ // print to console
197
+ fprintf (stderr, " Local Fabric Bridge has already been configured." );
198
+ return CHIP_NO_ERROR;
199
+ }
200
+
201
+ PairingCommand * pairingCommand = static_cast <PairingCommand *>(CommandMgr ().GetCommandByName (" pairing" , " already-discovered" ));
202
+ VerifyOrDie (pairingCommand != nullptr );
203
+
204
+ pairingCommand->RegisterCommissioningDelegate (this );
205
+ mLocalBridgeNodeId = deviceId;
206
+
207
+ DeviceMgr ().PairLocalFabricBridge (deviceId);
208
+
209
+ return CHIP_NO_ERROR;
210
+ }
211
+
212
+ void FabricSyncRemoveLocalBridgeCommand::OnDeviceRemoved (NodeId deviceId, CHIP_ERROR err)
213
+ {
214
+ if (mLocalBridgeNodeId != deviceId)
215
+ {
216
+ ChipLogProgress (NotSpecified, " A non-bridge device: NodeId: " ChipLogFormatX64 " is removed." , ChipLogValueX64 (deviceId));
217
+ return ;
218
+ }
219
+
220
+ if (err == CHIP_NO_ERROR)
221
+ {
222
+ DeviceMgr ().SetLocalBridgeNodeId (kUndefinedNodeId );
223
+ ChipLogProgress (NotSpecified, " Successfully removed local bridge device: NodeId: " ChipLogFormatX64,
224
+ ChipLogValueX64 (mLocalBridgeNodeId ));
225
+ }
226
+ else
227
+ {
228
+ ChipLogError (NotSpecified, " Failed to remove local bridge device (0x:" ChipLogFormatX64 " ) with error: %" CHIP_ERROR_FORMAT,
229
+ ChipLogValueX64 (deviceId), err.Format ());
230
+ }
231
+
232
+ mLocalBridgeNodeId = kUndefinedNodeId ;
233
+ }
234
+
235
+ CHIP_ERROR FabricSyncRemoveLocalBridgeCommand::RunCommand ()
236
+ {
237
+ NodeId bridgeNodeId = DeviceMgr ().GetLocalBridgeNodeId ();
238
+
239
+ if (bridgeNodeId == kUndefinedNodeId )
240
+ {
241
+ // print to console
242
+ fprintf (stderr, " Local Fabric Bridge is not configured yet, nothing to remove." );
243
+ return CHIP_NO_ERROR;
244
+ }
245
+
246
+ mLocalBridgeNodeId = bridgeNodeId;
247
+
248
+ PairingCommand * pairingCommand = static_cast <PairingCommand *>(CommandMgr ().GetCommandByName (" pairing" , " unpair" ));
249
+
250
+ if (pairingCommand == nullptr )
251
+ {
252
+ ChipLogError (NotSpecified, " Pairing unpair command is not available" );
253
+ return CHIP_ERROR_NOT_IMPLEMENTED;
254
+ }
255
+
256
+ pairingCommand->RegisterPairingDelegate (this );
257
+
258
+ DeviceMgr ().UnpairLocalFabricBridge ();
259
+
260
+ return CHIP_NO_ERROR;
261
+ }
262
+
164
263
void FabricSyncDeviceCommand::OnCommissioningWindowOpened (NodeId deviceId, CHIP_ERROR err, chip::SetupPayload payload)
165
264
{
166
265
ChipLogProgress (NotSpecified, " FabricSyncDeviceCommand::OnCommissioningWindowOpened" );
167
266
168
267
if (err == CHIP_NO_ERROR)
169
268
{
170
- char payloadBuffer[kMaxManaulCodeLength + 1 ];
269
+ char payloadBuffer[kMaxManualCodeLength + 1 ];
171
270
MutableCharSpan manualCode (payloadBuffer);
172
271
CHIP_ERROR error = ManualSetupPayloadGenerator (payload).payloadDecimalStringRepresentation (manualCode);
173
272
if (error == CHIP_NO_ERROR)
@@ -202,7 +301,7 @@ void FabricSyncDeviceCommand::OnCommissioningWindowOpened(NodeId deviceId, CHIP_
202
301
}
203
302
}
204
303
205
- void FabricSyncDeviceCommand::OnCommissioningComplete (chip:: NodeId deviceId, CHIP_ERROR err)
304
+ void FabricSyncDeviceCommand::OnCommissioningComplete (NodeId deviceId, CHIP_ERROR err)
206
305
{
207
306
if (mAssignedNodeId != deviceId)
208
307
{
0 commit comments