ReactOS  0.4.15-dev-3440-g915569a
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 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)
 
_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)
 
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;
380  m_Interfaces = NULL;;
381  m_NumInterfaces = 0;
382 
383  m_Traits = 0;
391 
393 
394  m_USBDHandle = NULL;
396 
397 #if (FX_CORE_MODE == FX_CORE_USER_MODE)
400 #endif
401 
403 }
FX_URB_TYPE m_UrbType
UCHAR m_NumInterfaces
WINUSB_INTERFACE_HANDLE m_WinUsbHandle
#define FALSE
Definition: types.h:117
PINTERFACE_DEREFERENCE m_BusInterfaceDereference
VOID MarkDisposeOverride(__in FxObjectLockState State=ObjectLock)
Definition: fxobject.hpp:1101
USBD_PIPE_HANDLE m_ControlPipe
FxIoTarget(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in USHORT ObjectSize)
Definition: fxiotarget.cpp:34
PUSB_CONFIGURATION_DESCRIPTOR m_ConfigDescriptor
BOOLEAN m_OnUSBD
ULONG m_HcdPortCapabilities
PVOID m_BusInterfaceContext
FxUsbInterface ** m_Interfaces
BOOLEAN m_MismatchedInterfacesInConfigDescriptor
USBD_HANDLE m_USBDHandle
PUSB_BUSIFFN_QUERY_BUS_TIME m_QueryBusTime
#define NULL
Definition: types.h:112
USBD_CONFIGURATION_HANDLE m_ConfigHandle
USB_DEVICE_DESCRIPTOR m_DeviceDescriptor
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
IWudfFile * m_pHostTargetFile
USBD_VERSION_INFORMATION m_UsbdVersionInformation

◆ ~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++) {
450  ASSERT(m_Interfaces[i] == NULL);
451  }
452 
453  if (m_Interfaces != NULL){
455  m_Interfaces = NULL;
456  }
457 
458  m_NumInterfaces = 0;
459 }
UCHAR m_NumInterfaces
PINTERFACE_DEREFERENCE m_BusInterfaceDereference
#define ASSERT(a)
Definition: mode.c:44
PUSB_CONFIGURATION_DESCRIPTOR m_ConfigDescriptor
PVOID m_BusInterfaceContext
unsigned char UCHAR
Definition: xmlstorage.h:181
FxUsbInterface ** m_Interfaces
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 NULL
Definition: types.h:112
void FxPoolFree(__in_xcount(ptr is at an offset from AllocationStart) PVOID ptr)
Definition: wdfpool.cpp:361

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 }
FxRequest * pRequest
VOID CompletePendedRequest(__in FxRequestBase *Request)
Definition: fxiotarget.cpp:508
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
PSINGLE_LIST_ENTRY ple
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
__inline FxIoTarget * GetTarget(VOID)
Definition: typedefs.h:119
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
static VOID _CancelSentRequests(__in PSINGLE_LIST_ENTRY RequestListHead)
Definition: fxiotarget.cpp:550
static __inline FxRequestBase * _FromListEntry(__in PLIST_ENTRY Entry)

Referenced by CleanupInterfacePipesAndDelete(), and PipesGotoRemoveState().

◆ _Releases_lock_()

FxUsbDevice::_Releases_lock_ ( _Global_critical_region_  )
inlineprotected

Definition at line 566 of file fxusbdevice.hpp.

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

◆ 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 }
FxUsbPipe ** m_ConfiguredPipes
UCHAR m_NumInterfaces
FxUsbInterface * pUsbInterface
UCHAR m_NumberOfConfiguredPipes
VOID CancelSentIo(VOID)
FxUsbInterface ** m_Interfaces
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1

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 }
__drv_restoresIRQL KIRQL __in BOOLEAN Unlock
Definition: fxobject.hpp:1474
Definition: ntbasedef.h:628
#define TRUE
Definition: types.h:120
KIRQL irql
Definition: wave.h:1
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
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
_In_ WDFUSBINTERFACE UsbInterface
Definition: wdfusb.h:2276
static VOID _CleanupPipesRequests(__in PLIST_ENTRY PendHead, __in PSINGLE_LIST_ENTRY SentHead)
struct _SINGLE_LIST_ENTRY * Next
Definition: ntbasedef.h:629
Definition: typedefs.h:119
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define NULL
Definition: types.h:112
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWAITLOCK * Lock
Definition: wdfsync.h:124
unsigned int ULONG
Definition: retypes.h:1
virtual VOID WaitForSentIoToComplete(VOID)
Definition: fxusbpipe.cpp:1419

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  }
_In_ WDFUSBDEVICE _Out_ PUSB_DEVICE_DESCRIPTOR UsbDeviceDescriptor
Definition: wdfusb.h:1005
USB_DEVICE_DESCRIPTOR m_DeviceDescriptor
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263

◆ 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 
948  sizeof(USB_INTERFACE_DESCRIPTOR),
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 
1031  status = pInterface->Commit(WDF_NO_OBJECT_ATTRIBUTES, NULL, this);
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 
1124 Done:
1125  return status;
1126 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
friend FxUsbInterface
#define WDF_PTR_ADD_OFFSET(_ptr, _offset)
Definition: wdfcore.h:144
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
BOOLEAN __inline FxBitArraySet(__inout_xcount((BitNumber/sizeof(UCHAR))+1) PUCHAR BitArray, __in UCHAR BitNumber)
Definition: usbutil.hpp:9
struct _USB_INTERFACE_DESCRIPTOR * PUSB_INTERFACE_DESCRIPTOR
PINTERFACE pInterface
PUSB_COMMON_DESCRIPTOR FxUsbFindDescriptorType(__in PVOID Buffer, __in size_t BufferLength, __in PVOID Start, __in LONG DescriptorType)
Definition: usbutil.cpp:174
UCHAR m_NumInterfaces
#define FALSE
Definition: types.h:117
#define UCHAR_MAX
Definition: fxusbdevice.cpp:33
#define USB_INTERFACE_DESCRIPTOR_TYPE
Definition: usb100.h:52
GLsizeiptr size
Definition: glext.h:5919
PFX_DRIVER_GLOBALS pFxDriverGlobals
#define ASSERT(a)
Definition: mode.c:44
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
PUSB_CONFIGURATION_DESCRIPTOR m_ConfigDescriptor
unsigned char UCHAR
Definition: xmlstorage.h:181
FxUsbInterface ** m_Interfaces
NTSTATUS FxUsbValidateConfigDescriptorHeaders(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PUSB_CONFIGURATION_DESCRIPTOR ConfigDescriptor, __in size_t ConfigDescriptorLength)
Definition: usbutil.cpp:111
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
#define TRACE_LEVEL_WARNING
Definition: storswtr.h:28
BOOLEAN m_MismatchedInterfacesInConfigDescriptor
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
#define NULL
Definition: types.h:112
#define WDF_NO_OBJECT_ATTRIBUTES
Definition: wdftypes.h:105
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
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
#define STATUS_SUCCESS
Definition: shellext.h:65
static SERVICE_STATUS status
Definition: service.c:31
#define TRACINGIOTARGET
Definition: dbgtrace.h:72
Definition: ps.c:97

◆ 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 {
2248  NTSTATUS status;
2249  PURB urbLocal = NULL;
2251  FxUsbUrb * pUrb = NULL;
2252  WDFMEMORY hMemory;
2253  ULONG size;
2254  FxObject* pParent;
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,
2268  &pFxDriverGlobals);
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 
2338 Done:
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 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_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
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN IsObjectDisposedOnRemove(__in FxObject *Object)
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
#define GET_ISO_URB_SIZE(n)
Definition: usbdlib.h:125
#define FALSE
Definition: types.h:117
_Must_inspect_result_ NTSTATUS __inline FxValidateObjectAttributesForParentHandle(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PWDF_OBJECT_ATTRIBUTES Attributes, __in ULONG Flags=FX_VALIDATE_OPTION_NONE_SPECIFIED)
GLsizeiptr size
Definition: glext.h:5919
PFX_DRIVER_GLOBALS pFxDriverGlobals
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID USBD_UrbFree(_In_ USBD_HANDLE USBDHandle, _In_ PURB Urb)
Definition: usbstubum.cpp:33
_Must_inspect_result_ NTSTATUS FxValidateObjectAttributes(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PWDF_OBJECT_ATTRIBUTES Attributes, __in ULONG Flags=FX_VALIDATE_OPTION_NONE_SPECIFIED)
_Must_inspect_result_ _In_ WDFUSBDEVICE _In_opt_ PWDF_OBJECT_ATTRIBUTES _In_ ULONG NumberOfIsochPackets
Definition: wdfusb.h:1699
WDFMEMORY hMemory
struct _URB * PURB
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
Definition: usb.h:529
USBD_HANDLE m_USBDHandle
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
#define STATUS_WDF_PARENT_NOT_SPECIFIED
Definition: wdfstatus.h:252
#define NULL
Definition: types.h:112
VOID DeleteFromFailedCreate(VOID)
Definition: fxobject.cpp:391
unsigned int ULONG
Definition: retypes.h:1
FxObject * pParent
Definition: fxdpcapi.cpp:86
FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals), Device, FX_TYPE_DEVICE,(PVOID *)&pDevice, &pFxDriverGlobals)
_Must_inspect_result_ _In_ WDFUSBDEVICE _In_ WDFREQUEST _In_ WDFMEMORY UrbMemory
Definition: wdfusb.h:1572
#define STATUS_SUCCESS
Definition: shellext.h:65
static SERVICE_STATUS status
Definition: service.c:31
#define TRACINGIOTARGET
Definition: dbgtrace.h:72
#define FxPointerNotNull(FxDriverGlobals, Ptr)
Definition: fxmacros.hpp:253
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes
Definition: ps.c:97

◆ 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 {
2131  NTSTATUS status;
2132  PURB urbLocal = NULL;
2134  FxUsbUrb * pUrb = NULL;
2135  WDFMEMORY hMemory;
2136  FxObject* pParent;
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,
2150  &pFxDriverGlobals);
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 
2218 Done:
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 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_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
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN IsObjectDisposedOnRemove(__in FxObject *Object)
#define FALSE
Definition: types.h:117
_Must_inspect_result_ NTSTATUS __inline FxValidateObjectAttributesForParentHandle(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PWDF_OBJECT_ATTRIBUTES Attributes, __in ULONG Flags=FX_VALIDATE_OPTION_NONE_SPECIFIED)
PFX_DRIVER_GLOBALS pFxDriverGlobals
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID USBD_UrbFree(_In_ USBD_HANDLE USBDHandle, _In_ PURB Urb)
Definition: usbstubum.cpp:33
_Must_inspect_result_ NTSTATUS FxValidateObjectAttributes(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PWDF_OBJECT_ATTRIBUTES Attributes, __in ULONG Flags=FX_VALIDATE_OPTION_NONE_SPECIFIED)
WDFMEMORY hMemory
struct _URB * PURB
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
Definition: usb.h:529
USBD_HANDLE m_USBDHandle
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
#define STATUS_WDF_PARENT_NOT_SPECIFIED
Definition: wdfstatus.h:252
#define NULL
Definition: types.h:112
VOID DeleteFromFailedCreate(VOID)
Definition: fxobject.cpp:391
FxObject * pParent
Definition: fxdpcapi.cpp:86
FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals), Device, FX_TYPE_DEVICE,(PVOID *)&pDevice, &pFxDriverGlobals)
_Must_inspect_result_ _In_ WDFUSBDEVICE _In_ WDFREQUEST _In_ WDFMEMORY UrbMemory
Definition: wdfusb.h:1572
#define STATUS_SUCCESS
Definition: shellext.h:65
NTSTATUS USBD_UrbAllocate(_In_ USBD_HANDLE USBDHandle, _Outptr_result_bytebuffer_(sizeof(URB)) PURB *Urb)
Definition: usbstubum.cpp:46
static SERVICE_STATUS status
Definition: service.c:31
#define TRACINGIOTARGET
Definition: dbgtrace.h:72
#define FxPointerNotNull(FxDriverGlobals, Ptr)
Definition: fxmacros.hpp:253
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes
Definition: ps.c:97

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);
1233  NTSTATUS status;
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 }
Definition: http.c:7251
LONG NTSTATUS
Definition: precomp.h:26
VOID CancelSentIo(VOID)
FxRequest * request
_Must_inspect_result_ NTSTATUS SubmitSyncRequestIgnoreTargetState(__in FxRequestBase *Request, __in_opt PWDF_REQUEST_SEND_OPTIONS RequestOptions)
_Must_inspect_result_ NTSTATUS FormatCycleRequest(__in FxRequestBase *Request)
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_In_opt_ PVOID _In_ ULONG _In_ PVOID context
Definition: wdfdriver.h:113
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
#define NULL
Definition: types.h:112
Definition: tftpd.h:85
static SERVICE_STATUS status
Definition: service.c:31
#define TRACINGIOTARGET
Definition: dbgtrace.h:72
Definition: ps.c:97

◆ Deconfig()

_Must_inspect_result_ NTSTATUS FxUsbDevice::Deconfig ( VOID  )

Definition at line 1877 of file fxusbdevice.cpp.

1880 {
1883 
1884  FxSyncRequest request(GetDriverGlobals(), NULL);
1885  NTSTATUS status;
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 }
FORCEINLINE VOID WDF_REQUEST_SEND_OPTIONS_INIT(_Out_ PWDF_REQUEST_SEND_OPTIONS Options, _In_ ULONG Flags)
Definition: wdfrequest.h:409
#define UsbBuildSelectConfigurationRequest(urb, length, configurationDescriptor)
Definition: usbdlib.h:53
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
_Must_inspect_result_ NTSTATUS SubmitSync(__in FxRequestBase *Request, __in_opt PWDF_REQUEST_SEND_OPTIONS Options=NULL, __out_opt PULONG Action=NULL)
FxRequest * request
int options
Definition: main.c:106
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID PipesGotoRemoveState(__in BOOLEAN ForceRemovePipes)
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
Definition: usb.h:529
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
#define NULL
Definition: types.h:112
Definition: tftpd.h:85
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
static SERVICE_STATUS status
Definition: service.c:31
#define TRACINGIOTARGET
Definition: dbgtrace.h:72
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
Definition: ps.c:97

◆ 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))
412 #endif
413 
414  if (m_USBDHandle) {
416  m_USBDHandle = NULL;
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
Definition: devices.h:37
VOID USBD_CloseHandle(_In_ USBD_HANDLE USBDHandle)
Definition: usbstubum.cpp:80
#define SAFE_RELEASE(p)
CfxDeviceBase * m_DeviceBase
Definition: fxobject.hpp:328
USBD_HANDLE m_USBDHandle
#define NULL
Definition: types.h:112
IWudfFile * m_pHostTargetFile
VOID NTAPI KeFlushQueuedDpcs(VOID)
Definition: dpc.c:919

◆ 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 {
594  FxUsbDeviceControlContext* pContext;
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 
628  urbType = GetFxUrbTypeForRequest(Request);
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)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_Must_inspect_result_ _In_ WDFUSBDEVICE _In_opt_ WDFREQUEST _In_opt_ PWDF_REQUEST_SEND_OPTIONS _In_ PWDF_USB_CONTROL_SETUP_PACKET SetupPacket
Definition: wdfusb.h:1331
LONG NTSTATUS
Definition: precomp.h:26
_In_ WDFREQUEST Request
Definition: wdfdevice.h:547
enum _FX_URB_TYPE FX_URB_TYPE
VOID StoreAndReferenceMemory(__in FxUsbDevice *Device, __in FxRequestBuffer *Buffer, __in PWDF_USB_CONTROL_SETUP_PACKET SetupPacket)
WDFIOTARGET GetHandle(VOID)
Definition: fxiotarget.hpp:307
#define ASSERT(a)
Definition: mode.c:44
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
size_t bufferSize
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
_URB_CONTROL_TRANSFER * m_Urb
Definition: fxusbdevice.hpp:86
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
Definition: usb.h:529
__checkReturn NTSTATUS AllocateUrb(__in USBD_HANDLE USBDHandle)
Definition: fxusbdevice.cpp:66
USBD_HANDLE m_USBDHandle
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
#define NULL
Definition: types.h:112
_URB_CONTROL_TRANSFER m_UrbLegacy
Definition: fxusbdevice.hpp:81
#define STATUS_SUCCESS
Definition: shellext.h:65
static SERVICE_STATUS status
Definition: service.c:31
#define TRACINGIOTARGET
Definition: dbgtrace.h:72
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
Definition: ps.c:97

◆ FormatCycleRequest()

_Must_inspect_result_ NTSTATUS FxUsbDevice::FormatCycleRequest ( __in FxRequestBase Request)

Definition at line 1261 of file fxusbdevice.cpp.

1264 {
1265  FxRequestBuffer emptyBuffer;
1266 
1267  return FormatIoctlRequest(Request,
1269  TRUE,
1270  &emptyBuffer,
1271  &emptyBuffer);
1272 }
#define TRUE
Definition: types.h:120
_In_ WDFREQUEST Request
Definition: wdfdevice.h:547
#define IOCTL_INTERNAL_USB_CYCLE_PORT
Definition: usbioctl.h:53
_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)

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 
539  urbType = GetFxUrbTypeForRequest(Request);
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 }
_URB_CONTROL_DESCRIPTOR_REQUEST m_UrbLegacy
FX_URB_TYPE GetFxUrbTypeForRequest(__in FxRequestBase *Request)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_URB_CONTROL_DESCRIPTOR_REQUEST * m_Urb
VOID SetUrbInfo(__in UCHAR StringIndex, __in USHORT LangID)
LONG NTSTATUS
Definition: precomp.h:26
_In_ WDFREQUEST Request
Definition: wdfdevice.h:547
_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:1075
enum _FX_URB_TYPE FX_URB_TYPE
WDFIOTARGET GetHandle(VOID)
Definition: fxiotarget.hpp:307
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
virtual VOID StoreAndReferenceMemory(__in FxRequestBuffer *Buffer)
_Must_inspect_result_ NTSTATUS AllocateDescriptor(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in size_t BufferSize)
__checkReturn NTSTATUS AllocateUrb(__in USBD_HANDLE USBDHandle)
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
Definition: usb.h:529
USBD_HANDLE m_USBDHandle
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
#define NULL
Definition: types.h:112
#define STATUS_SUCCESS
Definition: shellext.h:65
_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:1075
static SERVICE_STATUS status
Definition: service.c:31
#define TRACINGIOTARGET
Definition: dbgtrace.h:72
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
Definition: ps.c:97

◆ GetConfigDescriptor()

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

Definition at line 1276 of file fxusbdevice.cpp.

1280 {
1281  NTSTATUS status;
1282  USHORT copyLength;
1283 
1284  if (ConfigDescriptor == NULL) {
1285  //
1286  // Caller wants length to allocate
1287  //
1289  return STATUS_BUFFER_TOO_SMALL;
1290  }
1291 
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 }
LONG NTSTATUS
Definition: precomp.h:26
_Must_inspect_result_ _In_ WDFUSBDEVICE _Out_writes_bytes_to_opt_ ConfigDescriptorLength PVOID _Inout_ PUSHORT ConfigDescriptorLength
Definition: wdfusb.h:1036
#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
PUSB_CONFIGURATION_DESCRIPTOR m_ConfigDescriptor
unsigned short USHORT
Definition: pedump.c:61
#define NULL
Definition: types.h:112
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define STATUS_SUCCESS
Definition: shellext.h:65
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

◆ GetConfigHandle()

__inline USBD_CONFIGURATION_HANDLE FxUsbDevice::GetConfigHandle ( VOID  )
inline

Definition at line 234 of file fxusbdevice.hpp.

237  {
238  return m_ConfigHandle;
239  }
USBD_CONFIGURATION_HANDLE m_ConfigHandle

◆ GetControlPipeHandle()

USBD_PIPE_HANDLE FxUsbDevice::GetControlPipeHandle ( VOID  )
inline

Definition at line 369 of file fxusbdevice.hpp.

372  {
373  return m_ControlPipe;
374  }
USBD_PIPE_HANDLE m_ControlPipe

◆ 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
PVOID m_BusInterfaceContext
PUSB_BUSIFFN_QUERY_BUS_TIME m_QueryBusTime
#define NULL
Definition: types.h:112

◆ 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()) {
2466  return FxUrbTypeUsbdAllocated;
2467  }
2468 
2470  return FxUrbTypeUsbdAllocated;
2471  }
2472 
2473  return FxUrbTypeLegacy;
2474 }
FX_URB_TYPE m_UrbType
_In_ WDFREQUEST Request
Definition: wdfdevice.h:547
BOOLEAN IsObjectDisposedOnRemove(__in FxObject *Object)

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,
490  sizeof(m_UsbdVersionInformation));
491 }
_In_ WDFREQUEST _In_ NTSTATUS _In_ ULONG_PTR Information
Definition: wdfrequest.h:1044
ULONG m_HcdPortCapabilities
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
USBD_VERSION_INFORMATION m_UsbdVersionInformation

◆ GetInterfaceFromIndex()

FxUsbInterface * FxUsbDevice::GetInterfaceFromIndex ( __in UCHAR  InterfaceIndex)

Definition at line 2005 of file fxusbdevice.cpp.

2008 {
2010  return m_Interfaces[InterfaceIndex];
2011  }
2012 
2013  return NULL;
2014 }
_In_ WDFUSBDEVICE _In_ UCHAR InterfaceIndex
Definition: wdfusb.h:2459
UCHAR m_NumInterfaces
FxUsbInterface ** m_Interfaces
#define NULL
Definition: types.h:112

◆ 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()
UCHAR m_NumInterfaces
_In_ PVOID _In_ LONG InterfaceNumber
Definition: usbdlib.h:168
FxUsbInterface ** m_Interfaces
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 NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1

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 
2026  UsbInterface,
2028  (PVOID*) &pUsbInterface);
2029 
2031 
2032  return STATUS_SUCCESS;
2033 }
FxObjectHandleGetPtr(GetFxDriverGlobals(DriverGlobals), Fdo, FX_TYPE_DEVICE,(PVOID *)&pFdo)
FxUsbInterface * pUsbInterface
_In_ PVOID _In_ LONG InterfaceNumber
Definition: usbdlib.h:168
UCHAR GetInterfaceNumber(VOID)
_In_ WDFUSBINTERFACE UsbInterface
Definition: wdfusb.h:2276
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
#define STATUS_SUCCESS
Definition: shellext.h:65

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  }
UCHAR m_NumInterfaces

◆ GetPortStatus()

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

Definition at line 1131 of file fxusbdevice.cpp.

1134 {
1135  NTSTATUS status;
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 }
FORCEINLINE VOID WDF_REQUEST_SEND_OPTIONS_INIT(_Out_ PWDF_REQUEST_SEND_OPTIONS Options, _In_ ULONG Flags)
Definition: wdfrequest.h:409
Definition: http.c:7251
_Must_inspect_result_ NTSTATUS FormatInternalIoctlOthersRequest(__in FxRequestBase *Request, __in ULONG Ioctl, __in FxRequestBuffer *Buffers)
LONG NTSTATUS
Definition: precomp.h:26
#define FX_REQUEST_NUM_OTHER_PARAMS
_Must_inspect_result_ NTSTATUS SubmitSync(__in FxRequestBase *Request, __in_opt PWDF_REQUEST_SEND_OPTIONS Options=NULL, __out_opt PULONG Action=NULL)
Definition: match.c:390
int options
Definition: main.c:106
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_In_opt_ PVOID _In_ ULONG _In_ PVOID context
Definition: wdfdriver.h:113
_Outptr_ PUSB_DEVICE_HANDLE _In_ PUSB_DEVICE_HANDLE _In_ USHORT PortStatus
Definition: hubbusif.h:40
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
#define NULL
Definition: types.h:112
#define IOCTL_INTERNAL_USB_GET_PORT_STATUS
Definition: usbioctl.h:44
static SERVICE_STATUS status
Definition: service.c:31
#define TRACINGIOTARGET
Definition: dbgtrace.h:72
Definition: ps.c:97

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;
375  PVOID buffer;
378  USB_COMMON_DESCRIPTOR common;
379  ULONG length;
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(),
407  NonPagedPool,
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 
421  length = sizeof(USB_COMMON_DESCRIPTOR);
422  pDescriptor = (PUSB_STRING_DESCRIPTOR) &common;
423  }
424 
428  StringIndex,
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 
489 Done:
490 
491  return status;
492 }
FORCEINLINE VOID WDF_REQUEST_SEND_OPTIONS_INIT(_Out_ PWDF_REQUEST_SEND_OPTIONS Options, _In_ ULONG Flags)
Definition: wdfrequest.h:409
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ CLIPOBJ _In_ BRUSHOBJ _In_ LONG x1
Definition: winddi.h:3706
LONG NTSTATUS
Definition: precomp.h:26
struct _USB_COMMON_DESCRIPTOR USB_COMMON_DESCRIPTOR
GLuint buffer
Definition: glext.h:5915
_In_ WDFREQUEST Request
Definition: wdfdevice.h:547
_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:1075
_Must_inspect_result_ NTSTATUS SubmitSync(__in FxRequestBase *Request, __in_opt PWDF_REQUEST_SEND_OPTIONS Options=NULL, __out_opt PULONG Action=NULL)
#define UsbBuildGetDescriptorRequest(urb, length, descriptorType, descriptorIndex, languageId, transferBuffer, transferBufferMDL, transferBufferLength, link)
Definition: usbdlib.h:23
#define USB_STRING_DESCRIPTOR_TYPE
Definition: usb100.h:51
_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:1075
FxRequest * request
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2430
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
struct _USB_STRING_DESCRIPTOR USB_STRING_DESCRIPTOR
USHORT numChars
int options
Definition: main.c:106
_In_ PWDFDEVICE_INIT _In_ PWDF_REMOVE_LOCK_OPTIONS Options
Definition: wdfdevice.h:3531
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
FORCEINLINE LONGLONG WDF_REL_TIMEOUT_IN_SEC(_In_ ULONGLONG Time)
Definition: wdfcore.h:62
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
struct _USB_STRING_DESCRIPTOR * PUSB_STRING_DESCRIPTOR
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
Definition: usb.h:529
unsigned short USHORT
Definition: pedump.c:61
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
#define NULL
Definition: types.h:112
Definition: tftpd.h:85
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
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 _In_ UCHAR _In_opt_ USHORT LangID
Definition: wdfusb.h:1075
void FxPoolFree(__in_xcount(ptr is at an offset from AllocationStart) PVOID ptr)
Definition: wdfpool.cpp:361
static SERVICE_STATUS status
Definition: service.c:31
#define TRACINGIOTARGET
Definition: dbgtrace.h:72
#define STATUS_DEVICE_DATA_ERROR
Definition: udferr_usr.h:159
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
Definition: ps.c:97

◆ GetUrbType()

FX_URB_TYPE FxUsbDevice::GetUrbType ( VOID  )
inline

Definition at line 478 of file fxusbdevice.hpp.

481  {
482  return m_UrbType;
483  }
FX_URB_TYPE m_UrbType

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  }
USBD_HANDLE m_USBDHandle

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

◆ HasMismatchedInterfacesInConfigDescriptor()

BOOLEAN FxUsbDevice::HasMismatchedInterfacesInConfigDescriptor ( VOID  )
inline

Definition at line 409 of file fxusbdevice.hpp.

412  {
414  }
BOOLEAN m_MismatchedInterfacesInConfigDescriptor

◆ 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,
64  &m_USBDHandle);
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 
82  sizeof(struct _URB_CONTROL_DESCRIPTOR_REQUEST),
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(),
186  NonPagedPool,
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 
200  RtlZeroMemory(m_ConfigDescriptor, paddedSize);
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 
358 Done:
359 
360  return status;
361 }
FORCEINLINE VOID WDF_REQUEST_SEND_OPTIONS_INIT(_Out_ PWDF_REQUEST_SEND_OPTIONS Options, _In_ ULONG Flags)
Definition: wdfrequest.h:409
MdDeviceObject m_TargetDevice
Definition: fxiotarget.hpp:910
struct _USB_DEVICE_DESCRIPTOR USB_DEVICE_DESCRIPTOR
return STATUS_NOT_SUPPORTED
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
struct config_s config
#define UsbBuildGetStatusRequest(urb, op, index, transferBuffer, transferBufferMDL, link)
Definition: usbdlib.h:35
#define USB_BUSIF_USBDI_VERSION_1
Definition: usbbusif.h:74
FX_URB_TYPE m_UrbType
#define TRUE
Definition: types.h:120
WDFCASSERT(sizeof(WDF_DRIVER_CONFIG_V1_0)==sizeof(WDF_DRIVER_CONFIG_V1_1))
LONG NTSTATUS
Definition: precomp.h:26
PUSB_BUSIFFN_GETUSBDI_VERSION GetUSBDIVersion
Definition: usbbusif.h:99
#define USB_BUSIF_USBDI_VERSION_0
Definition: usbbusif.h:73
_Must_inspect_result_ NTSTATUS SubmitSync(__in FxRequestBase *Request, __in_opt PWDF_REQUEST_SEND_OPTIONS Options=NULL, __out_opt PULONG Action=NULL)
#define UsbBuildGetDescriptorRequest(urb, length, descriptorType, descriptorIndex, languageId, transferBuffer, transferBufferMDL, transferBufferLength, link)
Definition: usbdlib.h:23
PINTERFACE_DEREFERENCE InterfaceDereference
Definition: usbbusif.h:98
MdDeviceObject m_InStackDevice
Definition: fxiotarget.hpp:905
struct _USB_CONFIGURATION_DESCRIPTOR * PUSB_CONFIGURATION_DESCRIPTOR
FxRequest * request
#define USB_DEVICE_DESCRIPTOR_TYPE
Definition: usb100.h:49
PINTERFACE_DEREFERENCE m_BusInterfaceDereference
#define USB_CONFIGURATION_DESCRIPTOR_TYPE
Definition: usb100.h:50
USBD_PIPE_HANDLE m_ControlPipe
_Reserved_ PVOID Reserved
Definition: winddi.h:3974
struct _INTERFACE * PINTERFACE
int options
Definition: main.c:106
GLsizeiptr size
Definition: glext.h:5919
#define ASSERT(a)
Definition: mode.c:44
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
PUSB_BUSIFFN_QUERY_BUS_TIME QueryBusTime
Definition: usbbusif.h:100
#define USB_CONFIG_REMOTE_WAKEUP
Definition: usb100.h:71
PUSB_CONFIGURATION_DESCRIPTOR m_ConfigDescriptor
BOOLEAN m_OnUSBD
ULONG m_HcdPortCapabilities
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
PVOID m_BusInterfaceContext
#define USB_GETSTATUS_SELF_POWERED
Definition: usb100.h:45
_Must_inspect_result_ _In_ WDFDEVICE _In_ BOOLEAN _In_opt_ PVOID Tag
Definition: wdfdevice.h:4061
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
#define USBD_CLIENT_CONTRACT_VERSION_INVALID
Definition: usbdlib.h:99
FORCEINLINE LONGLONG WDF_REL_TIMEOUT_IN_SEC(_In_ ULONGLONG Time)
Definition: wdfcore.h:62
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
Definition: usb.h:529
PUSB_BUSIFFN_IS_DEVICE_HIGH_SPEED IsDeviceHighSpeed
Definition: usbbusif.h:103
unsigned short USHORT
Definition: pedump.c:61
USBD_HANDLE m_USBDHandle
PUSB_BUSIFFN_QUERY_BUS_TIME m_QueryBusTime
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
static HANDLE PipeHandle
Definition: dhcpcsvc.c:22
#define NULL
Definition: types.h:112
#define URB_FUNCTION_GET_STATUS_FROM_DEVICE
Definition: usb.h:105
static VOID _FormatIrp(__in PIRP Irp, __in const GUID *InterfaceGuid, __out PINTERFACE Interface, __in USHORT InterfaceSize, __in USHORT InterfaceVersion, __in_opt PVOID InterfaceSpecificData=NULL)
Definition: tftpd.h:85
unsigned int ULONG
Definition: retypes.h:1
USB_DEVICE_DESCRIPTOR m_DeviceDescriptor
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
USBD_VERSION_INFORMATION m_UsbdVersionInformation
#define STATUS_SUCCESS
Definition: shellext.h:65
FORCEINLINE VOID WDF_REQUEST_SEND_OPTIONS_SET_TIMEOUT(_Inout_ PWDF_REQUEST_SEND_OPTIONS Options, _In_ LONGLONG Timeout)
Definition: wdfrequest.h:421
struct _URB_CONTROL_DESCRIPTOR_REQUEST UrbControlDescriptorRequest
Definition: usb.h:545
static SERVICE_STATUS status
Definition: service.c:31
#define TRACINGIOTARGET
Definition: dbgtrace.h:72
#define STATUS_DEVICE_DATA_ERROR
Definition: udferr_usr.h:159
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
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
Definition: ps.c:97

◆ 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)
1213  NTSTATUS status;
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 }
#define STATUS_DEVICE_DOES_NOT_EXIST
Definition: ntstatus.h:428
LONG NTSTATUS
Definition: precomp.h:26
_Must_inspect_result_ NTSTATUS GetPortStatus(__out PULONG PortStatus)
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define USBD_PORT_CONNECTED
Definition: usbioctl.h:42
unsigned int ULONG
Definition: retypes.h:1
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

◆ IsEnabled()

BOOLEAN FxUsbDevice::IsEnabled ( VOID  )

Definition at line 1175 of file fxusbdevice.cpp.

1178 {
1179  NTSTATUS status;
1180  ULONG portStatus;
1181  BOOLEAN enabled;
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 }
#define USBD_PORT_ENABLED
Definition: usbioctl.h:41
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
_Must_inspect_result_ NTSTATUS GetPortStatus(__out PULONG PortStatus)
GLenum GLenum GLsizei const GLuint GLboolean enabled
Definition: glext.h:7750
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
unsigned int ULONG
Definition: retypes.h:1
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

◆ 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
#define TRUE
Definition: types.h:120
GLsizei GLsizei GLuint * obj
Definition: glext.h:6042
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
r parent
Definition: btrfs.c:2944
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object
#define NULL
Definition: types.h:112
Definition: tftpd.h:85
__inline BOOLEAN FxObjectCheckType(__in FxObject *Object, __in WDFTYPE Type)
Definition: fxhandle.h:240

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  }
BOOLEAN m_OnUSBD

◆ 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 }
__drv_restoresIRQL KIRQL __in BOOLEAN Unlock
Definition: fxobject.hpp:1474
Definition: ntbasedef.h:628
#define TRUE
Definition: types.h:120
FxUsbPipe ** m_ConfiguredPipes
KIRQL irql
Definition: wave.h:1
UCHAR m_NumInterfaces
WDF_IO_TARGET_STATE m_State
Definition: fxiotarget.hpp:928
FxUsbInterface * pUsbInterface
UCHAR KIRQL
Definition: env_spec_w32.h:591
UCHAR m_NumberOfConfiguredPipes
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
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
VOID CleanUpAndDelete(__in BOOLEAN ClearDestroyCallback)
static VOID _CleanupPipesRequests(__in PLIST_ENTRY PendHead, __in PSINGLE_LIST_ENTRY SentHead)
struct _SINGLE_LIST_ENTRY * Next
Definition: ntbasedef.h:629
FxUsbInterface ** m_Interfaces
Definition: typedefs.h:119
virtual VOID WaitForSentIoToComplete(VOID)
Definition: fxiotarget.hpp:676
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define NULL
Definition: types.h:112
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWAITLOCK * Lock
Definition: wdfsync.h:124
unsigned int ULONG
Definition: retypes.h:1

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 }
__drv_restoresIRQL KIRQL __in BOOLEAN Unlock
Definition: fxobject.hpp:1474
VOID CompletePendedRequestList(__in PLIST_ENTRY RequestListHead)
Definition: fxiotarget.cpp:520
Definition: ntbasedef.h:628
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
#define TRUE
Definition: types.h:120
FxUsbPipe ** m_ConfiguredPipes
KIRQL irql
Definition: wave.h:1
UCHAR m_NumInterfaces
FxUsbInterface * pUsbInterface
UCHAR KIRQL
Definition: env_spec_w32.h:591
UCHAR m_NumberOfConfiguredPipes
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
#define ASSERT(a)
Definition: mode.c:44
static __inline KIRQL MxGetCurrentIrql()
Definition: mxgeneralkm.h:86
struct _SINGLE_LIST_ENTRY * Next
Definition: ntbasedef.h:629
FxUsbInterface ** m_Interfaces
virtual VOID Purge(__in WDF_IO_TARGET_PURGE_IO_ACTION Action)
Definition: fxiotarget.cpp:918
Definition: typedefs.h:119
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
virtual VOID WaitForSentIoToComplete(VOID)
Definition: fxiotarget.hpp:676
_In_ WDFIOTARGET _In_ _Strict_type_match_ WDF_IO_TARGET_SENT_IO_ACTION Action
Definition: wdfiotarget.h:506
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define NULL
Definition: types.h:112
static VOID _CancelSentRequests(__in PSINGLE_LIST_ENTRY RequestListHead)
Definition: fxiotarget.cpp:550
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWAITLOCK * Lock
Definition: wdfsync.h:124
unsigned int ULONG
Definition: retypes.h:1

◆ 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,
790  ResultLength);
791 
792  if (!NT_SUCCESS(status)) {
795  "Could not retrieve capability %!GUID!, %!STATUS!",
797  goto exit;
798  }
799 
800 exit:
801  return status;
802 }
_Must_inspect_result_ _In_ WDFUSBDEVICE _In_ CONST GUID * CapabilityType
Definition: wdfusb.h:1611
_Must_inspect_result_ _In_ WDFUSBDEVICE _In_ CONST GUID _In_ ULONG CapabilityBufferLength
Definition: wdfusb.h:1611
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
USBD_HANDLE GetUSBDHandle(VOID)
#define STATUS_INVALID_DEVICE_STATE
Definition: udferr_usr.h:178
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
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
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
USBD_HANDLE m_USBDHandle
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
#define NULL
Definition: types.h:112
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG _Out_ PULONG ResultLength
Definition: wdfdevice.h:3776
void exit(int exitcode)
Definition: _exit.c:33
static SERVICE_STATUS status
Definition: service.c:31
#define TRACINGIOTARGET
Definition: dbgtrace.h:72
Definition: ps.c:97

◆ 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) {
474  m_Interfaces[i] = NULL;
475  return;
476  }
477  }
478 }
UCHAR m_NumInterfaces
unsigned char UCHAR
Definition: xmlstorage.h:181
FxUsbInterface ** m_Interfaces
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
IN PVOID IN PVOID IN USHORT IN USHORT IN PINTERFACE Interface
Definition: pci.h:361
#define NULL
Definition: types.h:112

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;
1082  NTSTATUS status;
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 }
Definition: http.c:7251
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
VOID CancelSentIo(VOID)
FxRequest * request
_Must_inspect_result_ NTSTATUS SubmitSyncRequestIgnoreTargetState(__in FxRequestBase *Request, __in_opt PWDF_REQUEST_SEND_OPTIONS RequestOptions)
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_In_opt_ PVOID _In_ ULONG _In_ PVOID context
Definition: wdfdriver.h:113
_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 TRACE_LEVEL_ERROR
Definition: storswtr.h:27
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
#define NULL
Definition: types.h:112
#define IOCTL_INTERNAL_USB_RESET_PORT
Definition: usbioctl.h:35
Definition: tftpd.h:85
static SERVICE_STATUS status
Definition: service.c:31
#define TRACINGIOTARGET
Definition: dbgtrace.h:72
Definition: ps.c:97

◆ 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;
1452  NTSTATUS status;
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  //
1507  size = sizeof(FxInterfacePipeInformation);
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 
1546  pIface = (PUSBD_INTERFACE_INFORMATION) pCur;
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(
1592  NonPagedPool,
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)
1618  FxUsbPipe(GetDriverGlobals(),this);
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) {
1671  size = GET_SELECT_INTERFACE_REQUEST_SIZE(maxNumPipes);
1672 
1673  pSelectUrb = (PURB) FxPoolAllocate(GetDriverGlobals(),
1674  NonPagedPool,
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;
1746  pIface = (PUSBD_INTERFACE_INFORMATION) pCur;
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")
1756  pIface = (PUSBD_INTERFACE_INFORMATION) pCur;
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 
1833 Done:
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 }
CfxDevice * m_Device
Definition: fxobject.hpp:329
FORCEINLINE VOID WDF_REQUEST_SEND_OPTIONS_INIT(_Out_ PWDF_REQUEST_SEND_OPTIONS Options, _In_ ULONG Flags)
Definition: wdfrequest.h:409
friend FxUsbPipe
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_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
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
#define GET_SELECT_INTERFACE_REQUEST_SIZE(totalPipes)
Definition: usbdlib.h:117
struct _USBD_INTERFACE_INFORMATION * PUSBD_INTERFACE_INFORMATION
Definition: fxirp.hpp:28
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
_Must_inspect_result_ NTSTATUS SubmitSync(__in FxRequestBase *Request, __in_opt PWDF_REQUEST_SEND_OPTIONS Options=NULL, __out_opt PULONG Action=NULL)
VOID SetNumConfiguredPipes(__in UCHAR NumberOfPipes)
VOID SetConfiguredPipes(__in FxUsbPipe **ppPipes)
if(dx==0 &&dy==0)
Definition: linetemp.h:174
UCHAR m_NumInterfaces
FxUsbInterface * pUsbInterface
VOID FormatSelectSettingUrb(__in_bcount(GET_SELECT_INTERFACE_REQUEST_SIZE(NumEndpoints)) PURB Urb, __in USHORT NumEndpoints, __in UCHAR SettingNumber)
WDFIOTARGET GetHandle(VOID)
Definition: fxiotarget.hpp:307
FxRequest * request
VOID SetInfo(__in PUSBD_INTERFACE_INFORMATION Interface)
#define UCHAR_MAX
Definition: fxusbdevice.cpp:33
int options
Definition: main.c:106
FxUsbInterface * GetInterfaceFromNumber(__in UCHAR InterfaceNumber)
GLsizeiptr size
Definition: glext.h:5919
PFX_DRIVER_GLOBALS pFxDriverGlobals
#define ASSERT(a)
Definition: mode.c:44
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define for
Definition: utility.h:88
unsigned char UCHAR
Definition: xmlstorage.h:181
VOID CleanupInterfacePipesAndDelete(__in FxUsbInterface *UsbInterface)
_Must_inspect_result_ _In_ WDFUSBINTERFACE _In_opt_ PWDF_OBJECT_ATTRIBUTES PipesAttributes
Definition: wdfusb.h:2388
_Must_inspect_result_ NTSTATUS Init(__in CfxDeviceBase *Device)
struct _URB * PURB
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
FORCEINLINE LONGLONG WDF_REL_TIMEOUT_IN_SEC(_In_ ULONGLONG Time)
Definition: wdfcore.h:62
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
BOOLEAN IsInterfaceConfigured(VOID)
Definition: usb.h:529
unsigned short USHORT
Definition: pedump.c:61
SINGLE_LIST_ENTRY * pCur
USBD_HANDLE m_USBDHandle
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
#define NULL
Definition: types.h:112
VOID Reuse(__in NTSTATUS Status=STATUS_SUCCESS)
Definition: fxirpum.cpp:661
Definition: tftpd.h:85
VOID DeleteFromFailedCreate(VOID)
Definition: fxobject.cpp:391
USBD_CONFIGURATION_HANDLE m_ConfigHandle
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define STATUS_SUCCESS
Definition: shellext.h:65
FORCEINLINE VOID WDF_REQUEST_SEND_OPTIONS_SET_TIMEOUT(_Inout_ PWDF_REQUEST_SEND_OPTIONS Options, _In_ LONGLONG Timeout)
Definition: wdfrequest.h:421
void FxPoolFree(__in_xcount(ptr is at an offset from AllocationStart) PVOID ptr)
Definition: wdfpool.cpp:361
static SERVICE_STATUS status
Definition: service.c:31
#define TRACINGIOTARGET
Definition: dbgtrace.h:72
FxIrp * irp
struct _URB_SELECT_INTERFACE UrbSelectInterface
Definition: usb.h:532
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
Definition: ps.c:97

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;
1324  NTSTATUS status;
1325  ULONG i, size;