e63fad28214a8fe0b061cde89175b68da32186d3
[reactos.git] / drivers / network / tcpip / include / titypes.h
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS TCP/IP protocol driver
4 * FILE: include/titypes.h
5 * PURPOSE: TCP/IP protocol driver types
6 */
7
8 #pragma once
9
10 /*
11 * VOID ReferenceObject(
12 * PVOID Object)
13 */
14 #define ReferenceObject(Object) \
15 { \
16 ASSERT((Object)->RefCount); \
17 InterlockedIncrement(&((Object)->RefCount)); \
18 }
19
20 /*
21 * VOID DereferenceObject(
22 * PVOID Object)
23 */
24 #define DereferenceObject(Object) \
25 { \
26 ASSERT((Object)->RefCount); \
27 if (InterlockedDecrement(&((Object)->RefCount)) == 0) \
28 (((Object)->Free)(Object)); \
29 }
30
31 /*
32 * VOID LockObject(PVOID Object, PKIRQL OldIrql)
33 */
34 #define LockObject(Object, Irql) \
35 { \
36 ReferenceObject(Object); \
37 KeAcquireSpinLock(&((Object)->Lock), Irql); \
38 memcpy(&(Object)->OldIrql, Irql, sizeof(KIRQL)); \
39 }
40
41 /*
42 * VOID LockObjectAtDpcLevel(PVOID Object)
43 */
44 #define LockObjectAtDpcLevel(Object) \
45 { \
46 ReferenceObject(Object); \
47 KeAcquireSpinLockAtDpcLevel(&((Object)->Lock)); \
48 (Object)->OldIrql = DISPATCH_LEVEL; \
49 }
50
51 /*
52 * VOID UnlockObject(PVOID Object, KIRQL OldIrql)
53 */
54 #define UnlockObject(Object, OldIrql) \
55 { \
56 KeReleaseSpinLock(&((Object)->Lock), OldIrql); \
57 DereferenceObject(Object); \
58 }
59
60 /*
61 * VOID UnlockObjectFromDpcLevel(PVOID Object)
62 */
63 #define UnlockObjectFromDpcLevel(Object) \
64 { \
65 KeReleaseSpinLockFromDpcLevel(&((Object)->Lock)); \
66 DereferenceObject(Object); \
67 }
68
69
70
71 #include <ip.h>
72
73 struct _ADDRESS_FILE;
74
75 /***************************************************
76 * Connection-less communication support structures *
77 ***************************************************/
78
79 typedef NTSTATUS (*DATAGRAM_SEND_ROUTINE)(
80 struct _ADDRESS_FILE *AddrFile,
81 PTDI_CONNECTION_INFORMATION ConnInfo,
82 PCHAR Buffer,
83 ULONG DataSize,
84 PULONG DataUsed);
85
86 /* Datagram completion handler prototype */
87 typedef VOID (*DATAGRAM_COMPLETION_ROUTINE)(
88 PVOID Context,
89 NDIS_STATUS Status,
90 ULONG Count);
91
92 typedef DATAGRAM_COMPLETION_ROUTINE PDATAGRAM_COMPLETION_ROUTINE;
93
94 typedef struct _DATAGRAM_RECEIVE_REQUEST {
95 struct _ADDRESS_FILE *AddressFile; /* AddressFile on behalf of */
96 LIST_ENTRY ListEntry; /* Entry on list */
97 IP_ADDRESS RemoteAddress; /* Remote address we receive from (NULL means any) */
98 USHORT RemotePort; /* Remote port we receive from (0 means any) */
99 PTDI_CONNECTION_INFORMATION ReturnInfo;/* Return information */
100 PCHAR Buffer; /* Pointer to receive buffer */
101 ULONG BufferSize; /* Size of Buffer */
102 DATAGRAM_COMPLETION_ROUTINE Complete; /* Completion routine */
103 PVOID Context; /* Pointer to context information */
104 DATAGRAM_COMPLETION_ROUTINE UserComplete; /* Completion routine */
105 PVOID UserContext; /* Pointer to context information */
106 PIRP Irp; /* IRP on behalf of */
107 } DATAGRAM_RECEIVE_REQUEST, *PDATAGRAM_RECEIVE_REQUEST;
108
109 /* Datagram build routine prototype */
110 typedef NTSTATUS (*DATAGRAM_BUILD_ROUTINE)(
111 PVOID Context,
112 PIP_ADDRESS LocalAddress,
113 USHORT LocalPort,
114 PIP_PACKET *IPPacket);
115
116 typedef struct _DATAGRAM_SEND_REQUEST {
117 LIST_ENTRY ListEntry;
118 PNDIS_PACKET PacketToSend;
119 DATAGRAM_COMPLETION_ROUTINE Complete; /* Completion routine */
120 PVOID Context; /* Pointer to context information */
121 IP_PACKET Packet;
122 UINT BufferSize;
123 IP_ADDRESS RemoteAddress;
124 USHORT RemotePort;
125 ULONG Flags; /* Protocol specific flags */
126 } DATAGRAM_SEND_REQUEST, *PDATAGRAM_SEND_REQUEST;
127
128 /* Transport address file context structure. The FileObject->FsContext2
129 field holds a pointer to this structure */
130 typedef struct _ADDRESS_FILE {
131 LIST_ENTRY ListEntry; /* Entry on list */
132 LONG RefCount; /* Reference count */
133 OBJECT_FREE_ROUTINE Free; /* Routine to use to free resources for the object */
134 KSPIN_LOCK Lock; /* Spin lock to manipulate this structure */
135 KIRQL OldIrql; /* Currently not used */
136 IP_ADDRESS Address; /* Address of this address file */
137 USHORT Family; /* Address family */
138 USHORT Protocol; /* Protocol number */
139 USHORT Port; /* Network port (network byte order) */
140 LONG Sharers; /* Number of file objects with this addr file */
141 UCHAR TTL; /* Time to live stored in packets sent from this address file */
142 UINT DF; /* Don't fragment */
143 UINT BCast; /* Receive broadcast packets */
144 UINT HeaderIncl; /* Include header in RawIP packets */
145 WORK_QUEUE_ITEM WorkItem; /* Work queue item handle */
146 DATAGRAM_COMPLETION_ROUTINE Complete; /* Completion routine for delete request */
147 PVOID Context; /* Delete request context */
148 DATAGRAM_SEND_ROUTINE Send; /* Routine to send a datagram */
149 LIST_ENTRY ReceiveQueue; /* List of outstanding receive requests */
150 LIST_ENTRY TransmitQueue; /* List of outstanding transmit requests */
151 struct _CONNECTION_ENDPOINT *Connection;
152 /* Associated connection or NULL if no associated connection exist */
153 struct _CONNECTION_ENDPOINT *Listener;
154 /* Associated listener (see transport/tcp/accept.c) */
155 IP_ADDRESS AddrCache; /* One entry address cache (destination
156 address of last packet transmitted) */
157 HANDLE ProcessId; /* Creator process ID */
158 LARGE_INTEGER CreationTime; /* Time of creation */
159
160 /* The following members are used to control event notification */
161
162 /* Connection indication handler */
163 PTDI_IND_CONNECT ConnectHandler;
164 PVOID ConnectHandlerContext;
165 BOOLEAN RegisteredConnectHandler;
166 /* Disconnect indication handler */
167 PTDI_IND_DISCONNECT DisconnectHandler;
168 PVOID DisconnectHandlerContext;
169 BOOLEAN RegisteredDisconnectHandler;
170 /* Error indication handler */
171 PTDI_IND_ERROR ErrorHandler;
172 PVOID ErrorHandlerContext;
173 PVOID ErrorHandlerOwner;
174 BOOLEAN RegisteredErrorHandler;
175 /* Receive indication handler */
176 PTDI_IND_RECEIVE ReceiveHandler;
177 PVOID ReceiveHandlerContext;
178 BOOLEAN RegisteredReceiveHandler;
179 /* Receive datagram indication handler */
180 PTDI_IND_RECEIVE_DATAGRAM ReceiveDatagramHandler;
181 PVOID ReceiveDatagramHandlerContext;
182 BOOLEAN RegisteredReceiveDatagramHandler;
183 /* Expedited receive indication handler */
184 PTDI_IND_RECEIVE_EXPEDITED ExpeditedReceiveHandler;
185 PVOID ExpeditedReceiveHandlerContext;
186 BOOLEAN RegisteredExpeditedReceiveHandler;
187 /* Chained receive indication handler */
188 PTDI_IND_CHAINED_RECEIVE ChainedReceiveHandler;
189 PVOID ChainedReceiveHandlerContext;
190 BOOLEAN RegisteredChainedReceiveHandler;
191 /* Chained receive datagram indication handler */
192 PTDI_IND_CHAINED_RECEIVE_DATAGRAM ChainedReceiveDatagramHandler;
193 PVOID ChainedReceiveDatagramHandlerContext;
194 BOOLEAN RegisteredChainedReceiveDatagramHandler;
195 /* Chained expedited receive indication handler */
196 PTDI_IND_CHAINED_RECEIVE_EXPEDITED ChainedReceiveExpeditedHandler;
197 PVOID ChainedReceiveExpeditedHandlerContext;
198 BOOLEAN RegisteredChainedReceiveExpeditedHandler;
199 } ADDRESS_FILE, *PADDRESS_FILE;
200
201 /* Structure used to search through Address Files */
202 typedef struct _AF_SEARCH {
203 PLIST_ENTRY Next; /* Next address file to check */
204 PIP_ADDRESS Address; /* Pointer to address to be found */
205 USHORT Port; /* Network port */
206 USHORT Protocol; /* Protocol number */
207 } AF_SEARCH, *PAF_SEARCH;
208
209 /*******************************************************
210 * Connection-oriented communication support structures *
211 *******************************************************/
212
213 typedef struct _TCP_RECEIVE_REQUEST {
214 LIST_ENTRY ListEntry; /* Entry on list */
215 PNDIS_BUFFER Buffer; /* Pointer to receive buffer */
216 ULONG BufferSize; /* Size of Buffer */
217 DATAGRAM_COMPLETION_ROUTINE Complete; /* Completion routine */
218 PVOID Context; /* Pointer to context information */
219 } TCP_RECEIVE_REQUEST, *PTCP_RECEIVE_REQUEST;
220
221 /* Connection states */
222 typedef enum {
223 ctListen = 0, /* Waiting for incoming connection requests */
224 ctSynSent, /* Waiting for matching connection request */
225 ctSynReceived, /* Waiting for connection request acknowledgment */
226 ctEstablished, /* Connection is open for data transfer */
227 ctFinWait1, /* Waiting for termination request or ack. for same */
228 ctFinWait2, /* Waiting for termination request from remote TCP */
229 ctCloseWait, /* Waiting for termination request from local user */
230 ctClosing, /* Waiting for termination ack. from remote TCP */
231 ctLastAck, /* Waiting for termination request ack. from remote TCP */
232 ctTimeWait, /* Waiting for enough time to pass to be sure the remote TCP
233 received the ack. of its connection termination request */
234 ctClosed /* Represents a closed connection */
235 } CONNECTION_STATE, *PCONNECTION_STATE;
236
237
238 /* Structure for an TCP segment */
239 typedef struct _TCP_SEGMENT {
240 LIST_ENTRY ListEntry;
241 PIP_PACKET IPPacket; /* Pointer to IP packet */
242 PVOID SegmentData; /* Pointer to segment data */
243 ULONG SequenceNumber; /* Sequence number of first byte in segment */
244 ULONG Length; /* Number of bytes in segment */
245 ULONG BytesDelivered; /* Number of bytes already delivered to the client */
246 } TCP_SEGMENT, *PTCP_SEGMENT;
247
248 typedef struct _TDI_BUCKET {
249 LIST_ENTRY Entry;
250 struct _CONNECTION_ENDPOINT *AssociatedEndpoint;
251 TDI_REQUEST Request;
252 NTSTATUS Status;
253 ULONG Information;
254 } TDI_BUCKET, *PTDI_BUCKET;
255
256 /* Transport connection context structure A.K.A. Transmission Control Block
257 (TCB) in TCP terminology. The FileObject->FsContext2 field holds a pointer
258 to this structure */
259 typedef struct _CONNECTION_ENDPOINT {
260 PVOID SocketContext; /* Context for lower layer (MUST be first member in struct) */
261 LIST_ENTRY ListEntry; /* Entry on list */
262 LONG RefCount; /* Reference count */
263 OBJECT_FREE_ROUTINE Free; /* Routine to use to free resources for the object */
264 KSPIN_LOCK Lock; /* Spin lock to protect this structure */
265 KIRQL OldIrql; /* The old irql is stored here for use in HandleSignalledConnection */
266 PVOID ClientContext; /* Pointer to client context information */
267 PADDRESS_FILE AddressFile; /* Associated address file object (NULL if none) */
268
269 /* Requests */
270 LIST_ENTRY ConnectRequest; /* Queued connect requests */
271 LIST_ENTRY ListenRequest; /* Queued listen requests */
272 LIST_ENTRY ReceiveRequest; /* Queued receive requests */
273 LIST_ENTRY SendRequest; /* Queued send requests */
274 LIST_ENTRY ShutdownRequest;/* Queued shutdown requests */
275
276 LIST_ENTRY PacketQueue; /* Queued received packets waiting to be processed */
277
278 /* Disconnect Timer */
279 KTIMER DisconnectTimer;
280 KDPC DisconnectDpc;
281
282 /* Socket state */
283 BOOLEAN SendShutdown;
284 BOOLEAN ReceiveShutdown;
285 NTSTATUS ReceiveShutdownStatus;
286 BOOLEAN Closing;
287
288 struct _CONNECTION_ENDPOINT *Next; /* Next connection in address file list */
289 } CONNECTION_ENDPOINT, *PCONNECTION_ENDPOINT;
290
291
292
293 /*************************
294 * TDI support structures *
295 *************************/
296
297 /* Transport control channel context structure. The FileObject->FsContext2
298 field holds a pointer to this structure */
299 typedef struct _CONTROL_CHANNEL {
300 LIST_ENTRY ListEntry; /* Entry on list */
301 LONG RefCount; /* Reference count */
302 OBJECT_FREE_ROUTINE Free; /* Routine to use to free resources for the object */
303 KSPIN_LOCK Lock; /* Spin lock to protect this structure */
304 } CONTROL_CHANNEL, *PCONTROL_CHANNEL;
305
306 /* Transport (TCP/UDP) endpoint context structure. The FileObject->FsContext
307 field holds a pointer to this structure */
308 typedef struct _TRANSPORT_CONTEXT {
309 union {
310 HANDLE AddressHandle;
311 CONNECTION_CONTEXT ConnectionContext;
312 HANDLE ControlChannel;
313 } Handle;
314 BOOLEAN CancelIrps;
315 KEVENT CleanupEvent;
316 } TRANSPORT_CONTEXT, *PTRANSPORT_CONTEXT;
317
318 typedef struct _TI_QUERY_CONTEXT {
319 PIRP Irp;
320 PMDL InputMdl;
321 PMDL OutputMdl;
322 TCP_REQUEST_QUERY_INFORMATION_EX QueryInfo;
323 } TI_QUERY_CONTEXT, *PTI_QUERY_CONTEXT;
324
325 /* EOF */