From c1ae85cc53352ad79a15bc38a2a8602e9d7c1d9b Mon Sep 17 00:00:00 2001 From: Junior Martinez <67972863+jmartinez-silabs@users.noreply.github.com> Date: Sun, 3 Mar 2024 15:25:41 -0500 Subject: [PATCH] [Silabs] remove lwipopts-thread.h. (#32002) * remove lwipopts-thread.h. LWIP is not using with our thread implementation * Fix to build efr32 test driver with openthread Inet endpoint instead of lwip (so it uses the same config as our sample apps). Add to implement additional InetInterface method that were missing for the openthread inet endpoint interface. Make TestInetAddress.cpp work for CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT --- src/inet/InetInterface.cpp | 35 +++++ src/inet/tests/TestInetAddress.cpp | 55 +++++-- src/lwip/BUILD.gn | 1 - src/lwip/silabs/lwipopts-thread.h | 182 ------------------------ src/lwip/silabs/lwipopts.h | 2 - src/test_driver/efr32/args.gni | 5 - third_party/silabs/silabs_lwip/BUILD.gn | 1 - 7 files changed, 79 insertions(+), 202 deletions(-) delete mode 100644 src/lwip/silabs/lwipopts-thread.h diff --git a/src/inet/InetInterface.cpp b/src/inet/InetInterface.cpp index 4a404a29db177c..a893f80f4d605b 100644 --- a/src/inet/InetInterface.cpp +++ b/src/inet/InetInterface.cpp @@ -113,6 +113,23 @@ bool InterfaceIterator::Next() return false; } +CHIP_ERROR InterfaceIterator::GetInterfaceName(char * nameBuf, size_t nameBufSize) +{ + VerifyOrReturnError(HasCurrent(), CHIP_ERROR_INCORRECT_STATE); + return InterfaceId(1).GetInterfaceName(nameBuf, nameBufSize); +} + +InterfaceId InterfaceIterator::GetInterfaceId() +{ + // only 1 interface is supported + return HasCurrent() ? InterfaceId(1) : InterfaceId::Null(); +} + +bool InterfaceIterator::IsUp() +{ + return HasCurrent() && (otThreadGetDeviceRole(Inet::globalOtInstance) != OT_DEVICE_ROLE_DISABLED); +} + InterfaceAddressIterator::InterfaceAddressIterator() { mNetifAddrList = nullptr; @@ -128,6 +145,8 @@ bool InterfaceAddressIterator::Next() { if (mNetifAddrList == nullptr) { + if (Inet::globalOtInstance == nullptr) + return false; mNetifAddrList = otIp6GetUnicastAddresses(Inet::globalOtInstance); mCurAddr = mNetifAddrList; } @@ -155,6 +174,22 @@ uint8_t InterfaceAddressIterator::GetPrefixLength() return 64; } +bool InterfaceAddressIterator::IsUp() +{ + return HasCurrent() && (otThreadGetDeviceRole(Inet::globalOtInstance) != OT_DEVICE_ROLE_DISABLED); +} + +InterfaceId InterfaceAddressIterator::GetInterfaceId() +{ + // only 1 interface is supported + return HasCurrent() ? InterfaceId(1) : InterfaceId::Null(); +} + +bool InterfaceAddressIterator::HasBroadcastAddress() +{ + return HasCurrent() && (otIp6GetMulticastAddresses(Inet::globalOtInstance) != nullptr); +} + #endif #if CHIP_SYSTEM_CONFIG_USE_LWIP && !CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT diff --git a/src/inet/tests/TestInetAddress.cpp b/src/inet/tests/TestInetAddress.cpp index 7e796ca05fc340..426d6b7141753c 100644 --- a/src/inet/tests/TestInetAddress.cpp +++ b/src/inet/tests/TestInetAddress.cpp @@ -35,6 +35,11 @@ #include +#elif CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT +#include +#include +#include + #else #include #include @@ -718,12 +723,6 @@ void CheckAddress(nlTestSuite * inSuite, const IPAddressContext & inContext, con CheckAddressQuartets(inSuite, inContext, inAddress); - // Convert the address to a string and compare it to the control string. - - inAddress.ToString(lAddressBuffer); - - CheckAddressString(inSuite, lAddressBuffer, inContext.mAddrString); - // Convert the control string to an address and compare the parsed address to the created address. lResult = IPAddress::FromString(inContext.mAddrString, lParsedAddress); @@ -735,6 +734,21 @@ void CheckAddress(nlTestSuite * inSuite, const IPAddressContext & inContext, con { fprintf(stdout, "Address parse mismatch for %s\n", inContext.mAddrString); } + + // Convert the address to a string and compare it to the control string. + + inAddress.ToString(lAddressBuffer); +#if CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT + // Embedded openthread stack otIp6AddressFromString format the string as a uncompressed IPV6 + // example ff01::1 is formatted has ff01:0:0:0:0:0:0:1 + // But the IPV6 address From string API (otIp6AddressFromString) handle both compressed and uncompressed format. + char uncompressedAddrStr[INET6_ADDRSTRLEN]; + // Reconvert the previously parsed control string to an uncompressed string format + lParsedAddress.ToString(uncompressedAddrStr); + CheckAddressString(inSuite, lAddressBuffer, uncompressedAddrStr); +#else + CheckAddressString(inSuite, lAddressBuffer, inContext.mAddrString); +#endif } // Test functions invoked from the suite. @@ -786,9 +800,22 @@ void CheckToString(nlTestSuite * inSuite, void * inContext) SetupIPAddress(lAddress, lCurrent); lAddress.ToString(lAddressBuffer); - +#if CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT + // Embedded openthread stack otIp6AddressFromString format the string as a uncompressed IPV6 + // So ff01::1 is formatted has ff01:0:0:0:0:0:0:1 + // But the IPV6 address From string API (otIp6AddressFromString) handle both compressed and uncompressed format. + // For this test, pass the expected, compressed, string throught the opentread stack address format API + // so the final check evaluates uncompressed IPV6 strings. + char uncompressedAddrStr[INET6_ADDRSTRLEN]; + IPAddress tempIpAddr; + // Set Expected compressed IPV6 String as otIpv6 Address + IPAddress::FromString(lCurrent->mAddr.mAddrString, strlen(lCurrent->mAddr.mAddrString), tempIpAddr); + // Reconvert the expected IPV6 String to an uncompressed string format + tempIpAddr.ToString(uncompressedAddrStr); + CheckAddressString(inSuite, lAddressBuffer, uncompressedAddrStr); +#else CheckAddressString(inSuite, lAddressBuffer, lCurrent->mAddr.mAddrString); - +#endif // CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT ++lCurrent; } } @@ -1015,6 +1042,9 @@ void CheckToIPv6(nlTestSuite * inSuite, void * inContext) #if LWIP_IPV6_SCOPES ip_addr_1.zone = 0; #endif +#elif CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT + otIp6Address ip_addr_1 = { 0 }, ip_addr_2 = { 0 }; + memcpy(ip_addr_1.mFields.m32, addr, sizeof(addr)); #else struct in6_addr ip_addr_1, ip_addr_2; ip_addr_1 = *reinterpret_cast(addr); @@ -1052,6 +1082,9 @@ void CheckFromIPv6(nlTestSuite * inSuite, void * inContext) #if CHIP_SYSTEM_CONFIG_USE_LWIP ip6_addr_t ip_addr; memcpy(ip_addr.addr, addr, sizeof(addr)); +#elif CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT + otIp6Address ip_addr; + memcpy(ip_addr.mFields.m32, addr, sizeof(addr)); #else struct in6_addr ip_addr; ip_addr = *reinterpret_cast(addr); @@ -1203,9 +1236,9 @@ void CheckFromIPv4(nlTestSuite * inSuite, void * inContext) */ void CheckFromSocket(nlTestSuite * inSuite, void * inContext) { -#if CHIP_SYSTEM_CONFIG_USE_LWIP +#if CHIP_SYSTEM_CONFIG_USE_LWIP || CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT (void) inSuite; - // This test is only supported for non LWIP stack. + // This test is not supported LWIP or OPEN_THREAD_ENDPOINT stacks. #else // CHIP_SYSTEM_CONFIG_USE_LWIP const struct TestContext * lContext = static_cast(inContext); IPAddressExpandedContextIterator lCurrent = lContext->mIPAddressExpandedContextRange.mBegin; @@ -1261,7 +1294,7 @@ void CheckFromSocket(nlTestSuite * inSuite, void * inContext) ++lCurrent; } -#endif // CHIP_SYSTEM_CONFIG_USE_LWIP +#endif // CHIP_SYSTEM_CONFIG_USE_LWIP || CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT } /** diff --git a/src/lwip/BUILD.gn b/src/lwip/BUILD.gn index c51383a944dc80..98e94def25fb84 100644 --- a/src/lwip/BUILD.gn +++ b/src/lwip/BUILD.gn @@ -226,7 +226,6 @@ if (current_os == "zephyr" || current_os == "mbed") { sources += [ "${lwip_platform}/lwipopts-rs911x.h", - "${lwip_platform}/lwipopts-thread.h", "${lwip_platform}/lwipopts-wf200.h", ] } else if (lwip_platform == "standalone") { diff --git a/src/lwip/silabs/lwipopts-thread.h b/src/lwip/silabs/lwipopts-thread.h deleted file mode 100644 index f667e5bb3a8f27..00000000000000 --- a/src/lwip/silabs/lwipopts-thread.h +++ /dev/null @@ -1,182 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2019 Nest Labs, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @file - * Compile-time configuration for LwIP on EFR32 platforms using the - * Silicon Labs EFR32 SDK. - * - */ - -#ifndef __LWIPOPTS_H__ -#define __LWIPOPTS_H__ - -#if CHIP_HAVE_CONFIG_H -#include -#endif - -#include - -#define NO_SYS 0 -#define MEM_ALIGNMENT (4) -#define MEMP_NUM_TCP_SEG (TCP_SND_QUEUELEN + 1) -#define LWIP_TIMEVAL_PRIVATE (0) -#define MEM_LIBC_MALLOC (0) -#define LWIP_COMPAT_MUTEX (0) -#define SYS_LIGHTWEIGHT_PROT (1) -#define LWIP_AUTOIP (0) -#define LWIP_DHCP_AUTOIP_COOP (0) -#define LWIP_SOCKET_SET_ERRNO 0 -#define IP_REASS_MAX_PBUFS 0 -#define IP_REASSEMBLY 0 -#define MEMP_NUM_REASSDATA 0 -#define LWIP_SO_RCVTIMEO 0 -#define SO_REUSE (1) -#define LWIP_RANDOMIZE_INITIAL_LOCAL_PORTS (1) -#define LWIP_STATS (0) -#define LWIP_TCPIP_CORE_LOCKING 1 -#define TCP_QUEUE_OOSEQ 0 -#define ARP_QUEUEING (0) -#define TCPIP_THREAD_NAME "LWIP" - -#define LWIP_SOCKET 0 - -#define LWIP_FREERTOS_USE_STATIC_TCPIP_TASK 1 - -#define LWIP_RAW 1 -#define MEMP_NUM_RAW_PCB (4) - -#define MEMP_NUM_UDP_PCB (5) - -#define LWIP_HAVE_LOOPIF (0) - -// TODO: not sure why this is disabled -#define LWIP_NETIF_LOOPBACK (0) - -#define MEMP_NUM_NETCONN (0) - -#define LWIP_IPV4 0 - -#define LWIP_IPV6 1 -#define LWIP_IPV6_ROUTE_TABLE_SUPPORT 1 -#define LWIP_ARP (0) -#define LWIP_DNS (0) -#define LWIP_ICMP (0) -#define LWIP_IGMP (0) -#define LWIP_DHCP (0) -#define LWIP_IPV6_REASS (0) -#define LWIP_IPV6_DHCP6 0 -#define LWIP_IPV6_AUTOCONFIG (0) -#define LWIP_IPV6_ROUTER_SUPPORT 0 -#define LWIP_ND6_LISTEN_RA 0 - -#define LWIP_ND6_NUM_NEIGHBORS (0) -#define LWIP_ND6_NUM_DESTINATIONS (0) -#define LWIP_ND6_NUM_PREFIXES (0) -#define LWIP_ND6_NUM_ROUTERS (0) -#define LWIP_ND6_MAX_MULTICAST_SOLICIT (0) -#define LWIP_ND6_MAX_UNICAST_SOLICIT (0) -#define LWIP_ND6_MAX_NEIGHBOR_ADVERTISEMENT (0) -#define LWIP_ND6_TCP_REACHABILITY_HINTS (0) - -#if defined(EFR32MG21) -#define MEMP_SEPARATE_POOLS (1) -#define LWIP_PBUF_FROM_CUSTOM_POOLS (0) -#define MEMP_USE_CUSTOM_POOLS (0) -#define PBUF_POOL_SIZE (5) -#define PBUF_POOL_BUFSIZE (1280) -#define PBUF_CUSTOM_POOL_IDX_START (MEMP_PBUF_POOL_SMALL) -#define PBUF_CUSTOM_POOL_IDX_END (MEMP_PBUF_POOL_LARGE) -#else -#define MEMP_SEPARATE_POOLS (1) -#define LWIP_PBUF_FROM_CUSTOM_POOLS (0) -#define MEMP_USE_CUSTOM_POOLS (0) -#define PBUF_POOL_SIZE (8) -#define PBUF_POOL_BUFSIZE (1280) -#define PBUF_CUSTOM_POOL_IDX_START (MEMP_PBUF_POOL_SMALL) -#define PBUF_CUSTOM_POOL_IDX_END (MEMP_PBUF_POOL_LARGE) -#endif - -#define TCP_MSS (1152) -#define TCP_SND_BUF (2 * TCP_MSS) -#define TCP_LISTEN_BACKLOG (1) - -#define ETH_PAD_SIZE (0) -#define SUB_ETHERNET_HEADER_SPACE (0) -#define PBUF_LINK_HLEN (0) - -#if defined(EFR32MG21) -#define TCPIP_THREAD_STACKSIZE (1536) -#else -#define TCPIP_THREAD_STACKSIZE (2048) -#endif - -#define TCPIP_THREAD_PRIO (2) - -#define NETIF_MAX_HWADDR_LEN 8U - -#define LWIP_IPV6_NUM_ADDRESSES 5 - -#define LWIP_IPV6_ND 0 -#define LWIP_ND6_QUEUEING 0 - -#define LWIP_MULTICAST_PING 0 - -#define TCPIP_MBOX_SIZE 6 -#define DEFAULT_RAW_RECVMBOX_SIZE 6 -#define DEFAULT_UDP_RECVMBOX_SIZE 6 -#define DEFAULT_TCP_RECVMBOX_SIZE 6 - -#ifdef LWIP_DEBUG - -#define MEMP_OVERFLOW_CHECK (0) -#define MEMP_SANITY_CHECK (0) -#define MEM_DEBUG (LWIP_DBG_OFF) -#define MEMP_DEBUG (LWIP_DBG_OFF) -#define PBUF_DEBUG (LWIP_DBG_OFF) -#define API_LIB_DEBUG (LWIP_DBG_OFF) -#define API_MSG_DEBUG (LWIP_DBG_OFF) -#define TCPIP_DEBUG (LWIP_DBG_OFF) -#define NETIF_DEBUG (LWIP_DBG_OFF) -#define SOCKETS_DEBUG (LWIP_DBG_OFF) -#define DEMO_DEBUG (LWIP_DBG_OFF) -#define DHCP_DEBUG (LWIP_DBG_OFF) -#define AUTOIP_DEBUG (LWIP_DBG_OFF) -#define ETHARP_DEBUG (LWIP_DBG_OFF) -#define IP_DEBUG (LWIP_DBG_OFF) -#define IP_REASS_DEBUG (LWIP_DBG_OFF) -#define IP6_DEBUG (LWIP_DBG_OFF) -#define RAW_DEBUG (LWIP_DBG_OFF) -#define ICMP_DEBUG (LWIP_DBG_OFF) -#define UDP_DEBUG (LWIP_DBG_OFF) -#define TCP_DEBUG (LWIP_DBG_OFF) -#define TCP_INPUT_DEBUG (LWIP_DBG_OFF) -#define TCP_OUTPUT_DEBUG (LWIP_DBG_OFF) -#define TCP_RTO_DEBUG (LWIP_DBG_OFF) -#define TCP_CWND_DEBUG (LWIP_DBG_OFF) -#define TCP_WND_DEBUG (LWIP_DBG_OFF) -#define TCP_FR_DEBUG (LWIP_DBG_OFF) -#define TCP_QLEN_DEBUG (LWIP_DBG_OFF) -#define TCP_RST_DEBUG (LWIP_DBG_OFF) -#define PPP_DEBUG (LWIP_DBG_OFF) -#endif - -#define LWIP_DBG_TYPES_ON \ - (LWIP_DBG_ON | LWIP_DBG_TRACE) /* (LWIP_DBG_ON|LWIP_DBG_TRACE|LWIP_DBG_STATE|LWIP_DBG_FRESH|LWIP_DBG_HALT) */ - -#endif /* __LWIPOPTS_H__ */ diff --git a/src/lwip/silabs/lwipopts.h b/src/lwip/silabs/lwipopts.h index 499e11d4700c19..722134514eb864 100644 --- a/src/lwip/silabs/lwipopts.h +++ b/src/lwip/silabs/lwipopts.h @@ -2,6 +2,4 @@ #include "lwipopts-wf200.h" #elif defined(RS911X_WIFI) #include "lwipopts-rs911x.h" -#else -#include "lwipopts-thread.h" #endif diff --git a/src/test_driver/efr32/args.gni b/src/test_driver/efr32/args.gni index a8d442d5c2140e..eaace30f8c3d75 100644 --- a/src/test_driver/efr32/args.gni +++ b/src/test_driver/efr32/args.gni @@ -29,9 +29,4 @@ chip_monolithic_tests = true openthread_external_platform = "${chip_root}/third_party/openthread/platforms/efr32:libopenthread-efr32" -#Fix me : Test driver should use same config as examples -# Problem : Linker issue if set to true -chip_system_config_use_open_thread_inet_endpoints = false -chip_with_lwip = true - pw_rpc_CONFIG = "$dir_pw_rpc:disable_global_mutex" diff --git a/third_party/silabs/silabs_lwip/BUILD.gn b/third_party/silabs/silabs_lwip/BUILD.gn index dd05ec4cf319c6..e148763a9ca70d 100644 --- a/third_party/silabs/silabs_lwip/BUILD.gn +++ b/third_party/silabs/silabs_lwip/BUILD.gn @@ -36,7 +36,6 @@ lwip_target("silabs_lwip") { sources = [ "${chip_root}/src/lwip/freertos/sys_arch.c", "${chip_root}/src/lwip/silabs/lwipopts-rs911x.h", - "${chip_root}/src/lwip/silabs/lwipopts-thread.h", "${chip_root}/src/lwip/silabs/lwipopts-wf200.h", ]