NTSTATUS BulkUsb_DispatchClose(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp) { NTSTATUS ntStatus; PFILE_OBJECT fileObject; PTDeviceExtension deviceExtension; PIO_STACK_LOCATION irpStack; PTPipeContext pipeContext; PUSBD_PIPE_INFORMATION pipeInformation; PAGED_CODE(); irpStack = IoGetCurrentIrpStackLocation(Irp); fileObject = irpStack->FileObject; pipeContext = NULL; pipeInformation = NULL; deviceExtension = (PTDeviceExtension) DeviceObject->DeviceExtension; BulkUsb_DbgPrint(3, ("file bulkdev: BulkUsb_DispatchClose - begins\n")); if(fileObject && fileObject->FsContext) { pipeInformation = fileObject->FsContext; if(0 != fileObject->FileName.Length) { pipeContext = BulkUsb_PipeWithName(DeviceObject, &fileObject->FileName); } if(pipeContext && pipeContext->PipeOpen) pipeContext->PipeOpen = FALSE; } ntStatus = STATUS_SUCCESS; Irp->IoStatus.Status = ntStatus; Irp->IoStatus.Information = 0; IoCompleteRequest(Irp, IO_NO_INCREMENT); InterlockedDecrement(&deviceExtension->OpenHandleCount); BulkUsb_DbgPrint(3, ("file bulkdev: BulkUsb_DispatchClose - ends\n")); return ntStatus; }
NTSTATUS BulkUsb_DispatchCreate( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp ) /*++ Routine Description: Dispatch routine for create. Arguments: DeviceObject - pointer to device object Irp - I/O request packet. Return Value: NT status value --*/ { ULONG i; NTSTATUS ntStatus; PFILE_OBJECT fileObject; PDEVICE_EXTENSION deviceExtension; PIO_STACK_LOCATION irpStack; PBULKUSB_PIPE_CONTEXT pipeContext; PUSBD_INTERFACE_INFORMATION interface; PAGED_CODE(); BulkUsb_DbgPrint(3, ("BulkUsb_DispatchCreate - begins\n")); // // initialize variables // irpStack = IoGetCurrentIrpStackLocation(Irp); fileObject = irpStack->FileObject; deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension; if(deviceExtension->DeviceState != Working) { ntStatus = STATUS_INVALID_DEVICE_STATE; goto BulkUsb_DispatchCreate_Exit; } if(deviceExtension->UsbInterface) { interface = deviceExtension->UsbInterface; } else { BulkUsb_DbgPrint(1, ("UsbInterface not found\n")); ntStatus = STATUS_INVALID_DEVICE_STATE; goto BulkUsb_DispatchCreate_Exit; } // // FsContext is Null for the device // if(fileObject) { fileObject->FsContext = NULL; } else { ntStatus = STATUS_INVALID_PARAMETER; goto BulkUsb_DispatchCreate_Exit; } if(0 == fileObject->FileName.Length) { // // opening a device as opposed to pipe. // ntStatus = STATUS_SUCCESS; InterlockedIncrement(&deviceExtension->OpenHandleCount); // // the device is idle if it has no open handles or pending PnP Irps // since we just received an open handle request, cancel idle req. // if(deviceExtension->SSEnable) { CancelSelectSuspend(deviceExtension); } goto BulkUsb_DispatchCreate_Exit; } pipeContext = BulkUsb_PipeWithName(DeviceObject, &fileObject->FileName); if(pipeContext == NULL) { ntStatus = STATUS_INVALID_PARAMETER; goto BulkUsb_DispatchCreate_Exit; } ntStatus = STATUS_INVALID_PARAMETER; for(i=0; i<interface->NumberOfPipes; i++) { if(pipeContext == &deviceExtension->PipeContext[i]) { // // found a match // BulkUsb_DbgPrint(3, ("open pipe %d\n", i)); fileObject->FsContext = &interface->Pipes[i]; ASSERT(fileObject->FsContext); pipeContext->PipeOpen = TRUE; ntStatus = STATUS_SUCCESS; // // increment OpenHandleCounts // InterlockedIncrement(&deviceExtension->OpenHandleCount); // // the device is idle if it has no open handles or pending PnP Irps // since we just received an open handle request, cancel idle req. // if(deviceExtension->SSEnable) { CancelSelectSuspend(deviceExtension); } } } BulkUsb_DispatchCreate_Exit: Irp->IoStatus.Status = ntStatus; Irp->IoStatus.Information = 0; IoCompleteRequest(Irp, IO_NO_INCREMENT); BulkUsb_DbgPrint(3, ("BulkUsb_DispatchCreate - ends\n")); return ntStatus; }
NTSTATUS BulkUsb_DispatchCreate(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp) { ULONG i; NTSTATUS ntStatus; PFILE_OBJECT fileObject; PTDeviceExtension deviceExtension; PIO_STACK_LOCATION irpStack; PTPipeContext pipeContext; PUSBD_INTERFACE_INFORMATION Interface; PAGED_CODE(); BulkUsb_DbgPrint(3, ("file bulkdev: BulkUsb_DispatchCreate - begins\n")); irpStack = IoGetCurrentIrpStackLocation(Irp); fileObject = irpStack->FileObject; deviceExtension = (PTDeviceExtension) DeviceObject->DeviceExtension; if(deviceExtension->DeviceState != WORKING) { ntStatus = STATUS_INVALID_DEVICE_STATE; goto BulkUsb_DispatchCreate_Exit; } if(deviceExtension->UsbInterface) Interface = deviceExtension->UsbInterface; else { BulkUsb_DbgPrint(1, ("file bulkdev: UsbInterface not found\n")); ntStatus = STATUS_INVALID_DEVICE_STATE; goto BulkUsb_DispatchCreate_Exit; } if(fileObject) fileObject->FsContext = NULL; else { ntStatus = STATUS_INVALID_PARAMETER; goto BulkUsb_DispatchCreate_Exit; } if(0 == fileObject->FileName.Length) { ntStatus = STATUS_SUCCESS; InterlockedIncrement(&deviceExtension->OpenHandleCount); if(deviceExtension->SSEnable) { CancelSelectSuspend(deviceExtension); } goto BulkUsb_DispatchCreate_Exit; } pipeContext = BulkUsb_PipeWithName(DeviceObject, &fileObject->FileName); if(pipeContext == NULL) { ntStatus = STATUS_INVALID_PARAMETER; goto BulkUsb_DispatchCreate_Exit; } ntStatus = STATUS_INVALID_PARAMETER; for(i = 0; i < Interface->NumberOfPipes; i++) { if(pipeContext == &deviceExtension->PipeContext[i]) { BulkUsb_DbgPrint(3, ("file bulkdev: open pipe %d\n", i)); fileObject->FsContext = &Interface->Pipes[i]; ASSERT(fileObject->FsContext); pipeContext->PipeOpen = TRUE; ntStatus = STATUS_SUCCESS; InterlockedIncrement(&deviceExtension->OpenHandleCount); if(deviceExtension->SSEnable) { CancelSelectSuspend(deviceExtension); } } } BulkUsb_DispatchCreate_Exit: Irp->IoStatus.Status = ntStatus; Irp->IoStatus.Information = 0; IoCompleteRequest(Irp, IO_NO_INCREMENT); BulkUsb_DbgPrint(3, ("file bulkdev: BulkUsb_DispatchCreate - ends\n")); return ntStatus; }
NTSTATUS BulkUsb_DispatchClose( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp ) /*++ Routine Description: Dispatch routine for close. Arguments: DeviceObject - pointer to device object Irp - I/O request packet Return Value: NT status value --*/ { NTSTATUS ntStatus; PFILE_OBJECT fileObject; PDEVICE_EXTENSION deviceExtension; PIO_STACK_LOCATION irpStack; PBULKUSB_PIPE_CONTEXT pipeContext; PUSBD_PIPE_INFORMATION pipeInformation; PAGED_CODE(); // // initialize variables // irpStack = IoGetCurrentIrpStackLocation(Irp); fileObject = irpStack->FileObject; pipeContext = NULL; pipeInformation = NULL; deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension; BulkUsb_DbgPrint(3, ("BulkUsb_DispatchClose - begins\n")); if(fileObject && fileObject->FsContext) { pipeInformation = fileObject->FsContext; if(0 != fileObject->FileName.Length) { pipeContext = BulkUsb_PipeWithName(DeviceObject, &fileObject->FileName); } if(pipeContext && pipeContext->PipeOpen) { pipeContext->PipeOpen = FALSE; } } // // set ntStatus to STATUS_SUCCESS // ntStatus = STATUS_SUCCESS; Irp->IoStatus.Status = ntStatus; Irp->IoStatus.Information = 0; IoCompleteRequest(Irp, IO_NO_INCREMENT); InterlockedDecrement(&deviceExtension->OpenHandleCount); BulkUsb_DbgPrint(3, ("BulkUsb_DispatchClose - ends\n")); return ntStatus; }