diff --git a/src/cli/README.md b/src/cli/README.md index d608af4fb..a62303988 100644 --- a/src/cli/README.md +++ b/src/cli/README.md @@ -38,6 +38,7 @@ OpenThread test scripts use the CLI to execute test cases. * [rloc16](#rloc16) * [route](#route) * [router](#router) +* [routerrole](#routerrole) * [routerupgradethreshold](#routerupgradethreshold) * [scan](#scan) * [singleton](#singleton) @@ -702,6 +703,34 @@ Age: 7 Done ``` +### routerrole + +Indicates whether the router role is enabled or disabled. + +```bash +> routerrole +Enabled +Done +``` + +### routerrole enable + +Enable the router role. + +```bash +> routerrole enable +Done +``` + +### routerrole disable + +Disable the router role. + +```bash +> routerrole disable +Done +``` + ### routerupgradethreshold Get the ROUTER_UPGRADE_THRESHOLD value. diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index 5e1ade057..2f774c5a1 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -87,6 +87,7 @@ const struct Command Interpreter::sCommands[] = { "rloc16", &ProcessRloc16 }, { "route", &ProcessRoute }, { "router", &ProcessRouter }, + { "routerrole", &ProcessRouterRole }, { "routerupgradethreshold", &ProcessRouterUpgradeThreshold }, { "scan", &ProcessScan }, { "singleton", &ProcessSingleton }, @@ -1479,6 +1480,38 @@ exit: AppendResult(error); } +void Interpreter::ProcessRouterRole(int argc, char *argv[]) +{ + ThreadError error = kThreadError_None; + + if (argc == 0) + { + if (otIsRouterRoleEnabled()) + { + sServer->OutputFormat("Enabled\r\n"); + } + else + { + sServer->OutputFormat("Disabled\r\n"); + } + } + else if (strcmp(argv[0], "enable") == 0) + { + otSetRouterRoleEnabled(true); + } + else if (strcmp(argv[0], "disable") == 0) + { + otSetRouterRoleEnabled(false); + } + else + { + ExitNow(error = kThreadError_Parse); + } + +exit: + AppendResult(error); +} + void Interpreter::ProcessRouterUpgradeThreshold(int argc, char *argv[]) { ThreadError error = kThreadError_None; diff --git a/src/cli/cli.hpp b/src/cli/cli.hpp index 7a2f11757..c9a5daeb6 100644 --- a/src/cli/cli.hpp +++ b/src/cli/cli.hpp @@ -167,6 +167,7 @@ private: static void ProcessReset(int argc, char *argv[]); static void ProcessRoute(int argc, char *argv[]); static void ProcessRouter(int argc, char *argv[]); + static void ProcessRouterRole(int argc, char *argv[]); static ThreadError ProcessRouteAdd(int argc, char *argv[]); static ThreadError ProcessRouteRemove(int argc, char *argv[]); static void ProcessRouterUpgradeThreshold(int argc, char *argv[]); diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index 6719aae0f..b9ce121e0 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -1031,11 +1031,7 @@ void Mle::HandleParentRequestTimer(void) switch (mParentRequestMode) { case kMleAttachAnyPartition: - if (mDeviceMode & ModeTlv::kModeFFD) - { - mMleRouter.BecomeLeader(); - } - else + if (mMleRouter.BecomeLeader() != kThreadError_None) { mParentRequestState = kParentIdle; BecomeDetached(); diff --git a/src/core/thread/mle_router.cpp b/src/core/thread/mle_router.cpp index c0b28a4a4..157b71cd9 100644 --- a/src/core/thread/mle_router.cpp +++ b/src/core/thread/mle_router.cpp @@ -184,7 +184,7 @@ ThreadError MleRouter::BecomeRouter(ThreadStatusTlv::Status aStatus) VerifyOrExit(mDeviceState == kDeviceStateDetached || mDeviceState == kDeviceStateChild, error = kThreadError_Busy); - VerifyOrExit(mRouterRoleEnabled && (mDeviceMode & ModeTlv::kModeFFD), ;); + VerifyOrExit(mRouterRoleEnabled && (mDeviceMode & ModeTlv::kModeFFD), error = kThreadError_InvalidState); for (int i = 0; i < kMaxRouterId; i++) { @@ -225,6 +225,7 @@ ThreadError MleRouter::BecomeLeader(void) VerifyOrExit(mDeviceState != kDeviceStateDisabled && mDeviceState != kDeviceStateLeader, error = kThreadError_Busy); + VerifyOrExit(mRouterRoleEnabled && (mDeviceMode & ModeTlv::kModeFFD), error = kThreadError_InvalidState); for (int i = 0; i < kMaxRouterId; i++) { @@ -1466,7 +1467,7 @@ void MleRouter::UpdateRoutes(const RouteTlv &aRoute, uint8_t aRouterId) #if 1 - for (int i = 0; i < kMaxRouterId; i++) + for (uint8_t i = 0; i < kMaxRouterId; i++) { if (mRouters[i].mAllocated == false || mRouters[i].mNextHop == kMaxRouterId) {