From 3d4f7e20af013ab56221a41f1bf5b68e56398e30 Mon Sep 17 00:00:00 2001 From: Zhang Jun Hao Date: Tue, 8 May 2018 16:45:52 +0800 Subject: [PATCH] feat(lwip): Optimize the configuration options for lwip --- components/lwip/Kconfig | 730 ++++++++++-------- components/lwip/apps/dhcpserver/dhcpserver.c | 3 +- .../include/lwip/apps/dhcpserver/dhcpserver.h | 5 +- components/lwip/include/lwip/port/lwipopts.h | 28 +- components/tcpip_adapter/tcpip_adapter_wifi.c | 24 +- 5 files changed, 458 insertions(+), 332 deletions(-) diff --git a/components/lwip/Kconfig b/components/lwip/Kconfig index 7119a53e..6e04e8fa 100755 --- a/components/lwip/Kconfig +++ b/components/lwip/Kconfig @@ -1,9 +1,432 @@ menu "LWIP" +menu "ARP" + +config LWIP_ARP_TABLE_SIZE + int "Number of active MAC-IP address pairs cached" + range 1 16 + default 10 + +config LWIP_ARP_MAXAGE + int "The time an ARP entry stays valid after its last update" + range 100 65535 + default 300 + +endmenu # LWIP ARP + +menu "SOCKET" + +config LWIP_MAX_SOCKETS + int "Max number of open sockets" + range 1 16 + default 10 + help + Sockets take up a certain amount of memory, and allowing fewer + sockets to be open at the same time conserves memory. Specify + the maximum amount of sockets here. The valid value is from 1 + to 16. + +config LWIP_SO_REUSE + bool "Enable SO_REUSEADDR option" + default y + help + Enabling this option allows binding to a port which remains in + TIME_WAIT. + +config LWIP_SO_REUSE_RXTOALL + bool "SO_REUSEADDR copies broadcast/multicast to all matches" + depends on LWIP_SO_REUSE + default y + help + Enabling this option means that any incoming broadcast or multicast + packet will be copied to all of the local sockets that it matches + (may be more than one if SO_REUSEADDR is set on the socket.) + + This increases memory overhead as the packets need to be copied, + however they are only copied per matching socket. You can safely + disable it if you don't plan to receive broadcast or multicast + traffic on more than one socket at a time. + +config LWIP_SO_RCVBUF + bool "Enable SO_RCVBUF option" + default n + help + Enabling this option allows checking for available data on a netconn. + +config LWIP_SO_LINGER + bool "Enable SO_LINGER processing" + default n + +config LWIP_RECV_BUFSIZE_DEFAULT + int "The default value for recv_bufsize" + default 11680 + range 2920 11680 + +config LWIP_TCP_CLOSE_TIMEOUT_MS_DEFAULT + int "TCP socket/netconn close waits time to send the FIN" + default 10000 + range 10000 20000 + +endmenu # LWIP SOCKET + +config LWIP_IP_FRAG + bool "Enable fragment outgoing IP packets" + default n + help + Enabling this option allows fragmenting outgoing IP packets if their size + exceeds MTU. + +menuconfig LWIP_IP_REASSEMBLY + bool "Enable reassembly incoming fragmented IP packets" + default n + help + Enabling this option allows reassemblying incoming fragmented IP packets. + +config LWIP_IP_REASS_MAX_PBUFS + int "Total maximum amount of pbufs waiting to be reassembled" + default 10 + range 1 16 + +config LWIP_IP_SOF_BROADCAST + bool "Enable broadcast filter per pcb on udp and raw send operation" + default n + help + +config LWIP_IP_SOF_BROADCAST_RECV + bool "Enable the broadcast filter on recv operations" + default n + help + +menuconfig LWIP_ICMP + bool "ICMP" + default y + help + +config LWIP_MULTICAST_PING + bool "Respond to multicast pings" + default n + depends on LWIP_ICMP + +config LWIP_BROADCAST_PING + bool "Respond to broadcast pings" + default n + depends on LWIP_ICMP + +config LWIP_RAW + bool "Enable application layer to hook into the IP layer itself" + default n + +menu "DHCP" + +config LWIP_DHCP_DOES_ARP_CHECK + bool "DHCP: Perform ARP check on any offered address" + default y + help + Enabling this option performs a check (via ARP request) if the offered IP address + is not already in use by another host on the network. + +config LWIP_DHCP_MAX_NTP_SERVERS + int "Maximum number of NTP servers" + default 1 + range 1 8 + help + Set maximum number of NTP servers used by LwIP SNTP module. + First argument of sntp_setserver/sntp_setservername functions + is limited to this value. + +config LWIP_DHCPS_LEASE_UNIT + int "Multiplier for lease time, in seconds" + range 1 3600 + default 60 + help + The DHCP server is calculating lease time multiplying the sent + and received times by this number of seconds per unit. + The default is 60, that equals one minute. + +config LWIP_DHCPS_MAX_STATION_NUM + int "Maximum number of stations" + range 1 8 + default 8 + help + The maximum number of DHCP clients that are connected to the server. + After this number is exceeded, DHCP server removes of the oldest device + from it's address pool, without notification. + +endmenu #DHCP + +menuconfig LWIP_AUTOIP + bool "Enable IPV4 Link-Local Addressing (AUTOIP)" + default n + help + Enabling this option allows the device to self-assign an address + in the 169.256/16 range if none is assigned statically or via DHCP. + + See RFC 3927. + +config LWIP_DHCP_AUTOIP_COOP_TRIES + int "DHCP Probes before self-assigning IPv4 LL address" + range 1 100 + default 2 + depends on LWIP_AUTOIP + help + DHCP client will send this many probes before self-assigning a + link local address. + + From LWIP help: "This can be set as low as 1 to get an AutoIP + address very quickly, but you should be prepared to handle a + changing IP address when DHCP overrides AutoIP." + +config LWIP_IGMP + bool "Enable IGMP module" + default y + +config DNS_MAX_SERVERS + int "The maximum of DNS servers" + range 1 5 + default 2 + +menuconfig LWIP_NETIF_LOOPBACK + bool "Enable per-interface loopback" + default n + help + Enabling this option means that if a packet is sent with a destination + address equal to the interface's own IP address, it will "loop back" and + be received by this interface. + +config LWIP_LOOPBACK_MAX_PBUFS + int "Max queued loopback packets per interface" + range 0 16 + default 0 + depends on LWIP_NETIF_LOOPBACK + help + Configure the maximum number of packets which can be queued for + loopback on a given interface. Reducing this number may cause packets + to be dropped, but will avoid filling memory with queued packet data. + +menu "TCP" + +config LWIP_MAX_ACTIVE_TCP + int "Maximum active TCP Connections" + range 1 32 + default 5 + help + The maximum number of simultaneously active TCP + connections. The practical maximum limit is + determined by available heap memory at runtime. + + Changing this value by itself does not substantially + change the memory usage of LWIP, except for preventing + new TCP connections after the limit is reached. + +config LWIP_MAX_LISTENING_TCP + int "Maximum listening TCP Connections" + range 1 16 + default 8 + help + The maximum number of simultaneously listening TCP + connections. The practical maximum limit is + determined by available heap memory at runtime. + + Changing this value by itself does not substantially + change the memory usage of LWIP, except for preventing + new listening TCP connections after the limit is reached. + + +config TCP_MAXRTX + int "Maximum number of retransmissions of data segments" + default 12 + range 3 12 + help + Set maximum number of retransmissions of data segments. + +config TCP_SYNMAXRTX + int "Maximum number of retransmissions of SYN segments" + default 6 + range 3 12 + help + Set maximum number of retransmissions of SYN segments. + +config TCP_MSS + int "Maximum Segment Size (MSS)" + default 1460 + range 536 1460 + help + Set maximum segment size for TCP transmission. + + Can be set lower to save RAM, the default value 1436 will give best throughput. + +config TCP_SND_BUF_DEFAULT + int "Default send buffer size" + default 2920 # 2 * default MSS + range 2920 11680 + help + Set default send buffer size for new TCP sockets. + + Per-socket send buffer size can be changed at runtime + with lwip_setsockopt(s, TCP_SNDBUF, ...). + + This value must be at least 2x the MSS size, and the default + is 4x the default MSS size. + + Setting a smaller default SNDBUF size can save some RAM, but + will decrease performance. + +config TCP_WND_DEFAULT + int "Default receive window size" + default 5840 # 4 * default MSS + range 2920 11680 + help + Set default TCP receive window size for new TCP sockets. + + Per-socket receive window size can be changed at runtime + with lwip_setsockopt(s, TCP_WINDOW, ...). + + Setting a smaller default receive window size can save some RAM, + but will significantly decrease performance. + +config TCP_RECVMBOX_SIZE + int "Default TCP receive mail box size" + default 6 + range 6 32 + help + Set TCP receive mail box size. Generally bigger value means higher throughput + but more memory. The recommended value is: TCP_WND_DEFAULT/TCP_MSS + 2, e.g. if + TCP_WND_DEFAULT=14360, TCP_MSS=1436, then the recommended receive mail box size is + (14360/1436 + 2) = 12. + + TCP receive mail box is a per socket mail box, when the application receives packets + from TCP socket, LWIP core firstly posts the packets to TCP receive mail box and the + application then fetches the packets from mail box. It means LWIP can caches maximum + TCP_RECCVMBOX_SIZE packets for each TCP socket, so the maximum possible cached TCP packets + for all TCP sockets is TCP_RECCVMBOX_SIZE multiples the maximum TCP socket number. In other + words, the bigger TCP_RECVMBOX_SIZE means more memory. + On the other hand, if the receiv mail box is too small, the mail box may be full. If the + mail box is full, the LWIP drops the packets. So generally we need to make sure the TCP + receive mail box is big enough to avoid packet drop between LWIP core and application. + +config TCP_QUEUE_OOSEQ + bool "Queue incoming out-of-order segments" + default n + help + Queue incoming out-of-order segments for later use. + + Disable this option to save some RAM during TCP sessions, at the expense + of increased retransmissions if segments arrive out of order. + +choice TCP_OVERSIZE + prompt "Pre-allocate transmit PBUF size" + default TCP_OVERSIZE_MSS + help + Allows enabling "oversize" allocation of TCP transmission pbufs ahead of time, + which can reduce the length of pbuf chains used for transmission. + + This will not make a difference to sockets where Nagle's algorithm + is disabled. + + Default value of MSS is fine for most applications, 25% MSS may save + some RAM when only transmitting small amounts of data. Disabled will + have worst performance and fragmentation characteristics, but uses + least RAM overall. + +config TCP_OVERSIZE_MSS + bool "MSS" +config TCP_OVERSIZE_QUARTER_MSS + bool "25% MSS" +config TCP_OVERSIZE_DISABLE + bool "Disabled" + +endchoice + +config LWIP_TCP_TIMESTAMPS + bool "Support the TCP timestamp option" + default n + help + The timestamp option is currently only used to help remote hosts, it is not + really used locally. Therefore, it is only enabled when a TS option is + received in the initial SYN packet from a remote host. + +endmenu # TCP + +menu "UDP" + +config LWIP_MAX_UDP_PCBS + int "Maximum active UDP control blocks" + range 1 32 + default 4 + help + The maximum number of active UDP "connections" (ie + UDP sockets sending/receiving data). + The practical maximum limit is determined by available + heap memory at runtime. + +config UDP_RECVMBOX_SIZE + int "Default UDP receive mail box size" + default 6 + range 6 64 + help + Set UDP receive mail box size. The recommended value is 6. + + UDP receive mail box is a per socket mail box, when the application receives packets + from UDP socket, LWIP core firstly posts the packets to UDP receive mail box and the + application then fetches the packets from mail box. It means LWIP can caches maximum + UDP_RECCVMBOX_SIZE packets for each UDP socket, so the maximum possible cached UDP packets + for all UDP sockets is UDP_RECCVMBOX_SIZE multiples the maximum UDP socket number. In other + words, the bigger UDP_RECVMBOX_SIZE means more memory. + On the other hand, if the receiv mail box is too small, the mail box may be full. If the + mail box is full, the LWIP drops the packets. So generally we need to make sure the UDP + receive mail box is big enough to avoid packet drop between LWIP core and application. + +endmenu # UDP + +config TCPIP_TASK_STACK_SIZE + int "TCP/IP Task Stack Size" + default 512 + range 512 2048 + help + Configure TCP/IP task stack size, used by LWIP to process multi-threaded TCP/IP operations. + Setting this stack too small will result in stack overflow crashes. + +menu "LWIP RAW API" + +config LWIP_MAX_RAW_PCBS + int "Maximum LWIP RAW PCBs" + range 1 32 + default 4 + help + The maximum number of simultaneously active LWIP + RAW protocol control blocks. The practical maximum + limit is determined by available heap memory at runtime. + +endmenu # LWIP RAW API + +menuconfig LWIP_IPV6 + bool "Enable IPv6" + default y + +config LWIP_IPV6_NUM_ADDRESSES + int "Number of IPv6 addresses per netif" + depends on LWIP_IPV6 + range 3 5 + default 3 + +config LWIP_IPV6_FORWARD + bool "Forward IPv6 packets across netifs" + depends on LWIP_IPV6 + default n + +config LWIP_IPV6_FRAG + bool "Fragment outgoing IPv6 packets that are too big" + depends on LWIP_IPV6 + default n + +config LWIP_STATS + bool "Enable statistics collection in lwip_stats" + default n + menuconfig LWIP_DEBUG bool "Enable lwip Debug" default n - + config LWIP_ETHARP_DEBUG bool "Enable debugging in etharp.c" depends on LWIP_DEBUG @@ -179,309 +602,4 @@ config LWIP_SNTP_DEBUG depends on LWIP_DEBUG default n -config LWIP_SO_REUSE - bool "Enable SO_REUSEADDR option" - default n - help - Enabling this option allows binding to a port which remains in - TIME_WAIT. - -config LWIP_SO_REUSE_RXTOALL - bool "SO_REUSEADDR copies broadcast/multicast to all matches" - depends on LWIP_SO_REUSE - default n - help - Enabling this option means that any incoming broadcast or multicast - packet will be copied to all of the local sockets that it matches - (may be more than one if SO_REUSEADDR is set on the socket.) - - This increases memory overhead as the packets need to be copied, - however they are only copied per matching socket. You can safely - disable it if you don't plan to receive broadcast or multicast - traffic on more than one socket at a time. - -config LWIP_SO_RCVBUF - bool "Enable SO_RCVBUF option" - default n - help - Enabling this option allows checking for available data on a netconn. - -config LWIP_DHCP_MAX_NTP_SERVERS - int "Maximum number of NTP servers" - default 1 - range 1 16 - help - Set maximum number of NTP servers used by LwIP SNTP module. - First argument of sntp_setserver/sntp_setservername functions - is limited to this value. - -config LWIP_IP_FRAG - bool "Enable fragment outgoing IP packets" - default n - help - Enabling this option allows fragmenting outgoing IP packets if their size - exceeds MTU. - -config LWIP_IP_REASSEMBLY - bool "Enable reassembly incoming fragmented IP packets" - default n - help - Enabling this option allows reassemblying incoming fragmented IP packets. - -config LWIP_STATS - bool "Enable LWIP statistics" - default n - help - Enabling this option allows LWIP statistics - -config LWIP_DHCP_DOES_ARP_CHECK - bool "DHCP: Perform ARP check on any offered address" - default y - help - Enabling this option performs a check (via ARP request) if the offered IP address - is not already in use by another host on the network. - -menuconfig LWIP_AUTOIP - bool "Enable IPV4 Link-Local Addressing (AUTOIP)" - default n - help - Enabling this option allows the device to self-assign an address - in the 169.256/16 range if none is assigned statically or via DHCP. - - See RFC 3927. - -config LWIP_DHCP_AUTOIP_COOP_TRIES - int "DHCP Probes before self-assigning IPv4 LL address" - range 1 100 - default 9 - depends on LWIP_AUTOIP - help - DHCP client will send this many probes before self-assigning a - link local address. - - From LWIP help: "This can be set as low as 1 to get an AutoIP - address very quickly, but you should be prepared to handle a - changing IP address when DHCP overrides AutoIP." - -menuconfig LWIP_NETIF_LOOPBACK - bool "Support per-interface loopback" - default n - help - Enabling this option means that if a packet is sent with a destination - address equal to the interface's own IP address, it will "loop back" and - be received by this interface. - -config LWIP_LOOPBACK_MAX_PBUFS - int "Max queued loopback packets per interface" - range 0 16 - default 0 - depends on LWIP_NETIF_LOOPBACK - help - Configure the maximum number of packets which can be queued for - loopback on a given interface. Reducing this number may cause packets - to be dropped, but will avoid filling memory with queued packet data. - -menu "TCP" - -config LWIP_MAX_ACTIVE_TCP - int "Maximum active TCP Connections" - range 1 1024 - default 5 - help - The maximum number of simultaneously active TCP - connections. The practical maximum limit is - determined by available heap memory at runtime. - - Changing this value by itself does not substantially - change the memory usage of LWIP, except for preventing - new TCP connections after the limit is reached. - -config LWIP_MAX_LISTENING_TCP - int "Maximum listening TCP Connections" - range 1 1024 - default 8 - help - The maximum number of simultaneously listening TCP - connections. The practical maximum limit is - determined by available heap memory at runtime. - - Changing this value by itself does not substantially - change the memory usage of LWIP, except for preventing - new listening TCP connections after the limit is reached. - - -config TCP_MAXRTX - int "Maximum number of retransmissions of data segments" - default 12 - range 3 12 - help - Set maximum number of retransmissions of data segments. - -config TCP_SYNMAXRTX - int "Maximum number of retransmissions of SYN segments" - default 6 - range 3 12 - help - Set maximum number of retransmissions of SYN segments. - -config TCP_MSS - int "Maximum Segment Size (MSS)" - default 1460 - range 536 1460 - help - Set maximum segment size for TCP transmission. - - Can be set lower to save RAM, the default value 1436 will give best throughput. - -config TCP_SND_BUF_DEFAULT - int "Default send buffer size" - default 2920 # 2 * default MSS - range 2920 65535 - help - Set default send buffer size for new TCP sockets. - - Per-socket send buffer size can be changed at runtime - with lwip_setsockopt(s, TCP_SNDBUF, ...). - - This value must be at least 2x the MSS size, and the default - is 4x the default MSS size. - - Setting a smaller default SNDBUF size can save some RAM, but - will decrease performance. - -config TCP_WND_DEFAULT - int "Default receive window size" - default 5840 # 4 * default MSS - range 2920 65535 - help - Set default TCP receive window size for new TCP sockets. - - Per-socket receive window size can be changed at runtime - with lwip_setsockopt(s, TCP_WINDOW, ...). - - Setting a smaller default receive window size can save some RAM, - but will significantly decrease performance. - -config TCP_RECVMBOX_SIZE - int "Default TCP receive mail box size" - default 6 - range 6 64 - help - Set TCP receive mail box size. Generally bigger value means higher throughput - but more memory. The recommended value is: TCP_WND_DEFAULT/TCP_MSS + 2, e.g. if - TCP_WND_DEFAULT=14360, TCP_MSS=1436, then the recommended receive mail box size is - (14360/1436 + 2) = 12. - - TCP receive mail box is a per socket mail box, when the application receives packets - from TCP socket, LWIP core firstly posts the packets to TCP receive mail box and the - application then fetches the packets from mail box. It means LWIP can caches maximum - TCP_RECCVMBOX_SIZE packets for each TCP socket, so the maximum possible cached TCP packets - for all TCP sockets is TCP_RECCVMBOX_SIZE multiples the maximum TCP socket number. In other - words, the bigger TCP_RECVMBOX_SIZE means more memory. - On the other hand, if the receiv mail box is too small, the mail box may be full. If the - mail box is full, the LWIP drops the packets. So generally we need to make sure the TCP - receive mail box is big enough to avoid packet drop between LWIP core and application. - -config TCP_QUEUE_OOSEQ - bool "Queue incoming out-of-order segments" - default n - help - Queue incoming out-of-order segments for later use. - - Disable this option to save some RAM during TCP sessions, at the expense - of increased retransmissions if segments arrive out of order. - -choice TCP_OVERSIZE - prompt "Pre-allocate transmit PBUF size" - default TCP_OVERSIZE_MSS - help - Allows enabling "oversize" allocation of TCP transmission pbufs ahead of time, - which can reduce the length of pbuf chains used for transmission. - - This will not make a difference to sockets where Nagle's algorithm - is disabled. - - Default value of MSS is fine for most applications, 25% MSS may save - some RAM when only transmitting small amounts of data. Disabled will - have worst performance and fragmentation characteristics, but uses - least RAM overall. - -config TCP_OVERSIZE_MSS - bool "MSS" -config TCP_OVERSIZE_QUARTER_MSS - bool "25% MSS" -config TCP_OVERSIZE_DISABLE - bool "Disabled" - -endchoice - -endmenu # TCP - -menu "UDP" - -config LWIP_MAX_UDP_PCBS - int "Maximum active UDP control blocks" - range 1 1024 - default 4 - help - The maximum number of active UDP "connections" (ie - UDP sockets sending/receiving data). - The practical maximum limit is determined by available - heap memory at runtime. - -config UDP_RECVMBOX_SIZE - int "Default UDP receive mail box size" - default 6 - range 6 64 - help - Set UDP receive mail box size. The recommended value is 6. - - UDP receive mail box is a per socket mail box, when the application receives packets - from UDP socket, LWIP core firstly posts the packets to UDP receive mail box and the - application then fetches the packets from mail box. It means LWIP can caches maximum - UDP_RECCVMBOX_SIZE packets for each UDP socket, so the maximum possible cached UDP packets - for all UDP sockets is UDP_RECCVMBOX_SIZE multiples the maximum UDP socket number. In other - words, the bigger UDP_RECVMBOX_SIZE means more memory. - On the other hand, if the receiv mail box is too small, the mail box may be full. If the - mail box is full, the LWIP drops the packets. So generally we need to make sure the UDP - receive mail box is big enough to avoid packet drop between LWIP core and application. - -endmenu # UDP - -config TCPIP_TASK_STACK_SIZE - int "TCP/IP Task Stack Size" - default 512 - # for high log levels, tcpip_adapter API calls can end up - # a few calls deep and logging there can trigger a stack overflow - range 2048 65536 if LOG_DEFAULT_LEVEL < 4 - range 2560 65536 if LOG_DEFAULT_LEVEL >= 4 - help - Configure TCP/IP task stack size, used by LWIP to process multi-threaded TCP/IP operations. - Setting this stack too small will result in stack overflow crashes. - -menu "ICMP" - -config LWIP_MULTICAST_PING - bool "Respond to multicast pings" - default n - -config LWIP_BROADCAST_PING - bool "Respond to broadcast pings" - default n - -endmenu # ICMP - -menu "LWIP RAW API" - -config LWIP_MAX_RAW_PCBS - int "Maximum LWIP RAW PCBs" - range 1 1024 - default 4 - help - The maximum number of simultaneously active LWIP - RAW protocol control blocks. The practical maximum - limit is determined by available heap memory at runtime. - -endmenu # LWIP RAW API - endmenu diff --git a/components/lwip/apps/dhcpserver/dhcpserver.c b/components/lwip/apps/dhcpserver/dhcpserver.c index 35119f9c..5f410718 100644 --- a/components/lwip/apps/dhcpserver/dhcpserver.c +++ b/components/lwip/apps/dhcpserver/dhcpserver.c @@ -13,6 +13,7 @@ // limitations under the License. #include "esp_common.h" +#include "sdkconfig.h" #include "lwip/inet.h" #include "lwip/err.h" #include "lwip/pbuf.h" @@ -41,7 +42,7 @@ static struct dhcps_lease dhcps_lease; static list_node* plist = NULL; static u8_t offer = 0xFF; static bool renew = false; -#define DHCPS_LEASE_TIME_DEF (120) +#define DHCPS_LEASE_TIME_DEF CONFIG_LWIP_DHCPS_LEASE_UNIT u32_t dhcps_lease_time = DHCPS_LEASE_TIME_DEF; //minute /****************************************************************************** * FunctionName : node_insert_to_list diff --git a/components/lwip/include/lwip/apps/dhcpserver/dhcpserver.h b/components/lwip/include/lwip/apps/dhcpserver/dhcpserver.h index 85cf84cf..30ba513f 100644 --- a/components/lwip/include/lwip/apps/dhcpserver/dhcpserver.h +++ b/components/lwip/include/lwip/apps/dhcpserver/dhcpserver.h @@ -3,6 +3,7 @@ #define USE_DNS +#include "sdkconfig.h" #include "esp_wifi.h" typedef struct dhcps_state { @@ -70,8 +71,8 @@ extern u32_t dhcps_lease_time; #define DHCP_OPTION_END 255 //#define USE_CLASS_B_NET 1 -#define DHCPS_DEBUG 0 -#define MAX_STATION_NUM 8 +#define DHCPS_DEBUG CONFIG_LWIP_DHCP_SERVER_DEBUG +#define MAX_STATION_NUM CONFIG_LWIP_DHCPS_MAX_STATION_NUM #define DHCPS_STATE_OFFER 1 #define DHCPS_STATE_DECLINE 2 diff --git a/components/lwip/include/lwip/port/lwipopts.h b/components/lwip/include/lwip/port/lwipopts.h index 3429c77d..1c1bc6b6 100644 --- a/components/lwip/include/lwip/port/lwipopts.h +++ b/components/lwip/include/lwip/port/lwipopts.h @@ -390,13 +390,13 @@ extern void vPortFree(void *pv, const char * file, unsigned line); /** * ARP_TABLE_SIZE: Number of active MAC-IP address pairs cached. */ -#define ARP_TABLE_SIZE 10 +#define ARP_TABLE_SIZE CONFIG_LWIP_ARP_TABLE_SIZE /** the time an ARP entry stays valid after its last update, * for ARP_TMR_INTERVAL = 1000, this is * (60 * 5) seconds = 5 minutes. */ -#define ARP_MAXAGE 300 +#define ARP_MAXAGE CONFIG_LWIP_ARP_MAXAGE /** * ARP_QUEUEING==1: Multiple outgoing packets are queued during hardware address @@ -506,7 +506,7 @@ extern void vPortFree(void *pv, const char * file, unsigned line); * PBUF_POOL_SIZE > IP_REASS_MAX_PBUFS so that the stack is still able to receive * packets even if the maximum amount of fragments is enqueued for reassembly! */ -#define IP_REASS_MAX_PBUFS 10 +#define IP_REASS_MAX_PBUFS CONFIG_LWIP_IP_REASS_MAX_PBUFS /** * IP_DEFAULT_TTL: Default value for Time-To-Live used by transport layers. @@ -518,13 +518,13 @@ extern void vPortFree(void *pv, const char * file, unsigned line); * filter per pcb on udp and raw send operations. To enable broadcast filter * on recv operations, you also have to set IP_SOF_BROADCAST_RECV=1. */ -#define IP_SOF_BROADCAST 0 +#define IP_SOF_BROADCAST CONFIG_LWIP_IP_SOF_BROADCAST /** * IP_SOF_BROADCAST_RECV (requires IP_SOF_BROADCAST=1) enable the broadcast * filter on recv operations. */ -#define IP_SOF_BROADCAST_RECV 0 +#define IP_SOF_BROADCAST_RECV CONFIG_LWIP_IP_SOF_BROADCAST_RECV /** * IP_FORWARD_ALLOW_TX_ON_RX_NETIF==1: allow ip_forward() to send packets back @@ -559,7 +559,7 @@ extern void vPortFree(void *pv, const char * file, unsigned line); * LWIP_ICMP==1: Enable ICMP module inside the IP stack. * Be careful, disable that make your product non-compliant to RFC1122 */ -#define LWIP_ICMP 1 +#define LWIP_ICMP CONFIG_LWIP_ICMP /** * ICMP_TTL: Default value for Time-To-Live used by ICMP packets. @@ -592,7 +592,7 @@ extern void vPortFree(void *pv, const char * file, unsigned line); /** * LWIP_RAW==1: Enable application layer to hook into the IP layer itself. */ -#define LWIP_RAW 0 +#define LWIP_RAW CONFIG_LWIP_RAW /** * LWIP_RAW==1: Enable application layer to hook into the IP layer itself. @@ -733,7 +733,7 @@ extern void vPortFree(void *pv, const char * file, unsigned line); /** * LWIP_IGMP==1: Turn on IGMP module. */ -#define LWIP_IGMP 1 +#define LWIP_IGMP CONFIG_LWIP_IGMP /** * LWIP_MULTICAST_TX_OPTIONS==1: Enable multicast TX support like the socket options @@ -770,7 +770,7 @@ extern void vPortFree(void *pv, const char * file, unsigned line); * The first server can be initialized automatically by defining * DNS_SERVER_ADDRESS(ipaddr), where 'ipaddr' is an 'ip_addr_t*' */ -#define DNS_MAX_SERVERS 2 +#define DNS_MAX_SERVERS CONFIG_DNS_MAX_SERVERS /** DNS do a name checking between the query and the response. */ #define DNS_DOES_NAME_CHECK 1 @@ -1405,17 +1405,17 @@ extern void vPortFree(void *pv, const char * file, unsigned line); /** * LWIP_SO_LINGER==1: Enable SO_LINGER processing. */ -#define LWIP_SO_LINGER 0 +#define LWIP_SO_LINGER CONFIG_LWIP_SO_LINGER /** * If LWIP_SO_RCVBUF is used, this is the default value for recv_bufsize. */ -#define RECV_BUFSIZE_DEFAULT INT_MAX +#define RECV_BUFSIZE_DEFAULT CONFIG_LWIP_RECV_BUFSIZE_DEFAULT /** * By default, TCP socket/netconn close waits 20 seconds max to send the FIN */ -#define LWIP_TCP_CLOSE_TIMEOUT_MS_DEFAULT 20000 +#define LWIP_TCP_CLOSE_TIMEOUT_MS_DEFAULT CONFIG_LWIP_TCP_CLOSE_TIMEOUT_MS_DEFAULT /** * SO_REUSE==1: Enable SO_REUSEADDR option. @@ -1671,12 +1671,12 @@ extern void vPortFree(void *pv, const char * file, unsigned line); /** * LWIP_IPV6==1: Enable IPv6 */ -#define LWIP_IPV6 1 +#define LWIP_IPV6 CONFIG_LWIP_IPV6 /** * LWIP_IPV6_NUM_ADDRESSES: Number of IPv6 addresses per netif. */ -#define LWIP_IPV6_NUM_ADDRESSES 3 +#define LWIP_IPV6_NUM_ADDRESSES CONFIG_LWIP_IPV6_NUM_ADDRESSES /** * LWIP_IPV6_FORWARD==1: Forward IPv6 packets across netifs diff --git a/components/tcpip_adapter/tcpip_adapter_wifi.c b/components/tcpip_adapter/tcpip_adapter_wifi.c index be948551..59f104a0 100644 --- a/components/tcpip_adapter/tcpip_adapter_wifi.c +++ b/components/tcpip_adapter/tcpip_adapter_wifi.c @@ -67,14 +67,15 @@ static void tcpip_adapter_dhcpc_done() if (clientdhcp->state == DHCP_STATE_BOUND) { /*send event here*/ system_station_got_ip_set(); - printf("ip:" IPSTR ",mask:" IPSTR ",gw:" IPSTR "\n", IP2STR(&(esp_netif[0]->ip_addr.u_addr.ip4)), - IP2STR(&(esp_netif[0]->netmask.u_addr.ip4)), IP2STR(&(esp_netif[0]->gw.u_addr.ip4))); + printf("ip:" IPSTR ",mask:" IPSTR ",gw:" IPSTR "\n", IP2STR(ip_2_ip4(&(esp_netif[0]->ip_addr))), + IP2STR(ip_2_ip4(&(esp_netif[0]->netmask))), IP2STR(ip_2_ip4(&(esp_netif[0]->gw)))); } else if (dhcp_fail_time < 100) { TCPIP_ATAPTER_LOG("dhcpc time(ms): %d\n", dhcp_fail_time * 200); dhcp_fail_time ++; os_timer_setfn(get_ip_timer, tcpip_adapter_dhcpc_done, NULL); os_timer_arm(get_ip_timer, 200, 1); } else { + extern void wifi_station_dhcpc_event(); wifi_station_dhcpc_event(); TCPIP_ATAPTER_LOG("ERROR dhcp get ip error\n"); free(get_ip_timer); @@ -255,8 +256,8 @@ void tcpip_adapter_start(uint8_t netif_index, bool authed) if (dhcps_flag) { dhcps_start(&esp_ip[TCPIP_ADAPTER_IF_AP]); printf("dhcp server start:("); - printf("ip:" IPSTR ",mask:" IPSTR ",gw:" IPSTR, IP2STR(&(esp_netif[TCPIP_ADAPTER_IF_AP]->ip_addr.u_addr.ip4)), - IP2STR(&(esp_netif[TCPIP_ADAPTER_IF_AP]->netmask.u_addr.ip4)), IP2STR(&(esp_netif[TCPIP_ADAPTER_IF_AP]->gw.u_addr.ip4))); + printf("ip:" IPSTR ",mask:" IPSTR ",gw:" IPSTR, IP2STR((ip_2_ip4(&esp_netif[TCPIP_ADAPTER_IF_AP]->ip_addr))), + IP2STR((ip_2_ip4(&esp_netif[TCPIP_ADAPTER_IF_AP]->netmask))), IP2STR((ip_2_ip4(&esp_netif[TCPIP_ADAPTER_IF_AP]->gw)))); printf(")\n"); } @@ -318,10 +319,15 @@ bool wifi_get_ip_info(WIFI_INTERFACE netif_index, struct ip_info* if_ip) return false; } + if(if_ip == NULL){ + TCPIP_ATAPTER_LOG("ERROR ip info is NULL\n"); + return false; + } + TCPIP_ATAPTER_LOG("Get netif[%d] ip info\n", netif_index); - if_ip->ip = esp_netif[netif_index]->ip_addr.u_addr.ip4; - if_ip->netmask = esp_netif[netif_index]->netmask.u_addr.ip4; - if_ip->gw = esp_netif[netif_index]->gw.u_addr.ip4; + if_ip->ip.addr = ip_addr_get_ip4_u32(&esp_netif[netif_index]->ip_addr); + if_ip->netmask.addr = ip_addr_get_ip4_u32(&esp_netif[netif_index]->netmask); + if_ip->gw.addr = ip_addr_get_ip4_u32(&esp_netif[netif_index]->gw); return true; } @@ -336,6 +342,7 @@ bool wifi_create_linklocal_ip(uint8_t netif_index, bool ipv6) return true; } +#if LWIP_IPV6 bool wifi_get_linklocal_ip(uint8_t netif_index, ip6_addr_t* linklocal) { if (TCPIP_ADAPTER_IF_VALID(netif_index)) { @@ -350,7 +357,6 @@ bool wifi_get_linklocal_ip(uint8_t netif_index, ip6_addr_t* linklocal) bool wifi_get_ipinfo_v6(uint8_t netif_index, uint8_t ip_index, ip6_addr_t* ipv6) { -#if LWIP_IPV6 if (TCPIP_ADAPTER_IF_VALID(netif_index)) { memcpy(ipv6, &esp_netif[netif_index]->ip6_addr[ip_index], sizeof(ip6_addr_t)); @@ -359,9 +365,9 @@ bool wifi_get_ipinfo_v6(uint8_t netif_index, uint8_t ip_index, ip6_addr_t* ipv6) return false; } -#endif return true; } +#endif bool wifi_softap_dhcps_start(void) {