Skip to content

Commit

Permalink
[Fabric-Admin] Reset PairingManager state before next command (projec…
Browse files Browse the repository at this point in the history
…t-chip#36795)

* [Fabric-Admin] Reset PairingManager state before next command

* Restyled by whitespace

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and yyzhong-g committed Dec 11, 2024
1 parent 2583994 commit 7efbd54
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ void FabricSyncAddBridgeCommand::OnCommissioningComplete(NodeId deviceId, CHIP_E
ChipLogValueX64(deviceId), err.Format());
}

PairingManager::Instance().ResetForNextCommand();
mBridgeNodeId = kUndefinedNodeId;
}

Expand Down Expand Up @@ -123,6 +124,7 @@ void FabricSyncRemoveBridgeCommand::OnDeviceRemoved(NodeId deviceId, CHIP_ERROR
ChipLogValueX64(deviceId), err.Format());
}

PairingManager::Instance().ResetForNextCommand();
mBridgeNodeId = kUndefinedNodeId;
}

Expand Down Expand Up @@ -174,6 +176,7 @@ void FabricSyncAddLocalBridgeCommand::OnCommissioningComplete(NodeId deviceId, C
ChipLogValueX64(deviceId), err.Format());
}

PairingManager::Instance().ResetForNextCommand();
mLocalBridgeNodeId = kUndefinedNodeId;
}

Expand Down Expand Up @@ -215,6 +218,7 @@ void FabricSyncRemoveLocalBridgeCommand::OnDeviceRemoved(NodeId deviceId, CHIP_E
ChipLogValueX64(deviceId), err.Format());
}

PairingManager::Instance().ResetForNextCommand();
mLocalBridgeNodeId = kUndefinedNodeId;
}

Expand Down Expand Up @@ -290,6 +294,8 @@ void FabricSyncDeviceCommand::OnCommissioningComplete(NodeId deviceId, CHIP_ERRO
ChipLogError(NotSpecified, "Failed to pair synced device (0x:" ChipLogFormatX64 ") with error: %" CHIP_ERROR_FORMAT,
ChipLogValueX64(deviceId), err.Format());
}

PairingManager::Instance().ResetForNextCommand();
}

CHIP_ERROR FabricSyncDeviceCommand::RunCommand(EndpointId remoteEndpointId)
Expand Down
31 changes: 31 additions & 0 deletions examples/fabric-admin/device_manager/PairingManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -661,4 +661,35 @@ CHIP_ERROR PairingManager::UnpairDevice(NodeId nodeId)
});
}

void PairingManager::ResetForNextCommand()
{
mCommissioningWindowDelegate = nullptr;
mPairingDelegate = nullptr;
mNodeId = chip::kUndefinedNodeId;
mVerifier = chip::ByteSpan();
mSalt = chip::ByteSpan();
mDiscriminator = 0;
mSetupPINCode = 0;
mDeviceIsICD = false;

memset(mRandomGeneratedICDSymmetricKey, 0, sizeof(mRandomGeneratedICDSymmetricKey));
memset(mVerifierBuffer, 0, sizeof(mVerifierBuffer));
memset(mSaltBuffer, 0, sizeof(mSaltBuffer));
memset(mRemoteIpAddr, 0, sizeof(mRemoteIpAddr));
memset(mOnboardingPayload, 0, sizeof(mOnboardingPayload));

mICDRegistration.ClearValue();
mICDCheckInNodeId.ClearValue();
mICDClientType.ClearValue();
mICDSymmetricKey.ClearValue();
mICDMonitoredSubject.ClearValue();
mICDStayActiveDurationMsec.ClearValue();

mWindowOpener.reset();
mOnOpenCommissioningWindowCallback.Cancel();
mOnOpenCommissioningWindowVerifierCallback.Cancel();
mCurrentFabricRemover.reset();
mCurrentFabricRemoveCallback.Cancel();
}

} // namespace admin
6 changes: 6 additions & 0 deletions examples/fabric-admin/device_manager/PairingManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ class PairingManager : public chip::Controller::DevicePairingDelegate,
*/
CHIP_ERROR UnpairDevice(chip::NodeId nodeId);

/**
* Resets the PairingManager's internal state to a baseline, making it ready to handle a new command.
* This method clears all internal states and resets all members to their initial values.
*/
void ResetForNextCommand();

private:
// Constructors
PairingManager();
Expand Down

0 comments on commit 7efbd54

Please sign in to comment.