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 8 #pragma once 9 10 /* 11 * VOID ReferenceObject( 12 * PVOID Object) 13 */ 14 #define ReferenceObject(Object) \ 15 { \ 16 ASSERT((Object)->RefCount); \ 17 InterlockedIncrement(&((Object)->RefCount)); \ 18 } 19 20 /* 21 * VOID DereferenceObject( 22 * PVOID Object) 23 */ 24 #define DereferenceObject(Object) \ 25 { \ 26 ASSERT((Object)->RefCount); \ 27 if (InterlockedDecrement(&((Object)->RefCount)) == 0) \ 28 (((Object)->Free)(Object)); \ 29 } 30 31 /* 32 * VOID LockObject(PVOID Object) 33 */ 34 #define LockObject(Object) do \ 35 { \ 36 ReferenceObject(Object); \ 37 KeEnterCriticalRegion(); \ 38 ExAcquireResourceExclusiveLite(&(Object)->Resource, TRUE); \ 39 } while(0) 40 41 /* 42 * VOID UnlockObject(PVOID Object) 43 */ 44 #define UnlockObject(Object) do \ 45 { \ 46 ExReleaseResourceLite(&(Object)->Resource); \ 47 KeLeaveCriticalRegion(); \ 48 DereferenceObject(Object); \ 49 } while(0) 50 51 #define ASSERT_TCPIP_OBJECT_LOCKED(Object) ASSERT(ExIsResourceAcquiredExclusiveLite(&(Object)->Resource)) 52 53 #include <ip.h> 54 55 struct _ADDRESS_FILE; 56 57 /*************************************************** 58 * Connection-less communication support structures * 59 ***************************************************/ 60 61 typedef NTSTATUS (*DATAGRAM_SEND_ROUTINE)( 62 struct _ADDRESS_FILE *AddrFile, 63 PTDI_CONNECTION_INFORMATION ConnInfo, 64 PCHAR Buffer, 65 ULONG DataSize, 66 PULONG DataUsed); 67 68 /* Datagram completion handler prototype */ 69 typedef VOID (*DATAGRAM_COMPLETION_ROUTINE)( 70 PVOID Context, 71 NDIS_STATUS Status, 72 ULONG Count); 73 74 typedef DATAGRAM_COMPLETION_ROUTINE PDATAGRAM_COMPLETION_ROUTINE; 75 76 typedef struct _DATAGRAM_RECEIVE_REQUEST { 77 struct _ADDRESS_FILE *AddressFile; /* AddressFile on behalf of */ 78 LIST_ENTRY ListEntry; /* Entry on list */ 79 IP_ADDRESS RemoteAddress; /* Remote address we receive from (NULL means any) */ 80 USHORT RemotePort; /* Remote port we receive from (0 means any) */ 81 PTDI_CONNECTION_INFORMATION ReturnInfo;/* Return information */ 82 PCHAR Buffer; /* Pointer to receive buffer */ 83 ULONG BufferSize; /* Size of Buffer */ 84 DATAGRAM_COMPLETION_ROUTINE Complete; /* Completion routine */ 85 PVOID Context; /* Pointer to context information */ 86 DATAGRAM_COMPLETION_ROUTINE UserComplete; /* Completion routine */ 87 PVOID UserContext; /* Pointer to context information */ 88 PIRP Irp; /* IRP on behalf of */ 89 } DATAGRAM_RECEIVE_REQUEST, *PDATAGRAM_RECEIVE_REQUEST; 90 91 /* Datagram build routine prototype */ 92 typedef NTSTATUS (*DATAGRAM_BUILD_ROUTINE)( 93 PVOID Context, 94 PIP_ADDRESS LocalAddress, 95 USHORT LocalPort, 96 PIP_PACKET *IPPacket); 97 98 typedef struct _DATAGRAM_SEND_REQUEST { 99 LIST_ENTRY ListEntry; 100 PNDIS_PACKET PacketToSend; 101 DATAGRAM_COMPLETION_ROUTINE Complete; /* Completion routine */ 102 PVOID Context; /* Pointer to context information */ 103 IP_PACKET Packet; 104 UINT BufferSize; 105 IP_ADDRESS RemoteAddress; 106 USHORT RemotePort; 107 ULONG Flags; /* Protocol specific flags */ 108 } DATAGRAM_SEND_REQUEST, *PDATAGRAM_SEND_REQUEST; 109 110 /* Transport address file context structure. The FileObject->FsContext2 111 field holds a pointer to this structure */ 112 typedef struct _ADDRESS_FILE { 113 LIST_ENTRY ListEntry; /* Entry on list */ 114 LONG RefCount; /* Reference count */ 115 OBJECT_FREE_ROUTINE Free; /* Routine to use to free resources for the object */ 116 ERESOURCE Resource; /* Resource to manipulate this structure */ 117 IP_ADDRESS Address; /* Address of this address file */ 118 USHORT Family; /* Address family */ 119 USHORT Protocol; /* Protocol number */ 120 USHORT Port; /* Network port (network byte order) */ 121 LONG Sharers; /* Number of file objects with this addr file */ 122 UCHAR TTL; /* Time to live stored in packets sent from this address file */ 123 UINT DF; /* Don't fragment */ 124 UINT BCast; /* Receive broadcast packets */ 125 UINT HeaderIncl; /* Include header in RawIP packets */ 126 DATAGRAM_COMPLETION_ROUTINE Complete; /* Completion routine for delete request */ 127 PVOID Context; /* Delete request context */ 128 DATAGRAM_SEND_ROUTINE Send; /* Routine to send a datagram */ 129 LIST_ENTRY ReceiveQueue; /* List of outstanding receive requests */ 130 LIST_ENTRY TransmitQueue; /* List of outstanding transmit requests */ 131 struct _CONNECTION_ENDPOINT *Connection; 132 /* Associated connection or NULL if no associated connection exist */ 133 struct _CONNECTION_ENDPOINT *Listener; 134 /* Associated listener (see transport/tcp/accept.c) */ 135 IP_ADDRESS AddrCache; /* One entry address cache (destination 136 address of last packet transmitted) */ 137 HANDLE ProcessId; /* Creator process ID */ 138 PVOID SubProcessTag; /* Creator process tag */ 139 LARGE_INTEGER CreationTime; /* Time of creation */ 140 141 /* The following members are used to control event notification */ 142 143 /* Connection indication handler */ 144 PTDI_IND_CONNECT ConnectHandler; 145 PVOID ConnectHandlerContext; 146 BOOLEAN RegisteredConnectHandler; 147 /* Disconnect indication handler */ 148 PTDI_IND_DISCONNECT DisconnectHandler; 149 PVOID DisconnectHandlerContext; 150 BOOLEAN RegisteredDisconnectHandler; 151 /* Error indication handler */ 152 PTDI_IND_ERROR ErrorHandler; 153 PVOID ErrorHandlerContext; 154 PVOID ErrorHandlerOwner; 155 BOOLEAN RegisteredErrorHandler; 156 /* Receive indication handler */ 157 PTDI_IND_RECEIVE ReceiveHandler; 158 PVOID ReceiveHandlerContext; 159 BOOLEAN RegisteredReceiveHandler; 160 /* Receive datagram indication handler */ 161 PTDI_IND_RECEIVE_DATAGRAM ReceiveDatagramHandler; 162 PVOID ReceiveDatagramHandlerContext; 163 BOOLEAN RegisteredReceiveDatagramHandler; 164 /* Expedited receive indication handler */ 165 PTDI_IND_RECEIVE_EXPEDITED ExpeditedReceiveHandler; 166 PVOID ExpeditedReceiveHandlerContext; 167 BOOLEAN RegisteredExpeditedReceiveHandler; 168 /* Chained receive indication handler */ 169 PTDI_IND_CHAINED_RECEIVE ChainedReceiveHandler; 170 PVOID ChainedReceiveHandlerContext; 171 BOOLEAN RegisteredChainedReceiveHandler; 172 /* Chained receive datagram indication handler */ 173 PTDI_IND_CHAINED_RECEIVE_DATAGRAM ChainedReceiveDatagramHandler; 174 PVOID ChainedReceiveDatagramHandlerContext; 175 BOOLEAN RegisteredChainedReceiveDatagramHandler; 176 /* Chained expedited receive indication handler */ 177 PTDI_IND_CHAINED_RECEIVE_EXPEDITED ChainedReceiveExpeditedHandler; 178 PVOID ChainedReceiveExpeditedHandlerContext; 179 BOOLEAN RegisteredChainedReceiveExpeditedHandler; 180 } ADDRESS_FILE, *PADDRESS_FILE; 181 182 /* Structure used to search through Address Files */ 183 typedef struct _AF_SEARCH { 184 PLIST_ENTRY Next; /* Next address file to check */ 185 PIP_ADDRESS Address; /* Pointer to address to be found */ 186 USHORT Port; /* Network port */ 187 USHORT Protocol; /* Protocol number */ 188 } AF_SEARCH, *PAF_SEARCH; 189 190 /******************************************************* 191 * Connection-oriented communication support structures * 192 *******************************************************/ 193 194 typedef struct _TCP_RECEIVE_REQUEST { 195 LIST_ENTRY ListEntry; /* Entry on list */ 196 PNDIS_BUFFER Buffer; /* Pointer to receive buffer */ 197 ULONG BufferSize; /* Size of Buffer */ 198 DATAGRAM_COMPLETION_ROUTINE Complete; /* Completion routine */ 199 PVOID Context; /* Pointer to context information */ 200 } TCP_RECEIVE_REQUEST, *PTCP_RECEIVE_REQUEST; 201 202 /* Connection states */ 203 typedef enum { 204 ctListen = 0, /* Waiting for incoming connection requests */ 205 ctSynSent, /* Waiting for matching connection request */ 206 ctSynReceived, /* Waiting for connection request acknowledgment */ 207 ctEstablished, /* Connection is open for data transfer */ 208 ctFinWait1, /* Waiting for termination request or ack. for same */ 209 ctFinWait2, /* Waiting for termination request from remote TCP */ 210 ctCloseWait, /* Waiting for termination request from local user */ 211 ctClosing, /* Waiting for termination ack. from remote TCP */ 212 ctLastAck, /* Waiting for termination request ack. from remote TCP */ 213 ctTimeWait, /* Waiting for enough time to pass to be sure the remote TCP 214 received the ack. of its connection termination request */ 215 ctClosed /* Represents a closed connection */ 216 } CONNECTION_STATE, *PCONNECTION_STATE; 217 218 219 /* Structure for an TCP segment */ 220 typedef struct _TCP_SEGMENT { 221 LIST_ENTRY ListEntry; 222 PIP_PACKET IPPacket; /* Pointer to IP packet */ 223 PVOID SegmentData; /* Pointer to segment data */ 224 ULONG SequenceNumber; /* Sequence number of first byte in segment */ 225 ULONG Length; /* Number of bytes in segment */ 226 ULONG BytesDelivered; /* Number of bytes already delivered to the client */ 227 } TCP_SEGMENT, *PTCP_SEGMENT; 228 229 typedef struct _TDI_BUCKET { 230 LIST_ENTRY Entry; 231 struct _CONNECTION_ENDPOINT *AssociatedEndpoint; 232 TDI_REQUEST Request; 233 NTSTATUS Status; 234 ULONG Information; 235 } TDI_BUCKET, *PTDI_BUCKET; 236 237 /* Transport connection context structure A.K.A. Transmission Control Block 238 (TCB) in TCP terminology. The FileObject->FsContext2 field holds a pointer 239 to this structure */ 240 typedef struct _CONNECTION_ENDPOINT { 241 PVOID SocketContext; /* Context for lower layer (MUST be first member in struct) */ 242 LIST_ENTRY ListEntry; /* Entry on list */ 243 LONG RefCount; /* Reference count */ 244 OBJECT_FREE_ROUTINE Free; /* Routine to use to free resources for the object */ 245 ERESOURCE Resource; /* The lock protecting this structure */ 246 PVOID ClientContext; /* Pointer to client context information */ 247 PADDRESS_FILE AddressFile; /* Associated address file object (NULL if none) */ 248 249 /* Requests */ 250 LIST_ENTRY ConnectRequest; /* Queued connect requests */ 251 LIST_ENTRY ListenRequest; /* Queued listen requests */ 252 LIST_ENTRY ReceiveRequest; /* Queued receive requests */ 253 LIST_ENTRY SendRequest; /* Queued send requests */ 254 LIST_ENTRY ShutdownRequest;/* Queued shutdown requests */ 255 256 LIST_ENTRY PacketQueue; /* Queued received packets waiting to be processed */ 257 258 /* Disconnect Timer */ 259 KTIMER DisconnectTimer; 260 KDPC DisconnectDpc; 261 PIO_WORKITEM DisconnectWorkItem; 262 263 /* Socket state */ 264 BOOLEAN SendShutdown; 265 BOOLEAN ReceiveShutdown; 266 NTSTATUS ReceiveShutdownStatus; 267 BOOLEAN Closing; 268 269 struct _CONNECTION_ENDPOINT *Next; /* Next connection in address file list */ 270 } CONNECTION_ENDPOINT, *PCONNECTION_ENDPOINT; 271 272 273 274 /************************* 275 * TDI support structures * 276 *************************/ 277 278 /* Transport control channel context structure. The FileObject->FsContext2 279 field holds a pointer to this structure */ 280 typedef struct _CONTROL_CHANNEL { 281 LIST_ENTRY ListEntry; /* Entry on list */ 282 LONG RefCount; /* Reference count */ 283 OBJECT_FREE_ROUTINE Free; /* Routine to use to free resources for the object */ 284 KSPIN_LOCK Lock; /* Spin lock to protect this structure */ 285 } CONTROL_CHANNEL, *PCONTROL_CHANNEL; 286 287 /* Transport (TCP/UDP) endpoint context structure. The FileObject->FsContext 288 field holds a pointer to this structure */ 289 typedef struct _TRANSPORT_CONTEXT { 290 union { 291 HANDLE AddressHandle; 292 CONNECTION_CONTEXT ConnectionContext; 293 HANDLE ControlChannel; 294 } Handle; 295 BOOLEAN CancelIrps; 296 KEVENT CleanupEvent; 297 } TRANSPORT_CONTEXT, *PTRANSPORT_CONTEXT; 298 299 typedef struct _TI_QUERY_CONTEXT { 300 PIRP Irp; 301 PMDL InputMdl; 302 PMDL OutputMdl; 303 TCP_REQUEST_QUERY_INFORMATION_EX QueryInfo; 304 } TI_QUERY_CONTEXT, *PTI_QUERY_CONTEXT; 305 306 /* EOF */ 307