ReactOS  0.4.15-dev-5446-g3f3714b
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 125 of file misc.c.

128 {
130 
131  if (Item)
132  {
134  }
135 
136  return Item;
137 }
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define USB_STOR_TAG
Definition: usbstor.h:10
static UCHAR ItemSize[4]
Definition: parser.c:16
_In_ WDFCOLLECTION _In_ WDFOBJECT Item
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ _Strict_type_match_ POOL_TYPE PoolType
Definition: wdfdevice.h:3810
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262

◆ FreeItem()

VOID FreeItem ( IN PVOID  Item)

Definition at line 140 of file misc.c.

142 {
144 }
#define USB_STOR_TAG
Definition: usbstor.h:10
_In_ WDFCOLLECTION _In_ WDFOBJECT Item
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099

◆ 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 147 of file misc.c.

156 {
157  PURB Urb;
159 
161  if (!Urb)
162  {
164  }
165 
168  Urb->UrbControlVendorClassRequest.TransferFlags = TransferFlags;
169  Urb->UrbControlVendorClassRequest.TransferBufferLength = TransferBufferLength;
170  Urb->UrbControlVendorClassRequest.TransferBuffer = TransferBuffer;
172  Urb->UrbControlVendorClassRequest.Index = Index;
173 
175 
176  FreeItem(Urb);
177  return Status;
178 }
VOID FreeItem(IN PVOID Item)
Definition: misc.c:43
struct _URB_CONTROL_VENDOR_OR_CLASS_REQUEST UrbControlVendorClassRequest
Definition: usb.h:548
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
LONG NTSTATUS
Definition: precomp.h:26
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFQUEUE _In_ _Strict_type_match_ WDF_REQUEST_TYPE RequestType
Definition: wdfdevice.h:4227
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
Status
Definition: gdiplustypes.h:24
_In_ WDFCOLLECTION _In_ ULONG Index
struct _URB * PURB
Definition: usb.h:529
#define URB_FUNCTION_CLASS_INTERFACE
Definition: usb.h:113
NTSTATUS USBSTOR_SyncUrbRequest(IN PDEVICE_OBJECT DeviceObject, OUT PURB UrbRequest)
Definition: misc.c:84
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
Definition: misc.c:30

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 34 of file misc.c.

37 {
38  KEVENT Event;
40  PIRP Irp;
43 
45  ASSERT(BusInterface);
46 
48 
51  NULL,
52  0,
53  NULL,
54  &Event,
55  &IoStatus);
56  if (Irp == NULL)
57  {
59  }
60 
61  // initialize request
63  Stack->MajorFunction = IRP_MJ_PNP;
64  Stack->MinorFunction = IRP_MN_QUERY_INTERFACE;
65  Stack->Parameters.QueryInterface.Size = sizeof(BUS_INTERFACE_STANDARD);
66  Stack->Parameters.QueryInterface.InterfaceType = (LPGUID)&USB_BUS_INTERFACE_USBDI_GUID;
67  Stack->Parameters.QueryInterface.Version = 2;
68  Stack->Parameters.QueryInterface.Interface = (PINTERFACE)BusInterface;
69  Stack->Parameters.QueryInterface.InterfaceSpecificData = NULL;
70  Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
71 
73 
74  if (Status == STATUS_PENDING)
75  {
77  Status = IoStatus.Status;
78  }
79 
80  return Status;
81 }
return STATUS_NOT_SUPPORTED
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
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 IRP_MJ_PNP
Definition: cdrw_usr.h:52
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
Definition: wdfrequest.h:636
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:467
struct _INTERFACE * PINTERFACE
Status
Definition: gdiplustypes.h:24
#define ASSERT(a)
Definition: mode.c:44
#define STATUS_PENDING
Definition: ntstatus.h:82
#define IRP_MN_QUERY_INTERFACE
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2695
struct _BUS_INTERFACE_STANDARD BUS_INTERFACE_STANDARD
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define NULL
Definition: types.h:112
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
__in UCHAR __in POWER_STATE __in_opt PVOID __in PIO_STATUS_BLOCK IoStatus
Definition: mxum.h:155
GUID * LPGUID
Definition: guiddef.h:81

Referenced by USBSTOR_FdoHandleStartDevice().

◆ USBSTOR_GetMaxLUN()

NTSTATUS USBSTOR_GetMaxLUN ( IN PDEVICE_OBJECT  DeviceObject,
IN PFDO_DEVICE_EXTENSION  DeviceExtension 
)

Definition at line 181 of file misc.c.

184 {
185  PUCHAR Buffer;
187 
189  if (!Buffer)
190  {
192  }
193 
194  Status = USBSTOR_ClassRequest(DeviceObject, DeviceExtension, USB_BULK_GET_MAX_LUN, DeviceExtension->InterfaceInformation->InterfaceNumber, USBD_TRANSFER_DIRECTION_IN, sizeof(UCHAR), Buffer);
195 
196  DPRINT("MaxLUN: %x\n", *Buffer);
197 
198  if (NT_SUCCESS(Status))
199  {
200  if (*Buffer > MAX_LUN)
201  {
202  // invalid response documented in usb mass storage specification
204  }
205  else
206  {
207  // store maxlun
208  DeviceExtension->MaxLUN = *Buffer;
209  }
210  }
211  else
212  {
213  // "USB Mass Storage Class. Bulk-Only Transport. Revision 1.0"
214  // 3.2 Get Max LUN (class-specific request) :
215  // Devices that do not support multiple LUNs may STALL this command.
216  USBSTOR_ResetDevice(DeviceExtension->LowerDeviceObject, DeviceExtension);
217 
218  DeviceExtension->MaxLUN = 0;
220  }
221 
223  return Status;
224 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
#define USBD_TRANSFER_DIRECTION_IN
Definition: usb.h:160
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
NTSTATUS USBSTOR_ResetDevice(IN PDEVICE_OBJECT DeviceObject, IN PFDO_DEVICE_EXTENSION DeviceExtension)
Definition: misc.c:227
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:147
Definition: bufpool.h:45
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define MAX_LUN
Definition: usbstor.h:61
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
unsigned char UCHAR
Definition: xmlstorage.h:181
#define USB_STOR_TAG
Definition: usbstor.h:10
#define USB_BULK_GET_MAX_LUN
Definition: usbstor.h:54
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define STATUS_DEVICE_DATA_ERROR
Definition: udferr_usr.h:159

Referenced by USBSTOR_FdoHandleStartDevice().

◆ USBSTOR_ResetDevice()

NTSTATUS USBSTOR_ResetDevice ( IN PDEVICE_OBJECT  DeviceObject,
IN PFDO_DEVICE_EXTENSION  DeviceExtension 
)

Definition at line 227 of file misc.c.

230 {
232 
233  Status = USBSTOR_ClassRequest(DeviceObject, DeviceExtension, USB_BULK_RESET_DEVICE, DeviceExtension->InterfaceInformation->InterfaceNumber, USBD_TRANSFER_DIRECTION_OUT, 0, NULL);
234  return Status;
235 }
#define USB_BULK_RESET_DEVICE
Definition: usbstor.h:55
LONG NTSTATUS
Definition: precomp.h:26
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
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:147
#define USBD_TRANSFER_DIRECTION_OUT
Definition: usb.h:159
Status
Definition: gdiplustypes.h:24
#define NULL
Definition: types.h:112

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 20 of file misc.c.

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

◆ USBSTOR_SyncUrbRequest()

NTSTATUS USBSTOR_SyncUrbRequest ( IN PDEVICE_OBJECT  DeviceObject,
OUT PURB  UrbRequest 
)

Definition at line 84 of file misc.c.

87 {
88  PIRP Irp;
89  PIO_STACK_LOCATION IoStack;
90  KEVENT Event;
92 
93  Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
94  if (!Irp)
95  {
97  }
98 
100 
101  IoStack = IoGetNextIrpStackLocation(Irp);
102 
103  // initialize stack location
105  IoStack->Parameters.DeviceIoControl.IoControlCode = IOCTL_INTERNAL_USB_SUBMIT_URB;
106  IoStack->Parameters.Others.Argument1 = (PVOID)UrbRequest;
107  IoStack->Parameters.DeviceIoControl.InputBufferLength = UrbRequest->UrbHeader.Length;
108  Irp->IoStatus.Status = STATUS_SUCCESS;
109 
111 
113 
114  if (Status == STATUS_PENDING)
115  {
117  Status = Irp->IoStatus.Status;
118  }
119 
120  IoFreeIrp(Irp);
121  return Status;
122 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define IOCTL_INTERNAL_USB_SUBMIT_URB
Definition: usbioctl.h:32
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:498
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:467
NTSTATUS NTAPI USBSTOR_SyncForwardIrpCompletionRoutine(PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Context)
Definition: misc.c:22
Status
Definition: gdiplustypes.h:24
#define STATUS_PENDING
Definition: ntstatus.h:82
#define IRP_MJ_INTERNAL_DEVICE_CONTROL
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2695
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define NULL
Definition: types.h:112
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
VOID NTAPI IoFreeIrp(IN PIRP Irp)
Definition: irp.c:1666
static PVOID
Definition: misc.c:50
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
Definition: irp.c:615
#define STATUS_SUCCESS
Definition: shellext.h:65
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3128

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

Variable Documentation

◆ SyncForwardIrpCompletionRoutine

IO_COMPLETION_ROUTINE SyncForwardIrpCompletionRoutine

Definition at line 16 of file misc.c.