aboutsummaryrefslogtreecommitdiff
path: root/src/ncp
diff options
context:
space:
mode:
authorSimon Lin <simonlin@google.com>2022-01-26 13:29:25 +0800
committerGitHub <noreply@github.com>2022-01-25 21:29:25 -0800
commit449b630cc4cdc313d3105cca1a88936dd817428e (patch)
treebbba0a629059b13700a84c696aafce262e32bb68 /src/ncp
parentecb4b8242a94d2feeea8dce3a812b0d51611158e (diff)
downloadot-br-posix-449b630cc4cdc313d3105cca1a88936dd817428e.tar.gz
[certification] disable auto Thread attaching for Reference Device (#1217)
This commit enhances `OTBR_NO_AUTO_ATTACH` option to disable auto Thread attaching for Reference Device: - Use `-DOTBR_NO_AUTO_ATTACH=1` to disable auto Thread attaching
Diffstat (limited to 'src/ncp')
-rw-r--r--src/ncp/ncp_openthread.cpp17
-rw-r--r--src/ncp/ncp_openthread.hpp4
2 files changed, 19 insertions, 2 deletions
diff --git a/src/ncp/ncp_openthread.cpp b/src/ncp/ncp_openthread.cpp
index 42882cc7..8d37e75e 100644
--- a/src/ncp/ncp_openthread.cpp
+++ b/src/ncp/ncp_openthread.cpp
@@ -197,12 +197,25 @@ void ControllerOpenThread::Process(const MainloopContext &aMainloop)
otSysMainloopProcess(mInstance, &aMainloop);
- if (getenv("OTBR_NO_AUTO_ATTACH") == nullptr && mThreadHelper->TryResumeNetwork() == OT_ERROR_NONE)
+ if (IsAutoAttachEnabled() && mThreadHelper->TryResumeNetwork() == OT_ERROR_NONE)
{
- setenv("OTBR_NO_AUTO_ATTACH", "1", 0);
+ DisableAutoAttach();
}
}
+bool ControllerOpenThread::IsAutoAttachEnabled(void)
+{
+ const char *val = getenv("OTBR_NO_AUTO_ATTACH");
+
+ // Auto Thread attaching is enabled if OTBR_NO_AUTO_ATTACH is unset, empty or "0"
+ return (val == nullptr || !strcmp(val, "") || !strcmp(val, "0"));
+}
+
+void ControllerOpenThread::DisableAutoAttach(void)
+{
+ setenv("OTBR_NO_AUTO_ATTACH", "1", 1);
+}
+
void ControllerOpenThread::PostTimerTask(Milliseconds aDelay, TaskRunner::Task<void> aTask)
{
mTaskRunner.Post(std::move(aDelay), std::move(aTask));
diff --git a/src/ncp/ncp_openthread.hpp b/src/ncp/ncp_openthread.hpp
index e8ce0c6e..b79e07ca 100644
--- a/src/ncp/ncp_openthread.hpp
+++ b/src/ncp/ncp_openthread.hpp
@@ -183,6 +183,10 @@ private:
void HandleBackboneRouterNdProxyEvent(otBackboneRouterNdProxyEvent aEvent, const otIp6Address *aAddress);
#endif
+ static bool IsAutoAttachEnabled(void);
+
+ static void DisableAutoAttach(void);
+
otInstance *mInstance;
otPlatformConfig mConfig;