bearermanagement/mpm/src/mpmcommsdataccess.cpp
changeset 0 5a93021fdf25
child 3 f7816ffc66ed
equal deleted inserted replaced
-1:000000000000 0:5a93021fdf25
       
     1 /*
       
     2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: MPM CommsDat access functions
       
    15 *
       
    16 */
       
    17 
       
    18 /**
       
    19 @file mpmcommsdataccess.cpp
       
    20 Mobility Policy Manager CommsDat access functions.
       
    21 */
       
    22 
       
    23 // INCLUDE FILES
       
    24 #include <e32base.h>
       
    25 #include <commdb.h>
       
    26 #include <metadatabase.h>
       
    27 #include <commsdattypeinfov1_1.h>
       
    28 #include <commsdattypesv1_1.h>
       
    29 #include <datamobilitycommsdattypes.h>
       
    30 #include <cmpluginbaseeng.h>
       
    31 #include <WlanCdbCols.h>
       
    32 #include <cmmanagerdef.h>
       
    33 #include <cmconnectionmethoddef.h>
       
    34 #include <wlancontainer.h>
       
    35 #include <utf.h>
       
    36 #include <cmpluginwlandef.h>
       
    37 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    38 #include <commsdattypeinfov1_1_internal.h>
       
    39 #include <commsdattypesv1_1_partner.h>
       
    40 #endif
       
    41 
       
    42 #include <in_sock.h>
       
    43 #include <cmgenconnsettings.h>
       
    44 #include <cmdestination.h>
       
    45 
       
    46 #include "mpmcommsdataccess.h"
       
    47 #include "mpmserversession.h"
       
    48 #include "mpmconnmonevents.h"
       
    49 #include "mpmiapselection.h"
       
    50 
       
    51 // ============================ MEMBER FUNCTIONS ===============================
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // CMPMCommsDatAccess::NewL
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 CMPMCommsDatAccess* CMPMCommsDatAccess::NewL()
       
    58     {
       
    59     CMPMCommsDatAccess* self = new ( ELeave ) CMPMCommsDatAccess();
       
    60     CleanupStack::PushL(self);
       
    61     self->ConstructL();
       
    62     CleanupStack::Pop(self);
       
    63     return self;
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CMPMCommsDatAccess::CMPMCommsDatAccess
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 CMPMCommsDatAccess::CMPMCommsDatAccess()
       
    71     {
       
    72     }
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // CMPMCommsDatAccess::ConstructL
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 void CMPMCommsDatAccess::ConstructL()
       
    79     {
       
    80     }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // CMPMCommsDatAccess::~CMPMCommsDatAccess
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 CMPMCommsDatAccess::~CMPMCommsDatAccess()
       
    87     {
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // CMPMCommsDatAccess::FindAllSnapsL
       
    92 // -----------------------------------------------------------------------------
       
    93 //
       
    94 void CMPMCommsDatAccess::FindAllSnapsL( RArray<TUint>& aSnapIds )
       
    95     {
       
    96     MPMLOGSTRING( "CMPMCommsDatAccess::FindAllSnapsL " )
       
    97 
       
    98     CMDBSession* db = CMDBSession::NewLC( KCDVersion1_1 );
       
    99     
       
   100     // Get the table id from generic
       
   101     // 
       
   102     CMDBGenericRecord* generic = static_cast<CMDBGenericRecord*>
       
   103         ( CCDRecordBase::RecordFactoryL( 0 ) );
       
   104     CleanupStack::PushL( generic );
       
   105     generic->InitializeL( TPtrC( KCDTypeNameDataMobilitySelectionPolicy ), 
       
   106                           NULL );
       
   107     generic->LoadL( *db );
       
   108 
       
   109     // Create the DN-IAP record set
       
   110     // 
       
   111     CMDBRecordSet<CCDDataMobilitySelectionPolicyRecord>* dnIAPRecordSet = 
       
   112         new ( ELeave ) CMDBRecordSet<CCDDataMobilitySelectionPolicyRecord>( 
       
   113         generic->TableId() );
       
   114     CleanupStack::PushL( dnIAPRecordSet );
       
   115 
       
   116     dnIAPRecordSet->LoadL( *db );
       
   117     for ( TInt i = 0; i < dnIAPRecordSet->iRecords.Count(); i++ )
       
   118         {
       
   119         CCDDataMobilitySelectionPolicyRecord* dnRecord = new ( ELeave ) 
       
   120         CCDDataMobilitySelectionPolicyRecord( generic->TableId() );
       
   121                 
       
   122         dnRecord->SetElementId( GetRealElementId( dnIAPRecordSet->iRecords[i] ) );
       
   123         dnRecord->LoadL( *db );
       
   124 
       
   125         TUint snapId = dnRecord->iSNAP;
       
   126         MPMLOGSTRING2( "CMPMCommsDatAccess::FindAllSnapsL snap %d", snapId )
       
   127 
       
   128         // Insert unique ids to array
       
   129         //
       
   130         aSnapIds.InsertInOrder( snapId );
       
   131         delete dnRecord;
       
   132         }
       
   133 
       
   134     CleanupStack::PopAndDestroy( dnIAPRecordSet );
       
   135     CleanupStack::PopAndDestroy( generic );
       
   136     CleanupStack::PopAndDestroy( db );
       
   137     }
       
   138 
       
   139 // -----------------------------------------------------------------------------
       
   140 // CMPMCommsDatAccess::ValidateIapL
       
   141 // -----------------------------------------------------------------------------
       
   142 //
       
   143 void CMPMCommsDatAccess::ValidateIapL( 
       
   144     const TConnectionId         aConnId,
       
   145     TUint32&                    aIapId, 
       
   146     TUint32&                    aNetId, 
       
   147     TBool&                      aLanOrWlan,
       
   148     CMPMServerSession&          aSession )
       
   149     {
       
   150     MPMLOGSTRING2(
       
   151         "CMPMCommsDatAccess::ValidateIapL: Validating chosen IAP Id = %i", 
       
   152         aIapId )
       
   153 
       
   154     aLanOrWlan = EFalse;
       
   155 
       
   156     SearchAccessNetIdL( aIapId, aNetId );
       
   157 
       
   158     CCommsDatabase* commsDatabase = CCommsDatabase::NewL();
       
   159     CleanupStack::PushL( commsDatabase );
       
   160 
       
   161     // Make hidden records visible
       
   162     // 
       
   163     commsDatabase->ShowHiddenRecords();
       
   164 
       
   165     CCommsDbTableView* commsDbIapTableView = 
       
   166         commsDatabase->OpenViewMatchingUintLC( TPtrC( IAP ),
       
   167                                                TPtrC( COMMDB_ID ),
       
   168                                                aIapId );
       
   169 
       
   170     User::LeaveIfError( commsDbIapTableView->GotoFirstRecord() );
       
   171 
       
   172     TInt length1( 0 );
       
   173 
       
   174     commsDbIapTableView->ReadColumnLengthL( TPtrC( IAP_SERVICE_TYPE ), 
       
   175                                             length1 );
       
   176     HBufC* buf1 = HBufC::NewLC( length1 );
       
   177     TPtr ptr1( buf1->Des() );
       
   178 
       
   179     // Read IAP's service type
       
   180     //
       
   181     commsDbIapTableView->ReadTextL(TPtrC( IAP_SERVICE_TYPE ), ptr1 );
       
   182     MPMLOGSTRING2(
       
   183         "CMPMCommsDatAccess::ValidateIapL: IAP service type = %S",
       
   184         &ptr1)
       
   185 
       
   186     // In case offline mode is enabled, we need to find out what type 
       
   187     // of bearer is used. Only LAN or WLAN is allowed in offline mode.
       
   188     // 
       
   189     if ( ptr1.Compare( TPtrC( LAN_SERVICE ) ) == KErrNone )
       
   190         {
       
   191         aLanOrWlan = ETrue;
       
   192 
       
   193         TUint32 service( 0 );
       
   194         commsDbIapTableView->ReadUintL( TPtrC( IAP_SERVICE ), service );
       
   195 
       
   196         // Now open a view to LAN_SERVICE table
       
   197         //
       
   198         CCommsDbTableView* commsDbLanTableView = 
       
   199             commsDatabase->OpenViewMatchingUintLC( TPtrC( LAN_SERVICE ),
       
   200                                                    TPtrC( COMMDB_ID ),
       
   201                                                    service );
       
   202 
       
   203         User::LeaveIfError( commsDbLanTableView->GotoFirstRecord() );
       
   204 
       
   205         TUint32 commDbId( 0 );
       
   206 
       
   207         commsDbLanTableView->ReadUintL( TPtrC( COMMDB_ID ), commDbId );
       
   208 
       
   209         // Now open a view to WLAN_SERVICE table
       
   210         //
       
   211         // If non wlan product, wlan tables won't exist and this will 
       
   212         // leave. In that case do not check WLAN related issues 
       
   213         //
       
   214         CCommsDbTableView* commsDbWlanTableView( NULL );
       
   215         TRAPD( err2, commsDbWlanTableView = 
       
   216                     commsDatabase->OpenViewMatchingUintLC( TPtrC( WLAN_SERVICE ),
       
   217                                                    TPtrC( WLAN_SERVICE_ID ),
       
   218                                                    commDbId );
       
   219                     CleanupStack::Pop( commsDbWlanTableView ) );
       
   220         if( err2 == KErrNone )
       
   221             {
       
   222             // Push back to cleanup stack. Object must be popped within 
       
   223             // TRAP, to avoid unbalance in cleanup stack and panic 71
       
   224             CleanupStack::PushL( commsDbWlanTableView );
       
   225             
       
   226             TInt err = commsDbWlanTableView->GotoFirstRecord();
       
   227 
       
   228             if ( err == KErrNone )
       
   229                 {
       
   230                 TWlanSsid ssid;
       
   231                 commsDbWlanTableView->ReadTextL( TPtrC( NU_WLAN_SSID ), ssid );
       
   232 
       
   233                 MPMLOGSSID( "CMPMCommsDatAccess<0x%x>::ValidateIapL: SSID = %S", 
       
   234                     aSession.ConnectionId(), &ssid )
       
   235 
       
   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 
       
   245                 // Store Iap Id, Net Id and empty APN to TConnInfo, 
       
   246                 // so that FindAPN can utilise the information 
       
   247                 // during the validation of next IAP to support 
       
   248                 // using existing WLAN connection SSID.
       
   249                 //
       
   250                 aSession.MyServer().Events()->AppendConnInfo( aConnId );
       
   251                 aSession.MyServer().Events()->SetConnInfo( aConnId, 
       
   252                                                            aIapId, 
       
   253                                                            presumedIapId, 
       
   254                                                            aNetId, 
       
   255                                                            ssid );
       
   256                 }
       
   257             else
       
   258                 {
       
   259                 MPMLOGSTRING2( "CMPMCommsDatAccess::ValidateIapL\
       
   260  GotoFirstRecord returned %d", err )
       
   261                 }
       
   262             CleanupStack::PopAndDestroy( commsDbWlanTableView );
       
   263             }
       
   264         else
       
   265             {
       
   266             MPMLOGSTRING2(
       
   267                         "CMPMCommsDatAccess::ValidateIapL: WLAN table view failed, err %d", err2 )
       
   268             }                
       
   269         CleanupStack::PopAndDestroy( commsDbLanTableView );
       
   270         }
       
   271 
       
   272     // If this IAP needs PDP Context management, we'll do it here
       
   273     // 
       
   274     else if ( ptr1.Compare(TPtrC(OUTGOING_WCDMA)) == KErrNone )
       
   275         {
       
   276         TUint32 service;
       
   277         commsDbIapTableView->ReadUintL( TPtrC( IAP_SERVICE ), service );
       
   278 
       
   279         // Now open a view to OUTGOING_WCDMA table
       
   280         //
       
   281         CCommsDbTableView* commsDbPsdTableView = 
       
   282             commsDatabase->OpenViewMatchingUintLC( TPtrC( OUTGOING_WCDMA ),
       
   283                                                    TPtrC( COMMDB_ID ),
       
   284                                                    service );
       
   285 
       
   286         User::LeaveIfError( commsDbPsdTableView->GotoFirstRecord() );
       
   287 
       
   288         TInt length2( 0 );
       
   289 
       
   290         commsDbPsdTableView->ReadColumnLengthL( TPtrC( GPRS_APN ), length2 );
       
   291 
       
   292         HBufC* buf2 = HBufC::NewLC( length2 );
       
   293         TPtr ptr2( buf2->Des() );
       
   294 
       
   295         // Read APN
       
   296         //
       
   297         commsDbPsdTableView->ReadTextL( TPtrC( GPRS_APN ), ptr2 );
       
   298         MPMLOGSTRING2(
       
   299             "CMPMCommsDatAccess::ValidateIapL: APN = %S", &ptr2)
       
   300 
       
   301         TUint32 presumedIapId = aIapId; 
       
   302 
       
   303         // Find and change Iap and Net Id if APN exist
       
   304         //
       
   305         aSession.MyServer().Events()->FindAPN( ptr2, aIapId, aNetId ); 
       
   306 
       
   307         // Store Iap Id, Net Id and APN to TConnInfo, 
       
   308         // so that FindAPN can utilise the information 
       
   309         // during the validation of next IAP to support 
       
   310         // using existing PDP context per APN.
       
   311         //
       
   312         aSession.MyServer().Events()->AppendConnInfo( aConnId );
       
   313         aSession.MyServer().Events()->SetConnInfo( aConnId, 
       
   314                                                    aIapId, 
       
   315                                                    presumedIapId, 
       
   316                                                    aNetId, 
       
   317                                                    ptr2 );
       
   318         CleanupStack::PopAndDestroy( buf2 );
       
   319         CleanupStack::PopAndDestroy( commsDbPsdTableView );
       
   320         }
       
   321     else if ( ptr1.Compare(TPtrC( VPN_SERVICE )) == KErrNone )
       
   322         {
       
   323         MPMLOGSTRING(
       
   324             "CMPMCommsDatAccess::ValidateIapL: Enable VPN in offline mode" )
       
   325         aLanOrWlan = ETrue;
       
   326         }
       
   327     else
       
   328         {
       
   329         MPMLOGSTRING(
       
   330             "CMPMCommsDatAccess::ValidateIapL: Service Type out of range" )
       
   331         }
       
   332 
       
   333     CleanupStack::PopAndDestroy( buf1 );
       
   334     CleanupStack::PopAndDestroy( commsDbIapTableView );
       
   335     CleanupStack::PopAndDestroy( commsDatabase );
       
   336 
       
   337     MPMLOGSTRING2(
       
   338         "CMPMCommsDatAccess::ValidateIapL: Validated IAP Id = %i", aIapId )
       
   339     }
       
   340 
       
   341 
       
   342 // -----------------------------------------------------------------------------
       
   343 // CMPMCommsDatAccess::CheckBearerL
       
   344 // -----------------------------------------------------------------------------
       
   345 //
       
   346 void CMPMCommsDatAccess::CheckBearerL( 
       
   347     TUint32&                    aIapId, 
       
   348     TBool&                      aLanOrWlan, 
       
   349     const RAvailableIAPList&    aAvailableIAPList,
       
   350     CMPMServerSession&          aSession )
       
   351     {
       
   352     MPMLOGSTRING2( "CMPMCommsDatAccess::CheckBearerL: IAP Id = %i", aIapId )
       
   353 
       
   354     aLanOrWlan = EFalse;
       
   355 
       
   356     // Use FindRealIapL to find the real IAP behind the virtual IAP.
       
   357     // 
       
   358     TUint32 realIapId( 0 );
       
   359     FindRealIapL( aIapId, 
       
   360                   realIapId, 
       
   361                   aAvailableIAPList,
       
   362                   aSession );
       
   363 
       
   364     if ( ( realIapId != 0 ) && ( aIapId != realIapId ) )
       
   365         {
       
   366         aIapId = realIapId;
       
   367         MPMLOGSTRING2(
       
   368             "CMPMCommsDatAccess::CheckBearerL: Found real IAP Id = %i", 
       
   369             aIapId )
       
   370         }
       
   371 
       
   372     CCommsDatabase* commsDatabase = CCommsDatabase::NewL();
       
   373     CleanupStack::PushL(commsDatabase);
       
   374 
       
   375     // Make hidden records visible
       
   376     // 
       
   377     commsDatabase->ShowHiddenRecords();
       
   378 
       
   379     CCommsDbTableView* commsDbIapTableView = 
       
   380         commsDatabase->OpenViewMatchingUintLC( TPtrC(IAP),
       
   381                                                TPtrC(COMMDB_ID),
       
   382                                                aIapId);
       
   383 
       
   384     User::LeaveIfError( commsDbIapTableView->GotoFirstRecord() );
       
   385 
       
   386     TInt length1( 0 );
       
   387 
       
   388     commsDbIapTableView->ReadColumnLengthL(TPtrC(IAP_SERVICE_TYPE), length1);
       
   389     HBufC* buf1 = HBufC::NewLC(length1);
       
   390     TPtr ptr1( buf1->Des() );
       
   391 
       
   392     // Read IAP's service type
       
   393     //
       
   394     commsDbIapTableView->ReadTextL(TPtrC(IAP_SERVICE_TYPE), ptr1);
       
   395     MPMLOGSTRING2(
       
   396         "CMPMCommsDatAccess::CheckBearerL: IAP_SERVICE_TYPE from CommsDat = %S",
       
   397         &ptr1 )
       
   398 
       
   399     // In case offline mode is enabled, we need to find out what type 
       
   400     // of bearer is used. Only LAN or WLAN is allowed in offline mode.
       
   401     // 
       
   402     if ( ptr1.Compare(TPtrC(LAN_SERVICE)) == KErrNone )
       
   403         {
       
   404         aLanOrWlan = ETrue;
       
   405         MPMLOGSTRING( "CMPMCommsDatAccess::CheckBearerL: Bearer type LAN/WLAN" )
       
   406         }
       
   407     else
       
   408         {
       
   409         aLanOrWlan = EFalse;
       
   410         MPMLOGSTRING( "CMPMCommsDatAccess::CheckBearerL: Bearer type GSM/UMTS" )
       
   411         }
       
   412 
       
   413     CleanupStack::PopAndDestroy(buf1);
       
   414     CleanupStack::PopAndDestroy(commsDbIapTableView);    
       
   415     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     }
       
   536 
       
   537 // -----------------------------------------------------------------------------
       
   538 // CMPMCommsDatAccess::DumpIAPsL
       
   539 // -----------------------------------------------------------------------------
       
   540 //
       
   541 void CMPMCommsDatAccess::DumpIAPsL() const
       
   542     {
       
   543 #ifdef _DEBUG
       
   544 
       
   545     // Dump CommsDat IAPs to log in order to support testing
       
   546     // 
       
   547     TInt err( KErrNone );
       
   548 
       
   549     MPMLOGSTRING( "Display CommsDat IAPs - Start" )
       
   550     MPMLOGSTRING( "" )
       
   551 
       
   552     CCommsDatabase* commsDatabase = CCommsDatabase::NewL();
       
   553     CleanupStack::PushL(commsDatabase);
       
   554 
       
   555     // Make hidden records visible
       
   556     // 
       
   557     commsDatabase->ShowHiddenRecords();
       
   558 
       
   559     // Iterate the IAP table from CommsDat
       
   560     CCommsDbTableView* table = NULL;
       
   561     table = commsDatabase->OpenTableLC( TPtrC( IAP ) );
       
   562 
       
   563     err = table->GotoFirstRecord();
       
   564 
       
   565     while ( !err )
       
   566         {
       
   567         TUint32 iapId( 0 );
       
   568         TInt    length1( 0 );
       
   569         TInt    length2( 0 );
       
   570 
       
   571         // Read IAP's ID
       
   572         //
       
   573         table->ReadUintL( TPtrC( COMMDB_ID ), iapId );
       
   574 
       
   575         // Read IAP's connection name
       
   576         //
       
   577         table->ReadColumnLengthL( TPtrC( COMMDB_NAME ), length1 );
       
   578         HBufC* buf1 = HBufC::NewLC( length1 );
       
   579         TPtr ptr1( buf1->Des() );
       
   580         table->ReadTextL( TPtrC( COMMDB_NAME ), ptr1 );
       
   581 
       
   582         // Read IAP's service type
       
   583         //
       
   584         table->ReadColumnLengthL(TPtrC( IAP_SERVICE_TYPE ), length2 );
       
   585         HBufC* buf2 = HBufC::NewLC( length2 );
       
   586         TPtr ptr2( buf2->Des() );
       
   587         table->ReadTextL(TPtrC( IAP_SERVICE_TYPE ), ptr2 );
       
   588 
       
   589         // Dump information to log
       
   590         // 
       
   591         MPMLOGSTRING3( "IAP %i: Name = %S", iapId, &ptr1 )
       
   592         MPMLOGSTRING2( "Service type = %S", &ptr2 )
       
   593 
       
   594         MPMLOGSTRING( "" )
       
   595         
       
   596         err = table->GotoNextRecord();
       
   597 
       
   598         CleanupStack::PopAndDestroy( buf2 );
       
   599         CleanupStack::PopAndDestroy( buf1 );
       
   600         }
       
   601 
       
   602     MPMLOGSTRING( "Display CommsDat IAPs - End" )
       
   603 
       
   604     CleanupStack::PopAndDestroy( table );
       
   605     CleanupStack::PopAndDestroy( commsDatabase );
       
   606 #endif // _DEBUG
       
   607     }
       
   608 
       
   609 
       
   610 // -----------------------------------------------------------------------------
       
   611 // CMPMCommsDatAccess::DumpSnapsL
       
   612 // -----------------------------------------------------------------------------
       
   613 //
       
   614 void CMPMCommsDatAccess::DumpSnapsL()
       
   615     {
       
   616 #ifdef _DEBUG
       
   617 
       
   618     // Dump CommsDat Snaps to log in order to support testing
       
   619     // 
       
   620     MPMLOGSTRING( "Display CommsDat Snaps - Start" )
       
   621     MPMLOGSTRING( "" )
       
   622 
       
   623     // Creating a session with the latest version
       
   624     // 
       
   625     CMDBSession* db = CMDBSession::NewLC( KCDVersion1_1 );
       
   626 
       
   627     db->SetAttributeMask( ECDHidden | ECDProtectedWrite );
       
   628 
       
   629     // Create the generic record set
       
   630     // 
       
   631     CMDBGenericRecord* generic = static_cast<CMDBGenericRecord*>
       
   632         ( CCDRecordBase::RecordFactoryL( 0 ) ); 
       
   633     CleanupStack::PushL( generic );  
       
   634     generic->InitializeL( TPtrC( KCDTypeNameDataMobilitySelectionPolicy ), 
       
   635                           NULL );
       
   636     generic->LoadL( *db );
       
   637 
       
   638     // Create the DN-IAP record set
       
   639     // 
       
   640     CMDBRecordSet<CCDDataMobilitySelectionPolicyRecord>* dnIAPRecordSet = 
       
   641         new ( ELeave ) CMDBRecordSet<CCDDataMobilitySelectionPolicyRecord>( 
       
   642         generic->TableId() );
       
   643     CleanupStack::PushL( dnIAPRecordSet ); 
       
   644 
       
   645     CCDDataMobilitySelectionPolicyRecord* dnIAPRecord = new ( ELeave ) 
       
   646         CCDDataMobilitySelectionPolicyRecord( generic->TableId() );
       
   647     CleanupStack::PushL( dnIAPRecord );
       
   648 
       
   649     // Find all the DN-IAP records
       
   650     // 
       
   651     dnIAPRecordSet->LoadL( *db );
       
   652 
       
   653     CCDIAPRecord*       linkedIAP;
       
   654     //CCDNetworkRecord*   linkedDN;
       
   655     //CCDNetworkRecord*   linkedDN2;
       
   656     CCDAccessPointRecord*   linkedAP;
       
   657     CCDAccessPointRecord*   linkedAP2;
       
   658     RArray<TInt>        prevRecordIds;
       
   659     CleanupClosePushL( prevRecordIds );
       
   660 
       
   661     for ( TInt i = 0; i < dnIAPRecordSet->iRecords.Count(); i++ )
       
   662         {
       
   663         // Load each DN-IAP entry based on the elementId in the record set
       
   664         // 
       
   665         dnIAPRecord->SetElementId( GetRealElementId( dnIAPRecordSet->iRecords[i] ) );
       
   666         dnIAPRecord->LoadL( *db );
       
   667 
       
   668 
       
   669         linkedAP =  static_cast<CCDAccessPointRecord*>( CCDAccessPointRecord::RecordFactoryL( KCDTIdAccessPointRecord ) );
       
   670         CleanupStack::PushL( linkedAP );
       
   671 
       
   672         // Find the SNAP AP pointed by DN-IAP entry
       
   673         //
       
   674         linkedAP->iRecordTag = (TInt)dnIAPRecord->iSNAP;
       
   675         TBool found = linkedAP->FindL( *db );
       
   676 
       
   677         // Don't print duplicates
       
   678         // 
       
   679         if ( found && KErrNotFound == prevRecordIds.Find( linkedAP->RecordId() ) )
       
   680             {
       
   681             prevRecordIds.Append( linkedAP->RecordId() );
       
   682             
       
   683             // Print the DN and host name pointed by DN-IAP entry.
       
   684             // HostName is EText field.
       
   685             // 
       
   686             TBuf<KCommsDatTextBufferLength> dn = linkedAP->iRecordName.GetL();
       
   687             MPMLOGSTRING3( "Snap: %d Snap Name = %s", (TInt)linkedAP->iRecordTag, dn.PtrZ() )
       
   688             
       
   689             // Related DN-IAP records 
       
   690             // Get the table id from generic record
       
   691             // 
       
   692             CMDBGenericRecord* generic2 = static_cast<CMDBGenericRecord*>
       
   693                 ( CCDRecordBase::RecordFactoryL( 0 ) ); 
       
   694             CleanupStack::PushL( generic2 );  
       
   695             generic2->InitializeL( TPtrC( 
       
   696                 KCDTypeNameDataMobilitySelectionPolicy ), NULL );
       
   697             generic2->LoadL( *db );
       
   698             
       
   699             // Doesn't quite work with generic records
       
   700             // 
       
   701             CMDBRecordSet<CCDDataMobilitySelectionPolicyRecord>* 
       
   702                 dnIAPRecordSet2 = new ( ELeave ) 
       
   703                 CMDBRecordSet<CCDDataMobilitySelectionPolicyRecord>( 
       
   704                 generic2->TableId() );
       
   705             CleanupStack::PushL( dnIAPRecordSet2 ); 
       
   706             
       
   707             // Prime one record with DN 
       
   708             // 
       
   709             CCDDataMobilitySelectionPolicyRecord* dnIAPRecord2 = 
       
   710                 new ( ELeave ) CCDDataMobilitySelectionPolicyRecord( 
       
   711                 generic2->TableId() );
       
   712             CleanupStack::PushL( dnIAPRecord2 );
       
   713             dnIAPRecord2->iSNAP = (TInt)linkedAP->iRecordTag;
       
   714             dnIAPRecordSet2->iRecords.Append( dnIAPRecord2 );
       
   715             CleanupStack::Pop( dnIAPRecord2 );
       
   716 
       
   717             if ( dnIAPRecordSet2->FindL( *db ) )
       
   718                 {
       
   719                 for (TInt j = 0; j < dnIAPRecordSet2->iRecords.Count(); j++)
       
   720                     {
       
   721                     dnIAPRecord2->SetElementId( GetRealElementId( dnIAPRecordSet2->iRecords[j] ) );
       
   722                     dnIAPRecord2->LoadL( *db );
       
   723 
       
   724                     if ( dnIAPRecord2->iIAP != 0 )
       
   725                         {
       
   726                         linkedIAP = static_cast<CCDIAPRecord*>
       
   727                             ( LoadLinkedRecordL( *db, dnIAPRecord2->iIAP ) );
       
   728                         MPMLOGSTRING3( "IAP = %d Priority = %d", 
       
   729                             linkedIAP->RecordId(), 
       
   730                             static_cast<TUint32>( dnIAPRecord2->iPriority ) )
       
   731                         delete linkedIAP;
       
   732                         dnIAPRecord2->iIAP = 0;
       
   733                         }
       
   734                     else if( dnIAPRecord2->iEmbeddedSNAP != 0 )
       
   735                         {
       
   736                         linkedAP2 =  static_cast<CCDAccessPointRecord*>( 
       
   737                                 CCDAccessPointRecord::RecordFactoryL( KCDTIdAccessPointRecord ) );
       
   738                         CleanupStack::PushL( linkedAP2 );
       
   739                         TInt esnap = dnIAPRecord2->iEmbeddedSNAP;
       
   740                         linkedAP2->iRecordTag = esnap;
       
   741                         if ( !linkedAP->FindL( *db ))
       
   742                             {
       
   743                             User::Leave( KErrNotFound );
       
   744                             }
       
   745                         
       
   746                         MPMLOGSTRING3( "Embedded Snap = %d Priority = %d", 
       
   747                             (TInt)linkedAP2->iRecordTag, 
       
   748                             static_cast<TUint32>( dnIAPRecord2->iPriority ) )
       
   749                         CleanupStack::PopAndDestroy( linkedAP2 );
       
   750                         dnIAPRecord2->iEmbeddedSNAP = 0;
       
   751                         }
       
   752                     else
       
   753                         {
       
   754                         // Each Snap has an initial entry in this table,
       
   755                         // where both the IAP and EmbeddedSNAP links 
       
   756                         // have null value. 
       
   757                         }
       
   758                     }
       
   759                 }
       
   760             CleanupStack::PopAndDestroy( dnIAPRecordSet2 );
       
   761             CleanupStack::PopAndDestroy( generic2 );
       
   762             MPMLOGSTRING( "" )
       
   763             }
       
   764         CleanupStack::PopAndDestroy( linkedAP );
       
   765         }
       
   766 
       
   767     MPMLOGSTRING( "Display CommsDat Snaps - End" )
       
   768 
       
   769     CleanupStack::PopAndDestroy( &prevRecordIds );
       
   770     CleanupStack::PopAndDestroy( dnIAPRecord );
       
   771     CleanupStack::PopAndDestroy( dnIAPRecordSet );
       
   772     CleanupStack::PopAndDestroy( generic );
       
   773     CleanupStack::PopAndDestroy( db );
       
   774 #endif // _DEBUG
       
   775     }
       
   776 
       
   777 // -----------------------------------------------------------------------------
       
   778 // CMPMCommsDatAccess::DeterminePrioritiesL
       
   779 // -----------------------------------------------------------------------------
       
   780 //
       
   781 void CMPMCommsDatAccess::DeterminePrioritiesL( 
       
   782     RArray<TNetIap>&          aDNIaps, 
       
   783     const RAvailableIAPList&  aAvailableIAPList,
       
   784     CMPMServerSession&        aSession )
       
   785     {
       
   786     MPMLOGSTRING( "CMPMCommsDatAccess::DeterminePrioritiesL" )
       
   787 
       
   788     TBool useGlobalPriorities( EFalse );
       
   789 
       
   790     for( TInt i( 0 ); ( i < aDNIaps.Count() ) && !useGlobalPriorities; i++ )
       
   791         {
       
   792         if( aDNIaps[i].iRanking == 
       
   793             CMManager::KDataMobilitySelectionPolicyPriorityWildCard )
       
   794             {
       
   795             // If any of the IAPs in the array has wildcard priority, 
       
   796             // then global bearer priorities should be used. 
       
   797             //
       
   798             useGlobalPriorities = ETrue;
       
   799             }
       
   800         }
       
   801 
       
   802     if( !useGlobalPriorities )
       
   803         {
       
   804         // If not a single IAP in the array had wildcard priority, 
       
   805         // then local priorities defined by user should be used. 
       
   806         //
       
   807         return;
       
   808         }
       
   809 
       
   810     for( TInt i( 0 ); i < aDNIaps.Count() ; i++ )
       
   811         {
       
   812         MPMLOGSTRING2(
       
   813             "CMPMCommsDatAccess::DeterminePrioritiesL: IapId = %i \
       
   814 has wildcard priority", aDNIaps[i].iIapId )
       
   815 
       
   816         // Find out the real IAP Id and check 
       
   817         // the global bearer priority for that.
       
   818         // 
       
   819         TUint32 priority( KLowestPriority );
       
   820         TUint32 iapId;
       
   821         FindRealIapL( aDNIaps[i].iIapId, 
       
   822                       iapId, 
       
   823                       aAvailableIAPList,
       
   824                       aSession );
       
   825 
       
   826         GlobalBearerPriorityL( iapId, 
       
   827                                priority );
       
   828 
       
   829         aDNIaps[i].iGlobalPriority = priority;
       
   830 
       
   831         MPMLOGSTRING3(
       
   832             "CMPMCommsDatAccess::DeterminePrioritiesL: IapId = %i \
       
   833 has global priority: %i", aDNIaps[i].iIapId, priority )
       
   834         }
       
   835 
       
   836     // Finally, sort the array according to global bearer priorities. 
       
   837     // 
       
   838     aDNIaps.Sort( TNetIap::CompareGlobalAndLocalPriority );
       
   839     }
       
   840 
       
   841 
       
   842 // -----------------------------------------------------------------------------
       
   843 // CMPMCommsDatAccess::GlobalBearerPriorityL
       
   844 // -----------------------------------------------------------------------------
       
   845 //
       
   846 void CMPMCommsDatAccess::GlobalBearerPriorityL( const TUint32   aIapId,
       
   847                                                TUint32&        aPriority )
       
   848     {
       
   849     MPMLOGSTRING2( "CMPMCommsDatAccess::GlobalBearerPriorityL: IapId: %i", 
       
   850         aIapId )
       
   851 
       
   852     CMDBSession* db = CMDBSession::NewLC( KCDVersion1_1 );
       
   853 
       
   854     db->SetAttributeMask( ECDHidden | ECDProtectedWrite );
       
   855 
       
   856     // Get the IAP record
       
   857     // 
       
   858     CCDIAPRecord* iap = LoadIapRecordLC( aIapId, db );
       
   859 
       
   860     // Get the service type of aIapId
       
   861     // 
       
   862     TBuf<KMaxTextLength + 1> service;
       
   863     service = iap->iServiceType.GetL();
       
   864     MPMLOGSTRING2(
       
   865         "CMPMCommsDatAccess::GlobalBearerPriorityL: Service type = %s",
       
   866         service.PtrZ() )
       
   867 
       
   868     // Get the table id from generic
       
   869     // 
       
   870     CMDBGenericRecord* record = static_cast<CMDBGenericRecord*>
       
   871         ( CCDRecordBase::RecordFactoryL( 0 ) );
       
   872     CleanupStack::PushL( record );
       
   873     record->InitializeL( TPtrC( KCDTypeNameGlobalService ), NULL );
       
   874     record->SetRecordId( KCDInitialRecordId );
       
   875     record->LoadL( *db );
       
   876 
       
   877     // Create Global Bearer Type Priorization Record
       
   878     // 
       
   879     CCDGlobalBearerTypePriorizationRecord* globalBearer = new ( ELeave ) 
       
   880         CCDGlobalBearerTypePriorizationRecord( record->TableId() );
       
   881     CleanupStack::PushL( globalBearer );
       
   882 
       
   883     // Set the service type of aIapId to Global 
       
   884     // Bearer Type Priorization Record
       
   885     // 
       
   886     globalBearer->iServiceType.SetL( service );
       
   887 
       
   888     if( globalBearer->FindL( *db ) )
       
   889         {
       
   890         // Get the priority of specified service type
       
   891         // 
       
   892         aPriority = ( TUint32 )globalBearer->iPriority;
       
   893         MPMLOGSTRING2(
       
   894             "CMPMCommsDatAccess::GlobalBearerPriorityL: Priority = %i", 
       
   895             aPriority )
       
   896         }
       
   897 
       
   898     // Release memory
       
   899     //
       
   900     CleanupStack::PopAndDestroy( globalBearer );
       
   901     CleanupStack::PopAndDestroy( record );
       
   902     CleanupStack::PopAndDestroy( iap );
       
   903     CleanupStack::PopAndDestroy( db );
       
   904     }
       
   905 
       
   906 // -----------------------------------------------------------------------------
       
   907 // CMPMCommsDatAccess::CheckWLANIapL
       
   908 // -----------------------------------------------------------------------------
       
   909 //
       
   910 void CMPMCommsDatAccess::CheckWLANIapL(CMPMServerSession& aSession)
       
   911     {
       
   912     MPMLOGSTRING( "CMPMCommsDatAccess::CheckWLANIapL" )
       
   913 
       
   914     TInt err( KErrNone );
       
   915     TBool found( EFalse );
       
   916 
       
   917     CCommsDatabase* commsDatabase = CCommsDatabase::NewL();
       
   918     CleanupStack::PushL( commsDatabase );
       
   919 
       
   920     // Make hidden records visible
       
   921     // 
       
   922     commsDatabase->ShowHiddenRecords();
       
   923 
       
   924     // Iterate the IAP table from CommsDat
       
   925     CCommsDbTableView* table = NULL;
       
   926     table = commsDatabase->OpenTableLC( TPtrC( IAP ) );
       
   927 
       
   928     err = table->GotoFirstRecord();
       
   929 
       
   930     while ( !err && !found )
       
   931         {
       
   932         TUint32 iapId( 0 );
       
   933         TInt    length( 0 );
       
   934 
       
   935         // Read IAP's ID
       
   936         //
       
   937         table->ReadUintL( TPtrC( COMMDB_ID ), iapId );
       
   938 
       
   939         // Read IAP's service type
       
   940         //
       
   941         table->ReadColumnLengthL(TPtrC( IAP_SERVICE_TYPE ), length );
       
   942         HBufC* buf = HBufC::NewLC( length );
       
   943         TPtr ptr( buf->Des() );
       
   944         table->ReadTextL(TPtrC( IAP_SERVICE_TYPE ), ptr );
       
   945 
       
   946         if ( ptr.Compare( TPtrC( LAN_SERVICE ) ) == KErrNone )
       
   947             {
       
   948             TUint32 service( 0 );
       
   949             table->ReadUintL( TPtrC( IAP_SERVICE ), service );
       
   950 
       
   951             // Now open a view to LAN_SERVICE table
       
   952             //
       
   953             CCommsDbTableView* commsDbLanTableView = 
       
   954                 commsDatabase->OpenViewMatchingUintLC( TPtrC( LAN_SERVICE ),
       
   955                                                        TPtrC( COMMDB_ID ),
       
   956                                                        service );
       
   957 
       
   958             User::LeaveIfError( commsDbLanTableView->GotoFirstRecord() );
       
   959 
       
   960             TUint32 commDbId( 0 );
       
   961 
       
   962             commsDbLanTableView->ReadUintL( TPtrC( COMMDB_ID ), commDbId );
       
   963 
       
   964             // Now open a view to WLAN_SERVICE table
       
   965             //
       
   966             // If non wlan product, wlan tables won't exist and this will 
       
   967             // leave. In that case do not check WLAN related issues 
       
   968             //
       
   969 
       
   970             CCommsDbTableView* commsDbWlanTableView( NULL );
       
   971             TRAP( err, commsDbWlanTableView = 
       
   972                          commsDatabase->OpenViewMatchingUintLC( 
       
   973                                                 TPtrC( WLAN_SERVICE ),
       
   974                                                 TPtrC( WLAN_SERVICE_ID ),
       
   975                                                 commDbId ); 
       
   976                          CleanupStack::Pop( commsDbWlanTableView ); );
       
   977             if ( err == KErrNone )
       
   978                 {
       
   979                 // Push back to cleanup stack. Object must be popped within 
       
   980                 // TRAP, to avoid unbalance in cleanup stack and panic 71
       
   981                 CleanupStack::PushL( commsDbWlanTableView );
       
   982                 
       
   983                 TInt error = commsDbWlanTableView->GotoFirstRecord();
       
   984 
       
   985                 if ( error == KErrNone )
       
   986                     {
       
   987                     // Easy WLAN is not considered to be "real" WLAN IAP
       
   988                     // 
       
   989                     TInt ssidLength( 0 );
       
   990                     commsDbWlanTableView->ReadColumnLengthL( 
       
   991                                                     TPtrC( NU_WLAN_SSID ), 
       
   992                                                     ssidLength );
       
   993                     if ( ssidLength != 0 )
       
   994                         {
       
   995                         found = ETrue;
       
   996 
       
   997                         MPMLOGSTRING( "CMPMCommsDatAccess::CheckWLANIapL:\
       
   998  Found WLAN IAP" )
       
   999 
       
  1000                         // If a single WLAN IAP was found in CommsDat, 
       
  1001                         // then set the need to scan WLAN networks as true.
       
  1002                         // 
       
  1003                         aSession.MyServer().SetWLANScanRequired( ETrue );
       
  1004                         }
       
  1005                     }
       
  1006 
       
  1007                 
       
  1008 
       
  1009                 // Release memory
       
  1010                 //
       
  1011                 CleanupStack::PopAndDestroy( commsDbWlanTableView );
       
  1012                 }
       
  1013             else
       
  1014                 {
       
  1015                 MPMLOGSTRING2(
       
  1016                             "CMPMCommsDatAccess::CheckWLANIapL: WLAN table view failed, err %d", err )
       
  1017                 }
       
  1018             CleanupStack::PopAndDestroy( commsDbLanTableView );
       
  1019             }
       
  1020         err = table->GotoNextRecord();
       
  1021 
       
  1022         CleanupStack::PopAndDestroy( buf );
       
  1023         }
       
  1024 
       
  1025     // If not a single WLAN IAP was found in CommsDat, 
       
  1026     // then set the need to scan WLAN networks as false.
       
  1027     // 
       
  1028     if ( !found )
       
  1029         {
       
  1030         MPMLOGSTRING( "CMPMCommsDatAccess::CheckWLANIapL: Not found WLAN IAP" )
       
  1031         aSession.MyServer().SetWLANScanRequired( EFalse );
       
  1032         }
       
  1033 
       
  1034     CleanupStack::PopAndDestroy( table );
       
  1035     CleanupStack::PopAndDestroy( commsDatabase );
       
  1036     }
       
  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 
       
  1349 // -----------------------------------------------------------------------------
       
  1350 // CMPMCommsDatAccess::CheckHiddenAgentL
       
  1351 // -----------------------------------------------------------------------------
       
  1352 //
       
  1353 TBool CMPMCommsDatAccess::CheckHiddenAgentL( const TUint32 aIapId ) const
       
  1354     {
       
  1355     MPMLOGSTRING2( "CMPMCommsDatAccess::CheckHiddenAgentL: IapId: %i", aIapId )
       
  1356 
       
  1357     TBool retValue( EFalse );
       
  1358 
       
  1359     CMDBSession* db = CMDBSession::NewLC( KCDVersion1_1 );
       
  1360 
       
  1361     db->SetAttributeMask( ECDHidden | ECDProtectedWrite );
       
  1362 
       
  1363     // First check that IAP exists
       
  1364     // 
       
  1365     CCDIAPRecord* iap = LoadIapRecordLC( aIapId, db );
       
  1366 
       
  1367     // Initialize generic record
       
  1368     // 
       
  1369     CMDBGenericRecord* generic = static_cast<CMDBGenericRecord*> ( 
       
  1370         CCDRecordBase::RecordFactoryL( 0 ) );
       
  1371     CleanupStack::PushL( generic );
       
  1372     generic->InitializeL( TPtrC( KCDTypeNameIAPMetadata ), NULL );
       
  1373     generic->LoadL( *db );
       
  1374 
       
  1375     CCDIAPMetadataRecord* record = new( ELeave ) CCDIAPMetadataRecord( 
       
  1376         generic->TableId() );
       
  1377     CleanupStack::PushL( record );
       
  1378 
       
  1379     // Check if the metadata entry exists
       
  1380     // 
       
  1381     record->iIAP.SetL( GetRealElementId( iap ) );
       
  1382     if ( record->FindL( *db ) )
       
  1383         {
       
  1384         // Metadata is specified, check is it true or false.
       
  1385         // 
       
  1386         if ( record->iMetadata & EMetaHiddenAgent )
       
  1387             {
       
  1388             MPMLOGSTRING( "CMPMCommsDatAccess::CheckHiddenAgentL: True" )
       
  1389             retValue = ETrue;
       
  1390             }
       
  1391         else
       
  1392             {
       
  1393             MPMLOGSTRING( "CMPMCommsDatAccess::CheckHiddenAgentL: False" )
       
  1394             retValue = EFalse;
       
  1395             }
       
  1396         }
       
  1397     else
       
  1398         {
       
  1399         // Metadata unspecified, use default value.
       
  1400         // 
       
  1401         MPMLOGSTRING( "CMPMCommsDatAccess::CheckHiddenAgentL: False" )
       
  1402         retValue = EFalse;
       
  1403         }
       
  1404 
       
  1405     // Release memory
       
  1406     //
       
  1407     CleanupStack::PopAndDestroy( record );
       
  1408     CleanupStack::PopAndDestroy( generic );
       
  1409     CleanupStack::PopAndDestroy( iap );
       
  1410     CleanupStack::PopAndDestroy( db );
       
  1411 
       
  1412     return retValue;
       
  1413     }
       
  1414 
       
  1415 
       
  1416 // -----------------------------------------------------------------------------
       
  1417 // CMPMCommsDatAccess::MatchSSIDL
       
  1418 // -----------------------------------------------------------------------------
       
  1419 //
       
  1420 void CMPMCommsDatAccess::MatchSSIDL( const TWlanSsid&   aSSID,
       
  1421                                      TUint32            aIapId, 
       
  1422                                      TBool&             aMatchFound,
       
  1423                                      CMPMServerSession& aSession )
       
  1424     {
       
  1425 #ifdef __WINS__    	
       
  1426     // To suppress compilation warning in WINSCW UREL build. aSession is used only for logging. 
       
  1427     aSession;
       
  1428 #endif
       
  1429     
       
  1430     MPMLOGSSID( "CMPMCommsDatAccess<0x%x>::MatchSSIDL: aSSID = %S", 
       
  1431         aSession.ConnectionId(), &aSSID )
       
  1432 
       
  1433     MPMLOGSTRING3( "CMPMCommsDatAccess<0x%x>::MatchSSIDL: aIapId = %d", 
       
  1434         aSession.ConnectionId(), aIapId )
       
  1435 
       
  1436     aMatchFound = EFalse;
       
  1437 
       
  1438     CCommsDatabase* commsDatabase = CCommsDatabase::NewL();
       
  1439     CleanupStack::PushL( commsDatabase );
       
  1440 
       
  1441     // Make hidden records visible
       
  1442     // 
       
  1443     commsDatabase->ShowHiddenRecords();
       
  1444 
       
  1445     CCommsDbTableView* commsDbIapTableView = 
       
  1446         commsDatabase->OpenViewMatchingUintLC( TPtrC( IAP ),
       
  1447                                                TPtrC( COMMDB_ID ),
       
  1448                                                aIapId );
       
  1449 
       
  1450     User::LeaveIfError( commsDbIapTableView->GotoFirstRecord() );
       
  1451 
       
  1452     TInt length1( 0 );
       
  1453 
       
  1454     commsDbIapTableView->ReadColumnLengthL( TPtrC( IAP_SERVICE_TYPE ), 
       
  1455                                             length1 );
       
  1456     HBufC* buf1 = HBufC::NewLC( length1 );
       
  1457     TPtr ptr1( buf1->Des() );
       
  1458 
       
  1459     // Read IAP's service type
       
  1460     //
       
  1461     commsDbIapTableView->ReadTextL(TPtrC( IAP_SERVICE_TYPE ), ptr1 );
       
  1462 
       
  1463     MPMLOGSTRING3(
       
  1464         "CMPMCommsDatAccess<0x%x>::MatchSSIDL: IAP service type = %S",
       
  1465         aSession.ConnectionId(), &ptr1 )
       
  1466 
       
  1467     // In case offline mode is enabled, we need to find out what type 
       
  1468     // of bearer is used. Only LAN or WLAN is allowed in offline mode.
       
  1469     // 
       
  1470     if ( ptr1.Compare( TPtrC( LAN_SERVICE ) ) == KErrNone )
       
  1471         {
       
  1472         TUint32 service( 0 );
       
  1473         commsDbIapTableView->ReadUintL( TPtrC( IAP_SERVICE ), service );
       
  1474 
       
  1475         // Now open a view to LAN_SERVICE table
       
  1476         //
       
  1477         CCommsDbTableView* commsDbLanTableView = 
       
  1478             commsDatabase->OpenViewMatchingUintLC( TPtrC( LAN_SERVICE ),
       
  1479                                                    TPtrC( COMMDB_ID ),
       
  1480                                                    service );
       
  1481 
       
  1482         User::LeaveIfError( commsDbLanTableView->GotoFirstRecord() );
       
  1483 
       
  1484         TUint32 commDbId( 0 );
       
  1485 
       
  1486         commsDbLanTableView->ReadUintL( TPtrC( COMMDB_ID ), commDbId );
       
  1487 
       
  1488         // Now open a view to WLAN_SERVICE table
       
  1489         //
       
  1490         CCommsDbTableView* commsDbWlanTableView = 
       
  1491             commsDatabase->OpenViewMatchingUintLC( TPtrC( WLAN_SERVICE ),
       
  1492                                                    TPtrC( WLAN_SERVICE_ID ),
       
  1493                                                    commDbId );
       
  1494 
       
  1495         TInt err = commsDbWlanTableView->GotoFirstRecord();
       
  1496 
       
  1497         if ( err == KErrNone )
       
  1498             {
       
  1499             TWlanSsid ssid;
       
  1500             commsDbWlanTableView->ReadTextL( TPtrC( NU_WLAN_SSID ), ssid );
       
  1501 
       
  1502             if ( aSSID.Compare( ssid ) == KErrNone )
       
  1503                 {
       
  1504                 aMatchFound = ETrue;
       
  1505                 MPMLOGSTRING2(
       
  1506                     "CMPMCommsDatAccess<0x%x>::MatchSSIDL Found matching SSID",
       
  1507                     aSession.ConnectionId() )
       
  1508                 }
       
  1509             }
       
  1510         else
       
  1511             {
       
  1512             MPMLOGSTRING3( "CMPMCommsDatAccess<0x%x>::MatchSSID\
       
  1513  GotoFirstRecord returned %d", aSession.ConnectionId(), err )
       
  1514             }
       
  1515 
       
  1516         // Release memory
       
  1517         //
       
  1518         CleanupStack::PopAndDestroy( commsDbWlanTableView );
       
  1519         CleanupStack::PopAndDestroy( commsDbLanTableView );
       
  1520         }
       
  1521 
       
  1522     // Release memory
       
  1523     //
       
  1524     CleanupStack::PopAndDestroy( buf1 );
       
  1525     CleanupStack::PopAndDestroy( commsDbIapTableView );
       
  1526     CleanupStack::PopAndDestroy( commsDatabase );
       
  1527     }
       
  1528 
       
  1529 
       
  1530 // -----------------------------------------------------------------------------
       
  1531 // CMPMCommsDatAccess::IsVirtualIapL
       
  1532 // -----------------------------------------------------------------------------
       
  1533 //
       
  1534 TBool CMPMCommsDatAccess::IsVirtualIapL( const TUint32 aVirtualIapId ) const
       
  1535     {
       
  1536     MPMLOGSTRING2( "CMPMCommsDatAccess::IsVirtualIapL: VirtualIapId: %i", 
       
  1537         aVirtualIapId )
       
  1538     TBool isVirtual( EFalse );
       
  1539 
       
  1540     // Open transaction
       
  1541     // 
       
  1542     CMDBSession* db = CMDBSession::NewLC( KCDVersion1_1 );
       
  1543 
       
  1544     db->SetAttributeMask( ECDHidden | ECDProtectedWrite );
       
  1545 
       
  1546     // Get IAP
       
  1547     // 
       
  1548     CCDIAPRecord* iap = LoadIapRecordLC( aVirtualIapId, db );
       
  1549 
       
  1550     TDesC& type = iap->iBearerType.GetL();
       
  1551 
       
  1552     if( type.Compare( TPtrC ( KCDTypeNameVirtualBearer ) ) == 0 )
       
  1553         {
       
  1554         isVirtual = ETrue;
       
  1555         MPMLOGSTRING( "CMPMCommsDatAccess::IsVirtualIapL: \
       
  1556 is virtual" )
       
  1557         }
       
  1558     CleanupStack::PopAndDestroy( iap );
       
  1559     CleanupStack::PopAndDestroy( db );
       
  1560     return isVirtual;
       
  1561     }
       
  1562     
       
  1563 // -----------------------------------------------------------------------------
       
  1564 // CMPMCommsDatAccess::SnapContainsWlanL
       
  1565 // -----------------------------------------------------------------------------
       
  1566 //
       
  1567 TBool CMPMCommsDatAccess::SnapContainsWlanL( TUint32			aSnapRecord, 
       
  1568                                              RArray<TUint>& 	aIapPath, 
       
  1569                                              TInt 		    	aMinNrWlan )
       
  1570     {
       
  1571     MPMLOGSTRING3( "CMPMCommsDatAccess::SnapContainsWlanL: snap %d, nr Wlans %d", 
       
  1572         aSnapRecord, aMinNrWlan )
       
  1573     TInt wlanFound(0);
       
  1574     RArray<TNetIap> destNetIaps;
       
  1575     CleanupClosePushL( destNetIaps );
       
  1576 
       
  1577     // Find the valid IAPs belonging to the Snap 
       
  1578     // and possible embedded SNAP. Store both in same array.
       
  1579     //
       
  1580     SearchDNEntriesWithEmbeddedL( aSnapRecord, destNetIaps, destNetIaps );
       
  1581 
       
  1582     // Check type of each IAP 
       
  1583     // Stop when specified number of WLAN IAPs has been found
       
  1584     // 
       
  1585     for( TInt j( 0 ); ( j < destNetIaps.Count() ) && 
       
  1586                       ( wlanFound < aMinNrWlan ); j++ )
       
  1587         {
       
  1588         // If entry is for embedded SNAP there are more than two chained 
       
  1589         // embedded snaps. This is illegal configuration. Skip this entry.
       
  1590         // 
       
  1591         if ( destNetIaps[j].iEmbeddedSnap != 0 )
       
  1592             {
       
  1593             MPMLOGSTRING( "CMPMCommsDatAccess::SnapContainsWlanL: \
       
  1594 Illegal configuration, more than one chained SNAP" )
       
  1595             }
       
  1596         else
       
  1597             {
       
  1598             if( CheckWlanL( destNetIaps[j].iIapId ) != ENotWlanIap )
       
  1599                 {
       
  1600                 MPMLOGSTRING(
       
  1601                     "CMPMCommsDatAccess::SnapContainsWlanL: WLAN IAP found" )
       
  1602                 wlanFound++;
       
  1603                 }
       
  1604             // If virtual IAP, check whether it may be using WLAN
       
  1605             // 
       
  1606             if( wlanFound < aMinNrWlan && IsVirtualIapL( destNetIaps[j].iIapId ) )
       
  1607                 {
       
  1608                 if ( WlanUnderVirtualL( destNetIaps[j].iIapId,
       
  1609                                         aIapPath ) )
       
  1610                     {
       
  1611                     MPMLOGSTRING( "CMPMCommsDatAccess::SnapContainsWlanL: \
       
  1612 WLAN IAP under virtual IAP found" )
       
  1613                     wlanFound++;
       
  1614                     }
       
  1615             
       
  1616                 }
       
  1617             }
       
  1618         }
       
  1619     CleanupStack::PopAndDestroy( &destNetIaps );
       
  1620     if( wlanFound < aMinNrWlan ) 
       
  1621         {
       
  1622         MPMLOGSTRING( "CMPMCommsDatAccess::SnapContainsWlanL: result false" )
       
  1623         return EFalse;
       
  1624         }
       
  1625     else
       
  1626         {
       
  1627         MPMLOGSTRING( "CMPMCommsDatAccess::SnapContainsWlanL: result true" )
       
  1628         return ETrue;
       
  1629         }
       
  1630     }
       
  1631 
       
  1632 
       
  1633 // -----------------------------------------------------------------------------
       
  1634 // CMPMCommsDatAccess::SearchDNEntriesWithEmbeddedL
       
  1635 // -----------------------------------------------------------------------------
       
  1636 //
       
  1637 void CMPMCommsDatAccess::SearchDNEntriesWithEmbeddedL( TUint32 aSnap, 
       
  1638                                                       RArray<TNetIap>& aDestNetIaps,
       
  1639                                                       RArray<TNetIap>& aEmbeddedIaps )
       
  1640     {
       
  1641     // Find the valid IAPs belonging to the Snap.
       
  1642     //
       
  1643     SearchDNEntriesL( aSnap, aDestNetIaps );
       
  1644 
       
  1645     TBool embeddedFound( EFalse );
       
  1646 
       
  1647     // Find the valid IAPs belonging to the embedded Snaps.
       
  1648     // 
       
  1649     for( TInt j = 0;( ( j < aDestNetIaps.Count() ) && !embeddedFound ); j++ )
       
  1650         {
       
  1651         // Go through the destNetIaps-array looking for EmbeddedId.
       
  1652         // 
       
  1653         if( aDestNetIaps[j].iEmbeddedSnap != 0 )
       
  1654             {
       
  1655             MPMLOGSTRING2( "CMPMCommsDatAccess::SearchDNEntriesWithEmbeddedL: \
       
  1656 Search Embedded SNAP: %i", aDestNetIaps[j].iEmbeddedSnap )
       
  1657 
       
  1658             TUint32 embedded = aDestNetIaps[j].iEmbeddedSnap;
       
  1659             // Exclude embedded Snap from destNetIaps, since 
       
  1660             // the IAPs it contains are listed in embeddedIaps. 
       
  1661             // 
       
  1662             aDestNetIaps.Remove( j );
       
  1663 
       
  1664             // If found, then search the IAPs belonging 
       
  1665             // to that embedded Snap.
       
  1666             // 
       
  1667             SearchDNEntriesL( embedded, aEmbeddedIaps );
       
  1668             embeddedFound = ETrue;
       
  1669             }
       
  1670         }
       
  1671     }
       
  1672 
       
  1673 
       
  1674 // -----------------------------------------------------------------------------
       
  1675 // CMPMCommsDatAccess::CheckWLanL
       
  1676 // -----------------------------------------------------------------------------
       
  1677 //
       
  1678 TWlanIapType CMPMCommsDatAccess::CheckWlanL( TUint32 aIapId ) const
       
  1679     {
       
  1680     MPMLOGSTRING2( "CMPMCommsDatAccess::CheckWlanL: IAP Id = %i", aIapId)
       
  1681 
       
  1682     TWlanIapType wlan( ENotWlanIap );
       
  1683     CCommsDatabase* commsDatabase = CCommsDatabase::NewL();
       
  1684     CleanupStack::PushL( commsDatabase );
       
  1685 
       
  1686     // Make hidden records visible
       
  1687     // 
       
  1688     commsDatabase->ShowHiddenRecords();
       
  1689 
       
  1690     CCommsDbTableView* commsDbIapTableView = 
       
  1691         commsDatabase->OpenViewMatchingUintLC( TPtrC( IAP ),
       
  1692                                                TPtrC( COMMDB_ID ),
       
  1693                                                aIapId );
       
  1694 
       
  1695     User::LeaveIfError( commsDbIapTableView->GotoFirstRecord() );
       
  1696 
       
  1697     TInt length1( 0 );
       
  1698 
       
  1699     commsDbIapTableView->ReadColumnLengthL( TPtrC( IAP_SERVICE_TYPE ), 
       
  1700                                             length1 );
       
  1701 
       
  1702     HBufC* buf1 = HBufC::NewLC( length1 );
       
  1703     TPtr ptr1( buf1->Des() );
       
  1704 
       
  1705     // Read IAP's service type
       
  1706     //
       
  1707     commsDbIapTableView->ReadTextL(TPtrC( IAP_SERVICE_TYPE ), ptr1 );
       
  1708     MPMLOGSTRING2(
       
  1709         "CMPMCommsDatAccess::CheckWlanL: IAP service type = %S", &ptr1 )
       
  1710 
       
  1711     if ( ptr1.Compare( TPtrC( LAN_SERVICE ) ) == KErrNone )
       
  1712         {
       
  1713         TUint32 service( 0 );
       
  1714         commsDbIapTableView->ReadUintL( TPtrC( IAP_SERVICE ), service );
       
  1715 
       
  1716         // Now open a view to LAN_SERVICE table
       
  1717         //
       
  1718         CCommsDbTableView* commsDbLanTableView = 
       
  1719             commsDatabase->OpenViewMatchingUintLC( TPtrC( LAN_SERVICE ),
       
  1720                                                    TPtrC( COMMDB_ID ),
       
  1721                                                    service );
       
  1722 
       
  1723         User::LeaveIfError( commsDbLanTableView->GotoFirstRecord() );
       
  1724 
       
  1725         TUint32 commDbId( 0 );
       
  1726 
       
  1727         commsDbLanTableView->ReadUintL( TPtrC( COMMDB_ID ), commDbId );
       
  1728 
       
  1729         // Now open a view to WLAN_SERVICE table
       
  1730         //
       
  1731         // If non wlan product, wlan tables won't exist and this will 
       
  1732         // leave. In that case do not check WLAN related issues 
       
  1733         //
       
  1734 
       
  1735         CCommsDbTableView* commsDbWlanTableView( NULL );
       
  1736         TRAPD( err2, commsDbWlanTableView = 
       
  1737                      commsDatabase->OpenViewMatchingUintLC( TPtrC( WLAN_SERVICE ),
       
  1738                                                             TPtrC( WLAN_SERVICE_ID ),
       
  1739                                                             commDbId );
       
  1740                      CleanupStack::Pop( commsDbWlanTableView ) );
       
  1741         if ( err2 == KErrNone )
       
  1742             {
       
  1743             // Push back to cleanup stack. Object must be popped within 
       
  1744             // TRAP, to avoid unbalance in cleanup stack and panic 71
       
  1745             CleanupStack::PushL( commsDbWlanTableView );
       
  1746 
       
  1747             TInt err = commsDbWlanTableView->GotoFirstRecord();
       
  1748 
       
  1749             if ( err == KErrNone )
       
  1750                 {
       
  1751                 MPMLOGSTRING( "CMPMCommsDatAccess::CheckWlanL: IAP is WLAN" )
       
  1752                 wlan = EWlanIap;
       
  1753                 TInt ssidLength( 0 );
       
  1754                 commsDbWlanTableView->ReadColumnLengthL( TPtrC( NU_WLAN_SSID ), 
       
  1755                                                      ssidLength );
       
  1756                 if ( ssidLength == 0 )
       
  1757                     {
       
  1758                     MPMLOGSTRING(
       
  1759                         "CMPMCommsDatAccess::CheckWlanL: IAP is Easy WLAN" )
       
  1760                     wlan = EEasyWlanIap;
       
  1761                     }
       
  1762                 }
       
  1763             else
       
  1764                 {
       
  1765                 MPMLOGSTRING2( "CMPMCommsDatAccess::CheckWlanL\
       
  1766  GotoFirstRecord returned %d", err )
       
  1767                }
       
  1768             // Release memory
       
  1769             //
       
  1770             CleanupStack::PopAndDestroy( commsDbWlanTableView );            
       
  1771             }
       
  1772         else
       
  1773             {
       
  1774             MPMLOGSTRING2(
       
  1775                         "CMPMCommsDatAccess::CheckWlanL: WLAN table view failed, err %d", err2 )
       
  1776             }                
       
  1777         CleanupStack::PopAndDestroy( commsDbLanTableView );
       
  1778         }
       
  1779 
       
  1780     // Release memory
       
  1781     //
       
  1782     CleanupStack::PopAndDestroy( buf1 );
       
  1783     CleanupStack::PopAndDestroy( commsDbIapTableView );
       
  1784     CleanupStack::PopAndDestroy( commsDatabase );
       
  1785 
       
  1786     return wlan;
       
  1787     }
       
  1788 
       
  1789 // -----------------------------------------------------------------------------
       
  1790 // CMPMCommsDatAccess::RemoveCategorisedIapsL
       
  1791 // -----------------------------------------------------------------------------
       
  1792 //
       
  1793 void CMPMCommsDatAccess::RemoveCategorisedIapsL( RAvailableIAPList& aIAPList )
       
  1794     {
       
  1795     MPMLOGSTRING( "CMPMCommsDatAccess::RemoveCategorisedIapsL" )
       
  1796 
       
  1797     // Creating a session with the latest version
       
  1798     // 
       
  1799     CMDBSession* db = CMDBSession::NewLC( KCDVersion1_1 );
       
  1800 
       
  1801     db->SetAttributeMask( ECDHidden | ECDProtectedWrite );
       
  1802 
       
  1803     // Create the generic record set
       
  1804     // 
       
  1805     CMDBGenericRecord* generic = static_cast<CMDBGenericRecord*>
       
  1806         ( CCDRecordBase::RecordFactoryL( 0 ) ); 
       
  1807     CleanupStack::PushL( generic );  
       
  1808     generic->InitializeL( TPtrC( KCDTypeNameDataMobilitySelectionPolicy ), 
       
  1809                           NULL );
       
  1810     generic->LoadL( *db );
       
  1811 
       
  1812     // Create the DN-IAP record set
       
  1813     // 
       
  1814     CMDBRecordSet<CCDDataMobilitySelectionPolicyRecord>* dnIAPRecordSet = 
       
  1815         new ( ELeave ) CMDBRecordSet<CCDDataMobilitySelectionPolicyRecord>( 
       
  1816         generic->TableId() );
       
  1817     CleanupStack::PushL( dnIAPRecordSet ); 
       
  1818 
       
  1819     CCDDataMobilitySelectionPolicyRecord* dnIAPRecord = new ( ELeave ) 
       
  1820         CCDDataMobilitySelectionPolicyRecord( generic->TableId() );
       
  1821     CleanupStack::PushL( dnIAPRecord );
       
  1822 
       
  1823     // Find all the DN-IAP records
       
  1824     // Trap leave in case no records exist
       
  1825     // 
       
  1826     TRAPD( err, dnIAPRecordSet->LoadL( *db ) )
       
  1827     if( err != KErrNone )
       
  1828         {
       
  1829         // print error code to log
       
  1830         //
       
  1831         MPMLOGSTRING2( "CMPMCommsDatAccess::RemoveCategorisedIapsL, \
       
  1832 loading DM selection policy records failed with %d", err )
       
  1833         CleanupStack::PopAndDestroy( dnIAPRecord );
       
  1834         CleanupStack::PopAndDestroy( dnIAPRecordSet );
       
  1835         CleanupStack::PopAndDestroy( generic );
       
  1836         CleanupStack::PopAndDestroy( db );
       
  1837         return;
       
  1838         }
       
  1839 
       
  1840     CCDIAPRecord*           linkedIAP;
       
  1841     CCDAccessPointRecord*   linkedAP;
       
  1842     RArray<TInt>            prevRecordIds;
       
  1843     CleanupClosePushL( prevRecordIds );
       
  1844 
       
  1845     // prepare for searching APs.
       
  1846 
       
  1847     for ( TInt i = 0; i < dnIAPRecordSet->iRecords.Count(); i++ )
       
  1848         {
       
  1849         linkedAP =  static_cast<CCDAccessPointRecord*>( CCDAccessPointRecord::RecordFactoryL( KCDTIdAccessPointRecord ) );
       
  1850         CleanupStack::PushL( linkedAP );
       
  1851         // Load each DN-IAP entry based on the elementId in the record set
       
  1852         // 
       
  1853         dnIAPRecord->SetElementId( GetRealElementId( dnIAPRecordSet->iRecords[i] ) );
       
  1854         dnIAPRecord->LoadL( *db );
       
  1855 
       
  1856         // Find the SNAP AP pointed by DN-IAP entry
       
  1857         //
       
  1858         linkedAP->iRecordTag = (TInt)dnIAPRecord->iSNAP;
       
  1859         TBool found = linkedAP->FindL( *db );
       
  1860 
       
  1861         if ( found && KErrNotFound == prevRecordIds.Find( linkedAP->RecordId() ) )
       
  1862             {
       
  1863             prevRecordIds.Append( linkedAP->RecordId() );
       
  1864             
       
  1865             // Print the DN and host name pointed by DN-IAP entry.
       
  1866             // HostName is EText field.
       
  1867             // 
       
  1868             TBuf<KMaxTextLength + 1> dn = linkedAP->iRecordName.GetL();
       
  1869             MPMLOGSTRING3( "    Snap: %d Snap Name = %s", (TInt)linkedAP->iRecordTag, dn.PtrZ() )
       
  1870             
       
  1871             // Related DN-IAP records 
       
  1872             // Get the table id from generic record
       
  1873             // 
       
  1874             CMDBGenericRecord* generic2 = static_cast<CMDBGenericRecord*>
       
  1875                 ( CCDRecordBase::RecordFactoryL( 0 ) ); 
       
  1876             CleanupStack::PushL( generic2 );  
       
  1877             generic2->InitializeL( TPtrC( 
       
  1878                 KCDTypeNameDataMobilitySelectionPolicy ), NULL );
       
  1879             generic2->LoadL( *db );
       
  1880             
       
  1881             // Doesn't quite work with generic records
       
  1882             // 
       
  1883             CMDBRecordSet<CCDDataMobilitySelectionPolicyRecord>* 
       
  1884                 dnIAPRecordSet2 = new ( ELeave ) 
       
  1885                 CMDBRecordSet<CCDDataMobilitySelectionPolicyRecord>( 
       
  1886                 generic2->TableId() );
       
  1887             CleanupStack::PushL( dnIAPRecordSet2 ); 
       
  1888             
       
  1889             // Prime one record with DN 
       
  1890             // 
       
  1891             CCDDataMobilitySelectionPolicyRecord* dnIAPRecord2 = 
       
  1892                 new ( ELeave ) CCDDataMobilitySelectionPolicyRecord( generic2->TableId() );
       
  1893             CleanupStack::PushL( dnIAPRecord2 );
       
  1894             dnIAPRecord2->iSNAP = (TInt)linkedAP->iRecordTag;
       
  1895             dnIAPRecordSet2->iRecords.Append( dnIAPRecord2 );
       
  1896             CleanupStack::Pop( dnIAPRecord2 );
       
  1897 
       
  1898             if ( dnIAPRecordSet2->FindL( *db ) )
       
  1899                 {
       
  1900                 for (TInt j = 0; j < dnIAPRecordSet2->iRecords.Count(); j++)
       
  1901                     {
       
  1902                     dnIAPRecord2->SetElementId( GetRealElementId( dnIAPRecordSet2->iRecords[j] ) );
       
  1903                     dnIAPRecord2->LoadL( *db );
       
  1904 
       
  1905                     if ( dnIAPRecord2->iIAP != 0 )
       
  1906                         {
       
  1907                         linkedIAP = static_cast<CCDIAPRecord*>
       
  1908                             ( LoadLinkedRecordL( *db, dnIAPRecord2->iIAP ) );
       
  1909 
       
  1910                         // Remove categorised IAP from aIAPList
       
  1911                         // 
       
  1912                         TInt index = KErrNotFound;
       
  1913                         index = aIAPList.Find( linkedIAP->RecordId() );
       
  1914                         if ( index != KErrNotFound )
       
  1915                             {
       
  1916                             MPMLOGSTRING2(
       
  1917                                 "        Remove categorised IAP = %i", 
       
  1918                                 linkedIAP->RecordId() )
       
  1919                             aIAPList.Remove( index );
       
  1920                             }
       
  1921 
       
  1922                         delete linkedIAP;
       
  1923                         dnIAPRecord2->iIAP = 0;
       
  1924                         }
       
  1925                     }
       
  1926                 }
       
  1927             CleanupStack::PopAndDestroy( dnIAPRecordSet2 );
       
  1928             CleanupStack::PopAndDestroy( generic2 );
       
  1929             }
       
  1930         CleanupStack::PopAndDestroy( linkedAP );
       
  1931         }
       
  1932 
       
  1933     CleanupStack::PopAndDestroy( &prevRecordIds );
       
  1934     CleanupStack::PopAndDestroy( dnIAPRecord );
       
  1935     CleanupStack::PopAndDestroy( dnIAPRecordSet );
       
  1936     CleanupStack::PopAndDestroy( generic );
       
  1937     CleanupStack::PopAndDestroy( db );
       
  1938     }
       
  1939 
       
  1940 // -----------------------------------------------------------------------------
       
  1941 // CMPMCommsDatAccess::GetIapServiceIdL
       
  1942 // -----------------------------------------------------------------------------
       
  1943 //
       
  1944 TUint32 CMPMCommsDatAccess::GetIapServiceIdL( TUint32 aIapId )
       
  1945     {
       
  1946     TUint32 serviceId( 0 );
       
  1947     CMDBSession* db = CMDBSession::NewLC( KCDVersion1_1 );
       
  1948 
       
  1949     db->SetAttributeMask( ECDHidden | ECDProtectedWrite );
       
  1950 
       
  1951     // First check that IAP exists
       
  1952     // 
       
  1953     CCDIAPRecord* iap = LoadIapRecordLC( aIapId, db );
       
  1954     serviceId = iap->iService;
       
  1955     CleanupStack::PopAndDestroy( iap );
       
  1956     CleanupStack::PopAndDestroy( db );
       
  1957 
       
  1958     MPMLOGSTRING3( "CMPMCommsDatAccess::GetiapServiceIdL - IAP Id: %d, service id: %d",     
       
  1959         aIapId, serviceId )
       
  1960 
       
  1961     return serviceId;
       
  1962     }
       
  1963 
       
  1964 // ============================= LOCAL FUNCTIONS ===============================
       
  1965 
       
  1966 // -----------------------------------------------------------------------------
       
  1967 // CMPMCommsDatAccess::LoadIapRecordLC
       
  1968 // -----------------------------------------------------------------------------
       
  1969 //
       
  1970 CCDIAPRecord* CMPMCommsDatAccess::LoadIapRecordLC( const TUint32 aIapId, CMDBSession* aDb ) const
       
  1971     {
       
  1972     CCDIAPRecord* iap = static_cast<CCDIAPRecord*> ( 
       
  1973         CCDRecordBase::RecordFactoryL( KCDTIdIAPRecord ) );
       
  1974     CleanupStack::PushL( iap );
       
  1975     iap->SetRecordId( aIapId );
       
  1976     iap->LoadL( *aDb );
       
  1977     return iap;    
       
  1978     }
       
  1979 
       
  1980 // -----------------------------------------------------------------------------
       
  1981 // CMPMCommsDatAccess::SearchAccessNetIdL
       
  1982 // -----------------------------------------------------------------------------
       
  1983 //
       
  1984 void CMPMCommsDatAccess::SearchAccessNetIdL( const TUint32&  aIapId,
       
  1985                                             TUint32&        aNetId )
       
  1986     {
       
  1987     MPMLOGSTRING2( "CMPMCommsDatAccess::SearchAccessNetIdL - IAP Id: %d", 
       
  1988         aIapId )
       
  1989 
       
  1990     CCommsDatabase* commsDatabase = CCommsDatabase::NewL();
       
  1991     CleanupStack::PushL(commsDatabase);
       
  1992 
       
  1993     // Make hidden records visible
       
  1994     // 
       
  1995     commsDatabase->ShowHiddenRecords();
       
  1996 
       
  1997     // Open IAP table view by matching IAP Id
       
  1998     //
       
  1999     CCommsDbTableView* commsDbTableView = 
       
  2000         commsDatabase->OpenViewMatchingUintLC( TPtrC( IAP ),
       
  2001                                                TPtrC( COMMDB_ID ),
       
  2002                                                aIapId );
       
  2003 
       
  2004     User::LeaveIfError( commsDbTableView->GotoFirstRecord() );
       
  2005 
       
  2006     commsDbTableView->ReadUintL(TPtrC( IAP_NETWORK ), aNetId );
       
  2007     MPMLOGSTRING2(
       
  2008         "CMPMCommsDatAccess::SearchAccessNetIdL - Found Access NetId: %d", 
       
  2009         aNetId )
       
  2010 
       
  2011     CleanupStack::PopAndDestroy(commsDbTableView);
       
  2012     CleanupStack::PopAndDestroy(commsDatabase);
       
  2013     }
       
  2014 
       
  2015 // -----------------------------------------------------------------------------
       
  2016 // CMPMCommsDatAccess::WlanUnderVirtualL
       
  2017 // -----------------------------------------------------------------------------
       
  2018 //
       
  2019 TBool CMPMCommsDatAccess::WlanUnderVirtualL( const TUint32  aVirtualIapId, 
       
  2020                                              RArray<TUint>& aIapPath )
       
  2021     {
       
  2022     MPMLOGSTRING2( "CMPMCommsDatAccess::WlanUnderVirtualL: VirtualIapId: %i", 
       
  2023         aVirtualIapId )
       
  2024     // Check that this Iap has not already traversed
       
  2025     //
       
  2026     if( aIapPath.Find( aVirtualIapId ) == KErrNotFound )
       
  2027         {
       
  2028         // append this Iap to path
       
  2029         //
       
  2030         aIapPath.Append( aVirtualIapId );
       
  2031         }
       
  2032     else
       
  2033         {
       
  2034         MPMLOGSTRING( "CMPMCommsDatAccess::WlanUnderVirtualL: Error, loop\
       
  2035 detected in configuration. Iap handling not continued" )
       
  2036         return EFalse;
       
  2037         }
       
  2038 
       
  2039     TBool wlan( EFalse );
       
  2040 
       
  2041     // Open session
       
  2042     // 
       
  2043     CMDBSession* db = CMDBSession::NewLC( KCDVersion1_1 );
       
  2044 
       
  2045     db->SetAttributeMask( ECDHidden | ECDProtectedWrite );
       
  2046 
       
  2047     CMDBGenericRecord * generic = static_cast<CMDBGenericRecord*>
       
  2048         ( CCDRecordBase::RecordFactoryL( 0 ) );
       
  2049     CleanupStack::PushL( generic );
       
  2050     generic->InitializeL( TPtrC( KCDTypeNameVirtualIAPNextLayer ), 
       
  2051                           NULL );
       
  2052     generic->LoadL( *db );
       
  2053 
       
  2054     CCDVirtualIAPNextLayerRecord* virtualNext = new ( ELeave ) 
       
  2055         CCDVirtualIAPNextLayerRecord( generic->TableId() );
       
  2056 
       
  2057     CleanupStack::PushL( virtualNext );
       
  2058     virtualNext->iIAP = aVirtualIapId;
       
  2059     if ( virtualNext->FindL( *db ) )
       
  2060         {
       
  2061         if ( virtualNext->iNextLayerSNAP != 0 )
       
  2062             {
       
  2063             // SNAP
       
  2064             // 
       
  2065             TInt snap = virtualNext->iNextLayerSNAP;
       
  2066             MPMLOGSTRING2(
       
  2067                 "CMPMCommsDatAccess::WlanUnderVirtualL: SNAP: %i", snap )
       
  2068 
       
  2069             // Check if SNAP contains WLAN
       
  2070             // 
       
  2071             wlan = SnapContainsWlanL( snap, aIapPath, KMPMNrWlansOne );
       
  2072             
       
  2073             }
       
  2074         else if ( virtualNext->iNextLayerIAP != 0 )
       
  2075             {
       
  2076             // IAP
       
  2077             // 
       
  2078             TInt iap = virtualNext->iNextLayerIAP;
       
  2079             MPMLOGSTRING2(
       
  2080                 "CMPMCommsDatAccess::WlanUnderVirtualL: IAP: %i", iap )
       
  2081             if( CheckWlanL( iap ) != ENotWlanIap )
       
  2082                 {
       
  2083                 wlan = ETrue;
       
  2084                 }
       
  2085         
       
  2086             // If virtual IAP, check whether it may be using WLAN
       
  2087             // 
       
  2088             if( !wlan && IsVirtualIapL( iap ) )
       
  2089                 {
       
  2090                 wlan = WlanUnderVirtualL( iap, aIapPath );
       
  2091                 }
       
  2092             }
       
  2093         else
       
  2094             {
       
  2095             MPMLOGSTRING( "CMPMCommsDatAccess::WlanUnderVirtualL: No underlying IAP\
       
  2096  defined for virtual IapId" )
       
  2097             }
       
  2098         }
       
  2099     // Remove this Iap from path 
       
  2100     //
       
  2101     MPMLOGSTRING2( "CMPMCommsDatAccess::WlanUnderVirtualL: removing %d from iap path", 
       
  2102                 aIapPath.Count() - 1 )
       
  2103     aIapPath.Remove( aIapPath.Count() - 1 );
       
  2104 
       
  2105     // Release memory
       
  2106     //
       
  2107     CleanupStack::PopAndDestroy( virtualNext );
       
  2108     CleanupStack::PopAndDestroy( generic );
       
  2109     CleanupStack::PopAndDestroy( db );
       
  2110     MPMLOGSTRING2(
       
  2111                 "CMPMCommsDatAccess::WlanUnderVirtualL: found: %i", wlan )
       
  2112     return wlan;
       
  2113     }
       
  2114 
       
  2115 // -----------------------------------------------------------------------------
       
  2116 // CMPMCommsDatAccess::SearchDNEntriesL
       
  2117 // -----------------------------------------------------------------------------
       
  2118 //
       
  2119 void CMPMCommsDatAccess::SearchDNEntriesL( const TUint32&   aSnapId,
       
  2120                                            RArray<TNetIap>& aDestNetIds )
       
  2121     {
       
  2122     MPMLOGSTRING2( "CMPMCommsDatAccess::SearchDNEntriesL: SNAP: %d", 
       
  2123         aSnapId )
       
  2124 
       
  2125     CCDAccessPointRecord* snapAPr =  static_cast<CCDAccessPointRecord*>( 
       
  2126             CCDAccessPointRecord::RecordFactoryL( KCDTIdAccessPointRecord ) );
       
  2127     
       
  2128     snapAPr->iRecordTag = aSnapId;
       
  2129     CleanupStack::PushL( snapAPr );
       
  2130 
       
  2131 //    CCDNetworkRecord* dnRecord = static_cast<CCDNetworkRecord*>
       
  2132 //        ( CCDRecordBase::RecordFactoryL( KCDTIdNetworkRecord ) );
       
  2133 //        dnRecord->SetRecordId( aSnapId );
       
  2134 
       
  2135     CMDBSession* db = CMDBSession::NewLC( KCDVersion1_1 );
       
  2136 
       
  2137     db->SetAttributeMask( ECDHidden | ECDProtectedWrite );
       
  2138 
       
  2139 //    TRAPD( err, snapAPr->LoadL( *db ) );
       
  2140 //    if ( err != KErrNone )
       
  2141     if ( !snapAPr->FindL( *db ) )
       
  2142         {
       
  2143         MPMLOGSTRING("CMPMCommsDatAccess::SearchDNEntriesL: SNAP not found")
       
  2144         CleanupStack::PopAndDestroy( db );
       
  2145         CleanupStack::PopAndDestroy( snapAPr );
       
  2146         return;
       
  2147         }
       
  2148 
       
  2149     // Get the table id from generic
       
  2150     // 
       
  2151     CMDBGenericRecord* generic = static_cast<CMDBGenericRecord*>
       
  2152         ( CCDRecordBase::RecordFactoryL( 0 ) );
       
  2153     CleanupStack::PushL( generic );
       
  2154     generic->InitializeL( TPtrC( KCDTypeNameDataMobilitySelectionPolicy ), 
       
  2155                           NULL );
       
  2156     generic->LoadL( *db );
       
  2157 
       
  2158     // Create the DN-IAP record set
       
  2159     // 
       
  2160     CMDBRecordSet<CCDDataMobilitySelectionPolicyRecord>* dnIAPRecordSet = 
       
  2161         new ( ELeave ) CMDBRecordSet<CCDDataMobilitySelectionPolicyRecord>( generic->TableId() );
       
  2162     CleanupStack::PushL( dnIAPRecordSet );
       
  2163 
       
  2164     CCDDataMobilitySelectionPolicyRecord* dnIAPRecord = new ( ELeave ) 
       
  2165         CCDDataMobilitySelectionPolicyRecord( generic->TableId() );
       
  2166     CleanupStack::PushL( dnIAPRecord );
       
  2167     dnIAPRecord->iSNAP = (TInt)snapAPr->iRecordTag;
       
  2168     dnIAPRecordSet->iRecords.Append( dnIAPRecord );
       
  2169     CleanupStack::Pop( dnIAPRecord );
       
  2170 
       
  2171     if ( dnIAPRecordSet->FindL( *db ) )
       
  2172         {
       
  2173         for ( TInt i = 0; i < dnIAPRecordSet->iRecords.Count(); i++ )
       
  2174             {
       
  2175             TNetIap elem;
       
  2176             dnIAPRecord->SetElementId( GetRealElementId( dnIAPRecordSet->iRecords[i] ) );
       
  2177             dnIAPRecord->LoadL( *db );
       
  2178 
       
  2179             if ( dnIAPRecord->iIAP != 0 )
       
  2180                 {
       
  2181                 // Add values to elem
       
  2182                 // 
       
  2183                 TUint32 iapElementId( dnIAPRecord->iIAP ); 
       
  2184                 elem.iSnap      = aSnapId;
       
  2185                 elem.iIapId     = ( iapElementId & 
       
  2186                                     KCDMaskShowRecordId ) >> KShift8;
       
  2187                 elem.iRanking   = static_cast<TUint32>( dnIAPRecord->iPriority );
       
  2188                 dnIAPRecord->iIAP = 0;
       
  2189                 }
       
  2190             else if( dnIAPRecord->iEmbeddedSNAP != 0 )
       
  2191                 {
       
  2192                 // Add values to elem
       
  2193                 // 
       
  2194                 elem.iSnap          = aSnapId;
       
  2195                 elem.iEmbeddedSnap  = dnIAPRecord->iEmbeddedSNAP;
       
  2196                 elem.iRanking       = static_cast<TUint32>( dnIAPRecord->iPriority );
       
  2197                 dnIAPRecord->iEmbeddedSNAP = 0;
       
  2198                 }
       
  2199             else
       
  2200                 {
       
  2201                 // Each Snap has an initial entry in this table,
       
  2202                 // where both the IAP and EmbeddedSNAP links 
       
  2203                 // have null value. 
       
  2204                 }
       
  2205 
       
  2206             // MPM should treat IAPs with Network Weight zero as the deleted 
       
  2207             // ones. If an IAP seems to belong to a group but it has weight 
       
  2208             // zero, it means that the IAP is not actually added to the group 
       
  2209             // but an IAP from that group is deleted and a new one is created 
       
  2210             // and this new IAP has got the same access network id that used 
       
  2211             // to belong to the deleted IAP.
       
  2212             // 
       
  2213             if ( elem.iRanking > 0 )
       
  2214                 {
       
  2215                 // Insert elem into RArray
       
  2216                 // 
       
  2217                 aDestNetIds.InsertInOrderAllowRepeats(elem, TNetIap::CompareRanking);
       
  2218                 }
       
  2219             else
       
  2220                 {
       
  2221                 if ( elem.iIapId != 0 )
       
  2222                     {
       
  2223                     MPMLOGSTRING2( "CMPMCommsDatAccess::SearchDNEntriesL: \
       
  2224 IapId %i removed because ranking is zero", elem.iIapId )
       
  2225                     }
       
  2226                 if ( elem.iEmbeddedSnap != 0 )
       
  2227                     {
       
  2228                     MPMLOGSTRING2( "CMPMCommsDatAccess::SearchDNEntriesL: \
       
  2229 EmbeddedSnap %i removed because ranking is zero", elem.iEmbeddedSnap )
       
  2230                     }
       
  2231                 }
       
  2232             }
       
  2233         }
       
  2234 
       
  2235     // Release memory
       
  2236     //
       
  2237     CleanupStack::PopAndDestroy( dnIAPRecordSet );
       
  2238     CleanupStack::PopAndDestroy( generic );
       
  2239     CleanupStack::PopAndDestroy( db );
       
  2240     CleanupStack::PopAndDestroy( snapAPr );
       
  2241 
       
  2242 #ifdef _DEBUG
       
  2243     // Print info into the log file
       
  2244     //
       
  2245     for ( TInt j = 0; j < aDestNetIds.Count(); j++ )
       
  2246         {
       
  2247         MPMLOGSTRING2(
       
  2248             "CMPMCommsDatAccess::SearchDNEntriesL: SNAP to array     = %i", 
       
  2249             aDestNetIds[j].iSnap )
       
  2250         MPMLOGSTRING2(
       
  2251             "CMPMCommsDatAccess::SearchDNEntriesL: Embedded to array = %i", 
       
  2252             aDestNetIds[j].iEmbeddedSnap )
       
  2253         MPMLOGSTRING2(
       
  2254             "CMPMCommsDatAccess::SearchDNEntriesL: IapId to array    = %i", 
       
  2255             aDestNetIds[j].iIapId )
       
  2256         MPMLOGSTRING2(
       
  2257             "CMPMCommsDatAccess::SearchDNEntriesL: Ranking to array  = %i", 
       
  2258             aDestNetIds[j].iRanking )
       
  2259         }
       
  2260 #endif // _DEBUG
       
  2261     }
       
  2262 
       
  2263 // -----------------------------------------------------------------------------
       
  2264 // CMPMCommsDatAccess::FindRealIapL
       
  2265 // -----------------------------------------------------------------------------
       
  2266 //
       
  2267 void CMPMCommsDatAccess::FindRealIapL( 
       
  2268     const TUint32               aVirtualIapId,
       
  2269     TUint32&                    aRealIapId, 
       
  2270     const RAvailableIAPList&    aAvailableIAPList,
       
  2271     CMPMServerSession&          aSession )
       
  2272     {
       
  2273     MPMLOGSTRING2( "CMPMCommsDatAccess::FindRealIapL: VirtualIapId: %i", 
       
  2274         aVirtualIapId )
       
  2275 
       
  2276     // Open transaction
       
  2277     // 
       
  2278     CMDBSession* db = CMDBSession::NewLC( KCDVersion1_1 );
       
  2279 
       
  2280     db->SetAttributeMask( ECDHidden | ECDProtectedWrite );
       
  2281 
       
  2282     // Get IAP
       
  2283     // 
       
  2284     CCDIAPRecord* iap = LoadIapRecordLC( aVirtualIapId, db );
       
  2285 
       
  2286     TDesC& type = iap->iBearerType.GetL();
       
  2287 
       
  2288     if( type.Compare( TPtrC ( KCDTypeNameVirtualBearer ) ) != 0 )
       
  2289         {
       
  2290         MPMLOGSTRING( "CMPMCommsDatAccess::FindRealIapL: \
       
  2291 aVirtualIapId is not virtual, return as aRealIapId" )
       
  2292 
       
  2293         aRealIapId = aVirtualIapId;
       
  2294 
       
  2295         // Release memory
       
  2296         //
       
  2297         CleanupStack::PopAndDestroy( iap );
       
  2298         CleanupStack::PopAndDestroy( db );
       
  2299         return;
       
  2300         }
       
  2301 
       
  2302     CMDBGenericRecord * generic = static_cast<CMDBGenericRecord*>
       
  2303         ( CCDRecordBase::RecordFactoryL( 0 ) );
       
  2304     CleanupStack::PushL( generic );
       
  2305     generic->InitializeL( TPtrC( KCDTypeNameVirtualIAPNextLayer ), 
       
  2306                           NULL );
       
  2307     generic->LoadL( *db );
       
  2308 
       
  2309     CCDVirtualIAPNextLayerRecord* virtualNext = new ( ELeave ) 
       
  2310         CCDVirtualIAPNextLayerRecord( generic->TableId() );
       
  2311 
       
  2312     CleanupStack::PushL( virtualNext );
       
  2313     virtualNext->iIAP = iap->RecordId();
       
  2314     if ( virtualNext->FindL( *db ) )
       
  2315         {
       
  2316         if ( virtualNext->iNextLayerSNAP != 0 )
       
  2317             {
       
  2318             // SNAP
       
  2319             // 
       
  2320             TInt snap = virtualNext->iNextLayerSNAP;
       
  2321             MPMLOGSTRING2(
       
  2322                 "CMPMCommsDatAccess::FindRealIapL: SNAP: %i", snap )
       
  2323             MPMLOGSTRING(
       
  2324                 "CMPMCommsDatAccess::FindRealIapL: Call ChooseBestIAPL" )
       
  2325 
       
  2326             TMpmConnPref tempMpmConnPref;
       
  2327             tempMpmConnPref.SetSnapId( snap );
       
  2328             aSession.IapSelectionL()->ChooseBestIAPL( tempMpmConnPref, aAvailableIAPList );
       
  2329             aRealIapId = tempMpmConnPref.IapId();
       
  2330             }
       
  2331         else if ( virtualNext->iNextLayerIAP != 0 )
       
  2332             {
       
  2333             // IAP
       
  2334             // 
       
  2335             CCDIAPRecord* iap2 = LoadIapRecordLC( virtualNext->iNextLayerIAP, db );
       
  2336             TDesC& type2 = iap2->iBearerType.GetL();
       
  2337             if( type2.Compare( TPtrC ( KCDTypeNameVirtualBearer ) ) == 0 )
       
  2338                 {
       
  2339                 // Virtual IAP
       
  2340                 // 
       
  2341                 MPMLOGSTRING2(
       
  2342                     "CMPMCommsDatAccess::FindRealIapL: Virtual IAP: %i", 
       
  2343                     iap2->RecordId() )
       
  2344                 MPMLOGSTRING(
       
  2345                     "CMPMCommsDatAccess::FindRealIapL: Call FindRealIapL" )
       
  2346 
       
  2347                 FindRealIapL( iap2->RecordId(), 
       
  2348                               aRealIapId, 
       
  2349                               aAvailableIAPList,
       
  2350                               aSession );
       
  2351                 }
       
  2352             else
       
  2353                 {
       
  2354                 aRealIapId = iap2->RecordId();
       
  2355 
       
  2356                 MPMLOGSTRING2(
       
  2357                     "CMPMCommsDatAccess::FindRealIapL: NextLayerIAP: %i", 
       
  2358                     aRealIapId )
       
  2359                 }
       
  2360             // Release memory
       
  2361             //
       
  2362             CleanupStack::PopAndDestroy( iap2 );
       
  2363             }
       
  2364         else
       
  2365             {
       
  2366             MPMLOGSTRING( "CMPMCommsDatAccess::FindRealIapL: No underlying IAP\
       
  2367  defined for virtual IapId" )
       
  2368             }
       
  2369         }
       
  2370 
       
  2371     // Release memory
       
  2372     //
       
  2373     CleanupStack::PopAndDestroy( virtualNext );
       
  2374     CleanupStack::PopAndDestroy( generic );
       
  2375     CleanupStack::PopAndDestroy( iap );
       
  2376     CleanupStack::PopAndDestroy( db );
       
  2377     }
       
  2378 
       
  2379 // -----------------------------------------------------------------------------
       
  2380 // CMPMCommsDatAccess::LoadLinkedRecordL
       
  2381 // -----------------------------------------------------------------------------
       
  2382 //
       
  2383 CCDRecordBase* CMPMCommsDatAccess::LoadLinkedRecordL( CMDBSession&  aSession, 
       
  2384                                   TMDBElementId aElementId )
       
  2385     {
       
  2386     // This is copied from commsdatSnapTests.cpp. 
       
  2387     // Loading linked records does not work currently.
       
  2388     // 
       
  2389     CCDRecordBase *record = static_cast<CCDRecordBase*>( 
       
  2390         CCDRecordBase::RecordFactoryL( aElementId ) );
       
  2391     CleanupStack::PushL( record );
       
  2392     record->LoadL( aSession );
       
  2393     CleanupStack::Pop( record );
       
  2394     return record;
       
  2395     }
       
  2396     
       
  2397 // -----------------------------------------------------------------------------
       
  2398 // CMPMCommsDatAccess::GetRealElementId
       
  2399 // -----------------------------------------------------------------------------
       
  2400 //
       
  2401 TUint32 CMPMCommsDatAccess::GetRealElementId( CMDBRecordBase* aRecord )
       
  2402     {
       
  2403     return aRecord->ElementId() & KCDMaskShowField;
       
  2404     }
       
  2405 
       
  2406 // -----------------------------------------------------------------------------
       
  2407 // CMPMCommsDatAccess::WlanBackgroundScanIsOnL
       
  2408 // -----------------------------------------------------------------------------
       
  2409 //
       
  2410 TBool CMPMCommsDatAccess::WlanBackgroundScanIsOnL()
       
  2411     {
       
  2412     CCommsDatabase*    commDB = NULL;
       
  2413     CCommsDbTableView* table  = NULL;
       
  2414 
       
  2415     // Open commDB
       
  2416     commDB = CCommsDatabase::NewL();
       
  2417     CleanupStack::PushL( commDB );
       
  2418 
       
  2419     // from connmondef.h
       
  2420     _LIT( KCmWlanDeviceSettings,        "WLANDeviceTable" );
       
  2421     _LIT( KCmWlanDeviceSettingsType,    "WlanDeviceSettingsType" );
       
  2422     _LIT( KCmBgScanInterval,            "WlanBgScanInterval" );
       
  2423     const TUint32 KCmWlanUserSettings  = 1;
       
  2424 
       
  2425     table = commDB->OpenViewMatchingUintLC( KCmWlanDeviceSettings,
       
  2426                                             KCmWlanDeviceSettingsType,
       
  2427                                             KCmWlanUserSettings );
       
  2428 
       
  2429     TInt err = table->GotoFirstRecord();
       
  2430 
       
  2431     if ( err )
       
  2432         {
       
  2433         User::Leave( err );  
       
  2434         }
       
  2435     
       
  2436     TUint32 scanInterval;
       
  2437     table->ReadUintL( KCmBgScanInterval, scanInterval ); 
       
  2438 
       
  2439     // cleanup
       
  2440     CleanupStack::PopAndDestroy( table );
       
  2441     CleanupStack::PopAndDestroy( commDB );
       
  2442     
       
  2443     return scanInterval != 0 ? ETrue : EFalse;
       
  2444     
       
  2445     }
       
  2446 
       
  2447 // -----------------------------------------------------------------------------
       
  2448 // IsInternetSnapL
       
  2449 // -----------------------------------------------------------------------------
       
  2450 //
       
  2451 TBool CMPMCommsDatAccess::IsInternetSnapL( TUint32 aIapId, TUint32 aSnapId )
       
  2452     {
       
  2453     MPMLOGSTRING3( 
       
  2454         "CMPMCommsDatAccess::IsInternetSnapL - aIapId = %d, aSnapId = %d", 
       
  2455         aIapId, aSnapId )
       
  2456 
       
  2457     TBool ret = EFalse;
       
  2458     
       
  2459     // Open transaction
       
  2460     CMDBSession* db = CMDBSession::NewLC( KCDVersion1_1 );
       
  2461 
       
  2462     if ( aSnapId )
       
  2463         {
       
  2464         // Check that snap purpose is internet
       
  2465         ret = IsInternetSnapL( *db, aSnapId );
       
  2466         }
       
  2467     else if ( aIapId )
       
  2468         {
       
  2469         RArray<TUint> snapIds;
       
  2470         
       
  2471         // Get destinations
       
  2472         FindAllSnapsL( snapIds );
       
  2473         CleanupClosePushL( snapIds );
       
  2474         
       
  2475         for (TInt index = 0; index < snapIds.Count(); index++)
       
  2476             {
       
  2477             RArray<TNetIap> ids;
       
  2478             // Get iaps belonging to this destination
       
  2479             SearchDNEntriesL( snapIds[index], ids );
       
  2480             CleanupClosePushL( ids );
       
  2481             
       
  2482             for (TInt index2 = 0; index2 < ids.Count(); index2++)
       
  2483                 {
       
  2484                 // Check if iap belongs to this destination
       
  2485                 if (ids[index2].iIapId == aIapId)
       
  2486                     {
       
  2487                     ret = IsInternetSnapL( *db, snapIds[index] );
       
  2488 
       
  2489                     if (ret)
       
  2490                         {
       
  2491                         break;
       
  2492                         }
       
  2493                     }
       
  2494                 }            
       
  2495             
       
  2496             CleanupStack::PopAndDestroy( &ids );
       
  2497             
       
  2498             if (ret)
       
  2499                 {
       
  2500                 break;
       
  2501                 }
       
  2502             }
       
  2503         
       
  2504         CleanupStack::PopAndDestroy( &snapIds );
       
  2505         }
       
  2506 
       
  2507     CleanupStack::PopAndDestroy( db );
       
  2508     
       
  2509     return ret;
       
  2510     }
       
  2511 
       
  2512 // -----------------------------------------------------------------------------
       
  2513 // IsInternetSnapL
       
  2514 // -----------------------------------------------------------------------------
       
  2515 //
       
  2516 TBool CMPMCommsDatAccess::IsInternetSnapL(CMDBSession& db, TUint32 aSnapId)
       
  2517     {
       
  2518     MPMLOGSTRING( "CMPMCommsDatAccess::IsInternetSnapL" )        
       
  2519     TBool ret = EFalse;
       
  2520     
       
  2521     CCDAccessPointRecord* snapAPr =  static_cast<CCDAccessPointRecord*>( 
       
  2522             CCDAccessPointRecord::RecordFactoryL( KCDTIdAccessPointRecord ) );
       
  2523     
       
  2524     snapAPr->iRecordTag = aSnapId;
       
  2525     CleanupStack::PushL( snapAPr );
       
  2526 
       
  2527     if ( !snapAPr->FindL( db ) )
       
  2528         {
       
  2529         MPMLOGSTRING("CMPMCommsDatAccess::IsInternetSnapL: SNAP not found")
       
  2530         CleanupStack::PopAndDestroy( snapAPr );
       
  2531         return ret;
       
  2532         }
       
  2533 
       
  2534     // Create snap metadata record
       
  2535     CMDBRecordSet<CCDSNAPMetadataRecord>* metaSet = 
       
  2536            new ( ELeave ) CMDBRecordSet<CCDSNAPMetadataRecord>( 
       
  2537             CCDSNAPMetadataRecord::TableIdL( db ) );
       
  2538     CleanupStack::PushL( metaSet );
       
  2539 
       
  2540     // Load snap metedata record
       
  2541     metaSet->LoadL( db );
       
  2542 
       
  2543     for ( TInt i = 0; i < metaSet->iRecords.Count(); ++i )
       
  2544         {
       
  2545         // Get value
       
  2546         TInt meta = QUERY_INT_FIELD( metaSet->iRecords[i], 
       
  2547                                      KCDTIdSNAPMetadataMetadata );
       
  2548         
       
  2549         TInt snap = QUERY_INT_FIELD( metaSet->iRecords[i],
       
  2550                                      KCDTIdSNAPMetadataSNAP ); 
       
  2551         // Check whether internet
       
  2552         if( meta & ESnapMetadataInternet )
       
  2553             {            
       
  2554             MPMLOGSTRING("CMPMCommsDatAccess::IsInternetSnapL: Internet snap found")
       
  2555             
       
  2556             if ( snap == aSnapId )
       
  2557                 {
       
  2558                 MPMLOGSTRING2("CMPMCommsDatAccess::IsInternetSnapL: This is internet snap: %d",
       
  2559                               aSnapId)
       
  2560                 ret = ETrue;
       
  2561                 break;
       
  2562                 }
       
  2563             }
       
  2564         }
       
  2565         
       
  2566     CleanupStack::PopAndDestroy( metaSet );
       
  2567     CleanupStack::PopAndDestroy( snapAPr );
       
  2568     return ret;
       
  2569     }
       
  2570 
       
  2571 // -----------------------------------------------------------------------------
       
  2572 // CMPMCommsDatAccess::GetBearerTypeL
       
  2573 // -----------------------------------------------------------------------------
       
  2574 //
       
  2575 TMPMBearerType CMPMCommsDatAccess::GetBearerTypeL( TUint32 aIapId )
       
  2576     {
       
  2577     MPMLOGSTRING( "CMPMCommsDatAccess::GetBearerTypeL" )
       
  2578     TMPMBearerType bearerType = EMPMBearerTypeOther;
       
  2579     RArray<TUint32> wlanArray;
       
  2580     
       
  2581     CMDBSession* db = CMDBSession::NewLC( KCDVersion1_1 );
       
  2582     
       
  2583     CleanupClosePushL( wlanArray );
       
  2584     BuildWlanArrayL(*db, wlanArray);
       
  2585     
       
  2586     CCDIAPRecord* record = LoadIapRecordLC( aIapId, db );
       
  2587     
       
  2588     TBuf<KMaxTextLength> bearerTypeName( record->iBearerType.GetL() );
       
  2589     TBuf<KMaxTextLength> serviceTypeName( record->iServiceType.GetL() );
       
  2590         
       
  2591     if ( ( serviceTypeName == TPtrC( KCDTypeNameOutgoingWCDMA ) ) ||
       
  2592          ( serviceTypeName == TPtrC( KCDTypeNameIncomingWCDMA ) ) )
       
  2593         {
       
  2594         // Packet data
       
  2595         bearerType = EMPMBearerTypePacketData;
       
  2596         }
       
  2597     else if ( serviceTypeName == TPtrC( KCDTypeNameLANService ) )
       
  2598         {
       
  2599         // LAN or WLAN
       
  2600         TUint32 bearerId( record->iBearer );
       
  2601             
       
  2602         if ( ( bearerTypeName == TPtrC( KCDTypeNameLANBearer ) ) &&
       
  2603              ( IsWlanBearer( wlanArray, record->iBearer ) ) )
       
  2604             {
       
  2605             // WLAN
       
  2606             bearerType = EMPMBearerTypeWlan;
       
  2607             }
       
  2608         }
       
  2609     else if ( ( bearerTypeName == TPtrC( KCDTypeNameVirtualBearer ) ) &&
       
  2610               ( serviceTypeName == TPtrC ( KCDTypeNameVPNService ) ) )
       
  2611         {
       
  2612         // VPN
       
  2613         bearerType = EMPMBearerTypeVpn;
       
  2614         }
       
  2615     
       
  2616     CleanupStack::PopAndDestroy( record );
       
  2617     CleanupStack::PopAndDestroy( &wlanArray );
       
  2618     CleanupStack::PopAndDestroy( db );
       
  2619     
       
  2620     return bearerType;
       
  2621     }
       
  2622 
       
  2623 // -----------------------------------------------------------------------------
       
  2624 // CMPMCommsDatAccess::IsWlanBearerL
       
  2625 // -----------------------------------------------------------------------------
       
  2626 //
       
  2627 TBool CMPMCommsDatAccess::IsWlanBearer(RArray<TUint32>& aWlanArray, TInt aBearerId)
       
  2628     {
       
  2629     MPMLOGSTRING( "CMPMCommsDatAccess::IsWlanBearer" )
       
  2630 
       
  2631     TInt index = aWlanArray.Find( aBearerId );
       
  2632 
       
  2633     if ( index != KErrNotFound )
       
  2634         {
       
  2635         return ETrue;
       
  2636         }
       
  2637     
       
  2638     return EFalse;
       
  2639     }
       
  2640 
       
  2641 // -----------------------------------------------------------------------------
       
  2642 // CMPMCommsDatAccess::BuildWlanArrayL
       
  2643 // -----------------------------------------------------------------------------
       
  2644 //
       
  2645 void CMPMCommsDatAccess::BuildWlanArrayL(CMDBSession& aDb, 
       
  2646                                          RArray<TUint32>& aWlanArray)
       
  2647     {
       
  2648     MPMLOGSTRING( "CMPMCommsDatAccess::BuildWlanArrayL" )
       
  2649     
       
  2650     CMDBRecordSet<CCDLANBearerRecord>* ptrLanBearerRecordSet = new( ELeave )
       
  2651             CMDBRecordSet<CCDLANBearerRecord>( KCDTIdLANBearerRecord );
       
  2652     CleanupStack::PushL( ptrLanBearerRecordSet );
       
  2653     ptrLanBearerRecordSet->LoadL( aDb );
       
  2654 
       
  2655     for ( TInt i = 0; i < ptrLanBearerRecordSet->iRecords.Count(); i++ )
       
  2656         {
       
  2657         TBuf<KMaxTextLength> bearerRecordName(
       
  2658                 ( (CCDLANBearerRecord*)ptrLanBearerRecordSet->iRecords[i] )->iRecordName.GetL() );
       
  2659 
       
  2660         // Check if bearer is WLAN
       
  2661         if ( bearerRecordName == TPtrC( KModemBearerWLAN ) )
       
  2662             {
       
  2663             aWlanArray.AppendL( ptrLanBearerRecordSet->iRecords[i]->RecordId() );
       
  2664             }
       
  2665         }
       
  2666     
       
  2667     CleanupStack::PopAndDestroy( ptrLanBearerRecordSet );    
       
  2668     }
       
  2669 
       
  2670 // -----------------------------------------------------------------------------
       
  2671 // CMPMCommsDatAccess::AreActiveIapsInSameSnapL
       
  2672 // -----------------------------------------------------------------------------
       
  2673 //
       
  2674 TBool CMPMCommsDatAccess::AreActiveIapsInSameSnapL ( RArray<TActiveBMConn>& aActiveBMConns,
       
  2675                                                      TUint32& aSnapId )
       
  2676     {
       
  2677     MPMLOGSTRING( "CMPMCommsDatAccess::AreActiveIapsInSameSnapL" )
       
  2678     TBool same = ETrue;
       
  2679     TUint32 snapId = 0;
       
  2680     TUint32 prevSnapId = 0;
       
  2681             
       
  2682     // Go through all active connections
       
  2683     for (TInt index = 0; index < aActiveBMConns.Count(); index++ )
       
  2684         {
       
  2685         // Do check only for active connections
       
  2686         if ( aActiveBMConns[index].iConnInfo.iState != EStarted )
       
  2687             {
       
  2688             continue;
       
  2689             }
       
  2690         
       
  2691         // Iap id must be nonzero
       
  2692         if ( aActiveBMConns[index].iConnInfo.iIapId )
       
  2693             {
       
  2694             prevSnapId = snapId;
       
  2695             // Get destination id for the iap
       
  2696             snapId = GetSnapIdL( aActiveBMConns[index].iConnInfo.iIapId );
       
  2697                         
       
  2698             // Check if previous iap's destination is different
       
  2699             if ( ( ( prevSnapId != snapId ) && prevSnapId && snapId ) ||
       
  2700                  !snapId )
       
  2701                 {
       
  2702                 // Set return value to false and leave loop
       
  2703                 same = EFalse;
       
  2704                 break;
       
  2705                 }
       
  2706             }
       
  2707         }
       
  2708     
       
  2709     // Return destId for later use
       
  2710     aSnapId = snapId;
       
  2711     
       
  2712     return same;
       
  2713     }
       
  2714 
       
  2715 // -----------------------------------------------------------------------------
       
  2716 // CMPMCommsDatAccess::SelectActiveConnectionL
       
  2717 // -----------------------------------------------------------------------------
       
  2718 //
       
  2719 void CMPMCommsDatAccess::SelectActiveConnectionL ( const TUint32 aSnapId,
       
  2720                                                    RArray<TActiveBMConn>& aActiveBMConns,
       
  2721                                                    TUint32& aActiveIapId,
       
  2722                                                    TUint32& aActiveSnapId,
       
  2723                                                    TMPMBearerType& aActiveBearerType,
       
  2724                                                    CMPMServerSession& aSession )
       
  2725     {
       
  2726     MPMLOGSTRING( "CMPMCommsDatAccess::SelectActiveConnectionL" )
       
  2727     RArray<TUint32> activeIaps;
       
  2728     RArray<TNetIap> iapIds;
       
  2729     
       
  2730     // Reset output parameters
       
  2731     aActiveIapId = 0;
       
  2732     aActiveSnapId = 0;
       
  2733     aActiveBearerType = EMPMBearerTypeNone;
       
  2734 
       
  2735     CleanupClosePushL( activeIaps );
       
  2736         
       
  2737     for (TInt index = 0; index < aActiveBMConns.Count(); index++ )
       
  2738         {
       
  2739         // Add only started iaps to array
       
  2740         if ( aActiveBMConns[index].iConnInfo.iState == EStarted )
       
  2741             {
       
  2742             activeIaps.AppendL ( aActiveBMConns[index].iConnInfo.iIapId );
       
  2743             }
       
  2744         }
       
  2745         
       
  2746     CleanupClosePushL( iapIds );
       
  2747     SearchDNEntriesL( aSnapId, iapIds );
       
  2748     
       
  2749     // Remove any deactived IAP from iapIds
       
  2750     TInt ret        = KErrNotFound;
       
  2751     TInt destCount  = iapIds.Count();
       
  2752     
       
  2753     // Decrement by one, because count is n, 
       
  2754     // but indexes in array are 0 .. n-1.
       
  2755     // 
       
  2756     destCount--;
       
  2757 
       
  2758     // This time we are browsing the array from the end to the beginning, 
       
  2759     // because removing one element from array affects index numbering.
       
  2760     for ( TInt k = destCount; k >= 0; k-- )
       
  2761         {
       
  2762         ret = activeIaps.Find( iapIds[k].iIapId );
       
  2763         if ( ret == KErrNotFound )
       
  2764             {
       
  2765             MPMLOGSTRING2( "CMPMCommsDatAccess::SelectActiveConnectionL: \
       
  2766 Remove deactived IAP = %i", iapIds[k].iIapId )
       
  2767             iapIds.Remove( k );
       
  2768             }
       
  2769         }
       
  2770 
       
  2771     // Determine the actual priorities for IAPs
       
  2772     DeterminePrioritiesL( iapIds, activeIaps, aSession );
       
  2773 
       
  2774     // Check if a matching available IAP is found.
       
  2775     if( iapIds.Count() )
       
  2776         {
       
  2777         // Go through all iaps
       
  2778         for ( TInt index = 0; index < iapIds.Count(); index++ )
       
  2779             {
       
  2780             // Get bearer type
       
  2781             TMPMBearerType bearerType = GetBearerTypeL( iapIds[index].iIapId );
       
  2782         
       
  2783             // If iap is not vpn, wlan or packet then skip it
       
  2784             if ( bearerType == EMPMBearerTypeOther )
       
  2785                 {
       
  2786                 continue;
       
  2787                 }
       
  2788             
       
  2789             // Set bearer type, iap id and snap id
       
  2790             for (TInt index2 = 0; index2 < aActiveBMConns.Count(); index2++ )
       
  2791                 {
       
  2792                 if ( ( aActiveBMConns[index2].iConnInfo.iIapId ==
       
  2793                        iapIds[index].iIapId ) )
       
  2794                     {
       
  2795                     if ( aSession.MyServer().DedicatedClients().Find(
       
  2796                          aActiveBMConns[index2].iConnInfo.iAppUid ) != KErrNone )
       
  2797                         {
       
  2798                         aActiveSnapId = aActiveBMConns[index2].iConnInfo.iSnap;
       
  2799                         aActiveIapId = aActiveBMConns[index2].iConnInfo.iIapId;
       
  2800                         aActiveBearerType = bearerType;
       
  2801                         }
       
  2802                     break;
       
  2803                     }
       
  2804                 }
       
  2805             
       
  2806             break;
       
  2807             }
       
  2808         }
       
  2809 
       
  2810     MPMLOGSTRING4(
       
  2811         "CMPMCommsDatAccess::SelectActiveConnectionL: Iap id = %i, Snap id = %i, \
       
  2812 Bearer type = %i",
       
  2813         aActiveIapId, aActiveSnapId, aActiveBearerType )
       
  2814     
       
  2815     CleanupStack::PopAndDestroy( &iapIds );
       
  2816     CleanupStack::PopAndDestroy( &activeIaps );
       
  2817     }
       
  2818     
       
  2819 // -----------------------------------------------------------------------------
       
  2820 // CMPMCommsDatAccess::GetSnapIdL
       
  2821 // -----------------------------------------------------------------------------
       
  2822 //
       
  2823 TUint32 CMPMCommsDatAccess::GetSnapIdL( TUint32 aIapId )
       
  2824     {
       
  2825     MPMLOGSTRING( "CMPMCommsDatAccess::GetSnapIdL" )
       
  2826     TUint32 snapId = 0;
       
  2827     RArray<TUint> snapIds;
       
  2828         
       
  2829     CleanupClosePushL( snapIds );
       
  2830     // Get destinations
       
  2831     FindAllSnapsL( snapIds );
       
  2832 
       
  2833     for (TInt index = 0; index < snapIds.Count(); index++)
       
  2834         {
       
  2835         RArray<TNetIap> ids;
       
  2836         // Get iaps belonging to this snap
       
  2837         CleanupClosePushL( ids );
       
  2838         SearchDNEntriesL( snapIds[index], ids );
       
  2839             
       
  2840         for (TInt index2 = 0; index2 < ids.Count(); index2++)
       
  2841             {
       
  2842             // Check if iap belongs to this destination
       
  2843             if (ids[index2].iIapId == aIapId)
       
  2844                 {
       
  2845                 snapId = snapIds[index];
       
  2846                 CleanupStack::PopAndDestroy( &ids );                    
       
  2847                 CleanupStack::PopAndDestroy( &snapIds );
       
  2848                 return snapId;
       
  2849                 }
       
  2850             }
       
  2851         
       
  2852         CleanupStack::PopAndDestroy( &ids );
       
  2853         }
       
  2854 
       
  2855     CleanupStack::PopAndDestroy( &snapIds );
       
  2856     
       
  2857     return snapId;
       
  2858     }
       
  2859 
       
  2860 // -----------------------------------------------------------------------------
       
  2861 // CMPMCommsDatAccess::IsSnapEmptyL
       
  2862 // -----------------------------------------------------------------------------
       
  2863 //
       
  2864 TBool CMPMCommsDatAccess::IsSnapEmptyL( TUint32 aSnapId )
       
  2865     {
       
  2866     MPMLOGSTRING( "CMPMCommsDatAccess::IsSnapEmptyL" )
       
  2867     TBool empty = ETrue;
       
  2868     
       
  2869     RArray<TNetIap> ids;
       
  2870     // Get iaps belonging to this snap
       
  2871     CleanupClosePushL( ids );
       
  2872     SearchDNEntriesL( aSnapId, ids );
       
  2873     
       
  2874     if ( ids.Count() )
       
  2875         {
       
  2876         empty = EFalse;
       
  2877         }
       
  2878     
       
  2879     CleanupStack::PopAndDestroy( &ids );    
       
  2880     
       
  2881     return empty;
       
  2882     }
       
  2883         
       
  2884 // -----------------------------------------------------------------------------
       
  2885 // VerifyIapExistsL
       
  2886 // -----------------------------------------------------------------------------
       
  2887 //
       
  2888 void CMPMCommsDatAccess::VerifyIapExistsL( TUint32 aIapId )
       
  2889     {
       
  2890     MPMLOGSTRING2( "CMPMCommsDatAccess::VerifyIapExistsL: aIapId %d", aIapId )
       
  2891     CMDBSession* db = CMDBSession::NewLC( KCDVersion1_1 );
       
  2892     db->SetAttributeMask( ECDProtectedWrite );
       
  2893     CCDIAPRecord* iapRecord = LoadIapRecordLC( aIapId, db );
       
  2894     CleanupStack::PopAndDestroy( iapRecord );
       
  2895     CleanupStack::PopAndDestroy( db );
       
  2896     }
       
  2897 
       
  2898 // -----------------------------------------------------------------------------
       
  2899 // ForcedRoamingL
       
  2900 // -----------------------------------------------------------------------------
       
  2901 //
       
  2902 TCmUsageOfWlan CMPMCommsDatAccess::ForcedRoamingL() const
       
  2903     {
       
  2904     TCmGenConnSettings cmGenConnSettings;
       
  2905     RCmManager rCmManager;
       
  2906     
       
  2907     rCmManager.CreateTablesAndOpenL();
       
  2908     CleanupClosePushL( rCmManager ); 
       
  2909     rCmManager.ReadGenConnSettingsL( cmGenConnSettings );
       
  2910     CleanupStack::PopAndDestroy( &rCmManager );
       
  2911     
       
  2912     return cmGenConnSettings.iUsageOfWlan;
       
  2913     }
       
  2914 
       
  2915 // -----------------------------------------------------------------------------
       
  2916 // MapAPRecIdtoSnapAPL
       
  2917 // -----------------------------------------------------------------------------
       
  2918 //
       
  2919 TInt CMPMCommsDatAccess::TierLinktoTagIdL( CMDBSession* aDbs, TUint32 aElementId )
       
  2920     {
       
  2921     ASSERT(aDbs);
       
  2922     
       
  2923     // declare tier record
       
  2924     CCDTierRecord* tier = static_cast<CCDTierRecord*>( 
       
  2925             CCDTierRecord::RecordFactoryL( KCDTIdTierRecord ) );
       
  2926     
       
  2927     CleanupStack::PushL( tier );
       
  2928     
       
  2929     tier->SetElementId( aElementId );
       
  2930     tier->LoadL( *aDbs );
       
  2931     TInt tag = tier->iRecordTag;
       
  2932 
       
  2933     CleanupStack::PopAndDestroy( tier );
       
  2934     return  tag;
       
  2935     }
       
  2936 
       
  2937 // -----------------------------------------------------------------------------
       
  2938 // MapAPRecIdtoSnapAPL
       
  2939 // -----------------------------------------------------------------------------
       
  2940 //
       
  2941 TInt CMPMCommsDatAccess::MapAPRecIdtoSnapAPL( TInt aApRecId )
       
  2942     {
       
  2943     CMDBSession* dbs = CMDBSession::NewLC( KCDVersion1_1 );
       
  2944         
       
  2945     CCDAccessPointRecord* ipt =  static_cast<CCDAccessPointRecord*>( 
       
  2946             CCDAccessPointRecord::RecordFactoryL( KCDTIdAccessPointRecord ) );
       
  2947 
       
  2948     CleanupStack::PushL( ipt );
       
  2949 
       
  2950     ipt->SetElementId( aApRecId );
       
  2951     
       
  2952     TBool found = ipt->FindL( *dbs );
       
  2953     if ( !found )
       
  2954         User::Leave( KErrNotFound );
       
  2955     
       
  2956     if ( TierLinktoTagIdL( dbs, ipt->iTier ) == KAfInet )  // ipprototm = 271064560 , iptm = 271064536
       
  2957         {
       
  2958         User::Leave( KErrArgument );
       
  2959         }
       
  2960 
       
  2961     TInt ap = ipt->iRecordTag;
       
  2962     
       
  2963     CleanupStack::PopAndDestroy( ipt );
       
  2964     CleanupStack::PopAndDestroy( dbs );
       
  2965 
       
  2966     return ap;
       
  2967     }
       
  2968 
       
  2969 // -----------------------------------------------------------------------------
       
  2970 // MapNetIdtoSnapAPL
       
  2971 // -----------------------------------------------------------------------------
       
  2972 //
       
  2973 TInt CMPMCommsDatAccess::MapNetIdtoSnapAPL( TInt aNetId )
       
  2974     {
       
  2975     CMDBSession* dbs = CMDBSession::NewLC( KCDVersion1_1 );
       
  2976         
       
  2977     CCDAccessPointRecord* ipt =  static_cast<CCDAccessPointRecord*>( 
       
  2978             CCDAccessPointRecord::RecordFactoryL( KCDTIdAccessPointRecord ) );
       
  2979 
       
  2980     CleanupStack::PushL( ipt );
       
  2981     ipt->iCustomSelectionPolicy = aNetId;
       
  2982 
       
  2983     TBool found = ipt->FindL( *dbs );
       
  2984     if ( !found )
       
  2985         User::Leave( KErrNotFound );
       
  2986     
       
  2987     if ( TierLinktoTagIdL( dbs, ipt->iTier ) == KAfInet )  // ipprototm = 271064560 , iptm = 271064536
       
  2988         {
       
  2989         User::Leave( KErrArgument );
       
  2990         }
       
  2991 
       
  2992     TInt ap = ipt->iRecordTag;
       
  2993     
       
  2994     CleanupStack::PopAndDestroy( ipt );
       
  2995     CleanupStack::PopAndDestroy( dbs );
       
  2996 
       
  2997     return ap;
       
  2998     }
       
  2999 
       
  3000 // -----------------------------------------------------------------------------
       
  3001 // MapSnapAPtoNetIdL
       
  3002 // -----------------------------------------------------------------------------
       
  3003 //
       
  3004 TInt CMPMCommsDatAccess::MapSnapAPtoNetIdL( TInt aAP )
       
  3005     {
       
  3006     CMDBSession* dbs = CMDBSession::NewLC( KCDVersion1_1 );
       
  3007         
       
  3008     CCDAccessPointRecord* ipt =  static_cast<CCDAccessPointRecord*>( 
       
  3009             CCDAccessPointRecord::RecordFactoryL( KCDTIdAccessPointRecord ) );
       
  3010     CleanupStack::PushL( ipt );
       
  3011     ipt->iRecordTag = aAP;
       
  3012     TBool found = ipt->FindL( *dbs );
       
  3013     if ( !found )
       
  3014         User::Leave( KErrNotFound );
       
  3015     
       
  3016     if ( TierLinktoTagIdL( dbs, ipt->iTier ) == KAfInet )  // ipprototm = 271064560 , iptm = 271064536
       
  3017         {
       
  3018         User::Leave( KErrArgument );
       
  3019         }
       
  3020 
       
  3021     TInt netid = ipt->iSelectionPolicy;
       
  3022     
       
  3023     CleanupStack::PopAndDestroy( ipt );
       
  3024     CleanupStack::PopAndDestroy( dbs );
       
  3025 
       
  3026     return netid;
       
  3027     }
       
  3028 
       
  3029 
       
  3030 // -----------------------------------------------------------------------------
       
  3031 // CMPMCommsDatAccess::ReadGenConnSettings
       
  3032 // -----------------------------------------------------------------------------
       
  3033 //
       
  3034 TCmGenConnSettings CMPMCommsDatAccess::ReadGenConnSettingsL() const
       
  3035     {
       
  3036     TCmGenConnSettings cmGenConnSettings;
       
  3037     RCmManager rCmManager;
       
  3038     
       
  3039     rCmManager.CreateTablesAndOpenL();
       
  3040     CleanupClosePushL( rCmManager ); 
       
  3041     rCmManager.ReadGenConnSettingsL( cmGenConnSettings );
       
  3042     CleanupStack::PopAndDestroy( &rCmManager );
       
  3043     
       
  3044     return cmGenConnSettings;
       
  3045     }
       
  3046 
       
  3047 // -----------------------------------------------------------------------------
       
  3048 // CMPMCommsDatAccess::WriteGenConnSettings
       
  3049 // -----------------------------------------------------------------------------
       
  3050 //
       
  3051 void CMPMCommsDatAccess::WriteGenConnSettingsL(TCmGenConnSettings& aGenConnSettings )
       
  3052     {
       
  3053     RCmManager rCmManager;
       
  3054     rCmManager.CreateTablesAndOpenL();
       
  3055     CleanupClosePushL( rCmManager ); 
       
  3056     rCmManager.WriteGenConnSettingsL( aGenConnSettings );
       
  3057     CleanupStack::PopAndDestroy( &rCmManager );
       
  3058     }
       
  3059 
       
  3060 
       
  3061 // -----------------------------------------------------------------------------
       
  3062 // CMPMCommsDatAccess::DestinationIdL
       
  3063 // -----------------------------------------------------------------------------
       
  3064 //
       
  3065 TUint32 CMPMCommsDatAccess::DestinationIdL( CMManager::TSnapPurpose aSnapPurpose )
       
  3066     {
       
  3067     MPMLOGSTRING( "CMPMCommsDatAccess::DestinationIdL" )
       
  3068     TUint32 destinationId = 0;
       
  3069     TInt snapMetadata = 0;
       
  3070     
       
  3071     RArray<TUint32> snapIds;    
       
  3072     CleanupClosePushL( snapIds );
       
  3073 
       
  3074     RCmManager rCmManager;
       
  3075     CleanupClosePushL( rCmManager ); 
       
  3076     rCmManager.CreateTablesAndOpenL();
       
  3077 
       
  3078     rCmManager.AllDestinationsL( snapIds );
       
  3079 
       
  3080     for ( TInt index = 0; index < snapIds.Count(); index++ )
       
  3081          {
       
  3082          RCmDestination dest;
       
  3083          CleanupClosePushL( dest );
       
  3084 
       
  3085          dest = rCmManager.DestinationL( snapIds[index] );
       
  3086          
       
  3087          snapMetadata = dest.MetadataL( CMManager::ESnapMetadataPurpose );
       
  3088          
       
  3089          if ( snapMetadata == aSnapPurpose )
       
  3090              {
       
  3091              destinationId = snapIds[index];
       
  3092              CleanupStack::PopAndDestroy( &dest );
       
  3093              break;
       
  3094              }        
       
  3095          CleanupStack::PopAndDestroy( &dest );
       
  3096          }
       
  3097     
       
  3098     CleanupStack::PopAndDestroy( &rCmManager );
       
  3099     CleanupStack::PopAndDestroy( &snapIds );
       
  3100 
       
  3101     if (!destinationId)
       
  3102         {
       
  3103         User::Leave(KErrNotFound);
       
  3104         }
       
  3105     
       
  3106     return destinationId;
       
  3107     }
       
  3108 
       
  3109 //  End of File