1 /*++ 2 3 Copyright (c) Microsoft Corporation. All rights reserved. 4 5 _WdfVersionBuild_ 6 7 Module Name: 8 9 WdfWMI.h 10 11 Abstract: 12 13 This is the C interface for WMI support 14 15 Environment: 16 17 kernel mode only 18 19 Revision History: 20 21 --*/ 22 23 // 24 // NOTE: This header is generated by stubwork. Please make any 25 // modifications to the corresponding template files 26 // (.x or .y) and use stubwork to regenerate the header 27 // 28 29 #ifndef _WDFWMI_H_ 30 #define _WDFWMI_H_ 31 32 #ifndef WDF_EXTERN_C 33 #ifdef __cplusplus 34 #define WDF_EXTERN_C extern "C" 35 #define WDF_EXTERN_C_START extern "C" { 36 #define WDF_EXTERN_C_END } 37 #else 38 #define WDF_EXTERN_C 39 #define WDF_EXTERN_C_START 40 #define WDF_EXTERN_C_END 41 #endif 42 #endif 43 44 WDF_EXTERN_C_START 45 46 47 48 #if (NTDDI_VERSION >= NTDDI_WIN2K) 49 50 typedef enum _WDF_WMI_PROVIDER_CONTROL { 51 WdfWmiControlInvalid = 0, 52 WdfWmiEventControl, 53 WdfWmiInstanceControl, 54 } WDF_WMI_PROVIDER_CONTROL; 55 56 // 57 // WdfWmiProviderExpensive: 58 // The provider's operations are expensive in terms of resources 59 // 60 // WdfWmiProviderReadOnly: 61 // The provider is read only. No set or set data item callbacks will be 62 // made on all instances of this provider. 63 // 64 // WdfWmiProviderEventOnly: 65 // Data item is being used to fire events only. It will not receive any 66 // callbacks on it to get / set / execute buffers. 67 // 68 typedef enum _WDF_WMI_PROVIDER_FLAGS { 69 WdfWmiProviderEventOnly = 0x0001, 70 WdfWmiProviderExpensive = 0x0002, 71 WdfWmiProviderTracing = 0x0004, 72 WdfWmiProviderValidFlags = WdfWmiProviderEventOnly | WdfWmiProviderExpensive | WdfWmiProviderTracing, 73 } WDF_WMI_PROVIDER_FLAGS; 74 75 76 77 typedef 78 _Function_class_(EVT_WDF_WMI_INSTANCE_QUERY_INSTANCE) 79 _IRQL_requires_same_ 80 _IRQL_requires_max_(PASSIVE_LEVEL) 81 NTSTATUS 82 STDCALL 83 EVT_WDF_WMI_INSTANCE_QUERY_INSTANCE( 84 _In_ 85 WDFWMIINSTANCE WmiInstance, 86 _In_ 87 ULONG OutBufferSize, 88 _Out_writes_bytes_to_(OutBufferSize, *BufferUsed) 89 PVOID OutBuffer, 90 _Out_ 91 PULONG BufferUsed 92 ); 93 94 typedef EVT_WDF_WMI_INSTANCE_QUERY_INSTANCE *PFN_WDF_WMI_INSTANCE_QUERY_INSTANCE; 95 96 typedef 97 _Function_class_(EVT_WDF_WMI_INSTANCE_SET_INSTANCE) 98 _IRQL_requires_same_ 99 _IRQL_requires_max_(PASSIVE_LEVEL) 100 NTSTATUS 101 STDCALL 102 EVT_WDF_WMI_INSTANCE_SET_INSTANCE( 103 _In_ 104 WDFWMIINSTANCE WmiInstance, 105 _In_ 106 ULONG InBufferSize, 107 _In_reads_bytes_(InBufferSize) 108 PVOID InBuffer 109 ); 110 111 typedef EVT_WDF_WMI_INSTANCE_SET_INSTANCE *PFN_WDF_WMI_INSTANCE_SET_INSTANCE; 112 113 typedef 114 _Function_class_(EVT_WDF_WMI_INSTANCE_SET_ITEM) 115 _IRQL_requires_same_ 116 _IRQL_requires_max_(PASSIVE_LEVEL) 117 NTSTATUS 118 STDCALL 119 EVT_WDF_WMI_INSTANCE_SET_ITEM( 120 _In_ 121 WDFWMIINSTANCE WmiInstance, 122 _In_ 123 ULONG DataItemId, 124 _In_ 125 ULONG InBufferSize, 126 _In_reads_bytes_(InBufferSize) 127 PVOID InBuffer 128 ); 129 130 typedef EVT_WDF_WMI_INSTANCE_SET_ITEM *PFN_WDF_WMI_INSTANCE_SET_ITEM; 131 132 typedef 133 _Function_class_(EVT_WDF_WMI_INSTANCE_EXECUTE_METHOD) 134 _IRQL_requires_same_ 135 _IRQL_requires_max_(PASSIVE_LEVEL) 136 NTSTATUS 137 STDCALL 138 EVT_WDF_WMI_INSTANCE_EXECUTE_METHOD( 139 _In_ 140 WDFWMIINSTANCE WmiInstance, 141 _In_ 142 ULONG MethodId, 143 _In_ 144 ULONG InBufferSize, 145 _In_ 146 ULONG OutBufferSize, 147 _When_(InBufferSize >= OutBufferSize, _Inout_updates_bytes_(InBufferSize)) 148 _When_(InBufferSize < OutBufferSize, _Inout_updates_bytes_(OutBufferSize)) 149 PVOID Buffer, 150 _Out_ 151 PULONG BufferUsed 152 ); 153 154 typedef EVT_WDF_WMI_INSTANCE_EXECUTE_METHOD *PFN_WDF_WMI_INSTANCE_EXECUTE_METHOD; 155 156 typedef 157 _Function_class_(EVT_WDF_WMI_PROVIDER_FUNCTION_CONTROL) 158 _IRQL_requires_same_ 159 _IRQL_requires_max_(PASSIVE_LEVEL) 160 NTSTATUS 161 STDCALL 162 EVT_WDF_WMI_PROVIDER_FUNCTION_CONTROL( 163 _In_ 164 WDFWMIPROVIDER WmiProvider, 165 _In_ 166 WDF_WMI_PROVIDER_CONTROL Control, 167 _In_ 168 BOOLEAN Enable 169 ); 170 171 typedef EVT_WDF_WMI_PROVIDER_FUNCTION_CONTROL *PFN_WDF_WMI_PROVIDER_FUNCTION_CONTROL; 172 173 typedef struct _WDF_WMI_PROVIDER_CONFIG { 174 // 175 // Size of this structure in bytes 176 // 177 ULONG Size; 178 179 // 180 // The GUID being registered 181 // 182 GUID Guid; 183 184 // 185 // Combination of values from the enum WDF_WMI_PROVIDER_FLAGS 186 // 187 ULONG Flags; 188 189 // 190 // Minimum expected buffer size for query and set instance requests. 191 // Ignored if WdfWmiProviderEventOnly is set in Flags. 192 // 193 ULONG MinInstanceBufferSize; 194 195 // 196 // Callback when caller is opening a provider which ha been marked as 197 // expensive or when a caller is interested in events. 198 // 199 PFN_WDF_WMI_PROVIDER_FUNCTION_CONTROL EvtWmiProviderFunctionControl; 200 201 } WDF_WMI_PROVIDER_CONFIG, *PWDF_WMI_PROVIDER_CONFIG; 202 203 FORCEINLINE 204 VOID 205 WDF_WMI_PROVIDER_CONFIG_INIT( 206 _Out_ PWDF_WMI_PROVIDER_CONFIG Config, 207 _In_ CONST GUID* Guid 208 ) 209 { 210 RtlZeroMemory(Config, sizeof(WDF_WMI_PROVIDER_CONFIG)); 211 212 Config->Size = sizeof(WDF_WMI_PROVIDER_CONFIG); 213 RtlCopyMemory(&Config->Guid, Guid, sizeof(GUID)); 214 } 215 216 typedef struct _WDF_WMI_INSTANCE_CONFIG { 217 // 218 // Size of the structure in bytes 219 // 220 ULONG Size; 221 222 // 223 // Optional parameter. If NULL, ProviderConfig must be set to a valid pointer 224 // value. If specified, indicates the provider to create an instance for. 225 // 226 WDFWMIPROVIDER Provider; 227 228 // 229 // Optional parameter. If NULL, Provider must be set to a valid handle 230 // value. If specifeid, indicates the configuration for a provider to be 231 // created and for this instance to be associated with. 232 // 233 PWDF_WMI_PROVIDER_CONFIG ProviderConfig; 234 235 // 236 // If the Provider is configured as read only and this field is set to TRUE, 237 // the EvtWmiInstanceQueryInstance is ignored and WDF will blindly copy the 238 // context associated with this instance (using RtlCopyMemory, with no locks 239 // held) into the query buffer. 240 // 241 BOOLEAN UseContextForQuery; 242 243 // 244 // If TRUE, the instance will be registered as well as created. 245 // 246 BOOLEAN Register; 247 248 // 249 // Callback when caller wants to query the entire data item's buffer. 250 // 251 PFN_WDF_WMI_INSTANCE_QUERY_INSTANCE EvtWmiInstanceQueryInstance; 252 253 // 254 // Callback when caller wants to set the entire data item's buffer. 255 // 256 PFN_WDF_WMI_INSTANCE_SET_INSTANCE EvtWmiInstanceSetInstance; 257 258 // 259 // Callback when caller wants to set a single field in the data item's buffer 260 // 261 PFN_WDF_WMI_INSTANCE_SET_ITEM EvtWmiInstanceSetItem; 262 263 // 264 // Callback when caller wants to execute a method on the data item. 265 // 266 PFN_WDF_WMI_INSTANCE_EXECUTE_METHOD EvtWmiInstanceExecuteMethod; 267 268 } WDF_WMI_INSTANCE_CONFIG, *PWDF_WMI_INSTANCE_CONFIG; 269 270 271 FORCEINLINE 272 VOID 273 WDF_WMI_INSTANCE_CONFIG_INIT_PROVIDER( 274 _Out_ PWDF_WMI_INSTANCE_CONFIG Config, 275 _In_ WDFWMIPROVIDER Provider 276 ) 277 { 278 RtlZeroMemory(Config, sizeof(WDF_WMI_INSTANCE_CONFIG)); 279 Config->Size = sizeof(WDF_WMI_INSTANCE_CONFIG); 280 281 Config->Provider = Provider; 282 } 283 284 FORCEINLINE 285 VOID 286 WDF_WMI_INSTANCE_CONFIG_INIT_PROVIDER_CONFIG( 287 _Out_ PWDF_WMI_INSTANCE_CONFIG Config, 288 _In_ PWDF_WMI_PROVIDER_CONFIG ProviderConfig 289 ) 290 { 291 RtlZeroMemory(Config, sizeof(WDF_WMI_INSTANCE_CONFIG)); 292 Config->Size = sizeof(WDF_WMI_INSTANCE_CONFIG); 293 294 Config->ProviderConfig = ProviderConfig; 295 } 296 297 FORCEINLINE 298 NTSTATUS 299 WDF_WMI_BUFFER_APPEND_STRING( 300 _Out_writes_bytes_(BufferLength) PVOID Buffer, 301 _In_ ULONG BufferLength, 302 _In_ PCUNICODE_STRING String, 303 _Out_ PULONG RequiredSize 304 ) 305 { 306 // 307 // Compute the length of buffer we need to use. Upon error the caller can 308 // use this length to report the required length. On success, the caller 309 // can use this length to know how many bytes were written. 310 // 311 *RequiredSize = String->Length + sizeof(USHORT); 312 313 // 314 // UNICODE_STRING.Length is the length of the string in bytes, not characters 315 // 316 317 // First check to see if there is enough space 318 // 1) to store the length of the string 319 // 2) to store the string itself 320 // 321 if (BufferLength < (String->Length + sizeof(USHORT))) { 322 // 323 // Not enough room in the string, report back how big a buffer is 324 // required. 325 // 326 return STATUS_BUFFER_TOO_SMALL; 327 } 328 329 // 330 // Store the length of the string 331 // 332 *(USHORT *) Buffer = String->Length; 333 334 // 335 // Copy the string to the buffer 336 // 337 RtlCopyMemory(WDF_PTR_ADD_OFFSET(Buffer, sizeof(USHORT)), 338 String->Buffer, 339 String->Length); 340 341 return STATUS_SUCCESS; 342 } 343 344 // 345 // WDF Function: WdfWmiProviderCreate 346 // 347 typedef 348 _Must_inspect_result_ 349 _IRQL_requires_max_(DISPATCH_LEVEL) 350 WDFAPI 351 NTSTATUS 352 (STDCALL *PFN_WDFWMIPROVIDERCREATE)( 353 _In_ 354 PWDF_DRIVER_GLOBALS DriverGlobals, 355 _In_ 356 WDFDEVICE Device, 357 _In_ 358 PWDF_WMI_PROVIDER_CONFIG WmiProviderConfig, 359 _In_opt_ 360 PWDF_OBJECT_ATTRIBUTES ProviderAttributes, 361 _Out_ 362 WDFWMIPROVIDER* WmiProvider 363 ); 364 365 _Must_inspect_result_ 366 _IRQL_requires_max_(DISPATCH_LEVEL) 367 FORCEINLINE 368 NTSTATUS 369 WdfWmiProviderCreate( 370 _In_ 371 WDFDEVICE Device, 372 _In_ 373 PWDF_WMI_PROVIDER_CONFIG WmiProviderConfig, 374 _In_opt_ 375 PWDF_OBJECT_ATTRIBUTES ProviderAttributes, 376 _Out_ 377 WDFWMIPROVIDER* WmiProvider 378 ) 379 { 380 return ((PFN_WDFWMIPROVIDERCREATE) WdfFunctions[WdfWmiProviderCreateTableIndex])(WdfDriverGlobals, Device, WmiProviderConfig, ProviderAttributes, WmiProvider); 381 } 382 383 // 384 // WDF Function: WdfWmiProviderGetDevice 385 // 386 typedef 387 _IRQL_requires_max_(DISPATCH_LEVEL) 388 WDFAPI 389 WDFDEVICE 390 (STDCALL *PFN_WDFWMIPROVIDERGETDEVICE)( 391 _In_ 392 PWDF_DRIVER_GLOBALS DriverGlobals, 393 _In_ 394 WDFWMIPROVIDER WmiProvider 395 ); 396 397 _IRQL_requires_max_(DISPATCH_LEVEL) 398 FORCEINLINE 399 WDFDEVICE 400 WdfWmiProviderGetDevice( 401 _In_ 402 WDFWMIPROVIDER WmiProvider 403 ) 404 { 405 return ((PFN_WDFWMIPROVIDERGETDEVICE) WdfFunctions[WdfWmiProviderGetDeviceTableIndex])(WdfDriverGlobals, WmiProvider); 406 } 407 408 // 409 // WDF Function: WdfWmiProviderIsEnabled 410 // 411 typedef 412 _IRQL_requires_max_(DISPATCH_LEVEL) 413 WDFAPI 414 BOOLEAN 415 (STDCALL *PFN_WDFWMIPROVIDERISENABLED)( 416 _In_ 417 PWDF_DRIVER_GLOBALS DriverGlobals, 418 _In_ 419 WDFWMIPROVIDER WmiProvider, 420 _In_ 421 WDF_WMI_PROVIDER_CONTROL ProviderControl 422 ); 423 424 _IRQL_requires_max_(DISPATCH_LEVEL) 425 FORCEINLINE 426 BOOLEAN 427 WdfWmiProviderIsEnabled( 428 _In_ 429 WDFWMIPROVIDER WmiProvider, 430 _In_ 431 WDF_WMI_PROVIDER_CONTROL ProviderControl 432 ) 433 { 434 return ((PFN_WDFWMIPROVIDERISENABLED) WdfFunctions[WdfWmiProviderIsEnabledTableIndex])(WdfDriverGlobals, WmiProvider, ProviderControl); 435 } 436 437 // 438 // WDF Function: WdfWmiProviderGetTracingHandle 439 // 440 typedef 441 _IRQL_requires_max_(DISPATCH_LEVEL) 442 WDFAPI 443 ULONGLONG 444 (STDCALL *PFN_WDFWMIPROVIDERGETTRACINGHANDLE)( 445 _In_ 446 PWDF_DRIVER_GLOBALS DriverGlobals, 447 _In_ 448 WDFWMIPROVIDER WmiProvider 449 ); 450 451 _IRQL_requires_max_(DISPATCH_LEVEL) 452 FORCEINLINE 453 ULONGLONG 454 WdfWmiProviderGetTracingHandle( 455 _In_ 456 WDFWMIPROVIDER WmiProvider 457 ) 458 { 459 return ((PFN_WDFWMIPROVIDERGETTRACINGHANDLE) WdfFunctions[WdfWmiProviderGetTracingHandleTableIndex])(WdfDriverGlobals, WmiProvider); 460 } 461 462 // 463 // WDF Function: WdfWmiInstanceCreate 464 // 465 typedef 466 _Must_inspect_result_ 467 _IRQL_requires_max_(DISPATCH_LEVEL) 468 WDFAPI 469 NTSTATUS 470 (STDCALL *PFN_WDFWMIINSTANCECREATE)( 471 _In_ 472 PWDF_DRIVER_GLOBALS DriverGlobals, 473 _In_ 474 WDFDEVICE Device, 475 _In_ 476 PWDF_WMI_INSTANCE_CONFIG InstanceConfig, 477 _In_opt_ 478 PWDF_OBJECT_ATTRIBUTES InstanceAttributes, 479 _Out_opt_ 480 WDFWMIINSTANCE* Instance 481 ); 482 483 _Must_inspect_result_ 484 _IRQL_requires_max_(DISPATCH_LEVEL) 485 FORCEINLINE 486 NTSTATUS 487 WdfWmiInstanceCreate( 488 _In_ 489 WDFDEVICE Device, 490 _In_ 491 PWDF_WMI_INSTANCE_CONFIG InstanceConfig, 492 _In_opt_ 493 PWDF_OBJECT_ATTRIBUTES InstanceAttributes, 494 _Out_opt_ 495 WDFWMIINSTANCE* Instance 496 ) 497 { 498 return ((PFN_WDFWMIINSTANCECREATE) WdfFunctions[WdfWmiInstanceCreateTableIndex])(WdfDriverGlobals, Device, InstanceConfig, InstanceAttributes, Instance); 499 } 500 501 // 502 // WDF Function: WdfWmiInstanceRegister 503 // 504 typedef 505 _Must_inspect_result_ 506 _IRQL_requires_max_(PASSIVE_LEVEL) 507 WDFAPI 508 NTSTATUS 509 (STDCALL *PFN_WDFWMIINSTANCEREGISTER)( 510 _In_ 511 PWDF_DRIVER_GLOBALS DriverGlobals, 512 _In_ 513 WDFWMIINSTANCE WmiInstance 514 ); 515 516 _Must_inspect_result_ 517 _IRQL_requires_max_(PASSIVE_LEVEL) 518 FORCEINLINE 519 NTSTATUS 520 WdfWmiInstanceRegister( 521 _In_ 522 WDFWMIINSTANCE WmiInstance 523 ) 524 { 525 return ((PFN_WDFWMIINSTANCEREGISTER) WdfFunctions[WdfWmiInstanceRegisterTableIndex])(WdfDriverGlobals, WmiInstance); 526 } 527 528 // 529 // WDF Function: WdfWmiInstanceDeregister 530 // 531 typedef 532 _IRQL_requires_max_(PASSIVE_LEVEL) 533 WDFAPI 534 VOID 535 (STDCALL *PFN_WDFWMIINSTANCEDEREGISTER)( 536 _In_ 537 PWDF_DRIVER_GLOBALS DriverGlobals, 538 _In_ 539 WDFWMIINSTANCE WmiInstance 540 ); 541 542 _IRQL_requires_max_(PASSIVE_LEVEL) 543 FORCEINLINE 544 VOID 545 WdfWmiInstanceDeregister( 546 _In_ 547 WDFWMIINSTANCE WmiInstance 548 ) 549 { 550 ((PFN_WDFWMIINSTANCEDEREGISTER) WdfFunctions[WdfWmiInstanceDeregisterTableIndex])(WdfDriverGlobals, WmiInstance); 551 } 552 553 // 554 // WDF Function: WdfWmiInstanceGetDevice 555 // 556 typedef 557 _IRQL_requires_max_(DISPATCH_LEVEL) 558 WDFAPI 559 WDFDEVICE 560 (STDCALL *PFN_WDFWMIINSTANCEGETDEVICE)( 561 _In_ 562 PWDF_DRIVER_GLOBALS DriverGlobals, 563 _In_ 564 WDFWMIINSTANCE WmiInstance 565 ); 566 567 _IRQL_requires_max_(DISPATCH_LEVEL) 568 FORCEINLINE 569 WDFDEVICE 570 WdfWmiInstanceGetDevice( 571 _In_ 572 WDFWMIINSTANCE WmiInstance 573 ) 574 { 575 return ((PFN_WDFWMIINSTANCEGETDEVICE) WdfFunctions[WdfWmiInstanceGetDeviceTableIndex])(WdfDriverGlobals, WmiInstance); 576 } 577 578 // 579 // WDF Function: WdfWmiInstanceGetProvider 580 // 581 typedef 582 _IRQL_requires_max_(DISPATCH_LEVEL) 583 WDFAPI 584 WDFWMIPROVIDER 585 (STDCALL *PFN_WDFWMIINSTANCEGETPROVIDER)( 586 _In_ 587 PWDF_DRIVER_GLOBALS DriverGlobals, 588 _In_ 589 WDFWMIINSTANCE WmiInstance 590 ); 591 592 _IRQL_requires_max_(DISPATCH_LEVEL) 593 FORCEINLINE 594 WDFWMIPROVIDER 595 WdfWmiInstanceGetProvider( 596 _In_ 597 WDFWMIINSTANCE WmiInstance 598 ) 599 { 600 return ((PFN_WDFWMIINSTANCEGETPROVIDER) WdfFunctions[WdfWmiInstanceGetProviderTableIndex])(WdfDriverGlobals, WmiInstance); 601 } 602 603 // 604 // WDF Function: WdfWmiInstanceFireEvent 605 // 606 typedef 607 _Must_inspect_result_ 608 _IRQL_requires_max_(APC_LEVEL) 609 WDFAPI 610 NTSTATUS 611 (STDCALL *PFN_WDFWMIINSTANCEFIREEVENT)( 612 _In_ 613 PWDF_DRIVER_GLOBALS DriverGlobals, 614 _In_ 615 WDFWMIINSTANCE WmiInstance, 616 _In_opt_ 617 ULONG EventDataSize, 618 _In_reads_bytes_opt_(EventDataSize) 619 PVOID EventData 620 ); 621 622 _Must_inspect_result_ 623 _IRQL_requires_max_(APC_LEVEL) 624 FORCEINLINE 625 NTSTATUS 626 WdfWmiInstanceFireEvent( 627 _In_ 628 WDFWMIINSTANCE WmiInstance, 629 _In_opt_ 630 ULONG EventDataSize, 631 _In_reads_bytes_opt_(EventDataSize) 632 PVOID EventData 633 ) 634 { 635 return ((PFN_WDFWMIINSTANCEFIREEVENT) WdfFunctions[WdfWmiInstanceFireEventTableIndex])(WdfDriverGlobals, WmiInstance, EventDataSize, EventData); 636 } 637 638 639 640 #endif // (NTDDI_VERSION >= NTDDI_WIN2K) 641 642 643 644 WDF_EXTERN_C_END 645 646 #endif // _WDFWMI_H_ 647 648