Skip to content

Commit

Permalink
Apply comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jepenven-silabs committed Jan 10, 2022
1 parent 68656a2 commit 268aaf4
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 49 deletions.
2 changes: 1 addition & 1 deletion examples/lighting-app/efr32/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +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
chip_system_config_use_open_thread_udp = true
1 change: 1 addition & 0 deletions examples/platform/efr32/project_include/OpenThreadConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
#define OPENTHREAD_CONFIG_DHCP6_SERVER_ENABLE 0
#define OPENTHREAD_CONFIG_TCP_ENABLE 0

// Support udp multicast by enabling Multicast Listener Registration (MRL)
#define OPENTHREAD_CONFIG_MLR_ENABLE 1

// Use the SiLabs-supplied default platform configuration for remainder
Expand Down
6 changes: 3 additions & 3 deletions src/app/server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ CHIP_ERROR Server::Init(AppDelegate * delegate, uint16_t secureServicePort, uint
err = mTransports.Init(UdpListenParameters(DeviceLayer::UDPEndPointManager())
.SetAddressType(IPAddressType::kIPv6)
.SetListenPort(mSecuredServicePort)
#if CHIP_SYSTEM_CONFIG_USE_OT_UDP
.SetOtInstance(chip::DeviceLayer::ThreadStackMgrImpl().OTInstance())
#endif // CHIP_SYSTEM_CONFIG_USE_OT_UDP
#if CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_UDP
.SetNativeParams(chip::DeviceLayer::ThreadStackMgrImpl().OTInstance())
#endif // CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_UDP

#if INET_CONFIG_ENABLE_IPV4
,
Expand Down
17 changes: 9 additions & 8 deletions src/inet/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import("${chip_root}/src/lwip/lwip.gni")
import("${chip_root}/src/platform/device.gni")
import("inet.gni")

if (chip_system_config_use_ot_udp) {
if (chip_system_config_use_open_thread_udp) {
import("//build_overrides/openthread.gni")
}

Expand Down Expand Up @@ -55,9 +55,10 @@ buildconfig_header("inet_buildconfig") {
}

defines += [ "INET_TCP_END_POINT_IMPL_CONFIG_FILE=<inet/TCPEndPointImpl${chip_system_config_inet}.h>" ]
if (chip_system_config_use_ot_udp) {
defines +=
[ "INET_UDP_END_POINT_IMPL_CONFIG_FILE=<inet/UDPEndPointImplOT.h>" ]
if (chip_system_config_use_open_thread_udp) {
defines += [
"INET_UDP_END_POINT_IMPL_CONFIG_FILE=<inet/UDPEndPointImpl_OpenThread.h>",
]
} else {
defines += [ "INET_UDP_END_POINT_IMPL_CONFIG_FILE=<inet/UDPEndPointImpl${chip_system_config_inet}.h>" ]
}
Expand Down Expand Up @@ -112,7 +113,7 @@ static_library("inet") {
public_deps += [ "${chip_root}/src/lwip" ]
}

if (chip_system_config_use_ot_udp) {
if (chip_system_config_use_open_thread_udp) {
if (chip_openthread_ftd) {
public_deps +=
[ "${chip_root}/third_party/openthread/repo:libopenthread-ftd" ]
Expand All @@ -139,10 +140,10 @@ static_library("inet") {
"UDPEndPointImpl.h",
]

if (chip_system_config_use_ot_udp) {
if (chip_system_config_use_open_thread_udp) {
sources += [
"UDPEndPointImplOT.cpp",
"UDPEndPointImplOT.h",
"UDPEndPointImpl_OpenThread.cpp",
"UDPEndPointImpl_OpenThread.h",
]
} else {
sources += [
Expand Down
2 changes: 1 addition & 1 deletion src/inet/UDPEndPoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ class DLL_EXPORT UDPEndPoint : public EndPointBasis<UDPEndPoint>
*/
virtual void Free() = 0;

virtual inline void SetOtInstance(otInstance * instance) { (void) instance; }
virtual inline void SetNativeParams(void * params) { (void) params; }

protected:
UDPEndPoint(EndPointManager<UDPEndPoint> & endPointManager) :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,13 @@
* limitations under the License.
*/

/**
* This file implements Inet::UDPEndPoint using OpenThread.
*/

#include <inet/UDPEndPointImplOT.h>
#include <inet/UDPEndPointImpl_OpenThread.h>

#include <lib/support/CodeUtils.h>
#include <lib/support/SafeInt.h>
#include <lib/support/logging/CHIPLogging.h>

#include <platform/OpenThread/OpenThreadUtils.h>
//#include <include/platform/ThreadStackManager.h>

#include <system/SystemPacketBuffer.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
* limitations under the License.
*/

/**
* This file declares an implementation of Inet::UDPEndPoint using sockets.
*/

#pragma once

#include <inet/UDPEndPoint.h>
Expand All @@ -47,7 +43,7 @@ class UDPEndPointImplOT : public UDPEndPoint
uint16_t GetBoundPort() const override;
void Free() override;
void HandleDataReceived(System::PacketBufferHandle && msg);
inline void SetOtInstance(otInstance * instance) { mOTInstance = instance; }
inline void SetNativeParams(otInstance * params) { mOTInstance = static_cast<otInstance *>(params); }
CHIP_ERROR SetMulticastLoopback(IPVersion aIPVersion, bool aLoopback) override;
CHIP_ERROR BindInterfaceImpl(IPAddressType addressType, InterfaceId interfaceId) override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ void GenericThreadStackManagerImpl_OpenThread_LwIP<ImplClass>::UpdateThreadInter

// Multicast won't work with LWIP on top of OT
// Duplication of listeners, unecessary timers, buffer duplication, hardfault etc...
#if CHIP_SYSTEM_CONFIG_USE_OT_UDP
#if CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_UDP
// Refresh Multicast listening
if (GenericThreadStackManagerImpl_OpenThread<ImplClass>::IsThreadAttachedNoLock())
{
Expand Down Expand Up @@ -262,7 +262,7 @@ void GenericThreadStackManagerImpl_OpenThread_LwIP<ImplClass>::UpdateThreadInter
}
}
}
#endif // CHIP_SYSTEM_CONFIG_USE_OT_UDP
#endif // CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_UDP
}

ChipLogDetail(DeviceLayer, "LwIP Thread interface addresses %s", isInterfaceUp ? "updated" : "cleared");
Expand Down
2 changes: 1 addition & 1 deletion src/system/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ buildconfig_header("system_buildconfig") {
"CHIP_WITH_NLFAULTINJECTION=${chip_with_nlfaultinjection}",
"CHIP_SYSTEM_CONFIG_USE_DISPATCH=${chip_system_config_use_dispatch}",
"CHIP_SYSTEM_CONFIG_USE_LWIP=${chip_system_config_use_lwip}",
"CHIP_SYSTEM_CONFIG_USE_OT_UDP=${chip_system_config_use_ot_udp}",
"CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_UDP=${chip_system_config_use_open_thread_udp}",
"CHIP_SYSTEM_CONFIG_USE_SOCKETS=${chip_system_config_use_sockets}",
"CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK=false",
"CHIP_SYSTEM_CONFIG_POSIX_LOCKING=${chip_system_config_posix_locking}",
Expand Down
8 changes: 6 additions & 2 deletions src/system/SystemPacketBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -847,8 +847,10 @@ namespace Inet {
class UDPEndPointImplLwIP;
} // namespace Inet

#if CHIP_SYSTEM_CONFIG_USE_OT_UDP
#if CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_UDP
// TODO : Temp Implementation issue : 13085
// Still use LwIP buffer even if using OpenThread UDP implementation
// since decoupling of LwIP from OpenThread is still in progress
namespace Inet {
class UDPEndPointImplOT;
} // namespace Inet
Expand All @@ -871,8 +873,10 @@ class LwIPPacketBufferView : public PacketBufferHandle
*/
static struct pbuf * UnsafeGetLwIPpbuf(const PacketBufferHandle & handle) { return PacketBufferHandle::GetLwIPpbuf(handle); }
friend class Inet::UDPEndPointImplLwIP;
#if CHIP_SYSTEM_CONFIG_USE_OT_UDP
#if CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_UDP
// TODO : Temp Implementation issue : 13085
// Still use LwIP buffer even if using OpenThread UDP implementation
// since decoupling of LwIP from OpenThread is still in progress
friend class Inet::UDPEndPointImplOT;
#endif
};
Expand Down
2 changes: 1 addition & 1 deletion src/system/system.gni
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ declare_args() {
chip_system_config_provide_statistics = true

# Use OpenThread UDP stack directly
chip_system_config_use_ot_udp = false
chip_system_config_use_open_thread_udp = false
}

declare_args() {
Expand Down
4 changes: 1 addition & 3 deletions src/transport/raw/UDP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ CHIP_ERROR UDP::Init(UdpListenParameters & params)
err = params.GetEndPointManager()->NewEndPoint(&mUDPEndPoint);
SuccessOrExit(err);

#if CHIP_SYSTEM_CONFIG_USE_OT_UDP
mUDPEndPoint->SetOtInstance(params.GetOtInstance());
#endif // CHIP_SYSTEM_CONFIG_USE_OT_UDP
mUDPEndPoint->SetNativeParams(params.GetNativeParams());

ChipLogDetail(Inet, "UDP::Init bind&listen port=%d", params.GetListenPort());

Expand Down
26 changes: 10 additions & 16 deletions src/transport/raw/UDP.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
#include <lib/core/CHIPCore.h>
#include <transport/raw/Base.h>

#if CHIP_SYSTEM_CONFIG_USE_OT_UDP
#if CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_UDP
struct otInstance;
#endif // CHIP_SYSTEM_CONFIG_USE_OT_UDP
#endif // CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_UDP

namespace chip {
namespace Transport {
Expand Down Expand Up @@ -75,26 +75,20 @@ class UdpListenParameters
return *this;
}

private:
Inet::EndPointManager<Inet::UDPEndPoint> * mEndPointManager; ///< Associated endpoint factory
Inet::IPAddressType mAddressType = Inet::IPAddressType::kIPv6; ///< type of listening socket
uint16_t mListenPort = CHIP_PORT; ///< UDP listen port
Inet::InterfaceId mInterfaceId = Inet::InterfaceId::Null(); ///< Interface to listen on

#if CHIP_SYSTEM_CONFIG_USE_OT_UDP
public:
otInstance * GetOtInstance() const { return mOtInstance; }
UdpListenParameters & SetOtInstance(otInstance * instance)
void * GetNativeParams() const { return mNativeParams; }
UdpListenParameters & SetNativeParams(void * params)
{
mOtInstance = instance;
mNativeParams = params;

return *this;
}

private:
otInstance * mOtInstance = nullptr;

#endif // CHIP_SYSTEM_CONFIG_USE_OT_UDP
Inet::EndPointManager<Inet::UDPEndPoint> * mEndPointManager; ///< Associated endpoint factory
Inet::IPAddressType mAddressType = Inet::IPAddressType::kIPv6; ///< type of listening socket
uint16_t mListenPort = CHIP_PORT; ///< UDP listen port
Inet::InterfaceId mInterfaceId = Inet::InterfaceId::Null(); ///< Interface to listen on
void * mNativeParams = nullptr;
};

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

0 comments on commit 268aaf4

Please sign in to comment.