[TCPIP]
[reactos.git] / reactos / drivers / network / 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
8 #pragma once
9
10 typedef VOID
11 (*PTCP_COMPLETION_ROUTINE)( PVOID Context, NTSTATUS Status, ULONG Count );
12
13 /* TCPv4 header structure */
14 #include <pshpack1.h>
15 typedef struct TCPv4_HEADER {
16 USHORT SourcePort; /* Source port */
17 USHORT DestinationPort; /* Destination port */
18 ULONG SequenceNumber; /* Sequence number */
19 ULONG AckNumber; /* Acknowledgement number */
20 UCHAR DataOffset; /* Data offset; 32-bit words (leftmost 4 bits) */
21 UCHAR Flags; /* Control bits (rightmost 6 bits) */
22 USHORT Window; /* Maximum acceptable receive window */
23 USHORT Checksum; /* Checksum of segment */
24 USHORT Urgent; /* Pointer to urgent data */
25 } TCPv4_HEADER, *PTCPv4_HEADER;
26
27 #define TCPOPT_END_OF_LIST 0x0
28 #define TCPOPT_NO_OPERATION 0x1
29 #define TCPOPT_MAX_SEG_SIZE 0x2
30
31 #define TCPOPTLEN_MAX_SEG_SIZE 0x4
32
33 /* Data offset; 32-bit words (leftmost 4 bits); convert to bytes */
34 #define TCP_DATA_OFFSET(DataOffset)(((DataOffset) & 0xF0) >> (4-2))
35
36
37 /* TCPv4 pseudo header */
38 typedef struct TCPv4_PSEUDO_HEADER {
39 ULONG SourceAddress; /* Source address */
40 ULONG DestinationAddress; /* Destination address */
41 UCHAR Zero; /* Reserved */
42 UCHAR Protocol; /* Protocol */
43 USHORT TCPLength; /* Size of TCP segment */
44 } TCPv4_PSEUDO_HEADER, *PTCPv4_PSEUDO_HEADER;
45 #include <poppack.h>
46
47 typedef struct _SLEEPING_THREAD {
48 LIST_ENTRY Entry;
49 PVOID SleepToken;
50 KEVENT Event;
51 } SLEEPING_THREAD, *PSLEEPING_THREAD;
52
53 typedef struct _CLIENT_DATA {
54 BOOLEAN Unlocked;
55 KSPIN_LOCK Lock;
56 KIRQL OldIrql;
57 } CLIENT_DATA, *PCLIENT_DATA;
58
59 /* Retransmission timeout constants */
60
61 /* Lower bound for retransmission timeout in TCP timer ticks */
62 #define TCP_MIN_RETRANSMISSION_TIMEOUT 1*1000 /* 1 tick */
63
64 /* Upper bound for retransmission timeout in TCP timer ticks */
65 #define TCP_MAX_RETRANSMISSION_TIMEOUT 1*60*1000 /* 1 tick */
66
67 /* Smoothing factor */
68 #define TCP_ALPHA_RETRANSMISSION_TIMEOUT(x)(((x)*8)/10) /* 0.8 */
69
70 /* Delay variance factor */
71 #define TCP_BETA_RETRANSMISSION_TIMEOUT(x)(((x)*16)/10) /* 1.6 */
72
73 #define SEL_CONNECT 1
74 #define SEL_FIN 2
75 #define SEL_RST 4
76 #define SEL_ABRT 8
77 #define SEL_READ 16
78 #define SEL_WRITE 32
79 #define SEL_ACCEPT 64
80 #define SEL_OOB 128
81 #define SEL_ERROR 256
82 #define SEL_FINOUT 512
83
84 #define FREAD 0x0001
85 #define FWRITE 0x0002
86
87 /* Datagram/segment send request flags */
88
89 #define SRF_URG TCP_URG
90 #define SRF_ACK TCP_ACK
91 #define SRF_PSH TCP_PSH
92 #define SRF_RST TCP_RST
93 #define SRF_SYN TCP_SYN
94 #define SRF_FIN TCP_FIN
95
96 extern LONG TCP_IPIdentification;
97 extern CLIENT_DATA ClientInfo;
98
99 /* accept.c */
100 NTSTATUS TCPCheckPeerForAccept(PVOID Context,
101 PTDI_REQUEST_KERNEL Request);
102 NTSTATUS TCPListen( PCONNECTION_ENDPOINT Connection, UINT Backlog );
103 BOOLEAN TCPAbortListenForSocket( PCONNECTION_ENDPOINT Listener,
104 PCONNECTION_ENDPOINT Connection );
105 NTSTATUS TCPAccept
106 ( PTDI_REQUEST Request,
107 PCONNECTION_ENDPOINT Listener,
108 PCONNECTION_ENDPOINT Connection,
109 PTCP_COMPLETION_ROUTINE Complete,
110 PVOID Context );
111
112 /* tcp.c */
113 PCONNECTION_ENDPOINT TCPAllocateConnectionEndpoint( PVOID ClientContext );
114 VOID TCPFreeConnectionEndpoint( PCONNECTION_ENDPOINT Connection );
115
116 NTSTATUS TCPSocket( PCONNECTION_ENDPOINT Connection,
117 UINT Family, UINT Type, UINT Proto );
118
119 VOID HandleSignalledConnection(PCONNECTION_ENDPOINT Connection);
120
121 PTCP_SEGMENT TCPCreateSegment(
122 PIP_PACKET IPPacket,
123 PTCPv4_HEADER TCPHeader,
124 ULONG SegmentLength);
125
126 VOID TCPFreeSegment(
127 PTCP_SEGMENT Segment);
128
129 VOID TCPAddSegment(
130 PCONNECTION_ENDPOINT Connection,
131 PTCP_SEGMENT Segment,
132 PULONG Acknowledged);
133
134 NTSTATUS TCPConnect(
135 PCONNECTION_ENDPOINT Connection,
136 PTDI_CONNECTION_INFORMATION ConnInfo,
137 PTDI_CONNECTION_INFORMATION ReturnInfo,
138 PTCP_COMPLETION_ROUTINE Complete,
139 PVOID Context);
140
141 NTSTATUS TCPDisconnect(
142 PCONNECTION_ENDPOINT Connection,
143 UINT Flags,
144 PLARGE_INTEGER Timeout,
145 PTDI_CONNECTION_INFORMATION ConnInfo,
146 PTDI_CONNECTION_INFORMATION ReturnInfo,
147 PTCP_COMPLETION_ROUTINE Complete,
148 PVOID Context);
149
150 NTSTATUS TCPReceiveData(
151 PCONNECTION_ENDPOINT Connection,
152 PNDIS_BUFFER Buffer,
153 ULONG ReceiveLength,
154 PULONG BytesReceived,
155 ULONG ReceiveFlags,
156 PTCP_COMPLETION_ROUTINE Complete,
157 PVOID Context);
158
159 NTSTATUS TCPSendData(
160 PCONNECTION_ENDPOINT Connection,
161 PCHAR Buffer,
162 ULONG DataSize,
163 PULONG DataUsed,
164 ULONG Flags,
165 PTCP_COMPLETION_ROUTINE Complete,
166 PVOID Context);
167
168 NTSTATUS TCPClose( PCONNECTION_ENDPOINT Connection );
169
170 NTSTATUS TCPTranslateError( const INT8 err );
171
172 UINT TCPAllocatePort( const UINT HintPort );
173
174 VOID TCPFreePort( const UINT Port );
175
176 NTSTATUS TCPGetSockAddress
177 ( PCONNECTION_ENDPOINT Connection,
178 PTRANSPORT_ADDRESS TransportAddress,
179 BOOLEAN RemoteAddress );
180
181 NTSTATUS TCPStartup(
182 VOID);
183
184 NTSTATUS TCPShutdown(
185 VOID);
186
187 BOOLEAN TCPRemoveIRP( PCONNECTION_ENDPOINT Connection, PIRP Irp );
188
189 VOID
190 TCPUpdateInterfaceLinkStatus(PIP_INTERFACE IF);
191
192 VOID
193 TCPUpdateInterfaceIPInformation(PIP_INTERFACE IF);
194
195 VOID
196 FlushListenQueue(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status);
197
198 VOID
199 FlushConnectQueue(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status);
200
201 VOID
202 FlushReceiveQueue(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status, const BOOLEAN interlocked);
203
204 VOID
205 FlushSendQueue(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status, const BOOLEAN interlocked);
206
207 VOID
208 FlushShutdownQueue(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status, const BOOLEAN interlocked);
209
210 VOID
211 FlushAllQueues(PCONNECTION_ENDPOINT Connection, NTSTATUS Status);
212
213 VOID CompleteBucket(PCONNECTION_ENDPOINT Connection, PTDI_BUCKET Bucket, const BOOLEAN Synchronous);