mirror of
https://github.com/espressif/openthread.git
synced 2026-08-14 14:47:46 +00:00
[mac] decouple mac frame from ip6 address (#2039)
This commit is contained in:
@@ -40,17 +40,10 @@
|
||||
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/debug.hpp"
|
||||
#include "net/ip6_address.hpp"
|
||||
|
||||
namespace ot {
|
||||
namespace Mac {
|
||||
|
||||
void ExtAddress::Set(const Ip6::Address &aIpAddress)
|
||||
{
|
||||
memcpy(m8, aIpAddress.GetIid(), sizeof(m8));
|
||||
m8[0] ^= 0x02;
|
||||
}
|
||||
|
||||
const char *Address::ToString(char *aBuf, uint16_t aSize) const
|
||||
{
|
||||
switch (mLength)
|
||||
|
||||
@@ -131,14 +131,6 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method converts an IPv6 Interface Identifier to an IEEE 802.15.4 Extended Address.
|
||||
*
|
||||
* @param[in] aIpAddress A reference to the IPv6 address.
|
||||
*
|
||||
*/
|
||||
void Set(const Ip6::Address &aIpAddress);
|
||||
|
||||
private:
|
||||
enum
|
||||
{
|
||||
|
||||
@@ -159,6 +159,12 @@ void Address::SetIid(const Mac::ExtAddress &aEui64)
|
||||
mFields.m8[kInterfaceIdentifierOffset] ^= 0x02;
|
||||
}
|
||||
|
||||
void Address::ToExtAddress(Mac::ExtAddress &aExtAddress) const
|
||||
{
|
||||
memcpy(aExtAddress.m8, mFields.m8 + kInterfaceIdentifierOffset, sizeof(aExtAddress.m8));
|
||||
aExtAddress.m8[0] ^= 0x02;
|
||||
}
|
||||
|
||||
uint8_t Address::GetScope(void) const
|
||||
{
|
||||
if (IsMulticast())
|
||||
|
||||
@@ -279,6 +279,14 @@ public:
|
||||
*/
|
||||
void SetIid(const Mac::ExtAddress &aEui64);
|
||||
|
||||
/**
|
||||
* This method converts the IPv6 Interface Identifier to an IEEE 802.15.4 Extended Address.
|
||||
*
|
||||
* @param[out] aExtAddress A reference to the extended address.
|
||||
*
|
||||
*/
|
||||
void ToExtAddress(Mac::ExtAddress &aExtAddress) const;
|
||||
|
||||
/**
|
||||
* This method returns the IPv6 address scope.
|
||||
*
|
||||
|
||||
@@ -954,7 +954,7 @@ otError MeshForwarder::GetMacSourceAddress(const Ip6::Address &aIp6Addr, Mac::Ad
|
||||
ThreadNetif &netif = GetNetif();
|
||||
|
||||
aMacAddr.mLength = sizeof(aMacAddr.mExtAddress);
|
||||
aMacAddr.mExtAddress.Set(aIp6Addr);
|
||||
aIp6Addr.ToExtAddress(aMacAddr.mExtAddress);
|
||||
|
||||
if (memcmp(&aMacAddr.mExtAddress, netif.GetMac().GetExtAddress(), sizeof(aMacAddr.mExtAddress)) != 0)
|
||||
{
|
||||
@@ -991,7 +991,7 @@ otError MeshForwarder::GetMacDestinationAddress(const Ip6::Address &aIp6Addr, Ma
|
||||
else
|
||||
{
|
||||
aMacAddr.mLength = sizeof(aMacAddr.mExtAddress);
|
||||
aMacAddr.mExtAddress.Set(aIp6Addr);
|
||||
aIp6Addr.ToExtAddress(aMacAddr.mExtAddress);
|
||||
}
|
||||
|
||||
return OT_ERROR_NONE;
|
||||
|
||||
@@ -2054,7 +2054,7 @@ void Mle::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessageIn
|
||||
VerifyOrExit(messageTagLength == sizeof(messageTag));
|
||||
SuccessOrExit(aMessage.SetLength(aMessage.GetLength() - sizeof(messageTag)));
|
||||
|
||||
macAddr.Set(aMessageInfo.GetPeerAddr());
|
||||
aMessageInfo.GetPeerAddr().ToExtAddress(macAddr);
|
||||
GenerateNonce(macAddr, frameCounter, Mac::Frame::kSecEncMic32, nonce);
|
||||
|
||||
aesCcm.SetKey(mleKey, 16);
|
||||
@@ -2261,7 +2261,7 @@ otError Mle::HandleAdvertisement(const Message &aMessage, const Ip6::MessageInfo
|
||||
SuccessOrExit(error = netif.GetMle().HandleAdvertisement(aMessage, aMessageInfo));
|
||||
}
|
||||
|
||||
macAddr.Set(aMessageInfo.GetPeerAddr());
|
||||
aMessageInfo.GetPeerAddr().ToExtAddress(macAddr);
|
||||
|
||||
isNeighbor = false;
|
||||
|
||||
@@ -2653,7 +2653,7 @@ otError Mle::HandleParentResponse(const Message &aMessage, const Ip6::MessageInf
|
||||
memcpy(mChildIdRequest.mChallenge, challenge.GetChallenge(), challenge.GetLength());
|
||||
mChildIdRequest.mChallengeLength = challenge.GetLength();
|
||||
|
||||
mParentCandidate.GetExtAddress().Set(aMessageInfo.GetPeerAddr());
|
||||
aMessageInfo.GetPeerAddr().ToExtAddress(mParentCandidate.GetExtAddress());
|
||||
mParentCandidate.SetRloc16(sourceAddress.GetRloc16());
|
||||
mParentCandidate.SetLinkFrameCounter(linkFrameCounter.GetFrameCounter());
|
||||
mParentCandidate.SetMleFrameCounter(mleFrameCounter.GetFrameCounter());
|
||||
@@ -3068,7 +3068,7 @@ otError Mle::HandleDiscoveryResponse(const Message &aMessage, const Ip6::Message
|
||||
result.mChannel = threadMessageInfo->mChannel;
|
||||
result.mRssi = threadMessageInfo->mRss;
|
||||
result.mLqi = threadMessageInfo->mLqi;
|
||||
static_cast<Mac::ExtAddress *>(&result.mExtAddress)->Set(aMessageInfo.GetPeerAddr());
|
||||
aMessageInfo.GetPeerAddr().ToExtAddress(*static_cast<Mac::ExtAddress *>(&result.mExtAddress));
|
||||
|
||||
// process MeshCoP TLVs
|
||||
while (offset < end)
|
||||
|
||||
@@ -676,7 +676,7 @@ otError MleRouter::HandleLinkRequest(const Message &aMessage, const Ip6::Message
|
||||
|
||||
VerifyOrExit(mParentRequestState == kParentIdle, error = OT_ERROR_INVALID_STATE);
|
||||
|
||||
macAddr.Set(aMessageInfo.GetPeerAddr());
|
||||
aMessageInfo.GetPeerAddr().ToExtAddress(macAddr);
|
||||
|
||||
// Challenge
|
||||
SuccessOrExit(error = Tlv::GetTlv(aMessage, Tlv::kChallenge, sizeof(challenge), challenge));
|
||||
@@ -880,7 +880,7 @@ otError MleRouter::HandleLinkAccept(const Message &aMessage, const Ip6::MessageI
|
||||
ChallengeTlv challenge;
|
||||
TlvRequestTlv tlvRequest;
|
||||
|
||||
macAddr.Set(aMessageInfo.GetPeerAddr());
|
||||
aMessageInfo.GetPeerAddr().ToExtAddress(macAddr);
|
||||
|
||||
// Version
|
||||
SuccessOrExit(error = Tlv::GetTlv(aMessage, Tlv::kVersion, sizeof(version), version));
|
||||
@@ -1270,7 +1270,7 @@ otError MleRouter::HandleAdvertisement(const Message &aMessage, const Ip6::Messa
|
||||
uint8_t routerId;
|
||||
uint8_t routerCount;
|
||||
|
||||
macAddr.Set(aMessageInfo.GetPeerAddr());
|
||||
aMessageInfo.GetPeerAddr().ToExtAddress(macAddr);
|
||||
|
||||
// Source Address
|
||||
SuccessOrExit(error = Tlv::GetTlv(aMessage, Tlv::kSourceAddress, sizeof(sourceAddress), sourceAddress));
|
||||
@@ -1661,7 +1661,7 @@ otError MleRouter::HandleParentRequest(const Message &aMessage, const Ip6::Messa
|
||||
(mRouters[GetLeaderId()].GetCost() + GetLinkCost(mRouters[GetLeaderId()].GetNextHop()) < kMaxRouteCost),
|
||||
error = OT_ERROR_DROP);
|
||||
|
||||
macAddr.Set(aMessageInfo.GetPeerAddr());
|
||||
aMessageInfo.GetPeerAddr().ToExtAddress(macAddr);
|
||||
|
||||
// Version
|
||||
SuccessOrExit(error = Tlv::GetTlv(aMessage, Tlv::kVersion, sizeof(version), version));
|
||||
@@ -2049,7 +2049,7 @@ otError MleRouter::HandleChildIdRequest(const Message &aMessage, const Ip6::Mess
|
||||
VerifyOrExit(mRole >= OT_DEVICE_ROLE_CHILD, error = OT_ERROR_INVALID_STATE);
|
||||
|
||||
// Find Child
|
||||
macAddr.Set(aMessageInfo.GetPeerAddr());
|
||||
aMessageInfo.GetPeerAddr().ToExtAddress(macAddr);
|
||||
|
||||
VerifyOrExit((child = FindChild(macAddr)) != NULL, error = OT_ERROR_ALREADY);
|
||||
|
||||
@@ -2226,7 +2226,7 @@ otError MleRouter::HandleChildUpdateRequest(const Message &aMessage, const Ip6::
|
||||
VerifyOrExit(mode.IsValid(), error = OT_ERROR_PARSE);
|
||||
|
||||
// Find Child
|
||||
macAddr.Set(aMessageInfo.GetPeerAddr());
|
||||
aMessageInfo.GetPeerAddr().ToExtAddress(macAddr);
|
||||
child = FindChild(macAddr);
|
||||
|
||||
tlvs[tlvslength++] = Tlv::kSourceAddress;
|
||||
@@ -2333,7 +2333,7 @@ otError MleRouter::HandleChildUpdateResponse(const Message &aMessage, const Ip6:
|
||||
otLogInfoMle(GetInstance(), "Received Child Update Response from child");
|
||||
|
||||
// Find Child
|
||||
macAddr.Set(aMessageInfo.GetPeerAddr());
|
||||
aMessageInfo.GetPeerAddr().ToExtAddress(macAddr);
|
||||
|
||||
VerifyOrExit((child = FindChild(macAddr)) != NULL, error = OT_ERROR_NOT_FOUND);
|
||||
|
||||
@@ -3275,7 +3275,7 @@ Neighbor *MleRouter::GetNeighbor(const Ip6::Address &aAddress)
|
||||
else
|
||||
{
|
||||
macaddr.mLength = sizeof(macaddr.mExtAddress);
|
||||
macaddr.mExtAddress.Set(aAddress);
|
||||
aAddress.ToExtAddress(macaddr.mExtAddress);
|
||||
}
|
||||
|
||||
ExitNow(rval = GetNeighbor(macaddr));
|
||||
|
||||
Reference in New Issue
Block a user