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

📄 pwmdrvdevice.cpp

📁 D12的USB驱动代码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
NTSTATUS PWMDrvDevice::InternalDeviceControl(KIrp I)
{
	NTSTATUS status;

	t << "Entering PWMDrvDevice::Internal Device Control, " << I << EOL;
	switch (I.IoctlCode())
	{
// TODO:	Insert case statements to handle requests specific to this device
//		case IOCTL_CODE:
// Call handler for this request code
//			status = This_Code_Handler(I);
//			break;

		default:
			// Unrecognized IOCTL request
			status = STATUS_INVALID_PARAMETER;
			break;
	}

	// If the IRP's IOCTL handler deferred processing using some driver
	// specific scheme, the status variable is set to STATUS_PENDING.
	// In this case we simply return that status, and the IRP will be
	// completed later.  Otherwise, complete the IRP using the status
	// returned by the IOCTL handler.
	if (status == STATUS_PENDING)
	{
		return status;
	}
	else
	{
		return I.PnpComplete(this, status);
	}
}

////////////////////////////////////////////////////////////////////////
//  PWMDrvDevice::DeviceControl
//
//	Routine Description:
//		Handler for IRP_MJ_DEVICE_CONTROL
//
//	Parameters:
//		I - Current IRP
// 
//	Return Value:
//		None
//
//	Comments:
//		This routine is the first handler for Device Control requests.
//		The KPnpDevice class handles restricting IRP flow
//		if the device is stopping or being removed.
//

NTSTATUS PWMDrvDevice::DeviceControl(KIrp I) 
{
	NTSTATUS status;

	t << "Entering PWMDrvDevice::Device Control, " << I << EOL;
	switch (I.IoctlCode())
	{
		case PWMDRV_IOCTL_DRV_VERSION:
			status = PWMDRV_IOCTL_DRV_VERSION_Handler(I);
			break;

		case PWMDRV_IOCTL_DEV_VERSION:
			status = PWMDRV_IOCTL_DEV_VERSION_Handler(I);
			break;

		case PWMDRV_IOCTL_SYS_INIT:
			status = PWMDRV_IOCTL_SYS_INIT_Handler(I);
			break;

		case PWMDRV_IOCTL_REG_READ:
			status = PWMDRV_IOCTL_REG_READ_Handler(I);
			break;

		case PWMDRV_IOCTL_REG_WRITE:
			status = PWMDRV_IOCTL_REG_WRITE_Handler(I);
			break;

		case PWMDRV_IOCTL_MASS_READ:
			status = PWMDRV_IOCTL_MASS_READ_Handler(I);
			break;

		case PWMDRV_IOCTL_MASS_WRITE:
			status = PWMDRV_IOCTL_MASS_WRITE_Handler(I);
			break;

		case PWMDRV_IOCTL_TEST:
			status = PWMDRV_IOCTL_TEST_Handler(I);
			break;

		default:
			// Unrecognized IOCTL request
			status = STATUS_INVALID_PARAMETER;
			break;
	}

	// If the IRP's IOCTL handler deferred processing using some driver
	// specific scheme, the status variable is set to STATUS_PENDING.
	// In this case we simply return that status, and the IRP will be
	// completed later.  Otherwise, complete the IRP using the status
	// returned by the IOCTL handler.
	if (status == STATUS_PENDING)
	{
		return status;
	}
	else
	{
		return I.PnpComplete(this, status);
	}
}

////////////////////////////////////////////////////////////////////////
//  PWMDrvDevice::PWMDRV_IOCTL_DRV_VERSION_Handler
//
//	Routine Description:
//		Handler for IO Control Code PWMDRV_IOCTL_DRV_VERSION
//
//	Parameters:
//		I - IRP containing IOCTL request
//
//	Return Value:
//		NTSTATUS - Status code indicating success or failure
//
//	Comments:
//		This routine implements the PWMDRV_IOCTL_DRV_VERSION function.
//		This routine runs at passive level.
//

NTSTATUS PWMDrvDevice::PWMDRV_IOCTL_DRV_VERSION_Handler(KIrp I)
{
	NTSTATUS status = STATUS_SUCCESS;

	t << "Entering PWMDrvDevice::PWMDRV_IOCTL_DRV_VERSION_Handler, " << I << EOL;
// TODO:	Verify that the input parameters are correct
//			If not, return STATUS_INVALID_PARAMETER

// TODO:	Handle the the PWMDRV_IOCTL_DRV_VERSION request, or 
//			defer the processing of the IRP (i.e. by queuing) and set
//			status to STATUS_PENDING.

// TODO:	Assuming that the request was handled here. Set I.Information
//			to indicate how much data to copy back to the user.
	I.Information() = 0;

	return status;
}

////////////////////////////////////////////////////////////////////////
//  PWMDrvDevice::PWMDRV_IOCTL_DEV_VERSION_Handler
//
//	Routine Description:
//		Handler for IO Control Code PWMDRV_IOCTL_DEV_VERSION
//
//	Parameters:
//		I - IRP containing IOCTL request
//
//	Return Value:
//		NTSTATUS - Status code indicating success or failure
//
//	Comments:
//		This routine implements the PWMDRV_IOCTL_DEV_VERSION function.
//		This routine runs at passive level.
//

NTSTATUS PWMDrvDevice::PWMDRV_IOCTL_DEV_VERSION_Handler(KIrp I)
{
	NTSTATUS status = STATUS_SUCCESS;

	t << "Entering PWMDrvDevice::PWMDRV_IOCTL_DEV_VERSION_Handler, " << I << EOL;
// TODO:	Verify that the input parameters are correct
//			If not, return STATUS_INVALID_PARAMETER

// TODO:	Handle the the PWMDRV_IOCTL_DEV_VERSION request, or 
//			defer the processing of the IRP (i.e. by queuing) and set
//			status to STATUS_PENDING.

// TODO:	Assuming that the request was handled here. Set I.Information
//			to indicate how much data to copy back to the user.
	I.Information() = 0;

	return status;
}

////////////////////////////////////////////////////////////////////////
//  PWMDrvDevice::PWMDRV_IOCTL_SYS_INIT_Handler
//
//	Routine Description:
//		Handler for IO Control Code PWMDRV_IOCTL_SYS_INIT
//
//	Parameters:
//		I - IRP containing IOCTL request
//
//	Return Value:
//		NTSTATUS - Status code indicating success or failure
//
//	Comments:
//		This routine implements the PWMDRV_IOCTL_SYS_INIT function.
//		This routine runs at passive level.
//

NTSTATUS PWMDrvDevice::PWMDRV_IOCTL_SYS_INIT_Handler(KIrp I)
{
	NTSTATUS status = STATUS_SUCCESS;

	t << "Entering PWMDrvDevice::PWMDRV_IOCTL_SYS_INIT_Handler, " << I << EOL;
// TODO:	Verify that the input parameters are correct
//			If not, return STATUS_INVALID_PARAMETER

// TODO:	Handle the the PWMDRV_IOCTL_SYS_INIT request, or 
//			defer the processing of the IRP (i.e. by queuing) and set
//			status to STATUS_PENDING.
	
	PURB pUrb = m_Lower.BuildClassRequest(
			NULL,							// transfer buffer
			0,								// transfer buffer size
			0,								// request reserved bits
			0x09,						// request
			0x01,								// Value
			FALSE,
			FALSE,
			NULL,
			0,
			URB_FUNCTION_CLASS_DEVICE,
			NULL
			);
	status = m_Lower.SubmitUrb(pUrb, NULL, NULL, 5000L);
// TODO:	Assuming that the request was handled here. Set I.Information
//			to indicate how much data to copy back to the user.
	I.Information() = 0;
	I.Status()=status;

	return status;
}

////////////////////////////////////////////////////////////////////////
//  PWMDrvDevice::PWMDRV_IOCTL_REG_READ_Handler
//
//	Routine Description:
//		Handler for IO Control Code PWMDRV_IOCTL_REG_READ
//
//	Parameters:
//		I - IRP containing IOCTL request
//
//	Return Value:
//		NTSTATUS - Status code indicating success or failure
//
//	Comments:
//		This routine implements the PWMDRV_IOCTL_REG_READ function.
//		This routine runs at passive level.
//

NTSTATUS PWMDrvDevice::PWMDRV_IOCTL_REG_READ_Handler(KIrp I)
{
	NTSTATUS status = STATUS_SUCCESS;

	t << "Entering PWMDrvDevice::PWMDRV_IOCTL_REG_READ_Handler, " << I << EOL;
// TODO:	Verify that the input parameters are correct
//			If not, return STATUS_INVALID_PARAMETER

// TODO:	Handle the the PWMDRV_IOCTL_REG_READ request, or 
//			defer the processing of the IRP (i.e. by queuing) and set
//			status to STATUS_PENDING.

// TODO:	Assuming that the request was handled here. Set I.Information
//			to indicate how much data to copy back to the user.
	I.Information() = 0;

	return status;
}

////////////////////////////////////////////////////////////////////////
//  PWMDrvDevice::PWMDRV_IOCTL_REG_WRITE_Handler
//
//	Routine Description:
//		Handler for IO Control Code PWMDRV_IOCTL_REG_WRITE
//
//	Parameters:
//		I - IRP containing IOCTL request
//
//	Return Value:
//		NTSTATUS - Status code indicating success or failure
//
//	Comments:
//		This routine implements the PWMDRV_IOCTL_REG_WRITE function.
//		This routine runs at passive level.
//

NTSTATUS PWMDrvDevice::PWMDRV_IOCTL_REG_WRITE_Handler(KIrp I)
{
	NTSTATUS status = STATUS_SUCCESS;

	t << "Entering PWMDrvDevice::PWMDRV_IOCTL_REG_WRITE_Handler, " << I << EOL;
// TODO:	Verify that the input parameters are correct
//			If not, return STATUS_INVALID_PARAMETER

// TODO:	Handle the the PWMDRV_IOCTL_REG_WRITE request, or 
//			defer the processing of the IRP (i.e. by queuing) and set
//			status to STATUS_PENDING.
	//KMemory Mem(I.Mdl());
	PULONG 	Mem	=(PULONG) I.IoctlBuffer();
	ULONG dwTotalSize = I.WriteSize(CURRENT);

	PURB pUrb = m_Endpoint2OUT.BuildBulkTransfer(
					Mem,          // Where is data coming from?
					dwTotalSize,  // How much data to read?
					FALSE,        // direction (FALSE = OUT)
					NULL		  // Link to next URB
					);	        
	//status = m_Lower.SubmitUrb(pUrb, NULL, NULL, 5000L);
	status = m_Endpoint2OUT.SubmitUrb(I, pUrb, NULL, NULL, 5000L);

// TODO:	Assuming that the request was handled here. Set I.Information
//			to indicate how much data to copy back to the user.
	I.Information() = 0;
	I.Status()=status;

	return status;
}

////////////////////////////////////////////////////////////////////////
//  PWMDrvDevice::PWMDRV_IOCTL_MASS_READ_Handler
//
//	Routine Description:
//		Handler for IO Control Code PWMDRV_IOCTL_MASS_READ
//
//	Parameters:
//		I - IRP containing IOCTL request
//
//	Return Value:
//		NTSTATUS - Status code indicating success or failure
//
//	Comments:
//		This routine implements the PWMDRV_IOCTL_MASS_READ function.
//		This routine runs at passive level.
//

NTSTATUS PWMDrvDevice::PWMDRV_IOCTL_MASS_READ_Handler(KIrp I)
{
	NTSTATUS status = STATUS_SUCCESS;

	t << "Entering PWMDrvDevice::PWMDRV_IOCTL_MASS_READ_Handler, " << I << EOL;
// TODO:	Verify that the input parameters are correct
//			If not, return STATUS_INVALID_PARAMETER

// TODO:	Handle the the PWMDRV_IOCTL_MASS_READ request, or 
//			defer the processing of the IRP (i.e. by queuing) and set
//			status to STATUS_PENDING.
	PURB pUrb = m_Lower.BuildVendorRequest(
			NULL,							// transfer buffer
			0,								// transfer buffer size
			0,								// request reserved bits
			CMD_MASS_READ,						// request
			0								// Value
			);

		// transmit
	status = m_Lower.SubmitUrb(pUrb, NULL, NULL, 5000L);
// TODO:	Assuming that the request was handled here. Set I.Information
//			to indicate how much data to copy back to the user.
	
	I.Information() = 0;
	I.Status() = status;

	return status;
}

////////////////////////////////////////////////////////////////////////
//  PWMDrvDevice::PWMDRV_IOCTL_MASS_WRITE_Handler
//
//	Routine Description:
//		Handler for IO Control Code PWMDRV_IOCTL_MASS_WRITE
//
//	Parameters:
//		I - IRP containing IOCTL request
//
//	Return Value:
//		NTSTATUS - Status code indicating success or failure
//
//	Comments:
//		This routine implements the PWMDRV_IOCTL_MASS_WRITE function.
//		This routine runs at passive level.
//

NTSTATUS PWMDrvDevice::PWMDRV_IOCTL_MASS_WRITE_Handler(KIrp I)
{
	NTSTATUS status = STATUS_SUCCESS;

	t << "Entering PWMDrvDevice::PWMDRV_IOCTL_MASS_WRITE_Handler, " << I << EOL;
// TODO:	Verify that the input parameters are correct
//			If not, return STATUS_INVALID_PARAMETER

// TODO:	Handle the the PWMDRV_IOCTL_MASS_WRITE request, or 
//			defer the processing of the IRP (i.e. by queuing) and set
//			status to STATUS_PENDING.

// TODO:	Assuming that the request was handled here. Set I.Information
//			to indicate how much data to copy back to the user.
	I.Information() = 0;

	return status;
}

////////////////////////////////////////////////////////////////////////
//  PWMDrvDevice::PWMDRV_IOCTL_TEST_Handler
//
//	Routine Description:
//		Handler for IO Control Code PWMDRV_IOCTL_TEST
//
//	Parameters:
//		I - IRP containing IOCTL request
//
//	Return Value:
//		NTSTATUS - Status code indicating success or failure
//
//	Comments:
//		This routine implements the PWMDRV_IOCTL_TEST function.
//		This routine runs at passive level.
//

NTSTATUS PWMDrvDevice::PWMDRV_IOCTL_TEST_Handler(KIrp I)
{
	NTSTATUS status = STATUS_SUCCESS;

	t << "Entering PWMDrvDevice::PWMDRV_IOCTL_TEST_Handler, " << I << EOL;
// TODO:	Verify that the input parameters are correct
//			If not, return STATUS_INVALID_PARAMETER

// TODO:	Handle the the PWMDRV_IOCTL_TEST request, or 
//			defer the processing of the IRP (i.e. by queuing) and set
//			status to STATUS_PENDING.

// TODO:	Assuming that the request was handled here. Set I.Information
//			to indicate how much data to copy back to the user.
	I.Information() = 0;

	return status;
}
/////////////////////////////////////////////////////////////
NTSTATUS PWMDrvDevice::OnQueryCapabilities(KIrp I)
{
	t << "Entering PWMDrvDevice::OnQueryCapabilities\n";

	I.CopyParametersDown();
	I.SetCompletionRoutine(LinkTo(OnQueryCapabilitiesComplete), this, TRUE, TRUE, TRUE);

	return m_Lower.PnpCall(this, I);
}

NTSTATUS PWMDrvDevice::OnQueryCapabilitiesComplete(KIrp I)
{
	if (I->PendingReturned)
		I.MarkPending();

	if(!m_bSurpriseRemove)
	{
		I.DeviceCapabilities()->SurpriseRemovalOK	= TRUE;
		I.DeviceCapabilities()->Removable			= TRUE;
		I.DeviceCapabilities()->EjectSupported		= TRUE;
		I.DeviceCapabilities()->WarmEjectSupported	= TRUE;
	}

	return STATUS_SUCCESS;
}





⌨️ 快捷键说明

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