29 ASSERT(CommandBlockLength <= 16);
36 Control->DataTransferLength = DataTransferLength;
39 Control->CommandBlockLength = CommandBlockLength;
108 if (
Context->csw->Status != 0x00)
110 DPRINT1(
"[USBSTOR] Expected Status 0x00 but got %x\n",
Context->csw->Status);
132 if (!ErrorHandlerWorkItemData)
143 Context->FDODeviceExtension->SrbErrorHandlingActive =
TRUE;
148 Context->FDODeviceExtension->TimerWorkQueueEnabled =
FALSE;
155 ErrorHandlerWorkItemData);
157 ErrorHandlerWorkItemData->
DeviceObject =
Context->FDODeviceExtension->FunctionalDeviceObject;
159 ErrorHandlerWorkItemData->
Irp =
Irp;
160 ErrorHandlerWorkItemData->
DeviceObject =
Context->FDODeviceExtension->FunctionalDeviceObject;
162 DPRINT1(
"Queuing WorkItemROutine\n");
197 if (
Context->TransferBufferMDL)
224 DPRINT(
"USBSTOR_CSWCompletionRoutine Status %x\n",
Irp->IoStatus.Status);
344 Context->Irp->IoStatus.Status =
Irp->IoStatus.Status;
395 Context->FDODeviceExtension->InterfaceInformation->Pipes[
Context->FDODeviceExtension->BulkInPipeIndex].PipeHandle,
440 DPRINT(
"USBSTOR_DataCompletionRoutine Irp %p Ctx %p Status %x\n",
Irp, Ctx,
Irp->IoStatus.Status);
486 DPRINT(
"USBSTOR_CBWCompletionRoutine Irp %p Ctx %p Status %x\n",
Irp, Ctx,
Irp->IoStatus.Status);
501 if (
Context->TransferDataLength)
513 PipeHandle =
Context->FDODeviceExtension->InterfaceInformation->Pipes[
Context->FDODeviceExtension->BulkOutPipeIndex].PipeHandle;
520 PipeHandle =
Context->FDODeviceExtension->InterfaceInformation->Pipes[
Context->FDODeviceExtension->BulkInPipeIndex].PipeHandle;
548 Context->FDODeviceExtension->InterfaceInformation->Pipes[
Context->FDODeviceExtension->BulkInPipeIndex].PipeHandle,
582 DPRINT(
"%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
583 Block[0] & 0xFF, Block[1] & 0xFF, Block[2] & 0xFF, Block[3] & 0xFF, Block[4] & 0xFF, Block[5] & 0xFF, Block[6] & 0xFF, Block[7] & 0xFF, Block[8] & 0xFF, Block[9] & 0xFF,
584 Block[10] & 0xFF, Block[11] & 0xFF, Block[12] & 0xFF, Block[13] & 0xFF, Block[14] & 0xFF, Block[15] & 0xFF, Block[16] & 0xFF, Block[17] & 0xFF, Block[18] & 0xFF, Block[19] & 0xFF,
585 Block[20] & 0xFF, Block[21] & 0xFF, Block[22] & 0xFF, Block[23] & 0xFF, Block[24] & 0xFF, Block[25] & 0xFF, Block[26] & 0xFF, Block[27] & 0xFF, Block[28] & 0xFF, Block[29] & 0xFF,
665 PDODeviceExtension->LUN,
678 FDODeviceExtension->InterfaceInformation->Pipes[FDODeviceExtension->BulkOutPipeIndex].PipeHandle,
689 Context->TransferData = TransferData;
690 Context->TransferDataLength = TransferDataLength;
691 Context->FDODeviceExtension = FDODeviceExtension;
692 Context->PDODeviceExtension = PDODeviceExtension;
693 Context->RetryCount = RetryCount;
698 if (
Context->TransferDataLength)
718 if (MdlVirtualAddress !=
Context->TransferData)
724 if (!
Context->TransferBufferMDL)
741 if (!
Context->TransferBufferMDL)
755 if (!
Context->TransferBufferMDL)
777 if (!
Context->TransferBufferMDL)
855 Cmd.LUN = (PDODeviceExtension->LUN &
MAX_LUN);
856 Cmd.AllocationLengthMsb =
HTONS(
Request->DataTransferLength & 0xFFFF) >> 8;
857 Cmd.AllocationLengthLsb =
HTONS(
Request->DataTransferLength & 0xFFFF) & 0xFF;
896 Cmd.LUN = (PDODeviceExtension->LUN &
MAX_LUN);
942 Cmd.LUN = (PDODeviceExtension->LUN &
MAX_LUN);
990 Irp->IoStatus.Information =
Request->DataTransferLength;
1042 Cmd.LUN = (PDODeviceExtension->LUN &
MAX_LUN);
1059 DPRINT1(
"USBSTOR_SendCapacityCmd> USBSTOR_SendCBW failed with %x\n",
Status);
1074 DPRINT1(
"USBSTOR_SendCapacityCmd> USBSTOR_SendData failed with %x\n",
Status);
1099 DPRINT1(
"------------------------\n");
1148 ULONG BlockCount, Temp;
1175 DPRINT(
"USBSTOR_SendReadWrite DataTransferLength %lu, BlockLength %lu\n",
Request->DataTransferLength, PDODeviceExtension->BlockLength);
1180 ASSERT(PDODeviceExtension->BlockLength);
1185 BlockCount =
Request->DataTransferLength / PDODeviceExtension->BlockLength;
1192 Cmd.LUN = (PDODeviceExtension->LUN &
MAX_LUN);
1193 Cmd.ContiguousLogicBlocksByte0 = pCDB->
CDB10.TransferBlocksMsb;
1194 Cmd.ContiguousLogicBlocksByte1 = pCDB->
CDB10.TransferBlocksLsb;
1195 Cmd.LogicalBlockByte0 = pCDB->
CDB10.LogicalBlockByte0;
1196 Cmd.LogicalBlockByte1 = pCDB->
CDB10.LogicalBlockByte1;
1197 Cmd.LogicalBlockByte2 = pCDB->
CDB10.LogicalBlockByte2;
1198 Cmd.LogicalBlockByte3 = pCDB->
CDB10.LogicalBlockByte3;
1203 Temp = (
Cmd.ContiguousLogicBlocksByte0 << 8 |
Cmd.ContiguousLogicBlocksByte1);
1204 ASSERT(Temp == BlockCount);
1206 DPRINT(
"USBSTOR_SendReadWrite BlockAddress %x%x%x%x BlockCount %lu BlockLength %lu\n",
Cmd.LogicalBlockByte0,
Cmd.LogicalBlockByte1,
Cmd.LogicalBlockByte2,
Cmd.LogicalBlockByte3, BlockCount, PDODeviceExtension->BlockLength);
1250 Cmd.LUN = (PDODeviceExtension->LUN &
MAX_LUN);
1342 DPRINT(
"USBSTOR_HandleExecuteSCSI Operation Code %x\n", pCDB->
AsByte[0]);
1351 DPRINT(
"SCSIOP_READ_CAPACITY Length %lu\n",
Request->DataTransferLength);
1356 DPRINT(
"SCSIOP_MODE_SENSE DataTransferLength %lu\n",
Request->DataTransferLength);
1367 DPRINT(
"SCSIOP_READ_FORMATTED_CAPACITY DataTransferLength %lu\n",
Request->DataTransferLength);
1376 DPRINT(
"SCSIOP_INQUIRY DataTransferLength %lu\n",
Request->DataTransferLength);
1385 DPRINT(
"SCSIOP_READ / SCSIOP_WRITE DataTransferLength %lu\n",
Request->DataTransferLength);
1394 DPRINT(
"SCSIOP_MEDIUM_REMOVAL\n");
1401 Irp->IoStatus.Information =
Request->DataTransferLength;
1414 DPRINT(
"SCSIOP_TEST_UNIT_READY\n");
1424 DPRINT1(
"Forwarding unknown Operation Code %x\n", pCDB->
AsByte[0]);
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
_In_ PSCSI_REQUEST_BLOCK _In_opt_ PVOID _In_ ULONG _In_ BOOLEAN _In_opt_ WDFREQUEST OriginalRequest
struct _READ_CAPACITY_DATA * PREAD_CAPACITY_DATA
#define SCSIOP_TEST_UNIT_READY
#define SCSIOP_MEDIUM_REMOVAL
#define SCSIOP_READ_CAPACITY
#define SCSIOP_MODE_SENSE
IRP_CONTEXT * PIRP_CONTEXT
#define NT_SUCCESS(StatCode)
struct _PDO_DEVICE_EXTENSION * PPDO_DEVICE_EXTENSION
struct _SCSI_REQUEST_BLOCK * PSCSI_REQUEST_BLOCK
#define SRB_STATUS_SUCCESS
VOID USBSTOR_QueueTerminateRequest(IN PDEVICE_OBJECT FDODeviceObject, IN PIRP Irp)
VOID USBSTOR_QueueNextRequest(IN PDEVICE_OBJECT DeviceObject)
VOID NTAPI ErrorHandlerWorkItemRoutine(PVOID Context)
#define ExAllocatePoolWithTag(hernya, size, tag)
VOID NTAPI IoBuildPartialMdl(IN PMDL SourceMdl, IN PMDL TargetMdl, IN PVOID VirtualAddress, IN ULONG Length)
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
VOID FreeItem(IN PVOID Item)
VOID NTAPI MmBuildMdlForNonPagedPool(IN PMDL Mdl)
#define IoCompleteRequest
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
VOID NTAPI IoFreeIrp(IN PIRP Irp)
#define SCSIOP_READ_FORMATTED_CAPACITY
struct _READ_CAPACITY_DATA_EX * PREAD_CAPACITY_DATA_EX
#define STATUS_MORE_PROCESSING_REQUIRED
PDEVICE_OBJECT DeviceObject
WORK_QUEUE_ITEM WorkQueueItem
struct _IO_STACK_LOCATION::@1575::@1576 DeviceIoControl
union _IO_STACK_LOCATION::@1575 Parameters
struct _IO_STACK_LOCATION::@3974::@4013 Others
COMMON_DEVICE_EXTENSION Common
LARGE_INTEGER LogicalBlockAddress
ULONG LogicalBlockAddress
#define RtlCopyMemory(Destination, Source, Length)
#define RtlZeroMemory(Destination, Length)
#define STATUS_INSUFFICIENT_RESOURCES
struct _CDB::_CDB10 CDB10
struct _CDB::_MODE_SENSE MODE_SENSE
NTSTATUS USBSTOR_HandleExecuteSCSI(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
IO_COMPLETION_ROUTINE USBSTOR_CSWCompletionRoutine
VOID DumpCBW(PUCHAR Block)
IO_COMPLETION_ROUTINE USBSTOR_CBWCompletionRoutine
static BOOLEAN USBSTOR_IsCSWValid(PIRP_CONTEXT Context)
IO_COMPLETION_ROUTINE USBSTOR_DataCompletionRoutine
NTSTATUS USBSTOR_QueueWorkItem(PIRP_CONTEXT Context, PIRP Irp)
NTSTATUS USBSTOR_SendInquiry(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN ULONG RetryCount)
NTSTATUS USBSTOR_SendCBW(PIRP_CONTEXT Context, PIRP Irp)
NTSTATUS USBSTOR_SendReadWrite(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN ULONG RetryCount)
NTSTATUS USBSTOR_BuildCBW(IN ULONG Tag, IN ULONG DataTransferLength, IN UCHAR LUN, IN UCHAR CommandBlockLength, IN PUCHAR CommandBlock, IN OUT PCBW Control)
PIRP_CONTEXT USBSTOR_AllocateIrpContext()
NTSTATUS USBSTOR_SendModeSense(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN ULONG RetryCount)
NTSTATUS USBSTOR_SendUnknownRequest(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp, IN ULONG RetryCount)
VOID USBSTOR_SendCSW(PIRP_CONTEXT Context, PIRP Irp)
NTSTATUS USBSTOR_SendCapacity(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN ULONG RetryCount)
NTSTATUS USBSTOR_SendRequest(IN PDEVICE_OBJECT DeviceObject, IN PIRP OriginalRequest, IN UCHAR CommandLength, IN PUCHAR Command, IN ULONG TransferDataLength, IN PUCHAR TransferData, IN ULONG RetryCount)
NTSTATUS USBSTOR_SendFormatCapacity(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN ULONG RetryCount)
NTSTATUS USBSTOR_SendTestUnit(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp, IN ULONG RetryCount)
#define USBD_TRANSFER_DIRECTION_IN
#define USBD_SHORT_TRANSFER_OK
#define USBD_TRANSFER_DIRECTION_OUT
#define UsbBuildInterruptOrBulkTransferRequest(urb, length, pipeHandle, transferBuffer, transferBufferMDL, transferBufferLength, transferFlags, link)
#define IOCTL_INTERNAL_USB_SUBMIT_URB
#define UFI_READ_FORMAT_CAPACITY_CMD_LEN
struct UFI_CAPACITY_RESPONSE * PUFI_CAPACITY_RESPONSE
#define UFI_TEST_UNIT_CMD_LEN
#define UFI_SENSE_CMD_LEN
struct UFI_MODE_PARAMETER_HEADER * PUFI_MODE_PARAMETER_HEADER
#define UFI_INQUIRY_CMD_LEN
#define UFI_READ_CAPACITY_CMD_LEN
#define UFI_READ_WRITE_CMD_LEN
_In_ PDEVICE_OBJECT DeviceObject
_Must_inspect_result_ _In_ WDFDEVICE _In_ BOOLEAN _In_opt_ PVOID Tag
_In_ UCHAR _In_ UCHAR _In_ ULONG Code
_In_ WDF_WMI_PROVIDER_CONTROL Control
VOID NTAPI ExQueueWorkItem(IN PWORK_QUEUE_ITEM WorkItem, IN WORK_QUEUE_TYPE QueueType)
#define ExInitializeWorkItem(Item, Routine, Context)
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
#define IRP_MJ_INTERNAL_DEVICE_CONTROL
#define MmGetMdlByteCount(_Mdl)
#define MmGetMdlVirtualAddress(_Mdl)