[SERVMAN]
[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 /* TCPv4 header flags */
28 #define TCP_URG 0x20
29 #define TCP_ACK 0x10
30 #define TCP_PSH 0x08
31 #define TCP_RST 0x04
32 #define TCP_SYN 0x02
33 #define TCP_FIN 0x01
34
35
36 #define TCPOPT_END_OF_LIST 0x0
37 #define TCPOPT_NO_OPERATION 0x1
38 #define TCPOPT_MAX_SEG_SIZE 0x2
39
40 #define TCPOPTLEN_MAX_SEG_SIZE 0x4
41
42 /* Data offset; 32-bit words (leftmost 4 bits); convert to bytes */
43 #define TCP_DATA_OFFSET(DataOffset)(((DataOffset) & 0xF0) >> (4-2))
44
45
46 /* TCPv4 pseudo header */
47 typedef struct TCPv4_PSEUDO_HEADER {
48 ULONG SourceAddress; /* Source address */
49 ULONG DestinationAddress; /* Destination address */
50 UCHAR Zero; /* Reserved */
51 UCHAR Protocol; /* Protocol */
52 USHORT TCPLength; /* Size of TCP segment */
53 } TCPv4_PSEUDO_HEADER, *PTCPv4_PSEUDO_HEADER;
54 #include <poppack.h>
55
56 typedef struct _SLEEPING_THREAD {
57 LIST_ENTRY Entry;
58 PVOID SleepToken;
59 KEVENT Event;
60 } SLEEPING_THREAD, *PSLEEPING_THREAD;
61
62 typedef struct _CLIENT_DATA {
63 BOOLEAN Unlocked;
64 KSPIN_LOCK Lock;
65 KIRQL OldIrql;
66 } CLIENT_DATA, *PCLIENT_DATA;
67
68 /* Retransmission timeout constants */
69
70 /* Lower bound for retransmission timeout in TCP timer ticks */
71 #define TCP_MIN_RETRANSMISSION_TIMEOUT 1*1000 /* 1 tick */
72
73 /* Upper bound for retransmission timeout in TCP timer ticks */
74 #define TCP_MAX_RETRANSMISSION_TIMEOUT 1*60*1000 /* 1 tick */
75
76 /* Smoothing factor */
77 #define TCP_ALPHA_RETRANSMISSION_TIMEOUT(x)(((x)*8)/10) /* 0.8 */
78
79 /* Delay variance factor */
80 #define TCP_BETA_RETRANSMISSION_TIMEOUT(x)(((x)*16)/10) /* 1.6 */
81
82
83 /* Datagram/segment send request flags */
84
85 #define SRF_URG TCP_URG
86 #define SRF_ACK TCP_ACK
87 #define SRF_PSH TCP_PSH
88 #define SRF_RST TCP_RST
89 #define SRF_SYN TCP_SYN
90 #define SRF_FIN TCP_FIN
91
92 extern LONG TCP_IPIdentification;
93 extern CLIENT_DATA ClientInfo;
94
95 /* accept.c */
96 NTSTATUS TCPServiceListeningSocket( PCONNECTION_ENDPOINT Listener,
97 PCONNECTION_ENDPOINT Connection,
98 PTDI_REQUEST_KERNEL Request );
99 NTSTATUS TCPListen( PCONNECTION_ENDPOINT Connection, UINT Backlog );
100 BOOLEAN TCPAbortListenForSocket( PCONNECTION_ENDPOINT Listener,
101 PCONNECTION_ENDPOINT Connection );
102 NTSTATUS TCPAccept
103 ( PTDI_REQUEST Request,
104 PCONNECTION_ENDPOINT Listener,
105 PCONNECTION_ENDPOINT Connection,
106 PTCP_COMPLETION_ROUTINE Complete,
107 PVOID Context );
108
109 /* tcp.c */
110 PCONNECTION_ENDPOINT TCPAllocateConnectionEndpoint( PVOID ClientContext );
111 VOID TCPFreeConnectionEndpoint( PCONNECTION_ENDPOINT Connection );
112
113 NTSTATUS TCPSocket( PCONNECTION_ENDPOINT Connection,
114 UINT Family, UINT Type, UINT Proto );
115
116 VOID HandleSignalledConnection(PCONNECTION_ENDPOINT Connection);
117
118 PTCP_SEGMENT TCPCreateSegment(
119 PIP_PACKET IPPacket,
120 PTCPv4_HEADER TCPHeader,
121 ULONG SegmentLength);
122
123 VOID TCPFreeSegment(
124 PTCP_SEGMENT Segment);
125
126 VOID TCPAddSegment(
127 PCONNECTION_ENDPOINT Connection,
128 PTCP_SEGMENT Segment,
129 PULONG Acknowledged);
130
131 NTSTATUS TCPConnect(
132 PCONNECTION_ENDPOINT Connection,
133 PTDI_CONNECTION_INFORMATION ConnInfo,
134 PTDI_CONNECTION_INFORMATION ReturnInfo,
135 PTCP_COMPLETION_ROUTINE Complete,
136 PVOID Context);
137
138 NTSTATUS TCPDisconnect(
139 PCONNECTION_ENDPOINT Connection,
140 UINT Flags,
141 PLARGE_INTEGER Timeout,
142 PTDI_CONNECTION_INFORMATION ConnInfo,
143 PTDI_CONNECTION_INFORMATION ReturnInfo,
144 PTCP_COMPLETION_ROUTINE Complete,
145 PVOID Context);
146
147 NTSTATUS TCPReceiveData(
148 PCONNECTION_ENDPOINT Connection,
149 PNDIS_BUFFER Buffer,
150 ULONG ReceiveLength,
151 PULONG BytesReceived,
152 ULONG ReceiveFlags,
153 PTCP_COMPLETION_ROUTINE Complete,
154 PVOID Context);
155
156 NTSTATUS TCPSendData(
157 PCONNECTION_ENDPOINT Connection,
158 PCHAR Buffer,
159 ULONG DataSize,
160 PULONG DataUsed,
161 ULONG Flags,
162 PTCP_COMPLETION_ROUTINE Complete,
163 PVOID Context);
164
165 NTSTATUS TCPClose( PCONNECTION_ENDPOINT Connection );
166
167 NTSTATUS TCPTranslateError( int OskitError );
168
169 UINT TCPAllocatePort( UINT HintPort );
170
171 VOID TCPFreePort( UINT Port );
172
173 NTSTATUS TCPGetSockAddress
174 ( PCONNECTION_ENDPOINT Connection,
175 PTRANSPORT_ADDRESS TransportAddress,
176 BOOLEAN RemoteAddress );
177
178 NTSTATUS TCPStartup(
179 VOID);
180
181 NTSTATUS TCPShutdown(
182 VOID);
183
184 BOOLEAN TCPRemoveIRP( PCONNECTION_ENDPOINT Connection, PIRP Irp );