ReactOS 0.4.16-dev-297-gc569aee
scsi.c File Reference
#include "usbstor.h"
#include <debug.h>
Include dependency graph for scsi.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

static NTSTATUS USBSTOR_SrbStatusToNtStatus (IN PSCSI_REQUEST_BLOCK Srb)
 
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)
 
static BOOLEAN USBSTOR_IsCSWValid (PIRP_CONTEXT Context)
 
static NTSTATUS USBSTOR_IssueRequestSense (IN PFDO_DEVICE_EXTENSION FDODeviceExtension, IN PIRP Irp)
 
NTSTATUS NTAPI USBSTOR_CSWCompletionRoutine (PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Ctx)
 
NTSTATUS USBSTOR_SendCSWRequest (PFDO_DEVICE_EXTENSION FDODeviceExtension, PIRP Irp)
 
NTSTATUS NTAPI USBSTOR_DataCompletionRoutine (PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Ctx)
 
NTSTATUS NTAPI USBSTOR_CBWCompletionRoutine (PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Ctx)
 
VOID DumpCBW (PUCHAR Block)
 
static NTSTATUS USBSTOR_SendCBWRequest (IN PFDO_DEVICE_EXTENSION FDODeviceExtension, IN PIRP Irp)
 
NTSTATUS USBSTOR_HandleExecuteSCSI (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 

Variables

IO_COMPLETION_ROUTINE USBSTOR_CSWCompletionRoutine
 
IO_COMPLETION_ROUTINE USBSTOR_DataCompletionRoutine
 
IO_COMPLETION_ROUTINE USBSTOR_CBWCompletionRoutine
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file scsi.c.

Function Documentation

◆ DumpCBW()

VOID DumpCBW ( PUCHAR  Block)

Definition at line 444 of file scsi.c.

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}
#define DPRINT
Definition: sndvol32.h:73

Referenced by USBSTOR_SendCBWRequest(), and USBSTOR_SendRequest().

◆ USBSTOR_CBWCompletionRoutine()

NTSTATUS NTAPI USBSTOR_CBWCompletionRoutine ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp,
PVOID  Ctx 
)

Definition at line 329 of file scsi.c.

333{
334 PIO_STACK_LOCATION IoStack;
336 PPDO_DEVICE_EXTENSION PDODeviceExtension;
337 PFDO_DEVICE_EXTENSION FDODeviceExtension;
339 ULONG TransferFlags;
340 PMDL Mdl = NULL;
341 PVOID TransferBuffer = 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;
374 TransferFlags = USBD_TRANSFER_DIRECTION_OUT;
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,
422 TransferFlags,
423 Request->DataTransferLength,
424 TransferBuffer,
425 Mdl,
427
429
430ResetRecovery:
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}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
#define DPRINT1
Definition: precomp.h:8
_In_ PIRP Irp
Definition: csq.h:116
static HANDLE PipeHandle
Definition: dhcpcsvc.c:22
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
struct _FDO_DEVICE_EXTENSION * PFDO_DEVICE_EXTENSION
struct _PDO_DEVICE_EXTENSION * PPDO_DEVICE_EXTENSION
#define SRB_STATUS_BUS_RESET
Definition: srb.h:353
#define SRB_FLAGS_DATA_OUT
Definition: srb.h:401
#define SRB_FLAGS_DATA_IN
Definition: srb.h:400
#define SRB_FLAGS_UNSPECIFIED_DIRECTION
Definition: srb.h:403
#define SRB_STATUS_SUCCESS
Definition: srb.h:341
VOID NTAPI USBSTOR_QueueResetDevice(IN PFDO_DEVICE_EXTENSION FDODeviceExtension)
Definition: error.c:148
VOID USBSTOR_QueueTerminateRequest(IN PDEVICE_OBJECT FDODeviceObject, IN PIRP Irp)
Definition: queue.c:186
#define IoAllocateMdl
Definition: fxmdl.h:88
VOID NTAPI IoBuildPartialMdl(IN PMDL SourceMdl, IN PMDL TargetMdl, IN PVOID VirtualAddress, IN ULONG Length)
Definition: iomdl.c:96
if(dx< 0)
Definition: linetemp.h:194
#define ASSERT(a)
Definition: mode.c:44
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:68
PVOID DeviceExtension
Definition: env_spec_w32.h:418
PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:3223
union _IO_STACK_LOCATION::@1579 Parameters
struct _IO_STACK_LOCATION::@3978::@4000 Scsi
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_IO_DEVICE_ERROR
Definition: udferr_usr.h:179
NTSTATUS USBSTOR_SendCSWRequest(PFDO_DEVICE_EXTENSION FDODeviceExtension, PIRP Irp)
Definition: scsi.c:242
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
IO_COMPLETION_ROUTINE USBSTOR_DataCompletionRoutine
Definition: scsi.c:256
#define USBD_TRANSFER_DIRECTION_IN
Definition: usb.h:160
#define USBD_SHORT_TRANSFER_OK
Definition: usb.h:154
#define USBD_TRANSFER_DIRECTION_OUT
Definition: usb.h:159
_In_ WDFREQUEST Request
Definition: wdfdevice.h:547
_In_ WDFDEVICE _In_ PVOID _In_opt_ PMDL Mdl
#define STATUS_CONTINUE_COMPLETION
#define MmGetMdlVirtualAddress(_Mdl)

◆ USBSTOR_CSWCompletionRoutine()

NTSTATUS NTAPI USBSTOR_CSWCompletionRoutine ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp,
PVOID  Ctx 
)

Definition at line 129 of file scsi.c.

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;
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;
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
227ResetRecovery:
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}
#define SRB_STATUS_AUTOSENSE_VALID
Definition: srb.h:387
#define SRB_FLAGS_DISABLE_AUTOSENSE
Definition: srb.h:399
#define SRB_STATUS_ERROR
Definition: srb.h:344
VOID NTAPI USBSTOR_QueueResetPipe(IN PFDO_DEVICE_EXTENSION FDODeviceExtension)
Definition: error.c:135
VOID USBSTOR_QueueNextRequest(IN PDEVICE_OBJECT DeviceObject)
Definition: queue.c:220
static NTSTATUS USBSTOR_IssueRequestSense(IN PFDO_DEVICE_EXTENSION FDODeviceExtension, IN PIRP Irp)
Definition: scsi.c:502
static BOOLEAN USBSTOR_IsCSWValid(PIRP_CONTEXT Context)
Definition: scsi.c:101
static NTSTATUS USBSTOR_SrbStatusToNtStatus(IN PSCSI_REQUEST_BLOCK Srb)
Definition: scsi.c:20
#define USBD_STATUS_STALL_PID
Definition: usb.h:175
LONG USBD_STATUS
Definition: usb.h:165
#define USBD_STATUS(Status)
Definition: usbdi.h:52
#define CSW_STATUS_PHASE_ERROR
Definition: usbstor.h:85
#define CSW_STATUS_COMMAND_PASSED
Definition: usbstor.h:83
#define CSW_STATUS_COMMAND_FAILED
Definition: usbstor.h:84

◆ USBSTOR_DataCompletionRoutine()

NTSTATUS NTAPI USBSTOR_DataCompletionRoutine ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp,
PVOID  Ctx 
)

Definition at line 260 of file scsi.c.

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}
#define SRB_STATUS_DATA_OVERRUN
Definition: srb.h:357
#define IoFreeMdl
Definition: fxmdl.h:89

◆ USBSTOR_HandleExecuteSCSI()

NTSTATUS USBSTOR_HandleExecuteSCSI ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 540 of file scsi.c.

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}
COMMON_DEVICE_EXTENSION Common
Definition: pci.h:59
static NTSTATUS USBSTOR_SendCBWRequest(IN PFDO_DEVICE_EXTENSION FDODeviceExtension, IN PIRP Irp)
Definition: scsi.c:456
#define SrbGetCdb(srb)
Definition: usbstor.h:18
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055

Referenced by USBSTOR_HandleTransferError(), and USBSTOR_StartIo().

◆ USBSTOR_IsCSWValid()

static BOOLEAN USBSTOR_IsCSWValid ( PIRP_CONTEXT  Context)
static

Definition at line 101 of file scsi.c.

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}
#define TRUE
Definition: types.h:120
#define PtrToUlong(u)
Definition: config.h:107
#define CSW_SIGNATURE
Definition: usbstor.h:66

Referenced by USBSTOR_CSWCompletionRoutine().

◆ USBSTOR_IssueBulkOrInterruptRequest()

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 
)
static

Definition at line 60 of file scsi.c.

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);
87 NextStack->Parameters.Others.Argument1 = &Context->Urb;
88
91 FDODeviceExtension,
92 TRUE,
93 TRUE,
94 TRUE);
95
96 return IoCallDriver(FDODeviceExtension->LowerDeviceObject, Irp);
97}
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:490
#define IoCallDriver
Definition: irp.c:1225
struct _IO_STACK_LOCATION::@1579::@1580 DeviceIoControl
struct _IO_STACK_LOCATION::@3978::@4017 Others
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER
Definition: usb.h:95
#define IOCTL_INTERNAL_USB_SUBMIT_URB
Definition: usbioctl.h:32
_In_ WDFREQUEST _In_opt_ PFN_WDF_REQUEST_COMPLETION_ROUTINE CompletionRoutine
Definition: wdfrequest.h:895
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2695
#define IRP_MJ_INTERNAL_DEVICE_CONTROL

Referenced by USBSTOR_CBWCompletionRoutine(), USBSTOR_SendCBWRequest(), and USBSTOR_SendCSWRequest().

◆ USBSTOR_IssueRequestSense()

static NTSTATUS USBSTOR_IssueRequestSense ( IN PFDO_DEVICE_EXTENSION  FDODeviceExtension,
IN PIRP  Irp 
)
static

Definition at line 502 of file scsi.c.

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}
#define SCSIOP_REQUEST_SENSE
Definition: cdrw_hw.h:870
#define CDB6GENERIC_LENGTH
Definition: cdrw_hw.h:830
#define SRB_FUNCTION_EXECUTE_SCSI
Definition: srb.h:315
#define SRB_FLAGS_NO_QUEUE_FREEZE
Definition: srb.h:404
UCHAR SenseInfoBufferLength
Definition: srb.h:259
PVOID DataBuffer
Definition: srb.h:263
UCHAR CdbLength
Definition: srb.h:258
PVOID SenseInfoBuffer
Definition: srb.h:264
UCHAR Function
Definition: srb.h:250
ULONG DataTransferLength
Definition: srb.h:261
ULONG SrbFlags
Definition: srb.h:260
USHORT Length
Definition: srb.h:249

Referenced by USBSTOR_CSWCompletionRoutine().

◆ USBSTOR_SendCBWRequest()

static NTSTATUS USBSTOR_SendCBWRequest ( IN PFDO_DEVICE_EXTENSION  FDODeviceExtension,
IN PIRP  Irp 
)
static

Definition at line 456 of file scsi.c.

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}
Definition: usbstor.h:71
Definition: usb.h:529
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
unsigned char * PUCHAR
Definition: typedefs.h:53
VOID DumpCBW(PUCHAR Block)
Definition: scsi.c:444
IO_COMPLETION_ROUTINE USBSTOR_CBWCompletionRoutine
Definition: scsi.c:325
#define CBW_SIGNATURE
Definition: usbstor.h:65
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by USBSTOR_HandleExecuteSCSI(), and USBSTOR_IssueRequestSense().

◆ USBSTOR_SendCSWRequest()

NTSTATUS USBSTOR_SendCSWRequest ( PFDO_DEVICE_EXTENSION  FDODeviceExtension,
PIRP  Irp 
)

Definition at line 242 of file scsi.c.

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}
Definition: usbstor.h:88
IO_COMPLETION_ROUTINE USBSTOR_CSWCompletionRoutine
Definition: scsi.c:125

Referenced by USBSTOR_CBWCompletionRoutine(), USBSTOR_DataCompletionRoutine(), and USBSTOR_ResetPipeWorkItemRoutine().

◆ USBSTOR_SrbStatusToNtStatus()

static NTSTATUS USBSTOR_SrbStatusToNtStatus ( IN PSCSI_REQUEST_BLOCK  Srb)
static

Definition at line 20 of file scsi.c.

22{
23 UCHAR SrbStatus;
24
25 SrbStatus = SRB_STATUS(Srb->SrbStatus);
26
27 switch (SrbStatus)
28 {
30 return STATUS_SUCCESS;
31
34
38
44
46 return STATUS_IO_TIMEOUT;
47
52
53 default:
55 }
56}
_In_ PSCSI_REQUEST_BLOCK Srb
Definition: cdrom.h:989
#define SRB_STATUS_INVALID_LUN
Definition: srb.h:362
#define SRB_STATUS_NO_HBA
Definition: srb.h:356
#define SRB_STATUS_INVALID_TARGET_ID
Definition: srb.h:363
#define SRB_STATUS_BAD_SRB_BLOCK_LENGTH
Definition: srb.h:360
#define SRB_STATUS_TIMEOUT
Definition: srb.h:349
#define SRB_STATUS_SELECTION_TIMEOUT
Definition: srb.h:350
#define SRB_STATUS_BAD_FUNCTION
Definition: srb.h:364
#define SRB_STATUS(Status)
Definition: srb.h:389
#define SRB_STATUS_COMMAND_TIMEOUT
Definition: srb.h:351
#define SRB_STATUS_NO_DEVICE
Definition: srb.h:348
#define STATUS_DEVICE_DOES_NOT_EXIST
Definition: ntstatus.h:428
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
UCHAR SrbStatus
Definition: srb.h:251
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define STATUS_DEVICE_NOT_CONNECTED
Definition: udferr_usr.h:160
#define STATUS_IO_TIMEOUT
Definition: udferr_usr.h:163

Referenced by USBSTOR_CSWCompletionRoutine().

Variable Documentation

◆ USBSTOR_CBWCompletionRoutine

IO_COMPLETION_ROUTINE USBSTOR_CBWCompletionRoutine

Definition at line 325 of file scsi.c.

Referenced by USBSTOR_SendCBW(), and USBSTOR_SendCBWRequest().

◆ USBSTOR_CSWCompletionRoutine

IO_COMPLETION_ROUTINE USBSTOR_CSWCompletionRoutine

Definition at line 125 of file scsi.c.

Referenced by USBSTOR_CBWCompletionRoutine(), USBSTOR_SendCSW(), and USBSTOR_SendCSWRequest().

◆ USBSTOR_DataCompletionRoutine

IO_COMPLETION_ROUTINE USBSTOR_DataCompletionRoutine

Definition at line 256 of file scsi.c.

Referenced by USBSTOR_CBWCompletionRoutine().