⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tdittcp.c

📁 网络驱动开发
💻 C
📖 第 1 页 / 共 2 页
字号:
/////////////////////////////////////////////////////////////////////////////
//// INCLUDE FILES

#include "ndis.h"

#include "INetInc.h"
#include "TDITTCP.h"

// Copyright And Configuration Management ----------------------------------
//
//             DriverEntry For TDI Test TCP (TTCP) Driver - TDITTCP.c
//
//                  PCAUSA TDI Client Samples For Windows NT
//
//      Copyright (c) 1999-2000 Printing Communications Associates, Inc.
//                                - PCAUSA -
//
//                             Thomas F. Divine
//                           4201 Brunswick Court
//                        Smyrna, Georgia 30080 USA
//                              (770) 432-4580
//                            tdivine@pcausa.com
// 
// End ---------------------------------------------------------------------

/////////////////////////////////////////////////////////////////////////////
//// TDITTCP GLOBAL DATA
//
// Some developers have suggested that the gollowing g_ data should
// be placed in the DeviceExtension instead of simply being "ordinary"
// global data.
//
// DeviceExtension memory allocated from the non-paged pool. Device driver
// global memory is also allocated from the non-paged pool - UNLESS you
// use #pragma directives to cause it to be allocated from the paged pool.
//
// In this driver, use of global memory is safe enough...
//
PDRIVER_OBJECT g_pTheDriverObject = NULL;


/////////////////////////////////////////////////////////////////////////////
//// DriverEntry
//
// Purpose
// This routine initializes the TDITTCP driver.
//
// Parameters
//   pDriverObject - Pointer to driver object created by system.
//   RegistryPath - Pointer to the Unicode name of the registry path
//                  for this driver.
//
// Return Value
// The function return value is the final status from the initialization
// operation.
//
// Remarks
//

NTSTATUS
DriverEntry(
    IN PDRIVER_OBJECT pDriverObject,
    IN PUNICODE_STRING RegistryPath
    )
{
   PDEVICE_EXTENSION pDeviceExtension = NULL;
   NTSTATUS          LoadStatus, Status = STATUS_SUCCESS;
   ULONG             DevicesCreated = 0;

   //
   // Initialize Global Data
   //
   KdPrint(("TDITTCP: DriverEntry\n") );
   KdPrint(("  RegistryPath: %ws\n", RegistryPath->Buffer) );

   g_pTheDriverObject = pDriverObject;

   LoadStatus = TCPS_DeviceLoad(
                  pDriverObject,
                  RegistryPath
                  );

   if( NT_SUCCESS( LoadStatus ) )
   {
      ++DevicesCreated;
   }

   LoadStatus = TCPC_DeviceLoad(
                  pDriverObject,
                  RegistryPath
                  );

   if( NT_SUCCESS( LoadStatus ) )
   {
      ++DevicesCreated;
   }

   LoadStatus = UDPS_DeviceLoad(
                  pDriverObject,
                  RegistryPath
                  );

   if( NT_SUCCESS( LoadStatus ) )
   {
      ++DevicesCreated;
   }

   LoadStatus = UDPC_DeviceLoad(
                  pDriverObject,
                  RegistryPath
                  );

   if( NT_SUCCESS( LoadStatus ) )
   {
      ++DevicesCreated;
   }

   if( !DevicesCreated )
   {
      return STATUS_UNSUCCESSFUL;
   }

   return STATUS_SUCCESS;
}


/////////////////////////////////////////////////////////////////////////////
//// TDITTCPDeviceOpen (IRP_MJ_CREATE Dispatch Routine)
//
// Purpose
// This is the dispatch routine for TDITTCP device create/open requests.
//
// Parameters
//    pDeviceObject - Pointer to the device object.
//    pIrp - Pointer to the request packet.
//
// Return Value
// Status is returned.
//
// Remarks
//

NTSTATUS
TDITTCPDeviceOpen(
    IN PDEVICE_OBJECT pDeviceObject,
    IN PIRP pIrp
    )
{
   PDEVICE_EXTENSION    pDeviceExtension;

   pDeviceExtension = pDeviceObject->DeviceExtension;

   //
   // Possibly Dispatch To Secondary Function Handler
   // -----------------------------------------------
   // The TDITTCP driver creates four devices:
   //   TDI TTCP TCP Server
   //   TDI TTCP UDP Server
   //   TDI TTCP TCP Client
   //   TDI TTCP UDP Client
   //
   // A different DEVICE_EXTENSION structure is created for each device.
   //
   // The device extension includes a secondary MajorFunction table that
   // points to different functions for each device. This means that each
   // of the four types of devices listed above can have their own
   // DeviceOpen routine.
   //
   if( pDeviceExtension && pDeviceExtension->MajorFunction[ IRP_MJ_CREATE ] )
   {
      return( (*pDeviceExtension->MajorFunction[ IRP_MJ_CREATE ])
               ( pDeviceObject, pIrp )
            );
   }

   KdPrint(("TDITTCPDeviceOpen: Default Handling...\n") );

   //
   // No need to do anything.
   //

   //
   // Fill these in before calling IoCompleteRequest.
   //
   // DON'T get cute and try to use the status field of
   // the irp in the return status.  That IRP IS GONE as
   // soon as you call IoCompleteRequest.
   //

   pIrp->IoStatus.Information = 0;

   TdiCompleteRequest( pIrp, STATUS_SUCCESS );

   return STATUS_SUCCESS;
}


/////////////////////////////////////////////////////////////////////////////
//// TDITTCPDeviceClose (IRP_MJ_CLOSE Dispatch Routine)
//
// Purpose
// This is the dispatch routine for TDITTCP device close requests.
//
// Parameters
//    pDeviceObject - Pointer to the device object.
//    pIrp - Pointer to the request packet.
//
// Return Value
// Status is returned.
//
// Remarks
//

NTSTATUS
TDITTCPDeviceClose(
    IN PDEVICE_OBJECT pDeviceObject,
    IN PIRP pIrp
    )
{
   PDEVICE_EXTENSION    pDeviceExtension;

   pDeviceExtension = pDeviceObject->DeviceExtension;

   //
   // Possibly Dispatch To Secondary Function Handler
   // -----------------------------------------------
   // The TDITTCP driver creates four devices:
   //   TDI TTCP TCP Server
   //   TDI TTCP UDP Server
   //   TDI TTCP TCP Client
   //   TDI TTCP UDP Client
   //
   // A different DEVICE_EXTENSION structure is created for each device.
   //
   // The device extension includes a secondary MajorFunction table that
   // points to different functions for each device. This means that each
   // of the four types of devices listed above can have their own
   // DeviceOpen routine.
   //
   if( pDeviceExtension && pDeviceExtension->MajorFunction[ IRP_MJ_CLOSE ] )
   {
      return( (*pDeviceExtension->MajorFunction[ IRP_MJ_CLOSE ])
               ( pDeviceObject, pIrp )
            );
   }

   KdPrint(("TDITTCPDeviceClose: Default Handling...\n") );

   //
   // No need to do anything.
   //

   //
   // Fill these in before calling IoCompleteRequest.
   //
   // DON'T get cute and try to use the status field of
   // the irp in the return status.  That IRP IS GONE as
   // soon as you call IoCompleteRequest.
   //

   KdPrint( ("TDITTCPDeviceClose: Closed!!\n") );

   pIrp->IoStatus.Information = 0;

   TdiCompleteRequest( pIrp, STATUS_SUCCESS );

   return STATUS_SUCCESS;
}


/////////////////////////////////////////////////////////////////////////////
//// TDITTCPDeviceRead (IRP_MJ_READ Dispatch Routine)
//
// Purpose
// This is the dispatch routine for TDITTCP device read requests.
//
// Parameters
//    pDeviceObject - Pointer to the device object.
//    pIrp - Pointer to the request packet.
//
// Return Value
// Status is returned.
//
// Remarks
// The TDITTCP sample DOES NOT support device Read/Write requests on the
// device. The DeviceIoControl interface is used instead.
//

NTSTATUS
TDITTCPDeviceRead(
    IN PDEVICE_OBJECT pDeviceObject,
    IN PIRP pIrp
    )
{
   PDEVICE_EXTENSION    pDeviceExtension;

   pIrp->IoStatus.Information = 0;      // Nothing Returned Yet

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -