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