📄 tcp.lst
字号:
C51 COMPILER V8.18 TCP 08/02/2010 19:52:46 PAGE 1
C51 COMPILER V8.18, COMPILATION OF MODULE TCP
OBJECT MODULE PLACED IN TCP.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE TCP.C LARGE BROWSE DEBUG OBJECTEXTEND
line level source
1 //-----------------------------------------------------------------------------
2 // Net TCP.C
3 //
4 // This module handles TCP segments
5 // Refer to RFC 793, 896, 1122, 1323, 2018, 2581
6 //
7 // A "connection" is a unique combination of 4 items: His IP address,
8 // his port number, my IP address, and my port number.
9 //
10 // Note that a SYN and a FIN count as a byte of data, but a RST does
11 // not count. Neither do any of the other flags.
12 // See "TCP/IP Illustrated, Volume 1" Sect 17.3 for info on flags
13 //-----------------------------------------------------------------------------
14 #include <string.h>
15 #include <stdlib.h>
16 #include <ctype.h> // toupper
17 #include "main.h" // toupper
18 #include "udp.h" // toupper
19 #include "rs232.h" // toupper
20 #include "tcp.h" // toupper
21 #include "ip.h" // toupper
22 #include "ARP.h" // toupper
23 UWORK8 idata just_closed; // Keeps track of when a conxn closed
24 // These structures keep track of connection information
25 Str_CONNECTION xdata StrConnection_buf[2]; //设置可以同时接收5组IP地址的TCP数据
26 UWORK32 initial_sequence_nr; //序列号
27 UWORK8 TcpStateFlag; //TCP的状态标志位,是在各个过程中的状态
28 char xdata text[];
29 // Options: MSS (4 bytes), NOPS (2 bytes), Selective ACK (2 bytes)
30 UWORK8 code options_buf[10] = {0x02, 0x04, 0x05, 0xB4, 0x01, 0x01, 0x04, 0x02};
31 UWORK8 code optionsRe_buf[4] = {0x02, 0x04, 0x05, 0x78}; //建立连接的TCP选项
32
33 UWORK8 HttpSendFlag; //TCP有发送的数据
34
35 //------------------------------------------------------------------------
36 // Initialize variables declared in this module
37 //
38 //------------------------------------------------------------------------
39 /*********************************************************************
40 函数名: void init_tcp(void)
41 功能: 初始化TCP的接收缓存器
42 输入: None
43 输出: None
44 返回: None
45 日期: 2004/02/04
46 *********************************************************************/
47 void init_tcp(void)
48 {
49 1 memset(StrConnection_buf, 0, sizeof(StrConnection_buf));
50 1 just_closed = FALSE;
51 1 initial_sequence_nr = 1;
52 1 }
53 //------------------------------------------------------------------------
54 // This runs every 0.5 seconds. If the connection has had no activity
55 // it initiates closing the connection.
C51 COMPILER V8.18 TCP 08/02/2010 19:52:46 PAGE 2
56 //
57 //------------------------------------------------------------------------
58 /*********************************************************************
59 函数名: void tcp_inactivity(void)
60 功能: 判断TCP的状态
61 输入: None
62 输出: None
63 返回: None
64 日期: 2004/02/04
65 This runs every 0.5 seconds. If the connection has had no activity
66 // it initiates closing the connection.
67 *********************************************************************/
68 //------------------------------------------------------------------------
69 // This runs every 0.5 seconds. If the connection has had no activity
70 // it initiates closing the connection.
71 //
72 //------------------------------------------------------------------------
73 /*
74 void tcp_inactivity(void)
75 {
76 UWORK8 idata nr;
77 // Look for active connections in the established state
78 for (nr = 0; nr < 2; nr++)
79 {
80 if ((StrConnection_buf[nr].ipaddr != 0) && (StrConnection_buf[nr].state == STATE_ESTABLISHED) && (St
-rConnection_buf[nr].inactivity))
81 {
82 // Decrement the timer and see if it hit 0
83 StrConnection_buf[nr].inactivity--;
84 if (StrConnection_buf[nr].inactivity == 0)
85 {
86 tcp_ReBack((FLG_ACK | FLG_FIN), 20, nr);
87 StrConnection_buf[nr].My_SERIESNUM++; // For my FIN
88 StrConnection_buf[nr].state = STATE_FIN_WAIT_1;
89 // if (debug) serial_send("TCP: Entered FIN_WAIT_1 state\r");
90 }
91 }
92 }
93 }
94 */
95 //------------------------------------------------------------------------
96 // This runs every 0.5 seconds. If the other end has not ACK'd
97 // everyting we have sent, it re-sends it. To save RAM space, we
98 // regenerate a segment rather than keeping a bunch of segments
99 // hanging around eating up RAM. A connection should not be in an
100 // opening or closing state when this timer expires, so we simply
101 // send a reset.
102 //
103 // If a connection is in the ESTABLISHED state when the timer expires
104 // then we have just sent a web page so re-send the page
105 //------------------------------------------------------------------------
106 /*
107 void tcp_retransmit(void)
108 {
109 UWORK8 idata retries = 0;
110 UWORK8 idata nr;
111
112 // Scan through all active connections
113 for (nr = 0; nr < 2; nr++)
114 {
115 if ((StrConnection_buf[nr].ipaddr != 0) && (StrConnection_buf[nr].timer))
116 {
C51 COMPILER V8.18 TCP 08/02/2010 19:52:46 PAGE 3
117 // Decrement the timer and see if it hit 0
118 StrConnection_buf[nr].timer--;
119 if (StrConnection_buf[nr].timer == 0)
120 {
121 // Socket just timed out. If we are not in ESTABLISHED state
122 // something is amiss so send reset and close connection
123 if (StrConnection_buf[nr].state != STATE_ESTABLISHED)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -