Skip to content

Commit 74824cb

Browse files
committed
review changes
1 parent 995f544 commit 74824cb

File tree

5 files changed

+23
-25
lines changed

5 files changed

+23
-25
lines changed

src/app/clusters/thread-border-router-management-server/thread-border-router-management-server.cpp

+7-13
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,9 @@ Status ServerInstance::HandleSetActiveDatasetRequest(bool failSafeArmed,
9595
return Status::InvalidInState;
9696
}
9797

98-
mBreadcrumb = req.breadcrumb;
99-
mRandomNumber = Crypto::GetRandU32();
100-
CHIP_ERROR err = mDelegate->SetActiveDataset(activeDataset, mRandomNumber, this);
101-
if (err != CHIP_NO_ERROR)
102-
{
103-
mRandomNumber = 0;
104-
}
98+
mBreadcrumb = req.breadcrumb;
99+
mSetActiveDatasetSequenceNumber++;
100+
CHIP_ERROR err = mDelegate->SetActiveDataset(activeDataset, mSetActiveDatasetSequenceNumber, this);
105101
return StatusIB(err).mStatus;
106102
}
107103

@@ -161,7 +157,8 @@ void ServerInstance::InvokeCommand(HandlerContext & ctxt)
161157
Status status = HandleSetActiveDatasetRequest(IsFailSafeArmed(ctx.mCommandHandler.GetAccessingFabricIndex()), req);
162158
if (status != Status::Success)
163159
{
164-
OnActivateDatasetComplete(mRandomNumber, ChipError(ChipError::SdkPart::kIMGlobalStatus, to_underlying(status)));
160+
OnActivateDatasetComplete(mSetActiveDatasetSequenceNumber,
161+
ChipError(ChipError::SdkPart::kIMGlobalStatus, to_underlying(status)));
165162
}
166163
}
167164
else
@@ -317,20 +314,19 @@ void ServerInstance::CommitSavedBreadcrumb()
317314
mBreadcrumb.ClearValue();
318315
}
319316

320-
void ServerInstance::OnActivateDatasetComplete(uint32_t randomNumber, CHIP_ERROR error)
317+
void ServerInstance::OnActivateDatasetComplete(uint32_t sequenceNum, CHIP_ERROR error)
321318
{
322319
auto commandHandleRef = std::move(mAsyncCommandHandle);
323320
auto commandHandle = commandHandleRef.Get();
324321
if (commandHandle == nullptr)
325322
{
326323
return;
327324
}
328-
if (mRandomNumber != randomNumber)
325+
if (mSetActiveDatasetSequenceNumber != sequenceNum)
329326
{
330327
// Previous SetActiveDatasetRequest was handled.
331328
return;
332329
}
333-
mRandomNumber = 0;
334330
if (error == CHIP_NO_ERROR)
335331
{
336332
// The successful completion of the activation process SHALL disarm the fail-safe timer.
@@ -356,8 +352,6 @@ void ServerInstance::OnFailSafeTimerExpired()
356352
{
357353
return;
358354
}
359-
// Reset the RandomNumeber so that the OnActivateDatasetComplete will not handle the previous SetActiveDatasetRequest command.
360-
mRandomNumber = 0;
361355
commandHandle->AddStatus(mPath, Status::Timeout);
362356
}
363357

src/app/clusters/thread-border-router-management-server/thread-border-router-management-server.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class ServerInstance : public CommandHandlerInterface, public AttributeAccessInt
5353
CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override;
5454

5555
// ActivateDatasetCallbackInterface
56-
void OnActivateDatasetComplete(uint32_t randomNum, CHIP_ERROR error) override;
56+
void OnActivateDatasetComplete(uint32_t sequenceNum, CHIP_ERROR error) override;
5757

5858
private:
5959
friend class TestThreadBorderRouterManagementCluster;
@@ -86,7 +86,7 @@ class ServerInstance : public CommandHandlerInterface, public AttributeAccessInt
8686
app::CommandHandler::Handle mAsyncCommandHandle;
8787
ConcreteCommandPath mPath = ConcreteCommandPath(0, 0, 0);
8888
Optional<uint64_t> mBreadcrumb;
89-
uint32_t mRandomNumber;
89+
uint32_t mSetActiveDatasetSequenceNumber = 0;
9090
};
9191

9292
bool IsFailSafeArmed(FabricIndex accessingFabricIndex);

src/app/clusters/thread-border-router-management-server/thread-br-delegate.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class Delegate
4848
// If the dataset is set successfully, OnActivateDatasetComplete should be called with CHIP_NO_ERROR when the
4949
// Border Router is attached to the Thread network.
5050
// If an error occurs while setting the active dataset, this callback should be called with the error.
51-
virtual void OnActivateDatasetComplete(uint32_t randomNumber, CHIP_ERROR error) = 0;
51+
virtual void OnActivateDatasetComplete(uint32_t sequenceNum, CHIP_ERROR error) = 0;
5252
};
5353

5454
enum class DatasetType : uint8_t
@@ -72,14 +72,16 @@ class Delegate
7272
virtual CHIP_ERROR GetDataset(Thread::OperationalDataset & dataset, DatasetType type) = 0;
7373

7474
// The Delegate implementation should back up the old active dataset at the beginning of function if no backup already exists.
75-
// The Delegate implementation should store the random number and pass it to OnActivateDatasetComplete.
76-
virtual CHIP_ERROR SetActiveDataset(const Thread::OperationalDataset & activeDataset, uint32_t randomNum,
75+
// The Delegate implementation must store the sequence number and pass it to OnActivateDatasetComplete.
76+
virtual CHIP_ERROR SetActiveDataset(const Thread::OperationalDataset & activeDataset, uint32_t sequenceNum,
7777
ActivateDatasetCallback * callback) = 0;
7878

7979
// The Delegate implementation should remove the backup active dataset in this function.
8080
virtual CHIP_ERROR CommitActiveDataset() = 0;
8181

82-
// The Delegate implementation should restore the backup active dataset in this function.
82+
// The Delegate implementation should restore the backup active dataset in this function. The delegate is allowed to call
83+
// OnActivateDatasetComplete for the previous SetActiveDataset request even after this function is called as the sequence
84+
// number passed to OnActivateDatasetComplete will be different.
8385
virtual CHIP_ERROR RevertActiveDataset() = 0;
8486

8587
virtual CHIP_ERROR SetPendingDataset(const Thread::OperationalDataset & pendingDataset) = 0;

src/platform/OpenThread/GenericThreadBorderRouterDelegate.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ CHIP_ERROR GenericOpenThreadBorderRouterDelegate::GetDataset(Thread::Operational
119119
}
120120

121121
CHIP_ERROR GenericOpenThreadBorderRouterDelegate::SetActiveDataset(const Thread::OperationalDataset & activeDataset,
122-
uint32_t randomNumber, ActivateDatasetCallback * callback)
122+
uint32_t sequenceNum, ActivateDatasetCallback * callback)
123123
{
124124
CHIP_ERROR err = BackupActiveDataset();
125125
if (err == CHIP_NO_ERROR)
@@ -128,8 +128,10 @@ CHIP_ERROR GenericOpenThreadBorderRouterDelegate::SetActiveDataset(const Thread:
128128
}
129129
if (err == CHIP_NO_ERROR)
130130
{
131-
mRandomNumber = randomNumber;
132-
mCallback = callback;
131+
// We can change the stored sequence number because OnActivateDatasetComplete executed later must be called for this
132+
// SetActiveDataset request
133+
mSequenceNum = sequenceNum;
134+
mCallback = callback;
133135
}
134136
return err;
135137
}
@@ -142,7 +144,7 @@ void GenericOpenThreadBorderRouterDelegate::OnPlatformEventHandler(const DeviceL
142144
if (event->Type == DeviceLayer::DeviceEventType::kThreadConnectivityChange &&
143145
event->ThreadConnectivityChange.Result == DeviceLayer::kConnectivity_Established)
144146
{
145-
delegate->mCallback->OnActivateDatasetComplete(delegate->mRandomNumber, CHIP_NO_ERROR);
147+
delegate->mCallback->OnActivateDatasetComplete(delegate->mSequenceNum, CHIP_NO_ERROR);
146148
// Delete Failsafe Keys after activating dataset is completed
147149
DeviceLayer::PersistedStorage::KeyValueStoreMgr().Delete(kFailsafeThreadDatasetTlvsKey);
148150
delegate->mCallback = nullptr;

src/platform/OpenThread/GenericThreadBorderRouterDelegate.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class GenericOpenThreadBorderRouterDelegate : public Delegate
6767

6868
CHIP_ERROR GetDataset(Thread::OperationalDataset & dataset, DatasetType type) override;
6969

70-
CHIP_ERROR SetActiveDataset(const Thread::OperationalDataset & activeDataset, uint32_t randomNumber,
70+
CHIP_ERROR SetActiveDataset(const Thread::OperationalDataset & activeDataset, uint32_t sequenceNum,
7171
ActivateDatasetCallback * callback) override;
7272

7373
CHIP_ERROR RevertActiveDataset() override;
@@ -82,7 +82,7 @@ class GenericOpenThreadBorderRouterDelegate : public Delegate
8282
CHIP_ERROR BackupActiveDataset();
8383
ActivateDatasetCallback * mCallback = nullptr;
8484
Thread::OperationalDataset mStagingDataset = {};
85-
uint32_t mRandomNumber;
85+
uint32_t mSequenceNum;
8686
char mThreadBorderRouterName[kBorderRouterNameMaxLength + 1];
8787
};
8888
} // namespace ThreadBorderRouterManagement

0 commit comments

Comments
 (0)