networkhandling/networkhandlingengine/NetworkHandlingGsmSrc/CNWNetworkViagLcEngine.cpp
changeset 0 ff3b6d0fd310
child 19 7d48bed6ce0c
equal deleted inserted replaced
-1:000000000000 0:ff3b6d0fd310
       
     1 /*
       
     2 * Copyright (c) 2002-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:  This module contains the implementation of CPENetworkViagEngine
       
    15 *                 class member functions.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <rmmcustomapi.h>
       
    23 #include "CNWNetworkViagLcEngine.h"
       
    24 #include "CNWNetworkViagBaseEngine.h"
       
    25 #include "CNWNetworkViagTimer.h"
       
    26 #include "NWPanic.pan"
       
    27 #include "NetworkHandlingDomainPSKeys.h"
       
    28 #include "NWLogger.h"
       
    29 
       
    30 //TEST
       
    31 #include <f32file.h>
       
    32 
       
    33 
       
    34 // CONSTANTS
       
    35 const TInt KNWDigitMask = 0x30;
       
    36 const TInt KNWRatMask = 0xC0;
       
    37 const TInt KNWCodeMask = 0xF;
       
    38 const TInt KTagLength( 12 );
       
    39 const TInt KStopChar( 255 ); // 0xFF
       
    40 const TUint KInvalid( 65535 ); // 0xFFFF 
       
    41 const TInt KDualHandset( 1 );
       
    42 const TInt KMaxVersion ( 255 );//  0xFF
       
    43 const TInt KTagCount( 4 );
       
    44 const TInt KTagOffset( 48 );
       
    45 const TInt KCSTwo( 2 );
       
    46 const TInt KCSNine( 9 );
       
    47 const TInt KCSFour( 4 );
       
    48 const TInt KCSThree( 3 );
       
    49 const TInt KCSTen( 10 );
       
    50 const TInt KCellAndLACLength( 5 );
       
    51 const TInt KCmpLength( 4 );
       
    52 
       
    53 // ============================ MEMBER FUNCTIONS ==============================
       
    54 
       
    55 // ----------------------------------------------------------------------------
       
    56 // CNWNetworkViagLcEngine::CNWNetworkViagLcEngine
       
    57 // C++ default constructor can NOT contain any code, that
       
    58 // might leave.
       
    59 // ----------------------------------------------------------------------------
       
    60 //
       
    61 CNWNetworkViagLcEngine::CNWNetworkViagLcEngine(
       
    62     CNWNetworkViagBaseEngine& aBase,
       
    63     TNWInfo& aNetworkInfo,
       
    64     RMmCustomAPI& aCustomAPI,
       
    65     TNWInterInfo& aInterNetworkInfo)
       
    66       : iBase ( aBase ),
       
    67         iNWNetworkInfo( aNetworkInfo ),
       
    68         iCustomAPI( aCustomAPI ),
       
    69         iInterNetworkInfo( aInterNetworkInfo ),
       
    70         iLastSection ( EFalse ),
       
    71         iMatchFound ( EFalse ),
       
    72         iActivation( ETrue ),
       
    73         iCbActivation( EFalse ),
       
    74         iCurrentLcCache( NULL )
       
    75     {
       
    76     NWLOGSTRING( KNWOBJECT, 
       
    77         "NW: CNWNetworkViagLcEngine::CNWNetworkViagLcEngine() called." );
       
    78     }
       
    79 
       
    80 // ----------------------------------------------------------------------------
       
    81 // CNWNetworkViagLcEngine::ConstructL
       
    82 // Symbian 2nd phase constructor can leave.
       
    83 // --------------------KTagLength----------------------------------------------
       
    84 //
       
    85 void CNWNetworkViagLcEngine::ConstructL()
       
    86     {
       
    87     NWLOGSTRING( KNWOBJECT, "NW: CNWNetworkViagLcEngine::ConstructL() Begin" );
       
    88     iLcCacheOne = new ( ELeave ) TViagElementReocord;
       
    89     iLcCacheTwo = new ( ELeave ) TViagElementReocord;
       
    90     iLcCacheThree = new ( ELeave ) TViagElementReocord;
       
    91     iLcCacheFour = new ( ELeave ) TViagElementReocord;
       
    92     NWLOGSTRING( KNWOBJECT, "NW: CNWNetworkViagLcEngine::ConstructL() End" );
       
    93     }
       
    94 
       
    95 // ----------------------------------------------------------------------------
       
    96 // CNWNetworkViagLcEngine::NewL
       
    97 // Two-phased constructor.
       
    98 // ----------------------------------------------------------------------------
       
    99 //
       
   100 CNWNetworkViagLcEngine* CNWNetworkViagLcEngine::NewL(
       
   101                 CNWNetworkViagBaseEngine& aBase,
       
   102                 TNWInfo& aNetworkInfo, 
       
   103                 RMmCustomAPI& aCustomAPI,
       
   104                 TNWInterInfo& aInterNetworkInfo)
       
   105     {
       
   106     NWLOGSTRING( KNWOBJECT, 
       
   107         "NW: CNWNetworkViagLcEngine::NewL() Begin." );
       
   108     
       
   109     CNWNetworkViagLcEngine* self = new (ELeave) CNWNetworkViagLcEngine(
       
   110                 aBase,
       
   111                 aNetworkInfo,
       
   112                 aCustomAPI,
       
   113                 aInterNetworkInfo );
       
   114     
       
   115     CleanupStack::PushL( self );
       
   116     self->ConstructL();
       
   117     CleanupStack::Pop( self );
       
   118     
       
   119     NWLOGSTRING( KNWOBJECT, 
       
   120         "NW: CNWNetworkViagLcEngine::NewL() End." );
       
   121     return self;
       
   122     }
       
   123 
       
   124 // ----------------------------------------------------------------------------
       
   125 // CNWNetworkViagLcEngine::~CNWNetworkViagLcEngine
       
   126 // Destructor
       
   127 // ----------------------------------------------------------------------------
       
   128 //
       
   129 CNWNetworkViagLcEngine::~CNWNetworkViagLcEngine()
       
   130     {
       
   131     NWLOGSTRING( KNWOBJECT,
       
   132         "NW: CNWNetworkViagLcEngine::~CNWNetworkViagLcEngine() Begin" );
       
   133     if ( iLcCacheOne )
       
   134         {
       
   135         ResetLcCache( *iLcCacheOne ); // Reset old values.     
       
   136         delete iLcCacheOne;
       
   137         }
       
   138 
       
   139     if ( iLcCacheTwo )
       
   140         {
       
   141         ResetLcCache( *iLcCacheTwo );
       
   142         delete iLcCacheTwo;
       
   143         }
       
   144     
       
   145     if ( iLcCacheThree )
       
   146         {
       
   147         ResetLcCache( *iLcCacheThree );
       
   148         delete iLcCacheThree;
       
   149         }
       
   150 
       
   151     if ( iLcCacheFour )
       
   152         {
       
   153         ResetLcCache( *iLcCacheFour );
       
   154         delete iLcCacheFour;
       
   155         }
       
   156 
       
   157     NWLOGSTRING(KNWOBJECT, 
       
   158         "NW: CNWNetworkViagLcEngine::CNWNetworkViagLcEngine() End");
       
   159     }
       
   160 
       
   161 // ----------------------------------------------------------------------------
       
   162 // CNWNetworkViagLcEngine::AddInBufferAsTUint
       
   163 // 
       
   164 // ----------------------------------------------------------------------------
       
   165 //
       
   166 void CNWNetworkViagLcEngine::AddInBufferAsTUint( 
       
   167         TDes & aBuffer, const TUint aData )
       
   168     {
       
   169     NWLOGSTRING2( KNWOBJECT, 
       
   170         "NW: CNWNetworkViagLcEngine::AddInBufferAsTUint() Begin,\
       
   171         aData = %d.", aData );
       
   172     
       
   173     aBuffer.Append( TChar( aData ) );    
       
   174     
       
   175     NWLOGSTRING( KNWOBJECT, 
       
   176         "NW: CNWNetworkViagLcEngine::AddInBufferAsTUint() End." );
       
   177     }
       
   178     
       
   179 // ----------------------------------------------------------------------------
       
   180 // CNWNetworkViagLcEngine::ExtendTUintIntoBuffer
       
   181 // 
       
   182 // ----------------------------------------------------------------------------
       
   183 //
       
   184 void CNWNetworkViagLcEngine::ExtendTUintIntoBuffer( 
       
   185         TDes & aDestData, const TUint aData )
       
   186     {
       
   187     NWLOGSTRING( KNWOBJECT, 
       
   188         "NW: CNWNetworkViagLcEngine::ExtendTUintIntoBuffer() Begin." );
       
   189     
       
   190     aDestData.Zero();
       
   191     aDestData.AppendNum( aData );    
       
   192     
       
   193     NWLOGSTRING( KNWOBJECT, 
       
   194         "NW: CNWNetworkViagLcEngine::ExtendTUintIntoBuffer() End." );
       
   195     }
       
   196 
       
   197 // ----------------------------------------------------------------------------
       
   198 // CNWNetworkViagLcEngine::ParseResult
       
   199 // Decides which parser is used. 
       
   200 // ----------------------------------------------------------------------------
       
   201 //
       
   202 void CNWNetworkViagLcEngine::ParseResult( 
       
   203     TNWNetworkElementFile aElementFile, const TDesC8&  aResponse )
       
   204     {
       
   205     NWLOGSTRING2( KNWOBJECT, "NW: CNWNetworkViagLcEngine::ParseResult() Begin,\
       
   206         aElementFile = 0x%x", aElementFile );
       
   207     
       
   208     switch (aElementFile)
       
   209         {
       
   210         case EFileSettings:
       
   211             ParseSettings( aResponse );
       
   212             break;
       
   213         case EFileTags:        
       
   214             ParseTags( aResponse );
       
   215             break;
       
   216         case EFileSubscribedOne:
       
   217         case EFileSubscribedTwo:
       
   218         case EFileSubscribedThree:
       
   219         case EFileSubscribedFour:
       
   220             ParseSubscribed( aElementFile, aResponse  );
       
   221             break;
       
   222         case EFileHZ:
       
   223         case EFileUnknown:
       
   224             {
       
   225             NWLOGSTRING2( KNWOBJECT, 
       
   226                 "NW: CNWNetworkViagSimReader::ReadSimFile NOT SUPPORTED VALUE \
       
   227                  %d", aElementFile );
       
   228             } 
       
   229         }
       
   230     
       
   231     NWLOGSTRING( KNWOBJECT, "NW: CNWNetworkViagLcEngine::ParseResult() End" );
       
   232     }
       
   233 
       
   234 // ----------------------------------------------------------------------------
       
   235 // CNWNetworkViagLcEngine::GetActivation
       
   236 // Gets activation bits. 
       
   237 // ----------------------------------------------------------------------------
       
   238 //
       
   239 void CNWNetworkViagLcEngine::GetActivation(
       
   240         TBool& aActivation, TBool& aCbActivation )
       
   241     {
       
   242     NWLOGSTRING3( KNWOBJECT, 
       
   243         "NW: CNWNetworkViagLcEngine::GetActivation() Begin,\
       
   244         aActivation = %d, aCbActivation = %d", 
       
   245         iActivation, iCbActivation );
       
   246     
       
   247     aActivation = iActivation;
       
   248     aCbActivation = iCbActivation;
       
   249     
       
   250     NWLOGSTRING( KNWOBJECT, 
       
   251         "NW: CNWNetworkViagLcEngine::ParseResult() End" );
       
   252     }
       
   253 
       
   254 // ----------------------------------------------------------------------------
       
   255 // CNWNetworkViagLcEngine::ParseSettings
       
   256 // Parse setting value from response and update it if wanted. 
       
   257 // ----------------------------------------------------------------------------
       
   258 //
       
   259 void CNWNetworkViagLcEngine::ParseSettings( const TDesC8& aResponse )
       
   260     {
       
   261     NWLOGSTRING( KNWOBJECT,
       
   262         "NW: CNWNetworkViagLcEngine::ParseSettings() Begin" );
       
   263     
       
   264     if ( aResponse.Length() >= 2 )
       
   265         {
       
   266         iActivation =  ( aResponse[0] & 0x01 );
       
   267         iCbActivation = STATIC_CAST( TBool,  ( aResponse[0] >> 1 ) & 0x01 );
       
   268         iVersion = static_cast<TUint8> (aResponse[1] );
       
   269         NWLOGSTRING2( KNWOBJECT, 
       
   270             "NW: CNWNetworkViagLcEngine::ParseSettings Version = %d", 
       
   271             iVersion );
       
   272      
       
   273         if ( iActivation ) // The general activation must be "activation"
       
   274             {
       
   275             if ( ( iVersion + KDualHandset ) > KMaxVersion ) // The update version must not be over 0xFF if so the 
       
   276                 {
       
   277                 iVersion = 0x00; 
       
   278                 }
       
   279             else
       
   280                 {
       
   281                 iVersion =  static_cast<TUint8> ( iVersion + KDualHandset  );
       
   282                 NWLOGSTRING2( KNWOBJECT, 
       
   283                     "NW: CNWNetworkViagLcEngine::UpdateVersion Version = %d", 
       
   284                     iVersion );
       
   285                 }
       
   286             UpdateVersion();
       
   287             }
       
   288         }
       
   289     
       
   290     NWLOGSTRING( KNWOBJECT, 
       
   291         "NW: CNWNetworkViagLcEngine::ParseSettings() End" );
       
   292     }
       
   293 
       
   294 // ----------------------------------------------------------------------------
       
   295 // CNWNetworkViagLcEngine::UpdateVersion
       
   296 // Updates version number to SIM
       
   297 // ----------------------------------------------------------------------------
       
   298 //
       
   299 void CNWNetworkViagLcEngine::UpdateVersion( )
       
   300     {
       
   301     NWLOGSTRING( KNWOBJECT,
       
   302         "NW: CNWNetworkViagLcEngine::UpdateVersion() Begin" );
       
   303     
       
   304     TInt errorCode( KErrNone );
       
   305     RMmCustomAPI::TViagUHZIUESettings hzSettings;
       
   306     if ( iActivation )
       
   307         {
       
   308         hzSettings.iSettings = 1;
       
   309         if ( iCbActivation )
       
   310             {
       
   311             hzSettings.iSettings = 3;
       
   312             }
       
   313         hzSettings.iVersion = iVersion;
       
   314         
       
   315         NWLOGSTRING2( KNWOBJECT, 
       
   316             "NW: CNWNetworkViagLcEngine::UpdateVersion iSettings = %d", 
       
   317             hzSettings.iSettings );
       
   318         NWLOGSTRING2( KNWOBJECT, 
       
   319             "NW: CNWNetworkViagLcEngine::UpdateVersion Version = %d", 
       
   320             hzSettings.iVersion );
       
   321         
       
   322         errorCode = iCustomAPI.WriteViagHomeZoneUHZIUESettings( hzSettings ); 
       
   323         if ( errorCode != KErrNone )
       
   324             {
       
   325             NWLOGSTRING2( KNWOBJECT,
       
   326                 "NW: CNWNetworkViagLcEngine::UpdateVersion Error %d", 
       
   327                 errorCode );
       
   328             }
       
   329         }
       
   330     else
       
   331         {
       
   332         NWLOGSTRING( KNWOBJECT,
       
   333             "NW: CNWNetworkViagLcEngine::UpdateVersion \
       
   334             General activation is OFF" );
       
   335         }
       
   336    
       
   337     NWLOGSTRING( KNWOBJECT,
       
   338         "NW: CNWNetworkViagLcEngine::UpdateVersion() End" );
       
   339     }
       
   340 
       
   341 
       
   342 // ----------------------------------------------------------------------------
       
   343 // CNWNetworkViagLcEngine::ParseTags
       
   344 // Parses zone tags from response and writes them to iZoneTags struct. 
       
   345 // ----------------------------------------------------------------------------
       
   346 //
       
   347 void CNWNetworkViagLcEngine::ParseTags( const TDesC8&  aResponse )
       
   348     {
       
   349     NWLOGSTRING2( KNWOBJECT, 
       
   350         "NW: CNWNetworkViagLcEngine::ParseTags() Begin,\
       
   351         length of aResponse = %d",aResponse.Length());
       
   352 
       
   353     TLex8 parse( aResponse );
       
   354     TInt zoneCount( 1 );
       
   355     TLexMark8 start;
       
   356     parse.Inc( KTagOffset ); // first 48 bits are ignored. 
       
   357  
       
   358     while ( zoneCount <= KTagCount ) // 4 zones, 
       
   359         {
       
   360         // 48.....96    Tag file legth is 96 bytes
       
   361         if ( ( KTagLength * zoneCount   ) <= aResponse.Length() )
       
   362             {
       
   363             parse.Mark( start );
       
   364             parse.Inc( KTagLength ); // // First tag
       
   365             
       
   366             TPtrC8 tag = parse.MarkedToken( start );
       
   367             TBuf<KTagLength> zoneText;
       
   368             TInt length = tag.Locate( KStopChar );
       
   369             
       
   370             TPtrC8 tempTag;
       
   371             // Check that there does'n come overflow
       
   372             if( length > KTagLength )
       
   373                 {
       
   374                 length = KTagLength;
       
   375                 }
       
   376             if ( length > 0 )
       
   377                 {
       
   378                 tempTag.Set( tag.Left( length ) );
       
   379                 iBase.DefaultAlphabetDecode( tempTag, zoneText );
       
   380                 }
       
   381             else if ( length == KErrNotFound )
       
   382                 {
       
   383                 tempTag.Set( tag.Left( KTagLength ) );
       
   384                 iBase.DefaultAlphabetDecode( tempTag, zoneText );
       
   385                 } 
       
   386             else
       
   387                 {
       
   388                 zoneText.Copy( KNullDesC );
       
   389                 }
       
   390             iBase.SetZoneTag( zoneCount+3, zoneText ); // First 4 tags comes from HZ file.
       
   391             }
       
   392         zoneCount++;    
       
   393         }
       
   394     NWLOGSTRING2( KNWOBJECT, "NW: CNWNetworkViagLcEngine::ParseTags(),\
       
   395         zoneCount = %d ", zoneCount ); 
       
   396     
       
   397     NWLOGSTRING( KNWOBJECT, "NW: CNWNetworkViagLcEngine::ParseTags() End" );
       
   398     }
       
   399 
       
   400 // ----------------------------------------------------------------------------
       
   401 // CNWNetworkViagLcEngine::ParseSubscribed
       
   402 // Checks if current LAC file contains any subscribed cells. If at least one subscribed cell is found 
       
   403 // parsefield method is called. 
       
   404 // ----------------------------------------------------------------------------
       
   405 //
       
   406 void CNWNetworkViagLcEngine::ParseSubscribed( 
       
   407         TNWNetworkElementFile aElementFile, 
       
   408         const TDesC8&  aResponse )
       
   409     {
       
   410     NWLOGSTRING3( KNWOBJECT, 
       
   411         "NW: CNWNetworkViagLcEngine::ParseSubscribed() Begin,\
       
   412         aElementFile = 0x%x, length(aResponse) = %d",
       
   413         aElementFile, aResponse.Length());
       
   414     
       
   415     switch ( aElementFile )
       
   416         {
       
   417         case EFileSubscribedOne:
       
   418             { 
       
   419             iCurrentLcCache  =  iLcCacheOne;
       
   420             iLastSection = EFalse;
       
   421             break;    
       
   422             }
       
   423             
       
   424         case EFileSubscribedTwo:
       
   425             {
       
   426             iCurrentLcCache  =  iLcCacheTwo;
       
   427             iLastSection = EFalse;
       
   428             break;
       
   429             }
       
   430         case EFileSubscribedThree:
       
   431             {
       
   432             iCurrentLcCache  =  iLcCacheThree;    
       
   433             iLastSection = EFalse;
       
   434             break;
       
   435             }
       
   436         case EFileSubscribedFour:
       
   437             {
       
   438             iCurrentLcCache  =  iLcCacheFour;    
       
   439             iLastSection = EFalse;
       
   440             break;
       
   441             }
       
   442 
       
   443         case EFileHZ:
       
   444         case EFileTags:
       
   445         case EFileSettings:
       
   446         case EFileUnknown:
       
   447         default:
       
   448             {
       
   449             NWLOGSTRING( KNWOBJECT, 
       
   450                 "NW: CNWNetworkViagLcEngine::ParseSubscribed() NOT SUPPORTED \
       
   451                 element file" );
       
   452             break;
       
   453             }
       
   454         }
       
   455     ResetLcCache( *iCurrentLcCache );
       
   456     if ( aResponse.Length() >= 2 )
       
   457         {
       
   458         TLex8 parse ( aResponse );
       
   459         //************************************************    
       
   460         //** Network Coding is 3 bytes length 
       
   461         //************************************************
       
   462 
       
   463         iCurrentLcCache->iRatType = static_cast<TNWRatType> ( 
       
   464                 aResponse[0] & KNWRatMask ) ; 
       
   465         if ( (aResponse[0] == 0xFF) && (aResponse[1] ==0xFF) && 
       
   466                 (aResponse[2] ==0xFF))
       
   467             {
       
   468              // Lac file not contain any subscribed cells.
       
   469             NWLOGSTRING( KNWOBJECT, 
       
   470                 "NW: CNWNetworkViagLcEngine::ParseSubscribed(),\
       
   471                 ac file not contain any subscribed cells" );
       
   472             
       
   473              iCurrentLcCache->iCellSubscribed = EFalse;
       
   474             return;
       
   475             }
       
   476         iCurrentLcCache->iCellSubscribed = ETrue;
       
   477         TUint temp = ( aResponse[0] & KNWCodeMask) ;        
       
   478         temp =   temp  << 16  | aResponse[1] << 8  | aResponse[2] ;
       
   479         TBuf<6> netdes;
       
   480         netdes.Num(temp);    
       
   481         iCurrentLcCache->iMCC = netdes.Left( 3 );  
       
   482         NWLOGSTRING2( KNWOBJECT, 
       
   483             "NW: CNWNetworkViagLcEngine::ParseSubscribed() iMCC = %S", 
       
   484             &iCurrentLcCache->iMCC );
       
   485         if ( (aResponse[0] & KNWDigitMask) == 0x00 )
       
   486             {
       
   487             NWLOGSTRING( KNWOBJECT, 
       
   488                "NW: CNWNetworkViagLcEngine::ParseSubscribed(),\
       
   489                (aResponse[0] & KNWDigitMask) == 0x00 " );
       
   490             iCurrentLcCache->iMNC = netdes.Mid( 3,2 );  
       
   491             }
       
   492         else
       
   493             {
       
   494             iCurrentLcCache->iMNC = netdes.Right( 3 );      
       
   495             }
       
   496         NWLOGSTRING2( KNWOBJECT, 
       
   497             "NW: CNWNetworkViagLcEngine::ParseSubscribed() iMNC = %S", 
       
   498             &iCurrentLcCache->iMNC );
       
   499         parse.Inc( 3 ); //  Skip the network coding out because above used hard coded values.
       
   500         
       
   501         //*******************************************************
       
   502         //** Start field parsing.            
       
   503         //*******************************************************
       
   504         iCurrentLcCache->iCellSubscribed = ParseField( parse );
       
   505         }
       
   506     
       
   507     NWLOGSTRING( KNWOBJECT, 
       
   508         "NW: CNWNetworkViagLcEngine::ParseSubscribed() End" );
       
   509     }
       
   510 
       
   511 
       
   512 
       
   513 // ----------------------------------------------------------------------------
       
   514 // CNWNetworkViagLcEngine::ParseField
       
   515 // Parses fields from given string to iField 
       
   516 // ----------------------------------------------------------------------------
       
   517 //
       
   518 TBool CNWNetworkViagLcEngine::ParseField( TLex8& aParse )
       
   519     {
       
   520     NWLOGSTRING( KNWOBJECT, "NW: CNWNetworkViagLcEngine::ParseField() Begin" );
       
   521     // Parse so long that last section 
       
   522     
       
   523     while ( !iLastSection ) // Continue so long that last section is ongoing.
       
   524         {
       
   525         TBool invalid =  ParseSection( aParse ); // Parse next section...
       
   526         if ( invalid )
       
   527             {
       
   528             iLastSection = ETrue;
       
   529             return EFalse;
       
   530             //continue;
       
   531             }
       
   532 
       
   533         NWLOGSTRING2( KNWOBJECT, "NW: CNWNetworkViagLcEngine::ParseField(),\
       
   534             iCodingScheme = %d", iCodingScheme );
       
   535         
       
   536         for ( TInt fieldIndex = 0; fieldIndex < iNumberOfFields; fieldIndex++ ) // Section contains one or more fields.
       
   537             {
       
   538             TNWViagFieldContent field;
       
   539             if ( iCodingScheme == KCSTwo || 
       
   540                     iCodingScheme == KCSFour || 
       
   541                     iCodingScheme == KCSTen )
       
   542                 {
       
   543                 field.iFieldLAC = static_cast<TUint16> (( 
       
   544                     aParse.Get() << 8 ) | aParse.Get() ); 
       
   545                 NWLOGSTRING2( KNWOBJECT, 
       
   546                     "NW: CNWNetworkViagLcEngine::ParseField() CodingScheme is ok fieldLAC = %d ", field.iFieldLAC );
       
   547                 }
       
   548             else 
       
   549                 {
       
   550                 field.iFieldLAC  = 0; // no lac 
       
   551                 NWLOGSTRING( KNWOBJECT, 
       
   552                     "NW: CNWNetworkViagLcEngine::ParseField() No fieldLAC " );
       
   553                 }
       
   554             if (field.iFieldLAC == KInvalid )
       
   555                 {
       
   556                 NWLOGSTRING( KNWOBJECT, 
       
   557                    "NW: CNWNetworkViagLcEngine::ParseField() FieldLAC data is \
       
   558                    INVALID! " );
       
   559                 return EFalse;
       
   560                 //break;
       
   561                 }
       
   562             field.iWildCarded = !static_cast<TBool> ( aParse.Get() >> 7 );
       
   563             aParse.UnGet(); 
       
   564             iNumberOfUnits = static_cast<TInt> ( aParse.Get() & 0x7F );
       
   565             
       
   566             TLexMark8 start;
       
   567             TInt lastSection = iCurrentLcCache->iCache.Count();
       
   568             
       
   569             for ( TInt unitIndex = 0; unitIndex < iNumberOfUnits; unitIndex++  ) // Field contains one or more units.
       
   570                 {    
       
   571                 // Cell id is readed  
       
   572                 if ( iCodingScheme != KCSThree )
       
   573                     {
       
   574                     field.iUnitType = EUnitCellId;
       
   575                     }
       
   576                 else
       
   577                     {
       
   578                     field.iUnitType = EUnitLac; // If SC is 3 the only field contains lac units.
       
   579                     }
       
   580                 aParse.Mark( start );
       
   581                
       
   582                 for ( TInt offset = 1; offset <= 2; offset++ )
       
   583                     {
       
   584                     if ( aParse.Eos() )
       
   585                         {
       
   586                         return EFalse; 
       
   587                         }
       
   588                     aParse.Inc();
       
   589                     }
       
   590                 TPtrC8  ci = aParse.MarkedToken( start );
       
   591                 
       
   592                 // The iUnit is TBuf that contains the lac or ci in separated space like " 23800 44444 12345"    
       
   593 
       
   594                 TUint unit = ( ci[ 0 ] << 8 ) | ci [ 1 ] ;
       
   595                 NWLOGSTRING2( KNWOBJECT, 
       
   596                     "NW: CNWNetworkViagLcEngine::ParseField() unit = %d ", 
       
   597                     unit );
       
   598               
       
   599                 if (  unit  == KInvalid ) // Cell or LAC should not be 0xFF if is then there is no valid data.
       
   600                     {
       
   601                     NWLOGSTRING( KNWOBJECT, 
       
   602                         "NW: CNWNetworkViagLcEngine::ParseField() unit data is \
       
   603                         INVALID! " );
       
   604                     return EFalse;
       
   605                     //break;
       
   606                     }
       
   607                 AddInBufferAsTUint( field.iUnit, unit );
       
   608                 } // Inner for loop end.
       
   609 
       
   610             // Store the field information.    
       
   611             if ( iNumberOfUnits != 0 ||( iNumberOfUnits == 0 && 
       
   612                     iCodingScheme == KCSTwo ) )
       
   613                 {
       
   614                 iCurrentLcCache->iCache[lastSection-1].iField.Append( field );
       
   615                 }
       
   616             }// Outage for loop end.
       
   617         }// While loop end.
       
   618     NWLOGSTRING2( KNWOBJECT, "NW: CNWNetworkViagLcEngine::ParseField(),\
       
   619         after while loop the running variable iLastSection = %d",
       
   620         iLastSection );
       
   621 
       
   622     NWLOGSTRING( KNWOBJECT, "NW: CNWNetworkViagLcEngine::ParseField() End " );
       
   623     return ETrue;
       
   624 }
       
   625 
       
   626 
       
   627 
       
   628 // ----------------------------------------------------------------------------
       
   629 // CNWNetworkViagLcEngine::ParseSection
       
   630 // Finds a section information from given string and saves it to iCurrentCache struct. 
       
   631 // ----------------------------------------------------------------------------
       
   632 //
       
   633 TBool CNWNetworkViagLcEngine::ParseSection( TLex8& aParse  )             
       
   634     {
       
   635     NWLOGSTRING( KNWOBJECT, "NW: CNWNetworkViagLcEngine::ParseSection() Begin" );
       
   636 //*****************************************
       
   637 //** Section Description.
       
   638 //*****************************************
       
   639 
       
   640     TInt sectFirst = static_cast<TUint> ( aParse.Get() );
       
   641     TInt secSecond = static_cast<TUint> ( aParse.Get() );
       
   642 
       
   643     if ( sectFirst == KStopChar )
       
   644         {
       
   645         NWLOGSTRING( KNWOBJECT, 
       
   646             "NW: CNWNetworkViagLcEngine::ParseSection() Invalid data!! " );
       
   647         return ETrue; // Invalid data...  RETURN BOOLEAN IS SECTION VALID OR NOT:....
       
   648         }
       
   649 
       
   650     TNWViagSectionContent section;
       
   651     section.iCodingScheme = static_cast<TInt> (( sectFirst & 0x78 ) >>3 );
       
   652     iCodingScheme = section.iCodingScheme;
       
   653     if ( iCodingScheme != KCSTwo && iCodingScheme != KCSThree && 
       
   654             iCodingScheme != KCSFour &&iCodingScheme != KCSNine && 
       
   655             iCodingScheme != KCSTen )
       
   656         {
       
   657         NWLOGSTRING2( KNWOBJECT, 
       
   658            "NW: CNWNetworkViagLcEngine::ParseSection() Invalid CodingScheme = \
       
   659            %d !! ", iCodingScheme );
       
   660         return ETrue; // Invalid coding scheme...
       
   661         }
       
   662     section.iLastSection = static_cast<TBool> ( sectFirst >> 7 );  
       
   663     section.iZoneId = static_cast<TInt>( sectFirst & 0x07 );
       
   664     if ( secSecond == KStopChar )
       
   665         {
       
   666         iNumberOfFields = 0;
       
   667         }
       
   668     else
       
   669         {
       
   670         iNumberOfFields = secSecond;
       
   671         }
       
   672     
       
   673     iLastSection = section.iLastSection;
       
   674     iCurrentLcCache->iCache.Append( section ); // Store the section info.        
       
   675     
       
   676     NWLOGSTRING2( KNWOBJECT, 
       
   677         "NW: CNWNetworkViagLcEngine::ParseSection() iLastSection = %d", 
       
   678         iLastSection );
       
   679     NWLOGSTRING2( KNWOBJECT, 
       
   680         "NW: CNWNetworkViagLcEngine::ParseSection() iZoneId = %d", 
       
   681         section.iZoneId );
       
   682     NWLOGSTRING2( KNWOBJECT, 
       
   683         "NW: CNWNetworkViagLcEngine::ParseSection() Coding Scheme = %d", 
       
   684         iCodingScheme );
       
   685     NWLOGSTRING( KNWOBJECT, 
       
   686         "NW: CNWNetworkViagLcEngine::ParseSection() End" );
       
   687 
       
   688     return EFalse;
       
   689     }
       
   690 
       
   691 // ----------------------------------------------------------------------------
       
   692 // CNWNetworkViagLcEngine::IsGsmCellSubscribed
       
   693 // Returns a boolean to indicate if there is at least one subscribed GSM cell. 
       
   694 // ----------------------------------------------------------------------------
       
   695 //    
       
   696 TBool CNWNetworkViagLcEngine::IsGsmCellSubscribed()
       
   697     {
       
   698     NWLOGSTRING( KNWOBJECT, 
       
   699         "NW: CNWNetworkViagLcEngine::IsGsmCellSubscribed() Begin" );
       
   700     TBool subscribed( EFalse );
       
   701     for (TInt lacIndex = EFileSubscribedOne; lacIndex <= EFileSubscribedFour; lacIndex++)
       
   702         {
       
   703         switch ( lacIndex )
       
   704             {
       
   705             case EFileSubscribedOne:
       
   706                 { 
       
   707                 iCurrentLcCache  =  iLcCacheOne;            
       
   708                 break;    
       
   709                 }        
       
   710             case EFileSubscribedTwo:
       
   711                 {
       
   712                 iCurrentLcCache  =  iLcCacheTwo;    
       
   713                 break;
       
   714                 }
       
   715             case EFileSubscribedThree:
       
   716                 {
       
   717                 iCurrentLcCache  =  iLcCacheThree;    
       
   718                 break;
       
   719                 }
       
   720             case EFileSubscribedFour:
       
   721                 {
       
   722                 iCurrentLcCache  =  iLcCacheFour;    
       
   723                 break;
       
   724                 }
       
   725             default:
       
   726                 break;
       
   727             }
       
   728             //  Ask from 02 that should the ERatAny also be in here.
       
   729         if ( ( iCurrentLcCache->iRatType == ERatGsm || 
       
   730                 iCurrentLcCache->iRatType == ERatAny )  &&
       
   731                iCurrentLcCache->iCellSubscribed )
       
   732             {
       
   733             subscribed =  ETrue; // if any of four files contains gsm cells then return true
       
   734             }
       
   735         }
       
   736     
       
   737     NWLOGSTRING2( KNWOBJECT, 
       
   738         "NW: CNWNetworkViagLcEngine::IsGsmCellSubscribed() End,\
       
   739         Subscribed = %d", subscribed );
       
   740     return subscribed;
       
   741     }
       
   742 
       
   743 
       
   744 
       
   745 // ----------------------------------------------------------------------------
       
   746 // CNWNetworkViagLcEngine::CellReselection
       
   747 // Is called by CNWNetworkCurrentNetworkMonitor in case of cell re-selection.
       
   748 // ----------------------------------------------------------------------------
       
   749 //
       
   750 void CNWNetworkViagLcEngine::CellReselection( )
       
   751     {
       
   752     NWLOGSTRING( KNWOBJECT, 
       
   753         "NW: CNWNetworkViagLcEngine::CellReselection() Begin" );
       
   754     NWLOGSTRING2( KNWOBJECT, 
       
   755         "NW: CNWNetworkViagLcEngine::CellReselection() NetInfo LAC = %d ", 
       
   756         iInterNetworkInfo.iLac );
       
   757     NWLOGSTRING2( KNWOBJECT, 
       
   758         "NW: CNWNetworkViagLcEngine::CellReselection() NetInfo CountryCode = \
       
   759         %S ", &iNWNetworkInfo.iCountryCode );
       
   760     NWLOGSTRING2( KNWOBJECT, 
       
   761         "NW: CNWNetworkViagLcEngine::CellReselection() NetInfo NetworkId = %S"
       
   762         , &iNWNetworkInfo.iNetworkId );    
       
   763     
       
   764     TBuf<KCellAndLACLength> lacBuf;
       
   765     lacBuf.Num( iInterNetworkInfo.iLac );
       
   766     NWLOGSTRING2( KNWOBJECT, 
       
   767         "NW: CNWNetworkViagLcEngine::CellReselection() NetInfo CellId = %d ",
       
   768         iInterNetworkInfo.iCellId );
       
   769     TBuf<10> cellBuf;
       
   770     cellBuf.Num( iInterNetworkInfo.iCellId ); 
       
   771     iMatchFound = EFalse;
       
   772  
       
   773     if ( iNWNetworkInfo.iNetworkMode == ENWModeWcdma )
       
   774         {
       
   775         TInt64  desCell;
       
   776         TLex cellId( cellBuf );
       
   777         TUint realId;
       
   778         cellId.Val( desCell );
       
   779         realId = static_cast<TUint16> (I64LOW( desCell ) );
       
   780         cellBuf.Num( realId );
       
   781         }
       
   782 
       
   783     //*************************************
       
   784     //** Lc-Caches - for loop
       
   785     //*************************************
       
   786 
       
   787     for (TInt lacIndex = EFileSubscribedOne; lacIndex <= EFileSubscribedFour; lacIndex++)
       
   788         {
       
   789         // Very first thing to do is to check if we heve the match already.
       
   790         if ( iMatchFound )
       
   791             {
       
   792             break;
       
   793             }
       
   794 
       
   795         // Get the next LC cache
       
   796         switch ( lacIndex  )
       
   797             {
       
   798             case EFileSubscribedOne:
       
   799                 { 
       
   800                 iCurrentLcCache  =  iLcCacheOne;            
       
   801                 break;    
       
   802                 }        
       
   803             case EFileSubscribedTwo:
       
   804                 {
       
   805                 iCurrentLcCache  =  iLcCacheTwo;    
       
   806                 break;
       
   807                 }
       
   808             case EFileSubscribedThree:
       
   809                 {
       
   810                 iCurrentLcCache  =  iLcCacheThree;    
       
   811                 break;
       
   812                 }
       
   813             case EFileSubscribedFour:
       
   814                 {
       
   815                 iCurrentLcCache  =  iLcCacheFour;    
       
   816                 break;
       
   817                 }
       
   818             }
       
   819 
       
   820         //**************************************************************************
       
   821         //** MNC,MCC,RAT => Search and select LC-cache that match with MNC,MCC, RAT
       
   822         //**************************************************************************
       
   823         NWLOGSTRING2( KNWOBJECT, 
       
   824             "NW: CNWNetworkViagLcEngine::CellReselection() LacIndex  = %d \
       
   825             ( 0 = iLcCacheOne, ... , 3 =  iLcCacheFour )", lacIndex );
       
   826         NWLOGSTRING2( KNWOBJECT, 
       
   827             "NW: CNWNetworkViagLcEngine::CellReselection() \
       
   828             CountryCode = %S ", &iCurrentLcCache->iMCC );
       
   829         NWLOGSTRING2( KNWOBJECT, 
       
   830             "NW: CNWNetworkViagLcEngine::CellReselection() NetworkId   \
       
   831             = %S ", &iCurrentLcCache->iMNC );
       
   832         NWLOGSTRING2( KNWOBJECT, 
       
   833             "NW: CNWNetworkViagLcEngine::CellReselection() NetInfo \
       
   834             NetworkMode = %d ( 0=ENWModeUnknown, 1=ENWModeUnregistered, \
       
   835             2=ENWModeGsm, 3=ENWModeAmps, 4=ENWModeCdma95, 5=ENWModeCdma2000, \
       
   836             6=ENWModeWcdma, 7=ENWModeTdcdma ) ", 
       
   837             iNWNetworkInfo.iNetworkMode );
       
   838         NWLOGSTRING2( KNWOBJECT, 
       
   839             "NW: CNWNetworkViagLcEngine::CellReselection() RatType\
       
   840             = %d ( 0=ERatUtran, 64=ERatGsm, 128=ERatAny, \
       
   841             192=ERatUnvalid ) ", iCurrentLcCache->iRatType );
       
   842 
       
   843         // Data check. If there are no content there is no need to continue further
       
   844         if ( !iCurrentLcCache->iCellSubscribed )
       
   845             {
       
   846             // If no subscribed cell then change lac file. 
       
   847             continue; 
       
   848             }
       
   849         if ( iCurrentLcCache->iCache.Count() == 0 )
       
   850             {
       
   851             NWLOGSTRING( KNWOBJECT, 
       
   852                 "NW: CNWNetworkViagLcEngine::CellReselection() Lac file does \
       
   853                 not contain any data, change lac file" );
       
   854             continue; // Lac file doesn't contain any data change lac file.
       
   855             }
       
   856 
       
   857         // Network check. If the subscribed network is same than the current one 
       
   858         // then there are no need to continue further
       
   859         if( !HandleNetworkCheck() )
       
   860             {
       
   861             continue;                
       
   862             }
       
   863 
       
   864         //***************************************
       
   865         //**    SECTION - while loop
       
   866         //***************************************
       
   867         TInt sectionIndex( KErrNotFound );
       
   868         do 
       
   869             {
       
   870             sectionIndex++;
       
   871             // Index = section 
       
   872             iCodingScheme = iCurrentLcCache->iCache[sectionIndex].iCodingScheme;
       
   873             TInt fieldCount = iCurrentLcCache->iCache[sectionIndex].iField.Count();
       
   874             
       
   875             if ( iCodingScheme == KCSNine )
       
   876                 {
       
   877                 WriteViagValues( sectionIndex );
       
   878                 break; // go out field search
       
   879                 }
       
   880 
       
   881             NWLOGSTRING2( KNWOBJECT, 
       
   882                 "NW: CNWNetworkViagLcEngine::CellReselection() SECTION iCoding\
       
   883                 Scheme = %d ", iCodingScheme );
       
   884 
       
   885             //************************************
       
   886             //** FIELD - for loop
       
   887             //************************************
       
   888             for (TInt index = 0; index < fieldCount; index++ )
       
   889                 {
       
   890                 // In following codingschemes all the cells that belongs field lac
       
   891                 if ( iCodingScheme != KCSThree )
       
   892                     {
       
   893                     if( !HandleCellMatch( cellBuf, lacBuf, sectionIndex, index ) )
       
   894                        {
       
   895                        continue;
       
   896                        }
       
   897                     }
       
   898                 else
       
   899                     {
       
   900                     // Fos coding scheme 3
       
   901                     HandleLACMatch( sectionIndex, index, lacBuf );                  
       
   902                     }
       
   903                 
       
   904                 // Check if we got match
       
   905                 if ( iMatchFound )
       
   906                     {
       
   907                     break;
       
   908                     }
       
   909                 }
       
   910 
       
   911             } while ( !iCurrentLcCache->iCache[sectionIndex].iLastSection && 
       
   912                     !iMatchFound );
       
   913         
       
   914         NWLOGSTRING3( KNWOBJECT, 
       
   915             "NW: CNWNetworkViagLcEngine::CellReselection(), after do-while\
       
   916             loop condition variable iCurrentLcCache->iCache[sectionIndex].\
       
   917             iLastSection = %d, iMatchFound = %d ",
       
   918             iCurrentLcCache->iCache[sectionIndex].iLastSection,
       
   919             iMatchFound );
       
   920         } // for 
       
   921 
       
   922     NWLOGSTRING( KNWOBJECT, "NW: CNWNetworkViagLcEngine::CellReselection() End" );
       
   923     
       
   924     } // ************* CELL RESELECTION ******************
       
   925 
       
   926 // ----------------------------------------------------------------------------
       
   927 // CNWNetworkViagLcEngine::ResetLcCache
       
   928 // Is called by CNWNetworkCurrentNetworkMonitor in case of cell re-selection.
       
   929 // ----------------------------------------------------------------------------
       
   930 //
       
   931 void CNWNetworkViagLcEngine::ResetLcCache( TViagElementReocord& aCurrentcache )
       
   932     {
       
   933     NWLOGSTRING( KNWOBJECT, 
       
   934         "NW: CNWNetworkViagLcEngine::ResetLcCache() Begin" );
       
   935     
       
   936     NWLOGSTRING2( KNWOBJECT, 
       
   937         "NW: CNWNetworkViagLcEngine::ResetLcCache(),\
       
   938         aCurrentcache.iCache.Count() = %d ",
       
   939         aCurrentcache.iCache.Count() );
       
   940     
       
   941     if ( aCurrentcache.iCache.Count() > 0 )
       
   942         {
       
   943         for ( TInt index = 0; index < aCurrentcache.iCache.Count(); index ++ )
       
   944             {
       
   945             aCurrentcache.iCache[index].iField.Close();
       
   946             }
       
   947         aCurrentcache.iCache.Close();
       
   948         }
       
   949     aCurrentcache.iRatType = ERatUnvalid;
       
   950     aCurrentcache.iMCC = KNullDesC;
       
   951     aCurrentcache.iMNC = KNullDesC;
       
   952     aCurrentcache.iCellSubscribed = EFalse;
       
   953     
       
   954     NWLOGSTRING( KNWOBJECT, 
       
   955         "NW: CNWNetworkViagLcEngine::ResetLcCache() End" );
       
   956     }
       
   957 
       
   958 // ----------------------------------------------------------------------------
       
   959 // CNWNetworkViagLcEngine::WriteViagValues
       
   960 // Selects correct zone type and calls iBase class WriteViagValues method.
       
   961 // ----------------------------------------------------------------------------
       
   962 //
       
   963 void CNWNetworkViagLcEngine::WriteViagValues( TInt aSectionIndex )
       
   964     {
       
   965     NWLOGSTRING2( KNWOBJECT, 
       
   966         "NW: CNWNetworkViagLcEngine::WriteViagValues() Begin,\
       
   967         aSectionIndex = %d ", aSectionIndex );
       
   968     
       
   969     TInt zoneId( KErrNotFound );
       
   970     if ( aSectionIndex >= 0 && aSectionIndex < iCurrentLcCache->iCache.Count() )
       
   971         {
       
   972         zoneId = iCurrentLcCache->iCache[aSectionIndex].iZoneId;
       
   973         
       
   974 
       
   975         NWLOGSTRING2( KNWOBJECT, 
       
   976             "NW: CNWNetworkViagLcEngine::WriteViagValues() ZoneId = %d ( 4 = \
       
   977             CityZone others HomeZone )", zoneId );
       
   978         TNWViagIndicatorType zoneType;
       
   979 
       
   980         if ( zoneId == 0 ) // Homezone
       
   981             {
       
   982             zoneType = ENWViagIndicatorTypeHomeZone; 
       
   983             }    
       
   984         else
       
   985             {
       
   986             zoneType = ENWViagIndicatorTypeCityZone; 
       
   987             }
       
   988 
       
   989         iBase.WriteViagValues( zoneType, zoneId );
       
   990         iMatchFound = ETrue;
       
   991         }
       
   992     
       
   993     NWLOGSTRING( KNWOBJECT, 
       
   994         "NW: CNWNetworkViagLcEngine::WriteViagValues() End " );
       
   995     }
       
   996 
       
   997 
       
   998 // ----------------------------------------------------------------------------
       
   999 // CNWNetworkViagLcEngine::HandleNetworkCheck
       
  1000 // Check network parameters.
       
  1001 // ----------------------------------------------------------------------------
       
  1002 //
       
  1003 TBool CNWNetworkViagLcEngine::HandleNetworkCheck()
       
  1004     {
       
  1005     NWLOGSTRING( KNWOBJECT, 
       
  1006         "NW: CNWNetworkViagLcEngine::HandleNetworkCheck() Begin " );
       
  1007     
       
  1008     TBool networkOk = ETrue;
       
  1009     
       
  1010     if ( ( iNWNetworkInfo.iCountryCode  == iCurrentLcCache->iMCC ) &&
       
  1011          ( iNWNetworkInfo.iNetworkId  == iCurrentLcCache->iMNC ) )
       
  1012         {
       
  1013         if ( iNWNetworkInfo.iNetworkMode  == ENWModeGsm ) 
       
  1014             {
       
  1015             if ( iCurrentLcCache->iRatType != ERatGsm &&
       
  1016                  iCurrentLcCache->iRatType != ERatAny )
       
  1017                 {
       
  1018                 NWLOGSTRING( KNWOBJECT, 
       
  1019                     "NW: CNWNetworkViagLcEngine::CellReselection() MNC and MCC \
       
  1020                     mathes but iRatType != ERatGsm or iRatType != ERatAny ==> \
       
  1021                     next cache file !" );
       
  1022                 networkOk = EFalse;
       
  1023                 }
       
  1024             }
       
  1025         else if ( iNWNetworkInfo.iNetworkMode == ENWModeWcdma )
       
  1026             {
       
  1027              if ( iCurrentLcCache->iRatType != ERatUtran &&
       
  1028                   iCurrentLcCache->iRatType != ERatAny )
       
  1029                 {
       
  1030                 NWLOGSTRING( KNWOBJECT, 
       
  1031                    "NW: CNWNetworkViagLcEngine::CellReselection() MNC and MCC \
       
  1032                    mathes but iRatType != ERatUtran or iRatType != ERatAny \
       
  1033                    ==> next cache file !" );
       
  1034                 networkOk = EFalse;
       
  1035                 }
       
  1036             }
       
  1037         }
       
  1038     else
       
  1039         {
       
  1040         NWLOGSTRING( KNWOBJECT, 
       
  1041             "NW: CNWNetworkViagLcEngine::CellReselection() MNC or MCC does not\
       
  1042              match ==> next cache file !" );
       
  1043         networkOk = EFalse;    // The MNC or MCC doesn't match.===> next cache file.
       
  1044         }
       
  1045 
       
  1046     NWLOGSTRING2( KNWOBJECT, 
       
  1047         "NW: CNWNetworkViagLcEngine::HandleNetworkCheck() End,\
       
  1048         networkOk = %d ", networkOk );
       
  1049     return networkOk;
       
  1050     }
       
  1051     
       
  1052     
       
  1053 // -----------------------------------------------------------------------------
       
  1054 // CNWNetworkViagLcEngine::HandleCellMatch
       
  1055 // Search a matching cell id from given Cache index.
       
  1056 // -----------------------------------------------------------------------------
       
  1057 //
       
  1058 TBool CNWNetworkViagLcEngine::HandleCellMatch( 
       
  1059         const TDesC & aCell, const TDesC & aLac,
       
  1060         TInt aSectionIndex, TInt aIndex )
       
  1061     {
       
  1062     NWLOGSTRING3( KNWOBJECT, 
       
  1063         "NW: CNWNetworkViagLcEngine::HandleCellMatch() Begin,\
       
  1064         aSectionIndex = %d, aIndex = %d", 
       
  1065         aSectionIndex, aIndex );
       
  1066     
       
  1067     TBool retVal = ETrue;
       
  1068     TInt sectionIndex = aSectionIndex;
       
  1069     TInt index = aIndex;
       
  1070    
       
  1071     TBuf<KCellAndLACLength> tempLac;
       
  1072     tempLac.Num(  iCurrentLcCache->iCache[sectionIndex].iField[index].iFieldLAC ); 
       
  1073     NWLOGSTRING2( KNWOBJECT, 
       
  1074         "NW: CNWNetworkViagLcEngine::HandleCellMatch() Field FieldLAC = %d ", 
       
  1075         iCurrentLcCache->iCache[sectionIndex].iField[index].iFieldLAC  );
       
  1076     NWLOGSTRING2( KNWOBJECT, 
       
  1077         "NW: CNWNetworkViagLcEngine::HandleCellMatch() NetInfo LAC = %d ", 
       
  1078         iInterNetworkInfo.iLac );
       
  1079                
       
  1080     if ( iCodingScheme == KCSTen )  // CodingScheme 10 LAC is wildcarded "123**"
       
  1081         {
       
  1082         if ( aLac.Left( 3 ) != tempLac.Left( 3 ) ) 
       
  1083             {
       
  1084             NWLOGSTRING( KNWOBJECT, 
       
  1085                 "NW: CNWNetworkViagLcEngine::HandleCellMatch() FIELD loop LAC\
       
  1086                  does not Match ");
       
  1087             retVal = EFalse; // Lac doesn't match go next FIELD
       
  1088             }
       
  1089         }
       
  1090     else if ( tempLac != aLac ) // Coding schemes 2,4...
       
  1091         {
       
  1092         NWLOGSTRING( KNWOBJECT, "NW: CNWNetworkViagLcEngine::HandleCellMatch()\
       
  1093                  FIELD loop LAC does not Match CodingScheme != 10 ");
       
  1094         // If Lac doesn't match then go next Field because the Lac is descriped in Field
       
  1095         retVal = EFalse;
       
  1096         }    
       
  1097 
       
  1098     // *************************************************
       
  1099     // ** Match cell 
       
  1100     // *************************************************
       
  1101 
       
  1102     if ( retVal )
       
  1103         {
       
  1104         TInt match( KErrNotFound );
       
  1105         NWLOGSTRING( KNWOBJECT, 
       
  1106             "NW: CNWNetworkViagLcEngine::HandleCellMatch() LAC MATCHS ");
       
  1107         if ( iCurrentLcCache->iCache[sectionIndex].iField[index].iUnitType == EUnitCellId )
       
  1108             {    
       
  1109             NWLOGSTRING( KNWOBJECT, 
       
  1110                 "NW: CNWNetworkViagLcEngine::CellReselection()  \
       
  1111                 Unit Type *CELL* ");
       
  1112 
       
  1113             NWLOGSTRING( KNWOBJECT, 
       
  1114                 "NW: CNWNetworkViagLcEngine::HandleCellMatch() \
       
  1115                 MATH CELL Wild Card Used" );
       
  1116             TBuf<5> workBuf;
       
  1117             workBuf.Zero();
       
  1118             TInt cursorPos = 0;
       
  1119             
       
  1120             TInt dataLen = iCurrentLcCache->iCache[sectionIndex].iField[index].iUnit.Length();
       
  1121             
       
  1122             TPtrC  cmpCell;
       
  1123             //*********** WHILE *********************
       
  1124             while ( match == KErrNotFound ) // Match is found or we are end of string.
       
  1125                 {
       
  1126                 if ( cursorPos == dataLen )
       
  1127                     {
       
  1128                     // The end of data reached
       
  1129                     break;
       
  1130                     }
       
  1131                 TUint unit( iCurrentLcCache->iCache[sectionIndex].iField[index].iUnit[cursorPos] );
       
  1132                 workBuf.Zero();
       
  1133                 // Expand TUint into string for the comparisation operations
       
  1134                 ExtendTUintIntoBuffer( workBuf, unit );
       
  1135                 cmpCell.Set( workBuf );
       
  1136                 
       
  1137                 NWLOGSTRING2( KNWOBJECT, 
       
  1138                     "NW: CNWNetworkViagLcEngine::HandleCellMatch()  CELL ID %S\
       
  1139                      FROM LAC FILE", &cmpCell );
       
  1140                 NWLOGSTRING2( KNWOBJECT, 
       
  1141                     "NW: CNWNetworkViagLcEngine::HandleCellMatch()  CELL ID %S\
       
  1142                     FROM NETWORK", &aCell ); 
       
  1143                 if ( cmpCell.Length() > 0 )
       
  1144                     {
       
  1145                     if ( iCurrentLcCache->iCache[sectionIndex].iField[index].iWildCarded )
       
  1146                         {
       
  1147                         // If cell is id start with "6" make exact match.
       
  1148                         if ( cmpCell[0] == '6' && cmpCell.Length() == KCellAndLACLength ||
       
  1149                              aCell[0] == '6' && aCell.Length() == KCellAndLACLength )   // If the wild card is in use 
       
  1150                             {
       
  1151                             if ( aCell == cmpCell ) 
       
  1152                                 {
       
  1153                                 match = KErrNone;
       
  1154                                 }
       
  1155                             }
       
  1156                         else 
       
  1157                             {
       
  1158                             if ( aCell.Length() < KCmpLength || cmpCell.Length() < KCmpLength )
       
  1159                                 {
       
  1160                                 match = CompareTIntCellIdValues( aCell, cmpCell );
       
  1161                                 }
       
  1162                             else
       
  1163                                 {
       
  1164                                 if ( aCell.Right( KCmpLength ) == cmpCell.Right( KCmpLength )  )
       
  1165                                     {
       
  1166                                     match = KErrNone;
       
  1167                                     }
       
  1168                                 }
       
  1169                             }
       
  1170                         } //  **** Wild card if 
       
  1171                     else
       
  1172                         {
       
  1173                         if ( aCell == cmpCell ) 
       
  1174                             {
       
  1175                             NWLOGSTRING( KNWOBJECT, 
       
  1176                                 "NW: CNWNetworkViagLcEngine::HandleCellMatch()\
       
  1177                                  EXACT MATCH FOUND *NO WC * " );
       
  1178                             match = KErrNone;
       
  1179                             }
       
  1180                         }
       
  1181                     }                                    
       
  1182                     cursorPos++;                                    
       
  1183                     
       
  1184                 } //***************** WHILE END *****************
       
  1185     
       
  1186             } // if ( iCurrentLcCache->iCache[sectionIndex].iField[index].iUnitType == EUnitCellId ) 
       
  1187         
       
  1188         //************************************************                        
       
  1189         //** Match cell End.    
       
  1190         //************************************************
       
  1191                 
       
  1192         // If match is found call writeViagValues, BUT in CS 2 match MUST be KErrNotFound that
       
  1193         // values is updated    
       
  1194         if ( ( match != KErrNotFound && iCodingScheme != KCSTwo ) ||
       
  1195              ( match == KErrNotFound && iCodingScheme == KCSTwo ) )
       
  1196             {
       
  1197             WriteViagValues( sectionIndex );
       
  1198             }    
       
  1199         }
       
  1200     NWLOGSTRING2( KNWOBJECT, 
       
  1201         "NW: CNWNetworkViagLcEngine::HandleCellMatch() End,\
       
  1202         retVal = %d", retVal );
       
  1203     
       
  1204     return retVal;
       
  1205     }
       
  1206 
       
  1207 // ----------------------------------------------------------------------------
       
  1208 // CNWNetworkViagLcEngine::HandleLACMatch
       
  1209 // Finds a matching Lac Id.
       
  1210 // ----------------------------------------------------------------------------
       
  1211 //
       
  1212 void CNWNetworkViagLcEngine::HandleLACMatch( 
       
  1213         TInt aSectionIndex, 
       
  1214         TInt aIndex, 
       
  1215         const TDesC& aLacBuf )
       
  1216     {
       
  1217     NWLOGSTRING3( KNWOBJECT, 
       
  1218         "NW: CNWNetworkViagLcEngine::HandleLACMatch() \
       
  1219         Begin, aSectionIndex = %d, aIndex = %d ",
       
  1220         aSectionIndex, aIndex );
       
  1221     
       
  1222     // Make sure that unit contains lac units.
       
  1223     TInt match( KErrNotFound );
       
  1224 
       
  1225     if ( iCurrentLcCache->iCache[aSectionIndex].iField[aIndex].iUnitType == EUnitLac )
       
  1226         {
       
  1227         TBuf<5> workBuf;    // This is enough for TUint16 (max value 65655)
       
  1228         TInt cursorPos = 0;
       
  1229         TInt dataLen = iCurrentLcCache->iCache[aSectionIndex].iField[aIndex].iUnit.Length();
       
  1230 
       
  1231         TPtrC  cmpLac;
       
  1232         while ( match == KErrNotFound ) // Match is found or we are end of string.
       
  1233             {
       
  1234             NWLOGSTRING( KNWOBJECT, 
       
  1235                 "NW: CNWNetworkViagLcEngine::HandleLACMatch()  *2*" );
       
  1236             if( cursorPos == dataLen )
       
  1237                 {
       
  1238                 NWLOGSTRING( KNWOBJECT, 
       
  1239                     "NW: CNWNetworkViagLcEngine::HandleLACMatch()  *3*" );
       
  1240                 break;
       
  1241                 }
       
  1242             NWLOGSTRING( KNWOBJECT, 
       
  1243                 "NW: CNWNetworkViagLcEngine::HandleLACMatch()  *4 *" );
       
  1244             // Get the LAC id as TUint...
       
  1245             TUint unit( iCurrentLcCache->iCache[aSectionIndex].iField[aIndex].iUnit[cursorPos] );
       
  1246             // ... and expand TUint into string for the comparisation operations
       
  1247             workBuf.Zero();
       
  1248             ExtendTUintIntoBuffer( workBuf, unit );
       
  1249             cmpLac.Set( workBuf );
       
  1250 
       
  1251 
       
  1252             NWLOGSTRING2( KNWOBJECT, 
       
  1253                 "NW: CNWNetworkViagLcEngine::HandleLACMatch()  LAC ID %S FROM \
       
  1254                 LAC FILE", &cmpLac );
       
  1255             NWLOGSTRING2( KNWOBJECT, 
       
  1256                 "NW: CNWNetworkViagLcEngine::HandleLACMatch()  LAC ID %S FROM \
       
  1257                 NETWORK", &aLacBuf ); 
       
  1258             if ( cmpLac.Length() > 0 )
       
  1259                 {  
       
  1260                 if ( aLacBuf == cmpLac )
       
  1261                     {
       
  1262                     NWLOGSTRING( KNWOBJECT, 
       
  1263                         "NW: CNWNetworkViagLcEngine::HandleLACMatch()  *5* LAC \
       
  1264                         MATCH FOUND" );
       
  1265                     match = KErrNone;
       
  1266                     WriteViagValues( aSectionIndex );
       
  1267                     }
       
  1268                 }
       
  1269             cursorPos++;    
       
  1270             } // ******************* while END ***********************
       
  1271         }// If lac is found then all cell ids are ok...
       
  1272 
       
  1273     NWLOGSTRING( KNWOBJECT, 
       
  1274         "NW: CNWNetworkViagLcEngine::HandleLACMatch() End " );
       
  1275     }
       
  1276 
       
  1277 // -----------------------------------------------------------------------------
       
  1278 // CNWNetworkViagLcEngine::CompareTIntCellIdValues
       
  1279 // 
       
  1280 // -----------------------------------------------------------------------------
       
  1281 // 
       
  1282 TInt CNWNetworkViagLcEngine::CompareTIntCellIdValues( 
       
  1283         const TDesC& aCell, 
       
  1284         const TDesC& aCmpCell )
       
  1285     {
       
  1286     NWLOGSTRING3( KNWOBJECT, 
       
  1287         "NW: CNWNetworkViagLcEngine::CompareTIntCellIdValues() Begin,\
       
  1288         aCell.length() = %d, aCmpCell.length() = %d ",
       
  1289         aCell.Length(), aCmpCell.Length() );
       
  1290     
       
  1291     TLex tempCellId( aCell.Right( KCmpLength ) );
       
  1292     TLex tempCmpCellId ( aCmpCell.Right( KCmpLength ) );
       
  1293                              
       
  1294     TInt cellid;
       
  1295     TInt cmpcellid;
       
  1296     TInt err = tempCellId.Val( cellid );
       
  1297     err = tempCmpCellId.Val( cmpcellid );
       
  1298     
       
  1299     if ( err == KErrNone && cellid == cmpcellid )
       
  1300         {
       
  1301         NWLOGSTRING3( KNWOBJECT, 
       
  1302             "NW: CNWNetworkViagLcEngine::CompareTIntCellIdValues(),\
       
  1303             err = %d, cellid = %d ", err, cellid );
       
  1304         return KErrNone;
       
  1305         }
       
  1306     else 
       
  1307         {
       
  1308         NWLOGSTRING( KNWOBJECT, 
       
  1309             "NW: CNWNetworkViagLcEngine::CompareTIntCellIdValues(),\
       
  1310             values not match " );
       
  1311         return KErrNotFound;
       
  1312         }
       
  1313     
       
  1314     NWLOGSTRING( KNWOBJECT, 
       
  1315         "NW: CNWNetworkViagLcEngine::CompareTIntCellIdValues() End " );
       
  1316     }
       
  1317 
       
  1318 //  End of File