More work on winsock stack (ping is now working)
[reactos.git] / reactos / drivers / net / afd / include / afd.h
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Ancillary Function Driver
4 * FILE: include/afd.h
5 * PURPOSE: Main driver header
6 */
7 #ifndef __AFD_H
8 #define __AFD_H
9
10 #include <winsock2.h>
11 #include <ddk/ntddk.h>
12 #include <net/tdikrnl.h>
13 #include <net/tdiinfo.h>
14 #include <afd/shared.h>
15 #include <debug.h>
16
17 /* Forward declarations */
18 struct _AFDFCB;
19
20 typedef struct _DEVICE_EXTENSION {
21 PDEVICE_OBJECT StorageDevice;
22 KSPIN_LOCK FCBListLock;
23 LIST_ENTRY FCBListHead;
24 } DEVICE_EXTENSION, *PDEVICE_EXTENSION;
25
26 /* Context Control Block structure */
27 typedef struct _AFDCCB {
28 struct _AFDFCB *FCB;
29 LIST_ENTRY ListEntry;
30 PFILE_OBJECT FileObject;
31 ULONG Flags;
32 LARGE_INTEGER CurrentByteOffset;
33 } AFDCCB, *PAFDCCB;
34
35 /* Flags for CCB structure */
36 #define CCB_CLEANED 0x00000001
37
38 /* Borrowed from http://www.acc.umu.se/~bosse/ntifs.h by Bo Branten */
39 typedef struct _FSRTL_COMMON_FCB_HEADER {
40 CSHORT NodeTypeCode;
41 CSHORT NodeByteSize;
42 UCHAR Flags;
43 UCHAR IsFastIoPossible;
44 UCHAR Flags2;
45 UCHAR Reserved;
46 PERESOURCE Resource;
47 PERESOURCE PagingIoResource;
48 LARGE_INTEGER AllocationSize;
49 LARGE_INTEGER FileSize;
50 LARGE_INTEGER ValidDataLength;
51 } FSRTL_COMMON_FCB_HEADER, *PFSRTL_COMMON_FCB_HEADER;
52
53 typedef struct _FsdNTRequiredFCB {
54 FSRTL_COMMON_FCB_HEADER CommonFCBHeader;
55 SECTION_OBJECT_POINTERS SectionObject;
56 ERESOURCE MainResource;
57 ERESOURCE PagingIoResource;
58 } FsdNTRequiredFCB, *PFsdNTRequiredFCB;
59
60 typedef struct _AFDFCB {
61 FsdNTRequiredFCB NTRequiredFCB;
62 LIST_ENTRY ListEntry;
63 BOOL CommandChannel;
64 PDEVICE_EXTENSION DeviceExt;
65 SHARE_ACCESS ShareAccess;
66 ULONG ReferenceCount;
67 ULONG OpenHandleCount;
68 HANDLE TdiAddressObjectHandle;
69 PFILE_OBJECT TdiAddressObject;
70 HANDLE TdiConnectionObjectHandle;
71 PFILE_OBJECT TdiConnectionObject;
72 LIST_ENTRY CCBListHead;
73 INT AddressFamily;
74 INT SocketType;
75 INT Protocol;
76 SOCKADDR SocketName;
77 PVOID HelperContext;
78 DWORD NotificationEvents;
79 UNICODE_STRING TdiDeviceName;
80 DWORD State;
81 PVOID SendBuffer;
82 LIST_ENTRY ReceiveQueue;
83 KSPIN_LOCK ReceiveQueueLock;
84 LIST_ENTRY ReadRequestQueue;
85 KSPIN_LOCK ReadRequestQueueLock;
86 } AFDFCB, *PAFDFCB;
87
88 /* Socket states */
89 #define SOCKET_STATE_CREATED 0
90 #define SOCKET_STATE_BOUND 1
91 #define SOCKET_STATE_LISTENING 2
92
93 typedef struct _AFD_BUFFER {
94 LIST_ENTRY ListEntry;
95 WSABUF Buffer;
96 } AFD_BUFFER, *PAFD_BUFFER;
97
98 typedef struct _AFD_READ_REQUEST {
99 LIST_ENTRY ListEntry;
100 PIRP Irp;
101 PFILE_REQUEST_RECVFROM RecvFromRequest;
102 PFILE_REPLY_RECVFROM RecvFromReply;
103 } AFD_READ_REQUEST, *PAFD_READ_REQUEST;
104
105 typedef struct IPSNMP_INFO {
106 ULONG Forwarding;
107 ULONG DefaultTTL;
108 ULONG InReceives;
109 ULONG InHdrErrors;
110 ULONG InAddrErrors;
111 ULONG ForwDatagrams;
112 ULONG InUnknownProtos;
113 ULONG InDiscards;
114 ULONG InDelivers;
115 ULONG OutRequests;
116 ULONG RoutingDiscards;
117 ULONG OutDiscards;
118 ULONG OutNoRoutes;
119 ULONG ReasmTimeout;
120 ULONG ReasmReqds;
121 ULONG ReasmOks;
122 ULONG ReasmFails;
123 ULONG FragOks;
124 ULONG FragFails;
125 ULONG FragCreates;
126 ULONG NumIf;
127 ULONG NumAddr;
128 ULONG NumRoutes;
129 } IPSNMP_INFO, *PIPSNMP_INFO;
130
131 typedef struct IPADDR_ENTRY {
132 ULONG Addr;
133 ULONG Index;
134 ULONG Mask;
135 ULONG BcastAddr;
136 ULONG ReasmSize;
137 USHORT Context;
138 USHORT Pad;
139 } IPADDR_ENTRY, *PIPADDR_ENTRY;
140
141
142 #define TL_INSTANCE 0
143
144 #define IP_MIB_STATS_ID 0x1
145 #define IP_MIB_ADDRTABLE_ENTRY_ID 0x102
146
147
148 /* IPv4 header format */
149 typedef struct IPv4_HEADER {
150 UCHAR VerIHL; /* 4-bit version, 4-bit Internet Header Length */
151 UCHAR Tos; /* Type of Service */
152 USHORT TotalLength; /* Total Length */
153 USHORT Id; /* Identification */
154 USHORT FlagsFragOfs; /* 3-bit Flags, 13-bit Fragment Offset */
155 UCHAR Ttl; /* Time to Live */
156 UCHAR Protocol; /* Protocol */
157 USHORT Checksum; /* Header Checksum */
158 ULONG SrcAddr; /* Source Address */
159 ULONG DstAddr; /* Destination Address */
160 } IPv4_HEADER, *PIPv4_HEADER;
161
162
163 /* IOCTL codes */
164
165 #define IOCTL_TCP_QUERY_INFORMATION_EX \
166 CTL_CODE(FILE_DEVICE_NETWORK, 0, METHOD_NEITHER, FILE_ANY_ACCESS)
167
168 #define IOCTL_TCP_SET_INFORMATION_EX \
169 CTL_CODE(FILE_DEVICE_NETWORK, 1, METHOD_BUFFERED, FILE_WRITE_ACCESS)
170
171
172 #ifdef i386
173
174 /* DWORD network to host byte order conversion for i386 */
175 #define DN2H(dw) \
176 ((((dw) & 0xFF000000L) >> 24) | \
177 (((dw) & 0x00FF0000L) >> 8) | \
178 (((dw) & 0x0000FF00L) << 8) | \
179 (((dw) & 0x000000FFL) << 24))
180
181 /* DWORD host to network byte order conversion for i386 */
182 #define DH2N(dw) \
183 ((((dw) & 0xFF000000L) >> 24) | \
184 (((dw) & 0x00FF0000L) >> 8) | \
185 (((dw) & 0x0000FF00L) << 8) | \
186 (((dw) & 0x000000FFL) << 24))
187
188 /* WORD network to host order conversion for i386 */
189 #define WN2H(w) \
190 ((((w) & 0xFF00) >> 8) | \
191 (((w) & 0x00FF) << 8))
192
193 /* WORD host to network byte order conversion for i386 */
194 #define WH2N(w) \
195 ((((w) & 0xFF00) >> 8) | \
196 (((w) & 0x00FF) << 8))
197
198 #else /* i386 */
199
200 /* DWORD network to host byte order conversion for other architectures */
201 #define DN2H(dw) \
202 (dw)
203
204 /* DWORD host to network byte order conversion for other architectures */
205 #define DH2N(dw) \
206 (dw)
207
208 /* WORD network to host order conversion for other architectures */
209 #define WN2H(w) \
210 (w)
211
212 /* WORD host to network byte order conversion for other architectures */
213 #define WH2N(w) \
214 (w)
215
216 #endif /* i386 */
217
218
219 extern NPAGED_LOOKASIDE_LIST BufferLookasideList;
220 extern NPAGED_LOOKASIDE_LIST ReadRequestLookasideList;
221
222
223 /* Prototypes from dispatch.c */
224
225 NTSTATUS AfdDispBind(
226 PIRP Irp,
227 PIO_STACK_LOCATION IrpSp);
228
229 NTSTATUS AfdDispListen(
230 PIRP Irp,
231 PIO_STACK_LOCATION IrpSp);
232
233 NTSTATUS AfdDispSendTo(
234 PIRP Irp,
235 PIO_STACK_LOCATION IrpSp);
236
237 NTSTATUS AfdDispRecvFrom(
238 PIRP Irp,
239 PIO_STACK_LOCATION IrpSp);
240
241 NTSTATUS AfdDispSelect(
242 PIRP Irp,
243 PIO_STACK_LOCATION IrpSp);
244
245 /* Prototypes from event.c */
246
247 NTSTATUS AfdRegisterEventHandlers(
248 PAFDFCB FCB);
249
250 NTSTATUS AfdDeregisterEventHandlers(
251 PAFDFCB FCB);
252
253 /* Prototypes from opnclose.c */
254
255 NTSTATUS STDCALL AfdCreate(
256 PDEVICE_OBJECT DeviceObject,
257 PIRP Irp);
258
259 NTSTATUS STDCALL AfdClose(
260 PDEVICE_OBJECT DeviceObject,
261 PIRP Irp);
262
263 /* Prototypes from rdwr.c */
264
265 NTSTATUS AfdEventReceiveDatagramHandler(
266 IN PVOID TdiEventContext,
267 IN LONG SourceAddressLength,
268 IN PVOID SourceAddress,
269 IN LONG OptionsLength,
270 IN PVOID Options,
271 IN ULONG ReceiveDatagramFlags,
272 IN ULONG BytesIndicated,
273 IN ULONG BytesAvailable,
274 OUT ULONG * BytesTaken,
275 IN PVOID Tsdu,
276 OUT PIRP * IoRequestPacket);
277
278 NTSTATUS STDCALL AfdRead(
279 PDEVICE_OBJECT DeviceObject,
280 PIRP Irp);
281
282 NTSTATUS STDCALL AfdWrite(
283 PDEVICE_OBJECT DeviceObject,
284 PIRP Irp);
285
286 /* Prototypes from routines.c */
287
288 ULONG WSABufferSize(
289 LPWSABUF Buffers,
290 DWORD BufferCount);
291
292 NTSTATUS MergeWSABuffers(
293 LPWSABUF Buffers,
294 DWORD BufferCount,
295 PVOID Destination,
296 ULONG MaxLength,
297 PULONG BytesCopied);
298
299 NTSTATUS FillWSABuffers(
300 PAFDFCB FCB,
301 LPWSABUF Buffers,
302 DWORD BufferCount,
303 PULONG BytesCopied);
304
305 VOID BuildIPv4Header(
306 PIPv4_HEADER IPHeader,
307 ULONG TotalSize,
308 ULONG Protocol,
309 PSOCKADDR SourceAddress,
310 PSOCKADDR DestinationAddress);
311
312 /* Prototypes from tdi.c */
313
314 NTSTATUS TdiCloseDevice(
315 HANDLE Handle,
316 PFILE_OBJECT FileObject);
317
318 NTSTATUS TdiOpenAddressFileIPv4(
319 PUNICODE_STRING DeviceName,
320 LPSOCKADDR Name,
321 PHANDLE AddressHandle,
322 PFILE_OBJECT *AddressObject);
323
324 NTSTATUS TdiOpenAddressFile(
325 PUNICODE_STRING DeviceName,
326 LPSOCKADDR Name,
327 PHANDLE AddressHandle,
328 PFILE_OBJECT *AddressObject);
329
330 NTSTATUS TdiSetEventHandler(
331 PFILE_OBJECT FileObject,
332 LONG EventType,
333 PVOID Handler,
334 PVOID Context);
335
336 NTSTATUS TdiQueryDeviceControl(
337 PFILE_OBJECT FileObject,
338 ULONG IoControlCode,
339 PVOID InputBuffer,
340 ULONG InputBufferLength,
341 PVOID OutputBuffer,
342 ULONG OutputBufferLength,
343 PULONG Return);
344
345 NTSTATUS TdiQueryInformationEx(
346 PFILE_OBJECT FileObject,
347 ULONG Entity,
348 ULONG Instance,
349 ULONG Class,
350 ULONG Type,
351 ULONG Id,
352 PVOID OutputBuffer,
353 PULONG OutputLength);
354
355 NTSTATUS TdiQueryAddress(
356 PFILE_OBJECT FileObject,
357 PULONG Address);
358
359 NTSTATUS TdiSend(
360 PFILE_OBJECT TransportObject,
361 PVOID Buffer,
362 ULONG BufferSize);
363
364 NTSTATUS TdiSendDatagram(
365 PFILE_OBJECT TransportObject,
366 LPSOCKADDR Address,
367 PMDL Mdl,
368 ULONG BufferSize);
369
370 #endif /*__AFD_H */
371
372 /* EOF */