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
|
/*++
Copyright (c) Microsoft Corporation. All rights reserved.
Module Name:
simemifdo.c
Abstract:
This module contains the implementation of the routines related to the
simemi virtual bus device.
--*/
#include "simemi.h"
#include <limits.h>
#include <ntintsafe.h>
NTSTATUS
SimEmiFdoCreateChildDevice (
_In_ WDFDEVICE Device,
_In_ WDFREQUEST Request
);
NTSTATUS
SimEmiFdoDeleteChildDevice (
_In_ WDFDEVICE Device,
_In_ WDFREQUEST Request
);
PSIM_EMI_BUS_PDO_DATA
SimEmiFdoFindChildDevice (
_In_ WDFDEVICE Device,
_In_ ULONG ChildDeviceHandle
);
EVT_WDF_CHILD_LIST_IDENTIFICATION_DESCRIPTION_CLEANUP SimEmiPdoIdentificationCleanup;
EVT_WDF_CHILD_LIST_IDENTIFICATION_DESCRIPTION_COMPARE SimEmiPdoIdentificationCompare;
EVT_WDF_CHILD_LIST_IDENTIFICATION_DESCRIPTION_DUPLICATE SimEmiPdoIdentificationDuplicate;
NTSTATUS
SimEmiFdoQueryChildDevice (
_In_ WDFDEVICE Device,
_In_ WDFREQUEST Request,
_Out_ PULONG OutputBufferSizeOut
);
NTSTATUS
SimEmiFdoUpdateChildDevice (
_In_ WDFDEVICE Device,
_In_ WDFREQUEST Request
);
#pragma alloc_text(PAGE, SimEmiFdoControl)
#pragma alloc_text(PAGE, SimEmiFdoCreateChildDevice)
#pragma alloc_text(PAGE, SimEmiFdoDeleteChildDevice)
#pragma alloc_text(PAGE, SimEmiFdoCreateDevice)
#pragma alloc_text(PAGE, SimEmiFdoFindChildDevice)
#pragma alloc_text(PAGE, SimEmiFdoQueryChildDevice)
#pragma alloc_text(PAGE, SimEmiFdoUpdateChildDevice)
VOID
SimEmiFdoControl (
_In_ WDFQUEUE Queue,
_In_ WDFREQUEST Request,
_In_ size_t OutputBufferLength,
_In_ size_t InputBufferLength,
_In_ ULONG IoControlCode
)
/*++
Routine Description:
This routine handles device control requests for the EMI Bus.
Arguments:
Queue - Supplies a reference to the WDF queue that this request originates.
Request - Supplies a reference to the WDF request that was sent.
OutputBufferLength - Supplies the length of the output buffer in bytes.
InputBufferLength - Supplies the length of the input buffer in bytes.
IoControlCode - Supplies the IOCTL for the request.
Return Value:
None.
--*/
{
WDFDEVICE Device;
PSIM_EMI_BUS_FDO_DATA FdoData;
ULONG OutputLength;
NTSTATUS Status;
UNREFERENCED_PARAMETER(OutputBufferLength);
UNREFERENCED_PARAMETER(InputBufferLength);
Device = WdfIoQueueGetDevice(Queue);
FdoData = SimEmiGetFdoData(Device);
ExAcquireFastMutex(&FdoData->BusMutex);
OutputLength = 0;
switch (IoControlCode) {
case IOCTL_EMI_BUS_CREATE_DEVICE:
Status = SimEmiFdoCreateChildDevice(Device, Request);
break;
case IOCTL_EMI_BUS_DELETE_DEVICE:
Status = SimEmiFdoDeleteChildDevice(Device, Request);
break;
case IOCTL_EMI_BUS_QUERY_DEVICE_INFO:
Status = SimEmiFdoQueryChildDevice(Device, Request, &OutputLength);
break;
case IOCTL_EMI_BUS_SET_DEVICE_RATE:
Status = SimEmiFdoUpdateChildDevice(Device, Request);
break;
default:
Status = STATUS_INVALID_DEVICE_REQUEST;
break;
}
WdfRequestCompleteWithInformation(Request, Status, OutputLength);
ExReleaseFastMutex(&FdoData->BusMutex);
return;
}
NTSTATUS
SimEmiFdoCreateChildDevice (
_In_ WDFDEVICE Device,
_In_ WDFREQUEST Request
)
/*++
Routine Description:
This routine handles an IOCTL_EMI_BUS_CREATE_DEVICE request.
Arguments:
Device - Supplies a reference to the BUS FDO device.
Request - Supplies a reference to the WDF Request.
Return Value:
NTSTATUS.
--*/
{
USHORT ChannelCount;
USHORT ChannelIndex;
PSIM_EMI_BUS_CHANNEL_INFO ChannelInfo;
ULONG ChannelInfoSize;
ULONG EntrySize;
SIM_EMI_BUS_PDO_IDENTIFICATION_INFO Identification;
PSIM_EMI_BUS_CREATE_DEVICE_INPUT_BUFFER InputBuffer;
size_t InputBufferLength;
ULONG RemainingBufferSize;
NTSTATUS Status;
RtlZeroMemory(&Identification,
sizeof(SIM_EMI_BUS_PDO_IDENTIFICATION_INFO));
Status = WdfRequestRetrieveInputBuffer(
Request,
sizeof(SIM_EMI_BUS_CREATE_DEVICE_INPUT_BUFFER),
(PVOID*)&InputBuffer,
&InputBufferLength);
if (!NT_SUCCESS(Status)) {
goto FdoCreateChildDeviceEnd;
}
ChannelCount = InputBuffer->ChannelCount;
if (InputBuffer->EmiVersion == EMI_VERSION_V1) {
if (ChannelCount != 1) {
Status = STATUS_INVALID_PARAMETER;
goto FdoCreateChildDeviceEnd;
}
} else if (InputBuffer->EmiVersion == EMI_VERSION_V2) {
if (ChannelCount == 0) {
Status = STATUS_INVALID_PARAMETER;
goto FdoCreateChildDeviceEnd;
}
} else {
Status = STATUS_INVALID_PARAMETER;
goto FdoCreateChildDeviceEnd;
}
if (InputBufferLength > ULONG_MAX) {
Status = STATUS_BUFFER_OVERFLOW;
goto FdoCreateChildDeviceEnd;
}
ChannelInfo = &InputBuffer->ChannelInfo[0];
ChannelInfoSize = 0;
RemainingBufferSize = (ULONG)InputBufferLength;
RemainingBufferSize -= FIELD_OFFSET(SIM_EMI_BUS_CREATE_DEVICE_INPUT_BUFFER,
ChannelInfo);
for (ChannelIndex = 0; ChannelIndex < ChannelCount; ++ChannelIndex) {
EntrySize = SIM_EMI_BUS_CHANNEL_INFO_SIZE(ChannelInfo->ChannelNameSize);
if (EntrySize > RemainingBufferSize) {
Status = STATUS_INVALID_PARAMETER;
goto FdoCreateChildDeviceEnd;
}
RemainingBufferSize -= EntrySize;
ChannelInfoSize += EntrySize;
ChannelInfo = SIM_EMI_BUS_CHANNEL_INFO_NEXT_CHANNEL_INFO(ChannelInfo);
}
WDF_CHILD_IDENTIFICATION_DESCRIPTION_HEADER_INIT(
&Identification.Header,
sizeof(SIM_EMI_BUS_PDO_IDENTIFICATION_INFO));
//#pragma warning( suppress : 4996 )
Identification.ChannelInfo = ExAllocatePool2(POOL_FLAG_NON_PAGED,
ChannelInfoSize,
SIM_EMI_TAG);
if (Identification.ChannelInfo == NULL) {
Status = STATUS_INSUFFICIENT_RESOURCES;
goto FdoCreateChildDeviceEnd;
}
//
// Initialize description and add the device.
//
Identification.EmiVersion = InputBuffer->EmiVersion;
Identification.ChildDeviceHandle = InputBuffer->ChildDeviceHandle;
Identification.ChannelCount = InputBuffer->ChannelCount;
Identification.ChannelInfoSize = ChannelInfoSize;
RtlCopyMemory(&Identification.ChannelInfo[0],
&InputBuffer->ChannelInfo[0],
ChannelInfoSize);
Status = WdfChildListAddOrUpdateChildDescriptionAsPresent(
WdfFdoGetDefaultChildList(Device),
&Identification.Header,
NULL);
if (!NT_SUCCESS(Status)) {
goto FdoCreateChildDeviceEnd;
}
Status = STATUS_SUCCESS;
FdoCreateChildDeviceEnd:
if (Identification.ChannelInfo != NULL) {
ExFreePoolWithTag(Identification.ChannelInfo, SIM_EMI_TAG);
}
return Status;
}
NTSTATUS
SimEmiFdoDeleteChildDevice (
_In_ WDFDEVICE Device,
_In_ WDFREQUEST Request
)
/*++
Routine Description:
This routine handles an IOCTL_EMI_BUS_DELETE_DEVICE request.
Arguments:
Device - Supplies a reference to the BUS FDO device.
Request - Supplies a reference to the WDF Request.
Return Value:
NTSTATUS.
--*/
{
WDFCHILDLIST ChildList;
SIM_EMI_BUS_PDO_IDENTIFICATION_INFO Identification;
PSIM_EMI_BUS_DELETE_DEVICE_INPUT_BUFFER InputBuffer;
NTSTATUS Status;
ChildList = WdfFdoGetDefaultChildList(Device);
Status = WdfRequestRetrieveInputBuffer(
Request,
sizeof(SIM_EMI_BUS_DELETE_DEVICE_INPUT_BUFFER),
(PVOID*)&InputBuffer,
NULL);
if (!NT_SUCCESS(Status)) {
goto FdoDeleteChildDeviceEnd;
}
WDF_CHILD_IDENTIFICATION_DESCRIPTION_HEADER_INIT(
&Identification.Header,
sizeof(SIM_EMI_BUS_PDO_IDENTIFICATION_INFO));
Identification.ChildDeviceHandle = InputBuffer->ChildDeviceHandle;
Status = WdfChildListUpdateChildDescriptionAsMissing(
ChildList,
&Identification.Header);
if (Status == STATUS_NO_SUCH_DEVICE) {
Status = STATUS_INVALID_PARAMETER;
}
FdoDeleteChildDeviceEnd:
return Status;
}
NTSTATUS
SimEmiFdoCreateDevice (
_In_ WDFDRIVER Driver,
_In_ PWDFDEVICE_INIT DeviceInit
)
/*++
Routine Description:
This routine creates and initializes the bus FDO device.
Arguments:
Driver - Supplies a reference to the WDFDRIVER for this device.
DeviceInit - Supplies a pointer to the WDFDEVICE_INIT instance for this
device.
Return Value:
NTSTATUS.
--*/
{
WDF_CHILD_LIST_CONFIG ChildListConfig;
WDFDEVICE DeviceHandle;
PSIM_EMI_BUS_FDO_DATA FdoData;
WDF_OBJECT_ATTRIBUTES FdoDeviceAttributes;
WDFQUEUE Queue;
WDF_IO_QUEUE_CONFIG QueueConfig;
NTSTATUS Status;
DECLARE_CONST_UNICODE_STRING(DeviceName, SIM_EMI_DEVICE_PATH);
DECLARE_CONST_UNICODE_STRING(DeviceAlias, SIM_EMI_DEVICE_ALIAS_PATH);
PAGED_CODE();
UNREFERENCED_PARAMETER(Driver);
KdPrint(("Initializing SimEmi PDO.\n"));
WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&FdoDeviceAttributes,
SIM_EMI_BUS_FDO_DATA);
WdfDeviceInitSetDeviceType(DeviceInit, FILE_DEVICE_BUS_EXTENDER);
WdfDeviceInitSetExclusive(DeviceInit, TRUE);
WdfDeviceInitSetIoType(DeviceInit, WdfDeviceIoBuffered);
//
// Initialize child list.
//
WDF_CHILD_LIST_CONFIG_INIT(&ChildListConfig,
sizeof(SIM_EMI_BUS_PDO_IDENTIFICATION_INFO),
&SimEmiPdoCreateDevice);
ChildListConfig.EvtChildListIdentificationDescriptionCleanup =
&SimEmiPdoIdentificationCleanup;
ChildListConfig.EvtChildListIdentificationDescriptionCompare =
&SimEmiPdoIdentificationCompare;
ChildListConfig.EvtChildListIdentificationDescriptionDuplicate =
&SimEmiPdoIdentificationDuplicate;
WdfFdoInitSetDefaultChildListConfig(DeviceInit,
&ChildListConfig,
WDF_NO_OBJECT_ATTRIBUTES);
Status = WdfDeviceInitAssignName(DeviceInit, &DeviceName);
if (!NT_SUCCESS(Status)) {
KdPrint(("WdfDeviceInitAssignName failed with status code 0x%08X.\n",
Status));
goto FdoCreateDeviceEnd;
}
Status = WdfDeviceCreate(&DeviceInit, &FdoDeviceAttributes, &DeviceHandle);
if (!NT_SUCCESS(Status)) {
KdPrint(("WdfDeviceCreate failed with status code 0x%08X.\n", Status));
goto FdoCreateDeviceEnd;
}
FdoData = SimEmiGetFdoData(DeviceHandle);
RtlZeroMemory(FdoData, sizeof(SIM_EMI_BUS_FDO_DATA));
InitializeListHead(&FdoData->ChildDevices);
ExInitializeFastMutex(&FdoData->BusMutex);
//
// Setup symbolic links for UM.
//
Status = WdfDeviceCreateSymbolicLink(DeviceHandle, &DeviceAlias);
if (!NT_SUCCESS(Status)) {
KdPrint(("WdfDeviceCreateSymbolicLink failed with status code :0x%08X.\n",
Status));
goto FdoCreateDeviceEnd;
}
//
// Initialize IO Queue.
//
WDF_IO_QUEUE_CONFIG_INIT_DEFAULT_QUEUE(&QueueConfig,
WdfIoQueueDispatchSequential);
QueueConfig.EvtIoDeviceControl = &SimEmiFdoControl;
Status = WdfIoQueueCreate(DeviceHandle,
&QueueConfig,
WDF_NO_OBJECT_ATTRIBUTES,
&Queue);
if (!NT_SUCCESS(Status)) {
KdPrint(("WdfIoQueueCreate failed with status code 0x%08X.\n", Status));
goto FdoCreateDeviceEnd;
}
Status = WdfDeviceCreateDeviceInterface(DeviceHandle,
&GUID_DEVICE_SIM_EMI_BUS,
NULL);
if (!NT_SUCCESS(Status)) {
KdPrint(("WdfDeviceCreateDeviceInterface failed with status code 0x%08X.\n",
Status));
goto FdoCreateDeviceEnd;
}
Status = STATUS_SUCCESS;
FdoCreateDeviceEnd:
return Status;
}
PSIM_EMI_BUS_PDO_DATA
SimEmiFdoFindChildDevice (
_In_ WDFDEVICE Device,
_In_ ULONG ChildDeviceHandle
)
/*++
Routine Description:
This routine locates the PDO data for the child device with the provided
device handle.
Arguments:
Device - Supplies a reference to the WDFDEVICE of the bus FDO.
ChildDeviceHandle - Supplies the device handle of the child device to
locate.
Return Value:
Returns a pointer to the PDO data for the child device with the provided
device handle or NULL if no child exists with the provided device handle.
--*/
{
PSIM_EMI_BUS_PDO_DATA ChildData;
PLIST_ENTRY ListEntry;
PSIM_EMI_BUS_FDO_DATA FdoData;
FdoData = SimEmiGetFdoData(Device);
ChildData = NULL;
for (ListEntry = FdoData->ChildDevices.Flink;
ListEntry != &FdoData->ChildDevices;
ListEntry = ListEntry->Flink) {
ChildData = CONTAINING_RECORD(ListEntry,
SIM_EMI_BUS_PDO_DATA,
Link);
if (ChildData->ChildDeviceHandle == ChildDeviceHandle) {
break;
}
ChildData = NULL;
}
return ChildData;
}
NTSTATUS
SimEmiFdoQueryChildDevice (
_In_ WDFDEVICE Device,
_In_ WDFREQUEST Request,
_Out_ PULONG OutputBufferSizeOut
)
/*++
Routine Description:
This routine handles an IOCTL_EMI_BUS_QUERY_DEVICE_INFO request.
Arguments:
Device - Supplies a reference to the BUS FDO device.
Request - Supplies a reference to the WDF Request.
OutputBufferSizeOut - Supplies a pointer in which to place the size of the
output data written.
Return Value:
NTSTATUS.
--*/
{
USHORT ChannelCount;
PSIM_EMI_CHANNEL_DATA ChannelData;
PSIM_EMI_BUS_CHANNEL_INFO ChannelInfo;
PSIM_EMI_BUS_PDO_DATA ChildData;
ULONG EntrySize;
PSIM_EMI_BUS_QUERY_DEVICE_INFO_INPUT_BUFFER InputBuffer;
PSIM_EMI_BUS_QUERY_DEVICE_INFO_OUTPUT_BUFFER OutputBuffer;
ULONG OutputBufferSize;
NTSTATUS Status;
Status = WdfRequestRetrieveInputBuffer(
Request,
sizeof(SIM_EMI_BUS_QUERY_DEVICE_INFO_INPUT_BUFFER),
(PVOID*)&InputBuffer,
NULL);
if (!NT_SUCCESS(Status)) {
goto FdoQueryChildDeviceEnd;
}
ChildData = SimEmiFdoFindChildDevice(Device,
InputBuffer->ChildDeviceHandle);
if (ChildData == NULL) {
Status = STATUS_NOT_FOUND;
goto FdoQueryChildDeviceEnd;
}
OutputBufferSize = FIELD_OFFSET(SIM_EMI_BUS_QUERY_DEVICE_INFO_OUTPUT_BUFFER,
ChannelInfo);
ChannelCount = ChildData->ChannelCount;
ChannelData = &ChildData->ChannelData[0];
while (ChannelCount != 0) {
EntrySize =
SIM_EMI_BUS_CHANNEL_INFO_SIZE(ChannelData->Info.ChannelNameSize);
Status = RtlULongAdd(OutputBufferSize, EntrySize, &OutputBufferSize);
if (!NT_SUCCESS(Status)) {
goto FdoQueryChildDeviceEnd;
}
ChannelData = SIM_EMI_CHANNEL_DATA_NEXT_CHANNEL_DATA(ChannelData);
ChannelCount -= 1;
}
*OutputBufferSizeOut = OutputBufferSize;
Status = WdfRequestRetrieveOutputBuffer(Request,
OutputBufferSize,
(PVOID*)&OutputBuffer,
NULL);
if (!NT_SUCCESS(Status)) {
goto FdoQueryChildDeviceEnd;
}
OutputBuffer->EmiVersion = ChildData->EmiVersion;
OutputBuffer->ChannelCount = ChildData->ChannelCount;
ChannelCount = ChildData->ChannelCount;
ChannelData = &ChildData->ChannelData[0];
ChannelInfo = &OutputBuffer->ChannelInfo[0];
while (ChannelCount != 0) {
EntrySize =
SIM_EMI_BUS_CHANNEL_INFO_SIZE(ChannelData->Info.ChannelNameSize);
RtlCopyMemory(ChannelInfo, &ChannelData->Info, EntrySize);
ChannelData = SIM_EMI_CHANNEL_DATA_NEXT_CHANNEL_DATA(ChannelData);
ChannelInfo = SIM_EMI_BUS_CHANNEL_INFO_NEXT_CHANNEL_INFO(ChannelInfo);
ChannelCount -= 1;
}
Status = STATUS_SUCCESS;
FdoQueryChildDeviceEnd:
return Status;
}
NTSTATUS
SimEmiFdoUpdateChildDevice (
_In_ WDFDEVICE Device,
_In_ WDFREQUEST Request
)
/*++
Routine Description:
This routine handles an IOCTL_EMI_BUS_SET_DEVICE_RATE request.
Arguments:
Device - Supplies a reference to the BUS FDO device.
Request - Supplies a reference to the WDF Request.
Return Value:
NTSTATUS.
--*/
{
PULONG64 AbsoluteEnergyRates;
USHORT ChannelCount;
PSIM_EMI_CHANNEL_DATA ChannelData;
PSIM_EMI_BUS_PDO_DATA ChildData;
PSIM_EMI_BUS_SET_DEVICE_RATE_INPUT_BUFFER InputBuffer;
ULONG InputBufferSize;
NTSTATUS Status;
Status = WdfRequestRetrieveInputBuffer(
Request,
sizeof(SIM_EMI_BUS_SET_DEVICE_RATE_INPUT_BUFFER),
(PVOID*)&InputBuffer,
NULL);
if (!NT_SUCCESS(Status)) {
goto FdoUpdateChildDeviceEnd;
}
ChildData = SimEmiFdoFindChildDevice(Device,
InputBuffer->ChildDeviceHandle);
if (ChildData == NULL) {
Status = STATUS_INVALID_PARAMETER;
goto FdoUpdateChildDeviceEnd;
}
if ((ChildData->EmiVersion != InputBuffer->EmiVersion) ||
(ChildData->ChannelCount != InputBuffer->ChannelCount)) {
Status = STATUS_INVALID_PARAMETER;
goto FdoUpdateChildDeviceEnd;
}
ChannelCount = ChildData->ChannelCount;
Status = RtlULongMult(sizeof(ULONG64), ChannelCount, &InputBufferSize);
if (!NT_SUCCESS(Status)) {
goto FdoUpdateChildDeviceEnd;
}
InputBufferSize += FIELD_OFFSET(SIM_EMI_BUS_SET_DEVICE_RATE_INPUT_BUFFER,
AbsoluteEnergyRates);
Status = WdfRequestRetrieveInputBuffer(Request,
InputBufferSize,
(PVOID*)&InputBuffer,
NULL);
if (!NT_SUCCESS(Status)) {
goto FdoUpdateChildDeviceEnd;
}
AbsoluteEnergyRates = &InputBuffer->AbsoluteEnergyRates[0];
ChannelData = &ChildData->ChannelData[0];
while (ChannelCount != 0) {
ChannelData->Info.AbsoluteEnergyRate = *AbsoluteEnergyRates;
AbsoluteEnergyRates += 1;
ChannelData = SIM_EMI_CHANNEL_DATA_NEXT_CHANNEL_DATA(ChannelData);
ChannelCount -= 1;
}
Status = STATUS_SUCCESS;
FdoUpdateChildDeviceEnd:
return Status;
}
VOID
SimEmiPdoIdentificationCleanup (
_In_ WDFCHILDLIST ChildList,
_Inout_ PWDF_CHILD_IDENTIFICATION_DESCRIPTION_HEADER IdentificationDescription
)
/*++
Routine Description:
This routine cleans up the resources owned by a bus PDO description
instance.
Arguments:
ChildList - Supplies a reference to the WDFCHILDLIST this description is
being added to.
IdentificationDescription - Supplies a pointer to the identification info
instance to clean up.
Return Value:
None.
--*/
{
PSIM_EMI_BUS_PDO_IDENTIFICATION_INFO Description;
UNREFERENCED_PARAMETER(ChildList);
Description =
(PSIM_EMI_BUS_PDO_IDENTIFICATION_INFO)IdentificationDescription;
if (Description->ChannelInfo != NULL) {
ExFreePoolWithTag(Description->ChannelInfo, SIM_EMI_TAG);
}
return;
}
BOOLEAN
SimEmiPdoIdentificationCompare (
_In_ WDFCHILDLIST ChildList,
_In_ PWDF_CHILD_IDENTIFICATION_DESCRIPTION_HEADER FirstIdentificationDescription,
_In_ PWDF_CHILD_IDENTIFICATION_DESCRIPTION_HEADER SecondIdentificationDescription
)
/*++
Routine Description:
This routine compares two SIM_EMI_BUS_PDO_IDENTIFICATION_INFOs for
equality.
Arguments:
ChildList - Supplies a reference to the WDFCHILDLIST this description is
being added to.
FirstIdentificationDescription - Supplies a pointer to a PDO identification
info instance.
SecondIdentificationDescription - Supplies a pointer to a PDO
identification instance.
Return Value:
Returns TRUE if FirstIdentificationInfo == SecondIdentificationInfo, FALSE
otherwise.
--*/
{
PSIM_EMI_BUS_PDO_IDENTIFICATION_INFO Description1;
PSIM_EMI_BUS_PDO_IDENTIFICATION_INFO Description2;
BOOLEAN Result;
UNREFERENCED_PARAMETER(ChildList);
Description1 =
(PSIM_EMI_BUS_PDO_IDENTIFICATION_INFO)FirstIdentificationDescription;
Description2 =
(PSIM_EMI_BUS_PDO_IDENTIFICATION_INFO)SecondIdentificationDescription;
Result = FALSE;
if (Description1->ChildDeviceHandle == Description2->ChildDeviceHandle) {
Result = TRUE;
}
return Result;
}
NTSTATUS
SimEmiPdoIdentificationDuplicate (
_In_ WDFCHILDLIST ChildList,
_In_ PWDF_CHILD_IDENTIFICATION_DESCRIPTION_HEADER SourceIdentificationDescription,
_Out_ PWDF_CHILD_IDENTIFICATION_DESCRIPTION_HEADER DestinationIdentificationDescription
)
/*++
Routine Description:
This routine duplicates a SIM_EMI_BUS_PDO_IDENTIFICATION_INFO instance.
Arguments:
ChildList - Supplies a reference to the WDFCHILDLIST this description is
being added to.
SourceIdentificationDescription - Supplies a pointer to the identification
info instance to duplicate.
DestinationIdentificationDescription - Supplies a pointer to the location
to place the copied identification info.
Return Value:
NTSTATUS.
--*/
{
ULONG ChannelInfoSize;
PSIM_EMI_BUS_PDO_IDENTIFICATION_INFO DestinationDescription;
PSIM_EMI_BUS_PDO_IDENTIFICATION_INFO SourceDescription;
NTSTATUS Status;
UNREFERENCED_PARAMETER(ChildList);
DestinationDescription =
(PSIM_EMI_BUS_PDO_IDENTIFICATION_INFO)DestinationIdentificationDescription;
SourceDescription =
(PSIM_EMI_BUS_PDO_IDENTIFICATION_INFO)SourceIdentificationDescription;
ChannelInfoSize = SourceDescription->ChannelInfoSize;
//#pragma warning( suppress : 4996 )
DestinationDescription->ChannelInfo = ExAllocatePool2(POOL_FLAG_NON_PAGED,
ChannelInfoSize,
SIM_EMI_TAG);
if (DestinationDescription->ChannelInfo == NULL) {
Status = STATUS_INSUFFICIENT_RESOURCES;
goto PdoIdentificationDuplicateEnd;
}
DestinationDescription->EmiVersion = SourceDescription->EmiVersion;
DestinationDescription->ChildDeviceHandle =
SourceDescription->ChildDeviceHandle;
DestinationDescription->ChannelCount = SourceDescription->ChannelCount;
DestinationDescription->ChannelInfoSize = ChannelInfoSize;
RtlCopyMemory(&DestinationDescription->ChannelInfo[0],
&SourceDescription->ChannelInfo[0],
ChannelInfoSize);
Status = STATUS_SUCCESS;
PdoIdentificationDuplicateEnd:
return Status;
}
|