ReactOS  0.4.15-dev-2947-g59e1b78
fxusbdeviceapikm.cpp
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) Microsoft Corporation
4 
5 Module Name:
6 
7  FxUsbDeviceAPI.cpp
8 
9 Abstract:
10 
11 
12 Author:
13 
14 Environment:
15 
16  kernel mode only
17 
18 Revision History:
19 
20 --*/
21 
22 #include "fxusbpch.hpp"
23 
24 extern "C" {
25 #include "FxUsbDeviceApiKm.tmh"
26 }
27 
28 //
29 // Extern "C" all APIs
30 //
31 extern "C" {
32 
36 WDFAPI
37 WDFEXPORT(WdfUsbTargetDeviceRetrieveCurrentFrameNumber)(
38  __in
40  __in
41  WDFUSBDEVICE UsbDevice,
42  __out
44  )
45 {
46  DDI_ENTRY();
47 
50 
52  UsbDevice,
54  (PVOID*) &pUsbDevice,
56 
58 
60 }
61 
65 WDFAPI
66 WDFEXPORT(WdfUsbTargetDeviceSendUrbSynchronously)(
67  __in
69  __in
70  WDFUSBDEVICE UsbDevice,
71  __in_opt
72  WDFREQUEST Request,
73  __in_opt
75  __in_xcount("union bug in SAL")
76  PURB Urb
77  )
78 {
83 
85  UsbDevice,
87  (PVOID*) &pUsbDevice,
89 
91  FxSyncRequest request(pFxDriverGlobals, &context, Request);
92 
93  //
94  // FxSyncRequest always succeesds for KM but can fail for UM.
95  //
96  status = request.Initialize();
97  if (!NT_SUCCESS(status)) {
99  "Failed to initialize FxSyncRequest");
100  return status;
101  }
102 
104  "WDFUSBDEVICE %p, Urb %p", UsbDevice, Urb);
105 
107 
109  if (!NT_SUCCESS(status)) {
110  return status;
111  }
112 
114  if (!NT_SUCCESS(status)) {
115  return status;
116  }
117 
118  buf.SetBuffer(Urb, 0);
119 
121  pUsbDevice,
122  request.m_TrueRequest,
123  &buf,
126 
127  if (NT_SUCCESS(status)) {
130  "WDFUSBDEVICE %p, WDFREQUEST %p being submitted",
131  UsbDevice, request.m_TrueRequest->GetTraceObjectHandle());
132 
134  }
135 
137  "Device %p, Urb %p, %!STATUS!",
138  UsbDevice, Urb, status);
139 
140  return status;
141 }
142 
145 NTSTATUS
146 WDFAPI
147 WDFEXPORT(WdfUsbTargetDeviceFormatRequestForUrb)(
148  __in
150  __in
151  WDFUSBDEVICE UsbDevice,
152  __in
153  WDFREQUEST Request,
154  __in
155  WDFMEMORY UrbMemory,
156  __in_opt
158  )
159 {
160  DDI_ENTRY();
161 
168  size_t bufferSize;
169 
171  UsbDevice,
173  (PVOID*) &pUsbDevice,
175 
177  "WDFUSBDEVICE %p, Request %p, Memory %p",
179 
181 
183  UrbMemory,
185  (PVOID*) &pMemory);
186 
188  Request,
190  (PVOID*) &pRequest);
191 
194  return status;
195  }
196 
200  }
201 
202  if (bufferSize < sizeof(_URB_HEADER)) {
205  "UrbMemory %p buffer size, %I64d, smaller then"
206  "_URB_HEADER, %!STATUS!",
208  return status;
209  }
210 
211  buf.SetMemory(pMemory, UrbOffsets);
212 
214  pUsbDevice,
215  pRequest,
216  &buf,
219 
221  FxUsbUrbContext* pContext;
222  pContext = (FxUsbUrbContext*) pRequest->GetContext();
223 
225  pContext->m_UsbParameters.Parameters.DeviceUrb.Buffer = UrbMemory;
226  }
227 
229  "WDFUSBDEVICE %p, Request %p, Memory %p, %!STATUS!",
231 
232  return status;
233 }
234 
237 NTSTATUS
238 WDFAPI
239 WDFEXPORT(WdfUsbTargetDeviceIsConnectedSynchronous)(
240  __in
242  __in
243  WDFUSBDEVICE UsbDevice
244  )
245 {
246  DDI_ENTRY();
247 
251 
253  UsbDevice,
255  (PVOID*) &pUsbDevice,
257 
259  if (!NT_SUCCESS(status)) {
260  return status;
261  }
262 
264 
265  return status;
266 }
267 
270 NTSTATUS
271 WDFEXPORT(WdfUsbTargetDeviceCyclePortSynchronously)(
272  __in
274  __in
275  WDFUSBDEVICE UsbDevice
276  )
277 /*++
278 
279 Routine Description:
280  Synchronously cycles a device on a USB port. This will cause the device
281  to be surprise removed and reenumerated. Very similar to the reenumerate
282  interface we use in the pnp state machine. Usually a driver will do this
283  after it has downloaded firmware and wants to be reenumerated as a new
284  device.
285 
286 
287 
288 
289 Arguments:
290  UsbDevice - the IOTARGET representing the device
291 
292 Return Value:
293  NTSTATUS
294 
295  --*/
296 {
297  DDI_ENTRY();
298 
302 
304  UsbDevice,
306  (PVOID*) &pUsbDevice,
308 
310  if (!NT_SUCCESS(status)) {
311  return status;
312  }
313 
315 
316  return status;
317 }
318 
321 NTSTATUS
322 WDFEXPORT(WdfUsbTargetDeviceFormatRequestForCyclePort)(
323  __in
325  __in
326  WDFUSBDEVICE UsbDevice,
327  __in
328  WDFREQUEST Request
329  )
330 /*++
331 
332 Routine Description:
333  Formats a WDFREQUEST so that it will cycle the port and reenumerate the
334  device when sent.
335 
336 Arguments:
337  UsbDevice - the IOTARGET representing the device that will be reenumerated
338 
339  Request - the request which will be formatted
340 
341 Return Value:
342  NTSTATUS
343 
344  --*/
345 {
346  DDI_ENTRY();
347 
352 
354  UsbDevice,
356  (PVOID*) &pUsbDevice,
358 
360  Request,
362  (PVOID*) &pRequest);
363 
365 
366  return status;
367 }
368 
371 NTSTATUS
372 WDFAPI
373 WDFEXPORT(WdfUsbTargetDeviceCreateUrb)(
374  __in
376  __in
377  WDFUSBDEVICE UsbDevice,
378  __in_opt
380  __out
381  WDFMEMORY* UrbMemory,
383  PURB* Urb
384  )
385 /*++
386 
387 Routine Description:
388  Creates a WDFUSBDEVICE handle for the client.
389 
390 Arguments:
391  Attributes - Attributes associated with this object
392 
393  UrbMemory - The returned handle to the caller for the allocated Urb
394 
395  Urb - (opt) Pointer to the associated urb buffer.
396 
397 Return Value:
398  STATUS_INVALID_PARAMETER - any required parameters are not present/invalid
399 
400  STATUS_INVALID_DEVICE_STATE - If the client did not specify a client contract verion while
401  creating the WDFUSBDEVICE
402 
403  STATUS_INSUFFICIENT_RESOURCES - could not allocated the object that backs
404  the handle
405 
406  STATUS_SUCCESS - success
407 
408  ...
409 
410  --*/
411 {
412  DDI_ENTRY();
413 
417 
419  UsbDevice,
421  (PVOID*) &pUsbDevice,
423 
424  //
425  // Basic parameter validation
426  //
428 
429  if (pUsbDevice->GetUSBDHandle() == NULL) {
431 
434  "USBDEVICE Must have been created with Client Contract Verion Info, %!STATUS!",
435  status);
436 
437  return status;
438  }
439 
441 
442  return status;
443 }
444 
445 } // extern "C"
#define DDI_ENTRY()
Definition: fxglobalskm.h:56
_Must_inspect_result_ __inline NTSTATUS GetCurrentFrameNumber(__in PULONG Current)
_Must_inspect_result_ NTSTATUS ValidateMemoryOffsets(__in_opt PWDFMEMORY_OFFSET Offsets)
Definition: ifxmemory.hpp:105
FxObjectHandleGetPtr(pFxDriverGlobals, UrbMemory, IFX_TYPE_MEMORY,(PVOID *) &pMemory)
FX_URB_TYPE GetUrbType(VOID)
__checkReturn NTSTATUS CreateUrb(__in_opt PWDF_OBJECT_ATTRIBUTES Attributes, __out WDFMEMORY *UrbMemory, __deref_opt_out_bcount(sizeof(URB)) PURB *Urb)
Definition: http.c:7251
struct _WDF_USB_REQUEST_COMPLETION_PARAMS::@3690::@3693 DeviceUrb
#define __in_opt
Definition: dbghelp.h:38
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
FxRequestBuffer buf
USBD_HANDLE GetUSBDHandle(VOID)
_In_ WDFREQUEST Request
Definition: wdfdevice.h:547
_Must_inspect_result_ NTSTATUS SubmitSync(__in FxRequestBase *Request, __in_opt PWDF_REQUEST_SEND_OPTIONS Options=NULL, __out_opt PULONG Action=NULL)
DriverGlobals
_Must_inspect_result_ __in WDFUSBDEVICE UsbDevice
__checkReturn __in WDFUSBDEVICE __in_opt PWDF_OBJECT_ATTRIBUTES __out WDFMEMORY __deref_opt_out_bcount(sizeof(URB)) PURB *Urb)
size_t bufferSize
NTSTATUS __inline FxValidateRequestOptions(_In_ PFX_DRIVER_GLOBALS FxDriverGlobals, _In_ PWDF_REQUEST_SEND_OPTIONS Options, _In_opt_ FxRequestBase *Request=NULL)
#define STATUS_INVALID_DEVICE_STATE
Definition: udferr_usr.h:178
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
FxRequest * request
_Must_inspect_result_ __in WDFUSBDEVICE __in WDFREQUEST __in WDFMEMORY __in_opt PWDFMEMORY_OFFSET UrbOffsets
_Must_inspect_result_ __in WDFUSBDEVICE __in_opt WDFREQUEST Request
#define TRACE_LEVEL_VERBOSE
Definition: storswtr.h:30
#define WDFEXPORT(a)
Definition: fxmacros.hpp:157
size_t BufferOffset
Definition: wdfmemory.h:65
#define WDFAPI
Definition: wdftypes.h:53
_Must_inspect_result_ __drv_maxIRQL(DISPATCH_LEVEL) NTSTATUS WDFAPI WDFEXPORT(WdfUsbTargetDeviceRetrieveCurrentFrameNumber)(__in PWDF_DRIVER_GLOBALS DriverGlobals
VOID SetUsbType(__in WDF_USB_REQUEST_TYPE Type)
#define __out
Definition: dbghelp.h:62
_Must_inspect_result_ NTSTATUS FormatCycleRequest(__in FxRequestBase *Request)
PFX_DRIVER_GLOBALS pFxDriverGlobals
_Must_inspect_result_ __in WDFUSBDEVICE __in_opt WDFREQUEST __in_opt PWDF_REQUEST_SEND_OPTIONS RequestOptions
FxUsbDevice * pUsbDevice
__inline NTSTATUS FxVerifierCheckIrqlLevel(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in KIRQL Irql)
Definition: fxverifier.h:158
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS status
_Must_inspect_result_ _In_ WDFDEVICE _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFUSBDEVICE * UsbDevice
Definition: wdfusb.h:901
_In_opt_ PVOID _In_ ULONG _In_ PVOID context
Definition: wdfdriver.h:113
_Must_inspect_result_ __in WDFUSBDEVICE __out PULONG CurrentFrameNumber
FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals), UsbDevice, FX_TYPE_IO_TARGET_USB_DEVICE,(PVOID *) &pUsbDevice, &pFxDriverGlobals)
WDF_USB_REQUEST_COMPLETION_PARAMS m_UsbParameters
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define _Must_inspect_result_
Definition: ms_sal.h:558
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
union _WDF_USB_REQUEST_COMPLETION_PARAMS::@3690 Parameters
NTSTATUS FxFormatUrbRequest(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in FxIoTarget *Target, __in FxRequestBase *Request, __in FxRequestBuffer *Buffer, __in FX_URB_TYPE FxUrbType, __drv_when(FxUrbType==FxUrbTypeUsbdAllocated, __in) __drv_when(FxUrbType !=FxUrbTypeUsbdAllocated, __in_opt) USBD_HANDLE UsbdHandle)
Definition: usbutil.cpp:62
_Must_inspect_result_ NTSTATUS CyclePort(VOID)
Definition: usb.h:529
FxPointerNotNull(pFxDriverGlobals, CurrentFrameNumber)
__inline FxRequestContext * GetContext(VOID)
unsigned int * PULONG
Definition: retypes.h:1
_Must_inspect_result_ __in WDFUSBDEVICE __in WDFREQUEST __in WDFMEMORY UrbMemory
#define NULL
Definition: types.h:112
Definition: tftpd.h:85
IFxMemory * pMemory
_Must_inspect_result_ _In_ WDFUSBDEVICE _Out_ PULONG CurrentFrameNumber
Definition: wdfusb.h:1300
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS RequestOptions
Definition: wdfiotarget.h:859
FxRequest * pRequest
_Must_inspect_result_ _In_ WDFUSBDEVICE _In_ WDFREQUEST _In_ WDFMEMORY UrbMemory
Definition: wdfusb.h:1572
__inline PFX_DRIVER_GLOBALS GetFxDriverGlobals(__in PWDF_DRIVER_GLOBALS DriverGlobals)
Definition: fxglobals.h:597
_Must_inspect_result_ NTSTATUS IsConnected(VOID)
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGIOTARGET, "WDFUSBDEVICE %p, Request %p, Memory %p", UsbDevice, Request, UrbMemory)
#define __in
Definition: dbghelp.h:35
__checkReturn __in WDFUSBDEVICE __in_opt PWDF_OBJECT_ATTRIBUTES Attributes
#define __checkReturn
Definition: ms_sal.h:2873
#define TRACINGIOTARGET
Definition: dbgtrace.h:72
virtual size_t GetBufferSize(VOID)=0
_Must_inspect_result_ __in WDFUSBDEVICE __in_opt WDFREQUEST __in_opt PWDF_REQUEST_SEND_OPTIONS __in_xcount("union bug in SAL") PURB Urb)
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes
Definition: ps.c:97