Some of you might want to retrieve the BSSID of the network using WLAN Info API. Others just want to retrieve the SSID so they can use the RConnectionMonitor. But sometimes you need both information for available WLANs.
In the following code I show how to retrieve both SSID and BSSID for all available WLANs. I am presenting a static version with the code that you can just use in a function.
Contents |
Header files:
#include <wlanmgmtclient.h>
Libraries:
//You must install the WLAN Info API plug-in
Capabilities Required:
CAPABILITY NetworkServices ReadUserData WriteUserData ReadDeviceData
/**
* Function that retrieves SSID of current scaned network
*
* The SSID is the Information Element with ID = 0
* The SSID can be at most 34 bytes, so the aSSID should have the capacity for 34 bytes
*
* Returns KErrNone if successful or the type of error ocurred
*/
TInt GetSSID(CWlanScanInfo *scanInfo, TDes8 &aSSID)
{
TInt error;
TUint8 ie;
TUint8 length;
TUint8 vdata[40];
const TUint8 *data = &vdata[0];
if(scanInfo == NULL)
return KErrNullPointerPassed;
if(aSSID.MaxLength() < 34)
return KErrNoMemory;
if((error = scanInfo->FirstIE(ie, length, &data)) == KErrNone)
{
if(ie == 0)
{
aSSID.Copy(data, length);
return KErrNone;
}
}
else
return error;
while((error = scanInfo->NextIE(ie, length, &data)) == KErrNone)
{
if(ie == 0)
{
aSSID.Copy(data, length);
return KErrNone;
}
}
return error;
}
/**
* This function is used to list WLAN Info with WLAN Info API
*
* @infoBuff - when function returns it holds the WLAN Information
*/
void GetWLANAPIInfoL(TDes &infoBuff)
{
CWlanScanInfo iScanInfo;
CWlanMgmtClient iWLANMgmtClient;
iWLANMgmtClient.GetScanResults(iScanInfo);
TInt i=1, k;
TBuf<36> bss;
_LIT(KNetwork, "Network ");
_LIT(KNEWLine, "\n");
_LIT(KSeparator, " - ");
_LIT(KBSSIDFormat, "%02X:");
_LIT(KSSIDUnknown, "SSID Unknown");
infoBuff.Zero();
for(iScanInfo.First(); !iScanInfo.IsDone(); iScanInfo.Next() )
{
infoBuff.Append(KNetwork);
infoBuff.AppendNum(i);
infoBuff.Append(KSeparator);
i++;
//Retrieve BSSID
TWlanBssid bssid;
iScanInfo.Bssid( bssid );
bss.Zero();
for(k = 0; k < bssid.Length(); k++)
bss.AppendFormat(KBSSIDFormat, bssid[k]);
//remove last :
bss.Delete(bss.Length()-1, 1);
infoBuff.Append(bss);
infoBuff.Append(KSeparator);
//Get transmision level
TInt8 rxLevel = iScanInfo->RXLevel();
infoBuff.AppendNum(rxLevel);
infoBuff.Append(KSeparator);
//Get SSID
TBuf8<36> ssid;
TInt err;
err = GetSSID(&iScanInfo, ssid);
if(err== KErrNone)
{
bss.Zero();
bss.Copy(ssid);
infoBuff.Append(bss);
}
else
infoBuff.Append(KSSIDUnknown);
infoBuff.Append(KNEWLine);
}
}
No related wiki articles found