diff --git a/src/app/server/CommissioningWindowManager.cpp b/src/app/server/CommissioningWindowManager.cpp index 3ddde11a931acb..980d020a3c7bc6 100644 --- a/src/app/server/CommissioningWindowManager.cpp +++ b/src/app/server/CommissioningWindowManager.cpp @@ -25,6 +25,10 @@ #include #include +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD && CHIP_DEVICE_CONFIG_THREAD_FTD +using namespace chip::DeviceLayer; +#endif + using namespace chip::app::Clusters; using namespace chip::System::Clock; @@ -108,6 +112,15 @@ void CommissioningWindowManager::ResetState() UpdateWindowStatus(CommissioningWindowStatusEnum::kWindowNotOpen); +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD && CHIP_DEVICE_CONFIG_THREAD_FTD + // Recover Router device role. + if (mRecoverRouterDeviceRole) + { + ThreadStackMgr().SetRouterPromotion(true); + mRecoverRouterDeviceRole = false; + } +#endif + UpdateOpenerFabricIndex(NullNullable); UpdateOpenerVendorId(NullNullable); @@ -457,6 +470,15 @@ CHIP_ERROR CommissioningWindowManager::StartAdvertisement() // reset all advertising, switching to our new commissioning mode. app::DnssdServer::Instance().StartServer(); +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD && CHIP_DEVICE_CONFIG_THREAD_FTD + // Block device role changing into Router if commissioning window opened and device not yet Router. + if (ConnectivityManagerImpl().GetThreadDeviceType() == ConnectivityManager::kThreadDeviceType_Router) + { + ThreadStackMgr().SetRouterPromotion(false); + mRecoverRouterDeviceRole = true; + } +#endif + return CHIP_NO_ERROR; } diff --git a/src/app/server/CommissioningWindowManager.h b/src/app/server/CommissioningWindowManager.h index cc2eda2ea29199..070a86a66816a1 100644 --- a/src/app/server/CommissioningWindowManager.h +++ b/src/app/server/CommissioningWindowManager.h @@ -215,6 +215,10 @@ class CommissioningWindowManager : public Messaging::UnsolicitedMessageHandler, bool mSEDActiveModeEnabled = false; #endif +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD && CHIP_DEVICE_CONFIG_THREAD_FTD + bool mRecoverRouterDeviceRole = false; +#endif + // For tests only, so that we can test the commissioning window timeout // without having to wait 3 minutes. Optional mMinCommissioningTimeoutOverride; diff --git a/src/include/platform/ThreadStackManager.h b/src/include/platform/ThreadStackManager.h index 07d5130de1e59e..137ac5d0d59814 100755 --- a/src/include/platform/ThreadStackManager.h +++ b/src/include/platform/ThreadStackManager.h @@ -106,6 +106,7 @@ class ThreadStackManager CHIP_ERROR GetPrimary802154MACAddress(uint8_t * buf); CHIP_ERROR GetExternalIPv6Address(chip::Inet::IPAddress & addr); CHIP_ERROR GetPollPeriod(uint32_t & buf); + void SetRouterPromotion(bool val); CHIP_ERROR JoinerStart(); CHIP_ERROR SetThreadProvision(ByteSpan aDataset); @@ -443,6 +444,11 @@ inline CHIP_ERROR ThreadStackManager::GetPollPeriod(uint32_t & buf) return static_cast(this)->_GetPollPeriod(buf); } +inline void ThreadStackManager::SetRouterPromotion(bool val) +{ + static_cast(this)->_SetRouterPromotion(val); +} + inline CHIP_ERROR ThreadStackManager::JoinerStart() { return static_cast(this)->_JoinerStart(); diff --git a/src/platform/Linux/ThreadStackManagerImpl.cpp b/src/platform/Linux/ThreadStackManagerImpl.cpp index ad7e48b640e237..9b27f7d6c68e0f 100755 --- a/src/platform/Linux/ThreadStackManagerImpl.cpp +++ b/src/platform/Linux/ThreadStackManagerImpl.cpp @@ -567,6 +567,11 @@ CHIP_ERROR ThreadStackManagerImpl::_JoinerStart() return CHIP_ERROR_NOT_IMPLEMENTED; } +void ThreadStackManagerImpl::_SetRouterPromotion(bool val) +{ + // Set Router Promotion is not supported on linux +} + CHIP_ERROR ThreadStackManagerImpl::_StartThreadScan(ThreadDriver::ScanCallback * callback) { // There is another ongoing scan request, reject the new one. diff --git a/src/platform/Linux/ThreadStackManagerImpl.h b/src/platform/Linux/ThreadStackManagerImpl.h index 4595db6cf6d20e..37e743fbe2e64b 100755 --- a/src/platform/Linux/ThreadStackManagerImpl.h +++ b/src/platform/Linux/ThreadStackManagerImpl.h @@ -108,6 +108,8 @@ class ThreadStackManagerImpl : public ThreadStackManager CHIP_ERROR _JoinerStart(); + void _SetRouterPromotion(bool val); + void _ResetThreadNetworkDiagnosticsCounts(); CHIP_ERROR _WriteThreadNetworkDiagnosticAttributeToTlv(AttributeId attributeId, app::AttributeValueEncoder & encoder); diff --git a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp index 3489213552e2f4..603924e71bbc34 100644 --- a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp +++ b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp @@ -1695,6 +1695,19 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_GetPollPeriod(u return CHIP_NO_ERROR; } +template +void GenericThreadStackManagerImpl_OpenThread::_SetRouterPromotion(bool val) +{ +#if CHIP_DEVICE_CONFIG_THREAD_FTD + Impl()->LockThreadStack(); + if (otThreadGetDeviceRole(DeviceLayer::ThreadStackMgrImpl().OTInstance()) != OT_DEVICE_ROLE_ROUTER) + { + otThreadSetRouterEligible(DeviceLayer::ThreadStackMgrImpl().OTInstance(), val); + } + Impl()->UnlockThreadStack(); +#endif +} + template CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::DoInit(otInstance * otInst) { diff --git a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h index 79d8f7385d780f..413f00649ab593 100755 --- a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h +++ b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h @@ -117,6 +117,7 @@ class GenericThreadStackManagerImpl_OpenThread void _ResetThreadNetworkDiagnosticsCounts(void); CHIP_ERROR _WriteThreadNetworkDiagnosticAttributeToTlv(AttributeId attributeId, app::AttributeValueEncoder & encoder); CHIP_ERROR _GetPollPeriod(uint32_t & buf); + void _SetRouterPromotion(bool val); void _OnWoBLEAdvertisingStart(void); void _OnWoBLEAdvertisingStop(void); diff --git a/src/platform/Tizen/ThreadStackManagerImpl.cpp b/src/platform/Tizen/ThreadStackManagerImpl.cpp index 75c2dec4c0aa1b..233f28b87b0293 100644 --- a/src/platform/Tizen/ThreadStackManagerImpl.cpp +++ b/src/platform/Tizen/ThreadStackManagerImpl.cpp @@ -471,6 +471,11 @@ CHIP_ERROR ThreadStackManagerImpl::_JoinerStart() return CHIP_ERROR_NOT_IMPLEMENTED; } +void ThreadStackManagerImpl::_SetRouterPromotion(bool val) +{ + // Set Router Promotion is not supported on Tizen +} + CHIP_ERROR ThreadStackManagerImpl::_StartThreadScan(NetworkCommissioning::ThreadDriver::ScanCallback * callback) { ChipLogError(DeviceLayer, "Not implemented"); diff --git a/src/platform/Tizen/ThreadStackManagerImpl.h b/src/platform/Tizen/ThreadStackManagerImpl.h index 5671853f24eb8f..96cc7c715036ef 100644 --- a/src/platform/Tizen/ThreadStackManagerImpl.h +++ b/src/platform/Tizen/ThreadStackManagerImpl.h @@ -98,6 +98,8 @@ class ThreadStackManagerImpl : public ThreadStackManager CHIP_ERROR _JoinerStart(); + void _SetRouterPromotion(bool val); + void _ResetThreadNetworkDiagnosticsCounts(); CHIP_ERROR _WriteThreadNetworkDiagnosticAttributeToTlv(AttributeId attributeId, app::AttributeValueEncoder & encoder);