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