Separate out interface up/down from Thread start/stop. (#278)

* Redefine otEnable/otDisable to just initialize/uninitialize the OpenThread stack.
* Remove otInit API since it is replaced by otEnable.
* Add otInterfaceUp/otInterfaceDown APIs to bring up/down IPv6 interface.
* Add otThreadStart/otThreadStop APIs to start/stop Thread protocol operation.
* Updated NCP implementation to utilize new APIs.
This commit is contained in:
Jonathan Hui
2016-07-25 17:52:47 -07:00
committed by GitHub
parent c595b240fb
commit 8c39011d9c
12 changed files with 271 additions and 91 deletions
+42 -15
View File
@@ -59,6 +59,7 @@ const struct Command Interpreter::sCommands[] =
{ "eidcache", &ProcessEidCache },
{ "extaddr", &ProcessExtAddress },
{ "extpanid", &ProcessExtPanId },
{ "ifconfig", &ProcessIfconfig },
{ "ipaddr", &ProcessIpAddr },
{ "keysequence", &ProcessKeySequence },
{ "leaderdata", &ProcessLeaderData },
@@ -77,9 +78,8 @@ const struct Command Interpreter::sCommands[] =
{ "router", &ProcessRouter },
{ "routerupgradethreshold", &ProcessRouterUpgradeThreshold },
{ "scan", &ProcessScan },
{ "start", &ProcessStart },
{ "state", &ProcessState },
{ "stop", &ProcessStop },
{ "thread", &ProcessThread },
{ "version", &ProcessVersion },
{ "whitelist", &ProcessWhitelist },
};
@@ -408,6 +408,34 @@ exit:
AppendResult(error);
}
void Interpreter::ProcessIfconfig(int argc, char *argv[])
{
ThreadError error = kThreadError_Parse;
if (argc == 0)
{
if (otIsInterfaceUp())
{
sServer->OutputFormat("up\r\n");
}
else
{
sServer->OutputFormat("down\r\n");
}
}
else if (strcmp(argv[0], "up") == 0)
{
SuccessOrExit(error = otInterfaceUp());
}
else if (strcmp(argv[0], "down") == 0)
{
SuccessOrExit(error = otInterfaceDown());
}
exit:
AppendResult(error);
}
ThreadError Interpreter::ProcessIpAddrAdd(int argc, char *argv[])
{
ThreadError error;
@@ -1192,16 +1220,6 @@ exit:
return;
}
void Interpreter::ProcessStart(int argc, char *argv[])
{
ThreadError error = kThreadError_None;
SuccessOrExit(error = otEnable());
exit:
AppendResult(error);
}
void Interpreter::ProcessState(int argc, char *argv[])
{
ThreadError error = kThreadError_None;
@@ -1259,11 +1277,20 @@ exit:
AppendResult(error);
}
void Interpreter::ProcessStop(int argc, char *argv[])
void Interpreter::ProcessThread(int argc, char *argv[])
{
ThreadError error = kThreadError_None;
ThreadError error = kThreadError_Parse;
SuccessOrExit(error = otDisable());
VerifyOrExit(argc > 0, error = kThreadError_Parse);
if (strcmp(argv[0], "start") == 0)
{
SuccessOrExit(error = otThreadStart());
}
else if (strcmp(argv[0], "stop") == 0)
{
SuccessOrExit(error = otThreadStop());
}
exit:
AppendResult(error);