From ae78315c059dac01d2c48e06fb99f59f15d00406 Mon Sep 17 00:00:00 2001 From: jepenven-silabs Date: Mon, 3 Jan 2022 13:37:15 -0500 Subject: [PATCH] Apply PR comments --- examples/lighting-app/efr32/args.gni | 1 + src/app/server/Server.cpp | 6 +++--- src/inet/BUILD.gn | 8 +++++++- src/inet/UDPEndPointImplOT.cpp | 17 +++++++++++++---- src/platform/EFR32/args.gni | 2 -- src/transport/raw/UDP.h | 4 ++-- 6 files changed, 26 insertions(+), 12 deletions(-) diff --git a/examples/lighting-app/efr32/args.gni b/examples/lighting-app/efr32/args.gni index 1b73ad66dcea58..d3853c338ba61e 100644 --- a/examples/lighting-app/efr32/args.gni +++ b/examples/lighting-app/efr32/args.gni @@ -22,3 +22,4 @@ pw_log_BACKEND = "${chip_root}/src/lib/support/pw_log_chip" pw_assert_BACKEND = "$dir_pw_assert_log" chip_enable_openthread = true chip_openthread_ftd = true +chip_system_config_use_ot_udp = true diff --git a/src/app/server/Server.cpp b/src/app/server/Server.cpp index 353b300c973d0d..e30c2f2851b98b 100644 --- a/src/app/server/Server.cpp +++ b/src/app/server/Server.cpp @@ -129,7 +129,7 @@ CHIP_ERROR Server::Init(AppDelegate * delegate, uint16_t secureServicePort, uint .SetListenPort(mSecuredServicePort) #if CHIP_SYSTEM_CONFIG_USE_OT_UDP .SetOtInstance(chip::DeviceLayer::ThreadStackMgrImpl().OTInstance()) -#endif +#endif // CHIP_SYSTEM_CONFIG_USE_OT_UDP #if INET_CONFIG_ENABLE_IPV4 , @@ -152,10 +152,10 @@ CHIP_ERROR Server::Init(AppDelegate * delegate, uint16_t secureServicePort, uint // TODO : Fix this once GroupDataProvider is implemented #Issue 11075 // for (iterate through all GroupDataProvider multicast Address) // { -#ifdef CHIP_ENABLE_GROUP_MESSAGING_TESTS +//#ifdef CHIP_ENABLE_GROUP_MESSAGING_TESTS err = mTransports.MulticastGroupJoinLeave(Transport::PeerAddress::Multicast(1, 1234), true); SuccessOrExit(err); -#endif +//#endif //} err = mSessions.Init(&DeviceLayer::SystemLayer(), &mTransports, &mMessageCounterManager); diff --git a/src/inet/BUILD.gn b/src/inet/BUILD.gn index 52265b09d7a2d8..709b2c39a7e9f5 100644 --- a/src/inet/BUILD.gn +++ b/src/inet/BUILD.gn @@ -113,7 +113,13 @@ static_library("inet") { } if (chip_system_config_use_ot_udp) { - public_deps += [ "${openthread_root}:libopenthread-ftd" ] + if (chip_openthread_ftd) { + public_deps += + [ "${chip_root}/third_party/openthread/repo:libopenthread-ftd" ] + } else { + public_deps += + [ "${chip_root}/third_party/openthread/repo:libopenthread-mtd" ] + } } if (chip_inet_config_enable_tcp_endpoint) { diff --git a/src/inet/UDPEndPointImplOT.cpp b/src/inet/UDPEndPointImplOT.cpp index e1e6b156846e4d..7634523fe65224 100644 --- a/src/inet/UDPEndPointImplOT.cpp +++ b/src/inet/UDPEndPointImplOT.cpp @@ -39,28 +39,34 @@ void UDPEndPointImplOT::handleUdpReceive(void * aContext, otMessage * aMessage, { UDPEndPointImplOT * ep = static_cast(aContext); IPPacketInfo pktInfo; - static uint16_t msgReceivedCount = 0; - uint16_t msgLen = otMessageGetLength(aMessage); + uint16_t msgLen = otMessageGetLength(aMessage); System::PacketBufferHandle payload; +#if CHIP_DETAIL_LOGGING + static uint16_t msgReceivedCount = 0; char sourceStr[Inet::IPAddress::kMaxStringLength]; char destStr[Inet::IPAddress::kMaxStringLength]; +#endif if (msgLen > System::PacketBuffer::kMaxSizeWithoutReserve) { + ChipLogError(Inet, "UDP message too long, discarding. Size received %d", msgLen); return; } - payload = System::PacketBufferHandle::New(msgLen, 0); - pktInfo.SrcAddress = chip::DeviceLayer::Internal::ToIPAddress(aMessageInfo->mPeerAddr); pktInfo.DestAddress = chip::DeviceLayer::Internal::ToIPAddress(aMessageInfo->mSockAddr); pktInfo.SrcPort = aMessageInfo->mPeerPort; pktInfo.DestPort = aMessageInfo->mSockPort; + payload = System::PacketBufferHandle::New(msgLen, 0); + if (payload.IsNull()) { + ChipLogError(Inet, "Failed to allocate a System buffer of size %d for UDP Message reception.", msgLen); return; } + +#if CHIP_DETAIL_LOGGING pktInfo.SrcAddress.ToString(sourceStr, Inet::IPAddress::kMaxStringLength); pktInfo.DestAddress.ToString(destStr, Inet::IPAddress::kMaxStringLength); @@ -69,10 +75,13 @@ void UDPEndPointImplOT::handleUdpReceive(void * aContext, otMessage * aMessage, ": %s\r\nDest Port %d\r\nPayload Length %d", ++msgReceivedCount, sourceStr, pktInfo.SrcPort, destStr, pktInfo.DestPort, msgLen); +#endif + memcpy(payload->Start(), &pktInfo, sizeof(IPPacketInfo)); if (otMessageRead(aMessage, 0, payload->Start() + sizeof(IPPacketInfo), msgLen) != msgLen) { + ChipLogError(Inet, "Failed to copy OpenThread buffer into System Packet buffer"); return; } payload->SetDataLength(msgLen + sizeof(IPPacketInfo)); diff --git a/src/platform/EFR32/args.gni b/src/platform/EFR32/args.gni index 85a985c07c4192..73e2fc12c4be01 100644 --- a/src/platform/EFR32/args.gni +++ b/src/platform/EFR32/args.gni @@ -32,8 +32,6 @@ lwip_platform = "efr32" chip_inet_config_enable_ipv4 = false -chip_system_config_use_ot_udp = true - chip_build_tests = false openthread_core_config_platform_check_file = diff --git a/src/transport/raw/UDP.h b/src/transport/raw/UDP.h index a7adc31f8635ca..ab4f1b4de85ffa 100644 --- a/src/transport/raw/UDP.h +++ b/src/transport/raw/UDP.h @@ -36,7 +36,7 @@ #if CHIP_SYSTEM_CONFIG_USE_OT_UDP struct otInstance; -#endif +#endif // CHIP_SYSTEM_CONFIG_USE_OT_UDP namespace chip { namespace Transport { @@ -94,7 +94,7 @@ class UdpListenParameters private: otInstance * mOtInstance = nullptr; -#endif +#endif // CHIP_SYSTEM_CONFIG_USE_OT_UDP }; /** Implements a transport using UDP. */