Embedded Xinu Operating System
An ongoing research project and educational operating system.
 All Data Structures Files Functions Variables Typedefs Enumerations Macros Groups Pages
Functions

Transmission Control Protocol driver. More...

Functions

ushort tcpAlloc (void)
 
ushort tcpChksum (struct packet *pkt, ushort len, struct netaddr *src, struct netaddr *dst)
 
devcall tcpClose (device *devptr)
 
devcall tcpControl (device *devptr, int func, long arg1, long arg2)
 
struct tcb * tcpDemux (ushort dstpt, ushort srcpt, struct netaddr *dstip, struct netaddr *srcip)
 
devcall tcpFree (struct tcb *tcbptr)
 
devcall tcpGetc (device *devptr)
 
devcall tcpInit (device *devptr)
 
devcall tcpOpen (device *devptr, va_list ap)
 
devcall tcpOpenActive (struct tcb *tcbptr)
 
devcall tcpPutc (device *devptr, char ch)
 
devcall tcpRead (device *devptr, void *buf, uint len)
 
int tcpRecv (struct packet *pkt, struct netaddr *src, struct netaddr *dst)
 
int tcpRecvAck (struct packet *pkt, struct tcb *tcbptr)
 
int tcpRecvData (struct packet *pkt, struct tcb *tcbptr)
 
int tcpRecvListen (struct packet *pkt, struct tcb *tcbptr, struct netaddr *src)
 
int tcpRecvOpts (struct packet *pkt, struct tcb *tcbptr)
 
int tcpRecvOther (struct packet *pkt, struct tcb *tcbptr)
 
int tcpRecvRtt (struct tcb *tcbptr)
 
int tcpRecvSynsent (struct packet *pkt, struct tcb *tcbptr)
 
bool tcpRecvValid (struct packet *pkt, struct tcb *tcbptr)
 
int tcpSend (struct tcb *tcbptr, uchar ctrl, uint seqnum, uint acknum, uint datastart, ushort datalen)
 
int tcpSendAck (struct tcb *tcbptr)
 
int tcpSendData (struct tcb *tcbptr)
 
int tcpSendPersist (struct tcb *tcbptr)
 
int tcpSendRst (struct packet *pkt, struct netaddr *src, struct netaddr *dst)
 
int tcpSendRxt (struct tcb *tcbptr)
 
int tcpSendSyn (struct tcb *tcbptr)
 
ushort tcpSendWindow (struct tcb *tcbptr)
 
tcpseq tcpSeqdiff (tcpseq first, tcpseq second)
 
int tcpSetup (struct tcb *tcbptr)
 
void tcpStat (struct tcb *tcbptr)
 
thread tcpTimer (void)
 
devcall tcpTimerPurge (struct tcb *tcbptr, uchar type)
 
int tcpTimerRemain (struct tcb *tcbptr, uchar type)
 
devcall tcpTimerSched (int time, struct tcb *tcbptr, uchar type)
 
void tcpTimerTrigger (uchar type, struct tcb *tcbptr)
 
devcall tcpWrite (device *devptr, void *buf, uint len)
 

Detailed Description

Transmission Control Protocol driver.

This module provides an interface to the Transmission Control Protocol (TCP).

Function Documentation

ushort tcpAlloc ( void  )

Allocate an available tcp device.

Returns
device number for a tcp device, SYSERR if none are free
devcall tcpClose ( device *  devptr)

Close a TCP device.

Parameters
devptrTCP device table entry
Returns
OK if TCP is closed properly, otherwise SYSERR
devcall tcpControl ( device *  devptr,
int  func,
long  arg1,
long  arg2 
)

Control function for TCP devices.

Parameters
devptrethernet device table entry
funccontrol function to execute
arg1first argument for the control function
arg2second argument for the control function
Returns
the result of the control function
struct tcb* tcpDemux ( ushort  dstpt,
ushort  srcpt,
struct netaddr *  dstip,
struct netaddr *  srcip 
)

Locate the TCP socket for a TCP packet

Parameters
dstptdestination port of the TCP packet
srcptsource port of the TCP packet
dstipdestination IP of the TCP packet
srcipsource IP of the TCP packet
Returns
most completely matched socket, NULL if no match
devcall tcpFree ( struct tcb *  tcbptr)

Delete a TCB.

Parameters
tcbptrpointer to transmission control block for connection TCB mutex is already held
devcall tcpGetc ( device *  devptr)

Read into a single octet from TCP.

Parameters
devptrTCP device table entry
Returns
character read from TCP
devcall tcpInit ( device *  devptr)

Initialize TCP structures.

Parameters
devptrtcp device table entry
Returns
OK if device is initialized
devcall tcpOpen ( device *  devptr,
va_list  ap 
)

Associate a tcp with a network device.

Parameters
devptrtcp device table entry
ap2nd argument is the local IP address 3rd argument is the remote IP address 4th argument is the local port (auto-assigned if zero) 5th argument is the remote port (ignored if zero) 6th argument is the mode (TCP_ACTIVE or TCP_PASSIVE)
Returns
OK if TCP is opened properly, otherwise SYSERR
devcall tcpOpenActive ( struct tcb *  tcbptr)

Actively opens a TCP connection.

Parameters
tcbptrTCB for connection
Returns
OK if tcp is opened properly, otherwise SYSERR
Precondition
-condition TCB mutex is already held
Postcondition
-condition TCB mutex is still held
devcall tcpPutc ( device *  devptr,
char  ch 
)

Write a single octet to send via TCP.

Parameters
devptrTCP device table entry
chcharacter to output
Returns
ch as an unsigned char cast to an int on success; SYSERR on failure.
devcall tcpRead ( device *  devptr,
void *  buf,
uint  len 
)

Read into a buffer from TCP.

Parameters
devptrTCP device table entry
bufbuffer to read octets into
lensize of the buffer
Returns
count of octets read
int tcpRecv ( struct packet *  pkt,
struct netaddr *  src,
struct netaddr *  dst 
)

Processes an incoming TCP packet. See RFC 793, pg 65 for an overview of the TCP packet arrival algorithm.

Parameters
pktincoming packet
srcsource of incoming packet
dstdestination of incoming packet
int tcpRecvAck ( struct packet *  pkt,
struct tcb *  tcbptr 
)

Process an ackowledgement of data in an incoming TCP segment for a connection which has been fully established.

Parameters
pktincoming packet
tcbptrpointer to transmission control block for connection TCB mutex is already held TCB mutex is still held
int tcpRecvData ( struct packet *  pkt,
struct tcb *  tcbptr 
)

Processes the data in an incoming packet for a TCP connection. Function based on RFC 763, pg 73-76.

Parameters
pktincoming packet
tcbptrpointer to transmission control block for connection
Precondition
-condition TCB mutex is already held
Postcondition
-condition TCB mutex is still held
int tcpRecvListen ( struct packet *  pkt,
struct tcb *  tcbptr,
struct netaddr *  src 
)

Processes an incoming packet for a TCP connection in the LISTEN state.

Parameters
pktincoming packet
tcbptrpointer to transmission control block for connection
srcsource IP address
Returns
OK
Precondition
-condition TCB mutex is already held
int tcpRecvOpts ( struct packet *  pkt,
struct tcb *  tcbptr 
)

Processes the options in an incoming packet for a TCP connection.

Parameters
pktincoming packet
tcbptrpointer to transmission control block for connection
Returns
OK
Precondition
-condition TCB mutex is already held
Postcondition
-condition TCB mutex is still held
int tcpRecvOther ( struct packet *  pkt,
struct tcb *  tcbptr 
)

Processes an incoming packet for a TCP connection in the SYNRECV, ESTAB, FINWT1, FINWT2, CLOSEWT, CLOSING, LASTACK, or TIMEWT state. Function based on RFC 763, pg 69-73.

Parameters
pktincoming packet
tcbptrpointer to transmission control block for connection
Precondition
-condition TCB mutex is already held
Postcondition
-condition TCB mutex is still held
int tcpRecvRtt ( struct tcb *  tcbptr)

Handle round trip time estimates based on an incoming acknowledgement.

Parameters
tcbptrpointer to transmission control block for connection
Returns
OK TCB mutex is already held TCB mutex is still held
int tcpRecvSynsent ( struct packet *  pkt,
struct tcb *  tcbptr 
)

Processes an incoming packet for a TCP connection in the SYNSENT state. Function based on RFC 763, pg 66-68.

Parameters
pktincoming packet
tcbptrpointer to transmission control block for connection
Returns
OK or TCP_ERR_SNDRST
Precondition
-condition TCB mutex is already held
bool tcpRecvValid ( struct packet *  pkt,
struct tcb *  tcbptr 
)

Checks if an incoming TCP segment is valid.

Parameters
pktincoming packet
tcbptrpointer to transmission control block for connection TCB mutex is already held TCB mutex is still held
int tcpSend ( struct tcb *  tcbptr,
uchar  ctrl,
uint  seqnum,
uint  acknum,
uint  datastart,
ushort  datalen 
)

Sends a TCP packet for a TCP connection.

Parameters
tcbptrpointer to the transmission control block for connection
ctrlcontrol flags to be set
seqnumsequence number for the packet
acknumacknowledgement number for the packet
datadata to be included in the packet, NULL if no data
datalenlength of the data, 0 if no data
Precondition
-condition TCB mutex is already held
Postcondition
-condition TCB mutex is still held
int tcpSendAck ( struct tcb *  tcbptr)

Sends an ACK packet to ackowledge all received data for a TCP connection.

Parameters
tcpptrpointer to the transmission control block for connection
Precondition
-condition TCB mutex is already held
Postcondition
-condition TCB mutex is still held
int tcpSendData ( struct tcb *  tcbptr)

Sends pending outbound data (including SYN and FIN) for a TCP connection, if new data is ready for transmission.

Parameters
tcpptrpointer to the transmission control block for connection
Returns
number of octets sent
Precondition
-condition TCB mutex is already held
Postcondition
-condition TCB mutex is still held

< amount of window filled with data pending ACK

< amount of data pending ACK or transmission

int tcpSendPersist ( struct tcb *  tcbptr)

Send a segment to probe a receiver who advertised a window size of 0.

Parameters
tcpptrpointer to the transmission control block for connection
Returns
number of octets sent
int tcpSendRst ( struct packet *  pkt,
struct netaddr *  src,
struct netaddr *  dst 
)

Sends a reset in response to an incorrect TCP packet

Parameters
pktincoming packet which requires a reset response
srcsource IP address of the packet
dstdestination IP address of the packet
int tcpSendRxt ( struct tcb *  tcbptr)

Retransmitts a segment of pending outbound data (including SYN and FIN) for a TCP connection.

Parameters
tcpptrpointer to the transmission control block for connection
Returns
number of octets sent

< amount of data pending ACK

int tcpSendSyn ( struct tcb *  tcbptr)

Sends an SYN packet to establish a TCP connection.

Parameters
tcpptrpointer to the transmission control block for connection
Precondition
-condition TCB mutex is already held
Postcondition
-condition TCB mutex is still held
ushort tcpSendWindow ( struct tcb *  tcbptr)

Calculates the window size to advertise in an outgoing TCP packet.

Parameters
tcbptrpointer to transmission control block for connection
Precondition
-condition TCB mutex is already held
Postcondition
-condition TCB mutex is still held
tcpseq tcpSeqdiff ( tcpseq  first,
tcpseq  second 
)

Calculates the difference between two sequence numbers.

Parameters
firstsequence number that occurs first
secondsequence number that occurs second
Returns
difference between two sequence numbers
int tcpSetup ( struct tcb *  tcbptr)

Intializes a transmission control block. tcbptr TCB for connection

Returns
OK if TCB is initialized properly, otherwise SYSERR
Precondition
-condition TCB mutex is already held
Postcondition
-condition TCB mutex is still held
void tcpStat ( struct tcb *  tcbptr)

Transmission Control Protocol status command.

Parameters
tcbptrpointer to transmission control block
thread tcpTimer ( void  )

TCP timer process to manage timeout and retransmit events.

devcall tcpTimerPurge ( struct tcb *  tcbptr,
uchar  type 
)

Remove all TCP timer events for a particular TCB.

Parameters
tcbptrTCB for which to remove all events
typetype of events to remove, all types are removed if NULL
Returns
the time elapsed for the first remvoed event, SYSERR if no events were removed
int tcpTimerRemain ( struct tcb *  tcbptr,
uchar  type 
)

Determine time reamining for a TCP timer event for a particular TCB.

Parameters
tcbptrTCB to which event corresponds
typetype of timer event
Returns
time remaining for event, 0 if no event exists
devcall tcpTimerSched ( int  time,
struct tcb *  tcbptr,
uchar  type 
)

Schedule TCP timer events.

Parameters
timemilliseconds before timer triggers
tcbptrTCB with which event is associated
typetype of timer event
Returns
OK if event is successfully scheduled, otherwise SYSERR
void tcpTimerTrigger ( uchar  type,
struct tcb *  tcbptr 
)

Processes TCP timer events.

Parameters
evtptrtimer event to process
devcall tcpWrite ( device *  devptr,
void *  buf,
uint  len 
)

Write into a buffer to send via TCP.

Parameters
devptrTCP device table entry
bufbuffer to read octets into
lensize of the buffer
Returns
count of octets written