From 6d470c2fb11a5b7220b622f412fefae6385d4c53 Mon Sep 17 00:00:00 2001 From: Jonathan Hui Date: Mon, 5 Jun 2017 12:31:54 -0700 Subject: [PATCH] Full End Devices should initiate mesh-under forwarding. (#1870) --- src/core/thread/mesh_forwarder.cpp | 48 ++++++++++++++++-------------- src/core/thread/mle.hpp | 11 +++++++ 2 files changed, 36 insertions(+), 23 deletions(-) diff --git a/src/core/thread/mesh_forwarder.cpp b/src/core/thread/mesh_forwarder.cpp index ba09a3840..34a6b4ce8 100644 --- a/src/core/thread/mesh_forwarder.cpp +++ b/src/core/thread/mesh_forwarder.cpp @@ -696,37 +696,39 @@ otError MeshForwarder::UpdateIp6Route(Message &aMessage) break; case OT_DEVICE_ROLE_CHILD: - if (aMessage.IsLinkSecurityEnabled()) + case OT_DEVICE_ROLE_ROUTER: + case OT_DEVICE_ROLE_LEADER: + if (mNetif.GetMle().IsMinimalEndDevice()) { - mMacDest.mLength = sizeof(mMacDest.mShortAddress); - - if (ip6Header.GetDestination().IsLinkLocalMulticast()) + if (aMessage.IsLinkSecurityEnabled()) { - mMacDest.mShortAddress = Mac::kShortAddrBroadcast; + mMacDest.mLength = sizeof(mMacDest.mShortAddress); + + if (ip6Header.GetDestination().IsLinkLocalMulticast()) + { + mMacDest.mShortAddress = Mac::kShortAddrBroadcast; + } + else + { + mMacDest.mShortAddress = mNetif.GetMle().GetNextHop(Mac::kShortAddrBroadcast); + } + + GetMacSourceAddress(ip6Header.GetSource(), mMacSource); + } + else if (ip6Header.GetDestination().IsLinkLocal() || ip6Header.GetDestination().IsLinkLocalMulticast()) + { + GetMacDestinationAddress(ip6Header.GetDestination(), mMacDest); + GetMacSourceAddress(ip6Header.GetSource(), mMacSource); } else { - mMacDest.mShortAddress = mNetif.GetMle().GetNextHop(Mac::kShortAddrBroadcast); + ExitNow(error = OT_ERROR_DROP); } - - GetMacSourceAddress(ip6Header.GetSource(), mMacSource); } - else if (ip6Header.GetDestination().IsLinkLocal() || ip6Header.GetDestination().IsLinkLocalMulticast()) - { - GetMacDestinationAddress(ip6Header.GetDestination(), mMacDest); - GetMacSourceAddress(ip6Header.GetSource(), mMacSource); - } - else - { - ExitNow(error = OT_ERROR_DROP); - } - - break; #if OPENTHREAD_FTD + else { - case OT_DEVICE_ROLE_ROUTER: - case OT_DEVICE_ROLE_LEADER: uint16_t rloc16; uint16_t aloc16; Neighbor *neighbor; @@ -827,10 +829,10 @@ otError MeshForwarder::UpdateIp6Route(Message &aMessage) mAddMeshHeader = true; } } - - break; } + #endif // OPENTHREAD_FTD + break; default: break; diff --git a/src/core/thread/mle.hpp b/src/core/thread/mle.hpp index ac586df89..3be370370 100644 --- a/src/core/thread/mle.hpp +++ b/src/core/thread/mle.hpp @@ -623,6 +623,17 @@ public: */ uint8_t GetDeviceMode(void) const { return mDeviceMode; } + /** + * This method indicates whether or not the device is a Minimal End Device. + * + * @returns TRUE if the device is a Minimal End Device, FALSE otherwise. + * + */ + bool IsMinimalEndDevice(void) const { + return (mDeviceMode & (ModeTlv::kModeFFD | ModeTlv::kModeRxOnWhenIdle)) != + (ModeTlv::kModeFFD | ModeTlv::kModeRxOnWhenIdle); + } + /** * This method sets the Device Mode as reported in the Mode TLV. *