2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS TCP/IP protocol driver
4 * FILE: tcpip/dispatch.h
5 * PURPOSE: TDI dispatch routines
6 * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
8 * CSH 01/08-2000 Created
9 * TODO: Validate device object in all dispatch routines
13 #include <pseh/pseh.h>
15 NTSTATUS
DispPrepareIrpForCancel(
16 PTRANSPORT_CONTEXT Context
,
18 PDRIVER_CANCEL CancelRoutine
)
20 * FUNCTION: Prepare an IRP for cancellation
22 * Context = Pointer to context information
23 * Irp = Pointer to an I/O request packet
24 * CancelRoutine = Routine to be called when I/O request is cancelled
31 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
33 IoAcquireCancelSpinLock(&OldIrql
);
36 IoMarkIrpPending(Irp
);
37 IoSetCancelRoutine(Irp
, CancelRoutine
);
38 IoReleaseCancelSpinLock(OldIrql
);
40 TI_DbgPrint(DEBUG_IRP
, ("Leaving (IRP at 0x%X can now be cancelled).\n", Irp
));
42 return STATUS_SUCCESS
;
45 /* IRP has already been cancelled */
47 IoReleaseCancelSpinLock(OldIrql
);
49 Irp
->IoStatus
.Status
= STATUS_CANCELLED
;
50 Irp
->IoStatus
.Information
= 0;
52 TI_DbgPrint(DEBUG_IRP
, ("Leaving (IRP was already cancelled).\n"));
54 return IRPFinish(Irp
, STATUS_CANCELLED
);
58 VOID
DispCancelComplete(
61 * FUNCTION: Completes a cancel request
63 * Context = Pointer to context information (FILE_OBJECT)
67 PFILE_OBJECT FileObject
;
68 PTRANSPORT_CONTEXT TranContext
;
70 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
72 FileObject
= (PFILE_OBJECT
)Context
;
73 TranContext
= (PTRANSPORT_CONTEXT
)FileObject
->FsContext
;
75 /* Set the cleanup event */
76 KeSetEvent(&TranContext
->CleanupEvent
, 0, FALSE
);
78 /* We are expected to release the cancel spin lock */
79 /*IoReleaseCancelSpinLock(OldIrql);*/
81 TI_DbgPrint(DEBUG_IRP
, ("Leaving.\n"));
85 VOID
DispDataRequestComplete(
90 * FUNCTION: Completes a send/receive IRP
92 * Context = Pointer to context information (IRP)
93 * Status = Status of the request
94 * Count = Number of bytes sent or received
98 PIO_STACK_LOCATION IrpSp
;
99 PTRANSPORT_CONTEXT TranContext
;
102 TI_DbgPrint(DEBUG_IRP
, ("Called for irp %x (%x, %d).\n",
103 Context
, Status
, Count
));
106 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
107 TranContext
= (PTRANSPORT_CONTEXT
)IrpSp
->FileObject
->FsContext
;
109 IoAcquireCancelSpinLock(&OldIrql
);
111 IoSetCancelRoutine(Irp
, NULL
);
113 if (Irp
->Cancel
|| TranContext
->CancelIrps
) {
114 /* The IRP has been cancelled */
116 TI_DbgPrint(DEBUG_IRP
, ("IRP is cancelled.\n"));
118 Status
= STATUS_CANCELLED
;
122 IoReleaseCancelSpinLock(OldIrql
);
124 Irp
->IoStatus
.Status
= Status
;
125 Irp
->IoStatus
.Information
= Count
;
127 TI_DbgPrint(MID_TRACE
, ("Irp->IoStatus.Status = %x\n",
128 Irp
->IoStatus
.Status
));
129 TI_DbgPrint(MID_TRACE
, ("Irp->IoStatus.Information = %d\n",
130 Irp
->IoStatus
.Information
));
131 TI_DbgPrint(DEBUG_IRP
, ("Completing IRP at (0x%X).\n", Irp
));
133 IRPFinish(Irp
, Irp
->IoStatus
.Status
);
135 TI_DbgPrint(DEBUG_IRP
, ("Done Completing IRP\n"));
138 typedef struct _DISCONNECT_TYPE
{
142 PFILE_OBJECT FileObject
;
143 } DISCONNECT_TYPE
, *PDISCONNECT_TYPE
;
145 VOID
DispDoDisconnect( PVOID Data
) {
146 PDISCONNECT_TYPE DisType
= (PDISCONNECT_TYPE
)Data
;
148 TI_DbgPrint(DEBUG_IRP
, ("PostCancel: DoDisconnect\n"));
154 DispDataRequestComplete
,
156 TI_DbgPrint(DEBUG_IRP
, ("PostCancel: DoDisconnect done\n"));
158 DispDataRequestComplete(DisType
->Irp
, STATUS_CANCELLED
, 0);
160 DispCancelComplete(DisType
->FileObject
);
163 VOID DDKAPI
DispCancelRequest(
164 PDEVICE_OBJECT Device
,
167 * FUNCTION: Cancels an IRP
169 * Device = Pointer to device object
170 * Irp = Pointer to an I/O request packet
173 PIO_STACK_LOCATION IrpSp
;
174 PTRANSPORT_CONTEXT TranContext
;
175 PFILE_OBJECT FileObject
;
177 DISCONNECT_TYPE DisType
;
179 /*NTSTATUS Status = STATUS_SUCCESS;*/
181 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
183 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
184 FileObject
= IrpSp
->FileObject
;
185 TranContext
= (PTRANSPORT_CONTEXT
)FileObject
->FsContext
;
186 MinorFunction
= IrpSp
->MinorFunction
;
188 TI_DbgPrint(DEBUG_IRP
, ("IRP at (0x%X) MinorFunction (0x%X) IrpSp (0x%X).\n", Irp
, MinorFunction
, IrpSp
));
190 Irp
->IoStatus
.Status
= STATUS_PENDING
;
194 TI_DbgPrint(MIN_TRACE
, ("Irp->Cancel is FALSE, should be TRUE.\n"));
197 /* Try canceling the request */
198 switch(MinorFunction
) {
201 DisType
.Type
= TDI_DISCONNECT_RELEASE
|
202 ((MinorFunction
== TDI_RECEIVE
) ? TDI_DISCONNECT_ABORT
: 0);
203 DisType
.Context
= TranContext
->Handle
.ConnectionContext
;
205 DisType
.FileObject
= FileObject
;
207 TCPRemoveIRP( TranContext
->Handle
.ConnectionContext
, Irp
);
209 if( !ChewCreate( &WorkItem
, sizeof(DISCONNECT_TYPE
),
210 DispDoDisconnect
, &DisType
) )
214 case TDI_SEND_DATAGRAM
:
215 Irp
->IoStatus
.Status
= STATUS_CANCELLED
;
216 if (FileObject
->FsContext2
!= (PVOID
)TDI_TRANSPORT_ADDRESS_FILE
) {
217 TI_DbgPrint(MIN_TRACE
, ("TDI_SEND_DATAGRAM, but no address file.\n"));
221 /*DGCancelSendRequest(TranContext->Handle.AddressHandle, Irp);*/
224 case TDI_RECEIVE_DATAGRAM
:
225 Irp
->IoStatus
.Status
= STATUS_CANCELLED
;
226 if (FileObject
->FsContext2
!= (PVOID
)TDI_TRANSPORT_ADDRESS_FILE
) {
227 TI_DbgPrint(MIN_TRACE
, ("TDI_RECEIVE_DATAGRAM, but no address file.\n"));
231 /*DGCancelReceiveRequest(TranContext->Handle.AddressHandle, Irp);*/
235 TI_DbgPrint(MIN_TRACE
, ("Unknown IRP. MinorFunction (0x%X).\n", MinorFunction
));
239 if( Irp
->IoStatus
.Status
== STATUS_PENDING
)
240 IoMarkIrpPending(Irp
);
242 IoReleaseCancelSpinLock(Irp
->CancelIrql
);
244 TI_DbgPrint(MAX_TRACE
, ("Leaving.\n"));
248 VOID DDKAPI
DispCancelListenRequest(
249 PDEVICE_OBJECT Device
,
252 * FUNCTION: Cancels a listen IRP
254 * Device = Pointer to device object
255 * Irp = Pointer to an I/O request packet
258 PIO_STACK_LOCATION IrpSp
;
259 PTRANSPORT_CONTEXT TranContext
;
260 PFILE_OBJECT FileObject
;
261 PCONNECTION_ENDPOINT Connection
;
262 /*NTSTATUS Status = STATUS_SUCCESS;*/
264 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
266 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
267 FileObject
= IrpSp
->FileObject
;
268 TranContext
= (PTRANSPORT_CONTEXT
)FileObject
->FsContext
;
269 ASSERT( TDI_LISTEN
== IrpSp
->MinorFunction
);
271 TI_DbgPrint(DEBUG_IRP
, ("IRP at (0x%X).\n", Irp
));
275 TI_DbgPrint(MIN_TRACE
, ("Irp->Cancel is FALSE, should be TRUE.\n"));
278 /* Try canceling the request */
279 Connection
= (PCONNECTION_ENDPOINT
)TranContext
->Handle
.ConnectionContext
;
280 TCPAbortListenForSocket(
281 Connection
->AddressFile
->Listener
,
284 IoReleaseCancelSpinLock(Irp
->CancelIrql
);
286 DispDataRequestComplete(Irp
, STATUS_CANCELLED
, 0);
288 DispCancelComplete(FileObject
);
290 TI_DbgPrint(MAX_TRACE
, ("Leaving.\n"));
294 NTSTATUS
DispTdiAccept(
297 * FUNCTION: TDI_ACCEPT handler
299 * Irp = Pointer to an I/O request packet
301 * Status of operation
304 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
306 return STATUS_NOT_IMPLEMENTED
;
310 NTSTATUS
DispTdiAssociateAddress(
313 * FUNCTION: TDI_ASSOCIATE_ADDRESS handler
315 * Irp = Pointer to an I/O request packet
317 * Status of operation
320 PTDI_REQUEST_KERNEL_ASSOCIATE Parameters
;
321 PTRANSPORT_CONTEXT TranContext
;
322 PIO_STACK_LOCATION IrpSp
;
323 PCONNECTION_ENDPOINT Connection
;
324 PFILE_OBJECT FileObject
;
325 PADDRESS_FILE AddrFile
= NULL
;
328 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
330 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
332 /* Get associated connection endpoint file object. Quit if none exists */
334 TranContext
= IrpSp
->FileObject
->FsContext
;
336 TI_DbgPrint(MID_TRACE
, ("Bad transport context.\n"));
337 return STATUS_INVALID_PARAMETER
;
340 Connection
= (PCONNECTION_ENDPOINT
)TranContext
->Handle
.ConnectionContext
;
342 TI_DbgPrint(MID_TRACE
, ("No connection endpoint file object.\n"));
343 return STATUS_INVALID_PARAMETER
;
346 if (Connection
->AddressFile
) {
347 TI_DbgPrint(MID_TRACE
, ("An address file is already asscociated.\n"));
348 return STATUS_INVALID_PARAMETER
;
351 Parameters
= (PTDI_REQUEST_KERNEL_ASSOCIATE
)&IrpSp
->Parameters
;
353 Status
= ObReferenceObjectByHandle(
354 Parameters
->AddressHandle
,
360 if (!NT_SUCCESS(Status
)) {
361 TI_DbgPrint(MID_TRACE
, ("Bad address file object handle (0x%X): %x.\n",
362 Parameters
->AddressHandle
, Status
));
363 return STATUS_INVALID_PARAMETER
;
366 if (FileObject
->FsContext2
!= (PVOID
)TDI_TRANSPORT_ADDRESS_FILE
) {
367 ObDereferenceObject(FileObject
);
368 TI_DbgPrint(MID_TRACE
, ("Bad address file object. Magic (0x%X).\n",
369 FileObject
->FsContext2
));
370 return STATUS_INVALID_PARAMETER
;
373 /* Get associated address file object. Quit if none exists */
375 TranContext
= FileObject
->FsContext
;
377 ObDereferenceObject(FileObject
);
378 TI_DbgPrint(MID_TRACE
, ("Bad transport context.\n"));
379 return STATUS_INVALID_PARAMETER
;
382 AddrFile
= (PADDRESS_FILE
)TranContext
->Handle
.AddressHandle
;
384 ObDereferenceObject(FileObject
);
385 TI_DbgPrint(MID_TRACE
, ("No address file object.\n"));
386 return STATUS_INVALID_PARAMETER
;
389 Connection
->AddressFile
= AddrFile
;
391 /* Add connection endpoint to the address file */
392 AddrFile
->Connection
= Connection
;
394 /* FIXME: Maybe do this in DispTdiDisassociateAddress() instead? */
395 ObDereferenceObject(FileObject
);
401 NTSTATUS
DispTdiConnect(
404 * FUNCTION: TDI_CONNECT handler
406 * Irp = Pointer to an I/O request packet
408 * Status of operation
411 PCONNECTION_ENDPOINT Connection
;
412 PTDI_REQUEST_KERNEL Parameters
;
413 PTRANSPORT_CONTEXT TranContext
;
414 PIO_STACK_LOCATION IrpSp
;
417 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
419 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
421 /* Get associated connection endpoint file object. Quit if none exists */
423 TranContext
= IrpSp
->FileObject
->FsContext
;
425 TI_DbgPrint(MID_TRACE
, ("Bad transport context.\n"));
426 return STATUS_INVALID_CONNECTION
;
429 Connection
= (PCONNECTION_ENDPOINT
)TranContext
->Handle
.ConnectionContext
;
431 TI_DbgPrint(MID_TRACE
, ("No connection endpoint file object.\n"));
432 return STATUS_INVALID_CONNECTION
;
435 Parameters
= (PTDI_REQUEST_KERNEL
)&IrpSp
->Parameters
;
438 TranContext
->Handle
.ConnectionContext
,
439 Parameters
->RequestConnectionInformation
,
440 Parameters
->ReturnConnectionInformation
,
441 DispDataRequestComplete
,
444 TI_DbgPrint(MAX_TRACE
, ("TCP Connect returned %08x\n", Status
));
450 NTSTATUS
DispTdiDisassociateAddress(
453 * FUNCTION: TDI_DISASSOCIATE_ADDRESS handler
455 * Irp = Pointer to an I/O request packet
457 * Status of operation
460 PCONNECTION_ENDPOINT Connection
;
461 PTRANSPORT_CONTEXT TranContext
;
462 PIO_STACK_LOCATION IrpSp
;
464 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
466 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
468 /* Get associated connection endpoint file object. Quit if none exists */
470 TranContext
= IrpSp
->FileObject
->FsContext
;
472 TI_DbgPrint(MID_TRACE
, ("Bad transport context.\n"));
473 return STATUS_INVALID_PARAMETER
;
476 Connection
= (PCONNECTION_ENDPOINT
)TranContext
->Handle
.ConnectionContext
;
478 TI_DbgPrint(MID_TRACE
, ("No connection endpoint file object.\n"));
479 return STATUS_INVALID_PARAMETER
;
482 if (!Connection
->AddressFile
) {
483 TI_DbgPrint(MID_TRACE
, ("No address file is asscociated.\n"));
484 return STATUS_INVALID_PARAMETER
;
487 return STATUS_SUCCESS
;
491 NTSTATUS
DispTdiDisconnect(
494 * FUNCTION: TDI_DISCONNECT handler
496 * Irp = Pointer to an I/O request packet
498 * Status of operation
502 PTDI_REQUEST_KERNEL_DISCONNECT DisReq
;
503 PCONNECTION_ENDPOINT Connection
;
504 PTRANSPORT_CONTEXT TranContext
;
505 PIO_STACK_LOCATION IrpSp
;
507 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
509 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
510 DisReq
= (PTDI_REQUEST_KERNEL_DISCONNECT
)&IrpSp
->Parameters
;
512 /* Get associated connection endpoint file object. Quit if none exists */
514 TranContext
= IrpSp
->FileObject
->FsContext
;
516 TI_DbgPrint(MID_TRACE
, ("Bad transport context.\n"));
517 return STATUS_INVALID_CONNECTION
;
520 Connection
= (PCONNECTION_ENDPOINT
)TranContext
->Handle
.ConnectionContext
;
522 TI_DbgPrint(MID_TRACE
, ("No connection endpoint file object.\n"));
523 return STATUS_INVALID_CONNECTION
;
526 Status
= TCPDisconnect(
527 TranContext
->Handle
.ConnectionContext
,
528 DisReq
->RequestFlags
,
529 DisReq
->RequestConnectionInformation
,
530 DisReq
->ReturnConnectionInformation
,
531 DispDataRequestComplete
,
534 TI_DbgPrint(MAX_TRACE
, ("TCP Connect returned %08x\n", Status
));
540 NTSTATUS
DispTdiListen(
543 * FUNCTION: TDI_LISTEN handler
545 * Irp = Pointer to an I/O request packet
547 * Status of operation
550 PCONNECTION_ENDPOINT Connection
;
551 PTDI_REQUEST_KERNEL Parameters
;
552 PTRANSPORT_CONTEXT TranContext
;
553 PIO_STACK_LOCATION IrpSp
;
554 NTSTATUS Status
= STATUS_SUCCESS
;
556 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
558 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
560 /* Get associated connection endpoint file object. Quit if none exists */
562 TranContext
= IrpSp
->FileObject
->FsContext
;
563 if (TranContext
== NULL
)
565 TI_DbgPrint(MID_TRACE
, ("Bad transport context.\n"));
566 return STATUS_INVALID_CONNECTION
;
569 Connection
= (PCONNECTION_ENDPOINT
)TranContext
->Handle
.ConnectionContext
;
570 if (Connection
== NULL
)
572 TI_DbgPrint(MID_TRACE
, ("No connection endpoint file object.\n"));
573 return STATUS_INVALID_CONNECTION
;
576 Parameters
= (PTDI_REQUEST_KERNEL
)&IrpSp
->Parameters
;
578 TI_DbgPrint(MIN_TRACE
, ("Connection->AddressFile: %x\n",
579 Connection
->AddressFile
));
580 if( Connection
->AddressFile
) {
581 TI_DbgPrint(MIN_TRACE
, ("Connection->AddressFile->Listener: %x\n",
582 Connection
->AddressFile
->Listener
));
585 /* Listening will require us to create a listening socket and store it in
586 * the address file. It will be signalled, and attempt to complete an irp
587 * when a new connection arrives. */
588 /* The important thing to note here is that the irp we'll complete belongs
589 * to the socket to be accepted onto, not the listener */
590 if( !Connection
->AddressFile
->Listener
) {
591 Connection
->AddressFile
->Listener
=
592 TCPAllocateConnectionEndpoint( NULL
);
594 if( !Connection
->AddressFile
->Listener
)
595 Status
= STATUS_NO_MEMORY
;
597 if( NT_SUCCESS(Status
) ) {
598 Connection
->AddressFile
->Listener
->AddressFile
=
599 Connection
->AddressFile
;
601 Status
= TCPSocket( Connection
->AddressFile
->Listener
,
602 Connection
->AddressFile
->Family
,
604 Connection
->AddressFile
->Protocol
);
607 if( NT_SUCCESS(Status
) )
608 Status
= TCPListen( Connection
->AddressFile
->Listener
, 1024 );
611 if( NT_SUCCESS(Status
) ) {
612 Status
= DispPrepareIrpForCancel
613 (TranContext
->Handle
.ConnectionContext
,
615 (PDRIVER_CANCEL
)DispCancelListenRequest
);
618 if( NT_SUCCESS(Status
) ) {
620 ( (PTDI_REQUEST
)Parameters
,
621 Connection
->AddressFile
->Listener
,
623 DispDataRequestComplete
,
627 TI_DbgPrint(MID_TRACE
,("Leaving %x\n", Status
));
633 NTSTATUS
DispTdiQueryInformation(
634 PDEVICE_OBJECT DeviceObject
,
637 * FUNCTION: TDI_QUERY_INFORMATION handler
639 * DeviceObject = Pointer to device object structure
640 * Irp = Pointer to an I/O request packet
642 * Status of operation
645 PTDI_REQUEST_KERNEL_QUERY_INFORMATION Parameters
;
646 PTRANSPORT_CONTEXT TranContext
;
647 PIO_STACK_LOCATION IrpSp
;
649 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
651 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
652 Parameters
= (PTDI_REQUEST_KERNEL_QUERY_INFORMATION
)&IrpSp
->Parameters
;
654 TranContext
= IrpSp
->FileObject
->FsContext
;
656 TI_DbgPrint(MID_TRACE
, ("Bad transport context.\n"));
657 return STATUS_INVALID_CONNECTION
;
660 switch (Parameters
->QueryType
)
662 case TDI_QUERY_ADDRESS_INFO
:
664 PTDI_ADDRESS_INFO AddressInfo
;
665 PADDRESS_FILE AddrFile
;
666 PTA_IP_ADDRESS Address
;
668 AddressInfo
= (PTDI_ADDRESS_INFO
)MmGetSystemAddressForMdl(Irp
->MdlAddress
);
670 switch ((ULONG
)IrpSp
->FileObject
->FsContext2
) {
671 case TDI_TRANSPORT_ADDRESS_FILE
:
672 AddrFile
= (PADDRESS_FILE
)TranContext
->Handle
.AddressHandle
;
675 case TDI_CONNECTION_FILE
:
677 ((PCONNECTION_ENDPOINT
)TranContext
->Handle
.ConnectionContext
)->
682 TI_DbgPrint(MIN_TRACE
, ("Invalid transport context\n"));
683 return STATUS_INVALID_PARAMETER
;
687 TI_DbgPrint(MID_TRACE
, ("No address file object.\n"));
688 return STATUS_INVALID_PARAMETER
;
691 if (MmGetMdlByteCount(Irp
->MdlAddress
) <
692 (FIELD_OFFSET(TDI_ADDRESS_INFO
, Address
.Address
[0].Address
) +
693 sizeof(TDI_ADDRESS_IP
))) {
694 TI_DbgPrint(MID_TRACE
, ("MDL buffer too small.\n"));
695 return STATUS_BUFFER_OVERFLOW
;
698 Address
= (PTA_IP_ADDRESS
)&AddressInfo
->Address
;
699 Address
->TAAddressCount
= 1;
700 Address
->Address
[0].AddressLength
= TDI_ADDRESS_LENGTH_IP
;
701 Address
->Address
[0].AddressType
= TDI_ADDRESS_TYPE_IP
;
702 Address
->Address
[0].Address
[0].sin_port
= AddrFile
->Port
;
703 Address
->Address
[0].Address
[0].in_addr
=
704 AddrFile
->Address
.Address
.IPv4Address
;
706 &Address
->Address
[0].Address
[0].sin_zero
,
707 sizeof(Address
->Address
[0].Address
[0].sin_zero
));
709 return STATUS_SUCCESS
;
712 case TDI_QUERY_CONNECTION_INFO
:
714 PTDI_CONNECTION_INFORMATION AddressInfo
;
715 PADDRESS_FILE AddrFile
;
716 PCONNECTION_ENDPOINT Endpoint
= NULL
;
718 AddressInfo
= (PTDI_CONNECTION_INFORMATION
)
719 MmGetSystemAddressForMdl(Irp
->MdlAddress
);
721 switch ((ULONG
)IrpSp
->FileObject
->FsContext2
) {
722 case TDI_TRANSPORT_ADDRESS_FILE
:
723 AddrFile
= (PADDRESS_FILE
)TranContext
->Handle
.AddressHandle
;
726 case TDI_CONNECTION_FILE
:
728 (PCONNECTION_ENDPOINT
)TranContext
->Handle
.ConnectionContext
;
732 TI_DbgPrint(MIN_TRACE
, ("Invalid transport context\n"));
733 return STATUS_INVALID_PARAMETER
;
737 TI_DbgPrint(MID_TRACE
, ("No connection object.\n"));
738 return STATUS_INVALID_PARAMETER
;
741 if (MmGetMdlByteCount(Irp
->MdlAddress
) <
742 (FIELD_OFFSET(TDI_CONNECTION_INFORMATION
, RemoteAddress
) +
744 TI_DbgPrint(MID_TRACE
, ("MDL buffer too small (ptr).\n"));
745 return STATUS_BUFFER_OVERFLOW
;
748 return TCPGetPeerAddress( Endpoint
, AddressInfo
->RemoteAddress
);
752 return STATUS_NOT_IMPLEMENTED
;
756 NTSTATUS
DispTdiReceive(
759 * FUNCTION: TDI_RECEIVE handler
761 * Irp = Pointer to an I/O request packet
763 * Status of operation
766 PIO_STACK_LOCATION IrpSp
;
767 PTDI_REQUEST_KERNEL_RECEIVE ReceiveInfo
;
768 PTRANSPORT_CONTEXT TranContext
;
772 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
774 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
775 ReceiveInfo
= (PTDI_REQUEST_KERNEL_RECEIVE
)&(IrpSp
->Parameters
);
777 TranContext
= IrpSp
->FileObject
->FsContext
;
778 if (TranContext
== NULL
)
780 TI_DbgPrint(MID_TRACE
, ("Bad transport context.\n"));
781 return STATUS_INVALID_CONNECTION
;
784 if (TranContext
->Handle
.ConnectionContext
== NULL
)
786 TI_DbgPrint(MID_TRACE
, ("No connection endpoint file object.\n"));
787 return STATUS_INVALID_CONNECTION
;
790 /* Initialize a receive request */
791 Status
= DispPrepareIrpForCancel
792 (TranContext
->Handle
.ConnectionContext
,
794 (PDRIVER_CANCEL
)DispCancelRequest
);
796 TI_DbgPrint(MID_TRACE
,("TCPIP<<< Got an MDL: %x\n", Irp
->MdlAddress
));
797 if (NT_SUCCESS(Status
))
799 Status
= TCPReceiveData(
800 TranContext
->Handle
.ConnectionContext
,
801 (PNDIS_BUFFER
)Irp
->MdlAddress
,
802 ReceiveInfo
->ReceiveLength
,
804 ReceiveInfo
->ReceiveFlags
,
805 DispDataRequestComplete
,
807 if (Status
!= STATUS_PENDING
)
809 DispDataRequestComplete(Irp
, Status
, BytesReceived
);
811 IoMarkIrpPending(Irp
);
814 TI_DbgPrint(DEBUG_IRP
, ("Leaving. Status is (0x%X)\n", Status
));
820 NTSTATUS
DispTdiReceiveDatagram(
823 * FUNCTION: TDI_RECEIVE_DATAGRAM handler
825 * Irp = Pointer to an I/O request packet
827 * Status of operation
830 PIO_STACK_LOCATION IrpSp
;
831 PTDI_REQUEST_KERNEL_RECEIVEDG DgramInfo
;
832 PTRANSPORT_CONTEXT TranContext
;
837 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
839 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
840 DgramInfo
= (PTDI_REQUEST_KERNEL_RECEIVEDG
)&(IrpSp
->Parameters
);
842 TranContext
= IrpSp
->FileObject
->FsContext
;
843 if (TranContext
== NULL
)
845 TI_DbgPrint(MID_TRACE
, ("Bad transport context.\n"));
846 return STATUS_INVALID_ADDRESS
;
849 /* Initialize a receive request */
850 Request
.Handle
.AddressHandle
= TranContext
->Handle
.AddressHandle
;
851 Request
.RequestNotifyObject
= DispDataRequestComplete
;
852 Request
.RequestContext
= Irp
;
854 Status
= DispPrepareIrpForCancel(
855 IrpSp
->FileObject
->FsContext
,
857 (PDRIVER_CANCEL
)DispCancelRequest
);
859 if (NT_SUCCESS(Status
))
864 NdisQueryBuffer( (PNDIS_BUFFER
)Irp
->MdlAddress
,
868 Status
= UDPReceiveDatagram(
869 Request
.Handle
.AddressHandle
,
870 DgramInfo
->ReceiveDatagramInformation
,
872 DgramInfo
->ReceiveLength
,
873 DgramInfo
->ReceiveFlags
,
874 DgramInfo
->ReturnDatagramInformation
,
876 (PDATAGRAM_COMPLETION_ROUTINE
)DispDataRequestComplete
,
878 if (Status
!= STATUS_PENDING
) {
879 DispDataRequestComplete(Irp
, Status
, BytesReceived
);
881 IoMarkIrpPending(Irp
);
884 TI_DbgPrint(DEBUG_IRP
, ("Leaving. Status is (0x%X)\n", Status
));
890 NTSTATUS
DispTdiSend(
893 * FUNCTION: TDI_SEND handler
895 * Irp = Pointer to an I/O request packet
897 * Status of operation
900 PIO_STACK_LOCATION IrpSp
;
901 PTDI_REQUEST_KERNEL_RECEIVE ReceiveInfo
;
902 PTRANSPORT_CONTEXT TranContext
;
906 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
908 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
909 ReceiveInfo
= (PTDI_REQUEST_KERNEL_RECEIVE
)&(IrpSp
->Parameters
);
911 TranContext
= IrpSp
->FileObject
->FsContext
;
912 if (TranContext
== NULL
)
914 TI_DbgPrint(MID_TRACE
, ("Bad transport context.\n"));
915 return STATUS_INVALID_CONNECTION
;
918 if (TranContext
->Handle
.ConnectionContext
== NULL
)
920 TI_DbgPrint(MID_TRACE
, ("No connection endpoint file object.\n"));
921 return STATUS_INVALID_CONNECTION
;
924 Status
= DispPrepareIrpForCancel(
925 IrpSp
->FileObject
->FsContext
,
927 (PDRIVER_CANCEL
)DispCancelRequest
);
929 TI_DbgPrint(MID_TRACE
,("TCPIP<<< Got an MDL: %x\n", Irp
->MdlAddress
));
930 if (NT_SUCCESS(Status
))
935 NdisQueryBuffer( Irp
->MdlAddress
, &Data
, &Len
);
937 TI_DbgPrint(MID_TRACE
,("About to TCPSendData\n"));
938 Status
= TCPSendData(
939 TranContext
->Handle
.ConnectionContext
,
941 ReceiveInfo
->ReceiveLength
,
943 ReceiveInfo
->ReceiveFlags
);
944 if (Status
!= STATUS_PENDING
)
946 DispDataRequestComplete(Irp
, Status
, BytesReceived
);
948 IoMarkIrpPending( Irp
);
951 TI_DbgPrint(DEBUG_IRP
, ("Leaving. Status is (0x%X)\n", Status
));
957 NTSTATUS
DispTdiSendDatagram(
960 * FUNCTION: TDI_SEND_DATAGRAM handler
962 * Irp = Pointer to an I/O request packet
964 * Status of operation
967 PIO_STACK_LOCATION IrpSp
;
969 PTDI_REQUEST_KERNEL_SENDDG DgramInfo
;
970 PTRANSPORT_CONTEXT TranContext
;
973 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
975 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
976 DgramInfo
= (PTDI_REQUEST_KERNEL_SENDDG
)&(IrpSp
->Parameters
);
977 TranContext
= IrpSp
->FileObject
->FsContext
;
979 /* Initialize a send request */
980 Request
.Handle
.AddressHandle
= TranContext
->Handle
.AddressHandle
;
981 Request
.RequestNotifyObject
= DispDataRequestComplete
;
982 Request
.RequestContext
= Irp
;
984 Status
= DispPrepareIrpForCancel(
985 IrpSp
->FileObject
->FsContext
,
987 (PDRIVER_CANCEL
)DispCancelRequest
);
989 if (NT_SUCCESS(Status
)) {
993 TI_DbgPrint(MID_TRACE
,("About to query buffer %x\n", Irp
->MdlAddress
));
995 NdisQueryBuffer( (PNDIS_BUFFER
)Irp
->MdlAddress
,
999 /* FIXME: DgramInfo->SendDatagramInformation->RemoteAddress
1000 must be of type PTDI_ADDRESS_IP */
1001 TI_DbgPrint(MID_TRACE
,
1002 ("About to call send routine %x\n",
1003 (*((PADDRESS_FILE
)Request
.Handle
.AddressHandle
)->Send
)));
1005 if( (*((PADDRESS_FILE
)Request
.Handle
.AddressHandle
)->Send
) )
1006 Status
= (*((PADDRESS_FILE
)Request
.Handle
.AddressHandle
)->Send
)(
1007 Request
.Handle
.AddressHandle
,
1008 DgramInfo
->SendDatagramInformation
,
1011 &Irp
->IoStatus
.Information
);
1013 Status
= STATUS_UNSUCCESSFUL
;
1015 if (Status
!= STATUS_PENDING
) {
1016 DispDataRequestComplete(Irp
, Status
, Irp
->IoStatus
.Information
);
1017 /* Return STATUS_PENDING because DispPrepareIrpForCancel
1018 marks Irp as pending */
1019 Status
= STATUS_PENDING
;
1021 IoMarkIrpPending( Irp
);
1024 TI_DbgPrint(DEBUG_IRP
, ("Leaving.\n"));
1030 NTSTATUS
DispTdiSetEventHandler(PIRP Irp
)
1032 * FUNCTION: TDI_SET_EVENT_HANDER handler
1034 * Irp = Pointer to a I/O request packet
1036 * Status of operation
1039 PTDI_REQUEST_KERNEL_SET_EVENT Parameters
;
1040 PTRANSPORT_CONTEXT TranContext
;
1041 PIO_STACK_LOCATION IrpSp
;
1042 PADDRESS_FILE AddrFile
;
1046 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
1048 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
1050 /* Get associated address file object. Quit if none exists */
1052 TranContext
= IrpSp
->FileObject
->FsContext
;
1054 TI_DbgPrint(MIN_TRACE
, ("Bad transport context.\n"));
1055 return STATUS_INVALID_PARAMETER
;
1058 AddrFile
= (PADDRESS_FILE
)TranContext
->Handle
.AddressHandle
;
1060 TI_DbgPrint(MIN_TRACE
, ("No address file object.\n"));
1061 return STATUS_INVALID_PARAMETER
;
1064 Parameters
= (PTDI_REQUEST_KERNEL_SET_EVENT
)&IrpSp
->Parameters
;
1065 Status
= STATUS_SUCCESS
;
1067 TcpipAcquireSpinLock(&AddrFile
->Lock
, &OldIrql
);
1069 /* Set the event handler. if an event handler is associated with
1070 a specific event, it's flag (RegisteredXxxHandler) is TRUE.
1071 If an event handler is not used it's flag is FALSE */
1072 switch (Parameters
->EventType
) {
1073 case TDI_EVENT_CONNECT
:
1074 if (!Parameters
->EventHandler
) {
1075 AddrFile
->ConnectHandlerContext
= NULL
;
1076 AddrFile
->RegisteredConnectHandler
= FALSE
;
1078 AddrFile
->ConnectHandler
=
1079 (PTDI_IND_CONNECT
)Parameters
->EventHandler
;
1080 AddrFile
->ConnectHandlerContext
= Parameters
->EventContext
;
1081 AddrFile
->RegisteredConnectHandler
= TRUE
;
1085 case TDI_EVENT_DISCONNECT
:
1086 if (!Parameters
->EventHandler
) {
1087 AddrFile
->DisconnectHandlerContext
= NULL
;
1088 AddrFile
->RegisteredDisconnectHandler
= FALSE
;
1090 AddrFile
->DisconnectHandler
=
1091 (PTDI_IND_DISCONNECT
)Parameters
->EventHandler
;
1092 AddrFile
->DisconnectHandlerContext
= Parameters
->EventContext
;
1093 AddrFile
->RegisteredDisconnectHandler
= TRUE
;
1097 case TDI_EVENT_ERROR
:
1098 if (Parameters
->EventHandler
== NULL
) {
1099 AddrFile
->ErrorHandlerContext
= NULL
;
1100 AddrFile
->RegisteredErrorHandler
= FALSE
;
1102 AddrFile
->ErrorHandler
=
1103 (PTDI_IND_ERROR
)Parameters
->EventHandler
;
1104 AddrFile
->ErrorHandlerContext
= Parameters
->EventContext
;
1105 AddrFile
->RegisteredErrorHandler
= TRUE
;
1109 case TDI_EVENT_RECEIVE
:
1110 if (Parameters
->EventHandler
== NULL
) {
1111 AddrFile
->ReceiveHandlerContext
= NULL
;
1112 AddrFile
->RegisteredReceiveHandler
= FALSE
;
1114 AddrFile
->ReceiveHandler
=
1115 (PTDI_IND_RECEIVE
)Parameters
->EventHandler
;
1116 AddrFile
->ReceiveHandlerContext
= Parameters
->EventContext
;
1117 AddrFile
->RegisteredReceiveHandler
= TRUE
;
1121 case TDI_EVENT_RECEIVE_DATAGRAM
:
1122 if (Parameters
->EventHandler
== NULL
) {
1123 AddrFile
->ReceiveDatagramHandlerContext
= NULL
;
1124 AddrFile
->RegisteredReceiveDatagramHandler
= FALSE
;
1126 AddrFile
->ReceiveDatagramHandler
=
1127 (PTDI_IND_RECEIVE_DATAGRAM
)Parameters
->EventHandler
;
1128 AddrFile
->ReceiveDatagramHandlerContext
= Parameters
->EventContext
;
1129 AddrFile
->RegisteredReceiveDatagramHandler
= TRUE
;
1133 case TDI_EVENT_RECEIVE_EXPEDITED
:
1134 if (Parameters
->EventHandler
== NULL
) {
1135 AddrFile
->ExpeditedReceiveHandlerContext
= NULL
;
1136 AddrFile
->RegisteredExpeditedReceiveHandler
= FALSE
;
1138 AddrFile
->ExpeditedReceiveHandler
=
1139 (PTDI_IND_RECEIVE_EXPEDITED
)Parameters
->EventHandler
;
1140 AddrFile
->ExpeditedReceiveHandlerContext
= Parameters
->EventContext
;
1141 AddrFile
->RegisteredExpeditedReceiveHandler
= TRUE
;
1145 case TDI_EVENT_CHAINED_RECEIVE
:
1146 if (Parameters
->EventHandler
== NULL
) {
1147 AddrFile
->ChainedReceiveHandlerContext
= NULL
;
1148 AddrFile
->RegisteredChainedReceiveHandler
= FALSE
;
1150 AddrFile
->ChainedReceiveHandler
=
1151 (PTDI_IND_CHAINED_RECEIVE
)Parameters
->EventHandler
;
1152 AddrFile
->ChainedReceiveHandlerContext
= Parameters
->EventContext
;
1153 AddrFile
->RegisteredChainedReceiveHandler
= TRUE
;
1157 case TDI_EVENT_CHAINED_RECEIVE_DATAGRAM
:
1158 if (Parameters
->EventHandler
== NULL
) {
1159 AddrFile
->ChainedReceiveDatagramHandlerContext
= NULL
;
1160 AddrFile
->RegisteredChainedReceiveDatagramHandler
= FALSE
;
1162 AddrFile
->ChainedReceiveDatagramHandler
=
1163 (PTDI_IND_CHAINED_RECEIVE_DATAGRAM
)Parameters
->EventHandler
;
1164 AddrFile
->ChainedReceiveDatagramHandlerContext
= Parameters
->EventContext
;
1165 AddrFile
->RegisteredChainedReceiveDatagramHandler
= TRUE
;
1169 case TDI_EVENT_CHAINED_RECEIVE_EXPEDITED
:
1170 if (Parameters
->EventHandler
== NULL
) {
1171 AddrFile
->ChainedReceiveExpeditedHandlerContext
= NULL
;
1172 AddrFile
->RegisteredChainedReceiveExpeditedHandler
= FALSE
;
1174 AddrFile
->ChainedReceiveExpeditedHandler
=
1175 (PTDI_IND_CHAINED_RECEIVE_EXPEDITED
)Parameters
->EventHandler
;
1176 AddrFile
->ChainedReceiveExpeditedHandlerContext
= Parameters
->EventContext
;
1177 AddrFile
->RegisteredChainedReceiveExpeditedHandler
= TRUE
;
1182 TI_DbgPrint(MIN_TRACE
, ("Unknown event type (0x%X).\n",
1183 Parameters
->EventType
));
1185 Status
= STATUS_INVALID_PARAMETER
;
1188 TcpipReleaseSpinLock(&AddrFile
->Lock
, OldIrql
);
1194 NTSTATUS
DispTdiSetInformation(
1197 * FUNCTION: TDI_SET_INFORMATION handler
1199 * Irp = Pointer to an I/O request packet
1201 * Status of operation
1204 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
1206 return STATUS_NOT_IMPLEMENTED
;
1210 VOID
DispTdiQueryInformationExComplete(
1215 * FUNCTION: Completes a TDI QueryInformationEx request
1217 * Context = Pointer to the IRP for the request
1218 * Status = TDI status of the request
1219 * ByteCount = Number of bytes returned in output buffer
1222 PTI_QUERY_CONTEXT QueryContext
;
1225 QueryContext
= (PTI_QUERY_CONTEXT
)Context
;
1226 if (NT_SUCCESS(Status
)) {
1227 Count
= CopyBufferToBufferChain(
1228 QueryContext
->InputMdl
,
1229 FIELD_OFFSET(TCP_REQUEST_QUERY_INFORMATION_EX
, Context
),
1230 (PCHAR
)&QueryContext
->QueryInfo
.Context
,
1234 MmUnlockPages(QueryContext
->InputMdl
);
1235 IoFreeMdl(QueryContext
->InputMdl
);
1236 if( QueryContext
->OutputMdl
) {
1237 MmUnlockPages(QueryContext
->OutputMdl
);
1238 IoFreeMdl(QueryContext
->OutputMdl
);
1241 QueryContext
->Irp
->IoStatus
.Information
= ByteCount
;
1242 QueryContext
->Irp
->IoStatus
.Status
= Status
;
1244 ExFreePool(QueryContext
);
1248 NTSTATUS
DispTdiQueryInformationEx(
1250 PIO_STACK_LOCATION IrpSp
)
1252 * FUNCTION: TDI QueryInformationEx handler
1254 * Irp = Pointer to I/O request packet
1255 * IrpSp = Pointer to current stack location of Irp
1257 * Status of operation
1260 PTCP_REQUEST_QUERY_INFORMATION_EX InputBuffer
;
1261 PTRANSPORT_CONTEXT TranContext
;
1262 PTI_QUERY_CONTEXT QueryContext
;
1264 TDI_REQUEST Request
;
1266 UINT InputBufferLength
;
1267 UINT OutputBufferLength
;
1268 BOOLEAN InputMdlLocked
= FALSE
;
1269 BOOLEAN OutputMdlLocked
= FALSE
;
1270 PMDL InputMdl
= NULL
;
1271 PMDL OutputMdl
= NULL
;
1272 NTSTATUS Status
= STATUS_SUCCESS
;
1274 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
1276 TranContext
= (PTRANSPORT_CONTEXT
)IrpSp
->FileObject
->FsContext
;
1278 switch ((ULONG
)IrpSp
->FileObject
->FsContext2
) {
1279 case TDI_TRANSPORT_ADDRESS_FILE
:
1280 Request
.Handle
.AddressHandle
= TranContext
->Handle
.AddressHandle
;
1283 case TDI_CONNECTION_FILE
:
1284 Request
.Handle
.ConnectionContext
= TranContext
->Handle
.ConnectionContext
;
1287 case TDI_CONTROL_CHANNEL_FILE
:
1288 Request
.Handle
.ControlChannel
= TranContext
->Handle
.ControlChannel
;
1292 TI_DbgPrint(MIN_TRACE
, ("Invalid transport context\n"));
1293 return STATUS_INVALID_PARAMETER
;
1296 InputBufferLength
= IrpSp
->Parameters
.DeviceIoControl
.InputBufferLength
;
1297 OutputBufferLength
= IrpSp
->Parameters
.DeviceIoControl
.OutputBufferLength
;
1299 /* Validate parameters */
1300 if ((InputBufferLength
== sizeof(TCP_REQUEST_QUERY_INFORMATION_EX
)) &&
1301 (OutputBufferLength
!= 0)) {
1303 InputBuffer
= (PTCP_REQUEST_QUERY_INFORMATION_EX
)
1304 IrpSp
->Parameters
.DeviceIoControl
.Type3InputBuffer
;
1305 OutputBuffer
= Irp
->UserBuffer
;
1307 QueryContext
= ExAllocatePool(NonPagedPool
, sizeof(TI_QUERY_CONTEXT
));
1310 InputMdl
= IoAllocateMdl(InputBuffer
,
1311 sizeof(TCP_REQUEST_QUERY_INFORMATION_EX
),
1314 OutputMdl
= IoAllocateMdl(OutputBuffer
,
1315 OutputBufferLength
, FALSE
, TRUE
, NULL
);
1317 if (InputMdl
&& OutputMdl
) {
1319 MmProbeAndLockPages(InputMdl
, Irp
->RequestorMode
,
1322 InputMdlLocked
= TRUE
;
1324 MmProbeAndLockPages(OutputMdl
, Irp
->RequestorMode
,
1327 OutputMdlLocked
= TRUE
;
1329 RtlCopyMemory(&QueryContext
->QueryInfo
,
1330 InputBuffer
, sizeof(TCP_REQUEST_QUERY_INFORMATION_EX
));
1332 Status
= STATUS_INSUFFICIENT_RESOURCES
;
1334 Status
= _SEH_GetExceptionCode();
1337 if (NT_SUCCESS(Status
)) {
1338 Size
= MmGetMdlByteCount(OutputMdl
);
1340 QueryContext
->Irp
= Irp
;
1341 QueryContext
->InputMdl
= InputMdl
;
1342 QueryContext
->OutputMdl
= OutputMdl
;
1344 Request
.RequestNotifyObject
= DispTdiQueryInformationExComplete
;
1345 Request
.RequestContext
= QueryContext
;
1346 Status
= InfoTdiQueryInformationEx(&Request
,
1347 &QueryContext
->QueryInfo
.ID
, OutputMdl
,
1348 &Size
, &QueryContext
->QueryInfo
.Context
);
1349 DispTdiQueryInformationExComplete(QueryContext
, Status
, Size
);
1351 TI_DbgPrint(MAX_TRACE
, ("Leaving. Status = (0x%X)\n", Status
));
1356 /* An error occurred if we get here */
1360 MmUnlockPages(InputMdl
);
1361 IoFreeMdl(InputMdl
);
1365 if (OutputMdlLocked
)
1366 MmUnlockPages(OutputMdl
);
1367 IoFreeMdl(OutputMdl
);
1370 ExFreePool(QueryContext
);
1372 Status
= STATUS_INSUFFICIENT_RESOURCES
;
1373 } else if( InputBufferLength
==
1374 sizeof(TCP_REQUEST_QUERY_INFORMATION_EX
) ) {
1375 /* Handle the case where the user is probing the buffer for length */
1376 TI_DbgPrint(MAX_TRACE
, ("InputBufferLength %d OutputBufferLength %d\n",
1377 InputBufferLength
, OutputBufferLength
));
1378 InputBuffer
= (PTCP_REQUEST_QUERY_INFORMATION_EX
)
1379 IrpSp
->Parameters
.DeviceIoControl
.Type3InputBuffer
;
1383 QueryContext
= ExAllocatePool(NonPagedPool
, sizeof(TI_QUERY_CONTEXT
));
1384 if (!QueryContext
) return STATUS_INSUFFICIENT_RESOURCES
;
1387 InputMdl
= IoAllocateMdl(InputBuffer
,
1388 sizeof(TCP_REQUEST_QUERY_INFORMATION_EX
),
1391 MmProbeAndLockPages(InputMdl
, Irp
->RequestorMode
,
1394 InputMdlLocked
= TRUE
;
1395 Status
= STATUS_SUCCESS
;
1397 TI_DbgPrint(MAX_TRACE
, ("Failed to acquire client buffer\n"));
1398 Status
= _SEH_GetExceptionCode();
1401 if( !NT_SUCCESS(Status
) || !InputMdl
) {
1402 if( InputMdl
) IoFreeMdl( InputMdl
);
1403 ExFreePool(QueryContext
);
1407 RtlCopyMemory(&QueryContext
->QueryInfo
,
1408 InputBuffer
, sizeof(TCP_REQUEST_QUERY_INFORMATION_EX
));
1410 QueryContext
->Irp
= Irp
;
1411 QueryContext
->InputMdl
= InputMdl
;
1412 QueryContext
->OutputMdl
= NULL
;
1414 Request
.RequestNotifyObject
= DispTdiQueryInformationExComplete
;
1415 Request
.RequestContext
= QueryContext
;
1416 Status
= InfoTdiQueryInformationEx(&Request
,
1417 &QueryContext
->QueryInfo
.ID
,
1420 &QueryContext
->QueryInfo
.Context
);
1421 DispTdiQueryInformationExComplete(QueryContext
, Status
, Size
);
1422 TI_DbgPrint(MAX_TRACE
, ("Leaving. Status = (0x%X)\n", Status
));
1423 } else Status
= STATUS_INVALID_PARAMETER
;
1425 TI_DbgPrint(MIN_TRACE
, ("Leaving. Status = (0x%X)\n", Status
));
1431 NTSTATUS
DispTdiSetInformationEx(
1433 PIO_STACK_LOCATION IrpSp
)
1435 * FUNCTION: TDI SetInformationEx handler
1437 * Irp = Pointer to I/O request packet
1438 * IrpSp = Pointer to current stack location of Irp
1440 * Status of operation
1443 PTRANSPORT_CONTEXT TranContext
;
1444 PTCP_REQUEST_SET_INFORMATION_EX Info
;
1445 TDI_REQUEST Request
;
1449 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
1451 TranContext
= (PTRANSPORT_CONTEXT
)IrpSp
->FileObject
->FsContext
;
1452 Info
= (PTCP_REQUEST_SET_INFORMATION_EX
)Irp
->AssociatedIrp
.SystemBuffer
;
1454 switch ((ULONG
)IrpSp
->FileObject
->FsContext2
) {
1455 case TDI_TRANSPORT_ADDRESS_FILE
:
1456 Request
.Handle
.AddressHandle
= TranContext
->Handle
.AddressHandle
;
1459 case TDI_CONNECTION_FILE
:
1460 Request
.Handle
.ConnectionContext
= TranContext
->Handle
.ConnectionContext
;
1463 case TDI_CONTROL_CHANNEL_FILE
:
1464 Request
.Handle
.ControlChannel
= TranContext
->Handle
.ControlChannel
;
1468 Irp
->IoStatus
.Status
= STATUS_INVALID_PARAMETER
;
1469 Irp
->IoStatus
.Information
= 0;
1471 TI_DbgPrint(DEBUG_IRP
, ("Completing IRP at (0x%X).\n", Irp
));
1473 return IRPFinish(Irp
, STATUS_INVALID_PARAMETER
);
1476 Status
= DispPrepareIrpForCancel(TranContext
, Irp
, NULL
);
1477 if (NT_SUCCESS(Status
)) {
1478 Request
.RequestNotifyObject
= DispDataRequestComplete
;
1479 Request
.RequestContext
= Irp
;
1481 Status
= InfoTdiSetInformationEx(&Request
, &Info
->ID
,
1482 &Info
->Buffer
, Info
->BufferSize
);
1484 if (Status
!= STATUS_PENDING
) {
1485 IoAcquireCancelSpinLock(&OldIrql
);
1486 IoSetCancelRoutine(Irp
, NULL
);
1487 IoReleaseCancelSpinLock(OldIrql
);
1494 /* TODO: Support multiple addresses per interface.
1495 * For now just set the nte context to the interface index.
1497 * Later on, create an NTE context and NTE instance
1500 NTSTATUS
DispTdiSetIPAddress( PIRP Irp
, PIO_STACK_LOCATION IrpSp
) {
1501 NTSTATUS Status
= STATUS_DEVICE_DOES_NOT_EXIST
;
1502 PIP_SET_ADDRESS IpAddrChange
=
1503 (PIP_SET_ADDRESS
)Irp
->AssociatedIrp
.SystemBuffer
;
1506 ForEachInterface(IF
) {
1507 if( IF
->Unicast
.Address
.IPv4Address
== IpAddrChange
->Address
) {
1508 Status
= STATUS_DUPLICATE_OBJECTID
;
1511 if( IF
->Index
== IpAddrChange
->NteIndex
) {
1512 IPRemoveInterfaceRoute( IF
);
1514 IF
->Unicast
.Type
= IP_ADDRESS_V4
;
1515 IF
->Unicast
.Address
.IPv4Address
= IpAddrChange
->Address
;
1516 IF
->Netmask
.Type
= IP_ADDRESS_V4
;
1517 IF
->Netmask
.Address
.IPv4Address
= IpAddrChange
->Netmask
;
1519 TI_DbgPrint(MID_TRACE
,("New Unicast Address: %x\n",
1520 IF
->Unicast
.Address
.IPv4Address
));
1521 TI_DbgPrint(MID_TRACE
,("New Netmask : %x\n",
1522 IF
->Netmask
.Address
.IPv4Address
));
1524 IPAddInterfaceRoute( IF
);
1526 IpAddrChange
->Address
= IF
->Index
;
1527 Status
= STATUS_SUCCESS
;
1528 Irp
->IoStatus
.Information
= IF
->Index
;
1533 Irp
->IoStatus
.Status
= Status
;
1537 NTSTATUS
DispTdiDeleteIPAddress( PIRP Irp
, PIO_STACK_LOCATION IrpSp
) {
1538 NTSTATUS Status
= STATUS_UNSUCCESSFUL
;
1539 PUSHORT NteIndex
= Irp
->AssociatedIrp
.SystemBuffer
;
1542 ForEachInterface(IF
) {
1543 if( IF
->Index
== *NteIndex
) {
1544 IF
->Unicast
.Type
= IP_ADDRESS_V4
;
1545 IF
->Unicast
.Address
.IPv4Address
= 0;
1546 IF
->Netmask
.Type
= IP_ADDRESS_V4
;
1547 IF
->Netmask
.Address
.IPv4Address
= 0;
1548 Status
= STATUS_SUCCESS
;
1552 Irp
->IoStatus
.Status
= Status
;