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