1 /*++ 2 3 Copyright (c) Microsoft Corporation 4 5 Module Name: 6 7 FxWmiDataBlock.hpp 8 9 Abstract: 10 11 This module implements the WMI data block object 12 13 Author: 14 15 16 17 18 Environment: 19 20 Both kernel and user mode 21 22 Revision History: 23 24 25 --*/ 26 27 #ifndef _FXWMIPROVIDER_H_ 28 #define _FXWMIPROVIDER_H_ 29 30 31 struct FxWmiProviderFunctionControlCallback : public FxCallback { 32 33 PFN_WDF_WMI_PROVIDER_FUNCTION_CONTROL m_Method; 34 35 FxWmiProviderFunctionControlCallback( 36 PFX_DRIVER_GLOBALS FxDriverGlobals 37 ) : 38 FxCallback(FxDriverGlobals), 39 m_Method(NULL) 40 { 41 } 42 43 ~FxWmiProviderFunctionControlCallback() 44 { 45 } 46 47 _Must_inspect_result_ 48 NTSTATUS 49 Invoke( 50 __in WDFDEVICE Device, 51 __in WDFWMIPROVIDER WmiProvider, 52 __in WDF_WMI_PROVIDER_CONTROL Control, 53 __in BOOLEAN Enable 54 ) 55 { 56 NTSTATUS status; 57 58 UNREFERENCED_PARAMETER(Device); 59 60 if (m_Method != NULL) { 61 CallbackStart(); 62 status = m_Method(WmiProvider, Control, Enable); 63 CallbackEnd(); 64 } 65 else { 66 status = STATUS_SUCCESS; 67 } 68 69 return status; 70 } 71 }; 72 73 class FxWmiProvider : public FxNonPagedObject { 74 75 friend FxWmiIrpHandler; 76 77 public: 78 FxWmiProvider( 79 __in PFX_DRIVER_GLOBALS FxDriverGlobals, 80 __in PWDF_WMI_PROVIDER_CONFIG Config, 81 __in CfxDevice* Device 82 ); 83 84 ~FxWmiProvider(); 85 86 static 87 _Must_inspect_result_ 88 NTSTATUS 89 _Create( 90 __in PFX_DRIVER_GLOBALS CallersGlobals, 91 __in WDFDEVICE Device, 92 __in_opt PWDF_OBJECT_ATTRIBUTES ProviderAttributes, 93 __in PWDF_WMI_PROVIDER_CONFIG WmiProviderConfig, 94 __out WDFWMIPROVIDER* WmiProvider, 95 __out FxWmiProvider** Provider 96 ); 97 98 CfxDevice* 99 GetDevice( 100 VOID 101 ) 102 { 103 return m_Parent->GetDevice(); 104 } 105 106 GUID* 107 GetGUID( 108 VOID 109 ) 110 { 111 return &m_Guid; 112 } 113 114 ULONG 115 GetFlags( 116 VOID 117 ) 118 { 119 return m_Flags; 120 } 121 122 ULONG 123 GetMinInstanceBufferSize( 124 VOID 125 ) 126 { 127 return m_MinInstanceBufferSize; 128 } 129 130 ULONG 131 GetRegistrationFlagsLocked( 132 VOID 133 ); 134 135 BOOLEAN 136 IsEventOnly( 137 VOID 138 ) 139 { 140 return FLAG_TO_BOOL(m_Flags, WdfWmiProviderEventOnly); 141 } 142 143 BOOLEAN 144 IsEnabled( 145 __in WDF_WMI_PROVIDER_CONTROL Control 146 ) 147 { 148 switch (Control) { 149 case WdfWmiEventControl: return m_EventControlEnabled; 150 case WdfWmiInstanceControl: return m_DataBlockControlEnabled; 151 default: ASSERT(FALSE); return FALSE; 152 } 153 } 154 155 ULONGLONG 156 GetTracingHandle( 157 VOID 158 ) 159 { 160 return m_TracingHandle; 161 } 162 163 VOID 164 SetTracingHandle( 165 __in ULONGLONG TracingHandle 166 ) 167 { 168 m_TracingHandle = TracingHandle; 169 } 170 171 WDFWMIPROVIDER 172 GetHandle( 173 VOID 174 ) 175 { 176 return (WDFWMIPROVIDER) GetObjectHandle(); 177 } 178 179 BOOLEAN 180 IsFunctionControlSupported( 181 VOID 182 ) 183 { 184 return m_FunctionControl.m_Method != NULL; 185 } 186 187 _Must_inspect_result_ 188 NTSTATUS 189 FunctionControl( 190 __in WDF_WMI_PROVIDER_CONTROL Control, 191 __in BOOLEAN Enable 192 ); 193 194 _Must_inspect_result_ 195 NTSTATUS 196 AddInstance( 197 __in FxWmiInstance* Instance, 198 __in BOOLEAN NoErrorIfPresent = FALSE 199 ); 200 201 VOID 202 RemoveInstance( 203 __in FxWmiInstance* Instance 204 ); 205 206 ULONG 207 GetInstanceIndex( 208 __in FxWmiInstance* Instance 209 ); 210 211 _Must_inspect_result_ 212 FxWmiInstance* 213 GetInstanceReferenced( 214 __in ULONG Index, 215 __in PVOID Tag 216 ); 217 218 _Must_inspect_result_ 219 FxWmiInstance* 220 GetInstanceReferencedLocked( 221 __in ULONG Index, 222 __in PVOID Tag 223 ); 224 225 // begin FxObject overrides 226 virtual 227 BOOLEAN 228 Dispose( 229 VOID 230 ); 231 // end FxObject overrides 232 233 protected: 234 enum AddInstanceAction { 235 AddInstanceToTail, 236 AddInstanceToHead 237 }; 238 239 _Must_inspect_result_ 240 NTSTATUS 241 AddInstanceLocked( 242 __in FxWmiInstance* Instance, 243 __in BOOLEAN NoErrorIfPresent, 244 __out PBOOLEAN Update, 245 __in AddInstanceAction Action = AddInstanceToTail 246 ); 247 248 protected: 249 // 250 // List entry used by FxWmiIrpHandler to hold the list of WMI providers 251 // 252 LIST_ENTRY m_ListEntry; 253 254 LIST_ENTRY m_InstanceListHead; 255 256 ULONG m_NumInstances; 257 258 FxWmiIrpHandler* m_Parent; 259 260 GUID m_Guid; 261 262 263 264 265 266 ULONGLONG m_TracingHandle; 267 268 ULONG m_MinInstanceBufferSize; 269 270 union { 271 // 272 // Set with values from WDF_WMI_PROVIDER_FLAGS 273 // 274 ULONG m_Flags; 275 276 // 277 // Not used by the code, but by the debug extension 278 // 279 struct { 280 ULONG EventOnly : 1; 281 ULONG Expensive : 1; 282 ULONG Tracing : 1; 283 } m_FlagsByName; 284 }; 285 286 FxWmiProviderFunctionControlCallback m_FunctionControl; 287 288 BOOLEAN m_EventControlEnabled; 289 290 BOOLEAN m_DataBlockControlEnabled; 291 292 BOOLEAN m_RemoveGuid; 293 }; 294 295 #endif // _FXWMIPROVIDER_H_ 296