ReactOS  0.4.15-dev-3303-g1ade494
fxusbinterfaceapi.cpp
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) Microsoft Corporation
4 
5 Module Name:
6 
7  FxUsbInterfaceAPI.cpp
8 
9 Abstract:
10 
11 
12 Author:
13 
14 Environment:
15 
16  Both kernel and user mode
17 
18 Revision History:
19 
20 --*/
21 #include "fxusbpch.hpp"
22 
23 extern "C" {
24 #include "FxUsbInterfaceAPI.tmh"
25 }
26 
27 //
28 // Extern "C" all APIs
29 //
30 extern "C" {
31 
35 WDFAPI
36 WDFEXPORT(WdfUsbInterfaceSelectSetting)(
37  __in
39  __in
40  WDFUSBINTERFACE UsbInterface,
41  __in_opt
43  __in
45  )
46 /*++
47 
48 Routine Description:
49  Selects an alternate setting on a given interface number
50 
51 Arguments:
52  UsbInterface - the interface whose setting will be selected
53 
54  PipesAttributes - Attributes to apply to each of the new pipes on the setting
55 
56  Params - Strucutre indicating how to select a new setting
57 
58 Return Value:
59  NTSTATUS
60 
61  --*/
62 {
63  DDI_ENTRY();
64 
68 
72  (PVOID*) &pUsbInterface,
74 
76 
78  if (!NT_SUCCESS(status)) {
79  return status;
80  }
81 
86  "Params size %d, expected %d %!STATUS!", Params->Size,
88  return status;
89  }
90 
94  if (!NT_SUCCESS(status)) {
95  return status;
96  }
97 
98 #if (FX_CORE_MODE == FX_CORE_USER_MODE)
100  FX_VERIFY_WITH_NAME(INTERNAL, TRAPMSG("UMDF may only select settings by index."),
101  DriverGlobals->DriverName);
102  }
103 #endif
104 
105  switch (Params->Type) {
107  if (Params->Types.Descriptor.InterfaceDescriptor == NULL) {
111  "InterfaceDescriptor passed in is NULL %!STATUS!", status);
112 
113  }
114  else {
117  Params->Types.Descriptor.InterfaceDescriptor
118  );
119  }
120  break;
121 
125  Params->Types.Interface.SettingIndex
126  );
127  break;
128 
130  if (Params->Types.Urb.Urb == NULL ||
131  Params->Types.Urb.Urb->UrbHeader.Function != URB_FUNCTION_SELECT_INTERFACE ||
132  (Params->Types.Urb.Urb->UrbHeader.Length <
133  sizeof(struct _URB_SELECT_INTERFACE) - sizeof(USBD_PIPE_INFORMATION)) ) {
137  "URB or URB fields passed in are invalid Urb 0x%p %!STATUS!",
138  Params->Types.Urb.Urb, status);
139 
140  }
141  else {
143  Params->Types.Urb.Urb);
144  }
145  break;
146 
147  default:
149  break;
150  }
151 
152  return status;
153 }
154 
155 
157 BYTE
158 WDFAPI
159 WDFEXPORT(WdfUsbInterfaceGetInterfaceNumber)(
160  __in
162  __in
163  WDFUSBINTERFACE UsbInterface
164  )
165 /*++
166 
167 Routine Description:
168  Returns the interface number of the given interface. The interface number
169  is not necessarily the same as the index of the interface. Once is specified
170  by the device, the other is where it is located within an internal array.
171 
172 Arguments:
173  UsbInterface - Interace whose number will be returned
174 
175 Return Value:
176  interface number
177 
178  --*/
179 {
180  DDI_ENTRY();
181 
183 
185  UsbInterface,
187  (PVOID*) &pUsbInterface);
188 
190 }
191 
193 BYTE
194 WDFAPI
195 WDFEXPORT(WdfUsbInterfaceGetNumEndpoints)(
196  __in
198  __in
199  WDFUSBINTERFACE UsbInterface,
200  __in
202  )
203 /*++
204 
205 Routine Description:
206  Returns the number of endpoints (not configured) for a given setting on the
207  given interface.
208 
209 Arguments:
210  UsbInterface - interface whose number of endpoints will be returned
211 
212  SettingsIndex - the index into the alternate setting array
213 
214 Return Value:
215  Number of endpoints
216 
217  --*/
218 {
219  DDI_ENTRY();
220 
222 
224  UsbInterface,
226  (PVOID*) &pUsbInterface);
227 
229 }
230 
232 VOID
233 WDFAPI
234 WDFEXPORT(WdfUsbInterfaceGetEndpointInformation)(
235  __in
237  __in
238  WDFUSBINTERFACE UsbInterface,
239  __in
241  __in
243  __out
245  )
246 /*++
247 
248 Routine Description:
249  Returns information on a given endpoint (unconfigured) for an interface +
250  alternate setting index.
251 
252 Arguments:
253  UsbInterface - interface which contains the endpoint
254 
255  SettingIndex - alternate setting index
256 
257  EndpointIndex - index into the endpoint array contained by interface+setting
258 
259  EndpointInfo - structure to be filled in with the info of the endpoint
260 
261 Return Value:
262  None
263 
264  --*/
265 {
266  DDI_ENTRY();
267 
270 
272  UsbInterface,
274  (PVOID*) &pUsbInterface,
276 
278 
279  if (EndpointInfo->Size != sizeof(WDF_USB_PIPE_INFORMATION)) {
282  "EndpointInfo Size %d incorrect, expected %d, %!STATUS!",
283  EndpointInfo->Size, sizeof(WDF_USB_PIPE_INFORMATION),
286  return;
287  }
288 
291  EndpointInfo);
292 }
293 
295 BYTE
296 WDFEXPORT(WdfUsbInterfaceGetNumSettings)(
297  __in
299  __in
300  WDFUSBINTERFACE UsbInterface
301  )
302 /*++
303 
304 Routine Description:
305  Returns the number of settings available on an interface.
306 
307 Arguments:
308  UsbInterface - the usb interface being queried
309 
310 Return Value:
311  Number of settings as described by the config descriptor
312 
313  --*/
314 {
315  DDI_ENTRY();
316 
318 
320  UsbInterface,
322  (PVOID*) &pUsbInterface);
323 
324  return pUsbInterface->GetNumSettings();
325 }
326 
328 VOID
329 WDFAPI
330 WDFEXPORT(WdfUsbInterfaceGetDescriptor)(
331  __in
333  __in
334  WDFUSBINTERFACE UsbInterface,
335  __in
337  __out
339  )
340 /*++
341 
342 Routine Description:
343  Returns the underlying USB interface descriptor for the given WDF handle
344 
345 Arguments:
346  UsbInterface - interface whose descriptor will be returned
347 
348  SettingIndex - alternatve setting whose interface should be returned
349 
350  InterfaceDescriptor - Pointer which will receive the descriptor
351 
352  --*/
353 {
354  DDI_ENTRY();
355 
358 
360  UsbInterface,
362  (PVOID*) &pUsbInterface,
364 
366 
368 }
369 
371 BYTE
372 WDFAPI
373 WDFEXPORT(WdfUsbInterfaceGetConfiguredSettingIndex)(
374  __in
376  __in
377  WDFUSBINTERFACE UsbInterface
378  )
379 /*++
380 
381 Routine Description:
382  Returns the alternate setting index which is currently configured
383 
384 Arguments:
385  UsbInterface - interfase whose configured setting is being queried
386 
387 Return Value:
388  The current setting or 0 on failure
389 
390  --*/
391 {
392  DDI_ENTRY();
393 
395 
397  UsbInterface,
399  (PVOID*) &pUsbInterface);
400 
402 }
403 
405 BYTE
406 WDFAPI
407 WDFEXPORT(WdfUsbInterfaceGetNumConfiguredPipes)(
408  __in
410  __in
411  WDFUSBINTERFACE UsbInterface
412  )
413 /*++
414 
415 Routine Description:
416  Returns the number of configured pipes on a given interface.
417 
418 Arguments:
419  UsbInterface - the configured interface
420 
421 Return Value:
422  Number of configured pipes or 0 on error
423 
424  --*/
425 {
426  DDI_ENTRY();
427 
429 
431  UsbInterface,
433  (PVOID*) &pUsbInterface);
434 
436 }
437 
439 WDFUSBPIPE
440 WDFAPI
441 WDFEXPORT(WdfUsbInterfaceGetConfiguredPipe)(
442  __in
444  __in
445  WDFUSBINTERFACE UsbInterface,
446  __in
448  __out_opt
450  )
451 /*++
452 
453 Routine Description:
454  Returns the WDFUSBPIPE handle for the configured interface + pipe index.
455  Optionally, information about the pipe is also returned.
456 
457 Arguments:
458  UsbInterface - configured interface
459 
460  PipeIndex - index into the number of pipes on the interface
461 
462  PipeInfo - information to be returned on the pipe
463 
464 Return Value:
465  valid WDFUSBPIPE or NULL on error
466 
467  --*/
468 {
469  DDI_ENTRY();
470 
474 
476  UsbInterface,
478  (PVOID*) &pUsbInterface,
480 
481  if (PipeInfo != NULL && PipeInfo->Size != sizeof(WDF_USB_PIPE_INFORMATION)) {
483 
486  "PipeInfo Size %d incorrect, expected %d, %!STATUS!",
487  PipeInfo->Size, sizeof(WDF_USB_PIPE_INFORMATION), status);
488 
490 
491  return NULL;
492  }
493 
495 }
496 
497 } // extern "C"
#define DDI_ENTRY()
Definition: fxglobalskm.h:56
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
_In_ WDFIOTARGET _In_ PWDF_REQUEST_COMPLETION_PARAMS Params
Definition: wdfrequest.h:306
VOID GetDescriptor(__in PUSB_INTERFACE_DESCRIPTOR UsbInterfaceDescriptor, __in UCHAR SettingIndex)
#define __in_opt
Definition: dbghelp.h:38
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_In_ WDFUSBINTERFACE _In_ UCHAR _Out_ PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor
Definition: wdfusb.h:2329
WDFUSBPIPE GetConfiguredPipe(__in UCHAR PipeIndex, __out_opt PWDF_USB_PIPE_INFORMATION PipeInfo)
LONG NTSTATUS
Definition: precomp.h:26
_Must_inspect_result_ NTSTATUS SelectSettingByDescriptor(__in PWDF_OBJECT_ATTRIBUTES PipesAttributes, __in PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor)
__in WDFUSBINTERFACE __in UCHAR __in UCHAR EndpointIndex
DriverGlobals
_Must_inspect_result_ NTSTATUS SelectSettingByIndex(__in PWDF_OBJECT_ATTRIBUTES PipesAttributes, __in UCHAR SettingIndex)
_Must_inspect_result_ __in WDFUSBINTERFACE __in_opt PWDF_OBJECT_ATTRIBUTES PipesAttributes
FX_VERIFY_WITH_NAME(DRIVER(BadArgument, TODO), CHECK(ERROR_STRING_HW_ACCESS_NOT_ALLOWED,(pDevice->IsDirectHardwareAccessAllowed()==TRUE)), DriverGlobals->DriverName)
_In_ WDFUSBINTERFACE _In_ UCHAR PipeIndex
Definition: wdfusb.h:2538
#define __out_opt
Definition: dbghelp.h:65
#define WDFEXPORT(a)
Definition: fxmacros.hpp:157
#define WDFAPI
Definition: wdftypes.h:53
PFX_DRIVER_GLOBALS pFxDriverGlobals
#define __out
Definition: dbghelp.h:62
UCHAR GetNumSettings(VOID)
VOID GetEndpointInformation(__in UCHAR SettingIndex, __in UCHAR PipeIndex, __in PWDF_USB_PIPE_INFORMATION PipeInfo)
UCHAR GetNumConfiguredPipes(VOID)
_Must_inspect_result_ NTSTATUS SelectSetting(__in PWDF_OBJECT_ATTRIBUTES PipesAttributes, __in PURB Urb)
__inline NTSTATUS FxVerifierCheckIrqlLevel(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in KIRQL Irql)
Definition: fxverifier.h:158
UCHAR GetInterfaceNumber(VOID)
_In_ WDFUSBINTERFACE UsbInterface
Definition: wdfusb.h:2276
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
UCHAR GetNumEndpoints(__in UCHAR SettingIndex)
_Must_inspect_result_ __drv_maxIRQL(PASSIVE_LEVEL) NTSTATUS WDFAPI WDFEXPORT(WdfUsbInterfaceSelectSetting)(__in PWDF_DRIVER_GLOBALS DriverGlobals
__in WDFUSBINTERFACE __in UCHAR PipeIndex
unsigned char UCHAR
Definition: xmlstorage.h:181
_Must_inspect_result_ NTSTATUS FxValidateObjectAttributes(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PWDF_OBJECT_ATTRIBUTES Attributes, __in ULONG Flags=FX_VALIDATE_OPTION_NONE_SPECIFIED)
_Must_inspect_result_ _In_ WDFUSBINTERFACE _In_opt_ PWDF_OBJECT_ATTRIBUTES PipesAttributes
Definition: wdfusb.h:2388
FxPointerNotNull(pFxDriverGlobals, Params)
UCHAR GetConfiguredSettingIndex(VOID)
FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals), UsbInterface, FX_TYPE_USB_INTERFACE,(PVOID *) &pUsbInterface, &pFxDriverGlobals)
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define _Must_inspect_result_
Definition: ms_sal.h:558
_In_ WDFUSBINTERFACE _In_ UCHAR _Out_opt_ PWDF_USB_PIPE_INFORMATION PipeInfo
Definition: wdfusb.h:2538
unsigned char BYTE
Definition: xxhash.c:193
#define URB_FUNCTION_SELECT_INTERFACE
Definition: usb.h:87
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
NTSTATUS status
__in WDFUSBINTERFACE __in UCHAR __out PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
#define NULL
Definition: types.h:112
_Must_inspect_result_ __in WDFUSBINTERFACE __in_opt PWDF_OBJECT_ATTRIBUTES __in PWDF_USB_INTERFACE_SELECT_SETTING_PARAMS Params
__in WDFUSBINTERFACE __in UCHAR __out_opt PWDF_USB_PIPE_INFORMATION PipeInfo
_Must_inspect_result_ __in WDFUSBINTERFACE UsbInterface
__in WDFUSBINTERFACE __in UCHAR __in UCHAR __out PWDF_USB_PIPE_INFORMATION EndpointInfo
FxObjectHandleGetPtr(GetFxDriverGlobals(DriverGlobals), UsbInterface, FX_TYPE_USB_INTERFACE,(PVOID *) &pUsbInterface)
FxUsbInterface * pUsbInterface
__inline PFX_DRIVER_GLOBALS GetFxDriverGlobals(__in PWDF_DRIVER_GLOBALS DriverGlobals)
Definition: fxglobals.h:597
_In_ WDFUSBINTERFACE _In_ UCHAR _In_ UCHAR _Out_ PWDF_USB_PIPE_INFORMATION EndpointInfo
Definition: wdfusb.h:2422
#define __in
Definition: dbghelp.h:35
_In_ WDFUSBINTERFACE _In_ UCHAR _In_ UCHAR EndpointIndex
Definition: wdfusb.h:2422
#define TRACINGIOTARGET
Definition: dbgtrace.h:72
__in WDFUSBINTERFACE __in UCHAR SettingIndex
FxVerifierDbgBreakPoint(pFxDriverGlobals)
_In_ WDFUSBINTERFACE _In_ UCHAR SettingIndex
Definition: wdfusb.h:2300
Definition: ps.c:97