📄 bulkusbdevice.cpp
字号:
T.Trace(TraceInfo, "HC Name: %s\n", HcName);
delete HcName;
}
ULONG CurrentFrame;
m_BusIntf.QueryBusTime(&CurrentFrame);
T.Trace(TraceInfo, "Current Frame: %u\n", CurrentFrame);
}
#endif
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// BulkUsbDevice::OnDevicePowerUp
// Handler for IRP_MJ_POWER subfcn IRP_MN_SET_POWER
// for a request to go to power on state from low power state
// 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.
//
// Arguments:
// IN I
// the power IRP
//
// Return Value:
// NTSTATUS
//
NTSTATUS BulkUsbDevice::OnDevicePowerUp(KIrp I)
{
T.Trace(TraceInfo, __FUNCTION__"++. IRP %p\n", I);
NTSTATUS status = STATUS_SUCCESS;
// TODO: Add device-specific code to:
// 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.
// The base class will handle completion of the IRP
T.Trace(TraceInfo, __FUNCTION__"--. IRP %p, STATUS %x\n", I, status);
return status;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// BulkUsbDevice::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 BulkUsbDevice::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;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// BulkUsbDevice::Create
// Dispatch routine for IRP_MJ_CREATE requests.
//
// Arguments:
// IN I
// the create IRP
//
// Return Value:
// NTSTATUS
//
NTSTATUS BulkUsbDevice::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;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// BulkUsbDevice::Close
// Dispatch routine for IRP_MJ_CLOSE requests.
//
// Arguments:
// IN I
// the close IRP
//
// Return Value:
// NTSTATUS
//
NTSTATUS BulkUsbDevice::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;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// BulkUsbDevice::Read
// Dispatch routine for IRP_MJ_READ requests.
//
// Arguments:
// IN I
// the read IRP
//
// Return Value:
// NTSTATUS
//
NTSTATUS BulkUsbDevice::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;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// BulkUsbDevice::Write
// Dispatch routine for IRP_MJ_WRITE requests.
//
// Arguments:
// IN I
// the write IRP
//
// Return Value:
// NTSTATUS
//
NTSTATUS BulkUsbDevice::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;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// BulkUsbDevice::DeviceControl
// Dispatch routine for IRP_MJ_DEVICE_CONTROL requests.
//
// Arguments:
// IN I
// the ioctl IRP
//
// Return Value:
// NTSTATUS
//
NTSTATUS BulkUsbDevice::DeviceControl(KIrp I)
{
T.Trace(TraceInfo, __FUNCTION__"++. IRP %p\n", I);
NTSTATUS status = STATUS_SUCCESS;
switch (I.IoctlCode())
{
case IOCTL_800:
status = IOCTL_800_Handler(I);
break;
case IOCTL_801:
status = IOCTL_801_Handler(I);
break;
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;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// BulkUsbDevice::IOCTL_800_Handler
// Handler for ioctl IOCTL_800. The DeviceControl
// method will complete the IRP.
//
// Arguments:
// IN I
// the ioctl IRP
//
// Return Value:
// NTSTATUS
//
NTSTATUS BulkUsbDevice::IOCTL_800_Handler(KIrp I)
{
T.Trace(TraceInfo, __FUNCTION__"++. IRP %p\n", I);
NTSTATUS status = STATUS_SUCCESS;
ULONG inputSize = I.IoctlInputBufferSize();
ULONG outputSize = I.IoctlOutputBufferSize();
// Buffered ioctl - using the same buffer so read the buffer before writing the buffer
PVOID inputBuffer = I.IoctlBuffer();
PVOID outputBuffer = I.IoctlBuffer();
// 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;
}
else
{
// TODO: copy data
// To satisfy the ioctl now, transfer data using the
// caller's buffers at "inputBuffer" and/or "outputBuffer".
// Then, indicate how much data was transferred:
I.Information() = 0;
}
T.Trace(NT_SUCCESS(status)?TraceInfo:TraceWarning, __FUNCTION__"--. IRP %p, STATUS %x\n", I, status);
return status;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// BulkUsbDevice::IOCTL_801_Handler
// Handler for ioctl IOCTL_801. The DeviceControl
// method will complete the IRP.
//
// Arguments:
// IN I
// the ioctl IRP
//
// Return Value:
// NTSTATUS
//
NTSTATUS BulkUsbDevice::IOCTL_801_Handler(KIrp I)
{
T.Trace(TraceInfo, __FUNCTION__"++. IRP %p\n", I);
NTSTATUS status = STATUS_SUCCESS;
ULONG inputSize = I.IoctlInputBufferSize();
ULONG outputSize = I.IoctlOutputBufferSize();
// Buffered ioctl - using the same buffer so read the buffer before writing the buffer
PVOID inputBuffer = I.IoctlBuffer();
PVOID outputBuffer = I.IoctlBuffer();
// 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;
}
else
{
// TODO: copy data
// To satisfy the ioctl now, transfer data using the
// caller's buffers at "inputBuffer" and/or "outputBuffer".
// Then, indicate how much data was transferred:
I.Information() = 0;
}
T.Trace(NT_SUCCESS(status)?TraceInfo:TraceWarning, __FUNCTION__"--. IRP %p, STATUS %x\n", I, status);
return status;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// BulkUsbDevice::CleanUp
// Dispatch routine for IRP_MJ_CLEANUP requests.
//
// Arguments:
// IN I
// the cleanup IRP
//
// Return Value:
// NTSTATUS
//
NTSTATUS BulkUsbDevice::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;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// BulkUsbDevice::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 BulkUsbDevice::Invalidate()
{
NTSTATUS status = STATUS_SUCCESS;
status = m_Lower.DeActivateConfiguration();
if (!NT_SUCCESS(status))
{
T.Trace(TraceWarning, __FUNCTION__" DeActivateConfiguration failed, STATUS %x\n", status);
}
m_Lower.ReleaseResources();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -