Click here to Skip to main content
15,879,535 members
Articles / Programming Languages / C
Tip/Trick

Demonstration of Wlan APIs from MSDN

Rate me:
Please Sign up or sign in to vote.
5.00/5 (3 votes)
27 Sep 2012CPOL 38.8K   1.6K   6   4
Windows Native API application

Introduction

This sample application is used to demonstrate WlanOpenHandle, WlanEnumInterfaces, WlanRegisterNotification, WlanScan, WlanGetNetworkBssList, WlanGetAvailableNetworkList. Parse the IES from the last beacon and probe response from BSS network. Add the IE (Information Element) during the WlanScan request. I have checked with (Intel(R) Centrino(R) Advanced-N 6205). This interface does not allow to send reserved information WiFi IES (52-126 according to the IEEE 802.11 spec) but I am able to include all the others in the scan request. I hope this code will be useful.

Background

Using the Code

Requirements:

  1. Visual Studio
  2. WDK and SDK
  3. Wireshark for verification for added IES in WlanScan request
C++
//open handle session and enumerate all wifi adapters. I have considered first adapter
//only if you have more than one adapter u need to add logic which adapter u need.

int FuncWlanOpenAndEnum()
{
	DWORD dwClientVersion=(IsVistaOrHigher() ? 2 : 1);

	printf("######## FuncWlanOpenAndEnum--->######## \n\n");
    //creating session handle for the client to connect to server.
	hResult=WlanOpenHandle(dwClientVersion,NULL,&pdwNegotiatedVersion,&phClientHandle);
	if(hResult!=ERROR_SUCCESS)
    {
    	printf("failed WlanOpenHandle=%d \n",hResult);
    	return hResult;
    }
	else
    {
    	printf("WlanOpenHandle is success=%d \n",hResult);
    }

    //Enumerates all the wifi adapters currently enabled on PC.
    //Returns the list of interfaces that are enabled on PC.
	hResult=WlanEnumInterfaces(phClientHandle,NULL,&pIfList);
	if(hResult!=ERROR_SUCCESS)
    {
    	printf("failed WlanEnumInterfaces check adapter is on=%d \n",hResult);
    	return hResult;
    }
	else
    {
    	printf("WlanEnumInterfaces is success=%d \n",hResult);
    }

	printf("######## FuncWlanOpenAndEnum<---######## \n \n");
	return hResult;
}

// prints the enumerated the interfaces add stores the interface in global variable
void FuncWlanPrintInterfaceNames()
{
	WCHAR SGuid[256]={0};

	printf("######## FuncWlanPrintInterfaceNames--->######## \n\n");

	for(unsigned int i=0;(i < pIfList->dwNumberOfItems);i++)
    {
        printf("WIFI Adapter Description =%ws \n",
            pIfList->InterfaceInfo[pIfList->dwIndex].strInterfaceDescription);
        StringFromGUID2(pIfList->InterfaceInfo[pIfList->dwIndex].InterfaceGuid,SGuid,256);
    	printf("WIFI Adapter GUID=%ws \n",SGuid);
    }
    
    //assuming PC has only one wifi card
	guidInterface=pIfList->InterfaceInfo[0].InterfaceGuid;

	printf("######## FuncWlanPrintInterfaceNames<---######## \n \n");
}
//you can refer to the sample for the other function 

Points of Interest

It will be the first sample source code that includes IE during scan request. Parsing of IES will be great as it is helpful. We can check that the required IES are received from access points.

This article was originally posted at http://code.msdn.microsoft.com

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Aricent
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

 
QuestionHi Pin
lalo132221-Jul-14 17:08
lalo132221-Jul-14 17:08 
QuestionFormatting issue with the source code Pin
Michael Haephrati25-Sep-12 9:25
professionalMichael Haephrati25-Sep-12 9:25 
AnswerRe: Formatting issue with the source code Pin
david pretham25-Sep-12 19:47
david pretham25-Sep-12 19:47 
GeneralRe: Formatting issue with the source code Pin
Member 109521065-Aug-14 22:57
Member 109521065-Aug-14 22: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.