[data-poll-sender] add logic to select poll destination (#4023)

This commit changes the interaction of `Mac` and `DataPollSender` such
that the selection of a data poll destination MAC address is delegated
to `DataPollSender` (related code is moved into `DataPollSender` from
`Mac`).
This commit is contained in:
Abtin Keshavarzian
2019-07-25 21:35:18 -07:00
committed by Jonathan Hui
parent 425e4a3326
commit aec0e0b2a0
3 changed files with 41 additions and 20 deletions
+20
View File
@@ -131,6 +131,26 @@ exit:
return error; return error;
} }
otError DataPollSender::GetPollDestinationAddress(Mac::Address &aDest) const
{
otError error = OT_ERROR_NONE;
Neighbor *parent = Get<Mle::MleRouter>().GetParentCandidate();
VerifyOrExit((parent != NULL) && parent->IsStateValidOrRestoring(), error = OT_ERROR_ABORT);
if ((Get<Mac::Mac>().GetShortAddress() == Mac::kShortAddrInvalid) || (parent != Get<Mle::MleRouter>().GetParent()))
{
aDest.SetExtended(parent->GetExtAddress());
}
else
{
aDest.SetShort(parent->GetRloc16());
}
exit:
return error;
}
otError DataPollSender::SetExternalPollPeriod(uint32_t aPeriod) otError DataPollSender::SetExternalPollPeriod(uint32_t aPeriod)
{ {
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
+11
View File
@@ -131,6 +131,17 @@ public:
*/ */
uint32_t GetExternalPollPeriod(void) const { return mExternalPollPeriod; } uint32_t GetExternalPollPeriod(void) const { return mExternalPollPeriod; }
/**
* This method gets the destination MAC address for a data poll frame.
*
* @param[out] aDest Reference to a `MAC::Address` to output the poll destination address (on success).
*
* @retval OT_ERROR_NONE @p aDest was updated successfully.
* @retval OT_ERROR_ABORT Abort the data poll transmission (not currently attached to any parent).
*
*/
otError GetPollDestinationAddress(Mac::Address &aDest) const;
/** /**
* This method informs the data poll sender of success/error status of a previously requested poll frame * This method informs the data poll sender of success/error status of a previously requested poll frame
* transmission. * transmission.
+10 -20
View File
@@ -791,41 +791,31 @@ void Mac::GenerateNonce(const ExtAddress &aAddress, uint32_t aFrameCounter, uint
otError Mac::PrepareDataRequest(Frame &aFrame) otError Mac::PrepareDataRequest(Frame &aFrame)
{ {
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
Neighbor *parent = Get<Mle::MleRouter>().GetParentCandidate(); Address src, dst;
uint16_t fcf; uint16_t fcf;
bool useExtendedAddr;
VerifyOrExit((parent != NULL) && parent->IsStateValidOrRestoring(), error = OT_ERROR_ABORT); SuccessOrExit(error = Get<DataPollSender>().GetPollDestinationAddress(dst));
VerifyOrExit(!dst.IsNone(), error = OT_ERROR_ABORT);
fcf = Frame::kFcfFrameMacCmd | Frame::kFcfPanidCompression | Frame::kFcfFrameVersion2006 | Frame::kFcfAckRequest | fcf = Frame::kFcfFrameMacCmd | Frame::kFcfPanidCompression | Frame::kFcfFrameVersion2006 | Frame::kFcfAckRequest |
Frame::kFcfSecurityEnabled; Frame::kFcfSecurityEnabled;
useExtendedAddr = (GetShortAddress() == kShortAddrInvalid) || (parent != Get<Mle::MleRouter>().GetParent()); if (dst.IsExtended())
if (useExtendedAddr)
{ {
fcf |= Frame::kFcfDstAddrExt | Frame::kFcfSrcAddrExt; fcf |= Frame::kFcfDstAddrExt | Frame::kFcfSrcAddrExt;
src.SetExtended(GetExtAddress());
} }
else else
{ {
fcf |= Frame::kFcfDstAddrShort | Frame::kFcfSrcAddrShort; fcf |= Frame::kFcfDstAddrShort | Frame::kFcfSrcAddrShort;
src.SetShort(GetShortAddress());
} }
aFrame.InitMacHeader(fcf, Frame::kKeyIdMode1 | Frame::kSecEncMic32); aFrame.InitMacHeader(fcf, Frame::kKeyIdMode1 | Frame::kSecEncMic32);
aFrame.SetDstPanId(GetPanId()); aFrame.SetDstPanId(GetPanId());
aFrame.SetSrcAddr(src);
if (useExtendedAddr) aFrame.SetDstAddr(dst);
{
aFrame.SetSrcAddr(GetExtAddress());
aFrame.SetDstAddr(parent->GetExtAddress());
}
else
{
aFrame.SetSrcAddr(GetShortAddress());
aFrame.SetDstAddr(parent->GetRloc16());
}
aFrame.SetCommandId(Frame::kMacCmdDataRequest); aFrame.SetCommandId(Frame::kMacCmdDataRequest);
exit: exit: