f5795152f12f2fb7a888737334d63be7d81a0959
[reactos.git] / reactos / dll / win32 / msafd / msafd.h
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Ancillary Function Driver DLL
4 * FILE: include/msafd.h
5 * PURPOSE: Ancillary Function Driver DLL header
6 */
7 #ifndef __MSAFD_H
8 #define __MSAFD_H
9
10 #include <stdio.h>
11 #include <stdlib.h>
12
13 #define WIN32_NO_STATUS
14 #include <winsock2.h>
15 #include <windows.h>
16 #include <ws2spi.h>
17 #define NTOS_MODE_USER
18 #include <ndk/ntndk.h>
19
20 /* This includes ntsecapi.h so it needs to come after the NDK */
21 #include <wsahelp.h>
22 #include <tdi.h>
23 #include <afd/shared.h>
24 #include <helpers.h>
25
26 extern HANDLE GlobalHeap;
27 extern WSPUPCALLTABLE Upcalls;
28 extern LPWPUCOMPLETEOVERLAPPEDREQUEST lpWPUCompleteOverlappedRequest;
29 extern LIST_ENTRY SockHelpersListHead;
30 extern HANDLE SockEvent;
31 extern HANDLE SockAsyncCompletionPort;
32 extern BOOLEAN SockAsyncSelectCalled;
33
34 typedef enum _SOCKET_STATE {
35 SocketOpen,
36 SocketBound,
37 SocketBoundUdp,
38 SocketConnected,
39 SocketClosed
40 } SOCKET_STATE, *PSOCKET_STATE;
41
42 typedef struct _SOCK_SHARED_INFO {
43 SOCKET_STATE State;
44 INT AddressFamily;
45 INT SocketType;
46 INT Protocol;
47 INT SizeOfLocalAddress;
48 INT SizeOfRemoteAddress;
49 struct linger LingerData;
50 ULONG SendTimeout;
51 ULONG RecvTimeout;
52 ULONG SizeOfRecvBuffer;
53 ULONG SizeOfSendBuffer;
54 struct {
55 BOOLEAN Listening:1;
56 BOOLEAN Broadcast:1;
57 BOOLEAN Debug:1;
58 BOOLEAN OobInline:1;
59 BOOLEAN ReuseAddresses:1;
60 BOOLEAN ExclusiveAddressUse:1;
61 BOOLEAN NonBlocking:1;
62 BOOLEAN DontUseWildcard:1;
63 BOOLEAN ReceiveShutdown:1;
64 BOOLEAN SendShutdown:1;
65 BOOLEAN UseDelayedAcceptance:1;
66 BOOLEAN UseSAN:1;
67 }; // Flags
68 DWORD CreateFlags;
69 DWORD CatalogEntryId;
70 DWORD ServiceFlags1;
71 DWORD ProviderFlags;
72 GROUP GroupID;
73 DWORD GroupType;
74 INT GroupPriority;
75 INT SocketLastError;
76 HWND hWnd;
77 LONG Unknown;
78 DWORD SequenceNumber;
79 UINT wMsg;
80 LONG AsyncEvents;
81 LONG AsyncDisabledEvents;
82 } SOCK_SHARED_INFO, *PSOCK_SHARED_INFO;
83
84 typedef struct _SOCKET_INFORMATION {
85 ULONG RefCount;
86 SOCKET Handle;
87 SOCK_SHARED_INFO SharedData;
88 DWORD HelperEvents;
89 PHELPER_DATA HelperData;
90 PVOID HelperContext;
91 PSOCKADDR LocalAddress;
92 PSOCKADDR RemoteAddress;
93 HANDLE TdiAddressHandle;
94 HANDLE TdiConnectionHandle;
95 PVOID AsyncData;
96 HANDLE EventObject;
97 LONG NetworkEvents;
98 CRITICAL_SECTION Lock;
99 PVOID SanData;
100 BOOL TrySAN;
101 SOCKADDR WSLocalAddress;
102 SOCKADDR WSRemoteAddress;
103 struct _SOCKET_INFORMATION *NextSocket;
104 } SOCKET_INFORMATION, *PSOCKET_INFORMATION;
105
106
107 typedef struct _SOCKET_CONTEXT {
108 SOCK_SHARED_INFO SharedData;
109 ULONG SizeOfHelperData;
110 ULONG Padding;
111 SOCKADDR LocalAddress;
112 SOCKADDR RemoteAddress;
113 /* Plus Helper Data */
114 } SOCKET_CONTEXT, *PSOCKET_CONTEXT;
115
116 typedef struct _ASYNC_DATA {
117 PSOCKET_INFORMATION ParentSocket;
118 DWORD SequenceNumber;
119 IO_STATUS_BLOCK IoStatusBlock;
120 AFD_POLL_INFO AsyncSelectInfo;
121 } ASYNC_DATA, *PASYNC_DATA;
122
123 SOCKET
124 WSPAPI
125 WSPAccept(
126 IN SOCKET s,
127 OUT LPSOCKADDR addr,
128 IN OUT LPINT addrlen,
129 IN LPCONDITIONPROC lpfnCondition,
130 IN DWORD dwCallbackData,
131 OUT LPINT lpErrno);
132
133 INT
134 WSPAPI
135 WSPAddressToString(
136 IN LPSOCKADDR lpsaAddress,
137 IN DWORD dwAddressLength,
138 IN LPWSAPROTOCOL_INFOW lpProtocolInfo,
139 OUT LPWSTR lpszAddressString,
140 IN OUT LPDWORD lpdwAddressStringLength,
141 OUT LPINT lpErrno);
142
143 INT
144 WSPAPI
145 WSPAsyncSelect(
146 IN SOCKET s,
147 IN HWND hWnd,
148 IN UINT wMsg,
149 IN LONG lEvent,
150 OUT LPINT lpErrno);
151
152 INT
153 WSPAPI WSPBind(
154 IN SOCKET s,
155 IN CONST SOCKADDR *name,
156 IN INT namelen,
157 OUT LPINT lpErrno);
158
159 INT
160 WSPAPI
161 WSPCancelBlockingCall(
162 OUT LPINT lpErrno);
163
164 INT
165 WSPAPI
166 WSPCleanup(
167 OUT LPINT lpErrno);
168
169 INT
170 WSPAPI
171 WSPCloseSocket(
172 IN SOCKET s,
173 OUT LPINT lpErrno);
174
175 INT
176 WSPAPI
177 WSPConnect(
178 IN SOCKET s,
179 IN CONST SOCKADDR *name,
180 IN INT namelen,
181 IN LPWSABUF lpCallerData,
182 OUT LPWSABUF lpCalleeData,
183 IN LPQOS lpSQOS,
184 IN LPQOS lpGQOS,
185 OUT LPINT lpErrno);
186
187 INT
188 WSPAPI
189 WSPDuplicateSocket(
190 IN SOCKET s,
191 IN DWORD dwProcessId,
192 OUT LPWSAPROTOCOL_INFOW lpProtocolInfo,
193 OUT LPINT lpErrno);
194
195 INT
196 WSPAPI
197 WSPEnumNetworkEvents(
198 IN SOCKET s,
199 IN WSAEVENT hEventObject,
200 OUT LPWSANETWORKEVENTS lpNetworkEvents,
201 OUT LPINT lpErrno);
202
203 INT
204 WSPAPI
205 WSPEventSelect(
206 IN SOCKET s,
207 IN WSAEVENT hEventObject,
208 IN LONG lNetworkEvents,
209 OUT LPINT lpErrno);
210
211 BOOL
212 WSPAPI
213 WSPGetOverlappedResult(
214 IN SOCKET s,
215 IN LPWSAOVERLAPPED lpOverlapped,
216 OUT LPDWORD lpcbTransfer,
217 IN BOOL fWait,
218 OUT LPDWORD lpdwFlags,
219 OUT LPINT lpErrno);
220
221 INT
222 WSPAPI
223 WSPGetPeerName(
224 IN SOCKET s,
225 OUT LPSOCKADDR name,
226 IN OUT LPINT namelen,
227 OUT LPINT lpErrno);
228
229 BOOL
230 WSPAPI
231 WSPGetQOSByName(
232 IN SOCKET s,
233 IN OUT LPWSABUF lpQOSName,
234 OUT LPQOS lpQOS,
235 OUT LPINT lpErrno);
236
237 INT
238 WSPAPI
239 WSPGetSockName(
240 IN SOCKET s,
241 OUT LPSOCKADDR name,
242 IN OUT LPINT namelen,
243 OUT LPINT lpErrno);
244
245 INT
246 WSPAPI
247 WSPGetSockOpt(
248 IN SOCKET s,
249 IN INT level,
250 IN INT optname,
251 OUT CHAR FAR* optval,
252 IN OUT LPINT optlen,
253 OUT LPINT lpErrno);
254
255 INT
256 WSPAPI
257 WSPIoctl(
258 IN SOCKET s,
259 IN DWORD dwIoControlCode,
260 IN LPVOID lpvInBuffer,
261 IN DWORD cbInBuffer,
262 OUT LPVOID lpvOutBuffer,
263 IN DWORD cbOutBuffer,
264 OUT LPDWORD lpcbBytesReturned,
265 IN LPWSAOVERLAPPED lpOverlapped,
266 IN LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine,
267 IN LPWSATHREADID lpThreadId,
268 OUT LPINT lpErrno);
269
270 SOCKET
271 WSPAPI
272 WSPJoinLeaf(
273 IN SOCKET s,
274 IN CONST SOCKADDR *name,
275 IN INT namelen,
276 IN LPWSABUF lpCallerData,
277 OUT LPWSABUF lpCalleeData,
278 IN LPQOS lpSQOS,
279 IN LPQOS lpGQOS,
280 IN DWORD dwFlags,
281 OUT LPINT lpErrno);
282
283 INT
284 WSPAPI
285 WSPListen(
286 IN SOCKET s,
287 IN INT backlog,
288 OUT LPINT lpErrno);
289
290 INT
291 WSPAPI
292 WSPRecv(
293 IN SOCKET s,
294 IN OUT LPWSABUF lpBuffers,
295 IN DWORD dwBufferCount,
296 OUT LPDWORD lpNumberOfBytesRecvd,
297 IN OUT LPDWORD lpFlags,
298 IN LPWSAOVERLAPPED lpOverlapped,
299 IN LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine,
300 IN LPWSATHREADID lpThreadId,
301 OUT LPINT lpErrno);
302
303 INT
304 WSPAPI
305 WSPRecvDisconnect(
306 IN SOCKET s,
307 OUT LPWSABUF lpInboundDisconnectData,
308 OUT LPINT lpErrno);
309
310 INT
311 WSPAPI
312 WSPRecvFrom(
313 IN SOCKET s,
314 IN OUT LPWSABUF lpBuffers,
315 IN DWORD dwBufferCount,
316 OUT LPDWORD lpNumberOfBytesRecvd,
317 IN OUT LPDWORD lpFlags,
318 OUT LPSOCKADDR lpFrom,
319 IN OUT LPINT lpFromlen,
320 IN LPWSAOVERLAPPED lpOverlapped,
321 IN LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine,
322 IN LPWSATHREADID lpThreadId,
323 OUT LPINT lpErrno);
324
325 INT
326 WSPAPI
327 WSPSelect(
328 IN INT nfds,
329 IN OUT fd_set *readfds,
330 IN OUT fd_set *writefds,
331 IN OUT fd_set *exceptfds,
332 IN CONST struct timeval *timeout,
333 OUT LPINT lpErrno);
334
335 INT
336 WSPAPI
337 WSPSend(
338 IN SOCKET s,
339 IN LPWSABUF lpBuffers,
340 IN DWORD dwBufferCount,
341 OUT LPDWORD lpNumberOfBytesSent,
342 IN DWORD dwFlags,
343 IN LPWSAOVERLAPPED lpOverlapped,
344 IN LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine,
345 IN LPWSATHREADID lpThreadId,
346 OUT LPINT lpErrno);
347
348 INT
349 WSPAPI
350 WSPSendDisconnect(
351 IN SOCKET s,
352 IN LPWSABUF lpOutboundDisconnectData,
353 OUT LPINT lpErrno);
354
355 INT
356 WSPAPI
357 WSPSendTo(
358 IN SOCKET s,
359 IN LPWSABUF lpBuffers,
360 IN DWORD dwBufferCount,
361 OUT LPDWORD lpNumberOfBytesSent,
362 IN DWORD dwFlags,
363 IN CONST SOCKADDR *lpTo,
364 IN INT iTolen,
365 IN LPWSAOVERLAPPED lpOverlapped,
366 IN LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine,
367 IN LPWSATHREADID lpThreadId,
368 OUT LPINT lpErrno);
369
370 INT
371 WSPAPI
372 WSPSetSockOpt(
373 IN SOCKET s,
374 IN INT level,
375 IN INT optname,
376 IN CONST CHAR FAR* optval,
377 IN INT optlen,
378 OUT LPINT lpErrno);
379
380 INT
381 WSPAPI
382 WSPShutdown(
383 IN SOCKET s,
384 IN INT how,
385 OUT LPINT lpErrno);
386
387 SOCKET
388 WSPAPI
389 WSPSocket(
390 IN INT af,
391 IN INT type,
392 IN INT protocol,
393 IN LPWSAPROTOCOL_INFOW lpProtocolInfo,
394 IN GROUP g,
395 IN DWORD dwFlags,
396 OUT LPINT lpErrno);
397
398 INT
399 WSPAPI
400 WSPStringToAddress(
401 IN LPWSTR AddressString,
402 IN INT AddressFamily,
403 IN LPWSAPROTOCOL_INFOW lpProtocolInfo,
404 OUT LPSOCKADDR lpAddress,
405 IN OUT LPINT lpAddressLength,
406 OUT LPINT lpErrno);
407
408
409 PSOCKET_INFORMATION GetSocketStructure(
410 SOCKET Handle
411 );
412
413 INT TranslateNtStatusError( NTSTATUS Status );
414
415 VOID DeleteSocketStructure( SOCKET Handle );
416
417 int GetSocketInformation(
418 PSOCKET_INFORMATION Socket,
419 ULONG AfdInformationClass,
420 PULONG Ulong OPTIONAL,
421 PLARGE_INTEGER LargeInteger OPTIONAL
422 );
423
424 int SetSocketInformation(
425 PSOCKET_INFORMATION Socket,
426 ULONG AfdInformationClass,
427 PULONG Ulong OPTIONAL,
428 PLARGE_INTEGER LargeInteger OPTIONAL
429 );
430
431 int CreateContext(
432 PSOCKET_INFORMATION Socket
433 );
434
435 int SockAsyncThread(
436 PVOID ThreadParam
437 );
438
439 VOID
440 SockProcessAsyncSelect(
441 PSOCKET_INFORMATION Socket,
442 PASYNC_DATA AsyncData
443 );
444
445 VOID
446 SockAsyncSelectCompletionRoutine(
447 PVOID Context,
448 PIO_STATUS_BLOCK IoStatusBlock
449 );
450
451 BOOLEAN
452 SockCreateOrReferenceAsyncThread(
453 VOID
454 );
455
456 BOOLEAN SockGetAsyncSelectHelperAfdHandle(
457 VOID
458 );
459
460 VOID SockProcessQueuedAsyncSelect(
461 PVOID Context,
462 PIO_STATUS_BLOCK IoStatusBlock
463 );
464
465 VOID
466 SockReenableAsyncSelectEvent (
467 IN PSOCKET_INFORMATION Socket,
468 IN ULONG Event
469 );
470
471 DWORD MsafdReturnWithErrno( NTSTATUS Status, LPINT Errno, DWORD Received,
472 LPDWORD ReturnedBytes );
473
474 typedef VOID (*PASYNC_COMPLETION_ROUTINE)(PVOID Context, PIO_STATUS_BLOCK IoStatusBlock);
475
476 #endif /* __MSAFD_H */
477
478 /* EOF */