ReactOS 0.4.15-dev-7670-g69b08be
usbstor.h File Reference
#include <wdm.h>
#include <ntstrsafe.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
 
struct  _STORAGE_ADAPTER_DESCRIPTOR_WIN8
 

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
 
typedef struct _STORAGE_ADAPTER_DESCRIPTOR_WIN8 STORAGE_ADAPTER_DESCRIPTOR_WIN8
 
typedef struct _STORAGE_ADAPTER_DESCRIPTOR_WIN8PSTORAGE_ADAPTER_DESCRIPTOR_WIN8
 

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_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 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 14 of file usbstor.h.

◆ CBW_SIGNATURE

#define CBW_SIGNATURE   0x43425355

Definition at line 65 of file usbstor.h.

◆ CSW_SIGNATURE

#define CSW_SIGNATURE   0x53425355

Definition at line 66 of file usbstor.h.

◆ CSW_STATUS_COMMAND_FAILED

#define CSW_STATUS_COMMAND_FAILED   0x01

Definition at line 84 of file usbstor.h.

◆ CSW_STATUS_COMMAND_PASSED

#define CSW_STATUS_COMMAND_PASSED   0x00

Definition at line 83 of file usbstor.h.

◆ CSW_STATUS_PHASE_ERROR

#define CSW_STATUS_PHASE_ERROR   0x02

Definition at line 85 of file usbstor.h.

◆ MAX_LUN

#define MAX_LUN   0xF

Definition at line 62 of file usbstor.h.

◆ SrbGetCdb

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

Definition at line 18 of file usbstor.h.

◆ USB_BULK_GET_MAX_LUN

#define USB_BULK_GET_MAX_LUN   0xFE

Definition at line 55 of file usbstor.h.

◆ USB_BULK_RESET_DEVICE

#define USB_BULK_RESET_DEVICE   0xFF

Definition at line 56 of file usbstor.h.

◆ USB_MAXCHILDREN

#define USB_MAXCHILDREN   16

Definition at line 61 of file usbstor.h.

◆ USB_PROTOCOL_ALAUDA

#define USB_PROTOCOL_ALAUDA   0xF4

Definition at line 49 of file usbstor.h.

◆ USB_PROTOCOL_BULK

#define USB_PROTOCOL_BULK   0x50

Definition at line 39 of file usbstor.h.

◆ USB_PROTOCOL_CB

#define USB_PROTOCOL_CB   0x01

Definition at line 38 of file usbstor.h.

◆ USB_PROTOCOL_CBI

#define USB_PROTOCOL_CBI   0x00

Definition at line 37 of file usbstor.h.

◆ USB_PROTOCOL_DATAFAB

#define USB_PROTOCOL_DATAFAB   0xF2

Definition at line 47 of file usbstor.h.

◆ USB_PROTOCOL_DPCM_USB

#define USB_PROTOCOL_DPCM_USB   0xF0

Definition at line 45 of file usbstor.h.

◆ USB_PROTOCOL_EUSB_SDDR09

#define USB_PROTOCOL_EUSB_SDDR09   0x81

Definition at line 42 of file usbstor.h.

◆ USB_PROTOCOL_FREECOM

#define USB_PROTOCOL_FREECOM   0xF1

Definition at line 46 of file usbstor.h.

◆ USB_PROTOCOL_JUMPSHOT

#define USB_PROTOCOL_JUMPSHOT   0xF3

Definition at line 48 of file usbstor.h.

◆ USB_PROTOCOL_KARMA

#define USB_PROTOCOL_KARMA   0xF5

Definition at line 50 of file usbstor.h.

◆ USB_PROTOCOL_SDDR55

#define USB_PROTOCOL_SDDR55   0x82

Definition at line 43 of file usbstor.h.

◆ USB_PROTOCOL_UAS

#define USB_PROTOCOL_UAS   0x62

Definition at line 40 of file usbstor.h.

◆ USB_PROTOCOL_USBAT

#define USB_PROTOCOL_USBAT   0x80

Definition at line 41 of file usbstor.h.

◆ USB_PROTOCOL_VENDOR

#define USB_PROTOCOL_VENDOR   0xFF

Definition at line 51 of file usbstor.h.

◆ USB_RECOVERABLE_ERRORS

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

Definition at line 58 of file usbstor.h.

◆ USB_STOR_TAG

#define USB_STOR_TAG   'sbsu'

Definition at line 11 of file usbstor.h.

◆ USB_SUBCLASS_8020

#define USB_SUBCLASS_8020   0x02

Definition at line 24 of file usbstor.h.

◆ USB_SUBCLASS_8070

#define USB_SUBCLASS_8070   0x05

Definition at line 27 of file usbstor.h.

◆ USB_SUBCLASS_CYP_ATACB

#define USB_SUBCLASS_CYP_ATACB   0xF1

Definition at line 32 of file usbstor.h.

◆ USB_SUBCLASS_ISD200

#define USB_SUBCLASS_ISD200   0xF0

Definition at line 31 of file usbstor.h.

◆ USB_SUBCLASS_LOCKABLE

#define USB_SUBCLASS_LOCKABLE   0x07

Definition at line 29 of file usbstor.h.

◆ USB_SUBCLASS_QIC

#define USB_SUBCLASS_QIC   0x03

Definition at line 25 of file usbstor.h.

◆ USB_SUBCLASS_RBC

#define USB_SUBCLASS_RBC   0x01

Definition at line 23 of file usbstor.h.

◆ USB_SUBCLASS_SCSI

#define USB_SUBCLASS_SCSI   0x06

Definition at line 28 of file usbstor.h.

◆ USB_SUBCLASS_UFI

#define USB_SUBCLASS_UFI   0x04

Definition at line 26 of file usbstor.h.

◆ USB_SUBCLASS_VENDOR

#define USB_SUBCLASS_VENDOR   0xFF

Definition at line 33 of file usbstor.h.

◆ USBSTOR_DEFAULT_MAX_TRANSFER_LENGTH

#define USBSTOR_DEFAULT_MAX_TRANSFER_LENGTH   0x10000

Definition at line 63 of file usbstor.h.

◆ USBSTOR_FDO_FLAGS_DEVICE_RESETTING

#define USBSTOR_FDO_FLAGS_DEVICE_RESETTING   0x00000001

Definition at line 117 of file usbstor.h.

◆ USBSTOR_FDO_FLAGS_IRP_LIST_FREEZE

#define USBSTOR_FDO_FLAGS_IRP_LIST_FREEZE   0x00000002

Definition at line 118 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

◆ PSTORAGE_ADAPTER_DESCRIPTOR_WIN8

◆ PUSBSTOR_COMMON_DEVICE_EXTENSION

◆ STORAGE_ADAPTER_DESCRIPTOR_WIN8

◆ USBSTOR_COMMON_DEVICE_EXTENSION

Function Documentation

◆ AllocateItem()

PVOID AllocateItem ( IN POOL_TYPE  PoolType,
IN ULONG  ItemSize 
)

Definition at line 29 of file misc.c.

32{
33 return ExAllocatePoolZero(PoolType, NumberOfBytes, TAG_KS);
34}
#define TAG_KS
Definition: misc.c:14
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ _Strict_type_match_ POOL_TYPE PoolType
Definition: wdfdevice.h:3815
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS _Inout_ PLARGE_INTEGER NumberOfBytes
Definition: iotypes.h:1036

◆ C_ASSERT()

C_ASSERT ( sizeof(CBW = =31)

◆ FreeItem()

VOID FreeItem ( IN PVOID  Item)

Definition at line 37 of file misc.c.

39{
41}
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
_In_ WDFCOLLECTION _In_ WDFOBJECT Item

◆ 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
struct _FDO_DEVICE_EXTENSION * PFDO_DEVICE_EXTENSION
#define ASSERT_IRQL_EQUAL(x)
Definition: debug.h:43
VOID USBSTOR_QueueTerminateRequest(IN PDEVICE_OBJECT FDODeviceObject, IN PIRP Irp)
Definition: queue.c:186
VOID USBSTOR_QueueNextRequest(IN PDEVICE_OBJECT DeviceObject)
Definition: queue.c:220
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
#define ASSERT(a)
Definition: mode.c:44
#define IoCompleteRequest
Definition: irp.c:1240
VOID NTAPI IoReleaseCancelSpinLock(IN KIRQL Irql)
Definition: util.c:150
COMMON_DEVICE_EXTENSION Common
Definition: pci.h:84
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define IO_NO_INCREMENT
Definition: iotypes.h:598

◆ USBSTOR_CreatePDO()

NTSTATUS USBSTOR_CreatePDO ( IN PDEVICE_OBJECT  DeviceObject,
IN UCHAR  LUN 
)

Definition at line 864 of file pdo.c.

867{
868 PDEVICE_OBJECT PDO;
870 PPDO_DEVICE_EXTENSION PDODeviceExtension;
871 PFDO_DEVICE_EXTENSION FDODeviceExtension;
872 PINQUIRYDATA InquiryData;
873
874 FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
875
876 // create child device object
878 if (!NT_SUCCESS(Status))
879 {
880 DPRINT1("Failed to create PDO, status %x\n", Status);
881 return Status;
882 }
883
884 // patch the stack size
885 PDO->StackSize = DeviceObject->StackSize;
886
887 PDODeviceExtension = (PPDO_DEVICE_EXTENSION)PDO->DeviceExtension;
888 InquiryData = (PINQUIRYDATA)&PDODeviceExtension->InquiryData;
889
890 // initialize device extension
891 RtlZeroMemory(PDODeviceExtension, sizeof(PDO_DEVICE_EXTENSION));
892 PDODeviceExtension->Common.IsFDO = FALSE;
893 PDODeviceExtension->LowerDeviceObject = DeviceObject;
894 PDODeviceExtension->PDODeviceObject = &FDODeviceExtension->ChildPDO[LUN];
895 PDODeviceExtension->Self = PDO;
896 PDODeviceExtension->LUN = LUN;
897
898 PDO->Flags |= DO_DIRECT_IO;
899
900 // device is initialized
901 PDO->Flags &= ~DO_DEVICE_INITIALIZING;
902
903 // output device object
904 FDODeviceExtension->ChildPDO[LUN] = PDO;
905
906 // send inquiry command by irp
908
909 if (!NT_SUCCESS(Status))
910 {
911 return Status;
912 }
913
914 if (InquiryData->DeviceType != DIRECT_ACCESS_DEVICE &&
916 {
918 }
919
920 return Status;
921}
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
#define DIRECT_ACCESS_DEVICE
Definition: cdrw_hw.h:1144
#define READ_ONLY_DIRECT_ACCESS_DEVICE
Definition: cdrw_hw.h:1149
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
struct _PDO_DEVICE_EXTENSION * PPDO_DEVICE_EXTENSION
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
Status
Definition: gdiplustypes.h:25
#define FILE_DEVICE_MASS_STORAGE
Definition: imports.h:62
#define FILE_AUTOGENERATED_DEVICE_NAME
Definition: iotypes.h:138
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 STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
PVOID DeviceExtension
Definition: env_spec_w32.h:418
UCHAR DeviceType
Definition: cdrw_hw.h:1116
COMMON_DEVICE_EXTENSION Common
Definition: pci.h:59
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
static NTSTATUS USBSTOR_FillInquiryData(IN PDEVICE_OBJECT PDODeviceObject)
Definition: pdo.c:824

◆ USBSTOR_FdoHandlePnp()

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

Definition at line 282 of file fdo.c.

285{
286 PIO_STACK_LOCATION IoStack;
287 PFDO_DEVICE_EXTENSION DeviceExtension;
289
291 DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
292 ASSERT(DeviceExtension->Common.IsFDO);
293
294 switch(IoStack->MinorFunction)
295 {
297 {
298 DPRINT("IRP_MN_SURPRISE_REMOVAL %p\n", DeviceObject);
299 Irp->IoStatus.Status = STATUS_SUCCESS;
300
301 // forward irp to next device object
303 return IoCallDriver(DeviceExtension->LowerDeviceObject, Irp);
304 }
306 {
307 DPRINT("IRP_MN_QUERY_DEVICE_RELATIONS %p Type: %u\n", DeviceObject, IoStack->Parameters.QueryDeviceRelations.Type);
308 return USBSTOR_FdoHandleDeviceRelations(DeviceExtension, Irp);
309 }
311 {
312 DPRINT1("USBSTOR_FdoHandlePnp: IRP_MN_STOP_DEVICE unimplemented\n");
314 Irp->IoStatus.Status = STATUS_SUCCESS;
315
316 // forward irp to next device object
318 return IoCallDriver(DeviceExtension->LowerDeviceObject, Irp);
319 }
321 {
322 DPRINT("IRP_MN_REMOVE_DEVICE\n");
323
324 return USBSTOR_FdoHandleRemoveDevice(DeviceObject, DeviceExtension, Irp);
325 }
327 {
328 // FIXME: set custom capabilities
330 return IoCallDriver(DeviceExtension->LowerDeviceObject, Irp);
331 }
334 {
335 if (DeviceExtension->IrpPendingCount != 0 || DeviceExtension->ActiveSrb != NULL)
336 {
337 /* We have pending requests */
338 DPRINT1("Failing removal/stop request due to pending requests present\n");
340 }
341 else
342 {
343 /* We're all clear */
344 Irp->IoStatus.Status = STATUS_SUCCESS;
345
347 return IoCallDriver(DeviceExtension->LowerDeviceObject, Irp);
348 }
349 break;
350 }
352 {
354 break;
355 }
356 default:
357 {
358 // forward irp to next device object
360 return IoCallDriver(DeviceExtension->LowerDeviceObject, Irp);
361 }
362 }
363
364 if (Status != STATUS_PENDING)
365 {
366 Irp->IoStatus.Status = Status;
368 }
369
370 return Status;
371}
VOID NTAPI IoStopTimer(PDEVICE_OBJECT DeviceObject)
Definition: iotimer.c:166
#define IRP_MN_SURPRISE_REMOVAL
Definition: ntifs_ex.h:408
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define IoCallDriver
Definition: irp.c:1225
#define STATUS_PENDING
Definition: ntstatus.h:82
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3128
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
NTSTATUS USBSTOR_FdoHandleRemoveDevice(IN PDEVICE_OBJECT DeviceObject, IN PFDO_DEVICE_EXTENSION DeviceExtension, IN OUT PIRP Irp)
Definition: fdo.c:100
NTSTATUS USBSTOR_FdoHandleDeviceRelations(IN PFDO_DEVICE_EXTENSION DeviceExtension, IN OUT PIRP Irp)
Definition: fdo.c:41
NTSTATUS USBSTOR_FdoHandleStartDevice(IN PDEVICE_OBJECT DeviceObject, IN PFDO_DEVICE_EXTENSION DeviceExtension, IN OUT PIRP Irp)
Definition: fdo.c:152
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2793
#define IRP_MN_START_DEVICE
#define IRP_MN_REMOVE_DEVICE
#define IRP_MN_QUERY_DEVICE_RELATIONS
#define IRP_MN_QUERY_STOP_DEVICE
#define IRP_MN_QUERY_CAPABILITIES
#define IRP_MN_STOP_DEVICE
#define IRP_MN_QUERY_REMOVE_DEVICE

◆ USBSTOR_GetBusInterface()

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

Definition at line 33 of file misc.c.

36{
39 PIRP Irp;
42
44 ASSERT(BusInterface);
45
47
50 NULL,
51 0,
52 NULL,
53 &Event,
54 &IoStatus);
55 if (Irp == NULL)
56 {
58 }
59
60 // initialize request
62 Stack->MajorFunction = IRP_MJ_PNP;
63 Stack->MinorFunction = IRP_MN_QUERY_INTERFACE;
64 Stack->Parameters.QueryInterface.Size = sizeof(BUS_INTERFACE_STANDARD);
65 Stack->Parameters.QueryInterface.InterfaceType = (LPGUID)&USB_BUS_INTERFACE_USBDI_GUID;
66 Stack->Parameters.QueryInterface.Version = 2;
67 Stack->Parameters.QueryInterface.Interface = (PINTERFACE)BusInterface;
68 Stack->Parameters.QueryInterface.InterfaceSpecificData = NULL;
69 Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
70
72
74 {
76 Status = IoStatus.Status;
77 }
78
79 return Status;
80}
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
__in UCHAR __in POWER_STATE __in_opt PVOID __in PIO_STATUS_BLOCK IoStatus
Definition: mxum.h:159
#define KernelMode
Definition: asm.h:34
@ NotificationEvent
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
GUID * LPGUID
Definition: guiddef.h:81
struct _INTERFACE * PINTERFACE
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
Definition: wdfrequest.h:639
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2695
#define IRP_MN_QUERY_INTERFACE
struct _BUS_INTERFACE_STANDARD BUS_INTERFACE_STANDARD
@ Executive
Definition: ketypes.h:415

◆ 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, MAXIMUM_USB_STRING_LENGTH, 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}
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
VOID FreeItem(IN PVOID Item)
Definition: misc.c:37
unsigned short USHORT
Definition: pedump.c:61
#define USB_CONFIGURATION_DESCRIPTOR_TYPE
Definition: usb100.h:50
#define MAXIMUM_USB_STRING_LENGTH
Definition: usb100.h:43
#define USB_DEVICE_DESCRIPTOR_TYPE
Definition: usb100.h:49
#define USB_STRING_DESCRIPTOR_TYPE
Definition: usb100.h:51

◆ 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}
NTSTATUS USBSTOR_SyncUrbRequest(IN PDEVICE_OBJECT DeviceObject, OUT PURB UrbRequest)
Definition: misc.c:83
#define NonPagedPool
Definition: env_spec_w32.h:307
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
Definition: misc.c:29
Definition: usb.h:529
struct _URB * PURB
#define URB_FUNCTION_GET_STATUS_FROM_ENDPOINT
Definition: usb.h:107
#define UsbBuildGetStatusRequest(urb, op, index, transferBuffer, transferBufferMDL, link)
Definition: usbdlib.h:35
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413

◆ USBSTOR_GetMaxLUN()

NTSTATUS USBSTOR_GetMaxLUN ( IN PDEVICE_OBJECT  DeviceObject,
IN PFDO_DEVICE_EXTENSION  DeviceExtension 
)

Definition at line 173 of file misc.c.

176{
179
181 if (!Buffer)
182 {
184 }
185
186 Status = USBSTOR_ClassRequest(DeviceObject, DeviceExtension, USB_BULK_GET_MAX_LUN, DeviceExtension->InterfaceInformation->InterfaceNumber, USBD_TRANSFER_DIRECTION_IN, sizeof(UCHAR), Buffer);
187
188 DPRINT("MaxLUN: %x\n", *Buffer);
189
190 if (NT_SUCCESS(Status))
191 {
192 if (*Buffer > MAX_LUN)
193 {
194 // invalid response documented in usb mass storage specification
196 }
197 else
198 {
199 // store maxlun
200 DeviceExtension->MaxLUN = *Buffer;
201 }
202 }
203 else
204 {
205 // "USB Mass Storage Class. Bulk-Only Transport. Revision 1.0"
206 // 3.2 Get Max LUN (class-specific request) :
207 // Devices that do not support multiple LUNs may STALL this command.
208 USBSTOR_ResetDevice(DeviceExtension->LowerDeviceObject, DeviceExtension);
209
210 DeviceExtension->MaxLUN = 0;
212 }
213
215 return Status;
216}
Definition: bufpool.h:45
NTSTATUS USBSTOR_ResetDevice(IN PDEVICE_OBJECT DeviceObject, IN PFDO_DEVICE_EXTENSION DeviceExtension)
Definition: misc.c:219
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:139
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
unsigned char * PUCHAR
Definition: typedefs.h:53
#define STATUS_DEVICE_DATA_ERROR
Definition: udferr_usr.h:159
#define USBD_TRANSFER_DIRECTION_IN
Definition: usb.h:160
#define USB_BULK_GET_MAX_LUN
Definition: usbstor.h:55
#define MAX_LUN
Definition: usbstor.h:62
#define USB_STOR_TAG
Definition: usbstor.h:11
unsigned char UCHAR
Definition: xmlstorage.h:181

◆ 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}
unsigned char BOOLEAN
#define TRUE
Definition: types.h:120
#define STATUS_DEVICE_CONFIGURATION_ERROR
Definition: ntstatus.h:619
uint32_t ULONG
Definition: typedefs.h:59
#define USB_ENDPOINT_DIRECTION_IN(x)
Definition: usb100.h:76
@ UsbdPipeTypeBulk
Definition: usb.h:247
_In_ WDFCOLLECTION _In_ ULONG Index

◆ USBSTOR_HandleDeviceControl()

NTSTATUS USBSTOR_HandleDeviceControl ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 413 of file disk.c.

416{
417 PIO_STACK_LOCATION IoStack;
419 PPDO_DEVICE_EXTENSION PDODeviceExtension;
421 PSCSI_INQUIRY_DATA ScsiInquiryData;
422 PINQUIRYDATA InquiryData;
423
425
426 switch (IoStack->Parameters.DeviceIoControl.IoControlCode)
427 {
430 break;
432 DPRINT1("USBSTOR_HandleDeviceControl IOCTL_SCSI_PASS_THROUGH NOT implemented\n");
434 break;
436 DPRINT1("USBSTOR_HandleDeviceControl IOCTL_SCSI_PASS_THROUGH_DIRECT NOT implemented\n");
438 break;
440 DPRINT1("USBSTOR_HandleDeviceControl IOCTL_STORAGE_GET_MEDIA_SERIAL_NUMBER NOT implemented\n");
442 break;
444 {
446
447 // Legacy port capability query
448 if (IoStack->Parameters.DeviceIoControl.OutputBufferLength == sizeof(PVOID))
449 {
450 Capabilities = *((PVOID *)Irp->AssociatedIrp.SystemBuffer) = ExAllocatePoolWithTag(NonPagedPool,
451 sizeof(IO_SCSI_CAPABILITIES),
453 Irp->IoStatus.Information = sizeof(PVOID);
454 }
455 else
456 {
457 Capabilities = Irp->AssociatedIrp.SystemBuffer;
458 Irp->IoStatus.Information = sizeof(IO_SCSI_CAPABILITIES);
459 }
460
461 if (Capabilities)
462 {
463 Capabilities->MaximumTransferLength = USBSTOR_DEFAULT_MAX_TRANSFER_LENGTH;
464 Capabilities->MaximumPhysicalPages = USBSTOR_DEFAULT_MAX_TRANSFER_LENGTH / PAGE_SIZE + 1; // See CORE-10515 and CORE-10755
465 Capabilities->SupportedAsynchronousEvents = 0;
466 Capabilities->AlignmentMask = 0;
467 Capabilities->TaggedQueuing = FALSE;
468 Capabilities->AdapterScansDown = FALSE;
469 Capabilities->AdapterUsesPio = FALSE;
471 }
472 else
473 {
475 }
476
477 break;
478 }
480 {
481 PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
482 ASSERT(PDODeviceExtension);
483 ASSERT(PDODeviceExtension->Common.IsFDO == FALSE);
484
485 // get parameters
486 BusInfo = Irp->AssociatedIrp.SystemBuffer;
487 ScsiInquiryData = (PSCSI_INQUIRY_DATA)(BusInfo + 1);
488 InquiryData = (PINQUIRYDATA)ScsiInquiryData->InquiryData;
489
490
491 BusInfo->NumberOfBuses = 1;
492 BusInfo->BusData[0].NumberOfLogicalUnits = 1; //FIXME
493 BusInfo->BusData[0].InitiatorBusId = 0;
494 BusInfo->BusData[0].InquiryDataOffset = sizeof(SCSI_ADAPTER_BUS_INFO);
495
496 ScsiInquiryData->PathId = 0;
497 ScsiInquiryData->TargetId = 0;
498 ScsiInquiryData->Lun = PDODeviceExtension->LUN & MAX_LUN;
499 ScsiInquiryData->DeviceClaimed = PDODeviceExtension->Claimed;
500 ScsiInquiryData->InquiryDataLength = sizeof(INQUIRYDATA);
501 ScsiInquiryData->NextInquiryDataOffset = 0;
502
503 // Note: INQUIRYDATA structure is larger than INQUIRYDATABUFFERSIZE
504 RtlZeroMemory(InquiryData, sizeof(INQUIRYDATA));
505 RtlCopyMemory(InquiryData, &PDODeviceExtension->InquiryData, sizeof(PDODeviceExtension->InquiryData));
506
507 InquiryData->Versions = 0x04;
508 InquiryData->ResponseDataFormat = 0x02; // some devices set this to 1
509
510 Irp->IoStatus.Information = sizeof(SCSI_ADAPTER_BUS_INFO) + sizeof(SCSI_INQUIRY_DATA) + sizeof(INQUIRYDATA) - 1;
512
513 break;
514 }
516 {
517 PSCSI_ADDRESS Address = Irp->AssociatedIrp.SystemBuffer;
518
519 Address->Length = sizeof(SCSI_ADDRESS);
520 Address->PortNumber = 0;
521 Address->PathId = 0;
522 Address->TargetId = 0;
523 Address->Lun = (((PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->LUN & MAX_LUN);
524 Irp->IoStatus.Information = sizeof(SCSI_ADDRESS);
525
527
528 break;
529 }
530 default:
531 DPRINT("USBSTOR_HandleDeviceControl IoControl %x not supported\n", IoStack->Parameters.DeviceIoControl.IoControlCode);
533 break;
534 }
535
536 return Status;
537}
struct _INQUIRYDATA * PINQUIRYDATA
struct _INQUIRYDATA INQUIRYDATA
NTSTATUS USBSTOR_HandleQueryProperty(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: disk.c:221
#define PAGE_SIZE
Definition: env_spec_w32.h:49
_Must_inspect_result_ typedef _Out_ PHIDP_CAPS Capabilities
Definition: hidclass.h:103
#define IOCTL_STORAGE_QUERY_PROPERTY
Definition: ntddstor.h:178
#define IOCTL_STORAGE_GET_MEDIA_SERIAL_NUMBER
Definition: ntddstor.h:151
static WCHAR Address[46]
Definition: ping.c:68
#define IOCTL_SCSI_PASS_THROUGH
Definition: scsi_port.h:47
#define IOCTL_SCSI_GET_ADDRESS
Definition: scsi_port.h:52
#define IOCTL_SCSI_GET_CAPABILITIES
Definition: scsi_port.h:50
struct _SCSI_ADAPTER_BUS_INFO SCSI_ADAPTER_BUS_INFO
#define IOCTL_SCSI_PASS_THROUGH_DIRECT
Definition: scsi_port.h:51
struct _SCSI_INQUIRY_DATA * PSCSI_INQUIRY_DATA
struct _SCSI_ADDRESS SCSI_ADDRESS
#define IOCTL_SCSI_GET_INQUIRY_DATA
Definition: scsi_port.h:49
struct _IO_SCSI_CAPABILITIES IO_SCSI_CAPABILITIES
UCHAR Versions
Definition: cdrw_hw.h:1120
UCHAR ResponseDataFormat
Definition: cdrw_hw.h:1121
SCSI_BUS_DATA BusData[1]
Definition: scsi_port.h:106
ULONG InquiryDataOffset
Definition: scsi_port.h:98
UCHAR NumberOfLogicalUnits
Definition: scsi_port.h:96
UCHAR InitiatorBusId
Definition: scsi_port.h:97
UCHAR InquiryData[1]
Definition: scsi_port.h:119
ULONG NextInquiryDataOffset
Definition: scsi_port.h:118
ULONG InquiryDataLength
Definition: scsi_port.h:117
BOOLEAN DeviceClaimed
Definition: scsi_port.h:116
void * PVOID
Definition: typedefs.h:50
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define USBSTOR_DEFAULT_MAX_TRANSFER_LENGTH
Definition: usbstor.h:63

◆ 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}
static NTSTATUS USBSTOR_SendCBWRequest(IN PFDO_DEVICE_EXTENSION FDODeviceExtension, IN PIRP Irp)
Definition: scsi.c:456
#define SrbGetCdb(srb)
Definition: usbstor.h:18
_In_ WDFREQUEST Request
Definition: wdfdevice.h:547

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;
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
173 {
174 DPRINT1("SRB_FUNCTION_FLUSH / SRB_FUNCTION_FLUSH_QUEUE / SRB_FUNCTION_SHUTDOWN\n");
175
176 // wait for pending requests to finish
177 USBSTOR_QueueWaitForPendingRequests(PDODeviceExtension->LowerDeviceObject);
178
179 Request->SrbStatus = SRB_STATUS_SUCCESS;
181 break;
182 }
183 default:
184 {
185 //
186 // not supported
187 //
189 Request->SrbStatus = SRB_STATUS_ERROR;
190 }
191 }
192
193 Irp->IoStatus.Status = Status;
195 return Status;
196}
#define SCSIOP_MODE_SENSE
Definition: cdrw_hw.h:896
#define SRB_FUNCTION_RELEASE_DEVICE
Definition: srb.h:321
#define SRB_FUNCTION_CLAIM_DEVICE
Definition: srb.h:316
#define SRB_FUNCTION_RELEASE_QUEUE
Definition: srb.h:319
#define SRB_FUNCTION_EXECUTE_SCSI
Definition: srb.h:315
#define SRB_STATUS_PENDING
Definition: srb.h:340
#define SRB_FUNCTION_FLUSH
Definition: srb.h:323
#define SRB_FUNCTION_FLUSH_QUEUE
Definition: srb.h:329
#define SRB_FUNCTION_SHUTDOWN
Definition: srb.h:322
struct _SCSI_REQUEST_BLOCK * PSCSI_REQUEST_BLOCK
#define SRB_STATUS_ERROR
Definition: srb.h:344
#define SRB_STATUS_BUSY
Definition: srb.h:345
#define SRB_STATUS_SUCCESS
Definition: srb.h:341
static BOOLEAN IsRequestValid(PIRP Irp)
Definition: disk.c:19
BOOLEAN USBSTOR_QueueAddIrp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: queue.c:75
VOID USBSTOR_QueueRelease(IN PDEVICE_OBJECT DeviceObject)
Definition: queue.c:262
VOID USBSTOR_QueueWaitForPendingRequests(IN PDEVICE_OBJECT DeviceObject)
Definition: queue.c:171
VOID NTAPI USBSTOR_CancelIo(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: queue.c:28
IoMarkIrpPending(Irp)
VOID NTAPI IoStartPacket(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PULONG Key, IN PDRIVER_CANCEL CancelFunction)
Definition: device.c:1876
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_DEVICE_BUSY
Definition: udferr_usr.h:129

◆ USBSTOR_PdoHandlePnp()

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

Definition at line 534 of file pdo.c.

537{
538 PIO_STACK_LOCATION IoStack;
539 PPDO_DEVICE_EXTENSION DeviceExtension;
542 ULONG bDelete;
543
545 DeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
546 ASSERT(DeviceExtension->Common.IsFDO == FALSE);
547
548 switch(IoStack->MinorFunction)
549 {
551 {
553 break;
554 }
556 {
558 break;
559 }
560 case IRP_MN_QUERY_ID:
561 {
562 if (IoStack->Parameters.QueryId.IdType == BusQueryDeviceID)
563 {
565 break;
566 }
567 else if (IoStack->Parameters.QueryId.IdType == BusQueryHardwareIDs)
568 {
570 break;
571 }
572 else if (IoStack->Parameters.QueryId.IdType == BusQueryInstanceID)
573 {
575 break;
576 }
577 else if (IoStack->Parameters.QueryId.IdType == BusQueryCompatibleIDs)
578 {
580 break;
581 }
582
583 DPRINT1("USBSTOR_PdoHandlePnp: IRP_MN_QUERY_ID IdType %x unimplemented\n", IoStack->Parameters.QueryId.IdType);
585 Irp->IoStatus.Information = 0;
586 break;
587 }
589 {
590 DPRINT("IRP_MN_REMOVE_DEVICE\n");
591
592 if(*DeviceExtension->PDODeviceObject != NULL)
593 {
594 *DeviceExtension->PDODeviceObject = NULL;
595 bDelete = TRUE;
596 }
597 else
598 {
599 // device object already marked for deletion
600 bDelete = FALSE;
601 }
602
603 Irp->IoStatus.Status = STATUS_SUCCESS;
605
606 if (bDelete)
607 {
609 }
610 return STATUS_SUCCESS;
611 }
613 {
614 // just forward irp to lower device
616
617 if (IoForwardIrpSynchronously(DeviceExtension->LowerDeviceObject, Irp))
618 {
619 Status = Irp->IoStatus.Status;
621
622 if (NT_SUCCESS(Status))
623 {
624 // check if no unique id
625 Caps = (PDEVICE_CAPABILITIES)IoStack->Parameters.DeviceCapabilities.Capabilities;
626 Caps->UniqueID = FALSE; // no unique id is supported
627 Caps->Removable = TRUE; //FIXME
628 }
629 }
630 break;
631 }
634 {
635 if (DeviceExtension->Claimed)
636 {
638 DPRINT1("[USBSTOR] Request %x fails because device is still claimed\n", IoStack->MinorFunction);
639 }
640 else
642 break;
643 }
645 {
646 // no-op for PDO
648 break;
649 }
651 {
653 break;
654 }
655 default:
656 {
657 // do nothing
658 Status = Irp->IoStatus.Status;
659 }
660 }
661
662 if (Status != STATUS_PENDING)
663 {
664 Irp->IoStatus.Status = Status;
666 }
667
668 return Status;
669}
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
BOOLEAN NTAPI IoForwardIrpSynchronously(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1625
NTSTATUS USBSTOR_PdoHandleQueryInstanceId(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
Definition: pdo.c:434
NTSTATUS USBSTOR_PdoHandleQueryCompatibleId(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
Definition: pdo.c:394
NTSTATUS USBSTOR_PdoHandleQueryDeviceId(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: pdo.c:179
NTSTATUS USBSTOR_PdoHandleQueryHardwareId(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
Definition: pdo.c:267
NTSTATUS USBSTOR_PdoHandleDeviceRelations(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
Definition: pdo.c:500
NTSTATUS USBSTOR_PdoHandleQueryDeviceText(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: pdo.c:125
#define IRP_MN_QUERY_ID
#define IRP_MN_QUERY_DEVICE_TEXT
* PDEVICE_CAPABILITIES
Definition: iotypes.h:965
@ BusQueryCompatibleIDs
Definition: iotypes.h:2938
@ BusQueryInstanceID
Definition: iotypes.h:2939
@ BusQueryDeviceID
Definition: iotypes.h:2936
@ BusQueryHardwareIDs
Definition: iotypes.h:2937

◆ 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}
VOID NTAPI USBSTOR_Cancel(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: queue.c:51
#define InsertTailList(ListHead, Entry)
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
#define BooleanFlagOn(F, SF)
Definition: ext2fs.h:183
IoSetCancelRoutine(Irp, CancelRoutine)
VOID NTAPI IoAcquireCancelSpinLock(OUT PKIRQL Irql)
Definition: util.c:56
LIST_ENTRY ListEntry
Definition: pci.h:86
#define USBSTOR_FDO_FLAGS_IRP_LIST_FREEZE
Definition: usbstor.h:118
DRIVER_CANCEL * PDRIVER_CANCEL
Definition: iotypes.h:2759

◆ 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 InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define KeInitializeSpinLock(sl)
Definition: env_spec_w32.h:604

◆ 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;
253
254 FDODeviceExtension->ActiveSrb = Request;
255
256 // start next packet
259}
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}

◆ USBSTOR_QueueResetDevice()

VOID NTAPI USBSTOR_QueueResetDevice ( IN PFDO_DEVICE_EXTENSION  FDODeviceExtension)

Definition at line 148 of file error.c.

150{
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}
VOID NTAPI USBSTOR_ResetDeviceWorkItemRoutine(IN PDEVICE_OBJECT FdoDevice, IN PVOID Context)
Definition: error.c:93
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 USBSTOR_FDO_FLAGS_DEVICE_RESETTING
Definition: usbstor.h:117
@ CriticalWorkQueue
Definition: extypes.h:189
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778

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

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}
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476

◆ 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,
181 FALSE,
182 NULL);
183}

◆ USBSTOR_ResetDevice()

NTSTATUS USBSTOR_ResetDevice ( IN PDEVICE_OBJECT  DeviceObject,
IN PFDO_DEVICE_EXTENSION  DeviceExtension 
)

Definition at line 219 of file misc.c.

222{
224
225 Status = USBSTOR_ClassRequest(DeviceObject, DeviceExtension, USB_BULK_RESET_DEVICE, DeviceExtension->InterfaceInformation->InterfaceNumber, USBD_TRANSFER_DIRECTION_OUT, 0, NULL);
226 return Status;
227}
#define USBD_TRANSFER_DIRECTION_OUT
Definition: usb.h:159
#define USB_BULK_RESET_DEVICE
Definition: usbstor.h:56

◆ 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}
static HANDLE PipeHandle
Definition: dhcpcsvc.c:22
struct _URB_PIPE_REQUEST UrbPipeRequest
Definition: usb.h:534
#define URB_FUNCTION_SYNC_RESET_PIPE_AND_CLEAR_STALL
Definition: usb.h:116

◆ USBSTOR_SelectConfigurationAndInterface()

NTSTATUS USBSTOR_SelectConfigurationAndInterface ( IN PDEVICE_OBJECT  DeviceObject,
IN PFDO_DEVICE_EXTENSION  DeviceExtension 
)

Definition at line 234 of file descriptor.c.

237{
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
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}
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
#define PagedPool
Definition: env_spec_w32.h:308
struct _URB_SELECT_CONFIGURATION UrbSelectConfiguration
Definition: usb.h:533
struct _URB_SELECT_INTERFACE UrbSelectInterface
Definition: usb.h:532
Definition: usbdlib.h:7
PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor
Definition: usbdlib.h:8
struct _USBD_INTERFACE_INFORMATION * PUSBD_INTERFACE_INFORMATION
PURB NTAPI USBD_CreateConfigurationRequestEx(PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor, PUSBD_INTERFACE_LIST_ENTRY InterfaceList)
Definition: usbd.c:329
#define UsbBuildSelectInterfaceRequest(urb, length, configurationHandle, interfaceNumber, alternateSetting)
Definition: usbdlib.h:59
_In_ PUSBD_INTERFACE_LIST_ENTRY InterfaceList
Definition: usbdlib.h:181
#define GET_SELECT_INTERFACE_REQUEST_SIZE(totalPipes)
Definition: usbdlib.h:117
struct _USBD_INTERFACE_LIST_ENTRY * PUSBD_INTERFACE_LIST_ENTRY
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID _Out_ PINTERFACE Interface
Definition: wdffdo.h:465
_In_ WDFUSBINTERFACE _In_ UCHAR _Out_ PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor
Definition: wdfusb.h:2334

◆ 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
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 SRB_STATUS_NO_DEVICE
Definition: srb.h:348
#define STATUS_DEVICE_DOES_NOT_EXIST
Definition: ntstatus.h:428
PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:3223
NTSTATUS USBSTOR_HandleExecuteSCSI(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: scsi.c:540

◆ USBSTOR_SyncUrbRequest()

NTSTATUS USBSTOR_SyncUrbRequest ( IN PDEVICE_OBJECT  DeviceObject,
OUT PURB  UrbRequest 
)

Definition at line 83 of file misc.c.

86{
87 PIRP Irp;
88 PIO_STACK_LOCATION IoStack;
91
92 Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
93 if (!Irp)
94 {
96 }
97
99
101
102 // initialize stack location
104 IoStack->Parameters.DeviceIoControl.IoControlCode = IOCTL_INTERNAL_USB_SUBMIT_URB;
105 IoStack->Parameters.Others.Argument1 = (PVOID)UrbRequest;
106 IoStack->Parameters.DeviceIoControl.InputBufferLength = UrbRequest->UrbHeader.Length;
107 Irp->IoStatus.Status = STATUS_SUCCESS;
108
110
112
113 if (Status == STATUS_PENDING)
114 {
116 Status = Irp->IoStatus.Status;
117 }
118
119 IoFreeIrp(Irp);
120 return Status;
121}
NTSTATUS NTAPI USBSTOR_SyncForwardIrpCompletionRoutine(PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Context)
Definition: misc.c:22
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:490
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
Definition: irp.c:615
VOID NTAPI IoFreeIrp(IN PIRP Irp)
Definition: irp.c:1666
#define IOCTL_INTERNAL_USB_SUBMIT_URB
Definition: usbioctl.h:32
#define IRP_MJ_INTERNAL_DEVICE_CONTROL

◆ 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);
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,
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 USBSTOR_TimerWorkerRoutine(IN PVOID Context)
Definition: error.c:167
DWORD ResetDevice(DWORD private_handle)
#define KeAcquireSpinLockAtDpcLevel(SpinLock)
Definition: ke.h:125
#define KeReleaseSpinLockFromDpcLevel(SpinLock)
Definition: ke.h:135
PDEVICE_OBJECT DeviceObject
Definition: usbstor.h:167
WORK_QUEUE_ITEM WorkQueueItem
Definition: usbstor.h:169
VOID NTAPI ExQueueWorkItem(IN PWORK_QUEUE_ITEM WorkItem, IN WORK_QUEUE_TYPE QueueType)
Definition: work.c:723
#define ExInitializeWorkItem(Item, Routine, Context)
Definition: exfuncs.h:265
@ DelayedWorkQueue
Definition: extypes.h:190