Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Telink] Block device role changing into Router if commissioning window opened and device not yet Router #25395

36 changes: 19 additions & 17 deletions src/app/server/CommissioningWindowManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <platform/DeviceControlServer.h>

#if CHIP_DEVICE_CONFIG_ENABLE_THREAD && CHIP_DEVICE_CONFIG_THREAD_FTD
#include <openthread/thread_ftd.h>
using namespace chip::DeviceLayer;
#endif

Expand Down Expand Up @@ -113,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)
s07641069 marked this conversation as resolved.
Show resolved Hide resolved
{
ThreadStackMgr().SetRouterPromotion(true);
mRecoverRouterDeviceRole = false;
}
#endif

UpdateOpenerFabricIndex(NullNullable);
UpdateOpenerVendorId(NullNullable);

Expand Down Expand Up @@ -454,6 +462,16 @@ CHIP_ERROR CommissioningWindowManager::StartAdvertisement()
UpdateWindowStatus(CommissioningWindowStatusEnum::kBasicWindowOpen);
}

#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 &&
otThreadGetDeviceRole(DeviceLayer::ThreadStackMgrImpl().OTInstance()) != OT_DEVICE_ROLE_ROUTER)
Damian-Nordic marked this conversation as resolved.
Show resolved Hide resolved
{
ThreadStackMgr().SetRouterPromotion(false);
mRecoverRouterDeviceRole = true;
}
#endif

if (mAppDelegate != nullptr)
{
mAppDelegate->OnCommissioningWindowOpened();
Expand Down Expand Up @@ -553,22 +571,6 @@ void CommissioningWindowManager::UpdateWindowStatus(CommissioningWindowStatusEnu
AdministratorCommissioning::Attributes::WindowStatus::Id);
}

#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 (mWindowStatus == CommissioningWindowStatusEnum::kEnhancedWindowOpen &&
ConnectivityManagerImpl().GetThreadDeviceType() == ConnectivityManager::kThreadDeviceType_Router &&
otThreadGetDeviceRole(DeviceLayer::ThreadStackMgrImpl().OTInstance()) != OT_DEVICE_ROLE_ROUTER)
{
otThreadSetRouterEligible(DeviceLayer::ThreadStackMgrImpl().OTInstance(), false);
mRecoverRouterDeviceRole = true;
}
// Recover Router device role.
else if (mWindowStatus == CommissioningWindowStatusEnum::kWindowNotOpen && mRecoverRouterDeviceRole)
{
otThreadSetRouterEligible(DeviceLayer::ThreadStackMgrImpl().OTInstance(), true);
mRecoverRouterDeviceRole = false;
}
#endif
}

void CommissioningWindowManager::UpdateOpenerVendorId(Nullable<VendorId> aNewOpenerVendorId)
Expand Down
6 changes: 6 additions & 0 deletions src/include/platform/ThreadStackManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -443,6 +444,11 @@ inline CHIP_ERROR ThreadStackManager::GetPollPeriod(uint32_t & buf)
return static_cast<ImplClass *>(this)->_GetPollPeriod(buf);
}

inline void ThreadStackManager::SetRouterPromotion(bool val)
{
static_cast<ImplClass *>(this)->_SetRouterPromotion(val);
}

inline CHIP_ERROR ThreadStackManager::JoinerStart()
{
return static_cast<ImplClass *>(this)->_JoinerStart();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1694,6 +1694,14 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::_GetPollPeriod(u
return CHIP_NO_ERROR;
}

template <class ImplClass>
void GenericThreadStackManagerImpl_OpenThread<ImplClass>::_SetRouterPromotion(bool val)
{
Impl()->LockThreadStack();
otThreadSetRouterEligible(DeviceLayer::ThreadStackMgrImpl().OTInstance(), val);
Impl()->UnlockThreadStack();
}

template <class ImplClass>
CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::DoInit(otInstance * otInst)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down