Пример #1
0
HBufC8* CAgentPosition::GetWiFiBufferL(TLocationAdditionalData* additionalData)
	{
	CBufBase* buffer = CBufFlat::NewL(50);
	CleanupStack::PushL(buffer);
	
	CWlanScanInfo* scanInfo=CWlanScanInfo::NewL();
	CleanupStack::PushL(scanInfo);
	CWlanMgmtClient* client=CWlanMgmtClient::NewL();
	CleanupStack::PushL(client);
	client->GetScanResults(*scanInfo);

	for(scanInfo->First(); !scanInfo->IsDone(); scanInfo->Next() )
	{
	
		TWiFiInfo wifiInfo;
		Mem::FillZ(&wifiInfo,sizeof(wifiInfo));
		
		//Retrieve BSSID
		TWlanBssid bssid;
		scanInfo->Bssid( bssid );
		//wifiInfo.macAddress.Zero();
		//wifiInfo.macAddress.Copy(bssid);
		for(TInt k = 0; k < bssid.Length(); k++)
			wifiInfo.macAddress[k] = bssid[k];
		
		//Retrieve transmision level
		TInt8 rxLevel = scanInfo->RXLevel();
		wifiInfo.rssi = rxLevel;
		
		//Retrieve SSID
		TBuf8<36> ssid;
		TInt err;
		err = GetSSID(scanInfo, ssid);
		if(err == KErrNone)
		{
			wifiInfo.ssidLen = ssid.Length();
			for(TInt i=0; i<wifiInfo.ssidLen; i++)
				wifiInfo.ssid[i] = ssid[i]; 
		}
		else 
		{
			wifiInfo.ssidLen = 0;
		}
		
		additionalData->uStructNum += 1;
		
		buffer->InsertL(buffer->Size(), &wifiInfo, sizeof(TWiFiInfo));
	}

	CleanupStack::PopAndDestroy(client);
	CleanupStack::PopAndDestroy(scanInfo);
	
	HBufC8* result = buffer->Ptr(0).AllocL();
	CleanupStack::PopAndDestroy(buffer);
	
	return result;
	}
Пример #2
0
QList<APReading*> Scanner::availableAPs()
{
  QList<APReading*> wlans;
  QString apName;
  QString apMac;
  short int apLevel;

  TUint8 ieLen = 0;
  const TUint8* ieData = NULL;
  TBuf<1000> buf16;
  TWlanBssid bssid;
  TInt retVal;

  CWlanScanInfo* pScanInfo = CWlanScanInfo::NewL();
  CleanupStack::PushL(pScanInfo);
  CWlanMgmtClient* pMgmtClient = CWlanMgmtClient::NewL();
  CleanupStack::PushL(pMgmtClient);
  pMgmtClient->GetScanResults(*pScanInfo);

  for(pScanInfo->First(); !pScanInfo->IsDone(); pScanInfo->Next() ) {
    apLevel = pScanInfo->RXLevel();

    retVal = pScanInfo->InformationElement(0, ieLen, &ieData);
    if (retVal == KErrNone) {
      TPtrC8 ptr(ieData, ieLen);
      buf16.Copy(ptr);
      apName = QString::fromUtf16(buf16.Ptr(),buf16.Length());
    }

    pScanInfo->Bssid(bssid);
    buf16.SetLength(0);
    for(TInt i = 0; i < bssid.Length(); i++)
      buf16.AppendFormat(_L("%02x:"), bssid[i]);

    if (buf16.Length() > 0)
      buf16.Delete(buf16.Length()-1, 1);

    apMac = QString::fromUtf16(buf16.Ptr(),buf16.Length());
    APReading *wlan = new APReading(apName, apMac, apLevel);
    wlans << wlan;
  }

  CleanupStack::PopAndDestroy(pMgmtClient);
  CleanupStack::PopAndDestroy(pScanInfo);

  return wlans;
}
QList<XQWLAN> XQAccessPointManagerPrivate::availableWLANs2L() const
{
    QList<XQWLAN> wlans;

    TWlanConnectionSecurityMode securityMode;
    TUint8 ieLen = 0;
    const TUint8* ieData = NULL;
    TBuf<1000> buf16;
    TUint16 capability;
    TInt lanType;
    TWlanBssid bssid;
    TInt retVal;
    
    CWlanScanInfo* pScanInfo = CWlanScanInfo::NewL();
    CleanupStack::PushL(pScanInfo);
    CWlanMgmtClient* pMgmtClient = CWlanMgmtClient::NewL();
    CleanupStack::PushL(pMgmtClient);
    pMgmtClient->GetScanResults(*pScanInfo);

    for(pScanInfo->First(); !pScanInfo->IsDone(); pScanInfo->Next() ) {
        XQWLAN wlan;
        wlan.d = new XQWLANPrivate();
    
        securityMode = pScanInfo->SecurityMode();
        switch (securityMode) {
            case EWlanConnectionSecurityOpen:
                wlan.d->securityMode = XQWLAN::WlanSecurityModeOpen;
                break;
            case EWlanConnectionSecurityWep:
                wlan.d->securityMode = XQWLAN::WlanSecurityModeWep;
                break;
            case EWlanConnectionSecurity802d1x:
                wlan.d->securityMode = XQWLAN::WlanSecurityMode802_1x;
                break;
            case EWlanConnectionSecurityWpa:
                wlan.d->securityMode = XQWLAN::WlanSecurityModeWpa;
                break;
            case EWlanConnectionSecurityWpaPsk:
                wlan.d->securityMode = XQWLAN::WlanSecurityModeWpa2;
                break;
        }
        
        //In general if the least significant bit of the capability field
        //is 1 then the network is of "Infrastructure Type" or else if the
        //capability field is 0 then the network is of "Ad-hoc type"
        capability = pScanInfo->Capability();
        lanType = capability & 1;
        if (lanType == 1) {
            wlan.d->networkMode = XQWLAN::WlanNetworkModeInfra;
        } else {
            wlan.d->networkMode = XQWLAN::WlanNetworkModeAdhoc;
        }
        
        wlan.d->signalStrength = pScanInfo->RXLevel();
        
        retVal = pScanInfo->InformationElement(KWlan802Dot11SsidIE, ieLen, &ieData);
        if (retVal == KErrNone) {
            TPtrC8 ptr(ieData, ieLen);
            buf16.Copy(ptr);
            wlan.d->ssid = QString::fromUtf16(buf16.Ptr(),buf16.Length());
        }
        
        pScanInfo->Bssid(bssid);
        buf16.SetLength(0);
        for(TInt i = 0; i < bssid.Length(); i++) {
            buf16.AppendFormat(_L("%02x:"), bssid[i]);
        }
        if (buf16.Length() > 0) {
            buf16.Delete(buf16.Length()-1, 1);
        }
        wlan.d->mac = QString::fromUtf16(buf16.Ptr(),buf16.Length());
        
        wlans << wlan;
    }

    CleanupStack::PopAndDestroy(pMgmtClient);    
    CleanupStack::PopAndDestroy(pScanInfo);
    
    return wlans;    
}