cmmanager/cmmgr/cmmplugins/cmpluginwlan/src/cmpluginwlan.cpp
changeset 23 7ec726f93df1
parent 20 9c97ad6591ae
child 27 489cf6208544
--- a/cmmanager/cmmgr/cmmplugins/cmpluginwlan/src/cmpluginwlan.cpp	Mon May 03 12:53:07 2010 +0300
+++ b/cmmanager/cmmgr/cmmplugins/cmpluginwlan/src/cmpluginwlan.cpp	Fri May 14 16:15:46 2010 +0300
@@ -1261,16 +1261,14 @@
 
     TBool retVal( EFalse );
 
-    if ( (TPtrC(aIapRecord->iServiceType) == TPtrC(KCDTypeNameLANService) ) &&
-            TPtrC(aIapRecord->iBearerType) == TPtrC(KCDTypeNameLANBearer) )
+    if ( ( TPtrC( aIapRecord->iServiceType ) == TPtrC( KCDTypeNameLANService ) ) &&
+            TPtrC( aIapRecord->iBearerType ) == TPtrC( KCDTypeNameLANBearer ) )
         {
         // Check if there is a WLAN record with an iServiceId == iIapRecord->iService.
         CCDWlanServiceRecord* tmprec = new( ELeave ) CCDWlanServiceRecord ( iWlanTableId );
         CleanupStack::PushL( tmprec );
 
-        TInt service = aIapRecord->iService;
-
-        tmprec->iWlanServiceId.SetL( (TUint32)service );
+        tmprec->iWlanServiceId.SetL( ( TUint32 )( aIapRecord->iService ) );
         if ( tmprec->FindL( iSession ) )
             {
             // we found at least one WLAN using this IAP,
@@ -1292,10 +1290,9 @@
     {
     OstTraceFunctionEntry0( CCMPLUGINWLAN_DELETEBEARERRECORDSL_ENTRY );
 
-    // as base class deletes service record, in this case LAN,
-    // only WLAN related stuff needs to be deleted
+    // As base class deletes service record, in this case LAN, only WLAN
+    // related stuff needs to be deleted.
     iWlanServiceRecord->DeleteL( iSession );
-    iWlanServiceRecord = NULL;
 
     OstTraceFunctionExit0( CCMPLUGINWLAN_DELETEBEARERRECORDSL_EXIT );
     }
@@ -1463,7 +1460,7 @@
                     aGenRecordArray[KIapRecordIndex] );
 
     CheckIfNameModifiedL( iapRecord, wlanServiceRecord );
-    wlanServiceRecord->iWlanServiceId.SetL( iapRecord->iService );
+    wlanServiceRecord->iWlanServiceId.SetL( ( TUint32 )( iapRecord->iService ) );
 
     CCDLANServiceRecord* serviceRecord =
             static_cast<CCDLANServiceRecord*>(
@@ -1491,101 +1488,125 @@
 // ----------------------------------------------------------------------------
 //
 void CCmPluginWlan::UpdateServiceRecordL(
-    RPointerArray<CommsDat::CCDRecordBase>& aGenRecordArray,
-    RPointerArray<CommsDat::CCDRecordBase>& aBearerSpecRecordArray )
+        RPointerArray<CommsDat::CCDRecordBase>& aGenRecordArray,
+        RPointerArray<CommsDat::CCDRecordBase>& aBearerSpecRecordArray )
     {
     OstTraceFunctionEntry0( CCMPLUGINWLAN_UPDATESERVICERECORDL_ENTRY );
 
-    // Delete the original record and create a copy from the parameter
+    // Delete the original record and create a copy from the client's copy.
     delete iServiceRecord;
     iServiceRecord = NULL;
 
-    iServiceRecord = static_cast<CCDLANServiceRecord*>
-                    (CCDRecordBase::RecordFactoryL( KCDTIdLANServiceRecord ) );
+    iServiceRecord = static_cast<CCDLANServiceRecord *>(
+            CCDRecordBase::RecordFactoryL( KCDTIdLANServiceRecord ) );
 
-    // LAN Service copy does not work so we have to copy it manually
+    // LAN Service copy does not work so we have to copy it manually.
+
+    // Plugin's commsdat copy.
+    CCDLANServiceRecord* origServiceRecord = static_cast<CCDLANServiceRecord*>( iServiceRecord );
 
-    CCDLANServiceRecord* lanServiceRecordTo =
-            static_cast<CCDLANServiceRecord *>(
-                    iServiceRecord );
+    // Client's copy of lan service record.
+    CCDLANServiceRecord* clientServiceRecordCopy =
+            static_cast<CCDLANServiceRecord*>( aGenRecordArray[KServiceRecordIndex] );
 
-    CCDLANServiceRecord* lanServiceRecordFrom =
-            static_cast<CCDLANServiceRecord *>(
-                    aGenRecordArray[KServiceRecordIndex] );
-
-    if ( !lanServiceRecordFrom->iRecordName.IsNull() )
+    if ( !clientServiceRecordCopy->iRecordTag.IsNull() )
+        {
+        origServiceRecord->iRecordTag.SetL( clientServiceRecordCopy->iRecordTag );
+        }
+    if ( !clientServiceRecordCopy->iRecordName.IsNull() )
+        {
+        origServiceRecord->iRecordName.SetL( clientServiceRecordCopy->iRecordName );
+        }
+    if ( !clientServiceRecordCopy->iServiceEnableLlmnr.IsNull() )
         {
-        lanServiceRecordTo->iRecordName.SetL( lanServiceRecordFrom->iRecordName );
+        origServiceRecord->iServiceEnableLlmnr.SetL( clientServiceRecordCopy->iServiceEnableLlmnr );
         }
-    if ( !lanServiceRecordFrom->iIfNetworks.IsNull() )
+    if ( !clientServiceRecordCopy->iIfNetworks.IsNull() )
         {
-        lanServiceRecordTo->iIfNetworks.SetL( lanServiceRecordFrom->iIfNetworks );
+        origServiceRecord->iIfNetworks.SetL( clientServiceRecordCopy->iIfNetworks );
         }
-    if ( !lanServiceRecordFrom->iIpGateway.IsNull() )
+    if ( !clientServiceRecordCopy->iIpNetmask.IsNull() )
+        {
+        origServiceRecord->iIpNetmask.SetL( clientServiceRecordCopy->iIpNetmask );
+        }
+    if ( !clientServiceRecordCopy->iIpGateway.IsNull() )
         {
-        lanServiceRecordTo->iIpGateway.SetL( lanServiceRecordFrom->iIpGateway );
+        origServiceRecord->iIpGateway.SetL( clientServiceRecordCopy->iIpGateway );
         }
-    if ( !lanServiceRecordFrom->iIpAddrFromServer.IsNull() )
+    if ( !clientServiceRecordCopy->iIpAddrFromServer.IsNull() )
         {
-        lanServiceRecordTo->iIpAddrFromServer.SetL( lanServiceRecordFrom->iIpAddrFromServer );
+        origServiceRecord->iIpAddrFromServer.SetL( clientServiceRecordCopy->iIpAddrFromServer );
         }
-    if ( !lanServiceRecordFrom->iIpAddr.IsNull() )
+    if ( !clientServiceRecordCopy->iIpAddr.IsNull() )
+        {
+        origServiceRecord->iIpAddr.SetL( clientServiceRecordCopy->iIpAddr );
+        }
+    if ( !clientServiceRecordCopy->iIpDnsAddrFromServer.IsNull() )
         {
-        lanServiceRecordTo->iIpAddr.SetL( lanServiceRecordFrom->iIpAddr );
+        origServiceRecord->iIpDnsAddrFromServer.SetL( clientServiceRecordCopy->iIpDnsAddrFromServer );
         }
-    if ( !lanServiceRecordFrom->iIpDnsAddrFromServer.IsNull() )
+    if ( !clientServiceRecordCopy->iIpNameServer1.IsNull() )
         {
-        lanServiceRecordTo->iIpDnsAddrFromServer.SetL( lanServiceRecordFrom->iIpDnsAddrFromServer );
+        origServiceRecord->iIpNameServer1.SetL( clientServiceRecordCopy->iIpNameServer1 );
         }
-    if ( !lanServiceRecordFrom->iIpNameServer1.IsNull() )
+    if ( !clientServiceRecordCopy->iIpNameServer2.IsNull() )
         {
-        lanServiceRecordTo->iIpNameServer1.SetL( lanServiceRecordFrom->iIpNameServer1 );
+        origServiceRecord->iIpNameServer2.SetL( clientServiceRecordCopy->iIpNameServer2 );
         }
-    if ( !lanServiceRecordFrom->iIpNameServer2.IsNull() )
+    if ( !clientServiceRecordCopy->iIp6DnsAddrFromServer.IsNull() )
         {
-        lanServiceRecordTo->iIpNameServer2.SetL( lanServiceRecordFrom->iIpNameServer2 );
+        origServiceRecord->iIp6DnsAddrFromServer.SetL( clientServiceRecordCopy->iIp6DnsAddrFromServer );
         }
-    if ( !lanServiceRecordFrom->iIp6DnsAddrFromServer.IsNull() )
+    if ( !clientServiceRecordCopy->iIp6NameServer1.IsNull() )
+        {
+        origServiceRecord->iIp6NameServer1.SetL( clientServiceRecordCopy->iIp6NameServer1 );
+        }
+    if ( !clientServiceRecordCopy->iIp6NameServer2.IsNull() )
         {
-        lanServiceRecordTo->iIp6DnsAddrFromServer.SetL( lanServiceRecordFrom->iIp6DnsAddrFromServer );
+        origServiceRecord->iIp6NameServer2.SetL( clientServiceRecordCopy->iIp6NameServer2 );
         }
-    if ( !lanServiceRecordFrom->iIp6NameServer1.IsNull() )
+    if ( !clientServiceRecordCopy->iIpAddrLeaseValidFrom.IsNull() )
         {
-        lanServiceRecordTo->iIp6NameServer1.SetL( lanServiceRecordFrom->iIp6NameServer1 );
+        origServiceRecord->iIpAddrLeaseValidFrom.SetL( clientServiceRecordCopy->iIpAddrLeaseValidFrom );
         }
-    if ( !lanServiceRecordFrom->iIp6NameServer2.IsNull() )
+    if ( !clientServiceRecordCopy->iIpAddrLeaseValidTo.IsNull() )
+        {
+        origServiceRecord->iIpAddrLeaseValidTo.SetL( clientServiceRecordCopy->iIpAddrLeaseValidTo );
+        }
+    if ( !clientServiceRecordCopy->iConfigDaemonManagerName.IsNull() )
         {
-        lanServiceRecordTo->iIp6NameServer2.SetL( lanServiceRecordFrom->iIp6NameServer2 );
+        origServiceRecord->iConfigDaemonManagerName.SetL( clientServiceRecordCopy->iConfigDaemonManagerName );
         }
-    if ( !lanServiceRecordFrom->iConfigDaemonManagerName.IsNull() )
+    if ( !clientServiceRecordCopy->iConfigDaemonName.IsNull() )
         {
-        lanServiceRecordTo->iConfigDaemonManagerName.SetL( lanServiceRecordFrom->iConfigDaemonManagerName );
+        origServiceRecord->iConfigDaemonName.SetL( clientServiceRecordCopy->iConfigDaemonName );
         }
-    if ( !lanServiceRecordFrom->iConfigDaemonName.IsNull() )
+    if ( !clientServiceRecordCopy->iServiceExtensionTableName.IsNull() )
         {
-        lanServiceRecordTo->iConfigDaemonName.SetL( lanServiceRecordFrom->iConfigDaemonName );
+        origServiceRecord->iServiceExtensionTableName.SetL( clientServiceRecordCopy->iServiceExtensionTableName );
+        }
+    if ( !clientServiceRecordCopy->iServiceExtensionTableRecordId.IsNull() )
+        {
+        origServiceRecord->iServiceExtensionTableRecordId.SetL( clientServiceRecordCopy->iServiceExtensionTableRecordId ); //TODO, check this works ok.
         }
 
-    lanServiceRecordTo->SetElementId( lanServiceRecordFrom->ElementId() );
-    // this is shared between wlan iaps so it cannot be hidden or protected
-    lanServiceRecordTo->ClearAttributes( ECDHidden );
-    lanServiceRecordTo->ClearAttributes( ECDProtectedWrite );
+    origServiceRecord->SetElementId( clientServiceRecordCopy->ElementId() );
 
-    if ( !ServiceRecord().RecordId() )
+    if ( !origServiceRecord->RecordId() )
         {
-        ServiceRecord().SetRecordId( KCDNewRecordRequest );
-        ServiceRecord().StoreL( iSession );
+        origServiceRecord->SetRecordId( KCDNewRecordRequest );
+        origServiceRecord->StoreL( iSession );
 
-        // Update needed values to record tables too( lanservice and wlanservice )
-        lanServiceRecordFrom->SetElementId( ServiceRecord().ElementId() );
-        CCDWlanServiceRecord* wlanServiceRecord =
-                static_cast<CCDWlanServiceRecord *>(
-                        aBearerSpecRecordArray[KWlanServiceRecordIndex] );
-        wlanServiceRecord->iWlanServiceId.SetL( ServiceRecord().RecordId() );
+        // Update received element ID to client's copy too.
+        clientServiceRecordCopy->SetElementId( origServiceRecord->ElementId() );
+        // Update needed values to other table records too (wlanservice).
+        CCDWlanServiceRecord* wlanServiceRecord = static_cast<CCDWlanServiceRecord *>(
+                aBearerSpecRecordArray[KWlanServiceRecordIndex] );
+        wlanServiceRecord->iWlanServiceId.SetL( origServiceRecord->RecordId() );
         }
     else
         {
-        ServiceRecord().ModifyL( iSession );
+        origServiceRecord->ModifyL( iSession );
         }
 
     OstTraceFunctionExit0( CCMPLUGINWLAN_UPDATESERVICERECORDL_EXIT );
@@ -1601,114 +1622,156 @@
     {
     OstTraceFunctionEntry0( CCMPLUGINWLAN_UPDATEBEARERRECORDSL_ENTRY );
 
+    // Delete the original record and create a copy from the client's copy.
     delete iWlanServiceRecord;
     iWlanServiceRecord = NULL;
 
-    CCDWlanServiceRecord* wlanServiceRecord =
-            static_cast<CCDWlanServiceRecord*>(
-                    aBearerSpecRecordArray[KWlanServiceRecordIndex] );
+    iWlanServiceRecord = new( ELeave ) CCDWlanServiceRecord( iWlanTableId );
 
-    iWlanServiceRecord = new( ELeave ) CCDWlanServiceRecord ( iWlanTableId );
-
-    iWlanServiceRecord->SetElementId( wlanServiceRecord->ElementId() );
-    iWlanServiceRecord->iRecordName.SetL( wlanServiceRecord->iRecordName );
+    // Client's copy of wlan service record.
+    CCDWlanServiceRecord* clientWlanServiceRecord = static_cast<CCDWlanServiceRecord*>(
+            aBearerSpecRecordArray[KWlanServiceRecordIndex] );
 
-    iWlanServiceRecord->iWlanServiceId.SetL( wlanServiceRecord->iWlanServiceId );
-    iWlanServiceRecord->iWlanConnMode.SetL( wlanServiceRecord->iWlanConnMode );
-    if ( !wlanServiceRecord->iWLanSSID.IsNull() )
+    if ( !clientWlanServiceRecord->iRecordTag.IsNull() )
         {
-        iWlanServiceRecord->iWLanSSID.SetL( wlanServiceRecord->iWLanSSID );
+        iWlanServiceRecord->iRecordTag.SetL(
+                clientWlanServiceRecord->iRecordTag );
+        }
+    if ( !clientWlanServiceRecord->iRecordName.IsNull() )
+        {
+        iWlanServiceRecord->iRecordName.SetL(
+                clientWlanServiceRecord->iRecordName );
         }
-    if ( !wlanServiceRecord->iWLanUsedSSID.IsNull() )
+    if ( !clientWlanServiceRecord->iWlanServiceId.IsNull() )
         {
-        iWlanServiceRecord->iWLanUsedSSID.SetL( wlanServiceRecord->iWLanUsedSSID );
+        iWlanServiceRecord->iWlanServiceId.SetL(
+                clientWlanServiceRecord->iWlanServiceId );
         }
-    if ( !wlanServiceRecord->iWLanWepKey1.IsNull() )
+    if ( !clientWlanServiceRecord->iWlanConnMode.IsNull() )
         {
-        iWlanServiceRecord->iWLanWepKey1.SetL( wlanServiceRecord->iWLanWepKey1 );
+        iWlanServiceRecord->iWlanConnMode.SetL(
+                clientWlanServiceRecord->iWlanConnMode );
+        }
+    if ( !clientWlanServiceRecord->iWLanSSID.IsNull() )
+        {
+        iWlanServiceRecord->iWLanSSID.SetL(
+                clientWlanServiceRecord->iWLanSSID );
         }
-    if ( !wlanServiceRecord->iWLanWepKey2.IsNull() )
+    if ( !clientWlanServiceRecord->iWLanUsedSSID.IsNull() )
         {
-        iWlanServiceRecord->iWLanWepKey2.SetL( wlanServiceRecord->iWLanWepKey2 );
+        iWlanServiceRecord->iWLanUsedSSID.SetL(
+                clientWlanServiceRecord->iWLanUsedSSID );
         }
-    if ( !wlanServiceRecord->iWLanWepKey3.IsNull() )
+    if ( !clientWlanServiceRecord->iWLanWepKey1.IsNull() )
         {
-        iWlanServiceRecord->iWLanWepKey3.SetL( wlanServiceRecord->iWLanWepKey3 );
+        iWlanServiceRecord->iWLanWepKey1.SetL(
+                clientWlanServiceRecord->iWLanWepKey1 );
         }
-    if ( !wlanServiceRecord->iWLanWepKey4.IsNull() )
+    if ( !clientWlanServiceRecord->iWLanWepKey2.IsNull() )
         {
-        iWlanServiceRecord->iWLanWepKey4.SetL( wlanServiceRecord->iWLanWepKey4 );
+        iWlanServiceRecord->iWLanWepKey2.SetL(
+                clientWlanServiceRecord->iWLanWepKey2 );
         }
-    if ( !wlanServiceRecord->iWlanWepIndex.IsNull() )
+    if ( !clientWlanServiceRecord->iWLanWepKey3.IsNull() )
         {
-        iWlanServiceRecord->iWlanWepIndex.SetL( wlanServiceRecord->iWlanWepIndex );
+        iWlanServiceRecord->iWLanWepKey3.SetL(
+                clientWlanServiceRecord->iWLanWepKey3 );
         }
-    if ( !wlanServiceRecord->iWlanSecMode.IsNull() )
+    if ( !clientWlanServiceRecord->iWLanWepKey4.IsNull() )
         {
-        iWlanServiceRecord->iWlanSecMode.SetL( wlanServiceRecord->iWlanSecMode );
+        iWlanServiceRecord->iWLanWepKey4.SetL(
+                clientWlanServiceRecord->iWLanWepKey4 );
         }
-    if ( !wlanServiceRecord->iWlanAuthMode.IsNull() )
+    if ( !clientWlanServiceRecord->iWlanWepIndex.IsNull() )
         {
-        iWlanServiceRecord->iWlanAuthMode.SetL( wlanServiceRecord->iWlanAuthMode );
+        iWlanServiceRecord->iWlanWepIndex.SetL(
+                clientWlanServiceRecord->iWlanWepIndex );
         }
-    if ( !wlanServiceRecord->iWlanEnableWpaPsk.IsNull() )
+    if ( !clientWlanServiceRecord->iWlanSecMode.IsNull() )
+        {
+        iWlanServiceRecord->iWlanSecMode.SetL(
+                clientWlanServiceRecord->iWlanSecMode );
+        }
+    if ( !clientWlanServiceRecord->iWlanAuthMode.IsNull() )
         {
-        iWlanServiceRecord->iWlanEnableWpaPsk.SetL( wlanServiceRecord->iWlanEnableWpaPsk );
-        }
-    if ( !wlanServiceRecord->iWLanWpaPreSharedKey.IsNull() )
-        {
-        iWlanServiceRecord->iWLanWpaPreSharedKey.SetL( wlanServiceRecord->iWLanWpaPreSharedKey );
+        iWlanServiceRecord->iWlanAuthMode.SetL(
+                clientWlanServiceRecord->iWlanAuthMode );
         }
-    if ( !wlanServiceRecord->iWlanWpaKeyLength.IsNull() )
+    if ( !clientWlanServiceRecord->iWlanEnableWpaPsk.IsNull() )
         {
-        iWlanServiceRecord->iWlanWpaKeyLength.SetL( wlanServiceRecord->iWlanWpaKeyLength );
+        iWlanServiceRecord->iWlanEnableWpaPsk.SetL(
+                clientWlanServiceRecord->iWlanEnableWpaPsk );
         }
-    if ( !wlanServiceRecord->iWLanEaps.IsNull() )
+    if ( !clientWlanServiceRecord->iWLanWpaPreSharedKey.IsNull() )
+        {
+        iWlanServiceRecord->iWLanWpaPreSharedKey.SetL(
+                clientWlanServiceRecord->iWLanWpaPreSharedKey );
+        }
+    if ( !clientWlanServiceRecord->iWlanWpaKeyLength.IsNull() )
         {
-        iWlanServiceRecord->iWLanEaps.SetL( wlanServiceRecord->iWLanEaps );
+        iWlanServiceRecord->iWlanWpaKeyLength.SetL(
+                clientWlanServiceRecord->iWlanWpaKeyLength );
         }
-    if ( !wlanServiceRecord->iWlanScanSSID.IsNull() )
+    if ( !clientWlanServiceRecord->iWLanEaps.IsNull() )
         {
-        iWlanServiceRecord->iWlanScanSSID.SetL( wlanServiceRecord->iWlanScanSSID );
+        iWlanServiceRecord->iWLanEaps.SetL(
+                clientWlanServiceRecord->iWLanEaps );
         }
-    if ( !wlanServiceRecord->iWlanChannelID.IsNull() )
+    if ( !clientWlanServiceRecord->iWlanScanSSID.IsNull() )
         {
-        iWlanServiceRecord->iWlanChannelID.SetL( wlanServiceRecord->iWlanChannelID );
+        iWlanServiceRecord->iWlanScanSSID.SetL(
+                clientWlanServiceRecord->iWlanScanSSID );
         }
-    if ( !wlanServiceRecord->iWlanFormatKey1.IsNull() )
+    if ( !clientWlanServiceRecord->iWlanChannelID.IsNull() )
+        {
+        iWlanServiceRecord->iWlanChannelID.SetL(
+                clientWlanServiceRecord->iWlanChannelID );
+        }
+    if ( !clientWlanServiceRecord->iWlanFormatKey1.IsNull() )
         {
-        iWlanServiceRecord->iWlanFormatKey1.SetL( wlanServiceRecord->iWlanFormatKey1 );
-        }
-    if ( !wlanServiceRecord->iWlanFormatKey2.IsNull() )
-        {
-        iWlanServiceRecord->iWlanFormatKey2.SetL( wlanServiceRecord->iWlanFormatKey2 );
+        iWlanServiceRecord->iWlanFormatKey1.SetL(
+                clientWlanServiceRecord->iWlanFormatKey1 );
         }
-    if ( !wlanServiceRecord->iWlanFormatKey3.IsNull() )
+    if ( !clientWlanServiceRecord->iWlanFormatKey2.IsNull() )
         {
-        iWlanServiceRecord->iWlanFormatKey3.SetL( wlanServiceRecord->iWlanFormatKey3 );
+        iWlanServiceRecord->iWlanFormatKey2.SetL(
+                clientWlanServiceRecord->iWlanFormatKey2 );
         }
-    if ( !wlanServiceRecord->iWlanFormatKey4.IsNull() )
+    if ( !clientWlanServiceRecord->iWlanFormatKey3.IsNull() )
+        {
+        iWlanServiceRecord->iWlanFormatKey3.SetL(
+                clientWlanServiceRecord->iWlanFormatKey3 );
+        }
+    if ( !clientWlanServiceRecord->iWlanFormatKey4.IsNull() )
         {
-        iWlanServiceRecord->iWlanFormatKey4.SetL( wlanServiceRecord->iWlanFormatKey4 );
+        iWlanServiceRecord->iWlanFormatKey4.SetL(
+                clientWlanServiceRecord->iWlanFormatKey4 );
         }
-    if ( !wlanServiceRecord->iWlanAllowSSIDRoaming.IsNull() )
+    if ( !clientWlanServiceRecord->iWlanAllowSSIDRoaming.IsNull() )
         {
-        iWlanServiceRecord->iWlanAllowSSIDRoaming.SetL( wlanServiceRecord->iWlanAllowSSIDRoaming );
+        iWlanServiceRecord->iWlanAllowSSIDRoaming.SetL(
+                clientWlanServiceRecord->iWlanAllowSSIDRoaming );
         }
-    if ( !wlanServiceRecord->iWLanEnabledEaps.IsNull() )
+    if ( !clientWlanServiceRecord->iWLanEnabledEaps.IsNull() )
         {
-        iWlanServiceRecord->iWLanEnabledEaps.SetL( wlanServiceRecord->iWLanEnabledEaps );
+        iWlanServiceRecord->iWLanEnabledEaps.SetL(
+                clientWlanServiceRecord->iWLanEnabledEaps );
         }
-    if ( !wlanServiceRecord->iWLanDisabledEaps.IsNull() )
+    if ( !clientWlanServiceRecord->iWLanDisabledEaps.IsNull() )
         {
-        iWlanServiceRecord->iWLanDisabledEaps.SetL( wlanServiceRecord->iWLanDisabledEaps );
+        iWlanServiceRecord->iWLanDisabledEaps.SetL(
+                clientWlanServiceRecord->iWLanDisabledEaps );
         }
 
+    iWlanServiceRecord->SetElementId( clientWlanServiceRecord->ElementId() );
+
     if ( !iWlanServiceRecord->RecordId() )
         {
         iWlanServiceRecord->SetRecordId( KCDNewRecordRequest );
         iWlanServiceRecord->StoreL( iSession );
-        wlanServiceRecord->SetElementId( iWlanServiceRecord->ElementId() );
+
+        // Update received element ID to client's copy too.
+        clientWlanServiceRecord->SetElementId( iWlanServiceRecord->ElementId() );
         }
     else
         {
@@ -1729,7 +1792,7 @@
 
     if ( !iWlanServiceRecord )
         {
-        // IAP not yet in CommDat
+        // IAP not yet in CommsDat.
         GetDefaultWlanServiceRecordL( aRecordArray );
         }
     else
@@ -1738,7 +1801,6 @@
         CleanupStack::PushL( wlanServiceRecord );
         CopyWlanServiceRecordL( iWlanServiceRecord, wlanServiceRecord );
         wlanServiceRecord->SetElementId( iWlanServiceRecord->ElementId() );
-        wlanServiceRecord->iWlanServiceId.SetL( iWlanServiceRecord->iWlanServiceId );
         aRecordArray.AppendL( wlanServiceRecord );
         CleanupStack::Pop( wlanServiceRecord );
         }
@@ -1754,11 +1816,120 @@
     {
     OstTraceFunctionEntry0( CCMPLUGINWLAN_COPYSERVICERECORDL_ENTRY );
 
-    __ASSERT_DEBUG( iServiceRecord != NULL, User::Leave( KErrNotFound ));
+    // New service record to be returned.
+    CCDRecordBase* serviceRecord = static_cast<CCDLANServiceRecord*>(
+            CCDRecordBase::RecordFactoryL( KCDTIdLANServiceRecord ) );
+    CleanupStack::PushL( serviceRecord );
+
+    CCDLANServiceRecord* tempServiceRecordPtrToNew =
+            static_cast<CCDLANServiceRecord*>( serviceRecord );
+
+    // CommsDat version of service record.
+    CCDLANServiceRecord* origServiceRecord =
+            static_cast<CCDLANServiceRecord*>( iServiceRecord );
 
-    CCDRecordBase* serviceRecord =
-            static_cast<CCDLANServiceRecord*>(
-                    CCDRecordBase::CreateCopyRecordL( *iServiceRecord ) );
+    if ( !origServiceRecord->iRecordTag.IsNull() )
+        {
+        tempServiceRecordPtrToNew->iRecordTag.SetL(
+                origServiceRecord->iRecordTag );
+        }
+    if ( !origServiceRecord->iRecordName.IsNull() )
+        {
+        tempServiceRecordPtrToNew->iRecordName.SetL(
+                origServiceRecord->iRecordName );
+        }
+    if ( !origServiceRecord->iServiceEnableLlmnr.IsNull() )
+        {
+        tempServiceRecordPtrToNew->iServiceEnableLlmnr.SetL(
+                origServiceRecord->iServiceEnableLlmnr );
+        }
+    if ( !origServiceRecord->iIfNetworks.IsNull() )
+        {
+        tempServiceRecordPtrToNew->iIfNetworks.SetL(
+                origServiceRecord->iIfNetworks );
+        }
+    if ( !origServiceRecord->iIpNetmask.IsNull() )
+        {
+        tempServiceRecordPtrToNew->iIpNetmask.SetL(
+                origServiceRecord->iIpNetmask );
+        }
+    if ( !origServiceRecord->iIpGateway.IsNull() )
+        {
+        tempServiceRecordPtrToNew->iIpGateway.SetL(
+                origServiceRecord->iIpGateway );
+        }
+    if ( !origServiceRecord->iIpAddrFromServer.IsNull() )
+        {
+        tempServiceRecordPtrToNew->iIpAddrFromServer.SetL(
+                origServiceRecord->iIpAddrFromServer );
+        }
+    if ( !origServiceRecord->iIpAddr.IsNull() )
+        {
+        tempServiceRecordPtrToNew->iIpAddr.SetL(
+                origServiceRecord->iIpAddr );
+        }
+    if ( !origServiceRecord->iIpDnsAddrFromServer.IsNull() )
+        {
+        tempServiceRecordPtrToNew->iIpDnsAddrFromServer.SetL(
+                origServiceRecord->iIpDnsAddrFromServer );
+        }
+    if ( !origServiceRecord->iIpNameServer1.IsNull() )
+        {
+        tempServiceRecordPtrToNew->iIpNameServer1.SetL(
+                origServiceRecord->iIpNameServer1 );
+        }
+    if ( !origServiceRecord->iIpNameServer2.IsNull() )
+        {
+        tempServiceRecordPtrToNew->iIpNameServer2.SetL(
+                origServiceRecord->iIpNameServer2 );
+        }
+    if ( !origServiceRecord->iIp6DnsAddrFromServer.IsNull() )
+        {
+        tempServiceRecordPtrToNew->iIp6DnsAddrFromServer.SetL(
+                origServiceRecord->iIp6DnsAddrFromServer );
+        }
+    if ( !origServiceRecord->iIp6NameServer1.IsNull() )
+        {
+        tempServiceRecordPtrToNew->iIp6NameServer1.SetL(
+                origServiceRecord->iIp6NameServer1 );
+        }
+    if ( !origServiceRecord->iIp6NameServer2.IsNull() )
+        {
+        tempServiceRecordPtrToNew->iIp6NameServer2.SetL(
+                origServiceRecord->iIp6NameServer2 );
+        }
+    if ( !origServiceRecord->iIpAddrLeaseValidFrom.IsNull() )
+        {
+        tempServiceRecordPtrToNew->iIpAddrLeaseValidFrom.SetL(
+                origServiceRecord->iIpAddrLeaseValidFrom );
+        }
+    if ( !origServiceRecord->iIpAddrLeaseValidTo.IsNull() )
+        {
+        tempServiceRecordPtrToNew->iIpAddrLeaseValidTo.SetL(
+                origServiceRecord->iIpAddrLeaseValidTo );
+        }
+    if ( !origServiceRecord->iConfigDaemonManagerName.IsNull() )
+        {
+        tempServiceRecordPtrToNew->iConfigDaemonManagerName.SetL(
+                origServiceRecord->iConfigDaemonManagerName );
+        }
+    if ( !origServiceRecord->iConfigDaemonName.IsNull() )
+        {
+        tempServiceRecordPtrToNew->iConfigDaemonName.SetL(
+                origServiceRecord->iConfigDaemonName );
+        }
+    if ( !origServiceRecord->iServiceExtensionTableName.IsNull() )
+        {
+        tempServiceRecordPtrToNew->iServiceExtensionTableName.SetL(
+                origServiceRecord->iServiceExtensionTableName );
+        }
+    if ( !origServiceRecord->iServiceExtensionTableRecordId.IsNull() )
+        {
+        tempServiceRecordPtrToNew->iServiceExtensionTableRecordId.SetL(
+                origServiceRecord->iServiceExtensionTableRecordId );
+        }
+
+    CleanupStack::Pop( serviceRecord );
 
     OstTraceFunctionExit0( CCMPLUGINWLAN_COPYSERVICERECORDL_EXIT );
     return serviceRecord;
@@ -1897,10 +2068,23 @@
         User::Leave( KErrArgument );
         }
 
-    aDestRecord->iRecordName.SetL( aSourceRecord->iRecordName );
-    aDestRecord->iRecordTag.SetL( aSourceRecord->iRecordTag );
-    aDestRecord->iWlanConnMode.SetL( aSourceRecord->iWlanConnMode );
+    if ( !aSourceRecord->iRecordTag.IsNull() )
+        {
+        aDestRecord->iRecordTag.SetL( aSourceRecord->iRecordTag );
+        }
+    if ( !aSourceRecord->iRecordName.IsNull() )
+        {
+        aDestRecord->iRecordName.SetL( aSourceRecord->iRecordName );
+        }
 
+    if ( !aSourceRecord->iWlanServiceId.IsNull() )
+        {
+        aDestRecord->iWlanServiceId.SetL( aSourceRecord->iWlanServiceId );
+        }
+    if ( !aSourceRecord->iWlanConnMode.IsNull() )
+        {
+        aDestRecord->iWlanConnMode.SetL( aSourceRecord->iWlanConnMode );
+        }
     if ( !aSourceRecord->iWLanSSID.IsNull() )
         {
         aDestRecord->iWLanSSID.SetL( aSourceRecord->iWLanSSID );
@@ -2290,9 +2474,10 @@
     OstTraceFunctionEntry0( CCMPLUGINWLAN_COPYBEARERRECORDSL_ENTRY );
 
     CCmPluginWlan* plugin = static_cast<CCmPluginWlan*>( aCopyInstance );
-    plugin->iWlanServiceRecord = new( ELeave ) CCDWlanServiceRecord ( iWlanTableId );
+    plugin->iWlanServiceRecord = new( ELeave ) CCDWlanServiceRecord( iWlanTableId );
 
     CopyWlanServiceRecordL( iWlanServiceRecord, plugin->iWlanServiceRecord );
+    plugin->iWlanServiceRecord->iWlanServiceId.SetL( 0 );
     plugin->iWAPISupported = iWAPISupported;
 
     OstTraceFunctionExit0( CCMPLUGINWLAN_COPYBEARERRECORDSL_EXIT );