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
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"));
139 VOID DDKAPI
DispCancelRequest(
140 PDEVICE_OBJECT Device
,
143 * FUNCTION: Cancels an IRP
145 * Device = Pointer to device object
146 * Irp = Pointer to an I/O request packet
149 PIO_STACK_LOCATION IrpSp
;
150 PTRANSPORT_CONTEXT TranContext
;
151 PFILE_OBJECT FileObject
;
153 /*NTSTATUS Status = STATUS_SUCCESS;*/
155 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
157 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
158 FileObject
= IrpSp
->FileObject
;
159 TranContext
= (PTRANSPORT_CONTEXT
)FileObject
->FsContext
;
160 MinorFunction
= IrpSp
->MinorFunction
;
162 TI_DbgPrint(DEBUG_IRP
, ("IRP at (0x%X) MinorFunction (0x%X) IrpSp (0x%X).\n", Irp
, MinorFunction
, IrpSp
));
166 TI_DbgPrint(MIN_TRACE
, ("Irp->Cancel is FALSE, should be TRUE.\n"));
169 /* Try canceling the request */
170 switch(MinorFunction
) {
173 ( TranContext
->Handle
.ConnectionContext
,
174 TDI_DISCONNECT_RELEASE
,
177 DispDataRequestComplete
,
183 ( TranContext
->Handle
.ConnectionContext
,
184 TDI_DISCONNECT_ABORT
| TDI_DISCONNECT_RELEASE
,
187 DispDataRequestComplete
,
191 case TDI_SEND_DATAGRAM
:
192 if (FileObject
->FsContext2
!= (PVOID
)TDI_TRANSPORT_ADDRESS_FILE
) {
193 TI_DbgPrint(MIN_TRACE
, ("TDI_SEND_DATAGRAM, but no address file.\n"));
197 /*DGCancelSendRequest(TranContext->Handle.AddressHandle, Irp);*/
200 case TDI_RECEIVE_DATAGRAM
:
201 if (FileObject
->FsContext2
!= (PVOID
)TDI_TRANSPORT_ADDRESS_FILE
) {
202 TI_DbgPrint(MIN_TRACE
, ("TDI_RECEIVE_DATAGRAM, but no address file.\n"));
206 /*DGCancelReceiveRequest(TranContext->Handle.AddressHandle, Irp);*/
210 TI_DbgPrint(MIN_TRACE
, ("Unknown IRP. MinorFunction (0x%X).\n", MinorFunction
));
214 IoReleaseCancelSpinLock(Irp
->CancelIrql
);
216 DispCancelComplete(FileObject
);
218 TI_DbgPrint(MAX_TRACE
, ("Leaving.\n"));
222 VOID DDKAPI
DispCancelListenRequest(
223 PDEVICE_OBJECT Device
,
226 * FUNCTION: Cancels a listen IRP
228 * Device = Pointer to device object
229 * Irp = Pointer to an I/O request packet
232 PIO_STACK_LOCATION IrpSp
;
233 PTRANSPORT_CONTEXT TranContext
;
234 PFILE_OBJECT FileObject
;
235 PCONNECTION_ENDPOINT Connection
;
236 /*NTSTATUS Status = STATUS_SUCCESS;*/
238 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
240 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
241 FileObject
= IrpSp
->FileObject
;
242 TranContext
= (PTRANSPORT_CONTEXT
)FileObject
->FsContext
;
243 ASSERT( TDI_LISTEN
== IrpSp
->MinorFunction
);
245 TI_DbgPrint(DEBUG_IRP
, ("IRP at (0x%X).\n", Irp
));
249 TI_DbgPrint(MIN_TRACE
, ("Irp->Cancel is FALSE, should be TRUE.\n"));
252 /* Try canceling the request */
253 Connection
= (PCONNECTION_ENDPOINT
)TranContext
->Handle
.ConnectionContext
;
254 TCPAbortListenForSocket(
255 Connection
->AddressFile
->Listener
,
258 IoReleaseCancelSpinLock(Irp
->CancelIrql
);
260 DispDataRequestComplete(Irp
, STATUS_CANCELLED
, 0);
262 DispCancelComplete(FileObject
);
264 TI_DbgPrint(MAX_TRACE
, ("Leaving.\n"));
268 NTSTATUS
DispTdiAccept(
271 * FUNCTION: TDI_ACCEPT handler
273 * Irp = Pointer to an I/O request packet
275 * Status of operation
278 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
280 return STATUS_NOT_IMPLEMENTED
;
284 NTSTATUS
DispTdiAssociateAddress(
287 * FUNCTION: TDI_ASSOCIATE_ADDRESS handler
289 * Irp = Pointer to an I/O request packet
291 * Status of operation
294 PTDI_REQUEST_KERNEL_ASSOCIATE Parameters
;
295 PTRANSPORT_CONTEXT TranContext
;
296 PIO_STACK_LOCATION IrpSp
;
297 PCONNECTION_ENDPOINT Connection
;
298 PFILE_OBJECT FileObject
;
299 PADDRESS_FILE AddrFile
= NULL
;
302 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
304 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
306 /* Get associated connection endpoint file object. Quit if none exists */
308 TranContext
= IrpSp
->FileObject
->FsContext
;
310 TI_DbgPrint(MID_TRACE
, ("Bad transport context.\n"));
311 return STATUS_INVALID_PARAMETER
;
314 Connection
= (PCONNECTION_ENDPOINT
)TranContext
->Handle
.ConnectionContext
;
316 TI_DbgPrint(MID_TRACE
, ("No connection endpoint file object.\n"));
317 return STATUS_INVALID_PARAMETER
;
320 if (Connection
->AddressFile
) {
321 TI_DbgPrint(MID_TRACE
, ("An address file is already asscociated.\n"));
322 return STATUS_INVALID_PARAMETER
;
325 Parameters
= (PTDI_REQUEST_KERNEL_ASSOCIATE
)&IrpSp
->Parameters
;
327 Status
= ObReferenceObjectByHandle(
328 Parameters
->AddressHandle
,
334 if (!NT_SUCCESS(Status
)) {
335 TI_DbgPrint(MID_TRACE
, ("Bad address file object handle (0x%X): %x.\n",
336 Parameters
->AddressHandle
, Status
));
337 return STATUS_INVALID_PARAMETER
;
340 if (FileObject
->FsContext2
!= (PVOID
)TDI_TRANSPORT_ADDRESS_FILE
) {
341 ObDereferenceObject(FileObject
);
342 TI_DbgPrint(MID_TRACE
, ("Bad address file object. Magic (0x%X).\n",
343 FileObject
->FsContext2
));
344 return STATUS_INVALID_PARAMETER
;
347 /* Get associated address file object. Quit if none exists */
349 TranContext
= FileObject
->FsContext
;
351 ObDereferenceObject(FileObject
);
352 TI_DbgPrint(MID_TRACE
, ("Bad transport context.\n"));
353 return STATUS_INVALID_PARAMETER
;
356 AddrFile
= (PADDRESS_FILE
)TranContext
->Handle
.AddressHandle
;
358 ObDereferenceObject(FileObject
);
359 TI_DbgPrint(MID_TRACE
, ("No address file object.\n"));
360 return STATUS_INVALID_PARAMETER
;
363 Connection
->AddressFile
= AddrFile
;
365 /* Add connection endpoint to the address file */
366 AddrFile
->Connection
= Connection
;
368 /* FIXME: Maybe do this in DispTdiDisassociateAddress() instead? */
369 ObDereferenceObject(FileObject
);
375 NTSTATUS
DispTdiConnect(
378 * FUNCTION: TDI_CONNECT handler
380 * Irp = Pointer to an I/O request packet
382 * Status of operation
385 PCONNECTION_ENDPOINT Connection
;
386 PTDI_REQUEST_KERNEL Parameters
;
387 PTRANSPORT_CONTEXT TranContext
;
388 PIO_STACK_LOCATION IrpSp
;
391 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
393 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
395 /* Get associated connection endpoint file object. Quit if none exists */
397 TranContext
= IrpSp
->FileObject
->FsContext
;
399 TI_DbgPrint(MID_TRACE
, ("Bad transport context.\n"));
400 return STATUS_INVALID_CONNECTION
;
403 Connection
= (PCONNECTION_ENDPOINT
)TranContext
->Handle
.ConnectionContext
;
405 TI_DbgPrint(MID_TRACE
, ("No connection endpoint file object.\n"));
406 return STATUS_INVALID_CONNECTION
;
409 Parameters
= (PTDI_REQUEST_KERNEL
)&IrpSp
->Parameters
;
412 TranContext
->Handle
.ConnectionContext
,
413 Parameters
->RequestConnectionInformation
,
414 Parameters
->ReturnConnectionInformation
,
415 DispDataRequestComplete
,
418 TI_DbgPrint(MAX_TRACE
, ("TCP Connect returned %08x\n", Status
));
424 NTSTATUS
DispTdiDisassociateAddress(
427 * FUNCTION: TDI_DISASSOCIATE_ADDRESS handler
429 * Irp = Pointer to an I/O request packet
431 * Status of operation
434 PCONNECTION_ENDPOINT Connection
;
435 PTRANSPORT_CONTEXT TranContext
;
436 PIO_STACK_LOCATION IrpSp
;
438 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
440 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
442 /* Get associated connection endpoint file object. Quit if none exists */
444 TranContext
= IrpSp
->FileObject
->FsContext
;
446 TI_DbgPrint(MID_TRACE
, ("Bad transport context.\n"));
447 return STATUS_INVALID_PARAMETER
;
450 Connection
= (PCONNECTION_ENDPOINT
)TranContext
->Handle
.ConnectionContext
;
452 TI_DbgPrint(MID_TRACE
, ("No connection endpoint file object.\n"));
453 return STATUS_INVALID_PARAMETER
;
456 if (!Connection
->AddressFile
) {
457 TI_DbgPrint(MID_TRACE
, ("No address file is asscociated.\n"));
458 return STATUS_INVALID_PARAMETER
;
461 return STATUS_SUCCESS
;
465 NTSTATUS
DispTdiDisconnect(
468 * FUNCTION: TDI_DISCONNECT handler
470 * Irp = Pointer to an I/O request packet
472 * Status of operation
476 PTDI_REQUEST_KERNEL_DISCONNECT DisReq
;
477 PCONNECTION_ENDPOINT Connection
;
478 PTRANSPORT_CONTEXT TranContext
;
479 PIO_STACK_LOCATION IrpSp
;
481 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
483 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
484 DisReq
= (PTDI_REQUEST_KERNEL_DISCONNECT
)&IrpSp
->Parameters
;
486 /* Get associated connection endpoint file object. Quit if none exists */
488 TranContext
= IrpSp
->FileObject
->FsContext
;
490 TI_DbgPrint(MID_TRACE
, ("Bad transport context.\n"));
491 return STATUS_INVALID_CONNECTION
;
494 Connection
= (PCONNECTION_ENDPOINT
)TranContext
->Handle
.ConnectionContext
;
496 TI_DbgPrint(MID_TRACE
, ("No connection endpoint file object.\n"));
497 return STATUS_INVALID_CONNECTION
;
500 Status
= TCPDisconnect(
501 TranContext
->Handle
.ConnectionContext
,
502 DisReq
->RequestFlags
,
503 DisReq
->RequestConnectionInformation
,
504 DisReq
->ReturnConnectionInformation
,
505 DispDataRequestComplete
,
508 TI_DbgPrint(MAX_TRACE
, ("TCP Connect returned %08x\n", Status
));
514 NTSTATUS
DispTdiListen(
517 * FUNCTION: TDI_LISTEN handler
519 * Irp = Pointer to an I/O request packet
521 * Status of operation
524 PCONNECTION_ENDPOINT Connection
;
525 PTDI_REQUEST_KERNEL Parameters
;
526 PTRANSPORT_CONTEXT TranContext
;
527 PIO_STACK_LOCATION IrpSp
;
528 NTSTATUS Status
= STATUS_SUCCESS
;
530 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
532 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
534 /* Get associated connection endpoint file object. Quit if none exists */
536 TranContext
= IrpSp
->FileObject
->FsContext
;
537 if (TranContext
== NULL
)
539 TI_DbgPrint(MID_TRACE
, ("Bad transport context.\n"));
540 return STATUS_INVALID_CONNECTION
;
543 Connection
= (PCONNECTION_ENDPOINT
)TranContext
->Handle
.ConnectionContext
;
544 if (Connection
== NULL
)
546 TI_DbgPrint(MID_TRACE
, ("No connection endpoint file object.\n"));
547 return STATUS_INVALID_CONNECTION
;
550 Parameters
= (PTDI_REQUEST_KERNEL
)&IrpSp
->Parameters
;
552 TI_DbgPrint(MIN_TRACE
, ("Connection->AddressFile: %x\n",
553 Connection
->AddressFile
));
554 if( Connection
->AddressFile
) {
555 TI_DbgPrint(MIN_TRACE
, ("Connection->AddressFile->Listener: %x\n",
556 Connection
->AddressFile
->Listener
));
559 /* Listening will require us to create a listening socket and store it in
560 * the address file. It will be signalled, and attempt to complete an irp
561 * when a new connection arrives. */
562 /* The important thing to note here is that the irp we'll complete belongs
563 * to the socket to be accepted onto, not the listener */
564 if( !Connection
->AddressFile
->Listener
) {
565 Connection
->AddressFile
->Listener
=
566 TCPAllocateConnectionEndpoint( NULL
);
568 if( !Connection
->AddressFile
->Listener
)
569 Status
= STATUS_NO_MEMORY
;
571 if( NT_SUCCESS(Status
) ) {
572 Connection
->AddressFile
->Listener
->AddressFile
=
573 Connection
->AddressFile
;
575 Status
= TCPSocket( Connection
->AddressFile
->Listener
,
576 Connection
->AddressFile
->Family
,
578 Connection
->AddressFile
->Protocol
);
581 if( NT_SUCCESS(Status
) )
582 Status
= TCPListen( Connection
->AddressFile
->Listener
, 1024 );
585 if( NT_SUCCESS(Status
) ) {
586 Status
= DispPrepareIrpForCancel
587 (TranContext
->Handle
.ConnectionContext
,
589 (PDRIVER_CANCEL
)DispCancelListenRequest
);
592 if( NT_SUCCESS(Status
) ) {
594 ( (PTDI_REQUEST
)Parameters
,
595 Connection
->AddressFile
->Listener
,
597 DispDataRequestComplete
,
601 TI_DbgPrint(MID_TRACE
,("Leaving %x\n", Status
));
607 NTSTATUS
DispTdiQueryInformation(
608 PDEVICE_OBJECT DeviceObject
,
611 * FUNCTION: TDI_QUERY_INFORMATION handler
613 * DeviceObject = Pointer to device object structure
614 * Irp = Pointer to an I/O request packet
616 * Status of operation
619 PTDI_REQUEST_KERNEL_QUERY_INFORMATION Parameters
;
620 PTRANSPORT_CONTEXT TranContext
;
621 PIO_STACK_LOCATION IrpSp
;
623 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
625 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
626 Parameters
= (PTDI_REQUEST_KERNEL_QUERY_INFORMATION
)&IrpSp
->Parameters
;
628 TranContext
= IrpSp
->FileObject
->FsContext
;
630 TI_DbgPrint(MID_TRACE
, ("Bad transport context.\n"));
631 return STATUS_INVALID_CONNECTION
;
634 switch (Parameters
->QueryType
)
636 case TDI_QUERY_ADDRESS_INFO
:
638 PTDI_ADDRESS_INFO AddressInfo
;
639 PADDRESS_FILE AddrFile
;
640 PTA_IP_ADDRESS Address
;
642 AddressInfo
= (PTDI_ADDRESS_INFO
)MmGetSystemAddressForMdl(Irp
->MdlAddress
);
644 switch ((ULONG
)IrpSp
->FileObject
->FsContext2
) {
645 case TDI_TRANSPORT_ADDRESS_FILE
:
646 AddrFile
= (PADDRESS_FILE
)TranContext
->Handle
.AddressHandle
;
649 case TDI_CONNECTION_FILE
:
651 ((PCONNECTION_ENDPOINT
)TranContext
->Handle
.ConnectionContext
)->
656 TI_DbgPrint(MIN_TRACE
, ("Invalid transport context\n"));
657 return STATUS_INVALID_PARAMETER
;
661 TI_DbgPrint(MID_TRACE
, ("No address file object.\n"));
662 return STATUS_INVALID_PARAMETER
;
665 if (MmGetMdlByteCount(Irp
->MdlAddress
) <
666 (FIELD_OFFSET(TDI_ADDRESS_INFO
, Address
.Address
[0].Address
) +
667 sizeof(TDI_ADDRESS_IP
))) {
668 TI_DbgPrint(MID_TRACE
, ("MDL buffer too small.\n"));
669 return STATUS_BUFFER_OVERFLOW
;
672 Address
= (PTA_IP_ADDRESS
)&AddressInfo
->Address
;
673 Address
->TAAddressCount
= 1;
674 Address
->Address
[0].AddressLength
= TDI_ADDRESS_LENGTH_IP
;
675 Address
->Address
[0].AddressType
= TDI_ADDRESS_TYPE_IP
;
676 Address
->Address
[0].Address
[0].sin_port
= AddrFile
->Port
;
677 Address
->Address
[0].Address
[0].in_addr
=
678 AddrFile
->Address
.Address
.IPv4Address
;
680 &Address
->Address
[0].Address
[0].sin_zero
,
681 sizeof(Address
->Address
[0].Address
[0].sin_zero
));
683 return STATUS_SUCCESS
;
686 case TDI_QUERY_CONNECTION_INFO
:
688 PTDI_CONNECTION_INFORMATION AddressInfo
;
689 PADDRESS_FILE AddrFile
;
690 PCONNECTION_ENDPOINT Endpoint
= NULL
;
692 AddressInfo
= (PTDI_CONNECTION_INFORMATION
)
693 MmGetSystemAddressForMdl(Irp
->MdlAddress
);
695 switch ((ULONG
)IrpSp
->FileObject
->FsContext2
) {
696 case TDI_TRANSPORT_ADDRESS_FILE
:
697 AddrFile
= (PADDRESS_FILE
)TranContext
->Handle
.AddressHandle
;
700 case TDI_CONNECTION_FILE
:
702 (PCONNECTION_ENDPOINT
)TranContext
->Handle
.ConnectionContext
;
706 TI_DbgPrint(MIN_TRACE
, ("Invalid transport context\n"));
707 return STATUS_INVALID_PARAMETER
;
711 TI_DbgPrint(MID_TRACE
, ("No connection object.\n"));
712 return STATUS_INVALID_PARAMETER
;
715 if (MmGetMdlByteCount(Irp
->MdlAddress
) <
716 (FIELD_OFFSET(TDI_CONNECTION_INFORMATION
, RemoteAddress
) +
718 TI_DbgPrint(MID_TRACE
, ("MDL buffer too small (ptr).\n"));
719 return STATUS_BUFFER_OVERFLOW
;
722 return TCPGetPeerAddress( Endpoint
, AddressInfo
->RemoteAddress
);
726 return STATUS_NOT_IMPLEMENTED
;
730 NTSTATUS
DispTdiReceive(
733 * FUNCTION: TDI_RECEIVE handler
735 * Irp = Pointer to an I/O request packet
737 * Status of operation
740 PIO_STACK_LOCATION IrpSp
;
741 PTDI_REQUEST_KERNEL_RECEIVE ReceiveInfo
;
742 PTRANSPORT_CONTEXT TranContext
;
746 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
748 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
749 ReceiveInfo
= (PTDI_REQUEST_KERNEL_RECEIVE
)&(IrpSp
->Parameters
);
751 TranContext
= IrpSp
->FileObject
->FsContext
;
752 if (TranContext
== NULL
)
754 TI_DbgPrint(MID_TRACE
, ("Bad transport context.\n"));
755 return STATUS_INVALID_CONNECTION
;
758 if (TranContext
->Handle
.ConnectionContext
== NULL
)
760 TI_DbgPrint(MID_TRACE
, ("No connection endpoint file object.\n"));
761 return STATUS_INVALID_CONNECTION
;
764 /* Initialize a receive request */
765 Status
= DispPrepareIrpForCancel
766 (TranContext
->Handle
.ConnectionContext
,
768 (PDRIVER_CANCEL
)DispCancelRequest
);
770 TI_DbgPrint(MID_TRACE
,("TCPIP<<< Got an MDL: %x\n", Irp
->MdlAddress
));
771 if (NT_SUCCESS(Status
))
773 Status
= TCPReceiveData(
774 TranContext
->Handle
.ConnectionContext
,
775 (PNDIS_BUFFER
)Irp
->MdlAddress
,
776 ReceiveInfo
->ReceiveLength
,
778 ReceiveInfo
->ReceiveFlags
,
779 DispDataRequestComplete
,
781 if (Status
!= STATUS_PENDING
)
783 DispDataRequestComplete(Irp
, Status
, BytesReceived
);
785 IoMarkIrpPending(Irp
);
788 TI_DbgPrint(DEBUG_IRP
, ("Leaving. Status is (0x%X)\n", Status
));
794 NTSTATUS
DispTdiReceiveDatagram(
797 * FUNCTION: TDI_RECEIVE_DATAGRAM handler
799 * Irp = Pointer to an I/O request packet
801 * Status of operation
804 PIO_STACK_LOCATION IrpSp
;
805 PTDI_REQUEST_KERNEL_RECEIVEDG DgramInfo
;
806 PTRANSPORT_CONTEXT TranContext
;
811 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
813 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
814 DgramInfo
= (PTDI_REQUEST_KERNEL_RECEIVEDG
)&(IrpSp
->Parameters
);
816 TranContext
= IrpSp
->FileObject
->FsContext
;
817 if (TranContext
== NULL
)
819 TI_DbgPrint(MID_TRACE
, ("Bad transport context.\n"));
820 return STATUS_INVALID_ADDRESS
;
823 /* Initialize a receive request */
824 Request
.Handle
.AddressHandle
= TranContext
->Handle
.AddressHandle
;
825 Request
.RequestNotifyObject
= DispDataRequestComplete
;
826 Request
.RequestContext
= Irp
;
828 Status
= DispPrepareIrpForCancel(
829 IrpSp
->FileObject
->FsContext
,
831 (PDRIVER_CANCEL
)DispCancelRequest
);
833 if (NT_SUCCESS(Status
))
838 NdisQueryBuffer( (PNDIS_BUFFER
)Irp
->MdlAddress
,
842 Status
= UDPReceiveDatagram(
843 Request
.Handle
.AddressHandle
,
844 DgramInfo
->ReceiveDatagramInformation
,
846 DgramInfo
->ReceiveLength
,
847 DgramInfo
->ReceiveFlags
,
848 DgramInfo
->ReturnDatagramInformation
,
850 (PDATAGRAM_COMPLETION_ROUTINE
)DispDataRequestComplete
,
852 if (Status
!= STATUS_PENDING
) {
853 DispDataRequestComplete(Irp
, Status
, BytesReceived
);
855 IoMarkIrpPending(Irp
);
858 TI_DbgPrint(DEBUG_IRP
, ("Leaving. Status is (0x%X)\n", Status
));
864 NTSTATUS
DispTdiSend(
867 * FUNCTION: TDI_SEND handler
869 * Irp = Pointer to an I/O request packet
871 * Status of operation
874 PIO_STACK_LOCATION IrpSp
;
875 PTDI_REQUEST_KERNEL_RECEIVE ReceiveInfo
;
876 PTRANSPORT_CONTEXT TranContext
;
880 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
882 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
883 ReceiveInfo
= (PTDI_REQUEST_KERNEL_RECEIVE
)&(IrpSp
->Parameters
);
885 TranContext
= IrpSp
->FileObject
->FsContext
;
886 if (TranContext
== NULL
)
888 TI_DbgPrint(MID_TRACE
, ("Bad transport context.\n"));
889 return STATUS_INVALID_CONNECTION
;
892 if (TranContext
->Handle
.ConnectionContext
== NULL
)
894 TI_DbgPrint(MID_TRACE
, ("No connection endpoint file object.\n"));
895 return STATUS_INVALID_CONNECTION
;
898 Status
= DispPrepareIrpForCancel(
899 IrpSp
->FileObject
->FsContext
,
901 (PDRIVER_CANCEL
)DispCancelRequest
);
903 TI_DbgPrint(MID_TRACE
,("TCPIP<<< Got an MDL: %x\n", Irp
->MdlAddress
));
904 if (NT_SUCCESS(Status
))
909 NdisQueryBuffer( Irp
->MdlAddress
, &Data
, &Len
);
911 TI_DbgPrint(MID_TRACE
,("About to TCPSendData\n"));
912 Status
= TCPSendData(
913 TranContext
->Handle
.ConnectionContext
,
915 ReceiveInfo
->ReceiveLength
,
917 ReceiveInfo
->ReceiveFlags
);
918 if (Status
!= STATUS_PENDING
)
920 DispDataRequestComplete(Irp
, Status
, BytesReceived
);
922 IoMarkIrpPending( Irp
);
925 TI_DbgPrint(DEBUG_IRP
, ("Leaving. Status is (0x%X)\n", Status
));
931 NTSTATUS
DispTdiSendDatagram(
934 * FUNCTION: TDI_SEND_DATAGRAM handler
936 * Irp = Pointer to an I/O request packet
938 * Status of operation
941 PIO_STACK_LOCATION IrpSp
;
943 PTDI_REQUEST_KERNEL_SENDDG DgramInfo
;
944 PTRANSPORT_CONTEXT TranContext
;
947 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
949 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
950 DgramInfo
= (PTDI_REQUEST_KERNEL_SENDDG
)&(IrpSp
->Parameters
);
951 TranContext
= IrpSp
->FileObject
->FsContext
;
953 /* Initialize a send request */
954 Request
.Handle
.AddressHandle
= TranContext
->Handle
.AddressHandle
;
955 Request
.RequestNotifyObject
= DispDataRequestComplete
;
956 Request
.RequestContext
= Irp
;
958 Status
= DispPrepareIrpForCancel(
959 IrpSp
->FileObject
->FsContext
,
961 (PDRIVER_CANCEL
)DispCancelRequest
);
963 if (NT_SUCCESS(Status
)) {
967 TI_DbgPrint(MID_TRACE
,("About to query buffer %x\n", Irp
->MdlAddress
));
969 NdisQueryBuffer( (PNDIS_BUFFER
)Irp
->MdlAddress
,
973 /* FIXME: DgramInfo->SendDatagramInformation->RemoteAddress
974 must be of type PTDI_ADDRESS_IP */
975 TI_DbgPrint(MID_TRACE
,
976 ("About to call send routine %x\n",
977 (*((PADDRESS_FILE
)Request
.Handle
.AddressHandle
)->Send
)));
979 if( (*((PADDRESS_FILE
)Request
.Handle
.AddressHandle
)->Send
) )
980 Status
= (*((PADDRESS_FILE
)Request
.Handle
.AddressHandle
)->Send
)(
981 Request
.Handle
.AddressHandle
,
982 DgramInfo
->SendDatagramInformation
,
985 &Irp
->IoStatus
.Information
);
987 Status
= STATUS_UNSUCCESSFUL
;
989 if (Status
!= STATUS_PENDING
) {
990 DispDataRequestComplete(Irp
, Status
, Irp
->IoStatus
.Information
);
991 /* Return STATUS_PENDING because DispPrepareIrpForCancel
992 marks Irp as pending */
993 Status
= STATUS_PENDING
;
995 IoMarkIrpPending( Irp
);
998 TI_DbgPrint(DEBUG_IRP
, ("Leaving.\n"));
1004 NTSTATUS
DispTdiSetEventHandler(PIRP Irp
)
1006 * FUNCTION: TDI_SET_EVENT_HANDER handler
1008 * Irp = Pointer to a I/O request packet
1010 * Status of operation
1013 PTDI_REQUEST_KERNEL_SET_EVENT Parameters
;
1014 PTRANSPORT_CONTEXT TranContext
;
1015 PIO_STACK_LOCATION IrpSp
;
1016 PADDRESS_FILE AddrFile
;
1020 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
1022 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
1024 /* Get associated address file object. Quit if none exists */
1026 TranContext
= IrpSp
->FileObject
->FsContext
;
1028 TI_DbgPrint(MIN_TRACE
, ("Bad transport context.\n"));
1029 return STATUS_INVALID_PARAMETER
;
1032 AddrFile
= (PADDRESS_FILE
)TranContext
->Handle
.AddressHandle
;
1034 TI_DbgPrint(MIN_TRACE
, ("No address file object.\n"));
1035 return STATUS_INVALID_PARAMETER
;
1038 Parameters
= (PTDI_REQUEST_KERNEL_SET_EVENT
)&IrpSp
->Parameters
;
1039 Status
= STATUS_SUCCESS
;
1041 TcpipAcquireSpinLock(&AddrFile
->Lock
, &OldIrql
);
1043 /* Set the event handler. if an event handler is associated with
1044 a specific event, it's flag (RegisteredXxxHandler) is TRUE.
1045 If an event handler is not used it's flag is FALSE */
1046 switch (Parameters
->EventType
) {
1047 case TDI_EVENT_CONNECT
:
1048 if (!Parameters
->EventHandler
) {
1049 AddrFile
->ConnectHandlerContext
= NULL
;
1050 AddrFile
->RegisteredConnectHandler
= FALSE
;
1052 AddrFile
->ConnectHandler
=
1053 (PTDI_IND_CONNECT
)Parameters
->EventHandler
;
1054 AddrFile
->ConnectHandlerContext
= Parameters
->EventContext
;
1055 AddrFile
->RegisteredConnectHandler
= TRUE
;
1059 case TDI_EVENT_DISCONNECT
:
1060 if (!Parameters
->EventHandler
) {
1061 AddrFile
->DisconnectHandlerContext
= NULL
;
1062 AddrFile
->RegisteredDisconnectHandler
= FALSE
;
1064 AddrFile
->DisconnectHandler
=
1065 (PTDI_IND_DISCONNECT
)Parameters
->EventHandler
;
1066 AddrFile
->DisconnectHandlerContext
= Parameters
->EventContext
;
1067 AddrFile
->RegisteredDisconnectHandler
= TRUE
;
1071 case TDI_EVENT_ERROR
:
1072 if (Parameters
->EventHandler
== NULL
) {
1073 AddrFile
->ErrorHandlerContext
= NULL
;
1074 AddrFile
->RegisteredErrorHandler
= FALSE
;
1076 AddrFile
->ErrorHandler
=
1077 (PTDI_IND_ERROR
)Parameters
->EventHandler
;
1078 AddrFile
->ErrorHandlerContext
= Parameters
->EventContext
;
1079 AddrFile
->RegisteredErrorHandler
= TRUE
;
1083 case TDI_EVENT_RECEIVE
:
1084 if (Parameters
->EventHandler
== NULL
) {
1085 AddrFile
->ReceiveHandlerContext
= NULL
;
1086 AddrFile
->RegisteredReceiveHandler
= FALSE
;
1088 AddrFile
->ReceiveHandler
=
1089 (PTDI_IND_RECEIVE
)Parameters
->EventHandler
;
1090 AddrFile
->ReceiveHandlerContext
= Parameters
->EventContext
;
1091 AddrFile
->RegisteredReceiveHandler
= TRUE
;
1095 case TDI_EVENT_RECEIVE_DATAGRAM
:
1096 if (Parameters
->EventHandler
== NULL
) {
1097 AddrFile
->ReceiveDatagramHandlerContext
= NULL
;
1098 AddrFile
->RegisteredReceiveDatagramHandler
= FALSE
;
1100 AddrFile
->ReceiveDatagramHandler
=
1101 (PTDI_IND_RECEIVE_DATAGRAM
)Parameters
->EventHandler
;
1102 AddrFile
->ReceiveDatagramHandlerContext
= Parameters
->EventContext
;
1103 AddrFile
->RegisteredReceiveDatagramHandler
= TRUE
;
1107 case TDI_EVENT_RECEIVE_EXPEDITED
:
1108 if (Parameters
->EventHandler
== NULL
) {
1109 AddrFile
->ExpeditedReceiveHandlerContext
= NULL
;
1110 AddrFile
->RegisteredExpeditedReceiveHandler
= FALSE
;
1112 AddrFile
->ExpeditedReceiveHandler
=
1113 (PTDI_IND_RECEIVE_EXPEDITED
)Parameters
->EventHandler
;
1114 AddrFile
->ExpeditedReceiveHandlerContext
= Parameters
->EventContext
;
1115 AddrFile
->RegisteredExpeditedReceiveHandler
= TRUE
;
1119 case TDI_EVENT_CHAINED_RECEIVE
:
1120 if (Parameters
->EventHandler
== NULL
) {
1121 AddrFile
->ChainedReceiveHandlerContext
= NULL
;
1122 AddrFile
->RegisteredChainedReceiveHandler
= FALSE
;
1124 AddrFile
->ChainedReceiveHandler
=
1125 (PTDI_IND_CHAINED_RECEIVE
)Parameters
->EventHandler
;
1126 AddrFile
->ChainedReceiveHandlerContext
= Parameters
->EventContext
;
1127 AddrFile
->RegisteredChainedReceiveHandler
= TRUE
;
1131 case TDI_EVENT_CHAINED_RECEIVE_DATAGRAM
:
1132 if (Parameters
->EventHandler
== NULL
) {
1133 AddrFile
->ChainedReceiveDatagramHandlerContext
= NULL
;
1134 AddrFile
->RegisteredChainedReceiveDatagramHandler
= FALSE
;
1136 AddrFile
->ChainedReceiveDatagramHandler
=
1137 (PTDI_IND_CHAINED_RECEIVE_DATAGRAM
)Parameters
->EventHandler
;
1138 AddrFile
->ChainedReceiveDatagramHandlerContext
= Parameters
->EventContext
;
1139 AddrFile
->RegisteredChainedReceiveDatagramHandler
= TRUE
;
1143 case TDI_EVENT_CHAINED_RECEIVE_EXPEDITED
:
1144 if (Parameters
->EventHandler
== NULL
) {
1145 AddrFile
->ChainedReceiveExpeditedHandlerContext
= NULL
;
1146 AddrFile
->RegisteredChainedReceiveExpeditedHandler
= FALSE
;
1148 AddrFile
->ChainedReceiveExpeditedHandler
=
1149 (PTDI_IND_CHAINED_RECEIVE_EXPEDITED
)Parameters
->EventHandler
;
1150 AddrFile
->ChainedReceiveExpeditedHandlerContext
= Parameters
->EventContext
;
1151 AddrFile
->RegisteredChainedReceiveExpeditedHandler
= TRUE
;
1156 TI_DbgPrint(MIN_TRACE
, ("Unknown event type (0x%X).\n",
1157 Parameters
->EventType
));
1159 Status
= STATUS_INVALID_PARAMETER
;
1162 TcpipReleaseSpinLock(&AddrFile
->Lock
, OldIrql
);
1168 NTSTATUS
DispTdiSetInformation(
1171 * FUNCTION: TDI_SET_INFORMATION handler
1173 * Irp = Pointer to an I/O request packet
1175 * Status of operation
1178 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
1180 return STATUS_NOT_IMPLEMENTED
;
1184 VOID
DispTdiQueryInformationExComplete(
1189 * FUNCTION: Completes a TDI QueryInformationEx request
1191 * Context = Pointer to the IRP for the request
1192 * Status = TDI status of the request
1193 * ByteCount = Number of bytes returned in output buffer
1196 PTI_QUERY_CONTEXT QueryContext
;
1199 QueryContext
= (PTI_QUERY_CONTEXT
)Context
;
1200 if (NT_SUCCESS(Status
)) {
1201 Count
= CopyBufferToBufferChain(
1202 QueryContext
->InputMdl
,
1203 FIELD_OFFSET(TCP_REQUEST_QUERY_INFORMATION_EX
, Context
),
1204 (PCHAR
)&QueryContext
->QueryInfo
.Context
,
1208 MmUnlockPages(QueryContext
->InputMdl
);
1209 IoFreeMdl(QueryContext
->InputMdl
);
1210 if( QueryContext
->OutputMdl
) {
1211 MmUnlockPages(QueryContext
->OutputMdl
);
1212 IoFreeMdl(QueryContext
->OutputMdl
);
1215 QueryContext
->Irp
->IoStatus
.Information
= ByteCount
;
1216 QueryContext
->Irp
->IoStatus
.Status
= Status
;
1218 ExFreePool(QueryContext
);
1222 NTSTATUS
DispTdiQueryInformationEx(
1224 PIO_STACK_LOCATION IrpSp
)
1226 * FUNCTION: TDI QueryInformationEx handler
1228 * Irp = Pointer to I/O request packet
1229 * IrpSp = Pointer to current stack location of Irp
1231 * Status of operation
1234 PTCP_REQUEST_QUERY_INFORMATION_EX InputBuffer
;
1235 PTRANSPORT_CONTEXT TranContext
;
1236 PTI_QUERY_CONTEXT QueryContext
;
1238 TDI_REQUEST Request
;
1240 UINT InputBufferLength
;
1241 UINT OutputBufferLength
;
1242 BOOLEAN InputMdlLocked
= FALSE
;
1243 BOOLEAN OutputMdlLocked
= FALSE
;
1244 PMDL InputMdl
= NULL
;
1245 PMDL OutputMdl
= NULL
;
1246 NTSTATUS Status
= STATUS_SUCCESS
;
1248 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
1250 TranContext
= (PTRANSPORT_CONTEXT
)IrpSp
->FileObject
->FsContext
;
1252 switch ((ULONG
)IrpSp
->FileObject
->FsContext2
) {
1253 case TDI_TRANSPORT_ADDRESS_FILE
:
1254 Request
.Handle
.AddressHandle
= TranContext
->Handle
.AddressHandle
;
1257 case TDI_CONNECTION_FILE
:
1258 Request
.Handle
.ConnectionContext
= TranContext
->Handle
.ConnectionContext
;
1261 case TDI_CONTROL_CHANNEL_FILE
:
1262 Request
.Handle
.ControlChannel
= TranContext
->Handle
.ControlChannel
;
1266 TI_DbgPrint(MIN_TRACE
, ("Invalid transport context\n"));
1267 return STATUS_INVALID_PARAMETER
;
1270 InputBufferLength
= IrpSp
->Parameters
.DeviceIoControl
.InputBufferLength
;
1271 OutputBufferLength
= IrpSp
->Parameters
.DeviceIoControl
.OutputBufferLength
;
1273 /* Validate parameters */
1274 if ((InputBufferLength
== sizeof(TCP_REQUEST_QUERY_INFORMATION_EX
)) &&
1275 (OutputBufferLength
!= 0)) {
1277 InputBuffer
= (PTCP_REQUEST_QUERY_INFORMATION_EX
)
1278 IrpSp
->Parameters
.DeviceIoControl
.Type3InputBuffer
;
1279 OutputBuffer
= Irp
->UserBuffer
;
1281 QueryContext
= ExAllocatePool(NonPagedPool
, sizeof(TI_QUERY_CONTEXT
));
1284 InputMdl
= IoAllocateMdl(InputBuffer
,
1285 sizeof(TCP_REQUEST_QUERY_INFORMATION_EX
),
1288 OutputMdl
= IoAllocateMdl(OutputBuffer
,
1289 OutputBufferLength
, FALSE
, TRUE
, NULL
);
1291 if (InputMdl
&& OutputMdl
) {
1293 MmProbeAndLockPages(InputMdl
, Irp
->RequestorMode
,
1296 InputMdlLocked
= TRUE
;
1298 MmProbeAndLockPages(OutputMdl
, Irp
->RequestorMode
,
1301 OutputMdlLocked
= TRUE
;
1303 RtlCopyMemory(&QueryContext
->QueryInfo
,
1304 InputBuffer
, sizeof(TCP_REQUEST_QUERY_INFORMATION_EX
));
1306 Status
= STATUS_INSUFFICIENT_RESOURCES
;
1308 Status
= _SEH_GetExceptionCode();
1311 if (NT_SUCCESS(Status
)) {
1312 Size
= MmGetMdlByteCount(OutputMdl
);
1314 QueryContext
->Irp
= Irp
;
1315 QueryContext
->InputMdl
= InputMdl
;
1316 QueryContext
->OutputMdl
= OutputMdl
;
1318 Request
.RequestNotifyObject
= DispTdiQueryInformationExComplete
;
1319 Request
.RequestContext
= QueryContext
;
1320 Status
= InfoTdiQueryInformationEx(&Request
,
1321 &QueryContext
->QueryInfo
.ID
, OutputMdl
,
1322 &Size
, &QueryContext
->QueryInfo
.Context
);
1323 DispTdiQueryInformationExComplete(QueryContext
, Status
, Size
);
1325 TI_DbgPrint(MAX_TRACE
, ("Leaving. Status = (0x%X)\n", Status
));
1330 /* An error occurred if we get here */
1334 MmUnlockPages(InputMdl
);
1335 IoFreeMdl(InputMdl
);
1339 if (OutputMdlLocked
)
1340 MmUnlockPages(OutputMdl
);
1341 IoFreeMdl(OutputMdl
);
1344 ExFreePool(QueryContext
);
1346 Status
= STATUS_INSUFFICIENT_RESOURCES
;
1347 } else if( InputBufferLength
==
1348 sizeof(TCP_REQUEST_QUERY_INFORMATION_EX
) ) {
1349 /* Handle the case where the user is probing the buffer for length */
1350 TI_DbgPrint(MAX_TRACE
, ("InputBufferLength %d OutputBufferLength %d\n",
1351 InputBufferLength
, OutputBufferLength
));
1352 InputBuffer
= (PTCP_REQUEST_QUERY_INFORMATION_EX
)
1353 IrpSp
->Parameters
.DeviceIoControl
.Type3InputBuffer
;
1357 QueryContext
= ExAllocatePool(NonPagedPool
, sizeof(TI_QUERY_CONTEXT
));
1358 if (!QueryContext
) return STATUS_INSUFFICIENT_RESOURCES
;
1361 InputMdl
= IoAllocateMdl(InputBuffer
,
1362 sizeof(TCP_REQUEST_QUERY_INFORMATION_EX
),
1365 MmProbeAndLockPages(InputMdl
, Irp
->RequestorMode
,
1368 InputMdlLocked
= TRUE
;
1369 Status
= STATUS_SUCCESS
;
1371 TI_DbgPrint(MAX_TRACE
, ("Failed to acquire client buffer\n"));
1372 Status
= _SEH_GetExceptionCode();
1375 if( !NT_SUCCESS(Status
) || !InputMdl
) {
1376 if( InputMdl
) IoFreeMdl( InputMdl
);
1377 ExFreePool(QueryContext
);
1381 RtlCopyMemory(&QueryContext
->QueryInfo
,
1382 InputBuffer
, sizeof(TCP_REQUEST_QUERY_INFORMATION_EX
));
1384 QueryContext
->Irp
= Irp
;
1385 QueryContext
->InputMdl
= InputMdl
;
1386 QueryContext
->OutputMdl
= NULL
;
1388 Request
.RequestNotifyObject
= DispTdiQueryInformationExComplete
;
1389 Request
.RequestContext
= QueryContext
;
1390 Status
= InfoTdiQueryInformationEx(&Request
,
1391 &QueryContext
->QueryInfo
.ID
,
1394 &QueryContext
->QueryInfo
.Context
);
1395 DispTdiQueryInformationExComplete(QueryContext
, Status
, Size
);
1396 TI_DbgPrint(MAX_TRACE
, ("Leaving. Status = (0x%X)\n", Status
));
1397 } else Status
= STATUS_INVALID_PARAMETER
;
1399 TI_DbgPrint(MIN_TRACE
, ("Leaving. Status = (0x%X)\n", Status
));
1405 NTSTATUS
DispTdiSetInformationEx(
1407 PIO_STACK_LOCATION IrpSp
)
1409 * FUNCTION: TDI SetInformationEx handler
1411 * Irp = Pointer to I/O request packet
1412 * IrpSp = Pointer to current stack location of Irp
1414 * Status of operation
1417 PTRANSPORT_CONTEXT TranContext
;
1418 PTCP_REQUEST_SET_INFORMATION_EX Info
;
1419 TDI_REQUEST Request
;
1423 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
1425 TranContext
= (PTRANSPORT_CONTEXT
)IrpSp
->FileObject
->FsContext
;
1426 Info
= (PTCP_REQUEST_SET_INFORMATION_EX
)Irp
->AssociatedIrp
.SystemBuffer
;
1428 switch ((ULONG
)IrpSp
->FileObject
->FsContext2
) {
1429 case TDI_TRANSPORT_ADDRESS_FILE
:
1430 Request
.Handle
.AddressHandle
= TranContext
->Handle
.AddressHandle
;
1433 case TDI_CONNECTION_FILE
:
1434 Request
.Handle
.ConnectionContext
= TranContext
->Handle
.ConnectionContext
;
1437 case TDI_CONTROL_CHANNEL_FILE
:
1438 Request
.Handle
.ControlChannel
= TranContext
->Handle
.ControlChannel
;
1442 Irp
->IoStatus
.Status
= STATUS_INVALID_PARAMETER
;
1443 Irp
->IoStatus
.Information
= 0;
1445 TI_DbgPrint(DEBUG_IRP
, ("Completing IRP at (0x%X).\n", Irp
));
1447 return IRPFinish(Irp
, STATUS_INVALID_PARAMETER
);
1450 Status
= DispPrepareIrpForCancel(TranContext
, Irp
, NULL
);
1451 if (NT_SUCCESS(Status
)) {
1452 Request
.RequestNotifyObject
= DispDataRequestComplete
;
1453 Request
.RequestContext
= Irp
;
1455 Status
= InfoTdiSetInformationEx(&Request
, &Info
->ID
,
1456 &Info
->Buffer
, Info
->BufferSize
);
1458 if (Status
!= STATUS_PENDING
) {
1459 IoAcquireCancelSpinLock(&OldIrql
);
1460 IoSetCancelRoutine(Irp
, NULL
);
1461 IoReleaseCancelSpinLock(OldIrql
);
1468 /* TODO: Support multiple addresses per interface.
1469 * For now just set the nte context to the interface index.
1471 * Later on, create an NTE context and NTE instance
1474 NTSTATUS
DispTdiSetIPAddress( PIRP Irp
, PIO_STACK_LOCATION IrpSp
) {
1475 NTSTATUS Status
= STATUS_DEVICE_DOES_NOT_EXIST
;
1476 PIP_SET_ADDRESS IpAddrChange
=
1477 (PIP_SET_ADDRESS
)Irp
->AssociatedIrp
.SystemBuffer
;
1480 ForEachInterface(IF
) {
1481 if( IF
->Unicast
.Address
.IPv4Address
== IpAddrChange
->Address
) {
1482 Status
= STATUS_DUPLICATE_OBJECTID
;
1485 if( IF
->Index
== IpAddrChange
->NteIndex
) {
1486 IPRemoveInterfaceRoute( IF
);
1488 IF
->Unicast
.Type
= IP_ADDRESS_V4
;
1489 IF
->Unicast
.Address
.IPv4Address
= IpAddrChange
->Address
;
1490 IF
->Netmask
.Type
= IP_ADDRESS_V4
;
1491 IF
->Netmask
.Address
.IPv4Address
= IpAddrChange
->Netmask
;
1493 TI_DbgPrint(MID_TRACE
,("New Unicast Address: %x\n",
1494 IF
->Unicast
.Address
.IPv4Address
));
1495 TI_DbgPrint(MID_TRACE
,("New Netmask : %x\n",
1496 IF
->Netmask
.Address
.IPv4Address
));
1498 IPAddInterfaceRoute( IF
);
1500 IpAddrChange
->Address
= IF
->Index
;
1501 Status
= STATUS_SUCCESS
;
1502 Irp
->IoStatus
.Information
= IF
->Index
;
1507 Irp
->IoStatus
.Status
= Status
;
1511 NTSTATUS
DispTdiDeleteIPAddress( PIRP Irp
, PIO_STACK_LOCATION IrpSp
) {
1512 NTSTATUS Status
= STATUS_UNSUCCESSFUL
;
1513 PUSHORT NteIndex
= Irp
->AssociatedIrp
.SystemBuffer
;
1516 ForEachInterface(IF
) {
1517 if( IF
->Index
== *NteIndex
) {
1518 IF
->Unicast
.Type
= IP_ADDRESS_V4
;
1519 IF
->Unicast
.Address
.IPv4Address
= 0;
1520 IF
->Netmask
.Type
= IP_ADDRESS_V4
;
1521 IF
->Netmask
.Address
.IPv4Address
= 0;
1522 Status
= STATUS_SUCCESS
;
1526 Irp
->IoStatus
.Status
= Status
;