From fff21a2f854d18ba1a352925360cdf2996690998 Mon Sep 17 00:00:00 2001 From: Douglas Rocha Ferraz <2106161+rochaferraz@users.noreply.github.com> Date: Tue, 1 Mar 2022 17:59:29 -0500 Subject: [PATCH] Revert "Cherry pick Generic Thread Network commissioning Driver (#15392)" (#15693) This reverts commit 61b943311df2105eda33e95b81c7c202fc057266. Change-Id: I4af90cea2cbb48d25eec2a1876f936bc405dd782 --- examples/lighting-app/telink/CMakeLists.txt | 1 - examples/persistent-storage/qpg/args.gni | 1 - examples/shell/efr32/BUILD.gn | 1 + examples/shell/efr32/args.gni | 1 - .../shell/efr32/include/CHIPProjectConfig.h | 2 - examples/shell/mbed/CMakeLists.txt | 1 - .../mbed/main/include/CHIPProjectConfig.h | 4 - examples/shell/nrfconnect/CHIPProjectConfig.h | 4 - examples/shell/nxp/k32w/k32w0/BUILD.gn | 6 +- src/include/platform/ThreadStackManager.h | 27 +-- .../GenericConnectivityManagerImpl_Thread.cpp | 5 - src/platform/BUILD.gn | 8 - src/platform/EFR32/ThreadStackManagerImpl.cpp | 1 + src/platform/Linux/ThreadStackManagerImpl.cpp | 10 +- src/platform/Linux/ThreadStackManagerImpl.h | 14 +- ...enericNetworkCommissioningThreadDriver.cpp | 194 ------------------ .../GenericNetworkCommissioningThreadDriver.h | 114 ---------- ...nericThreadStackManagerImpl_OpenThread.cpp | 121 ----------- ...GenericThreadStackManagerImpl_OpenThread.h | 13 +- src/test_driver/efr32/BUILD.gn | 3 - 20 files changed, 15 insertions(+), 516 deletions(-) delete mode 100644 src/platform/OpenThread/GenericNetworkCommissioningThreadDriver.cpp delete mode 100644 src/platform/OpenThread/GenericNetworkCommissioningThreadDriver.h diff --git a/examples/lighting-app/telink/CMakeLists.txt b/examples/lighting-app/telink/CMakeLists.txt index 1e4ceefb35b364..cabca3ee2eb539 100644 --- a/examples/lighting-app/telink/CMakeLists.txt +++ b/examples/lighting-app/telink/CMakeLists.txt @@ -93,7 +93,6 @@ target_sources(app PRIVATE ${CHIP_ROOT}/src/app/clusters/level-control/level-control.cpp ${CHIP_ROOT}/src/app/clusters/color-control-server/color-control-server.cpp ${CHIP_ROOT}/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.cpp - ${CHIP_ROOT}/src/app/clusters/network-commissioning/network-commissioning.cpp ${CHIP_ROOT}/src/app/clusters/network-commissioning-old/network-commissioning-ember.cpp ${CHIP_ROOT}/src/app/clusters/network-commissioning-old/network-commissioning-old.cpp ${CHIP_ROOT}/src/app/clusters/ota-requestor/ota-requestor-server.cpp diff --git a/examples/persistent-storage/qpg/args.gni b/examples/persistent-storage/qpg/args.gni index 4918e5af9de27b..b0d121b1029802 100644 --- a/examples/persistent-storage/qpg/args.gni +++ b/examples/persistent-storage/qpg/args.gni @@ -16,4 +16,3 @@ import("//build_overrides/chip.gni") import("${chip_root}/examples/platform/qpg/args.gni") qpg_sdk_target = get_label_info(":sdk", "label_no_toolchain") -chip_enable_openthread = false diff --git a/examples/shell/efr32/BUILD.gn b/examples/shell/efr32/BUILD.gn index ea683bed9362cf..64e73d4cfbb981 100644 --- a/examples/shell/efr32/BUILD.gn +++ b/examples/shell/efr32/BUILD.gn @@ -49,6 +49,7 @@ efr32_sdk("sdk") { defines = [ "BOARD_ID=${efr32_board}", "OPENTHREAD_CONFIG_CLI_TRANSPORT=OT_CLI_TRANSPORT_CONSOLE", + "ENABLE_CHIP_SHELL", ] } diff --git a/examples/shell/efr32/args.gni b/examples/shell/efr32/args.gni index 9d49561c413334..1b73ad66dcea58 100644 --- a/examples/shell/efr32/args.gni +++ b/examples/shell/efr32/args.gni @@ -22,4 +22,3 @@ pw_log_BACKEND = "${chip_root}/src/lib/support/pw_log_chip" pw_assert_BACKEND = "$dir_pw_assert_log" chip_enable_openthread = true chip_openthread_ftd = true -chip_build_libshell = true diff --git a/examples/shell/efr32/include/CHIPProjectConfig.h b/examples/shell/efr32/include/CHIPProjectConfig.h index b47c348e6df34c..e5be53a055f434 100644 --- a/examples/shell/efr32/include/CHIPProjectConfig.h +++ b/examples/shell/efr32/include/CHIPProjectConfig.h @@ -113,5 +113,3 @@ * A size, in bytes, of the individual debug event logging buffer. */ #define CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE (512) - -#define _NO_NETWORK_COMMISSIONING_DRIVER_ diff --git a/examples/shell/mbed/CMakeLists.txt b/examples/shell/mbed/CMakeLists.txt index fbd5b2576ecf9b..18397ba9b8d689 100644 --- a/examples/shell/mbed/CMakeLists.txt +++ b/examples/shell/mbed/CMakeLists.txt @@ -21,7 +21,6 @@ include(${MBED_PATH}/tools/cmake/app.cmake) project(${APP_TARGET}) - add_subdirectory(${MBED_PATH} ./mbed_build) add_subdirectory(${MBED_OS_POSIX_SOCKET_PATH} ./mbed_os_posix_socket_build) diff --git a/examples/shell/mbed/main/include/CHIPProjectConfig.h b/examples/shell/mbed/main/include/CHIPProjectConfig.h index 44bf03fc40b208..ab3dbbecc38342 100644 --- a/examples/shell/mbed/main/include/CHIPProjectConfig.h +++ b/examples/shell/mbed/main/include/CHIPProjectConfig.h @@ -33,7 +33,3 @@ // Use a default pairing code if one hasn't been provisioned in flash. #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021 #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00 - -// shell app uses openthread but does not have the NETWORK_COMMISSIONING cluster or zap config -// Do not instantiate the NETWORK_COMMISSIONING thread driver -#define _NO_NETWORK_COMMISSIONING_DRIVER_ diff --git a/examples/shell/nrfconnect/CHIPProjectConfig.h b/examples/shell/nrfconnect/CHIPProjectConfig.h index 4b35fcd6a8cf58..cc90aa590dfd57 100644 --- a/examples/shell/nrfconnect/CHIPProjectConfig.h +++ b/examples/shell/nrfconnect/CHIPProjectConfig.h @@ -42,7 +42,3 @@ * 0x4E53: nrfconnect shell */ #define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID 0x4E53 - -// shell app uses openthread but does not have the NETWORK_COMMISSIONING cluster or zap config -// Do not instantiate the NETWORK_COMMISSIONING thread driver -#define _NO_NETWORK_COMMISSIONING_DRIVER_ diff --git a/examples/shell/nxp/k32w/k32w0/BUILD.gn b/examples/shell/nxp/k32w/k32w0/BUILD.gn index 505373a42bf860..dbb85ebe56be38 100644 --- a/examples/shell/nxp/k32w/k32w0/BUILD.gn +++ b/examples/shell/nxp/k32w/k32w0/BUILD.gn @@ -44,11 +44,7 @@ k32w0_sdk("sdk") { "${k32w0_platform_dir}/util/include", ] - defines = [ - # shell app uses openthread but does not have the NETWORK_COMMISSIONING cluster or zap config. - "_NO_NETWORK_COMMISSIONING_DRIVER_", - ] - + defines = [] if (is_debug) { defines += [ "BUILD_RELEASE=0" ] } else { diff --git a/src/include/platform/ThreadStackManager.h b/src/include/platform/ThreadStackManager.h index e4c0e4696ab3c0..f9db5e3df3c6e7 100644 --- a/src/include/platform/ThreadStackManager.h +++ b/src/include/platform/ThreadStackManager.h @@ -27,7 +27,6 @@ #include #include #include -#include namespace chip { @@ -89,9 +88,6 @@ class ThreadStackManager bool TryLockThreadStack(); void UnlockThreadStack(); bool HaveRouteToAddress(const chip::Inet::IPAddress & destAddr); - bool IsThreadEnabled(); - bool IsThreadProvisioned(); - bool IsThreadAttached(); CHIP_ERROR GetThreadProvision(ByteSpan & netInfo); CHIP_ERROR GetAndLogThreadStatsCounters(); CHIP_ERROR GetAndLogThreadTopologyMinimal(); @@ -103,9 +99,6 @@ class ThreadStackManager CHIP_ERROR JoinerStart(); CHIP_ERROR SetThreadProvision(ByteSpan aDataset); CHIP_ERROR SetThreadEnabled(bool val); - CHIP_ERROR AttachToThreadNetwork(ByteSpan netInfo, NetworkCommissioning::Internal::WirelessDriver::ConnectCallback * callback); - CHIP_ERROR StartThreadScan(NetworkCommissioning::ThreadDriver::ScanCallback * callback); - void OnThreadAttachFinished(void); #if CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT CHIP_ERROR AddSrpService(const char * aInstanceName, const char * aName, uint16_t aPort, @@ -152,6 +145,9 @@ class ThreadStackManager friend class Internal::GenericThreadStackManagerImpl_FreeRTOS; void OnPlatformEvent(const ChipDeviceEvent * event); + bool IsThreadEnabled(); + bool IsThreadProvisioned(); + bool IsThreadAttached(); void ErasePersistentInfo(); ConnectivityManager::ThreadDeviceType GetThreadDeviceType(); CHIP_ERROR SetThreadDeviceType(ConnectivityManager::ThreadDeviceType threadRole); @@ -351,23 +347,6 @@ inline CHIP_ERROR ThreadStackManager::SetThreadProvision(ByteSpan netInfo) return static_cast(this)->_SetThreadProvision(netInfo); } -inline CHIP_ERROR -ThreadStackManager::AttachToThreadNetwork(ByteSpan netInfo, - NetworkCommissioning::Internal::WirelessDriver::ConnectCallback * callback) -{ - return static_cast(this)->_AttachToThreadNetwork(netInfo, callback); -} - -inline void ThreadStackManager::OnThreadAttachFinished(void) -{ - static_cast(this)->_OnThreadAttachFinished(); -} - -inline CHIP_ERROR ThreadStackManager::StartThreadScan(NetworkCommissioning::ThreadDriver::ScanCallback * callback) -{ - return static_cast(this)->_StartThreadScan(callback); -} - inline void ThreadStackManager::ErasePersistentInfo() { static_cast(this)->_ErasePersistentInfo(); diff --git a/src/include/platform/internal/GenericConnectivityManagerImpl_Thread.cpp b/src/include/platform/internal/GenericConnectivityManagerImpl_Thread.cpp index 1eb0f3f89242bb..b02aed72f903a3 100644 --- a/src/include/platform/internal/GenericConnectivityManagerImpl_Thread.cpp +++ b/src/include/platform/internal/GenericConnectivityManagerImpl_Thread.cpp @@ -44,11 +44,6 @@ void GenericConnectivityManagerImpl_Thread::_OnPlatformEvent(const Ch (event->Type == DeviceEventType::kThreadStateChange && event->ThreadStateChange.NetDataChanged); const bool fabricMembershipChanged = (event->Type == DeviceEventType::kFabricMembershipChange); - if (threadConnChanged && event->ThreadConnectivityChange.Result == kConnectivity_Established) - { - ThreadStackMgrImpl().OnThreadAttachFinished(); - } - // If any of the above events has occurred, assess whether there's been a change in // service connectivity via Thread. if (threadConnChanged || threadAddrChanged || threadNetDataChanged || fabricMembershipChanged) diff --git a/src/platform/BUILD.gn b/src/platform/BUILD.gn index 40ff8450a968ca..741134a0c931fc 100644 --- a/src/platform/BUILD.gn +++ b/src/platform/BUILD.gn @@ -296,14 +296,6 @@ if (chip_device_platform != "none") { "PlatformEventSupport.cpp", ] - # Linux has its own NetworkCommissioningThreadDriver - if (chip_enable_openthread && chip_device_platform != "linux") { - sources += [ - "OpenThread/GenericNetworkCommissioningThreadDriver.cpp", - "OpenThread/GenericNetworkCommissioningThreadDriver.h", - ] - } - if (chip_enable_ota_requestor) { sources += [ "GenericOTARequestorDriver.cpp", diff --git a/src/platform/EFR32/ThreadStackManagerImpl.cpp b/src/platform/EFR32/ThreadStackManagerImpl.cpp index fbd89807260177..da08ecfa0f930b 100644 --- a/src/platform/EFR32/ThreadStackManagerImpl.cpp +++ b/src/platform/EFR32/ThreadStackManagerImpl.cpp @@ -28,6 +28,7 @@ #include #include + #include #include diff --git a/src/platform/Linux/ThreadStackManagerImpl.cpp b/src/platform/Linux/ThreadStackManagerImpl.cpp index 29114d00c7051a..d50aed7be164c4 100644 --- a/src/platform/Linux/ThreadStackManagerImpl.cpp +++ b/src/platform/Linux/ThreadStackManagerImpl.cpp @@ -289,7 +289,7 @@ CHIP_ERROR ThreadStackManagerImpl::_SetThreadEnabled(bool val) VerifyOrReturnError(mProxy, CHIP_ERROR_INCORRECT_STATE); if (val) { - openthread_io_openthread_border_router_call_attach(mProxy.get(), nullptr, _OnThreadBrAttachFinished, this); + openthread_io_openthread_border_router_call_attach(mProxy.get(), nullptr, _OnThreadAttachFinished, this); } else { @@ -311,7 +311,7 @@ CHIP_ERROR ThreadStackManagerImpl::_SetThreadEnabled(bool val) return CHIP_NO_ERROR; } -void ThreadStackManagerImpl::_OnThreadBrAttachFinished(GObject * source_object, GAsyncResult * res, gpointer user_data) +void ThreadStackManagerImpl::_OnThreadAttachFinished(GObject * source_object, GAsyncResult * res, gpointer user_data) { ThreadStackManagerImpl * this_ = reinterpret_cast(user_data); std::unique_ptr attachRes; @@ -507,7 +507,7 @@ CHIP_ERROR ThreadStackManagerImpl::_JoinerStart() return CHIP_ERROR_NOT_IMPLEMENTED; } -CHIP_ERROR ThreadStackManagerImpl::_StartThreadScan(ThreadDriver::ScanCallback * callback) +CHIP_ERROR ThreadStackManagerImpl::StartThreadScan(ThreadDriver::ScanCallback * callback) { // There is another ongoing scan request, reject the new one. VerifyOrReturnError(mpScanCallback == nullptr, CHIP_ERROR_INCORRECT_STATE); @@ -637,8 +637,8 @@ CHIP_ERROR ThreadStackManagerImpl::_WriteThreadNetworkDiagnosticAttributeToTlv(A } CHIP_ERROR -ThreadStackManagerImpl::_AttachToThreadNetwork(ByteSpan netInfo, - NetworkCommissioning::Internal::WirelessDriver::ConnectCallback * callback) +ThreadStackManagerImpl::AttachToThreadNetwork(ByteSpan netInfo, + NetworkCommissioning::Internal::WirelessDriver::ConnectCallback * callback) { // There is another ongoing connect request, reject the new one. VerifyOrReturnError(mpConnectCallback == nullptr, CHIP_ERROR_INCORRECT_STATE); diff --git a/src/platform/Linux/ThreadStackManagerImpl.h b/src/platform/Linux/ThreadStackManagerImpl.h index e725bb5d72f64d..caac53708b9922 100644 --- a/src/platform/Linux/ThreadStackManagerImpl.h +++ b/src/platform/Linux/ThreadStackManagerImpl.h @@ -65,13 +65,10 @@ class ThreadStackManagerImpl : public ThreadStackManager bool _IsThreadAttached(); - CHIP_ERROR _AttachToThreadNetwork(ByteSpan netInfo, NetworkCommissioning::Internal::WirelessDriver::ConnectCallback * callback); + CHIP_ERROR AttachToThreadNetwork(ByteSpan netInfo, NetworkCommissioning::Internal::WirelessDriver::ConnectCallback * callback); CHIP_ERROR _SetThreadEnabled(bool val); - - void _OnThreadAttachFinished(void); - - static void _OnThreadBrAttachFinished(GObject * source_object, GAsyncResult * res, gpointer user_data); + static void _OnThreadAttachFinished(GObject * source_object, GAsyncResult * res, gpointer user_data); ConnectivityManager::ThreadDeviceType _GetThreadDeviceType(); @@ -103,7 +100,7 @@ class ThreadStackManagerImpl : public ThreadStackManager CHIP_ERROR _WriteThreadNetworkDiagnosticAttributeToTlv(AttributeId attributeId, app::AttributeValueEncoder & encoder); - CHIP_ERROR _StartThreadScan(NetworkCommissioning::ThreadDriver::ScanCallback * callback); + CHIP_ERROR StartThreadScan(NetworkCommissioning::ThreadDriver::ScanCallback * callback); ~ThreadStackManagerImpl() = default; @@ -148,10 +145,5 @@ class ThreadStackManagerImpl : public ThreadStackManager bool mAttached; }; -inline void ThreadStackManagerImpl::_OnThreadAttachFinished(void) -{ - // stub for ThreadStackManager.h -} - } // namespace DeviceLayer } // namespace chip diff --git a/src/platform/OpenThread/GenericNetworkCommissioningThreadDriver.cpp b/src/platform/OpenThread/GenericNetworkCommissioningThreadDriver.cpp deleted file mode 100644 index ccb3a408e7ecc3..00000000000000 --- a/src/platform/OpenThread/GenericNetworkCommissioningThreadDriver.cpp +++ /dev/null @@ -1,194 +0,0 @@ -/* - * - * Copyright (c) 2021 Project CHIP Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include -#include - -#include - -using namespace chip; -using namespace chip::Thread; - -namespace chip { -namespace DeviceLayer { -namespace NetworkCommissioning { -// NOTE: For ThreadDriver, we use two network configs, one is mSavedNetwork, and another is mStagingNetwork, during init, it will -// load the network config from thread persistent info, and loads it into both mSavedNetwork and mStagingNetwork. When updating the -// networks, all changes are made on the staging network. When validated we can commit it and save it to the persistent info - -CHIP_ERROR GenericThreadDriver::Init() -{ - ByteSpan currentProvision; - VerifyOrReturnError(ThreadStackMgrImpl().IsThreadAttached(), CHIP_NO_ERROR); - VerifyOrReturnError(ThreadStackMgrImpl().GetThreadProvision(currentProvision) == CHIP_NO_ERROR, CHIP_NO_ERROR); - - mSavedNetwork.Init(currentProvision); - mStagingNetwork.Init(currentProvision); - - return CHIP_NO_ERROR; -} - -CHIP_ERROR GenericThreadDriver::CommitConfiguration() -{ - // Note: on AttachToThreadNetwork OpenThread will persist the networks on its own, - // we don't have much to do for saving the networks (see Init() above, - // we just load the saved dataset from ot instance.) - mSavedNetwork = mStagingNetwork; - return CHIP_NO_ERROR; -} - -CHIP_ERROR GenericThreadDriver::RevertConfiguration() -{ - mStagingNetwork = mSavedNetwork; - return CHIP_NO_ERROR; -} - -Status GenericThreadDriver::AddOrUpdateNetwork(ByteSpan operationalDataset) -{ - uint8_t extpanid[kSizeExtendedPanId]; - uint8_t newExtpanid[kSizeExtendedPanId]; - Thread::OperationalDataset newDataset; - - newDataset.Init(operationalDataset); - VerifyOrReturnError(newDataset.IsCommissioned(), Status::kOutOfRange); - - newDataset.GetExtendedPanId(newExtpanid); - mStagingNetwork.GetExtendedPanId(extpanid); - - // We only support one active operational dataset. Add/Update based on either: - // Staging network not commissioned yet (active) or we are updating the dataset with same Extended Pan ID. - VerifyOrReturnError(!mStagingNetwork.IsCommissioned() || memcmp(extpanid, newExtpanid, kSizeExtendedPanId) == 0, - Status::kBoundsExceeded); - - mStagingNetwork = newDataset; - return Status::kSuccess; -} - -Status GenericThreadDriver::RemoveNetwork(ByteSpan networkId) -{ - uint8_t extpanid[kSizeExtendedPanId]; - if (!mStagingNetwork.IsCommissioned()) - { - return Status::kNetworkNotFound; - } - else if (mStagingNetwork.GetExtendedPanId(extpanid) != CHIP_NO_ERROR) - { - return Status::kUnknownError; - } - - VerifyOrReturnError(networkId.size() == kSizeExtendedPanId && memcmp(networkId.data(), extpanid, kSizeExtendedPanId) == 0, - Status::kNetworkNotFound); - mStagingNetwork.Clear(); - return Status::kSuccess; -} - -Status GenericThreadDriver::ReorderNetwork(ByteSpan networkId, uint8_t index) -{ - uint8_t extpanid[kSizeExtendedPanId]; - if (!mStagingNetwork.IsCommissioned()) - { - return Status::kNetworkNotFound; - } - else if (mStagingNetwork.GetExtendedPanId(extpanid) != CHIP_NO_ERROR) - { - return Status::kUnknownError; - } - - VerifyOrReturnError(networkId.size() == kSizeExtendedPanId && memcmp(networkId.data(), extpanid, kSizeExtendedPanId) == 0, - Status::kNetworkNotFound); - - return Status::kSuccess; -} - -void GenericThreadDriver::ConnectNetwork(ByteSpan networkId, ConnectCallback * callback) -{ - NetworkCommissioning::Status status = Status::kSuccess; - uint8_t extpanid[kSizeExtendedPanId]; - if (!mStagingNetwork.IsCommissioned()) - { - ExitNow(status = Status::kNetworkNotFound); - } - else if (mStagingNetwork.GetExtendedPanId(extpanid) != CHIP_NO_ERROR) - { - ExitNow(status = Status::kUnknownError); - } - - VerifyOrExit((networkId.size() == kSizeExtendedPanId && memcmp(networkId.data(), extpanid, kSizeExtendedPanId) == 0), - status = Status::kNetworkNotFound); - - VerifyOrExit(DeviceLayer::ThreadStackMgrImpl().AttachToThreadNetwork(mStagingNetwork.AsByteSpan(), callback) == CHIP_NO_ERROR, - status = Status::kUnknownError); - -exit: - if (status != Status::kSuccess) - { - callback->OnResult(status, CharSpan(), 0); - } -} - -void GenericThreadDriver::ScanNetworks(ThreadDriver::ScanCallback * callback) -{ - CHIP_ERROR err = DeviceLayer::ThreadStackMgrImpl().StartThreadScan(callback); - if (err != CHIP_NO_ERROR) - { - callback->OnFinished(Status::kUnknownError, CharSpan(), nullptr); - } -} - -size_t GenericThreadDriver::ThreadNetworkIterator::Count() -{ - return driver->mStagingNetwork.IsCommissioned() ? 1 : 0; -} - -bool GenericThreadDriver::ThreadNetworkIterator::Next(Network & item) -{ - if (exhausted || !driver->mStagingNetwork.IsCommissioned()) - { - return false; - } - uint8_t extpanid[kSizeExtendedPanId]; - VerifyOrReturnError(driver->mStagingNetwork.GetExtendedPanId(extpanid) == CHIP_NO_ERROR, false); - memcpy(item.networkID, extpanid, kSizeExtendedPanId); - item.networkIDLen = kSizeExtendedPanId; - item.connected = false; - exhausted = true; - - ByteSpan currentProvision; - Thread::OperationalDataset currentDataset; - uint8_t enabledExtPanId[Thread::kSizeExtendedPanId]; - - // The Thread network is not actually enabled. - VerifyOrReturnError(ConnectivityMgrImpl().IsThreadAttached(), true); - VerifyOrReturnError(ThreadStackMgrImpl().GetThreadProvision(currentProvision) == CHIP_NO_ERROR, true); - VerifyOrReturnError(currentDataset.Init(currentProvision) == CHIP_NO_ERROR, true); - // The Thread network is not enabled, but has a different extended pan id. - VerifyOrReturnError(currentDataset.GetExtendedPanId(enabledExtPanId) == CHIP_NO_ERROR, true); - VerifyOrReturnError(memcmp(extpanid, enabledExtPanId, kSizeExtendedPanId) == 0, true); - // The Thread network is enabled and has the same extended pan id as the one in our record. - item.connected = true; - - return true; -} - -} // namespace NetworkCommissioning -} // namespace DeviceLayer -} // namespace chip diff --git a/src/platform/OpenThread/GenericNetworkCommissioningThreadDriver.h b/src/platform/OpenThread/GenericNetworkCommissioningThreadDriver.h deleted file mode 100644 index 3fc7b132ea30b9..00000000000000 --- a/src/platform/OpenThread/GenericNetworkCommissioningThreadDriver.h +++ /dev/null @@ -1,114 +0,0 @@ -/* - * - * Copyright (c) 2021 Project CHIP Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -namespace chip { -namespace DeviceLayer { -namespace NetworkCommissioning { - -template -class otScanResponseIterator : public Iterator -{ -public: - otScanResponseIterator(T * apScanResponse) : mpScanResponse(apScanResponse) {} - size_t Count() override { return itemCount; } - bool Next(T & item) override - { - if (mpScanResponse == nullptr || currentIterating >= itemCount) - { - return false; - } - item = mpScanResponse[currentIterating]; - currentIterating++; - return true; - } - void Release() override - { - itemCount = currentIterating = 0; - Platform::MemoryFree(mpScanResponse); - mpScanResponse = nullptr; - } - - void Add(T * pResponse) - { - size_t tempCount = itemCount + 1; - mpScanResponse = static_cast(Platform::MemoryRealloc(mpScanResponse, kItemSize * tempCount)); - if (mpScanResponse) - { - // first item at index. update after the copy. - memcpy(&(mpScanResponse[itemCount]), pResponse, kItemSize); - itemCount = tempCount; - } - } - -private: - size_t currentIterating = 0; - size_t itemCount = 0; - size_t kItemSize = sizeof(T); - T * mpScanResponse; -}; - -class GenericThreadDriver final : public ThreadDriver -{ -public: - class ThreadNetworkIterator final : public NetworkIterator - { - public: - ThreadNetworkIterator(GenericThreadDriver * aDriver) : driver(aDriver) {} - size_t Count() override; - bool Next(Network & item) override; - void Release() override { delete this; } - ~ThreadNetworkIterator() = default; - - private: - GenericThreadDriver * driver; - bool exhausted = false; - }; - - // BaseDriver - NetworkIterator * GetNetworks() override { return new ThreadNetworkIterator(this); } - CHIP_ERROR Init() override; - CHIP_ERROR Shutdown() override { return CHIP_NO_ERROR; } // Nothing to do on EFR32 for shutdown. - - // WirelessDriver - uint8_t GetMaxNetworks() override { return 1; } - uint8_t GetScanNetworkTimeoutSeconds() override { return 10; } - uint8_t GetConnectNetworkTimeoutSeconds() override { return 20; } - - CHIP_ERROR CommitConfiguration() override; - CHIP_ERROR RevertConfiguration() override; - - Status RemoveNetwork(ByteSpan networkId) override; - Status ReorderNetwork(ByteSpan networkId, uint8_t index) override; - void ConnectNetwork(ByteSpan networkId, ConnectCallback * callback) override; - - // ThreadDriver - Status AddOrUpdateNetwork(ByteSpan operationalDataset) override; - void ScanNetworks(ScanCallback * callback) override; - -private: - ThreadNetworkIterator mThreadIterator = ThreadNetworkIterator(this); - Thread::OperationalDataset mSavedNetwork = {}; - Thread::OperationalDataset mStagingNetwork = {}; -}; - -} // namespace NetworkCommissioning -} // namespace DeviceLayer -} // namespace chip diff --git a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp index e13114d160380f..134cca16c7bcb2 100644 --- a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp +++ b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp @@ -46,14 +46,12 @@ #endif #include -#include #include #include #include #include #include #include -#include #include #include #include @@ -75,7 +73,6 @@ extern "C" void otAppCliInit(otInstance * aInstance); using namespace chip::app; using namespace chip::app::Clusters; using namespace chip::app::DataModel; -using namespace chip::DeviceLayer::NetworkCommissioning; using chip::Inet::IPPrefix; @@ -83,23 +80,6 @@ namespace chip { namespace DeviceLayer { namespace Internal { -// Network commissioning -namespace { -#ifndef _NO_NETWORK_COMMISSIONING_DRIVER_ -NetworkCommissioning::GenericThreadDriver sGenericThreadDriver; -Clusters::NetworkCommissioning::Instance sThreadNetworkCommissioningInstance(0 /* Endpoint Id */, &sGenericThreadDriver); -#endif - -void initNetworkCommissioningThreadDriver(void) -{ -#ifndef _NO_NETWORK_COMMISSIONING_DRIVER_ - sThreadNetworkCommissioningInstance.Init(); -#endif -} - -NetworkCommissioning::ThreadScanResponse * scanResult; -otScanResponseIterator mScanResponseIter(scanResult); -} // namespace // Fully instantiate the generic implementation class in whatever compilation unit includes this file. template class GenericThreadStackManagerImpl_OpenThread; @@ -301,26 +281,6 @@ bool GenericThreadStackManagerImpl_OpenThread::_IsThreadProvisioned(v return provisioned; } -template -CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_GetThreadProvision(ByteSpan & netInfo) -{ - VerifyOrReturnError(Impl()->IsThreadProvisioned(), CHIP_ERROR_INCORRECT_STATE); - otOperationalDatasetTlvs datasetTlv; - - Impl()->LockThreadStack(); - otError otErr = otDatasetGetActiveTlvs(mOTInst, &datasetTlv); - Impl()->UnlockThreadStack(); - if (otErr != OT_ERROR_NONE) - { - return MapOpenThreadError(otErr); - } - - ReturnErrorOnFailure(mActiveDataset.Init(ByteSpan(datasetTlv.mTlvs, datasetTlv.mLength))); - netInfo = mActiveDataset.AsByteSpan(); - - return CHIP_NO_ERROR; -} - template bool GenericThreadStackManagerImpl_OpenThread::_IsThreadAttached(void) { @@ -333,85 +293,6 @@ bool GenericThreadStackManagerImpl_OpenThread::_IsThreadAttached(void return (curRole != OT_DEVICE_ROLE_DISABLED && curRole != OT_DEVICE_ROLE_DETACHED); } -template -CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_AttachToThreadNetwork( - ByteSpan netInfo, NetworkCommissioning::Internal::WirelessDriver::ConnectCallback * callback) -{ - // There is another ongoing connect request, reject the new one. - VerifyOrReturnError(mpConnectCallback == nullptr, CHIP_ERROR_INCORRECT_STATE); - ReturnErrorOnFailure(Impl()->SetThreadEnabled(false)); - ReturnErrorOnFailure(Impl()->SetThreadProvision(netInfo)); - ReturnErrorOnFailure(Impl()->SetThreadEnabled(true)); - mpConnectCallback = callback; - return CHIP_NO_ERROR; -} - -template -void GenericThreadStackManagerImpl_OpenThread::_OnThreadAttachFinished() -{ - if (mpConnectCallback != nullptr) - { - DeviceLayer::SystemLayer().ScheduleLambda([this]() { - mpConnectCallback->OnResult(NetworkCommissioning::Status::kSuccess, CharSpan(), 0); - mpConnectCallback = nullptr; - }); - } -} - -template -CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_StartThreadScan(ThreadDriver::ScanCallback * callback) -{ - // If there is another ongoing scan request, reject the new one. - VerifyOrReturnError(mpScanCallback == nullptr, CHIP_ERROR_INCORRECT_STATE); - mpScanCallback = callback; - CHIP_ERROR err = MapOpenThreadError(otLinkActiveScan(mOTInst, 0, /* all channels */ - 0, /* default value `kScanDurationDefault` = 300 ms. */ - _OnNetworkScanFinished, this)); - return err; -} - -template -void GenericThreadStackManagerImpl_OpenThread::_OnNetworkScanFinished(otActiveScanResult * aResult, void * aContext) -{ - reinterpret_cast(aContext)->_OnNetworkScanFinished(aResult); -} - -template -void GenericThreadStackManagerImpl_OpenThread::_OnNetworkScanFinished(otActiveScanResult * aResult) -{ - if (aResult == nullptr) // scan completed - { - if (mpScanCallback != nullptr) - { - DeviceLayer::SystemLayer().ScheduleLambda([this]() { - mpScanCallback->OnFinished(NetworkCommissioning::Status::kSuccess, CharSpan(), &mScanResponseIter); - mpScanCallback = nullptr; - }); - } - } - else - { - ChipLogProgress( - DeviceLayer, - "Thread Network: %s Panid 0x%" PRIx16 " Channel %" PRIu16 " RSSI %" PRId16 " LQI %" PRIu16 " Version %" PRIu16, - aResult->mNetworkName.m8, aResult->mPanId, aResult->mChannel, aResult->mRssi, aResult->mLqi, aResult->mVersion); - - NetworkCommissioning::ThreadScanResponse scanResponse = { 0 }; - - scanResponse.panId = aResult->mPanId; // why is scanResponse.panID 64b - scanResponse.channel = aResult->mChannel; // why is scanResponse.channel 16b - scanResponse.version = aResult->mVersion; - scanResponse.rssi = aResult->mRssi; - scanResponse.lqi = aResult->mLqi; - scanResponse.extendedAddress = Encoding::BigEndian::Get64(aResult->mExtAddress.m8); - scanResponse.extendedPanId = Encoding::BigEndian::Get64(aResult->mExtendedPanId.m8); - scanResponse.networkNameLen = strnlen(aResult->mNetworkName.m8, OT_NETWORK_NAME_MAX_SIZE); - memcpy(scanResponse.networkName, aResult->mNetworkName.m8, scanResponse.networkNameLen); - - mScanResponseIter.Add(&scanResponse); - } -} - template ConnectivityManager::ThreadDeviceType GenericThreadStackManagerImpl_OpenThread::_GetThreadDeviceType(void) { @@ -1623,8 +1504,6 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::DoInit(otInstanc ChipLogProgress(DeviceLayer, "OpenThread ifconfig up and thread start"); } - initNetworkCommissioningThreadDriver(); - exit: ChipLogProgress(DeviceLayer, "OpenThread started: %s", otThreadErrorToString(otErr)); return err; diff --git a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h index 5b44e32b668f87..ca10b5d31cd3fe 100644 --- a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h +++ b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h @@ -26,7 +26,6 @@ #pragma once #include -#include #include #if CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT @@ -40,7 +39,6 @@ #include #include #include -#include namespace chip { namespace DeviceLayer { @@ -84,14 +82,9 @@ class GenericThreadStackManagerImpl_OpenThread bool _IsThreadAttached(void); CHIP_ERROR _GetThreadProvision(ByteSpan & netInfo); CHIP_ERROR _SetThreadProvision(ByteSpan netInfo); - CHIP_ERROR _AttachToThreadNetwork(ByteSpan netInfo, NetworkCommissioning::Internal::WirelessDriver::ConnectCallback * callback); - void _OnThreadAttachFinished(void); void _ErasePersistentInfo(void); ConnectivityManager::ThreadDeviceType _GetThreadDeviceType(void); CHIP_ERROR _SetThreadDeviceType(ConnectivityManager::ThreadDeviceType deviceType); - CHIP_ERROR _StartThreadScan(NetworkCommissioning::ThreadDriver::ScanCallback * callback); - static void _OnNetworkScanFinished(otActiveScanResult * aResult, void * aContext); - void _OnNetworkScanFinished(otActiveScanResult * aResult); #if CHIP_DEVICE_CONFIG_ENABLE_SED CHIP_ERROR _GetSEDPollingConfig(ConnectivityManager::SEDPollingConfig & pollingConfig); @@ -143,11 +136,7 @@ class GenericThreadStackManagerImpl_OpenThread // ===== Private members for use by this class only. otInstance * mOTInst; - uint64_t mOverrunCount = 0; - Thread::OperationalDataset mActiveDataset = {}; - - NetworkCommissioning::ThreadDriver::ScanCallback * mpScanCallback; - NetworkCommissioning::Internal::WirelessDriver::ConnectCallback * mpConnectCallback; + uint64_t mOverrunCount = 0; #if CHIP_DEVICE_CONFIG_ENABLE_SED ConnectivityManager::SEDPollingConfig mPollingConfig; diff --git a/src/test_driver/efr32/BUILD.gn b/src/test_driver/efr32/BUILD.gn index a0c4d3433df98b..ea4feada715cef 100644 --- a/src/test_driver/efr32/BUILD.gn +++ b/src/test_driver/efr32/BUILD.gn @@ -57,9 +57,6 @@ efr32_sdk("sdk") { "BOARD_ID=${efr32_board}", "EFR32_LOG_ENABLED=1", "PW_RPC_ENABLED", - - # Thread is built but test driver do not have the NETWORK_COMMISSIONING cluster or zap config. - "_NO_NETWORK_COMMISSIONING_DRIVER_", ] }