diff --git a/src/inet/EndPointStateLwIP.h b/src/inet/EndPointStateLwIP.h index ffc1c18b14c5d1..d42f613931484e 100644 --- a/src/inet/EndPointStateLwIP.h +++ b/src/inet/EndPointStateLwIP.h @@ -32,23 +32,14 @@ struct tcp_pcb; namespace chip { namespace Inet { +/** + * Definitions shared by all LwIP EndPoint classes. + */ class DLL_EXPORT EndPointStateLwIP { protected: EndPointStateLwIP() : mLwIPEndPointType(LwIPEndPointType::Unknown) {} - /** Encapsulated LwIP protocol control block */ - union - { - const void * mVoid; /**< An untyped protocol control buffer reference */ -#if INET_CONFIG_ENABLE_UDP_ENDPOINT - udp_pcb * mUDP; /**< User datagram protocol (UDP) control */ -#endif // INET_CONFIG_ENABLE_UDP_ENDPOINT -#if INET_CONFIG_ENABLE_TCP_ENDPOINT - tcp_pcb * mTCP; /**< Transmission control protocol (TCP) control */ -#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT - }; - enum class LwIPEndPointType : uint8_t { Unknown = 0, diff --git a/src/inet/EndPointStateSockets.h b/src/inet/EndPointStateSockets.h index c83b3a106d689b..661c804ef82c7e 100644 --- a/src/inet/EndPointStateSockets.h +++ b/src/inet/EndPointStateSockets.h @@ -30,6 +30,9 @@ namespace chip { namespace Inet { +/** + * Definitions shared by all sockets-based EndPoint classes. + */ class DLL_EXPORT EndPointStateSockets { protected: diff --git a/src/inet/IANAConstants.h b/src/inet/IANAConstants.h index 05b3efa2b37640..4d9038da61b4bb 100644 --- a/src/inet/IANAConstants.h +++ b/src/inet/IANAConstants.h @@ -44,20 +44,6 @@ typedef enum #endif // INET_CONFIG_ENABLE_IPV4 } IPVersion; -/** - * @enum IPProtocol - * - * The numbers of some of the protocols in the IP family. - * - */ -typedef enum -{ - kIPProtocol_ICMPv6 = 58, /**< ICMPv6 */ -#if INET_CONFIG_ENABLE_IPV4 - kIPProtocol_ICMPv4 = 1, /**< ICMPv4 */ -#endif // INET_CONFIG_ENABLE_IPV4 -} IPProtocol; - /** * @brief Internet protocol multicast address scope * diff --git a/src/inet/InetConfig.h b/src/inet/InetConfig.h index 37793a174b3d82..2e69398afbb8ef 100644 --- a/src/inet/InetConfig.h +++ b/src/inet/InetConfig.h @@ -87,32 +87,6 @@ #define INET_CONFIG_MAX_IP_AND_UDP_HEADER_SIZE (40 + 8) #endif // INET_CONFIG_MAX_IP_AND_UDP_HEADER_SIZE -/** - * @def INET_CONFIG_WILL_OVERRIDE_OS_ERROR_FUNCS - * - * @brief - * This defines whether (1) or not (0) your platform will override - * the platform- and system-specific INET_MapOSError, - * INET_DescribeOSError, and INET_IsOSError functions. - * - */ -#ifndef INET_CONFIG_WILL_OVERRIDE_OS_ERROR_FUNCS -#define INET_CONFIG_WILL_OVERRIDE_OS_ERROR_FUNCS 0 -#endif // INET_CONFIG_WILL_OVERRIDE_OS_ERROR_FUNCS - -/** - * @def INET_CONFIG_WILL_OVERRIDE_LWIP_ERROR_FUNCS - * - * @brief - * This defines whether (1) or not (0) your platform will override - * the platform- and system-specific INET_MapLwIPError, - * INET_DescribeLwIPError, and INET_IsLwIPError functions. - * - */ -#ifndef INET_CONFIG_WILL_OVERRIDE_LWIP_ERROR_FUNCS -#define INET_CONFIG_WILL_OVERRIDE_LWIP_ERROR_FUNCS 0 -#endif // INET_CONFIG_WILL_OVERRIDE_LWIP_ERROR_FUNCS - /** * @def INET_CONFIG_NUM_TCP_ENDPOINTS * @@ -177,32 +151,6 @@ #define INET_CONFIG_ENABLE_UDP_ENDPOINT 0 #endif // INET_CONFIG_ENABLE_UDP_ENDPOINT -/** - * @def INET_CONFIG_EVENT_RESERVED - * - * @brief - * This defines the first number in the default chip System Layer event code space reserved for use by the Inet Layer. - * Event codes used by each layer must not overlap. - */ -#ifndef INET_CONFIG_EVENT_RESERVED -#define INET_CONFIG_EVENT_RESERVED 1000 -#endif /* INET_CONFIG_EVENT_RESERVED */ - -/** - * @def _INET_CONFIG_EVENT - * - * @brief - * This defines a mapping function for InetLayer event types that allows - * mapping such event types into a platform- or system-specific range. - * - * @note - * By default, this definition is a copy of _CHIP_SYSTEM_CONFIG_LWIP_EVENT. - * - */ -#ifndef _INET_CONFIG_EVENT -#define _INET_CONFIG_EVENT(e) _CHIP_SYSTEM_CONFIG_LWIP_EVENT(INET_CONFIG_EVENT_RESERVED + (e)) -#endif // _INET_CONFIG_EVENT - /** * @def INET_CONFIG_TEST * diff --git a/src/inet/InetError.h b/src/inet/InetError.h index af5ec8c195fb49..33b845731c0da3 100644 --- a/src/inet/InetError.h +++ b/src/inet/InetError.h @@ -23,9 +23,6 @@ * Error types, ranges, and mappings overrides may be made by * defining the appropriate INET_CONFIG_* or _INET_CONFIG_* * macros. - * - * NOTE WELL: On some platforms, this header is included by C-language programs. - * */ #pragma once diff --git a/src/inet/InetLayer.h b/src/inet/InetLayer.h index 6e5bde9a1cad85..4da18d1c0b706e 100644 --- a/src/inet/InetLayer.h +++ b/src/inet/InetLayer.h @@ -39,8 +39,8 @@ namespace Inet { * Template providing traits for EndPoint types used by EndPointManager. * * Instances must define: - * static constexpr const char * Name; - * static constexpr int SystemStatsKey; + * static constexpr const char * kName; + * static constexpr int kSystemStatsKey; */ template struct EndPointProperties; @@ -56,12 +56,13 @@ class EndPointManager using EndPointVisitor = Loop (*)(EndPoint *); EndPointManager() {} - virtual ~EndPointManager() {} + virtual ~EndPointManager() { VerifyOrDie(mLayerState.Destroy()); } CHIP_ERROR Init(System::Layer & systemLayer) { RegisterLayerErrorFormatter(); VerifyOrReturnError(mLayerState.SetInitializing(), CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturnError(systemLayer.IsInitialized(), CHIP_ERROR_INCORRECT_STATE); mSystemLayer = &systemLayer; mLayerState.SetInitialized(); return CHIP_NO_ERROR; @@ -71,6 +72,7 @@ class EndPointManager { // Return to uninitialized state to permit re-initialization. VerifyOrReturnError(mLayerState.ResetFromInitialized(), CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturnError(mSystemLayer->IsInitialized(), CHIP_ERROR_INCORRECT_STATE); mSystemLayer = nullptr; return CHIP_NO_ERROR; } @@ -85,17 +87,17 @@ class EndPointManager *retEndPoint = CreateEndPoint(); if (*retEndPoint == nullptr) { - ChipLogError(Inet, "%s endpoint pool FULL", EndPointProperties::Name); + ChipLogError(Inet, "%s endpoint pool FULL", EndPointProperties::kName); return CHIP_ERROR_ENDPOINT_POOL_FULL; } - SYSTEM_STATS_INCREMENT(EndPointProperties::SystemStatsKey); + SYSTEM_STATS_INCREMENT(EndPointProperties::kSystemStatsKey); return CHIP_NO_ERROR; } void DeleteEndPoint(EndPoint * endPoint) { - SYSTEM_STATS_DECREMENT(EndPointProperties::SystemStatsKey); + SYSTEM_STATS_DECREMENT(EndPointProperties::kSystemStatsKey); ReleaseEndPoint(endPoint); } @@ -108,7 +110,7 @@ class EndPointManager System::Layer * mSystemLayer; }; -template +template class EndPointManagerImplPool : public EndPointManager { public: @@ -126,7 +128,7 @@ class EndPointManagerImplPool : public EndPointManager sEndPointPool; + ObjectPool::kNumEndPoints> sEndPointPool; }; class TCPEndPoint; diff --git a/src/inet/TCPEndPoint.h b/src/inet/TCPEndPoint.h index 503a2bba9a08dc..4f1b479a2760c8 100644 --- a/src/inet/TCPEndPoint.h +++ b/src/inet/TCPEndPoint.h @@ -691,8 +691,9 @@ class DLL_EXPORT TCPEndPoint : public EndPointBasis template <> struct EndPointProperties { - static constexpr const char * Name = "TCP"; - static constexpr int SystemStatsKey = System::Stats::kInetLayer_NumTCPEps; + static constexpr const char * kName = "TCP"; + static constexpr size_t kNumEndPoints = INET_CONFIG_NUM_TCP_ENDPOINTS; + static constexpr int kSystemStatsKey = System::Stats::kInetLayer_NumTCPEps; }; } // namespace Inet diff --git a/src/inet/TCPEndPointImpl.h b/src/inet/TCPEndPointImpl.h index 43c69bd48bca38..a6fa7c09319817 100644 --- a/src/inet/TCPEndPointImpl.h +++ b/src/inet/TCPEndPointImpl.h @@ -34,7 +34,7 @@ namespace chip { namespace Inet { -using TCPEndPointManagerImpl = EndPointManagerImplPool; +using TCPEndPointManagerImpl = EndPointManagerImplPool; } // namespace Inet } // namespace chip diff --git a/src/inet/TCPEndPointImplLwIP.h b/src/inet/TCPEndPointImplLwIP.h index 36a995b0cfd699..b680f86b3b64e5 100644 --- a/src/inet/TCPEndPointImplLwIP.h +++ b/src/inet/TCPEndPointImplLwIP.h @@ -40,7 +40,9 @@ namespace Inet { class TCPEndPointImplLwIP : public TCPEndPoint, public EndPointStateLwIP { public: - TCPEndPointImplLwIP(EndPointManager & endPointManager) : TCPEndPoint(endPointManager), mUnackedLength(0) {} + TCPEndPointImplLwIP(EndPointManager & endPointManager) : + TCPEndPoint(endPointManager), mUnackedLength(0), mTCP(nullptr) + {} // TCPEndPoint overrides. CHIP_ERROR GetPeerInfo(IPAddress * retAddr, uint16_t * retPort) const override; @@ -79,6 +81,7 @@ class TCPEndPointImplLwIP : public TCPEndPoint, public EndPointStateLwIP uint16_t mUnackedLength; // Amount sent but awaiting ACK. Used as a form of reference count // to hang-on to backing packet buffers until they are no longer needed. + tcp_pcb * mTCP; // LwIP Transmission control protocol (TCP) control block. uint16_t RemainingToSend(); BufferOffset FindStartOfUnsent(); diff --git a/src/inet/UDPEndPoint.h b/src/inet/UDPEndPoint.h index f18720a63288ee..005dccf26eb8b5 100644 --- a/src/inet/UDPEndPoint.h +++ b/src/inet/UDPEndPoint.h @@ -292,8 +292,9 @@ class DLL_EXPORT UDPEndPoint : public EndPointBasis template <> struct EndPointProperties { - static constexpr const char * Name = "UDP"; - static constexpr int SystemStatsKey = System::Stats::kInetLayer_NumUDPEps; + static constexpr const char * kName = "UDP"; + static constexpr size_t kNumEndPoints = INET_CONFIG_NUM_UDP_ENDPOINTS; + static constexpr int kSystemStatsKey = System::Stats::kInetLayer_NumUDPEps; }; } // namespace Inet diff --git a/src/inet/UDPEndPointImpl.h b/src/inet/UDPEndPointImpl.h index 6abf72c5d73257..037c652089cfbe 100644 --- a/src/inet/UDPEndPointImpl.h +++ b/src/inet/UDPEndPointImpl.h @@ -34,7 +34,7 @@ namespace chip { namespace Inet { -using UDPEndPointManagerImpl = EndPointManagerImplPool; +using UDPEndPointManagerImpl = EndPointManagerImplPool; } // namespace Inet } // namespace chip diff --git a/src/inet/UDPEndPointImplLwIP.h b/src/inet/UDPEndPointImplLwIP.h index 7319526c8affdd..473c5fa2180ab2 100644 --- a/src/inet/UDPEndPointImplLwIP.h +++ b/src/inet/UDPEndPointImplLwIP.h @@ -32,7 +32,7 @@ namespace Inet { class UDPEndPointImplLwIP : public UDPEndPoint, public EndPointStateLwIP { public: - UDPEndPointImplLwIP(EndPointManager & endPointManager) : UDPEndPoint(endPointManager) {} + UDPEndPointImplLwIP(EndPointManager & endPointManager) : UDPEndPoint(endPointManager), mUDP(nullptr) {} // UDPEndPoint overrides. CHIP_ERROR SetMulticastLoopback(IPVersion aIPVersion, bool aLoopback) override; @@ -84,6 +84,8 @@ class UDPEndPointImplLwIP : public UDPEndPoint, public EndPointStateLwIP #else // LWIP_VERSION_MAJOR <= 1 && LWIP_VERSION_MINOR < 5 static void LwIPReceiveUDPMessage(void * arg, struct udp_pcb * pcb, struct pbuf * p, ip_addr_t * addr, u16_t port); #endif // LWIP_VERSION_MAJOR > 1 || LWIP_VERSION_MINOR >= 5 + + udp_pcb * mUDP; // LwIP User datagram protocol (UDP) control block. }; using UDPEndPointImpl = UDPEndPointImplLwIP; diff --git a/src/lib/dnssd/minimal_mdns/tests/TestAdvertiser.cpp b/src/lib/dnssd/minimal_mdns/tests/TestAdvertiser.cpp index 68364226a6ece1..e9bc9fd1ea4661 100644 --- a/src/lib/dnssd/minimal_mdns/tests/TestAdvertiser.cpp +++ b/src/lib/dnssd/minimal_mdns/tests/TestAdvertiser.cpp @@ -558,6 +558,7 @@ int TestAdvertiser(void) mdnsAdvertiser.Init(context.GetUDPEndPointManager()); nlTestRunner(&theSuite, &server); server.Shutdown(); + context.Shutdown(); return nlTestRunnerStats(&theSuite); } diff --git a/src/messaging/tests/echo/common.cpp b/src/messaging/tests/echo/common.cpp index d1f7c4df8ac7e5..77d867df075c68 100644 --- a/src/messaging/tests/echo/common.cpp +++ b/src/messaging/tests/echo/common.cpp @@ -65,5 +65,6 @@ void ShutdownChip(void) gMessageCounterManager.Shutdown(); gExchangeManager.Shutdown(); gSessionManager.Shutdown(); + (void) chip::DeviceLayer::TCPEndPointManager()->Shutdown(); chip::DeviceLayer::PlatformMgr().Shutdown(); } diff --git a/src/system/SystemLayer.h b/src/system/SystemLayer.h index c8fb4d5e28e19e..9731dd1bbfcd26 100644 --- a/src/system/SystemLayer.h +++ b/src/system/SystemLayer.h @@ -33,7 +33,6 @@ #include #include #include -#include #include #include #include diff --git a/src/system/SystemLayerImplLwIP.h b/src/system/SystemLayerImplLwIP.h index e3ee1d5f885182..e59e45094fcf16 100644 --- a/src/system/SystemLayerImplLwIP.h +++ b/src/system/SystemLayerImplLwIP.h @@ -33,7 +33,7 @@ class LayerImplLwIP : public LayerLwIP { public: LayerImplLwIP(); - ~LayerImplLwIP() = default; + ~LayerImplLwIP() { VerifyOrDie(mLayerState.Destroy()); } // Layer overrides. CHIP_ERROR Init() override; diff --git a/src/system/SystemLayerImplSelect.h b/src/system/SystemLayerImplSelect.h index 65d852cd7e4629..9211971ea1c28a 100644 --- a/src/system/SystemLayerImplSelect.h +++ b/src/system/SystemLayerImplSelect.h @@ -40,8 +40,8 @@ namespace System { class LayerImplSelect : public LayerSocketsLoop { public: - LayerImplSelect() = default; - ~LayerImplSelect() = default; + LayerImplSelect() = default; + ~LayerImplSelect() { VerifyOrDie(mLayerState.Destroy()); } // Layer overrides. CHIP_ERROR Init() override;