bearermanagement/mpm/src/mpmcommsdataccess.cpp
branchRCL_3
changeset 24 05bc53fe583b
parent 13 c14618f9de99
child 25 83ca720e2b9a
equal deleted inserted replaced
23:fc7b30ed2058 24:05bc53fe583b
     1 /*
     1 /*
     2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). 
     2 * Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies). 
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
   232 
   232 
   233                 MPMLOGSSID( "CMPMCommsDatAccess<0x%x>::ValidateIapL: SSID = %S", 
   233                 MPMLOGSSID( "CMPMCommsDatAccess<0x%x>::ValidateIapL: SSID = %S", 
   234                     aSession.ConnectionId(), &ssid )
   234                     aSession.ConnectionId(), &ssid )
   235 
   235 
   236                 TUint32 presumedIapId = aIapId; 
   236                 TUint32 presumedIapId = aIapId; 
   237 
       
   238                 // Find and change Iap and Net Id if SSID exist
       
   239                 //
       
   240                 if ( !CheckEasyWLanL( aIapId ) )
       
   241                     {
       
   242                     aSession.MyServer().Events()->FindSSID( ssid, aIapId, aNetId );
       
   243                     }
       
   244 
   237 
   245                 // Store Iap Id, Net Id and empty APN to TConnInfo, 
   238                 // Store Iap Id, Net Id and empty APN to TConnInfo, 
   246                 // so that FindAPN can utilise the information 
   239                 // so that FindAPN can utilise the information 
   247                 // during the validation of next IAP to support 
   240                 // during the validation of next IAP to support 
   248                 // using existing WLAN connection SSID.
   241                 // using existing WLAN connection SSID.
   411         }
   404         }
   412 
   405 
   413     CleanupStack::PopAndDestroy(buf1);
   406     CleanupStack::PopAndDestroy(buf1);
   414     CleanupStack::PopAndDestroy(commsDbIapTableView);    
   407     CleanupStack::PopAndDestroy(commsDbIapTableView);    
   415     CleanupStack::PopAndDestroy(commsDatabase);
   408     CleanupStack::PopAndDestroy(commsDatabase);
   416     }
       
   417 
       
   418 // -----------------------------------------------------------------------------
       
   419 // CMPMCommsDatAccess::CheckEasyWLanL
       
   420 // -----------------------------------------------------------------------------
       
   421 //
       
   422 TBool CMPMCommsDatAccess::CheckEasyWLanL( TUint32 aIapId ) const
       
   423     {
       
   424     MPMLOGSTRING2( "CMPMCommsDatAccess::CheckEasyWLanL: IAP Id = %i", aIapId)
       
   425 
       
   426     TBool easyWlan = EFalse;
       
   427     CCommsDatabase* commsDatabase = CCommsDatabase::NewL();
       
   428     CleanupStack::PushL( commsDatabase );
       
   429 
       
   430     // Make hidden records visible
       
   431     // 
       
   432     commsDatabase->ShowHiddenRecords();
       
   433 
       
   434     CCommsDbTableView* commsDbIapTableView = 
       
   435         commsDatabase->OpenViewMatchingUintLC( TPtrC( IAP ),
       
   436                                                TPtrC( COMMDB_ID ),
       
   437                                                aIapId );
       
   438 
       
   439     User::LeaveIfError( commsDbIapTableView->GotoFirstRecord() );
       
   440 
       
   441     TInt length1( 0 );
       
   442 
       
   443     commsDbIapTableView->ReadColumnLengthL( TPtrC( IAP_SERVICE_TYPE ), 
       
   444                                             length1 );
       
   445 
       
   446     HBufC* buf1 = HBufC::NewLC( length1 );
       
   447     TPtr ptr1( buf1->Des() );
       
   448 
       
   449     // Read IAP's service type
       
   450     //
       
   451     commsDbIapTableView->ReadTextL(TPtrC( IAP_SERVICE_TYPE ), ptr1 );
       
   452     MPMLOGSTRING2(
       
   453         "CMPMCommsDatAccess::CheckEasyWLanL: IAP service type = %S", &ptr1 )
       
   454 
       
   455     if ( ptr1.Compare( TPtrC( LAN_SERVICE ) ) == KErrNone )
       
   456         {
       
   457         TUint32 service( 0 );
       
   458         commsDbIapTableView->ReadUintL( TPtrC( IAP_SERVICE ), service );
       
   459 
       
   460         // Now open a view to LAN_SERVICE table
       
   461         //
       
   462         CCommsDbTableView* commsDbLanTableView = 
       
   463             commsDatabase->OpenViewMatchingUintLC( TPtrC( LAN_SERVICE ),
       
   464                                                    TPtrC( COMMDB_ID ),
       
   465                                                    service );
       
   466 
       
   467         User::LeaveIfError( commsDbLanTableView->GotoFirstRecord() );
       
   468 
       
   469         TUint32 commDbId( 0 );
       
   470 
       
   471         commsDbLanTableView->ReadUintL( TPtrC( COMMDB_ID ), commDbId );
       
   472 
       
   473         // Now open a view to WLAN_SERVICE table
       
   474         //
       
   475         // If non wlan product, wlan tables won't exist and this will 
       
   476         // leave. In that case do not check WLAN related issues 
       
   477         //
       
   478         CCommsDbTableView* commsDbWlanTableView( NULL );
       
   479         TRAPD( err2, commsDbWlanTableView =
       
   480                      commsDatabase->OpenViewMatchingUintLC( TPtrC( WLAN_SERVICE ),
       
   481                                                             TPtrC( WLAN_SERVICE_ID ),
       
   482                                                             commDbId );
       
   483                      CleanupStack::Pop( commsDbWlanTableView ) );
       
   484         if ( err2 == KErrNone )
       
   485             {
       
   486             // Push back to cleanup stack. Object must be popped within 
       
   487             // TRAP, to avoid unbalance in cleanup stack and panic 71
       
   488             CleanupStack::PushL( commsDbWlanTableView );
       
   489 
       
   490             TInt err = commsDbWlanTableView->GotoFirstRecord();
       
   491 
       
   492             if ( err == KErrNone )
       
   493                 {
       
   494                 TInt ssidLength( 0 );
       
   495                 commsDbWlanTableView->ReadColumnLengthL( TPtrC( NU_WLAN_SSID ), 
       
   496                                                                 ssidLength );
       
   497                 if ( ssidLength == 0 )
       
   498                     {
       
   499                     MPMLOGSTRING(
       
   500                         "CMPMCommsDatAccess::CheckEasyWLanL: IAP is Easy WLAN" )
       
   501                     easyWlan = ETrue;
       
   502                     }
       
   503                 else
       
   504                     {
       
   505                     MPMLOGSTRING(
       
   506                         "CMPMCommsDatAccess::CheckEasyWLanL: IAP isn't Easy WLAN" )
       
   507                     easyWlan = EFalse;
       
   508                     }
       
   509                 }
       
   510             else
       
   511                 {
       
   512                 MPMLOGSTRING2( "CMPMCommsDatAccess::CheckEasyWLanL\
       
   513  GotoFirstRecord returned %d", err )
       
   514                 }
       
   515 
       
   516             // Release memory
       
   517             //
       
   518             CleanupStack::PopAndDestroy( commsDbWlanTableView );
       
   519             }
       
   520         else
       
   521             {
       
   522             MPMLOGSTRING2(
       
   523                         "CMPMCommsDatAccess::CheckEasyWLanL: WLAN table view failed, err %d", err2 )
       
   524             }    
       
   525         CleanupStack::PopAndDestroy( commsDbLanTableView );
       
   526         }
       
   527 
       
   528     // Release memory
       
   529     //
       
   530     CleanupStack::PopAndDestroy( buf1 );
       
   531     CleanupStack::PopAndDestroy( commsDbIapTableView );
       
   532     CleanupStack::PopAndDestroy( commsDatabase );
       
   533 
       
   534     return easyWlan;
       
   535     }
   409     }
   536 
   410 
   537 // -----------------------------------------------------------------------------
   411 // -----------------------------------------------------------------------------
   538 // CMPMCommsDatAccess::DumpIAPsL
   412 // CMPMCommsDatAccess::DumpIAPsL
   539 // -----------------------------------------------------------------------------
   413 // -----------------------------------------------------------------------------
  1032         }
   906         }
  1033 
   907 
  1034     CleanupStack::PopAndDestroy( table );
   908     CleanupStack::PopAndDestroy( table );
  1035     CleanupStack::PopAndDestroy( commsDatabase );
   909     CleanupStack::PopAndDestroy( commsDatabase );
  1036     }
   910     }
  1037         
       
  1038 // -----------------------------------------------------------------------------
       
  1039 // CMPMCommsDatAccess::CheckWLANIapWithSsidL
       
  1040 // -----------------------------------------------------------------------------
       
  1041 //
       
  1042 
       
  1043 TUint32 CMPMCommsDatAccess::CheckWLANIapWithSsidL( TWlanSsid& aSsid, 
       
  1044                                                    TUint32 aSecMode,
       
  1045                                                    TWlanNetMode aConnMode )
       
  1046     {
       
  1047     MPMLOGSTRING( "CMPMCommsDatAccess::CheckWLANIapWithSsidL" )
       
  1048     TUint iapId( 0 );
       
  1049 
       
  1050     // Creating a session with the latest version
       
  1051     //     
       
  1052     CMDBSession* db = CMDBSession::NewLC( KCDVersion1_1 );
       
  1053 
       
  1054     db->SetAttributeMask( ECDHidden | ECDProtectedWrite );
       
  1055 
       
  1056     // Find Wlan service record
       
  1057     //
       
  1058     TBuf<KWlanMaxSsidLength> ssid16;
       
  1059     CnvUtfConverter::ConvertToUnicodeFromUtf8( ssid16, aSsid );
       
  1060     MPMLOGSTRING4( "CMPMCommsDatAccess::CheckWLANIapWithSsidL sec:%d, conn:%d ssid %S", 
       
  1061                    aSecMode, 
       
  1062                    aConnMode, 
       
  1063                    &ssid16 )
       
  1064     CMDBRecordSet<CCDWlanServiceRecord>* wlanSet = 
       
  1065         new ( ELeave ) CMDBRecordSet<CCDWlanServiceRecord>( 
       
  1066          CCDWlanServiceRecord::TableIdL( *db ) );
       
  1067     CleanupStack::PushL( wlanSet ); 
       
  1068 
       
  1069     CCDWlanServiceRecord* wlanRecord = new ( ELeave ) 
       
  1070         CCDWlanServiceRecord( CCDWlanServiceRecord::TableIdL( *db ) );
       
  1071 
       
  1072     CleanupStack::PushL( wlanRecord ); 
       
  1073     wlanSet->LoadL( *db );
       
  1074     
       
  1075     MPMLOGSTRING2( "CMPMCommsDatAccess::CheckWLANIapWithSsidL, record count:%d", 
       
  1076                    wlanSet->iRecords.Count() )
       
  1077     TBool matchFound( EFalse );
       
  1078     for (TInt i = 0; ( i < wlanSet->iRecords.Count() ) && !matchFound; i++ )
       
  1079         {
       
  1080         wlanRecord->SetElementId( GetRealElementId( wlanSet->iRecords[i] ) );
       
  1081         wlanRecord->LoadL( *db );
       
  1082         TBuf<KWlanMaxSsidLength> ssid;
       
  1083         ssid = wlanRecord->iWLanSSID;
       
  1084         //if not easywlan, continue
       
  1085         //
       
  1086         if( ssid.Compare( KNullDesC() ) )
       
  1087             {
       
  1088             ssid = wlanRecord->iWLanSSID.GetL();
       
  1089             TUint32 secMode = wlanRecord->iWlanSecMode;
       
  1090             TUint32 connMode = wlanRecord->iWlanConnMode;
       
  1091         
       
  1092             if ( connMode )
       
  1093                 {
       
  1094                 connMode = 1;    
       
  1095                 }
       
  1096             MPMLOGSTRING3( "CMPMCommsDatAccess::CheckWLANIapWithSsidL CommsDat secmode:%d, connmode:%d ", 
       
  1097         				   secMode, 
       
  1098         				   connMode )
       
  1099 
       
  1100             if ( !ssid.Compare( ssid16 ) && ( aConnMode == connMode ) )
       
  1101         	    {
       
  1102         	    //compare sec mode
       
  1103         	    if ( aSecMode == EWlanSecModeOpen || aSecMode == EWlanSecModeWep )
       
  1104         		    {
       
  1105         		    if ( aSecMode == secMode )
       
  1106         		        {
       
  1107         		        MPMLOGSTRING( "CMPMCommsDatAccess::CheckWLANIapWithSsidL match found, open/wep " )
       
  1108         		        matchFound = ETrue;
       
  1109         		        }
       
  1110         			    
       
  1111         		    }
       
  1112             	//WPA PSK case
       
  1113             	else if ( aSecMode == EWlanSecModeWpa2 )
       
  1114             		{
       
  1115         	    	if ( ( secMode > EWlanSecModeWep ) && (wlanRecord->iWlanEnableWpaPsk) )
       
  1116         	    	    {
       
  1117         	    	    MPMLOGSTRING( "CMPMCommsDatAccess::CheckWLANIapWithSsidL match found, wpa psk " )
       
  1118         	    	    matchFound = ETrue;
       
  1119         	    	    }
       
  1120             		}
       
  1121             	//aSecMode = EWlanSecModeWpa
       
  1122             	else
       
  1123             		{
       
  1124         	    	if ( secMode > EWlanSecModeWep )
       
  1125         	    	    {
       
  1126         	    	    MPMLOGSTRING( "CMPMCommsDatAccess::CheckWLANIapWithSsidL match found, wpa " )
       
  1127         	    	    matchFound = ETrue;
       
  1128         	    	    }
       
  1129             		}
       
  1130         			
       
  1131         		}
       
  1132         	}
       
  1133         }
       
  1134     
       
  1135     if ( matchFound )
       
  1136         {
       
  1137         // load Iap record
       
  1138         //
       
  1139         CCDIAPRecord* iapRecord = static_cast<CCDIAPRecord*> ( 
       
  1140             CCDRecordBase::RecordFactoryL( KCDTIdIAPRecord ) );
       
  1141         CleanupStack::PushL( iapRecord );
       
  1142 
       
  1143         CCDLANServiceRecord* lanRecord = static_cast<CCDLANServiceRecord*> (
       
  1144             CCDRecordBase::RecordFactoryL( KCDTIdLANServiceRecord ));
       
  1145         CleanupStack::PushL( lanRecord );
       
  1146         
       
  1147         iapRecord->iServiceType.SetL( TPtrC( KCDTypeNameLANService ) );
       
  1148         
       
  1149         lanRecord->SetRecordId( wlanRecord->iWlanServiceId );
       
  1150         lanRecord->LoadL( *db );
       
  1151 
       
  1152         iapRecord->iService = lanRecord->ElementId();
       
  1153 
       
  1154 /*        iapRecord->iServiceType.SetL( TPtrC( KCDTypeNameLANService ) );
       
  1155         iapRecord->iService = wlanRecord->iWlanServiceId;
       
  1156 */
       
  1157         if( iapRecord->FindL( *db ) )
       
  1158             {
       
  1159             MPMLOGSTRING( "CMPMCommsDatAccess::CheckWLANIapWithSsidL iap found" )
       
  1160             // Iap record found
       
  1161             //
       
  1162             iapId = iapRecord->RecordId();
       
  1163             }
       
  1164         CleanupStack::PopAndDestroy( lanRecord );
       
  1165         CleanupStack::PopAndDestroy( iapRecord );
       
  1166         }
       
  1167     CleanupStack::PopAndDestroy( wlanRecord );
       
  1168     CleanupStack::PopAndDestroy( wlanSet );
       
  1169     CleanupStack::PopAndDestroy( db );
       
  1170     
       
  1171     return iapId;
       
  1172     }
       
  1173 
       
  1174 // -----------------------------------------------------------------------------
       
  1175 // CMPMCommsDatAccess::SetEasyWlanDataL
       
  1176 // -----------------------------------------------------------------------------
       
  1177 //
       
  1178 void CMPMCommsDatAccess::SetEasyWlanDataL( const TWlanSsid& aSsid,
       
  1179                                            TUint            aSecMode,
       
  1180                                            TWlanNetMode     aConnMode,
       
  1181                                            TWepKeyData      aWepData,
       
  1182                                            TUint            aEnableWpaPsk,
       
  1183                                            const TDesC8&    aWpaPsk,
       
  1184                                            TUint            aWpaKeyLen )
       
  1185     {
       
  1186     MPMLOGSTRING( "CMPMCommsDatAccess::SetEasyWlanDataL" )
       
  1187     CMDBSession* dbSession = CMDBSession::NewL( KCDVersion1_1 );
       
  1188     CleanupStack::PushL(dbSession);
       
  1189 
       
  1190     // Try to open a transaction to obtain write lock
       
  1191     dbSession->OpenTransactionL();
       
  1192 
       
  1193     TUint32 wlanId = FindEasyWlanServiceIdL( dbSession );
       
  1194     if( !wlanId )
       
  1195         {
       
  1196         MPMLOGSTRING( "CMPMCommsDatAccess::SetEasyWlanDataL unable to store \
       
  1197  easy wlan settings" )
       
  1198         dbSession->Close();		
       
  1199 		CleanupStack::PopAndDestroy( dbSession );
       
  1200         return;
       
  1201         }
       
  1202     
       
  1203     CMDBGenericRecord* record = static_cast<CMDBGenericRecord*> 
       
  1204 				    ( CCDRecordBase::RecordFactoryL( 0));
       
  1205     CleanupStack::PushL( record );
       
  1206     record->InitializeL( TPtrC( WLAN_SERVICE ),NULL );
       
  1207     record->SetRecordId( wlanId );
       
  1208     record->LoadL( *dbSession );
       
  1209 
       
  1210         TBuf<KWlanMaxSsidLength> ssid16;
       
  1211         CnvUtfConverter::ConvertToUnicodeFromUtf8( ssid16, aSsid );
       
  1212         CMDBField<TDesC>* textField = (CMDBField<TDesC>*)record->GetFieldByIdL(KCDTIdWlanUsedSSID);
       
  1213         textField->SetMaxLengthL( ssid16.Length());
       
  1214         textField->SetL( ssid16 );
       
  1215     
       
  1216         *((CMDBField<TUint32>*)record->GetFieldByIdL(KCDTIdWlanSecMode)) = aSecMode;
       
  1217         *((CMDBField<TUint32>*)record->GetFieldByIdL(KCDTIdWlanConnMode)) = aConnMode;
       
  1218     
       
  1219         if (aEnableWpaPsk)
       
  1220     	    {
       
  1221     	    MPMLOGSTRING( "CMPMCommsDatAccess::SetEasyWlanDataL wpa psk" )
       
  1222     	    CMDBField<TDesC8>* binField = (CMDBField<TDesC8>*)
       
  1223 		   									record->GetFieldByIdL(KCDTIdWlanWpaPreSharedKey);
       
  1224 		    binField->SetMaxLengthL( aWpaKeyLen );
       
  1225 		    binField->SetL( aWpaPsk );
       
  1226 
       
  1227 		    *((CMDBField<TUint32>*)record->GetFieldByIdL(KCDTIdWlanWpaKeyLength)) = aWpaKeyLen;
       
  1228 		    *((CMDBField<TUint32>*)record->GetFieldByIdL(KCDTIdWlanEnableWpaPsk)) = aEnableWpaPsk;
       
  1229     	    }
       
  1230         else if (aSecMode == EWlanSecModeWep)
       
  1231     	    {
       
  1232     	    MPMLOGSTRING( "CMPMCommsDatAccess::SetEasyWlanDataL wep psk" )
       
  1233      	    *((CMDBField<TUint32>*)record->GetFieldByIdL( KCDTIdWlanWepIndex )) = 
       
  1234      	        aWepData.iDefaultWep;
       
  1235  
       
  1236     	    SetWepKeyL( KCDTIdWlanFormatKey1, KCDTIdWlanWepKey1, 
       
  1237     	                aWepData.iWep1, aWepData.iWepFormat1, record );
       
  1238             SetWepKeyL( KCDTIdWlanFormatKey2, KCDTIdWlanWepKey2, 
       
  1239                         aWepData.iWep2, aWepData.iWepFormat2, record );
       
  1240             SetWepKeyL( KCDTIdWlanFormatKey3, KCDTIdWlanWepKey3, 
       
  1241                         aWepData.iWep3, aWepData.iWepFormat3, record );
       
  1242             SetWepKeyL( KCDTIdWlanFormatKey4, KCDTIdWlanWepKey4, 
       
  1243                         aWepData.iWep4, aWepData.iWepFormat4, record );
       
  1244     	    }
       
  1245     	else
       
  1246     	    {
       
  1247     	    MPMLOGSTRING2( "CMPMCommsDatAccess::SetEasyWlanDataL sec mode %d, no key data written",
       
  1248     	         aSecMode )
       
  1249     	    }
       
  1250     
       
  1251         //Finally save all to commsdat.
       
  1252         record->ModifyL( *dbSession );
       
  1253         dbSession->CommitTransactionL();
       
  1254         dbSession->Close();
       
  1255         CleanupStack::PopAndDestroy( record );
       
  1256         CleanupStack::PopAndDestroy( dbSession );
       
  1257     }
       
  1258 
       
  1259 // -----------------------------------------------------------------------------
       
  1260 // CMPMCommsDatAccess::SetWepKeyL
       
  1261 // -----------------------------------------------------------------------------
       
  1262 //
       
  1263 void CMPMCommsDatAccess::SetWepKeyL( TMDBElementId       aFormatId,
       
  1264                                      TMDBElementId       aKeyId, 
       
  1265                                      TWlanWepKey         aWepKey,
       
  1266                                      TUint               aWepFormat,
       
  1267                                      CMDBGenericRecord*  aRecord )
       
  1268     {
       
  1269     CMDBField<TUint32>* formatField = static_cast<CMDBField<TUint32>*>
       
  1270             ( aRecord->GetFieldByIdL( aFormatId ) );
       
  1271     formatField->SetL( aWepFormat );
       
  1272     CMDBField<TDesC8>* wepKey = static_cast<CMDBField<TDesC8>*>
       
  1273             ( aRecord->GetFieldByIdL( aKeyId ) );
       
  1274     if ( aWepFormat )
       
  1275         {
       
  1276         wepKey->SetL( aWepKey );
       
  1277         }
       
  1278     else
       
  1279         {
       
  1280         //Convert Ascii to Hex format, as only Hex value to be stored in CommsDat
       
  1281         HBufC8* buf8Conv = HBufC8::NewLC( aWepKey.Length() * KMpmDoubleLength );
       
  1282         ConvertAsciiToHex( aWepKey, buf8Conv );
       
  1283         wepKey->SetL( buf8Conv->Des() );
       
  1284         CleanupStack::PopAndDestroy( buf8Conv );
       
  1285         }
       
  1286     }
       
  1287 
       
  1288 // -----------------------------------------------------------------------------
       
  1289 // CMPMCommsDatAccess::ConvertAsciiToHex
       
  1290 // -----------------------------------------------------------------------------
       
  1291 //
       
  1292 void CMPMCommsDatAccess::ConvertAsciiToHex( const TDesC8& aSource, 
       
  1293         							        HBufC8* aDest )
       
  1294     {
       
  1295     MPMLOGSTRING( "CMPMCommsDatAccess::ConvertAsciiToHex" )
       
  1296     _LIT( hex, "0123456789ABCDEF" );
       
  1297     TInt size = aSource.Size();
       
  1298     TPtr8 ptr = aDest->Des();
       
  1299     for ( TInt ii = 0; ii < size; ii++ )
       
  1300     	{
       
  1301     	TText8 ch = aSource[ii];
       
  1302     	ptr.Append( hex()[(ch/16)&0x0f] );
       
  1303     	ptr.Append( hex()[ch&0x0f] );
       
  1304     	}
       
  1305     }
       
  1306 
       
  1307 // -----------------------------------------------------------------------------
       
  1308 // CMPMCommsDatAccess::FindEasyWlanServiceIdL
       
  1309 // -----------------------------------------------------------------------------
       
  1310 //
       
  1311 TUint32 CMPMCommsDatAccess::FindEasyWlanServiceIdL( CMDBSession* aDb )
       
  1312     {
       
  1313     // if the method returns the record container there is for 
       
  1314     // some reason garbage data in the key values
       
  1315     //
       
  1316     TUint32 wlanId( 0 );
       
  1317     MPMLOGSTRING( "CMPMCommsDatAccess::FindEasyWlanServiceIdL" )    
       
  1318 
       
  1319     CMDBRecordSet<CCDWlanServiceRecord>* wlanSet = 
       
  1320         new ( ELeave ) CMDBRecordSet<CCDWlanServiceRecord>( 
       
  1321          CCDWlanServiceRecord::TableIdL( *aDb ) );
       
  1322     CleanupStack::PushL( wlanSet ); 
       
  1323     wlanSet->LoadL( *aDb );
       
  1324     
       
  1325     TBool found( EFalse );
       
  1326     for ( TInt i = 0; i < wlanSet->iRecords.Count() && !found; i++ )
       
  1327         {
       
  1328         CCDWlanServiceRecord* wlanRecord = new ( ELeave ) 
       
  1329             CCDWlanServiceRecord( CCDWlanServiceRecord::TableIdL( *aDb ) );
       
  1330         CleanupStack::PushL( wlanRecord );
       
  1331 
       
  1332         wlanRecord->SetElementId( GetRealElementId( wlanSet->iRecords[i] ) );
       
  1333         wlanRecord->LoadL( *aDb );
       
  1334         
       
  1335         TDesC ssid = wlanRecord->iWLanSSID;
       
  1336         if( !ssid.Compare( KNullDesC() ) )
       
  1337             {
       
  1338             MPMLOGSTRING2( "CMPMCommsDatAccess::FindEasyWlanServiceIdL: \
       
  1339 found service entry %i", wlanRecord->RecordId() )
       
  1340             wlanId = wlanRecord->RecordId();
       
  1341             found = ETrue;
       
  1342             }
       
  1343         CleanupStack::PopAndDestroy( wlanRecord );
       
  1344         }
       
  1345     CleanupStack::PopAndDestroy( wlanSet );
       
  1346     return wlanId;
       
  1347     }
       
  1348 
   911 
  1349 // -----------------------------------------------------------------------------
   912 // -----------------------------------------------------------------------------
  1350 // CMPMCommsDatAccess::CheckHiddenAgentL
   913 // CMPMCommsDatAccess::CheckHiddenAgentL
  1351 // -----------------------------------------------------------------------------
   914 // -----------------------------------------------------------------------------
  1352 //
   915 //
  1751                 MPMLOGSTRING( "CMPMCommsDatAccess::CheckWlanL: IAP is WLAN" )
  1314                 MPMLOGSTRING( "CMPMCommsDatAccess::CheckWlanL: IAP is WLAN" )
  1752                 wlan = EWlanIap;
  1315                 wlan = EWlanIap;
  1753                 TInt ssidLength( 0 );
  1316                 TInt ssidLength( 0 );
  1754                 commsDbWlanTableView->ReadColumnLengthL( TPtrC( NU_WLAN_SSID ), 
  1317                 commsDbWlanTableView->ReadColumnLengthL( TPtrC( NU_WLAN_SSID ), 
  1755                                                      ssidLength );
  1318                                                      ssidLength );
  1756                 if ( ssidLength == 0 )
       
  1757                     {
       
  1758                     MPMLOGSTRING(
       
  1759                         "CMPMCommsDatAccess::CheckWlanL: IAP is Easy WLAN" )
       
  1760                     wlan = EEasyWlanIap;
       
  1761                     }
       
  1762                 }
  1319                 }
  1763             else
  1320             else
  1764                 {
  1321                 {
  1765                 MPMLOGSTRING2( "CMPMCommsDatAccess::CheckWlanL\
  1322                 MPMLOGSTRING2( "CMPMCommsDatAccess::CheckWlanL\
  1766  GotoFirstRecord returned %d", err )
  1323  GotoFirstRecord returned %d", err )
  2323             MPMLOGSTRING(
  1880             MPMLOGSTRING(
  2324                 "CMPMCommsDatAccess::FindRealIapL: Call ChooseBestIAPL" )
  1881                 "CMPMCommsDatAccess::FindRealIapL: Call ChooseBestIAPL" )
  2325 
  1882 
  2326             TMpmConnPref tempMpmConnPref;
  1883             TMpmConnPref tempMpmConnPref;
  2327             tempMpmConnPref.SetSnapId( snap );
  1884             tempMpmConnPref.SetSnapId( snap );
  2328             
  1885 
  2329             // Ensure that there will be no infinite loops by dropping
  1886             // Ensure that there will be no infinite loops by dropping
  2330             // this virtual iap out from the list of available iaps.
  1887             // this virtual iap out from the list of available iaps.
  2331             // E.g. next layer SNAP could be the same as current SNAP.
  1888             // E.g. next layer SNAP could be the same as current SNAP.
  2332             RAvailableIAPList tempList;
  1889             RAvailableIAPList tempList;
  2333             CleanupClosePushL( tempList );
  1890             CleanupClosePushL( tempList );
  2342                     tempList.Append( aAvailableIAPList[i] );
  1899                     tempList.Append( aAvailableIAPList[i] );
  2343                     }
  1900                     }
  2344                 }
  1901                 }
  2345             aSession.IapSelectionL()->ChooseBestIAPL( tempMpmConnPref, tempList );
  1902             aSession.IapSelectionL()->ChooseBestIAPL( tempMpmConnPref, tempList );
  2346             CleanupStack::PopAndDestroy( &tempList );
  1903             CleanupStack::PopAndDestroy( &tempList );
  2347             
  1904 
  2348             aRealIapId = tempMpmConnPref.IapId();
  1905             aRealIapId = tempMpmConnPref.IapId();
  2349             }
  1906             }
  2350         else if ( virtualNext->iNextLayerIAP != 0 )
  1907         else if ( virtualNext->iNextLayerIAP != 0 )
  2351             {
  1908             {
  2352             // IAP
  1909             // IAP
  2594     CleanupStack::PopAndDestroy( snapAPr );
  2151     CleanupStack::PopAndDestroy( snapAPr );
  2595     return ret;
  2152     return ret;
  2596     }
  2153     }
  2597 
  2154 
  2598 // -----------------------------------------------------------------------------
  2155 // -----------------------------------------------------------------------------
       
  2156 // CMPMCommsDatAccess::IsIntranetSnapL
       
  2157 // -----------------------------------------------------------------------------
       
  2158 //
       
  2159 TBool CMPMCommsDatAccess::IsIntranetSnapL( TUint32 aSnapId )
       
  2160     {
       
  2161     MPMLOGSTRING( "CMPMCommsDatAccess::IsIntranetSnapL" )
       
  2162 
       
  2163     RCmManager rCmManager;
       
  2164     rCmManager.OpenLC();
       
  2165 
       
  2166     RCmDestination dest = rCmManager.DestinationL( aSnapId );
       
  2167     CleanupClosePushL(dest);
       
  2168     TInt snapMetadata = dest.MetadataL( CMManager::ESnapMetadataPurpose );
       
  2169     CleanupStack::PopAndDestroy( &dest );
       
  2170     CleanupStack::PopAndDestroy( &rCmManager );
       
  2171     
       
  2172     if ( snapMetadata == CMManager::ESnapPurposeIntranet )
       
  2173         {
       
  2174         return ETrue;
       
  2175         }
       
  2176     
       
  2177     return EFalse;            
       
  2178     }
       
  2179 
       
  2180 // -----------------------------------------------------------------------------
  2599 // CMPMCommsDatAccess::GetBearerTypeL
  2181 // CMPMCommsDatAccess::GetBearerTypeL
  2600 // -----------------------------------------------------------------------------
  2182 // -----------------------------------------------------------------------------
  2601 //
  2183 //
  2602 TMPMBearerType CMPMCommsDatAccess::GetBearerTypeL( TUint32 aIapId )
  2184 TMPMBearerType CMPMCommsDatAccess::GetBearerTypeL( TUint32 aIapId )
  2603     {
  2185     {
  2690             aWlanArray.AppendL( ptrLanBearerRecordSet->iRecords[i]->RecordId() );
  2272             aWlanArray.AppendL( ptrLanBearerRecordSet->iRecords[i]->RecordId() );
  2691             }
  2273             }
  2692         }
  2274         }
  2693     
  2275     
  2694     CleanupStack::PopAndDestroy( ptrLanBearerRecordSet );    
  2276     CleanupStack::PopAndDestroy( ptrLanBearerRecordSet );    
  2695     }
       
  2696 
       
  2697 // -----------------------------------------------------------------------------
       
  2698 // CMPMCommsDatAccess::AreActiveIapsInSameSnapL
       
  2699 // -----------------------------------------------------------------------------
       
  2700 //
       
  2701 TBool CMPMCommsDatAccess::AreActiveIapsInSameSnapL ( RArray<TActiveBMConn>& aActiveBMConns,
       
  2702                                                      TUint32& aSnapId,
       
  2703                                                      CMPMServer& aServer )
       
  2704     {
       
  2705     MPMLOGSTRING( "CMPMCommsDatAccess::AreActiveIapsInSameSnapL" )
       
  2706     TBool same = ETrue;
       
  2707     TUint32 snapId = 0;
       
  2708     TUint32 prevSnapId = 0;
       
  2709             
       
  2710     // Go through all active connections
       
  2711     for (TInt index = 0; index < aActiveBMConns.Count(); index++ )
       
  2712         {
       
  2713         CMPMServerSession* serverSession = aServer.GetServerSession(
       
  2714                 aActiveBMConns[index].iConnInfo.iConnId );
       
  2715     
       
  2716         // Do check only for active connections
       
  2717         if ( aActiveBMConns[index].iConnInfo.iState != EStarted ||
       
  2718              !serverSession->ChooseBestIapCalled())
       
  2719             {
       
  2720             continue;
       
  2721             }
       
  2722         
       
  2723         // Iap id must be nonzero
       
  2724         if ( aActiveBMConns[index].iConnInfo.iIapId )
       
  2725             {
       
  2726             prevSnapId = snapId;
       
  2727             // Get destination id for the iap
       
  2728             snapId = aActiveBMConns[index].iConnInfo.iSnap;
       
  2729             
       
  2730             // Check if previous iap's destination is different
       
  2731             if ( ( ( prevSnapId != snapId ) && prevSnapId && snapId ) ||
       
  2732                  !snapId )
       
  2733                 {
       
  2734                 // Set return value to false and leave loop
       
  2735                 same = EFalse;
       
  2736                 break;
       
  2737                 }
       
  2738             }
       
  2739         }
       
  2740     
       
  2741     // Return destId for later use
       
  2742     aSnapId = snapId;
       
  2743     
       
  2744     return same;
       
  2745     }
       
  2746 
       
  2747 // -----------------------------------------------------------------------------
       
  2748 // CMPMCommsDatAccess::SelectActiveConnectionL
       
  2749 // -----------------------------------------------------------------------------
       
  2750 //
       
  2751 void CMPMCommsDatAccess::SelectActiveConnectionL ( const TUint32 aSnapId,
       
  2752                                                    RArray<TActiveBMConn>& aActiveBMConns,
       
  2753                                                    TUint32& aActiveIapId,
       
  2754                                                    TUint32& aActiveSnapId,
       
  2755                                                    TMPMBearerType& aActiveBearerType,
       
  2756                                                    CMPMServerSession& aSession )
       
  2757     {
       
  2758     MPMLOGSTRING( "CMPMCommsDatAccess::SelectActiveConnectionL" )
       
  2759     RArray<TUint32> activeIaps;
       
  2760     RArray<TNetIap> iapIds;
       
  2761     
       
  2762     // Reset output parameters
       
  2763     aActiveIapId = 0;
       
  2764     aActiveSnapId = 0;
       
  2765     aActiveBearerType = EMPMBearerTypeNone;
       
  2766 
       
  2767     CleanupClosePushL( activeIaps );
       
  2768         
       
  2769     for (TInt index = 0; index < aActiveBMConns.Count(); index++ )
       
  2770         {
       
  2771         CMPMServerSession* serverSession = 
       
  2772             aSession.MyServer().GetServerSession(
       
  2773                 aActiveBMConns[index].iConnInfo.iConnId );
       
  2774 
       
  2775         // Add only started iaps to array
       
  2776         if ( aActiveBMConns[index].iConnInfo.iState == EStarted &&
       
  2777              serverSession->ChooseBestIapCalled() )
       
  2778             {
       
  2779             activeIaps.AppendL ( aActiveBMConns[index].iConnInfo.iIapId );
       
  2780             }
       
  2781         }
       
  2782         
       
  2783     CleanupClosePushL( iapIds );
       
  2784     SearchDNEntriesL( aSnapId, iapIds );
       
  2785     
       
  2786     // Remove any deactived IAP from iapIds
       
  2787     TInt ret        = KErrNotFound;
       
  2788     TInt destCount  = iapIds.Count();
       
  2789     
       
  2790     // Decrement by one, because count is n, 
       
  2791     // but indexes in array are 0 .. n-1.
       
  2792     // 
       
  2793     destCount--;
       
  2794 
       
  2795     // This time we are browsing the array from the end to the beginning, 
       
  2796     // because removing one element from array affects index numbering.
       
  2797     for ( TInt k = destCount; k >= 0; k-- )
       
  2798         {
       
  2799         ret = activeIaps.Find( iapIds[k].iIapId );
       
  2800         if ( ret == KErrNotFound )
       
  2801             {
       
  2802             MPMLOGSTRING2( "CMPMCommsDatAccess::SelectActiveConnectionL: \
       
  2803 Remove deactived IAP = %i", iapIds[k].iIapId )
       
  2804             iapIds.Remove( k );
       
  2805             }
       
  2806         }
       
  2807 
       
  2808     // Determine the actual priorities for IAPs
       
  2809     if( iapIds.Count() > 1 )
       
  2810         {
       
  2811         DeterminePrioritiesL( iapIds, activeIaps, aSession );
       
  2812         }
       
  2813 
       
  2814     // Check if a matching available IAP is found.
       
  2815     if( iapIds.Count() )
       
  2816         {
       
  2817         // Go through all iaps
       
  2818         for ( TInt index = 0; index < iapIds.Count(); index++ )
       
  2819             {
       
  2820             // Get bearer type
       
  2821             TMPMBearerType bearerType = GetBearerTypeL( iapIds[index].iIapId );
       
  2822         
       
  2823             // If iap is not vpn, wlan or packet then skip it
       
  2824             if ( bearerType == EMPMBearerTypeOther )
       
  2825                 {
       
  2826                 continue;
       
  2827                 }
       
  2828             
       
  2829             // Set bearer type, iap id and snap id
       
  2830             for (TInt index2 = 0; index2 < aActiveBMConns.Count(); index2++ )
       
  2831                 {
       
  2832                 if ( ( aActiveBMConns[index2].iConnInfo.iIapId ==
       
  2833                        iapIds[index].iIapId ) )
       
  2834                     {
       
  2835                     if ( aSession.MyServer().DedicatedClients().Find(
       
  2836                          aActiveBMConns[index2].iConnInfo.iAppUid ) != KErrNone )
       
  2837                         {
       
  2838                         aActiveSnapId = aActiveBMConns[index2].iConnInfo.iSnap;
       
  2839                         aActiveIapId = aActiveBMConns[index2].iConnInfo.iIapId;
       
  2840                         aActiveBearerType = bearerType;
       
  2841                         }
       
  2842                     break;
       
  2843                     }
       
  2844                 }
       
  2845             
       
  2846             break;
       
  2847             }
       
  2848         }
       
  2849 
       
  2850     MPMLOGSTRING4(
       
  2851         "CMPMCommsDatAccess::SelectActiveConnectionL: Iap id = %i, Snap id = %i, \
       
  2852 Bearer type = %i",
       
  2853         aActiveIapId, aActiveSnapId, aActiveBearerType )
       
  2854     
       
  2855     CleanupStack::PopAndDestroy( &iapIds );
       
  2856     CleanupStack::PopAndDestroy( &activeIaps );
       
  2857     }
       
  2858     
       
  2859 // -----------------------------------------------------------------------------
       
  2860 // CMPMCommsDatAccess::GetSnapIdL
       
  2861 // -----------------------------------------------------------------------------
       
  2862 //
       
  2863 TUint32 CMPMCommsDatAccess::GetSnapIdL( TUint32 aIapId )
       
  2864     {
       
  2865     MPMLOGSTRING( "CMPMCommsDatAccess::GetSnapIdL" )
       
  2866     TUint32 snapId = 0;
       
  2867     RArray<TUint> snapIds;
       
  2868         
       
  2869     CleanupClosePushL( snapIds );
       
  2870     // Get destinations
       
  2871     FindAllSnapsL( snapIds );
       
  2872 
       
  2873     for (TInt index = 0; index < snapIds.Count(); index++)
       
  2874         {
       
  2875         RArray<TNetIap> ids;
       
  2876         // Get iaps belonging to this snap
       
  2877         CleanupClosePushL( ids );
       
  2878         SearchDNEntriesL( snapIds[index], ids );
       
  2879             
       
  2880         for (TInt index2 = 0; index2 < ids.Count(); index2++)
       
  2881             {
       
  2882             // Check if iap belongs to this destination
       
  2883             if (ids[index2].iIapId == aIapId)
       
  2884                 {
       
  2885                 snapId = snapIds[index];
       
  2886                 CleanupStack::PopAndDestroy( &ids );                    
       
  2887                 CleanupStack::PopAndDestroy( &snapIds );
       
  2888                 return snapId;
       
  2889                 }
       
  2890             }
       
  2891         
       
  2892         CleanupStack::PopAndDestroy( &ids );
       
  2893         }
       
  2894 
       
  2895     CleanupStack::PopAndDestroy( &snapIds );
       
  2896     
       
  2897     return snapId;
       
  2898     }
  2277     }
  2899 
  2278 
  2900 // -----------------------------------------------------------------------------
  2279 // -----------------------------------------------------------------------------
  2901 // CMPMCommsDatAccess::IsSnapEmptyL
  2280 // CMPMCommsDatAccess::IsSnapEmptyL
  2902 // -----------------------------------------------------------------------------
  2281 // -----------------------------------------------------------------------------
  3144         }
  2523         }
  3145     
  2524     
  3146     return destinationId;
  2525     return destinationId;
  3147     }
  2526     }
  3148 
  2527 
       
  2528 // -----------------------------------------------------------------------------
       
  2529 // CMPMCommsDatAccess::GetDefaultConnectionL
       
  2530 // -----------------------------------------------------------------------------
       
  2531 //
       
  2532 void CMPMCommsDatAccess::GetDefaultConnectionL( TCmDefConnType& aType, TUint32& aId )
       
  2533     {
       
  2534     MPMLOGSTRING( "CMPMCommsDatAccess::GetDefaultConnectionL" )
       
  2535 
       
  2536     RCmManager rCmManager;
       
  2537     CleanupClosePushL( rCmManager ); 
       
  2538     rCmManager.CreateTablesAndOpenL();
       
  2539     
       
  2540     TCmDefConnValue defConnValue;
       
  2541     rCmManager.ReadDefConnL( defConnValue );
       
  2542     
       
  2543     aType = defConnValue.iType;
       
  2544     aId = defConnValue.iId;
       
  2545     
       
  2546     CleanupStack::PopAndDestroy( &rCmManager );
       
  2547     
       
  2548     }
       
  2549 
  3149 //  End of File
  2550 //  End of File