1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
|
/*++
Copyright (c) Microsoft Corporation. All rights reserved.
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
Module Name:
WmiHandler.c
Abstract:
--
Environment:
Kernel mode
--*/
#include "WmiSamp.h"
#define MOFRESOURCENAME L"MofResourceName"
//
// Private methods.
//
EVT_WDF_WMI_INSTANCE_QUERY_INSTANCE EvtWmiClass1DataQueryInstance;
EVT_WDF_WMI_INSTANCE_QUERY_INSTANCE EvtWmiClass2DataQueryInstance;
EVT_WDF_WMI_INSTANCE_QUERY_INSTANCE EvtWmiClass3DataQueryInstance;
EVT_WDF_WMI_INSTANCE_QUERY_INSTANCE EvtWmiClass5DataQueryInstance;
EVT_WDF_WMI_INSTANCE_QUERY_INSTANCE EvtWmiClass6DataQueryInstance;
EVT_WDF_WMI_INSTANCE_SET_ITEM EvtWmiClass1DataSetItem;
EVT_WDF_WMI_INSTANCE_SET_INSTANCE EvtWmiClass1DataSetInstance;
EVT_WDF_WMI_INSTANCE_SET_INSTANCE EvtWmiClass2DataSetInstance;
EVT_WDF_WMI_INSTANCE_SET_INSTANCE EvtWmiClass3DataSetInstance;
EVT_WDF_WMI_INSTANCE_SET_INSTANCE EvtWmiClass5DataSetInstance;
EVT_WDF_WMI_INSTANCE_SET_INSTANCE EvtWmiClass6DataSetInstance;
EVT_WDF_WMI_INSTANCE_EXECUTE_METHOD EvtWmiClass1ExecuteMethod;
#ifdef ALLOC_PRAGMA
#pragma alloc_text (PAGE, WmiSampWmiRegistration)
#pragma alloc_text (PAGE, EvtWmiClass1DataQueryInstance)
#pragma alloc_text (PAGE, EvtWmiClass1DataSetInstance)
#pragma alloc_text (PAGE, EvtWmiClass1DataSetItem)
#pragma alloc_text (PAGE, EvtWmiClass1ExecuteMethod)
#pragma alloc_text (PAGE, EvtWmiClass2DataQueryInstance)
#pragma alloc_text (PAGE, EvtWmiClass2DataSetInstance)
#pragma alloc_text (PAGE, EvtWmiClass3DataQueryInstance)
#pragma alloc_text (PAGE, EvtWmiClass3DataSetInstance)
#pragma alloc_text (PAGE, EvtWmiClass5DataQueryInstance)
#pragma alloc_text (PAGE, EvtWmiClass5DataSetInstance)
#pragma alloc_text (PAGE, EvtWmiClass6DataQueryInstance)
#pragma alloc_text (PAGE, EvtWmiClass6DataSetInstance)
#endif
//
// The SampleInstanceConfig defines an array of data set used for the creation
// of WMI instances.
//
WMI_SAMPLE_INSTANCE_CONFIG SampleInstanceConfig[] = {
{
WmiSampleClass1Guid,
WmiSampleClass1_SIZE,
EvtWmiClass1DataQueryInstance,
EvtWmiClass1DataSetInstance,
EvtWmiClass1DataSetItem,
EvtWmiClass1ExecuteMethod
},
{
WmiSampleClass2Guid,
WmiSampleClass2_SIZE,
EvtWmiClass2DataQueryInstance,
EvtWmiClass2DataSetInstance,
NULL,
NULL
},
{
WmiSampleClass5Guid,
WmiSampleClass5_SIZE,
EvtWmiClass5DataQueryInstance,
EvtWmiClass5DataSetInstance,
NULL,
NULL
},
{
WmiSampleClass6Guid,
WmiSampleClass6_SIZE,
EvtWmiClass6DataQueryInstance,
EvtWmiClass6DataSetInstance,
NULL,
NULL
},
};
//
// The DynamicInstanceConfig defines the data set used for the dynamic creation
// of WMI instances.
//
WMI_SAMPLE_INSTANCE_CONFIG DynamicInstanceConfig = {
WmiSampleClass3Guid,
WmiSampleClass3_SIZE,
EvtWmiClass3DataQueryInstance,
EvtWmiClass3DataSetInstance,
NULL,
NULL
};
NTSTATUS
WmiSampWmiRegistration(
_In_ WDFDEVICE Device
)
/*++
Routine Description:
This function creates WMI provider instances for handling the WMI irps to
the driver.
Arguments:
Device - The Framework device object for which the WMI provider instances
are to be created and registered. This device object will be the parent
object of the new WMI instance objects.
Return Value:
NT Status code.
--*/
{
NTSTATUS status;
ULONG i;
WDF_WMI_PROVIDER_CONFIG providerConfig;
WDF_WMI_INSTANCE_CONFIG instanceConfig;
DECLARE_CONST_UNICODE_STRING(mofResourceName, MOFRESOURCENAME);
PAGED_CODE();
//
// Register the MOF resource names of any customized WMI data providers
// that are not defined in wmicore.mof.
//
status = WdfDeviceAssignMofResourceName(Device, &mofResourceName);
if (!NT_SUCCESS(status)) {
DebugPrint(("[WmiSamp] Status = 0x%08x, WmiSampWmiRegistration\n", status));
return status;
}
//
// Create a WMI instance object for each instance of each data block that
// the driver supports for a device.
//
for (i = 0; i < ARRAYSIZE(SampleInstanceConfig); i++) {
//
// Initialize the config structures for the Provider and the Instance
// and define event callback functions that support a WMI client's
// requests to access the driver's WMI data blocks.
//
WDF_WMI_PROVIDER_CONFIG_INIT(&providerConfig, &SampleInstanceConfig[i].Guid);
providerConfig.MinInstanceBufferSize = SampleInstanceConfig[i].MinSize;
//
// The WDFWMIPROVIDER handle is needed if multiple instances for the provider
// has to be created or if the instances have to be created sometime after
// the provider is created. In case below, the provider handle is not needed
// because only one instance is needed and can be created when the provider
// is created.
//
WDF_WMI_INSTANCE_CONFIG_INIT_PROVIDER_CONFIG(&instanceConfig, &providerConfig);
//
// Create a Provider object as part of the Instance creation call by setting
// the Register value in the Instance Config to TRUE. This eliminates the
// need to call WdfWmiProviderRegister.
//
instanceConfig.Register = TRUE;
instanceConfig.EvtWmiInstanceQueryInstance = SampleInstanceConfig[i].EvtWmiInstanceQueryInstance;
instanceConfig.EvtWmiInstanceSetInstance = SampleInstanceConfig[i].EvtWmiInstanceSetInstance;
instanceConfig.EvtWmiInstanceSetItem = SampleInstanceConfig[i].EvtWmiInstanceSetItem;
instanceConfig.EvtWmiInstanceExecuteMethod = SampleInstanceConfig[i].EvtWmiInstanceExecuteMethod;
//
// Create the WMI instance object for this data block.
//
status = WdfWmiInstanceCreate(Device,
&instanceConfig,
WDF_NO_OBJECT_ATTRIBUTES,
WDF_NO_HANDLE);
if (!NT_SUCCESS(status)) {
DebugPrint(("[WmiSamp] Status = 0x%08x, WmiSampWmiRegistration\n", status));
return status;
}
}
return status;
}
NTSTATUS
WmiSampDynamicWmiRegistration(
_In_ WDFDEVICE Device
)
/*++
Routine Description:
This function creates WMI provider instance if the dynamic instance does not
already exist. If it does exist, this funciton deregisters and deletes the
WMI instance. This function assumes that the mof has already been registered
with the given Framework device object (by a previous call to WmiSampWmiRegistration).
Arguments:
Device - The Framework device object for which a WMI provider instance
has to be created if the instance does not exist or deleted if the
instance exists.
Return Value:
NT Status code.
--*/
{
NTSTATUS status = STATUS_SUCCESS;
PWMI_SAMPLE_DEVICE_DATA wmiDeviceData;
WDF_WMI_PROVIDER_CONFIG providerConfig;
WDF_WMI_INSTANCE_CONFIG instanceConfig;
wmiDeviceData = GetWmiSampleDeviceData(Device);
//
// If the dynamic provider already exists, then delete the dynamic provider
// and all of its instances.
//
if (wmiDeviceData->DynamicInstance) {
DebugPrint(("Delete Dynamic instance.\n"));
//
// Deregister the dynamic WMI Instance so that this instance does not
// receive any more WMI query callbacks.
//
WdfWmiInstanceDeregister(wmiDeviceData->DynamicInstance);
//
// Delete the dynamic WMI Instance object.
//
WdfObjectDelete(wmiDeviceData->DynamicInstance);
wmiDeviceData->DynamicInstance = NULL;
} else {
DebugPrint(("Create Dynamic instance.\n"));
//
// Initialize the config structures for the Provider and the Instance
// and define event callback functions that support a WMI client's
// requests to access the driver's WMI data blocks.
//
WDF_WMI_PROVIDER_CONFIG_INIT(&providerConfig, &DynamicInstanceConfig.Guid);
providerConfig.MinInstanceBufferSize = DynamicInstanceConfig.MinSize;
//
// You would want to create a WDFWMIPROVIDER handle separately if you are
// going to dynamically create instances on the provider. Since we are
// statically creating one instance, there is no need to create the provider
// handle.
//
WDF_WMI_INSTANCE_CONFIG_INIT_PROVIDER_CONFIG(&instanceConfig, &providerConfig);
//
// Create a Provider object as part of the Instance creation call by setting
// the Register value in the Instance Config to TRUE. This eliminates the
// need to call WdfWmiProviderRegister.
//
instanceConfig.Register = TRUE;
instanceConfig.EvtWmiInstanceQueryInstance = DynamicInstanceConfig.EvtWmiInstanceQueryInstance;
instanceConfig.EvtWmiInstanceSetInstance = DynamicInstanceConfig.EvtWmiInstanceSetInstance;
instanceConfig.EvtWmiInstanceSetItem = DynamicInstanceConfig.EvtWmiInstanceSetItem;
instanceConfig.EvtWmiInstanceExecuteMethod = DynamicInstanceConfig.EvtWmiInstanceExecuteMethod;
//
// Create the WMI instance object for this data block.
//
status = WdfWmiInstanceCreate(Device,
&instanceConfig,
WDF_NO_OBJECT_ATTRIBUTES,
&(wmiDeviceData->DynamicInstance));
if (!NT_SUCCESS(status)) {
DebugPrint(("[WmiSamp] Status = 0x%08x, WmiSampDynamicWmiRegistration\n", status));
return status;
}
//
// Increment the Create count if the dynamic WMI Instance was created.
//
wmiDeviceData->CreateCount++;
}
return status;
}
NTSTATUS
EvtWmiClass1DataQueryInstance(
WDFWMIINSTANCE WmiInstance,
ULONG OutBufferSize,
PVOID OutBuffer,
PULONG BufferUsed
)
/*++
Routine Description:
This is the callback routine for the WMI Query irp on the Instance representing
the sample class 1. This routine gets the current value for the data members
of the sample class and copies it to the given output buffer. The sample class1
is made up of the same parameters as the Embedded Class EC1.
Arguments:
WmiInstance - The handle to the WMI instance object.
OutBufferSize - The size (in bytes) of the output buffer into which the
instance data is to be copied.
OutBuffer - Pointer to the output buffer.
BufferUsed - Pointer to the location that receives the number of bytes that
were copied into the output buffer.
Return Value:
NT Status code.
--*/
{
WDFDEVICE device;
PWMI_SAMPLE_DEVICE_DATA wmiDeviceData;
UNREFERENCED_PARAMETER(OutBufferSize);
PAGED_CODE();
device = WdfWmiInstanceGetDevice(WmiInstance);
wmiDeviceData = GetWmiSampleDeviceData(device);
//
// Plain EC1.
//
*BufferUsed = WmiSampGetEc1(wmiDeviceData,
OutBuffer,
0);
return STATUS_SUCCESS;
}
NTSTATUS
EvtWmiClass1DataSetInstance(
WDFWMIINSTANCE WmiInstance,
ULONG InBufferSize,
PVOID InBuffer
)
{
WDFDEVICE device;
PWMI_SAMPLE_DEVICE_DATA wmiDeviceData;
PAGED_CODE();
//
// InBufferSize is guaranteed to be at least WmiSampleClass1_SIZE
// which in this case is EC1_SIZE.
//
UNREFERENCED_PARAMETER(InBufferSize);
device = WdfWmiInstanceGetDevice(WmiInstance);
wmiDeviceData = GetWmiSampleDeviceData(device);
//
// Plain EC1.
//
WmiSampSetEc1(wmiDeviceData,
InBuffer,
EC1_SIZE,
0);
return STATUS_SUCCESS;
}
NTSTATUS
EvtWmiClass1DataSetItem(
WDFWMIINSTANCE WmiInstance,
ULONG DataItemId,
ULONG InBufferSize,
PVOID InBuffer
)
{
NTSTATUS status = STATUS_SUCCESS;
PAGED_CODE();
UNREFERENCED_PARAMETER(WmiInstance);
UNREFERENCED_PARAMETER(DataItemId);
UNREFERENCED_PARAMETER(InBufferSize);
UNREFERENCED_PARAMETER(InBuffer);
return status;
}
NTSTATUS
EvtWmiClass1ExecuteMethod(
WDFWMIINSTANCE WmiInstance,
ULONG MethodId,
ULONG InBufferSize,
ULONG OutBufferSize,
PVOID Buffer,
PULONG BufferUsed
)
{
NTSTATUS status;
WDFDEVICE device;
PWMI_SAMPLE_DEVICE_DATA wmiDeviceData;
UNREFERENCED_PARAMETER(OutBufferSize);
PAGED_CODE();
device = WdfWmiInstanceGetDevice(WmiInstance);
wmiDeviceData = GetWmiSampleDeviceData(device);
switch (MethodId) {
case SetEC1:
{
if (InBufferSize >= EC1_SIZE) {
WmiSampSetEc1(wmiDeviceData,
Buffer,
EC1_SIZE,
0);
status = STATUS_SUCCESS;
} else {
status = STATUS_INVALID_PARAMETER_MIX;
DebugPrint(("[WmiSamp] Status = 0x%08x, EvtWmiClass1ExecuteMethod\n", status));
}
}
break;
case DummyMethod:
status = STATUS_SUCCESS;
break;
default:
status = STATUS_WMI_ITEMID_NOT_FOUND;
DebugPrint(("[WmiSamp] Status = 0x%08x, EvtWmiClass1ExecuteMethod\n", status));
break;
}
*BufferUsed = 0;
return status;
}
NTSTATUS
EvtWmiClass2DataQueryInstance(
WDFWMIINSTANCE WmiInstance,
ULONG OutBufferSize,
PVOID OutBuffer,
PULONG BufferUsed
)
/*++
Routine Description:
This is the callback routine for the WMI Query irp on the Instance representing
the sample class 2. This routine gets the current value for the data members
of the sample class and copies it to the given output buffer. The sample class2
contains an embedded class.
Arguments:
WmiInstance - The handle to the WMI instance object.
OutBufferSize - The size (in bytes) of the output buffer into which the
instance data is to be copied.
OutBuffer - Pointer to the output buffer.
BufferUsed - Pointer to the location that receives the number of bytes that
were copied into the output buffer.
Return Value:
NT Status code.
--*/
{
WDFDEVICE device;
PWMI_SAMPLE_DEVICE_DATA wmiDeviceData;
UNREFERENCED_PARAMETER(OutBufferSize);
PAGED_CODE();
device = WdfWmiInstanceGetDevice(WmiInstance);
wmiDeviceData = GetWmiSampleDeviceData(device);
//
// Plain (Embedded) EC1.
//
*BufferUsed = WmiSampGetEc1(wmiDeviceData,
OutBuffer,
0);
return STATUS_SUCCESS;
}
NTSTATUS
EvtWmiClass2DataSetInstance(
WDFWMIINSTANCE WmiInstance,
ULONG InBufferSize,
PVOID InBuffer
)
{
WDFDEVICE device;
PWMI_SAMPLE_DEVICE_DATA wmiDeviceData;
PAGED_CODE();
//
// InBufferSize is guaranteed to be at least WmiSampleClass2_SIZE
// which in this case is EC1_SIZE.
//
UNREFERENCED_PARAMETER(InBufferSize);
device = WdfWmiInstanceGetDevice(WmiInstance);
wmiDeviceData = GetWmiSampleDeviceData(device);
//
// Plain (Embedded) EC1.
//
WmiSampSetEc1(wmiDeviceData,
InBuffer,
EC1_SIZE,
0);
return STATUS_SUCCESS;
}
NTSTATUS
EvtWmiClass3DataQueryInstance(
WDFWMIINSTANCE WmiInstance,
ULONG OutBufferSize,
PVOID OutBuffer,
PULONG BufferUsed
)
/*++
Routine Description:
This is the callback routine for the WMI Query irp on the Instance representing
the sample class 3. This routine gets the current value for the data members
of the sample class and copies it to the given output buffer. The sample class3
contains a fixed array of embedded class EC1.
Arguments:
WmiInstance - The handle to the WMI instance object.
OutBufferSize - The size (in bytes) of the output buffer into which the
instance data is to be copied.
OutBuffer - Pointer to the output buffer.
BufferUsed - Pointer to the location that receives the number of bytes that
were copied into the output buffer.
Return Value:
NT Status code.
--*/
{
NTSTATUS status;
WDFDEVICE device;
PWMI_SAMPLE_DEVICE_DATA wmiDeviceData;
ULONG sizeNeeded;
ULONG sizeUsed;
ULONG i;
UNREFERENCED_PARAMETER(OutBufferSize);
PAGED_CODE();
device = WdfWmiInstanceGetDevice(WmiInstance);
wmiDeviceData = GetWmiSampleDeviceData(device);
//
// Fixed array of EC1.
//
sizeNeeded = 0;
for (i = 0; i < EC1_COUNT; i++) {
sizeNeeded += ALIGN_UP(wmiDeviceData->Ec1Length[i], PVOID);
}
if (OutBufferSize < sizeNeeded) {
*BufferUsed = 0;
status = STATUS_BUFFER_TOO_SMALL;
} else {
*BufferUsed = 0;
for (i = 0; i < EC1_COUNT; i++) {
sizeUsed = WmiSampGetEc1(wmiDeviceData, OutBuffer, i);
OutBuffer = Add2Ptr(OutBuffer, ALIGN_UP(sizeUsed, PVOID));
*BufferUsed += sizeUsed;
}
status = STATUS_SUCCESS;
}
return status;
}
NTSTATUS
EvtWmiClass3DataSetInstance(
WDFWMIINSTANCE WmiInstance,
ULONG InBufferSize,
PVOID InBuffer
)
/*++
Routine Description:
---
Arguments:
WmiInstance -
InBufferSize -
InBuffer -
Return Value:
NT Status code.
--*/
{
NTSTATUS status = STATUS_SUCCESS;
WDFDEVICE device;
PWMI_SAMPLE_DEVICE_DATA wmiDeviceData;
ULONG i;
PEC1 Ec1;
PAGED_CODE();
device = WdfWmiInstanceGetDevice(WmiInstance);
wmiDeviceData = GetWmiSampleDeviceData(device);
//
// Fixed array of EC1.
//
Ec1 = (PEC1)InBuffer;
for (i = 0; i < EC1_COUNT; i++) {
if (InBufferSize >= EC1_SIZE) {
WmiSampSetEc1(wmiDeviceData, Ec1, EC1_SIZE, i);
InBufferSize -= EC1_SIZE;
Ec1++;
} else {
status = STATUS_INVALID_PARAMETER_MIX;
DebugPrint(("[WmiSamp] Status = 0x%08x, EvtWmiClass3DataSetInstance\n", status));
}
}
return status;
}
NTSTATUS
EvtWmiClass5DataQueryInstance(
WDFWMIINSTANCE WmiInstance,
ULONG OutBufferSize,
PVOID OutBuffer,
PULONG BufferUsed
)
/*++
Routine Description:
This is the callback routine for the WMI Query irp on the Instance representing
the sample class 5. This routine gets the current value for the data members
of the sample class and copies it to the given output buffer. The sample class5
contains an embedded class.
Arguments:
WmiInstance - The handle to the WMI instance object.
OutBufferSize - The size (in bytes) of the output buffer into which the
instance data is to be copied.
OutBuffer - Pointer to the output buffer.
BufferUsed - Pointer to the location that receives the number of bytes that
were copied into the output buffer.
Return Value:
NT Status code.
--*/
{
WDFDEVICE device;
PWMI_SAMPLE_DEVICE_DATA wmiDeviceData;
UNREFERENCED_PARAMETER(OutBufferSize);
PAGED_CODE();
device = WdfWmiInstanceGetDevice(WmiInstance);
wmiDeviceData = GetWmiSampleDeviceData(device);
//
// Plain (Embedded) EC2.
//
*BufferUsed = WmiSampGetEc2(wmiDeviceData,
OutBuffer,
0);
return STATUS_SUCCESS;
}
NTSTATUS
EvtWmiClass5DataSetInstance(
WDFWMIINSTANCE WmiInstance,
ULONG InBufferSize,
PVOID InBuffer
)
{
WDFDEVICE device;
PWMI_SAMPLE_DEVICE_DATA wmiDeviceData;
PAGED_CODE();
//
// InBufferSize is guaranteed to be at least WmiSampleClass5_SIZE
// which in this case is EC2_SIZE.
//
UNREFERENCED_PARAMETER(InBufferSize);
device = WdfWmiInstanceGetDevice(WmiInstance);
wmiDeviceData = GetWmiSampleDeviceData(device);
//
// Plain (Embedded) EC2.
//
WmiSampSetEc2(wmiDeviceData,
InBuffer,
EC2_SIZE,
0);
return STATUS_SUCCESS;
}
NTSTATUS
EvtWmiClass6DataQueryInstance(
WDFWMIINSTANCE WmiInstance,
ULONG OutBufferSize,
PVOID OutBuffer,
PULONG BufferUsed
)
/*++
Routine Description:
This is the callback routine for the WMI Query irp on the Instance representing
the sample class 6. This routine gets the current value for the data members
of the sample class and copies it to the given output buffer. The sample class6
contains a fixed array of embedded class EC2.
Arguments:
WmiInstance - The handle to the WMI instance object.
OutBufferSize - The size (in bytes) of the output buffer into which the
instance data is to be copied.
OutBuffer - Pointer to the output buffer.
BufferUsed - Pointer to the location that receives the number of bytes that
were copied into the output buffer.
Return Value:
NT Status code.
--*/
{
NTSTATUS status;
WDFDEVICE device;
PWMI_SAMPLE_DEVICE_DATA wmiDeviceData;
ULONG sizeNeeded;
ULONG sizeUsed;
ULONG i;
UNREFERENCED_PARAMETER(OutBufferSize);
PAGED_CODE();
device = WdfWmiInstanceGetDevice(WmiInstance);
wmiDeviceData = GetWmiSampleDeviceData(device);
//
// Fixed array of EC2.
//
sizeNeeded = 0;
for (i = 0; i < EC2_COUNT; i++) {
sizeNeeded += ALIGN_UP(wmiDeviceData->Ec2Length[i], PVOID);
}
if (OutBufferSize < sizeNeeded) {
*BufferUsed = 0;
status = STATUS_BUFFER_TOO_SMALL;
} else {
*BufferUsed = 0;
for (i = 0; i < EC2_COUNT; i++) {
sizeUsed = WmiSampGetEc2(wmiDeviceData, OutBuffer, i);
OutBuffer = Add2Ptr(OutBuffer, ALIGN_UP(sizeUsed, PVOID));
*BufferUsed += sizeUsed;
}
status = STATUS_SUCCESS;
}
return status;
}
NTSTATUS
EvtWmiClass6DataSetInstance(
WDFWMIINSTANCE WmiInstance,
ULONG InBufferSize,
PVOID InBuffer
)
/*++
Routine Description:
This is the callback routine for setting the WMI data provider's instance
data supplied by a WMI client. This routine copies the data in the input
buffer and updates the sample class6 data which contains a fixed array of
embedded class EC2.
Arguments:
WmiInstance - The handle to the WMI instance object.
InBufferSize - The size (in bytes) of the input buffer from which the
instance data is to be copied.
InBuffer - Pointer to the input buffer.
Return Value:
NT Status code.
--*/
{
NTSTATUS status = STATUS_SUCCESS;
WDFDEVICE device;
PWMI_SAMPLE_DEVICE_DATA wmiDeviceData;
ULONG i;
PEC2 Ec2;
PAGED_CODE();
device = WdfWmiInstanceGetDevice(WmiInstance);
wmiDeviceData = GetWmiSampleDeviceData(device);
//
// Fixed array of EC2.
//
Ec2 = (PEC2)InBuffer;
for (i = 0; i < EC2_COUNT; i++) {
if (InBufferSize >= EC2_SIZE) {
WmiSampSetEc2(wmiDeviceData, Ec2, EC2_SIZE, i);
InBufferSize -= EC2_SIZE;
Ec2++;
} else {
status = STATUS_INVALID_PARAMETER_MIX;
DebugPrint(("[WmiSamp] Status = 0x%08x, EvtWmiClass6DataSetInstance\n", status));
}
}
return status;
}
|