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 DEBUG_REFCHECK(Object) { \
14 if ((Object)->RefCount <= 0) { \
15 TI_DbgPrint(MIN_TRACE, ("Object at (0x%X) has invalid reference count (%d).\n", \
16 (Object), (Object)->RefCount)); \
21 * VOID ReferenceObject(
24 #define ReferenceObject(Object) \
26 CHAR c1, c2, c3, c4; \
28 c1 = ((Object)->Tag >> 24) & 0xFF; \
29 c2 = ((Object)->Tag >> 16) & 0xFF; \
30 c3 = ((Object)->Tag >> 8) & 0xFF; \
31 c4 = ((Object)->Tag & 0xFF); \
33 DEBUG_REFCHECK(Object); \
34 TI_DbgPrint(DEBUG_REFCOUNT, ("Referencing object of type (%c%c%c%c) at (0x%X). RefCount (%d).\n", \
35 c4, c3, c2, c1, (Object), (Object)->RefCount)); \
37 InterlockedIncrement(&((Object)->RefCount)); \
41 * VOID DereferenceObject(
44 #define DereferenceObject(Object) \
46 CHAR c1, c2, c3, c4; \
48 c1 = ((Object)->Tag >> 24) & 0xFF; \
49 c2 = ((Object)->Tag >> 16) & 0xFF; \
50 c3 = ((Object)->Tag >> 8) & 0xFF; \
51 c4 = ((Object)->Tag & 0xFF); \
53 DEBUG_REFCHECK(Object); \
54 TI_DbgPrint(DEBUG_REFCOUNT, ("Dereferencing object of type (%c%c%c%c) at (0x%X). RefCount (%d).\n", \
55 c4, c3, c2, c1, (Object), (Object)->RefCount)); \
57 if (InterlockedDecrement(&((Object)->RefCount)) == 0) \
58 (((Object)->Free)(Object)); \
64 * VOID ReferenceObject(
67 #define ReferenceObject(Object) \
69 InterlockedIncrement(&((Object)->RefCount)); \
73 * VOID DereferenceObject(
76 #define DereferenceObject(Object) \
78 if (InterlockedDecrement(&((Object)->RefCount)) == 0) \
79 (((Object)->Free)(Object)); \
89 /***************************************************
90 * Connection-less communication support structures *
91 ***************************************************/
93 typedef NTSTATUS (*DATAGRAM_SEND_ROUTINE
)(
94 struct _ADDRESS_FILE
*AddrFile
,
95 PTDI_CONNECTION_INFORMATION ConnInfo
,
100 /* Datagram completion handler prototype */
101 typedef VOID (*DATAGRAM_COMPLETION_ROUTINE
)(
106 typedef DATAGRAM_COMPLETION_ROUTINE PDATAGRAM_COMPLETION_ROUTINE
;
108 typedef struct _DATAGRAM_RECEIVE_REQUEST
{
109 struct _ADDRESS_FILE
*AddressFile
; /* AddressFile on behalf of */
110 LIST_ENTRY ListEntry
; /* Entry on list */
111 IP_ADDRESS RemoteAddress
; /* Remote address we receive from (NULL means any) */
112 USHORT RemotePort
; /* Remote port we receive from (0 means any) */
113 PTDI_CONNECTION_INFORMATION ReturnInfo
;/* Return information */
114 PCHAR Buffer
; /* Pointer to receive buffer */
115 ULONG BufferSize
; /* Size of Buffer */
116 DATAGRAM_COMPLETION_ROUTINE Complete
; /* Completion routine */
117 PVOID Context
; /* Pointer to context information */
118 DATAGRAM_COMPLETION_ROUTINE UserComplete
; /* Completion routine */
119 PVOID UserContext
; /* Pointer to context information */
120 PIRP Irp
; /* IRP on behalf of */
121 } DATAGRAM_RECEIVE_REQUEST
, *PDATAGRAM_RECEIVE_REQUEST
;
123 /* Datagram build routine prototype */
124 typedef NTSTATUS (*DATAGRAM_BUILD_ROUTINE
)(
126 PIP_ADDRESS LocalAddress
,
128 PIP_PACKET
*IPPacket
);
130 typedef struct _DATAGRAM_SEND_REQUEST
{
131 LIST_ENTRY ListEntry
;
132 PNDIS_PACKET PacketToSend
;
133 DATAGRAM_COMPLETION_ROUTINE Complete
; /* Completion routine */
134 PVOID Context
; /* Pointer to context information */
137 IP_ADDRESS RemoteAddress
;
139 ULONG Flags
; /* Protocol specific flags */
140 } DATAGRAM_SEND_REQUEST
, *PDATAGRAM_SEND_REQUEST
;
142 /* Transport address file context structure. The FileObject->FsContext2
143 field holds a pointer to this structure */
144 typedef struct _ADDRESS_FILE
{
145 LIST_ENTRY ListEntry
; /* Entry on list */
146 KSPIN_LOCK Lock
; /* Spin lock to manipulate this structure */
147 OBJECT_FREE_ROUTINE Free
; /* Routine to use to free resources for the object */
148 IP_ADDRESS Address
; /* Address of this address file */
149 USHORT Family
; /* Address family */
150 USHORT Protocol
; /* Protocol number */
151 USHORT Port
; /* Network port (network byte order) */
152 UCHAR TTL
; /* Time to live stored in packets sent from this address file */
153 WORK_QUEUE_ITEM WorkItem
; /* Work queue item handle */
154 DATAGRAM_COMPLETION_ROUTINE Complete
; /* Completion routine for delete request */
155 PVOID Context
; /* Delete request context */
156 DATAGRAM_SEND_ROUTINE Send
; /* Routine to send a datagram */
157 LIST_ENTRY ReceiveQueue
; /* List of outstanding receive requests */
158 LIST_ENTRY TransmitQueue
; /* List of outstanding transmit requests */
159 struct _CONNECTION_ENDPOINT
*Connection
;
160 /* Associated connection or NULL if no associated connection exist */
161 struct _CONNECTION_ENDPOINT
*Listener
;
162 /* Associated listener (see transport/tcp/accept.c) */
163 IP_ADDRESS AddrCache
; /* One entry address cache (destination
164 address of last packet transmitted) */
166 /* The following members are used to control event notification */
168 /* Connection indication handler */
169 PTDI_IND_CONNECT ConnectHandler
;
170 PVOID ConnectHandlerContext
;
171 BOOLEAN RegisteredConnectHandler
;
172 /* Disconnect indication handler */
173 PTDI_IND_DISCONNECT DisconnectHandler
;
174 PVOID DisconnectHandlerContext
;
175 BOOLEAN RegisteredDisconnectHandler
;
176 /* Error indication handler */
177 PTDI_IND_ERROR ErrorHandler
;
178 PVOID ErrorHandlerContext
;
179 PVOID ErrorHandlerOwner
;
180 BOOLEAN RegisteredErrorHandler
;
181 /* Receive indication handler */
182 PTDI_IND_RECEIVE ReceiveHandler
;
183 PVOID ReceiveHandlerContext
;
184 BOOLEAN RegisteredReceiveHandler
;
185 /* Receive datagram indication handler */
186 PTDI_IND_RECEIVE_DATAGRAM ReceiveDatagramHandler
;
187 PVOID ReceiveDatagramHandlerContext
;
188 BOOLEAN RegisteredReceiveDatagramHandler
;
189 /* Expedited receive indication handler */
190 PTDI_IND_RECEIVE_EXPEDITED ExpeditedReceiveHandler
;
191 PVOID ExpeditedReceiveHandlerContext
;
192 BOOLEAN RegisteredExpeditedReceiveHandler
;
193 /* Chained receive indication handler */
194 PTDI_IND_CHAINED_RECEIVE ChainedReceiveHandler
;
195 PVOID ChainedReceiveHandlerContext
;
196 BOOLEAN RegisteredChainedReceiveHandler
;
197 /* Chained receive datagram indication handler */
198 PTDI_IND_CHAINED_RECEIVE_DATAGRAM ChainedReceiveDatagramHandler
;
199 PVOID ChainedReceiveDatagramHandlerContext
;
200 BOOLEAN RegisteredChainedReceiveDatagramHandler
;
201 /* Chained expedited receive indication handler */
202 PTDI_IND_CHAINED_RECEIVE_EXPEDITED ChainedReceiveExpeditedHandler
;
203 PVOID ChainedReceiveExpeditedHandlerContext
;
204 BOOLEAN RegisteredChainedReceiveExpeditedHandler
;
205 } ADDRESS_FILE
, *PADDRESS_FILE
;
207 /* Structure used to search through Address Files */
208 typedef struct _AF_SEARCH
{
209 PLIST_ENTRY Next
; /* Next address file to check */
210 PIP_ADDRESS Address
; /* Pointer to address to be found */
211 USHORT Port
; /* Network port */
212 USHORT Protocol
; /* Protocol number */
213 } AF_SEARCH
, *PAF_SEARCH
;
215 /*******************************************************
216 * Connection-oriented communication support structures *
217 *******************************************************/
219 typedef struct _TCP_RECEIVE_REQUEST
{
220 LIST_ENTRY ListEntry
; /* Entry on list */
221 PNDIS_BUFFER Buffer
; /* Pointer to receive buffer */
222 ULONG BufferSize
; /* Size of Buffer */
223 DATAGRAM_COMPLETION_ROUTINE Complete
; /* Completion routine */
224 PVOID Context
; /* Pointer to context information */
225 } TCP_RECEIVE_REQUEST
, *PTCP_RECEIVE_REQUEST
;
227 /* Connection states */
229 ctListen
= 0, /* Waiting for incoming connection requests */
230 ctSynSent
, /* Waiting for matching connection request */
231 ctSynReceived
, /* Waiting for connection request acknowledgment */
232 ctEstablished
, /* Connection is open for data transfer */
233 ctFinWait1
, /* Waiting for termination request or ack. for same */
234 ctFinWait2
, /* Waiting for termination request from remote TCP */
235 ctCloseWait
, /* Waiting for termination request from local user */
236 ctClosing
, /* Waiting for termination ack. from remote TCP */
237 ctLastAck
, /* Waiting for termination request ack. from remote TCP */
238 ctTimeWait
, /* Waiting for enough time to pass to be sure the remote TCP
239 received the ack. of its connection termination request */
240 ctClosed
/* Represents a closed connection */
241 } CONNECTION_STATE
, *PCONNECTION_STATE
;
244 /* Structure for an TCP segment */
245 typedef struct _TCP_SEGMENT
{
246 LIST_ENTRY ListEntry
;
247 PIP_PACKET IPPacket
; /* Pointer to IP packet */
248 PVOID SegmentData
; /* Pointer to segment data */
249 ULONG SequenceNumber
; /* Sequence number of first byte in segment */
250 ULONG Length
; /* Number of bytes in segment */
251 ULONG BytesDelivered
; /* Number of bytes already delivered to the client */
252 } TCP_SEGMENT
, *PTCP_SEGMENT
;
254 typedef struct _TDI_BUCKET
{
256 struct _CONNECTION_ENDPOINT
*AssociatedEndpoint
;
260 } TDI_BUCKET
, *PTDI_BUCKET
;
262 /* Transport connection context structure A.K.A. Transmission Control Block
263 (TCB) in TCP terminology. The FileObject->FsContext2 field holds a pointer
265 typedef struct _CONNECTION_ENDPOINT
{
266 LIST_ENTRY ListEntry
; /* Entry on list */
267 KSPIN_LOCK Lock
; /* Spin lock to protect this structure */
268 PVOID ClientContext
; /* Pointer to client context information */
269 PADDRESS_FILE AddressFile
; /* Associated address file object (NULL if none) */
270 PVOID SocketContext
; /* Context for lower layer */
273 LIST_ENTRY ConnectRequest
; /* Queued connect rqueusts */
274 LIST_ENTRY ListenRequest
; /* Queued listen requests */
275 LIST_ENTRY ReceiveRequest
; /* Queued receive requests */
276 LIST_ENTRY SendRequest
; /* Queued send requests */
277 LIST_ENTRY CompletionQueue
;/* Completed requests to finish */
280 UINT SignalState
; /* Active signals from oskit */
281 } CONNECTION_ENDPOINT
, *PCONNECTION_ENDPOINT
;
285 /*************************
286 * TDI support structures *
287 *************************/
289 /* Transport control channel context structure. The FileObject->FsContext2
290 field holds a pointer to this structure */
291 typedef struct _CONTROL_CHANNEL
{
292 LIST_ENTRY ListEntry
; /* Entry on list */
293 KSPIN_LOCK Lock
; /* Spin lock to protect this structure */
294 } CONTROL_CHANNEL
, *PCONTROL_CHANNEL
;
296 /* Transport (TCP/UDP) endpoint context structure. The FileObject->FsContext
297 field holds a pointer to this structure */
298 typedef struct _TRANSPORT_CONTEXT
{
300 HANDLE AddressHandle
;
301 CONNECTION_CONTEXT ConnectionContext
;
302 HANDLE ControlChannel
;
306 } TRANSPORT_CONTEXT
, *PTRANSPORT_CONTEXT
;
308 typedef struct _TI_QUERY_CONTEXT
{
312 TCP_REQUEST_QUERY_INFORMATION_EX QueryInfo
;
313 } TI_QUERY_CONTEXT
, *PTI_QUERY_CONTEXT
;
315 #endif /* __TITYPES_H */