hotspotfw/hsclient/src/hssiaphandler.cpp
changeset 58 301aeb18ae47
parent 46 2fbd1d709fe7
child 61 e1d68407ed06
equal deleted inserted replaced
56:de27cc8389dd 58:301aeb18ae47
    23 #include "hotspotclientserver.h"
    23 #include "hotspotclientserver.h"
    24 #include "am_debug.h"
    24 #include "am_debug.h"
    25 #include <es_enum.h>
    25 #include <es_enum.h>
    26 
    26 
    27 #include <cmconnectionmethod.h>
    27 #include <cmconnectionmethod.h>
       
    28 #include <cmpluginwlandef.h>
    28 #include <cmconnectionmethoddef.h>
    29 #include <cmconnectionmethoddef.h>
    29 #include <cmmanager.h>
    30 #include <cmmanager.h>
    30 #include <cmmanagerdef.h>
    31 #include <cmmanagerdef.h>
    31 #include <cmdestination.h>
    32 #include <cmdestination.h>
    32 
    33 
   107     serviceId = plugin.GetIntAttributeL( EWlanServiceId );
   108     serviceId = plugin.GetIntAttributeL( EWlanServiceId );
   108     DEBUG1("CHssIapHandler::ChangeSettingsL WLAN serviceId: %d", serviceId);
   109     DEBUG1("CHssIapHandler::ChangeSettingsL WLAN serviceId: %d", serviceId);
   109     
   110     
   110     if  ( aSettings.Name.Length() > 0 )
   111     if  ( aSettings.Name.Length() > 0 )
   111         {
   112         {
   112         plugin.SetStringAttributeL( ECmName, aSettings.Name );
   113         plugin.SetStringAttributeL( CMManager::ECmName, aSettings.Name );
   113         plugin.UpdateL();
   114         }
   114         }
   115     
       
   116     if  ( aSettings.iSSID.Length() > 0 )
       
   117         {
       
   118         plugin.SetStringAttributeL( CMManager::EWlanSSID, aSettings.iSSID );
       
   119         }
       
   120     
       
   121     plugin.SetIntAttributeL( CMManager::EWlanConnectionMode, 
       
   122                               aSettings.iConnectionMode );
       
   123     plugin.SetIntAttributeL( CMManager::EWlanChannelID, 0 );
       
   124     plugin.SetIntAttributeL( CMManager::EWlanSecurityMode, 
       
   125                               aSettings.iSecurityMode );
       
   126     
       
   127     plugin.UpdateL();
   115     CleanupStack::PopAndDestroy( &plugin ); 
   128     CleanupStack::PopAndDestroy( &plugin ); 
   116     CleanupStack::PopAndDestroy( &cmManager ); 
   129     CleanupStack::PopAndDestroy( &cmManager ); 
   117 
   130 
   118     // CommsDat section starts
   131     // CommsDat section starts
   119     CMDBSession* dbSession = CMDBSession::NewL(CMDBSession::LatestVersion());
   132     CMDBSession* dbSession = CMDBSession::NewL( CMDBSession::LatestVersion() );
   120     CleanupStack::PushL( dbSession );
   133     CleanupStack::PushL( dbSession );
   121     iWLANRecord = static_cast<CMDBGenericRecord*>
   134     iWLANRecord = static_cast<CMDBGenericRecord*>
   122         ( CCDRecordBase::RecordFactoryL( 0 ) );
   135         ( CCDRecordBase::RecordFactoryL( 0 ) );
   123             
   136             
   124     iWLANRecord->InitializeL( KGenericTable(),NULL );
   137     iWLANRecord->InitializeL( KGenericTable(),NULL );
   125     iWLANRecord->SetRecordId( serviceId );
   138     iWLANRecord->SetRecordId( serviceId );
   126     iWLANRecord->LoadL( *dbSession );
   139     iWLANRecord->LoadL( *dbSession );
   127 
   140     
   128     // Set Network Name
   141     if( aSettings.iSecurityMode == EHssWep )
   129     if ( aSettings.iSSID.Length() > 0 )
       
   130         {
       
   131         CMDBField<TDesC>* textField = 
       
   132             (CMDBField<TDesC>*)iWLANRecord->GetFieldByIdL( KCDTIdWlanSSID );            
       
   133         textField->SetMaxLengthL( aSettings.iSSID.Length() );
       
   134         textField->SetL( aSettings.iSSID );
       
   135         }
       
   136     
       
   137     // Set Connection Mode 
       
   138     *((CMDBField<TUint32>*)iWLANRecord->GetFieldByIdL( KCDTIdWlanConnMode)) = 
       
   139                                                    aSettings.iConnectionMode;
       
   140     
       
   141     // Set Channel Id.
       
   142     *((CMDBField<TUint32>*)iWLANRecord->GetFieldByIdL( KCDTIdWlanChannelID )) = 0;
       
   143     
       
   144     //  Set Security Mode
       
   145     *((CMDBField<TUint32>*)iWLANRecord->GetFieldByIdL( KCDTIdWlanSecMode )) = 
       
   146                                                     aSettings.iSecurityMode;
       
   147     
       
   148     // Check if THssIapSettings is created wrong (dynamically). 
       
   149     // -> Then default value is not set to security mode and it will be huge.
       
   150     // -> Destination can become unusable.
       
   151     TInt secMode = aSettings.iSecurityMode;
       
   152     if ( secMode > EHssWpa2Only )
       
   153         {
       
   154         secMode = EHssAllowUnsecure;
       
   155         }
       
   156     
       
   157     if( secMode == EHssWep )
       
   158         {
   142         {
   159         DEBUG("CHssIapHandler::ChangeSettingsL -> SecurityMode == EHssWep");
   143         DEBUG("CHssIapHandler::ChangeSettingsL -> SecurityMode == EHssWep");
   160         *((CMDBField<TUint32>*)iWLANRecord->GetFieldByIdL(KCDTIdWlanAuthMode)) = aSettings.iAuthenticationMode;
   144         *((CMDBField<TUint32>*)iWLANRecord->GetFieldByIdL(KCDTIdWlanAuthMode)) = aSettings.iAuthenticationMode;
   161         *((CMDBField<TUint32>*)iWLANRecord->GetFieldByIdL( KCDTIdWlanWepIndex )) = aSettings.iWepIndex;
   145         *((CMDBField<TUint32>*)iWLANRecord->GetFieldByIdL( KCDTIdWlanWepIndex )) = aSettings.iWepIndex;
   162                 
   146                 
   165         *((CMDBField<TUint32>*)iWLANRecord->GetFieldByIdL( KCDTIdWlanFormatKey1 )) = aSettings.iWepKeyFormat[0];
   149         *((CMDBField<TUint32>*)iWLANRecord->GetFieldByIdL( KCDTIdWlanFormatKey1 )) = aSettings.iWepKeyFormat[0];
   166         *((CMDBField<TUint32>*)iWLANRecord->GetFieldByIdL( KCDTIdWlanFormatKey2 )) = aSettings.iWepKeyFormat[1];
   150         *((CMDBField<TUint32>*)iWLANRecord->GetFieldByIdL( KCDTIdWlanFormatKey2 )) = aSettings.iWepKeyFormat[1];
   167         *((CMDBField<TUint32>*)iWLANRecord->GetFieldByIdL( KCDTIdWlanFormatKey3 )) = aSettings.iWepKeyFormat[2];
   151         *((CMDBField<TUint32>*)iWLANRecord->GetFieldByIdL( KCDTIdWlanFormatKey3 )) = aSettings.iWepKeyFormat[2];
   168         *((CMDBField<TUint32>*)iWLANRecord->GetFieldByIdL( KCDTIdWlanFormatKey4 )) = aSettings.iWepKeyFormat[3];
   152         *((CMDBField<TUint32>*)iWLANRecord->GetFieldByIdL( KCDTIdWlanFormatKey4 )) = aSettings.iWepKeyFormat[3];
   169         }
   153         }
   170     else if( secMode > EHssWep )
   154     else if( aSettings.iSecurityMode > EHssWep )
   171         {
   155         {
   172         DEBUG("CHssIapHandler::ChangeSettingsL -> SecurityMode > EHssWep");
   156         DEBUG("CHssIapHandler::ChangeSettingsL -> SecurityMode > EHssWep");
   173         if ( aSettings.iEnableWpaPsk ) // Use PreSharedKey
   157         if ( aSettings.iEnableWpaPsk ) // Use PreSharedKey
   174             {
   158             {
   175             TBuf8<KHssWlanWpaPskLength> buf;
   159             TBuf8<KHssWlanWpaPskLength> buf;
   186             binField->SetL( buf);
   170             binField->SetL( buf);
   187        
   171        
   188             *((CMDBField<TUint32>*)iWLANRecord->GetFieldByIdL(KCDTIdWlanWpaKeyLength)) = aSettings.iWPAKeyLength;
   172             *((CMDBField<TUint32>*)iWLANRecord->GetFieldByIdL(KCDTIdWlanWpaKeyLength)) = aSettings.iWPAKeyLength;
   189             *((CMDBField<TUint32>*)iWLANRecord->GetFieldByIdL(KCDTIdWlanEnableWpaPsk)) = aSettings.iEnableWpaPsk;
   173             *((CMDBField<TUint32>*)iWLANRecord->GetFieldByIdL(KCDTIdWlanEnableWpaPsk)) = aSettings.iEnableWpaPsk;
   190             }
   174             }
   191         else // Use EAP. EAP settings can be set with EAP API.
   175         else // Use EAP. EAP settings can be set using EAP API.
   192             {
   176             {
   193             DEBUG("CHssIapHandler::ChangeSettingsL -> SecurityMode > EHssWep -> EAP");
   177             DEBUG("CHssIapHandler::ChangeSettingsL -> SecurityMode > EHssWep -> EAP");
   194             *((CMDBField<TUint32>*)iWLANRecord->GetFieldByIdL(KCDTIdWlanEnableWpaPsk)) = aSettings.iEnableWpaPsk;
   178             *((CMDBField<TUint32>*)iWLANRecord->GetFieldByIdL(KCDTIdWlanEnableWpaPsk)) = aSettings.iEnableWpaPsk;
   195             }
   179             }
   196         }
   180         }
       
   181     
   197     // Update access point, be prepared that Commsdat might be locked
   182     // Update access point, be prepared that Commsdat might be locked
   198     TInt errCode( KErrLocked );
   183     TInt errCode( KErrLocked );
   199     TInt retryCount( 0 );
   184     TInt retryCount( 0 );
   200     
   185     
   201     while( errCode == KErrLocked && retryCount < KRetryCount )
   186     while( errCode == KErrLocked && retryCount < KRetryCount )