📄 tcpconn.c
字号:
UTIL_IsLargeIntegerZero(
CanDetachProceed,
pTDIH_DeviceExtension->OutstandingIoRequests,
&(pTDIH_DeviceExtension->IoRequestsSpinLock)
);
if (CanDetachProceed)
{
// signal the event object. Note that this is simply an
// advisory check we do here (to wake up a sleeping thread).
// It is the responsibility of the thread performing the detach to
// ensure that no operations are truly in progress.
KeSetEvent(&(pTDIH_DeviceExtension->IoInProgressEvent), IO_NO_INCREMENT, FALSE);
}
// Although the success return value is hard-coded here, you can
// return an appropriate value (either success or more-processing-reqd)
// based upon what it is that you wish to do in your completion routine.
return(STATUS_SUCCESS);
}
/////////////////////////////////////////////////////////////////////////////
//// TDIH_TdiCloseConnection
//
// Purpose
// This is the hook for TdiCloseConnection
//
// Parameters
//
// Return Value
//
// Remarks
//
NTSTATUS
TDIH_TdiCloseConnection(
PTDIH_DeviceExtension pTDIH_DeviceExtension,
PIRP Irp,
PIO_STACK_LOCATION IrpSp
)
{
NTSTATUS RC;
KdPrint(( "TDIH_TdiCloseConnection: Entry...\n" ));
try
{
PDEVICE_OBJECT pLowerDeviceObject = NULL;
pLowerDeviceObject = pTDIH_DeviceExtension->LowerDeviceObject;
// Be careful about not screwing up badly. This is actually not recommended by the I/O Manager.
if (Irp->CurrentLocation == 1)
{
ULONG ReturnedInformation = 0;
// Bad!! Fudge the error code. Break if we can ...
KdPrint(("TDIH_TdiCloseConnection encountered bogus current location\n"));
// UTIL_BreakPoint();
RC = STATUS_INVALID_DEVICE_REQUEST;
Irp->IoStatus.Status = RC;
Irp->IoStatus.Information = ReturnedInformation;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return( RC );
}
IoCopyCurrentIrpStackLocationToNext( Irp );
IoSetCompletionRoutine(
Irp,
TDIH_TdiCloseConnectionComplete,
pTDIH_DeviceExtension,
TRUE,
TRUE,
TRUE
);
UTIL_IncrementLargeInteger(
pTDIH_DeviceExtension->OutstandingIoRequests,
(unsigned long)1,
&(pTDIH_DeviceExtension->IoRequestsSpinLock)
);
// Clear the fast-IO notification event protected by the resource
// we have acquired.
KeClearEvent(&(pTDIH_DeviceExtension->IoInProgressEvent));
RC = IoCallDriver(pLowerDeviceObject, Irp);
try_return(RC);
try_exit: NOTHING;
}
finally
{
}
return(RC);
}
NTSTATUS
TDIH_TdiConnectEventHandler(
IN PVOID TdiEventContext, // Context From SetEventHandler
IN LONG RemoteAddressLength,
IN PVOID RemoteAddress,
IN LONG UserDataLength, // Unused for MSTCP
IN PVOID UserData, // Unused for MSTCP
IN LONG OptionsLength,
IN PVOID Options,
OUT CONNECTION_CONTEXT *ConnectionContext,
OUT PIRP *hAcceptIrp
)
{
NTSTATUS Status;
AddrObj *pAddrObj;
PTDIH_DeviceExtension pTDIH_DeviceExtension;
KdPrint(("TDIH_TdiConnectEventHandler: Entry...\n") );
//
// EventContext Points To Our Address Object Record
//
ASSERT( TdiEventContext );
pAddrObj = (AddrObj * )TdiEventContext;
if( !pAddrObj )
{
return( STATUS_DATA_NOT_ACCEPTED );
}
pTDIH_DeviceExtension = pAddrObj->ao_DeviceExtension;
//
// Pass To Connect Event Handler Set On The Address Object
//
ASSERT( pAddrObj->ao_connect );
Status = pAddrObj->ao_connect(
pAddrObj->ao_conncontext,
RemoteAddressLength,
RemoteAddress,
UserDataLength, // Unused for MSTCP
UserData, // Unused for MSTCP
OptionsLength,
Options,
ConnectionContext,
hAcceptIrp
);
KdPrint(( "TDIH_ConnectEventHandler: Status: 0x%8.8X\n", Status ));
return( Status );
}
/////////////////////////////////////////////////////////////////////////////
//// TDIH_TdiConnectComplete
//
// Purpose
//
// Parameters
//
// Return Value
//
// Remarks
//
NTSTATUS
TDIH_TdiConnectComplete(
PDEVICE_OBJECT pDeviceObject,
PIRP Irp,
void *Context
)
{
PTDIH_DeviceExtension pTDIH_DeviceExtension;
BOOLEAN CanDetachProceed = FALSE;
PDEVICE_OBJECT pAssociatedDeviceObject = NULL;
NTSTATUS Status = Irp->IoStatus.Status;
KdPrint(( "TDIH_TdiConnectComplete: Status: 0x%8.8X\n", Status ));
pTDIH_DeviceExtension = (PTDIH_DeviceExtension )(Context);
ASSERT( pTDIH_DeviceExtension );
//
// Propogate The IRP Pending Flag
//
if (Irp->PendingReturned)
{
IoMarkIrpPending(Irp);
}
// Ensure that this is a valid device object pointer, else return
// immediately.
pAssociatedDeviceObject = pTDIH_DeviceExtension->pFilterDeviceObject;
if (pAssociatedDeviceObject != pDeviceObject)
{
KdPrint(( "TDIH_ConnectComplete: Invalid Device Object Pointer\n" ));
return(STATUS_SUCCESS);
}
// Note that you could do all sorts of processing at this point
// depending upon the results of the operation. Be careful though
// about what you chose to do, about the fact that this completion
// routine is being invoked in an arbitrary thread context and probably
// at high IRQL.
UTIL_DecrementLargeInteger(
pTDIH_DeviceExtension->OutstandingIoRequests,
(unsigned long)1,
&(pTDIH_DeviceExtension->IoRequestsSpinLock)
);
// If the outstanding count is 0, signal the appropriate event which will
// allow any pending detach to proceed.
UTIL_IsLargeIntegerZero(
CanDetachProceed,
pTDIH_DeviceExtension->OutstandingIoRequests,
&(pTDIH_DeviceExtension->IoRequestsSpinLock)
);
if (CanDetachProceed)
{
// signal the event object. Note that this is simply an
// advisory check we do here (to wake up a sleeping thread).
// It is the responsibility of the thread performing the detach to
// ensure that no operations are truly in progress.
KeSetEvent(&(pTDIH_DeviceExtension->IoInProgressEvent), IO_NO_INCREMENT, FALSE);
}
// Although the success return value is hard-coded here, you can
// return an appropriate value (either success or more-processing-reqd)
// based upon what it is that you wish to do in your completion routine.
return(STATUS_SUCCESS);
}
/////////////////////////////////////////////////////////////////////////////
//// TDIH_TdiConnect
//
// Purpose
// This is the hook for TdiConnect
//
// Parameters
//
// Return Value
//
// Remarks
//
NTSTATUS
TDIH_TdiConnect(
PTDIH_DeviceExtension pTDIH_DeviceExtension,
PIRP Irp,
PIO_STACK_LOCATION IrpSp
)
{
NTSTATUS RC;
PTDI_REQUEST_KERNEL p;
KdPrint(( "TDIH_TdiConnect: Entry...\n" ));
p = (PTDI_REQUEST_KERNEL )&IrpSp->Parameters;
//
// Display The Remote Address
//
DEBUG_DumpTransportAddress(
(p->RequestConnectionInformation)->RemoteAddress
);
//
// Pass The Request To TCP Device
//
try
{
PDEVICE_OBJECT pLowerDeviceObject = NULL;
pLowerDeviceObject = pTDIH_DeviceExtension->LowerDeviceObject;
// Be careful about not screwing up badly. This is actually not recommended by the I/O Manager.
if (Irp->CurrentLocation == 1)
{
ULONG ReturnedInformation = 0;
// Bad!! Fudge the error code. Break if we can ...
KdPrint(("TDIH_TdiConnect encountered bogus current location\n"));
// UTIL_BreakPoint();
RC = STATUS_INVALID_DEVICE_REQUEST;
Irp->IoStatus.Status = RC;
Irp->IoStatus.Information = ReturnedInformation;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return( RC );
}
IoCopyCurrentIrpStackLocationToNext( Irp );
IoSetCompletionRoutine(
Irp,
TDIH_TdiConnectComplete,
pTDIH_DeviceExtension,
TRUE,
TRUE,
TRUE
);
UTIL_IncrementLargeInteger(
pTDIH_DeviceExtension->OutstandingIoRequests,
(unsigned long)1,
&(pTDIH_DeviceExtension->IoRequestsSpinLock)
);
// Clear the fast-IO notification event protected by the resource
// we have acquired.
KeClearEvent(&(pTDIH_DeviceExtension->IoInProgressEvent));
RC = IoCallDriver(pLowerDeviceObject, Irp);
try_return(RC);
try_exit: NOTHING;
}
finally
{
}
return(RC);
}
/////////////////////////////////////////////////////////////////////////////
//// TDIH_TdiDisconnectComplete
//
// Purpose
//
// Parameters
//
// Return Value
//
// Remarks
//
NTSTATUS
TDIH_TdiDisconnectComplete(
PDEVICE_OBJECT pDeviceObject,
PIRP Irp,
void *Context
)
{
PTDIH_DeviceExtension pTDIH_DeviceExtension;
BOOLEAN CanDetachProceed = FALSE;
PDEVICE_OBJECT pAssociatedDeviceObject = NULL;
NTSTATUS Status = Irp->IoStatus.Status;
KdPrint(( "TDIH_TdiDisconnectComplete: Status: 0x%8.8X\n", Status ));
pTDIH_DeviceExtension = (PTDIH_DeviceExtension )(Context);
ASSERT( pTDIH_DeviceExtension );
//
// Propogate The IRP Pending Flag
//
if (Irp->PendingReturned)
{
IoMarkIrpPending(Irp);
}
// Ensure that this is a valid device object pointer, else return
// immediately.
pAssociatedDeviceObject = pTDIH_DeviceExtension->pFilterDeviceObject;
if (pAssociatedDeviceObject != pDeviceObject)
{
KdPrint(( "TDIH_DisconnectComplete: Invalid Device Object Pointer\n" ));
return(STATUS_SUCCESS);
}
// Note that you could do all sorts of processing at this point
// depending upon the results of the operation. Be careful though
// about what you chose to do, about the fact that this completion
// routine is being invoked in an arbitrary thread context and probably
// at high IRQL.
UTIL_DecrementLargeInteger(
pTDIH_DeviceExtension->OutstandingIoRequests,
(unsigned long)1,
&(pTDIH_DeviceExtension->IoRequestsSpinLock)
);
// If the outstanding count is 0, signal the appropriate event which will
// allow any pending detach to proceed.
UTIL_IsLargeIntegerZero(
CanDetachProceed,
pTDIH_DeviceExtension->OutstandingIoRequests,
&(pTDIH_DeviceExtension->IoRequestsSpinLock)
);
if (CanDetachProceed)
{
// signal the event object. Note that this is simply an
// advisory check we do here (to wake up a sleeping thread).
// It is the responsibility of the thread performing the detach to
// ensure that no operations are truly in progress.
KeSetEvent(&(pTDIH_DeviceExtension->IoInProgressEvent), IO_NO_INCREMENT, FALSE);
}
// Although the success return value is hard-coded here, you can
// return an appropriate value (either success or more-processing-reqd)
// based upon what it is that you wish to do in your completion routine.
return(STATUS_SUCCESS);
}
/////////////////////////////////////////////////////////////////////////////
//// TDIH_TdiDisconnect
//
// Purpose
// This is the hook for TdiDisconnect
//
// Parameters
//
// Return Value
//
// Remarks
//
NTSTATUS
TDIH_TdiDisconnect(
PTDIH_DeviceExtension pTDIH_DeviceExtension,
PIRP Irp,
PIO_STACK_LOCATION IrpSp
)
{
NTSTATUS RC;
KdPrint(( "TDIH_TdiDisconnect: Entry...\n" ));
//
// Pass The Request To TCP Device
//
try
{
PDEVICE_OBJECT pLowerDeviceObject = NULL;
pLowerDeviceObject = pTDIH_DeviceExtension->LowerDeviceObject;
// Be careful about not screwing up badly. This is actually not recommended by the I/O Manager.
if (Irp->CurrentLocation == 1)
{
ULONG ReturnedInformation = 0;
// Bad!! Fudge the error code. Break if we can ...
KdPrint(("TDIH_TdiDisconnect encountered bogus current location\n"));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -