creator/engine/src/creator_connectionmethod.cpp
branchRCL_3
changeset 22 fad26422216a
parent 21 b3cee849fa46
child 23 f8280f3bfeb7
equal deleted inserted replaced
21:b3cee849fa46 22:fad26422216a
     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 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "engine.h"
       
    20 #include "enginewrapper.h"
       
    21 #include "creator_connectionmethod.h" 
       
    22 #include "creator_traces.h"
       
    23 
       
    24 
       
    25 
       
    26 using namespace CMManager;
       
    27 //#define KUidLanBearerType  0x1020737A
       
    28 #include <cmpluginpacketdatadef.h>  
       
    29 #include <cmplugincsddef.h> 
       
    30 #include <cmpluginhscsddef.h> 
       
    31 #include <cmmanagerext.h>
       
    32 #include <cmdestinationext.h> 
       
    33 #include <cmpluginembdestinationdef.h>
       
    34 #include <cmpluginvpndef.h>
       
    35 #include <cmpluginlandef.h> 
       
    36 #include <cmdefconnvalues.h>
       
    37 #include <cmconnectionmethoddef.h>
       
    38 
       
    39 
       
    40 #include <wlanmgmtinterface.h>
       
    41 #include <wlanmgmtclient.h>
       
    42 #include <wlanmgmtclient.inl> 
       
    43 #include <wlanmgmtcommon.h> 
       
    44 #include <wlanscaninfo.h> 
       
    45 #include <wlanscaninfo.inl> 
       
    46 #include <wlanscaninfointerface.h>
       
    47 
       
    48 //#include <WEPSecuritySettingsUI.h>//For WEP setting
       
    49 //#include <dbcreatorcommon.h>
       
    50 
       
    51 static const TInt KConnectionSettingssFieldLength = 128;
       
    52 
       
    53 _LIT(KCreatorConnectionSettingssPrefixName, "CR_");
       
    54 
       
    55 //----------------------------------------------------------------------------
       
    56 
       
    57 CConnectionSettingsParameters::CConnectionSettingsParameters()
       
    58     {
       
    59     LOGSTRING("Creator: CConnectionSettingsParameters::CConnectionSettingsParameters");
       
    60         
       
    61     iConnectionName = HBufC::New(KConnectionSettingssFieldLength);
       
    62     iStartPage = HBufC::New(KConnectionSettingssFieldLength);
       
    63     iLoginName = HBufC::New(KConnectionSettingssFieldLength);
       
    64     iLoginPass = HBufC::New(KConnectionSettingssFieldLength);
       
    65     iIPAddr = HBufC::New(KConnectionSettingssFieldLength);
       
    66     iIP4NameServer1 = HBufC::New(KConnectionSettingssFieldLength);
       
    67     iIP4NameServer2 = HBufC::New(KConnectionSettingssFieldLength);
       
    68     iDefaultTelNumber = HBufC::New(KConnectionSettingssFieldLength);
       
    69     iProxyServerAddress = HBufC::New(KConnectionSettingssFieldLength);
       
    70     iSubnetMask = HBufC::New(KConnectionSettingssFieldLength); 
       
    71     iGatewayAddress = HBufC::New(KConnectionSettingssFieldLength);
       
    72     iWLANName = HBufC::New(KConnectionSettingssFieldLength);
       
    73     iWlanIpAddr = HBufC::New(KConnectionSettingssFieldLength);
       
    74     iIP6NameServer1 = HBufC::New(KConnectionSettingssFieldLength);
       
    75     iIP6NameServer2 = HBufC::New(KConnectionSettingssFieldLength);
       
    76     }
       
    77 
       
    78 CConnectionSettingsParameters::~CConnectionSettingsParameters()
       
    79     {
       
    80     LOGSTRING("Creator: CConnectionSettingssParameters::~CConnectionSettingssParameters");
       
    81 
       
    82     delete iProxyServerAddress;
       
    83     delete iDefaultTelNumber;
       
    84     delete iIP4NameServer2;
       
    85     delete iIP4NameServer1;
       
    86     delete iIPAddr;    
       
    87     delete iLoginPass;
       
    88     delete iLoginName;
       
    89     delete iStartPage;
       
    90     delete iConnectionName;
       
    91     delete iSubnetMask;  
       
    92     delete iGatewayAddress;
       
    93     delete iWLANName;
       
    94     delete iWlanIpAddr;
       
    95     delete iIP6NameServer1;
       
    96     delete iIP6NameServer2;    
       
    97     }
       
    98 
       
    99 //----------------------------------------------------------------------------
       
   100 
       
   101 CCreatorConnectionSettings* CCreatorConnectionSettings::NewL(CCreatorEngine* aEngine)
       
   102     {
       
   103     CCreatorConnectionSettings* self = CCreatorConnectionSettings::NewLC(aEngine);
       
   104     CleanupStack::Pop(self);
       
   105     return self;
       
   106     }
       
   107 
       
   108 CCreatorConnectionSettings* CCreatorConnectionSettings::NewLC(CCreatorEngine* aEngine)
       
   109     {
       
   110     CCreatorConnectionSettings* self = new (ELeave) CCreatorConnectionSettings;
       
   111     CleanupStack::PushL(self);
       
   112     self->ConstructL(aEngine);
       
   113     return self;
       
   114     }
       
   115 
       
   116 CCreatorConnectionSettings::CCreatorConnectionSettings()
       
   117     {
       
   118     }
       
   119 
       
   120 void CCreatorConnectionSettings::ConstructL(CCreatorEngine* aEngine)
       
   121     {
       
   122     LOGSTRING("Creator: CCreatorConnectionSettings::ConstructL");
       
   123 
       
   124     iEngine = aEngine;
       
   125     
       
   126     iCmManagerExt.CreateTablesAndOpenL();
       
   127     }
       
   128 
       
   129 CCreatorConnectionSettings::~CCreatorConnectionSettings()
       
   130     {
       
   131     LOGSTRING("Creator: CCreatorConnectionSettings::~CCreatorConnectionSettings");
       
   132 
       
   133     if ( iEngine && iEntryIds.Count() )
       
   134         {
       
   135         TRAP_IGNORE( iEngine->WriteEntryIdsToStoreL( iEntryIds, KUidDictionaryUidIAP ) );
       
   136         }
       
   137     iEntryIds.Reset();
       
   138     iEntryIds.Close();
       
   139     
       
   140     if (iParameters)
       
   141         {
       
   142         delete iParameters;
       
   143         }
       
   144     
       
   145     iCmManagerExt.Close();
       
   146     }
       
   147     
       
   148 
       
   149 //----------------------------------------------------------------------------
       
   150 
       
   151 TBool CCreatorConnectionSettings::AskDataFromUserL(TInt aCommand)
       
   152     {
       
   153     LOGSTRING("Creator: CCreatorConnectionSettings::AskDataFromUserL");
       
   154     
       
   155     CCreatorModuleBase::AskDataFromUserL( aCommand );
       
   156     
       
   157     if( aCommand == ECmdDeleteIAPs )
       
   158         {
       
   159         return iEngine->GetEngineWrapper()->YesNoQueryDialog(_L("Delete all Connection Methods?"), this, ECreatorModuleDelete );
       
   160         }
       
   161     else if( aCommand == ECmdDeleteCreatorIAPs )
       
   162         {
       
   163         return iEngine->GetEngineWrapper()->YesNoQueryDialog(_L("Delete all Connection Methods created with Creator?"), this, ECreatorModuleDelete );
       
   164         }
       
   165     else
       
   166         {
       
   167         return iEngine->GetEngineWrapper()->EntriesQueryDialog(&iEntriesToBeCreated, _L("How many entries to create?"), EFalse, this, ECreatorModuleStart );
       
   168         }
       
   169     }
       
   170 
       
   171 
       
   172 //----------------------------------------------------------------------------
       
   173 
       
   174 TInt CCreatorConnectionSettings::CreateConnectionSettingsEntryL(CCreatorModuleBaseParameters *aParameters)
       
   175     {
       
   176     LOGSTRING("Creator: CCreatorConnectionSettings::CreateConnectionSettingsEntryL");
       
   177 
       
   178     CConnectionSettingsParameters* parameters = (CConnectionSettingsParameters*) aParameters;
       
   179     
       
   180     // clear any existing parameter definations 
       
   181     delete iParameters;
       
   182     iParameters = NULL;
       
   183             
       
   184     // random data needed if no predefined data available
       
   185     if (!parameters)
       
   186         {
       
   187         iParameters = new (ELeave) CConnectionSettingsParameters();
       
   188         parameters = iParameters;
       
   189         SetRandomParametersL(*parameters);
       
   190         }
       
   191     
       
   192     if( parameters->iBearerType == KRandomBearerType )
       
   193     	{
       
   194     	SetRandomBearerTypeL(*parameters);
       
   195     	}
       
   196     
       
   197     TInt err = KErrNone;
       
   198 
       
   199     // create unique name for each network destination
       
   200     RCmDestinationExt dest;
       
   201     TInt destinationError = KErrNone;
       
   202     TInt count = 0;
       
   203 	TBuf<KConnectionSettingssFieldLength> name;
       
   204 	name.Copy(parameters->iConnectionName->Des());
       
   205     do
       
   206     	{
       
   207     	TRAP(destinationError, dest = iCmManagerExt.CreateDestinationL(name));
       
   208     	if (destinationError == KErrAlreadyExists)
       
   209     		{
       
   210     		name.Copy(parameters->iConnectionName->Des());
       
   211     		count++;
       
   212     		name.AppendFormat(_L(" (%d)"), count);
       
   213     		}
       
   214     	else if (destinationError != KErrNone)
       
   215     		{
       
   216     		User::Leave(destinationError);
       
   217     		}
       
   218     	}
       
   219     while (destinationError == KErrAlreadyExists);
       
   220     parameters->iConnectionName->Des().Copy(name);        
       
   221 
       
   222     CleanupClosePushL(dest);
       
   223     dest.UpdateL();
       
   224     
       
   225     RCmConnectionMethodExt conMethod = dest.CreateConnectionMethodL( parameters->iBearerType);//KUidPacketDataBearerType
       
   226     CleanupClosePushL( conMethod );
       
   227     
       
   228     if(parameters->iBearerType == KUidWlanBearerType)
       
   229         {
       
   230         //IP net mask of interface
       
   231         conMethod.SetStringAttributeL( EWlanIpNetMask, parameters->iSubnetMask->Des()  );
       
   232 
       
   233         //IP address of EPOC.
       
   234         conMethod.SetStringAttributeL( EWlanIpAddr, parameters->iWlanIpAddr->Des()  );
       
   235         //
       
   236         //following gateway ID:s is not workin, 
       
   237         //logically ID would be EWlanIpGateway because EWlanIpNetMask
       
   238         //is going to net mask, which is just before gateway in ui
       
   239         //--->
       
   240         conMethod.SetStringAttributeL( EWlanIpGateway, parameters->iGatewayAddress->Des()  );
       
   241         //conMethod.SetStringAttributeL( EApIspIPGateway, parameters->iGatewayAddress->Des()  );
       
   242         conMethod.SetStringAttributeL( ECmWapIPGatewayAddress, parameters->iGatewayAddress->Des()  );
       
   243         conMethod.SetStringAttributeL( ECmIPGateway, parameters->iGatewayAddress->Des()  );
       
   244         //<---
       
   245         
       
   246         //IP Address of primary and secondary name server (IP v4).
       
   247         conMethod.SetStringAttributeL( EWlanIpNameServer1, parameters->iIP4NameServer1->Des()  );
       
   248         conMethod.SetStringAttributeL( EWlanIpNameServer2, parameters->iIP4NameServer2->Des()  );
       
   249         //The SSID of this WLAN connection.
       
   250         conMethod.SetStringAttributeL( EWlanSSID, parameters->iWLANName->Des()  );
       
   251 
       
   252         //IP6 address of primary and secondary name servers
       
   253         conMethod.SetStringAttributeL( EWlanIp6NameServer1, parameters->iIP6NameServer1->Des()  );
       
   254         conMethod.SetStringAttributeL( EWlanIp6NameServer2, parameters->iIP6NameServer2->Des()  );        
       
   255 
       
   256         //
       
   257         //Setting secure mode settings
       
   258         //
       
   259         
       
   260         //Network status (default: EWlanSecModeOpen) // EWlanAuthenticationMode use instead?
       
   261         conMethod.SetIntAttributeL( EWlanSecurityMode, parameters->iWLanSecMode );
       
   262         //WLAN Network mode  
       
   263         conMethod.SetIntAttributeL( EWlanConnectionMode, parameters->iWlanNetMode );
       
   264         
       
   265         
       
   266         if(parameters->iWLanSecMode == EWlanSecModeOpen)
       
   267             {}//Nothing to set when mode is open
       
   268         else if(parameters->iWLanSecMode == EWlanSecModeWep)
       
   269             {
       
   270             //See WEPSecuritySettingsUI.h
       
   271             
       
   272             
       
   273             ///CWEPSecuritySettings
       
   274            // conMethod.SetIntAttributeL( EWlanSecurityMode, parameters->iWLanSecMode );
       
   275             }
       
   276         else if(parameters->iWLanSecMode == EWlanSecMode802_1x)
       
   277             {
       
   278             }
       
   279         else if(parameters->iWLanSecMode == EWlanSecModeWpa)
       
   280             {
       
   281             }
       
   282         else if(parameters->iWLanSecMode == EWlanSecModeWpa2)
       
   283             {
       
   284             }            
       
   285         
       
   286         //WLAN security setting 
       
   287         //conMethod.SetStringAttributeL( EWlanAuthenticationMode, parameters->iIP6NameServer2->Des()  );
       
   288         //Utilise this method
       
   289         //conMethod.SetStringAttributeL( EWlanSecurityMode, parameters->iWLanSecMode  );
       
   290         }
       
   291     //Not known special attributes for packet data 
       
   292     else if(parameters->iBearerType == KUidPacketDataBearerType)
       
   293         {
       
   294 
       
   295         //Access point name.
       
   296         conMethod.SetStringAttributeL( EPacketDataAPName, parameters->iConnectionName->Des() );//crash
       
   297         
       
   298         //Authentication user name
       
   299         conMethod.SetStringAttributeL( EPacketDataIFAuthName, parameters->iLoginName->Des()  );
       
   300         ///TProtocolType a;
       
   301         //EPdpTypeIPv4 or EPdpTypeIPv6
       
   302         conMethod.SetIntAttributeL( EPacketDataPDPType, parameters->iProtocolType  );
       
   303                 
       
   304         //IP6 address of primary and secondary name servers
       
   305         conMethod.SetStringAttributeL( EPacketDataIPIP6NameServer1, parameters->iIP6NameServer1->Des()  );
       
   306         conMethod.SetStringAttributeL( EPacketDataIPIP6NameServer2, parameters->iIP6NameServer2->Des()  );                
       
   307         //IP address of primary name server
       
   308         conMethod.SetStringAttributeL( EPacketDataIPNameServer1, parameters->iIP4NameServer1->Des()  );
       
   309         //IP address of secondary name server
       
   310         conMethod.SetStringAttributeL( EPacketDataIPNameServer2, parameters->iIP4NameServer2->Des()  );
       
   311         
       
   312         //Also existing but UI not showing them: EPacketDataHeaderCompression, EPacketDataDisablePlainTextAuth
       
   313         //EPacketDataIFAuthPass, EDialIFAuthPass, EPacketDataIFPromptForAuth, EPacketDataIPAddr
       
   314         }
       
   315     else if(parameters->iBearerType == KUidCSDBearerType || parameters->iBearerType == KUidHSCSDBearerType)
       
   316         {
       
   317         //Authentication user name
       
   318         conMethod.SetStringAttributeL( EDialIFAuthName, parameters->iLoginName->Des()  );
       
   319         //Dial-up number
       
   320         conMethod.SetStringAttributeL( EDialDefaultTelNum, parameters->iDefaultTelNumber->Des() );
       
   321         //Call type
       
   322         conMethod.SetIntAttributeL( EDialCallType , parameters->iBearerCallTypeIsdn );
       
   323         //Maximum speed
       
   324         conMethod.SetIntAttributeL( EDialMaxConnSpeed, parameters->iBearerSpeed );
       
   325         //Prompt user for username and password? (Only for dial out)
       
   326         conMethod.SetBoolAttributeL( EDialPromptForLogin, parameters->iPromptPassword );
       
   327         //IP6 address of primary and secondary name servers
       
   328         conMethod.SetStringAttributeL( EDialIP6NameServer1, parameters->iIP6NameServer1->Des()  );
       
   329         conMethod.SetStringAttributeL( EDialIP6NameServer2, parameters->iIP6NameServer2->Des()  );         
       
   330         //Disable plaintext authentication
       
   331         conMethod.SetBoolAttributeL( EDialDisablePlainTextAuth, parameters->iDisableTextAuth );       
       
   332         //IP address of primary name server
       
   333         conMethod.SetStringAttributeL( EDialIPNameServer1, parameters->iIP4NameServer1->Des()  );
       
   334         //IP address of secondary name server
       
   335         conMethod.SetStringAttributeL( EDialIPNameServer2, parameters->iIP4NameServer2->Des()  );
       
   336 
       
   337         //Also existing  EDialEnableIPHeaderComp; EDialIFPromptForAuth;EDialIPAddress parameters
       
   338         
       
   339         }
       
   340     else if(parameters->iBearerType == KUidLanBearerType)
       
   341         {
       
   342 
       
   343         conMethod.SetStringAttributeL( ELanIpNetMask, parameters->iSubnetMask->Des() );
       
   344         conMethod.SetStringAttributeL( ELanIpGateway, parameters->iGatewayAddress->Des());
       
   345         conMethod.SetStringAttributeL( ELanIpAddr, parameters->iIPAddr->Des() );
       
   346         conMethod.SetStringAttributeL( ELanIpNameServer1, parameters->iIP4NameServer1->Des() );
       
   347         conMethod.SetStringAttributeL( ELanIpNameServer2, parameters->iIP4NameServer2->Des() );
       
   348         conMethod.SetStringAttributeL( ELanIp6NameServer1,parameters->iIP6NameServer1->Des() );
       
   349         conMethod.SetStringAttributeL( ELanIp6NameServer2,parameters->iIP6NameServer2->Des() );
       
   350         
       
   351         }
       
   352     else //KUidEmbeddedDestination and KPluginVPNBearerTypeUid
       
   353         {
       
   354         //NOTE: NOT Tested, because no supporting Emulator for them
       
   355         
       
   356         //Authentication user name
       
   357         conMethod.SetStringAttributeL( ECmIFAuthName, parameters->iLoginName->Des()  );
       
   358         //IP6 address of primary and secondary name servers
       
   359         conMethod.SetStringAttributeL( ECmIP6NameServer1, parameters->iIP6NameServer1->Des()  );
       
   360         conMethod.SetStringAttributeL( ECmIP6NameServer2, parameters->iIP6NameServer2->Des()  );        
       
   361         //Disable plaintext authentication
       
   362         conMethod.SetBoolAttributeL( ECmDisablePlainTextAuth, parameters->iDisableTextAuth );
       
   363         //Prompt user for authentication
       
   364         conMethod.SetBoolAttributeL( ECmIFPromptForAuth, parameters->iPromptPassword );
       
   365         //Authentication password
       
   366         conMethod.SetStringAttributeL( ECmIFAuthPass, parameters->iLoginPass->Des()  );
       
   367         }
       
   368     
       
   369     //
       
   370     //Adding common attributes, all not neccessary used with all bearer types, but should not cause any problems eather
       
   371     //
       
   372 
       
   373     //CM Name (Connection Method, formelly known as Access Point)         
       
   374     conMethod.SetStringAttributeL( ECmName, parameters->iConnectionName->Des() );        
       
   375     // Start page of CM
       
   376     conMethod.SetStringAttributeL( ECmStartPage, parameters->iStartPage->Des() );
       
   377     // Enable Proxy   
       
   378     conMethod.SetBoolAttributeL( ECmProxyUsageEnabled, parameters->iUseProxy );
       
   379     // Server Name
       
   380     conMethod.SetStringAttributeL( ECmProxyServerName, parameters->iProxyServerAddress->Des() );
       
   381     // Port Number
       
   382     conMethod.SetIntAttributeL( ECmProxyPortNumber, parameters->iProxyPortNumber );
       
   383     //Proxy login name
       
   384     conMethod.SetStringAttributeL( ECmWapIPProxyLoginName, parameters->iLoginName->Des() );
       
   385     //Proxy login password
       
   386     conMethod.SetStringAttributeL( ECmWapIPProxyLoginPass, parameters->iLoginPass->Des() );
       
   387     //IP address of gateway
       
   388     conMethod.SetStringAttributeL( ECmIPGateway, parameters->iGatewayAddress->Des() );
       
   389     //connection-oriented or connectionless API should be used
       
   390     //ECmWapIPWSPOption option TWapWSPOption: ECmWapWspOptionConnectionless or ECmWapWspOptionConnectionOriented    
       
   391     conMethod.SetIntAttributeL( ECmWapIPWSPOption, parameters->iWapWspOption );   
       
   392     //NOT WORKING????? Attempt secure WTLS connection to the gateway
       
   393     conMethod.SetBoolAttributeL( ECmWapIPSecurity, parameters->iSecureAuthentication );
       
   394       
       
   395     //
       
   396     //Adding advanced settings (Network type, Phone IP addr, DNS addr, proxy srv name, proxy port nbr
       
   397     //
       
   398     
       
   399     //IP address of interface
       
   400     conMethod.SetStringAttributeL( ECmIPAddress, parameters->iIPAddr->Des() );    
       
   401     //IP address of primary name server
       
   402     conMethod.SetStringAttributeL( ECmIPNameServer1, parameters->iIP4NameServer1->Des()  );
       
   403     //IP address of secondary name server
       
   404     conMethod.SetStringAttributeL( ECmIPNameServer2, parameters->iIP4NameServer2->Des()  );
       
   405       
       
   406     
       
   407     conMethod.UpdateL();
       
   408 
       
   409     //If no defaults set, set the created CM as a default
       
   410     SetDefaultCML( conMethod );
       
   411     
       
   412     // id has been generated, store it for being able to delete
       
   413     // only entries created with Creator
       
   414     iEntryIds.Append( dest.Id() );
       
   415     
       
   416     conMethod.Close();
       
   417     CleanupStack::Pop(  );//conMethod
       
   418     
       
   419     dest.UpdateL();
       
   420     dest.Close();
       
   421     CleanupStack::Pop(); // dest
       
   422         
       
   423     return err;
       
   424     }
       
   425 
       
   426 //----------------------------------------------------------------------------
       
   427 void CConnectionSettingsParameters::SetRandomCMNameL(CCreatorEngine& aEngine)
       
   428     {
       
   429     LOGSTRING("Creator: CConnectionSettingsParameters::SetRandomCMNameL");
       
   430 
       
   431     TInt num = aEngine.RandomNumber(1, 3);
       
   432     TBuf<10> apType;
       
   433 
       
   434     if (num==1)
       
   435         {
       
   436         apType = _L("mms");
       
   437         }            
       
   438     else if (num==2)
       
   439         {
       
   440         apType = _L("wap");
       
   441         }
       
   442     else
       
   443         {
       
   444         apType = _L("internet");
       
   445         }
       
   446     TBuf<160> company = aEngine.RandomString(CCreatorEngine::ECompany);
       
   447     iConnectionName->Des() = KCreatorConnectionSettingssPrefixName;
       
   448     iConnectionName->Des().Append( company );
       
   449     iConnectionName->Des().Append(_L(" "));
       
   450     iConnectionName->Des().Append(apType);
       
   451     }
       
   452 
       
   453 void CConnectionSettingsParameters::SetRandomWLANNameL(CCreatorEngine& aEngine)
       
   454     {
       
   455     LOGSTRING("Creator: CConnectionSettingsParameters::SetRandomWLANNameL");
       
   456 
       
   457     TBuf<160> company = aEngine.RandomString(CCreatorEngine::ECompany);
       
   458     iWLANName->Des() = KCreatorConnectionSettingssPrefixName;
       
   459     iWLANName->Des().Append( company );
       
   460     iWLANName->Des().Append( _L(" WLAN") );
       
   461     }
       
   462 
       
   463 void CConnectionSettingsParameters::SetRandomWLANNetModeL(CCreatorEngine& aEngine)
       
   464     {
       
   465     LOGSTRING("Creator: CConnectionSettingsParameters::SetRandomWLANNetModeL");
       
   466 
       
   467     TInt wlanNetModeRand = aEngine.RandomNumber(1, 2);
       
   468     if(wlanNetModeRand == 1)
       
   469         {
       
   470         iWlanNetMode = EAdhoc;//Ad-Hoc mode
       
   471         }
       
   472     else
       
   473         {
       
   474         iWlanNetMode = CMManager::EInfra;//Infrastructure mode
       
   475         } 
       
   476     }
       
   477 
       
   478 void CConnectionSettingsParameters::SetRandomWLANSecurityModeL(CCreatorEngine& aEngine)
       
   479     {
       
   480     LOGSTRING("Creator: CConnectionSettingsParameters::SetRandomWLANSecurityModeL");
       
   481 
       
   482     TInt wlanSecModeRand = aEngine.RandomNumber(1, 5);
       
   483     if(wlanSecModeRand == 1)
       
   484         {
       
   485         iWLanSecMode = EWlanSecModeOpen;///< Open security mode
       
   486         }
       
   487     else if(wlanSecModeRand == 2)
       
   488         {
       
   489         iWLanSecMode = EWlanSecModeWep;///< WEP security mode
       
   490         //See WEPSecuritySettingsUI.h
       
   491                 
       
   492         ///CWEPSecuritySettings
       
   493                 
       
   494         //WEP key in us
       
   495         
       
   496         //Authentication type
       
   497                 
       
   498         //WEP Key settings (key len, key format, key data)        
       
   499         }
       
   500     else if(wlanSecModeRand == 3)
       
   501         {
       
   502         iWLanSecMode = EWlanSecMode802_1x; ///< 802.1x security mode
       
   503         }
       
   504     else if(wlanSecModeRand == 4)
       
   505         {
       
   506         iWLanSecMode = EWlanSecModeWpa;///< WPA security mode
       
   507         }
       
   508     else if(wlanSecModeRand == 5)
       
   509         {
       
   510         iWLanSecMode = EWlanSecModeWpa2;///< WPA@ security mode
       
   511         }
       
   512     }
       
   513 
       
   514 void CConnectionSettingsParameters::SetRandomLoginNameL(CCreatorEngine& aEngine)
       
   515     {
       
   516     iLoginName->Des() = aEngine.RandomString(CCreatorEngine::EFirstName);
       
   517     iLoginName->Des().LowerCase();
       
   518     }
       
   519 
       
   520 void CConnectionSettingsParameters::SetRandomLoginPassL(CCreatorEngine& aEngine)
       
   521     {
       
   522     iLoginPass->Des() = aEngine.RandomString(CCreatorEngine::ESurname);
       
   523     iLoginPass->Des().LowerCase();
       
   524     }
       
   525 
       
   526 void CConnectionSettingsParameters::SetRandomSecureAuthenticationL(CCreatorEngine& /*aEngine*/)
       
   527     {
       
   528     iSecureAuthentication = EFalse;
       
   529     }
       
   530 
       
   531 void CConnectionSettingsParameters::SetRandomPromptPasswordL(CCreatorEngine& /*aEngine*/)
       
   532     {
       
   533     iPromptPassword = ETrue;
       
   534     }
       
   535 
       
   536 void CConnectionSettingsParameters::SetRandomUseProxyL(CCreatorEngine& /*aEngine*/)
       
   537     {
       
   538     iUseProxy = ETrue;
       
   539     }
       
   540 
       
   541 void CConnectionSettingsParameters::SetRandomProxyAddressL(CCreatorEngine& /*aEngine*/)
       
   542     {
       
   543     iProxyServerAddress->Des() = _L("127.0.0.1");
       
   544     }
       
   545 
       
   546 void CConnectionSettingsParameters::SetRandomProxyPortL(CCreatorEngine& /*aEngine*/)
       
   547     {
       
   548     iProxyPortNumber = 80;
       
   549     }
       
   550 
       
   551 void CConnectionSettingsParameters::SetRandomStartPageL(CCreatorEngine& aEngine)
       
   552     {
       
   553     LOGSTRING("Creator: CConnectionSettingsParameters::SetRandomStartPageL");
       
   554 
       
   555     TInt num = aEngine.RandomNumber(1, 3);
       
   556     TBuf<10> apType;
       
   557 
       
   558     if (num==1)
       
   559         {
       
   560         apType = _L("mms");
       
   561         }            
       
   562     else if (num==2)
       
   563         {
       
   564         apType = _L("wap");
       
   565         }
       
   566     else
       
   567         {
       
   568         apType = _L("internet");
       
   569         }
       
   570     TBuf<160> company = aEngine.RandomString(CCreatorEngine::ECompany);    
       
   571     iStartPage->Des() = _L("http://");
       
   572     iStartPage->Des().Append(apType);
       
   573     iStartPage->Des().Append(_L("."));
       
   574     iStartPage->Des().Append(company);
       
   575     iStartPage->Des().Append(_L(".com"));
       
   576     iStartPage->Des().LowerCase();
       
   577     }
       
   578 
       
   579 void CConnectionSettingsParameters::SetRandomIPAddressL(CCreatorEngine& /*aEngine*/)
       
   580     {
       
   581     iIPAddr->Des() = _L("10.10.10.10");
       
   582     }
       
   583 
       
   584 void CConnectionSettingsParameters::SetRandomIP4NameServer1L(CCreatorEngine& /*aEngine*/)
       
   585     {
       
   586     iIP4NameServer1->Des() = _L("10.1.1.1");
       
   587     }
       
   588 void CConnectionSettingsParameters::SetRandomIP4NameServer2L(CCreatorEngine& /*aEngine*/)
       
   589     {
       
   590     iIP4NameServer2->Des() = _L("10.2.2.2");
       
   591     }
       
   592 
       
   593 void CConnectionSettingsParameters::SetRandomProtocolTypeL(CCreatorEngine& aEngine)
       
   594     {
       
   595     LOGSTRING("Creator: CConnectionSettingsParameters::SetRandomProtocolTypeL");
       
   596 
       
   597     TInt protocolTypeRand = aEngine.RandomNumber(1, 2);
       
   598     if(protocolTypeRand == 1)
       
   599         {
       
   600         iProtocolType = RPacketContext::EPdpTypeIPv4;
       
   601         }
       
   602     else
       
   603         {
       
   604         iProtocolType = RPacketContext::EPdpTypeIPv6;
       
   605         }
       
   606     }
       
   607 
       
   608 void CConnectionSettingsParameters::SetRandomTelephoneNumberL(CCreatorEngine& aEngine)
       
   609     {
       
   610     iDefaultTelNumber->Des() = aEngine.RandomString(CCreatorEngine::EPhoneNumber);
       
   611     }
       
   612 
       
   613 void CConnectionSettingsParameters::SetRandomBearerTypeIsdnL(CCreatorEngine& /*aEngine*/)
       
   614     {
       
   615     iBearerCallTypeIsdn = ECmCallTypeISDNv110;
       
   616     }
       
   617 
       
   618 void CConnectionSettingsParameters::SetRandomBearerSpeedL(CCreatorEngine& /*aEngine*/)
       
   619     {
       
   620     iBearerSpeed = ECmSpeed14400;
       
   621     }
       
   622 
       
   623 void CConnectionSettingsParameters::SetRandomWapWspOptionL(CCreatorEngine& /*aEngine*/)
       
   624     {
       
   625     iWapWspOption = ECmWapWspOptionConnectionless;
       
   626     }
       
   627 
       
   628 void CConnectionSettingsParameters::SetRandomSubnetMaskL(CCreatorEngine& /*aEngine*/)
       
   629     {
       
   630     iSubnetMask->Des() = _L("255.255.255.0");
       
   631     }
       
   632 
       
   633 void CConnectionSettingsParameters::SetRandomGatewayAddressL(CCreatorEngine& /*aEngine*/)
       
   634     {
       
   635     iGatewayAddress->Des() = _L("10.0.0.1");
       
   636     }
       
   637 
       
   638 void CConnectionSettingsParameters::SetRandomWlanIpAddrL(CCreatorEngine& /*aEngine*/)
       
   639     {
       
   640     iWlanIpAddr->Des() = _L("10.0.0.99");
       
   641     }
       
   642 
       
   643 void CConnectionSettingsParameters::SetRandomIPv6NameServer1L(CCreatorEngine& /*aEngine*/)
       
   644     {
       
   645     iIP6NameServer1->Des() = _L("2007:abcd:1000:2000:3000:4000:5000:6001");
       
   646     }
       
   647 
       
   648 void CConnectionSettingsParameters::SetRandomIPv6NameServer2L(CCreatorEngine& /*aEngine*/)
       
   649     {
       
   650     iIP6NameServer2->Des() = _L("2007:abcd:1000:2000:3000:4000:5000:6002");
       
   651     }
       
   652 
       
   653 void CConnectionSettingsParameters::SetRandomDisableTextAuthL(CCreatorEngine& /*aEngine*/)
       
   654     {
       
   655     iDisableTextAuth = EFalse;
       
   656     }
       
   657 
       
   658 void CCreatorConnectionSettings::SetRandomBearerTypeL(CConnectionSettingsParameters& parameters)
       
   659 	{
       
   660     LOGSTRING("Creator: CCreatorConnectionSettings::SetRandomBearerTypeL");
       
   661 
       
   662 	RArray<TUint32> supportedBearers = RArray<TUint32>( 10 );
       
   663 	iCmManagerExt.SupportedBearersL(supportedBearers);
       
   664 	CleanupClosePushL( supportedBearers );
       
   665 	    
       
   666 	//In random mode, skipping KUidLanBearerType
       
   667 	//Because of Emulator migh show it as supported, when it's really not
       
   668 	//and that causes weird situation in UI when there is an item, but it can't be opened
       
   669 	TInt lanID = supportedBearers.Find(KUidLanBearerType);
       
   670 	if( lanID != KErrNotFound )
       
   671 		{
       
   672 		supportedBearers.Remove(lanID);
       
   673 		}
       
   674 	
       
   675 	// in emulator remove WLAN
       
   676 	#ifdef __WINSCW__	
       
   677 	TInt wlanID = supportedBearers.Find(KUidWlanBearerType);
       
   678 	if( wlanID != KErrNotFound )
       
   679 		{
       
   680 		supportedBearers.Remove(wlanID);
       
   681 		}
       
   682 	#endif	
       
   683 				
       
   684 	/*
       
   685 	    for(TInt i = 0; i<supportedCount; i++)
       
   686 	        {
       
   687 	        TUint bearer = supportedBearers[i];
       
   688 	        if(bearer == KUidLanBearerType)
       
   689 	            {
       
   690 	            supportedBearers.Remove(i);
       
   691 	            }
       
   692 	        }
       
   693 	    */
       
   694 	    
       
   695 	//Select random bearer type. 
       
   696 	//Also possible to use SupportedBearersL() -method to find supported methods
       
   697 	//but using that will cause problems when setting attributes.
       
   698 	TInt supportedCount = supportedBearers.Count();    
       
   699 	TInt bearerTypeID = iEngine->RandomNumber(0, supportedCount-1);
       
   700 	    
       
   701 	TUint bearerType = supportedBearers[bearerTypeID];
       
   702 	    
       
   703 	//Bearer types KUidEmbeddedDestination and KPluginVPNBearerTypeUid is not supported
       
   704 	if(bearerType == KUidWlanBearerType)//Wireless LAN
       
   705 		{            
       
   706 		parameters.iBearerType = KUidWlanBearerType;
       
   707 		}
       
   708 	else if(bearerType == KUidPacketDataBearerType)//Packet data (GPRS)
       
   709 		{
       
   710 		parameters.iBearerType = KUidPacketDataBearerType;
       
   711 		}
       
   712 	else if(bearerType == KUidCSDBearerType)//Data Call
       
   713 		{
       
   714 		parameters.iBearerType = KUidCSDBearerType;
       
   715 		}
       
   716 	else if(bearerType == KUidHSCSDBearerType) //High speed GSM
       
   717 		{
       
   718 		parameters.iBearerType = KUidHSCSDBearerType;
       
   719 		}
       
   720 	else if(bearerType == KUidEmbeddedDestination)
       
   721 		{
       
   722 		parameters.iBearerType = KUidEmbeddedDestination;
       
   723 		}
       
   724 	else// if(bearerType == KPluginVPNBearerTypeUid)
       
   725 		{
       
   726 		parameters.iBearerType = KPluginVPNBearerTypeUid;
       
   727 		}
       
   728 	/* In random mode skipping LAN type
       
   729 	    else// if(bearerType == KUidLanBearerType)
       
   730 	        {
       
   731 	        iBearerType = KUidLanBearerType;
       
   732 	        }*/
       
   733 	    
       
   734 	CleanupStack::PopAndDestroy(); // supportedBearers
       
   735 	}
       
   736 
       
   737 void CCreatorConnectionSettings::SetRandomParametersL(CConnectionSettingsParameters& parameters)
       
   738     {
       
   739     LOGSTRING("Creator: CCreatorConnectionSettings::SetRandomParametersL");
       
   740         
       
   741     // Connection method name:
       
   742     parameters.SetRandomCMNameL(*iEngine);
       
   743     
       
   744     SetRandomBearerTypeL(parameters);
       
   745  
       
   746     if(parameters.iBearerType == KUidWlanBearerType)//Wireless LAN
       
   747         {           
       
   748         // WLAN name:
       
   749         parameters.SetRandomWLANNameL(*iEngine);
       
   750         
       
   751         //WLAN network mode        
       
   752         parameters.SetRandomWLANNetModeL(*iEngine);     
       
   753         
       
   754         //WLAN security mode:
       
   755         parameters.SetRandomWLANSecurityModeL(*iEngine);
       
   756         }
       
   757     
       
   758     // Login name:
       
   759     parameters.SetRandomLoginNameL(*iEngine);
       
   760 
       
   761     // Login password:
       
   762     parameters.SetRandomLoginPassL(*iEngine);
       
   763 
       
   764     // Secure authentication:
       
   765     parameters.SetRandomSecureAuthenticationL(*iEngine);
       
   766     
       
   767     // Prompt password:
       
   768     parameters.SetRandomPromptPasswordL(*iEngine);    
       
   769 
       
   770     // Use proxy:
       
   771     parameters.SetRandomUseProxyL(*iEngine);    
       
   772     
       
   773     // Proxy address
       
   774     parameters.SetRandomProxyAddressL(*iEngine);    
       
   775     
       
   776     // Proxy port number:
       
   777     parameters.SetRandomProxyPortL(*iEngine);    
       
   778 
       
   779     // Start page:
       
   780     parameters.SetRandomStartPageL(*iEngine);
       
   781        
       
   782     // IP address:
       
   783     parameters.SetRandomIPAddressL(*iEngine);    
       
   784     
       
   785     // IPv4 name servers:
       
   786     parameters.SetRandomIP4NameServer1L(*iEngine);
       
   787     parameters.SetRandomIP4NameServer2L(*iEngine);
       
   788       
       
   789     // Protocol type:
       
   790     parameters.SetRandomProtocolTypeL(*iEngine);
       
   791     
       
   792     // Default telephone number:
       
   793     parameters.SetRandomTelephoneNumberL(*iEngine);
       
   794          
       
   795     // Bearer isdn
       
   796     parameters.SetRandomBearerTypeIsdnL(*iEngine);
       
   797 
       
   798     // Bearer speed:
       
   799     parameters.SetRandomBearerSpeedL(*iEngine);    
       
   800 
       
   801     // WAP wsp option:
       
   802     parameters.SetRandomWapWspOptionL(*iEngine);
       
   803 
       
   804     // Subnet mask:
       
   805     parameters.SetRandomSubnetMaskL(*iEngine);
       
   806     
       
   807     // Gateway address:
       
   808     parameters.SetRandomGatewayAddressL(*iEngine);
       
   809     
       
   810     // WLAN ip address:
       
   811     parameters.SetRandomWlanIpAddrL(*iEngine);
       
   812 
       
   813     // IPv6 name servers:
       
   814     parameters.SetRandomIPv6NameServer1L(*iEngine);
       
   815     parameters.SetRandomIPv6NameServer2L(*iEngine);
       
   816     
       
   817     // Disable text authorization:
       
   818     parameters.SetRandomDisableTextAuthL(*iEngine);    
       
   819     }
       
   820 
       
   821 //----------------------------------------------------------------------------
       
   822 
       
   823 void CCreatorConnectionSettings::SetDefaultCML(RCmConnectionMethodExt conMethod)
       
   824     {
       
   825     LOGSTRING("Creator: CCreatorConnectionSettings::SetDefaultCM");
       
   826 
       
   827     TCmDefConnValue defConnValue;
       
   828         
       
   829     //Returns the default connection method/SNAP.
       
   830     TRAPD( err, iCmManagerExt.ReadDefConnL( defConnValue ) );
       
   831     if( err ==  KErrNotSupported )
       
   832         {
       
   833         return; //If Default Connection NOT supported, just returning 
       
   834         }
       
   835     else if ( err != KErrNone )
       
   836         {
       
   837         User::Leave( err ); //If something else happend
       
   838         }
       
   839     else if ( defConnValue.iId == 0 ) // default not set
       
   840         {       
       
   841         TCmDefConnValue newDefaultCM;        
       
   842         HBufC* cmName = conMethod.GetStringAttributeL( ECmName );        
       
   843         CleanupStack::PushL( cmName );
       
   844         newDefaultCM.iId = AccessPointNameToIdL( cmName->Des() );
       
   845         newDefaultCM.iType = ECmDefConnDestination;
       
   846         //Stores the default connection method/SNAP.
       
   847         iCmManagerExt.WriteDefConnL( newDefaultCM );
       
   848         CleanupStack::PopAndDestroy( cmName );        
       
   849        }
       
   850     }
       
   851 
       
   852 //----------------------------------------------------------------------------
       
   853 
       
   854 TUint32 CCreatorConnectionSettings::AccessPointNameToIdL(const TDesC& aAPName,
       
   855                                                          TBool aAnyIfNotFound )
       
   856     {
       
   857     LOGSTRING("Creator: CCreatorConnectionSettings::AccessPointNameToIdL");
       
   858 
       
   859     //RCmDestination destination
       
   860     
       
   861     RArray<TUint32> destIdArray = RArray<TUint32>( 10 );
       
   862     
       
   863     iCmManagerExt.AllDestinationsL( destIdArray );
       
   864     
       
   865     CleanupClosePushL( destIdArray );
       
   866     TUint32 id = 0 ;
       
   867     TBool found = EFalse;
       
   868     
       
   869     for( TInt i = 0; i < destIdArray.Count(); i++ )
       
   870         {
       
   871         RCmDestinationExt dest = iCmManagerExt.DestinationL( destIdArray[i] );           
       
   872         CleanupClosePushL( dest );        
       
   873 
       
   874         HBufC* destName = dest.NameLC();
       
   875         
       
   876         if (destName->CompareF(aAPName) == 0){        
       
   877          id = dest.Id();
       
   878          found = ETrue;
       
   879         }
       
   880         if ( !found && id == 0 && aAnyIfNotFound )
       
   881             {
       
   882             id = dest.Id();
       
   883             }
       
   884         CleanupStack::PopAndDestroy( 2 ); // destName , dest
       
   885         if(found)
       
   886             {
       
   887             break;
       
   888             }
       
   889         }
       
   890 
       
   891     CleanupStack::PopAndDestroy(); // destIdArray   
       
   892     return id;
       
   893     }
       
   894 
       
   895 //----------------------------------------------------------------------------
       
   896 
       
   897 void CCreatorConnectionSettings::HandleSessionEventL(TMsvSessionEvent /*aEvent*/, TAny* /*aArg1*/, TAny* /*aArg2*/, TAny* /*aArg3*/) // from MMsvSessionObserver
       
   898     {
       
   899     LOGSTRING("Creator: CCreatorConnectionSettings::HandleSessionEventL");
       
   900     }
       
   901 
       
   902 //----------------------------------------------------------------------------
       
   903 void CCreatorConnectionSettings::DeleteAllL()
       
   904     {
       
   905     LOGSTRING("Creator: CCreatorConnectionSettings::DeleteAllL");
       
   906     DeleteAllDestinationsL( EFalse );
       
   907     }
       
   908 
       
   909 //----------------------------------------------------------------------------
       
   910 void CCreatorConnectionSettings::DeleteAllCreatedByCreatorL()
       
   911     {
       
   912     LOGSTRING("Creator: CCreatorConnectionSettings::DeleteAllCreatedByCreatorL");
       
   913     iEntryIds.Reset();
       
   914     
       
   915     // fetch ids of entries created by Creator
       
   916     iEngine->ReadEntryIdsFromStoreL( iEntryIds, KUidDictionaryUidIAP );
       
   917     
       
   918     // delete entries
       
   919     DeleteAllDestinationsL( ETrue );
       
   920     }
       
   921 
       
   922 //----------------------------------------------------------------------------
       
   923 
       
   924 void CCreatorConnectionSettings::DeleteAllDestinationsL( TBool aOnlyCreatedWithCreator )
       
   925     {
       
   926     LOGSTRING("Creator: CCreatorConnectionSettings::DeleteAllDestinationsL");
       
   927     RArray<TUint32> destIdArray(5);
       
   928     CleanupClosePushL( destIdArray );
       
   929     iCmManagerExt.AllDestinationsL( destIdArray );    
       
   930     
       
   931     for( TInt i = 0; i < destIdArray.Count(); i++ )
       
   932         {
       
   933         TRAP_IGNORE
       
   934             (
       
   935             RCmDestinationExt dest = iCmManagerExt.DestinationL( destIdArray[i] );           
       
   936             CleanupClosePushL( dest );
       
   937             
       
   938             if ( !aOnlyCreatedWithCreator || iEntryIds.Find( destIdArray[i]) != KErrNotFound )
       
   939                 {
       
   940                 dest.DeleteLD();
       
   941                 }
       
   942             CleanupStack::PopAndDestroy(); // dest
       
   943             );
       
   944         }
       
   945    
       
   946     CleanupStack::PopAndDestroy(); // destIdArray 
       
   947     
       
   948     // reset must be done here, because iEntryIds is stored in destructor
       
   949     iEntryIds.Reset();
       
   950     
       
   951     // all entries deleted, remove the IMPS related registry
       
   952     iEngine->RemoveStoreL( KUidDictionaryUidIAP );
       
   953     }
       
   954 //----------------------------------------------------------------------------