diff --git a/src/inet/IPAddress-StringFuncts.cpp b/src/inet/IPAddress-StringFuncts.cpp index 3db3f53fc31f2c..773034dbd289dc 100644 --- a/src/inet/IPAddress-StringFuncts.cpp +++ b/src/inet/IPAddress-StringFuncts.cpp @@ -46,13 +46,8 @@ char * IPAddress::ToString(char * buf, uint32_t bufSize) const #if INET_CONFIG_ENABLE_IPV4 if (IsIPv4()) { -#if LWIP_VERSION_MAJOR > 1 || LWIP_VERSION_MINOR >= 5 ip4_addr_t ip4_addr = ToIPv4(); ip4addr_ntoa_r(&ip4_addr, buf, (int) bufSize); -#else // LWIP_VERSION_MAJOR <= 1 - ip_addr_t ip4_addr = ToIPv4(); - ipaddr_ntoa_r(&ip4_addr, buf, (int) bufSize); -#endif // LWIP_VERSION_MAJOR <= 1 } else #endif // INET_CONFIG_ENABLE_IPV4 @@ -93,15 +88,9 @@ bool IPAddress::FromString(const char * str, IPAddress & output) if (strchr(str, ':') == nullptr) { #if CHIP_SYSTEM_CONFIG_USE_LWIP -#if LWIP_VERSION_MAJOR > 1 || LWIP_VERSION_MINOR >= 5 ip4_addr_t ipv4Addr; if (!ip4addr_aton(str, &ipv4Addr)) return false; -#else // LWIP_VERSION_MAJOR <= 1 - ip_addr_t ipv4Addr; - if (!ipaddr_aton(str, &ipv4Addr)) - return false; -#endif // LWIP_VERSION_MAJOR <= 1 #else // !CHIP_SYSTEM_CONFIG_USE_LWIP struct in_addr ipv4Addr; if (inet_pton(AF_INET, str, &ipv4Addr) < 1) diff --git a/src/inet/IPAddress.cpp b/src/inet/IPAddress.cpp index cbc1c8d4b08f74..74ef40144ec102 100644 --- a/src/inet/IPAddress.cpp +++ b/src/inet/IPAddress.cpp @@ -119,7 +119,6 @@ ip4_addr_t IPAddress::ToIPv4() const #endif // INET_CONFIG_ENABLE_IPV4 -#if LWIP_VERSION_MAJOR > 1 || LWIP_VERSION_MINOR >= 5 ip_addr_t IPAddress::ToLwIPAddr(void) const { ip_addr_t ret; @@ -173,7 +172,6 @@ lwip_ip_addr_type IPAddress::ToLwIPAddrType(IPAddressType typ) return ret; } -#endif // LWIP_VERSION_MAJOR > 1 || LWIP_VERSION_MINOR >= 5 ip6_addr_t IPAddress::ToIPv6() const { diff --git a/src/inet/IPAddress.h b/src/inet/IPAddress.h index a688efb543ab29..ab326463ce4399 100644 --- a/src/inet/IPAddress.h +++ b/src/inet/IPAddress.h @@ -61,24 +61,6 @@ #define NL_INET_IPV6_ADDR_LEN_IN_BYTES (16) #define NL_INET_IPV6_MCAST_GROUP_LEN_IN_BYTES (14) -/** - * @brief Adaptation for LwIP ip4_addr_t type. - * - * @details - * Before LwIP 2.0.0, the \c ip_addr_t type alias referred to a structure comprising - * an IPv4 address. At LwIP 2.0.0 and thereafter, this type alias is renamed \c ip4_addr_t - * and \c ip_addr_t is replaced with an alias to a union of both. Here, the \c ip4_addr_t - * type alias is provided even when the LwIP version is earlier than 2.0.0 so as to prepare - * for the import of the new logic. - */ -#if CHIP_SYSTEM_CONFIG_USE_LWIP && INET_CONFIG_ENABLE_IPV4 && LWIP_VERSION_MAJOR < 2 && LWIP_VERSION_MINOR < 5 -typedef ip_addr_t ip4_addr_t; -#endif // CHIP_SYSTEM_CONFIG_USE_LWIP && INET_CONFIG_ENABLE_IPV4 && LWIP_VERSION_MAJOR < 2 && LWIP_VERSION_MINOR < 5 - -#if CHIP_SYSTEM_CONFIG_USE_LWIP && LWIP_VERSION_MAJOR == 1 && LWIP_VERSION_MINOR >= 5 -typedef u8_t lwip_ip_addr_type; -#endif // CHIP_SYSTEM_CONFIG_USE_LWIP && LWIP_VERSION_MAJOR == 1 && LWIP_VERSION_MINOR >= 5 - namespace chip { namespace Inet { @@ -489,7 +471,6 @@ class DLL_EXPORT IPAddress #if CHIP_SYSTEM_CONFIG_USE_LWIP -#if LWIP_VERSION_MAJOR > 1 || LWIP_VERSION_MINOR >= 5 /** * @fn ToLwIPAddr() const * @@ -508,10 +489,9 @@ class DLL_EXPORT IPAddress * * @details * Use ToLwIPAddrType(IPAddressType) to convert the IP address type - * to its underlying LwIP address type code. (LWIP_VERSION_MAJOR > 1 only). + * to its underlying LwIP address type code. */ static lwip_ip_addr_type ToLwIPAddrType(IPAddressType); -#endif // LWIP_VERSION_MAJOR > 1 || LWIP_VERSION_MINOR >= 5 ip6_addr_t ToIPv6(void) const; diff --git a/src/inet/InetInterface.cpp b/src/inet/InetInterface.cpp index 637ae2ee789e15..1ce272d4b60a45 100644 --- a/src/inet/InetInterface.cpp +++ b/src/inet/InetInterface.cpp @@ -96,7 +96,7 @@ CHIP_ERROR InterfaceId::InterfaceNameToId(const char * intfName, InterfaceId & i return INET_ERROR_UNKNOWN_INTERFACE; } struct netif * intf; -#if LWIP_VERSION_MAJOR >= 2 && LWIP_VERSION_MINOR >= 0 && defined(NETIF_FOREACH) +#if defined(NETIF_FOREACH) NETIF_FOREACH(intf) #else for (intf = netif_list; intf != NULL; intf = intf->next) @@ -120,7 +120,7 @@ bool InterfaceIterator::Next() // Verify the previous netif is still on the list if netifs. If so, // advance to the next nextif. struct netif * prevNetif = mCurNetif; -#if LWIP_VERSION_MAJOR >= 2 && LWIP_VERSION_MINOR >= 0 && defined(NETIF_FOREACH) +#if defined(NETIF_FOREACH) NETIF_FOREACH(mCurNetif) #else for (mCurNetif = netif_list; mCurNetif != NULL; mCurNetif = mCurNetif->next) @@ -152,12 +152,7 @@ bool InterfaceIterator::IsUp() bool InterfaceIterator::SupportsMulticast() { - return HasCurrent() && -#if LWIP_VERSION_MAJOR > 1 || LWIP_VERSION_MINOR >= 5 - (mCurNetif->flags & (NETIF_FLAG_IGMP | NETIF_FLAG_MLD6 | NETIF_FLAG_BROADCAST)) != 0; -#else - (mCurNetif->flags & NETIF_FLAG_POINTTOPOINT) == 0; -#endif // LWIP_VERSION_MAJOR > 1 || LWIP_VERSION_MINOR >= 5 + return HasCurrent() && (mCurNetif->flags & (NETIF_FLAG_IGMP | NETIF_FLAG_MLD6 | NETIF_FLAG_BROADCAST)) != 0; } bool InterfaceIterator::HasBroadcastAddress() diff --git a/src/inet/TCPEndPointImplLwIP.cpp b/src/inet/TCPEndPointImplLwIP.cpp index 4be562848e17fb..88cb6fc0c55b34 100644 --- a/src/inet/TCPEndPointImplLwIP.cpp +++ b/src/inet/TCPEndPointImplLwIP.cpp @@ -74,8 +74,6 @@ CHIP_ERROR TCPEndPointImplLwIP::BindImpl(IPAddressType addrType, const IPAddress ip_set_option(mTCP, SOF_REUSEADDR); } -#if LWIP_VERSION_MAJOR > 1 || LWIP_VERSION_MINOR >= 5 - ip_addr_t ipAddr; if (addr != IPAddress::Any) { @@ -94,25 +92,6 @@ CHIP_ERROR TCPEndPointImplLwIP::BindImpl(IPAddressType addrType, const IPAddress else res = INET_ERROR_WRONG_ADDRESS_TYPE; res = chip::System::MapErrorLwIP(tcp_bind(mTCP, &ipAddr, port)); - -#else // LWIP_VERSION_MAJOR <= 1 || LWIP_VERSION_MINOR >= 5 - - if (addrType == IPAddressType::kIPv6) - { - ip6_addr_t ipv6Addr = addr.ToIPv6(); - res = chip::System::MapErrorLwIP(tcp_bind_ip6(mTCP, &ipv6Addr, port)); - } -#if INET_CONFIG_ENABLE_IPV4 - else if (addrType == IPAddressType::kIPv4) - { - ip_addr_t ipv4Addr = addr.ToIPv4(); - res = chip::System::MapErrorLwIP(tcp_bind(mTCP, &ipv4Addr, port)); - } -#endif // INET_CONFIG_ENABLE_IPV4 - else - res = INET_ERROR_WRONG_ADDRESS_TYPE; - -#endif // LWIP_VERSION_MAJOR <= 1 || LWIP_VERSION_MINOR >= 5 } // Unlock LwIP stack @@ -168,25 +147,8 @@ CHIP_ERROR TCPEndPointImplLwIP::ConnectImpl(const IPAddress & addr, uint16_t por tcp_arg(mTCP, this); tcp_err(mTCP, LwIPHandleError); -#if LWIP_VERSION_MAJOR > 1 || LWIP_VERSION_MINOR >= 5 ip_addr_t lwipAddr = addr.ToLwIPAddr(); res = chip::System::MapErrorLwIP(tcp_connect(mTCP, &lwipAddr, port, LwIPHandleConnectComplete)); -#else // LWIP_VERSION_MAJOR <= 1 || LWIP_VERSION_MINOR >= 5 - if (addrType == IPAddressType::kIPv6) - { - ip6_addr_t lwipAddr = addr.ToIPv6(); - res = chip::System::MapErrorLwIP(tcp_connect_ip6(mTCP, &lwipAddr, port, LwIPHandleConnectComplete)); - } -#if INET_CONFIG_ENABLE_IPV4 - else if (addrType == IPAddressType::kIPv4) - { - ip_addr_t lwipAddr = addr.ToIPv4(); - res = chip::System::MapErrorLwIP(tcp_connect(mTCP, &lwipAddr, port, LwIPHandleConnectComplete)); - } -#endif // INET_CONFIG_ENABLE_IPV4 - else - res = INET_ERROR_WRONG_ADDRESS_TYPE; -#endif // LWIP_VERSION_MAJOR <= 1 || LWIP_VERSION_MINOR >= 5 // Ensure that TCP timers are started if (res == CHIP_NO_ERROR) @@ -221,17 +183,8 @@ CHIP_ERROR TCPEndPointImplLwIP::GetPeerInfo(IPAddress * retAddr, uint16_t * retP if (mTCP != nullptr) { *retPort = mTCP->remote_port; - -#if LWIP_VERSION_MAJOR > 1 || LWIP_VERSION_MINOR >= 5 *retAddr = IPAddress(mTCP->remote_ip); -#else // LWIP_VERSION_MAJOR <= 1 || LWIP_VERSION_MINOR >= 5 -#if INET_CONFIG_ENABLE_IPV4 - *retAddr = PCB_ISIPV6(mTCP) ? IPAddress(mTCP->remote_ip.ip6) : IPAddress(mTCP->remote_ip.ip4); -#else // !INET_CONFIG_ENABLE_IPV4 - *retAddr = IPAddress(mTCP->remote_ip.ip6); -#endif // !INET_CONFIG_ENABLE_IPV4 -#endif // LWIP_VERSION_MAJOR <= 1 || LWIP_VERSION_MINOR >= 5 - res = CHIP_NO_ERROR; + res = CHIP_NO_ERROR; } // Unlock LwIP stack @@ -251,17 +204,8 @@ CHIP_ERROR TCPEndPointImplLwIP::GetLocalInfo(IPAddress * retAddr, uint16_t * ret if (mTCP != nullptr) { *retPort = mTCP->local_port; - -#if LWIP_VERSION_MAJOR > 1 || LWIP_VERSION_MINOR >= 5 *retAddr = IPAddress(mTCP->local_ip); -#else // LWIP_VERSION_MAJOR <= 1 || LWIP_VERSION_MINOR >= 5 -#if INET_CONFIG_ENABLE_IPV4 - *retAddr = PCB_ISIPV6(mTCP) ? IPAddress(mTCP->local_ip.ip6) : IPAddress(mTCP->local_ip.ip4); -#else // !INET_CONFIG_ENABLE_IPV4 - *retAddr = IPAddress(mTCP->local_ip.ip6); -#endif // !INET_CONFIG_ENABLE_IPV4 -#endif // LWIP_VERSION_MAJOR <= 1 || LWIP_VERSION_MINOR >= 5 - res = CHIP_NO_ERROR; + res = CHIP_NO_ERROR; } // Unlock LwIP stack @@ -656,8 +600,6 @@ TCPEndPointImplLwIP::BufferOffset TCPEndPointImplLwIP::FindStartOfUnsent() CHIP_ERROR TCPEndPointImplLwIP::GetPCB(IPAddressType addrType) { // IMMPORTANT: This method MUST be called with the LwIP stack LOCKED! - -#if LWIP_VERSION_MAJOR > 1 || LWIP_VERSION_MINOR >= 5 if (mTCP == NULL) { switch (addrType) @@ -705,37 +647,6 @@ CHIP_ERROR TCPEndPointImplLwIP::GetPCB(IPAddressType addrType) break; } } -#else // LWIP_VERSION_MAJOR <= 1 || LWIP_VERSION_MINOR >= 5 - if (mTCP == NULL) - { - if (addrType == IPAddressType::kIPv6) - mTCP = tcp_new_ip6(); -#if INET_CONFIG_ENABLE_IPV4 - else if (addrType == IPAddressType::kIPv4) - mTCP = tcp_new(); -#endif // INET_CONFIG_ENABLE_IPV4 - else - return INET_ERROR_WRONG_ADDRESS_TYPE; - if (mTCP == NULL) - { - return CHIP_ERROR_NO_MEMORY; - } - else - { - mLwIPEndPointType = LwIPEndPointType::TCP; - } - } - else - { -#if INET_CONFIG_ENABLE_IPV4 - const IPAddressType pcbType = PCB_ISIPV6(mTCP) ? IPAddressType::kIPv6 : IPAddressType::kIPv4; -#else // !INET_CONFIG_ENABLE_IPV4 - const IPAddressType pcbType = IPAddressType::kIPv6; -#endif // !INET_CONFIG_ENABLE_IPV4 - if (addrType != pcbType) - return INET_ERROR_WRONG_ADDRESS_TYPE; - } -#endif // LWIP_VERSION_MAJOR <= 1 || LWIP_VERSION_MINOR >= 5 return CHIP_NO_ERROR; } diff --git a/src/inet/UDPEndPointImplLwIP.cpp b/src/inet/UDPEndPointImplLwIP.cpp index 6231f9248c6c34..e5f74911bbd0a1 100644 --- a/src/inet/UDPEndPointImplLwIP.cpp +++ b/src/inet/UDPEndPointImplLwIP.cpp @@ -39,6 +39,8 @@ #include #include +static_assert(LWIP_VERSION_MAJOR > 1, "CHIP requires LwIP 2.0 or later"); + #if !defined(RAW_FLAGS_MULTICAST_LOOP) || !defined(UDP_FLAGS_MULTICAST_LOOP) || !defined(raw_clear_flags) || \ !defined(raw_set_flags) || !defined(udp_clear_flags) || !defined(udp_set_flags) #define HAVE_LWIP_MULTICAST_LOOP 0 @@ -72,7 +74,6 @@ CHIP_ERROR UDPEndPointImplLwIP::BindImpl(IPAddressType addressType, const IPAddr // Bind the PCB to the specified address/port. if (res == CHIP_NO_ERROR) { -#if LWIP_VERSION_MAJOR > 1 || LWIP_VERSION_MINOR >= 5 ip_addr_t ipAddr = address.ToLwIPAddr(); // TODO: IPAddress ANY has only one constant state, however addressType @@ -88,22 +89,6 @@ CHIP_ERROR UDPEndPointImplLwIP::BindImpl(IPAddressType addressType, const IPAddr } res = chip::System::MapErrorLwIP(udp_bind(mUDP, &ipAddr, port)); -#else // LWIP_VERSION_MAJOR <= 1 && LWIP_VERSION_MINOR < 5 - if (addressType == IPAddressType::kIPv6) - { - ip6_addr_t ipv6Addr = address.ToIPv6(); - res = chip::System::MapErrorLwIP(udp_bind_ip6(mUDP, &ipv6Addr, port)); - } -#if INET_CONFIG_ENABLE_IPV4 - else if (addressType == IPAddressType::kIPv4) - { - ip4_addr_t ipv4Addr = address.ToIPv4(); - res = chip::System::MapErrorLwIP(udp_bind(mUDP, &ipv4Addr, port)); - } -#endif // INET_CONFIG_ENABLE_IPV4 - else - res = INET_ERROR_WRONG_ADDRESS_TYPE; -#endif // LWIP_VERSION_MAJOR <= 1 || LWIP_VERSION_MINOR >= 5 } if (res == CHIP_NO_ERROR) @@ -172,18 +157,7 @@ CHIP_ERROR UDPEndPointImplLwIP::ListenImpl() // Lock LwIP stack LOCK_TCPIP_CORE(); -#if LWIP_VERSION_MAJOR > 1 || LWIP_VERSION_MINOR >= 5 udp_recv(mUDP, LwIPReceiveUDPMessage, this); -#else // LWIP_VERSION_MAJOR <= 1 && LWIP_VERSION_MINOR < 5 - if (PCB_ISIPV6(mUDP)) - { - udp_recv_ip6(mUDP, LwIPReceiveUDPMessage, this); - } - else - { - udp_recv(mUDP, LwIPReceiveUDPMessage, this); - } -#endif // LWIP_VERSION_MAJOR <= 1 || LWIP_VERSION_MINOR >= 5 // Unlock LwIP stack UNLOCK_TCPIP_CORE(); @@ -228,8 +202,6 @@ CHIP_ERROR UDPEndPointImplLwIP::SendMsgImpl(const IPPacketInfo * pktInfo, System const uint16_t & destPort = pktInfo->DestPort; const InterfaceId & intfId = pktInfo->Interface; -#if LWIP_VERSION_MAJOR > 1 || LWIP_VERSION_MINOR >= 5 - ip_addr_t lwipSrcAddr = srcAddr.ToLwIPAddr(); ip_addr_t lwipDestAddr = destAddr.ToLwIPAddr(); @@ -253,60 +225,6 @@ CHIP_ERROR UDPEndPointImplLwIP::SendMsgImpl(const IPPacketInfo * pktInfo, System ip_addr_copy(mUDP->local_ip, boundAddr); -#else // LWIP_VERSION_MAJOR <= 1 && LWIP_VERSION_MINOR < 5 - - ipX_addr_t boundAddr; - ipX_addr_copy(boundAddr, mUDP->local_ip); - - if (PCB_ISIPV6(mUDP)) - { - ip6_addr_t lwipSrcAddr = srcAddr.ToIPv6(); - ip6_addr_t lwipDestAddr = destAddr.ToIPv6(); - - if (!ip6_addr_isany(&lwipSrcAddr)) - { - ipX_addr_copy(mUDP->local_ip, *ip6_2_ipX(&lwipSrcAddr)); - } - - if (intfId.IsPresent()) - { - lwipErr = - udp_sendto_if_ip6(mUDP, System::LwIPPacketBufferView::UnsafeGetLwIPpbuf(msg), &lwipDestAddr, destPort, intfId); - } - else - { - lwipErr = udp_sendto_ip6(mUDP, System::LwIPPacketBufferView::UnsafeGetLwIPpbuf(msg), &lwipDestAddr, destPort); - } - } - -#if INET_CONFIG_ENABLE_IPV4 - - else - { - ip4_addr_t lwipSrcAddr = srcAddr.ToIPv4(); - ip4_addr_t lwipDestAddr = destAddr.ToIPv4(); - ipX_addr_t boundAddr; - - if (!ip_addr_isany(&lwipSrcAddr)) - { - ipX_addr_copy(mUDP->local_ip, *ip_2_ipX(&lwipSrcAddr)); - } - - if (intfId.IsPresent()) - { - lwipErr = udp_sendto_if(mUDP, System::LwIPPacketBufferView::UnsafeGetLwIPpbuf(msg), &lwipDestAddr, destPort, intfId); - } - else - { - lwipErr = udp_sendto(mUDP, System::LwIPPacketBufferView::UnsafeGetLwIPpbuf(msg), &lwipDestAddr, destPort); - } - } - - ipX_addr_copy(mUDP->local_ip, boundAddr); - -#endif // INET_CONFIG_ENABLE_IPV4 -#endif // LWIP_VERSION_MAJOR <= 1 || LWIP_VERSION_MINOR >= 5 - // Unlock LwIP stack UNLOCK_TCPIP_CORE(); @@ -375,20 +293,12 @@ CHIP_ERROR UDPEndPointImplLwIP::GetPCB(IPAddressType addrType) // Allocate a PCB of the appropriate type. if (addrType == IPAddressType::kIPv6) { -#if LWIP_VERSION_MAJOR > 1 || LWIP_VERSION_MINOR >= 5 mUDP = udp_new_ip_type(IPADDR_TYPE_V6); -#else // LWIP_VERSION_MAJOR <= 1 && LWIP_VERSION_MINOR < 5 - mUDP = udp_new_ip6(); -#endif // LWIP_VERSION_MAJOR <= 1 || LWIP_VERSION_MINOR >= 5 } #if INET_CONFIG_ENABLE_IPV4 else if (addrType == IPAddressType::kIPv4) { -#if LWIP_VERSION_MAJOR > 1 || LWIP_VERSION_MINOR >= 5 mUDP = udp_new_ip_type(IPADDR_TYPE_V4); -#else // LWIP_VERSION_MAJOR <= 1 && LWIP_VERSION_MINOR < 5 - mUDP = udp_new(); -#endif // LWIP_VERSION_MAJOR <= 1 || LWIP_VERSION_MINOR >= 5 } #endif // INET_CONFIG_ENABLE_IPV4 else @@ -413,7 +323,6 @@ CHIP_ERROR UDPEndPointImplLwIP::GetPCB(IPAddressType addrType) IPAddressType pcbAddrType; // Get the address type of the existing PCB. -#if LWIP_VERSION_MAJOR > 1 || LWIP_VERSION_MINOR >= 5 switch (static_cast(IP_GET_TYPE(&mUDP->local_ip))) { case IPADDR_TYPE_V6: @@ -427,13 +336,6 @@ CHIP_ERROR UDPEndPointImplLwIP::GetPCB(IPAddressType addrType) default: return INET_ERROR_WRONG_ADDRESS_TYPE; } -#else // LWIP_VERSION_MAJOR <= 1 && LWIP_VERSION_MINOR < 5 -#if INET_CONFIG_ENABLE_IPV4 - pcbAddrType = PCB_ISIPV6(mUDP) ? IPAddressType::kIPv6 : IPAddressType::kIPv4; -#else // !INET_CONFIG_ENABLE_IPV4 - pcbAddrType = IPAddressType::kIPv6; -#endif // !INET_CONFIG_ENABLE_IPV4 -#endif // LWIP_VERSION_MAJOR <= 1 && LWIP_VERSION_MINOR < 5 // Fail if the existing PCB is not the correct type. VerifyOrReturnError(addrType == pcbAddrType, INET_ERROR_WRONG_ADDRESS_TYPE); @@ -442,12 +344,8 @@ CHIP_ERROR UDPEndPointImplLwIP::GetPCB(IPAddressType addrType) return CHIP_NO_ERROR; } -#if LWIP_VERSION_MAJOR > 1 || LWIP_VERSION_MINOR >= 5 void UDPEndPointImplLwIP::LwIPReceiveUDPMessage(void * arg, struct udp_pcb * pcb, struct pbuf * p, const ip_addr_t * addr, u16_t port) -#else // LWIP_VERSION_MAJOR <= 1 && LWIP_VERSION_MINOR < 5 -void UDPEndPointImplLwIP::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 { UDPEndPointImplLwIP * ep = static_cast(arg); IPPacketInfo * pktInfo = nullptr; @@ -474,27 +372,11 @@ void UDPEndPointImplLwIP::LwIPReceiveUDPMessage(void * arg, struct udp_pcb * pcb pktInfo = GetPacketInfo(buf); if (pktInfo != nullptr) { -#if LWIP_VERSION_MAJOR > 1 || LWIP_VERSION_MINOR >= 5 pktInfo->SrcAddress = IPAddress(*addr); pktInfo->DestAddress = IPAddress(*ip_current_dest_addr()); -#else // LWIP_VERSION_MAJOR <= 1 - if (PCB_ISIPV6(pcb)) - { - pktInfo->SrcAddress = IPAddress(*(ip6_addr_t *) addr); - pktInfo->DestAddress = IPAddress(*ip6_current_dest_addr()); - } -#if INET_CONFIG_ENABLE_IPV4 - else - { - pktInfo->SrcAddress = IPAddress(*addr); - pktInfo->DestAddress = IPAddress(*ip_current_dest_addr()); - } -#endif // INET_CONFIG_ENABLE_IPV4 -#endif // LWIP_VERSION_MAJOR <= 1 - - pktInfo->Interface = InterfaceId(ip_current_netif()); - pktInfo->SrcPort = port; - pktInfo->DestPort = pcb->local_port; + pktInfo->Interface = InterfaceId(ip_current_netif()); + pktInfo->SrcPort = port; + pktInfo->DestPort = pcb->local_port; } ep->Retain(); @@ -579,7 +461,7 @@ struct netif * UDPEndPointImplLwIP::FindNetifFromInterfaceId(InterfaceId aInterf { struct netif * lRetval = nullptr; -#if LWIP_VERSION_MAJOR >= 2 && LWIP_VERSION_MINOR >= 0 && defined(NETIF_FOREACH) +#if defined(NETIF_FOREACH) NETIF_FOREACH(lRetval) { if (lRetval == aInterfaceId.GetPlatformInterface()) @@ -587,10 +469,10 @@ struct netif * UDPEndPointImplLwIP::FindNetifFromInterfaceId(InterfaceId aInterf break; } } -#else // LWIP_VERSION_MAJOR < 2 || !defined(NETIF_FOREACH) +#else // defined(NETIF_FOREACH) for (lRetval = netif_list; lRetval != nullptr && lRetval != aInterfaceId.GetPlatformInterface(); lRetval = lRetval->next) ; -#endif // LWIP_VERSION_MAJOR >= 2 && LWIP_VERSION_MINOR >= 0 && defined(NETIF_FOREACH) +#endif // defined(NETIF_FOREACH) return (lRetval); } diff --git a/src/inet/UDPEndPointImplLwIP.h b/src/inet/UDPEndPointImplLwIP.h index 473c5fa2180ab2..accb18bfcb7dbc 100644 --- a/src/inet/UDPEndPointImplLwIP.h +++ b/src/inet/UDPEndPointImplLwIP.h @@ -79,11 +79,7 @@ class UDPEndPointImplLwIP : public UDPEndPoint, public EndPointStateLwIP static IPPacketInfo * GetPacketInfo(const chip::System::PacketBufferHandle & aBuffer); CHIP_ERROR GetPCB(IPAddressType addrType4); -#if LWIP_VERSION_MAJOR > 1 || LWIP_VERSION_MINOR >= 5 static void LwIPReceiveUDPMessage(void * arg, struct udp_pcb * pcb, struct pbuf * p, const ip_addr_t * addr, u16_t port); -#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. }; diff --git a/src/inet/arpa-inet-compatibility.h b/src/inet/arpa-inet-compatibility.h index bd7cb1e7b4fb78..b5da1843f1b00c 100644 --- a/src/inet/arpa-inet-compatibility.h +++ b/src/inet/arpa-inet-compatibility.h @@ -25,18 +25,17 @@ #else // !CHIP_SYSTEM_CONFIG_USE_SOCKETS -// NOTE WELL: when LWIP_VERSION_MAJOR == 1, LWIP_PREFIX_BYTEORDER_FUNCS instead of LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS #if CHIP_SYSTEM_CONFIG_USE_LWIP #include #include -#if (defined(LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS) || defined(LWIP_PREFIX_BYTEORDER_FUNCS)) +#if defined(LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS) #define htons(x) lwip_htons(x) #define ntohs(x) lwip_ntohs(x) #define htonl(x) lwip_htonl(x) #define ntohl(x) lwip_ntohl(x) -#endif // (defined(LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS) || defined(LWIP_PREFIX_BYTEORDER_FUNCS)) +#endif // defined(LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS) #endif // CHIP_SYSTEM_CONFIG_USE_LWIP #endif // !CHIP_SYSTEM_CONFIG_USE_SOCKETS diff --git a/src/inet/tests/TestInetCommonPosix.cpp b/src/inet/tests/TestInetCommonPosix.cpp index 5da8e44d7253ee..86120482e8e55d 100644 --- a/src/inet/tests/TestInetCommonPosix.cpp +++ b/src/inet/tests/TestInetCommonPosix.cpp @@ -55,9 +55,9 @@ #if CHIP_SYSTEM_CONFIG_USE_LWIP #include -#if !(LWIP_VERSION_MAJOR >= 2 && LWIP_VERSION_MINOR >= 1) +#if (LWIP_VERSION_MAJOR == 2) && (LWIP_VERSION_MINOR == 0) #include -#endif // !(LWIP_VERSION_MAJOR >= 2 && LWIP_VERSION_MINOR >= 1) +#endif // (LWIP_VERSION_MAJOR == 2) && (LWIP_VERSION_MINOR == 0) #include #include #include @@ -97,7 +97,7 @@ static void AcquireLwIP(void) static void ReleaseLwIP(void) { -#if !(LWIP_VERSION_MAJOR >= 2 && LWIP_VERSION_MINOR >= 1) +#if (LWIP_VERSION_MAJOR == 2) && (LWIP_VERSION_MINOR == 0) if (sLwIPAcquireCount > 0 && --sLwIPAcquireCount == 0) { #if defined(INCLUDE_vTaskDelete) && INCLUDE_vTaskDelete @@ -107,7 +107,7 @@ static void ReleaseLwIP(void) tcpip_finish(NULL, NULL); #endif // defined(INCLUDE_vTaskDelete) && INCLUDE_vTaskDelete } -#endif +#endif // (LWIP_VERSION_MAJOR == 2) && (LWIP_VERSION_MINOR == 0) } #if CHIP_TARGET_STYLE_UNIX @@ -325,11 +325,7 @@ void InitNetwork() IPAddress ip4Gateway = (j < gNetworkOptions.IPv4GatewayAddr.size()) ? gNetworkOptions.IPv4GatewayAddr[j] : IPAddress::Any; { -#if LWIP_VERSION_MAJOR > 1 ip4_addr_t ip4AddrLwIP, ip4NetmaskLwIP, ip4GatewayLwIP; -#else // LWIP_VERSION_MAJOR <= 1 - ip_addr_t ip4AddrLwIP, ip4NetmaskLwIP, ip4GatewayLwIP; -#endif // LWIP_VERSION_MAJOR <= 1 ip4AddrLwIP = ip4Addr.ToIPv4(); IP4_ADDR(&ip4NetmaskLwIP, 255, 255, 255, 0); @@ -343,7 +339,7 @@ void InitNetwork() netif_create_ip6_linklocal_address(&(sNetIFs[j]), 1); -#if !(LWIP_VERSION_MAJOR >= 2 && LWIP_VERSION_MINOR >= 1) +#if (LWIP_VERSION_MAJOR == 2) && (LWIP_VERSION_MINOR == 0) if (j < gNetworkOptions.LocalIPv6Addr.size()) { ip6_addr_t ip6addr = gNetworkOptions.LocalIPv6Addr[j].ToIPv6(); @@ -381,7 +377,7 @@ void InitNetwork() } } } -#endif +#endif // (LWIP_VERSION_MAJOR == 2) && (LWIP_VERSION_MINOR == 0) netif_set_up(&(sNetIFs[j])); netif_set_link_up(&(sNetIFs[j])); diff --git a/src/platform/Ameba/ConnectivityManagerImpl.cpp b/src/platform/Ameba/ConnectivityManagerImpl.cpp index 4a96a893a0ad65..e70938d1f09f76 100644 --- a/src/platform/Ameba/ConnectivityManagerImpl.cpp +++ b/src/platform/Ameba/ConnectivityManagerImpl.cpp @@ -733,15 +733,15 @@ void ConnectivityManagerImpl::OnStationIPv4AddressLost(void) void ConnectivityManagerImpl::OnIPv6AddressAvailable(void) { -#if LWIP_VERSION_MAJOR >= 2 && LWIP_VERSION_MINOR >= 1 +#if LWIP_VERSION_MAJOR > 2 || LWIP_VERSION_MINOR > 0 #if LWIP_IPV6 uint8_t * ipv6_0 = LwIP_GetIPv6_linklocal(&xnetif[0]); uint8_t * ipv6_1 = LwIP_GetIPv6_global(&xnetif[0]); #endif -#endif +#endif // LWIP_VERSION_MAJOR > 2 || LWIP_VERSION_MINOR > 0 #if CHIP_PROGRESS_LOGGING { -#if LWIP_VERSION_MAJOR >= 2 && LWIP_VERSION_MINOR >= 1 +#if LWIP_VERSION_MAJOR > 2 || LWIP_VERSION_MINOR > 0 #if LWIP_IPV6 ChipLogProgress(DeviceLayer, "\n\r\tLink-local IPV6 => %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x", @@ -752,7 +752,7 @@ void ConnectivityManagerImpl::OnIPv6AddressAvailable(void) ipv6_1[0], ipv6_1[1], ipv6_1[2], ipv6_1[3], ipv6_1[4], ipv6_1[5], ipv6_1[6], ipv6_1[7], ipv6_1[8], ipv6_1[9], ipv6_1[10], ipv6_1[11], ipv6_1[12], ipv6_1[13], ipv6_1[14], ipv6_1[15]); #endif -#endif +#endif // LWIP_VERSION_MAJOR > 2 || LWIP_VERSION_MINOR > 0 } #endif // CHIP_PROGRESS_LOGGING @@ -782,14 +782,14 @@ void ConnectivityManagerImpl::DHCPProcessThread(void * param) PlatformMgr().LockChipStack(); sInstance.OnStationIPv4AddressAvailable(); PlatformMgr().UnlockChipStack(); -#if LWIP_VERSION_MAJOR >= 2 && LWIP_VERSION_MINOR >= 1 +#if LWIP_VERSION_MAJOR > 2 || LWIP_VERSION_MINOR > 0 #if LWIP_IPV6 LwIP_DHCP6(0, DHCP6_START); PlatformMgr().LockChipStack(); sInstance.OnIPv6AddressAvailable(); PlatformMgr().UnlockChipStack(); #endif -#endif +#endif // LWIP_VERSION_MAJOR > 2 || LWIP_VERSION_MINOR > 0 vTaskDelete(NULL); } diff --git a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread_LwIP.cpp b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread_LwIP.cpp index cb9c425776f769..957dc20a05ab24 100644 --- a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread_LwIP.cpp +++ b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread_LwIP.cpp @@ -275,9 +275,9 @@ err_t GenericThreadStackManagerImpl_OpenThread_LwIP::DoInitThreadNetI netif->name[0] = CHIP_DEVICE_CONFIG_LWIP_THREAD_IF_NAME[0]; netif->name[1] = CHIP_DEVICE_CONFIG_LWIP_THREAD_IF_NAME[1]; netif->output_ip6 = SendPacket; -#if LWIP_IPV4 || LWIP_VERSION_MAJOR < 2 +#if LWIP_IPV4 netif->output = NULL; -#endif /* LWIP_IPV4 || LWIP_VERSION_MAJOR < 2 */ +#endif // LWIP_IPV4 netif->linkoutput = NULL; netif->flags = NETIF_FLAG_UP | NETIF_FLAG_LINK_UP | NETIF_FLAG_BROADCAST; netif->mtu = CHIP_DEVICE_CONFIG_THREAD_IF_MTU; @@ -293,13 +293,8 @@ err_t GenericThreadStackManagerImpl_OpenThread_LwIP::DoInitThreadNetI * NB: This method is called in the LwIP TCPIP thread with the LwIP core lock held. */ template -#if LWIP_VERSION_MAJOR < 2 -err_t GenericThreadStackManagerImpl_OpenThread_LwIP::SendPacket(struct netif * netif, struct pbuf * pktPBuf, - struct ip6_addr * ipaddr) -#else err_t GenericThreadStackManagerImpl_OpenThread_LwIP::SendPacket(struct netif * netif, struct pbuf * pktPBuf, const struct ip6_addr * ipaddr) -#endif { err_t lwipErr = ERR_OK; otError otErr; diff --git a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread_LwIP.h b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread_LwIP.h index c829512a872593..cc497db7b24b97 100644 --- a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread_LwIP.h +++ b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread_LwIP.h @@ -73,11 +73,7 @@ class GenericThreadStackManagerImpl_OpenThread_LwIP : public GenericThreadStackM bool mAddrAssigned[LWIP_IPV6_NUM_ADDRESSES]; static err_t DoInitThreadNetIf(struct netif * netif); -#if LWIP_VERSION_MAJOR < 2 - static err_t SendPacket(struct netif * netif, struct pbuf * pkt, struct ip6_addr * ipaddr); -#else static err_t SendPacket(struct netif * netif, struct pbuf * pkt, const struct ip6_addr * ipaddr); -#endif static void ReceivePacket(otMessage * pkt, void * context); inline ImplClass * Impl() { return static_cast(this); } diff --git a/src/system/SystemStats.cpp b/src/system/SystemStats.cpp index 57f6a4ee475f9e..bf3473fd62c924 100644 --- a/src/system/SystemStats.cpp +++ b/src/system/SystemStats.cpp @@ -107,13 +107,6 @@ bool Difference(Snapshot & result, Snapshot & after, Snapshot & before) #if CHIP_SYSTEM_CONFIG_USE_LWIP && LWIP_STATS && MEMP_STATS -// To use LwIP 1.x, some additional definitions are required here. -#if LWIP_VERSION_MAJOR < 2 -#ifndef MEMP_STATS_GET -#define MEMP_STATS_GET(FIELD, INDEX) (lwip_stats.memp[INDEX].FIELD) -#endif // !defined(MEMP_STATS_GET) -#endif // LWIP_VERSION_MAJOR - void UpdateLwipPbufCounts(void) { #if LWIP_PBUF_FROM_CUSTOM_POOLS diff --git a/src/system/tests/TestSystemPacketBuffer.cpp b/src/system/tests/TestSystemPacketBuffer.cpp index 15a9a5e3a6a34f..84922d911cc23b 100644 --- a/src/system/tests/TestSystemPacketBuffer.cpp +++ b/src/system/tests/TestSystemPacketBuffer.cpp @@ -48,11 +48,11 @@ #include #if CHIP_SYSTEM_CONFIG_USE_LWIP -#if (LWIP_VERSION_MAJOR >= 2 && LWIP_VERSION_MINOR >= 1) -#define PBUF_TYPE(pbuf) (pbuf)->type_internal -#else +#if (LWIP_VERSION_MAJOR == 2) && (LWIP_VERSION_MINOR == 0) #define PBUF_TYPE(pbuf) (pbuf)->type -#endif // (LWIP_VERSION_MAJOR >= 2 && LWIP_VERSION_MINOR >= 1) +#else // (LWIP_VERSION_MAJOR == 2) && (LWIP_VERSION_MINOR == 0) +#define PBUF_TYPE(pbuf) (pbuf)->type_internal +#endif // (LWIP_VERSION_MAJOR == 2) && (LWIP_VERSION_MINOR == 0) #endif // CHIP_SYSTEM_CONFIG_USE_LWIP using ::chip::Encoding::PacketBufferWriter; diff --git a/src/system/tests/TestSystemTimer.cpp b/src/system/tests/TestSystemTimer.cpp index 5ee0f9a2cd1534..93924d2cf5e56f 100644 --- a/src/system/tests/TestSystemTimer.cpp +++ b/src/system/tests/TestSystemTimer.cpp @@ -442,12 +442,12 @@ static int TestSetup(void * aContext) { TestContext & lContext = *reinterpret_cast(aContext); -#if CHIP_SYSTEM_CONFIG_USE_LWIP && LWIP_VERSION_MAJOR <= 2 && LWIP_VERSION_MINOR < 1 +#if CHIP_SYSTEM_CONFIG_USE_LWIP && LWIP_VERSION_MAJOR == 2 && LWIP_VERSION_MINOR == 0 static sys_mbox_t * sLwIPEventQueue = NULL; sys_mbox_new(sLwIPEventQueue, 100); tcpip_init(NULL, NULL); -#endif // CHIP_SYSTEM_CONFIG_USE_LWIP && LWIP_VERSION_MAJOR <= 2 && LWIP_VERSION_MINOR < 1 +#endif // CHIP_SYSTEM_CONFIG_USE_LWIP && LWIP_VERSION_MAJOR == 2 && LWIP_VERSION_MINOR == 0 sLayer.Init(); @@ -467,11 +467,9 @@ static int TestTeardown(void * aContext) lContext.mLayer->Shutdown(); -#if CHIP_SYSTEM_CONFIG_USE_LWIP -#if !(LWIP_VERSION_MAJOR >= 2 && LWIP_VERSION_MINOR >= 1) +#if CHIP_SYSTEM_CONFIG_USE_LWIP && (LWIP_VERSION_MAJOR == 2) && (LWIP_VERSION_MINOR == 0) tcpip_finish(NULL, NULL); -#endif -#endif +#endif // CHIP_SYSTEM_CONFIG_USE_LWIP && (LWIP_VERSION_MAJOR == 2) && (LWIP_VERSION_MINOR == 0) return (SUCCESS); }