mirror of
https://github.com/espressif/openthread.git
synced 2026-08-02 09:07:47 +00:00
[data-poll-manager] do not sent data poll when there is no parent (e.g., when detached) (#2109)
This commit is contained in:
committed by
Jonathan Hui
parent
cf8a789e24
commit
cfb8766928
@@ -418,6 +418,28 @@ otError Frame::SetDstAddr(const ExtAddress &aExtAddress)
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError Frame::SetDstAddr(const Address &aAddress)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
switch (aAddress.mLength)
|
||||
{
|
||||
case sizeof(ShortAddress):
|
||||
error = SetDstAddr(aAddress.mShortAddress);
|
||||
break;
|
||||
|
||||
case sizeof(ExtAddress):
|
||||
error = SetDstAddr(aAddress.mExtAddress);
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
uint8_t Frame::FindSrcPanIdIndex(void) const
|
||||
{
|
||||
uint8_t index = 0;
|
||||
@@ -567,6 +589,28 @@ otError Frame::SetSrcAddr(const ExtAddress &aExtAddress)
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError Frame::SetSrcAddr(const Address &aAddress)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
switch (aAddress.mLength)
|
||||
{
|
||||
case sizeof(ShortAddress):
|
||||
error = SetSrcAddr(aAddress.mShortAddress);
|
||||
break;
|
||||
|
||||
case sizeof(ExtAddress):
|
||||
error = SetSrcAddr(aAddress.mExtAddress);
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
uint8_t Frame::FindSecurityHeaderIndex(void) const
|
||||
{
|
||||
uint8_t index = 0;
|
||||
|
||||
@@ -387,6 +387,16 @@ public:
|
||||
*/
|
||||
otError SetDstAddr(const ExtAddress &aExtAddress);
|
||||
|
||||
/**
|
||||
* This method sets the Destination Address.
|
||||
*
|
||||
* @param[in] aAddress The Destination Address.
|
||||
*
|
||||
* @retval OT_ERROR_NONE Successfully set the Destination Address.
|
||||
*
|
||||
*/
|
||||
otError SetDstAddr(const Address &aAddress);
|
||||
|
||||
/**
|
||||
* This method gets the Source PAN Identifier.
|
||||
*
|
||||
@@ -418,7 +428,7 @@ public:
|
||||
otError GetSrcAddr(Address &aAddress) const;
|
||||
|
||||
/**
|
||||
* This method gets the Source Address.
|
||||
* This method sets the Source Address.
|
||||
*
|
||||
* @param[in] aShortAddress The Source Address.
|
||||
*
|
||||
@@ -428,7 +438,7 @@ public:
|
||||
otError SetSrcAddr(ShortAddress aShortAddress);
|
||||
|
||||
/**
|
||||
* This method gets the Source Address.
|
||||
* This method sets the Source Address.
|
||||
*
|
||||
* @param[in] aExtAddress The Source Address.
|
||||
*
|
||||
@@ -437,6 +447,16 @@ public:
|
||||
*/
|
||||
otError SetSrcAddr(const ExtAddress &aExtAddress);
|
||||
|
||||
/**
|
||||
* This method sets the Source Address.
|
||||
*
|
||||
* @param[in] aAddress The Source Address.
|
||||
*
|
||||
* @retval OT_ERROR_NONE Successfully set the Source Address.
|
||||
*
|
||||
*/
|
||||
otError SetSrcAddr(const Address &aAddress);
|
||||
|
||||
/**
|
||||
* This method gets the Security Level Identifier.
|
||||
*
|
||||
@@ -555,7 +575,6 @@ public:
|
||||
* @param[in] aLength The MAC Frame Length.
|
||||
*
|
||||
* @retval OT_ERROR_NONE Successfully set the MAC Frame Length.
|
||||
* @retval OT_ERROR_INVALID_ARGS The @p aLength value was invalid.
|
||||
*
|
||||
*/
|
||||
otError SetLength(uint8_t aLength) { SetPsduLength(aLength); return OT_ERROR_NONE; }
|
||||
|
||||
@@ -97,10 +97,14 @@ otError DataPollManager::SendDataPoll(void)
|
||||
MeshForwarder &meshForwarder = GetMeshForwarder();
|
||||
otError error;
|
||||
Message *message;
|
||||
Neighbor *parent;
|
||||
|
||||
VerifyOrExit(mEnabled, error = OT_ERROR_INVALID_STATE);
|
||||
VerifyOrExit(!meshForwarder.GetNetif().GetMac().GetRxOnWhenIdle(), error = OT_ERROR_INVALID_STATE);
|
||||
|
||||
parent = meshForwarder.GetNetif().GetMle().GetParent();
|
||||
VerifyOrExit((parent != NULL) && parent->IsStateValidOrRestoring(), error = OT_ERROR_INVALID_STATE);
|
||||
|
||||
mTimer.Stop();
|
||||
|
||||
for (message = meshForwarder.GetSendQueue().GetHead(); message; message = message->GetNext())
|
||||
|
||||
@@ -566,7 +566,35 @@ Message *MeshForwarder::GetDirectTransmission(void)
|
||||
break;
|
||||
|
||||
case Message::kTypeMacDataPoll:
|
||||
ExitNow();
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
Neighbor *parent = netif.GetMle().GetParent();
|
||||
|
||||
if ((parent != NULL) && (parent->IsStateValidOrRestoring()))
|
||||
{
|
||||
mMacSource.mShortAddress = netif.GetMac().GetShortAddress();
|
||||
|
||||
if (mMacSource.mShortAddress != Mac::kShortAddrInvalid)
|
||||
{
|
||||
mMacSource.mLength = sizeof(mMacSource.mShortAddress);
|
||||
mMacDest.mLength = sizeof(mMacDest.mShortAddress);
|
||||
mMacDest.mShortAddress = parent->GetRloc16();
|
||||
}
|
||||
else
|
||||
{
|
||||
mMacSource.mLength = sizeof(mMacSource.mExtAddress);
|
||||
memcpy(mMacSource.mExtAddress.m8, netif.GetMac().GetExtAddress(), sizeof(mMacSource.mExtAddress));
|
||||
mMacDest.mLength = sizeof(mMacDest.mExtAddress);
|
||||
memcpy(mMacDest.mExtAddress.m8, &parent->GetExtAddress(), sizeof(mMacDest.mExtAddress));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
error = OT_ERROR_DROP;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case Message::kTypeSupervision:
|
||||
error = OT_ERROR_DROP;
|
||||
@@ -1105,26 +1133,12 @@ exit:
|
||||
otError MeshForwarder::SendPoll(Message &aMessage, Mac::Frame &aFrame)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
Mac::Address macSource;
|
||||
uint16_t fcf;
|
||||
Neighbor *neighbor;
|
||||
|
||||
macSource.mShortAddress = netif.GetMac().GetShortAddress();
|
||||
|
||||
if (macSource.mShortAddress != Mac::kShortAddrInvalid)
|
||||
{
|
||||
macSource.mLength = sizeof(macSource.mShortAddress);
|
||||
}
|
||||
else
|
||||
{
|
||||
macSource.mLength = sizeof(macSource.mExtAddress);
|
||||
memcpy(&macSource.mExtAddress, netif.GetMac().GetExtAddress(), sizeof(macSource.mExtAddress));
|
||||
}
|
||||
|
||||
// initialize MAC header
|
||||
fcf = Mac::Frame::kFcfFrameMacCmd | Mac::Frame::kFcfPanidCompression | Mac::Frame::kFcfFrameVersion2006;
|
||||
|
||||
if (macSource.mLength == sizeof(Mac::ShortAddress))
|
||||
if (mMacSource.mLength == sizeof(Mac::ShortAddress))
|
||||
{
|
||||
fcf |= Mac::Frame::kFcfDstAddrShort | Mac::Frame::kFcfSrcAddrShort;
|
||||
}
|
||||
@@ -1137,21 +1151,8 @@ otError MeshForwarder::SendPoll(Message &aMessage, Mac::Frame &aFrame)
|
||||
|
||||
aFrame.InitMacHeader(fcf, Mac::Frame::kKeyIdMode1 | Mac::Frame::kSecEncMic32);
|
||||
aFrame.SetDstPanId(netif.GetMac().GetPanId());
|
||||
|
||||
neighbor = netif.GetMle().GetParent();
|
||||
assert(neighbor != NULL);
|
||||
|
||||
if (macSource.mLength == 2)
|
||||
{
|
||||
aFrame.SetDstAddr(neighbor->GetRloc16());
|
||||
aFrame.SetSrcAddr(macSource.mShortAddress);
|
||||
}
|
||||
else
|
||||
{
|
||||
aFrame.SetDstAddr(neighbor->GetExtAddress());
|
||||
aFrame.SetSrcAddr(macSource.mExtAddress);
|
||||
}
|
||||
|
||||
aFrame.SetSrcAddr(mMacSource);
|
||||
aFrame.SetDstAddr(mMacDest);
|
||||
aFrame.SetCommandId(Mac::Frame::kMacCmdDataRequest);
|
||||
|
||||
mMessageNextOffset = aMessage.GetLength();
|
||||
@@ -1273,24 +1274,8 @@ otError MeshForwarder::SendFragment(Message &aMessage, Mac::Frame &aFrame)
|
||||
aFrame.InitMacHeader(fcf, secCtl);
|
||||
aFrame.SetDstPanId(dstpan);
|
||||
aFrame.SetSrcPanId(netif.GetMac().GetPanId());
|
||||
|
||||
if (mMacDest.mLength == 2)
|
||||
{
|
||||
aFrame.SetDstAddr(mMacDest.mShortAddress);
|
||||
}
|
||||
else
|
||||
{
|
||||
aFrame.SetDstAddr(mMacDest.mExtAddress);
|
||||
}
|
||||
|
||||
if (mMacSource.mLength == 2)
|
||||
{
|
||||
aFrame.SetSrcAddr(mMacSource.mShortAddress);
|
||||
}
|
||||
else
|
||||
{
|
||||
aFrame.SetSrcAddr(mMacSource.mExtAddress);
|
||||
}
|
||||
aFrame.SetDstAddr(mMacDest);
|
||||
aFrame.SetSrcAddr(mMacSource);
|
||||
|
||||
payload = aFrame.GetPayload();
|
||||
|
||||
@@ -1468,25 +1453,8 @@ otError MeshForwarder::SendEmptyFrame(Mac::Frame &aFrame, bool aAckRequest)
|
||||
|
||||
aFrame.SetDstPanId(netif.GetMac().GetPanId());
|
||||
aFrame.SetSrcPanId(netif.GetMac().GetPanId());
|
||||
|
||||
if (mMacDest.mLength == 2)
|
||||
{
|
||||
aFrame.SetDstAddr(mMacDest.mShortAddress);
|
||||
}
|
||||
else
|
||||
{
|
||||
aFrame.SetDstAddr(mMacDest.mExtAddress);
|
||||
}
|
||||
|
||||
if (macSource.mLength == 2)
|
||||
{
|
||||
aFrame.SetSrcAddr(macSource.mShortAddress);
|
||||
}
|
||||
else
|
||||
{
|
||||
aFrame.SetSrcAddr(macSource.mExtAddress);
|
||||
}
|
||||
|
||||
aFrame.SetDstAddr(mMacDest);
|
||||
aFrame.SetSrcAddr(macSource);
|
||||
aFrame.SetPayloadLength(0);
|
||||
aFrame.SetFramePending(false);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user