Skip to content

Commit

Permalink
update mStagingNetwork to the dataset in NVS after thread panid chang…
Browse files Browse the repository at this point in the history
  • Loading branch information
DejinChen authored Jan 24, 2024
1 parent b08e41c commit 4aa833d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ CHIP_ERROR GenericThreadDriver::Init(Internal::BaseDriver::NetworkStatusChangeCa
{
ThreadStackMgrImpl().SetNetworkStatusChangeCallback(statusChangeCallback);
ThreadStackMgrImpl().GetThreadProvision(mStagingNetwork);
ReturnErrorOnFailure(PlatformMgr().AddEventHandler(OnThreadStateChangeHandler, reinterpret_cast<intptr_t>(this)));

// If the network configuration backup exists, it means that the device has been rebooted with
// the fail-safe armed. Since OpenThread persists all operational dataset changes, the backup
Expand All @@ -56,6 +57,16 @@ CHIP_ERROR GenericThreadDriver::Init(Internal::BaseDriver::NetworkStatusChangeCa
return CHIP_NO_ERROR;
}

void GenericThreadDriver::OnThreadStateChangeHandler(const ChipDeviceEvent * event, intptr_t arg)
{
if ((event->Type == DeviceEventType::kThreadStateChange) &&
(event->ThreadStateChange.OpenThread.Flags & OT_CHANGED_THREAD_PANID))
{
// Update the mStagingNetwork when thread panid changed
ThreadStackMgrImpl().GetThreadProvision(reinterpret_cast<GenericThreadDriver *>(arg)->mStagingNetwork);
}
}

void GenericThreadDriver::Shutdown()
{
ThreadStackMgrImpl().SetNetworkStatusChangeCallback(nullptr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class GenericThreadDriver final : public ThreadDriver
private:
uint8_t scanNetworkTimeoutSeconds;
uint8_t connectNetworkTimeout;
static void OnThreadStateChangeHandler(const ChipDeviceEvent * event, intptr_t arg);
Status MatchesNetworkId(const Thread::OperationalDataset & dataset, const ByteSpan & networkId) const;
CHIP_ERROR BackupConfiguration();

Expand Down

0 comments on commit 4aa833d

Please sign in to comment.