Add accessor methods to neighbor/child/router objects. (#1577)

This commit is contained in:
Jonathan Hui
2017-04-11 13:25:11 -07:00
committed by GitHub
parent 92106b87c8
commit a5c3fb6aaf
12 changed files with 1176 additions and 606 deletions
+12 -12
View File
@@ -479,17 +479,17 @@ ThreadError otThreadGetParentInfo(otInstance *aInstance, otRouterInfo *aParentIn
VerifyOrExit(aParentInfo != NULL, error = kThreadError_InvalidArgs);
parent = aInstance->mThreadNetif.GetMle().GetParent();
memcpy(aParentInfo->mExtAddress.m8, parent->mMacAddr.m8, OT_EXT_ADDRESS_SIZE);
memcpy(aParentInfo->mExtAddress.m8, &parent->GetExtAddress(), sizeof(aParentInfo->mExtAddress));
aParentInfo->mRloc16 = parent->mValid.mRloc16;
aParentInfo->mRouterId = Mle::Mle::GetRouterId(parent->mValid.mRloc16);
aParentInfo->mNextHop = parent->mNextHop;
aParentInfo->mPathCost = parent->mCost;
aParentInfo->mLinkQualityIn = parent->mLinkInfo.GetLinkQuality(aInstance->mThreadNetif.GetMac().GetNoiseFloor());
aParentInfo->mLinkQualityOut = parent->mLinkQualityOut;
aParentInfo->mAge = static_cast<uint8_t>(Timer::MsecToSec(Timer::GetNow() - parent->mLastHeard));
aParentInfo->mAllocated = parent->mAllocated;
aParentInfo->mLinkEstablished = parent->mState == Neighbor::kStateValid;
aParentInfo->mRloc16 = parent->GetRloc16();
aParentInfo->mRouterId = Mle::Mle::GetRouterId(parent->GetRloc16());
aParentInfo->mNextHop = parent->GetNextHop();
aParentInfo->mPathCost = parent->GetCost();
aParentInfo->mLinkQualityIn = parent->GetLinkInfo().GetLinkQuality(aInstance->mThreadNetif.GetMac().GetNoiseFloor());
aParentInfo->mLinkQualityOut = parent->GetLinkQualityOut();
aParentInfo->mAge = static_cast<uint8_t>(Timer::MsecToSec(Timer::GetNow() - parent->GetLastHeard()));
aParentInfo->mAllocated = parent->IsAllocated();
aParentInfo->mLinkEstablished = parent->GetState() == Neighbor::kStateValid;
exit:
return error;
@@ -503,7 +503,7 @@ ThreadError otThreadGetParentAverageRssi(otInstance *aInstance, int8_t *aParentR
VerifyOrExit(aParentRssi != NULL, error = kThreadError_InvalidArgs);
parent = aInstance->mThreadNetif.GetMle().GetParent();
*aParentRssi = parent->mLinkInfo.GetAverageRss();
*aParentRssi = parent->GetLinkInfo().GetAverageRss();
VerifyOrExit(*aParentRssi != LinkQualityInfo::kUnknownRss, error = kThreadError_Failed);
@@ -519,7 +519,7 @@ ThreadError otThreadGetParentLastRssi(otInstance *aInstance, int8_t *aLastRssi)
VerifyOrExit(aLastRssi != NULL, error = kThreadError_InvalidArgs);
parent = aInstance->mThreadNetif.GetMle().GetParent();
*aLastRssi = parent->mLinkInfo.GetLastRss();
*aLastRssi = parent->GetLinkInfo().GetLastRss();
VerifyOrExit(*aLastRssi != LinkQualityInfo::kUnknownRss, error = kThreadError_Failed);
+13 -13
View File
@@ -1182,19 +1182,19 @@ ThreadError Mac::ProcessReceiveSecurity(Frame &aFrame, const Address &aSrcAddr,
// the tag/MIC. Such a frame is later filtered in `RxDoneTask` which only allows MAC
// Data Request frames from a child being restored.
if (aNeighbor->mState == Neighbor::kStateValid)
if (aNeighbor->GetState() == Neighbor::kStateValid)
{
if (keySequence < aNeighbor->mKeySequence)
if (keySequence < aNeighbor->GetKeySequence())
{
ExitNow(error = kThreadError_Security);
}
else if (keySequence == aNeighbor->mKeySequence)
else if (keySequence == aNeighbor->GetKeySequence())
{
if ((frameCounter + 1) < aNeighbor->mValid.mLinkFrameCounter)
if ((frameCounter + 1) < aNeighbor->GetLinkFrameCounter())
{
ExitNow(error = kThreadError_Security);
}
else if ((frameCounter + 1) == aNeighbor->mValid.mLinkFrameCounter)
else if ((frameCounter + 1) == aNeighbor->GetLinkFrameCounter())
{
// drop duplicated packets
ExitNow(error = kThreadError_Duplicated);
@@ -1227,15 +1227,15 @@ ThreadError Mac::ProcessReceiveSecurity(Frame &aFrame, const Address &aSrcAddr,
VerifyOrExit(memcmp(tag, aFrame.GetFooter(), tagLength) == 0, error = kThreadError_Security);
if ((keyIdMode == Frame::kKeyIdMode1) && (aNeighbor->mState == Neighbor::kStateValid))
if ((keyIdMode == Frame::kKeyIdMode1) && (aNeighbor->GetState() == Neighbor::kStateValid))
{
if (aNeighbor->mKeySequence != keySequence)
if (aNeighbor->GetKeySequence() != keySequence)
{
aNeighbor->mKeySequence = keySequence;
aNeighbor->mValid.mMleFrameCounter = 0;
aNeighbor->SetKeySequence(keySequence);
aNeighbor->SetMleFrameCounter(0);
}
aNeighbor->mValid.mLinkFrameCounter = frameCounter + 1;
aNeighbor->SetLinkFrameCounter(frameCounter + 1);
if (keySequence > mNetif.GetKeyManager().GetCurrentKeySequence())
{
@@ -1316,7 +1316,7 @@ void Mac::ReceiveDoneTask(Frame *aFrame, ThreadError aError)
}
srcaddr.mLength = sizeof(srcaddr.mExtAddress);
memcpy(&srcaddr.mExtAddress, &neighbor->mMacAddr, sizeof(srcaddr.mExtAddress));
srcaddr.mExtAddress = neighbor->GetExtAddress();
break;
case sizeof(ExtAddress):
@@ -1390,11 +1390,11 @@ void Mac::ReceiveDoneTask(Frame *aFrame, ThreadError aError)
if (neighbor != NULL)
{
neighbor->mLinkInfo.AddRss(mNoiseFloor, aFrame->mPower);
neighbor->GetLinkInfo().AddRss(mNoiseFloor, aFrame->mPower);
if (aFrame->GetSecurityEnabled() == true)
{
switch (neighbor->mState)
switch (neighbor->GetState())
{
case Neighbor::kStateValid:
break;
+13 -15
View File
@@ -462,22 +462,22 @@ void AddressResolver::HandleAddressError(Coap::Header &aHeader, Message &aMessag
for (int i = 0; i < numChildren; i++)
{
if (children[i].mState != Neighbor::kStateValid || (children[i].mMode & Mle::ModeTlv::kModeFFD) != 0)
if (children[i].GetState() != Neighbor::kStateValid || children[i].IsFullThreadDevice())
{
continue;
}
for (int j = 0; j < Child::kMaxIp6AddressPerChild; j++)
for (uint8_t j = 0; j < Child::kMaxIp6AddressPerChild; j++)
{
if (memcmp(&children[i].mIp6Address[j], targetTlv.GetTarget(), sizeof(children[i].mIp6Address[j])) == 0 &&
memcmp(&children[i].mMacAddr, &macAddr, sizeof(children[i].mMacAddr)))
if (children[i].GetIp6Address(j) == *targetTlv.GetTarget() &&
memcmp(&children[i].GetExtAddress(), &macAddr, sizeof(macAddr)))
{
// Target EID matches child address and Mesh Local EID differs on child
memset(&children[i].mIp6Address[j], 0, sizeof(children[i].mIp6Address[j]));
memset(&children[i].GetIp6Address(j), 0, sizeof(children[i].GetIp6Address(j)));
memset(&destination, 0, sizeof(destination));
destination.mFields.m16[0] = HostSwap16(0xfe80);
destination.SetIid(children[i].mMacAddr);
destination.SetIid(children[i].GetExtAddress());
SendAddressError(targetTlv, mlIidTlv, &destination);
ExitNow();
@@ -529,24 +529,22 @@ void AddressResolver::HandleAddressQuery(Coap::Header &aHeader, Message &aMessag
for (int i = 0; i < numChildren; i++)
{
if (children[i].mState != Neighbor::kStateValid ||
(children[i].mMode & Mle::ModeTlv::kModeFFD) != 0 ||
children[i].mLinkFailures >= Mle::kFailedChildTransmissions)
if (children[i].GetState() != Neighbor::kStateValid ||
children[i].IsFullThreadDevice() ||
children[i].GetLinkFailures() >= Mle::kFailedChildTransmissions)
{
continue;
}
for (int j = 0; j < Child::kMaxIp6AddressPerChild; j++)
for (uint8_t j = 0; j < Child::kMaxIp6AddressPerChild; j++)
{
if (memcmp(&children[i].mIp6Address[j], targetTlv.GetTarget(), sizeof(children[i].mIp6Address[j])))
if (children[i].GetIp6Address(j) != *targetTlv.GetTarget())
{
continue;
}
children[i].mMacAddr.m8[0] ^= 0x2;
mlIidTlv.SetIid(children[i].mMacAddr.m8);
children[i].mMacAddr.m8[0] ^= 0x2;
lastTransactionTimeTlv.SetTime(Timer::GetNow() - children[i].mLastHeard);
mlIidTlv.SetIid(children[i].GetExtAddress());
lastTransactionTimeTlv.SetTime(Timer::GetNow() - children[i].GetLastHeard());
SendAddressQueryResponse(targetTlv, mlIidTlv, &lastTransactionTimeTlv, aMessageInfo.GetPeerAddr());
ExitNow();
}
+9 -9
View File
@@ -100,18 +100,18 @@ ThreadError KeyManager::SetMasterKey(const void *aKey, uint8_t aKeyLength)
// reset parent frame counters
routers = mNetif.GetMle().GetParent();
routers->mKeySequence = 0;
routers->mValid.mLinkFrameCounter = 0;
routers->mValid.mMleFrameCounter = 0;
routers->SetKeySequence(0);
routers->SetLinkFrameCounter(0);
routers->SetMleFrameCounter(0);
// reset router frame counters
routers = mNetif.GetMle().GetRouters(&num);
for (uint8_t i = 0; i < num; i++)
{
routers[i].mKeySequence = 0;
routers[i].mValid.mLinkFrameCounter = 0;
routers[i].mValid.mMleFrameCounter = 0;
routers[i].SetKeySequence(0);
routers[i].SetLinkFrameCounter(0);
routers[i].SetMleFrameCounter(0);
}
// reset child frame counters
@@ -119,9 +119,9 @@ ThreadError KeyManager::SetMasterKey(const void *aKey, uint8_t aKeyLength)
for (uint8_t i = 0; i < num; i++)
{
children[i].mKeySequence = 0;
children[i].mValid.mLinkFrameCounter = 0;
children[i].mValid.mMleFrameCounter = 0;
children[i].SetKeySequence(0);
children[i].SetLinkFrameCounter(0);
children[i].SetMleFrameCounter(0);
}
mNetif.SetStateChangedFlags(OT_NET_KEY_SEQUENCE_COUNTER);
+57 -51
View File
@@ -185,7 +185,7 @@ void MeshForwarder::ClearChildIndirectMessages(Child &aChild)
{
Message *nextMessage;
VerifyOrExit(aChild.GetQueuedMessageCount() > 0);
VerifyOrExit(aChild.GetIndirectMessageCount() > 0);
for (Message *message = mSendQueue.GetHead(); message; message = nextMessage)
{
@@ -222,7 +222,7 @@ void MeshForwarder::UpdateIndirectMessages(void)
{
Child *child = &children[i];
if (child->IsStateValidOrRestoring() || (child->GetQueuedMessageCount() == 0))
if (child->IsStateValidOrRestoring() || (child->GetIndirectMessageCount() == 0))
{
continue;
}
@@ -254,12 +254,12 @@ void MeshForwarder::ScheduleTransmissionTask(void)
{
Child &child = children[i];
if (!child.IsStateValidOrRestoring() || !child.mDataRequest)
if (!child.IsStateValidOrRestoring() || !child.IsDataRequestPending())
{
continue;
}
mSendMessage = child.mIndirectSendInfo.mMessage;
mSendMessage = child.GetIndirectMessage();
mSendMessageMaxMacTxAttempts = Mac::kIndirectFrameMacTxAttempts;
if (mSendMessage == NULL)
@@ -275,13 +275,13 @@ void MeshForwarder::ScheduleTransmissionTask(void)
{
// A NULL `mSendMessage` triggers an empty frame to be sent to the child.
if (child.ShouldUseShortAddress())
if (child.IsIndirectSourceMatchShort())
{
mMacSource.mLength = sizeof(mMacSource.mShortAddress);
mMacSource.mShortAddress = mNetif.GetMac().GetShortAddress();
mMacDest.mLength = sizeof(mMacDest.mShortAddress);
mMacDest.mShortAddress = child.mValid.mRloc16;
mMacDest.mShortAddress = child.GetRloc16();
}
else
{
@@ -289,7 +289,7 @@ void MeshForwarder::ScheduleTransmissionTask(void)
memcpy(mMacSource.mExtAddress.m8, mNetif.GetMac().GetExtAddress(), sizeof(mMacDest.mExtAddress));
mMacDest.mLength = sizeof(mMacDest.mExtAddress);
memcpy(mMacDest.mExtAddress.m8, child.mMacAddr.m8, sizeof(mMacDest.mExtAddress));
mMacDest.mExtAddress = child.GetExtAddress();
}
}
@@ -339,8 +339,7 @@ ThreadError MeshForwarder::SendMessage(Message &aMessage)
for (uint8_t i = 0; i < numChildren; i++, child++)
{
if (child->IsStateValidOrRestoring() &&
(child->mMode & Mle::ModeTlv::kModeRxOnWhenIdle) == 0)
if (child->IsStateValidOrRestoring() && !child->IsRxOnWhenIdle())
{
aMessage.SetChildMask(i);
mSourceMatchController.IncrementMessageCount(*child);
@@ -349,7 +348,7 @@ ThreadError MeshForwarder::SendMessage(Message &aMessage)
}
}
else if ((neighbor = mNetif.GetMle().GetNeighbor(ip6Header.GetDestination())) != NULL &&
(neighbor->mMode & Mle::ModeTlv::kModeRxOnWhenIdle) == 0 &&
!neighbor->IsRxOnWhenIdle() &&
!aMessage.GetDirectTransmission())
{
// destined for a sleepy child
@@ -373,7 +372,7 @@ ThreadError MeshForwarder::SendMessage(Message &aMessage)
IgnoreReturnValue(meshHeader.Init(aMessage));
if ((neighbor = mNetif.GetMle().GetNeighbor(meshHeader.GetDestination())) != NULL &&
(neighbor->mMode & Mle::ModeTlv::kModeRxOnWhenIdle) == 0)
!neighbor->IsRxOnWhenIdle())
{
// destined for a sleepy child
child = static_cast<Child *>(neighbor);
@@ -470,24 +469,24 @@ Message *MeshForwarder::GetIndirectTransmission(Child &aChild)
}
}
aChild.mIndirectSendInfo.mMessage = message;
aChild.mIndirectSendInfo.mFragmentOffset = 0;
aChild.mIndirectSendInfo.mTxAttemptCounter = 0;
aChild.SetIndirectMessage(message);
aChild.SetIndirectFragmentOffset(0);
aChild.ResetIndirectTxAttempts();
return message;
}
void MeshForwarder::PrepareIndirectTransmission(Message &aMessage, const Child &aChild)
{
if (aChild.mIndirectSendInfo.mTxAttemptCounter > 0)
if (aChild.GetIndirectTxAttempts() > 0)
{
mSendMessageIsARetransmission = true;
mSendMessageFrameCounter = aChild.mIndirectSendInfo.mFrameCounter;
mSendMessageKeyId = aChild.mIndirectSendInfo.mKeyId;
mSendMessageDataSequenceNumber = aChild.mIndirectSendInfo.mDataSequenceNumber;
mSendMessageFrameCounter = aChild.GetIndirectFrameCounter();
mSendMessageKeyId = aChild.GetIndirectKeyId();
mSendMessageDataSequenceNumber = aChild.GetIndirectDataSequenceNumber();
}
aMessage.SetOffset(aChild.mIndirectSendInfo.mFragmentOffset);
aMessage.SetOffset(aChild.GetIndirectFragmentOffset());
switch (aMessage.GetType())
{
@@ -506,15 +505,15 @@ void MeshForwarder::PrepareIndirectTransmission(Message &aMessage, const Child &
}
else
{
if (aChild.ShouldUseShortAddress())
if (aChild.IsIndirectSourceMatchShort())
{
mMacDest.mLength = sizeof(mMacDest.mShortAddress);
mMacDest.mShortAddress = aChild.mValid.mRloc16;
mMacDest.mShortAddress = aChild.GetRloc16();
}
else
{
mMacDest.mLength = sizeof(mMacDest.mExtAddress);
memcpy(mMacDest.mExtAddress.m8, aChild.mMacAddr.m8, sizeof(mMacDest.mExtAddress));
mMacDest.mExtAddress = aChild.GetExtAddress();
}
}
@@ -568,7 +567,7 @@ ThreadError MeshForwarder::UpdateMeshRoute(Message &aMessage)
}
mMacDest.mLength = sizeof(mMacDest.mShortAddress);
mMacDest.mShortAddress = neighbor->mValid.mRloc16;
mMacDest.mShortAddress = neighbor->GetRloc16();
mMacSource.mLength = sizeof(mMacSource.mShortAddress);
mMacSource.mShortAddress = mNetif.GetMac().GetShortAddress();
@@ -696,7 +695,7 @@ ThreadError MeshForwarder::UpdateIp6Route(Message &aMessage)
}
else if ((neighbor = mNetif.GetMle().GetNeighbor(ip6Header.GetDestination())) != NULL)
{
mMeshDest = neighbor->mValid.mRloc16;
mMeshDest = neighbor->GetRloc16();
}
else if (mNetif.GetNetworkDataLeader().IsOnMesh(ip6Header.GetDestination()))
{
@@ -911,8 +910,8 @@ ThreadError MeshForwarder::HandleFrameRequest(Mac::Frame &aFrame)
// already checked and handled in `SendFragment()` method.
if (((child = mNetif.GetMle().GetChild(macDest)) != NULL)
&& ((child->mMode & Mle::ModeTlv::kModeRxOnWhenIdle) == 0)
&& (child->GetQueuedMessageCount() > 1))
&& !child->IsRxOnWhenIdle()
&& (child->GetIndirectMessageCount() > 1))
{
aFrame.SetFramePending(true);
}
@@ -979,12 +978,12 @@ ThreadError MeshForwarder::SendPoll(Message &aMessage, Mac::Frame &aFrame)
if (macSource.mLength == 2)
{
aFrame.SetDstAddr(neighbor->mValid.mRloc16);
aFrame.SetDstAddr(neighbor->GetRloc16());
aFrame.SetSrcAddr(macSource.mShortAddress);
}
else
{
aFrame.SetDstAddr(neighbor->mMacAddr);
aFrame.SetDstAddr(neighbor->GetExtAddress());
aFrame.SetSrcAddr(macSource.mExtAddress);
}
@@ -1353,7 +1352,7 @@ void MeshForwarder::HandleSentFrame(Mac::Frame &aFrame, ThreadError aError)
case kThreadError_None:
if (aFrame.GetAckRequest())
{
neighbor->mLinkFailures = 0;
neighbor->ResetLinkFailures();
}
break;
@@ -1363,11 +1362,11 @@ void MeshForwarder::HandleSentFrame(Mac::Frame &aFrame, ThreadError aError)
break;
case kThreadError_NoAck:
neighbor->mLinkFailures++;
neighbor->IncrementLinkFailures();
if (mNetif.GetMle().IsActiveRouter(neighbor->mValid.mRloc16))
if (mNetif.GetMle().IsActiveRouter(neighbor->GetRloc16()))
{
if (neighbor->mLinkFailures >= Mle::kFailedRouterTransmissions)
if (neighbor->GetLinkFailures() >= Mle::kFailedRouterTransmissions)
{
mNetif.GetMle().RemoveNeighbor(*neighbor);
}
@@ -1383,22 +1382,22 @@ void MeshForwarder::HandleSentFrame(Mac::Frame &aFrame, ThreadError aError)
if ((child = mNetif.GetMle().GetChild(macDest)) != NULL)
{
child->mDataRequest = false;
child->SetDataRequestPending(false);
VerifyOrExit(mSendMessage != NULL);
if (mSendMessage == child->mIndirectSendInfo.mMessage)
if (mSendMessage == child->GetIndirectMessage())
{
switch (aError)
{
case kThreadError_None:
child->mIndirectSendInfo.mTxAttemptCounter = 0;
child->ResetIndirectTxAttempts();
break;
default:
child->mIndirectSendInfo.mTxAttemptCounter++;
child->IncrementIndirectTxAttempts();
if (child->mIndirectSendInfo.mTxAttemptCounter < kMaxPollTriggeredTxAttempts)
if (child->GetIndirectTxAttempts() < kMaxPollTriggeredTxAttempts)
{
// We save the frame counter, key id, and data sequence number of
// current frame so we use the same values for the retransmission
@@ -1407,15 +1406,22 @@ void MeshForwarder::HandleSentFrame(Mac::Frame &aFrame, ThreadError aError)
if (aFrame.GetSecurityEnabled())
{
aFrame.GetFrameCounter(child->mIndirectSendInfo.mFrameCounter);
aFrame.GetKeyId(child->mIndirectSendInfo.mKeyId);
child->mIndirectSendInfo.mDataSequenceNumber = aFrame.GetSequence();
uint32_t frameCounter;
uint8_t keyId;
aFrame.GetFrameCounter(frameCounter);
child->SetIndirectFrameCounter(frameCounter);
aFrame.GetKeyId(keyId);
child->SetIndirectKeyId(keyId);
child->SetIndirectDataSequenceNumber(aFrame.GetSequence());
}
ExitNow();
}
child->mIndirectSendInfo.mTxAttemptCounter = 0;
child->ResetIndirectTxAttempts();
// We set the NextOffset to end of message, since there is no need to
// send any remaining fragments in the message to the child, if all tx
@@ -1429,17 +1435,17 @@ void MeshForwarder::HandleSentFrame(Mac::Frame &aFrame, ThreadError aError)
if (mMessageNextOffset < mSendMessage->GetLength())
{
if (mSendMessage == child->mIndirectSendInfo.mMessage)
if (mSendMessage == child->GetIndirectMessage())
{
child->mIndirectSendInfo.mFragmentOffset = mMessageNextOffset;
child->SetIndirectFragmentOffset(mMessageNextOffset);
}
}
else
{
if (mSendMessage == child->mIndirectSendInfo.mMessage)
if (mSendMessage == child->GetIndirectMessage())
{
child->mIndirectSendInfo.mFragmentOffset = 0;
child->mIndirectSendInfo.mMessage = NULL;
child->SetIndirectFragmentOffset(0);
child->SetIndirectMessage(NULL);
// add short address for subsequent indirect messages after
// one indirect message to valid sleepy devices is sent out successfully
@@ -1485,7 +1491,7 @@ void MeshForwarder::HandleSentFrame(Mac::Frame &aFrame, ThreadError aError)
{
neighbor = mNetif.GetMle().GetParent();
if (neighbor->mState == Neighbor::kStateInvalid)
if (neighbor->GetState() == Neighbor::kStateInvalid)
{
mDataPollManager.StopPolling();
mNetif.GetMle().BecomeDetached();
@@ -1957,12 +1963,12 @@ void MeshForwarder::HandleDataRequest(const Mac::Address &aMacSource, const Thre
VerifyOrExit(mNetif.GetMle().GetDeviceState() != Mle::kDeviceStateDetached);
VerifyOrExit((child = mNetif.GetMle().GetChild(aMacSource)) != NULL);
child->mLastHeard = Timer::GetNow();
child->mLinkFailures = 0;
child->SetLastHeard(Timer::GetNow());
child->ResetLinkFailures();
if (!mSourceMatchController.IsEnabled() || (child->GetQueuedMessageCount() > 0))
if (!mSourceMatchController.IsEnabled() || (child->GetIndirectMessageCount() > 0))
{
child->mDataRequest = true;
child->SetDataRequestPending(true);
}
mScheduleTransmissionTask.Post();
+48 -48
View File
@@ -501,7 +501,7 @@ ThreadError Mle::BecomeChild(otMleAttachFilter aFilter)
if (aFilter == kMleAttachAnyPartition)
{
mParent.mState = Neighbor::kStateInvalid;
mParent.SetState(Neighbor::kStateInvalid);
mLastPartitionId = mNetif.GetMle().GetPreviousPartitionId();
mLastPartitionRouterIdSequence = mNetif.GetMle().GetRouterIdSequence();
}
@@ -1267,7 +1267,7 @@ void Mle::HandleParentRequestTimer(void)
switch (mParentRequestState)
{
case kParentIdle:
if (mParent.mState == Neighbor::kStateValid)
if (mParent.GetState() == Neighbor::kStateValid)
{
SendChildUpdateRequest();
}
@@ -1285,14 +1285,14 @@ void Mle::HandleParentRequestTimer(void)
case kParentRequestStart:
mParentRequestState = kParentRequestRouter;
mParentCandidate.mState = Neighbor::kStateInvalid;
mParentCandidate.SetState(Neighbor::kStateInvalid);
SendParentRequest();
break;
case kParentRequestRouter:
mParentRequestState = kParentRequestChild;
if (mParentCandidate.mState == Neighbor::kStateValid)
if (mParentCandidate.GetState() == Neighbor::kStateValid)
{
SendChildIdRequest();
mParentRequestState = kChildIdRequest;
@@ -1308,7 +1308,7 @@ void Mle::HandleParentRequestTimer(void)
case kParentRequestChild:
mParentRequestState = kParentRequestChild;
if (mParentCandidate.mState == Neighbor::kStateValid)
if (mParentCandidate.GetState() == Neighbor::kStateValid)
{
SendChildIdRequest();
mParentRequestState = kChildIdRequest;
@@ -1566,7 +1566,7 @@ ThreadError Mle::SendChildIdRequest(void)
memset(&destination, 0, sizeof(destination));
destination.mFields.m16[0] = HostSwap16(0xfe80);
destination.SetIid(mParentCandidate.mMacAddr);
destination.SetIid(mParentCandidate.GetExtAddress());
SuccessOrExit(error = SendMessage(*message, destination));
otLogInfoMle(GetInstance(), "Sent Child ID Request");
@@ -1695,7 +1695,7 @@ ThreadError Mle::SendChildUpdateRequest(void)
memset(&destination, 0, sizeof(destination));
destination.mFields.m16[0] = HostSwap16(0xfe80);
destination.SetIid(mParent.mMacAddr);
destination.SetIid(mParent.GetExtAddress());
SuccessOrExit(error = SendMessage(*message, destination));
otLogInfoMle(GetInstance(), "Sent Child Update Request to parent");
@@ -1763,7 +1763,7 @@ ThreadError Mle::SendChildUpdateResponse(const uint8_t *aTlvs, uint8_t aNumTlvs,
memset(&destination, 0, sizeof(destination));
destination.mFields.m16[0] = HostSwap16(0xfe80);
destination.SetIid(mParent.mMacAddr);
destination.SetIid(mParent.GetExtAddress());
SuccessOrExit(error = SendMessage(*message, destination));
otLogInfoMle(GetInstance(), "Sent Child Update Response to parent");
@@ -2101,11 +2101,11 @@ void Mle::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessageIn
break;
}
if (neighbor != NULL && neighbor->mState == Neighbor::kStateValid)
if (neighbor != NULL && neighbor->GetState() == Neighbor::kStateValid)
{
if (keySequence == neighbor->mKeySequence)
if (keySequence == neighbor->GetKeySequence())
{
if (frameCounter < neighbor->mValid.mMleFrameCounter)
if (frameCounter < neighbor->GetMleFrameCounter())
{
otLogDebgMle(GetInstance(), "mle frame reject 1");
ExitNow();
@@ -2113,17 +2113,17 @@ void Mle::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessageIn
}
else
{
if (keySequence <= neighbor->mKeySequence)
if (keySequence <= neighbor->GetKeySequence())
{
otLogDebgMle(GetInstance(), "mle frame reject 2");
ExitNow();
}
neighbor->mKeySequence = keySequence;
neighbor->mValid.mLinkFrameCounter = 0;
neighbor->SetKeySequence(keySequence);
neighbor->SetLinkFrameCounter(0);
}
neighbor->mValid.mMleFrameCounter = frameCounter + 1;
neighbor->SetMleFrameCounter(frameCounter + 1);
}
else
{
@@ -2256,12 +2256,12 @@ ThreadError Mle::HandleAdvertisement(const Message &aMessage, const Ip6::Message
break;
case kDeviceStateChild:
if (memcmp(&mParent.mMacAddr, &macAddr, sizeof(mParent.mMacAddr)))
if (memcmp(&mParent.GetExtAddress(), &macAddr, sizeof(macAddr)))
{
break;
}
if ((mParent.mValid.mRloc16 == sourceAddress.GetRloc16()) &&
if ((mParent.GetRloc16() == sourceAddress.GetRloc16()) &&
(leaderData.GetPartitionId() != mLeaderData.GetPartitionId() ||
leaderData.GetLeaderRouterId() != GetLeaderId()))
{
@@ -2279,13 +2279,13 @@ ThreadError Mle::HandleAdvertisement(const Message &aMessage, const Ip6::Message
}
isNeighbor = true;
mParent.mLastHeard = mParentRequestTimer.GetNow();
mParent.SetLastHeard(Timer::GetNow());
break;
case kDeviceStateRouter:
case kDeviceStateLeader:
if ((neighbor = mNetif.GetMle().GetNeighbor(macAddr)) != NULL &&
neighbor->mState == Neighbor::kStateValid)
neighbor->GetState() == Neighbor::kStateValid)
{
isNeighbor = true;
}
@@ -2480,16 +2480,16 @@ bool Mle::IsBetterParent(uint16_t aRloc16, uint8_t aLinkQuality, ConnectivityTlv
{
bool rval = false;
uint8_t candidateLinkQualityIn = mParentCandidate.mLinkInfo.GetLinkQuality(mNetif.GetMac().GetNoiseFloor());
uint8_t candidateTwoWayLinkQuality = (candidateLinkQualityIn < mParentCandidate.mLinkQualityOut)
? candidateLinkQualityIn : mParentCandidate.mLinkQualityOut;
uint8_t candidateLinkQualityIn = mParentCandidate.GetLinkInfo().GetLinkQuality(mNetif.GetMac().GetNoiseFloor());
uint8_t candidateTwoWayLinkQuality = (candidateLinkQualityIn < mParentCandidate.GetLinkQualityOut())
? candidateLinkQualityIn : mParentCandidate.GetLinkQualityOut();
if (aLinkQuality != candidateTwoWayLinkQuality)
{
ExitNow(rval = (aLinkQuality > candidateTwoWayLinkQuality));
}
if (IsActiveRouter(aRloc16) != IsActiveRouter(mParentCandidate.mValid.mRloc16))
if (IsActiveRouter(aRloc16) != IsActiveRouter(mParentCandidate.GetRloc16()))
{
ExitNow(rval = IsActiveRouter(aRloc16));
}
@@ -2521,7 +2521,7 @@ exit:
void Mle::ResetParentCandidate(void)
{
memset(&mParentCandidate, 0, sizeof(mParentCandidate));
mParentCandidate.mState = Neighbor::kStateInvalid;
mParentCandidate.SetState(Neighbor::kStateInvalid);
}
ThreadError Mle::HandleParentResponse(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo,
@@ -2602,7 +2602,7 @@ ThreadError Mle::HandleParentResponse(const Message &aMessage, const Ip6::Messag
}
// if already have a candidate parent, only seek a better parent
if (mParentCandidate.mState == Neighbor::kStateValid)
if (mParentCandidate.GetState() == Neighbor::kStateValid)
{
int compare = 0;
@@ -2639,17 +2639,17 @@ ThreadError Mle::HandleParentResponse(const Message &aMessage, const Ip6::Messag
memcpy(mChildIdRequest.mChallenge, challenge.GetChallenge(), challenge.GetLength());
mChildIdRequest.mChallengeLength = challenge.GetLength();
mParentCandidate.mMacAddr.Set(aMessageInfo.GetPeerAddr());
mParentCandidate.mValid.mRloc16 = sourceAddress.GetRloc16();
mParentCandidate.mValid.mLinkFrameCounter = linkFrameCounter.GetFrameCounter();
mParentCandidate.mValid.mMleFrameCounter = mleFrameCounter.GetFrameCounter();
mParentCandidate.mMode = ModeTlv::kModeFFD | ModeTlv::kModeRxOnWhenIdle | ModeTlv::kModeFullNetworkData;
mParentCandidate.mLinkInfo.Clear();
mParentCandidate.mLinkInfo.AddRss(mNetif.GetMac().GetNoiseFloor(), threadMessageInfo->mRss);
mParentCandidate.mLinkFailures = 0;
mParentCandidate.mLinkQualityOut = LinkQualityInfo::ConvertLinkMarginToLinkQuality(linkMarginTlv.GetLinkMargin());
mParentCandidate.mState = Neighbor::kStateValid;
mParentCandidate.mKeySequence = aKeySequence;
mParentCandidate.GetExtAddress().Set(aMessageInfo.GetPeerAddr());
mParentCandidate.SetRloc16(sourceAddress.GetRloc16());
mParentCandidate.SetLinkFrameCounter(linkFrameCounter.GetFrameCounter());
mParentCandidate.SetMleFrameCounter(mleFrameCounter.GetFrameCounter());
mParentCandidate.SetDeviceMode(ModeTlv::kModeFFD | ModeTlv::kModeRxOnWhenIdle | ModeTlv::kModeFullNetworkData);
mParentCandidate.GetLinkInfo().Clear();
mParentCandidate.GetLinkInfo().AddRss(mNetif.GetMac().GetNoiseFloor(), threadMessageInfo->mRss);
mParentCandidate.ResetLinkFailures();
mParentCandidate.SetLinkQualityOut(LinkQualityInfo::ConvertLinkMarginToLinkQuality(linkMarginTlv.GetLinkMargin()));
mParentCandidate.SetState(Neighbor::kStateValid);
mParentCandidate.SetKeySequence(aKeySequence);
mParentPriority = connectivity.GetParentPriority();
mParentLinkQuality3 = connectivity.GetLinkQuality3();
@@ -2769,7 +2769,7 @@ ThreadError Mle::HandleChildIdResponse(const Message &aMessage, const Ip6::Messa
mParent = mParentCandidate;
ResetParentCandidate();
mParent.mValid.mRloc16 = sourceAddress.GetRloc16();
mParent.SetRloc16(sourceAddress.GetRloc16());
mNetif.GetNetworkDataLeader().SetNetworkData(leaderData.GetDataVersion(), leaderData.GetStableDataVersion(),
(mDeviceMode & ModeTlv::kModeFullNetworkData) == 0,
@@ -2809,7 +2809,7 @@ ThreadError Mle::HandleChildUpdateRequest(const Message &aMessage, const Ip6::Me
// Source Address
SuccessOrExit(error = Tlv::GetTlv(aMessage, Tlv::kSourceAddress, sizeof(sourceAddress), sourceAddress));
VerifyOrExit(sourceAddress.IsValid(), error = kThreadError_Parse);
VerifyOrExit(mParent.mValid.mRloc16 == sourceAddress.GetRloc16(), error = kThreadError_Drop);
VerifyOrExit(mParent.GetRloc16() == sourceAddress.GetRloc16(), error = kThreadError_Drop);
// Leader Data
if (Tlv::GetTlv(aMessage, Tlv::kLeaderData, sizeof(leaderData), leaderData) == kThreadError_None)
@@ -2915,8 +2915,8 @@ ThreadError Mle::HandleChildUpdateResponse(const Message &aMessage, const Ip6::M
mleFrameCounter.SetFrameCounter(linkFrameCounter.GetFrameCounter());
}
mParent.mValid.mLinkFrameCounter = linkFrameCounter.GetFrameCounter();
mParent.mValid.mMleFrameCounter = mleFrameCounter.GetFrameCounter();
mParent.SetLinkFrameCounter(linkFrameCounter.GetFrameCounter());
mParent.SetMleFrameCounter(mleFrameCounter.GetFrameCounter());
SetStateChild(GetRloc16());
@@ -3122,12 +3122,12 @@ exit:
Neighbor *Mle::GetNeighbor(uint16_t aAddress)
{
if ((mParent.mState == Neighbor::kStateValid) && (mParent.mValid.mRloc16 == aAddress))
if ((mParent.GetState() == Neighbor::kStateValid) && (mParent.GetRloc16() == aAddress))
{
return &mParent;
}
if ((mParentCandidate.mState == Neighbor::kStateValid) && (mParentCandidate.mValid.mRloc16 == aAddress))
if ((mParentCandidate.GetState() == Neighbor::kStateValid) && (mParentCandidate.GetRloc16() == aAddress))
{
return &mParentCandidate;
}
@@ -3137,14 +3137,14 @@ Neighbor *Mle::GetNeighbor(uint16_t aAddress)
Neighbor *Mle::GetNeighbor(const Mac::ExtAddress &aAddress)
{
if ((mParent.mState == Neighbor::kStateValid) &&
(memcmp(&mParent.mMacAddr, &aAddress, sizeof(mParent.mMacAddr)) == 0))
if ((mParent.GetState() == Neighbor::kStateValid) &&
(memcmp(&mParent.GetExtAddress(), &aAddress, sizeof(aAddress)) == 0))
{
return &mParent;
}
if ((mParentCandidate.mState == Neighbor::kStateValid) &&
(memcmp(&mParentCandidate.mMacAddr, &aAddress, sizeof(mParentCandidate.mMacAddr)) == 0))
if ((mParentCandidate.GetState() == Neighbor::kStateValid) &&
(memcmp(&mParentCandidate.GetExtAddress(), &aAddress, sizeof(aAddress)) == 0))
{
return &mParentCandidate;
}
@@ -3173,7 +3173,7 @@ Neighbor *Mle::GetNeighbor(const Mac::Address &aAddress)
uint16_t Mle::GetNextHop(uint16_t aDestination) const
{
(void)aDestination;
return (mParent.mState == Neighbor::kStateValid) ? mParent.mValid.mRloc16 : static_cast<uint16_t>
return (mParent.GetState() == Neighbor::kStateValid) ? mParent.GetRloc16() : static_cast<uint16_t>
(Mac::kShortAddrInvalid);
}
@@ -3189,7 +3189,7 @@ bool Mle::IsAnycastLocator(const Ip6::Address &aAddress) const
Router *Mle::GetParent()
{
if ((mParent.mState != Neighbor::kStateValid) && (mParentCandidate.mState == Neighbor::kStateValid))
if ((mParent.GetState() != Neighbor::kStateValid) && (mParentCandidate.GetState() == Neighbor::kStateValid))
{
return &mParentCandidate;
}
File diff suppressed because it is too large Load Diff
+5 -5
View File
@@ -230,7 +230,7 @@ ThreadError NetworkDiagnostic::AppendChildTable(Message &aMessage)
for (int i = 0; i < numChildren; i++)
{
if (children[i].mState == Neighbor::kStateValid)
if (children[i].GetState() == Neighbor::kStateValid)
{
count++;
}
@@ -242,16 +242,16 @@ ThreadError NetworkDiagnostic::AppendChildTable(Message &aMessage)
for (int i = 0; i < numChildren; i++)
{
if (children[i].mState == Neighbor::kStateValid)
if (children[i].GetState() == Neighbor::kStateValid)
{
timeout = 0;
while (static_cast<uint32_t>(1 << timeout) < children[i].mTimeout) { timeout++; }
while (static_cast<uint32_t>(1 << timeout) < children[i].GetTimeout()) { timeout++; }
entry.SetReserved(0);
entry.SetTimeout(timeout + 4);
entry.SetChildId(mNetif.GetMle().GetChildId(children[i].mValid.mRloc16));
entry.SetMode(children[i].mMode);
entry.SetChildId(mNetif.GetMle().GetChildId(children[i].GetRloc16()));
entry.SetMode(children[i].GetDeviceMode());
SuccessOrExit(error = aMessage.Append(&entry, sizeof(ChildTableEntry)));
}
+19 -15
View File
@@ -56,7 +56,9 @@ otInstance *SourceMatchController::GetInstance(void)
void SourceMatchController::IncrementMessageCount(Child &aChild)
{
if (aChild.mQueuedMessageCount++ == 0)
aChild.IncrementIndirectMessageCount();
if (aChild.GetIndirectMessageCount() == 0)
{
AddEntry(aChild);
}
@@ -64,14 +66,16 @@ void SourceMatchController::IncrementMessageCount(Child &aChild)
void SourceMatchController::DecrementMessageCount(Child &aChild)
{
if (aChild.mQueuedMessageCount == 0)
if (aChild.GetIndirectMessageCount() == 0)
{
otLogWarnMac(GetInstance(), "DecrementMessageCount(child 0x%04x) called when already at zero count.",
aChild.mValid.mRloc16);
aChild.GetRloc16());
ExitNow();
}
if (--aChild.mQueuedMessageCount == 0)
aChild.DecrementIndirectMessageCount();
if (aChild.GetIndirectMessageCount() == 0)
{
ClearEntry(aChild);
}
@@ -82,7 +86,7 @@ exit:
void SourceMatchController::ResetMessageCount(Child &aChild)
{
aChild.mQueuedMessageCount = 0;
aChild.ResetIndirectMessageCount();
ClearEntry(aChild);
}
@@ -90,7 +94,7 @@ void SourceMatchController::SetSrcMatchAsShort(Child &aChild, bool aUseShortAddr
{
VerifyOrExit(aChild.mUseShortAddress != aUseShortAddress);
if (aChild.mQueuedMessageCount > 0)
if (aChild.GetIndirectMessageCount() > 0)
{
ClearEntry(aChild);
aChild.mUseShortAddress = aUseShortAddress;
@@ -144,18 +148,18 @@ ThreadError SourceMatchController::AddAddress(const Child &aChild)
if (aChild.mUseShortAddress)
{
error = otPlatRadioAddSrcMatchShortEntry(GetInstance(), aChild.mValid.mRloc16);
error = otPlatRadioAddSrcMatchShortEntry(GetInstance(), aChild.GetRloc16());
otLogDebgMac(GetInstance(), "SrcAddrMatch - Adding short addr: 0x%04x -- %s (%d)",
aChild.mValid.mRloc16, otThreadErrorToString(error), error);
aChild.GetRloc16(), otThreadErrorToString(error), error);
}
else
{
uint8_t addr[sizeof(aChild.mMacAddr)];
uint8_t addr[sizeof(aChild.GetExtAddress())];
for (uint8_t i = 0; i < sizeof(addr); i++)
{
addr[i] = aChild.mMacAddr.m8[sizeof(addr) - 1 - i];
addr[i] = aChild.GetExtAddress().m8[sizeof(addr) - 1 - i];
}
error = otPlatRadioAddSrcMatchExtEntry(GetInstance(), addr);
@@ -174,25 +178,25 @@ void SourceMatchController::ClearEntry(Child &aChild)
if (aChild.mSourceMatchPending)
{
otLogDebgMac(GetInstance(), "SrcAddrMatch - Clearing pending flag for 0x%04x", aChild.mValid.mRloc16);
otLogDebgMac(GetInstance(), "SrcAddrMatch - Clearing pending flag for 0x%04x", aChild.GetRloc16());
aChild.mSourceMatchPending = false;
ExitNow();
}
if (aChild.mUseShortAddress)
{
error = otPlatRadioClearSrcMatchShortEntry(GetInstance(), aChild.mValid.mRloc16);
error = otPlatRadioClearSrcMatchShortEntry(GetInstance(), aChild.GetRloc16());
otLogDebgMac(GetInstance(), "SrcAddrMatch - Clearing short address: 0x%04x -- %s (%d)",
aChild.mValid.mRloc16, otThreadErrorToString(error), error);
aChild.GetRloc16(), otThreadErrorToString(error), error);
}
else
{
uint8_t addr[sizeof(aChild.mMacAddr)];
uint8_t addr[sizeof(aChild.GetExtAddress())];
for (uint8_t i = 0; i < sizeof(addr); i++)
{
addr[i] = aChild.mMacAddr.m8[sizeof(aChild.mMacAddr) - 1 - i];
addr[i] = aChild.GetExtAddress().m8[sizeof(aChild.GetExtAddress()) - 1 - i];
}
error = otPlatRadioClearSrcMatchExtEntry(GetInstance(), addr);
+12 -1
View File
@@ -274,11 +274,22 @@ public:
/**
* This method sets the ML-EID IID.
*
* @param[in] aIid A pointer to the ML-EID IID..
* @param[in] aIid A pointer to the ML-EID IID.
*
*/
void SetIid(const uint8_t *aIid) { memcpy(mIid, aIid, sizeof(mIid)); }
/**
* This method sets the ML-EID IID.
*
* @param[in] aExtAddress A reference to the MAC Extended Address.
*
*/
void SetIid(const Mac::ExtAddress &aExtAddress) {
memcpy(mIid, aExtAddress.m8, sizeof(mIid));
mIid[0] ^= 0x2;
}
private:
uint8_t mIid[8];
} OT_TOOL_PACKED_END;
+614 -53
View File
@@ -35,6 +35,7 @@
#define TOPOLOGY_HPP_
#include <openthread-core-config.h>
#include <openthread/platform/random.h>
#include <mac/mac_frame.hpp>
#include <net/ip6.hpp>
#include <thread/mle_tlvs.hpp>
@@ -50,33 +51,11 @@ namespace Thread {
class Neighbor
{
public:
Mac::ExtAddress mMacAddr; ///< The IEEE 802.15.4 Extended Address
uint32_t mLastHeard; ///< Time when last heard.
union
{
struct
{
uint32_t mLinkFrameCounter; ///< The Link Frame Counter
uint32_t mMleFrameCounter; ///< The MLE Frame Counter
uint16_t mRloc16; ///< The RLOC16
} mValid;
struct
{
uint8_t mChallenge[Mle::ChallengeTlv::kMaxSize]; ///< The challenge value
uint8_t mChallengeLength; ///< The challenge length
} mPending;
};
uint32_t mKeySequence; ///< Current key sequence
/**
* Neighbor link states.
*
*/
enum State
#if _WIN32
: unsigned int
#endif
{
kStateInvalid, ///< Neighbor link is invalid
kStateRestored, ///< Neighbor is restored from non-volatile memory
@@ -87,11 +66,21 @@ public:
kStateValid, ///< Link is valid
};
State mState : 3; ///< The link state
uint8_t mMode : 4; ///< The MLE device mode
bool mDataRequest : 1; ///< Indicates whether or not a Data Poll was received
uint8_t mLinkFailures; ///< Consecutive link failure count
LinkQualityInfo mLinkInfo; ///< Link quality info (contains average RSS, link margin and link quality)
/**
* This method returns the current state.
*
* @returns The current state.
*
*/
State GetState(void) const { return static_cast<State>(mState); }
/**
* This method sets the current state.
*
* @param[in] aState The state value.
*
*/
void SetState(State aState) { mState = static_cast<uint8_t>(aState); }
/**
* Check if the neighbor/child is in valid state or if it is being restored.
@@ -112,6 +101,258 @@ public:
}
}
/**
* This method gets the device mode flags.
*
* @returns The device mode flags.
*
*/
uint8_t GetDeviceMode(void) const { return mMode; }
/**
* This method sets the device mode flags.
*
* @param[in] aMode The device mode flags.
*
*/
void SetDeviceMode(uint8_t aMode) { mMode = aMode; }
/**
* This method indicates whether or not the device is rx-on-when-idle.
*
* @returns TRUE if rx-on-when-idle, FALSE otherwise.
*
*/
bool IsRxOnWhenIdle(void) const { return (mMode & Mle::ModeTlv::kModeRxOnWhenIdle) != 0; }
/**
* This method indicates whether or not the device is a Full Thread Device.
*
* @returns TRUE if a Full Thread Device, FALSE otherwise.
*
*/
bool IsFullThreadDevice(void) const { return (mMode & Mle::ModeTlv::kModeFFD) != 0; }
/**
* This method indicates whether or not the device uses secure IEEE 802.15.4 Data Request messages.
*
* @returns TRUE if using secure IEEE 802.15.4 Data Request messages, FALSE otherwise.
*
*/
bool IsSecureDataRequest(void) const { return (mMode & Mle::ModeTlv::kModeSecureDataRequest) != 0; }
/**
* This method indicates whether or not the device requests Full Network Data.
*
* @returns TRUE if requests Full Network Data, FALSE otherwise.
*
*/
bool IsFullNetworkData(void) const { return (mMode & Mle::ModeTlv::kModeFullNetworkData) != 0; }
/**
* This method sets all bytes of the Extended Address to zero.
*
*/
void ClearExtAddress(void) { memset(&mMacAddr, 0, sizeof(mMacAddr)); }
/**
* This method returns the Extended Address.
*
* @returns A reference to the Extended Address.
*
*/
Mac::ExtAddress &GetExtAddress(void) { return mMacAddr; }
/**
* This method returns the Extended Address.
*
* @returns A reference to the Extended Address.
*
*/
const Mac::ExtAddress &GetExtAddress(void) const { return mMacAddr; }
/**
* This method sets the Extended Address.
*
* @param[in] aAddress The Extended Address value to set.
*
*/
void SetExtAddress(const Mac::ExtAddress &aAddress) { mMacAddr = aAddress; }
/**
* This method gets the key sequence value.
*
* @returns The key sequence value.
*
*/
uint32_t GetKeySequence(void) const { return mKeySequence; }
/**
* This method sets the key sequence value.
*
* @parma[in] aKeySequence The key sequence value.
*
*/
void SetKeySequence(uint32_t aKeySequence) { mKeySequence = aKeySequence; }
/**
* This method returns the last heard time.
*
* @returns The last heard time.
*
*/
uint32_t GetLastHeard(void) const { return mLastHeard; }
/**
* This method sets the last heard time.
*
* @param[in] aLastHeard The last heard time.
*
*/
void SetLastHeard(uint32_t aLastHeard) { mLastHeard = aLastHeard; }
/**
* This method gets the link frame counter value.
*
* @returns The link frame counter value.
*
*/
uint32_t GetLinkFrameCounter(void) const { return mValid.mLinkFrameCounter; }
/**
* This method sets the link frame counter value.
*
* @param[in] aFrameCounter The link frame counter value.
*
*/
void SetLinkFrameCounter(uint32_t aFrameCounter) { mValid.mLinkFrameCounter = aFrameCounter; }
/**
* This method gets the MLE frame counter value.
*
* @returns The MLE frame counter value.
*
*/
uint32_t GetMleFrameCounter(void) const { return mValid.mMleFrameCounter; }
/**
* This method sets the MLE frame counter value.
*
* @param[in] aFrameCounter The MLE frame counter value.
*
*/
void SetMleFrameCounter(uint32_t aFrameCounter) { mValid.mMleFrameCounter = aFrameCounter; }
/**
* This method gets the RLOC16 value.
*
* @returns The RLOC16 value.
*
*/
uint16_t GetRloc16(void) const { return mValid.mRloc16; }
/**
* This method sets the RLOC16 value.
*
* @param[in] aRloc16 The RLOC16 value.
*
*/
void SetRloc16(uint16_t aRloc16) { mValid.mRloc16 = aRloc16; }
/**
* This method indicates whether an IEEE 802.15.4 Data Request message was received.
*
* @returns TRUE if an IEEE 802.15.4 Data Request message was received, FALSE otherwise.
*
*/
bool IsDataRequestPending(void) const { return mDataRequest; }
/**
* This method sets the indicator for whether an IEEE 802.15.4 Data Request message was received.
*
* @param[in] aPending TRUE if an IEEE 802.15.4 Data Request message was received, FALSE otherwise.
*
*/
void SetDataRequestPending(bool aPending) { mDataRequest = aPending; }
/**
* This method gets the number of consecutive link failures.
*
* @returns The number of consecutive link failures.
*
*/
uint8_t GetLinkFailures(void) const { return mLinkFailures; }
/**
* This method increments the number of consecutive link failures.
*
*/
void IncrementLinkFailures(void) { mLinkFailures++; }
/**
* This method resets the number of consecutive link failures to zero.
*
*/
void ResetLinkFailures(void) { mLinkFailures = 0; }
/**
* This method returns the LinkQualityInfo object.
*
* @returns The LinkQualityInfo object.
*
*/
LinkQualityInfo &GetLinkInfo(void) { return mLinkInfo; }
/**
* This method generates a new challenge value for MLE Link Request/Response exchanges.
*
*/
void GenerateChallenge(void) {
for (uint8_t i = 0; i < sizeof(mPending.mChallenge); i++) {
mPending.mChallenge[i] = static_cast<uint8_t>(otPlatRandomGet());
}
}
/**
* This method returns the current challenge value for MLE Link Request/Response exchanges.
*
* @returns The current challenge value.
*
*/
const uint8_t *GetChallenge(void) const { return mPending.mChallenge; }
/**
* This method returns the size (byets) of the challenge value for MLE Link Request/Response exchanges.
*
* @returns The size (byets) of the challenge value for MLE Link Request/Response exchanges.
*
*/
uint8_t GetChallengeSize(void) const { return sizeof(mPending.mChallenge); }
private:
Mac::ExtAddress mMacAddr; ///< The IEEE 802.15.4 Extended Address
uint32_t mLastHeard; ///< Time when last heard.
union
{
struct
{
uint32_t mLinkFrameCounter; ///< The Link Frame Counter
uint32_t mMleFrameCounter; ///< The MLE Frame Counter
uint16_t mRloc16; ///< The RLOC16
} mValid;
struct
{
uint8_t mChallenge[Mle::ChallengeTlv::kMaxSize]; ///< The challenge value
uint8_t mChallengeLength; ///< The challenge length
} mPending;
};
uint32_t mKeySequence; ///< Current key sequence
uint8_t mState : 3; ///< The link state
uint8_t mMode : 4; ///< The MLE device mode
bool mDataRequest : 1; ///< Indicates whether or not a Data Poll was received
uint8_t mLinkFailures; ///< Consecutive link failure count
LinkQualityInfo mLinkInfo; ///< Link quality info (contains average RSS, link margin and link quality)
};
/**
@@ -129,31 +370,211 @@ public:
kMaxRequestTlvs = 5,
};
Ip6::Address mIp6Address[kMaxIp6AddressPerChild]; ///< Registered IPv6 addresses
uint32_t mTimeout; ///< Child timeout
struct
{
uint32_t mFrameCounter; ///< Frame counter for current indirect message (used fore retx).
Message *mMessage; ///< Current indirect message.
uint16_t mFragmentOffset; ///< 6LoWPAN fragment offset for the indirect message.
uint8_t mKeyId; ///< Key Id for current indirect message (used for retx).
uint8_t mTxAttemptCounter; ///< Number of data poll triggered tx attempts.
uint8_t mDataSequenceNumber; ///< MAC level Data Sequence Number (DSN) for retx attempts.
} mIndirectSendInfo; ///< Info about current outbound indirect message.
union
{
uint8_t mRequestTlvs[kMaxRequestTlvs]; ///< Requested MLE TLVs
uint8_t mAttachChallenge[Mle::ChallengeTlv::kMaxSize]; ///< The challenge value
};
uint8_t mNetworkDataVersion; ///< Current Network Data version
/**
* This method checks if a short or extended address should be used.
*
* @returns `true` if a short address should be used, `false` for extended address.
* This method clears the IPv6 addresses for the child.
*
*/
bool ShouldUseShortAddress(void) const { return mUseShortAddress; }
void ClearIp6Addresses(void) { memset(mIp6Address, 0, sizeof(mIp6Address)); }
/**
* This method gets the IPv6 address at index @p aIndex.
*
* @param[in] aIndex The index into the IPv6 address list.
*
* @returns A reference to the IPv6 address entry at index @p aIndex.
*
*/
Ip6::Address &GetIp6Address(uint8_t aIndex) { return mIp6Address[aIndex]; }
/**
* This method gets the child timeout.
*
* @returns The child timeout.
*
*/
uint32_t GetTimeout(void) const { return mTimeout; }
/**
* This method sets the child timeout.
*
* @param[in] aTimeout The child timeout.
*
*/
void SetTimeout(uint32_t aTimeout) { mTimeout = aTimeout; }
/**
* This method gets the network data version.
*
* @returns The network data version.
*
*/
uint8_t GetNetworkDataVersion(void) const { return mNetworkDataVersion; }
/**
* This method sets the network data version.
*
* @param[in] aVersion The network data version.
*
*/
void SetNetworkDataVersion(uint8_t aVersion) { mNetworkDataVersion = aVersion; }
/**
* This method generates a new challenge value to use during a child attach.
*
*/
void GenerateChallenge(void) {
for (uint8_t i = 0; i < sizeof(mAttachChallenge); i++) {
mAttachChallenge[i] = static_cast<uint8_t>(otPlatRandomGet());
}
}
/**
* This method gets the current challenge value used during attach.
*
* @returns The current challenge value.
*
*/
const uint8_t *GetChallenge(void) const { return mAttachChallenge; }
/**
* This method gets the challenge size (bytes) used during attach.
*
* @returns The challenge size (bytes).
*
*/
uint8_t GetChallengeSize(void) const { return sizeof(mAttachChallenge); }
/**
* This method gets the IEEE 802.15.4 Frame Counter used during indirect retransmissions.
*
* @returns The IEEE 802.15.4 Frame Counter value.
*
*/
uint32_t GetIndirectFrameCounter(void) const { return mIndirectFrameCounter; }
/**
* This method sets the IEEE 802.15.4 Frame Counter to use during indirect retransmissions.
*
* @param[in] aFrameCounter The IEEE 802.15.4 Frame Counter value.
*
*/
void SetIndirectFrameCounter(uint32_t aFrameCounter) { mIndirectFrameCounter = aFrameCounter; }
/**
* This method gets the message buffer to use for indirect transmissions.
*
* @returns The message buffer.
*
*/
Message *GetIndirectMessage(void) { return mIndirectMessage; }
/**
* This method sets the message buffer to use for indirect transmissions.
*
* @param[in] aMessage The message buffer.
*
*/
void SetIndirectMessage(Message *aMessage) { mIndirectMessage = aMessage; }
/**
* This method gets the 6LoWPAN Fragment Offset to use for indirect transmissions.
*
* @returns The 6LoWPAN Fragment Offset value.
*
*/
uint16_t GetIndirectFragmentOffset(void) const { return mIndirectFragmentOffset; }
/**
* This method sets the 6LoWPAN Fragment Offset to use for indirect transmissions.
*
* @param[in] aFragmentOffset The 6LoWPAN Fragment Offset value to use.
*
*/
void SetIndirectFragmentOffset(uint16_t aFragmentOffset) { mIndirectFragmentOffset = aFragmentOffset; }
/**
* This method gets the IEEE 802.15.4 Key ID to use for indirect retransmissions.
*
* @returns The IEEE 802.15.4 Key ID value.
*
*/
uint8_t GetIndirectKeyId(void) const { return mIndirectKeyId; }
/**
* This method sets the IEEE 802.15.4 Key ID value to use for indirect retransmissions.
*
* @param[in] aKeyId The IEEE 802.15.4 Key ID value.
*
*/
void SetIndirectKeyId(uint8_t aKeyId) { mIndirectKeyId = aKeyId; }
/**
* This method gets the number of indirect transmission attempts for the current message.
*
* @returns The number of indirect transmission attempts.
*
*/
uint8_t GetIndirectTxAttempts(void) const { return mIndirectTxAttempts; }
/**
* This method resets the number of indirect transmission attempts to zero.
*
*/
void ResetIndirectTxAttempts(void) { mIndirectTxAttempts = 0; }
/**
* This method increments the number of indirect transmission attempts.
*
*/
void IncrementIndirectTxAttempts(void) { mIndirectTxAttempts++; }
/**
* This method gets the IEEE 802.15.4 Data Sequence Number to use during indirect retransmissions.
*
* @returns The IEEE 802.15.4 Data Sequence Number value.
*
*/
uint8_t GetIndirectDataSequenceNumber(void) const { return mIndirectDsn; }
/**
* This method sets the IEEE 802.15.4 Data Sequence Number to use during indirect retransmissions.
*
* @param[in] aDsn The IEEE 802.15.4 Data Sequence Number value.
*
*/
void SetIndirectDataSequenceNumber(uint8_t aDsn) { mIndirectDsn = aDsn; }
/**
* This method indicates whether or not to source match on the source address.
*
* @returns TRUE if using the short address, FALSE if using the extended address.
*
*/
bool IsIndirectSourceMatchShort(void) const { return mUseShortAddress; }
/**
* This method sets whether or not to source match on the source address.
*
* @param[in] aShort TRUE if using the short address, FALSE if using the extended address.
*
*/
void SetIndirectSourceMatchShort(bool aShort) { mUseShortAddress = aShort; }
/**
* This method indicates whether or not the child needs to be added to the source match table.
*
* @returns TRUE if the child needs to be added to the source match table, FALSE otherwise.
*
*/
bool IsIndirectSourceMatchPending(void) const { return mSourceMatchPending; }
/**
* This method sets whether or not the child needs to be added to the source match table.
*
* @param[in] aPending TRUE if the child needs to be added to the source match table, FALSE otherwise.
*
*/
void SetIndirectSourceMatchPending(bool aPending) { mSourceMatchPending = aPending; }
/**
* This method returns the number of queued message(s) for the child
@@ -161,12 +582,71 @@ public:
* @returns Number of queues message(s).
*
*/
uint16_t GetQueuedMessageCount(void) const { return mQueuedMessageCount; }
uint16_t GetIndirectMessageCount(void) const { return mQueuedMessageCount; }
/**
* This method increments the indirect message count.
*
*/
void IncrementIndirectMessageCount(void) { mQueuedMessageCount++; }
/**
* This method decrements the indirect message count.
*
*/
void DecrementIndirectMessageCount(void) { mQueuedMessageCount--; }
/**
* This method resets the indirect message count to zero.
*
*/
void ResetIndirectMessageCount(void) { mQueuedMessageCount = 0; }
/**
* This method clears the requested TLV list.
*
*/
void ClearRequestTlvs(void) { memset(mRequestTlvs, Mle::Tlv::kInvalid, sizeof(mRequestTlvs)); }
/**
* This method returns the requested TLV at index @p aIndex.
*
* @param[in] aIndex The index into the requested TLV list.
*
* @returns The requested TLV at index @p aIndex.
*
*/
uint8_t GetRequestTlv(uint8_t aIndex) const { return mRequestTlvs[aIndex]; }
/**
* This method sets the requested TLV at index @p aIndex.
*
* @param[in] aIndex The index into the requested TLV list.
* @param[in] aType The TLV type.
*
*/
void SetRequestTlv(uint8_t aIndex, uint8_t aType) { mRequestTlvs[aIndex] = aType; }
private:
uint16_t mQueuedMessageCount : 13; ///< Number of queued indirect messages for the child.
bool mUseShortAddress : 1; ///< Indicates whether to use short or extended address.
bool mSourceMatchPending : 1; ///< Indicates whether or not pending to add to src match table.
Ip6::Address mIp6Address[kMaxIp6AddressPerChild]; ///< Registered IPv6 addresses
uint32_t mTimeout; ///< Child timeout
union
{
uint8_t mRequestTlvs[kMaxRequestTlvs]; ///< Requested MLE TLVs
uint8_t mAttachChallenge[Mle::ChallengeTlv::kMaxSize]; ///< The challenge value
};
uint32_t mIndirectFrameCounter; ///< Frame counter for current indirect message (used fore retx).
Message *mIndirectMessage; ///< Current indirect message.
uint16_t mIndirectFragmentOffset; ///< 6LoWPAN fragment offset for the indirect message.
uint8_t mIndirectKeyId; ///< Key Id for current indirect message (used for retx).
uint8_t mIndirectTxAttempts; ///< Number of data poll triggered tx attempts.
uint8_t mIndirectDsn; ///< MAC level Data Sequence Number (DSN) for retx attempts.
uint8_t mNetworkDataVersion; ///< Current Network Data version
uint16_t mQueuedMessageCount : 13; ///< Number of queued indirect messages for the child.
bool mUseShortAddress : 1; ///< Indicates whether to use short or extended address.
bool mSourceMatchPending : 1; ///< Indicates whether or not pending to add to src match table.
};
/**
@@ -176,6 +656,87 @@ private:
class Router : public Neighbor
{
public:
/**
* This method gets the router ID of the next hop to this router.
*
* @returns The router ID of the next hop to this router.
*
*/
uint8_t GetNextHop(void) const { return mNextHop; }
/**
* This method sets the router ID of the next hop to this router.
*
* @param[in] aRouterId The router ID of the next hop to this router.
*
*/
void SetNextHop(uint8_t aRouterId) { mNextHop = aRouterId; }
/**
* This method gets the link quality out value for this router.
*
* @returns The link quality out value for this router.
*
*/
uint8_t GetLinkQualityOut(void) const { return mLinkQualityOut; }
/**
* This method sets the link quality out value for this router.
*
* @param[in] aLinkQuality The link quality out value for this router.
*
*/
void SetLinkQualityOut(uint8_t aLinkQuality) { mLinkQualityOut = aLinkQuality; }
/**
* This method get the route cost to this router.
*
* @returns The route cost to this router.
*
*/
uint8_t GetCost(void) const { return mCost; }
/**
* This method sets the router cost to this router.
*
* @param[in] aCost The router cost to this router.
*
*/
void SetCost(uint8_t aCost) { mCost = aCost; }
/**
* This method indicates whether or not this router ID has been allocated.
*
* @returns TRUE if this router ID has been allocated, FALSE otherwise.
*
*/
bool IsAllocated(void) const { return mAllocated; }
/**
* This method sets whether or not this router ID has been allocated.
*
* @param[in] aAllocated TRUE if this router ID has been allocated, FALSE otherwise.
*
*/
void SetAllocated(bool aAllocated) { mAllocated = aAllocated; }
/**
* This method indicates whether the reclaim delay is in effect for this router ID.
*
* @returns TRUE if the reclaim delay is in effect, FALSE otherwise.
*
*/
bool IsReclaimDelay(void) const { return mReclaimDelay; }
/**
* This method sets whether the reclaim delay is in effect for this router ID.
*
* @param[in] aReclaimDelay TRUE if the reclaim delay is in effect, FALSE otherwise.
*
*/
void SetReclaimDelay(bool aReclaimDelay) { mReclaimDelay = aReclaimDelay; }
private:
uint8_t mNextHop; ///< The next hop towards this router
uint8_t mLinkQualityOut : 2; ///< The link quality out for this router
uint8_t mCost : 4; ///< The cost to this router via neighbor router
+2 -2
View File
@@ -95,10 +95,10 @@ void test_packed_union()
void test_packed_enum()
{
Thread::Neighbor neighbor;
neighbor.mState = Thread::Neighbor::kStateValid;
neighbor.SetState(Thread::Neighbor::kStateValid);
// Make sure that when we read the 3 bit field it is read as unsigned, so it return '4'
VerifyOrQuit(neighbor.mState == Thread::Neighbor::kStateValid, "Toolchain::OT_TOOL_PACKED failed 4\n");
VerifyOrQuit(neighbor.GetState() == Thread::Neighbor::kStateValid, "Toolchain::OT_TOOL_PACKED failed 4\n");
}
void test_addr_sizes()