1 /**
2   ******************************************************************************
3   * @file    lwipopts.h
4   * @author  MCD Application Team
5   * @version V1.0.0
6   * @date    11/20/2009
7   * @brief   lwIP Options Configuration.
8   *          This file is based on Utilities\lwip-1.3.1\src\include\lwip\opt.h
9   *          and contains the lwIP configuration for the STM32F107 demonstration.
10   ******************************************************************************
11   * @copy
12   *
13   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
14   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
15   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
16   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
17   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
18   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
19   *
20   * <h2><center>&copy; COPYRIGHT 2009 STMicroelectronics</center></h2>
21   */
22 
23 #ifndef __LWIPOPTS_H__
24 #define __LWIPOPTS_H__
25 #include "cmsis_os.h"
26 
27 #define LWIP_NOASSERT			1
28 
29 // move from opt.h for bes adapter
30 #define LWIP_TCPIP_CORE_LOCKING         1
31 #define MEMP_NUM_SELECT_CB              8
32 #define MEMP_NUM_TCPIP_MSG_API          16
33 #define ETH_PAD_SIZE                    2
34 #define LWIP_RAW                        1
35 #define LWIP_DNS                        1
36 #define SO_REUSE                        1
37 #define SO_REUSE_RXTOALL                1
38 #define SNTP_SERVER_DNS            	1
39 #define SNTP_STARTUP_DELAY          	0
40 #define SNTP_RECV_TIMEOUT           	5000
41 
42 
43 #define MAX_MSG_IN_LWIP_MBOX 50
44 
45 /*----------------Thread Priority---------------------------------------------*/
46 //#define TCPIP_THREAD_PRIO	    	osPriorityHigh
47 //#define DEFAULT_THREAD_PRIO	    	osPriorityNormal
48 #define TCPIP_THREAD_PRIO	    	31
49 #define DEFAULT_THREAD_PRIO	    	32
50 
51 /**
52  * SYS_LIGHTWEIGHT_PROT==1: if you want inter-task protection for certain
53  * critical regions during buffer allocation, deallocation and memory
54  * allocation and deallocation.
55  */
56 #define SYS_LIGHTWEIGHT_PROT    1
57 
58 /**
59  * NO_SYS==1: Provides VERY minimal functionality. Otherwise,
60  * use lwIP facilities.
61  */
62 #define NO_SYS                  0
63 
64 /* ---------- Memory options ---------- */
65 #define MEM_LIBC_MALLOC                 1
66 extern void *rt_malloc(int size);
67 extern void *rt_calloc(int count, int size);
68 extern void rt_free(void *rmem);
69 #define mem_clib_free rt_free
70 #define mem_clib_malloc rt_malloc
71 #define mem_clib_calloc rt_calloc
72 
73 #define MEMP_MEM_MALLOC                 1
74 
75 #define LWIP_COMPAT_MUTEX_ALLOWED       (1)
76 
77 /* MEM_ALIGNMENT: should be set to the alignment of the CPU for which
78    lwIP is compiled. 4 byte alignment -> define MEM_ALIGNMENT to 4, 2
79    byte alignment -> define MEM_ALIGNMENT to 2. */
80 #define MEM_ALIGNMENT           4
81 
82 /* MEM_SIZE: the size of the heap memory. If the application will send
83 a lot of data that needs to be copied, this should be set high. */
84 #define MEM_SIZE                (20*1024) // used for Lwip malloc
85 
86 #define MAX_SOCKETS_TCP 12
87 #define MAX_LISTENING_SOCKETS_TCP 4
88 #define MAX_SOCKETS_UDP 22
89 #define TCP_SND_BUF_COUNT 5
90 
91 #define TCP_MEM_SIZE     (MAX_SOCKETS_TCP * \
92 							PBUF_POOL_BUFSIZE * (TCP_SND_BUF/TCP_MSS))
93 
94 /* Buffer size needed for UDP: Max. number of UDP sockets * Size of pbuf
95  */
96 #define UDP_MEM_SIZE (MAX_SOCKETS_UDP * PBUF_POOL_BUFSIZE)
97 
98 /* MEMP_NUM_PBUF: the number of memp struct pbufs. If the application
99    sends a lot of data out of ROM (or other static memory), this
100    should be set high. */
101 #define MEMP_NUM_PBUF           10
102 /* MEMP_NUM_UDP_PCB: the number of UDP protocol control blocks. One
103    per active UDP "connection". */
104 #define MEMP_NUM_UDP_PCB        (MAX_SOCKETS_UDP + 2)
105 /* MEMP_NUM_TCP_PCB: the number of simulatenously active TCP
106    connections. */
107 #define MEMP_NUM_TCP_PCB        MAX_SOCKETS_TCP
108 /* MEMP_NUM_TCP_PCB_LISTEN: the number of listening TCP
109    connections. */
110 #define MEMP_NUM_TCP_PCB_LISTEN MAX_LISTENING_SOCKETS_TCP
111 /* MEMP_NUM_TCP_SEG: the number of simultaneously queued TCP
112    segments. */
113 
114 /**
115  * MEMP_NUM_SYS_TIMEOUT: the number of simulateously active timeouts.
116  * (requires NO_SYS==0)
117  */
118 #define MEMP_NUM_SYS_TIMEOUT            12
119 
120 /**
121  * MEMP_NUM_NETBUF: the number of struct netbufs.
122  * (only needed if you use the sequential API, like api_lib.c)
123  */
124 
125 #define MEMP_NUM_NETBUF                 16
126 
127 /**
128  * MEMP_NUM_NETCONN: the number of struct netconns.
129  * (only needed if you use the sequential API, like api_lib.c)
130  *
131  * This number corresponds to the maximum number of active sockets at any
132  * given point in time. This number must be sum of max. TCP sockets, max. TCP
133  * sockets used for listening, and max. number of UDP sockets
134  */
135 #define MEMP_NUM_NETCONN	(MAX_SOCKETS_TCP + \
136 	MAX_LISTENING_SOCKETS_TCP + MAX_SOCKETS_UDP)
137 
138 /* ---------- Pbuf options ---------- */
139 /* PBUF_POOL_SIZE: the number of buffers in the pbuf pool. */
140 #define PBUF_POOL_SIZE          30
141 
142 /* PBUF_POOL_BUFSIZE: the size of each pbuf in the pbuf pool. */
143 #define PBUF_POOL_BUFSIZE       1536
144 
145 /* Enable IPv4 Auto IP	*/
146 #ifdef CONFIG_AUTOIP
147 #define LWIP_AUTOIP                     1
148 #define LWIP_DHCP_AUTOIP_COOP           1
149 #define LWIP_DHCP_AUTOIP_COOP_TRIES		5
150 #endif
151 
152 #define DNS_TABLE_SIZE                 2  // number of table entries, default 4
153 //#define DNS_MAX_NAME_LENGTH            64  // max. name length, default 256
154 #define DNS_MAX_SERVERS                2  // number of DNS servers, default 2
155 #define DNS_DOES_NAME_CHECK            1  // compare received name with given,def 0
156 #define DNS_MSG_SIZE                   512
157 #define MDNS_MSG_SIZE                   512
158 
159 #define MDNS_TABLE_SIZE                 1  // number of mDNS table entries
160 #define MDNS_MAX_SERVERS                1  // number of mDNS multicast addresses
161 /* TODO: Number of active UDP PCBs is equal to number of active UDP sockets plus
162  * two. Need to find the users of these 2 PCBs
163  */
164 
165 
166 /* ---------- TCP options ---------- */
167 #define LWIP_TCP                1
168 #define TCP_TTL                 255
169 
170 
171 #define TCPIP_THREAD_STACKSIZE                  25600 //8192
172 
173 /* Controls if TCP should queue segments that arrive out of
174    order. Define to 0 if your device is low on memory. */
175 #define TCP_QUEUE_OOSEQ         1
176 
177 /**
178  * TCPIP_MBOX_SIZE: The mailbox size for the tcpip thread messages
179  * The queue size value itself is platform-dependent, but is passed to
180  * sys_mbox_new() when tcpip_init is called.
181  */
182 #define MEMP_NUM_TCPIP_MSG_INPKT        64
183 #define TCPIP_MBOX_SIZE                 64
184 
185 /**
186  * DEFAULT_TCP_RECVMBOX_SIZE: The mailbox size for the incoming packets on a
187  * NETCONN_TCP. The queue size value itself is platform-dependent, but is passed
188  * to sys_mbox_new() when the recvmbox is created.
189  */
190 #define DEFAULT_ACCEPTMBOX_SIZE         8
191 #define DEFAULT_RAW_RECVMBOX_SIZE       4
192 #define DEFAULT_TCP_RECVMBOX_SIZE       20
193 
194 /* TCP Maximum segment size. */
195 #define TCP_MSS                 (1500 - 40)      /* TCP_MSS = (Ethernet MTU - IP header size - TCP header size) */
196 
197 /* TCP sender buffer space (bytes). */
198 #define TCP_SND_BUF             (44*TCP_MSS)
199 
200 /* TCP sender buffer space (pbufs). This must be at least = 2 *
201    TCP_SND_BUF/TCP_MSS for things to work. */
202 #define TCP_SND_QUEUELEN        (4* TCP_SND_BUF/TCP_MSS)
203 
204 /* TCP receive window. */
205 #define TCP_WND                 (10*TCP_MSS)
206 
207 /**
208  * Enable TCP_KEEPALIVE
209  */
210 #define LWIP_TCP_KEEPALIVE              1
211 
212 /**
213  * TCP_SYNMAXRTX: Maximum number of retransmissions of SYN segments.
214  */
215 #define TCP_SYNMAXRTX                   10
216 
217 #define TCP_MAX_ACCEPT_CONN 5
218 #define MEMP_NUM_TCP_SEG               (TCP_SND_QUEUELEN*2)
219 
220 #define IP_REASS_MAX_PBUFS              0
221 #define IP_REASSEMBLY                   0
222 #define IP_REASS_MAX_PBUFS              0
223 #define IP_REASSEMBLY                   0
224 #define MEMP_NUM_REASSDATA              0
225 #define IP_FRAG                         0
226 
227 /* ---------- ICMP options ---------- */
228 #define LWIP_ICMP                       1
229 
230 
231 /* ---------- DHCP options ---------- */
232 /* Define LWIP_DHCP to 1 if you want DHCP configuration of
233    interfaces. DHCP is not implemented in lwIP 0.5.1, however, so
234    turning this on does currently not work. */
235 #define LWIP_DHCP               1
236 #define DHCP_DOES_ARP_CHECK     0
237 
238 
239 /* ---------- UDP options ---------- */
240 #define LWIP_UDP                1
241 #define UDP_TTL                 255
242 #define DEFAULT_UDP_RECVMBOX_SIZE       MAX_MSG_IN_LWIP_MBOX
243 
244 /* ---------- Statistics options ---------- */
245 #define LWIP_STATS 0
246 
247 #define LWIP_IGMP 1
248 #if LWIP_IGMP
249 #ifndef LWIP_RAND
250 #define LWIP_RAND() ((u32_t)aos_rand())
251 #endif
252 #endif
253 
254 #define LWIP_RANDOMIZE_INITIAL_LOCAL_PORTS 1
255 
256 #define IP_FORWARD 0
257 
258 #define LWIP_NETIF_STATUS_CALLBACK	1
259 
260 #include <errno.h>
261 #define ERRNO				1
262 
263 /*
264    --------------------------------------
265    ---------- Checksum options ----------
266    --------------------------------------
267 */
268 
269 /*
270 The STM32F107 allows computing and verifying the IP, UDP, TCP and ICMP checksums by hardware:
271  - To use this feature let the following define uncommented.
272  - To disable it and process by CPU comment the  the checksum.
273 */
274 // #define CHECKSUM_BY_HARDWARE
275 
276 #ifdef CHECKSUM_BY_HARDWARE
277   /* CHECKSUM_GEN_IP==0: Generate checksums by hardware for outgoing IP packets.*/
278   #define CHECKSUM_GEN_IP                 1
279   /* CHECKSUM_GEN_UDP==0: Generate checksums by hardware for outgoing UDP packets.*/
280   #define CHECKSUM_GEN_UDP                0
281   /* CHECKSUM_GEN_TCP==0: Generate checksums by hardware for outgoing TCP packets.*/
282   #define CHECKSUM_GEN_TCP                0
283   /* CHECKSUM_CHECK_IP==0: Check checksums by hardware for incoming IP packets.*/
284   #define CHECKSUM_CHECK_IP               1
285   /* CHECKSUM_CHECK_UDP==0: Check checksums by hardware for incoming UDP packets.*/
286   #define CHECKSUM_CHECK_UDP              0
287   /* CHECKSUM_CHECK_TCP==0: Check checksums by hardware for incoming TCP packets.*/
288   #define CHECKSUM_CHECK_TCP              0
289 #else
290   /* CHECKSUM_GEN_IP==1: Generate checksums in software for outgoing IP packets.*/
291   #define CHECKSUM_GEN_IP                 1
292   /* CHECKSUM_GEN_UDP==1: Generate checksums in software for outgoing UDP packets.*/
293   #define CHECKSUM_GEN_UDP                1
294   /* CHECKSUM_GEN_TCP==1: Generate checksums in software for outgoing TCP packets.*/
295   #define CHECKSUM_GEN_TCP                1
296   /* CHECKSUM_CHECK_IP==1: Check checksums in software for incoming IP packets.*/
297   #define CHECKSUM_CHECK_IP               1
298   /* CHECKSUM_CHECK_UDP==1: Check checksums in software for incoming UDP packets.*/
299   #define CHECKSUM_CHECK_UDP              1
300   /* CHECKSUM_CHECK_TCP==1: Check checksums in software for incoming TCP packets.*/
301   #define CHECKSUM_CHECK_TCP              1
302 #endif
303 
304 
305 /*
306    ----------------------------------------------
307    ---------- Sequential layer options ----------
308    ----------------------------------------------
309 */
310 /**
311  * LWIP_NETCONN==1: Enable Netconn API (require to use api_lib.c)
312  */
313 #define LWIP_NETCONN                    1
314 /*
315    ------------------------------------
316    ---------- Socket options ----------
317    ------------------------------------
318 */
319 /**
320  * LWIP_SOCKET==1: Enable Socket API (require to use sockets.c)
321  */
322 #define LWIP_SOCKET                     1
323 #define LWIP_NETIF_API			1
324 
325 /**
326  * LWIP_RECV_CB==1: Enable callback when a socket receives data.
327  */
328 #define LWIP_RECV_CB                1
329 /**
330  * SO_REUSE==1: Enable SO_REUSEADDR option.
331  */
332 #define SO_REUSE                        1
333 #define SO_REUSE_RXTOALL 				1
334 #define LWIP_SO_RCVTIMEO                1
335 #define LWIP_SO_SNDTIMEO                1
336 
337 #define LWIP_SO_RCVBUF 1
338 #define LWIP_SO_RCVTCPBUF 1
339 
340 #define TCP_LISTEN_BACKLOG		1
341 
342 #define ARP_QUEUEING                    1
343 #define LWIP_DHCP_MAX_NTP_SERVERS       3
344 
345 #if defined(LWIP_FULLDUPLEX_SUPPORT)
346 //#define LWIP_NETCONN_FULLDUPLEX 1
347 #define LWIP_NETCONN_SEM_PER_THREAD 1
348 #endif
349 
350 //#define LWIP_PROVIDE_ERRNO 1
351 #define LWIP_MAILBOX_QUEUE  1
352 #define LWIP_TIMEVAL_PRIVATE 0
353 
354 // add for alios things compatible
355 #define LWIP_IPV6                       0
356 
357 #ifdef CONFIG_AOS_MESH
358 #define LWIP_DECLARE_HOOK \
359     struct netif *lwip_hook_ip6_route(const ip6_addr_t *src, const ip6_addr_t *dest); \
360     int lwip_hook_mesh_is_mcast_subscribed(const ip6_addr_t *dest);
361 #define LWIP_HOOK_IP6_ROUTE(src, dest)           lwip_hook_ip6_route(src, dest)
362 #define LWIP_HOOK_MESH_IS_MCAST_SUBSCRIBED(dest) lwip_hook_mesh_is_mcast_subscribed(dest)
363 
364 #define LWIP_ICMP6                      1
365 #define CHECKSUM_CHECK_ICMP6            0
366 #define LWIP_MULTICAST_PING             1
367 
368 #endif
369 
370 /*
371    ------------------------------------
372    --------- customize macros ---------
373    ------------------------------------
374 */
375 /**
376  * LWIP_THREAD_EXIT_HOOK==1: bes add for thread exit proc
377  */
378 #define LWIP_THREAD_EXIT_HOOK			1
379 /**
380  * LWIP_NTP_HOOK==1: bes add for ntp maintain
381  */
382 #define LWIP_NTP_HOOK					1
383 /**
384  * DHCP_REBIND_PRE_ADDR: bes add for DHCP
385  */
386 /* uncommented below define to try to rebind last offerred address when link get reconnected*/
387 //#define DHCP_REBIND_PRE_ADDR
388 #ifdef DHCP_REBIND_PRE_ADDR
389 /* dhcp retry interval ms */
390 #define DHCP_RETRY_INTERVAL	500
391 #endif
392 /**
393  * LWIP_ARP_ENHANCEMENT==1: bes add for arp
394  */
395 #define LWIP_ARP_ENHANCEMENT			1
396 /**
397  * LWIP_NET_STATUS==0: bes add for net flow customize
398  */
399 #define LWIP_NET_STATUS					0
400 /**
401  * LWIP_PBUF_NEW_API==1: bes add new PBUF api
402  */
403 #define LWIP_PBUF_NEW_API				1
404 /**
405  * LWIP_PBUF_NEW_MEMCPY==1: bes add for PBUF use mymemcpy
406  */
407 #define LWIP_PBUF_NEW_MEMCPY			1
408 /**
409  * LWIP_IN_ADDR_TYPE_CSTM==1: bes add for in_addr use u32_t s_addr
410  */
411 #define LWIP_IN_ADDR_TYPE_CSTM			1
412 
413 /*
414  * LWIP_NETIF_HOSTNAME==1: use DHCP_OPTION_HOSTNAME with netif's hostname
415  * field.
416  */
417 #define LWIP_NETIF_HOSTNAME             1
418 
419 /**
420  * Loopback demo related options.
421  */
422 #define LWIP_NETIF_LOOPBACK             1
423 #define LWIP_HAVE_LOOPIF                1
424 #define LWIP_NETIF_LOOPBACK_MULTITHREADING       1
425 #define LWIP_LOOPBACK_MAX_PBUFS         8
426 
427 #define LWIP_TIMERS                     1
428 #define LWIP_TCPIP_TIMEOUT              1
429 
430 /**
431  * TCP_RESOURCE_FAIL_RETRY_LIMIT: limit for retrying sending of tcp segment
432  * on resource failure error returned by driver.
433  */
434 #define TCP_RESOURCE_FAIL_RETRY_LIMIT     50
435 
436 /*
437    ---------------------------------------
438    ---------- Debugging options ----------
439    ---------------------------------------
440 */
441 #define LWIP_DEBUG
442 
443 #define DNS_DEBUG                       LWIP_DBG_OFF
444 #define PKTPRINT_DEBUG                  LWIP_DBG_ON
445 #define ETHARP_DEBUG                    LWIP_DBG_OFF
446 #define REENTER_DEBUG                   LWIP_DBG_OFF
447 #define ARP_DEBUG                       LWIP_DBG_OFF
448 #define DNSCLI_DEBUG                    LWIP_DBG_ON
449 #define IPERF_DEBUG                     LWIP_DBG_ON
450 #define PING_DEBUG                      LWIP_DBG_ON
451 #define IFCONFIG_DEBUG                  LWIP_DBG_ON
452 #define SOCKET_ALLOC_DEBUG              LWIP_DBG_OFF
453 
454 #endif /* __LWIPOPTS_H__ */
455 
456 /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
457