Skip to content

Commit

Permalink
[Thread] Fix linker errors when linking with OpenThread MTD (#3845)
Browse files Browse the repository at this point in the history
- Add config variable CHIP_DEVICE_CONFIG_THREAD_FTD
  indicating if CHIP should use Full Thread Device features.
- On nrfconnect bind the variable to Kconfig variable
  CONFIG_OPENTHREAD_FTD.
- Fix ThreadStackManager build with FTD features disabled.
  • Loading branch information
Damian-Nordic authored and pull[bot] committed Nov 30, 2020
1 parent 0629b10 commit 4593714
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 30 deletions.
9 changes: 9 additions & 0 deletions src/include/platform/CHIPDeviceConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,15 @@
#define CHIP_DEVICE_CONFIG_ENABLE_THREAD 0
#endif

/**
* CHIP_DEVICE_CONFIG_THREAD_FTD
*
* Enable Full Thread Device features
*/
#ifndef CHIP_DEVICE_CONFIG_THREAD_FTD
#define CHIP_DEVICE_CONFIG_THREAD_FTD 1
#endif

/**
* CHIP_DEVICE_CONFIG_THREAD_TASK_NAME
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@

#include <openthread/cli.h>
#include <openthread/dataset.h>
#include <openthread/dataset_ftd.h>
#include <openthread/joiner.h>
#include <openthread/link.h>
#include <openthread/netdata.h>
#include <openthread/tasklet.h>
#include <openthread/thread.h>

#if CHIP_DEVICE_CONFIG_THREAD_FTD
#include <openthread/dataset_ftd.h>
#include <openthread/thread_ftd.h>
#endif

#include <platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h>
#include <platform/OpenThread/OpenThreadUtils.h>
#include <platform/ThreadStackManager.h>
Expand Down Expand Up @@ -281,36 +285,24 @@ bool GenericThreadStackManagerImpl_OpenThread<ImplClass>::_IsThreadAttached(void
template <class ImplClass>
ConnectivityManager::ThreadDeviceType GenericThreadStackManagerImpl_OpenThread<ImplClass>::_GetThreadDeviceType(void)
{
otLinkModeConfig linkMode;
ConnectivityManager::ThreadDeviceType deviceType;

Impl()->LockThreadStack();

linkMode = otThreadGetLinkMode(mOTInst);
const otLinkModeConfig linkMode = otThreadGetLinkMode(mOTInst);

#if CHIP_DEVICE_CONFIG_THREAD_FTD
if (linkMode.mDeviceType && otThreadIsRouterEligible(mOTInst))
ExitNow(deviceType = ConnectivityManager::kThreadDeviceType_Router);
if (linkMode.mDeviceType)
{
if (otThreadIsRouterEligible(mOTInst))
{
deviceType = ConnectivityManager::kThreadDeviceType_Router;
}
else
{
deviceType = ConnectivityManager::kThreadDeviceType_FullEndDevice;
}
}
else
{
if (linkMode.mRxOnWhenIdle)
{
deviceType = ConnectivityManager::kThreadDeviceType_MinimalEndDevice;
}
else
{
deviceType = ConnectivityManager::kThreadDeviceType_SleepyEndDevice;
}
}
ExitNow(deviceType = ConnectivityManager::kThreadDeviceType_FullEndDevice);
#endif
if (linkMode.mRxOnWhenIdle)
ExitNow(deviceType = ConnectivityManager::kThreadDeviceType_MinimalEndDevice);

ExitNow(deviceType = ConnectivityManager::kThreadDeviceType_SleepyEndDevice);

exit:
Impl()->UnlockThreadStack();

return deviceType;
Expand All @@ -323,11 +315,18 @@ GenericThreadStackManagerImpl_OpenThread<ImplClass>::_SetThreadDeviceType(Connec
CHIP_ERROR err = CHIP_NO_ERROR;
otLinkModeConfig linkMode;

VerifyOrExit(deviceType == ConnectivityManager::kThreadDeviceType_Router ||
deviceType == ConnectivityManager::kThreadDeviceType_FullEndDevice ||
deviceType == ConnectivityManager::kThreadDeviceType_MinimalEndDevice ||
deviceType == ConnectivityManager::kThreadDeviceType_SleepyEndDevice,
err = CHIP_ERROR_INVALID_ARGUMENT);
switch (deviceType)
{
#if CHIP_DEVICE_CONFIG_THREAD_FTD
case ConnectivityManager::kThreadDeviceType_Router:
case ConnectivityManager::kThreadDeviceType_FullEndDevice:
#endif
case ConnectivityManager::kThreadDeviceType_MinimalEndDevice:
case ConnectivityManager::kThreadDeviceType_SleepyEndDevice:
break;
default:
ExitNow(err = CHIP_ERROR_INVALID_ARGUMENT);
}

#if CHIP_PROGRESS_LOGGING

Expand Down Expand Up @@ -362,12 +361,14 @@ GenericThreadStackManagerImpl_OpenThread<ImplClass>::_SetThreadDeviceType(Connec

switch (deviceType)
{
#if CHIP_DEVICE_CONFIG_THREAD_FTD
case ConnectivityManager::kThreadDeviceType_Router:
case ConnectivityManager::kThreadDeviceType_FullEndDevice:
linkMode.mDeviceType = true;
linkMode.mRxOnWhenIdle = true;
otThreadSetRouterEligible(mOTInst, deviceType == ConnectivityManager::kThreadDeviceType_Router);
break;
#endif
case ConnectivityManager::kThreadDeviceType_MinimalEndDevice:
linkMode.mDeviceType = false;
linkMode.mRxOnWhenIdle = true;
Expand Down Expand Up @@ -607,8 +608,9 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::_GetAndLogThread
#define TELEM_NEIGHBOR_TABLE_SIZE (64)
#define TELEM_PRINT_BUFFER_SIZE (64)

#if CHIP_DEVICE_CONFIG_THREAD_FTD
template <class ImplClass>
CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::_GetAndLogThreadTopologyFull(void)
CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::_GetAndLogThreadTopologyFull()
{
CHIP_ERROR err = CHIP_NO_ERROR;
otError otErr;
Expand Down Expand Up @@ -762,6 +764,13 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::_GetAndLogThread
}
return err;
}
#else // CHIP_DEVICE_CONFIG_THREAD_FTD
template <class ImplClass>
CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::_GetAndLogThreadTopologyFull()
{
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
}
#endif

template <class ImplClass>
CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::_GetPrimary802154MACAddress(uint8_t * buf)
Expand Down
1 change: 1 addition & 0 deletions src/platform/nrfconnect/CHIPDevicePlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP 0

#define CHIP_DEVICE_CONFIG_ENABLE_THREAD CONFIG_NET_L2_OPENTHREAD
#define CHIP_DEVICE_CONFIG_THREAD_FTD CONFIG_OPENTHREAD_FTD

#define CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE CONFIG_BT

Expand Down

0 comments on commit 4593714

Please sign in to comment.