Revert my patch from yesterday. Need to take more time to work on it.
[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 struct _ADDRESS_FILE;
95
96 /***************************************************
97 * Connection-less communication support structures *
98 ***************************************************/
99
100 typedef NTSTATUS (*DATAGRAM_SEND_ROUTINE)(
101 struct _ADDRESS_FILE *AddrFile,
102 PTDI_CONNECTION_INFORMATION ConnInfo,
103 PCHAR Buffer,
104 ULONG DataSize,
105 PULONG DataUsed);
106
107 /* Datagram completion handler prototype */
108 typedef VOID (*DATAGRAM_COMPLETION_ROUTINE)(
109 PVOID Context,
110 NDIS_STATUS Status,
111 ULONG Count);
112
113 typedef DATAGRAM_COMPLETION_ROUTINE PDATAGRAM_COMPLETION_ROUTINE;
114
115 typedef struct _DATAGRAM_RECEIVE_REQUEST {
116 LIST_ENTRY ListEntry; /* Entry on list */
117 IP_ADDRESS RemoteAddress; /* Remote address we receive from (NULL means any) */
118 USHORT RemotePort; /* Remote port we receive from (0 means any) */
119 PTDI_CONNECTION_INFORMATION ReturnInfo;/* Return information */
120 PCHAR Buffer; /* Pointer to receive buffer */
121 ULONG BufferSize; /* Size of Buffer */
122 DATAGRAM_COMPLETION_ROUTINE Complete; /* Completion routine */
123 PVOID Context; /* Pointer to context information */
124 DATAGRAM_COMPLETION_ROUTINE UserComplete; /* Completion routine */
125 PVOID UserContext; /* Pointer to context information */
126 } DATAGRAM_RECEIVE_REQUEST, *PDATAGRAM_RECEIVE_REQUEST;
127
128 /* Datagram build routine prototype */
129 typedef NTSTATUS (*DATAGRAM_BUILD_ROUTINE)(
130 PVOID Context,
131 PIP_ADDRESS LocalAddress,
132 USHORT LocalPort,
133 PIP_PACKET *IPPacket);
134
135 typedef struct _DATAGRAM_SEND_REQUEST {
136 LIST_ENTRY ListEntry;
137 PNDIS_PACKET PacketToSend;
138 DATAGRAM_COMPLETION_ROUTINE Complete; /* Completion routine */
139 PVOID Context; /* Pointer to context information */
140 IP_PACKET Packet;
141 UINT BufferSize;
142 IP_ADDRESS RemoteAddress;
143 USHORT RemotePort;
144 ULONG Flags; /* Protocol specific flags */
145 } DATAGRAM_SEND_REQUEST, *PDATAGRAM_SEND_REQUEST;
146
147 /* Transport address file context structure. The FileObject->FsContext2
148 field holds a pointer to this structure */
149 typedef struct _ADDRESS_FILE {
150 DEFINE_TAG
151 LIST_ENTRY ListEntry; /* Entry on list */
152 KSPIN_LOCK Lock; /* Spin lock to manipulate this structure */
153 OBJECT_FREE_ROUTINE Free; /* Routine to use to free resources for the object */
154 USHORT Flags; /* Flags for address file (see below) */
155 IP_ADDRESS Address; /* Address of this address file */
156 USHORT Family; /* Address family */
157 USHORT Protocol; /* Protocol number */
158 USHORT Port; /* Network port (network byte order) */
159 WORK_QUEUE_ITEM WorkItem; /* Work queue item handle */
160 DATAGRAM_COMPLETION_ROUTINE Complete; /* Completion routine for delete request */
161 PVOID Context; /* Delete request context */
162 DATAGRAM_SEND_ROUTINE Send; /* Routine to send a datagram */
163 LIST_ENTRY ReceiveQueue; /* List of outstanding receive requests */
164 LIST_ENTRY TransmitQueue; /* List of outstanding transmit requests */
165 struct _CONNECTION_ENDPOINT *Connection;
166 /* Associated connection or NULL if no associated connection exist */
167 struct _CONNECTION_ENDPOINT *Listener;
168 /* Associated listener (see transport/tcp/accept.c) */
169 IP_ADDRESS AddrCache; /* One entry address cache (destination
170 address of last packet transmitted) */
171
172 /* The following members are used to control event notification */
173
174 /* Connection indication handler */
175 PTDI_IND_CONNECT ConnectHandler;
176 PVOID ConnectHandlerContext;
177 BOOL RegisteredConnectHandler;
178 /* Disconnect indication handler */
179 PTDI_IND_DISCONNECT DisconnectHandler;
180 PVOID DisconnectHandlerContext;
181 BOOL RegisteredDisconnectHandler;
182 /* Error indication handler */
183 PTDI_IND_ERROR ErrorHandler;
184 PVOID ErrorHandlerContext;
185 PVOID ErrorHandlerOwner;
186 BOOL RegisteredErrorHandler;
187 /* Receive indication handler */
188 PTDI_IND_RECEIVE ReceiveHandler;
189 PVOID ReceiveHandlerContext;
190 BOOL RegisteredReceiveHandler;
191 /* Receive datagram indication handler */
192 PTDI_IND_RECEIVE_DATAGRAM ReceiveDatagramHandler;
193 PVOID ReceiveDatagramHandlerContext;
194 BOOL RegisteredReceiveDatagramHandler;
195 /* Expedited receive indication handler */
196 PTDI_IND_RECEIVE_EXPEDITED ExpeditedReceiveHandler;
197 PVOID ExpeditedReceiveHandlerContext;
198 BOOL RegisteredExpeditedReceiveHandler;
199 /* Chained receive indication handler */
200 PTDI_IND_CHAINED_RECEIVE ChainedReceiveHandler;
201 PVOID ChainedReceiveHandlerContext;
202 BOOL RegisteredChainedReceiveHandler;
203 /* Chained receive datagram indication handler */
204 PTDI_IND_CHAINED_RECEIVE_DATAGRAM ChainedReceiveDatagramHandler;
205 PVOID ChainedReceiveDatagramHandlerContext;
206 BOOL RegisteredChainedReceiveDatagramHandler;
207 /* Chained expedited receive indication handler */
208 PTDI_IND_CHAINED_RECEIVE_EXPEDITED ChainedReceiveExpeditedHandler;
209 PVOID ChainedReceiveExpeditedHandlerContext;
210 BOOL RegisteredChainedReceiveExpeditedHandler;
211 } ADDRESS_FILE, *PADDRESS_FILE;
212
213 /* Address File Flag constants */
214 #define AFF_VALID 0x0001 /* Address file object is valid for use */
215 #define AFF_BUSY 0x0002 /* Address file object is exclusive to someone */
216 #define AFF_DELETE 0x0004 /* Address file object is sheduled to be deleted */
217 #define AFF_SEND 0x0008 /* A send request is pending */
218 #define AFF_RECEIVE 0x0010 /* A receive request is pending */
219 #define AFF_PENDING 0x001C /* A request is pending */
220
221 /* Macros for manipulating address file object flags */
222
223 #define AF_IS_VALID(ADF) ((ADF)->Flags & AFF_VALID)
224 #define AF_SET_VALID(ADF) ((ADF)->Flags |= AFF_VALID)
225 #define AF_CLR_VALID(ADF) ((ADF)->Flags &= ~AFF_VALID)
226
227 #define AF_IS_BUSY(ADF) ((ADF)->Flags & AFF_BUSY)
228 #define AF_SET_BUSY(ADF) ((ADF)->Flags |= AFF_BUSY)
229 #define AF_CLR_BUSY(ADF) ((ADF)->Flags &= ~AFF_BUSY)
230
231 #define AF_IS_PENDING(ADF, X) (ADF->Flags & X)
232 #define AF_SET_PENDING(ADF, X) (ADF->Flags |= X)
233 #define AF_CLR_PENDING(ADF, X) (ADF->Flags &= ~X)
234
235
236 /* Structure used to search through Address Files */
237 typedef struct _AF_SEARCH {
238 PLIST_ENTRY Next; /* Next address file to check */
239 PIP_ADDRESS Address; /* Pointer to address to be found */
240 USHORT Port; /* Network port */
241 USHORT Protocol; /* Protocol number */
242 } AF_SEARCH, *PAF_SEARCH;
243
244 /*******************************************************
245 * Connection-oriented communication support structures *
246 *******************************************************/
247
248 typedef struct _TCP_RECEIVE_REQUEST {
249 LIST_ENTRY ListEntry; /* Entry on list */
250 PNDIS_BUFFER Buffer; /* Pointer to receive buffer */
251 ULONG BufferSize; /* Size of Buffer */
252 DATAGRAM_COMPLETION_ROUTINE Complete; /* Completion routine */
253 PVOID Context; /* Pointer to context information */
254 } TCP_RECEIVE_REQUEST, *PTCP_RECEIVE_REQUEST;
255
256 /* Connection states */
257 typedef enum {
258 ctListen = 0, /* Waiting for incoming connection requests */
259 ctSynSent, /* Waiting for matching connection request */
260 ctSynReceived, /* Waiting for connection request acknowledgment */
261 ctEstablished, /* Connection is open for data transfer */
262 ctFinWait1, /* Waiting for termination request or ack. for same */
263 ctFinWait2, /* Waiting for termination request from remote TCP */
264 ctCloseWait, /* Waiting for termination request from local user */
265 ctClosing, /* Waiting for termination ack. from remote TCP */
266 ctLastAck, /* Waiting for termination request ack. from remote TCP */
267 ctTimeWait, /* Waiting for enough time to pass to be sure the remote TCP
268 received the ack. of its connection termination request */
269 ctClosed /* Represents a closed connection */
270 } CONNECTION_STATE, *PCONNECTION_STATE;
271
272
273 /* Structure for an TCP segment */
274 typedef struct _TCP_SEGMENT {
275 LIST_ENTRY ListEntry;
276 PIP_PACKET IPPacket; /* Pointer to IP packet */
277 PVOID SegmentData; /* Pointer to segment data */
278 ULONG SequenceNumber; /* Sequence number of first byte in segment */
279 ULONG Length; /* Number of bytes in segment */
280 ULONG BytesDelivered; /* Number of bytes already delivered to the client */
281 } TCP_SEGMENT, *PTCP_SEGMENT;
282
283 typedef struct _TDI_BUCKET {
284 LIST_ENTRY Entry;
285 struct _CONNECTION_ENDPOINT *AssociatedEndpoint;
286 TDI_REQUEST Request;
287 } TDI_BUCKET, *PTDI_BUCKET;
288
289 /* Transport connection context structure A.K.A. Transmission Control Block
290 (TCB) in TCP terminology. The FileObject->FsContext2 field holds a pointer
291 to this structure */
292 typedef struct _CONNECTION_ENDPOINT {
293 LIST_ENTRY ListEntry; /* Entry on list */
294 KSPIN_LOCK Lock; /* Spin lock to protect this structure */
295 PVOID ClientContext; /* Pointer to client context information */
296 PADDRESS_FILE AddressFile; /* Associated address file object (NULL if none) */
297 PVOID SocketContext; /* Context for lower layer */
298
299 UINT State; /* Socket state W.R.T. oskit */
300
301 /* Requests */
302 LIST_ENTRY ConnectRequest; /* Queued connect rqueusts */
303 LIST_ENTRY ListenRequest; /* Queued listen requests */
304 LIST_ENTRY ReceiveRequest; /* Queued receive requests */
305
306 /* Signals */
307 LIST_ENTRY SignalList; /* Entry in the list of sockets waiting for
308 * notification service to the client */
309 UINT SignalState; /* Active signals from oskit */
310 BOOLEAN Signalled; /* Are we a member of the signal list */
311 } CONNECTION_ENDPOINT, *PCONNECTION_ENDPOINT;
312
313
314
315 /*************************
316 * TDI support structures *
317 *************************/
318
319 /* Transport control channel context structure. The FileObject->FsContext2
320 field holds a pointer to this structure */
321 typedef struct _CONTROL_CHANNEL {
322 LIST_ENTRY ListEntry; /* Entry on list */
323 KSPIN_LOCK Lock; /* Spin lock to protect this structure */
324 } CONTROL_CHANNEL, *PCONTROL_CHANNEL;
325
326 /* Transport (TCP/UDP) endpoint context structure. The FileObject->FsContext
327 field holds a pointer to this structure */
328 typedef struct _TRANSPORT_CONTEXT {
329 union {
330 HANDLE AddressHandle;
331 CONNECTION_CONTEXT ConnectionContext;
332 HANDLE ControlChannel;
333 } Handle;
334 BOOL CancelIrps;
335 KEVENT CleanupEvent;
336 } TRANSPORT_CONTEXT, *PTRANSPORT_CONTEXT;
337
338 typedef struct _TI_QUERY_CONTEXT {
339 PIRP Irp;
340 PMDL InputMdl;
341 PMDL OutputMdl;
342 TCP_REQUEST_QUERY_INFORMATION_EX QueryInfo;
343 } TI_QUERY_CONTEXT, *PTI_QUERY_CONTEXT;
344
345 #endif /* __TITYPES_H */
346
347 /* EOF */