ReactOS 0.4.16-dev-338-g34e76ad
FxUsbDevice Class Reference

#include <fxusbdevice.hpp>

Inheritance diagram for FxUsbDevice:
Collaboration diagram for FxUsbDevice:

Public Member Functions

 FxUsbDevice (__in PFX_DRIVER_GLOBALS FxDriverGlobals)
 
_Must_inspect_result_ NTSTATUS InitDevice (__in ULONG USBDClientContractVersionForWdfClient)
 
_Must_inspect_result_ NTSTATUS GetConfigDescriptor (__out PVOID ConfigDescriptor, __inout PUSHORT ConfigDescriptorLength)
 
_Must_inspect_result_ NTSTATUS GetString (__in_ecount(*NumCharacters) PUSHORT String, __in PUSHORT NumCharacters, __in UCHAR StringIndex, __in_opt USHORT LangID, __in_opt WDFREQUEST Request=NULL, __in_opt PWDF_REQUEST_SEND_OPTIONS Options=NULL)
 
__inline VOID CopyDeviceDescriptor (__out PUSB_DEVICE_DESCRIPTOR UsbDeviceDescriptor)
 
VOID GetInformation (__out PWDF_USB_DEVICE_INFORMATION Information)
 
__inline USBD_CONFIGURATION_HANDLE GetConfigHandle (VOID)
 
_Must_inspect_result_ __inline NTSTATUS GetCurrentFrameNumber (__in PULONG Current)
 
_Must_inspect_result_ NTSTATUS SelectConfigAuto (__in PWDF_OBJECT_ATTRIBUTES PipeAttributes)
 
_Must_inspect_result_ NTSTATUS SelectConfigInterfaces (__in PWDF_OBJECT_ATTRIBUTES PipesAttributes, __in PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor, __in_ecount(NumInterfaces) PUSB_INTERFACE_DESCRIPTOR *InterfaceDescriptors, __in ULONG NumInterfaces)
 
_Must_inspect_result_ NTSTATUS SelectConfig (__in PWDF_OBJECT_ATTRIBUTES PipesAttributes, __in PURB Urb, __in FX_URB_TYPE FxUrbType, __out_opt PUCHAR NumConfiguredInterfaces)
 
_Must_inspect_result_ NTSTATUS Deconfig (VOID)
 
_Must_inspect_result_ NTSTATUS SelectInterfaceByInterface (__in PWDF_OBJECT_ATTRIBUTES PipesAttributes, __in PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor)
 
_Must_inspect_result_ NTSTATUS SelectInterface (__in PWDF_OBJECT_ATTRIBUTES PipesAttributes, __in PURB Urb)
 
UCHAR GetNumInterfaces (VOID)
 
UCHAR GetInterfaceNumEndpoints (__in UCHAR InterfaceNumber)
 
WDFUSBPIPE GetInterfacePipeReferenced (__in UCHAR InterfaceNumber, __in UCHAR EndpointNumber)
 
_Must_inspect_result_ NTSTATUS FormatStringRequest (__in FxRequestBase *Request, __in FxRequestBuffer *RequestBuffer, __in UCHAR StringIndex, __in USHORT LangID)
 
_Must_inspect_result_ NTSTATUS FormatControlRequest (__in FxRequestBase *Request, __in PWDF_USB_CONTROL_SETUP_PACKET Packet, __in FxRequestBuffer *RequestBuffer)
 
_Must_inspect_result_ NTSTATUS IsConnected (VOID)
 
_Must_inspect_result_ NTSTATUS Reset (VOID)
 
_Must_inspect_result_ NTSTATUS CyclePort (VOID)
 
_Must_inspect_result_ NTSTATUS FormatCycleRequest (__in FxRequestBase *Request)
 
BOOLEAN OnUSBD (VOID)
 
USBD_PIPE_HANDLE GetControlPipeHandle (VOID)
 
_Must_inspect_result_ NTSTATUS CreateInterfaces (VOID)
 
_Must_inspect_result_ NTSTATUS SelectConfigSingle (__in PWDF_OBJECT_ATTRIBUTES PipeAttributes, __in PWDF_USB_DEVICE_SELECT_CONFIG_PARAMS Params)
 
_Must_inspect_result_ NTSTATUS SelectConfigMulti (__in PWDF_OBJECT_ATTRIBUTES PipeAttributes, __in PWDF_USB_DEVICE_SELECT_CONFIG_PARAMS Params)
 
_Must_inspect_result_ NTSTATUS SelectConfigDescriptor (__in PWDF_OBJECT_ATTRIBUTES PipeAttributes, __in PWDF_USB_DEVICE_SELECT_CONFIG_PARAMS Params)
 
FxUsbInterfaceGetInterfaceFromIndex (__in UCHAR InterfaceIndex)
 
BOOLEAN HasMismatchedInterfacesInConfigDescriptor (VOID)
 
VOID CancelSentIo (VOID)
 
BOOLEAN IsEnabled (VOID)
 
_Must_inspect_result_ NTSTATUS QueryUsbCapability (__in CONST GUID *CapabilityType, __in ULONG CapabilityBufferLength, __drv_when(CapabilityBufferLength==0, __out_opt) __drv_when(CapabilityBufferLength !=0 &&ResultLength==NULL, __out_bcount(CapabilityBufferLength)) __drv_when(CapabilityBufferLength !=0 &&ResultLength !=NULL, __out_bcount_part_opt(CapabilityBufferLength, *ResultLength)) PVOID CapabilityBuffer, __out_opt __drv_when(ResultLength !=NULL, __deref_out_range(<=, CapabilityBufferLength)) PULONG ResultLength)
 
__checkReturn NTSTATUS CreateUrb (__in_opt PWDF_OBJECT_ATTRIBUTES Attributes, __out WDFMEMORY *UrbMemory, __deref_opt_out_bcount(sizeof(URB)) PURB *Urb)
 
__checkReturn NTSTATUS CreateIsochUrb (__in_opt PWDF_OBJECT_ATTRIBUTES Attributes, __in ULONG NumberOfIsochPackets, __out WDFMEMORY *UrbMemory, __deref_opt_out_bcount(GET_ISOCH_URB_SIZE(NumberOfIsochPackets)) PURB *Urb)
 
USBD_HANDLE GetUSBDHandle (VOID)
 
FX_URB_TYPE GetUrbType (VOID)
 
FX_URB_TYPE GetFxUrbTypeForRequest (__in FxRequestBase *Request)
 
BOOLEAN IsObjectDisposedOnRemove (__in FxObject *Object)
 
- Public Member Functions inherited from FxIoTarget
 FxIoTarget (__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in USHORT ObjectSize)
 
 FxIoTarget (__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in USHORT ObjectSize, __in WDFTYPE WdfType)
 
virtual _Must_inspect_result_ NTSTATUS Start (VOID)
 
virtual VOID Stop (__in WDF_IO_TARGET_SENT_IO_ACTION Action)
 
virtual VOID Purge (__in WDF_IO_TARGET_PURGE_IO_ACTION Action)
 
virtual VOID Remove (VOID)
 
NTSTATUS _Must_inspect_result_ QueryInterface (__inout FxQueryInterfaceParams *Params)
 
__inline WDF_IO_TARGET_STATE GetState (VOID)
 
__inline MdDeviceObject GetTargetDevice (VOID)
 
__inline MdDeviceObject GetTargetPDO (VOID)
 
__inline MdFileObject GetTargetFileObject (VOID)
 
__inline WDFDEVICE GetDeviceHandle (VOID)
 
WDFIOTARGET GetHandle (VOID)
 
__inline FxDriverGetDriver (VOID)
 
virtual _Must_inspect_result_ MdDeviceObject GetTargetDeviceObject (_In_ CfxDeviceBase *Device)
 
_Must_inspect_result_ NTSTATUS Init (__in CfxDeviceBase *Device)
 
ULONG Submit (__in FxRequestBase *Request, __in_opt PWDF_REQUEST_SEND_OPTIONS Options, __in_opt ULONG Flags)
 
 FX_DECLARE_VF_FUNCTION_P1 (NTSTATUS, VerifySubmitLocked, _In_ FxRequestBase *)
 
ULONG SubmitLocked (__in FxRequestBase *Request, __in_opt PWDF_REQUEST_SEND_OPTIONS Options, __in ULONG Flags)
 
_Must_inspect_result_ NTSTATUS SubmitSync (__in FxRequestBase *Request, __in_opt PWDF_REQUEST_SEND_OPTIONS Options=NULL, __out_opt PULONG Action=NULL)
 
VOID TimerCallback (__in FxRequestBase *Request)
 
VOID CompleteCanceledRequest (__in FxRequestBase *Request)
 
VOID SubmitPendedRequest (__in FxRequestBase *Request)
 
VOID CompletePendedRequest (__in FxRequestBase *Request)
 
BOOLEAN __inline HasEnoughStackLocations (__in FxIrp *Irp)
 
_Must_inspect_result_ NTSTATUS FormatIoRequest (__inout FxRequestBase *Request, __in UCHAR MajorCode, __in FxRequestBuffer *IoBuffer, __in_opt PLONGLONG StartingOffset, __in_opt FxFileObject *FileObject=NULL)
 
_Must_inspect_result_ NTSTATUS FormatIoctlRequest (__in FxRequestBase *Request, __in ULONG Ioctl, __in BOOLEAN Internal, __in FxRequestBuffer *InputBuffer, __in FxRequestBuffer *OutputBuffer, __in_opt FxFileObject *FileObject=NULL)
 
_Must_inspect_result_ NTSTATUS FormatInternalIoctlOthersRequest (__in FxRequestBase *Request, __in ULONG Ioctl, __in FxRequestBuffer *Buffers)
 
VOID CancelSentIo (VOID)
 
_Must_inspect_result_ NTSTATUS SubmitSyncRequestIgnoreTargetState (__in FxRequestBase *Request, __in_opt PWDF_REQUEST_SEND_OPTIONS RequestOptions)
 
VOID UpdateTargetIoType (VOID)
 
BOOLEAN HasValidStackSize (VOID)
 
virtual VOID Send (_In_ MdIrp Irp)
 
- 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 FxUsbPipe
 
friend FxUsbInterface
 
- Public Attributes inherited from FxIoTarget
FxTransactionedEntry m_TransactionedEntry
 
BOOLEAN m_InStack
 
BOOLEAN m_AddedToDeviceList
 

Protected Member Functions

 ~FxUsbDevice (VOID)
 
VOID RemoveDeletedInterface (__in FxUsbInterface *Interface)
 
virtual _Must_inspect_result_ NTSTATUS Start (VOID)
 
virtual VOID Stop (__in WDF_IO_TARGET_SENT_IO_ACTION Action)
 
virtual VOID Purge (__in WDF_IO_TARGET_PURGE_IO_ACTION Action)
 
VOID PipesGotoRemoveState (__in BOOLEAN ForceRemovePipes)
 
FxUsbInterfaceGetInterfaceFromNumber (__in UCHAR InterfaceNumber)
 
_Must_inspect_result_ NTSTATUS GetInterfaceNumberFromInterface (__in WDFUSBINTERFACE UsbInterface, __out PUCHAR InterfaceNumber)
 
VOID CleanupInterfacePipesAndDelete (__in FxUsbInterface *UsbInterface)
 
 _Acquires_lock_ (_Global_critical_region_) VOID AcquireInterfaceIterationLock(VOID)
 
 _Releases_lock_ (_Global_critical_region_) VOID ReleaseInterfaceIterationLock(VOID)
 
ULONG GetDefaultMaxTransferSize (VOID)
 
VOID FormatInterfaceSelectSettingUrb (__in PURB Urb, __in USHORT NumEndpoints, __in UCHAR InterfaceNumber, __in UCHAR SettingNumber)
 
virtual BOOLEAN Dispose (VOID)
 
_Must_inspect_result_ NTSTATUS GetPortStatus (__out PULONG PortStatus)
 
_Must_inspect_result_ NTSTATUS SendSyncRequest (__in FxSyncRequest *Request, __in ULONGLONG Time)
 
_Must_inspect_result_ NTSTATUS SendSyncUmUrb (__inout PUMURB Urb, __in ULONGLONG Time, __in_opt WDFREQUEST Request=NULL, __in_opt PWDF_REQUEST_SEND_OPTIONS Options=NULL)
 
- Protected Member Functions inherited from FxIoTarget
 ~FxIoTarget ()
 
_Must_inspect_result_ NTSTATUS InitModeSpecific (__in CfxDeviceBase *Device)
 
virtual BOOLEAN Dispose (VOID)
 
VOID FailPendedRequest (__in FxRequestBase *Request, __in NTSTATUS Status)
 
VOID DrainPendedRequestsLocked (__in PLIST_ENTRY RequestListHead, __in BOOLEAN RequestWillBeResent)
 
VOID CompletePendedRequestList (__in PLIST_ENTRY RequestListHead)
 
VOID SubmitPendedRequests (__in PLIST_ENTRY RequestListHeadHead)
 
VOID GetSentRequestsListLocked (__in PSINGLE_LIST_ENTRY RequestListHead, __in PLIST_ENTRY SendList, __out PBOOLEAN AddedToList)
 
virtual _Must_inspect_result_ NTSTATUS GotoStartState (__in PLIST_ENTRY RequestListHead, __in BOOLEAN Lock=TRUE)
 
virtual VOID GotoStopState (__in WDF_IO_TARGET_SENT_IO_ACTION Action, __in PSINGLE_LIST_ENTRY SentRequestListHead, __out PBOOLEAN Wait, __in BOOLEAN LockSelf)
 
virtual VOID GotoPurgeState (__in WDF_IO_TARGET_PURGE_IO_ACTION Action, __in PLIST_ENTRY PendedRequestListHead, __in PSINGLE_LIST_ENTRY SentRequestListHead, __out PBOOLEAN Wait, __in BOOLEAN LockSelf)
 
_Must_inspect_result_ NTSTATUS PendRequestLocked (__in FxRequestBase *Request)
 
__inline VOID CompleteRequest (__in FxRequestBase *Request)
 
VOID HandleFailedResubmit (__in FxRequestBase *Request)
 
VOID RequestCompletionRoutine (__in FxRequestBase *Request)
 
BOOLEAN RemoveCompletedRequestLocked (__in FxRequestBase *Request)
 
virtual VOID ClearTargetPointers (VOID)
 
UCHAR GetTargetIoType (VOID)
 
virtual VOID GotoRemoveState (__in WDF_IO_TARGET_STATE NewState, __in PLIST_ENTRY PendedRequestListHead, __in PSINGLE_LIST_ENTRY SentRequestListHead, __in BOOLEAN Lock, __out PBOOLEAN Wait)
 
virtual VOID WaitForSentIoToComplete (VOID)
 
virtual VOID WaitForDisposeEvent (VOID)
 
virtual VOID Forward (__in MdIrp Irp)
 
__inline VOID CopyFileObjectAndFlags (__in FxRequestBase *Request)
 
__inline VOID IncrementIoCount (VOID)
 
__inline VOID DecrementIoCount (VOID)
 
VOID PrintDisposeMessage (VOID)
 
- 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)
 

Static Protected Member Functions

static VOID _CleanupPipesRequests (__in PLIST_ENTRY PendHead, __in PSINGLE_LIST_ENTRY SentHead)
 
- Static Protected Member Functions inherited from FxIoTarget
static VOID _CancelSentRequests (__in PSINGLE_LIST_ENTRY RequestListHead)
 
static VOID _RequestCancelled (__in FxIrpQueue *Queue, __in MdIrp Irp, __in PMdIoCsqIrpContext pCsqContext, __in KIRQL CallerIrql)
 
- Static Protected Member Functions inherited from FxObject
static PVOID _GetBase (__in FxObject *Object)
 

Protected Attributes

USBD_HANDLE m_USBDHandle
 
USBD_PIPE_HANDLE m_ControlPipe
 
FxUsbInterface ** m_Interfaces
 
USBD_CONFIGURATION_HANDLE m_ConfigHandle
 
USB_DEVICE_DESCRIPTOR m_DeviceDescriptor
 
PUSB_CONFIGURATION_DESCRIPTOR m_ConfigDescriptor
 
USBD_VERSION_INFORMATION m_UsbdVersionInformation
 
PUSB_BUSIFFN_QUERY_BUS_TIME m_QueryBusTime
 
PVOID m_BusInterfaceContext
 
PINTERFACE_DEREFERENCE m_BusInterfaceDereference
 
FxWaitLockInternal m_InterfaceIterationLock
 
ULONG m_HcdPortCapabilities
 
ULONG m_Traits
 
BOOLEAN m_OnUSBD
 
UCHAR m_NumInterfaces
 
BOOLEAN m_MismatchedInterfacesInConfigDescriptor
 
FX_URB_TYPE m_UrbType
 
- Protected Attributes inherited from FxIoTarget
LIST_ENTRY m_SentIoListHead
 
LIST_ENTRY m_IgnoredIoListHead
 
FxCREvent m_SentIoEvent
 
FxCREventm_DisposeEvent
 
FxCREvent m_DisposeEventUm
 
FxIrpQueue m_PendedQueue
 
FxDriverm_Driver
 
MdDeviceObject m_InStackDevice
 
MdDeviceObject m_TargetDevice
 
MdDeviceObject m_TargetPdo
 
MdFileObject m_TargetFileObject
 
WDF_IO_TARGET_STATE m_State
 
LONG m_IoCount
 
CCHAR m_TargetStackSize
 
UCHAR m_TargetIoType
 
BOOLEAN m_WaitingForSentIo
 
BOOLEAN m_Removing
 
- Protected Attributes inherited from FxObject
union {
   CfxDeviceBase *   m_DeviceBase
 
   CfxDevice *   m_Device
 
}; 
 

Private Attributes

IWudfFile * m_pHostTargetFile
 
WINUSB_INTERFACE_HANDLE m_WinUsbHandle
 

Additional Inherited Members

- Static Public Member Functions inherited from FxIoTarget
static VOID _CancelSentRequest (__in FxRequestBase *Request)
 
static FxIoTarget_FromEntry (__in FxTransactionedEntry *Entry)
 
- 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 Public Attributes inherited from FxIoTarget
static const PVOID m_SentRequestTag = (PVOID) 'lcnC'
 
- Static Protected Attributes inherited from FxIoTarget
static MdCompletionRoutineType _RequestCompletionRoutine
 
static EVT_WDF_REQUEST_COMPLETION_ROUTINE _SyncCompletionRoutine
 

Detailed Description

Definition at line 183 of file fxusbdevice.hpp.

Constructor & Destructor Documentation

◆ FxUsbDevice()

FxUsbDevice::FxUsbDevice ( __in PFX_DRIVER_GLOBALS  FxDriverGlobals)

Definition at line 371 of file fxusbdevice.cpp.

373 :
374 FxIoTarget(FxDriverGlobals, sizeof(FxUsbDevice), FX_TYPE_IO_TARGET_USB_DEVICE)
375{
378
379 m_OnUSBD = FALSE;
381 m_NumInterfaces = 0;
382
383 m_Traits = 0;
391
393
396
397#if (FX_CORE_MODE == FX_CORE_USER_MODE)
400#endif
401
403}
VOID MarkDisposeOverride(__in FxObjectLockState State=ObjectLock)
Definition: fxobject.hpp:1101
WINUSB_INTERFACE_HANDLE m_WinUsbHandle
USBD_PIPE_HANDLE m_ControlPipe
USB_DEVICE_DESCRIPTOR m_DeviceDescriptor
PINTERFACE_DEREFERENCE m_BusInterfaceDereference
PUSB_BUSIFFN_QUERY_BUS_TIME m_QueryBusTime
USBD_VERSION_INFORMATION m_UsbdVersionInformation
USBD_HANDLE m_USBDHandle
IWudfFile * m_pHostTargetFile
PUSB_CONFIGURATION_DESCRIPTOR m_ConfigDescriptor
FX_URB_TYPE m_UrbType
UCHAR m_NumInterfaces
ULONG m_HcdPortCapabilities
PVOID m_BusInterfaceContext
FxUsbInterface ** m_Interfaces
BOOLEAN m_OnUSBD
USBD_CONFIGURATION_HANDLE m_ConfigHandle
BOOLEAN m_MismatchedInterfacesInConfigDescriptor
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
@ ObjectDoNotLock
Definition: fxobject.hpp:128
@ FX_TYPE_IO_TARGET_USB_DEVICE
Definition: fxtypes.h:102
@ FxUrbTypeLegacy
Definition: fxusbdevice.hpp:27
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262

◆ ~FxUsbDevice()

FxUsbDevice::~FxUsbDevice ( VOID  )
protected

Definition at line 435 of file fxusbdevice.cpp.

436{
437 UCHAR i;
438
442 }
443
444 if (m_ConfigDescriptor != NULL) {
447 }
448
449 for (i = 0; i < m_NumInterfaces; i++) {
451 }
452
453 if (m_Interfaces != NULL){
456 }
457
458 m_NumInterfaces = 0;
459}
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
unsigned char UCHAR
Definition: xmlstorage.h:181

Member Function Documentation

◆ _Acquires_lock_()

FxUsbDevice::_Acquires_lock_ ( _Global_critical_region_  )
inlineprotected

Definition at line 557 of file fxusbdevice.hpp.

562 {
564 }
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
FxWaitLockInternal m_InterfaceIterationLock

◆ _CleanupPipesRequests()

VOID FxUsbDevice::_CleanupPipesRequests ( __in PLIST_ENTRY  PendHead,
__in PSINGLE_LIST_ENTRY  SentHead 
)
staticprotected

Definition at line 792 of file fxusbdevice.cpp.

796{
797 while (!IsListEmpty(PendHead)) {
800
801 ple = RemoveHeadList(PendHead);
802
804
807 }
808
809 _CancelSentRequests(SentHead);
810}
VOID CompletePendedRequest(__in FxRequestBase *Request)
Definition: fxiotarget.cpp:508
static VOID _CancelSentRequests(__in PSINGLE_LIST_ENTRY RequestListHead)
Definition: fxiotarget.cpp:550
static __inline FxRequestBase * _FromListEntry(__in PLIST_ENTRY Entry)
__inline FxIoTarget * GetTarget(VOID)
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
#define RemoveHeadList(ListHead)
Definition: env_spec_w32.h:964
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
PSINGLE_LIST_ENTRY ple
FxRequest * pRequest
Definition: typedefs.h:120

Referenced by CleanupInterfacePipesAndDelete(), and PipesGotoRemoveState().

◆ _Releases_lock_()

FxUsbDevice::_Releases_lock_ ( _Global_critical_region_  )
inlineprotected

Definition at line 566 of file fxusbdevice.hpp.

571 {
573 }

◆ CancelSentIo()

VOID FxUsbDevice::CancelSentIo ( VOID  )

Definition at line 2095 of file fxusbdevice.cpp.

2098{
2100 ULONG iInterface, iPipe;
2101
2102 for (iInterface = 0; iInterface < m_NumInterfaces; iInterface++) {
2103 pUsbInterface = m_Interfaces[iInterface];
2104
2106 for (iPipe = 0;
2108 iPipe++) {
2109
2110 if (pUsbInterface->m_ConfiguredPipes[iPipe] != NULL) {
2112 }
2113
2114 }
2115 }
2116 }
2117 FxIoTarget::CancelSentIo(); // __super call
2118}
VOID CancelSentIo(VOID)
FxUsbPipe ** m_ConfiguredPipes
UCHAR m_NumberOfConfiguredPipes
FxUsbInterface * pUsbInterface
uint32_t ULONG
Definition: typedefs.h:59

Referenced by CyclePort(), and Reset().

◆ CleanupInterfacePipesAndDelete()

VOID FxUsbDevice::CleanupInterfacePipesAndDelete ( __in FxUsbInterface UsbInterface)
protected

Definition at line 2052 of file fxusbdevice.cpp.

2055{
2056 SINGLE_LIST_ENTRY sentHead;
2057 LIST_ENTRY pendHead;
2058 ULONG iPipe;
2059 FxUsbPipe *pPipe;
2060 KIRQL irql;
2061
2062 sentHead.Next = NULL;
2063 InitializeListHead(&pendHead);
2064
2065 AcquireInterfaceIterationLock();
2066
2067 Lock(&irql);
2068 for (iPipe = 0; iPipe < UsbInterface->m_NumberOfConfiguredPipes; iPipe++) {
2069 BOOLEAN wait;
2070
2071 wait = FALSE;
2072 pPipe = UsbInterface->m_ConfiguredPipes[iPipe];
2073 pPipe->GotoRemoveState(
2075 &pendHead,
2076 &sentHead,
2077 TRUE,
2078 &wait);
2079 }
2080 Unlock(irql);
2081
2082 _CleanupPipesRequests(&pendHead, &sentHead);
2083
2084 for (iPipe = 0; iPipe < UsbInterface->m_NumberOfConfiguredPipes; iPipe++) {
2085 pPipe = UsbInterface->m_ConfiguredPipes[iPipe];
2086 pPipe->WaitForSentIoToComplete();
2087 }
2088
2089 UsbInterface->CleanUpAndDelete(FALSE);
2090
2091 ReleaseInterfaceIterationLock();
2092}
unsigned char BOOLEAN
__drv_restoresIRQL KIRQL __in BOOLEAN Unlock
Definition: fxobject.hpp:1474
static VOID _CleanupPipesRequests(__in PLIST_ENTRY PendHead, __in PSINGLE_LIST_ENTRY SentHead)
virtual VOID GotoRemoveState(__in WDF_IO_TARGET_STATE NewState, __in PLIST_ENTRY PendedRequestListHead, __in PSINGLE_LIST_ENTRY SentRequestListHead, __in BOOLEAN Lock, __out PBOOLEAN Wait)
Definition: fxusbpipe.cpp:1367
virtual VOID WaitForSentIoToComplete(VOID)
Definition: fxusbpipe.cpp:1419
#define TRUE
Definition: types.h:120
KIRQL irql
Definition: wave.h:1
UCHAR KIRQL
Definition: env_spec_w32.h:591
Definition: ntbasedef.h:636
struct _SINGLE_LIST_ENTRY * Next
Definition: ntbasedef.h:637
@ WdfIoTargetDeleted
Definition: wdfiotarget.h:57
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWAITLOCK * Lock
Definition: wdfsync.h:127
_In_ WDFUSBINTERFACE UsbInterface
Definition: wdfusb.h:2276

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

◆ CopyDeviceDescriptor()

__inline VOID FxUsbDevice::CopyDeviceDescriptor ( __out PUSB_DEVICE_DESCRIPTOR  UsbDeviceDescriptor)
inline

Definition at line 218 of file fxusbdevice.hpp.

221 {
224 sizeof(m_DeviceDescriptor));
225 }
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
_In_ WDFUSBDEVICE _Out_ PUSB_DEVICE_DESCRIPTOR UsbDeviceDescriptor
Definition: wdfusb.h:1008

◆ CreateInterfaces()

_Must_inspect_result_ NTSTATUS FxUsbDevice::CreateInterfaces ( VOID  )

Definition at line 898 of file fxusbdevice.cpp.

901{
903 UCHAR descCountBitMap[UCHAR_MAX / sizeof(UCHAR)];
904 PUSB_INTERFACE_DESCRIPTOR pInterfaceDescriptor;
905 UCHAR iInterface, numFound;
907 ULONG size;
908 ULONG totalLength;
909
912 totalLength = m_ConfigDescriptor->wTotalLength;
913
914 //
915 // Make sure each PCOMMON_DESCRIPTOR_HEADER within the entire config descriptor is well formed.
916 // If successful, we can walk the config descriptor using common headers without any more top
917 // level error checking. Task specific checking of the specialized header types must still occur.
918 //
923 );
924
925 if (!NT_SUCCESS(status)) {
928 "Validation of the config descriptor failed due to a bad common descriptor header, %!STATUS!",
929 status);
930 return status;
931 }
932
933 //
934 // Validate all interface descriptors in config descriptor are at least
935 // sizeof(USB_INTERFACE_DESCRIPTOR).
936 //
937
938
939
940
941
950 0
951 );
952
953 if (!NT_SUCCESS(status)) {
956 "Validation of interface descriptors in config descriptor failed, %!STATUS!",
957 status);
958
959 return status;
960 }
961
963 //
964 // Use an array of one in the zero case
965 //
966 size = sizeof(FxUsbInterface*);
967 }
968 else {
970 }
971
972 //
973 // Allocate an array large enough to hold pointers to interfaces
974 //
976 FxPoolAllocate(pFxDriverGlobals, NonPagedPool, size);
977
978 if (m_Interfaces == NULL) {
980
983 "Could not allocate memory for %d interfaces, %!STATUS!",
985
986 goto Done;
987 }
988
991
992 //
993 // Iterate over the desciptors again, this time allocating an FxUsbInterface
994 // for each one and capturing the interface information.
995 //
996 RtlZeroMemory(descCountBitMap, sizeof(descCountBitMap));
997 iInterface = 0;
998 numFound = 0;
999
1000 pInterfaceDescriptor = (PUSB_INTERFACE_DESCRIPTOR) FxUsbFindDescriptorType(
1005 );
1006
1007 while (pInterfaceDescriptor != NULL &&
1008 iInterface < m_ConfigDescriptor->bNumInterfaces) {
1009
1010 //
1011 // This function will retun false if the bit wasn't already set
1012 //
1013 if (FxBitArraySet(descCountBitMap,
1014 pInterfaceDescriptor->bInterfaceNumber) == FALSE) {
1016
1019 this,
1020 pInterfaceDescriptor);
1021
1022 if (pInterface == NULL) {
1026 "Could not allocate memory for interface object #%d, %!STATUS!",
1027 iInterface, status);
1028 goto Done;
1029 }
1030
1032
1033 //
1034 // This should never fail
1035 //
1037
1038 if (!NT_SUCCESS(status)) {
1039 goto Done;
1040 }
1041
1042 status = pInterface->CreateSettings();
1043 if (!NT_SUCCESS(status)) {
1044 goto Done;
1045 }
1046
1047#if (FX_CORE_MODE == FX_CORE_USER_MODE)
1048 status = pInterface->SetWinUsbHandle(iInterface);
1049 if (!NT_SUCCESS(status)) {
1050 goto Done;
1051 }
1052
1053 status = pInterface->MakeAndConfigurePipes(WDF_NO_OBJECT_ATTRIBUTES,
1054 pInterfaceDescriptor->bNumEndpoints);
1055 if (!NT_SUCCESS(status)) {
1056 goto Done;
1057 }
1058#endif
1059
1060 m_Interfaces[iInterface] = pInterface;
1061
1062 iInterface++;
1063 }
1064
1065 pInterfaceDescriptor = (PUSB_INTERFACE_DESCRIPTOR) FxUsbFindDescriptorType(
1067 totalLength,
1068 WDF_PTR_ADD_OFFSET(pInterfaceDescriptor,
1069 pInterfaceDescriptor->bLength),
1071 );
1072 }
1073
1074 //
1075 // We cannot check for the error case of
1076 //
1077 // pInterfaceDescriptor != NULL &&
1078 // iInterface == m_ConfigDescriptor->bNumInterfaces
1079 //
1080 // Because if there are multiple alternative settings for the last interface
1081 // in the config descriptor, we will have hit the limit of interfaces
1082 // (correctly), but have found another pInterfaceDescriptor (the next alt
1083 // setting).
1084 //
1085
1086 //
1087 // We already logged and found the case where iInterface >= m_NumInterfaces.
1088 // Check for the case where we found too few interfaces and when we found
1089 // no interfaces even though the config descriptor says otherwise.
1090 //
1091 //
1092 if (iInterface == 0 && m_NumInterfaces > 0) {
1094
1097 "Config descriptor indicated there were %d interfaces, but did not "
1098 "find any interface descriptors in config descriptor %p, %!STATUS!",
1100 }
1101 else if (pInterfaceDescriptor != NULL && m_NumInterfaces == 0) {
1104 "Config descriptor indicated there were 0 interfaces, but an interface "
1105 "descriptor was found");
1106
1108 }
1109 else if (iInterface < m_NumInterfaces) {
1112 "Config descriptor indicated there were %d interfaces, only found "
1113 "%d interfaces", m_NumInterfaces, iInterface);
1114
1115 //
1116 // Instead of considering this an error, just use the number found.
1117 // This will not have an adverse affect elsewhere and since the framework
1118 // is probably more strict then previous USB code, this would have not
1119 // been found earlier by a WDM driver.
1120 //
1121 m_NumInterfaces = iInterface;
1122 }
1123
1124Done:
1125 return status;
1126}
LONG NTSTATUS
Definition: precomp.h:26
friend FxUsbInterface
#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)
PFX_DRIVER_GLOBALS pFxDriverGlobals
PINTERFACE pInterface
GLsizeiptr size
Definition: glext.h:5919
#define UCHAR_MAX
Definition: limits.h:25
#define STATUS_SUCCESS
Definition: shellext.h:65
#define TRACE_LEVEL_WARNING
Definition: storswtr.h:28
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
Definition: ps.c:97
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
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
NTSTATUS FxUsbValidateConfigDescriptorHeaders(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PUSB_CONFIGURATION_DESCRIPTOR ConfigDescriptor, __in size_t ConfigDescriptorLength)
Definition: usbutil.cpp:111
@ FxUsbValidateDescriptorOpAtLeast
Definition: usbutil.hpp:128
BOOLEAN __inline FxBitArraySet(__inout_xcount((BitNumber/sizeof(UCHAR))+1) PUCHAR BitArray, __in UCHAR BitNumber)
Definition: usbutil.hpp:9
#define WDF_PTR_ADD_OFFSET(_ptr, _offset)
Definition: wdfcore.h:144
#define WDF_NO_OBJECT_ATTRIBUTES
Definition: wdftypes.h:105

◆ CreateIsochUrb()

__checkReturn NTSTATUS FxUsbDevice::CreateIsochUrb ( __in_opt PWDF_OBJECT_ATTRIBUTES  Attributes,
__in ULONG  NumberOfIsochPackets,
__out WDFMEMORY *  UrbMemory,
__deref_opt_out_bcount(GET_ISOCH_URB_SIZE(NumberOfIsochPackets)) PURB Urb 
)

Definition at line 2237 of file fxusbdevice.cpp.

2247{
2249 PURB urbLocal = NULL;
2251 FxUsbUrb * pUrb = NULL;
2252 WDFMEMORY hMemory;
2253 ULONG size;
2255
2256 //
2257 // Get the parent's globals if it is present, else use the ones for FxUsbDevice
2258 //
2261
2262 if (NT_SUCCESS(status)) {
2263
2265 Attributes->ParentObject,
2267 (PVOID*)&pParent,
2269
2273 "Urb must be parented to FxDevice or IoAllocated Request");
2275 goto Done;
2276 }
2277
2278 }
2280
2282 pParent = this;
2284
2285 }
2286 else {
2287
2288 goto Done;
2289 }
2290
2292 if (!NT_SUCCESS(status)) {
2293 goto Done;
2294 }
2295
2297
2298 *UrbMemory = NULL;
2299
2301
2302 if (!NT_SUCCESS(status)) {
2303
2304 urbLocal = NULL;
2307 "USBDEVICE Must have been created with Client Contract Version Info, %!STATUS!",
2308 status);
2309
2310 goto Done;
2311
2312 }
2313
2315
2316 pUrb = new(pFxDriverGlobals, Attributes)
2318
2319 if (pUrb == NULL) {
2321 goto Done;
2322 }
2323
2324 urbLocal = NULL;
2325
2327
2328 if (!NT_SUCCESS(status)) {
2329 goto Done;
2330 }
2331
2332 *UrbMemory = hMemory;
2333
2334 if (Urb) {
2335 *Urb = (PURB) pUrb->GetBuffer();
2336 }
2337
2338Done:
2339
2340 if (!NT_SUCCESS(status)) {
2341
2342 if (pUrb) {
2343 pUrb->DeleteFromFailedCreate();
2344 }
2345
2346 if (urbLocal) {
2347 USBD_UrbFree(m_USBDHandle, urbLocal);
2348 }
2349
2350 }
2351
2352 return status;
2353}
VOID DeleteFromFailedCreate(VOID)
Definition: fxobject.cpp:391
_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
BOOLEAN IsObjectDisposedOnRemove(__in FxObject *Object)
FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals), Device, FX_TYPE_DEVICE,(PVOID *)&pDevice, &pFxDriverGlobals)
FxObject * pParent
Definition: fxdpcapi.cpp:86
WDFMEMORY hMemory
#define FxPointerNotNull(FxDriverGlobals, Ptr)
Definition: fxmacros.hpp:253
@ FX_TYPE_OBJECT
Definition: fxtypes.h:45
_Must_inspect_result_ NTSTATUS __inline FxValidateObjectAttributesForParentHandle(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PWDF_OBJECT_ATTRIBUTES Attributes, __in ULONG Flags=FX_VALIDATE_OPTION_NONE_SPECIFIED)
_Must_inspect_result_ NTSTATUS FxValidateObjectAttributes(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PWDF_OBJECT_ATTRIBUTES Attributes, __in ULONG Flags=FX_VALIDATE_OPTION_NONE_SPECIFIED)
Definition: usb.h:529
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
struct _URB * PURB
#define GET_ISO_URB_SIZE(n)
Definition: usbdlib.h:125
NTSTATUS USBD_IsochUrbAllocate(_In_ USBD_HANDLE USBDHandle, _In_ ULONG NumberOfIsochPacket, _Outptr_result_bytebuffer_(sizeof(struct _URB_ISOCH_TRANSFER)+(NumberOfIsochPackets *sizeof(USBD_ISO_PACKET_DESCRIPTOR)) - sizeof(USBD_ISO_PACKET_DESCRIPTOR)) PURB *Urb)
Definition: usbstubum.cpp:60
VOID USBD_UrbFree(_In_ USBD_HANDLE USBDHandle, _In_ PURB Urb)
Definition: usbstubum.cpp:33
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes
#define STATUS_WDF_PARENT_NOT_SPECIFIED
Definition: wdfstatus.h:252
_Must_inspect_result_ _In_ WDFUSBDEVICE _In_ WDFREQUEST _In_ WDFMEMORY UrbMemory
Definition: wdfusb.h:1576
_Must_inspect_result_ _In_ WDFUSBDEVICE _In_opt_ PWDF_OBJECT_ATTRIBUTES _In_ ULONG NumberOfIsochPackets
Definition: wdfusb.h:1703

◆ CreateUrb()

__checkReturn NTSTATUS FxUsbDevice::CreateUrb ( __in_opt PWDF_OBJECT_ATTRIBUTES  Attributes,
__out WDFMEMORY *  UrbMemory,
__deref_opt_out_bcount(sizeof(URB)) PURB Urb 
)

Definition at line 2122 of file fxusbdevice.cpp.

2130{
2132 PURB urbLocal = NULL;
2134 FxUsbUrb * pUrb = NULL;
2135 WDFMEMORY hMemory;
2137
2138 //
2139 // Get the parent's globals if it is present, else use the ones for FxUsbDevice
2140 //
2143
2144 if (NT_SUCCESS(status)) {
2145
2147 Attributes->ParentObject,
2149 (PVOID*)&pParent,
2151
2155 "Urb must be parented to FxDevice or an IoAllocated Request");
2157 goto Done;
2158 }
2159
2160 }
2162
2164 pParent = this;
2166
2167 }
2168 else {
2169
2170 goto Done;
2171 }
2172
2174 if (!NT_SUCCESS(status)) {
2175 goto Done;
2176 }
2177
2179
2180 *UrbMemory = NULL;
2181
2182 status = USBD_UrbAllocate(m_USBDHandle, &urbLocal);
2183
2184 if (!NT_SUCCESS(status)) {
2185
2186 urbLocal = NULL;
2189 "USBDEVICE Must have been created with Client Contract Version Info, %!STATUS!",
2190 status);
2191
2192 goto Done;
2193
2194 }
2195
2196 pUrb = new(pFxDriverGlobals, Attributes)
2197 FxUsbUrb(pFxDriverGlobals, m_USBDHandle, urbLocal, sizeof(URB));
2198
2199 if (pUrb == NULL) {
2201 goto Done;
2202 }
2203
2204 urbLocal = NULL;
2205
2207
2208 if (!NT_SUCCESS(status)) {
2209 goto Done;
2210 }
2211
2212 *UrbMemory = hMemory;
2213
2214 if (Urb) {
2215 *Urb = (PURB) pUrb->GetBuffer();
2216 }
2217
2218Done:
2219
2220 if (!NT_SUCCESS(status)) {
2221
2222 if (pUrb) {
2223 pUrb->DeleteFromFailedCreate();
2224 }
2225
2226 if (urbLocal) {
2227 USBD_UrbFree(m_USBDHandle, urbLocal);
2228 }
2229
2230 }
2231
2232 return status;
2233}
NTSTATUS USBD_UrbAllocate(_In_ USBD_HANDLE USBDHandle, _Outptr_result_bytebuffer_(sizeof(URB)) PURB *Urb)
Definition: usbstubum.cpp:46

Referenced by __deref_opt_out_bcount().

◆ CyclePort()

_Must_inspect_result_ NTSTATUS FxUsbDevice::CyclePort ( VOID  )

Definition at line 1227 of file fxusbdevice.cpp.

1230{
1232 FxSyncRequest request(GetDriverGlobals(), &context);
1234
1235 //
1236 // FxSyncRequest always succeesds for KM.
1237 //
1238 status = request.Initialize();
1239 if (!NT_SUCCESS(status)) {
1241 "Failed to initialize FxSyncRequest");
1242 return status;
1243 }
1244
1245 status = FormatCycleRequest(request.m_TrueRequest);
1246
1247 if (NT_SUCCESS(status)) {
1248 CancelSentIo();
1250 //
1251 // NOTE: CyclePort causes the device to be removed and re-enumerated so
1252 // don't do anymore operations after this point.
1253 //
1254 }
1255
1256 return status;
1257}
_Must_inspect_result_ NTSTATUS SubmitSyncRequestIgnoreTargetState(__in FxRequestBase *Request, __in_opt PWDF_REQUEST_SEND_OPTIONS RequestOptions)
_Must_inspect_result_ NTSTATUS FormatCycleRequest(__in FxRequestBase *Request)
VOID CancelSentIo(VOID)
Definition: http.c:7252
Definition: tftpd.h:86

◆ Deconfig()

_Must_inspect_result_ NTSTATUS FxUsbDevice::Deconfig ( VOID  )

Definition at line 1877 of file fxusbdevice.cpp.

1880{
1883
1884 FxSyncRequest request(GetDriverGlobals(), NULL);
1886
1887 //
1888 // FxSyncRequest always succeesds for KM but can fail for UM.
1889 //
1890 status = request.Initialize();
1891 if (!NT_SUCCESS(status)) {
1893 "Failed to initialize FxSyncRequest");
1894 return status;
1895 }
1896
1897 status = request.m_TrueRequest->ValidateTarget(this);
1898 if (!NT_SUCCESS(status)) {
1899 return status;
1900 }
1901
1902 //
1903 // This will remove and free all interfaces and associated pipes
1904 //
1906
1907 RtlZeroMemory(&urb, sizeof(urb));
1908
1909#pragma prefast(suppress: __WARNING_BUFFER_OVERFLOW, "this annotation change in usb.h is communicated to usb team");
1910 UsbBuildSelectConfigurationRequest((PURB) &urb, sizeof(urb), NULL);
1911#pragma prefast(suppress: __WARNING_BUFFER_OVERFLOW, "this annotation change in usb.h is communicated to usb team");
1912 FxFormatUsbRequest(request.m_TrueRequest, (PURB) &urb, FxUrbTypeLegacy, NULL);
1913
1916
1917 status = SubmitSync(request.m_TrueRequest, &options);
1918
1919 return status;
1920}
_Must_inspect_result_ NTSTATUS SubmitSync(__in FxRequestBase *Request, __in_opt PWDF_REQUEST_SEND_OPTIONS Options=NULL, __out_opt PULONG Action=NULL)
VOID PipesGotoRemoveState(__in BOOLEAN ForceRemovePipes)
#define UsbBuildSelectConfigurationRequest(urb, length, configurationDescriptor)
Definition: usbdlib.h:53
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 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

◆ Dispose()

BOOLEAN FxUsbDevice::Dispose ( VOID  )
protectedvirtual

Reimplemented from FxIoTarget.

Definition at line 406 of file fxusbdevice.cpp.

409{
410#if ((FX_CORE_MODE)==(FX_CORE_KERNEL_MODE))
411 KeFlushQueuedDpcs();
412#endif
413
414 if (m_USBDHandle) {
417 }
418
419#if (FX_CORE_MODE == FX_CORE_USER_MODE)
420 IWudfDevice* device = NULL;
421 IWudfDeviceStack* devstack = NULL;
422
424 devstack = device->GetDeviceStackInterface();
425
426 if (m_pHostTargetFile) {
427 devstack->CloseFile(m_pHostTargetFile);
429 }
430#endif
431
432 return FxIoTarget::Dispose(); // __super call
433}
MdDeviceObject __inline GetDeviceObject(VOID)
Definition: fxdevice.hpp:174
virtual BOOLEAN Dispose(VOID)
Definition: fxiotarget.cpp:154
CfxDeviceBase * m_DeviceBase
Definition: fxobject.hpp:328
Definition: devices.h:37
VOID USBD_CloseHandle(_In_ USBD_HANDLE USBDHandle)
Definition: usbstubum.cpp:80
#define SAFE_RELEASE(p)

◆ FormatControlRequest()

_Must_inspect_result_ NTSTATUS FxUsbDevice::FormatControlRequest ( __in FxRequestBase Request,
__in PWDF_USB_CONTROL_SETUP_PACKET  Packet,
__in FxRequestBuffer RequestBuffer 
)

Definition at line 588 of file fxusbdevicekm.cpp.

593{
596 size_t bufferSize;
597 FX_URB_TYPE urbType;
598
599 bufferSize = RequestBuffer->GetBufferLength();
600
601 //
602 // We can only transfer 2 bytes worth of data, so if the buffer is larger,
603 // fail here.
604 //
605 if (bufferSize > 0xFFFF) {
608 "Control transfer buffer is limited to 0xFFFF bytes in size, "
609 "%I64d requested ", bufferSize);
610
612 }
613
614 status = Request->ValidateTarget(this);
615 if (!NT_SUCCESS(status)) {
617 "WDFUSBDEVICE %p, Request %p, setting target failed, "
618 "%!STATUS!", GetHandle(), Request, status);
619
620 return status;
621 }
622
623 if (Request->HasContextType(FX_RCT_USB_CONTROL_REQUEST)) {
624 pContext = (FxUsbDeviceControlContext*) Request->GetContext();
625 }
626 else {
627
629 pContext = new(GetDriverGlobals()) FxUsbDeviceControlContext(urbType);
630 if (pContext == NULL) {
632 }
633
634 if (urbType == FxUrbTypeUsbdAllocated) {
635 status = pContext->AllocateUrb(m_USBDHandle);
636 if (!NT_SUCCESS(status)) {
638 "FxUsbDeviceControlContext::AllocateUrb Failed, %!STATUS!", status);
639
640 delete pContext;
641 return status;
642 }
643 //
644 // Since the AllocateUrb routine calls USBD_xxxUrbAllocate APIs to allocate an Urb, it is
645 // important to release those resorces before the devnode is removed. Those
646 // resoruces are removed at the time Request is disposed.
647 //
648 Request->EnableContextDisposeNotification();
649 }
650
651 Request->SetContext(pContext);
652 }
653
654 if (RequestBuffer->HasMdl()) {
655 PMDL pMdl;
656
657 pMdl = NULL;
658 ASSERT(pContext->m_PartialMdl == NULL);
659
660 status = RequestBuffer->GetOrAllocateMdl(GetDriverGlobals(),
661 &pMdl,
662 &pContext->m_PartialMdl,
663 &pContext->m_UnlockPages,
665
666 if (!NT_SUCCESS(status)) {
667 return status;
668 }
669
670 ASSERT(pMdl != NULL);
671 }
672
673 pContext->StoreAndReferenceMemory(this, RequestBuffer, SetupPacket);
674
675 if (pContext->m_Urb == &pContext->m_UrbLegacy) {
676 urbType = FxUrbTypeLegacy;
677 }
678 else {
679 urbType = FxUrbTypeUsbdAllocated;
680 }
681
682 FxFormatUsbRequest(Request, (PURB)pContext->m_Urb, urbType, m_USBDHandle);
683
684 return STATUS_SUCCESS;
685}
FX_URB_TYPE GetFxUrbTypeForRequest(__in FxRequestBase *Request)
@ FX_RCT_USB_CONTROL_REQUEST
@ FxUrbTypeUsbdAllocated
Definition: fxusbdevice.hpp:28
enum _FX_URB_TYPE FX_URB_TYPE
size_t bufferSize
_URB_CONTROL_TRANSFER * m_Urb
Definition: fxusbdevice.hpp:86
_URB_CONTROL_TRANSFER m_UrbLegacy
Definition: fxusbdevice.hpp:81
__checkReturn NTSTATUS AllocateUrb(__in USBD_HANDLE USBDHandle)
Definition: fxusbdevice.cpp:66
VOID StoreAndReferenceMemory(__in FxUsbDevice *Device, __in FxRequestBuffer *Buffer, __in PWDF_USB_CONTROL_SETUP_PACKET SetupPacket)
#define GetHandle(h)
Definition: treelist.c:116
_In_ WDFREQUEST Request
Definition: wdfdevice.h:547
_Must_inspect_result_ _In_ WDFUSBDEVICE _In_opt_ WDFREQUEST _In_opt_ PWDF_REQUEST_SEND_OPTIONS _In_ PWDF_USB_CONTROL_SETUP_PACKET SetupPacket
Definition: wdfusb.h:1337
@ IoModifyAccess
Definition: ketypes.h:865

◆ FormatCycleRequest()

_Must_inspect_result_ NTSTATUS FxUsbDevice::FormatCycleRequest ( __in FxRequestBase Request)

Definition at line 1261 of file fxusbdevice.cpp.

1264{
1265 FxRequestBuffer emptyBuffer;
1266
1269 TRUE,
1270 &emptyBuffer,
1271 &emptyBuffer);
1272}
_Must_inspect_result_ NTSTATUS FormatIoctlRequest(__in FxRequestBase *Request, __in ULONG Ioctl, __in BOOLEAN Internal, __in FxRequestBuffer *InputBuffer, __in FxRequestBuffer *OutputBuffer, __in_opt FxFileObject *FileObject=NULL)
#define IOCTL_INTERNAL_USB_CYCLE_PORT
Definition: usbioctl.h:53

Referenced by CyclePort().

◆ FormatInterfaceSelectSettingUrb()

VOID FxUsbDevice::FormatInterfaceSelectSettingUrb ( __in PURB  Urb,
__in USHORT  NumEndpoints,
__in UCHAR  InterfaceNumber,
__in UCHAR  SettingNumber 
)
protected

◆ FormatStringRequest()

_Must_inspect_result_ NTSTATUS FxUsbDevice::FormatStringRequest ( __in FxRequestBase Request,
__in FxRequestBuffer RequestBuffer,
__in UCHAR  StringIndex,
__in USHORT  LangID 
)

Definition at line 496 of file fxusbdevicekm.cpp.

520{
521 FxUsbDeviceStringContext* pContext;
523 FX_URB_TYPE urbType;
524
525 status = Request->ValidateTarget(this);
526 if (!NT_SUCCESS(status)) {
528 "WDFUSBDEVICE %p, Request %p, setting target failed, "
529 "%!STATUS!", GetHandle(), Request, status);
530
531 return status;
532 }
533
534 if (Request->HasContextType(FX_RCT_USB_STRING_REQUEST)) {
535 pContext = (FxUsbDeviceStringContext*) Request->GetContext();
536 }
537 else {
538
540 pContext = new(GetDriverGlobals()) FxUsbDeviceStringContext(urbType);
541 if (pContext == NULL) {
543 }
544
545 if (urbType == FxUrbTypeUsbdAllocated) {
546 status = pContext->AllocateUrb(m_USBDHandle);
547 if (!NT_SUCCESS(status)) {
549 "FxUsbDeviceStringContext::AllocateUrb failed, %!STATUS!", status);
550 delete pContext;
551 return status;
552 }
553
554 //
555 // Since the AllocateUrb routine calls USBD_xxxUrbAllocate APIs to allocate an Urb, it is
556 // important to release those resorces before the devnode is removed. Those
557 // resoruces are removed at the time Request is disposed.
558 //
559 Request->EnableContextDisposeNotification();
560 }
561
562 Request->SetContext(pContext);
563 }
564
566 RequestBuffer->GetBufferLength());
567 if (!NT_SUCCESS(status)) {
568 return status;
569 }
570
571 pContext->StoreAndReferenceMemory(RequestBuffer);
572 pContext->SetUrbInfo(StringIndex, LangID);
573
574 if (pContext->m_Urb == &pContext->m_UrbLegacy) {
575 urbType = FxUrbTypeLegacy;
576 }
577 else {
578 urbType = FxUrbTypeUsbdAllocated;
579 }
580
581 FxFormatUsbRequest(Request, (PURB)pContext->m_Urb, urbType, m_USBDHandle);
582
583 return STATUS_SUCCESS;
584}
@ FX_RCT_USB_STRING_REQUEST
virtual VOID StoreAndReferenceMemory(__in FxRequestBuffer *Buffer)
VOID SetUrbInfo(__in UCHAR StringIndex, __in USHORT LangID)
_Must_inspect_result_ NTSTATUS AllocateDescriptor(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in size_t BufferSize)
__checkReturn NTSTATUS AllocateUrb(__in USBD_HANDLE USBDHandle)
_URB_CONTROL_DESCRIPTOR_REQUEST m_UrbLegacy
_URB_CONTROL_DESCRIPTOR_REQUEST * m_Urb
_Must_inspect_result_ _In_ WDFUSBDEVICE _In_opt_ WDFREQUEST _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_writes_opt_ NumCharacters PUSHORT _Inout_ PUSHORT _In_ UCHAR StringIndex
Definition: wdfusb.h:1080
_Must_inspect_result_ _In_ WDFUSBDEVICE _In_opt_ WDFREQUEST _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_writes_opt_ NumCharacters PUSHORT _Inout_ PUSHORT _In_ UCHAR _In_opt_ USHORT LangID
Definition: wdfusb.h:1083

◆ GetConfigDescriptor()

_Must_inspect_result_ NTSTATUS FxUsbDevice::GetConfigDescriptor ( __out PVOID  ConfigDescriptor,
__inout PUSHORT  ConfigDescriptorLength 
)

Definition at line 1276 of file fxusbdevice.cpp.

1280{
1282 USHORT copyLength;
1283
1284 if (ConfigDescriptor == NULL) {
1285 //
1286 // Caller wants length to allocate
1287 //
1290 }
1291
1292 if (*ConfigDescriptorLength < m_ConfigDescriptor->wTotalLength) {
1293 //
1294 // Valid ConfigDescriptor passed in, but its too small. Copy as many
1295 // bytes as we can.
1296 //
1297 copyLength = *ConfigDescriptorLength;
1299 }
1300 else {
1301 copyLength = m_ConfigDescriptor->wTotalLength;
1303 }
1304
1305 //
1306 // Always indicate to the caller the number of required bytes or the
1307 // number of bytes we copied.
1308 //
1311
1312 return status;
1313}
unsigned short USHORT
Definition: pedump.c:61
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
_Must_inspect_result_ _In_ WDFUSBDEVICE _Out_writes_bytes_to_opt_ ConfigDescriptorLength PVOID ConfigDescriptor
Definition: wdfusb.h:1036
_Must_inspect_result_ _In_ WDFUSBDEVICE _Out_writes_bytes_to_opt_ ConfigDescriptorLength PVOID _Inout_ PUSHORT ConfigDescriptorLength
Definition: wdfusb.h:1040

◆ GetConfigHandle()

__inline USBD_CONFIGURATION_HANDLE FxUsbDevice::GetConfigHandle ( VOID  )
inline

Definition at line 234 of file fxusbdevice.hpp.

237 {
238 return m_ConfigHandle;
239 }

◆ GetControlPipeHandle()

USBD_PIPE_HANDLE FxUsbDevice::GetControlPipeHandle ( VOID  )
inline

Definition at line 369 of file fxusbdevice.hpp.

372 {
373 return m_ControlPipe;
374 }

◆ GetCurrentFrameNumber()

_Must_inspect_result_ __inline NTSTATUS FxUsbDevice::GetCurrentFrameNumber ( __in PULONG  Current)
inline

Definition at line 244 of file fxusbdevice.hpp.

247 {
248 if (m_QueryBusTime != NULL) {
249 return m_QueryBusTime(m_BusInterfaceContext, Current);
250 }
251 else {
252 return STATUS_UNSUCCESSFUL;
253 }
254 }
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132

◆ GetDefaultMaxTransferSize()

ULONG FxUsbDevice::GetDefaultMaxTransferSize ( VOID  )
protected

Definition at line 494 of file fxusbdevice.cpp.

519{
520 //
521 // On a usbport serviced stack (which can be running on Win2k) or on a
522 // usbd stack on XP and later. In any case, always use the current max
523 // transfer size definition.
524 //
526}
#define USBD_DEFAULT_MAXIMUM_TRANSFER_SIZE
Definition: usb.h:236

Referenced by FxUsbInterface::FormatSelectSettingUrb(), SelectConfigDescriptor(), SelectConfigInterfaces(), SelectConfigMulti(), and SelectConfigSingle().

◆ GetFxUrbTypeForRequest()

FX_URB_TYPE FxUsbDevice::GetFxUrbTypeForRequest ( __in FxRequestBase Request)

Definition at line 2434 of file fxusbdevice.cpp.

2460{
2461 if (m_UrbType == FxUrbTypeLegacy) {
2462 return FxUrbTypeLegacy;
2463 }
2464
2465 if (Request->IsAllocatedFromIo()) {
2467 }
2468
2471 }
2472
2473 return FxUrbTypeLegacy;
2474}

Referenced by FxUsbPipe::FormatAbortRequest(), FormatControlRequest(), FxUsbPipe::FormatResetRequest(), FormatStringRequest(), and FxUsbPipe::FormatTransferRequest().

◆ GetInformation()

VOID FxUsbDevice::GetInformation ( __out PWDF_USB_DEVICE_INFORMATION  Information)

Definition at line 481 of file fxusbdevice.cpp.

484{
485 Information->Traits = m_Traits;
486 Information->HcdPortCapabilities = m_HcdPortCapabilities;
487
488 RtlCopyMemory(&Information->UsbdVersionInformation,
491}
_In_ WDFREQUEST _In_ NTSTATUS _In_ ULONG_PTR Information
Definition: wdfrequest.h:1049

◆ GetInterfaceFromIndex()

FxUsbInterface * FxUsbDevice::GetInterfaceFromIndex ( __in UCHAR  InterfaceIndex)

Definition at line 2005 of file fxusbdevice.cpp.

2008{
2011 }
2012
2013 return NULL;
2014}
_In_ WDFUSBDEVICE _In_ UCHAR InterfaceIndex
Definition: wdfusb.h:2462

◆ GetInterfaceFromNumber()

FxUsbInterface * FxUsbDevice::GetInterfaceFromNumber ( __in UCHAR  InterfaceNumber)
protected

Definition at line 2036 of file fxusbdevice.cpp.

2039{
2040 ULONG i;
2041
2042 for (i = 0; i < m_NumInterfaces; i++) {
2044 return m_Interfaces[i];
2045 }
2046 }
2047
2048 return NULL;
2049}
return pUsbInterface GetInterfaceNumber()
_In_ PVOID _In_ LONG InterfaceNumber
Definition: usbdlib.h:169

Referenced by SelectConfig().

◆ GetInterfaceNumberFromInterface()

_Must_inspect_result_ NTSTATUS FxUsbDevice::GetInterfaceNumberFromInterface ( __in WDFUSBINTERFACE  UsbInterface,
__out PUCHAR  InterfaceNumber 
)
protected

Definition at line 2018 of file fxusbdevice.cpp.

2022{
2024
2028 (PVOID*) &pUsbInterface);
2029
2031
2032 return STATUS_SUCCESS;
2033}
UCHAR GetInterfaceNumber(VOID)
FxObjectHandleGetPtr(GetFxDriverGlobals(DriverGlobals), Fdo, FX_TYPE_DEVICE,(PVOID *)&pFdo)
@ FX_TYPE_USB_INTERFACE
Definition: fxtypes.h:104

Referenced by SelectConfigMulti().

◆ GetInterfaceNumEndpoints()

UCHAR FxUsbDevice::GetInterfaceNumEndpoints ( __in UCHAR  InterfaceNumber)

◆ GetInterfacePipeReferenced()

WDFUSBPIPE FxUsbDevice::GetInterfacePipeReferenced ( __in UCHAR  InterfaceNumber,
__in UCHAR  EndpointNumber 
)

◆ GetNumInterfaces()

UCHAR FxUsbDevice::GetNumInterfaces ( VOID  )
inline

Definition at line 301 of file fxusbdevice.hpp.

304 {
305 return m_NumInterfaces;
306 }

◆ GetPortStatus()

_Must_inspect_result_ NTSTATUS FxUsbDevice::GetPortStatus ( __out PULONG  PortStatus)
protected

Definition at line 1131 of file fxusbdevice.cpp.

1134{
1136
1139 FxSyncRequest syncRequest(GetDriverGlobals(), &context);
1140
1141 //
1142 // FxSyncRequest always succeesds for KM.
1143 //
1144 status = syncRequest.Initialize();
1145 if (!NT_SUCCESS(status)) {
1147 "Failed to initialize FxSyncRequest");
1148 return status;
1149 }
1150
1151 *PortStatus = 0;
1152 args[0].SetBuffer(PortStatus, 0);
1153 args[1].SetBuffer(NULL, 0);
1154 args[2].SetBuffer(NULL, 0);
1155
1156 status = FormatInternalIoctlOthersRequest(syncRequest.m_TrueRequest,
1158 args);
1159
1160 if (NT_SUCCESS(status)) {
1162
1165
1166 status = SubmitSync(syncRequest.m_TrueRequest, &options);
1167 }
1168
1169 return status;
1170}
_Must_inspect_result_ NTSTATUS FormatInternalIoctlOthersRequest(__in FxRequestBase *Request, __in ULONG Ioctl, __in FxRequestBuffer *Buffers)
#define FX_REQUEST_NUM_OTHER_PARAMS
_Outptr_ PUSB_DEVICE_HANDLE _In_ PUSB_DEVICE_HANDLE _In_ USHORT PortStatus
Definition: hubbusif.h:42
Definition: match.c:390
#define IOCTL_INTERNAL_USB_GET_PORT_STATUS
Definition: usbioctl.h:44

Referenced by IsConnected(), and IsEnabled().

◆ GetString()

_Must_inspect_result_ NTSTATUS FxUsbDevice::GetString ( __in_ecount *NumCharacters PUSHORT  String,
__in PUSHORT  NumCharacters,
__in UCHAR  StringIndex,
__in_opt USHORT  LangID,
__in_opt WDFREQUEST  Request = NULL,
__in_opt PWDF_REQUEST_SEND_OPTIONS  Options = NULL 
)

Definition at line 365 of file fxusbdevicekm.cpp.

373{
374 PUSB_STRING_DESCRIPTOR pDescriptor;
381
382 FxSyncRequest request(GetDriverGlobals(), NULL, Request);
383
384 //
385 // FxSyncRequest always succeesds for KM.
386 //
387 status = request.Initialize();
388 if (!NT_SUCCESS(status)) {
390 "Failed to initialize FxSyncRequest");
391 return status;
392 }
393
394 buffer = NULL;
395
396 status = request.m_TrueRequest->ValidateTarget(this);
397 if (!NT_SUCCESS(status)) {
398 goto Done;
399 }
400
401 RtlZeroMemory(&urb, sizeof(urb));
402
403 if (String != NULL) {
404 length = sizeof(USB_STRING_DESCRIPTOR) + (*NumCharacters - 1) * sizeof(WCHAR);
405
406 buffer = FxPoolAllocate(GetDriverGlobals(),
408 length);
409
410 if (buffer == NULL) {
412 goto Done;
413 }
414
416 pDescriptor = (PUSB_STRING_DESCRIPTOR) buffer;
417 }
418 else {
419 RtlZeroMemory(&common, sizeof(common));
420
422 pDescriptor = (PUSB_STRING_DESCRIPTOR) &common;
423 }
424
429 LangID,
430 pDescriptor,
431 NULL,
432 length,
433 NULL);
434
435 if (Options != NULL) {
436 pOptions = Options;
437 }
438 else {
442
443 pOptions = &options;
444 }
445#pragma prefast(suppress: __WARNING_BUFFER_OVERFLOW, "this annotation change in usb.h is communicated to usb team")
446 FxFormatUsbRequest(request.m_TrueRequest, (PURB) &urb, FxUrbTypeLegacy, NULL);
447 status = SubmitSync(request.m_TrueRequest, pOptions);
448
449 if (NT_SUCCESS(status)) {
451
452 //
453 // Make sure we got an even number of bytes and that we got a header
454 //
455 if ((pDescriptor->bLength & 0x1) ||
456 pDescriptor->bLength < sizeof(USB_COMMON_DESCRIPTOR)) {
458 }
459 else {
460 //
461 // bLength is the length of the entire descriptor. Subtract off
462 // the descriptor header and then divide by the size of a WCHAR.
463 //
464 numChars =
465 (pDescriptor->bLength - sizeof(USB_COMMON_DESCRIPTOR)) / sizeof(WCHAR);
466
467 if (String != NULL) {
468 if (*NumCharacters >= numChars) {
469 length = numChars * sizeof(WCHAR);
470 }
471 else {
472 length = *NumCharacters * sizeof(WCHAR);
474 }
475
477 RtlCopyMemory(String, pDescriptor->bString, length);
478 }
479 else {
481 }
482 }
483 }
484
485 if (buffer != NULL) {
487 }
488
489Done:
490
491 return status;
492}
USHORT numChars
GLuint buffer
Definition: glext.h:5915
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
#define STATUS_DEVICE_DATA_ERROR
Definition: udferr_usr.h:159
struct _USB_STRING_DESCRIPTOR * PUSB_STRING_DESCRIPTOR
#define USB_STRING_DESCRIPTOR_TYPE
Definition: usb100.h:51
struct _USB_STRING_DESCRIPTOR USB_STRING_DESCRIPTOR
struct _USB_COMMON_DESCRIPTOR USB_COMMON_DESCRIPTOR
#define UsbBuildGetDescriptorRequest(urb, length, descriptorType, descriptorIndex, languageId, transferBuffer, transferBufferMDL, transferBufferLength, link)
Definition: usbdlib.h:23
FORCEINLINE LONGLONG WDF_REL_TIMEOUT_IN_SEC(_In_ ULONGLONG Time)
Definition: wdfcore.h:62
_In_ PWDFDEVICE_INIT _In_ PWDF_REMOVE_LOCK_OPTIONS Options
Definition: wdfdevice.h:3534
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2433
FORCEINLINE VOID WDF_REQUEST_SEND_OPTIONS_SET_TIMEOUT(_Inout_ PWDF_REQUEST_SEND_OPTIONS Options, _In_ LONGLONG Timeout)
Definition: wdfrequest.h:421
_Must_inspect_result_ _In_ WDFUSBDEVICE _In_opt_ WDFREQUEST _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_writes_opt_ NumCharacters PUSHORT _Inout_ PUSHORT NumCharacters
Definition: wdfusb.h:1078
__wchar_t WCHAR
Definition: xmlstorage.h:180

◆ GetUrbType()

FX_URB_TYPE FxUsbDevice::GetUrbType ( VOID  )
inline

Definition at line 478 of file fxusbdevice.hpp.

481 {
482 return m_UrbType;
483 }

Referenced by __in_xcount().

◆ GetUSBDHandle()

USBD_HANDLE FxUsbDevice::GetUSBDHandle ( VOID  )
inline

Definition at line 470 of file fxusbdevice.hpp.

473 {
474 return m_USBDHandle;
475 }

Referenced by __deref_opt_out_bcount(), __in_xcount(), and QueryUsbCapability().

◆ HasMismatchedInterfacesInConfigDescriptor()

BOOLEAN FxUsbDevice::HasMismatchedInterfacesInConfigDescriptor ( VOID  )
inline

Definition at line 409 of file fxusbdevice.hpp.

◆ InitDevice()

_Must_inspect_result_ NTSTATUS FxUsbDevice::InitDevice ( __in ULONG  USBDClientContractVersionForWdfClient)

Definition at line 43 of file fxusbdevicekm.cpp.

46{
47 URB urb;
48 FxSyncRequest request(GetDriverGlobals(), NULL);
51 ULONG size;
52
53 RtlZeroMemory(&urb, sizeof(urb));
54
55 if (USBDClientContractVersionForWdfClient != USBD_CLIENT_CONTRACT_VERSION_INVALID) {
56
57 //
58 // Register with USBDEX.lib
59 //
62 USBDClientContractVersionForWdfClient,
65
66 if (!NT_SUCCESS(status)) {
69 "USBD_CreateHandle failed, %!STATUS!", status);
70 goto Done;
71 }
72
74 }
75
76 status = request.m_TrueRequest->ValidateTarget(this);
77 if (!NT_SUCCESS(status)) {
78 goto Done;
79 }
80
84 0,
85 0,
87 NULL,
88 sizeof(m_DeviceDescriptor),
89 NULL);
90
91 FxFormatUsbRequest(request.m_TrueRequest, &urb, FxUrbTypeLegacy, NULL);
92
95
96 status = SubmitSync(request.m_TrueRequest, &options);
97 if (!NT_SUCCESS(status)) {
100 "Could not retrieve device descriptor, %!STATUS!", status);
101 goto Done;
102 }
103
104 //
105 // After successfully completing any default control URB, USBD/usbport fills
106 // in the PipeHandle field of the URB (it is the same offset in every URB,
107 // which this CASSERT verifies. Since USBD_DEFAULT_PIPE_TRANSFER is not
108 // supported by USBD (it is by USBPORT), this is the prescribed way of getting
109 // the default control pipe so that you can set the PipeHandle field in
110 // _URB_CONTROL_TRANSFER.
111 //
114
116
118
119 RtlZeroMemory(&config, sizeof(config));
120 size = sizeof(config);
121
125 0,
126 0,
127 &config,
128 NULL,
129 size,
130 NULL);
131
132 request.m_TrueRequest->GetSubmitFxIrp()->Reuse(STATUS_SUCCESS);
133 request.m_TrueRequest->ClearFieldsForReuse();
134 FxFormatUsbRequest(request.m_TrueRequest, &urb, FxUrbTypeLegacy, NULL);
135
136 status = SubmitSync(request.m_TrueRequest, &options);
137 if (!NT_SUCCESS(status)) {
140 "Could not retrieve config descriptor size, %!STATUS!", status);
141 goto Done;
142 }
143 else if (urb.UrbControlDescriptorRequest.TransferBufferLength == 0) {
144 //
145 // Not enough info returned
146 //
148
151 "Could not retrieve config descriptor size, zero bytes transferred, "
152 " %!STATUS!", status);
153
154 goto Done;
155 }
156 else if (config.wTotalLength < size) {
157 //
158 // Not enough info returned
159 //
161
164 "Could not retrieve config descriptor size, config.wTotalLength %d < "
165 "sizeof(config descriptor) (%d), %!STATUS!",
166 config.wTotalLength, size, status);
167
168 goto Done;
169 }
170
171 //
172 // Allocate an additional memory at the end of the buffer so if we
173 // accidentily access fields beyond the end of the buffer we don't crash
174
175 //
176
177
178
179
180
181 size = config.wTotalLength;
182 ULONG paddedSize = size + sizeof(USB_DEVICE_DESCRIPTOR);
183
185 FxPoolAllocate(GetDriverGlobals(),
187 paddedSize);
188
189 if (m_ConfigDescriptor == NULL) {
191
194 "Could not allocate %d bytes for config descriptor, %!STATUS!",
195 paddedSize, status);
196
197 goto Done;
198 }
199
201
205 0,
206 0,
208 NULL,
209 size,
210 NULL);
211
212 request.m_TrueRequest->GetSubmitFxIrp()->Reuse(STATUS_SUCCESS);
213 request.m_TrueRequest->ClearFieldsForReuse();
214 FxFormatUsbRequest(request.m_TrueRequest, &urb, FxUrbTypeLegacy, NULL);
215
216 status = SubmitSync(request.m_TrueRequest, &options);
217 if (!NT_SUCCESS(status)) {
220 "Could not retrieve config descriptor, %!STATUS!", status);
221 goto Done;
222 } else if(m_ConfigDescriptor->wTotalLength != size) {
223 //
224 // Invalid wTotalLength
225 //
229 "Defective USB device reported two different config descriptor "
230 "wTotalLength values: %d and %d, %!STATUS!",
232 goto Done;
233 }
234
235 //
236 // Check to see if we are wait wake capable
237 //
240 }
241
242 //
243 // Check to see if we are self or bus powered
244 //
245 USHORT deviceStatus;
246
249 0,
250 &deviceStatus,
251 NULL,
252 NULL);
253
254 request.m_TrueRequest->GetSubmitFxIrp()->Reuse(STATUS_SUCCESS);
255 request.m_TrueRequest->ClearFieldsForReuse();
256 FxFormatUsbRequest(request.m_TrueRequest, &urb, FxUrbTypeLegacy, NULL);
257
258 status = SubmitSync(request.m_TrueRequest, &options);
259 if (NT_SUCCESS(status) && (deviceStatus & USB_GETSTATUS_SELF_POWERED)) {
261 }
262
263 //
264 // Revert back to success b/c we don't care if the usb device get status
265 // fails
266 //
268
270
271 RtlZeroMemory(&busIf, sizeof(busIf));
272
273 //
274 // All PNP irps must have this initial status
275 //
276 request.m_TrueRequest->GetSubmitFxIrp()->Reuse(STATUS_NOT_SUPPORTED);
277 request.m_TrueRequest->ClearFieldsForReuse();
278
280 request.m_TrueRequest->GetSubmitFxIrp()->GetIrp(),
281 &USB_BUS_INTERFACE_USBDI_GUID,
282 (PINTERFACE) &busIf,
283 sizeof(busIf),
285
286 request.m_TrueRequest->VerifierSetFormatted();
287
288 status = SubmitSync(request.m_TrueRequest);
289
290 if (!NT_SUCCESS(status)) {
291 //
292 // Retry with the older interface
293 //
294 RtlZeroMemory(&busIf, sizeof(busIf));
295
296 //
297 // All PNP irps must have this initial status
298 //
299
300 request.m_TrueRequest->GetSubmitFxIrp()->Reuse(STATUS_NOT_SUPPORTED);
301 request.m_TrueRequest->ClearFieldsForReuse();
302
304 request.m_TrueRequest->GetSubmitFxIrp()->GetIrp(),
305 &USB_BUS_INTERFACE_USBDI_GUID,
306 (PINTERFACE) &busIf,
309
310 request.m_TrueRequest->VerifierSetFormatted();
311
312 status = SubmitSync(request.m_TrueRequest);
313 }
314
315 if (NT_SUCCESS(status)) {
316 //
317 // Need to check for NULL b/c we may have only retrieved the V0 interface
318 //
319 if (busIf.IsDeviceHighSpeed != NULL &&
320 busIf.IsDeviceHighSpeed(busIf.BusContext)) {
322 }
323
324 //
325 // Stash these off for later
326 //
330
331 ASSERT(busIf.GetUSBDIVersion != NULL);
332 busIf.GetUSBDIVersion(busIf.BusContext,
335 }
336 else if (status == STATUS_NOT_SUPPORTED) {
337 //
338 // We will only use m_ControlPipe on stacks which do not support
339 // USBD_DEFAULT_PIPE_TRANSFER. If all the QIs failed, then we know
340 // definitively that we are running on USBD and we need m_ControlPipe
341 // to be != NULL for later control transfers
342 //
344
345 m_OnUSBD = TRUE;
346
347 //
348 // The QI failed with not supported, do not return error
349 //
351 }
352 else {
355 "Query Interface for bus returned error, %!STATUS!", status);
356 }
357
358Done:
359
360 return status;
361}
MdDeviceObject m_TargetDevice
Definition: fxiotarget.hpp:910
MdDeviceObject m_InStackDevice
Definition: fxiotarget.hpp:905
#define STATUS_NOT_SUPPORTED
Definition: d3dkmdt.h:48
struct config_s config
static HANDLE PipeHandle
Definition: dhcpcsvc.c:22
static VOID _FormatIrp(__in PIRP Irp, __in const GUID *InterfaceGuid, __out PINTERFACE Interface, __in USHORT InterfaceSize, __in USHORT InterfaceVersion, __in_opt PVOID InterfaceSpecificData=NULL)
struct _URB_CONTROL_DESCRIPTOR_REQUEST UrbControlDescriptorRequest
Definition: usb.h:545
PINTERFACE_DEREFERENCE InterfaceDereference
Definition: usbbusif.h:98
PUSB_BUSIFFN_GETUSBDI_VERSION GetUSBDIVersion
Definition: usbbusif.h:99
PUSB_BUSIFFN_IS_DEVICE_HIGH_SPEED IsDeviceHighSpeed
Definition: usbbusif.h:103
PUSB_BUSIFFN_QUERY_BUS_TIME QueryBusTime
Definition: usbbusif.h:100
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define USB_GETSTATUS_SELF_POWERED
Definition: usb100.h:45
struct _USB_CONFIGURATION_DESCRIPTOR * PUSB_CONFIGURATION_DESCRIPTOR
#define USB_CONFIGURATION_DESCRIPTOR_TYPE
Definition: usb100.h:50
#define USB_DEVICE_DESCRIPTOR_TYPE
Definition: usb100.h:49
#define USB_CONFIG_REMOTE_WAKEUP
Definition: usb100.h:71
struct _USB_DEVICE_DESCRIPTOR USB_DEVICE_DESCRIPTOR
#define URB_FUNCTION_GET_STATUS_FROM_DEVICE
Definition: usb.h:105
#define USB_BUSIF_USBDI_VERSION_1
Definition: usbbusif.h:74
#define USB_BUSIF_USBDI_VERSION_0
Definition: usbbusif.h:73
#define UsbBuildGetStatusRequest(urb, op, index, transferBuffer, transferBufferMDL, link)
Definition: usbdlib.h:35
#define USBD_CLIENT_CONTRACT_VERSION_INVALID
Definition: usbdlib.h:99
NTSTATUS USBD_CreateHandle(_In_ PDEVICE_OBJECT DeviceObject, _In_ PDEVICE_OBJECT TargetDeviceObject, _In_ ULONG USBDClientContractVersion, _In_ ULONG PoolTag, _Out_ USBD_HANDLE *USBDHandle)
Definition: usbstubum.cpp:90
#define WDFCASSERT(c)
Definition: wdfassert.h:93
_Must_inspect_result_ _In_ WDFDEVICE _In_ BOOLEAN _In_opt_ PVOID Tag
Definition: wdfdevice.h:4065
@ WDF_USB_DEVICE_TRAIT_SELF_POWERED
Definition: wdfusb.h:142
@ WDF_USB_DEVICE_TRAIT_AT_HIGH_SPEED
Definition: wdfusb.h:144
@ WDF_USB_DEVICE_TRAIT_REMOTE_WAKE_CAPABLE
Definition: wdfusb.h:143
_Reserved_ PVOID Reserved
Definition: winddi.h:3974

◆ IsConnected()

_Must_inspect_result_ NTSTATUS FxUsbDevice::IsConnected ( VOID  )

Definition at line 1202 of file fxusbdevice.cpp.

1205{
1206#if (FX_CORE_MODE == FX_CORE_USER_MODE)
1207
1208
1209
1210
1211 return STATUS_UNSUCCESSFUL;
1212#elif (FX_CORE_MODE == FX_CORE_KERNEL_MODE)
1214 ULONG portStatus;
1215
1216 status = GetPortStatus(&portStatus);
1217 if (NT_SUCCESS(status) && (portStatus & USBD_PORT_CONNECTED) == 0) {
1219 }
1220
1221 return status;
1222#endif
1223}
_Must_inspect_result_ NTSTATUS GetPortStatus(__out PULONG PortStatus)
#define STATUS_DEVICE_DOES_NOT_EXIST
Definition: ntstatus.h:428
#define USBD_PORT_CONNECTED
Definition: usbioctl.h:42

◆ IsEnabled()

BOOLEAN FxUsbDevice::IsEnabled ( VOID  )

Definition at line 1175 of file fxusbdevice.cpp.

1178{
1180 ULONG portStatus;
1182
1183 enabled = TRUE;
1184 status = GetPortStatus(&portStatus);
1185
1186 //
1187 // Inability to get STATUS_SUCCESS from GetPortStatus is more likely a resource
1188 // issue rather than a device issue so return FALSE from this function only if
1189 // we were able to read the PortStatus and the port was disabled.
1190 // What you don't want is to continuosly reset the device (by returning FALSE)
1191 // instead of resetting pipe (by returning TRUE) under low memory conditions.
1192 //
1193 if (NT_SUCCESS(status) && (portStatus & USBD_PORT_ENABLED) == 0) {
1194 enabled = FALSE;
1195 }
1196
1197 return enabled;
1198}
GLenum GLenum GLsizei const GLuint GLboolean enabled
Definition: glext.h:7750
#define USBD_PORT_ENABLED
Definition: usbioctl.h:41

◆ IsObjectDisposedOnRemove()

BOOLEAN FxUsbDevice::IsObjectDisposedOnRemove ( __in FxObject Object)

Definition at line 2356 of file fxusbdevice.cpp.

2379{
2380 FxObject * obj;
2381 FxObject * parent;
2382 BOOLEAN isObjectDisposedOnRemove = FALSE;
2383
2384 obj = Object;
2385
2386 //
2387 // By adding a reference now, we simulate what GetParentObjectReferenced
2388 // does later, thus allowing simple logic on when/how to release the
2389 // reference on exit.
2390 //
2391 obj->ADDREF(Object);
2392
2393 while (obj != NULL) {
2394
2395 if (obj == (FxObject*) m_Device) {
2396
2397 isObjectDisposedOnRemove = TRUE;
2398 break;
2399 }
2400
2402
2404 if (request->IsAllocatedFromIo()) {
2405
2406 isObjectDisposedOnRemove = TRUE;
2407 break;
2408 }
2409 }
2410
2411 parent = obj->GetParentObjectReferenced(Object);
2412
2413 //
2414 // Release the reference previously taken by the top of the function
2415 // or GetParentObjectReferenced in a previous pass in the loop.
2416 //
2417 obj->RELEASE(Object);
2418 obj = parent;
2419 }
2420
2421 if (obj != NULL) {
2422
2423 //
2424 // Release the reference previously taken by the top of the function
2425 // or GetParentObjectReferenced in a last pass in the loop.
2426 //
2427 obj->RELEASE(Object);
2428 }
2429
2430 return isObjectDisposedOnRemove;
2431}
CfxDevice * m_Device
Definition: fxobject.hpp:329
r parent
Definition: btrfs.c:3010
__inline BOOLEAN FxObjectCheckType(__in FxObject *Object, __in WDFTYPE Type)
Definition: fxhandle.h:240
@ FX_TYPE_REQUEST
Definition: fxtypes.h:53
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object

Referenced by CreateIsochUrb(), CreateUrb(), and GetFxUrbTypeForRequest().

◆ OnUSBD()

BOOLEAN FxUsbDevice::OnUSBD ( VOID  )
inline

Definition at line 361 of file fxusbdevice.hpp.

364 {
365 return m_OnUSBD;
366 }

◆ PipesGotoRemoveState()

VOID FxUsbDevice::PipesGotoRemoveState ( __in BOOLEAN  ForceRemovePipes)
protected

Definition at line 813 of file fxusbdevice.cpp.

816{
817 SINGLE_LIST_ENTRY sentHead;
818 LIST_ENTRY pendHead, interfaceHead;
820 ULONG iPipe, intfIndex;
821 KIRQL irql;
822
823 sentHead.Next = NULL;
824 InitializeListHead(&pendHead);
825 InitializeListHead(&interfaceHead);
826
827 AcquireInterfaceIterationLock();
828
829 Lock(&irql);
830 for (intfIndex = 0; intfIndex < m_NumInterfaces; intfIndex++ ) {
831 pUsbInterface = m_Interfaces[intfIndex];
832
834 for (iPipe = 0;
836 iPipe++) {
837 BOOLEAN wait;
838
839 wait = FALSE;
840
841 //
842 // Pipe can be NULL if the interface is half initialized
843 //
844 if (pUsbInterface->m_ConfiguredPipes[iPipe] != NULL) {
847 &pendHead,
848 &sentHead,
849 TRUE,
850 &wait);
851
852 }
853 }
854 }
855 }
856 Unlock(irql);
857
858 //
859 // We cleanup requests no matter what the new state is because we complete all
860 // pended requests in the surprise removed case.
861 //
862 _CleanupPipesRequests(&pendHead, &sentHead);
863
864 //
865 // Only destroy child pipe objects when the parent is going away or the
866 // caller indicates that this is the desired action.
867 //
868 if (m_State == WdfIoTargetDeleted || ForceRemovePipes) {
869 for (intfIndex = 0; intfIndex < m_NumInterfaces; intfIndex++) {
870 pUsbInterface = m_Interfaces[intfIndex];
871
873 //
874 // Iterate over the pipes and clean each one up
875 //
876 for (iPipe = 0;
878 iPipe++) {
879 //
880 // Same reason as above
881 //
882 if (pUsbInterface->m_ConfiguredPipes[iPipe] != NULL) {
885 }
886 }
887 }
888
890 }
891 }
892
893 ReleaseInterfaceIterationLock();
894}
WDF_IO_TARGET_STATE m_State
Definition: fxiotarget.hpp:928
virtual VOID WaitForSentIoToComplete(VOID)
Definition: fxiotarget.hpp:676
VOID CleanUpAndDelete(__in BOOLEAN ClearDestroyCallback)

Referenced by Deconfig().

◆ Purge()

VOID FxUsbDevice::Purge ( __in WDF_IO_TARGET_PURGE_IO_ACTION  Action)
protectedvirtual

Reimplemented from FxIoTarget.

Definition at line 694 of file fxusbdevice.cpp.

697{
699 SINGLE_LIST_ENTRY sentHead;
700 ULONG iPipe, iInterface;
701 KIRQL irql;
702
703 sentHead.Next = NULL;
704
705 //
706 // Purge all of our own I/O first
707 //
709
710 //
711 // if we are just canceling i/o, then we just acquire the spin lock b/c
712 // we can be called at dispatch level for this action code.
713 //
714 if (Action != WdfIoTargetPurgeIo) {
716
717 AcquireInterfaceIterationLock();
718 }
719
720 //
721 // Since we don't have to synchronize on the I/O already sent, just set
722 // each pipe's state to purged.
723 //
724 Lock(&irql);
725
726 for (iInterface = 0; iInterface < m_NumInterfaces; iInterface++) {
727 pUsbInterface = m_Interfaces[iInterface];
728
730 for (iPipe = 0;
732 iPipe++) {
733
734 if (pUsbInterface->m_ConfiguredPipes[iPipe] != NULL) {
735 BOOLEAN wait;
736 LIST_ENTRY pendedHead;
737
738 wait = FALSE;
739 InitializeListHead(&pendedHead);
740
742 Action,
743 &pendedHead,
744 &sentHead,
745 &wait,
746 TRUE
747 );
748
749 //
750 // Complete any requests pulled off from this pipe.
751 //
753 CompletePendedRequestList(&pendedHead);
754 }
755 }
756 }
757 }
758 Unlock(irql);
759
760 //
761 // Cancel all sent requests.
762 //
763 _CancelSentRequests(&sentHead);
764
765 for (iInterface = 0; iInterface < m_NumInterfaces; iInterface++) {
766 pUsbInterface = m_Interfaces[iInterface];
767
769 //
770 // Iterate over the pipes and clean each one up
771 //
772 for (iPipe = 0;
774 iPipe++) {
775 //
776 // Same reason as above
777 //
778 if (pUsbInterface->m_ConfiguredPipes[iPipe] != NULL) {
781 }
782 }
783 }
784 }
785
786 if (Action != WdfIoTargetPurgeIo) {
787 ReleaseInterfaceIterationLock();
788 }
789}
VOID CompletePendedRequestList(__in PLIST_ENTRY RequestListHead)
Definition: fxiotarget.cpp:520
virtual VOID Purge(__in WDF_IO_TARGET_PURGE_IO_ACTION Action)
Definition: fxiotarget.cpp:918
VOID GotoPurgeState(__in WDF_IO_TARGET_PURGE_IO_ACTION Action, __in PLIST_ENTRY PendedRequestListHead, __in PSINGLE_LIST_ENTRY SentRequestListHead, __out PBOOLEAN Wait, __in BOOLEAN LockSelf)
Definition: fxusbpipe.cpp:1294
static __inline KIRQL MxGetCurrentIrql()
Definition: mxgeneralkm.h:86
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
_In_ WDFIOTARGET _In_ _Strict_type_match_ WDF_IO_TARGET_SENT_IO_ACTION Action
Definition: wdfiotarget.h:510
@ WdfIoTargetPurgeIo
Definition: wdfiotarget.h:79

◆ QueryUsbCapability()

Definition at line 755 of file fxusbdevicekm.cpp.

768{
770
771 if (ResultLength != NULL) {
772 *ResultLength = 0;
773 }
774
775 if (GetUSBDHandle() == NULL) {
777
780 "WDFUSBDEVICE must have been created using WdfUsbTargetDeviceCreateWithParameters, %!STATUS!",
781 status);
782
783 return status;
784 }
785
789 (PUCHAR) CapabilityBuffer,
791
792 if (!NT_SUCCESS(status)) {
795 "Could not retrieve capability %!GUID!, %!STATUS!",
797 goto exit;
798 }
799
800exit:
801 return status;
802}
USBD_HANDLE GetUSBDHandle(VOID)
#define exit(n)
Definition: config.h:202
unsigned char * PUCHAR
Definition: typedefs.h:53
#define STATUS_INVALID_DEVICE_STATE
Definition: udferr_usr.h:178
NTSTATUS USBD_QueryUsbCapability(_In_ USBD_HANDLE USBDHandle, _In_ const GUID *CapabilityType, _In_ ULONG OutputBufferLength, _When_(OutputBufferLength==0, _Pre_null_) _When_(OutputBufferLength !=0 &&ResultLength==NULL, _Out_writes_bytes_(OutputBufferLength)) _When_(OutputBufferLength !=0 &&ResultLength !=NULL, _Out_writes_bytes_to_opt_(OutputBufferLength, *ResultLength)) PUCHAR OutputBuffer, _Out_opt_ _When_(ResultLength !=NULL, _Deref_out_range_(<=, OutputBufferLength)) PULONG ResultLength)
Definition: usbstubum.cpp:111
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG _Out_ PULONG ResultLength
Definition: wdfdevice.h:3776
_Must_inspect_result_ _In_ WDFUSBDEVICE _In_ CONST GUID _In_ ULONG CapabilityBufferLength
Definition: wdfusb.h:1615
_Must_inspect_result_ _In_ WDFUSBDEVICE _In_ CONST GUID * CapabilityType
Definition: wdfusb.h:1613

◆ RemoveDeletedInterface()

VOID FxUsbDevice::RemoveDeletedInterface ( __in FxUsbInterface Interface)
protected

Definition at line 462 of file fxusbdevice.cpp.

465{
466 UCHAR i;
467
468 if (m_Interfaces == NULL) {
469 return;
470 }
471
472 for (i = 0; i < m_NumInterfaces; i++) {
473 if (m_Interfaces[i] == Interface) {
475 return;
476 }
477 }
478}
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID _Out_ PINTERFACE Interface
Definition: wdffdo.h:465

Referenced by FxUsbInterface::~FxUsbInterface().

◆ Reset()

_Must_inspect_result_ NTSTATUS FxUsbDevice::Reset ( VOID  )

Definition at line 1075 of file fxusbdevicekm.cpp.

1078{
1080 FxSyncRequest request(GetDriverGlobals(), &context);
1081 FxRequestBuffer emptyBuffer;
1083
1084 //
1085 // FxSyncRequest always succeesds for KM.
1086 //
1087 status = request.Initialize();
1088 if (!NT_SUCCESS(status)) {
1090 "Failed to initialize FxSyncRequest");
1091 return status;
1092 }
1093
1094 status = FormatIoctlRequest(request.m_TrueRequest,
1096 TRUE,
1097 &emptyBuffer,
1098 &emptyBuffer);
1099 if (NT_SUCCESS(status)) {
1100 CancelSentIo();
1102 }
1103
1104 return status;
1105}
#define IOCTL_INTERNAL_USB_RESET_PORT
Definition: usbioctl.h:35

◆ SelectConfig()

_Must_inspect_result_ NTSTATUS FxUsbDevice::SelectConfig ( __in PWDF_OBJECT_ATTRIBUTES  PipesAttributes,
__in PURB  Urb,
__in FX_URB_TYPE  FxUrbType,
__out_opt PUCHAR  NumConfiguredInterfaces 
)

Definition at line 1424 of file fxusbdevice.cpp.

1446{
1448 PUCHAR pCur, pEnd;
1450 FxUsbPipe* pPipe;
1451 PURB pSelectUrb;
1453 ULONG iPipe;
1454 USHORT maxNumPipes, size;
1455 UCHAR numPipes;
1456 FxInterfacePipeInformation* pPipeInfo;
1459 UCHAR intfIndex;
1460 FxIrp* irp;
1461
1463 FxSyncRequest request(GetDriverGlobals(), NULL);
1464
1465 pIface = NULL;
1466 maxNumPipes = 0;
1467 size = 0;
1468 pPipeInfo = NULL;
1469 pSelectUrb = NULL;
1470
1471 //
1472 // Callers to this function have guaranteed that there are interfaces
1473 // reported on this device.
1474 //
1475 ASSERT(m_NumInterfaces != 0);
1476
1477 if (NumConfiguredInterfaces != NULL) {
1478 *NumConfiguredInterfaces = 0;
1479 }
1480
1481 //
1482 // FxSyncRequest always succeesds for KM but can fail for UM.
1483 //
1484 status = request.Initialize();
1485 if (!NT_SUCCESS(status)) {
1487 "Failed to initialize FxSyncRequest");
1488 goto Done;
1489 }
1490
1491 //
1492 // Allocate a PIRP for the select config and possible select interface(s)
1493 //
1494 status = request.m_TrueRequest->ValidateTarget(this);
1495 if (!NT_SUCCESS(status)) {
1496 goto Done;
1497 }
1498
1499 //
1500 // Allocate a pool for storing the FxUsbPipe ** before we
1501 // assign them to the Interfaces just in case all doesn't go well.
1502 //
1503 if (m_NumInterfaces == 0) {
1504 //
1505 // Use one in the zero case to make the logic simpler
1506 //
1508 }
1509 else {
1511 }
1512
1513 pPipeInfo = (FxInterfacePipeInformation*) FxPoolAllocate(
1515 );
1516
1517 if (pPipeInfo == NULL) {
1521 "Could not internal allocate tracking info for selecting a config on "
1522 "WDFUSBDEVICE 0x%p, %!STATUS!", GetHandle(), status);
1523 goto Done;
1524 }
1525
1526 RtlZeroMemory(pPipeInfo, size);
1527
1528 //
1529 // The following code and the one in select setting have a lot in common
1530 // but can't leverage on that as that sends the select interface URB down
1531 // Our goal is allocate the resources -- the pipes and the select setting URB
1532 // before sending down the select config URB so that the tear down is simpler.
1533 //
1534
1535 //
1536 // Each FxUsbInterface will need a FxUsbPipe* for each pipe contained in
1537 // the interface.
1538 //
1539 pCur = (PUCHAR) &Urb->UrbSelectConfiguration.Interface;
1540 pEnd = ((PUCHAR) Urb) + Urb->UrbSelectConfiguration.Hdr.Length;
1541 intfIndex = 0;
1542
1543 for ( ; pCur < pEnd; pCur += pIface->Length, intfIndex++) {
1544 FxUsbPipe** ppPipes;
1545
1547 if (pIface->NumberOfPipes > UCHAR_MAX) {
1551 "WDFUSBDEVICE supports a maximum of %d pipes per interface, "
1552 "USBD_INTERFACE_INFORMATION %p specified %d, %!STATUS!",
1553 UCHAR_MAX, pIface, pIface->NumberOfPipes, status);
1554 goto Done;
1555 }
1556
1558 if (pUsbInterface == NULL) {
1562 "Could not find an instance of an interface descriptor with "
1563 "InterfaceNumber %d, %!STATUS!",
1564 pIface->InterfaceNumber, status);
1565 goto Done;
1566 }
1567
1568 numPipes = (UCHAR) pIface->NumberOfPipes;
1569
1570 //
1571 // Track the maximum number of pipes we have seen in an interface in
1572 // case we need to allocate a select interface URB.
1573 //
1574 if (numPipes > maxNumPipes) {
1575 maxNumPipes = (USHORT) numPipes;
1576 }
1577
1578 if (numPipes > 0) {
1579 size = numPipes * sizeof(FxUsbPipe *);
1580 }
1581 else {
1582 //
1583 // It is valid to have an interface with zero pipes in it. In that
1584 // case, we just allocate one entry so that we have a valid array
1585 // and keep the remaining code simple.
1586 //
1587 size = sizeof(FxUsbPipe*);
1588 }
1589
1590 ppPipes = (FxUsbPipe**) FxPoolAllocate(
1593 size
1594 );
1595
1596 if (ppPipes == NULL) {
1600 "Could not allocate memory for Pipes "
1601 "InterfaceNumber %d, %!STATUS!",
1602 pIface->InterfaceNumber, status);
1603 goto Done;
1604 }
1605
1606 RtlZeroMemory(ppPipes, size);
1607
1608 //
1609 // We store the pointer to the newly allocated arary in a temporary b/c
1610 // we can still fail and we don't want a half baked interface.
1611 //
1612
1613 pPipeInfo[intfIndex].Pipes = ppPipes;
1614 pPipeInfo[intfIndex].NumPipes = numPipes;
1615
1616 for (iPipe = 0; iPipe < numPipes; iPipe++) {
1617 ppPipes[iPipe] = new (GetDriverGlobals(), PipesAttributes)
1619
1620 if (ppPipes[iPipe] == NULL) {
1624 "Could not allocate a pipe object, %!STATUS!", status);
1625 goto Done;
1626 }
1627
1628 pPipe = ppPipes[iPipe];
1629 status = pPipe->Init(m_Device);
1630 if (!NT_SUCCESS(status)) {
1633 "Could not Init the pipe object, %!STATUS!", status);
1634 goto Done;
1635 }
1636
1638 if (!NT_SUCCESS(status)) {
1641 "Could not commit the pipe object, %!STATUS!", status);
1642 goto Done;
1643 }
1644 }
1645
1646
1647
1648
1649
1650
1651
1652
1653
1656 }
1657 }
1658
1659 //
1660 // If we are selecting more then one interface and at least one of them
1661 // has pipes in them, allocate a select interface URB that will be used
1662 // after the select config to select each interface. The select interface
1663 // URB will be big enough to select the largest interface in the group.
1664 //
1665 // The select interface URB is allocated before the select config so that
1666 // we know once the select config has completed successfully, we can be
1667 // guaranteed that we can select the interfaces we want and not have to
1668 // handle undoing the select config upon URB allocation failure.
1669 //
1670 if (m_NumInterfaces > 1 && maxNumPipes > 0) {
1672
1673 pSelectUrb = (PURB) FxPoolAllocate(GetDriverGlobals(),
1675 size
1676 );
1677
1678 if (pSelectUrb == NULL) {
1682 "Could not allocate a select interface URB, %!STATUS!", status);
1683 goto Done;
1684 }
1685
1686 RtlZeroMemory(pSelectUrb, size);
1687 }
1688
1689 //
1690 // Send the select config to the usb core
1691 //
1695
1696 FxFormatUsbRequest(request.m_TrueRequest, Urb, FxUrbType, m_USBDHandle);
1697 status = SubmitSync(request.m_TrueRequest, &options);
1698
1699 if (NT_SUCCESS(status)) {
1700 //
1701 // Save the config handle and store off all the pipes
1702 //
1703 m_ConfigHandle = Urb->UrbSelectConfiguration.ConfigurationHandle;
1704
1705 //
1706 // Initialize the first interface
1707 //
1708 pIface = &Urb->UrbSelectConfiguration.Interface;
1709
1712
1713 //
1714 // The interface now owns the array of pipes
1715 //
1716 pUsbInterface->SetConfiguredPipes(pPipeInfo[0].Pipes);
1717 pPipeInfo[0].Pipes = NULL;
1718 pPipeInfo[0].NumPipes = 0;
1719
1720 pUsbInterface->SetInfo(pIface);
1721
1722 //
1723 // Since this could be the only interface, set the index now, so if we
1724 // return the number of configured interfaces, it will be valid for the
1725 // single interface case.
1726 //
1727 intfIndex = 1;
1728
1729 //
1730 // If we have a more then one interface, we must select each of the addtional
1731 // interfaces after the select config because usbccgp (the generic parent
1732 // driver) didn't fill out all of the pipe info for IAD (interface
1733 // association descriptor) devices. The first interface is filled out
1734 // property, it is 2->N that are left blank.
1735 //
1736 // pSelectUrb can be equal to NULL and have more then one interface if
1737 // all interfaces have no pipes associated with them. In that case, we
1738 // still want to iterate over the remaining pipes so that we can
1739 // initialize our structures properly.
1740 //
1741 if (m_NumInterfaces > 1) {
1742 //
1743 // Loop over the interfaces again.
1744 //
1745 pCur = (PUCHAR) &Urb->UrbSelectConfiguration.Interface;
1747 pEnd = ((PUCHAR) Urb) + Urb->UrbSelectConfiguration.Hdr.Length;
1748
1749 //
1750 // Start at the 2nd one since the first is already selected
1751 //
1752 pCur += pIface->Length;
1753
1754 for ( ; pCur < pEnd; pCur += pIface->Length, intfIndex++) {
1755#pragma prefast(suppress: __WARNING_UNUSED_POINTER_ASSIGNMENT, "pIface is used in the for loop in many places. It looks like a false positive")
1757 ASSERT(pIface->NumberOfPipes <= maxNumPipes);
1758
1761
1762 //
1763 // Valid to have an interface with no pipes. If there are no
1764 // pipes, GET_SELECT_INTERFACE_REQUEST_SIZE will compute value
1765 // too small of a size to pass validation.
1766 //
1767 if (pIface->NumberOfPipes > 0) {
1768
1770 pSelectUrb,
1771 (USHORT) pIface->NumberOfPipes,
1772 pIface->AlternateSetting
1773 );
1774 irp = request.m_TrueRequest->GetSubmitFxIrp();
1776
1777 request.m_TrueRequest->ClearFieldsForReuse();
1778 FxFormatUsbRequest(request.m_TrueRequest,
1779 pSelectUrb,
1781 NULL);
1782
1783 status = SubmitSync(request.m_TrueRequest, &options);
1784 if (!NT_SUCCESS(status)) {
1787 "USB core failed Select Interface URB, %!STATUS!",
1788 status);
1789 goto Done;
1790 }
1791
1792 //
1793 // Copy the info back into the original select config URB
1794 //
1795
1796 RtlCopyMemory(pIface,
1797 &pSelectUrb->UrbSelectInterface.Interface,
1798 pSelectUrb->UrbSelectInterface.Interface.Length);
1799 }
1800
1801 //
1802 // Update the pointer to point to the new pipes with the pointer
1803 // to the pipes stored earlier.
1804 //
1805 ASSERT(pPipeInfo[intfIndex].NumPipes == pIface->NumberOfPipes);
1807
1808 //
1809 // The interface now owns the array of pipes
1810 //
1811 pUsbInterface->SetConfiguredPipes(pPipeInfo[intfIndex].Pipes);
1812 pPipeInfo[intfIndex].Pipes = NULL;
1813 pPipeInfo[intfIndex].NumPipes = 0;
1814
1815 //
1816 // SetInfo only after a successful select config so that we can
1817 // copy the USBD_PIPE_INFORMATION .
1818 //
1819 pUsbInterface->SetInfo(pIface);
1820 }
1821 }
1822
1823 if (NumConfiguredInterfaces != NULL) {
1824 *NumConfiguredInterfaces = intfIndex;
1825 }
1826 }
1827 else {
1830 "USB core failed Select Configuration, %!STATUS!", status);
1831 }
1832
1833Done:
1834 if (pSelectUrb != NULL) {
1835 FxPoolFree(pSelectUrb);
1836 pSelectUrb = NULL;
1837 }
1838
1839 if (pPipeInfo != NULL) {
1840 //
1841 // Free all arrays that may have been allocated
1842 //
1843 for (intfIndex = 0; intfIndex < m_NumInterfaces; intfIndex++) {
1844 //
1845 // We can have NumPipes == 0 and still have an allocated array, so
1846 // use the array != NULL as the check.
1847 //
1848 if (pPipeInfo[intfIndex].Pipes != NULL) {
1849 //
1850 // Delete any pipes that might have been created
1851 //
1852 for (iPipe = 0; iPipe < pPipeInfo[intfIndex].NumPipes; iPipe++) {
1853 if (pPipeInfo[intfIndex].Pipes[iPipe] != NULL) {
1854 pPipeInfo[intfIndex].Pipes[iPipe]->DeleteFromFailedCreate();
1855 pPipeInfo[intfIndex].Pipes[iPipe] = NULL;
1856 }
1857 }
1858
1859 //
1860 // Now free the array itself and clear out the count
1861 //
1862 FxPoolFree(pPipeInfo[intfIndex].Pipes);
1863 pPipeInfo[intfIndex].Pipes = NULL;
1864 pPipeInfo[intfIndex].NumPipes = 0;
1865 }
1866 }
1867
1868 FxPoolFree(pPipeInfo);
1869 pPipeInfo = NULL;
1870 }
1871
1872 return status;
1873}
_Must_inspect_result_ NTSTATUS Init(__in CfxDeviceBase *Device)
Definition: fxirp.hpp:28
VOID Reuse(__in NTSTATUS Status=STATUS_SUCCESS)
Definition: fxirpum.cpp:661
VOID CleanupInterfacePipesAndDelete(__in FxUsbInterface *UsbInterface)
friend FxUsbPipe
FxUsbInterface * GetInterfaceFromNumber(__in UCHAR InterfaceNumber)
VOID FormatSelectSettingUrb(__in_bcount(GET_SELECT_INTERFACE_REQUEST_SIZE(NumEndpoints)) PURB Urb, __in USHORT NumEndpoints, __in UCHAR SettingNumber)
VOID SetConfiguredPipes(__in FxUsbPipe **ppPipes)
BOOLEAN IsInterfaceConfigured(VOID)
VOID SetInfo(__in PUSBD_INTERFACE_INFORMATION Interface)
VOID SetNumConfiguredPipes(__in UCHAR NumberOfPipes)
SINGLE_LIST_ENTRY * pCur
FxIrp * irp
if(dx< 0)
Definition: linetemp.h:194
#define for
Definition: utility.h:88
struct _URB_SELECT_INTERFACE UrbSelectInterface
Definition: usb.h:532
struct _USBD_INTERFACE_INFORMATION * PUSBD_INTERFACE_INFORMATION
#define GET_SELECT_INTERFACE_REQUEST_SIZE(totalPipes)
Definition: usbdlib.h:117
_Must_inspect_result_ _In_ WDFUSBINTERFACE _In_opt_ PWDF_OBJECT_ATTRIBUTES PipesAttributes
Definition: wdfusb.h:2390

Referenced by SelectConfigDescriptor(), SelectConfigInterfaces(), SelectConfigMulti(), and SelectConfigSingle().

◆ SelectConfigAuto()

_Must_inspect_result_ NTSTATUS FxUsbDevice::SelectConfigAuto ( __in PWDF_OBJECT_ATTRIBUTES  PipeAttributes)

◆ SelectConfigDescriptor()

_Must_inspect_result_ NTSTATUS FxUsbDevice::SelectConfigDescriptor ( __in PWDF_OBJECT_ATTRIBUTES  PipeAttributes,
__in PWDF_USB_DEVICE_SELECT_CONFIG_PARAMS  Params 
)

Definition at line 1317 of file fxusbdevice.cpp.

1321{
1322 PUSBD_INTERFACE_LIST_ENTRY pInterfaces;
1323 PURB urb;
1325 ULONG i, size;
1326 PUSB_CONFIGURATION_DESCRIPTOR configurationDescriptor;
1327 PUSB_INTERFACE_DESCRIPTOR* interfaceDescriptors;
1328 ULONG numInterfaces;
1330
1332
1333 configurationDescriptor = Params->Types.Descriptor.ConfigurationDescriptor;
1334 interfaceDescriptors = Params->Types.Descriptor.InterfaceDescriptors;
1335 numInterfaces = Params->Types.Descriptor.NumInterfaceDescriptors;
1336
1337 for (i = 0; i < numInterfaces; i++) {
1338 if (interfaceDescriptors[i] == NULL) {
1340 }
1341 }
1342
1343 //
1344 // eventually size = sizeof(USBD_INTERFACE_LIST_ENTRY) * (numInterfaces + 1)
1345 //
1346 status = RtlULongAdd(numInterfaces, 1, &size);
1347 if (!NT_SUCCESS(status)) {
1348 return status;
1349 }
1350
1351 status = RtlULongMult(size, sizeof(USBD_INTERFACE_LIST_ENTRY), &size);
1352 if (!NT_SUCCESS(status)) {
1353 return status;
1354 }
1355
1356 pInterfaces = (PUSBD_INTERFACE_LIST_ENTRY) FxPoolAllocate(
1358
1359 if (pInterfaces == NULL) {
1361
1364 "Could not allocate array of USBD_INTERFACE_LIST_ENTRY, %!STATUS!",
1365 status);
1366
1367 return status;
1368 }
1369
1370 RtlZeroMemory(pInterfaces, size);
1371
1372 for (i = 0; i < numInterfaces; i++) {
1373 pInterfaces[i].InterfaceDescriptor = interfaceDescriptors[i];
1374 }
1375
1376 if (configurationDescriptor == NULL) {
1377 configurationDescriptor = m_ConfigDescriptor;
1378 }
1379
1380 //
1381 // NOTE:
1382 //
1383 // Creating a config request using the caller's config descriptor does not
1384 // currently work if the provided config descriptor is not the same as the
1385 // descriptor reported by the device. It does not work because we try to
1386 // validate the interface number in the URB against an existing
1387 // FxUsbInterface (which is based on the config descriptor described by the
1388 // device, not the provided one), and if that validation fails, we return
1389 // !NT_SUCCESS from SelectConfig().
1390 //
1392 configurationDescriptor,
1393 pInterfaces,
1395 if (urb == NULL) {
1397 }
1398 else {
1400 FxPoolFree(urb);
1401 urb = NULL;
1402 }
1403
1404 FxPoolFree(pInterfaces);
1405 pInterfaces = NULL;
1406
1407 return status;
1408}
_Must_inspect_result_ NTSTATUS SelectConfig(__in PWDF_OBJECT_ATTRIBUTES PipesAttributes, __in PURB Urb, __in FX_URB_TYPE FxUrbType, __out_opt PUCHAR NumConfiguredInterfaces)
ULONG GetDefaultMaxTransferSize(VOID)
Definition: usbdlib.h:7
PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor
Definition: usbdlib.h:8
struct _USBD_INTERFACE_LIST_ENTRY * PUSBD_INTERFACE_LIST_ENTRY
PURB FxUsbCreateConfigRequest(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PUSB_CONFIGURATION_DESCRIPTOR ConfigDesc, __in PUSBD_INTERFACE_LIST_ENTRY InterfaceList, __in ULONG DefaultMaxPacketSize)
Definition: usbutil.cpp:364
_In_ WDFIOTARGET _In_ PWDF_REQUEST_COMPLETION_PARAMS Params
Definition: wdfrequest.h:308

◆ SelectConfigInterfaces()

_Must_inspect_result_ NTSTATUS FxUsbDevice::SelectConfigInterfaces ( __in PWDF_OBJECT_ATTRIBUTES  PipesAttributes,
__in PUSB_CONFIGURATION_DESCRIPTOR  ConfigurationDescriptor,
__in_ecount(NumInterfaces) PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptors,
__in ULONG  NumInterfaces 
)

Definition at line 1924 of file fxusbdevice.cpp.

1930{
1931 PUSBD_INTERFACE_LIST_ENTRY pInterfaces;
1932 PURB urb;
1934 ULONG i, size;
1936
1938
1939 //
1940 // eventually size = sizeof(USBD_INTERFACE_LIST_ENTRY) * (NumInterfaces + 1)
1941 //
1942 status = RtlULongAdd(NumInterfaces, 1, &size);
1943 if (!NT_SUCCESS(status)) {
1944 return status;
1945 }
1946
1947 status = RtlULongMult(size, sizeof(USBD_INTERFACE_LIST_ENTRY), &size);
1948 if (!NT_SUCCESS(status)) {
1949 return status;
1950 }
1951
1952 for (i = 0; i < NumInterfaces; i++) {
1953 if (InterfaceDescriptors[i] == NULL) {
1955 }
1956 }
1957
1958 pInterfaces = (PUSBD_INTERFACE_LIST_ENTRY) FxPoolAllocate(
1961 size
1962 );
1963
1964 if (pInterfaces == NULL) {
1966
1969 "Could not allocate array of USBD_INTERFACE_LIST_ENTRY, %!STATUS!",
1970 status);
1971
1972 return status;
1973 }
1974
1975 RtlZeroMemory(pInterfaces, size);
1976
1977 for (i = 0; i < NumInterfaces; i++) {
1978 pInterfaces[i].InterfaceDescriptor = InterfaceDescriptors[i];
1979 }
1980
1981 if (ConfigurationDescriptor == NULL) {
1982 ConfigurationDescriptor = m_ConfigDescriptor;
1983 }
1984
1986 ConfigurationDescriptor,
1987 pInterfaces,
1989 if (urb == NULL) {
1991 }
1992 else {
1994 FxPoolFree(urb);
1995 urb = NULL;
1996 }
1997
1998 FxPoolFree(pInterfaces);
1999 pInterfaces = NULL;
2000
2001 return status;
2002}

◆ SelectConfigMulti()

_Must_inspect_result_ NTSTATUS FxUsbDevice::SelectConfigMulti ( __in PWDF_OBJECT_ATTRIBUTES  PipeAttributes,
__in PWDF_USB_DEVICE_SELECT_CONFIG_PARAMS  Params 
)

Definition at line 898 of file fxusbdevicekm.cpp.

918{
920 PURB urb;
922 ULONG size;
923 UCHAR i;
925
927
928 Params->Types.MultiInterface.NumberOfConfiguredInterfaces = 0;
929
930 //
931 // The array needs an extra element which is zero'd out to mark the end
932 //
934 pList = (PUSBD_INTERFACE_LIST_ENTRY) FxPoolAllocate(
937 size
938 );
939
940 if (pList == NULL) {
942 }
943
945
947 for (i = 0; i < m_NumInterfaces; i++) {
948 pList[i].InterfaceDescriptor =
950
954 "WDFUSBDEVICE %p could not retrieve AlternateSetting 0 for "
955 "bInterfaceNumber %d", GetHandle(),
956 m_Interfaces[i]->m_InterfaceNumber);
957
959 goto Done;
960 }
961 }
962 }
963 else {
964 //
965 // Type is WdfUsbTargetDeviceSelectConfigTypeInterfacesPairs
966 //
967 UCHAR interfacePairsNum = 0;
968 UCHAR bitArray[UCHAR_MAX/sizeof(UCHAR)];
969
970 //
971 // initialize the bit array
972 //
973 RtlZeroMemory(bitArray, sizeof(bitArray));
974 //
975 // Build a list of descriptors from the Setting pairs
976 // passed in by the user. There could be interfaces not
977 // covered in the setting/interface pairs array passed.
978 // If that is the case return STATUS_INVALID_PARAMETER
979 //
980 for (i = 0; i < Params->Types.MultiInterface.NumberInterfaces ; i++) {
982 UCHAR interfaceNumber;
983 UCHAR altSettingIndex;
984
985 settingPair = &Params->Types.MultiInterface.Pairs[i];
986
988 settingPair->UsbInterface,
989 &interfaceNumber
990 );
991
992 //
993 //convert the interface handle to interface number
994 //
995 if (NT_SUCCESS(status)) {
996 altSettingIndex = settingPair->SettingIndex;
997
998 //
999 // do the following only if the bit is not already set
1000 //
1001 if (FxBitArraySet(&bitArray[0], interfaceNumber) == FALSE) {
1002 pList[interfacePairsNum].InterfaceDescriptor =
1005 interfaceNumber,
1006 altSettingIndex
1007 );
1008
1009 if (pList[interfacePairsNum].InterfaceDescriptor == NULL) {
1014 "WDFUSBDEVICE %p could not retrieve "
1015 "AlternateSetting %d for "
1016 "bInterfaceNumber %d, returning %!STATUS!",
1017 GetHandle(),
1018 altSettingIndex, interfaceNumber, status);
1019 goto Done;
1020 }
1021
1022 interfacePairsNum++;
1023 }
1024 }
1025 else {
1026 goto Done;
1027 }
1028 }
1029
1030 //
1031 // Check if there are any interfaces not specified by the array. If
1032 // there are, then select setting 0 for them.
1033 //
1034 if (m_NumInterfaces > interfacePairsNum) {
1038 "WDFUSBDEVICE %p interface pairs set (%d) is not equal to actual "
1039 "# of interfaces (%d) reported by the device, %!STATUS!",
1040 GetObjectHandle(), interfacePairsNum, m_NumInterfaces, status);
1041 goto Done;
1042 }
1043 } //WdfUsbTargetDeviceSelectConfigTypeInterfacesPairs
1044
1048 pList,
1050 );
1051
1052 if (urb == NULL) {
1054 }
1055 else {
1058 urb,
1060 &Params->Types.MultiInterface.NumberOfConfiguredInterfaces);
1061
1062 FxPoolFree(urb);
1063 urb = NULL;
1064 }
1065
1066Done:
1068 pList = NULL;
1069
1070 return status;
1071}
_Must_inspect_result_ NTSTATUS GetInterfaceNumberFromInterface(__in WDFUSBINTERFACE UsbInterface, __out PUCHAR InterfaceNumber)
PUSB_INTERFACE_DESCRIPTOR GetSettingDescriptor(__in UCHAR Setting)
FxChildList * pList
return pObject GetObjectHandle()
WDFUSBINTERFACE UsbInterface
Definition: wdfusb.h:522
struct _USBD_INTERFACE_LIST_ENTRY USBD_INTERFACE_LIST_ENTRY
PUSB_INTERFACE_DESCRIPTOR FxUsbParseConfigurationDescriptor(__in PUSB_CONFIGURATION_DESCRIPTOR ConfigDesc, __in UCHAR InterfaceNumber, __in UCHAR AlternateSetting)
Definition: usbutil.cpp:307
_In_ WDFUSBINTERFACE _In_ UCHAR _Out_ PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor
Definition: wdfusb.h:2334
@ WdfUsbTargetDeviceSelectConfigTypeMultiInterface
Definition: wdfusb.h:129

◆ SelectConfigSingle()

_Must_inspect_result_ NTSTATUS FxUsbDevice::SelectConfigSingle ( __in PWDF_OBJECT_ATTRIBUTES  PipeAttributes,
__in PWDF_USB_DEVICE_SELECT_CONFIG_PARAMS  Params 
)

Definition at line 806 of file fxusbdevicekm.cpp.

830{
831 //
832 // The array needs an extra element which is zero'd out to mark the end
833 //
834 USBD_INTERFACE_LIST_ENTRY listEntry[2];
835 PURB urb;
837
838 RtlZeroMemory(&Params->Types.SingleInterface,
839 sizeof(Params->Types.SingleInterface));
840
841 if (m_NumInterfaces > 1) {
843
846 "WDFUSBDEVICE %p cannot be auto configured for a single interface "
847 "since there are %d interfaces on the device, %!STATUS!",
849
850 return status;
851 }
852
853 RtlZeroMemory(&listEntry[0], sizeof(listEntry));
854
855 //
856 // Use AlternateSetting 0 by default
857 //
859
860 if (listEntry[0].InterfaceDescriptor == NULL) {
863 "WDFUSBDEVICE %p could not retrieve AlternateSetting 0 for "
864 "bInterfaceNumber %d", GetHandle(),
865 m_Interfaces[0]->m_InterfaceNumber);
866
868 }
869
872 &listEntry[0],
874
875 if (urb == NULL) {
877 }
878 else {
880
881 if (NT_SUCCESS(status)) {
882 Params->Types.SingleInterface.NumberConfiguredPipes =
884
885 Params->Types.SingleInterface.ConfiguredUsbInterface =
887 }
888
889 FxPoolFree(urb);
890 urb = NULL;
891 }
892
893 return status;
894}
WDFUSBINTERFACE GetHandle(VOID)
UCHAR GetNumConfiguredPipes(VOID)
_Must_inspect_result_ _In_ WDFUSBDEVICE _In_opt_ PWDF_OBJECT_ATTRIBUTES PipeAttributes
Definition: wdfusb.h:1242

◆ SelectInterface()

_Must_inspect_result_ NTSTATUS FxUsbDevice::SelectInterface ( __in PWDF_OBJECT_ATTRIBUTES  PipesAttributes,
__in PURB  Urb 
)

◆ SelectInterfaceByInterface()

_Must_inspect_result_ NTSTATUS FxUsbDevice::SelectInterfaceByInterface ( __in PWDF_OBJECT_ATTRIBUTES  PipesAttributes,
__in PUSB_INTERFACE_DESCRIPTOR  InterfaceDescriptor 
)

◆ SendSyncRequest()

_Must_inspect_result_ NTSTATUS FxUsbDevice::SendSyncRequest ( __in FxSyncRequest *  Request,
__in ULONGLONG  Time 
)
protected

Definition at line 31 of file fxusbdeviceum.cpp.

35{
38
41
42 status = SubmitSync(Request->m_TrueRequest, &options);
43 if (!NT_SUCCESS(status)) {
45 "FxUsbDevice SubmitSync failed");
46 goto Done;
47 }
48
49Done:
50 return status;
51}
static PLARGE_INTEGER Time
Definition: time.c:105

◆ SendSyncUmUrb()

_Must_inspect_result_ NTSTATUS FxUsbDevice::SendSyncUmUrb ( __inout PUMURB  Urb,
__in ULONGLONG  Time,
__in_opt WDFREQUEST  Request = NULL,
__in_opt PWDF_REQUEST_SEND_OPTIONS  Options = NULL 
)
protected

Definition at line 55 of file fxusbdeviceum.cpp.

61{
64 FxSyncRequest request(GetDriverGlobals(), NULL, Request);
65
66 status = request.Initialize();
67 if (!NT_SUCCESS(status)) {
69 "Failed to initialize FxSyncRequest");
70 return status;
71 }
72
73 if (NULL == Options) {
75 }
76
79
80 status = request.m_TrueRequest->ValidateTarget(this);
81 if (NT_SUCCESS(status)) {
82 FxUsbUmFormatRequest(request.m_TrueRequest, &Urb->UmUrbHeader, m_pHostTargetFile);
83 status = SubmitSync(request.m_TrueRequest, Options);
84 if (!NT_SUCCESS(status)) {
86 "FxUsbDevice SubmitSync failed");
87 return status;
88 }
89 }
90
91 return status;
92}
VOID FxUsbUmFormatRequest(__in FxRequestBase *Request, __in_xcount(Urb->Length) PUMURB_HEADER Urb, __in IWudfFile *HostFile, __in BOOLEAN Reuse)
Definition: usbutil.cpp:486

Referenced by FxUsbInterface::MakeAndConfigurePipes(), FxUsbInterface::SelectSettingByIndex(), and FxUsbInterface::SetWinUsbHandle().

◆ Start()

_Must_inspect_result_ NTSTATUS FxUsbDevice::Start ( VOID  )
protectedvirtual

Reimplemented from FxIoTarget.

Definition at line 530 of file fxusbdevice.cpp.

533{
535
537
538 if (NT_SUCCESS(status)) {
541 ULONG i, iInterface;
543 KIRQL irql;
544
546
547 Lock(&irql);
548
549 //
550 // Iterate over all of the interfaces. For each pipe on each interface,
551 // grab all pended i/o for later submission.
552 //
553 for (iInterface = 0; iInterface < m_NumInterfaces; iInterface++){
554
555 pUsbInterface = m_Interfaces[iInterface];
556
557 for (i = 0; i < pUsbInterface->m_NumberOfConfiguredPipes; i++) {
559 }
560 }
561 Unlock(irql);
562
563 //
564 // Since we are going to reference the FxUsbPipe's outside of the
565 // lock and the interface can go away in the meantime, add a reference
566 // (multiple times perhaps) to each FxUsbPipe to make sure it sticks
567 // around.
568 //
569 for (ple = head.Flink; ple != &head; ple = ple->Flink) {
571 pRequest->GetTarget()->ADDREF(this);
572 }
573
574 //
575 // Drain the list of pended requests.
576 //
577 while (!IsListEmpty(&head)) {
579
581
583
585
587
588 //
589 // Release the reference taken above when accumulating pended i/o.
590 //
591 pTarget->RELEASE(this);
592 }
593 }
594
595 return status;
596}
struct outqueuenode * head
Definition: adnsresfilter.c:66
VOID SubmitPendedRequest(__in FxRequestBase *Request)
Definition: fxiotarget.cpp:206
virtual _Must_inspect_result_ NTSTATUS Start(VOID)
Definition: fxiotarget.cpp:282
virtual _Must_inspect_result_ NTSTATUS GotoStartState(__in PLIST_ENTRY RequestListHead, __in BOOLEAN Lock=TRUE)
Definition: fxusbpipe.cpp:1133
FxIoTarget * pTarget
Definition: fxdeviceapi.cpp:97

◆ Stop()

VOID FxUsbDevice::Stop ( __in WDF_IO_TARGET_SENT_IO_ACTION  Action)
protectedvirtual

Reimplemented from FxIoTarget.

Definition at line 601 of file fxusbdevice.cpp.

604{
607 ULONG iPipe, iInterface;
608 KIRQL irql;
609
610 head.Next = NULL;
611
612 //
613 // Stop all of our own I/O first
614 //
616
617 //
618 // if we are just canceling i/o, then we just acquire the spin lock b/c
619 // we can be called at dispatch level for this action code.
620 //
623
624 AcquireInterfaceIterationLock();
625 }
626
627 //
628 // Since we don't have to synchronize on the I/O already sent, just set
629 // each pipe's state to stop.
630 //
631 Lock(&irql);
632
633 for (iInterface = 0; iInterface < m_NumInterfaces; iInterface++) {
634 pUsbInterface = m_Interfaces[iInterface];
635
637 for (iPipe = 0;
639 iPipe++) {
640
641 if (pUsbInterface->m_ConfiguredPipes[iPipe] != NULL) {
642 BOOLEAN wait;
643
644 wait = FALSE;
645
647 Action,
648 &head,
649 &wait,
650 TRUE
651 );
652 }
653 }
654 }
655 }
656 Unlock(irql);
657
658 //
659 // If we are leaving sent IO pending, the io target will set the IO
660 // completion event during stop even if there is still outstanding IO.
661 //
662
663 if (head.Next != NULL) {
665 }
666
667 for (iInterface = 0; iInterface < m_NumInterfaces; iInterface++) {
668 pUsbInterface = m_Interfaces[iInterface];
669
671 //
672 // Iterate over the pipes and clean each one up
673 //
674 for (iPipe = 0;
676 iPipe++) {
677 //
678 // Same reason as above
679 //
680 if (pUsbInterface->m_ConfiguredPipes[iPipe] != NULL) {
683 }
684 }
685 }
686 }
687
689 ReleaseInterfaceIterationLock();
690 }
691}
virtual VOID Stop(__in WDF_IO_TARGET_SENT_IO_ACTION Action)
Definition: fxiotarget.cpp:748
virtual VOID GotoStopState(__in WDF_IO_TARGET_SENT_IO_ACTION Action, __in PSINGLE_LIST_ENTRY SentRequestListHead, __out PBOOLEAN Wait, __in BOOLEAN LockSelf)
Definition: fxusbpipe.cpp:1217
HRESULT Next([in] ULONG celt, [out, size_is(celt), length_is(*pceltFetched)] STATPROPSETSTG *rgelt, [out] ULONG *pceltFetched)
@ WdfIoTargetLeaveSentIoPending
Definition: wdfiotarget.h:73

Member Data Documentation

◆ FxUsbInterface

friend FxUsbDevice::FxUsbInterface

Definition at line 186 of file fxusbdevice.hpp.

Referenced by CreateInterfaces().

◆ FxUsbPipe

friend FxUsbDevice::FxUsbPipe

Definition at line 185 of file fxusbdevice.hpp.

Referenced by SelectConfig().

◆ m_BusInterfaceContext

PVOID FxUsbDevice::m_BusInterfaceContext
protected

Definition at line 635 of file fxusbdevice.hpp.

Referenced by FxUsbDevice(), GetCurrentFrameNumber(), InitDevice(), and ~FxUsbDevice().

◆ m_BusInterfaceDereference

PINTERFACE_DEREFERENCE FxUsbDevice::m_BusInterfaceDereference
protected

Definition at line 637 of file fxusbdevice.hpp.

Referenced by FxUsbDevice(), InitDevice(), and ~FxUsbDevice().

◆ m_ConfigDescriptor

◆ m_ConfigHandle

USBD_CONFIGURATION_HANDLE FxUsbDevice::m_ConfigHandle
protected

◆ m_ControlPipe

USBD_PIPE_HANDLE FxUsbDevice::m_ControlPipe
protected

Definition at line 621 of file fxusbdevice.hpp.

Referenced by FxUsbDevice(), GetControlPipeHandle(), and InitDevice().

◆ m_DeviceDescriptor

USB_DEVICE_DESCRIPTOR FxUsbDevice::m_DeviceDescriptor
protected

Definition at line 627 of file fxusbdevice.hpp.

Referenced by CopyDeviceDescriptor(), FxUsbDevice(), and InitDevice().

◆ m_HcdPortCapabilities

ULONG FxUsbDevice::m_HcdPortCapabilities
protected

Definition at line 641 of file fxusbdevice.hpp.

Referenced by FxUsbDevice(), GetInformation(), and InitDevice().

◆ m_InterfaceIterationLock

FxWaitLockInternal FxUsbDevice::m_InterfaceIterationLock
protected

Definition at line 639 of file fxusbdevice.hpp.

Referenced by _Acquires_lock_(), and _Releases_lock_().

◆ m_Interfaces

◆ m_MismatchedInterfacesInConfigDescriptor

BOOLEAN FxUsbDevice::m_MismatchedInterfacesInConfigDescriptor
protected

◆ m_NumInterfaces

◆ m_OnUSBD

BOOLEAN FxUsbDevice::m_OnUSBD
protected

Definition at line 645 of file fxusbdevice.hpp.

Referenced by FxUsbDevice(), InitDevice(), and OnUSBD().

◆ m_pHostTargetFile

IWudfFile* FxUsbDevice::m_pHostTargetFile
private

◆ m_QueryBusTime

PUSB_BUSIFFN_QUERY_BUS_TIME FxUsbDevice::m_QueryBusTime
protected

Definition at line 633 of file fxusbdevice.hpp.

Referenced by FxUsbDevice(), GetCurrentFrameNumber(), and InitDevice().

◆ m_Traits

ULONG FxUsbDevice::m_Traits
protected

◆ m_UrbType

FX_URB_TYPE FxUsbDevice::m_UrbType
protected

Definition at line 651 of file fxusbdevice.hpp.

Referenced by FxUsbDevice(), GetFxUrbTypeForRequest(), GetUrbType(), and InitDevice().

◆ m_USBDHandle

USBD_HANDLE FxUsbDevice::m_USBDHandle
protected

◆ m_UsbdVersionInformation

USBD_VERSION_INFORMATION FxUsbDevice::m_UsbdVersionInformation
protected

Definition at line 631 of file fxusbdevice.hpp.

Referenced by FxUsbDevice(), GetInformation(), and InitDevice().

◆ m_WinUsbHandle

WINUSB_INTERFACE_HANDLE FxUsbDevice::m_WinUsbHandle
private

Definition at line 663 of file fxusbdevice.hpp.

Referenced by FxUsbDevice(), and FxUsbInterface::SetWinUsbHandle().


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