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

📄 tdittcp.c

📁 网络驱动开发
💻 C
📖 第 1 页 / 共 2 页
字号:
   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_READ ] )
   {
      return( (*pDeviceExtension->MajorFunction[ IRP_MJ_READ ])
               ( pDeviceObject, pIrp )
            );
   }

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

   //
   // Return Failure
   //
   TdiCompleteRequest( pIrp, STATUS_NOT_IMPLEMENTED );

   return STATUS_NOT_IMPLEMENTED;
}


/////////////////////////////////////////////////////////////////////////////
//// TDITTCPDeviceWrite (IRP_MJ_WRITE Dispatch Routine)
//
// Purpose
// This is the dispatch routine for TDITTCP device write 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
// protocol device. The DeviceIoControl interface is used instead.
//

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

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

   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_WRITE ] )
   {
      return( (*pDeviceExtension->MajorFunction[ IRP_MJ_WRITE ])
               ( pDeviceObject, pIrp )
            );
   }

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

   //
   // Return Failure
   //
   TdiCompleteRequest( pIrp, STATUS_NOT_IMPLEMENTED );

   return STATUS_NOT_IMPLEMENTED;
}


/////////////////////////////////////////////////////////////////////////////
//// TDITTCPDeviceIoControl (IRP_MJ_DEVICE_CONTROL Dispatch Routine)
//
// Purpose
// This is the dispatch routine for PROTOCOL device IOCTL requests.
//
// Parameters
//    pDeviceObject - Pointer to the device object.
//    pIrp - Pointer to the request packet.
//
// Return Value
// Status is returned.
//
// Remarks
//

NTSTATUS
TDITTCPDeviceIoControl(
    IN PDEVICE_OBJECT pDeviceObject,
    IN PIRP pIrp
    )
{
   PDEVICE_EXTENSION    pDeviceExtension;
   NTSTATUS             Status;
   PIO_STACK_LOCATION   pIrpSp;
   ULONG                nFunctionCode;

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

   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_DEVICE_CONTROL ] )
   {
      return( (*pDeviceExtension->MajorFunction[ IRP_MJ_DEVICE_CONTROL ])
               ( pDeviceObject, pIrp )
            );
   }

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

   pIrpSp = IoGetCurrentIrpStackLocation(pIrp);

   nFunctionCode=pIrpSp->Parameters.DeviceIoControl.IoControlCode;

   switch( nFunctionCode )
   {
      default:
         KdPrint((  "FunctionCode: 0x%8.8X\n", nFunctionCode ));
         Status = STATUS_NOT_IMPLEMENTED;
         break;
   }

   TdiCompleteRequest( pIrp, Status );

   return( Status );
}


/////////////////////////////////////////////////////////////////////////////
//// TDITTCPDeviceCleanup (IRP_MJ_CLEANUP Dispatch Routine)
//
// Purpose
// This is the dispatch routine for TDITTCP device cleanup requests.
//
// Parameters
//    pDeviceObject - Pointer to the device object.
//    pFlushIrp - Pointer to the flush request packet.
//
// Return Value
// Status is returned.
//
// Remarks
//

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

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

   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_CLEANUP ] )
   {
      return( (*pDeviceExtension->MajorFunction[ IRP_MJ_CLEANUP ])
               ( pDeviceObject, pIrp )
            );
   }

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

   pIrp->IoStatus.Status = STATUS_SUCCESS;

   return( STATUS_SUCCESS );
}


/////////////////////////////////////////////////////////////////////////////
//// TDITTCPDriverUnload
//
// Purpose
//
// Parameters
//   pDriverObject - Pointer to driver object created by system.
//
// Return Value
//
// Remarks
//

VOID
TDITTCPDriverUnload(
    IN PDRIVER_OBJECT pDriverObject
    )
{
   PDEVICE_OBJECT     pDeviceObject;
   PDEVICE_OBJECT     pOldDeviceObject;
   PDEVICE_EXTENSION  pDeviceExtension;

   KdPrint(("TDITTCPDriverUnload: Entry...\n") );

   //
   // Delete The Driver's Devices
   //
   pDeviceObject = pDriverObject->DeviceObject;

   while( pDeviceObject != NULL )
   {
      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->DeviceUnload )
      {
         (*pDeviceExtension->DeviceUnload)( pDeviceObject );
      }

      //
      // Now Delete This Device Object
      //
      pOldDeviceObject = pDeviceObject;
      pDeviceObject = pDeviceObject->NextDevice;

      IoDeleteDevice( pOldDeviceObject );
   }
}

⌨️ 快捷键说明

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