ReactOS  0.4.15-dev-2961-gecb0c09
fxusbpipeum.cpp
Go to the documentation of this file.
1 //
2 // Copyright (C) Microsoft. All rights reserved.
3 //
4 #include "fxusbpch.hpp"
5 
6 extern "C" {
7 #include "FxUsbPipeUm.tmh"
8 }
9 
10 #include "Fxglobals.h"
11 
12 VOID
15  __in WINUSB_INTERFACE_HANDLE WinUsbHandle,
16  __in UCHAR PipeId,
18  )
19 {
20  RtlZeroMemory(&m_UmUrb, sizeof(m_UmUrb));
21 
22  m_UmUrb.UmUrbPipeRequest.Hdr.InterfaceHandle = WinUsbHandle;
23  m_UmUrb.UmUrbPipeRequest.Hdr.Function = Function;
24  m_UmUrb.UmUrbPipeRequest.Hdr.Length = sizeof(m_UmUrb.UmUrbPipeRequest);
25 
26  m_UmUrb.UmUrbPipeRequest.PipeID = PipeId;
27 
29 }
30 
31 VOID
34  )
35 /*++
36 
37 Routine Description:
38  virtual function which stores and references memory if it is an FxObject
39  and then fills in the appropriate fields in the URB.
40 
41 Arguments:
42  Buffer - union which can be many types of memory
43 
44 Return Value:
45  None
46 
47  --*/
48 {
49  RtlZeroMemory(&m_UmUrb, sizeof(m_UmUrb));
50 
53 
55 
56  Buffer->AssignValues(&m_UmUrb.UmUrbBulkOrInterruptTransfer.TransferBuffer,
57  NULL,
58  &m_UmUrb.UmUrbBulkOrInterruptTransfer.TransferBufferLength);
59 }
60 
61 VOID
63  __in MdDeviceObject /*DeviceObject*/,
65  )
66 {
67  FxUsbPipeRepeatReader * pRepeater;
68  pRepeater = (FxUsbPipeRepeatReader *)Context;
69 
70  pRepeater->RequestIrp->Forward();
71 }
72 
77  __in size_t TotalBufferLength
78  )
79 {
81  WDF_OBJECT_ATTRIBUTES attributes;
83  LONG i;
84 
86 
87 #if (FX_CORE_MODE == FX_CORE_KERNEL_MODE)
88  if (TotalBufferLength <= MAXUSHORT) {
91  }
92  else {
95  }
96 #elif (FX_CORE_MODE == FX_CORE_USER_MODE)
99 #endif
100 
101  if (m_Lookaside == NULL) {
103  }
104 
105  if (Config->BufferAttributes == NULL) {
106  WDF_OBJECT_ATTRIBUTES_INIT(&attributes);
107  }
108  else {
109  RtlCopyMemory(&attributes,
110  Config->BufferAttributes,
111  sizeof(WDF_OBJECT_ATTRIBUTES));
112  }
113 
114  //
115  // By specifying the loookaside as the parent for the memory objects that
116  // will be created, when we destroy the lookaside list, we will destroy any
117  // outstanding memory objects that have been allocated. This can happen if
118  // we initialize the repeater, but never send any i/o. (Normally the
119  // memory object would be freed when the read completes.)
120  //
121  attributes.ParentObject = m_Lookaside->GetObjectHandle();
122 
123  status = m_Lookaside->Initialize(TotalBufferLength, &attributes);
124  if (!NT_SUCCESS(status)) {
125  return status;
126  }
127 
130  &m_WorkItem
131  );
132  if (!NT_SUCCESS(status)) {
134  "Could not allocate workitem: %!STATUS!", status);
135  return status;
136  }
137 
138  m_Offsets.BufferLength = Config->TransferLength;
139  m_Offsets.BufferOffset = Config->HeaderLength;
140 
141  for (i = 0; i < m_NumReaders; i++) {
142  FxUsbPipeRepeatReader* pRepeater;
143 
144  pRepeater = &m_Readers[i];
145 
146  pRepeater->Parent = this;
147 
148 #if (FX_CORE_MODE == FX_CORE_KERNEL_MODE)
150 #elif (FX_CORE_MODE == FX_CORE_USER_MODE)
151  pRepeater->m_ReadWorkItem.Allocate(m_Pipe->m_Device->GetDeviceObject());
152 #endif
153 
154  //
155  // This will allocate the PIRP
156  //
159  NULL,
160  m_Pipe,
163  &pRepeater->Request);
164 
165  if (!NT_SUCCESS(status)) {
166  return status;
167  }
168 
169  pRepeater->RequestIrp = pRepeater->Request->GetSubmitIrp();
170 
171  //
172  // Initialize the event before FormatRepeater clears it
173  //
175 
176  if (!NT_SUCCESS(status)) {
179  "Could not initialize ReadCompletedEvent: %!STATUS!",
180  status);
181 
182  return status;
183  }
184 
185  //
186  // This will allocate the context
187  //
188  status = FormatRepeater(pRepeater);
189 
190  if (!NT_SUCCESS(status)) {
191  return status;
192  }
193  }
194 
195  return STATUS_SUCCESS;
196 }
197 
198 VOID
200  __in PWINUSB_PIPE_INFORMATION PipeInfo,
203  )
204 {
207 
208  if (m_UsbInterface != NULL) {
209  m_UsbInterface->RELEASE(this);
211  }
212 
214  m_UsbInterface->ADDREF(this);
215 }
216 
218 NTSTATUS
222  __in ULONG TransferFlags
223  )
224 {
225  FxUsbPipeTransferContext* pContext;
227  size_t bufferSize;
228  ULONG dummyLength;
229 
230  //
231  // Make sure request is for the right type
232  //
235 
237  "WDFUSBPIPE %p not the right type, %!STATUS!",
238  GetHandle(), status);
239 
240  return status;
241  }
242 
243  bufferSize = Buffer->GetBufferLength();
244 
245  status = RtlSizeTToULong(bufferSize, &dummyLength);
246  if (!NT_SUCCESS(status)) {
248  "WDFUSBPIPE %p, buffer size truncated, %!STATUS!",
249  GetHandle(), status);
250  return status;
251  }
252 
253  //
254  // On reads, check to make sure the read in value is an integral number of
255  // packet sizes
256  //
257  if (TransferFlags & USBD_TRANSFER_DIRECTION_IN) {
258  if (IsInEndpoint() == FALSE) {
260  "Pipe %p, sending __in transaction on a __out endpoint",
261  this);
262 
264  }
265 
266  if (m_CheckPacketSize &&
267  (bufferSize % m_PipeInformationUm.MaximumPacketSize) != 0) {
269  }
270  }
271  else {
272  if (IsOutEndpoint() == FALSE) {
274  "Pipe %p, sending __out transaction on an __in endpoint",
275  this);
276 
278  }
279  }
280 
281  status = Request->ValidateTarget(this);
282  if (!NT_SUCCESS(status)) {
284  "Pipe %p, Request %p, setting target failed, "
285  "status %!STATUS!", this, Request, status);
286 
287  return status;
288  }
289 
290  if (Request->HasContextType(FX_RCT_USB_PIPE_XFER)) {
291  pContext = (FxUsbPipeTransferContext*) Request->GetContext();
292  }
293  else {
295  if (pContext == NULL) {
297  }
298 
299  Request->SetContext(pContext);
300  }
301 
302  pContext->StoreAndReferenceMemory(Buffer);
303 
304  pContext->m_UmUrb.UmUrbHeader.InterfaceHandle = m_UsbInterface->m_WinUsbHandle;
305 
306  pContext->m_UmUrb.UmUrbBulkOrInterruptTransfer.PipeID = m_PipeInformationUm.PipeId;
308 
310 
311  return STATUS_SUCCESS;
312 }
313 
314 VOID
317  )
318 {
319 
320 
321 
322 
323  PipeInformation->MaximumPacketSize = m_PipeInformationUm.MaximumPacketSize;
324  PipeInformation->EndpointAddress = m_PipeInformationUm.PipeId;
325  PipeInformation->Interval = m_PipeInformationUm.Interval;
328 }
329 
332  VOID
333  )
334 {
335  return _UsbdPipeTypeToWdf(m_PipeInformationUm.PipeType);
336 }
337 
338 BOOLEAN
341  )
342 {
343  return _UsbdPipeTypeToWdf(m_PipeInformationUm.PipeType) == Type ? TRUE : FALSE;
344 }
345 
#define UMURB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER
Definition: umusb.h:17
CfxDevice * m_Device
Definition: fxobject.hpp:329
_Must_inspect_result_ NTSTATUS FormatTransferRequest(__in FxRequestBase *Request, __in FxRequestBuffer *Buffer, __in ULONG TransferFlags=0)
#define RtlSizeTToULong
WINUSB_INTERFACE_HANDLE m_WinUsbHandle
struct _UMURB_PIPE_REQUEST UmUrbPipeRequest
Definition: umusb.h:186
static _Must_inspect_result_ NTSTATUS _Create(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PVOID WdmObject, __out FxSystemWorkItem **pObject)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
static MX_WORKITEM_ROUTINE _ReadWorkItem
Definition: fxusbpipe.hpp:310
_In_ CDROM_SCAN_FOR_SPECIAL_INFO _In_ PCDROM_SCAN_FOR_SPECIAL_HANDLER Function
Definition: cdrom.h:1154
MdDeviceObject __inline GetDeviceObject(VOID)
Definition: fxdevice.hpp:174
#define __in_opt
Definition: dbghelp.h:38
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
struct _UMURB_HEADER UmUrbHeader
Definition: umusb.h:175
#define USBD_TRANSFER_DIRECTION_IN
Definition: usb.h:160
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
static _Must_inspect_result_ NTSTATUS _Create(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in_opt PWDF_OBJECT_ATTRIBUTES RequestAttributes, __in_opt MdIrp Irp, __in_opt FxIoTarget *Target, __in FxRequestIrpOwnership Ownership, __in FxRequestConstructorCaller Caller, __deref_out FxRequest **Request)
Definition: fxrequest.cpp:161
_In_ WDFREQUEST Request
Definition: wdfdevice.h:547
__inline BOOLEAN IsOutEndpoint(VOID)
Definition: fxusbpipe.hpp:531
#define TRACE_LEVEL_INFORMATION
Definition: storswtr.h:29
FxUsbDevice * m_UsbDevice
Definition: fxusbpipe.hpp:698
FxSystemWorkItem * m_WorkItem
Definition: fxusbpipe.hpp:360
_In_ WDFUSBPIPE _Out_ PWDF_USB_PIPE_INFORMATION PipeInformation
Definition: wdfusb.h:1741
BOOLEAN IsType(__in WDF_USB_PIPE_TYPE Type)
__inline BOOLEAN IsInEndpoint(VOID)
Definition: fxusbpipe.hpp:513
CHECK_RETURN_IF_USER_MODE __inline NTSTATUS Initialize(__in EVENT_TYPE Type, __in BOOLEAN InitialState)
Definition: mxeventkm.h:55
#define FALSE
Definition: types.h:117
long LONG
Definition: pedump.c:60
size_t BufferOffset
Definition: wdfmemory.h:65
VOID SetUsbType(__in WDF_USB_REQUEST_TYPE Type)
PVOID __inline GetObjectHandle(VOID)
Definition: fxobject.hpp:603
#define __out
Definition: dbghelp.h:62
unsigned char BOOLEAN
Definition: bufpool.h:45
static MdDeferredRoutineType _FxUsbPipeContinuousReadDpc
Definition: fxusbpipe.hpp:306
_Must_inspect_result_ NTSTATUS Config(__in PWDF_USB_CONTINUOUS_READER_CONFIG Config, __in size_t TotalBufferLength)
Definition: fxusbpipekm.cpp:88
VOID GetInformation(__out PWDF_USB_PIPE_INFORMATION PipeInformation)
#define STATUS_INVALID_BUFFER_SIZE
Definition: ntstatus.h:650
_In_ PVOID _In_ LONG InterfaceNumber
Definition: usbdlib.h:168
virtual _Must_inspect_result_ NTSTATUS Initialize(__in size_t BufferSize, __in PWDF_OBJECT_ATTRIBUTES MemoryAttributes)=0
PFX_DRIVER_GLOBALS pFxDriverGlobals
__inline MdIrp GetSubmitIrp(VOID)
_In_ WDFUSBINTERFACE UsbInterface
Definition: wdfusb.h:2276
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
WDFUSBPIPE GetHandle(VOID)
Definition: fxusbpipe.hpp:504
FxLookasideList * m_Lookaside
Definition: fxusbpipe.hpp:345
Type
Definition: Type.h:6
struct _UMURB_BULK_OR_INTERRUPT_TRANSFER UmUrbBulkOrInterruptTransfer
Definition: umusb.h:203
VOID SetInfo(__in WDF_USB_REQUEST_TYPE Type, __in USBD_PIPE_HANDLE PipeHandle, __in USHORT Function)
Definition: fxusbpipe.cpp:1028
FxUsbInterface * m_UsbInterface
Definition: fxusbpipe.hpp:700
unsigned char UCHAR
Definition: xmlstorage.h:181
size_t BufferLength
Definition: wdfmemory.h:72
WDF_USB_PIPE_TYPE GetType(VOID)
size_t bufferSize
UCHAR GetConfiguredSettingIndex(VOID)
virtual VOID StoreAndReferenceMemory(__in FxRequestBuffer *Buffer)
#define _Must_inspect_result_
Definition: ms_sal.h:558
_In_ WDFUSBINTERFACE _In_ UCHAR _Out_opt_ PWDF_USB_PIPE_INFORMATION PipeInfo
Definition: wdfusb.h:2538
VOID FxUsbUmFormatRequest(__in FxRequestBase *Request, __in_xcount(Urb->Length) PUMURB_HEADER Urb, __in IWudfFile *HostFile, __in BOOLEAN Reuse)
Definition: usbutil.cpp:486
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_CHILD_LIST_CONFIG Config
Definition: wdfchildlist.h:474
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
_Must_inspect_result_ NTSTATUS FormatRepeater(__in FxUsbPipeRepeatReader *Repeater)
Definition: fxusbpipe.cpp:687
FORCEINLINE VOID WDF_OBJECT_ATTRIBUTES_INIT(_Out_ PWDF_OBJECT_ATTRIBUTES Attributes)
Definition: wdfobject.h:147
FxUsbPipeRepeatReader m_Readers[1]
Definition: fxusbpipe.hpp:406
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned short USHORT
Definition: pedump.c:61
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
WDFOBJECT ParentObject
Definition: wdfobject.h:130
WDFMEMORY_OFFSET m_Offsets
Definition: fxusbpipe.hpp:355
#define NULL
Definition: types.h:112
#define WDF_NO_OBJECT_ATTRIBUTES
Definition: wdftypes.h:105
#define MAXUSHORT
Definition: typedefs.h:83
UCHAR m_InterfaceNumber
Definition: fxusbpipe.hpp:726
enum _WDF_USB_PIPE_TYPE WDF_USB_PIPE_TYPE
WINUSB_PIPE_INFORMATION m_PipeInformationUm
Definition: fxusbpipe.hpp:720
unsigned int ULONG
Definition: retypes.h:1
FxUsbPipeContinuousReader * Parent
Definition: fxusbpipe.hpp:194
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
IWudfFile * m_pHostTargetFile
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define STATUS_SUCCESS
Definition: shellext.h:65
#define TRACINGIO
Definition: dbgtrace.h:66
BOOLEAN m_CheckPacketSize
Definition: fxusbpipe.hpp:732
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
Definition: dpc.c:712
#define __in
Definition: dbghelp.h:35
static SERVICE_STATUS status
Definition: service.c:31
#define TRACINGIOTARGET
Definition: dbgtrace.h:72
static WDF_USB_PIPE_TYPE _UsbdPipeTypeToWdf(__in USBD_PIPE_TYPE UsbdPipeType)
Definition: fxusbpipe.hpp:643
enum _WDF_USB_REQUEST_TYPE WDF_USB_REQUEST_TYPE
VOID InitPipe(__in PUSBD_PIPE_INFORMATION PipeInfo, __in UCHAR InterfaceNumber, __in FxUsbInterface *UsbInterface)
Definition: fxusbpipe.cpp:1073
virtual VOID StoreAndReferenceMemory(__in FxRequestBuffer *Buffer)
Definition: fxusbpipekm.cpp:13
Definition: ps.c:97