Revert my patch from yesterday. Need to take more time to work on it.
[reactos.git] / reactos / drivers / net / tcpip / include / tcp.h
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS TCP/IP protocol driver
4 * FILE: include/tcp.h
5 * PURPOSE: Transmission Control Protocol definitions
6 */
7 #ifndef __TCP_H
8 #define __TCP_H
9
10 typedef VOID
11 (*PTCP_COMPLETION_ROUTINE)( PVOID Context, NTSTATUS Status, ULONG Count );
12
13 /* TCPv4 header structure */
14 typedef struct TCPv4_HEADER {
15 USHORT SourcePort; /* Source port */
16 USHORT DestinationPort; /* Destination port */
17 ULONG SequenceNumber; /* Sequence number */
18 ULONG AckNumber; /* Acknowledgement number */
19 UCHAR DataOffset; /* Data offset; 32-bit words (leftmost 4 bits) */
20 UCHAR Flags; /* Control bits (rightmost 6 bits) */
21 USHORT Window; /* Maximum acceptable receive window */
22 USHORT Checksum; /* Checksum of segment */
23 USHORT Urgent; /* Pointer to urgent data */
24 } __attribute__((packed)) TCPv4_HEADER, *PTCPv4_HEADER;
25
26 /* TCPv4 header flags */
27 #define TCP_URG 0x20
28 #define TCP_ACK 0x10
29 #define TCP_PSH 0x08
30 #define TCP_RST 0x04
31 #define TCP_SYN 0x02
32 #define TCP_FIN 0x01
33
34
35 #define TCPOPT_END_OF_LIST 0x0
36 #define TCPOPT_NO_OPERATION 0x1
37 #define TCPOPT_MAX_SEG_SIZE 0x2
38
39 #define TCPOPTLEN_MAX_SEG_SIZE 0x4
40
41 /* Data offset; 32-bit words (leftmost 4 bits); convert to bytes */
42 #define TCP_DATA_OFFSET(DataOffset)(((DataOffset) & 0xF0) >> (4-2))
43
44
45 /* TCPv4 pseudo header */
46 typedef struct TCPv4_PSEUDO_HEADER {
47 ULONG SourceAddress; /* Source address */
48 ULONG DestinationAddress; /* Destination address */
49 UCHAR Zero; /* Reserved */
50 UCHAR Protocol; /* Protocol */
51 USHORT TCPLength; /* Size of TCP segment */
52 } __attribute__((packed)) TCPv4_PSEUDO_HEADER, *PTCPv4_PSEUDO_HEADER;
53
54 typedef struct _SLEEPING_THREAD {
55 LIST_ENTRY Entry;
56 PVOID SleepToken;
57 KEVENT Event;
58 } SLEEPING_THREAD, *PSLEEPING_THREAD;
59
60 /* Retransmission timeout constants */
61
62 /* Lower bound for retransmission timeout in TCP timer ticks */
63 #define TCP_MIN_RETRANSMISSION_TIMEOUT 1*1000 /* 1 tick */
64
65 /* Upper bound for retransmission timeout in TCP timer ticks */
66 #define TCP_MAX_RETRANSMISSION_TIMEOUT 1*60*1000 /* 1 tick */
67
68 /* Smoothing factor */
69 #define TCP_ALPHA_RETRANSMISSION_TIMEOUT(x)(((x)*8)/10) /* 0.8 */
70
71 /* Delay variance factor */
72 #define TCP_BETA_RETRANSMISSION_TIMEOUT(x)(((x)*16)/10) /* 1.6 */
73
74
75 /* Datagram/segment send request flags */
76
77 #define SRF_URG TCP_URG
78 #define SRF_ACK TCP_ACK
79 #define SRF_PSH TCP_PSH
80 #define SRF_RST TCP_RST
81 #define SRF_SYN TCP_SYN
82 #define SRF_FIN TCP_FIN
83
84 extern LONG TCP_IPIdentification;
85 extern LIST_ENTRY SignalledConnections;
86 extern LIST_ENTRY SleepingThreadsList;
87 extern FAST_MUTEX SleepingThreadsLock;
88 extern RECURSIVE_MUTEX TCPLock;
89
90 /* accept.c */
91 NTSTATUS TCPServiceListeningSocket( PCONNECTION_ENDPOINT Listener,
92 PCONNECTION_ENDPOINT Connection,
93 PTDI_REQUEST_KERNEL Request );
94 NTSTATUS TCPListen( PCONNECTION_ENDPOINT Connection, UINT Backlog );
95 VOID TCPAbortListenForSocket( PCONNECTION_ENDPOINT Listener,
96 PCONNECTION_ENDPOINT Connection );
97 NTSTATUS TCPAccept
98 ( PTDI_REQUEST Request,
99 PCONNECTION_ENDPOINT Listener,
100 PCONNECTION_ENDPOINT Connection,
101 PTCP_COMPLETION_ROUTINE Complete,
102 PVOID Context );
103
104 /* tcp.c */
105 PCONNECTION_ENDPOINT TCPAllocateConnectionEndpoint( PVOID ClientContext );
106 VOID TCPFreeConnectionEndpoint( PCONNECTION_ENDPOINT Connection );
107
108 NTSTATUS TCPSocket( PCONNECTION_ENDPOINT Connection,
109 UINT Family, UINT Type, UINT Proto );
110
111 PTCP_SEGMENT TCPCreateSegment(
112 PIP_PACKET IPPacket,
113 PTCPv4_HEADER TCPHeader,
114 ULONG SegmentLength);
115
116 VOID TCPFreeSegment(
117 PTCP_SEGMENT Segment);
118
119 VOID TCPAddSegment(
120 PCONNECTION_ENDPOINT Connection,
121 PTCP_SEGMENT Segment,
122 PULONG Acknowledged);
123
124 NTSTATUS TCPConnect(
125 PCONNECTION_ENDPOINT Connection,
126 PTDI_CONNECTION_INFORMATION ConnInfo,
127 PTDI_CONNECTION_INFORMATION ReturnInfo,
128 PTCP_COMPLETION_ROUTINE Complete,
129 PVOID Context);
130
131 NTSTATUS TCPDisconnect(
132 PCONNECTION_ENDPOINT Connection,
133 UINT Flags,
134 PTDI_CONNECTION_INFORMATION ConnInfo,
135 PTDI_CONNECTION_INFORMATION ReturnInfo,
136 PTCP_COMPLETION_ROUTINE Complete,
137 PVOID Context);
138
139 NTSTATUS TCPReceiveData(
140 PCONNECTION_ENDPOINT Connection,
141 PNDIS_BUFFER Buffer,
142 ULONG ReceiveLength,
143 PULONG BytesReceived,
144 ULONG ReceiveFlags,
145 PTCP_COMPLETION_ROUTINE Complete,
146 PVOID Context);
147
148 NTSTATUS TCPSendData(
149 PCONNECTION_ENDPOINT Connection,
150 PCHAR Buffer,
151 ULONG DataSize,
152 PULONG DataUsed,
153 ULONG Flags);
154
155 NTSTATUS TCPClose( PCONNECTION_ENDPOINT Connection );
156
157 PVOID TCPPrepareInterface( PIP_INTERFACE IF );
158
159 VOID TCPDisposeInterfaceData( PVOID Data );
160
161 NTSTATUS TCPTranslateError( int OskitError );
162
163 VOID TCPTimeout();
164
165 UINT TCPAllocatePort( UINT HintPort );
166
167 VOID TCPFreePort( UINT Port );
168
169 NTSTATUS TCPGetPeerAddress
170 ( PCONNECTION_ENDPOINT Connection,
171 PTRANSPORT_ADDRESS TransportAddress );
172
173 NTSTATUS TCPStartup(
174 VOID);
175
176 NTSTATUS TCPShutdown(
177 VOID);
178
179 #endif /* __TCP_H */