?? drvdevice.cpp
字號:
// DRVDevice.cpp
// Implementation of DRVDevice device class
//
// Generated by DriverWizard version DriverStudio 2.7.0 (Build 562)
// Requires Compuware's DriverWorks classes
//
#pragma warning(disable:4065) // Allow switch statement with no cases
#include <vdw.h>
#include <kusb.h>
#include "..\DRVDeviceinterface.h"
#include "DRV.h"
#include "DRVDevice.h"
#include "..\DRVioctl.h"
#pragma hdrstop("DRV.pch")
extern KTrace t; // Global driver trace object
GUID DRVDevice_Guid = DRVDevice_CLASS_GUID;
////////////////////////////////////////////////////////////////////////
// DRVDevice::DRVDevice
//
// Routine Description:
// This is the constructor for the Functional Device Object, or FDO.
// It is derived from KPnpDevice, which builds in automatic
// dispatching of subfunctions of IRP_MJ_POWER and IRP_MJ_PNP to
// virtual member functions.
//
// Parameters:
// Pdo - Physical Device Object - this is a pointer to a system
// device object that represents the physical device.
//
// Unit - Unit number. This is a number to append to the device's
// base device name to form the Logical Device Object's name
//
// Return Value:
// None
//
// Comments:
// The object being constructed contains a data member (m_Lower) of type
// KPnpLowerDevice. By initializing it, the driver binds the FDO to the
// PDO and creates an interface to the upper edge of the system class driver.
//
DRVDevice::DRVDevice(PDEVICE_OBJECT Pdo, ULONG Unit) :
KPnpDevice(Pdo, &DRVDevice_Guid)
{
t << "Entering DRVDevice::DRVDevice (constructor)\n";
// Check constructor status
if ( ! NT_SUCCESS(m_ConstructorStatus) )
{
return;
}
// Remember our unit number
m_Unit = Unit;
// Initialize the lower device
m_Lower.Initialize(this, Pdo);
// Initialize the interface object. The wizard generates code
// to support a single interface. You may create and add additional
// interfaces. By default, the wizard uses InterfaceNumber 0 (the
// first interface descriptor), ConfigurationValue 1 (the first
// configuration descriptor), and initial interface alternate
// setting of 0. If your device has multiple interfaces or alternate
// settings for an interface, you can add additional KUsbInterface
// objects or adjust the parameters passed to this function.
m_Interface.Initialize(
m_Lower, //KUsbLowerDevice
0, //InterfaceNumber
1, //ConfigurationValue
0 //Initial Interface Alternate Setting
);
// Initialize each Pipe object
m_Endpoint2IN.Initialize(m_Lower, 0x82, 64);
m_Endpoint2OUT.Initialize(m_Lower, 0x2, 64);
m_Endpoint1IN.Initialize(m_Lower, 0x81, 16);
m_Endpoint1OUT.Initialize(m_Lower, 0x1, 16);
// Inform the base class of the lower edge device object
SetLowerDevice(&m_Lower);
// Initialize the PnP Policy settings to the "standard" policy
SetPnpPolicy();
// TODO: Customize the PnP Policy for this device by setting
// flags in m_Policies.
// Initialize the Power Policy settings to the "standard" policy
SetPowerPolicy();
// TODO: Customize the Power Policy for this device by setting
// flags in m_PowerPolicies.
}
////////////////////////////////////////////////////////////////////////
// DRVDevice::~DRVDevice
//
// Routine Description:
// This is the destructor for the Functional Device Object, or FDO.
//
// Parameters:
// None
//
// Return Value:
// None
//
// Comments:
// None
//
DRVDevice::~DRVDevice()
{
t << "Entering DRVDevice::~DRVDevice() (destructor)\n";
}
////////////////////////////////////////////////////////////////////////
// PNPMinorFunctionName
//
// Routine Description:
// Return a string describing the Plug and Play minor function
//
// Parameters:
// mn - Minor function code
//
// Return Value:
// char * - Ascii name of minor function
//
// Comments:
// This function is used for tracing the IRPs. Remove the function,
// or conditionalize it for debug-only builds, if you want to save
// space in the driver image.
//
char *PNPMinorFunctionName(ULONG mn)
{
static char* minors[] = {
"IRP_MN_START_DEVICE",
"IRP_MN_QUERY_REMOVE_DEVICE",
"IRP_MN_REMOVE_DEVICE",
"IRP_MN_CANCEL_REMOVE_DEVICE",
"IRP_MN_STOP_DEVICE",
"IRP_MN_QUERY_STOP_DEVICE",
"IRP_MN_CANCEL_STOP_DEVICE",
"IRP_MN_QUERY_DEVICE_RELATIONS",
"IRP_MN_QUERY_INTERFACE",
"IRP_MN_QUERY_CAPABILITIES",
"IRP_MN_QUERY_RESOURCES",
"IRP_MN_QUERY_RESOURCE_REQUIREMENTS",
"IRP_MN_QUERY_DEVICE_TEXT",
"IRP_MN_FILTER_RESOURCE_REQUIREMENTS",
"<unknown minor function>",
"IRP_MN_READ_CONFIG",
"IRP_MN_WRITE_CONFIG",
"IRP_MN_EJECT",
"IRP_MN_SET_LOCK",
"IRP_MN_QUERY_ID",
"IRP_MN_QUERY_PNP_DEVICE_STATE",
"IRP_MN_QUERY_BUS_INFORMATION",
"IRP_MN_DEVICE_USAGE_NOTIFICATION",
"IRP_MN_SURPRISE_REMOVAL",
"IRP_MN_QUERY_LEGACY_BUS_INFORMATION"
};
if (mn > 0x18) // IRP_MN_QUERY_LEGACY_BUS_INFORMATION
return "<unknown minor function>";
else
return minors[mn];
}
////////////////////////////////////////////////////////////////////////
// DRVDevice::DefaultPnp
//
// Routine Description:
// Default handler for IRP_MJ_PNP
//
// Parameters:
// I - Current IRP
//
// Return Value:
// NTSTATUS - Result returned from lower device
//
// Comments:
// This routine just passes the IRP through to the lower device. It is
// the default handler for IRP_MJ_PNP. IRPs that correspond to
// any virtual members of KpnpDevice that handle minor functions of
// IRP_MJ_PNP and that are not overridden get passed to this routine.
//
NTSTATUS DRVDevice::DefaultPnp(KIrp I)
{
t << "Entering DRVDevice::DefaultPnp with IRP minor function="
<< PNPMinorFunctionName(I.MinorFunction()) << EOL;
I.ForceReuseOfCurrentStackLocationInCalldown();
return m_Lower.PnpCall(this, I);
}
////////////////////////////////////////////////////////////////////////
// DRVDevice::DefaultPower
//
// Routine Description:
// Default handler for IRP_MJ_POWER
//
// Parameters:
// I - Current IRP
//
// Return Value:
// NTSTATUS - Result returned from lower device
//
// Comments:
// This routine just passes the IRP through to the lower device. It is
// the default handler for IRP_MJ_POWER.
//
NTSTATUS DRVDevice::DefaultPower(KIrp I)
{
t << "Entering DRVDevice::DefaultPower\n";
I.IndicatePowerIrpProcessed();
I.CopyParametersDown();
return m_Lower.PnpPowerCall(this, I);
}
////////////////////////////////////////////////////////////////////////////////
// DRVDevice::SystemControl
//
// Routine Description:
// Default handler for IRP_MJ_SYSTEM_CONTROL
//
// Parameters:
// I - Current IRP
//
// Return Value:
// NTSTATUS - Result returned from lower device
//
// Comments:
// This routine just passes the IRP through to the next device since this driver
// is not a WMI provider.
//
NTSTATUS DRVDevice::SystemControl(KIrp I)
{
t << "Entering DRVDevice::SystemControl\n";
I.ForceReuseOfCurrentStackLocationInCalldown();
return m_Lower.PnpCall(this, I);
}
////////////////////////////////////////////////////////////////////////
// DRVDevice::OnStartDevice
//
// Routine Description:
// Handler for IRP_MJ_PNP subfcn IRP_MN_START_DEVICE
//
// Parameters:
// I - Current IRP
//
// Return Value:
// NTSTATUS - Result code
//
// Comments:
// Typically, the driver sends a SET CONFIGURATION request for the
// USB device by using KUsbLowerDevice::ActivateConfiguration with
// the ConfigurationValue to activate. The wizard generates code to
// support a single configuration. You may create and add additional
// configurations.
//
NTSTATUS DRVDevice::OnStartDevice(KIrp I)
{
t << "Entering DRVDevice::OnStartDevice\n";
NTSTATUS status = STATUS_UNSUCCESSFUL;
AC_STATUS acStatus = AC_SUCCESS;
I.Information() = 0;
// The default Pnp policy has already cleared the IRP with the lower device
//By default, the wizard passes a ConfigurationValue of 1 to
//ActivateConfiguration(). This corresponds to the first configuration
//that the device reports in its configuration descriptor. If the device
//supports multiple configurations, pass the appropriate
//ConfigurationValue of the configuration to activate here.
acStatus = m_Lower.ActivateConfiguration(
1 // ConfigurationValue 1 (the first configuration)
);
switch (acStatus)
{
case AC_SUCCESS:
t << "USB Configuration OK\n";
status = STATUS_SUCCESS;
break;
case AC_COULD_NOT_LOCATE_INTERFACE:
t << "Could not locate interface\n";
break;
case AC_COULD_NOT_PRECONFIGURE_INTERFACE:
t << "Could not get configuration descriptor\n";
break;
case AC_CONFIGURATION_REQUEST_FAILED:
t << "Board did not accept configuration URB\n";
break;
case AC_FAILED_TO_INITIALIZE_INTERFACE_OBJECT:
t << "Failed to initialize interface object\n";
break;
case AC_FAILED_TO_GET_DESCRIPTOR:
t << "Failed to get device descriptor\n";
break;
case AC_FAILED_TO_OPEN_PIPE_OBJECT:
//NOTE: this may not be an error. It could mean that
//the device has an endpoint for which a KUsbPipe object has
//not been instanced. If the intention is to not use this endpoint,
//then it's likely not a problem.
status = STATUS_SUCCESS;
t << "Failed to open pipe object\n";
break;
default:
t << "Unexpected error activating USB configuration\n";
break;
}
return status; // base class completes the IRP
}
////////////////////////////////////////////////////////////////////////
// DRVDevice::OnStopDevice
//
// Routine Description:
// Handler for IRP_MJ_PNP subfcn IRP_MN_STOP_DEVICE
//
// Parameters:
// I - Current IRP
//
// Return Value:
// NTSTATUS - Result code
//
// Comments:
// The system calls this when the device is stopped.
// The driver should release any hardware resources
// in this routine.
//
// The base class passes the irp to the lower device.
//
NTSTATUS DRVDevice::OnStopDevice(KIrp I)
{
NTSTATUS status = STATUS_SUCCESS;
t << "Entering DRVDevice::OnStopDevice\n";
m_Lower.DeActivateConfiguration();
// TODO: Add device-specific code to stop your device
return status;
// The following macro simply allows compilation at Warning Level 4
// If you reference this parameter in the function simply remove the macro.
UNREFERENCED_PARAMETER(I);
}
////////////////////////////////////////////////////////////////////////
// DRVDevice::OnRemoveDevice
//
// Routine Description:
// Handler for IRP_MJ_PNP subfcn IRP_MN_REMOVE_DEVICE
//
// Parameters:
// I - Current IRP
//
// Return Value:
// NTSTATUS - Result code
//
// Comments:
// The system calls this when the device is removed.
// Our PnP policy will take care of
// (1) giving the IRP to the lower device
// (2) detaching the PDO
// (3) deleting the device object
//
NTSTATUS DRVDevice::OnRemoveDevice(KIrp I)
{
t << "Entering DRVDevice::OnRemoveDevice\n";
// Device removed, release the system resources used by the USB lower device.
m_Lower.ReleaseResources();
// TODO: Add device-specific code to remove your device
return STATUS_SUCCESS;
// The following macro simply allows compilation at Warning Level 4
// If you reference this parameter in the function simply remove the macro.
UNREFERENCED_PARAMETER(I);
}
////////////////////////////////////////////////////////////////////////
// DRVDevice::OnDevicePowerUp
//
// Routine Description:
// Handler for IRP_MJ_POWER with minor function IRP_MN_SET_POWER
// for a request to go to power on state from low power state
//
// Parameters:
// I - IRP containing POWER request
//
// Return Value:
// NTSTATUS - Status code indicating success or failure
//
// Comments:
// This routine implements the OnDevicePowerUp function.
// This function was called by the framework from the completion
// routine of the IRP_MJ_POWER dispatch handler in KPnpDevice.
// The bus driver has completed the IRP and this driver can now
// access the hardware device.
// This routine runs at dispatch level.
//
NTSTATUS DRVDevice::OnDevicePowerUp(KIrp I)
{
NTSTATUS status = STATUS_SUCCESS;
t << "Entering DRVDevice::OnDevicePowerUp\n";
// TODO: Service the device.
// Restore any context to the hardware device that
// was saved during the handling of a power down request.
// See the OnDeviceSleep function.
// Do NOT complete this IRP.
//
return status;
// The following macro simply allows compilation at Warning Level 4
// If you reference this parameter in the function simply remove the macro.
UNREFERENCED_PARAMETER(I);
}
////////////////////////////////////////////////////////////////////////
// DRVDevice::OnDeviceSleep
//
// Routine Description:
// Handler for IRP_MJ_POWER with minor function IRP_MN_SET_POWER
// for a request to go to a low power state from a high power state
//
// Parameters:
// I - IRP containing POWER request
//
// Return Value:
// NTSTATUS - Status code indicating success or failure
//
// Comments:
// This routine implements the OnDeviceSleep function.
// This function was called by the framework from the IRP_MJ_POWER
// dispatch handler in KPnpDevice prior to forwarding to the PDO.
// The hardware has yet to be powered down and this driver can now
// access the hardware device.
// This routine runs at passive level.
//
NTSTATUS DRVDevice::OnDeviceSleep(KIrp I)
{
NTSTATUS status = STATUS_SUCCESS;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -