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);
123 VOID NTAPI
DispCancelRequest(
124 PDEVICE_OBJECT Device
,
127 * FUNCTION: Cancels an IRP
129 * Device = Pointer to device object
130 * Irp = Pointer to an I/O request packet
133 PIO_STACK_LOCATION IrpSp
;
134 PTRANSPORT_CONTEXT TranContext
;
135 PFILE_OBJECT FileObject
;
137 DISCONNECT_TYPE DisType
;
139 /*NTSTATUS Status = STATUS_SUCCESS;*/
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
.Type
= TDI_DISCONNECT_RELEASE
|
163 ((MinorFunction
== TDI_RECEIVE
) ? TDI_DISCONNECT_ABORT
: 0);
164 DisType
.Context
= TranContext
->Handle
.ConnectionContext
;
166 DisType
.FileObject
= FileObject
;
168 TCPRemoveIRP( TranContext
->Handle
.ConnectionContext
, Irp
);
170 IoReleaseCancelSpinLock(Irp
->CancelIrql
);
172 if( !ChewCreate( &WorkItem
, sizeof(DISCONNECT_TYPE
),
173 DispDoDisconnect
, &DisType
) )
177 case TDI_SEND_DATAGRAM
:
178 if (FileObject
->FsContext2
!= (PVOID
)TDI_TRANSPORT_ADDRESS_FILE
) {
179 TI_DbgPrint(MIN_TRACE
, ("TDI_SEND_DATAGRAM, but no address file.\n"));
183 DGRemoveIRP(TranContext
->Handle
.AddressHandle
, Irp
);
186 case TDI_RECEIVE_DATAGRAM
:
187 if (FileObject
->FsContext2
!= (PVOID
)TDI_TRANSPORT_ADDRESS_FILE
) {
188 TI_DbgPrint(MIN_TRACE
, ("TDI_RECEIVE_DATAGRAM, but no address file.\n"));
192 DGRemoveIRP(TranContext
->Handle
.AddressHandle
, Irp
);
196 TI_DbgPrint(MIN_TRACE
, ("Unknown IRP. MinorFunction (0x%X).\n", MinorFunction
));
200 IoReleaseCancelSpinLock(Irp
->CancelIrql
);
201 IRPFinish(Irp
, STATUS_CANCELLED
);
203 TI_DbgPrint(MAX_TRACE
, ("Leaving.\n"));
207 VOID NTAPI
DispCancelListenRequest(
208 PDEVICE_OBJECT Device
,
211 * FUNCTION: Cancels a listen IRP
213 * Device = Pointer to device object
214 * Irp = Pointer to an I/O request packet
217 PIO_STACK_LOCATION IrpSp
;
218 PTRANSPORT_CONTEXT TranContext
;
219 PFILE_OBJECT FileObject
;
220 PCONNECTION_ENDPOINT Connection
;
221 /*NTSTATUS Status = STATUS_SUCCESS;*/
223 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
225 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
226 FileObject
= IrpSp
->FileObject
;
227 TranContext
= (PTRANSPORT_CONTEXT
)FileObject
->FsContext
;
228 ASSERT( TDI_LISTEN
== IrpSp
->MinorFunction
);
230 TI_DbgPrint(DEBUG_IRP
, ("IRP at (0x%X).\n", Irp
));
234 TI_DbgPrint(MIN_TRACE
, ("Irp->Cancel is FALSE, should be TRUE.\n"));
237 /* Try canceling the request */
238 Connection
= (PCONNECTION_ENDPOINT
)TranContext
->Handle
.ConnectionContext
;
240 TCPRemoveIRP(Connection
, Irp
);
242 TCPAbortListenForSocket(
243 Connection
->AddressFile
->Listener
,
246 IoReleaseCancelSpinLock(Irp
->CancelIrql
);
248 Irp
->IoStatus
.Information
= 0;
249 IRPFinish(Irp
, STATUS_CANCELLED
);
251 TI_DbgPrint(MAX_TRACE
, ("Leaving.\n"));
255 NTSTATUS
DispTdiAccept(
258 * FUNCTION: TDI_ACCEPT handler
260 * Irp = Pointer to an I/O request packet
262 * Status of operation
265 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
267 return STATUS_NOT_IMPLEMENTED
;
271 NTSTATUS
DispTdiAssociateAddress(
274 * FUNCTION: TDI_ASSOCIATE_ADDRESS handler
276 * Irp = Pointer to an I/O request packet
278 * Status of operation
281 PTDI_REQUEST_KERNEL_ASSOCIATE Parameters
;
282 PTRANSPORT_CONTEXT TranContext
;
283 PIO_STACK_LOCATION IrpSp
;
284 PCONNECTION_ENDPOINT Connection
;
285 PFILE_OBJECT FileObject
;
286 PADDRESS_FILE AddrFile
= NULL
;
289 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
291 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
293 /* Get associated connection endpoint file object. Quit if none exists */
295 TranContext
= IrpSp
->FileObject
->FsContext
;
297 TI_DbgPrint(MID_TRACE
, ("Bad transport context.\n"));
298 return STATUS_INVALID_PARAMETER
;
301 Connection
= (PCONNECTION_ENDPOINT
)TranContext
->Handle
.ConnectionContext
;
303 TI_DbgPrint(MID_TRACE
, ("No connection endpoint file object.\n"));
304 return STATUS_INVALID_PARAMETER
;
307 if (Connection
->AddressFile
) {
308 TI_DbgPrint(MID_TRACE
, ("An address file is already asscociated.\n"));
309 return STATUS_INVALID_PARAMETER
;
312 Parameters
= (PTDI_REQUEST_KERNEL_ASSOCIATE
)&IrpSp
->Parameters
;
314 Status
= ObReferenceObjectByHandle(
315 Parameters
->AddressHandle
,
321 if (!NT_SUCCESS(Status
)) {
322 TI_DbgPrint(MID_TRACE
, ("Bad address file object handle (0x%X): %x.\n",
323 Parameters
->AddressHandle
, Status
));
324 return STATUS_INVALID_PARAMETER
;
327 if (FileObject
->FsContext2
!= (PVOID
)TDI_TRANSPORT_ADDRESS_FILE
) {
328 ObDereferenceObject(FileObject
);
329 TI_DbgPrint(MID_TRACE
, ("Bad address file object. Magic (0x%X).\n",
330 FileObject
->FsContext2
));
331 return STATUS_INVALID_PARAMETER
;
334 /* Get associated address file object. Quit if none exists */
336 TranContext
= FileObject
->FsContext
;
338 ObDereferenceObject(FileObject
);
339 TI_DbgPrint(MID_TRACE
, ("Bad transport context.\n"));
340 return STATUS_INVALID_PARAMETER
;
343 AddrFile
= (PADDRESS_FILE
)TranContext
->Handle
.AddressHandle
;
345 ObDereferenceObject(FileObject
);
346 TI_DbgPrint(MID_TRACE
, ("No address file object.\n"));
347 return STATUS_INVALID_PARAMETER
;
350 Connection
->AddressFile
= AddrFile
;
352 /* Add connection endpoint to the address file */
353 AddrFile
->Connection
= Connection
;
355 /* FIXME: Maybe do this in DispTdiDisassociateAddress() instead? */
356 ObDereferenceObject(FileObject
);
362 NTSTATUS
DispTdiConnect(
365 * FUNCTION: TDI_CONNECT handler
367 * Irp = Pointer to an I/O request packet
369 * Status of operation
372 PCONNECTION_ENDPOINT Connection
;
373 PTDI_REQUEST_KERNEL Parameters
;
374 PTRANSPORT_CONTEXT TranContext
;
375 PIO_STACK_LOCATION IrpSp
;
378 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
380 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
382 /* Get associated connection endpoint file object. Quit if none exists */
384 TcpipRecursiveMutexEnter( &TCPLock
, TRUE
);
386 TranContext
= IrpSp
->FileObject
->FsContext
;
388 TI_DbgPrint(MID_TRACE
, ("Bad transport context.\n"));
389 Status
= STATUS_INVALID_PARAMETER
;
393 Connection
= (PCONNECTION_ENDPOINT
)TranContext
->Handle
.ConnectionContext
;
395 TI_DbgPrint(MID_TRACE
, ("No connection endpoint file object.\n"));
396 Status
= STATUS_INVALID_PARAMETER
;
400 Parameters
= (PTDI_REQUEST_KERNEL
)&IrpSp
->Parameters
;
403 TranContext
->Handle
.ConnectionContext
,
404 Parameters
->RequestConnectionInformation
,
405 Parameters
->ReturnConnectionInformation
,
406 DispDataRequestComplete
,
410 TcpipRecursiveMutexLeave( &TCPLock
);
412 if (Status
!= STATUS_PENDING
) {
413 DispDataRequestComplete(Irp
, Status
, 0);
415 IoMarkIrpPending(Irp
);
417 TI_DbgPrint(MAX_TRACE
, ("TCP Connect returned %08x\n", Status
));
423 NTSTATUS
DispTdiDisassociateAddress(
426 * FUNCTION: TDI_DISASSOCIATE_ADDRESS handler
428 * Irp = Pointer to an I/O request packet
430 * Status of operation
433 PCONNECTION_ENDPOINT Connection
;
434 PTRANSPORT_CONTEXT TranContext
;
435 PIO_STACK_LOCATION IrpSp
;
437 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
439 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
441 /* Get associated connection endpoint file object. Quit if none exists */
443 TranContext
= IrpSp
->FileObject
->FsContext
;
445 TI_DbgPrint(MID_TRACE
, ("Bad transport context.\n"));
446 return STATUS_INVALID_PARAMETER
;
449 Connection
= (PCONNECTION_ENDPOINT
)TranContext
->Handle
.ConnectionContext
;
451 TI_DbgPrint(MID_TRACE
, ("No connection endpoint file object.\n"));
452 return STATUS_INVALID_PARAMETER
;
455 if (!Connection
->AddressFile
) {
456 TI_DbgPrint(MID_TRACE
, ("No address file is asscociated.\n"));
457 return STATUS_INVALID_PARAMETER
;
460 /* Remove this connection from the address file */
461 Connection
->AddressFile
->Connection
= NULL
;
463 /* Remove the address file from this connection */
464 Connection
->AddressFile
= NULL
;
466 return STATUS_SUCCESS
;
470 NTSTATUS
DispTdiDisconnect(
473 * FUNCTION: TDI_DISCONNECT handler
475 * Irp = Pointer to an I/O request packet
477 * Status of operation
481 PTDI_REQUEST_KERNEL_DISCONNECT DisReq
;
482 PCONNECTION_ENDPOINT Connection
;
483 PTRANSPORT_CONTEXT TranContext
;
484 PIO_STACK_LOCATION IrpSp
;
486 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
488 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
489 DisReq
= (PTDI_REQUEST_KERNEL_DISCONNECT
)&IrpSp
->Parameters
;
491 TcpipRecursiveMutexEnter( &TCPLock
, TRUE
);
493 /* Get associated connection endpoint file object. Quit if none exists */
495 TranContext
= IrpSp
->FileObject
->FsContext
;
497 TI_DbgPrint(MID_TRACE
, ("Bad transport context.\n"));
498 Status
= STATUS_INVALID_PARAMETER
;
502 Connection
= (PCONNECTION_ENDPOINT
)TranContext
->Handle
.ConnectionContext
;
504 TI_DbgPrint(MID_TRACE
, ("No connection endpoint file object.\n"));
505 Status
= STATUS_INVALID_PARAMETER
;
509 Status
= TCPDisconnect(
510 TranContext
->Handle
.ConnectionContext
,
511 DisReq
->RequestFlags
,
512 DisReq
->RequestConnectionInformation
,
513 DisReq
->ReturnConnectionInformation
,
514 DispDataRequestComplete
,
518 TcpipRecursiveMutexLeave( &TCPLock
);
520 if (Status
!= STATUS_PENDING
) {
521 DispDataRequestComplete(Irp
, Status
, 0);
523 IoMarkIrpPending(Irp
);
525 TI_DbgPrint(MAX_TRACE
, ("TCP Disconnect returned %08x\n", Status
));
531 NTSTATUS
DispTdiListen(
534 * FUNCTION: TDI_LISTEN handler
536 * Irp = Pointer to an I/O request packet
538 * Status of operation
541 PCONNECTION_ENDPOINT Connection
;
542 PTDI_REQUEST_KERNEL Parameters
;
543 PTRANSPORT_CONTEXT TranContext
;
544 PIO_STACK_LOCATION IrpSp
;
545 NTSTATUS Status
= STATUS_SUCCESS
;
547 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
549 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
551 /* Get associated connection endpoint file object. Quit if none exists */
553 TcpipRecursiveMutexEnter( &TCPLock
, TRUE
);
555 TranContext
= IrpSp
->FileObject
->FsContext
;
556 if (TranContext
== NULL
)
558 TI_DbgPrint(MID_TRACE
, ("Bad transport context.\n"));
559 Status
= STATUS_INVALID_PARAMETER
;
563 Connection
= (PCONNECTION_ENDPOINT
)TranContext
->Handle
.ConnectionContext
;
564 if (Connection
== NULL
)
566 TI_DbgPrint(MID_TRACE
, ("No connection endpoint file object.\n"));
567 Status
= STATUS_INVALID_PARAMETER
;
571 Parameters
= (PTDI_REQUEST_KERNEL
)&IrpSp
->Parameters
;
573 TI_DbgPrint(MIN_TRACE
, ("Connection->AddressFile: %x\n",
574 Connection
->AddressFile
));
575 if( Connection
->AddressFile
) {
576 TI_DbgPrint(MIN_TRACE
, ("Connection->AddressFile->Listener: %x\n",
577 Connection
->AddressFile
->Listener
));
580 /* Listening will require us to create a listening socket and store it in
581 * the address file. It will be signalled, and attempt to complete an irp
582 * when a new connection arrives. */
583 /* The important thing to note here is that the irp we'll complete belongs
584 * to the socket to be accepted onto, not the listener */
585 if( !Connection
->AddressFile
->Listener
) {
586 Connection
->AddressFile
->Listener
=
587 TCPAllocateConnectionEndpoint( NULL
);
589 if( !Connection
->AddressFile
->Listener
)
590 Status
= STATUS_NO_MEMORY
;
592 if( NT_SUCCESS(Status
) ) {
593 Connection
->AddressFile
->Listener
->AddressFile
=
594 Connection
->AddressFile
;
596 Status
= TCPSocket( Connection
->AddressFile
->Listener
,
597 Connection
->AddressFile
->Family
,
599 Connection
->AddressFile
->Protocol
);
602 if( NT_SUCCESS(Status
) )
603 Status
= TCPListen( Connection
->AddressFile
->Listener
, 1024 );
606 if( NT_SUCCESS(Status
) ) {
607 Status
= DispPrepareIrpForCancel
608 (TranContext
->Handle
.ConnectionContext
,
610 (PDRIVER_CANCEL
)DispCancelListenRequest
);
613 if( NT_SUCCESS(Status
) ) {
615 ( (PTDI_REQUEST
)Parameters
,
616 Connection
->AddressFile
->Listener
,
618 DispDataRequestComplete
,
623 TcpipRecursiveMutexLeave( &TCPLock
);
625 if (Status
!= STATUS_PENDING
) {
626 DispDataRequestComplete(Irp
, Status
, 0);
628 IoMarkIrpPending(Irp
);
630 TI_DbgPrint(MID_TRACE
,("Leaving %x\n", Status
));
636 NTSTATUS
DispTdiQueryInformation(
637 PDEVICE_OBJECT DeviceObject
,
640 * FUNCTION: TDI_QUERY_INFORMATION handler
642 * DeviceObject = Pointer to device object structure
643 * Irp = Pointer to an I/O request packet
645 * Status of operation
648 PTDI_REQUEST_KERNEL_QUERY_INFORMATION Parameters
;
649 PTRANSPORT_CONTEXT TranContext
;
650 PIO_STACK_LOCATION IrpSp
;
653 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
655 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
656 Parameters
= (PTDI_REQUEST_KERNEL_QUERY_INFORMATION
)&IrpSp
->Parameters
;
658 TcpipRecursiveMutexEnter( &TCPLock
, TRUE
);
660 TranContext
= IrpSp
->FileObject
->FsContext
;
662 TI_DbgPrint(MID_TRACE
, ("Bad transport context.\n"));
663 TcpipRecursiveMutexLeave(&TCPLock
);
664 return STATUS_INVALID_PARAMETER
;
667 switch (Parameters
->QueryType
)
669 case TDI_QUERY_ADDRESS_INFO
:
671 PTDI_ADDRESS_INFO AddressInfo
;
672 PADDRESS_FILE AddrFile
;
673 PTA_IP_ADDRESS Address
;
674 PCONNECTION_ENDPOINT Endpoint
= NULL
;
677 if (MmGetMdlByteCount(Irp
->MdlAddress
) <
678 (FIELD_OFFSET(TDI_ADDRESS_INFO
, Address
.Address
[0].Address
) +
679 sizeof(TDI_ADDRESS_IP
))) {
680 TI_DbgPrint(MID_TRACE
, ("MDL buffer too small.\n"));
681 TcpipRecursiveMutexLeave(&TCPLock
);
682 return STATUS_BUFFER_TOO_SMALL
;
685 AddressInfo
= (PTDI_ADDRESS_INFO
)MmGetSystemAddressForMdl(Irp
->MdlAddress
);
686 Address
= (PTA_IP_ADDRESS
)&AddressInfo
->Address
;
688 switch ((ULONG_PTR
)IrpSp
->FileObject
->FsContext2
) {
689 case TDI_TRANSPORT_ADDRESS_FILE
:
690 AddrFile
= (PADDRESS_FILE
)TranContext
->Handle
.AddressHandle
;
692 Address
->TAAddressCount
= 1;
693 Address
->Address
[0].AddressLength
= TDI_ADDRESS_LENGTH_IP
;
694 Address
->Address
[0].AddressType
= TDI_ADDRESS_TYPE_IP
;
695 Address
->Address
[0].Address
[0].sin_port
= AddrFile
->Port
;
696 Address
->Address
[0].Address
[0].in_addr
= AddrFile
->Address
.Address
.IPv4Address
;
698 &Address
->Address
[0].Address
[0].sin_zero
,
699 sizeof(Address
->Address
[0].Address
[0].sin_zero
));
700 TcpipRecursiveMutexLeave(&TCPLock
);
701 return STATUS_SUCCESS
;
703 case TDI_CONNECTION_FILE
:
705 (PCONNECTION_ENDPOINT
)TranContext
->Handle
.ConnectionContext
;
706 TCPGetSockAddress( Endpoint
, (PTRANSPORT_ADDRESS
)Address
, FALSE
);
707 DbgPrint("Returning socket address %x\n", Address
->Address
[0].Address
[0].in_addr
);
709 &Address
->Address
[0].Address
[0].sin_zero
,
710 sizeof(Address
->Address
[0].Address
[0].sin_zero
));
711 TcpipRecursiveMutexLeave(&TCPLock
);
712 return STATUS_SUCCESS
;
715 TI_DbgPrint(MIN_TRACE
, ("Invalid transport context\n"));
716 TcpipRecursiveMutexLeave(&TCPLock
);
717 return STATUS_INVALID_PARAMETER
;
721 TI_DbgPrint(MID_TRACE
, ("No address file object.\n"));
722 TcpipRecursiveMutexLeave(&TCPLock
);
723 return STATUS_INVALID_PARAMETER
;
726 TcpipRecursiveMutexLeave(&TCPLock
);
727 return STATUS_SUCCESS
;
730 case TDI_QUERY_CONNECTION_INFO
:
732 PTDI_CONNECTION_INFORMATION AddressInfo
;
733 PADDRESS_FILE AddrFile
;
734 PCONNECTION_ENDPOINT Endpoint
= NULL
;
736 if (MmGetMdlByteCount(Irp
->MdlAddress
) <
737 (FIELD_OFFSET(TDI_CONNECTION_INFORMATION
, RemoteAddress
) +
739 TI_DbgPrint(MID_TRACE
, ("MDL buffer too small (ptr).\n"));
740 TcpipRecursiveMutexLeave(&TCPLock
);
741 return STATUS_BUFFER_TOO_SMALL
;
744 AddressInfo
= (PTDI_CONNECTION_INFORMATION
)
745 MmGetSystemAddressForMdl(Irp
->MdlAddress
);
747 switch ((ULONG_PTR
)IrpSp
->FileObject
->FsContext2
) {
748 case TDI_TRANSPORT_ADDRESS_FILE
:
749 AddrFile
= (PADDRESS_FILE
)TranContext
->Handle
.AddressHandle
;
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
) )
1066 Status
= (*((PADDRESS_FILE
)Request
.Handle
.AddressHandle
)->Send
)(
1067 Request
.Handle
.AddressHandle
,
1068 DgramInfo
->SendDatagramInformation
,
1072 Irp
->IoStatus
.Information
= DataUsed
;
1075 Status
= STATUS_UNSUCCESSFUL
;
1079 TcpipRecursiveMutexLeave( &TCPLock
);
1081 if (Status
!= STATUS_PENDING
) {
1082 DispDataRequestComplete(Irp
, Status
, Irp
->IoStatus
.Information
);
1084 IoMarkIrpPending(Irp
);
1086 TI_DbgPrint(DEBUG_IRP
, ("Leaving.\n"));
1092 NTSTATUS
DispTdiSetEventHandler(PIRP Irp
)
1094 * FUNCTION: TDI_SET_EVENT_HANDER handler
1096 * Irp = Pointer to a I/O request packet
1098 * Status of operation
1101 PTDI_REQUEST_KERNEL_SET_EVENT Parameters
;
1102 PTRANSPORT_CONTEXT TranContext
;
1103 PIO_STACK_LOCATION IrpSp
;
1104 PADDRESS_FILE AddrFile
;
1108 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
1110 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
1112 /* Get associated address file object. Quit if none exists */
1114 TranContext
= IrpSp
->FileObject
->FsContext
;
1116 TI_DbgPrint(MIN_TRACE
, ("Bad transport context.\n"));
1117 return STATUS_INVALID_PARAMETER
;
1120 AddrFile
= (PADDRESS_FILE
)TranContext
->Handle
.AddressHandle
;
1122 TI_DbgPrint(MIN_TRACE
, ("No address file object.\n"));
1123 return STATUS_INVALID_PARAMETER
;
1126 Parameters
= (PTDI_REQUEST_KERNEL_SET_EVENT
)&IrpSp
->Parameters
;
1127 Status
= STATUS_SUCCESS
;
1129 TcpipAcquireSpinLock(&AddrFile
->Lock
, &OldIrql
);
1131 /* Set the event handler. if an event handler is associated with
1132 a specific event, it's flag (RegisteredXxxHandler) is TRUE.
1133 If an event handler is not used it's flag is FALSE */
1134 switch (Parameters
->EventType
) {
1135 case TDI_EVENT_CONNECT
:
1136 if (!Parameters
->EventHandler
) {
1137 AddrFile
->ConnectHandlerContext
= NULL
;
1138 AddrFile
->RegisteredConnectHandler
= FALSE
;
1140 AddrFile
->ConnectHandler
=
1141 (PTDI_IND_CONNECT
)Parameters
->EventHandler
;
1142 AddrFile
->ConnectHandlerContext
= Parameters
->EventContext
;
1143 AddrFile
->RegisteredConnectHandler
= TRUE
;
1147 case TDI_EVENT_DISCONNECT
:
1148 if (!Parameters
->EventHandler
) {
1149 AddrFile
->DisconnectHandlerContext
= NULL
;
1150 AddrFile
->RegisteredDisconnectHandler
= FALSE
;
1152 AddrFile
->DisconnectHandler
=
1153 (PTDI_IND_DISCONNECT
)Parameters
->EventHandler
;
1154 AddrFile
->DisconnectHandlerContext
= Parameters
->EventContext
;
1155 AddrFile
->RegisteredDisconnectHandler
= TRUE
;
1159 case TDI_EVENT_ERROR
:
1160 if (Parameters
->EventHandler
== NULL
) {
1161 AddrFile
->ErrorHandlerContext
= NULL
;
1162 AddrFile
->RegisteredErrorHandler
= FALSE
;
1164 AddrFile
->ErrorHandler
=
1165 (PTDI_IND_ERROR
)Parameters
->EventHandler
;
1166 AddrFile
->ErrorHandlerContext
= Parameters
->EventContext
;
1167 AddrFile
->RegisteredErrorHandler
= TRUE
;
1171 case TDI_EVENT_RECEIVE
:
1172 if (Parameters
->EventHandler
== NULL
) {
1173 AddrFile
->ReceiveHandlerContext
= NULL
;
1174 AddrFile
->RegisteredReceiveHandler
= FALSE
;
1176 AddrFile
->ReceiveHandler
=
1177 (PTDI_IND_RECEIVE
)Parameters
->EventHandler
;
1178 AddrFile
->ReceiveHandlerContext
= Parameters
->EventContext
;
1179 AddrFile
->RegisteredReceiveHandler
= TRUE
;
1183 case TDI_EVENT_RECEIVE_DATAGRAM
:
1184 if (Parameters
->EventHandler
== NULL
) {
1185 AddrFile
->ReceiveDatagramHandlerContext
= NULL
;
1186 AddrFile
->RegisteredReceiveDatagramHandler
= FALSE
;
1188 AddrFile
->ReceiveDatagramHandler
=
1189 (PTDI_IND_RECEIVE_DATAGRAM
)Parameters
->EventHandler
;
1190 AddrFile
->ReceiveDatagramHandlerContext
= Parameters
->EventContext
;
1191 AddrFile
->RegisteredReceiveDatagramHandler
= TRUE
;
1195 case TDI_EVENT_RECEIVE_EXPEDITED
:
1196 if (Parameters
->EventHandler
== NULL
) {
1197 AddrFile
->ExpeditedReceiveHandlerContext
= NULL
;
1198 AddrFile
->RegisteredExpeditedReceiveHandler
= FALSE
;
1200 AddrFile
->ExpeditedReceiveHandler
=
1201 (PTDI_IND_RECEIVE_EXPEDITED
)Parameters
->EventHandler
;
1202 AddrFile
->ExpeditedReceiveHandlerContext
= Parameters
->EventContext
;
1203 AddrFile
->RegisteredExpeditedReceiveHandler
= TRUE
;
1207 case TDI_EVENT_CHAINED_RECEIVE
:
1208 if (Parameters
->EventHandler
== NULL
) {
1209 AddrFile
->ChainedReceiveHandlerContext
= NULL
;
1210 AddrFile
->RegisteredChainedReceiveHandler
= FALSE
;
1212 AddrFile
->ChainedReceiveHandler
=
1213 (PTDI_IND_CHAINED_RECEIVE
)Parameters
->EventHandler
;
1214 AddrFile
->ChainedReceiveHandlerContext
= Parameters
->EventContext
;
1215 AddrFile
->RegisteredChainedReceiveHandler
= TRUE
;
1219 case TDI_EVENT_CHAINED_RECEIVE_DATAGRAM
:
1220 if (Parameters
->EventHandler
== NULL
) {
1221 AddrFile
->ChainedReceiveDatagramHandlerContext
= NULL
;
1222 AddrFile
->RegisteredChainedReceiveDatagramHandler
= FALSE
;
1224 AddrFile
->ChainedReceiveDatagramHandler
=
1225 (PTDI_IND_CHAINED_RECEIVE_DATAGRAM
)Parameters
->EventHandler
;
1226 AddrFile
->ChainedReceiveDatagramHandlerContext
= Parameters
->EventContext
;
1227 AddrFile
->RegisteredChainedReceiveDatagramHandler
= TRUE
;
1231 case TDI_EVENT_CHAINED_RECEIVE_EXPEDITED
:
1232 if (Parameters
->EventHandler
== NULL
) {
1233 AddrFile
->ChainedReceiveExpeditedHandlerContext
= NULL
;
1234 AddrFile
->RegisteredChainedReceiveExpeditedHandler
= FALSE
;
1236 AddrFile
->ChainedReceiveExpeditedHandler
=
1237 (PTDI_IND_CHAINED_RECEIVE_EXPEDITED
)Parameters
->EventHandler
;
1238 AddrFile
->ChainedReceiveExpeditedHandlerContext
= Parameters
->EventContext
;
1239 AddrFile
->RegisteredChainedReceiveExpeditedHandler
= TRUE
;
1244 TI_DbgPrint(MIN_TRACE
, ("Unknown event type (0x%X).\n",
1245 Parameters
->EventType
));
1247 Status
= STATUS_INVALID_PARAMETER
;
1250 TcpipReleaseSpinLock(&AddrFile
->Lock
, OldIrql
);
1256 NTSTATUS
DispTdiSetInformation(
1259 * FUNCTION: TDI_SET_INFORMATION handler
1261 * Irp = Pointer to an I/O request packet
1263 * Status of operation
1266 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
1268 return STATUS_NOT_IMPLEMENTED
;
1272 VOID
DispTdiQueryInformationExComplete(
1277 * FUNCTION: Completes a TDI QueryInformationEx request
1279 * Context = Pointer to the IRP for the request
1280 * Status = TDI status of the request
1281 * ByteCount = Number of bytes returned in output buffer
1284 PTI_QUERY_CONTEXT QueryContext
;
1287 QueryContext
= (PTI_QUERY_CONTEXT
)Context
;
1288 if (NT_SUCCESS(Status
)) {
1289 Count
= CopyBufferToBufferChain(
1290 QueryContext
->InputMdl
,
1291 FIELD_OFFSET(TCP_REQUEST_QUERY_INFORMATION_EX
, Context
),
1292 (PCHAR
)&QueryContext
->QueryInfo
.Context
,
1296 MmUnlockPages(QueryContext
->InputMdl
);
1297 IoFreeMdl(QueryContext
->InputMdl
);
1298 if( QueryContext
->OutputMdl
) {
1299 MmUnlockPages(QueryContext
->OutputMdl
);
1300 IoFreeMdl(QueryContext
->OutputMdl
);
1303 QueryContext
->Irp
->IoStatus
.Information
= ByteCount
;
1304 QueryContext
->Irp
->IoStatus
.Status
= Status
;
1306 exFreePool(QueryContext
);
1310 NTSTATUS
DispTdiQueryInformationEx(
1312 PIO_STACK_LOCATION IrpSp
)
1314 * FUNCTION: TDI QueryInformationEx handler
1316 * Irp = Pointer to I/O request packet
1317 * IrpSp = Pointer to current stack location of Irp
1319 * Status of operation
1322 PTCP_REQUEST_QUERY_INFORMATION_EX InputBuffer
;
1323 PTRANSPORT_CONTEXT TranContext
;
1324 PTI_QUERY_CONTEXT QueryContext
;
1326 TDI_REQUEST Request
;
1328 UINT InputBufferLength
;
1329 UINT OutputBufferLength
;
1330 BOOLEAN InputMdlLocked
= FALSE
;
1331 BOOLEAN OutputMdlLocked
= FALSE
;
1332 PMDL InputMdl
= NULL
;
1333 PMDL OutputMdl
= NULL
;
1334 NTSTATUS Status
= STATUS_SUCCESS
;
1336 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
1338 TranContext
= (PTRANSPORT_CONTEXT
)IrpSp
->FileObject
->FsContext
;
1340 switch ((ULONG_PTR
)IrpSp
->FileObject
->FsContext2
) {
1341 case TDI_TRANSPORT_ADDRESS_FILE
:
1342 Request
.Handle
.AddressHandle
= TranContext
->Handle
.AddressHandle
;
1345 case TDI_CONNECTION_FILE
:
1346 Request
.Handle
.ConnectionContext
= TranContext
->Handle
.ConnectionContext
;
1349 case TDI_CONTROL_CHANNEL_FILE
:
1350 Request
.Handle
.ControlChannel
= TranContext
->Handle
.ControlChannel
;
1354 TI_DbgPrint(MIN_TRACE
, ("Invalid transport context\n"));
1355 return STATUS_INVALID_PARAMETER
;
1358 InputBufferLength
= IrpSp
->Parameters
.DeviceIoControl
.InputBufferLength
;
1359 OutputBufferLength
= IrpSp
->Parameters
.DeviceIoControl
.OutputBufferLength
;
1361 /* Validate parameters */
1362 if ((InputBufferLength
== sizeof(TCP_REQUEST_QUERY_INFORMATION_EX
)) &&
1363 (OutputBufferLength
!= 0)) {
1365 InputBuffer
= (PTCP_REQUEST_QUERY_INFORMATION_EX
)
1366 IrpSp
->Parameters
.DeviceIoControl
.Type3InputBuffer
;
1367 OutputBuffer
= Irp
->UserBuffer
;
1369 QueryContext
= exAllocatePool(NonPagedPool
, sizeof(TI_QUERY_CONTEXT
));
1372 InputMdl
= IoAllocateMdl(InputBuffer
,
1373 sizeof(TCP_REQUEST_QUERY_INFORMATION_EX
),
1376 OutputMdl
= IoAllocateMdl(OutputBuffer
,
1377 OutputBufferLength
, FALSE
, TRUE
, NULL
);
1379 if (InputMdl
&& OutputMdl
) {
1381 MmProbeAndLockPages(InputMdl
, Irp
->RequestorMode
,
1384 InputMdlLocked
= TRUE
;
1386 MmProbeAndLockPages(OutputMdl
, Irp
->RequestorMode
,
1389 OutputMdlLocked
= TRUE
;
1391 RtlCopyMemory(&QueryContext
->QueryInfo
,
1392 InputBuffer
, sizeof(TCP_REQUEST_QUERY_INFORMATION_EX
));
1394 Status
= STATUS_INSUFFICIENT_RESOURCES
;
1395 } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
) {
1396 Status
= _SEH2_GetExceptionCode();
1399 if (NT_SUCCESS(Status
)) {
1400 Size
= MmGetMdlByteCount(OutputMdl
);
1402 QueryContext
->Irp
= Irp
;
1403 QueryContext
->InputMdl
= InputMdl
;
1404 QueryContext
->OutputMdl
= OutputMdl
;
1406 Request
.RequestNotifyObject
= DispTdiQueryInformationExComplete
;
1407 Request
.RequestContext
= QueryContext
;
1408 Status
= InfoTdiQueryInformationEx(&Request
,
1409 &QueryContext
->QueryInfo
.ID
, OutputMdl
,
1410 &Size
, &QueryContext
->QueryInfo
.Context
);
1411 DispTdiQueryInformationExComplete(QueryContext
, Status
, Size
);
1413 TI_DbgPrint(MAX_TRACE
, ("Leaving. Status = (0x%X)\n", Status
));
1418 /* An error occurred if we get here */
1422 MmUnlockPages(InputMdl
);
1423 IoFreeMdl(InputMdl
);
1427 if (OutputMdlLocked
)
1428 MmUnlockPages(OutputMdl
);
1429 IoFreeMdl(OutputMdl
);
1432 exFreePool(QueryContext
);
1434 Status
= STATUS_INSUFFICIENT_RESOURCES
;
1435 } else if( InputBufferLength
==
1436 sizeof(TCP_REQUEST_QUERY_INFORMATION_EX
) ) {
1437 /* Handle the case where the user is probing the buffer for length */
1438 TI_DbgPrint(MAX_TRACE
, ("InputBufferLength %d OutputBufferLength %d\n",
1439 InputBufferLength
, OutputBufferLength
));
1440 InputBuffer
= (PTCP_REQUEST_QUERY_INFORMATION_EX
)
1441 IrpSp
->Parameters
.DeviceIoControl
.Type3InputBuffer
;
1445 QueryContext
= exAllocatePool(NonPagedPool
, sizeof(TI_QUERY_CONTEXT
));
1446 if (!QueryContext
) return STATUS_INSUFFICIENT_RESOURCES
;
1449 InputMdl
= IoAllocateMdl(InputBuffer
,
1450 sizeof(TCP_REQUEST_QUERY_INFORMATION_EX
),
1453 MmProbeAndLockPages(InputMdl
, Irp
->RequestorMode
,
1456 InputMdlLocked
= TRUE
;
1457 Status
= STATUS_SUCCESS
;
1458 } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
) {
1459 TI_DbgPrint(MAX_TRACE
, ("Failed to acquire client buffer\n"));
1460 Status
= _SEH2_GetExceptionCode();
1463 if( !NT_SUCCESS(Status
) || !InputMdl
) {
1464 if( InputMdl
) IoFreeMdl( InputMdl
);
1465 exFreePool(QueryContext
);
1469 RtlCopyMemory(&QueryContext
->QueryInfo
,
1470 InputBuffer
, sizeof(TCP_REQUEST_QUERY_INFORMATION_EX
));
1472 QueryContext
->Irp
= Irp
;
1473 QueryContext
->InputMdl
= InputMdl
;
1474 QueryContext
->OutputMdl
= NULL
;
1476 Request
.RequestNotifyObject
= DispTdiQueryInformationExComplete
;
1477 Request
.RequestContext
= QueryContext
;
1478 Status
= InfoTdiQueryInformationEx(&Request
,
1479 &QueryContext
->QueryInfo
.ID
,
1482 &QueryContext
->QueryInfo
.Context
);
1483 DispTdiQueryInformationExComplete(QueryContext
, Status
, Size
);
1484 TI_DbgPrint(MAX_TRACE
, ("Leaving. Status = (0x%X)\n", Status
));
1485 } else Status
= STATUS_INVALID_PARAMETER
;
1487 TI_DbgPrint(MIN_TRACE
, ("Leaving. Status = (0x%X)\n", Status
));
1493 NTSTATUS
DispTdiSetInformationEx(
1495 PIO_STACK_LOCATION IrpSp
)
1497 * FUNCTION: TDI SetInformationEx handler
1499 * Irp = Pointer to I/O request packet
1500 * IrpSp = Pointer to current stack location of Irp
1502 * Status of operation
1505 PTRANSPORT_CONTEXT TranContext
;
1506 PTCP_REQUEST_SET_INFORMATION_EX Info
;
1507 TDI_REQUEST Request
;
1510 TI_DbgPrint(DEBUG_IRP
, ("Called.\n"));
1512 TranContext
= (PTRANSPORT_CONTEXT
)IrpSp
->FileObject
->FsContext
;
1513 Info
= (PTCP_REQUEST_SET_INFORMATION_EX
)Irp
->AssociatedIrp
.SystemBuffer
;
1515 switch ((ULONG_PTR
)IrpSp
->FileObject
->FsContext2
) {
1516 case TDI_TRANSPORT_ADDRESS_FILE
:
1517 Request
.Handle
.AddressHandle
= TranContext
->Handle
.AddressHandle
;
1520 case TDI_CONNECTION_FILE
:
1521 Request
.Handle
.ConnectionContext
= TranContext
->Handle
.ConnectionContext
;
1524 case TDI_CONTROL_CHANNEL_FILE
:
1525 Request
.Handle
.ControlChannel
= TranContext
->Handle
.ControlChannel
;
1529 Irp
->IoStatus
.Status
= STATUS_INVALID_PARAMETER
;
1530 Irp
->IoStatus
.Information
= 0;
1532 TI_DbgPrint(DEBUG_IRP
, ("Completing IRP at (0x%X).\n", Irp
));
1534 return Irp
->IoStatus
.Status
;
1537 Status
= DispPrepareIrpForCancel(TranContext
, Irp
, NULL
);
1538 if (NT_SUCCESS(Status
)) {
1539 Request
.RequestNotifyObject
= DispDataRequestComplete
;
1540 Request
.RequestContext
= Irp
;
1542 Status
= InfoTdiSetInformationEx(&Request
, &Info
->ID
,
1543 &Info
->Buffer
, Info
->BufferSize
);
1549 /* TODO: Support multiple addresses per interface.
1550 * For now just set the nte context to the interface index.
1552 * Later on, create an NTE context and NTE instance
1555 NTSTATUS
DispTdiSetIPAddress( PIRP Irp
, PIO_STACK_LOCATION IrpSp
) {
1556 NTSTATUS Status
= STATUS_DEVICE_DOES_NOT_EXIST
;
1557 PIP_SET_ADDRESS IpAddrChange
=
1558 (PIP_SET_ADDRESS
)Irp
->AssociatedIrp
.SystemBuffer
;
1561 TI_DbgPrint(MID_TRACE
,("Setting IP Address for adapter %d\n",
1562 IpAddrChange
->NteIndex
));
1564 ForEachInterface(IF
) {
1565 TI_DbgPrint(MID_TRACE
,("Looking at adapter %d\n", IF
->Index
));
1567 if( IF
->Unicast
.Address
.IPv4Address
== IpAddrChange
->Address
) {
1568 Status
= STATUS_DUPLICATE_OBJECTID
;
1571 if( IF
->Index
== IpAddrChange
->NteIndex
) {
1572 IPRemoveInterfaceRoute( IF
);
1574 IF
->Unicast
.Type
= IP_ADDRESS_V4
;
1575 IF
->Unicast
.Address
.IPv4Address
= IpAddrChange
->Address
;
1576 IF
->Netmask
.Type
= IP_ADDRESS_V4
;
1577 IF
->Netmask
.Address
.IPv4Address
= IpAddrChange
->Netmask
;
1578 IF
->Broadcast
.Type
= IP_ADDRESS_V4
;
1579 IF
->Broadcast
.Address
.IPv4Address
=
1580 IF
->Unicast
.Address
.IPv4Address
|
1581 ~IF
->Netmask
.Address
.IPv4Address
;
1583 TI_DbgPrint(MID_TRACE
,("New Unicast Address: %x\n",
1584 IF
->Unicast
.Address
.IPv4Address
));
1585 TI_DbgPrint(MID_TRACE
,("New Netmask : %x\n",
1586 IF
->Netmask
.Address
.IPv4Address
));
1588 IPAddInterfaceRoute( IF
);
1590 IpAddrChange
->Address
= IF
->Index
;
1591 Status
= STATUS_SUCCESS
;
1592 Irp
->IoStatus
.Information
= IF
->Index
;
1597 Irp
->IoStatus
.Status
= Status
;
1601 NTSTATUS
DispTdiDeleteIPAddress( PIRP Irp
, PIO_STACK_LOCATION IrpSp
) {
1602 NTSTATUS Status
= STATUS_UNSUCCESSFUL
;
1603 PUSHORT NteIndex
= Irp
->AssociatedIrp
.SystemBuffer
;
1606 ForEachInterface(IF
) {
1607 if( IF
->Index
== *NteIndex
) {
1608 IPRemoveInterfaceRoute( IF
);
1609 IF
->Unicast
.Type
= IP_ADDRESS_V4
;
1610 IF
->Unicast
.Address
.IPv4Address
= 0;
1611 IF
->Netmask
.Type
= IP_ADDRESS_V4
;
1612 IF
->Netmask
.Address
.IPv4Address
= 0;
1613 IF
->Broadcast
.Type
= IP_ADDRESS_V4
;
1614 IF
->Broadcast
.Address
.IPv4Address
= 0;
1615 Status
= STATUS_SUCCESS
;
1619 Irp
->IoStatus
.Status
= Status
;