ReactOS 0.4.16-dev-1946-g52006dd
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#if defined(EVENT_TRACING)
26#include "FxUsbDeviceApiKm.tmh"
27#endif
28}
29
30//
31// Extern "C" all APIs
32//
33extern "C" {
34
40WDFEXPORT(WdfUsbTargetDeviceRetrieveCurrentFrameNumber)(
41 __in
42 PWDF_DRIVER_GLOBALS DriverGlobals,
43 __in
44 WDFUSBDEVICE UsbDevice,
45 __out
47 )
48{
49 DDI_ENTRY();
50
53
57 (PVOID*) &pUsbDevice,
59
61
63}
64
70WDFEXPORT(WdfUsbTargetDeviceSendUrbSynchronously)(
71 __in
72 PWDF_DRIVER_GLOBALS DriverGlobals,
73 __in
74 WDFUSBDEVICE UsbDevice,
76 WDFREQUEST Request,
79 __in_xcount("union bug in SAL")
80 PURB Urb
81 )
82{
87
91 (PVOID*) &pUsbDevice,
93
95 FxSyncRequest request(pFxDriverGlobals, &context, Request);
96
97 //
98 // FxSyncRequest always succeesds for KM but can fail for UM.
99 //
100 status = request.Initialize();
101 if (!NT_SUCCESS(status)) {
103 "Failed to initialize FxSyncRequest");
104 return status;
105 }
106
108 "WDFUSBDEVICE %p, Urb %p", UsbDevice, Urb);
109
111
113 if (!NT_SUCCESS(status)) {
114 return status;
115 }
116
118 if (!NT_SUCCESS(status)) {
119 return status;
120 }
121
122 buf.SetBuffer(Urb, 0);
123
126 request.m_TrueRequest,
127 &buf,
130
131 if (NT_SUCCESS(status)) {
134 "WDFUSBDEVICE %p, WDFREQUEST %p being submitted",
135 UsbDevice, request.m_TrueRequest->GetTraceObjectHandle());
136
138 }
139
141 "Device %p, Urb %p, %!STATUS!",
143
144 return status;
145}
146
150WDFAPI
151NTAPI
152WDFEXPORT(WdfUsbTargetDeviceFormatRequestForUrb)(
153 __in
154 PWDF_DRIVER_GLOBALS DriverGlobals,
155 __in
156 WDFUSBDEVICE UsbDevice,
157 __in
158 WDFREQUEST Request,
159 __in
160 WDFMEMORY UrbMemory,
163 )
164{
165 DDI_ENTRY();
166
174
176 UsbDevice,
178 (PVOID*) &pUsbDevice,
180
182 "WDFUSBDEVICE %p, Request %p, Memory %p",
184
186
188 UrbMemory,
190 (PVOID*) &pMemory);
191
193 Request,
195 (PVOID*) &pRequest);
196
199 return status;
200 }
201
205 }
206
207 if (bufferSize < sizeof(_URB_HEADER)) {
210 "UrbMemory %p buffer size, %I64d, smaller then"
211 "_URB_HEADER, %!STATUS!",
213 return status;
214 }
215
216 buf.SetMemory(pMemory, UrbOffsets);
217
220 pRequest,
221 &buf,
224
226 FxUsbUrbContext* pContext;
227 pContext = (FxUsbUrbContext*) pRequest->GetContext();
228
231 }
232
234 "WDFUSBDEVICE %p, Request %p, Memory %p, %!STATUS!",
236
237 return status;
238}
239
243WDFAPI
244NTAPI
245WDFEXPORT(WdfUsbTargetDeviceIsConnectedSynchronous)(
246 __in
247 PWDF_DRIVER_GLOBALS DriverGlobals,
248 __in
249 WDFUSBDEVICE UsbDevice
250 )
251{
252 DDI_ENTRY();
253
257
259 UsbDevice,
261 (PVOID*) &pUsbDevice,
263
265 if (!NT_SUCCESS(status)) {
266 return status;
267 }
268
270
271 return status;
272}
273
277NTAPI
278WDFEXPORT(WdfUsbTargetDeviceCyclePortSynchronously)(
279 __in
280 PWDF_DRIVER_GLOBALS DriverGlobals,
281 __in
282 WDFUSBDEVICE UsbDevice
283 )
284/*++
285
286Routine Description:
287 Synchronously cycles a device on a USB port. This will cause the device
288 to be surprise removed and reenumerated. Very similar to the reenumerate
289 interface we use in the pnp state machine. Usually a driver will do this
290 after it has downloaded firmware and wants to be reenumerated as a new
291 device.
292
293
294
295
296Arguments:
297 UsbDevice - the IOTARGET representing the device
298
299Return Value:
300 NTSTATUS
301
302 --*/
303{
304 DDI_ENTRY();
305
309
311 UsbDevice,
313 (PVOID*) &pUsbDevice,
315
317 if (!NT_SUCCESS(status)) {
318 return status;
319 }
320
322
323 return status;
324}
325
329NTAPI
330WDFEXPORT(WdfUsbTargetDeviceFormatRequestForCyclePort)(
331 __in
332 PWDF_DRIVER_GLOBALS DriverGlobals,
333 __in
334 WDFUSBDEVICE UsbDevice,
335 __in
336 WDFREQUEST Request
337 )
338/*++
339
340Routine Description:
341 Formats a WDFREQUEST so that it will cycle the port and reenumerate the
342 device when sent.
343
344Arguments:
345 UsbDevice - the IOTARGET representing the device that will be reenumerated
346
347 Request - the request which will be formatted
348
349Return Value:
350 NTSTATUS
351
352 --*/
353{
354 DDI_ENTRY();
355
360
362 UsbDevice,
364 (PVOID*) &pUsbDevice,
366
368 Request,
370 (PVOID*) &pRequest);
371
373
374 return status;
375}
376
380WDFAPI
381NTAPI
382WDFEXPORT(WdfUsbTargetDeviceCreateUrb)(
383 __in
384 PWDF_DRIVER_GLOBALS DriverGlobals,
385 __in
386 WDFUSBDEVICE UsbDevice,
389 __out
390 WDFMEMORY* UrbMemory,
392 PURB* Urb
393 )
394/*++
395
396Routine Description:
397 Creates a WDFUSBDEVICE handle for the client.
398
399Arguments:
400 Attributes - Attributes associated with this object
401
402 UrbMemory - The returned handle to the caller for the allocated Urb
403
404 Urb - (opt) Pointer to the associated urb buffer.
405
406Return Value:
407 STATUS_INVALID_PARAMETER - any required parameters are not present/invalid
408
409 STATUS_INVALID_DEVICE_STATE - If the client did not specify a client contract verion while
410 creating the WDFUSBDEVICE
411
412 STATUS_INSUFFICIENT_RESOURCES - could not allocated the object that backs
413 the handle
414
415 STATUS_SUCCESS - success
416
417 ...
418
419 --*/
420{
421 DDI_ENTRY();
422
426
428 UsbDevice,
430 (PVOID*) &pUsbDevice,
432
433 //
434 // Basic parameter validation
435 //
437
438 if (pUsbDevice->GetUSBDHandle() == NULL) {
440
443 "USBDEVICE Must have been created with Client Contract Verion Info, %!STATUS!",
444 status);
445
446 return status;
447 }
448
450
451 return status;
452}
453
454} // 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:33
#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
__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 _Must_inspect_result_
Definition: no_sal2.h:62
#define __checkReturn
Definition: sal_old.h:113
#define __deref_opt_out_bcount(size)
Definition: sal_old.h:184
#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::@4014 Parameters
struct _WDF_USB_REQUEST_COMPLETION_PARAMS::@4014::@4017 DeviceUrb
Definition: http.c:7252
Definition: tftpd.h:86
Definition: ps.c:97
uint32_t * PULONG
Definition: typedefs.h:59
#define NTAPI
Definition: typedefs.h:36
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_INVALID_DEVICE_STATE
Definition: udferr_usr.h:178
_In_ PIO_STACK_LOCATION _In_ PURB Urb
Definition: usbdlib.h:267
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:64
_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