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

22 changes: 22 additions & 0 deletions src/app/server/CommissioningWindowManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
#include <platform/CommissionableDataProvider.h>
#include <platform/DeviceControlServer.h>

#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;

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

UpdateOpenerFabricIndex(NullNullable);
UpdateOpenerVendorId(NullNullable);

Expand Down Expand Up @@ -449,6 +462,15 @@ 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)
{
ThreadStackMgr().SetRouterPromotion(false);
mRecoverRouterDeviceRole = true;
}
#endif

if (mAppDelegate != nullptr)
{
mAppDelegate->OnCommissioningWindowOpened();
Expand Down
4 changes: 4 additions & 0 deletions src/app/server/CommissioningWindowManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<System::Clock::Seconds16> mMinCommissioningTimeoutOverride;
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,19 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::_GetPollPeriod(u
return CHIP_NO_ERROR;
}

template <class ImplClass>
void GenericThreadStackManagerImpl_OpenThread<ImplClass>::_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 <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