ReactOS  0.4.15-dev-1150-g593bcce
usbstor.h File Reference
#include <wdm.h>
#include <usbdi.h>
#include <usbbusif.h>
#include <usbdlib.h>
#include <classpnp.h>
#include <pshpack1.h>
#include <poppack.h>
Include dependency graph for usbstor.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  CBW
 
struct  CSW
 
struct  IRP_CONTEXT
 
struct  __COMMON_DEVICE_EXTENSION__
 
struct  FDO_DEVICE_EXTENSION
 
struct  PDO_DEVICE_EXTENSION
 
struct  _ERRORHANDLER_WORKITEM_DATA
 

Macros

#define USB_STOR_TAG   'sbsu'
 
#define BooleanFlagOn(Flags, SingleFlag)   ((BOOLEAN)((((Flags) & (SingleFlag)) != 0)))
 
#define SrbGetCdb(srb)   ((PCDB)(srb->Cdb))
 
#define USB_SUBCLASS_RBC   0x01
 
#define USB_SUBCLASS_8020   0x02
 
#define USB_SUBCLASS_QIC   0x03
 
#define USB_SUBCLASS_UFI   0x04
 
#define USB_SUBCLASS_8070   0x05
 
#define USB_SUBCLASS_SCSI   0x06
 
#define USB_SUBCLASS_LOCKABLE   0x07
 
#define USB_SUBCLASS_ISD200   0xF0
 
#define USB_SUBCLASS_CYP_ATACB   0xF1
 
#define USB_SUBCLASS_VENDOR   0xFF
 
#define USB_PROTOCOL_CBI   0x00
 
#define USB_PROTOCOL_CB   0x01
 
#define USB_PROTOCOL_BULK   0x50
 
#define USB_PROTOCOL_UAS   0x62
 
#define USB_PROTOCOL_USBAT   0x80
 
#define USB_PROTOCOL_EUSB_SDDR09   0x81
 
#define USB_PROTOCOL_SDDR55   0x82
 
#define USB_PROTOCOL_DPCM_USB   0xF0
 
#define USB_PROTOCOL_FREECOM   0xF1
 
#define USB_PROTOCOL_DATAFAB   0xF2
 
#define USB_PROTOCOL_JUMPSHOT   0xF3
 
#define USB_PROTOCOL_ALAUDA   0xF4
 
#define USB_PROTOCOL_KARMA   0xF5
 
#define USB_PROTOCOL_VENDOR   0xFF
 
#define USB_BULK_GET_MAX_LUN   0xFE
 
#define USB_BULK_RESET_DEVICE   0xFF
 
#define USB_RECOVERABLE_ERRORS
 
#define USB_MAXCHILDREN   16
 
#define MAX_LUN   0xF
 
#define USBSTOR_DEFAULT_MAX_TRANSFER_LENGTH   0x10000
 
#define CBW_SIGNATURE   0x43425355
 
#define CSW_SIGNATURE   0x53425355
 
#define CSW_STATUS_COMMAND_PASSED   0x00
 
#define CSW_STATUS_COMMAND_FAILED   0x01
 
#define CSW_STATUS_PHASE_ERROR   0x02
 
#define USBSTOR_FDO_FLAGS_DEVICE_RESETTING   0x00000001
 
#define USBSTOR_FDO_FLAGS_IRP_LIST_FREEZE   0x00000002
 

Typedefs

typedef struct CBWPCBW
 
typedef struct CSWPCSW
 
typedef struct IRP_CONTEXTPIRP_CONTEXT
 
typedef struct __COMMON_DEVICE_EXTENSION__ USBSTOR_COMMON_DEVICE_EXTENSION
 
typedef struct __COMMON_DEVICE_EXTENSION__PUSBSTOR_COMMON_DEVICE_EXTENSION
 
typedef struct FDO_DEVICE_EXTENSIONPFDO_DEVICE_EXTENSION
 
typedef struct PDO_DEVICE_EXTENSIONPPDO_DEVICE_EXTENSION
 
typedef struct _ERRORHANDLER_WORKITEM_DATA ERRORHANDLER_WORKITEM_DATA
 
typedef struct _ERRORHANDLER_WORKITEM_DATAPERRORHANDLER_WORKITEM_DATA
 

Functions

 C_ASSERT (sizeof(CBW)==31)
 
NTSTATUS USBSTOR_FdoHandlePnp (IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
 
NTSTATUS USBSTOR_PdoHandlePnp (IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
 
NTSTATUS USBSTOR_CreatePDO (IN PDEVICE_OBJECT DeviceObject, IN UCHAR LUN)
 
NTSTATUS NTAPI USBSTOR_SyncForwardIrp (IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
 
NTSTATUS NTAPI USBSTOR_GetBusInterface (IN PDEVICE_OBJECT DeviceObject, OUT PUSB_BUS_INTERFACE_USBDI_V2 BusInterface)
 
PVOID AllocateItem (IN POOL_TYPE PoolType, IN ULONG ItemSize)
 
VOID FreeItem (IN PVOID Item)
 
NTSTATUS USBSTOR_SyncUrbRequest (IN PDEVICE_OBJECT DeviceObject, OUT PURB UrbRequest)
 
NTSTATUS USBSTOR_GetMaxLUN (IN PDEVICE_OBJECT DeviceObject, IN PFDO_DEVICE_EXTENSION DeviceExtension)
 
NTSTATUS NTAPI USBSTOR_SyncForwardIrpCompletionRoutine (PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Context)
 
NTSTATUS USBSTOR_ResetDevice (IN PDEVICE_OBJECT DeviceObject, IN PFDO_DEVICE_EXTENSION DeviceExtension)
 
NTSTATUS USBSTOR_GetDescriptors (IN PDEVICE_OBJECT DeviceObject)
 
NTSTATUS USBSTOR_SelectConfigurationAndInterface (IN PDEVICE_OBJECT DeviceObject, IN PFDO_DEVICE_EXTENSION DeviceExtension)
 
NTSTATUS USBSTOR_GetPipeHandles (IN PFDO_DEVICE_EXTENSION DeviceExtension)
 
NTSTATUS USBSTOR_HandleExecuteSCSI (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS USBSTOR_SendCSWRequest (PFDO_DEVICE_EXTENSION FDODeviceExtension, PIRP Irp)
 
NTSTATUS USBSTOR_HandleInternalDeviceControl (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS USBSTOR_HandleDeviceControl (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
VOID NTAPI USBSTOR_StartIo (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
VOID USBSTOR_QueueWaitForPendingRequests (IN PDEVICE_OBJECT DeviceObject)
 
VOID USBSTOR_QueueRelease (IN PDEVICE_OBJECT DeviceObject)
 
BOOLEAN USBSTOR_QueueAddIrp (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
VOID NTAPI USBSTOR_CancelIo (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
VOID USBSTOR_QueueInitialize (PFDO_DEVICE_EXTENSION FDODeviceExtension)
 
VOID USBSTOR_QueueNextRequest (IN PDEVICE_OBJECT DeviceObject)
 
VOID USBSTOR_QueueTerminateRequest (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS USBSTOR_GetEndpointStatus (IN PDEVICE_OBJECT DeviceObject, IN UCHAR bEndpointAddress, OUT PUSHORT Value)
 
NTSTATUS USBSTOR_ResetPipeWithHandle (IN PDEVICE_OBJECT DeviceObject, IN USBD_PIPE_HANDLE PipeHandle)
 
VOID NTAPI USBSTOR_TimerRoutine (PDEVICE_OBJECT DeviceObject, PVOID Context)
 
VOID NTAPI USBSTOR_QueueResetPipe (IN PFDO_DEVICE_EXTENSION FDODeviceExtension)
 
VOID NTAPI USBSTOR_QueueResetDevice (IN PFDO_DEVICE_EXTENSION FDODeviceExtension)
 

Macro Definition Documentation

◆ BooleanFlagOn

#define BooleanFlagOn (   Flags,
  SingleFlag 
)    ((BOOLEAN)((((Flags) & (SingleFlag)) != 0)))

Definition at line 13 of file usbstor.h.

◆ CBW_SIGNATURE

#define CBW_SIGNATURE   0x43425355

Definition at line 64 of file usbstor.h.

◆ CSW_SIGNATURE

#define CSW_SIGNATURE   0x53425355

Definition at line 65 of file usbstor.h.

◆ CSW_STATUS_COMMAND_FAILED

#define CSW_STATUS_COMMAND_FAILED   0x01

Definition at line 83 of file usbstor.h.

◆ CSW_STATUS_COMMAND_PASSED

#define CSW_STATUS_COMMAND_PASSED   0x00

Definition at line 82 of file usbstor.h.

◆ CSW_STATUS_PHASE_ERROR

#define CSW_STATUS_PHASE_ERROR   0x02

Definition at line 84 of file usbstor.h.

◆ MAX_LUN

#define MAX_LUN   0xF

Definition at line 61 of file usbstor.h.

◆ SrbGetCdb

#define SrbGetCdb (   srb)    ((PCDB)(srb->Cdb))

Definition at line 17 of file usbstor.h.

◆ USB_BULK_GET_MAX_LUN

#define USB_BULK_GET_MAX_LUN   0xFE

Definition at line 54 of file usbstor.h.

◆ USB_BULK_RESET_DEVICE

#define USB_BULK_RESET_DEVICE   0xFF

Definition at line 55 of file usbstor.h.

◆ USB_MAXCHILDREN

#define USB_MAXCHILDREN   16

Definition at line 60 of file usbstor.h.

◆ USB_PROTOCOL_ALAUDA

#define USB_PROTOCOL_ALAUDA   0xF4

Definition at line 48 of file usbstor.h.

◆ USB_PROTOCOL_BULK

#define USB_PROTOCOL_BULK   0x50

Definition at line 38 of file usbstor.h.

◆ USB_PROTOCOL_CB

#define USB_PROTOCOL_CB   0x01

Definition at line 37 of file usbstor.h.

◆ USB_PROTOCOL_CBI

#define USB_PROTOCOL_CBI   0x00

Definition at line 36 of file usbstor.h.

◆ USB_PROTOCOL_DATAFAB

#define USB_PROTOCOL_DATAFAB   0xF2

Definition at line 46 of file usbstor.h.

◆ USB_PROTOCOL_DPCM_USB

#define USB_PROTOCOL_DPCM_USB   0xF0

Definition at line 44 of file usbstor.h.

◆ USB_PROTOCOL_EUSB_SDDR09

#define USB_PROTOCOL_EUSB_SDDR09   0x81

Definition at line 41 of file usbstor.h.

◆ USB_PROTOCOL_FREECOM

#define USB_PROTOCOL_FREECOM   0xF1

Definition at line 45 of file usbstor.h.

◆ USB_PROTOCOL_JUMPSHOT

#define USB_PROTOCOL_JUMPSHOT   0xF3

Definition at line 47 of file usbstor.h.

◆ USB_PROTOCOL_KARMA

#define USB_PROTOCOL_KARMA   0xF5

Definition at line 49 of file usbstor.h.

◆ USB_PROTOCOL_SDDR55

#define USB_PROTOCOL_SDDR55   0x82

Definition at line 42 of file usbstor.h.

◆ USB_PROTOCOL_UAS

#define USB_PROTOCOL_UAS   0x62

Definition at line 39 of file usbstor.h.

◆ USB_PROTOCOL_USBAT

#define USB_PROTOCOL_USBAT   0x80

Definition at line 40 of file usbstor.h.

◆ USB_PROTOCOL_VENDOR

#define USB_PROTOCOL_VENDOR   0xFF

Definition at line 50 of file usbstor.h.

◆ USB_RECOVERABLE_ERRORS

#define USB_RECOVERABLE_ERRORS
Value:
#define USBD_STATUS_ENDPOINT_HALTED
Definition: usb.h:190
#define USBD_STATUS_STALL_PID
Definition: usb.h:175
#define USBD_STATUS_DEV_NOT_RESPONDING
Definition: usb.h:176
#define USBD_STATUS_NO_BANDWIDTH
Definition: usb.h:195

Definition at line 57 of file usbstor.h.

◆ USB_STOR_TAG

#define USB_STOR_TAG   'sbsu'

Definition at line 10 of file usbstor.h.

◆ USB_SUBCLASS_8020

#define USB_SUBCLASS_8020   0x02

Definition at line 23 of file usbstor.h.

◆ USB_SUBCLASS_8070

#define USB_SUBCLASS_8070   0x05

Definition at line 26 of file usbstor.h.

◆ USB_SUBCLASS_CYP_ATACB

#define USB_SUBCLASS_CYP_ATACB   0xF1

Definition at line 31 of file usbstor.h.

◆ USB_SUBCLASS_ISD200

#define USB_SUBCLASS_ISD200   0xF0

Definition at line 30 of file usbstor.h.

◆ USB_SUBCLASS_LOCKABLE

#define USB_SUBCLASS_LOCKABLE   0x07

Definition at line 28 of file usbstor.h.

◆ USB_SUBCLASS_QIC

#define USB_SUBCLASS_QIC   0x03

Definition at line 24 of file usbstor.h.

◆ USB_SUBCLASS_RBC

#define USB_SUBCLASS_RBC   0x01

Definition at line 22 of file usbstor.h.

◆ USB_SUBCLASS_SCSI

#define USB_SUBCLASS_SCSI   0x06

Definition at line 27 of file usbstor.h.

◆ USB_SUBCLASS_UFI

#define USB_SUBCLASS_UFI   0x04

Definition at line 25 of file usbstor.h.

◆ USB_SUBCLASS_VENDOR

#define USB_SUBCLASS_VENDOR   0xFF

Definition at line 32 of file usbstor.h.

◆ USBSTOR_DEFAULT_MAX_TRANSFER_LENGTH

#define USBSTOR_DEFAULT_MAX_TRANSFER_LENGTH   0x10000

Definition at line 62 of file usbstor.h.

◆ USBSTOR_FDO_FLAGS_DEVICE_RESETTING

#define USBSTOR_FDO_FLAGS_DEVICE_RESETTING   0x00000001

Definition at line 116 of file usbstor.h.

◆ USBSTOR_FDO_FLAGS_IRP_LIST_FREEZE

#define USBSTOR_FDO_FLAGS_IRP_LIST_FREEZE   0x00000002

Definition at line 117 of file usbstor.h.

Typedef Documentation

◆ ERRORHANDLER_WORKITEM_DATA

◆ PCBW

typedef struct CBW * PCBW

◆ PCSW

typedef struct CSW * PCSW

◆ PERRORHANDLER_WORKITEM_DATA

◆ PFDO_DEVICE_EXTENSION

◆ PIRP_CONTEXT

◆ PPDO_DEVICE_EXTENSION

◆ PUSBSTOR_COMMON_DEVICE_EXTENSION

◆ USBSTOR_COMMON_DEVICE_EXTENSION

Function Documentation

◆ AllocateItem()

PVOID AllocateItem ( IN POOL_TYPE  PoolType,
IN ULONG  ItemSize 
)

Definition at line 30 of file misc.c.

33 {
35  if (!Item)
36  return Item;
37 
39  return Item;
40 }
#define TAG_KS
Definition: misc.c:14
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS _Inout_ PLARGE_INTEGER NumberOfBytes
Definition: iotypes.h:1018
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
_Must_inspect_result_ _In_ FLT_CONTEXT_TYPE _In_ SIZE_T _In_ POOL_TYPE PoolType
Definition: fltkernel.h:1444

◆ C_ASSERT()

C_ASSERT ( sizeof(CBW = =31)

◆ FreeItem()

VOID FreeItem ( IN PVOID  Item)

Definition at line 43 of file misc.c.

45 {
46  ExFreePool(Item);
47 }
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

◆ USBSTOR_CancelIo()

VOID NTAPI USBSTOR_CancelIo ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 28 of file queue.c.

31 {
32  PFDO_DEVICE_EXTENSION FDODeviceExtension;
33 
34  FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
36  ASSERT(FDODeviceExtension->Common.IsFDO);
37 
38  // this IRP isn't in our list here
39  // now release the cancel lock
40  IoReleaseCancelSpinLock(Irp->CancelIrql);
41  Irp->IoStatus.Status = STATUS_CANCELLED;
42 
45 
47 }
_In_ PIRP Irp
Definition: csq.h:116
#define ASSERT_IRQL_EQUAL(x)
Definition: debug.h:43
struct _FDO_DEVICE_EXTENSION * PFDO_DEVICE_EXTENSION
VOID USBSTOR_QueueNextRequest(IN PDEVICE_OBJECT DeviceObject)
Definition: queue.c:220
#define IoCompleteRequest
Definition: irp.c:1240
VOID USBSTOR_QueueTerminateRequest(IN PDEVICE_OBJECT FDODeviceObject, IN PIRP Irp)
Definition: queue.c:186
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
COMMON_DEVICE_EXTENSION Common
Definition: pci.h:81
VOID NTAPI IoReleaseCancelSpinLock(IN KIRQL Irql)
Definition: util.c:150
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
#define IO_NO_INCREMENT
Definition: iotypes.h:581

◆ USBSTOR_CreatePDO()

NTSTATUS USBSTOR_CreatePDO ( IN PDEVICE_OBJECT  DeviceObject,
IN UCHAR  LUN 
)

Definition at line 843 of file pdo.c.

846 {
847  PDEVICE_OBJECT PDO;
849  PPDO_DEVICE_EXTENSION PDODeviceExtension;
850  PFDO_DEVICE_EXTENSION FDODeviceExtension;
851  PINQUIRYDATA InquiryData;
852 
853  FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
854 
855  // create child device object
857  if (!NT_SUCCESS(Status))
858  {
859  DPRINT1("Failed to create PDO, status %x\n", Status);
860  return Status;
861  }
862 
863  // patch the stack size
864  PDO->StackSize = DeviceObject->StackSize;
865 
866  PDODeviceExtension = (PPDO_DEVICE_EXTENSION)PDO->DeviceExtension;
867  InquiryData = (PINQUIRYDATA)&PDODeviceExtension->InquiryData;
868 
869  // initialize device extension
870  RtlZeroMemory(PDODeviceExtension, sizeof(PDO_DEVICE_EXTENSION));
871  PDODeviceExtension->Common.IsFDO = FALSE;
872  PDODeviceExtension->LowerDeviceObject = DeviceObject;
873  PDODeviceExtension->PDODeviceObject = &FDODeviceExtension->ChildPDO[LUN];
874  PDODeviceExtension->Self = PDO;
875  PDODeviceExtension->LUN = LUN;
876 
877  PDO->Flags |= DO_DIRECT_IO;
878 
879  // device is initialized
880  PDO->Flags &= ~DO_DEVICE_INITIALIZING;
881 
882  // output device object
883  FDODeviceExtension->ChildPDO[LUN] = PDO;
884 
885  // send inquiry command by irp
887 
888  if (!NT_SUCCESS(Status))
889  {
890  return Status;
891  }
892 
893  if (InquiryData->DeviceType != DIRECT_ACCESS_DEVICE &&
895  {
896  return STATUS_NOT_SUPPORTED;
897  }
898 
899  return Status;
900 }
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
LONG NTSTATUS
Definition: precomp.h:26
struct _PDO_DEVICE_EXTENSION * PPDO_DEVICE_EXTENSION
#define FILE_DEVICE_MASS_STORAGE
Definition: imports.h:62
struct _FDO_DEVICE_EXTENSION * PFDO_DEVICE_EXTENSION
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
#define FALSE
Definition: types.h:117
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
COMMON_DEVICE_EXTENSION Common
Definition: pci.h:56
#define FILE_AUTOGENERATED_DEVICE_NAME
Definition: iotypes.h:138
#define DIRECT_ACCESS_DEVICE
Definition: cdrw_hw.h:1144
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
UCHAR DeviceType
Definition: cdrw_hw.h:1116
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
#define DPRINT1
Definition: precomp.h:8
#define READ_ONLY_DIRECT_ACCESS_DEVICE
Definition: cdrw_hw.h:1149
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
static NTSTATUS USBSTOR_FillInquiryData(IN PDEVICE_OBJECT PDODeviceObject)
Definition: pdo.c:803

◆ USBSTOR_FdoHandlePnp()

NTSTATUS USBSTOR_FdoHandlePnp ( IN PDEVICE_OBJECT  DeviceObject,
IN OUT PIRP  Irp 
)

Definition at line 277 of file fdo.c.

280 {
281  PIO_STACK_LOCATION IoStack;
282  PFDO_DEVICE_EXTENSION DeviceExtension;
284 
286  DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
287  ASSERT(DeviceExtension->Common.IsFDO);
288 
289  switch(IoStack->MinorFunction)
290  {
292  {
293  DPRINT("IRP_MN_SURPRISE_REMOVAL %p\n", DeviceObject);
294  Irp->IoStatus.Status = STATUS_SUCCESS;
295 
296  // forward irp to next device object
298  return IoCallDriver(DeviceExtension->LowerDeviceObject, Irp);
299  }
301  {
302  DPRINT("IRP_MN_QUERY_DEVICE_RELATIONS %p Type: %u\n", DeviceObject, IoStack->Parameters.QueryDeviceRelations.Type);
303  return USBSTOR_FdoHandleDeviceRelations(DeviceExtension, Irp);
304  }
305  case IRP_MN_STOP_DEVICE:
306  {
307  DPRINT1("USBSTOR_FdoHandlePnp: IRP_MN_STOP_DEVICE unimplemented\n");
309  Irp->IoStatus.Status = STATUS_SUCCESS;
310 
311  // forward irp to next device object
313  return IoCallDriver(DeviceExtension->LowerDeviceObject, Irp);
314  }
316  {
317  DPRINT("IRP_MN_REMOVE_DEVICE\n");
318 
319  return USBSTOR_FdoHandleRemoveDevice(DeviceObject, DeviceExtension, Irp);
320  }
322  {
323  // FIXME: set custom capabilities
325  return IoCallDriver(DeviceExtension->LowerDeviceObject, Irp);
326  }
329  {
330 #if 0
331  //
332  // we can if nothing is pending
333  //
334  if (DeviceExtension->IrpPendingCount != 0 ||
335  DeviceExtension->ActiveSrb != NULL)
336 #else
337  if (TRUE)
338 #endif
339  {
340  /* We have pending requests */
341  DPRINT1("Failing removal/stop request due to pending requests present\n");
343  }
344  else
345  {
346  /* We're all clear */
347  Irp->IoStatus.Status = STATUS_SUCCESS;
348 
350  return IoCallDriver(DeviceExtension->LowerDeviceObject, Irp);
351  }
352  break;
353  }
354  case IRP_MN_START_DEVICE:
355  {
357  break;
358  }
359  default:
360  {
361  // forward irp to next device object
363  return IoCallDriver(DeviceExtension->LowerDeviceObject, Irp);
364  }
365  }
366 
367  if (Status != STATUS_PENDING)
368  {
369  Irp->IoStatus.Status = Status;
371  }
372 
373  return Status;
374 }
#define IRP_MN_REMOVE_DEVICE
NTSTATUS USBSTOR_FdoHandleDeviceRelations(IN PFDO_DEVICE_EXTENSION DeviceExtension, IN OUT PIRP Irp)
Definition: fdo.c:41
_In_ PIRP Irp
Definition: csq.h:116
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS USBSTOR_FdoHandleStartDevice(IN PDEVICE_OBJECT DeviceObject, IN PFDO_DEVICE_EXTENSION DeviceExtension, IN OUT PIRP Irp)
Definition: fdo.c:152
struct _FDO_DEVICE_EXTENSION * PFDO_DEVICE_EXTENSION
NTSTATUS USBSTOR_FdoHandleRemoveDevice(IN PDEVICE_OBJECT DeviceObject, IN PFDO_DEVICE_EXTENSION DeviceExtension, IN OUT PIRP Irp)
Definition: fdo.c:100
#define IRP_MN_QUERY_REMOVE_DEVICE
VOID NTAPI IoStopTimer(PDEVICE_OBJECT DeviceObject)
Definition: iotimer.c:166
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
#define IRP_MN_QUERY_STOP_DEVICE
#define IRP_MN_SURPRISE_REMOVAL
Definition: ntifs_ex.h:408
#define IRP_MN_STOP_DEVICE
#define STATUS_PENDING
Definition: ntstatus.h:82
#define IRP_MN_START_DEVICE
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
Status
Definition: gdiplustypes.h:24
COMMON_DEVICE_EXTENSION Common
Definition: pci.h:81
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IRP_MN_QUERY_DEVICE_RELATIONS
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define DPRINT1
Definition: precomp.h:8
#define IO_NO_INCREMENT
Definition: iotypes.h:581
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3107
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define IRP_MN_QUERY_CAPABILITIES

◆ USBSTOR_GetBusInterface()

NTSTATUS NTAPI USBSTOR_GetBusInterface ( IN PDEVICE_OBJECT  DeviceObject,
OUT PUSB_BUS_INTERFACE_USBDI_V2  BusInterface 
)

Definition at line 57 of file misc.c.

60 {
61  KEVENT Event;
63  PIRP Irp;
65  PIO_STACK_LOCATION Stack;
66 
68  ASSERT(BusInterface);
69 
71 
74  NULL,
75  0,
76  NULL,
77  &Event,
78  &IoStatus);
79  if (Irp == NULL)
80  {
82  }
83 
84  // initialize request
86  Stack->MajorFunction = IRP_MJ_PNP;
88  Stack->Parameters.QueryInterface.Size = sizeof(BUS_INTERFACE_STANDARD);
89  Stack->Parameters.QueryInterface.InterfaceType = (LPGUID)&USB_BUS_INTERFACE_USBDI_GUID;
90  Stack->Parameters.QueryInterface.Version = 2;
91  Stack->Parameters.QueryInterface.Interface = (PINTERFACE)BusInterface;
92  Stack->Parameters.QueryInterface.InterfaceSpecificData = NULL;
93  Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
94 
96 
97  if (Status == STATUS_PENDING)
98  {
100  Status = IoStatus.Status;
101  }
102 
103  return Status;
104 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
IN PLARGE_INTEGER IN ULONG IN BOOLEAN IN ULONG IN BOOLEAN OUT PIO_STATUS_BLOCK IoStatus
Definition: fatprocs.h:2659
PIRP NTAPI IoBuildSynchronousFsdRequest(IN ULONG MajorFunction, IN PDEVICE_OBJECT DeviceObject, IN PVOID Buffer, IN ULONG Length, IN PLARGE_INTEGER StartingOffset, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:1069
_In_ PIRP Irp
Definition: csq.h:116
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define FALSE
Definition: types.h:117
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:450
smooth NULL
Definition: ftsmooth.c:416
struct _INTERFACE * PINTERFACE
#define STATUS_PENDING
Definition: ntstatus.h:82
#define IRP_MN_QUERY_INTERFACE
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2691
struct _BUS_INTERFACE_STANDARD BUS_INTERFACE_STANDARD
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
HRESULT QueryInterface([in] REFIID riid, [out, iid_is(riid)] void **ppvObject)
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3107
GUID * LPGUID
Definition: guiddef.h:81

◆ USBSTOR_GetDescriptors()

NTSTATUS USBSTOR_GetDescriptors ( IN PDEVICE_OBJECT  DeviceObject)

Definition at line 75 of file descriptor.c.

77 {
79  PFDO_DEVICE_EXTENSION DeviceExtension;
80  USHORT DescriptorLength;
81 
82  DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
83 
84  // first get device descriptor
85  Status = USBSTOR_GetDescriptor(DeviceExtension->LowerDeviceObject, USB_DEVICE_DESCRIPTOR_TYPE, sizeof(USB_DEVICE_DESCRIPTOR), 0, 0, (PVOID*)&DeviceExtension->DeviceDescriptor);
86  if (!NT_SUCCESS(Status))
87  {
88  DeviceExtension->DeviceDescriptor = NULL;
89  return Status;
90  }
91 
92  // now get basic configuration descriptor
93  Status = USBSTOR_GetDescriptor(DeviceExtension->LowerDeviceObject, USB_CONFIGURATION_DESCRIPTOR_TYPE, sizeof(USB_CONFIGURATION_DESCRIPTOR), 0, 0, (PVOID*)&DeviceExtension->ConfigurationDescriptor);
94  if (!NT_SUCCESS(Status))
95  {
96  FreeItem(DeviceExtension->DeviceDescriptor);
97  DeviceExtension->DeviceDescriptor = NULL;
98  return Status;
99  }
100 
101  // backup length
102  DescriptorLength = DeviceExtension->ConfigurationDescriptor->wTotalLength;
103 
104  // release basic descriptor
105  FreeItem(DeviceExtension->ConfigurationDescriptor);
106  DeviceExtension->ConfigurationDescriptor = NULL;
107 
108  // allocate full descriptor
109  Status = USBSTOR_GetDescriptor(DeviceExtension->LowerDeviceObject, USB_CONFIGURATION_DESCRIPTOR_TYPE, DescriptorLength, 0, 0, (PVOID*)&DeviceExtension->ConfigurationDescriptor);
110  if (!NT_SUCCESS(Status))
111  {
112  FreeItem(DeviceExtension->DeviceDescriptor);
113  DeviceExtension->DeviceDescriptor = NULL;
114  return Status;
115  }
116 
117  // check if there is a serial number provided
118  if (DeviceExtension->DeviceDescriptor->iSerialNumber)
119  {
120  // get serial number
121  Status = USBSTOR_GetDescriptor(DeviceExtension->LowerDeviceObject, USB_STRING_DESCRIPTOR_TYPE, 100 * sizeof(WCHAR), DeviceExtension->DeviceDescriptor->iSerialNumber, 0x0409, (PVOID*)&DeviceExtension->SerialNumber);
122  if (!NT_SUCCESS(Status))
123  {
124  FreeItem(DeviceExtension->DeviceDescriptor);
125  DeviceExtension->DeviceDescriptor = NULL;
126 
127  FreeItem(DeviceExtension->ConfigurationDescriptor);
128  DeviceExtension->ConfigurationDescriptor = NULL;
129 
130  DeviceExtension->SerialNumber = NULL;
131  return Status;
132  }
133  }
134 
135  return Status;
136 }
LONG NTSTATUS
Definition: precomp.h:26
#define USB_STRING_DESCRIPTOR_TYPE
Definition: usb100.h:51
struct _FDO_DEVICE_EXTENSION * PFDO_DEVICE_EXTENSION
VOID FreeItem(IN PVOID Item)
Definition: misc.c:43
NTSTATUS NTAPI USBSTOR_GetDescriptor(IN PDEVICE_OBJECT DeviceObject, IN UCHAR DescriptorType, IN ULONG DescriptorLength, IN UCHAR DescriptorIndex, IN LANGID LanguageId, OUT PVOID *OutDescriptor)
Definition: descriptor.c:18
#define USB_DEVICE_DESCRIPTOR_TYPE
Definition: usb100.h:49
#define USB_CONFIGURATION_DESCRIPTOR_TYPE
Definition: usb100.h:50
smooth NULL
Definition: ftsmooth.c:416
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
unsigned short USHORT
Definition: pedump.c:61
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464

◆ USBSTOR_GetEndpointStatus()

NTSTATUS USBSTOR_GetEndpointStatus ( IN PDEVICE_OBJECT  DeviceObject,
IN UCHAR  bEndpointAddress,
OUT PUSHORT  Value 
)

Definition at line 18 of file error.c.

22 {
23  PURB Urb;
25 
26  DPRINT("Allocating URB\n");
28  if (!Urb)
29  {
30  DPRINT1("OutofMemory!\n");
32  }
33 
34  // build status
36 
37  // send the request
38  DPRINT1("Sending Request DeviceObject %p, Urb %p\n", DeviceObject, Urb);
40 
41  FreeItem(Urb);
42  return Status;
43 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define UsbBuildGetStatusRequest(urb, op, index, transferBuffer, transferBufferMDL, link)
Definition: usbdlib.h:35
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
Definition: misc.c:30
LONG NTSTATUS
Definition: precomp.h:26
IN UCHAR Value
Definition: halp.h:394
VOID FreeItem(IN PVOID Item)
Definition: misc.c:43
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define URB_FUNCTION_GET_STATUS_FROM_ENDPOINT
Definition: usb.h:107
Status
Definition: gdiplustypes.h:24
struct _URB * PURB
Definition: usb.h:529
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
NTSTATUS USBSTOR_SyncUrbRequest(IN PDEVICE_OBJECT DeviceObject, OUT PURB UrbRequest)
Definition: misc.c:107
#define DPRINT1
Definition: precomp.h:8

◆ USBSTOR_GetMaxLUN()

NTSTATUS USBSTOR_GetMaxLUN ( IN PDEVICE_OBJECT  DeviceObject,
IN PFDO_DEVICE_EXTENSION  DeviceExtension 
)

Definition at line 204 of file misc.c.

207 {
208  PUCHAR Buffer;
210 
212  if (!Buffer)
213  {
215  }
216 
217  Status = USBSTOR_ClassRequest(DeviceObject, DeviceExtension, USB_BULK_GET_MAX_LUN, DeviceExtension->InterfaceInformation->InterfaceNumber, USBD_TRANSFER_DIRECTION_IN, sizeof(UCHAR), Buffer);
218 
219  DPRINT("MaxLUN: %x\n", *Buffer);
220 
221  if (NT_SUCCESS(Status))
222  {
223  if (*Buffer > MAX_LUN)
224  {
225  // invalid response documented in usb mass storage specification
227  }
228  else
229  {
230  // store maxlun
231  DeviceExtension->MaxLUN = *Buffer;
232  }
233  }
234  else
235  {
236  // "USB Mass Storage Class. Bulk-Only Transport. Revision 1.0"
237  // 3.2 Get Max LUN (class-specific request) :
238  // Devices that do not support multiple LUNs may STALL this command.
239  USBSTOR_ResetDevice(DeviceExtension->LowerDeviceObject, DeviceExtension);
240 
241  DeviceExtension->MaxLUN = 0;
243  }
244 
246  return Status;
247 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
#define USBD_TRANSFER_DIRECTION_IN
Definition: usb.h:160
NTSTATUS USBSTOR_ResetDevice(IN PDEVICE_OBJECT DeviceObject, IN PFDO_DEVICE_EXTENSION DeviceExtension)
Definition: misc.c:250
NTSTATUS USBSTOR_ClassRequest(IN PDEVICE_OBJECT DeviceObject, IN PFDO_DEVICE_EXTENSION DeviceExtension, IN UCHAR RequestType, IN USHORT Index, IN ULONG TransferFlags, IN ULONG TransferBufferLength, IN PVOID TransferBuffer)
Definition: misc.c:170
void DPRINT(...)
Definition: polytest.cpp:61
Definition: bufpool.h:45
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define MAX_LUN
Definition: usbstor.h:61
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
unsigned char UCHAR
Definition: xmlstorage.h:181
Status
Definition: gdiplustypes.h:24
#define USB_STOR_TAG
Definition: usbstor.h:10
#define USB_BULK_GET_MAX_LUN
Definition: usbstor.h:54
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define STATUS_DEVICE_DATA_ERROR
Definition: udferr_usr.h:159

◆ USBSTOR_GetPipeHandles()

NTSTATUS USBSTOR_GetPipeHandles ( IN PFDO_DEVICE_EXTENSION  DeviceExtension)

Definition at line 319 of file descriptor.c.

321 {
322  ULONG Index;
323  BOOLEAN BulkInFound = FALSE, BulkOutFound = FALSE;
324 
325  // enumerate all pipes and extract bulk-in / bulk-out pipe handle
326  for (Index = 0; Index < DeviceExtension->InterfaceInformation->NumberOfPipes; Index++)
327  {
328  if (DeviceExtension->InterfaceInformation->Pipes[Index].PipeType == UsbdPipeTypeBulk)
329  {
330  if (USB_ENDPOINT_DIRECTION_IN(DeviceExtension->InterfaceInformation->Pipes[Index].EndpointAddress))
331  {
332  DeviceExtension->BulkInPipeIndex = Index;
333 
334  // there should not be another bulk in pipe
335  ASSERT(BulkInFound == FALSE);
336  BulkInFound = TRUE;
337  }
338  else
339  {
340  DeviceExtension->BulkOutPipeIndex = Index;
341 
342  // there should not be another bulk out pipe
343  ASSERT(BulkOutFound == FALSE);
344  BulkOutFound = TRUE;
345  }
346  }
347  }
348 
349  if (!BulkInFound || !BulkOutFound)
350  {
351  // WTF? usb port driver does not give us bulk pipe access
352  DPRINT1("USBSTOR_GetPipeHandles> BulkInFound %c BulkOutFound %c missing!!!\n", BulkInFound, BulkOutFound);
354  }
355 
356  return STATUS_SUCCESS;
357 }
#define USB_ENDPOINT_DIRECTION_IN(x)
Definition: usb100.h:76
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
static const UCHAR Index[8]
Definition: usbohci.c:18
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_DEVICE_CONFIGURATION_ERROR
Definition: ntstatus.h:619
return STATUS_SUCCESS
Definition: btrfs.c:3014

◆ USBSTOR_HandleDeviceControl()

NTSTATUS USBSTOR_HandleDeviceControl ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 417 of file disk.c.

420 {
421  PIO_STACK_LOCATION IoStack;
423  PPDO_DEVICE_EXTENSION PDODeviceExtension;
424  PSCSI_ADAPTER_BUS_INFO BusInfo;
425  PSCSI_INQUIRY_DATA ScsiInquiryData;
426  PINQUIRYDATA InquiryData;
427 
429 
430  switch (IoStack->Parameters.DeviceIoControl.IoControlCode)
431  {
434  break;
436  DPRINT1("USBSTOR_HandleDeviceControl IOCTL_SCSI_PASS_THROUGH NOT implemented\n");
438  break;
440  DPRINT1("USBSTOR_HandleDeviceControl IOCTL_SCSI_PASS_THROUGH_DIRECT NOT implemented\n");
442  break;
444  DPRINT1("USBSTOR_HandleDeviceControl IOCTL_STORAGE_GET_MEDIA_SERIAL_NUMBER NOT implemented\n");
446  break;
448  {
450 
451  // Legacy port capability query
452  if (IoStack->Parameters.DeviceIoControl.OutputBufferLength == sizeof(PVOID))
453  {
454  Capabilities = *((PVOID *)Irp->AssociatedIrp.SystemBuffer) = ExAllocatePoolWithTag(NonPagedPool,
455  sizeof(IO_SCSI_CAPABILITIES),
456  USB_STOR_TAG);
457  Irp->IoStatus.Information = sizeof(PVOID);
458  }
459  else
460  {
461  Capabilities = Irp->AssociatedIrp.SystemBuffer;
462  Irp->IoStatus.Information = sizeof(IO_SCSI_CAPABILITIES);
463  }
464 
465  if (Capabilities)
466  {
467  Capabilities->MaximumTransferLength = USBSTOR_DEFAULT_MAX_TRANSFER_LENGTH;
468  Capabilities->MaximumPhysicalPages = USBSTOR_DEFAULT_MAX_TRANSFER_LENGTH / PAGE_SIZE + 1; // See CORE-10515 and CORE-10755
469  Capabilities->SupportedAsynchronousEvents = 0;
470  Capabilities->AlignmentMask = 0;
471  Capabilities->TaggedQueuing = FALSE;
472  Capabilities->AdapterScansDown = FALSE;
473  Capabilities->AdapterUsesPio = FALSE;
475  }
476  else
477  {
479  }
480 
481  break;
482  }
484  {
485  PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
486  ASSERT(PDODeviceExtension);
487  ASSERT(PDODeviceExtension->Common.IsFDO == FALSE);
488 
489  // get parameters
490  BusInfo = Irp->AssociatedIrp.SystemBuffer;
491  ScsiInquiryData = (PSCSI_INQUIRY_DATA)(BusInfo + 1);
492  InquiryData = (PINQUIRYDATA)ScsiInquiryData->InquiryData;
493 
494 
495  BusInfo->NumberOfBuses = 1;
496  BusInfo->BusData[0].NumberOfLogicalUnits = 1; //FIXME
497  BusInfo->BusData[0].InitiatorBusId = 0;
498  BusInfo->BusData[0].InquiryDataOffset = sizeof(SCSI_ADAPTER_BUS_INFO);
499 
500  ScsiInquiryData->PathId = 0;
501  ScsiInquiryData->TargetId = 0;
502  ScsiInquiryData->Lun = PDODeviceExtension->LUN & MAX_LUN;
503  ScsiInquiryData->DeviceClaimed = PDODeviceExtension->Claimed;
504  ScsiInquiryData->InquiryDataLength = sizeof(INQUIRYDATA);
505  ScsiInquiryData->NextInquiryDataOffset = 0;
506 
507  // Note: INQUIRYDATA structure is larger than INQUIRYDATABUFFERSIZE
508  RtlZeroMemory(InquiryData, sizeof(INQUIRYDATA));
509  RtlCopyMemory(InquiryData, &PDODeviceExtension->InquiryData, sizeof(PDODeviceExtension->InquiryData));
510 
511  InquiryData->Versions = 0x04;
512  InquiryData->ResponseDataFormat = 0x02; // some devices set this to 1
513 
514  Irp->IoStatus.Information = sizeof(SCSI_ADAPTER_BUS_INFO) + sizeof(SCSI_INQUIRY_DATA) + sizeof(INQUIRYDATA) - 1;
516 
517  break;
518  }
520  {
521  PSCSI_ADDRESS Address = Irp->AssociatedIrp.SystemBuffer;
522 
523  Address->Length = sizeof(SCSI_ADDRESS);
524  Address->PortNumber = 0;
525  Address->PathId = 0;
526  Address->TargetId = 0;
527  Address->Lun = (((PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->LUN & MAX_LUN);
528  Irp->IoStatus.Information = sizeof(SCSI_ADDRESS);
529 
531 
532  break;
533  }
534  default:
535  DPRINT("USBSTOR_HandleDeviceControl IoControl %x not supported\n", IoStack->Parameters.DeviceIoControl.IoControlCode);
537  break;
538  }
539 
540  return Status;
541 }
struct _SCSI_ADAPTER_BUS_INFO SCSI_ADAPTER_BUS_INFO
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define IOCTL_SCSI_GET_ADDRESS
Definition: scsi_port.h:52
_In_ PIRP Irp
Definition: csq.h:116
#define USBSTOR_DEFAULT_MAX_TRANSFER_LENGTH
Definition: usbstor.h:62
UCHAR ResponseDataFormat
Definition: cdrw_hw.h:1121
LONG NTSTATUS
Definition: precomp.h:26
struct _PDO_DEVICE_EXTENSION * PPDO_DEVICE_EXTENSION
struct _INQUIRYDATA * PINQUIRYDATA
ULONG NextInquiryDataOffset
Definition: scsi_port.h:118
SCSI_BUS_DATA BusData[1]
Definition: scsi_port.h:106
#define FALSE
Definition: types.h:117
_Must_inspect_result_ typedef _Out_ PHIDP_CAPS Capabilities
Definition: hidclass.h:103
struct _SCSI_INQUIRY_DATA * PSCSI_INQUIRY_DATA
struct _INQUIRYDATA INQUIRYDATA
static WCHAR Address[46]
Definition: ping.c:68
COMMON_DEVICE_EXTENSION Common
Definition: pci.h:56
void DPRINT(...)
Definition: polytest.cpp:61
void * PVOID
Definition: retypes.h:9
ULONG InquiryDataOffset
Definition: scsi_port.h:98
#define IOCTL_STORAGE_QUERY_PROPERTY
Definition: ntddstor.h:178
#define IOCTL_STORAGE_GET_MEDIA_SERIAL_NUMBER
Definition: ntddstor.h:151
#define MAX_LUN
Definition: usbstor.h:61
NTSTATUS USBSTOR_HandleQueryProperty(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: disk.c:226
UCHAR Versions
Definition: cdrw_hw.h:1120
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
Status
Definition: gdiplustypes.h:24
#define USB_STOR_TAG
Definition: usbstor.h:10
#define PAGE_SIZE
Definition: env_spec_w32.h:49
UCHAR InquiryData[1]
Definition: scsi_port.h:119
#define IOCTL_SCSI_PASS_THROUGH
Definition: scsi_port.h:47
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
#define IOCTL_SCSI_GET_INQUIRY_DATA
Definition: scsi_port.h:49
#define IOCTL_SCSI_PASS_THROUGH_DIRECT
Definition: scsi_port.h:51
ULONG InquiryDataLength
Definition: scsi_port.h:117
UCHAR InitiatorBusId
Definition: scsi_port.h:97
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
#define DPRINT1
Definition: precomp.h:8
BOOLEAN DeviceClaimed
Definition: scsi_port.h:116
#define IOCTL_SCSI_GET_CAPABILITIES
Definition: scsi_port.h:50
struct _SCSI_ADDRESS SCSI_ADDRESS
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
UCHAR NumberOfLogicalUnits
Definition: scsi_port.h:96
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3107
return STATUS_SUCCESS
Definition: btrfs.c:3014
struct _IO_SCSI_CAPABILITIES IO_SCSI_CAPABILITIES

◆ 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 }
_In_ WDFREQUEST Request
Definition: cdrom.h:1234
_In_ PIRP Irp
Definition: csq.h:116
struct _PDO_DEVICE_EXTENSION * PPDO_DEVICE_EXTENSION
FORCEINLINE PCDB SrbGetCdb(_In_ PVOID Srb)
Definition: srbhelper.h:583
#define FALSE
Definition: types.h:117
COMMON_DEVICE_EXTENSION Common
Definition: pci.h:56
void DPRINT(...)
Definition: polytest.cpp:61
static NTSTATUS USBSTOR_SendCBWRequest(IN PFDO_DEVICE_EXTENSION FDODeviceExtension, IN PIRP Irp)
Definition: scsi.c:456
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3107

Referenced by USBSTOR_HandleTransferError(), and USBSTOR_StartIo().

◆ USBSTOR_HandleInternalDeviceControl()

NTSTATUS USBSTOR_HandleInternalDeviceControl ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 81 of file disk.c.

84 {
85  PIO_STACK_LOCATION IoStack;
87  PPDO_DEVICE_EXTENSION PDODeviceExtension;
89 
91  Request = (PSCSI_REQUEST_BLOCK)IoStack->Parameters.Others.Argument1;
92  ASSERT(Request);
93  PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
94  ASSERT(PDODeviceExtension->Common.IsFDO == FALSE);
95 
96  switch(Request->Function)
97  {
99  {
100  DPRINT("SRB_FUNCTION_EXECUTE_SCSI\n");
101 
102  if (!IsRequestValid(Irp))
103  {
105  break;
106  }
107 
108  if (Request->Cdb[0] == SCSIOP_MODE_SENSE)
109  {
110  DPRINT("USBSTOR_Scsi: SRB_FUNCTION_EXECUTE_SCSI - FIXME SCSIOP_MODE_SENSE\n");
111  // FIXME Get from registry WriteProtect for StorageDevicePolicies;
112  // L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\StorageDevicePolicies"
113  // QueryTable[0].Name = L"WriteProtect"
114  }
115 
117  Request->SrbStatus = SRB_STATUS_PENDING;
118 
119  // add the request
120  if (!USBSTOR_QueueAddIrp(PDODeviceExtension->LowerDeviceObject, Irp))
121  {
122  IoStartPacket(PDODeviceExtension->LowerDeviceObject, Irp, &Request->QueueSortKey, USBSTOR_CancelIo);
123  }
124 
125  return STATUS_PENDING;
126  }
128  {
129  DPRINT1("SRB_FUNCTION_RELEASE_DEVICE\n");
130  ASSERT(PDODeviceExtension->Claimed == TRUE);
131 
132  // release claim
133  PDODeviceExtension->Claimed = FALSE;
135  break;
136  }
138  {
139  DPRINT1("SRB_FUNCTION_CLAIM_DEVICE\n");
140 
141  // check if the device has been claimed
142  if (PDODeviceExtension->Claimed)
143  {
144  // device has already been claimed
146  Request->SrbStatus = SRB_STATUS_BUSY;
147  break;
148  }
149 
150  // claim device
151  PDODeviceExtension->Claimed = TRUE;
152 
153  // output device object
154  Request->DataBuffer = DeviceObject;
155 
157  break;
158  }
160  {
161  DPRINT1("SRB_FUNCTION_RELEASE_QUEUE\n");
162 
163  USBSTOR_QueueRelease(PDODeviceExtension->LowerDeviceObject);
164 
165  Request->SrbStatus = SRB_STATUS_SUCCESS;
167  break;
168  }
169 
171  case SRB_FUNCTION_FLUSH:
173  {
174  DPRINT1("SRB_FUNCTION_FLUSH / SRB_FUNCTION_FLUSH_QUEUE / SRB_FUNCTION_SHUTDOWN\n");
175 
176  // HACK: don't flush pending requests
177 #if 0 // we really need a proper storage stack
178  //
179  // wait for pending requests to finish
180  //
181  USBSTOR_QueueWaitForPendingRequests(PDODeviceExtension->LowerDeviceObject);
182 #endif
183 
184  Request->SrbStatus = SRB_STATUS_SUCCESS;
186  break;
187  }
188  default:
189  {
190  //
191  // not supported
192  //
194  Request->SrbStatus = SRB_STATUS_ERROR;
195  }
196  }
197 
198  Irp->IoStatus.Status = Status;
200  return Status;
201 }
_In_ WDFREQUEST Request
Definition: cdrom.h:1234
VOID NTAPI USBSTOR_CancelIo(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: queue.c:28
struct _SCSI_REQUEST_BLOCK * PSCSI_REQUEST_BLOCK
_In_ PIRP Irp
Definition: csq.h:116
#define TRUE
Definition: types.h:120
#define SCSIOP_MODE_SENSE
Definition: cdrw_hw.h:896
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
struct _PDO_DEVICE_EXTENSION * PPDO_DEVICE_EXTENSION
BOOLEAN USBSTOR_QueueAddIrp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: queue.c:75
static BOOLEAN IsRequestValid(PIRP Irp)
Definition: disk.c:19
#define SRB_FUNCTION_FLUSH_QUEUE
Definition: srb.h:321
#define SRB_FUNCTION_RELEASE_QUEUE
Definition: srb.h:311
#define SRB_FUNCTION_CLAIM_DEVICE
Definition: srb.h:308
#define SRB_STATUS_ERROR
Definition: srb.h:336
#define FALSE
Definition: types.h:117
VOID USBSTOR_QueueRelease(IN PDEVICE_OBJECT DeviceObject)
Definition: queue.c:262
VOID NTAPI IoStartPacket(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PULONG Key, IN PDRIVER_CANCEL CancelFunction)
Definition: device.c:1876
#define SRB_STATUS_PENDING
Definition: srb.h:332
#define SRB_FUNCTION_RELEASE_DEVICE
Definition: srb.h:313
#define IoCompleteRequest
Definition: irp.c:1240
COMMON_DEVICE_EXTENSION Common
Definition: pci.h:56
void DPRINT(...)
Definition: polytest.cpp:61
#define SRB_STATUS_BUSY
Definition: srb.h:337
#define SRB_FUNCTION_FLUSH
Definition: srb.h:315
#define STATUS_PENDING
Definition: ntstatus.h:82
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
#define SRB_FUNCTION_SHUTDOWN
Definition: srb.h:314
#define STATUS_DEVICE_BUSY
Definition: udferr_usr.h:129
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
#define DPRINT1
Definition: precomp.h:8
VOID USBSTOR_QueueWaitForPendingRequests(IN PDEVICE_OBJECT DeviceObject)
Definition: queue.c:171
#define SRB_FUNCTION_EXECUTE_SCSI
Definition: srb.h:307
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
#define IO_NO_INCREMENT
Definition: iotypes.h:581
#define SRB_STATUS_SUCCESS
Definition: srb.h:333
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3107
return STATUS_SUCCESS
Definition: btrfs.c:3014
IoMarkIrpPending(Irp)

◆ USBSTOR_PdoHandlePnp()

NTSTATUS USBSTOR_PdoHandlePnp ( IN PDEVICE_OBJECT  DeviceObject,
IN OUT PIRP  Irp 
)

Definition at line 511 of file pdo.c.

514 {
515  PIO_STACK_LOCATION IoStack;
516  PPDO_DEVICE_EXTENSION DeviceExtension;
519  ULONG bDelete;
520 
522  DeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
523  ASSERT(DeviceExtension->Common.IsFDO == FALSE);
524 
525  switch(IoStack->MinorFunction)
526  {
528  {
530  break;
531  }
533  {
535  break;
536  }
537  case IRP_MN_QUERY_ID:
538  {
539  if (IoStack->Parameters.QueryId.IdType == BusQueryDeviceID)
540  {
542  break;
543  }
544  else if (IoStack->Parameters.QueryId.IdType == BusQueryHardwareIDs)
545  {
547  break;
548  }
549  else if (IoStack->Parameters.QueryId.IdType == BusQueryInstanceID)
550  {
552  break;
553  }
554  else if (IoStack->Parameters.QueryId.IdType == BusQueryCompatibleIDs)
555  {
557  break;
558  }
559 
560  DPRINT1("USBSTOR_PdoHandlePnp: IRP_MN_QUERY_ID IdType %x unimplemented\n", IoStack->Parameters.QueryId.IdType);
562  Irp->IoStatus.Information = 0;
563  break;
564  }
566  {
567  DPRINT("IRP_MN_REMOVE_DEVICE\n");
568 
569  if(*DeviceExtension->PDODeviceObject != NULL)
570  {
571  *DeviceExtension->PDODeviceObject = NULL;
572  bDelete = TRUE;
573  }
574  else
575  {
576  // device object already marked for deletion
577  bDelete = FALSE;
578  }
579 
580  Irp->IoStatus.Status = STATUS_SUCCESS;
582 
583  if (bDelete)
584  {
586  }
587  return STATUS_SUCCESS;
588  }
590  {
591  // just forward irp to lower device
592  Status = USBSTOR_SyncForwardIrp(DeviceExtension->LowerDeviceObject, Irp);
594 
595  if (NT_SUCCESS(Status))
596  {
597  // check if no unique id
598  Caps = (PDEVICE_CAPABILITIES)IoStack->Parameters.DeviceCapabilities.Capabilities;
599  Caps->UniqueID = FALSE; // no unique id is supported
600  Caps->Removable = TRUE; //FIXME
601  }
602  break;
603  }
606  {
607 #if 0
608  //
609  // if we're not claimed it's ok
610  //
611  if (DeviceExtension->Claimed)
612 #else
613  if (TRUE)
614 #endif
615  {
617  DPRINT1("[USBSTOR] Request %x fails because device is still claimed\n", IoStack->MinorFunction);
618  }
619  else
621  break;
622  }
623  case IRP_MN_START_DEVICE:
624  {
625  // no-op for PDO
627  break;
628  }
630  {
632  break;
633  }
634  default:
635  {
636  // do nothing
637  Status = Irp->IoStatus.Status;
638  }
639  }
640 
641  if (Status != STATUS_PENDING)
642  {
643  Irp->IoStatus.Status = Status;
645  }
646 
647  return Status;
648 }
#define IRP_MN_REMOVE_DEVICE
#define IRP_MN_QUERY_ID
NTSTATUS USBSTOR_PdoHandleDeviceRelations(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
Definition: pdo.c:477
_In_ PIRP Irp
Definition: csq.h:116
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS USBSTOR_PdoHandleQueryDeviceText(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: pdo.c:125
struct _PDO_DEVICE_EXTENSION * PPDO_DEVICE_EXTENSION
NTSTATUS USBSTOR_PdoHandleQueryDeviceId(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: pdo.c:179
#define FALSE
Definition: types.h:117
#define IRP_MN_QUERY_REMOVE_DEVICE
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
NTSTATUS NTAPI USBSTOR_SyncForwardIrp(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: misc.c:34
NTSTATUS USBSTOR_PdoHandleQueryInstanceId(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
Definition: pdo.c:434
COMMON_DEVICE_EXTENSION Common
Definition: pci.h:56
void DPRINT(...)
Definition: polytest.cpp:61
#define IRP_MN_QUERY_STOP_DEVICE
#define IRP_MN_SURPRISE_REMOVAL
Definition: ntifs_ex.h:408
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
#define IRP_MN_START_DEVICE
#define IRP_MN_QUERY_DEVICE_TEXT
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
NTSTATUS USBSTOR_PdoHandleQueryCompatibleId(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
Definition: pdo.c:394
Status
Definition: gdiplustypes.h:24
NTSTATUS USBSTOR_PdoHandleQueryHardwareId(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
Definition: pdo.c:267
* PDEVICE_CAPABILITIES
Definition: iotypes.h:948
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
#define IRP_MN_QUERY_DEVICE_RELATIONS
#define DPRINT1
Definition: precomp.h:8
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:581
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3107
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define IRP_MN_QUERY_CAPABILITIES

◆ USBSTOR_QueueAddIrp()

BOOLEAN USBSTOR_QueueAddIrp ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 75 of file queue.c.

78 {
79  PDRIVER_CANCEL OldDriverCancel;
80  KIRQL OldLevel;
81  PFDO_DEVICE_EXTENSION FDODeviceExtension;
82  BOOLEAN IrpListFreeze;
83  BOOLEAN SrbProcessing;
85  PSCSI_REQUEST_BLOCK Request = (PSCSI_REQUEST_BLOCK)IoStack->Parameters.Others.Argument1;
86 
87  FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
88  ASSERT(FDODeviceExtension->Common.IsFDO);
89 
91 
92  KeAcquireSpinLock(&FDODeviceExtension->IrpListLock, &OldLevel);
93 
94  SrbProcessing = FDODeviceExtension->IrpPendingCount != 0;
95 
96  if (SrbProcessing)
97  {
98  // add irp to queue
99  InsertTailList(&FDODeviceExtension->IrpListHead, &Irp->Tail.Overlay.ListEntry);
100  }
101 
102  FDODeviceExtension->IrpPendingCount++;
103  KeClearEvent(&FDODeviceExtension->NoPendingRequests);
104 
105  // check if queue is freezed
106  IrpListFreeze = BooleanFlagOn(FDODeviceExtension->Flags, USBSTOR_FDO_FLAGS_IRP_LIST_FREEZE);
107 
108  KeReleaseSpinLock(&FDODeviceExtension->IrpListLock, OldLevel);
109 
110  // synchronize with cancellations by holding the cancel lock
111  IoAcquireCancelSpinLock(&Irp->CancelIrql);
112 
113  if (SrbProcessing)
114  {
115  ASSERT(FDODeviceExtension->ActiveSrb != NULL);
116 
117  OldDriverCancel = IoSetCancelRoutine(Irp, USBSTOR_Cancel);
118  }
119  else
120  {
121  ASSERT(FDODeviceExtension->ActiveSrb == NULL);
122 
123  FDODeviceExtension->ActiveSrb = Request;
124  OldDriverCancel = IoSetCancelRoutine(Irp, USBSTOR_CancelIo);
125  }
126 
127  // check if the irp has already been cancelled
128  if (Irp->Cancel && OldDriverCancel == NULL)
129  {
130  // cancel irp
131  Irp->CancelRoutine(DeviceObject, Irp);
132  return FALSE;
133  }
134 
135  IoReleaseCancelSpinLock(Irp->CancelIrql);
136 
137  // if list is freezed, dont start this packet
138  DPRINT("IrpListFreeze: %lu IrpPendingCount %lu\n", IrpListFreeze, FDODeviceExtension->IrpPendingCount);
139 
140  return (IrpListFreeze || SrbProcessing);
141 }
DRIVER_CANCEL * PDRIVER_CANCEL
Definition: iotypes.h:2739
_In_ WDFREQUEST Request
Definition: cdrom.h:1234
VOID NTAPI USBSTOR_CancelIo(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: queue.c:28
struct _SCSI_REQUEST_BLOCK * PSCSI_REQUEST_BLOCK
_In_ PIRP Irp
Definition: csq.h:116
#define BooleanFlagOn(F, SF)
Definition: ext2fs.h:183
LIST_ENTRY ListEntry
Definition: pci.h:83
VOID NTAPI IoAcquireCancelSpinLock(OUT PKIRQL Irql)
Definition: util.c:56
#define InsertTailList(ListHead, Entry)
IoSetCancelRoutine(Irp, CancelRoutine)
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
COMMON_DEVICE_EXTENSION Common
Definition: pci.h:81
VOID NTAPI IoReleaseCancelSpinLock(IN KIRQL Irql)
Definition: util.c:150
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define USBSTOR_FDO_FLAGS_IRP_LIST_FREEZE
Definition: usbstor.h:117
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3107
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
IoMarkIrpPending(Irp)
VOID NTAPI USBSTOR_Cancel(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: queue.c:51

◆ USBSTOR_QueueInitialize()

VOID USBSTOR_QueueInitialize ( PFDO_DEVICE_EXTENSION  FDODeviceExtension)

Definition at line 17 of file queue.c.

19 {
20  ASSERT(FDODeviceExtension->Common.IsFDO);
21  KeInitializeSpinLock(&FDODeviceExtension->IrpListLock);
22  InitializeListHead(&FDODeviceExtension->IrpListHead);
23  KeInitializeEvent(&FDODeviceExtension->NoPendingRequests, NotificationEvent, TRUE);
24 }
#define TRUE
Definition: types.h:120
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:238
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
COMMON_DEVICE_EXTENSION Common
Definition: pci.h:81
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944

◆ USBSTOR_QueueNextRequest()

VOID USBSTOR_QueueNextRequest ( IN PDEVICE_OBJECT  DeviceObject)

Definition at line 220 of file queue.c.

222 {
223  PFDO_DEVICE_EXTENSION FDODeviceExtension;
224  PIRP Irp;
225  PIO_STACK_LOCATION IoStack;
227 
228  FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
229  ASSERT(FDODeviceExtension->Common.IsFDO);
230 
231  // check first if there's already a request pending or the queue is frozen
232  if (FDODeviceExtension->ActiveSrb != NULL ||
234  {
235  // no work to do yet
236  return;
237  }
238 
239  // remove first irp from list
241 
242  // is there an irp pending
243  if (!Irp)
244  {
245  // no work to do
247  return;
248  }
249 
251  Request = (PSCSI_REQUEST_BLOCK)IoStack->Parameters.Others.Argument1;
252  ASSERT(Request);
253 
254  FDODeviceExtension->ActiveSrb = Request;
255 
256  // start next packet
259 }
_In_ WDFREQUEST Request
Definition: cdrom.h:1234
VOID NTAPI USBSTOR_CancelIo(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: queue.c:28
struct _SCSI_REQUEST_BLOCK * PSCSI_REQUEST_BLOCK
_In_ PIRP Irp
Definition: csq.h:116
#define TRUE
Definition: types.h:120
#define BooleanFlagOn(F, SF)
Definition: ext2fs.h:183
struct _FDO_DEVICE_EXTENSION * PFDO_DEVICE_EXTENSION
VOID NTAPI IoStartPacket(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PULONG Key, IN PDRIVER_CANCEL CancelFunction)
Definition: device.c:1876
smooth NULL
Definition: ftsmooth.c:416
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
COMMON_DEVICE_EXTENSION Common
Definition: pci.h:81
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
#define USBSTOR_FDO_FLAGS_IRP_LIST_FREEZE
Definition: usbstor.h:117
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3107
PIRP USBSTOR_RemoveIrp(IN PDEVICE_OBJECT DeviceObject)
Definition: queue.c:144
VOID NTAPI IoStartNextPacket(IN PDEVICE_OBJECT DeviceObject, IN BOOLEAN Cancelable)
Definition: device.c:1847

◆ USBSTOR_QueueRelease()

VOID USBSTOR_QueueRelease ( IN PDEVICE_OBJECT  DeviceObject)

Definition at line 262 of file queue.c.

264 {
265  PFDO_DEVICE_EXTENSION FDODeviceExtension;
266  PIRP Irp;
267  KIRQL OldLevel;
268  PIO_STACK_LOCATION IoStack;
270 
271  FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
272  ASSERT(FDODeviceExtension->Common.IsFDO);
273 
274  KeAcquireSpinLock(&FDODeviceExtension->IrpListLock, &OldLevel);
275 
276  // clear freezed status
277  FDODeviceExtension->Flags &= ~USBSTOR_FDO_FLAGS_IRP_LIST_FREEZE;
278 
279  KeReleaseSpinLock(&FDODeviceExtension->IrpListLock, OldLevel);
280 
281  // grab newest irp
283 
284  if (!Irp)
285  {
286  return;
287  }
288 
290  Request = (PSCSI_REQUEST_BLOCK)IoStack->Parameters.Others.Argument1;
291 
293  Irp,
294  &Request->QueueSortKey,
296 }
_In_ WDFREQUEST Request
Definition: cdrom.h:1234
VOID NTAPI USBSTOR_CancelIo(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: queue.c:28
struct _SCSI_REQUEST_BLOCK * PSCSI_REQUEST_BLOCK
_In_ PIRP Irp
Definition: csq.h:116
struct _FDO_DEVICE_EXTENSION * PFDO_DEVICE_EXTENSION
UCHAR KIRQL
Definition: env_spec_w32.h:591
VOID NTAPI IoStartPacket(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PULONG Key, IN PDRIVER_CANCEL CancelFunction)
Definition: device.c:1876
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
COMMON_DEVICE_EXTENSION Common
Definition: pci.h:81
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define USBSTOR_FDO_FLAGS_IRP_LIST_FREEZE
Definition: usbstor.h:117
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3107
PIRP USBSTOR_RemoveIrp(IN PDEVICE_OBJECT DeviceObject)
Definition: queue.c:144

◆ USBSTOR_QueueResetDevice()

VOID NTAPI USBSTOR_QueueResetDevice ( IN PFDO_DEVICE_EXTENSION  FDODeviceExtension)

Definition at line 148 of file error.c.

150 {
151  KIRQL OldIrql;
152 
153  DPRINT("USBSTOR_QueueResetDevice\n");
154 
155  KeAcquireSpinLock(&FDODeviceExtension->CommonLock, &OldIrql);
156  FDODeviceExtension->Flags |= USBSTOR_FDO_FLAGS_DEVICE_RESETTING;
157  KeReleaseSpinLock(&FDODeviceExtension->CommonLock, OldIrql);
158 
159  IoQueueWorkItem(FDODeviceExtension->ResetDeviceWorkItem,
162  NULL);
163 }
UCHAR KIRQL
Definition: env_spec_w32.h:591
VOID NTAPI USBSTOR_ResetDeviceWorkItemRoutine(IN PDEVICE_OBJECT FdoDevice, IN PVOID Context)
Definition: error.c:93
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
#define USBSTOR_FDO_FLAGS_DEVICE_RESETTING
Definition: usbstor.h:116
VOID NTAPI IoQueueWorkItem(IN PIO_WORKITEM IoWorkItem, IN PIO_WORKITEM_ROUTINE WorkerRoutine, IN WORK_QUEUE_TYPE QueueType, IN PVOID Context)
Definition: iowork.c:40
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627

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

◆ USBSTOR_QueueResetPipe()

VOID NTAPI USBSTOR_QueueResetPipe ( IN PFDO_DEVICE_EXTENSION  FDODeviceExtension)

Definition at line 135 of file error.c.

137 {
138  DPRINT("USBSTOR_QueueResetPipe\n");
139 
140  IoQueueWorkItem(FDODeviceExtension->ResetDeviceWorkItem,
143  FDODeviceExtension);
144 }
VOID NTAPI USBSTOR_ResetPipeWorkItemRoutine(IN PDEVICE_OBJECT FdoDevice, IN PVOID Ctx)
Definition: error.c:75
void DPRINT(...)
Definition: polytest.cpp:61
VOID NTAPI IoQueueWorkItem(IN PIO_WORKITEM IoWorkItem, IN PIO_WORKITEM_ROUTINE WorkerRoutine, IN WORK_QUEUE_TYPE QueueType, IN PVOID Context)
Definition: iowork.c:40

Referenced by USBSTOR_CSWCompletionRoutine(), and USBSTOR_DataCompletionRoutine().

◆ USBSTOR_QueueTerminateRequest()

VOID USBSTOR_QueueTerminateRequest ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 186 of file queue.c.

189 {
190  KIRQL OldLevel;
191  PFDO_DEVICE_EXTENSION FDODeviceExtension;
193  PSCSI_REQUEST_BLOCK Request = (PSCSI_REQUEST_BLOCK)IoStack->Parameters.Others.Argument1;
194 
195  FDODeviceExtension = (PFDO_DEVICE_EXTENSION)FDODeviceObject->DeviceExtension;
196  ASSERT(FDODeviceExtension->Common.IsFDO);
197 
198  KeAcquireSpinLock(&FDODeviceExtension->IrpListLock, &OldLevel);
199 
200  FDODeviceExtension->IrpPendingCount--;
201 
202  // check if this was our current active SRB
203  if (FDODeviceExtension->ActiveSrb == Request)
204  {
205  // indicate processing is completed
206  FDODeviceExtension->ActiveSrb = NULL;
207  }
208 
209  // Set the event if nothing else is pending
210  if (FDODeviceExtension->IrpPendingCount == 0 &&
211  FDODeviceExtension->ActiveSrb == NULL)
212  {
213  KeSetEvent(&FDODeviceExtension->NoPendingRequests, IO_NO_INCREMENT, FALSE);
214  }
215 
216  KeReleaseSpinLock(&FDODeviceExtension->IrpListLock, OldLevel);
217 }
_In_ WDFREQUEST Request
Definition: cdrom.h:1234
struct _SCSI_REQUEST_BLOCK * PSCSI_REQUEST_BLOCK
_In_ PIRP Irp
Definition: csq.h:116
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:416
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
COMMON_DEVICE_EXTENSION Common
Definition: pci.h:81
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define IO_NO_INCREMENT
Definition: iotypes.h:581
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3107

◆ USBSTOR_QueueWaitForPendingRequests()

VOID USBSTOR_QueueWaitForPendingRequests ( IN PDEVICE_OBJECT  DeviceObject)

Definition at line 171 of file queue.c.

173 {
174  PFDO_DEVICE_EXTENSION FDODeviceExtension;
175 
176  FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
177 
178  KeWaitForSingleObject(&FDODeviceExtension->NoPendingRequests,
179  Executive,
180  KernelMode,
181  FALSE,
182  NULL);
183 }
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
struct _FDO_DEVICE_EXTENSION * PFDO_DEVICE_EXTENSION
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:416
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464

◆ USBSTOR_ResetDevice()

NTSTATUS USBSTOR_ResetDevice ( IN PDEVICE_OBJECT  DeviceObject,
IN PFDO_DEVICE_EXTENSION  DeviceExtension 
)

Definition at line 250 of file misc.c.

253 {
255 
256  Status = USBSTOR_ClassRequest(DeviceObject, DeviceExtension, USB_BULK_RESET_DEVICE, DeviceExtension->InterfaceInformation->InterfaceNumber, USBD_TRANSFER_DIRECTION_OUT, 0, NULL);
257  return Status;
258 }
#define USB_BULK_RESET_DEVICE
Definition: usbstor.h:55
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS USBSTOR_ClassRequest(IN PDEVICE_OBJECT DeviceObject, IN PFDO_DEVICE_EXTENSION DeviceExtension, IN UCHAR RequestType, IN USHORT Index, IN ULONG TransferFlags, IN ULONG TransferBufferLength, IN PVOID TransferBuffer)
Definition: misc.c:170
#define USBD_TRANSFER_DIRECTION_OUT
Definition: usb.h:159
smooth NULL
Definition: ftsmooth.c:416
Status
Definition: gdiplustypes.h:24
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464

◆ USBSTOR_ResetPipeWithHandle()

NTSTATUS USBSTOR_ResetPipeWithHandle ( IN PDEVICE_OBJECT  DeviceObject,
IN USBD_PIPE_HANDLE  PipeHandle 
)

Definition at line 46 of file error.c.

49 {
50  PURB Urb;
52 
53  DPRINT("Allocating URB\n");
54  Urb = (PURB)AllocateItem(NonPagedPool, sizeof(struct _URB_PIPE_REQUEST));
55  if (!Urb)
56  {
57  DPRINT1("OutofMemory!\n");
59  }
60 
61  Urb->UrbPipeRequest.Hdr.Length = sizeof(struct _URB_PIPE_REQUEST);
63  Urb->UrbPipeRequest.PipeHandle = PipeHandle;
64 
65  // send the request
66  DPRINT1("Sending Request DeviceObject %p, Urb %p\n", DeviceObject, Urb);
68 
69  FreeItem(Urb);
70  return Status;
71 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
Definition: misc.c:30
LONG NTSTATUS
Definition: precomp.h:26
VOID FreeItem(IN PVOID Item)
Definition: misc.c:43
void DPRINT(...)
Definition: polytest.cpp:61
#define URB_FUNCTION_SYNC_RESET_PIPE_AND_CLEAR_STALL
Definition: usb.h:116
struct _URB_PIPE_REQUEST UrbPipeRequest
Definition: usb.h:534
Status
Definition: gdiplustypes.h:24
struct _URB * PURB
Definition: usb.h:529
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
static HANDLE PipeHandle
Definition: dhcpcsvc.c:21
NTSTATUS USBSTOR_SyncUrbRequest(IN PDEVICE_OBJECT DeviceObject, OUT PURB UrbRequest)
Definition: misc.c:107
#define DPRINT1
Definition: precomp.h:8

◆ USBSTOR_SelectConfigurationAndInterface()

NTSTATUS USBSTOR_SelectConfigurationAndInterface ( IN PDEVICE_OBJECT  DeviceObject,
IN PFDO_DEVICE_EXTENSION  DeviceExtension 
)

Definition at line 234 of file descriptor.c.

237 {
238  PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
239  PUSB_ENDPOINT_DESCRIPTOR InEndpointDescriptor, OutEndpointDescriptor;
241  PURB Urb;
243 
244  Status = USBSTOR_ScanConfigurationDescriptor(DeviceExtension->ConfigurationDescriptor, &InterfaceDescriptor, &InEndpointDescriptor, &OutEndpointDescriptor);
245  if (!NT_SUCCESS(Status))
246  {
247  return Status;
248  }
249 
250  // now allocate one interface entry and terminating null entry
252  if (!InterfaceList)
253  {
255  }
256 
257  // initialize interface list entry
258  InterfaceList[0].InterfaceDescriptor = InterfaceDescriptor;
259 
260  // now allocate the urb
261  Urb = USBD_CreateConfigurationRequestEx(DeviceExtension->ConfigurationDescriptor, InterfaceList);
262  if (!Urb)
263  {
266  }
267 
268 
270 
271  // submit urb
272  Status = USBSTOR_SyncUrbRequest(DeviceExtension->LowerDeviceObject, Urb);
273  if (!NT_SUCCESS(Status))
274  {
275  // failed to set configuration
276  DPRINT1("USBSTOR_SelectConfiguration failed to set interface %x\n", Status);
278  ExFreePoolWithTag(Urb, 0);
279  return Status;
280  }
281 
282  // backup interface information
283  DeviceExtension->InterfaceInformation = (PUSBD_INTERFACE_INFORMATION)AllocateItem(NonPagedPool, Urb->UrbSelectConfiguration.Interface.Length);
284  if (!DeviceExtension->InterfaceInformation)
285  {
287  ExFreePoolWithTag(Urb, 0);
289  }
290 
291  // copy interface information
292  RtlCopyMemory(DeviceExtension->InterfaceInformation, &Urb->UrbSelectConfiguration.Interface, Urb->UrbSelectConfiguration.Interface.Length);
293 
294  // store pipe handle
295  DeviceExtension->ConfigurationHandle = Urb->UrbSelectConfiguration.ConfigurationHandle;
296 
297  // now prepare interface urb
298  UsbBuildSelectInterfaceRequest(Urb, GET_SELECT_INTERFACE_REQUEST_SIZE(InterfaceDescriptor->bNumEndpoints), DeviceExtension->ConfigurationHandle, InterfaceDescriptor->bInterfaceNumber, InterfaceDescriptor->bAlternateSetting);
299 
300  // copy interface information structure back - as offset for SelectConfiguration / SelectInterface request do differ
301  RtlCopyMemory(&Urb->UrbSelectInterface.Interface, DeviceExtension->InterfaceInformation, DeviceExtension->InterfaceInformation->Length);
302 
303  // now select the interface
304  Status = USBSTOR_SyncUrbRequest(DeviceExtension->LowerDeviceObject, Urb);
305  if (NT_SUCCESS(Status))
306  {
307  // update configuration info
308  ASSERT(Urb->UrbSelectInterface.Interface.Length == DeviceExtension->InterfaceInformation->Length);
309  RtlCopyMemory(DeviceExtension->InterfaceInformation, &Urb->UrbSelectInterface.Interface, Urb->UrbSelectInterface.Interface.Length);
310  }
311 
313  ExFreePoolWithTag(Urb, 0);
314 
315  return Status;
316 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
struct _USBD_INTERFACE_LIST_ENTRY * PUSBD_INTERFACE_LIST_ENTRY
_In_ PUSBD_INTERFACE_LIST_ENTRY InterfaceList
Definition: usbdlib.h:181
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
Definition: misc.c:30
LONG NTSTATUS
Definition: precomp.h:26
#define GET_SELECT_INTERFACE_REQUEST_SIZE(totalPipes)
Definition: usbdlib.h:117
struct _USBD_INTERFACE_INFORMATION * PUSBD_INTERFACE_INFORMATION
Definition: usbdlib.h:7
VOID FreeItem(IN PVOID Item)
Definition: misc.c:43
NTSTATUS NTAPI USBSTOR_ScanConfigurationDescriptor(IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor, OUT PUSB_INTERFACE_DESCRIPTOR *OutInterfaceDescriptor, OUT PUSB_ENDPOINT_DESCRIPTOR *InEndpointDescriptor, OUT PUSB_ENDPOINT_DESCRIPTOR *OutEndpointDescriptor)
Definition: descriptor.c:140
IN PVOID IN PVOID IN USHORT IN USHORT IN PINTERFACE Interface
Definition: pci.h:361
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
struct _URB_SELECT_CONFIGURATION UrbSelectConfiguration
Definition: usb.h:533
PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor
Definition: usbdlib.h:8
Definition: usb.h:529
NTSTATUS USBSTOR_SyncUrbRequest(IN PDEVICE_OBJECT DeviceObject, OUT PURB UrbRequest)
Definition: misc.c:107
#define DPRINT1
Definition: precomp.h:8
#define UsbBuildSelectInterfaceRequest(urb, length, configurationHandle, interfaceNumber, alternateSetting)
Definition: usbdlib.h:59
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
PURB NTAPI USBD_CreateConfigurationRequestEx(PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor, PUSBD_INTERFACE_LIST_ENTRY InterfaceList)
Definition: usbd.c:329
struct _URB_SELECT_INTERFACE UrbSelectInterface
Definition: usb.h:532

◆ 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 }
_In_ PIRP Irp
Definition: csq.h:116
#define USBD_TRANSFER_DIRECTION_IN
Definition: usb.h:160
Definition: usbstor.h:86
IO_COMPLETION_ROUTINE USBSTOR_CSWCompletionRoutine
Definition: scsi.c:125
smooth NULL
Definition: ftsmooth.c:416
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

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

◆ USBSTOR_StartIo()

VOID NTAPI USBSTOR_StartIo ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 300 of file queue.c.

303 {
304  PIO_STACK_LOCATION IoStack;
306  PFDO_DEVICE_EXTENSION FDODeviceExtension;
307  PPDO_DEVICE_EXTENSION PDODeviceExtension;
308  KIRQL OldLevel;
309  BOOLEAN ResetInProgress;
310 
311  DPRINT("USBSTOR_StartIo\n");
312 
313  FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
314  ASSERT(FDODeviceExtension->Common.IsFDO);
315 
316  IoAcquireCancelSpinLock(&OldLevel);
317 
319 
320  // check if the irp has been cancelled
321  if (Irp->Cancel)
322  {
323  IoReleaseCancelSpinLock(OldLevel);
324 
325  Irp->IoStatus.Status = STATUS_CANCELLED;
326  Irp->IoStatus.Information = 0;
327 
331  return;
332  }
333 
334  IoReleaseCancelSpinLock(OldLevel);
335 
336  KeAcquireSpinLock(&FDODeviceExtension->CommonLock, &OldLevel);
337  ResetInProgress = BooleanFlagOn(FDODeviceExtension->Flags, USBSTOR_FDO_FLAGS_DEVICE_RESETTING);
338  KeReleaseSpinLock(&FDODeviceExtension->CommonLock, OldLevel);
339 
341 
342  PDODeviceExtension = (PPDO_DEVICE_EXTENSION)IoStack->DeviceObject->DeviceExtension;
343  Request = IoStack->Parameters.Scsi.Srb;
344  ASSERT(PDODeviceExtension->Common.IsFDO == FALSE);
345 
346  if (ResetInProgress)
347  {
348  // hard reset is in progress
349  Request->SrbStatus = SRB_STATUS_NO_DEVICE;
350  Request->DataTransferLength = 0;
351  Irp->IoStatus.Information = 0;
352  Irp->IoStatus.Status = STATUS_DEVICE_DOES_NOT_EXIST;
356  return;
357  }
358 
360 
361  // FIXME: handle error
362 }
#define STATUS_DEVICE_DOES_NOT_EXIST
Definition: ntstatus.h:428
_In_ WDFREQUEST Request
Definition: cdrom.h:1234
_In_ PIRP Irp
Definition: csq.h:116
#define BooleanFlagOn(F, SF)
Definition: ext2fs.h:183
VOID NTAPI IoAcquireCancelSpinLock(OUT PKIRQL Irql)
Definition: util.c:56
struct _PDO_DEVICE_EXTENSION * PPDO_DEVICE_EXTENSION
#define SRB_STATUS_NO_DEVICE
Definition: srb.h:340
IoSetCancelRoutine(Irp, CancelRoutine)
struct _FDO_DEVICE_EXTENSION * PFDO_DEVICE_EXTENSION
UCHAR KIRQL
Definition: env_spec_w32.h:591
VOID USBSTOR_QueueNextRequest(IN PDEVICE_OBJECT DeviceObject)
Definition: queue.c:220
#define FALSE
Definition: types.h:117
PVOID DeviceExtension
Definition: env_spec_w32.h:418
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
COMMON_DEVICE_EXTENSION Common
Definition: pci.h:56
void DPRINT(...)
Definition: polytest.cpp:61
VOID USBSTOR_QueueTerminateRequest(IN PDEVICE_OBJECT FDODeviceObject, IN PIRP Irp)
Definition: queue.c:186
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:3202
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define USBSTOR_FDO_FLAGS_DEVICE_RESETTING
Definition: usbstor.h:116
COMMON_DEVICE_EXTENSION Common
Definition: pci.h:81
VOID NTAPI IoReleaseCancelSpinLock(IN KIRQL Irql)
Definition: util.c:150
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
NTSTATUS USBSTOR_HandleExecuteSCSI(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: scsi.c:540
#define IO_NO_INCREMENT
Definition: iotypes.h:581
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3107

◆ USBSTOR_SyncForwardIrp()

NTSTATUS NTAPI USBSTOR_SyncForwardIrp ( IN PDEVICE_OBJECT  DeviceObject,
IN OUT PIRP  Irp 
)

◆ USBSTOR_SyncForwardIrpCompletionRoutine()

NTSTATUS NTAPI USBSTOR_SyncForwardIrpCompletionRoutine ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp,
PVOID  Context 
)

Definition at line 22 of file misc.c.

26 {
27  if (Irp->PendingReturned)
28  {
30  }
32 }
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:68
_In_ PIRP Irp
Definition: csq.h:116
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
#define FALSE
Definition: types.h:117
#define IO_NO_INCREMENT
Definition: iotypes.h:581

◆ USBSTOR_SyncUrbRequest()

NTSTATUS USBSTOR_SyncUrbRequest ( IN PDEVICE_OBJECT  DeviceObject,
OUT PURB  UrbRequest 
)

Definition at line 107 of file misc.c.

110 {
111  PIRP Irp;
112  PIO_STACK_LOCATION IoStack;
113  KEVENT Event;
115 
116  Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
117  if (!Irp)
118  {
120  }
121 
123 
124  IoStack = IoGetNextIrpStackLocation(Irp);
125 
126  // initialize stack location
128  IoStack->Parameters.DeviceIoControl.IoControlCode = IOCTL_INTERNAL_USB_SUBMIT_URB;
129  IoStack->Parameters.Others.Argument1 = (PVOID)UrbRequest;
130  IoStack->Parameters.DeviceIoControl.InputBufferLength = UrbRequest->UrbHeader.Length;
131  Irp->IoStatus.Status = STATUS_SUCCESS;
132 
134 
136 
137  if (Status == STATUS_PENDING)
138  {
140  Status = Irp->IoStatus.Status;
141  }
142 
143  IoFreeIrp(Irp);
144  return Status;
145 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define IOCTL_INTERNAL_USB_SUBMIT_URB
Definition: usbioctl.h:32
_In_ PIRP Irp
Definition: csq.h:116
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:498
#define FALSE
Definition: types.h:117
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:450
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS NTAPI USBSTOR_SyncForwardIrpCompletionRoutine(PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Context)
Definition: misc.c:22
#define STATUS_PENDING
Definition: ntstatus.h:82
#define IRP_MJ_INTERNAL_DEVICE_CONTROL
Status
Definition: gdiplustypes.h:24
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2691
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
VOID NTAPI IoFreeIrp(IN PIRP Irp)
Definition: irp.c:1666
static PVOID
Definition: misc.c:50
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
Definition: irp.c:615
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3107
return STATUS_SUCCESS
Definition: btrfs.c:3014

◆ USBSTOR_TimerRoutine()

VOID NTAPI USBSTOR_TimerRoutine ( PDEVICE_OBJECT  DeviceObject,
PVOID  Context 
)

Definition at line 205 of file error.c.

208 {
209  PFDO_DEVICE_EXTENSION FDODeviceExtension;
211  PERRORHANDLER_WORKITEM_DATA WorkItemData;
212 
213  FDODeviceExtension = (PFDO_DEVICE_EXTENSION)Context;
214  DPRINT1("[USBSTOR] TimerRoutine entered\n");
215  // DPRINT1("[USBSTOR] ActiveSrb %p ResetInProgress %x LastTimerActiveSrb %p\n", FDODeviceExtension->ActiveSrb, FDODeviceExtension->ResetInProgress, FDODeviceExtension->LastTimerActiveSrb);
216 
217  KeAcquireSpinLockAtDpcLevel(&FDODeviceExtension->IrpListLock);
218 
219  // is there an active srb and no global reset is in progress
220  if (FDODeviceExtension->ActiveSrb && /* FDODeviceExtension->ResetInProgress == FALSE && */ FDODeviceExtension->TimerWorkQueueEnabled)
221  {
222  if (FDODeviceExtension->LastTimerActiveSrb != NULL && FDODeviceExtension->LastTimerActiveSrb == FDODeviceExtension->ActiveSrb)
223  {
224  // check if empty
225  DPRINT1("[USBSTOR] ActiveSrb %p hang detected\n", FDODeviceExtension->ActiveSrb);
226  ResetDevice = TRUE;
227  }
228  else
229  {
230  // update pointer
231  FDODeviceExtension->LastTimerActiveSrb = FDODeviceExtension->ActiveSrb;
232  }
233  }
234  else
235  {
236  // reset srb
237  FDODeviceExtension->LastTimerActiveSrb = NULL;
238  }
239 
240  KeReleaseSpinLockFromDpcLevel(&FDODeviceExtension->IrpListLock);
241 
242 
243  if (ResetDevice && FDODeviceExtension->TimerWorkQueueEnabled && FDODeviceExtension->SrbErrorHandlingActive == FALSE)
244  {
245  WorkItemData = ExAllocatePoolWithTag(NonPagedPool,
247  USB_STOR_TAG);
248  if (WorkItemData)
249  {
250  // Initialize and queue the work item to handle the error
251  ExInitializeWorkItem(&WorkItemData->WorkQueueItem,
253  WorkItemData);
254 
255  WorkItemData->DeviceObject = FDODeviceExtension->FunctionalDeviceObject;
256 
257  DPRINT1("[USBSTOR] Queing Timer WorkItem\n");
259  }
260  }
261 }
VOID NTAPI ExQueueWorkItem(IN PWORK_QUEUE_ITEM WorkItem, IN WORK_QUEUE_TYPE QueueType)
Definition: work.c:717
#define TRUE
Definition: types.h:120
DWORD ResetDevice(DWORD private_handle)
VOID NTAPI KeAcquireSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:192
WORK_QUEUE_ITEM WorkQueueItem
Definition: usbstor.h:168
struct _FDO_DEVICE_EXTENSION * PFDO_DEVICE_EXTENSION
PDEVICE_OBJECT DeviceObject
Definition: usbstor.h:166
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define ExInitializeWorkItem(Item, Routine, Context)
Definition: exfuncs.h:265
VOID NTAPI KeReleaseSpinLockFromDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:215
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define USB_STOR_TAG
Definition: usbstor.h:10
#define DPRINT1
Definition: precomp.h:8
VOID NTAPI USBSTOR_TimerWorkerRoutine(IN PVOID Context)
Definition: error.c:167