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