xdmprotocols/XcapProtocol/XcapUtils/src/XcapEarlyIms.cpp
changeset 0 c8caa15ef882
equal deleted inserted replaced
-1:000000000000 0:c8caa15ef882
       
     1 /*
       
     2 * Copyright (c) 2005 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:   CXcapEarlyIms
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #ifdef _DEBUG
       
    23     #include <f32file.h>  
       
    24     #include <flogger.h>
       
    25     #include <e32debug.h>
       
    26 #endif
       
    27 #include <cdblen.h>
       
    28 #include <commsdat.h>
       
    29 #include <metadatabase.h>
       
    30 #include <commsdattypesv1_1.h>
       
    31 #include <mmretrieve.h>
       
    32 #include "XcapEarlyIms.h"
       
    33 #include "XcapUtilsInterface.h"
       
    34 
       
    35 // ----------------------------------------------------------
       
    36 // CXcapEarlyIms::CXcapEarlyIms
       
    37 // 
       
    38 // ----------------------------------------------------------
       
    39 //
       
    40 CXcapEarlyIms::CXcapEarlyIms() : CActive( EPriorityNormal ),
       
    41                                  iRequestComplete( EFalse ),
       
    42                                  iSimType( ESimTypeUnknown )
       
    43                                  
       
    44     { 
       
    45     }
       
    46 
       
    47 // ----------------------------------------------------------
       
    48 // CXcapEarlyIms::NewL
       
    49 // 
       
    50 // ----------------------------------------------------------
       
    51 //
       
    52 EXPORT_C CXcapEarlyIms* CXcapEarlyIms::NewL()
       
    53     {
       
    54     CXcapEarlyIms* self = new ( ELeave ) CXcapEarlyIms();
       
    55     CleanupStack::PushL( self );
       
    56     self->ConstructL();
       
    57     CleanupStack::Pop();  //self
       
    58     return self;
       
    59     }
       
    60 
       
    61 // ----------------------------------------------------
       
    62 // CXcapEarlyIms::~CXcapEarlyIms
       
    63 // 
       
    64 // ----------------------------------------------------
       
    65 //
       
    66 CXcapEarlyIms::~CXcapEarlyIms()
       
    67     {
       
    68     #ifdef _DEBUG
       
    69         WriteToLog( _L8( "CXcapEarlyIms::~CXcapEarlyIms()" ) );
       
    70     #endif
       
    71     delete iImpu;
       
    72     delete iImpi;
       
    73     delete iAuthData;
       
    74     delete iRetriever;
       
    75     iPhone.Close();
       
    76     iServer.Close();
       
    77     }
       
    78 
       
    79 // ----------------------------------------------------------
       
    80 // CXcapEarlyIms::ConstructL
       
    81 // 
       
    82 // ----------------------------------------------------------
       
    83 //
       
    84 void CXcapEarlyIms::ConstructL()
       
    85     {
       
    86     #ifdef _DEBUG
       
    87         DeleteLogFileL();
       
    88         WriteToLog( _L8( "CXcapEarlyIms::ConstructL()" ) );
       
    89     #endif
       
    90     #ifndef __FAKE_IMPU__
       
    91         TName tsyName;
       
    92         TInt numPhone = 0;
       
    93         TBool found = EFalse;
       
    94         RTelServer::TPhoneInfo phoneInfo;
       
    95         User::LeaveIfError( iServer.Connect() );
       
    96         TBuf<KCommsDbSvrMaxFieldLength> tsyModuleName;
       
    97 	    ModuleNameL( tsyModuleName );
       
    98         User::LeaveIfError( iServer.LoadPhoneModule( tsyModuleName ) );
       
    99         User::LeaveIfError( iServer.EnumeratePhones( numPhone ) );
       
   100         for( TInt i = 0;!found && i < numPhone;i++ )
       
   101             {
       
   102             User::LeaveIfError( iServer.GetTsyName( i, tsyName ) );
       
   103             User::LeaveIfError( iServer.GetPhoneInfo( i, phoneInfo ) );
       
   104             if( tsyName.CompareF( tsyModuleName ) == 0 )
       
   105                 found = ETrue;
       
   106             }
       
   107         __ASSERT_ALWAYS( found, User::Leave( KErrNotFound ) );
       
   108         User::LeaveIfError( iPhone.Open( iServer, phoneInfo.iName ) ); 
       
   109         SelectSimTypeL();
       
   110     #endif
       
   111     CActiveScheduler::Add( this );    
       
   112     } 
       
   113 
       
   114 // ----------------------------------------------------------
       
   115 // CXcapEarlyIms::RequestSimDataL
       
   116 // 
       
   117 // ----------------------------------------------------------
       
   118 //
       
   119 EXPORT_C void CXcapEarlyIms::RequestSimDataL( MXcapEarlyImsObs* aObserver )
       
   120     {
       
   121     #ifdef _DEBUG
       
   122         WriteToLog( _L8( "CXcapEarlyIms::RequestSimDataL()" ) );
       
   123     #endif
       
   124     #ifdef __FAKE_IMPU__
       
   125         iStatus = KRequestPending;
       
   126         TRequestStatus* status = &iStatus;
       
   127         User::RequestComplete( status, KErrNone );
       
   128         SetActive();
       
   129     #else
       
   130         if( !IsActive() )
       
   131 		    {
       
   132 		    TUint32 caps( 0 );    
       
   133             User::LeaveIfError( iPhone.GetIdentityCaps( caps ) );
       
   134             if( !( caps & RMobilePhone::KCapsGetSubscriberId ) )
       
   135 	  	        User::Leave( KErrNotSupported );
       
   136             iPhone.GetSubscriberId( iStatus, iImsi );
       
   137             iRequestPhase = TRequestAuth;
       
   138             iRequestComplete = EFalse;
       
   139 		    SetActive(); 
       
   140     	    }
       
   141     #endif 
       
   142     iObserver = aObserver;   
       
   143     }
       
   144 
       
   145 // ----------------------------------------------------------
       
   146 // CXcapEarlyIms::PublicIDL
       
   147 // 
       
   148 // ----------------------------------------------------------
       
   149 //
       
   150 EXPORT_C TPtrC8 CXcapEarlyIms::PublicIDL()
       
   151     {
       
   152     #ifdef _DEBUG
       
   153         WriteToLog( _L8( "CXcapEarlyIms::PublicIDL()" ) );
       
   154     #endif
       
   155     #ifdef __FAKE_IMPU__
       
   156         return KXcapFakeImpu();
       
   157     #else
       
   158         if( iRequestComplete && iRequestPhase == TRequestIdle )
       
   159             {
       
   160             switch( iSimType )
       
   161                 {
       
   162                 case ESimTypeWcdma:
       
   163                     return iAuthData->iIMPUArray[0]; 
       
   164                 case ESimTypeGsm:
       
   165                     return DeriveL();
       
   166                 default:
       
   167                     return TPtrC8();
       
   168                 }
       
   169             }
       
   170         else return TPtrC8(); 
       
   171     #endif
       
   172     }
       
   173 
       
   174 // ----------------------------------------------------------
       
   175 // CXcapEarlyIms::DeriveL
       
   176 // 
       
   177 // ----------------------------------------------------------
       
   178 //
       
   179 TPtrC8 CXcapEarlyIms::DeriveL()
       
   180     {
       
   181     #ifdef _DEBUG
       
   182         WriteToLog( _L8( "CXcapEarlyIms::DeriveL()" ) );
       
   183     #endif
       
   184     _LIT8( KImsMnc,       "ims.mnc" );
       
   185     _LIT8( KMcc,          ".mcc" );
       
   186     _LIT8( K3gppnetwork,  ".3gppnetwork.org");
       
   187     _LIT8( KAt,           "@");
       
   188     _LIT8( KSip,          "sip:");
       
   189     _LIT8( KZero,         "0");
       
   190     TPtrC networkDesc( iNetworkInfoPckg().iNetworkId );
       
   191     TPtrC countryDesc( iNetworkInfoPckg().iCountryCode );
       
   192     TInt nwlength = networkDesc.Length() + countryDesc.Length();
       
   193     if( networkDesc.Length() == 2 )
       
   194         nwlength = nwlength + 1;
       
   195     //private user identity
       
   196     TInt impiLength = iImsi.Length() + KAt().Length() + KImsMnc().Length() +
       
   197                       nwlength + KMcc().Length() + K3gppnetwork().Length();   
       
   198     iImpi = HBufC8::NewL( impiLength );
       
   199 	TPtr8 impiDesc( iImpi->Des() );
       
   200 	impiDesc.Append( iImsi );
       
   201 	impiDesc.Append( KAt );
       
   202 	impiDesc.Append( KImsMnc );
       
   203 	if( networkDesc.Length() == 2 )
       
   204     	impiDesc.Append( KZero );
       
   205 	impiDesc.Append( networkDesc );	
       
   206 	impiDesc.Append( KMcc );	
       
   207 	impiDesc.Append( countryDesc );
       
   208 	impiDesc.Append( K3gppnetwork );
       
   209     //public user identity
       
   210     TInt impuLength = KSip().Length() + impiDesc.Length();
       
   211     iImpu = HBufC8::NewL( impuLength );
       
   212     TPtr8 impuDesc( iImpu->Des() );
       
   213     impuDesc.Append( KSip );
       
   214 	impuDesc.Append( impiDesc );
       
   215 	#ifdef _DEBUG
       
   216         WriteToLog( _L8( "  IMPI: %S" ), &impiDesc );
       
   217         WriteToLog( _L8( "  IMPU: %S" ), &impuDesc );
       
   218     #endif
       
   219     return impuDesc;  
       
   220     }
       
   221 
       
   222 // ----------------------------------------------------------
       
   223 // CXcapEarlyIms::SelectSimTypeL
       
   224 // 
       
   225 // ----------------------------------------------------------
       
   226 //
       
   227 void CXcapEarlyIms::SelectSimTypeL()
       
   228     {
       
   229     #ifdef _DEBUG
       
   230         WriteToLog( _L8( "CXcapEarlyIms::SelectSimTypeL()" ) );
       
   231     #endif
       
   232 	TUint32 caps;
       
   233 	User::LeaveIfError( iPhone.GetIccAccessCaps( caps ) );
       
   234 	if( caps & RMobilePhone::KCapsSimAccessSupported )
       
   235 		{
       
   236 		if( caps & RMobilePhone::KCapsUSimAccessSupported )
       
   237 		    {			
       
   238 		    #ifdef _DEBUG
       
   239                 WriteToLog( _L8( "  USIM Card" ) );
       
   240             #endif
       
   241 		    iSimType = ESimTypeWcdma;
       
   242 		    }
       
   243 		else
       
   244 		    {
       
   245 		    #ifdef _DEBUG
       
   246                 WriteToLog( _L8( "  2G SIM Card" ) );
       
   247             #endif
       
   248 		    iSimType = ESimTypeGsm;
       
   249 		    }
       
   250 		}
       
   251     else
       
   252         {
       
   253         #ifdef _DEBUG
       
   254             WriteToLog( _L8( "  No SIM Card" ) );
       
   255         #endif
       
   256         iSimType = ESimTypeUnknown;
       
   257         }
       
   258     }
       
   259 		    
       
   260 // ----------------------------------------------------------
       
   261 // CXcapEarlyIms::RunL
       
   262 // 
       
   263 // ----------------------------------------------------------
       
   264 //
       
   265 void CXcapEarlyIms::RunL()
       
   266     {
       
   267     #ifdef _DEBUG
       
   268         WriteToLog( _L8( "CXcapEarlyIms::RunL()" ) );
       
   269         WriteToLog( _L8( "  Status:        %d" ), iStatus.Int() );
       
   270         WriteToLog( _L8( "  Request phase: %d" ), iRequestPhase );
       
   271     #endif
       
   272     #ifdef __FAKE_IMPU__
       
   273         iObserver->RequestComplete( KErrNone );
       
   274     #else
       
   275         if( iStatus.Int() == KErrNone )
       
   276             {
       
   277             switch( iRequestPhase )
       
   278                 {
       
   279                 case TRequestIdle:
       
   280                     break; 
       
   281                 case TRequestAuth:
       
   282                     {
       
   283                     #ifdef _DEBUG
       
   284                         HBufC8* buf = HBufC8::NewLC( iImsi.Length() );
       
   285                         TPtr8 desc( buf->Des() );
       
   286                         desc.Copy( iImsi );
       
   287                         WriteToLog( _L8( "  IMSI retrieved: %S" ), &desc );
       
   288                         CleanupStack::PopAndDestroy();  //buf
       
   289                     #endif
       
   290                     iPhone.GetHomeNetwork( iStatus, iNetworkInfoPckg );
       
   291                     iRequestPhase = TRequestNetwork;
       
   292                     SetActive(); 
       
   293                     }
       
   294                     break;
       
   295                 case TRequestNetwork:
       
   296                     {
       
   297                     #ifdef _DEBUG
       
   298                         HBufC8* nwid = HBufC8::NewLC( iNetworkInfoPckg().iNetworkId.Length() );
       
   299                         HBufC8* country = HBufC8::NewLC( iNetworkInfoPckg().iCountryCode.Length() );
       
   300                         TPtr8 desc1( nwid->Des() );
       
   301                         TPtr8 desc2( country->Des() );
       
   302                         desc1.Copy( iNetworkInfoPckg().iNetworkId );
       
   303                         desc2.Copy( iNetworkInfoPckg().iCountryCode );
       
   304                         WriteToLog( _L8( "  Home network info retrieved" ) );
       
   305                         WriteToLog( _L8( "    Network ID:   %S" ), &desc1 );
       
   306                         WriteToLog( _L8( "    Country code: %S" ), &desc2  );
       
   307                         CleanupStack::PopAndDestroy( 2 );  //country, nwid
       
   308                     #endif
       
   309                     if( iSimType == ESimTypeWcdma )
       
   310                         {
       
   311     	                iAuthData = RMobilePhone::CImsAuthorizationInfoV5::NewL();
       
   312             	        iRetriever = CAsyncRetrieveAuthorizationInfo::NewL( iPhone, *iAuthData );
       
   313                         iRequestPhase = TRequestUsimAuth;
       
   314 	    	            iRetriever->Start( iStatus );
       
   315 	        	        SetActive();
       
   316                         }
       
   317                     else
       
   318                         {
       
   319                         #ifdef _DEBUG
       
   320                             WriteToLog( _L8( "  Request complete" ) );
       
   321                         #endif
       
   322                         iObserver->RequestComplete( KErrNone );
       
   323                         iRequestPhase = TRequestIdle;
       
   324                         iRequestComplete = ETrue;
       
   325                         }
       
   326                     }
       
   327                     break;
       
   328                 case TRequestUsimAuth:
       
   329                     {
       
   330                     #ifdef _DEBUG
       
   331                         RMobilePhone::TAuthorizationDataSource source(
       
   332                             iAuthData->iAuthenticationDataSource );
       
   333                         TBuf8<4> sourceDesc( source == RMobilePhone::EFromUSIM
       
   334                             ? _L8( "USIM" ) : _L8( "ISIM" ) );  
       
   335                         WriteToLog( _L8( "  USIM auth retrieved" ) );
       
   336                         WriteToLog( _L8( "    IMPI:           %S" ), &iAuthData->iIMPI );
       
   337                         WriteToLog( _L8( "    IMPU:           %S" ), &iAuthData->iIMPUArray[0] );
       
   338                         WriteToLog( _L8( "    Domain:         %S" ), &iAuthData->iHomeNetworkDomainName );
       
   339                         WriteToLog( _L8( "    AuthDataSource: %S" ), &sourceDesc );
       
   340                     #endif
       
   341                     iObserver->RequestComplete( KErrNone );
       
   342                     iRequestPhase = TRequestIdle;
       
   343                     iRequestComplete = ETrue;
       
   344                     }
       
   345                     break;
       
   346                 default:
       
   347                     break;
       
   348                 }
       
   349             }
       
   350         else iObserver->RequestComplete( iStatus.Int() );
       
   351     #endif
       
   352     }
       
   353     
       
   354 // ----------------------------------------------------------
       
   355 // CXcapEarlyIms::DoCancel
       
   356 // 
       
   357 // ----------------------------------------------------------
       
   358 //
       
   359 void CXcapEarlyIms::DoCancel()
       
   360     {
       
   361     #ifdef _DEBUG
       
   362         WriteToLog( _L8( "CXcapEarlyIms::DoCancel() - State: %d" ), iRequestPhase );
       
   363     #endif
       
   364     switch( iRequestPhase )
       
   365         {
       
   366         case TRequestIdle:
       
   367             break; 
       
   368         case TRequestAuth:
       
   369             iPhone.CancelAsyncRequest( EMobilePhoneGetSubscriberId );
       
   370             break;
       
   371         case TRequestNetwork:
       
   372             iPhone.CancelAsyncRequest( EMobilePhoneGetHomeNetwork );
       
   373             break;
       
   374         case TRequestUsimAuth:
       
   375             delete iRetriever;
       
   376             iRetriever = NULL;
       
   377             break;
       
   378         default:
       
   379             break;
       
   380         }
       
   381     }
       
   382 
       
   383 // ----------------------------------------------------------
       
   384 // CXcapEarlyIms::ModuleNameL
       
   385 // 
       
   386 // ----------------------------------------------------------
       
   387 //
       
   388 void CXcapEarlyIms::ModuleNameL( TDes& aModuleName ) const
       
   389     {
       
   390     __ASSERT_ALWAYS( aModuleName.MaxSize() >= KCommsDbSvrMaxFieldLength, User::Leave( KErrArgument ) );
       
   391     using namespace CommsDat;
       
   392     CMDBSession* db = CMDBSession::NewLC( KCDLatestVersion );
       
   393     CMDBField<TUint32>* field = new ( ELeave ) CMDBField<TUint32>( KCDTIdModemPhoneServicesSMS );
       
   394     CleanupStack::PushL( field );
       
   395     field->SetRecordId( 1 );
       
   396     field->LoadL( *db );
       
   397     TUint32 modemId = *field;
       
   398     CMDBField<TDesC>* tsyField = new ( ELeave ) CMDBField<TDesC>( KCDTIdTsyName );
       
   399     CleanupStack::PushL( tsyField );
       
   400     tsyField->SetRecordId( modemId );
       
   401     tsyField->LoadL( *db );
       
   402     aModuleName = *tsyField;
       
   403     CleanupStack::PopAndDestroy( 3 ); //tsyField, field, db
       
   404     }
       
   405  
       
   406 #ifdef _DEBUG              
       
   407 // ----------------------------------------------------
       
   408 // CXcapEarlyIms::WriteToLog
       
   409 //
       
   410 // ----------------------------------------------------
       
   411 //
       
   412 void CXcapEarlyIms::WriteToLog( TRefByValue<const TDesC8> aFmt,... )
       
   413     {
       
   414     VA_LIST list;
       
   415     VA_START( list, aFmt );
       
   416     TBuf8<KUtilsLogBufMaxSize> buf;
       
   417     buf.FormatList( aFmt, list );
       
   418     RFileLogger::Write( KUtilsLogDir, KUtilsLogFile, EFileLoggingModeAppend, buf );
       
   419     }
       
   420 
       
   421 // ----------------------------------------------------------
       
   422 // CXcapEarlyIms::DeleteLogFileL
       
   423 // 
       
   424 // ----------------------------------------------------------
       
   425 //
       
   426 void CXcapEarlyIms::DeleteLogFileL()
       
   427     {
       
   428     RFs session;
       
   429     TBuf<32> log( _L( "C:\\logs\\XDM\\" ) );
       
   430     User::LeaveIfError( session.Connect() );
       
   431     CFileMan* manager = CFileMan::NewL( session );
       
   432     log.Append( KUtilsLogFile );
       
   433     manager->Delete( log );
       
   434     session.Close();
       
   435     delete manager;
       
   436     manager = NULL;
       
   437     }
       
   438 #endif  //_DEBUG
       
   439       
       
   440 
       
   441 
       
   442 
       
   443 
       
   444 // End of File