/*****************************************************************************
* nettcp.c - Network Transport Control Protocol program file.
*
* Copyright (c) 1998 by Global Election Systems Inc. All rights reserved.
*
* The authors hereby grant permission to use, copy, modify, distribute,
* and license this software and its documentation for any purpose, provided
* that existing copyright notices are retained in all copies and that this
* notice and the following disclaimer are included verbatim in any
* distributions. No written agreement, license, or royalty fee is required
* for any of the authorized uses.
*
* THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************
* REVISION HISTORY
*
* 98-02-02 Guy Lancaster <[email protected]>, Global Election Systems Inc.
* Original based on ka9q and BSD codes.
******************************************************************************
* NOTES
*
* MAXIMUM WINDOW
* We use a signed short int for the segment size adjustment (trimSeg()) to
* allow returning error codes. Thus our maximum segment size must be <=
* INT_MAX (i.e. 32767) rather than MAX_UINT. This is not a problem
* considering that we are using a PPP link over a serial link.
*
* HEADER CACHE
* The header values are all loaded in the header caches before being
* written to the outgoing segment so that a debugger can see the values
* of the header last sent.
******************************************************************************
* TO DO
*
* - Implement a SENDFIN flag in the tcb flags and use it in tcpOutput().
* - FINISH close!
*****************************************************************************/
#include "typedefs.h"
#include "avconfig.h"
#include <string.h>
#include "stdio.h" // Required for debug.h
#include "timer.h"
#include "avos.h"
#include "netbuf.h"
#include "devio.h"
#include "net.h"
#include "netmagic.h"
#include "netip.h"
#include "netiphdr.h"
#include "nettcp.h"
#include "nettcphd.h"
#include "debug.h"
/*************************/
/*** LOCAL DEFINITIONS ***/
/*************************/
/* Configuration */
#define MAXTCP 6 /* Maximum TCP connections incl listeners. */
#define TCPTTL 64 /* Default time-to-live for TCP datagrams. */
#define OPTSPACE 5*4 /* TCP options space - must be a multiple of 4. */
#define NTCB 16 /* # TCB hash table headers */
#define MAXRETRANS 12 /* Maximum retransmissions. */
#define MAXKEEPTIMES 10 /* Maximum keep alive probe timeouts. */
#define MAXLISTEN 2 /* Maximum queued cloned listen connections. */
#define MAXFINWAIT2 600L /* Max time in seconds to wait for peer FIN. */
#define WRITESLEEP TICKSPERSEC /* Sleep time write waits for buffers (jiffies). */
#define STACK_SIZE NETSTACK /* Minimal stack. */
/*
* TCP connection control flag masks.
*/
#define FORCE 1 /* We owe the other end an ACK or window update */
#define CLONE 2 /* Server-type TCB, cloned on incoming SYN */
#define RETRAN 4 /* A retransmission has occurred */
#define ACTIVE 8 /* TCB created with an active open */
#define SYNACK 16 /* Our SYN has been acked */
#define KEEPALIVE 32 /* Send a keepalive probe */
/* Round trip timing parameters */
#define AGAIN 8 /* Average RTT gain = 1/8 */
#define DGAIN 4 /* Mean deviation gain = 1/4 */
#define MSL2 30 /* Guess at two maximum-segment lifetimes in seconds */
/* procInFlags return codes. */
#define ACKOK 0 /* OK to process segment. */
#define ACKDROP -1 /* Drop the segment. */
#define ACKRESET -2 /* Return segment as a reset. */
#define ACKCLOSE -3 /* Close the connection. */
/************************/
/*** LOCAL DATA TYPES ***/
/************************/
/*
* Combined TCP/IP headers with no options. Used to cached the headers.
*/
typedef struct TcpIPHdr_s {
IPHdr ipHdr; /* IP header - no options. */
TCPHdr tcpHdr; /* TCP header. tcpSeq, ack, off, & win
* are in host byte order.
*/
char options[OPTSPACE]; /* Cache for TCP options. */
} TCPIPHdr;
/*
* TCP connection states.
*/
typedef enum {
CLOSED = 0, /* Must be 0 */
LISTEN = 1,
SYN_SENT= 2,
SYN_RECEIVED = 3,
ESTABLISHED = 4,
FINWAIT1 = 5,
FINWAIT2 = 6,
CLOSE_WAIT = 7,
CLOSING = 8,
LAST_ACK = 9,
TIME_WAIT = 10
} TCPState;
/*
* TCP session close reason codes.
*/
typedef enum {
NORMAL = 0, /* Normal close */
RESET = 1, /* Reset by other end */
TIMEOUT = 2, /* Excessive retransmissions */
NETWORK = 3 /* Network problem (ICMP message) */
} TCPReason;
/*
* TCP connection control block.
*/
typedef struct TCPCB_s {
struct TCPCB_s *prev; /* Linked list pointers for hash table */
struct TCPCB_s *next;
Connection conn; /* Connection struct for hash lookup. */
TCPState state; /* Connection state */
int freeOnClose; /* Flag set to free TCB on close. */
int closeReason; /* Reason for closing - TCPERR_ or 0 */
int traceLevel; /* Trace level this connection. */
/*
* Send sequence variables.
*/
struct {
int32 una; /* First unacknowledged sequence number */
int32 nxt; /* Next sequence num to be sent for the first time */
int32 ptr; /* Working transmission pointer */
int16 wnd; /* Other end's offered receive window */
int32 wl1; /* Sequence number used for last window update */
int32 wl2; /* Ack number used for last window update */
} snd;
int32 iss; /* Initial send sequence number */
int16 cwind; /* Congestion window */
int16 ssthresh; /* Slow-start threshold */
int32 resent; /* Count of bytes retransmitted */
/* Receive sequence variables */
struct {
int32 nxt; /* Incoming sequence number expected next */
int16 wnd; /* Our offered receive window */
int16 up; /* Receive urgent pointer */
} rcv;
int32 irs; /* Initial receive sequence number */
int16 mss; /* Maximum segment size */
int32 rerecv; /* Count of duplicate bytes received */
int minFreeBufs; /* Minimum free buffers before we'll queue something. */
char backoff; /* Backoff interval */
char flags; /* Control flags */
int listenQOpen; /* Max queued listen connections. */
int listenQHead; /* Head of cloned TCB queue. */
int listenQTail; /* Tail of cloned TCB queue. */
struct TCPCB_s
*listenQ[MAXLISTEN + 1]; /* Circular queue of clones. */
NBufQHdr rcvq; /* Receive queue */
int16 rcvcnt; /* Bytes on receive queue. */
NBuf *rcvBuf; /* Hold one buffer while we trim it. */
NBufQHdr sndq; /* Send queue */
int16 sndcnt; /* Number of unacknowledged sequence numbers on
* send queue. NB: includes SYN and FIN, which don't
* actually appear on sndq!
*/
NBufQHdr *reseq; /* Out-of-order segment queue */
Timer resendTimer; /* Timeout timer */
u_int32 retransTime; /* Retransmission time - 0 for none. */
u_int retransCnt; /* Retransmission count at current wl2. */
u_int32 rttStart; /* Start time for round trip measurement. */
int32 rttseq; /* Sequence number being timed */
int32 srtt; /* Smoothed round trip time, milliseconds */
int32 mdev; /* Mean deviation, milliseconds */
u_long keepAlive; /* Keepalive in Jiffys - 0 fo
没有合适的资源?快使用搜索试试~ 我知道了~
uCOS-net-1.0.rar_UCys.Net_ucos_ucos net
共44个文件
h:22个
c:20个
txt:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 57 浏览量
2022-09-23
22:50:45
上传
评论
收藏 193KB RAR 举报
温馨提示
UCOS-ii对于网络的支持代码,对于使用Ucos-ii建立自己网络操作系统软件的朋友至关重要
资源推荐
资源详情
资源评论
收起资源包目录
uCOS-net-1.0.rar (44个子文件)
www.pudn.com.txt 218B
uCOS_Net_r0
TIMER.H 6KB
rand.h 2KB
TIMER.C 11KB
NETMAGIC.H 3KB
netfsm.h 8KB
netlcp.h 6KB
netppp.h 8KB
nettcp.h 9KB
netchpms.c 11KB
netchpms.h 3KB
net.h 27KB
NETPAP.H 5KB
netchap.c 24KB
netip.h 5KB
README.htm 9KB
avos.c 6KB
chat.c 18KB
net.c 8KB
NETPAP.C 15KB
netchap.h 7KB
netfsm.c 21KB
NETMAGIC.C 3KB
netbuf.c 22KB
netvj.c 17KB
netvj.h 6KB
netauth.c 23KB
netip.c 15KB
netlcp.c 51KB
NETIPCP.H 5KB
netipcp.c 34KB
neticmp.h 9KB
netauth.h 4KB
netppp.c 44KB
netbuf.h 16KB
debug.h 4KB
rand.c 4KB
typedefs.h 5KB
debug.c 31KB
netiphdr.h 8KB
nettcp.c 93KB
chat.h 2KB
neticmp.c 14KB
avos.h 5KB
共 44 条
- 1
资源评论
小波思基
- 粉丝: 72
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功