87515ce981f910f738d5ef26b8cd26e85861e663
[tpg/acess2.git] / Modules / IPStack / tcp.h
1 /*
2  * Acess2 IP Stack
3  * - TCP Definitions
4  */
5 #ifndef _TCP_H_
6 #define _TCP_H_
7
8 #include "ipstack.h"
9
10 typedef struct sTCPHeader       tTCPHeader;
11 typedef struct sTCPListener     tTCPListener;
12 typedef struct sTCPStoredPacket tTCPStoredPacket;
13 typedef struct sTCPConnection   tTCPConnection;
14
15 struct sTCPHeader
16 {
17         Uint16  SourcePort;
18         Uint16  DestPort;
19         Uint32  SequenceNumber;
20         Uint32  AcknowlegementNumber;
21         #if 0
22         struct {
23                 unsigned Reserved:      4;
24                 unsigned DataOffset: 4; // Size of the header in 32-bit words
25         } __attribute__ ((packed));
26         #else
27         Uint8   DataOffset;
28         #endif
29         #if 0
30         struct {        // Lowest to Highest
31                 unsigned FIN:   1;      // Last packet
32                 unsigned SYN:   1;      // Synchronise Sequence Numbers
33                 unsigned RST:   1;      // Reset Connection
34                 unsigned PSH:   1;      // Push Function
35                 unsigned ACK:   1;      // Acknowlegement field is significant
36                 unsigned URG:   1;      // Urgent pointer is significant
37                 unsigned ECE:   1;      // ECN-Echo
38                 unsigned CWR:   1;      // Congestion Window Reduced
39         } __attribute__ ((packed)) Flags;
40         #else
41         Uint8   Flags;
42         #endif
43         Uint16  WindowSize;
44         
45         Uint16  Checksum;
46         Uint16  UrgentPointer;
47         
48         Uint8   Options[];
49 } __attribute__ ((packed));
50
51 enum eTCPFlags
52 {
53         TCP_FLAG_FIN    = 0x01,
54         TCP_FLAG_SYN    = 0x02,
55         TCP_FLAG_RST    = 0x04,
56         TCP_FLAG_PSH    = 0x08,
57         TCP_FLAG_ACK    = 0x10,
58         TCP_FLAG_URG    = 0x20,
59         TCP_FLAG_ECE    = 0x40,
60         TCP_FLAG_CWR    = 0x80
61 };
62
63 struct sTCPListener
64 {
65         struct sTCPListener     *Next;  //!< Next server in the list
66         Uint16  Port;           //!< Listening port (0 disables the server)
67         tInterface      *Interface;     //!< Listening Interface
68         tVFS_Node       Node;   //!< Server Directory node
69          int    NextID;         //!< Name of the next connection
70         tSpinlock       lConnections;   //!< Spinlock for connections
71         tTCPConnection  *Connections;   //!< Connections (linked list)
72          tTCPConnection *volatile NewConnections;
73 };
74
75 struct sTCPStoredPacket
76 {
77         struct sTCPStoredPacket *Next;
78         Uint32  Sequence;
79         Uint8   Data[];
80 };
81
82 struct sTCPConnection
83 {
84         struct sTCPConnection   *Next;
85          int    State;  //!< Connection state (see ::eTCPConnectionState)
86         Uint16  LocalPort;      //!< Local port
87         Uint16  RemotePort;     //!< Remote port
88         tInterface      *Interface;     //!< Listening Interface
89         tVFS_Node       Node;   //!< Node
90         
91          int    NextSequenceSend;       //!< Next sequence value for outbound packets
92          int    NextSequenceRcv;        //!< Next expected sequence value for inbound
93         
94         tTCPStoredPacket        *QueuedPackets; //!< Non-ACKed packets
95         
96         tSpinlock       lRecievedPackets;
97         tTCPStoredPacket        *RecievedPackets;       //!< Unread Packets
98         tTCPStoredPacket        *RecievedPacketsTail;   //!< Unread Packets (End of list)
99         
100         tTCPStoredPacket        *FuturePackets; //!< Out of sequence packets
101         
102         union {
103                 tIPv4   v4;
104                 tIPv6   v6;
105         } RemoteIP;     //!< Remote IP Address
106         // Type is determined by LocalInterface->Type
107 };
108
109 enum eTCPConnectionState
110 {
111         TCP_ST_CLOSED,
112         TCP_ST_HALFOPEN,
113         TCP_ST_OPEN
114 };
115
116 #endif

UCC git Repository :: git.ucc.asn.au