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

📄 xunicdevice.cpp

📁 WDM驱动程序实例,用DriverStudio加vc
💻 CPP
📖 第 1 页 / 共 2 页
字号:
}

///////////////////////////////////////////////////////////////////////////////////////////////////
//  XunicDevice::OnDeviceSleep
//		Handler for IRP_MJ_POWER subfcn IRP_MN_SET_POWER 
//		for a request to go to a low power state from a high power state
//		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.
//
//	Arguments:
//		IN	I
//			the power IRP
//
//	Return Value:
//		NTSTATUS
//
NTSTATUS XunicDevice::OnDeviceSleep(KIrp I)
{
	T.Trace(TraceInfo, __FUNCTION__"++.  IRP %p\n", I);

	NTSTATUS status = STATUS_SUCCESS;

	// TODO: Add device-specific code to:
	//		 Save any context to the hardware device that will be required 
	//		 during a power up request. See the OnDevicePowerUp function.
	//		 Do NOT complete this IRP.  The base class handles forwarding
	//		 this IRP to the PDO.

	T.Trace(TraceInfo, __FUNCTION__"--.  IRP %p, STATUS %x\n", I, status);

	return status;
}


///////////////////////////////////////////////////////////////////////////////////////////////////
//  XunicDevice::Create
//		Dispatch routine for IRP_MJ_CREATE requests.  
//
//	Arguments:
//		IN I 
//			the create IRP
//
//	Return Value:
//		NTSTATUS
//
NTSTATUS XunicDevice::Create(KIrp I)
{
	T.Trace(TraceInfo, __FUNCTION__"++.  IRP %p\n", I);

	// TODO: For any IRP, to display the contents of the IRP
	//		 in a formatted way, use the KTrace << operator:
	//			 T << I;

	NTSTATUS status = STATUS_SUCCESS;

	// TODO: At this point, perform custom processing for IRP_MJ_CREATE
	// Generally a create IRP is targeted at our FDO, so its not needed
	// to pass it down to the PDO.  

	I.Information() = 0;
	I.PnpComplete(this, status);

	T.Trace(TraceInfo, __FUNCTION__"--.  IRP %p, STATUS %x\n", I, status);

	return status;
}

///////////////////////////////////////////////////////////////////////////////////////////////////
//  XunicDevice::Close
//		Dispatch routine for IRP_MJ_CLOSE requests.  
//
//	Arguments:
//		IN I 
//			the close IRP
//
//	Return Value:
//		NTSTATUS
//
NTSTATUS XunicDevice::Close(KIrp I)
{
	T.Trace(TraceInfo, __FUNCTION__"++.  IRP %p\n", I);

	NTSTATUS status = STATUS_SUCCESS;

	// TODO: At this point, perform custom processing for IRP_MJ_CLOSE
	// Generally a close IRP is targeted at our FDO, so we don't need
	// to pass it down to the PDO.  

	I.Information() = 0;
	I.PnpComplete(this, status);

	T.Trace(TraceInfo, __FUNCTION__"--.  IRP %p, STATUS %x\n", I, status);

	return status;
}

///////////////////////////////////////////////////////////////////////////////////////////////////
//  XunicDevice::Read
//		Dispatch routine for IRP_MJ_READ requests.  
//
//	Arguments:
//		IN I 
//			the read IRP
//
//	Return Value:
//		NTSTATUS
//
NTSTATUS XunicDevice::Read(KIrp I)
{
	T.Trace(TraceInfo, __FUNCTION__"++.  IRP %p\n", I);

	NTSTATUS status = STATUS_SUCCESS;

	// TODO: Validate the parameters of the IRP.  Replace "FALSE"
	//		 in the following line with error checking code that
	//		 evaulates to TRUE if the request is not valid.
	if (FALSE)
	{
		status = STATUS_INVALID_PARAMETER;
		I.Information() = 0;
		I.PnpComplete(status);

		T.Trace(TraceWarning, __FUNCTION__"--.  IRP %p, STATUS %x\n", I, status);

		return status;
	}

	// Always ok to read 0 elements
	if (I.ReadSize() == 0)
	{
		I.Information() = 0;
		I.PnpComplete(this, status);

		T.Trace(TraceInfo, __FUNCTION__"--.  IRP %p, STATUS %x\n", I, status);

		return status;
	}

	KMemory Mem(I.Mdl());	// Declare a memory object

	// Get a pointer to the caller's buffer.  Note that this
	// routine is safe on all platforms. 
	PUCHAR pBuffer = (PUCHAR) Mem.MapToSystemSpace();
	ULONG readSize = I.ReadSize();
	ULONG bytesRead = 0;

	// TODO: At this point, perform any processing for IRP_MJ_READ
	//		 To satisfy the read now, transfer data from the driver
	//		 to the caller's buffer at "pBuffer".  Then, indicate
	//		 how much data was transferred:

	I.Information() = bytesRead;


	I.PnpComplete(this, status);

	T.Trace(TraceInfo, __FUNCTION__"--.  IRP %p, STATUS %x\n", I, status);

	return status;
}

///////////////////////////////////////////////////////////////////////////////////////////////////
//  XunicDevice::Write
//		Dispatch routine for IRP_MJ_WRITE requests.  
//
//	Arguments:
//		IN I 
//			the write IRP
//
//	Return Value:
//		NTSTATUS
//
NTSTATUS XunicDevice::Write(KIrp I)
{
	T.Trace(TraceInfo, __FUNCTION__"++.  IRP %p\n", I);

	NTSTATUS status = STATUS_SUCCESS;

	// TODO: Validate the parameters of the IRP.  Replace "FALSE"
	//		 in the following line with error checking code that
	//		 evaulates to TRUE if the request is not valid.
	if (FALSE)
	{
		status = STATUS_INVALID_PARAMETER;
		I.Information() = 0;
		I.PnpComplete(status);

		T.Trace(TraceWarning, __FUNCTION__"--.  IRP %p, STATUS %x\n", I, status);

		return status;
	}

	// Always ok to write 0 elements
	if (I.WriteSize() == 0)
	{
		I.Information() = 0;
		I.PnpComplete(this, status);
        
		T.Trace(TraceInfo, __FUNCTION__"--.  IRP %p, STATUS %x\n", I, status);

		return status;
	}

	KMemory Mem(I.Mdl());	// Declare a memory object

	// Get a pointer to the caller's buffer.  Note that this
	// routine is safe on all platforms. 
	PUCHAR pBuffer = (PUCHAR) Mem.MapToSystemSpace();
	ULONG writeSize = I.WriteSize();
	ULONG bytesSent = 0;
	// TODO: At this point, perform any processing for IRP_MJ_WRITE
	//		 To satisfy the write now, transfer data to the driver
	//		 from the caller's buffer at "pBuffer".  Then, indicate
	//		 how much data was transferred:

	I.Information() = bytesSent;

	I.PnpComplete(this, status);

	T.Trace(TraceInfo, __FUNCTION__"--.  IRP %p, STATUS %x\n", I, status);

	return status;
}

///////////////////////////////////////////////////////////////////////////////////////////////////
//  XunicDevice::DeviceControl
//		Dispatch routine for IRP_MJ_DEVICE_CONTROL requests.  
//
//	Arguments:
//		IN I 
//			the ioctl IRP
//
//	Return Value:
//		NTSTATUS
//
NTSTATUS XunicDevice::DeviceControl(KIrp I)
{
	T.Trace(TraceInfo, __FUNCTION__"++.  IRP %p\n", I);

	NTSTATUS status = STATUS_SUCCESS;

	switch (I.IoctlCode())
	{
    case 0:

	default:
		status = STATUS_INVALID_DEVICE_REQUEST;
		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)
	{
		I.PnpComplete(this, status);
	}

	T.Trace(TraceInfo, __FUNCTION__"--.  IRP %p, STATUS %x\n", I, status);

	return status;
}

///////////////////////////////////////////////////////////////////////////////////////////////////
//  XunicDevice::CleanUp
//		Dispatch routine for IRP_MJ_CLEANUP requests.  
//
//	Arguments:
//		IN I 
//			the cleanup IRP
//
//	Return Value:
//		NTSTATUS
//
NTSTATUS XunicDevice::CleanUp(KIrp I)
{
	T.Trace(TraceInfo, __FUNCTION__"++.  IRP %p\n", I);

	NTSTATUS status = STATUS_SUCCESS;

	// TODO: At this point, perform custom processing for IRP_MJ_CLEANUP

	I.PnpComplete(this, status);

	T.Trace(TraceInfo, __FUNCTION__"--.  IRP %p, STATUS %x\n", I, status);

	return status;
}

///////////////////////////////////////////////////////////////////////////////////////////////////
//  XunicDevice::Invalidate
//		This method performs resource cleanup.
//		This function is called from OnStopDevice, OnRemoveDevice and
//		OnStartDevice (in error conditions).  It calls the Invalidate
//		member funcitons for each resource to free the underlying system
//		resource if allocated.  It is safe to call Invalidate more than
//		once for a resource, or for an uninitialized resource.
//
//	Arguments:
//		none
//
//	Return Value:
//		none
//
VOID XunicDevice::Invalidate()
{
	NTSTATUS status = STATUS_SUCCESS;
}

⌨️ 快捷键说明

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