📄 uip.lst
字号:
C51 COMPILER V9.00 UIP 02/08/2010 20:58:31 PAGE 1
C51 COMPILER V9.00, COMPILATION OF MODULE UIP
OBJECT MODULE PLACED IN .\uip.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE ..\uip1.0\uip\uip.c LARGE BROWSE INCDIR(..\uip1.0\apps;..\uip1.0\uip;..\cp2
-200;..\cp2200;..\uip1.0\apps\dhcpc;..\uip1.0\apps\httpd) DEBUG OBJECTEXTEND PRINT(.\uip.lst) OBJECT(.\uip.obj)
line level source
1 #define DEBUG_PRINTF/*(...)*/ /*printf(__VA_ARGS__)*/
2
3 /**
4 * \defgroup uip The uIP TCP/IP stack
5 * @{
6 *
7 * uIP is an implementation of the TCP/IP protocol stack intended for
8 * small 8-bit and 16-bit microcontrollers.
9 *
10 * uIP provides the necessary protocols for Internet communication,
11 * with a very small code footprint and RAM requirements - the uIP
12 * code size is on the order of a few kilobytes and RAM usage is on
13 * the order of a few hundred bytes.
14 */
15
16 /**
17 * \file
18 * The uIP TCP/IP stack code.
19 * \author Adam Dunkels <adam@dunkels.com>
20 */
21
22 /*
23 * Copyright (c) 2001-2003, Adam Dunkels.
24 * All rights reserved.
25 *
26 * Redistribution and use in source and binary forms, with or without
27 * modification, are permitted provided that the following conditions
28 * are met:
29 * 1. Redistributions of source code must retain the above copyright
30 * notice, this list of conditions and the following disclaimer.
31 * 2. Redistributions in binary form must reproduce the above copyright
32 * notice, this list of conditions and the following disclaimer in the
33 * documentation and/or other materials provided with the distribution.
34 * 3. The name of the author may not be used to endorse or promote
35 * products derived from this software without specific prior
36 * written permission.
37 *
38 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
39 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
40 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
41 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
42 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
43 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
44 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
45 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
46 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
47 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
48 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
49 *
50 * This file is part of the uIP TCP/IP stack.
51 *
52 * $Id: uip.c,v 1.65 2006/06/11 21:46:39 adam Exp $
53 *
54 */
C51 COMPILER V9.00 UIP 02/08/2010 20:58:31 PAGE 2
55
56 /*
57 * uIP is a small implementation of the IP, UDP and TCP protocols (as
58 * well as some basic ICMP stuff). The implementation couples the IP,
59 * UDP, TCP and the application layers very tightly. To keep the size
60 * of the compiled code down, this code frequently uses the goto
61 * statement. While it would be possible to break the uip_process()
62 * function into many smaller functions, this would increase the code
63 * size because of the overhead of parameter passing and the fact that
64 * the optimier would not be as efficient.
65 *
66 * The principle is that we have a small buffer, called the uip_buf,
67 * in which the device driver puts an incoming packet. The TCP/IP
68 * stack parses the headers in the packet, and calls the
69 * application. If the remote host has sent data to the application,
70 * this data is present in the uip_buf and the application read the
71 * data from there. It is up to the application to put this data into
72 * a byte stream if needed. The application will not be fed with data
73 * that is out of sequence.
74 *
75 * If the application whishes to send data to the peer, it should put
76 * its data into the uip_buf. The uip_appdata pointer points to the
77 * first available byte. The TCP/IP stack will calculate the
78 * checksums, and fill in the necessary header fields and finally send
79 * the packet back to the peer.
80 */
81
82 #include "uip.h"
83 #include "uipopt.h"
84 #include "uip_arch.h"
85
86 #if UIP_CONF_IPV6
#include "uip-neighbor.h"
#endif /* UIP_CONF_IPV6 */
89
90 #include <string.h>
91
92 /*---------------------------------------------------------------------------*/
93 /* Variable definitions. */
94
95
96 /* The IP address of this host. If it is defined to be fixed (by
97 setting UIP_FIXEDADDR to 1 in uipopt.h), the address is set
98 here. Otherwise, the address */
99 #if UIP_FIXEDADDR > 0
const uip_ipaddr_t uip_hostaddr =
{HTONS((UIP_IPADDR0 << 8) | UIP_IPADDR1),
HTONS((UIP_IPADDR2 << 8) | UIP_IPADDR3)};
const uip_ipaddr_t uip_draddr =
{HTONS((UIP_DRIPADDR0 << 8) | UIP_DRIPADDR1),
HTONS((UIP_DRIPADDR2 << 8) | UIP_DRIPADDR3)};
const uip_ipaddr_t uip_netmask =
{HTONS((UIP_NETMASK0 << 8) | UIP_NETMASK1),
HTONS((UIP_NETMASK2 << 8) | UIP_NETMASK3)};
#else
110 uip_ipaddr_t uip_hostaddr, uip_draddr, uip_netmask;
111 #endif /* UIP_FIXEDADDR */
112
113 static const uip_ipaddr_t all_ones_addr =
114 #if UIP_CONF_IPV6
{0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff};
#else /* UIP_CONF_IPV6 */
C51 COMPILER V9.00 UIP 02/08/2010 20:58:31 PAGE 3
117 {0xffff,0xffff};
118 #endif /* UIP_CONF_IPV6 */
119 static const uip_ipaddr_t all_zeroes_addr =
120 #if UIP_CONF_IPV6
{0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000};
#else /* UIP_CONF_IPV6 */
123 {0x0000,0x0000};
124 #endif /* UIP_CONF_IPV6 */
125
126
127 #if UIP_FIXEDETHADDR
const struct uip_eth_addr uip_ethaddr = {{UIP_ETHADDR0,
UIP_ETHADDR1,
UIP_ETHADDR2,
UIP_ETHADDR3,
UIP_ETHADDR4,
UIP_ETHADDR5}};
#else
135 struct uip_eth_addr uip_ethaddr = {{0,0,0,0,0,0}};
136 #endif
137
138 #ifndef UIP_CONF_EXTERNAL_BUFFER
139 u8_t uip_buf[UIP_BUFSIZE + 2]; /* The packet buffer that contains
140 incoming packets. */
141 #endif /* UIP_CONF_EXTERNAL_BUFFER */
142
143 void *uip_appdata; /* The uip_appdata pointer points to
144 application data. */
145 void *uip_sappdata; /* The uip_appdata pointer points to
146 the application data which is to
147 be sent. */
148 #if UIP_URGDATA > 0
void *uip_urgdata; /* The uip_urgdata pointer points to
urgent data (out-of-band data), if
present. */
u16_t uip_urglen, uip_surglen;
#endif /* UIP_URGDATA > 0 */
154
155 u16_t uip_len, uip_slen;
156 /* The uip_len is either 8 or 16 bits,
157 depending on the maximum packet
158 size. */
159
160 u8_t uip_flags; /* The uip_flags variable is used for
161 communication between the TCP/IP stack
162 and the application program. */
163
164 #if UIP_TCP
165 struct uip_conn *uip_conn; /* uip_conn always points to the current
166 connection. */
167
168 struct uip_conn uip_conns[UIP_CONNS];
169 /* The uip_conns array holds all TCP
170 connections. */
171 u16_t uip_listenports[UIP_LISTENPORTS];
172 /* The uip_listenports list all currently
173 listning ports. */
174 #endif /* UIP_TCP */
175
176 #if UIP_UDP
177 struct uip_udp_conn *uip_udp_conn;
178 struct uip_udp_conn uip_udp_conns[UIP_UDP_CONNS];
C51 COMPILER V9.00 UIP 02/08/2010 20:58:31 PAGE 4
179 #endif /* UIP_UDP */
180
181 static u16_t ipid; /* Ths ipid variable is an increasing
182 number that is used for the IP ID
183 field. */
184
185 void uip_setipid(u16_t id) { ipid = id; }
186
187 #if UIP_TCP
188 static u8_t iss[4]; /* The iss variable is used for the TCP
189 initial sequence number. */
190 #endif /* UIP_TCP */
191
192 #if UIP_ACTIVE_OPEN
193 static u16_t lastport; /* Keeps track of the last port used for
194 a new connection. */
195 #endif /* UIP_ACTIVE_OPEN */
196
197 /* Temporary variables. */
198 #if UIP_TCP
199 u8_t uip_acc32[4];
200 static u8_t c, opt;
201 static u16_t tmp16;
202 #endif /* UIP_TCP */
203
204 /* Structures and definitions. */
205 #define TCP_FIN 0x01
206 #define TCP_SYN 0x02
207 #define TCP_RST 0x04
208 #define TCP_PSH 0x08
209 #define TCP_ACK 0x10
210 #define TCP_URG 0x20
211 #define TCP_CTL 0x3f
212
213 #define TCP_OPT_END 0 /* End of TCP options list */
214 #define TCP_OPT_NOOP 1 /* "No-operation" TCP option */
215 #define TCP_OPT_MSS 2 /* Maximum segment size TCP option */
216
217 #define TCP_OPT_MSS_LEN 4 /* Length of TCP MSS option. */
218
219 #define ICMP_ECHO_REPLY 0
220 #define ICMP_ECHO 8
221
222 #define ICMP6_ECHO_REPLY 129
223 #define ICMP6_ECHO 128
224 #define ICMP6_NEIGHBOR_SOLICITATION 135
225 #define ICMP6_NEIGHBOR_ADVERTISEMENT 136
226
227 #define ICMP6_FLAG_S (1 << 6)
228
229 #define ICMP6_OPTION_SOURCE_LINK_ADDRESS 1
230 #define ICMP6_OPTION_TARGET_LINK_ADDRESS 2
231
232
233 /* Macros. */
234 #define BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])
235 #define FBUF ((struct uip_tcpip_hdr *)&uip_reassbuf[0])
236 #define ICMPBUF ((struct uip_icmpip_hdr *)&uip_buf[UIP_LLH_LEN])
237 #define UDPBUF ((struct uip_udpip_hdr *)&uip_buf[UIP_LLH_LEN])
238
239
240 #if UIP_STATISTICS == 1
C51 COMPILER V9.00 UIP 02/08/2010 20:58:31 PAGE 5
241 struct uip_stats uip_stat;
242 #define UIP_STAT(s) s
243 #else
#define UIP_STAT(s)
#endif /* UIP_STATISTICS == 1 */
246
247 #if UIP_LOGGING == 1
#include <stdio.h>
void uip_log(char *msg);
#define UIP_LOG(m) uip_log(m)
#else
252 #define UIP_LOG(m)
253 #endif /* UIP_LOGGING == 1 */
254
255 #if ! UIP_ARCH_ADD32 && UIP_TCP
256 void
257 uip_add32(u8_t *op32, u16_t op16)
258 {
259 1 uip_acc32[3] = op32[3] + (op16 & 0xff);
260 1 uip_acc32[2] = op32[2] + (op16 >> 8);
261 1 uip_acc32[1] = op32[1];
262 1 uip_acc32[0] = op32[0];
263 1
264 1 if(uip_acc32[2] < (op16 >> 8)) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -