From: SnickerSun Date: Wed, 28 Feb 2024 09:06:57 +0000 (+0800) Subject: 重新移植lwip,cat1_service 可以正常运行udp服务 X-Git-Tag: release_V1.2.70_20241020_135402~1274^2~52 X-Git-Url: http://git.snicker.com.cn/css/static/script.js?a=commitdiff_plain;h=7784a312fac0cddb8cb767496ca4566e04917ee2;p=mirrors%2FFD230.git 重新移植lwip,cat1_service 可以正常运行udp服务 --- diff --git a/code/sdk/drivers/peripheral/slip/cat1Service/cat1_at_cmd.cpp b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_at_cmd.cpp index 5b9f8e849..7d0f12bc2 100644 --- a/code/sdk/drivers/peripheral/slip/cat1Service/cat1_at_cmd.cpp +++ b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_at_cmd.cpp @@ -104,19 +104,6 @@ static uint32_t cat1_dial(uint8_t *para, uint32_t paraLen, char *strCommonCmd) static uint32_t cat1_answer(uint8_t *para, uint32_t paraLen, char *strCommonCmd) { UNUSED(strCommonCmd); - uint8_t argv[PPG_MAX_ARGC][PPG_MAX_ARGV_LEN] = { 0 }; - uint32_t argc = 0; - - int ret = ConvertCmdToParam(para, paraLen, argv, &argc); - if (ret != PPG_SUCCESS) { - printf("CAT1TEST ATCMD Convert Command Failed\n"); - return ERRCODE_FAIL; - } - - if (argc != 1) { - printf("CAT1TEST ATCMD Set Parameter Failed\n"); - return ERRCODE_FAIL; - } printf("CAT1TEST ATCMD answer \n"); @@ -125,19 +112,7 @@ static uint32_t cat1_answer(uint8_t *para, uint32_t paraLen, char *strCommonCmd) static uint32_t cat1_hungup(uint8_t *para, uint32_t paraLen, char *strCommonCmd) { UNUSED(strCommonCmd); - uint8_t argv[PPG_MAX_ARGC][PPG_MAX_ARGV_LEN] = { 0 }; - uint32_t argc = 0; - int ret = ConvertCmdToParam(para, paraLen, argv, &argc); - if (ret != PPG_SUCCESS) { - printf("CAT1TEST ATCMD Convert Command Failed\n"); - return ERRCODE_FAIL; - } - - if (argc != 1) { - printf("CAT1TEST ATCMD Set Parameter Failed\n"); - return ERRCODE_FAIL; - } printf("CAT1TEST ATCMD hungup \n"); @@ -148,24 +123,23 @@ static uint32_t cat1_hungup(uint8_t *para, uint32_t paraLen, char *strCommonCmd) static uint32_t cat1_getsignal(uint8_t *para, uint32_t paraLen, char *strCommonCmd) { UNUSED(strCommonCmd); - uint8_t argv[PPG_MAX_ARGC][PPG_MAX_ARGV_LEN] = { 0 }; - uint32_t argc = 0; - - int ret = ConvertCmdToParam(para, paraLen, argv, &argc); - if (ret != PPG_SUCCESS) { - printf("CAT1TEST ATCMD Convert Command Failed\n"); - return ERRCODE_FAIL; - } - if (argc != 1) { - printf("CAT1TEST ATCMD Set Parameter Failed\n"); - return ERRCODE_FAIL; - } printf("CAT1TEST ATCMD getsignal \n"); + return ERRCODE_SUCC; +} + +extern void LwipTestEnter(void); + +static uint32_t cat1_nettest(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + UNUSED(strCommonCmd); + printf("CAT1TEST ATCMD nettest \n"); + LwipTestEnter(); + return ERRCODE_SUCC; } static const at_cmd_table_t g_cat1_cmd[] = { @@ -174,6 +148,7 @@ static const at_cmd_table_t g_cat1_cmd[] = { { (char *)"AT^CAT1ANSWER", cat1_answer, (char *)"1" }, { (char *)"AT^CAT1HUNGUP", cat1_hungup, (char *)"1" }, { (char *)"AT^CAT1GETSIGNAL", cat1_getsignal, (char *)"1" }, + { (char *)"AT^CAT1NETTEST", cat1_nettest, (char *)"1" }, }; at_cmd_table_t *get_cat1_cmd_table(uint32_t *cmd_count) diff --git a/code/sdk/drivers/peripheral/slip/cat1Service/cat1_server.cpp b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_server.cpp index 2a24befbc..62aa42150 100644 --- a/code/sdk/drivers/peripheral/slip/cat1Service/cat1_server.cpp +++ b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_server.cpp @@ -281,7 +281,9 @@ static int udp_socket_init() return listen_sock; } - +#include "cmsis_os2.h" +extern osStatus_t osDelay(uint32_t ticks); +#define cat1_msleep(ms) osDelay(ms) /* osDelay(1) : 1ms */ int cat1_server_task(void *pvParameters) { char rx_buffer[512]; @@ -294,7 +296,7 @@ int cat1_server_task(void *pvParameters) if( g_listen_sock < 0 ) { printf("socket init fail and retry\n"); // vTaskDelay(1000/portTICK_RATE_MS); - uapi_tcxo_delay_ms(1000); + cat1_msleep(1000); continue; } @@ -365,14 +367,14 @@ void wifi_status() errcode_t cat1_server_init(void) { - // osal_task *task_handle = osal_kthread_create((osal_kthread_handler)cat1_server_task, NULL, - // "cat1_service", CAT1_SERVICE_TASK_SIZE); - // if (task_handle == NULL) { - // PRINT_ERR("create cat1 service thread fail!\r\n"); - // return ERRCODE_FAIL; - // } + osal_task *task_handle = osal_kthread_create((osal_kthread_handler)cat1_server_task, NULL, + "cat1_service", CAT1_SERVICE_TASK_SIZE); + if (task_handle == NULL) { + PRINT_ERR("create cat1 service thread fail!\r\n"); + return ERRCODE_FAIL; + } - // osal_kthread_set_priority(task_handle, CAT1_SERVICE_TASK_PRIO); + osal_kthread_set_priority(task_handle, CAT1_SERVICE_TASK_PRIO); return ERRCODE_SUCC; } diff --git a/code/sdk/open_source/openharmony/third_party/lwip/CMakeLists.txt b/code/sdk/open_source/openharmony/third_party/lwip/CMakeLists.txt index 79744ded6..ab65c2afe 100644 --- a/code/sdk/open_source/openharmony/third_party/lwip/CMakeLists.txt +++ b/code/sdk/open_source/openharmony/third_party/lwip/CMakeLists.txt @@ -35,11 +35,34 @@ include(${LWIP_ROOT_DIR}/src/Filelists.cmake) # set(CPACK_SOURCE_IGNORE_FILES "/build/;${CPACK_SOURCE_IGNORE_FILES};.git") # set(CPACK_SOURCE_PACKAGE_FILE_NAME "lwip-${LWIP_VERSION_MAJOR}.${LWIP_VERSION_MINOR}.${LWIP_VERSION_REVISION}") # include(CPack) -set(PORT_SOURCES - ${LWIP_ROOT_DIR}/port/LiteOS/sys_arch.c +set(lwipport_SRCS + # ${LWIP_ROOT_DIR}/port/LiteOS/sys_arch.c + ${LWIP_ROOT_DIR}/port/lwip-2.1/porting/src/sys_arch.c + ${LWIP_ROOT_DIR}/port/lwip-2.1/porting/src/api_shell.c + ${LWIP_ROOT_DIR}/port/lwip-2.1/porting/src/driverif.c + ${LWIP_ROOT_DIR}/port/lwip-2.1/porting/src/lwip_init.c + ${LWIP_ROOT_DIR}/port/lwip-2.1/porting/src/netdb_porting.c + ${LWIP_ROOT_DIR}/port/lwip-2.1/porting/src/sockets_porting.c + ${LWIP_ROOT_DIR}/port/lwip-2.1/enhancement/src/fixme.c + ${LWIP_ROOT_DIR}/port/lwip-2.1/enhancement/src/lwip_ifaddrs.c ) - +set(lwiptest_SRCS + ${LWIP_ROOT_DIR}/port/test/test_main.c + ${LWIP_ROOT_DIR}/port/test/net_socket_test_001.c + ${LWIP_ROOT_DIR}/port/test/net_socket_test_002.c + ${LWIP_ROOT_DIR}/port/test/net_socket_test_003.c + ${LWIP_ROOT_DIR}/port/test/net_socket_test_004.c + ${LWIP_ROOT_DIR}/port/test/net_socket_test_005.c + ${LWIP_ROOT_DIR}/port/test/net_socket_test_006.c + ${LWIP_ROOT_DIR}/port/test/net_socket_test_007.c + ${LWIP_ROOT_DIR}/port/test/net_socket_test_008.c + # ${LWIP_ROOT_DIR}/port/test/net_socket_test_009.c + # ${LWIP_ROOT_DIR}/port/test/net_socket_test_010.c + ${LWIP_ROOT_DIR}/port/test/net_socket_test_011.c + ${LWIP_ROOT_DIR}/port/test/net_socket_test_012.c + ${LWIP_ROOT_DIR}/port/test/net_socket_test_013.c +) set(SOURCES ${lwipcore_SRCS} ${lwipcore4_SRCS} @@ -50,13 +73,14 @@ set(SOURCES ${lwipmbedtls_SRCS} # ${lwiphttp_SRCS} ${lwiphttp_SRCS} - ${PORT_SOURCES} + ${lwipport_SRCS} + ${lwiptest_SRCS} ) set(PUBLIC_HEADER + # ${LWIP_ROOT_DIR}/port/include + ${LWIP_ROOT_DIR}/port/lwip-2.1/porting/include ${LWIP_ROOT_DIR}/src/include - # ${LWIP_ROOT_DIR}/test/unit - ${LWIP_ROOT_DIR}/port/include ) set(PRIVATE_HEADER diff --git a/code/sdk/open_source/openharmony/third_party/lwip/doc/doxygen/output/index.html b/code/sdk/open_source/openharmony/third_party/lwip/doc/doxygen/output/index.html new file mode 100644 index 000000000..a52e09fcf --- /dev/null +++ b/code/sdk/open_source/openharmony/third_party/lwip/doc/doxygen/output/index.html @@ -0,0 +1,10 @@ + + + + Redirection + + + + index.html + + diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/BUILD.gn b/code/sdk/open_source/openharmony/third_party/lwip/port/BUILD.gn new file mode 100644 index 000000000..5e15cf3e4 --- /dev/null +++ b/code/sdk/open_source/openharmony/third_party/lwip/port/BUILD.gn @@ -0,0 +1,42 @@ +# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. +# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import("//kernel/liteos_m/liteos.gni") + +declare_args() { + ohos_kernel_liteos_m_lwip_path = "lwip-2.1" +} + +config("public") { + configs = [ "$ohos_kernel_liteos_m_lwip_path:public" ] +} + +group("net") { + deps = [ "$ohos_kernel_liteos_m_lwip_path" ] +} diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/LiteOS/ethernetif.c b/code/sdk/open_source/openharmony/third_party/lwip/port/LiteOS/ethernetif.c deleted file mode 100644 index 0d23e5e18..000000000 --- a/code/sdk/open_source/openharmony/third_party/lwip/port/LiteOS/ethernetif.c +++ /dev/null @@ -1,421 +0,0 @@ -/** -* @file -* Ethernet Interface Skeleton -* -*/ - -/* -* Copyright (c) 2001-2004 Swedish Institute of Computer Science. -* All rights reserved. -* -* Redistribution and use in source and binary forms, with or without modification, -* are permitted provided that the following conditions are met: -* -* 1. Redistributions of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* 2. Redistributions in binary form must reproduce the above copyright notice, -* this list of conditions and the following disclaimer in the documentation -* and/or other materials provided with the distribution. -* 3. The name of the author may not be used to endorse or promote products -* derived from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT -* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT -* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING -* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY -* OF SUCH DAMAGE. -* -* This file is part of the lwIP TCP/IP stack. -* -* Author: Adam Dunkels -* -*/ - -/* -* This file is a skeleton for developing Ethernet network interface -* drivers for lwIP. Add code to the low_level functions and do a -* search-and-replace for the word "ethernetif" to replace it with -* something that better describes your network interface. -*/ - -#include "lwip/opt.h" -#include "lwip/def.h" -#include "lwip/mem.h" -#include "lwip/pbuf.h" -#include "lwip/timers.h" -#include "netif/etharp.h" -#include "err.h" -#include "ethernetif.h" -#include "includes.h" -#include "stm32f429_eth.h" -#include "lwipopts/netconf.h" -#include -#include "los_base.h" - -#define netifINTERFACE_TASK_STACK_SIZE ( 512u ) -#define netifINTERFACE_TASK_PRIORITY ( 4u ) - -/* Define those to better describe your network interface. */ -#define IFNAME0 'w' -#define IFNAME1 'f' - - -static struct netif *s_pxNetIf = NULL; - - -/* Ethernet Rx & Tx DMA Descriptors */ -extern ETH_DMADESCTypeDef DMARxDscrTab[ETH_RXBUFNB], DMATxDscrTab[ETH_TXBUFNB]; - -/* Ethernet Receive buffers */ -extern uint8_t Rx_Buff[ETH_RXBUFNB][ETH_RX_BUF_SIZE]; - -/* Ethernet Transmit buffers */ -extern uint8_t Tx_Buff[ETH_TXBUFNB][ETH_TX_BUF_SIZE]; - -/* Global pointers to track current transmit and receive descriptors */ -extern ETH_DMADESCTypeDef *DMATxDescToSet; -extern ETH_DMADESCTypeDef *DMARxDescToGet; - -/* Global pointer for last received frame infos */ -extern ETH_DMA_Rx_Frame_infos *DMA_RX_FRAME_infos; - - -static void ethernetif_input( void * pvParameters ); -static void arp_timer(void *arg); - - -/** -* In this function, the hardware should be initialized. -* Called from ethernetif_init(). -* -* @param netif the already initialized lwip network interface structure -* for this ethernetif -*/ -static void low_level_init(struct netif *netif) -{ - uint32_t i; - - /* set netif MAC hardware address length */ - netif->hwaddr_len = ETHARP_HWADDR_LEN; - - /* set netif MAC hardware address */ - netif->hwaddr[0] = MAC_ADDR0; - netif->hwaddr[1] = MAC_ADDR1; - netif->hwaddr[2] = MAC_ADDR2; - netif->hwaddr[3] = MAC_ADDR3; - netif->hwaddr[4] = MAC_ADDR4; - netif->hwaddr[5] = MAC_ADDR5; - - /* set netif maximum transfer unit */ - netif->mtu = 1500; - - /* Accept broadcast address and ARP traffic */ - netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP; - - s_pxNetIf =netif; - - /* initialize MAC address in ethernet MAC */ - ETH_MACAddressConfig(ETH_MAC_Address0, netif->hwaddr); - - /* Initialize Tx Descriptors list: Chain Mode */ - ETH_DMATxDescChainInit(DMATxDscrTab, &Tx_Buff[0][0], ETH_TXBUFNB); - /* Initialize Rx Descriptors list: Chain Mode */ - ETH_DMARxDescChainInit(DMARxDscrTab, &Rx_Buff[0][0], ETH_RXBUFNB); - - /* Enable Ethernet Rx interrrupt */ - { - for(i=0; iBuffer1Addr); - bufferoffset = 0; - - for(q = p; q != NULL; q = q->next) - { - if((DmaTxDesc->Status & ETH_DMATxDesc_OWN) != (u32)RESET) - { -// errval = ERR_BUF; - goto error; - } - - /* Get bytes in current lwIP buffer */ - byteslefttocopy = q->len; - payloadoffset = 0; - - /* Check if the length of data to copy is bigger than Tx buffer size*/ - while( (byteslefttocopy + bufferoffset) > ETH_TX_BUF_SIZE ) - { - /* Copy data to Tx buffer*/ - memcpy( (u8_t*)((u8_t*)buffer + bufferoffset), (u8_t*)((u8_t*)q->payload + payloadoffset), (ETH_TX_BUF_SIZE - bufferoffset) ); - - /* Point to next descriptor */ - DmaTxDesc = (ETH_DMADESCTypeDef *)(DmaTxDesc->Buffer2NextDescAddr); - - /* Check if the buffer is available */ - if((DmaTxDesc->Status & ETH_DMATxDesc_OWN) != (u32)RESET) - { -// errval = ERR_USE; - goto error; - } - - buffer = (u8 *)(DmaTxDesc->Buffer1Addr); - - byteslefttocopy = byteslefttocopy - (ETH_TX_BUF_SIZE - bufferoffset); - payloadoffset = payloadoffset + (ETH_TX_BUF_SIZE - bufferoffset); - framelength = framelength + (ETH_TX_BUF_SIZE - bufferoffset); - bufferoffset = 0; - } - - /* Copy the remaining bytes */ - memcpy( (u8_t*)((u8_t*)buffer + bufferoffset), (u8_t*)((u8_t*)q->payload + payloadoffset), byteslefttocopy ); - bufferoffset = bufferoffset + byteslefttocopy; - framelength = framelength + byteslefttocopy; - } - - /* Prepare transmit descriptors to give to DMA*/ - ETH_Prepare_Transmit_Descriptors(framelength); -// errval = ERR_OK; - /* Give semaphore and exit */ - error: - -// /* When Transmit Underflow flag is set, clear it and issue a Transmit Poll Demand to resume transmission */ -// if ((ETH->DMASR & ETH_DMASR_TUS) != (uint32_t)RESET) -// { -// /* Clear TUS ETHERNET DMA flag */ -// ETH->DMASR = ETH_DMASR_TUS; - -// /* Resume DMA transmission*/ -// ETH->DMATPDR = 0; -// } -// return errval; - SYS_ARCH_UNPROTECT(sr); - return ERR_OK; -} - -/** -* Should allocate a pbuf and transfer the bytes of the incoming -* packet from the interface into the pbuf. -* -* @param netif the lwip network interface structure for this ethernetif -* @return a pbuf filled with the received packet (including MAC header) -* NULL on memory error -*/ -static struct pbuf * low_level_input(struct netif *netif) -{ - struct pbuf *p= NULL, *q; - u32_t len; - FrameTypeDef frame; - u8 *buffer; - __IO ETH_DMADESCTypeDef *DMARxDesc; - uint32_t bufferoffset = 0; - uint32_t payloadoffset = 0; - uint32_t byteslefttocopy = 0; - uint32_t i=0; - - /* get received frame */ - frame = ETH_Get_Received_Frame_interrupt(); - - /* Obtain the size of the packet and put it into the "len" variable. */ - len = frame.length; - buffer = (u8 *)frame.buffer; - - if (len > 0) - { - /* We allocate a pbuf chain of pbufs from the Lwip buffer pool */ - p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL); - } - - if (p != NULL) - { - DMARxDesc = frame.descriptor; - bufferoffset = 0; - for(q = p; q != NULL; q = q->next) - { - byteslefttocopy = q->len; - payloadoffset = 0; - - /* Check if the length of bytes to copy in current pbuf is bigger than Rx buffer size*/ - while( (byteslefttocopy + bufferoffset) > ETH_RX_BUF_SIZE ) - { - /* Copy data to pbuf*/ - memcpy( (u8_t*)((u8_t*)q->payload + payloadoffset), (u8_t*)((u8_t*)buffer + bufferoffset), (ETH_RX_BUF_SIZE - bufferoffset)); - - /* Point to next descriptor */ - DMARxDesc = (ETH_DMADESCTypeDef *)(DMARxDesc->Buffer2NextDescAddr); - buffer = (unsigned char *)(DMARxDesc->Buffer1Addr); - - byteslefttocopy = byteslefttocopy - (ETH_RX_BUF_SIZE - bufferoffset); - payloadoffset = payloadoffset + (ETH_RX_BUF_SIZE - bufferoffset); - bufferoffset = 0; - } - - /* Copy remaining data in pbuf */ - memcpy( (u8_t*)((u8_t*)q->payload + payloadoffset), (u8_t*)((u8_t*)buffer + bufferoffset), byteslefttocopy); - bufferoffset = bufferoffset + byteslefttocopy; - } - } - - /* Release descriptors to DMA */ - DMARxDesc =frame.descriptor; - - /* Set Own bit in Rx descriptors: gives the buffers back to DMA */ - for (i=0; iSeg_Count; i++) - { - DMARxDesc->Status = ETH_DMARxDesc_OWN; - DMARxDesc = (ETH_DMADESCTypeDef *)(DMARxDesc->Buffer2NextDescAddr); - } - - /* Clear Segment_Count */ - DMA_RX_FRAME_infos->Seg_Count =0; - - /* When Rx Buffer unavailable flag is set: clear it and resume reception */ - if ((ETH->DMASR & ETH_DMASR_RBUS) != (u32)RESET) - { - /* Clear RBUS ETHERNET DMA flag */ - ETH->DMASR = ETH_DMASR_RBUS; - /* Resume DMA reception */ - ETH->DMARPDR = 0; - } - return p; -} - - -/** -* This function is the ethernetif_input task, it is processed when a packet -* is ready to be read from the interface. It uses the function low_level_input() -* that should handle the actual reception of bytes from the network -* interface. Then the type of the received packet is determined and -* the appropriate input function is called. -* -* @param netif the lwip network interface structure for this ethernetif -*/ -void ethernetif_input( void * pvParameters ) -{ - struct pbuf *p; - err_t err; - - /* move received packet into a new pbuf */ - while (1) - { - SYS_ARCH_DECL_PROTECT(sr); - SYS_ARCH_PROTECT(sr); - p = low_level_input(s_pxNetIf); - SYS_ARCH_UNPROTECT(sr); - if (p == NULL) - continue; - err = s_pxNetIf->input(p, s_pxNetIf); - if (err != ERR_OK){ - LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n")); - pbuf_free(p); - p = NULL; - } - /*sleep 5 ms*/ - LOS_Msleep(5); - } -} - -/** -* Should be called at the beginning of the program to set up the -* network interface. It calls the function low_level_init() to do the -* actual setup of the hardware. -* -* This function should be passed as a parameter to netif_add(). -* -* @param netif the lwip network interface structure for this ethernetif -* @return ERR_OK if the loopif is initialized -* ERR_MEM if private data couldn't be allocated -* any other err_t on error -*/ -err_t ethernetif_init(struct netif *netif) -{ -// ETH_BSP_Config(); - - LWIP_ASSERT("netif != NULL", (netif != NULL)); - -#if LWIP_NETIF_HOSTNAME - /* Initialize interface hostname */ - netif->hostname = "lwip"; -#endif /* LWIP_NETIF_HOSTNAME */ - - netif->name[0] = IFNAME0; - netif->name[1] = IFNAME1; - - netif->output = etharp_output; - netif->linkoutput = low_level_output; - - - /* initialize the hardware */ - low_level_init(netif); - - etharp_init(); - sys_timeout(ARP_TMR_INTERVAL, arp_timer, NULL); - - return ERR_OK; -} - - -static void arp_timer(void *arg) -{ - etharp_tmr(); - sys_timeout(ARP_TMR_INTERVAL, arp_timer, NULL); -} - diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/LiteOS/ethernetif.h b/code/sdk/open_source/openharmony/third_party/lwip/port/LiteOS/ethernetif.h deleted file mode 100644 index 03cf992ae..000000000 --- a/code/sdk/open_source/openharmony/third_party/lwip/port/LiteOS/ethernetif.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef __ETHERNETIF_H__ -#define __ETHERNETIF_H__ - - -#include "lwip/err.h" -#include "lwip/netif.h" - -err_t ethernetif_init(struct netif *netif); - -#endif diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/LiteOS/sys_arch.c b/code/sdk/open_source/openharmony/third_party/lwip/port/LiteOS/sys_arch.c deleted file mode 100644 index 23493aa8e..000000000 --- a/code/sdk/open_source/openharmony/third_party/lwip/port/LiteOS/sys_arch.c +++ /dev/null @@ -1,513 +0,0 @@ -/* - * Copyright (c) 2001-2003 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY - * OF SUCH DAMAGE. - * - * This file is part of the lwIP TCP/IP stack. - * - * Author: Adam Dunkels - * - */ - //============================================================================ - //Ҷ���Ƽ� 2018-05-01 ��д - //============================================================================ -#define SYS_ARCH_GLOBALS - -/* lwIP includes. */ -#include "lwip/debug.h" -#include "lwip/def.h" -#include "lwip/sys.h" -#include "lwip/mem.h" -#include "lwip/stats.h" -#include "lwip/err.h" -// #include "includes.h" -#include "arch/sys_arch.h" -#include "cmsis_os.h" -#include "los_sem.h" - -#define SYS_THREAD_MAX 6 -static u16_t s_nextthread = 0; - -/*----------------------------------------------------------------------------*/ -/* DEFINITIONS */ -/*----------------------------------------------------------------------------*/ -#define LWIP_ARCH_TICK_PER_MS 1000/OS_CFG_TICK_RATE_HZ - -/*----------------------------------------------------------------------------*/ -/* VARIABLES */ -/*----------------------------------------------------------------------------*/ - -u32_t sys_now() -{ - return LOS_TickCountGet(); -} -//===================================================================================== -/*-----------------------------------------------------------------------------------*/ -//Creates an empty mailbox. -err_t sys_mbox_new(sys_mbox_t *mbox, int size) -{ - osMessageQueueAttr_t queue_def; - (void ) size; - *mbox = osMessageQueueNew(MAX_QUEUES, MAX_QUEUE_ENTRIES,&queue_def); - -#if SYS_STATS - ++lwip_stats.sys.mbox.used; - if(lwip_stats.sys.mbox.max < lwip_stats.sys.mbox.used){ - lwip_stats.sys.mbox.max = lwip_stats.sys.mbox.used; - } -#endif /* SYS_STATS */ - if (*mbox == NULL){ - return ERR_MEM; - } - - return ERR_OK; -} - -/*-----------------------------------------------------------------------------------*/ -/* - Deallocates a mailbox. If there are messages still present in the - mailbox when the mailbox is deallocated, it is an indication of a - programming error in lwIP and the developer should be notified. -*/ -void sys_mbox_free(sys_mbox_t *mbox) -{ - if(osOK != osMessageQueueDelete(*mbox)) - { -#if SYS_STATS - lwip_stats.sys.mbox.err++; -#endif /* SYS_STATS */ - } -#if SYS_STATS - --lwip_stats.sys.mbox.used; -#endif /* SYS_STATS */ -} - -/*-----------------------------------------------------------------------------------*/ -// Posts the "msg" to the mailbox. -void sys_mbox_post(sys_mbox_t *mbox, void *data) -{ - while (osOK != osMessageQueuePut(*mbox, data,0,portMAX_DELAY)) - { - } -} - -/*-----------------------------------------------------------------------------------*/ -// Try to post the "msg" to the mailbox. -err_t sys_mbox_trypost(sys_mbox_t *mbox, void *msg) -{ - err_t result; - osStatus_t ret; - ret = osMessageQueuePut(*mbox, msg, 0,0); - if( osOK == ret) - { - result = ERR_OK; - } - else - { - result = ERR_MEM; -#if SYS_STATS - lwip_stats.sys.mbox.err++; -#endif /* SYS_STATS */ - } - return result; -} - -/*-----------------------------------------------------------------------------------*/ -/* - Blocks the thread until a message arrives in the mailbox, but does - not block the thread longer than "timeout" milliseconds (similar to - the sys_arch_sem_wait() function). The "msg" argument is a result - parameter that is set by the function (i.e., by doing "*msg = - ptr"). The "msg" parameter maybe NULL to indicate that the message - should be dropped. - - The return values are the same as for the sys_arch_sem_wait() function: - Number of milliseconds spent waiting or SYS_ARCH_TIMEOUT if there was a - timeout. - - Note that a function with a similar name, sys_mbox_fetch(), is - implemented by lwIP. -*/ -u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout) -{ - void *dummyptr; - UINT64 StartTime, EndTime, Elapsed; - osStatus_t ret; - - StartTime = LOS_TickCountGet(); - - if( msg == NULL ){ - msg = &dummyptr; - } - - if( timeout != 0 ){ - ret = osMessageQueueGet(*mbox, *msg,NULL,timeout); - if ( osOK == ret ){ - EndTime = LOS_TickCountGet(); - Elapsed = (EndTime - StartTime); - return ( Elapsed ); - } - // timed out blocking for message - else{ - *msg = NULL; - return SYS_ARCH_TIMEOUT; - } - } - // block forever for a message. - else - { - ret = osMessageQueueGet(*mbox, *msg,NULL,portMAX_DELAY); - while(osOK == ret ) - { - ret = osMessageQueueGet(*mbox, *msg,NULL,portMAX_DELAY); - } // time is arbitrary - EndTime = LOS_TickCountGet(); - Elapsed = EndTime - StartTime; - return ( Elapsed ); // return time blocked TODO test - } -} - -/*-----------------------------------------------------------------------------------*/ -/* - Similar to sys_arch_mbox_fetch, but if message is not ready immediately, we'll - return with SYS_MBOX_EMPTY. On success, 0 is returned. -*/ -u32_t sys_arch_mbox_tryfetch(sys_mbox_t *mbox, void **msg) -{ - void *dummyptr; - osStatus_t ret; - - if( msg == NULL ) - { - msg = &dummyptr; - } - ret = osMessageQueueGet(*mbox, *msg,NULL,0); - if ( osOK == ret ){ - return ERR_OK; - } - else - { - return SYS_MBOX_EMPTY; - } -} - - -static osPriority_t get_prio(int prio) -{ - osPriority_t ret = osPriorityNormal; - if (prio >= 7) - { - ret = osPriorityRealtime; - } - else if(prio == 6) - { - ret = osPriorityHigh; - } - else if(prio == 5) - { - ret = osPriorityAboveNormal; - } - else if(prio == 4) - { - ret = osPriorityNormal; - } - else if(prio == 3) - { - ret = osPriorityBelowNormal; - } - else if(prio == 2) - { - ret = osPriorityLow; - } - else if(prio == 1) - { - ret = osPriorityIdle; - } - else - { - ret = osPriorityNormal; - } - return ret; -} - -/* - Starts a new thread with priority "prio" that will begin its execution in the - function "thread()". The "arg" argument will be passed as an argument to the - thread() function. The id of the new thread is returned. Both the id and - the priority are system dependent. -*/ -sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread , void *arg, int stacksize, int prio) -{ - osThreadId_t id; - osThreadAttr_t thread_def; - - if ( s_nextthread < SYS_THREAD_MAX ) - { - thread_def.name = name; - thread_def.priority = get_prio(prio); - thread_def.stack_size = stacksize; - id = osThreadNew(thread, arg, &thread_def); - if (NULL != id) - { - return id; - } - else - { - return NULL; - } - } - else - { - return NULL; - } -} - -//===================================================================================== - -/*----------------------------------------------------------------------------------*/ -int sys_mbox_valid(sys_mbox_t *mbox) -{ - if (*mbox == SYS_MBOX_NULL){ - return 0; - } - else{ - return 1; - } -} -/*-----------------------------------------------------------------------------------*/ -void sys_mbox_set_invalid(sys_mbox_t *mbox) -{ - *mbox = SYS_MBOX_NULL; -} - -/*-----------------------------------------------------------------------------------*/ -// Creates a new semaphore. The "count" argument specifies -// the initial state of the semaphore. -err_t sys_sem_new(sys_sem_t *sem, u8_t count) -{ - u32_t ret; - ret = LOS_SemCreate(count,(UINT32 *)sem); - if(ret != LOS_OK){ -#if SYS_STATS - ++lwip_stats.sys.sem.err; -#endif /* SYS_STATS */ - return ERR_MEM; - } - // Means it can't be taken - if(count == 0){ - ret = LOS_SemPend((UINT32)*sem, 1); - } - -#if SYS_STATS - ++lwip_stats.sys.sem.used; - if (lwip_stats.sys.sem.max < lwip_stats.sys.sem.used){ - lwip_stats.sys.sem.max = lwip_stats.sys.sem.used; - } -#endif /* SYS_STATS */ - - return ERR_OK; -} - -/*-----------------------------------------------------------------------------------*/ -/* - Blocks the thread while waiting for the semaphore to be - signaled. If the "timeout" argument is non-zero, the thread should - only be blocked for the specified time (measured in - milliseconds). - - If the timeout argument is non-zero, the return value is the number of - milliseconds spent waiting for the semaphore to be signaled. If the - semaphore wasn't signaled within the specified time, the return value is - SYS_ARCH_TIMEOUT. If the thread didn't have to wait for the semaphore - (i.e., it was already signaled), the function may return zero. - - Notice that lwIP implements a function with a similar name, - sys_sem_wait(), that uses the sys_arch_sem_wait() function. -*/ -u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout) -{ - UINT64 StartTime, EndTime, Elapsed; - u32_t ret; - StartTime = LOS_TickCountGet(); - - if(timeout != 0) - { - ret = LOS_SemPend((UINT32)*sem, timeout); - if(LOS_OK == ret) - { - EndTime = LOS_TickCountGet(); - Elapsed = EndTime - StartTime; - return (Elapsed); // return time blocked TODO test - } - else - { - return SYS_ARCH_TIMEOUT; - } - } - // must block without a timeout - else - { - while(LOS_OK != LOS_SemPend((UINT32)*sem, LOS_WAIT_FOREVER)) - { - } - EndTime = LOS_TickCountGet(); - Elapsed = EndTime - StartTime; - return ( Elapsed ); // return time blocked - } -} - -/*-----------------------------------------------------------------------------------*/ -// Signals a semaphore -void sys_sem_signal(sys_sem_t *sem) -{ - LOS_SemPost((UINT32)*sem); -} - -/*-----------------------------------------------------------------------------------*/ -// Deallocates a semaphore -void sys_sem_free(sys_sem_t *sem) -{ -#if SYS_STATS - --lwip_stats.sys.sem.used; -#endif /* SYS_STATS */ - LOS_SemDelete((UINT32)*sem); -} -/*-----------------------------------------------------------------------------------*/ -int sys_sem_valid(sys_sem_t *sem) -{ - if (*sem == SYS_SEM_NULL){ - return 0; - } - else{ - return 1; - } -} - -/*-----------------------------------------------------------------------------------*/ -void sys_sem_set_invalid(sys_sem_t *sem) -{ - *sem = SYS_SEM_NULL; -} - -/*-----------------------------------------------------------------------------------*/ -// Initialize sys arch -void sys_init(void) -{ - // keep track of how many threads have been created - s_nextthread = 0; -} -/*-----------------------------------------------------------------------------------*/ - /* Mutexes*/ -/*-----------------------------------------------------------------------------------*/ -/*-----------------------------------------------------------------------------------*/ -#if LWIP_COMPAT_MUTEX == 0 -/* Create a new mutex*/ -err_t sys_mutex_new(sys_mutex_t *mutex) -{ - osMutexDef_t mutex_def; - //*mutex = xSemaphoreCreateMutex(); - *mutex = osMutexCreate (&mutex_def); - if(*mutex == NULL){ -#if SYS_STATS - ++lwip_stats.sys.mutex.err; -#endif /* SYS_STATS */ - return ERR_MEM; - } - -#if SYS_STATS - ++lwip_stats.sys.mutex.used; - if(lwip_stats.sys.mutex.max < lwip_stats.sys.mutex.used){ - lwip_stats.sys.mutex.max = lwip_stats.sys.mutex.used; - } -#endif /* SYS_STATS */ - return ERR_OK; -} -/*-----------------------------------------------------------------------------------*/ -/* Deallocate a mutex*/ -void sys_mutex_free(sys_mutex_t *mutex) -{ -#if SYS_STATS - --lwip_stats.sys.mutex.used; -#endif /* SYS_STATS */ - osMutexDelete(*mutex); -} -/*-----------------------------------------------------------------------------------*/ -/* Lock a mutex*/ -void sys_mutex_lock(sys_mutex_t *mutex) -{ - osMutexWait(*mutex, portMAX_DELAY); -} - -/*-----------------------------------------------------------------------------------*/ -/* Unlock a mutex*/ -void sys_mutex_unlock(sys_mutex_t *mutex) -{ - osMutexRelease(*mutex); -} -#endif /*LWIP_COMPAT_MUTEX*/ - -/*-----------------------------------------------------------------------------------*/ -// TODO -/*-----------------------------------------------------------------------------------*/ -/* - This optional function does a "fast" critical region protection and returns - the previous protection level. This function is only called during very short - critical regions. An embedded system which supports ISR-based drivers might - want to implement this function by disabling interrupts. Task-based systems - might want to implement this by using a mutex or disabling tasking. This - function should support recursive calls from the same task or interrupt. In - other words, sys_arch_protect() could be called while already protected. In - that case the return value indicates that it is already protected. - - sys_arch_protect() is only required if your port is supporting an operating - system. -*/ -sys_prot_t sys_arch_protect(void) -{ - sys_prot_t ret; - ret = LOS_IntLock(); - return ret; -} - -/* - This optional function does a "fast" set of critical region protection to the - value specified by pval. See the documentation for sys_arch_protect() for - more information. This function is only required if your port is supporting - an operating system. -*/ -void sys_arch_unprotect(sys_prot_t pval) -{ - LOS_IntRestore(pval); -} - -/* - * Prints an assertion messages and aborts execution. - */ -void sys_assert( const char *msg ) -{ - ( void ) msg; - LOS_IntLock(); - for(;;); -} - diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/LiteOS/sys_arch.h b/code/sdk/open_source/openharmony/third_party/lwip/port/LiteOS/sys_arch.h deleted file mode 100644 index 83d0c0806..000000000 --- a/code/sdk/open_source/openharmony/third_party/lwip/port/LiteOS/sys_arch.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2001-2003 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY - * OF SUCH DAMAGE. - * - * This file is part of the lwIP TCP/IP stack. - * - * Author: Adam Dunkels - * - */ -#ifndef __SYS_RTXC_H__ -#define __SYS_RTXC_H__ - -#include "FreeRTOS.h" -#include "task.h" -#include "queue.h" -#include "semphr.h" - -#define SYS_MBOX_NULL (xQueueHandle)0 -#define SYS_SEM_NULL (xSemaphoreHandle)0 -#define SYS_DEFAULT_THREAD_STACK_DEPTH configMINIMAL_STACK_SIZE - -typedef xSemaphoreHandle sys_sem_t; -typedef xQueueHandle sys_mbox_t; -typedef xTaskHandle sys_thread_t; - -typedef struct _sys_arch_state_t -{ - // Task creation data. - char cTaskName[configMAX_TASK_NAME_LEN]; - unsigned short nStackDepth; - unsigned short nTaskCount; -} sys_arch_state_t; - - - -//extern sys_arch_state_t s_sys_arch_state; - -//void sys_set_default_state(); -//void sys_set_state(signed char *pTaskName, unsigned short nStackSize); - -/* Message queue constants. */ -#define archMESG_QUEUE_LENGTH ( 6 ) -#endif /* __SYS_RTXC_H__ */ - diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/include/arch/bpstruct.h b/code/sdk/open_source/openharmony/third_party/lwip/port/include/arch/bpstruct.h deleted file mode 100644 index 177758c5e..000000000 --- a/code/sdk/open_source/openharmony/third_party/lwip/port/include/arch/bpstruct.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2001-2003 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY - * OF SUCH DAMAGE. - * - * This file is part of the lwIP TCP/IP stack. - * - * Author: Adam Dunkels - * - */ - -#if defined(__IAR_SYSTEMS_ICC__) -#pragma pack(1) -#endif - diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/include/arch/cc.h b/code/sdk/open_source/openharmony/third_party/lwip/port/include/arch/cc.h deleted file mode 100644 index fe872c236..000000000 --- a/code/sdk/open_source/openharmony/third_party/lwip/port/include/arch/cc.h +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (c) 2001-2003 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY - * OF SUCH DAMAGE. - * - * This file is part of the lwIP TCP/IP stack. - * - * Author: Adam Dunkels - * - */ -#ifndef __CC_H__ -#define __CC_H__ - -#include "arch/cpu.h" - -typedef unsigned char u8_t; -typedef signed char s8_t; -typedef unsigned short u16_t; -typedef signed short s16_t; -typedef unsigned long u32_t; -typedef signed long s32_t; -typedef u32_t mem_ptr_t; - -//typedef int sys_prot_t; -//#define U16_F "hu" -//#define S16_F "d" -//#define X16_F "hx" -//#define U32_F "u" -//#define S32_F "d" -//#define X32_F "x" -//#define SZT_F "uz" - -#define U16_F "4d" -#define S16_F "4d" -#define X16_F "4x" -#define U32_F "8ld" -#define S32_F "8ld" -#define X32_F "8lx" - -/* define compiler specific symbols */ -#if defined (__ICCARM__) - -#define PACK_STRUCT_BEGIN -#define PACK_STRUCT_STRUCT -#define PACK_STRUCT_END -#define PACK_STRUCT_FIELD(x) x -#define PACK_STRUCT_USE_INCLUDES - -#elif defined (__CC_ARM) - -#define PACK_STRUCT_BEGIN __packed -#define PACK_STRUCT_STRUCT -#define PACK_STRUCT_END -#define PACK_STRUCT_FIELD(x) x - -#elif defined (__GNUC__) - -#define PACK_STRUCT_BEGIN -#define PACK_STRUCT_STRUCT __attribute__ ((__packed__)) -#define PACK_STRUCT_END -#define PACK_STRUCT_FIELD(x) x - -#elif defined (__TASKING__) - -#define PACK_STRUCT_BEGIN -#define PACK_STRUCT_STRUCT -#define PACK_STRUCT_END -#define PACK_STRUCT_FIELD(x) x - -#endif - -//�궨�� -#define LWIP_PLATFORM_ASSERT(x) do { printf("Assertion \"%s\" failed at line %d in %s\n", \ - x, __LINE__, __FILE__);} while(0) - -#define LWIP_ERROR(message, expression, handler) do { if (!(expression)) { \ - printf("Assertion \"%s\" failed at line %d in %s\n", message, __LINE__, __FILE__); \ - fflush(NULL);handler;} } while(0) - -#endif /* __CC_H__ */ diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/include/arch/epstruct.h b/code/sdk/open_source/openharmony/third_party/lwip/port/include/arch/epstruct.h deleted file mode 100644 index 1e1a049cb..000000000 --- a/code/sdk/open_source/openharmony/third_party/lwip/port/include/arch/epstruct.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2001-2003 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY - * OF SUCH DAMAGE. - * - * This file is part of the lwIP TCP/IP stack. - * - * Author: Adam Dunkels - * - */ - -#if defined(__IAR_SYSTEMS_ICC__) -#pragma pack() -#endif - diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/include/arch/init.h b/code/sdk/open_source/openharmony/third_party/lwip/port/include/arch/init.h deleted file mode 100644 index e622c73ae..000000000 --- a/code/sdk/open_source/openharmony/third_party/lwip/port/include/arch/init.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2001-2003 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY - * OF SUCH DAMAGE. - * - * This file is part of the lwIP TCP/IP stack. - * - * Author: Adam Dunkels - * - */ -#ifndef __ARCH_INIT_H__ -#define __ARCH_INIT_H__ - -#define TCPIP_INIT_DONE(arg) tcpip_init_done(arg) - -void tcpip_init_done(void *); -int wait_for_tcpip_init(void); - -#endif /* __ARCH_INIT_H__ */ - - - - diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/include/arch/lib.h b/code/sdk/open_source/openharmony/third_party/lwip/port/include/arch/lib.h deleted file mode 100644 index 378f25b88..000000000 --- a/code/sdk/open_source/openharmony/third_party/lwip/port/include/arch/lib.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2001-2003 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY - * OF SUCH DAMAGE. - * - * This file is part of the lwIP TCP/IP stack. - * - * Author: Adam Dunkels - * - */ -#ifndef __LIB_H__ -#define __LIB_H__ - -#include - - -#endif /* __LIB_H__ */ diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/include/arch/perf.h b/code/sdk/open_source/openharmony/third_party/lwip/port/include/arch/perf.h deleted file mode 100644 index 334d42af8..000000000 --- a/code/sdk/open_source/openharmony/third_party/lwip/port/include/arch/perf.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2001-2003 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY - * OF SUCH DAMAGE. - * - * This file is part of the lwIP TCP/IP stack. - * - * Author: Adam Dunkels - * - */ -#ifndef __PERF_H__ -#define __PERF_H__ - -#define PERF_START /* null definition */ -#define PERF_STOP(x) /* null definition */ - -#endif /* __PERF_H__ */ diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/include/arch/sys_arch.h b/code/sdk/open_source/openharmony/third_party/lwip/port/include/arch/sys_arch.h deleted file mode 100644 index 316820301..000000000 --- a/code/sdk/open_source/openharmony/third_party/lwip/port/include/arch/sys_arch.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2001-2003 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY - * OF SUCH DAMAGE. - * - * This file is part of the lwIP TCP/IP stack. - * - * Author: Adam Dunkels - * - */ -#ifndef __SYS_RTXC_H__ -#define __SYS_RTXC_H__ - -// #include "includes.h" -#include "arch/cc.h" - -#ifdef SYS_ARCH_GLOBALS -#define SYS_ARCH_EXT -#else -#define SYS_ARCH_EXT extern -#endif - -/*-----------------macros-----------------------------------------------------*/ -#define LWIP_STK_SIZE 512 -#define LWIP_TASK_MAX 8 -/* The user can change this priority level. - * It is important that there was no crossing with other levels. - */ -#define LWIP_TSK_PRIO 3 -#define LWIP_TASK_START_PRIO LWIP_TSK_PRIO -#define LWIP_TASK_END_PRIO LWIP_TSK_PRIO +LWIP_TASK_MAX - -/* This is the number of threads that can be started with sys_thread_new() */ -#define SYS_THREAD_MAX 6 - -#define MAX_QUEUES 10 // ��Ϣ��������� -#define MAX_QUEUE_ENTRIES 20 // ÿ����Ϣ����Ĵ�С - -#define SYS_MBOX_NULL (void *)0 -#define SYS_SEM_NULL (void *)0 - -//#define sys_arch_mbox_tryfetch(mbox,msg) sys_arch_mbox_fetch(mbox,msg,1) -/** struct of LwIP mailbox */ - - -// typedef OS_SEM sys_sem_t; // type of semiphores -// typedef OS_MUTEX sys_mutex_t; // type of mutex -// typedef OS_Q sys_mbox_t; // type of mailboxes -// typedef CPU_INT08U sys_thread_t; // type of id of the new thread -// typedef CPU_INT08U sys_prot_t; -typedef void* sys_sem_t; -typedef void* sys_mutex_t; -typedef void* sys_mbox_t; -typedef void* sys_thread_t; -typedef unsigned long sys_prot_t; - -#define portMAX_DELAY 0xffffffffUL - -#endif /* __SYS_RTXC_H__ */ - diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/include/lwipopts.h b/code/sdk/open_source/openharmony/third_party/lwip/port/include/lwipopts.h deleted file mode 100644 index 3787af9d3..000000000 --- a/code/sdk/open_source/openharmony/third_party/lwip/port/include/lwipopts.h +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (c) 2001-2003 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY - * OF SUCH DAMAGE. - * - * This file is part of the lwIP TCP/IP stack. - * - * Author: Simon Goldschmidt - * - */ -#ifndef LWIP_HDR_LWIPOPTS_H__ -#define LWIP_HDR_LWIPOPTS_H__ - -/* Prevent having to link sys_arch.c (we don't test the API layers in unit tests) */ -#if 0 -#define NO_SYS 1 -#else -#define NO_SYS 0 -#define LWIP_COMPAT_MUTEX_ALLOWED 1 -#endif - -#define LWIP_NETCONN 0 -#define LWIP_SOCKET 1 -#define SYS_LIGHTWEIGHT_PROT 0 -#define LWIP_COMPAT_MUTEX 2 -#define LWIP_IPV4 1 -#define LWIP_IPV6 1 -#define IPV6_FRAG_COPYHEADER 1 -#define LWIP_IPV6_DUP_DETECT_ATTEMPTS 0 - -/* Enable some protocols to test them */ -#define LWIP_DHCP 0 -#define LWIP_AUTOIP 0 - -#define LWIP_IGMP 1 -#define LWIP_DNS 1 - -#define LWIP_ALTCP 1 - -/* Turn off checksum verification of fuzzed data */ -#define CHECKSUM_CHECK_IP 0 -#define CHECKSUM_CHECK_UDP 0 -#define CHECKSUM_CHECK_TCP 0 -#define CHECKSUM_CHECK_ICMP 0 -#define CHECKSUM_CHECK_ICMP6 0 - -#define MEM_USE_POOLS 0 -#define MEM_LIBC_MALLOC 1 -#define SLIP_USE_RX_THREAD 1 - -/* Minimal changes to opt.h required for tcp unit tests: */ -#define MEM_SIZE (1*1024) -#define MEMP_NUM_TCP_SEG TCP_SND_QUEUELEN -#define TCP_OVERSIZE 1 -#define TCP_SND_BUF (4 * TCP_MSS) /*TCP_MSS 536 as default**/ -#define TCP_WND (2 * TCP_MSS) -#define TCP_SND_QUEUELEN ((8 * (TCP_SND_BUF)) / (TCP_MSS)) -#define LWIP_WND_SCALE 1 -#define TCP_RCV_SCALE 2 -#define PBUF_POOL_SIZE 4 /* pbuf tests need ~200KByte */ - -/* Minimal changes to opt.h required for etharp unit tests: */ -#define ETHARP_SUPPORT_STATIC_ENTRIES 1 - -#define LWIP_NUM_NETIF_CLIENT_DATA 1 -#define LWIP_SNMP 1 -#define MIB2_STATS 1 -#define LWIP_MDNS_RESPONDER 1 -#define SLIP_DEBUG 0x80U //LWIP_DBG_ON -#define LWIP_DEBUG - -#define LWIP_POSIX_SOCKETS_IO_NAMES 0 -#define MEMP_MEM_MALLOC 1 -#define LWIP_UDP 1 -#define LWIP_TCP 1 -#endif /* LWIP_HDR_LWIPOPTS_H__ */ diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/BUILD.gn b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/BUILD.gn new file mode 100644 index 000000000..650253516 --- /dev/null +++ b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/BUILD.gn @@ -0,0 +1,42 @@ +# Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import("//kernel/liteos_m/liteos.gni") +import("$LITEOSTHIRDPARTY/lwip/lwip.gni") +import("$LITEOSTOPDIR/components/net/lwip-2.1/lwip_porting.gni") + +module_switch = defined(LOSCFG_NET_LWIP_SACK) +module_name = "lwip" +kernel_module(module_name) { + sources = LWIP_PORTING_FILES + LWIPNOAPPSFILES - [ "$LWIPDIR/api/sockets.c" ] + include_dirs = [ "//commonlibrary/utils_lite/include" ] +} + +config("public") { + include_dirs = LWIP_PORTING_INCLUDE_DIRS + LWIP_INCLUDE_DIRS +} diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/enhancement/src/fixme.c b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/enhancement/src/fixme.c new file mode 100644 index 000000000..aa24063c7 --- /dev/null +++ b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/enhancement/src/fixme.c @@ -0,0 +1,199 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include + +#define NETIFAPI_VAR_REF(name) API_VAR_REF(name) +#define NETIFAPI_VAR_DECLARE(name) API_VAR_DECLARE(struct netifapi_msg, name) +#define NETIFAPI_VAR_ALLOC(name) API_VAR_ALLOC(struct netifapi_msg, MEMP_NETIFAPI_MSG, name, ERR_MEM) +#define NETIFAPI_VAR_FREE(name) API_VAR_FREE(MEMP_NETIFAPI_MSG, name) + +#if LWIP_DHCP +#include +#include + +err_t dhcp_is_bound(struct netif *netif) +{ + struct dhcp *dhcp = NULL; + + LWIP_ERROR("netif != NULL", (netif != NULL), return ERR_ARG); + + dhcp = netif_dhcp_data(netif); + LWIP_ERROR("netif->dhcp != NULL", (dhcp != NULL), return ERR_ARG); + + if (dhcp->state == DHCP_STATE_BOUND) { + return ERR_OK; + } else { + return ERR_INPROGRESS; + } +} +#endif /* LWIP_DHCP */ + +static struct netif *netif_find_by_name(const char *name) +{ + struct netif *netif = NULL; + LWIP_ASSERT_CORE_LOCKED(); + if (name == NULL) { + return NULL; + } + NETIF_FOREACH(netif) { + if (strcmp("lo", name) == 0 && (netif->name[0] == 'l' && netif->name[1] == 'o')) { + LWIP_DEBUGF(NETIF_DEBUG, ("netif_find_by_name: found lo\n")); + return netif; + } + + if (strcmp(netif->full_name, name) == 0) { + LWIP_DEBUGF(NETIF_DEBUG, ("netif_find_by_name: found %s\n", name)); + return netif; + } + } + + LWIP_DEBUGF(NETIF_DEBUG, ("netif_find_by_name: didn't find %s\n", name)); + return NULL; +} + +static err_t netifapi_do_find_by_name(struct tcpip_api_call_data *m) +{ + /* cast through void* to silence alignment warnings. + * We know it works because the structs have been instantiated as struct netifapi_msg */ + struct netifapi_msg *msg = (struct netifapi_msg *)(void *)m; + msg->netif = netif_find_by_name(msg->msg.ifs.name); + return ERR_OK; +} + +struct netif *netifapi_netif_find_by_name(const char *name) +{ + struct netif *netif = NULL; + NETIFAPI_VAR_DECLARE(msg); + NETIFAPI_VAR_ALLOC(msg); + NETIFAPI_VAR_REF(msg).netif = NULL; +#if LWIP_MPU_COMPATIBLE + if (strncpy_s(NETIFAPI_VAR_REF(msg).msg.ifs.name, NETIF_NAMESIZE, name, NETIF_NAMESIZE - 1)) { + NETIFAPI_VAR_FREE(msg); + return netif; + } + NETIFAPI_VAR_REF(msg).msg.ifs.name[NETIF_NAMESIZE - 1] = '\0'; +#else + NETIFAPI_VAR_REF(msg).msg.ifs.name = (char *)name; +#endif /* LWIP_MPU_COMPATIBLE */ + + (void)tcpip_api_call(netifapi_do_find_by_name, &API_VAR_REF(msg).call); + netif = msg.netif; + NETIFAPI_VAR_FREE(msg); + return netif; +} + +#if LWIP_IPV6 +int ip6addr_aton(const char *cp, ip6_addr_t *addr) +{ + const int ipv6_blocks = 8; + u16_t current_block_index = 0; + u16_t current_block_value = 0; + u16_t addr16[ipv6_blocks]; + u16_t *a16 = (u16_t *)addr->addr; + int squash_pos = ipv6_blocks; + int i; + const unsigned char *sc = (const unsigned char *)cp; + const unsigned char *ss = (const unsigned char *)(cp - 1); + + for (; ; sc++) { + if (current_block_index >= ipv6_blocks) { + return 0; // address too long + } + if (*sc == 0) { + if (sc - ss == 1) { + if (squash_pos != current_block_index) { + return 0; // empty address or address ends with a single ':' + } // else address ends with one valid "::" + } else { + addr16[current_block_index++] = current_block_value; + } + break; + } else if (*sc == ':') { + if (sc - ss == 1) { + if (sc != (const unsigned char *)cp || sc[1] != ':') { + return 0; // address begins with a single ':' or contains ":::" + } // else address begins with one valid "::" + } else { + addr16[current_block_index++] = current_block_value; + } + if (sc[1] == ':') { + if (squash_pos != ipv6_blocks) { + return 0; // more than one "::" + } + squash_pos = current_block_index; + sc++; + } + ss = sc; // ss points to the recent ':' position + current_block_value = 0; + } else if (lwip_isxdigit(*sc) && (sc - ss) < 5) { // 4 hex-digits at most + current_block_value = (current_block_value << 4) + + (*sc | ('a' - 'A')) - '0' - ('a' - '9' - 1) * (*sc >= 'A'); +#if LWIP_IPV4 + } else if (*sc == '.' && current_block_index < ipv6_blocks - 1) { + ip4_addr_t ip4; + int ret = ip4addr_aton((const char *)(ss + 1), &ip4); + if (!ret) { + return 0; + } + ip4.addr = lwip_ntohl(ip4.addr); + addr16[current_block_index++] = (u16_t)(ip4.addr >> 16); + addr16[current_block_index++] = (u16_t)(ip4.addr); + break; +#endif /* LWIP_IPV4 */ + } else { + return 0; // unexpected char or too many digits + } + } + + if (squash_pos == ipv6_blocks && current_block_index != ipv6_blocks) { + return 0; // address too short + } + if (squash_pos != ipv6_blocks && current_block_index == ipv6_blocks) { + return 0; // unexpected "::" in address + } + + for (i = 0; i < squash_pos; ++i) { + a16[i] = lwip_htons(addr16[i]); + } + for (; i < ipv6_blocks - current_block_index + squash_pos; ++i) { + a16[i] = 0; + } + for (; i < ipv6_blocks; ++i) { + a16[i] = lwip_htons(addr16[i - ipv6_blocks + current_block_index]); + } + + return 1; +} +#endif /* LWIP_IPV6 */ diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/enhancement/src/lwip_ifaddrs.c b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/enhancement/src/lwip_ifaddrs.c new file mode 100644 index 000000000..97ba25993 --- /dev/null +++ b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/enhancement/src/lwip_ifaddrs.c @@ -0,0 +1,334 @@ +/* + * Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "lwip/opt.h" + +#if LWIP_IFADDRS +#if (LWIP_IPV4 || LWIP_IPV6) && LWIP_SOCKET +#include "ifaddrs.h" + +#include + +#include "lwip/sys.h" +#include "lwip/tcpip.h" +#include "lwip/priv/sockets_priv.h" +#include "lwip/mem.h" +#include "lwip/netif.h" +#include "lwip/dhcp.h" + +struct ifaddrs_storage { + struct ifaddrs ifa; + union { + struct sockaddr sa; + struct sockaddr_in s4; +#if LWIP_IPV6 + struct sockaddr_in6 s6; +#endif + } addr, netmask, dstaddr; + char name[IFNAMSIZ]; +}; + +struct getifaddrs_arg { + struct ifaddrs **ifap; + sys_sem_t cb_completed; + int ret; +}; + +static int tcpip_init_finish = 1; +void lwip_freeifaddrs(struct ifaddrs *ifa); +static void ifaddrs_add_tail(struct ifaddrs **ifap, struct ifaddrs *ifaddr) +{ + struct ifaddrs *temp = NULL; + + ifaddr->ifa_next = NULL; + if (*ifap == NULL) { + *ifap = ifaddr; + return; + } + + for (temp = *ifap; temp->ifa_next != NULL; temp = temp->ifa_next) { + /* nothing */ + } + + temp->ifa_next = ifaddr; +} + +static struct ifaddrs_storage *new_ifaddrs_storage(void) +{ + struct ifaddrs *ifaddr = NULL; + struct ifaddrs_storage *if_storage = NULL; + + if_storage = (struct ifaddrs_storage *)mem_malloc(sizeof(struct ifaddrs_storage)); + if (if_storage != NULL) { + (void)memset_s((void*)if_storage, sizeof(struct ifaddrs_storage), 0, sizeof(struct ifaddrs_storage)); + ifaddr = &if_storage->ifa; + ifaddr->ifa_name = if_storage->name; + ifaddr->ifa_addr = &if_storage->addr.sa; + ifaddr->ifa_netmask = &if_storage->netmask.sa; + ifaddr->ifa_dstaddr = &if_storage->dstaddr.sa; + } + + return if_storage; +} + +static int get_ifa_name(struct netif *netif, struct ifaddrs *ifaddr) +{ + int ret; + + if (netif->link_layer_type == LOOPBACK_IF) { + ifaddr->ifa_flags |= IFF_LOOPBACK; + ret = snprintf_s(ifaddr->ifa_name, NETIF_NAMESIZE, (NETIF_NAMESIZE - 1), "%.2s", netif->name); + } else { + ret = snprintf_s(ifaddr->ifa_name, NETIF_NAMESIZE, (NETIF_NAMESIZE - 1), "%s", netif_get_name(netif)); + } + + return ret; +} + +#if LWIP_IPV4 +static int get_ipv4_ifaddr(struct netif *netif, struct ifaddrs *ifaddr) +{ + struct sockaddr_in *addr_in = NULL; + + if (netif->flags & NETIF_FLAG_UP) { + ifaddr->ifa_flags |= IFF_UP; + } + + if (netif->flags & NETIF_FLAG_ETHARP) { + ifaddr->ifa_flags = ifaddr->ifa_flags & ((unsigned int)(~IFF_NOARP)); + } else { + ifaddr->ifa_flags |= IFF_NOARP; + } + + if (netif->flags & NETIF_FLAG_BROADCAST) { + ifaddr->ifa_flags |= IFF_BROADCAST; + } + +#if LWIP_DHCP + if (dhcp_supplied_address(netif)) { + ifaddr->ifa_flags |= IFF_DYNAMIC; + } +#endif + +#if LWIP_IGMP + if (netif->flags & NETIF_FLAG_IGMP) { + ifaddr->ifa_flags |= IFF_MULTICAST; + } +#endif + + if (netif->flags & NETIF_FLAG_LINK_UP) { + ifaddr->ifa_flags |= IFF_RUNNING; + } + +#if LWIP_HAVE_LOOPIF + if (netif->link_layer_type == LOOPBACK_IF) { + addr_in = (struct sockaddr_in *)ifaddr->ifa_addr; + addr_in->sin_family = AF_INET; + addr_in->sin_addr.s_addr = ((ip4_addr_t *)&netif->ip_addr)->addr; + } else +#endif + { + addr_in = (struct sockaddr_in *)ifaddr->ifa_addr; + addr_in->sin_family = AF_INET; + addr_in->sin_addr.s_addr = ((ip4_addr_t *)&netif->ip_addr)->addr; + + addr_in = (struct sockaddr_in *)ifaddr->ifa_netmask; + addr_in->sin_family = AF_INET; + addr_in->sin_addr.s_addr = ((ip4_addr_t *)&netif->netmask)->addr; + + addr_in = (struct sockaddr_in *)ifaddr->ifa_broadaddr; + addr_in->sin_family = AF_INET; + addr_in->sin_addr.s_addr = (((ip4_addr_t *)&netif->ip_addr)->addr & ((ip4_addr_t *)&netif->netmask)->addr) | + ~((ip4_addr_t *)&netif->netmask)->addr; + } + + return get_ifa_name(netif, ifaddr); +} +#endif /* LWIP_IPV4 */ + +#if LWIP_IPV6 +/* Stack support to retrieve the below flags for ipv6 +IFF_UP +IFF_MULTICAST +IFF_RUNNING +IFF_LOOPBACK +*/ +static int get_ipv6_ifaddr(struct netif *netif, struct ifaddrs *ifaddr, int tmp_index) +{ + struct sockaddr_in6 *addr_in6 = NULL; + + /* As of now supports the below falgs only */ + if (netif->flags & NETIF_FLAG_UP) { + ifaddr->ifa_flags |= IFF_UP; + } + +#if LWIP_IPV6_MLD + if (netif->flags & NETIF_FLAG_MLD6) { + ifaddr->ifa_flags |= IFF_MULTICAST; + } +#endif + + if (netif->flags & NETIF_FLAG_LINK_UP) { + ifaddr->ifa_flags |= IFF_RUNNING; + } + + addr_in6 = (struct sockaddr_in6 *)ifaddr->ifa_addr; + addr_in6->sin6_family = AF_INET6; + inet6_addr_from_ip6addr(&addr_in6->sin6_addr, (ip6_addr_t *)&netif->ip6_addr[tmp_index]); + + return get_ifa_name(netif, ifaddr); +} +#endif + +static void getifaddrs_internal(struct getifaddrs_arg *arg) +{ + struct netif *netif = NULL; + struct ifaddrs *ifaddr = NULL; + struct ifaddrs_storage *if_storage = NULL; + +#if LWIP_IPV6 + int n; +#endif + + arg->ret = ENOMEM; + for (netif = netif_list; netif != NULL; netif = netif->next) { +#if LWIP_IPV4 + if_storage = new_ifaddrs_storage(); + if (if_storage == NULL) { + lwip_freeifaddrs( + *(arg->ifap)); /* ifap is assigned to NULL in getifaddrs, so garbage value will not be there */ + arg->ret = ENOMEM; + goto RETURN; + } + + /* if get one or more netif info, then getifaddrs return 0(OK) */ + arg->ret = 0; + ifaddr = &if_storage->ifa; + (void)get_ipv4_ifaddr(netif, ifaddr); + ifaddrs_add_tail(arg->ifap, ifaddr); +#endif /* LWIP_IPV4 */ +#if LWIP_IPV6 + for (n = 0; n < LWIP_IPV6_NUM_ADDRESSES; n++) { + if ((netif->ip6_addr_state[n] & IP6_ADDR_VALID) == 0) { + continue; + } + if_storage = new_ifaddrs_storage(); + if (if_storage == NULL) { + lwip_freeifaddrs( + *(arg->ifap)); /* ifap is assigned to NULL in getifaddrs, so garbage value will not be there */ + arg->ret = ENOMEM; + goto RETURN; + } + + /* if get one or more netif info, then getifaddrs return 0(OK) */ + arg->ret = 0; + ifaddr = &if_storage->ifa; + (void)get_ipv6_ifaddr(netif, ifaddr, n); + ifaddrs_add_tail(arg->ifap, ifaddr); + } +#endif + } + +RETURN: +#if !LWIP_TCPIP_CORE_LOCKING + sys_sem_signal(&arg->cb_completed); +#endif + return; +} + +int lwip_getifaddrs(struct ifaddrs **ifap) +{ + struct getifaddrs_arg arg; + + LWIP_ERROR("lwip_getifaddrs : ifap is NULL", (ifap != NULL), return ERR_ARG); + *ifap = NULL; + + if (!tcpip_init_finish) { + set_errno(EACCES); + return -1; + } + arg.ret = 0; + arg.ifap = ifap; + +#if LWIP_TCPIP_CORE_LOCKING + LOCK_TCPIP_CORE(); + getifaddrs_internal(&arg); + UNLOCK_TCPIP_CORE(); +#else + + if (sys_sem_new(&arg.cb_completed, 0) != ERR_OK) { + set_errno(ENOMEM); + return -1; + } + + tcpip_callback((tcpip_callback_fn)getifaddrs_internal, &arg); + (void)sys_arch_sem_wait(&arg.cb_completed, 0); + sys_sem_free(&arg.cb_completed); +#endif + + if (arg.ret != 0) { + set_errno(arg.ret); + *ifap = NULL; + return -1; + } + + return 0; +} + +static void freeifaddrs_iteration(struct ifaddrs *ifa) +{ + if (ifa == NULL) { + return; + } + + if (ifa->ifa_next != NULL) { + freeifaddrs_iteration(ifa->ifa_next); + } + + mem_free(ifa); +} + +void lwip_freeifaddrs(struct ifaddrs *ifa) +{ + freeifaddrs_iteration(ifa); +} + +int getifaddrs(struct ifaddrs **ifap) +{ + return lwip_getifaddrs(ifap); +} + +void freeifaddrs(struct ifaddrs *ifa) +{ + lwip_freeifaddrs(ifa); +} + +#endif /* (LWIP_IPV4 || LWIP_IPV6) && LWIP_SOCKET */ +#endif /* LWIP_IFADDRS */ \ No newline at end of file diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/lwip_porting.gni b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/lwip_porting.gni new file mode 100644 index 000000000..9b03eb9a1 --- /dev/null +++ b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/lwip_porting.gni @@ -0,0 +1,46 @@ +# Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import("//kernel/liteos_m/liteos.gni") + +LWIP_PORTING_DIR = get_path_info(".", "abspath") + +LWIP_PORTING_INCLUDE_DIRS = [ "$LWIP_PORTING_DIR/porting/include" ] + +LWIP_PORTING_FILES = [ + "$LWIP_PORTING_DIR/porting/src/driverif.c", + "$LWIP_PORTING_DIR/porting/src/netdb_porting.c", + "$LWIP_PORTING_DIR/porting/src/sockets_porting.c", + "$LWIP_PORTING_DIR/porting/src/sys_arch.c", + "$LWIP_PORTING_DIR/enhancement/src/fixme.c", + "$LWIP_PORTING_DIR/enhancement/src/lwip_ifaddrs.c", +] + +if (defined(LOSCFG_SHELL)) { + LWIP_PORTING_FILES += [ "$LWIP_PORTING_DIR/porting/src/api_shell.c" ] +} diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/arch/cc.h b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/arch/cc.h new file mode 100644 index 000000000..c776b2fe5 --- /dev/null +++ b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/arch/cc.h @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LWIP_PORTING_CC_H_ +#define _LWIP_PORTING_CC_H_ + +#ifdef LITTLE_ENDIAN +#undef LITTLE_ENDIAN +#endif + +#ifdef BIG_ENDIAN +#undef BIG_ENDIAN +#endif + +#include +#include +#include +#include "securec.h" + +#ifdef htons +#define LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS +#endif + +// #define SOCKLEN_T_DEFINED +// #define SA_FAMILY_T_DEFINED +// #define IN_PORT_T_DEFINED + +#define LWIP_TIMEVAL_PRIVATE 1 +#define LWIP_ERRNO_STDINCLUDE +#define LWIP_SOCKET_STDINCLUDE + +#define LWIP_DNS_API_DEFINE_ERRORS 0 +#define LWIP_DNS_API_DEFINE_FLAGS 0 +#define LWIP_DNS_API_DECLARE_STRUCTS 0 +#define LWIP_DNS_API_DECLARE_H_ERRNO 0 + +#ifndef __SIZEOF_POINTER__ +#define __SIZEOF_POINTER__ 4 // 32 bit system +#endif + +// #define LOS_TASK_STATUS_DETACHED 0x0100 // reserved + +#if defined(__arm__) && defined(__ARMCC_VERSION) + /* Keil uVision4 tools */ + #define PACK_STRUCT_BEGIN __packed + #define PACK_STRUCT_STRUCT + #define PACK_STRUCT_END + #define PACK_STRUCT_FIELD(fld) fld + #define ALIGNED(n) __align(n) +#elif defined (__IAR_SYSTEMS_ICC__) + /* IAR Embedded Workbench tools */ + #define PACK_STRUCT_BEGIN __packed + #define PACK_STRUCT_STRUCT + #define PACK_STRUCT_END + #define PACK_STRUCT_FIELD(fld) fld + // #error NEEDS ALIGNED +#else + /* GCC tools (CodeSourcery) */ + #define PACK_STRUCT_BEGIN + #define PACK_STRUCT_STRUCT __attribute__ ((__packed__)) + #define PACK_STRUCT_END + #define PACK_STRUCT_FIELD(fld) fld + #define ALIGNED(n) __attribute__((aligned (n))) +#endif + +#define LWIP_RAND rand + +#ifndef LWIP_LOGGER +#define LWIP_LOGGER(msg) +#endif + +extern void LwipLogPrintf(const char *fmt, ...); +#define LWIP_PLATFORM_DIAG(vars) LwipLogPrintf vars +#define LWIP_PLATFORM_ASSERT(x) do { \ + LWIP_PLATFORM_DIAG(("Assertion \"%s\" failed at line %d in %s\n", x, __LINE__, __FILE__)); \ + } while (0) + +// #define init_waitqueue_head(...) +// #define poll_check_waiters(...) + +#ifndef _BSD_SOURCE +#define _BSD_SOURCE 1 +#endif + +#endif /* _LWIP_PORTING_CC_H_ */ diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/arch/perf.h b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/arch/perf.h new file mode 100644 index 000000000..43147ef77 --- /dev/null +++ b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/arch/perf.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LWIP_PORTING_PERF_H_ +#define _LWIP_PORTING_PERF_H_ + +#if LWIP_PERF + +#define PERF_START do { /* something to do */ } while (0) +#define PERF_STOP(x) do { /* something to do */ } while (0) + +#endif + +#endif /* _LWIP_PORTING_PERF_H_ */ diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/arch/sys_arch.h b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/arch/sys_arch.h new file mode 100644 index 000000000..3541e9072 --- /dev/null +++ b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/arch/sys_arch.h @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LWIP_PORTING_SYS_ARCH_H_ +#define _LWIP_PORTING_SYS_ARCH_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Mutex + */ +typedef uint32_t sys_mutex_t; + +/** + * Semaphore + */ +typedef uint32_t sys_sem_t; + +/** + * MessageBox + */ +typedef uint32_t sys_mbox_t; + +/** + * Protector + */ +typedef void *sys_prot_t; + +/** + * Thread + */ +typedef uint32_t sys_thread_t; + +#ifdef __cplusplus +} +#endif + +#endif /* _LWIP_PORTING_SYS_ARCH_H_ */ diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/lwip/api_shell.h b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/lwip/api_shell.h new file mode 100644 index 000000000..7e063a156 --- /dev/null +++ b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/lwip/api_shell.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef LWIP_API_SHELL_H +#define LWIP_API_SHELL_H + +#include "arch/cc.h" +#include "lwip/opt.h" + +#if defined (__cplusplus) && __cplusplus +extern "C" { +#endif + +u32_t lwip_ifconfig(int argc, const char **argv); +u32_t OsShellPing(int argc, const char **argv); +LWIP_STATIC int OsPingFunc(u32_t *parg); + +#if defined (__cplusplus) && __cplusplus +} +#endif +#endif /* LWIP_HDR_API_SHELL_H */ diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/lwip/dhcp.h b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/lwip/dhcp.h new file mode 100644 index 000000000..70f9b9bf9 --- /dev/null +++ b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/lwip/dhcp.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LWIP_PORTING_DHCP_H_ +#define _LWIP_PORTING_DHCP_H_ + +#include_next + +err_t dhcp_is_bound(struct netif *netif); + +#endif /* _LWIP_PORTING_DHCP_H_ */ diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/lwip/inet.h b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/lwip/inet.h new file mode 100644 index 000000000..5f1dacc73 --- /dev/null +++ b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/lwip/inet.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LWIP_PORTING_INET_H_ +#define _LWIP_PORTING_INET_H_ + +#include +#include +#include_next + +#if LWIP_IPV4 +#define inet_addr_from_ip4addr(target_inaddr, source_ipaddr) \ + ((target_inaddr)->s_addr = ip4_addr_get_u32(source_ipaddr)) +#define inet_addr_to_ip4addr(target_ipaddr, source_inaddr) \ + (ip4_addr_set_u32(target_ipaddr, (source_inaddr)->s_addr)) + +/* directly map this to the lwip internal functions */ +#define inet_ntoa_r(addr, buf, buflen) ip4addr_ntoa_r((const ip4_addr_t*)&(addr), buf, buflen) +#endif /* LWIP_IPV4 */ +#if LWIP_IPV6 +#define inet6_addr_from_ip6addr(target_in6addr, source_ip6addr) \ + {(target_in6addr)->s6_addr32[0] = (source_ip6addr)->addr[0]; \ + (target_in6addr)->s6_addr32[1] = (source_ip6addr)->addr[1]; \ + (target_in6addr)->s6_addr32[2] = (source_ip6addr)->addr[2]; \ + (target_in6addr)->s6_addr32[3] = (source_ip6addr)->addr[3];} +#define inet6_addr_to_ip6addr(target_ip6addr, source_in6addr) \ + {(target_ip6addr)->addr[0] = (source_in6addr)->s6_addr32[0]; \ + (target_ip6addr)->addr[1] = (source_in6addr)->s6_addr32[1]; \ + (target_ip6addr)->addr[2] = (source_in6addr)->s6_addr32[2]; \ + (target_ip6addr)->addr[3] = (source_in6addr)->s6_addr32[3]; \ + ip6_addr_clear_zone(target_ip6addr);} +#endif /* LWIP_IPV6 */ + +#endif /* _LWIP_PORTING_INET_H_ */ diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/lwip/lwipopts.h b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/lwip/lwipopts.h new file mode 100644 index 000000000..8191880e3 --- /dev/null +++ b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/lwip/lwipopts.h @@ -0,0 +1,251 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LWIP_PORTING_LWIPOPTS_H_ +#define _LWIP_PORTING_LWIPOPTS_H_ + +// lwIP debug options, comment the ones you don't want +#define LWIP_DEBUG 1 +#if LWIP_DEBUG +#define ETHARP_DEBUG LWIP_DBG_OFF +#define NETIF_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 SOCKETS_DEBUG LWIP_DBG_OFF +#define ICMP_DEBUG LWIP_DBG_OFF +#define IGMP_DEBUG LWIP_DBG_OFF +#define INET_DEBUG LWIP_DBG_OFF +#define IP_DEBUG LWIP_DBG_OFF +#define DRIVERIF_DEBUG LWIP_DBG_OFF +#define IP_REASS_DEBUG LWIP_DBG_OFF +#define RAW_DEBUG LWIP_DBG_OFF +#define MEM_DEBUG LWIP_DBG_OFF +#define MEMP_DEBUG LWIP_DBG_OFF +#define SYS_DEBUG LWIP_DBG_OFF +#define TIMERS_DEBUG LWIP_DBG_OFF +#define TCP_DEBUG LWIP_DBG_OFF +#define TCP_ERR_DEBUG LWIP_DBG_OFF +#define TCP_INPUT_DEBUG LWIP_DBG_OFF +#define TCP_FR_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_OUTPUT_DEBUG LWIP_DBG_OFF +#define TCP_RST_DEBUG LWIP_DBG_OFF +#define TCP_QLEN_DEBUG LWIP_DBG_OFF +#define TCP_SACK_DEBUG LWIP_DBG_OFF +#define TCP_TLP_DEBUG LWIP_DBG_OFF +#define UDP_DEBUG LWIP_DBG_OFF +#define TCPIP_DEBUG LWIP_DBG_OFF +#define SLIP_DEBUG LWIP_DBG_OFF +#define DHCP_DEBUG LWIP_DBG_OFF +#define AUTOIP_DEBUG LWIP_DBG_OFF +#define DNS_DEBUG LWIP_DBG_OFF +#define TFTP_DEBUG LWIP_DBG_OFF +#define SYS_ARCH_DEBUG LWIP_DBG_OFF +#define SNTP_DEBUG LWIP_DBG_OFF +#define IP6_DEBUG LWIP_DBG_OFF +#define DHCP6_DEBUG LWIP_DBG_OFF +#define DRV_STS_DEBUG LWIP_DBG_OFF +#endif + +// Options only in new opt.h +#define LWIP_SOCKET_SELECT 0 +#define LWIP_SOCKET_POLL 1 + +// Options in old opt.h that differs from new opt.h +#define MEM_ALIGNMENT __SIZEOF_POINTER__ +#define MEMP_NUM_NETDB 8 +#define IP_REASS_MAXAGE 3 +#define IP_SOF_BROADCAST 1 +#define IP_SOF_BROADCAST_RECV 1 +#define LWIP_MULTICAST_PING 1 +#define LWIP_RAW 1 +#define LWIP_DHCP_AUTOIP_COOP_TRIES 64 +#define TCP_LISTEN_BACKLOG 1 +#define TCP_DEFAULT_LISTEN_BACKLOG 16 + +#define LWIP_WND_SCALE 1 +#define TCP_RCV_SCALE 7 + +#define LWIP_NETIF_HOSTNAME 1 +#define LWIP_NETIF_TX_SINGLE_PBUF 1 +#define LWIP_NETCONN_FULLDUPLEX 1 // Caution +#define LWIP_COMPAT_SOCKETS 1 //2 +#define LWIP_POSIX_SOCKETS_IO_NAMES 0 +#define LWIP_TCP_KEEPALIVE 1 +#define RECV_BUFSIZE_DEFAULT 65535 +#define SO_REUSE_RXTOALL 1 + +#define LWIP_CHECKSUM_ON_COPY 1 +#define LWIP_IPV6 1 +#define LWIP_IPV6_NUM_ADDRESSES 5 +#define LWIP_ND6_NUM_PREFIXES 10 +#define LWIP_IPV6_DHCP6 1 +#define LWIP_IPV6_DHCP6_STATEFUL 1 + +// Options in old lwipopts.h +#define ARP_QUEUEING 1 +#define DEFAULT_ACCEPTMBOX_SIZE 32 +#define DEFAULT_RAW_RECVMBOX_SIZE 128 +#define DEFAULT_TCP_RECVMBOX_SIZE 128 +#define DEFAULT_UDP_RECVMBOX_SIZE 128 +#define ETHARP_SUPPORT_STATIC_ENTRIES 1 +#define ETH_PAD_SIZE 2 +#define IP_REASS_MAX_PBUFS (((65535) / (IP_FRAG_MAX_MTU - 20 - 8) + 1) * MEMP_NUM_REASSDATA) +// #define LWIP_COMPAT_SOCKETS 2 +#define LWIP_DBG_MIN_LEVEL LWIP_DBG_LEVEL_OFF +#define LWIP_DHCP 1 +#define LWIP_DNS 1 +#define LWIP_ETHERNET 1 +#define LWIP_HAVE_LOOPIF 1 +#define LWIP_IGMP 1 +#define LWIP_NETIF_API 1 +#define LWIP_NETIF_LINK_CALLBACK 1 +#define LWIP_NETIF_LOOPBACK 1 +#define LWIP_POSIX_SOCKETS_IO_NAMES 0 +#define LWIP_RAW 1 +#define LWIP_SO_RCVBUF 1 +#define LWIP_SO_RCVTIMEO 1 +#define LWIP_SO_SNDTIMEO 1 +#define LWIP_STATS_DISPLAY 1 +#define MEM_LIBC_MALLOC 1 +#define MEMP_NUM_ARP_QUEUE (65535 * LWIP_CONFIG_NUM_SOCKETS / (IP_FRAG_MAX_MTU - 20 - 8)) +#define MEMP_NUM_NETBUF (65535 * 3 * LWIP_CONFIG_NUM_SOCKETS / (IP_FRAG_MAX_MTU - 20 - 8)) +#define MEMP_NUM_NETCONN LWIP_CONFIG_NUM_SOCKETS +#define MEMP_NUM_PBUF LWIP_CONFIG_NUM_SOCKETS*2 +#define MEMP_NUM_RAW_PCB LWIP_CONFIG_NUM_SOCKETS +#define MEMP_NUM_REASSDATA (IP_REASS_MAX_MEM_SIZE / 65535) +#define MEMP_NUM_TCPIP_MSG_API 64 +#define MEMP_NUM_TCPIP_MSG_INPKT 512 +#define MEMP_NUM_TCP_PCB LWIP_CONFIG_NUM_SOCKETS +#define MEMP_NUM_TCP_PCB_LISTEN LWIP_CONFIG_NUM_SOCKETS +#define MEMP_NUM_TCP_SEG (((TCP_SND_BUF * 3 / 2) + TCP_WND) * LWIP_CONFIG_NUM_SOCKETS / TCP_MSS) +#define MEMP_NUM_UDP_PCB LWIP_CONFIG_NUM_SOCKETS +#define MEM_SIZE (4*1024*1024) // (512*1024) +#define PBUF_POOL_BUFSIZE 1550 +#define PBUF_POOL_SIZE 64 +#define SO_REUSE 1 +#define TCPIP_MBOX_SIZE 512 +#define TCPIP_THREAD_PRIO 5 +#define TCPIP_THREAD_STACKSIZE 0x6000 +#define TCP_MAXRTX 64 +#define TCP_MSS 1400 +#define TCP_SND_BUF 65535 +#define TCP_SND_QUEUELEN (8 * TCP_SND_BUF) / TCP_MSS +#define TCP_TTL 255 +#define TCP_WND 32768 +#define UDP_TTL 255 + +// Options in old lwipopts.h but kept in Defaults with new opt.h +#define IP_FORWARD 0 +#define LWIP_DBG_TYPES_ON LWIP_DBG_ON +#define LWIP_ICMP 1 +#define LWIP_NETCONN 1 +#define LWIP_SOCKET 1 +#define LWIP_STATS 1 +#define LWIP_TCP 1 +#define LWIP_UDP 1 +#define NO_SYS 0 +#define TCP_QUEUE_OOSEQ LWIP_TCP + +#if defined LWIP_STATS_DISPLAY && !LWIP_STATS +#undef LWIP_STATS_DISPLAY +#define LWIP_STATS_DISPLAY 0 +#endif + +// Change some options for lwIP 2.1.2 +#undef TCP_MAXRTX +#define TCP_MAXRTX 12 + +#undef LWIP_COMPAT_SOCKETS +#define LWIP_COMPAT_SOCKETS 0 + +#define MEMP_NUM_SYS_TIMEOUT (LWIP_NUM_SYS_TIMEOUT_INTERNAL + (LWIP_IPV6 * LWIP_IPV6_DHCP6)) + +#undef DEFAULT_ACCEPTMBOX_SIZE +#define DEFAULT_ACCEPTMBOX_SIZE LWIP_CONFIG_NUM_SOCKETS + +#undef TCP_MSS +#define TCP_MSS (IP_FRAG_MAX_MTU - 20 - 20) + +#undef IP_SOF_BROADCAST_RECV +#define IP_SOF_BROADCAST_RECV 0 + +/** + * Defines whether to enable debugging for driver module. + */ +#ifndef DRIVERIF_DEBUG +#define DRIVERIF_DEBUG LWIP_DBG_OFF +#endif + +// Options for old lwipopts.h +#define IP_FRAG_MAX_MTU 1500 +#define LWIP_CONFIG_NUM_SOCKETS 128 +#define IP_REASS_MAX_MEM_SIZE (MEM_SIZE / 4) + +// Options for enhancement code, same for old lwipopts.h +#define LWIP_NETIF_PROMISC 1 +#define LWIP_TFTP LOSCFG_NET_LWIP_SACK_TFTP +#define LWIP_DHCPS 1 +#define LWIP_ENABLE_NET_CAPABILITY 1 +#define LWIP_ENABLE_CAP_NET_BROADCAST 0 + +// Options for liteos_m +#undef LWIP_NETIF_PROMISC +#define LWIP_NETIF_PROMISC 0 + +#define MEMP_MEM_MALLOC 1 + +#undef LWIP_IPV6 +#define LWIP_IPV6 0 + +#undef LWIP_SOCKET_SELECT +#define LWIP_SOCKET_SELECT 1 + + +/* MIB2 stats are required to check IPv4 reassembly results */ +#define MIB2_STATS 1 +#define SLIP_RX_FROM_ISR 1 + +// use PBUF_RAM instead of PBUF_POOL in udp_input +#define USE_PBUF_RAM_UDP_INPUT 1 + +#ifdef LOSCFG_FS_VFS +#include "vfs_config.h" +#define LWIP_SOCKET_OFFSET CONFIG_NFILE_DESCRIPTORS +#endif + +#define LWIP_SOCKET_IOCTL 0 +#define LWIP_SOCKET_FCNTL 0 + +#endif /* _LWIP_PORTING_LWIPOPTS_H_ */ diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/lwip/netdb.h b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/lwip/netdb.h new file mode 100644 index 000000000..0533eb329 --- /dev/null +++ b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/lwip/netdb.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LWIP_PORTING_NETDB_H_ +#define _LWIP_PORTING_NETDB_H_ + +#include "lwip/arch.h" +#include +#include_next + +#endif /* _LWIP_PORTING_NETDB_H_ */ diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/lwip/netif.h b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/lwip/netif.h new file mode 100644 index 000000000..04aff212f --- /dev/null +++ b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/lwip/netif.h @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LWIP_PORTING_NETIF_H_ +#define _LWIP_PORTING_NETIF_H_ + +#include "lwip/arch.h" +#include +#include + +#define netif_find netifapi_netif_find_by_name + +#if LWIP_DHCPS +#define LWIP_NETIF_CLIENT_DATA_INDEX_DHCP LWIP_NETIF_CLIENT_DATA_INDEX_DHCP, \ + LWIP_NETIF_CLIENT_DATA_INDEX_DHCPS +#endif + +#define linkoutput linkoutput; \ + void (*drv_send)(struct netif *netif, struct pbuf *p); \ + u8_t (*drv_set_hwaddr)(struct netif *netif, u8_t *addr, u8_t len); \ + void (*drv_config)(struct netif *netif, u32_t config_flags, u8_t setBit); \ + char full_name[IFNAMSIZ]; \ + u16_t link_layer_type +#include_next +#undef linkoutput +#if LWIP_DHCPS +#undef LWIP_NETIF_CLIENT_DATA_INDEX_DHCP +#endif + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +// redefine NETIF_NAMESIZE which was defined in netif.h +#undef NETIF_NAMESIZE +#define NETIF_NAMESIZE IFNAMSIZ + +#define LOOPBACK_IF 0 +#define ETHERNET_DRIVER_IF 1 +#define WIFI_DRIVER_IF 801 +#define BT_PROXY_IF 802 + +err_t driverif_init(struct netif *netif); +void driverif_input(struct netif *netif, struct pbuf *p); + +#define netif_get_name(netif) ((netif)->full_name) + +#ifdef __cplusplus +} +#endif + +#endif /* _LWIP_PORTING_NETIF_H_ */ diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/lwip/netifapi.h b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/lwip/netifapi.h new file mode 100644 index 000000000..44858b7c0 --- /dev/null +++ b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/lwip/netifapi.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LWIP_PORTING_NETIFAPI_H_ +#define _LWIP_PORTING_NETIFAPI_H_ + +#include_next + +#ifdef __cplusplus +extern "C" { +#endif + +err_t netifapi_dhcps_start(struct netif *netif, char *start_ip, u16_t ip_num); +err_t netifapi_dhcps_stop(struct netif *netif); + +#define netifapi_dhcp_cleanup(n) netifapi_netif_common(n, dhcp_cleanup, NULL) +#define netifapi_dhcp_is_bound(n) netifapi_netif_common(n, NULL, dhcp_is_bound) + +void netifapi_netif_rmv_ip6_address(struct netif *netif, ip_addr_t *ipaddr); +struct netif *netifapi_netif_find_by_name(const char *name); + +#ifdef __cplusplus +} +#endif + +#endif /* _LWIP_PORTING_NETIFAPI_H_ */ diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/lwip/sockets.h b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/lwip/sockets.h new file mode 100644 index 000000000..adf0985f6 --- /dev/null +++ b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/lwip/sockets.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LWIP_PORTING_SOCKETS_H_ +#define _LWIP_PORTING_SOCKETS_H_ + +#include "lwip/arch.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include_next + +#ifdef __cplusplus +extern "C" { +#endif + +#if FD_SETSIZE < (LWIP_SOCKET_OFFSET + MEMP_NUM_NETCONN) +#error "external FD_SETSIZE too small for number of sockets" +#else +#define LWIP_SELECT_MAXNFDS FD_SETSIZE +#endif + +#if IOV_MAX > 0xFFFF +#error "IOV_MAX larger than supported by LwIP" +#endif + +#if LWIP_UDP && LWIP_UDPLITE +#define UDPLITE_SEND_CSCOV 0x01 /* sender checksum coverage */ +#define UDPLITE_RECV_CSCOV 0x02 /* minimal receiver checksum coverage */ +#endif + +// For BSD 4.4 socket sa_len compatibility +#define DF_NADDR(addr) ip_addr_t naddr = (addr) +#define SA_LEN(addr, _) (IP_IS_V4_VAL(addr) ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6)) +#define sa_len sa_data[0] * 0 + SA_LEN(naddr, _) +#define sin_len sin_zero[0] +#define sin6_len sin6_addr.s6_addr[0] + +// for sockets.c, TCP_KEEPALIVE is not supported currently +#define TCP_KEEPALIVE 0xFF +#define SIN_ZERO_LEN 8 + +int closesocket(int sockfd); +int ioctlsocket(int s, long cmd, void *argp); + +#ifdef __cplusplus +} +#endif + +#endif /* _LWIP_PORTING_SOCKETS_H_ */ diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/lwipopts.h b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/lwipopts.h new file mode 100644 index 000000000..4f1ab7216 --- /dev/null +++ b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/lwipopts.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __LITEOS_M_LWIPOPTS_H__ +#define __LITEOS_M_LWIPOPTS_H__ + +// Just redirect +#include "lwip/lwipopts.h" + +#endif // __LITEOS_M_LWIPOPTS_H__ diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/src/api_shell.c b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/src/api_shell.c new file mode 100644 index 000000000..b62966b24 --- /dev/null +++ b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/src/api_shell.c @@ -0,0 +1,610 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#define LWIP_STATIC static +#define DHCP_STATE_OFF 0 +#define LWIP_EXT_POLL_SUPPORT 1 + +#include "lwip/api.h" +#include "lwip/netdb.h" +#include "lwip/stats.h" +#include "lwip/err.h" +#include "lwip/ip_addr.h" +#include "lwip/icmp.h" +#include "lwip/tcpip.h" +#include "lwip/inet_chksum.h" +#include "los_config.h" +#include +#include +#include +// #include "los_debug.h" +#include "lwip/netif.h" +#include "los_task.h" + +/* Forward Declarations [START] */ +#ifndef LWIP_TESTBED +LWIP_STATIC +#endif +int print_netif(struct netif *netif, char *print_buf, unsigned int buf_len); + +#ifndef LWIP_TESTBED +LWIP_STATIC +#endif +void lwip_ifconfig_show_internal(void *arg); + +#if LWIP_DNS +LWIP_STATIC unsigned int get_hostip(const char *hname); + +#ifndef LWIP_TESTBED +LWIP_STATIC +#endif +struct hostent *gethostnameinfo(const char *host, char *tmphstbuf, size_t hstbuflen); +#endif /* LWIP_DNS */ + +#define PRINT_BUF_LEN 1024 + +struct ifconfig_option { + char iface[IFNAMSIZ]; + unsigned int option; + ip_addr_t ip_addr; + ip_addr_t netmask; + ip_addr_t gw; + unsigned char ethaddr[6]; + u16_t mtu; + /* when using telnet, print to the telnet socket will result in system */ + /* deadlock. So we cahe the prinf data to a buf, and when the tcpip */ + /* callback returns, then print the data out to the telnet socket */ + sys_sem_t cb_completed; + char cb_print_buf[PRINT_BUF_LEN]; + unsigned int print_len; +}; + +#ifndef LWIP_TESTBED +LWIP_STATIC +#endif +int print_netif(struct netif *netif, char *print_buf, unsigned int buf_len) +{ + int i, ret; + char *tmp = print_buf; + + if (buf_len < 1) { + goto out; + } + if (netif->link_type == LOOPBACK_IF) { + ret = snprintf_s(tmp, buf_len, (buf_len - 1), "%s\t", netif->name); + } else { + ret = snprintf_s(tmp, buf_len, (buf_len - 1), "%s%u\t", netif->name, netif->num); + } + + if ((ret <= 0) || ((unsigned int)ret >= buf_len)) + goto out; + tmp += ret; + buf_len -= (unsigned int)ret; +#if LWIP_IPV4 + ret = snprintf_s(tmp, buf_len, (buf_len - 1), "ip:%s ", ipaddr_ntoa(&netif->ip_addr)); + if ((ret <= 0) || ((unsigned int)ret >= buf_len)) + goto out; + tmp += ret; + buf_len -= (unsigned int)ret; + + ret = snprintf_s(tmp, buf_len, (buf_len - 1), "netmask:%s ", ipaddr_ntoa(&netif->netmask)); + if ((ret <= 0) || ((unsigned int)ret >= buf_len)) + goto out; + tmp += ret; + buf_len -= (unsigned int)ret; + + ret = snprintf_s(tmp, buf_len, (buf_len - 1), "gateway:%s\n", ipaddr_ntoa(&netif->gw)); + if ((ret <= 0) || ((unsigned int)ret >= buf_len)) + goto out; + tmp += ret; + buf_len -= (unsigned int)ret; +#endif + ret = snprintf_s(tmp, buf_len, (buf_len - 1), "\tHWaddr "); + if ((ret <= 0) || ((unsigned int)ret >= buf_len)) + goto out; + tmp += ret; + buf_len -= (unsigned int)ret; + + for (i = 0; i < netif->hwaddr_len - 1; i++) { + ret = snprintf_s(tmp, buf_len, (buf_len - 1), "%02x:", netif->hwaddr[i]); + if ((ret <= 0) || ((unsigned int)ret >= buf_len)) + goto out; + tmp += ret; + buf_len -= (unsigned int)ret; + } + + ret = snprintf_s(tmp, buf_len, (buf_len - 1), "%02x", netif->hwaddr[i]); + if ((ret <= 0) || ((unsigned int)ret >= buf_len)) + goto out; + tmp += ret; + buf_len -= (unsigned int)ret; + + ret = snprintf_s(tmp, buf_len, (buf_len - 1), " MTU:%d %s", netif->mtu, + netif->flags & NETIF_FLAG_UP ? "Running" : "Stop"); + if ((ret <= 0) || ((unsigned int)ret >= buf_len)) + goto out; + tmp += ret; + buf_len -= (unsigned int)ret; + + if (netif_default == netif && netif_is_up(netif)) { + ret = snprintf_s(tmp, buf_len, (buf_len - 1), " %s", "Default"); + if ((ret <= 0) || ((unsigned int)ret >= buf_len)) + goto out; + tmp += ret; + buf_len -= (unsigned int)ret; + } + + ret = snprintf_s(tmp, buf_len, (buf_len - 1), " %s\n", netif->flags & NETIF_FLAG_LINK_UP ? "Link UP" : "Link Down"); + if ((ret <= 0) || ((unsigned int)ret >= buf_len)) + goto out; + tmp += ret; + +out: + return (int)(tmp - print_buf); +} + +#ifndef LWIP_TESTBED +LWIP_STATIC +#endif +void lwip_ifconfig_show_internal(void *arg) +{ + struct netif *netif = NULL; + struct ifconfig_option *ifconfig_cmd = (struct ifconfig_option *)arg; + int ret; + + if (netif_list == NULL) { + ret = snprintf_s(ifconfig_cmd->cb_print_buf, PRINT_BUF_LEN - ifconfig_cmd->print_len, + ((PRINT_BUF_LEN - ifconfig_cmd->print_len) - 1), "Device not init\n"); + if ((ret > 0) && ((unsigned int)ret < (PRINT_BUF_LEN - ifconfig_cmd->print_len))) { + ifconfig_cmd->print_len += (unsigned int)ret; + } + sys_sem_signal(&ifconfig_cmd->cb_completed); + return; + } + + if (ifconfig_cmd->iface[0] == '\0') { + /* display all netif */ + for (netif = netif_list; netif != NULL; netif = netif->next) { + ret = print_netif(netif, ifconfig_cmd->cb_print_buf + ifconfig_cmd->print_len, + PRINT_BUF_LEN - ifconfig_cmd->print_len); + ifconfig_cmd->print_len += (unsigned int)ret; + } + } else { + netif = netif_find(ifconfig_cmd->iface); + if (netif == NULL) { + ret = snprintf_s(ifconfig_cmd->cb_print_buf + ifconfig_cmd->print_len, + (PRINT_BUF_LEN - ifconfig_cmd->print_len), + ((PRINT_BUF_LEN - ifconfig_cmd->print_len) - 1), "Device not found\n"); + if ((ret > 0) && ((unsigned int)ret < (PRINT_BUF_LEN - ifconfig_cmd->print_len))) { + ifconfig_cmd->print_len += (unsigned int)ret; + } + + sys_sem_signal(&ifconfig_cmd->cb_completed); + return; + } + + ret = print_netif(netif, ifconfig_cmd->cb_print_buf + ifconfig_cmd->print_len, + PRINT_BUF_LEN - ifconfig_cmd->print_len); + ifconfig_cmd->print_len += (unsigned int)ret; + } + sys_sem_signal(&ifconfig_cmd->cb_completed); +} + +u32_t lwip_ifconfig(int argc, const char **argv) +{ + static struct ifconfig_option ifconfig_cmd; + err_t ret; + + (void)memset_s(&ifconfig_cmd, sizeof(ifconfig_cmd), 0, sizeof(ifconfig_cmd)); + if (sys_sem_new(&ifconfig_cmd.cb_completed, 0) != ERR_OK) { + PRINTK("%s: sys_sem_new fail\n", __FUNCTION__); + return 1; + } + + /* Get the interface */ + + /* no more arguments, show all the interface state. */ + ret = tcpip_callback(lwip_ifconfig_show_internal, &ifconfig_cmd); + if (ret != ERR_OK) { + sys_sem_free(&ifconfig_cmd.cb_completed); + PRINTK("ifconfig : internal error, l:%d err:%d\n", __LINE__, ret); + return 1; + } + (void)sys_arch_sem_wait(&ifconfig_cmd.cb_completed, 0); + sys_sem_free(&ifconfig_cmd.cb_completed); + ifconfig_cmd.cb_print_buf[PRINT_BUF_LEN - 1] = '\0'; + PRINTK("%s", ifconfig_cmd.cb_print_buf); + + return 0; +} + +#if LWIP_DNS +#ifndef LWIP_TESTBED +LWIP_STATIC +#endif +struct hostent *gethostnameinfo(const char *host, char *tmphstbuf, size_t hstbuflen) +{ + static struct hostent hostbuf; + struct hostent *hp = NULL; + int res; + int herr; + + if (tmphstbuf == NULL) + return NULL; + res = lwip_gethostbyname_r(host, &hostbuf, tmphstbuf, hstbuflen, &hp, &herr); + /* Check for errors. */ + if (res || hp == NULL) { + return NULL; + } + return hp; +} + +LWIP_STATIC unsigned int get_hostip(const char *hname) +{ + unsigned int ip = 0; + errno_t ret; + const size_t hstbuflen = 1024; + char *tmphstbuf = NULL; + + tmphstbuf = (char *)zalloc(sizeof(char) * hstbuflen); + if (tmphstbuf == NULL) + return 0; + + struct hostent *pent = gethostnameinfo(hname, tmphstbuf, hstbuflen); + if (pent == NULL || pent->h_addr == NULL) { + free(tmphstbuf); + return 0; + } + ret = memcpy_s(&ip, sizeof(ip), pent->h_addr, sizeof(pent->h_addr)); + if (ret != EOK) { + free(tmphstbuf); + return 0; + } + free(tmphstbuf); + return ip; +} + +#endif + +static int ping_taskid = -1; +static int ping_kill = 0; +#define LWIP_SHELL_CMD_PING_TIMEOUT 2000 +#define LWIP_SHELL_CMD_PING_RETRY_TIMES 4 +#define PING_ZERO_DATA_LEN 8 + +static void lwip_ping_usage(void) +{ + PRINTK("Usage:\n ping [ip]\n"); +} + +LWIP_STATIC int OsPingFunc(u32_t *parg) +{ + int sfd; + struct sockaddr_in to; + struct pbuf *pbuf_resp = NULL; + struct icmp_echo_hdr *iecho = NULL; + struct icmp_echo_hdr *iecho_resp = NULL; + struct ip_hdr *iphdr_resp = NULL; + u32_t iecho_len; + s16_t ip_hlen; + u32_t forever; + u32_t i; + u32_t succ_cnt = 0; + u32_t failed_cnt = 0; + struct timespec start, end; + long timout_ms; + struct pollfd pfd; + long rtt; + int ret = 0; + u32_t intrvl; + char *data_buf = NULL; + BOOL timeout_flag = FALSE; + char buf[50]; + + u32_t destip = parg[0]; + u32_t cnt = parg[1]; + u32_t interval = parg[2]; + u32_t data_len = parg[3]; + + iecho_len = sizeof(struct icmp_echo_hdr) + data_len; + sfd = lwip_socket(PF_INET, SOCK_RAW, IPPROTO_ICMP); + if (sfd < 0) { + perror("Ping socket"); + return -1; + } + pbuf_resp = pbuf_alloc(PBUF_RAW, IP_HLEN + sizeof(struct icmp_echo_hdr), PBUF_RAM); + if (pbuf_resp == NULL) { + PRINTK("Ping: pbuf_resp malloc failed\n"); + ret = -1; + goto FAILURE; + } + iecho = (struct icmp_echo_hdr *)mem_malloc(iecho_len); + if (iecho == NULL) { + PRINTK("Ping: echo request malloc failed\n"); + ret = -1; + goto FAILURE; + } + + to.sin_family = AF_INET; + to.sin_addr.s_addr = destip; /* already in network order */ + to.sin_port = 0; + + if (data_len > PING_ZERO_DATA_LEN) { + (void)memset_s(iecho, sizeof(struct icmp_echo_hdr) + PING_ZERO_DATA_LEN, + 0, sizeof(struct icmp_echo_hdr) + PING_ZERO_DATA_LEN); + data_buf = (char *)iecho + sizeof(struct icmp_echo_hdr) + PING_ZERO_DATA_LEN; + for (i = 0; i < data_len - PING_ZERO_DATA_LEN; i++) { + *(data_buf + i) = i + 0x10; + } + } else { + (void)memset_s(iecho, sizeof(struct icmp_echo_hdr) + data_len, 0, sizeof(struct icmp_echo_hdr) + data_len); + } + iecho->id = htons((u16_t)LOS_CurTaskIDGet()); + ICMPH_TYPE_SET(iecho, (u8_t)ICMP_ECHO); + forever = (cnt ? 0 : 1); + i = 0; + while (!ping_kill && (forever || (i < cnt))) { + iecho->seqno = htons((u16_t)i); + iecho->chksum = 0; +#if (CHECKSUM_GEN_ICMP > 0) + iecho->chksum = inet_chksum((void *)iecho, iecho_len); +#endif + ret = sendto(sfd, iecho, iecho_len, 0, (struct sockaddr *)&to, (socklen_t)sizeof(to)); + if (ret < 0) { + perror("Ping: sending ICMP echo request failed\n"); + goto FAILURE; + } + + /* capture the start time to calculate RTT */ + (void)clock_gettime(CLOCK_MONOTONIC_RAW, &start); + + /* poll for ICMP echo response msg */ + pfd.fd = sfd; + + do { + pfd.events = POLLIN; + pfd.revents = 0; + timeout_flag = FALSE; + ret = lwip_poll(&pfd, 1, LWIP_SHELL_CMD_PING_TIMEOUT); + if (ret < 0) { + perror("Ping: poll\n"); + goto FAILURE; + } else if (ret == 0) { + /* first type timeout event */ + timeout_flag = TRUE; + break; + } + + ret = recv(sfd, pbuf_resp->payload, pbuf_resp->len, MSG_DONTWAIT); + if (ret < 0) { + perror("Ping: recv echo reply failed\n"); + goto FAILURE; + } + + /* Accessing ip header and icmp header */ + iphdr_resp = pbuf_resp->payload; + + ip_hlen = (IPH_HL(iphdr_resp) << 2); /* 2: offset */ + if (pbuf_header(pbuf_resp, -ip_hlen)) { + /* this failure will never happen, but failure handle is written just to be in safe side */ + PRINTK("Ping : memory management failure\n"); + goto FAILURE; + } + iecho_resp = (struct icmp_echo_hdr *)pbuf_resp->payload; + /* Reverting back pbuf to its original state */ + if (pbuf_header(pbuf_resp, ip_hlen)) { + /* this failure will never happen, but failure handle is written just to be in safe side */ + PRINTK("ping : memory management failure\n"); + goto FAILURE; + } + + if ((iphdr_resp->src.addr != to.sin_addr.s_addr) || + ((ICMPH_TYPE(iecho_resp) == ICMP_ECHO) && (iphdr_resp->src.addr == to.sin_addr.s_addr))) { + /* second type timeout event */ + (void)clock_gettime(CLOCK_MONOTONIC_RAW, &end); + timout_ms = ((end.tv_sec - start.tv_sec) * OS_SYS_MS_PER_SECOND + \ + (end.tv_nsec - start.tv_nsec) / OS_SYS_NS_PER_MS); + timout_ms = LWIP_SHELL_CMD_PING_TIMEOUT - timout_ms; + } else { + timout_ms = 0; + break; + } + } while (timout_ms >= 0); + + /* all timeout events are true timeout */ + if ((timout_ms < 0) || (timeout_flag == TRUE)) { + failed_cnt++; + i++; + PRINTK("\nPing: destination unreachable ..."); + continue; + } + /* capture the end time to calculate round trip time */ + (void)clock_gettime(CLOCK_MONOTONIC_RAW, &end); + rtt = ((end.tv_sec - start.tv_sec) * OS_SYS_MS_PER_SECOND + \ + (end.tv_nsec - start.tv_nsec) / OS_SYS_NS_PER_MS); + + if (iphdr_resp->src.addr == to.sin_addr.s_addr) { + switch (ICMPH_TYPE(iecho_resp)) { + case ICMP_ER: + PRINTK("\n[%u]Reply from %s: ", i, inet_ntop(AF_INET, &to.sin_addr, buf, sizeof(buf))); + if (rtt > 0) { + PRINTK("time=%ims ", rtt); + } else { + PRINTK("time<1ms "); + } + PRINTK("TTL=%u", iphdr_resp->_ttl); + + /* delay 1s for every successful ping */ + intrvl = interval; + do { + if (intrvl < 1000) { /* 1000: 1000ms = 1s */ + sys_msleep(intrvl); + break; + } + intrvl -= 1000; /* 1000: 1000ms = 1s */ + sys_msleep(1000); /* 1000: 1000ms = 1s */ + if (ping_kill == 1) { + break; + } + } while (intrvl > 0); + succ_cnt++; + break; + case ICMP_DUR: + PRINTK("\nPing: destination host unreachable ..."); + break; + case ICMP_SQ: + PRINTK("\nPing: source quench ..."); + break; + case ICMP_RD: + PRINTK("\nPing: redirect ..."); + break; + case ICMP_TE: + PRINTK("\nPing: time exceeded ..."); + break; + case ICMP_PP: + PRINTK("\nPing: parameter problem ..."); + break; + default: + PRINTK("\nPing: unknown error ..."); + break; + } + i++; + } + } + + PRINTK("\n--- %s ping statistics ---\n", inet_ntop(AF_INET, &to.sin_addr, buf, sizeof(buf))); + PRINTK("%u packets transmitted, %u received, %u loss\n", i, succ_cnt, failed_cnt); + +FAILURE: + ping_kill = 0; + (void)lwip_close(sfd); + if (pbuf_resp != NULL) { + (void)pbuf_free(pbuf_resp); + } + if (iecho != NULL) { + mem_free(iecho); + } + return ret; +} + +static void ping_cmd(u32_t *parg) +{ + int ret; + + ret = OsPingFunc(parg); + if (ret < 0) { + PRINTK("Ping cmd failed due to some errors\n"); + } + free(parg); + ping_taskid = -1; +} + +u32_t OsShellPing(int argc, const char **argv) +{ + int ret; + u32_t i = 0; + u32_t count; + int count_set = 0; + u32_t interval = 1000; /* default ping interval */ + u32_t data_len = 48; /* default data length */ + ip4_addr_t dst_ipaddr; + TSK_INIT_PARAM_S stPingTask; + u32_t *parg = NULL; + + if ((argc < 1) || (argv == NULL)) { + PRINTK("Ping: require dest ipaddr at least\n"); + goto ping_error; + } + + if (!count_set) { + count = LWIP_SHELL_CMD_PING_RETRY_TIMES; + } + + /* initialize dst IP address */ + if (argc <= 0) { + goto ping_error; + } +#if LWIP_DNS + dst_ipaddr.addr = get_hostip(argv[i]); +#endif /* LWIP_DNS */ + + if (dst_ipaddr.addr == IPADDR_NONE || dst_ipaddr.addr == IPADDR_ANY) { + PRINTK("Invalid dest ipaddr: NONE or ANY\n"); + return LOS_NOK; + } + + parg = (u32_t *)malloc(4 * sizeof(int)); /* 4: number of args */ + if (parg == NULL) { + return LOS_NOK; + } + parg[0] = dst_ipaddr.addr; + parg[1] = count; + parg[2] = interval; + parg[3] = data_len; + + /* start one task if ping forever or ping count greater than 60 */ + if (count == 0 || count > LWIP_SHELL_CMD_PING_RETRY_TIMES) { + if (ping_taskid > 0) { + free(parg); + PRINTK("Ping task already running and only support one now\n"); + return LOS_NOK; + } + stPingTask.pfnTaskEntry = (TSK_ENTRY_FUNC)ping_cmd; + stPingTask.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE; + stPingTask.pcName = "ping_task"; + stPingTask.usTaskPrio = 8; /* 8: higher than shell */ + stPingTask.uwResved = LOS_TASK_STATUS_DETACHED; + stPingTask.pArgs = (UINTPTR)parg; + ret = LOS_TaskCreate((UINT32 *)(&ping_taskid), &stPingTask); + if (ret != LOS_OK) { + PRINTK("ping_task create failed 0x%08x.\n", ret); + count = LWIP_SHELL_CMD_PING_RETRY_TIMES; + } else { + return LOS_OK; + } + } + + /* two cases: + 1, ping cout less than LWIP_SHELL_CMD_PING_RETRY_TIMES; + 2, ping task create failed; + */ + if (OsPingFunc(parg) < 0) { + PRINTK("Ping cmd failed due some errors\n"); + } + + free(parg); + + return LOS_OK; +ping_error: + lwip_ping_usage(); + return LOS_NOK; +} + diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/src/driverif.c b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/src/driverif.c new file mode 100644 index 000000000..1b852a78e --- /dev/null +++ b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/src/driverif.c @@ -0,0 +1,355 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include + +#define LWIP_NETIF_HOSTNAME_DEFAULT "default" +#define LINK_SPEED_OF_YOUR_NETIF_IN_BPS 100000000 // 100Mbps + +#define link_rx_drop cachehit +#define link_rx_overrun cachehit + +#define LWIP_STATIC static + +#define NETIF_NAME_PREFIX_MAX_LENGTH 10 +#define NETIF_NAME_PREFIX_ETH "eth" +#define NETIF_NAME_PREFIX_WIFI "wlan" +#define NETIF_NAME_PREFIX_BT "bt" + +#ifndef LWIP_NETIF_IFINDEX_MAX_EX +#define LWIP_NETIF_IFINDEX_MAX_EX 255 +#endif + +LWIP_STATIC void driverif_get_ifname_prefix(struct netif *netif, char *prefix, int prefixLen) +{ + if (prefix == NULL || netif == NULL) { + LWIP_ASSERT("invalid param", 0); + return; + } + switch (netif->link_type) { + case ETHERNET_DRIVER_IF: + strcpy_s(prefix, prefixLen, NETIF_NAME_PREFIX_ETH); + break; + case WIFI_DRIVER_IF: + strcpy_s(prefix, prefixLen, NETIF_NAME_PREFIX_WIFI); + break; + case BT_PROXY_IF: + strcpy_s(prefix, prefixLen, NETIF_NAME_PREFIX_BT); + break; + default: + LWIP_ASSERT("invalid link_layer_type", 0); + break; + } +} + +LWIP_STATIC void driverif_init_ifname(struct netif *netif) +{ + struct netif *tmpnetif = NULL; + char prefix[NETIF_NAME_PREFIX_MAX_LENGTH] = {0}; + + driverif_get_ifname_prefix(netif, prefix, NETIF_NAME_PREFIX_MAX_LENGTH); + netif->name[0] = prefix[0]; + netif->name[1] = prefix[1]; + + if (netif->full_name[0] != '\0') { + LWIP_DEBUGF(DRIVERIF_DEBUG, ("netif already has fullname %s\n", netif->full_name)); + return; + } + for (int i = 0; i < LWIP_NETIF_IFINDEX_MAX_EX; ++i) { + if (snprintf_s(netif->full_name, sizeof(netif->full_name), sizeof(netif->full_name) - 1, + "%s%d", prefix, i) < 0) { + break; + } + NETIF_FOREACH(tmpnetif) { + if (strcmp(tmpnetif->full_name, netif->full_name) == 0) { + break; + } + } + if (tmpnetif == NULL) { + LWIP_DEBUGF(DRIVERIF_DEBUG, ("set fullname success %s\n", netif->full_name)); + return; + } + } + netif->full_name[0] = '\0'; +} + +/* + * This function should do the actual transmission of the packet. The packet is + * contained in the pbuf that is passed to the function. This pbuf + * might be chained. + * + * @param netif the lwip network interface structure for this driverif + * @param p the MAC packet to send (e.g. IP packet including MAC_addresses and type) + * @return ERR_OK if the packet could be sent + * an err_t value if the packet couldn't be sent + * + * @note Returning ERR_MEM here if a DMA queue of your MAC is full can lead to + * strange results. You might consider waiting for space in the DMA queue + * to become availale since the stack doesn't retry to send a packet + * dropped because of memory failure (except for the TCP timers). + */ + +LWIP_STATIC err_t driverif_output(struct netif *netif, struct pbuf *p) +{ + LWIP_DEBUGF(DRIVERIF_DEBUG, ("driverif_output : send packet pbuf 0x%p of length %"U16_F" through netif 0x%p\n", \ + (void *)p, p->tot_len, (void *)netif)); + +#if PF_PKT_SUPPORT + if (all_pkt_raw_pcbs != NULL) { + p->flags = (u16_t)(p->flags & ~(PBUF_FLAG_LLMCAST | PBUF_FLAG_LLBCAST | PBUF_FLAG_HOST)); + p->flags |= PBUF_FLAG_OUTGOING; + (void)raw_pkt_input(p, netif, NULL); + } +#endif + +#if ETH_PAD_SIZE + (void)pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */ +#endif + + netif->drv_send(netif, p); + +#if ETH_PAD_SIZE + (void)pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */ +#endif + MIB2_STATS_NETIF_ADD(netif, ifoutoctets, p->tot_len); + LINK_STATS_INC(link.xmit); + + return ERR_OK; +} + +void driverif_input_proc(struct netif *netif, struct pbuf *p) +{ + u16_t ethhdr_type; + struct eth_hdr *ethhdr = NULL; + err_t ret = ERR_VAL; + + ethhdr = (struct eth_hdr *)p->payload; + ethhdr_type = ntohs(ethhdr->type); + + switch (ethhdr_type) { + /* IP or ARP packet? */ + case ETHTYPE_IP: + case ETHTYPE_IPV6: + case ETHTYPE_ARP: +#if ETHARP_SUPPORT_VLAN + case ETHTYPE_VLAN: +#endif /* ETHARP_SUPPORT_VLAN */ + LWIP_DEBUGF(DRIVERIF_DEBUG, ("driverif_input : received packet of type %"U16_F"\n", ethhdr_type)); + /* full packet send to tcpip_thread to process */ + if (netif->input != NULL) { + ret = netif->input(p, netif); + } + + if (ret != ERR_OK) { + LWIP_DEBUGF(DRIVERIF_DEBUG, ("driverif_input: IP input error\n")); + (void)pbuf_free(p); + LINK_STATS_INC(link.drop); + LINK_STATS_INC(link.link_rx_drop); + if (ret == ERR_MEM) { + MIB2_STATS_NETIF_INC(netif, ifinerrors); + LINK_STATS_INC(link.link_rx_overrun); + } + } else { + LINK_STATS_INC(link.recv); + } + break; + + default: + LWIP_DEBUGF(DRIVERIF_DEBUG, ("driverif_input : received packet is of unsupported type %"U16_F"\n", \ + ethhdr_type)); + (void)pbuf_free(p); + LINK_STATS_INC(link.drop); + LINK_STATS_INC(link.link_rx_drop); + break; + } +} + +/* + * This function should be called by network driver to pass the input packet to LwIP. + * Before calling this API, driver has to keep the packet in pbuf structure. Driver has to + * call pbuf_alloc() with type as PBUF_RAM to create pbuf structure. Then driver + * has to pass the pbuf structure to this API. This will add the pbuf into the TCPIP thread. + * Once this packet is processed by TCPIP thread, pbuf will be freed. Driver is not required to + * free the pbuf. + * + * @param netif the lwip network interface structure for this driverif + * @param p packet in pbuf structure format + */ +void driverif_input(struct netif *netif, struct pbuf *p) +{ +#if PF_PKT_SUPPORT +#if (DRIVERIF_DEBUG & LWIP_DBG_OFF) + u16_t ethhdr_type; + struct eth_hdr* ethhdr = NULL; +#endif + err_t ret = ERR_VAL; +#endif + + LWIP_ERROR("driverif_input : invalid arguments", ((netif != NULL) && (p != NULL)), return); + + LWIP_DEBUGF(DRIVERIF_DEBUG, ("driverif_input : going to receive input packet. netif 0x%p, pbuf 0x%p, \ + packet_length %"U16_F"\n", (void *)netif, (void *)p, p->tot_len)); + + /* points to packet payload, which starts with an Ethernet header */ + MIB2_STATS_NETIF_ADD(netif, ifinoctets, p->tot_len); + if (p->len < SIZEOF_ETH_HDR) { + (void)pbuf_free(p); + LINK_STATS_INC(link.drop); + LINK_STATS_INC(link.link_rx_drop); + return; + } + +#if PF_PKT_SUPPORT +#if (DRIVERIF_DEBUG & LWIP_DBG_OFF) + ethhdr = (struct eth_hdr *)p->payload; + ethhdr_type = ntohs(ethhdr->type); + LWIP_DEBUGF(DRIVERIF_DEBUG, ("driverif_input : received packet of type %"U16_F" netif->input=%p\n", \ + ethhdr_type, netif->input)); +#endif + + /* full packet send to tcpip_thread to process */ + if (netif->input) { + ret = netif->input(p, netif); + } + if (ret != ERR_OK) { + LWIP_DEBUGF(DRIVERIF_DEBUG, ("driverif_input: IP input error\n")); + (void)pbuf_free(p); + LINK_STATS_INC(link.drop); + LINK_STATS_INC(link.link_rx_drop); + if (ret == ERR_MEM) { + LINK_STATS_INC(link.link_rx_overrun); + } + } else { + LINK_STATS_INC(link.recv); + } + +#else + driverif_input_proc(netif, p); +#endif + + LWIP_DEBUGF(DRIVERIF_DEBUG, ("driverif_input : received packet is processed\n")); +} + +/* + * Should be called at the beginning of the program to set up the + * network interface. It calls the function low_level_init() to do the + * actual setup of the hardware. + * + * This function should be passed as a parameter to netif_add(). + * + * @param netif the lwip network interface structure for this driverif + * @return ERR_OK if the loopif is initialized + * ERR_MEM on Allocation Failure + * any other err_t on error + */ +err_t driverif_init(struct netif *netif) +{ + u16_t link_layer_type; + + if (netif == NULL) { + return ERR_IF; + } + link_layer_type = netif->link_layer_type; + LWIP_ERROR("driverif_init : invalid link_layer_type in netif", \ + ((link_layer_type == ETHERNET_DRIVER_IF) \ + || (link_layer_type == WIFI_DRIVER_IF \ + || link_layer_type == BT_PROXY_IF)), \ + return ERR_IF); + + LWIP_ERROR("driverif_init : netif hardware length is greater than maximum supported", \ + (netif->hwaddr_len <= NETIF_MAX_HWADDR_LEN), return ERR_IF); + + LWIP_ERROR("driverif_init : drv_send is null", (netif->drv_send != NULL), return ERR_IF); + +#if LWIP_NETIF_PROMISC + LWIP_ERROR("driverif_init : drv_config is null", (netif->drv_config != NULL), return ERR_IF); +#endif + +#if LWIP_NETIF_HOSTNAME + /* Initialize interface hostname */ + netif->hostname = LWIP_NETIF_HOSTNAME_DEFAULT; +#endif /* LWIP_NETIF_HOSTNAME */ + + /* + * Initialize the snmp variables and counters inside the struct netif. + * The last argument should be replaced with your link speed, in units + * of bits per second. + */ + NETIF_INIT_SNMP(netif, snmp_ifType_ethernet_csmacd, LINK_SPEED_OF_YOUR_NETIF_IN_BPS); + + netif->output = etharp_output; + netif->linkoutput = driverif_output; + + /* init the netif's full name */ + driverif_init_ifname(netif); + + /* maximum transfer unit */ + netif->mtu = IP_FRAG_MAX_MTU; + + /* device capabilities */ + /* don't set NETIF_FLAG_ETHARP if this device is not an ethernet one */ + netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | +#if DRIVER_STATUS_CHECK + NETIF_FLAG_DRIVER_RDY | +#endif +#if LWIP_IGMP + NETIF_FLAG_IGMP | +#endif + + /** + @page RFC-2710 RFC-2710 + @par Compliant Sections + Section 5. Node State Transition Diagram + @par Behavior Description + MLD messages are sent for multicast addresses whose scope is 2 + (link-local), including Solicited-Node multicast addresses.\n + Behavior:Stack will send MLD6 report /Done to solicited node multicast address + if the LWIP_MLD6_ENABLE_MLD_ON_DAD is enabled. By default, this is disabled. + */ + /* Enable sending MLD report /done for solicited address during neighbour discovery */ +#if LWIP_IPV6 && LWIP_IPV6_MLD +#if LWIP_MLD6_ENABLE_MLD_ON_DAD + NETIF_FLAG_MLD6 | +#endif /* LWIP_MLD6_ENABLE_MLD_ON_DAD */ +#endif + NETIF_FLAG_LINK_UP; + +#if DRIVER_STATUS_CHECK + netif->waketime = -1; +#endif /* DRIVER_STATUS_CHECK */ + LWIP_DEBUGF(DRIVERIF_DEBUG, ("driverif_init : Initialized netif 0x%p\n", (void *)netif)); + return ERR_OK; +} diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/src/lwip_init.c b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/src/lwip_init.c new file mode 100644 index 000000000..8d748657b --- /dev/null +++ b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/src/lwip_init.c @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include "lwip/tcpip.h" +#include "ohos_init.h" + +void TcpIpPortingInit(void) +{ + tcpip_init(NULL, NULL); +} +SYSEX_SERVICE_INIT(TcpIpPortingInit); diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/src/netdb_porting.c b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/src/netdb_porting.c new file mode 100644 index 000000000..c5bd51089 --- /dev/null +++ b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/src/netdb_porting.c @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "lwip/netdb.h" + +#if LWIP_DNS && LWIP_SOCKET + +struct hostent *gethostbyname(const char *name) +{ + if (name == NULL) { + return NULL; + } + return lwip_gethostbyname(name); +} + +int gethostbyname_r(const char *name, struct hostent *ret, char *buf, size_t buflen, struct hostent **result, + int *h_errnop) +{ + return lwip_gethostbyname_r(name, ret, buf, buflen, result, h_errnop); +} + +void freeaddrinfo(struct addrinfo *res) +{ + lwip_freeaddrinfo(res); +} + +int getaddrinfo(const char *restrict nodename, const char *restrict servname, const struct addrinfo *restrict hints, + struct addrinfo **restrict res) +{ + return lwip_getaddrinfo(nodename, servname, hints, res); +} + +#endif \ No newline at end of file diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/src/sockets_porting.c b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/src/sockets_porting.c new file mode 100644 index 000000000..efcc017e5 --- /dev/null +++ b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/src/sockets_porting.c @@ -0,0 +1,780 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "lwip/sockets.h" +#include "lwip/priv/tcpip_priv.h" +#include "lwip/priv/sockets_priv.h" +#include "lwip/prot/dhcp.h" +#include "lwip/dhcp.h" +#include "lwip/if_api.h" + +#if !LWIP_COMPAT_SOCKETS +#if LWIP_SOCKET + +#define CHECK_NULL_PTR(ptr) do { if ((ptr) == NULL) { set_errno(EFAULT); return -1; } } while (0) + +int accept(int s, struct sockaddr *addr, socklen_t *addrlen) +{ + return lwip_accept(s, addr, addrlen); +} + +int bind(int s, const struct sockaddr *name, socklen_t namelen) +{ + CHECK_NULL_PTR(name); + if (namelen < sizeof(*name)) { + set_errno(EINVAL); + return -1; + } + return lwip_bind(s, name, namelen); +} + +int shutdown(int s, int how) +{ + return lwip_shutdown(s, how); +} + +int getpeername(int s, struct sockaddr *name, socklen_t *namelen) +{ + CHECK_NULL_PTR(name); + CHECK_NULL_PTR(namelen); + return lwip_getpeername(s, name, namelen); +} + +int getsockname(int s, struct sockaddr *name, socklen_t *namelen) +{ + CHECK_NULL_PTR(name); + CHECK_NULL_PTR(namelen); + return lwip_getsockname(s, name, namelen); +} + +int getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen) +{ + return lwip_getsockopt(s, level, optname, optval, optlen); +} + +int setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen) +{ + return lwip_setsockopt(s, level, optname, optval, optlen); +} + +int closesocket(int s) +{ + return lwip_close(s); +} + +int connect(int s, const struct sockaddr *name, socklen_t namelen) +{ + CHECK_NULL_PTR(name); + if (namelen < sizeof(*name)) { + set_errno(EINVAL); + return -1; + } + return lwip_connect(s, name, namelen); +} + +int listen(int s, int backlog) +{ + return lwip_listen(s, backlog); +} + +ssize_t recv(int s, void *mem, size_t len, int flags) +{ + CHECK_NULL_PTR(mem); + return lwip_recv(s, mem, len, flags); +} + +ssize_t recvfrom(int s, void *mem, size_t len, int flags, + struct sockaddr *from, socklen_t *fromlen) +{ + CHECK_NULL_PTR(mem); + return lwip_recvfrom(s, mem, len, flags, from, fromlen); +} + +ssize_t recvmsg(int s, struct msghdr *message, int flags) +{ + CHECK_NULL_PTR(message); + if (message->msg_iovlen) { + CHECK_NULL_PTR(message->msg_iov); + } + return lwip_recvmsg(s, message, flags); +} + +ssize_t send(int s, const void *dataptr, size_t size, int flags) +{ + CHECK_NULL_PTR(dataptr); + return lwip_send(s, dataptr, size, flags); +} + +ssize_t sendmsg(int s, const struct msghdr *message, int flags) +{ + return lwip_sendmsg(s, message, flags); +} + +ssize_t sendto(int s, const void *dataptr, size_t size, int flags, + const struct sockaddr *to, socklen_t tolen) +{ + CHECK_NULL_PTR(dataptr); + if (to && tolen < sizeof(*to)) { + set_errno(EINVAL); + return -1; + } + return lwip_sendto(s, dataptr, size, flags, to, tolen); +} + +int socket(int domain, int type, int protocol) +{ + return lwip_socket(domain, type, protocol); +} + +const char *inet_ntop(int af, const void *src, char *dst, socklen_t size) +{ + return lwip_inet_ntop(af, src, dst, size); +} + +int inet_pton(int af, const char *src, void *dst) +{ + return lwip_inet_pton(af, src, dst); +} + +#ifndef LWIP_INET_ADDR_FUNC +in_addr_t inet_addr(const char *cp) +{ + return ipaddr_addr(cp); +} +#endif + +#ifndef LWIP_INET_NTOA_FUNC +char *inet_ntoa(struct in_addr addr) +{ + return ip4addr_ntoa((const ip4_addr_t*)&(addr)); +} +#endif + +#ifndef LWIP_INET_ATON_FUNC +int inet_aton(const char *cp, struct in_addr *addr) +{ + return ip4addr_aton(cp, (ip4_addr_t*)addr); +} +#endif + +int ioctlsocket(int s, long cmd, void *argp) +{ + return lwip_ioctl(s, cmd, argp); +} + +#ifdef LWIP_SOCKET_READ_FUNC +ssize_t read(int fd, void *buf, size_t len) +{ + return lwip_read(fd, buf, len); +} +#endif + +#ifdef LWIP_SOCKET_WRITE_FUNC +ssize_t write(int fd, const void *buf, size_t len) +{ + return lwip_write(fd, buf, len); +} +#endif + +#ifdef LWIP_SOCKET_CLOSE_FUNC +int close(int fd) +{ + return lwip_close(fd); +} +#endif + +#if LWIP_SOCKET_IOCTL +#ifdef LWIP_SOCKET_IOCTL_FUNC +int ioctl(int fd, int req, ...) +{ + UINTPTR arg = 0; + va_list ap; + va_start(ap, req); + arg = va_arg(ap, UINTPTR); + va_end(ap); + return lwip_ioctl(fd, (long)req, (void *)arg); +} +#endif +#endif + +#if LWIP_SOCKET_FCNTL +#ifdef LWIP_SOCKET_FCNTL_FUNC +int fcntl(int fd, int cmd, ...) +{ + int val = 0; + va_list ap; + va_start(ap, cmd); + val = va_arg(ap, int); + va_end(ap); + return lwip_fcntl(fd, cmd, val); +} +#endif +#endif + +#if LWIP_SOCKET_SELECT +#ifdef LWIP_SOCKET_SELECT_FUNC +int select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, struct timeval *timeout) +{ + return lwip_select(maxfdp1, readset, writeset, exceptset, timeout); +} +#endif +#endif + +#if LWIP_SOCKET_POLL +#ifdef LWIP_SOCKET_POLL_FUNC +int poll(struct pollfd *fds, nfds_t nfds, int timeout) +{ + return lwip_poll(fds, nfds, timeout); +} +#endif +#endif + +unsigned int if_nametoindex(const char *ifname) +{ + return lwip_if_nametoindex(ifname); +} + +#endif +#endif /* !LWIP_COMPAT_SOCKETS */ + +#define IOCTL_CMD_CASE_HANDLER() do { \ + err_t err; \ + struct lwip_ioctl_apimsg msg; \ + msg.sock = sock; \ + msg.cmd = cmd; \ + msg.argp = argp; \ + \ + err = tcpip_api_call(lwip_do_ioctl_impl, &msg.call); \ + if (err != ENOSYS) { \ + sock_set_errno(sock, err); \ + done_socket(sock); \ + return -(err != ERR_OK); \ + } \ +} while (0) + +struct lwip_ioctl_apimsg { + struct tcpip_api_call_data call; + struct lwip_sock *sock; + long cmd; + void *argp; +}; + +static err_t lwip_do_ioctl_impl(struct tcpip_api_call_data *call); + +#include "../api/sockets.c" + +static u8_t lwip_ioctl_internal_SIOCGIFCONF(struct ifreq *ifr) +{ + struct ifconf *ifc = NULL; + struct netif *netif = NULL; + struct ifreq ifreq; + struct sockaddr_in *sock_in = NULL; + int pos; + int len; + int ret; + + /* Format the caller's buffer. */ + ifc = (struct ifconf *)ifr; + len = ifc->ifc_len; + + /* Loop over the interfaces, and write an info block for each. */ + pos = 0; + for (netif = netif_list; netif != NULL; netif = netif->next) { + if (ifc->ifc_buf == NULL) { + pos = (pos + (int)sizeof(struct ifreq)); + continue; + } + + if (len < (int)sizeof(ifreq)) { + break; + } + (void)memset_s(&ifreq, sizeof(struct ifreq), 0, sizeof(struct ifreq)); + if (netif->link_layer_type == LOOPBACK_IF) { + ret = snprintf_s(ifreq.ifr_name, IFNAMSIZ, (IFNAMSIZ - 1), "%.2s", netif->name); + if ((ret <= 0) || (ret >= IFNAMSIZ)) { + LWIP_DEBUGF(NETIF_DEBUG, ("lwip_ioctl: snprintf_s ifr_name failed.")); + return ENOBUFS; + } + } else { + ret = snprintf_s(ifreq.ifr_name, IFNAMSIZ, (IFNAMSIZ - 1), "%s", netif_get_name(netif)); + if ((ret <= 0) || (ret >= IFNAMSIZ)) { + LWIP_DEBUGF(NETIF_DEBUG, ("lwip_ioctl: snprintf_s ifr_name failed.")); + return ENOBUFS; + } + } + + sock_in = (struct sockaddr_in *)&ifreq.ifr_addr; + sock_in->sin_family = AF_INET; + sock_in->sin_addr.s_addr = ip_2_ip4(&netif->ip_addr)->addr; + if (memcpy_s(ifc->ifc_buf + pos, sizeof(struct ifreq), &ifreq, sizeof(struct ifreq)) != EOK) { + return ENOBUFS; + } + pos = pos + (int)sizeof(struct ifreq); + len = len - (int)sizeof(struct ifreq); + } + + ifc->ifc_len = pos; + + return 0; +} + +static u8_t lwip_ioctl_internal_SIOCGIFADDR(struct ifreq *ifr) +{ + struct netif *netif = NULL; + struct sockaddr_in *sock_in = NULL; + + /* get netif ipaddr */ + netif = netif_find(ifr->ifr_name); + if (netif == NULL) { + return ENODEV; + } else { + sock_in = (struct sockaddr_in *)&ifr->ifr_addr; + sock_in->sin_family = AF_INET; + sock_in->sin_addr.s_addr = ip_2_ip4(&netif->ip_addr)->addr; + return 0; + } +} + +static u8_t lwip_ioctl_internal_SIOCGIFNETMASK(struct ifreq *ifr) +{ + struct netif *netif = NULL; + struct sockaddr_in *sock_in = NULL; + + /* get netif netmask */ + netif = netif_find(ifr->ifr_name); + if (netif == NULL) { + return ENODEV; + } else { + sock_in = (struct sockaddr_in *)&ifr->ifr_netmask; + sock_in->sin_family = AF_INET; + sock_in->sin_addr.s_addr = ip_2_ip4(&netif->netmask)->addr; + return 0; + } +} + +static u8_t lwip_ioctl_internal_SIOCGIFHWADDR(struct ifreq *ifr) +{ + struct netif *netif = NULL; + + /* get netif hw addr */ + netif = netif_find(ifr->ifr_name); + if (netif == NULL) { + return ENODEV; + } +#if LWIP_HAVE_LOOPIF + else if (netif->link_layer_type == LOOPBACK_IF) { + return EPERM; + } +#endif /* LWIP_HAVE_LOOPIF */ + else { + if (memcpy_s((void *)ifr->ifr_hwaddr.sa_data, sizeof(ifr->ifr_hwaddr.sa_data), + (void *)netif->hwaddr, netif->hwaddr_len) != EOK) { + return EINVAL; + } + return 0; + } +} + +static u8_t lwip_ioctl_internal_SIOCSIFFLAGS(struct ifreq *ifr) +{ + struct netif *netif = NULL; + + /* set netif hw addr */ + netif = netif_find(ifr->ifr_name); + if (netif == NULL) { + return ENODEV; + } +#if LWIP_HAVE_LOOPIF + else if (netif->link_layer_type == LOOPBACK_IF) { + return EPERM; + } +#endif /* LWIP_HAVE_LOOPIF */ + else { + if (((unsigned short)ifr->ifr_flags & IFF_UP) && !(netif->flags & NETIF_FLAG_UP)) { + (void)netif_set_up(netif); + } else if (!((unsigned short)ifr->ifr_flags & IFF_UP) && (netif->flags & NETIF_FLAG_UP)) { + (void)netif_set_down(netif); + } + if (((unsigned short)ifr->ifr_flags & IFF_RUNNING) && !(netif->flags & NETIF_FLAG_LINK_UP)) { + (void)netif_set_link_up(netif); + } else if (!((unsigned short)ifr->ifr_flags & IFF_RUNNING) && (netif->flags & NETIF_FLAG_LINK_UP)) { + (void)netif_set_link_down(netif); + } + + if ((unsigned short)ifr->ifr_flags & IFF_BROADCAST) { + netif->flags |= NETIF_FLAG_BROADCAST; + } else { + netif->flags = netif->flags & (~NETIF_FLAG_BROADCAST); + } + if ((unsigned short)ifr->ifr_flags & IFF_NOARP) { + netif->flags = (netif->flags & (~NETIF_FLAG_ETHARP)); + } else { + netif->flags |= NETIF_FLAG_ETHARP; + } + + if ((unsigned short)ifr->ifr_flags & IFF_MULTICAST) { +#if LWIP_IGMP + netif->flags |= NETIF_FLAG_IGMP; +#endif /* LWIP_IGMP */ +#if LWIP_IPV6 && LWIP_IPV6_MLD + netif->flags |= NETIF_FLAG_MLD6; +#endif /* LWIP_IPV6_MLD */ + } else { +#if LWIP_IGMP + netif->flags = (netif->flags & ~NETIF_FLAG_IGMP); +#endif /* LWIP_IGMP */ +#if LWIP_IPV6 && LWIP_IPV6_MLD + netif->flags = (netif->flags & ~NETIF_FLAG_MLD6); +#endif /* LWIP_IPV6_MLD */ + } + +#if LWIP_DHCP + if ((unsigned short)ifr->ifr_flags & IFF_DYNAMIC) { + (void)dhcp_start(netif); + } else { + dhcp_stop(netif); +#if !LWIP_DHCP_SUBSTITUTE + dhcp_cleanup(netif); +#endif + } +#endif + +#if LWIP_NETIF_PROMISC + if (((unsigned short)ifr->ifr_flags & IFF_PROMISC)) { + netif->flags |= NETIF_FLAG_PROMISC; + } else { + netif->flags &= ~NETIF_FLAG_PROMISC; + } + if (netif->drv_config) { + netif->drv_config(netif, IFF_PROMISC, !!((unsigned short)ifr->ifr_flags & IFF_PROMISC)); + } +#endif /* LWIP_NETIF_PROMISC */ + return 0; + } +} + +static u8_t lwip_ioctl_internal_SIOCGIFFLAGS(struct ifreq *ifr) +{ + struct netif *netif = NULL; + + /* set netif hw addr */ + netif = netif_find(ifr->ifr_name); + if (netif == NULL) { + return ENODEV; + } else { + if (netif->flags & NETIF_FLAG_UP) { + ifr->ifr_flags = ((unsigned short)(ifr->ifr_flags)) | IFF_UP; + } else { + ifr->ifr_flags = ((unsigned short)(ifr->ifr_flags)) & ~IFF_UP; + } + if (netif->flags & NETIF_FLAG_LINK_UP) { + ifr->ifr_flags = ((unsigned short)(ifr->ifr_flags)) | IFF_RUNNING; + } else { + ifr->ifr_flags = ((unsigned short)(ifr->ifr_flags)) & ~IFF_RUNNING; + } + if (netif->flags & NETIF_FLAG_BROADCAST) { + ifr->ifr_flags = ((unsigned short)(ifr->ifr_flags)) | IFF_BROADCAST; + } else { + ifr->ifr_flags = ((unsigned short)(ifr->ifr_flags)) & ~IFF_BROADCAST; + } + if (netif->flags & NETIF_FLAG_ETHARP) { + ifr->ifr_flags = ((unsigned short)(ifr->ifr_flags)) & ~IFF_NOARP; + } else { + ifr->ifr_flags = ((unsigned short)(ifr->ifr_flags)) | IFF_NOARP; + } + +#if LWIP_IGMP || LWIP_IPV6_MLD + if ( +#if LWIP_IGMP + (netif->flags & NETIF_FLAG_IGMP) +#endif /* LWIP_IGMP */ +#if LWIP_IGMP && LWIP_IPV6_MLD + || +#endif /* LWIP_IGMP && LWIP_IPV6_MLD */ +#if LWIP_IPV6_MLD + (netif->flags & NETIF_FLAG_MLD6) +#endif /* LWIP_IPV6_MLD */ + ) { + ifr->ifr_flags = (short)((unsigned short)ifr->ifr_flags | IFF_MULTICAST); + } else { + ifr->ifr_flags = (short)((unsigned short)ifr->ifr_flags & (~IFF_MULTICAST)); + } +#endif /* LWIP_IGMP || LWIP_IPV6_MLD */ + +#if LWIP_DHCP + if (dhcp_supplied_address(netif)) { + ifr->ifr_flags = (short)((unsigned short)ifr->ifr_flags | IFF_DYNAMIC); + } else { + ifr->ifr_flags = (short)((unsigned short)ifr->ifr_flags & (~IFF_DYNAMIC)); + } +#endif + +#if LWIP_HAVE_LOOPIF + if (netif->link_layer_type == LOOPBACK_IF) { + ifr->ifr_flags = ((unsigned short)(ifr->ifr_flags)) | IFF_LOOPBACK; + } +#endif + +#if LWIP_NETIF_PROMISC + if (netif->flags & NETIF_FLAG_PROMISC) { + ifr->ifr_flags = ((unsigned short)(ifr->ifr_flags)) | IFF_PROMISC; + } else { + ifr->ifr_flags = ((unsigned short)(ifr->ifr_flags)) & ~IFF_PROMISC; + } +#endif /* LWIP_NETIF_PROMISC */ + + return 0; + } +} + +static u8_t lwip_ioctl_internal_SIOCGIFNAME(struct ifreq *ifr) +{ + struct netif *netif = NULL; + int ret; + + for (netif = netif_list; netif != NULL; netif = netif->next) { + if (ifr->ifr_ifindex == netif_get_index(netif)) { + break; + } + } + + if (netif == NULL) { + return ENODEV; + } else { + if (netif->link_layer_type == LOOPBACK_IF) { + ret = snprintf_s(ifr->ifr_name, IFNAMSIZ, (IFNAMSIZ - 1), "%.2s", netif->name); + if ((ret <= 0) || (ret >= IFNAMSIZ)) { + return ENOBUFS; + } + } else { + ret = snprintf_s(ifr->ifr_name, IFNAMSIZ, (IFNAMSIZ - 1), "%s", netif_get_name(netif)); + if ((ret <= 0) || (ret >= IFNAMSIZ)) { + return ENOBUFS; + } + } + return 0; + } +} + +static u8_t lwip_validate_ifname(const char *name, u8_t *let_pos) +{ + unsigned short num_pos = 0; + unsigned short letter_pos = 0; + unsigned short pos = 0; + u8_t have_num = 0; + + /* if the first position of variable name is not letter, such as '6eth2' */ + if (!((*name >= 'a' && *name <= 'z') || (*name >= 'A' && *name <= 'Z'))) { + return 0; + } + + /* check if the position of letter is bigger than the the position of digital */ + while (*name != '\0') { + if ((*name >= '0') && (*name <= '9')) { + num_pos = pos; + have_num = 1; + } else if (((*name >= 'a') && (*name <= 'z')) || ((*name >= 'A') && (*name <= 'Z'))) { + letter_pos = pos; + if (have_num != 0) { + return 0; + } + } else { + return 0; + } + pos++; + name++; + } + + /* for the speacil case as all position of variable name is letter, such as 'ethabc' */ + if (num_pos == 0) { + return 0; + } + + /* cheak if the digital in the variable name is bigger than 255, such as 'eth266' */ + if (atoi(name - (pos - letter_pos - 1)) > 255) { + return 0; + } + + *let_pos = (u8_t)letter_pos; + + return 1; +} + +static u8_t lwip_ioctl_internal_SIOCSIFNAME(struct ifreq *ifr) +{ + struct netif *netif = NULL; + u8_t letter_pos = 0; + + netif = netif_find(ifr->ifr_name); + if (netif == NULL) { + return ENODEV; + } else if (netif->link_layer_type == LOOPBACK_IF) { + return EPERM; + } else if ((netif->flags & IFF_UP) != 0) { + return EBUSY; + } else { + if (strncmp(ifr->ifr_name, ifr->ifr_newname, IFNAMSIZ) == 0) { + /* not change */ + return 0; + } + + ifr->ifr_newname[IFNAMSIZ - 1] = '\0'; + if ((lwip_validate_ifname(ifr->ifr_newname, &letter_pos) == 0) || (strlen(ifr->ifr_newname) > (IFNAMSIZ - 1))) { + return EINVAL; + } + + if (strncpy_s(netif->full_name, sizeof(netif->full_name), ifr->ifr_newname, strlen(ifr->ifr_newname)) != EOK) { + return EINVAL; + } + } + + return 0; +} + +static u8_t lwip_ioctl_internal_SIOCGIFINDEX(struct ifreq *ifr) +{ + struct netif *netif = NULL; + + netif = netif_find(ifr->ifr_name); + if (netif == NULL) { + return ENODEV; + } else { + ifr->ifr_ifindex = netif_get_index(netif); + return 0; + } +} + +static u8_t lwip_ioctl_internal_SIOCGIFMTU(struct ifreq *ifr) +{ + struct netif *netif = NULL; + + /* get netif hw addr */ + netif = netif_find(ifr->ifr_name); + if (netif == NULL) { + return ENODEV; + } else { + ifr->ifr_mtu = netif->mtu; + return 0; + } +} + +static u8_t lwip_ioctl_internal_SIOCGIFBRDADDR(struct ifreq *ifr) +{ + struct netif *netif = NULL; + struct sockaddr_in *sock_in = NULL; + + /* get netif subnet broadcast addr */ + netif = netif_find(ifr->ifr_name); + if (netif == NULL) { + return ENODEV; + } + if (ip4_addr_isany_val(*(ip_2_ip4(&netif->netmask)))) { + return ENXIO; + } + sock_in = (struct sockaddr_in *)&ifr->ifr_addr; + sock_in->sin_family = AF_INET; + sock_in->sin_addr.s_addr = (ip_2_ip4(&((netif)->ip_addr))->addr | ~(ip_2_ip4(&netif->netmask)->addr)); + return 0; +} + +static u8_t lwip_ioctl_impl(const struct lwip_sock *sock, long cmd, void *argp) +{ + u8_t err = 0; + struct ifreq *ifr = (struct ifreq *)argp; + u8_t is_ipv6 = 0; + + /* allow it only on IPv6 sockets... */ + is_ipv6 = NETCONNTYPE_ISIPV6((unsigned int)(sock->conn->type)); + + switch ((u32_t)cmd) { + case SIOCGIFCONF: + if (is_ipv6 != 0) { + err = EINVAL; + } else { + err = lwip_ioctl_internal_SIOCGIFCONF(ifr); + } + break; + case SIOCGIFADDR: + if (is_ipv6 != 0) { + err = EINVAL; + } else { + err = lwip_ioctl_internal_SIOCGIFADDR(ifr); + } + break; + case SIOCGIFNETMASK: + if (is_ipv6 != 0) { + err = EINVAL; + } else { + err = lwip_ioctl_internal_SIOCGIFNETMASK(ifr); + } + break; + case SIOCGIFHWADDR: + err = lwip_ioctl_internal_SIOCGIFHWADDR(ifr); + break; + case SIOCSIFFLAGS: + err = lwip_ioctl_internal_SIOCSIFFLAGS(ifr); + break; + case SIOCGIFFLAGS: + err = lwip_ioctl_internal_SIOCGIFFLAGS(ifr); + break; + case SIOCGIFNAME: + err = lwip_ioctl_internal_SIOCGIFNAME(ifr); + break; + case SIOCSIFNAME: + err = lwip_ioctl_internal_SIOCSIFNAME(ifr); + break; + case SIOCGIFINDEX: + err = lwip_ioctl_internal_SIOCGIFINDEX(ifr); + break; + case SIOCGIFMTU: + err = lwip_ioctl_internal_SIOCGIFMTU(ifr); + break; + case SIOCGIFBRDADDR: + if (is_ipv6 != 0) { + err = EINVAL; + } else { + err = lwip_ioctl_internal_SIOCGIFBRDADDR(ifr); + } + break; + default: + err = ENOSYS; + LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_ioctl(UNIMPL: 0x%lx)\n", cmd)); + break; + } + + return err; +} + +static err_t lwip_do_ioctl_impl(struct tcpip_api_call_data *call) +{ + struct lwip_ioctl_apimsg *msg = (struct lwip_ioctl_apimsg *)(void *)call; + return lwip_ioctl_impl(msg->sock, msg->cmd, msg->argp); +} \ No newline at end of file diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/src/sys_arch.c b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/src/sys_arch.c new file mode 100644 index 000000000..195c5d347 --- /dev/null +++ b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/src/sys_arch.c @@ -0,0 +1,445 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef LOSCFG_KERNEL_SMP +#define LOSCFG_KERNEL_SMP 0 +#endif + +#if (LOSCFG_KERNEL_SMP) +SPIN_LOCK_INIT(arch_protect_spin); +static u32_t lwprot_thread = LOS_ERRNO_TSK_ID_INVALID; +static int lwprot_count = 0; +#endif /* LOSCFG_KERNEL_SMP */ + +#define ROUND_UP_DIV(val, div) (((val) + (div) - 1) / (div)) +#define LWIP_LOG_BUF_SIZE 64 + +/** + * Thread and System misc + */ +sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread, void *arg, int stackSize, int prio) +{ + UINT32 taskID = LOS_ERRNO_TSK_ID_INVALID; + UINT32 ret; + TSK_INIT_PARAM_S task = {0}; + + if (name == NULL || (strlen(name) == 0)) { + LWIP_DEBUGF(SYS_DEBUG, ("sys_thread_new: name is null")); + return -1; + } + + /* Create host Task */ + task.pfnTaskEntry = (TSK_ENTRY_FUNC)thread; + task.uwStackSize = stackSize; + task.pcName = (char *)name; + task.usTaskPrio = prio; + task.pArgs = (UINTPTR)arg; + task.uwResved = LOS_TASK_STATUS_DETACHED; + ret = LOS_TaskCreate(&taskID, &task); + if (ret != LOS_OK) { + LWIP_DEBUGF(SYS_DEBUG, ("sys_thread_new: LOS_TaskCreate error %u\n", ret)); + return -1; + } + + return taskID; +} + +void sys_init(void) +{ + /* set rand seed to make random sequence diff on every startup */ + // UINT32 seedlsb = (UINT32)LOS_SysCycleGet(); + // srand(seedlsb); +} + +u32_t sys_now(void) +{ + /* Lwip docs mentioned like wraparound is not a problem in this function */ + return (u32_t)((LOS_TickCountGet() * OS_SYS_MS_PER_SECOND) / + LOSCFG_BASE_CORE_TICK_PER_SECOND); +} + +/** + * Protector + */ +sys_prot_t sys_arch_protect(void) +{ +#if (LOSCFG_KERNEL_SMP) + /* Note that we are using spinlock instead of mutex for LiteOS-SMP here: + * 1. spinlock is more effective for short critical region protection. + * 2. this function is called only in task context, not in interrupt handler. + * so it's not needed to disable interrupt. + */ + if (lwprot_thread != LOS_CurTaskIDGet()) { + /* We are locking the spinlock where it has not been locked before + * or is being locked by another thread */ + LOS_SpinLock(&arch_protect_spin); + lwprot_thread = LOS_CurTaskIDGet(); + lwprot_count = 1; + } else { + /* It is already locked by THIS thread */ + lwprot_count++; + } +#else + LOS_TaskLock(); +#endif /* LOSCFG_KERNEL_SMP */ + return 0; /* return value is unused */ +} + +void sys_arch_unprotect(sys_prot_t pval) +{ + LWIP_UNUSED_ARG(pval); +#if (LOSCFG_KERNEL_SMP) + if (lwprot_thread == LOS_CurTaskIDGet()) { + lwprot_count--; + if (lwprot_count == 0) { + lwprot_thread = LOS_ERRNO_TSK_ID_INVALID; + LOS_SpinUnlock(&arch_protect_spin); + } + } +#else + LOS_TaskUnlock(); +#endif /* LOSCFG_KERNEL_SMP */ +} + +/** + * MessageBox + */ +err_t sys_mbox_new(sys_mbox_t *mbox, int size) +{ + if (mbox == NULL) { + LWIP_DEBUGF(SYS_DEBUG, ("sys_mbox_new: mbox is null")); + return ERR_ARG; + } + + CHAR qName[] = "lwIP"; + UINT32 ret = LOS_QueueCreate(qName, (UINT16)size, (UINT32 *)mbox, 0, sizeof(void *)); + switch (ret) { + case LOS_OK: + return ERR_OK; + case LOS_ERRNO_QUEUE_CB_UNAVAILABLE: + case LOS_ERRNO_QUEUE_CREATE_NO_MEMORY: + return ERR_MEM; + default: + break; + } + LWIP_DEBUGF(SYS_DEBUG, ("%s: LOS_QueueCreate error %u\n", __FUNCTION__, ret)); + return ERR_ARG; +} + +void sys_mbox_post(sys_mbox_t *mbox, void *msg) +{ + if (mbox == NULL) { + LWIP_DEBUGF(SYS_DEBUG, ("sys_mbox_post: mbox is null")); + return; + } + + /* Caution: the second parameter is NOT &msg */ + UINT32 ret = LOS_QueueWrite(*mbox, msg, sizeof(char *), LOS_WAIT_FOREVER); + if (ret != LOS_OK) { + LWIP_DEBUGF(SYS_DEBUG, ("%s: LOS_QueueWrite error %u\n", __FUNCTION__, ret)); + } +} + +err_t sys_mbox_trypost(sys_mbox_t *mbox, void *msg) +{ + if (mbox == NULL) { + LWIP_DEBUGF(SYS_DEBUG, ("sys_mbox_trypost: mbox is null")); + return ERR_ARG; + } + + /* Caution: the second parameter is NOT &msg */ + UINT32 ret = LOS_QueueWrite(*mbox, msg, sizeof(char *), 0); + switch (ret) { + case LOS_OK: + return ERR_OK; + case LOS_ERRNO_QUEUE_ISFULL: + return ERR_MEM; + default: + break; + } + LWIP_DEBUGF(SYS_DEBUG, ("%s: LOS_QueueWrite error %u\n", __FUNCTION__, ret)); + return ERR_ARG; +} + +err_t sys_mbox_trypost_fromisr(sys_mbox_t *mbox, void *msg) +{ + (void)mbox; + (void)msg; + return ERR_ARG; +} + +u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeoutMs) +{ + if (mbox == NULL) { + LWIP_DEBUGF(SYS_DEBUG, ("sys_arch_mbox_fetch: mbox is null")); + return (u32_t)ERR_ARG; + } + + void *ignore = 0; /* if msg==NULL, the fetched msg should be dropped */ + UINT64 tick = ROUND_UP_DIV((UINT64)timeoutMs * LOSCFG_BASE_CORE_TICK_PER_SECOND, OS_SYS_MS_PER_SECOND); + UINT32 ret = LOS_QueueRead(*mbox, msg ? msg : &ignore, sizeof(void *), tick ? (UINT32)tick : LOS_WAIT_FOREVER); + switch (ret) { + case LOS_OK: + return ERR_OK; + case LOS_ERRNO_QUEUE_ISEMPTY: + case LOS_ERRNO_QUEUE_TIMEOUT: + return SYS_ARCH_TIMEOUT; + default: + break; + } + LWIP_DEBUGF(SYS_DEBUG, ("%s: LOS_QueueRead error %u\n", __FUNCTION__, ret)); + return SYS_ARCH_TIMEOUT; /* Errors should be treated as timeout */ +} + +u32_t sys_arch_mbox_tryfetch(sys_mbox_t *mbox, void **msg) +{ + if (mbox == NULL) { + LWIP_DEBUGF(SYS_DEBUG, ("sys_arch_mbox_tryfetch: mbox is null")); + return (u32_t)ERR_ARG; + } + + void *ignore = 0; /* if msg==NULL, the fetched msg should be dropped */ + UINT32 ret = LOS_QueueRead(*mbox, msg ? msg : &ignore, sizeof(void *), 0); + switch (ret) { + case LOS_OK: + return ERR_OK; + case LOS_ERRNO_QUEUE_ISEMPTY: + return SYS_MBOX_EMPTY; + case LOS_ERRNO_QUEUE_TIMEOUT: + return SYS_ARCH_TIMEOUT; + default: + break; + } + LWIP_DEBUGF(SYS_DEBUG, ("%s: LOS_QueueRead error %u\n", __FUNCTION__, ret)); + return SYS_MBOX_EMPTY; /* Errors should be treated as timeout */ +} + +void sys_mbox_free(sys_mbox_t *mbox) +{ + if (mbox == NULL) { + LWIP_DEBUGF(SYS_DEBUG, ("sys_mbox_free: mbox is null")); + return; + } + + (void)LOS_QueueDelete(*mbox); +} + +int sys_mbox_valid(sys_mbox_t *mbox) +{ + if (mbox == NULL) { + LWIP_DEBUGF(SYS_DEBUG, ("sys_mbox_valid: mbox is null")); + return ERR_ARG; + } + + QUEUE_INFO_S queueInfo; + return LOS_OK == LOS_QueueInfoGet(*mbox, &queueInfo); +} + +void sys_mbox_set_invalid(sys_mbox_t *mbox) +{ + if (mbox == NULL) { + LWIP_DEBUGF(SYS_DEBUG, ("sys_mbox_set_invalid: mbox is null")); + return; + } + + *mbox = LOSCFG_BASE_IPC_QUEUE_LIMIT; +} + +/** + * Semaphore + */ +err_t sys_sem_new(sys_sem_t *sem, u8_t count) +{ + if (sem == NULL) { + LWIP_DEBUGF(SYS_DEBUG, ("sys_sem_new: sem is null")); + return ERR_ARG; + } + + UINT32 ret = LOS_SemCreate(count, (UINT32 *)(sem)); + if (ret != LOS_OK) { + return ERR_ARG; + } + + return ERR_OK; +} + +void sys_sem_signal(sys_sem_t *sem) +{ + if (sem == NULL) { + LWIP_DEBUGF(SYS_DEBUG, ("sys_sem_signal: sem is null")); + return; + } + (void)LOS_SemPost(*sem); +} + +u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeoutMs) +{ + if (sem == NULL) { + LWIP_DEBUGF(SYS_DEBUG, ("sys_arch_sem_wait: sem is null")); + return (u32_t)ERR_ARG; + } + + UINT64 tick = ROUND_UP_DIV((UINT64)timeoutMs * LOSCFG_BASE_CORE_TICK_PER_SECOND, OS_SYS_MS_PER_SECOND); + UINT32 ret = LOS_SemPend(*sem, tick ? (UINT32)tick : LOS_WAIT_FOREVER); // timeoutMs 0 means wait forever + switch (ret) { + case LOS_OK: + return ERR_OK; + case LOS_ERRNO_SEM_TIMEOUT: + return SYS_ARCH_TIMEOUT; + default: + break; + } + LWIP_DEBUGF(SYS_DEBUG, ("%s: LOS_SemPend error %u\n", __FUNCTION__, ret)); + return SYS_ARCH_TIMEOUT; /* Errors should be treated as timeout */ +} + +void sys_sem_free(sys_sem_t *sem) +{ + if (sem == NULL) { + LWIP_DEBUGF(SYS_DEBUG, ("sys_sem_free: sem is null")); + return; + } + (void)LOS_SemDelete(*sem); +} + +int sys_sem_valid(sys_sem_t *sem) +{ + if (sem == NULL) { + LWIP_DEBUGF(SYS_DEBUG, ("sys_sem_valid: sem is null")); + return ERR_ARG; + } + return *sem != LOSCFG_BASE_IPC_SEM_LIMIT; +} + +void sys_sem_set_invalid(sys_sem_t *sem) +{ + if (sem == NULL) { + LWIP_DEBUGF(SYS_DEBUG, ("sys_sem_set_invalid: sem is null")); + return; + } + *sem = LOSCFG_BASE_IPC_SEM_LIMIT; +} + +/** + * Mutex + */ +err_t sys_mutex_new(sys_mutex_t *mutex) +{ + if (mutex == NULL) { + LWIP_DEBUGF(SYS_DEBUG, ("sys_mutex_new: mutex is null")); + return ERR_ARG; + } + + UINT32 ret = LOS_MuxCreate((UINT32 *)mutex); + if (ret != LOS_OK) { + return ERR_ARG; + } + + return ERR_OK; +} + +void sys_mutex_lock(sys_mutex_t *mutex) +{ + if (mutex == NULL) { + LWIP_DEBUGF(SYS_DEBUG, ("sys_mutex_lock: mutex is null")); + return; + } + + (void)LOS_MuxPend(*mutex, LOS_WAIT_FOREVER); +} + +void sys_mutex_unlock(sys_mutex_t *mutex) +{ + if (mutex == NULL) { + LWIP_DEBUGF(SYS_DEBUG, ("sys_mutex_unlock: mutex is null")); + return; + } + + (void)LOS_MuxPost(*mutex); +} + +void sys_mutex_free(sys_mutex_t *mutex) +{ + if (mutex == NULL) { + LWIP_DEBUGF(SYS_DEBUG, ("sys_mutex_free: mutex is null")); + return; + } + + (void)LOS_MuxDelete(*mutex); +} + +int sys_mutex_valid(sys_mutex_t *mutex) +{ + if (mutex == NULL) { + LWIP_DEBUGF(SYS_DEBUG, ("sys_mutex_valid: mutex is null")); + return ERR_ARG; + } + + return *mutex != LOSCFG_BASE_IPC_MUX_LIMIT; +} + +void sys_mutex_set_invalid(sys_mutex_t *mutex) +{ + if (mutex == NULL) { + LWIP_DEBUGF(SYS_DEBUG, ("sys_mutex_set_invalid: mutex is null")); + return; + } + + *mutex = LOSCFG_BASE_IPC_MUX_LIMIT; +} + +void LwipLogPrintf(const char *fmt, ...) +{ + if ((fmt == NULL) || (strlen(fmt) == 0)) { + return; + } + + int len; + char buf[LWIP_LOG_BUF_SIZE] = {0}; + va_list ap; + va_start(ap, fmt); + len = vsprintf_s(buf, sizeof(buf) - 1, fmt, ap); + va_end(ap); + if (len < 0) { + LWIP_LOGGER("log param invalid or buf is not enough."); + return; + } + LWIP_LOGGER(buf); +} diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/test/lwip_test.h b/code/sdk/open_source/openharmony/third_party/lwip/port/test/lwip_test.h new file mode 100644 index 000000000..33596887e --- /dev/null +++ b/code/sdk/open_source/openharmony/third_party/lwip/port/test/lwip_test.h @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef LWIP_TEST_H +#define LWIP_TEST_H + +#include "lwip/arch.h" +#include "lwip/sockets.h" +#include +#include +#include "securec.h" +#ifdef __cplusplus +extern "C" { +#endif + +extern int g_testCase; +extern int g_testError; +extern int g_testTemp; +#define LWIP_TEST_RET_OK 0 +#define LWIP_TEST_RET_ERR 1 + +#define LOCALHOST "127.0.0.1" +#define STACK_IP LOCALHOST +#define STACK_PORT 2277 +#define PEER_PORT STACK_PORT +#define SERVER_PORT STACK_PORT +#define CLIENT_PORT 2288 +#define PEER_IP LOCALHOST +#define BUF_SIZE (128 * 1) +#define IOV_LENGTH 2 +#define STACK_TEST_SIZE (0x800UL) + +#define ICUNIT_ASSERT_NOT_EQUAL(a, b, c) if ((a) == (b)) { \ + g_testError = (c); \ + LWIP_ASSERT("lwip test", 0); \ + } +#define ICUNIT_ASSERT_EQUAL(a, b, c) if ((a) != (b)) { \ + g_testError = (c); \ + LWIP_ASSERT("lwip test", 0); \ + } + + +#include "debug_print.h" + +#define LogPrintln(fmt, arg...) \ + PRINT("[lwip] %s: " fmt "\n", __FUNCTION__, ##arg) + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_TEST_H */ diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/test/net_socket_test_001.c b/code/sdk/open_source/openharmony/third_party/lwip/port/test/net_socket_test_001.c new file mode 100644 index 000000000..a92e9ba27 --- /dev/null +++ b/code/sdk/open_source/openharmony/third_party/lwip/port/test/net_socket_test_001.c @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "lwip_test.h" + +#define TEST_CASE 110 + +int SocketTest(void) +{ + LogPrintln("net_socket_test_001.c enter"); + g_testCase = TEST_CASE; + int fd = socket(0, 0, 0); + LWIP_ASSERT("socket invalid param.", fd == -1); + return LWIP_TEST_RET_OK; +} diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/test/net_socket_test_002.c b/code/sdk/open_source/openharmony/third_party/lwip/port/test/net_socket_test_002.c new file mode 100644 index 000000000..139b8ef7e --- /dev/null +++ b/code/sdk/open_source/openharmony/third_party/lwip/port/test/net_socket_test_002.c @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "lwip_test.h" +#include "lwipopts.h" +#include +#include + +#define MSG "Hi, I am UDP" +#define TEST_CASE 120 + +static char g_buf[BUF_SIZE + 1] = { 0 }; + +void UdpTestTask(void *p) +{ + (void)p; + LogPrintln("net_socket_test_002.c enter"); + g_testCase = TEST_CASE; + int sfd; + struct sockaddr_in srvAddr = { 0 }; + struct sockaddr_in clnAddr = { 0 }; + socklen_t clnAddrLen = sizeof(clnAddr); + int ret; + struct msghdr msg = { 0 }; + struct iovec iov[IOV_LENGTH] = { 0 }; + int recvCount = 0; + + /* socket creation */ + sfd = socket(AF_INET, SOCK_DGRAM, 0); + LWIP_ASSERT("socket invalid param.", sfd != -1); + + srvAddr.sin_family = AF_INET; + srvAddr.sin_addr.s_addr = inet_addr(STACK_IP); + srvAddr.sin_port = htons(STACK_PORT); + ret = bind(sfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr)); + LWIP_ASSERT("socket invalid param.", ret == 0); + + /* send */ + clnAddr.sin_family = AF_INET; + clnAddr.sin_addr.s_addr = inet_addr(PEER_IP); + clnAddr.sin_port = htons(PEER_PORT); + (void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf)); + (void)strcpy_s(g_buf, sizeof(g_buf), MSG); + ret = sendto(sfd, g_buf, strlen(MSG), 0, (struct sockaddr*)&clnAddr, + (socklen_t)sizeof(clnAddr)); + LWIP_ASSERT("socket invalid param.", ret != -1); + + ret = ioctlsocket(sfd, FIONREAD, &recvCount); + ICUNIT_ASSERT_EQUAL(ret, 0, 1); + LogPrintln("udp recv count %d", recvCount); + + /* recv */ + (void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf)); + ret = recvfrom(sfd, g_buf, sizeof(g_buf), 0, (struct sockaddr*)&clnAddr, + &clnAddrLen); + LWIP_ASSERT("socket invalid param.", ret == strlen(MSG)); + + /* sendmsg */ + clnAddr.sin_family = AF_INET; + clnAddr.sin_addr.s_addr = inet_addr(PEER_IP); + clnAddr.sin_port = htons(PEER_PORT); + (void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf)); + (void)strcpy_s(g_buf, sizeof(g_buf), MSG); + msg.msg_name = &clnAddr; + msg.msg_namelen = sizeof(clnAddr); + msg.msg_iov = iov; + msg.msg_iovlen = IOV_LENGTH; + iov[0].iov_base = g_buf; + iov[0].iov_len = strlen(MSG); + iov[1].iov_base = g_buf; + iov[1].iov_len = strlen(MSG); + ret = sendmsg(sfd, &msg, 0); + LWIP_ASSERT("socket invalid param.", ret == IOV_LENGTH * strlen(MSG)); + + /* recvmsg */ + (void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf)); + (void)memset_s(&msg, sizeof(msg), 0, sizeof(msg)); + msg.msg_name = &clnAddr; + msg.msg_namelen = sizeof(clnAddr); + msg.msg_iov = iov; + msg.msg_iovlen = 1; + iov[0].iov_base = g_buf; + iov[0].iov_len = sizeof(g_buf); + ret = recvmsg(sfd, &msg, 0); + LWIP_ASSERT("socket invalid param.", ret == IOV_LENGTH * strlen(MSG)); + + /* close socket */ + ret = closesocket(sfd); + LWIP_ASSERT("socket invalid param.", ret != -1); + return; +} + +int UdpTest() +{ + int ret = sys_thread_new("udp_test", UdpTestTask, NULL, + STACK_TEST_SIZE, TCPIP_THREAD_PRIO); + ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 23); + return ret; +} diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/test/net_socket_test_003.c b/code/sdk/open_source/openharmony/third_party/lwip/port/test/net_socket_test_003.c new file mode 100644 index 000000000..d9e896109 --- /dev/null +++ b/code/sdk/open_source/openharmony/third_party/lwip/port/test/net_socket_test_003.c @@ -0,0 +1,251 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "lwip_test.h" +#include "lwipopts.h" +#include +#include + +#define SRV_MSG "Hi, I am TCP server" +#define CLI_MSG "Hi, I am TCP client" +#define TEST_CASE 130 + +static char g_buf[BUF_SIZE + 1] = { 0 }; + +static int SampleTcpServer() +{ + g_testCase++; + int sfd, lsfd; + struct sockaddr_in srvAddr = { 0 }; + struct sockaddr_in clnAddr = { 0 }; + socklen_t clnAddrLen = sizeof(clnAddr); + struct msghdr msg = { 0 }; + struct iovec iov[IOV_LENGTH] = { 0 }; + int ret; + + /* tcp server */ + lsfd = socket(AF_INET, SOCK_STREAM, 0); + LogPrintln("create server socket inet stream: %d", lsfd); + ICUNIT_ASSERT_NOT_EQUAL(lsfd, -1, 1); + + srvAddr.sin_family = AF_INET; + srvAddr.sin_addr.s_addr = inet_addr(STACK_IP); + srvAddr.sin_port = htons(STACK_PORT); + ret = bind(lsfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr)); + LogPrintln("bind socket %d to %s:%d: %d", lsfd, inet_ntoa(srvAddr.sin_addr), ntohs(srvAddr.sin_port), ret); + ICUNIT_ASSERT_EQUAL(ret, 0, 2); + + ret = listen(lsfd, 0); + LogPrintln("listen socket %d: %d", lsfd, ret); + ICUNIT_ASSERT_EQUAL(ret, 0, 3); + + sfd = accept(lsfd, (struct sockaddr*)&clnAddr, &clnAddrLen); + LogPrintln("accept socket %d: %d <%s:%d>", lsfd, sfd, inet_ntoa(clnAddr.sin_addr), ntohs(clnAddr.sin_port)); + ICUNIT_ASSERT_NOT_EQUAL(sfd, -1, 4); + + /* send */ + (void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf)); + (void)strcpy_s(g_buf, sizeof(g_buf), SRV_MSG); + ret = send(sfd, g_buf, strlen(SRV_MSG), 0); + LogPrintln("server send on socket %d: %d", sfd, ret); + ICUNIT_ASSERT_EQUAL(ret, strlen(SRV_MSG), 5); + + /* recv */ + (void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf)); + ret = recv(sfd, g_buf, sizeof(g_buf), 0); + LogPrintln("server recv on socket %d: %d", sfd, ret); + LogPrintln("ser:%s", g_buf); + ICUNIT_ASSERT_EQUAL(ret, strlen(CLI_MSG), 6); + + /* sendmsg */ + clnAddr.sin_family = AF_INET; + clnAddr.sin_addr.s_addr = inet_addr(PEER_IP); + clnAddr.sin_port = htons(PEER_PORT); + (void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf)); + (void)strcpy_s(g_buf, sizeof(g_buf), SRV_MSG); + msg.msg_name = &clnAddr; + msg.msg_namelen = sizeof(clnAddr); + msg.msg_iov = iov; + msg.msg_iovlen = IOV_LENGTH; + iov[0].iov_base = g_buf; + iov[0].iov_len = strlen(SRV_MSG); + iov[1].iov_base = g_buf; + iov[1].iov_len = strlen(SRV_MSG); + ret = sendmsg(sfd, &msg, 0); + LogPrintln("sendmsg on socket %d: %d", sfd, ret); + ICUNIT_ASSERT_EQUAL(ret, IOV_LENGTH * strlen(SRV_MSG), 7); + + /* recvmsg */ + (void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf)); + (void)memset_s(&msg, sizeof(msg), 0, sizeof(msg)); + msg.msg_name = &clnAddr; + msg.msg_namelen = sizeof(clnAddr); + msg.msg_iov = iov; + msg.msg_iovlen = 1; + iov[0].iov_base = g_buf; + iov[0].iov_len = sizeof(g_buf); + ret = recvmsg(sfd, &msg, 0); + LogPrintln("recvmsg on socket %d: %d", sfd, ret); + ICUNIT_ASSERT_EQUAL(ret, IOV_LENGTH * strlen(CLI_MSG), 8); + + ret = shutdown(sfd, SHUT_RDWR); + LogPrintln("shutdown socket %d: %d", sfd, ret); + ICUNIT_ASSERT_EQUAL(ret, 0, 9); + + ret = closesocket(sfd); + ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 10); + ret = closesocket(lsfd); + ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 11); + + return 0; +} + +static int SampleTcpClient() +{ + g_testCase++; + int sfd; + struct sockaddr_in srvAddr = { 0 }; + struct sockaddr_in clnAddr = { 0 }; + int ret; + struct msghdr msg = { 0 }; + struct iovec iov[IOV_LENGTH] = { 0 }; + struct sockaddr addr; + socklen_t addrLen = sizeof(addr); + + /* tcp client connection */ + sfd = socket(AF_INET, SOCK_STREAM, 0); + LogPrintln("create client socket inet stream: %d", sfd); + ICUNIT_ASSERT_NOT_EQUAL(sfd, -1, 10); + + srvAddr.sin_family = AF_INET; + srvAddr.sin_addr.s_addr = inet_addr(PEER_IP); + srvAddr.sin_port = htons(PEER_PORT); + ret = connect(sfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr)); + LogPrintln("connect socket %d to %s:%d: %d", sfd, inet_ntoa(srvAddr.sin_addr), ntohs(srvAddr.sin_port), ret); + ICUNIT_ASSERT_EQUAL(ret, 0, 11); + + /* test getpeername */ + ret = getpeername(sfd, &addr, &addrLen); + LogPrintln("getpeername %d %s:%d: %d", \ + sfd, inet_ntoa(((struct sockaddr_in*)&addr)->sin_addr), ntohs(((struct sockaddr_in*)&addr)->sin_port), ret); + ICUNIT_ASSERT_EQUAL(ret, 0, 12); + ICUNIT_ASSERT_EQUAL(addrLen, sizeof(struct sockaddr_in), 13); + ICUNIT_ASSERT_EQUAL(((struct sockaddr_in*)&addr)->sin_addr.s_addr, \ + inet_addr(PEER_IP), 14); + + /* test getsockname */ + ret = getsockname(sfd, &addr, &addrLen); + LogPrintln("getsockname %d %s:%d: %d", \ + sfd, inet_ntoa(((struct sockaddr_in*)&addr)->sin_addr), ntohs(((struct sockaddr_in*)&addr)->sin_port), ret); + ICUNIT_ASSERT_EQUAL(ret, 0, 15); + ICUNIT_ASSERT_EQUAL(addrLen, sizeof(struct sockaddr_in), 16); + ICUNIT_ASSERT_EQUAL(((struct sockaddr_in*)&addr)->sin_addr.s_addr, \ + inet_addr(STACK_IP), 17); + + /* send */ + (void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf)); + (void)strcpy_s(g_buf, sizeof(g_buf), CLI_MSG); + ret = send(sfd, g_buf, strlen(CLI_MSG), 0); + LogPrintln("client send on socket %d: %d", sfd, ret); + ICUNIT_ASSERT_EQUAL(ret, strlen(CLI_MSG), 18); + + /* recv */ + (void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf)); + ret = recv(sfd, g_buf, sizeof(g_buf), 0); + LogPrintln("client recv on socket %d: %d", sfd, ret); + LogPrintln("cli:%s", g_buf); + ICUNIT_ASSERT_EQUAL(ret, strlen(SRV_MSG), 19); + + /* sendmsg */ + clnAddr.sin_family = AF_INET; + clnAddr.sin_addr.s_addr = inet_addr(PEER_IP); + clnAddr.sin_port = htons(PEER_PORT); + (void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf)); + (void)strcpy_s(g_buf, sizeof(g_buf), CLI_MSG); + msg.msg_name = &clnAddr; + msg.msg_namelen = sizeof(clnAddr); + msg.msg_iov = iov; + msg.msg_iovlen = IOV_LENGTH; + iov[0].iov_base = g_buf; + iov[0].iov_len = strlen(CLI_MSG); + iov[1].iov_base = g_buf; + iov[1].iov_len = strlen(CLI_MSG); + ret = sendmsg(sfd, &msg, 0); + LogPrintln("sendmsg on socket %d: %d", sfd, ret); + ICUNIT_ASSERT_EQUAL(ret, 2 * strlen(CLI_MSG), 20); + + /* recvmsg */ + (void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf)); + (void)memset_s(&msg, sizeof(msg), 0, sizeof(msg)); + msg.msg_name = &clnAddr; + msg.msg_namelen = sizeof(clnAddr); + msg.msg_iov = iov; + msg.msg_iovlen = 1; + iov[0].iov_base = g_buf; + iov[0].iov_len = sizeof(g_buf); + ret = recvmsg(sfd, &msg, 0); + LogPrintln("recvmsg on socket %d: %d", sfd, ret); + ICUNIT_ASSERT_EQUAL(ret, IOV_LENGTH * strlen(SRV_MSG), 21); + + ret = shutdown(sfd, SHUT_RDWR); + LogPrintln("shutdown socket %d: %d", sfd, ret); + ICUNIT_ASSERT_EQUAL(ret, 0, 22); + + ret = closesocket(sfd); + ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 23); + return 0; +} + +static void TcpServerRoutine(void *p) +{ + (void)p; + (void)SampleTcpServer(); +} + +static void TcpClientRoutine(void *p) +{ + (void)p; + (void)SampleTcpClient(); +} + +void TcpTest() +{ + LogPrintln("net_socket_test_003.c enter"); + g_testCase = TEST_CASE; + int ret; + ret = sys_thread_new("tcp_server", TcpServerRoutine, NULL, + STACK_TEST_SIZE, TCPIP_THREAD_PRIO); + ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 23); + + ret = sys_thread_new("tcp_client", TcpClientRoutine, NULL, + STACK_TEST_SIZE, TCPIP_THREAD_PRIO); + ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 24); +} diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/test/net_socket_test_004.c b/code/sdk/open_source/openharmony/third_party/lwip/port/test/net_socket_test_004.c new file mode 100644 index 000000000..e1a841013 --- /dev/null +++ b/code/sdk/open_source/openharmony/third_party/lwip/port/test/net_socket_test_004.c @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "lwip_test.h" + +#define TEST_CASE 140 +#define OPT_TIMEOUT 1000 + +int SockOptTest() +{ + LogPrintln("net_socket_test_004.c enter"); + g_testCase = TEST_CASE; + int ret, error, flag; + struct timeval timeout; + socklen_t len; + + int fd = socket(AF_INET, SOCK_STREAM, 0); + ICUNIT_ASSERT_NOT_EQUAL(fd, -1, 1); + + error = -1; + len = sizeof(error); + ret = getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len); + LogPrintln("getsockopt(%d, SOL_SOCKET, SO_ERROR, &error, &len)=%d, error=%d, len=%d, errno=%d", \ + fd, ret, error, len, errno); + ICUNIT_ASSERT_EQUAL(ret, 0, 2); + ICUNIT_ASSERT_EQUAL(error, 0, 3); + + len = sizeof(timeout); + ret = getsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, &len); + ICUNIT_ASSERT_EQUAL(ret, 0, 4); + + timeout.tv_sec = OPT_TIMEOUT; + len = sizeof(timeout); + ret = setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, len); + ICUNIT_ASSERT_EQUAL(ret, 0, 5); + + (void)memset_s(&timeout, len, 0, len); + ret = getsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, &len); + ICUNIT_ASSERT_EQUAL(ret, 0, 6); + ICUNIT_ASSERT_EQUAL(timeout.tv_sec, OPT_TIMEOUT, 7); + + error = -1; + len = sizeof(error); + ret = getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len); + LogPrintln("getsockopt(%d, SOL_SOCKET, SO_ERROR, &error, &len)=%d, error=%d, len=%d, errno=%d", \ + fd, ret, error, len, errno); + ICUNIT_ASSERT_EQUAL(ret, 0, 8); + ICUNIT_ASSERT_EQUAL(error, 0, 9); + + flag = 1; + ret = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(flag)); + LogPrintln("setsockopt(TCP_NODELAY) ret=%d", ret); + ICUNIT_ASSERT_EQUAL(ret, 0, 10); + + ret = closesocket(fd); + ICUNIT_ASSERT_EQUAL(ret, 0, 11); + + return LWIP_TEST_RET_OK; +} diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/test/net_socket_test_005.c b/code/sdk/open_source/openharmony/third_party/lwip/port/test/net_socket_test_005.c new file mode 100644 index 000000000..c7ec42892 --- /dev/null +++ b/code/sdk/open_source/openharmony/third_party/lwip/port/test/net_socket_test_005.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "lwip_test.h" + +#define TEST_CASE 150 + +int ByteOrderTest(void) +{ + LogPrintln("net_socket_test_005.c enter"); +#if BYTE_ORDER == LITTLE_ENDIAN + g_testCase = TEST_CASE + 1; + uint32_t hl = ntohl(0x12345678); + ICUNIT_ASSERT_EQUAL(hl, 0x78563412, 1); + + uint32_t nl = htonl(0x12345678); + ICUNIT_ASSERT_EQUAL(nl, 0x78563412, 2); + + uint16_t hs = ntohs(0x1234); + ICUNIT_ASSERT_EQUAL(hs, 0x3412, 3); + + uint16_t ns = htons(0x1234); + ICUNIT_ASSERT_EQUAL(ns, 0x3412, 4); +#else + g_testCase = TEST_CASE; + uint32_t hl = ntohl(0x12345678); + ICUNIT_ASSERT_EQUAL(hl, 0x12345678, 5); + + uint32_t nl = htonl(0x12345678); + ICUNIT_ASSERT_EQUAL(nl, 0x12345678, 6); + + uint16_t hs = ntohs(0x1234); + ICUNIT_ASSERT_EQUAL(hs, 0x1234, 7); + + uint16_t ns = htons(0x1234); + ICUNIT_ASSERT_EQUAL(ns, 0x1234, 8); +#endif + return LWIP_TEST_RET_OK; +} diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/test/net_socket_test_006.c b/code/sdk/open_source/openharmony/third_party/lwip/port/test/net_socket_test_006.c new file mode 100644 index 000000000..59a2789be --- /dev/null +++ b/code/sdk/open_source/openharmony/third_party/lwip/port/test/net_socket_test_006.c @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "lwip_test.h" + +#define TEST_CASE 160 +#define TEMP_BUF_SIZE 32 +int InetTest() +{ + LogPrintln("net_socket_test_006.c enter"); + g_testCase = TEST_CASE; + struct in_addr in; + int ret = inet_pton(AF_INET, "300.10.10.10", &in); + ICUNIT_ASSERT_EQUAL(ret, 0, 1); + + ret = inet_pton(AF_INET, "10.11.12.13", &in); + ICUNIT_ASSERT_EQUAL(ret, 1, 2); +#if BYTE_ORDER == LITTLE_ENDIAN + g_testCase++; + ICUNIT_ASSERT_EQUAL(in.s_addr, 0x0d0c0b0a, 3); +#else + ICUNIT_ASSERT_EQUAL(in.s_addr, 0x0a0b0c0d, 4); +#endif + + const char *p = inet_ntoa(in); + ICUNIT_ASSERT_EQUAL(strcmp(p, "10.11.12.13"), 0, 5); + + char buf[TEMP_BUF_SIZE]; + p = inet_ntop(AF_INET, &in, buf, sizeof(buf)); + ICUNIT_ASSERT_EQUAL(p, buf, 6); + ICUNIT_ASSERT_EQUAL(strcmp(p, "10.11.12.13"), 0, 7); + + return LWIP_TEST_RET_OK; +} diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/test/net_socket_test_007.c b/code/sdk/open_source/openharmony/third_party/lwip/port/test/net_socket_test_007.c new file mode 100644 index 000000000..bb4d6c9dc --- /dev/null +++ b/code/sdk/open_source/openharmony/third_party/lwip/port/test/net_socket_test_007.c @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "lwip_test.h" +#include "lwipopts.h" +#include +#include + +static char g_buf[BUF_SIZE + 1] = { 0 }; +static char g_buf_temp[BUF_SIZE + 1] = { 0 }; + +#define SEND_UDP_COUNT 10000 // send count +#define TEST_CASE 170 + +static void UdpTestMoreTask(void *p) +{ + (void)p; + LogPrintln("net_socket_test_007.c enter"); + if (g_testCase < TEST_CASE) { + g_testCase = TEST_CASE; + } else { + g_testCase++; + } + + int sfd; + struct sockaddr_in srvAddr = { 0 }; + struct sockaddr_in clnAddr = { 0 }; + socklen_t clnAddrLen = sizeof(clnAddr); + int ret; + int i; + + /* socket creation */ + sfd = socket(AF_INET, SOCK_DGRAM, 0); + LWIP_ASSERT("socket invalid param.", sfd != -1); + + srvAddr.sin_family = AF_INET; + srvAddr.sin_addr.s_addr = inet_addr(STACK_IP); + srvAddr.sin_port = htons(STACK_PORT); + ret = bind(sfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr)); + LWIP_ASSERT("socket invalid param.", ret == 0); + + /* send */ + clnAddr.sin_family = AF_INET; + clnAddr.sin_addr.s_addr = inet_addr(PEER_IP); + clnAddr.sin_port = htons(PEER_PORT); + if (g_buf_temp[0] == '\0') { + for (i = 0; i < BUF_SIZE; i++) { + g_buf_temp[i] = 'U'; + } + g_buf_temp[BUF_SIZE] = '\0'; + } + + LogPrintln("udp begin send"); + for (i = 0; i < SEND_UDP_COUNT; i++) { + ret = memcpy_s(g_buf, sizeof(g_buf), g_buf_temp, sizeof(g_buf_temp)); + ICUNIT_ASSERT_EQUAL(ret, EOK, 1); + ret = sendto(sfd, g_buf, BUF_SIZE, 0, (struct sockaddr*)&clnAddr, (socklen_t)sizeof(clnAddr)); + LWIP_ASSERT("socket invalid param.", ret != -1); + + /* recv */ + (void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf)); + ret = recvfrom(sfd, g_buf, sizeof(g_buf), 0, (struct sockaddr*)&clnAddr, + &clnAddrLen); + LWIP_ASSERT("socket invalid param.", ret == BUF_SIZE); + } + LogPrintln("udp end send"); + + /* close socket */ + ret = closesocket(sfd); + LWIP_ASSERT("socket invalid param.", ret != -1); +} + +void UdpTestMore() +{ + int ret; + ret = sys_thread_new("udp_more", UdpTestMoreTask, NULL, + STACK_TEST_SIZE * 2, TCPIP_THREAD_PRIO); + ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 10); +} + diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/test/net_socket_test_008.c b/code/sdk/open_source/openharmony/third_party/lwip/port/test/net_socket_test_008.c new file mode 100644 index 000000000..f46106a87 --- /dev/null +++ b/code/sdk/open_source/openharmony/third_party/lwip/port/test/net_socket_test_008.c @@ -0,0 +1,185 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "lwip_test.h" +#include "lwipopts.h" +#include +#include + +#define SEND_TCP_COUNT 1000 // send count +#define STACK_PORT_8 2288 +#define TEST_CASE 180 + +static char g_serverSendBuf[BUF_SIZE + 1] = { 0 }; +static char g_clientRecvBuf[BUF_SIZE + 1] = { 0 }; + +static void InitMsgBuf() +{ + int i; + if (g_serverSendBuf[0] != '\0') { + return; + } + for (i = 0; i < BUF_SIZE; i++) { + g_serverSendBuf[i] = 'S'; + } + g_serverSendBuf[BUF_SIZE] = '\0'; +} + +static int SampleTcpServer() +{ + g_testCase++; + int sfd, lsfd; + struct sockaddr_in srvAddr = { 0 }; + struct sockaddr_in clnAddr = { 0 }; + socklen_t clnAddrLen = sizeof(clnAddr); + int ret; + int i; + + /* tcp server */ + lsfd = socket(AF_INET, SOCK_STREAM, 0); + LogPrintln("create server socket inet stream: %d", lsfd); + ICUNIT_ASSERT_NOT_EQUAL(lsfd, -1, 1); + + srvAddr.sin_family = AF_INET; + srvAddr.sin_addr.s_addr = inet_addr(STACK_IP); + srvAddr.sin_port = htons(STACK_PORT_8); + ret = bind(lsfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr)); + LogPrintln("bind socket %d to %s:%d: %d", lsfd, inet_ntoa(srvAddr.sin_addr), ntohs(srvAddr.sin_port), ret); + ICUNIT_ASSERT_EQUAL(ret, 0, 2); + + ret = listen(lsfd, 0); + LogPrintln("listen socket %d: %d", lsfd, ret); + ICUNIT_ASSERT_EQUAL(ret, 0, 3); + + sfd = accept(lsfd, (struct sockaddr*)&clnAddr, &clnAddrLen); + LogPrintln("accept socket %d: %d <%s:%d>", lsfd, sfd, inet_ntoa(clnAddr.sin_addr), ntohs(clnAddr.sin_port)); + ICUNIT_ASSERT_NOT_EQUAL(sfd, -1, 4); + + for (i = 0; i < SEND_TCP_COUNT; i++) { + /* send */ + ret = send(sfd, g_serverSendBuf, BUF_SIZE, 0); + ICUNIT_ASSERT_EQUAL(ret, BUF_SIZE, 5); + } + ret = closesocket(sfd); + ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 7); + ret = closesocket(lsfd); + ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 8); + return 0; +} + +static int SampleTcpClient() +{ + g_testCase++; + int sfd; + struct sockaddr_in srvAddr = { 0 }; + int ret; + int i; + struct sockaddr addr; + socklen_t addrLen = sizeof(addr); + int recvCount = 0; + + /* tcp client connection */ + sfd = socket(AF_INET, SOCK_STREAM, 0); + LogPrintln("create client socket inet stream: %d", sfd); + ICUNIT_ASSERT_NOT_EQUAL(sfd, -1, 7); + + srvAddr.sin_family = AF_INET; + srvAddr.sin_addr.s_addr = inet_addr(PEER_IP); + srvAddr.sin_port = htons(STACK_PORT_8); + ret = connect(sfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr)); + LogPrintln("connect socket %d to %s:%d: %d", sfd, inet_ntoa(srvAddr.sin_addr), ntohs(srvAddr.sin_port), ret); + ICUNIT_ASSERT_EQUAL(ret, 0, 8); + + /* test getpeername */ + ret = getpeername(sfd, &addr, &addrLen); + LogPrintln("getpeername %d %s:%d: %d", + sfd, inet_ntoa(((struct sockaddr_in*)&addr)->sin_addr), ntohs(((struct sockaddr_in*)&addr)->sin_port), ret); + ICUNIT_ASSERT_EQUAL(ret, 0, 9); + ICUNIT_ASSERT_EQUAL(addrLen, sizeof(struct sockaddr_in), 10); + ICUNIT_ASSERT_EQUAL(((struct sockaddr_in*)&addr)->sin_addr.s_addr, \ + inet_addr(PEER_IP), 11); + + /* test getsockname */ + ret = getsockname(sfd, &addr, &addrLen); + LogPrintln("getsockname %d %s:%d: %d", + sfd, inet_ntoa(((struct sockaddr_in*)&addr)->sin_addr), ntohs(((struct sockaddr_in*)&addr)->sin_port), ret); + ICUNIT_ASSERT_EQUAL(ret, 0, 12); + ICUNIT_ASSERT_EQUAL(addrLen, sizeof(struct sockaddr_in), 13); + ICUNIT_ASSERT_EQUAL(((struct sockaddr_in*)&addr)->sin_addr.s_addr, \ + inet_addr(STACK_IP), 14); + + LogPrintln("tcp begin recv"); + for (i = 0; i < 2 * SEND_TCP_COUNT; i++) { + /* recv */ + (void)memset_s(g_clientRecvBuf, sizeof(g_clientRecvBuf), 0, sizeof(g_clientRecvBuf)); + ret = recv(sfd, g_clientRecvBuf, BUF_SIZE, 0); + recvCount += ret; + if (recvCount >= BUF_SIZE * SEND_TCP_COUNT) { + LogPrintln("client recv on socket %d: %d, i = %d", sfd, recvCount, i); + break; + } + } + ICUNIT_ASSERT_EQUAL(recvCount, BUF_SIZE * SEND_TCP_COUNT, recvCount); + LogPrintln("tcp end recv"); + ret = closesocket(sfd); + ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 17); + return 0; +} + +static void TcpServerRoutine(void *p) +{ + (void)p; + (void)SampleTcpServer(); +} + +static void TcpClientRoutine(void *p) +{ + (void)p; + (void)SampleTcpClient(); +} + +void TcpTestMore() +{ + LogPrintln("net_socket_test_008.c enter"); + if (g_testCase < TEST_CASE) { + g_testCase = TEST_CASE; + } + + int ret; + InitMsgBuf(); + ret = sys_thread_new("tcp_server_more", TcpServerRoutine, NULL, + STACK_TEST_SIZE, TCPIP_THREAD_PRIO); + ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 17); + + ret = sys_thread_new("tcp_client_more", TcpClientRoutine, NULL, + STACK_TEST_SIZE, TCPIP_THREAD_PRIO); + ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 18); +} diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/test/net_socket_test_009.c b/code/sdk/open_source/openharmony/third_party/lwip/port/test/net_socket_test_009.c new file mode 100644 index 000000000..95b678f42 --- /dev/null +++ b/code/sdk/open_source/openharmony/third_party/lwip/port/test/net_socket_test_009.c @@ -0,0 +1,165 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "lwip_test.h" +#include "lwipopts.h" +#include +#include + +#define SRV_MSG "Hi, I am TCP server" +#define CLI_MSG "Hi, I am TCP client" + +#define TEST_CASE 190 +#define STACK_PORT_9 2299 +#define TIME_OUT 10 // timeout 10s + +static char g_buf[BUF_SIZE + 1] = { 0 }; + +static int SampleTcpServer() +{ +#if LWIP_SOCKET_SELECT + g_testCase++; + int sfd, lsfd; + struct sockaddr_in srvAddr = { 0 }; + struct sockaddr_in clnAddr = { 0 }; + socklen_t clnAddrLen = sizeof(clnAddr); + fd_set fdsr; + struct timeval tv; + int ret; + + /* tcp server */ + lsfd = socket(AF_INET, SOCK_STREAM, 0); + LogPrintln("create server socket inet stream: %d", lsfd); + ICUNIT_ASSERT_NOT_EQUAL(lsfd, -1, 1); + + srvAddr.sin_family = AF_INET; + srvAddr.sin_addr.s_addr = inet_addr(STACK_IP); + srvAddr.sin_port = htons(STACK_PORT_9); + ret = bind(lsfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr)); + LogPrintln("bind socket %d to %s:%d: %d", lsfd, inet_ntoa(srvAddr.sin_addr), ntohs(srvAddr.sin_port), ret); + ICUNIT_ASSERT_EQUAL(ret, 0, 2); + + ret = listen(lsfd, 0); + LogPrintln("listen socket %d: %d", lsfd, ret); + ICUNIT_ASSERT_EQUAL(ret, 0, 3); + + FD_ZERO(&fdsr); + FD_SET(lsfd, &fdsr); + // timeout setting + tv.tv_sec = TIME_OUT; + tv.tv_usec = 0; + + ret = select(lsfd + 1, &fdsr, NULL, NULL, &tv); + if (ret < 0) { + LogPrintln("select error"); + ICUNIT_ASSERT_EQUAL(-1, 0, 4); + } else if (ret == 0) { + LogPrintln("select timeout"); + ICUNIT_ASSERT_EQUAL(-1, 0, 5); + } + + sfd = accept(lsfd, (struct sockaddr*)&clnAddr, &clnAddrLen); + LogPrintln("accept socket %d: %d <%s:%d>", lsfd, sfd, inet_ntoa(clnAddr.sin_addr), ntohs(clnAddr.sin_port)); + ICUNIT_ASSERT_NOT_EQUAL(sfd, -1, 6); + + /* send */ + (void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf)); + (void)strcpy_s(g_buf, sizeof(g_buf), SRV_MSG); + ret = send(sfd, g_buf, strlen(SRV_MSG), 0); + LogPrintln("server send on socket %d: %d", sfd, ret); + ICUNIT_ASSERT_EQUAL(ret, strlen(SRV_MSG), 7); + + ret = closesocket(sfd); + ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 8); + ret = closesocket(lsfd); + ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 9); +#endif + return 0; +} + +static int SampleTcpClient() +{ +#if LWIP_SOCKET_SELECT + g_testCase++; + int sfd; + struct sockaddr_in srvAddr = { 0 }; + int ret; + + /* tcp client connection */ + sfd = socket(AF_INET, SOCK_STREAM, 0); + LogPrintln("create client socket inet stream: %d", sfd); + ICUNIT_ASSERT_NOT_EQUAL(sfd, -1, 10); + + srvAddr.sin_family = AF_INET; + srvAddr.sin_addr.s_addr = inet_addr(PEER_IP); + srvAddr.sin_port = htons(STACK_PORT_9); + ret = connect(sfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr)); + LogPrintln("connect socket %d to %s:%d: %d", sfd, inet_ntoa(srvAddr.sin_addr), ntohs(srvAddr.sin_port), ret); + ICUNIT_ASSERT_EQUAL(ret, 0, 11); + + /* recv */ + (void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf)); + ret = recv(sfd, g_buf, sizeof(g_buf), 0); + LogPrintln("client recv on socket %d: %d", sfd, ret); + LogPrintln("cli:%s", g_buf); + ICUNIT_ASSERT_EQUAL(ret, strlen(SRV_MSG), 12); + + ret = closesocket(sfd); + ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 13); +#endif + return 0; +} + +static void TcpServerRoutine(void *p) +{ + (void)p; + (void)SampleTcpServer(); +} + +static void TcpClientRoutine(void *p) +{ + (void)p; + (void)SampleTcpClient(); +} + +void TcpTestSelect() +{ + LogPrintln("net_socket_test_009.c enter"); + g_testCase = TEST_CASE; + int ret; + ret = sys_thread_new("tcp_server_select", TcpServerRoutine, NULL, + STACK_TEST_SIZE, TCPIP_THREAD_PRIO); + ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 23); + + ret = sys_thread_new("tcp_client_select", TcpClientRoutine, NULL, + STACK_TEST_SIZE, TCPIP_THREAD_PRIO); + ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 24); +} diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/test/net_socket_test_010.c b/code/sdk/open_source/openharmony/third_party/lwip/port/test/net_socket_test_010.c new file mode 100644 index 000000000..354cbbd8f --- /dev/null +++ b/code/sdk/open_source/openharmony/third_party/lwip/port/test/net_socket_test_010.c @@ -0,0 +1,160 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "lwip_test.h" +#include "lwipopts.h" +#include +#include + +#define SRV_MSG "Hi, I am TCP server" +#define CLI_MSG "Hi, I am TCP client" + +#define TEST_CASE 200 +#define STACK_PORT_10 2230 +#define POLL_OPEN_MAX 10 +#define TIME_OUT (1000 * 10) // timeout 10s +static char g_buf[BUF_SIZE + 1] = { 0 }; + +static int SampleTcpServer() +{ +#if LWIP_SOCKET_POLL + g_testCase++; + int sfd, lsfd; + struct sockaddr_in srvAddr = { 0 }; + struct sockaddr_in clnAddr = { 0 }; + socklen_t clnAddrLen = sizeof(clnAddr); + struct pollfd client[POLL_OPEN_MAX] = {0}; + int ret; + + /* tcp server */ + lsfd = socket(AF_INET, SOCK_STREAM, 0); + LogPrintln("create server socket inet stream: %d", lsfd); + ICUNIT_ASSERT_NOT_EQUAL(lsfd, -1, 1); + + srvAddr.sin_family = AF_INET; + srvAddr.sin_addr.s_addr = inet_addr(STACK_IP); + srvAddr.sin_port = htons(STACK_PORT_10); + ret = bind(lsfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr)); + LogPrintln("bind socket %d to %s:%d: %d", lsfd, inet_ntoa(srvAddr.sin_addr), ntohs(srvAddr.sin_port), ret); + ICUNIT_ASSERT_EQUAL(ret, 0, 2); + + ret = listen(lsfd, 0); + LogPrintln("listen socket %d: %d", lsfd, ret); + ICUNIT_ASSERT_EQUAL(ret, 0, 3); + + client[0].fd = lsfd; + client[0].events = POLLIN; + ret = poll(client, 1, TIME_OUT); + if (ret < 0) { + LogPrintln("poll error"); + ICUNIT_ASSERT_EQUAL(-1, 0, 4); + } else if (ret == 0) { + LogPrintln("poll timeout"); + ICUNIT_ASSERT_EQUAL(-1, 0, 5); + } + + sfd = accept(lsfd, (struct sockaddr*)&clnAddr, &clnAddrLen); + LogPrintln("accept socket %d: %d <%s:%d>", lsfd, sfd, inet_ntoa(clnAddr.sin_addr), ntohs(clnAddr.sin_port)); + ICUNIT_ASSERT_NOT_EQUAL(sfd, -1, 6); + + /* recv */ + (void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf)); + ret = recv(sfd, g_buf, sizeof(g_buf), 0); + LogPrintln("server recv on socket %d: %d", sfd, ret); + LogPrintln("ser:%s", g_buf); + ICUNIT_ASSERT_EQUAL(ret, strlen(CLI_MSG), 7); + + ret = closesocket(sfd); + ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 8); + ret = closesocket(lsfd); + ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 9); +#endif + return 0; +} + +static int SampleTcpClient() +{ +#if LWIP_SOCKET_POLL + g_testCase++; + int sfd; + struct sockaddr_in srvAddr = { 0 }; + int ret; + + /* tcp client connection */ + sfd = socket(AF_INET, SOCK_STREAM, 0); + LogPrintln("create client socket inet stream: %d", sfd); + ICUNIT_ASSERT_NOT_EQUAL(sfd, -1, 10); + + srvAddr.sin_family = AF_INET; + srvAddr.sin_addr.s_addr = inet_addr(PEER_IP); + srvAddr.sin_port = htons(STACK_PORT_10); + ret = connect(sfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr)); + LogPrintln("connect socket %d to %s:%d: %d", sfd, inet_ntoa(srvAddr.sin_addr), ntohs(srvAddr.sin_port), ret); + ICUNIT_ASSERT_EQUAL(ret, 0, 11); + + /* send */ + (void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf)); + (void)strcpy_s(g_buf, sizeof(g_buf), CLI_MSG); + ret = send(sfd, g_buf, strlen(CLI_MSG), 0); + LogPrintln("client send on socket %d: %d", sfd, ret); + ICUNIT_ASSERT_EQUAL(ret, strlen(CLI_MSG), 12); + + ret = closesocket(sfd); + ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 13); +#endif + return 0; +} + +static void TcpServerRoutine(void *p) +{ + (void)p; + (void)SampleTcpServer(); +} + +static void TcpClientRoutine(void *p) +{ + (void)p; + (void)SampleTcpClient(); +} + +void TcpTestPoll() +{ + LogPrintln("net_socket_test_010.c enter"); + g_testCase = TEST_CASE; + int ret; + ret = sys_thread_new("tcp_server_poll", TcpServerRoutine, NULL, + STACK_TEST_SIZE, TCPIP_THREAD_PRIO); + ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 23); + + ret = sys_thread_new("tcp_client_poll", TcpClientRoutine, NULL, + STACK_TEST_SIZE, TCPIP_THREAD_PRIO); + ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 24); +} diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/test/net_socket_test_011.c b/code/sdk/open_source/openharmony/third_party/lwip/port/test/net_socket_test_011.c new file mode 100644 index 000000000..c64f9b779 --- /dev/null +++ b/code/sdk/open_source/openharmony/third_party/lwip/port/test/net_socket_test_011.c @@ -0,0 +1,444 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "lwip_test.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "lwip/prot/iana.h" + +#define MSG "Hi, I am testing BT netif." +#define STACK_IP_BT "192.168.167.1" +#define PEER_IP_BT "100.100.100.100" +#define GATEWAY_IP_BT "192.168.167.239" +#define NETIF_MAC "121212" +#define PEER_MAC "454545" +#define NETIF_NAME_BT "bt1000" +#define TEST_CASE 210 +static char g_buf[BUF_SIZE + 1] = { 0 }; +struct netif *btProxyNf = NULL; + +static void ReplayArpTask(); +static void ArpPackageProc(struct netif *netif, struct pbuf *p); +extern void driverif_input(struct netif *netif, struct pbuf *p); +static void ReplayArpEncodeEthernet(struct netif *netif, struct pbuf *p); + +static void ReplayUdpEncodeEthernet(struct netif *netif, struct pbuf *p) +{ + int ret; + ret = pbuf_add_header(p, SIZEOF_ETH_HDR); + ICUNIT_ASSERT_EQUAL(ret, 0, 1); + + struct eth_hdr *ethhdr; + ethhdr = (struct eth_hdr *)p->payload; + ethhdr->type = lwip_htons(ETHTYPE_IP); + SMEMCPY(ðhdr->dest, NETIF_MAC, ETH_HWADDR_LEN); + SMEMCPY(ðhdr->src, PEER_MAC, ETH_HWADDR_LEN); + + driverif_input(netif, p); +} + +static void ReplayUdpEncodeIp(struct pbuf *p, ip4_addr_t *src, ip4_addr_t *dest) +{ + struct ip_hdr *iphdr; + int ret; +#if CHECKSUM_GEN_IP_INLINE + u32_t chk_sum = 0; +#endif /* CHECKSUM_GEN_IP_INLINE */ + + // ip header + ret = pbuf_add_header(p, IP_HLEN); + ICUNIT_ASSERT_EQUAL(ret, 0, 2); + iphdr = (struct ip_hdr *)p->payload; + IPH_TTL_SET(iphdr, UDP_TTL); + IPH_PROTO_SET(iphdr, IP_PROTO_UDP); + +#if CHECKSUM_GEN_IP_INLINE + chk_sum += PP_NTOHS(IP_PROTO_UDP | (ttl << 8)); +#endif /* CHECKSUM_GEN_IP_INLINE */ + + /* dest cannot be NULL here */ + ip4_addr_copy(iphdr->dest, *dest); +#if CHECKSUM_GEN_IP_INLINE + chk_sum += ip4_addr_get_u32(&iphdr->dest) & 0xFFFF; + chk_sum += ip4_addr_get_u32(&iphdr->dest) >> 16; +#endif /* CHECKSUM_GEN_IP_INLINE */ + + u16_t ip_hlen = IP_HLEN; + IPH_VHL_SET(iphdr, 4, ip_hlen / 4); + IPH_TOS_SET(iphdr, 0); +#if CHECKSUM_GEN_IP_INLINE + chk_sum += PP_NTOHS(tos | (iphdr->_v_hl << 8)); +#endif /* CHECKSUM_GEN_IP_INLINE */ + IPH_LEN_SET(iphdr, lwip_htons(p->tot_len)); +#if CHECKSUM_GEN_IP_INLINE + chk_sum += iphdr->_len; +#endif /* CHECKSUM_GEN_IP_INLINE */ + IPH_OFFSET_SET(iphdr, 0); + IPH_ID_SET(iphdr, lwip_htons(0)); +#if CHECKSUM_GEN_IP_INLINE + chk_sum += iphdr->_id; +#endif /* CHECKSUM_GEN_IP_INLINE */ + ip4_addr_copy(iphdr->src, *src); + +#if CHECKSUM_GEN_IP_INLINE + chk_sum += ip4_addr_get_u32(&iphdr->src) & 0xFFFF; + chk_sum += ip4_addr_get_u32(&iphdr->src) >> 16; + chk_sum = (chk_sum >> 16) + (chk_sum & 0xFFFF); + chk_sum = (chk_sum >> 16) + chk_sum; + chk_sum = ~chk_sum; + IF__NETIF_CHECKSUM_ENABLED(netif, NETIF_CHECKSUM_GEN_IP) { + iphdr->_chksum = (u16_t)chk_sum; /* network order */ + } +#if LWIP_CHECKSUM_CTRL_PER_NETIF + else { + IPH_CHKSUM_SET(iphdr, 0); + } +#endif /* LWIP_CHECKSUM_CTRL_PER_NETIF */ +#else /* CHECKSUM_GEN_IP_INLINE */ + IPH_CHKSUM_SET(iphdr, 0); +#if CHECKSUM_GEN_IP + IF__NETIF_CHECKSUM_ENABLED(netif, NETIF_CHECKSUM_GEN_IP) { + IPH_CHKSUM_SET(iphdr, inet_chksum(iphdr, ip_hlen)); + } +#endif /* CHECKSUM_GEN_IP */ +#endif /* CHECKSUM_GEN_IP_INLINE */ + + ReplayUdpEncodeEthernet(btProxyNf, p); +} + +static void ReplayUdp(void *ptemp) +{ + struct udp_hdr *udphdr; + ip4_addr_t sipaddr, dipaddr; + int size = strlen(MSG); + int ret; + (void)ptemp; + + LogPrintln("encode udp replay packet"); + inet_pton(AF_INET, PEER_IP_BT, &sipaddr); + inet_pton(AF_INET, STACK_IP_BT, &dipaddr); + + struct pbuf *p = pbuf_alloc(PBUF_TRANSPORT, size, PBUF_RAM); + u16_t chksum = LWIP_CHKSUM_COPY(p->payload, MSG, size); + + // udp header + ret = pbuf_add_header(p, UDP_HLEN); + ICUNIT_ASSERT_EQUAL(ret, 0, 1); + udphdr = (struct udp_hdr *)p->payload; + udphdr->src = lwip_htons(STACK_PORT); + udphdr->dest = lwip_htons(STACK_PORT); + udphdr->len = lwip_htons(p->tot_len); + /* in UDP, 0 checksum means 'no checksum' */ + u16_t udpchksum = ip_chksum_pseudo_partial(p, IP_PROTO_UDP, p->tot_len, UDP_HLEN, &sipaddr, &dipaddr); + u32_t acc = udpchksum + (u16_t)~(chksum); + udpchksum = FOLD_U32T(acc); + if (udpchksum == 0x0000) { + udpchksum = 0xffff; + } + udphdr->chksum = udpchksum; + udphdr->chksum = 0; + + ReplayUdpEncodeIp(p, &sipaddr, &dipaddr); +} + +static void ReplayUdpTask() +{ + int ret; + ret = sys_thread_new("replay_udp", ReplayUdp, NULL, + STACK_TEST_SIZE, TCPIP_THREAD_PRIO); + ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 3); +} + +static void ParsePackageIpUdp(struct netif *netif, struct pbuf *btBuf) +{ + // get scr_addr and dest_addr from ip head + const struct ip_hdr *iphdr; + iphdr = (const struct ip_hdr *)btBuf->payload; + ip4_addr_p_t ip4_addr_scr = iphdr->src; + ip4_addr_p_t ip4_addr_dest = iphdr->dest; + char buf[32]; + int dataLen; + + // get scr_port and dest port from tcp head + u16_t scr_port, dest_port; + void *data; + struct udp_hdr *udphdr; + udphdr = (struct udp_hdr *)((u8_t *)iphdr + IPH_HL_BYTES(iphdr)); + scr_port = udphdr->src; + dest_port = udphdr->dest; + data = (void *)((u8_t *)udphdr + UDP_HLEN); + + LogPrintln("======Bt netif send package======"); + LogPrintln("netif full name %s", netif->full_name); + (void)inet_ntop(AF_INET, &ip4_addr_scr.addr, buf, sizeof(buf)); + LogPrintln("package src ip %s", buf); + (void)inet_ntop(AF_INET, &ip4_addr_dest.addr, buf, sizeof(buf)); + LogPrintln("package dest ip %s", buf); + LogPrintln("package src port %d", lwip_ntohs(scr_port)); + LogPrintln("package dest port %d", lwip_ntohs(dest_port)); + LogPrintln("send data %s", (char *)data); + dataLen = lwip_ntohs(udphdr->len) - UDP_HLEN; + LogPrintln("send data length %d", dataLen); + ICUNIT_ASSERT_EQUAL(dataLen, strlen(MSG), 4); + LogPrintln("================================="); + + ReplayUdpTask(); +} + +static void ParsePackageEthernet(struct netif *netif, struct pbuf *p) +{ + u16_t next_hdr_offset = SIZEOF_ETH_HDR; + // get src mac and dest mac + struct eth_hdr *ethhdr; + ethhdr = (struct eth_hdr *)p->payload; + u16_t type = ethhdr->type; + + switch (type) { +#if LWIP_IPV4 && LWIP_ARP + /* IP packet? */ + case PP_HTONS(ETHTYPE_IP): // 0x0008 + if (!(netif->flags & NETIF_FLAG_ETHARP)) { + return; + } + /* skip Ethernet header (min. size checked above) */ + if (pbuf_remove_header(p, next_hdr_offset)) { + return; + } else { + /* pass to IP layer */ + ParsePackageIpUdp(netif, p); + } + break; + + case PP_HTONS(ETHTYPE_ARP): // 0x0608 + if (!(netif->flags & NETIF_FLAG_ETHARP)) { + return; + } + /* skip Ethernet header (min. size checked above) */ + if (pbuf_remove_header(p, next_hdr_offset)) { + return; + } else { + /* pass p to ARP module */ + LogPrintln("recv arp packet"); + ArpPackageProc(netif, p); + } + break; +#endif /* LWIP_IPV4 && LWIP_ARP */ + + default: + LogPrintln("type is other %d", type); + break; + } +} + +static void BtProxySend(struct netif *netif, struct pbuf *p) +{ + if (netif == NULL || p == NULL) { + LogPrintln("%s : netif = NUll or p = NULL!", __func__); + return; + } +#if ETH_PAD_SIZE + (void)pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */ +#endif + ParsePackageEthernet(netif, p); +} + +static struct netif *CreateBtNetIf() +{ + struct netif *btNetif = NULL; + btNetif = (struct netif *)malloc(sizeof(struct netif)); + if (btNetif == NULL) { + LogPrintln("%s fail : netif malloc fail!", __func__); + LWIP_ASSERT("btNetif malloc fail.", 0); + return NULL; + } + (void)memset_s(btNetif, sizeof(struct netif), 0, sizeof(struct netif)); + btNetif->drv_send = BtProxySend; + btNetif->link_layer_type = BT_PROXY_IF; + btNetif->hwaddr_len = ETH_HWADDR_LEN; + (void)memcpy_s(&btNetif->hwaddr, sizeof(btNetif->hwaddr), NETIF_MAC, ETH_HWADDR_LEN); + (void)memcpy_s(&btNetif->full_name, sizeof(btNetif->full_name), NETIF_NAME_BT, sizeof(NETIF_NAME_BT)); + ip4_addr_t gw, ipaddr, netmask; + IP4_ADDR(&gw, 192, 168, 167, 239); + IP4_ADDR(&ipaddr, 192, 168, 167, 1); + IP4_ADDR(&netmask, 255, 255, 255, 255); + int ret = 0; + if ((ret = netifapi_netif_add(btNetif, &ipaddr, &netmask, &gw, btNetif, driverif_init, tcpip_input)) != ERR_OK) { + LogPrintln("%s : netifapi_netif_add fail!,ret=%d", __func__, ret); + LWIP_ASSERT("btNetif add fail.", 0); + return NULL; + } + LogPrintln("netifapi_netif_add success!"); + netif_set_link_up(btNetif); + netifapi_netif_set_up(btNetif); + return btNetif; +} + +static void UdpTestNetifTask(void *p) +{ + (void)p; + LogPrintln("net_socket_test_011.c enter"); + g_testCase = TEST_CASE; + int sfd; + struct sockaddr_in srvAddr = { 0 }; + struct sockaddr_in clnAddr = { 0 }; + socklen_t clnAddrLen = sizeof(clnAddr); + struct ifreq nif; + int ret; + + btProxyNf = CreateBtNetIf(); + + /* socket creation */ + sfd = socket(AF_INET, SOCK_DGRAM, 0); + LWIP_ASSERT("socket invalid param.", sfd != -1); + + srvAddr.sin_family = AF_INET; + srvAddr.sin_addr.s_addr = inet_addr(STACK_IP_BT); + srvAddr.sin_port = htons(STACK_PORT); + ret = bind(sfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr)); + LWIP_ASSERT("socket invalid param.", ret == 0); + + char *inface = NETIF_NAME_BT; + (void)strcpy_s(nif.ifr_name, sizeof(nif.ifr_name), inface); + if (setsockopt(sfd, SOL_SOCKET, SO_BINDTODEVICE, (char *)&nif, sizeof(nif)) < 0) { + LogPrintln("set intaface fail"); + LWIP_ASSERT("set intaface fail.", 0); + } + + /* send */ + clnAddr.sin_family = AF_INET; + clnAddr.sin_addr.s_addr = inet_addr(PEER_IP_BT); + clnAddr.sin_port = htons(PEER_PORT); + (void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf)); + (void)strcpy_s(g_buf, sizeof(g_buf), MSG); + ret = sendto(sfd, g_buf, strlen(MSG), 0, (struct sockaddr*)&clnAddr, + (socklen_t)sizeof(clnAddr)); + LogPrintln("client send success: %d", sfd); + LWIP_ASSERT("socket invalid param.", ret != -1); + + /* recv */ + (void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf)); + ret = recvfrom(sfd, g_buf, sizeof(g_buf), 0, (struct sockaddr*)&clnAddr, + &clnAddrLen); + LWIP_ASSERT("socket invalid param.", ret == strlen(MSG)); + LogPrintln("cli recv: %s", g_buf); + + /* close socket */ + ret = closesocket(sfd); + LWIP_ASSERT("socket invalid param.", ret != -1); + return; +} + +int UdpTestNetif() +{ + int ret = sys_thread_new("udp_test_netif", UdpTestNetifTask, NULL, + STACK_TEST_SIZE, TCPIP_THREAD_PRIO); + ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 23); + return ret; +} + +static void ArpPackageProc(struct netif *netif, struct pbuf *p) +{ + struct etharp_hdr *hdr; + ip4_addr_t sipaddr, dipaddr; + hdr = (struct etharp_hdr *)p->payload; + + if (hdr->opcode != PP_HTONS(ARP_REQUEST)) { + LogPrintln("opcode %d is not arp request", hdr->opcode); + return; + } + + inet_pton(AF_INET, GATEWAY_IP_BT, &sipaddr); + inet_pton(AF_INET, STACK_IP_BT, &dipaddr); + if (memcmp(&hdr->dipaddr, &sipaddr, sizeof(ip4_addr_t)) != EOK) { + LogPrintln("hdr->dipaddr %u is invalid", hdr->dipaddr); + return; + } + + ReplayArpTask(); +} + +static void ReplayArpEncodeEthernet(struct netif *netif, struct pbuf *p) +{ + int ret; + ret = pbuf_add_header(p, SIZEOF_ETH_HDR); + ICUNIT_ASSERT_EQUAL(ret, 0, 1); + + struct eth_hdr *ethhdr; + ethhdr = (struct eth_hdr *)p->payload; + ethhdr->type = lwip_htons(ETHTYPE_ARP); + SMEMCPY(ðhdr->dest, NETIF_MAC, ETH_HWADDR_LEN); + SMEMCPY(ðhdr->src, PEER_MAC, ETH_HWADDR_LEN); + + driverif_input(netif, p); +} + +static void ReplayArp(void *ptemp) +{ + struct etharp_hdr *hdr; + ip4_addr_t sipaddr, dipaddr; + + (void)ptemp; + LogPrintln("encode arp replay packet"); + inet_pton(AF_INET, GATEWAY_IP_BT, &sipaddr); + inet_pton(AF_INET, STACK_IP_BT, &dipaddr); + struct pbuf *p = pbuf_alloc(PBUF_LINK, SIZEOF_ETHARP_HDR, PBUF_RAM); + hdr = (struct etharp_hdr *)p->payload; + hdr->opcode = PP_HTONS(ARP_REPLY); + /* Write the ARP MAC-Addresses */ + SMEMCPY(&hdr->shwaddr, PEER_MAC, ETH_HWADDR_LEN); + SMEMCPY(&hdr->dhwaddr, NETIF_MAC, ETH_HWADDR_LEN); + /* Copy struct ip4_addr_wordaligned to aligned ip4_addr, to support compilers without + * structure packing. */ + IPADDR_WORDALIGNED_COPY_FROM_IP4_ADDR_T(&hdr->sipaddr, &sipaddr); + IPADDR_WORDALIGNED_COPY_FROM_IP4_ADDR_T(&hdr->dipaddr, &dipaddr); + hdr->hwtype = PP_HTONS(LWIP_IANA_HWTYPE_ETHERNET); + hdr->proto = PP_HTONS(ETHTYPE_IP); + /* set hwlen and protolen */ + hdr->hwlen = ETH_HWADDR_LEN; + hdr->protolen = sizeof(ip4_addr_t); + + ReplayArpEncodeEthernet(btProxyNf, p); +} + +static void ReplayArpTask() +{ + int ret; + ret = sys_thread_new("replay_arp", ReplayArp, NULL, + STACK_TEST_SIZE, TCPIP_THREAD_PRIO); + ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 23); +} diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/test/net_socket_test_012.c b/code/sdk/open_source/openharmony/third_party/lwip/port/test/net_socket_test_012.c new file mode 100644 index 000000000..9967c8b3a --- /dev/null +++ b/code/sdk/open_source/openharmony/third_party/lwip/port/test/net_socket_test_012.c @@ -0,0 +1,151 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "lwip_test.h" +#include "lwipopts.h" +#include +#include + +#define SRV_MSG "Hi, I am TCP server" +#define CLI_MSG "Hi, I am TCP client" +#define TEST_CASE 220 +#define TEST_COUNT 100 +#define STACK_PORT_TCP_DUP_START 3000 + +static int g_portServer = STACK_PORT_TCP_DUP_START; +static int g_portClient = STACK_PORT_TCP_DUP_START; + +static char g_bufServer[BUF_SIZE + 1] = { 0 }; +static char g_bufClient[BUF_SIZE + 1] = { 0 }; + +static int SampleTcpServer() +{ + int sfd, lsfd; + struct sockaddr_in srvAddr = { 0 }; + struct sockaddr_in clnAddr = { 0 }; + socklen_t clnAddrLen = sizeof(clnAddr); + int ret; + + /* tcp server */ + lsfd = socket(AF_INET, SOCK_STREAM, 0); + ICUNIT_ASSERT_NOT_EQUAL(lsfd, -1, 1); + + srvAddr.sin_family = AF_INET; + srvAddr.sin_addr.s_addr = inet_addr(STACK_IP); + srvAddr.sin_port = htons(g_portServer); + g_portServer++; + ret = bind(lsfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr)); + ICUNIT_ASSERT_EQUAL(ret, 0, 2); + + ret = listen(lsfd, 0); + ICUNIT_ASSERT_EQUAL(ret, 0, 3); + + sfd = accept(lsfd, (struct sockaddr*)&clnAddr, &clnAddrLen); + ICUNIT_ASSERT_NOT_EQUAL(sfd, -1, 4); + + /* send */ + (void)memset_s(g_bufServer, sizeof(g_bufServer), 0, sizeof(g_bufServer)); + (void)strcpy_s(g_bufServer, sizeof(g_bufServer), SRV_MSG); + ret = send(sfd, g_bufServer, strlen(SRV_MSG), 0); + ICUNIT_ASSERT_EQUAL(ret, strlen(SRV_MSG), 5); + + ret = closesocket(sfd); + ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 10); + ret = closesocket(lsfd); + ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 11); + + return 0; +} + +static int SampleTcpClient() +{ + int sfd; + struct sockaddr_in srvAddr = { 0 }; + int ret; + + /* tcp client connection */ + sfd = socket(AF_INET, SOCK_STREAM, 0); + ICUNIT_ASSERT_NOT_EQUAL(sfd, -1, 10); + + srvAddr.sin_family = AF_INET; + srvAddr.sin_addr.s_addr = inet_addr(PEER_IP); + srvAddr.sin_port = htons(g_portClient); + g_portClient++; + ret = connect(sfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr)); + ICUNIT_ASSERT_EQUAL(ret, 0, 11); + + /* recv */ + (void)memset_s(g_bufClient, sizeof(g_bufClient), 0, sizeof(g_bufClient)); + ret = recv(sfd, g_bufClient, sizeof(g_bufClient), 0); + ICUNIT_ASSERT_EQUAL(ret, strlen(SRV_MSG), 19); + + ret = closesocket(sfd); + ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 23); + return 0; +} + +static void TcpServerRoutine(void *p) +{ + (void)p; + g_testCase++; + + int i; + for (i = 0; i < TEST_COUNT; i++) { + (void)SampleTcpServer(); + } + LogPrintln("tcp server g_portServer = %d", g_portServer); +} + +static void TcpClientRoutine(void *p) +{ + (void)p; + g_testCase++; + + int i; + for (i = 0; i < TEST_COUNT; i++) { + (void)SampleTcpClient(); + } + LogPrintln("tcp server g_portClient = %d", g_portClient); +} + +void TcpTestDup() +{ + LogPrintln("net_socket_test_012.c enter"); + g_testCase = TEST_CASE; + int ret; + ret = sys_thread_new("tcp_server_dup", TcpServerRoutine, NULL, + STACK_TEST_SIZE, TCPIP_THREAD_PRIO); + ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 23); + + ret = sys_thread_new("tcp_client_dup", TcpClientRoutine, NULL, + STACK_TEST_SIZE, TCPIP_THREAD_PRIO); + ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 24); +} diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/test/net_socket_test_013.c b/code/sdk/open_source/openharmony/third_party/lwip/port/test/net_socket_test_013.c new file mode 100644 index 000000000..e1a7623df --- /dev/null +++ b/code/sdk/open_source/openharmony/third_party/lwip/port/test/net_socket_test_013.c @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "lwip_test.h" +#include "lwipopts.h" +#include +#include + +#define TEST_CASE 230 +#define STACK_PORT_TCP_LONG 2231 +#define TCP_LONG_BUF_SIZE (2 * 1024) + +static int SampleTcpServer() +{ + int sfd, lsfd; + struct sockaddr_in srvAddr = { 0 }; + struct sockaddr_in clnAddr = { 0 }; + socklen_t clnAddrLen = sizeof(clnAddr); + int ret; + static char serverBuf[TCP_LONG_BUF_SIZE] = {0}; + + /* tcp server */ + lsfd = socket(AF_INET, SOCK_STREAM, 0); + ICUNIT_ASSERT_NOT_EQUAL(lsfd, -1, 1); + + srvAddr.sin_family = AF_INET; + srvAddr.sin_addr.s_addr = inet_addr(STACK_IP); + srvAddr.sin_port = htons(STACK_PORT_TCP_LONG); + ret = bind(lsfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr)); + ICUNIT_ASSERT_EQUAL(ret, 0, 2); + + ret = listen(lsfd, 0); + ICUNIT_ASSERT_EQUAL(ret, 0, 3); + + sfd = accept(lsfd, (struct sockaddr*)&clnAddr, &clnAddrLen); + ICUNIT_ASSERT_NOT_EQUAL(sfd, -1, 4); + + /* send */ + ret = send(sfd, serverBuf, TCP_LONG_BUF_SIZE, 0); + ICUNIT_ASSERT_EQUAL(ret, TCP_LONG_BUF_SIZE, 6); + + ret = closesocket(sfd); + ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 7); + ret = closesocket(lsfd); + ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 8); + + return 0; +} + +static int SampleTcpClient() +{ + int sfd; + struct sockaddr_in srvAddr = { 0 }; + int ret, i; + int recvCount = 0; + static char clientBuf[TCP_LONG_BUF_SIZE] = {0}; + + /* tcp client connection */ + sfd = socket(AF_INET, SOCK_STREAM, 0); + ICUNIT_ASSERT_NOT_EQUAL(sfd, -1, 9); + + srvAddr.sin_family = AF_INET; + srvAddr.sin_addr.s_addr = inet_addr(PEER_IP); + srvAddr.sin_port = htons(STACK_PORT_TCP_LONG); + ret = connect(sfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr)); + ICUNIT_ASSERT_EQUAL(ret, 0, 10); + + /* recv */ + for (i = 0; i < TCP_LONG_BUF_SIZE; i++) { + ret = recv(sfd, clientBuf, TCP_LONG_BUF_SIZE, 0); + recvCount += ret; + if (recvCount >= TCP_LONG_BUF_SIZE) { + LogPrintln("client recv on socket %d: %d, i = %d", sfd, recvCount, i); + break; + } + } + ICUNIT_ASSERT_NOT_EQUAL(i, TCP_LONG_BUF_SIZE, 12); + ret = closesocket(sfd); + ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 13); + return 0; +} + +static void TcpServerRoutine(void *p) +{ + (void)p; + g_testCase++; + (void)SampleTcpServer(); +} + +static void TcpClientRoutine(void *p) +{ + (void)p; + g_testCase++; + (void)SampleTcpClient(); +} + +void TcpTestLong() +{ + LogPrintln("net_socket_test_013.c enter"); + g_testCase = TEST_CASE; + int ret; + ret = sys_thread_new("tcp_server_long", TcpServerRoutine, NULL, + STACK_TEST_SIZE, TCPIP_THREAD_PRIO); + ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 23); + + ret = sys_thread_new("tcp_client_long", TcpClientRoutine, NULL, + STACK_TEST_SIZE, TCPIP_THREAD_PRIO); + ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 24); +} diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/test/test_main.c b/code/sdk/open_source/openharmony/third_party/lwip/port/test/test_main.c new file mode 100644 index 000000000..ad6ee11b0 --- /dev/null +++ b/code/sdk/open_source/openharmony/third_party/lwip/port/test/test_main.c @@ -0,0 +1,160 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "sys/socket.h" +// #include "hos_cmsis_adp.h" +#include "cmsis_os2.h" +#include "lwip_test.h" + +#define LWIP_TEST_TIMEOUT 1000 // timeout 1s +#define LWIP_TEST_COUNT_FLAG 100 + +#define SOCKET_TEST 10 +#define UDP_TEST 20 +#define TCP_TEST 30 +#define OPT_TEST 40 +#define ORDER_TEST 50 +#define INET_TEST 60 +#define UDP_MORE_TEST 70 +#define TCP_MORE_TEST 80 +#define TCP_SELECT_TEST 90 +#define TCP_POLL_TEST 100 +#define NETIF_TEST 110 +#define TCP_DUP_TEST 120 +#define TCP_LONG_TEST 130 + +int g_lwipTimerCount = 0; +int g_testCase = LWIP_TEST_COUNT_FLAG; +int g_testError = 0; +int g_testTemp = LWIP_TEST_COUNT_FLAG; +extern void abort(void); +extern int SocketTest(void); +extern int UdpTest(void); +extern void TcpTest(); +extern int SockOptTest(); +extern int ByteOrderTest(void); +extern int InetTest(); +extern int UdpTestMore(void); +extern void TcpTestMore(); +extern void TcpTestSelect(); +extern void TcpTestPoll(); +extern int UdpTestNetif(void); +extern void TcpTestDup(); +extern void TcpTestLong(); + + +osTimerId_t g_lwipTestTimerId = NULL; + +// time out 1s +static void LwipTestTimeoutCallback(void const *argument) +{ + + g_lwipTimerCount++; + LogPrintln("LwipTestTimeoutCallback enter %d",g_lwipTimerCount); + if(g_lwipTimerCount > 130) + { + if (g_lwipTestTimerId != NULL) { + osTimerStop(g_lwipTestTimerId); + } + g_lwipTimerCount = 0; + } + switch (g_lwipTimerCount) { + case SOCKET_TEST: + SocketTest(); + break; + case UDP_TEST: + UdpTest(); + break; + case TCP_TEST: + TcpTest(); + break; + case OPT_TEST: + SockOptTest(); + break; + case ORDER_TEST: + ByteOrderTest(); + break; + case INET_TEST: + InetTest(); + break; + case UDP_MORE_TEST: + UdpTestMore(); + break; + case TCP_MORE_TEST: + TcpTestMore(); + break; + case TCP_SELECT_TEST: + // TcpTestSelect(); + break; + case TCP_POLL_TEST: + // TcpTestPoll(); + break; + case NETIF_TEST: + UdpTestNetif(); + break; + case TCP_DUP_TEST: + TcpTestDup(); + break; + case TCP_LONG_TEST: + TcpTestLong(); + break; + default: + break; + } +} + + +void LwipTestStartTimer(uint32_t timeout) +{ + osStatus_t status; + LogPrintln("LwipTestStartTimer timeout %d",timeout); + + if (g_lwipTestTimerId != NULL) { + status = osTimerStart(g_lwipTestTimerId, timeout); + if (status != osOK) { + return; + } + } else { + g_lwipTestTimerId = osTimerNew((osTimerFunc_t)LwipTestTimeoutCallback, osTimerPeriodic, NULL, NULL); + if (g_lwipTestTimerId == NULL) { + return; + } + status = osTimerStart(g_lwipTestTimerId, timeout); + if (status != osOK) { + return; + } + } +} + +void LwipTestEnter() +{ + LwipTestStartTimer(LWIP_TEST_TIMEOUT); +} diff --git a/code/sdk/open_source/openharmony/third_party/lwip/src/Filelists.cmake b/code/sdk/open_source/openharmony/third_party/lwip/src/Filelists.cmake index 07cf932ad..5430b38ee 100644 --- a/code/sdk/open_source/openharmony/third_party/lwip/src/Filelists.cmake +++ b/code/sdk/open_source/openharmony/third_party/lwip/src/Filelists.cmake @@ -84,7 +84,7 @@ set(lwipapi_SRCS ${LWIP_DIR}/src/api/netbuf.c ${LWIP_DIR}/src/api/netdb.c ${LWIP_DIR}/src/api/netifapi.c - ${LWIP_DIR}/src/api/sockets.c + # ${LWIP_DIR}/src/api/sockets.c ${LWIP_DIR}/src/api/tcpip.c ) diff --git a/code/sdk/open_source/openharmony/third_party/lwip/src/api/sockets.c b/code/sdk/open_source/openharmony/third_party/lwip/src/api/sockets.c index 092ee246d..1329a9a16 100644 --- a/code/sdk/open_source/openharmony/third_party/lwip/src/api/sockets.c +++ b/code/sdk/open_source/openharmony/third_party/lwip/src/api/sockets.c @@ -2534,7 +2534,6 @@ lwip_poll_should_wake(const struct lwip_select_cb *scb, int fd, int has_recveven #endif /* LWIP_SOCKET_POLL */ #if LWIP_SOCKET_SELECT || LWIP_SOCKET_POLL -#define poll_check_waiters(...) /** * Callback registered in the netconn layer for each socket-netconn. * Processes recvevent (data available) and wakes up tasks waiting for select. @@ -2631,7 +2630,7 @@ event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len) } else { SYS_ARCH_UNPROTECT(lev); } - poll_check_waiters(s, check_waiters); + // poll_check_waiters(s, check_waiters); done_socket(sock); } @@ -2648,7 +2647,6 @@ event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len) * select_cb_list during our UNPROTECT/PROTECT. We use a generational counter to * detect this change and restart the list walk. The list is expected to be small */ - static void select_check_waiters(int s, int has_recvevent, int has_sendevent, int has_errevent) { struct lwip_select_cb *scb; diff --git a/code/sdk/open_source/openharmony/third_party/lwip/src/include/lwip/arch.h b/code/sdk/open_source/openharmony/third_party/lwip/src/include/lwip/arch.h index 161f72098..58dae33aa 100644 --- a/code/sdk/open_source/openharmony/third_party/lwip/src/include/lwip/arch.h +++ b/code/sdk/open_source/openharmony/third_party/lwip/src/include/lwip/arch.h @@ -122,17 +122,17 @@ #if !defined(LWIP_HAVE_INT64) && defined(UINT64_MAX) #define LWIP_HAVE_INT64 1 #endif -// typedef uint8_t u8_t; -// typedef int8_t s8_t; -// typedef uint16_t u16_t; -// typedef int16_t s16_t; -// typedef uint32_t u32_t; -// typedef int32_t s32_t; +typedef uint8_t u8_t; +typedef int8_t s8_t; +typedef uint16_t u16_t; +typedef int16_t s16_t; +typedef uint32_t u32_t; +typedef int32_t s32_t; #if LWIP_HAVE_INT64 typedef uint64_t u64_t; typedef int64_t s64_t; #endif -// typedef uintptr_t mem_ptr_t; +typedef uintptr_t mem_ptr_t; #endif /** Define this to 1 in arch/cc.h of your port if your compiler does not provide diff --git a/code/sdk/open_source/openharmony/third_party/lwip/src/include/lwip/debug.h b/code/sdk/open_source/openharmony/third_party/lwip/src/include/lwip/debug.h index 326bde8fe..579fd242b 100644 --- a/code/sdk/open_source/openharmony/third_party/lwip/src/include/lwip/debug.h +++ b/code/sdk/open_source/openharmony/third_party/lwip/src/include/lwip/debug.h @@ -134,10 +134,10 @@ /** Enable debug message printing, but only if debug message type is enabled * AND is of correct type AND is at least LWIP_DBG_LEVEL. */ -// #ifdef __DOXYGEN__ -// #define LWIP_DEBUG -// #undef LWIP_DEBUG -// #endif +#ifdef __DOXYGEN__ +#define LWIP_DEBUG +#undef LWIP_DEBUG +#endif #ifdef LWIP_DEBUG #define LWIP_DEBUGF(debug, message) do { \ diff --git a/code/sdk/open_source/openharmony/third_party/lwip/src/include/lwip/sockets.h b/code/sdk/open_source/openharmony/third_party/lwip/src/include/lwip/sockets.h index 82df7a254..7d089b726 100644 --- a/code/sdk/open_source/openharmony/third_party/lwip/src/include/lwip/sockets.h +++ b/code/sdk/open_source/openharmony/third_party/lwip/src/include/lwip/sockets.h @@ -695,7 +695,7 @@ ssize_t lwip_recvfrom_internal(int s, void *mem, size_t len, int flags, struct s #define ioctl(s,cmd,argp) lwip_ioctl(s,cmd,argp) #endif /* LWIP_POSIX_SOCKETS_IO_NAMES */ #endif /* LWIP_COMPAT_SOCKETS != 2 */ -#define DF_NADDR(addr) ip_addr_t naddr = addr + #endif /* LWIP_COMPAT_SOCKETS */ #ifdef __cplusplus diff --git a/code/sdk/open_source/openharmony/third_party/lwip/src/include/netif/slipif.h b/code/sdk/open_source/openharmony/third_party/lwip/src/include/netif/slipif.h index 2593a5a19..65ba31f83 100644 --- a/code/sdk/open_source/openharmony/third_party/lwip/src/include/netif/slipif.h +++ b/code/sdk/open_source/openharmony/third_party/lwip/src/include/netif/slipif.h @@ -56,7 +56,7 @@ * If disabled, slipif_poll() polls the serial line (using sio_tryread()). */ #ifndef SLIP_RX_FROM_ISR -#define SLIP_RX_FROM_ISR 1 +#define SLIP_RX_FROM_ISR 0 #endif /** Set this to 1 (default for SLIP_RX_FROM_ISR) to queue incoming packets