Пример #1
0
//
// Register our GUID and Datablock generated from the Firefly.mof file.
//
NTSTATUS
WmiInitialize(
    WDFDEVICE       Device,
    PDEVICE_CONTEXT DeviceContext
    )
{
    WDF_WMI_PROVIDER_CONFIG providerConfig;
    WDF_WMI_INSTANCE_CONFIG instanceConfig;
    WDF_OBJECT_ATTRIBUTES woa;
    WDFWMIINSTANCE instance;
    NTSTATUS status;
    DECLARE_CONST_UNICODE_STRING(mofRsrcName, MOFRESOURCENAME);

    UNREFERENCED_PARAMETER(DeviceContext);

    PAGED_CODE();

    status = WdfDeviceAssignMofResourceName(Device, &mofRsrcName);
    if (!NT_SUCCESS(status)) {
        KdPrint(("FireFly: Error in WdfDeviceAssignMofResourceName %x\n", status));
        return status;
    }

    WDF_WMI_PROVIDER_CONFIG_INIT(&providerConfig, &FireflyDeviceInformation_GUID);
    providerConfig.MinInstanceBufferSize = sizeof(FireflyDeviceInformation);

    WDF_WMI_INSTANCE_CONFIG_INIT_PROVIDER_CONFIG(&instanceConfig, &providerConfig);
    instanceConfig.Register = TRUE;
    instanceConfig.EvtWmiInstanceQueryInstance = EvtWmiInstanceQueryInstance;
    instanceConfig.EvtWmiInstanceSetInstance = EvtWmiInstanceSetInstance;
    instanceConfig.EvtWmiInstanceSetItem = EvtWmiInstanceSetItem;

    WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&woa, FireflyDeviceInformation);

    //
    // No need to store the WDFWMIINSTANCE in the device context because it is
    // passed back in the WMI instance callbacks and is not referenced outside
    // of those callbacks.
    //
    status = WdfWmiInstanceCreate(Device, &instanceConfig, &woa, &instance);

    if (NT_SUCCESS(status)) {
        FireflyDeviceInformation* info;

        info = InstanceGetInfo(instance);
        info->TailLit = TRUE;
    }

    return status;
}
Пример #2
0
Файл: wmi.c Проект: uri247/wdk80
NTSTATUS
Bus_WmiRegistration(
    WDFDEVICE      Device
    )
/*++
Routine Description

    Registers with WMI as a data provider for this
    instance of the device

--*/
{
    WDF_WMI_PROVIDER_CONFIG providerConfig;
    WDF_WMI_INSTANCE_CONFIG instanceConfig;
    PFDO_DEVICE_DATA deviceData;
    NTSTATUS status;
    DECLARE_CONST_UNICODE_STRING(busRsrcName, BUSRESOURCENAME);

    PAGED_CODE();

    deviceData = FdoGetData(Device);

    //
    // Register WMI classes.
    // First specify the resource name which contain the binary mof resource.
    //
    status = WdfDeviceAssignMofResourceName(Device, &busRsrcName);
    if (!NT_SUCCESS(status)) {
        return status;
    }

    WDF_WMI_PROVIDER_CONFIG_INIT(&providerConfig, &ToasterBusInformation_GUID);
    providerConfig.MinInstanceBufferSize = sizeof(TOASTER_BUS_WMI_STD_DATA);

    //
    // 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);

    //
    // By setting Regsiter to TRUE, we tell the framework to create a provider
    // as part of the Instance creation call. This eliminates the need to
    // call WdfWmiProviderRegister.
    //
    instanceConfig.Register = TRUE;
    instanceConfig.EvtWmiInstanceQueryInstance = Bus_EvtStdDataQueryInstance;
    instanceConfig.EvtWmiInstanceSetInstance = Bus_EvtStdDataSetInstance;
    instanceConfig.EvtWmiInstanceSetItem = Bus_EvtStdDataSetItem;

    status = WdfWmiInstanceCreate(
        Device,
        &instanceConfig,
        WDF_NO_OBJECT_ATTRIBUTES,
        WDF_NO_HANDLE
        );

    if (NT_SUCCESS(status)) {
        deviceData->StdToasterBusData.ErrorCount = 0;
    }

    return status;
}
Пример #3
0
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;
}
Пример #4
0
NTSTATUS
ToasterWmiRegistration(
    _In_ WDFDEVICE Device
    )

/*++

Routine Description

    Registers with WMI as a data provider for this instance of the device.

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;
    PFDO_DATA fdoData;
    PToasterDeviceInformation pData;
    PToasterControl controlData;

    WDFWMIINSTANCE instance;
    WDF_OBJECT_ATTRIBUTES woa;
    WDF_WMI_PROVIDER_CONFIG providerConfig;
    WDF_WMI_INSTANCE_CONFIG instanceConfig;
    DECLARE_CONST_UNICODE_STRING(mofResourceName, MOFRESOURCENAME);

    PAGED_CODE();

    fdoData = ToasterFdoGetData(Device);

    //
    // 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)) {

        WppPrintDeviceError(fdoData->WppRecorderLog,
                            "[Toaster] Status = 0x%08x, WdfDeviceAssignMofResourceName failed\n",
                            status);
        return status;
    }

    //
    // Initialize the config structures for the Provider and the Instance and
    // define event callback functions that support a WMI client's request to
    // access the driver's WMI data blocks.
    //

    WDF_WMI_PROVIDER_CONFIG_INIT(&providerConfig, &ToasterDeviceInformation_GUID);

    //
    // Specify minimum expected buffer size for query and set instance requests.
    // Since the query block size is different than the set block size, set it
    // to zero and manually check for the buffer size for each operation.
    //
    providerConfig.MinInstanceBufferSize = 0;

    //
    // 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 the 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 = EvtWmiInstanceStdDeviceDataQueryInstance;
    instanceConfig.EvtWmiInstanceSetInstance   = EvtWmiInstanceStdDeviceDataSetInstance;
    instanceConfig.EvtWmiInstanceSetItem       = EvtWmiInstanceStdDeviceDataSetItem;

    WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&woa, ToasterDeviceInformation);

    //
    // Create the WMI instance object for this data block.
    //
    status = WdfWmiInstanceCreate(Device,
                                  &instanceConfig,
                                  &woa,
                                  &instance);
    if (!NT_SUCCESS(status)) {

        WppPrintDeviceError(fdoData->WppRecorderLog,
                            "[Toaster] Status = 0x%08x, WdfWmiInstanceCreate failed\n",
                            status);
        return status;
    }

    pData = ToasterWmiGetData(instance);

    pData->ConnectorType = TOASTER_WMI_STD_USB;
    pData->Capacity = 2000;
    pData->ErrorCount = 0;
    pData->Controls = 5;
    pData->DebugPrintLevel = DebugLevel;

    WDF_WMI_PROVIDER_CONFIG_INIT(&providerConfig, &TOASTER_NOTIFY_DEVICE_ARRIVAL_EVENT);
    providerConfig.Flags = WdfWmiProviderEventOnly;

    //
    // Specify minimum expected buffer size for query and set instance requests.
    // Since the query block size is different than the set block size, set it
    // to zero and manually check for the buffer size for each operation.
    //
    providerConfig.MinInstanceBufferSize = 0;

    WDF_WMI_INSTANCE_CONFIG_INIT_PROVIDER_CONFIG(&instanceConfig, &providerConfig);
    instanceConfig.Register = TRUE;

    //
    // Create the WMI instance object for this data block.
    //
    status = WdfWmiInstanceCreate(Device,
                                  &instanceConfig,
                                  WDF_NO_OBJECT_ATTRIBUTES,
                                  &fdoData->WmiDeviceArrivalEvent);

    if (!NT_SUCCESS(status)) {

        WppPrintDeviceError(fdoData->WppRecorderLog,
                            "[Toaster] Status = 0x%08x, WdfWmiInstanceCreate failed\n",
                            status);
        return status;
    }


    //
    // Register the Toaster Control class.
    //

    //
    // Initialize the config structures for the Provider and the Instance and
    // define event callback functions that support a WMI client's request to
    // access the driver's WMI data blocks.
    //

    WDF_WMI_PROVIDER_CONFIG_INIT(&providerConfig, &ToasterControl_GUID);

    //
    // Specify minimum expected buffer size for query and set instance requests.
    //
    providerConfig.MinInstanceBufferSize = ToasterControl_SIZE;

    //
    // 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 the 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 = EvtWmiInstanceToasterControlQueryInstance;
    instanceConfig.EvtWmiInstanceSetInstance   = EvtWmiInstanceToasterControlSetInstance;
    instanceConfig.EvtWmiInstanceSetItem       = EvtWmiInstanceToasterControlSetItem;
    instanceConfig.EvtWmiInstanceExecuteMethod = EvtWmiInstanceToasterControlExecuteMethod;

    WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&woa, ToasterControl);

    //
    // Create the WMI instance object for this data block.
    //
    status = WdfWmiInstanceCreate(Device,
                                  &instanceConfig,
                                  &woa,
                                  &instance);
    if (!NT_SUCCESS(status)) {

        WppPrintDeviceError(fdoData->WppRecorderLog,
                            "[Toaster] Status = 0x%08x, WdfWmiInstanceCreate failed\n",
                            status);
        return status;
    }

    controlData = ToasterWmiGetControlData(instance);
    controlData->ControlValue = 25;

    return status;
}