30
30
#include " app/clusters/general-commissioning-server/general-commissioning-server.h"
31
31
#include " app/data-model/Nullable.h"
32
32
#include " app/server/Server.h"
33
+ #include " crypto/RandUtils.h"
33
34
#include " lib/core/CHIPError.h"
34
35
#include " lib/support/CodeUtils.h"
35
36
#include " lib/support/Span.h"
@@ -102,7 +103,12 @@ Status ServerInstance::HandleSetActiveDatasetRequest(bool failSafeArmed,
102
103
}
103
104
104
105
mBreadcrumb = req.breadcrumb ;
105
- CHIP_ERROR err = mDelegate ->SetActiveDataset (activeDataset, this );
106
+ mRandomNumber = Crypto::GetRandU32 ();
107
+ CHIP_ERROR err = mDelegate ->SetActiveDataset (activeDataset, mRandomNumber , this );
108
+ if (err != CHIP_NO_ERROR)
109
+ {
110
+ mRandomNumber = 0 ;
111
+ }
106
112
return StatusIB (err).mStatus ;
107
113
}
108
114
@@ -318,14 +324,20 @@ void ServerInstance::CommitSavedBreadcrumb()
318
324
mBreadcrumb .ClearValue ();
319
325
}
320
326
321
- void ServerInstance::OnActivateDatasetComplete (CHIP_ERROR error)
327
+ void ServerInstance::OnActivateDatasetComplete (uint32_t randomNumber, CHIP_ERROR error)
322
328
{
323
329
auto commandHandleRef = std::move (mAsyncCommandHandle );
324
330
auto commandHandle = commandHandleRef.Get ();
325
331
if (commandHandle == nullptr )
326
332
{
327
333
return ;
328
334
}
335
+ if (mRandomNumber != randomNumber)
336
+ {
337
+ // Previous SetActiveDatasetRequest was handled.
338
+ return ;
339
+ }
340
+ mRandomNumber = 0 ;
329
341
if (error == CHIP_NO_ERROR)
330
342
{
331
343
// The successful completion of the activation process SHALL disarm the fail-safe timer.
@@ -352,6 +364,8 @@ void ServerInstance::OnFailSafeTimerExpired()
352
364
{
353
365
return ;
354
366
}
367
+ // Reset the RandomNumeber so that the OnActivateDatasetComplete will not handle the previous SetActiveDatasetRequest command.
368
+ mRandomNumber = 0 ;
355
369
commandHandle->AddStatus (mPath , Status::Timeout);
356
370
}
357
371
0 commit comments