BCM WL 6.30.102.9 (r366174)
[tomato.git] / release / src-rt / cfe / cfe / net / net_tcp_internal.h
blob9f7aa4c67ada5ae0fbb01c9e2a2723343f5440bd
1 /* *********************************************************************
2 * Broadcom Common Firmware Environment (CFE)
3 *
4 * TCP Protocol Internal Definitions File: net_tcp_internal.h
5 *
6 * This file contains the structures and constants needed to
7 * maintain TCP connections.
8 *
9 * Author: Mitch Lichtenberg (mpl@broadcom.com)
11 *********************************************************************
13 * Copyright 2000,2001,2002,2003
14 * Broadcom Corporation. All rights reserved.
16 * This software is furnished under license and may be used and
17 * copied only in accordance with the following terms and
18 * conditions. Subject to these conditions, you may download,
19 * copy, install, use, modify and distribute modified or unmodified
20 * copies of this software in source and/or binary form. No title
21 * or ownership is transferred hereby.
23 * 1) Any source code used, modified or distributed must reproduce
24 * and retain this copyright notice and list of conditions
25 * as they appear in the source file.
27 * 2) No right is granted to use any trade name, trademark, or
28 * logo of Broadcom Corporation. The "Broadcom Corporation"
29 * name may not be used to endorse or promote products derived
30 * from this software without the prior written permission of
31 * Broadcom Corporation.
33 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
34 * IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
35 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
36 * PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
37 * SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
38 * PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
39 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
40 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
41 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
42 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
43 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
44 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
45 * THE POSSIBILITY OF SUCH DAMAGE.
46 ********************************************************************* */
50 /* *********************************************************************
51 * TCP Constants
52 ********************************************************************* */
55 #define TCP_MAX_PORTS 8
56 #define TCP_MAX_TCBS 16
57 #define TCP_BUF_SIZE 65536
59 #define TCP_MAX_SEG_SIZE 1400
61 #define TCP_CONNECT_TIMER (30*CFE_HZ)
62 #define TCP_RETX_TIMER (1*CFE_HZ)
63 #define TCP_TIMEWAIT_TIMER (30*CFE_HZ)
64 #define TCP_SEND_TIMER (CFE_HZ)
66 #define TCP_FAST_TIMER (CFE_HZ/5) /* 200ms */
67 #define TCP_KEEPALIVE_TIMER (CFE_HZ*60) /* one minute */
70 /* *********************************************************************
71 * TCP Protocol
72 ********************************************************************* */
74 #define TCPFLG_FIN 0x0001
75 #define TCPFLG_SYN 0x0002
76 #define TCPFLG_RST 0x0004
77 #define TCPFLG_PSH 0x0008
78 #define TCPFLG_ACK 0x0010
79 #define TCPFLG_URG 0x0020
80 #define TCPHDRSIZE(flg) (((flg) >> 12)*4)
81 #define TCPHDRFLG(size) (((size)/4)<<12)
83 #define TCP_HDR_LENGTH 20
85 #define TCP_MAX_SEG_OPT 0x0204
87 /* *********************************************************************
88 * TCP State machine
89 ********************************************************************* */
91 /*
92 * TCB states, see RFC
95 #define TCPSTATE_CLOSED 0
96 #define TCPSTATE_LISTEN 1
97 #define TCPSTATE_SYN_SENT 2
98 #define TCPSTATE_SYN_RECEIVED 3
99 #define TCPSTATE_ESTABLISHED 4
100 #define TCPSTATE_CLOSE_WAIT 5
101 #define TCPSTATE_FINWAIT_1 6
102 #define TCPSTATE_FINWAIT_2 7
103 #define TCPSTATE_CLOSING 8
104 #define TCPSTATE_LAST_ACK 9
105 #define TCPSTATE_TIME_WAIT 10
108 * Masks for TCP states - we use these so we can make
109 * bit vectors of states for easy tests.
112 #define M_TCPSTATE_CLOSED (1 << TCPSTATE_CLOSED)
113 #define M_TCPSTATE_LISTEN (1 << TCPSTATE_LISTEN)
114 #define M_TCPSTATE_SYN_SENT (1 << TCPSTATE_SYN_SENT)
115 #define M_TCPSTATE_SYN_RECEIVED (1 << TCPSTATE_SYN_RECEIVED)
116 #define M_TCPSTATE_ESTABLISHED (1 << TCPSTATE_ESTABLISHED)
117 #define M_TCPSTATE_CLOSE_WAIT (1 << TCPSTATE_CLOSE_WAIT)
118 #define M_TCPSTATE_FINWAIT_1 (1 << TCPSTATE_FINWAIT_1)
119 #define M_TCPSTATE_FINWAIT_2 (1 << TCPSTATE_FINWAIT_2)
120 #define M_TCPSTATE_CLOSING (1 << TCPSTATE_CLOSING)
121 #define M_TCPSTATE_LAST_ACK (1 << TCPSTATE_LAST_ACK)
122 #define M_TCPSTATE_TIME_WAIT (1 << TCPSTATE_TIME_WAIT)
123 #define M_TCPSTATE_CLOSED (1 << TCPSTATE_CLOSED)
126 * This macro returns true if a given state is in a
127 * set of states (defined below)
130 #define TCPSTATE_IN_SET(state,set) ((1 << (state)) & (set))
133 * Intresting groups of TCP states
136 /* ABORTSTATES - tcp_abort will send a RST if our TCB is one of these. */
137 #define M_TCPSTATE_ABORTSTATES \
138 M_TCPSTATE_SYN_SENT | M_TCPSTATE_SYN_RECEIVED | M_TCPSTATE_ESTABLISHED | \
139 M_TCPSTATE_FINWAIT_1 | M_TCPSTATE_FINWAIT_2 | M_TCPSTATE_CLOSING | \
140 M_TCPSTATE_LAST_ACK | M_TCPSTATE_CLOSE_WAIT
142 /* SEND_OK - tcp_send will send data if our TCB is one of these */
143 #define M_TCPSTATE_SEND_OK \
144 M_TCPSTATE_ESTABLISHED | M_TCPSTATE_CLOSE_WAIT
146 /* RECV_OK - tcp_recv will pass up data if our TCB is in one of these */
147 #define M_TCPSTATE_RECV_OK \
148 M_TCPSTATE_ESTABLISHED | M_TCPSTATE_CLOSE_WAIT
150 /* PEERADDR_OK - tcp_peeraddr will return a value if TCB is in one of these */
151 #define M_TCPSTATE_PEERADDR_OK \
152 M_TCPSTATE_SYN_SENT | M_TCPSTATE_SYN_RECEIVED | M_TCPSTATE_ESTABLISHED | \
153 M_TCPSTATE_FINWAIT_1 | M_TCPSTATE_FINWAIT_2 | M_TCPSTATE_CLOSING | \
154 M_TCPSTATE_LAST_ACK | M_TCPSTATE_CLOSE_WAIT
156 /* RESETKEEPALIVE - reset keepalive timer in these states */
157 #define M_TCPSTATE_RESETKEEPALIVE \
158 M_TCPSTATE_ESTABLISHED | M_TCPSTATE_CLOSE_WAIT | M_TCPSTATE_FINWAIT_1 | \
159 M_TCPSTATE_FINWAIT_2 | M_TCPSTATE_CLOSING | M_TCPSTATE_LAST_ACK
161 #define CONNINPROGRESS - connection is in progress in these states */
162 #define M_TCPSTATE_CONNINPROGRESS \
163 M_TCPSTATE_LISTEN | M_TCPSTATE_SYN_SENT | M_TCPSTATE_SYN_RECEIVED
167 * TCP flags for the control block
170 #define TCB_FLG_OUTPUT 1 /* need to call tcp_output */
171 #define TCB_FLG_SENDMSG 2
172 #define TCB_FLG_DLYACK 4 /* delayed ack is pending */
174 /* *********************************************************************
175 * TCP Control Block
176 ********************************************************************* */
178 typedef struct tcb_s {
179 queue_t tcb_qb; /* next/previous in list */
180 int tcb_socknum; /* socket number, index into table */
182 int tcb_state; /* current connection state */
184 uint8_t tcb_peeraddr[IP_ADDR_LEN]; /* Peer's IP Address */
185 uint16_t tcb_peerport; /* Peer's port address */
186 uint16_t tcb_lclport; /* My port address */
188 uint16_t tcb_txflags; /* packet flags for next tx packet */
190 cfe_timer_t tcb_timer_2msl; /* 2MSL timer, used in TIME_WAIT */
191 cfe_timer_t tcb_timer_keep; /* Timer for keepalives and connections */
192 cfe_timer_t tcb_timer_retx; /* send retransmission timer */
193 cfe_timer_t tcb_timer_pers; /* Persist timer */
195 int tcb_retrycnt; /* Retry counter */
197 int tcb_mtu; /* MTU if underlying link */
198 unsigned int tcb_flags; /* Misc protocol flags */
199 unsigned int tcb_sockflags; /* flags set by user api */
202 * Buffers
205 tcpmodbuf_t tcb_txbuf; /* Transmit buffer */
206 tcpmodbuf_t tcb_rxbuf; /* Receive buffer */
209 * Send sequence variables
212 uint32_t tcb_sendunack; /* oldest unacknowledged seqnum */
213 uint32_t tcb_sendnext; /* Next seqnum to send */
214 uint32_t tcb_sendwindow; /* Last advertised send window */
217 * Receive sequence variables
220 uint32_t tcb_rcvnext; /* next in-order receive seq num */
221 uint32_t tcb_rcvack; /* last transmitted acknowledgement */
224 * Window management variables
226 int tcb_dup_ackcnt; /* Duplicate ack counter */
228 } tcb_t;
230 /* *********************************************************************
231 * Macros to muck with sequence numbers
232 ********************************************************************* */
234 #define TCPSEQ_LT(a,b) ((int)((a)-(b)) < 0)
235 #define TCPSEQ_LEQ(a,b) ((int)((a)-(b)) <= 0)
236 #define TCPSEQ_GT(a,b) ((int)((a)-(b)) > 0)
237 #define TCPSEQ_GEQ(a,b) ((int)((a)-(b)) >= 0)
239 #define TCPSEQ_DIFF(a,b) ((int)((a)-(b)))