wlanutilities/wlanqtutilities/wrapper/src/wlanqtutilscmmwrapper_s60.cpp
branchGCC_SURGE
changeset 47 b3d8f88532b7
parent 34 30a5f517c615
parent 46 2fbd1d709fe7
equal deleted inserted replaced
34:30a5f517c615 47:b3d8f88532b7
     1 /*
       
     2  * Copyright (c) 2009 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  * This is a source file for CmmWrapperPrivate class.
       
    16  */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <e32base.h>
       
    20 #include <cmmanagerdef.h>
       
    21 #include <cmconnectionmethodext.h>
       
    22 #include <cmdestinationext.h>
       
    23 #include <cmpluginwlandef.h>
       
    24 #include "wlanqtutilscommon.h"
       
    25 #include "wlanqtutilsiap.h"
       
    26 #include "wlanqtutilswlanap.h"
       
    27 #include "wlanqtutilswlaniap.h"
       
    28 #include "wlanqtutilscmmwrapper.h"
       
    29 #include "wlanqtutilscmmwrapper_s60_p.h"
       
    30 
       
    31 #ifdef WLANQTUTILS_NO_OST_TRACES_FLAG
       
    32 #include <opensystemtrace.h>
       
    33 #else
       
    34 #include "OstTraceDefinitions.h"
       
    35 #endif
       
    36 #ifdef OST_TRACE_COMPILER_IN_USE
       
    37 #include "wlanqtutilscmmwrapper_s60Traces.h"
       
    38 #endif
       
    39 
       
    40 
       
    41 // =========== PRIVATE CLASS MEMBER FUNCTIONS ===============
       
    42 //
       
    43 // ---------------------------------------------------------
       
    44 // CmmWrapperPrivate::CmmWrapperPrivate()
       
    45 // Constructor
       
    46 // ---------------------------------------------------------
       
    47 //
       
    48 CmmWrapperPrivate::CmmWrapperPrivate(CmmWrapper *wrapper) :
       
    49     q_ptr(wrapper)
       
    50     {
       
    51     OstTraceFunctionEntry1( CMMWRAPPERPRIVATE_CMMWRAPPERPRIVATE_ENTRY, this );
       
    52     
       
    53     TRAPD(err, iCmManagerExt.OpenL());
       
    54     if (err != KErrNone) {
       
    55         // todo
       
    56     }
       
    57     
       
    58     OstTraceFunctionExit1( CMMWRAPPERPRIVATE_CMMWRAPPERPRIVATE_EXIT, this );
       
    59     }
       
    60 
       
    61 // ---------------------------------------------------------
       
    62 // CmmWrapperPrivate::CmmWrapperPrivate()
       
    63 // Destructor
       
    64 // ---------------------------------------------------------
       
    65 //
       
    66 CmmWrapperPrivate::~CmmWrapperPrivate()
       
    67     {
       
    68     OstTraceFunctionEntry1( CMMWRAPPERPRIVATE_CMMWRAPPERPRIVATEDESTR_ENTRY, this );
       
    69     
       
    70     iCmManagerExt.Close();
       
    71 
       
    72     OstTraceFunctionExit1( CMMWRAPPERPRIVATE_CMMWRAPPERPRIVATEDESTR_EXIT, this );
       
    73     }
       
    74 
       
    75 // ---------------------------------------------------------
       
    76 // CmmWrapperPrivate::fetchIaps()
       
    77 // ---------------------------------------------------------
       
    78 //
       
    79 int CmmWrapperPrivate::fetchIaps(QList<WlanQtUtilsIap*>& iapList)
       
    80     {    
       
    81     TRAPD(err, fetchIapsL(iapList));
       
    82     return err;
       
    83     }
       
    84 
       
    85 // ---------------------------------------------------------
       
    86 // CmmWrapperPrivate::fetchIapsL()
       
    87 // ---------------------------------------------------------
       
    88 //
       
    89 void CmmWrapperPrivate::fetchIapsL(QList<WlanQtUtilsIap*>& iapList)
       
    90     {
       
    91     OstTraceFunctionEntry1( CMMWRAPPERPRIVATE_FETCHIAPSL_ENTRY, this );
       
    92     
       
    93     // reset the list, just in case
       
    94     iapList.clear();
       
    95     
       
    96     //Array granularity 10
       
    97     RArray<TUint32> destinationIdArray = RArray<TUint32> (10);
       
    98 
       
    99     destinationIdArray.Reset();
       
   100     iCmManagerExt.AllDestinationsL(destinationIdArray);
       
   101 
       
   102     // looping all the SNAPs through
       
   103     QList<WlanQtUtilsIap*> snapsIapList;
       
   104     for (TInt i = 0; i < destinationIdArray.Count(); i++)
       
   105         {
       
   106         snapsIapList.clear();
       
   107         RCmDestinationExt dest;
       
   108         dest = iCmManagerExt.DestinationL(destinationIdArray[i]);
       
   109         TUint32 id = dest.Id();
       
   110 
       
   111         if (getIapListFromSnap(id, snapsIapList) == KErrNone)
       
   112             {
       
   113             iapList.append(snapsIapList);
       
   114             }
       
   115         }
       
   116 
       
   117     OstTraceFunctionExit1( CMMWRAPPERPRIVATE_FETCHIAPSL_EXIT, this );
       
   118     }
       
   119 
       
   120 // ---------------------------------------------------------
       
   121 // CmmWrapperPrivate::createWlanIap()
       
   122 // Creates a new WLAN IAP
       
   123 // ---------------------------------------------------------
       
   124 //
       
   125 WlanQtUtilsWlanIap *CmmWrapperPrivate::createWlanIap(const WlanQtUtilsWlanAp *aWlanAp)
       
   126     {
       
   127     WlanQtUtilsWlanIap *iap = NULL;
       
   128 
       
   129     TRAPD(err, iap = createWlanIapL(aWlanAp));
       
   130 
       
   131     if (err != KErrNone)
       
   132         {
       
   133         // Todo: trace
       
   134         }
       
   135     return iap;
       
   136     }
       
   137 
       
   138 // ---------------------------------------------------------
       
   139 // CmmWrapperPrivate::createWlanIapL()
       
   140 // Creates a new WLAN IAP
       
   141 // ---------------------------------------------------------
       
   142 //
       
   143 WlanQtUtilsWlanIap *CmmWrapperPrivate::createWlanIapL(const WlanQtUtilsWlanAp *aWlanAp)
       
   144     {
       
   145     OstTraceFunctionEntry1( CMMWRAPPERPRIVATE_CREATEWLANIAPL_ENTRY, this );
       
   146     
       
   147     // Create the new IAP
       
   148     RCmConnectionMethodExt plugin = iCmManagerExt.CreateConnectionMethodL(
       
   149             KUidWlanBearerType);
       
   150     CleanupClosePushL(plugin);
       
   151 
       
   152     // Convert QString to Symbian buffer
       
   153     TBufC<KMaxSsidLen> buffer(aWlanAp->ssid().utf16());
       
   154 
       
   155     WlanQtUtilsWlanSecMode secMode = aWlanAp->securityMode();
       
   156     int cmManagersSecMode = wlanQtUtils2CmmSecModeMap(secMode);
       
   157 
       
   158     plugin.SetStringAttributeL(CMManager::ECmName, buffer);
       
   159     plugin.SetStringAttributeL(CMManager::EWlanSSID, buffer);
       
   160     plugin.SetIntAttributeL(CMManager::EWlanSecurityMode, cmManagersSecMode);
       
   161     // Todo: other parameters such as security keys
       
   162 #if 0
       
   163     // TODO the security settings API plugin needs to be initialized here
       
   164     // with the iap id.
       
   165     // Check if the key value has been given
       
   166     QString key = aWlanAp->securityKey();
       
   167     if ( key.length() > 0 )
       
   168         {
       
   169         // Set the security key values here
       
   170         if ( secMode == CMManager::EWlanSecModeWpa || 
       
   171              secMode == CMManager::EWlanSecModeWpa2 )
       
   172             {
       
   173             // Store the WPA key to the database using the security settings API
       
   174             TBufC<KMaxWEPKeyLen> bufKey(key.utf16());
       
   175             plugin.SetStringAttributeL( CMManager::EWlanWpaPreSharedKey, bufKey );
       
   176         
       
   177             }
       
   178         else if ( secMode == CMManager::EWlanSecModeWep )
       
   179             {
       
   180             // Store the WPA key to the database using the security settings API
       
   181             TBufC<KMaxWPAKeyLen> bufKey(key.utf16());
       
   182             plugin.SetStringAttributeL( CMManager::EWlanWepKey1, bufKey );
       
   183             }
       
   184         }
       
   185 #endif
       
   186 
       
   187     plugin.UpdateL();
       
   188 
       
   189     TInt iapId = plugin.GetIntAttributeL(CMManager::ECmIapId);
       
   190     
       
   191     CleanupStack::PopAndDestroy(&plugin); // Close() called on "plugin"
       
   192 
       
   193     // Read details of the new IAP and create the WLAN IAP class
       
   194     RCmConnectionMethodExt connectionMethod = iCmManagerExt.ConnectionMethodL( iapId );
       
   195     WlanQtUtilsIap *newIap = getIapInfoL(connectionMethod);
       
   196     
       
   197     OstTraceFunctionExit1( CMMWRAPPERPRIVATE_CREATEWLANIAPL_EXIT, this );
       
   198     return qobject_cast<WlanQtUtilsWlanIap *>(newIap);
       
   199     }
       
   200     
       
   201 // ---------------------------------------------------------
       
   202 // CmmWrapperPrivate::moveIapToInternetSnap()
       
   203 // ---------------------------------------------------------
       
   204 //
       
   205 void CmmWrapperPrivate::moveIapToInternetSnap( TInt32 aIapId )
       
   206     {
       
   207     TRAPD( err, moveIapToInternetSnapL( aIapId ) );
       
   208     if (err != KErrNone)
       
   209         {
       
   210         // todo: add trace
       
   211         }
       
   212     }
       
   213 
       
   214 // ---------------------------------------------------------
       
   215 // CmmWrapperPrivate::moveIapToInternetSnapL()
       
   216 // ---------------------------------------------------------
       
   217 //
       
   218 void CmmWrapperPrivate::moveIapToInternetSnapL( TInt32 aIapId )
       
   219     {
       
   220     OstTraceFunctionEntry1( CMMWRAPPERPRIVATE_MOVEIAPTOINTERNETSNAPL_ENTRY, this );
       
   221     
       
   222     // Read all destination(SNAP) settings into an array
       
   223     RArray<TUint32> destinations;
       
   224     CleanupClosePushL(destinations);
       
   225     iCmManagerExt.AllDestinationsL(destinations);
       
   226     RCmDestinationExt destination;
       
   227     // Loop through each destination
       
   228     for(TInt i = 0; i < destinations.Count(); i++)
       
   229         {
       
   230         destination = iCmManagerExt.DestinationL(destinations[i]);
       
   231         CleanupClosePushL(destination); 
       
   232         // Internet destination will always exist in the system.
       
   233         // Internet destination will have ESnapPurposeInternet set in its metadata.
       
   234         if (destination.MetadataL(CMManager::ESnapMetadataPurpose) == CMManager::ESnapPurposeInternet)
       
   235             {
       
   236             RCmConnectionMethodExt iap = iCmManagerExt.ConnectionMethodL( aIapId );
       
   237             CleanupClosePushL( iap );        
       
   238             destination.AddConnectionMethodL( iap );
       
   239             destination.UpdateL();
       
   240             CleanupStack::PopAndDestroy(); // iap
       
   241             }
       
   242         CleanupStack::PopAndDestroy(); // destination
       
   243         }
       
   244     CleanupStack::PopAndDestroy(); // destinations
       
   245 
       
   246     OstTraceFunctionExit1( CMMWRAPPERPRIVATE_MOVEIAPTOINTERNETSNAPL_EXIT, this );
       
   247     }
       
   248     
       
   249 // ---------------------------------------------------------
       
   250 // CmmWrapperPrivate::getIapListFromSnap()
       
   251 // ---------------------------------------------------------
       
   252 //
       
   253 int CmmWrapperPrivate::getIapListFromSnap(TUint32 aDestId,
       
   254         QList<WlanQtUtilsIap*>& iapList)
       
   255     {
       
   256     OstTraceFunctionEntry1( CMMWRAPPERPRIVATE_GETIAPLISTFROMSNAP_ENTRY, this );
       
   257     
       
   258     RCmDestinationExt dest;
       
   259     TRAPD(err, dest = iCmManagerExt.DestinationL(aDestId));
       
   260     if (err != KErrNone)
       
   261         {
       
   262         OstTraceFunctionExit1( CMMWRAPPERPRIVATE_GETIAPLISTFROMSNAP_EXIT, this );
       
   263         return err;
       
   264         }
       
   265 
       
   266     // Copy IAPs from the SNAP into iapList.
       
   267     int destIapCount = dest.ConnectionMethodCount();
       
   268     for (TInt i = 0; i < destIapCount; i++)
       
   269         {
       
   270         WlanQtUtilsIap* iap = NULL;
       
   271         TRAP(err, iap = getIapInfoL(dest.ConnectionMethodL(i)));
       
   272         
       
   273         if (err == KErrNone)
       
   274             {
       
   275             iapList.append(iap);
       
   276             }
       
   277         }
       
   278 
       
   279     OstTraceFunctionExit1( DUP1_CMMWRAPPERPRIVATE_GETIAPLISTFROMSNAP_EXIT, this );
       
   280     return err;
       
   281     }
       
   282 
       
   283 // ---------------------------------------------------------
       
   284 // CmmWrapperPrivate::getIapInfoL()
       
   285 // ---------------------------------------------------------
       
   286 //
       
   287 WlanQtUtilsIap *CmmWrapperPrivate::getIapInfoL(
       
   288     RCmConnectionMethodExt aConnectionMethod)
       
   289     {
       
   290     OstTraceFunctionEntry1( CMMWRAPPERPRIVATE_GETIAPINFOL_ENTRY, this );
       
   291     
       
   292     TUint iapId = aConnectionMethod.GetIntAttributeL(CMManager::ECmIapId);
       
   293     
       
   294     TUint netId = aConnectionMethod.GetIntAttributeL(CMManager::ECmNetworkId);
       
   295 
       
   296     HBufC* iapName = aConnectionMethod.GetStringAttributeL(CMManager::ECmName);
       
   297 
       
   298     TUint iapBearerType = aConnectionMethod.GetIntAttributeL(CMManager::ECmBearerType);
       
   299 
       
   300     QString name = QString::fromUtf16(iapName->Ptr(), iapName->Length());
       
   301     WlanQtUtilsBearerType bearer;
       
   302 
       
   303     WlanQtUtilsIap* newIap = NULL;
       
   304     if (iapBearerType == KUidPacketDataBearerType)
       
   305         {
       
   306         bearer = WlanQtUtilsBearerTypeCellular;
       
   307         newIap = new WlanQtUtilsIap(iapId, netId, name, bearer);
       
   308         }
       
   309     else
       
   310         {
       
   311         TInt secModeFromCmManager =
       
   312                 aConnectionMethod.GetIntAttributeL(CMManager::EWlanSecurityMode);
       
   313         WlanQtUtilsWlanSecMode secMode = cmm2WlanQtUtilsSecModeMap(secModeFromCmManager);
       
   314         bearer = WlanQtUtilsBearerTypeWlan;
       
   315         //Note ssid is set same as iap name
       
   316         WlanQtUtilsWlanIap* wlanIap = 
       
   317             new WlanQtUtilsWlanIap(iapId, netId, name, bearer, name, secMode);
       
   318         newIap = wlanIap;
       
   319         }
       
   320 
       
   321     OstTraceFunctionExit1( CMMWRAPPERPRIVATE_GETIAPINFOL_EXIT, this );
       
   322     return newIap;
       
   323     }
       
   324 
       
   325 // ---------------------------------------------------------
       
   326 // CmmWrapperPrivate::cmm2WlanQtUtilsSecModeMap()
       
   327 // Maps CMManager's WLAN security mode into WlanQtUtilsWlanSecMode.
       
   328 // CMManager uses sec mode type TConnMonSecurityMode defined
       
   329 // in rconnmon.h.
       
   330 // ---------------------------------------------------------
       
   331 //
       
   332 WlanQtUtilsWlanSecMode CmmWrapperPrivate::cmm2WlanQtUtilsSecModeMap(int aSecModeFromCmManager)
       
   333     {
       
   334     WlanQtUtilsWlanSecMode ret;
       
   335     switch (aSecModeFromCmManager)
       
   336         {
       
   337         case CMManager::EWlanSecModeWep:
       
   338             ret = WlanQtUtilsWlanSecModeWep;
       
   339             break;
       
   340         case CMManager::EWlanSecMode802_1x:
       
   341             ret = WlanQtUtilsWlanSecMode802_1x;
       
   342             break;
       
   343         case CMManager::EWlanSecModeWpa:
       
   344             ret = WlanQtUtilsWlanSecModeWpa;
       
   345             break;
       
   346         case CMManager::EWlanSecModeWpa2:
       
   347             ret = WlanQtUtilsWlanSecModeWpa2;
       
   348             break;
       
   349         default:
       
   350             ret = WlanQtUtilsWlanSecModeOpen;
       
   351             break;
       
   352         }
       
   353     
       
   354     return ret;
       
   355     }
       
   356 
       
   357 // ---------------------------------------------------------
       
   358 // Maps WlanQtUtilsWlanSecMode into CMManager's WLAN security mode
       
   359 // (TWlanSecMode, defined in cmpluginwlandef.h).
       
   360 // ---------------------------------------------------------
       
   361 //
       
   362 int CmmWrapperPrivate::wlanQtUtils2CmmSecModeMap(WlanQtUtilsWlanSecMode aWlanQtUtilsSecMode)
       
   363     {
       
   364     int ret;
       
   365     switch (aWlanQtUtilsSecMode)
       
   366         {
       
   367         case WlanQtUtilsWlanSecModeWep:
       
   368             ret = CMManager::EWlanSecModeWep;
       
   369             break;
       
   370         case WlanQtUtilsWlanSecMode802_1x:
       
   371             ret = CMManager::EWlanSecMode802_1x;
       
   372             break;
       
   373         case WlanQtUtilsWlanSecModeWpa:
       
   374             ret = CMManager::EWlanSecModeWpa;
       
   375             break;
       
   376         case WlanQtUtilsWlanSecModeWpa2:
       
   377             ret = CMManager::EWlanSecModeWpa2;
       
   378             break;
       
   379         default:
       
   380             ret = CMManager::EWlanSecModeOpen;
       
   381             break;
       
   382         }
       
   383 
       
   384     return ret;
       
   385     }
       
   386 
       
   387 //end of file
       
   388