xref: /reactos/sdk/include/reactos/drivers/afd/shared.h (revision c2c66aff)
1 /*
2  * COPYRIGHT:   See COPYING in the top level directory
3  * PROJECT:     ReactOS Ancillary Function Driver
4  * FILE:        include/reactos/drivers/afd/shared.h
5  * PURPOSE:     Shared definitions for AFD.SYS and MSAFD.DLL
6  */
7 #ifndef __AFD_SHARED_H
8 #define __AFD_SHARED_H
9 
10 #define AFD_MAX_EVENTS                  10
11 #define AFD_PACKET_COMMAND_LENGTH	15
12 #define AfdCommand "AfdOpenPacketXX"
13 
14 /* Extra definition of WSABUF for AFD so that I don't have to include any
15  * userland winsock headers. */
16 typedef struct _AFD_WSABUF {
17     UINT  len;
18     PCHAR buf;
19 } AFD_WSABUF, *PAFD_WSABUF;
20 
21 typedef struct _AFD_CREATE_PACKET {
22     DWORD				EndpointFlags;
23     DWORD				GroupID;
24     DWORD				SizeOfTransportName;
25     WCHAR				TransportName[1];
26 } AFD_CREATE_PACKET, *PAFD_CREATE_PACKET;
27 
28 typedef struct _AFD_INFO {
29     ULONG			        InformationClass;
30     union {
31         ULONG			        Ulong;
32         LARGE_INTEGER	                LargeInteger;
33         BOOLEAN                         Boolean;
34     }					Information;
35     ULONG				Padding;
36 } AFD_INFO, *PAFD_INFO;
37 
38 typedef struct _AFD_BIND_DATA {
39     ULONG				ShareType;
40     TRANSPORT_ADDRESS	Address;
41 } AFD_BIND_DATA, *PAFD_BIND_DATA;
42 
43 typedef struct _AFD_LISTEN_DATA {
44     BOOLEAN				UseSAN;
45     ULONG				Backlog;
46     BOOLEAN				UseDelayedAcceptance;
47 } AFD_LISTEN_DATA, *PAFD_LISTEN_DATA;
48 
49 typedef struct _AFD_HANDLE_ {
50     SOCKET				Handle;
51     ULONG				Events;
52     NTSTATUS			        Status;
53 } AFD_HANDLE, *PAFD_HANDLE;
54 
55 typedef struct _AFD_POLL_INFO {
56     LARGE_INTEGER		        Timeout;
57     ULONG				HandleCount;
58     ULONG_PTR                               Exclusive;
59     AFD_HANDLE			        Handles[1];
60 } AFD_POLL_INFO, *PAFD_POLL_INFO;
61 
62 typedef struct _AFD_ACCEPT_DATA {
63     ULONG				UseSAN;
64     ULONG				SequenceNumber;
65     HANDLE				ListenHandle;
66 } AFD_ACCEPT_DATA, *PAFD_ACCEPT_DATA;
67 
68 typedef struct _AFD_RECEIVED_ACCEPT_DATA {
69     ULONG				SequenceNumber;
70     TRANSPORT_ADDRESS			Address;
71 } AFD_RECEIVED_ACCEPT_DATA, *PAFD_RECEIVED_ACCEPT_DATA;
72 
73 typedef struct _AFD_PENDING_ACCEPT_DATA {
74     ULONG				SequenceNumber;
75     ULONG				SizeOfData;
76     ULONG				ReturnSize;
77 } AFD_PENDING_ACCEPT_DATA, *PAFD_PENDING_ACCEPT_DATA;
78 
79 typedef struct _AFD_DEFER_ACCEPT_DATA {
80     ULONG				SequenceNumber;
81     BOOLEAN				RejectConnection;
82 } AFD_DEFER_ACCEPT_DATA, *PAFD_DEFER_ACCEPT_DATA;
83 
84 typedef struct  _AFD_RECV_INFO {
85     PAFD_WSABUF				BufferArray;
86     ULONG				BufferCount;
87     ULONG				AfdFlags;
88     ULONG				TdiFlags;
89 } AFD_RECV_INFO , *PAFD_RECV_INFO ;
90 
91 typedef struct _AFD_RECV_INFO_UDP {
92     PAFD_WSABUF				BufferArray;
93     ULONG				BufferCount;
94     ULONG				AfdFlags;
95     ULONG				TdiFlags;
96     PVOID				Address;
97     PINT				AddressLength;
98 } AFD_RECV_INFO_UDP, *PAFD_RECV_INFO_UDP;
99 
100 typedef struct  _AFD_SEND_INFO {
101     PAFD_WSABUF				BufferArray;
102     ULONG				BufferCount;
103     ULONG				AfdFlags;
104     ULONG				TdiFlags;
105 } AFD_SEND_INFO , *PAFD_SEND_INFO ;
106 
107 typedef struct _AFD_SEND_INFO_UDP {
108     PAFD_WSABUF				BufferArray;
109     ULONG				BufferCount;
110     ULONG				AfdFlags;
111     TDI_REQUEST_SEND_DATAGRAM		TdiRequest;
112     TDI_CONNECTION_INFORMATION		TdiConnection;
113 } AFD_SEND_INFO_UDP, *PAFD_SEND_INFO_UDP;
114 
115 C_ASSERT(sizeof(AFD_RECV_INFO) == sizeof(AFD_SEND_INFO));
116 
117 typedef struct  _AFD_CONNECT_INFO {
118     BOOLEAN				UseSAN;
119     ULONG				Root;
120     ULONG				Unknown;
121     TRANSPORT_ADDRESS			RemoteAddress;
122 } AFD_CONNECT_INFO , *PAFD_CONNECT_INFO ;
123 
124 typedef struct _AFD_EVENT_SELECT_INFO {
125     HANDLE				EventObject;
126     ULONG				Events;
127 } AFD_EVENT_SELECT_INFO, *PAFD_EVENT_SELECT_INFO;
128 
129 typedef struct _AFD_ENUM_NETWORK_EVENTS_INFO {
130     HANDLE Event;
131     ULONG PollEvents;
132     NTSTATUS EventStatus[AFD_MAX_EVENTS];
133 } AFD_ENUM_NETWORK_EVENTS_INFO, *PAFD_ENUM_NETWORK_EVENTS_INFO;
134 
135 typedef struct _AFD_DISCONNECT_INFO {
136     ULONG				DisconnectType;
137     LARGE_INTEGER			Timeout;
138 } AFD_DISCONNECT_INFO, *PAFD_DISCONNECT_INFO;
139 
140 typedef struct _AFD_VALIDATE_GROUP_DATA
141 {
142     LONG GroupId;
143     TRANSPORT_ADDRESS Address;
144 } AFD_VALIDATE_GROUP_DATA, *PAFD_VALIDATE_GROUP_DATA;
145 
146 typedef struct _AFD_TDI_HANDLE_DATA
147 {
148     HANDLE TdiAddressHandle;
149     HANDLE TdiConnectionHandle;
150 } AFD_TDI_HANDLE_DATA, *PAFD_TDI_HANDLE_DATA;
151 
152 /* AFD Packet Endpoint Flags */
153 #define AFD_ENDPOINT_CONNECTIONLESS	0x1
154 #define AFD_ENDPOINT_MESSAGE_ORIENTED	0x10
155 #define AFD_ENDPOINT_RAW		0x100
156 #define AFD_ENDPOINT_MULTIPOINT		0x1000
157 #define AFD_ENDPOINT_C_ROOT		0x10000
158 #define AFD_ENDPOINT_D_ROOT	        0x100000
159 
160 /* AFD TDI Query Flags */
161 #define AFD_ADDRESS_HANDLE      0x1L
162 #define AFD_CONNECTION_HANDLE   0x2L
163 
164 /* AFD event bits */
165 #define AFD_EVENT_RECEIVE_BIT                   0
166 #define AFD_EVENT_OOB_RECEIVE_BIT               1
167 #define AFD_EVENT_SEND_BIT                      2
168 #define AFD_EVENT_DISCONNECT_BIT                3
169 #define AFD_EVENT_ABORT_BIT                     4
170 #define AFD_EVENT_CLOSE_BIT                     5
171 #define AFD_EVENT_CONNECT_BIT                   6
172 #define AFD_EVENT_ACCEPT_BIT                    7
173 #define AFD_EVENT_CONNECT_FAIL_BIT              8
174 #define AFD_EVENT_QOS_BIT                       9
175 #define AFD_EVENT_GROUP_QOS_BIT                 10
176 #define AFD_EVENT_ROUTING_INTERFACE_CHANGE_BIT  11
177 #define AFD_EVENT_ADDRESS_LIST_CHANGE_BIT       12
178 #define AFD_MAX_EVENT                           13
179 #define AFD_ALL_EVENTS                          ((1 << AFD_MAX_EVENT) - 1)
180 
181 /* AFD Info Flags */
182 #define AFD_INFO_INLINING_MODE		0x01L
183 #define AFD_INFO_BLOCKING_MODE		0x02L
184 #define AFD_INFO_SENDS_IN_PROGRESS	0x04L
185 #define AFD_INFO_RECEIVE_WINDOW_SIZE	0x06L
186 #define AFD_INFO_SEND_WINDOW_SIZE	0x07L
187 #define AFD_INFO_GROUP_ID_TYPE	        0x10L
188 #define AFD_INFO_RECEIVE_CONTENT_SIZE   0x11L
189 
190 /* AFD Share Flags */
191 #define AFD_SHARE_UNIQUE		0x0L
192 #define AFD_SHARE_REUSE			0x1L
193 #define AFD_SHARE_WILDCARD		0x2L
194 #define AFD_SHARE_EXCLUSIVE		0x3L
195 
196 /* AFD Disconnect Flags */
197 #define AFD_DISCONNECT_SEND		0x01L
198 #define AFD_DISCONNECT_RECV		0x02L
199 #define AFD_DISCONNECT_ABORT		0x04L
200 #define AFD_DISCONNECT_DATAGRAM		0x08L
201 
202 /* AFD Event Flags */
203 #define AFD_EVENT_RECEIVE                   (1 << AFD_EVENT_RECEIVE_BIT)
204 #define AFD_EVENT_OOB_RECEIVE               (1 << AFD_EVENT_OOB_RECEIVE_BIT)
205 #define AFD_EVENT_SEND                      (1 << AFD_EVENT_SEND_BIT)
206 #define AFD_EVENT_DISCONNECT                (1 << AFD_EVENT_DISCONNECT_BIT)
207 #define AFD_EVENT_ABORT                     (1 << AFD_EVENT_ABORT_BIT)
208 #define AFD_EVENT_CLOSE                     (1 << AFD_EVENT_CLOSE_BIT)
209 #define AFD_EVENT_CONNECT                   (1 << AFD_EVENT_CONNECT_BIT)
210 #define AFD_EVENT_ACCEPT                    (1 << AFD_EVENT_ACCEPT_BIT)
211 #define AFD_EVENT_CONNECT_FAIL              (1 << AFD_EVENT_CONNECT_FAIL_BIT)
212 #define AFD_EVENT_QOS                       (1 << AFD_EVENT_QOS_BIT)
213 #define AFD_EVENT_GROUP_QOS                 (1 << AFD_EVENT_GROUP_QOS_BIT)
214 #define AFD_EVENT_ROUTING_INTERFACE_CHANGE  (1 << AFD_EVENT_ROUTING_INTERFACE_CHANGE_BIT)
215 #define AFD_EVENT_ADDRESS_LIST_CHANGE       (1 << AFD_EVENT_ADDRESS_LIST_CHANGE_BIT)
216 
217 /* AFD SEND/RECV Flags */
218 #define AFD_SKIP_FIO			0x1L
219 #define AFD_OVERLAPPED			0x2L
220 #define AFD_IMMEDIATE                   0x4L
221 
222 /* IOCTL Generation */
223 #define FSCTL_AFD_BASE                  FILE_DEVICE_NETWORK
224 #define _AFD_CONTROL_CODE(Operation,Method) \
225   ((FSCTL_AFD_BASE)<<12 | (Operation<<2) | Method)
226 
227 /* AFD Commands */
228 #define AFD_BIND			0
229 #define AFD_CONNECT			1
230 #define AFD_START_LISTEN		2
231 #define AFD_WAIT_FOR_LISTEN		3
232 #define AFD_ACCEPT			4
233 #define AFD_RECV			5
234 #define AFD_RECV_DATAGRAM		6
235 #define AFD_SEND			7
236 #define AFD_SEND_DATAGRAM		8
237 #define AFD_SELECT			9
238 #define AFD_DISCONNECT			10
239 #define AFD_GET_SOCK_NAME		11
240 #define AFD_GET_PEER_NAME               12
241 #define AFD_GET_TDI_HANDLES		13
242 #define AFD_SET_INFO			14
243 #define AFD_GET_CONTEXT_SIZE		15
244 #define AFD_GET_CONTEXT			16
245 #define AFD_SET_CONTEXT			17
246 #define AFD_SET_CONNECT_DATA		18
247 #define AFD_SET_CONNECT_OPTIONS		19
248 #define AFD_SET_DISCONNECT_DATA		20
249 #define AFD_SET_DISCONNECT_OPTIONS	21
250 #define AFD_GET_CONNECT_DATA		22
251 #define AFD_GET_CONNECT_OPTIONS		23
252 #define AFD_GET_DISCONNECT_DATA		24
253 #define AFD_GET_DISCONNECT_OPTIONS	25
254 #define AFD_SET_CONNECT_DATA_SIZE       26
255 #define AFD_SET_CONNECT_OPTIONS_SIZE    27
256 #define AFD_SET_DISCONNECT_DATA_SIZE    28
257 #define AFD_SET_DISCONNECT_OPTIONS_SIZE 29
258 #define AFD_GET_INFO			30
259 #define AFD_EVENT_SELECT		33
260 #define AFD_ENUM_NETWORK_EVENTS         34
261 #define AFD_DEFER_ACCEPT		35
262 #define AFD_GET_PENDING_CONNECT_DATA	41
263 #define AFD_VALIDATE_GROUP		42
264 
265 /* AFD IOCTLs */
266 
267 #define IOCTL_AFD_BIND \
268   _AFD_CONTROL_CODE(AFD_BIND, METHOD_NEITHER)
269 #define IOCTL_AFD_CONNECT \
270   _AFD_CONTROL_CODE(AFD_CONNECT, METHOD_NEITHER)
271 #define IOCTL_AFD_START_LISTEN \
272   _AFD_CONTROL_CODE(AFD_START_LISTEN, METHOD_NEITHER)
273 #define IOCTL_AFD_WAIT_FOR_LISTEN \
274   _AFD_CONTROL_CODE(AFD_WAIT_FOR_LISTEN, METHOD_BUFFERED )
275 #define IOCTL_AFD_ACCEPT \
276   _AFD_CONTROL_CODE(AFD_ACCEPT, METHOD_BUFFERED )
277 #define IOCTL_AFD_RECV \
278   _AFD_CONTROL_CODE(AFD_RECV, METHOD_NEITHER)
279 #define IOCTL_AFD_RECV_DATAGRAM \
280   _AFD_CONTROL_CODE(AFD_RECV_DATAGRAM, METHOD_NEITHER)
281 #define IOCTL_AFD_SEND \
282   _AFD_CONTROL_CODE(AFD_SEND, METHOD_NEITHER)
283 #define IOCTL_AFD_SEND_DATAGRAM \
284   _AFD_CONTROL_CODE(AFD_SEND_DATAGRAM, METHOD_NEITHER)
285 #define IOCTL_AFD_SELECT \
286   _AFD_CONTROL_CODE(AFD_SELECT, METHOD_BUFFERED )
287 #define IOCTL_AFD_DISCONNECT \
288   _AFD_CONTROL_CODE(AFD_DISCONNECT, METHOD_NEITHER)
289 #define IOCTL_AFD_GET_SOCK_NAME \
290   _AFD_CONTROL_CODE(AFD_GET_SOCK_NAME, METHOD_NEITHER)
291 #define IOCTL_AFD_GET_PEER_NAME \
292   _AFD_CONTROL_CODE(AFD_GET_PEER_NAME, METHOD_NEITHER)
293 #define IOCTL_AFD_GET_TDI_HANDLES \
294   _AFD_CONTROL_CODE(AFD_GET_TDI_HANDLES, METHOD_NEITHER)
295 #define IOCTL_AFD_SET_INFO \
296   _AFD_CONTROL_CODE(AFD_SET_INFO, METHOD_NEITHER)
297 #define IOCTL_AFD_GET_CONTEXT_SIZE \
298   _AFD_CONTROL_CODE(AFD_GET_CONTEXT_SIZE, METHOD_NEITHER)
299 #define IOCTL_AFD_GET_CONTEXT \
300   _AFD_CONTROL_CODE(AFD_GET_CONTEXT, METHOD_NEITHER)
301 #define IOCTL_AFD_SET_CONTEXT \
302   _AFD_CONTROL_CODE(AFD_SET_CONTEXT, METHOD_NEITHER)
303 #define IOCTL_AFD_SET_CONNECT_DATA \
304   _AFD_CONTROL_CODE(AFD_SET_CONNECT_DATA, METHOD_NEITHER)
305 #define IOCTL_AFD_SET_CONNECT_OPTIONS \
306   _AFD_CONTROL_CODE(AFD_SET_CONNECT_OPTIONS, METHOD_NEITHER)
307 #define IOCTL_AFD_SET_DISCONNECT_DATA \
308   _AFD_CONTROL_CODE(AFD_SET_DISCONNECT_DATA, METHOD_NEITHER)
309 #define IOCTL_AFD_SET_DISCONNECT_OPTIONS \
310   _AFD_CONTROL_CODE(AFD_SET_DISCONNECT_OPTIONS, METHOD_NEITHER)
311 #define IOCTL_AFD_GET_CONNECT_DATA \
312   _AFD_CONTROL_CODE(AFD_GET_CONNECT_DATA, METHOD_NEITHER)
313 #define IOCTL_AFD_GET_CONNECT_OPTIONS \
314   _AFD_CONTROL_CODE(AFD_GET_CONNECT_OPTIONS, METHOD_NEITHER)
315 #define IOCTL_AFD_GET_DISCONNECT_DATA \
316   _AFD_CONTROL_CODE(AFD_GET_DISCONNECT_DATA, METHOD_NEITHER)
317 #define IOCTL_AFD_GET_DISCONNECT_OPTIONS \
318   _AFD_CONTROL_CODE(AFD_GET_DISCONNECT_OPTIONS, METHOD_NEITHER)
319 #define IOCTL_AFD_SET_CONNECT_DATA_SIZE \
320   _AFD_CONTROL_CODE(AFD_SET_CONNECT_DATA_SIZE, METHOD_NEITHER)
321 #define IOCTL_AFD_SET_CONNECT_OPTIONS_SIZE \
322   _AFD_CONTROL_CODE(AFD_SET_CONNECT_OPTIONS_SIZE, METHOD_NEITHER)
323 #define IOCTL_AFD_SET_DISCONNECT_DATA_SIZE \
324   _AFD_CONTROL_CODE(AFD_SET_DISCONNECT_DATA_SIZE, METHOD_NEITHER)
325 #define IOCTL_AFD_SET_DISCONNECT_OPTIONS_SIZE \
326   _AFD_CONTROL_CODE(AFD_SET_DISCONNECT_OPTIONS_SIZE, METHOD_NEITHER)
327 #define IOCTL_AFD_GET_INFO \
328   _AFD_CONTROL_CODE(AFD_GET_INFO, METHOD_NEITHER)
329 #define IOCTL_AFD_EVENT_SELECT \
330   _AFD_CONTROL_CODE(AFD_EVENT_SELECT, METHOD_NEITHER)
331 #define IOCTL_AFD_DEFER_ACCEPT \
332   _AFD_CONTROL_CODE(AFD_DEFER_ACCEPT, METHOD_NEITHER)
333 #define IOCTL_AFD_GET_PENDING_CONNECT_DATA \
334   _AFD_CONTROL_CODE(AFD_GET_PENDING_CONNECT_DATA, METHOD_NEITHER)
335 #define IOCTL_AFD_ENUM_NETWORK_EVENTS \
336   _AFD_CONTROL_CODE(AFD_ENUM_NETWORK_EVENTS, METHOD_NEITHER)
337 #define IOCTL_AFD_VALIDATE_GROUP \
338   _AFD_CONTROL_CODE(AFD_VALIDATE_GROUP, METHOD_NEITHER)
339 
340 typedef struct _AFD_SOCKET_INFORMATION {
341     BOOL CommandChannel;
342     INT AddressFamily;
343     INT SocketType;
344     INT Protocol;
345     PVOID HelperContext;
346     DWORD NotificationEvents;
347     UNICODE_STRING TdiDeviceName;
348     SOCKADDR Name;
349 } AFD_SOCKET_INFORMATION, *PAFD_SOCKET_INFORMATION;
350 
351 typedef struct _FILE_REQUEST_BIND {
352     SOCKADDR Name;
353 } FILE_REQUEST_BIND, *PFILE_REQUEST_BIND;
354 
355 typedef struct _FILE_REPLY_BIND {
356     INT Status;
357     HANDLE TdiAddressObjectHandle;
358     HANDLE TdiConnectionObjectHandle;
359 } FILE_REPLY_BIND, *PFILE_REPLY_BIND;
360 
361 typedef struct _FILE_REQUEST_LISTEN {
362     INT Backlog;
363 } FILE_REQUEST_LISTEN, *PFILE_REQUEST_LISTEN;
364 
365 typedef struct _FILE_REPLY_LISTEN {
366     INT Status;
367 } FILE_REPLY_LISTEN, *PFILE_REPLY_LISTEN;
368 
369 typedef struct _FILE_REQUEST_SENDTO {
370     LPWSABUF Buffers;
371     DWORD BufferCount;
372     DWORD Flags;
373     SOCKADDR To;
374     INT ToLen;
375 } FILE_REQUEST_SENDTO, *PFILE_REQUEST_SENDTO;
376 
377 typedef struct _FILE_REPLY_SENDTO {
378     INT Status;
379     DWORD NumberOfBytesSent;
380 } FILE_REPLY_SENDTO, *PFILE_REPLY_SENDTO;
381 
382 typedef struct _FILE_REQUEST_RECVFROM {
383     LPWSABUF Buffers;
384     DWORD BufferCount;
385     LPDWORD Flags;
386     LPSOCKADDR From;
387     LPINT FromLen;
388 } FILE_REQUEST_RECVFROM, *PFILE_REQUEST_RECVFROM;
389 
390 typedef struct _FILE_REPLY_RECVFROM {
391     INT Status;
392     DWORD NumberOfBytesRecvd;
393 } FILE_REPLY_RECVFROM, *PFILE_REPLY_RECVFROM;
394 
395 typedef struct _FILE_REQUEST_RECV {
396     LPWSABUF Buffers;
397     DWORD BufferCount;
398     LPDWORD Flags;
399 } FILE_REQUEST_RECV, *PFILE_REQUEST_RECV;
400 
401 typedef struct _FILE_REPLY_RECV {
402     INT Status;
403     DWORD NumberOfBytesRecvd;
404 } FILE_REPLY_RECV, *PFILE_REPLY_RECV;
405 
406 
407 typedef struct _FILE_REQUEST_SEND {
408     LPWSABUF Buffers;
409     DWORD BufferCount;
410     DWORD Flags;
411 } FILE_REQUEST_SEND, *PFILE_REQUEST_SEND;
412 
413 typedef struct _FILE_REPLY_SEND {
414     INT Status;
415     DWORD NumberOfBytesSent;
416 } FILE_REPLY_SEND, *PFILE_REPLY_SEND;
417 
418 
419 typedef struct _FILE_REQUEST_ACCEPT {
420     LPSOCKADDR addr;
421     INT addrlen;
422     LPCONDITIONPROC lpfnCondition;
423     DWORD dwCallbackData;
424 } FILE_REQUEST_ACCEPT, *PFILE_REQUEST_ACCEPT;
425 
426 typedef struct _FILE_REPLY_ACCEPT {
427     INT Status;
428     INT addrlen;
429     SOCKET Socket;
430 } FILE_REPLY_ACCEPT, *PFILE_REPLY_ACCEPT;
431 
432 
433 typedef struct _FILE_REQUEST_CONNECT {
434     LPSOCKADDR name;
435     INT namelen;
436     LPWSABUF lpCallerData;
437     LPWSABUF lpCalleeData;
438     LPQOS lpSQOS;
439     LPQOS lpGQOS;
440 } FILE_REQUEST_CONNECT, *PFILE_REQUEST_CONNECT;
441 
442 typedef struct _FILE_REPLY_CONNECT {
443     INT Status;
444 } FILE_REPLY_CONNECT, *PFILE_REPLY_CONNECT;
445 
446 #endif /*__AFD_SHARED_H */
447 
448 /* EOF */
449