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