mirror of
https://github.com/espressif/openthread.git
synced 2026-10-02 22:07:36 +00:00
[mac-frame] add DetermineFcfAddrType() helper (#10780)
This commit adds the `DetermineFcfAddrType()` helper function, which determines the Frame Control Field (FCF) address type for a given address. The result is bit-shifted based on whether the address is the source or destination and whether the frame uses the general format or is a multipurpose frame. This helper simplifies methods that prepare MAC headers.
This commit is contained in:
+34
-50
@@ -56,36 +56,12 @@ void TxFrame::Info::PrepareHeadersIn(TxFrame &aTxFrame) const
|
|||||||
|
|
||||||
fcf = static_cast<uint16_t>(mType) | static_cast<uint16_t>(mVersion);
|
fcf = static_cast<uint16_t>(mType) | static_cast<uint16_t>(mVersion);
|
||||||
|
|
||||||
switch (mAddrs.mSource.GetType())
|
fcf |= DetermineFcfAddrType(mAddrs.mSource, kFcfSrcAddrShift);
|
||||||
{
|
fcf |= DetermineFcfAddrType(mAddrs.mDestination, kFcfDstAddrShift);
|
||||||
case Address::kTypeNone:
|
|
||||||
fcf |= kFcfSrcAddrNone;
|
|
||||||
break;
|
|
||||||
case Address::kTypeShort:
|
|
||||||
fcf |= kFcfSrcAddrShort;
|
|
||||||
break;
|
|
||||||
case Address::kTypeExtended:
|
|
||||||
fcf |= kFcfSrcAddrExt;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (mAddrs.mDestination.GetType())
|
if (!mAddrs.mDestination.IsNone() && !mAddrs.mDestination.IsBroadcast() && (mType != kTypeAck))
|
||||||
{
|
{
|
||||||
case Address::kTypeNone:
|
fcf |= kFcfAckRequest;
|
||||||
fcf |= kFcfDstAddrNone;
|
|
||||||
break;
|
|
||||||
case Address::kTypeShort:
|
|
||||||
fcf |= kFcfDstAddrShort;
|
|
||||||
fcf |= ((mAddrs.mDestination.GetShort() == kShortAddrBroadcast) ? 0 : kFcfAckRequest);
|
|
||||||
break;
|
|
||||||
case Address::kTypeExtended:
|
|
||||||
fcf |= (kFcfDstAddrExt | kFcfAckRequest);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mType == kTypeAck)
|
|
||||||
{
|
|
||||||
fcf &= ~kFcfAckRequest;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fcf |= (mSecurityLevel != kSecurityNone) ? kFcfSecurityEnabled : 0;
|
fcf |= (mSecurityLevel != kSecurityNone) ? kFcfSecurityEnabled : 0;
|
||||||
@@ -917,6 +893,33 @@ exit:
|
|||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint16_t Frame::DetermineFcfAddrType(const Address &aAddress, uint16_t aBitShift)
|
||||||
|
{
|
||||||
|
// Determines the FCF address type for a given `aAddress`. The
|
||||||
|
// result will be bit-shifted using `aBitShift` value which
|
||||||
|
// correspond to whether address is the source or destination
|
||||||
|
// and whether the frame uses the general format or is a
|
||||||
|
// multipurpose frame
|
||||||
|
|
||||||
|
uint16_t fcfAddrType = kFcfAddrNone;
|
||||||
|
|
||||||
|
switch (aAddress.GetType())
|
||||||
|
{
|
||||||
|
case Address::kTypeNone:
|
||||||
|
break;
|
||||||
|
case Address::kTypeShort:
|
||||||
|
fcfAddrType = kFcfAddrShort;
|
||||||
|
break;
|
||||||
|
case Address::kTypeExtended:
|
||||||
|
fcfAddrType = kFcfAddrExt;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
fcfAddrType <<= aBitShift;
|
||||||
|
|
||||||
|
return fcfAddrType;
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t Frame::CalculateSecurityHeaderSize(uint8_t aSecurityControl)
|
uint8_t Frame::CalculateSecurityHeaderSize(uint8_t aSecurityControl)
|
||||||
{
|
{
|
||||||
uint8_t size = kSecurityControlSize + kFrameCounterSize;
|
uint8_t size = kSecurityControlSize + kFrameCounterSize;
|
||||||
@@ -1535,29 +1538,10 @@ Error TxFrame::GenerateWakeupFrame(PanId aPanId, const Address &aDest, const Add
|
|||||||
fcf = kTypeMultipurpose | kMpFcfLongFrame | kMpFcfPanidPresent | kMpFcfSecurityEnabled | kMpFcfSequenceSuppression |
|
fcf = kTypeMultipurpose | kMpFcfLongFrame | kMpFcfPanidPresent | kMpFcfSecurityEnabled | kMpFcfSequenceSuppression |
|
||||||
kMpFcfIePresent;
|
kMpFcfIePresent;
|
||||||
|
|
||||||
switch (aDest.GetType())
|
VerifyOrExit(!aDest.IsNone() && !aSource.IsNone(), error = kErrorInvalidArgs);
|
||||||
{
|
|
||||||
case Address::Type::kTypeShort:
|
|
||||||
fcf |= kMpFcfDstAddrShort;
|
|
||||||
break;
|
|
||||||
case Address::Type::kTypeExtended:
|
|
||||||
fcf |= kMpFcfDstAddrExt;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
ExitNow(error = kErrorInvalidArgs);
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (aSource.GetType())
|
fcf |= DetermineFcfAddrType(aDest, kMpFcfDstAddrShift);
|
||||||
{
|
fcf |= DetermineFcfAddrType(aSource, kMpFcfSrcAddrShift);
|
||||||
case Address::Type::kTypeShort:
|
|
||||||
fcf |= kMpFcfSrcAddrShort;
|
|
||||||
break;
|
|
||||||
case Address::Type::kTypeExtended:
|
|
||||||
fcf |= kMpFcfSrcAddrExt;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
ExitNow(error = kErrorInvalidArgs);
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.Init(mPsdu, GetMtu());
|
builder.Init(mPsdu, GetMtu());
|
||||||
|
|
||||||
|
|||||||
@@ -942,6 +942,8 @@ protected:
|
|||||||
static bool IsAckRequest(uint16_t aFcf) { return MaskFcf<kFcfAckRequest, kMpFcfAckRequest>(aFcf); }
|
static bool IsAckRequest(uint16_t aFcf) { return MaskFcf<kFcfAckRequest, kMpFcfAckRequest>(aFcf); }
|
||||||
static bool IsVersion2015(uint16_t aFcf) { return (aFcf & kFcfFrameVersionMask) == kVersion2015; }
|
static bool IsVersion2015(uint16_t aFcf) { return (aFcf & kFcfFrameVersionMask) == kVersion2015; }
|
||||||
|
|
||||||
|
static uint16_t DetermineFcfAddrType(const Address &aAddress, uint16_t aBitShift);
|
||||||
|
|
||||||
static uint8_t CalculateAddrFieldSize(uint16_t aFcf);
|
static uint8_t CalculateAddrFieldSize(uint16_t aFcf);
|
||||||
static uint8_t CalculateSecurityHeaderSize(uint8_t aSecurityControl);
|
static uint8_t CalculateSecurityHeaderSize(uint8_t aSecurityControl);
|
||||||
static uint8_t CalculateMicSize(uint8_t aSecurityControl);
|
static uint8_t CalculateMicSize(uint8_t aSecurityControl);
|
||||||
|
|||||||
Reference in New Issue
Block a user