1*8a978a17SVictor Perevertkin /*++
2*8a978a17SVictor Perevertkin
3*8a978a17SVictor Perevertkin Copyright (c) Microsoft Corporation
4*8a978a17SVictor Perevertkin
5*8a978a17SVictor Perevertkin Module Name:
6*8a978a17SVictor Perevertkin
7*8a978a17SVictor Perevertkin FxUsbPipeAPI.cpp
8*8a978a17SVictor Perevertkin
9*8a978a17SVictor Perevertkin Abstract:
10*8a978a17SVictor Perevertkin
11*8a978a17SVictor Perevertkin
12*8a978a17SVictor Perevertkin Author:
13*8a978a17SVictor Perevertkin
14*8a978a17SVictor Perevertkin Environment:
15*8a978a17SVictor Perevertkin
16*8a978a17SVictor Perevertkin Both kernel and user mode
17*8a978a17SVictor Perevertkin
18*8a978a17SVictor Perevertkin Revision History:
19*8a978a17SVictor Perevertkin
20*8a978a17SVictor Perevertkin --*/
21*8a978a17SVictor Perevertkin
22*8a978a17SVictor Perevertkin #include "fxusbpch.hpp"
23*8a978a17SVictor Perevertkin
24*8a978a17SVictor Perevertkin extern "C" {
25*8a978a17SVictor Perevertkin #include "FxUsbPipeAPI.tmh"
26*8a978a17SVictor Perevertkin }
27*8a978a17SVictor Perevertkin
28*8a978a17SVictor Perevertkin //
29*8a978a17SVictor Perevertkin // extern "C" the whole file since we are exporting the APIs by name
30*8a978a17SVictor Perevertkin //
31*8a978a17SVictor Perevertkin extern "C" {
32*8a978a17SVictor Perevertkin
__drv_maxIRQL(DISPATCH_LEVEL)33*8a978a17SVictor Perevertkin __drv_maxIRQL(DISPATCH_LEVEL)
34*8a978a17SVictor Perevertkin VOID
35*8a978a17SVictor Perevertkin WDFAPI
36*8a978a17SVictor Perevertkin WDFEXPORT(WdfUsbTargetPipeGetInformation)(
37*8a978a17SVictor Perevertkin __in
38*8a978a17SVictor Perevertkin PWDF_DRIVER_GLOBALS DriverGlobals,
39*8a978a17SVictor Perevertkin __in
40*8a978a17SVictor Perevertkin WDFUSBPIPE Pipe,
41*8a978a17SVictor Perevertkin __out
42*8a978a17SVictor Perevertkin PWDF_USB_PIPE_INFORMATION PipeInformation
43*8a978a17SVictor Perevertkin )
44*8a978a17SVictor Perevertkin {
45*8a978a17SVictor Perevertkin DDI_ENTRY();
46*8a978a17SVictor Perevertkin
47*8a978a17SVictor Perevertkin PFX_DRIVER_GLOBALS pFxDriverGlobals;
48*8a978a17SVictor Perevertkin FxUsbPipe* pUsbPipe;
49*8a978a17SVictor Perevertkin
50*8a978a17SVictor Perevertkin FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals),
51*8a978a17SVictor Perevertkin Pipe,
52*8a978a17SVictor Perevertkin FX_TYPE_IO_TARGET_USB_PIPE,
53*8a978a17SVictor Perevertkin (PVOID*) &pUsbPipe,
54*8a978a17SVictor Perevertkin &pFxDriverGlobals);
55*8a978a17SVictor Perevertkin
56*8a978a17SVictor Perevertkin FxPointerNotNull(pFxDriverGlobals, PipeInformation);
57*8a978a17SVictor Perevertkin
58*8a978a17SVictor Perevertkin pUsbPipe->GetInformation(PipeInformation);
59*8a978a17SVictor Perevertkin }
60*8a978a17SVictor Perevertkin
__drv_maxIRQL(DISPATCH_LEVEL)61*8a978a17SVictor Perevertkin __drv_maxIRQL(DISPATCH_LEVEL)
62*8a978a17SVictor Perevertkin BOOLEAN
63*8a978a17SVictor Perevertkin WDFAPI
64*8a978a17SVictor Perevertkin WDFEXPORT(WdfUsbTargetPipeIsInEndpoint)(
65*8a978a17SVictor Perevertkin __in
66*8a978a17SVictor Perevertkin PWDF_DRIVER_GLOBALS DriverGlobals,
67*8a978a17SVictor Perevertkin __in
68*8a978a17SVictor Perevertkin WDFUSBPIPE Pipe
69*8a978a17SVictor Perevertkin )
70*8a978a17SVictor Perevertkin {
71*8a978a17SVictor Perevertkin DDI_ENTRY();
72*8a978a17SVictor Perevertkin
73*8a978a17SVictor Perevertkin FxUsbPipe* pUsbPipe;
74*8a978a17SVictor Perevertkin
75*8a978a17SVictor Perevertkin FxObjectHandleGetPtr(GetFxDriverGlobals(DriverGlobals),
76*8a978a17SVictor Perevertkin Pipe,
77*8a978a17SVictor Perevertkin FX_TYPE_IO_TARGET_USB_PIPE,
78*8a978a17SVictor Perevertkin (PVOID*) &pUsbPipe);
79*8a978a17SVictor Perevertkin
80*8a978a17SVictor Perevertkin return pUsbPipe->IsInEndpoint();
81*8a978a17SVictor Perevertkin }
82*8a978a17SVictor Perevertkin
__drv_maxIRQL(DISPATCH_LEVEL)83*8a978a17SVictor Perevertkin __drv_maxIRQL(DISPATCH_LEVEL)
84*8a978a17SVictor Perevertkin BOOLEAN
85*8a978a17SVictor Perevertkin WDFAPI
86*8a978a17SVictor Perevertkin WDFEXPORT(WdfUsbTargetPipeIsOutEndpoint)(
87*8a978a17SVictor Perevertkin __in
88*8a978a17SVictor Perevertkin PWDF_DRIVER_GLOBALS DriverGlobals,
89*8a978a17SVictor Perevertkin __in
90*8a978a17SVictor Perevertkin WDFUSBPIPE Pipe
91*8a978a17SVictor Perevertkin )
92*8a978a17SVictor Perevertkin {
93*8a978a17SVictor Perevertkin DDI_ENTRY();
94*8a978a17SVictor Perevertkin
95*8a978a17SVictor Perevertkin FxUsbPipe* pUsbPipe;
96*8a978a17SVictor Perevertkin
97*8a978a17SVictor Perevertkin FxObjectHandleGetPtr(GetFxDriverGlobals(DriverGlobals),
98*8a978a17SVictor Perevertkin Pipe,
99*8a978a17SVictor Perevertkin FX_TYPE_IO_TARGET_USB_PIPE,
100*8a978a17SVictor Perevertkin (PVOID*) &pUsbPipe);
101*8a978a17SVictor Perevertkin
102*8a978a17SVictor Perevertkin return pUsbPipe->IsOutEndpoint();
103*8a978a17SVictor Perevertkin }
104*8a978a17SVictor Perevertkin
__drv_maxIRQL(DISPATCH_LEVEL)105*8a978a17SVictor Perevertkin __drv_maxIRQL(DISPATCH_LEVEL)
106*8a978a17SVictor Perevertkin WDF_USB_PIPE_TYPE
107*8a978a17SVictor Perevertkin WDFAPI
108*8a978a17SVictor Perevertkin WDFEXPORT(WdfUsbTargetPipeGetType)(
109*8a978a17SVictor Perevertkin __in
110*8a978a17SVictor Perevertkin PWDF_DRIVER_GLOBALS DriverGlobals,
111*8a978a17SVictor Perevertkin __in
112*8a978a17SVictor Perevertkin WDFUSBPIPE Pipe
113*8a978a17SVictor Perevertkin )
114*8a978a17SVictor Perevertkin {
115*8a978a17SVictor Perevertkin DDI_ENTRY();
116*8a978a17SVictor Perevertkin
117*8a978a17SVictor Perevertkin FxUsbPipe* pUsbPipe;
118*8a978a17SVictor Perevertkin
119*8a978a17SVictor Perevertkin FxObjectHandleGetPtr(GetFxDriverGlobals(DriverGlobals),
120*8a978a17SVictor Perevertkin Pipe,
121*8a978a17SVictor Perevertkin FX_TYPE_IO_TARGET_USB_PIPE,
122*8a978a17SVictor Perevertkin (PVOID*) &pUsbPipe);
123*8a978a17SVictor Perevertkin
124*8a978a17SVictor Perevertkin return pUsbPipe->GetType();
125*8a978a17SVictor Perevertkin }
126*8a978a17SVictor Perevertkin
__drv_maxIRQL(DISPATCH_LEVEL)127*8a978a17SVictor Perevertkin __drv_maxIRQL(DISPATCH_LEVEL)
128*8a978a17SVictor Perevertkin VOID
129*8a978a17SVictor Perevertkin WDFAPI
130*8a978a17SVictor Perevertkin WDFEXPORT(WdfUsbTargetPipeSetNoMaximumPacketSizeCheck)(
131*8a978a17SVictor Perevertkin __in
132*8a978a17SVictor Perevertkin PWDF_DRIVER_GLOBALS DriverGlobals,
133*8a978a17SVictor Perevertkin __in
134*8a978a17SVictor Perevertkin WDFUSBPIPE Pipe
135*8a978a17SVictor Perevertkin )
136*8a978a17SVictor Perevertkin {
137*8a978a17SVictor Perevertkin DDI_ENTRY();
138*8a978a17SVictor Perevertkin
139*8a978a17SVictor Perevertkin PFX_DRIVER_GLOBALS pFxDriverGlobals;
140*8a978a17SVictor Perevertkin FxUsbPipe* pUsbPipe;
141*8a978a17SVictor Perevertkin
142*8a978a17SVictor Perevertkin FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals),
143*8a978a17SVictor Perevertkin Pipe,
144*8a978a17SVictor Perevertkin FX_TYPE_IO_TARGET_USB_PIPE,
145*8a978a17SVictor Perevertkin (PVOID*) &pUsbPipe,
146*8a978a17SVictor Perevertkin &pFxDriverGlobals);
147*8a978a17SVictor Perevertkin
148*8a978a17SVictor Perevertkin DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGIOTARGET,
149*8a978a17SVictor Perevertkin "WDFUSBPIPE %p", Pipe);
150*8a978a17SVictor Perevertkin
151*8a978a17SVictor Perevertkin pUsbPipe->SetNoCheckPacketSize();
152*8a978a17SVictor Perevertkin }
153*8a978a17SVictor Perevertkin
154*8a978a17SVictor Perevertkin _Must_inspect_result_
__drv_maxIRQL(PASSIVE_LEVEL)155*8a978a17SVictor Perevertkin __drv_maxIRQL(PASSIVE_LEVEL)
156*8a978a17SVictor Perevertkin NTSTATUS
157*8a978a17SVictor Perevertkin WDFAPI
158*8a978a17SVictor Perevertkin WDFEXPORT(WdfUsbTargetPipeWriteSynchronously)(
159*8a978a17SVictor Perevertkin __in
160*8a978a17SVictor Perevertkin PWDF_DRIVER_GLOBALS DriverGlobals,
161*8a978a17SVictor Perevertkin __in
162*8a978a17SVictor Perevertkin WDFUSBPIPE Pipe,
163*8a978a17SVictor Perevertkin __in_opt
164*8a978a17SVictor Perevertkin WDFREQUEST Request,
165*8a978a17SVictor Perevertkin __in_opt
166*8a978a17SVictor Perevertkin PWDF_REQUEST_SEND_OPTIONS RequestOptions,
167*8a978a17SVictor Perevertkin __in_opt
168*8a978a17SVictor Perevertkin PWDF_MEMORY_DESCRIPTOR MemoryDescriptor,
169*8a978a17SVictor Perevertkin __out_opt
170*8a978a17SVictor Perevertkin PULONG BytesWritten
171*8a978a17SVictor Perevertkin )
172*8a978a17SVictor Perevertkin {
173*8a978a17SVictor Perevertkin DDI_ENTRY();
174*8a978a17SVictor Perevertkin
175*8a978a17SVictor Perevertkin DoTraceLevelMessage(
176*8a978a17SVictor Perevertkin GetFxDriverGlobals(DriverGlobals), TRACE_LEVEL_VERBOSE, TRACINGIOTARGET,
177*8a978a17SVictor Perevertkin "WDFUSBPIPE %p", Pipe);
178*8a978a17SVictor Perevertkin
179*8a978a17SVictor Perevertkin return FxUsbPipe::_SendTransfer(GetFxDriverGlobals(DriverGlobals),
180*8a978a17SVictor Perevertkin Pipe,
181*8a978a17SVictor Perevertkin Request,
182*8a978a17SVictor Perevertkin RequestOptions,
183*8a978a17SVictor Perevertkin MemoryDescriptor,
184*8a978a17SVictor Perevertkin BytesWritten,
185*8a978a17SVictor Perevertkin 0);
186*8a978a17SVictor Perevertkin }
187*8a978a17SVictor Perevertkin
188*8a978a17SVictor Perevertkin _Must_inspect_result_
__drv_maxIRQL(DISPATCH_LEVEL)189*8a978a17SVictor Perevertkin __drv_maxIRQL(DISPATCH_LEVEL)
190*8a978a17SVictor Perevertkin NTSTATUS
191*8a978a17SVictor Perevertkin WDFAPI
192*8a978a17SVictor Perevertkin WDFEXPORT(WdfUsbTargetPipeFormatRequestForWrite)(
193*8a978a17SVictor Perevertkin __in
194*8a978a17SVictor Perevertkin PWDF_DRIVER_GLOBALS DriverGlobals,
195*8a978a17SVictor Perevertkin __in
196*8a978a17SVictor Perevertkin WDFUSBPIPE Pipe,
197*8a978a17SVictor Perevertkin __in
198*8a978a17SVictor Perevertkin WDFREQUEST Request,
199*8a978a17SVictor Perevertkin __in_opt
200*8a978a17SVictor Perevertkin WDFMEMORY WriteMemory,
201*8a978a17SVictor Perevertkin __in_opt
202*8a978a17SVictor Perevertkin PWDFMEMORY_OFFSET WriteOffsets
203*8a978a17SVictor Perevertkin )
204*8a978a17SVictor Perevertkin {
205*8a978a17SVictor Perevertkin DDI_ENTRY();
206*8a978a17SVictor Perevertkin
207*8a978a17SVictor Perevertkin DoTraceLevelMessage(GetFxDriverGlobals(DriverGlobals), TRACE_LEVEL_VERBOSE, TRACINGIOTARGET,
208*8a978a17SVictor Perevertkin "WDFUSBPIPE %p, WDFREQUEST %p, WDFMEMORY %p",
209*8a978a17SVictor Perevertkin Pipe, Request, WriteMemory);
210*8a978a17SVictor Perevertkin
211*8a978a17SVictor Perevertkin return FxUsbPipe::_FormatTransfer(GetFxDriverGlobals(DriverGlobals),
212*8a978a17SVictor Perevertkin Pipe,
213*8a978a17SVictor Perevertkin Request,
214*8a978a17SVictor Perevertkin WriteMemory,
215*8a978a17SVictor Perevertkin WriteOffsets,
216*8a978a17SVictor Perevertkin 0);
217*8a978a17SVictor Perevertkin }
218*8a978a17SVictor Perevertkin
219*8a978a17SVictor Perevertkin _Must_inspect_result_
__drv_maxIRQL(PASSIVE_LEVEL)220*8a978a17SVictor Perevertkin __drv_maxIRQL(PASSIVE_LEVEL)
221*8a978a17SVictor Perevertkin NTSTATUS
222*8a978a17SVictor Perevertkin WDFAPI
223*8a978a17SVictor Perevertkin WDFEXPORT(WdfUsbTargetPipeReadSynchronously)(
224*8a978a17SVictor Perevertkin __in
225*8a978a17SVictor Perevertkin PWDF_DRIVER_GLOBALS DriverGlobals,
226*8a978a17SVictor Perevertkin __in
227*8a978a17SVictor Perevertkin WDFUSBPIPE Pipe,
228*8a978a17SVictor Perevertkin __in_opt
229*8a978a17SVictor Perevertkin WDFREQUEST Request,
230*8a978a17SVictor Perevertkin __in_opt
231*8a978a17SVictor Perevertkin PWDF_REQUEST_SEND_OPTIONS RequestOptions,
232*8a978a17SVictor Perevertkin __in_opt
233*8a978a17SVictor Perevertkin PWDF_MEMORY_DESCRIPTOR MemoryDescriptor,
234*8a978a17SVictor Perevertkin __out_opt
235*8a978a17SVictor Perevertkin PULONG BytesRead
236*8a978a17SVictor Perevertkin )
237*8a978a17SVictor Perevertkin {
238*8a978a17SVictor Perevertkin DDI_ENTRY();
239*8a978a17SVictor Perevertkin
240*8a978a17SVictor Perevertkin DoTraceLevelMessage(GetFxDriverGlobals(DriverGlobals), TRACE_LEVEL_VERBOSE, TRACINGIOTARGET,
241*8a978a17SVictor Perevertkin "WDFUSBPIPE %p", Pipe);
242*8a978a17SVictor Perevertkin
243*8a978a17SVictor Perevertkin return FxUsbPipe::_SendTransfer(
244*8a978a17SVictor Perevertkin GetFxDriverGlobals(DriverGlobals),
245*8a978a17SVictor Perevertkin Pipe,
246*8a978a17SVictor Perevertkin Request,
247*8a978a17SVictor Perevertkin RequestOptions,
248*8a978a17SVictor Perevertkin MemoryDescriptor,
249*8a978a17SVictor Perevertkin BytesRead,
250*8a978a17SVictor Perevertkin USBD_TRANSFER_DIRECTION_IN | USBD_SHORT_TRANSFER_OK
251*8a978a17SVictor Perevertkin );
252*8a978a17SVictor Perevertkin }
253*8a978a17SVictor Perevertkin
254*8a978a17SVictor Perevertkin _Must_inspect_result_
__drv_maxIRQL(DISPATCH_LEVEL)255*8a978a17SVictor Perevertkin __drv_maxIRQL(DISPATCH_LEVEL)
256*8a978a17SVictor Perevertkin NTSTATUS
257*8a978a17SVictor Perevertkin WDFAPI
258*8a978a17SVictor Perevertkin WDFEXPORT(WdfUsbTargetPipeFormatRequestForRead)(
259*8a978a17SVictor Perevertkin __in
260*8a978a17SVictor Perevertkin PWDF_DRIVER_GLOBALS DriverGlobals,
261*8a978a17SVictor Perevertkin __in
262*8a978a17SVictor Perevertkin WDFUSBPIPE Pipe,
263*8a978a17SVictor Perevertkin __in
264*8a978a17SVictor Perevertkin WDFREQUEST Request,
265*8a978a17SVictor Perevertkin __in_opt
266*8a978a17SVictor Perevertkin WDFMEMORY ReadMemory,
267*8a978a17SVictor Perevertkin __in_opt
268*8a978a17SVictor Perevertkin PWDFMEMORY_OFFSET ReadOffsets
269*8a978a17SVictor Perevertkin )
270*8a978a17SVictor Perevertkin {
271*8a978a17SVictor Perevertkin DDI_ENTRY();
272*8a978a17SVictor Perevertkin
273*8a978a17SVictor Perevertkin DoTraceLevelMessage(
274*8a978a17SVictor Perevertkin GetFxDriverGlobals(DriverGlobals), TRACE_LEVEL_VERBOSE, TRACINGIOTARGET,
275*8a978a17SVictor Perevertkin "WDFUSBPIPE %p, WDFREQUEST %p, WDFMEMORY %p",
276*8a978a17SVictor Perevertkin Pipe, Request, ReadMemory);
277*8a978a17SVictor Perevertkin
278*8a978a17SVictor Perevertkin return FxUsbPipe::_FormatTransfer(
279*8a978a17SVictor Perevertkin GetFxDriverGlobals(DriverGlobals),
280*8a978a17SVictor Perevertkin Pipe,
281*8a978a17SVictor Perevertkin Request,
282*8a978a17SVictor Perevertkin ReadMemory,
283*8a978a17SVictor Perevertkin ReadOffsets,
284*8a978a17SVictor Perevertkin USBD_TRANSFER_DIRECTION_IN | USBD_SHORT_TRANSFER_OK
285*8a978a17SVictor Perevertkin );
286*8a978a17SVictor Perevertkin }
287*8a978a17SVictor Perevertkin
288*8a978a17SVictor Perevertkin _Must_inspect_result_
__drv_maxIRQL(DISPATCH_LEVEL)289*8a978a17SVictor Perevertkin __drv_maxIRQL(DISPATCH_LEVEL)
290*8a978a17SVictor Perevertkin NTSTATUS
291*8a978a17SVictor Perevertkin WDFAPI
292*8a978a17SVictor Perevertkin WDFEXPORT(WdfUsbTargetPipeConfigContinuousReader)(
293*8a978a17SVictor Perevertkin __in
294*8a978a17SVictor Perevertkin PWDF_DRIVER_GLOBALS DriverGlobals,
295*8a978a17SVictor Perevertkin __in
296*8a978a17SVictor Perevertkin WDFUSBPIPE Pipe,
297*8a978a17SVictor Perevertkin __in
298*8a978a17SVictor Perevertkin PWDF_USB_CONTINUOUS_READER_CONFIG Config
299*8a978a17SVictor Perevertkin )
300*8a978a17SVictor Perevertkin {
301*8a978a17SVictor Perevertkin DDI_ENTRY();
302*8a978a17SVictor Perevertkin
303*8a978a17SVictor Perevertkin PFX_DRIVER_GLOBALS pFxDriverGlobals;
304*8a978a17SVictor Perevertkin FxUsbPipe* pUsbPipe;
305*8a978a17SVictor Perevertkin NTSTATUS status;
306*8a978a17SVictor Perevertkin size_t total;
307*8a978a17SVictor Perevertkin
308*8a978a17SVictor Perevertkin FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals),
309*8a978a17SVictor Perevertkin Pipe,
310*8a978a17SVictor Perevertkin FX_TYPE_IO_TARGET_USB_PIPE,
311*8a978a17SVictor Perevertkin (PVOID*) &pUsbPipe,
312*8a978a17SVictor Perevertkin &pFxDriverGlobals);
313*8a978a17SVictor Perevertkin
314*8a978a17SVictor Perevertkin FxPointerNotNull(pFxDriverGlobals, Config);
315*8a978a17SVictor Perevertkin
316*8a978a17SVictor Perevertkin if (Config->Size != sizeof(WDF_USB_CONTINUOUS_READER_CONFIG)) {
317*8a978a17SVictor Perevertkin status = STATUS_INFO_LENGTH_MISMATCH;
318*8a978a17SVictor Perevertkin
319*8a978a17SVictor Perevertkin DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGIOTARGET,
320*8a978a17SVictor Perevertkin "Config %p incorrect size %d, expected %d %!STATUS!",
321*8a978a17SVictor Perevertkin Config, Config->Size, sizeof(WDF_USB_CONTINUOUS_READER_CONFIG),
322*8a978a17SVictor Perevertkin status);
323*8a978a17SVictor Perevertkin
324*8a978a17SVictor Perevertkin return status;
325*8a978a17SVictor Perevertkin }
326*8a978a17SVictor Perevertkin
327*8a978a17SVictor Perevertkin if (Config->EvtUsbTargetPipeReadComplete == NULL) {
328*8a978a17SVictor Perevertkin status = STATUS_INVALID_PARAMETER;
329*8a978a17SVictor Perevertkin DoTraceLevelMessage(
330*8a978a17SVictor Perevertkin pFxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGIOTARGET,
331*8a978a17SVictor Perevertkin "NULL EvtUsbTargetPipeReadComplete not allowed %!STATUS!", status);
332*8a978a17SVictor Perevertkin return status;
333*8a978a17SVictor Perevertkin }
334*8a978a17SVictor Perevertkin
335*8a978a17SVictor Perevertkin if (Config->TransferLength == 0) {
336*8a978a17SVictor Perevertkin status = STATUS_INVALID_PARAMETER;
337*8a978a17SVictor Perevertkin DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGIOTARGET,
338*8a978a17SVictor Perevertkin "TransferLength of 0 not allowed %!STATUS!", status);
339*8a978a17SVictor Perevertkin return status;
340*8a978a17SVictor Perevertkin }
341*8a978a17SVictor Perevertkin
342*8a978a17SVictor Perevertkin status = RtlSizeTAdd(Config->HeaderLength,
343*8a978a17SVictor Perevertkin Config->TransferLength,
344*8a978a17SVictor Perevertkin &total);
345*8a978a17SVictor Perevertkin
346*8a978a17SVictor Perevertkin if (!NT_SUCCESS(status)) {
347*8a978a17SVictor Perevertkin DoTraceLevelMessage(
348*8a978a17SVictor Perevertkin pFxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGIOTARGET,
349*8a978a17SVictor Perevertkin "HeaderLength + TransferLength overflow %!STATUS!", status);
350*8a978a17SVictor Perevertkin return status;
351*8a978a17SVictor Perevertkin }
352*8a978a17SVictor Perevertkin
353*8a978a17SVictor Perevertkin status = RtlSizeTAdd(total,
354*8a978a17SVictor Perevertkin Config->TrailerLength,
355*8a978a17SVictor Perevertkin &total);
356*8a978a17SVictor Perevertkin
357*8a978a17SVictor Perevertkin if (!NT_SUCCESS(status)) {
358*8a978a17SVictor Perevertkin DoTraceLevelMessage(
359*8a978a17SVictor Perevertkin pFxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGIOTARGET,
360*8a978a17SVictor Perevertkin "HeaderLength + TransferLength + TrailerLength overflow %!STATUS!",
361*8a978a17SVictor Perevertkin status);
362*8a978a17SVictor Perevertkin return status;
363*8a978a17SVictor Perevertkin }
364*8a978a17SVictor Perevertkin
365*8a978a17SVictor Perevertkin //
366*8a978a17SVictor Perevertkin // Internally WDF will assign a parent to the memory, so do not allow the driver
367*8a978a17SVictor Perevertkin // to do so.
368*8a978a17SVictor Perevertkin //
369*8a978a17SVictor Perevertkin status = FxValidateObjectAttributes(pFxDriverGlobals,
370*8a978a17SVictor Perevertkin Config->BufferAttributes,
371*8a978a17SVictor Perevertkin FX_VALIDATE_OPTION_PARENT_NOT_ALLOWED);
372*8a978a17SVictor Perevertkin if (!NT_SUCCESS(status)) {
373*8a978a17SVictor Perevertkin return status;
374*8a978a17SVictor Perevertkin }
375*8a978a17SVictor Perevertkin
376*8a978a17SVictor Perevertkin //
377*8a978a17SVictor Perevertkin // Only bulk or interrrupt is allowed for a continous reader
378*8a978a17SVictor Perevertkin //
379*8a978a17SVictor Perevertkin if ((pUsbPipe->IsType(WdfUsbPipeTypeBulk) ||
380*8a978a17SVictor Perevertkin pUsbPipe->IsType(WdfUsbPipeTypeInterrupt)) == FALSE) {
381*8a978a17SVictor Perevertkin status = STATUS_INVALID_DEVICE_REQUEST;
382*8a978a17SVictor Perevertkin
383*8a978a17SVictor Perevertkin DoTraceLevelMessage(
384*8a978a17SVictor Perevertkin pFxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGIOTARGET,
385*8a978a17SVictor Perevertkin "WDFUSBPIPE %p type %!WDF_USB_PIPE_TYPE!, only bulk or interrupt "
386*8a978a17SVictor Perevertkin "pipes can be configured for continous readers, %!STATUS!",
387*8a978a17SVictor Perevertkin Pipe, pUsbPipe->GetType(), status);
388*8a978a17SVictor Perevertkin
389*8a978a17SVictor Perevertkin return status;
390*8a978a17SVictor Perevertkin }
391*8a978a17SVictor Perevertkin
392*8a978a17SVictor Perevertkin if (pUsbPipe->IsOutEndpoint()) {
393*8a978a17SVictor Perevertkin status = STATUS_INVALID_DEVICE_REQUEST;
394*8a978a17SVictor Perevertkin
395*8a978a17SVictor Perevertkin DoTraceLevelMessage(
396*8a978a17SVictor Perevertkin pFxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGIOTARGET,
397*8a978a17SVictor Perevertkin "WDFUSBPIPE %p, wrong direction for continuous reader, %!STATUS!",
398*8a978a17SVictor Perevertkin Pipe, status);
399*8a978a17SVictor Perevertkin
400*8a978a17SVictor Perevertkin return status;
401*8a978a17SVictor Perevertkin }
402*8a978a17SVictor Perevertkin
403*8a978a17SVictor Perevertkin status = pUsbPipe->ValidateTransferLength(Config->TransferLength);
404*8a978a17SVictor Perevertkin if (!NT_SUCCESS(status)) {
405*8a978a17SVictor Perevertkin DoTraceLevelMessage(
406*8a978a17SVictor Perevertkin pFxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGIOTARGET,
407*8a978a17SVictor Perevertkin "TransferLength %I64d not a valid transer length (not integral of max "
408*8a978a17SVictor Perevertkin "packet size %d) %!STATUS!", Config->TransferLength,
409*8a978a17SVictor Perevertkin pUsbPipe->GetMaxPacketSize(), status);
410*8a978a17SVictor Perevertkin return status;
411*8a978a17SVictor Perevertkin }
412*8a978a17SVictor Perevertkin
413*8a978a17SVictor Perevertkin status = pUsbPipe->InitContinuousReader(Config, total);
414*8a978a17SVictor Perevertkin
415*8a978a17SVictor Perevertkin return status;
416*8a978a17SVictor Perevertkin }
417*8a978a17SVictor Perevertkin
418*8a978a17SVictor Perevertkin _Must_inspect_result_
__drv_maxIRQL(PASSIVE_LEVEL)419*8a978a17SVictor Perevertkin __drv_maxIRQL(PASSIVE_LEVEL)
420*8a978a17SVictor Perevertkin NTSTATUS
421*8a978a17SVictor Perevertkin WDFAPI
422*8a978a17SVictor Perevertkin WDFEXPORT(WdfUsbTargetPipeAbortSynchronously)(
423*8a978a17SVictor Perevertkin __in
424*8a978a17SVictor Perevertkin PWDF_DRIVER_GLOBALS DriverGlobals,
425*8a978a17SVictor Perevertkin __in
426*8a978a17SVictor Perevertkin WDFUSBPIPE Pipe,
427*8a978a17SVictor Perevertkin __in_opt
428*8a978a17SVictor Perevertkin WDFREQUEST Request,
429*8a978a17SVictor Perevertkin __in_opt
430*8a978a17SVictor Perevertkin PWDF_REQUEST_SEND_OPTIONS RequestOptions
431*8a978a17SVictor Perevertkin )
432*8a978a17SVictor Perevertkin {
433*8a978a17SVictor Perevertkin DDI_ENTRY();
434*8a978a17SVictor Perevertkin
435*8a978a17SVictor Perevertkin PFX_DRIVER_GLOBALS pFxDriverGlobals;
436*8a978a17SVictor Perevertkin FxUsbPipe* pUsbPipe;
437*8a978a17SVictor Perevertkin NTSTATUS status;
438*8a978a17SVictor Perevertkin
439*8a978a17SVictor Perevertkin FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals),
440*8a978a17SVictor Perevertkin Pipe,
441*8a978a17SVictor Perevertkin FX_TYPE_IO_TARGET_USB_PIPE,
442*8a978a17SVictor Perevertkin (PVOID*) &pUsbPipe,
443*8a978a17SVictor Perevertkin &pFxDriverGlobals);
444*8a978a17SVictor Perevertkin
445*8a978a17SVictor Perevertkin FxUsbPipeRequestContext context(FxUrbTypeLegacy);
446*8a978a17SVictor Perevertkin
447*8a978a17SVictor Perevertkin FxSyncRequest request(pFxDriverGlobals, &context, Request);
448*8a978a17SVictor Perevertkin
449*8a978a17SVictor Perevertkin //
450*8a978a17SVictor Perevertkin // FxSyncRequest always succeesds for KM but can fail for UM.
451*8a978a17SVictor Perevertkin //
452*8a978a17SVictor Perevertkin status = request.Initialize();
453*8a978a17SVictor Perevertkin if (!NT_SUCCESS(status)) {
454*8a978a17SVictor Perevertkin DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGIOTARGET,
455*8a978a17SVictor Perevertkin "Failed to initialize FxSyncRequest");
456*8a978a17SVictor Perevertkin return status;
457*8a978a17SVictor Perevertkin }
458*8a978a17SVictor Perevertkin
459*8a978a17SVictor Perevertkin DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGIOTARGET,
460*8a978a17SVictor Perevertkin "Pipe %p", Pipe);
461*8a978a17SVictor Perevertkin
462*8a978a17SVictor Perevertkin status = FxVerifierCheckIrqlLevel(pFxDriverGlobals, PASSIVE_LEVEL);
463*8a978a17SVictor Perevertkin if (!NT_SUCCESS(status)) {
464*8a978a17SVictor Perevertkin return status;
465*8a978a17SVictor Perevertkin }
466*8a978a17SVictor Perevertkin
467*8a978a17SVictor Perevertkin status = FxValidateRequestOptions(pFxDriverGlobals, RequestOptions);
468*8a978a17SVictor Perevertkin if (!NT_SUCCESS(status)) {
469*8a978a17SVictor Perevertkin DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGIOTARGET,
470*8a978a17SVictor Perevertkin "Invalid request options");
471*8a978a17SVictor Perevertkin return status;
472*8a978a17SVictor Perevertkin }
473*8a978a17SVictor Perevertkin
474*8a978a17SVictor Perevertkin status = pUsbPipe->FormatAbortRequest(request.m_TrueRequest);
475*8a978a17SVictor Perevertkin if (NT_SUCCESS(status)) {
476*8a978a17SVictor Perevertkin DoTraceLevelMessage(
477*8a978a17SVictor Perevertkin pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGIOTARGET,
478*8a978a17SVictor Perevertkin "WDFUSBPIPE %p, WDFREQUEST %p being submitted",
479*8a978a17SVictor Perevertkin Pipe, request.m_TrueRequest->GetTraceObjectHandle());
480*8a978a17SVictor Perevertkin
481*8a978a17SVictor Perevertkin status = pUsbPipe->SubmitSync(request.m_TrueRequest, RequestOptions);
482*8a978a17SVictor Perevertkin }
483*8a978a17SVictor Perevertkin
484*8a978a17SVictor Perevertkin DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGIOTARGET,
485*8a978a17SVictor Perevertkin "WDFUSBPIPE %p, %!STATUS!", Pipe, status);
486*8a978a17SVictor Perevertkin
487*8a978a17SVictor Perevertkin return status;
488*8a978a17SVictor Perevertkin }
489*8a978a17SVictor Perevertkin
490*8a978a17SVictor Perevertkin _Must_inspect_result_
__drv_maxIRQL(DISPATCH_LEVEL)491*8a978a17SVictor Perevertkin __drv_maxIRQL(DISPATCH_LEVEL)
492*8a978a17SVictor Perevertkin NTSTATUS
493*8a978a17SVictor Perevertkin WDFAPI
494*8a978a17SVictor Perevertkin WDFEXPORT(WdfUsbTargetPipeFormatRequestForAbort)(
495*8a978a17SVictor Perevertkin __in
496*8a978a17SVictor Perevertkin PWDF_DRIVER_GLOBALS DriverGlobals,
497*8a978a17SVictor Perevertkin __in
498*8a978a17SVictor Perevertkin WDFUSBPIPE Pipe,
499*8a978a17SVictor Perevertkin __in
500*8a978a17SVictor Perevertkin WDFREQUEST Request
501*8a978a17SVictor Perevertkin )
502*8a978a17SVictor Perevertkin {
503*8a978a17SVictor Perevertkin DDI_ENTRY();
504*8a978a17SVictor Perevertkin
505*8a978a17SVictor Perevertkin PFX_DRIVER_GLOBALS pFxDriverGlobals;
506*8a978a17SVictor Perevertkin FxRequest* pRequest;
507*8a978a17SVictor Perevertkin FxUsbPipe* pUsbPipe;
508*8a978a17SVictor Perevertkin NTSTATUS status;
509*8a978a17SVictor Perevertkin
510*8a978a17SVictor Perevertkin FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals),
511*8a978a17SVictor Perevertkin Pipe,
512*8a978a17SVictor Perevertkin FX_TYPE_IO_TARGET_USB_PIPE,
513*8a978a17SVictor Perevertkin (PVOID*) &pUsbPipe,
514*8a978a17SVictor Perevertkin &pFxDriverGlobals);
515*8a978a17SVictor Perevertkin
516*8a978a17SVictor Perevertkin DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGIOTARGET,
517*8a978a17SVictor Perevertkin "Pipe %p, Request %p", Pipe, Request);
518*8a978a17SVictor Perevertkin
519*8a978a17SVictor Perevertkin FxObjectHandleGetPtr(pFxDriverGlobals,
520*8a978a17SVictor Perevertkin Request,
521*8a978a17SVictor Perevertkin FX_TYPE_REQUEST,
522*8a978a17SVictor Perevertkin (PVOID*) &pRequest);
523*8a978a17SVictor Perevertkin
524*8a978a17SVictor Perevertkin status = pUsbPipe->FormatAbortRequest(pRequest);
525*8a978a17SVictor Perevertkin
526*8a978a17SVictor Perevertkin DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGIOTARGET,
527*8a978a17SVictor Perevertkin "Pipe %p, Request %p, status %!STATUS!",
528*8a978a17SVictor Perevertkin Pipe, Request, status);
529*8a978a17SVictor Perevertkin
530*8a978a17SVictor Perevertkin return status;
531*8a978a17SVictor Perevertkin }
532*8a978a17SVictor Perevertkin
533*8a978a17SVictor Perevertkin _Must_inspect_result_
__drv_maxIRQL(PASSIVE_LEVEL)534*8a978a17SVictor Perevertkin __drv_maxIRQL(PASSIVE_LEVEL)
535*8a978a17SVictor Perevertkin NTSTATUS
536*8a978a17SVictor Perevertkin WDFAPI
537*8a978a17SVictor Perevertkin WDFEXPORT(WdfUsbTargetPipeResetSynchronously)(
538*8a978a17SVictor Perevertkin __in
539*8a978a17SVictor Perevertkin PWDF_DRIVER_GLOBALS DriverGlobals,
540*8a978a17SVictor Perevertkin __in
541*8a978a17SVictor Perevertkin WDFUSBPIPE Pipe,
542*8a978a17SVictor Perevertkin __in_opt
543*8a978a17SVictor Perevertkin WDFREQUEST Request,
544*8a978a17SVictor Perevertkin __in_opt
545*8a978a17SVictor Perevertkin PWDF_REQUEST_SEND_OPTIONS RequestOptions
546*8a978a17SVictor Perevertkin )
547*8a978a17SVictor Perevertkin {
548*8a978a17SVictor Perevertkin DDI_ENTRY();
549*8a978a17SVictor Perevertkin
550*8a978a17SVictor Perevertkin PFX_DRIVER_GLOBALS pFxDriverGlobals;
551*8a978a17SVictor Perevertkin FxUsbPipe* pUsbPipe;
552*8a978a17SVictor Perevertkin NTSTATUS status;
553*8a978a17SVictor Perevertkin
554*8a978a17SVictor Perevertkin FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals),
555*8a978a17SVictor Perevertkin Pipe,
556*8a978a17SVictor Perevertkin FX_TYPE_IO_TARGET_USB_PIPE,
557*8a978a17SVictor Perevertkin (PVOID*) &pUsbPipe,
558*8a978a17SVictor Perevertkin &pFxDriverGlobals);
559*8a978a17SVictor Perevertkin
560*8a978a17SVictor Perevertkin FxUsbPipeRequestContext context(FxUrbTypeLegacy);
561*8a978a17SVictor Perevertkin
562*8a978a17SVictor Perevertkin FxSyncRequest request(pFxDriverGlobals, &context, Request);
563*8a978a17SVictor Perevertkin
564*8a978a17SVictor Perevertkin //
565*8a978a17SVictor Perevertkin // FxSyncRequest always succeesds for KM but can fail for UM.
566*8a978a17SVictor Perevertkin //
567*8a978a17SVictor Perevertkin status = request.Initialize();
568*8a978a17SVictor Perevertkin if (!NT_SUCCESS(status)) {
569*8a978a17SVictor Perevertkin DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGIOTARGET,
570*8a978a17SVictor Perevertkin "Failed to initialize FxSyncRequest");
571*8a978a17SVictor Perevertkin return status;
572*8a978a17SVictor Perevertkin }
573*8a978a17SVictor Perevertkin
574*8a978a17SVictor Perevertkin DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGIOTARGET,
575*8a978a17SVictor Perevertkin "WDFUSBPIPE %p reset", Pipe);
576*8a978a17SVictor Perevertkin
577*8a978a17SVictor Perevertkin status = FxVerifierCheckIrqlLevel(pFxDriverGlobals, PASSIVE_LEVEL);
578*8a978a17SVictor Perevertkin if (!NT_SUCCESS(status)) {
579*8a978a17SVictor Perevertkin return status;
580*8a978a17SVictor Perevertkin }
581*8a978a17SVictor Perevertkin
582*8a978a17SVictor Perevertkin status = FxValidateRequestOptions(pFxDriverGlobals, RequestOptions);
583*8a978a17SVictor Perevertkin if (!NT_SUCCESS(status)) {
584*8a978a17SVictor Perevertkin DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGIOTARGET,
585*8a978a17SVictor Perevertkin "Invalid request options");
586*8a978a17SVictor Perevertkin return status;
587*8a978a17SVictor Perevertkin }
588*8a978a17SVictor Perevertkin
589*8a978a17SVictor Perevertkin status = pUsbPipe->FormatResetRequest(request.m_TrueRequest);
590*8a978a17SVictor Perevertkin
591*8a978a17SVictor Perevertkin if (NT_SUCCESS(status)) {
592*8a978a17SVictor Perevertkin DoTraceLevelMessage(
593*8a978a17SVictor Perevertkin pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGIOTARGET,
594*8a978a17SVictor Perevertkin "WDFUSBPIPE %p, WDFREQUEST %p being submitted",
595*8a978a17SVictor Perevertkin Pipe, request.m_TrueRequest->GetTraceObjectHandle());
596*8a978a17SVictor Perevertkin
597*8a978a17SVictor Perevertkin pUsbPipe->CancelSentIo();
598*8a978a17SVictor Perevertkin
599*8a978a17SVictor Perevertkin //
600*8a978a17SVictor Perevertkin // Even if the previous state of the target was stopped let this IO go through by
601*8a978a17SVictor Perevertkin // ignoring target state.
602*8a978a17SVictor Perevertkin //
603*8a978a17SVictor Perevertkin status = pUsbPipe->SubmitSyncRequestIgnoreTargetState(request.m_TrueRequest, RequestOptions);
604*8a978a17SVictor Perevertkin }
605*8a978a17SVictor Perevertkin
606*8a978a17SVictor Perevertkin DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGIOTARGET,
607*8a978a17SVictor Perevertkin "WDFUSBPIPE %p reset, %!STATUS!", Pipe, status);
608*8a978a17SVictor Perevertkin
609*8a978a17SVictor Perevertkin return status;
610*8a978a17SVictor Perevertkin }
611*8a978a17SVictor Perevertkin
612*8a978a17SVictor Perevertkin _Must_inspect_result_
__drv_maxIRQL(DISPATCH_LEVEL)613*8a978a17SVictor Perevertkin __drv_maxIRQL(DISPATCH_LEVEL)
614*8a978a17SVictor Perevertkin NTSTATUS
615*8a978a17SVictor Perevertkin WDFAPI
616*8a978a17SVictor Perevertkin WDFEXPORT(WdfUsbTargetPipeFormatRequestForReset)(
617*8a978a17SVictor Perevertkin __in
618*8a978a17SVictor Perevertkin PWDF_DRIVER_GLOBALS DriverGlobals,
619*8a978a17SVictor Perevertkin __in
620*8a978a17SVictor Perevertkin WDFUSBPIPE Pipe,
621*8a978a17SVictor Perevertkin __in
622*8a978a17SVictor Perevertkin WDFREQUEST Request
623*8a978a17SVictor Perevertkin )
624*8a978a17SVictor Perevertkin {
625*8a978a17SVictor Perevertkin DDI_ENTRY();
626*8a978a17SVictor Perevertkin
627*8a978a17SVictor Perevertkin PFX_DRIVER_GLOBALS pFxDriverGlobals;
628*8a978a17SVictor Perevertkin FxRequest* pRequest;
629*8a978a17SVictor Perevertkin FxUsbPipe* pUsbPipe;
630*8a978a17SVictor Perevertkin NTSTATUS status;
631*8a978a17SVictor Perevertkin
632*8a978a17SVictor Perevertkin FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals),
633*8a978a17SVictor Perevertkin Pipe,
634*8a978a17SVictor Perevertkin FX_TYPE_IO_TARGET_USB_PIPE,
635*8a978a17SVictor Perevertkin (PVOID*) &pUsbPipe,
636*8a978a17SVictor Perevertkin &pFxDriverGlobals);
637*8a978a17SVictor Perevertkin
638*8a978a17SVictor Perevertkin DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGIOTARGET,
639*8a978a17SVictor Perevertkin "Pipe %p, Request %p", Pipe, Request);
640*8a978a17SVictor Perevertkin
641*8a978a17SVictor Perevertkin FxObjectHandleGetPtr(pFxDriverGlobals,
642*8a978a17SVictor Perevertkin Request,
643*8a978a17SVictor Perevertkin FX_TYPE_REQUEST,
644*8a978a17SVictor Perevertkin (PVOID*) &pRequest);
645*8a978a17SVictor Perevertkin
646*8a978a17SVictor Perevertkin status = pUsbPipe->FormatResetRequest(pRequest);
647*8a978a17SVictor Perevertkin
648*8a978a17SVictor Perevertkin DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGIOTARGET,
649*8a978a17SVictor Perevertkin "Pipe %p, Request %p = 0x%x",
650*8a978a17SVictor Perevertkin Pipe, Request, status);
651*8a978a17SVictor Perevertkin
652*8a978a17SVictor Perevertkin return status;
653*8a978a17SVictor Perevertkin }
654*8a978a17SVictor Perevertkin
655*8a978a17SVictor Perevertkin _Must_inspect_result_
__drv_maxIRQL(PASSIVE_LEVEL)656*8a978a17SVictor Perevertkin __drv_maxIRQL(PASSIVE_LEVEL)
657*8a978a17SVictor Perevertkin NTSTATUS
658*8a978a17SVictor Perevertkin WDFAPI
659*8a978a17SVictor Perevertkin WDFEXPORT(WdfUsbTargetPipeSendUrbSynchronously)(
660*8a978a17SVictor Perevertkin __in
661*8a978a17SVictor Perevertkin PWDF_DRIVER_GLOBALS DriverGlobals,
662*8a978a17SVictor Perevertkin __in
663*8a978a17SVictor Perevertkin WDFUSBPIPE Pipe,
664*8a978a17SVictor Perevertkin __in_opt
665*8a978a17SVictor Perevertkin WDFREQUEST Request,
666*8a978a17SVictor Perevertkin __in_opt
667*8a978a17SVictor Perevertkin PWDF_REQUEST_SEND_OPTIONS RequestOptions,
668*8a978a17SVictor Perevertkin __in_xcount("union bug in SAL")
669*8a978a17SVictor Perevertkin PURB Urb
670*8a978a17SVictor Perevertkin )
671*8a978a17SVictor Perevertkin {
672*8a978a17SVictor Perevertkin DDI_ENTRY();
673*8a978a17SVictor Perevertkin
674*8a978a17SVictor Perevertkin FxRequestBuffer buf;
675*8a978a17SVictor Perevertkin PFX_DRIVER_GLOBALS pFxDriverGlobals;
676*8a978a17SVictor Perevertkin FxUsbPipe* pUsbPipe;
677*8a978a17SVictor Perevertkin NTSTATUS status;
678*8a978a17SVictor Perevertkin
679*8a978a17SVictor Perevertkin FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals),
680*8a978a17SVictor Perevertkin Pipe,
681*8a978a17SVictor Perevertkin FX_TYPE_IO_TARGET_USB_PIPE,
682*8a978a17SVictor Perevertkin (PVOID*) &pUsbPipe,
683*8a978a17SVictor Perevertkin &pFxDriverGlobals);
684*8a978a17SVictor Perevertkin
685*8a978a17SVictor Perevertkin FxUsbUrbContext context;
686*8a978a17SVictor Perevertkin FxSyncRequest request(pFxDriverGlobals, &context, Request);
687*8a978a17SVictor Perevertkin
688*8a978a17SVictor Perevertkin //
689*8a978a17SVictor Perevertkin // FxSyncRequest always succeesds for KM but can fail for UM.
690*8a978a17SVictor Perevertkin //
691*8a978a17SVictor Perevertkin status = request.Initialize();
692*8a978a17SVictor Perevertkin if (!NT_SUCCESS(status)) {
693*8a978a17SVictor Perevertkin DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGIOTARGET,
694*8a978a17SVictor Perevertkin "Failed to initialize FxSyncRequest");
695*8a978a17SVictor Perevertkin return status;
696*8a978a17SVictor Perevertkin }
697*8a978a17SVictor Perevertkin
698*8a978a17SVictor Perevertkin DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGIOTARGET,
699*8a978a17SVictor Perevertkin "WDFUSBPIPE %p, Urb %p", Pipe, Urb);
700*8a978a17SVictor Perevertkin
701*8a978a17SVictor Perevertkin FxPointerNotNull(pFxDriverGlobals, Urb);
702*8a978a17SVictor Perevertkin
703*8a978a17SVictor Perevertkin status = FxVerifierCheckIrqlLevel(pFxDriverGlobals, PASSIVE_LEVEL);
704*8a978a17SVictor Perevertkin if (!NT_SUCCESS(status)) {
705*8a978a17SVictor Perevertkin return status;
706*8a978a17SVictor Perevertkin }
707*8a978a17SVictor Perevertkin
708*8a978a17SVictor Perevertkin status = FxValidateRequestOptions(pFxDriverGlobals, RequestOptions);
709*8a978a17SVictor Perevertkin if (!NT_SUCCESS(status)) {
710*8a978a17SVictor Perevertkin return status;
711*8a978a17SVictor Perevertkin }
712*8a978a17SVictor Perevertkin
713*8a978a17SVictor Perevertkin buf.SetBuffer(Urb, 0);
714*8a978a17SVictor Perevertkin
715*8a978a17SVictor Perevertkin status = FxFormatUrbRequest(pFxDriverGlobals,
716*8a978a17SVictor Perevertkin pUsbPipe,
717*8a978a17SVictor Perevertkin request.m_TrueRequest,
718*8a978a17SVictor Perevertkin &buf,
719*8a978a17SVictor Perevertkin pUsbPipe->GetUrbType(),
720*8a978a17SVictor Perevertkin pUsbPipe->GetUSBDHandle());
721*8a978a17SVictor Perevertkin
722*8a978a17SVictor Perevertkin if (NT_SUCCESS(status)) {
723*8a978a17SVictor Perevertkin DoTraceLevelMessage(
724*8a978a17SVictor Perevertkin pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGIOTARGET,
725*8a978a17SVictor Perevertkin "WDFUSBPIPE %p, WDFREQUEST %p being submitted",
726*8a978a17SVictor Perevertkin Pipe, request.m_TrueRequest->GetTraceObjectHandle());
727*8a978a17SVictor Perevertkin
728*8a978a17SVictor Perevertkin status = pUsbPipe->SubmitSync(request.m_TrueRequest, RequestOptions);
729*8a978a17SVictor Perevertkin }
730*8a978a17SVictor Perevertkin
731*8a978a17SVictor Perevertkin DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGIOTARGET,
732*8a978a17SVictor Perevertkin "WDFUSBPIPE %p, Urb %p, %!STATUS!",
733*8a978a17SVictor Perevertkin Pipe, Urb, status);
734*8a978a17SVictor Perevertkin
735*8a978a17SVictor Perevertkin return status;
736*8a978a17SVictor Perevertkin }
737*8a978a17SVictor Perevertkin
738*8a978a17SVictor Perevertkin _Must_inspect_result_
__drv_maxIRQL(DISPATCH_LEVEL)739*8a978a17SVictor Perevertkin __drv_maxIRQL(DISPATCH_LEVEL)
740*8a978a17SVictor Perevertkin NTSTATUS
741*8a978a17SVictor Perevertkin WDFAPI
742*8a978a17SVictor Perevertkin WDFEXPORT(WdfUsbTargetPipeFormatRequestForUrb)(
743*8a978a17SVictor Perevertkin __in
744*8a978a17SVictor Perevertkin PWDF_DRIVER_GLOBALS DriverGlobals,
745*8a978a17SVictor Perevertkin __in
746*8a978a17SVictor Perevertkin WDFUSBPIPE Pipe,
747*8a978a17SVictor Perevertkin __in
748*8a978a17SVictor Perevertkin WDFREQUEST Request,
749*8a978a17SVictor Perevertkin __in
750*8a978a17SVictor Perevertkin WDFMEMORY UrbMemory,
751*8a978a17SVictor Perevertkin __in_opt
752*8a978a17SVictor Perevertkin PWDFMEMORY_OFFSET UrbOffsets
753*8a978a17SVictor Perevertkin )
754*8a978a17SVictor Perevertkin {
755*8a978a17SVictor Perevertkin DDI_ENTRY();
756*8a978a17SVictor Perevertkin
757*8a978a17SVictor Perevertkin PFX_DRIVER_GLOBALS pFxDriverGlobals;
758*8a978a17SVictor Perevertkin IFxMemory* pMemory;
759*8a978a17SVictor Perevertkin FxUsbPipe* pUsbPipe;
760*8a978a17SVictor Perevertkin FxRequest* pRequest;
761*8a978a17SVictor Perevertkin FxRequestBuffer buf;
762*8a978a17SVictor Perevertkin NTSTATUS status;
763*8a978a17SVictor Perevertkin size_t bufferSize;
764*8a978a17SVictor Perevertkin
765*8a978a17SVictor Perevertkin FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals),
766*8a978a17SVictor Perevertkin Pipe,
767*8a978a17SVictor Perevertkin FX_TYPE_IO_TARGET_USB_PIPE,
768*8a978a17SVictor Perevertkin (PVOID*) &pUsbPipe,
769*8a978a17SVictor Perevertkin &pFxDriverGlobals);
770*8a978a17SVictor Perevertkin
771*8a978a17SVictor Perevertkin DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGIOTARGET,
772*8a978a17SVictor Perevertkin "Pipe %p, Request %p, Memory %p",
773*8a978a17SVictor Perevertkin Pipe, Request, UrbMemory);
774*8a978a17SVictor Perevertkin
775*8a978a17SVictor Perevertkin FxObjectHandleGetPtr(pFxDriverGlobals,
776*8a978a17SVictor Perevertkin UrbMemory,
777*8a978a17SVictor Perevertkin IFX_TYPE_MEMORY,
778*8a978a17SVictor Perevertkin (PVOID*) &pMemory);
779*8a978a17SVictor Perevertkin
780*8a978a17SVictor Perevertkin FxObjectHandleGetPtr(pFxDriverGlobals,
781*8a978a17SVictor Perevertkin Request,
782*8a978a17SVictor Perevertkin FX_TYPE_REQUEST,
783*8a978a17SVictor Perevertkin (PVOID*) &pRequest);
784*8a978a17SVictor Perevertkin
785*8a978a17SVictor Perevertkin status = pMemory->ValidateMemoryOffsets(UrbOffsets);
786*8a978a17SVictor Perevertkin if (!NT_SUCCESS(status)) {
787*8a978a17SVictor Perevertkin return status;
788*8a978a17SVictor Perevertkin }
789*8a978a17SVictor Perevertkin
790*8a978a17SVictor Perevertkin bufferSize = pMemory->GetBufferSize();
791*8a978a17SVictor Perevertkin if (UrbOffsets != NULL && UrbOffsets->BufferOffset > 0) {
792*8a978a17SVictor Perevertkin bufferSize -= UrbOffsets->BufferOffset;
793*8a978a17SVictor Perevertkin }
794*8a978a17SVictor Perevertkin
795*8a978a17SVictor Perevertkin if (bufferSize < sizeof(_URB_HEADER)) {
796*8a978a17SVictor Perevertkin status = STATUS_INVALID_PARAMETER;
797*8a978a17SVictor Perevertkin DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGIOTARGET,
798*8a978a17SVictor Perevertkin "UrbMemory %p buffer size, %I64d, smaller then "
799*8a978a17SVictor Perevertkin "_URB_HEADER, %!STATUS!", UrbMemory,
800*8a978a17SVictor Perevertkin pMemory->GetBufferSize(), status);
801*8a978a17SVictor Perevertkin return status;
802*8a978a17SVictor Perevertkin }
803*8a978a17SVictor Perevertkin
804*8a978a17SVictor Perevertkin buf.SetMemory(pMemory, UrbOffsets);
805*8a978a17SVictor Perevertkin
806*8a978a17SVictor Perevertkin status = FxFormatUrbRequest(pFxDriverGlobals,
807*8a978a17SVictor Perevertkin pUsbPipe,
808*8a978a17SVictor Perevertkin pRequest,
809*8a978a17SVictor Perevertkin &buf,
810*8a978a17SVictor Perevertkin pUsbPipe->GetUrbType(),
811*8a978a17SVictor Perevertkin pUsbPipe->GetUSBDHandle());
812*8a978a17SVictor Perevertkin
813*8a978a17SVictor Perevertkin if (NT_SUCCESS(status)) {
814*8a978a17SVictor Perevertkin FxUsbUrbContext* pContext;
815*8a978a17SVictor Perevertkin pContext = (FxUsbUrbContext*) pRequest->GetContext();
816*8a978a17SVictor Perevertkin
817*8a978a17SVictor Perevertkin pContext->SetUsbType(WdfUsbRequestTypePipeUrb);
818*8a978a17SVictor Perevertkin pContext->m_UsbParameters.Parameters.PipeUrb.Buffer = UrbMemory;
819*8a978a17SVictor Perevertkin }
820*8a978a17SVictor Perevertkin
821*8a978a17SVictor Perevertkin DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGIOTARGET,
822*8a978a17SVictor Perevertkin "Pipe %p, Request %p, Memory %p, status %!STATUS!",
823*8a978a17SVictor Perevertkin Pipe, Request, UrbMemory, status);
824*8a978a17SVictor Perevertkin
825*8a978a17SVictor Perevertkin return status;
826*8a978a17SVictor Perevertkin }
827*8a978a17SVictor Perevertkin
__drv_maxIRQL(DISPATCH_LEVEL)828*8a978a17SVictor Perevertkin __drv_maxIRQL(DISPATCH_LEVEL)
829*8a978a17SVictor Perevertkin USBD_PIPE_HANDLE
830*8a978a17SVictor Perevertkin WDFAPI
831*8a978a17SVictor Perevertkin WDFEXPORT(WdfUsbTargetPipeWdmGetPipeHandle)(
832*8a978a17SVictor Perevertkin __in
833*8a978a17SVictor Perevertkin PWDF_DRIVER_GLOBALS DriverGlobals,
834*8a978a17SVictor Perevertkin __in
835*8a978a17SVictor Perevertkin WDFUSBPIPE UsbPipe
836*8a978a17SVictor Perevertkin )
837*8a978a17SVictor Perevertkin /*++
838*8a978a17SVictor Perevertkin
839*8a978a17SVictor Perevertkin Routine Description:
840*8a978a17SVictor Perevertkin Returns the underlying WDM USBD pipe handle
841*8a978a17SVictor Perevertkin
842*8a978a17SVictor Perevertkin Arguments:
843*8a978a17SVictor Perevertkin UsbPipe - the WDF pipe whose WDM handle will be returned
844*8a978a17SVictor Perevertkin
845*8a978a17SVictor Perevertkin Return Value:
846*8a978a17SVictor Perevertkin valid handle value or NULL on error
847*8a978a17SVictor Perevertkin
848*8a978a17SVictor Perevertkin --*/
849*8a978a17SVictor Perevertkin {
850*8a978a17SVictor Perevertkin DDI_ENTRY();
851*8a978a17SVictor Perevertkin
852*8a978a17SVictor Perevertkin FxUsbPipe* pUsbPipe;
853*8a978a17SVictor Perevertkin
854*8a978a17SVictor Perevertkin FxObjectHandleGetPtr(GetFxDriverGlobals(DriverGlobals),
855*8a978a17SVictor Perevertkin UsbPipe,
856*8a978a17SVictor Perevertkin FX_TYPE_IO_TARGET_USB_PIPE,
857*8a978a17SVictor Perevertkin (PVOID*) &pUsbPipe);
858*8a978a17SVictor Perevertkin
859*8a978a17SVictor Perevertkin return pUsbPipe->WdmGetPipeHandle();
860*8a978a17SVictor Perevertkin }
861*8a978a17SVictor Perevertkin
862*8a978a17SVictor Perevertkin } // extern "C"
863