Working on UDP, removed debug from some code, fixed ARP setting hwtype to 0x100 ...
[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;  //!< Next server in the list
65         Uint16  Port;           //!< Listening port (0 disables the server)
66         tInterface      *Interface;     //!< Listening Interface
67         tVFS_Node       Node;   //!< Server Directory node
68          int    NextID;         //!< Name of the next connection
69         tSpinlock       lConnections;   //!< Spinlock for connections
70         tTCPConnection  *Connections;   //!< Connections (linked list)
71          tTCPConnection *volatile NewConnections;
72 };
73
74 struct sTCPConnection
75 {
76         struct sTCPConnection   *Next;
77          int    State;  //!< Connection state (see ::eTCPConnectionState)
78         Uint16  LocalPort;      //!< Local port
79         Uint16  RemotePort;     //!< Remote port
80         tInterface      *Interface;     //!< Listening Interface
81         tVFS_Node       Node;   //!< Node
82         
83          int    NextSequenceSend;       //!< Next sequence value for outbound packets
84          int    NextSequenceRcv;        //!< Next expected sequence value for inbound
85         
86          int    nQueuedPackets; //!< Number of packets not ACKed
87         struct {
88                  int    Sequence;
89                 void    *Data;
90         }       *QueuedPackets; //!< Non-ACKed packets
91         
92         
93          int    nFuturePackets; //!< Number of packets recieved that are out of sequence
94         struct {
95                  int    SequenceNum;
96                 void    *Data;
97         }       **FuturePackets;        //!< Out of sequence packets
98         
99         union {
100                 tIPv4   v4;
101                 tIPv6   v6;
102         } RemoteIP;     //!< Remote IP Address
103         // Type is determined by LocalInterface->Type
104 };
105
106 enum eTCPConnectionState
107 {
108         TCP_ST_CLOSED,
109         TCP_ST_HALFOPEN,
110         TCP_ST_OPEN
111 };
112
113 #endif

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