Skip to content

Commit

Permalink
[Telink] Block device role changing into Router if commissioning wind…
Browse files Browse the repository at this point in the history
…ow opened and device not yet Router (#25395)

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

* [Telink] Add CHIP_DEVICE_CONFIG_ENABLE_THREAD check

* [Telink] - Add API in ThreadStackManager
- Add Thread stack lock during otThreadSetRouterEligible
- Suppress Router promotion whenever any commissioning window is open

* [Telink] Fix typo

* [Telink] Move device role check into SetRouterPromotion

* [Telink] Use _SetRouterPromotion only for FTD

* [Telink] Move SetRouterPromotion(false) at the end of OpenCommissioningWindow
  • Loading branch information
s07641069 authored and pull[bot] committed Oct 11, 2023
1 parent 1d71fed commit 2899985
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 0 deletions.
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)
{
ThreadStackMgr().SetRouterPromotion(true);
mRecoverRouterDeviceRole = false;
}
#endif

UpdateOpenerFabricIndex(NullNullable);
UpdateOpenerVendorId(NullNullable);

Expand Down Expand Up @@ -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;
}

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
5 changes: 5 additions & 0 deletions src/platform/Linux/ThreadStackManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions src/platform/Linux/ThreadStackManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1695,6 +1695,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
5 changes: 5 additions & 0 deletions src/platform/Tizen/ThreadStackManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 2 additions & 0 deletions src/platform/Tizen/ThreadStackManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 2899985

Please sign in to comment.