Example #1
1
File: wmi.c Project: kcrazy/winekit
NTSTATUS
SerialWmiRegisterInstance(
    WDFDEVICE Device,
    const GUID* Guid,
    ULONG MinInstanceBufferSize,
    PFN_WDF_WMI_INSTANCE_QUERY_INSTANCE EvtWmiInstanceQueryInstance
    )
{
    WDF_WMI_PROVIDER_CONFIG providerConfig;
    WDF_WMI_INSTANCE_CONFIG instanceConfig;

    PAGED_CODE();

    //
    // Create and register WMI providers and instances  blocks
    //
    WDF_WMI_PROVIDER_CONFIG_INIT(&providerConfig, Guid);
    providerConfig.MinInstanceBufferSize = MinInstanceBufferSize;

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

    return WdfWmiInstanceCreate(Device,
                                &instanceConfig,
                                WDF_NO_OBJECT_ATTRIBUTES,
                                WDF_NO_HANDLE);
}
Example #2
0
File: wmi.c Project: ms-iot/bsp
_Use_decl_annotations_
NTSTATUS
SerialWmiRegisterInstance(
    WDFDEVICE Device,
    const GUID* Guid,
    ULONG MinInstanceBufferSize,
    PFN_WDF_WMI_INSTANCE_QUERY_INSTANCE EvtWmiInstanceQueryInstance
    )
{
    NTSTATUS status;
    WDF_WMI_PROVIDER_CONFIG providerConfig;
    WDF_WMI_INSTANCE_CONFIG instanceConfig;

    PAGED_CODE();

    TraceEvents(TRACE_LEVEL_INFORMATION, DBG_WMI, "++SerialWmiRegisterInstance\r\n");

    // Create and register WMI providers and instances  blocks

    WDF_WMI_PROVIDER_CONFIG_INIT(&providerConfig, Guid);
    providerConfig.MinInstanceBufferSize = MinInstanceBufferSize;

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

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

    TraceEvents(TRACE_LEVEL_INFORMATION, DBG_WMI, "--SerialWmiRegisterInstance()=%Xh\r\n",status);
    return status;
}
Example #3
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;
}
Example #4
0
File: wmi.c Project: 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;
}
Example #5
0
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;
}
Example #6
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;
}
Example #7
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;
}