This is a merge onto head of the last two months worth of changes to the
[reactos.git] / reactos / drivers / net / 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 #ifdef DBG
12
13 #define DEFINE_TAG ULONG Tag;
14 #define INIT_TAG(_Object, _Tag) \
15 ((_Object)->Tag = (_Tag))
16
17 #define DEBUG_REFCHECK(Object) { \
18 if ((Object)->RefCount <= 0) { \
19 TI_DbgPrint(MIN_TRACE, ("Object at (0x%X) has invalid reference count (%d).\n", \
20 (Object), (Object)->RefCount)); \
21 } \
22 }
23
24 /*
25 * VOID ReferenceObject(
26 * PVOID Object)
27 */
28 #define ReferenceObject(Object) \
29 { \
30 CHAR c1, c2, c3, c4; \
31 \
32 c1 = ((Object)->Tag >> 24) & 0xFF; \
33 c2 = ((Object)->Tag >> 16) & 0xFF; \
34 c3 = ((Object)->Tag >> 8) & 0xFF; \
35 c4 = ((Object)->Tag & 0xFF); \
36 \
37 DEBUG_REFCHECK(Object); \
38 TI_DbgPrint(DEBUG_REFCOUNT, ("Referencing object of type (%c%c%c%c) at (0x%X). RefCount (%d).\n", \
39 c4, c3, c2, c1, (Object), (Object)->RefCount)); \
40 \
41 InterlockedIncrement(&((Object)->RefCount)); \
42 }
43
44 /*
45 * VOID DereferenceObject(
46 * PVOID Object)
47 */
48 #define DereferenceObject(Object) \
49 { \
50 CHAR c1, c2, c3, c4; \
51 \
52 c1 = ((Object)->Tag >> 24) & 0xFF; \
53 c2 = ((Object)->Tag >> 16) & 0xFF; \
54 c3 = ((Object)->Tag >> 8) & 0xFF; \
55 c4 = ((Object)->Tag & 0xFF); \
56 \
57 DEBUG_REFCHECK(Object); \
58 TI_DbgPrint(DEBUG_REFCOUNT, ("Dereferencing object of type (%c%c%c%c) at (0x%X). RefCount (%d).\n", \
59 c4, c3, c2, c1, (Object), (Object)->RefCount)); \
60 \
61 if (InterlockedDecrement(&((Object)->RefCount)) == 0) \
62 (((Object)->Free)(Object)); \
63 }
64
65 #else /* DBG */
66
67 #define DEFINE_TAG
68 #define INIT_TAG(Object, Tag)
69
70 /*
71 * VOID ReferenceObject(
72 * PVOID Object)
73 */
74 #define ReferenceObject(Object) \
75 { \
76 InterlockedIncrement(&((Object)->RefCount)); \
77 }
78
79 /*
80 * VOID DereferenceObject(
81 * PVOID Object)
82 */
83 #define DereferenceObject(Object) \
84 { \
85 if (InterlockedDecrement(&((Object)->RefCount)) == 0) \
86 (((Object)->Free)(Object)); \
87 }
88
89 #endif /* DBG */
90
91
92 #include <ip.h>
93
94
95 /***************************************************
96 * Connection-less communication support structures *
97 ***************************************************/
98
99 typedef NTSTATUS (*DATAGRAM_SEND_ROUTINE)(
100 PTDI_REQUEST Request,
101 PTDI_CONNECTION_INFORMATION ConnInfo,
102 PNDIS_BUFFER Buffer,
103 ULONG DataSize);
104
105 /* Datagram completion handler prototype */
106 typedef VOID (*DATAGRAM_COMPLETION_ROUTINE)(
107 PVOID Context,
108 NDIS_STATUS Status,
109 ULONG Count);
110
111 typedef struct _DATAGRAM_RECEIVE_REQUEST {
112 LIST_ENTRY ListEntry; /* Entry on list */
113 PIP_ADDRESS RemoteAddress; /* Remote address we receive from (NULL means any) */
114 USHORT RemotePort; /* Remote port we receive from (0 means any) */
115 PTDI_CONNECTION_INFORMATION ReturnInfo; /* Return information */
116 PNDIS_BUFFER Buffer; /* Pointer to receive buffer */
117 ULONG BufferSize; /* Size of Buffer */
118 DATAGRAM_COMPLETION_ROUTINE Complete; /* Completion routine */
119 PVOID Context; /* Pointer to context information */
120 } DATAGRAM_RECEIVE_REQUEST, *PDATAGRAM_RECEIVE_REQUEST;
121
122 /* Datagram build routine prototype */
123 typedef NTSTATUS (*DATAGRAM_BUILD_ROUTINE)(
124 PVOID Context,
125 PIP_ADDRESS LocalAddress,
126 USHORT LocalPort,
127 PIP_PACKET *IPPacket);
128
129 typedef struct _DATAGRAM_SEND_REQUEST {
130 LIST_ENTRY ListEntry;
131 PNDIS_PACKET PacketToSend;
132 DATAGRAM_COMPLETION_ROUTINE Complete; /* Completion routine */
133 PVOID Context; /* Pointer to context information */
134 IP_PACKET Packet;
135 UINT BufferSize;
136 IP_ADDRESS RemoteAddress;
137 USHORT RemotePort;
138 ULONG Flags; /* Protocol specific flags */
139 } DATAGRAM_SEND_REQUEST, *PDATAGRAM_SEND_REQUEST;
140
141 #if 0
142 #define InitializeDatagramSendRequest( \
143 _SendRequest, \
144 _RemoteAddress, \
145 _RemotePort, \
146 _Buffer, \
147 _BufferSize, \
148 _Complete, \
149 _Context, \
150 _Build, \
151 _Flags) { \
152 (_SendRequest)->RemoteAddress = (_RemoteAddress); \
153 (_SendRequest)->RemotePort = (_RemotePort); \
154 (_SendRequest)->Buffer = (_Buffer); \
155 (_SendRequest)->BufferSize = (_BufferSize); \
156 (_SendRequest)->Complete = (_Complete); \
157 (_SendRequest)->Context = (_Context); \
158 (_SendRequest)->Build = (_Build); \
159 (_SendRequest)->Flags = (_Flags); \
160 }
161 #endif /* These things bug me... They hide the member names. */
162
163 /* Transport address file context structure. The FileObject->FsContext2
164 field holds a pointer to this structure */
165 typedef struct _ADDRESS_FILE {
166 DEFINE_TAG
167 LIST_ENTRY ListEntry; /* Entry on list */
168 KSPIN_LOCK Lock; /* Spin lock to manipulate this structure */
169 ULONG RefCount; /* Number of references to this object */
170 OBJECT_FREE_ROUTINE Free; /* Routine to use to free resources for the object */
171 USHORT Flags; /* Flags for address file (see below) */
172 PADDRESS_ENTRY ADE; /* Associated address entry */
173 USHORT Protocol; /* Protocol number */
174 USHORT Port; /* Network port (network byte order) */
175 WORK_QUEUE_ITEM WorkItem; /* Work queue item handle */
176 DATAGRAM_COMPLETION_ROUTINE Complete; /* Completion routine for delete request */
177 PVOID Context; /* Delete request context */
178 DATAGRAM_SEND_ROUTINE Send; /* Routine to send a datagram */
179 LIST_ENTRY ReceiveQueue; /* List of outstanding receive requests */
180 LIST_ENTRY TransmitQueue; /* List of outstanding transmit requests */
181 struct _CONNECTION_ENDPOINT *Connection;
182 /* Associated connection or NULL if no
183 associated connection exist */
184 PIP_ADDRESS AddrCache; /* One entry address cache (destination
185 address of last packet transmitted) */
186
187 /* The following members are used to control event notification */
188
189 /* Connection indication handler */
190 PTDI_IND_CONNECT ConnectHandler;
191 PVOID ConnectHandlerContext;
192 BOOL RegisteredConnectHandler;
193 /* Disconnect indication handler */
194 PTDI_IND_DISCONNECT DisconnectHandler;
195 PVOID DisconnectHandlerContext;
196 BOOL RegisteredDisconnectHandler;
197 /* Error indication handler */
198 PTDI_IND_ERROR ErrorHandler;
199 PVOID ErrorHandlerContext;
200 PVOID ErrorHandlerOwner;
201 BOOL RegisteredErrorHandler;
202 /* Receive indication handler */
203 PTDI_IND_RECEIVE ReceiveHandler;
204 PVOID ReceiveHandlerContext;
205 BOOL RegisteredReceiveHandler;
206 /* Receive datagram indication handler */
207 PTDI_IND_RECEIVE_DATAGRAM ReceiveDatagramHandler;
208 PVOID ReceiveDatagramHandlerContext;
209 BOOL RegisteredReceiveDatagramHandler;
210 /* Expedited receive indication handler */
211 PTDI_IND_RECEIVE_EXPEDITED ExpeditedReceiveHandler;
212 PVOID ExpeditedReceiveHandlerContext;
213 BOOL RegisteredExpeditedReceiveHandler;
214 /* Chained receive indication handler */
215 PTDI_IND_CHAINED_RECEIVE ChainedReceiveHandler;
216 PVOID ChainedReceiveHandlerContext;
217 BOOL RegisteredChainedReceiveHandler;
218 /* Chained receive datagram indication handler */
219 PTDI_IND_CHAINED_RECEIVE_DATAGRAM ChainedReceiveDatagramHandler;
220 PVOID ChainedReceiveDatagramHandlerContext;
221 BOOL RegisteredChainedReceiveDatagramHandler;
222 /* Chained expedited receive indication handler */
223 PTDI_IND_CHAINED_RECEIVE_EXPEDITED ChainedReceiveExpeditedHandler;
224 PVOID ChainedReceiveExpeditedHandlerContext;
225 BOOL RegisteredChainedReceiveExpeditedHandler;
226 } ADDRESS_FILE, *PADDRESS_FILE;
227
228 /* Address File Flag constants */
229 #define AFF_VALID 0x0001 /* Address file object is valid for use */
230 #define AFF_BUSY 0x0002 /* Address file object is exclusive to someone */
231 #define AFF_DELETE 0x0004 /* Address file object is sheduled to be deleted */
232 #define AFF_SEND 0x0008 /* A send request is pending */
233 #define AFF_RECEIVE 0x0010 /* A receive request is pending */
234 #define AFF_PENDING 0x001C /* A request is pending */
235
236 /* Macros for manipulating address file object flags */
237
238 #define AF_IS_VALID(ADF) ((ADF)->Flags & AFF_VALID)
239 #define AF_SET_VALID(ADF) ((ADF)->Flags |= AFF_VALID)
240 #define AF_CLR_VALID(ADF) ((ADF)->Flags &= ~AFF_VALID)
241
242 #define AF_IS_BUSY(ADF) ((ADF)->Flags & AFF_BUSY)
243 #define AF_SET_BUSY(ADF) ((ADF)->Flags |= AFF_BUSY)
244 #define AF_CLR_BUSY(ADF) ((ADF)->Flags &= ~AFF_BUSY)
245
246 #define AF_IS_PENDING(ADF, X) (ADF->Flags & X)
247 #define AF_SET_PENDING(ADF, X) (ADF->Flags |= X)
248 #define AF_CLR_PENDING(ADF, X) (ADF->Flags &= ~X)
249
250
251 /* Structure used to search through Address Files */
252 typedef struct _AF_SEARCH {
253 PLIST_ENTRY Next; /* Next address file to check */
254 PIP_ADDRESS Address; /* Pointer to address to be found */
255 USHORT Port; /* Network port */
256 USHORT Protocol; /* Protocol number */
257 } AF_SEARCH, *PAF_SEARCH;
258
259 /*******************************************************
260 * Connection-oriented communication support structures *
261 *******************************************************/
262
263 typedef struct _TCP_RECEIVE_REQUEST {
264 LIST_ENTRY ListEntry; /* Entry on list */
265 PNDIS_BUFFER Buffer; /* Pointer to receive buffer */
266 ULONG BufferSize; /* Size of Buffer */
267 DATAGRAM_COMPLETION_ROUTINE Complete; /* Completion routine */
268 PVOID Context; /* Pointer to context information */
269 } TCP_RECEIVE_REQUEST, *PTCP_RECEIVE_REQUEST;
270
271 /* Connection states */
272 typedef enum {
273 ctListen = 0, /* Waiting for incoming connection requests */
274 ctSynSent, /* Waiting for matching connection request */
275 ctSynReceived, /* Waiting for connection request acknowledgment */
276 ctEstablished, /* Connection is open for data transfer */
277 ctFinWait1, /* Waiting for termination request or ack. for same */
278 ctFinWait2, /* Waiting for termination request from remote TCP */
279 ctCloseWait, /* Waiting for termination request from local user */
280 ctClosing, /* Waiting for termination ack. from remote TCP */
281 ctLastAck, /* Waiting for termination request ack. from remote TCP */
282 ctTimeWait, /* Waiting for enough time to pass to be sure the remote TCP
283 received the ack. of its connection termination request */
284 ctClosed /* Represents a closed connection */
285 } CONNECTION_STATE, *PCONNECTION_STATE;
286
287
288 /* Structure for an TCP segment */
289 typedef struct _TCP_SEGMENT {
290 LIST_ENTRY ListEntry;
291 PIP_PACKET IPPacket; /* Pointer to IP packet */
292 PVOID SegmentData; /* Pointer to segment data */
293 ULONG SequenceNumber; /* Sequence number of first byte in segment */
294 ULONG Length; /* Number of bytes in segment */
295 ULONG BytesDelivered; /* Number of bytes already delivered to the client */
296 } TCP_SEGMENT, *PTCP_SEGMENT;
297
298
299 /* Transport connection context structure A.K.A. Transmission Control Block
300 (TCB) in TCP terminology. The FileObject->FsContext2 field holds a pointer
301 to this structure */
302 typedef struct _CONNECTION_ENDPOINT {
303 LIST_ENTRY ListEntry; /* Entry on list */
304 KSPIN_LOCK Lock; /* Spin lock to protect this structure */
305 ULONG RefCount; /* Number of references to this object */
306 PVOID ClientContext; /* Pointer to client context information */
307 PADDRESS_FILE AddressFile; /* Associated address file object (NULL if none) */
308 PVOID SocketContext; /* Context for lower layer */
309
310 #if 0
311 PIP_ADDRESS LocalAddress; /* Pointer to local IP address */
312 USHORT LocalPort; /* Local port number (network byte order) */
313
314 PIP_ADDRESS RemoteAddress; /* Pointer to remote IP address */
315 USHORT RemotePort; /* Remote port number (network byte order) */
316
317 CONNECTION_STATE State; /* Connection state */
318 /* Send sequence variables */
319 ULONG SendUnacknowledged; /* Highest sequence number that is acknowledged */
320 ULONG SendNext; /* Sequence number of last data block sent */
321 ULONG SendWindow; /* Maximum allowed number of octets in a segment */
322 ULONG SendUrgentPointer; /* Sequence number of start of urgent data */
323 ULONG SendWL1; /* Sequence number used for last window update */
324 ULONG SendWL2; /* Acknowledgment number used for last window update */
325 ULONG SendISS; /* Initial send sequence number */
326
327 /* Receive sequence variables */
328 ULONG ReceiveNext; /* Next sequence number expected and start of receive window */
329 ULONG ReceiveWindow; /* Maximum allowed number of octets in a segment */
330 ULONG ReceiveUrgentPointer; /* Sequence number of start of urgent data */
331 ULONG ReceiveIRS; /* Initial receive sequence number */
332 ULONG ReceiveDelivered; /* Next sequence number to be delivered to the client */
333
334 /* Statistics for computing the retransmission timeout */
335 ULONG TimestampSend; /* Timestamp when sending a segment */
336 ULONG TimestampAck; /* Timestamp when receiving acknowledgment */
337 #endif
338
339 /* Requests */
340 PTDI_REQUEST ListenRequest; /* Queued listen request */
341 LIST_ENTRY ReceiveRequests; /* Queued receive requests */
342
343 /* Queues */
344 LIST_ENTRY ReceivedSegments;/* Segments that are received */
345
346 } CONNECTION_ENDPOINT, *PCONNECTION_ENDPOINT;
347
348
349
350 /*************************
351 * TDI support structures *
352 *************************/
353
354 /* Transport control channel context structure. The FileObject->FsContext2
355 field holds a pointer to this structure */
356 typedef struct _CONTROL_CHANNEL {
357 LIST_ENTRY ListEntry; /* Entry on list */
358 KSPIN_LOCK Lock; /* Spin lock to protect this structure */
359 ULONG RefCount; /* Number of references to this object */
360 } CONTROL_CHANNEL, *PCONTROL_CHANNEL;
361
362 /* Transport (TCP/UDP) endpoint context structure. The FileObject->FsContext
363 field holds a pointer to this structure */
364 typedef struct _TRANSPORT_CONTEXT {
365 union {
366 HANDLE AddressHandle;
367 CONNECTION_CONTEXT ConnectionContext;
368 HANDLE ControlChannel;
369 } Handle;
370 ULONG RefCount;
371 BOOL CancelIrps;
372 KEVENT CleanupEvent;
373 } TRANSPORT_CONTEXT, *PTRANSPORT_CONTEXT;
374
375 typedef struct _TI_QUERY_CONTEXT {
376 PIRP Irp;
377 PMDL InputMdl;
378 PMDL OutputMdl;
379 TCP_REQUEST_QUERY_INFORMATION_EX QueryInfo;
380 } TI_QUERY_CONTEXT, *PTI_QUERY_CONTEXT;
381
382 #endif /* __TITYPES_H */
383
384 /* EOF */