Skip to content

Commit 07f4d4c

Browse files
me-no-devigrr
authored andcommitted
Lwip addons (#2260)
* Add multicast TTL to UDP and rework UdpContext * Add limit for TCP TIME_WAIT pcbs * Add liblwip_gcc.a * Make the changes be backward compatible with the current xcc version
1 parent 8606733 commit 07f4d4c

File tree

10 files changed

+297
-229
lines changed

10 files changed

+297
-229
lines changed

Diff for: boards.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1680,7 +1680,7 @@ coredev.build.lwip_flags=
16801680

16811681
coredev.menu.LwIPVariant.Espressif=Espressif (xcc)
16821682
coredev.menu.LwIPVariant.Espressif.build.lwip_lib=-llwip
1683-
coredev.menu.LwIPVariant.Espressif.build.lwip_flags=
1683+
coredev.menu.LwIPVariant.Espressif.build.lwip_flags=-DLWIP_MAYBE_XCC
16841684
coredev.menu.LwIPVariant.Prebuilt=Prebuilt Source (gcc)
16851685
coredev.menu.LwIPVariant.Prebuilt.build.lwip_lib=-llwip_gcc
16861686
coredev.menu.LwIPVariant.Prebuilt.build.lwip_flags=-DLWIP_OPEN_SRC

Diff for: libraries/ESP8266WiFi/src/include/UdpContext.h

+21-20
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ class UdpContext
4444
, _tx_buf_head(0)
4545
, _tx_buf_cur(0)
4646
, _tx_buf_offset(0)
47-
, _multicast_ttl(1)
48-
, _dest_port(0)
4947
{
5048
_pcb = udp_new();
51-
_dest_addr.addr = 0;
49+
#ifdef LWIP_MAYBE_XCC
50+
_mcast_ttl = 1;
51+
#endif
5252
}
5353

5454
~UdpContext()
@@ -87,8 +87,8 @@ class UdpContext
8787

8888
bool connect(ip_addr_t addr, uint16_t port)
8989
{
90-
_dest_addr = addr;
91-
_dest_port = port;
90+
ip_addr_copy(_pcb->remote_ip, addr);
91+
_pcb->remote_port = port;
9292
return true;
9393
}
9494

@@ -106,17 +106,16 @@ class UdpContext
106106

107107
void setMulticastInterface(ip_addr_t addr)
108108
{
109-
// newer versions of lwip have a macro to set the multicast ip
110-
// udp_set_multicast_netif_addr(_pcb, addr);
111-
_pcb->multicast_ip = addr;
109+
udp_set_multicast_netif_addr(_pcb, addr);
112110
}
113111

114112
void setMulticastTTL(int ttl)
115113
{
116-
// newer versions of lwip have an additional field (mcast_ttl) for this purpose
117-
// and a macro to set it instead of direct field access
118-
// udp_set_multicast_ttl(_pcb, ttl);
119-
_multicast_ttl = ttl;
114+
#ifdef LWIP_MAYBE_XCC
115+
_mcast_ttl = ttl;
116+
#else
117+
udp_set_multicast_ttl(_pcb, ttl);
118+
#endif
120119
}
121120

122121
// warning: handler is called from tcp stack context
@@ -275,20 +274,22 @@ class UdpContext
275274

276275

277276
if (!addr) {
278-
addr = &_dest_addr;
279-
port = _dest_port;
277+
addr = &_pcb->remote_ip;
278+
port = _pcb->remote_port;
280279
}
281-
280+
#ifdef LWIP_MAYBE_XCC
282281
uint16_t old_ttl = _pcb->ttl;
283282
if (ip_addr_ismulticast(addr)) {
284-
_pcb->ttl = _multicast_ttl;
283+
_pcb->ttl = _mcast_ttl;
285284
}
286-
285+
#endif
287286
err_t err = udp_sendto(_pcb, tx_copy, addr, port);
288287
if (err != ERR_OK) {
289288
DEBUGV(":ust rc=%d\r\n", err);
290289
}
290+
#ifdef LWIP_MAYBE_XCC
291291
_pcb->ttl = old_ttl;
292+
#endif
292293
pbuf_free(tx_copy);
293294
return err == ERR_OK;
294295
}
@@ -365,10 +366,10 @@ class UdpContext
365366
pbuf* _tx_buf_head;
366367
pbuf* _tx_buf_cur;
367368
size_t _tx_buf_offset;
368-
uint16_t _multicast_ttl;
369-
uint16_t _dest_port;
370-
ip_addr_t _dest_addr;
371369
rxhandler_t _on_rx;
370+
#ifdef LWIP_MAYBE_XCC
371+
uint16_t _mcast_ttl;
372+
#endif
372373
};
373374

374375

Diff for: tools/sdk/lib/liblwip_gcc.a

8.35 KB
Binary file not shown.

Diff for: tools/sdk/lwip/include/lwip/tcp_impl.h

+37-17
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
22
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
3-
* All rights reserved.
4-
*
5-
* Redistribution and use in source and binary forms, with or without modification,
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without modification,
66
* are permitted provided that the following conditions are met:
77
*
88
* 1. Redistributions of source code must retain the above copyright notice,
@@ -11,21 +11,21 @@
1111
* this list of conditions and the following disclaimer in the documentation
1212
* and/or other materials provided with the distribution.
1313
* 3. The name of the author may not be used to endorse or promote products
14-
* derived from this software without specific prior written permission.
14+
* derived from this software without specific prior written permission.
1515
*
16-
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17-
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18-
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19-
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20-
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
21-
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22-
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23-
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24-
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
16+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17+
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18+
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19+
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
21+
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24+
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
2525
* OF SUCH DAMAGE.
2626
*
2727
* This file is part of the lwIP TCP/IP stack.
28-
*
28+
*
2929
* Author: Adam Dunkels <adam@sics.se>
3030
*
3131
*/
@@ -284,7 +284,7 @@ struct tcp_seg {
284284
u16_t oversize_left; /* Extra bytes available at the end of the last
285285
pbuf in unsent (used for asserting vs.
286286
tcp_pcb.unsent_oversized only) */
287-
#endif /* TCP_OVERSIZE_DBGCHECK */
287+
#endif /* TCP_OVERSIZE_DBGCHECK */
288288
#if TCP_CHECKSUM_ON_COPY
289289
u16_t chksum;
290290
u8_t chksum_swapped;
@@ -313,7 +313,7 @@ extern u32_t tcp_ticks;
313313

314314
/* The TCP PCB lists. */
315315
union tcp_listen_pcbs_t { /* List of all TCP PCBs in LISTEN state. */
316-
struct tcp_pcb_listen *listen_pcbs;
316+
struct tcp_pcb_listen *listen_pcbs;
317317
struct tcp_pcb *pcbs;
318318
};
319319
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. *
325325

326326
extern struct tcp_pcb *tcp_tmp_pcb; /* Only used for temporary storage. */
327327

328-
/* Axioms about the above lists:
328+
/* Axioms about the above lists:
329329
1) Every TCP PCB that is not CLOSED is in one of the lists.
330330
2) A PCB is only in one of the lists.
331331
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. */
396396

397397
#endif /* LWIP_DEBUG */
398398

399+
#define TCP_TW_LIMIT(l) \
400+
do { \
401+
u32_t tcp_tmp_pcbs_count = 0; \
402+
tcp_tmp_pcb = tcp_tw_pcbs; \
403+
while(tcp_tmp_pcb != NULL) { \
404+
if(++tcp_tmp_pcbs_count == (l)) { \
405+
struct tcp_pcb *_tcp_tmp_pcb = tcp_tmp_pcb->next; \
406+
tcp_tmp_pcb->next = NULL; \
407+
tcp_tmp_pcb = _tcp_tmp_pcb; \
408+
while(tcp_tmp_pcb != NULL) { \
409+
_tcp_tmp_pcb = tcp_tmp_pcb; \
410+
tcp_pcb_purge(tcp_tmp_pcb); \
411+
tcp_tmp_pcb = tcp_tmp_pcb->next; \
412+
memp_free(MEMP_TCP_PCB, _tcp_tmp_pcb); \
413+
} \
414+
break; \
415+
} \
416+
tcp_tmp_pcb = tcp_tmp_pcb->next; \
417+
} \
418+
} while(0)
399419

400420
/* Internal functions: */
401421
struct tcp_pcb *tcp_pcb_copy(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR;

Diff for: tools/sdk/lwip/include/lwip/udp.h

+28-15
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
22
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
3-
* All rights reserved.
4-
*
5-
* Redistribution and use in source and binary forms, with or without modification,
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without modification,
66
* are permitted provided that the following conditions are met:
77
*
88
* 1. Redistributions of source code must retain the above copyright notice,
@@ -11,21 +11,21 @@
1111
* this list of conditions and the following disclaimer in the documentation
1212
* and/or other materials provided with the distribution.
1313
* 3. The name of the author may not be used to endorse or promote products
14-
* derived from this software without specific prior written permission.
14+
* derived from this software without specific prior written permission.
1515
*
16-
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17-
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18-
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19-
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20-
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
21-
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22-
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23-
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24-
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
16+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17+
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18+
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19+
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
21+
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24+
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
2525
* OF SUCH DAMAGE.
2626
*
2727
* This file is part of the lwIP TCP/IP stack.
28-
*
28+
*
2929
* Author: Adam Dunkels <adam@sics.se>
3030
*
3131
*/
@@ -103,6 +103,10 @@ struct udp_pcb {
103103
#if LWIP_IGMP
104104
/** outgoing network interface for multicast packets */
105105
ip_addr_t multicast_ip;
106+
#ifndef LWIP_MAYBE_XCC
107+
/** TTL for outgoing multicast packets */
108+
u8_t mcast_ttl;
109+
#endif /* LWIP_MAYBE_XCC */
106110
#endif /* LWIP_IGMP */
107111

108112
#if LWIP_UDPLITE
@@ -113,7 +117,7 @@ struct udp_pcb {
113117
/** receive callback function */
114118
udp_recv_fn recv;
115119
/** user-supplied argument for the recv callback */
116-
void *recv_arg;
120+
void *recv_arg;
117121
};
118122
/* udp_pcbs export for exernal reference (e.g. SNMP agent) */
119123
extern struct udp_pcb *udp_pcbs;
@@ -156,6 +160,15 @@ void udp_input (struct pbuf *p, struct netif *inp)ICACHE_FLASH_
156160

157161
#define udp_init() /* Compatibility define, not init needed. */
158162

163+
#if LWIP_IGMP
164+
#define udp_set_multicast_netif_addr(pcb, ipaddr) ip_addr_copy((pcb)->multicast_ip, (ipaddr))
165+
#define udp_get_multicast_netif_addr(pcb) ((pcb)->multicast_ip)
166+
#ifndef LWIP_MAYBE_XCC
167+
#define udp_set_multicast_ttl(pcb, value) do { (pcb)->mcast_ttl = value; } while(0)
168+
#define udp_get_multicast_ttl(pcb) ((pcb)->mcast_ttl)
169+
#endif /* LWIP_MAYBE_XCC */
170+
#endif /* LWIP_IGMP */
171+
159172
#if UDP_DEBUG
160173
void udp_debug_print(struct udp_hdr *udphdr)ICACHE_FLASH_ATTR;
161174
#else

0 commit comments

Comments
 (0)