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