📄 ocrw.c
字号:
--*/
{
NTSTATUS ntStatus = STATUS_SUCCESS;
PD12_PIPE pipeHandle = NULL;
PFILE_OBJECT fileObject;
PIO_STACK_LOCATION irpStack, nextStack;
PDEVICE_EXTENSION deviceExtension;
PURB urb;
PD12_RW_CONTEXT context = NULL;
D12_KdPrint (("D12TEST.SYS: enter D12_Read\n"));
D12_IncrementIoCount(DeviceObject);
deviceExtension = DeviceObject->DeviceExtension;
if (deviceExtension->AcceptingRequests == FALSE) {
ntStatus = STATUS_DELETE_PENDING;
Irp->IoStatus.Status = ntStatus;
Irp->IoStatus.Information = 0;
IoCompleteRequest (Irp,
IO_NO_INCREMENT
);
D12_DecrementIoCount(DeviceObject);
return ntStatus;
}
irpStack = IoGetCurrentIrpStackLocation (Irp);
fileObject = irpStack->FileObject;
pipeHandle = fileObject->FsContext;
if (!pipeHandle) {
ntStatus = STATUS_INVALID_HANDLE;
goto D12_Read_Reject;
}
//
// submit the write request to USB
//
switch (pipeHandle->PipeInfo->PipeType) {
case UsbdPipeTypeIsochronous:
D12_ResetPipe(DeviceObject, pipeHandle, FALSE);
urb = D12_BuildIsoRequest(DeviceObject,
Irp,
pipeHandle,
TRUE);
if (urb) {
nextStack = IoGetNextIrpStackLocation(Irp);
ASSERT(nextStack != NULL);
ASSERT(DeviceObject->StackSize>1);
nextStack->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL;
nextStack->Parameters.Others.Argument1 = urb;
nextStack->Parameters.DeviceIoControl.IoControlCode =
IOCTL_INTERNAL_USB_SUBMIT_URB;
IoSetCompletionRoutine(Irp,
D12_IsoReadWrite_Complete,
urb,
TRUE,
TRUE,
TRUE);
D12_KdPrint (("D12TEST.SYS: IRP = 0x%x current = 0x%x next = 0x%x\n",
Irp, irpStack, nextStack));
ntStatus = IoCallDriver(deviceExtension->TopOfStackDeviceObject,
Irp);
goto D12_Read_Done;
} else {
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
}
break;
case UsbdPipeTypeInterrupt:
case UsbdPipeTypeBulk:
urb = D12_BuildAsyncRequest(DeviceObject,
Irp,
pipeHandle,
TRUE);
if (urb) {
context = ExAllocatePool(NonPagedPool, sizeof(D12_RW_CONTEXT));
}
if (urb && context) {
context->Urb = urb;
context->DeviceObject = DeviceObject;
nextStack = IoGetNextIrpStackLocation(Irp);
ASSERT(nextStack != NULL);
ASSERT(DeviceObject->StackSize>1);
nextStack->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL;
nextStack->Parameters.Others.Argument1 = urb;
nextStack->Parameters.DeviceIoControl.IoControlCode =
IOCTL_INTERNAL_USB_SUBMIT_URB;
IoSetCompletionRoutine(Irp,
D12_AsyncReadWrite_Complete,
context,
TRUE,
TRUE,
TRUE);
D12_KdPrint (("D12TEST.SYS: IRP = 0x%x current = 0x%x next = 0x%x\n",
Irp, irpStack, nextStack));
D12_AddPendingIrp(DeviceObject, Irp);
ntStatus = IoCallDriver(deviceExtension->TopOfStackDeviceObject,
Irp);
goto D12_Read_Done;
} else {
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
}
break;
default:
ntStatus = STATUS_INVALID_PARAMETER;
TRAP();
}
D12_Read_Reject:
Irp->IoStatus.Status = ntStatus;
Irp->IoStatus.Information = 0;
IoCompleteRequest (Irp,
IO_NO_INCREMENT
);
D12_Read_Done:
return ntStatus;
}
NTSTATUS
D12_Write(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp
)
/*++
Routine Description:
Arguments:
DeviceObject - pointer to the device object for this instance of the 82930
device.
Return Value:
NT status code
--*/
{
NTSTATUS ntStatus = STATUS_SUCCESS;
PD12_PIPE pipeHandle = NULL;
PFILE_OBJECT fileObject;
PIO_STACK_LOCATION irpStack, nextStack;
PDEVICE_EXTENSION deviceExtension;
PURB urb;
PD12_RW_CONTEXT context = NULL;
D12_KdPrint (("D12TEST.SYS: enter D12_Write\n"));
D12_IncrementIoCount(DeviceObject);
deviceExtension = DeviceObject->DeviceExtension;
if (deviceExtension->AcceptingRequests == FALSE) {
ntStatus = STATUS_DELETE_PENDING;
Irp->IoStatus.Status = ntStatus;
Irp->IoStatus.Information = 0;
D12_DecrementIoCount(DeviceObject);
IoCompleteRequest (Irp,
IO_NO_INCREMENT
);
return ntStatus;
}
irpStack = IoGetCurrentIrpStackLocation (Irp);
fileObject = irpStack->FileObject;
// MmProbeAndLockPages(Irp->MdlAddress,
// KernelMode,
// IoReadAccess);
pipeHandle = fileObject->FsContext;
if (!pipeHandle)
{
ntStatus = STATUS_INVALID_HANDLE;
goto D12_Write_Reject;
}
//
// submit the write request to USB
//
switch (pipeHandle->PipeInfo->PipeType) {
case UsbdPipeTypeIsochronous:
D12_ResetPipe(DeviceObject, pipeHandle, FALSE);
urb = D12_BuildIsoRequest(DeviceObject,
Irp,
pipeHandle,
FALSE);
if (urb) {
nextStack = IoGetNextIrpStackLocation(Irp);
ASSERT(nextStack != NULL);
ASSERT(DeviceObject->StackSize>1);
nextStack->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL;
nextStack->Parameters.Others.Argument1 = urb;
nextStack->Parameters.DeviceIoControl.IoControlCode =
IOCTL_INTERNAL_USB_SUBMIT_URB;
IoSetCompletionRoutine(Irp,
D12_IsoReadWrite_Complete,
urb,
TRUE,
TRUE,
TRUE);
D12_KdPrint (("D12TEST.SYS: IRP = 0x%x current = 0x%x next = 0x%x\n",
Irp, irpStack, nextStack));
ntStatus = IoCallDriver(deviceExtension->TopOfStackDeviceObject,
Irp);
goto D12_Write_Done;
} else {
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
}
break;
case UsbdPipeTypeInterrupt:
case UsbdPipeTypeBulk:
urb = D12_BuildAsyncRequest(DeviceObject,
Irp,
pipeHandle,
FALSE);
if (urb) {
context = ExAllocatePool(NonPagedPool, sizeof(D12_RW_CONTEXT));
}
if (urb && context) {
context->Urb = urb;
context->DeviceObject = DeviceObject;
nextStack = IoGetNextIrpStackLocation(Irp);
ASSERT(nextStack != NULL);
ASSERT(DeviceObject->StackSize>1);
nextStack->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL;
nextStack->Parameters.Others.Argument1 = urb;
nextStack->Parameters.DeviceIoControl.IoControlCode =
IOCTL_INTERNAL_USB_SUBMIT_URB;
IoSetCompletionRoutine(Irp,
D12_AsyncReadWrite_Complete,
context,
TRUE,
TRUE,
TRUE);
D12_KdPrint (("D12TEST.SYS: IRP = 0x%x current = 0x%x next = 0x%x\n",
Irp, irpStack, nextStack));
D12_AddPendingIrp(DeviceObject, Irp);
ntStatus = IoCallDriver(deviceExtension->TopOfStackDeviceObject,
Irp);
goto D12_Write_Done;
} else {
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
}
break;
default:
ntStatus = STATUS_INVALID_PARAMETER;
TRAP();
}
D12_Write_Reject:
Irp->IoStatus.Status = ntStatus;
Irp->IoStatus.Information = 0;
IoCompleteRequest (Irp,
IO_NO_INCREMENT
);
D12_Write_Done:
return ntStatus;
}
NTSTATUS
D12_Close(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp
)
/*++
Routine Description:
Arguments:
DeviceObject - pointer to the device object for this instance of the 82930
devcice.
Return Value:
NT status code
--*/
{
NTSTATUS ntStatus;
PFILE_OBJECT fileObject;
PIO_STACK_LOCATION irpStack;
PDEVICE_EXTENSION deviceExtension;
PD12_PIPE pipeHandle = NULL;
D12_KdPrint (("D12TEST.SYS: entering D12_Close\n"));
D12_IncrementIoCount(DeviceObject);
deviceExtension = DeviceObject->DeviceExtension;
irpStack = IoGetCurrentIrpStackLocation (Irp);
fileObject = irpStack->FileObject;
if (fileObject->FsContext) {
// closing pipe handle
pipeHandle = fileObject->FsContext;
D12_KdPrint (("D12TEST.SYS: closing pipe %x\n", pipeHandle));
pipeHandle->Opened = FALSE;
}
Irp->IoStatus.Status = STATUS_SUCCESS;
Irp->IoStatus.Information = 0;
ntStatus = Irp->IoStatus.Status;
IoCompleteRequest (Irp,
IO_NO_INCREMENT
);
D12_DecrementIoCount(DeviceObject);
D12_KdPrint (("D12TEST.SYS: exit D12_Close\n"));
return ntStatus;
}
NTSTATUS
D12_Create(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp
)
/*++
Routine Description:
//
// Entry point for CreateFile calls
// user mode apps may open "\\.\D12-x\yy"
// where yy is the internal pipe id
//
Arguments:
DeviceObject - pointer to the device object for this instance of the 82930
devcice.
Return Value:
NT status code
--*/
{
NTSTATUS ntStatus = STATUS_SUCCESS;
PD12_PIPE pipeHandle = NULL;
PFILE_OBJECT fileObject;
PIO_STACK_LOCATION irpStack;
PDEVICE_EXTENSION deviceExtension;
ULONG i;
D12_KdPrint (("D12TEST.SYS: entering D12_Create\n"));
D12_IncrementIoCount(DeviceObject);
deviceExtension = DeviceObject->DeviceExtension;
if (deviceExtension->AcceptingRequests == FALSE) {
ntStatus = STATUS_DELETE_PENDING;
Irp->IoStatus.Status = ntStatus;
Irp->IoStatus.Information = 0;
IoCompleteRequest (Irp,
IO_NO_INCREMENT
);
D12_DecrementIoCount(DeviceObject);
return ntStatus;
}
irpStack = IoGetCurrentIrpStackLocation (Irp);
fileObject = irpStack->FileObject;
// fscontext is null for device
fileObject->FsContext = NULL;
if (fileObject->FileName.Length != 0) {
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
//
// a name was specified, convert it to a pipe id
//
for (i=0; i<D12_MAX_PIPES; i++) {
if (RtlCompareMemory (fileObject->FileName.Buffer,
deviceExtension->PipeList[i].Name,
fileObject->FileName.Length)
== fileObject->FileName.Length &&
!deviceExtension->PipeList[i].Opened) {
//
// found a match
//
pipeHandle = &deviceExtension->PipeList[i];
//D12_ResetPipe(DeviceObject, pipeHandle);
break;
}
}
}
// if we are opening a pipe set stuff up and set FsContext
if (pipeHandle) {
D12_KdPrint (("D12TEST.SYS: open pipe %x\n", pipeHandle));
fileObject->FsContext = pipeHandle;
pipeHandle->Opened = TRUE;
pipeHandle->bPerfTimerEnabled = FALSE;
ntStatus = STATUS_SUCCESS;
}
Irp->IoStatus.Status = ntStatus;
Irp->IoStatus.Information = 0;
IoCompleteRequest (Irp,
IO_NO_INCREMENT
);
D12_DecrementIoCount(DeviceObject);
D12_KdPrint (("D12TEST.SYS: exit D12_Create %x\n", ntStatus));
return ntStatus;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -