menu "LWIP"

config LWIP_USE_IRAM
    bool "Enable lwip use iram option"
    default n

config LWIP_HIGH_THROUGHPUT
    bool "Enable lwip high throughput"
    default n
    select TCP_QUEUE_OOSEQ
    select TCP_HIGH_SPEED_RETRANSMISSION
    select SOC_FULL_ICACHE
    select WIFI_TX_RATE_SEQUENCE_FROM_HIGH
    select HEAP_DISABLE_IRAM
    help
        Enable this option, also enable "TCP_QUEUE_OOSEQ", "TCP_HIGH_SPEED_RETRANSMISSION" and
        "SOC_FULL_ICACHE", so lwip should cache TCP message received in disorder sequence and
        chip should full 32 KB IRAM as icache. For these 2 reasons, the global heap user can used
        may reduce a lot.

config LWIP_GLOBAL_DATA_LINK_IRAM
    bool "Link LWIP global data to IRAM"
    default y
    depends on !LWIP_HIGH_THROUGHPUT
    depends on !SOC_FULL_ICACHE
    help
        Link LWIP global data(.bss .data COMMON) from DRAM to IRAM.

config ESP_LWIP_RECV_REST_DATA
    bool "Receive rest data although TCP aborts"
    default n
    help
        Receive rest data although TCP aborts.

config TCPIP_RECVMBOX_SIZE
    int "TCPIP task receive mail box size"
    default 32
    range 6 64
    help
        Set TCPIP task receive mail box size. Generally bigger value means higher throughput
        but more memory. The value should be bigger than UDP/TCP mail box size.

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

config LWIP_ESP_GRATUITOUS_ARP
    bool "Send gratuitous ARP periodically"
    default n
    help
        Enable this option allows to send gratuitous ARP periodically.

        This option solve the compatibility issues.If the ARP table of the AP is old, and the AP
        doesn't send ARP request to update it's ARP table, this will lead to the STA sending IP packet fail.
        Thus we send gratuitous ARP periodically to let AP update it's ARP table.

config LWIP_GARP_TMR_INTERVAL
    int "GARP timer interval(seconds)"
    default 60
    depends on LWIP_ESP_GRATUITOUS_ARP
    help
        Set the timer interval for gratuitous ARP. The default value is 60s

endmenu # LWIP ARP

menu "SOCKET"

config LWIP_IPV6_MLD_SOCK
    bool "LWIP socket supports IPv6 multicast configuration"
    default y
    depends on LWIP_IPV6
    help
        Enable the option can enable LWIP socket IPv6 multicast configuration.

config LWIP_SOCKET_MULTITHREAD
    bool "LWIP socket supports multithread"
    default y
    help
        Enable the option can enable LWIP socket multithread and all
        function will be thread safe.

config ENABLE_NONBLOCK_SPEEDUP
    bool "Speed up send speed of nonblock TCP"
    default n
    help
        Enable this option, send speed of nonblock TCP will increase obviously.

config SET_SOLINGER_DEFAULT
    bool "set socket SO_LINGER default"
    default y
    depends on LWIP_SOCKET_MULTITHREAD
    help
        The function is only used by socket multi-thread.

        Enable this option can set the target socket to enable the "SO_LINGER" and config timeout to be "0" when it is created.
        It means that if close the socket, all send queue will be dropped, so heap memory can be collected immediately,
        but some packets which are waiting to be sent will lost.

config ESP_UDP_SYNC_SEND
    bool "LWIP socket UDP sync send"
    default y
    help
        Enable the option can enable LWIP socket UDP sync send. CPU cost
        should decrease but memory cost increase and it can make UDP
        throughput increase a lot.

config ESP_UDP_SYNC_RETRY_MAX
    int "LWIP socket UDP sync send retry max count"
    range 1 10
    default 5
    depends on ESP_UDP_SYNC_SEND
    help
        When UDP sync send count reaches the value, then the packet should
        be lost and LWIP core thread wake up the up-level send thread.

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_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.

config LWIP_DHCP_DISCOVER_RETRANSMISSION_INTERVAL
    int "DHCP discover retransmission interval (milliseconds)"
    default 250 # 4 * default retransmission interval
    range 250 1000
    help
        Set time interval of retransmissions of DHCP discover.

config LWIP_ESP_DHCP_OPTION
    bool "Enable DHCP option60 and option61 in discovery and request state"
    default n
    help
        Maybe some routers need add those option to get IP address.
        Enable this config to add option60 and option61 in discovery and request state
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_AUTOIP_MAX_CONFLICTS
    int "Max IP conflicts before rate limiting"
    range 1 100
    default 9
    depends on LWIP_AUTOIP
    help
        If the AUTOIP functionality detects this many IP conflicts while
        self-assigning an address, it will go into a rate limited mode.

config LWIP_AUTOIP_RATE_LIMIT_INTERVAL
    int "Rate limited interval (seconds)"
    range 5 120
    default 20
    depends on LWIP_AUTOIP
    help
        If rate limiting self-assignment requests, wait this long between
        each request.

config LWIP_IGMP
    bool "Enable IGMP module"
    default y

config ESP_DNS
    bool "Enable espressif advansed DNS"
    default y
    help
        Enable this option, espressif advansed DNS functions will be enable. User can set the
        reserved DNS server(its index is DNS_FALLBACK_SERVER_INDEX) which will not be changed by DHCP.

config DNS_MAX_SERVERS
    int "The maximum of DNS servers"
    range 2 5
    default 3 if ESP_DNS
    default 2 if !ESP_DNS

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 TCP_HIGH_SPEED_RETRANSMISSION
    bool "TCP high speed retransmissions"
    default n
    help
        "Enable this option, TCP retransmissions time will always be set to 500ms forcely."

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 14600
    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 y
    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.

config LWIP_TCP_RTO_TIME
    int "Default TCP RTO TIME"
    default 1000
    help
        Set default TCP RTO time for a reasonable initial RTO.
        Advise to set initial RTO to 1 second

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 2048
    range 2048 8192
    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 n

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_ND6_RDNSS_MAX_DNS_SERVERS
    bool "The IPv6 ND6 RDNSS max DNS servers"
    depends on LWIP_IPV6
    default n
    help
        Use IPv6 Router Advertisement Recursive DNS Server Option (as per RFC 6106) 
        to copy a defined maximum number of DNS servers to the DNS module

config LWIP_STATS
    bool "Enable statistics collection in lwip_stats"
    default n

config ESP_LWIP_MEM_DBG
    bool "Enable LWIP memory debug"
    default n
    help
        Enable this option, LWIP allocated memory information can be traced by "heap" components.

        User can call "heap_trace_start(HEAP_TRACE_LEAKS)" to start tracing and call "heap_trace_dump()"
        to list the memory map. 

menuconfig LWIP_DEBUG
    bool "Enable lwip Debug"
    default n

config LWIP_ETHARP_DEBUG
    bool "Enable debugging in etharp.c"
    depends on LWIP_DEBUG
    default n

config LWIP_NETIF_DEBUG
    bool "Enable debugging in netif.c"
    depends on LWIP_DEBUG
    default n

config LWIP_PBUF_DEBUG
    bool "Enable debugging in pbuf.c"
    depends on LWIP_DEBUG
    default n

config LWIP_API_LIB_DEBUG
    bool "Enable debugging in api_lib.c"
    depends on LWIP_DEBUG
    default n

config LWIP_API_MSG_DEBUG
    bool "Enable debugging in api_msg.c"
    depends on LWIP_DEBUG
    default n

config LWIP_SOCKETS_DEBUG
    bool "Enable debugging in sockets.c"
    depends on LWIP_DEBUG
    default n

config LWIP_ICMP_DEBUG
    bool "Enable debugging in icmp.c"
    depends on LWIP_DEBUG
    default n

config LWIP_IGMP_DEBUG
    bool "Enable debugging in igmp.c"
    depends on LWIP_DEBUG
    default n

config LWIP_INET_DEBUG
    bool "Enable debugging in inet.c"
    depends on LWIP_DEBUG
    default n

config LWIP_ETHERNETIF_DEBUG
    bool "Enable debugging in ethernetif.c"
    depends on LWIP_DEBUG
    default n

config LWIP_IP_DEBUG
    bool "Enable debugging for IP"
    depends on LWIP_DEBUG
    default n

config LWIP_IP_REASS_DEBUG
    bool "Enable debugging in ip_frag.c for both frag & reass"
    depends on LWIP_DEBUG
    default n

config LWIP_RAW_DEBUG
    bool "Enable debugging in raw.c"
    depends on LWIP_DEBUG
    default n

config LWIP_MEM_DEBUG
    bool "Enable debugging in mem.c"
    depends on LWIP_DEBUG
    default n

config LWIP_MEMP_DEBUG
    bool "Enable debugging in memp.c"
    depends on LWIP_DEBUG
    default n

config LWIP_SYS_DEBUG
    bool "Enable debugging in sys.c"
    depends on LWIP_DEBUG
    default n

config LWIP_TIMERS_DEBUG
    bool "Enable debugging in timers.c"
    depends on LWIP_DEBUG
    default n

config LWIP_TCP_DEBUG
    bool "Enable debugging for TCP"
    depends on LWIP_DEBUG
    default n

config LWIP_TCP_INPUT_DEBUG
    bool "Enable debugging in tcp_in.c for incoming debug"
    depends on LWIP_DEBUG
    default n

config LWIP_TCP_FR_DEBUG
    bool "Enable debugging in tcp_in.c for fast retransmit"
    depends on LWIP_DEBUG
    default n

config LWIP_TCP_RTO_DEBUG
    bool "Enable debugging in TCP for retransmit"
    depends on LWIP_DEBUG
    default n

config LWIP_TCP_CWND_DEBUG
    bool "Enable debugging for TCP congestion window"
    depends on LWIP_DEBUG
    default n

config LWIP_TCP_WND_DEBUG
    bool "Enable debugging in tcp_in.c for window updating"
    depends on LWIP_DEBUG
    default n

config LWIP_TCP_OUTPUT_DEBUG
    bool "Enable debugging in tcp_out.c output functions"
    depends on LWIP_DEBUG
    default n

config LWIP_TCP_RST_DEBUG
    bool "Enable debugging for TCP with the RST message"
    depends on LWIP_DEBUG
    default n

config LWIP_TCP_QLEN_DEBUG
    bool "Enable debugging for TCP queue lengths"
    depends on LWIP_DEBUG
    default n

config LWIP_UDP_DEBUG
    bool "Enable debugging in UDP"
    depends on LWIP_DEBUG
    default n

config LWIP_TCPIP_DEBUG
    bool "Enable debugging in tcpip.c"
    depends on LWIP_DEBUG
    default n

config LWIP_SLIP_DEBUG
    bool "Enable debugging in slipif.c"
    depends on LWIP_DEBUG
    default n

config LWIP_DHCP_DEBUG
    bool "Enable debugging in dhcp.c"
    depends on LWIP_DEBUG
    default n

config LWIP_DHCP_SERVER_DEBUG
    bool "Enable debugging in dhcpserver.c"
    depends on LWIP_DEBUG
    default n

config LWIP_AUTOIP_DEBUG
    bool "Enable debugging in autoip.c"
    depends on LWIP_DEBUG
    default n

config LWIP_DNS_DEBUG
    bool "Enable debugging for DNS"
    depends on LWIP_DEBUG
    default n

config LWIP_IP6_DEBUG
    bool "Enable debugging for IPv6"
    depends on LWIP_DEBUG
    default n

config LWIP_SNTP_DEBUG
    bool "Enable debugging for SNTP."
    depends on LWIP_DEBUG
    default n

config LWIP_THREAD_SAFE_DEBUG
    bool "Enable debugging for LWIP thread safety."
    depends on LWIP_DEBUG
    default n

config LWIP_PBUF_CACHE_DEBUG
    bool "Enable debugging for LWIP pbuf cache."
    depends on LWIP_DEBUG
    default n

config LWIP_TCP_TXRX_PBUF_DEBUG
    bool "Enable debugging for TCP TX/RX data."
    depends on LWIP_DEBUG
    default n

endmenu
