Work on IP/TCP Stack
[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 sTCPConnection   tTCPConnection;
13
14 struct sTCPHeader
15 {
16         Uint16  SourcePort;
17         Uint16  DestPort;
18         Uint32  SequenceNumber;
19         Uint32  AcknowlegementNumber;
20         #if 0
21         struct {
22                 unsigned Reserved:      4;
23                 unsigned DataOffset: 4; // Size of the header in 32-bit words
24         } __attribute__ ((packed));
25         #else
26         Uint8   DataOffset;
27         #endif
28         #if 0
29         struct {        // Lowest to Highest
30                 unsigned FIN:   1;      // Last packet
31                 unsigned SYN:   1;      // Synchronise Sequence Numbers
32                 unsigned RST:   1;      // Reset Connection
33                 unsigned PSH:   1;      // Push Function
34                 unsigned ACK:   1;      // Acknowlegement field is significant
35                 unsigned URG:   1;      // Urgent pointer is significant
36                 unsigned ECE:   1;      // ECN-Echo
37                 unsigned CWR:   1;      // Congestion Window Reduced
38         } __attribute__ ((packed)) Flags;
39         #else
40         Uint8   Flags;
41         #endif
42         Uint16  WindowSize;
43         
44         Uint16  Checksum;
45         Uint16  UrgentPointer;
46         
47         Uint8   Options[];
48 } __attribute__ ((packed));
49
50 enum eTCPFlags
51 {
52         TCP_FLAG_FIN    = 0x01,
53         TCP_FLAG_SYN    = 0x02,
54         TCP_FLAG_RST    = 0x04,
55         TCP_FLAG_PSH    = 0x08,
56         TCP_FLAG_ACK    = 0x10,
57         TCP_FLAG_URG    = 0x20,
58         TCP_FLAG_ECE    = 0x40,
59         TCP_FLAG_CWR    = 0x80
60 };
61
62 struct sTCPListener
63 {
64         struct sTCPListener     *Next;
65         Uint16  Port;
66         tInterface      *Interface;
67         tVFS_Node       Node;
68          int    NextID;
69         tTCPConnection  *Connections;
70 };
71
72 struct sTCPConnection
73 {
74         struct sTCPConnection   *Next;
75          int    State;
76         Uint16  LocalPort;
77         Uint16  RemotePort;
78         tVFS_Node       Node;
79         
80          int    NextSequenceSend;
81          int    NextSequenceRcv;
82         
83          int    nQueuedPackets;
84         struct {
85                  int    Sequence;
86                 void    *Data;
87         }       *QueuedPackets;
88         
89         
90          int    nFuturePackets;
91         struct {
92                  int    SequenceNum;
93                 void    *Data;
94         }       **FuturePackets;
95         
96         tInterface      *Interface;
97         union {
98                 tIPv4   v4;
99                 tIPv6   v6;
100         } RemoteIP;     // Type is determined by LocalInterface->Type
101 };
102
103 enum eTCPConnectionState
104 {
105         TCP_ST_CLOSED,
106         TCP_ST_HALFOPEN,
107         TCP_ST_OPEN
108 };
109
110 #endif

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