diff --git a/script/check-posix-pty b/script/check-posix-pty index 5e64783a2..68b57eb9d 100755 --- a/script/check-posix-pty +++ b/script/check-posix-pty @@ -129,6 +129,12 @@ send "ipaddr\r\n" expect "Done" send "coex\r\n" expect "Done" +send "coap start\r\n" +expect "Done" +send "coap resource TestResource\r\n" +expect "Done" +send "coap set TestContent\r\n" +expect "Done" wait EOF @@ -142,7 +148,7 @@ EOF fi done - netstat -an | grep -q 61631 || die 'TMF port is not available!' + netstat -an | grep -q 5683 || die 'Application CoAP port is not available!' extaddr=$(grep -aoE '[0-9a-z]{16}' $OT_OUTPUT) echo "Extended address is: ${extaddr}" @@ -157,15 +163,15 @@ EOF fi LEADER_ALOC=fdde:ad00:beef::ff:fe00:fc00 - # Retrievie extended address through network diagnostic get - coap_response=$(echo -n '120100' | xxd -r -p | coap-client -m POST coap://[${LEADER_ALOC}]:61631/d/dg -f- | xxd -p | grep 0008) + # Retrievie test resource through application CoAP + coap_response=$(coap-client -B 5 -m GET coap://[${LEADER_ALOC}]:5683/TestResource) echo "CoAP response is: ${coap_response}" - # Verify CoAP response contains the extended address - if [[ ${coap_response} == *${extaddr}* ]]; then + # Verify CoAP response contains the test content + if [[ ${coap_response} == *TestContent* ]]; then echo 'Success' else - die 'Failed to get extended address' + die 'Failed to access application CoAP' fi } diff --git a/src/core/net/ip6.cpp b/src/core/net/ip6.cpp index 93da2099f..053c78300 100644 --- a/src/core/net/ip6.cpp +++ b/src/core/net/ip6.cpp @@ -1004,13 +1004,11 @@ otError Ip6::ProcessReceiveCallback(Message & aMessage, if (mIsReceiveIp6FilterEnabled) { // do not pass messages sent to an RLOC/ALOC, except Service Locator -#if !OPENTHREAD_CONFIG_PLATFORM_NETIF_ENABLE bool isLocator = Get().IsMeshLocalAddress(aMessageInfo.GetSockAddr()) && aMessageInfo.GetSockAddr().GetIid().IsLocator(); VerifyOrExit(!isLocator || aMessageInfo.GetSockAddr().GetIid().IsAnycastServiceLocator(), error = OT_ERROR_NO_ROUTE); -#endif switch (aIpProto) { @@ -1041,13 +1039,11 @@ otError Ip6::ProcessReceiveCallback(Message & aMessage, // do not pass MLE messages ExitNow(error = OT_ERROR_NO_ROUTE); } -#if !OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE else if ((destPort == Tmf::kUdpPort) && Get().IsTmfMessage(aMessageInfo)) { // do not pass TMF messages ExitNow(error = OT_ERROR_NO_ROUTE); } -#endif #if OPENTHREAD_FTD if (destPort == Get().GetJoinerUdpPort()) diff --git a/src/core/net/udp6.cpp b/src/core/net/udp6.cpp index 4c579a2bb..af2f9624c 100644 --- a/src/core/net/udp6.cpp +++ b/src/core/net/udp6.cpp @@ -242,7 +242,7 @@ otError Udp::Bind(SocketHandle &aSocket, const SockAddr &aSockAddr) } while (error != OT_ERROR_NONE); } #if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE - else if (!IsMlePort(aSocket.mSockName.mPort)) + else if (ShouldUsePlatformUdp(aSocket)) { error = otPlatUdpBind(&aSocket); } @@ -275,10 +275,26 @@ void Udp::SetBackboneSocket(SocketHandle &aSocket) } } -const Udp::SocketHandle *Udp::GetBackboneSockets(void) +const Udp::SocketHandle *Udp::GetBackboneSockets(void) const { return mPrevBackboneSockets != nullptr ? mPrevBackboneSockets->GetNext() : mSockets.GetHead(); } + +bool Udp::IsBackboneSocket(const SocketHandle &aSocket) const +{ + bool retval = false; + + for (const SocketHandle *sock = GetBackboneSockets(); sock != nullptr; sock = sock->GetNext()) + { + if (sock == &aSocket) + { + ExitNow(retval = true); + } + } + +exit: + return retval; +} #endif otError Udp::Connect(SocketHandle &aSocket, const SockAddr &aSockAddr) @@ -293,7 +309,7 @@ otError Udp::Connect(SocketHandle &aSocket, const SockAddr &aSockAddr) } #if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE - if (!IsMlePort(aSocket.mSockName.mPort)) + if (ShouldUsePlatformUdp(aSocket)) { error = otPlatUdpConnect(&aSocket); } @@ -356,8 +372,7 @@ otError Udp::SendTo(SocketHandle &aSocket, Message &aMessage, const MessageInfo messageInfoLocal.SetSockPort(aSocket.GetSockName().mPort); #if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE - if (!IsMlePort(aSocket.mSockName.mPort) && - !(aSocket.mSockName.mPort == Tmf::kUdpPort && aMessage.GetSubType() == Message::kSubTypeJoinerEntrust)) + if (ShouldUsePlatformUdp(aSocket)) { // Replace anycast address with a valid unicast address since response messages typically copy the peer address if (Get().IsAnycastLocator(messageInfoLocal.GetSockAddr())) @@ -483,7 +498,7 @@ otError Udp::HandleMessage(Message &aMessage, MessageInfo &aMessageInfo) aMessageInfo.mSockPort = udpHeader.GetDestinationPort(); #if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE - VerifyOrExit(IsMlePort(aMessageInfo.mSockPort)); + VerifyOrExit(!ShouldUsePlatformUdp(aMessageInfo.mSockPort)); #endif for (Receiver *receiver = mReceivers.GetHead(); receiver; receiver = receiver->GetNext()) @@ -533,16 +548,25 @@ exit: return; } -bool Udp::IsMlePort(uint16_t aPort) const +#if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE +bool Udp::ShouldUsePlatformUdp(uint16_t aPort) const { - bool isMlePort = (aPort == Mle::kUdpPort); - + return (aPort != Mle::kUdpPort && aPort != Tmf::kUdpPort #if OPENTHREAD_FTD - isMlePort = isMlePort || (aPort == Get().GetJoinerUdpPort()); + && aPort != Get().GetJoinerUdpPort() #endif - - return isMlePort; + ); } +bool Udp::ShouldUsePlatformUdp(const Udp::SocketHandle &aSocket) const +{ + return (ShouldUsePlatformUdp(aSocket.mSockName.mPort) +#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE + || IsBackboneSocket(aSocket) +#endif + ); +} +#endif + } // namespace Ip6 } // namespace ot diff --git a/src/core/net/udp6.hpp b/src/core/net/udp6.hpp index 37cf6ff79..cd201aecf 100644 --- a/src/core/net/udp6.hpp +++ b/src/core/net/udp6.hpp @@ -595,11 +595,15 @@ private: void AddSocket(SocketHandle &aSocket); void RemoveSocket(SocketHandle &aSocket); - bool IsMlePort(uint16_t aPort) const; +#if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE + bool ShouldUsePlatformUdp(uint16_t aPort) const; + bool ShouldUsePlatformUdp(const SocketHandle &aSocket) const; +#endif #if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE void SetBackboneSocket(SocketHandle &aSocket); - const SocketHandle *GetBackboneSockets(void); + const SocketHandle *GetBackboneSockets(void) const; + bool IsBackboneSocket(const SocketHandle &aSocket) const; #endif uint16_t mEphemeralPort;