⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tcp.h

📁 代码在ti的c67系列单片机上实现了完整的TCPIP协议栈
💻 H
字号:
//----------------------------------------------------------------------
//  Ip Stack
//----------------------------------------------------------------------
//  File: tcp.h
//   
//  TCP Private Data
//
// Author: Michael A. Denio
// Copyright 1999 by Texas Instruments Inc.
//----------------------------------------------------------------------

#ifndef _TCP_INC_
#define _TCP_INC_

//-----------------------------------------------------------------------
//
// Global Task Information
//

// Route Defined Messages
#define MSG_TCP_TIMER                   (ID_TCP*MSG_BLOCK + 0)


//
// TCP Header Option Definitions
//
#define TCPOPT_EOL              0
#define TCPOPT_NOP              1
#define TCPOPT_MAXSEG           2
#define TCPOLEN_MAXSEG          4
#define TCPOPT_WINDOW           3
#define TCPOLEN_WINDOW          3
#define TCPOPT_TIMESTAMP        8
#define TCPOLEN_TIMESTAMP       10


//
// TCP Definitions
//

#define TCP_ISSINCR     128000l         // ISS Bump Increment

// TCP Protocol Definitions
#define TCP_TFLAGS_DEFAULT      0
#define TCP_MAX_OPTIONS         20      // Max number of option bytes in hdr
#define TCP_MSS_DEFAULT         536     // Default mss (BSD uses 512)
#define TCP_MSS_DEFAULT_NR      1500    // Default mss sent if no route MTU
#define TCP_LINGERTIME          120     // max seconds for SO_LINGER option
#define TCP_MAXRTX              12      // maximum retransmits waiting for ACK
#define TCP_KEEP_CNT            8       // max probes before drop
#define TCP_MAXWIN              65535   // max window size
#define TCP_MAXBACKOFF          12      // max index into tcp_backoff[]
#define TCP_DUPACKTHRESH        3       // Dup ACK's before retransmit

// Timer Constants (in 1/2 second ticks)
#define TCPTV_MSL        60             // max seg lifetime
#define TCPTV_MAX_IDLE   1200           // max connection idle
#define TCPTV_RTXMIN     2              // minimum value retransmit timer
#define TCPTV_RTXMAX     128            // max value retransmit timer
#define TCPTV_PERSMIN    10             // minumum value persist timer
#define TCPTV_PERSMAX    120            // max value persist timer
#define TCPTV_KEEP_INIT  150            // initial connect keep alive
#define TCPTV_KEEP_IDLE  14400          // dflt time before first probe
#define TCPTV_KEEP_INTVL 150            // probe interval
#define TCPTV_SRTTBASE   0              // base roundtrip time start at 0
#define TCPTV_RTTDFLT    6              // default RTT if no measurements

#define TCP_FIXP_SCALE   16             // multiplier for fix point
#define TCP_FIXP_SHIFT   4              // shift for fix point

//
// RangeSet Macro sets time value and verifies it is in range
//
#define	TCPT_RANGESET(tv, value, tvmin, tvmax) { \
	(tv) = (value); \
        if ((UINT32)(tv) < (UINT32)(tvmin)) \
		(tv) = (tvmin); \
        else if ((UINT32)(tv) > (UINT32)(tvmax)) \
		(tv) = (tvmax); \
}

//
// TCP Net Packet Format Definitions
//

// TCP Flag Equates
#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 Protocol Block
typedef struct _tcpprot {
        struct  _tcpprot *pNext;
        struct  _tcpprot *pPrev;
        HANDLE  hSock;                  // Handle to parent socket
        HANDLE  hSBRx;                  // Receive Socket Buffer
        HANDLE  hSBTx;                  // Transmit Socket Buffer
        HANDLE  hFrag;                  // Out of order frags
        UINT32  dwTicksRexmt;           // Retransmit Timer
        UINT32  dwTicksPersist;         // Persist Timer
        UINT32  dwTicksKeep;            // Keepalive Timer
        UINT32  dwTicksWait2;           // FIN_WAIT2 Timer
        uint    t_mss;                  // maximum segment size
        int     t_state;                // state of this connection
        int     t_rtxindex;             // Index into tcp_backoff[]
        uint    t_dupacks;              // consecutive dup acks received
        uint    t_flags;
#define TF_ACKNOW       0x0001          // ack peer immediately
#define TF_DELACK       0x0002          // ack, but try to delay it
#define TF_NODELAY      0x0004          // don't delay packets to coalesce
#define TF_NOOPT        0x0008          // don't use tcp options
#define TF_NOPUSH       0x0010          // don't use buffer empty to goto send
#define TF_SENTFIN      0x0020          // have sent FIN
#define TF_RCVD_MSS     0x0040          // other side has send MSS
#define TF_REQ_TSTMP    0x0080          // have/will request timestamps
#define TF_RCVD_TSTMP   0x0100          // a timestamp was received in SYN
#define TF_PERSIST      0x0200          // called from PERSIST
#define TF_DETACHED     0x0300          // Detached by the Socket layer
#define TF_NEEDOUTPUT   0x0400          // Last call to output was aborted
//
// The following fields are used as in the protocol specification.
// See RFC783, Dec. 1981, page 21.
//
// send sequence variables
        UINT32  iss;                    // initial send sequence number
        UINT32  snd_una;                // send unacknowledged
        UINT32  snd_nxt;                // send next
        UINT32  snd_up;                 // send urgent pointer
        UINT32  snd_wnd;                // send window
        UINT32  snd_wl1;                // window update seg seq number
        UINT32  snd_wl2;                // window update seg ack number
// receive sequence variables
        UINT32  irs;                    // initial receive sequence number
        UINT32  rcv_nxt;                // receive next
        UINT32  rcv_up;                 // receive urgent pointer
        UINT32  rcv_adv;                // advertised window

        UINT32  snd_max;                // highest sequence number sent
        UINT32  snd_cwnd;               // congestion-controlled window
        UINT32  max_sndwnd;             // largest window peer has offered
//
// Transmit timing stuff.
//
        UINT32  t_tidle;                // inactivity time (in ticks)
        UINT32  t_trtt;                 // rttseq's round trip time (in ticks)
        UINT32  t_trtx;                 // current value of rtx timer (in ticks)
        UINT32  t_rttseq;               // sequence number being timed in trtt
        UINT32  t_srtt;                 // FIXP: smoothed round-trip time
        UINT32  t_rttvar;               // FIXP: variance in round-trip time

// out-of-band data
        INT8    t_oobflags;             // have some
        INT8    t_iobc;                 // input charcter
#define	TCPOOB_HAVEDATA	0x01
#define	TCPOOB_HADDATA	0x02
        int     t_softerror;            // possible error not yet reported
                                        // This is the "best guess" error
                                        // when a problem is detected
} TCPPROT;

// TCP State
#define TSTATE_CLOSED       0
#define TSTATE_LISTEN       1
#define TSTATE_SYNSENT      2
#define TSTATE_SYNRCVD      3
#define TSTATE_ESTAB        4
#define TSTATE_CLOSEWAIT    5
#define TSTATE_FINWAIT1     6
#define TSTATE_CLOSING      7
#define TSTATE_LASTACK      8
#define TSTATE_FINWAIT2     9
#define TSTATE_TIMEWAIT     10

// Local Functions
extern void   TcpDrop( TCPPROT *pt, int Error );
extern void   TcpClose( TCPPROT *pt );
extern void   TcpUsrClose( TCPPROT *pt );
extern int    TcpOutput( TCPPROT *pt );
extern void   TcpTimeoutAdd( TCPPROT *pt );
extern void   TcpTimeoutRemove( TCPPROT *pt );
extern void   TcpTimeoutRexmt( TCPPROT *pt );
extern void   TcpTimeoutKeep( TCPPROT *pt );
extern void   TcpTimeoutPersist( TCPPROT *pt );
extern void   TcpTimeoutWait2( TCPPROT *pt );
extern void   TcpSetPersist( TCPPROT *pt );
extern uint   TcpValidateMetrics( TCPPROT *pt, uint rcvmss );
extern void   TcpXmitTimer( TCPPROT *pt, UINT32 rtt );
extern void   TcpGenPacket( TCPPROT *pt, IPN dwIPDst, uint PortDst,
                            IPN dwIPSrc, uint PortSrc,
                            UINT32 seq, UINT32 ask, int flags );

// TCP Global Variables

extern UINT32  tcp_iss;                 // Send Sequence
extern UINT32  tcp_now;                 // TCP Tick Time

#endif


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -