Link to home
Start Free TrialLog in
Avatar of overlook
overlook

asked on

How to monitor the event indication between NDIS and 802.11 NIC from user mode

Dear experts,

I wanna to enable my application the cabability to record and monitor the status of 802.11 NIC real-time.  The DDK document of NdisMIndicateStatus() showes that 802.11 NIC probably indicates the link status, such as NDIS_STATUS_MEDIA_DISCONNECT and NDIS_STATUS_MEDIA_CONNECT, to ndis by NdisMIndicateStatus().

Could you please tell me if there is any possible idea and example to get these indications form IO manager, the ISR of ndis, or some kinds of virtual NIC?

Thank you very much!

-Liang
Avatar of opanza
opanza

Hi Liang,

The OID you can use for monitoring NIC status is OID_GEN_MEDIA_CONNECT_STATUS. It works like the 802.11 Wireless LAN OIDs. The values you can get from the NIC are these:

- NdisMediaStateConnected
- NdisMediaStateDisconnected

For more information about OID_GEN_MEDIA_CONNECT_STATUS: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/network/hh/network/22genoid_3c85f327-a594-4cfc-a2c0-e320e157934f.xml.asp

If you want to know what OIDs your device supports, please have a look to OID_GEN_SUPPORTED_LIST (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/network/hh/network/22genoid_bef9c800-d23a-44d3-bd6c-19be54f291cb.xml.asp)
Avatar of overlook

ASKER

Thanks for the rapid expertise feedback.

Do you mean I can query the OID_GEN_MEDIA_CONNECT_STATUS periodicly in my application to get the current status of 802.11 NIC?

However, the polling mechanism can not get all the events generated by 802.11 NIC.  According to Microsoft's document "IEEE 802.11 Network Adapter Design Guidelines for Windows XP", Native WiFi driver not only generates meida connect event when the association status changes, but also trigger a notification to the upper layer when the RSSI is below or above the threshold.  

Anyway, it's desireable if there is a facility to capture the registered NDIS events in user mode.

-Liang
Then set an RSSI trigger value. This value not only determines whether the signal strength (RSSI) changes, but also when a media-specific status indication happened.

These media-specific status indications are:

- Received signal strength indication.
- Authentication indication.
- Pairwise master key ID candidate indication.
- Media streaming indication.
- Radio state indication.

For RSSI indications, the buffer referenced by StatusBuffer must contain an NDIS_802_11_RSSI value.

For the other indications, the buffer referenced by StatusBuffer must contain the following structure:

typedef struct _NDIS_802_11_STATUS_INDICATION
{
  NDIS_802_11_STATUS_TYPE  StatusType;
} NDIS_802_11_STATUS_INDICATION, *PNDIS_802_11_STATUS_INDICATION;

The NDIS_802_11_STATUS_TYPE enumeration has the following values:

- Ndis802_11StatusType_Authentication
- Ndis802_11StatusType_PMKID_CandidateList
- Ndis802_11StatusType_MediaStreamMode
- Ndis802_11StatusType_RadioState
A correction to the above. Setting an RSSI trigger value only will retrieve media-specific RSSI indications (signal strength).

To retrive Authentication, Pairwise master key ID candidate, Media streaming and Radio state indications you have to use NdisMIndicateStatus function with the GeneralStatus parameter set to NDIS_STATUS_MEDIA_SPECIFIC_INDICATION.

Sorry about that.
Maybe you can try IOCTL_NDISUIO_REQUEST_NOTIFICATION. This IOCTL allows the application to get adapter-related notifications. It fills in a NDISUIO_DEVICE_NOTIFICATION structure. This strcture is for device notification of Media State, bind/unbind, power up/down, adapter arrival/removal, etc.
I tried to get the connection status information via the DeviceIoControl interface.  However, the return value fails to be matched with the expected value:  NDIS_STATUS_MEDIA_CONNECT and NDIS_STATUS_MEDIA_DISCONNECT.

Why?

NDIS_STATUS                  Dot11_GetMediaConnectStatus(
      HANDLE      handle )
{
      UCHAR                               buf[1024];
      NDIS_STATUS                        status = S_OK;
      PNDISUIO_QUERY_OID            pQueryOid;
      DWORD                              dwBytesReturned;
      DWORD                              dwError;


      pQueryOid = (PNDISUIO_QUERY_OID)&buf[0];
      pQueryOid->Oid = OID_GEN_MEDIA_CONNECT_STATUS;

      if (!DeviceIoControl(
                        handle,
                        IOCTL_NDISUIO_QUERY_OID_VALUE,
                        (LPVOID) &buf[0],
                        sizeof(buf),
                        (LPVOID) &buf[0],
                        sizeof(buf),
                        &dwBytesReturned,
                        NULL))
      {
            dwError = GetLastError();
            DEBUGP(("IOCTL GET_MEDIA_CONNECT_STATUS  failed: %d\n", dwError));
            status = E_FAIL;
      }



      memcpy( &status, buf, sizeof(NDIS_STATUS));

      if( status == NDIS_STATUS_MEDIA_CONNECT )
      {
            PRINTF(("media connected.\n"));
      }
      else if( status == NDIS_STATUS_MEDIA_DISCONNECT )
      {
            PRINTF(("media disconnected.\n"));
      }
      else
      {
            PRINTF(("undefined return value.\n"));
      }


      return status;
}
ASKER CERTIFIED SOLUTION
Avatar of opanza
opanza

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Liang,

i'm also trying to develop a deamon to monitor whether the Wi-Fi NIC is connected or not with Wi-Fi n/w. i want to catch the connected status and then load another C# application, and when the connection goes bad i want to pass a message to the loaded C# app. i cant go to 'rawether' library because it is commerial.

but i'm unable to understant how to start with Win  DDK's NDIS. i'm not much familer with DDK. so can u explain how to monitor the Wi-Fi NIC connection status ' NDIS_STATUS_MEDIA_CONNECT' and 'NDIS_STATUS_MEDIA_DISCONNECT' with simple example.

it is better if u can provide me a full solution of sample application as help.

thanks in advance,
netbirds@gmail.com
-netbirds-