blob: eafc6e53af5afd04e27dc7e854c7ec20037bb844 [file] [log] [blame]
/*************************************************************
*
* This Software is the property of VIA Telecom, Inc. and may only be used pursuant to a license from VIA Telecom, Inc.
*
* Any unauthorized use inconsistent with the terms of such license is strictly prohibited.
*
* Copyright (c) 2002-2010 VIA Telecom, Inc. All rights reserved.
*
*************************************************************/
/*************************************************************************
*
* File Name: tcp.h
* Project: TCP/IP
*
* Original Author: Steve Pye
* Creation Date: Based on PVCS Rev 1.1 (15 Apr 1998)
*
* Description: TCP Data Structures
* Restrictions:
* Dependencies:
*
*************************************************************************
*
* This Software is the property of ISOTEL Research Ltd.
* Unauthorized use is prohibited.
*
* ISOTEL Research Ltd.
* Suite 340, 525 - 28th Street S.E.
* Calgary, Alberta, Canada T2A 6W9
* Tel: (403)275-0041 Fax: (403)274-3598
*
*
*************************************************************************
*
* RCS Log Information
*
* removed!
*
* removed!
*
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
*
* removed!
* removed!
*
*
************************************************************************/
#ifndef _TCP_H_
#define _TCP_H_ 1
#include "IP_TYPE.H"
#include "IP.H"
/* TCP Header */
struct tcp_header
{
kal_uint16 src; /* source port number */
kal_uint16 dst; /* destination port number */
kal_uint32 seq; /* sequence number */
kal_uint32 ack; /* acknowledgement sequence number */
kal_uint8 hlen; /* [7:3] header 32-bit word length */
kal_uint8 ctl; /* TCP control bit flags */
kal_uint16 win; /* offered window */
kal_uint16 chk; /* checksum over TCP header+data */
kal_uint16 urg; /* offset from seq of last byte of */
}; /* urgent data */
/* TCP Header Control Field Bit Flags */
#define TCP_FIN 0x01
#define TCP_SYN 0x02
#define TCP_RST 0x04
#define TCP_PSH 0x08
#define TCP_ACK 0x10
#define TCP_URG 0x20
/* TCP/IP Header */
struct tcpip_header
{
struct ip_header ip; /* IP header without options */
struct tcp_header tcp; /* TCP header without options */
};
/* TCP Constant Sizes */
#define TCP_HEADERSIZE 20 /* default TCP header size */
#define TCP_MAXHDRSIZE 40 /* should really be 24 but nops ok */
#define TCP_MAXSEGSIZE 536 /* IP_MAXDGMSIZE-TCPIP_HEADERSIZE */
#define TCP_MSSOPTSIZE 4 /* max seg size option length */
#define TCP_MSS_BACKOFF 80 /* in the case of VSNP type packets */
/* TCP Maximum Segment Size Option */
struct tcp_mssopt
{
kal_uint8 type; /* TCPOPT_MAXSEG */
kal_uint8 len; /* TCP_MSSOPTSIZE */
kal_uint16 mss; /* maximum segment size */
};
#define TCPOPT_TYPE 0 /* option type field offset */
#define TCPOPT_LEN 1 /* option length field offset */
#define TCPOPT_MSS 2 /* option mss field offset */
/* TCP Option Types */
#define TCPOPT_EOL 0 /* end-of-list option */
#define TCPOPT_NOP 1 /* no-operation option (padding) */
#define TCPOPT_MAXSEG 2 /* maximum segment size option */
/* TCP Protocol States */
#define TCPS_CLOSED 0 /* closed */
#define TCPS_LISTEN 1 /* passive: listening for SYN */
#define TCPS_SYNSENT 2 /* active: have sent SYN */
#define TCPS_SYNRCVD 3 /* have sent and received SYN */
#define TCPS_ESTABLISHED 4 /* established */
#define TCPS_CLOSEWAIT 5 /* rcvd FIN, awaiting user close */
#define TCPS_FINWAIT1 6 /* user closed, sent FIN */
#define TCPS_CLOSING 7 /* closed xchd FIN; await FIN ACK */
#define TCPS_LASTACK 8 /* had FIN and close await FIN ACK */
#define TCPS_FINWAIT2 9 /* have closed, FIN is acked */
#define TCPS_TIMEWAIT 10 /* in 2*MSL quiet wait after close */
#define TCP_NSTATES 11
/*set for trace, copy from TCP Protocol States above*/
enum TraceTcpStates
{
TCP_CLOSED,
TCP_LISTEN,
TCP_SYNSENT,
TCP_SYNRCVD,
TCP_ESTABLISHED,
TCP_CLOSEWAIT,
TCP_FINWAIT1,
TCP_CLOSING,
TCP_LASTACK,
TCP_FINWAIT2,
TCP_TIMEWAIT,
TCP_STATE_NUM
};
#define TCP_HAVERCVDSYN(s) ((s) >= TCPS_SYNRCVD)
#define TCP_HAVERCVDFIN(s) ((s) >= TCPS_TIMEWAIT)
#define TCP_HAVESENTSYN(s) ((s) >= TCPS_SYNSENT)
#define TCP_HAVESENTFIN(s) ((s) >= TCPS_FINWAIT1)
/* TCP Sequence Number Ordinality Macros. Note that if two sequence numbers
differ by more than half the sequence space, then their ordinality is
reversed and wraparound is assumed to have occurred. */
#define SEQ_LT(a,b) ( (kal_int32)((a)-(b)) < 0 )
#define SEQ_LE(a,b) ( (kal_int32)((a)-(b)) <= 0 )
#define SEQ_GT(a,b) ( (kal_int32)((a)-(b)) > 0 )
#define SEQ_GE(a,b) ( (kal_int32)((a)-(b)) >= 0 )
/* TCP Send and Receive Sequence Number Initialization Macros */
#define TCP_RECVSEQINIT(tp) \
(tp)->rcv_adv = (tp)->rcv_nxt = (tp)->rcv_irs + 1
#define TCP_SENDSEQINIT(tp) \
(tp)->snd_una = (tp)->snd_nxt = (tp)->snd_max = (tp)->snd_iss
#define TCP_PUSHURGINIT(tp) \
(tp)->snd_psh = (tp)->snd_urg = (tp)->snd_una-1
/* TCP Set Time Value Within a Defined Range Macro */
#define TCPT_RANGESET( tv, value, tvmin, tvmax ) \
{ \
(tv) = (value); \
if( (tv) < (tvmin) ) \
(tv) = (tvmin); \
else if( (tv) > (tvmax) ) \
(tv) = (tvmax); \
}
/* TCP Initial Sequence Number Assignment Increment. RFC793 suggests that
the TCP connection snd_iss should be assigned from a counter that is
incremented by 1 every 4 usecs. Then TCP_ISSINCR =
1 (incr) 1 (secs) 10^6 (incr)
------------------ x ------------------ = --------------------
4 x 10^(-6) (secs) IP_CLOCKHZ (ticks) 4 x IP_CLOCKHZ (tick)
For an IP clock tick of 250 msecs (i.e. IP_CLOCKHZ = 4 ticks/sec)
TCP_ISSINCR = 1/16 x 10^6 = 62500 incr/tick. */
#define TCP_ISSINCR (62500UL) /* tcp_iss increment on each tick */
/* Round-Trip Time and Variance Scaling Factors. The smoothed round-trip
time and estimated variance are stored in the tcb as fixed point
values scaled-up by the multipliers below. */
#define TCP_RTT_SCALE 8 /* multiplier for SRTT */
#define TCP_RTT_SHIFT 3 /* log2 of SRTT multiplier */
#define TCP_RTTVAR_SCALE 4 /* multiplier for RTTVAR */
#define TCP_RTTVAR_SHIFT 2 /* log2 of RTTVAR multiplier */
#define REAL_RTTUNIT 1000000UL /* route cache rtt values recorded */
/* in units of microseconds */
/* TCP Retransmit Timeout Macro */
#define TCP_REXMTVAL(tp) ((((kal_int32)(tp)->t_srtt)>>TCP_RTT_SHIFT)+((kal_int32)(tp)->t_rttvar))
#endif /* _TCP_H_ */