mirror of
https://github.com/espressif/openthread.git
synced 2026-08-14 06:37:46 +00:00
Add API to constrain the use of the Router/Leader role. (#285)
This commit is contained in:
@@ -478,6 +478,23 @@ otPanId otGetPanId(void);
|
||||
*/
|
||||
ThreadError otSetPanId(otPanId aPanId);
|
||||
|
||||
/**
|
||||
* This function indicates whether or not the Router Role is enabled.
|
||||
*
|
||||
* @retval TRUE If the Router Role is enabled.
|
||||
* @retval FALSE If the Router Role is not enabled.
|
||||
*
|
||||
*/
|
||||
bool otIsRouterRoleEnabled(void);
|
||||
|
||||
/**
|
||||
* This function sets whether or not the Router Role is enabled.
|
||||
*
|
||||
* @param[in] aEnabled TRUE if the Router Role is enabled, FALSE otherwise.
|
||||
*
|
||||
*/
|
||||
void otSetRouterRoleEnabled(bool aEnabled);
|
||||
|
||||
/**
|
||||
* Get the IEEE 802.15.4 Short Address.
|
||||
*
|
||||
|
||||
@@ -250,6 +250,16 @@ ThreadError otSetPanId(otPanId aPanId)
|
||||
return sThreadNetif->GetMac().SetPanId(aPanId);
|
||||
}
|
||||
|
||||
bool otIsRouterRoleEnabled(void)
|
||||
{
|
||||
return sThreadNetif->GetMle().IsRouterRoleEnabled();
|
||||
}
|
||||
|
||||
void otSetRouterRoleEnabled(bool aEnabled)
|
||||
{
|
||||
sThreadNetif->GetMle().SetRouterRoleEnabled(aEnabled);
|
||||
}
|
||||
|
||||
otShortAddress otGetShortAddress(void)
|
||||
{
|
||||
return sThreadNetif->GetMac().GetShortAddress();
|
||||
|
||||
@@ -68,10 +68,26 @@ MleRouter::MleRouter(ThreadNetif &aThreadNetif):
|
||||
mPreviousRouterId = kMaxRouterId;
|
||||
mAdvertiseInterval = kAdvertiseIntervalMin;
|
||||
mRouterIdSequenceLastUpdated = 0;
|
||||
mRouterRoleEnabled = true;
|
||||
|
||||
mCoapMessageId = otPlatRandomGet();
|
||||
}
|
||||
|
||||
bool MleRouter::IsRouterRoleEnabled(void) const
|
||||
{
|
||||
return mRouterRoleEnabled && (mDeviceMode & ModeTlv::kModeFFD);
|
||||
}
|
||||
|
||||
void MleRouter::SetRouterRoleEnabled(bool aEnabled)
|
||||
{
|
||||
mRouterRoleEnabled = aEnabled;
|
||||
|
||||
if (!mRouterRoleEnabled && (mDeviceState == kDeviceStateRouter || mDeviceState == kDeviceStateLeader))
|
||||
{
|
||||
BecomeDetached();
|
||||
}
|
||||
}
|
||||
|
||||
int MleRouter::AllocateRouterId(void)
|
||||
{
|
||||
int rval = -1;
|
||||
@@ -167,7 +183,7 @@ ThreadError MleRouter::BecomeRouter(void)
|
||||
|
||||
VerifyOrExit(mDeviceState == kDeviceStateDetached || mDeviceState == kDeviceStateChild,
|
||||
error = kThreadError_Busy);
|
||||
VerifyOrExit(mDeviceMode & ModeTlv::kModeFFD, ;);
|
||||
VerifyOrExit(mRouterRoleEnabled && (mDeviceMode & ModeTlv::kModeFFD), ;);
|
||||
|
||||
for (int i = 0; i < kMaxRouterId; i++)
|
||||
{
|
||||
|
||||
@@ -76,6 +76,26 @@ public:
|
||||
*/
|
||||
explicit MleRouter(ThreadNetif &aThreadNetif);
|
||||
|
||||
/**
|
||||
* This method indicates whether or not the Router Role is enabled.
|
||||
*
|
||||
* @retval true If the Router Role is enabled.
|
||||
* @retval false If the Router Role is not enabled.
|
||||
*
|
||||
*/
|
||||
bool IsRouterRoleEnabled(void) const;
|
||||
|
||||
/**
|
||||
* This method sets whether or not the Router Role is enabled.
|
||||
*
|
||||
* If @p aEnable is false and the device is currently operating as a router, this call will cause the device to
|
||||
* detach and attempt to reattach as a child.
|
||||
*
|
||||
* @param[in] aEnabled TRUE to enable the Router Role, FALSE otherwise.
|
||||
*
|
||||
*/
|
||||
void SetRouterRoleEnabled(bool aEnabled);
|
||||
|
||||
/**
|
||||
* This method generates an Address Solicit request for a Router ID.
|
||||
*
|
||||
@@ -436,6 +456,7 @@ private:
|
||||
uint8_t mNetworkIdTimeout;
|
||||
uint8_t mRouterUpgradeThreshold;
|
||||
uint8_t mLeaderWeight;
|
||||
bool mRouterRoleEnabled;
|
||||
|
||||
int8_t mRouterId;
|
||||
int8_t mPreviousRouterId;
|
||||
|
||||
Reference in New Issue
Block a user