From 3e9e9db41383e4aae4b8bca866cc57b68e7d9500 Mon Sep 17 00:00:00 2001 From: chendejin Date: Mon, 19 Aug 2024 16:50:45 +0800 Subject: [PATCH] OpenThread: clear the previous srp host and services when connecting to a new network --- ...GenericNetworkCommissioningThreadDriver.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/platform/OpenThread/GenericNetworkCommissioningThreadDriver.cpp b/src/platform/OpenThread/GenericNetworkCommissioningThreadDriver.cpp index 0e7701ec481add..ed5d7ede410f39 100644 --- a/src/platform/OpenThread/GenericNetworkCommissioningThreadDriver.cpp +++ b/src/platform/OpenThread/GenericNetworkCommissioningThreadDriver.cpp @@ -189,6 +189,24 @@ void GenericThreadDriver::ConnectNetwork(ByteSpan networkId, ConnectCallback * c status = Status::kUnknownError; } + if (status == Status::kSuccess && ThreadStackMgrImpl().IsThreadAttached()) + { + Thread::OperationalDataset currentDataset; + if (ThreadStackMgrImpl().GetThreadProvision(currentDataset) == CHIP_NO_ERROR) + { + // Clear the previous srp host and services + if (!currentDataset.AsByteSpan().data_equal(mStagingNetwork.AsByteSpan()) && + ThreadStackMgrImpl().ClearAllSrpHostAndServices() != CHIP_NO_ERROR) + { + status = Status::kUnknownError; + } + } + else + { + status = Status::kUnknownError; + } + } + if (status == Status::kSuccess && DeviceLayer::ThreadStackMgrImpl().AttachToThreadNetwork(mStagingNetwork, callback) != CHIP_NO_ERROR) {