ReactOS 0.4.16-dev-401-g45b008d
usbstor.h
Go to the documentation of this file.
1#ifndef _USBSTOR_H_
2#define _USBSTOR_H_
3
4#include <wdm.h>
5#include <ntstrsafe.h>
6#include <usbdi.h>
7#include <usbbusif.h>
8#include <usbdlib.h>
9#include <classpnp.h>
10
11#define USB_STOR_TAG 'sbsu'
12
13#ifndef BooleanFlagOn
14#define BooleanFlagOn(Flags, SingleFlag) ((BOOLEAN)((((Flags) & (SingleFlag)) != 0)))
15#endif
16
17#ifndef SrbGetCdb
18#define SrbGetCdb(srb) ((PCDB)(srb->Cdb))
19#endif
20
21// Storage subclass codes
22
23#define USB_SUBCLASS_RBC 0x01 // Typically, flash devices
24#define USB_SUBCLASS_8020 0x02 // CD-ROM
25#define USB_SUBCLASS_QIC 0x03 // QIC-157 Tapes
26#define USB_SUBCLASS_UFI 0x04 // Floppy
27#define USB_SUBCLASS_8070 0x05 // Removable media
28#define USB_SUBCLASS_SCSI 0x06 // Transparent
29#define USB_SUBCLASS_LOCKABLE 0x07 // Password-protected
30
31#define USB_SUBCLASS_ISD200 0xF0 // ISD200 ATA
32#define USB_SUBCLASS_CYP_ATACB 0xF1 // Cypress ATACB
33#define USB_SUBCLASS_VENDOR 0xFF // Use vendor specific
34
35// Storage protocol codes
36
37#define USB_PROTOCOL_CBI 0x00 // Control/Bulk/Interrupt
38#define USB_PROTOCOL_CB 0x01 // Control/Bulk w/o interrupt
39#define USB_PROTOCOL_BULK 0x50 // bulk only
40#define USB_PROTOCOL_UAS 0x62 // USB Attached SCSI
41#define USB_PROTOCOL_USBAT 0x80 // SCM-ATAPI bridge
42#define USB_PROTOCOL_EUSB_SDDR09 0x81 // SCM-SCSI bridge for SDDR-09
43#define USB_PROTOCOL_SDDR55 0x82 // SDDR-55 (made up)
44
45#define USB_PROTOCOL_DPCM_USB 0xF0 // Combination CB/SDDR09
46#define USB_PROTOCOL_FREECOM 0xF1 // Freecom
47#define USB_PROTOCOL_DATAFAB 0xF2 // Datafab chipsets
48#define USB_PROTOCOL_JUMPSHOT 0xF3 // Lexar Jumpshot
49#define USB_PROTOCOL_ALAUDA 0xF4 // Alauda chipsets
50#define USB_PROTOCOL_KARMA 0xF5 // Rio Karma
51#define USB_PROTOCOL_VENDOR 0xFF // Use vendor specific
52
53// Mass storage class-specific commands
54
55#define USB_BULK_GET_MAX_LUN 0xFE
56#define USB_BULK_RESET_DEVICE 0xFF
57
58#define USB_RECOVERABLE_ERRORS (USBD_STATUS_STALL_PID | USBD_STATUS_DEV_NOT_RESPONDING \
59 | USBD_STATUS_ENDPOINT_HALTED | USBD_STATUS_NO_BANDWIDTH)
60
61#define USB_MAXCHILDREN 16
62#define MAX_LUN 0xF
63#define USBSTOR_DEFAULT_MAX_TRANSFER_LENGTH 0x10000
64
65#define CBW_SIGNATURE 0x43425355
66#define CSW_SIGNATURE 0x53425355
67
68#include <pshpack1.h>
69
70typedef struct
71{
72 ULONG Signature; // CBW signature
73 ULONG Tag; // CBW Tag of operation
74 ULONG DataTransferLength; // data transfer length
75 UCHAR Flags; // CBW Flags endpoint direction
76 UCHAR LUN; // lun unit
77 UCHAR CommandBlockLength; // Command block length
78 UCHAR CommandBlock[16];
80
81C_ASSERT(sizeof(CBW) == 31);
82
83#define CSW_STATUS_COMMAND_PASSED 0x00
84#define CSW_STATUS_COMMAND_FAILED 0x01
85#define CSW_STATUS_PHASE_ERROR 0x02
86
87typedef struct
88{
89 ULONG Signature; // CSW signature
90 ULONG Tag; // CSW tag
91 ULONG DataResidue; // CSW data transfer diff
92 UCHAR Status; // CSW status
94
95#include <poppack.h>
96
97typedef struct
98{
101 ULONG StallRetryCount; // the number of retries after receiving USBD_STATUS_STALL_PID status
102 union
103 {
106 };
110
112{
114
116
117#define USBSTOR_FDO_FLAGS_DEVICE_RESETTING 0x00000001 // hard reset is in progress
118#define USBSTOR_FDO_FLAGS_IRP_LIST_FREEZE 0x00000002 // the irp list is freezed
119
120typedef struct
121{
122 USBSTOR_COMMON_DEVICE_EXTENSION Common; // common device extension
123
124 PDEVICE_OBJECT FunctionalDeviceObject; // functional device object
125 PDEVICE_OBJECT PhysicalDeviceObject; // physical device object
126 PDEVICE_OBJECT LowerDeviceObject; // lower device object
127 USB_BUS_INTERFACE_USBDI_V2 BusInterface; // bus interface of device
128 PUSB_DEVICE_DESCRIPTOR DeviceDescriptor; // usb device descriptor
129 PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor; // usb configuration descriptor
132 USBD_CONFIGURATION_HANDLE ConfigurationHandle; // usb configuration handle
133 UCHAR BulkInPipeIndex; // bulk in pipe index
134 UCHAR BulkOutPipeIndex; // bulk out pipe index
135 UCHAR MaxLUN; // max lun for device
136 PDEVICE_OBJECT ChildPDO[USB_MAXCHILDREN]; // max 16 child pdo devices
137 KSPIN_LOCK IrpListLock; // irp list lock
138 LIST_ENTRY IrpListHead; // irp list head
139 ULONG IrpPendingCount; // count of irp pending
140 PSCSI_REQUEST_BLOCK ActiveSrb; // stores the current active SRB
141 KEVENT NoPendingRequests; // set if no pending or in progress requests
142 PSCSI_REQUEST_BLOCK LastTimerActiveSrb; // last timer tick active srb
143 ULONG SrbErrorHandlingActive; // error handling of srb is activated
144 ULONG TimerWorkQueueEnabled; // timer work queue enabled
145 ULONG InstanceCount; // pdo instance count
151
152typedef struct
153{
155
156 UCHAR LUN; // lun id
157 BOOLEAN Claimed; // indicating if it has been claimed by upper driver
159 PDEVICE_OBJECT *PDODeviceObject; // entry in pdo list
161 // the whole structure is not stored
162 UCHAR InquiryData[INQUIRYDATABUFFERSIZE]; // USB SCSI inquiry data
164
166{
172
173// we need this to be compatible with ReactOS' classpnp (which is compiled with NTDDI_WIN8)
176 ULONG Size;
190
191
192//---------------------------------------------------------------------
193//
194// fdo.c routines
195//
199 IN OUT PIRP Irp);
200
201//---------------------------------------------------------------------
202//
203// pdo.c routines
204//
208 IN OUT PIRP Irp);
209
213 IN UCHAR LUN);
214
215//---------------------------------------------------------------------
216//
217// misc.c routines
218//
219
221NTAPI
224 OUT PUSB_BUS_INTERFACE_USBDI_V2 BusInterface);
225
226PVOID
230
231VOID
233 IN PVOID Item);
234
238 OUT PURB UrbRequest);
239
243 IN PFDO_DEVICE_EXTENSION DeviceExtension);
244
248 IN PFDO_DEVICE_EXTENSION DeviceExtension);
249
250//---------------------------------------------------------------------
251//
252// descriptor.c routines
253//
254
258
262 IN PFDO_DEVICE_EXTENSION DeviceExtension);
263
266 IN PFDO_DEVICE_EXTENSION DeviceExtension);
267
268//---------------------------------------------------------------------
269//
270// scsi.c routines
271//
275 IN PIRP Irp);
276
279 PFDO_DEVICE_EXTENSION FDODeviceExtension,
280 PIRP Irp);
281
282
283//---------------------------------------------------------------------
284//
285// disk.c routines
286//
290 IN PIRP Irp);
291
295 IN PIRP Irp);
296
297//---------------------------------------------------------------------
298//
299// queue.c routines
300//
301VOID
302NTAPI
305 PIRP Irp);
306
307VOID
310
311VOID
314
318 IN PIRP Irp);
319
320VOID
321NTAPI
324 IN PIRP Irp);
325
326VOID
328 PFDO_DEVICE_EXTENSION FDODeviceExtension);
329
330VOID
333
334VOID
337 IN PIRP Irp);
338
339//---------------------------------------------------------------------
340//
341// error.c routines
342//
346 IN UCHAR bEndpointAddress,
348
353
354VOID
355NTAPI
358 PVOID Context);
359
360VOID
361NTAPI
363 IN PFDO_DEVICE_EXTENSION FDODeviceExtension);
364
365VOID
366NTAPI
368 IN PFDO_DEVICE_EXTENSION FDODeviceExtension);
369
370#endif // _USBSTOR_H_
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1157
#define INQUIRYDATABUFFERSIZE
Definition: cdrw_hw.h:1113
_In_ PIRP Irp
Definition: csq.h:116
static HANDLE PipeHandle
Definition: dhcpcsvc.c:22
ULONG KSPIN_LOCK
Definition: env_spec_w32.h:72
#define C_ASSERT(e)
Definition: intsafe.h:73
_Must_inspect_result_ _Out_ PNDIS_STATUS _Out_ PNDIS_HANDLE ConfigurationHandle
Definition: ndis.h:3945
unsigned short USHORT
Definition: pedump.c:61
static UCHAR ItemSize[4]
Definition: parser.c:16
const KSDEVICE_DESCRIPTOR DeviceDescriptor
Definition: splitter.c:257
Definition: usbstor.h:71
UCHAR LUN
Definition: usbstor.h:76
UCHAR CommandBlockLength
Definition: usbstor.h:77
ULONG Signature
Definition: usbstor.h:72
ULONG Tag
Definition: usbstor.h:73
UCHAR Flags
Definition: usbstor.h:75
ULONG DataTransferLength
Definition: usbstor.h:74
Definition: usbstor.h:88
ULONG Signature
Definition: usbstor.h:89
ULONG DataResidue
Definition: usbstor.h:91
ULONG Tag
Definition: usbstor.h:90
UCHAR Status
Definition: usbstor.h:92
USBSTOR_COMMON_DEVICE_EXTENSION Common
Definition: usbstor.h:122
ULONG TimerWorkQueueEnabled
Definition: usbstor.h:144
UCHAR BulkOutPipeIndex
Definition: usbstor.h:134
PIO_WORKITEM ResetDeviceWorkItem
Definition: usbstor.h:147
PDEVICE_OBJECT FunctionalDeviceObject
Definition: usbstor.h:124
LIST_ENTRY IrpListHead
Definition: usbstor.h:138
PSCSI_REQUEST_BLOCK LastTimerActiveSrb
Definition: usbstor.h:142
PUSBD_INTERFACE_INFORMATION InterfaceInformation
Definition: usbstor.h:131
USB_BUS_INTERFACE_USBDI_V2 BusInterface
Definition: usbstor.h:127
IRP_CONTEXT CurrentIrpContext
Definition: usbstor.h:149
KSPIN_LOCK IrpListLock
Definition: usbstor.h:137
KEVENT NoPendingRequests
Definition: usbstor.h:141
PSCSI_REQUEST_BLOCK ActiveSrb
Definition: usbstor.h:140
PDEVICE_OBJECT LowerDeviceObject
Definition: usbstor.h:126
PUSB_STRING_DESCRIPTOR SerialNumber
Definition: usbstor.h:130
KSPIN_LOCK CommonLock
Definition: usbstor.h:146
ULONG SrbErrorHandlingActive
Definition: usbstor.h:143
ULONG ErrorIndex
Definition: usbstor.h:100
PIRP Irp
Definition: usbstor.h:99
ULONG StallRetryCount
Definition: usbstor.h:101
SCSI_REQUEST_BLOCK SenseSrb
Definition: usbstor.h:108
PDEVICE_OBJECT LowerDeviceObject
Definition: usbstor.h:158
PDEVICE_OBJECT * PDODeviceObject
Definition: usbstor.h:159
USBSTOR_COMMON_DEVICE_EXTENSION Common
Definition: usbstor.h:154
PDEVICE_OBJECT Self
Definition: usbstor.h:160
PDEVICE_OBJECT DeviceObject
Definition: usbstor.h:167
WORK_QUEUE_ITEM WorkQueueItem
Definition: usbstor.h:169
Definition: typedefs.h:120
Definition: usb.h:529
INT POOL_TYPE
Definition: typedefs.h:78
#define NTAPI
Definition: typedefs.h:36
uint16_t * PUSHORT
Definition: typedefs.h:56
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
NTSTATUS USBSTOR_HandleExecuteSCSI(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: scsi.c:540
NTSTATUS USBSTOR_SendCSWRequest(PFDO_DEVICE_EXTENSION FDODeviceExtension, PIRP Irp)
Definition: scsi.c:242
struct PDO_DEVICE_EXTENSION * PPDO_DEVICE_EXTENSION
struct __COMMON_DEVICE_EXTENSION__ USBSTOR_COMMON_DEVICE_EXTENSION
struct _STORAGE_ADAPTER_DESCRIPTOR_WIN8 * PSTORAGE_ADAPTER_DESCRIPTOR_WIN8
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
NTSTATUS USBSTOR_FdoHandlePnp(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
Definition: fdo.c:276
NTSTATUS USBSTOR_SyncUrbRequest(IN PDEVICE_OBJECT DeviceObject, OUT PURB UrbRequest)
Definition: misc.c:83
VOID NTAPI USBSTOR_QueueResetDevice(IN PFDO_DEVICE_EXTENSION FDODeviceExtension)
Definition: error.c:148
NTSTATUS USBSTOR_ResetPipeWithHandle(IN PDEVICE_OBJECT DeviceObject, IN USBD_PIPE_HANDLE PipeHandle)
Definition: error.c:46
struct FDO_DEVICE_EXTENSION * PFDO_DEVICE_EXTENSION
VOID NTAPI USBSTOR_QueueResetPipe(IN PFDO_DEVICE_EXTENSION FDODeviceExtension)
Definition: error.c:135
NTSTATUS USBSTOR_GetMaxLUN(IN PDEVICE_OBJECT DeviceObject, IN PFDO_DEVICE_EXTENSION DeviceExtension)
Definition: misc.c:173
NTSTATUS USBSTOR_HandleInternalDeviceControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: disk.c:81
NTSTATUS USBSTOR_ResetDevice(IN PDEVICE_OBJECT DeviceObject, IN PFDO_DEVICE_EXTENSION DeviceExtension)
Definition: misc.c:219
NTSTATUS USBSTOR_CreatePDO(IN PDEVICE_OBJECT DeviceObject, IN UCHAR LUN)
Definition: pdo.c:864
VOID USBSTOR_QueueInitialize(PFDO_DEVICE_EXTENSION FDODeviceExtension)
Definition: queue.c:17
#define USB_MAXCHILDREN
Definition: usbstor.h:61
NTSTATUS USBSTOR_GetDescriptors(IN PDEVICE_OBJECT DeviceObject)
Definition: descriptor.c:75
struct _ERRORHANDLER_WORKITEM_DATA * PERRORHANDLER_WORKITEM_DATA
struct CBW * PCBW
VOID USBSTOR_QueueTerminateRequest(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: queue.c:186
PVOID AllocateItem(IN POOL_TYPE PoolType, IN ULONG ItemSize)
Definition: misc.c:29
struct _ERRORHANDLER_WORKITEM_DATA ERRORHANDLER_WORKITEM_DATA
struct CSW * PCSW
struct __COMMON_DEVICE_EXTENSION__ * PUSBSTOR_COMMON_DEVICE_EXTENSION
NTSTATUS USBSTOR_PdoHandlePnp(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
Definition: pdo.c:534
VOID USBSTOR_QueueWaitForPendingRequests(IN PDEVICE_OBJECT DeviceObject)
Definition: queue.c:171
NTSTATUS NTAPI USBSTOR_GetBusInterface(IN PDEVICE_OBJECT DeviceObject, OUT PUSB_BUS_INTERFACE_USBDI_V2 BusInterface)
Definition: misc.c:33
NTSTATUS USBSTOR_HandleDeviceControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: disk.c:413
struct IRP_CONTEXT * PIRP_CONTEXT
NTSTATUS USBSTOR_GetPipeHandles(IN PFDO_DEVICE_EXTENSION DeviceExtension)
Definition: descriptor.c:319
VOID USBSTOR_QueueNextRequest(IN PDEVICE_OBJECT DeviceObject)
Definition: queue.c:220
NTSTATUS USBSTOR_SelectConfigurationAndInterface(IN PDEVICE_OBJECT DeviceObject, IN PFDO_DEVICE_EXTENSION DeviceExtension)
Definition: descriptor.c:234
NTSTATUS USBSTOR_GetEndpointStatus(IN PDEVICE_OBJECT DeviceObject, IN UCHAR bEndpointAddress, OUT PUSHORT Value)
Definition: error.c:18
VOID NTAPI USBSTOR_CancelIo(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: queue.c:28
VOID FreeItem(IN PVOID Item)
Definition: misc.c:37
VOID NTAPI USBSTOR_StartIo(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: queue.c:300
struct _STORAGE_ADAPTER_DESCRIPTOR_WIN8 STORAGE_ADAPTER_DESCRIPTOR_WIN8
VOID NTAPI USBSTOR_TimerRoutine(PDEVICE_OBJECT DeviceObject, PVOID Context)
Definition: error.c:205
_In_ WDFCOLLECTION _In_ WDFOBJECT Item
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ _Strict_type_match_ POOL_TYPE PoolType
Definition: wdfdevice.h:3815
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413
unsigned char UCHAR
Definition: xmlstorage.h:181