📄 wmi.c
字号:
/*++
Copyright (c) 1990-2000 Microsoft Corporation All Rights Reserved
Module Name:
WMI.C
Abstract:
This module handle all the WMI Irps.
Environment:
Kernel mode
Revision History:
Eliyas Yakub Oct 26, 1998
--*/
#include <ntddk.h>
#include <initguid.h>
#include <wdmguid.h>
#include <wmistr.h>
#include <wmilib.h>
#include "main.h"
NTSTATUS
ToasterSystemControl (
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp
)
/*++
Routine Description
We have just received a System Control IRP.
Assume that this is a WMI IRP and
call into the WMI system library and let it handle this IRP for us.
--*/
{
PDEVICE_EXTENSION fdoData;
SYSCTL_IRP_DISPOSITION disposition;
NTSTATUS status;
PIO_STACK_LOCATION stack;
PAGED_CODE();
stack = IoGetCurrentIrpStackLocation (Irp);
fdoData = ( PDEVICE_EXTENSION ) DeviceObject->DeviceExtension;
if ( fdoData->DevicePnPState == Removed) {
Irp->IoStatus.Status = status = STATUS_DELETE_PENDING;
IoCompleteRequest (Irp, IO_NO_INCREMENT);
return status;
}
status = WmiSystemControl(&fdoData->WmiLibInfo,
DeviceObject,
Irp,
&disposition);
switch(disposition)
{
case IrpProcessed:
{
//
// This irp has been processed and may be completed or pending.
break;
}
case IrpNotCompleted:
{
//
// This irp has not been completed, but has been fully processed.
// we will complete it now
IoCompleteRequest(Irp, IO_NO_INCREMENT);
break;
}
case IrpForward:
case IrpNotWmi:
{
//
// This irp is either not a WMI irp or is a WMI irp targeted
// at a device lower in the stack.
IoSkipCurrentIrpStackLocation (Irp);
status = IoCallDriver (fdoData->NextLowerDriver, Irp);
break;
}
default:
{
//
// We really should never get here, but if we do just forward....
ASSERT(FALSE);
IoSkipCurrentIrpStackLocation (Irp);
status = IoCallDriver (fdoData->NextLowerDriver, Irp);
break;
}
}
return(status);
}
//--- The End ---
#if 0
PCHAR
WMIMinorFunctionString (
UCHAR MinorFunction
);
#ifdef ALLOC_PRAGMA
#pragma alloc_text(PAGE,ToasterWmiRegistration)
#pragma alloc_text(PAGE,ToasterWmiDeRegistration)
#pragma alloc_text(PAGE,ToasterSystemControl)
#pragma alloc_text(PAGE,ToasterSetWmiDataItem)
#pragma alloc_text(PAGE,ToasterSetWmiDataBlock)
#pragma alloc_text(PAGE,ToasterQueryWmiDataBlock)
#pragma alloc_text(PAGE,ToasterQueryWmiRegInfo)
#endif
#define MOFRESOURCENAME L"MofResourceName"
#define WMI_TOASTER_DRIVER_INFORMATION 0
DEFINE_GUID (TOASTER_WMI_STD_DATA_GUID,
0xBBA21300, 0x6DD3, 0x11d2, 0xB8, 0x44, 0x00, 0xC0, 0x4F, 0xAD, 0x51, 0x71);
WMIGUIDREGINFO ToasterWmiGuidList[1] =
{
{
&TOASTER_WMI_STD_DATA_GUID, 1, 0 // driver information
}
};
//
// Global debug error level
//
extern ULONG DebugLevel;
NTSTATUS
ToasterWmiRegistration(
PFDO_DATA FdoData
)
/*++
Routine Description
Registers with WMI as a data provider for this
instance of the device
--*/
{
NTSTATUS status;
PAGED_CODE();
FdoData->WmiLibInfo.GuidCount = sizeof (ToasterWmiGuidList) /
sizeof (WMIGUIDREGINFO);
ASSERT (1 == FdoData->WmiLibInfo.GuidCount);
FdoData->WmiLibInfo.GuidList = ToasterWmiGuidList;
FdoData->WmiLibInfo.QueryWmiRegInfo = ToasterQueryWmiRegInfo;
FdoData->WmiLibInfo.QueryWmiDataBlock = ToasterQueryWmiDataBlock;
FdoData->WmiLibInfo.SetWmiDataBlock = ToasterSetWmiDataBlock;
FdoData->WmiLibInfo.SetWmiDataItem = ToasterSetWmiDataItem;
FdoData->WmiLibInfo.ExecuteWmiMethod = NULL;
FdoData->WmiLibInfo.WmiFunctionControl = NULL;
//
// Register with WMI
//
status = IoWMIRegistrationControl(FdoData->Self,
WMIREG_ACTION_REGISTER
);
//
// Initialize the Std device data structure
//
FdoData->StdDeviceData.ConnectorType = TOASTER_WMI_STD_USB;
FdoData->StdDeviceData.Capacity = 2000;
FdoData->StdDeviceData.ErrorCount = 0;
FdoData->StdDeviceData.Controls = 5;
FdoData->StdDeviceData.DebugPrintLevel = DebugLevel;
return status;
}
NTSTATUS
ToasterWmiDeRegistration(
PFDO_DATA FdoData
)
/*++
Routine Description
Inform WMI to remove this DeviceObject from its
list of providers. This function also
decrements the reference count of the deviceobject.
--*/
{
PAGED_CODE();
return IoWMIRegistrationControl(FdoData->Self,
WMIREG_ACTION_DEREGISTER
);
}
//
// WMI System Call back functions
//
NTSTATUS
ToasterSetWmiDataItem(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp,
IN ULONG GuidIndex,
IN ULONG InstanceIndex,
IN ULONG DataItemId,
IN ULONG BufferSize,
IN PUCHAR Buffer
)
/*++
Routine Description:
This routine is a callback into the driver to set for the contents of
a data block. When the driver has finished filling the data block it
must call WmiCompleteRequest to complete the irp. The driver can
return STATUS_PENDING if the irp cannot be completed immediately.
Arguments:
DeviceObject is the device whose data block is being queried
Irp is the Irp that makes this request
GuidIndex is the index into the list of guids provided when the
device registered
InstanceIndex is the index that denotes which instance of the data block
is being queried.
DataItemId has the id of the data item being set
BufferSize has the size of the data item passed
Buffer has the new values for the data item
Return Value:
status
--*/
{
PFDO_DATA fdoData;
NTSTATUS status;
PAGED_CODE();
ToasterDebugPrint ((3, "Entered ToasterSetWmiDataItem\n"));
fdoData = (PFDO_DATA) DeviceObject->DeviceExtension;
switch(GuidIndex) {
case WMI_TOASTER_DRIVER_INFORMATION:
if(DataItemId == 5)
{
DebugLevel = fdoData->StdDeviceData.DebugPrintLevel =
*((PULONG)Buffer);
status = STATUS_SUCCESS;
}
else
status = STATUS_WMI_READ_ONLY;
break;
default:
status = STATUS_WMI_GUID_NOT_FOUND;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -