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