diff --git a/boards.txt b/boards.txt index 1519bba24..af080f735 100644 --- a/boards.txt +++ b/boards.txt @@ -1680,7 +1680,7 @@ coredev.build.lwip_flags= coredev.menu.LwIPVariant.Espressif=Espressif (xcc) coredev.menu.LwIPVariant.Espressif.build.lwip_lib=-llwip -coredev.menu.LwIPVariant.Espressif.build.lwip_flags= +coredev.menu.LwIPVariant.Espressif.build.lwip_flags=-DLWIP_MAYBE_XCC coredev.menu.LwIPVariant.Prebuilt=Prebuilt Source (gcc) coredev.menu.LwIPVariant.Prebuilt.build.lwip_lib=-llwip_gcc coredev.menu.LwIPVariant.Prebuilt.build.lwip_flags=-DLWIP_OPEN_SRC diff --git a/libraries/ESP8266WiFi/src/include/UdpContext.h b/libraries/ESP8266WiFi/src/include/UdpContext.h index c367492cd..9213accfe 100644 --- a/libraries/ESP8266WiFi/src/include/UdpContext.h +++ b/libraries/ESP8266WiFi/src/include/UdpContext.h @@ -44,11 +44,11 @@ public: , _tx_buf_head(0) , _tx_buf_cur(0) , _tx_buf_offset(0) - , _multicast_ttl(1) - , _dest_port(0) { _pcb = udp_new(); - _dest_addr.addr = 0; +#ifdef LWIP_MAYBE_XCC + _mcast_ttl = 1; +#endif } ~UdpContext() @@ -87,8 +87,8 @@ public: bool connect(ip_addr_t addr, uint16_t port) { - _dest_addr = addr; - _dest_port = port; + ip_addr_copy(_pcb->remote_ip, addr); + _pcb->remote_port = port; return true; } @@ -106,17 +106,16 @@ public: void setMulticastInterface(ip_addr_t addr) { - // newer versions of lwip have a macro to set the multicast ip - // udp_set_multicast_netif_addr(_pcb, addr); - _pcb->multicast_ip = addr; + udp_set_multicast_netif_addr(_pcb, addr); } void setMulticastTTL(int ttl) { - // newer versions of lwip have an additional field (mcast_ttl) for this purpose - // and a macro to set it instead of direct field access - // udp_set_multicast_ttl(_pcb, ttl); - _multicast_ttl = ttl; +#ifdef LWIP_MAYBE_XCC + _mcast_ttl = ttl; +#else + udp_set_multicast_ttl(_pcb, ttl); +#endif } // warning: handler is called from tcp stack context @@ -275,20 +274,22 @@ public: if (!addr) { - addr = &_dest_addr; - port = _dest_port; + addr = &_pcb->remote_ip; + port = _pcb->remote_port; } - +#ifdef LWIP_MAYBE_XCC uint16_t old_ttl = _pcb->ttl; if (ip_addr_ismulticast(addr)) { - _pcb->ttl = _multicast_ttl; + _pcb->ttl = _mcast_ttl; } - +#endif err_t err = udp_sendto(_pcb, tx_copy, addr, port); if (err != ERR_OK) { DEBUGV(":ust rc=%d\r\n", err); } +#ifdef LWIP_MAYBE_XCC _pcb->ttl = old_ttl; +#endif pbuf_free(tx_copy); return err == ERR_OK; } @@ -365,10 +366,10 @@ private: pbuf* _tx_buf_head; pbuf* _tx_buf_cur; size_t _tx_buf_offset; - uint16_t _multicast_ttl; - uint16_t _dest_port; - ip_addr_t _dest_addr; rxhandler_t _on_rx; +#ifdef LWIP_MAYBE_XCC + uint16_t _mcast_ttl; +#endif }; diff --git a/tools/sdk/lib/liblwip_gcc.a b/tools/sdk/lib/liblwip_gcc.a index 6006179d8..f1cfed0d3 100644 Binary files a/tools/sdk/lib/liblwip_gcc.a and b/tools/sdk/lib/liblwip_gcc.a differ diff --git a/tools/sdk/lwip/include/lwip/tcp_impl.h b/tools/sdk/lwip/include/lwip/tcp_impl.h index 24ca8bb95..f6778700a 100644 --- a/tools/sdk/lwip/include/lwip/tcp_impl.h +++ b/tools/sdk/lwip/include/lwip/tcp_impl.h @@ -1,8 +1,8 @@ /* * Copyright (c) 2001-2004 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, + * 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, @@ -11,21 +11,21 @@ * 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. + * 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 + * 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 * */ @@ -284,7 +284,7 @@ struct tcp_seg { u16_t oversize_left; /* Extra bytes available at the end of the last pbuf in unsent (used for asserting vs. tcp_pcb.unsent_oversized only) */ -#endif /* TCP_OVERSIZE_DBGCHECK */ +#endif /* TCP_OVERSIZE_DBGCHECK */ #if TCP_CHECKSUM_ON_COPY u16_t chksum; u8_t chksum_swapped; @@ -313,7 +313,7 @@ extern u32_t tcp_ticks; /* The TCP PCB lists. */ union tcp_listen_pcbs_t { /* List of all TCP PCBs in LISTEN state. */ - struct tcp_pcb_listen *listen_pcbs; + struct tcp_pcb_listen *listen_pcbs; struct tcp_pcb *pcbs; }; extern struct tcp_pcb *tcp_bound_pcbs; @@ -325,7 +325,7 @@ extern struct tcp_pcb *tcp_tw_pcbs; /* List of all TCP PCBs in TIME-WAIT. * extern struct tcp_pcb *tcp_tmp_pcb; /* Only used for temporary storage. */ -/* Axioms about the above lists: +/* Axioms about the above lists: 1) Every TCP PCB that is not CLOSED is in one of the lists. 2) A PCB is only in one of the lists. 3) All PCBs in the tcp_listen_pcbs list is in LISTEN state. @@ -396,6 +396,26 @@ extern struct tcp_pcb *tcp_tmp_pcb; /* Only used for temporary storage. */ #endif /* LWIP_DEBUG */ +#define TCP_TW_LIMIT(l) \ + do { \ + u32_t tcp_tmp_pcbs_count = 0; \ + tcp_tmp_pcb = tcp_tw_pcbs; \ + while(tcp_tmp_pcb != NULL) { \ + if(++tcp_tmp_pcbs_count == (l)) { \ + struct tcp_pcb *_tcp_tmp_pcb = tcp_tmp_pcb->next; \ + tcp_tmp_pcb->next = NULL; \ + tcp_tmp_pcb = _tcp_tmp_pcb; \ + while(tcp_tmp_pcb != NULL) { \ + _tcp_tmp_pcb = tcp_tmp_pcb; \ + tcp_pcb_purge(tcp_tmp_pcb); \ + tcp_tmp_pcb = tcp_tmp_pcb->next; \ + memp_free(MEMP_TCP_PCB, _tcp_tmp_pcb); \ + } \ + break; \ + } \ + tcp_tmp_pcb = tcp_tmp_pcb->next; \ + } \ + } while(0) /* Internal functions: */ struct tcp_pcb *tcp_pcb_copy(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR; diff --git a/tools/sdk/lwip/include/lwip/udp.h b/tools/sdk/lwip/include/lwip/udp.h index cb53d33e7..2e4b57ae7 100644 --- a/tools/sdk/lwip/include/lwip/udp.h +++ b/tools/sdk/lwip/include/lwip/udp.h @@ -1,8 +1,8 @@ /* * Copyright (c) 2001-2004 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, + * 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, @@ -11,21 +11,21 @@ * 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. + * 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 + * 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 * */ @@ -103,6 +103,10 @@ struct udp_pcb { #if LWIP_IGMP /** outgoing network interface for multicast packets */ ip_addr_t multicast_ip; +#ifndef LWIP_MAYBE_XCC + /** TTL for outgoing multicast packets */ + u8_t mcast_ttl; +#endif /* LWIP_MAYBE_XCC */ #endif /* LWIP_IGMP */ #if LWIP_UDPLITE @@ -113,7 +117,7 @@ struct udp_pcb { /** receive callback function */ udp_recv_fn recv; /** user-supplied argument for the recv callback */ - void *recv_arg; + void *recv_arg; }; /* udp_pcbs export for exernal reference (e.g. SNMP agent) */ extern struct udp_pcb *udp_pcbs; @@ -156,6 +160,15 @@ void udp_input (struct pbuf *p, struct netif *inp)ICACHE_FLASH_ #define udp_init() /* Compatibility define, not init needed. */ +#if LWIP_IGMP +#define udp_set_multicast_netif_addr(pcb, ipaddr) ip_addr_copy((pcb)->multicast_ip, (ipaddr)) +#define udp_get_multicast_netif_addr(pcb) ((pcb)->multicast_ip) +#ifndef LWIP_MAYBE_XCC +#define udp_set_multicast_ttl(pcb, value) do { (pcb)->mcast_ttl = value; } while(0) +#define udp_get_multicast_ttl(pcb) ((pcb)->mcast_ttl) +#endif /* LWIP_MAYBE_XCC */ +#endif /* LWIP_IGMP */ + #if UDP_DEBUG void udp_debug_print(struct udp_hdr *udphdr)ICACHE_FLASH_ATTR; #else diff --git a/tools/sdk/lwip/include/lwipopts.h b/tools/sdk/lwip/include/lwipopts.h index c163ac625..2081b3aea 100644 --- a/tools/sdk/lwip/include/lwipopts.h +++ b/tools/sdk/lwip/include/lwipopts.h @@ -6,9 +6,9 @@ /* * Copyright (c) 2001-2004 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, + * 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, @@ -17,21 +17,21 @@ * 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. + * 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 + * 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 * */ @@ -56,7 +56,7 @@ #define SYS_LIGHTWEIGHT_PROT 0 #endif -/** +/** * NO_SYS==1: Provides VERY minimal functionality. Otherwise, * use lwIP facilities. */ @@ -179,8 +179,8 @@ /** * MEMP_USE_CUSTOM_POOLS==1: whether to include a user file lwippools.h * that defines additional pools beyond the "standard" ones required - * by lwIP. If you set this to 1, you must have lwippools.h in your - * inlude path somewhere. + * by lwIP. If you set this to 1, you must have lwippools.h in your + * inlude path somewhere. */ #ifndef MEMP_USE_CUSTOM_POOLS #define MEMP_USE_CUSTOM_POOLS 0 @@ -255,6 +255,14 @@ #define MEMP_NUM_TCP_PCB_LISTEN 2 #endif +/** + * MEMP_NUM_TCP_PCB_TIME_WAIT: the number of TCP pcbs in TIME_WAIT state. + * (requires the LWIP_TCP option, 0 = disabled) + */ +#ifndef MEMP_NUM_TCP_PCB_TIME_WAIT +#define MEMP_NUM_TCP_PCB_TIME_WAIT 5 +#endif + /** * MEMP_NUM_TCP_SEG: the number of simultaneously queued TCP segments. * (requires the LWIP_TCP option) @@ -328,7 +336,7 @@ /** * MEMP_NUM_TCPIP_MSG_API: the number of struct tcpip_msg, which are used - * for callback/timeout API communication. + * for callback/timeout API communication. * (only needed if you use tcpip.c) */ #ifndef MEMP_NUM_TCPIP_MSG_API @@ -337,7 +345,7 @@ /** * MEMP_NUM_TCPIP_MSG_INPKT: the number of struct tcpip_msg, which are used - * for incoming packets. + * for incoming packets. * (only needed if you use tcpip.c) */ #ifndef MEMP_NUM_TCPIP_MSG_INPKT @@ -402,7 +410,7 @@ #endif /** - * PBUF_POOL_SIZE: the number of buffers in the pbuf pool. + * PBUF_POOL_SIZE: the number of buffers in the pbuf pool. */ #ifndef PBUF_POOL_SIZE #define PBUF_POOL_SIZE 10 @@ -714,7 +722,7 @@ /** * SNMP_CONCURRENT_REQUESTS: Number of concurrent requests the module will - * allow. At least one request buffer is required. + * allow. At least one request buffer is required. */ #ifndef SNMP_CONCURRENT_REQUESTS #define SNMP_CONCURRENT_REQUESTS 0 @@ -729,7 +737,7 @@ #endif /** - * SNMP_PRIVATE_MIB: + * SNMP_PRIVATE_MIB: */ #ifndef SNMP_PRIVATE_MIB #define SNMP_PRIVATE_MIB 0 @@ -775,7 +783,7 @@ ---------------------------------- */ /** - * LWIP_IGMP==1: Turn on IGMP module. + * LWIP_IGMP==1: Turn on IGMP module. */ #ifndef LWIP_IGMP #define LWIP_IGMP 1 @@ -903,12 +911,12 @@ #endif /** - * TCP_WND: The size of a TCP window. This must be at least + * TCP_WND: The size of a TCP window. This must be at least * (2 * TCP_MSS) for things to work well */ #ifndef TCP_WND #define TCP_WND (*(volatile uint32*)0x600011F0) -#endif +#endif /** * TCP_MAXRTX: Maximum number of retransmissions of data segments. @@ -973,7 +981,7 @@ /** - * TCP_SND_BUF: TCP sender buffer space (bytes). + * TCP_SND_BUF: TCP sender buffer space (bytes). */ #ifndef TCP_SND_BUF #define TCP_SND_BUF 2 * TCP_MSS @@ -1064,7 +1072,7 @@ #ifndef LWIP_EVENT_API #define LWIP_EVENT_API 0 #define LWIP_CALLBACK_API 1 -#else +#else #define LWIP_EVENT_API 1 #define LWIP_CALLBACK_API 0 #endif @@ -1762,28 +1770,28 @@ #ifndef CHECKSUM_GEN_IP #define CHECKSUM_GEN_IP 1 #endif - + /** * CHECKSUM_GEN_UDP==1: Generate checksums in software for outgoing UDP packets. */ #ifndef CHECKSUM_GEN_UDP #define CHECKSUM_GEN_UDP 1 #endif - + /** * CHECKSUM_GEN_TCP==1: Generate checksums in software for outgoing TCP packets. */ #ifndef CHECKSUM_GEN_TCP #define CHECKSUM_GEN_TCP 1 #endif - + /** * CHECKSUM_CHECK_IP==1: Check checksums in software for incoming IP packets. */ #ifndef CHECKSUM_CHECK_IP #define CHECKSUM_CHECK_IP 1 #endif - + /** * CHECKSUM_CHECK_UDP==1: Check checksums in software for incoming UDP packets. */ diff --git a/tools/sdk/lwip/src/Makefile b/tools/sdk/lwip/src/Makefile index e03fda331..5f65751bd 100644 --- a/tools/sdk/lwip/src/Makefile +++ b/tools/sdk/lwip/src/Makefile @@ -28,5 +28,8 @@ all: $(LWIP_LIB) install: all cp -f $(LWIP_LIB) $(SDK_PATH)/lib/$(LWIP_LIB) +release: all + cp -f $(LWIP_LIB) $(SDK_PATH)/lib/liblwip_gcc.a + clean: @rm -rf $(BUILD_PATH) $(LWIP_LIB) diff --git a/tools/sdk/lwip/src/core/tcp.c b/tools/sdk/lwip/src/core/tcp.c index ee50cebd7..a3651c61d 100644 --- a/tools/sdk/lwip/src/core/tcp.c +++ b/tools/sdk/lwip/src/core/tcp.c @@ -10,9 +10,9 @@ /* * Copyright (c) 2001-2004 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, + * 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, @@ -21,21 +21,21 @@ * 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. + * 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 + * 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 * */ @@ -61,17 +61,17 @@ static const char mem_debug_file[] ICACHE_RODATA_ATTR = __FILE__; #if TCP_DEBUG const char tcp_state_str_rodata[][12] ICACHE_RODATA_ATTR = { - "CLOSED", - "LISTEN", - "SYN_SENT", - "SYN_RCVD", - "ESTABLISHED", - "FIN_WAIT_1", - "FIN_WAIT_2", - "CLOSE_WAIT", - "CLOSING", - "LAST_ACK", - "TIME_WAIT" + "CLOSED", + "LISTEN", + "SYN_SENT", + "SYN_RCVD", + "ESTABLISHED", + "FIN_WAIT_1", + "FIN_WAIT_2", + "CLOSE_WAIT", + "CLOSING", + "LAST_ACK", + "TIME_WAIT" }; char tcp_state_str[12]; @@ -105,7 +105,7 @@ struct tcp_pcb ** const tcp_pcb_lists[] ICACHE_RODATA_ATTR = {&tcp_listen_pcbs.p /** Only used for temporary storage. */ struct tcp_pcb *tcp_tmp_pcb; -/** Timer counter to handle calling slow-timer from tcp_tmr() */ +/** Timer counter to handle calling slow-timer from tcp_tmr() */ static u8_t tcp_timer; static u16_t tcp_new_port(void);//����µ�tcp���ض˿� @@ -166,7 +166,9 @@ tcp_close_shutdown(struct tcp_pcb *pcb, u8_t rst_on_unacked_data) TCP_RMV(&tcp_active_pcbs, pcb); pcb->state = TIME_WAIT; TCP_REG(&tcp_tw_pcbs, pcb); - +#if MEMP_NUM_TCP_PCB_TIME_WAIT + TCP_TW_LIMIT(MEMP_NUM_TCP_PCB_TIME_WAIT); +#endif return ERR_OK; } } @@ -177,24 +179,24 @@ tcp_close_shutdown(struct tcp_pcb *pcb, u8_t rst_on_unacked_data) * however, it is in this state once allocated and as yet unused * and the user needs some way to free it should the need arise. * Calling tcp_close() with a pcb that has already been closed, (i.e. twice) - * or for a pcb that has been used and then entered the CLOSED state + * or for a pcb that has been used and then entered the CLOSED state * is erroneous, but this should never happen as the pcb has in those cases * been freed, and so any remaining handles are bogus. */ - /*��CLOSED״̬�¹ر�һ��pcb�ƺ��Ǵ���ģ� - *������ˣ�һ�������״̬�·����˶��һ�û��ʹ��,�û���ҪһЩ�취���ͷ��� - *����һ���Ѿ����رյ�pcb��tcp_close(),(��2��)����һ���Ѿ���ʹ����֮�󣬽���CLOSE״̬�Ǵ���� - *������Щ����±��ͷŵ�pcb�Dz�����ڵ�,��ˣ��κ�ʣ��ľ���Ǽٵ� - */ - err = ERR_OK;//�趨����ֵ + /*��CLOSED״̬�¹ر�һ��pcb�ƺ��Ǵ���ģ� + *������ˣ�һ�������״̬�·����˶��һ�û��ʹ��,�û���ҪһЩ�취���ͷ��� + *����һ���Ѿ����رյ�pcb��tcp_close(),(��2��)����һ���Ѿ���ʹ����֮�󣬽���CLOSE״̬�Ǵ���� + *������Щ����±��ͷŵ�pcb�Dz�����ڵ�,��ˣ��κ�ʣ��ľ���Ǽٵ� + */ + err = ERR_OK;//�趨����ֵ if (pcb->local_port != 0) { - TCP_RMV(&tcp_bound_pcbs, pcb); + TCP_RMV(&tcp_bound_pcbs, pcb); } memp_free(MEMP_TCP_PCB, pcb);//��MEMP_TCP_PCB�ڴ���趨�ͷŵ���pcb��Ӧ�ĵ�Ԫֵ,�ͷ��ڴ� pcb = NULL; break; case LISTEN: err = ERR_OK; - tcp_pcb_remove(&tcp_listen_pcbs.pcbs, pcb);//�Ӽ����PCB�б���ɾ���Ӧ��pcb + tcp_pcb_remove(&tcp_listen_pcbs.pcbs, pcb);//�Ӽ����PCB�б���ɾ���Ӧ��pcb memp_free(MEMP_TCP_PCB_LISTEN, pcb);//��MEMP_TCP_PCB_LISTEN�ڴ�����趨�ͷŵ�pcb��Ԫֵ ,�ͷ��ڴ� pcb = NULL; break; @@ -261,14 +263,14 @@ tcp_close_shutdown(struct tcp_pcb *pcb, u8_t rst_on_unacked_data) * @return ERR_OK if connection has been closed * another err_t if closing failed and pcb is not freed */ - /* - *ͨ��PCB�ر��������� - *�����е�pcbӦ�ñ��ͷŵģ�Ҳ����ԶҲ���ᱻʹ���� - *���û�����ӻ�����Ҳû�б�����,���ӵ�pcbӦ�ñ��ͷŵ� - *���һ�����ӱ�����(����SYN�Ѿ������ջ�����һ���ر��е�״̬) - *���ӱ��ر��ˣ�����������һ�����ڹرյ�״̬ - *pcb�Զ���tcp_slowtmr()�ͷ�,�����������Dz���ȫ�� - */ + /* + *ͨ��PCB�ر��������� + *�����е�pcbӦ�ñ��ͷŵģ�Ҳ����ԶҲ���ᱻʹ���� + *���û�����ӻ�����Ҳû�б�����,���ӵ�pcbӦ�ñ��ͷŵ� + *���һ�����ӱ�����(����SYN�Ѿ������ջ�����һ���ر��е�״̬) + *���ӱ��ر��ˣ�����������һ�����ڹرյ�״̬ + *pcb�Զ���tcp_slowtmr()�ͷ�,�����������Dz���ȫ�� + */ err_t tcp_close(struct tcp_pcb *pcb) { @@ -341,7 +343,7 @@ tcp_abandon(struct tcp_pcb *pcb, int reset) u32_t seqno, ackno; u16_t remote_port, local_port; ip_addr_t remote_ip, local_ip; -#if LWIP_CALLBACK_API +#if LWIP_CALLBACK_API tcp_err_fn errf; #endif /* LWIP_CALLBACK_API */ void *errf_arg; @@ -373,7 +375,7 @@ tcp_abandon(struct tcp_pcb *pcb, int reset) if (pcb->unsent != NULL) { tcp_segs_free(pcb->unsent); } -#if TCP_QUEUE_OOSEQ +#if TCP_QUEUE_OOSEQ if (pcb->ooseq != NULL) { tcp_segs_free(pcb->ooseq); } @@ -555,7 +557,7 @@ tcp_listen_with_backlog(struct tcp_pcb *pcb, u8_t backlog) return (struct tcp_pcb *)lpcb; } -/** +/** * Update the state that tracks the available window space to advertise. * * Returns how much extra window would be advertised if we sent an @@ -636,7 +638,7 @@ tcp_new_port(void) #define TCP_LOCAL_PORT_RANGE_END 0x7fff #endif static u16_t port = TCP_LOCAL_PORT_RANGE_START; - + again: // if (++port >= TCP_LOCAL_PORT_RANGE_END) { // port = TCP_LOCAL_PORT_RANGE_START; @@ -646,7 +648,7 @@ tcp_new_port(void) if (port < TCP_LOCAL_PORT_RANGE_START) port += TCP_LOCAL_PORT_RANGE_START; /* Check all PCB lists. */ - for (i = 0; i < NUM_TCP_PCB_LISTS; i++) { + for (i = 0; i < NUM_TCP_PCB_LISTS; i++) { for(pcb = *tcp_pcb_lists[i]; pcb != NULL; pcb = pcb->next) { if (pcb->local_port == port) { goto again; @@ -743,7 +745,7 @@ tcp_connect(struct tcp_pcb *pcb, ip_addr_t *ipaddr, u16_t port, pcb->ssthresh = pcb->mss * 10; #if LWIP_CALLBACK_API pcb->connected = connected;//ע��connected�ص����� -#else /* LWIP_CALLBACK_API */ +#else /* LWIP_CALLBACK_API */ LWIP_UNUSED_ARG(connected); #endif /* LWIP_CALLBACK_API */ @@ -849,7 +851,7 @@ tcp_slowtmr(void) LWIP_DEBUGF(TCP_CWND_DEBUG, ("tcp_slowtmr: cwnd %"U16_F " ssthresh %"U16_F"\n", pcb->cwnd, pcb->ssthresh)); - + /* The following needs to be called AFTER cwnd is set to one mss - STJ */ tcp_rexmit_rto(pcb); @@ -873,7 +875,7 @@ tcp_slowtmr(void) if((u32_t)(tcp_ticks - pcb->tmr) > (pcb->keep_idle + (pcb->keep_cnt*pcb->keep_intvl)) / TCP_SLOW_INTERVAL) -#else +#else if((u32_t)(tcp_ticks - pcb->tmr) > (pcb->keep_idle + TCP_MAXIDLE) / TCP_SLOW_INTERVAL) #endif /* LWIP_TCP_KEEPALIVE */ @@ -881,17 +883,17 @@ tcp_slowtmr(void) LWIP_DEBUGF(TCP_DEBUG, ("tcp_slowtmr: KEEPALIVE timeout. Aborting connection to %"U16_F".%"U16_F".%"U16_F".%"U16_F".\n", ip4_addr1_16(&pcb->remote_ip), ip4_addr2_16(&pcb->remote_ip), ip4_addr3_16(&pcb->remote_ip), ip4_addr4_16(&pcb->remote_ip))); - + ++pcb_remove; ++pcb_reset; } #if LWIP_TCP_KEEPALIVE - else if((u32_t)(tcp_ticks - pcb->tmr) > + else if((u32_t)(tcp_ticks - pcb->tmr) > (pcb->keep_idle + pcb->keep_cnt_sent * pcb->keep_intvl) / TCP_SLOW_INTERVAL) #else - else if((u32_t)(tcp_ticks - pcb->tmr) > - (pcb->keep_idle + pcb->keep_cnt_sent * TCP_KEEPINTVL_DEFAULT) + else if((u32_t)(tcp_ticks - pcb->tmr) > + (pcb->keep_idle + pcb->keep_cnt_sent * TCP_KEEPINTVL_DEFAULT) / TCP_SLOW_INTERVAL) #endif /* LWIP_TCP_KEEPALIVE */ { @@ -942,12 +944,12 @@ tcp_slowtmr(void) LWIP_ASSERT("tcp_slowtmr: first pcb == tcp_active_pcbs", tcp_active_pcbs == pcb); tcp_active_pcbs = pcb->next; } - + if (pcb_reset) { tcp_rst(pcb->snd_nxt, pcb->rcv_nxt, &pcb->local_ip, &pcb->remote_ip, pcb->local_port, pcb->remote_port); } - + TCP_EVENT_ERR(pcb->errf, pcb->callback_arg, ERR_ABRT); pcb2 = pcb; pcb = pcb->next; @@ -971,7 +973,7 @@ tcp_slowtmr(void) } } - + /* Steps through all of the TIME-WAIT PCBs. */ prev = NULL; pcb = tcp_tw_pcbs; @@ -983,7 +985,7 @@ tcp_slowtmr(void) if ((u32_t)(tcp_ticks - pcb->tmr) > 2 * TCP_MSL / TCP_SLOW_INTERVAL) { ++pcb_remove; } - + /* If the PCB should be removed, do it. */ @@ -1101,7 +1103,7 @@ tcp_setprio(struct tcp_pcb *pcb, u8_t prio) * * @param seg the old tcp_seg * @return a copy of seg - */ + */ struct tcp_seg * tcp_seg_copy(struct tcp_seg *seg) { @@ -1111,7 +1113,7 @@ tcp_seg_copy(struct tcp_seg *seg) if (cseg == NULL) { return NULL; } - SMEMCPY((u8_t *)cseg, (const u8_t *)seg, sizeof(struct tcp_seg)); + SMEMCPY((u8_t *)cseg, (const u8_t *)seg, sizeof(struct tcp_seg)); pbuf_ref(cseg->p); return cseg; } @@ -1150,7 +1152,7 @@ tcp_kill_prio(u8_t prio) mprio = TCP_PRIO_MAX; - + /* We kill the oldest active connection that has lower priority than prio. */ inactivity = 0; inactive = NULL; @@ -1207,7 +1209,7 @@ tcp_alloc(u8_t prio) { struct tcp_pcb *pcb; u32_t iss; - + pcb = (struct tcp_pcb *)memp_malloc(MEMP_TCP_PCB);//�����ڴ�ؿռ� if (pcb == NULL) { //os_printf("tcp_pcb memory is fail\n"); @@ -1253,18 +1255,18 @@ tcp_alloc(u8_t prio) pcb->snd_wl2 = iss; //��ʼ�����ʹ��ڸ����ֶ� pcb->snd_nxt = iss; pcb->lastack = iss; - pcb->snd_lbb = iss; + pcb->snd_lbb = iss; pcb->tmr = tcp_ticks; //��¼���ƿ鴴��ϵͳʱ�� pcb->polltmr = 0; //����������¼���ʱ�� #if LWIP_CALLBACK_API pcb->recv = tcp_recv_null; //ע�������ݵ�Ĭ���ϲ㺯�� -#endif /* LWIP_CALLBACK_API */ - +#endif /* LWIP_CALLBACK_API */ + /* Init KEEPALIVE timer */ pcb->keep_idle = TCP_KEEPIDLE_DEFAULT; - + #if LWIP_TCP_KEEPALIVE pcb->keep_intvl = TCP_KEEPINTVL_DEFAULT; pcb->keep_cnt = TCP_KEEPCNT_DEFAULT; @@ -1300,10 +1302,10 @@ tcp_new(void) * ���ֶν���Ϊ����ݸ�������� * @param pcb tcp_pcb to set the callback argument * @param arg void pointer argument to pass to callback functions - */ + */ void tcp_arg(struct tcp_pcb *pcb, void *arg) -{ +{ pcb->callback_arg = arg; } #if LWIP_CALLBACK_API @@ -1314,7 +1316,7 @@ tcp_arg(struct tcp_pcb *pcb, void *arg) *����ƿ��recv�ֶ�ע�ắ���յ����ʱ�ص� * @param pcb tcp_pcb to set the recv callback * @param recv callback function to call for this pcb when data is received - */ + */ void tcp_recv(struct tcp_pcb *pcb, tcp_recv_fn recv) { @@ -1327,7 +1329,7 @@ tcp_recv(struct tcp_pcb *pcb, tcp_recv_fn recv) *����ƿ�send �ֶ�ע�ắ����ݷ��ͳɹ���ص� * @param pcb tcp_pcb to set the sent callback * @param sent callback function to call for this pcb when data is successfully sent - */ + */ void tcp_sent(struct tcp_pcb *pcb, tcp_sent_fn sent) { @@ -1341,7 +1343,7 @@ tcp_sent(struct tcp_pcb *pcb, tcp_sent_fn sent) * @param pcb tcp_pcb to set the err callback * @param err callback function to call for this pcb when a fatal error * has occured on the connection - */ + */ void tcp_err(struct tcp_pcb *pcb, tcp_err_fn err) { @@ -1355,7 +1357,7 @@ tcp_err(struct tcp_pcb *pcb, tcp_err_fn err) * @param pcb tcp_pcb to set the accept callback * @param accept callback function to call for this pcb when LISTENing * connection has been connected to another host - */ + */ void tcp_accept(struct tcp_pcb *pcb, tcp_accept_fn accept) { @@ -1369,15 +1371,15 @@ tcp_accept(struct tcp_pcb *pcb, tcp_accept_fn accept) * from TCP. The interval is specified in terms of the TCP coarse * timer interval, which is called twice a second. *����ƿ��POLL�ֶ�ע�ắ��ú��������Ա����� - */ + */ void tcp_poll(struct tcp_pcb *pcb, tcp_poll_fn poll, u8_t interval) { #if LWIP_CALLBACK_API pcb->poll = poll; -#else /* LWIP_CALLBACK_API */ +#else /* LWIP_CALLBACK_API */ LWIP_UNUSED_ARG(poll); -#endif /* LWIP_CALLBACK_API */ +#endif /* LWIP_CALLBACK_API */ pcb->pollinterval = interval; } @@ -1461,7 +1463,7 @@ tcp_pcb_remove(struct tcp_pcb **pcblist, struct tcp_pcb *pcb) TCP_RMV(pcblist, pcb); tcp_pcb_purge(pcb); - + /* if there is an outstanding delayed ACKs, send it */ if (pcb->state != TIME_WAIT && pcb->state != LISTEN && @@ -1492,7 +1494,7 @@ u32_t tcp_next_iss(void) { static u32_t iss = 6510; - + again: iss += tcp_ticks; /* XXX */ if (iss == 0) @@ -1632,21 +1634,21 @@ tcp_debug_print_pcbs(void) pcb->local_port, pcb->remote_port, pcb->snd_nxt, pcb->rcv_nxt)); tcp_debug_print_state(pcb->state); - } + } LWIP_DEBUGF(TCP_DEBUG, ("Listen PCB states:\n")); for(pcb = (struct tcp_pcb *)tcp_listen_pcbs.pcbs; pcb != NULL; pcb = pcb->next) { LWIP_DEBUGF(TCP_DEBUG, ("Local port %"U16_F", foreign port %"U16_F" snd_nxt %"U32_F" rcv_nxt %"U32_F" ", pcb->local_port, pcb->remote_port, pcb->snd_nxt, pcb->rcv_nxt)); tcp_debug_print_state(pcb->state); - } + } LWIP_DEBUGF(TCP_DEBUG, ("TIME-WAIT PCB states:\n")); for(pcb = tcp_tw_pcbs; pcb != NULL; pcb = pcb->next) { LWIP_DEBUGF(TCP_DEBUG, ("Local port %"U16_F", foreign port %"U16_F" snd_nxt %"U32_F" rcv_nxt %"U32_F" ", pcb->local_port, pcb->remote_port, pcb->snd_nxt, pcb->rcv_nxt)); tcp_debug_print_state(pcb->state); - } + } } /** diff --git a/tools/sdk/lwip/src/core/tcp_in.c b/tools/sdk/lwip/src/core/tcp_in.c index be74a28ac..409559605 100644 --- a/tools/sdk/lwip/src/core/tcp_in.c +++ b/tools/sdk/lwip/src/core/tcp_in.c @@ -6,7 +6,7 @@ * * These functions are generally called in the order (ip_input() ->) * tcp_input() -> * tcp_process() -> tcp_receive() (-> application). - * + * */ /* @@ -92,12 +92,12 @@ static err_t tcp_timewait_input(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR; * @param p received TCP segment to process (p->payload pointing to the IP header) * @param inp network interface on which this segment was received */ - /** - * TCP��ʼ�����봦�?��֤��TCPͷ���������IP����� - - * @����p:������յ�TCP��(ָ��IPͷ�ĸ���) - * @����inp:���նε�����ӿ� - */ + /** + * TCP��ʼ�����봦�?��֤��TCPͷ���������IP����� + + * @����p:������յ�TCP��(ָ��IPͷ�ĸ���) + * @����inp:���նε�����ӿ� + */ void tcp_input(struct pbuf *p, struct netif *inp) { @@ -112,15 +112,15 @@ tcp_input(struct pbuf *p, struct netif *inp) PERF_START; - TCP_STATS_INC(tcp.recv); //״̬��1 + TCP_STATS_INC(tcp.recv); //״̬��1 snmp_inc_tcpinsegs(); //tcp����μ�1 iphdr = (struct ip_hdr *)p->payload;// pointer to the actual data in the buffer - /* - *��ͷ����(IHL)��4λ��IPЭ���ͷ�ij��ȣ�ָ��IPv4Э���ͷ���ȵ��ֽ������ٸ�32λ�� - *����IPv4�İ�ͷ���ܰ�ɱ������Ŀ�ѡ ���������ֶο�������ȷ��IPv4��ݱ�����ݲ��ֵ�ƫ������ - *IPv4��ͷ����С������20���ֽڣ����IHL����ֶε���Сֵ��ʮ���Ʊ�ʾ����5 (5x4 = 20�ֽ�)�� - *����˵�����ʾ�İ�ͷ�����ֽ�����4�ֽڵı��� + /* + *��ͷ����(IHL)��4λ��IPЭ���ͷ�ij��ȣ�ָ��IPv4Э���ͷ���ȵ��ֽ������ٸ�32λ�� + *����IPv4�İ�ͷ���ܰ�ɱ������Ŀ�ѡ ���������ֶο�������ȷ��IPv4��ݱ�����ݲ��ֵ�ƫ������ + *IPv4��ͷ����С������20���ֽڣ����IHL����ֶε���Сֵ��ʮ���Ʊ�ʾ����5 (5x4 = 20�ֽ�)�� + *����˵�����ʾ�İ�ͷ�����ֽ�����4�ֽڵı��� */ tcphdr = (struct tcp_hdr *)((u8_t *)p->payload + IPH_HL(iphdr) * 4); @@ -135,7 +135,7 @@ tcp_input(struct pbuf *p, struct netif *inp) TCP_STATS_INC(tcp.lenerr);//���󳤶ȼ��� TCP_STATS_INC(tcp.drop);//��ֹ���� snmp_inc_tcpinerrs(); - pbuf_free(p);//�ͷ�buffer + pbuf_free(p);//�ͷ�buffer return; } @@ -183,23 +183,23 @@ tcp_input(struct pbuf *p, struct netif *inp) /* Convert fields in TCP header to host byte order. */ tcphdr->src = ntohs(tcphdr->src); //ת��Դ��ַ tcphdr->dest = ntohs(tcphdr->dest); //ת��Ŀ�ĵ�ַ - seqno = tcphdr->seqno = ntohl(tcphdr->seqno); //ת�����к� + seqno = tcphdr->seqno = ntohl(tcphdr->seqno); //ת�����к� ackno = tcphdr->ackno = ntohl(tcphdr->ackno); //ת��Ӧ��� tcphdr->wnd = ntohs(tcphdr->wnd); //ת��tcp���� - flags = TCPH_FLAGS(tcphdr);//�õ�tcp header�ı�־ - /* - *��־��3λ�����ֶΣ��� - * ����λ��1λ - * ���ֶ�λ��1λ��ȡֵ��0��������ݱ��ֶΣ���1����ݱ����ֶܷΣ� - * ����λ��1λ��ȡֵ��0����ݰ����û�а�1����ݰ�����и��İ� - */ + flags = TCPH_FLAGS(tcphdr);//�õ�tcp header�ı�־ + /* + *��־��3λ�����ֶΣ��� + * ����λ��1λ + * ���ֶ�λ��1λ��ȡֵ��0��������ݱ��ֶΣ���1����ݱ����ֶܷΣ� + * ����λ��1λ��ȡֵ��0����ݰ����û�а�1����ݰ�����и��İ� + */ tcplen = p->tot_len + ((flags & (TCP_FIN | TCP_SYN)) ? 1 : 0);//TCP_FIN �� TCP_SYN ��λ��1�������0 /* Demultiplex an incoming segment. First, we check if it is destined for an active connection. ���ȣ�����Ƿ�һ��Ҫ����һ������*/ //////////////////////////////////////////////////////////////////////////////////////// - prev = NULL; + prev = NULL; for(pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) {//������б� LWIP_ASSERT("tcp_input: active pcb->state != CLOSED", pcb->state != CLOSED); LWIP_ASSERT("tcp_input: active pcb->state != TIME-WAIT", pcb->state != TIME_WAIT); @@ -286,9 +286,9 @@ tcp_input(struct pbuf *p, struct netif *inp) /* put this listening pcb at the head of the listening list */ tcp_listen_pcbs.listen_pcbs = lpcb; } - + LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_input: packed for LISTENing connection.\n")); - tcp_listen_input(lpcb);//����tcp������ݰ� + tcp_listen_input(lpcb);//����tcp������ݰ� pbuf_free(p); return; } @@ -385,7 +385,7 @@ tcp_input(struct pbuf *p, struct netif *inp) //PSH��־ PSH ����λ�� //��PSH=1ʱ��Ҫ���ͷ����Ϸ��͸÷ֶΣ� //����շ�����Ľ����Ľ���Ӧ�ò㣬�������д��? - + if (flags & TCP_PSH) { recv_data->flags |= PBUF_FLAG_PUSH;//���bufferӦ������������ } @@ -411,7 +411,7 @@ tcp_input(struct pbuf *p, struct netif *inp) if (pcb->rcv_wnd != TCP_WND) { pcb->rcv_wnd++; } - + TCP_EVENT_CLOSED(pcb, err); if (err == ERR_ABRT) { goto aborted; @@ -595,21 +595,21 @@ tcp_listen_input(struct tcp_pcb_listen *pcb) static err_t tcp_timewait_input(struct tcp_pcb *pcb) { - + if (flags & TCP_RST) { //RST��λ��ֱ�ӷ��� return ERR_OK; } - + if (flags & TCP_SYN) { //��SYN������Ϣ����������ݱ���ڽ��մ����ڣ����ͷ�����RST���� - + if (TCP_SEQ_BETWEEN(seqno, pcb->rcv_nxt, pcb->rcv_nxt+pcb->rcv_wnd)) { - + tcp_rst(ackno, seqno + tcplen, ip_current_dest_addr(), ip_current_src_addr(), tcphdr->dest, tcphdr->src); return ERR_OK; } } else if (flags & TCP_FIN) { //���İ�FIN������Ϣ - + pcb->tmr = tcp_ticks; //��λ�ȴ�2MSLʱ�䣬���ƿ����µȴ�2MSL } @@ -648,7 +648,7 @@ tcp_process(struct tcp_pcb *pcb) acceptable = 1; } } else { - if (TCP_SEQ_BETWEEN(seqno, pcb->rcv_nxt, + if (TCP_SEQ_BETWEEN(seqno, pcb->rcv_nxt, pcb->rcv_nxt+pcb->rcv_wnd)) { acceptable = 1; } @@ -669,12 +669,12 @@ tcp_process(struct tcp_pcb *pcb) } } - if ((flags & TCP_SYN) && (pcb->state != SYN_SENT && pcb->state != SYN_RCVD)) { + if ((flags & TCP_SYN) && (pcb->state != SYN_SENT && pcb->state != SYN_RCVD)) { /* Cope with new connection attempt after remote end crashed */ tcp_ack_now(pcb); return ERR_OK; } - + if ((pcb->flags & TF_RXCLOSED) == 0) { /* Update the PCB (in)activity timer unless rx is closed (see tcp_shutdown) */ pcb->tmr = tcp_ticks; @@ -808,6 +808,9 @@ tcp_process(struct tcp_pcb *pcb) TCP_RMV(&tcp_active_pcbs, pcb); pcb->state = TIME_WAIT; TCP_REG(&tcp_tw_pcbs, pcb); + #if MEMP_NUM_TCP_PCB_TIME_WAIT + TCP_TW_LIMIT(MEMP_NUM_TCP_PCB_TIME_WAIT); + #endif } else { tcp_ack_now(pcb); pcb->state = CLOSING; @@ -825,6 +828,9 @@ tcp_process(struct tcp_pcb *pcb) TCP_RMV(&tcp_active_pcbs, pcb); pcb->state = TIME_WAIT; TCP_REG(&tcp_tw_pcbs, pcb); +#if MEMP_NUM_TCP_PCB_TIME_WAIT + TCP_TW_LIMIT(MEMP_NUM_TCP_PCB_TIME_WAIT); +#endif } break; case CLOSING: @@ -835,6 +841,9 @@ tcp_process(struct tcp_pcb *pcb) TCP_RMV(&tcp_active_pcbs, pcb); pcb->state = TIME_WAIT; TCP_REG(&tcp_tw_pcbs, pcb); +#if MEMP_NUM_TCP_PCB_TIME_WAIT + TCP_TW_LIMIT(MEMP_NUM_TCP_PCB_TIME_WAIT); +#endif } break; case LAST_ACK: @@ -939,7 +948,7 @@ tcp_receive(struct tcp_pcb *pcb) #if TCP_WND_DEBUG } else { if (pcb->snd_wnd != tcphdr->wnd) { - LWIP_DEBUGF(TCP_WND_DEBUG, + LWIP_DEBUGF(TCP_WND_DEBUG, ("tcp_receive: no window update lastack %"U32_F" ackno %" U32_F" wl1 %"U32_F" seqno %"U32_F" wl2 %"U32_F"\n", pcb->lastack, ackno, pcb->snd_wl1, seqno, pcb->snd_wl2)); @@ -954,12 +963,12 @@ tcp_receive(struct tcp_pcb *pcb) * 3) the advertised window hasn't changed ���ش���û�и��� * 4) There is outstanding unacknowledged data (retransmission timer running)������ݵȴ�ȷ�� * 5) The ACK is == biggest ACK sequence number so far seen (snd_una) ackno = lastack - * - * If it passes all five, should process as a dupack: - * a) dupacks < 3: do nothing - * b) dupacks == 3: fast retransmit - * c) dupacks > 3: increase cwnd - * + * + * If it passes all five, should process as a dupack: + * a) dupacks < 3: do nothing + * b) dupacks == 3: fast retransmit + * c) dupacks > 3: increase cwnd + * * If it only passes 1-3, should reset dupack counter (and add to * stats, which we don't do in lwIP) * @@ -1002,10 +1011,10 @@ tcp_receive(struct tcp_pcb *pcb) } } else if (TCP_SEQ_BETWEEN(ackno, pcb->lastack+1, pcb->snd_nxt)){//ackno��lastack+1��snd_nxt֮�䣬�жϷ��ʹ�������� /* We come here when the ACK acknowledges new data. */ - + if (pcb->flags & TF_INFR) { pcb->flags &= ~TF_INFR;// Reset the "IN Fast Retransmit" flag,since we are no longer in fast retransmit - pcb->cwnd = pcb->ssthresh;//Reset the congestion window to the "slow start threshold". + pcb->cwnd = pcb->ssthresh;//Reset the congestion window to the "slow start threshold". } /* Reset the number of retransmissions. */ @@ -1047,7 +1056,7 @@ tcp_receive(struct tcp_pcb *pcb) ntohl(pcb->unacked->tcphdr->seqno) + TCP_TCPLEN(pcb->unacked): 0)); /* Remove segment from the unacknowledged list if the incoming - ACK acknowlegdes them. + ACK acknowlegdes them. *�ͷ�unacked�����ϱ�ȷ�ϵı��ĶΣ� *ֱ��unacked����Ϊ��ֹͣ*/ while (pcb->unacked != NULL && @@ -1068,7 +1077,7 @@ tcp_receive(struct tcp_pcb *pcb) pcb->acked--; } - pcb->snd_queuelen -= pbuf_clen(next->p);//�������������pbufs���� + pcb->snd_queuelen -= pbuf_clen(next->p);//�������������pbufs���� tcp_seg_free(next);//�ͷ�tcp�� LWIP_DEBUGF(TCP_QLEN_DEBUG, ("%"U16_F" (after freeing unacked)\n", (u16_t)pcb->snd_queuelen)); @@ -1099,13 +1108,13 @@ tcp_receive(struct tcp_pcb *pcb) in fact have been sent once. */ /** unsent�������Ƿ��ܱ�acknoȷ�ϵı��ĶΣ������ͷ�**/ while (pcb->unsent != NULL && - TCP_SEQ_BETWEEN(ackno, ntohl(pcb->unsent->tcphdr->seqno) + + TCP_SEQ_BETWEEN(ackno, ntohl(pcb->unsent->tcphdr->seqno) + TCP_TCPLEN(pcb->unsent), pcb->snd_nxt)) { LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_receive: removing %"U32_F":%"U32_F" from pcb->unsent\n", ntohl(pcb->unsent->tcphdr->seqno), ntohl(pcb->unsent->tcphdr->seqno) + TCP_TCPLEN(pcb->unsent))); - next = pcb->unsent;//pcbδ���ͱ�־ + next = pcb->unsent;//pcbδ���ͱ�־ pcb->unsent = pcb->unsent->next;//δ���͵���һ�� LWIP_DEBUGF(TCP_QLEN_DEBUG, ("tcp_receive: queuelen %"U16_F" ... ", (u16_t)pcb->snd_queuelen)); LWIP_ASSERT("pcb->snd_queuelen >= pbuf_clen(next->p)", (pcb->snd_queuelen >= pbuf_clen(next->p))); @@ -1252,7 +1261,7 @@ tcp_receive(struct tcp_pcb *pcb) /* The sequence number must be within the window (above rcv_nxt and below rcv_nxt + rcv_wnd) in order to be further processed. */ - if (TCP_SEQ_BETWEEN(seqno, pcb->rcv_nxt, + if (TCP_SEQ_BETWEEN(seqno, pcb->rcv_nxt, pcb->rcv_nxt + pcb->rcv_wnd - 1)){//rcv_nxt < seqno < rcv_nxt + rcv_wnd - 1,������ڽ��շ�Χ�� if (pcb->rcv_nxt == seqno) { /* The incoming segment is the next in sequence. We check if @@ -1261,12 +1270,12 @@ tcp_receive(struct tcp_pcb *pcb) tcplen = TCP_TCPLEN(&inseg);//���㱨�Ķγ��� if (tcplen > pcb->rcv_wnd) {//������մ��ڴ�С��������β���ض� - LWIP_DEBUGF(TCP_INPUT_DEBUG, + LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_receive: other end overran receive window" "seqno %"U32_F" len %"U16_F" right edge %"U32_F"\n", seqno, tcplen, pcb->rcv_nxt + pcb->rcv_wnd)); if (TCPH_FLAGS(inseg.tcphdr) & TCP_FIN) { - /* Must remove the FIN from the header as we're trimming + /* Must remove the FIN from the header as we're trimming * that byte of sequence-space from the packet */ TCPH_FLAGS_SET(inseg.tcphdr, TCPH_FLAGS(inseg.tcphdr) &~ TCP_FIN); } @@ -1286,7 +1295,7 @@ tcp_receive(struct tcp_pcb *pcb) - inseq overlaps with ooseq */ if (pcb->ooseq != NULL) { if (TCPH_FLAGS(inseg.tcphdr) & TCP_FIN) { - LWIP_DEBUGF(TCP_INPUT_DEBUG, + LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_receive: received in-order FIN, binning ooseq queue\n")); /* Received in-order FIN means anything that was received * out of order must now have been received in-order, so @@ -1394,7 +1403,7 @@ tcp_receive(struct tcp_pcb *pcb) recv_flags |= TF_GOT_FIN; if (pcb->state == ESTABLISHED) { /* force passive close or we can move to active close */ pcb->state = CLOSE_WAIT; - } + } } pcb->ooseq = cseg->next; @@ -1507,12 +1516,12 @@ tcp_receive(struct tcp_pcb *pcb) } /* check if the remote side overruns our receive window */ if ((u32_t)tcplen + seqno > pcb->rcv_nxt + (u32_t)pcb->rcv_wnd) { - LWIP_DEBUGF(TCP_INPUT_DEBUG, + LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_receive: other end overran receive window" "seqno %"U32_F" len %"U16_F" right edge %"U32_F"\n", seqno, tcplen, pcb->rcv_nxt + pcb->rcv_wnd)); if (TCPH_FLAGS(next->next->tcphdr) & TCP_FIN) { - /* Must remove the FIN from the header as we're trimming + /* Must remove the FIN from the header as we're trimming * that byte of sequence-space from the packet */ TCPH_FLAGS_SET(next->next->tcphdr, TCPH_FLAGS(next->next->tcphdr) &~ TCP_FIN); } @@ -1549,7 +1558,7 @@ tcp_receive(struct tcp_pcb *pcb) } /** - * Parses the options contained in the incoming segment. + * Parses the options contained in the incoming segment. * * Called from tcp_listen_input() and tcp_process(). * Currently, only the MSS option is supported! @@ -1606,7 +1615,7 @@ tcp_parseopt(struct tcp_pcb *pcb) return; } /* TCP timestamp option with valid length */ - tsval = (opts[c+2]) | (opts[c+3] << 8) | + tsval = (opts[c+2]) | (opts[c+3] << 8) | (opts[c+4] << 16) | (opts[c+5] << 24); if (flags & TCP_SYN) { pcb->ts_recent = ntohl(tsval); diff --git a/tools/sdk/lwip/src/core/udp.c b/tools/sdk/lwip/src/core/udp.c index db12c48e9..42539d6d7 100644 --- a/tools/sdk/lwip/src/core/udp.c +++ b/tools/sdk/lwip/src/core/udp.c @@ -144,7 +144,7 @@ udp_input(struct pbuf *p, struct netif *inp) /* all packets for DHCP_CLIENT_PORT not coming from DHCP_SERVER_PORT are dropped! */ if (src == DHCP_SERVER_PORT) { if ((inp->dhcp != NULL) && (inp->dhcp->pcb != NULL)) { - /* accept the packe if + /* accept the packe if (- broadcast or directed to us) -> DHCP is link-layer-addressed, local ip is always ANY! - inp->dhcp->pcb->remote == ANY or iphdr->src */ if ((ip_addr_isany(&inp->dhcp->pcb->remote_ip) || @@ -196,7 +196,7 @@ udp_input(struct pbuf *p, struct netif *inp) (broadcast))) { #endif /* IP_SOF_BROADCAST_RECV */ local_match = 1; - if ((uncon_pcb == NULL) && + if ((uncon_pcb == NULL) && ((pcb->flags & UDP_FLAGS_CONNECTED) == 0)) { /* the first unconnected matching PCB */ uncon_pcb = pcb; @@ -422,7 +422,7 @@ udp_send_chksum(struct udp_pcb *pcb, struct pbuf *p, * * If the PCB already has a remote address association, it will * be restored after the data is sent. - * + * * @return lwIP error code (@see udp_send for possible error codes) * * @see udp_disconnect() udp_send() @@ -504,6 +504,7 @@ udp_sendto_if_chksum(struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *dst_ip, ip_addr_t *src_ip; err_t err; struct pbuf *q; /* q will be sent down the stack */ + u8_t ttl; #if IP_SOF_BROADCAST /* broadcast filter? */ @@ -553,11 +554,11 @@ udp_sendto_if_chksum(struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *dst_ip, udphdr->src = htons(pcb->local_port); udphdr->dest = htons(dst_port); /* in UDP, 0 checksum means 'no checksum' */ - udphdr->chksum = 0x0000; + udphdr->chksum = 0x0000; /* Multicast Loop? */ #if LWIP_IGMP - if (ip_addr_ismulticast(dst_ip) && ((pcb->flags & UDP_FLAGS_MULTICAST_LOOP) != 0)) { + if (((pcb->flags & UDP_FLAGS_MULTICAST_LOOP) != 0) && ip_addr_ismulticast(dst_ip)) { q->flags |= PBUF_FLAG_MCASTLOOP; } #endif /* LWIP_IGMP */ @@ -665,13 +666,21 @@ udp_sendto_if_chksum(struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *dst_ip, udphdr->chksum = udpchksum; } #endif /* CHECKSUM_GEN_UDP */ + + /* Determine TTL to use */ +#if LWIP_IGMP + ttl = (ip_addr_ismulticast(dst_ip) ? pcb->mcast_ttl : pcb->ttl); +#else /* LWIP_IGMP */ + ttl = pcb->ttl; +#endif /* LWIP_IGMP */ + LWIP_DEBUGF(UDP_DEBUG, ("udp_send: UDP checksum 0x%04"X16_F"\n", udphdr->chksum)); LWIP_DEBUGF(UDP_DEBUG, ("udp_send: ip_output_if (,,,,IP_PROTO_UDP,)\n")); /* output to IP */ #if LWIP_NETIF_HWADDRHINT netif->addr_hint = &(pcb->addr_hint); #endif /* LWIP_NETIF_HWADDRHINT*/ - err = ip_output_if(q, src_ip, dst_ip, pcb->ttl, pcb->tos, IP_PROTO_UDP, netif); + err = ip_output_if(q, src_ip, dst_ip, ttl, pcb->tos, IP_PROTO_UDP, netif); #if LWIP_NETIF_HWADDRHINT netif->addr_hint = NULL; #endif /* LWIP_NETIF_HWADDRHINT*/ @@ -950,6 +959,9 @@ udp_new(void) /* initialize PCB to all zeroes */ os_memset(pcb, 0, sizeof(struct udp_pcb)); pcb->ttl = UDP_TTL; +#if LWIP_IGMP + pcb->mcast_ttl = UDP_TTL; +#endif } return pcb; }