ReactOS  0.4.15-dev-1049-g1062a29
scsi.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Universal Serial Bus Bulk Storage Driver
3  * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4  * PURPOSE: USB block storage device driver.
5  * COPYRIGHT: 2005-2006 James Tabor
6  * 2011-2012 Michael Martin (michael.martin@reactos.org)
7  * 2011-2013 Johannes Anderwald (johannes.anderwald@reactos.org)
8  * 2017 Vadim Galyant
9  * 2019 Victor Perevertkin (victor.perevertkin@reactos.org)
10  */
11 
12 #include "usbstor.h"
13 
14 #define NDEBUG
15 #include <debug.h>
16 
17 
18 static
22 {
23  UCHAR SrbStatus;
24 
25  SrbStatus = SRB_STATUS(Srb->SrbStatus);
26 
27  switch (SrbStatus)
28  {
29  case SRB_STATUS_SUCCESS:
30  return STATUS_SUCCESS;
31 
34 
38 
41  case SRB_STATUS_NO_HBA:
44 
45  case SRB_STATUS_TIMEOUT:
46  return STATUS_IO_TIMEOUT;
47 
52 
53  default:
55  }
56 }
57 
58 static
61  IN PFDO_DEVICE_EXTENSION FDODeviceExtension,
62  IN PIRP Irp,
64  IN ULONG TransferFlags,
65  IN ULONG TransferBufferLength,
66  IN PVOID TransferBuffer,
67  IN PMDL TransferBufferMDL,
69 {
70  PIO_STACK_LOCATION NextStack;
71  PIRP_CONTEXT Context = &FDODeviceExtension->CurrentIrpContext;
72 
74 
75  Context->Urb.UrbHeader.Length = sizeof(struct _URB_BULK_OR_INTERRUPT_TRANSFER);
76  Context->Urb.UrbHeader.Function = URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER;
77 
78  Context->Urb.UrbBulkOrInterruptTransfer.PipeHandle = PipeHandle;
79  Context->Urb.UrbBulkOrInterruptTransfer.TransferFlags = TransferFlags;
80  Context->Urb.UrbBulkOrInterruptTransfer.TransferBufferLength = TransferBufferLength;
81  Context->Urb.UrbBulkOrInterruptTransfer.TransferBuffer = TransferBuffer;
82  Context->Urb.UrbBulkOrInterruptTransfer.TransferBufferMDL = TransferBufferMDL;
83 
84  NextStack = IoGetNextIrpStackLocation(Irp);
86  NextStack->Parameters.DeviceIoControl.IoControlCode = IOCTL_INTERNAL_USB_SUBMIT_URB;
87  NextStack->Parameters.Others.Argument1 = &Context->Urb;
88 
91  FDODeviceExtension,
92  TRUE,
93  TRUE,
94  TRUE);
95 
96  return IoCallDriver(FDODeviceExtension->LowerDeviceObject, Irp);
97 }
98 
99 static
100 BOOLEAN
103 {
104  if (Context->csw.Signature != CSW_SIGNATURE)
105  {
106  DPRINT1("[USBSTOR] Expected Signature %x but got %x\n", CSW_SIGNATURE, Context->csw.Signature);
107  return FALSE;
108  }
109 
110  if (Context->csw.Tag != PtrToUlong(Context->Irp))
111  {
112  DPRINT1("[USBSTOR] Expected Tag %Ix but got %x\n", PtrToUlong(Context->Irp), Context->csw.Tag);
113  return FALSE;
114  }
115 
116  return TRUE;
117 }
118 
119 static
120 NTSTATUS
122  IN PFDO_DEVICE_EXTENSION FDODeviceExtension,
123  IN PIRP Irp);
124 
125 IO_COMPLETION_ROUTINE USBSTOR_CSWCompletionRoutine;
126 
127 NTSTATUS
128 NTAPI
131  PIRP Irp,
132  PVOID Ctx)
133 {
135  PIO_STACK_LOCATION IoStack;
136  PPDO_DEVICE_EXTENSION PDODeviceExtension;
137  PFDO_DEVICE_EXTENSION FDODeviceExtension;
139 
140  DPRINT("USBSTOR_CSWCompletionRoutine Irp %p Ctx %p Status %x\n", Irp, Ctx, Irp->IoStatus.Status);
141 
143  PDODeviceExtension = (PPDO_DEVICE_EXTENSION)IoStack->DeviceObject->DeviceExtension;
144  FDODeviceExtension = (PFDO_DEVICE_EXTENSION)Ctx;
145  Context = &FDODeviceExtension->CurrentIrpContext;
146  Request = IoStack->Parameters.Scsi.Srb;
147  ASSERT(Request);
148 
149  // first check for Irp errors
150  if (!NT_SUCCESS(Irp->IoStatus.Status))
151  {
152  if (USBD_STATUS(Context->Urb.UrbHeader.Status) == USBD_STATUS(USBD_STATUS_STALL_PID))
153  {
154  if (Context->StallRetryCount < 2)
155  {
156  ++Context->StallRetryCount;
157 
158  // clear stall and resend cbw
159  USBSTOR_QueueResetPipe(FDODeviceExtension);
160 
162  }
163  }
164  else
165  {
166  DPRINT1("USBSTOR_CSWCompletionRoutine: Urb.Hdr.Status - %x\n", Context->Urb.UrbHeader.Status);
167  }
168 
169  goto ResetRecovery;
170  }
171 
172  // now check the CSW packet validity
174  {
175  goto ResetRecovery;
176  }
177 
178  // finally check for CSW errors
179  if (Context->csw.Status == CSW_STATUS_COMMAND_PASSED)
180  {
181  // should happen only when a sense request was sent
182  if (Request != FDODeviceExtension->ActiveSrb)
183  {
184  ASSERT(IoStack->Parameters.Scsi.Srb == &Context->SenseSrb);
185  FDODeviceExtension->ActiveSrb->SenseInfoBufferLength = Request->DataTransferLength;
186  Request = FDODeviceExtension->ActiveSrb;
187  IoStack->Parameters.Scsi.Srb = Request;
188  Request->SrbStatus |= SRB_STATUS_AUTOSENSE_VALID;
189  }
190 
191  Irp->IoStatus.Status = USBSTOR_SrbStatusToNtStatus(Request);
192  }
193  else if (Context->csw.Status == CSW_STATUS_COMMAND_FAILED)
194  {
195  // the command is correct but with failed status - issue request sense
196  DPRINT("USBSTOR_CSWCompletionRoutine: CSW_STATUS_COMMAND_FAILED\n");
197 
198  ASSERT(FDODeviceExtension->ActiveSrb == Request);
199 
200  // setting a generic error status, additional information
201  // should be read by higher-level driver from SenseInfoBuffer
202  Request->SrbStatus = SRB_STATUS_ERROR;
203  Request->ScsiStatus = 2;
204  Request->DataTransferLength = 0;
205 
206  DPRINT("Flags: %x SBL: %x, buf: %p\n", Request->SrbFlags, Request->SenseInfoBufferLength, Request->SenseInfoBuffer);
207 
208  if (!(Request->SrbFlags & SRB_FLAGS_DISABLE_AUTOSENSE) &&
209  Request->SenseInfoBufferLength &&
210  Request->SenseInfoBuffer)
211  {
212  USBSTOR_IssueRequestSense(FDODeviceExtension, Irp);
214  }
215 
216  Irp->IoStatus.Status = STATUS_IO_DEVICE_ERROR;
217  }
218 
219  Irp->IoStatus.Information = Request->DataTransferLength;
220 
221  // terminate current request
222  USBSTOR_QueueTerminateRequest(PDODeviceExtension->LowerDeviceObject, Irp);
223  USBSTOR_QueueNextRequest(PDODeviceExtension->LowerDeviceObject);
224 
226 
227 ResetRecovery:
228 
229  Request = FDODeviceExtension->ActiveSrb;
230  IoStack->Parameters.Scsi.Srb = Request;
231  Irp->IoStatus.Information = 0;
232  Irp->IoStatus.Status = STATUS_IO_DEVICE_ERROR;
233  Request->SrbStatus = SRB_STATUS_BUS_RESET;
234 
235  USBSTOR_QueueTerminateRequest(PDODeviceExtension->LowerDeviceObject, Irp);
236  USBSTOR_QueueResetDevice(FDODeviceExtension);
237 
239 }
240 
241 NTSTATUS
243  PFDO_DEVICE_EXTENSION FDODeviceExtension,
244  PIRP Irp)
245 {
246  return USBSTOR_IssueBulkOrInterruptRequest(FDODeviceExtension,
247  Irp,
248  FDODeviceExtension->InterfaceInformation->Pipes[FDODeviceExtension->BulkInPipeIndex].PipeHandle,
250  sizeof(CSW),
251  &FDODeviceExtension->CurrentIrpContext.csw,
252  NULL,
254 }
255 
256 IO_COMPLETION_ROUTINE USBSTOR_DataCompletionRoutine;
257 
258 NTSTATUS
259 NTAPI
262  PIRP Irp,
263  PVOID Ctx)
264 {
266  PIO_STACK_LOCATION IoStack;
268  PFDO_DEVICE_EXTENSION FDODeviceExtension;
269  PPDO_DEVICE_EXTENSION PDODeviceExtension;
270 
271  DPRINT("USBSTOR_DataCompletionRoutine Irp %p Ctx %p Status %x\n", Irp, Ctx, Irp->IoStatus.Status);
272 
273  FDODeviceExtension = (PFDO_DEVICE_EXTENSION)Ctx;
274  Context = &FDODeviceExtension->CurrentIrpContext;
276  Request = IoStack->Parameters.Scsi.Srb;
277  PDODeviceExtension = (PPDO_DEVICE_EXTENSION)IoStack->DeviceObject->DeviceExtension;
278 
279  // for Sense Request a partial MDL was already freed (if existed)
280  if (Request == FDODeviceExtension->ActiveSrb &&
281  Context->Urb.UrbBulkOrInterruptTransfer.TransferBufferMDL != Irp->MdlAddress)
282  {
283  IoFreeMdl(Context->Urb.UrbBulkOrInterruptTransfer.TransferBufferMDL);
284  }
285 
286  if (NT_SUCCESS(Irp->IoStatus.Status))
287  {
288  if (Context->Urb.UrbBulkOrInterruptTransfer.TransferBufferLength < Request->DataTransferLength)
289  {
290  Request->SrbStatus = SRB_STATUS_DATA_OVERRUN;
291  }
292  else
293  {
294  Request->SrbStatus = SRB_STATUS_SUCCESS;
295  }
296 
297  Request->DataTransferLength = Context->Urb.UrbBulkOrInterruptTransfer.TransferBufferLength;
298  USBSTOR_SendCSWRequest(FDODeviceExtension, Irp);
299  }
300  else if (USBD_STATUS(Context->Urb.UrbHeader.Status) == USBD_STATUS(USBD_STATUS_STALL_PID))
301  {
302  ++Context->StallRetryCount;
303 
304  Request->SrbStatus = SRB_STATUS_DATA_OVERRUN;
305  Request->DataTransferLength = Context->Urb.UrbBulkOrInterruptTransfer.TransferBufferLength;
306 
307  // clear stall and resend cbw
308  USBSTOR_QueueResetPipe(FDODeviceExtension);
309  }
310  else
311  {
312  Irp->IoStatus.Information = 0;
313  Irp->IoStatus.Status = STATUS_IO_DEVICE_ERROR;
314  Request->SrbStatus = SRB_STATUS_BUS_RESET;
315 
316  USBSTOR_QueueTerminateRequest(PDODeviceExtension->LowerDeviceObject, Irp);
317  USBSTOR_QueueResetDevice(FDODeviceExtension);
318 
320  }
321 
323 }
324 
325 IO_COMPLETION_ROUTINE USBSTOR_CBWCompletionRoutine;
326 
327 NTSTATUS
328 NTAPI
331  PIRP Irp,
332  PVOID Ctx)
333 {
334  PIO_STACK_LOCATION IoStack;
336  PPDO_DEVICE_EXTENSION PDODeviceExtension;
337  PFDO_DEVICE_EXTENSION FDODeviceExtension;
340  PMDL Mdl = NULL;
342 
343  DPRINT("USBSTOR_CBWCompletionRoutine Irp %p Ctx %p Status %x\n", Irp, Ctx, Irp->IoStatus.Status);
344 
345  FDODeviceExtension = (PFDO_DEVICE_EXTENSION)Ctx;
347  Request = IoStack->Parameters.Scsi.Srb;
348  PDODeviceExtension = (PPDO_DEVICE_EXTENSION)IoStack->DeviceObject->DeviceExtension;
349 
350  if (!NT_SUCCESS(Irp->IoStatus.Status))
351  {
352  goto ResetRecovery;
353  }
354 
355  // a request without the buffer AND not a sense request
356  // for a sense request we provide just a TransferBuffer, an Mdl will be allocated by usbport (see below)
357  if (!Irp->MdlAddress && Request == FDODeviceExtension->ActiveSrb)
358  {
359  Request->SrbStatus = SRB_STATUS_SUCCESS;
360  USBSTOR_SendCSWRequest(FDODeviceExtension, Irp);
362  }
363 
364  // a request with the data buffer
365 
367  {
368  PipeHandle = FDODeviceExtension->InterfaceInformation->Pipes[FDODeviceExtension->BulkInPipeIndex].PipeHandle;
370  }
372  {
373  PipeHandle = FDODeviceExtension->InterfaceInformation->Pipes[FDODeviceExtension->BulkOutPipeIndex].PipeHandle;
375  }
376  else
377  {
378  // we check the validity of a request in disk.c so we should never be here
379  DPRINT1("Warning: shouldn't be here\n");
380  goto ResetRecovery;
381  }
382 
383  // if it is not a Sense Request
384  if (Request == FDODeviceExtension->ActiveSrb)
385  {
386  if (MmGetMdlVirtualAddress(Irp->MdlAddress) == Request->DataBuffer)
387  {
388  Mdl = Irp->MdlAddress;
389  }
390  else
391  {
392  Mdl = IoAllocateMdl(Request->DataBuffer,
393  Request->DataTransferLength,
394  FALSE,
395  FALSE,
396  NULL);
397 
398  if (Mdl)
399  {
400  IoBuildPartialMdl(Irp->MdlAddress,
401  Mdl,
402  Request->DataBuffer,
403  Request->DataTransferLength);
404  }
405  }
406 
407  if (!Mdl)
408  {
409  DPRINT1("USBSTOR_CBWCompletionRoutine: Mdl - %p\n", Mdl);
410  goto ResetRecovery;
411  }
412  }
413  else
414  {
415  ASSERT(Request->DataBuffer);
416  TransferBuffer = Request->DataBuffer;
417  }
418 
419  USBSTOR_IssueBulkOrInterruptRequest(FDODeviceExtension,
420  Irp,
421  PipeHandle,
423  Request->DataTransferLength,
425  Mdl,
427 
429 
430 ResetRecovery:
431  Request = FDODeviceExtension->ActiveSrb;
432  IoStack->Parameters.Scsi.Srb = Request;
433  Irp->IoStatus.Information = 0;
434  Irp->IoStatus.Status = STATUS_IO_DEVICE_ERROR;
435  Request->SrbStatus = SRB_STATUS_BUS_RESET;
436 
437  USBSTOR_QueueTerminateRequest(PDODeviceExtension->LowerDeviceObject, Irp);
438  USBSTOR_QueueResetDevice(FDODeviceExtension);
439 
441 }
442 
443 VOID
445  PUCHAR Block)
446 {
447  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",
448  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,
449  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,
450  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,
451  Block[30] & 0xFF);
452 }
453 
454 static
455 NTSTATUS
457  IN PFDO_DEVICE_EXTENSION FDODeviceExtension,
458  IN PIRP Irp)
459 {
460  PPDO_DEVICE_EXTENSION PDODeviceExtension;
461  PIO_STACK_LOCATION IoStack;
463  PIRP_CONTEXT Context = &FDODeviceExtension->CurrentIrpContext;
464 
465  RtlZeroMemory(&Context->cbw, sizeof(CBW));
466  RtlZeroMemory(&Context->Urb, sizeof(URB));
467 
469  PDODeviceExtension = IoStack->DeviceObject->DeviceExtension;
470  Request = IoStack->Parameters.Scsi.Srb;
471 
472  // Make a CBW structure from SCSI request block
473  Context->cbw.Signature = CBW_SIGNATURE;
474  Context->cbw.Tag = PtrToUlong(Irp);
475  Context->cbw.DataTransferLength = Request->DataTransferLength;
476  Context->cbw.Flags = ((UCHAR)Request->SrbFlags & SRB_FLAGS_UNSPECIFIED_DIRECTION) << 1;
477  Context->cbw.LUN = PDODeviceExtension->LUN;
478  Context->cbw.CommandBlockLength = Request->CdbLength;
479 
480  RtlCopyMemory(&Context->cbw.CommandBlock, Request->Cdb, Request->CdbLength);
481 
482  DPRINT("CBW for IRP %p\n", Irp);
483  DumpCBW((PUCHAR)&Context->cbw);
484 
485  // initialize rest of context
486  Context->Irp = Irp;
487  Context->StallRetryCount = 0;
488 
490  FDODeviceExtension,
491  Irp,
492  FDODeviceExtension->InterfaceInformation->Pipes[FDODeviceExtension->BulkOutPipeIndex].PipeHandle,
494  sizeof(CBW),
495  &Context->cbw,
496  NULL,
498 }
499 
500 static
501 NTSTATUS
503  IN PFDO_DEVICE_EXTENSION FDODeviceExtension,
504  IN PIRP Irp)
505 {
506  PIO_STACK_LOCATION IoStack;
507  PSCSI_REQUEST_BLOCK CurrentSrb;
508  PSCSI_REQUEST_BLOCK SenseSrb;
509 
510  DPRINT("USBSTOR_IssueRequestSense: \n");
511 
512  CurrentSrb = FDODeviceExtension->ActiveSrb;
513  SenseSrb = &FDODeviceExtension->CurrentIrpContext.SenseSrb;
515  IoStack->Parameters.Scsi.Srb = SenseSrb;
516 
517  RtlZeroMemory(SenseSrb, sizeof(*SenseSrb));
518 
520  SenseSrb->Length = sizeof(*SenseSrb);
521  SenseSrb->CdbLength = CDB6GENERIC_LENGTH;
522  SenseSrb->SrbFlags = SRB_FLAGS_DATA_IN |
525 
526  ASSERT(CurrentSrb->SenseInfoBufferLength);
527  ASSERT(CurrentSrb->SenseInfoBuffer);
528  DPRINT("SenseInfoBuffer %x, SenseInfoBufferLength %x\n", CurrentSrb->SenseInfoBuffer, CurrentSrb->SenseInfoBufferLength);
529 
530  SenseSrb->DataTransferLength = CurrentSrb->SenseInfoBufferLength;
531  SenseSrb->DataBuffer = CurrentSrb->SenseInfoBuffer;
532 
533  SrbGetCdb(SenseSrb)->CDB6GENERIC.OperationCode = SCSIOP_REQUEST_SENSE;
534  SrbGetCdb(SenseSrb)->AsByte[4] = CurrentSrb->SenseInfoBufferLength;
535 
536  return USBSTOR_SendCBWRequest(FDODeviceExtension, Irp);
537 }
538 
539 NTSTATUS
542  IN PIRP Irp)
543 {
544  PIO_STACK_LOCATION IoStack;
546  PPDO_DEVICE_EXTENSION PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
547 
548  ASSERT(PDODeviceExtension->Common.IsFDO == FALSE);
549 
551  Request = IoStack->Parameters.Scsi.Srb;
552 
553  DPRINT("USBSTOR_HandleExecuteSCSI Operation Code %x, Length %lu\n", SrbGetCdb(Request)->CDB10.OperationCode, Request->DataTransferLength);
554 
555  // check that we're sending to the right LUN
556  ASSERT(SrbGetCdb(Request)->CDB10.LogicalUnitNumber == PDODeviceExtension->LUN);
557 
558  return USBSTOR_SendCBWRequest(PDODeviceExtension->LowerDeviceObject->DeviceExtension, Irp);
559 }
#define STATUS_DEVICE_DOES_NOT_EXIST
Definition: ntstatus.h:428
#define SRB_FLAGS_DISABLE_AUTOSENSE
Definition: srb.h:391
#define SRB_STATUS_BUS_RESET
Definition: srb.h:345
#define SRB_FLAGS_UNSPECIFIED_DIRECTION
Definition: srb.h:395
#define IN
Definition: typedefs.h:39
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
static NTSTATUS USBSTOR_SrbStatusToNtStatus(IN PSCSI_REQUEST_BLOCK Srb)
Definition: scsi.c:20
ULONG SrbFlags
Definition: srb.h:252
#define IOCTL_INTERNAL_USB_SUBMIT_URB
Definition: usbioctl.h:32
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:68
#define MmGetMdlVirtualAddress(_Mdl)
#define SRB_STATUS_AUTOSENSE_VALID
Definition: srb.h:379
_In_ PIRP Irp
Definition: csq.h:116
#define SRB_FLAGS_NO_QUEUE_FREEZE
Definition: srb.h:396
#define TRUE
Definition: types.h:120
PVOID DataBuffer
Definition: srb.h:255
unsigned char * PUCHAR
Definition: retypes.h:3
ULONG DataTransferLength
Definition: srb.h:253
LONG NTSTATUS
Definition: precomp.h:26
#define USBD_TRANSFER_DIRECTION_IN
Definition: usb.h:160
#define CSW_STATUS_COMMAND_PASSED
Definition: usbstor.h:82
struct _PDO_DEVICE_EXTENSION * PPDO_DEVICE_EXTENSION
#define SRB_STATUS_COMMAND_TIMEOUT
Definition: srb.h:343
Definition: usbstor.h:69
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
UCHAR CdbLength
Definition: srb.h:250
#define SRB_STATUS_NO_DEVICE
Definition: srb.h:340
NTSTATUS USBSTOR_HandleExecuteSCSI(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: scsi.c:540
static NTSTATUS USBSTOR_IssueRequestSense(IN PFDO_DEVICE_EXTENSION FDODeviceExtension, IN PIRP Irp)
Definition: scsi.c:502
#define STATUS_CONTINUE_COMPLETION
FORCEINLINE PCDB SrbGetCdb(_In_ PVOID Srb)
Definition: srbhelper.h:583
Definition: usbstor.h:86
#define SRB_STATUS_BAD_SRB_BLOCK_LENGTH
Definition: srb.h:352
#define SRB_FLAGS_DATA_IN
Definition: srb.h:392
#define SRB_STATUS_INVALID_TARGET_ID
Definition: srb.h:355
#define SRB_STATUS(Status)
Definition: srb.h:381
IO_COMPLETION_ROUTINE USBSTOR_CSWCompletionRoutine
Definition: scsi.c:125
struct _FDO_DEVICE_EXTENSION * PFDO_DEVICE_EXTENSION
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:498
#define STATUS_IO_DEVICE_ERROR
Definition: udferr_usr.h:179
#define SRB_STATUS_ERROR
Definition: srb.h:336
_In_ NDIS_HANDLE _In_ PNDIS_REQUEST Request
Definition: ndis.h:5173
VOID NTAPI IoBuildPartialMdl(IN PMDL SourceMdl, IN PMDL TargetMdl, IN PVOID VirtualAddress, IN ULONG Length)
Definition: iomdl.c:96
VOID USBSTOR_QueueNextRequest(IN PDEVICE_OBJECT DeviceObject)
Definition: queue.c:220
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define FALSE
Definition: types.h:117
IO_COMPLETION_ROUTINE USBSTOR_DataCompletionRoutine
Definition: scsi.c:256
#define USBD_TRANSFER_DIRECTION_OUT
Definition: usb.h:159
PVOID DeviceExtension
Definition: env_spec_w32.h:418
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define SRB_STATUS_NO_HBA
Definition: srb.h:348
COMMON_DEVICE_EXTENSION Common
Definition: pci.h:56
void DPRINT(...)
Definition: polytest.cpp:61
#define CSW_STATUS_COMMAND_FAILED
Definition: usbstor.h:83
VOID USBSTOR_QueueTerminateRequest(IN PDEVICE_OBJECT FDODeviceObject, IN PIRP Irp)
Definition: queue.c:186
#define PtrToUlong(u)
Definition: config.h:107
#define CSW_SIGNATURE
Definition: usbstor.h:65
#define STATUS_DEVICE_NOT_CONNECTED
Definition: udferr_usr.h:160
static BOOLEAN USBSTOR_IsCSWValid(PIRP_CONTEXT Context)
Definition: scsi.c:101
#define SRB_STATUS_BAD_FUNCTION
Definition: srb.h:356
NTSTATUS USBSTOR_SendCSWRequest(PFDO_DEVICE_EXTENSION FDODeviceExtension, PIRP Irp)
Definition: scsi.c:242
#define CDB6GENERIC_LENGTH
Definition: cdrw_hw.h:830
#define CSW_STATUS_PHASE_ERROR
Definition: usbstor.h:84
if(!(yy_init))
Definition: macro.lex.yy.c:714
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
UCHAR Function
Definition: srb.h:242
PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:3202
USHORT Length
Definition: srb.h:241
#define IRP_MJ_INTERNAL_DEVICE_CONTROL
#define SRB_STATUS_DATA_OVERRUN
Definition: srb.h:349
VOID NTAPI IoFreeMdl(PMDL Mdl)
Definition: iomdl.c:146
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
unsigned char UCHAR
Definition: xmlstorage.h:181
LONG USBD_STATUS
Definition: usb.h:165
VOID DumpCBW(PUCHAR Block)
Definition: scsi.c:444
#define SRB_STATUS_SELECTION_TIMEOUT
Definition: srb.h:342
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2691
#define USBD_STATUS_STALL_PID
Definition: usb.h:175
#define SRB_STATUS_INVALID_LUN
Definition: srb.h:354
PMDL NTAPI IoAllocateMdl(IN PVOID VirtualAddress, IN ULONG Length, IN BOOLEAN SecondaryBuffer, IN BOOLEAN ChargeQuota, IN PIRP Irp)
Definition: iomdl.c:22
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
UCHAR SenseInfoBufferLength
Definition: srb.h:251
#define USBD_SHORT_TRANSFER_OK
Definition: usb.h:154
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
Definition: usb.h:529
#define SRB_STATUS_TIMEOUT
Definition: srb.h:341
struct _CDB::_CDB6GENERIC CDB6GENERIC
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
static HANDLE PipeHandle
Definition: dhcpcsvc.c:21
#define SRB_FLAGS_DATA_OUT
Definition: srb.h:393
static NTSTATUS USBSTOR_IssueBulkOrInterruptRequest(IN PFDO_DEVICE_EXTENSION FDODeviceExtension, IN PIRP Irp, IN USBD_PIPE_HANDLE PipeHandle, IN ULONG TransferFlags, IN ULONG TransferBufferLength, IN PVOID TransferBuffer, IN PMDL TransferBufferMDL, IN PIO_COMPLETION_ROUTINE CompletionRoutine)
Definition: scsi.c:60
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
IO_COMPLETION_ROUTINE * PIO_COMPLETION_ROUTINE
Definition: iotypes.h:2814
#define STATUS_IO_TIMEOUT
Definition: udferr_usr.h:163
#define DPRINT1
Definition: precomp.h:8
VOID NTAPI USBSTOR_QueueResetPipe(IN PFDO_DEVICE_EXTENSION FDODeviceExtension)
Definition: error.c:135
PVOID SenseInfoBuffer
Definition: srb.h:256
IO_COMPLETION_ROUTINE USBSTOR_CBWCompletionRoutine
Definition: scsi.c:325
#define SRB_FUNCTION_EXECUTE_SCSI
Definition: srb.h:307
struct tagContext Context
Definition: acpixf.h:1034
_In_ PIRP _In_opt_ PVOID _In_opt_ POPLOCK_WAIT_COMPLETE_ROUTINE CompletionRoutine
Definition: fsrtlfuncs.h:673
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define SRB_STATUS_SUCCESS
Definition: srb.h:333
#define SCSIOP_REQUEST_SENSE
Definition: cdrw_hw.h:870
IN PSCSI_REQUEST_BLOCK Srb
Definition: class2.h:49
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3107
static NTSTATUS USBSTOR_SendCBWRequest(IN PFDO_DEVICE_EXTENSION FDODeviceExtension, IN PIRP Irp)
Definition: scsi.c:456
return STATUS_SUCCESS
Definition: btrfs.c:3014
VOID NTAPI USBSTOR_QueueResetDevice(IN PFDO_DEVICE_EXTENSION FDODeviceExtension)
Definition: error.c:148
#define CBW_SIGNATURE
Definition: usbstor.h:64
UCHAR AsByte[16]
Definition: scsi.h:1988
#define URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER
Definition: usb.h:95