|
|
1.1 root 1: /*++
2:
3: Copyright (c) 1989 Microsoft Corporation
4:
5: Module Name:
6:
7: tdikrnl.h
8:
9: Abstract:
10:
11: This header file contains interface definitions for NT transport
12: providers running in kernel mode. This interface is documented in the
13: NT Transport Driver Interface (TDI) Specification, Version 2.
14:
15: Author:
16:
17: Dave Beaver (dbeaver) 20 June 1991
18:
19: Revision History:
20:
21: --*/
22:
23: #ifndef _TDI_KRNL_
24: #define _TDI_KRNL_
25:
26: #include <tdi.h> // get the user mode includes
27:
28: //
29: // In this TDI, a kernel mode client calls TDI using IoCallDriver with the
30: // current Irp stack pointer set to 16 bytes of pointers to other structures.
31: // each of the supported NtDeviceIoControlFile analogs has a somehat different
32: // structure, laid out below.
33: //
34: // The IrpSP information passed by kernel mode clients looks like:
35: //
36:
37: typedef struct _TDI_REQUEST_KERNEL {
38: ULONG RequestFlags;
39: PTDI_CONNECTION_INFORMATION RequestConnectionInformation;
40: PTDI_CONNECTION_INFORMATION ReturnConnectionInformation;
41: PVOID RequestSpecific;
42: } TDI_REQUEST_KERNEL, *PTDI_REQUEST_KERNEL;
43:
44: //
45: // defined request codes for the kernel clients. We make these the same
46: // as the IOCTL codes mostly for convenience; either can be used with
47: // the same results.
48: //
49:
50: #define TDI_ASSOCIATE_ADDRESS (0x01)
51: #define TDI_DISASSOCIATE_ADDRESS (0x02)
52: #define TDI_CONNECT (0x03)
53: #define TDI_LISTEN (0x04)
54: #define TDI_ACCEPT (0x05)
55: #define TDI_DISCONNECT (0x06)
56: #define TDI_SEND (0x07)
57: #define TDI_RECEIVE (0x08)
58: #define TDI_SEND_DATAGRAM (0x09)
59: #define TDI_RECEIVE_DATAGRAM (0x0A)
60: #define TDI_SET_EVENT_HANDLER (0x0B)
61: #define TDI_QUERY_INFORMATION (0x0C)
62: #define TDI_SET_INFORMATION (0x0D)
63: #define TDI_ACTION (0x0E)
64:
65: //
66: // TdiOpenAddress (Not Used)
67: // TdiCloseAddress (Not Used)
68: // TdiOpenConnection (Not Used)
69: // TdiCloseConnection (Not Used)
70: //
71:
72: //
73: // some useful constants for comparison when determining the file type;
74: // not required.
75: //
76:
77: #define TDI_TRANSPORT_ADDRESS_FILE 1
78: #define TDI_CONNECTION_FILE 2
79: #define TDI_CONTROL_CHANNEL_FILE 3
80:
81: //
82: // TdiAssociateAddress
83: //
84:
85: typedef struct _TDI_REQUEST_KERNEL_ASSOCIATE {
86: HANDLE AddressHandle;
87: } TDI_REQUEST_KERNEL_ASSOCIATE, *PTDI_REQUEST_KERNEL_ASSOCIATE;
88:
89: //
90: // TdiDisassociateAddress -- None supplied
91: //
92:
93: typedef TDI_REQUEST_KERNEL TDI_REQUEST_KERNEL_DISASSOCIATE,
94: *PTDI_REQUEST_KERNEL_DISASSOCIATE;
95:
96: //
97: // TdiConnect uses the structure given above (TDI_REQUEST_KERNEL); it's
98: // defined again below for convenience
99: //
100:
101: typedef TDI_REQUEST_KERNEL TDI_REQUEST_KERNEL_CONNECT,
102: *PTDI_REQUEST_KERNEL_CONNECT;
103:
104: //
105: // TdiDisconnect uses the structure given above (TDI_REQUEST_KERNEL); it's
106: // defined again below for convenience
107: //
108:
109: typedef TDI_REQUEST_KERNEL TDI_REQUEST_KERNEL_DISCONNECT,
110: *PTDI_REQUEST_KERNEL_DISCONNECT;
111:
112: //
113: // TdiListen uses the structure given above (TDI_REQUEST_KERNEL); it's
114: // defined again below for convenience
115: //
116:
117: typedef TDI_REQUEST_KERNEL TDI_REQUEST_KERNEL_LISTEN,
118: *PTDI_REQUEST_KERNEL_LISTEN;
119:
120: //
121: // TdiAccept
122: //
123:
124: typedef struct _TDI_REQUEST_KERNEL_ACCEPT {
125: PTDI_CONNECTION_INFORMATION RequestConnectionInformation;
126: PTDI_CONNECTION_INFORMATION ReturnConnectionInformation;
127: } TDI_REQUEST_KERNEL_ACCEPT, *PTDI_REQUEST_KERNEL_ACCEPT;
128:
129: //
130: // TdiSend
131: //
132:
133: typedef struct _TDI_REQUEST_KERNEL_SEND {
134: ULONG SendLength;
135: ULONG SendFlags;
136: } TDI_REQUEST_KERNEL_SEND, *PTDI_REQUEST_KERNEL_SEND;
137:
138: //
139: // TdiReceive
140: //
141:
142: typedef struct _TDI_REQUEST_KERNEL_RECEIVE {
143: ULONG ReceiveLength;
144: ULONG ReceiveFlags;
145: } TDI_REQUEST_KERNEL_RECEIVE, *PTDI_REQUEST_KERNEL_RECEIVE;
146:
147: //
148: // TdiSendDatagram
149: //
150:
151: typedef struct _TDI_REQUEST_KERNEL_SENDDG {
152: ULONG SendLength;
153: PTDI_CONNECTION_INFORMATION SendDatagramInformation;
154: } TDI_REQUEST_KERNEL_SENDDG, *PTDI_REQUEST_KERNEL_SENDDG;
155:
156: //
157: // TdiReceiveDatagram
158: //
159:
160: typedef struct _TDI_REQUEST_KERNEL_RECEIVEDG {
161: ULONG ReceiveLength;
162: PTDI_CONNECTION_INFORMATION ReceiveDatagramInformation;
163: PTDI_CONNECTION_INFORMATION ReturnDatagramInformation;
164: ULONG ReceiveFlags;
165: } TDI_REQUEST_KERNEL_RECEIVEDG, *PTDI_REQUEST_KERNEL_RECEIVEDG;
166:
167: //
168: // TdiSetEventHandler
169: //
170:
171: typedef struct _TDI_REQUEST_KERNEL_SET_EVENT {
172: int EventType;
173: PVOID EventHandler;
174: PVOID EventContext;
175: } TDI_REQUEST_KERNEL_SET_EVENT, *PTDI_REQUEST_KERNEL_SET_EVENT;
176:
177: //
178: // TdiQueryInformation
179: //
180:
181: typedef struct _TDI_REQUEST_KERNEL_QUERY_INFO {
182: int QueryType;
183: PTDI_CONNECTION_INFORMATION RequestConnectionInformation;
184: } TDI_REQUEST_KERNEL_QUERY_INFORMATION, *PTDI_REQUEST_KERNEL_QUERY_INFORMATION;
185:
186: //
187: // TdiSetInformation
188: //
189:
190: typedef struct _TDI_REQUEST_KERNEL_SET_INFO {
191: int SetType;
192: PTDI_CONNECTION_INFORMATION RequestConnectionInformation;
193: } TDI_REQUEST_KERNEL_SET_INFORMATION, *PTDI_REQUEST_KERNEL_SET_INFORMATION;
194:
195: //
196: // Event types that are known
197: //
198:
199: #define TDI_EVENT_CONNECT ((USHORT)0) // TDI_IND_CONNECT event handler.
200: #define TDI_EVENT_DISCONNECT ((USHORT)1) // TDI_IND_DISCONNECT event handler.
201: #define TDI_EVENT_ERROR ((USHORT)2) // TDI_IND_ERROR event handler.
202: #define TDI_EVENT_RECEIVE ((USHORT)3) // TDI_IND_RECEIVE event handler.
203: #define TDI_EVENT_RECEIVE_DATAGRAM ((USHORT)4) // TDI_IND_RECEIVE_DATAGRAM event handler.
204: #define TDI_EVENT_RECEIVE_EXPEDITED ((USHORT)5) // TDI_IND_RECEIVE_EXPEDITED event handler.
205: #define TDI_EVENT_SEND_POSSIBLE ((USHORT)6) // TDI_IND_SEND_POSSIBLE event handler
206:
207: //
208: // indicate connection event prototype. This is invoked when a request for
209: // connection has been received by the provider and the user wishes to either
210: // accept or reject that request.
211: //
212:
213: typedef
214: NTSTATUS
215: (*PTDI_IND_CONNECT)(
216: IN PVOID TdiEventContext,
217: IN int RemoteAddressLength,
218: IN PVOID RemoteAddress,
219: IN int UserDataLength,
220: IN PVOID UserData,
221: IN int OptionsLength,
222: IN PVOID Options,
223: OUT CONNECTION_CONTEXT *ConnectionContext,
224: OUT PIRP *AcceptIrp
225: )
226: ;
227:
228: NTSTATUS
229: TdiDefaultConnectHandler (
230: IN PVOID TdiEventContext,
231: IN int RemoteAddressLength,
232: IN PVOID RemoteAddress,
233: IN int UserDataLength,
234: IN PVOID UserData,
235: IN int OptionsLength,
236: IN PVOID Options,
237: OUT CONNECTION_CONTEXT *ConnectionContext,
238: OUT PIRP *AcceptIrp
239: );
240:
241: //
242: // Disconnection indication prototype. This is invoked when a connection is
243: // being disconnected for a reason other than the user requesting it. Note that
244: // this is a change from TDI V1, which indicated only when the remote caused
245: // a disconnection. Any non-directed disconnection will cause this indication.
246: //
247:
248: typedef
249: NTSTATUS
250: (*PTDI_IND_DISCONNECT)(
251: IN PVOID TdiEventContext,
252: IN CONNECTION_CONTEXT ConnectionContext,
253: IN int DisconnectDataLength,
254: IN PVOID DisconnectData,
255: IN int DisconnectInformationLength,
256: IN PVOID DisconnectInformation,
257: IN ULONG DisconnectFlags
258: );
259:
260: NTSTATUS
261: TdiDefaultDisconnectHandler (
262: IN PVOID TdiEventContext,
263: IN CONNECTION_CONTEXT ConnectionContext,
264: IN int DisconnectDataLength,
265: IN PVOID DisconnectData,
266: IN int DisconnectInformationLength,
267: IN PVOID DisconnectInformation,
268: IN ULONG DisconnectFlags
269: );
270:
271: //
272: // A protocol error has occurred when this indication happens. This indication
273: // occurs only for errors of the worst type; the address this indication is
274: // delivered to is no longer usable for protocol-related operations, and
275: // should not be used for operations henceforth. All connections associated
276: // it are invalid.
277: // For NetBIOS-type providers, this indication is also delivered when a name
278: // in conflict or duplicate name occurs.
279: //
280:
281: typedef
282: NTSTATUS
283: (*PTDI_IND_ERROR)(
284: IN PVOID TdiEventContext, // the endpoint's file object.
285: IN NTSTATUS Status // status code indicating error type.
286: );
287:
288: NTSTATUS
289: TdiDefaultErrorHandler (
290: IN PVOID TdiEventContext, // the endpoint's file object.
291: IN NTSTATUS Status // status code indicating error type.
292: );
293:
294: //
295: // TDI_IND_RECEIVE indication handler definition. This client routine is
296: // called by the transport provider when a connection-oriented TSDU is received
297: // that should be presented to the client.
298: //
299:
300: typedef
301: NTSTATUS
302: (*PTDI_IND_RECEIVE)(
303: IN PVOID TdiEventContext,
304: IN CONNECTION_CONTEXT ConnectionContext,
305: IN ULONG ReceiveFlags,
306: IN ULONG BytesIndicated,
307: IN ULONG BytesAvailable,
308: OUT ULONG *BytesTaken,
309: IN PVOID Tsdu, // pointer describing this TSDU, typically a lump of bytes
310: OUT PIRP *IoRequestPacket // TdiReceive IRP if MORE_PROCESSING_REQUIRED.
311: );
312:
313: NTSTATUS
314: TdiDefaultReceiveHandler (
315: IN PVOID TdiEventContext,
316: IN CONNECTION_CONTEXT ConnectionContext,
317: IN ULONG ReceiveFlags,
318: IN ULONG BytesIndicated,
319: IN ULONG BytesAvailable,
320: OUT ULONG *BytesTaken,
321: IN PVOID Tsdu, // pointer describing this TSDU, typically a lump of bytes
322: OUT PIRP *IoRequestPacket // TdiReceive IRP if MORE_PROCESSING_REQUIRED.
323: );
324:
325: //
326: // TDI_IND_RECEIVE_DATAGRAM indication handler definition. This client routine
327: // is called by the transport provider when a connectionless TSDU is received
328: // that should be presented to the client.
329: //
330:
331: typedef
332: NTSTATUS
333: (*PTDI_IND_RECEIVE_DATAGRAM)(
334: IN PVOID TdiEventContext, // the event context
335: IN int SourceAddressLength, // length of the originator of the datagram
336: IN PVOID SourceAddress, // string describing the originator of the datagram
337: IN int OptionsLength, // options for the receive
338: IN PVOID Options, //
339: IN ULONG ReceiveDatagramFlags, //
340: IN ULONG BytesIndicated, // number of bytes this indication
341: IN ULONG BytesAvailable, // number of bytes in complete Tsdu
342: OUT ULONG *BytesTaken, // number of bytes used
343: IN PVOID Tsdu, // pointer describing this TSDU, typically a lump of bytes
344: OUT PIRP *IoRequestPacket // TdiReceive IRP if MORE_PROCESSING_REQUIRED.
345: );
346:
347: NTSTATUS
348: TdiDefaultRcvDatagramHandler (
349: IN PVOID TdiEventContext, // the event context
350: IN int SourceAddressLength, // length of the originator of the datagram
351: IN PVOID SourceAddress, // string describing the originator of the datagram
352: IN int OptionsLength, // options for the receive
353: IN PVOID Options, //
354: IN ULONG ReceiveDatagramFlags, //
355: IN ULONG BytesIndicated, // number of bytes this indication
356: IN ULONG BytesAvailable, // number of bytes in complete Tsdu
357: OUT ULONG *BytesTaken, // number of bytes used
358: IN PVOID Tsdu, // pointer describing this TSDU, typically a lump of bytes
359: OUT PIRP *IoRequestPacket // TdiReceive IRP if MORE_PROCESSING_REQUIRED.
360: );
361:
362: //
363: // This indication is delivered if expedited data is received on the connection.
364: // This will only occur in providers that support expedited data.
365: //
366:
367: typedef
368: NTSTATUS
369: (*PTDI_IND_RECEIVE_EXPEDITED)(
370: IN PVOID TdiEventContext,
371: IN CONNECTION_CONTEXT ConnectionContext,
372: IN ULONG ReceiveFlags, //
373: IN ULONG BytesIndicated, // number of bytes in this indication
374: IN ULONG BytesAvailable, // number of bytes in complete Tsdu
375: OUT ULONG *BytesTaken, // number of bytes used by indication routine
376: IN PVOID Tsdu, // pointer describing this TSDU, typically a lump of bytes
377: OUT PIRP *IoRequestPacket // TdiReceive IRP if MORE_PROCESSING_REQUIRED.
378: );
379:
380: NTSTATUS
381: TdiDefaultRcvExpeditedHandler (
382: IN PVOID TdiEventContext,
383: IN CONNECTION_CONTEXT ConnectionContext,
384: IN ULONG ReceiveFlags, //
385: IN ULONG BytesIndicated, // number of bytes in this indication
386: IN ULONG BytesAvailable, // number of bytes in complete Tsdu
387: OUT ULONG *BytesTaken, // number of bytes used by indication routine
388: IN PVOID Tsdu, // pointer describing this TSDU, typically a lump of bytes
389: OUT PIRP *IoRequestPacket // TdiReceive IRP if MORE_PROCESSING_REQUIRED.
390: );
391:
392: //
393: // This indication is delivered if there is room for a send in the buffer of
394: // a buffering protocol.
395: //
396:
397: typedef
398: NTSTATUS
399: (*PTDI_IND_SEND_POSSIBLE)(
400: IN PVOID TdiEventContext,
401: IN PVOID ConnectionContext,
402: IN ULONG BytesAvailable);
403:
404: NTSTATUS
405: TdiDefaultSendPossibleHandler (
406: IN PVOID TdiEventContext,
407: IN PVOID ConnectionContext,
408: IN ULONG BytesAvailable);
409:
410: //
411: // defined MACROS to allow the kernel mode client to easily build an IRP for
412: // any function.
413: //
414:
415: #define TdiBuildAssociateAddress(Irp, DevObj, FileObj, CompRoutine, Contxt, AddrHandle) \
416: { \
417: PTDI_REQUEST_KERNEL_ASSOCIATE p; \
418: PIO_STACK_LOCATION _IRPSP; \
419: if ( CompRoutine != NULL) { \
420: IoSetCompletionRoutine( Irp, CompRoutine, Contxt, TRUE, TRUE, TRUE);\
421: } else { \
422: IoSetCompletionRoutine( Irp, NULL, NULL, FALSE, FALSE, FALSE); \
423: } \
424: _IRPSP = IoGetNextIrpStackLocation (Irp); \
425: _IRPSP->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL; \
426: _IRPSP->MinorFunction = TDI_ASSOCIATE_ADDRESS; \
427: _IRPSP->DeviceObject = DevObj; \
428: _IRPSP->FileObject = FileObj; \
429: p = (PTDI_REQUEST_KERNEL_ASSOCIATE)&_IRPSP->Parameters; \
430: p->AddressHandle = (HANDLE)(AddrHandle); \
431: }
432:
433: #define TdiBuildDisassociateAddress(Irp, DevObj, FileObj, CompRoutine, Contxt) \
434: { \
435: PTDI_REQUEST_KERNEL_DISASSOCIATE p; \
436: PIO_STACK_LOCATION _IRPSP; \
437: if ( CompRoutine != NULL) { \
438: IoSetCompletionRoutine( Irp, CompRoutine, Contxt, TRUE, TRUE, TRUE);\
439: } else { \
440: IoSetCompletionRoutine( Irp, NULL, NULL, FALSE, FALSE, FALSE); \
441: } \
442: _IRPSP = IoGetNextIrpStackLocation (Irp); \
443: _IRPSP->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL; \
444: _IRPSP->MinorFunction = TDI_DISASSOCIATE_ADDRESS; \
445: _IRPSP->DeviceObject = DevObj; \
446: _IRPSP->FileObject = FileObj; \
447: p = (PTDI_REQUEST_KERNEL_DISASSOCIATE)&_IRPSP->Parameters; \
448: }
449:
450: #define TdiBuildConnect(Irp, DevObj, FileObj, CompRoutine, Contxt, Time, RequestConnectionInfo, ReturnConnectionInfo)\
451: { \
452: PTDI_REQUEST_KERNEL p; \
453: PIO_STACK_LOCATION _IRPSP; \
454: if ( CompRoutine != NULL) { \
455: IoSetCompletionRoutine( Irp, CompRoutine, Contxt, TRUE, TRUE, TRUE);\
456: } else { \
457: IoSetCompletionRoutine( Irp, NULL, NULL, FALSE, FALSE, FALSE); \
458: } \
459: _IRPSP = IoGetNextIrpStackLocation (Irp); \
460: _IRPSP->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL; \
461: _IRPSP->MinorFunction = TDI_CONNECT; \
462: _IRPSP->DeviceObject = DevObj; \
463: _IRPSP->FileObject = FileObj; \
464: p = (PTDI_REQUEST_KERNEL)&_IRPSP->Parameters; \
465: p->RequestConnectionInformation = RequestConnectionInfo; \
466: p->ReturnConnectionInformation = ReturnConnectionInfo; \
467: p->RequestSpecific = (PVOID)Time; \
468: }
469:
470: #define TdiBuildListen(Irp, DevObj, FileObj, CompRoutine, Contxt, Flags, RequestConnectionInfo, ReturnConnectionInfo)\
471: { \
472: PTDI_REQUEST_KERNEL p; \
473: PIO_STACK_LOCATION _IRPSP; \
474: if ( CompRoutine != NULL) { \
475: IoSetCompletionRoutine( Irp, CompRoutine, Contxt, TRUE, TRUE, TRUE);\
476: } else { \
477: IoSetCompletionRoutine( Irp, NULL, NULL, FALSE, FALSE, FALSE); \
478: } \
479: _IRPSP = IoGetNextIrpStackLocation (Irp); \
480: _IRPSP->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL; \
481: _IRPSP->MinorFunction = TDI_LISTEN; \
482: _IRPSP->DeviceObject = DevObj; \
483: _IRPSP->FileObject = FileObj; \
484: p = (PTDI_REQUEST_KERNEL)&_IRPSP->Parameters; \
485: p->RequestFlags = Flags; \
486: p->RequestConnectionInformation = RequestConnectionInfo; \
487: p->ReturnConnectionInformation = ReturnConnectionInfo; \
488: }
489:
490: #define TdiBuildAccept(Irp, DevObj, FileObj, CompRoutine, Contxt, RequestConnectionInfo, ReturnConnectionInfo)\
491: { \
492: PTDI_REQUEST_KERNEL_ACCEPT p; \
493: PIO_STACK_LOCATION _IRPSP; \
494: if ( CompRoutine != NULL) { \
495: IoSetCompletionRoutine( Irp, CompRoutine, Contxt, TRUE, TRUE, TRUE);\
496: } else { \
497: IoSetCompletionRoutine( Irp, NULL, NULL, FALSE, FALSE, FALSE); \
498: } \
499: _IRPSP = IoGetNextIrpStackLocation (Irp); \
500: _IRPSP->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL; \
501: _IRPSP->MinorFunction = TDI_ACCEPT; \
502: _IRPSP->DeviceObject = DevObj; \
503: _IRPSP->FileObject = FileObj; \
504: p = (PTDI_REQUEST_KERNEL_ACCEPT)&_IRPSP->Parameters; \
505: p->RequestConnectionInformation = RequestConnectionInfo; \
506: p->ReturnConnectionInformation = ReturnConnectionInfo; \
507: }
508:
509: #define TdiBuildDisconnect(Irp, DevObj, FileObj, CompRoutine, Contxt, Time, Flags, RequestConnectionInfo, ReturnConnectionInfo)\
510: { \
511: PTDI_REQUEST_KERNEL p; \
512: PIO_STACK_LOCATION _IRPSP; \
513: if ( CompRoutine != NULL) { \
514: IoSetCompletionRoutine( Irp, CompRoutine, Contxt, TRUE, TRUE, TRUE);\
515: } else { \
516: IoSetCompletionRoutine( Irp, NULL, NULL, FALSE, FALSE, FALSE); \
517: } \
518: _IRPSP = IoGetNextIrpStackLocation (Irp); \
519: _IRPSP->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL; \
520: _IRPSP->MinorFunction = TDI_DISCONNECT; \
521: _IRPSP->DeviceObject = DevObj; \
522: _IRPSP->FileObject = FileObj; \
523: p = (PTDI_REQUEST_KERNEL)&_IRPSP->Parameters; \
524: p->RequestFlags = Flags; \
525: p->RequestConnectionInformation = RequestConnectionInfo; \
526: p->ReturnConnectionInformation = ReturnConnectionInfo; \
527: p->RequestSpecific = (PVOID)Time; \
528: }
529:
530: #define TdiBuildReceive(Irp, DevObj, FileObj, CompRoutine, Contxt, MdlAddr, InFlags, ReceiveLen)\
531: { \
532: PTDI_REQUEST_KERNEL_RECEIVE p; \
533: PIO_STACK_LOCATION _IRPSP; \
534: if ( CompRoutine != NULL) { \
535: IoSetCompletionRoutine( Irp, CompRoutine, Contxt, TRUE, TRUE, TRUE);\
536: } else { \
537: IoSetCompletionRoutine( Irp, NULL, NULL, FALSE, FALSE, FALSE); \
538: } \
539: _IRPSP = IoGetNextIrpStackLocation (Irp); \
540: _IRPSP->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL; \
541: _IRPSP->MinorFunction = TDI_RECEIVE; \
542: _IRPSP->DeviceObject = DevObj; \
543: _IRPSP->FileObject = FileObj; \
544: p = (PTDI_REQUEST_KERNEL_RECEIVE)&_IRPSP->Parameters; \
545: p->ReceiveFlags = InFlags; \
546: p->ReceiveLength = ReceiveLen; \
547: Irp->MdlAddress = MdlAddr; \
548: }
549:
550: #define TdiBuildSend(Irp, DevObj, FileObj, CompRoutine, Contxt, MdlAddr, InFlags, SendLen)\
551: { \
552: PTDI_REQUEST_KERNEL_SEND p; \
553: PIO_STACK_LOCATION _IRPSP; \
554: if ( CompRoutine != NULL) { \
555: IoSetCompletionRoutine( Irp, CompRoutine, Contxt, TRUE, TRUE, TRUE);\
556: } else { \
557: IoSetCompletionRoutine( Irp, NULL, NULL, FALSE, FALSE, FALSE); \
558: } \
559: _IRPSP = IoGetNextIrpStackLocation (Irp); \
560: _IRPSP->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL; \
561: _IRPSP->MinorFunction = TDI_SEND; \
562: _IRPSP->DeviceObject = DevObj; \
563: _IRPSP->FileObject = FileObj; \
564: p = (PTDI_REQUEST_KERNEL_SEND)&_IRPSP->Parameters; \
565: p->SendFlags = InFlags; \
566: p->SendLength = SendLen; \
567: Irp->MdlAddress = MdlAddr; \
568: }
569:
570: #define TdiBuildSendDatagram(Irp, DevObj, FileObj, CompRoutine, Contxt, MdlAddr, SendLen, SendDatagramInfo)\
571: { \
572: PTDI_REQUEST_KERNEL_SENDDG p; \
573: PIO_STACK_LOCATION _IRPSP; \
574: if ( CompRoutine != NULL) { \
575: IoSetCompletionRoutine( Irp, CompRoutine, Contxt, TRUE, TRUE, TRUE);\
576: } else { \
577: IoSetCompletionRoutine( Irp, NULL, NULL, FALSE, FALSE, FALSE); \
578: } \
579: _IRPSP = IoGetNextIrpStackLocation (Irp); \
580: _IRPSP->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL; \
581: _IRPSP->MinorFunction = TDI_SEND_DATAGRAM; \
582: _IRPSP->DeviceObject = DevObj; \
583: _IRPSP->FileObject = FileObj; \
584: p = (PTDI_REQUEST_KERNEL_SENDDG)&_IRPSP->Parameters; \
585: p->SendLength = SendLen; \
586: p->SendDatagramInformation = SendDatagramInfo; \
587: Irp->MdlAddress = MdlAddr; \
588: }
589:
590: #define TdiBuildReceiveDatagram(Irp, DevObj, FileObj, CompRoutine, Contxt, MdlAddr, ReceiveLen, ReceiveDatagramInfo, ReturnInfo, InFlags)\
591: { \
592: PTDI_REQUEST_KERNEL_RECEIVEDG p; \
593: PIO_STACK_LOCATION _IRPSP; \
594: if ( CompRoutine != NULL) { \
595: IoSetCompletionRoutine( Irp, CompRoutine, Contxt, TRUE, TRUE, TRUE);\
596: } else { \
597: IoSetCompletionRoutine( Irp, NULL, NULL, FALSE, FALSE, FALSE); \
598: } \
599: _IRPSP = IoGetNextIrpStackLocation (Irp); \
600: _IRPSP->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL; \
601: _IRPSP->MinorFunction = TDI_RECEIVE_DATAGRAM; \
602: _IRPSP->DeviceObject = DevObj; \
603: _IRPSP->FileObject = FileObj; \
604: p = (PTDI_REQUEST_KERNEL_RECEIVEDG)&_IRPSP->Parameters; \
605: p->ReceiveLength = ReceiveLen; \
606: p->ReceiveDatagramInformation = ReceiveDatagramInfo; \
607: p->ReturnDatagramInformation = ReturnInfo; \
608: p->ReceiveFlags = InFlags; \
609: Irp->MdlAddress = MdlAddr; \
610: }
611:
612: #define TdiBuildSetEventHandler(Irp, DevObj, FileObj, CompRoutine, Contxt, InEventType, InEventHandler, InEventContext) \
613: { \
614: PTDI_REQUEST_KERNEL_SET_EVENT p; \
615: PIO_STACK_LOCATION _IRPSP; \
616: if ( CompRoutine != NULL) { \
617: IoSetCompletionRoutine( Irp, CompRoutine, Contxt, TRUE, TRUE, TRUE);\
618: } else { \
619: IoSetCompletionRoutine( Irp, NULL, NULL, FALSE, FALSE, FALSE); \
620: } \
621: _IRPSP = IoGetNextIrpStackLocation (Irp); \
622: _IRPSP->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL; \
623: _IRPSP->MinorFunction = TDI_SET_EVENT_HANDLER; \
624: _IRPSP->DeviceObject = DevObj; \
625: _IRPSP->FileObject = FileObj; \
626: p = (PTDI_REQUEST_KERNEL_SET_EVENT)&_IRPSP->Parameters; \
627: p->EventType = InEventType; \
628: p->EventHandler = (PVOID)InEventHandler; \
629: p->EventContext = (PVOID)InEventContext; \
630: }
631:
632: #define TdiBuildQueryInformation(Irp, DevObj, FileObj, CompRoutine, Contxt, QType, MdlAddr)\
633: { \
634: PTDI_REQUEST_KERNEL_QUERY_INFORMATION p; \
635: PIO_STACK_LOCATION _IRPSP; \
636: Irp->MdlAddress = MdlAddr; \
637: if ( CompRoutine != NULL) { \
638: IoSetCompletionRoutine( Irp, CompRoutine, Contxt, TRUE, TRUE, TRUE);\
639: } else { \
640: IoSetCompletionRoutine( Irp, NULL, NULL, FALSE, FALSE, FALSE); \
641: } \
642: _IRPSP = IoGetNextIrpStackLocation (Irp); \
643: _IRPSP->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL; \
644: _IRPSP->MinorFunction = TDI_QUERY_INFORMATION; \
645: _IRPSP->DeviceObject = DevObj; \
646: _IRPSP->FileObject = FileObj; \
647: p = (PTDI_REQUEST_KERNEL_QUERY_INFORMATION)&_IRPSP->Parameters; \
648: p->QueryType = (ULONG)QType; \
649: p->RequestConnectionInformation = NULL; \
650: }
651:
652:
653: #define TdiBuildSetInformation(Irp, DevObj, FileObj, CompRoutine, Contxt, SType, MdlAddr)\
654: { \
655: PTDI_REQUEST_KERNEL_SET_INFORMATION p; \
656: PIO_STACK_LOCATION _IRPSP; \
657: Irp->MdlAddress = MdlAddr; \
658: if ( CompRoutine != NULL) { \
659: IoSetCompletionRoutine( Irp, CompRoutine, Contxt, TRUE, TRUE, TRUE);\
660: } else { \
661: IoSetCompletionRoutine( Irp, NULL, NULL, FALSE, FALSE, FALSE); \
662: } \
663: _IRPSP = IoGetNextIrpStackLocation (Irp); \
664: _IRPSP->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL; \
665: _IRPSP->MinorFunction = TDI_SET_INFORMATION; \
666: _IRPSP->DeviceObject = DevObj; \
667: _IRPSP->FileObject = FileObj; \
668: p = (PTDI_REQUEST_KERNEL_SET_INFORMATION)&_IRPSP->Parameters; \
669: p->SetType = (ULONG)SType; \
670: p->RequestConnectionInformation = NULL; \
671: }
672:
673: #define TdiBuildAction(Irp, DevObj, FileObj, CompRoutine, Contxt, MdlAddr)\
674: { \
675: PIO_STACK_LOCATION _IRPSP; \
676: if ( CompRoutine != NULL) { \
677: IoSetCompletionRoutine( Irp, CompRoutine, Contxt, TRUE, TRUE, TRUE);\
678: } else { \
679: IoSetCompletionRoutine( Irp, NULL, NULL, FALSE, FALSE, FALSE); \
680: } \
681: _IRPSP = IoGetNextIrpStackLocation (Irp); \
682: _IRPSP->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL; \
683: _IRPSP->MinorFunction = TDI_ACTION; \
684: _IRPSP->DeviceObject = DevObj; \
685: _IRPSP->FileObject = FileObj; \
686: Irp->MdlAddress = MdlAddr; \
687: }
688:
689: //
690: // definitions for the helper routines for TDI compliant transports and clients
691: //
692: // Note that the IOCTL used here for the Irp Function is not real; it is used
693: // to avoid this IO routine having to map buffers (which we don't want).
694: //
695: //PIRP
696: //TdiBuildInternalDeviceControlIrp (
697: // IN CCHAR IrpSubFunction,
698: // IN PDEVICE_OBJECT DeviceObject,
699: // IN PFILE_OBJECT FileObject,
700: // IN PKEVENT Event,
701: // IN PIO_STATUS_BLOCK IoStatusBlock
702: // );
703:
704: #define TdiBuildInternalDeviceControlIrp(IrpSubFunction,DeviceObject,FileObject,Event,IoStatusBlock) \
705: IoBuildDeviceIoControlRequest (\
706: 0x00000003,\
707: DeviceObject, \
708: NULL, \
709: 0, \
710: NULL, \
711: 0, \
712: TRUE, \
713: Event, \
714: IoStatusBlock)
715:
716:
717: //
718: // VOID
719: // TdiCopyLookaheadData(
720: // IN PVOID Destination,
721: // IN PVOID Source,
722: // IN ULONG Length,
723: // IN ULONG ReceiveFlags
724: // );
725: //
726:
727: #ifdef _M_IX86
728: #define TdiCopyLookaheadData(_Destination,_Source,_Length,_ReceiveFlags) \
729: RtlCopyMemory(_Destination,_Source,_Length)
730: #else
731: #define TdiCopyLookaheadData(_Destination,_Source,_Length,_ReceiveFlags) { \
732: if ((_ReceiveFlags) & TDI_RECEIVE_COPY_LOOKAHEAD) { \
733: RtlCopyMemory(_Destination,_Source,_Length); \
734: } else { \
735: PUCHAR _Src = (_Source); \
736: PUCHAR _Dest = (_Destination); \
737: PUCHAR _End = _Dest + (_Length); \
738: while (_Dest < _End) { \
739: *_Dest++ = *_Src++; \
740: } \
741: } \
742: }
743: #endif
744:
745:
746: NTSTATUS
747: TdiMapUserRequest(
748: IN PDEVICE_OBJECT DeviceObject,
749: IN PIRP Irp,
750: IN PIO_STACK_LOCATION IrpSp
751: );
752:
753: VOID
754: TdiMapBuffer (
755: IN PMDL MdlChain
756: );
757:
758: VOID
759: TdiUnmapBuffer (
760: IN PMDL MdlChain
761: );
762:
763: NTSTATUS
764: TdiCopyBufferToMdl (
765: IN PVOID SourceBuffer,
766: IN ULONG SourceOffset,
767: IN ULONG SourceBytesToCopy,
768: IN PMDL DestinationMdlChain,
769: IN ULONG DestinationOffset,
770: IN PULONG BytesCopied
771: );
772:
773: NTSTATUS
774: TdiCopyMdlToBuffer(
775: IN PMDL SourceMdlChain,
776: IN ULONG SourceOffset,
777: IN PVOID DestinationBuffer,
778: IN ULONG DestinationOffset,
779: IN ULONG DestinationBufferSize,
780: OUT PULONG BytesCopied
781: );
782:
783: VOID
784: TdiBuildNetbiosAddress (
785: IN PUCHAR NetbiosName,
786: IN BOOLEAN IsGroupName,
787: IN OUT PTA_NETBIOS_ADDRESS NetworkName
788: );
789:
790: NTSTATUS
791: TdiBuildNetbiosAddressEa (
792: IN PUCHAR Buffer,
793: IN BOOLEAN IsGroupName,
794: IN PUCHAR NetbiosName
795: );
796:
797: //++
798: //
799: // VOID
800: // TdiCompleteRequest (
801: // IN PIRP Irp,
802: // IN NTSTATUS Status
803: // );
804: //
805: // Routine Description:
806: //
807: // This routine is used to complete an IRP with the indicated
808: // status.
809: //
810: // Arguments:
811: //
812: // Irp - Supplies a pointer to the Irp to complete
813: //
814: // Status - Supplies the completion status for the Irp
815: //
816: // Return Value:
817: //
818: // None.
819: //
820: //--
821:
822: #define TdiCompleteRequest(IRP,STATUS) { \
823: (IRP)->IoStatus.Status = (STATUS); \
824: IoCompleteRequest( (IRP), IO_NETWORK_INCREMENT ); \
825: }
826:
827: #endif // _TDI_KRNL_
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.