ReactOS 0.4.16-dev-1946-g52006dd
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 29 of file fxusbinterface.cpp.

33 :
34 FxNonPagedObject(FX_TYPE_USB_INTERFACE ,sizeof(FxUsbInterface), FxDriverGlobals),
36{
37 m_UsbDevice->ADDREF(this);
38
39 m_InterfaceNumber = InterfaceDescriptor->bInterfaceNumber;
40 m_Protocol = InterfaceDescriptor->bInterfaceProtocol;
41 m_Class = InterfaceDescriptor->bInterfaceClass;
42 m_SubClass = InterfaceDescriptor->bInterfaceSubClass;
43
45 m_NumSettings = 0;
48 m_Settings = NULL;
49
51}
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 53 of file fxusbinterface.cpp.

54{
55 ULONG i;
56
58
59 for (i = 0; i < m_NumberOfConfiguredPipes; i++) {
61 }
62
63 if (m_ConfiguredPipes != NULL) {
66 }
67
69
70 if (m_Settings != NULL) {
71 FxPoolFree(m_Settings);
72 m_Settings = NULL;
73 }
74
75 //
76 // Release the reference taken in the constructor
77 //
78 m_UsbDevice->RELEASE(this);
79}
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 557 of file fxusbinterface.cpp.

573{
577 }
578 else {
579 return STATUS_SUCCESS;
580 }
581}
_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 82 of file fxusbinterface.cpp.

101{
102 FxUsbPipe** pPipes;
103 ULONG numPipes;
104 KIRQL irql;
105 ULONG i;
106
107 //
108 // Capture the values, clear them out of the object and then clean them up
109 // outside of the lock.
110 //
111 m_UsbDevice->Lock(&irql);
112
113 pPipes = m_ConfiguredPipes;
114 numPipes = m_NumberOfConfiguredPipes;
115
118
120
121 if (pPipes != NULL) {
122 for (i = 0; i < numPipes; i++) {
123 if (pPipes[i] != NULL) {
124 if (Failure) {
125 //
126 // FxIoTarget::Remove will be called in FxIoTarget::Dispose()
127 //
128 pPipes[i]->DeleteFromFailedCreate();
129 }
130 else {
131 pPipes[i]->DeleteObject();
132 }
133 }
134 else {
135 //
136 // No more pointers to delete, break out of the loop
137 //
138 break;
139 }
140 }
141
142 FxPoolFree(pPipes);
143 pPipes = NULL;
144 }
145}
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 977 of file fxusbinterface.cpp.

998{
999 PipeInfo->MaximumPacketSize = EndpointDesc->wMaxPacketSize;
1000 PipeInfo->EndpointAddress = EndpointDesc->bEndpointAddress;
1001 PipeInfo->Interval = EndpointDesc->bInterval;
1002
1003 //
1004 // Extract the lower 2 bits which contain the EP type
1005 //
1007 (USBD_PIPE_TYPE) (EndpointDesc->bmAttributes & 0x03)
1008 );
1009
1010 //
1011 // Filling in a default value since the EndpointDescriptor doesn't contain it
1012 //
1013 if (PipeInfo->PipeType == WdfUsbPipeTypeControl) {
1014 PipeInfo->MaximumTransferSize = FxUsbPipeControlMaxTransferSize;
1015 }
1016 else {
1017 PipeInfo->MaximumTransferSize = DetermineDefaultMaxTransferSize();
1018 }
1019
1020 PipeInfo->SettingIndex = SettingIndex;
1021}
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 199 of file fxusbinterface.cpp.

216{
217 PUSB_INTERFACE_DESCRIPTOR pDescriptor;
218 ULONG size;
219 UCHAR i;
220
221 //
222 // No need to validate the size of the interface descriptor since FxUsbDevice::CreateInterfaces
223 // has already done so
224 //
230 );
231
232 //
233 // Calculate the number of settings for this interface
234 //
235 while (pDescriptor != NULL) {
236 if (m_InterfaceNumber == pDescriptor->bInterfaceNumber) {
238 }
242 WDF_PTR_ADD_OFFSET(pDescriptor, pDescriptor->bLength),
244 );
245 }
247 m_Settings = (FxUsbInterfaceSetting *) FxPoolAllocate(
249
250 if (m_Settings == NULL) {
253 "Could not allocate memory for %d settings for bInterfaceNumber %d "
254 "(Protocol %d, Class %d, SubClass %d), %!STATUS!",
257
259 }
260
261 RtlZeroMemory(m_Settings, size);
262
263 //
264 // Add all the settings for this interface
265 //
271 );
272
273 while (pDescriptor != NULL) {
274 if (m_InterfaceNumber == pDescriptor->bInterfaceNumber) {
275 if (pDescriptor->bAlternateSetting < m_NumSettings) {
276 m_Settings[pDescriptor->bAlternateSetting].InterfaceDescriptor = pDescriptor;
277 }
278 else {
281 "Interface Number %d does not have contiguous alternate settings,"
282 "expected %d settings, found alt setting %d, %!STATUS!",
283 pDescriptor->bInterfaceNumber, m_NumSettings,
285
287 }
288 }
289
293 WDF_PTR_ADD_OFFSET(pDescriptor, pDescriptor->bLength),
295 );
296 }
297
298 for (i = 0; i < m_NumSettings; i++) {
299
300 if (m_Settings[i].InterfaceDescriptor == NULL) {
303 "Interface Number %d does not have contiguous alternate settings,"
304 "expected consecutive %d settings, but alt setting %d missing "
305 "%!STATUS!", m_InterfaceNumber, m_NumSettings, i,
307
309 }
310
311 //
312 // Only validate the endpoints if the interface reports it has some. We don't
313 // want to validate EP descriptors that may be after the interface descriptor
314 // that are never used because bNumEndpoints doesn't indicate they are present.
315 //
316 if (m_Settings[i].InterfaceDescriptor->bNumEndpoints > 0) {
317 PVOID pRelativeEnd;
319
320 //
321 // Validate that each endpoint descriptor is the correct size for this alt setting.
322 // We will use the next inteface descriptor as the end, and if this is the last
323 // interface descriptor, use the end of the config descriptor as our end.
324 //
325 pRelativeEnd = FxUsbFindDescriptorType(
328 m_Settings[i].InterfaceDescriptor,
330 );
331
332 if (pRelativeEnd == NULL) {
333 //
334 // This is the last alt setting in the config descriptor, use the end of the
335 // config descriptor as our end
336 //
339 }
340
341 //
342 // Limit the number of endpoints validated to bNumEndpoints. In theory
343 // there could be EP descriptors after N EP descriptors that are never
344 // used, thus we don't want to risk valdiating them and failing them
345 // (ie an app compat concern, in a perfect world we would validate them)
346 //
350 m_Settings[i].InterfaceDescriptor,
351 pRelativeEnd,
355 m_Settings[i].InterfaceDescriptor->bNumEndpoints
356 );
357
358 if (!NT_SUCCESS(status)) {
361 "Interface Number %d does not have a valid endpoint descriptor,"
362 "%!STATUS!", m_InterfaceNumber, status);
363
364 return status;
365 }
366 }
367 }
368
369 return STATUS_SUCCESS;
370}
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:33
#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:176
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:209
@ 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 952 of file fxusbinterface.cpp.

967{
970 }
971 else {
973 }
974}
@ 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 786 of file fxusbinterface.cpp.

812{
813 ULONG defaultMaxTransferSize;
814 USHORT size;
815 UCHAR i;
816
818
820
821 //
822 // Setup the URB, format the request, and send it
823 //
825 size,
828 SettingNumber);
829
830 defaultMaxTransferSize = m_UsbDevice->GetDefaultMaxTransferSize();
831
832 Urb->UrbSelectInterface.Interface.Length =
833 GET_USBD_INTERFACE_SIZE(NumEndpoints);
834
835 Urb->UrbSelectInterface.Interface.NumberOfPipes = NumEndpoints;
836
837 for (i = 0; i < NumEndpoints; i++) {
838
839 //
840 // Make sure that the Interface Length conveys the exact number of EP's
841 //
842 ASSERT(
843 &Urb->UrbSelectInterface.Interface.Pipes[i] <
844 WDF_PTR_ADD_OFFSET(&Urb->UrbSelectInterface.Interface,
845 Urb->UrbSelectInterface.Interface.Length)
846 );
847
848 Urb->UrbSelectInterface.Interface.Pipes[i].PipeFlags = 0x0;
849 Urb->UrbSelectInterface.Interface.Pipes[i].MaximumTransferSize =
850 defaultMaxTransferSize;
851 }
852}
ULONG GetDefaultMaxTransferSize(VOID)
USBD_CONFIGURATION_HANDLE m_ConfigHandle
unsigned short USHORT
Definition: pedump.c:61
PINTERFACE Interface
Definition: iotypes.h:3250
#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
_In_ PIO_STACK_LOCATION _In_ PURB Urb
Definition: usbdlib.h:267

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

◆ GetConfiguredPipe()

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

Definition at line 1024 of file fxusbinterface.cpp.

1042{
1044 return NULL;
1045 }
1046 else {
1047 if (PipeInfo != NULL) {
1049 }
1050
1052 }
1053}
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 1087 of file fxusbinterface.cpp.

1103{
1104 if (IsInterfaceConfigured()) {
1105 return m_CurAlternateSetting;
1106 }
1107 else {
1110 "WDFUSBINTERFACE %p not configured, cannot retrieve configured "
1111 "setting index", GetHandle());
1112
1114
1115 return 0;
1116 }
1117}
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 1056 of file fxusbinterface.cpp.

1074{
1075 if (SettingIndex >= m_NumSettings) {
1076 RtlZeroMemory(UsbInterfaceDescriptor,
1077 sizeof(*UsbInterfaceDescriptor));
1078 }
1079 else {
1080 RtlCopyMemory(UsbInterfaceDescriptor,
1082 sizeof(*UsbInterfaceDescriptor));
1083 }
1084}
#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 855 of file fxusbinterface.cpp.

878{
879 PUCHAR pEnd, pCur;
880 PUSB_INTERFACE_DESCRIPTOR pInterfaceDesc;
881 PUSB_ENDPOINT_DESCRIPTOR pEndpointDesc;
882 UCHAR curEndpointIndex;
883 BOOLEAN endPointFound;
884
885 pInterfaceDesc = NULL;
886 curEndpointIndex = 0;
887 endPointFound = FALSE;
888 UNREFERENCED_PARAMETER(endPointFound);
889
890 //
891 // Extract the interface descriptor for the alternate setting for the interface
892 //
893 pInterfaceDesc = GetSettingDescriptor(SettingIndex);
894
895 if (pInterfaceDesc == NULL) {
896 return;
897 }
898
899 pEnd = (PUCHAR) WDF_PTR_ADD_OFFSET(
902 );
903
904 //
905 // Start from the descriptor after current one
906 //
907 pCur = (PUCHAR) WDF_PTR_ADD_OFFSET(pInterfaceDesc, pInterfaceDesc->bLength);
908
909 //
910 // Iterate through the list of EP descriptors following the interface descriptor
911 // we just found and get the endpoint descriptor which matches the endpoint
912 // index or we hit another interface descriptor
913 //
914 // We have already validated that the descriptor headers are well formed and within
915 // the config descriptor bounds
916 //
917 while (pCur < pEnd) {
919
920 //
921 // If we hit the next interface no way we can find the EndPoint
922 //
924 break;
925 }
926
927 if (pCommonDesc->bDescriptorType == USB_ENDPOINT_DESCRIPTOR_TYPE) {
928 //
929 // Size of pEndpointDesc has been validated by CreateSettings() and
930 // is within the config descriptor
931 //
932 pEndpointDesc = (PUSB_ENDPOINT_DESCRIPTOR) pCommonDesc;
933
934 if (EndpointIndex == curEndpointIndex) {
936 pEndpointDesc,
938 break;
939 }
940
941 curEndpointIndex++;
942 }
943
944 //
945 // Advance past this descriptor
946 //
947 pCur += pCommonDesc->bLength;
948 }
949}
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
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:329
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 1120 of file fxusbinterface.cpp.

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

◆ 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 1145 of file fxusbinterface.cpp.

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

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:1075
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 148 of file fxusbinterface.cpp.

151{
152 ULONG i;
153
154 if (m_ConfiguredPipes == NULL) {
155 return;
156 }
157
158 for (i = 0; i < m_NumberOfConfiguredPipes; i++) {
159 if (m_ConfiguredPipes[i] == Pipe) {
161 return;
162 }
163 }
164}
_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 585 of file fxusbinterface.cpp.

607{
608 FxSyncRequest request(GetDriverGlobals(), NULL);
609 LIST_ENTRY pendHead;
610 FxUsbPipe* pPipe;
612 UCHAR iPipe, numPipes;
614 FxUsbPipe ** ppPipes;
615 ULONG size;
616
617 //
618 // FxSyncRequest always succeesds for KM but can fail for UM.
619 //
620 status = request.Initialize();
621 if (!NT_SUCCESS(status)) {
623 "Failed to initialize FxSyncRequest");
624 return status;
625 }
626
627 //
628 // Subtract the size of the embedded pipe.
629 //
630 const ULONG interfaceStructSize = sizeof(Urb->UrbSelectInterface.Interface) -
631 sizeof(USBD_PIPE_INFORMATION);
632
633 //
634 // This check will happen twice for SelectSettingByInterface/Descriptor.
635 //
636 // We could just do it here, but the above two functions will unnecessarily
637 // have to build an URB.
638 //
639 if (IsInterfaceConfigured() &&
641 Urb->UrbSelectInterface.Interface.AlternateSetting) {
642 //
643 // don't do anything
644 //
645 return STATUS_SUCCESS;
646 }
647
648 InitializeListHead(&pendHead);
649 numPipes = 0;
650 ppPipes = NULL;
651
652 if (Urb->UrbSelectInterface.Hdr.Length < interfaceStructSize) {
656 "Urb header length 0x%x is less than expected 0x%x"
657 "%!STATUS!", Urb->UrbSelectInterface.Hdr.Length, interfaceStructSize,status
658 );
659 return status;
660 }
661
662 status = request.m_TrueRequest->ValidateTarget(m_UsbDevice);
663 if (!NT_SUCCESS(status)) {
664 goto Done;
665 }
666
667 //
668 // Urb->UrbSelectInterface.Interface.NumberOfPipes is set when the URB
669 // completes. So, we must compute the number of pipes being requested based
670 // on the size of the structure and its Length (as set by the caller).
671 // To calculate the number of pipes we need to account for the
672 // embedded pipe in the structure.
673 //
674 numPipes = (UCHAR) ((Urb->UrbSelectInterface.Interface.Length -
675 interfaceStructSize) /
677 );
678
679 if (numPipes > 0) {
680 size = numPipes * sizeof(FxUsbPipe *);
681 }
682 else {
683 //
684 // It is valid to have an interface with zero pipes in it. In that
685 // case, we just allocate one entry so that we have a valid array
686 // and keep the remaining code simple.
687 //
688 size = sizeof(FxUsbPipe*);
689 }
690
691 //
692 // If the interface is already configured don't do anything with the old
693 // settings till we allocate new.
694 //
695 ppPipes = (FxUsbPipe **) FxPoolAllocate(GetDriverGlobals(), NonPagedPool, size);
696
697 if (ppPipes == NULL) {
701 "Unable to allocate memory %!STATUS!"
702 , status);
703 goto Done;
704 }
705
706 RtlZeroMemory(ppPipes, size);
707
708 for (iPipe = 0; iPipe < numPipes; iPipe++) {
709 ppPipes[iPipe] = new (GetDriverGlobals(), PipesAttributes)
711
712 if (ppPipes[iPipe] == NULL) {
716 "Unable to allocate memory for the pipes %!STATUS!", status);
717 goto Done;
718 }
719
720 pPipe = ppPipes[iPipe];
721
722 status = pPipe->Init(m_UsbDevice->m_Device);
723 if (!NT_SUCCESS(status)) {
726 "Init pipe failed %!STATUS!", status);
727 goto Done;
728 }
729
730 status = pPipe->Commit(PipesAttributes, NULL, this);
731
732 if (!NT_SUCCESS(status)) {
735 "Commit pipe failed %!STATUS!", status);
736 goto Done;
737 }
738 }
739
740 if (IsInterfaceConfigured()) {
741 //
742 // Delete the old pipes
743 //
745 }
746
747
750
752
754 status = m_UsbDevice->SubmitSync(request.m_TrueRequest, &options, NULL);
755
756 //
757 // If select interface URB fails we are at the point of no return and we
758 // will end up with no configured pipes.
759 //
760 if (NT_SUCCESS(status)) {
761 SetNumConfiguredPipes(numPipes);
762 SetConfiguredPipes(ppPipes);
763 SetInfo(&Urb->UrbSelectInterface.Interface);
764 }
765
766Done:
767 if (!NT_SUCCESS(status)) {
768 if (ppPipes != NULL) {
769 ASSERT(ppPipes != m_ConfiguredPipes);
770
771 for (iPipe = 0; iPipe < numPipes; iPipe++) {
772 if (ppPipes[iPipe] != NULL) {
773 ppPipes[iPipe]->DeleteFromFailedCreate();
774 }
775 }
776
777 FxPoolFree(ppPipes);
778 ppPipes = NULL;
779 }
780 }
781
782 return status;
783}
_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:31
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 490 of file fxusbinterface.cpp.

506{
507 PURB urb;
509 USHORT size;
510
511 if (IsInterfaceConfigured() &&
512 (m_CurAlternateSetting == InterfaceDescriptor->bAlternateSetting)) {
513 //
514 // Don't do anything
515 //
516 return STATUS_SUCCESS;
517 }
518
519 if (InterfaceDescriptor->bInterfaceNumber != m_InterfaceNumber) {
521
524 "WDFUSBINTERFACE %p has interface num %d, select setting by "
525 "descriptor specified interface num %d, %!STATUS!",
527 InterfaceDescriptor->bInterfaceNumber, status
528 );
529
530 return status;
531 }
532
534
535 urb = (PURB) FxPoolAllocate(GetDriverGlobals(), NonPagedPool, size);
536
537 if (urb == NULL) {
539 }
540 else {
542 urb,
543 InterfaceDescriptor->bNumEndpoints,
544 InterfaceDescriptor->bAlternateSetting
545 );
546
548
549 FxPoolFree(urb);
550 }
551
552 return status;
553}
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 374 of file fxusbinterface.cpp.

392{
393#if (FX_CORE_MODE == FX_CORE_KERNEL_MODE)
394 PURB urb;
395#elif (FX_CORE_MODE == FX_CORE_USER_MODE)
396 UMURB urb;
397 PUSB_INTERFACE_DESCRIPTOR interfaceDesc;
398#endif
400 UCHAR numEP;
402 USHORT size;
403
405
406 //
407 // We should have at least 1 setting on the interface
408 //
409 ASSERT(m_NumSettings != 0);
410
411 //
412 // If m_NumberOfConfiguredPipes == 0 then it also tells us that
413 // the interface wasn't configured. So it can keep track of configuredness
414 // of the interface. Could there be a case when the selected setting has 0
415 // EP's. Due to the above case we use m_InterfaceConfigured.
416 //
418 return STATUS_SUCCESS;
419 }
420
421 //
422 // Check for an invalid alternate setting
423 //
426 }
427
428 RtlCopyMemory(&entry, &m_Settings[SettingIndex], sizeof(entry));
429
430 //
431 // Create the configured pipes
432 //
433 numEP = entry.InterfaceDescriptor->bNumEndpoints;
434
436
437#if (FX_CORE_MODE == FX_CORE_KERNEL_MODE)
438 urb = (PURB) FxPoolAllocate(GetDriverGlobals(), NonPagedPool, size);
439
440 if (urb == NULL) {
442 }
443 else {
445
447
448 FxPoolFree(urb);
449 urb = NULL;
450 }
451#elif (FX_CORE_MODE == FX_CORE_USER_MODE)
452 RtlZeroMemory(&urb, sizeof(UMURB));
453
454 urb.UmUrbSelectInterface.Hdr.InterfaceHandle = m_WinUsbHandle;
455 urb.UmUrbSelectInterface.Hdr.Function = UMURB_FUNCTION_SELECT_INTERFACE;
456 urb.UmUrbSelectInterface.Hdr.Length = sizeof(_UMURB_SELECT_INTERFACE);
457
458 urb.UmUrbSelectInterface.AlternateSetting = SettingIndex;
459
460 status = m_UsbDevice->SendSyncUmUrb(&urb, 2);
461
462 if (NT_SUCCESS(status)) {
463 RtlZeroMemory(&urb, sizeof(UMURB));
464
465 urb.UmUrbInterfaceInformation.Hdr.InterfaceHandle = m_WinUsbHandle;
466 urb.UmUrbInterfaceInformation.Hdr.Function = UMURB_FUNCTION_GET_DESCRIPTOR_FROM_INTERFACE;
467 urb.UmUrbInterfaceInformation.Hdr.Length = sizeof(_UMURB_INTERFACE_INFORMATION);
468
469 urb.UmUrbInterfaceInformation.AlternateSetting = SettingIndex;
470
471 status = m_UsbDevice->SendSyncUmUrb(&urb, 2);
472
473 if (NT_SUCCESS(status)) {
474 interfaceDesc = &urb.UmUrbInterfaceInformation.UsbInterfaceDescriptor;
475
476 m_Settings[SettingIndex].InterfaceDescriptorAlloc = *interfaceDesc;
477
479
481 }
482 }
483#endif
484
485 return status;
486}
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 167 of file fxusbinterface.cpp.

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

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:189

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: