mirror of
https://github.com/espressif/openthread.git
synced 2026-07-18 18:14:07 +00:00
[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:
committed by
Jonathan Hui
parent
425e4a3326
commit
aec0e0b2a0
@@ -131,6 +131,26 @@ exit:
|
||||
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 error = OT_ERROR_NONE;
|
||||
|
||||
@@ -131,6 +131,17 @@ public:
|
||||
*/
|
||||
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
|
||||
* transmission.
|
||||
|
||||
+10
-20
@@ -791,41 +791,31 @@ void Mac::GenerateNonce(const ExtAddress &aAddress, uint32_t aFrameCounter, uint
|
||||
|
||||
otError Mac::PrepareDataRequest(Frame &aFrame)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
Neighbor *parent = Get<Mle::MleRouter>().GetParentCandidate();
|
||||
uint16_t fcf;
|
||||
bool useExtendedAddr;
|
||||
otError error = OT_ERROR_NONE;
|
||||
Address src, dst;
|
||||
uint16_t fcf;
|
||||
|
||||
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 |
|
||||
Frame::kFcfSecurityEnabled;
|
||||
|
||||
useExtendedAddr = (GetShortAddress() == kShortAddrInvalid) || (parent != Get<Mle::MleRouter>().GetParent());
|
||||
|
||||
if (useExtendedAddr)
|
||||
if (dst.IsExtended())
|
||||
{
|
||||
fcf |= Frame::kFcfDstAddrExt | Frame::kFcfSrcAddrExt;
|
||||
src.SetExtended(GetExtAddress());
|
||||
}
|
||||
else
|
||||
{
|
||||
fcf |= Frame::kFcfDstAddrShort | Frame::kFcfSrcAddrShort;
|
||||
src.SetShort(GetShortAddress());
|
||||
}
|
||||
|
||||
aFrame.InitMacHeader(fcf, Frame::kKeyIdMode1 | Frame::kSecEncMic32);
|
||||
aFrame.SetDstPanId(GetPanId());
|
||||
|
||||
if (useExtendedAddr)
|
||||
{
|
||||
aFrame.SetSrcAddr(GetExtAddress());
|
||||
aFrame.SetDstAddr(parent->GetExtAddress());
|
||||
}
|
||||
else
|
||||
{
|
||||
aFrame.SetSrcAddr(GetShortAddress());
|
||||
aFrame.SetDstAddr(parent->GetRloc16());
|
||||
}
|
||||
|
||||
aFrame.SetSrcAddr(src);
|
||||
aFrame.SetDstAddr(dst);
|
||||
aFrame.SetCommandId(Frame::kMacCmdDataRequest);
|
||||
|
||||
exit:
|
||||
|
||||
Reference in New Issue
Block a user