From e96e3e07f52e9815af11aacddfbc8ad004d7c114 Mon Sep 17 00:00:00 2001 From: "Man, Jianting (Meco)" <920369182@qq.com> Date: Wed, 23 Feb 2022 10:56:43 -0500 Subject: [PATCH] [lwip] integrate lwip porting layer (#5606) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [lwip] integrate lwip porting layer * Lwip 通用文件梳理 (#2) * [modify] extract the common files for different version about lwip. * [update] the initialization logic of lwIP. * 整理源码结构 * ethernetif 头文件 ""改为<> * 整理代码 * add macro definition "RT_USING_DEVICE_IPC". * [update] mandatory selected "RT_USING_DEVICE_IPC". * [modify] compile error for lost "lwip/init.h" Co-authored-by: xiangxistu <52819708+xiangxistu@users.noreply.github.com> Co-authored-by: liuxianliang --- bsp/lm3s9b9x/rtconfig.h | 1 + bsp/lpc176x/rtconfig.h | 1 + bsp/sam7x/rtconfig.h | 1 + components/net/at/SConscript | 6 +- components/net/lwip/Kconfig | 3 +- components/net/lwip/lwip-1.4.1/SConscript | 3 - .../src/arch/include/arch/bpstruct.h | 35 - .../src/arch/include/arch/epstruct.h | 35 - .../lwip-1.4.1/src/arch/include/arch/perf.h | 52 - .../src/arch/include/arch/sys_arch.h | 58 - .../net/lwip/lwip-1.4.1/src/arch/sys_arch.c | 740 ------------ .../lwip-1.4.1/src/include/netif/ethernetif.h | 52 - .../lwip/lwip-1.4.1/src/netif/ethernetif.c | 945 --------------- components/net/lwip/lwip-2.0.3/SConscript | 3 - .../src/arch/include/arch/bpstruct.h | 35 - .../lwip-2.0.3/src/arch/include/arch/cc.h | 108 -- .../src/arch/include/arch/epstruct.h | 35 - .../lwip-2.0.3/src/arch/include/arch/perf.h | 52 - .../src/arch/include/arch/sys_arch.h | 57 - .../net/lwip/lwip-2.0.3/src/arch/sys_arch.c | 773 ------------- .../lwip-2.0.3/src/include/netif/ethernetif.h | 53 - .../lwip/lwip-2.0.3/src/netif/ethernetif.c | 1022 ----------------- components/net/lwip/lwip-2.1.2/SConscript | 15 +- .../src/arch/include/arch/bpstruct.h | 35 - .../lwip-2.1.2/src/arch/include/arch/cc.h | 106 -- .../src/arch/include/arch/epstruct.h | 35 - .../lwip-2.1.2/src/include/netif/ethernetif.h | 52 - components/net/lwip/port/SConscript | 10 + components/net/lwip/port/arch/bpstruct.h | 13 + .../src/arch/include => port}/arch/cc.h | 15 +- components/net/lwip/port/arch/epstruct.h | 13 + .../src/arch/include => port}/arch/perf.h | 52 +- .../src/arch/include => port}/arch/sys_arch.h | 12 +- .../src/netif => port}/ethernetif.c | 214 ++-- components/net/lwip/port/netif/ethernetif.h | 61 + .../{lwip-2.1.2/src/arch => port}/sys_arch.c | 388 +++---- 36 files changed, 427 insertions(+), 4664 deletions(-) delete mode 100644 components/net/lwip/lwip-1.4.1/src/arch/include/arch/bpstruct.h delete mode 100644 components/net/lwip/lwip-1.4.1/src/arch/include/arch/epstruct.h delete mode 100644 components/net/lwip/lwip-1.4.1/src/arch/include/arch/perf.h delete mode 100644 components/net/lwip/lwip-1.4.1/src/arch/include/arch/sys_arch.h delete mode 100644 components/net/lwip/lwip-1.4.1/src/arch/sys_arch.c delete mode 100644 components/net/lwip/lwip-1.4.1/src/include/netif/ethernetif.h delete mode 100644 components/net/lwip/lwip-1.4.1/src/netif/ethernetif.c delete mode 100644 components/net/lwip/lwip-2.0.3/src/arch/include/arch/bpstruct.h delete mode 100644 components/net/lwip/lwip-2.0.3/src/arch/include/arch/cc.h delete mode 100644 components/net/lwip/lwip-2.0.3/src/arch/include/arch/epstruct.h delete mode 100644 components/net/lwip/lwip-2.0.3/src/arch/include/arch/perf.h delete mode 100644 components/net/lwip/lwip-2.0.3/src/arch/include/arch/sys_arch.h delete mode 100644 components/net/lwip/lwip-2.0.3/src/arch/sys_arch.c delete mode 100644 components/net/lwip/lwip-2.0.3/src/include/netif/ethernetif.h delete mode 100644 components/net/lwip/lwip-2.0.3/src/netif/ethernetif.c delete mode 100644 components/net/lwip/lwip-2.1.2/src/arch/include/arch/bpstruct.h delete mode 100644 components/net/lwip/lwip-2.1.2/src/arch/include/arch/cc.h delete mode 100644 components/net/lwip/lwip-2.1.2/src/arch/include/arch/epstruct.h delete mode 100644 components/net/lwip/lwip-2.1.2/src/include/netif/ethernetif.h create mode 100644 components/net/lwip/port/SConscript create mode 100644 components/net/lwip/port/arch/bpstruct.h rename components/net/lwip/{lwip-1.4.1/src/arch/include => port}/arch/cc.h (93%) create mode 100644 components/net/lwip/port/arch/epstruct.h rename components/net/lwip/{lwip-2.1.2/src/arch/include => port}/arch/perf.h (82%) rename components/net/lwip/{lwip-2.1.2/src/arch/include => port}/arch/sys_arch.h (91%) rename components/net/lwip/{lwip-2.1.2/src/netif => port}/ethernetif.c (90%) create mode 100644 components/net/lwip/port/netif/ethernetif.h rename components/net/lwip/{lwip-2.1.2/src/arch => port}/sys_arch.c (72%) diff --git a/bsp/lm3s9b9x/rtconfig.h b/bsp/lm3s9b9x/rtconfig.h index 741899fb34..a69dccc906 100644 --- a/bsp/lm3s9b9x/rtconfig.h +++ b/bsp/lm3s9b9x/rtconfig.h @@ -57,6 +57,7 @@ /* SECTION: Device System */ /* Using Device System*/ #define RT_USING_DEVICE +#define RT_USING_DEVICE_IPC #define RT_USING_UART1 // #define RT_USING_UART2 diff --git a/bsp/lpc176x/rtconfig.h b/bsp/lpc176x/rtconfig.h index c15fc48ee5..f75a88f851 100644 --- a/bsp/lpc176x/rtconfig.h +++ b/bsp/lpc176x/rtconfig.h @@ -64,6 +64,7 @@ //
#define RT_USING_DEVICE +#define RT_USING_DEVICE_IPC // #define RT_USING_UART0 // diff --git a/bsp/sam7x/rtconfig.h b/bsp/sam7x/rtconfig.h index 432f347569..70a06c79bf 100644 --- a/bsp/sam7x/rtconfig.h +++ b/bsp/sam7x/rtconfig.h @@ -57,6 +57,7 @@ /* SECTION: Device System */ /* Using Device System*/ #define RT_USING_DEVICE +#define RT_USING_DEVICE_IPC #define RT_USING_UART1 #define RT_UART_RX_BUFFER_SIZE 128 diff --git a/components/net/at/SConscript b/components/net/at/SConscript index 81df9738b8..2a06470d38 100644 --- a/components/net/at/SConscript +++ b/components/net/at/SConscript @@ -13,13 +13,13 @@ if GetDepend(['AT_USING_SERVER']): src/at_server.c src/at_base_cmd.c ''') - + if GetDepend(['AT_USING_CLIENT']): src += Glob('src/at_client.c') - + if GetDepend(['AT_USING_SOCKET']): src += Glob('at_socket/*.c') - path += [cwd + '/at_socket'] + path += [cwd + '/at_socket'] group = DefineGroup('AT', src, depend = ['RT_USING_AT'], CPPPATH = path) diff --git a/components/net/lwip/Kconfig b/components/net/lwip/Kconfig index dce5a74a52..8299540493 100644 --- a/components/net/lwip/Kconfig +++ b/components/net/lwip/Kconfig @@ -1,6 +1,7 @@ -menuconfig RT_USING_LWIP +menuconfig RT_USING_LWIP bool "Enable light weight TCP/IP stack (lwIP)" select RT_USING_DEVICE + select RT_USING_DEVICE_IPC default n if RT_USING_LWIP diff --git a/components/net/lwip/lwip-1.4.1/SConscript b/components/net/lwip/lwip-1.4.1/SConscript index 848e2d8255..8525e89f2a 100644 --- a/components/net/lwip/lwip-1.4.1/SConscript +++ b/components/net/lwip/lwip-1.4.1/SConscript @@ -10,7 +10,6 @@ src/api/netdb.c src/api/netifapi.c src/api/sockets.c src/api/tcpip.c -src/arch/sys_arch.c src/core/def.c src/core/dhcp.c src/core/dns.c @@ -35,7 +34,6 @@ src/core/ipv4/ip.c src/core/ipv4/ip_addr.c src/core/ipv4/ip_frag.c src/netif/etharp.c -src/netif/ethernetif.c src/netif/slipif.c """) @@ -68,7 +66,6 @@ src/netif/ppp/vj.c path = [GetCurrentDir() + '/src', GetCurrentDir() + '/src/include', GetCurrentDir() + '/src/include/ipv4', - GetCurrentDir() + '/src/arch/include', GetCurrentDir() + '/src/include/netif'] if GetDepend(['RT_LWIP_SNMP']): diff --git a/components/net/lwip/lwip-1.4.1/src/arch/include/arch/bpstruct.h b/components/net/lwip/lwip-1.4.1/src/arch/include/arch/bpstruct.h deleted file mode 100644 index 74ead358fa..0000000000 --- a/components/net/lwip/lwip-1.4.1/src/arch/include/arch/bpstruct.h +++ /dev/null @@ -1,35 +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(__ICCARM__) -#pragma pack(1) -#endif diff --git a/components/net/lwip/lwip-1.4.1/src/arch/include/arch/epstruct.h b/components/net/lwip/lwip-1.4.1/src/arch/include/arch/epstruct.h deleted file mode 100644 index f6390959ea..0000000000 --- a/components/net/lwip/lwip-1.4.1/src/arch/include/arch/epstruct.h +++ /dev/null @@ -1,35 +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(__ICCARM__) -#pragma pack() -#endif diff --git a/components/net/lwip/lwip-1.4.1/src/arch/include/arch/perf.h b/components/net/lwip/lwip-1.4.1/src/arch/include/arch/perf.h deleted file mode 100644 index 675f1f65dc..0000000000 --- a/components/net/lwip/lwip-1.4.1/src/arch/include/arch/perf.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2001, 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. - * - * This file is part of the lwIP TCP/IP stack. - * - * Author: Adam Dunkels - * - * $Id: perf.h,v 1.1.1.1 2004/12/16 14:17:13 bear Exp $ - */ -#ifndef __ARCH_PERF_H__ -#define __ARCH_PERF_H__ - -//#include - -#define PERF_START /* null definition */ -#define PERF_STOP(x) /* null definition */ - -/* -void perf_print(unsigned long c1l, unsigned long c1h, - unsigned long c2l, unsigned long c2h, - char *key); - -void perf_print_times(struct tms *start, struct tms *end, char *key); - -void perf_init(char *fname); -*/ -#endif /* __ARCH_PERF_H__ */ diff --git a/components/net/lwip/lwip-1.4.1/src/arch/include/arch/sys_arch.h b/components/net/lwip/lwip-1.4.1/src/arch/include/arch/sys_arch.h deleted file mode 100644 index f3cfef9821..0000000000 --- a/components/net/lwip/lwip-1.4.1/src/arch/include/arch/sys_arch.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2001, 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. - * - * This file is part of the lwIP TCP/IP stack. - * - * Author: Adam Dunkels - * - * $Id: sys_arch.h,v 1.3 2005/03/13 16:03:23 bear Exp $ - */ -#ifndef __ARCH_SYS_ARCH_H__ -#define __ARCH_SYS_ARCH_H__ - -#include "arch/cc.h" -#include - -#define SYS_MBOX_NULL RT_NULL -#define SYS_SEM_NULL RT_NULL - -typedef rt_uint32_t sys_prot_t; - -#define SYS_MBOX_SIZE 10 -#define SYS_LWIP_TIMER_NAME "timer" -#define SYS_LWIP_MBOX_NAME "mbox" -#define SYS_LWIP_SEM_NAME "sem" -#define SYS_LWIP_MUTEX_NAME "mu" - -typedef rt_sem_t sys_sem_t; -typedef rt_mutex_t sys_mutex_t; -typedef rt_mailbox_t sys_mbox_t; -typedef rt_thread_t sys_thread_t; - - -#endif /* __ARCH_SYS_ARCH_H__ */ diff --git a/components/net/lwip/lwip-1.4.1/src/arch/sys_arch.c b/components/net/lwip/lwip-1.4.1/src/arch/sys_arch.c deleted file mode 100644 index af2a4b891e..0000000000 --- a/components/net/lwip/lwip-1.4.1/src/arch/sys_arch.c +++ /dev/null @@ -1,740 +0,0 @@ -/* - * COPYRIGHT (C) 2006-2021, RT-Thread Development Team - * 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. - * - * Change Logs: - * Date Author Notes - * 2012-12-8 Bernard add file header - * export bsd socket symbol for RT-Thread Application Module - * 2017-11-15 Bernard add lock for init_done callback. - */ - -#include -#include - -#include "lwip/sys.h" -#include "lwip/opt.h" -#include "lwip/stats.h" -#include "lwip/err.h" -#include "arch/sys_arch.h" -#include "lwip/debug.h" -#include "lwip/netif.h" -#include "lwip/tcpip.h" -#include "netif/ethernetif.h" -#include "lwip/sio.h" -#include -#include "lwip/inet.h" - -#include - -/* - * Initialize the network interface device - * - * @return the operation status, ERR_OK on OK, ERR_IF on error - */ -static err_t netif_device_init(struct netif *netif) -{ - struct eth_device *ethif; - - ethif = (struct eth_device *)netif->state; - if (ethif != RT_NULL) - { - rt_device_t device; - - /* get device object */ - device = (rt_device_t) ethif; - if (rt_device_init(device) != RT_EOK) - { - return ERR_IF; - } - - /* copy device flags to netif flags */ - netif->flags = ethif->flags; - - return ERR_OK; - } - - return ERR_IF; -} -/* - * Initialize the ethernetif layer and set network interface device up - */ -static void tcpip_init_done_callback(void *arg) -{ - rt_device_t device; - struct eth_device *ethif; - struct ip_addr ipaddr, netmask, gw; - struct rt_list_node* node; - struct rt_object* object; - struct rt_object_information *information; - - LWIP_ASSERT("invalid arg.\n",arg); - - IP4_ADDR(&gw, 0,0,0,0); - IP4_ADDR(&ipaddr, 0,0,0,0); - IP4_ADDR(&netmask, 0,0,0,0); - - /* enter critical */ - rt_enter_critical(); - - /* for each network interfaces */ - information = rt_object_get_information(RT_Object_Class_Device); - RT_ASSERT(information != RT_NULL); - for (node = information->object_list.next; - node != &(information->object_list); - node = node->next) - { - object = rt_list_entry(node, struct rt_object, list); - device = (rt_device_t)object; - if (device->type == RT_Device_Class_NetIf) - { - ethif = (struct eth_device *)device; - - /* leave critical */ - rt_exit_critical(); - LOCK_TCPIP_CORE(); - - netif_add(ethif->netif, &ipaddr, &netmask, &gw, - ethif, netif_device_init, tcpip_input); - - if (netif_default == RT_NULL) - netif_set_default(ethif->netif); - -#if LWIP_DHCP - if (ethif->flags & NETIF_FLAG_DHCP) - { - /* if this interface uses DHCP, start the DHCP client */ - dhcp_start(ethif->netif); - } - else -#endif - { - /* set interface up */ - netif_set_up(ethif->netif); - } - - if (!(ethif->flags & ETHIF_LINK_PHYUP)) - { - netif_set_link_up(ethif->netif); - } - - UNLOCK_TCPIP_CORE(); - /* enter critical */ - rt_enter_critical(); - } - } - - /* leave critical */ - rt_exit_critical(); - rt_sem_release((rt_sem_t)arg); -} - -/** - * LwIP system initialization - */ -int lwip_system_init(void) -{ - rt_err_t rc; - struct rt_semaphore done_sem; - - /* set default netif to NULL */ - netif_default = RT_NULL; - - rc = rt_sem_init(&done_sem, "done", 0, RT_IPC_FLAG_FIFO); - - if (rc != RT_EOK) - { - LWIP_ASSERT("Failed to create semaphore", 0); - - return -1; - } - - tcpip_init(tcpip_init_done_callback, (void *)&done_sem); - - /* waiting for initialization done */ - if (rt_sem_take(&done_sem, RT_WAITING_FOREVER) != RT_EOK) - { - rt_sem_detach(&done_sem); - - return -1; - } - rt_sem_detach(&done_sem); - - /* set default ip address */ -#if !LWIP_DHCP - if (netif_default != RT_NULL) - { - struct ip_addr ipaddr, netmask, gw; - - ipaddr.addr = inet_addr(RT_LWIP_IPADDR); - gw.addr = inet_addr(RT_LWIP_GWADDR); - netmask.addr = inet_addr(RT_LWIP_MSKADDR); - - netifapi_netif_set_addr(netif_default, &ipaddr, &netmask, &gw); - } -#endif - rt_kprintf("lwIP-%d.%d.%d initialized!\n", LWIP_VERSION_MAJOR, LWIP_VERSION_MINOR, LWIP_VERSION_REVISION); - - return 0; -} -INIT_PREV_EXPORT(lwip_system_init); - -void sys_init(void) -{ - /* nothing on RT-Thread porting */ -} - -void lwip_sys_init(void) -{ - lwip_system_init(); -} - -/* - * Create a new semaphore - * - * @return the operation status, ERR_OK on OK; others on error - */ -err_t sys_sem_new(sys_sem_t *sem, u8_t count) -{ - static unsigned short counter = 0; - char tname[RT_NAME_MAX]; - sys_sem_t tmpsem; - - RT_DEBUG_NOT_IN_INTERRUPT; - - rt_snprintf(tname, RT_NAME_MAX, "%s%d", SYS_LWIP_SEM_NAME, counter); - counter ++; - - tmpsem = rt_sem_create(tname, count, RT_IPC_FLAG_FIFO); - if (tmpsem == RT_NULL) - return ERR_MEM; - else - { - *sem = tmpsem; - - return ERR_OK; - } -} - -/* - * Deallocate a semaphore - */ -void sys_sem_free(sys_sem_t *sem) -{ - RT_DEBUG_NOT_IN_INTERRUPT; - rt_sem_delete(*sem); -} - -/* - * Signal a semaphore - */ -void sys_sem_signal(sys_sem_t *sem) -{ - rt_sem_release(*sem); -} - -/* - * Block the thread while waiting for the semaphore to be signaled - * - * @return If the timeout argument is non-zero, it will return the number of milliseconds - * spent waiting for the semaphore to be signaled; If the semaphore isn't signaled - * within the specified time, it will return SYS_ARCH_TIMEOUT; If the thread doesn't - * wait for the semaphore, it will return zero - */ -u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout) -{ - rt_err_t ret; - s32_t t; - u32_t tick; - - RT_DEBUG_NOT_IN_INTERRUPT; - - /* get the begin tick */ - tick = rt_tick_get(); - if (timeout == 0) - t = RT_WAITING_FOREVER; - else - { - /* convert msecond to os tick */ - if (timeout < (1000/RT_TICK_PER_SECOND)) - t = 1; - else - t = timeout / (1000/RT_TICK_PER_SECOND); - } - - ret = rt_sem_take(*sem, t); - - if (ret == -RT_ETIMEOUT) - return SYS_ARCH_TIMEOUT; - else - { - if (ret == RT_EOK) - ret = 1; - } - - /* get elapse msecond */ - tick = rt_tick_get() - tick; - - /* convert tick to msecond */ - tick = tick * (1000 / RT_TICK_PER_SECOND); - if (tick == 0) - tick = 1; - - return tick; -} - -#ifndef sys_sem_valid -/** Check if a semaphore is valid/allocated: - * return 1 for valid, 0 for invalid - */ -int sys_sem_valid(sys_sem_t *sem) -{ - return (int)(*sem); -} -#endif - -#ifndef sys_sem_set_invalid -/** Set a semaphore invalid so that sys_sem_valid returns 0 - */ -void sys_sem_set_invalid(sys_sem_t *sem) -{ - *sem = RT_NULL; -} -#endif - -/* ====================== Mutex ====================== */ - -/** Create a new mutex - * @param mutex pointer to the mutex to create - * @return a new mutex - */ -err_t sys_mutex_new(sys_mutex_t *mutex) -{ - static unsigned short counter = 0; - char tname[RT_NAME_MAX]; - sys_mutex_t tmpmutex; - - RT_DEBUG_NOT_IN_INTERRUPT; - - rt_snprintf(tname, RT_NAME_MAX, "%s%d", SYS_LWIP_MUTEX_NAME, counter); - counter ++; - - tmpmutex = rt_mutex_create(tname, RT_IPC_FLAG_PRIO); - if (tmpmutex == RT_NULL) - return ERR_MEM; - else - { - *mutex = tmpmutex; - - return ERR_OK; - } -} - -/** Lock a mutex - * @param mutex the mutex to lock - */ -void sys_mutex_lock(sys_mutex_t *mutex) -{ - RT_DEBUG_NOT_IN_INTERRUPT; - rt_mutex_take(*mutex, RT_WAITING_FOREVER); - - return; -} - -/** Unlock a mutex - * @param mutex the mutex to unlock - */ -void sys_mutex_unlock(sys_mutex_t *mutex) -{ - rt_mutex_release(*mutex); -} - -/** Delete a semaphore - * @param mutex the mutex to delete - */ -void sys_mutex_free(sys_mutex_t *mutex) -{ - RT_DEBUG_NOT_IN_INTERRUPT; - - rt_mutex_delete(*mutex); -} - -#ifndef sys_mutex_valid -/** Check if a mutex is valid/allocated: - * return 1 for valid, 0 for invalid - */ -int sys_mutex_valid(sys_mutex_t *mutex) -{ - return (int)(*mutex); -} -#endif - -#ifndef sys_mutex_set_invalid -/** Set a mutex invalid so that sys_mutex_valid returns 0 - */ -void sys_mutex_set_invalid(sys_mutex_t *mutex) -{ - *mutex = RT_NULL; -} -#endif - -/* ====================== Mailbox ====================== */ - -/* - * Create an empty mailbox for maximum "size" elements - * - * @return the operation status, ERR_OK on OK; others on error - */ -err_t sys_mbox_new(sys_mbox_t *mbox, int size) -{ - static unsigned short counter = 0; - char tname[RT_NAME_MAX]; - sys_mbox_t tmpmbox; - - RT_DEBUG_NOT_IN_INTERRUPT; - - rt_snprintf(tname, RT_NAME_MAX, "%s%d", SYS_LWIP_MBOX_NAME, counter); - counter ++; - - tmpmbox = rt_mb_create(tname, size, RT_IPC_FLAG_FIFO); - if (tmpmbox != RT_NULL) - { - *mbox = tmpmbox; - - return ERR_OK; - } - - return ERR_MEM; -} - -/* - * Deallocate a mailbox - */ -void sys_mbox_free(sys_mbox_t *mbox) -{ - RT_DEBUG_NOT_IN_INTERRUPT; - - rt_mb_delete(*mbox); - - return; -} - -/** Post a message to an mbox - may not fail - * -> blocks if full, only used from tasks not from ISR - * @param mbox mbox to posts the message - * @param msg message to post (ATTENTION: can be NULL) - */ -void sys_mbox_post(sys_mbox_t *mbox, void *msg) -{ - RT_DEBUG_NOT_IN_INTERRUPT; - - rt_mb_send_wait(*mbox, (rt_ubase_t)msg, RT_WAITING_FOREVER); - - return; -} - -/* - * Try to post the "msg" to the mailbox - * - * @return return ERR_OK if the "msg" is posted, ERR_MEM if the mailbox is full - */ -err_t sys_mbox_trypost(sys_mbox_t *mbox, void *msg) -{ - if (rt_mb_send(*mbox, (rt_ubase_t)msg) == RT_EOK) - return ERR_OK; - - return ERR_MEM; -} - -/** Wait for a new message to arrive in the mbox - * @param mbox mbox to get a message from - * @param msg pointer where the message is stored - * @param timeout maximum time (in milliseconds) to wait for a message - * @return time (in milliseconds) waited for a message, may be 0 if not waited - or SYS_ARCH_TIMEOUT on timeout - * The returned time has to be accurate to prevent timer jitter! - */ -u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout) -{ - rt_err_t ret; - s32_t t; - u32_t tick; - - RT_DEBUG_NOT_IN_INTERRUPT; - - /* get the begin tick */ - tick = rt_tick_get(); - - if(timeout == 0) - t = RT_WAITING_FOREVER; - else - { - /* convirt msecond to os tick */ - if (timeout < (1000/RT_TICK_PER_SECOND)) - t = 1; - else - t = timeout / (1000/RT_TICK_PER_SECOND); - } - - ret = rt_mb_recv(*mbox, (rt_ubase_t *)msg, t); - if(ret != RT_EOK) - { - return SYS_ARCH_TIMEOUT; - } - - /* get elapse msecond */ - tick = rt_tick_get() - tick; - - /* convert tick to msecond */ - tick = tick * (1000 / RT_TICK_PER_SECOND); - if (tick == 0) - tick = 1; - - return tick; -} - -/** - * @ingroup sys_mbox - * This is similar to sys_arch_mbox_fetch, however if a message is not - * present in the mailbox, it immediately returns with the code - * SYS_MBOX_EMPTY. On success 0 is returned. - * To allow for efficient implementations, this can be defined as a - * function-like macro in sys_arch.h instead of a normal function. For - * example, a naive implementation could be: - * \#define sys_arch_mbox_tryfetch(mbox,msg) sys_arch_mbox_fetch(mbox,msg,1) - * although this would introduce unnecessary delays. - * - * @param mbox mbox to get a message from - * @param msg pointer where the message is stored - * @return 0 (milliseconds) if a message has been received - * or SYS_MBOX_EMPTY if the mailbox is empty - */ -u32_t sys_arch_mbox_tryfetch(sys_mbox_t *mbox, void **msg) -{ - int ret; - - ret = rt_mb_recv(*mbox, (rt_ubase_t *)msg, 0); - if(ret == -RT_ETIMEOUT) - { - return SYS_ARCH_TIMEOUT; - } - else - { - if (ret == RT_EOK) - ret = 0; - } - - return ret; -} - -#ifndef sys_mbox_valid -/** Check if an mbox is valid/allocated: - * return 1 for valid, 0 for invalid - */ -int sys_mbox_valid(sys_mbox_t *mbox) -{ - return (int)(*mbox); -} -#endif - -#ifndef sys_mbox_set_invalid -/** Set an mbox invalid so that sys_mbox_valid returns 0 - */ -void sys_mbox_set_invalid(sys_mbox_t *mbox) -{ - *mbox = RT_NULL; -} -#endif - -/* ====================== System ====================== */ - -/* - * Start a new thread named "name" 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 - */ -sys_thread_t sys_thread_new(const char *name, - lwip_thread_fn thread, - void *arg, - int stacksize, - int prio) -{ - rt_thread_t t; - - RT_DEBUG_NOT_IN_INTERRUPT; - - /* create thread */ - t = rt_thread_create(name, thread, arg, stacksize, prio, 20); - RT_ASSERT(t != RT_NULL); - - /* startup thread */ - rt_thread_startup(t); - - return t; -} - -sys_prot_t sys_arch_protect(void) -{ - rt_base_t level; - - /* disable interrupt */ - level = rt_hw_interrupt_disable(); - - return level; -} - -void sys_arch_unprotect(sys_prot_t pval) -{ - /* enable interrupt */ - rt_hw_interrupt_enable(pval); - - return; -} - -void sys_arch_assert(const char *file, int line) -{ - rt_kprintf("\nAssertion: %d in %s, thread %s\n", - line, file, rt_thread_self()->name); - RT_ASSERT(0); -} - -u32_t sys_jiffies(void) -{ - return rt_tick_get(); -} - -u32_t sys_now(void) -{ - return rt_tick_get_millisecond(); -} - -#ifdef RT_LWIP_PPP -u32_t sio_read(sio_fd_t fd, u8_t *buf, u32_t size) -{ - u32_t len; - - RT_ASSERT(fd != RT_NULL); - - len = rt_device_read((rt_device_t)fd, 0, buf, size); - if (len <= 0) - return 0; - - return len; -} - -u32_t sio_write(sio_fd_t fd, u8_t *buf, u32_t size) -{ - RT_ASSERT(fd != RT_NULL); - - return rt_device_write((rt_device_t)fd, 0, buf, size); -} - -void sio_read_abort(sio_fd_t fd) -{ - rt_kprintf("read_abort\n"); -} - -void ppp_trace(int level, const char *format, ...) -{ - va_list args; - rt_size_t length; - static char rt_log_buf[RT_CONSOLEBUF_SIZE]; - - va_start(args, format); - length = rt_vsprintf(rt_log_buf, format, args); - rt_device_write((rt_device_t)rt_console_get_device(), 0, rt_log_buf, length); - va_end(args); -} -#endif - -/* - * export bsd socket symbol for RT-Thread Application Module - */ -#if LWIP_SOCKET -#include -RTM_EXPORT(lwip_accept); -RTM_EXPORT(lwip_bind); -RTM_EXPORT(lwip_shutdown); -RTM_EXPORT(lwip_getpeername); -RTM_EXPORT(lwip_getsockname); -RTM_EXPORT(lwip_getsockopt); -RTM_EXPORT(lwip_setsockopt); -RTM_EXPORT(lwip_close); -RTM_EXPORT(lwip_connect); -RTM_EXPORT(lwip_listen); -RTM_EXPORT(lwip_recv); -RTM_EXPORT(lwip_read); -RTM_EXPORT(lwip_recvfrom); -RTM_EXPORT(lwip_send); -RTM_EXPORT(lwip_sendto); -RTM_EXPORT(lwip_socket); -RTM_EXPORT(lwip_write); -RTM_EXPORT(lwip_select); -RTM_EXPORT(lwip_ioctl); -RTM_EXPORT(lwip_fcntl); - -RTM_EXPORT(lwip_htons); -RTM_EXPORT(lwip_ntohs); -RTM_EXPORT(lwip_htonl); -RTM_EXPORT(lwip_ntohl); - -RTM_EXPORT(ipaddr_aton); -RTM_EXPORT(ipaddr_ntoa); - -#if LWIP_DNS -#include -RTM_EXPORT(lwip_gethostbyname); -RTM_EXPORT(lwip_gethostbyname_r); -RTM_EXPORT(lwip_freeaddrinfo); -RTM_EXPORT(lwip_getaddrinfo); -#endif - -#endif - -#if LWIP_DHCP -#include -RTM_EXPORT(dhcp_start); -RTM_EXPORT(dhcp_renew); -RTM_EXPORT(dhcp_stop); -#endif - -#if LWIP_NETIF_API -#include -RTM_EXPORT(netifapi_netif_set_addr); -#endif - -#if LWIP_NETIF_LINK_CALLBACK -RTM_EXPORT(netif_set_link_callback); -#endif - -#if LWIP_NETIF_STATUS_CALLBACK -RTM_EXPORT(netif_set_status_callback); -#endif - -RTM_EXPORT(netif_find); -RTM_EXPORT(netif_set_addr); -RTM_EXPORT(netif_set_ipaddr); -RTM_EXPORT(netif_set_gw); -RTM_EXPORT(netif_set_netmask); diff --git a/components/net/lwip/lwip-1.4.1/src/include/netif/ethernetif.h b/components/net/lwip/lwip-1.4.1/src/include/netif/ethernetif.h deleted file mode 100644 index 650ad32eff..0000000000 --- a/components/net/lwip/lwip-1.4.1/src/include/netif/ethernetif.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef __NETIF_ETHERNETIF_H__ -#define __NETIF_ETHERNETIF_H__ - -#include "lwip/netif.h" -#include - -#define NIOCTL_GADDR 0x01 -#ifndef RT_LWIP_ETH_MTU -#define ETHERNET_MTU 1500 -#else -#define ETHERNET_MTU RT_LWIP_ETH_MTU -#endif - -/* eth flag with auto_linkup or phy_linkup */ -#define ETHIF_LINK_AUTOUP 0x0000 -#define ETHIF_LINK_PHYUP 0x0100 - -struct eth_device -{ - /* inherit from rt_device */ - struct rt_device parent; - - /* network interface for lwip */ - struct netif *netif; - struct rt_semaphore tx_ack; - - rt_uint16_t flags; - rt_uint8_t link_changed; - rt_uint8_t link_status; - rt_uint8_t rx_notice; - - /* eth device interface */ - struct pbuf* (*eth_rx)(rt_device_t dev); - rt_err_t (*eth_tx)(rt_device_t dev, struct pbuf* p); -}; - -#ifdef __cplusplus -extern "C" { -#endif - - rt_err_t eth_device_ready(struct eth_device* dev); - rt_err_t eth_device_init(struct eth_device * dev, const char *name); - rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_uint16_t flag); - rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up); - - int eth_system_device_init(void); - -#ifdef __cplusplus -} -#endif - -#endif /* __NETIF_ETHERNETIF_H__ */ diff --git a/components/net/lwip/lwip-1.4.1/src/netif/ethernetif.c b/components/net/lwip/lwip-1.4.1/src/netif/ethernetif.c deleted file mode 100644 index 6bb9eec19f..0000000000 --- a/components/net/lwip/lwip-1.4.1/src/netif/ethernetif.c +++ /dev/null @@ -1,945 +0,0 @@ -/* - * Copyright (c) 2001-2004 Swedish Institute of Computer Science. - * COPYRIGHT (C) 2006-2010, RT-Thread Development Team - * 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 - * - * Change Logs: - * Date Author Notes - * 2010-07-07 Bernard fix send mail to mailbox issue. - * 2011-07-30 mbbill port lwIP 1.4.0 to RT-Thread - * 2012-04-10 Bernard add more compatible with RT-Thread. - * 2012-11-12 Bernard The network interface can be initialized - * after lwIP initialization. - * 2013-02-28 aozima fixed list_tcps bug: ipaddr_ntoa isn't reentrant. - */ - -#include - -#include "lwip/opt.h" -#include "lwip/debug.h" -#include "lwip/def.h" -#include "lwip/mem.h" -#include "lwip/pbuf.h" -#include "lwip/sys.h" -#include "lwip/netif.h" -#include "lwip/stats.h" -#include "lwip/tcpip.h" - -#include "netif/etharp.h" -#include "netif/ethernetif.h" -#include "lwip/inet.h" - -#define netifapi_netif_set_link_up(n) netifapi_netif_common(n, netif_set_link_up, NULL) -#define netifapi_netif_set_link_down(n) netifapi_netif_common(n, netif_set_link_down, NULL) - -#ifndef RT_LWIP_ETHTHREAD_PRIORITY -#define RT_ETHERNETIF_THREAD_PREORITY 0x90 -#else -#define RT_ETHERNETIF_THREAD_PREORITY RT_LWIP_ETHTHREAD_PRIORITY -#endif - -#ifndef LWIP_NO_TX_THREAD -/** - * Tx message structure for Ethernet interface - */ -struct eth_tx_msg -{ - struct netif *netif; - struct pbuf *buf; -}; - -static struct rt_mailbox eth_tx_thread_mb; -static struct rt_thread eth_tx_thread; -#ifndef RT_LWIP_ETHTHREAD_MBOX_SIZE -static char eth_tx_thread_mb_pool[32 * 4]; -static char eth_tx_thread_stack[512]; -#else -static char eth_tx_thread_mb_pool[RT_LWIP_ETHTHREAD_MBOX_SIZE * 4]; -static char eth_tx_thread_stack[RT_LWIP_ETHTHREAD_STACKSIZE]; -#endif -#endif - -#ifndef LWIP_NO_RX_THREAD -static struct rt_mailbox eth_rx_thread_mb; -static struct rt_thread eth_rx_thread; -#ifndef RT_LWIP_ETHTHREAD_MBOX_SIZE -static char eth_rx_thread_mb_pool[48 * 4]; -static char eth_rx_thread_stack[1024]; -#else -static char eth_rx_thread_mb_pool[RT_LWIP_ETHTHREAD_MBOX_SIZE * 4]; -static char eth_rx_thread_stack[RT_LWIP_ETHTHREAD_STACKSIZE]; -#endif -#endif - -#ifdef RT_USING_NETDEV - -#include "lwip/ip.h" -#include "lwip/init.h" -#include "lwip/netdb.h" -#include - -static int lwip_netdev_set_up(struct netdev *netif) -{ - netif_set_up((struct netif *)netif->user_data); - return ERR_OK; -} - -static int lwip_netdev_set_down(struct netdev *netif) -{ - netif_set_down((struct netif *)netif->user_data); - return ERR_OK; -} - -static int lwip_netdev_set_addr_info(struct netdev *netif, ip_addr_t *ip_addr, ip_addr_t *netmask, ip_addr_t *gw) -{ - if (ip_addr && netmask && gw) - { - netif_set_addr((struct netif *)netif->user_data, ip_addr, netmask, gw); - } - else - { - if (ip_addr) - { - netif_set_ipaddr((struct netif *)netif->user_data, ip_addr); - } - - if (netmask) - { - netif_set_netmask((struct netif *)netif->user_data, netmask); - } - - if (gw) - { - netif_set_gw((struct netif *)netif->user_data, gw); - } - } - - return ERR_OK; -} - -#ifdef RT_LWIP_DNS -static int lwip_netdev_set_dns_server(struct netdev *netif, uint8_t dns_num, ip_addr_t *dns_server) -{ - extern void dns_setserver(uint8_t dns_num, ip_addr_t *dns_server); - dns_setserver(dns_num, dns_server); - return ERR_OK; -} -#endif /* RT_LWIP_DNS */ - -#ifdef RT_LWIP_DHCP -static int lwip_netdev_set_dhcp(struct netdev *netif, rt_bool_t is_enabled) -{ - netdev_low_level_set_dhcp_status(netif, is_enabled); - - if(RT_TRUE == is_enabled) - { - dhcp_start((struct netif *)netif->user_data); - } - else - { - dhcp_stop((struct netif *)netif->user_data); - } - - return ERR_OK; -} -#endif /* RT_LWIP_DHCP */ - -#ifdef RT_USING_FINSH -#ifdef RT_LWIP_USING_PING -extern int lwip_ping_recv(int s, int *ttl); -extern err_t lwip_ping_send(int s, ip_addr_t *addr, int size); - -int lwip_netdev_ping(struct netdev *netif, const char *host, size_t data_len, - uint32_t timeout, struct netdev_ping_resp *ping_resp) -{ - int s, ttl, recv_len, result = 0; - int elapsed_time; - rt_tick_t recv_start_tick; -#if LWIP_VERSION_MAJOR >= 2U - struct timeval recv_timeout = { timeout / RT_TICK_PER_SECOND, timeout % RT_TICK_PER_SECOND }; -#else - int recv_timeout = timeout * 1000UL / RT_TICK_PER_SECOND; -#endif - ip_addr_t target_addr; - struct addrinfo hint, *res = RT_NULL; - struct sockaddr_in *h = RT_NULL; - struct in_addr ina; - - RT_ASSERT(netif); - RT_ASSERT(host); - RT_ASSERT(ping_resp); - - rt_memset(&hint, 0x00, sizeof(hint)); - /* convert URL to IP */ - if (lwip_getaddrinfo(host, RT_NULL, &hint, &res) != 0) - { - return -RT_ERROR; - } - SMEMCPY(&h, &res->ai_addr, sizeof(struct sockaddr_in *)); - SMEMCPY(&ina, &h->sin_addr, sizeof(ina)); - lwip_freeaddrinfo(res); - if (inet_aton(inet_ntoa(ina), &target_addr) == 0) - { - return -RT_ERROR; - } - SMEMCPY(&(ping_resp->ip_addr), &target_addr, sizeof(ip_addr_t)); - - /* new a socket */ - if ((s = lwip_socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP)) < 0) - { - return -RT_ERROR; - } - - lwip_setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &recv_timeout, sizeof(recv_timeout)); - - if (lwip_ping_send(s, &target_addr, data_len) == ERR_OK) - { - recv_start_tick = rt_tick_get(); - if ((recv_len = lwip_ping_recv(s, &ttl)) >= 0) - { - elapsed_time = (rt_tick_get() - recv_start_tick) * 1000UL / RT_TICK_PER_SECOND; - ping_resp->data_len = recv_len; - ping_resp->ttl = ttl; - ping_resp->ticks = elapsed_time; - } - else - { - result = -RT_ETIMEOUT; - goto __exit; - } - } - else - { - result = -RT_ETIMEOUT; - goto __exit; - } - -__exit: - lwip_close(s); - - return result; -} -#endif /* RT_LWIP_USING_PING */ - -#if defined (RT_LWIP_TCP) || defined (RT_LWIP_UDP) -void lwip_netdev_netstat(struct netdev *netif) -{ - extern void list_tcps(void); - extern void list_udps(void); - -#ifdef RT_LWIP_TCP - list_tcps(); -#endif -#ifdef RT_LWIP_UDP - list_udps(); -#endif -} -#endif /* RT_LWIP_TCP || RT_LWIP_UDP */ -#endif /* RT_USING_FINSH */ - -static int lwip_netdev_set_default(struct netdev *netif) -{ - netif_set_default((struct netif *)netif->user_data); - return ERR_OK; -} - -const struct netdev_ops lwip_netdev_ops = -{ - lwip_netdev_set_up, - lwip_netdev_set_down, - - lwip_netdev_set_addr_info, -#ifdef RT_LWIP_DNS - lwip_netdev_set_dns_server, -#else - NULL, -#endif /* RT_LWIP_DNS */ - -#ifdef RT_LWIP_DHCP - lwip_netdev_set_dhcp, -#else - NULL, -#endif /* RT_LWIP_DHCP */ - -#ifdef RT_USING_FINSH -#ifdef RT_LWIP_USING_PING - lwip_netdev_ping, -#else - NULL, -#endif /* RT_LWIP_USING_PING */ - -#if defined (RT_LWIP_TCP) || defined (RT_LWIP_UDP) - lwip_netdev_netstat, -#endif /* RT_LWIP_TCP || RT_LWIP_UDP */ -#endif /* RT_USING_FINSH */ - - lwip_netdev_set_default, -}; - -static int netdev_add(struct netif *lwip_netif) -{ -#define LWIP_NETIF_NAME_LEN 2 - int result = 0; - struct netdev *netdev = RT_NULL; - char name[LWIP_NETIF_NAME_LEN + 1] = {0}; - - RT_ASSERT(lwip_netif); - - netdev = (struct netdev *)rt_calloc(1, sizeof(struct netdev)); - if (netdev == RT_NULL) - { - return -ERR_IF; - } - -#ifdef SAL_USING_LWIP - extern int sal_lwip_netdev_set_pf_info(struct netdev *netdev); - /* set the lwIP network interface device protocol family information */ - sal_lwip_netdev_set_pf_info(netdev); -#endif /* SAL_USING_LWIP */ - - rt_strncpy(name, lwip_netif->name, LWIP_NETIF_NAME_LEN); - result = netdev_register(netdev, name, (void *)lwip_netif); - - /* Update netdev info after registered */ - netdev->flags = lwip_netif->flags; - netdev->mtu = lwip_netif->mtu; - netdev->ops = &lwip_netdev_ops; - netdev->hwaddr_len = lwip_netif->hwaddr_len; - SMEMCPY(netdev->hwaddr, lwip_netif->hwaddr, lwip_netif->hwaddr_len); - netdev->ip_addr = lwip_netif->ip_addr; - netdev->gw = lwip_netif->gw; - netdev->netmask = lwip_netif->netmask; - -#ifdef RT_LWIP_DHCP - netdev_low_level_set_dhcp_status(netdev, RT_TRUE); -#endif - - return result; -} - -/* synchronize lwIP network interface device and network interface device flags */ -static int netdev_flags_sync(struct netif *lwip_netif) -{ - struct netdev *netdev = NULL; - - RT_ASSERT(lwip_netif); - - netdev = netdev_get_by_name(lwip_netif->name); - if (netdev == RT_NULL) - { - return -ERR_IF; - } - - netdev->flags |= lwip_netif->flags; - - return ERR_OK; -} -#endif /* RT_USING_NETDEV */ - -static err_t ethernetif_linkoutput(struct netif *netif, struct pbuf *p) -{ -#ifndef LWIP_NO_TX_THREAD - struct eth_tx_msg msg; - struct eth_device* enetif; - - RT_ASSERT(netif != RT_NULL); - enetif = (struct eth_device*)netif->state; - - /* send a message to eth tx thread */ - msg.netif = netif; - msg.buf = p; - if (rt_mb_send(ð_tx_thread_mb, (rt_ubase_t) &msg) == RT_EOK) - { - /* waiting for ack */ - rt_sem_take(&(enetif->tx_ack), RT_WAITING_FOREVER); - } -#else - struct eth_device* enetif; - - RT_ASSERT(netif != RT_NULL); - enetif = (struct eth_device*)netif->state; - - if (enetif->eth_tx(&(enetif->parent), p) != RT_EOK) - { - return ERR_IF; - } -#endif - return ERR_OK; -} - -static err_t eth_netif_device_init(struct netif *netif) -{ - struct eth_device *ethif; - - ethif = (struct eth_device*)netif->state; - if (ethif != RT_NULL) - { - rt_device_t device; - -#ifdef RT_USING_NETDEV - /* network interface device register */ - netdev_add(netif); -#endif /* RT_USING_NETDEV */ - - /* get device object */ - device = (rt_device_t) ethif; - if (rt_device_init(device) != RT_EOK) - { - return ERR_IF; - } - - /* copy device flags to netif flags */ - netif->flags = (ethif->flags & 0xff); - - /* set default netif */ - if (netif_default == RT_NULL) - netif_set_default(ethif->netif); - -#if LWIP_DHCP - if (ethif->flags & NETIF_FLAG_DHCP) - { - /* if this interface uses DHCP, start the DHCP client */ - dhcp_start(ethif->netif); - } - else -#endif - { - /* set interface up */ - netif_set_up(ethif->netif); - } - - if (!(ethif->flags & ETHIF_LINK_PHYUP)) - { - /* set link_up for this netif */ - netif_set_link_up(ethif->netif); - } - - return ERR_OK; - } - - return ERR_IF; -} - -/* Keep old drivers compatible in RT-Thread */ -rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_uint16_t flags) -{ - struct netif* netif; -#if LWIP_NETIF_HOSTNAME -#define LWIP_HOSTNAME_LEN 16 - char *hostname = RT_NULL; - netif = (struct netif*) rt_calloc (1, sizeof(struct netif) + LWIP_HOSTNAME_LEN); -#else - netif = (struct netif*) rt_calloc (1, sizeof(struct netif)); -#endif - if (netif == RT_NULL) - { - rt_kprintf("malloc netif failed\n"); - return -RT_ERROR; - } - - /* set netif */ - dev->netif = netif; - /* device flags, which will be set to netif flags when initializing */ - dev->flags = flags; - /* link changed status of device */ - dev->link_changed = 0x00; - /* avoid send the same mail to mailbox */ - dev->rx_notice = 0x00; - dev->parent.type = RT_Device_Class_NetIf; - /* register to RT-Thread device manager */ - rt_device_register(&(dev->parent), name, RT_DEVICE_FLAG_RDWR); - rt_sem_init(&(dev->tx_ack), name, 0, RT_IPC_FLAG_FIFO); - - /* set name */ - netif->name[0] = name[0]; - netif->name[1] = name[1]; - - /* set hw address to 6 */ - netif->hwaddr_len = 6; - /* maximum transfer unit */ - netif->mtu = ETHERNET_MTU; - - /* get hardware MAC address */ - rt_device_control(&(dev->parent), NIOCTL_GADDR, netif->hwaddr); - - /* set output */ - netif->output = etharp_output; - netif->linkoutput = ethernetif_linkoutput; - -#if LWIP_NETIF_HOSTNAME - /* Initialize interface hostname */ - hostname = (char *)netif + sizeof(struct netif); - rt_sprintf(hostname, "rtthread_%02x%02x", name[0], name[1]); - netif->hostname = hostname; -#endif /* LWIP_NETIF_HOSTNAME */ - - /* if tcp thread has been started up, we add this netif to the system */ - if (rt_thread_find("tcpip") != RT_NULL) - { - struct ip_addr ipaddr, netmask, gw; - - #if LWIP_DHCP - if (dev->flags & NETIF_FLAG_DHCP) - { - IP4_ADDR(&ipaddr, 0, 0, 0, 0); - IP4_ADDR(&gw, 0, 0, 0, 0); - IP4_ADDR(&netmask, 0, 0, 0, 0); - } - else - #endif - { - ipaddr.addr = inet_addr(RT_LWIP_IPADDR); - gw.addr = inet_addr(RT_LWIP_GWADDR); - netmask.addr = inet_addr(RT_LWIP_MSKADDR); - } - - netifapi_netif_add(netif, &ipaddr, &netmask, &gw, dev, eth_netif_device_init, tcpip_input); - } - -#ifdef RT_USING_NETDEV - /* network interface device flags synchronize */ - netdev_flags_sync(netif); -#endif /* RT_USING_NETDEV */ - - - return RT_EOK; -} - -rt_err_t eth_device_init(struct eth_device * dev, const char *name) -{ - rt_uint16_t flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP; - -#if LWIP_DHCP - /* DHCP support */ - flags |= NETIF_FLAG_DHCP; -#endif - -#if LWIP_IGMP - /* IGMP support */ - flags |= NETIF_FLAG_IGMP; -#endif - - return eth_device_init_with_flag(dev, name, flags); -} - -#ifndef LWIP_NO_RX_THREAD -rt_err_t eth_device_ready(struct eth_device* dev) -{ - if (dev->netif) - { - if(dev->rx_notice == RT_FALSE) - { - dev->rx_notice = RT_TRUE; - return rt_mb_send(ð_rx_thread_mb, (rt_ubase_t)dev); - } - else - return RT_EOK; - /* post message to Ethernet thread */ - } - else - return -RT_ERROR; /* netif is not initialized yet, just return. */ -} - -rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up) -{ - rt_uint32_t level; - - RT_ASSERT(dev != RT_NULL); - - level = rt_hw_interrupt_disable(); - dev->link_changed = 0x01; - if (up == RT_TRUE) - dev->link_status = 0x01; - else - dev->link_status = 0x00; - rt_hw_interrupt_enable(level); - - /* post message to ethernet thread */ - return rt_mb_send(ð_rx_thread_mb, (rt_ubase_t)dev); -} -#else -/* NOTE: please not use it in interrupt when no RxThread exist */ -rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up) -{ - if (up == RT_TRUE) - netifapi_netif_set_link_up(dev->netif); - else - netifapi_netif_set_link_down(dev->netif); - - return RT_EOK; -} -#endif - -#ifndef LWIP_NO_TX_THREAD -/* Ethernet Tx Thread */ -static void eth_tx_thread_entry(void* parameter) -{ - struct eth_tx_msg* msg; - - while (1) - { - if (rt_mb_recv(ð_tx_thread_mb, (rt_ubase_t*)&msg, RT_WAITING_FOREVER) == RT_EOK) - { - struct eth_device* enetif; - - RT_ASSERT(msg->netif != RT_NULL); - RT_ASSERT(msg->buf != RT_NULL); - - enetif = (struct eth_device*)msg->netif->state; - if (enetif != RT_NULL) - { - /* call driver's interface */ - if (enetif->eth_tx(&(enetif->parent), msg->buf) != RT_EOK) - { - /* transmit eth packet failed */ - } - } - - /* send ACK */ - rt_sem_release(&(enetif->tx_ack)); - } - } -} -#endif - -#ifndef LWIP_NO_RX_THREAD -/* Ethernet Rx Thread */ -static void eth_rx_thread_entry(void* parameter) -{ - struct eth_device* device; - - while (1) - { - if (rt_mb_recv(ð_rx_thread_mb, (rt_ubase_t*)&device, RT_WAITING_FOREVER) == RT_EOK) - { - rt_base_t level; - struct pbuf *p; - - /* check link status */ - if (device->link_changed) - { - int status; - rt_uint32_t level; - - level = rt_hw_interrupt_disable(); - status = device->link_status; - device->link_changed = 0x00; - rt_hw_interrupt_enable(level); - - if (status) - netifapi_netif_set_link_up(device->netif); - else - netifapi_netif_set_link_down(device->netif); - } - - level = rt_hw_interrupt_disable(); - /* 'rx_notice' will be modify in the interrupt or here */ - device->rx_notice = RT_FALSE; - rt_hw_interrupt_enable(level); - - /* receive all of buffer */ - while(1) - { - if(device->eth_rx == RT_NULL) break; - - p = device->eth_rx(&(device->parent)); - if (p != RT_NULL) - { - /* notify to upper layer */ - if( device->netif->input(p, device->netif) != ERR_OK ) - { - LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: Input error\n")); - pbuf_free(p); - p = NULL; - } - } - else break; - } - } - else - { - LWIP_ASSERT("Should not happen!\n",0); - } - } -} -#endif - -int eth_system_device_init(void) -{ - rt_err_t result = RT_EOK; - - /* initialize Rx thread. */ -#ifndef LWIP_NO_RX_THREAD - /* initialize mailbox and create Ethernet Rx thread */ - result = rt_mb_init(ð_rx_thread_mb, "erxmb", - ð_rx_thread_mb_pool[0], sizeof(eth_rx_thread_mb_pool)/4, - RT_IPC_FLAG_FIFO); - RT_ASSERT(result == RT_EOK); - - result = rt_thread_init(ð_rx_thread, "erx", eth_rx_thread_entry, RT_NULL, - ð_rx_thread_stack[0], sizeof(eth_rx_thread_stack), - RT_ETHERNETIF_THREAD_PREORITY, 16); - RT_ASSERT(result == RT_EOK); - result = rt_thread_startup(ð_rx_thread); - RT_ASSERT(result == RT_EOK); -#endif - - /* initialize Tx thread */ -#ifndef LWIP_NO_TX_THREAD - /* initialize mailbox and create Ethernet Tx thread */ - result = rt_mb_init(ð_tx_thread_mb, "etxmb", - ð_tx_thread_mb_pool[0], sizeof(eth_tx_thread_mb_pool)/4, - RT_IPC_FLAG_FIFO); - RT_ASSERT(result == RT_EOK); - - result = rt_thread_init(ð_tx_thread, "etx", eth_tx_thread_entry, RT_NULL, - ð_tx_thread_stack[0], sizeof(eth_tx_thread_stack), - RT_ETHERNETIF_THREAD_PREORITY, 16); - RT_ASSERT(result == RT_EOK); - - result = rt_thread_startup(ð_tx_thread); - RT_ASSERT(result == RT_EOK); -#endif - - return (int)result; -} -INIT_PREV_EXPORT(eth_system_device_init); - -void set_if(char* netif_name, char* ip_addr, char* gw_addr, char* nm_addr) -{ - struct ip_addr *ip; - struct ip_addr addr; - struct netif * netif = netif_list; - - if(strlen(netif_name) > sizeof(netif->name)) - { - rt_kprintf("network interface name too long!\r\n"); - return; - } - - while(netif != RT_NULL) - { - if(strncmp(netif_name, netif->name, sizeof(netif->name)) == 0) - break; - - netif = netif->next; - if( netif == RT_NULL ) - { - rt_kprintf("network interface: %s not found!\r\n", netif_name); - return; - } - } - - ip = (struct ip_addr *)&addr; - - /* set ip address */ - if ((ip_addr != RT_NULL) && ipaddr_aton(ip_addr, &addr)) - { - netif_set_ipaddr(netif, ip); - } - - /* set gateway address */ - if ((gw_addr != RT_NULL) && ipaddr_aton(gw_addr, &addr)) - { - netif_set_gw(netif, ip); - } - - /* set netmask address */ - if ((nm_addr != RT_NULL) && ipaddr_aton(nm_addr, &addr)) - { - netif_set_netmask(netif, ip); - } -} - -#ifdef RT_USING_FINSH -#include -FINSH_FUNCTION_EXPORT(set_if, set network interface address); - -#if LWIP_DNS -#include -void set_dns(uint8_t dns_num, char* dns_server) -{ - struct ip_addr addr; - - if ((dns_server != RT_NULL) && ipaddr_aton(dns_server, &addr)) - { - dns_setserver(dns_num, &addr); - } -} -FINSH_FUNCTION_EXPORT(set_dns, set DNS server address); -#endif - -void list_if(void) -{ - rt_ubase_t index; - struct netif * netif; - - rt_enter_critical(); - - netif = netif_list; - - while( netif != RT_NULL ) - { - rt_kprintf("network interface: %c%c%s\n", - netif->name[0], - netif->name[1], - (netif == netif_default)?" (Default)":""); - rt_kprintf("MTU: %d\n", netif->mtu); - rt_kprintf("MAC: "); - for (index = 0; index < netif->hwaddr_len; index ++) - rt_kprintf("%02x ", netif->hwaddr[index]); - rt_kprintf("\nFLAGS:"); - if (netif->flags & NETIF_FLAG_UP) rt_kprintf(" UP"); - else rt_kprintf(" DOWN"); - if (netif->flags & NETIF_FLAG_LINK_UP) rt_kprintf(" LINK_UP"); - else rt_kprintf(" LINK_DOWN"); - if (netif->flags & NETIF_FLAG_DHCP) rt_kprintf(" DHCP"); - if (netif->flags & NETIF_FLAG_POINTTOPOINT) rt_kprintf(" PPP"); - if (netif->flags & NETIF_FLAG_ETHARP) rt_kprintf(" ETHARP"); - if (netif->flags & NETIF_FLAG_IGMP) rt_kprintf(" IGMP"); - rt_kprintf("\n"); - rt_kprintf("ip address: %s\n", ipaddr_ntoa(&(netif->ip_addr))); - rt_kprintf("gw address: %s\n", ipaddr_ntoa(&(netif->gw))); - rt_kprintf("net mask : %s\n", ipaddr_ntoa(&(netif->netmask))); - rt_kprintf("\r\n"); - - netif = netif->next; - } - -#if LWIP_DNS - { - struct ip_addr ip_addr; - - for(index=0; index -#include - -void list_tcps(void) -{ - rt_uint32_t num = 0; - struct tcp_pcb *pcb; - char local_ip_str[16]; - char remote_ip_str[16]; - - extern struct tcp_pcb *tcp_active_pcbs; - extern union tcp_listen_pcbs_t tcp_listen_pcbs; - extern struct tcp_pcb *tcp_tw_pcbs; - extern const char *tcp_state_str[]; - - rt_enter_critical(); - rt_kprintf("Active PCB states:\n"); - for(pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) - { - strcpy(local_ip_str, ipaddr_ntoa(&(pcb->local_ip))); - strcpy(remote_ip_str, ipaddr_ntoa(&(pcb->remote_ip))); - - rt_kprintf("#%d %s:%d <==> %s:%d snd_nxt 0x%08X rcv_nxt 0x%08X ", - num++, - local_ip_str, - pcb->local_port, - remote_ip_str, - pcb->remote_port, - pcb->snd_nxt, - pcb->rcv_nxt); - rt_kprintf("state: %s\n", tcp_state_str[pcb->state]); - } - - rt_kprintf("Listen PCB states:\n"); - num = 0; - for(pcb = (struct tcp_pcb *)tcp_listen_pcbs.pcbs; pcb != NULL; pcb = pcb->next) - { - rt_kprintf("#%d local port %d ", num++, pcb->local_port); - rt_kprintf("state: %s\n", tcp_state_str[pcb->state]); - } - - rt_kprintf("TIME-WAIT PCB states:\n"); - num = 0; - for(pcb = tcp_tw_pcbs; pcb != NULL; pcb = pcb->next) - { - strcpy(local_ip_str, ipaddr_ntoa(&(pcb->local_ip))); - strcpy(remote_ip_str, ipaddr_ntoa(&(pcb->remote_ip))); - - rt_kprintf("#%d %s:%d <==> %s:%d snd_nxt 0x%08X rcv_nxt 0x%08X ", - num++, - local_ip_str, - pcb->local_port, - remote_ip_str, - pcb->remote_port, - pcb->snd_nxt, - pcb->rcv_nxt); - rt_kprintf("state: %s\n", tcp_state_str[pcb->state]); - } - rt_exit_critical(); -} -FINSH_FUNCTION_EXPORT(list_tcps, list all of tcp connections); -#endif - -#if LWIP_UDP -#include "lwip/udp.h" -void list_udps(void) -{ - struct udp_pcb *pcb; - rt_uint32_t num = 0; - char local_ip_str[16]; - char remote_ip_str[16]; - - rt_enter_critical(); - rt_kprintf("Active UDP PCB states:\n"); - for (pcb = udp_pcbs; pcb != NULL; pcb = pcb->next) - { - strcpy(local_ip_str, ipaddr_ntoa(&(pcb->local_ip))); - strcpy(remote_ip_str, ipaddr_ntoa(&(pcb->remote_ip))); - - rt_kprintf("#%d %d %s:%d <==> %s:%d \n", - num, (int)pcb->flags, - local_ip_str, - pcb->local_port, - remote_ip_str, - pcb->remote_port); - - num++; - } - rt_exit_critical(); -} -FINSH_FUNCTION_EXPORT(list_udps, list all of udp connections); -#endif /* LWIP_UDP */ - -#endif diff --git a/components/net/lwip/lwip-2.0.3/SConscript b/components/net/lwip/lwip-2.0.3/SConscript index 36d8e92dc6..9f99cd6f1a 100644 --- a/components/net/lwip/lwip-2.0.3/SConscript +++ b/components/net/lwip/lwip-2.0.3/SConscript @@ -1,7 +1,6 @@ from building import * src = Split(""" -src/arch/sys_arch.c src/api/api_lib.c src/api/api_msg.c src/api/err.c @@ -27,7 +26,6 @@ src/core/tcp_out.c src/core/timeouts.c src/core/udp.c src/netif/ethernet.c -src/netif/ethernetif.c src/netif/lowpan6.c """) @@ -64,7 +62,6 @@ src = src + ipv4_src path = [GetCurrentDir() + '/src', GetCurrentDir() + '/src/include', GetCurrentDir() + '/src/include/ipv4', - GetCurrentDir() + '/src/arch/include', GetCurrentDir() + '/src/include/netif'] if not GetDepend('RT_USING_SAL'): diff --git a/components/net/lwip/lwip-2.0.3/src/arch/include/arch/bpstruct.h b/components/net/lwip/lwip-2.0.3/src/arch/include/arch/bpstruct.h deleted file mode 100644 index 74ead358fa..0000000000 --- a/components/net/lwip/lwip-2.0.3/src/arch/include/arch/bpstruct.h +++ /dev/null @@ -1,35 +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(__ICCARM__) -#pragma pack(1) -#endif diff --git a/components/net/lwip/lwip-2.0.3/src/arch/include/arch/cc.h b/components/net/lwip/lwip-2.0.3/src/arch/include/arch/cc.h deleted file mode 100644 index ad029e8999..0000000000 --- a/components/net/lwip/lwip-2.0.3/src/arch/include/arch/cc.h +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (c) 2001, 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. - * - * This file is part of the lwIP TCP/IP stack. - * - * Author: Adam Dunkels - * - * $Id: cc.h,v 1.1.1.1 2004/12/16 14:17:13 bear Exp $ - */ -#ifndef __ARCH_CC_H__ -#define __ARCH_CC_H__ - -#include -#include -#include - -#ifndef BYTE_ORDER -#ifdef ARCH_CPU_BIG_ENDIAN -#define BYTE_ORDER BIG_ENDIAN -#else -#define BYTE_ORDER LITTLE_ENDIAN -#endif /* ARCH_CPU_BIG_ENDIAN */ -#endif /* BYTE_ORDER */ - -#define U16_F "hu" -#define S16_F "hd" -#define X16_F "hx" -#define U32_F "lu" -#define S32_F "ld" -#define X32_F "lx" - -#include -/* some errno not defined in newlib */ -#ifndef ENSRNOTFOUND -#define ENSRNOTFOUND 163 /* Domain name not found */ -/* WARNING: ESHUTDOWN also not defined in newlib. We chose - 180 here because the number "108" which is used - in arch.h has been assigned to another error code. */ -#endif - -/* LWIP_TIMEVAL_PRIVATE: provided by */ -#include -#define LWIP_TIMEVAL_PRIVATE 0 - -#if defined(__CC_ARM) /* ARMCC compiler */ -#define PACK_STRUCT_FIELD(x) x -#define PACK_STRUCT_STRUCT __attribute__ ((__packed__)) -#define PACK_STRUCT_BEGIN -#define PACK_STRUCT_END -#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) /*Arm Compiler 6*/ -#define PACK_STRUCT_FIELD(x) x -#define PACK_STRUCT_STRUCT __attribute__((packed)) -#define PACK_STRUCT_BEGIN -#define PACK_STRUCT_END -#elif defined(__IAR_SYSTEMS_ICC__) /* IAR Compiler */ -#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(__GNUC__) /* GNU GCC Compiler */ -#define PACK_STRUCT_FIELD(x) x -#define PACK_STRUCT_STRUCT __attribute__((packed)) -#define PACK_STRUCT_BEGIN -#define PACK_STRUCT_END -#elif defined(_MSC_VER) -#define PACK_STRUCT_FIELD(x) x -#define PACK_STRUCT_STRUCT -#define PACK_STRUCT_BEGIN -#define PACK_STRUCT_END -#endif - -void sys_arch_assert(const char* file, int line); -#define LWIP_PLATFORM_DIAG(x) do {rt_kprintf x;} while(0) -#define LWIP_PLATFORM_ASSERT(x) do {rt_kprintf(x); sys_arch_assert(__FILE__, __LINE__);}while(0) - -#define SYS_ARCH_DECL_PROTECT(level) register rt_base_t level -#define SYS_ARCH_PROTECT(level) do {level = rt_hw_interrupt_disable();} while(0) -#define SYS_ARCH_UNPROTECT(level) do {rt_hw_interrupt_enable(level);} while(0) - - -#endif /* __ARCH_CC_H__ */ - diff --git a/components/net/lwip/lwip-2.0.3/src/arch/include/arch/epstruct.h b/components/net/lwip/lwip-2.0.3/src/arch/include/arch/epstruct.h deleted file mode 100644 index f6390959ea..0000000000 --- a/components/net/lwip/lwip-2.0.3/src/arch/include/arch/epstruct.h +++ /dev/null @@ -1,35 +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(__ICCARM__) -#pragma pack() -#endif diff --git a/components/net/lwip/lwip-2.0.3/src/arch/include/arch/perf.h b/components/net/lwip/lwip-2.0.3/src/arch/include/arch/perf.h deleted file mode 100644 index 675f1f65dc..0000000000 --- a/components/net/lwip/lwip-2.0.3/src/arch/include/arch/perf.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2001, 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. - * - * This file is part of the lwIP TCP/IP stack. - * - * Author: Adam Dunkels - * - * $Id: perf.h,v 1.1.1.1 2004/12/16 14:17:13 bear Exp $ - */ -#ifndef __ARCH_PERF_H__ -#define __ARCH_PERF_H__ - -//#include - -#define PERF_START /* null definition */ -#define PERF_STOP(x) /* null definition */ - -/* -void perf_print(unsigned long c1l, unsigned long c1h, - unsigned long c2l, unsigned long c2h, - char *key); - -void perf_print_times(struct tms *start, struct tms *end, char *key); - -void perf_init(char *fname); -*/ -#endif /* __ARCH_PERF_H__ */ diff --git a/components/net/lwip/lwip-2.0.3/src/arch/include/arch/sys_arch.h b/components/net/lwip/lwip-2.0.3/src/arch/include/arch/sys_arch.h deleted file mode 100644 index d065298bff..0000000000 --- a/components/net/lwip/lwip-2.0.3/src/arch/include/arch/sys_arch.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2001, 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. - * - * This file is part of the lwIP TCP/IP stack. - * - * Author: Adam Dunkels - * - * $Id: sys_arch.h,v 1.3 2005/03/13 16:03:23 bear Exp $ - */ -#ifndef __ARCH_SYS_ARCH_H__ -#define __ARCH_SYS_ARCH_H__ - -#include "arch/cc.h" -#include - -#define SYS_MBOX_NULL RT_NULL -#define SYS_SEM_NULL RT_NULL - -typedef rt_uint32_t sys_prot_t; - -#define SYS_MBOX_SIZE 10 -#define SYS_LWIP_TIMER_NAME "timer" -#define SYS_LWIP_MBOX_NAME "mbox" -#define SYS_LWIP_SEM_NAME "sem" -#define SYS_LWIP_MUTEX_NAME "mu" - -typedef rt_sem_t sys_sem_t; -typedef rt_mutex_t sys_mutex_t; -typedef rt_mailbox_t sys_mbox_t; -typedef rt_thread_t sys_thread_t; - -#endif /* __ARCH_SYS_ARCH_H__ */ diff --git a/components/net/lwip/lwip-2.0.3/src/arch/sys_arch.c b/components/net/lwip/lwip-2.0.3/src/arch/sys_arch.c deleted file mode 100644 index b779264f96..0000000000 --- a/components/net/lwip/lwip-2.0.3/src/arch/sys_arch.c +++ /dev/null @@ -1,773 +0,0 @@ -/* - * COPYRIGHT (C) 2006-2021, RT-Thread Development Team - * 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. - * - * Change Logs: - * Date Author Notes - * 2012-12-8 Bernard add file header - * export bsd socket symbol for RT-Thread Application Module - * 2017-11-15 Bernard add lock for init_done callback. - */ - -#include -#include - -#include "lwip/sys.h" -#include "lwip/opt.h" -#include "lwip/stats.h" -#include "lwip/err.h" -#include "arch/sys_arch.h" -#include "lwip/debug.h" -#include "lwip/netif.h" -#include "lwip/netifapi.h" -#include "lwip/tcpip.h" -#include "netif/ethernetif.h" -#include "lwip/sio.h" -#include "lwip/init.h" -#include "lwip/dhcp.h" -#include "lwip/inet.h" - -#include - -/* - * Initialize the network interface device - * - * @return the operation status, ERR_OK on OK, ERR_IF on error - */ -static err_t netif_device_init(struct netif *netif) -{ - struct eth_device *ethif; - - ethif = (struct eth_device *)netif->state; - if (ethif != RT_NULL) - { - rt_device_t device; - - /* get device object */ - device = (rt_device_t) ethif; - if (rt_device_init(device) != RT_EOK) - { - return ERR_IF; - } - - /* copy device flags to netif flags */ - netif->flags = ethif->flags; - - return ERR_OK; - } - - return ERR_IF; -} -/* - * Initialize the ethernetif layer and set network interface device up - */ -static void tcpip_init_done_callback(void *arg) -{ - rt_device_t device; - struct eth_device *ethif; - ip4_addr_t ipaddr, netmask, gw; - struct rt_list_node* node; - struct rt_object* object; - struct rt_object_information *information; - - LWIP_ASSERT("invalid arg.\n",arg); - - IP4_ADDR(&gw, 0,0,0,0); - IP4_ADDR(&ipaddr, 0,0,0,0); - IP4_ADDR(&netmask, 0,0,0,0); - - /* enter critical */ - rt_enter_critical(); - - /* for each network interfaces */ - information = rt_object_get_information(RT_Object_Class_Device); - RT_ASSERT(information != RT_NULL); - for (node = information->object_list.next; - node != &(information->object_list); - node = node->next) - { - object = rt_list_entry(node, struct rt_object, list); - device = (rt_device_t)object; - if (device->type == RT_Device_Class_NetIf) - { - ethif = (struct eth_device *)device; - - /* leave critical */ - rt_exit_critical(); - LOCK_TCPIP_CORE(); - - netif_add(ethif->netif, &ipaddr, &netmask, &gw, - ethif, netif_device_init, tcpip_input); - - if (netif_default == RT_NULL) - netif_set_default(ethif->netif); - -#if LWIP_DHCP - /* set interface up */ - netif_set_up(ethif->netif); - /* if this interface uses DHCP, start the DHCP client */ - dhcp_start(ethif->netif); -#else - /* set interface up */ - netif_set_up(ethif->netif); -#endif - - if (ethif->flags & ETHIF_LINK_PHYUP) - { - netif_set_link_up(ethif->netif); - } - - UNLOCK_TCPIP_CORE(); - /* enter critical */ - rt_enter_critical(); - } - } - - /* leave critical */ - rt_exit_critical(); - rt_sem_release((rt_sem_t)arg); -} - -/** - * LwIP system initialization - */ -extern int eth_system_device_init_private(void); -int lwip_system_init(void) -{ - rt_err_t rc; - struct rt_semaphore done_sem; - static rt_bool_t init_ok = RT_FALSE; - - if (init_ok) - { - rt_kprintf("lwip system already init.\n"); - return 0; - } - - eth_system_device_init_private(); - - /* set default netif to NULL */ - netif_default = RT_NULL; - - rc = rt_sem_init(&done_sem, "done", 0, RT_IPC_FLAG_FIFO); - - if (rc != RT_EOK) - { - LWIP_ASSERT("Failed to create semaphore", 0); - - return -1; - } - - tcpip_init(tcpip_init_done_callback, (void *)&done_sem); - - /* waiting for initialization done */ - if (rt_sem_take(&done_sem, RT_WAITING_FOREVER) != RT_EOK) - { - rt_sem_detach(&done_sem); - - return -1; - } - rt_sem_detach(&done_sem); - - /* set default ip address */ -#if !LWIP_DHCP - if (netif_default != RT_NULL) - { - struct ip4_addr ipaddr, netmask, gw; - - ipaddr.addr = inet_addr(RT_LWIP_IPADDR); - gw.addr = inet_addr(RT_LWIP_GWADDR); - netmask.addr = inet_addr(RT_LWIP_MSKADDR); - - netifapi_netif_set_addr(netif_default, &ipaddr, &netmask, &gw); - } -#endif - rt_kprintf("lwIP-%d.%d.%d initialized!\n", LWIP_VERSION_MAJOR, LWIP_VERSION_MINOR, LWIP_VERSION_REVISION); - - init_ok = RT_TRUE; - - return 0; -} -INIT_PREV_EXPORT(lwip_system_init); - -void sys_init(void) -{ - /* nothing on RT-Thread porting */ -} - -void lwip_sys_init(void) -{ - lwip_system_init(); -} - -/* - * Create a new semaphore - * - * @return the operation status, ERR_OK on OK; others on error - */ -err_t sys_sem_new(sys_sem_t *sem, u8_t count) -{ - static unsigned short counter = 0; - char tname[RT_NAME_MAX]; - sys_sem_t tmpsem; - - RT_DEBUG_NOT_IN_INTERRUPT; - - rt_snprintf(tname, RT_NAME_MAX, "%s%d", SYS_LWIP_SEM_NAME, counter); - counter ++; - - tmpsem = rt_sem_create(tname, count, RT_IPC_FLAG_FIFO); - if (tmpsem == RT_NULL) - return ERR_MEM; - else - { - *sem = tmpsem; - - return ERR_OK; - } -} - -/* - * Deallocate a semaphore - */ -void sys_sem_free(sys_sem_t *sem) -{ - RT_DEBUG_NOT_IN_INTERRUPT; - rt_sem_delete(*sem); -} - -/* - * Signal a semaphore - */ -void sys_sem_signal(sys_sem_t *sem) -{ - rt_sem_release(*sem); -} - -/* - * Block the thread while waiting for the semaphore to be signaled - * - * @return If the timeout argument is non-zero, it will return the number of milliseconds - * spent waiting for the semaphore to be signaled; If the semaphore isn't signaled - * within the specified time, it will return SYS_ARCH_TIMEOUT; If the thread doesn't - * wait for the semaphore, it will return zero - */ -u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout) -{ - rt_err_t ret; - s32_t t; - u32_t tick; - - RT_DEBUG_NOT_IN_INTERRUPT; - - /* get the begin tick */ - tick = rt_tick_get(); - if (timeout == 0) - t = RT_WAITING_FOREVER; - else - { - /* convert msecond to os tick */ - if (timeout < (1000/RT_TICK_PER_SECOND)) - t = 1; - else - t = timeout / (1000/RT_TICK_PER_SECOND); - } - - ret = rt_sem_take(*sem, t); - - if (ret == -RT_ETIMEOUT) - return SYS_ARCH_TIMEOUT; - else - { - if (ret == RT_EOK) - ret = 1; - } - - /* get elapse msecond */ - tick = rt_tick_get() - tick; - - /* convert tick to msecond */ - tick = tick * (1000 / RT_TICK_PER_SECOND); - if (tick == 0) - tick = 1; - - return tick; -} - -#ifndef sys_sem_valid -/** Check if a semaphore is valid/allocated: - * return 1 for valid, 0 for invalid - */ -int sys_sem_valid(sys_sem_t *sem) -{ - return (int)(*sem); -} -#endif - -#ifndef sys_sem_set_invalid -/** Set a semaphore invalid so that sys_sem_valid returns 0 - */ -void sys_sem_set_invalid(sys_sem_t *sem) -{ - *sem = RT_NULL; -} -#endif - -/* ====================== Mutex ====================== */ - -/** Create a new mutex - * @param mutex pointer to the mutex to create - * @return a new mutex - */ -err_t sys_mutex_new(sys_mutex_t *mutex) -{ - static unsigned short counter = 0; - char tname[RT_NAME_MAX]; - sys_mutex_t tmpmutex; - - RT_DEBUG_NOT_IN_INTERRUPT; - - rt_snprintf(tname, RT_NAME_MAX, "%s%d", SYS_LWIP_MUTEX_NAME, counter); - counter ++; - - tmpmutex = rt_mutex_create(tname, RT_IPC_FLAG_PRIO); - if (tmpmutex == RT_NULL) - return ERR_MEM; - else - { - *mutex = tmpmutex; - - return ERR_OK; - } -} - -/** Lock a mutex - * @param mutex the mutex to lock - */ -void sys_mutex_lock(sys_mutex_t *mutex) -{ - RT_DEBUG_NOT_IN_INTERRUPT; - rt_mutex_take(*mutex, RT_WAITING_FOREVER); - - return; -} - -/** Unlock a mutex - * @param mutex the mutex to unlock - */ -void sys_mutex_unlock(sys_mutex_t *mutex) -{ - rt_mutex_release(*mutex); -} - -/** Delete a semaphore - * @param mutex the mutex to delete - */ -void sys_mutex_free(sys_mutex_t *mutex) -{ - RT_DEBUG_NOT_IN_INTERRUPT; - - rt_mutex_delete(*mutex); -} - -#ifndef sys_mutex_valid -/** Check if a mutex is valid/allocated: - * return 1 for valid, 0 for invalid - */ -int sys_mutex_valid(sys_mutex_t *mutex) -{ - return (int)(*mutex); -} -#endif - -#ifndef sys_mutex_set_invalid -/** Set a mutex invalid so that sys_mutex_valid returns 0 - */ -void sys_mutex_set_invalid(sys_mutex_t *mutex) -{ - *mutex = RT_NULL; -} -#endif - -/* ====================== Mailbox ====================== */ - -/* - * Create an empty mailbox for maximum "size" elements - * - * @return the operation status, ERR_OK on OK; others on error - */ -err_t sys_mbox_new(sys_mbox_t *mbox, int size) -{ - static unsigned short counter = 0; - char tname[RT_NAME_MAX]; - sys_mbox_t tmpmbox; - - RT_DEBUG_NOT_IN_INTERRUPT; - - rt_snprintf(tname, RT_NAME_MAX, "%s%d", SYS_LWIP_MBOX_NAME, counter); - counter ++; - - tmpmbox = rt_mb_create(tname, size, RT_IPC_FLAG_FIFO); - if (tmpmbox != RT_NULL) - { - *mbox = tmpmbox; - - return ERR_OK; - } - - return ERR_MEM; -} - -/* - * Deallocate a mailbox - */ -void sys_mbox_free(sys_mbox_t *mbox) -{ - RT_DEBUG_NOT_IN_INTERRUPT; - - rt_mb_delete(*mbox); - - return; -} - -/** Post a message to an mbox - may not fail - * -> blocks if full, only used from tasks not from ISR - * @param mbox mbox to posts the message - * @param msg message to post (ATTENTION: can be NULL) - */ -void sys_mbox_post(sys_mbox_t *mbox, void *msg) -{ - RT_DEBUG_NOT_IN_INTERRUPT; - - rt_mb_send_wait(*mbox, (rt_ubase_t)msg, RT_WAITING_FOREVER); - - return; -} - -/* - * Try to post the "msg" to the mailbox - * - * @return return ERR_OK if the "msg" is posted, ERR_MEM if the mailbox is full - */ -err_t sys_mbox_trypost(sys_mbox_t *mbox, void *msg) -{ - if (rt_mb_send(*mbox, (rt_ubase_t)msg) == RT_EOK) - return ERR_OK; - - return ERR_MEM; -} - -/** Wait for a new message to arrive in the mbox - * @param mbox mbox to get a message from - * @param msg pointer where the message is stored - * @param timeout maximum time (in milliseconds) to wait for a message - * @return time (in milliseconds) waited for a message, may be 0 if not waited - or SYS_ARCH_TIMEOUT on timeout - * The returned time has to be accurate to prevent timer jitter! - */ -u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout) -{ - rt_err_t ret; - s32_t t; - u32_t tick; - - RT_DEBUG_NOT_IN_INTERRUPT; - - /* get the begin tick */ - tick = rt_tick_get(); - - if(timeout == 0) - t = RT_WAITING_FOREVER; - else - { - /* convirt msecond to os tick */ - if (timeout < (1000/RT_TICK_PER_SECOND)) - t = 1; - else - t = timeout / (1000/RT_TICK_PER_SECOND); - } - - ret = rt_mb_recv(*mbox, (rt_ubase_t *)msg, t); - if(ret != RT_EOK) - { - return SYS_ARCH_TIMEOUT; - } - - /* get elapse msecond */ - tick = rt_tick_get() - tick; - - /* convert tick to msecond */ - tick = tick * (1000 / RT_TICK_PER_SECOND); - if (tick == 0) - tick = 1; - - return tick; -} - -/** - * @ingroup sys_mbox - * This is similar to sys_arch_mbox_fetch, however if a message is not - * present in the mailbox, it immediately returns with the code - * SYS_MBOX_EMPTY. On success 0 is returned. - * To allow for efficient implementations, this can be defined as a - * function-like macro in sys_arch.h instead of a normal function. For - * example, a naive implementation could be: - * \#define sys_arch_mbox_tryfetch(mbox,msg) sys_arch_mbox_fetch(mbox,msg,1) - * although this would introduce unnecessary delays. - * - * @param mbox mbox to get a message from - * @param msg pointer where the message is stored - * @return 0 (milliseconds) if a message has been received - * or SYS_MBOX_EMPTY if the mailbox is empty - */ -u32_t sys_arch_mbox_tryfetch(sys_mbox_t *mbox, void **msg) -{ - int ret; - - ret = rt_mb_recv(*mbox, (rt_ubase_t *)msg, 0); - - if(ret == -RT_ETIMEOUT) - return SYS_ARCH_TIMEOUT; - else - { - if (ret == RT_EOK) - ret = 0; - } - - return ret; -} - -#ifndef sys_mbox_valid -/** Check if an mbox is valid/allocated: - * return 1 for valid, 0 for invalid - */ -int sys_mbox_valid(sys_mbox_t *mbox) -{ - return (int)(*mbox); -} -#endif - -#ifndef sys_mbox_set_invalid -/** Set an mbox invalid so that sys_mbox_valid returns 0 - */ -void sys_mbox_set_invalid(sys_mbox_t *mbox) -{ - *mbox = RT_NULL; -} -#endif - -/* ====================== System ====================== */ - -/* - * Start a new thread named "name" 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 - */ -sys_thread_t sys_thread_new(const char *name, - lwip_thread_fn thread, - void *arg, - int stacksize, - int prio) -{ - rt_thread_t t; - - RT_DEBUG_NOT_IN_INTERRUPT; - - /* create thread */ - t = rt_thread_create(name, thread, arg, stacksize, prio, 20); - RT_ASSERT(t != RT_NULL); - - /* startup thread */ - rt_thread_startup(t); - - return t; -} - -sys_prot_t sys_arch_protect(void) -{ - rt_base_t level; - - /* disable interrupt */ - level = rt_hw_interrupt_disable(); - - return level; -} - -void sys_arch_unprotect(sys_prot_t pval) -{ - /* enable interrupt */ - rt_hw_interrupt_enable(pval); - - return; -} - -void sys_arch_assert(const char *file, int line) -{ - rt_kprintf("\nAssertion: %d in %s, thread %s\n", - line, file, rt_thread_self()->name); - RT_ASSERT(0); -} - -u32_t sys_jiffies(void) -{ - return rt_tick_get(); -} - -u32_t sys_now(void) -{ - return rt_tick_get_millisecond(); -} - - -RT_WEAK -void mem_init(void) -{ -} - -void *mem_calloc(mem_size_t count, mem_size_t size) -{ - return rt_calloc(count, size); -} - -void *mem_trim(void *mem, mem_size_t size) -{ - // return rt_realloc(mem, size); - /* not support trim yet */ - return mem; -} - -void *mem_malloc(mem_size_t size) -{ - return rt_malloc(size); -} - -void mem_free(void *mem) -{ - rt_free(mem); -} - -#ifdef RT_LWIP_PPP -u32_t sio_read(sio_fd_t fd, u8_t *buf, u32_t size) -{ - u32_t len; - - RT_ASSERT(fd != RT_NULL); - - len = rt_device_read((rt_device_t)fd, 0, buf, size); - if (len <= 0) - return 0; - - return len; -} - -u32_t sio_write(sio_fd_t fd, u8_t *buf, u32_t size) -{ - RT_ASSERT(fd != RT_NULL); - - return rt_device_write((rt_device_t)fd, 0, buf, size); -} - -void sio_read_abort(sio_fd_t fd) -{ - rt_kprintf("read_abort\n"); -} - -void ppp_trace(int level, const char *format, ...) -{ - va_list args; - rt_size_t length; - static char rt_log_buf[RT_CONSOLEBUF_SIZE]; - - va_start(args, format); - length = rt_vsprintf(rt_log_buf, format, args); - rt_device_write((rt_device_t)rt_console_get_device(), 0, rt_log_buf, length); - va_end(args); -} -#endif - -/* - * export bsd socket symbol for RT-Thread Application Module - */ -#if LWIP_SOCKET -#include -RTM_EXPORT(lwip_accept); -RTM_EXPORT(lwip_bind); -RTM_EXPORT(lwip_shutdown); -RTM_EXPORT(lwip_getpeername); -RTM_EXPORT(lwip_getsockname); -RTM_EXPORT(lwip_getsockopt); -RTM_EXPORT(lwip_setsockopt); -RTM_EXPORT(lwip_close); -RTM_EXPORT(lwip_connect); -RTM_EXPORT(lwip_listen); -RTM_EXPORT(lwip_recv); -RTM_EXPORT(lwip_read); -RTM_EXPORT(lwip_recvfrom); -RTM_EXPORT(lwip_send); -RTM_EXPORT(lwip_sendto); -RTM_EXPORT(lwip_socket); -RTM_EXPORT(lwip_write); -RTM_EXPORT(lwip_select); -RTM_EXPORT(lwip_ioctl); -RTM_EXPORT(lwip_fcntl); - -RTM_EXPORT(lwip_htons); -RTM_EXPORT(lwip_htonl); - -#if LWIP_DNS -#include -RTM_EXPORT(lwip_gethostbyname); -RTM_EXPORT(lwip_gethostbyname_r); -RTM_EXPORT(lwip_freeaddrinfo); -RTM_EXPORT(lwip_getaddrinfo); -#endif - -#endif - -#if LWIP_DHCP -#include -RTM_EXPORT(dhcp_start); -RTM_EXPORT(dhcp_renew); -RTM_EXPORT(dhcp_stop); -#endif - -#if LWIP_NETIF_API -#include -RTM_EXPORT(netifapi_netif_set_addr); -#endif - -#if LWIP_NETIF_LINK_CALLBACK -RTM_EXPORT(netif_set_link_callback); -#endif - -#if LWIP_NETIF_STATUS_CALLBACK -RTM_EXPORT(netif_set_status_callback); -#endif - -RTM_EXPORT(netif_find); -RTM_EXPORT(netif_set_addr); -RTM_EXPORT(netif_set_ipaddr); -RTM_EXPORT(netif_set_gw); -RTM_EXPORT(netif_set_netmask); diff --git a/components/net/lwip/lwip-2.0.3/src/include/netif/ethernetif.h b/components/net/lwip/lwip-2.0.3/src/include/netif/ethernetif.h deleted file mode 100644 index 1459e3241d..0000000000 --- a/components/net/lwip/lwip-2.0.3/src/include/netif/ethernetif.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef __NETIF_ETHERNETIF_H__ -#define __NETIF_ETHERNETIF_H__ - -#include "lwip/netif.h" -#include - -#define NIOCTL_GADDR 0x01 -#ifndef RT_LWIP_ETH_MTU -#define ETHERNET_MTU 1500 -#else -#define ETHERNET_MTU RT_LWIP_ETH_MTU -#endif - -/* eth flag with auto_linkup or phy_linkup */ -#define ETHIF_LINK_AUTOUP 0x0000 -#define ETHIF_LINK_PHYUP 0x0100 - -struct eth_device -{ - /* inherit from rt_device */ - struct rt_device parent; - - /* network interface for lwip */ - struct netif *netif; - struct rt_semaphore tx_ack; - - rt_uint16_t flags; - rt_uint8_t link_changed; - rt_uint8_t link_status; - rt_uint8_t rx_notice; - - /* eth device interface */ - struct pbuf* (*eth_rx)(rt_device_t dev); - rt_err_t (*eth_tx)(rt_device_t dev, struct pbuf* p); -}; - -#ifdef __cplusplus -extern "C" { -#endif - - rt_err_t eth_device_ready(struct eth_device* dev); - rt_err_t eth_device_init(struct eth_device * dev, const char *name); - rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_uint16_t flag); - rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up); - void eth_device_deinit(struct eth_device *dev); - - int eth_system_device_init(void); - -#ifdef __cplusplus -} -#endif - -#endif /* __NETIF_ETHERNETIF_H__ */ diff --git a/components/net/lwip/lwip-2.0.3/src/netif/ethernetif.c b/components/net/lwip/lwip-2.0.3/src/netif/ethernetif.c deleted file mode 100644 index b278490f16..0000000000 --- a/components/net/lwip/lwip-2.0.3/src/netif/ethernetif.c +++ /dev/null @@ -1,1022 +0,0 @@ -/* - * Copyright (c) 2001-2004 Swedish Institute of Computer Science. - * COPYRIGHT (C) 2006-2018, RT-Thread Development Team - * 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 - * - * Change Logs: - * Date Author Notes - * 2010-07-07 Bernard fix send mail to mailbox issue. - * 2011-07-30 mbbill port lwIP 1.4.0 to RT-Thread - * 2012-04-10 Bernard add more compatible with RT-Thread. - * 2012-11-12 Bernard The network interface can be initialized - * after lwIP initialization. - * 2013-02-28 aozima fixed list_tcps bug: ipaddr_ntoa isn't reentrant. - * 2016-08-18 Bernard port to lwIP 2.0.0 - * 2020-08-10 lizhirui fixed some problems when this is running on 64-bit cpu - */ - -#include "lwip/opt.h" - -#include "lwip/opt.h" -#include "lwip/debug.h" -#include "lwip/def.h" -#include "lwip/mem.h" -#include "lwip/pbuf.h" -#include "lwip/sys.h" -#include "lwip/netif.h" -#include "lwip/stats.h" -#include "lwip/tcpip.h" -#include "lwip/dhcp.h" -#include "lwip/netifapi.h" - -#include "netif/etharp.h" -#include "netif/ethernetif.h" - -#include "lwip/inet.h" - -#if LWIP_IPV6 -#include "lwip/ethip6.h" -#endif /* LWIP_IPV6 */ - -#define netifapi_netif_set_link_up(n) netifapi_netif_common(n, netif_set_link_up, NULL) -#define netifapi_netif_set_link_down(n) netifapi_netif_common(n, netif_set_link_down, NULL) - -#ifndef RT_LWIP_ETHTHREAD_PRIORITY -#define RT_ETHERNETIF_THREAD_PREORITY 0x90 -#else -#define RT_ETHERNETIF_THREAD_PREORITY RT_LWIP_ETHTHREAD_PRIORITY -#endif - -#ifndef LWIP_NO_TX_THREAD -/** - * Tx message structure for Ethernet interface - */ -struct eth_tx_msg -{ - struct netif *netif; - struct pbuf *buf; -}; - -static struct rt_mailbox eth_tx_thread_mb; -static struct rt_thread eth_tx_thread; -#ifndef RT_LWIP_ETHTHREAD_MBOX_SIZE -static char eth_tx_thread_mb_pool[32 * sizeof(rt_ubase_t)]; -static char eth_tx_thread_stack[512]; -#else -static char eth_tx_thread_mb_pool[RT_LWIP_ETHTHREAD_MBOX_SIZE * sizeof(rt_ubase_t)]; -static char eth_tx_thread_stack[RT_LWIP_ETHTHREAD_STACKSIZE]; -#endif -#endif - -#ifndef LWIP_NO_RX_THREAD -static struct rt_mailbox eth_rx_thread_mb; -static struct rt_thread eth_rx_thread; -#ifndef RT_LWIP_ETHTHREAD_MBOX_SIZE -static char eth_rx_thread_mb_pool[48 * sizeof(rt_ubase_t)]; -static char eth_rx_thread_stack[1024]; -#else -static char eth_rx_thread_mb_pool[RT_LWIP_ETHTHREAD_MBOX_SIZE * sizeof(rt_ubase_t)]; -static char eth_rx_thread_stack[RT_LWIP_ETHTHREAD_STACKSIZE]; -#endif -#endif - -#ifdef RT_USING_NETDEV - -#include "lwip/ip.h" -#include "lwip/init.h" -#include "lwip/netdb.h" -#include - -static int lwip_netdev_set_up(struct netdev *netif) -{ - netif_set_up((struct netif *)netif->user_data); - return ERR_OK; -} - -static int lwip_netdev_set_down(struct netdev *netif) -{ - netif_set_down((struct netif *)netif->user_data); - return ERR_OK; -} - -static int lwip_netdev_set_addr_info(struct netdev *netif, ip_addr_t *ip_addr, ip_addr_t *netmask, ip_addr_t *gw) -{ - if (ip_addr && netmask && gw) - { - netif_set_addr((struct netif *)netif->user_data, ip_2_ip4(ip_addr), ip_2_ip4(netmask), ip_2_ip4(gw)); - } - else - { - if (ip_addr) - { - netif_set_ipaddr((struct netif *)netif->user_data, ip_2_ip4(ip_addr)); - } - - if (netmask) - { - netif_set_netmask((struct netif *)netif->user_data, ip_2_ip4(netmask)); - } - - if (gw) - { - netif_set_gw((struct netif *)netif->user_data, ip_2_ip4(gw)); - } - } - - return ERR_OK; -} - -#ifdef RT_LWIP_DNS -static int lwip_netdev_set_dns_server(struct netdev *netif, uint8_t dns_num, ip_addr_t *dns_server) -{ - extern void dns_setserver(uint8_t dns_num, const ip_addr_t *dns_server); - dns_setserver(dns_num, dns_server); - return ERR_OK; -} -#endif /* RT_LWIP_DNS */ - -#ifdef RT_LWIP_DHCP -static int lwip_netdev_set_dhcp(struct netdev *netif, rt_bool_t is_enabled) -{ - netdev_low_level_set_dhcp_status(netif, is_enabled); - - /*add dhcp start or stop must call dhcp_start and dhcp_stop function*/ - if(is_enabled == RT_TRUE) - { - dhcp_start((struct netif *)netif->user_data); - } - else - { - dhcp_stop((struct netif *)netif->user_data); - } - return ERR_OK; -} -#endif /* RT_LWIP_DHCP */ - -#ifdef RT_USING_FINSH -#ifdef RT_LWIP_USING_PING -extern int lwip_ping_recv(int s, int *ttl); -extern err_t lwip_ping_send(int s, ip_addr_t *addr, int size); - -int lwip_netdev_ping(struct netdev *netif, const char *host, size_t data_len, - uint32_t timeout, struct netdev_ping_resp *ping_resp) -{ - int s, ttl, recv_len, result = 0; - int elapsed_time; - rt_tick_t recv_start_tick; -#if LWIP_VERSION_MAJOR >= 2U - struct timeval recv_timeout = { timeout / RT_TICK_PER_SECOND, timeout % RT_TICK_PER_SECOND }; -#else - int recv_timeout = timeout * 1000UL / RT_TICK_PER_SECOND; -#endif - ip_addr_t target_addr; - struct addrinfo hint, *res = RT_NULL; - struct sockaddr_in *h = RT_NULL; - struct in_addr ina; - - RT_ASSERT(netif); - RT_ASSERT(host); - RT_ASSERT(ping_resp); - - rt_memset(&hint, 0x00, sizeof(hint)); - /* convert URL to IP */ - if (lwip_getaddrinfo(host, RT_NULL, &hint, &res) != 0) - { - return -RT_ERROR; - } - SMEMCPY(&h, &res->ai_addr, sizeof(struct sockaddr_in *)); - SMEMCPY(&ina, &h->sin_addr, sizeof(ina)); - lwip_freeaddrinfo(res); - if (inet_aton(inet_ntoa(ina), &target_addr) == 0) - { - return -RT_ERROR; - } - SMEMCPY(&(ping_resp->ip_addr), &target_addr, sizeof(ip_addr_t)); - - /* new a socket */ - if ((s = lwip_socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP)) < 0) - { - return -RT_ERROR; - } - - lwip_setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &recv_timeout, sizeof(recv_timeout)); - - if (lwip_ping_send(s, &target_addr, data_len) == ERR_OK) - { - recv_start_tick = rt_tick_get(); - if ((recv_len = lwip_ping_recv(s, &ttl)) >= 0) - { - elapsed_time = (rt_tick_get() - recv_start_tick) * 1000UL / RT_TICK_PER_SECOND; - ping_resp->data_len = recv_len; - ping_resp->ttl = ttl; - ping_resp->ticks = elapsed_time; - } - else - { - result = -RT_ETIMEOUT; - goto __exit; - } - } - else - { - result = -RT_ETIMEOUT; - goto __exit; - } - -__exit: - lwip_close(s); - - return result; -} -#endif /* RT_LWIP_USING_PING */ - -#if defined (RT_LWIP_TCP) || defined (RT_LWIP_UDP) -void lwip_netdev_netstat(struct netdev *netif) -{ - extern void list_tcps(void); - extern void list_udps(void); - -#ifdef RT_LWIP_TCP - list_tcps(); -#endif -#ifdef RT_LWIP_UDP - list_udps(); -#endif -} -#endif /* RT_LWIP_TCP || RT_LWIP_UDP */ -#endif /* RT_USING_FINSH */ - -static int lwip_netdev_set_default(struct netdev *netif) -{ - netif_set_default((struct netif *)netif->user_data); - return ERR_OK; -} - -const struct netdev_ops lwip_netdev_ops = -{ - lwip_netdev_set_up, - lwip_netdev_set_down, - - lwip_netdev_set_addr_info, -#ifdef RT_LWIP_DNS - lwip_netdev_set_dns_server, -#else - NULL, -#endif /* RT_LWIP_DNS */ - -#ifdef RT_LWIP_DHCP - lwip_netdev_set_dhcp, -#else - NULL, -#endif /* RT_LWIP_DHCP */ - -#ifdef RT_USING_FINSH -#ifdef RT_LWIP_USING_PING - lwip_netdev_ping, -#else - NULL, -#endif /* RT_LWIP_USING_PING */ - -#if defined (RT_LWIP_TCP) || defined (RT_LWIP_UDP) - lwip_netdev_netstat, -#endif /* RT_LWIP_TCP || RT_LWIP_UDP */ -#endif /* RT_USING_FINSH */ - - lwip_netdev_set_default, -}; - -static int netdev_add(struct netif *lwip_netif) -{ -#define LWIP_NETIF_NAME_LEN 2 - int result = 0; - struct netdev *netdev = RT_NULL; - char name[LWIP_NETIF_NAME_LEN + 1] = {0}; - - RT_ASSERT(lwip_netif); - - netdev = (struct netdev *)rt_calloc(1, sizeof(struct netdev)); - if (netdev == RT_NULL) - { - return -ERR_IF; - } - -#ifdef SAL_USING_LWIP - extern int sal_lwip_netdev_set_pf_info(struct netdev *netdev); - /* set the lwIP network interface device protocol family information */ - sal_lwip_netdev_set_pf_info(netdev); -#endif /* SAL_USING_LWIP */ - - rt_strncpy(name, lwip_netif->name, LWIP_NETIF_NAME_LEN); - result = netdev_register(netdev, name, (void *)lwip_netif); - - /* Update netdev info after registered */ - netdev->flags = lwip_netif->flags; - netdev->mtu = lwip_netif->mtu; - netdev->ops = &lwip_netdev_ops; - netdev->hwaddr_len = lwip_netif->hwaddr_len; - SMEMCPY(netdev->hwaddr, lwip_netif->hwaddr, lwip_netif->hwaddr_len); - netdev->ip_addr = lwip_netif->ip_addr; - netdev->gw = lwip_netif->gw; - netdev->netmask = lwip_netif->netmask; - -#ifdef RT_LWIP_DHCP - netdev_low_level_set_dhcp_status(netdev, RT_TRUE); -#endif - - return result; -} - -static void netdev_del(struct netif *lwip_netif) -{ - char name[LWIP_NETIF_NAME_LEN + 1]; - struct netdev *netdev; - - RT_ASSERT(lwip_netif); - - rt_strncpy(name, lwip_netif->name, LWIP_NETIF_NAME_LEN); - netdev = netdev_get_by_name(name); - netdev_unregister(netdev); - rt_free(netdev); -} - -/* synchronize lwIP network interface device and network interface device flags */ -static int netdev_flags_sync(struct netif *lwip_netif) -{ - struct netdev *netdev = NULL; - - RT_ASSERT(lwip_netif); - - netdev = netdev_get_by_name(lwip_netif->name); - if (netdev == RT_NULL) - { - return -ERR_IF; - } - - netdev->flags |= lwip_netif->flags; - - return ERR_OK; -} -#endif /* RT_USING_NETDEV */ - -static err_t ethernetif_linkoutput(struct netif *netif, struct pbuf *p) -{ -#ifndef LWIP_NO_TX_THREAD - struct eth_tx_msg msg; - struct eth_device* enetif; - - RT_ASSERT(netif != RT_NULL); - enetif = (struct eth_device*)netif->state; - - /* send a message to eth tx thread */ - msg.netif = netif; - msg.buf = p; - if (rt_mb_send(ð_tx_thread_mb, (rt_ubase_t) &msg) == RT_EOK) - { - /* waiting for ack */ - rt_sem_take(&(enetif->tx_ack), RT_WAITING_FOREVER); - } -#else - struct eth_device* enetif; - - RT_ASSERT(netif != RT_NULL); - enetif = (struct eth_device*)netif->state; - - if (enetif->eth_tx(&(enetif->parent), p) != RT_EOK) - { - return ERR_IF; - } -#endif - return ERR_OK; -} - -static err_t eth_netif_device_init(struct netif *netif) -{ - struct eth_device *ethif; - -#ifdef RT_USING_NETDEV - /* network interface device register */ - netdev_add(netif); -#endif /* RT_USING_NETDEV */ - - ethif = (struct eth_device*)netif->state; - if (ethif != RT_NULL) - { - rt_device_t device; - - /* get device object */ - device = (rt_device_t) ethif; - if (rt_device_init(device) != RT_EOK) - { - return ERR_IF; - } - - /* copy device flags to netif flags */ - netif->flags = (ethif->flags & 0xff); - -#if LWIP_IPV6 - netif->output_ip6 = ethip6_output; - netif->ip6_autoconfig_enabled = 1; - netif_create_ip6_linklocal_address(netif, 1); - -#if LWIP_IPV6_MLD - netif->flags |= NETIF_FLAG_MLD6; - - /* - * For hardware/netifs that implement MAC filtering. - * All-nodes link-local is handled by default, so we must let the hardware know - * to allow multicast packets in. - * Should set mld_mac_filter previously. */ - if (netif->mld_mac_filter != NULL) - { - ip6_addr_t ip6_allnodes_ll; - ip6_addr_set_allnodes_linklocal(&ip6_allnodes_ll); - netif->mld_mac_filter(netif, &ip6_allnodes_ll, NETIF_ADD_MAC_FILTER); - } -#endif /* LWIP_IPV6_MLD */ - -#endif /* LWIP_IPV6 */ - - /* set default netif */ - if (netif_default == RT_NULL) - netif_set_default(ethif->netif); - -#if LWIP_DHCP - /* set interface up */ - netif_set_up(ethif->netif); - /* if this interface uses DHCP, start the DHCP client */ - dhcp_start(ethif->netif); -#else - /* set interface up */ - netif_set_up(ethif->netif); -#endif - - if (ethif->flags & ETHIF_LINK_PHYUP) - { - /* set link_up for this netif */ - netif_set_link_up(ethif->netif); - } - - return ERR_OK; - } - - return ERR_IF; -} - -/* Keep old drivers compatible in RT-Thread */ -rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_uint16_t flags) -{ - struct netif* netif; -#if LWIP_NETIF_HOSTNAME -#define LWIP_HOSTNAME_LEN 16 - char *hostname = RT_NULL; - netif = (struct netif*) rt_calloc (1, sizeof(struct netif) + LWIP_HOSTNAME_LEN); -#else - netif = (struct netif*) rt_calloc (1, sizeof(struct netif)); -#endif - if (netif == RT_NULL) - { - rt_kprintf("malloc netif failed\n"); - return -RT_ERROR; - } - - /* set netif */ - dev->netif = netif; - /* device flags, which will be set to netif flags when initializing */ - dev->flags = flags; - /* link changed status of device */ - dev->link_changed = 0x00; - /* avoid send the same mail to mailbox */ - dev->rx_notice = 0x00; - dev->parent.type = RT_Device_Class_NetIf; - /* register to RT-Thread device manager */ - rt_device_register(&(dev->parent), name, RT_DEVICE_FLAG_RDWR); - rt_sem_init(&(dev->tx_ack), name, 0, RT_IPC_FLAG_FIFO); - - /* set name */ - netif->name[0] = name[0]; - netif->name[1] = name[1]; - - /* set hw address to 6 */ - netif->hwaddr_len = 6; - /* maximum transfer unit */ - netif->mtu = ETHERNET_MTU; - - /* get hardware MAC address */ - rt_device_control(&(dev->parent), NIOCTL_GADDR, netif->hwaddr); - - /* set output */ - netif->output = etharp_output; - netif->linkoutput = ethernetif_linkoutput; - -#if LWIP_NETIF_HOSTNAME - /* Initialize interface hostname */ - hostname = (char *)netif + sizeof(struct netif); - rt_sprintf(hostname, "rtthread_%02x%02x", name[0], name[1]); - netif->hostname = hostname; -#endif /* LWIP_NETIF_HOSTNAME */ - - /* if tcp thread has been started up, we add this netif to the system */ - if (rt_thread_find("tcpip") != RT_NULL) - { - ip4_addr_t ipaddr, netmask, gw; - -#if !LWIP_DHCP - ipaddr.addr = inet_addr(RT_LWIP_IPADDR); - gw.addr = inet_addr(RT_LWIP_GWADDR); - netmask.addr = inet_addr(RT_LWIP_MSKADDR); -#else - IP4_ADDR(&ipaddr, 0, 0, 0, 0); - IP4_ADDR(&gw, 0, 0, 0, 0); - IP4_ADDR(&netmask, 0, 0, 0, 0); -#endif - netifapi_netif_add(netif, &ipaddr, &netmask, &gw, dev, eth_netif_device_init, tcpip_input); - } - -#ifdef RT_USING_NETDEV - /* network interface device flags synchronize */ - netdev_flags_sync(netif); -#endif /* RT_USING_NETDEV */ - - return RT_EOK; -} - -rt_err_t eth_device_init(struct eth_device * dev, const char *name) -{ - rt_uint16_t flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP; - -#if LWIP_IGMP - /* IGMP support */ - flags |= NETIF_FLAG_IGMP; -#endif - - return eth_device_init_with_flag(dev, name, flags); -} - -void eth_device_deinit(struct eth_device *dev) -{ - struct netif* netif = dev->netif; - -#if LWIP_DHCP - dhcp_stop(netif); - dhcp_cleanup(netif); -#endif - netif_set_down(netif); - netif_remove(netif); -#ifdef RT_USING_NETDEV - netdev_del(netif); -#endif - rt_device_close(&(dev->parent)); - rt_device_unregister(&(dev->parent)); - rt_sem_detach(&(dev->tx_ack)); - rt_free(netif); -} - -#ifndef LWIP_NO_RX_THREAD -rt_err_t eth_device_ready(struct eth_device* dev) -{ - if (dev->netif) - { - if(dev->rx_notice == RT_FALSE) - { - dev->rx_notice = RT_TRUE; - return rt_mb_send(ð_rx_thread_mb, (rt_ubase_t)dev); - } - else - return RT_EOK; - /* post message to Ethernet thread */ - } - else - return -RT_ERROR; /* netif is not initialized yet, just return. */ -} - -rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up) -{ - rt_uint32_t level; - - RT_ASSERT(dev != RT_NULL); - - level = rt_hw_interrupt_disable(); - dev->link_changed = 0x01; - if (up == RT_TRUE) - dev->link_status = 0x01; - else - dev->link_status = 0x00; - rt_hw_interrupt_enable(level); - - /* post message to ethernet thread */ - return rt_mb_send(ð_rx_thread_mb, (rt_ubase_t)dev); -} -#else -/* NOTE: please not use it in interrupt when no RxThread exist */ -rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up) -{ - if (up == RT_TRUE) - netifapi_netif_set_link_up(dev->netif); - else - netifapi_netif_set_link_down(dev->netif); - - return RT_EOK; -} -#endif - -#ifndef LWIP_NO_TX_THREAD -/* Ethernet Tx Thread */ -static void eth_tx_thread_entry(void* parameter) -{ - struct eth_tx_msg* msg; - - while (1) - { - if (rt_mb_recv(ð_tx_thread_mb, (rt_ubase_t *)&msg, RT_WAITING_FOREVER) == RT_EOK) - { - struct eth_device* enetif; - - RT_ASSERT(msg->netif != RT_NULL); - RT_ASSERT(msg->buf != RT_NULL); - - enetif = (struct eth_device*)msg->netif->state; - if (enetif != RT_NULL) - { - /* call driver's interface */ - if (enetif->eth_tx(&(enetif->parent), msg->buf) != RT_EOK) - { - /* transmit eth packet failed */ - } - } - - /* send ACK */ - rt_sem_release(&(enetif->tx_ack)); - } - } -} -#endif - -#ifndef LWIP_NO_RX_THREAD -/* Ethernet Rx Thread */ -static void eth_rx_thread_entry(void* parameter) -{ - struct eth_device* device; - - while (1) - { - if (rt_mb_recv(ð_rx_thread_mb, (rt_ubase_t *)&device, RT_WAITING_FOREVER) == RT_EOK) - { - rt_base_t level; - struct pbuf *p; - - /* check link status */ - if (device->link_changed) - { - int status; - rt_uint32_t level; - - level = rt_hw_interrupt_disable(); - status = device->link_status; - device->link_changed = 0x00; - rt_hw_interrupt_enable(level); - - if (status) - netifapi_netif_set_link_up(device->netif); - else - netifapi_netif_set_link_down(device->netif); - } - - level = rt_hw_interrupt_disable(); - /* 'rx_notice' will be modify in the interrupt or here */ - device->rx_notice = RT_FALSE; - rt_hw_interrupt_enable(level); - - /* receive all of buffer */ - while(1) - { - if(device->eth_rx == RT_NULL) break; - - p = device->eth_rx(&(device->parent)); - if (p != RT_NULL) - { - /* notify to upper layer */ - if( device->netif->input(p, device->netif) != ERR_OK ) - { - LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: Input error\n")); - pbuf_free(p); - p = NULL; - } - } - else break; - } - } - else - { - LWIP_ASSERT("Should not happen!\n",0); - } - } -} -#endif - -/* this function does not need, - * use eth_system_device_init_private() - * call by lwip_system_init(). - */ -int eth_system_device_init(void) -{ - return 0; -} - -int eth_system_device_init_private(void) -{ - rt_err_t result = RT_EOK; - - /* initialize Rx thread. */ -#ifndef LWIP_NO_RX_THREAD - /* initialize mailbox and create Ethernet Rx thread */ - result = rt_mb_init(ð_rx_thread_mb, "erxmb", - ð_rx_thread_mb_pool[0], sizeof(eth_rx_thread_mb_pool)/sizeof(rt_ubase_t), - RT_IPC_FLAG_FIFO); - RT_ASSERT(result == RT_EOK); - - result = rt_thread_init(ð_rx_thread, "erx", eth_rx_thread_entry, RT_NULL, - ð_rx_thread_stack[0], sizeof(eth_rx_thread_stack), - RT_ETHERNETIF_THREAD_PREORITY, 16); - RT_ASSERT(result == RT_EOK); - result = rt_thread_startup(ð_rx_thread); - RT_ASSERT(result == RT_EOK); -#endif - - /* initialize Tx thread */ -#ifndef LWIP_NO_TX_THREAD - /* initialize mailbox and create Ethernet Tx thread */ - result = rt_mb_init(ð_tx_thread_mb, "etxmb", - ð_tx_thread_mb_pool[0], sizeof(eth_tx_thread_mb_pool)/sizeof(rt_ubase_t), - RT_IPC_FLAG_FIFO); - RT_ASSERT(result == RT_EOK); - - result = rt_thread_init(ð_tx_thread, "etx", eth_tx_thread_entry, RT_NULL, - ð_tx_thread_stack[0], sizeof(eth_tx_thread_stack), - RT_ETHERNETIF_THREAD_PREORITY, 16); - RT_ASSERT(result == RT_EOK); - - result = rt_thread_startup(ð_tx_thread); - RT_ASSERT(result == RT_EOK); -#endif - - return (int)result; -} - -void set_if(char* netif_name, char* ip_addr, char* gw_addr, char* nm_addr) -{ - ip4_addr_t *ip; - ip4_addr_t addr; - struct netif * netif = netif_list; - - if(strlen(netif_name) > sizeof(netif->name)) - { - rt_kprintf("network interface name too long!\r\n"); - return; - } - - while(netif != RT_NULL) - { - if(strncmp(netif_name, netif->name, sizeof(netif->name)) == 0) - break; - - netif = netif->next; - if( netif == RT_NULL ) - { - rt_kprintf("network interface: %s not found!\r\n", netif_name); - return; - } - } - - ip = (ip4_addr_t *)&addr; - - /* set ip address */ - if ((ip_addr != RT_NULL) && ip4addr_aton(ip_addr, &addr)) - { - netif_set_ipaddr(netif, ip); - } - - /* set gateway address */ - if ((gw_addr != RT_NULL) && ip4addr_aton(gw_addr, &addr)) - { - netif_set_gw(netif, ip); - } - - /* set netmask address */ - if ((nm_addr != RT_NULL) && ip4addr_aton(nm_addr, &addr)) - { - netif_set_netmask(netif, ip); - } -} - -#ifdef RT_USING_FINSH -#include -FINSH_FUNCTION_EXPORT(set_if, set network interface address); - -#if LWIP_DNS -#include -void set_dns(uint8_t dns_num, char* dns_server) -{ - ip_addr_t addr; - - if ((dns_server != RT_NULL) && ipaddr_aton(dns_server, &addr)) - { - dns_setserver(dns_num, &addr); - } -} -FINSH_FUNCTION_EXPORT(set_dns, set DNS server address); -#endif - -void list_if(void) -{ - rt_ubase_t index; - struct netif * netif; - - rt_enter_critical(); - - netif = netif_list; - - while( netif != RT_NULL ) - { - rt_kprintf("network interface: %c%c%s\n", - netif->name[0], - netif->name[1], - (netif == netif_default)?" (Default)":""); - rt_kprintf("MTU: %d\n", netif->mtu); - rt_kprintf("MAC: "); - for (index = 0; index < netif->hwaddr_len; index ++) - rt_kprintf("%02x ", netif->hwaddr[index]); - rt_kprintf("\nFLAGS:"); - if (netif->flags & NETIF_FLAG_UP) rt_kprintf(" UP"); - else rt_kprintf(" DOWN"); - if (netif->flags & NETIF_FLAG_LINK_UP) rt_kprintf(" LINK_UP"); - else rt_kprintf(" LINK_DOWN"); - if (netif->flags & NETIF_FLAG_ETHARP) rt_kprintf(" ETHARP"); - if (netif->flags & NETIF_FLAG_BROADCAST) rt_kprintf(" BROADCAST"); - if (netif->flags & NETIF_FLAG_IGMP) rt_kprintf(" IGMP"); - rt_kprintf("\n"); - rt_kprintf("ip address: %s\n", ipaddr_ntoa(&(netif->ip_addr))); - rt_kprintf("gw address: %s\n", ipaddr_ntoa(&(netif->gw))); - rt_kprintf("net mask : %s\n", ipaddr_ntoa(&(netif->netmask))); -#if LWIP_IPV6 - { - ip6_addr_t *addr; - int addr_state; - int i; - - addr = (ip6_addr_t *)&netif->ip6_addr[0]; - addr_state = netif->ip6_addr_state[0]; - - rt_kprintf("\nipv6 link-local: %s state:%02X %s\n", ip6addr_ntoa(addr), - addr_state, ip6_addr_isvalid(addr_state)?"VALID":"INVALID"); - - for(i=1; iip6_addr[i]; - addr_state = netif->ip6_addr_state[i]; - - rt_kprintf("ipv6[%d] address: %s state:%02X %s\n", i, ip6addr_ntoa(addr), - addr_state, ip6_addr_isvalid(addr_state)?"VALID":"INVALID"); - } - - } - rt_kprintf("\r\n"); -#endif /* LWIP_IPV6 */ - netif = netif->next; - } - -#if LWIP_DNS - { - const ip_addr_t *ip_addr; - - for(index=0; index -#include - -void list_tcps(void) -{ - rt_uint32_t num = 0; - struct tcp_pcb *pcb; - char local_ip_str[16]; - char remote_ip_str[16]; - - extern struct tcp_pcb *tcp_active_pcbs; - extern union tcp_listen_pcbs_t tcp_listen_pcbs; - extern struct tcp_pcb *tcp_tw_pcbs; - - rt_enter_critical(); - rt_kprintf("Active PCB states:\n"); - for(pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) - { - strcpy(local_ip_str, ipaddr_ntoa(&(pcb->local_ip))); - strcpy(remote_ip_str, ipaddr_ntoa(&(pcb->remote_ip))); - - rt_kprintf("#%d %s:%d <==> %s:%d snd_nxt 0x%08X rcv_nxt 0x%08X ", - num++, - local_ip_str, - pcb->local_port, - remote_ip_str, - pcb->remote_port, - pcb->snd_nxt, - pcb->rcv_nxt); - rt_kprintf("state: %s\n", tcp_debug_state_str(pcb->state)); - } - - rt_kprintf("Listen PCB states:\n"); - num = 0; - for(pcb = (struct tcp_pcb *)tcp_listen_pcbs.pcbs; pcb != NULL; pcb = pcb->next) - { - rt_kprintf("#%d local port %d ", num++, pcb->local_port); - rt_kprintf("state: %s\n", tcp_debug_state_str(pcb->state)); - } - - rt_kprintf("TIME-WAIT PCB states:\n"); - num = 0; - for(pcb = tcp_tw_pcbs; pcb != NULL; pcb = pcb->next) - { - strcpy(local_ip_str, ipaddr_ntoa(&(pcb->local_ip))); - strcpy(remote_ip_str, ipaddr_ntoa(&(pcb->remote_ip))); - - rt_kprintf("#%d %s:%d <==> %s:%d snd_nxt 0x%08X rcv_nxt 0x%08X ", - num++, - local_ip_str, - pcb->local_port, - remote_ip_str, - pcb->remote_port, - pcb->snd_nxt, - pcb->rcv_nxt); - rt_kprintf("state: %s\n", tcp_debug_state_str(pcb->state)); - } - rt_exit_critical(); -} -FINSH_FUNCTION_EXPORT(list_tcps, list all of tcp connections); -#endif /* LWIP_TCP */ - -#if LWIP_UDP -#include "lwip/udp.h" -void list_udps(void) -{ - struct udp_pcb *pcb; - rt_uint32_t num = 0; - char local_ip_str[16]; - char remote_ip_str[16]; - - rt_enter_critical(); - rt_kprintf("Active UDP PCB states:\n"); - for (pcb = udp_pcbs; pcb != NULL; pcb = pcb->next) - { - strcpy(local_ip_str, ipaddr_ntoa(&(pcb->local_ip))); - strcpy(remote_ip_str, ipaddr_ntoa(&(pcb->remote_ip))); - - rt_kprintf("#%d %d %s:%d <==> %s:%d \n", - num, (int)pcb->flags, - local_ip_str, - pcb->local_port, - remote_ip_str, - pcb->remote_port); - - num++; - } - rt_exit_critical(); -} -FINSH_FUNCTION_EXPORT(list_udps, list all of udp connections); -#endif /* LWIP_UDP */ - -#endif diff --git a/components/net/lwip/lwip-2.1.2/SConscript b/components/net/lwip/lwip-2.1.2/SConscript index 04f59167d5..4c5fba2054 100644 --- a/components/net/lwip/lwip-2.1.2/SConscript +++ b/components/net/lwip/lwip-2.1.2/SConscript @@ -23,14 +23,14 @@ src/core/timeouts.c src/core/udp.c """) -# 1.1 +# 1.1 lwipcore_altcp_SRCS = Split(""" src/core/altcp.c src/core/altcp_alloc.c src/core/altcp_tcp.c """) -# 1.2 +# 1.2 lwipcore4_SRCS = Split(""" src/core/ipv4/autoip.c src/core/ipv4/dhcp.c @@ -42,7 +42,7 @@ src/core/ipv4/ip4.c src/core/ipv4/ip4_addr.c """) -# 1.3 +# 1.3 lwipcore6_SRCS = Split(""" src/core/ipv6/dhcp6.c src/core/ipv6/ethip6.c @@ -71,7 +71,6 @@ src/api/tcpip.c # 3. Files implementing various generic network interface functions lwipnetif_SRCS = Split(""" src/netif/ethernet.c -src/netif/ethernetif.c """) # 3.1 Files implementing an IEEE 802.1D bridge by using a multilayer netif approach @@ -226,11 +225,8 @@ lwipping_SRCS = Split(""" src/apps/ping/ping.c """) -src = Split(""" -src/arch/sys_arch.c -""") - -src += lwipcore_SRCS # rm mem.c +src = [] +src += lwipcore_SRCS src += lwipcore_altcp_SRCS src += lwipapi_SRCS src += lwipnetif_SRCS @@ -240,7 +236,6 @@ src += lwipcore4_SRCS path = [cwd + '/src', cwd + '/src/include', - cwd + '/src/arch/include', cwd + '/src/include/netif'] if not GetDepend('RT_USING_SAL'): diff --git a/components/net/lwip/lwip-2.1.2/src/arch/include/arch/bpstruct.h b/components/net/lwip/lwip-2.1.2/src/arch/include/arch/bpstruct.h deleted file mode 100644 index 74ead358fa..0000000000 --- a/components/net/lwip/lwip-2.1.2/src/arch/include/arch/bpstruct.h +++ /dev/null @@ -1,35 +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(__ICCARM__) -#pragma pack(1) -#endif diff --git a/components/net/lwip/lwip-2.1.2/src/arch/include/arch/cc.h b/components/net/lwip/lwip-2.1.2/src/arch/include/arch/cc.h deleted file mode 100644 index e54b0a7ae7..0000000000 --- a/components/net/lwip/lwip-2.1.2/src/arch/include/arch/cc.h +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2001, 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. - * - * This file is part of the lwIP TCP/IP stack. - * - * Author: Adam Dunkels - * - * $Id: cc.h,v 1.1.1.1 2004/12/16 14:17:13 bear Exp $ - */ -#ifndef __ARCH_CC_H__ -#define __ARCH_CC_H__ - -#include -#include -#include - -#ifndef BYTE_ORDER -#ifdef ARCH_CPU_BIG_ENDIAN -#define BYTE_ORDER BIG_ENDIAN -#else -#define BYTE_ORDER LITTLE_ENDIAN -#endif /* ARCH_CPU_BIG_ENDIAN */ -#endif /* BYTE_ORDER */ - -#define U16_F "hu" -#define S16_F "hd" -#define X16_F "hx" -#define U32_F "lu" -#define S32_F "ld" -#define X32_F "lx" - -#include -/* some errno not defined in newlib */ -#ifndef ENSRNOTFOUND -#define ENSRNOTFOUND 163 /* Domain name not found */ -/* WARNING: ESHUTDOWN also not defined in newlib. We chose - 180 here because the number "108" which is used - in arch.h has been assigned to another error code. */ -#endif - -/* LWIP_TIMEVAL_PRIVATE: provided by */ -#include -#define LWIP_TIMEVAL_PRIVATE 0 - -#if defined(__CC_ARM) /* ARMCC compiler */ -#define PACK_STRUCT_FIELD(x) x -#define PACK_STRUCT_STRUCT __attribute__ ((__packed__)) -#define PACK_STRUCT_BEGIN -#define PACK_STRUCT_END -#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) /*Arm Compiler 6*/ -#define PACK_STRUCT_FIELD(x) x -#define PACK_STRUCT_STRUCT __attribute__((packed)) -#define PACK_STRUCT_BEGIN -#define PACK_STRUCT_END -#elif defined(__IAR_SYSTEMS_ICC__) /* IAR Compiler */ -#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(__GNUC__) /* GNU GCC Compiler */ -#define PACK_STRUCT_FIELD(x) x -#define PACK_STRUCT_STRUCT __attribute__((packed)) -#define PACK_STRUCT_BEGIN -#define PACK_STRUCT_END -#elif defined(_MSC_VER) -#define PACK_STRUCT_FIELD(x) x -#define PACK_STRUCT_STRUCT -#define PACK_STRUCT_BEGIN -#define PACK_STRUCT_END -#endif - -void sys_arch_assert(const char* file, int line); -#define LWIP_PLATFORM_DIAG(x) do {rt_kprintf x;} while(0) -#define LWIP_PLATFORM_ASSERT(x) do {rt_kprintf(x); sys_arch_assert(__FILE__, __LINE__);}while(0) - -#define SYS_ARCH_DECL_PROTECT(level) register rt_base_t level -#define SYS_ARCH_PROTECT(level) do {level = rt_hw_interrupt_disable();} while(0) -#define SYS_ARCH_UNPROTECT(level) do {rt_hw_interrupt_enable(level);} while(0) - -#endif /* __ARCH_CC_H__ */ diff --git a/components/net/lwip/lwip-2.1.2/src/arch/include/arch/epstruct.h b/components/net/lwip/lwip-2.1.2/src/arch/include/arch/epstruct.h deleted file mode 100644 index f6390959ea..0000000000 --- a/components/net/lwip/lwip-2.1.2/src/arch/include/arch/epstruct.h +++ /dev/null @@ -1,35 +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(__ICCARM__) -#pragma pack() -#endif diff --git a/components/net/lwip/lwip-2.1.2/src/include/netif/ethernetif.h b/components/net/lwip/lwip-2.1.2/src/include/netif/ethernetif.h deleted file mode 100644 index 6d5044b1b7..0000000000 --- a/components/net/lwip/lwip-2.1.2/src/include/netif/ethernetif.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef __NETIF_ETHERNETIF_H__ -#define __NETIF_ETHERNETIF_H__ - -#include "lwip/netif.h" -#include - -#define NIOCTL_GADDR 0x01 -#ifndef RT_LWIP_ETH_MTU -#define ETHERNET_MTU 1500 -#else -#define ETHERNET_MTU RT_LWIP_ETH_MTU -#endif - -/* eth flag with auto_linkup or phy_linkup */ -#define ETHIF_LINK_AUTOUP 0x0000 -#define ETHIF_LINK_PHYUP 0x0100 - -struct eth_device -{ - /* inherit from rt_device */ - struct rt_device parent; - - /* network interface for lwip */ - struct netif *netif; - - rt_uint16_t flags; - rt_uint8_t link_changed; - rt_uint8_t link_status; - rt_uint8_t rx_notice; - - /* eth device interface */ - struct pbuf* (*eth_rx)(rt_device_t dev); - rt_err_t (*eth_tx)(rt_device_t dev, struct pbuf* p); -}; - -#ifdef __cplusplus -extern "C" { -#endif - - rt_err_t eth_device_ready(struct eth_device* dev); - rt_err_t eth_device_init(struct eth_device * dev, const char *name); - rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_uint16_t flag); - rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up); - void eth_device_deinit(struct eth_device *dev); - - int eth_system_device_init(void); - -#ifdef __cplusplus -} -#endif - -#endif /* __NETIF_ETHERNETIF_H__ */ diff --git a/components/net/lwip/port/SConscript b/components/net/lwip/port/SConscript new file mode 100644 index 0000000000..c2ca3678a4 --- /dev/null +++ b/components/net/lwip/port/SConscript @@ -0,0 +1,10 @@ +from building import * + +cwd = GetCurrentDir() +path = [cwd] + +src = Glob('*.c') + +group = DefineGroup('lwIP', src, depend = ['RT_USING_LWIP'], CPPPATH = path) + +Return('group') diff --git a/components/net/lwip/port/arch/bpstruct.h b/components/net/lwip/port/arch/bpstruct.h new file mode 100644 index 0000000000..9ca70cff7f --- /dev/null +++ b/components/net/lwip/port/arch/bpstruct.h @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2006-2022, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2022-02-20 Meco Man add RT-Thread copyright + */ + +#if defined(__ICCARM__) +#pragma pack(1) +#endif diff --git a/components/net/lwip/lwip-1.4.1/src/arch/include/arch/cc.h b/components/net/lwip/port/arch/cc.h similarity index 93% rename from components/net/lwip/lwip-1.4.1/src/arch/include/arch/cc.h rename to components/net/lwip/port/arch/cc.h index 4679777257..d62c97df54 100644 --- a/components/net/lwip/lwip-1.4.1/src/arch/include/arch/cc.h +++ b/components/net/lwip/port/arch/cc.h @@ -1,3 +1,13 @@ +/* + * Copyright (c) 2006-2022, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2022-02-20 Meco Man add RT-Thread copyright + */ + /* * Copyright (c) 2001, Swedish Institute of Computer Science. * All rights reserved. @@ -37,8 +47,6 @@ #include #include -#include -#include #ifndef BYTE_ORDER #ifdef ARCH_CPU_BIG_ENDIAN @@ -48,6 +56,8 @@ #endif /* ARCH_CPU_BIG_ENDIAN */ #endif /* BYTE_ORDER */ +#ifdef RT_USING_LWIP141 +#include typedef uint8_t u8_t; typedef int8_t s8_t; typedef uint16_t u16_t; @@ -62,6 +72,7 @@ typedef uintptr_t mem_ptr_t; #define U32_F "lu" #define S32_F "ld" #define X32_F "lx" +#endif /* RT_USING_LWIP141 */ #include /* some errno not defined in newlib */ diff --git a/components/net/lwip/port/arch/epstruct.h b/components/net/lwip/port/arch/epstruct.h new file mode 100644 index 0000000000..a7ed4f4a26 --- /dev/null +++ b/components/net/lwip/port/arch/epstruct.h @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2006-2022, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2022-02-20 Meco Man add RT-Thread copyright + */ + +#if defined(__ICCARM__) +#pragma pack() +#endif diff --git a/components/net/lwip/lwip-2.1.2/src/arch/include/arch/perf.h b/components/net/lwip/port/arch/perf.h similarity index 82% rename from components/net/lwip/lwip-2.1.2/src/arch/include/arch/perf.h rename to components/net/lwip/port/arch/perf.h index 675f1f65dc..4b7720ef40 100644 --- a/components/net/lwip/lwip-2.1.2/src/arch/include/arch/perf.h +++ b/components/net/lwip/port/arch/perf.h @@ -1,33 +1,33 @@ /* * Copyright (c) 2001, Swedish Institute of Computer Science. - * All rights reserved. + * 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 Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * 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 Institute 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 INSTITUTE 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 INSTITUTE 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. + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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. * * This file is part of the lwIP TCP/IP stack. - * + * * Author: Adam Dunkels * * $Id: perf.h,v 1.1.1.1 2004/12/16 14:17:13 bear Exp $ @@ -42,8 +42,8 @@ /* void perf_print(unsigned long c1l, unsigned long c1h, - unsigned long c2l, unsigned long c2h, - char *key); + unsigned long c2l, unsigned long c2h, + char *key); void perf_print_times(struct tms *start, struct tms *end, char *key); diff --git a/components/net/lwip/lwip-2.1.2/src/arch/include/arch/sys_arch.h b/components/net/lwip/port/arch/sys_arch.h similarity index 91% rename from components/net/lwip/lwip-2.1.2/src/arch/include/arch/sys_arch.h rename to components/net/lwip/port/arch/sys_arch.h index e487f58211..99b193ea65 100644 --- a/components/net/lwip/lwip-2.1.2/src/arch/include/arch/sys_arch.h +++ b/components/net/lwip/port/arch/sys_arch.h @@ -1,3 +1,13 @@ +/* + * Copyright (c) 2006-2022, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2022-02-20 Meco Man add RT-Thread copyright + */ + /* * Copyright (c) 2001, Swedish Institute of Computer Science. * All rights reserved. @@ -54,6 +64,4 @@ typedef rt_mutex_t sys_mutex_t; typedef rt_mailbox_t sys_mbox_t; typedef rt_thread_t sys_thread_t; -// err_t sys_mbox_trypost_fromisr(sys_mbox_t *q, void *msg); - #endif /* __ARCH_SYS_ARCH_H__ */ diff --git a/components/net/lwip/lwip-2.1.2/src/netif/ethernetif.c b/components/net/lwip/port/ethernetif.c similarity index 90% rename from components/net/lwip/lwip-2.1.2/src/netif/ethernetif.c rename to components/net/lwip/port/ethernetif.c index aeb2678869..76ea3a6472 100644 --- a/components/net/lwip/lwip-2.1.2/src/netif/ethernetif.c +++ b/components/net/lwip/port/ethernetif.c @@ -1,6 +1,24 @@ +/* + * Copyright (c) 2006-2022, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2010-07-07 Bernard fix send mail to mailbox issue. + * 2011-07-30 mbbill port lwIP 1.4.0 to RT-Thread + * 2012-04-10 Bernard add more compatible with RT-Thread. + * 2012-11-12 Bernard The network interface can be initialized + * after lwIP initialization. + * 2013-02-28 aozima fixed list_tcps bug: ipaddr_ntoa isn't reentrant. + * 2016-08-18 Bernard port to lwIP 2.0.0 + * 2018-11-02 MurphyZhao port to lwIP 2.1.0 + * 2021-09-07 Grissiom fix eth_tx_msg ack bug + * 2022-02-22 xiangxistu integrate v1.4.1 v2.0.3 and v2.1.2 porting layer + */ + /* * Copyright (c) 2001-2004 Swedish Institute of Computer Science. - * COPYRIGHT (C) 2006-2021, RT-Thread Development Team * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -28,36 +46,25 @@ * This file is part of the lwIP TCP/IP stack. * * Author: Adam Dunkels - * - * Change Logs: - * Date Author Notes - * 2010-07-07 Bernard fix send mail to mailbox issue. - * 2011-07-30 mbbill port lwIP 1.4.0 to RT-Thread - * 2012-04-10 Bernard add more compatible with RT-Thread. - * 2012-11-12 Bernard The network interface can be initialized - * after lwIP initialization. - * 2013-02-28 aozima fixed list_tcps bug: ipaddr_ntoa isn't reentrant. - * 2016-08-18 Bernard port to lwIP 2.0.0 - * 2018-11-02 MurphyZhao port to lwIP 2.1.0 - * 2021-09-07 Grissiom fix eth_tx_msg ack bug */ -#include "lwip/opt.h" -#include "lwip/debug.h" -#include "lwip/def.h" -#include "lwip/mem.h" -#include "lwip/pbuf.h" -#include "lwip/sys.h" -#include "lwip/netif.h" -#include "lwip/stats.h" -#include "lwip/tcpip.h" -#include "lwip/dhcp.h" -#include "lwip/netifapi.h" +#include -#include "netif/etharp.h" -#include "netif/ethernetif.h" - -#include "lwip/inet.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include @@ -88,10 +95,10 @@ struct eth_tx_msg static struct rt_mailbox eth_tx_thread_mb; static struct rt_thread eth_tx_thread; #ifndef RT_LWIP_ETHTHREAD_MBOX_SIZE -static char eth_tx_thread_mb_pool[32 * 4]; +static char eth_tx_thread_mb_pool[32 * sizeof(rt_ubase_t)]; static char eth_tx_thread_stack[512]; #else -static char eth_tx_thread_mb_pool[RT_LWIP_ETHTHREAD_MBOX_SIZE * 4]; +static char eth_tx_thread_mb_pool[RT_LWIP_ETHTHREAD_MBOX_SIZE * sizeof(rt_ubase_t)]; static char eth_tx_thread_stack[RT_LWIP_ETHTHREAD_STACKSIZE]; #endif #endif @@ -100,10 +107,10 @@ static char eth_tx_thread_stack[RT_LWIP_ETHTHREAD_STACKSIZE]; static struct rt_mailbox eth_rx_thread_mb; static struct rt_thread eth_rx_thread; #ifndef RT_LWIP_ETHTHREAD_MBOX_SIZE -static char eth_rx_thread_mb_pool[48 * 4]; +static char eth_rx_thread_mb_pool[48 * sizeof(rt_ubase_t)]; static char eth_rx_thread_stack[1024]; #else -static char eth_rx_thread_mb_pool[RT_LWIP_ETHTHREAD_MBOX_SIZE * 4]; +static char eth_rx_thread_mb_pool[RT_LWIP_ETHTHREAD_MBOX_SIZE * sizeof(rt_ubase_t)]; static char eth_rx_thread_stack[RT_LWIP_ETHTHREAD_STACKSIZE]; #endif #endif @@ -127,6 +134,9 @@ static int lwip_netdev_set_down(struct netdev *netif) return ERR_OK; } +#ifndef ip_2_ip4 +#define ip_2_ip4(ipaddr) (ipaddr) +#endif static int lwip_netdev_set_addr_info(struct netdev *netif, ip_addr_t *ip_addr, ip_addr_t *netmask, ip_addr_t *gw) { if (ip_addr && netmask && gw) @@ -157,7 +167,12 @@ static int lwip_netdev_set_addr_info(struct netdev *netif, ip_addr_t *ip_addr, i #ifdef RT_LWIP_DNS static int lwip_netdev_set_dns_server(struct netdev *netif, uint8_t dns_num, ip_addr_t *dns_server) { +#if LWIP_VERSION_MAJOR == 1U /* v1.x */ + extern void dns_setserver(u8_t numdns, ip_addr_t *dnsserver); +#else /* >=2.x */ extern void dns_setserver(uint8_t dns_num, const ip_addr_t *dns_server); +#endif /* LWIP_VERSION_MAJOR == 1U */ + dns_setserver(dns_num, dns_server); return ERR_OK; } @@ -192,10 +207,10 @@ int lwip_netdev_ping(struct netdev *netif, const char *host, size_t data_len, int s, ttl, recv_len, result = 0; int elapsed_time; rt_tick_t recv_start_tick; -#if LWIP_VERSION_MAJOR >= 2U - struct timeval recv_timeout = { timeout / RT_TICK_PER_SECOND, timeout % RT_TICK_PER_SECOND }; -#else +#if LWIP_VERSION_MAJOR == 1U /* v1.x */ int recv_timeout = timeout * 1000UL / RT_TICK_PER_SECOND; +#else /* >= v2.x */ + struct timeval recv_timeout = { timeout / RT_TICK_PER_SECOND, timeout % RT_TICK_PER_SECOND }; #endif ip_addr_t target_addr; struct addrinfo hint, *res = RT_NULL; @@ -320,6 +335,50 @@ const struct netdev_ops lwip_netdev_ops = lwip_netdev_set_default, }; +/* synchronize lwIP network interface device and network interface device flags */ +static int netdev_flags_sync(struct netif *lwip_netif) +{ + struct netdev *netdev = NULL; + + RT_ASSERT(lwip_netif); + + netdev = netdev_get_by_name(lwip_netif->name); + if (netdev == RT_NULL) + { + return -ERR_IF; + } + + netdev->mtu = lwip_netif->mtu; + + /* the macro definition is different from lwip-1.4.1 and lwip-2.x.x about 'flags'. */ + if(lwip_netif->flags & NETIF_FLAG_BROADCAST) + { + netdev->flags |= NETDEV_FLAG_BROADCAST; + } + if(lwip_netif->flags & NETIF_FLAG_ETHARP) + { + netdev->flags |= NETDEV_FLAG_ETHARP; + } + if(lwip_netif->flags & NETIF_FLAG_IGMP) + { + netdev->flags |= NETDEV_FLAG_IGMP; + } +#if LWIP_VERSION_MAJOR >= 2U /* >= v2.x */ + if(lwip_netif->flags & NETIF_FLAG_MLD6) + { + netdev->flags |= NETDEV_FLAG_MLD6; + } +#endif /* LWIP_VERSION_MAJOR >= 2U */ + +#if LWIP_DHCP + netdev_low_level_set_dhcp_status(netdev, RT_TRUE); +#else + netdev_low_level_set_dhcp_status(netdev, RT_FALSE); +#endif + + return ERR_OK; +} + static int netdev_add(struct netif *lwip_netif) { #define LWIP_NETIF_NAME_LEN 2 @@ -345,8 +404,7 @@ static int netdev_add(struct netif *lwip_netif) result = netdev_register(netdev, name, (void *)lwip_netif); /* Update netdev info after registered */ - netdev->flags = lwip_netif->flags; - netdev->mtu = lwip_netif->mtu; + netdev_flags_sync(lwip_netif); netdev->ops = &lwip_netdev_ops; netdev->hwaddr_len = lwip_netif->hwaddr_len; SMEMCPY(netdev->hwaddr, lwip_netif->hwaddr, lwip_netif->hwaddr_len); @@ -354,10 +412,6 @@ static int netdev_add(struct netif *lwip_netif) netdev->gw = lwip_netif->gw; netdev->netmask = lwip_netif->netmask; -#ifdef RT_LWIP_DHCP - netdev_low_level_set_dhcp_status(netdev, RT_TRUE); -#endif - return result; } @@ -373,25 +427,6 @@ static void netdev_del(struct netif *lwip_netif) netdev_unregister(netdev); rt_free(netdev); } - -/* synchronize lwIP network interface device and network interface device flags */ -static int netdev_flags_sync(struct netif *lwip_netif) -{ - struct netdev *netdev = NULL; - - RT_ASSERT(lwip_netif); - - netdev = netdev_get_by_name(lwip_netif->name); - if (netdev == RT_NULL) - { - return -ERR_IF; - } - - netdev->mtu = lwip_netif->mtu; - netdev->flags |= lwip_netif->flags; - - return ERR_OK; -} #endif /* RT_USING_NETDEV */ static err_t ethernetif_linkoutput(struct netif *netif, struct pbuf *p) @@ -479,14 +514,12 @@ static err_t eth_netif_device_init(struct netif *netif) if (netif_default == RT_NULL) netif_set_default(ethif->netif); -#if LWIP_DHCP /* set interface up */ netif_set_up(ethif->netif); + +#if LWIP_DHCP /* if this interface uses DHCP, start the DHCP client */ dhcp_start(ethif->netif); -#else - /* set interface up */ - netif_set_up(ethif->netif); #endif if (ethif->flags & ETHIF_LINK_PHYUP) @@ -495,6 +528,11 @@ static err_t eth_netif_device_init(struct netif *netif) netif_set_link_up(ethif->netif); } +#ifdef RT_USING_NETDEV + /* network interface device flags synchronize */ + netdev_flags_sync(netif); +#endif /* RT_USING_NETDEV */ + return ERR_OK; } @@ -520,7 +558,6 @@ rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_ /* set netif */ dev->netif = netif; - /* device flags, which will be set to netif flags when initializing */ dev->flags = flags; /* link changed status of device */ dev->link_changed = 0x00; @@ -555,7 +592,11 @@ rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_ /* if tcp thread has been started up, we add this netif to the system */ if (rt_thread_find("tcpip") != RT_NULL) { +#if LWIP_VERSION_MAJOR == 1U /* v1.x */ + struct ip_addr ipaddr, netmask, gw; +#else /* >= v2.x */ ip4_addr_t ipaddr, netmask, gw; +#endif /* LWIP_VERSION_MAJOR == 1U */ #if !LWIP_DHCP ipaddr.addr = inet_addr(RT_LWIP_IPADDR); @@ -569,11 +610,6 @@ rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_ netifapi_netif_add(netif, &ipaddr, &netmask, &gw, dev, eth_netif_device_init, tcpip_input); } -#ifdef RT_USING_NETDEV - /* network interface device flags synchronize */ - netdev_flags_sync(netif); -#endif /* RT_USING_NETDEV */ - return RT_EOK; } @@ -766,7 +802,7 @@ int eth_system_device_init_private(void) #ifndef LWIP_NO_RX_THREAD /* initialize mailbox and create Ethernet Rx thread */ result = rt_mb_init(ð_rx_thread_mb, "erxmb", - ð_rx_thread_mb_pool[0], sizeof(eth_rx_thread_mb_pool)/4, + ð_rx_thread_mb_pool[0], sizeof(eth_rx_thread_mb_pool)/sizeof(rt_ubase_t), RT_IPC_FLAG_FIFO); RT_ASSERT(result == RT_EOK); @@ -782,7 +818,7 @@ int eth_system_device_init_private(void) #ifndef LWIP_NO_TX_THREAD /* initialize mailbox and create Ethernet Tx thread */ result = rt_mb_init(ð_tx_thread_mb, "etxmb", - ð_tx_thread_mb_pool[0], sizeof(eth_tx_thread_mb_pool)/4, + ð_tx_thread_mb_pool[0], sizeof(eth_tx_thread_mb_pool)/sizeof(rt_ubase_t), RT_IPC_FLAG_FIFO); RT_ASSERT(result == RT_EOK); @@ -800,8 +836,14 @@ int eth_system_device_init_private(void) void set_if(char* netif_name, char* ip_addr, char* gw_addr, char* nm_addr) { +#if LWIP_VERSION_MAJOR == 1U /* v1.x */ + struct ip_addr *ip; + struct ip_addr addr; +#else /* >= v2.x */ ip4_addr_t *ip; ip4_addr_t addr; +#endif /* LWIP_VERSION_MAJOR == 1U */ + struct netif * netif = netif_list; if(strlen(netif_name) > sizeof(netif->name)) @@ -823,22 +865,27 @@ void set_if(char* netif_name, char* ip_addr, char* gw_addr, char* nm_addr) } } +#if LWIP_VERSION_MAJOR == 1U /* v1.x */ + ip = (struct ip_addr *)&addr; +#else /* >= v2.x */ ip = (ip4_addr_t *)&addr; +#endif /* LWIP_VERSION_MAJOR == 1U */ + /* set ip address */ - if ((ip_addr != RT_NULL) && ip4addr_aton(ip_addr, &addr)) + if ((ip_addr != RT_NULL) && inet_aton(ip_addr, &addr)) { netif_set_ipaddr(netif, ip); } /* set gateway address */ - if ((gw_addr != RT_NULL) && ip4addr_aton(gw_addr, &addr)) + if ((gw_addr != RT_NULL) && inet_aton(gw_addr, &addr)) { netif_set_gw(netif, ip); } /* set netmask address */ - if ((nm_addr != RT_NULL) && ip4addr_aton(nm_addr, &addr)) + if ((nm_addr != RT_NULL) && inet_aton(nm_addr, &addr)) { netif_set_netmask(netif, ip); } @@ -922,13 +969,24 @@ void list_if(void) #if LWIP_DNS { +#if LWIP_VERSION_MAJOR == 1U /* v1.x */ + struct ip_addr ip_addr; + + for(index=0; index= v2.x */ const ip_addr_t *ip_addr; for(index=0; index +#if LWIP_VERSION_MAJOR == 1U /* v1.x */ +#include +#else /* >= v2.x */ #include +#endif /* LWIP_VERSION_MAJOR == 1U */ void list_tcps(void) { diff --git a/components/net/lwip/port/netif/ethernetif.h b/components/net/lwip/port/netif/ethernetif.h new file mode 100644 index 0000000000..53e34b6d25 --- /dev/null +++ b/components/net/lwip/port/netif/ethernetif.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2006-2022, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2022-02-22 liuxianliang integrate v1.4.1 v2.0.3 and v2.1.2 porting layer + */ + +#ifndef __NETIF_ETHERNETIF_H__ +#define __NETIF_ETHERNETIF_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "lwip/netif.h" +#include + +#define NIOCTL_GADDR 0x01 +#ifndef RT_LWIP_ETH_MTU +#define ETHERNET_MTU 1500 +#else +#define ETHERNET_MTU RT_LWIP_ETH_MTU +#endif + +/* eth flag with auto_linkup or phy_linkup */ +#define ETHIF_LINK_AUTOUP 0x0000 +#define ETHIF_LINK_PHYUP 0x0100 + +struct eth_device +{ + /* inherit from rt_device */ + struct rt_device parent; + + /* network interface for lwip */ + struct netif *netif; + + rt_uint16_t flags; + rt_uint8_t link_changed; + rt_uint8_t link_status; + rt_uint8_t rx_notice; + + /* eth device interface */ + struct pbuf* (*eth_rx)(rt_device_t dev); + rt_err_t (*eth_tx)(rt_device_t dev, struct pbuf* p); +}; + +int eth_system_device_init(void); +void eth_device_deinit(struct eth_device *dev); +rt_err_t eth_device_ready(struct eth_device* dev); +rt_err_t eth_device_init(struct eth_device * dev, const char *name); +rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_uint16_t flag); +rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up); + +#ifdef __cplusplus +} +#endif + +#endif /* __NETIF_ETHERNETIF_H__ */ diff --git a/components/net/lwip/lwip-2.1.2/src/arch/sys_arch.c b/components/net/lwip/port/sys_arch.c similarity index 72% rename from components/net/lwip/lwip-2.1.2/src/arch/sys_arch.c rename to components/net/lwip/port/sys_arch.c index b0bf76c98a..6cd23586c9 100644 --- a/components/net/lwip/lwip-2.1.2/src/arch/sys_arch.c +++ b/components/net/lwip/port/sys_arch.c @@ -1,167 +1,52 @@ /* - * COPYRIGHT (C) 2006-2021, RT-Thread Development Team - * All rights reserved. + * Copyright (c) 2006-2022, RT-Thread Development Team * - * 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. + * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes * 2012-12-8 Bernard add file header * export bsd socket symbol for RT-Thread Application Module - * 2017-11-15 Bernard add lock for init_done callback. - * 2018-11-02 MurphyZhao port to lwip2.1.0 + * 2013-05-25 Bernard port to v1.4.1 + * 2017-03-26 HuangXiHans port to v2.0.2 + * 2017-11-15 Bernard add lock for init_done callback + * 2018-11-02 MurphyZhao port to v2.1.0 + * 2020-06-20 liuxianliang port to v2.1.2 + * 2021-06-25 liuxianliang port to v2.0.3 + * 2022-01-18 Meco Man remove v2.0.2 + * 2022-02-20 Meco Man integrate v1.4.1 v2.0.3 and v2.1.2 porting layer */ #include #include -#include "lwip/sys.h" -#include "lwip/opt.h" -#include "lwip/stats.h" -#include "lwip/err.h" -#include "arch/sys_arch.h" -#include "lwip/debug.h" -#include "lwip/netif.h" -#include "lwip/netifapi.h" -#include "lwip/tcpip.h" -#include "netif/ethernetif.h" -#include "lwip/sio.h" -#include "lwip/init.h" -#include "lwip/dhcp.h" -#include "lwip/inet.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include -#include "netif/etharp.h" - -#include -#include - -/* - * Initialize the network interface device - * - * @return the operation status, ERR_OK on OK, ERR_IF on error - */ -static err_t netif_device_init(struct netif *netif) -{ - struct eth_device *ethif; - - ethif = (struct eth_device *)netif->state; - if (ethif != RT_NULL) - { - rt_device_t device; - - /* get device object */ - device = (rt_device_t) ethif; - if (rt_device_init(device) != RT_EOK) - { - return ERR_IF; - } - - /* copy device flags to netif flags */ - netif->flags = ethif->flags; - netif->mtu = ETHERNET_MTU; - - /* set output */ - netif->output = etharp_output; - - return ERR_OK; - } - - return ERR_IF; -} /* * Initialize the ethernetif layer and set network interface device up */ static void tcpip_init_done_callback(void *arg) { - rt_device_t device; - struct eth_device *ethif; - ip4_addr_t ipaddr, netmask, gw; - struct rt_list_node* node; - struct rt_object* object; - struct rt_object_information *information; - - LWIP_ASSERT("invalid arg.\n",arg); - - IP4_ADDR(&gw, 0,0,0,0); - IP4_ADDR(&ipaddr, 0,0,0,0); - IP4_ADDR(&netmask, 0,0,0,0); - - /* enter critical */ - rt_enter_critical(); - - /* for each network interfaces */ - information = rt_object_get_information(RT_Object_Class_Device); - RT_ASSERT(information != RT_NULL); - for (node = information->object_list.next; - node != &(information->object_list); - node = node->next) - { - object = rt_list_entry(node, struct rt_object, list); - device = (rt_device_t)object; - if (device->type == RT_Device_Class_NetIf) - { - ethif = (struct eth_device *)device; - - /* leave critical */ - rt_exit_critical(); - LOCK_TCPIP_CORE(); - - netif_add(ethif->netif, &ipaddr, &netmask, &gw, - ethif, netif_device_init, tcpip_input); - - if (netif_default == RT_NULL) - netif_set_default(ethif->netif); - -#if LWIP_DHCP - /* set interface up */ - netif_set_up(ethif->netif); - /* if this interface uses DHCP, start the DHCP client */ - dhcp_start(ethif->netif); -#else - /* set interface up */ - netif_set_up(ethif->netif); -#endif - - if (ethif->flags & ETHIF_LINK_PHYUP) - { - netif_set_link_up(ethif->netif); - } - - UNLOCK_TCPIP_CORE(); - /* enter critical */ - rt_enter_critical(); - } - } - - /* leave critical */ - rt_exit_critical(); rt_sem_release((rt_sem_t)arg); } /** * LwIP system initialization */ -extern int eth_system_device_init_private(void); int lwip_system_init(void) { rt_err_t rc; @@ -174,13 +59,13 @@ int lwip_system_init(void) return 0; } + extern int eth_system_device_init_private(void); eth_system_device_init_private(); /* set default netif to NULL */ netif_default = RT_NULL; rc = rt_sem_init(&done_sem, "done", 0, RT_IPC_FLAG_FIFO); - if (rc != RT_EOK) { LWIP_ASSERT("Failed to create semaphore", 0); @@ -199,19 +84,6 @@ int lwip_system_init(void) } rt_sem_detach(&done_sem); - /* set default ip address */ -#if !LWIP_DHCP - if (netif_default != RT_NULL) - { - struct ip4_addr ipaddr, netmask, gw; - - ipaddr.addr = inet_addr(RT_LWIP_IPADDR); - gw.addr = inet_addr(RT_LWIP_GWADDR); - netmask.addr = inet_addr(RT_LWIP_MSKADDR); - - netifapi_netif_set_addr(netif_default, &ipaddr, &netmask, &gw); - } -#endif rt_kprintf("lwIP-%d.%d.%d initialized!\n", LWIP_VERSION_MAJOR, LWIP_VERSION_MINOR, LWIP_VERSION_REVISION); init_ok = RT_TRUE; @@ -248,7 +120,9 @@ err_t sys_sem_new(sys_sem_t *sem, u8_t count) tmpsem = rt_sem_create(tname, count, RT_IPC_FLAG_FIFO); if (tmpsem == RT_NULL) + { return ERR_MEM; + } else { *sem = tmpsem; @@ -293,20 +167,24 @@ u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout) /* get the begin tick */ tick = rt_tick_get(); if (timeout == 0) + { t = RT_WAITING_FOREVER; + } else { /* convert msecond to os tick */ - if (timeout < (1000/RT_TICK_PER_SECOND)) + if (timeout < (1000 / RT_TICK_PER_SECOND)) t = 1; else - t = timeout / (1000/RT_TICK_PER_SECOND); + t = timeout / (1000 / RT_TICK_PER_SECOND); } ret = rt_sem_take(*sem, t); if (ret == -RT_ETIMEOUT) + { return SYS_ARCH_TIMEOUT; + } else { if (ret == RT_EOK) @@ -362,11 +240,12 @@ err_t sys_mutex_new(sys_mutex_t *mutex) tmpmutex = rt_mutex_create(tname, RT_IPC_FLAG_PRIO); if (tmpmutex == RT_NULL) + { return ERR_MEM; + } else { *mutex = tmpmutex; - return ERR_OK; } } @@ -378,7 +257,6 @@ void sys_mutex_lock(sys_mutex_t *mutex) { RT_DEBUG_NOT_IN_INTERRUPT; rt_mutex_take(*mutex, RT_WAITING_FOREVER); - return; } @@ -396,7 +274,6 @@ void sys_mutex_unlock(sys_mutex_t *mutex) void sys_mutex_free(sys_mutex_t *mutex) { RT_DEBUG_NOT_IN_INTERRUPT; - rt_mutex_delete(*mutex); } @@ -454,9 +331,7 @@ err_t sys_mbox_new(sys_mbox_t *mbox, int size) void sys_mbox_free(sys_mbox_t *mbox) { RT_DEBUG_NOT_IN_INTERRUPT; - rt_mb_delete(*mbox); - return; } @@ -468,9 +343,7 @@ void sys_mbox_free(sys_mbox_t *mbox) void sys_mbox_post(sys_mbox_t *mbox, void *msg) { RT_DEBUG_NOT_IN_INTERRUPT; - rt_mb_send_wait(*mbox, (rt_ubase_t)msg, RT_WAITING_FOREVER); - return; } @@ -482,16 +355,19 @@ void sys_mbox_post(sys_mbox_t *mbox, void *msg) err_t sys_mbox_trypost(sys_mbox_t *mbox, void *msg) { if (rt_mb_send(*mbox, (rt_ubase_t)msg) == RT_EOK) + { return ERR_OK; + } return ERR_MEM; } -err_t -sys_mbox_trypost_fromisr(sys_mbox_t *q, void *msg) +#if (LWIP_VERSION_MAJOR * 100 + LWIP_VERSION_MINOR) >= 201 /* >= v2.1.0 */ +err_t sys_mbox_trypost_fromisr(sys_mbox_t *q, void *msg) { return sys_mbox_trypost(q, msg); } +#endif /* (LWIP_VERSION_MAJOR * 100 + LWIP_VERSION_MINOR) >= 201 */ /** Wait for a new message to arrive in the mbox * @param mbox mbox to get a message from @@ -513,14 +389,16 @@ u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout) tick = rt_tick_get(); if(timeout == 0) + { t = RT_WAITING_FOREVER; + } else { /* convirt msecond to os tick */ - if (timeout < (1000/RT_TICK_PER_SECOND)) + if (timeout < (1000 / RT_TICK_PER_SECOND)) t = 1; else - t = timeout / (1000/RT_TICK_PER_SECOND); + t = timeout / (1000 / RT_TICK_PER_SECOND); } ret = rt_mb_recv(*mbox, (rt_ubase_t *)msg, t); @@ -561,9 +439,10 @@ u32_t sys_arch_mbox_tryfetch(sys_mbox_t *mbox, void **msg) int ret; ret = rt_mb_recv(*mbox, (rt_ubase_t *)msg, 0); - if(ret == -RT_ETIMEOUT) + { return SYS_ARCH_TIMEOUT; + } else { if (ret == RT_EOK) @@ -622,19 +501,13 @@ sys_thread_t sys_thread_new(const char *name, sys_prot_t sys_arch_protect(void) { rt_base_t level; - - /* disable interrupt */ - level = rt_hw_interrupt_disable(); - + level = rt_hw_interrupt_disable(); /* disable interrupt */ return level; } void sys_arch_unprotect(sys_prot_t pval) { - /* enable interrupt */ - rt_hw_interrupt_enable(pval); - - return; + rt_hw_interrupt_enable(pval); /* enable interrupt */ } void sys_arch_assert(const char *file, int line) @@ -654,76 +527,8 @@ u32_t sys_now(void) return rt_tick_get_millisecond(); } -#if MEM_OVERFLOW_CHECK || MEMP_OVERFLOW_CHECK -/** - * Check if a mep element was victim of an overflow or underflow - * (e.g. the restricted area after/before it has been altered) - * - * @param p the mem element to check - * @param size allocated size of the element - * @param descr1 description of the element source shown on error - * @param descr2 description of the element source shown on error - */ -void -mem_overflow_check_raw(void *p, size_t size, const char *descr1, const char *descr2) -{ -#if MEM_SANITY_REGION_AFTER_ALIGNED || MEM_SANITY_REGION_BEFORE_ALIGNED - u16_t k; - u8_t *m; - -#if MEM_SANITY_REGION_AFTER_ALIGNED > 0 - m = (u8_t *)p + size; - for (k = 0; k < MEM_SANITY_REGION_AFTER_ALIGNED; k++) { - if (m[k] != 0xcd) { - char errstr[128]; - snprintf(errstr, sizeof(errstr), "detected mem overflow in %s%s", descr1, descr2); - LWIP_ASSERT(errstr, 0); - } - } -#endif /* MEM_SANITY_REGION_AFTER_ALIGNED > 0 */ - -#if MEM_SANITY_REGION_BEFORE_ALIGNED > 0 - m = (u8_t *)p - MEM_SANITY_REGION_BEFORE_ALIGNED; - for (k = 0; k < MEM_SANITY_REGION_BEFORE_ALIGNED; k++) { - if (m[k] != 0xcd) { - char errstr[128]; - snprintf(errstr, sizeof(errstr), "detected mem underflow in %s%s", descr1, descr2); - LWIP_ASSERT(errstr, 0); - } - } -#endif /* MEM_SANITY_REGION_BEFORE_ALIGNED > 0 */ -#else - LWIP_UNUSED_ARG(p); - LWIP_UNUSED_ARG(desc); - LWIP_UNUSED_ARG(descr); -#endif -} - -/** - * Initialize the restricted area of a mem element. - */ -void -mem_overflow_init_raw(void *p, size_t size) -{ -#if MEM_SANITY_REGION_BEFORE_ALIGNED > 0 || MEM_SANITY_REGION_AFTER_ALIGNED > 0 - u8_t *m; -#if MEM_SANITY_REGION_BEFORE_ALIGNED > 0 - m = (u8_t *)p - MEM_SANITY_REGION_BEFORE_ALIGNED; - memset(m, 0xcd, MEM_SANITY_REGION_BEFORE_ALIGNED); -#endif -#if MEM_SANITY_REGION_AFTER_ALIGNED > 0 - m = (u8_t *)p + size; - memset(m, 0xcd, MEM_SANITY_REGION_AFTER_ALIGNED); -#endif -#else /* MEM_SANITY_REGION_BEFORE_ALIGNED > 0 || MEM_SANITY_REGION_AFTER_ALIGNED > 0 */ - LWIP_UNUSED_ARG(p); - LWIP_UNUSED_ARG(desc); -#endif /* MEM_SANITY_REGION_BEFORE_ALIGNED > 0 || MEM_SANITY_REGION_AFTER_ALIGNED > 0 */ -} -#endif /* MEM_OVERFLOW_CHECK || MEMP_OVERFLOW_CHECK */ - -RT_WEAK -void mem_init(void) +#if LWIP_VERSION_MAJOR >= 2U /* >= v2.x */ +RT_WEAK void mem_init(void) { } @@ -748,6 +553,7 @@ void mem_free(void *mem) { rt_free(mem); } +#endif /* LWIP_VERSION_MAJOR >= 2U */ #ifdef RT_LWIP_PPP u32_t sio_read(sio_fd_t fd, u8_t *buf, u32_t size) @@ -766,7 +572,6 @@ u32_t sio_read(sio_fd_t fd, u8_t *buf, u32_t size) u32_t sio_write(sio_fd_t fd, u8_t *buf, u32_t size) { RT_ASSERT(fd != RT_NULL); - return rt_device_write((rt_device_t)fd, 0, buf, size); } @@ -786,7 +591,74 @@ void ppp_trace(int level, const char *format, ...) rt_device_write((rt_device_t)rt_console_get_device(), 0, rt_log_buf, length); va_end(args); } +#endif /* RT_LWIP_PPP */ + +#if (LWIP_VERSION_MAJOR * 100 + LWIP_VERSION_MINOR) >= 201 /* >= v2.1.0 */ +#if MEM_OVERFLOW_CHECK || MEMP_OVERFLOW_CHECK +/** + * Check if a mep element was victim of an overflow or underflow + * (e.g. the restricted area after/before it has been altered) + * + * @param p the mem element to check + * @param size allocated size of the element + * @param descr1 description of the element source shown on error + * @param descr2 description of the element source shown on error + */ +void mem_overflow_check_raw(void *p, size_t size, const char *descr1, const char *descr2) +{ +#if MEM_SANITY_REGION_AFTER_ALIGNED || MEM_SANITY_REGION_BEFORE_ALIGNED + u16_t k; + u8_t *m; + +#if MEM_SANITY_REGION_AFTER_ALIGNED > 0 + m = (u8_t *)p + size; + for (k = 0; k < MEM_SANITY_REGION_AFTER_ALIGNED; k++) { + if (m[k] != 0xcd) { + char errstr[128]; + rt_snprintf(errstr, sizeof(errstr), "detected mem overflow in %s%s", descr1, descr2); + LWIP_ASSERT(errstr, 0); + } + } +#endif /* MEM_SANITY_REGION_AFTER_ALIGNED > 0 */ + +#if MEM_SANITY_REGION_BEFORE_ALIGNED > 0 + m = (u8_t *)p - MEM_SANITY_REGION_BEFORE_ALIGNED; + for (k = 0; k < MEM_SANITY_REGION_BEFORE_ALIGNED; k++) { + if (m[k] != 0xcd) { + char errstr[128]; + rt_snprintf(errstr, sizeof(errstr), "detected mem underflow in %s%s", descr1, descr2); + LWIP_ASSERT(errstr, 0); + } + } +#endif /* MEM_SANITY_REGION_BEFORE_ALIGNED > 0 */ +#else + LWIP_UNUSED_ARG(p); + LWIP_UNUSED_ARG(desc); + LWIP_UNUSED_ARG(descr); +#endif /* MEM_SANITY_REGION_AFTER_ALIGNED || MEM_SANITY_REGION_BEFORE_ALIGNED */ +} + +/** + * Initialize the restricted area of a mem element. + */ +void mem_overflow_init_raw(void *p, size_t size) +{ +#if MEM_SANITY_REGION_BEFORE_ALIGNED > 0 || MEM_SANITY_REGION_AFTER_ALIGNED > 0 + u8_t *m; +#if MEM_SANITY_REGION_BEFORE_ALIGNED > 0 + m = (u8_t *)p - MEM_SANITY_REGION_BEFORE_ALIGNED; + rt_memset(m, 0xcd, MEM_SANITY_REGION_BEFORE_ALIGNED); #endif +#if MEM_SANITY_REGION_AFTER_ALIGNED > 0 + m = (u8_t *)p + size; + rt_memset(m, 0xcd, MEM_SANITY_REGION_AFTER_ALIGNED); +#endif +#else /* MEM_SANITY_REGION_BEFORE_ALIGNED > 0 || MEM_SANITY_REGION_AFTER_ALIGNED > 0 */ + LWIP_UNUSED_ARG(p); + LWIP_UNUSED_ARG(desc); +#endif /* MEM_SANITY_REGION_BEFORE_ALIGNED > 0 || MEM_SANITY_REGION_AFTER_ALIGNED > 0 */ +} +#endif /* MEM_OVERFLOW_CHECK || MEMP_OVERFLOW_CHECK */ #ifdef LWIP_HOOK_IP4_ROUTE_SRC struct netif *lwip_ip4_route_src(const ip4_addr_t *dest, const ip4_addr_t *src) @@ -813,10 +685,8 @@ struct netif *lwip_ip4_route_src(const ip4_addr_t *dest, const ip4_addr_t *src) return netif; } #endif /* LWIP_HOOK_IP4_ROUTE_SRC */ +#endif /* (LWIP_VERSION_MAJOR * 100 + LWIP_VERSION_MINOR) >= 201 */ -/* - * export bsd socket symbol for RT-Thread Application Module - */ #if LWIP_SOCKET #include RTM_EXPORT(lwip_accept); @@ -839,9 +709,12 @@ RTM_EXPORT(lwip_write); RTM_EXPORT(lwip_select); RTM_EXPORT(lwip_ioctl); RTM_EXPORT(lwip_fcntl); - RTM_EXPORT(lwip_htons); +RTM_EXPORT(lwip_ntohs); RTM_EXPORT(lwip_htonl); +RTM_EXPORT(lwip_ntohl); +RTM_EXPORT(ipaddr_aton); +RTM_EXPORT(ipaddr_ntoa); #if LWIP_DNS #include @@ -849,29 +722,28 @@ RTM_EXPORT(lwip_gethostbyname); RTM_EXPORT(lwip_gethostbyname_r); RTM_EXPORT(lwip_freeaddrinfo); RTM_EXPORT(lwip_getaddrinfo); -#endif - -#endif +#endif /* LWIP_DNS */ +#endif /* LWIP_SOCKET */ #if LWIP_DHCP #include RTM_EXPORT(dhcp_start); RTM_EXPORT(dhcp_renew); RTM_EXPORT(dhcp_stop); -#endif +#endif /* LWIP_DHCP */ #if LWIP_NETIF_API #include RTM_EXPORT(netifapi_netif_set_addr); -#endif +#endif /* LWIP_NETIF_API */ #if LWIP_NETIF_LINK_CALLBACK RTM_EXPORT(netif_set_link_callback); -#endif +#endif /* LWIP_NETIF_LINK_CALLBACK */ #if LWIP_NETIF_STATUS_CALLBACK RTM_EXPORT(netif_set_status_callback); -#endif +#endif /* LWIP_NETIF_STATUS_CALLBACK */ RTM_EXPORT(netif_find); RTM_EXPORT(netif_set_addr);