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/pseh2.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
30 PIO_STACK_LOCATION IrpSp
;
31 PTRANSPORT_CONTEXT TransContext
;
33 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
35 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
36 TransContext
= (PTRANSPORT_CONTEXT
)IrpSp
->FileObject
->FsContext
;
38 IoAcquireCancelSpinLock(&OldIrql
);
40 if (!Irp
->Cancel
&& !TransContext
->CancelIrps
) {
41 (void)IoSetCancelRoutine(Irp
, CancelRoutine
);
42 IoReleaseCancelSpinLock(OldIrql
);
44 TI_DbgPrint(DEBUG_IRP
, ("Leaving (IRP at 0x%X can now be cancelled).\n", Irp
));
46 return STATUS_SUCCESS
;
49 /* IRP has already been cancelled */
51 IoReleaseCancelSpinLock(OldIrql
);
53 Irp
->IoStatus
.Status
= STATUS_CANCELLED
;
54 Irp
->IoStatus
.Information
= 0;
56 TI_DbgPrint(DEBUG_IRP
, ("Leaving (IRP was already cancelled).\n"));
58 return Irp
->IoStatus
.Status
;
61 VOID
DispDataRequestComplete(
66 * FUNCTION: Completes a send/receive IRP
68 * Context = Pointer to context information (IRP)
69 * Status = Status of the request
70 * Count = Number of bytes sent or received
74 PIO_STACK_LOCATION IrpSp
;
75 PTRANSPORT_CONTEXT TranContext
;
78 TI_DbgPrint(DEBUG_IRP
, ("Called for irp %x (%x, %d).\n",
79 Context
, Status
, Count
));
82 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
83 TranContext
= (PTRANSPORT_CONTEXT
)IrpSp
->FileObject
->FsContext
;
85 IoAcquireCancelSpinLock(&OldIrql
);
87 (void)IoSetCancelRoutine(Irp
, NULL
);
89 IoReleaseCancelSpinLock(OldIrql
);
91 Irp
->IoStatus
.Status
= Status
;
92 Irp
->IoStatus
.Information
= Count
;
94 TI_DbgPrint(MID_TRACE
, ("Irp->IoStatus.Status = %x\n",
95 Irp
->IoStatus
.Status
));
96 TI_DbgPrint(MID_TRACE
, ("Irp->IoStatus.Information = %d\n",
97 Irp
->IoStatus
.Information
));
98 TI_DbgPrint(DEBUG_IRP
, ("Completing IRP at (0x%X).\n", Irp
));
100 IRPFinish(Irp
, Status
);
102 TI_DbgPrint(DEBUG_IRP
, ("Done Completing IRP\n"));
105 VOID
DispDoDisconnect( PVOID Data
) {
106 PDISCONNECT_TYPE DisType
= (PDISCONNECT_TYPE
)Data
;
108 TI_DbgPrint(DEBUG_IRP
, ("PostCancel: DoDisconnect\n"));
109 TcpipRecursiveMutexEnter(&TCPLock
, TRUE
);
115 DispDataRequestComplete
,
117 TcpipRecursiveMutexLeave(&TCPLock
);
118 TI_DbgPrint(DEBUG_IRP
, ("PostCancel: DoDisconnect done\n"));
120 DispDataRequestComplete(DisType
->Irp
, STATUS_CANCELLED
, 0);
125 VOID NTAPI
DispCancelRequest(
126 PDEVICE_OBJECT Device
,
129 * FUNCTION: Cancels an IRP
131 * Device = Pointer to device object
132 * Irp = Pointer to an I/O request packet
135 PIO_STACK_LOCATION IrpSp
;
136 PTRANSPORT_CONTEXT TranContext
;
137 PFILE_OBJECT FileObject
;
139 PDISCONNECT_TYPE DisType
;
141 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
143 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
144 FileObject
= IrpSp
->FileObject
;
145 TranContext
= (PTRANSPORT_CONTEXT
)FileObject
->FsContext
;
146 MinorFunction
= IrpSp
->MinorFunction
;
148 TI_DbgPrint(DEBUG_IRP
, ("IRP at (0x%X) MinorFunction (0x%X) IrpSp (0x%X).\n", Irp
, MinorFunction
, IrpSp
));
150 Irp
->IoStatus
.Status
= STATUS_CANCELLED
;
151 Irp
->IoStatus
.Information
= 0;
155 TI_DbgPrint(MIN_TRACE
, ("Irp->Cancel is FALSE, should be TRUE.\n"));
158 /* Try canceling the request */
159 switch(MinorFunction
) {
162 DisType
= exAllocatePool(NonPagedPool
, sizeof(DISCONNECT_TYPE
));
165 DisType
->Type
= TDI_DISCONNECT_RELEASE
|
166 ((MinorFunction
== TDI_RECEIVE
) ? TDI_DISCONNECT_ABORT
: 0);
167 DisType
->Context
= TranContext
->Handle
.ConnectionContext
;
170 TCPRemoveIRP( TranContext
->Handle
.ConnectionContext
, Irp
);
172 if (!ChewCreate(DispDoDisconnect
, DisType
))
176 IoReleaseCancelSpinLock(Irp
->CancelIrql
);
179 case TDI_SEND_DATAGRAM
:
180 if (FileObject
->FsContext2
!= (PVOID
)TDI_TRANSPORT_ADDRESS_FILE
) {
181 TI_DbgPrint(MIN_TRACE
, ("TDI_SEND_DATAGRAM, but no address file.\n"));
185 DGRemoveIRP(TranContext
->Handle
.AddressHandle
, Irp
);
188 case TDI_RECEIVE_DATAGRAM
:
189 if (FileObject
->FsContext2
!= (PVOID
)TDI_TRANSPORT_ADDRESS_FILE
) {
190 TI_DbgPrint(MIN_TRACE
, ("TDI_RECEIVE_DATAGRAM, but no address file.\n"));
194 DGRemoveIRP(TranContext
->Handle
.AddressHandle
, Irp
);
198 TCPRemoveIRP(TranContext
->Handle
.ConnectionContext
, Irp
);
202 TI_DbgPrint(MIN_TRACE
, ("Unknown IRP. MinorFunction (0x%X).\n", MinorFunction
));
206 IoReleaseCancelSpinLock(Irp
->CancelIrql
);
207 IRPFinish(Irp
, STATUS_CANCELLED
);
209 TI_DbgPrint(MAX_TRACE
, ("Leaving.\n"));
213 VOID NTAPI
DispCancelListenRequest(
214 PDEVICE_OBJECT Device
,
217 * FUNCTION: Cancels a listen IRP
219 * Device = Pointer to device object
220 * Irp = Pointer to an I/O request packet
223 PIO_STACK_LOCATION IrpSp
;
224 PTRANSPORT_CONTEXT TranContext
;
225 PFILE_OBJECT FileObject
;
226 PCONNECTION_ENDPOINT Connection
;
227 /*NTSTATUS Status = STATUS_SUCCESS;*/
229 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
231 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
232 FileObject
= IrpSp
->FileObject
;
233 TranContext
= (PTRANSPORT_CONTEXT
)FileObject
->FsContext
;
234 ASSERT( TDI_LISTEN
== IrpSp
->MinorFunction
);
236 TI_DbgPrint(DEBUG_IRP
, ("IRP at (0x%X).\n", Irp
));
240 TI_DbgPrint(MIN_TRACE
, ("Irp->Cancel is FALSE, should be TRUE.\n"));
243 /* Try canceling the request */
244 Connection
= (PCONNECTION_ENDPOINT
)TranContext
->Handle
.ConnectionContext
;
246 TCPRemoveIRP(Connection
, Irp
);
248 TCPAbortListenForSocket(
249 Connection
->AddressFile
->Listener
,
252 IoReleaseCancelSpinLock(Irp
->CancelIrql
);
254 Irp
->IoStatus
.Information
= 0;
255 IRPFinish(Irp
, STATUS_CANCELLED
);
257 TI_DbgPrint(MAX_TRACE
, ("Leaving.\n"));
261 NTSTATUS
DispTdiAccept(
264 * FUNCTION: TDI_ACCEPT handler
266 * Irp = Pointer to an I/O request packet
268 * Status of operation
271 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
273 return STATUS_NOT_IMPLEMENTED
;
277 NTSTATUS
DispTdiAssociateAddress(
280 * FUNCTION: TDI_ASSOCIATE_ADDRESS handler
282 * Irp = Pointer to an I/O request packet
284 * Status of operation
287 PTDI_REQUEST_KERNEL_ASSOCIATE Parameters
;
288 PTRANSPORT_CONTEXT TranContext
;
289 PIO_STACK_LOCATION IrpSp
;
290 PCONNECTION_ENDPOINT Connection
;
291 PFILE_OBJECT FileObject
;
292 PADDRESS_FILE AddrFile
= NULL
;
295 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
297 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
299 /* Get associated connection endpoint file object. Quit if none exists */
301 TranContext
= IrpSp
->FileObject
->FsContext
;
303 TI_DbgPrint(MID_TRACE
, ("Bad transport context.\n"));
304 return STATUS_INVALID_PARAMETER
;
307 Connection
= (PCONNECTION_ENDPOINT
)TranContext
->Handle
.ConnectionContext
;
309 TI_DbgPrint(MID_TRACE
, ("No connection endpoint file object.\n"));
310 return STATUS_INVALID_PARAMETER
;
313 if (Connection
->AddressFile
) {
314 TI_DbgPrint(MID_TRACE
, ("An address file is already asscociated.\n"));
315 return STATUS_INVALID_PARAMETER
;
318 Parameters
= (PTDI_REQUEST_KERNEL_ASSOCIATE
)&IrpSp
->Parameters
;
320 Status
= ObReferenceObjectByHandle(
321 Parameters
->AddressHandle
,
327 if (!NT_SUCCESS(Status
)) {
328 TI_DbgPrint(MID_TRACE
, ("Bad address file object handle (0x%X): %x.\n",
329 Parameters
->AddressHandle
, Status
));
330 return STATUS_INVALID_PARAMETER
;
333 if (FileObject
->FsContext2
!= (PVOID
)TDI_TRANSPORT_ADDRESS_FILE
) {
334 ObDereferenceObject(FileObject
);
335 TI_DbgPrint(MID_TRACE
, ("Bad address file object. Magic (0x%X).\n",
336 FileObject
->FsContext2
));
337 return STATUS_INVALID_PARAMETER
;
340 /* Get associated address file object. Quit if none exists */
342 TranContext
= FileObject
->FsContext
;
344 ObDereferenceObject(FileObject
);
345 TI_DbgPrint(MID_TRACE
, ("Bad transport context.\n"));
346 return STATUS_INVALID_PARAMETER
;
349 AddrFile
= (PADDRESS_FILE
)TranContext
->Handle
.AddressHandle
;
351 ObDereferenceObject(FileObject
);
352 TI_DbgPrint(MID_TRACE
, ("No address file object.\n"));
353 return STATUS_INVALID_PARAMETER
;
356 Connection
->AddressFile
= AddrFile
;
358 /* Add connection endpoint to the address file */
359 AddrFile
->Connection
= Connection
;
361 /* FIXME: Maybe do this in DispTdiDisassociateAddress() instead? */
362 ObDereferenceObject(FileObject
);
368 NTSTATUS
DispTdiConnect(
371 * FUNCTION: TDI_CONNECT handler
373 * Irp = Pointer to an I/O request packet
375 * Status of operation
378 PCONNECTION_ENDPOINT Connection
;
379 PTDI_REQUEST_KERNEL Parameters
;
380 PTRANSPORT_CONTEXT TranContext
;
381 PIO_STACK_LOCATION IrpSp
;
384 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
386 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
388 /* Get associated connection endpoint file object. Quit if none exists */
390 TcpipRecursiveMutexEnter( &TCPLock
, TRUE
);
392 TranContext
= IrpSp
->FileObject
->FsContext
;
394 TI_DbgPrint(MID_TRACE
, ("Bad transport context.\n"));
395 Status
= STATUS_INVALID_PARAMETER
;
399 Connection
= (PCONNECTION_ENDPOINT
)TranContext
->Handle
.ConnectionContext
;
401 TI_DbgPrint(MID_TRACE
, ("No connection endpoint file object.\n"));
402 Status
= STATUS_INVALID_PARAMETER
;
406 Parameters
= (PTDI_REQUEST_KERNEL
)&IrpSp
->Parameters
;
408 Status
= DispPrepareIrpForCancel(TranContext
->Handle
.ConnectionContext
,
412 if (NT_SUCCESS(Status
)) {
414 TranContext
->Handle
.ConnectionContext
,
415 Parameters
->RequestConnectionInformation
,
416 Parameters
->ReturnConnectionInformation
,
417 DispDataRequestComplete
,
422 TcpipRecursiveMutexLeave( &TCPLock
);
424 if (Status
!= STATUS_PENDING
) {
425 DispDataRequestComplete(Irp
, Status
, 0);
427 IoMarkIrpPending(Irp
);
429 TI_DbgPrint(MAX_TRACE
, ("TCP Connect returned %08x\n", Status
));
435 NTSTATUS
DispTdiDisassociateAddress(
438 * FUNCTION: TDI_DISASSOCIATE_ADDRESS handler
440 * Irp = Pointer to an I/O request packet
442 * Status of operation
445 PCONNECTION_ENDPOINT Connection
;
446 PTRANSPORT_CONTEXT TranContext
;
447 PIO_STACK_LOCATION IrpSp
;
449 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
451 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
453 /* Get associated connection endpoint file object. Quit if none exists */
455 TranContext
= IrpSp
->FileObject
->FsContext
;
457 TI_DbgPrint(MID_TRACE
, ("Bad transport context.\n"));
458 return STATUS_INVALID_PARAMETER
;
461 Connection
= (PCONNECTION_ENDPOINT
)TranContext
->Handle
.ConnectionContext
;
463 TI_DbgPrint(MID_TRACE
, ("No connection endpoint file object.\n"));
464 return STATUS_INVALID_PARAMETER
;
467 if (!Connection
->AddressFile
) {
468 TI_DbgPrint(MID_TRACE
, ("No address file is asscociated.\n"));
469 return STATUS_INVALID_PARAMETER
;
472 /* Remove this connection from the address file */
473 Connection
->AddressFile
->Connection
= NULL
;
475 /* Remove the address file from this connection */
476 Connection
->AddressFile
= NULL
;
478 return STATUS_SUCCESS
;
482 NTSTATUS
DispTdiDisconnect(
485 * FUNCTION: TDI_DISCONNECT handler
487 * Irp = Pointer to an I/O request packet
489 * Status of operation
493 PTDI_REQUEST_KERNEL_DISCONNECT DisReq
;
494 PCONNECTION_ENDPOINT Connection
;
495 PTRANSPORT_CONTEXT TranContext
;
496 PIO_STACK_LOCATION IrpSp
;
498 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
500 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
501 DisReq
= (PTDI_REQUEST_KERNEL_DISCONNECT
)&IrpSp
->Parameters
;
503 TcpipRecursiveMutexEnter( &TCPLock
, TRUE
);
505 /* Get associated connection endpoint file object. Quit if none exists */
507 TranContext
= IrpSp
->FileObject
->FsContext
;
509 TI_DbgPrint(MID_TRACE
, ("Bad transport context.\n"));
510 Status
= STATUS_INVALID_PARAMETER
;
514 Connection
= (PCONNECTION_ENDPOINT
)TranContext
->Handle
.ConnectionContext
;
516 TI_DbgPrint(MID_TRACE
, ("No connection endpoint file object.\n"));
517 Status
= STATUS_INVALID_PARAMETER
;
521 Status
= TCPDisconnect(
522 TranContext
->Handle
.ConnectionContext
,
523 DisReq
->RequestFlags
,
524 DisReq
->RequestConnectionInformation
,
525 DisReq
->ReturnConnectionInformation
,
526 DispDataRequestComplete
,
530 TcpipRecursiveMutexLeave( &TCPLock
);
532 if (Status
!= STATUS_PENDING
) {
533 DispDataRequestComplete(Irp
, Status
, 0);
535 IoMarkIrpPending(Irp
);
537 TI_DbgPrint(MAX_TRACE
, ("TCP Disconnect returned %08x\n", Status
));
543 NTSTATUS
DispTdiListen(
546 * FUNCTION: TDI_LISTEN handler
548 * Irp = Pointer to an I/O request packet
550 * Status of operation
553 PCONNECTION_ENDPOINT Connection
;
554 PTDI_REQUEST_KERNEL Parameters
;
555 PTRANSPORT_CONTEXT TranContext
;
556 PIO_STACK_LOCATION IrpSp
;
557 NTSTATUS Status
= STATUS_SUCCESS
;
559 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
561 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
563 /* Get associated connection endpoint file object. Quit if none exists */
565 TcpipRecursiveMutexEnter( &TCPLock
, TRUE
);
567 TranContext
= IrpSp
->FileObject
->FsContext
;
568 if (TranContext
== NULL
)
570 TI_DbgPrint(MID_TRACE
, ("Bad transport context.\n"));
571 Status
= STATUS_INVALID_PARAMETER
;
575 Connection
= (PCONNECTION_ENDPOINT
)TranContext
->Handle
.ConnectionContext
;
576 if (Connection
== NULL
)
578 TI_DbgPrint(MID_TRACE
, ("No connection endpoint file object.\n"));
579 Status
= STATUS_INVALID_PARAMETER
;
583 Parameters
= (PTDI_REQUEST_KERNEL
)&IrpSp
->Parameters
;
585 TI_DbgPrint(MIN_TRACE
, ("Connection->AddressFile: %x\n",
586 Connection
->AddressFile
));
587 ASSERT(Connection
->AddressFile
);
589 Status
= DispPrepareIrpForCancel
590 (TranContext
->Handle
.ConnectionContext
,
592 (PDRIVER_CANCEL
)DispCancelListenRequest
);
594 /* Listening will require us to create a listening socket and store it in
595 * the address file. It will be signalled, and attempt to complete an irp
596 * when a new connection arrives. */
597 /* The important thing to note here is that the irp we'll complete belongs
598 * to the socket to be accepted onto, not the listener */
599 if( NT_SUCCESS(Status
) && !Connection
->AddressFile
->Listener
) {
600 Connection
->AddressFile
->Listener
=
601 TCPAllocateConnectionEndpoint( NULL
);
603 if( !Connection
->AddressFile
->Listener
)
604 Status
= STATUS_NO_MEMORY
;
606 if( NT_SUCCESS(Status
) ) {
607 Connection
->AddressFile
->Listener
->AddressFile
=
608 Connection
->AddressFile
;
610 Status
= TCPSocket( Connection
->AddressFile
->Listener
,
611 Connection
->AddressFile
->Family
,
613 Connection
->AddressFile
->Protocol
);
616 if( NT_SUCCESS(Status
) )
617 Status
= TCPListen( Connection
->AddressFile
->Listener
, 1024 );
621 if( NT_SUCCESS(Status
) ) {
623 ( (PTDI_REQUEST
)Parameters
,
624 Connection
->AddressFile
->Listener
,
626 DispDataRequestComplete
,
631 TcpipRecursiveMutexLeave( &TCPLock
);
633 if (Status
!= STATUS_PENDING
) {
634 DispDataRequestComplete(Irp
, Status
, 0);
636 IoMarkIrpPending(Irp
);
638 TI_DbgPrint(MID_TRACE
,("Leaving %x\n", Status
));
644 NTSTATUS
DispTdiQueryInformation(
645 PDEVICE_OBJECT DeviceObject
,
648 * FUNCTION: TDI_QUERY_INFORMATION handler
650 * DeviceObject = Pointer to device object structure
651 * Irp = Pointer to an I/O request packet
653 * Status of operation
656 PTDI_REQUEST_KERNEL_QUERY_INFORMATION Parameters
;
657 PTRANSPORT_CONTEXT TranContext
;
658 PIO_STACK_LOCATION IrpSp
;
661 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
663 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
664 Parameters
= (PTDI_REQUEST_KERNEL_QUERY_INFORMATION
)&IrpSp
->Parameters
;
666 TcpipRecursiveMutexEnter( &TCPLock
, TRUE
);
668 TranContext
= IrpSp
->FileObject
->FsContext
;
670 TI_DbgPrint(MID_TRACE
, ("Bad transport context.\n"));
671 TcpipRecursiveMutexLeave(&TCPLock
);
672 return STATUS_INVALID_PARAMETER
;
675 switch (Parameters
->QueryType
)
677 case TDI_QUERY_ADDRESS_INFO
:
679 PTDI_ADDRESS_INFO AddressInfo
;
680 PADDRESS_FILE AddrFile
;
681 PTA_IP_ADDRESS Address
;
682 PCONNECTION_ENDPOINT Endpoint
= NULL
;
685 if (MmGetMdlByteCount(Irp
->MdlAddress
) <
686 (FIELD_OFFSET(TDI_ADDRESS_INFO
, Address
.Address
[0].Address
) +
687 sizeof(TDI_ADDRESS_IP
))) {
688 TI_DbgPrint(MID_TRACE
, ("MDL buffer too small.\n"));
689 TcpipRecursiveMutexLeave(&TCPLock
);
690 return STATUS_BUFFER_TOO_SMALL
;
693 AddressInfo
= (PTDI_ADDRESS_INFO
)MmGetSystemAddressForMdl(Irp
->MdlAddress
);
694 Address
= (PTA_IP_ADDRESS
)&AddressInfo
->Address
;
696 switch ((ULONG
)IrpSp
->FileObject
->FsContext2
) {
697 case TDI_TRANSPORT_ADDRESS_FILE
:
698 AddrFile
= (PADDRESS_FILE
)TranContext
->Handle
.AddressHandle
;
700 Address
->TAAddressCount
= 1;
701 Address
->Address
[0].AddressLength
= TDI_ADDRESS_LENGTH_IP
;
702 Address
->Address
[0].AddressType
= TDI_ADDRESS_TYPE_IP
;
703 Address
->Address
[0].Address
[0].sin_port
= AddrFile
->Port
;
704 Address
->Address
[0].Address
[0].in_addr
= AddrFile
->Address
.Address
.IPv4Address
;
706 &Address
->Address
[0].Address
[0].sin_zero
,
707 sizeof(Address
->Address
[0].Address
[0].sin_zero
));
708 TcpipRecursiveMutexLeave(&TCPLock
);
709 return STATUS_SUCCESS
;
711 case TDI_CONNECTION_FILE
:
713 (PCONNECTION_ENDPOINT
)TranContext
->Handle
.ConnectionContext
;
714 TCPGetSockAddress( Endpoint
, (PTRANSPORT_ADDRESS
)Address
, FALSE
);
715 DbgPrint("Returning socket address %x\n", Address
->Address
[0].Address
[0].in_addr
);
717 &Address
->Address
[0].Address
[0].sin_zero
,
718 sizeof(Address
->Address
[0].Address
[0].sin_zero
));
719 TcpipRecursiveMutexLeave(&TCPLock
);
720 return STATUS_SUCCESS
;
723 TI_DbgPrint(MIN_TRACE
, ("Invalid transport context\n"));
724 TcpipRecursiveMutexLeave(&TCPLock
);
725 return STATUS_INVALID_PARAMETER
;
729 case TDI_QUERY_CONNECTION_INFO
:
731 PTDI_CONNECTION_INFORMATION AddressInfo
;
732 PADDRESS_FILE AddrFile
;
733 PCONNECTION_ENDPOINT Endpoint
= NULL
;
735 if (MmGetMdlByteCount(Irp
->MdlAddress
) <
736 (FIELD_OFFSET(TDI_CONNECTION_INFORMATION
, RemoteAddress
) +
738 TI_DbgPrint(MID_TRACE
, ("MDL buffer too small (ptr).\n"));
739 TcpipRecursiveMutexLeave(&TCPLock
);
740 return STATUS_BUFFER_TOO_SMALL
;
743 AddressInfo
= (PTDI_CONNECTION_INFORMATION
)
744 MmGetSystemAddressForMdl(Irp
->MdlAddress
);
746 switch ((ULONG
)IrpSp
->FileObject
->FsContext2
) {
747 case TDI_TRANSPORT_ADDRESS_FILE
:
748 AddrFile
= (PADDRESS_FILE
)TranContext
->Handle
.AddressHandle
;
749 Endpoint
= AddrFile
? AddrFile
->Connection
: NULL
;
752 case TDI_CONNECTION_FILE
:
754 (PCONNECTION_ENDPOINT
)TranContext
->Handle
.ConnectionContext
;
758 TI_DbgPrint(MIN_TRACE
, ("Invalid transport context\n"));
759 TcpipRecursiveMutexLeave(&TCPLock
);
760 return STATUS_INVALID_PARAMETER
;
764 TI_DbgPrint(MID_TRACE
, ("No connection object.\n"));
765 TcpipRecursiveMutexLeave(&TCPLock
);
766 return STATUS_INVALID_PARAMETER
;
769 Status
= TCPGetSockAddress( Endpoint
, AddressInfo
->RemoteAddress
, TRUE
);
771 TcpipRecursiveMutexLeave(&TCPLock
);
776 TcpipRecursiveMutexLeave(&TCPLock
);
777 return STATUS_NOT_IMPLEMENTED
;
781 NTSTATUS
DispTdiReceive(
784 * FUNCTION: TDI_RECEIVE handler
786 * Irp = Pointer to an I/O request packet
788 * Status of operation
791 PIO_STACK_LOCATION IrpSp
;
792 PTDI_REQUEST_KERNEL_RECEIVE ReceiveInfo
;
793 PTRANSPORT_CONTEXT TranContext
;
795 ULONG BytesReceived
= 0;
797 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
799 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
800 ReceiveInfo
= (PTDI_REQUEST_KERNEL_RECEIVE
)&(IrpSp
->Parameters
);
802 TcpipRecursiveMutexEnter( &TCPLock
, TRUE
);
804 TranContext
= IrpSp
->FileObject
->FsContext
;
805 if (TranContext
== NULL
)
807 TI_DbgPrint(MID_TRACE
, ("Bad transport context.\n"));
808 Status
= STATUS_INVALID_PARAMETER
;
812 if (TranContext
->Handle
.ConnectionContext
== NULL
)
814 TI_DbgPrint(MID_TRACE
, ("No connection endpoint file object.\n"));
815 Status
= STATUS_INVALID_PARAMETER
;
819 /* Initialize a receive request */
820 Status
= DispPrepareIrpForCancel
821 (TranContext
->Handle
.ConnectionContext
,
823 (PDRIVER_CANCEL
)DispCancelRequest
);
825 TI_DbgPrint(MID_TRACE
,("TCPIP<<< Got an MDL: %x\n", Irp
->MdlAddress
));
826 if (NT_SUCCESS(Status
))
828 Status
= TCPReceiveData(
829 TranContext
->Handle
.ConnectionContext
,
830 (PNDIS_BUFFER
)Irp
->MdlAddress
,
831 ReceiveInfo
->ReceiveLength
,
833 ReceiveInfo
->ReceiveFlags
,
834 DispDataRequestComplete
,
839 TcpipRecursiveMutexLeave( &TCPLock
);
841 if (Status
!= STATUS_PENDING
) {
842 DispDataRequestComplete(Irp
, Status
, BytesReceived
);
844 IoMarkIrpPending(Irp
);
846 TI_DbgPrint(DEBUG_IRP
, ("Leaving. Status is (0x%X)\n", Status
));
852 NTSTATUS
DispTdiReceiveDatagram(
855 * FUNCTION: TDI_RECEIVE_DATAGRAM handler
857 * Irp = Pointer to an I/O request packet
859 * Status of operation
862 PIO_STACK_LOCATION IrpSp
;
863 PTDI_REQUEST_KERNEL_RECEIVEDG DgramInfo
;
864 PTRANSPORT_CONTEXT TranContext
;
867 ULONG BytesReceived
= 0;
869 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
871 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
872 DgramInfo
= (PTDI_REQUEST_KERNEL_RECEIVEDG
)&(IrpSp
->Parameters
);
874 TcpipRecursiveMutexEnter( &TCPLock
, TRUE
);
876 TranContext
= IrpSp
->FileObject
->FsContext
;
877 if (TranContext
== NULL
)
879 TI_DbgPrint(MID_TRACE
, ("Bad transport context.\n"));
880 Status
= STATUS_INVALID_PARAMETER
;
884 /* Initialize a receive request */
885 Request
.Handle
.AddressHandle
= TranContext
->Handle
.AddressHandle
;
886 Request
.RequestNotifyObject
= DispDataRequestComplete
;
887 Request
.RequestContext
= Irp
;
889 Status
= DispPrepareIrpForCancel(
890 IrpSp
->FileObject
->FsContext
,
892 (PDRIVER_CANCEL
)DispCancelRequest
);
894 if (NT_SUCCESS(Status
))
899 NdisQueryBuffer( (PNDIS_BUFFER
)Irp
->MdlAddress
,
903 Status
= DGReceiveDatagram(
904 Request
.Handle
.AddressHandle
,
905 DgramInfo
->ReceiveDatagramInformation
,
907 DgramInfo
->ReceiveLength
,
908 DgramInfo
->ReceiveFlags
,
909 DgramInfo
->ReturnDatagramInformation
,
911 (PDATAGRAM_COMPLETION_ROUTINE
)DispDataRequestComplete
,
917 TcpipRecursiveMutexLeave( &TCPLock
);
919 if (Status
!= STATUS_PENDING
) {
920 DispDataRequestComplete(Irp
, Status
, BytesReceived
);
922 IoMarkIrpPending(Irp
);
924 TI_DbgPrint(DEBUG_IRP
, ("Leaving. Status is (0x%X)\n", Status
));
930 NTSTATUS
DispTdiSend(
933 * FUNCTION: TDI_SEND handler
935 * Irp = Pointer to an I/O request packet
937 * Status of operation
940 PIO_STACK_LOCATION IrpSp
;
941 PTDI_REQUEST_KERNEL_SEND SendInfo
;
942 PTRANSPORT_CONTEXT TranContext
;
946 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
948 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
949 SendInfo
= (PTDI_REQUEST_KERNEL_SEND
)&(IrpSp
->Parameters
);
951 TcpipRecursiveMutexEnter( &TCPLock
, TRUE
);
953 TranContext
= IrpSp
->FileObject
->FsContext
;
954 if (TranContext
== NULL
)
956 TI_DbgPrint(MID_TRACE
, ("Bad transport context.\n"));
957 Status
= STATUS_INVALID_PARAMETER
;
961 if (TranContext
->Handle
.ConnectionContext
== NULL
)
963 TI_DbgPrint(MID_TRACE
, ("No connection endpoint file object.\n"));
964 Status
= STATUS_INVALID_PARAMETER
;
968 Status
= DispPrepareIrpForCancel(
969 IrpSp
->FileObject
->FsContext
,
971 (PDRIVER_CANCEL
)DispCancelRequest
);
973 TI_DbgPrint(MID_TRACE
,("TCPIP<<< Got an MDL: %x\n", Irp
->MdlAddress
));
974 if (NT_SUCCESS(Status
))
979 NdisQueryBuffer( Irp
->MdlAddress
, &Data
, &Len
);
981 TI_DbgPrint(MID_TRACE
,("About to TCPSendData\n"));
982 Status
= TCPSendData(
983 TranContext
->Handle
.ConnectionContext
,
985 SendInfo
->SendLength
,
988 DispDataRequestComplete
,
993 TcpipRecursiveMutexLeave( &TCPLock
);
995 if (Status
!= STATUS_PENDING
) {
996 DispDataRequestComplete(Irp
, Status
, BytesSent
);
998 IoMarkIrpPending(Irp
);
1000 TI_DbgPrint(DEBUG_IRP
, ("Leaving. Status is (0x%X)\n", Status
));
1006 NTSTATUS
DispTdiSendDatagram(
1009 * FUNCTION: TDI_SEND_DATAGRAM handler
1011 * Irp = Pointer to an I/O request packet
1013 * Status of operation
1016 PIO_STACK_LOCATION IrpSp
;
1017 TDI_REQUEST Request
;
1018 PTDI_REQUEST_KERNEL_SENDDG DgramInfo
;
1019 PTRANSPORT_CONTEXT TranContext
;
1022 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
1024 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
1025 DgramInfo
= (PTDI_REQUEST_KERNEL_SENDDG
)&(IrpSp
->Parameters
);
1027 TcpipRecursiveMutexEnter( &TCPLock
, TRUE
);
1029 TranContext
= IrpSp
->FileObject
->FsContext
;
1030 if (TranContext
== NULL
)
1032 TI_DbgPrint(MID_TRACE
, ("Bad transport context.\n"));
1033 Status
= STATUS_INVALID_PARAMETER
;
1037 /* Initialize a send request */
1038 Request
.Handle
.AddressHandle
= TranContext
->Handle
.AddressHandle
;
1039 Request
.RequestNotifyObject
= DispDataRequestComplete
;
1040 Request
.RequestContext
= Irp
;
1042 Status
= DispPrepareIrpForCancel(
1043 IrpSp
->FileObject
->FsContext
,
1045 (PDRIVER_CANCEL
)DispCancelRequest
);
1047 if (NT_SUCCESS(Status
)) {
1051 TI_DbgPrint(MID_TRACE
,("About to query buffer %x\n", Irp
->MdlAddress
));
1053 NdisQueryBuffer( (PNDIS_BUFFER
)Irp
->MdlAddress
,
1057 /* FIXME: DgramInfo->SendDatagramInformation->RemoteAddress
1058 must be of type PTDI_ADDRESS_IP */
1059 TI_DbgPrint(MID_TRACE
,
1060 ("About to call send routine %x\n",
1061 (*((PADDRESS_FILE
)Request
.Handle
.AddressHandle
)->Send
)));
1063 if( (*((PADDRESS_FILE
)Request
.Handle
.AddressHandle
)->Send
!= NULL
) )
1064 Status
= (*((PADDRESS_FILE
)Request
.Handle
.AddressHandle
)->Send
)(
1065 Request
.Handle
.AddressHandle
,
1066 DgramInfo
->SendDatagramInformation
,
1069 &Irp
->IoStatus
.Information
);
1071 Status
= STATUS_UNSUCCESSFUL
;
1075 TcpipRecursiveMutexLeave( &TCPLock
);
1077 if (Status
!= STATUS_PENDING
) {
1078 DispDataRequestComplete(Irp
, Status
, Irp
->IoStatus
.Information
);
1080 IoMarkIrpPending(Irp
);
1082 TI_DbgPrint(DEBUG_IRP
, ("Leaving.\n"));
1088 NTSTATUS
DispTdiSetEventHandler(PIRP Irp
)
1090 * FUNCTION: TDI_SET_EVENT_HANDER handler
1092 * Irp = Pointer to a I/O request packet
1094 * Status of operation
1097 PTDI_REQUEST_KERNEL_SET_EVENT Parameters
;
1098 PTRANSPORT_CONTEXT TranContext
;
1099 PIO_STACK_LOCATION IrpSp
;
1100 PADDRESS_FILE AddrFile
;
1104 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
1106 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
1108 /* Get associated address file object. Quit if none exists */
1110 TranContext
= IrpSp
->FileObject
->FsContext
;
1112 TI_DbgPrint(MIN_TRACE
, ("Bad transport context.\n"));
1113 return STATUS_INVALID_PARAMETER
;
1116 AddrFile
= (PADDRESS_FILE
)TranContext
->Handle
.AddressHandle
;
1118 TI_DbgPrint(MIN_TRACE
, ("No address file object.\n"));
1119 return STATUS_INVALID_PARAMETER
;
1122 Parameters
= (PTDI_REQUEST_KERNEL_SET_EVENT
)&IrpSp
->Parameters
;
1123 Status
= STATUS_SUCCESS
;
1125 TcpipAcquireSpinLock(&AddrFile
->Lock
, &OldIrql
);
1127 /* Set the event handler. if an event handler is associated with
1128 a specific event, it's flag (RegisteredXxxHandler) is TRUE.
1129 If an event handler is not used it's flag is FALSE */
1130 switch (Parameters
->EventType
) {
1131 case TDI_EVENT_CONNECT
:
1132 if (!Parameters
->EventHandler
) {
1133 AddrFile
->ConnectHandlerContext
= NULL
;
1134 AddrFile
->RegisteredConnectHandler
= FALSE
;
1136 AddrFile
->ConnectHandler
=
1137 (PTDI_IND_CONNECT
)Parameters
->EventHandler
;
1138 AddrFile
->ConnectHandlerContext
= Parameters
->EventContext
;
1139 AddrFile
->RegisteredConnectHandler
= TRUE
;
1143 case TDI_EVENT_DISCONNECT
:
1144 if (!Parameters
->EventHandler
) {
1145 AddrFile
->DisconnectHandlerContext
= NULL
;
1146 AddrFile
->RegisteredDisconnectHandler
= FALSE
;
1148 AddrFile
->DisconnectHandler
=
1149 (PTDI_IND_DISCONNECT
)Parameters
->EventHandler
;
1150 AddrFile
->DisconnectHandlerContext
= Parameters
->EventContext
;
1151 AddrFile
->RegisteredDisconnectHandler
= TRUE
;
1155 case TDI_EVENT_ERROR
:
1156 if (Parameters
->EventHandler
== NULL
) {
1157 AddrFile
->ErrorHandlerContext
= NULL
;
1158 AddrFile
->RegisteredErrorHandler
= FALSE
;
1160 AddrFile
->ErrorHandler
=
1161 (PTDI_IND_ERROR
)Parameters
->EventHandler
;
1162 AddrFile
->ErrorHandlerContext
= Parameters
->EventContext
;
1163 AddrFile
->RegisteredErrorHandler
= TRUE
;
1167 case TDI_EVENT_RECEIVE
:
1168 if (Parameters
->EventHandler
== NULL
) {
1169 AddrFile
->ReceiveHandlerContext
= NULL
;
1170 AddrFile
->RegisteredReceiveHandler
= FALSE
;
1172 AddrFile
->ReceiveHandler
=
1173 (PTDI_IND_RECEIVE
)Parameters
->EventHandler
;
1174 AddrFile
->ReceiveHandlerContext
= Parameters
->EventContext
;
1175 AddrFile
->RegisteredReceiveHandler
= TRUE
;
1179 case TDI_EVENT_RECEIVE_DATAGRAM
:
1180 if (Parameters
->EventHandler
== NULL
) {
1181 AddrFile
->ReceiveDatagramHandlerContext
= NULL
;
1182 AddrFile
->RegisteredReceiveDatagramHandler
= FALSE
;
1184 AddrFile
->ReceiveDatagramHandler
=
1185 (PTDI_IND_RECEIVE_DATAGRAM
)Parameters
->EventHandler
;
1186 AddrFile
->ReceiveDatagramHandlerContext
= Parameters
->EventContext
;
1187 AddrFile
->RegisteredReceiveDatagramHandler
= TRUE
;
1191 case TDI_EVENT_RECEIVE_EXPEDITED
:
1192 if (Parameters
->EventHandler
== NULL
) {
1193 AddrFile
->ExpeditedReceiveHandlerContext
= NULL
;
1194 AddrFile
->RegisteredExpeditedReceiveHandler
= FALSE
;
1196 AddrFile
->ExpeditedReceiveHandler
=
1197 (PTDI_IND_RECEIVE_EXPEDITED
)Parameters
->EventHandler
;
1198 AddrFile
->ExpeditedReceiveHandlerContext
= Parameters
->EventContext
;
1199 AddrFile
->RegisteredExpeditedReceiveHandler
= TRUE
;
1203 case TDI_EVENT_CHAINED_RECEIVE
:
1204 if (Parameters
->EventHandler
== NULL
) {
1205 AddrFile
->ChainedReceiveHandlerContext
= NULL
;
1206 AddrFile
->RegisteredChainedReceiveHandler
= FALSE
;
1208 AddrFile
->ChainedReceiveHandler
=
1209 (PTDI_IND_CHAINED_RECEIVE
)Parameters
->EventHandler
;
1210 AddrFile
->ChainedReceiveHandlerContext
= Parameters
->EventContext
;
1211 AddrFile
->RegisteredChainedReceiveHandler
= TRUE
;
1215 case TDI_EVENT_CHAINED_RECEIVE_DATAGRAM
:
1216 if (Parameters
->EventHandler
== NULL
) {
1217 AddrFile
->ChainedReceiveDatagramHandlerContext
= NULL
;
1218 AddrFile
->RegisteredChainedReceiveDatagramHandler
= FALSE
;
1220 AddrFile
->ChainedReceiveDatagramHandler
=
1221 (PTDI_IND_CHAINED_RECEIVE_DATAGRAM
)Parameters
->EventHandler
;
1222 AddrFile
->ChainedReceiveDatagramHandlerContext
= Parameters
->EventContext
;
1223 AddrFile
->RegisteredChainedReceiveDatagramHandler
= TRUE
;
1227 case TDI_EVENT_CHAINED_RECEIVE_EXPEDITED
:
1228 if (Parameters
->EventHandler
== NULL
) {
1229 AddrFile
->ChainedReceiveExpeditedHandlerContext
= NULL
;
1230 AddrFile
->RegisteredChainedReceiveExpeditedHandler
= FALSE
;
1232 AddrFile
->ChainedReceiveExpeditedHandler
=
1233 (PTDI_IND_CHAINED_RECEIVE_EXPEDITED
)Parameters
->EventHandler
;
1234 AddrFile
->ChainedReceiveExpeditedHandlerContext
= Parameters
->EventContext
;
1235 AddrFile
->RegisteredChainedReceiveExpeditedHandler
= TRUE
;
1240 TI_DbgPrint(MIN_TRACE
, ("Unknown event type (0x%X).\n",
1241 Parameters
->EventType
));
1243 Status
= STATUS_INVALID_PARAMETER
;
1246 TcpipReleaseSpinLock(&AddrFile
->Lock
, OldIrql
);
1252 NTSTATUS
DispTdiSetInformation(
1255 * FUNCTION: TDI_SET_INFORMATION handler
1257 * Irp = Pointer to an I/O request packet
1259 * Status of operation
1262 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
1264 return STATUS_NOT_IMPLEMENTED
;
1268 VOID
DispTdiQueryInformationExComplete(
1273 * FUNCTION: Completes a TDI QueryInformationEx request
1275 * Context = Pointer to the IRP for the request
1276 * Status = TDI status of the request
1277 * ByteCount = Number of bytes returned in output buffer
1280 PTI_QUERY_CONTEXT QueryContext
;
1283 QueryContext
= (PTI_QUERY_CONTEXT
)Context
;
1284 if (NT_SUCCESS(Status
)) {
1285 Count
= CopyBufferToBufferChain(
1286 QueryContext
->InputMdl
,
1287 FIELD_OFFSET(TCP_REQUEST_QUERY_INFORMATION_EX
, Context
),
1288 (PCHAR
)&QueryContext
->QueryInfo
.Context
,
1292 MmUnlockPages(QueryContext
->InputMdl
);
1293 IoFreeMdl(QueryContext
->InputMdl
);
1294 if( QueryContext
->OutputMdl
) {
1295 MmUnlockPages(QueryContext
->OutputMdl
);
1296 IoFreeMdl(QueryContext
->OutputMdl
);
1299 QueryContext
->Irp
->IoStatus
.Information
= ByteCount
;
1300 QueryContext
->Irp
->IoStatus
.Status
= Status
;
1302 exFreePool(QueryContext
);
1306 NTSTATUS
DispTdiQueryInformationEx(
1308 PIO_STACK_LOCATION IrpSp
)
1310 * FUNCTION: TDI QueryInformationEx handler
1312 * Irp = Pointer to I/O request packet
1313 * IrpSp = Pointer to current stack location of Irp
1315 * Status of operation
1318 PTCP_REQUEST_QUERY_INFORMATION_EX InputBuffer
;
1319 PTRANSPORT_CONTEXT TranContext
;
1320 PTI_QUERY_CONTEXT QueryContext
;
1322 TDI_REQUEST Request
;
1324 UINT InputBufferLength
;
1325 UINT OutputBufferLength
;
1326 BOOLEAN InputMdlLocked
= FALSE
;
1327 BOOLEAN OutputMdlLocked
= FALSE
;
1328 PMDL InputMdl
= NULL
;
1329 PMDL OutputMdl
= NULL
;
1330 NTSTATUS Status
= STATUS_SUCCESS
;
1332 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
1334 TranContext
= (PTRANSPORT_CONTEXT
)IrpSp
->FileObject
->FsContext
;
1336 switch ((ULONG
)IrpSp
->FileObject
->FsContext2
) {
1337 case TDI_TRANSPORT_ADDRESS_FILE
:
1338 Request
.Handle
.AddressHandle
= TranContext
->Handle
.AddressHandle
;
1341 case TDI_CONNECTION_FILE
:
1342 Request
.Handle
.ConnectionContext
= TranContext
->Handle
.ConnectionContext
;
1345 case TDI_CONTROL_CHANNEL_FILE
:
1346 Request
.Handle
.ControlChannel
= TranContext
->Handle
.ControlChannel
;
1350 TI_DbgPrint(MIN_TRACE
, ("Invalid transport context\n"));
1351 return STATUS_INVALID_PARAMETER
;
1354 InputBufferLength
= IrpSp
->Parameters
.DeviceIoControl
.InputBufferLength
;
1355 OutputBufferLength
= IrpSp
->Parameters
.DeviceIoControl
.OutputBufferLength
;
1357 /* Validate parameters */
1358 if ((InputBufferLength
== sizeof(TCP_REQUEST_QUERY_INFORMATION_EX
)) &&
1359 (OutputBufferLength
!= 0)) {
1361 InputBuffer
= (PTCP_REQUEST_QUERY_INFORMATION_EX
)
1362 IrpSp
->Parameters
.DeviceIoControl
.Type3InputBuffer
;
1363 OutputBuffer
= Irp
->UserBuffer
;
1365 QueryContext
= exAllocatePool(NonPagedPool
, sizeof(TI_QUERY_CONTEXT
));
1368 InputMdl
= IoAllocateMdl(InputBuffer
,
1369 sizeof(TCP_REQUEST_QUERY_INFORMATION_EX
),
1372 OutputMdl
= IoAllocateMdl(OutputBuffer
,
1373 OutputBufferLength
, FALSE
, TRUE
, NULL
);
1375 if (InputMdl
&& OutputMdl
) {
1377 MmProbeAndLockPages(InputMdl
, Irp
->RequestorMode
,
1380 InputMdlLocked
= TRUE
;
1382 MmProbeAndLockPages(OutputMdl
, Irp
->RequestorMode
,
1385 OutputMdlLocked
= TRUE
;
1387 RtlCopyMemory(&QueryContext
->QueryInfo
,
1388 InputBuffer
, sizeof(TCP_REQUEST_QUERY_INFORMATION_EX
));
1390 Status
= STATUS_INSUFFICIENT_RESOURCES
;
1391 } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
) {
1392 Status
= _SEH2_GetExceptionCode();
1395 if (NT_SUCCESS(Status
)) {
1396 Size
= MmGetMdlByteCount(OutputMdl
);
1398 QueryContext
->Irp
= Irp
;
1399 QueryContext
->InputMdl
= InputMdl
;
1400 QueryContext
->OutputMdl
= OutputMdl
;
1402 Request
.RequestNotifyObject
= DispTdiQueryInformationExComplete
;
1403 Request
.RequestContext
= QueryContext
;
1404 Status
= InfoTdiQueryInformationEx(&Request
,
1405 &QueryContext
->QueryInfo
.ID
, OutputMdl
,
1406 &Size
, &QueryContext
->QueryInfo
.Context
);
1407 DispTdiQueryInformationExComplete(QueryContext
, Status
, Size
);
1409 TI_DbgPrint(MAX_TRACE
, ("Leaving. Status = (0x%X)\n", Status
));
1414 /* An error occurred if we get here */
1418 MmUnlockPages(InputMdl
);
1419 IoFreeMdl(InputMdl
);
1423 if (OutputMdlLocked
)
1424 MmUnlockPages(OutputMdl
);
1425 IoFreeMdl(OutputMdl
);
1428 exFreePool(QueryContext
);
1430 Status
= STATUS_INSUFFICIENT_RESOURCES
;
1431 } else if( InputBufferLength
==
1432 sizeof(TCP_REQUEST_QUERY_INFORMATION_EX
) ) {
1433 /* Handle the case where the user is probing the buffer for length */
1434 TI_DbgPrint(MAX_TRACE
, ("InputBufferLength %d OutputBufferLength %d\n",
1435 InputBufferLength
, OutputBufferLength
));
1436 InputBuffer
= (PTCP_REQUEST_QUERY_INFORMATION_EX
)
1437 IrpSp
->Parameters
.DeviceIoControl
.Type3InputBuffer
;
1441 QueryContext
= exAllocatePool(NonPagedPool
, sizeof(TI_QUERY_CONTEXT
));
1442 if (!QueryContext
) return STATUS_INSUFFICIENT_RESOURCES
;
1445 InputMdl
= IoAllocateMdl(InputBuffer
,
1446 sizeof(TCP_REQUEST_QUERY_INFORMATION_EX
),
1449 MmProbeAndLockPages(InputMdl
, Irp
->RequestorMode
,
1452 InputMdlLocked
= TRUE
;
1453 Status
= STATUS_SUCCESS
;
1454 } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
) {
1455 TI_DbgPrint(MAX_TRACE
, ("Failed to acquire client buffer\n"));
1456 Status
= _SEH2_GetExceptionCode();
1459 if( !NT_SUCCESS(Status
) || !InputMdl
) {
1460 if( InputMdl
) IoFreeMdl( InputMdl
);
1461 exFreePool(QueryContext
);
1465 RtlCopyMemory(&QueryContext
->QueryInfo
,
1466 InputBuffer
, sizeof(TCP_REQUEST_QUERY_INFORMATION_EX
));
1468 QueryContext
->Irp
= Irp
;
1469 QueryContext
->InputMdl
= InputMdl
;
1470 QueryContext
->OutputMdl
= NULL
;
1472 Request
.RequestNotifyObject
= DispTdiQueryInformationExComplete
;
1473 Request
.RequestContext
= QueryContext
;
1474 Status
= InfoTdiQueryInformationEx(&Request
,
1475 &QueryContext
->QueryInfo
.ID
,
1478 &QueryContext
->QueryInfo
.Context
);
1479 DispTdiQueryInformationExComplete(QueryContext
, Status
, Size
);
1480 TI_DbgPrint(MAX_TRACE
, ("Leaving. Status = (0x%X)\n", Status
));
1481 } else Status
= STATUS_INVALID_PARAMETER
;
1483 TI_DbgPrint(MIN_TRACE
, ("Leaving. Status = (0x%X)\n", Status
));
1489 NTSTATUS
DispTdiSetInformationEx(
1491 PIO_STACK_LOCATION IrpSp
)
1493 * FUNCTION: TDI SetInformationEx handler
1495 * Irp = Pointer to I/O request packet
1496 * IrpSp = Pointer to current stack location of Irp
1498 * Status of operation
1501 PTRANSPORT_CONTEXT TranContext
;
1502 PTCP_REQUEST_SET_INFORMATION_EX Info
;
1503 TDI_REQUEST Request
;
1506 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
1508 TranContext
= (PTRANSPORT_CONTEXT
)IrpSp
->FileObject
->FsContext
;
1509 Info
= (PTCP_REQUEST_SET_INFORMATION_EX
)Irp
->AssociatedIrp
.SystemBuffer
;
1511 switch ((ULONG
)IrpSp
->FileObject
->FsContext2
) {
1512 case TDI_TRANSPORT_ADDRESS_FILE
:
1513 Request
.Handle
.AddressHandle
= TranContext
->Handle
.AddressHandle
;
1516 case TDI_CONNECTION_FILE
:
1517 Request
.Handle
.ConnectionContext
= TranContext
->Handle
.ConnectionContext
;
1520 case TDI_CONTROL_CHANNEL_FILE
:
1521 Request
.Handle
.ControlChannel
= TranContext
->Handle
.ControlChannel
;
1525 Irp
->IoStatus
.Status
= STATUS_INVALID_PARAMETER
;
1526 Irp
->IoStatus
.Information
= 0;
1528 TI_DbgPrint(DEBUG_IRP
, ("Completing IRP at (0x%X).\n", Irp
));
1530 return Irp
->IoStatus
.Status
;
1533 Status
= DispPrepareIrpForCancel(TranContext
, Irp
, NULL
);
1534 if (NT_SUCCESS(Status
)) {
1535 Request
.RequestNotifyObject
= DispDataRequestComplete
;
1536 Request
.RequestContext
= Irp
;
1538 Status
= InfoTdiSetInformationEx(&Request
, &Info
->ID
,
1539 &Info
->Buffer
, Info
->BufferSize
);
1545 /* TODO: Support multiple addresses per interface.
1546 * For now just set the nte context to the interface index.
1548 * Later on, create an NTE context and NTE instance
1551 NTSTATUS
DispTdiSetIPAddress( PIRP Irp
, PIO_STACK_LOCATION IrpSp
) {
1552 NTSTATUS Status
= STATUS_DEVICE_DOES_NOT_EXIST
;
1553 PIP_SET_ADDRESS IpAddrChange
=
1554 (PIP_SET_ADDRESS
)Irp
->AssociatedIrp
.SystemBuffer
;
1557 TI_DbgPrint(MID_TRACE
,("Setting IP Address for adapter %d\n",
1558 IpAddrChange
->NteIndex
));
1560 ForEachInterface(IF
) {
1561 TI_DbgPrint(MID_TRACE
,("Looking at adapter %d\n", IF
->Index
));
1563 if( IF
->Unicast
.Address
.IPv4Address
== IpAddrChange
->Address
) {
1564 Status
= STATUS_DUPLICATE_OBJECTID
;
1567 if( IF
->Index
== IpAddrChange
->NteIndex
) {
1568 IPRemoveInterfaceRoute( IF
);
1570 IF
->Unicast
.Type
= IP_ADDRESS_V4
;
1571 IF
->Unicast
.Address
.IPv4Address
= IpAddrChange
->Address
;
1572 IF
->Netmask
.Type
= IP_ADDRESS_V4
;
1573 IF
->Netmask
.Address
.IPv4Address
= IpAddrChange
->Netmask
;
1574 IF
->Broadcast
.Type
= IP_ADDRESS_V4
;
1575 IF
->Broadcast
.Address
.IPv4Address
=
1576 IF
->Unicast
.Address
.IPv4Address
|
1577 ~IF
->Netmask
.Address
.IPv4Address
;
1579 TI_DbgPrint(MID_TRACE
,("New Unicast Address: %x\n",
1580 IF
->Unicast
.Address
.IPv4Address
));
1581 TI_DbgPrint(MID_TRACE
,("New Netmask : %x\n",
1582 IF
->Netmask
.Address
.IPv4Address
));
1584 IPAddInterfaceRoute( IF
);
1586 IpAddrChange
->Address
= IF
->Index
;
1587 Status
= STATUS_SUCCESS
;
1588 Irp
->IoStatus
.Information
= IF
->Index
;
1593 Irp
->IoStatus
.Status
= Status
;
1597 NTSTATUS
DispTdiDeleteIPAddress( PIRP Irp
, PIO_STACK_LOCATION IrpSp
) {
1598 NTSTATUS Status
= STATUS_UNSUCCESSFUL
;
1599 PUSHORT NteIndex
= Irp
->AssociatedIrp
.SystemBuffer
;
1602 ForEachInterface(IF
) {
1603 if( IF
->Index
== *NteIndex
) {
1604 IPRemoveInterfaceRoute( IF
);
1605 IF
->Unicast
.Type
= IP_ADDRESS_V4
;
1606 IF
->Unicast
.Address
.IPv4Address
= 0;
1607 IF
->Netmask
.Type
= IP_ADDRESS_V4
;
1608 IF
->Netmask
.Address
.IPv4Address
= 0;
1609 IF
->Broadcast
.Type
= IP_ADDRESS_V4
;
1610 IF
->Broadcast
.Address
.IPv4Address
= 0;
1611 Status
= STATUS_SUCCESS
;
1615 Irp
->IoStatus
.Status
= Status
;