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
13 #define DEFINE_TAG ULONG Tag;
14 #define INIT_TAG(_Object, _Tag) \
15 ((_Object)->Tag = (_Tag))
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)); \
25 * VOID ReferenceObject(
28 #define ReferenceObject(Object) \
30 CHAR c1, c2, c3, c4; \
32 c1 = ((Object)->Tag >> 24) & 0xFF; \
33 c2 = ((Object)->Tag >> 16) & 0xFF; \
34 c3 = ((Object)->Tag >> 8) & 0xFF; \
35 c4 = ((Object)->Tag & 0xFF); \
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)); \
41 InterlockedIncrement(&((Object)->RefCount)); \
45 * VOID DereferenceObject(
48 #define DereferenceObject(Object) \
50 CHAR c1, c2, c3, c4; \
52 c1 = ((Object)->Tag >> 24) & 0xFF; \
53 c2 = ((Object)->Tag >> 16) & 0xFF; \
54 c3 = ((Object)->Tag >> 8) & 0xFF; \
55 c4 = ((Object)->Tag & 0xFF); \
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)); \
61 if (InterlockedDecrement(&((Object)->RefCount)) == 0) \
62 (((Object)->Free)(Object)); \
68 #define INIT_TAG(Object, Tag)
71 * VOID ReferenceObject(
74 #define ReferenceObject(Object) \
76 InterlockedIncrement(&((Object)->RefCount)); \
80 * VOID DereferenceObject(
83 #define DereferenceObject(Object) \
85 if (InterlockedDecrement(&((Object)->RefCount)) == 0) \
86 (((Object)->Free)(Object)); \
96 /***************************************************
97 * Connection-less communication support structures *
98 ***************************************************/
100 typedef NTSTATUS (*DATAGRAM_SEND_ROUTINE
)(
101 struct _ADDRESS_FILE
*AddrFile
,
102 PTDI_CONNECTION_INFORMATION ConnInfo
,
107 /* Datagram completion handler prototype */
108 typedef VOID (*DATAGRAM_COMPLETION_ROUTINE
)(
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
;
124 /* Datagram build routine prototype */
125 typedef NTSTATUS (*DATAGRAM_BUILD_ROUTINE
)(
127 PIP_ADDRESS LocalAddress
,
129 PIP_PACKET
*IPPacket
);
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 */
138 IP_ADDRESS RemoteAddress
;
140 ULONG Flags
; /* Protocol specific flags */
141 } DATAGRAM_SEND_REQUEST
, *PDATAGRAM_SEND_REQUEST
;
144 #define InitializeDatagramSendRequest( \
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); \
163 #endif /* These things bug me... They hide the member names. */
165 /* Transport address file context structure. The FileObject->FsContext2
166 field holds a pointer to this structure */
167 typedef struct _ADDRESS_FILE
{
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) */
189 /* The following members are used to control event notification */
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
;
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 */
238 /* Macros for manipulating address file object flags */
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)
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)
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)
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
;
261 /*******************************************************
262 * Connection-oriented communication support structures *
263 *******************************************************/
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
;
273 /* Connection states */
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
;
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
;
300 typedef struct _TDI_BUCKET
{
303 } TDI_BUCKET
, *PTDI_BUCKET
;
305 /* Transport connection context structure A.K.A. Transmission Control Block
306 (TCB) in TCP terminology. The FileObject->FsContext2 field holds a pointer
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 */
316 UINT State
; /* Socket state W.R.T. oskit */
319 LIST_ENTRY ConnectRequest
; /* Queued connect rqueusts */
320 LIST_ENTRY ListenRequest
; /* Queued listen requests */
321 LIST_ENTRY ReceiveRequest
; /* Queued receive requests */
324 LIST_ENTRY ReceivedSegments
;/* Segments that are received */
325 } CONNECTION_ENDPOINT
, *PCONNECTION_ENDPOINT
;
329 /*************************
330 * TDI support structures *
331 *************************/
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
;
341 /* Transport (TCP/UDP) endpoint context structure. The FileObject->FsContext
342 field holds a pointer to this structure */
343 typedef struct _TRANSPORT_CONTEXT
{
345 HANDLE AddressHandle
;
346 CONNECTION_CONTEXT ConnectionContext
;
347 HANDLE ControlChannel
;
352 } TRANSPORT_CONTEXT
, *PTRANSPORT_CONTEXT
;
354 typedef struct _TI_QUERY_CONTEXT
{
358 TCP_REQUEST_QUERY_INFORMATION_EX QueryInfo
;
359 } TI_QUERY_CONTEXT
, *PTI_QUERY_CONTEXT
;
361 #endif /* __TITYPES_H */