diff --git a/examples/apps/cli/README.md b/examples/apps/cli/README.md index 86af4037f..284ec6f2c 100644 --- a/examples/apps/cli/README.md +++ b/examples/apps/cli/README.md @@ -23,6 +23,12 @@ $ cd /output//bin $ ./ot-cli 1 ``` +Set the PAN ID: + +```bash +> panid 0x1234 +``` + Bring up the IPv6 interface: ```bash @@ -65,6 +71,12 @@ $ cd /output//bin $ ./ot-cli 2 ``` +Set the PAN ID: + +```bash +> panid 0x1234 +``` + Bring up the IPv6 interface: ```bash diff --git a/src/core/openthread.cpp b/src/core/openthread.cpp index 06794a816..fa2bfbdcd 100644 --- a/src/core/openthread.cpp +++ b/src/core/openthread.cpp @@ -276,7 +276,17 @@ otPanId otGetPanId(void) ThreadError otSetPanId(otPanId aPanId) { - return sThreadNetif->GetMac().SetPanId(aPanId); + ThreadError error = kThreadError_None; + + // do not allow setting PAN ID to broadcast if Thread is running + VerifyOrExit(aPanId != Mac::kPanIdBroadcast || + sThreadNetif->GetMle().GetDeviceState() != Mle::kDeviceStateDisabled, + error = kThreadError_InvalidState); + + error = sThreadNetif->GetMac().SetPanId(aPanId); + +exit: + return error; } bool otIsRouterRoleEnabled(void) @@ -894,6 +904,7 @@ ThreadError otThreadStart(void) ThreadError error = kThreadError_None; VerifyOrExit(mEnabled, error = kThreadError_InvalidState); + VerifyOrExit(sThreadNetif->GetMac().GetPanId() != Mac::kPanIdBroadcast, error = kThreadError_InvalidState); error = sThreadNetif->GetMle().Start();