From fd5ee20ca757436550e0853a5f53671aa85d5fc2 Mon Sep 17 00:00:00 2001 From: Arkadiusz Bokowy Date: Thu, 30 Nov 2023 09:16:02 +0100 Subject: [PATCH 1/5] [Tizen] Implement GetThreadVersion in thread stack manager --- src/include/platform/ThreadStackManager.h | 6 ++++++ .../Tizen/NetworkCommissioningThreadDriver.cpp | 12 +++++------- src/platform/Tizen/ThreadStackManagerImpl.cpp | 16 ++++++++++++++++ src/platform/Tizen/ThreadStackManagerImpl.h | 2 ++ 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/include/platform/ThreadStackManager.h b/src/include/platform/ThreadStackManager.h index a28aea640ba46e..ca600dab41a7c8 100644 --- a/src/include/platform/ThreadStackManager.h +++ b/src/include/platform/ThreadStackManager.h @@ -179,6 +179,7 @@ class ThreadStackManager void OnPlatformEvent(const ChipDeviceEvent * event); void ErasePersistentInfo(); + uint16_t GetThreadVersion(); ConnectivityManager::ThreadDeviceType GetThreadDeviceType(); CHIP_ERROR SetThreadDeviceType(ConnectivityManager::ThreadDeviceType threadRole); @@ -397,6 +398,11 @@ inline void ThreadStackManager::ErasePersistentInfo() static_cast(this)->_ErasePersistentInfo(); } +inline uint16_t ThreadStackManager::GetThreadVersion() +{ + return static_cast(this)->_GetThreadVersion(); +} + inline ConnectivityManager::ThreadDeviceType ThreadStackManager::GetThreadDeviceType() { return static_cast(this)->_GetThreadDeviceType(); diff --git a/src/platform/Tizen/NetworkCommissioningThreadDriver.cpp b/src/platform/Tizen/NetworkCommissioningThreadDriver.cpp index 003564b4c90f0f..9a6516c966091d 100644 --- a/src/platform/Tizen/NetworkCommissioningThreadDriver.cpp +++ b/src/platform/Tizen/NetworkCommissioningThreadDriver.cpp @@ -28,7 +28,6 @@ #include #include "NetworkCommissioningDriver.h" -#include "ThreadStackManagerImpl.h" namespace chip { namespace DeviceLayer { @@ -38,8 +37,8 @@ namespace NetworkCommissioning { CHIP_ERROR TizenThreadDriver::Init(BaseDriver::NetworkStatusChangeCallback * networkStatusChangeCallback) { - VerifyOrReturnError(ConnectivityMgrImpl().IsThreadAttached(), CHIP_NO_ERROR); - VerifyOrReturnError(ThreadStackMgrImpl().GetThreadProvision(mStagingNetwork) == CHIP_NO_ERROR, CHIP_NO_ERROR); + VerifyOrReturnError(ConnectivityMgr().IsThreadAttached(), CHIP_NO_ERROR); + VerifyOrReturnError(ThreadStackMgr().GetThreadProvision(mStagingNetwork) == CHIP_NO_ERROR, CHIP_NO_ERROR); mSavedNetwork.Init(mStagingNetwork.AsByteSpan()); @@ -133,7 +132,7 @@ void TizenThreadDriver::ConnectNetwork(ByteSpan networkId, ConnectCallback * cal (networkId.size() == Thread::kSizeExtendedPanId && memcmp(networkId.data(), extpanid, Thread::kSizeExtendedPanId) == 0), status = Status::kNetworkNotFound); - VerifyOrExit(DeviceLayer::ThreadStackMgrImpl().AttachToThreadNetwork(mStagingNetwork, callback) == CHIP_NO_ERROR, + VerifyOrExit(DeviceLayer::ThreadStackMgr().AttachToThreadNetwork(mStagingNetwork, callback) == CHIP_NO_ERROR, status = Status::kUnknownError); exit: @@ -145,7 +144,7 @@ void TizenThreadDriver::ConnectNetwork(ByteSpan networkId, ConnectCallback * cal void TizenThreadDriver::ScanNetworks(ThreadDriver::ScanCallback * callback) { - CHIP_ERROR err = DeviceLayer::ThreadStackMgrImpl().StartThreadScan(callback); + CHIP_ERROR err = DeviceLayer::ThreadStackMgr().StartThreadScan(callback); if (err != CHIP_NO_ERROR) { callback->OnFinished(Status::kUnknownError, CharSpan(), nullptr); @@ -179,8 +178,7 @@ ThreadCapabilities TizenThreadDriver::GetSupportedThreadFeatures() uint16_t TizenThreadDriver::GetThreadVersion() { - // TODO Needs to be implemented with Tizen Thread stack api - return 0; + return DeviceLayer::ThreadStackMgr().GetThreadVersion(); } #endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD diff --git a/src/platform/Tizen/ThreadStackManagerImpl.cpp b/src/platform/Tizen/ThreadStackManagerImpl.cpp index 950b6ec300292c..5c238173251b14 100644 --- a/src/platform/Tizen/ThreadStackManagerImpl.cpp +++ b/src/platform/Tizen/ThreadStackManagerImpl.cpp @@ -394,6 +394,22 @@ CHIP_ERROR ThreadStackManagerImpl::_SetThreadEnabled(bool val) return CHIP_ERROR_INTERNAL; } +uint16_t ThreadStackManagerImpl::_GetThreadVersion() +{ + int threadErr = THREAD_ERROR_NONE; + thread_version_e version = 0; + + VerifyOrExit(mIsInitialized, ChipLogError(DeviceLayer, "Thread stack not initialized")); + + threadErr = thread_get_version(mThreadInstance, &version); + VerifyOrExit(threadErr == THREAD_ERROR_NONE, ChipLogError(DeviceLayer, "FAIL: get thread version")); + + ChipLogProgress(DeviceLayer, "Thread version [%u]", version); + +exit: + return version; +} + ConnectivityManager::ThreadDeviceType ThreadStackManagerImpl::_GetThreadDeviceType() { VerifyOrReturnError(mIsInitialized, ConnectivityManager::ThreadDeviceType::kThreadDeviceType_NotSupported, diff --git a/src/platform/Tizen/ThreadStackManagerImpl.h b/src/platform/Tizen/ThreadStackManagerImpl.h index 3c0206cfd525fe..267d6cbd0575c2 100644 --- a/src/platform/Tizen/ThreadStackManagerImpl.h +++ b/src/platform/Tizen/ThreadStackManagerImpl.h @@ -84,6 +84,8 @@ class ThreadStackManagerImpl : public ThreadStackManager void _OnThreadAttachFinished(void); + uint16_t _GetThreadVersion(); + ConnectivityManager::ThreadDeviceType _GetThreadDeviceType(); CHIP_ERROR _SetThreadDeviceType(ConnectivityManager::ThreadDeviceType deviceType); From 4d2879b390f2ac285f0b2e8ada60cca8a740edcb Mon Sep 17 00:00:00 2001 From: Arkadiusz Bokowy Date: Wed, 14 Aug 2024 10:12:19 +0200 Subject: [PATCH 2/5] Move otThreadGetVersion() usage to Thread stack manager class --- .../OpenThread/GenericNetworkCommissioningThreadDriver.cpp | 2 +- .../OpenThread/GenericThreadStackManagerImpl_OpenThread.h | 1 + .../OpenThread/GenericThreadStackManagerImpl_OpenThread.hpp | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/platform/OpenThread/GenericNetworkCommissioningThreadDriver.cpp b/src/platform/OpenThread/GenericNetworkCommissioningThreadDriver.cpp index 711ad4930f96d4..232d8c6f591172 100644 --- a/src/platform/OpenThread/GenericNetworkCommissioningThreadDriver.cpp +++ b/src/platform/OpenThread/GenericNetworkCommissioningThreadDriver.cpp @@ -325,7 +325,7 @@ ThreadCapabilities GenericThreadDriver::GetSupportedThreadFeatures() uint16_t GenericThreadDriver::GetThreadVersion() { - return otThreadGetVersion(); + return ThreadStackMgrImpl().GetThreadVersion(); } } // namespace NetworkCommissioning diff --git a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h index c45ff84bb0f26e..51a61ab4c906fa 100644 --- a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h +++ b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h @@ -94,6 +94,7 @@ class GenericThreadStackManagerImpl_OpenThread NetworkCommissioning::Internal::WirelessDriver::ConnectCallback * callback); void _OnThreadAttachFinished(void); void _ErasePersistentInfo(void); + uint16_t _GetThreadVersion(); ConnectivityManager::ThreadDeviceType _GetThreadDeviceType(void); CHIP_ERROR _SetThreadDeviceType(ConnectivityManager::ThreadDeviceType deviceType); CHIP_ERROR _StartThreadScan(NetworkCommissioning::ThreadDriver::ScanCallback * callback); diff --git a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.hpp b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.hpp index 61452f5ff0ec90..ff90218a7b8ed3 100644 --- a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.hpp +++ b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.hpp @@ -524,6 +524,12 @@ void GenericThreadStackManagerImpl_OpenThread::_OnNetworkScanFinished } } +template +uint16_t GenericThreadStackManagerImpl_OpenThread::_GetThreadVersion() +{ + return otThreadGetVersion(); +} + template ConnectivityManager::ThreadDeviceType GenericThreadStackManagerImpl_OpenThread::_GetThreadDeviceType(void) { From e3c2087ca559babc0ddd25fe1a56a080b277dee0 Mon Sep 17 00:00:00 2001 From: Arkadiusz Bokowy Date: Wed, 14 Aug 2024 10:15:08 +0200 Subject: [PATCH 3/5] Update C++ style --- ...GenericThreadStackManagerImpl_OpenThread.h | 40 +++++++++---------- ...nericThreadStackManagerImpl_OpenThread.hpp | 28 ++++++------- src/platform/OpenThread/OpenThreadUtils.cpp | 2 +- src/platform/OpenThread/OpenThreadUtils.h | 2 +- 4 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h index 51a61ab4c906fa..8469f906b9f3f8 100644 --- a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h +++ b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h @@ -70,7 +70,7 @@ class GenericThreadStackManagerImpl_OpenThread otInstance * OTInstance() const; static void OnOpenThreadStateChange(uint32_t flags, void * context); - inline void OverrunErrorTally(void); + inline void OverrunErrorTally(); void SetNetworkStatusChangeCallback(NetworkCommissioning::Internal::BaseDriver::NetworkStatusChangeCallback * statusChangeCallback) { @@ -80,22 +80,22 @@ class GenericThreadStackManagerImpl_OpenThread protected: // ===== Methods that implement the ThreadStackManager abstract interface. - void _ProcessThreadActivity(void); + void _ProcessThreadActivity(); bool _HaveRouteToAddress(const Inet::IPAddress & destAddr); void _OnPlatformEvent(const ChipDeviceEvent * event); - bool _IsThreadEnabled(void); + bool _IsThreadEnabled(); CHIP_ERROR _SetThreadEnabled(bool val); - bool _IsThreadProvisioned(void); - bool _IsThreadAttached(void); + bool _IsThreadProvisioned(); + bool _IsThreadAttached(); CHIP_ERROR _GetThreadProvision(Thread::OperationalDataset & dataset); CHIP_ERROR _SetThreadProvision(ByteSpan netInfo); CHIP_ERROR _AttachToThreadNetwork(const Thread::OperationalDataset & dataset, NetworkCommissioning::Internal::WirelessDriver::ConnectCallback * callback); - void _OnThreadAttachFinished(void); - void _ErasePersistentInfo(void); + void _OnThreadAttachFinished(); + void _ErasePersistentInfo(); uint16_t _GetThreadVersion(); - ConnectivityManager::ThreadDeviceType _GetThreadDeviceType(void); + ConnectivityManager::ThreadDeviceType _GetThreadDeviceType(); CHIP_ERROR _SetThreadDeviceType(ConnectivityManager::ThreadDeviceType deviceType); CHIP_ERROR _StartThreadScan(NetworkCommissioning::ThreadDriver::ScanCallback * callback); static void _OnNetworkScanFinished(otActiveScanResult * aResult, void * aContext); @@ -106,16 +106,16 @@ class GenericThreadStackManagerImpl_OpenThread CHIP_ERROR _SetPollingInterval(System::Clock::Milliseconds32 pollingInterval); #endif // CHIP_CONFIG_ENABLE_ICD_SERVER - bool _HaveMeshConnectivity(void); - CHIP_ERROR _GetAndLogThreadStatsCounters(void); - CHIP_ERROR _GetAndLogThreadTopologyMinimal(void); - CHIP_ERROR _GetAndLogThreadTopologyFull(void); + bool _HaveMeshConnectivity(); + CHIP_ERROR _GetAndLogThreadStatsCounters(); + CHIP_ERROR _GetAndLogThreadTopologyMinimal(); + CHIP_ERROR _GetAndLogThreadTopologyFull(); CHIP_ERROR _GetPrimary802154MACAddress(uint8_t * buf); CHIP_ERROR _GetExternalIPv6Address(chip::Inet::IPAddress & addr); - void _ResetThreadNetworkDiagnosticsCounts(void); + void _ResetThreadNetworkDiagnosticsCounts(); CHIP_ERROR _GetPollPeriod(uint32_t & buf); - void _OnWoBLEAdvertisingStart(void); - void _OnWoBLEAdvertisingStop(void); + void _OnWoBLEAdvertisingStart(); + void _OnWoBLEAdvertisingStop(); #if CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT CHIP_ERROR _AddSrpService(const char * aInstanceName, const char * aName, uint16_t aPort, @@ -145,8 +145,8 @@ class GenericThreadStackManagerImpl_OpenThread CHIP_ERROR ConfigureThreadStack(otInstance * otInst); CHIP_ERROR DoInit(otInstance * otInst); - bool IsThreadAttachedNoLock(void); - bool IsThreadInterfaceUpNoLock(void); + bool IsThreadAttachedNoLock(); + bool IsThreadInterfaceUpNoLock(); private: // ===== Private members for use by this class only. @@ -283,19 +283,19 @@ inline otInstance * GenericThreadStackManagerImpl_OpenThread::OTInsta } template -inline void GenericThreadStackManagerImpl_OpenThread::OverrunErrorTally(void) +inline void GenericThreadStackManagerImpl_OpenThread::OverrunErrorTally() { mOverrunCount++; } template -inline void GenericThreadStackManagerImpl_OpenThread::_OnWoBLEAdvertisingStart(void) +inline void GenericThreadStackManagerImpl_OpenThread::_OnWoBLEAdvertisingStart() { // Do nothing by default. } template -inline void GenericThreadStackManagerImpl_OpenThread::_OnWoBLEAdvertisingStop(void) +inline void GenericThreadStackManagerImpl_OpenThread::_OnWoBLEAdvertisingStop() { // Do nothing by default. } diff --git a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.hpp b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.hpp index ff90218a7b8ed3..df880ae0510ee2 100644 --- a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.hpp +++ b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.hpp @@ -27,6 +27,7 @@ #define GENERIC_THREAD_STACK_MANAGER_IMPL_OPENTHREAD_IPP #include +#include #include #include @@ -59,7 +60,6 @@ #include #include -#include extern "C" void otSysProcessDrivers(otInstance * aInstance); #if CHIP_DEVICE_CONFIG_THREAD_ENABLE_CLI @@ -80,7 +80,7 @@ app::Clusters::NetworkCommissioning::Instance sThreadNetworkCommissioningInstance(CHIP_DEVICE_CONFIG_THREAD_NETWORK_ENDPOINT_ID /* Endpoint Id */, &sGenericThreadDriver); #endif -void initNetworkCommissioningThreadDriver(void) +void initNetworkCommissioningThreadDriver() { #ifndef _NO_GENERIC_THREAD_NETWORK_COMMISSIONING_DRIVER_ sThreadNetworkCommissioningInstance.Init(); @@ -143,7 +143,7 @@ void GenericThreadStackManagerImpl_OpenThread::OnOpenThreadStateChang } template -void GenericThreadStackManagerImpl_OpenThread::_ProcessThreadActivity(void) +void GenericThreadStackManagerImpl_OpenThread::_ProcessThreadActivity() { otTaskletsProcess(mOTInst); otSysProcessDrivers(mOTInst); @@ -256,7 +256,7 @@ void GenericThreadStackManagerImpl_OpenThread::_OnPlatformEvent(const } template -bool GenericThreadStackManagerImpl_OpenThread::_IsThreadEnabled(void) +bool GenericThreadStackManagerImpl_OpenThread::_IsThreadEnabled() { VerifyOrReturnValue(mOTInst, false); otDeviceRole curRole; @@ -330,7 +330,7 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_SetThreadProvis } template -bool GenericThreadStackManagerImpl_OpenThread::_IsThreadProvisioned(void) +bool GenericThreadStackManagerImpl_OpenThread::_IsThreadProvisioned() { VerifyOrReturnValue(mOTInst, false); bool provisioned; @@ -363,7 +363,7 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_GetThreadProvis } template -bool GenericThreadStackManagerImpl_OpenThread::_IsThreadAttached(void) +bool GenericThreadStackManagerImpl_OpenThread::_IsThreadAttached() { VerifyOrReturnValue(mOTInst, false); otDeviceRole curRole; @@ -531,7 +531,7 @@ uint16_t GenericThreadStackManagerImpl_OpenThread::_GetThreadVersion( } template -ConnectivityManager::ThreadDeviceType GenericThreadStackManagerImpl_OpenThread::_GetThreadDeviceType(void) +ConnectivityManager::ThreadDeviceType GenericThreadStackManagerImpl_OpenThread::_GetThreadDeviceType() { VerifyOrReturnValue(mOTInst, ConnectivityManager::kThreadDeviceType_NotSupported); ConnectivityManager::ThreadDeviceType deviceType; @@ -657,7 +657,7 @@ GenericThreadStackManagerImpl_OpenThread::_SetThreadDeviceType(Connec } template -bool GenericThreadStackManagerImpl_OpenThread::_HaveMeshConnectivity(void) +bool GenericThreadStackManagerImpl_OpenThread::_HaveMeshConnectivity() { VerifyOrReturnValue(mOTInst, false); bool res; @@ -706,7 +706,7 @@ bool GenericThreadStackManagerImpl_OpenThread::_HaveMeshConnectivity( } template -CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_GetAndLogThreadStatsCounters(void) +CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_GetAndLogThreadStatsCounters() { VerifyOrReturnError(mOTInst, CHIP_ERROR_INCORRECT_STATE); CHIP_ERROR err = CHIP_NO_ERROR; @@ -801,7 +801,7 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_GetAndLogThread } template -CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_GetAndLogThreadTopologyMinimal(void) +CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_GetAndLogThreadTopologyMinimal() { VerifyOrReturnError(mOTInst, CHIP_ERROR_INCORRECT_STATE); CHIP_ERROR err = CHIP_NO_ERROR; @@ -1078,7 +1078,7 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_GetExternalIPv6 } template -void GenericThreadStackManagerImpl_OpenThread::_ResetThreadNetworkDiagnosticsCounts(void) +void GenericThreadStackManagerImpl_OpenThread::_ResetThreadNetworkDiagnosticsCounts() { // Based on the spec, only OverrunCount should be resetted. mOverrunCount = 0; @@ -1181,14 +1181,14 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::DoInit(otInstanc } template -bool GenericThreadStackManagerImpl_OpenThread::IsThreadAttachedNoLock(void) +bool GenericThreadStackManagerImpl_OpenThread::IsThreadAttachedNoLock() { otDeviceRole curRole = otThreadGetDeviceRole(mOTInst); return (curRole != OT_DEVICE_ROLE_DISABLED && curRole != OT_DEVICE_ROLE_DETACHED); } template -bool GenericThreadStackManagerImpl_OpenThread::IsThreadInterfaceUpNoLock(void) +bool GenericThreadStackManagerImpl_OpenThread::IsThreadInterfaceUpNoLock() { return otIp6IsEnabled(mOTInst); } @@ -1248,7 +1248,7 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_SetPollingInter #endif // CHIP_CONFIG_ENABLE_ICD_SERVER template -void GenericThreadStackManagerImpl_OpenThread::_ErasePersistentInfo(void) +void GenericThreadStackManagerImpl_OpenThread::_ErasePersistentInfo() { VerifyOrReturn(mOTInst); ChipLogProgress(DeviceLayer, "Erasing Thread persistent info..."); diff --git a/src/platform/OpenThread/OpenThreadUtils.cpp b/src/platform/OpenThread/OpenThreadUtils.cpp index 093997c66fb789..f2470b38ce4821 100644 --- a/src/platform/OpenThread/OpenThreadUtils.cpp +++ b/src/platform/OpenThread/OpenThreadUtils.cpp @@ -80,7 +80,7 @@ bool FormatOpenThreadError(char * buf, uint16_t bufSize, CHIP_ERROR err) /** * Register a text error formatter for OpenThread errors. */ -void RegisterOpenThreadErrorFormatter(void) +void RegisterOpenThreadErrorFormatter() { static ErrorFormatter sOpenThreadErrorFormatter = { FormatOpenThreadError, NULL }; diff --git a/src/platform/OpenThread/OpenThreadUtils.h b/src/platform/OpenThread/OpenThreadUtils.h index f9609e8d8728af..ab0cdd06a8aa6f 100644 --- a/src/platform/OpenThread/OpenThreadUtils.h +++ b/src/platform/OpenThread/OpenThreadUtils.h @@ -59,7 +59,7 @@ namespace Internal { #endif // CHIP_CONFIG_OPENTHREAD_ERROR_MAX extern CHIP_ERROR MapOpenThreadError(otError otErr); -extern void RegisterOpenThreadErrorFormatter(void); +extern void RegisterOpenThreadErrorFormatter(); /** * Log information related to a state change in the OpenThread stack. From a14ff4e8ab19cdff7b07b9ad2a7fa5da85593baa Mon Sep 17 00:00:00 2001 From: Arkadiusz Bokowy Date: Wed, 14 Aug 2024 11:14:12 +0200 Subject: [PATCH 4/5] Make GetThreadVersion public interface --- src/include/platform/ThreadStackManager.h | 12 +++---- ...enericNetworkCommissioningThreadDriver.cpp | 4 ++- ...GenericThreadStackManagerImpl_OpenThread.h | 2 +- ...nericThreadStackManagerImpl_OpenThread.hpp | 13 ++++---- .../NetworkCommissioningThreadDriver.cpp | 4 ++- src/platform/Tizen/ThreadStackManagerImpl.cpp | 31 +++++++++---------- src/platform/Tizen/ThreadStackManagerImpl.h | 8 +---- 7 files changed, 36 insertions(+), 38 deletions(-) diff --git a/src/include/platform/ThreadStackManager.h b/src/include/platform/ThreadStackManager.h index ca600dab41a7c8..f9f7aed04e4253 100644 --- a/src/include/platform/ThreadStackManager.h +++ b/src/include/platform/ThreadStackManager.h @@ -105,6 +105,7 @@ class ThreadStackManager CHIP_ERROR GetAndLogThreadTopologyFull(); CHIP_ERROR GetPrimary802154MACAddress(uint8_t * buf); CHIP_ERROR GetExternalIPv6Address(chip::Inet::IPAddress & addr); + CHIP_ERROR GetThreadVersion(uint16_t & version); CHIP_ERROR GetPollPeriod(uint32_t & buf); CHIP_ERROR SetThreadProvision(ByteSpan aDataset); @@ -179,7 +180,6 @@ class ThreadStackManager void OnPlatformEvent(const ChipDeviceEvent * event); void ErasePersistentInfo(); - uint16_t GetThreadVersion(); ConnectivityManager::ThreadDeviceType GetThreadDeviceType(); CHIP_ERROR SetThreadDeviceType(ConnectivityManager::ThreadDeviceType threadRole); @@ -398,11 +398,6 @@ inline void ThreadStackManager::ErasePersistentInfo() static_cast(this)->_ErasePersistentInfo(); } -inline uint16_t ThreadStackManager::GetThreadVersion() -{ - return static_cast(this)->_GetThreadVersion(); -} - inline ConnectivityManager::ThreadDeviceType ThreadStackManager::GetThreadDeviceType() { return static_cast(this)->_GetThreadDeviceType(); @@ -450,6 +445,11 @@ inline CHIP_ERROR ThreadStackManager::GetExternalIPv6Address(chip::Inet::IPAddre return static_cast(this)->_GetExternalIPv6Address(addr); } +inline CHIP_ERROR ThreadStackManager::GetThreadVersion(uint16_t & version) +{ + return static_cast(this)->_GetThreadVersion(version); +} + inline CHIP_ERROR ThreadStackManager::GetPollPeriod(uint32_t & buf) { return static_cast(this)->_GetPollPeriod(buf); diff --git a/src/platform/OpenThread/GenericNetworkCommissioningThreadDriver.cpp b/src/platform/OpenThread/GenericNetworkCommissioningThreadDriver.cpp index 232d8c6f591172..89560b07d97fe5 100644 --- a/src/platform/OpenThread/GenericNetworkCommissioningThreadDriver.cpp +++ b/src/platform/OpenThread/GenericNetworkCommissioningThreadDriver.cpp @@ -325,7 +325,9 @@ ThreadCapabilities GenericThreadDriver::GetSupportedThreadFeatures() uint16_t GenericThreadDriver::GetThreadVersion() { - return ThreadStackMgrImpl().GetThreadVersion(); + uint16_t version; + VerifyOrReturnError(ConnectivityMgrImpl().GetThreadVersion(version) == CHIP_NO_ERROR, 0); + return version; } } // namespace NetworkCommissioning diff --git a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h index 8469f906b9f3f8..169820c103e828 100644 --- a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h +++ b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h @@ -94,7 +94,6 @@ class GenericThreadStackManagerImpl_OpenThread NetworkCommissioning::Internal::WirelessDriver::ConnectCallback * callback); void _OnThreadAttachFinished(); void _ErasePersistentInfo(); - uint16_t _GetThreadVersion(); ConnectivityManager::ThreadDeviceType _GetThreadDeviceType(); CHIP_ERROR _SetThreadDeviceType(ConnectivityManager::ThreadDeviceType deviceType); CHIP_ERROR _StartThreadScan(NetworkCommissioning::ThreadDriver::ScanCallback * callback); @@ -112,6 +111,7 @@ class GenericThreadStackManagerImpl_OpenThread CHIP_ERROR _GetAndLogThreadTopologyFull(); CHIP_ERROR _GetPrimary802154MACAddress(uint8_t * buf); CHIP_ERROR _GetExternalIPv6Address(chip::Inet::IPAddress & addr); + CHIP_ERROR _GetThreadVersion(uint16_t & version); void _ResetThreadNetworkDiagnosticsCounts(); CHIP_ERROR _GetPollPeriod(uint32_t & buf); void _OnWoBLEAdvertisingStart(); diff --git a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.hpp b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.hpp index df880ae0510ee2..6916c096c9ce50 100644 --- a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.hpp +++ b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.hpp @@ -524,12 +524,6 @@ void GenericThreadStackManagerImpl_OpenThread::_OnNetworkScanFinished } } -template -uint16_t GenericThreadStackManagerImpl_OpenThread::_GetThreadVersion() -{ - return otThreadGetVersion(); -} - template ConnectivityManager::ThreadDeviceType GenericThreadStackManagerImpl_OpenThread::_GetThreadDeviceType() { @@ -1077,6 +1071,13 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_GetExternalIPv6 return CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND; } +template +CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_GetThreadVersion(uint16_t & version) +{ + version = otThreadGetVersion(); + return CHIP_NO_ERROR; +} + template void GenericThreadStackManagerImpl_OpenThread::_ResetThreadNetworkDiagnosticsCounts() { diff --git a/src/platform/Tizen/NetworkCommissioningThreadDriver.cpp b/src/platform/Tizen/NetworkCommissioningThreadDriver.cpp index 9a6516c966091d..f954e6c2fc67e0 100644 --- a/src/platform/Tizen/NetworkCommissioningThreadDriver.cpp +++ b/src/platform/Tizen/NetworkCommissioningThreadDriver.cpp @@ -178,7 +178,9 @@ ThreadCapabilities TizenThreadDriver::GetSupportedThreadFeatures() uint16_t TizenThreadDriver::GetThreadVersion() { - return DeviceLayer::ThreadStackMgr().GetThreadVersion(); + uint16_t version = 0; + DeviceLayer::ThreadStackMgr().GetThreadVersion(version); + return version; } #endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD diff --git a/src/platform/Tizen/ThreadStackManagerImpl.cpp b/src/platform/Tizen/ThreadStackManagerImpl.cpp index 5c238173251b14..0ae0f8f84ad7c8 100644 --- a/src/platform/Tizen/ThreadStackManagerImpl.cpp +++ b/src/platform/Tizen/ThreadStackManagerImpl.cpp @@ -54,9 +54,12 @@ #include #include +#include #include #include +using chip::DeviceLayer::Internal::TizenToChipError; + namespace chip { namespace DeviceLayer { @@ -394,22 +397,6 @@ CHIP_ERROR ThreadStackManagerImpl::_SetThreadEnabled(bool val) return CHIP_ERROR_INTERNAL; } -uint16_t ThreadStackManagerImpl::_GetThreadVersion() -{ - int threadErr = THREAD_ERROR_NONE; - thread_version_e version = 0; - - VerifyOrExit(mIsInitialized, ChipLogError(DeviceLayer, "Thread stack not initialized")); - - threadErr = thread_get_version(mThreadInstance, &version); - VerifyOrExit(threadErr == THREAD_ERROR_NONE, ChipLogError(DeviceLayer, "FAIL: get thread version")); - - ChipLogProgress(DeviceLayer, "Thread version [%u]", version); - -exit: - return version; -} - ConnectivityManager::ThreadDeviceType ThreadStackManagerImpl::_GetThreadDeviceType() { VerifyOrReturnError(mIsInitialized, ConnectivityManager::ThreadDeviceType::kThreadDeviceType_NotSupported, @@ -530,6 +517,18 @@ CHIP_ERROR ThreadStackManagerImpl::_GetExternalIPv6Address(chip::Inet::IPAddress return CHIP_ERROR_NOT_IMPLEMENTED; } +CHIP_ERROR ThreadStackManagerImpl::_GetThreadVersion(uint16_t & version) +{ + VerifyOrReturnError(mIsInitialized, CHIP_ERROR_UNINITIALIZED); + + int threadErr = thread_get_version(mThreadInstance, &version); + VerifyOrReturnError(threadErr == THREAD_ERROR_NONE, TizenToChipError(threadErr), + ChipLogError(DeviceLayer, "FAIL: Get thread version: %s", get_error_message(threadErr))); + + ChipLogProgress(DeviceLayer, "Thread version [%u]", version); + return CHIP_NO_ERROR; +} + CHIP_ERROR ThreadStackManagerImpl::_GetPollPeriod(uint32_t & buf) { ChipLogError(DeviceLayer, "Not implemented"); diff --git a/src/platform/Tizen/ThreadStackManagerImpl.h b/src/platform/Tizen/ThreadStackManagerImpl.h index 267d6cbd0575c2..2bb0954bc8d25c 100644 --- a/src/platform/Tizen/ThreadStackManagerImpl.h +++ b/src/platform/Tizen/ThreadStackManagerImpl.h @@ -84,8 +84,6 @@ class ThreadStackManagerImpl : public ThreadStackManager void _OnThreadAttachFinished(void); - uint16_t _GetThreadVersion(); - ConnectivityManager::ThreadDeviceType _GetThreadDeviceType(); CHIP_ERROR _SetThreadDeviceType(ConnectivityManager::ThreadDeviceType deviceType); @@ -93,15 +91,11 @@ class ThreadStackManagerImpl : public ThreadStackManager bool _HaveMeshConnectivity(); CHIP_ERROR _GetAndLogThreadStatsCounters(); - CHIP_ERROR _GetAndLogThreadTopologyMinimal(); - CHIP_ERROR _GetAndLogThreadTopologyFull(); - CHIP_ERROR _GetPrimary802154MACAddress(uint8_t * buf); - CHIP_ERROR _GetExternalIPv6Address(chip::Inet::IPAddress & addr); - + CHIP_ERROR _GetThreadVersion(uint16_t & version); CHIP_ERROR _GetPollPeriod(uint32_t & buf); void _ResetThreadNetworkDiagnosticsCounts(); From 037a48b199cca422598465bf3120b254564b5b50 Mon Sep 17 00:00:00 2001 From: Arkadiusz Bokowy Date: Wed, 14 Aug 2024 11:28:32 +0200 Subject: [PATCH 5/5] Implement mock _GetThreadVersion() for Linux, NuttX and WebOS --- src/platform/Linux/NetworkCommissioningThreadDriver.cpp | 6 +++--- src/platform/Linux/ThreadStackManagerImpl.cpp | 7 +++++++ src/platform/Linux/ThreadStackManagerImpl.h | 2 +- src/platform/NuttX/NetworkCommissioningThreadDriver.cpp | 6 +++--- src/platform/NuttX/ThreadStackManagerImpl.cpp | 7 +++++++ src/platform/NuttX/ThreadStackManagerImpl.h | 2 +- .../OpenThread/GenericNetworkCommissioningThreadDriver.cpp | 4 ++-- src/platform/webos/NetworkCommissioningThreadDriver.cpp | 6 +++--- src/platform/webos/ThreadStackManagerImpl.cpp | 7 +++++++ src/platform/webos/ThreadStackManagerImpl.h | 2 +- 10 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/platform/Linux/NetworkCommissioningThreadDriver.cpp b/src/platform/Linux/NetworkCommissioningThreadDriver.cpp index 9bb6015809fc9a..6792e9c04439e8 100644 --- a/src/platform/Linux/NetworkCommissioningThreadDriver.cpp +++ b/src/platform/Linux/NetworkCommissioningThreadDriver.cpp @@ -211,9 +211,9 @@ ThreadCapabilities LinuxThreadDriver::GetSupportedThreadFeatures() uint16_t LinuxThreadDriver::GetThreadVersion() { - // TODO https://github.com/project-chip/connectedhomeip/issues/30602 - // Needs to be implemented with DBUS io.openthread.BorderRouter Thread API - return 0; + uint16_t version = 0; + ThreadStackMgrImpl().GetThreadVersion(version); + return version; } #endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD diff --git a/src/platform/Linux/ThreadStackManagerImpl.cpp b/src/platform/Linux/ThreadStackManagerImpl.cpp index 126d30164492fe..76fd478a050f89 100644 --- a/src/platform/Linux/ThreadStackManagerImpl.cpp +++ b/src/platform/Linux/ThreadStackManagerImpl.cpp @@ -563,6 +563,13 @@ CHIP_ERROR ThreadStackManagerImpl::_GetExternalIPv6Address(chip::Inet::IPAddress return CHIP_ERROR_NOT_IMPLEMENTED; } +CHIP_ERROR ThreadStackManagerImpl::_GetThreadVersion(uint16_t & version) +{ + // TODO https://github.com/project-chip/connectedhomeip/issues/30602 + // Needs to be implemented with DBUS io.openthread.BorderRouter Thread API + return CHIP_ERROR_NOT_IMPLEMENTED; +} + CHIP_ERROR ThreadStackManagerImpl::_GetPollPeriod(uint32_t & buf) { // TODO: Remove Weave legacy APIs diff --git a/src/platform/Linux/ThreadStackManagerImpl.h b/src/platform/Linux/ThreadStackManagerImpl.h index e9c1a825d35a91..685348a4ae4a72 100755 --- a/src/platform/Linux/ThreadStackManagerImpl.h +++ b/src/platform/Linux/ThreadStackManagerImpl.h @@ -113,7 +113,7 @@ class ThreadStackManagerImpl : public ThreadStackManager CHIP_ERROR _GetPrimary802154MACAddress(uint8_t * buf); CHIP_ERROR _GetExternalIPv6Address(chip::Inet::IPAddress & addr); - + CHIP_ERROR _GetThreadVersion(uint16_t & version); CHIP_ERROR _GetPollPeriod(uint32_t & buf); void _ResetThreadNetworkDiagnosticsCounts(); diff --git a/src/platform/NuttX/NetworkCommissioningThreadDriver.cpp b/src/platform/NuttX/NetworkCommissioningThreadDriver.cpp index 79da48d49c0419..27c410400421a8 100644 --- a/src/platform/NuttX/NetworkCommissioningThreadDriver.cpp +++ b/src/platform/NuttX/NetworkCommissioningThreadDriver.cpp @@ -211,9 +211,9 @@ ThreadCapabilities LinuxThreadDriver::GetSupportedThreadFeatures() uint16_t LinuxThreadDriver::GetThreadVersion() { - // TODO https://github.com/project-chip/connectedhomeip/issues/30602 - // Needs to be implemented with DBUS io.openthread.BorderRouter Thread API - return 0; + uint16_t version = 0; + ThreadStackMgrImpl().GetThreadVersion(version); + return version; } #endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD diff --git a/src/platform/NuttX/ThreadStackManagerImpl.cpp b/src/platform/NuttX/ThreadStackManagerImpl.cpp index cb717324fc989d..8eb1538128108b 100644 --- a/src/platform/NuttX/ThreadStackManagerImpl.cpp +++ b/src/platform/NuttX/ThreadStackManagerImpl.cpp @@ -568,6 +568,13 @@ CHIP_ERROR ThreadStackManagerImpl::_GetExternalIPv6Address(chip::Inet::IPAddress return CHIP_ERROR_NOT_IMPLEMENTED; } +CHIP_ERROR ThreadStackManagerImpl::_GetThreadVersion(uint16_t & version) +{ + // TODO https://github.com/project-chip/connectedhomeip/issues/30602 + // Needs to be implemented with DBUS io.openthread.BorderRouter Thread API + return CHIP_ERROR_NOT_IMPLEMENTED; +} + CHIP_ERROR ThreadStackManagerImpl::_GetPollPeriod(uint32_t & buf) { // TODO: Remove Weave legacy APIs diff --git a/src/platform/NuttX/ThreadStackManagerImpl.h b/src/platform/NuttX/ThreadStackManagerImpl.h index 5ef3d8ed36555f..ce66d51c2201a2 100644 --- a/src/platform/NuttX/ThreadStackManagerImpl.h +++ b/src/platform/NuttX/ThreadStackManagerImpl.h @@ -114,7 +114,7 @@ class ThreadStackManagerImpl : public ThreadStackManager CHIP_ERROR _GetPrimary802154MACAddress(uint8_t * buf); CHIP_ERROR _GetExternalIPv6Address(chip::Inet::IPAddress & addr); - + CHIP_ERROR _GetThreadVersion(uint16_t & version); CHIP_ERROR _GetPollPeriod(uint32_t & buf); CHIP_ERROR _JoinerStart(); diff --git a/src/platform/OpenThread/GenericNetworkCommissioningThreadDriver.cpp b/src/platform/OpenThread/GenericNetworkCommissioningThreadDriver.cpp index 89560b07d97fe5..0e7701ec481add 100644 --- a/src/platform/OpenThread/GenericNetworkCommissioningThreadDriver.cpp +++ b/src/platform/OpenThread/GenericNetworkCommissioningThreadDriver.cpp @@ -325,8 +325,8 @@ ThreadCapabilities GenericThreadDriver::GetSupportedThreadFeatures() uint16_t GenericThreadDriver::GetThreadVersion() { - uint16_t version; - VerifyOrReturnError(ConnectivityMgrImpl().GetThreadVersion(version) == CHIP_NO_ERROR, 0); + uint16_t version = 0; + ThreadStackMgrImpl().GetThreadVersion(version); return version; } diff --git a/src/platform/webos/NetworkCommissioningThreadDriver.cpp b/src/platform/webos/NetworkCommissioningThreadDriver.cpp index 557d3f6f7f7cf7..7a9f5873d57e9c 100644 --- a/src/platform/webos/NetworkCommissioningThreadDriver.cpp +++ b/src/platform/webos/NetworkCommissioningThreadDriver.cpp @@ -211,9 +211,9 @@ ThreadCapabilities LinuxThreadDriver::GetSupportedThreadFeatures() uint16_t LinuxThreadDriver::GetThreadVersion() { - // TODO https://github.com/project-chip/connectedhomeip/issues/30602 - // Needs to be implemented with DBUS io.openthread.BorderRouter Thread API - return 0; + uint16_t version = 0; + ThreadStackMgrImpl().GetThreadVersion(version); + return version; } #endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD diff --git a/src/platform/webos/ThreadStackManagerImpl.cpp b/src/platform/webos/ThreadStackManagerImpl.cpp index cb538fa34ec618..cda82e673ac275 100644 --- a/src/platform/webos/ThreadStackManagerImpl.cpp +++ b/src/platform/webos/ThreadStackManagerImpl.cpp @@ -525,6 +525,13 @@ CHIP_ERROR ThreadStackManagerImpl::_GetExternalIPv6Address(chip::Inet::IPAddress return CHIP_ERROR_NOT_IMPLEMENTED; } +CHIP_ERROR ThreadStackManagerImpl::_GetThreadVersion(uint16_t & version) +{ + // TODO https://github.com/project-chip/connectedhomeip/issues/30602 + // Needs to be implemented with DBUS io.openthread.BorderRouter Thread API + return CHIP_ERROR_NOT_IMPLEMENTED; +} + CHIP_ERROR ThreadStackManagerImpl::_GetPollPeriod(uint32_t & buf) { // TODO: Remove Weave legacy APIs diff --git a/src/platform/webos/ThreadStackManagerImpl.h b/src/platform/webos/ThreadStackManagerImpl.h index b102e16ab568f7..64c3b8f6200bb8 100644 --- a/src/platform/webos/ThreadStackManagerImpl.h +++ b/src/platform/webos/ThreadStackManagerImpl.h @@ -101,7 +101,7 @@ class ThreadStackManagerImpl : public ThreadStackManager CHIP_ERROR _GetPrimary802154MACAddress(uint8_t * buf); CHIP_ERROR _GetExternalIPv6Address(chip::Inet::IPAddress & addr); - + CHIP_ERROR _GetThreadVersion(uint16_t & version); CHIP_ERROR _GetPollPeriod(uint32_t & buf); void _ResetThreadNetworkDiagnosticsCounts();