6. The device extension has these extra fields added.

WMILIB_CONTEXT WmiLibInfo; // WMI Context

BOOLEAN IdlePowerDownEnable; // Enable power down option

BOOLEAN WMIEventEnabled; // Enable WMI events

WmiLibInfo is used to pass the Wdm3 WMI GUIDs and various callbacks, as described later.

IdlePowerDownEnable implements the MSPower_DeviceEnable WMI data block. If IdlePowerDownEnable is TRUE, the driver can power down when it is idle.

Finally, WMIEventEnabled is used to enable WMI event reporting.

7. The main WMI code needs to refer to the driver registry path that was passed to DriverEntry. Therefore, DriverEntry saves a copy in its Wdm3RegistryPath global variable.

// Save a copy of our RegistryPath for WMI

Wdm3RegistryPath.MaximumLength = RegistryPath->MaximumLength;

Wdm3RegistryPath.Length = 0;

Wdm3RegistryPath.Buffer = (PWSTR)ExAllocatePool(PagedPool, Wdm3RegistryPath.MaximumLength);

if (Wdm3RegistryPath.Buffer == NULL) return STATUS_INSUFFICIENT_RESOURCES;

RtlCopyUnicodeString(&Wdm3RegistryPath, RegistryPath);

The driver unload routine Wdm3Unload deletes the Wdm3RegistryPath buffer.

Registering as a WMI Data Provider

You must register as a WMI provider by calling IoWmiRegistrationControl with a WMIREG_ACTION_REGISTER command for each device when it is ready to handle WMI IRPs. The Wdm3 driver makes this call in its RegisterWmi routine. RegisterWmi is called at the end of Wdm3AddDevice. The corresponding DeregisterWmi routine deregisters the WMI support by calling IoWmiRegistrationControl with the WMIREG_ACTION_DEREGISTER command. DeregisterWmi is called when the device is removed.

Listing 12.3 shows the RegisterWmi and DeregisterWMI routines. RegisterWmi also sets up the WmiLibInfo structure in the device extension, ready for processing by the System Control WMI IRP. Table 12.1 shows the WmiLibInfo WMILIB_CONTEXT structure fields.

WmiLibInfo first contains the list of WMI block GUIDs that are handled by this driver. Wdm3GuidList is an array of these WMIGUIDREGINFO structures. Each specifies the GUID pointer, a count of instances, and optionally some flags. There is only one instance of each WMI block for this device. No flags are specified, as the appropriate flags are used later in the call to QueryWmiRegInfo.

The WMILIB_CONTEXT WmiLibInfo field also sets up several callback routines that we shall meet later. These are used to help the processing of the IRP_MJ_SYSTEM_CONTROL WMI IRP.

After calling IoWmiRegistrationControl, your driver will then be sent an IRP_MN_REGINFO System Control IRP to obtain the device's WMI MOF information, as described in the following.

Listing 12.3 RegisterWmi and DeregisterWMI code

const int GUID_COUNT = 3;

WMIGUIOREGINFO Wdm3GuidList[GUID_CЩUNT] = {

 { &WDM3_WMI_GUID, 1. 0 }, // Wdm3Information

 { &GUID_POWER_DEVICE_ENABLE, 1, 0}, // MSPower_DeviceEnable

 { &WDM3_WMI_EVENT_GUID, 1, 0}, // Wdm3Event

};

const ULONG WDM3_WMI_GUID_INDEX = 0;

const ULONG GUID_POWER_DEVICE_ENABLE_INDEX = 1;

const ULONG WDM3_WMI_EVENT_GUID_INDEX = 2;

void RegisterWmi(IN PDEVICE_OBJECT fdo) {

 PWDM3_DEVICE_EXTENSION dx=(PWDM3_DEVICE_EXTENSION)fdo->DeviceExtension;

 dx->WmiLibInfo.GuidCount = GUID_COUNT;

 dx->WmiLibInfo.GuidList = Wdm3GuidList;

 dx->WmiLibInfo.QueryWmiRegInfo = QueryWmiRegInfo;

 dx->WmiLibInfo.QueryWmiDataBlock = QueryWmiDataBlock;

 dx->WmiLibInfo.SetWmiDataBlock = SetWmiDataBlock;

 dx->WmiLibInfo.SetWmiDataItem = SetWmiDataItem;

 dx->WmiLibInfo.ExecuteWmiMethod = ExecuteWmiMethod;

 dx->WmiLibInfo.WmiFunctionControl = WmiFunctionControl;

 NTSTATUS status = IoWMIRegistrationControl(fdo, WMIREG_ACTION_REGISTER);

 DebugPrint('RegisterWmi %x', status);

}

void DeregisterWmi( IN PDEVICE_OBJECT fdo) {

 IoWMIRegistrationControl(fdo, WMIREG_ACTION_DEREGISTER);

 DebugPrintMsg('DeregisterWmi');

}

Table 12.1 WMILIB_CONTEXT structure

GuidCount ULONG Required Count of WMI blocks
GuidList  Required Array with the GUIDs of the WMI blocks supported, etc.
QueryWmiRegInfo Required Provide further information about the WMIblocks you are registering
QueryWmiDataBlock Callback Required Return a single instance or all instances of adata block
SetWmiDataBlock Callback Optional Set all data items in a single instance of adata block
SetWmiDataItem
Добавить отзыв
ВСЕ ОТЗЫВЫ О КНИГЕ В ИЗБРАННОЕ

0

Вы можете отметить интересные вам фрагменты текста, которые будут доступны по уникальной ссылке в адресной строке браузера.

Отметить Добавить цитату
×