Skip to content

Commit

Permalink
Apply PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jepenven-silabs committed Jan 4, 2022
1 parent 1e5714a commit ae78315
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 12 deletions.
1 change: 1 addition & 0 deletions examples/lighting-app/efr32/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions src/app/server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
,
Expand All @@ -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);
Expand Down
8 changes: 7 additions & 1 deletion src/inet/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
17 changes: 13 additions & 4 deletions src/inet/UDPEndPointImplOT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,34 @@ void UDPEndPointImplOT::handleUdpReceive(void * aContext, otMessage * aMessage,
{
UDPEndPointImplOT * ep = static_cast<UDPEndPointImplOT *>(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);

Expand All @@ -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));
Expand Down
2 changes: 0 additions & 2 deletions src/platform/EFR32/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
4 changes: 2 additions & 2 deletions src/transport/raw/UDP.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -94,7 +94,7 @@ class UdpListenParameters
private:
otInstance * mOtInstance = nullptr;

#endif
#endif // CHIP_SYSTEM_CONFIG_USE_OT_UDP
};

/** Implements a transport using UDP. */
Expand Down

0 comments on commit ae78315

Please sign in to comment.