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
11 * VOID ReferenceObject(
14 #define ReferenceObject(Object) \
16 InterlockedIncrement(&((Object)->RefCount)); \
20 * VOID DereferenceObject(
23 #define DereferenceObject(Object) \
25 if (InterlockedDecrement(&((Object)->RefCount)) == 0) \
26 (((Object)->Free)(Object)); \
30 * VOID LockObject(PVOID Object, PKIRQL OldIrql)
32 #define LockObject(Object, Irql) \
34 ReferenceObject(Object); \
35 KeAcquireSpinLock(&((Object)->Lock), Irql); \
36 memcpy(&(Object)->OldIrql, Irql, sizeof(KIRQL)); \
40 * VOID LockObjectAtDpcLevel(PVOID Object)
42 #define LockObjectAtDpcLevel(Object) \
44 ReferenceObject(Object); \
45 KeAcquireSpinLockAtDpcLevel(&((Object)->Lock)); \
46 (Object)->OldIrql = DISPATCH_LEVEL; \
50 * VOID UnlockObject(PVOID Object, KIRQL OldIrql)
52 #define UnlockObject(Object, OldIrql) \
54 KeReleaseSpinLock(&((Object)->Lock), OldIrql); \
55 DereferenceObject(Object); \
59 * VOID UnlockObjectFromDpcLevel(PVOID Object)
61 #define UnlockObjectFromDpcLevel(Object) \
63 KeReleaseSpinLockFromDpcLevel(&((Object)->Lock)); \
64 DereferenceObject(Object); \
73 /***************************************************
74 * Connection-less communication support structures *
75 ***************************************************/
77 typedef NTSTATUS (*DATAGRAM_SEND_ROUTINE
)(
78 struct _ADDRESS_FILE
*AddrFile
,
79 PTDI_CONNECTION_INFORMATION ConnInfo
,
84 /* Datagram completion handler prototype */
85 typedef VOID (*DATAGRAM_COMPLETION_ROUTINE
)(
90 typedef DATAGRAM_COMPLETION_ROUTINE PDATAGRAM_COMPLETION_ROUTINE
;
92 typedef struct _DATAGRAM_RECEIVE_REQUEST
{
93 struct _ADDRESS_FILE
*AddressFile
; /* AddressFile on behalf of */
94 LIST_ENTRY ListEntry
; /* Entry on list */
95 IP_ADDRESS RemoteAddress
; /* Remote address we receive from (NULL means any) */
96 USHORT RemotePort
; /* Remote port we receive from (0 means any) */
97 PTDI_CONNECTION_INFORMATION ReturnInfo
;/* Return information */
98 PCHAR Buffer
; /* Pointer to receive buffer */
99 ULONG BufferSize
; /* Size of Buffer */
100 DATAGRAM_COMPLETION_ROUTINE Complete
; /* Completion routine */
101 PVOID Context
; /* Pointer to context information */
102 DATAGRAM_COMPLETION_ROUTINE UserComplete
; /* Completion routine */
103 PVOID UserContext
; /* Pointer to context information */
104 PIRP Irp
; /* IRP on behalf of */
105 } DATAGRAM_RECEIVE_REQUEST
, *PDATAGRAM_RECEIVE_REQUEST
;
107 /* Datagram build routine prototype */
108 typedef NTSTATUS (*DATAGRAM_BUILD_ROUTINE
)(
110 PIP_ADDRESS LocalAddress
,
112 PIP_PACKET
*IPPacket
);
114 typedef struct _DATAGRAM_SEND_REQUEST
{
115 LIST_ENTRY ListEntry
;
116 PNDIS_PACKET PacketToSend
;
117 DATAGRAM_COMPLETION_ROUTINE Complete
; /* Completion routine */
118 PVOID Context
; /* Pointer to context information */
121 IP_ADDRESS RemoteAddress
;
123 ULONG Flags
; /* Protocol specific flags */
124 } DATAGRAM_SEND_REQUEST
, *PDATAGRAM_SEND_REQUEST
;
126 /* Transport address file context structure. The FileObject->FsContext2
127 field holds a pointer to this structure */
128 typedef struct _ADDRESS_FILE
{
129 LIST_ENTRY ListEntry
; /* Entry on list */
130 LONG RefCount
; /* Reference count */
131 OBJECT_FREE_ROUTINE Free
; /* Routine to use to free resources for the object */
132 KSPIN_LOCK Lock
; /* Spin lock to manipulate this structure */
133 KIRQL OldIrql
; /* Currently not used */
134 IP_ADDRESS Address
; /* Address of this address file */
135 USHORT Family
; /* Address family */
136 USHORT Protocol
; /* Protocol number */
137 USHORT Port
; /* Network port (network byte order) */
138 UCHAR TTL
; /* Time to live stored in packets sent from this address file */
139 UINT DF
; /* Don't fragment */
140 UINT BCast
; /* Receive broadcast packets */
141 UINT HeaderIncl
; /* Include header in RawIP packets */
142 WORK_QUEUE_ITEM WorkItem
; /* Work queue item handle */
143 DATAGRAM_COMPLETION_ROUTINE Complete
; /* Completion routine for delete request */
144 PVOID Context
; /* Delete request context */
145 DATAGRAM_SEND_ROUTINE Send
; /* Routine to send a datagram */
146 LIST_ENTRY ReceiveQueue
; /* List of outstanding receive requests */
147 LIST_ENTRY TransmitQueue
; /* List of outstanding transmit requests */
148 struct _CONNECTION_ENDPOINT
*Connection
;
149 /* Associated connection or NULL if no associated connection exist */
150 struct _CONNECTION_ENDPOINT
*Listener
;
151 /* Associated listener (see transport/tcp/accept.c) */
152 IP_ADDRESS AddrCache
; /* One entry address cache (destination
153 address of last packet transmitted) */
155 /* The following members are used to control event notification */
157 /* Connection indication handler */
158 PTDI_IND_CONNECT ConnectHandler
;
159 PVOID ConnectHandlerContext
;
160 BOOLEAN RegisteredConnectHandler
;
161 /* Disconnect indication handler */
162 PTDI_IND_DISCONNECT DisconnectHandler
;
163 PVOID DisconnectHandlerContext
;
164 BOOLEAN RegisteredDisconnectHandler
;
165 /* Error indication handler */
166 PTDI_IND_ERROR ErrorHandler
;
167 PVOID ErrorHandlerContext
;
168 PVOID ErrorHandlerOwner
;
169 BOOLEAN RegisteredErrorHandler
;
170 /* Receive indication handler */
171 PTDI_IND_RECEIVE ReceiveHandler
;
172 PVOID ReceiveHandlerContext
;
173 BOOLEAN RegisteredReceiveHandler
;
174 /* Receive datagram indication handler */
175 PTDI_IND_RECEIVE_DATAGRAM ReceiveDatagramHandler
;
176 PVOID ReceiveDatagramHandlerContext
;
177 BOOLEAN RegisteredReceiveDatagramHandler
;
178 /* Expedited receive indication handler */
179 PTDI_IND_RECEIVE_EXPEDITED ExpeditedReceiveHandler
;
180 PVOID ExpeditedReceiveHandlerContext
;
181 BOOLEAN RegisteredExpeditedReceiveHandler
;
182 /* Chained receive indication handler */
183 PTDI_IND_CHAINED_RECEIVE ChainedReceiveHandler
;
184 PVOID ChainedReceiveHandlerContext
;
185 BOOLEAN RegisteredChainedReceiveHandler
;
186 /* Chained receive datagram indication handler */
187 PTDI_IND_CHAINED_RECEIVE_DATAGRAM ChainedReceiveDatagramHandler
;
188 PVOID ChainedReceiveDatagramHandlerContext
;
189 BOOLEAN RegisteredChainedReceiveDatagramHandler
;
190 /* Chained expedited receive indication handler */
191 PTDI_IND_CHAINED_RECEIVE_EXPEDITED ChainedReceiveExpeditedHandler
;
192 PVOID ChainedReceiveExpeditedHandlerContext
;
193 BOOLEAN RegisteredChainedReceiveExpeditedHandler
;
194 } ADDRESS_FILE
, *PADDRESS_FILE
;
196 /* Structure used to search through Address Files */
197 typedef struct _AF_SEARCH
{
198 PLIST_ENTRY Next
; /* Next address file to check */
199 PIP_ADDRESS Address
; /* Pointer to address to be found */
200 USHORT Port
; /* Network port */
201 USHORT Protocol
; /* Protocol number */
202 } AF_SEARCH
, *PAF_SEARCH
;
204 /*******************************************************
205 * Connection-oriented communication support structures *
206 *******************************************************/
208 typedef struct _TCP_RECEIVE_REQUEST
{
209 LIST_ENTRY ListEntry
; /* Entry on list */
210 PNDIS_BUFFER Buffer
; /* Pointer to receive buffer */
211 ULONG BufferSize
; /* Size of Buffer */
212 DATAGRAM_COMPLETION_ROUTINE Complete
; /* Completion routine */
213 PVOID Context
; /* Pointer to context information */
214 } TCP_RECEIVE_REQUEST
, *PTCP_RECEIVE_REQUEST
;
216 /* Connection states */
218 ctListen
= 0, /* Waiting for incoming connection requests */
219 ctSynSent
, /* Waiting for matching connection request */
220 ctSynReceived
, /* Waiting for connection request acknowledgment */
221 ctEstablished
, /* Connection is open for data transfer */
222 ctFinWait1
, /* Waiting for termination request or ack. for same */
223 ctFinWait2
, /* Waiting for termination request from remote TCP */
224 ctCloseWait
, /* Waiting for termination request from local user */
225 ctClosing
, /* Waiting for termination ack. from remote TCP */
226 ctLastAck
, /* Waiting for termination request ack. from remote TCP */
227 ctTimeWait
, /* Waiting for enough time to pass to be sure the remote TCP
228 received the ack. of its connection termination request */
229 ctClosed
/* Represents a closed connection */
230 } CONNECTION_STATE
, *PCONNECTION_STATE
;
233 /* Structure for an TCP segment */
234 typedef struct _TCP_SEGMENT
{
235 LIST_ENTRY ListEntry
;
236 PIP_PACKET IPPacket
; /* Pointer to IP packet */
237 PVOID SegmentData
; /* Pointer to segment data */
238 ULONG SequenceNumber
; /* Sequence number of first byte in segment */
239 ULONG Length
; /* Number of bytes in segment */
240 ULONG BytesDelivered
; /* Number of bytes already delivered to the client */
241 } TCP_SEGMENT
, *PTCP_SEGMENT
;
243 typedef struct _TDI_BUCKET
{
245 struct _CONNECTION_ENDPOINT
*AssociatedEndpoint
;
249 } TDI_BUCKET
, *PTDI_BUCKET
;
251 /* Transport connection context structure A.K.A. Transmission Control Block
252 (TCB) in TCP terminology. The FileObject->FsContext2 field holds a pointer
254 typedef struct _CONNECTION_ENDPOINT
{
255 LIST_ENTRY ListEntry
; /* Entry on list */
256 LONG RefCount
; /* Reference count */
257 OBJECT_FREE_ROUTINE Free
; /* Routine to use to free resources for the object */
258 KSPIN_LOCK Lock
; /* Spin lock to protect this structure */
259 KIRQL OldIrql
; /* The old irql is stored here for use in HandleSignalledConnection */
260 PVOID ClientContext
; /* Pointer to client context information */
261 PADDRESS_FILE AddressFile
; /* Associated address file object (NULL if none) */
262 PVOID SocketContext
; /* Context for lower layer */
265 LIST_ENTRY ConnectRequest
; /* Queued connect rqueusts */
266 LIST_ENTRY ListenRequest
; /* Queued listen requests */
267 LIST_ENTRY ReceiveRequest
; /* Queued receive requests */
268 LIST_ENTRY SendRequest
; /* Queued send requests */
269 LIST_ENTRY CompletionQueue
;/* Completed requests to finish */
272 UINT SignalState
; /* Active signals from oskit */
273 } CONNECTION_ENDPOINT
, *PCONNECTION_ENDPOINT
;
277 /*************************
278 * TDI support structures *
279 *************************/
281 /* Transport control channel context structure. The FileObject->FsContext2
282 field holds a pointer to this structure */
283 typedef struct _CONTROL_CHANNEL
{
284 LIST_ENTRY ListEntry
; /* Entry on list */
285 LONG RefCount
; /* Reference count */
286 OBJECT_FREE_ROUTINE Free
; /* Routine to use to free resources for the object */
287 KSPIN_LOCK Lock
; /* Spin lock to protect this structure */
288 } CONTROL_CHANNEL
, *PCONTROL_CHANNEL
;
290 /* Transport (TCP/UDP) endpoint context structure. The FileObject->FsContext
291 field holds a pointer to this structure */
292 typedef struct _TRANSPORT_CONTEXT
{
294 HANDLE AddressHandle
;
295 CONNECTION_CONTEXT ConnectionContext
;
296 HANDLE ControlChannel
;
300 } TRANSPORT_CONTEXT
, *PTRANSPORT_CONTEXT
;
302 typedef struct _TI_QUERY_CONTEXT
{
306 TCP_REQUEST_QUERY_INFORMATION_EX QueryInfo
;
307 } TI_QUERY_CONTEXT
, *PTI_QUERY_CONTEXT
;