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