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