From 9dadddb9f897a33132f9befeb9f2abe47d9fc8b4 Mon Sep 17 00:00:00 2001 From: chendejin Date: Tue, 23 Jan 2024 15:05:48 +0800 Subject: [PATCH] update mStagingNetwork to the dataset in NVS after thread panid changed --- .../GenericNetworkCommissioningThreadDriver.cpp | 11 +++++++++++ .../GenericNetworkCommissioningThreadDriver.h | 1 + 2 files changed, 12 insertions(+) diff --git a/src/platform/OpenThread/GenericNetworkCommissioningThreadDriver.cpp b/src/platform/OpenThread/GenericNetworkCommissioningThreadDriver.cpp index 0859c3f723d5d5..9774ad4be10ef5 100644 --- a/src/platform/OpenThread/GenericNetworkCommissioningThreadDriver.cpp +++ b/src/platform/OpenThread/GenericNetworkCommissioningThreadDriver.cpp @@ -47,6 +47,7 @@ CHIP_ERROR GenericThreadDriver::Init(Internal::BaseDriver::NetworkStatusChangeCa { ThreadStackMgrImpl().SetNetworkStatusChangeCallback(statusChangeCallback); ThreadStackMgrImpl().GetThreadProvision(mStagingNetwork); + PlatformMgr().AddEventHandler(OnThreadStateChangeHandler, reinterpret_cast(&mStagingNetwork)); // 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 @@ -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(arg))); + } +} + void GenericThreadDriver::Shutdown() { ThreadStackMgrImpl().SetNetworkStatusChangeCallback(nullptr); diff --git a/src/platform/OpenThread/GenericNetworkCommissioningThreadDriver.h b/src/platform/OpenThread/GenericNetworkCommissioningThreadDriver.h index bbfec6a44ff879..28dc8f176ddd1f 100644 --- a/src/platform/OpenThread/GenericNetworkCommissioningThreadDriver.h +++ b/src/platform/OpenThread/GenericNetworkCommissioningThreadDriver.h @@ -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();