⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wmi.c

📁 无奈啊啊 啊啊 啊啊
💻 C
📖 第 1 页 / 共 2 页
字号:
/*++

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:

    WMI.C

Abstract:

    This module handles all the WMI Irps.


Environment:

    Kernel mode

Revision History:

    Eliyas Yakub Dec 12, 1998


--*/
#include <ntddk.h>
#include "..\inc\driver.h"
#include "busenum.h"
#include "stdio.h"
#include <initguid.h>
#include <wdmguid.h>
#include <wmistr.h>
#include <wmilib.h>
#include "..\inc\public.h"

PCHAR
WMIMinorFunctionString (
    UCHAR MinorFunction
);

#ifdef ALLOC_PRAGMA
#pragma alloc_text(PAGE,Bus_WmiRegistration)
#pragma alloc_text(PAGE,Bus_WmiDeRegistration)
#pragma alloc_text(PAGE,Bus_SystemControl)
#pragma alloc_text(PAGE,Bus_SetWmiDataItem)
#pragma alloc_text(PAGE,Bus_SetWmiDataBlock)
#pragma alloc_text(PAGE,Bus_QueryWmiDataBlock)
#pragma alloc_text(PAGE,Bus_QueryWmiRegInfo)
#endif

#define MOFRESOURCENAME L"MofResourceName"

#define NUMBER_OF_WMI_GUIDS                 1
#define WMI_TOASTER_BUS_DRIVER_INFORMATION  0

WMIGUIDREGINFO ToasterBusWmiGuidList[] =
{
    {
        &TOASTER_BUS_WMI_STD_DATA_GUID, 1, 0 // driver information
    }
};

NTSTATUS
Bus_WmiRegistration(
    PFDO_DEVICE_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 (ToasterBusWmiGuidList) /
                                 sizeof (WMIGUIDREGINFO);
    ASSERT (NUMBER_OF_WMI_GUIDS == FdoData->WmiLibInfo.GuidCount);
    FdoData->WmiLibInfo.GuidList = ToasterBusWmiGuidList;
    FdoData->WmiLibInfo.QueryWmiRegInfo = Bus_QueryWmiRegInfo;
    FdoData->WmiLibInfo.QueryWmiDataBlock = Bus_QueryWmiDataBlock;
    FdoData->WmiLibInfo.SetWmiDataBlock = Bus_SetWmiDataBlock;
    FdoData->WmiLibInfo.SetWmiDataItem = Bus_SetWmiDataItem;
    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->StdToasterBusData.ErrorCount = 0; 
    FdoData->StdToasterBusData.DebugPrintLevel = BusEnumDebugLevel;

    return status;
    
}

NTSTATUS
Bus_WmiDeRegistration(
    PFDO_DEVICE_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
                                 );

}

NTSTATUS
Bus_SystemControl (
    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.

--*/
{
    PFDO_DEVICE_DATA               fdoData;
    SYSCTL_IRP_DISPOSITION  disposition;
    NTSTATUS                status;
    PIO_STACK_LOCATION      stack;
    PCOMMON_DEVICE_DATA     commonData;

    PAGED_CODE();

    stack = IoGetCurrentIrpStackLocation (Irp);

    commonData = (PCOMMON_DEVICE_DATA) DeviceObject->DeviceExtension;

    if (!commonData->IsFDO) {
        //
        // The PDO, just complete the request with the current status
        //
        Bus_KdPrint (commonData, BUS_DBG_WMI_TRACE, 
            ("PDO %s\n", WMIMinorFunctionString(stack->MinorFunction)));
        status = Irp->IoStatus.Status;
        IoCompleteRequest (Irp, IO_NO_INCREMENT);
        return status;
    }

    fdoData = (PFDO_DEVICE_DATA) DeviceObject->DeviceExtension;
    
    Bus_KdPrint (fdoData, BUS_DBG_WMI_TRACE, 
             ("FDO: %s\n", WMIMinorFunctionString(stack->MinorFunction)));

    Bus_IncIoCount (fdoData);
    
    if (fdoData->DevicePnPState == Deleted) {
        Irp->IoStatus.Status = status = STATUS_DELETE_PENDING;
        IoCompleteRequest (Irp, IO_NO_INCREMENT);
        Bus_DecIoCount (fdoData);
        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 targetted
            // 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;
        }        
    }

    Bus_DecIoCount (fdoData);

    return(status);
}

//
// WMI System Call back functions
//

NTSTATUS
Bus_SetWmiDataItem(
    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_DEVICE_DATA    fdoData;
    NTSTATUS status;

    PAGED_CODE();

    fdoData = (PFDO_DEVICE_DATA) DeviceObject->DeviceExtension;

    switch(GuidIndex) {
    
    case WMI_TOASTER_BUS_DRIVER_INFORMATION:
        if(DataItemId == 2)
        {
           BusEnumDebugLevel = fdoData->StdToasterBusData.DebugPrintLevel = 
                                    *((PULONG)Buffer);
           status = STATUS_SUCCESS;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -