- Rework our oskittcp signalling
[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 #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 #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 /* Retransmission timeout constants */
63
64 /* Lower bound for retransmission timeout in TCP timer ticks */
65 #define TCP_MIN_RETRANSMISSION_TIMEOUT 1*1000 /* 1 tick */
66
67 /* Upper bound for retransmission timeout in TCP timer ticks */
68 #define TCP_MAX_RETRANSMISSION_TIMEOUT 1*60*1000 /* 1 tick */
69
70 /* Smoothing factor */
71 #define TCP_ALPHA_RETRANSMISSION_TIMEOUT(x)(((x)*8)/10) /* 0.8 */
72
73 /* Delay variance factor */
74 #define TCP_BETA_RETRANSMISSION_TIMEOUT(x)(((x)*16)/10) /* 1.6 */
75
76
77 /* Datagram/segment send request flags */
78
79 #define SRF_URG TCP_URG
80 #define SRF_ACK TCP_ACK
81 #define SRF_PSH TCP_PSH
82 #define SRF_RST TCP_RST
83 #define SRF_SYN TCP_SYN
84 #define SRF_FIN TCP_FIN
85
86 extern LONG TCP_IPIdentification;
87 extern LIST_ENTRY SignalledConnectionsList;
88 extern KSPIN_LOCK SignalledConnectionsLock;
89 extern LIST_ENTRY SleepingThreadsList;
90 extern FAST_MUTEX SleepingThreadsLock;
91 extern RECURSIVE_MUTEX TCPLock;
92
93 /* accept.c */
94 NTSTATUS TCPServiceListeningSocket( PCONNECTION_ENDPOINT Listener,
95 PCONNECTION_ENDPOINT Connection,
96 PTDI_REQUEST_KERNEL Request );
97 NTSTATUS TCPListen( PCONNECTION_ENDPOINT Connection, UINT Backlog );
98 VOID TCPAbortListenForSocket( PCONNECTION_ENDPOINT Listener,
99 PCONNECTION_ENDPOINT Connection );
100 NTSTATUS TCPAccept
101 ( PTDI_REQUEST Request,
102 PCONNECTION_ENDPOINT Listener,
103 PCONNECTION_ENDPOINT Connection,
104 PTCP_COMPLETION_ROUTINE Complete,
105 PVOID Context );
106
107 /* tcp.c */
108 ULONG HandleSignalledConnection( PCONNECTION_ENDPOINT Connection );
109 PCONNECTION_ENDPOINT TCPAllocateConnectionEndpoint( PVOID ClientContext );
110 VOID TCPFreeConnectionEndpoint( PCONNECTION_ENDPOINT Connection );
111
112 NTSTATUS TCPSocket( PCONNECTION_ENDPOINT Connection,
113 UINT Family, UINT Type, UINT Proto );
114
115 PTCP_SEGMENT TCPCreateSegment(
116 PIP_PACKET IPPacket,
117 PTCPv4_HEADER TCPHeader,
118 ULONG SegmentLength);
119
120 VOID TCPFreeSegment(
121 PTCP_SEGMENT Segment);
122
123 VOID TCPAddSegment(
124 PCONNECTION_ENDPOINT Connection,
125 PTCP_SEGMENT Segment,
126 PULONG Acknowledged);
127
128 NTSTATUS TCPConnect(
129 PCONNECTION_ENDPOINT Connection,
130 PTDI_CONNECTION_INFORMATION ConnInfo,
131 PTDI_CONNECTION_INFORMATION ReturnInfo,
132 PTCP_COMPLETION_ROUTINE Complete,
133 PVOID Context);
134
135 NTSTATUS TCPDisconnect(
136 PCONNECTION_ENDPOINT Connection,
137 UINT Flags,
138 PTDI_CONNECTION_INFORMATION ConnInfo,
139 PTDI_CONNECTION_INFORMATION ReturnInfo,
140 PTCP_COMPLETION_ROUTINE Complete,
141 PVOID Context);
142
143 NTSTATUS TCPReceiveData(
144 PCONNECTION_ENDPOINT Connection,
145 PNDIS_BUFFER Buffer,
146 ULONG ReceiveLength,
147 PULONG BytesReceived,
148 ULONG ReceiveFlags,
149 PTCP_COMPLETION_ROUTINE Complete,
150 PVOID Context);
151
152 NTSTATUS TCPSendData(
153 PCONNECTION_ENDPOINT Connection,
154 PCHAR Buffer,
155 ULONG DataSize,
156 PULONG DataUsed,
157 ULONG Flags,
158 PTCP_COMPLETION_ROUTINE Complete,
159 PVOID Context);
160
161 NTSTATUS TCPClose( PCONNECTION_ENDPOINT Connection );
162
163 NTSTATUS TCPTranslateError( int OskitError );
164
165 VOID TCPTimeout();
166
167 UINT TCPAllocatePort( UINT HintPort );
168
169 VOID TCPFreePort( UINT Port );
170
171 NTSTATUS TCPGetSockAddress
172 ( PCONNECTION_ENDPOINT Connection,
173 PTRANSPORT_ADDRESS TransportAddress,
174 BOOLEAN RemoteAddress );
175
176 NTSTATUS TCPStartup(
177 VOID);
178
179 NTSTATUS TCPShutdown(
180 VOID);
181
182 VOID TCPRemoveIRP( PCONNECTION_ENDPOINT Connection, PIRP Irp );
183
184 #endif /* __TCP_H */