Click here to Skip to main content
15,881,781 members
Articles / Mobile Apps / Windows Mobile

How To Query Miniport Driver Information (802.11 OIDs) using Windows Management Instrumentation (WMI) Mechanism

Rate me:
Please Sign up or sign in to vote.
3.32/5 (12 votes)
10 Apr 2009CDDL3 min read 68.3K   1.1K   27   10
Query 802.11 OIDs using WMI mechanism

Introduction

In my previous article, we have seen how to query miniport driver using DeviceIOControl function. DeviceIOControl function uses IOCTL_NDIS_QUERY_GLOBAL_STATS IOCTL and many developers are misusing this IOCTL. So this IOCTL will be deprecated in later operating system releases.

Instead of IOCTL_NDIS_QUERY_GLOBAL_STATS IOCTL, Windows Management Instrumentation (WMI) interfaces can be used for querying miniport driver information. A client application which consumes Windows Management Instrumentation (WMI) mechanism can query and set OIDs maintained by NDIS Miniport drivers.

Background

Windows Management Instrumentation (WMI) is a kernel mode service that drivers can use to make measurement and instrumentation data available to user-mode applications.

NDIS automatically registers with WMI each instance of a miniport driver as a data provider. After it is registered, WMI clients can query and set OIDs supported by the miniport driver. NDIS automatically registers GUID for standard miniport driver OIDs. You can check the standard NDIS WMI classes using wbemtest.exe tool. Run wbemtest.exe from command window and connect with “root\wmi” namespace. Now you can enumerate all NDIS WMI classes using ‘Enum Classes…’ option.

Using the Code

This article demonstrates how to query Signal Strength of a wireless network. A Wireless network card driver exposes various 802.11 OIDs and many of these OIDs are mapped into various WMI classes.

In this example code snippet given below, I am using MSNdis_80211_ReceivedSignalStrength WMI class. This is the WMI class corresponding to 802.11 OID OID_802_11_RSSI. The instance of this class returns the signal strength of currently connected wireless network. Anyway I am not going to explain in depth about System.Management namespace classes. With the help of System.Management namespace classes, we can access the instance of the above WMI class.

C#
/// <summary>
/// Print signal strength list
/// </summary>
public static void printSignalStrength(string wlanInterfaceName)
{
    try
    {
        //WMI query for accessing signal strength of wireless network
        ManagementScope ms = new ManagementScope("\\\\localhost\\root\\wmi");
        string wmiquery = string.Format("SELECT Ndis80211ReceivedSignalStrength 
		FROM  MSNdis_80211_ReceivedSignalStrength 
		where InstanceName=\"{0}\"", wlanInterfaceName);
         //way to query object state
        ObjectQuery oq = new ObjectQuery(wmiquery);
        ManagementObjectSearcher query = new ManagementObjectSearcher(ms, oq);
        ManagementObjectCollection moc = query.Get();
        ManagementObjectCollection.ManagementObjectEnumerator moe = moc.GetEnumerator();
         while (moe.MoveNext()) ;
         //accessing received signal strength property
        Int32 rssi = (Int32)moe.Current.GetPropertyValue
			("Ndis80211ReceivedSignalStrength");
         Console.WriteLine("Received Signal Strength : {0}", rssi);
    }
    catch (ManagementException e)
    {
        Console.WriteLine("Exception: {0}", e.Message);
    }
    catch (Exception e)
    {
        Console.WriteLine("Exception: {0}", e.Message);
    }
}

Here MSNdis_80211_ReceivedSignalStrength class provides a data member ‘InstanceName’ which specifies the card name used for querying signal strength. In the above example, I have hardcoded it to my wireless card name. You can check wireless adapter names using Device Manager->Network Adapters and specify a card name shown in your machine. Since MSNdis_80211_ReceivedSignalStrength requires an active wireless network connection, please ensure that your wireless card is connected into a network.

System.Management namespace provides access to management information about the system, devices, etc. Applications can query management information using classes like ManagementObjectSearcher, ManagementQuery, ManagementScope, etc. In the above code snippet, you have seen how I have used it in a C# application.

C#
//WMI query for accessing signal strength of wireless network
ManagementScope ms = new ManagementScope("\\\\localhost\\root\\wmi");

ManagementScope class specifies namespace or scope for management operations. The next statement specifies the WMI query. Here we are trying to access signal strength of currently connected wireless network. So in our case, signal strength is management information.

C#
string wmiquery = string.Format("SELECT Ndis80211ReceivedSignalStrength FROM  
    MSNdis_80211_ReceivedSignalStrength where InstanceName=\"{0}\"", wlanInterfaceName);
//way to query object state
ObjectQuery oq = new ObjectQuery(wmiquery);
ManagementObjectSearcher query = new ManagementObjectSearcher(ms, oq);

ManagementObjectSearcher class retrieves management objects on the system based on the specified query. It can be used to enumerate any management objects in the system like network adapters, processes, etc.

C#
ManagementObjectCollection moc = query.Get();
ManagementObjectCollection.ManagementObjectEnumerator moe = moc.GetEnumerator();

while (moe.MoveNext()) ;

//accessing received signal strength property
Int32 rssi = (Int32)moe.Current.GetPropertyValue("Ndis80211ReceivedSignalStrength");

The above code shows how to retrieve collection of management objects using ManagementObjectSearcher class. Moreover we can access the value of property 'Ndis80211ReceivedSignalStrength' directly from the object collection enumerator.

References

  1. How to query miniport driver information (802.11 OIDs) using DeviceIOControl() function?
  2. How to access wireless network parameters using native WiFi API?

Conclusion

This article demonstrates how to access signal strength using Windows Management Instrumentation (WMI) mechanism. In the next article, I will show you another way of accessing miniport driver information using native Wi-Fi API.

License

This article, along with any associated source code and files, is licensed under The Common Development and Distribution License (CDDL)


Written By
Software Developer (Senior)
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 5 Pin
Manoj Kumar Choubey25-Apr-12 0:30
professionalManoj Kumar Choubey25-Apr-12 0:30 
GeneralSending data to the driver using WMI Pin
kmurthyjs5-Mar-10 6:16
kmurthyjs5-Mar-10 6:16 
QuestionHow To Query Miniport Driver Information using WMI in C/C++ Pin
kmurthyjs22-Feb-10 5:47
kmurthyjs22-Feb-10 5:47 
AnswerRe: How To Query Miniport Driver Information using WMI in C/C++ Pin
Maju M3-Mar-10 16:37
Maju M3-Mar-10 16:37 
GeneralNot working in Vista Pin
tomnash9-Jan-09 13:19
tomnash9-Jan-09 13:19 
GeneralRe: Not working in Vista Pin
Maju M9-Apr-09 23:41
Maju M9-Apr-09 23:41 
GeneralCannot open driver handle Pin
RickNash14-Apr-08 5:23
RickNash14-Apr-08 5:23 
GeneralRe: Cannot open driver handle Pin
RickNash14-Apr-08 5:27
RickNash14-Apr-08 5:27 
GeneralRe: Figured this out Pin
RickNash14-Apr-08 22:22
RickNash14-Apr-08 22:22 
GeneralRe: Figured this out Pin
Maju M22-Jun-08 17:57
Maju M22-Jun-08 17:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.