Skip to content

Commit

Permalink
Add target endpoint id to commissioning window opener params
Browse files Browse the repository at this point in the history
Co-authored-by: Yufeng Wang <[email protected]>
  • Loading branch information
samadDotDev and yufengwangca committed Jul 19, 2024
1 parent 19a774a commit a1f1f2a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/controller/CommissioningWindowOpener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ CHIP_ERROR CommissioningWindowOpener::OpenCommissioningWindow(const Commissionin
mCommissioningWindowVerifierCallback = nullptr;
mNodeId = params.GetNodeId();
mCommissioningWindowTimeout = params.GetTimeout();
if (params.HasEndpointId())
{
mTargetEndpointId = params.GetEndpointId();
}

if (params.GetReadVIDPIDAttributes())
{
Expand Down Expand Up @@ -162,6 +166,10 @@ CHIP_ERROR CommissioningWindowOpener::OpenCommissioningWindow(const Commissionin
mPBKDFIterations = params.GetIteration();
mCommissioningWindowOption = CommissioningWindowOption::kTokenWithProvidedPIN;
mDiscriminator.SetLongValue(params.GetDiscriminator());
if (params.HasEndpointId())
{
mTargetEndpointId = params.GetEndpointId();
}

mNextStep = Step::kOpenCommissioningWindow;

Expand All @@ -173,9 +181,7 @@ CHIP_ERROR CommissioningWindowOpener::OpenCommissioningWindowInternal(Messaging:
{
ChipLogProgress(Controller, "OpenCommissioningWindow for device ID 0x" ChipLogFormatX64, ChipLogValueX64(mNodeId));

constexpr EndpointId kAdministratorCommissioningClusterEndpoint = 0;

ClusterBase cluster(exchangeMgr, sessionHandle, kAdministratorCommissioningClusterEndpoint);
ClusterBase cluster(exchangeMgr, sessionHandle, mTargetEndpointId);

if (mCommissioningWindowOption != CommissioningWindowOption::kOriginalSetupCode)
{
Expand Down
3 changes: 2 additions & 1 deletion src/controller/CommissioningWindowOpener.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ class CommissioningWindowOpener
Callback::Callback<OnOpenBasicCommissioningWindow> * mBasicCommissioningWindowCallback = nullptr;
SetupPayload mSetupPayload;
SetupDiscriminator mDiscriminator{};
NodeId mNodeId = kUndefinedNodeId;
NodeId mNodeId = kUndefinedNodeId;
EndpointId mTargetEndpointId = kRootEndpointId; // Default endpoint for Administrator Commissioning Cluster
System::Clock::Seconds16 mCommissioningWindowTimeout = System::Clock::kZero;
CommissioningWindowOption mCommissioningWindowOption = CommissioningWindowOption::kOriginalSetupCode;
Crypto::Spake2pVerifier mVerifier; // Used for non-basic commissioning.
Expand Down
9 changes: 9 additions & 0 deletions src/controller/CommissioningWindowParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ class CommissioningWindowCommonParams
return static_cast<Derived &>(*this);
}

bool HasEndpointId() const { return mEndpointId.HasValue(); }
EndpointId GetEndpointId() const { return mEndpointId.Value(); }
Derived & SetEndpointId(EndpointId endpointId)
{
mEndpointId = MakeOptional(endpointId);
return static_cast<Derived &>(*this);
}

System::Clock::Seconds16 GetTimeout() const { return mTimeout; }
// The duration for which the commissioning window should remain open.
Derived & SetTimeout(System::Clock::Seconds16 timeout)
Expand Down Expand Up @@ -82,6 +90,7 @@ class CommissioningWindowCommonParams

private:
NodeId mNodeId = kUndefinedNodeId;
Optional<EndpointId> mEndpointId = NullOptional;
System::Clock::Seconds16 mTimeout = System::Clock::Seconds16(300); // Defaulting
uint32_t mIteration = 1000; // Defaulting
Optional<uint16_t> mDiscriminator = NullOptional; // Using optional type to avoid picking a sentinnel in valid range
Expand Down

0 comments on commit a1f1f2a

Please sign in to comment.