📄 uip.lst
字号:
C51 COMPILER V8.16 UIP 03/16/2009 23:18:13 PAGE 1
C51 COMPILER V8.16, COMPILATION OF MODULE UIP
OBJECT MODULE PLACED IN .\debug\uip.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE uip.c LARGE BROWSE DEBUG OBJECTEXTEND PRINT(.\debug\uip.lst) OBJECT(.\debug
-\uip.obj)
line level source
1 /**
2 * \addtogroup uip
3 * @{
4 */
5
6 /**
7 * \file
8 * The uIP TCP/IP stack code.
9 * \author Adam Dunkels <adam@dunkels.com>
10 */
11
12 /*
13 * Copyright (c) 2001-2003, Adam Dunkels.
14 * All rights reserved.
15 *
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
18 * are met:
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
24 * 3. The name of the author may not be used to endorse or promote
25 * products derived from this software without specific prior
26 * written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
29 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
30 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
32 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
34 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
36 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *
40 * This file is part of the uIP TCP/IP stack.
41 *
42 * $Id: uip.c,v 1.62.2.10 2003/10/07 13:23:01 adam Exp $
43 *
44 */
45
46 /*
47 This is a small implementation of the IP and TCP protocols (as well as
48 some basic ICMP stuff). The implementation couples the IP, TCP and the
49 application layers very tightly. To keep the size of the compiled code
50 down, this code also features heavy usage of the goto statement.
51
52 The principle is that we have a small buffer, called the uip_buf, in
53 which the device driver puts an incoming packet. The TCP/IP stack
54 parses the headers in the packet, and calls upon the application. If
C51 COMPILER V8.16 UIP 03/16/2009 23:18:13 PAGE 2
55 the remote host has sent data to the application, this data is present
56 in the uip_buf and the application read the data from there. It is up
57 to the application to put this data into a byte stream if needed. The
58 application will not be fed with data that is out of sequence.
59
60 If the application whishes to send data to the peer, it should put its
61 data into the uip_buf, 40 bytes from the start of the buffer. The
62 TCP/IP stack will calculate the checksums, and fill in the necessary
63 header fields and finally send the packet back to the peer.
64 */
65
66 #include "uip.h"
67 #include "uipopt.h"
68 #include "uip_arch.h"
69 #include "uart.h"
70 #include "myopt.h"
71 /*-----------------------------------------------------------------------------------*/
72 /* Variable definitions. */
73
74
75 /* The IP address of this host. If it is defined to be fixed (by setting UIP_FIXEDADDR to 1 in uipopt.h),
-the address is set here. Otherwise, the address */
76 #if UIP_FIXEDADDR > 0
77 const u16_t uip_hostaddr[2] =
78 {HTONS((UIP_IPADDR0 << 8) | UIP_IPADDR1),
79 HTONS((UIP_IPADDR2 << 8) | UIP_IPADDR3)};
80 const u16_t uip_arp_draddr[2] =
81 {HTONS((UIP_DRIPADDR0 << 8) | UIP_DRIPADDR1),
82 HTONS((UIP_DRIPADDR2 << 8) | UIP_DRIPADDR3)};
83 const u16_t uip_arp_netmask[2] =
84 {HTONS((UIP_NETMASK0 << 8) | UIP_NETMASK1),
85 HTONS((UIP_NETMASK2 << 8) | UIP_NETMASK3)};
86 #else
u16_t uip_hostaddr[2];
u16_t uip_arp_draddr[2], uip_arp_netmask[2];
#endif /* UIP_FIXEDADDR */
90
91 u8_t uip_buf[UIP_BUFSIZE+2]; /* The packet buffer that contains
92 incoming packets. */
93 volatile u8_t *uip_appdata; /* The uip_appdata pointer points to
94 application data. */
95 volatile u8_t *uip_sappdata; /* The uip_appdata pointer points to the
96 application data which is to be sent. */
97 #if UIP_URGDATA > 0
98 volatile u8_t *uip_urgdata; /* The uip_urgdata pointer points to
99 urgent data (out-of-band data), if
100 present. */
101 volatile u8_t uip_urglen, uip_surglen;
102 #endif /* UIP_URGDATA > 0 */
103
104 volatile u16_t uip_len, uip_slen;
105 /* The uip_len is either 8 or 16 bits,
106 depending on the maximum packet
107 size. */
108
109 volatile u8_t uip_flags; /* The uip_flags variable is used for
110 communication between the TCP/IP stack
111 and the application program. */
112 struct uip_conn *uip_conn; /* uip_conn always points to the current
113 connection. */
114
115 struct uip_conn uip_conns[UIP_CONNS];
C51 COMPILER V8.16 UIP 03/16/2009 23:18:13 PAGE 3
116 /* The uip_conns array holds all TCP
117 connections. */
118 u16_t uip_listenports[UIP_LISTENPORTS];
119 /* The uip_listenports list all currently
120 listning ports. */
121 #if UIP_UDP
struct uip_udp_conn *uip_udp_conn;
struct uip_udp_conn uip_udp_conns[UIP_UDP_CONNS];
#endif /* UIP_UDP */
125
126
127 static u16_t ipid; /* Ths ipid variable is an increasing
128 number that is used for the IP ID
129 field. */
130
131 static u8_t iss[4]; /* The iss variable is used for the TCP
132 initial sequence number. */
133
134 #if UIP_ACTIVE_OPEN
static u16_t lastport; /* Keeps track of the last port used for
a new connection. */
#endif /* UIP_ACTIVE_OPEN */
138
139 /* Temporary variables. */
140 volatile u8_t uip_acc32[4];
141 static u8_t c, opt;
142 static u16_t tmp16;
143
144 /* Structures and definitions. */
145 #define TCP_FIN 0x01
146 #define TCP_SYN 0x02
147 #define TCP_RST 0x04
148 #define TCP_PSH 0x08
149 #define TCP_ACK 0x10
150 #define TCP_URG 0x20
151 #define TCP_CTL 0x3f
152
153 #define ICMP_ECHO_REPLY 0
154 #define ICMP_ECHO 8
155
156 /* Macros. */
157 #define BUF ((uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])
158 #define FBUF ((uip_tcpip_hdr *)&uip_reassbuf[0])
159 #define ICMPBUF ((uip_icmpip_hdr *)&uip_buf[UIP_LLH_LEN])
160 #define UDPBUF ((uip_udpip_hdr *)&uip_buf[UIP_LLH_LEN])
161
162 #if UIP_STATISTICS == 1
163 struct uip_stats uip_stat;
164 #define UIP_STAT(s) s
165 #else
#define UIP_STAT(s)
#endif /* UIP_STATISTICS == 1 */
168
169 #if UIP_LOGGING == 1
#include <stdio.h>
void uip_log(char *msg);
#define UIP_LOG(m) uip_log(m)
#else
174 #define UIP_LOG(m)
175 #endif /* UIP_LOGGING == 1 */
176
177 /*-----------------------------------------------------------------------------------*/
C51 COMPILER V8.16 UIP 03/16/2009 23:18:13 PAGE 4
178 void
179 uip_init(void)
180 {
181 1 for(c = 0; c < UIP_LISTENPORTS; ++c) {
182 2 uip_listenports[c] = 0;
183 2 }
184 1 for(c = 0; c < UIP_CONNS; ++c) {
185 2 uip_conns[c].tcpstateflags = CLOSED;
186 2 }
187 1 #if UIP_ACTIVE_OPEN
lastport = 1024;
#endif /* UIP_ACTIVE_OPEN */
190 1
191 1 #if UIP_UDP
for(c = 0; c < UIP_UDP_CONNS; ++c) {
uip_udp_conns[c].lport = 0;
}
#endif /* UIP_UDP */
196 1
197 1
198 1 /* IPv4 initialization. */
199 1 #if UIP_FIXEDADDR == 0
uip_hostaddr[0] = uip_hostaddr[1] = 0;
#endif /* UIP_FIXEDADDR */
202 1
203 1 }
204 /*-----------------------------------------------------------------------------------*/
205 #if UIP_ACTIVE_OPEN
struct uip_conn *
uip_connect(u16_t *ripaddr, u16_t rport)
{
register struct uip_conn *conn, *cconn;
/* Find an unused local port. */
again:
++lastport;
if(lastport >= 32000) {
lastport = 4096;
}
/* Check if this port is already in use, and if so try to find
another one. */
for(c = 0; c < UIP_CONNS; ++c) {
conn = &uip_conns[c];
if(conn->tcpstateflags != CLOSED &&
conn->lport == htons(lastport)) {
goto again;
}
}
conn = 0;
for(c = 0; c < UIP_CONNS; ++c) {
cconn = &uip_conns[c];
if(cconn->tcpstateflags == CLOSED) {
conn = cconn;
break;
}
if(cconn->tcpstateflags == TIME_WAIT) {
if(conn == 0 ||
cconn->timer > uip_conn->timer) {
C51 COMPILER V8.16 UIP 03/16/2009 23:18:13 PAGE 5
conn = cconn;
}
}
}
if(conn == 0) {
return 0;
}
conn->tcpstateflags = SYN_SENT;
conn->snd_nxt[0] = iss[0];
conn->snd_nxt[1] = iss[1];
conn->snd_nxt[2] = iss[2];
conn->snd_nxt[3] = iss[3];
conn->initialmss = conn->mss = UIP_TCP_MSS;
conn->len = 1; /* TCP length of the SYN is one. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -