My fork of the HTTPServer (working)
Embed:
(wiki syntax)
Show/hide line numbers
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 00039 #include "lwip/opt.h" 00040 00041 #include "lwip/init.h" 00042 #include "lwip/stats.h" 00043 #include "lwip/sys.h" 00044 #include "lwip/mem.h" 00045 #include "lwip/memp.h" 00046 #include "lwip/pbuf.h" 00047 #include "lwip/netif.h" 00048 #include "lwip/sockets.h" 00049 #include "lwip/ip.h" 00050 #include "lwip/raw.h" 00051 #include "lwip/udp.h" 00052 #include "lwip/tcp.h" 00053 #include "lwip/autoip.h" 00054 #include "lwip/igmp.h" 00055 #include "lwip/dns.h" 00056 #include "netif/etharp.h" 00057 00058 /* Compile-time sanity checks for configuration errors. 00059 * These can be done independently of LWIP_DEBUG, without penalty. 00060 */ 00061 #ifndef BYTE_ORDER 00062 #error "BYTE_ORDER is not defined, you have to define it in your cc.h" 00063 #endif 00064 #if (!LWIP_ARP && ARP_QUEUEING) 00065 #error "If you want to use ARP Queueing, you have to define LWIP_ARP=1 in your lwipopts.h" 00066 #endif 00067 #if (!LWIP_UDP && LWIP_UDPLITE) 00068 #error "If you want to use UDP Lite, you have to define LWIP_UDP=1 in your lwipopts.h" 00069 #endif 00070 #if (!LWIP_UDP && LWIP_SNMP) 00071 #error "If you want to use SNMP, you have to define LWIP_UDP=1 in your lwipopts.h" 00072 #endif 00073 #if (!LWIP_UDP && LWIP_DHCP) 00074 #error "If you want to use DHCP, you have to define LWIP_UDP=1 in your lwipopts.h" 00075 #endif 00076 #if (!LWIP_UDP && LWIP_IGMP) 00077 #error "If you want to use IGMP, you have to define LWIP_UDP=1 in your lwipopts.h" 00078 #endif 00079 #if (!LWIP_UDP && LWIP_DNS) 00080 #error "If you want to use DNS, you have to define LWIP_UDP=1 in your lwipopts.h" 00081 #endif 00082 #if (LWIP_ARP && (ARP_TABLE_SIZE > 0x7f)) 00083 #error "If you want to use ARP, ARP_TABLE_SIZE must fit in an s8_t, so, you have to reduce it in your lwipopts.h" 00084 #endif 00085 #if (LWIP_ARP && ARP_QUEUEING && (MEMP_NUM_ARP_QUEUE<=0)) 00086 #error "If you want to use ARP Queueing, you have to define MEMP_NUM_ARP_QUEUE>=1 in your lwipopts.h" 00087 #endif 00088 #if (LWIP_RAW && (MEMP_NUM_RAW_PCB<=0)) 00089 #error "If you want to use RAW, you have to define MEMP_NUM_RAW_PCB>=1 in your lwipopts.h" 00090 #endif 00091 #if (LWIP_UDP && (MEMP_NUM_UDP_PCB<=0)) 00092 #error "If you want to use UDP, you have to define MEMP_NUM_UDP_PCB>=1 in your lwipopts.h" 00093 #endif 00094 #if (LWIP_TCP && (MEMP_NUM_TCP_PCB<=0)) 00095 #error "If you want to use TCP, you have to define MEMP_NUM_TCP_PCB>=1 in your lwipopts.h" 00096 #endif 00097 #if (LWIP_TCP && (TCP_WND > 0xffff)) 00098 #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" 00099 #endif 00100 #if (LWIP_TCP && (TCP_SND_QUEUELEN > 0xffff)) 00101 #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" 00102 #endif 00103 #if (LWIP_TCP && ((TCP_MAXRTX > 12) || (TCP_SYNMAXRTX > 12))) 00104 #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" 00105 #endif 00106 #if (LWIP_TCP && TCP_LISTEN_BACKLOG && (TCP_DEFAULT_LISTEN_BACKLOG < 0) || (TCP_DEFAULT_LISTEN_BACKLOG > 0xff)) 00107 #error "If you want to use TCP backlog, TCP_DEFAULT_LISTEN_BACKLOG must fit into an u8_t" 00108 #endif 00109 #if (LWIP_IGMP && (MEMP_NUM_IGMP_GROUP<=1)) 00110 #error "If you want to use IGMP, you have to define MEMP_NUM_IGMP_GROUP>1 in your lwipopts.h" 00111 #endif 00112 #if (PPP_SUPPORT && (NO_SYS==1)) 00113 #error "If you want to use PPP, you have to define NO_SYS=0 in your lwipopts.h" 00114 #endif 00115 #if (LWIP_NETIF_API && (NO_SYS==1)) 00116 #error "If you want to use NETIF API, you have to define NO_SYS=0 in your lwipopts.h" 00117 #endif 00118 #if ((LWIP_SOCKET || LWIP_NETCONN) && (NO_SYS==1)) 00119 #error "If you want to use Sequential API, you have to define NO_SYS=0 in your lwipopts.h" 00120 #endif 00121 #if ((LWIP_NETCONN || LWIP_SOCKET) && (MEMP_NUM_TCPIP_MSG_API<=0)) 00122 #error "If you want to use Sequential API, you have to define MEMP_NUM_TCPIP_MSG_API>=1 in your lwipopts.h" 00123 #endif 00124 #if (!LWIP_NETCONN && LWIP_SOCKET) 00125 #error "If you want to use Socket API, you have to define LWIP_NETCONN=1 in your lwipopts.h" 00126 #endif 00127 #if (((!LWIP_DHCP) || (!LWIP_AUTOIP)) && LWIP_DHCP_AUTOIP_COOP) 00128 #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" 00129 #endif 00130 #if (((!LWIP_DHCP) || (!LWIP_ARP)) && DHCP_DOES_ARP_CHECK) 00131 #error "If you want to use DHCP ARP checking, you have to define LWIP_DHCP=1 and LWIP_ARP=1 in your lwipopts.h" 00132 #endif 00133 #if (!LWIP_ARP && LWIP_AUTOIP) 00134 #error "If you want to use AUTOIP, you have to define LWIP_ARP=1 in your lwipopts.h" 00135 #endif 00136 #if (LWIP_SNMP && (SNMP_CONCURRENT_REQUESTS<=0)) 00137 #error "If you want to use SNMP, you have to define SNMP_CONCURRENT_REQUESTS>=1 in your lwipopts.h" 00138 #endif 00139 #if (LWIP_SNMP && (SNMP_TRAP_DESTINATIONS<=0)) 00140 #error "If you want to use SNMP, you have to define SNMP_TRAP_DESTINATIONS>=1 in your lwipopts.h" 00141 #endif 00142 #if (LWIP_TCP && ((LWIP_EVENT_API && LWIP_CALLBACK_API) || (!LWIP_EVENT_API && !LWIP_CALLBACK_API))) 00143 #error "One and exactly one of LWIP_EVENT_API and LWIP_CALLBACK_API has to be enabled in your lwipopts.h" 00144 #endif 00145 /* There must be sufficient timeouts, taking into account requirements of the subsystems. */ 00146 #if ((NO_SYS==0) && (MEMP_NUM_SYS_TIMEOUT < (LWIP_TCP + IP_REASSEMBLY + LWIP_ARP + (2*LWIP_DHCP) + LWIP_AUTOIP + LWIP_IGMP + LWIP_DNS + PPP_SUPPORT))) 00147 #error "MEMP_NUM_SYS_TIMEOUT is too low to accomodate all required timeouts" 00148 #endif 00149 #if (IP_REASSEMBLY && (MEMP_NUM_REASSDATA > IP_REASS_MAX_PBUFS)) 00150 #error "MEMP_NUM_REASSDATA > IP_REASS_MAX_PBUFS doesn't make sense since each struct ip_reassdata must hold 2 pbufs at least!" 00151 #endif 00152 #if (MEM_LIBC_MALLOC && MEM_USE_POOLS) 00153 #error "MEM_LIBC_MALLOC and MEM_USE_POOLS may not both be simultaneously enabled in your lwipopts.h" 00154 #endif 00155 #if (MEM_USE_POOLS && !MEMP_USE_CUSTOM_POOLS) 00156 #error "MEM_USE_POOLS requires custom pools (MEMP_USE_CUSTOM_POOLS) to be enabled in your lwipopts.h" 00157 #endif 00158 #if (PBUF_POOL_BUFSIZE <= MEM_ALIGNMENT) 00159 #error "PBUF_POOL_BUFSIZE must be greater than MEM_ALIGNMENT or the offset may take the full first pbuf" 00160 #endif 00161 #if (TCP_QUEUE_OOSEQ && !LWIP_TCP) 00162 #error "TCP_QUEUE_OOSEQ requires LWIP_TCP" 00163 #endif 00164 #if (DNS_LOCAL_HOSTLIST && !DNS_LOCAL_HOSTLIST_IS_DYNAMIC && !(defined(DNS_LOCAL_HOSTLIST_INIT))) 00165 #error "you have to define define DNS_LOCAL_HOSTLIST_INIT {{'host1', 0x123}, {'host2', 0x234}} to initialize DNS_LOCAL_HOSTLIST" 00166 #endif 00167 00168 00169 /* Compile-time checks for deprecated options. 00170 */ 00171 #ifdef MEMP_NUM_TCPIP_MSG 00172 #error "MEMP_NUM_TCPIP_MSG option is deprecated. Remove it from your lwipopts.h." 00173 #endif 00174 #ifdef MEMP_NUM_API_MSG 00175 #error "MEMP_NUM_API_MSG option is deprecated. Remove it from your lwipopts.h." 00176 #endif 00177 #ifdef TCP_REXMIT_DEBUG 00178 #error "TCP_REXMIT_DEBUG option is deprecated. Remove it from your lwipopts.h." 00179 #endif 00180 #ifdef RAW_STATS 00181 #error "RAW_STATS option is deprecated. Remove it from your lwipopts.h." 00182 #endif 00183 #ifdef ETHARP_QUEUE_FIRST 00184 #error "ETHARP_QUEUE_FIRST option is deprecated. Remove it from your lwipopts.h." 00185 #endif 00186 #ifdef ETHARP_ALWAYS_INSERT 00187 #error "ETHARP_ALWAYS_INSERT option is deprecated. Remove it from your lwipopts.h." 00188 #endif 00189 #if SO_REUSE 00190 /* I removed the lot since this was an ugly hack. It broke the raw-API. 00191 It also came with many ugly goto's, Christiaan Simons. */ 00192 #error "SO_REUSE currently unavailable, this was a hack" 00193 #endif 00194 00195 #ifdef LWIP_DEBUG 00196 static void 00197 lwip_sanity_check(void) 00198 { 00199 /* Warnings */ 00200 #if LWIP_NETCONN 00201 if (MEMP_NUM_NETCONN > (MEMP_NUM_TCP_PCB+MEMP_NUM_TCP_PCB_LISTEN+MEMP_NUM_UDP_PCB+MEMP_NUM_RAW_PCB)) 00202 LWIP_PLATFORM_DIAG(("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\n")); 00203 #endif /* LWIP_NETCONN */ 00204 #if LWIP_TCP 00205 if (MEMP_NUM_TCP_SEG < TCP_SND_QUEUELEN) 00206 LWIP_PLATFORM_DIAG(("lwip_sanity_check: WARNING: MEMP_NUM_TCP_SEG should be at least as big as TCP_SND_QUEUELEN\n")); 00207 if (TCP_SND_QUEUELEN < (2 * (TCP_SND_BUF/TCP_MSS))) 00208 LWIP_PLATFORM_DIAG(("lwip_sanity_check: WARNING: TCP_SND_QUEUELEN must be at least as much as (2 * TCP_SND_BUF/TCP_MSS) for things to work\n")); 00209 if (TCP_SNDLOWAT > TCP_SND_BUF) 00210 LWIP_PLATFORM_DIAG(("lwip_sanity_check: WARNING: TCP_SNDLOWAT must be less than or equal to TCP_SND_BUF.\n")); 00211 if (TCP_WND > (PBUF_POOL_SIZE*PBUF_POOL_BUFSIZE)) 00212 LWIP_PLATFORM_DIAG(("lwip_sanity_check: WARNING: TCP_WND is larger than space provided by PBUF_POOL_SIZE*PBUF_POOL_BUFSIZE\n")); 00213 if (TCP_WND < TCP_MSS) 00214 LWIP_PLATFORM_DIAG(("lwip_sanity_check: WARNING: TCP_WND is smaller than MSS\n")); 00215 #endif /* LWIP_TCP */ 00216 } 00217 #else /* LWIP_DEBUG */ 00218 #define lwip_sanity_check() 00219 #endif /* LWIP_DEBUG */ 00220 00221 /** 00222 * Perform Sanity check of user-configurable values, and initialize all modules. 00223 */ 00224 void 00225 lwip_init(void) 00226 { 00227 /* Sanity check user-configurable values */ 00228 lwip_sanity_check(); 00229 00230 /* Modules initialization */ 00231 stats_init(); 00232 sys_init(); 00233 mem_init(); 00234 memp_init(); 00235 pbuf_init(); 00236 netif_init(); 00237 #if LWIP_SOCKET 00238 lwip_socket_init(); 00239 #endif /* LWIP_SOCKET */ 00240 ip_init(); 00241 #if LWIP_ARP 00242 etharp_init(); 00243 #endif /* LWIP_ARP */ 00244 #if LWIP_RAW 00245 raw_init(); 00246 #endif /* LWIP_RAW */ 00247 #if LWIP_UDP 00248 udp_init(); 00249 #endif /* LWIP_UDP */ 00250 #if LWIP_TCP 00251 tcp_init(); 00252 #endif /* LWIP_TCP */ 00253 #if LWIP_AUTOIP 00254 autoip_init(); 00255 #endif /* LWIP_AUTOIP */ 00256 #if LWIP_IGMP 00257 igmp_init(); 00258 #endif /* LWIP_IGMP */ 00259 #if LWIP_DNS 00260 dns_init(); 00261 #endif /* LWIP_DNS */ 00262 }
Generated on Tue Jul 12 2022 19:24:05 by 1.7.2