wlansecuritysettings/wpasecuritysettingsui/src/WPASecuritySettingsImpl.cpp
branchRCL_3
changeset 43 30e048a7b597
parent 2 1c7bc153c08e
equal deleted inserted replaced
37:75a6055b8ce3 43:30e048a7b597
    14 * Description: Implementation of class CWPASecuritySettingsImpl.     
    14 * Description: Implementation of class CWPASecuritySettingsImpl.     
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 /*
    18 /*
    19 * %version: tr1cfwln#27 %
    19 * %version: tr1cfwln#29 %
    20 */
    20 */
    21 
    21 
    22 // INCLUDE FILES
    22 // INCLUDE FILES
    23 
    23 
    24 #include "WPASecuritySettingsUiPanic.h"
    24 #include "WPASecuritySettingsUiPanic.h"
    67 //
    67 //
    68 CWPASecuritySettingsImpl::CWPASecuritySettingsImpl( 
    68 CWPASecuritySettingsImpl::CWPASecuritySettingsImpl( 
    69                                                 TSecurityMode aSecurityMode )
    69                                                 TSecurityMode aSecurityMode )
    70 : iSecurityMode( aSecurityMode ),
    70 : iSecurityMode( aSecurityMode ),
    71   iWPAMode( EFalse ),
    71   iWPAMode( EFalse ),
    72   iWpa2Only( EFalse )
    72   iWpa2Only( EFalse ),
       
    73   iWPAUnencryptedConn( EFalse )
    73     {
    74     {
    74     iWPAEAPPlugin.Zero();
    75     iWPAEAPPlugin.Zero();
    75     iWPAPreSharedKey.Zero();
    76     iWPAPreSharedKey.Zero();
    76     }
    77     }
    77 
    78 
   121                     TPtrC( WLAN_SERVICE ), TPtrC( WLAN_SERVICE_ID ), aIapId );
   122                     TPtrC( WLAN_SERVICE ), TPtrC( WLAN_SERVICE_ID ), aIapId );
   122 
   123 
   123     TInt errorCode = wLanServiceTable->GotoFirstRecord();
   124     TInt errorCode = wLanServiceTable->GotoFirstRecord();
   124     if ( errorCode == KErrNone )
   125     if ( errorCode == KErrNone )
   125         {
   126         {
   126         // Get WPA Mode
   127         if ( iSecurityMode == ESecurityMode8021x )
   127         TRAPD( err, wLanServiceTable->ReadUintL( TPtrC( WLAN_ENABLE_WPA_PSK ),
   128             {
   128                                                 ( TUint32& ) iWPAMode ) );
   129             // in 802.1x PSK mode is not supported
   129         if ( err != KErrNone )
   130             iWPAMode = EFalse;
   130             { // do not leave if value is not present in table...
   131             }
   131             if ( err != KErrUnknown )
   132         else
   132                 User::Leave( err );
   133             {
   133             }
   134             // Get WPA Mode
   134 
   135             TRAPD( err, wLanServiceTable->ReadUintL( TPtrC( WLAN_ENABLE_WPA_PSK ),
       
   136                                                     ( TUint32& ) iWPAMode ) );
       
   137             if ( err != KErrNone )
       
   138                 { // do not leave if value is not present in table...
       
   139                 if ( err != KErrUnknown )
       
   140                     User::Leave( err );
       
   141                 }
       
   142             }
       
   143         
   135         TUint32 secMode = 0;
   144         TUint32 secMode = 0;
   136         // Get WPA2 Only Mode
   145         // Get WPA2 Only Mode
   137         TRAP( err, wLanServiceTable->ReadUintL( TPtrC( WLAN_SECURITY_MODE ),
   146         TRAPD( err, wLanServiceTable->ReadUintL( TPtrC( WLAN_SECURITY_MODE ),
   138                                                  secMode ) );
   147                                                  secMode ) );
   139         if ( err != KErrNone )
   148         if ( err != KErrNone )
   140             { // do not leave if value is not present in table...
   149             { // do not leave if value is not present in table...
   141             if ( err != KErrUnknown )
   150             if ( err != KErrUnknown )
   142                 User::Leave( err );
   151                 User::Leave( err );
   143             }
   152             }
   144 
   153 
   145         iWpa2Only = secMode == EWpa2;
   154         iWpa2Only = secMode == EWpa2;
       
   155 
       
   156         // Get Unencrypted Connection mode for 802.1x
       
   157         if ( iSecurityMode == ESecurityMode8021x )
       
   158             {
       
   159             // WLAN_WPA_KEY_LENGTH is used also for Unencrypted Connection mode
       
   160             TRAPD( err2, wLanServiceTable->ReadUintL( TPtrC( WLAN_WPA_KEY_LENGTH ),
       
   161                                                 ( TUint32& ) iWPAUnencryptedConn ) );
       
   162             if ( err2 != KErrNone )
       
   163                 { // do not leave if value is not present in table...
       
   164                 if ( err2 != KErrUnknown )
       
   165                     User::Leave( err2 );
       
   166                 }
       
   167             }
   146 
   168 
   147         // Get EAP list
   169         // Get EAP list
   148     	iWPAEAPPlugin.Copy( *wLanServiceTable->ReadLongTextLC( 
   170     	iWPAEAPPlugin.Copy( *wLanServiceTable->ReadLongTextLC( 
   149                                                         TPtrC( WLAN_EAPS ) ) );
   171                                                         TPtrC( WLAN_EAPS ) ) );
   150 	    CleanupStack::PopAndDestroy();
   172 	    CleanupStack::PopAndDestroy();
   246             // finally, wipe old column data
   268             // finally, wipe old column data
   247             iWPAEAPPlugin.Zero();
   269             iWPAEAPPlugin.Zero();
   248 	        }
   270 	        }
   249 	        
   271 	        
   250         // Get PreShared Key
   272         // Get PreShared Key
   251         wLanServiceTable->ReadTextL( TPtrC( WLAN_WPA_PRE_SHARED_KEY ), 
   273 	    if ( iSecurityMode != ESecurityMode8021x )
       
   274 	        {
       
   275             wLanServiceTable->ReadTextL( TPtrC( WLAN_WPA_PRE_SHARED_KEY ), 
   252                                     iWPAPreSharedKey );
   276                                     iWPAPreSharedKey );
       
   277 	        }
   253 
   278 
   254         if ( !IsValidPsk( iWPAPreSharedKey ) )
   279         if ( !IsValidPsk( iWPAPreSharedKey ) )
   255             {       
   280             {       
   256             // invalid key format
   281             // invalid key format
   257             iWPAPreSharedKey.Zero();
   282             iWPAPreSharedKey.Zero();
   291         // Save link to LAN service
   316         // Save link to LAN service
   292         wLanServiceTable->WriteUintL( TPtrC( WLAN_SERVICE_ID ), aIapId );
   317         wLanServiceTable->WriteUintL( TPtrC( WLAN_SERVICE_ID ), aIapId );
   293         }
   318         }
   294 
   319 
   295     // Save WPA Mode
   320     // Save WPA Mode
   296     wLanServiceTable->WriteUintL( TPtrC( WLAN_ENABLE_WPA_PSK ), 
   321     if ( iSecurityMode != ESecurityMode8021x )
       
   322         {
       
   323         wLanServiceTable->WriteUintL( TPtrC( WLAN_ENABLE_WPA_PSK ), 
   297                                   ( TUint32& ) iWPAMode );
   324                                   ( TUint32& ) iWPAMode );
       
   325         }
   298 
   326 
   299     TUint32 secMode;
   327     TUint32 secMode;
   300 
   328 
   301     if ( iSecurityMode == ESecurityMode8021x )
   329     if ( iSecurityMode == ESecurityMode8021x )
   302         {
   330         {
   329 
   357 
   330     wLanServiceTable->WriteTextL( TPtrC( WLAN_DISABLED_EAPS ), 
   358     wLanServiceTable->WriteTextL( TPtrC( WLAN_DISABLED_EAPS ), 
   331                                   iWPADisabledEAPPlugin? 
   359                                   iWPADisabledEAPPlugin? 
   332                                         (const TDesC8&)*iWPADisabledEAPPlugin: 
   360                                         (const TDesC8&)*iWPADisabledEAPPlugin: 
   333                                         (const TDesC8&)KNullDesC8 );
   361                                         (const TDesC8&)KNullDesC8 );
   334     // Save PreShared Key
   362  
   335     wLanServiceTable->WriteTextL( TPtrC( WLAN_WPA_PRE_SHARED_KEY ), 
   363 
       
   364 
       
   365     if ( iSecurityMode == ESecurityMode8021x )
       
   366         {
       
   367         // In 802.1x WpaKeyLength is not used 
       
   368         // and the field is reused to save UnencryptedConn mode
       
   369         wLanServiceTable->WriteUintL( TPtrC( WLAN_WPA_KEY_LENGTH ), 
       
   370                                       ( TUint32& ) iWPAUnencryptedConn );
       
   371         }
       
   372     else
       
   373         {
       
   374         // Save PreShared Key
       
   375         wLanServiceTable->WriteTextL( TPtrC( WLAN_WPA_PRE_SHARED_KEY ), 
   336                                   iWPAPreSharedKey );
   376                                   iWPAPreSharedKey );
   337 
   377     
   338     // Save PreShared Key Length
   378         // Save PreShared Key Length
   339     wLanServiceTable->WriteUintL( TPtrC( WLAN_WPA_KEY_LENGTH ), 
   379         wLanServiceTable->WriteUintL( TPtrC( WLAN_WPA_KEY_LENGTH ), 
   340                                   iWPAPreSharedKey.Length() );
   380                                         iWPAPreSharedKey.Length() );
       
   381         }
   341 
   382 
   342     wLanServiceTable->PutRecordChanges();
   383     wLanServiceTable->PutRecordChanges();
   343 
   384 
   344     if ( iPlugin )
   385     if ( iPlugin )
   345         {
   386         {
   540     // prime with service id                
   581     // prime with service id                
   541     *sidField = aIapId;
   582     *sidField = aIapId;
   542 
   583 
   543     if( generic->FindL( aSession) )
   584     if( generic->FindL( aSession) )
   544         {
   585         {
   545         // Get WPA mode
   586         if ( iSecurityMode == ESecurityMode8021x )
   546         CMDBField<TUint>* enableWpaPskField = static_cast<CMDBField<TUint>*>
   587             {
       
   588             // in 802.1x PSK mode is not supported
       
   589             iWPAMode = EFalse;
       
   590             }
       
   591         else
       
   592             {
       
   593             // Get WPA mode
       
   594             CMDBField<TUint>* enableWpaPskField = static_cast<CMDBField<TUint>*>
   547                           ( generic->GetFieldByIdL( KCDTIdWlanEnableWpaPsk ) );
   595                           ( generic->GetFieldByIdL( KCDTIdWlanEnableWpaPsk ) );
   548         iWPAMode = *enableWpaPskField;
   596             iWPAMode = *enableWpaPskField;
       
   597             }
   549         
   598         
   550         // Get WPA2 Only Mode
   599         // Get WPA2 Only Mode
   551         CMDBField<TUint>* secModeField = static_cast<CMDBField<TUint>*>
   600         CMDBField<TUint>* secModeField = static_cast<CMDBField<TUint>*>
   552                                ( generic->GetFieldByIdL( KCDTIdWlanSecMode ) );
   601                                ( generic->GetFieldByIdL( KCDTIdWlanSecMode ) );
   553         TUint32 secMode = *secModeField;
   602         TUint32 secMode = *secModeField;
   554         iWpa2Only = secMode == EWpa2;
   603         iWpa2Only = secMode == EWpa2;
       
   604  
       
   605         // Get 802.1x Unencrypted Connection saved in reused WpaKeyLengthField
       
   606         if ( iSecurityMode == ESecurityMode8021x )
       
   607             {
       
   608             CMDBField<TUint>* WpaKeyLengthField = static_cast<CMDBField<TUint>*>
       
   609                           ( generic->GetFieldByIdL( KCDTIdWlanWpaKeyLength ) );
       
   610             iWPAUnencryptedConn = *WpaKeyLengthField;
       
   611             }
   555         
   612         
   556         // Get EAP plugins
   613         // Get EAP plugins
   557         CMDBField<TDesC>* wlanEapsField = static_cast<CMDBField<TDesC>*>
   614         CMDBField<TDesC>* wlanEapsField = static_cast<CMDBField<TDesC>*>
   558                                   ( generic->GetFieldByIdL( KCDTIdWlanEaps ) );
   615                                   ( generic->GetFieldByIdL( KCDTIdWlanEaps ) );
   559         iWPAEAPPlugin = *wlanEapsField;
   616         iWPAEAPPlugin = *wlanEapsField;
   650             // finally, wipe old column data
   707             // finally, wipe old column data
   651             iWPAEAPPlugin.Zero();
   708             iWPAEAPPlugin.Zero();
   652 	        }
   709 	        }
   653 
   710 
   654         // GetWPA preshared key
   711         // GetWPA preshared key
   655         CMDBField<TDesC8>* wpaPskField = static_cast<CMDBField<TDesC8>*>
   712 	    if ( iSecurityMode != ESecurityMode8021x )
       
   713 	        {
       
   714             CMDBField<TDesC8>* wpaPskField = static_cast<CMDBField<TDesC8>*>
   656                        ( generic->GetFieldByIdL( KCDTIdWlanWpaPreSharedKey ) );
   715                        ( generic->GetFieldByIdL( KCDTIdWlanWpaPreSharedKey ) );
   657         iWPAPreSharedKey = *wpaPskField;
   716             iWPAPreSharedKey = *wpaPskField;
   658         
   717 	        }
       
   718 	    
   659         if ( !IsValidPsk( iWPAPreSharedKey ) )
   719         if ( !IsValidPsk( iWPAPreSharedKey ) )
   660             {       
   720             {       
   661             // invalid key format
   721             // invalid key format
   662             iWPAPreSharedKey.Zero();
   722             iWPAPreSharedKey.Zero();
   663             }
   723             }
   696     
   756     
   697     TBool found = generic->FindL( aSession);
   757     TBool found = generic->FindL( aSession);
   698    
   758    
   699     // If loading failed, WLAN service record will be 
   759     // If loading failed, WLAN service record will be 
   700     // created and StoreL()-d, otherwise, ModifyL()
   760     // created and StoreL()-d, otherwise, ModifyL()
   701     
   761 
   702     // Set WPA mode
   762     if ( iSecurityMode != ESecurityMode8021x )
   703     CMDBField<TUint>* enableWpaPskField = static_cast<CMDBField<TUint>*>
   763         {
   704                           ( generic->GetFieldByIdL( KCDTIdWlanEnableWpaPsk ) );
   764         // Set WPA mode
   705     enableWpaPskField->SetL( iWPAMode );
   765         CMDBField<TUint>* enableWpaPskField = static_cast<CMDBField<TUint>*>
       
   766                 ( generic->GetFieldByIdL( KCDTIdWlanEnableWpaPsk ) );
       
   767         enableWpaPskField->SetL( iWPAMode );
       
   768         }
   706     
   769     
   707     // Set security mode
   770     // Set security mode
   708     TUint32 secMode;
   771     TUint32 secMode;
   709     if ( iSecurityMode == ESecurityMode8021x )
   772     if ( iSecurityMode == ESecurityMode8021x )
   710         {
   773         {
   743                           ( generic->GetFieldByIdL( KCDTIdWlanDisabledEaps ) );
   806                           ( generic->GetFieldByIdL( KCDTIdWlanDisabledEaps ) );
   744     wlanDisabledEapsField->SetL( iWPADisabledEAPPlugin? 
   807     wlanDisabledEapsField->SetL( iWPADisabledEAPPlugin? 
   745                                     (const TDesC8&)*iWPADisabledEAPPlugin: 
   808                                     (const TDesC8&)*iWPADisabledEAPPlugin: 
   746                                     (const TDesC8&)KNullDesC8 );
   809                                     (const TDesC8&)KNullDesC8 );
   747 
   810 
   748     // Save PreShared Key
       
   749     CMDBField<TDesC8>* wpaPskField = static_cast<CMDBField<TDesC8>*>
       
   750                        ( generic->GetFieldByIdL( KCDTIdWlanWpaPreSharedKey ) );
       
   751     wpaPskField->SetL( iWPAPreSharedKey );
       
   752 
       
   753     // Save PreShared Key length
   811     // Save PreShared Key length
   754     CMDBField<TUint>* keyLengthField = static_cast<CMDBField<TUint>*>
   812     CMDBField<TUint>* keyLengthField = static_cast<CMDBField<TUint>*>
   755                         ( generic->GetFieldByIdL( KCDTIdWlanWpaKeyLength ) );
   813                         ( generic->GetFieldByIdL( KCDTIdWlanWpaKeyLength ) );
   756     keyLengthField->SetL( iWPAPreSharedKey.Length() );
   814     if ( iSecurityMode == ESecurityMode8021x )
       
   815         {
       
   816         // In 802.1x keyLengthField is reused to contain Unencrypted Connection info
       
   817         keyLengthField->SetL( iWPAUnencryptedConn );
       
   818         }
       
   819     else
       
   820         {
       
   821         keyLengthField->SetL( iWPAPreSharedKey.Length() );
       
   822         
       
   823         // Save PreShared Key
       
   824         CMDBField<TDesC8>* wpaPskField = static_cast<CMDBField<TDesC8>*>
       
   825                            ( generic->GetFieldByIdL( KCDTIdWlanWpaPreSharedKey ) );
       
   826         wpaPskField->SetL( iWPAPreSharedKey );
       
   827         }
   757     
   828     
   758     TInt error( KErrNone );
   829     TInt error( KErrNone );
   759     
   830     
   760     // Saving changes
   831     // Saving changes
   761     for ( TInt i( 0 ); i < KRetryCount; i++ )
   832     for ( TInt i( 0 ); i < KRetryCount; i++ )