Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers lwip_init.c Source File

lwip_init.c

Go to the documentation of this file.
00001 /**
00002  * @file
00003  * Modules initialization
00004  *
00005  */
00006 
00007 /*
00008  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
00009  * All rights reserved.
00010  *
00011  * Redistribution and use in source and binary forms, with or without modification,
00012  * are permitted provided that the following conditions are met:
00013  *
00014  * 1. Redistributions of source code must retain the above copyright notice,
00015  *    this list of conditions and the following disclaimer.
00016  * 2. Redistributions in binary form must reproduce the above copyright notice,
00017  *    this list of conditions and the following disclaimer in the documentation
00018  *    and/or other materials provided with the distribution.
00019  * 3. The name of the author may not be used to endorse or promote products
00020  *    derived from this software without specific prior written permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
00023  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00024  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
00025  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00026  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
00027  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00028  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00029  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
00030  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
00031  * OF SUCH DAMAGE.
00032  *
00033  * This file is part of the lwIP TCP/IP stack.
00034  *
00035  * Author: Adam Dunkels <adam@sics.se>
00036  */
00037 
00038 #include "lwip/opt.h"
00039 
00040 #include "lwip/init.h"
00041 #include "lwip/stats.h"
00042 #include "lwip/sys.h"
00043 #include "lwip/mem.h"
00044 #include "lwip/memp.h"
00045 #include "lwip/pbuf.h"
00046 #include "lwip/netif.h"
00047 #include "lwip/sockets.h"
00048 #include "lwip/ip.h"
00049 #include "lwip/raw.h"
00050 #include "lwip/udp.h"
00051 #include "lwip/priv/tcp_priv.h"
00052 #include "lwip/igmp.h"
00053 #include "lwip/dns.h"
00054 #include "lwip/timeouts.h"
00055 #include "lwip/etharp.h"
00056 #include "lwip/ip6.h"
00057 #include "lwip/nd6.h"
00058 #include "lwip/mld6.h"
00059 #include "lwip/api.h"
00060 
00061 #ifndef LWIP_SKIP_PACKING_CHECK
00062 
00063 #ifdef PACK_STRUCT_USE_INCLUDES
00064 #  include "arch/bpstruct.h"
00065 #endif
00066 PACK_STRUCT_BEGIN
00067 struct packed_struct_test {
00068   PACK_STRUCT_FLD_8(u8_t  dummy1);
00069   PACK_STRUCT_FIELD(u32_t dummy2);
00070 } PACK_STRUCT_STRUCT;
00071 PACK_STRUCT_END
00072 #ifdef PACK_STRUCT_USE_INCLUDES
00073 #  include "arch/epstruct.h"
00074 #endif
00075 #define PACKED_STRUCT_TEST_EXPECTED_SIZE 5
00076 
00077 #endif
00078 
00079 /* Compile-time sanity checks for configuration errors.
00080  * These can be done independently of LWIP_DEBUG, without penalty.
00081  */
00082 #ifndef BYTE_ORDER
00083 #error "BYTE_ORDER is not defined, you have to define it in your cc.h"
00084 #endif
00085 #if (!IP_SOF_BROADCAST && IP_SOF_BROADCAST_RECV)
00086 #error "If you want to use broadcast filter per pcb on recv operations, you have to define IP_SOF_BROADCAST=1 in your lwipopts.h"
00087 #endif
00088 #if (!LWIP_UDP && LWIP_UDPLITE)
00089 #error "If you want to use UDP Lite, you have to define LWIP_UDP=1 in your lwipopts.h"
00090 #endif
00091 #if (!LWIP_UDP && LWIP_DHCP)
00092 #error "If you want to use DHCP, you have to define LWIP_UDP=1 in your lwipopts.h"
00093 #endif
00094 #if (!LWIP_UDP && !LWIP_RAW && LWIP_MULTICAST_TX_OPTIONS)
00095 #error "If you want to use LWIP_MULTICAST_TX_OPTIONS, you have to define LWIP_UDP=1 and/or LWIP_RAW=1 in your lwipopts.h"
00096 #endif
00097 #if (!LWIP_UDP && LWIP_DNS)
00098 #error "If you want to use DNS, you have to define LWIP_UDP=1 in your lwipopts.h"
00099 #endif
00100 #if !MEMP_MEM_MALLOC /* MEMP_NUM_* checks are disabled when not using the pool allocator */
00101 #if (LWIP_ARP && ARP_QUEUEING && (MEMP_NUM_ARP_QUEUE<=0))
00102 #error "If you want to use ARP Queueing, you have to define MEMP_NUM_ARP_QUEUE>=1 in your lwipopts.h"
00103 #endif
00104 #if (LWIP_RAW && (MEMP_NUM_RAW_PCB<=0))
00105 #error "If you want to use RAW, you have to define MEMP_NUM_RAW_PCB>=1 in your lwipopts.h"
00106 #endif
00107 #if (LWIP_UDP && (MEMP_NUM_UDP_PCB<=0))
00108 #error "If you want to use UDP, you have to define MEMP_NUM_UDP_PCB>=1 in your lwipopts.h"
00109 #endif
00110 #if (LWIP_TCP && (MEMP_NUM_TCP_PCB<=0))
00111 #error "If you want to use TCP, you have to define MEMP_NUM_TCP_PCB>=1 in your lwipopts.h"
00112 #endif
00113 #if (LWIP_IGMP && (MEMP_NUM_IGMP_GROUP<=1))
00114 #error "If you want to use IGMP, you have to define MEMP_NUM_IGMP_GROUP>1 in your lwipopts.h"
00115 #endif
00116 #if (LWIP_IGMP && !LWIP_MULTICAST_TX_OPTIONS)
00117 #error "If you want to use IGMP, you have to define LWIP_MULTICAST_TX_OPTIONS==1 in your lwipopts.h"
00118 #endif
00119 #if (LWIP_IGMP && !LWIP_IPV4)
00120 #error "IGMP needs LWIP_IPV4 enabled in your lwipopts.h"
00121 #endif
00122 #if ((LWIP_NETCONN || LWIP_SOCKET) && (MEMP_NUM_TCPIP_MSG_API<=0))
00123 #error "If you want to use Sequential API, you have to define MEMP_NUM_TCPIP_MSG_API>=1 in your lwipopts.h"
00124 #endif
00125 /* There must be sufficient timeouts, taking into account requirements of the subsystems. */
00126 #if LWIP_TIMERS && (MEMP_NUM_SYS_TIMEOUT < LWIP_NUM_SYS_TIMEOUT_INTERNAL)
00127 #error "MEMP_NUM_SYS_TIMEOUT is too low to accomodate all required timeouts"
00128 #endif
00129 #if (IP_REASSEMBLY && (MEMP_NUM_REASSDATA > IP_REASS_MAX_PBUFS))
00130 #error "MEMP_NUM_REASSDATA > IP_REASS_MAX_PBUFS doesn't make sense since each struct ip_reassdata must hold 2 pbufs at least!"
00131 #endif
00132 #endif /* !MEMP_MEM_MALLOC */
00133 #if LWIP_WND_SCALE
00134 #if (LWIP_TCP && (TCP_WND > 0xffffffff))
00135 #error "If you want to use TCP, TCP_WND must fit in an u32_t, so, you have to reduce it in your lwipopts.h"
00136 #endif
00137 #if (LWIP_TCP && (TCP_RCV_SCALE > 14))
00138 #error "The maximum valid window scale value is 14!"
00139 #endif
00140 #if (LWIP_TCP && (TCP_WND > (0xFFFFU << TCP_RCV_SCALE)))
00141 #error "TCP_WND is bigger than the configured LWIP_WND_SCALE allows!"
00142 #endif
00143 #if (LWIP_TCP && ((TCP_WND >> TCP_RCV_SCALE) == 0))
00144 #error "TCP_WND is too small for the configured LWIP_WND_SCALE (results in zero window)!"
00145 #endif
00146 #else /* LWIP_WND_SCALE */
00147 #if (LWIP_TCP && (TCP_WND > 0xffff))
00148 #error "If you want to use TCP, TCP_WND must fit in an u16_t, so, you have to reduce it in your lwipopts.h (or enable window scaling)"
00149 #endif
00150 #endif /* LWIP_WND_SCALE */
00151 #if (LWIP_TCP && (TCP_SND_QUEUELEN > 0xffff))
00152 #error "If you want to use TCP, TCP_SND_QUEUELEN must fit in an u16_t, so, you have to reduce it in your lwipopts.h"
00153 #endif
00154 #if (LWIP_TCP && (TCP_SND_QUEUELEN < 2))
00155 #error "TCP_SND_QUEUELEN must be at least 2 for no-copy TCP writes to work"
00156 #endif
00157 #if (LWIP_TCP && ((TCP_MAXRTX > 12) || (TCP_SYNMAXRTX > 12)))
00158 #error "If you want to use TCP, TCP_MAXRTX and TCP_SYNMAXRTX must less or equal to 12 (due to tcp_backoff table), so, you have to reduce them in your lwipopts.h"
00159 #endif
00160 #if (LWIP_TCP && TCP_LISTEN_BACKLOG && ((TCP_DEFAULT_LISTEN_BACKLOG < 0) || (TCP_DEFAULT_LISTEN_BACKLOG > 0xff)))
00161 #error "If you want to use TCP backlog, TCP_DEFAULT_LISTEN_BACKLOG must fit into an u8_t"
00162 #endif
00163 #if (LWIP_TCP && LWIP_TCP_SACK_OUT && !TCP_QUEUE_OOSEQ)
00164 #error "To use LWIP_TCP_SACK_OUT, TCP_QUEUE_OOSEQ needs to be enabled"
00165 #endif
00166 #if (LWIP_TCP && LWIP_TCP_SACK_OUT && (LWIP_TCP_MAX_SACK_NUM < 1))
00167 #error "LWIP_TCP_MAX_SACK_NUM must be greater than 0"
00168 #endif
00169 #if (LWIP_NETIF_API && (NO_SYS==1))
00170 #error "If you want to use NETIF API, you have to define NO_SYS=0 in your lwipopts.h"
00171 #endif
00172 #if ((LWIP_SOCKET || LWIP_NETCONN) && (NO_SYS==1))
00173 #error "If you want to use Sequential API, you have to define NO_SYS=0 in your lwipopts.h"
00174 #endif
00175 #if (((!LWIP_DHCP) || (!LWIP_AUTOIP)) && LWIP_DHCP_AUTOIP_COOP)
00176 #error "If you want to use DHCP/AUTOIP cooperation mode, you have to define LWIP_DHCP=1 and LWIP_AUTOIP=1 in your lwipopts.h"
00177 #endif
00178 #if (((!LWIP_DHCP) || (!LWIP_ARP)) && DHCP_DOES_ARP_CHECK)
00179 #error "If you want to use DHCP ARP checking, you have to define LWIP_DHCP=1 and LWIP_ARP=1 in your lwipopts.h"
00180 #endif
00181 #if (!LWIP_ARP && LWIP_AUTOIP)
00182 #error "If you want to use AUTOIP, you have to define LWIP_ARP=1 in your lwipopts.h"
00183 #endif
00184 #if (LWIP_TCP && ((LWIP_EVENT_API && LWIP_CALLBACK_API) || (!LWIP_EVENT_API && !LWIP_CALLBACK_API)))
00185 #error "One and exactly one of LWIP_EVENT_API and LWIP_CALLBACK_API has to be enabled in your lwipopts.h"
00186 #endif
00187 #if (LWIP_ALTCP && LWIP_EVENT_API)
00188 #error "The application layered tcp API does not work with LWIP_EVENT_API"
00189 #endif
00190 #if (MEM_LIBC_MALLOC && MEM_USE_POOLS)
00191 #error "MEM_LIBC_MALLOC and MEM_USE_POOLS may not both be simultaneously enabled in your lwipopts.h"
00192 #endif
00193 #if (MEM_USE_POOLS && !MEMP_USE_CUSTOM_POOLS)
00194 #error "MEM_USE_POOLS requires custom pools (MEMP_USE_CUSTOM_POOLS) to be enabled in your lwipopts.h"
00195 #endif
00196 #if (PBUF_POOL_BUFSIZE <= MEM_ALIGNMENT)
00197 #error "PBUF_POOL_BUFSIZE must be greater than MEM_ALIGNMENT or the offset may take the full first pbuf"
00198 #endif
00199 #if (DNS_LOCAL_HOSTLIST && !DNS_LOCAL_HOSTLIST_IS_DYNAMIC && !(defined(DNS_LOCAL_HOSTLIST_INIT)))
00200 #error "you have to define define DNS_LOCAL_HOSTLIST_INIT {{'host1', 0x123}, {'host2', 0x234}} to initialize DNS_LOCAL_HOSTLIST"
00201 #endif
00202 #if !LWIP_ETHERNET && LWIP_ARP
00203 #error "LWIP_ETHERNET needs to be turned on for LWIP_ARP"
00204 #endif
00205 #if LWIP_TCPIP_CORE_LOCKING_INPUT && !LWIP_TCPIP_CORE_LOCKING
00206 #error "When using LWIP_TCPIP_CORE_LOCKING_INPUT, LWIP_TCPIP_CORE_LOCKING must be enabled, too"
00207 #endif
00208 #if LWIP_TCP && LWIP_NETIF_TX_SINGLE_PBUF && !TCP_OVERSIZE
00209 #error "LWIP_NETIF_TX_SINGLE_PBUF needs TCP_OVERSIZE enabled to create single-pbuf TCP packets"
00210 #endif
00211 #if LWIP_NETCONN && LWIP_TCP
00212 #if NETCONN_COPY != TCP_WRITE_FLAG_COPY
00213 #error "NETCONN_COPY != TCP_WRITE_FLAG_COPY"
00214 #endif
00215 #if NETCONN_MORE != TCP_WRITE_FLAG_MORE
00216 #error "NETCONN_MORE != TCP_WRITE_FLAG_MORE"
00217 #endif
00218 #endif /* LWIP_NETCONN && LWIP_TCP */
00219 #if LWIP_SOCKET
00220 #endif /* LWIP_SOCKET */
00221 
00222 
00223 /* Compile-time checks for deprecated options.
00224  */
00225 #ifdef MEMP_NUM_TCPIP_MSG
00226 #error "MEMP_NUM_TCPIP_MSG option is deprecated. Remove it from your lwipopts.h."
00227 #endif
00228 #ifdef TCP_REXMIT_DEBUG
00229 #error "TCP_REXMIT_DEBUG option is deprecated. Remove it from your lwipopts.h."
00230 #endif
00231 #ifdef RAW_STATS
00232 #error "RAW_STATS option is deprecated. Remove it from your lwipopts.h."
00233 #endif
00234 #ifdef ETHARP_QUEUE_FIRST
00235 #error "ETHARP_QUEUE_FIRST option is deprecated. Remove it from your lwipopts.h."
00236 #endif
00237 #ifdef ETHARP_ALWAYS_INSERT
00238 #error "ETHARP_ALWAYS_INSERT option is deprecated. Remove it from your lwipopts.h."
00239 #endif
00240 #if !NO_SYS && LWIP_TCPIP_CORE_LOCKING && LWIP_COMPAT_MUTEX && !defined(LWIP_COMPAT_MUTEX_ALLOWED)
00241 #error "LWIP_COMPAT_MUTEX cannot prevent priority inversion. It is recommended to implement priority-aware mutexes. (Define LWIP_COMPAT_MUTEX_ALLOWED to disable this error.)"
00242 #endif
00243 
00244 #ifndef LWIP_DISABLE_TCP_SANITY_CHECKS
00245 #define LWIP_DISABLE_TCP_SANITY_CHECKS  0
00246 #endif
00247 #ifndef LWIP_DISABLE_MEMP_SANITY_CHECKS
00248 #define LWIP_DISABLE_MEMP_SANITY_CHECKS 0
00249 #endif
00250 
00251 /* MEMP sanity checks */
00252 #if MEMP_MEM_MALLOC
00253 #if !LWIP_DISABLE_MEMP_SANITY_CHECKS
00254 #if LWIP_NETCONN || LWIP_SOCKET
00255 #if !MEMP_NUM_NETCONN && LWIP_SOCKET
00256 #error "lwip_sanity_check: WARNING: MEMP_NUM_NETCONN cannot be 0 when using sockets!"
00257 #endif
00258 #else /* MEMP_MEM_MALLOC */
00259 #if MEMP_NUM_NETCONN > (MEMP_NUM_TCP_PCB+MEMP_NUM_TCP_PCB_LISTEN+MEMP_NUM_UDP_PCB+MEMP_NUM_RAW_PCB)
00260 #error "lwip_sanity_check: WARNING: MEMP_NUM_NETCONN should be less than the sum of MEMP_NUM_{TCP,RAW,UDP}_PCB+MEMP_NUM_TCP_PCB_LISTEN. If you know what you are doing, define LWIP_DISABLE_MEMP_SANITY_CHECKS to 1 to disable this error."
00261 #endif
00262 #endif /* LWIP_NETCONN || LWIP_SOCKET */
00263 #endif /* !LWIP_DISABLE_MEMP_SANITY_CHECKS */
00264 #if MEM_USE_POOLS
00265 #error "MEMP_MEM_MALLOC and MEM_USE_POOLS cannot be enabled at the same time"
00266 #endif
00267 #ifdef LWIP_HOOK_MEMP_AVAILABLE
00268 #error "LWIP_HOOK_MEMP_AVAILABLE doesn't make sense with MEMP_MEM_MALLOC"
00269 #endif
00270 #endif /* MEMP_MEM_MALLOC */
00271 
00272 /* TCP sanity checks */
00273 #if !LWIP_DISABLE_TCP_SANITY_CHECKS
00274 #if LWIP_TCP
00275 #if !MEMP_MEM_MALLOC && (MEMP_NUM_TCP_SEG < TCP_SND_QUEUELEN)
00276 #error "lwip_sanity_check: WARNING: MEMP_NUM_TCP_SEG should be at least as big as TCP_SND_QUEUELEN. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error."
00277 #endif
00278 #if TCP_SND_BUF < (2 * TCP_MSS)
00279 #error "lwip_sanity_check: WARNING: TCP_SND_BUF must be at least as much as (2 * TCP_MSS) for things to work smoothly. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error."
00280 #endif
00281 #if TCP_SND_QUEUELEN < (2 * (TCP_SND_BUF / TCP_MSS))
00282 #error "lwip_sanity_check: WARNING: TCP_SND_QUEUELEN must be at least as much as (2 * TCP_SND_BUF/TCP_MSS) for things to work. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error."
00283 #endif
00284 #if TCP_SNDLOWAT >= TCP_SND_BUF
00285 #error "lwip_sanity_check: WARNING: TCP_SNDLOWAT must be less than TCP_SND_BUF. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error."
00286 #endif
00287 #if TCP_SNDLOWAT >= (0xFFFF - (4 * TCP_MSS))
00288 #error "lwip_sanity_check: WARNING: TCP_SNDLOWAT must at least be 4*MSS below u16_t overflow!"
00289 #endif
00290 #if TCP_SNDQUEUELOWAT >= TCP_SND_QUEUELEN
00291 #error "lwip_sanity_check: WARNING: TCP_SNDQUEUELOWAT must be less than TCP_SND_QUEUELEN. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error."
00292 #endif
00293 #if !MEMP_MEM_MALLOC && PBUF_POOL_SIZE && (PBUF_POOL_BUFSIZE <= (PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN + PBUF_IP_HLEN + PBUF_TRANSPORT_HLEN))
00294 #error "lwip_sanity_check: WARNING: PBUF_POOL_BUFSIZE does not provide enough space for protocol headers. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error."
00295 #endif
00296 #if !MEMP_MEM_MALLOC && PBUF_POOL_SIZE && (TCP_WND > (PBUF_POOL_SIZE * (PBUF_POOL_BUFSIZE - (PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN + PBUF_IP_HLEN + PBUF_TRANSPORT_HLEN))))
00297 #error "lwip_sanity_check: WARNING: TCP_WND is larger than space provided by PBUF_POOL_SIZE * (PBUF_POOL_BUFSIZE - protocol headers). If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error."
00298 #endif
00299 #if TCP_WND < TCP_MSS
00300 #error "lwip_sanity_check: WARNING: TCP_WND is smaller than MSS. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error."
00301 #endif
00302 #endif /* LWIP_TCP */
00303 #endif /* !LWIP_DISABLE_TCP_SANITY_CHECKS */
00304 
00305 /**
00306  * @ingroup lwip_nosys
00307  * Initialize all modules.
00308  * Use this in NO_SYS mode. Use tcpip_init() otherwise.
00309  */
00310 void
00311 lwip_init(void)
00312 {
00313 #ifndef LWIP_SKIP_CONST_CHECK
00314   int a = 0;
00315   LWIP_UNUSED_ARG(a);
00316   LWIP_ASSERT("LWIP_CONST_CAST not implemented correctly. Check your lwIP port.", LWIP_CONST_CAST(void *, &a) == &a);
00317 #endif
00318 #ifndef LWIP_SKIP_PACKING_CHECK
00319   LWIP_ASSERT("Struct packing not implemented correctly. Check your lwIP port.", sizeof(struct packed_struct_test) == PACKED_STRUCT_TEST_EXPECTED_SIZE);
00320 #endif
00321 
00322   /* Modules initialization */
00323   stats_init();
00324 #if !NO_SYS
00325   sys_init();
00326 #endif /* !NO_SYS */
00327   mem_init();
00328   memp_init();
00329   pbuf_init();
00330   netif_init();
00331 #if LWIP_IPV4
00332   ip_init();
00333 #if LWIP_ARP
00334   etharp_init();
00335 #endif /* LWIP_ARP */
00336 #endif /* LWIP_IPV4 */
00337 #if LWIP_RAW
00338   raw_init();
00339 #endif /* LWIP_RAW */
00340 #if LWIP_UDP
00341   udp_init();
00342 #endif /* LWIP_UDP */
00343 #if LWIP_TCP
00344   tcp_init();
00345 #endif /* LWIP_TCP */
00346 #if LWIP_IGMP
00347   igmp_init();
00348 #endif /* LWIP_IGMP */
00349 #if LWIP_DNS
00350   dns_init();
00351 #endif /* LWIP_DNS */
00352 
00353 #if LWIP_TIMERS
00354   sys_timeouts_init();
00355 #endif /* LWIP_TIMERS */
00356 }