wlanutilities/wlanqtutilities/tsrc/stubs/stub_wlanscaninfo.cpp
changeset 39 7b3e49e4608a
child 53 bdc64aa9b954
equal deleted inserted replaced
36:682dd021f9be 39:7b3e49e4608a
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 * WLAN Management API stubbing for WLAN Qt Utilities.
       
    16 */
       
    17 
       
    18 #include <e32base.h>
       
    19 #include "wlanscaninfo.h"
       
    20 
       
    21 #include <cmmanager_shim.h>
       
    22 
       
    23 #include "wlanqtutilstestcontext.h"
       
    24 #include "wlanqtutilsap.h"
       
    25 
       
    26 extern WlanQtUtilsTestContext testContext;
       
    27 
       
    28 // Information Element ID for SSID as specified in 802.11.
       
    29 static const TUint8 KWlan802Dot11SsidIE = 0;
       
    30 
       
    31 // Bit mask for Capability info field to get type (Infra/AdHoc).
       
    32 static const TUint8 KWlan802Dot11CapabilityEssMask = 0x0001;
       
    33 
       
    34 // ---------------------------------------------------------
       
    35 // CWlanScanInfo::NewL
       
    36 // ---------------------------------------------------------
       
    37 //
       
    38 CWlanScanInfo* CWlanScanInfo::NewL()
       
    39     {
       
    40     CWlanScanInfo* self = new CWlanScanInfo;
       
    41     return self;
       
    42     }
       
    43     
       
    44 // ---------------------------------------------------------
       
    45 // CWlanScanInfo::~CWlanScanInfo
       
    46 // ---------------------------------------------------------
       
    47 //
       
    48 CWlanScanInfo::~CWlanScanInfo()
       
    49     {
       
    50     }
       
    51 
       
    52 // ---------------------------------------------------------
       
    53 // CWlanScanInfo::~First
       
    54 // ---------------------------------------------------------
       
    55 //
       
    56 const TWlanScanInfoFrame* CWlanScanInfo::First()
       
    57     {
       
    58     // Rewind to the beginning of scan result list
       
    59     testContext.mScan.mScanResultIterator = 0;
       
    60     
       
    61     return (TWlanScanInfoFrame*)1;   // Info frame is not supported
       
    62     }
       
    63 
       
    64 // ---------------------------------------------------------
       
    65 // CWlanScanInfo::~Next
       
    66 // ---------------------------------------------------------
       
    67 //
       
    68 const TWlanScanInfoFrame* CWlanScanInfo::Next()
       
    69     {
       
    70     // Go to next AP in scan results
       
    71     testContext.mScan.mScanResultIterator++;
       
    72     
       
    73     return (TWlanScanInfoFrame*)1;   // Info frame is not supported
       
    74     }
       
    75 
       
    76 // ---------------------------------------------------------
       
    77 // CWlanScanInfo::~IsDone
       
    78 // ---------------------------------------------------------
       
    79 //
       
    80 TBool CWlanScanInfo::IsDone() const
       
    81     {
       
    82     TBool result = EFalse;
       
    83     
       
    84     // Iterating is complete when iterator is one past the last item
       
    85     if (testContext.mScan.mScanResultIterator >=
       
    86         testContext.mScan.mWlanScanResultList.count()) {
       
    87         result = ETrue;
       
    88     }
       
    89     
       
    90     return result;
       
    91     }
       
    92 
       
    93 // ---------------------------------------------------------
       
    94 // CWlanScanInfo::RXLevel
       
    95 // ---------------------------------------------------------
       
    96 //
       
    97 TUint8 CWlanScanInfo::RXLevel() const
       
    98     {
       
    99     QSharedPointer<WlanQtUtilsAp> ap(GetCurrentAp());
       
   100     int rxlevel = ap->value(WlanQtUtilsAp::ConfIdSignalStrength).toInt();
       
   101     
       
   102     return (TUint8)rxlevel;
       
   103     }
       
   104 
       
   105 // ---------------------------------------------------------
       
   106 // CWlanScanInfo::Bssid
       
   107 // ---------------------------------------------------------
       
   108 //
       
   109 void CWlanScanInfo::Bssid(
       
   110     TWlanBssid& aBssid ) const
       
   111     {
       
   112     QSharedPointer<WlanQtUtilsAp> ap(GetCurrentAp());
       
   113     QByteArray bssid = ap->value(WlanQtUtilsAp::ConfIdBssid).toByteArray();
       
   114 
       
   115     // Length must match, since BSSID is always the same length
       
   116     Q_ASSERT(bssid.length() == KWlanMaxBssidLength);
       
   117     
       
   118     // Copy the BSSID
       
   119     aBssid.Copy((const unsigned char *)bssid.constData(), bssid.length());
       
   120     }
       
   121 
       
   122 // ---------------------------------------------------------
       
   123 // CWlanScanInfo::Capability
       
   124 // ---------------------------------------------------------
       
   125 //
       
   126 TUint16 CWlanScanInfo::Capability() const
       
   127     {
       
   128     QSharedPointer<WlanQtUtilsAp> ap(GetCurrentAp());
       
   129     
       
   130     TUint16 capabilities = 0;
       
   131     
       
   132     // Only connection mode cabability is supported 
       
   133     int connMode = ap->value(WlanQtUtilsAp::ConfIdConnectionMode).toInt();
       
   134     if (connMode == CMManagerShim::Infra) {
       
   135         capabilities |= KWlan802Dot11CapabilityEssMask; 
       
   136     }
       
   137     
       
   138     return capabilities;
       
   139     }
       
   140 
       
   141 // ---------------------------------------------------------
       
   142 // CWlanScanInfo::InformationElement
       
   143 // ---------------------------------------------------------
       
   144 //
       
   145 TInt CWlanScanInfo::InformationElement(
       
   146     TUint8 aIE, 
       
   147     TUint8& aLength, 
       
   148     const TUint8** aData )
       
   149     {
       
   150     // Static SSID buffer
       
   151     static TBuf8<255> ssidBuffer;
       
   152     
       
   153     QSharedPointer<WlanQtUtilsAp> ap(GetCurrentAp());
       
   154     
       
   155     aLength = 0;
       
   156     
       
   157     // Only SSID IE is supported
       
   158     Q_ASSERT(aIE == KWlan802Dot11SsidIE);
       
   159     (void)aIE;
       
   160     
       
   161     // Cypy the SSID
       
   162     QString ssid = ap->value(WlanQtUtilsAp::ConfIdSsid).toString();
       
   163     QByteArray ssidData(ssid.toUtf8());
       
   164     ssidBuffer.Copy(
       
   165         (TUint8*)ssidData.data(),
       
   166         ssidData.length());
       
   167 
       
   168     // Give reference to the buffer to the caller
       
   169     *aData = ssidBuffer.Ptr();
       
   170     aLength = (TUint8)ssidBuffer.Length();
       
   171     
       
   172     return KErrNone;
       
   173     }
       
   174 
       
   175 // ---------------------------------------------------------
       
   176 // CWlanScanInfo::IsProtectedSetupSupported
       
   177 // ---------------------------------------------------------
       
   178 //
       
   179 TBool CWlanScanInfo::IsProtectedSetupSupported()
       
   180     {
       
   181     QSharedPointer<WlanQtUtilsAp> ap(GetCurrentAp());
       
   182     
       
   183     TBool wpsSupport;
       
   184     bool wps = ap->value(WlanQtUtilsAp::ConfIdWpsSupported).toBool();
       
   185     if (wps) {
       
   186         wpsSupport = ETrue;
       
   187     } else {
       
   188         wpsSupport = EFalse;
       
   189     }
       
   190     
       
   191     return wpsSupport;
       
   192     }
       
   193 
       
   194 // ---------------------------------------------------------
       
   195 // CWlanScanInfo::ExtendedSecurityMode
       
   196 // ---------------------------------------------------------
       
   197 //
       
   198 TWlanConnectionExtentedSecurityMode CWlanScanInfo::ExtendedSecurityMode() const
       
   199     {
       
   200     QSharedPointer<WlanQtUtilsAp> ap(GetCurrentAp());
       
   201     int secMode = ap->value(WlanQtUtilsAp::ConfIdSecurityMode).toInt();
       
   202     bool pskUse = ap->value(WlanQtUtilsAp::ConfIdWpaPskUse).toBool();
       
   203     
       
   204     TWlanConnectionExtentedSecurityMode ret;
       
   205     switch (secMode) {
       
   206     case CMManagerShim::WlanSecModeWep:
       
   207         // Both WEP security modes are mapped to same WEP sec mode value.
       
   208         // We test both of them, and toggle the used value each time.
       
   209         static bool wepOpen = true;
       
   210         if (wepOpen) {
       
   211             ret = EWlanConnectionExtentedSecurityModeWepOpen;
       
   212         } else {
       
   213             ret = EWlanConnectionExtentedSecurityModeWepShared;
       
   214         }
       
   215         wepOpen = !wepOpen;
       
   216         break;
       
   217         
       
   218     case CMManagerShim::WlanSecMode802_1x:
       
   219         ret = EWlanConnectionExtentedSecurityMode802d1x;        
       
   220         break;
       
   221         
       
   222     case CMManagerShim::WlanSecModeWpa:
       
   223         if (pskUse)
       
   224             {
       
   225             ret = EWlanConnectionExtentedSecurityModeWpaPsk;
       
   226             }
       
   227         else
       
   228             {
       
   229             ret = EWlanConnectionExtentedSecurityModeWpa;            
       
   230             }
       
   231         break;
       
   232         
       
   233     case CMManagerShim::WlanSecModeWpa2:
       
   234         if (pskUse)
       
   235             {
       
   236             ret = EWlanConnectionExtentedSecurityModeWpa2Psk;
       
   237             }
       
   238         else
       
   239             {
       
   240             ret = EWlanConnectionExtentedSecurityModeWpa2;            
       
   241             }
       
   242         break;
       
   243         
       
   244     case CMManagerShim::WlanSecModeWapi:
       
   245         if (pskUse)
       
   246             {
       
   247             ret = EWlanConnectionExtentedSecurityModeWapiPsk;
       
   248             }
       
   249         else
       
   250             {
       
   251             ret = EWlanConnectionExtentedSecurityModeWapi;            
       
   252             }
       
   253         break;
       
   254         
       
   255     default:
       
   256         ret = EWlanConnectionExtentedSecurityModeOpen;
       
   257         break;
       
   258     }
       
   259     
       
   260     return ret;
       
   261     }
       
   262 
       
   263 // ---------------------------------------------------------
       
   264 // CWlanScanInfo::CWlanScanInfo
       
   265 // ---------------------------------------------------------
       
   266 //
       
   267 CWlanScanInfo::CWlanScanInfo()
       
   268     {
       
   269     }
       
   270 
       
   271 // ---------------------------------------------------------
       
   272 // CWlanScanInfo::GetCurrentAp
       
   273 // ---------------------------------------------------------
       
   274 //
       
   275 QSharedPointer<WlanQtUtilsAp> CWlanScanInfo::GetCurrentAp() const
       
   276     {
       
   277     // If this fails, client iterates erroneously
       
   278     Q_ASSERT(!IsDone());
       
   279     
       
   280     // Get the currently iterated AP
       
   281     QSharedPointer<WlanQtUtilsAp> ap(
       
   282         testContext.mScan.mWlanScanResultList[
       
   283             testContext.mScan.mScanResultIterator]);
       
   284     
       
   285     return ap;
       
   286     }