Skip to content

Commit b8628ca

Browse files
[Fabric-Admin] Reset PairingManager state before next command (#36795)
* [Fabric-Admin] Reset PairingManager state before next command * Restyled by whitespace --------- Co-authored-by: Restyled.io <commits@restyled.io>
1 parent e4a0402 commit b8628ca

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

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

+6
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ void FabricSyncAddBridgeCommand::OnCommissioningComplete(NodeId deviceId, CHIP_E
8383
ChipLogValueX64(deviceId), err.Format());
8484
}
8585

86+
PairingManager::Instance().ResetForNextCommand();
8687
mBridgeNodeId = kUndefinedNodeId;
8788
}
8889

@@ -123,6 +124,7 @@ void FabricSyncRemoveBridgeCommand::OnDeviceRemoved(NodeId deviceId, CHIP_ERROR
123124
ChipLogValueX64(deviceId), err.Format());
124125
}
125126

127+
PairingManager::Instance().ResetForNextCommand();
126128
mBridgeNodeId = kUndefinedNodeId;
127129
}
128130

@@ -174,6 +176,7 @@ void FabricSyncAddLocalBridgeCommand::OnCommissioningComplete(NodeId deviceId, C
174176
ChipLogValueX64(deviceId), err.Format());
175177
}
176178

179+
PairingManager::Instance().ResetForNextCommand();
177180
mLocalBridgeNodeId = kUndefinedNodeId;
178181
}
179182

@@ -215,6 +218,7 @@ void FabricSyncRemoveLocalBridgeCommand::OnDeviceRemoved(NodeId deviceId, CHIP_E
215218
ChipLogValueX64(deviceId), err.Format());
216219
}
217220

221+
PairingManager::Instance().ResetForNextCommand();
218222
mLocalBridgeNodeId = kUndefinedNodeId;
219223
}
220224

@@ -290,6 +294,8 @@ void FabricSyncDeviceCommand::OnCommissioningComplete(NodeId deviceId, CHIP_ERRO
290294
ChipLogError(NotSpecified, "Failed to pair synced device (0x:" ChipLogFormatX64 ") with error: %" CHIP_ERROR_FORMAT,
291295
ChipLogValueX64(deviceId), err.Format());
292296
}
297+
298+
PairingManager::Instance().ResetForNextCommand();
293299
}
294300

295301
CHIP_ERROR FabricSyncDeviceCommand::RunCommand(EndpointId remoteEndpointId)

examples/fabric-admin/device_manager/PairingManager.cpp

+31
Original file line numberDiff line numberDiff line change
@@ -661,4 +661,35 @@ CHIP_ERROR PairingManager::UnpairDevice(NodeId nodeId)
661661
});
662662
}
663663

664+
void PairingManager::ResetForNextCommand()
665+
{
666+
mCommissioningWindowDelegate = nullptr;
667+
mPairingDelegate = nullptr;
668+
mNodeId = chip::kUndefinedNodeId;
669+
mVerifier = chip::ByteSpan();
670+
mSalt = chip::ByteSpan();
671+
mDiscriminator = 0;
672+
mSetupPINCode = 0;
673+
mDeviceIsICD = false;
674+
675+
memset(mRandomGeneratedICDSymmetricKey, 0, sizeof(mRandomGeneratedICDSymmetricKey));
676+
memset(mVerifierBuffer, 0, sizeof(mVerifierBuffer));
677+
memset(mSaltBuffer, 0, sizeof(mSaltBuffer));
678+
memset(mRemoteIpAddr, 0, sizeof(mRemoteIpAddr));
679+
memset(mOnboardingPayload, 0, sizeof(mOnboardingPayload));
680+
681+
mICDRegistration.ClearValue();
682+
mICDCheckInNodeId.ClearValue();
683+
mICDClientType.ClearValue();
684+
mICDSymmetricKey.ClearValue();
685+
mICDMonitoredSubject.ClearValue();
686+
mICDStayActiveDurationMsec.ClearValue();
687+
688+
mWindowOpener.reset();
689+
mOnOpenCommissioningWindowCallback.Cancel();
690+
mOnOpenCommissioningWindowVerifierCallback.Cancel();
691+
mCurrentFabricRemover.reset();
692+
mCurrentFabricRemoveCallback.Cancel();
693+
}
694+
664695
} // namespace admin

examples/fabric-admin/device_manager/PairingManager.h

+6
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,12 @@ class PairingManager : public chip::Controller::DevicePairingDelegate,
134134
*/
135135
CHIP_ERROR UnpairDevice(chip::NodeId nodeId);
136136

137+
/**
138+
* Resets the PairingManager's internal state to a baseline, making it ready to handle a new command.
139+
* This method clears all internal states and resets all members to their initial values.
140+
*/
141+
void ResetForNextCommand();
142+
137143
private:
138144
// Constructors
139145
PairingManager();

0 commit comments

Comments
 (0)