Create a branch for Aleksandar Andrejevic for his work on NTVDM. See http://jira...
[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 LONG Sharers; /* Number of file objects with this addr file */
139 UCHAR TTL; /* Time to live stored in packets sent from this address file */
140 UINT DF; /* Don't fragment */
141 UINT BCast; /* Receive broadcast packets */
142 UINT HeaderIncl; /* Include header in RawIP packets */
143 WORK_QUEUE_ITEM WorkItem; /* Work queue item handle */
144 DATAGRAM_COMPLETION_ROUTINE Complete; /* Completion routine for delete request */
145 PVOID Context; /* Delete request context */
146 DATAGRAM_SEND_ROUTINE Send; /* Routine to send a datagram */
147 LIST_ENTRY ReceiveQueue; /* List of outstanding receive requests */
148 LIST_ENTRY TransmitQueue; /* List of outstanding transmit requests */
149 struct _CONNECTION_ENDPOINT *Connection;
150 /* Associated connection or NULL if no associated connection exist */
151 struct _CONNECTION_ENDPOINT *Listener;
152 /* Associated listener (see transport/tcp/accept.c) */
153 IP_ADDRESS AddrCache; /* One entry address cache (destination
154 address of last packet transmitted) */
155
156 /* The following members are used to control event notification */
157
158 /* Connection indication handler */
159 PTDI_IND_CONNECT ConnectHandler;
160 PVOID ConnectHandlerContext;
161 BOOLEAN RegisteredConnectHandler;
162 /* Disconnect indication handler */
163 PTDI_IND_DISCONNECT DisconnectHandler;
164 PVOID DisconnectHandlerContext;
165 BOOLEAN RegisteredDisconnectHandler;
166 /* Error indication handler */
167 PTDI_IND_ERROR ErrorHandler;
168 PVOID ErrorHandlerContext;
169 PVOID ErrorHandlerOwner;
170 BOOLEAN RegisteredErrorHandler;
171 /* Receive indication handler */
172 PTDI_IND_RECEIVE ReceiveHandler;
173 PVOID ReceiveHandlerContext;
174 BOOLEAN RegisteredReceiveHandler;
175 /* Receive datagram indication handler */
176 PTDI_IND_RECEIVE_DATAGRAM ReceiveDatagramHandler;
177 PVOID ReceiveDatagramHandlerContext;
178 BOOLEAN RegisteredReceiveDatagramHandler;
179 /* Expedited receive indication handler */
180 PTDI_IND_RECEIVE_EXPEDITED ExpeditedReceiveHandler;
181 PVOID ExpeditedReceiveHandlerContext;
182 BOOLEAN RegisteredExpeditedReceiveHandler;
183 /* Chained receive indication handler */
184 PTDI_IND_CHAINED_RECEIVE ChainedReceiveHandler;
185 PVOID ChainedReceiveHandlerContext;
186 BOOLEAN RegisteredChainedReceiveHandler;
187 /* Chained receive datagram indication handler */
188 PTDI_IND_CHAINED_RECEIVE_DATAGRAM ChainedReceiveDatagramHandler;
189 PVOID ChainedReceiveDatagramHandlerContext;
190 BOOLEAN RegisteredChainedReceiveDatagramHandler;
191 /* Chained expedited receive indication handler */
192 PTDI_IND_CHAINED_RECEIVE_EXPEDITED ChainedReceiveExpeditedHandler;
193 PVOID ChainedReceiveExpeditedHandlerContext;
194 BOOLEAN RegisteredChainedReceiveExpeditedHandler;
195 } ADDRESS_FILE, *PADDRESS_FILE;
196
197 /* Structure used to search through Address Files */
198 typedef struct _AF_SEARCH {
199 PLIST_ENTRY Next; /* Next address file to check */
200 PIP_ADDRESS Address; /* Pointer to address to be found */
201 USHORT Port; /* Network port */
202 USHORT Protocol; /* Protocol number */
203 } AF_SEARCH, *PAF_SEARCH;
204
205 /*******************************************************
206 * Connection-oriented communication support structures *
207 *******************************************************/
208
209 typedef struct _TCP_RECEIVE_REQUEST {
210 LIST_ENTRY ListEntry; /* Entry on list */
211 PNDIS_BUFFER Buffer; /* Pointer to receive buffer */
212 ULONG BufferSize; /* Size of Buffer */
213 DATAGRAM_COMPLETION_ROUTINE Complete; /* Completion routine */
214 PVOID Context; /* Pointer to context information */
215 } TCP_RECEIVE_REQUEST, *PTCP_RECEIVE_REQUEST;
216
217 /* Connection states */
218 typedef enum {
219 ctListen = 0, /* Waiting for incoming connection requests */
220 ctSynSent, /* Waiting for matching connection request */
221 ctSynReceived, /* Waiting for connection request acknowledgment */
222 ctEstablished, /* Connection is open for data transfer */
223 ctFinWait1, /* Waiting for termination request or ack. for same */
224 ctFinWait2, /* Waiting for termination request from remote TCP */
225 ctCloseWait, /* Waiting for termination request from local user */
226 ctClosing, /* Waiting for termination ack. from remote TCP */
227 ctLastAck, /* Waiting for termination request ack. from remote TCP */
228 ctTimeWait, /* Waiting for enough time to pass to be sure the remote TCP
229 received the ack. of its connection termination request */
230 ctClosed /* Represents a closed connection */
231 } CONNECTION_STATE, *PCONNECTION_STATE;
232
233
234 /* Structure for an TCP segment */
235 typedef struct _TCP_SEGMENT {
236 LIST_ENTRY ListEntry;
237 PIP_PACKET IPPacket; /* Pointer to IP packet */
238 PVOID SegmentData; /* Pointer to segment data */
239 ULONG SequenceNumber; /* Sequence number of first byte in segment */
240 ULONG Length; /* Number of bytes in segment */
241 ULONG BytesDelivered; /* Number of bytes already delivered to the client */
242 } TCP_SEGMENT, *PTCP_SEGMENT;
243
244 typedef struct _TDI_BUCKET {
245 LIST_ENTRY Entry;
246 struct _CONNECTION_ENDPOINT *AssociatedEndpoint;
247 TDI_REQUEST Request;
248 NTSTATUS Status;
249 ULONG Information;
250 } TDI_BUCKET, *PTDI_BUCKET;
251
252 /* Transport connection context structure A.K.A. Transmission Control Block
253 (TCB) in TCP terminology. The FileObject->FsContext2 field holds a pointer
254 to this structure */
255 typedef struct _CONNECTION_ENDPOINT {
256 PVOID SocketContext; /* Context for lower layer (MUST be first member in struct) */
257 LIST_ENTRY ListEntry; /* Entry on list */
258 LONG RefCount; /* Reference count */
259 OBJECT_FREE_ROUTINE Free; /* Routine to use to free resources for the object */
260 KSPIN_LOCK Lock; /* Spin lock to protect this structure */
261 KIRQL OldIrql; /* The old irql is stored here for use in HandleSignalledConnection */
262 PVOID ClientContext; /* Pointer to client context information */
263 PADDRESS_FILE AddressFile; /* Associated address file object (NULL if none) */
264
265 /* Requests */
266 LIST_ENTRY ConnectRequest; /* Queued connect rqueusts */
267 LIST_ENTRY ListenRequest; /* Queued listen requests */
268 LIST_ENTRY ReceiveRequest; /* Queued receive requests */
269 LIST_ENTRY SendRequest; /* Queued send requests */
270 LIST_ENTRY ShutdownRequest;/* Queued shutdown requests */
271
272 LIST_ENTRY PacketQueue; /* Queued received packets waiting to be processed */
273
274 /* Disconnect Timer */
275 KTIMER DisconnectTimer;
276 KDPC DisconnectDpc;
277
278 /* Socket state */
279 BOOLEAN SendShutdown;
280 BOOLEAN ReceiveShutdown;
281 NTSTATUS ReceiveShutdownStatus;
282
283 struct _CONNECTION_ENDPOINT *Next; /* Next connection in address file list */
284 } CONNECTION_ENDPOINT, *PCONNECTION_ENDPOINT;
285
286
287
288 /*************************
289 * TDI support structures *
290 *************************/
291
292 /* Transport control channel context structure. The FileObject->FsContext2
293 field holds a pointer to this structure */
294 typedef struct _CONTROL_CHANNEL {
295 LIST_ENTRY ListEntry; /* Entry on list */
296 LONG RefCount; /* Reference count */
297 OBJECT_FREE_ROUTINE Free; /* Routine to use to free resources for the object */
298 KSPIN_LOCK Lock; /* Spin lock to protect this structure */
299 } CONTROL_CHANNEL, *PCONTROL_CHANNEL;
300
301 /* Transport (TCP/UDP) endpoint context structure. The FileObject->FsContext
302 field holds a pointer to this structure */
303 typedef struct _TRANSPORT_CONTEXT {
304 union {
305 HANDLE AddressHandle;
306 CONNECTION_CONTEXT ConnectionContext;
307 HANDLE ControlChannel;
308 } Handle;
309 BOOLEAN CancelIrps;
310 KEVENT CleanupEvent;
311 } TRANSPORT_CONTEXT, *PTRANSPORT_CONTEXT;
312
313 typedef struct _TI_QUERY_CONTEXT {
314 PIRP Irp;
315 PMDL InputMdl;
316 PMDL OutputMdl;
317 TCP_REQUEST_QUERY_INFORMATION_EX QueryInfo;
318 } TI_QUERY_CONTEXT, *PTI_QUERY_CONTEXT;
319
320 /* EOF */