1 /*++ 2 3 Copyright (c) Microsoft. All rights reserved. 4 5 Module Name: 6 7 WudfDispatcher.h 8 9 Abstract: 10 11 This file contains the class definition of the WUDF dispatcher object. 12 13 Author: 14 15 16 17 Environment: 18 19 User mode only 20 21 Revision History: 22 23 24 25 --*/ 26 #pragma once 27 28 extern const GUID IID_FxMessageDispatch; 29 extern const GUID IID_FxMessageDispatch2; 30 31 class FxMessageDispatch; 32 33 class FxMessageDispatch : 34 public FxStump, 35 public IFxMessageDispatch2 36 { 37 // 38 // Manager functions. 39 // 40 private: 41 FxMessageDispatch( 42 _In_ FxDevice* Device 43 ) : 44 m_cRefs(1), 45 m_Device(Device) 46 { 47 } 48 49 public: 50 ~FxMessageDispatch() 51 { 52 // SAFE_RELEASE(m_Device); 53 } 54 55 static 56 NTSTATUS 57 _CreateAndInitialize( 58 _In_ PFX_DRIVER_GLOBALS DriverGlobals, 59 _In_ FxDevice* Device, 60 _Out_ FxMessageDispatch ** ppWudfDispatcher 61 ); 62 63 // 64 // IUnknown 65 // 66 public: 67 HRESULT 68 __stdcall 69 QueryInterface( 70 _In_ REFIID riid, 71 _Out_ LPVOID* ppvObject 72 ); 73 74 ULONG 75 __stdcall 76 AddRef(); 77 78 ULONG 79 __stdcall 80 Release(); 81 82 // 83 // IFxMessageDispatch 84 // 85 public: 86 virtual void __stdcall 87 DispatchPnP( 88 _In_ IWudfIrp * pIrp 89 ); 90 91 virtual void __stdcall 92 CreateFile( 93 _In_ IWudfIoIrp * pCreateIrp 94 ); 95 96 virtual void __stdcall 97 DeviceControl( 98 _In_ IWudfIoIrp * pIrp, 99 _In_opt_ IUnknown * pFxContext 100 ); 101 102 virtual void __stdcall 103 ReadFile( 104 _In_ IWudfIoIrp * pIrp, 105 _In_opt_ IUnknown * pFxContext 106 ); 107 108 virtual void __stdcall 109 WriteFile( 110 _In_ IWudfIoIrp * pIrp, 111 _In_opt_ IUnknown * pFxContext 112 ); 113 114 virtual void __stdcall 115 CleanupFile( 116 _In_ IWudfIoIrp * pIrp, 117 _In_ IUnknown * pFxContext 118 ); 119 120 virtual void __stdcall 121 CloseFile( 122 _In_ IWudfIoIrp * pIrp, 123 _In_ IUnknown * pFxContext 124 ); 125 126 virtual 127 VOID 128 __stdcall 129 GetPreferredTransferMode( 130 _Out_ UMINT::WDF_DEVICE_IO_BUFFER_RETRIEVAL *RetrievalMode, 131 _Out_ UMINT::WDF_DEVICE_IO_TYPE *RWPreference, 132 _Out_ UMINT::WDF_DEVICE_IO_TYPE *IoctlPreference 133 ); 134 135 virtual void __stdcall 136 FlushBuffers( 137 _In_ IWudfIoIrp * pIrp, 138 _In_opt_ IUnknown * pFxContext 139 ); 140 141 virtual void __stdcall 142 QueryInformationFile( 143 _In_ IWudfIoIrp * pIrp, 144 _In_opt_ IUnknown * pFxContext 145 ); 146 147 virtual void __stdcall 148 SetInformationFile( 149 _In_ IWudfIoIrp * pIrp, 150 _In_opt_ IUnknown * pFxContext 151 ); 152 153 virtual NTSTATUS __stdcall 154 ProcessWmiPowerQueryOrSetData( 155 _In_ RdWmiPowerAction Action, 156 _Out_ BOOLEAN *QueryResult 157 ); 158 159 // 160 // We should remove these methods from this interface. 161 // 162 virtual WUDF_INTERFACE_CONTEXT __stdcall 163 RemoteInterfaceArrival( 164 _In_ LPCGUID pDeviceInterfaceGuid, 165 _In_ PCWSTR pSymbolicLink 166 ); 167 168 virtual void __stdcall 169 RemoteInterfaceRemoval( 170 _In_ WUDF_INTERFACE_CONTEXT RemoteInterfaceID 171 ); 172 173 virtual BOOL __stdcall 174 TransportQueryID( 175 _In_ DWORD Id, 176 _In_ PVOID DataBuffer, 177 _In_ SIZE_T cbDataBufferSize 178 ); 179 180 virtual ULONG __stdcall 181 GetDirectTransferThreshold( 182 VOID 183 ); 184 185 virtual void __stdcall 186 PoFxDevicePowerRequired( 187 VOID 188 ); 189 190 virtual void __stdcall 191 PoFxDevicePowerNotRequired( 192 VOID 193 ); 194 195 // 196 // Additional public functions. 197 // 198 public: 199 // 200 // Returns the Dispatcher object from the given interface without 201 // incrementing the refcount. 202 // 203 static 204 FxMessageDispatch* 205 _GetObjFromItf( 206 _In_ IFxMessageDispatch* pIFxMessageDispatch 207 ); 208 209 // 210 // Returns the specified interface from the given object without 211 // incrementing the refcount. 212 // 213 static 214 IFxMessageDispatch* 215 _GetDispatcherItf( 216 _In_ FxMessageDispatch* pWudfDispatcher 217 ); 218 219 // 220 // Returns a weak ref to the embedded user-mode driver object. 221 // 222 PDRIVER_OBJECT_UM 223 GetDriverObject( 224 VOID 225 ) 226 { 227 return m_Device->GetDriver()->GetDriverObject(); 228 } 229 230 MdDeviceObject 231 GetDeviceObject( 232 VOID 233 ) 234 { 235 return m_Device->GetDeviceObject(); 236 } 237 238 // 239 // Data members. 240 // 241 private: 242 // 243 // Reference count for debugging purposes. The lifetime is managed by 244 // FxDevice. 245 // 246 LONG m_cRefs; 247 248 // 249 // Device object associated with this dispatcher object. 250 // 251 FxDevice * m_Device; 252 }; 253 254