Sync with trunk (r48545)
[reactos.git] / include / ddk / tdikrnl.h
1 /*
2 * tdikrnl.h
3 *
4 * TDI kernel mode definitions
5 *
6 * This file is part of the w32api package.
7 *
8 * Contributors:
9 * Created by Casper S. Hornstrup <chorns@users.sourceforge.net>
10 *
11 * THIS SOFTWARE IS NOT COPYRIGHTED
12 *
13 * This source code is offered for use in the public domain. You may
14 * use, modify or distribute it freely.
15 *
16 * This code is distributed in the hope that it will be useful but
17 * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
18 * DISCLAIMED. This includes but is not limited to warranties of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20 *
21 */
22
23 #ifndef __TDIKRNL_H
24 #define __TDIKRNL_H
25
26 #include "tdi.h"
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 #if defined(_TDI_)
33 #define TDIKRNLAPI
34 #else
35 #define TDIKRNLAPI DECLSPEC_IMPORT
36 #endif
37
38
39 typedef struct _TDI_REQUEST_KERNEL {
40 ULONG RequestFlags;
41 PTDI_CONNECTION_INFORMATION RequestConnectionInformation;
42 PTDI_CONNECTION_INFORMATION ReturnConnectionInformation;
43 PVOID RequestSpecific;
44 } TDI_REQUEST_KERNEL, *PTDI_REQUEST_KERNEL;
45
46 /* Request codes */
47 #define TDI_ASSOCIATE_ADDRESS 0x01
48 #define TDI_DISASSOCIATE_ADDRESS 0x02
49 #define TDI_CONNECT 0x03
50 #define TDI_LISTEN 0x04
51 #define TDI_ACCEPT 0x05
52 #define TDI_DISCONNECT 0x06
53 #define TDI_SEND 0x07
54 #define TDI_RECEIVE 0x08
55 #define TDI_SEND_DATAGRAM 0x09
56 #define TDI_RECEIVE_DATAGRAM 0x0A
57 #define TDI_SET_EVENT_HANDLER 0x0B
58 #define TDI_QUERY_INFORMATION 0x0C
59 #define TDI_SET_INFORMATION 0x0D
60 #define TDI_ACTION 0x0E
61
62 #define TDI_DIRECT_SEND 0x27
63 #define TDI_DIRECT_SEND_DATAGRAM 0x29
64
65 #define TDI_TRANSPORT_ADDRESS_FILE 1
66 #define TDI_CONNECTION_FILE 2
67 #define TDI_CONTROL_CHANNEL_FILE 3
68
69 /* Internal TDI IOCTLS */
70 #define IOCTL_TDI_QUERY_DIRECT_SEND_HANDLER _TDI_CONTROL_CODE(0x80, METHOD_NEITHER)
71 #define IOCTL_TDI_QUERY_DIRECT_SENDDG_HANDLER _TDI_CONTROL_CODE(0x81, METHOD_NEITHER)
72
73 /* TdiAssociateAddress */
74 typedef struct _TDI_REQUEST_KERNEL_ASSOCIATE {
75 HANDLE AddressHandle;
76 } TDI_REQUEST_KERNEL_ASSOCIATE, *PTDI_REQUEST_KERNEL_ASSOCIATE;
77
78 /* TdiDisassociateAddress */
79 typedef TDI_REQUEST_KERNEL TDI_REQUEST_KERNEL_DISASSOCIATE,
80 *PTDI_REQUEST_KERNEL_DISASSOCIATE;
81
82 /* TdiAccept */
83 typedef struct _TDI_REQUEST_KERNEL_ACCEPT {
84 PTDI_CONNECTION_INFORMATION RequestConnectionInformation;
85 PTDI_CONNECTION_INFORMATION ReturnConnectionInformation;
86 } TDI_REQUEST_KERNEL_ACCEPT, *PTDI_REQUEST_KERNEL_ACCEPT;
87
88 /* TdiConnect */
89 typedef TDI_REQUEST_KERNEL TDI_REQUEST_KERNEL_CONNECT,
90 *PTDI_REQUEST_KERNEL_CONNECT;
91
92 /* TdiDisconnect */
93 typedef TDI_REQUEST_KERNEL TDI_REQUEST_KERNEL_DISCONNECT,
94 *PTDI_REQUEST_KERNEL_DISCONNECT;
95
96 /* TdiListen */
97 typedef TDI_REQUEST_KERNEL TDI_REQUEST_KERNEL_LISTEN,
98 *PTDI_REQUEST_KERNEL_LISTEN;
99
100 /* TdiReceive */
101 typedef struct _TDI_REQUEST_KERNEL_RECEIVE {
102 ULONG ReceiveLength;
103 ULONG ReceiveFlags;
104 } TDI_REQUEST_KERNEL_RECEIVE, *PTDI_REQUEST_KERNEL_RECEIVE;
105
106 /* TdiReceiveDatagram */
107 typedef struct _TDI_REQUEST_KERNEL_RECEIVEDG {
108 ULONG ReceiveLength;
109 PTDI_CONNECTION_INFORMATION ReceiveDatagramInformation;
110 PTDI_CONNECTION_INFORMATION ReturnDatagramInformation;
111 ULONG ReceiveFlags;
112 } TDI_REQUEST_KERNEL_RECEIVEDG, *PTDI_REQUEST_KERNEL_RECEIVEDG;
113
114 /* TdiSend */
115 typedef struct _TDI_REQUEST_KERNEL_SEND {
116 ULONG SendLength;
117 ULONG SendFlags;
118 } TDI_REQUEST_KERNEL_SEND, *PTDI_REQUEST_KERNEL_SEND;
119
120 /* TdiSendDatagram */
121 typedef struct _TDI_REQUEST_KERNEL_SENDDG {
122 ULONG SendLength;
123 PTDI_CONNECTION_INFORMATION SendDatagramInformation;
124 } TDI_REQUEST_KERNEL_SENDDG, *PTDI_REQUEST_KERNEL_SENDDG;
125
126 /* TdiSetEventHandler */
127 typedef struct _TDI_REQUEST_KERNEL_SET_EVENT {
128 LONG EventType;
129 PVOID EventHandler;
130 PVOID EventContext;
131 } TDI_REQUEST_KERNEL_SET_EVENT, *PTDI_REQUEST_KERNEL_SET_EVENT;
132
133 /* TdiQueryInformation */
134 typedef struct _TDI_REQUEST_KERNEL_QUERY_INFO {
135 LONG QueryType;
136 PTDI_CONNECTION_INFORMATION RequestConnectionInformation;
137 } TDI_REQUEST_KERNEL_QUERY_INFORMATION, *PTDI_REQUEST_KERNEL_QUERY_INFORMATION;
138
139 /* TdiSetInformation */
140 typedef struct _TDI_REQUEST_KERNEL_SET_INFO {
141 LONG SetType;
142 PTDI_CONNECTION_INFORMATION RequestConnectionInformation;
143 } TDI_REQUEST_KERNEL_SET_INFORMATION, *PTDI_REQUEST_KERNEL_SET_INFORMATION;
144
145 /* Event types */
146 #define TDI_EVENT_CONNECT 0
147 #define TDI_EVENT_DISCONNECT 1
148 #define TDI_EVENT_ERROR 2
149 #define TDI_EVENT_RECEIVE 3
150 #define TDI_EVENT_RECEIVE_DATAGRAM 4
151 #define TDI_EVENT_RECEIVE_EXPEDITED 5
152 #define TDI_EVENT_SEND_POSSIBLE 6
153 #define TDI_EVENT_CHAINED_RECEIVE 7
154 #define TDI_EVENT_CHAINED_RECEIVE_DATAGRAM 8
155 #define TDI_EVENT_CHAINED_RECEIVE_EXPEDITED 9
156 #define TDI_EVENT_ERROR_EX 10
157
158 typedef NTSTATUS
159 (NTAPI *PTDI_IND_CONNECT)(
160 IN PVOID TdiEventContext,
161 IN LONG RemoteAddressLength,
162 IN PVOID RemoteAddress,
163 IN LONG UserDataLength,
164 IN PVOID UserData,
165 IN LONG OptionsLength,
166 IN PVOID Options,
167 OUT CONNECTION_CONTEXT *ConnectionContext,
168 OUT PIRP *AcceptIrp);
169
170 TDIKRNLAPI
171 NTSTATUS
172 NTAPI
173 TdiDefaultConnectHandler(
174 IN PVOID TdiEventContext,
175 IN LONG RemoteAddressLength,
176 IN PVOID RemoteAddress,
177 IN LONG UserDataLength,
178 IN PVOID UserData,
179 IN LONG OptionsLength,
180 IN PVOID Options,
181 OUT CONNECTION_CONTEXT *ConnectionContext,
182 OUT PIRP *AcceptIrp);
183
184 typedef NTSTATUS
185 (NTAPI *PTDI_IND_DISCONNECT)(
186 IN PVOID TdiEventContext,
187 IN CONNECTION_CONTEXT ConnectionContext,
188 IN LONG DisconnectDataLength,
189 IN PVOID DisconnectData,
190 IN LONG DisconnectInformationLength,
191 IN PVOID DisconnectInformation,
192 IN ULONG DisconnectFlags);
193
194 TDIKRNLAPI
195 NTSTATUS
196 NTAPI
197 TdiDefaultDisconnectHandler(
198 IN PVOID TdiEventContext,
199 IN CONNECTION_CONTEXT ConnectionContext,
200 IN LONG DisconnectDataLength,
201 IN PVOID DisconnectData,
202 IN LONG DisconnectInformationLength,
203 IN PVOID DisconnectInformation,
204 IN ULONG DisconnectFlags);
205
206 typedef NTSTATUS
207 (NTAPI *PTDI_IND_ERROR)(
208 IN PVOID TdiEventContext,
209 IN NTSTATUS Status);
210
211 typedef NTSTATUS
212 (NTAPI *PTDI_IND_ERROR_EX)(
213 IN PVOID TdiEventContext,
214 IN NTSTATUS Status,
215 IN PVOID Buffer);
216
217 TDIKRNLAPI
218 NTSTATUS
219 NTAPI
220 TdiDefaultErrorHandler(
221 IN PVOID TdiEventContext,
222 IN NTSTATUS Status);
223
224 typedef NTSTATUS
225 (NTAPI *PTDI_IND_RECEIVE)(
226 IN PVOID TdiEventContext,
227 IN CONNECTION_CONTEXT ConnectionContext,
228 IN ULONG ReceiveFlags,
229 IN ULONG BytesIndicated,
230 IN ULONG BytesAvailable,
231 OUT ULONG *BytesTaken,
232 IN PVOID Tsdu,
233 OUT PIRP *IoRequestPacket);
234
235 TDIKRNLAPI
236 NTSTATUS
237 NTAPI
238 TdiDefaultReceiveHandler(
239 IN PVOID TdiEventContext,
240 IN CONNECTION_CONTEXT ConnectionContext,
241 IN ULONG ReceiveFlags,
242 IN ULONG BytesIndicated,
243 IN ULONG BytesAvailable,
244 OUT ULONG *BytesTaken,
245 IN PVOID Tsdu,
246 OUT PIRP *IoRequestPacket);
247
248 typedef NTSTATUS
249 (NTAPI *PTDI_IND_RECEIVE_DATAGRAM)(
250 IN PVOID TdiEventContext,
251 IN LONG SourceAddressLength,
252 IN PVOID SourceAddress,
253 IN LONG OptionsLength,
254 IN PVOID Options,
255 IN ULONG ReceiveDatagramFlags,
256 IN ULONG BytesIndicated,
257 IN ULONG BytesAvailable,
258 OUT ULONG *BytesTaken,
259 IN PVOID Tsdu,
260 OUT PIRP *IoRequestPacket);
261
262 TDIKRNLAPI
263 NTSTATUS NTAPI
264 TdiDefaultRcvDatagramHandler(
265 IN PVOID TdiEventContext,
266 IN LONG SourceAddressLength,
267 IN PVOID SourceAddress,
268 IN LONG OptionsLength,
269 IN PVOID Options,
270 IN ULONG ReceiveDatagramFlags,
271 IN ULONG BytesIndicated,
272 IN ULONG BytesAvailable,
273 OUT ULONG *BytesTaken,
274 IN PVOID Tsdu,
275 OUT PIRP *IoRequestPacket);
276
277 typedef NTSTATUS
278 (NTAPI *PTDI_IND_RECEIVE_EXPEDITED)(
279 IN PVOID TdiEventContext,
280 IN CONNECTION_CONTEXT ConnectionContext,
281 IN ULONG ReceiveFlags,
282 IN ULONG BytesIndicated,
283 IN ULONG BytesAvailable,
284 OUT ULONG *BytesTaken,
285 IN PVOID Tsdu,
286 OUT PIRP *IoRequestPacket);
287
288 TDIKRNLAPI
289 NTSTATUS
290 NTAPI
291 TdiDefaultRcvExpeditedHandler(
292 IN PVOID TdiEventContext,
293 IN CONNECTION_CONTEXT ConnectionContext,
294 IN ULONG ReceiveFlags,
295 IN ULONG BytesIndicated,
296 IN ULONG BytesAvailable,
297 OUT ULONG *BytesTaken,
298 IN PVOID Tsdu,
299 OUT PIRP *IoRequestPacket);
300
301 typedef NTSTATUS
302 (NTAPI *PTDI_IND_CHAINED_RECEIVE)(
303 IN PVOID TdiEventContext,
304 IN CONNECTION_CONTEXT ConnectionContext,
305 IN ULONG ReceiveFlags,
306 IN ULONG ReceiveLength,
307 IN ULONG StartingOffset,
308 IN PMDL Tsdu,
309 IN PVOID TsduDescriptor);
310
311 TDIKRNLAPI
312 NTSTATUS
313 NTAPI
314 TdiDefaultChainedReceiveHandler(
315 IN PVOID TdiEventContext,
316 IN CONNECTION_CONTEXT ConnectionContext,
317 IN ULONG ReceiveFlags,
318 IN ULONG ReceiveLength,
319 IN ULONG StartingOffset,
320 IN PMDL Tsdu,
321 IN PVOID TsduDescriptor);
322
323 typedef NTSTATUS
324 (NTAPI *PTDI_IND_CHAINED_RECEIVE_DATAGRAM)(
325 IN PVOID TdiEventContext,
326 IN LONG SourceAddressLength,
327 IN PVOID SourceAddress,
328 IN LONG OptionsLength,
329 IN PVOID Options,
330 IN ULONG ReceiveDatagramFlags,
331 IN ULONG ReceiveDatagramLength,
332 IN ULONG StartingOffset,
333 IN PMDL Tsdu,
334 IN PVOID TsduDescriptor);
335
336 TDIKRNLAPI
337 NTSTATUS
338 NTAPI
339 TdiDefaultChainedRcvDatagramHandler(
340 IN PVOID TdiEventContext,
341 IN LONG SourceAddressLength,
342 IN PVOID SourceAddress,
343 IN LONG OptionsLength,
344 IN PVOID Options,
345 IN ULONG ReceiveDatagramFlags,
346 IN ULONG ReceiveDatagramLength,
347 IN ULONG StartingOffset,
348 IN PMDL Tsdu,
349 IN PVOID TsduDescriptor);
350
351 typedef NTSTATUS
352 (NTAPI *PTDI_IND_CHAINED_RECEIVE_EXPEDITED)(
353 IN PVOID TdiEventContext,
354 IN CONNECTION_CONTEXT ConnectionContext,
355 IN ULONG ReceiveFlags,
356 IN ULONG ReceiveLength,
357 IN ULONG StartingOffset,
358 IN PMDL Tsdu,
359 IN PVOID TsduDescriptor);
360
361 TDIKRNLAPI
362 NTSTATUS
363 NTAPI
364 TdiDefaultChainedRcvExpeditedHandler(
365 IN PVOID TdiEventContext,
366 IN CONNECTION_CONTEXT ConnectionContext,
367 IN ULONG ReceiveFlags,
368 IN ULONG ReceiveLength,
369 IN ULONG StartingOffset,
370 IN PMDL Tsdu,
371 IN PVOID TsduDescriptor);
372
373 typedef NTSTATUS
374 (NTAPI *PTDI_IND_SEND_POSSIBLE)(
375 IN PVOID TdiEventContext,
376 IN PVOID ConnectionContext,
377 IN ULONG BytesAvailable);
378
379 TDIKRNLAPI
380 NTSTATUS
381 NTAPI
382 TdiDefaultSendPossibleHandler(
383 IN PVOID TdiEventContext,
384 IN PVOID ConnectionContext,
385 IN ULONG BytesAvailable);
386
387
388
389 /* Macros and functions to build IRPs */
390
391 #define TdiBuildBaseIrp( \
392 bIrp, bDevObj, bFileObj, bCompRoutine, bContxt, bIrpSp, bMinor) \
393 { \
394 bIrpSp->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL; \
395 bIrpSp->MinorFunction = (bMinor); \
396 bIrpSp->DeviceObject = (bDevObj); \
397 bIrpSp->FileObject = (bFileObj); \
398 if (bCompRoutine) \
399 { \
400 IoSetCompletionRoutine(bIrp, bCompRoutine, bContxt, TRUE, TRUE, TRUE);\
401 } \
402 else \
403 IoSetCompletionRoutine(bIrp, NULL, NULL, FALSE, FALSE, FALSE); \
404 }
405
406 /*
407 * VOID
408 * TdiBuildAccept(
409 * IN PIRP Irp,
410 * IN PDEVICE_OBJECT DevObj,
411 * IN PFILE_OBJECT FileObj,
412 * IN PVOID CompRoutine,
413 * IN PVOID Contxt,
414 * IN PTDI_CONNECTION_INFORMATION RequestConnectionInfo,
415 * OUT PTDI_CONNECTION_INFORMATION ReturnConnectionInfo);
416 */
417 #define TdiBuildAccept( \
418 Irp, DevObj, FileObj, CompRoutine, Contxt, \
419 RequestConnectionInfo, ReturnConnectionInfo) \
420 { \
421 PTDI_REQUEST_KERNEL_ACCEPT _Request; \
422 PIO_STACK_LOCATION _IrpSp; \
423 \
424 _IrpSp = IoGetNextIrpStackLocation(Irp); \
425 \
426 TdiBuildBaseIrp(Irp, DevObj, FileObj, CompRoutine, \
427 Contxt, _IrpSp, TDI_ACCEPT); \
428 \
429 _Request = (PTDI_REQUEST_KERNEL_ACCEPT)&_IrpSp->Parameters; \
430 _Request->RequestConnectionInformation = (RequestConnectionInfo); \
431 _Request->ReturnConnectionInformation = (ReturnConnectionInfo); \
432 }
433
434 /*
435 * VOID
436 * TdiBuildAction(
437 * IN PIRP Irp,
438 * IN PDEVICE_OBJECT DevObj,
439 * IN PFILE_OBJECT FileObj,
440 * IN PVOID CompRoutine,
441 * IN PVOID Contxt,
442 * IN PMDL MdlAddr);
443 */
444 #define TdiBuildAction( \
445 Irp, DevObj, FileObj, CompRoutine, Contxt, MdlAddr) \
446 { \
447 PIO_STACK_LOCATION _IrpSp; \
448 \
449 _IrpSp = IoGetNextIrpStackLocation(Irp); \
450 \
451 TdiBuildBaseIrp(Irp, DevObj, FileObj, CompRoutine, \
452 Contxt, _IrpSp, TDI_ACTION); \
453 \
454 (Irp)->MdlAddress = (MdlAddr); \
455 }
456
457 /*
458 * VOID
459 * TdiBuildAssociateAddress(
460 * IN PIRP Irp,
461 * IN PDEVICE_OBJECT DevObj,
462 * IN PFILE_OBJECT FileObj,
463 * IN PVOID CompRoutine,
464 * IN PVOID Contxt,
465 * IN HANDLE AddrHandle);
466 */
467 #define TdiBuildAssociateAddress( \
468 Irp, DevObj, FileObj, CompRoutine, Contxt, AddrHandle) \
469 { \
470 PTDI_REQUEST_KERNEL_ASSOCIATE _Request; \
471 PIO_STACK_LOCATION _IrpSp; \
472 \
473 _IrpSp = IoGetNextIrpStackLocation(Irp); \
474 \
475 TdiBuildBaseIrp(Irp, DevObj, FileObj, CompRoutine, \
476 Contxt, _IrpSp, TDI_ASSOCIATE_ADDRESS); \
477 \
478 _Request = (PTDI_REQUEST_KERNEL_ASSOCIATE)&_IrpSp->Parameters; \
479 _Request->AddressHandle = (HANDLE)(AddrHandle); \
480 }
481
482 /*
483 * VOID
484 * TdiBuildConnect(
485 * IN PIRP Irp,
486 * IN PDEVICE_OBJECT DevObj,
487 * IN PFILE_OBJECT FileObj,
488 * IN PVOID CompRoutine,
489 * IN PVOID Contxt,
490 * IN PLARGE_INTEGER Time,
491 * IN PTDI_CONNECTION_INFORMATION RequestConnectionInfo,
492 * OUT PTDI_CONNECTION_INFORMATION ReturnConnectionInfo);
493 */
494 #define TdiBuildConnect( \
495 Irp, DevObj, FileObj, CompRoutine, Contxt, \
496 Time, RequestConnectionInfo, ReturnConnectionInfo) \
497 { \
498 PTDI_REQUEST_KERNEL _Request; \
499 PIO_STACK_LOCATION _IrpSp; \
500 \
501 _IrpSp = IoGetNextIrpStackLocation(Irp); \
502 \
503 TdiBuildBaseIrp(Irp, DevObj, FileObj, CompRoutine, \
504 Contxt, _IrpSp, TDI_CONNECT); \
505 \
506 _Request = (PTDI_REQUEST_KERNEL)&_IrpSp->Parameters; \
507 _Request->RequestConnectionInformation = (RequestConnectionInfo); \
508 _Request->ReturnConnectionInformation = (ReturnConnectionInfo); \
509 _Request->RequestSpecific = (PVOID)(Time); \
510 }
511
512 /*
513 * VOID
514 * TdiBuildDisassociateAddress(
515 * IN PIRP Irp,
516 * IN PDEVICE_OBJECT DevObj,
517 * IN PFILE_OBJECT FileObj,
518 * IN PVOID CompRoutine,
519 * IN PVOID Contxt);
520 */
521 #define TdiBuildDisassociateAddress( \
522 Irp, DevObj, FileObj, CompRoutine, Contxt) \
523 { \
524 PIO_STACK_LOCATION _IrpSp; \
525 \
526 _IrpSp = IoGetNextIrpStackLocation(Irp); \
527 \
528 TdiBuildBaseIrp(Irp, DevObj, FileObj, CompRoutine, \
529 Contxt, _IrpSp, TDI_DISASSOCIATE_ADDRESS); \
530 }
531
532 /*
533 * VOID
534 * TdiBuildDisconnect(
535 * IN PIRP Irp,
536 * IN PDEVICE_OBJECT DevObj,
537 * IN PFILE_OBJECT FileObj,
538 * IN PVOID CompRoutine,
539 * IN PVOID Contxt,
540 * IN PLARGE_INTEGER Time,
541 * IN PULONG Flags,
542 * IN PTDI_CONNECTION_INFORMATION RequestConnectionInfo,
543 * OUT PTDI_CONNECTION_INFORMATION ReturnConnectionInfo);
544 */
545 #define TdiBuildDisconnect( \
546 Irp, DevObj, FileObj, CompRoutine, Contxt, Time, \
547 Flags, RequestConnectionInfo, ReturnConnectionInfo) \
548 { \
549 PTDI_REQUEST_KERNEL _Request; \
550 PIO_STACK_LOCATION _IrpSp; \
551 \
552 _IrpSp = IoGetNextIrpStackLocation(Irp); \
553 \
554 TdiBuildBaseIrp(Irp, DevObj, FileObj, CompRoutine, \
555 Contxt, _IrpSp, TDI_DISCONNECT); \
556 \
557 _Request = (PTDI_REQUEST_KERNEL)&_IrpSp->Parameters; \
558 _Request->RequestConnectionInformation = (RequestConnectionInfo); \
559 _Request->ReturnConnectionInformation = (ReturnConnectionInfo); \
560 _Request->RequestSpecific = (PVOID)(Time); \
561 _Request->RequestFlags = (Flags); \
562 }
563
564 /*
565 * PIRP
566 * TdiBuildInternalDeviceControlIrp(
567 * IN CCHAR IrpSubFunction,
568 * IN PDEVICE_OBJECT DeviceObject,
569 * IN PFILE_OBJECT FileObject,
570 * IN PKEVENT Event,
571 * IN PIO_STATUS_BLOCK IoStatusBlock);
572 */
573 #define TdiBuildInternalDeviceControlIrp( \
574 IrpSubFunction, DeviceObject, \
575 FileObject, Event, IoStatusBlock) \
576 IoBuildDeviceIoControlRequest( \
577 IrpSubFunction, DeviceObject, \
578 NULL, 0, NULL, 0, \
579 TRUE, Event, IoStatusBlock)
580
581 /*
582 * VOID
583 * TdiBuildListen(
584 * IN PIRP Irp,
585 * IN PDEVICE_OBJECT DevObj,
586 * IN PFILE_OBJECT FileObj,
587 * IN PVOID CompRoutine,
588 * IN PVOID Contxt,
589 * IN ULONG Flags,
590 * IN PTDI_CONNECTION_INFORMATION RequestConnectionInfo,
591 * OUT PTDI_CONNECTION_INFORMATION ReturnConnectionInfo);
592 */
593 #define TdiBuildListen( \
594 Irp, DevObj, FileObj, CompRoutine, Contxt, \
595 Flags, RequestConnectionInfo, ReturnConnectionInfo) \
596 { \
597 PTDI_REQUEST_KERNEL _Request; \
598 PIO_STACK_LOCATION _IrpSp; \
599 \
600 _IrpSp = IoGetNextIrpStackLocation(Irp); \
601 \
602 TdiBuildBaseIrp(Irp, DevObj, FileObj, CompRoutine, \
603 Contxt, _IrpSp, TDI_LISTEN); \
604 \
605 _Request = (PTDI_REQUEST_KERNEL)&_IrpSp->Parameters; \
606 _Request->RequestConnectionInformation = (RequestConnectionInfo); \
607 _Request->ReturnConnectionInformation = (ReturnConnectionInfo); \
608 _Request->RequestFlags = (Flags); \
609 }
610
611 TDIKRNLAPI
612 VOID
613 NTAPI
614 TdiBuildNetbiosAddress(
615 IN PUCHAR NetbiosName,
616 IN BOOLEAN IsGroupName,
617 IN OUT PTA_NETBIOS_ADDRESS NetworkName);
618
619 TDIKRNLAPI
620 NTSTATUS
621 NTAPI
622 TdiBuildNetbiosAddressEa(
623 IN PUCHAR Buffer,
624 IN BOOLEAN IsGroupName,
625 IN PUCHAR NetbiosName);
626
627 /*
628 * VOID
629 * TdiBuildQueryInformation(
630 * IN PIRP Irp,
631 * IN PDEVICE_OBJECT DevObj,
632 * IN PFILE_OBJECT FileObj,
633 * IN PVOID CompRoutine,
634 * IN PVOID Contxt,
635 * IN UINT QType,
636 * IN PMDL MdlAddr);
637 */
638 #define TdiBuildQueryInformation( \
639 Irp, DevObj, FileObj, CompRoutine, Contxt, QType, MdlAddr) \
640 { \
641 PTDI_REQUEST_KERNEL_QUERY_INFORMATION _Request; \
642 PIO_STACK_LOCATION _IrpSp; \
643 \
644 _IrpSp = IoGetNextIrpStackLocation(Irp); \
645 \
646 TdiBuildBaseIrp(Irp, DevObj, FileObj, CompRoutine, \
647 Contxt, _IrpSp, TDI_QUERY_INFORMATION); \
648 \
649 _Request = (PTDI_REQUEST_KERNEL_QUERY_INFORMATION)&_IrpSp->Parameters; \
650 _Request->RequestConnectionInformation = NULL; \
651 _Request->QueryType = (ULONG)(QType); \
652 (Irp)->MdlAddress = (MdlAddr); \
653 }
654
655 /*
656 * VOID
657 * TdiBuildReceive(
658 * IN PIRP Irp,
659 * IN PDEVICE_OBJECT DevObj,
660 * IN PFILE_OBJECT FileObj,
661 * IN PVOID CompRoutine,
662 * IN PVOID Contxt,
663 * IN PMDL MdlAddr,
664 * IN ULONG InFlags,
665 * IN ULONG ReceiveLen);
666 */
667 #define TdiBuildReceive( \
668 Irp, DevObj, FileObj, CompRoutine, Contxt, \
669 MdlAddr, InFlags, ReceiveLen) \
670 { \
671 PTDI_REQUEST_KERNEL_RECEIVE _Request; \
672 PIO_STACK_LOCATION _IrpSp; \
673 \
674 _IrpSp = IoGetNextIrpStackLocation(Irp); \
675 \
676 TdiBuildBaseIrp(Irp, DevObj, FileObj, CompRoutine, \
677 Contxt, _IrpSp, TDI_RECEIVE); \
678 \
679 _Request = (PTDI_REQUEST_KERNEL_RECEIVE)&_IrpSp->Parameters; \
680 _Request->ReceiveFlags = (InFlags); \
681 _Request->ReceiveLength = (ReceiveLen); \
682 (Irp)->MdlAddress = (MdlAddr); \
683 }
684
685 /*
686 * VOID
687 * TdiBuildReceiveDatagram(
688 * IN PIRP Irp,
689 * IN PDEVICE_OBJECT DevObj,
690 * IN PFILE_OBJECT FileObj,
691 * IN PVOID CompRoutine,
692 * IN PVOID Contxt,
693 * IN PMDL MdlAddr,
694 * IN ULONG ReceiveLen,
695 * IN PTDI_CONNECTION_INFORMATION ReceiveDatagramInfo,
696 * OUT PTDI_CONNECTION_INFORMATION ReturnInfo,
697 * ULONG InFlags);
698 */
699 #define TdiBuildReceiveDatagram( \
700 Irp, DevObj, FileObj, CompRoutine, Contxt, MdlAddr, \
701 ReceiveLen, ReceiveDatagramInfo, ReturnInfo, InFlags) \
702 { \
703 PTDI_REQUEST_KERNEL_RECEIVEDG _Request; \
704 PIO_STACK_LOCATION _IrpSp; \
705 \
706 _IrpSp = IoGetNextIrpStackLocation(Irp); \
707 \
708 TdiBuildBaseIrp(Irp, DevObj, FileObj, CompRoutine, \
709 Contxt, _IrpSp, TDI_RECEIVE_DATAGRAM); \
710 \
711 _Request = (PTDI_REQUEST_KERNEL_RECEIVEDG)&_IrpSp->Parameters; \
712 _Request->ReceiveDatagramInformation = (ReceiveDatagramInfo); \
713 _Request->ReturnDatagramInformation = (ReturnInfo); \
714 _Request->ReceiveLength = (ReceiveLen); \
715 _Request->ReceiveFlags = (InFlags); \
716 (Irp)->MdlAddress = (MdlAddr); \
717 }
718
719 /*
720 * VOID
721 * TdiBuildSend(
722 * IN PIRP Irp,
723 * IN PDEVICE_OBJECT DevObj,
724 * IN PFILE_OBJECT FileObj,
725 * IN PVOID CompRoutine,
726 * IN PVOID Contxt,
727 * IN PMDL MdlAddr,
728 * IN ULONG InFlags,
729 * IN ULONG SendLen);
730 */
731 #define TdiBuildSend( \
732 Irp, DevObj, FileObj, CompRoutine, Contxt, \
733 MdlAddr, InFlags, SendLen) \
734 { \
735 PTDI_REQUEST_KERNEL_SEND _Request; \
736 PIO_STACK_LOCATION _IrpSp; \
737 \
738 _IrpSp = IoGetNextIrpStackLocation(Irp); \
739 \
740 TdiBuildBaseIrp(Irp, DevObj, FileObj, CompRoutine, \
741 Contxt, _IrpSp, TDI_SEND); \
742 \
743 _Request = (PTDI_REQUEST_KERNEL_SEND)&_IrpSp->Parameters; \
744 _Request->SendFlags = (InFlags); \
745 _Request->SendLength = (SendLen); \
746 (Irp)->MdlAddress = (MdlAddr); \
747 }
748
749 /*
750 * VOID
751 * TdiBuildSendDatagram(
752 * IN PIRP Irp,
753 * IN PDEVICE_OBJECT DevObj,
754 * IN PFILE_OBJECT FileObj,
755 * IN PVOID CompRoutine,
756 * IN PVOID Contxt,
757 * IN PMDL MdlAddr,
758 * IN ULONG SendLen,
759 * IN PTDI_CONNECTION_INFORMATION SendDatagramInfo);
760 */
761 #define TdiBuildSendDatagram( \
762 Irp, DevObj, FileObj, CompRoutine, Contxt, \
763 MdlAddr, SendLen, SendDatagramInfo) \
764 { \
765 PTDI_REQUEST_KERNEL_SENDDG _Request; \
766 PIO_STACK_LOCATION _IrpSp; \
767 \
768 _IrpSp = IoGetNextIrpStackLocation(Irp); \
769 \
770 TdiBuildBaseIrp(Irp, DevObj, FileObj, CompRoutine, \
771 Contxt, _IrpSp, TDI_SEND_DATAGRAM); \
772 \
773 _Request = (PTDI_REQUEST_KERNEL_SENDDG)&_IrpSp->Parameters; \
774 _Request->SendDatagramInformation = (SendDatagramInfo); \
775 _Request->SendLength = (SendLen); \
776 (Irp)->MdlAddress = (MdlAddr); \
777 }
778
779 /*
780 * VOID
781 * TdiBuildSetEventHandler(
782 * IN PIRP Irp,
783 * IN PDEVICE_OBJECT DevObj,
784 * IN PFILE_OBJECT FileObj,
785 * IN PVOID CompRoutine,
786 * IN PVOID Contxt,
787 * IN INT InEventType,
788 * IN PVOID InEventHandler,
789 * IN PVOID InEventContext);
790 */
791 #define TdiBuildSetEventHandler( \
792 Irp, DevObj, FileObj, CompRoutine, Contxt, \
793 InEventType, InEventHandler, InEventContext) \
794 { \
795 PTDI_REQUEST_KERNEL_SET_EVENT _Request; \
796 PIO_STACK_LOCATION _IrpSp; \
797 \
798 _IrpSp = IoGetNextIrpStackLocation(Irp); \
799 \
800 TdiBuildBaseIrp(Irp, DevObj, FileObj, CompRoutine, \
801 Contxt, _IrpSp, TDI_SET_EVENT_HANDLER); \
802 \
803 _Request = (PTDI_REQUEST_KERNEL_SET_EVENT)&_IrpSp->Parameters; \
804 _Request->EventType = (InEventType); \
805 _Request->EventHandler = (PVOID)(InEventHandler); \
806 _Request->EventContext = (PVOID)(InEventContext); \
807 }
808
809 /*
810 * VOID
811 * TdiBuildSetInformation(
812 * IN PIRP Irp,
813 * IN PDEVICE_OBJECT DevObj,
814 * IN PFILE_OBJECT FileObj,
815 * IN PVOID CompRoutine,
816 * IN PVOID Contxt,
817 * IN UINT SType,
818 * IN PMDL MdlAddr);
819 */
820 #define TdiBuildSetInformation( \
821 Irp, DevObj, FileObj, CompRoutine, Contxt, SType, MdlAddr) \
822 { \
823 PTDI_REQUEST_KERNEL_SET_INFORMATION _Request; \
824 PIO_STACK_LOCATION _IrpSp; \
825 \
826 _IrpSp = IoGetNextIrpStackLocation(Irp); \
827 \
828 TdiBuildBaseIrp(Irp, DevObj, FileObj, CompRoutine, \
829 Contxt, _IrpSp, TDI_SET_INFORMATION); \
830 \
831 _Request = (PTDI_REQUEST_KERNEL_SET_INFORMATION)&_IrpSp->Parameters; \
832 _Request->RequestConnectionInformation = NULL; \
833 _Request->SetType = (ULONG)(SType); \
834 (Irp)->MdlAddress = (MdlAddr); \
835 }
836
837 /* TDI20_CLIENT_INTERFACE_INFO.TdiVersion constants */
838 #define TDI_CURRENT_MAJOR_VERSION 2
839 #define TDI_CURRENT_MINOR_VERSION 0
840
841 #define TDI_CURRENT_VERSION ((TDI_CURRENT_MINOR_VERSION) << 8 \
842 | (TDI_CURRENT_MAJOR_VERSION))
843
844 #define TDI_VERSION_ONE 0x0001
845
846 typedef enum _TDI_PNP_OPCODE {
847 TDI_PNP_OP_MIN,
848 TDI_PNP_OP_ADD,
849 TDI_PNP_OP_DEL,
850 TDI_PNP_OP_UPDATE,
851 TDI_PNP_OP_PROVIDERREADY,
852 TDI_PNP_OP_NETREADY,
853 TDI_PNP_OP_ADD_IGNORE_BINDING,
854 TDI_PNP_OP_DELETE_IGNORE_BINDING,
855 TDI_PNP_OP_MAX
856 } TDI_PNP_OPCODE;
857
858 /* TDI_PNP_CONTEXT.ContextType */
859 #define TDI_PNP_CONTEXT_TYPE_IF_NAME 0x1
860 #define TDI_PNP_CONTEXT_TYPE_IF_ADDR 0x2
861 #define TDI_PNP_CONTEXT_TYPE_PDO 0x3
862 #define TDI_PNP_CONTEXT_TYPE_FIRST_OR_LAST_IF 0x4
863
864 typedef struct _TDI_PNP_CONTEXT {
865 USHORT ContextSize;
866 USHORT ContextType;
867 UCHAR ContextData[1];
868 } TDI_PNP_CONTEXT, *PTDI_PNP_CONTEXT;
869
870 typedef VOID
871 (NTAPI *TDI_ADD_ADDRESS_HANDLER)(
872 IN PTA_ADDRESS Address);
873
874 typedef VOID
875 (NTAPI *TDI_ADD_ADDRESS_HANDLER_V2)(
876 IN PTA_ADDRESS Address,
877 IN PUNICODE_STRING DeviceName,
878 IN PTDI_PNP_CONTEXT Context);
879
880 typedef VOID
881 (NTAPI *TDI_BINDING_HANDLER)(
882 IN TDI_PNP_OPCODE PnPOpcode,
883 IN PUNICODE_STRING DeviceName,
884 IN PWSTR MultiSZBindList);
885
886 typedef VOID
887 (NTAPI *TDI_BIND_HANDLER)(
888 IN PUNICODE_STRING DeviceName);
889
890 typedef VOID
891 (NTAPI *TDI_DEL_ADDRESS_HANDLER)(
892 IN PTA_ADDRESS Address);
893
894 typedef VOID
895 (NTAPI *TDI_DEL_ADDRESS_HANDLER_V2)(
896 IN PTA_ADDRESS Address,
897 IN PUNICODE_STRING DeviceName,
898 IN PTDI_PNP_CONTEXT Context);
899
900 typedef NTSTATUS
901 (NTAPI *TDI_PNP_POWER_HANDLER)(
902 IN PUNICODE_STRING DeviceName,
903 IN PNET_PNP_EVENT PowerEvent,
904 IN PTDI_PNP_CONTEXT Context1,
905 IN PTDI_PNP_CONTEXT Context2);
906
907 typedef VOID
908 (NTAPI *TDI_UNBIND_HANDLER)(
909 IN PUNICODE_STRING DeviceName);
910
911 typedef VOID
912 (NTAPI *ProviderPnPPowerComplete)(
913 IN PNET_PNP_EVENT NetEvent,
914 IN NTSTATUS ProviderStatus);
915
916 typedef struct _TDI20_CLIENT_INTERFACE_INFO {
917 _ANONYMOUS_UNION union {
918 _ANONYMOUS_STRUCT struct {
919 UCHAR MajorTdiVersion;
920 UCHAR MinorTdiVersion;
921 } DUMMYSTRUCTNAME;
922 USHORT TdiVersion;
923 } DUMMYUNIONNAME;
924 USHORT Unused;
925 PUNICODE_STRING ClientName;
926 TDI_PNP_POWER_HANDLER PnPPowerHandler;
927 _ANONYMOUS_UNION union {
928 TDI_BINDING_HANDLER BindingHandler;
929 _ANONYMOUS_STRUCT struct {
930 TDI_BIND_HANDLER BindHandler;
931 TDI_UNBIND_HANDLER UnBindHandler;
932 } DUMMYSTRUCTNAME;
933 }DUMMYUNIONNAME2;
934 _ANONYMOUS_UNION union {
935 _ANONYMOUS_STRUCT struct {
936 TDI_ADD_ADDRESS_HANDLER_V2 AddAddressHandlerV2;
937 TDI_DEL_ADDRESS_HANDLER_V2 DelAddressHandlerV2;
938 } DUMMYSTRUCTNAME;
939 _ANONYMOUS_STRUCT struct {
940 TDI_ADD_ADDRESS_HANDLER AddAddressHandler;
941 TDI_DEL_ADDRESS_HANDLER DelAddressHandler;
942 } DUMMYSTRUCTNAME2;
943 } DUMMYUNIONNAME3;
944 } TDI20_CLIENT_INTERFACE_INFO, *PTDI20_CLIENT_INTERFACE_INFO;
945
946 typedef TDI20_CLIENT_INTERFACE_INFO TDI_CLIENT_INTERFACE_INFO;
947 typedef TDI_CLIENT_INTERFACE_INFO *PTDI_CLIENT_INTERFACE_INFO;
948
949
950 /* TDI functions */
951
952 /*
953 * VOID
954 * TdiCompleteRequest(
955 * IN PIRP Irp,
956 * IN NTSTATUS Status);
957 */
958 #define TdiCompleteRequest(Irp, Status) \
959 { \
960 (Irp)->IoStatus.Status = (Status); \
961 IoCompleteRequest((Irp), IO_NETWORK_INCREMENT); \
962 }
963
964 TDIKRNLAPI
965 NTSTATUS
966 NTAPI
967 TdiCopyBufferToMdl(
968 IN PVOID SourceBuffer,
969 IN ULONG SourceOffset,
970 IN ULONG SourceBytesToCopy,
971 IN PMDL DestinationMdlChain,
972 IN ULONG DestinationOffset,
973 IN PULONG BytesCopied);
974
975 /*
976 * VOID
977 * TdiCopyLookaheadData(
978 * IN PVOID Destination,
979 * IN PVOID Source,
980 * IN ULONG Length,
981 * IN ULONG ReceiveFlags);
982 */
983 #define TdiCopyLookaheadData(Destination, Source, Length, ReceiveFlags) \
984 RtlCopyMemory(Destination, Source, Length)
985
986 TDIKRNLAPI
987 NTSTATUS
988 NTAPI
989 TdiCopyMdlChainToMdlChain (
990 IN PMDL SourceMdlChain,
991 IN ULONG SourceOffset,
992 IN PMDL DestinationMdlChain,
993 IN ULONG DestinationOffset,
994 OUT PULONG BytesCopied);
995
996 TDIKRNLAPI
997 NTSTATUS
998 NTAPI
999 TdiCopyMdlToBuffer(
1000 IN PMDL SourceMdlChain,
1001 IN ULONG SourceOffset,
1002 IN PVOID DestinationBuffer,
1003 IN ULONG DestinationOffset,
1004 IN ULONG DestinationBufferSize,
1005 OUT PULONG BytesCopied);
1006
1007 TDIKRNLAPI
1008 NTSTATUS
1009 NTAPI
1010 TdiDeregisterAddressChangeHandler(
1011 IN HANDLE BindingHandle);
1012
1013 TDIKRNLAPI
1014 NTSTATUS
1015 NTAPI
1016 TdiDeregisterDeviceObject(
1017 IN HANDLE DevRegistrationHandle);
1018
1019 TDIKRNLAPI
1020 NTSTATUS
1021 NTAPI
1022 TdiDeregisterNetAddress(
1023 IN HANDLE AddrRegistrationHandle);
1024
1025 TDIKRNLAPI
1026 NTSTATUS
1027 NTAPI
1028 TdiDeregisterPnPHandlers(
1029 IN HANDLE BindingHandle);
1030
1031 TDIKRNLAPI
1032 NTSTATUS
1033 NTAPI
1034 TdiDeregisterProvider(
1035 IN HANDLE ProviderHandle);
1036
1037 TDIKRNLAPI
1038 NTSTATUS
1039 NTAPI
1040 TdiEnumerateAddresses(
1041 IN HANDLE BindingHandle);
1042
1043 TDIKRNLAPI
1044 VOID
1045 NTAPI
1046 TdiInitialize(
1047 VOID);
1048
1049 TDIKRNLAPI
1050 VOID
1051 NTAPI
1052 TdiMapBuffer(
1053 IN PMDL MdlChain);
1054
1055 TDIKRNLAPI
1056 NTSTATUS
1057 NTAPI
1058 TdiMapUserRequest(
1059 IN PDEVICE_OBJECT DeviceObject,
1060 IN PIRP Irp,
1061 IN PIO_STACK_LOCATION IrpSp);
1062
1063 TDIKRNLAPI
1064 BOOLEAN
1065 NTAPI
1066 TdiMatchPdoWithChainedReceiveContext(
1067 IN PVOID TsduDescriptor,
1068 IN PVOID PDO);
1069
1070 TDIKRNLAPI
1071 VOID
1072 NTAPI
1073 TdiPnPPowerComplete(
1074 IN HANDLE BindingHandle,
1075 IN PNET_PNP_EVENT PowerEvent,
1076 IN NTSTATUS Status);
1077
1078 TDIKRNLAPI
1079 NTSTATUS
1080 NTAPI
1081 TdiPnPPowerRequest(
1082 IN PUNICODE_STRING DeviceName,
1083 IN PNET_PNP_EVENT PowerEvent,
1084 IN PTDI_PNP_CONTEXT Context1,
1085 IN PTDI_PNP_CONTEXT Context2,
1086 IN ProviderPnPPowerComplete ProtocolCompletionHandler);
1087
1088 TDIKRNLAPI
1089 NTSTATUS
1090 NTAPI
1091 TdiProviderReady(
1092 IN HANDLE ProviderHandle);
1093
1094 TDIKRNLAPI
1095 NTSTATUS
1096 NTAPI
1097 TdiRegisterAddressChangeHandler(
1098 IN TDI_ADD_ADDRESS_HANDLER AddHandler,
1099 IN TDI_DEL_ADDRESS_HANDLER DeleteHandler,
1100 OUT HANDLE *BindingHandle);
1101
1102 TDIKRNLAPI
1103 NTSTATUS
1104 NTAPI
1105 TdiRegisterDeviceObject(
1106 IN PUNICODE_STRING DeviceName,
1107 OUT HANDLE *DevRegistrationHandle);
1108
1109 TDIKRNLAPI
1110 NTSTATUS
1111 NTAPI
1112 TdiRegisterNetAddress(
1113 IN PTA_ADDRESS Address,
1114 IN PUNICODE_STRING DeviceName,
1115 IN PTDI_PNP_CONTEXT Context,
1116 OUT HANDLE *AddrRegistrationHandle);
1117
1118 TDIKRNLAPI
1119 NTSTATUS
1120 NTAPI
1121 TdiRegisterNotificationHandler(
1122 IN TDI_BIND_HANDLER BindHandler,
1123 IN TDI_UNBIND_HANDLER UnbindHandler,
1124 OUT HANDLE *BindingHandle);
1125
1126 TDIKRNLAPI
1127 NTSTATUS
1128 NTAPI
1129 TdiRegisterPnPHandlers(
1130 IN PTDI_CLIENT_INTERFACE_INFO ClientInterfaceInfo,
1131 IN ULONG InterfaceInfoSize,
1132 OUT HANDLE *BindingHandle);
1133
1134 TDIKRNLAPI
1135 NTSTATUS
1136 NTAPI
1137 TdiRegisterProvider(
1138 IN PUNICODE_STRING ProviderName,
1139 OUT HANDLE *ProviderHandle);
1140
1141 TDIKRNLAPI
1142 VOID
1143 NTAPI
1144 TdiReturnChainedReceives(
1145 IN PVOID *TsduDescriptors,
1146 IN ULONG NumberOfTsdus);
1147
1148 TDIKRNLAPI
1149 VOID
1150 NTAPI
1151 TdiUnmapBuffer(
1152 IN PMDL MdlChain);
1153
1154 #ifdef __cplusplus
1155 }
1156 #endif
1157
1158 #endif /* __TDIKRNL_H */