adaptationlayer/tsy/nokiatsy_dll/src/cmmphonebookoperationwrite.cpp
changeset 8 6295dc2169f3
parent 7 fa67e03b87df
child 9 8486d82aef45
equal deleted inserted replaced
7:fa67e03b87df 8:6295dc2169f3
     1 /*
     1 /*
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of the License "Eclipse Public License v1.0"
     5 * under the terms of the License "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    25 #include <ctsy/serviceapi/gsmerror.h>       // For error code
    25 #include <ctsy/serviceapi/gsmerror.h>       // For error code
    26 #include "tsylogger.h"
    26 #include "tsylogger.h"
    27 #include "cmmmessagerouter.h"
    27 #include "cmmmessagerouter.h"
    28 #include "cmmphonebookoperationwrite.h"
    28 #include "cmmphonebookoperationwrite.h"
    29 #include "cmmphonebookalphastring.h"
    29 #include "cmmphonebookalphastring.h"
    30 #include "osttracedefinitions.h"
    30 #include "OstTraceDefinitions.h"
    31 #ifdef OST_TRACE_COMPILER_IN_USE
    31 #ifdef OST_TRACE_COMPILER_IN_USE
    32 #include "cmmphonebookoperationwritetraces.h"
    32 #include "cmmphonebookoperationwritetraces.h"
    33 #endif
    33 #endif
    34 
    34 
    35 // EXTERNAL DATA STRUCTURES
    35 // EXTERNAL DATA STRUCTURES
    38 // EXTERNAL FUNCTION PROTOTYPES
    38 // EXTERNAL FUNCTION PROTOTYPES
    39     // None
    39     // None
    40 
    40 
    41 // CONSTANTS
    41 // CONSTANTS
    42 
    42 
       
    43 const TUint8 KOwnNumberTextSize = 20;
       
    44 const TUint8 KMaxMobileTelNumberSize = 100;
    43 // MACROS
    45 // MACROS
    44     // None
    46     // None
    45 
    47 
    46 // LOCAL CONSTANTS AND MACROS
    48 // LOCAL CONSTANTS AND MACROS
    47     // None
    49     // None
    89 // ---------------------------------------------------------------------------
    91 // ---------------------------------------------------------------------------
    90 
    92 
    91 CMmPhoneBookOperationWrite* CMmPhoneBookOperationWrite::NewL(
    93 CMmPhoneBookOperationWrite* CMmPhoneBookOperationWrite::NewL(
    92     CMmPhoneBookStoreMessHandler* aMmPhoneBookStoreMessHandler,
    94     CMmPhoneBookStoreMessHandler* aMmPhoneBookStoreMessHandler,
    93     CMmUiccMessHandler* aUiccMessHandler,
    95     CMmUiccMessHandler* aUiccMessHandler,
    94     const CMmDataPackage* aDataPackage ) // Data
    96     const CMmDataPackage* aDataPackage,
       
    97     TInt aIpc ) // Data
    95     {
    98     {
    96 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::NewL");
    99 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::NewL");
    97 OstTrace0( TRACE_NORMAL, CMMPHONEBOOKOPERATIONWRITE_NEWL, "CMmPhoneBookOperationWrite::NewL" );
   100 OstTrace0( TRACE_NORMAL, CMMPHONEBOOKOPERATIONWRITE_NEWL, "CMmPhoneBookOperationWrite::NewL" );
    98 
   101 
    99     TName phonebookTypeName;
   102     TName phonebookTypeName;
   100 
   103 
   101     CMmPhoneBookOperationWrite* mmPhoneBookOperationWrite =
   104     CMmPhoneBookOperationWrite* mmPhoneBookOperationWrite =
   102         new( ELeave ) CMmPhoneBookOperationWrite();
   105         new( ELeave ) CMmPhoneBookOperationWrite();
   103 
   106 
   104     const CPhoneBookDataPackage* phoneBookData =
   107     if( ( EMmTsyONStoreWriteIPC != aIpc )&&
   105         static_cast<const CPhoneBookDataPackage*>( aDataPackage );
   108         ( EMmTsyONStoreWriteEntryIPC != aIpc ) )
   106 
   109         {
   107     phoneBookData->GetPhoneBookName( phonebookTypeName );
   110         TName phonebookTypeName;
   108     // Store phonebook name 
   111 
   109     mmPhoneBookOperationWrite->iPhoneBookTypeName = phonebookTypeName;
   112         const CPhoneBookDataPackage* phoneBookData =
       
   113             static_cast<const CPhoneBookDataPackage*>( aDataPackage );
       
   114 
       
   115         phoneBookData->GetPhoneBookName( phonebookTypeName );
       
   116         // Store phonebook name 
       
   117         mmPhoneBookOperationWrite->iPhoneBookTypeName = phonebookTypeName;
       
   118         }
       
   119 
   110 
   120 
   111     mmPhoneBookOperationWrite->iMmPhoneBookStoreMessHandler =
   121     mmPhoneBookOperationWrite->iMmPhoneBookStoreMessHandler =
   112         aMmPhoneBookStoreMessHandler;
   122         aMmPhoneBookStoreMessHandler;
   113 
   123 
   114     mmPhoneBookOperationWrite->iMmUiccMessHandler = aUiccMessHandler;
   124     mmPhoneBookOperationWrite->iMmUiccMessHandler = aUiccMessHandler;
   141     {
   151     {
   142 TFLOGSTRING2("TSY: CMmPhoneBookOperationWrite::UICCCreateReq Ipc: %d", aIpc);
   152 TFLOGSTRING2("TSY: CMmPhoneBookOperationWrite::UICCCreateReq Ipc: %d", aIpc);
   143 OstTraceExt1( TRACE_NORMAL, DUP1_CMMPHONEBOOKOPERATIONWRITE_UICCCREATEREQ, "CMmPhoneBookOperationWrite::UICCCreateReq;aIpc=%hd", aIpc );
   153 OstTraceExt1( TRACE_NORMAL, DUP1_CMMPHONEBOOKOPERATIONWRITE_UICCCREATEREQ, "CMmPhoneBookOperationWrite::UICCCreateReq;aIpc=%hd", aIpc );
   144     
   154     
   145     TInt ret (KErrNotSupported);
   155     TInt ret (KErrNotSupported);
       
   156     iSavedIpc = aIpc;
       
   157     
   146     const CPhoneBookDataPackage* phoneBookData =
   158     const CPhoneBookDataPackage* phoneBookData =
   147         static_cast<const CPhoneBookDataPackage*>( aDataPackage );
   159         static_cast<const CPhoneBookDataPackage*>( aDataPackage );
   148 
   160 
   149         if( aIpc == EMmTsyPhoneBookStoreWriteIPC )
   161         switch( aIpc )
   150             {
   162             {
       
   163             case EMmTsyPhoneBookStoreWriteIPC:
       
   164                 {
   151                 TInt16 index( 0 );
   165                 TInt16 index( 0 );
   152                 // Store Entry to the operation which needs to be write in SIM
   166                 // Store Entry to the operation which needs to be write in SIM
   153                 phoneBookData->UnPackData( index, iPhoneBookEntry );
   167                 phoneBookData->UnPackData( index, iPhoneBookEntry );
   154 
   168 
   155                 if ( iPhoneBookEntry )
   169                 if ( iPhoneBookEntry )
   156                     {
   170                     {
   157                     // get the index Number needs to be write
   171                     // get the index Number needs to be write
   158                     iPhoneBookEntry->iLocation = static_cast<TUint16>( index );
   172                     iPhoneBookEntry->iLocation = static_cast<TUint16>( index );
   159                     
   173                     
   160                     // Convert Phone Book name to file id
   174                     // Convert Phone Book name to file id
   161                     TUint16 fileIdExt ( UICC_ILLEGAL_FILE_ID );
   175                     iFileId = ConvertToPBfileId( 
   162                     TUint16 pbFileId = ConvertToPBfileId( 
       
   163                                          iPhoneBookTypeName,
   176                                          iPhoneBookTypeName,
   164                                          fileIdExt,
   177                                          iExtFileId,
   165                                          iMmUiccMessHandler->GetCardType() );
   178                                          iMmUiccMessHandler->GetCardType() );
   166                                          
   179                                          
   167                     TUint8 pbArrayIndex ( ConvertToConfArrayIndex( pbFileId ) );
   180                     iArrayIndex = ConvertToConfArrayIndex( iFileId );
   168 
   181                     ret = UiccPbReqWriteL( aTransId, index, *iPhoneBookEntry );
   169                     if( PB_MBDN_FID == pbFileId )
   182                     }
   170                         {
   183                 break;
   171                         // For MBDN PhoneBook first read MBI file 
   184                 }
   172                         // Check if the mailbox inidcation type is correct
   185             case EMmTsyONStoreWriteEntryIPC:
   173                         if( index <= iMmPhoneBookStoreMessHandler->
   186                 {
   174                                 iPBStoreConf[pbArrayIndex].iMbiRecLen )
   187                 iFileId = PB_MSISDN_FID;
   175                             {
   188                 iExtFileId = PB_EXT1_FID;
   176                             iCurrentWritePhase = EPBWritePhase_Read_MBI_profile;
   189                 iArrayIndex = EPhonebookTypeMSISDN;
   177                             // read MBDN record number from MBI first record 
   190                 
   178                             //Profile number
   191                 RMobileONStore::TMobileONEntryV1 entry;
   179                             ret = UiccPbReqReadMBI( index, aTransId );
   192                 aDataPackage->UnPackData( entry );
   180                             }
   193 
   181                         else
   194                 iPhoneBookEntry = new( ELeave ) CPhoneBookStoreEntry;
   182                             {
   195                 CleanupStack::PushL( iPhoneBookEntry );
   183                             ret = KErrArgument;
   196                 iPhoneBookEntry->ConstructL();
   184                             }
   197                 
   185                         }
   198                 // Copy index number
   186                     else
   199                 iPhoneBookEntry->iLocation = entry.iIndex;
   187                         {
   200 
   188                         ret = UiccPbReqWriteL( aTransId, index, *iPhoneBookEntry );
   201                 iPhoneBookEntry->iText = HBufC::NewL( KOwnNumberTextSize );
   189                         }
   202                 // Copy name
   190                     }
   203                 TPtr ptrToName ( iPhoneBookEntry->iText->Des() );
   191             }
   204                 CopyData( entry.iText,  ptrToName );
   192         else
   205 
   193             {
   206                 iPhoneBookEntry->iNumber = HBufC::NewL( KMaxMobileTelNumberSize );
       
   207                 // Copy Number
       
   208                 TPtr ptrToNumber( iPhoneBookEntry->iNumber->Des() );
       
   209                 CopyData( entry.iNumber.iTelNumber, ptrToNumber );
       
   210                 
       
   211                 CleanupStack::Pop( iPhoneBookEntry );
       
   212 
       
   213                 // Send Request 
       
   214                 ret = UiccPbReqWriteL( aTransId, entry.iIndex, *iPhoneBookEntry );
       
   215 
       
   216                 break;
       
   217                 }
       
   218             case EMmTsyONStoreWriteIPC:
       
   219                 {
       
   220                 iFileId = PB_MSISDN_FID;
       
   221                 iExtFileId = PB_EXT1_FID;
       
   222                 
       
   223                 iArrayIndex = EPhonebookTypeMSISDN;
       
   224 
       
   225                 TDesC8* entry = NULL;
       
   226                 aDataPackage->UnPackData( entry );
       
   227 
       
   228                 // Unpack entry param to get the location
       
   229                 RMobileONStore::TMobileONEntryV1Pckg* entryPckg =
       
   230                     reinterpret_cast<RMobileONStore::TMobileONEntryV1Pckg*>( entry );
       
   231                 RMobileONStore::TMobileONEntryV1& onEntry = ( *entryPckg )();
       
   232 
       
   233                 iPhoneBookEntry = new( ELeave ) CPhoneBookStoreEntry;
       
   234                 CleanupStack::PushL( iPhoneBookEntry );
       
   235                 iPhoneBookEntry->ConstructL();
       
   236                 
       
   237                 // Copy index number
       
   238                 iPhoneBookEntry->iLocation = onEntry.iIndex;
       
   239 
       
   240                 iPhoneBookEntry->iText = HBufC::NewL( KOwnNumberTextSize );
       
   241                 // Copy name
       
   242                 TPtr ptrToName ( iPhoneBookEntry->iText->Des() );
       
   243                 CopyData( onEntry.iText,  ptrToName );
       
   244 
       
   245                 iPhoneBookEntry->iNumber = HBufC::NewL( KMaxMobileTelNumberSize );
       
   246                 // Copy Number
       
   247                 TPtr ptrToNumber( iPhoneBookEntry->iNumber->Des() );
       
   248                 CopyData( onEntry.iNumber.iTelNumber, ptrToNumber );
       
   249                 
       
   250                 CleanupStack::Pop( iPhoneBookEntry );
       
   251 
       
   252                 // Send Request 
       
   253                 ret = UiccPbReqWriteL( aTransId, onEntry.iIndex, *iPhoneBookEntry );
       
   254 
       
   255                 break;
       
   256                 }
       
   257             default:
       
   258                 {
   194 TFLOGSTRING2("TSY: CMmPhoneBookOperationWrite::UICCCreateReq Unknown Ipc: %d", aIpc);
   259 TFLOGSTRING2("TSY: CMmPhoneBookOperationWrite::UICCCreateReq Unknown Ipc: %d", aIpc);
   195 OstTraceExt1( TRACE_NORMAL, DUP2_CMMPHONEBOOKOPERATIONWRITE_UICCCREATEREQ, "CMmPhoneBookOperationWrite::UICCCreateReq;Unknown aIpc =%hd", aIpc );
   260 OstTraceExt1( TRACE_NORMAL, DUP2_CMMPHONEBOOKOPERATIONWRITE_UICCCREATEREQ, "CMmPhoneBookOperationWrite::UICCCreateReq;Unknown aIpc =%hd", aIpc );
       
   261                  
       
   262                 break;
       
   263                 }
   196             }
   264             }
   197     return ret;
   265     return ret;
   198     }
   266     }
   199 
   267 
   200 
   268 
   210     {
   278     {
   211 TFLOGSTRING3("TSY: CMmPhoneBookOperationWrite::SimPbReqWriteL, aTransId:%d,index:%d", aTransId,  aIndex);
   279 TFLOGSTRING3("TSY: CMmPhoneBookOperationWrite::SimPbReqWriteL, aTransId:%d,index:%d", aTransId,  aIndex);
   212 OstTraceExt2( TRACE_NORMAL, CMMPHONEBOOKOPERATIONWRITE_UICCPBREQWRITEL, "CMmPhoneBookOperationWrite::UiccPbReqWriteL;aTransId=%hhu;aIndex=%hd", aTransId, aIndex );
   280 OstTraceExt2( TRACE_NORMAL, CMMPHONEBOOKOPERATIONWRITE_UICCPBREQWRITEL, "CMmPhoneBookOperationWrite::UiccPbReqWriteL;aTransId=%hhu;aIndex=%hd", aTransId, aIndex );
   213     
   281     
   214     TInt ret( KErrNone );
   282     TInt ret( KErrNone );
   215     // Check for no of EXT records required for Writing this Entry
   283     
   216     TUint8 extRecordNo ( 0 ); 
   284     if( ( PB_MBDN_FID == iFileId )&&
   217 
   285         ( 0 == iCurrentWritePhase ) )
   218     if( UICC_EF_FDN_NO_EXT_NUM_LEN < iPhoneBookEntry->iNumber->Length() )
   286         {
   219         {
   287         iCurrentWritePhase = EPBWritePhase_Read_MBI_profile;
   220         extRecordNo++;
   288         // read MBDN record number from MBI first record 
   221         TInt extDataLength = iPhoneBookEntry->iNumber->Length() - 
   289         //Profile number
   222                              UICC_EF_FDN_NO_EXT_NUM_LEN;
   290         ret = UiccPbReqReadMBI( aIndex, aTransId );
   223         while ( extDataLength > UICC_EF_EXT_REC_NUM_LEN)
   291         }
   224             {
   292     else
   225             extRecordNo++;
   293         {
   226             extDataLength = extDataLength - UICC_EF_EXT_REC_NUM_LEN;
   294         // Check for no of EXT records required for Writing this Entry
   227             }
   295         TUint8 extRecordNo ( 0 ); 
   228         }
   296         GetExtRecNum( extRecordNo );
   229         
       
   230     // reserve Space for ext record no
       
   231     iExtRecordArrayToBeWrite.ReserveL( extRecordNo );
       
   232     // File reserved memory with 0
       
   233     for( TInt count = 0; count < extRecordNo; count++ )
       
   234         {
       
   235         iExtRecordArrayToBeWrite.Insert( 0 , count );
       
   236         }
       
   237 
       
   238     // Convert Phone Book name to file id
       
   239     TUint16 fileIdExt ( UICC_ILLEGAL_FILE_ID );
       
   240     TUint16 pbFileId = ConvertToPBfileId( 
       
   241                           iPhoneBookTypeName,
       
   242                           fileIdExt,
       
   243                           iMmUiccMessHandler->GetCardType() );
       
   244 
       
   245     if( UICC_ILLEGAL_FILE_ID != pbFileId )
       
   246         {
       
   247         TUint8 pbArrayIndex ( ConvertToConfArrayIndex( pbFileId ) );
       
   248 
   297 
   249         // Check if the index To read is valid
   298         // Check if the index To read is valid
   250         if(  aIndex <= iMmPhoneBookStoreMessHandler->
   299         if( ( UICC_ILLEGAL_FILE_ID != iFileId ) &&
   251                 iPBStoreConf[pbArrayIndex].iNoOfRecords )
   300             ( aIndex <= iMmPhoneBookStoreMessHandler->
   252             {
   301                  iPBStoreConf[iArrayIndex].iNoOfRecords ) )
   253             // if Entry present in list Store it locally
   302             {
   254             TPBEntry entry;
       
   255             if( 0 < aIndex )
   303             if( 0 < aIndex )
   256                 {
   304                 {
   257                 // Check for index present the store list
   305                 ret =  StartWriteEntryIndex( 
   258                 if( iMmPhoneBookStoreMessHandler->IndexCheckInPBList(
       
   259                         aIndex,
   306                         aIndex,
   260                         pbArrayIndex,
   307                         extRecordNo, 
   261                         entry ) )
   308                         aTransId, 
   262                     {
   309                         aDataToWrite );                
   263                     // Check if Entry is present or not 
       
   264                     if( entry.iEntryPresent )
       
   265                         {
       
   266                         // Check if no if ext records are sufficient from 
       
   267                         //previous Entry
       
   268                         if( extRecordNo  > entry.PBEntryExtRecord.Count() )
       
   269                             {
       
   270                             // Update old record number which needs to be 
       
   271                             //updated by new entry
       
   272                             if( entry.PBEntryExtRecord.Count() > 0 )
       
   273                                 {
       
   274                                 for( TInt i=0; 
       
   275                                       i < entry.PBEntryExtRecord.Count();
       
   276                                       i++ )
       
   277                                     {
       
   278                                     // Append record number to be write from 
       
   279                                     //old Entry
       
   280                                     iExtRecordArrayToBeWrite.Append( 
       
   281                                             entry.PBEntryExtRecord[i] );
       
   282                                     iExtRecordArrayToBeDelete.Append( 
       
   283                                             entry.PBEntryExtRecord[i] );
       
   284                                     }
       
   285                                 }
       
   286                             // Search for more free records
       
   287                             iCurrentWritePhase = EPBWritePhase_Search_Ext_Entry;
       
   288                             
       
   289                             // Send request to read first entry in Ext
       
   290                             iExtRecordNo = 1 ;
       
   291                             ret = UiccPbReqWriteReadExt(
       
   292                                     pbFileId,
       
   293                                     fileIdExt,
       
   294                                     iExtRecordNo,
       
   295                                     aTransId);
       
   296                             }
       
   297                         else  // when reocrds to be delete and write are 0 or to
       
   298                               // be write record less
       
   299                             {
       
   300                             // Check of both records are 0
       
   301                             if( ( extRecordNo == 0 ) && 
       
   302                                     ( entry.PBEntryExtRecord.Count() == 0 ))
       
   303                                 {
       
   304                                 // Start Writing Entry
       
   305                                 iCurrentWritePhase = EPBWritePhase_Write_Entry;
       
   306                                 ret = UiccPBReqWriteEntry( 
       
   307                                         pbFileId,
       
   308                                         aIndex,
       
   309                                         aTransId,
       
   310                                         aDataToWrite );
       
   311                                 }
       
   312                             else
       
   313                                 {
       
   314                                 // Start copy Ext record number to be write array
       
   315                                 for( TInt i=0; i <  extRecordNo; i++ )
       
   316                                     {
       
   317                                     // Append record number to be write from old
       
   318                                     //Entry
       
   319                                     iExtRecordArrayToBeWrite.Append(
       
   320                                             entry.PBEntryExtRecord[i]);
       
   321                                     iExtRecordArrayToBeDelete.Append(
       
   322                                             entry.PBEntryExtRecord[i]);
       
   323                                     }
       
   324                                 // Update records needs to be deleted
       
   325                                 // From old Entry
       
   326                                 for( TInt i=extRecordNo;
       
   327                                        i < entry.PBEntryExtRecord.Count();
       
   328                                        i++ )
       
   329                                     {
       
   330                                     // Append record number to be deleted from 
       
   331                                     //old Entry
       
   332                                     iExtRecordArrayToBeDelete.Append( 
       
   333                                             entry.PBEntryExtRecord[i]);
       
   334                                     }
       
   335                                 // Start Deleting the EXT Records
       
   336                                 iCurrentWritePhase = EPBWritePhase_Write_Ext_Entry;
       
   337                                 iExtDeleteOperation = ETrue;
       
   338                                 TUint8 index ( iExtRecordArrayToBeDelete[0] );
       
   339                                 // Send request to Write main Entry
       
   340                                 ret = UiccPbReqWriteExtDelete(
       
   341                                         pbFileId,
       
   342                                         fileIdExt,
       
   343                                         index,
       
   344                                         aTransId );
       
   345                                 }
       
   346                             }
       
   347                         }
       
   348                     else
       
   349                         {
       
   350                         // If entry not present
       
   351                         // Check if EXT Records are needed for Entry to be written
       
   352                         if( 0 < extRecordNo )
       
   353                             {
       
   354                             // Search for free ext records 
       
   355                             iCurrentWritePhase = EPBWritePhase_Search_Ext_Entry;
       
   356                             
       
   357                             // Send request To read First EXT record
       
   358                             iExtRecordNo = 1;
       
   359                             ret = UiccPbReqWriteReadExt(
       
   360                                     pbFileId,
       
   361                                     fileIdExt,
       
   362                                     iExtRecordNo,
       
   363                                     aTransId );
       
   364                             }
       
   365                         else
       
   366                             {
       
   367                             // Start Writting Entry
       
   368                             iCurrentWritePhase = EPBWritePhase_Write_Entry;
       
   369                             TUint8 indexToWrite = iPhoneBookEntry->iLocation;
       
   370                             ret = UiccPBReqWriteEntry(
       
   371                                     pbFileId,
       
   372                                     indexToWrite,
       
   373                                     aTransId,
       
   374                                     aDataToWrite );
       
   375                             }
       
   376                         }
       
   377                     }   // end of if Entry is present in the list
       
   378                 else
       
   379                     {
       
   380                     // First Read that Entry from SIM and then delete that entry
       
   381                     // with EXT records if there are Any
       
   382                     iCurrentWritePhase = EPBWritePhase_Read_Entry;
       
   383                     ret = UiccPbReqWriteRead( pbFileId, aIndex, aTransId );
       
   384                     
       
   385                     // read Main entry with given index number
       
   386                     }
       
   387                 }
   310                 }
   388             else
   311             else
   389                 {
   312                 {
   390                 // Start Serching For first free Entry in the Stored list
   313                 // Start Serching For first free Entry in the Stored list
   391                 TInt index = iMmPhoneBookStoreMessHandler->
   314                 iEntryToWrite = iMmPhoneBookStoreMessHandler->
   392                 EmptyEntryCheckInPBList( pbArrayIndex );
   315                 EmptyEntryCheckInPBList( iArrayIndex );
   393                 if( 0 < index )
   316                 if( 0 < iEntryToWrite )
   394                     {
   317                     {
   395                     //Check if EXT records Are needed or not
   318                     //Check if EXT records Are needed or not
   396                     if( 0 < extRecordNo )
   319                     if( 0 < extRecordNo )
   397                         {
   320                         {
   398                         // Start Serching for EXT records
   321                         // Start Serching for EXT records
   399                         // Search for free ext records 
   322                         // Search for free ext records 
   400                         iCurrentWritePhase = EPBWritePhase_Search_Ext_Entry;
   323                         iCurrentWritePhase = EPBWritePhase_Search_Ext_Entry;
   401                             
   324                         
   402                         // Send request To read First EXT record
   325                         // Send request To read First EXT record
   403                         iExtRecordNo = 1;
   326                         iExtRecordNo = 1;
   404                         ret = UiccPbReqWriteReadExt(
   327                         ret = UiccPbReqWriteReadExt(
   405                                 pbFileId,
       
   406                                 fileIdExt,
       
   407                                 iExtRecordNo,
   328                                 iExtRecordNo,
   408                                 aTransId );
   329                                 aTransId );
   409                         }
   330                         }
   410                     else
   331                     else
   411                         {
   332                         {
   412                         // Start Writing Entry on given Index
   333                         // Start Writing Entry on given Index
   413                         // Start Writting Entry
   334                         // Start Writting Entry
   414                         iCurrentWritePhase = EPBWritePhase_Write_Entry;
   335                         iCurrentWritePhase = EPBWritePhase_Write_Entry;
   415                         ret = UiccPBReqWriteEntry(
   336                         ret = UiccPBReqWriteEntry(
   416                                 pbFileId,
   337                                 iEntryToWrite,
   417                                 index,
       
   418                                 aTransId,
   338                                 aTransId,
   419                                 aDataToWrite );
   339                                 aDataToWrite );
   420                         }
   340                         }
   421                     }
   341                     }
   422                 else
   342                 else
   424                     // Start searching for first free Entry from SIM
   344                     // Start searching for first free Entry from SIM
   425                     iCurrentWritePhase = EPBWritePhase_Read_Entry;
   345                     iCurrentWritePhase = EPBWritePhase_Read_Entry;
   426                     iLocationSearch = ETrue;
   346                     iLocationSearch = ETrue;
   427                     iEntryToWrite = 1;
   347                     iEntryToWrite = 1;
   428                     ret = UiccPbReqWriteRead(
   348                     ret = UiccPbReqWriteRead(
   429                             pbFileId,
       
   430                             iEntryToWrite,
   349                             iEntryToWrite,
   431                             aTransId );
   350                             aTransId );
   432                     }
   351                     }
   433                 }
   352                 }
   434             }
   353             }
   435         else
   354         else
   436             {
   355             {
   437             ret = KErrArgument;
   356             ret = KErrArgument;
   438             }            
   357             }
   439         }
   358         }
   440     else
   359 
   441         {
       
   442         ret = KErrArgument;
       
   443         }
       
   444     return ret;
   360     return ret;
   445     }
   361     }
   446 
       
   447 
   362 
   448 
   363 
   449 // ---------------------------------------------------------------------------
   364 // ---------------------------------------------------------------------------
   450 // CMmPhoneBookOperationWrite::UiccPBReqWriteEntry
   365 // CMmPhoneBookOperationWrite::UiccPBReqWriteEntry
   451 // Constructs an ISI-message to Write main Entry data
   366 // Constructs an ISI-message to Write main Entry data
   452 // ---------------------------------------------------------------------------
   367 // ---------------------------------------------------------------------------
   453 //
   368 //
   454 TInt CMmPhoneBookOperationWrite::UiccPBReqWriteEntry( 
   369 TInt CMmPhoneBookOperationWrite::UiccPBReqWriteEntry( 
   455              TUint16 aFileId,
       
   456              TUint8 aIndex,
   370              TUint8 aIndex,
   457              TUint8 aTransId,
   371              TUint8 aTransId,
   458              CPhoneBookStoreEntry& aDataToWrite )
   372              CPhoneBookStoreEntry& aDataToWrite )
   459     {
   373     {
   460 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::UiccPBReqWriteEntry");
   374 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::UiccPBReqWriteEntry");
   475         cmdParams.filePath.Append( static_cast<TUint8>( DF_PHONEBOOK >> 8 ));
   389         cmdParams.filePath.Append( static_cast<TUint8>( DF_PHONEBOOK >> 8 ));
   476         cmdParams.filePath.Append( static_cast<TUint8>( DF_PHONEBOOK ));
   390         cmdParams.filePath.Append( static_cast<TUint8>( DF_PHONEBOOK ));
   477         }
   391         }
   478     
   392     
   479     cmdParams.serviceType = UICC_APPL_UPDATE_LINEAR_FIXED;
   393     cmdParams.serviceType = UICC_APPL_UPDATE_LINEAR_FIXED;
   480     cmdParams.fileId = aFileId;
   394     cmdParams.fileId = iFileId;
   481     cmdParams.trId = static_cast<TUiccTrId>( aTransId );
   395     cmdParams.trId = static_cast<TUiccTrId>( aTransId );
   482     // Check for valid record number
   396     // Check for valid record number
   483     TUint8 arrayIndex ( ConvertToConfArrayIndex( aFileId ) );
       
   484     if( aIndex <= iMmPhoneBookStoreMessHandler->
   397     if( aIndex <= iMmPhoneBookStoreMessHandler->
   485                      iPBStoreConf[arrayIndex].iNoOfRecords )
   398                      iPBStoreConf[iArrayIndex].iNoOfRecords )
   486         {
   399         {
   487         cmdParams.record = aIndex;
   400         cmdParams.record = aIndex;
   488         }
   401         }
   489     else
   402     else
   490         {
   403         {
   496     
   409     
   497     TPtr16 ptrToName = aDataToWrite.iText->Des();
   410     TPtr16 ptrToName = aDataToWrite.iText->Des();
   498     // Convert the Entry Name from ASCII format to UCS2
   411     // Convert the Entry Name from ASCII format to UCS2
   499     CMmStaticUtility::ConvertUcs2ToGsmUcs2Data( ptrToName, nameBuf );
   412     CMmStaticUtility::ConvertUcs2ToGsmUcs2Data( ptrToName, nameBuf );
   500     if( nameBuf.Length() < iMmPhoneBookStoreMessHandler->
   413     if( nameBuf.Length() < iMmPhoneBookStoreMessHandler->
   501                            iPBStoreConf[ arrayIndex ].iAlphaStringlength )
   414                            iPBStoreConf[iArrayIndex].iAlphaStringlength )
   502         {
   415         {
   503         // Fill rest of the Bytes 
   416         // Fill rest of the Bytes 
   504         for( TInt count = nameBuf.Length(); count < ( iMmPhoneBookStoreMessHandler->
   417         for( TInt count = nameBuf.Length(); count < ( iMmPhoneBookStoreMessHandler->
   505                       iPBStoreConf[ arrayIndex ].iAlphaStringlength ); count++ )
   418                       iPBStoreConf[ iArrayIndex ].iAlphaStringlength ); count++ )
   506             {
   419             {
   507             nameBuf.Append( KTagUnusedbyte );
   420             nameBuf.Append( KTagUnusedbyte );
   508             }
   421             }
   509         }
   422         }
   510     TBuf8<300>numberBuf;
   423     TBuf8<300>numberBuf;
   511     TPtr16 ptrToNumber = aDataToWrite.iNumber->Des();
   424     TPtr16 ptrToNumber = aDataToWrite.iNumber->Des();
   512     iMmPhoneBookStoreMessHandler->ConvertToBCDFromUCS2(
   425     if( ptrToNumber.Length() > 0 )
   513                                   ptrToNumber,
   426         {
   514                                   numberBuf,
   427         iMmPhoneBookStoreMessHandler->ConvertToBCDFromUCS2(
   515                                   aFileId );
   428                                       ptrToNumber,
       
   429                                       numberBuf,
       
   430                                       iFileId );
       
   431         }
   516     
   432     
   517     // Store number length
   433     // Store number length
   518     TUint8 numLength ( numberBuf.Length() );
   434     TUint8 numLength ( numberBuf.Length() );
   519     
   435     
   520     if( numberBuf.Length() < UICC_EF_EXT_REC_NUM_LEN )
   436     if( numberBuf.Length() < UICC_EF_EXT_REC_NUM_LEN )
   528             }
   444             }
   529         }
   445         }
   530     
   446     
   531     TBuf8<200>fileDataWrite;
   447     TBuf8<200>fileDataWrite;
   532     fileDataWrite.Append( nameBuf.Mid( 0, iMmPhoneBookStoreMessHandler->
   448     fileDataWrite.Append( nameBuf.Mid( 0, iMmPhoneBookStoreMessHandler->
   533                           iPBStoreConf[ arrayIndex ].iAlphaStringlength ) );
   449                           iPBStoreConf[ iArrayIndex ].iAlphaStringlength ) );
   534     fileDataWrite.Append( numLength );
   450     fileDataWrite.Append( numLength );
   535     fileDataWrite.Append( numberBuf.Mid( 0, UICC_EF_EXT_REC_NUM_LEN ) );
   451     fileDataWrite.Append( numberBuf.Mid( 0, UICC_EF_EXT_REC_NUM_LEN ) );
   536     // Append Capability configuration byte as not used
   452     // Append Capability configuration byte as not used
   537     fileDataWrite.Append( KTagUnusedbyte );
   453     fileDataWrite.Append( KTagUnusedbyte );
   538 
   454 
   571 //
   487 //
   572 
   488 
   573 TInt CMmPhoneBookOperationWrite::UiccPbReqWriteExt(
   489 TInt CMmPhoneBookOperationWrite::UiccPbReqWriteExt(
   574         TUint8 aTransId,
   490         TUint8 aTransId,
   575         TUint8 aIndex,
   491         TUint8 aIndex,
   576         TUint16 aFileId,
       
   577         TUint16 aFileIdExt,
       
   578         CPhoneBookStoreEntry& aDataToWrite )
   492         CPhoneBookStoreEntry& aDataToWrite )
   579     {
   493     {
   580 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::UiccPbReqWriteExt");
   494 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::UiccPbReqWriteExt");
   581 OstTrace0( TRACE_NORMAL, CMMPHONEBOOKOPERATIONWRITE_UICCPBWRITEEXT, "CMmPhoneBookOperationWrite::UiccPbReqWriteExt" );
   495 OstTrace0( TRACE_NORMAL, CMMPHONEBOOKOPERATIONWRITE_UICCPBWRITEEXT, "CMmPhoneBookOperationWrite::UiccPbReqWriteExt" );
   582     
   496     
   594         {
   508         {
   595         cmdParams.filePath.Append( static_cast<TUint8>( DF_PHONEBOOK >> 8 ));
   509         cmdParams.filePath.Append( static_cast<TUint8>( DF_PHONEBOOK >> 8 ));
   596         cmdParams.filePath.Append( static_cast<TUint8>( DF_PHONEBOOK ));
   510         cmdParams.filePath.Append( static_cast<TUint8>( DF_PHONEBOOK ));
   597         }
   511         }
   598     
   512     
   599     cmdParams.fileId = aFileIdExt;
   513     cmdParams.fileId = iExtFileId;
   600     cmdParams.serviceType = UICC_APPL_UPDATE_LINEAR_FIXED;
   514     cmdParams.serviceType = UICC_APPL_UPDATE_LINEAR_FIXED;
   601     cmdParams.trId = static_cast<TUiccTrId>( aTransId );
   515     cmdParams.trId = static_cast<TUiccTrId>( aTransId );
   602     
   516     
   603     // File Data
   517     // File Data
   604     TBuf8<255>numBuf;
   518     TBuf8<255>numBuf;
   606     TPtr16 ptrToNumber = aDataToWrite.iNumber->Des();
   520     TPtr16 ptrToNumber = aDataToWrite.iNumber->Des();
   607 
   521 
   608     iMmPhoneBookStoreMessHandler->ConvertToBCDFromUCS2(
   522     iMmPhoneBookStoreMessHandler->ConvertToBCDFromUCS2(
   609                                   ptrToNumber,
   523                                   ptrToNumber,
   610                                   numBuf,
   524                                   numBuf,
   611                                   aFileId );
   525                                   iFileId );
   612     
   526     
   613         if( numBuf.Length() > ( 10 + ( iExtRecordWritten* 11 ) ))
   527         if( numBuf.Length() > ( 10 + ( iExtRecordWritten* 11 ) ))
   614             {
   528             {
   615             // form EXt file Data
   529             // form EXt file Data
   616             // Append Record type
   530             // Append Record type
   653                 }
   567                 }
   654             }
   568             }
   655         
   569         
   656         cmdParams.fileData.Append( extFileData );
   570         cmdParams.fileData.Append( extFileData );
   657 
   571 
   658     TUint8 arrayIndex ( ConvertToConfArrayIndex( aFileId ));
   572     if( aIndex <= iMmPhoneBookStoreMessHandler->iPBStoreConf[iArrayIndex].iExtNoOfRec )
   659     if( aIndex <= iMmPhoneBookStoreMessHandler->iPBStoreConf[arrayIndex].iExtNoOfRec )
       
   660         {
   573         {
   661         cmdParams.record = aIndex;
   574         cmdParams.record = aIndex;
   662         }
   575         }
   663     else
   576     else
   664         {
   577         {
   684 // CMmPhoneBookOperationWrite::UiccPbReqWriteReadExt
   597 // CMmPhoneBookOperationWrite::UiccPbReqWriteReadExt
   685 // Constructs an ISI-message to Read The existing Entry EXT record
   598 // Constructs an ISI-message to Read The existing Entry EXT record
   686 // ---------------------------------------------------------------------------
   599 // ---------------------------------------------------------------------------
   687 //
   600 //
   688 TInt CMmPhoneBookOperationWrite::UiccPbReqWriteReadExt(
   601 TInt CMmPhoneBookOperationWrite::UiccPbReqWriteReadExt(
   689              TUint16 aFileId,
       
   690              TUint16 aFileIdExt,
       
   691              TUint8 aIndex,
   602              TUint8 aIndex,
   692              TUint8 aTransId)
   603              TUint8 aTransId)
   693     {
   604     {
   694 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::UiccPbReqWriteEXTDelete");
   605 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::UiccPbReqWriteEXTDelete");
   695 OstTrace0( TRACE_NORMAL, CMMPHONEBOOKOPERATIONWRITE_UICCPBREQWRITEREADEXT, "CMmPhoneBookOperationWrite::UiccPbReqWriteReadExt" );
   606 OstTrace0( TRACE_NORMAL, CMMPHONEBOOKOPERATIONWRITE_UICCPBREQWRITEREADEXT, "CMmPhoneBookOperationWrite::UiccPbReqWriteReadExt" );
   712     
   623     
   713     // Append transaction id 
   624     // Append transaction id 
   714     cmdParams.trId = static_cast<TUiccTrId>( aTransId );
   625     cmdParams.trId = static_cast<TUiccTrId>( aTransId );
   715     
   626     
   716     // Append File id
   627     // Append File id
   717     cmdParams.fileId = aFileIdExt;
   628     cmdParams.fileId = iExtFileId;
   718     
   629     
   719     // Append serviceType
   630     // Append serviceType
   720     cmdParams.serviceType = UICC_APPL_READ_LINEAR_FIXED;
   631     cmdParams.serviceType = UICC_APPL_READ_LINEAR_FIXED;
   721     
   632     
   722     
   633     
   723     TUint8 arrayIndex( ConvertToConfArrayIndex( aFileId ) );
       
   724     // Check for the valid index neds to be read
   634     // Check for the valid index neds to be read
   725     if( aIndex <= iMmPhoneBookStoreMessHandler->
   635     if( aIndex <= iMmPhoneBookStoreMessHandler->
   726                    iPBStoreConf[arrayIndex].iExtNoOfRec )
   636                    iPBStoreConf[iArrayIndex].iExtNoOfRec )
   727         {
   637         {
   728         // Append recor number
   638         // Append recor number
   729         cmdParams.record = aIndex;
   639         cmdParams.record = aIndex;
   730         }
   640         }
   731     else
   641     else
   749 // CMmPhoneBookOperationWrite::UiccPbReqWriteRead
   659 // CMmPhoneBookOperationWrite::UiccPbReqWriteRead
   750 // Constructs an ISI-message to Read The existing Entry
   660 // Constructs an ISI-message to Read The existing Entry
   751 // ---------------------------------------------------------------------------
   661 // ---------------------------------------------------------------------------
   752 //
   662 //
   753 TInt CMmPhoneBookOperationWrite::UiccPbReqWriteRead(
   663 TInt CMmPhoneBookOperationWrite::UiccPbReqWriteRead(
   754                      TUint16 aFileId,
       
   755                      TUint8 aIndex,
   664                      TUint8 aIndex,
   756                      TUint8 aTransId )
   665                      TUint8 aTransId )
   757     {
   666     {
   758 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::UiccPbReqWriteRead");
   667 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::UiccPbReqWriteRead");
   759 OstTrace0( TRACE_NORMAL, CMMPHONEBOOKOPERATIONWRITE_UICCPBREQWRITEREAD, "CMmPhoneBookOperationWrite::UiccPbReqWriteRead" );
   668 OstTrace0( TRACE_NORMAL, CMMPHONEBOOKOPERATIONWRITE_UICCPBREQWRITEREAD, "CMmPhoneBookOperationWrite::UiccPbReqWriteRead" );
   773         cmdParams.filePath.Append( static_cast<TUint8>( DF_PHONEBOOK >> 8 ));
   682         cmdParams.filePath.Append( static_cast<TUint8>( DF_PHONEBOOK >> 8 ));
   774         cmdParams.filePath.Append( static_cast<TUint8>( DF_PHONEBOOK ));
   683         cmdParams.filePath.Append( static_cast<TUint8>( DF_PHONEBOOK ));
   775         }
   684         }
   776     
   685     
   777     cmdParams.trId = static_cast<TUiccTrId>( aTransId );
   686     cmdParams.trId = static_cast<TUiccTrId>( aTransId );
   778     cmdParams.fileId = aFileId;
   687     cmdParams.fileId = iFileId;
   779     cmdParams.serviceType =  UICC_APPL_READ_LINEAR_FIXED ;
   688     cmdParams.serviceType =  UICC_APPL_READ_LINEAR_FIXED ;
   780     TUint8 arrayIndex ( ConvertToConfArrayIndex( aFileId ) );
       
   781     if( aIndex <= iMmPhoneBookStoreMessHandler->
   689     if( aIndex <= iMmPhoneBookStoreMessHandler->
   782                     iPBStoreConf[arrayIndex].iNoOfRecords )
   690                     iPBStoreConf[iArrayIndex].iNoOfRecords )
   783         {
   691         {
   784         cmdParams.record = aIndex;
   692         cmdParams.record = aIndex;
   785         }
   693         }
   786     else
   694     else
   787         {
   695         {
   803 // CMmPhoneBookOperationWrite::UiccPbReqWriteEXTDelete
   711 // CMmPhoneBookOperationWrite::UiccPbReqWriteEXTDelete
   804 // Constructs an ISI-message to delete EXT File Data
   712 // Constructs an ISI-message to delete EXT File Data
   805 // ---------------------------------------------------------------------------
   713 // ---------------------------------------------------------------------------
   806 //
   714 //
   807 TInt CMmPhoneBookOperationWrite::UiccPbReqWriteExtDelete(
   715 TInt CMmPhoneBookOperationWrite::UiccPbReqWriteExtDelete(
   808                   TUint16 aFileId,
       
   809                   TUint16 aFileIdExt,
       
   810                   TUint8 aIndex,
   716                   TUint8 aIndex,
   811                   TUint8 aTransId )
   717                   TUint8 aTransId )
   812     {
   718     {
   813 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::UiccPbReqWriteEXTDelete");
   719 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::UiccPbReqWriteEXTDelete");
   814 OstTrace0( TRACE_NORMAL, CMMPHONEBOOKOPERATIONWRITE_UICCPBREQWRITEEXTDELETE, "CMmPhoneBookOperationWrite::UiccPbReqWriteEXTDelete" );
   720 OstTrace0( TRACE_NORMAL, CMMPHONEBOOKOPERATIONWRITE_UICCPBREQWRITEEXTDELETE, "CMmPhoneBookOperationWrite::UiccPbReqWriteEXTDelete" );
   829         cmdParams.filePath.Append( static_cast<TUint8>( DF_PHONEBOOK >> 8 ));
   735         cmdParams.filePath.Append( static_cast<TUint8>( DF_PHONEBOOK >> 8 ));
   830         cmdParams.filePath.Append( static_cast<TUint8>( DF_PHONEBOOK ));
   736         cmdParams.filePath.Append( static_cast<TUint8>( DF_PHONEBOOK ));
   831         }
   737         }
   832     
   738     
   833     cmdParams.trId = static_cast<TUiccTrId>( aTransId );
   739     cmdParams.trId = static_cast<TUiccTrId>( aTransId );
   834     cmdParams.fileId = aFileIdExt;
   740     cmdParams.fileId = iExtFileId;
   835     cmdParams.serviceType =  UICC_APPL_UPDATE_LINEAR_FIXED ;
   741     cmdParams.serviceType =  UICC_APPL_UPDATE_LINEAR_FIXED ;
   836     
   742    
   837     TUint8 arrayIndex ( ConvertToConfArrayIndex( aFileId ) );
       
   838 
       
   839     
       
   840     if( aIndex <= iMmPhoneBookStoreMessHandler->
   743     if( aIndex <= iMmPhoneBookStoreMessHandler->
   841                    iPBStoreConf[arrayIndex].iExtNoOfRec)
   744                    iPBStoreConf[iArrayIndex].iExtNoOfRec)
   842         {
   745         {
   843         cmdParams.record = aIndex;
   746         cmdParams.record = aIndex;
   844         }
   747         }
   845     else
   748     else
   846         {
   749         {
   867 
   770 
   868     return ret ;
   771     return ret ;
   869     }
   772     }
   870 
   773 
   871 
   774 
       
   775 
   872 // ---------------------------------------------------------------------------
   776 // ---------------------------------------------------------------------------
   873 // CMmPhoneBookOperationWrite::UiccPbReqReadMBI
   777 // CMmPhoneBookOperationWrite::UiccPbReqReadMBI
   874 // Constructs an ISI-message to Read MBI profile from first record 
   778 // Constructs an ISI-message to Read MBI profile from first record 
   875 // ---------------------------------------------------------------------------
   779 // ---------------------------------------------------------------------------
   876 //
   780 //
   877 TInt CMmPhoneBookOperationWrite::UiccPbReqReadMBI( TUint8 aIndex, TUint8 aTransId )
   781 TInt CMmPhoneBookOperationWrite::StartWriteEntryIndex( 
       
   782         TUint16 aIndex,
       
   783         TUint8 aExtRecNo, 
       
   784         TUint8 aTransId, 
       
   785         CPhoneBookStoreEntry& aDataToWrite )
       
   786     {
       
   787 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::StartWriteForEntryPresentInList");
       
   788 OstTrace0( TRACE_NORMAL, CMMPHONEBOOKOPERATIONWRITE_STARTWRITEFORENTRYPRESENTINLIST, "CMmPhoneBookOperationWrite::StartWriteForEntryPresentInList" );
       
   789 
       
   790     TInt ret( KErrNone );
       
   791     // if Entry present in list Store it locally
       
   792     TPBEntry entry;
       
   793         // Check for index present the store list
       
   794         if( iMmPhoneBookStoreMessHandler->IndexCheckInPBList(
       
   795                 aIndex,
       
   796                 iArrayIndex,
       
   797                 entry ) )
       
   798             {
       
   799             // Check if Entry is present or not 
       
   800             if( entry.iEntryPresent )
       
   801                 {
       
   802                 // Check if no if ext records are sufficient from 
       
   803                 //previous Entry
       
   804                 if( aExtRecNo  > entry.PBEntryExtRecord.Count() )
       
   805                     {
       
   806                     ret = CheckForExtRecordNum( entry, aTransId );
       
   807                     }
       
   808                 else  
       
   809                     {
       
   810                     // check for reocrds to be delete
       
   811                     ret = ContinueWriteEntry( aExtRecNo, 
       
   812                                               entry, 
       
   813                                               aTransId, 
       
   814                                               aDataToWrite );
       
   815                     }
       
   816                 }
       
   817             else
       
   818                 {
       
   819                 // If entry not present
       
   820                 // Check if EXT Records are needed for Entry to be written
       
   821                 if( 0 < aExtRecNo )
       
   822                     {
       
   823                     // Search for free ext records 
       
   824                     iCurrentWritePhase = EPBWritePhase_Search_Ext_Entry;
       
   825                     // Send request To read First EXT record
       
   826                     iExtRecordNo = 1;
       
   827                     ret = UiccPbReqWriteReadExt(
       
   828                             iExtRecordNo,
       
   829                             aTransId );
       
   830                     }
       
   831                 else
       
   832                     {
       
   833                     // Start Writting Entry
       
   834                     iCurrentWritePhase = EPBWritePhase_Write_Entry;
       
   835                     TUint8 indexToWrite = iPhoneBookEntry->iLocation;
       
   836                     ret = UiccPBReqWriteEntry(
       
   837                             indexToWrite,
       
   838                             aTransId,
       
   839                             aDataToWrite );
       
   840                     }
       
   841                 }
       
   842             }   // end of if Entry is present in the list
       
   843         else
       
   844             {
       
   845             // First Read that Entry from SIM and then delete that entry
       
   846             // with EXT records if there are Any
       
   847             iCurrentWritePhase = EPBWritePhase_Read_Entry;
       
   848             ret = UiccPbReqWriteRead( aIndex, aTransId );
       
   849             }
       
   850 
       
   851     return ret;
       
   852     }
       
   853 
       
   854 
       
   855 // ---------------------------------------------------------------------------
       
   856 // CMmPhoneBookOperationWrite::UiccPbReqReadMBI
       
   857 // Constructs an ISI-message to Read MBI profile from first record 
       
   858 // ---------------------------------------------------------------------------
       
   859 //
       
   860 TInt CMmPhoneBookOperationWrite::UiccPbReqReadMBI( TUint8 aOffset, TUint8 aTransId )
   878     {
   861     {
   879 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::UiccPbReqReadMBI");
   862 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::UiccPbReqReadMBI");
   880 OstTrace0( TRACE_NORMAL, DUP1_CMMPHONEBOOKOPERATIONWRITE_UICCPBREQREADMBI, "CMmPhoneBookOperationWrite::UiccPbReqReadMBI" );
   863 OstTrace0( TRACE_NORMAL, DUP1_CMMPHONEBOOKOPERATIONWRITE_UICCPBREQREADMBI, "CMmPhoneBookOperationWrite::UiccPbReqReadMBI" );
   881         
   864         
   882         TInt ret ( KErrNone );
   865         TInt ret ( KErrNone );
   896         
   879         
   897         cmdParams.trId = static_cast<TUiccTrId>( aTransId );
   880         cmdParams.trId = static_cast<TUiccTrId>( aTransId );
   898         cmdParams.fileId = PB_MBI_FID;
   881         cmdParams.fileId = PB_MBI_FID;
   899         cmdParams.serviceType =  UICC_APPL_READ_LINEAR_FIXED ;
   882         cmdParams.serviceType =  UICC_APPL_READ_LINEAR_FIXED ;
   900         cmdParams.dataAmount = 1;
   883         cmdParams.dataAmount = 1;
   901         cmdParams.dataOffset = aIndex;
   884         
       
   885         if( aOffset <= iMmPhoneBookStoreMessHandler->
       
   886                 iPBStoreConf[iArrayIndex].iMbiRecLen )
       
   887             {
       
   888             cmdParams.dataOffset = aOffset;
       
   889             }
       
   890         else
       
   891             {
       
   892             ret = KErrArgument;
       
   893             }
       
   894         
   902         cmdParams.record = 1;   // only first profile number is supported
   895         cmdParams.record = 1;   // only first profile number is supported
   903         
   896         
   904         
   897         
   905         if( KErrNone == ret )
   898         if( KErrNone == ret )
   906             {
   899             {
   918 // ---------------------------------------------------------------------------
   911 // ---------------------------------------------------------------------------
   919 //
   912 //
   920 TInt CMmPhoneBookOperationWrite::UiccPBReqWriteMBIProfile( 
   913 TInt CMmPhoneBookOperationWrite::UiccPBReqWriteMBIProfile( 
   921         TUint8 aTransId,
   914         TUint8 aTransId,
   922         TUint8 aIndex,
   915         TUint8 aIndex,
   923         TUint8 aOperationType)
   916         TUint8 aOperationType )
   924     {
   917     {
   925 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::UiccPBReqWriteMBIProfile");
   918 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::UiccPBReqWriteMBIProfile");
   926 OstTrace0( TRACE_FATAL, CMMPHONEBOOKOPERATIONWRITE_UICCPBREQWRITEMBIPROFILE, "CMmPhoneBookOperationWrite::UiccPBReqWriteMBIProfile" );
   919 OstTrace0( TRACE_FATAL, CMMPHONEBOOKOPERATIONWRITE_UICCPBREQWRITEMBIPROFILE, "CMmPhoneBookOperationWrite::UiccPBReqWriteMBIProfile" );
   927 
   920 
   928     TInt ret ( KErrNone );
   921     TInt ret ( KErrNone );
   982 OstTrace0( TRACE_NORMAL, CMMPHONEBOOKOPERATIONWRITE_HANDLEUICCPBRESPL, "CMmPhoneBookOperationWrite::HandleUICCPbRespL" );
   975 OstTrace0( TRACE_NORMAL, CMMPHONEBOOKOPERATIONWRITE_HANDLEUICCPBRESPL, "CMmPhoneBookOperationWrite::HandleUICCPbRespL" );
   983     
   976     
   984     TBool complete ( EFalse );
   977     TBool complete ( EFalse );
   985     TInt ret ( KErrNone );
   978     TInt ret ( KErrNone );
   986     
   979     
   987     TUint16 fileIdExt ( 0x0000 );
       
   988     TUint16 fileId = ConvertToPBfileId( iPhoneBookTypeName, fileIdExt, iMmUiccMessHandler->GetCardType() );
       
   989     //// Check for PhoenBook Index for which needs to checked
       
   990     TUint8 pbArrayIndex = ConvertToConfArrayIndex( fileId );
       
   991 
       
   992     switch( iCurrentWritePhase )
   980     switch( iCurrentWritePhase )
   993         {
   981         {
   994         case EPBWritePhase_Read_Entry:
   982         case EPBWritePhase_Read_Entry:
   995             {
   983             {
   996             ret = HandleWriteReadEntryResp(
   984             ret = HandleWriteReadEntryResp(
   997                   aStatus,
   985                   aStatus,
   998                   aFileData,
   986                   aFileData,
   999                   aTransId,
   987                   aTransId );
  1000                   fileId,
       
  1001                   fileIdExt,
       
  1002                   pbArrayIndex );
       
  1003             break;
   988             break;
  1004             }
   989             }
  1005         case EPBWritePhase_Read_Ext_Entry:
   990         case EPBWritePhase_Read_Ext_Entry:
  1006             {
   991             {
  1007             ret = HandleWriteReadExtEntryResp(
   992             ret = HandleWriteReadExtEntryResp(
  1008                   aStatus,
   993                   aStatus,
  1009                   aFileData,
   994                   aFileData,
  1010                   aTransId,
   995                   aTransId );
  1011                   fileId,
       
  1012                   fileIdExt );
       
  1013             break;
   996             break;
  1014             }
   997             }
  1015         case EPBWritePhase_Search_Ext_Entry:
   998         case EPBWritePhase_Search_Ext_Entry:
  1016             {
   999             {
  1017             ret = HandleWriteSearchExtEntryResp(
  1000             ret = HandleWriteSearchExtEntryResp(
  1018                   aStatus,
  1001                   aStatus,
  1019                   aFileData,
  1002                   aFileData,
  1020                   aTransId,
  1003                   aTransId );
  1021                   fileId,
       
  1022                   fileIdExt );
       
  1023             break;
  1004             break;
  1024             }
  1005             }
  1025         case EPBWritePhase_Write_Entry:
  1006         case EPBWritePhase_Write_Entry:
  1026             {
  1007             {
  1027             ret = HandleWriteEntryResp(
  1008             ret = HandleWriteEntryResp(
  1028                   aStatus,
  1009                   aStatus,
  1029                   aTransId,
  1010                   aTransId );
  1030                   fileId,
       
  1031                   fileIdExt );
       
  1032             break;
  1011             break;
  1033             }
  1012             }
  1034         case EPBWritePhase_Write_Ext_Entry:
  1013         case EPBWritePhase_Write_Ext_Entry:
  1035             {
  1014             {
  1036             ret = HandleWriteExtEntryResp(
  1015             ret = HandleWriteExtEntryResp(
  1037                   aStatus,
  1016                   aStatus,
  1038                   aTransId,
  1017                   aTransId );
  1039                   fileId,
       
  1040                   fileIdExt );
       
  1041             break;
  1018             break;
  1042             }
  1019             }
  1043         case EPBWritePhase_Read_MBI_profile:
  1020         case EPBWritePhase_Read_MBI_profile:
  1044             {
  1021             {
  1045             ret = HandleWriteMBIReadResp(
  1022             ret = HandleWriteMBIReadResp(
  1064             }
  1041             }
  1065         }
  1042         }
  1066     
  1043     
  1067     if( ( KErrNone != ret ) || ( iCurrentWritePhase == EPBWritePhase_complete ))
  1044     if( ( KErrNone != ret ) || ( iCurrentWritePhase == EPBWritePhase_complete ))
  1068         {
  1045         {
  1069         // Complete the to common TSY
  1046         switch( iSavedIpc )
  1070         CPhoneBookDataPackage phoneBookData;
  1047             {
  1071 
  1048             case EMmTsyONStoreWriteIPC:
  1072         //create a struct
  1049                 {
  1073         TPBEntryInfo pbEntryInfo;
  1050                 // Reset SavedIpc IPC.
  1074         // Set the structure as it has failed, we don't care of following
  1051                 iSavedIpc = 0;
  1075         // information so set to 0
  1052                 if( KErrNone != ret )
  1076         pbEntryInfo.iMaxNumLength = 0;
  1053                     {
  1077         pbEntryInfo.iLocation = 0;
  1054                     // Complete failed request
  1078         if( KErrNone == ret )
  1055                     iMmPhoneBookStoreMessHandler->MessageRouter()->Complete(
  1079             {
  1056                             EMmTsyONStoreWriteIPC,
  1080             pbEntryInfo.iLocation = iPhoneBookEntry->iLocation;
  1057                             NULL,
  1081             }
  1058                             ret );
  1082         // For EXT file Errors need not to pass to commontsy
  1059                     }
  1083         if( KErrGeneral == ret )
  1060                 else
  1084             {
  1061                     {
  1085             ret = KErrNone;
  1062                     // Create data package
  1086             }
  1063                     CMmDataPackage numberData;
  1087         phoneBookData.SetPhoneBookName( iPhoneBookTypeName );
  1064                     numberData.PackData( &iPhoneBookEntry->iLocation );
  1088 
  1065 
  1089         //Pack Data and complete
  1066                     // Complete request
  1090         phoneBookData.PackData( &pbEntryInfo );
  1067                     iMmPhoneBookStoreMessHandler->MessageRouter()->Complete(
  1091         iMmPhoneBookStoreMessHandler->MessageRouter()->Complete(
  1068                             EMmTsyONStoreWriteIPC,
  1092             EMmTsyPhoneBookStoreWriteIPC,
  1069                             &numberData,
  1093             &phoneBookData,
  1070                             ret );
  1094             ret );
  1071                     }
  1095 
  1072                 
       
  1073                 // delete PhoneBook Entry
       
  1074                 delete iPhoneBookEntry;
       
  1075                 break;
       
  1076                 }
       
  1077             case EMmTsyONStoreWriteEntryIPC:
       
  1078                 {
       
  1079                 // Reset saved IPC.
       
  1080                 iSavedIpc = 0;
       
  1081                 // Complete request
       
  1082                 iMmPhoneBookStoreMessHandler->MessageRouter()->Complete(
       
  1083                         EMmTsyONStoreWriteEntryIPC,
       
  1084                         ret );
       
  1085                 
       
  1086                 // Delete Phone Book Entry
       
  1087                 delete iPhoneBookEntry;
       
  1088                 break;
       
  1089                 }
       
  1090             case EMmTsyPhoneBookStoreWriteIPC:
       
  1091                 {
       
  1092                 // Complete the to common TSY
       
  1093                 CPhoneBookDataPackage phoneBookData;
       
  1094 
       
  1095                 //create a struct
       
  1096                 TPBEntryInfo pbEntryInfo;
       
  1097                 // Set the structure as it has failed, we don't care of following
       
  1098                 // information so set to 0
       
  1099                 pbEntryInfo.iMaxNumLength = 0;
       
  1100                 pbEntryInfo.iLocation = 0;
       
  1101                 if( KErrNone == ret )
       
  1102                     {
       
  1103                     // Convert Phone Book name to file id
       
  1104                     pbEntryInfo.iMaxNumLength = iMmPhoneBookStoreMessHandler->
       
  1105                                      iPBStoreConf[iArrayIndex].iNumlength;
       
  1106                     if( 0 != iPhoneBookEntry->iLocation )
       
  1107                         {
       
  1108                         pbEntryInfo.iLocation = iPhoneBookEntry->iLocation;
       
  1109                         }
       
  1110                     else
       
  1111                         {
       
  1112                         pbEntryInfo.iLocation = iEntryToWrite;
       
  1113                         }
       
  1114                     }
       
  1115                 // For EXT file Errors need not to pass to commontsy
       
  1116                 if( KErrGeneral == ret )
       
  1117                     {
       
  1118                     ret = KErrNone;
       
  1119                     }
       
  1120                 phoneBookData.SetPhoneBookName( iPhoneBookTypeName );
       
  1121 
       
  1122                 //Pack Data and complete
       
  1123                 phoneBookData.PackData( &pbEntryInfo );
       
  1124                 iMmPhoneBookStoreMessHandler->MessageRouter()->Complete(
       
  1125                         EMmTsyPhoneBookStoreWriteIPC,
       
  1126                         &phoneBookData,
       
  1127                         ret );
       
  1128                 break;
       
  1129                 }
       
  1130             default:
       
  1131                 {
       
  1132 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::HandleSimPbRespL - unknown Ipc ");
       
  1133 OstTrace0( TRACE_NORMAL, DUP2_CMMPHONEBOOKOPERATIONWRITE_HANDLEUICCPBRESPL, "CMmPhoneBookOperationWrite::HandleUICCPbRespL - unknown Ipc" );
       
  1134                 break;
       
  1135                 }
       
  1136             }
  1096         // set flag to indicate that we can remove this operation from array
  1137         // set flag to indicate that we can remove this operation from array
  1097         complete = ETrue;
  1138         complete = ETrue;
  1098         }
  1139         }
  1099     return complete;
  1140     return complete;
  1100     }
  1141     }
  1106 // ---------------------------------------------------------------------------
  1147 // ---------------------------------------------------------------------------
  1107 //
  1148 //
  1108 TInt CMmPhoneBookOperationWrite::HandleWriteReadEntryResp(
  1149 TInt CMmPhoneBookOperationWrite::HandleWriteReadEntryResp(
  1109     TInt aStatus,
  1150     TInt aStatus,
  1110     const TDesC8& aFileData,
  1151     const TDesC8& aFileData,
  1111     TUint8 aTransId,
  1152     TUint8 aTransId )
  1112     TUint16 aFileId,
       
  1113     TUint16 aFileIdExt,
       
  1114     TUint8 aArrayIndex )
       
  1115     {
  1153     {
  1116 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::HandleWriteReadEntryResp");
  1154 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::HandleWriteReadEntryResp");
  1117 OstTrace0( TRACE_NORMAL, CMMPHONEBOOKOPERATIONWRITE_HANDLEWRITEREADENTRYRESP, "CMmPhoneBookOperationWrite::HandleWriteReadEntryResp" );
  1155 OstTrace0( TRACE_NORMAL, CMMPHONEBOOKOPERATIONWRITE_HANDLEWRITEREADENTRYRESP, "CMmPhoneBookOperationWrite::HandleWriteReadEntryResp" );
  1118     TInt ret ( KErrNone );
  1156     TInt ret ( KErrNone );
  1119     
  1157     
  1127             if( !iLocationSearch )
  1165             if( !iLocationSearch )
  1128                 {
  1166                 {
  1129                 
  1167                 
  1130                 // Check for Ext data present or not
  1168                 // Check for Ext data present or not
  1131                 if( 0xFF == aFileData[iMmPhoneBookStoreMessHandler->
  1169                 if( 0xFF == aFileData[iMmPhoneBookStoreMessHandler->
  1132                             iPBStoreConf[aArrayIndex].iAlphaStringlength+ 13] )
  1170                             iPBStoreConf[iArrayIndex].iAlphaStringlength+ 13] )
  1133                     {
  1171                     {
  1134                     // No EXT Records 
  1172                     // No EXT Records 
  1135                     // Check if EXT reords needed for Entry to be write
  1173                     // Check if EXT reords needed for Entry to be write
  1136                     if( ( KErrNotFound != iExtRecordArrayToBeWrite.Find( 0 ) ))
  1174                     if( ( KErrNotFound != iExtRecordArrayToBeWrite.Find( 0 ) ))
  1137                         {
  1175                         {
  1140                         iCurrentWritePhase = EPBWritePhase_Search_Ext_Entry;
  1178                         iCurrentWritePhase = EPBWritePhase_Search_Ext_Entry;
  1141                         
  1179                         
  1142                         // Send request to read first entry in Ext
  1180                         // Send request to read first entry in Ext
  1143                         iExtRecordNo = 1;
  1181                         iExtRecordNo = 1;
  1144                         ret = UiccPbReqWriteReadExt(
  1182                         ret = UiccPbReqWriteReadExt(
  1145                               aFileId,
       
  1146                               aFileIdExt,
       
  1147                               iExtRecordNo,
  1183                               iExtRecordNo,
  1148                               aTransId );
  1184                               aTransId );
  1149                         }
  1185                         }
  1150                     else
  1186                     else
  1151                         {
  1187                         {
  1152                         // Start Write main Entry
  1188                         // Start Write main Entry
  1153                         iCurrentWritePhase = EPBWritePhase_Write_Entry;
  1189                         iCurrentWritePhase = EPBWritePhase_Write_Entry;
  1154                         TUint8 indexToWrite ( 0 );
  1190                         TUint8 indexToWrite ( 0 );
  1155                         if( PB_MBDN_FID == aFileId )
  1191                         if( PB_MBDN_FID == iFileId )
  1156                             {
  1192                             {
  1157                             indexToWrite = iEntryToWrite;
  1193                             indexToWrite = iEntryToWrite;
  1158                             }
  1194                             }
  1159                         else
  1195                         else
  1160                             {
  1196                             {
  1161                             indexToWrite = iPhoneBookEntry->iLocation;
  1197                             indexToWrite = iPhoneBookEntry->iLocation;
  1162                             }
  1198                             }
  1163                         ret = UiccPBReqWriteEntry(
  1199                         ret = UiccPBReqWriteEntry(
  1164                               aFileId,
       
  1165                               indexToWrite,
  1200                               indexToWrite,
  1166                               aTransId,
  1201                               aTransId,
  1167                               *iPhoneBookEntry );
  1202                               *iPhoneBookEntry );
  1168                         }
  1203                         }
  1169                     }
  1204                     }
  1170                 else
  1205                 else
  1171                     {
  1206                     {
  1172                     // Append this Record number to be Delete record Array
  1207                     // Append this Record number to be Delete record Array
  1173                     iExtRecordArrayToBeDelete.Append(
  1208                     iExtRecordArrayToBeDelete.Append(
  1174                                     iMmPhoneBookStoreMessHandler->
  1209                                     iMmPhoneBookStoreMessHandler->
  1175                                     iPBStoreConf[aArrayIndex].iAlphaStringlength+ 13 );
  1210                                     iPBStoreConf[iArrayIndex].iAlphaStringlength+ 13 );
  1176                     
  1211                     
  1177                     // Start Reading EXT Record
  1212                     // Start Reading EXT Record
  1178                     iCurrentWritePhase = EPBWritePhase_Read_Ext_Entry;
  1213                     iCurrentWritePhase = EPBWritePhase_Read_Ext_Entry;
  1179                     TUint8 indexToRead = iMmPhoneBookStoreMessHandler->
  1214                     TUint8 indexToRead = iMmPhoneBookStoreMessHandler->
  1180                                iPBStoreConf[aArrayIndex].iAlphaStringlength+ 13;
  1215                                iPBStoreConf[iArrayIndex].iAlphaStringlength+ 13;
  1181                     ret = UiccPbReqWriteReadExt(
  1216                     ret = UiccPbReqWriteReadExt(
  1182                           aFileId,
       
  1183                           aFileIdExt,
       
  1184                           indexToRead,
  1217                           indexToRead,
  1185                           aTransId );
  1218                           aTransId );
  1186                     }
  1219                     }
  1187                 }
  1220                 }
  1188             else
  1221             else
  1190                 // Serach for next location
  1223                 // Serach for next location
  1191                 // Start searching for first free Entry
  1224                 // Start searching for first free Entry
  1192                 iCurrentWritePhase = EPBWritePhase_Read_Entry;
  1225                 iCurrentWritePhase = EPBWritePhase_Read_Entry;
  1193                 iEntryToWrite++;
  1226                 iEntryToWrite++;
  1194                 ret = UiccPbReqWriteRead(
  1227                 ret = UiccPbReqWriteRead(
  1195                       aFileId,
       
  1196                       iEntryToWrite,
  1228                       iEntryToWrite,
  1197                       aTransId );
  1229                       aTransId );
  1198                 }
  1230                 }
  1199             }
  1231             }
  1200         else
  1232         else
  1209                 iCurrentWritePhase = EPBWritePhase_Search_Ext_Entry;
  1241                 iCurrentWritePhase = EPBWritePhase_Search_Ext_Entry;
  1210                 
  1242                 
  1211                 // Send request to read first entry in Ext
  1243                 // Send request to read first entry in Ext
  1212                 iExtRecordNo = 1;
  1244                 iExtRecordNo = 1;
  1213                 ret = UiccPbReqWriteReadExt(
  1245                 ret = UiccPbReqWriteReadExt(
  1214                       aFileId,
       
  1215                       aFileIdExt,
       
  1216                       iExtRecordNo,
  1246                       iExtRecordNo,
  1217                       aTransId);
  1247                       aTransId);
  1218                 }
  1248                 }
  1219             else
  1249             else
  1220                 {
  1250                 {
  1221                 // For MBDN PhoneBook First update MBI File
  1251                 // For MBDN PhoneBook First update MBI File
  1222                 
  1252                 
  1223                 // Start Write Entry
  1253                 // Start Write Entry
  1224                 iCurrentWritePhase = EPBWritePhase_Write_Entry;
  1254                 iCurrentWritePhase = EPBWritePhase_Write_Entry;
  1225                 TUint8 index ( 0 ); 
  1255                 TUint8 index ( 0 ); 
  1226                 if( ( PB_MBDN_FID == aFileId )|| ( 0 == iPhoneBookEntry->iLocation ))
  1256                 if( ( PB_MBDN_FID == iFileId )|| ( 0 == iPhoneBookEntry->iLocation ))
  1227                     {
  1257                     {
  1228                     index = iEntryToWrite; 
  1258                     index = iEntryToWrite; 
  1229                     }
  1259                     }
  1230                 else
  1260                 else
  1231                     {
  1261                     {
  1232                     index = iPhoneBookEntry->iLocation;
  1262                     index = iPhoneBookEntry->iLocation;
  1233                     }
  1263                     }
  1234                 ret = UiccPBReqWriteEntry(
  1264                 ret = UiccPBReqWriteEntry(
  1235                         aFileId,
       
  1236                         index,
  1265                         index,
  1237                         aTransId,
  1266                         aTransId,
  1238                         *iPhoneBookEntry );
  1267                         *iPhoneBookEntry );
  1239                 }
  1268                 }
  1240             }
  1269             }
  1257 // ---------------------------------------------------------------------------
  1286 // ---------------------------------------------------------------------------
  1258 //
  1287 //
  1259 TInt CMmPhoneBookOperationWrite::HandleWriteReadExtEntryResp(
  1288 TInt CMmPhoneBookOperationWrite::HandleWriteReadExtEntryResp(
  1260     TInt aStatus,
  1289     TInt aStatus,
  1261     const TDesC8& aFileData,
  1290     const TDesC8& aFileData,
  1262     TUint8 aTransId,
  1291     TUint8 aTransId )
  1263     TUint16 aFileId,
       
  1264     TUint16 aFileIdExt)
       
  1265     {
  1292     {
  1266 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::HandleWriteReadExtEntryResp");
  1293 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::HandleWriteReadExtEntryResp");
  1267 OstTrace0( TRACE_NORMAL, CMMPHONEBOOKOPERATIONWRITE_HANDLEWRITEREADEXTENTRYRESP, "CMmPhoneBookOperationWrite::HandleWriteReadExtEntryResp" );
  1294 OstTrace0( TRACE_NORMAL, CMMPHONEBOOKOPERATIONWRITE_HANDLEWRITEREADEXTENTRYRESP, "CMmPhoneBookOperationWrite::HandleWriteReadExtEntryResp" );
  1268     TInt ret ( KErrNone );
  1295     TInt ret ( KErrNone );
  1269     
  1296     
  1290                     iExtDeleteOperation= ETrue;
  1317                     iExtDeleteOperation= ETrue;
  1291                     //last index
  1318                     //last index
  1292                     TUint8 index = iExtRecordArrayToBeDelete[
  1319                     TUint8 index = iExtRecordArrayToBeDelete[
  1293                                         iExtRecordArrayToBeDelete.Count() -1 ];
  1320                                         iExtRecordArrayToBeDelete.Count() -1 ];
  1294                     ret = UiccPbReqWriteExtDelete(
  1321                     ret = UiccPbReqWriteExtDelete(
  1295                           aFileId,
       
  1296                           aFileIdExt,
       
  1297                           index,
  1322                           index,
  1298                           aTransId );
  1323                           aTransId );
  1299                     }
  1324                     }
  1300                 else
  1325                 else
  1301                     {
  1326                     {
  1307                     // Start Searching for remaining records
  1332                     // Start Searching for remaining records
  1308                     iCurrentWritePhase = EPBWritePhase_Search_Ext_Entry;
  1333                     iCurrentWritePhase = EPBWritePhase_Search_Ext_Entry;
  1309                     // Start Searching for first location
  1334                     // Start Searching for first location
  1310                     iExtRecordNo = 1;
  1335                     iExtRecordNo = 1;
  1311                     ret = UiccPbReqWriteReadExt(
  1336                     ret = UiccPbReqWriteReadExt(
  1312                           aFileId,
       
  1313                           aFileIdExt,
       
  1314                           iExtRecordNo,
  1337                           iExtRecordNo,
  1315                           aTransId );
  1338                           aTransId );
  1316                     }
  1339                     }
  1317                 }
  1340                 }
  1318             else
  1341             else
  1325                     iExtDeleteOperation = ETrue;
  1348                     iExtDeleteOperation = ETrue;
  1326                     //last index
  1349                     //last index
  1327                     TUint8 index = 
  1350                     TUint8 index = 
  1328                       iExtRecordArrayToBeDelete[ iExtRecordArrayToBeDelete.Count() -1 ];
  1351                       iExtRecordArrayToBeDelete[ iExtRecordArrayToBeDelete.Count() -1 ];
  1329                     ret = UiccPbReqWriteExtDelete(
  1352                     ret = UiccPbReqWriteExtDelete(
  1330                           aFileId,
       
  1331                           aFileIdExt,
       
  1332                           index,
  1353                           index,
  1333                           aTransId );
  1354                           aTransId );
  1334                     }
  1355                     }
  1335                 else
  1356                 else
  1336                     {
  1357                     {
  1337                     // Start Writing main Entry
  1358                     // Start Writing main Entry
  1338                     iCurrentWritePhase = EPBWritePhase_Write_Entry;
  1359                     iCurrentWritePhase = EPBWritePhase_Write_Entry;
  1339                     //last index
  1360                     //last index
  1340                     TUint8 index (0 );
  1361                     TUint8 index (0 );
  1341                     if( PB_MBDN_FID == aFileId )
  1362                     if( PB_MBDN_FID == iFileId )
  1342                         {
  1363                         {
  1343                         index = iEntryToWrite;
  1364                         index = iEntryToWrite;
  1344                         }
  1365                         }
  1345                     else
  1366                     else
  1346                         {
  1367                         {
  1347                         index = iPhoneBookEntry->iLocation;
  1368                         index = iPhoneBookEntry->iLocation;
  1348                         }
  1369                         }
  1349                     ret = UiccPBReqWriteEntry(
  1370                     ret = UiccPBReqWriteEntry(
  1350                           aFileId,
       
  1351                           index,
  1371                           index,
  1352                           aTransId,
  1372                           aTransId,
  1353                           *iPhoneBookEntry );
  1373                           *iPhoneBookEntry );
  1354                     }
  1374                     }
  1355                 }
  1375                 }
  1359             // Append Current record no to the Array
  1379             // Append Current record no to the Array
  1360             iExtRecordArrayToBeDelete.Append( aFileData[UICC_EXT_REC_NO_OFFSET] );
  1380             iExtRecordArrayToBeDelete.Append( aFileData[UICC_EXT_REC_NO_OFFSET] );
  1361             // Raed Next 
  1381             // Raed Next 
  1362             iCurrentWritePhase = EPBWritePhase_Read_Ext_Entry;
  1382             iCurrentWritePhase = EPBWritePhase_Read_Ext_Entry;
  1363             ret = UiccPbReqWriteReadExt(
  1383             ret = UiccPbReqWriteReadExt(
  1364                   aFileId,
       
  1365                   aFileIdExt,
       
  1366                   aFileData[UICC_EXT_REC_NO_OFFSET],
  1384                   aFileData[UICC_EXT_REC_NO_OFFSET],
  1367                   aTransId );
  1385                   aTransId );
  1368             }
  1386             }
  1369         }
  1387         }
  1370     else
  1388     else
  1381 // ---------------------------------------------------------------------------
  1399 // ---------------------------------------------------------------------------
  1382 //
  1400 //
  1383 TInt CMmPhoneBookOperationWrite::HandleWriteSearchExtEntryResp(
  1401 TInt CMmPhoneBookOperationWrite::HandleWriteSearchExtEntryResp(
  1384     TInt aStatus,
  1402     TInt aStatus,
  1385     const TDesC8& aFileData,
  1403     const TDesC8& aFileData,
  1386     TUint8 aTransId,
  1404     TUint8 aTransId )
  1387     TUint16 aFileId,
       
  1388     TUint16 aFileIdExt)
       
  1389     {
  1405     {
  1390 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::HandleWriteSearchExtEntryResp");
  1406 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::HandleWriteSearchExtEntryResp");
  1391 OstTrace0( TRACE_NORMAL, CMMPHONEBOOKOPERATIONWRITE_HANDLEWRITESEARCHEXTENTRYRESP, "CMmPhoneBookOperationWrite::HandleWriteSearchExtEntryResp" );
  1407 OstTrace0( TRACE_NORMAL, CMMPHONEBOOKOPERATIONWRITE_HANDLEWRITESEARCHEXTENTRYRESP, "CMmPhoneBookOperationWrite::HandleWriteSearchExtEntryResp" );
  1392     TInt ret ( KErrNone );
  1408     TInt ret ( KErrNone );
  1393     TUint8 arrayIndex ( ConvertToConfArrayIndex( aFileId ) );
  1409 
  1394     
       
  1395     if( UICC_STATUS_OK == aStatus)
  1410     if( UICC_STATUS_OK == aStatus)
  1396         {
  1411         {
  1397         // Check if Entry is Free
  1412         // Check if Entry is Free
  1398         if( KErrNotFound == EmptyEntryCheck( aFileData ) )
  1413         if( KErrNotFound == EmptyEntryCheck( aFileData ) )
  1399             {
  1414             {
  1411                     iCurrentWritePhase = EPBWritePhase_Write_Ext_Entry;
  1426                     iCurrentWritePhase = EPBWritePhase_Write_Ext_Entry;
  1412                     iExtDeleteOperation = ETrue;
  1427                     iExtDeleteOperation = ETrue;
  1413                     TUint8 index = 
  1428                     TUint8 index = 
  1414                     iExtRecordArrayToBeDelete[ iExtRecordArrayToBeDelete.Count() -1 ];
  1429                     iExtRecordArrayToBeDelete[ iExtRecordArrayToBeDelete.Count() -1 ];
  1415                     ret = UiccPbReqWriteExtDelete( 
  1430                     ret = UiccPbReqWriteExtDelete( 
  1416                             aFileId,
       
  1417                             aFileIdExt,
       
  1418                             index,
  1431                             index,
  1419                             aTransId );
  1432                             aTransId );
  1420                     iExtRecordArrayToBeDelete.Remove( 
  1433                     iExtRecordArrayToBeDelete.Remove( 
  1421                             iExtRecordArrayToBeDelete.Count() -1 );
  1434                             iExtRecordArrayToBeDelete.Count() -1 );
  1422                     iExtRecordArrayToBeDelete.Compress();
  1435                     iExtRecordArrayToBeDelete.Compress();
  1426                     // Start Writing the Entry
  1439                     // Start Writing the Entry
  1427                     iCurrentWritePhase = EPBWritePhase_Write_Entry;
  1440                     iCurrentWritePhase = EPBWritePhase_Write_Entry;
  1428                     TUint8 index ( 0 );
  1441                     TUint8 index ( 0 );
  1429                         // Start writing main Entry
  1442                         // Start writing main Entry
  1430                     if( ( iPhoneBookEntry->iLocation == 0 )||
  1443                     if( ( iPhoneBookEntry->iLocation == 0 )||
  1431                         ( PB_MBDN_FID == aFileId ) )
  1444                         ( PB_MBDN_FID == iFileId ) )
  1432                         {
  1445                         {
  1433                         index = iEntryToWrite;
  1446                         index = iEntryToWrite;
  1434                         }
  1447                         }
  1435                     else
  1448                     else
  1436                         {
  1449                         {
  1437                         index = iPhoneBookEntry->iLocation;
  1450                         index = iPhoneBookEntry->iLocation;
  1438                         }
  1451                         }
  1439                     if( 0 < index )
  1452                     if( 0 < index )
  1440                         {
  1453                         {
  1441                         ret = UiccPBReqWriteEntry(
  1454                         ret = UiccPBReqWriteEntry(
  1442                                 aFileId,
       
  1443                                 index,
  1455                                 index,
  1444                                 aTransId,
  1456                                 aTransId,
  1445                                 *iPhoneBookEntry );
  1457                                 *iPhoneBookEntry );
  1446                         }
  1458                         }
  1447                     else
  1459                     else
  1454                 {
  1466                 {
  1455                 // further search for free records
  1467                 // further search for free records
  1456                 iCurrentWritePhase = EPBWritePhase_Search_Ext_Entry;
  1468                 iCurrentWritePhase = EPBWritePhase_Search_Ext_Entry;
  1457                 TUint8 index = iExtRecordNo++;
  1469                 TUint8 index = iExtRecordNo++;
  1458                 if( index < iMmPhoneBookStoreMessHandler->
  1470                 if( index < iMmPhoneBookStoreMessHandler->
  1459                             iPBStoreConf[ arrayIndex ].iExtNoOfRec )
  1471                             iPBStoreConf[ iArrayIndex ].iExtNoOfRec )
  1460                     {
  1472                     {
  1461                     ret = UiccPbReqWriteReadExt(
  1473                     ret = UiccPbReqWriteReadExt(
  1462                           aFileId,
       
  1463                           aFileIdExt,
       
  1464                           index,
  1474                           index,
  1465                           aTransId );
  1475                           aTransId );
  1466                     }
  1476                     }
  1467                 else
  1477                 else
  1468                     {
  1478                     {
  1474             {
  1484             {
  1475             // further search for free records
  1485             // further search for free records
  1476             iCurrentWritePhase = EPBWritePhase_Search_Ext_Entry;
  1486             iCurrentWritePhase = EPBWritePhase_Search_Ext_Entry;
  1477             TUint8 index = iExtRecordNo++;
  1487             TUint8 index = iExtRecordNo++;
  1478             if( index < iMmPhoneBookStoreMessHandler->
  1488             if( index < iMmPhoneBookStoreMessHandler->
  1479                         iPBStoreConf[ arrayIndex ].iExtNoOfRec )
  1489                         iPBStoreConf[ iArrayIndex ].iExtNoOfRec )
  1480                 {
  1490                 {
  1481                 ret = UiccPbReqWriteReadExt(
  1491                 ret = UiccPbReqWriteReadExt(
  1482                       aFileId,
       
  1483                       aFileIdExt,
       
  1484                       index,
  1492                       index,
  1485                       aTransId );
  1493                       aTransId );
  1486                 }
  1494                 }
  1487             else
  1495             else
  1488                 {
  1496                 {
  1505 // Handle write response for EXT part of Entry
  1513 // Handle write response for EXT part of Entry
  1506 // ---------------------------------------------------------------------------
  1514 // ---------------------------------------------------------------------------
  1507 //
  1515 //
  1508 TInt CMmPhoneBookOperationWrite::HandleWriteEntryResp(
  1516 TInt CMmPhoneBookOperationWrite::HandleWriteEntryResp(
  1509     TInt aStatus,
  1517     TInt aStatus,
  1510     TUint8 aTransId,
  1518     TUint8 aTransId )
  1511     TUint16 aFileId,
       
  1512     TUint16 aFileIdExt) 
       
  1513     {
  1519     {
  1514 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::HandleWriteEntryResp");
  1520 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::HandleWriteEntryResp");
  1515 OstTrace0( TRACE_NORMAL, CMMPHONEBOOKOPERATIONWRITE_HANDLEWRITEENTRYRESP, "CMmPhoneBookOperationWrite::HandleWriteEntryResp" );
  1521 OstTrace0( TRACE_NORMAL, CMMPHONEBOOKOPERATIONWRITE_HANDLEWRITEENTRYRESP, "CMmPhoneBookOperationWrite::HandleWriteEntryResp" );
  1516     TInt ret ( KErrNone );
  1522     TInt ret ( KErrNone );
  1517     TUint8 arrayIndex ( ConvertToConfArrayIndex( aFileId ));
  1523 
  1518     
       
  1519     if( UICC_STATUS_OK == aStatus )
  1524     if( UICC_STATUS_OK == aStatus )
  1520         {
  1525         {
  1521         iEntryToUpdateInList = new ( ELeave ) TPBEntry();
  1526         iEntryToUpdateInList = new ( ELeave ) TPBEntry();
  1522         
  1527         
  1523         // Update the Entry needs to be Stored
  1528         // Update the Entry needs to be Stored
  1524         if( ( 0 == iPhoneBookEntry->iLocation )|| ( PB_MBDN_FID == aFileId ) )
  1529         if( ( 0 == iPhoneBookEntry->iLocation )|| ( PB_MBDN_FID == iFileId ) )
  1525             {
  1530             {
  1526             iEntryToUpdateInList->iEntryIndex = iEntryToWrite;
  1531             iEntryToUpdateInList->iEntryIndex = iEntryToWrite;
  1527             iEntryToUpdateInList->iEntryPresent = ETrue;
  1532             iEntryToUpdateInList->iEntryPresent = ETrue;
  1528             }
  1533             }
  1529         else
  1534         else
  1541             // Start Writing to EXT records
  1546             // Start Writing to EXT records
  1542             TUint8 index = iExtRecordArrayToBeWrite[0];
  1547             TUint8 index = iExtRecordArrayToBeWrite[0];
  1543             ret = UiccPbReqWriteExt(
  1548             ret = UiccPbReqWriteExt(
  1544                     aTransId,
  1549                     aTransId,
  1545                     index,
  1550                     index,
  1546                     aFileId,
       
  1547                     aFileIdExt,
       
  1548                     *iPhoneBookEntry );
  1551                     *iPhoneBookEntry );
  1549             }
  1552             }
  1550         else
  1553         else
  1551             {
  1554             {
  1552             // Remove old Entry from the list 
  1555             // Remove old Entry from the list 
  1553             TInt index = iMmPhoneBookStoreMessHandler->
  1556             TInt index = iMmPhoneBookStoreMessHandler->
  1554                          GetIndexForPresentEntry( iPhoneBookEntry->iLocation, arrayIndex );
  1557                          GetIndexForPresentEntry( iPhoneBookEntry->iLocation, iArrayIndex );
  1555             if( 0 <= index )
  1558             if( 0 <= index )
  1556                 {
  1559                 {
  1557                 iMmPhoneBookStoreMessHandler->UpdateEntryFromList( 
  1560                 iMmPhoneBookStoreMessHandler->UpdateEntryFromList( 
  1558                                                 iEntryToUpdateInList,
  1561                                                 iEntryToUpdateInList,
  1559                                                 index,
  1562                                                 index,
  1560                                                 arrayIndex );
  1563                                                 iArrayIndex );
  1561                 }
  1564                 }
  1562             else
  1565             else
  1563                 {
  1566                 {
  1564                 // Append the Entry to the List
  1567                 // Append the Entry to the List
  1565                 iMmPhoneBookStoreMessHandler->StoreEntryToPhoneBookList(
  1568                 iMmPhoneBookStoreMessHandler->StoreEntryToPhoneBookList(
  1566                                                 iEntryToUpdateInList,
  1569                                                 iEntryToUpdateInList,
  1567                                                 arrayIndex );
  1570                                                 iArrayIndex );
  1568                 }
  1571                 }
  1569             // If it is MBDN Phone Book then update MBI File also
  1572             // If it is MBDN Phone Book then update MBI File also
  1570             if( PB_MBDN_FID == aFileId)
  1573             if( PB_MBDN_FID == iFileId)
  1571                 {
  1574                 {
  1572                 // Start Writing MBI file
  1575                 // Start Writing MBI file
  1573                 iCurrentWritePhase = EPBWritePhase_Write_MBI_profile;
  1576                 iCurrentWritePhase = EPBWritePhase_Write_MBI_profile;
  1574                 ret = UiccPBReqWriteMBIProfile( 
  1577                 ret = UiccPBReqWriteMBIProfile( 
  1575                         aTransId,
  1578                         aTransId,
  1584             }
  1587             }
  1585         }
  1588         }
  1586     else
  1589     else
  1587         {
  1590         {
  1588         // If it is a MBDN PhoneBook Then delete MBI profile by writin 0
  1591         // If it is a MBDN PhoneBook Then delete MBI profile by writin 0
  1589         if( PB_MBDN_FID == aFileId)
  1592         if( PB_MBDN_FID == iFileId)
  1590             {
  1593             {
  1591             // Start Writing MBI file
  1594             // Start Writing MBI file
  1592             iCurrentWritePhase = EPBWritePhase_Write_MBI_profile;
  1595             iCurrentWritePhase = EPBWritePhase_Write_MBI_profile;
  1593             ret = UiccPBReqWriteMBIProfile( 
  1596             ret = UiccPBReqWriteMBIProfile( 
  1594                     aTransId,
  1597                     aTransId,
  1612 // Handle write response for EXT part of Entry
  1615 // Handle write response for EXT part of Entry
  1613 // ---------------------------------------------------------------------------
  1616 // ---------------------------------------------------------------------------
  1614 //
  1617 //
  1615 TInt CMmPhoneBookOperationWrite::HandleWriteExtEntryResp(
  1618 TInt CMmPhoneBookOperationWrite::HandleWriteExtEntryResp(
  1616     TInt aStatus,
  1619     TInt aStatus,
  1617     TUint8 aTransId,
  1620     TUint8 aTransId )
  1618     TUint16 aFileId,
       
  1619     TUint16 aFileIdExt) 
       
  1620     {
  1621     {
  1621 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::HandleWriteExtEntryResp");
  1622 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::HandleWriteExtEntryResp");
  1622 OstTrace0( TRACE_NORMAL, CMMPHONEBOOKOPERATIONWRITE_HANDLEWRITEEXTENTRYRESP, "CMmPhoneBookOperationWrite::HandleWriteExtEntryResp" );
  1623 OstTrace0( TRACE_NORMAL, CMMPHONEBOOKOPERATIONWRITE_HANDLEWRITEEXTENTRYRESP, "CMmPhoneBookOperationWrite::HandleWriteExtEntryResp" );
  1623     TInt ret ( KErrNone );
  1624     TInt ret ( KErrNone );
  1624     TUint8 arrayIndex ( ConvertToConfArrayIndex( aFileId ));
       
  1625     
  1625     
  1626     if( UICC_STATUS_OK  == aStatus )
  1626     if( UICC_STATUS_OK  == aStatus )
  1627         {
  1627         {
  1628         if( iExtDeleteOperation )
  1628         if( iExtDeleteOperation )
  1629             {
  1629             {
  1635                 iExtRecordArrayToBeDelete.Compress();
  1635                 iExtRecordArrayToBeDelete.Compress();
  1636                 }
  1636                 }
  1637             // Remove old Entry from the list 
  1637             // Remove old Entry from the list 
  1638             TInt index = iMmPhoneBookStoreMessHandler->GetIndexForPresentEntry(
  1638             TInt index = iMmPhoneBookStoreMessHandler->GetIndexForPresentEntry(
  1639                                                         iPhoneBookEntry->iLocation,
  1639                                                         iPhoneBookEntry->iLocation,
  1640                                                         arrayIndex );
  1640                                                         iArrayIndex );
  1641             if( 0 <= index )
  1641             if( 0 <= index )
  1642                 {
  1642                 {
  1643                 iMmPhoneBookStoreMessHandler->RemoveExtEntryFromList(
  1643                 iMmPhoneBookStoreMessHandler->RemoveExtEntryFromList(
  1644                                                 index,
  1644                                                 index,
  1645                                                 arrayIndex);
  1645                                                 iArrayIndex);
  1646                 }
  1646                 }
  1647             
  1647             
  1648             if( iExtRecordArrayToBeDelete.Count() > 0 )
  1648             if( iExtRecordArrayToBeDelete.Count() > 0 )
  1649                 {
  1649                 {
  1650                 iCurrentWritePhase = EPBWritePhase_Write_Ext_Entry;
  1650                 iCurrentWritePhase = EPBWritePhase_Write_Ext_Entry;
  1651                 iExtDeleteOperation = ETrue;
  1651                 iExtDeleteOperation = ETrue;
  1652                 TUint8 index = iExtRecordArrayToBeDelete[
  1652                 TUint8 index = iExtRecordArrayToBeDelete[
  1653                                iExtRecordArrayToBeDelete.Count() -1 ];
  1653                                iExtRecordArrayToBeDelete.Count() -1 ];
  1654                 ret = UiccPbReqWriteExtDelete(
  1654                 ret = UiccPbReqWriteExtDelete(
  1655                               aFileId,
       
  1656                               aFileIdExt,
       
  1657                               index,
  1655                               index,
  1658                               aTransId );
  1656                               aTransId );
  1659                 }
  1657                 }
  1660             else
  1658             else
  1661                 {
  1659                 {
  1662                 // Start Writing the Entry
  1660                 // Start Writing the Entry
  1663                 iCurrentWritePhase = EPBWritePhase_Write_Entry;
  1661                 iCurrentWritePhase = EPBWritePhase_Write_Entry;
  1664                 TUint8 index ( 0 );
  1662                 TUint8 index ( 0 );
  1665                 // Start writing main Entry
  1663                 // Start writing main Entry
  1666                 if( ( iPhoneBookEntry->iLocation == 0 )||
  1664                 if( ( iPhoneBookEntry->iLocation == 0 )||
  1667                       ( PB_MBDN_FID == aFileId ) )
  1665                       ( PB_MBDN_FID == iFileId ) )
  1668                     {
  1666                     {
  1669                     index = iEntryToWrite;
  1667                     index = iEntryToWrite;
  1670                     }
  1668                     }
  1671                 else
  1669                 else
  1672                     {
  1670                     {
  1673                     index = iPhoneBookEntry->iLocation;
  1671                     index = iPhoneBookEntry->iLocation;
  1674                     }
  1672                     }
  1675                 if( 0 < index )
  1673                 if( 0 < index )
  1676                     {
  1674                     {
  1677                     ret = UiccPBReqWriteEntry(
  1675                     ret = UiccPBReqWriteEntry(
  1678                           aFileId,
       
  1679                           index,
  1676                           index,
  1680                           aTransId,
  1677                           aTransId,
  1681                           *iPhoneBookEntry );
  1678                           *iPhoneBookEntry );
  1682                     }
  1679                     }
  1683                 else
  1680                 else
  1703                 iEntryToUpdateInList->PBEntryExtRecord.Append( iExtRecordArrayToBeWrite[0] );
  1700                 iEntryToUpdateInList->PBEntryExtRecord.Append( iExtRecordArrayToBeWrite[0] );
  1704                 TUint8 index = iExtRecordArrayToBeWrite[0];
  1701                 TUint8 index = iExtRecordArrayToBeWrite[0];
  1705                 ret = UiccPbReqWriteExt(
  1702                 ret = UiccPbReqWriteExt(
  1706                       aTransId,
  1703                       aTransId,
  1707                       index,
  1704                       index,
  1708                       aFileId,
       
  1709                       aFileIdExt,
       
  1710                       *iPhoneBookEntry );
  1705                       *iPhoneBookEntry );
  1711                 }
  1706                 }
  1712             else
  1707             else
  1713                 {
  1708                 {
  1714                 // Overwrite old Entry from the list 
  1709                 // Overwrite old Entry from the list 
  1715                 TInt index = iMmPhoneBookStoreMessHandler->
  1710                 TInt index = iMmPhoneBookStoreMessHandler->
  1716                                 GetIndexForPresentEntry( 
  1711                                 GetIndexForPresentEntry( 
  1717                                   iPhoneBookEntry->iLocation,
  1712                                   iPhoneBookEntry->iLocation,
  1718                                   arrayIndex );
  1713                                   iArrayIndex );
  1719                 if( 0 <= index )
  1714                 if( 0 <= index )
  1720                     {
  1715                     {
  1721                     iMmPhoneBookStoreMessHandler->UpdateEntryFromList(
  1716                     iMmPhoneBookStoreMessHandler->UpdateEntryFromList(
  1722                                                    iEntryToUpdateInList,
  1717                                                    iEntryToUpdateInList,
  1723                                                    index,
  1718                                                    index,
  1724                                                    arrayIndex );
  1719                                                    iArrayIndex );
  1725                     }
  1720                     }
  1726                 else
  1721                 else
  1727                     {
  1722                     {
  1728                     // Append the Entry to the List
  1723                     // Append the Entry to the List
  1729                     iMmPhoneBookStoreMessHandler->StoreEntryToPhoneBookList(
  1724                     iMmPhoneBookStoreMessHandler->StoreEntryToPhoneBookList(
  1730                                                     iEntryToUpdateInList,
  1725                                                     iEntryToUpdateInList,
  1731                                                     arrayIndex );
  1726                                                     iArrayIndex );
  1732                     }
  1727                     }
  1733                 // If it is MBDN PhoenBook then update MBI Profile also
  1728                 // If it is MBDN PhoenBook then update MBI Profile also
  1734                 if( PB_MBDN_FID == aFileId)
  1729                 if( PB_MBDN_FID == iFileId)
  1735                     {
  1730                     {
  1736                     // Start Writing MBI file
  1731                     // Start Writing MBI file
  1737                     iCurrentWritePhase = EPBWritePhase_Write_MBI_profile;
  1732                     iCurrentWritePhase = EPBWritePhase_Write_MBI_profile;
  1738                     ret = UiccPBReqWriteMBIProfile( 
  1733                     ret = UiccPBReqWriteMBIProfile( 
  1739                             aTransId,
  1734                             aTransId,
  1749                 }
  1744                 }
  1750             }
  1745             }
  1751         }
  1746         }
  1752     else
  1747     else
  1753         {
  1748         {
  1754         if( PB_MBDN_FID == aFileId )
  1749         if( PB_MBDN_FID == iFileId )
  1755             {
  1750             {
  1756             // Start Writing MBI File
  1751             // Start Writing MBI File
  1757             iCurrentWritePhase = EPBWritePhase_Write_MBI_profile;
  1752             iCurrentWritePhase = EPBWritePhase_Write_MBI_profile;
  1758             ret = UiccPBReqWriteMBIProfile( 
  1753             ret = UiccPBReqWriteMBIProfile( 
  1759                     aTransId,
  1754                     aTransId,
  1840         else
  1835         else
  1841             {
  1836             {
  1842             ret = KErrArgument;
  1837             ret = KErrArgument;
  1843             }
  1838             }
  1844         }
  1839         }
  1845 
       
  1846 
       
  1847     return ret;
  1840     return ret;
  1848     }
  1841     }
  1849 
  1842 
       
  1843 
       
  1844 
       
  1845 
       
  1846 // ---------------------------------------------------------------------------
       
  1847 // void CMmPhoneBookOperationWrite::GetExtRecNum
       
  1848 // Get the total number of Ext records needed for new entry
       
  1849 // ---------------------------------------------------------------------------
       
  1850 //
       
  1851 void CMmPhoneBookOperationWrite::GetExtRecNum( TUint8 &aExtRecordNo )
       
  1852 {
       
  1853 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::GetExtRecNum");
       
  1854 OstTrace0( TRACE_NORMAL, DUP1_CMMPHONEBOOKOPERATIONWRITE_UICCPBREQWRITEMSISDN, "CMmPhoneBookOperationWrite::UiccPbReqWriteMsisdn" );
       
  1855 
       
  1856 
       
  1857     if( UICC_EF_FDN_NO_EXT_NUM_LEN < iPhoneBookEntry->iNumber->Length() )
       
  1858         {
       
  1859         aExtRecordNo++;
       
  1860         TInt extDataLength = iPhoneBookEntry->iNumber->Length() - 
       
  1861                               UICC_EF_FDN_NO_EXT_NUM_LEN;
       
  1862         while ( extDataLength > UICC_EF_EXT_REC_NUM_LEN)
       
  1863             {
       
  1864             aExtRecordNo++;
       
  1865             extDataLength = extDataLength - UICC_EF_EXT_REC_NUM_LEN;
       
  1866             }
       
  1867         }
       
  1868     
       
  1869     // reserve Space for ext record no
       
  1870     iExtRecordArrayToBeWrite.ReserveL( aExtRecordNo );
       
  1871     // File reserved memory with 0
       
  1872     for( TInt count = 0; count < aExtRecordNo; count++ )
       
  1873         {
       
  1874         iExtRecordArrayToBeWrite.Insert( 0, count );
       
  1875         }
       
  1876 }
       
  1877 
       
  1878 
       
  1879 
       
  1880 // ---------------------------------------------------------------------------
       
  1881 // void CMmPhoneBookOperationWrite::CheckForExtRecordNum
       
  1882 // Check for EXT number of records for new Entry is sufficiet or not
       
  1883 // ---------------------------------------------------------------------------
       
  1884 //
       
  1885 TInt CMmPhoneBookOperationWrite::CheckForExtRecordNum( 
       
  1886         TPBEntry entry, 
       
  1887         TUint8 aTransId )
       
  1888     {
       
  1889 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::CheckForExtRecordNum");
       
  1890 OstTrace0( TRACE_NORMAL, CMMPHONEBOOKOPERATIONWRITE_CHECKFOREXTRECORDNUM, "CMmPhoneBookOperationWrite::CheckForExtRecordNum" );
       
  1891 
       
  1892     TInt ret( KErrNone );
       
  1893     
       
  1894     // Update old record number which needs to be 
       
  1895     //updated by new entry
       
  1896     if( entry.PBEntryExtRecord.Count() > 0 )
       
  1897         {
       
  1898         for( TInt i=0; 
       
  1899              i < entry.PBEntryExtRecord.Count();
       
  1900              i++ )
       
  1901             {
       
  1902             // Append record number to be write from 
       
  1903             //old Entry
       
  1904             iExtRecordArrayToBeWrite.Append( 
       
  1905                     entry.PBEntryExtRecord[i] );
       
  1906             iExtRecordArrayToBeDelete.Append( 
       
  1907                     entry.PBEntryExtRecord[i] );
       
  1908             }
       
  1909         }
       
  1910     // Search for more free records
       
  1911     iCurrentWritePhase = EPBWritePhase_Search_Ext_Entry;
       
  1912     
       
  1913     // Send request to read first entry in Ext
       
  1914     iExtRecordNo = 1 ;
       
  1915     ret = UiccPbReqWriteReadExt(
       
  1916             iExtRecordNo,
       
  1917             aTransId);
       
  1918 
       
  1919     return ret;
       
  1920     }
       
  1921 
       
  1922 
       
  1923 
       
  1924 // ---------------------------------------------------------------------------
       
  1925 // void CMmPhoneBookOperationWrite::ContinueWriteEntry
       
  1926 // Check for records to deleted else start writing new entry
       
  1927 // ---------------------------------------------------------------------------
       
  1928 //
       
  1929 TInt CMmPhoneBookOperationWrite::ContinueWriteEntry( 
       
  1930         TUint8 aExtRecNo, 
       
  1931         TPBEntry entry, 
       
  1932         TUint8 aTransId,
       
  1933         CPhoneBookStoreEntry& aDataToWrite )
       
  1934     {
       
  1935 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::ContinueWriteEntry");
       
  1936 OstTrace0( TRACE_NORMAL, CMMPHONEBOOKOPERATIONWRITE_CONTINUEWRITEENTRY, "CMmPhoneBookOperationWrite::ContinueWriteEntry" );
       
  1937 
       
  1938     TInt ret( KErrNone );
       
  1939     
       
  1940     // Check of both records are 0
       
  1941     if( ( aExtRecNo == 0 ) && 
       
  1942         ( entry.PBEntryExtRecord.Count() == 0 ))
       
  1943         {
       
  1944         // Start Writing Entry
       
  1945         iCurrentWritePhase = EPBWritePhase_Write_Entry;
       
  1946         ret = UiccPBReqWriteEntry( 
       
  1947                 iPhoneBookEntry->iLocation,
       
  1948                 aTransId,
       
  1949                 aDataToWrite );
       
  1950         }
       
  1951     else
       
  1952         {
       
  1953         // Start copy Ext record number to be write array
       
  1954         for( TInt i=0; i <  aExtRecNo; i++ )
       
  1955             {
       
  1956             // Append record number to be write from old
       
  1957             //Entry
       
  1958             iExtRecordArrayToBeWrite.Append(
       
  1959                     entry.PBEntryExtRecord[i]);
       
  1960             iExtRecordArrayToBeDelete.Append(
       
  1961                     entry.PBEntryExtRecord[i]);
       
  1962             }
       
  1963         // Update records needs to be deleted
       
  1964         // From old Entry
       
  1965         for( TInt i=aExtRecNo;
       
  1966              i < entry.PBEntryExtRecord.Count();
       
  1967              i++ )
       
  1968             {
       
  1969             // Append record number to be deleted from 
       
  1970             //old Entry
       
  1971             iExtRecordArrayToBeDelete.Append( 
       
  1972                     entry.PBEntryExtRecord[i]);
       
  1973             }
       
  1974         // Start Deleting the EXT Records
       
  1975         iCurrentWritePhase = EPBWritePhase_Write_Ext_Entry;
       
  1976         iExtDeleteOperation = ETrue;
       
  1977         TUint8 index ( iExtRecordArrayToBeDelete[0] );
       
  1978         // Send request to Write main Entry
       
  1979         ret = UiccPbReqWriteExtDelete(
       
  1980                 index,
       
  1981                 aTransId );
       
  1982         }
       
  1983 
       
  1984     return ret;
       
  1985     }
       
  1986 
       
  1987 // ---------------------------------------------------------------------------
       
  1988 // void CMmPhoneBookOperationWrite::GetExtRecNum
       
  1989 // Get the total number of Ext records needed for new entry
       
  1990 // ---------------------------------------------------------------------------
       
  1991 //
       
  1992 void CMmPhoneBookOperationWrite::CopyData( const TDesC16& aSource, TDes16& aTarget )
       
  1993 {
       
  1994 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::CopyData");
       
  1995 OstTrace0( TRACE_NORMAL, CMMPHONEBOOKOPERATIONWRITE_COPYDATA, "CMmPhoneBookOperationWrite::CopyData" );
       
  1996 
       
  1997 TInt temp ( aSource.Length() );
       
  1998 TInt temp1( aTarget.MaxLength() );
       
  1999     if( aSource.Length() <= aTarget.MaxLength() )
       
  2000         {
       
  2001         // Start Copy Data
       
  2002         for( TInt count(0); count < aSource.Length(); count++ )
       
  2003             {
       
  2004             aTarget.Append( aSource[count] );
       
  2005             }
       
  2006         }
       
  2007 }
       
  2008 
  1850 // End of file
  2009 // End of file