Beispiel #1
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;    
}