ReactOS 0.4.15-dev-7953-g1f49173
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  __COMMON_DEVICE_EXTENSION__
 
struct  FDO_DEVICE_EXTENSION
 
struct  PDO_DEVICE_EXTENSION
 
struct  CBW
 
struct  CSW
 
struct  UFI_INQUIRY_CMD
 
struct  UFI_INQUIRY_RESPONSE
 
struct  UFI_READ_WRITE_CMD
 
struct  UFI_CAPACITY_CMD
 
struct  UFI_CAPACITY_RESPONSE
 
struct  UFI_SENSE_CMD
 
struct  UFI_MODE_PARAMETER_HEADER
 
struct  UFI_TIMER_PROTECT_PAGE
 
struct  UFI_READ_FORMAT_CAPACITY
 
struct  UFI_CAPACITY_FORMAT_HEADER
 
struct  UFI_CAPACITY_DESCRIPTOR
 
struct  UFI_TEST_UNIT_CMD
 
struct  UFI_UNKNOWN_CMD
 
struct  IRP_CONTEXT
 
struct  _ERRORHANDLER_WORKITEM_DATA
 

Macros

#define USB_STOR_TAG   'sbsu'
 
#define USB_MAXCHILDREN   (16)
 
#define HTONS(n)   (((((unsigned short)(n) & 0xFF)) << 8) | (((unsigned short)(n) & 0xFF00) >> 8))
 
#define NTOHS(n)   (((((unsigned short)(n) & 0xFF)) << 8) | (((unsigned short)(n) & 0xFF00) >> 8))
 
#define HTONL(n)
 
#define NTOHL(n)
 
#define USB_RECOVERABLE_ERRORS
 
#define USB_BULK_GET_MAX_LUN   0xFE
 
#define USB_BULK_RESET_DEVICE   0xFF
 
#define CBW_SIGNATURE   0x43425355
 
#define CSW_SIGNATURE   0x53425355
 
#define MAX_LUN   0xF
 
#define UFI_INQUIRY_CMD_LEN   0x6
 
#define UFI_READ_WRITE_CMD_LEN   (0xA)
 
#define UFI_CAPACITY_CMD_LEN   0xA
 
#define UFI_READ_CAPACITY_CMD_LEN   0xA
 
#define UFI_SENSE_CMD_LEN   (6)
 
#define UFI_READ_FORMAT_CAPACITY_CMD_LEN   (10)
 
#define UNFORMATTED_MEDIA_CODE_DESCRIPTORY_TYPE   (1)
 
#define FORMAT_MEDIA_CODE_DESCRIPTOR_TYPE   (2)
 
#define CARTRIDGE_MEDIA_CODE_DESCRIPTOR_TYPE   (3)
 
#define UFI_TEST_UNIT_CMD_LEN   (6)
 

Typedefs

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 CBWPCBW
 
typedef struct CSWPCSW
 
typedef struct UFI_INQUIRY_CMDPUFI_INQUIRY_CMD
 
typedef struct UFI_INQUIRY_RESPONSEPUFI_INQUIRY_RESPONSE
 
typedef struct UFI_CAPACITY_CMDPUFI_CAPACITY_CMD
 
typedef struct UFI_CAPACITY_RESPONSEPUFI_CAPACITY_RESPONSE
 
typedef struct UFI_SENSE_CMDPUFI_SENSE_CMD
 
typedef struct UFI_MODE_PARAMETER_HEADERPUFI_MODE_PARAMETER_HEADER
 
typedef struct UFI_TIMER_PROTECT_PAGEPUFI_TIMER_PROTECT_PAGE
 
typedef struct UFI_READ_FORMAT_CAPACITYPUFI_READ_FORMAT_CAPACITY
 
typedef struct UFI_CAPACITY_FORMAT_HEADERPUFI_CAPACITY_FORMAT_HEADER
 
typedef struct UFI_CAPACITY_DESCRIPTORPUFI_CAPACITY_DESCRIPTOR
 
typedef struct UFI_TEST_UNIT_CMDPUFI_TEST_UNIT_CMD
 
typedef struct UFI_UNKNOWN_CMDPUFI_UNKNOWN_CMD
 
typedef struct IRP_CONTEXTPIRP_CONTEXT
 
typedef struct _ERRORHANDLER_WORKITEM_DATA ERRORHANDLER_WORKITEM_DATA
 
typedef struct _ERRORHANDLER_WORKITEM_DATAPERRORHANDLER_WORKITEM_DATA
 

Functions

 C_ASSERT (sizeof(CBW)==31)
 
 C_ASSERT (sizeof(UFI_INQUIRY_CMD)==12)
 
 C_ASSERT (sizeof(UFI_INQUIRY_RESPONSE)==36)
 
 C_ASSERT (sizeof(UFI_READ_WRITE_CMD)==12)
 
 C_ASSERT (sizeof(UFI_CAPACITY_CMD)==12)
 
 C_ASSERT (sizeof(UFI_CAPACITY_RESPONSE)==8)
 
 C_ASSERT (sizeof(UFI_SENSE_CMD)==12)
 
 C_ASSERT (sizeof(UFI_MODE_PARAMETER_HEADER)==8)
 
 C_ASSERT (sizeof(UFI_TIMER_PROTECT_PAGE)==8)
 
 C_ASSERT (sizeof(UFI_READ_FORMAT_CAPACITY)==12)
 
 C_ASSERT (sizeof(UFI_CAPACITY_FORMAT_HEADER)==4)
 
 C_ASSERT (sizeof(UFI_TEST_UNIT_CMD)==12)
 
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)
 
BOOLEAN USBSTOR_IsFloppy (IN PUCHAR Buffer, IN ULONG BufferLength, OUT PUCHAR MediumTypeCode)
 
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, IN ULONG RetryCount)
 
NTSTATUS NTAPI USBSTOR_CSWCompletionRoutine (PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Ctx)
 
NTSTATUS USBSTOR_SendCBW (PIRP_CONTEXT Context, PIRP Irp)
 
VOID USBSTOR_SendCSW (PIRP_CONTEXT Context, 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 NTAPI ErrorHandlerWorkItemRoutine (PVOID Context)
 
VOID NTAPI ResetHandlerWorkItemRoutine (PVOID Context)
 
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)
 

Macro Definition Documentation

◆ CARTRIDGE_MEDIA_CODE_DESCRIPTOR_TYPE

#define CARTRIDGE_MEDIA_CODE_DESCRIPTOR_TYPE   (3)

Definition at line 288 of file usbstor.h.

◆ CBW_SIGNATURE

#define CBW_SIGNATURE   0x43425355

Definition at line 103 of file usbstor.h.

◆ CSW_SIGNATURE

#define CSW_SIGNATURE   0x53425355

Definition at line 104 of file usbstor.h.

◆ FORMAT_MEDIA_CODE_DESCRIPTOR_TYPE

#define FORMAT_MEDIA_CODE_DESCRIPTOR_TYPE   (2)

Definition at line 287 of file usbstor.h.

◆ HTONL

#define HTONL (   n)
Value:
(((((unsigned long)(n) & 0xFF)) << 24) | \
((((unsigned long)(n) & 0xFF00)) << 8) | \
((((unsigned long)(n) & 0xFF0000)) >> 8) | \
((((unsigned long)(n) & 0xFF000000)) >> 24))
GLdouble n
Definition: glext.h:7729
#define long
Definition: qsort.c:33

Definition at line 16 of file usbstor.h.

◆ HTONS

#define HTONS (   n)    (((((unsigned short)(n) & 0xFF)) << 8) | (((unsigned short)(n) & 0xFF00) >> 8))

Definition at line 13 of file usbstor.h.

◆ MAX_LUN

#define MAX_LUN   0xF

Definition at line 106 of file usbstor.h.

◆ NTOHL

#define NTOHL (   n)
Value:
(((((unsigned long)(n) & 0xFF)) << 24) | \
((((unsigned long)(n) & 0xFF00)) << 8) | \
((((unsigned long)(n) & 0xFF0000)) >> 8) | \
((((unsigned long)(n) & 0xFF000000)) >> 24))

Definition at line 22 of file usbstor.h.

◆ NTOHS

#define NTOHS (   n)    (((((unsigned short)(n) & 0xFF)) << 8) | (((unsigned short)(n) & 0xFF00) >> 8))

Definition at line 14 of file usbstor.h.

◆ UFI_CAPACITY_CMD_LEN

#define UFI_CAPACITY_CMD_LEN   0xA

Definition at line 190 of file usbstor.h.

◆ UFI_INQUIRY_CMD_LEN

#define UFI_INQUIRY_CMD_LEN   0x6

Definition at line 132 of file usbstor.h.

◆ UFI_READ_CAPACITY_CMD_LEN

#define UFI_READ_CAPACITY_CMD_LEN   0xA

Definition at line 201 of file usbstor.h.

◆ UFI_READ_FORMAT_CAPACITY_CMD_LEN

#define UFI_READ_FORMAT_CAPACITY_CMD_LEN   (10)

Definition at line 265 of file usbstor.h.

◆ UFI_READ_WRITE_CMD_LEN

#define UFI_READ_WRITE_CMD_LEN   (0xA)

Definition at line 172 of file usbstor.h.

◆ UFI_SENSE_CMD_LEN

#define UFI_SENSE_CMD_LEN   (6)

Definition at line 221 of file usbstor.h.

◆ UFI_TEST_UNIT_CMD_LEN

#define UFI_TEST_UNIT_CMD_LEN   (6)

Definition at line 307 of file usbstor.h.

◆ UNFORMATTED_MEDIA_CODE_DESCRIPTORY_TYPE

#define UNFORMATTED_MEDIA_CODE_DESCRIPTORY_TYPE   (1)

Definition at line 286 of file usbstor.h.

◆ USB_BULK_GET_MAX_LUN

#define USB_BULK_GET_MAX_LUN   0xFE

Definition at line 85 of file usbstor.h.

◆ USB_BULK_RESET_DEVICE

#define USB_BULK_RESET_DEVICE   0xFF

Definition at line 86 of file usbstor.h.

◆ USB_MAXCHILDREN

#define USB_MAXCHILDREN   (16)

Definition at line 11 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 27 of file usbstor.h.

◆ USB_STOR_TAG

#define USB_STOR_TAG   'sbsu'

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

◆ PUFI_CAPACITY_CMD

◆ PUFI_CAPACITY_DESCRIPTOR

◆ PUFI_CAPACITY_FORMAT_HEADER

◆ PUFI_CAPACITY_RESPONSE

◆ PUFI_INQUIRY_CMD

◆ PUFI_INQUIRY_RESPONSE

◆ PUFI_MODE_PARAMETER_HEADER

◆ PUFI_READ_FORMAT_CAPACITY

◆ PUFI_SENSE_CMD

◆ PUFI_TEST_UNIT_CMD

◆ PUFI_TIMER_PROTECT_PAGE

◆ PUFI_UNKNOWN_CMD

◆ PUSBSTOR_COMMON_DEVICE_EXTENSION

◆ 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() [1/12]

C_ASSERT ( sizeof(CBW = =31)

◆ C_ASSERT() [2/12]

C_ASSERT ( sizeof(UFI_CAPACITY_CMD = =12)

◆ C_ASSERT() [3/12]

C_ASSERT ( sizeof(UFI_CAPACITY_FORMAT_HEADER = =4)

◆ C_ASSERT() [4/12]

C_ASSERT ( sizeof(UFI_CAPACITY_RESPONSE = =8)

◆ C_ASSERT() [5/12]

C_ASSERT ( sizeof(UFI_INQUIRY_CMD = =12)

◆ C_ASSERT() [6/12]

C_ASSERT ( sizeof(UFI_INQUIRY_RESPONSE = =36)

◆ C_ASSERT() [7/12]

C_ASSERT ( sizeof(UFI_MODE_PARAMETER_HEADER = =8)

◆ C_ASSERT() [8/12]

C_ASSERT ( sizeof(UFI_READ_FORMAT_CAPACITY = =12)

◆ C_ASSERT() [9/12]

C_ASSERT ( sizeof(UFI_READ_WRITE_CMD = =12)

◆ C_ASSERT() [10/12]

C_ASSERT ( sizeof(UFI_SENSE_CMD = =12)

◆ C_ASSERT() [11/12]

C_ASSERT ( sizeof(UFI_TEST_UNIT_CMD = =12)

◆ C_ASSERT() [12/12]

C_ASSERT ( sizeof(UFI_TIMER_PROTECT_PAGE = =8)

◆ ErrorHandlerWorkItemRoutine()

VOID NTAPI ErrorHandlerWorkItemRoutine ( PVOID  Context)

Definition at line 248 of file error.c.

250{
252
253 if (WorkItemData->Context->ErrorIndex == 2)
254 {
255 //
256 // reset device
257 //
258 USBSTOR_HandleTransferError(WorkItemData->DeviceObject, WorkItemData->Context);
259 }
260 else
261 {
262 //
263 // clear stall
264 //
266 }
267
268 //
269 // Free Work Item Data
270 //
271 ExFreePoolWithTag(WorkItemData, USB_STOR_TAG);
272}
VOID NTAPI USBSTOR_ResetHandlerWorkItemRoutine(PVOID Context)
Definition: error.c:228
NTSTATUS USBSTOR_HandleTransferError(PDEVICE_OBJECT DeviceObject, PIRP_CONTEXT Context)
Definition: error.c:112
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
ULONG ErrorIndex
Definition: usbstor.h:100
PDEVICE_OBJECT DeviceObject
Definition: usbstor.h:167
#define USB_STOR_TAG
Definition: usbstor.h:11
struct _ERRORHANDLER_WORKITEM_DATA * PERRORHANDLER_WORKITEM_DATA

Referenced by USBSTOR_QueueWorkItem().

◆ FreeItem()

VOID FreeItem ( IN PVOID  Item)

Definition at line 37 of file misc.c.

39{
41}
_In_ WDFCOLLECTION _In_ WDFOBJECT Item

◆ ResetHandlerWorkItemRoutine()

VOID NTAPI ResetHandlerWorkItemRoutine ( PVOID  Context)

◆ 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

Referenced by USBSTOR_HandleInternalDeviceControl(), USBSTOR_QueueAddIrp(), USBSTOR_QueueNextRequest(), and USBSTOR_QueueRelease().

◆ 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

Referenced by USBSTOR_FdoHandleStartDevice().

◆ USBSTOR_CSWCompletionRoutine()

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

Definition at line 129 of file scsi.c.

133{
135 PIO_STACK_LOCATION IoStack;
136 PPDO_DEVICE_EXTENSION PDODeviceExtension;
137 PFDO_DEVICE_EXTENSION FDODeviceExtension;
139
140 DPRINT("USBSTOR_CSWCompletionRoutine Irp %p Ctx %p Status %x\n", Irp, Ctx, Irp->IoStatus.Status);
141
143 PDODeviceExtension = (PPDO_DEVICE_EXTENSION)IoStack->DeviceObject->DeviceExtension;
144 FDODeviceExtension = (PFDO_DEVICE_EXTENSION)Ctx;
145 Context = &FDODeviceExtension->CurrentIrpContext;
146 Request = IoStack->Parameters.Scsi.Srb;
148
149 // first check for Irp errors
150 if (!NT_SUCCESS(Irp->IoStatus.Status))
151 {
152 if (USBD_STATUS(Context->Urb.UrbHeader.Status) == USBD_STATUS(USBD_STATUS_STALL_PID))
153 {
154 if (Context->StallRetryCount < 2)
155 {
156 ++Context->StallRetryCount;
157
158 // clear stall and resend cbw
159 USBSTOR_QueueResetPipe(FDODeviceExtension);
160
162 }
163 }
164 else
165 {
166 DPRINT1("USBSTOR_CSWCompletionRoutine: Urb.Hdr.Status - %x\n", Context->Urb.UrbHeader.Status);
167 }
168
169 goto ResetRecovery;
170 }
171
172 // now check the CSW packet validity
174 {
175 goto ResetRecovery;
176 }
177
178 // finally check for CSW errors
179 if (Context->csw.Status == CSW_STATUS_COMMAND_PASSED)
180 {
181 // should happen only when a sense request was sent
182 if (Request != FDODeviceExtension->ActiveSrb)
183 {
184 ASSERT(IoStack->Parameters.Scsi.Srb == &Context->SenseSrb);
185 FDODeviceExtension->ActiveSrb->SenseInfoBufferLength = Request->DataTransferLength;
186 Request = FDODeviceExtension->ActiveSrb;
187 IoStack->Parameters.Scsi.Srb = Request;
189 }
190
191 Irp->IoStatus.Status = USBSTOR_SrbStatusToNtStatus(Request);
192 }
193 else if (Context->csw.Status == CSW_STATUS_COMMAND_FAILED)
194 {
195 // the command is correct but with failed status - issue request sense
196 DPRINT("USBSTOR_CSWCompletionRoutine: CSW_STATUS_COMMAND_FAILED\n");
197
198 ASSERT(FDODeviceExtension->ActiveSrb == Request);
199
200 // setting a generic error status, additional information
201 // should be read by higher-level driver from SenseInfoBuffer
202 Request->SrbStatus = SRB_STATUS_ERROR;
203 Request->ScsiStatus = 2;
204 Request->DataTransferLength = 0;
205
206 DPRINT("Flags: %x SBL: %x, buf: %p\n", Request->SrbFlags, Request->SenseInfoBufferLength, Request->SenseInfoBuffer);
207
208 if (!(Request->SrbFlags & SRB_FLAGS_DISABLE_AUTOSENSE) &&
209 Request->SenseInfoBufferLength &&
210 Request->SenseInfoBuffer)
211 {
212 USBSTOR_IssueRequestSense(FDODeviceExtension, Irp);
214 }
215
216 Irp->IoStatus.Status = STATUS_IO_DEVICE_ERROR;
217 }
218
219 Irp->IoStatus.Information = Request->DataTransferLength;
220
221 // terminate current request
222 USBSTOR_QueueTerminateRequest(PDODeviceExtension->LowerDeviceObject, Irp);
223 USBSTOR_QueueNextRequest(PDODeviceExtension->LowerDeviceObject);
224
226
227ResetRecovery:
228
229 Request = FDODeviceExtension->ActiveSrb;
230 IoStack->Parameters.Scsi.Srb = Request;
231 Irp->IoStatus.Information = 0;
232 Irp->IoStatus.Status = STATUS_IO_DEVICE_ERROR;
233 Request->SrbStatus = SRB_STATUS_BUS_RESET;
234
235 USBSTOR_QueueTerminateRequest(PDODeviceExtension->LowerDeviceObject, Irp);
236 USBSTOR_QueueResetDevice(FDODeviceExtension);
237
239}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
#define SRB_STATUS_BUS_RESET
Definition: srb.h:353
#define SRB_STATUS_AUTOSENSE_VALID
Definition: srb.h:387
#define SRB_FLAGS_DISABLE_AUTOSENSE
Definition: srb.h:399
#define SRB_STATUS_ERROR
Definition: srb.h:344
VOID NTAPI USBSTOR_QueueResetDevice(IN PFDO_DEVICE_EXTENSION FDODeviceExtension)
Definition: error.c:148
VOID NTAPI USBSTOR_QueueResetPipe(IN PFDO_DEVICE_EXTENSION FDODeviceExtension)
Definition: error.c:135
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:68
#define DPRINT
Definition: sndvol32.h:71
PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:3223
union _IO_STACK_LOCATION::@1564 Parameters
struct _IO_STACK_LOCATION::@3978::@4000 Scsi
#define STATUS_IO_DEVICE_ERROR
Definition: udferr_usr.h:179
static NTSTATUS USBSTOR_IssueRequestSense(IN PFDO_DEVICE_EXTENSION FDODeviceExtension, IN PIRP Irp)
Definition: scsi.c:502
static BOOLEAN USBSTOR_IsCSWValid(PIRP_CONTEXT Context)
Definition: scsi.c:101
static NTSTATUS USBSTOR_SrbStatusToNtStatus(IN PSCSI_REQUEST_BLOCK Srb)
Definition: scsi.c:20
LONG USBD_STATUS
Definition: usb.h:165
#define USBD_STATUS(Status)
Definition: usbdi.h:52
#define CSW_STATUS_PHASE_ERROR
Definition: usbstor.h:85
#define CSW_STATUS_COMMAND_PASSED
Definition: usbstor.h:83
#define CSW_STATUS_COMMAND_FAILED
Definition: usbstor.h:84
_In_ WDFREQUEST Request
Definition: wdfdevice.h:547
#define STATUS_CONTINUE_COMPLETION

◆ 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
struct _IO_STACK_LOCATION::@3978::@4003 QueryDeviceRelations
#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
#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

Referenced by USBSTOR_DispatchPnp().

◆ 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

Referenced by USBSTOR_FdoHandleStartDevice().

◆ 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

Referenced by USBSTOR_FdoHandleStartDevice().

◆ 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
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by USBSTOR_FdoHandleStartDevice().

◆ 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

Referenced by USBSTOR_FdoHandleStartDevice().

◆ 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
struct _IO_STACK_LOCATION::@1564::@1565 DeviceIoControl
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

Referenced by USBSTOR_DispatchDeviceControl().

◆ USBSTOR_HandleExecuteSCSI()

NTSTATUS USBSTOR_HandleExecuteSCSI ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp,
IN ULONG  RetryCount 
)

Definition at line 1306 of file scsi.c.

1310{
1311 PCDB pCDB;
1313 PIO_STACK_LOCATION IoStack;
1315 PPDO_DEVICE_EXTENSION PDODeviceExtension;
1316
1317 //
1318 // get PDO device extension
1319 //
1320 PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
1321
1322 //
1323 // sanity check
1324 //
1325 ASSERT(PDODeviceExtension->Common.IsFDO == FALSE);
1326
1327 //
1328 // get current stack location
1329 //
1331
1332 //
1333 // get request block
1334 //
1335 Request = (PSCSI_REQUEST_BLOCK)IoStack->Parameters.Others.Argument1;
1336
1337 //
1338 // get SCSI command data block
1339 //
1340 pCDB = (PCDB)Request->Cdb;
1341
1342 DPRINT("USBSTOR_HandleExecuteSCSI Operation Code %x\n", pCDB->AsByte[0]);
1343
1344 if (pCDB->AsByte[0] == SCSIOP_READ_CAPACITY)
1345 {
1346 //
1347 // sanity checks
1348 //
1349 ASSERT(Request->DataBuffer);
1350
1351 DPRINT("SCSIOP_READ_CAPACITY Length %lu\n", Request->DataTransferLength);
1353 }
1354 else if (pCDB->MODE_SENSE.OperationCode == SCSIOP_MODE_SENSE)
1355 {
1356 DPRINT("SCSIOP_MODE_SENSE DataTransferLength %lu\n", Request->DataTransferLength);
1357 ASSERT(pCDB->MODE_SENSE.AllocationLength == Request->DataTransferLength);
1358 ASSERT(Request->DataBuffer);
1359
1360 //
1361 // send mode sense command
1362 //
1364 }
1365 else if (pCDB->AsByte[0] == SCSIOP_READ_FORMATTED_CAPACITY)
1366 {
1367 DPRINT("SCSIOP_READ_FORMATTED_CAPACITY DataTransferLength %lu\n", Request->DataTransferLength);
1368
1369 //
1370 // send read format capacity
1371 //
1373 }
1374 else if (pCDB->AsByte[0] == SCSIOP_INQUIRY)
1375 {
1376 DPRINT("SCSIOP_INQUIRY DataTransferLength %lu\n", Request->DataTransferLength);
1377
1378 //
1379 // send read format capacity
1380 //
1382 }
1383 else if (pCDB->MODE_SENSE.OperationCode == SCSIOP_READ || pCDB->MODE_SENSE.OperationCode == SCSIOP_WRITE)
1384 {
1385 DPRINT("SCSIOP_READ / SCSIOP_WRITE DataTransferLength %lu\n", Request->DataTransferLength);
1386
1387 //
1388 // send read / write command
1389 //
1391 }
1392 else if (pCDB->AsByte[0] == SCSIOP_MEDIUM_REMOVAL)
1393 {
1394 DPRINT("SCSIOP_MEDIUM_REMOVAL\n");
1395
1396 //
1397 // just complete the request
1398 //
1399 Request->SrbStatus = SRB_STATUS_SUCCESS;
1400 Irp->IoStatus.Status = STATUS_SUCCESS;
1401 Irp->IoStatus.Information = Request->DataTransferLength;
1402 USBSTOR_QueueTerminateRequest(PDODeviceExtension->LowerDeviceObject, Irp);
1404
1405 //
1406 // start next request
1407 //
1408 USBSTOR_QueueNextRequest(PDODeviceExtension->LowerDeviceObject);
1409
1410 return STATUS_SUCCESS;
1411 }
1412 else if (pCDB->MODE_SENSE.OperationCode == SCSIOP_TEST_UNIT_READY)
1413 {
1414 DPRINT("SCSIOP_TEST_UNIT_READY\n");
1415
1416 //
1417 // send test unit command
1418 //
1420 }
1421 else
1422 {
1423 // Unknown request. Simply forward
1424 DPRINT1("Forwarding unknown Operation Code %x\n", pCDB->AsByte[0]);
1426 }
1427
1428 return Status;
1429}
#define SCSIOP_INQUIRY
Definition: cdrw_hw.h:888
#define SCSIOP_TEST_UNIT_READY
Definition: cdrw_hw.h:866
#define SCSIOP_MEDIUM_REMOVAL
Definition: cdrw_hw.h:902
#define SCSIOP_READ_CAPACITY
Definition: cdrw_hw.h:904
#define SCSIOP_WRITE
Definition: cdrw_hw.h:906
#define SCSIOP_MODE_SENSE
Definition: cdrw_hw.h:896
#define SCSIOP_READ
Definition: cdrw_hw.h:905
struct _SCSI_REQUEST_BLOCK * PSCSI_REQUEST_BLOCK
#define SRB_STATUS_SUCCESS
Definition: srb.h:341
#define SCSIOP_READ_FORMATTED_CAPACITY
Definition: scsi.h:273
struct _IO_STACK_LOCATION::@3978::@4017 Others
Definition: cdrw_hw.h:28
UCHAR AsByte[16]
Definition: scsi.h:1988
struct _CDB::_MODE_SENSE MODE_SENSE
NTSTATUS USBSTOR_SendInquiry(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN ULONG RetryCount)
Definition: scsi.c:866
NTSTATUS USBSTOR_SendReadWrite(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN ULONG RetryCount)
Definition: scsi.c:1140
NTSTATUS USBSTOR_SendModeSense(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN ULONG RetryCount)
Definition: scsi.c:951
NTSTATUS USBSTOR_SendUnknownRequest(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp, IN ULONG RetryCount)
Definition: scsi.c:1259
NTSTATUS USBSTOR_SendCapacity(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN ULONG RetryCount)
Definition: scsi.c:911
NTSTATUS USBSTOR_SendFormatCapacity(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN ULONG RetryCount)
Definition: scsi.c:825
NTSTATUS USBSTOR_SendTestUnit(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp, IN ULONG RetryCount)
Definition: scsi.c:1215

◆ 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 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
#define SRB_STATUS_BUSY
Definition: srb.h:345
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

Referenced by USBSTOR_DispatchScsi().

◆ USBSTOR_IsFloppy()

BOOLEAN USBSTOR_IsFloppy ( IN PUCHAR  Buffer,
IN ULONG  BufferLength,
OUT PUCHAR  MediumTypeCode 
)

Definition at line 409 of file misc.c.

413{
414 PUFI_CAPACITY_FORMAT_HEADER FormatHeader;
416 ULONG Length, Index, BlockCount, BlockLength;
417
418 //
419 // get format header
420 //
421 FormatHeader = (PUFI_CAPACITY_FORMAT_HEADER)Buffer;
422
423 //
424 // sanity checks
425 //
426 ASSERT(FormatHeader->Reserved1 == 0x00);
427 ASSERT(FormatHeader->Reserved2 == 0x00);
428 ASSERT(FormatHeader->Reserved3 == 0x00);
429
430 //
431 // is there capacity data
432 //
433 if (!FormatHeader->CapacityLength)
434 {
435 //
436 // no data provided
437 //
438 DPRINT1("[USBSTOR] No capacity length\n");
439 return FALSE;
440 }
441
442 //
443 // the format header are always 8 bytes in length
444 //
445 ASSERT((FormatHeader->CapacityLength & 0x7) == 0);
446 DPRINT1("CapacityLength %x\n", FormatHeader->CapacityLength);
447
448 //
449 // grab length and locate first descriptor
450 //
451 Length = FormatHeader->CapacityLength;
452 Descriptor = (PUFI_CAPACITY_DESCRIPTOR)(FormatHeader + 1);
453 for(Index = 0; Index < Length / sizeof(UFI_CAPACITY_DESCRIPTOR); Index++)
454 {
455 //
456 // blocks are little endian format
457 //
458 BlockCount = NTOHL(Descriptor->BlockCount);
459
460 //
461 // get block length
462 //
463 BlockLength = NTOHL((Descriptor->BlockLengthByte0 << 24 | Descriptor->BlockLengthByte1 << 16 | Descriptor->BlockLengthByte2 << 8));
464
465 DPRINT1("BlockCount %x BlockLength %x Code %x\n", BlockCount, BlockLength, Descriptor->Code);
466
467 if (BlockLength == 512 && BlockCount == 1440)
468 {
469 //
470 // 720 KB DD
471 //
472 *MediumTypeCode = 0x1E;
473 return TRUE;
474 }
475 else if (BlockLength == 1024 && BlockCount == 1232)
476 {
477 //
478 // 1,25 MB
479 //
480 *MediumTypeCode = 0x93;
481 return TRUE;
482 }
483 else if (BlockLength == 512 && BlockCount == 2880)
484 {
485 //
486 // 1,44MB KB DD
487 //
488 *MediumTypeCode = 0x94;
489 return TRUE;
490 }
491
492 //
493 // move to next descriptor
494 //
495 Descriptor = (Descriptor + 1);
496 }
497
498 //
499 // no floppy detected
500 //
501 return FALSE;
502}
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
struct UFI_CAPACITY_FORMAT_HEADER * PUFI_CAPACITY_FORMAT_HEADER
struct UFI_CAPACITY_DESCRIPTOR * PUFI_CAPACITY_DESCRIPTOR
#define NTOHL(n)
Definition: usbstor.h:22
_Must_inspect_result_ _In_ WDFIORESLIST _In_ PIO_RESOURCE_DESCRIPTOR Descriptor
Definition: wdfresource.h:342

Referenced by USBSTOR_SendFormatCapacityIrp().

◆ 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
struct _IO_STACK_LOCATION::@3978::@4005 DeviceCapabilities
struct _IO_STACK_LOCATION::@3978::@4009 QueryId
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

Referenced by USBSTOR_DispatchPnp().

◆ 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;
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

Referenced by USBSTOR_HandleInternalDeviceControl().

◆ 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

Referenced by USBSTOR_FdoHandleStartDevice().

◆ 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

Referenced by USBSTOR_Cancel(), USBSTOR_CancelIo(), USBSTOR_CSWCompletionRoutine(), USBSTOR_HandleExecuteSCSI(), USBSTOR_HandleTransferError(), USBSTOR_ResetDeviceWorkItemRoutine(), USBSTOR_SendModeSense(), and USBSTOR_StartIo().

◆ 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}

Referenced by USBSTOR_HandleInternalDeviceControl().

◆ 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;
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

Referenced by USBSTOR_Cancel(), USBSTOR_CancelIo(), USBSTOR_CBWCompletionRoutine(), USBSTOR_CSWCompletionRoutine(), USBSTOR_DataCompletionRoutine(), USBSTOR_HandleExecuteSCSI(), USBSTOR_HandleTransferError(), USBSTOR_SendModeSense(), and USBSTOR_StartIo().

◆ 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}

Referenced by USBSTOR_HandleInternalDeviceControl().

◆ 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

Referenced by USBSTOR_GetMaxLUN(), USBSTOR_HandleTransferError(), USBSTOR_ResetDeviceWorkItemRoutine(), and USBSTOR_TimerWorkerRoutine().

◆ 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

Referenced by USBSTOR_HandleTransferError(), USBSTOR_ResetDeviceWorkItemRoutine(), USBSTOR_ResetHandlerWorkItemRoutine(), USBSTOR_ResetPipeWorkItemRoutine(), and USBSTOR_TimerWorkerRoutine().

◆ 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

Referenced by USBSTOR_FdoHandleStartDevice().

◆ USBSTOR_SendCBW()

NTSTATUS USBSTOR_SendCBW ( PIRP_CONTEXT  Context,
PIRP  Irp 
)

Definition at line 591 of file scsi.c.

594{
595 PIO_STACK_LOCATION IoStack;
596
597 //
598 // get next stack location
599 //
601
602 //
603 // initialize stack location
604 //
607 IoStack->Parameters.Others.Argument1 = (PVOID)&Context->Urb;
608 IoStack->Parameters.DeviceIoControl.InputBufferLength = Context->Urb.UrbHeader.Length;
609 Irp->IoStatus.Status = STATUS_SUCCESS;
610
611 //
612 // setup completion routine
613 //
615
616 //
617 // call driver
618 //
619 return IoCallDriver(Context->FDODeviceExtension->LowerDeviceObject, Irp);
620}
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:490
IO_COMPLETION_ROUTINE USBSTOR_CBWCompletionRoutine
Definition: scsi.c:325
#define IOCTL_INTERNAL_USB_SUBMIT_URB
Definition: usbioctl.h:32
#define IRP_MJ_INTERNAL_DEVICE_CONTROL

Referenced by USBSTOR_SendModeSense(), and USBSTOR_SendRequest().

◆ USBSTOR_SendCSW()

VOID USBSTOR_SendCSW ( PIRP_CONTEXT  Context,
PIRP  Irp 
)

Definition at line 379 of file scsi.c.

382{
383 PIO_STACK_LOCATION IoStack;
384
385 //
386 // get next irp stack location
387 //
389
390 //
391 // now initialize the urb for sending the csw
392 //
394 sizeof(struct _URB_BULK_OR_INTERRUPT_TRANSFER),
395 Context->FDODeviceExtension->InterfaceInformation->Pipes[Context->FDODeviceExtension->BulkInPipeIndex].PipeHandle,
396 Context->csw,
397 NULL,
398 512, //FIXME
400 NULL);
401
402 //
403 // initialize stack location
404 //
407 IoStack->Parameters.Others.Argument1 = (PVOID)&Context->Urb;
408 IoStack->Parameters.DeviceIoControl.InputBufferLength = Context->Urb.UrbHeader.Length;
409 Irp->IoStatus.Status = STATUS_SUCCESS;
410
411
412 //
413 // setup completion routine
414 //
416
417 //
418 // call driver
419 //
420 IoCallDriver(Context->FDODeviceExtension->LowerDeviceObject, Irp);
421}
IO_COMPLETION_ROUTINE USBSTOR_CSWCompletionRoutine
Definition: scsi.c:125
#define USBD_SHORT_TRANSFER_OK
Definition: usb.h:154
#define UsbBuildInterruptOrBulkTransferRequest(urb, length, pipeHandle, transferBuffer, transferBufferMDL, transferBufferLength, transferFlags, link)
Definition: usbdlib.h:12

Referenced by USBSTOR_DataCompletionRoutine(), USBSTOR_ResetHandlerWorkItemRoutine(), and USBSTOR_SendModeSense().

◆ 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
NTSTATUS USBSTOR_HandleExecuteSCSI(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: scsi.c:540
#define USBSTOR_FDO_FLAGS_DEVICE_RESETTING
Definition: usbstor.h:117

Referenced by DriverEntry().

◆ 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}

Referenced by USBCCGP_SyncUrbRequest(), USBSTOR_SyncForwardIrp(), and USBSTOR_SyncUrbRequest().

◆ 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
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
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
Definition: irp.c:615
VOID NTAPI IoFreeIrp(IN PIRP Irp)
Definition: irp.c:1666

Referenced by USBSTOR_ClassRequest(), USBSTOR_GetDescriptor(), USBSTOR_GetEndpointStatus(), USBSTOR_ResetPipeWithHandle(), and USBSTOR_SelectConfigurationAndInterface().

◆ 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
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

Referenced by USBSTOR_AddDevice().