ReactOS 0.4.16-dev-106-g10b08aa
misc.c File Reference
#include "usbstor.h"
#include <debug.h>
Include dependency graph for misc.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

NTSTATUS NTAPI USBSTOR_SyncForwardIrpCompletionRoutine (PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Context)
 
NTSTATUS NTAPI USBSTOR_GetBusInterface (IN PDEVICE_OBJECT DeviceObject, OUT PUSB_BUS_INTERFACE_USBDI_V2 BusInterface)
 
NTSTATUS USBSTOR_SyncUrbRequest (IN PDEVICE_OBJECT DeviceObject, OUT PURB UrbRequest)
 
PVOID AllocateItem (IN POOL_TYPE PoolType, IN ULONG ItemSize)
 
VOID FreeItem (IN PVOID Item)
 
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)
 
NTSTATUS USBSTOR_GetMaxLUN (IN PDEVICE_OBJECT DeviceObject, IN PFDO_DEVICE_EXTENSION DeviceExtension)
 
NTSTATUS USBSTOR_ResetDevice (IN PDEVICE_OBJECT DeviceObject, IN PFDO_DEVICE_EXTENSION DeviceExtension)
 

Variables

IO_COMPLETION_ROUTINE SyncForwardIrpCompletionRoutine
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 12 of file misc.c.

Function Documentation

◆ AllocateItem()

PVOID AllocateItem ( IN POOL_TYPE  PoolType,
IN ULONG  ItemSize 
)

Definition at line 124 of file misc.c.

127{
129}
FORCEINLINE PVOID ExAllocatePoolZero(ULONG PoolType, SIZE_T NumberOfBytes, ULONG Tag)
Definition: precomp.h:45
static UCHAR ItemSize[4]
Definition: parser.c:16
#define USB_STOR_TAG
Definition: usbstor.h:11
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ _Strict_type_match_ POOL_TYPE PoolType
Definition: wdfdevice.h:3815

◆ FreeItem()

VOID FreeItem ( IN PVOID  Item)

Definition at line 132 of file misc.c.

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

◆ USBSTOR_ClassRequest()

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 at line 139 of file misc.c.

148{
149 PURB Urb;
151
153 if (!Urb)
154 {
156 }
157
160 Urb->UrbControlVendorClassRequest.TransferFlags = TransferFlags;
161 Urb->UrbControlVendorClassRequest.TransferBufferLength = TransferBufferLength;
162 Urb->UrbControlVendorClassRequest.TransferBuffer = TransferBuffer;
165
167
168 FreeItem(Urb);
169 return Status;
170}
LONG NTSTATUS
Definition: precomp.h:26
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
Definition: misc.c:29
NTSTATUS USBSTOR_SyncUrbRequest(IN PDEVICE_OBJECT DeviceObject, OUT PURB UrbRequest)
Definition: misc.c:83
VOID FreeItem(IN PVOID Item)
Definition: misc.c:132
#define NonPagedPool
Definition: env_spec_w32.h:307
Status
Definition: gdiplustypes.h:25
Definition: usb.h:529
struct _URB_CONTROL_VENDOR_OR_CLASS_REQUEST UrbControlVendorClassRequest
Definition: usb.h:548
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define URB_FUNCTION_CLASS_INTERFACE
Definition: usb.h:113
struct _URB * PURB
_In_ WDFCOLLECTION _In_ ULONG Index
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFQUEUE _In_ _Strict_type_match_ WDF_REQUEST_TYPE RequestType
Definition: wdfdevice.h:4233

Referenced by USBSTOR_GetMaxLUN(), and USBSTOR_ResetDevice().

◆ 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
_In_ PIRP Irp
Definition: csq.h:116
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define ASSERT(a)
Definition: mode.c:44
__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
#define IoCallDriver
Definition: irp.c:1225
#define STATUS_PENDING
Definition: ntstatus.h:82
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
GUID * LPGUID
Definition: guiddef.h:81
struct _INTERFACE * PINTERFACE
_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_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
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
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
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:73
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_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_SyncForwardIrpCompletionRoutine()

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

Definition at line 19 of file misc.c.

23{
24 if (Irp->PendingReturned)
25 {
27 }
29}
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:68
#define IO_NO_INCREMENT
Definition: iotypes.h:598

◆ 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}
#define TRUE
Definition: types.h:120
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
struct _IO_STACK_LOCATION::@1575::@1576 DeviceIoControl
union _IO_STACK_LOCATION::@1575 Parameters
struct _IO_STACK_LOCATION::@3974::@4013 Others
void * PVOID
Definition: typedefs.h:50
#define IOCTL_INTERNAL_USB_SUBMIT_URB
Definition: usbioctl.h:32
#define IRP_MJ_INTERNAL_DEVICE_CONTROL

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

Variable Documentation

◆ SyncForwardIrpCompletionRoutine

IO_COMPLETION_ROUTINE SyncForwardIrpCompletionRoutine

Definition at line 15 of file misc.c.