ReactOS 0.4.15-dev-7131-ge4d03f4
fxusbdeviceapikm.cpp
Go to the documentation of this file.
1/*++
2
3Copyright (c) Microsoft Corporation
4
5Module Name:
6
7 FxUsbDeviceAPI.cpp
8
9Abstract:
10
11
12Author:
13
14Environment:
15
16 kernel mode only
17
18Revision History:
19
20--*/
21
22#include "fxusbpch.hpp"
23
24extern "C" {
25#include "FxUsbDeviceApiKm.tmh"
26}
27
28//
29// Extern "C" all APIs
30//
31extern "C" {
32
37WDFEXPORT(WdfUsbTargetDeviceRetrieveCurrentFrameNumber)(
38 __in
40 __in
41 WDFUSBDEVICE UsbDevice,
42 __out
44 )
45{
46 DDI_ENTRY();
47
50
54 (PVOID*) &pUsbDevice,
56
58
60}
61
66WDFEXPORT(WdfUsbTargetDeviceSendUrbSynchronously)(
67 __in
69 __in
70 WDFUSBDEVICE UsbDevice,
72 WDFREQUEST Request,
75 __in_xcount("union bug in SAL")
76 PURB Urb
77 )
78{
83
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
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
146WDFAPI
147WDFEXPORT(WdfUsbTargetDeviceFormatRequestForUrb)(
148 __in
150 __in
151 WDFUSBDEVICE UsbDevice,
152 __in
153 WDFREQUEST Request,
154 __in
155 WDFMEMORY UrbMemory,
158 )
159{
160 DDI_ENTRY();
161
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
215 pRequest,
216 &buf,
219
221 FxUsbUrbContext* pContext;
222 pContext = (FxUsbUrbContext*) pRequest->GetContext();
223
226 }
227
229 "WDFUSBDEVICE %p, Request %p, Memory %p, %!STATUS!",
231
232 return status;
233}
234
238WDFAPI
239WDFEXPORT(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
271WDFEXPORT(WdfUsbTargetDeviceCyclePortSynchronously)(
272 __in
274 __in
275 WDFUSBDEVICE UsbDevice
276 )
277/*++
278
279Routine 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
289Arguments:
290 UsbDevice - the IOTARGET representing the device
291
292Return 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
322WDFEXPORT(WdfUsbTargetDeviceFormatRequestForCyclePort)(
323 __in
325 __in
326 WDFUSBDEVICE UsbDevice,
327 __in
328 WDFREQUEST Request
329 )
330/*++
331
332Routine Description:
333 Formats a WDFREQUEST so that it will cycle the port and reenumerate the
334 device when sent.
335
336Arguments:
337 UsbDevice - the IOTARGET representing the device that will be reenumerated
338
339 Request - the request which will be formatted
340
341Return 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
372WDFAPI
373WDFEXPORT(WdfUsbTargetDeviceCreateUrb)(
374 __in
376 __in
377 WDFUSBDEVICE UsbDevice,
380 __out
381 WDFMEMORY* UrbMemory,
383 PURB* Urb
384 )
385/*++
386
387Routine Description:
388 Creates a WDFUSBDEVICE handle for the client.
389
390Arguments:
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
397Return 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"
LONG NTSTATUS
Definition: precomp.h:26
_Must_inspect_result_ NTSTATUS SubmitSync(__in FxRequestBase *Request, __in_opt PWDF_REQUEST_SEND_OPTIONS Options=NULL, __out_opt PULONG Action=NULL)
__inline FxRequestContext * GetContext(VOID)
_Must_inspect_result_ NTSTATUS FormatCycleRequest(__in FxRequestBase *Request)
_Must_inspect_result_ NTSTATUS IsConnected(VOID)
_Must_inspect_result_ __inline NTSTATUS GetCurrentFrameNumber(__in PULONG Current)
__checkReturn NTSTATUS CreateUrb(__in_opt PWDF_OBJECT_ATTRIBUTES Attributes, __out WDFMEMORY *UrbMemory, __deref_opt_out_bcount(sizeof(URB)) PURB *Urb)
_Must_inspect_result_ NTSTATUS CyclePort(VOID)
FX_URB_TYPE GetUrbType(VOID)
USBD_HANDLE GetUSBDHandle(VOID)
virtual size_t GetBufferSize(VOID)=0
_Must_inspect_result_ NTSTATUS ValidateMemoryOffsets(__in_opt PWDFMEMORY_OFFSET Offsets)
Definition: ifxmemory.hpp:105
#define __in
Definition: dbghelp.h:35
#define __in_opt
Definition: dbghelp.h:38
#define __out
Definition: dbghelp.h:62
#define TRACINGIOTARGET
Definition: dbgtrace.h:72
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define __drv_maxIRQL(irql)
Definition: driverspecs.h:291
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
DriverGlobals
__inline PFX_DRIVER_GLOBALS GetFxDriverGlobals(__in PWDF_DRIVER_GLOBALS DriverGlobals)
Definition: fxglobals.h:597
#define DDI_ENTRY()
Definition: fxglobalskm.h:56
#define WDFEXPORT(a)
Definition: fxmacros.hpp:157
#define FxPointerNotNull(FxDriverGlobals, Ptr)
Definition: fxmacros.hpp:253
NTSTATUS __inline FxValidateRequestOptions(_In_ PFX_DRIVER_GLOBALS FxDriverGlobals, _In_ PWDF_REQUEST_SEND_OPTIONS Options, _In_opt_ FxRequestBase *Request=NULL)
@ IFX_TYPE_MEMORY
Definition: fxtypes.h:55
@ FX_TYPE_REQUEST
Definition: fxtypes.h:53
@ FX_TYPE_IO_TARGET_USB_DEVICE
Definition: fxtypes.h:102
_Must_inspect_result_ __in WDFUSBDEVICE __in_opt WDFREQUEST __in_opt PWDF_REQUEST_SEND_OPTIONS RequestOptions
_Must_inspect_result_ __in WDFUSBDEVICE __in WDFREQUEST __in WDFMEMORY UrbMemory
FxUsbDevice * pUsbDevice
_Must_inspect_result_ __in WDFUSBDEVICE __in_opt WDFREQUEST Request
_Must_inspect_result_ __in WDFUSBDEVICE __out PULONG CurrentFrameNumber
FxObjectHandleGetPtr(pFxDriverGlobals, UrbMemory, IFX_TYPE_MEMORY,(PVOID *) &pMemory)
FxRequestBuffer buf
NTSTATUS status
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGIOTARGET, "WDFUSBDEVICE %p, Request %p, Memory %p", UsbDevice, Request, UrbMemory)
IFxMemory * pMemory
FxRequest * pRequest
_Must_inspect_result_ __in WDFUSBDEVICE UsbDevice
size_t bufferSize
_Must_inspect_result_ __in WDFUSBDEVICE __in WDFREQUEST __in WDFMEMORY __in_opt PWDFMEMORY_OFFSET UrbOffsets
__checkReturn __in WDFUSBDEVICE __in_opt PWDF_OBJECT_ATTRIBUTES Attributes
FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals), UsbDevice, FX_TYPE_IO_TARGET_USB_DEVICE,(PVOID *) &pUsbDevice, &pFxDriverGlobals)
PFX_DRIVER_GLOBALS pFxDriverGlobals
__inline NTSTATUS FxVerifierCheckIrqlLevel(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in KIRQL Irql)
Definition: fxverifier.h:158
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define __checkReturn
Definition: ms_sal.h:2873
#define _Must_inspect_result_
Definition: ms_sal.h:558
#define __deref_opt_out_bcount(size)
Definition: ms_sal.h:2812
#define __in_xcount(size)
Definition: specstrings.h:109
#define TRACE_LEVEL_VERBOSE
Definition: storswtr.h:30
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
VOID SetUsbType(__in WDF_USB_REQUEST_TYPE Type)
WDF_USB_REQUEST_COMPLETION_PARAMS m_UsbParameters
Definition: usb.h:529
size_t BufferOffset
Definition: wdfmemory.h:65
union _WDF_USB_REQUEST_COMPLETION_PARAMS::@3890 Parameters
struct _WDF_USB_REQUEST_COMPLETION_PARAMS::@3890::@3893 DeviceUrb
Definition: http.c:7252
Definition: tftpd.h:86
Definition: ps.c:97
uint32_t * PULONG
Definition: typedefs.h:59
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_INVALID_DEVICE_STATE
Definition: udferr_usr.h:178
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_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes
_In_ WDFREQUEST Request
Definition: wdfdevice.h:547
_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:867
#define WDFAPI
Definition: wdftypes.h:53
_Must_inspect_result_ _In_ WDFUSBDEVICE _In_ WDFREQUEST _In_ WDFMEMORY UrbMemory
Definition: wdfusb.h:1576
_Must_inspect_result_ _In_ WDFDEVICE _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFUSBDEVICE * UsbDevice
Definition: wdfusb.h:906
_Must_inspect_result_ _In_ WDFUSBDEVICE _Out_ PULONG CurrentFrameNumber
Definition: wdfusb.h:1303
@ WdfUsbRequestTypeDeviceUrb
Definition: wdfusb.h:91