[AFD] Introduce and use pool tags. Thanks go to Arty for assisting me with this....
[reactos.git] / drivers / network / afd / include / afd.h
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: drivers/net/afd/include/afd.h
5 * PURPOSE: Ancillary functions driver -- constants and structures
6 * PROGRAMMER: Art Yerkes (ayerkes@speakeasy.net)
7 * UPDATE HISTORY:
8 * 20040630 Created
9 */
10
11 #ifndef _AFD_H
12 #define _AFD_H
13
14 #include <ntifs.h>
15 #include <ndk/obtypes.h>
16 #include <tdi.h>
17 #include <tcpioctl.h>
18 #define _WINBASE_
19 #define _WINDOWS_H
20 #define _INC_WINDOWS
21 #include <windef.h>
22 #include <winsock2.h>
23 #include <afd/shared.h>
24 #include <pseh/pseh2.h>
25
26 #include "tdi_proto.h"
27 #include "tdiconn.h"
28 #include "debug.h"
29
30 #ifndef MIN
31 #define MIN(x,y) (((x)<(y))?(x):(y))
32 #endif
33
34 #define TL_INSTANCE 0
35 #define IP_MIB_STATS_ID 1
36 #define IP_MIB_ADDRTABLE_ENTRY_ID 0x102
37
38 #define TAG_AFD_DATA_BUFFER 'BdfA'
39 #define TAG_AFD_TRANSPORT_ADDRESS 'tdfA'
40 #define TAG_AFD_SOCKET_CONTEXT 'XdfA'
41 #define TAG_AFD_CONNECT_DATA 'cdfA'
42 #define TAG_AFD_DISCONNECT_DATA 'ddfA'
43
44 #define TAG_AFD_CONNECT_OPTIONS 'ocfA'
45 #define TAG_AFD_DISCONNECT_OPTIONS 'odfA'
46 #define TAG_AFD_ACCEPT_QUEUE 'qafA'
47 #define TAG_AFD_POLL_HANDLE 'hpfA'
48 #define TAG_AFD_FCB 'cffA'
49 #define TAG_AFD_ACTIVE_POLL 'pafA'
50 #define TAG_AFD_EA_INFO 'aefA'
51 #define TAG_AFD_STORED_DATAGRAM 'gsfA'
52 #define TAG_AFD_SNMP_ADDRESS_INFO 'asfA'
53 #define TAG_AFD_TDI_CONNECTION_INFORMATION 'cTfA'
54 #define TAG_AFD_WSA_BUFFER 'bWfA'
55
56 typedef struct IPADDR_ENTRY {
57 ULONG Addr;
58 ULONG Index;
59 ULONG Mask;
60 ULONG BcastAddr;
61 ULONG ReasmSize;
62 USHORT Context;
63 USHORT Pad;
64 } IPADDR_ENTRY, *PIPADDR_ENTRY;
65
66 #define DN2H(dw) \
67 ((((dw) & 0xFF000000L) >> 24) | \
68 (((dw) & 0x00FF0000L) >> 8) | \
69 (((dw) & 0x0000FF00L) << 8) | \
70 (((dw) & 0x000000FFL) << 24))
71
72 #define SOCKET_STATE_INVALID_TRANSITION ((DWORD)-1)
73 #define SOCKET_STATE_CREATED 0
74 #define SOCKET_STATE_BOUND 1
75 #define SOCKET_STATE_CONNECTING 2
76 #define SOCKET_STATE_CONNECTED 3
77 #define SOCKET_STATE_LISTENING 4
78 #define SOCKET_STATE_MASK 0x0000ffff
79 #define SOCKET_STATE_EOF_READ 0x20000000
80 #define SOCKET_STATE_LOCKED 0x40000000
81 #define SOCKET_STATE_NEW 0x80000000
82 #define SOCKET_STATE_CLOSED 0x00000100
83
84 #define FUNCTION_CONNECT 0
85 #define FUNCTION_RECV 1
86 #define FUNCTION_SEND 2
87 #define FUNCTION_PREACCEPT 3
88 #define FUNCTION_ACCEPT 4
89 #define FUNCTION_DISCONNECT 5
90 #define FUNCTION_CLOSE 6
91 #define MAX_FUNCTIONS 7
92
93 #define IN_FLIGHT_REQUESTS 5
94
95 #define EXTRA_LOCK_BUFFERS 2 /* Number of extra buffers needed
96 * for ancillary data on packet
97 * requests. */
98
99 /* XXX This is a hack we should clean up later
100 * We do this in order to get some storage for the locked handle table
101 * Maybe I'll use some tail item in the irp instead */
102 #define AFD_HANDLES(x) ((PAFD_HANDLE)(x)->Exclusive)
103 #define SET_AFD_HANDLES(x,y) (((x)->Exclusive) = (ULONG_PTR)(y))
104
105 typedef struct _AFD_MAPBUF {
106 PVOID BufferAddress;
107 PMDL Mdl;
108 } AFD_MAPBUF, *PAFD_MAPBUF;
109
110 typedef struct _AFD_DEVICE_EXTENSION {
111 PDEVICE_OBJECT DeviceObject;
112 LIST_ENTRY Polls;
113 KSPIN_LOCK Lock;
114 } AFD_DEVICE_EXTENSION, *PAFD_DEVICE_EXTENSION;
115
116 typedef struct _AFD_ACTIVE_POLL {
117 LIST_ENTRY ListEntry;
118 PIRP Irp;
119 PAFD_DEVICE_EXTENSION DeviceExt;
120 KDPC TimeoutDpc;
121 KTIMER Timer;
122 PKEVENT EventObject;
123 BOOLEAN Exclusive;
124 } AFD_ACTIVE_POLL, *PAFD_ACTIVE_POLL;
125
126 typedef struct _IRP_LIST {
127 LIST_ENTRY ListEntry;
128 PIRP Irp;
129 } IRP_LIST, *PIRP_LIST;
130
131 typedef struct _AFD_TDI_OBJECT {
132 PFILE_OBJECT Object;
133 HANDLE Handle;
134 } AFD_TDI_OBJECT, *PAFD_TDI_OBJECT;
135
136 typedef struct _AFD_TDI_OBJECT_QELT {
137 LIST_ENTRY ListEntry;
138 UINT Seq;
139 PTDI_CONNECTION_INFORMATION ConnInfo;
140 AFD_TDI_OBJECT Object;
141 } AFD_TDI_OBJECT_QELT, *PAFD_TDI_OBJECT_QELT;
142
143 typedef struct _AFD_IN_FLIGHT_REQUEST {
144 PIRP InFlightRequest;
145 PTDI_CONNECTION_INFORMATION ConnectionCallInfo;
146 PTDI_CONNECTION_INFORMATION ConnectionReturnInfo;
147 } AFD_IN_FLIGHT_REQUEST, *PAFD_IN_FLIGHT_REQUEST;
148
149 typedef struct _AFD_DATA_WINDOW {
150 PCHAR Window;
151 UINT BytesUsed, Size, Content;
152 } AFD_DATA_WINDOW, *PAFD_DATA_WINDOW;
153
154 typedef struct _AFD_STORED_DATAGRAM {
155 LIST_ENTRY ListEntry;
156 UINT Len;
157 PTRANSPORT_ADDRESS Address;
158 CHAR Buffer[1];
159 } AFD_STORED_DATAGRAM, *PAFD_STORED_DATAGRAM;
160
161 typedef struct _AFD_FCB {
162 BOOLEAN Locked, Critical, Overread, NonBlocking, OobInline, TdiReceiveClosed, SendClosed;
163 UINT State, Flags, GroupID, GroupType;
164 KIRQL OldIrql;
165 UINT LockCount;
166 PVOID CurrentThread;
167 PFILE_OBJECT FileObject;
168 PAFD_DEVICE_EXTENSION DeviceExt;
169 BOOLEAN DelayedAccept;
170 UINT ConnSeq;
171 USHORT DisconnectFlags;
172 BOOLEAN DisconnectPending;
173 LARGE_INTEGER DisconnectTimeout;
174 PTRANSPORT_ADDRESS LocalAddress, RemoteAddress;
175 PTDI_CONNECTION_INFORMATION AddressFrom, ConnectCallInfo, ConnectReturnInfo;
176 AFD_TDI_OBJECT AddressFile, Connection;
177 AFD_IN_FLIGHT_REQUEST ConnectIrp, ListenIrp, ReceiveIrp, SendIrp, DisconnectIrp;
178 AFD_DATA_WINDOW Send, Recv;
179 KMUTEX Mutex;
180 PKEVENT EventSelect;
181 DWORD EventSelectTriggers;
182 DWORD EventSelectDisabled;
183 UNICODE_STRING TdiDeviceName;
184 PVOID Context;
185 DWORD PollState;
186 NTSTATUS PollStatus[FD_MAX_EVENTS];
187 NTSTATUS LastReceiveStatus;
188 UINT ContextSize;
189 PVOID ConnectData;
190 UINT FilledConnectData;
191 UINT ConnectDataSize;
192 PVOID DisconnectData;
193 UINT FilledDisconnectData;
194 UINT DisconnectDataSize;
195 PVOID ConnectOptions;
196 UINT FilledConnectOptions;
197 UINT ConnectOptionsSize;
198 PVOID DisconnectOptions;
199 UINT FilledDisconnectOptions;
200 UINT DisconnectOptionsSize;
201 LIST_ENTRY PendingIrpList[MAX_FUNCTIONS];
202 LIST_ENTRY DatagramList;
203 LIST_ENTRY PendingConnections;
204 } AFD_FCB, *PAFD_FCB;
205
206 /* bind.c */
207
208 NTSTATUS WarmSocketForBind( PAFD_FCB FCB, ULONG ShareType );
209 NTSTATUS NTAPI
210 AfdBindSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp,
211 PIO_STACK_LOCATION IrpSp);
212
213 /* connect.c */
214
215 NTSTATUS MakeSocketIntoConnection( PAFD_FCB FCB );
216 NTSTATUS WarmSocketForConnection( PAFD_FCB FCB );
217 NTSTATUS NTAPI
218 AfdStreamSocketConnect(PDEVICE_OBJECT DeviceObject, PIRP Irp,
219 PIO_STACK_LOCATION IrpSp);
220 NTSTATUS NTAPI
221 AfdGetConnectData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
222 PIO_STACK_LOCATION IrpSp);
223 NTSTATUS NTAPI
224 AfdSetConnectData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
225 PIO_STACK_LOCATION IrpSp);
226 NTSTATUS NTAPI
227 AfdSetConnectDataSize(PDEVICE_OBJECT DeviceObject, PIRP Irp,
228 PIO_STACK_LOCATION IrpSp);
229 NTSTATUS NTAPI
230 AfdGetConnectOptions(PDEVICE_OBJECT DeviceObject, PIRP Irp,
231 PIO_STACK_LOCATION IrpSp);
232 NTSTATUS NTAPI
233 AfdSetConnectOptions(PDEVICE_OBJECT DeviceObject, PIRP Irp,
234 PIO_STACK_LOCATION IrpSp);
235 NTSTATUS NTAPI
236 AfdSetConnectOptionsSize(PDEVICE_OBJECT DeviceObject, PIRP Irp,
237 PIO_STACK_LOCATION IrpSp);
238
239 /* context.c */
240
241 NTSTATUS NTAPI
242 AfdGetContext( PDEVICE_OBJECT DeviceObject, PIRP Irp,
243 PIO_STACK_LOCATION IrpSp );
244 NTSTATUS NTAPI
245 AfdGetContextSize( PDEVICE_OBJECT DeviceObject, PIRP Irp,
246 PIO_STACK_LOCATION IrpSp );
247 NTSTATUS NTAPI
248 AfdSetContext( PDEVICE_OBJECT DeviceObject, PIRP Irp,
249 PIO_STACK_LOCATION IrpSp );
250
251 /* info.c */
252
253 NTSTATUS NTAPI
254 AfdGetInfo( PDEVICE_OBJECT DeviceObject, PIRP Irp,
255 PIO_STACK_LOCATION IrpSp );
256
257 NTSTATUS NTAPI
258 AfdSetInfo( PDEVICE_OBJECT DeviceObject, PIRP Irp,
259 PIO_STACK_LOCATION IrpSp );
260
261 NTSTATUS NTAPI
262 AfdGetSockName( PDEVICE_OBJECT DeviceObject, PIRP Irp,
263 PIO_STACK_LOCATION IrpSp );
264
265 NTSTATUS NTAPI
266 AfdGetPeerName( PDEVICE_OBJECT DeviceObject, PIRP Irp,
267 PIO_STACK_LOCATION IrpSp );
268
269 /* listen.c */
270 NTSTATUS AfdWaitForListen( PDEVICE_OBJECT DeviceObject, PIRP Irp,
271 PIO_STACK_LOCATION IrpSp );
272
273 NTSTATUS AfdListenSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp,
274 PIO_STACK_LOCATION IrpSp);
275
276 NTSTATUS AfdAccept( PDEVICE_OBJECT DeviceObject, PIRP Irp,
277 PIO_STACK_LOCATION IrpSp );
278
279 /* lock.c */
280
281 PAFD_WSABUF LockBuffers( PAFD_WSABUF Buf, UINT Count,
282 PVOID AddressBuf, PINT AddressLen,
283 BOOLEAN Write, BOOLEAN LockAddress,
284 KPROCESSOR_MODE LockMode );
285 VOID UnlockBuffers( PAFD_WSABUF Buf, UINT Count, BOOL Address );
286 BOOLEAN SocketAcquireStateLock( PAFD_FCB FCB );
287 NTSTATUS NTAPI UnlockAndMaybeComplete
288 ( PAFD_FCB FCB, NTSTATUS Status, PIRP Irp,
289 UINT Information );
290 VOID SocketStateUnlock( PAFD_FCB FCB );
291 NTSTATUS LostSocket( PIRP Irp );
292 PAFD_HANDLE LockHandles( PAFD_HANDLE HandleArray, UINT HandleCount );
293 VOID UnlockHandles( PAFD_HANDLE HandleArray, UINT HandleCount );
294 PVOID LockRequest( PIRP Irp, PIO_STACK_LOCATION IrpSp, BOOLEAN Output, KPROCESSOR_MODE *LockMode );
295 VOID UnlockRequest( PIRP Irp, PIO_STACK_LOCATION IrpSp );
296 PVOID GetLockedData( PIRP Irp, PIO_STACK_LOCATION IrpSp );
297 NTSTATUS LeaveIrpUntilLater( PAFD_FCB FCB, PIRP Irp, UINT Function );
298 NTSTATUS QueueUserModeIrp(PAFD_FCB FCB, PIRP Irp, UINT Function);
299
300 /* main.c */
301
302 VOID OskitDumpBuffer( PCHAR Buffer, UINT Len );
303 VOID DestroySocket( PAFD_FCB FCB );
304 DRIVER_CANCEL AfdCancelHandler;
305 VOID RetryDisconnectCompletion(PAFD_FCB FCB);
306 BOOLEAN CheckUnlockExtraBuffers(PAFD_FCB FCB, PIO_STACK_LOCATION IrpSp);
307
308 /* read.c */
309
310 IO_COMPLETION_ROUTINE ReceiveComplete;
311
312 IO_COMPLETION_ROUTINE PacketSocketRecvComplete;
313
314 NTSTATUS NTAPI
315 AfdConnectedSocketReadData(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp, BOOLEAN Short);
316 NTSTATUS NTAPI
317 AfdPacketSocketReadData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
318 PIO_STACK_LOCATION IrpSp );
319
320 /* select.c */
321
322 NTSTATUS NTAPI
323 AfdSelect( PDEVICE_OBJECT DeviceObject, PIRP Irp,
324 PIO_STACK_LOCATION IrpSp );
325 NTSTATUS NTAPI
326 AfdEventSelect( PDEVICE_OBJECT DeviceObject, PIRP Irp,
327 PIO_STACK_LOCATION IrpSp );
328 NTSTATUS NTAPI
329 AfdEnumEvents( PDEVICE_OBJECT DeviceObject, PIRP Irp,
330 PIO_STACK_LOCATION IrpSp );
331 VOID PollReeval( PAFD_DEVICE_EXTENSION DeviceObject, PFILE_OBJECT FileObject );
332 VOID KillSelectsForFCB( PAFD_DEVICE_EXTENSION DeviceExt,
333 PFILE_OBJECT FileObject, BOOLEAN ExclusiveOnly );
334 VOID ZeroEvents( PAFD_HANDLE HandleArray,
335 UINT HandleCount );
336 VOID SignalSocket(
337 PAFD_ACTIVE_POLL Poll OPTIONAL, PIRP _Irp OPTIONAL,
338 PAFD_POLL_INFO PollReq, NTSTATUS Status);
339
340 /* tdi.c */
341
342 NTSTATUS TdiOpenAddressFile(
343 PUNICODE_STRING DeviceName,
344 PTRANSPORT_ADDRESS Name,
345 ULONG ShareType,
346 PHANDLE AddressHandle,
347 PFILE_OBJECT *AddressObject);
348
349 NTSTATUS TdiAssociateAddressFile(
350 HANDLE AddressHandle,
351 PFILE_OBJECT ConnectionObject);
352
353 NTSTATUS TdiDisassociateAddressFile(
354 PFILE_OBJECT ConnectionObject);
355
356 NTSTATUS TdiListen
357 ( PIRP *Irp,
358 PFILE_OBJECT ConnectionObject,
359 PTDI_CONNECTION_INFORMATION *RequestConnectionInfo,
360 PTDI_CONNECTION_INFORMATION *ReturnConnectionInfo,
361 PIO_COMPLETION_ROUTINE CompletionRoutine,
362 PVOID CompletionContext);
363
364 NTSTATUS TdiReceive
365 ( PIRP *Irp,
366 PFILE_OBJECT ConnectionObject,
367 USHORT Flags,
368 PCHAR Buffer,
369 UINT BufferLength,
370 PIO_COMPLETION_ROUTINE CompletionRoutine,
371 PVOID CompletionContext);
372
373 NTSTATUS TdiSend
374 ( PIRP *Irp,
375 PFILE_OBJECT ConnectionObject,
376 USHORT Flags,
377 PCHAR Buffer,
378 UINT BufferLength,
379 PIO_COMPLETION_ROUTINE CompletionRoutine,
380 PVOID CompletionContext);
381
382 NTSTATUS TdiReceiveDatagram(
383 PIRP *Irp,
384 PFILE_OBJECT TransportObject,
385 USHORT Flags,
386 PCHAR Buffer,
387 UINT BufferLength,
388 PTDI_CONNECTION_INFORMATION From,
389 PIO_COMPLETION_ROUTINE CompletionRoutine,
390 PVOID CompletionContext);
391
392 NTSTATUS TdiSendDatagram(
393 PIRP *Irp,
394 PFILE_OBJECT TransportObject,
395 PCHAR Buffer,
396 UINT BufferLength,
397 PTDI_CONNECTION_INFORMATION To,
398 PIO_COMPLETION_ROUTINE CompletionRoutine,
399 PVOID CompletionContext);
400
401 NTSTATUS TdiQueryMaxDatagramLength(
402 PFILE_OBJECT FileObject,
403 PUINT MaxDatagramLength);
404
405 /* write.c */
406
407 NTSTATUS NTAPI
408 AfdConnectedSocketWriteData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
409 PIO_STACK_LOCATION IrpSp, BOOLEAN Short);
410 NTSTATUS NTAPI
411 AfdPacketSocketWriteData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
412 PIO_STACK_LOCATION IrpSp);
413
414 #endif /* _AFD_H */