ReactOS 0.4.15-dev-7942-gd23573b
FxUsbInterface Class Reference

#include <fxusbinterface.hpp>

Inheritance diagram for FxUsbInterface:
Collaboration diagram for FxUsbInterface:

Public Member Functions

 FxUsbInterface (_In_ PFX_DRIVER_GLOBALS FxDriverGlobals, _In_ FxUsbDevice *UsbDevice, _In_ PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor)
 
VOID SetInfo (__in PUSBD_INTERFACE_INFORMATION Interface)
 
VOID CleanUpAndDelete (__in BOOLEAN ClearDestroyCallback)
 
_Must_inspect_result_ NTSTATUS SelectSetting (__in PWDF_OBJECT_ATTRIBUTES PipesAttributes, __in PURB Urb)
 
UCHAR GetNumConfiguredPipes (VOID)
 
UCHAR GetInterfaceNumber (VOID)
 
UCHAR GetNumSettings (VOID)
 
UCHAR GetNumEndpoints (__in UCHAR SettingIndex)
 
VOID GetEndpointInformation (__in UCHAR SettingIndex, __in UCHAR PipeIndex, __in PWDF_USB_PIPE_INFORMATION PipeInfo)
 
VOID GetDescriptor (__in PUSB_INTERFACE_DESCRIPTOR UsbInterfaceDescriptor, __in UCHAR SettingIndex)
 
UCHAR GetConfiguredSettingIndex (VOID)
 
WDFUSBPIPE GetConfiguredPipe (__in UCHAR PipeIndex, __out_opt PWDF_USB_PIPE_INFORMATION PipeInfo)
 
_Must_inspect_result_ NTSTATUS CreateSettings (VOID)
 
VOID SetNumConfiguredPipes (__in UCHAR NumberOfPipes)
 
VOID SetConfiguredPipes (__in FxUsbPipe **ppPipes)
 
BOOLEAN IsInterfaceConfigured (VOID)
 
_Must_inspect_result_ NTSTATUS SelectSettingByDescriptor (__in PWDF_OBJECT_ATTRIBUTES PipesAttributes, __in PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor)
 
_Must_inspect_result_ NTSTATUS SelectSettingByIndex (__in PWDF_OBJECT_ATTRIBUTES PipesAttributes, __in UCHAR SettingIndex)
 
VOID CopyEndpointFieldsFromDescriptor (__in PWDF_USB_PIPE_INFORMATION PipeInfo, __in PUSB_ENDPOINT_DESCRIPTOR EndpointDesc, __in UCHAR SettingIndex)
 
ULONG DetermineDefaultMaxTransferSize (VOID)
 
WDFUSBINTERFACE GetHandle (VOID)
 
PUSB_INTERFACE_DESCRIPTOR GetSettingDescriptor (__in UCHAR Setting)
 
NTSTATUS CheckAndSelectSettingByIndex (__in UCHAR SettingIndex)
 
NTSTATUS UpdatePipeAttributes (__in PWDF_OBJECT_ATTRIBUTES PipesAttributes)
 
NTSTATUS SetWinUsbHandle (_In_ UCHAR FrameworkInterfaceIndex)
 
NTSTATUS MakeAndConfigurePipes (__in PWDF_OBJECT_ATTRIBUTES PipesAttributes, __in UCHAR NumPipes)
 
- Public Member Functions inherited from FxNonPagedObject
 FxNonPagedObject (__in WDFTYPE Type, __in USHORT Size, __in PFX_DRIVER_GLOBALS FxDriverGlobals)
 
 FxNonPagedObject (__in WDFTYPE Type, __in USHORT Size, __in PFX_DRIVER_GLOBALS FxDriverGlobals, __in FxObjectType ObjectType)
 
virtual ~FxNonPagedObject (VOID)
 
 _Acquires_lock_ (this->m_NPLock.m_Lock) __drv_maxIRQL(DISPATCH_LEVEL) __drv_setsIRQL(DISPATCH_LEVEL) VOID Lock(__out __drv_deref(__drv_savesIRQL) PKIRQL PreviousIrql)
 
 _Releases_lock_ (this->m_NPLock.m_Lock) __drv_requiresIRQL(DISPATCH_LEVEL) __inline VOID Unlock(__in __drv_restoresIRQL KIRQL PreviousIrql)
 
 _Acquires_lock_ (this->m_NPLock.m_Lock) __drv_requiresIRQL(DISPATCH_LEVEL) VOID LockAtDispatch(VOID)
 
 _Requires_lock_held_ (this->m_NPLock.m_Lock) _Releases_lock_(this -> m_NPLock.m_Lock) __drv_requiresIRQL(DISPATCH_LEVEL) __inline VOID UnlockFromDispatch(VOID)
 
- Public Member Functions inherited from FxObject
PVOID GetCOMWrapper ()
 
void SetCOMWrapper (__drv_aliasesMem PVOID Wrapper)
 
 FxObject (__in WDFTYPE Type, __in USHORT Size, __in PFX_DRIVER_GLOBALS FxDriverGlobals)
 
virtual ~FxObject (VOID)
 
PVOID __inline operator new (__in size_t Size, __in PFX_DRIVER_GLOBALS FxDriverGlobals, __in FxObjectType Type)
 
PVOID __inline operator new (__in size_t Size, __in PFX_DRIVER_GLOBALS FxDriverGlobals, __in_opt PWDF_OBJECT_ATTRIBUTES Attributes, __in USHORT ExtraSize=0)
 
VOID operator delete (__in PVOID Memory)
 
VOID SetNoContextHeader (VOID)
 
PVOID __inline GetObjectHandle (VOID)
 
__inline FxContextHeaderGetContextHeader (VOID)
 
__inline PFX_DRIVER_GLOBALS GetDriverGlobals (VOID)
 
WDFTYPE GetType (VOID)
 
USHORT GetObjectSize (VOID)
 
LONG GetRefCnt (VOID)
 
FxTagTrackerGetTagTracker (VOID)
 
CfxDeviceGetDevice (VOID)
 
CfxDeviceBaseGetDeviceBase (VOID)
 
VOID SetDeviceBase (__in CfxDeviceBase *DeviceBase)
 
__inline VOID CallCleanup (VOID)
 
ULONG __inline AddRef (__in_opt PVOID Tag=NULL, __in LONG Line=0, __in_opt PSTR File=NULL)
 
virtual ULONG Release (__in_opt PVOID Tag=NULL, __in LONG Line=0, __in_opt PSTR File=NULL)
 
virtual ULONG AddRefOverride (__in WDFOBJECT_OFFSET Offset, __in_opt PVOID Tag=NULL, __in LONG Line=0, __in_opt PSTR File=NULL)
 
virtual ULONG ReleaseOverride (__in WDFOBJECT_OFFSET Offset, __in_opt PVOID Tag=NULL, __in LONG Line=0, __in_opt PSTR File=NULL)
 
virtual _Must_inspect_result_ NTSTATUS QueryInterface (__in FxQueryInterfaceParams *Params)
 
VOID MarkTraceState (VOID)
 
BOOLEAN __inline IsTraceState (VOID)
 
VOID __inline TraceDroppedEvent (__in FxObjectDroppedEvent Event)
 
VOID MarkPassiveDispose (__in FxObjectLockState State=ObjectLock)
 
VOID MarkPassiveCallbacks (__in FxObjectLockState State=ObjectLock)
 
VOID MarkForceDisposeThread (__in FxObjectLockState State=ObjectLock)
 
BOOLEAN IsPassiveCallbacks (__in BOOLEAN AcquireLock=TRUE)
 
BOOLEAN IsPassiveDispose (__in BOOLEAN AcquireLock=TRUE)
 
BOOLEAN IsForceDisposeThread (__in BOOLEAN AcquireLock=TRUE)
 
VOID MarkCommitted (VOID)
 
BOOLEAN IsCommitted (VOID)
 
VOID MarkDisposeOverride (__in FxObjectLockState State=ObjectLock)
 
VOID MarkNoDeleteDDI (__in FxObjectLockState State=ObjectLock)
 
BOOLEAN IsNoDeleteDDI (VOID)
 
_Must_inspect_result_ NTSTATUS Commit (__in_opt PWDF_OBJECT_ATTRIBUTES Attributes, __out_opt WDFOBJECT *ObjectHandle, __in_opt FxObject *Parent=NULL, __in BOOLEAN AssignDriverAsDefaultParent=TRUE)
 
VOID DeleteFromFailedCreate (VOID)
 
VOID ClearEvtCallbacks (VOID)
 
BOOLEAN EarlyDispose (VOID)
 
virtual VOID DeleteObject (VOID)
 
virtual BOOLEAN Dispose (VOID)
 
_Must_inspect_result_ NTSTATUS AssignParentObject (__in FxObject *ParentObject)
 
_Must_inspect_result_ NTSTATUS AddContext (__in FxContextHeader *Header, __in PVOID *Context, __in PWDF_OBJECT_ATTRIBUTES Attributes)
 
_Must_inspect_result_ NTSTATUS RemoveParentAssignment (VOID)
 
_Must_inspect_result_ FxObjectGetParentObjectReferenced (__in PVOID Tag)
 
BOOLEAN IsDisposed (VOID)
 

Public Attributes

friend FxUsbDevice
 
friend FxUsbPipe
 

Protected Member Functions

 ~FxUsbInterface (VOID)
 
VOID RemoveDeletedPipe (__in FxUsbPipe *Pipe)
 
VOID FormatSelectSettingUrb (__in_bcount(GET_SELECT_INTERFACE_REQUEST_SIZE(NumEndpoints)) PURB Urb, __in USHORT NumEndpoints, __in UCHAR SettingNumber)
 
 __field_ecount (m_NumSettings) FxUsbInterfaceSetting *m_Settings
 
- Protected Member Functions inherited from FxObject
 FxObject (__in WDFTYPE Type, __in USHORT Size, __in PFX_DRIVER_GLOBALS FxDriverGlobals, __in FxObjectType ObjectType)
 
FxObjectDebugExtensionGetDebugExtension (VOID)
 
BOOLEAN IsDebug (VOID)
 
VOID AllocateTagTracker (__in WDFTYPE Type)
 
virtual VOID SelfDestruct (VOID)
 
PVOID __inline GetObjectHandleUnchecked (VOID)
 
VOID __inline DestroyChildren (VOID)
 
VOID DeleteEarlyDisposedObject (VOID)
 

Protected Attributes

FxUsbDevicem_UsbDevice
 
FxUsbPipe ** m_ConfiguredPipes
 
UCHAR m_NumSettings
 
UCHAR m_NumberOfConfiguredPipes
 
UCHAR m_InterfaceNumber
 
UCHAR m_CurAlternateSetting
 
UCHAR m_Class
 
UCHAR m_SubClass
 
UCHAR m_Protocol
 
- Protected Attributes inherited from FxObject
union {
   CfxDeviceBase *   m_DeviceBase
 
   CfxDevice *   m_Device
 
}; 
 

Private Attributes

WINUSB_INTERFACE_HANDLE m_WinUsbHandle
 

Additional Inherited Members

- Static Public Member Functions inherited from FxObject
static FxObject_FromDisposeEntry (__in PSINGLE_LIST_ENTRY Entry)
 
static FxObject_GetObjectFromHandle (__in WDFOBJECT Handle, __inout PWDFOBJECT_OFFSET ObjectOffset)
 
static PVOID __inline _ToHandle (__in FxObject *Object)
 
static VOID __inline _ReferenceActual (__in WDFOBJECT Object, __in_opt PVOID Tag, __in LONG Line, __in PSTR File)
 
static VOID __inline _DereferenceActual (__in WDFOBJECT Object, __in_opt PVOID Tag, __in LONG Line, __in PSTR File)
 
static PVOID _GetDebugBase (__in FxObject *Object)
 
static PFX_POOL_HEADER _CleanupPointer (__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in FxObject *Object)
 
static _Must_inspect_result_ NTSTATUS _GetEffectiveLock (__in FxObject *Object, __in_opt IFxHasCallbacks *Callbacks, __in BOOLEAN AutomaticLocking, __in BOOLEAN PassiveCallbacks, __out FxCallbackLock **CallbackLock, __out_opt FxObject **CallbackLockObject)
 
static _Must_inspect_result_ NTSTATUS _ObjectQuery (_In_ FxObject *Object, _In_ CONST GUID *Guid, _In_ ULONG QueryBufferLength, _Out_writes_bytes_(QueryBufferLength) PVOID QueryBuffer)
 
- Static Protected Member Functions inherited from FxObject
static PVOID _GetBase (__in FxObject *Object)
 

Detailed Description

Definition at line 32 of file fxusbinterface.hpp.

Constructor & Destructor Documentation

◆ FxUsbInterface()

FxUsbInterface::FxUsbInterface ( _In_ PFX_DRIVER_GLOBALS  FxDriverGlobals,
_In_ FxUsbDevice UsbDevice,
_In_ PUSB_INTERFACE_DESCRIPTOR  InterfaceDescriptor 
)

Definition at line 27 of file fxusbinterface.cpp.

31 :
32 FxNonPagedObject(FX_TYPE_USB_INTERFACE ,sizeof(FxUsbInterface), FxDriverGlobals),
34{
35 m_UsbDevice->ADDREF(this);
36
37 m_InterfaceNumber = InterfaceDescriptor->bInterfaceNumber;
38 m_Protocol = InterfaceDescriptor->bInterfaceProtocol;
39 m_Class = InterfaceDescriptor->bInterfaceClass;
40 m_SubClass = InterfaceDescriptor->bInterfaceSubClass;
41
43 m_NumSettings = 0;
46 m_Settings = NULL;
47
49}
VOID MarkNoDeleteDDI(__in FxObjectLockState State=ObjectLock)
Definition: fxobject.hpp:1118
FxUsbPipe ** m_ConfiguredPipes
UCHAR m_NumberOfConfiguredPipes
FxUsbDevice * m_UsbDevice
#define NULL
Definition: types.h:112
@ ObjectDoNotLock
Definition: fxobject.hpp:128
@ FX_TYPE_USB_INTERFACE
Definition: fxtypes.h:104
_In_ WDFUSBINTERFACE _In_ UCHAR _Out_ PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor
Definition: wdfusb.h:2334
_Must_inspect_result_ _In_ WDFDEVICE _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFUSBDEVICE * UsbDevice
Definition: wdfusb.h:906

◆ ~FxUsbInterface()

FxUsbInterface::~FxUsbInterface ( VOID  )
protected

Definition at line 51 of file fxusbinterface.cpp.

52{
53 ULONG i;
54
56
57 for (i = 0; i < m_NumberOfConfiguredPipes; i++) {
59 }
60
61 if (m_ConfiguredPipes != NULL) {
64 }
65
67
68 if (m_Settings != NULL) {
69 FxPoolFree(m_Settings);
70 m_Settings = NULL;
71 }
72
73 //
74 // Release the reference taken in the constructor
75 //
76 m_UsbDevice->RELEASE(this);
77}
VOID RemoveDeletedInterface(__in FxUsbInterface *Interface)
void FxPoolFree(__in_xcount(ptr is at an offset from AllocationStart) PVOID ptr)
Definition: wdfpool.cpp:361
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define ASSERT(a)
Definition: mode.c:44
uint32_t ULONG
Definition: typedefs.h:59

Member Function Documentation

◆ __field_ecount()

FxUsbInterface::__field_ecount ( m_NumSettings  )
protected

◆ CheckAndSelectSettingByIndex()

_Must_inspect_result_ NTSTATUS FxUsbInterface::CheckAndSelectSettingByIndex ( __in UCHAR  SettingIndex)

Definition at line 555 of file fxusbinterface.cpp.

571{
575 }
576 else {
577 return STATUS_SUCCESS;
578 }
579}
_Must_inspect_result_ NTSTATUS SelectSettingByIndex(__in PWDF_OBJECT_ATTRIBUTES PipesAttributes, __in UCHAR SettingIndex)
return pUsbInterface GetConfiguredSettingIndex()
#define STATUS_SUCCESS
Definition: shellext.h:65
_In_ WDFUSBINTERFACE _In_ UCHAR SettingIndex
Definition: wdfusb.h:2303

◆ CleanUpAndDelete()

VOID FxUsbInterface::CleanUpAndDelete ( __in BOOLEAN  ClearDestroyCallback)

Definition at line 80 of file fxusbinterface.cpp.

99{
100 FxUsbPipe** pPipes;
101 ULONG numPipes;
102 KIRQL irql;
103 ULONG i;
104
105 //
106 // Capture the values, clear them out of the object and then clean them up
107 // outside of the lock.
108 //
109 m_UsbDevice->Lock(&irql);
110
111 pPipes = m_ConfiguredPipes;
112 numPipes = m_NumberOfConfiguredPipes;
113
116
118
119 if (pPipes != NULL) {
120 for (i = 0; i < numPipes; i++) {
121 if (pPipes[i] != NULL) {
122 if (Failure) {
123 //
124 // FxIoTarget::Remove will be called in FxIoTarget::Dispose()
125 //
126 pPipes[i]->DeleteFromFailedCreate();
127 }
128 else {
129 pPipes[i]->DeleteObject();
130 }
131 }
132 else {
133 //
134 // No more pointers to delete, break out of the loop
135 //
136 break;
137 }
138 }
139
140 FxPoolFree(pPipes);
141 pPipes = NULL;
142 }
143}
virtual VOID DeleteObject(VOID)
__drv_restoresIRQL KIRQL __in BOOLEAN Unlock
Definition: fxobject.hpp:1474
VOID DeleteFromFailedCreate(VOID)
Definition: fxobject.cpp:391
KIRQL irql
Definition: wave.h:1
UCHAR KIRQL
Definition: env_spec_w32.h:591

Referenced by FxUsbDevice::PipesGotoRemoveState().

◆ CopyEndpointFieldsFromDescriptor()

VOID FxUsbInterface::CopyEndpointFieldsFromDescriptor ( __in PWDF_USB_PIPE_INFORMATION  PipeInfo,
__in PUSB_ENDPOINT_DESCRIPTOR  EndpointDesc,
__in UCHAR  SettingIndex 
)

Definition at line 974 of file fxusbinterface.cpp.

995{
996 PipeInfo->MaximumPacketSize = EndpointDesc->wMaxPacketSize;
997 PipeInfo->EndpointAddress = EndpointDesc->bEndpointAddress;
998 PipeInfo->Interval = EndpointDesc->bInterval;
999
1000 //
1001 // Extract the lower 2 bits which contain the EP type
1002 //
1004 (USBD_PIPE_TYPE) (EndpointDesc->bmAttributes & 0x03)
1005 );
1006
1007 //
1008 // Filling in a default value since the EndpointDescriptor doesn't contain it
1009 //
1010 if (PipeInfo->PipeType == WdfUsbPipeTypeControl) {
1011 PipeInfo->MaximumTransferSize = FxUsbPipeControlMaxTransferSize;
1012 }
1013 else {
1014 PipeInfo->MaximumTransferSize = DetermineDefaultMaxTransferSize();
1015 }
1016
1017 PipeInfo->SettingIndex = SettingIndex;
1018}
ULONG DetermineDefaultMaxTransferSize(VOID)
static WDF_USB_PIPE_TYPE _UsbdPipeTypeToWdf(__in USBD_PIPE_TYPE UsbdPipeType)
Definition: fxusbpipe.hpp:643
@ FxUsbPipeControlMaxTransferSize
Definition: fxusbpipe.hpp:17
enum _USBD_PIPE_TYPE USBD_PIPE_TYPE
_In_ WDFUSBINTERFACE _In_ UCHAR _Out_opt_ PWDF_USB_PIPE_INFORMATION PipeInfo
Definition: wdfusb.h:2543
@ WdfUsbPipeTypeControl
Definition: wdfusb.h:119

Referenced by GetEndpointInformation().

◆ CreateSettings()

_Must_inspect_result_ NTSTATUS FxUsbInterface::CreateSettings ( VOID  )

Definition at line 197 of file fxusbinterface.cpp.

214{
215 PUSB_INTERFACE_DESCRIPTOR pDescriptor;
216 ULONG size;
217 UCHAR i;
218
219 //
220 // No need to validate the size of the interface descriptor since FxUsbDevice::CreateInterfaces
221 // has already done so
222 //
228 );
229
230 //
231 // Calculate the number of settings for this interface
232 //
233 while (pDescriptor != NULL) {
234 if (m_InterfaceNumber == pDescriptor->bInterfaceNumber) {
236 }
240 WDF_PTR_ADD_OFFSET(pDescriptor, pDescriptor->bLength),
242 );
243 }
245 m_Settings = (FxUsbInterfaceSetting *) FxPoolAllocate(
247
248 if (m_Settings == NULL) {
251 "Could not allocate memory for %d settings for bInterfaceNumber %d "
252 "(Protocol %d, Class %d, SubClass %d), %!STATUS!",
255
257 }
258
259 RtlZeroMemory(m_Settings, size);
260
261 //
262 // Add all the settings for this interface
263 //
269 );
270
271 while (pDescriptor != NULL) {
272 if (m_InterfaceNumber == pDescriptor->bInterfaceNumber) {
273 if (pDescriptor->bAlternateSetting < m_NumSettings) {
274 m_Settings[pDescriptor->bAlternateSetting].InterfaceDescriptor = pDescriptor;
275 }
276 else {
279 "Interface Number %d does not have contiguous alternate settings,"
280 "expected %d settings, found alt setting %d, %!STATUS!",
281 pDescriptor->bInterfaceNumber, m_NumSettings,
283
285 }
286 }
287
291 WDF_PTR_ADD_OFFSET(pDescriptor, pDescriptor->bLength),
293 );
294 }
295
296 for (i = 0; i < m_NumSettings; i++) {
297
298 if (m_Settings[i].InterfaceDescriptor == NULL) {
301 "Interface Number %d does not have contiguous alternate settings,"
302 "expected consecutive %d settings, but alt setting %d missing "
303 "%!STATUS!", m_InterfaceNumber, m_NumSettings, i,
305
307 }
308
309 //
310 // Only validate the endpoints if the interface reports it has some. We don't
311 // want to validate EP descriptors that may be after the interface descriptor
312 // that are never used because bNumEndpoints doesn't indicate they are present.
313 //
314 if (m_Settings[i].InterfaceDescriptor->bNumEndpoints > 0) {
315 PVOID pRelativeEnd;
317
318 //
319 // Validate that each endpoint descriptor is the correct size for this alt setting.
320 // We will use the next inteface descriptor as the end, and if this is the last
321 // interface descriptor, use the end of the config descriptor as our end.
322 //
323 pRelativeEnd = FxUsbFindDescriptorType(
326 m_Settings[i].InterfaceDescriptor,
328 );
329
330 if (pRelativeEnd == NULL) {
331 //
332 // This is the last alt setting in the config descriptor, use the end of the
333 // config descriptor as our end
334 //
337 }
338
339 //
340 // Limit the number of endpoints validated to bNumEndpoints. In theory
341 // there could be EP descriptors after N EP descriptors that are never
342 // used, thus we don't want to risk valdiating them and failing them
343 // (ie an app compat concern, in a perfect world we would validate them)
344 //
348 m_Settings[i].InterfaceDescriptor,
349 pRelativeEnd,
353 m_Settings[i].InterfaceDescriptor->bNumEndpoints
354 );
355
356 if (!NT_SUCCESS(status)) {
359 "Interface Number %d does not have a valid endpoint descriptor,"
360 "%!STATUS!", m_InterfaceNumber, status);
361
362 return status;
363 }
364 }
365 }
366
367 return STATUS_SUCCESS;
368}
LONG NTSTATUS
Definition: precomp.h:26
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
PUSB_CONFIGURATION_DESCRIPTOR m_ConfigDescriptor
#define TRACINGIOTARGET
Definition: dbgtrace.h:72
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define NonPagedPool
Definition: env_spec_w32.h:307
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
GLsizeiptr size
Definition: glext.h:5919
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
Definition: ps.c:97
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define USB_ENDPOINT_DESCRIPTOR_TYPE
Definition: usb100.h:53
struct _USB_INTERFACE_DESCRIPTOR * PUSB_INTERFACE_DESCRIPTOR
#define USB_INTERFACE_DESCRIPTOR_TYPE
Definition: usb100.h:52
PUSB_COMMON_DESCRIPTOR FxUsbFindDescriptorType(__in PVOID Buffer, __in size_t BufferLength, __in PVOID Start, __in LONG DescriptorType)
Definition: usbutil.cpp:174
NTSTATUS FxUsbValidateDescriptorType(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PUSB_CONFIGURATION_DESCRIPTOR ConfigDescriptor, __in PVOID Start, __in PVOID End, __in LONG DescriptorType, __in size_t SizeToValidate, __in FxUsbValidateDescriptorOp Op, __in ULONG MaximumNumDescriptorsToValidate)
Definition: usbutil.cpp:207
@ FxUsbValidateDescriptorOpAtLeast
Definition: usbutil.hpp:128
#define WDF_PTR_ADD_OFFSET(_ptr, _offset)
Definition: wdfcore.h:144
unsigned char UCHAR
Definition: xmlstorage.h:181

◆ DetermineDefaultMaxTransferSize()

ULONG FxUsbInterface::DetermineDefaultMaxTransferSize ( VOID  )

Definition at line 949 of file fxusbinterface.cpp.

964{
967 }
968 else {
970 }
971}
@ FxUsbPipeHighSpeedMaxTransferSize
Definition: fxusbpipe.hpp:15
@ FxUsbPipeLowSpeedMaxTransferSize
Definition: fxusbpipe.hpp:16
@ WDF_USB_DEVICE_TRAIT_AT_HIGH_SPEED
Definition: wdfusb.h:144

Referenced by CopyEndpointFieldsFromDescriptor().

◆ FormatSelectSettingUrb()

VOID FxUsbInterface::FormatSelectSettingUrb ( __in_bcount(GET_SELECT_INTERFACE_REQUEST_SIZE(NumEndpoints)) PURB  Urb,
__in USHORT  NumEndpoints,
__in UCHAR  SettingNumber 
)
protected

Definition at line 784 of file fxusbinterface.cpp.

810{
811 ULONG defaultMaxTransferSize;
812 USHORT size;
813 UCHAR i;
814
816
817 RtlZeroMemory(Urb, size);
818
819 //
820 // Setup the URB, format the request, and send it
821 //
823 size,
826 SettingNumber);
827
828 defaultMaxTransferSize = m_UsbDevice->GetDefaultMaxTransferSize();
829
830 Urb->UrbSelectInterface.Interface.Length =
831 GET_USBD_INTERFACE_SIZE(NumEndpoints);
832
833 Urb->UrbSelectInterface.Interface.NumberOfPipes = NumEndpoints;
834
835 for (i = 0; i < NumEndpoints; i++) {
836
837 //
838 // Make sure that the Interface Length conveys the exact number of EP's
839 //
840 ASSERT(
841 &Urb->UrbSelectInterface.Interface.Pipes[i] <
842 WDF_PTR_ADD_OFFSET(&Urb->UrbSelectInterface.Interface,
843 Urb->UrbSelectInterface.Interface.Length)
844 );
845
846 Urb->UrbSelectInterface.Interface.Pipes[i].PipeFlags = 0x0;
847 Urb->UrbSelectInterface.Interface.Pipes[i].MaximumTransferSize =
848 defaultMaxTransferSize;
849 }
850}
ULONG GetDefaultMaxTransferSize(VOID)
USBD_CONFIGURATION_HANDLE m_ConfigHandle
unsigned short USHORT
Definition: pedump.c:61
#define GET_USBD_INTERFACE_SIZE(numEndpoints)
Definition: usbdlib.h:121
#define UsbBuildSelectInterfaceRequest(urb, length, configurationHandle, interfaceNumber, alternateSetting)
Definition: usbdlib.h:59
#define GET_SELECT_INTERFACE_REQUEST_SIZE(totalPipes)
Definition: usbdlib.h:117

Referenced by FxUsbDevice::SelectConfig(), SelectSettingByDescriptor(), and SelectSettingByIndex().

◆ GetConfiguredPipe()

WDFUSBPIPE FxUsbInterface::GetConfiguredPipe ( __in UCHAR  PipeIndex,
__out_opt PWDF_USB_PIPE_INFORMATION  PipeInfo 
)

Definition at line 1021 of file fxusbinterface.cpp.

1039{
1041 return NULL;
1042 }
1043 else {
1044 if (PipeInfo != NULL) {
1046 }
1047
1049 }
1050}
VOID GetInformation(__out PWDF_USB_PIPE_INFORMATION PipeInformation)
WDFUSBPIPE GetHandle(VOID)
Definition: fxusbpipe.hpp:504
_In_ WDFUSBINTERFACE _In_ UCHAR PipeIndex
Definition: wdfusb.h:2540

◆ GetConfiguredSettingIndex()

UCHAR FxUsbInterface::GetConfiguredSettingIndex ( VOID  )

Definition at line 1084 of file fxusbinterface.cpp.

1100{
1101 if (IsInterfaceConfigured()) {
1102 return m_CurAlternateSetting;
1103 }
1104 else {
1107 "WDFUSBINTERFACE %p not configured, cannot retrieve configured "
1108 "setting index", GetHandle());
1109
1111
1112 return 0;
1113 }
1114}
BOOLEAN IsInterfaceConfigured(VOID)
FxVerifierDbgBreakPoint(pFxDriverGlobals)
#define GetHandle(h)
Definition: treelist.c:116

Referenced by FxUsbPipe::GetInformation().

◆ GetDescriptor()

VOID FxUsbInterface::GetDescriptor ( __in PUSB_INTERFACE_DESCRIPTOR  UsbInterfaceDescriptor,
__in UCHAR  SettingIndex 
)

Definition at line 1053 of file fxusbinterface.cpp.

1071{
1072 if (SettingIndex >= m_NumSettings) {
1073 RtlZeroMemory(UsbInterfaceDescriptor,
1074 sizeof(*UsbInterfaceDescriptor));
1075 }
1076 else {
1077 RtlCopyMemory(UsbInterfaceDescriptor,
1079 sizeof(*UsbInterfaceDescriptor));
1080 }
1081}
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263

◆ GetEndpointInformation()

VOID FxUsbInterface::GetEndpointInformation ( __in UCHAR  SettingIndex,
__in UCHAR  PipeIndex,
__in PWDF_USB_PIPE_INFORMATION  PipeInfo 
)

Definition at line 853 of file fxusbinterface.cpp.

876{
877 PUCHAR pEnd, pCur;
878 PUSB_INTERFACE_DESCRIPTOR pInterfaceDesc;
879 PUSB_ENDPOINT_DESCRIPTOR pEndpointDesc;
880 UCHAR curEndpointIndex;
881 BOOLEAN endPointFound;
882
883 pInterfaceDesc = NULL;
884 curEndpointIndex = 0;
885 endPointFound = FALSE;
886
887 //
888 // Extract the interface descriptor for the alternate setting for the interface
889 //
890 pInterfaceDesc = GetSettingDescriptor(SettingIndex);
891
892 if (pInterfaceDesc == NULL) {
893 return;
894 }
895
896 pEnd = (PUCHAR) WDF_PTR_ADD_OFFSET(
899 );
900
901 //
902 // Start from the descriptor after current one
903 //
904 pCur = (PUCHAR) WDF_PTR_ADD_OFFSET(pInterfaceDesc, pInterfaceDesc->bLength);
905
906 //
907 // Iterate through the list of EP descriptors following the interface descriptor
908 // we just found and get the endpoint descriptor which matches the endpoint
909 // index or we hit another interface descriptor
910 //
911 // We have already validated that the descriptor headers are well formed and within
912 // the config descriptor bounds
913 //
914 while (pCur < pEnd) {
916
917 //
918 // If we hit the next interface no way we can find the EndPoint
919 //
921 break;
922 }
923
924 if (pCommonDesc->bDescriptorType == USB_ENDPOINT_DESCRIPTOR_TYPE) {
925 //
926 // Size of pEndpointDesc has been validated by CreateSettings() and
927 // is within the config descriptor
928 //
929 pEndpointDesc = (PUSB_ENDPOINT_DESCRIPTOR) pCommonDesc;
930
931 if (EndpointIndex == curEndpointIndex) {
933 pEndpointDesc,
935 break;
936 }
937
938 curEndpointIndex++;
939 }
940
941 //
942 // Advance past this descriptor
943 //
944 pCur += pCommonDesc->bLength;
945 }
946}
unsigned char BOOLEAN
VOID CopyEndpointFieldsFromDescriptor(__in PWDF_USB_PIPE_INFORMATION PipeInfo, __in PUSB_ENDPOINT_DESCRIPTOR EndpointDesc, __in UCHAR SettingIndex)
PUSB_INTERFACE_DESCRIPTOR GetSettingDescriptor(__in UCHAR Setting)
#define FALSE
Definition: types.h:117
SINGLE_LIST_ENTRY * pCur
unsigned char * PUCHAR
Definition: typedefs.h:53
struct _USB_COMMON_DESCRIPTOR * PUSB_COMMON_DESCRIPTOR
struct _USB_ENDPOINT_DESCRIPTOR * PUSB_ENDPOINT_DESCRIPTOR
_In_ WDFUSBINTERFACE _In_ UCHAR _In_ UCHAR EndpointIndex
Definition: wdfusb.h:2426

◆ GetHandle()

WDFUSBINTERFACE FxUsbInterface::GetHandle ( VOID  )
inline

Definition at line 173 of file fxusbinterface.hpp.

174 {
175 return (WDFUSBINTERFACE) GetObjectHandle();
176 }
return pObject GetObjectHandle()

Referenced by if(), and FxUsbDevice::SelectConfigSingle().

◆ GetInterfaceNumber()

UCHAR FxUsbInterface::GetInterfaceNumber ( VOID  )
inline

Definition at line 70 of file fxusbinterface.hpp.

73 {
74 return m_InterfaceNumber;
75 }

Referenced by FxUsbDevice::GetInterfaceNumberFromInterface().

◆ GetNumConfiguredPipes()

UCHAR FxUsbInterface::GetNumConfiguredPipes ( VOID  )
inline

Definition at line 62 of file fxusbinterface.hpp.

65 {
67 }

Referenced by FxUsbDevice::SelectConfigSingle().

◆ GetNumEndpoints()

UCHAR FxUsbInterface::GetNumEndpoints ( __in UCHAR  SettingIndex)

Definition at line 1117 of file fxusbinterface.cpp.

1132{
1133 if (SettingIndex >= m_NumSettings) {
1134 return 0;
1135 }
1136 else {
1137 return m_Settings[SettingIndex].InterfaceDescriptor->bNumEndpoints;
1138 }
1139}

◆ GetNumSettings()

UCHAR FxUsbInterface::GetNumSettings ( VOID  )
inline

Definition at line 78 of file fxusbinterface.hpp.

81 {
82 return m_NumSettings;
83 }

Referenced by switch().

◆ GetSettingDescriptor()

PUSB_INTERFACE_DESCRIPTOR FxUsbInterface::GetSettingDescriptor ( __in UCHAR  Setting)

Definition at line 1142 of file fxusbinterface.cpp.

1157{
1158 UCHAR i;
1159
1160 for (i = 0; i < m_NumSettings; i++) {
1161 if (m_Settings[i].InterfaceDescriptor->bAlternateSetting == Setting) {
1162 return m_Settings[i].InterfaceDescriptor;
1163 }
1164 }
1165
1166 return NULL;
1167}

Referenced by GetEndpointInformation(), FxUsbDevice::SelectConfigMulti(), and FxUsbDevice::SelectConfigSingle().

◆ IsInterfaceConfigured()

BOOLEAN FxUsbInterface::IsInterfaceConfigured ( VOID  )
inline

◆ MakeAndConfigurePipes()

NTSTATUS FxUsbInterface::MakeAndConfigurePipes ( __in PWDF_OBJECT_ATTRIBUTES  PipesAttributes,
__in UCHAR  NumPipes 
)

Definition at line 85 of file fxusbinterfaceum.cpp.

89{
91 UCHAR iPipe;
92 FxUsbPipe* pPipe;
93 FxUsbPipe** ppPipes;
94 //
95 // Zero pipes are a valid configuration, this simplifies the code below.
96 //
97 ULONG size = (NumPipes == 0 ? 1 : NumPipes) * sizeof(FxUsbPipe*);
98 UMURB urb;
99
100 ppPipes = (FxUsbPipe**)FxPoolAllocate(GetDriverGlobals(), NonPagedPool, size);
101 if (ppPipes == NULL) {
105 "Unable to allocate memory %!STATUS!", status);
106 goto Done;
107 }
108
109 RtlZeroMemory(ppPipes, size);
110
111 for (iPipe = 0; iPipe < NumPipes; iPipe++) {
112 ppPipes[iPipe] = new (GetDriverGlobals(), PipesAttributes)
114
115 if (ppPipes[iPipe] == NULL) {
119 "Unable to allocate memory for the pipes %!STATUS!", status);
120 goto Done;
121 }
122
123 pPipe = ppPipes[iPipe];
124
125 status = pPipe->Init(m_UsbDevice->m_Device);
126 if (!NT_SUCCESS(status)) {
129 "Init pipe failed %!STATUS!", status);
130 goto Done;
131 }
132
133 status = pPipe->Commit(PipesAttributes, NULL, this);
134 if (!NT_SUCCESS(status)) {
137 "Commit pipe failed %!STATUS!", status);
138 goto Done;
139 }
140 }
141
142 if (IsInterfaceConfigured()) {
143 //
144 // Delete the old pipes
145 //
147 }
148
149 SetNumConfiguredPipes(NumPipes);
150 SetConfiguredPipes(ppPipes);
151
152 for (iPipe = 0; iPipe < m_NumberOfConfiguredPipes ; iPipe++) {
153 RtlZeroMemory(&urb, sizeof(UMURB));
154
155 urb.UmUrbQueryPipe.Hdr.InterfaceHandle = m_WinUsbHandle;
156 urb.UmUrbQueryPipe.Hdr.Function = UMURB_FUNCTION_QUERY_PIPE;
157 urb.UmUrbQueryPipe.Hdr.Length = sizeof(_UMURB_QUERY_PIPE);
158
159 urb.UmUrbQueryPipe.AlternateSetting = m_CurAlternateSetting;
160 urb.UmUrbQueryPipe.PipeID = iPipe;
161
162 status = m_UsbDevice->SendSyncUmUrb(&urb, 2);
163
164 if (!NT_SUCCESS(status)) {
167 "Send UMURB_FUNCTION_QUERY_PIPE failed %!STATUS!", status);
168 goto Done;
169 }
170
171 m_ConfiguredPipes[iPipe]->InitPipe(&urb.UmUrbQueryPipe.PipeInformation,
173 this);
174 }
175
176Done:
177 if (!NT_SUCCESS(status)) {
178 if (ppPipes != NULL) {
179 ASSERT(ppPipes != m_ConfiguredPipes);
180
181 for (iPipe = 0; iPipe < NumPipes; iPipe++) {
182 if (ppPipes[iPipe] != NULL) {
183 ppPipes[iPipe]->DeleteFromFailedCreate();
184 }
185 }
186
187 FxPoolFree(ppPipes);
188 ppPipes = NULL;
189 }
190 }
191
192 return status;
193}
_Must_inspect_result_ NTSTATUS Init(__in CfxDeviceBase *Device)
CfxDevice * m_Device
Definition: fxobject.hpp:329
_Must_inspect_result_ NTSTATUS Commit(__in_opt PWDF_OBJECT_ATTRIBUTES Attributes, __out_opt WDFOBJECT *ObjectHandle, __in_opt FxObject *Parent=NULL, __in BOOLEAN AssignDriverAsDefaultParent=TRUE)
Definition: fxobject.cpp:904
VOID CleanupInterfacePipesAndDelete(__in FxUsbInterface *UsbInterface)
_Must_inspect_result_ NTSTATUS SendSyncUmUrb(__inout PUMURB Urb, __in ULONGLONG Time, __in_opt WDFREQUEST Request=NULL, __in_opt PWDF_REQUEST_SEND_OPTIONS Options=NULL)
VOID SetConfiguredPipes(__in FxUsbPipe **ppPipes)
WINUSB_INTERFACE_HANDLE m_WinUsbHandle
VOID SetNumConfiguredPipes(__in UCHAR NumberOfPipes)
VOID InitPipe(__in PUSBD_PIPE_INFORMATION PipeInfo, __in UCHAR InterfaceNumber, __in FxUsbInterface *UsbInterface)
Definition: fxusbpipe.cpp:1073
Definition: umusb.h:173
struct _UMURB_QUERY_PIPE UmUrbQueryPipe
Definition: umusb.h:237
#define UMURB_FUNCTION_QUERY_PIPE
Definition: umusb.h:46
_Must_inspect_result_ _In_ WDFUSBINTERFACE _In_opt_ PWDF_OBJECT_ATTRIBUTES PipesAttributes
Definition: wdfusb.h:2390

Referenced by SelectSettingByIndex().

◆ RemoveDeletedPipe()

VOID FxUsbInterface::RemoveDeletedPipe ( __in FxUsbPipe Pipe)
protected

Definition at line 146 of file fxusbinterface.cpp.

149{
150 ULONG i;
151
152 if (m_ConfiguredPipes == NULL) {
153 return;
154 }
155
156 for (i = 0; i < m_NumberOfConfiguredPipes; i++) {
157 if (m_ConfiguredPipes[i] == Pipe) {
159 return;
160 }
161 }
162}
_In_ WDFUSBPIPE Pipe
Definition: wdfusb.h:1741

Referenced by FxUsbPipe::~FxUsbPipe().

◆ SelectSetting()

_Must_inspect_result_ NTSTATUS FxUsbInterface::SelectSetting ( __in PWDF_OBJECT_ATTRIBUTES  PipesAttributes,
__in PURB  Urb 
)

Definition at line 583 of file fxusbinterface.cpp.

605{
606 FxSyncRequest request(GetDriverGlobals(), NULL);
607 LIST_ENTRY pendHead;
608 FxUsbPipe* pPipe;
610 UCHAR iPipe, numPipes;
612 FxUsbPipe ** ppPipes;
613 ULONG size;
614
615 //
616 // FxSyncRequest always succeesds for KM but can fail for UM.
617 //
618 status = request.Initialize();
619 if (!NT_SUCCESS(status)) {
621 "Failed to initialize FxSyncRequest");
622 return status;
623 }
624
625 //
626 // Subtract the size of the embedded pipe.
627 //
628 const ULONG interfaceStructSize = sizeof(Urb->UrbSelectInterface.Interface) -
629 sizeof(USBD_PIPE_INFORMATION);
630
631 //
632 // This check will happen twice for SelectSettingByInterface/Descriptor.
633 //
634 // We could just do it here, but the above two functions will unnecessarily
635 // have to build an URB.
636 //
637 if (IsInterfaceConfigured() &&
639 Urb->UrbSelectInterface.Interface.AlternateSetting) {
640 //
641 // don't do anything
642 //
643 return STATUS_SUCCESS;
644 }
645
646 InitializeListHead(&pendHead);
647 numPipes = 0;
648 ppPipes = NULL;
649
650 if (Urb->UrbSelectInterface.Hdr.Length < interfaceStructSize) {
654 "Urb header length 0x%x is less than expected 0x%x"
655 "%!STATUS!", Urb->UrbSelectInterface.Hdr.Length, interfaceStructSize,status
656 );
657 return status;
658 }
659
660 status = request.m_TrueRequest->ValidateTarget(m_UsbDevice);
661 if (!NT_SUCCESS(status)) {
662 goto Done;
663 }
664
665 //
666 // Urb->UrbSelectInterface.Interface.NumberOfPipes is set when the URB
667 // completes. So, we must compute the number of pipes being requested based
668 // on the size of the structure and its Length (as set by the caller).
669 // To calculate the number of pipes we need to account for the
670 // embedded pipe in the structure.
671 //
672 numPipes = (UCHAR) ((Urb->UrbSelectInterface.Interface.Length -
673 interfaceStructSize) /
675 );
676
677 if (numPipes > 0) {
678 size = numPipes * sizeof(FxUsbPipe *);
679 }
680 else {
681 //
682 // It is valid to have an interface with zero pipes in it. In that
683 // case, we just allocate one entry so that we have a valid array
684 // and keep the remaining code simple.
685 //
686 size = sizeof(FxUsbPipe*);
687 }
688
689 //
690 // If the interface is already configured don't do anything with the old
691 // settings till we allocate new.
692 //
693 ppPipes = (FxUsbPipe **) FxPoolAllocate(GetDriverGlobals(), NonPagedPool, size);
694
695 if (ppPipes == NULL) {
699 "Unable to allocate memory %!STATUS!"
700 , status);
701 goto Done;
702 }
703
704 RtlZeroMemory(ppPipes, size);
705
706 for (iPipe = 0; iPipe < numPipes; iPipe++) {
707 ppPipes[iPipe] = new (GetDriverGlobals(), PipesAttributes)
709
710 if (ppPipes[iPipe] == NULL) {
714 "Unable to allocate memory for the pipes %!STATUS!", status);
715 goto Done;
716 }
717
718 pPipe = ppPipes[iPipe];
719
720 status = pPipe->Init(m_UsbDevice->m_Device);
721 if (!NT_SUCCESS(status)) {
724 "Init pipe failed %!STATUS!", status);
725 goto Done;
726 }
727
728 status = pPipe->Commit(PipesAttributes, NULL, this);
729
730 if (!NT_SUCCESS(status)) {
733 "Commit pipe failed %!STATUS!", status);
734 goto Done;
735 }
736 }
737
738 if (IsInterfaceConfigured()) {
739 //
740 // Delete the old pipes
741 //
743 }
744
745
748
750
751 FxFormatUsbRequest(request.m_TrueRequest, Urb, FxUrbTypeLegacy, NULL);
752 status = m_UsbDevice->SubmitSync(request.m_TrueRequest, &options, NULL);
753
754 //
755 // If select interface URB fails we are at the point of no return and we
756 // will end up with no configured pipes.
757 //
758 if (NT_SUCCESS(status)) {
759 SetNumConfiguredPipes(numPipes);
760 SetConfiguredPipes(ppPipes);
761 SetInfo(&Urb->UrbSelectInterface.Interface);
762 }
763
764Done:
765 if (!NT_SUCCESS(status)) {
766 if (ppPipes != NULL) {
767 ASSERT(ppPipes != m_ConfiguredPipes);
768
769 for (iPipe = 0; iPipe < numPipes; iPipe++) {
770 if (ppPipes[iPipe] != NULL) {
771 ppPipes[iPipe]->DeleteFromFailedCreate();
772 }
773 }
774
775 FxPoolFree(ppPipes);
776 ppPipes = NULL;
777 }
778 }
779
780 return status;
781}
_Must_inspect_result_ NTSTATUS SubmitSync(__in FxRequestBase *Request, __in_opt PWDF_REQUEST_SEND_OPTIONS Options=NULL, __out_opt PULONG Action=NULL)
VOID SetInfo(__in PUSBD_INTERFACE_INFORMATION Interface)
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
@ FxUrbTypeLegacy
Definition: fxusbdevice.hpp:27
Definition: typedefs.h:120
Definition: tftpd.h:86
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
struct _USBD_PIPE_INFORMATION USBD_PIPE_INFORMATION
VOID FxFormatUsbRequest(__in FxRequestBase *Request, __in PURB Urb, __in FX_URB_TYPE FxUrbType, __drv_when(FxUrbType==FxUrbTypeUsbdAllocated, __in) __drv_when(FxUrbType !=FxUrbTypeUsbdAllocated, __in_opt) USBD_HANDLE UsbdHandle)
Definition: usbutil.cpp:29
FORCEINLINE LONGLONG WDF_REL_TIMEOUT_IN_SEC(_In_ ULONGLONG Time)
Definition: wdfcore.h:62
FORCEINLINE VOID WDF_REQUEST_SEND_OPTIONS_INIT(_Out_ PWDF_REQUEST_SEND_OPTIONS Options, _In_ ULONG Flags)
Definition: wdfrequest.h:409
@ WDF_REQUEST_SEND_OPTION_IGNORE_TARGET_STATE
Definition: wdfrequest.h:110
FORCEINLINE VOID WDF_REQUEST_SEND_OPTIONS_SET_TIMEOUT(_Inout_ PWDF_REQUEST_SEND_OPTIONS Options, _In_ LONGLONG Timeout)
Definition: wdfrequest.h:421

Referenced by SelectSettingByDescriptor(), SelectSettingByIndex(), and switch().

◆ SelectSettingByDescriptor()

_Must_inspect_result_ NTSTATUS FxUsbInterface::SelectSettingByDescriptor ( __in PWDF_OBJECT_ATTRIBUTES  PipesAttributes,
__in PUSB_INTERFACE_DESCRIPTOR  InterfaceDescriptor 
)

Definition at line 488 of file fxusbinterface.cpp.

504{
505 PURB urb;
507 USHORT size;
508
509 if (IsInterfaceConfigured() &&
510 (m_CurAlternateSetting == InterfaceDescriptor->bAlternateSetting)) {
511 //
512 // Don't do anything
513 //
514 return STATUS_SUCCESS;
515 }
516
517 if (InterfaceDescriptor->bInterfaceNumber != m_InterfaceNumber) {
519
522 "WDFUSBINTERFACE %p has interface num %d, select setting by "
523 "descriptor specified interface num %d, %!STATUS!",
525 InterfaceDescriptor->bInterfaceNumber, status
526 );
527
528 return status;
529 }
530
532
533 urb = (PURB) FxPoolAllocate(GetDriverGlobals(), NonPagedPool, size);
534
535 if (urb == NULL) {
537 }
538 else {
540 urb,
541 InterfaceDescriptor->bNumEndpoints,
542 InterfaceDescriptor->bAlternateSetting
543 );
544
546
547 FxPoolFree(urb);
548 }
549
550 return status;
551}
VOID FormatSelectSettingUrb(__in_bcount(GET_SELECT_INTERFACE_REQUEST_SIZE(NumEndpoints)) PURB Urb, __in USHORT NumEndpoints, __in UCHAR SettingNumber)
_Must_inspect_result_ NTSTATUS SelectSetting(__in PWDF_OBJECT_ATTRIBUTES PipesAttributes, __in PURB Urb)
Definition: usb.h:529
struct _URB * PURB

Referenced by switch().

◆ SelectSettingByIndex()

_Must_inspect_result_ NTSTATUS FxUsbInterface::SelectSettingByIndex ( __in PWDF_OBJECT_ATTRIBUTES  PipesAttributes,
__in UCHAR  SettingIndex 
)

Definition at line 372 of file fxusbinterface.cpp.

390{
391#if (FX_CORE_MODE == FX_CORE_KERNEL_MODE)
392 PURB urb;
393#elif (FX_CORE_MODE == FX_CORE_USER_MODE)
394 UMURB urb;
395 PUSB_INTERFACE_DESCRIPTOR interfaceDesc;
396#endif
398 UCHAR numEP;
400 USHORT size;
401
403
404 //
405 // We should have at least 1 setting on the interface
406 //
407 ASSERT(m_NumSettings != 0);
408
409 //
410 // If m_NumberOfConfiguredPipes == 0 then it also tells us that
411 // the interface wasn't configured. So it can keep track of configuredness
412 // of the interface. Could there be a case when the selected setting has 0
413 // EP's. Due to the above case we use m_InterfaceConfigured.
414 //
416 return STATUS_SUCCESS;
417 }
418
419 //
420 // Check for an invalid alternate setting
421 //
424 }
425
426 RtlCopyMemory(&entry, &m_Settings[SettingIndex], sizeof(entry));
427
428 //
429 // Create the configured pipes
430 //
431 numEP = entry.InterfaceDescriptor->bNumEndpoints;
432
434
435#if (FX_CORE_MODE == FX_CORE_KERNEL_MODE)
436 urb = (PURB) FxPoolAllocate(GetDriverGlobals(), NonPagedPool, size);
437
438 if (urb == NULL) {
440 }
441 else {
443
445
446 FxPoolFree(urb);
447 urb = NULL;
448 }
449#elif (FX_CORE_MODE == FX_CORE_USER_MODE)
450 RtlZeroMemory(&urb, sizeof(UMURB));
451
452 urb.UmUrbSelectInterface.Hdr.InterfaceHandle = m_WinUsbHandle;
453 urb.UmUrbSelectInterface.Hdr.Function = UMURB_FUNCTION_SELECT_INTERFACE;
454 urb.UmUrbSelectInterface.Hdr.Length = sizeof(_UMURB_SELECT_INTERFACE);
455
456 urb.UmUrbSelectInterface.AlternateSetting = SettingIndex;
457
458 status = m_UsbDevice->SendSyncUmUrb(&urb, 2);
459
460 if (NT_SUCCESS(status)) {
461 RtlZeroMemory(&urb, sizeof(UMURB));
462
463 urb.UmUrbInterfaceInformation.Hdr.InterfaceHandle = m_WinUsbHandle;
464 urb.UmUrbInterfaceInformation.Hdr.Function = UMURB_FUNCTION_GET_DESCRIPTOR_FROM_INTERFACE;
465 urb.UmUrbInterfaceInformation.Hdr.Length = sizeof(_UMURB_INTERFACE_INFORMATION);
466
467 urb.UmUrbInterfaceInformation.AlternateSetting = SettingIndex;
468
469 status = m_UsbDevice->SendSyncUmUrb(&urb, 2);
470
471 if (NT_SUCCESS(status)) {
472 interfaceDesc = &urb.UmUrbInterfaceInformation.UsbInterfaceDescriptor;
473
474 m_Settings[SettingIndex].InterfaceDescriptorAlloc = *interfaceDesc;
475
477
479 }
480 }
481#endif
482
483 return status;
484}
NTSTATUS MakeAndConfigurePipes(__in PWDF_OBJECT_ATTRIBUTES PipesAttributes, __in UCHAR NumPipes)
uint32_t entry
Definition: isohybrid.c:63
#define UMURB_FUNCTION_SELECT_INTERFACE
Definition: umusb.h:9
#define UMURB_FUNCTION_GET_DESCRIPTOR_FROM_INTERFACE
Definition: umusb.h:40

Referenced by CheckAndSelectSettingByIndex(), and switch().

◆ SetConfiguredPipes()

VOID FxUsbInterface::SetConfiguredPipes ( __in FxUsbPipe **  ppPipes)
inline

Definition at line 131 of file fxusbinterface.hpp.

134 {
135 m_ConfiguredPipes = ppPipes;
136 }

Referenced by MakeAndConfigurePipes(), FxUsbDevice::SelectConfig(), and SelectSetting().

◆ SetInfo()

VOID FxUsbInterface::SetInfo ( __in PUSBD_INTERFACE_INFORMATION  Interface)

Definition at line 165 of file fxusbinterface.cpp.

181{
182 UCHAR i;
183
184 ASSERT(m_InterfaceNumber == InterfaceInfo->InterfaceNumber);
185
186 m_CurAlternateSetting = InterfaceInfo->AlternateSetting;
187
188 for (i = 0; i < m_NumberOfConfiguredPipes ; i++) {
189 m_ConfiguredPipes[i]->InitPipe(&InterfaceInfo->Pipes[i],
190 InterfaceInfo->InterfaceNumber,
191 this);
192 }
193}

Referenced by FxUsbDevice::SelectConfig(), and SelectSetting().

◆ SetNumConfiguredPipes()

VOID FxUsbInterface::SetNumConfiguredPipes ( __in UCHAR  NumberOfPipes)
inline

Definition at line 123 of file fxusbinterface.hpp.

126 {
127 m_NumberOfConfiguredPipes = NumberOfPipes;
128 }

Referenced by MakeAndConfigurePipes(), FxUsbDevice::SelectConfig(), and SelectSetting().

◆ SetWinUsbHandle()

NTSTATUS FxUsbInterface::SetWinUsbHandle ( _In_ UCHAR  FrameworkInterfaceIndex)

Definition at line 28 of file fxusbinterfaceum.cpp.

31{
33 UMURB urb;
34
35 if (m_InterfaceNumber != FrameworkInterfaceIndex) {
37 "Composite device detected: Converting absolute interface "
38 "index %d to relative interface index %d", m_InterfaceNumber,
39 FrameworkInterfaceIndex);
40 }
41
42 if (FrameworkInterfaceIndex == 0) {
44 }
45 else {
46 RtlZeroMemory(&urb, sizeof(UMURB));
47
51
52 //
53 // If this is using the WinUSB dispatcher, this will ultimately call
54 // WinUsb_GetAssociatedInterface which expects a 0-based index but starts
55 // counting from index 1. To get the handle for interface n, we pass n-1
56 // and WinUSB will return the handle for (n-1)+1.
57 //
58 // The NativeUSB dispatcher ultimately calls WdfUsbTargetDeviceGetInterface.
59 // Unlike WinUSB.sys, this starts counting from index zero. The NativeUSB
60 // dispatcher expects this framework quirk and adjusts accordingly. See
61 // WudfNativeUsbDispatcher.cpp for more information.
62 //
63 // The actual interface number may differ from the interface index in
64 // composite devices. In all cases, the interface index (starting from zero)
65 // must be used.
66 //
67 urb.UmUrbGetAssociatedInterface.InterfaceIndex = FrameworkInterfaceIndex - 1;
68
70
71 if (NT_SUCCESS(status)) {
72 m_WinUsbHandle = urb.UmUrbGetAssociatedInterface.InterfaceHandle;
73 }
74 else {
76 "Failed to retrieve WinUsb interface handle");
78 }
79 }
80
81 return status;
82}
WINUSB_INTERFACE_HANDLE m_WinUsbHandle
#define TRACE_LEVEL_INFORMATION
Definition: storswtr.h:29
struct _UMURB_GET_ASSOCIATED_INTERFACE UmUrbGetAssociatedInterface
Definition: umusb.h:239
#define UMURB_FUNCTION_GET_ASSOCIATED_INTERFACE
Definition: umusb.h:54

◆ UpdatePipeAttributes()

NTSTATUS FxUsbInterface::UpdatePipeAttributes ( __in PWDF_OBJECT_ATTRIBUTES  PipesAttributes)

Definition at line 196 of file fxusbinterfaceum.cpp.

199{
201 UCHAR iPipe;
202 FxUsbPipe** ppPipes;
203 UCHAR numberOfPipes;
204
205 numberOfPipes = m_NumberOfConfiguredPipes;
206 ppPipes = m_ConfiguredPipes;
207
208 for (iPipe = 0; iPipe < numberOfPipes; iPipe++) {
209 status = FxObjectAllocateContext(ppPipes[iPipe],
211 TRUE,
212 NULL);
213 if (!NT_SUCCESS(status)) {
216 "UpdatePipeAttributes failed %!STATUS!", status);
217 break;
218 }
219 }
220
221 //
222 // Pipe attributes are updated as part of select
223 // config and it is ok for the client driver to configure
224 // twice with the same attributes. In a similar scenario,
225 // KMDF will return STATUS_SUCCESS, so we should do the
226 // same for UMDF for consistency
227 //
230 }
231
232 return status;
233}
_Must_inspect_result_ NTSTATUS FxObjectAllocateContext(__in FxObject *Object, __in PWDF_OBJECT_ATTRIBUTES Attributes, __in BOOLEAN AllowCallbacksOnly, __deref_opt_out PVOID *Context)
Definition: handleapi.cpp:397
#define STATUS_OBJECT_NAME_EXISTS
Definition: ntstatus.h:114

Member Data Documentation

◆ FxUsbDevice

friend FxUsbInterface::FxUsbDevice

Definition at line 34 of file fxusbinterface.hpp.

◆ FxUsbPipe

friend FxUsbInterface::FxUsbPipe

Definition at line 35 of file fxusbinterface.hpp.

Referenced by MakeAndConfigurePipes(), and SelectSetting().

◆ m_Class

UCHAR FxUsbInterface::m_Class
protected

Definition at line 255 of file fxusbinterface.hpp.

Referenced by CreateSettings(), and FxUsbInterface().

◆ m_ConfiguredPipes

◆ m_CurAlternateSetting

UCHAR FxUsbInterface::m_CurAlternateSetting
protected

◆ m_InterfaceNumber

◆ m_NumberOfConfiguredPipes

◆ m_NumSettings

UCHAR FxUsbInterface::m_NumSettings
protected

◆ m_Protocol

UCHAR FxUsbInterface::m_Protocol
protected

Definition at line 257 of file fxusbinterface.hpp.

Referenced by CreateSettings(), and FxUsbInterface().

◆ m_SubClass

UCHAR FxUsbInterface::m_SubClass
protected

Definition at line 256 of file fxusbinterface.hpp.

Referenced by CreateSettings(), and FxUsbInterface().

◆ m_UsbDevice

◆ m_WinUsbHandle

WINUSB_INTERFACE_HANDLE FxUsbInterface::m_WinUsbHandle
private

The documentation for this class was generated from the following files: