[mac] decouple mac frame from ip6 address (#2039)

This commit is contained in:
Buke Po
2017-07-28 18:40:00 -07:00
committed by Jonathan Hui
parent a61e98ea0f
commit d009e77cd3
7 changed files with 28 additions and 29 deletions
-7
View File
@@ -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)
-8
View File
@@ -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
{
+6
View File
@@ -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())
+8
View File
@@ -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.
*
+2 -2
View File
@@ -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;
+4 -4
View File
@@ -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)
+8 -8
View File
@@ -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));