adaptationlayer/tsy/nokiatsy_dll/src/cmmphonebookoperationwrite.cpp
changeset 5 8ccc39f9d787
child 7 fa67e03b87df
equal deleted inserted replaced
4:510c70acdbf6 5:8ccc39f9d787
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 * 
       
    12 * Contributors:
       
    13 * 
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //  INCLUDE FILES
       
    20 #include <etelmm.h>
       
    21 #include <tisi.h>
       
    22 #include <pn_const.h>
       
    23 #include <ctsy/serviceapi/mmtsy_ipcdefs.h>
       
    24 #include <etelmmerr.h>      // For error code
       
    25 #include <ctsy/serviceapi/gsmerror.h>       // For error code
       
    26 #include "tsylogger.h"
       
    27 #include "cmmmessagerouter.h"
       
    28 #include "cmmphonebookoperationwrite.h"
       
    29 #include "cmmphonebookalphastring.h"
       
    30 #include "osttracedefinitions.h"
       
    31 #ifdef OST_TRACE_COMPILER_IN_USE
       
    32 #include "cmmphonebookoperationwritetraces.h"
       
    33 #endif
       
    34 
       
    35 // EXTERNAL DATA STRUCTURES
       
    36     // None
       
    37 
       
    38 // EXTERNAL FUNCTION PROTOTYPES
       
    39     // None
       
    40 
       
    41 // CONSTANTS
       
    42 
       
    43 // MACROS
       
    44     // None
       
    45 
       
    46 // LOCAL CONSTANTS AND MACROS
       
    47     // None
       
    48 
       
    49 // MODULE DATA STRUCTURES
       
    50     // None
       
    51 
       
    52 // LOCAL FUNCTION PROTOTYPES
       
    53     // None
       
    54 
       
    55 // ==================== LOCAL FUNCTIONS =====================================
       
    56     // None
       
    57 
       
    58 
       
    59 // ================= MEMBER FUNCTIONS =======================================
       
    60 
       
    61 // ---------------------------------------------------------------------------
       
    62 // CMmPhoneBookOperationWrite::CMmPhoneBookOperationWrite
       
    63 // C++ default constructor can NOT contain any code, that
       
    64 // might leave.
       
    65 // ---------------------------------------------------------------------------
       
    66 //
       
    67 CMmPhoneBookOperationWrite::CMmPhoneBookOperationWrite()
       
    68     {
       
    69 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::\
       
    70         CMmPhoneBookOperationWrite");
       
    71 OstTrace0( TRACE_NORMAL, CMMPHONEBOOKOPERATIONWRITE_CMMPHONEBOOKOPERATIONWRITE, "CMmPhoneBookOperationWrite::CMmPhoneBookOperationWrite" );
       
    72     iPhoneBookEntry = NULL;
       
    73     }
       
    74 
       
    75 // ---------------------------------------------------------------------------
       
    76 // CMmPhoneBookOperationWrite::~CMmPhoneBookOperationWrite
       
    77 // C++ destructor.
       
    78 // ---------------------------------------------------------------------------
       
    79 //
       
    80 CMmPhoneBookOperationWrite::~CMmPhoneBookOperationWrite()
       
    81     {
       
    82 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::\
       
    83         ~CMmPhoneBookOperationWrite");
       
    84 OstTrace0( TRACE_NORMAL, DUP1_CMMPHONEBOOKOPERATIONWRITE_CMMPHONEBOOKOPERATIONWRITE, "CMmPhoneBookOperationWrite::~CMmPhoneBookOperationWrite" );
       
    85     }
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 // CMmPhoneBookOperationWrite::NewL
       
    89 // Creates a new CMmPhonebookOperationWrite object instance.
       
    90 // Two-phased constructor.
       
    91 // ---------------------------------------------------------------------------
       
    92 
       
    93 CMmPhoneBookOperationWrite* CMmPhoneBookOperationWrite::NewL(
       
    94     CMmPhoneBookStoreMessHandler* aMmPhoneBookStoreMessHandler,
       
    95     const CMmDataPackage* aDataPackage ) // Data
       
    96     {
       
    97 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::NewL");
       
    98 OstTrace0( TRACE_NORMAL, CMMPHONEBOOKOPERATIONWRITE_NEWL, "CMmPhoneBookOperationWrite::NewL" );
       
    99 
       
   100     TName phonebookTypeName;
       
   101 
       
   102     CMmPhoneBookOperationWrite* mmPhoneBookOperationWrite =
       
   103         new( ELeave ) CMmPhoneBookOperationWrite();
       
   104 
       
   105     const CPhoneBookDataPackage* phoneBookData =
       
   106         static_cast<const CPhoneBookDataPackage*>( aDataPackage );
       
   107 
       
   108     phoneBookData->GetPhoneBookName( phonebookTypeName );
       
   109     // Store phonebook name 
       
   110     mmPhoneBookOperationWrite->iPhoneBookTypeName = phonebookTypeName;
       
   111 
       
   112     mmPhoneBookOperationWrite->iMmPhoneBookStoreMessHandler =
       
   113         aMmPhoneBookStoreMessHandler;
       
   114 
       
   115     return mmPhoneBookOperationWrite;
       
   116     }
       
   117 
       
   118 // ---------------------------------------------------------------------------
       
   119 // CMmPhoneBookOperationWrite::ConstructL
       
   120 // Initialises object attributes.
       
   121 // ---------------------------------------------------------------------------
       
   122 //
       
   123 void CMmPhoneBookOperationWrite::ConstructL()
       
   124     {
       
   125 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::ConstructL");
       
   126 OstTrace0( TRACE_NORMAL, CMMPHONEBOOKOPERATIONWRITE_CONSTRUCTL, "CMmPhoneBookOperationWrite::ConstructL" );
       
   127     }
       
   128 
       
   129 
       
   130 // ---------------------------------------------------------------------------
       
   131 // TInt CMmPhoneBookOperationWrite::CreateReq
       
   132 // Separate request
       
   133 // ---------------------------------------------------------------------------
       
   134 //
       
   135 TInt CMmPhoneBookOperationWrite::UICCCreateReq
       
   136         (
       
   137         TInt aIpc,
       
   138         const CMmDataPackage* aDataPackage,
       
   139         TUint8 aTransId
       
   140         )
       
   141     {
       
   142 TFLOGSTRING2("TSY: CMmPhoneBookOperationWrite::UICCCreateReq Ipc: %d", aIpc);
       
   143 OstTraceExt1( TRACE_NORMAL, DUP1_CMMPHONEBOOKOPERATIONWRITE_UICCCREATEREQ, "CMmPhoneBookOperationWrite::UICCCreateReq;aIpc=%hd", aIpc );
       
   144     
       
   145     TInt ret (KErrNone);
       
   146     const CPhoneBookDataPackage* phoneBookData =
       
   147         static_cast<const CPhoneBookDataPackage*>( aDataPackage );
       
   148 
       
   149         if( aIpc == EMmTsyPhoneBookStoreWriteIPC )
       
   150             {
       
   151                 TInt16 index( 0 );
       
   152                 // Store Entry to the operation which needs to be write in SIM
       
   153                 phoneBookData->UnPackData( index, iPhoneBookEntry );
       
   154 
       
   155                 if ( iPhoneBookEntry )
       
   156                     {
       
   157                     // get the index Number needs to be write
       
   158                     iPhoneBookEntry->iLocation = static_cast<TUint16>( index );
       
   159                     
       
   160                     // Convert Phone Book name to file id
       
   161                     TUint16 fileIdExt ( UICC_ILLEGAL_FILE_ID );
       
   162                     TUint16 pbFileId = ConvertToPBfileId( iPhoneBookTypeName, fileIdExt );
       
   163                     TUint8 pbArrayIndex ( ConvertToConfArrayIndex( pbFileId ) );
       
   164 
       
   165                     if( PB_MBDN_FID == pbFileId )
       
   166                         {
       
   167                         // For MBDN PhoneBook first read MBI file 
       
   168                         // Check if the mailbox inidcation type is correct
       
   169                         if( index <= iMmPhoneBookStoreMessHandler->
       
   170                                 iPBStoreConf[pbArrayIndex].iMbiRecLen )
       
   171                             {
       
   172                             iCurrentWritePhase = EPBWritePhase_Read_MBI_profile;
       
   173                             // read MBDN record number from MBI first record Profile number
       
   174                             ret = UiccPbReqReadMBI( index, aTransId );
       
   175                             }
       
   176                         else
       
   177                             {
       
   178                             ret = KErrArgument;
       
   179                             }
       
   180                         }
       
   181                     else
       
   182                         {
       
   183                         ret = UiccPbReqWriteL( aTransId, index, *iPhoneBookEntry );
       
   184                         }
       
   185                     }
       
   186             }
       
   187         else
       
   188             {
       
   189 TFLOGSTRING2("TSY: CMmPhoneBookOperationWrite::UICCCreateReq Unknown Ipc: %d", aIpc);
       
   190 OstTraceExt1( TRACE_NORMAL, DUP2_CMMPHONEBOOKOPERATIONWRITE_UICCCREATEREQ, "CMmPhoneBookOperationWrite::UICCCreateReq;Unknown aIpc =%hd", aIpc );
       
   191             }
       
   192     return ret;
       
   193     }
       
   194 
       
   195 
       
   196 // ---------------------------------------------------------------------------
       
   197 // CMmPhoneBookOperationWrite::UiccPbReqWriteL
       
   198 // Constructs an ISI-message to read entry from SIM
       
   199 // ---------------------------------------------------------------------------
       
   200 //
       
   201 TInt CMmPhoneBookOperationWrite::UiccPbReqWriteL(
       
   202         TUint8 aTransId,
       
   203         TInt16 aIndex,
       
   204         CPhoneBookStoreEntry& aDataToWrite )
       
   205     {
       
   206 TFLOGSTRING3("TSY: CMmPhoneBookOperationWrite::SimPbReqWriteL, aTransId:%d,index:%d", aTransId,  aIndex);
       
   207 OstTraceExt2( TRACE_NORMAL, CMMPHONEBOOKOPERATIONWRITE_UICCPBREQWRITEL, "CMmPhoneBookOperationWrite::UiccPbReqWriteL;aTransId=%hhu;aIndex=%hd", aTransId, aIndex );
       
   208     
       
   209     TInt ret( KErrNone );
       
   210     // Check for no of EXT records required for Writing this Entry
       
   211     TUint8 extRecordNo ( 0 ); 
       
   212 
       
   213     if( UICC_EF_FDN_NO_EXT_NUM_LEN < iPhoneBookEntry->iNumber->Length() )
       
   214         {
       
   215         extRecordNo++;
       
   216         TInt extDataLength = iPhoneBookEntry->iNumber->Length() - 
       
   217                              UICC_EF_FDN_NO_EXT_NUM_LEN;
       
   218         while ( extDataLength > UICC_EF_EXT_REC_NUM_LEN)
       
   219             {
       
   220             extRecordNo++;
       
   221             extDataLength = extDataLength - UICC_EF_EXT_REC_NUM_LEN;
       
   222             }
       
   223         }
       
   224         
       
   225     // reserve Space for ext record no
       
   226     iExtRecordArrayToBeWrite.ReserveL( extRecordNo );
       
   227     // File reserved memory with 0
       
   228     for( TInt count = 0; count < extRecordNo; count++ )
       
   229         {
       
   230         iExtRecordArrayToBeWrite.Insert( 0 , count );
       
   231         }
       
   232 
       
   233     // Convert Phone Book name to file id
       
   234     TUint16 fileIdExt ( UICC_ILLEGAL_FILE_ID );
       
   235     TUint16 pbFileId = ConvertToPBfileId( iPhoneBookTypeName, fileIdExt );
       
   236 
       
   237     if( UICC_ILLEGAL_FILE_ID != pbFileId )
       
   238         {
       
   239         TUint8 pbArrayIndex ( ConvertToConfArrayIndex( pbFileId ) );
       
   240 
       
   241         // Check if the index To read is valid
       
   242         if(  aIndex <= iMmPhoneBookStoreMessHandler->
       
   243                 iPBStoreConf[pbArrayIndex].iNoOfRecords )
       
   244             {
       
   245             // if Entry present in list Store it locally
       
   246             TPBEntry entry;
       
   247             if( 0 < aIndex )
       
   248                 {
       
   249                 // Check for index present the store list
       
   250                 if( iMmPhoneBookStoreMessHandler->IndexCheckInPBList(
       
   251                         aIndex,
       
   252                         pbArrayIndex,
       
   253                         entry ) )
       
   254                     {
       
   255                     // Check if Entry is present or not 
       
   256                     if( entry.iEntryPresent )
       
   257                         {
       
   258                         // Check if no if ext records are sufficient from previous Entry
       
   259                         if( extRecordNo  > entry.PBEntryExtRecord.Count() )
       
   260                             {
       
   261                             // Update old record number which needs to be updated by new entry
       
   262                             if( entry.PBEntryExtRecord.Count() > 0 )
       
   263                                 {
       
   264                                 for( TInt i=0; i <  entry.PBEntryExtRecord.Count(); i++ )
       
   265                                     {
       
   266                                     // Append record number to be write from old Entry
       
   267                                     iExtRecordArrayToBeWrite.Append( 
       
   268                                             entry.PBEntryExtRecord[i] );
       
   269                                     iExtRecordArrayToBeDelete.Append( 
       
   270                                             entry.PBEntryExtRecord[i] );
       
   271                                     }
       
   272                                 }
       
   273                             // Search for more free records
       
   274                             iCurrentWritePhase = EPBWritePhase_Search_Ext_Entry;
       
   275                             
       
   276                             // Send request to read first entry in Ext
       
   277                             iExtRecordNo = 1 ;
       
   278                             ret = UiccPbReqWriteReadExt(
       
   279                                     pbFileId,
       
   280                                     fileIdExt,
       
   281                                     iExtRecordNo,
       
   282                                     aTransId);
       
   283                             }
       
   284                         else  // when reocrds to be delete and write are 0 or to be write record less
       
   285                             {
       
   286                             // Check of both records are 0
       
   287                             if( ( extRecordNo == 0 ) && 
       
   288                                     ( entry.PBEntryExtRecord.Count() == 0 ))
       
   289                                 {
       
   290                                 // Start Writing Entry
       
   291                                 iCurrentWritePhase = EPBWritePhase_Write_Entry;
       
   292                                 ret = UiccPBReqWriteEntry( 
       
   293                                         pbFileId,
       
   294                                         aIndex,
       
   295                                         aTransId,
       
   296                                         aDataToWrite );
       
   297                                 }
       
   298                             else
       
   299                                 {
       
   300                                 // Start copy Ext record number to be write array
       
   301                                 for( TInt i=0; i <  extRecordNo; i++ )
       
   302                                     {
       
   303                                     // Append record number to be write from old Entry
       
   304                                     iExtRecordArrayToBeWrite.Append(
       
   305                                             entry.PBEntryExtRecord[i]);
       
   306                                     iExtRecordArrayToBeDelete.Append(
       
   307                                             entry.PBEntryExtRecord[i]);
       
   308                                     }
       
   309                                 // Update records needs to be deleted
       
   310                                 // From old Entry
       
   311                                 for( TInt i=extRecordNo; i <  entry.PBEntryExtRecord.Count(); i++ )
       
   312                                     {
       
   313                                     // Append record number to be deleted from old Entry
       
   314                                     iExtRecordArrayToBeDelete.Append( 
       
   315                                             entry.PBEntryExtRecord[i]);
       
   316                                     }
       
   317                                 // Start Deleting the EXT Records
       
   318                                 iCurrentWritePhase = EPBWritePhase_Write_Ext_Entry;
       
   319                                 iExtDeleteOperation = ETrue;
       
   320                                 TUint8 index ( iExtRecordArrayToBeDelete[0] );
       
   321                                 // Send request to Write main Entry
       
   322                                 ret = UiccPbReqWriteExtDelete(
       
   323                                         pbFileId,
       
   324                                         fileIdExt,
       
   325                                         index,
       
   326                                         aTransId );
       
   327                                 }
       
   328                             }
       
   329                         }
       
   330                     else
       
   331                         {
       
   332                         // If entry not present
       
   333                         // Check if EXT Records are needed for Entry to be written
       
   334                         if( 0 < extRecordNo )
       
   335                             {
       
   336                             // Search for free ext records 
       
   337                             iCurrentWritePhase = EPBWritePhase_Search_Ext_Entry;
       
   338                             
       
   339                             // Send request To read First EXT record
       
   340                             iExtRecordNo = 1;
       
   341                             ret = UiccPbReqWriteReadExt(
       
   342                                     pbFileId,
       
   343                                     fileIdExt,
       
   344                                     iExtRecordNo,
       
   345                                     aTransId );
       
   346                             }
       
   347                         else
       
   348                             {
       
   349                             // Start Writting Entry
       
   350                             iCurrentWritePhase = EPBWritePhase_Write_Entry;
       
   351                             TUint8 indexToWrite = iPhoneBookEntry->iLocation;
       
   352                             ret = UiccPBReqWriteEntry(
       
   353                                     pbFileId,
       
   354                                     indexToWrite,
       
   355                                     aTransId,
       
   356                                     aDataToWrite );
       
   357                             }
       
   358                         }
       
   359                     }   // end of if Entry is present in the list
       
   360                 else
       
   361                     {
       
   362                     // First Read that Entry from SIM and then delete that entry with EXT records if there are Any
       
   363                     iCurrentWritePhase = EPBWritePhase_Read_Entry;
       
   364                     ret = UiccPbReqWriteRead( pbFileId, aIndex, aTransId );
       
   365                     
       
   366                     // read Main entry with given index number
       
   367                     }
       
   368                 }
       
   369             else
       
   370                 {
       
   371                 // Start Serching For first free Entry in the Stored list
       
   372                 TInt index = iMmPhoneBookStoreMessHandler->
       
   373                 EmptyEntryCheckInPBList( pbArrayIndex );
       
   374                 if( 0 < index )
       
   375                     {
       
   376                     //Check if EXT records Are needed or not
       
   377                     if( 0 < extRecordNo )
       
   378                         {
       
   379                         // Start Serching for EXT records
       
   380                         // Search for free ext records 
       
   381                         iCurrentWritePhase = EPBWritePhase_Search_Ext_Entry;
       
   382                             
       
   383                         // Send request To read First EXT record
       
   384                         iExtRecordNo = 1;
       
   385                         ret = UiccPbReqWriteReadExt(
       
   386                                 pbFileId,
       
   387                                 fileIdExt,
       
   388                                 iExtRecordNo,
       
   389                                 aTransId );
       
   390                         }
       
   391                     else
       
   392                         {
       
   393                         // Start Writing Entry on given Index
       
   394                         // Start Writting Entry
       
   395                         iCurrentWritePhase = EPBWritePhase_Write_Entry;
       
   396                         ret = UiccPBReqWriteEntry(
       
   397                                 pbFileId,
       
   398                                 index,
       
   399                                 aTransId,
       
   400                                 aDataToWrite );
       
   401                         }
       
   402                     }
       
   403                 else
       
   404                     {
       
   405                     // Start searching for first free Entry from SIM
       
   406                     iCurrentWritePhase = EPBWritePhase_Read_Entry;
       
   407                     iLocationSearch = ETrue;
       
   408                     iEntryToWrite = 1;
       
   409                     ret = UiccPbReqWriteRead(
       
   410                             pbFileId,
       
   411                             iEntryToWrite,
       
   412                             aTransId );
       
   413                     }
       
   414                 }
       
   415             }
       
   416         else
       
   417             {
       
   418             ret = KErrArgument;
       
   419             }            
       
   420         }
       
   421     else
       
   422         {
       
   423         ret = KErrArgument;
       
   424         }
       
   425     return ret;
       
   426     }
       
   427 
       
   428 
       
   429 
       
   430 // ---------------------------------------------------------------------------
       
   431 // CMmPhoneBookOperationWrite::UiccPBReqWriteEntry
       
   432 // Constructs an ISI-message to Write main Entry data
       
   433 // ---------------------------------------------------------------------------
       
   434 //
       
   435 TInt CMmPhoneBookOperationWrite::UiccPBReqWriteEntry( TUint16 aFileId, TUint8 aIndex, TUint8 aTransId, CPhoneBookStoreEntry& aDataToWrite )
       
   436     {
       
   437 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::UiccPBReqWriteEntry");
       
   438 OstTrace0( TRACE_NORMAL, CMMPHONEBOOKOPERATIONWRITE_UICCPBREQWRITEENTRY, "CMmPhoneBookOperationWrite::UiccPBReqWriteEntry" );
       
   439 
       
   440     TInt ret( KErrNone );
       
   441     
       
   442     TUiccWriteLinearFixed cmdParams;
       
   443     cmdParams.messHandlerPtr  = static_cast<MUiccOperationBase*> 
       
   444                                ( iMmPhoneBookStoreMessHandler );
       
   445     cmdParams.filePath.Append( static_cast<TUint8>( MF_FILE >> 8 ));
       
   446     cmdParams.filePath.Append( static_cast<TUint8>( MF_FILE ));
       
   447     cmdParams.filePath.Append( APPL_FILE_ID>>8);
       
   448     cmdParams.filePath.Append( APPL_FILE_ID);
       
   449     cmdParams.filePath.Append( static_cast<TUint8>( DF_PHONEBOOK >> 8 ));
       
   450     cmdParams.filePath.Append( static_cast<TUint8>( DF_PHONEBOOK ));
       
   451     cmdParams.serviceType = UICC_APPL_UPDATE_LINEAR_FIXED;
       
   452     cmdParams.fileId = aFileId;
       
   453     cmdParams.trId = static_cast<TUiccTrId>( aTransId );
       
   454     // Check for valid record number
       
   455     TUint8 arrayIndex ( ConvertToConfArrayIndex( aFileId ) );
       
   456     if( aIndex <= iMmPhoneBookStoreMessHandler->iPBStoreConf[arrayIndex].iNoOfRecords )
       
   457         {
       
   458         cmdParams.record = aIndex;
       
   459         }
       
   460     else
       
   461         {
       
   462         ret = KErrArgument;
       
   463         }
       
   464     
       
   465     
       
   466     TBuf8<241>nameBuf;
       
   467     
       
   468     TPtr16 ptrToName = aDataToWrite.iText->Des();
       
   469     // Convert the Entry Name from ASCII format to UCS2
       
   470     CMmStaticUtility::ConvertUcs2ToGsmUcs2Data( ptrToName, nameBuf );
       
   471     if( nameBuf.Length() < iMmPhoneBookStoreMessHandler->
       
   472                            iPBStoreConf[ arrayIndex ].iAlphaStringlength )
       
   473         {
       
   474         // Fill rest of the Bytes 
       
   475         for( TInt count = nameBuf.Length(); count < ( iMmPhoneBookStoreMessHandler->
       
   476                       iPBStoreConf[ arrayIndex ].iAlphaStringlength ); count++ )
       
   477             {
       
   478             nameBuf.Append( KTagUnusedbyte );
       
   479             }
       
   480         }
       
   481     TBuf8<300>numberBuf;
       
   482     TPtr16 ptrToNumber = aDataToWrite.iNumber->Des();
       
   483     iMmPhoneBookStoreMessHandler->ConvertToBCDFromUCS2(
       
   484                                   ptrToNumber,
       
   485                                   numberBuf,
       
   486                                   aFileId );
       
   487     
       
   488     // Store number length
       
   489     TUint8 numLength ( numberBuf.Length() );
       
   490     
       
   491     if( numberBuf.Length() < UICC_EF_EXT_REC_NUM_LEN )
       
   492         {
       
   493         // fill  rest of the bytes
       
   494         for( TInt count = numberBuf.Length(); count < UICC_EF_EXT_REC_NUM_LEN; count++)
       
   495             {
       
   496             numberBuf.Append( KTagUnusedbyte );
       
   497             }
       
   498         }
       
   499     
       
   500     TBuf8<200>fileDataWrite;
       
   501     fileDataWrite.Append( nameBuf.Mid( 0, iMmPhoneBookStoreMessHandler->
       
   502                           iPBStoreConf[ arrayIndex ].iAlphaStringlength ) );
       
   503     fileDataWrite.Append( numLength );
       
   504     fileDataWrite.Append( numberBuf.Mid( 0, UICC_EF_EXT_REC_NUM_LEN ) );
       
   505     // Append Capability configuration byte as not used
       
   506     fileDataWrite.Append( KTagUnusedbyte );
       
   507 
       
   508     // Chekc for EXT Data is present or not
       
   509     if( 0 < iExtRecordArrayToBeWrite.Count() )
       
   510         {
       
   511         // Append Extension recorNo from iExtRecordArray to be write
       
   512         fileDataWrite.Append( iExtRecordArrayToBeWrite[0] );
       
   513         }
       
   514     else
       
   515         {
       
   516         // there is no EXT record
       
   517         fileDataWrite.Append( KTagUnusedbyte );
       
   518         }
       
   519     
       
   520     // Append 
       
   521     cmdParams.fileData.Append( fileDataWrite );
       
   522     
       
   523     if( KErrNone == ret )
       
   524         {
       
   525         ret = iMmPhoneBookStoreMessHandler->UiccMessHandler()->
       
   526             CreateUiccApplCmdReq( cmdParams );
       
   527 TFLOGSTRING2("TSY: CreateUiccApplCmdReq returns %d", ret);
       
   528 OstTraceExt1( TRACE_NORMAL, DUP1_CMMPHONEBOOKOPERATIONWRITE_UICCPBREQWRITEENTRY, "CMmPhoneBookOperationWrite::UiccPBReqWriteEntry;ret=%hd", ret );
       
   529         
       
   530         }
       
   531 
       
   532     return ret;
       
   533     }
       
   534 
       
   535 
       
   536 // ---------------------------------------------------------------------------
       
   537 // CMmPhoneBookOperationWrite::UiccPbReqWriteExt
       
   538 // Constructs an ISI-message to Write EXT Data 
       
   539 // ---------------------------------------------------------------------------
       
   540 //
       
   541 
       
   542 TInt CMmPhoneBookOperationWrite::UiccPbReqWriteExt(
       
   543         TUint8 aTransId,
       
   544         TUint8 aIndex,
       
   545         TUint16 aFileId,
       
   546         TUint16 aFileIdExt,
       
   547         CPhoneBookStoreEntry& aDataToWrite )
       
   548     {
       
   549 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::UiccPbReqWriteExt");
       
   550 OstTrace0( TRACE_NORMAL, CMMPHONEBOOKOPERATIONWRITE_UICCPBWRITEEXT, "CMmPhoneBookOperationWrite::UiccPbReqWriteExt" );
       
   551     
       
   552     TInt ret( KErrNone );
       
   553     
       
   554     TUiccWriteLinearFixed cmdParams;
       
   555     cmdParams.messHandlerPtr  = static_cast<MUiccOperationBase*> 
       
   556                                 ( iMmPhoneBookStoreMessHandler );
       
   557     cmdParams.filePath.Append( static_cast<TUint8>( MF_FILE >> 8 ));
       
   558     cmdParams.filePath.Append( static_cast<TUint8>( MF_FILE ));
       
   559     cmdParams.filePath.Append( APPL_FILE_ID>>8);
       
   560     cmdParams.filePath.Append( APPL_FILE_ID);
       
   561     cmdParams.filePath.Append( static_cast<TUint8>( DF_PHONEBOOK >> 8 ));
       
   562     cmdParams.filePath.Append( static_cast<TUint8>( DF_PHONEBOOK ));
       
   563     cmdParams.fileId = aFileIdExt;
       
   564     cmdParams.serviceType = UICC_APPL_UPDATE_LINEAR_FIXED;
       
   565     cmdParams.trId = static_cast<TUiccTrId>( aTransId );
       
   566     
       
   567     // File Data
       
   568     TBuf8<255>numBuf;
       
   569     TBuf8<13>extFileData;
       
   570     TPtr16 ptrToNumber = aDataToWrite.iNumber->Des();
       
   571 
       
   572     iMmPhoneBookStoreMessHandler->ConvertToBCDFromUCS2(
       
   573                                   ptrToNumber,
       
   574                                   numBuf,
       
   575                                   aFileId );
       
   576     
       
   577         if( numBuf.Length() > ( 10 + ( iExtRecordWritten* 11 ) ))
       
   578             {
       
   579             // form EXt file Data
       
   580             // Append Record type
       
   581             extFileData.Append( 0x02 );
       
   582             // Append Data
       
   583             extFileData.Append( numBuf.Mid( 11 + ( iExtRecordWritten* 11 ), 
       
   584                      ( numBuf.Length() - ( 11 + ( iExtRecordWritten* 11 ) ) ) ) );
       
   585             // Check if Data ids less than 11
       
   586             if( extFileData.Length() < 12 )
       
   587                 {
       
   588                 extFileData.AppendFill( 0xFF, ( 12 - extFileData.Length() ) );
       
   589                 }
       
   590             // Check if there is more Ext Record to be write
       
   591             if( iExtRecordArrayToBeWrite.Count() > 0 )
       
   592                 {
       
   593                 // Append record Number
       
   594                 extFileData.Append( iExtRecordArrayToBeWrite[0] );
       
   595                 }
       
   596             else
       
   597                 {
       
   598                 extFileData.Append( 0xFF );
       
   599                 }
       
   600             }
       
   601         else
       
   602             {
       
   603             // Append Record type
       
   604             extFileData.Append( 0x02 );
       
   605             // Append Data
       
   606             extFileData.Append( numBuf.Mid( 11 + ( iExtRecordWritten* 11 ), 11 ) );
       
   607             
       
   608             // Check if there is more Ext Record to be write
       
   609             if( iExtRecordArrayToBeWrite.Count() > 0 )
       
   610                 {
       
   611                 // Append record Number
       
   612                 extFileData.Append( iExtRecordArrayToBeWrite[0] );
       
   613                 }
       
   614             else
       
   615                 {
       
   616                 extFileData.Append( 0xFF );
       
   617                 }
       
   618             }
       
   619         
       
   620         cmdParams.fileData.Append( extFileData );
       
   621 
       
   622     TUint8 arrayIndex ( ConvertToConfArrayIndex( aFileId ));
       
   623     if( aIndex <= iMmPhoneBookStoreMessHandler->iPBStoreConf[arrayIndex].iExtNoOfRec )
       
   624         {
       
   625         cmdParams.record = aIndex;
       
   626         }
       
   627     else
       
   628         {
       
   629         ret = KErrGeneral;
       
   630         }
       
   631     
       
   632     if( KErrNone == ret )
       
   633         {
       
   634         ret = iMmPhoneBookStoreMessHandler->UiccMessHandler()->
       
   635             CreateUiccApplCmdReq( cmdParams );
       
   636 TFLOGSTRING2("TSY: CreateUiccApplCmdReq returns %d", ret);
       
   637 OstTraceExt1( TRACE_NORMAL, CMMPHONEBOOKOPERATIONWRITE_UICCPBREQWRITEEXT, "CMmPhoneBookOperationWrite::UiccPbReqWriteExt;ret=%hd", ret );
       
   638         }
       
   639     
       
   640     return ret;
       
   641     }
       
   642 
       
   643 
       
   644 
       
   645 
       
   646 
       
   647 // ---------------------------------------------------------------------------
       
   648 // CMmPhoneBookOperationWrite::UiccPbReqWriteReadExt
       
   649 // Constructs an ISI-message to Read The existing Entry EXT record
       
   650 // ---------------------------------------------------------------------------
       
   651 //
       
   652 TInt CMmPhoneBookOperationWrite::UiccPbReqWriteReadExt(
       
   653              TUint16 aFileId,
       
   654              TUint16 aFileIdExt,
       
   655              TUint8 aIndex,
       
   656              TUint8 aTransId)
       
   657     {
       
   658 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::UiccPbReqWriteEXTDelete");
       
   659 OstTrace0( TRACE_NORMAL, CMMPHONEBOOKOPERATIONWRITE_UICCPBREQWRITEREADEXT, "CMmPhoneBookOperationWrite::UiccPbReqWriteReadExt" );
       
   660     
       
   661     TInt ret ( KErrNone );
       
   662     
       
   663     TUiccReadLinearFixed cmdParams;
       
   664     cmdParams.messHandlerPtr  = static_cast<MUiccOperationBase*> 
       
   665                                ( iMmPhoneBookStoreMessHandler );
       
   666     cmdParams.filePath.Append( static_cast<TUint8>( MF_FILE >> 8 ));
       
   667     cmdParams.filePath.Append( static_cast<TUint8>( MF_FILE ));
       
   668     cmdParams.filePath.Append( APPL_FILE_ID>>8);
       
   669     cmdParams.filePath.Append( APPL_FILE_ID);
       
   670     cmdParams.filePath.Append( static_cast<TUint8>( DF_PHONEBOOK >> 8 ));
       
   671     cmdParams.filePath.Append( static_cast<TUint8>( DF_PHONEBOOK ));
       
   672     
       
   673     // Append transaction id 
       
   674     cmdParams.trId = static_cast<TUiccTrId>( aTransId );
       
   675     
       
   676     // Append File id
       
   677     cmdParams.fileId = aFileIdExt;
       
   678     
       
   679     // Append serviceType
       
   680     cmdParams.serviceType = UICC_APPL_READ_LINEAR_FIXED;
       
   681     
       
   682     
       
   683     TUint8 arrayIndex( ConvertToConfArrayIndex( aFileId ) );
       
   684     // Check for the valid index neds to be read
       
   685     if( aIndex <= iMmPhoneBookStoreMessHandler->iPBStoreConf[arrayIndex].iExtNoOfRec )
       
   686         {
       
   687         // Append recor number
       
   688         cmdParams.record = aIndex;
       
   689         }
       
   690     else
       
   691         {
       
   692         ret = KErrGeneral;
       
   693         }
       
   694     
       
   695     if( KErrNone == ret )
       
   696         {
       
   697         ret = iMmPhoneBookStoreMessHandler->UiccMessHandler()->
       
   698             CreateUiccApplCmdReq( cmdParams );
       
   699 TFLOGSTRING2("TSY: CreateUiccApplCmdReq returns %d", ret);
       
   700 OstTraceExt1( TRACE_NORMAL, DUP1_CMMPHONEBOOKOPERATIONWRITE_UICCPBREQWRITEREADEXT, "CMmPhoneBookOperationWrite::UiccPbReqWriteReadExt;ret=%hd", ret );
       
   701         }
       
   702 
       
   703     return ret;
       
   704     
       
   705     }
       
   706 
       
   707 // ---------------------------------------------------------------------------
       
   708 // CMmPhoneBookOperationWrite::UiccPbReqWriteRead
       
   709 // Constructs an ISI-message to Read The existing Entry
       
   710 // ---------------------------------------------------------------------------
       
   711 //
       
   712 TInt CMmPhoneBookOperationWrite::UiccPbReqWriteRead(
       
   713                      TUint16 aFileId,
       
   714                      TUint8 aIndex,
       
   715                      TUint8 aTransId )
       
   716     {
       
   717 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::UiccPbReqWriteRead");
       
   718 OstTrace0( TRACE_NORMAL, CMMPHONEBOOKOPERATIONWRITE_UICCPBREQWRITEREAD, "CMmPhoneBookOperationWrite::UiccPbReqWriteRead" );
       
   719     
       
   720     TInt ret ( KErrNone );
       
   721     
       
   722     TUiccReadLinearFixed cmdParams;
       
   723     cmdParams.messHandlerPtr  = static_cast<MUiccOperationBase*> 
       
   724                                ( iMmPhoneBookStoreMessHandler );
       
   725     cmdParams.filePath.Append( static_cast<TUint8>( MF_FILE >> 8 ));
       
   726     cmdParams.filePath.Append( static_cast<TUint8>( MF_FILE ));
       
   727     cmdParams.filePath.Append( APPL_FILE_ID>>8);
       
   728     cmdParams.filePath.Append( APPL_FILE_ID);
       
   729     cmdParams.filePath.Append( static_cast<TUint8>( DF_PHONEBOOK >> 8 ));
       
   730     cmdParams.filePath.Append( static_cast<TUint8>( DF_PHONEBOOK ));
       
   731     cmdParams.trId = static_cast<TUiccTrId>( aTransId );
       
   732     cmdParams.fileId = aFileId;
       
   733     cmdParams.serviceType =  UICC_APPL_READ_LINEAR_FIXED ;
       
   734     TUint8 arrayIndex ( ConvertToConfArrayIndex( aFileId ) );
       
   735     if( aIndex <= iMmPhoneBookStoreMessHandler->iPBStoreConf[arrayIndex].iNoOfRecords )
       
   736         {
       
   737         cmdParams.record = aIndex;
       
   738         }
       
   739     else
       
   740         {
       
   741         ret = KErrOverflow;
       
   742         }
       
   743     
       
   744     if( KErrNone == ret )
       
   745         {
       
   746         ret = iMmPhoneBookStoreMessHandler->UiccMessHandler()->
       
   747             CreateUiccApplCmdReq( cmdParams );
       
   748 TFLOGSTRING2("TSY: CreateUiccApplCmdReq returns %d", ret);
       
   749 OstTraceExt1( TRACE_NORMAL, DUP1_CMMPHONEBOOKOPERATIONWRITE_UICCPBREQWRITEREAD, "CMmPhoneBookOperationWrite::UiccPbReqWriteRead;ret=%hd", ret );
       
   750         }
       
   751 
       
   752     return ret;
       
   753 
       
   754     }
       
   755 // ---------------------------------------------------------------------------
       
   756 // CMmPhoneBookOperationWrite::UiccPbReqWriteEXTDelete
       
   757 // Constructs an ISI-message to delete EXT File Data
       
   758 // ---------------------------------------------------------------------------
       
   759 //
       
   760 TInt CMmPhoneBookOperationWrite::UiccPbReqWriteExtDelete(
       
   761                   TUint16 aFileId,
       
   762                   TUint16 aFileIdExt,
       
   763                   TUint8 aIndex,
       
   764                   TUint8 aTransId )
       
   765     {
       
   766 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::UiccPbReqWriteEXTDelete");
       
   767 OstTrace0( TRACE_NORMAL, CMMPHONEBOOKOPERATIONWRITE_UICCPBREQWRITEEXTDELETE, "CMmPhoneBookOperationWrite::UiccPbReqWriteEXTDelete" );
       
   768     
       
   769     TInt ret ( KErrNone );
       
   770     TBuf8<13>deleteEntryData;
       
   771     
       
   772     TUiccWriteLinearFixed cmdParams;
       
   773     cmdParams.messHandlerPtr  = static_cast<MUiccOperationBase*> 
       
   774                                ( iMmPhoneBookStoreMessHandler );
       
   775     cmdParams.filePath.Append( static_cast<TUint8>( MF_FILE >> 8 ));
       
   776     cmdParams.filePath.Append( static_cast<TUint8>( MF_FILE ));
       
   777     cmdParams.filePath.Append( APPL_FILE_ID>>8);
       
   778     cmdParams.filePath.Append( APPL_FILE_ID);
       
   779     cmdParams.filePath.Append( static_cast<TUint8>( DF_PHONEBOOK >> 8 ));
       
   780     cmdParams.filePath.Append( static_cast<TUint8>( DF_PHONEBOOK ));
       
   781     cmdParams.trId = static_cast<TUiccTrId>( aTransId );
       
   782     cmdParams.fileId = aFileIdExt;
       
   783     cmdParams.serviceType =  UICC_APPL_UPDATE_LINEAR_FIXED ;
       
   784     
       
   785     TUint8 arrayIndex ( ConvertToConfArrayIndex( aFileId ) );
       
   786 
       
   787     
       
   788     if( aIndex <= iMmPhoneBookStoreMessHandler->iPBStoreConf[arrayIndex].iExtNoOfRec)
       
   789         {
       
   790         cmdParams.record = aIndex;
       
   791         }
       
   792     else
       
   793         {
       
   794         ret = KErrGeneral;
       
   795         }
       
   796     
       
   797     
       
   798     // Append record Type Byte
       
   799     deleteEntryData.Append( 0x00 );
       
   800     // Fill Empty record Data
       
   801     deleteEntryData.AppendFill( 0xFF, 11 );
       
   802     // Fill the next record number
       
   803     deleteEntryData.Append( 0xFF );
       
   804     
       
   805     cmdParams.fileData.Append( deleteEntryData );
       
   806 
       
   807     if( KErrNone == ret )
       
   808         {
       
   809         ret = iMmPhoneBookStoreMessHandler->UiccMessHandler()->
       
   810             CreateUiccApplCmdReq( cmdParams );
       
   811 TFLOGSTRING2("TSY: CreateUiccApplCmdReq returns %d", ret);
       
   812 OstTraceExt1( TRACE_NORMAL, DUP1_CMMPHONEBOOKOPERATIONWRITE_UICCPBREQWRITEEXTDELETE, "CMmPhoneBookOperationWrite::UiccPbReqWriteExtDelete;ret=%hd", ret );
       
   813         }
       
   814 
       
   815     return ret ;
       
   816     }
       
   817 
       
   818 
       
   819 // ---------------------------------------------------------------------------
       
   820 // CMmPhoneBookOperationWrite::UiccPbReqReadMBI
       
   821 // Constructs an ISI-message to Read MBI profile from first record 
       
   822 // ---------------------------------------------------------------------------
       
   823 //
       
   824 TInt CMmPhoneBookOperationWrite::UiccPbReqReadMBI( TUint8 aIndex, TUint8 aTransId )
       
   825     {
       
   826 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::UiccPbReqReadMBI");
       
   827 OstTrace0( TRACE_NORMAL, DUP1_CMMPHONEBOOKOPERATIONWRITE_UICCPBREQREADMBI, "CMmPhoneBookOperationWrite::UiccPbReqReadMBI" );
       
   828         
       
   829         TInt ret ( KErrNone );
       
   830         TUiccReadLinearFixed cmdParams;
       
   831         cmdParams.messHandlerPtr  = static_cast<MUiccOperationBase*> 
       
   832                                    ( iMmPhoneBookStoreMessHandler );
       
   833         cmdParams.filePath.Append( static_cast<TUint8>( MF_FILE >> 8 ));
       
   834         cmdParams.filePath.Append( static_cast<TUint8>( MF_FILE ));
       
   835         cmdParams.filePath.Append( APPL_FILE_ID>>8);
       
   836         cmdParams.filePath.Append( APPL_FILE_ID);
       
   837         cmdParams.filePath.Append( static_cast<TUint8>( DF_PHONEBOOK >> 8 ));
       
   838         cmdParams.filePath.Append( static_cast<TUint8>( DF_PHONEBOOK ));
       
   839         cmdParams.trId = static_cast<TUiccTrId>( aTransId );
       
   840         cmdParams.fileId = PB_MBI_FID;
       
   841         cmdParams.serviceType =  UICC_APPL_READ_LINEAR_FIXED ;
       
   842         cmdParams.dataAmount = 1;
       
   843         cmdParams.dataOffset = aIndex;
       
   844         cmdParams.record = 1;   // only first profile number is supported
       
   845         
       
   846         
       
   847         if( KErrNone == ret )
       
   848             {
       
   849             ret = iMmPhoneBookStoreMessHandler->UiccMessHandler()->
       
   850                 CreateUiccApplCmdReq( cmdParams );
       
   851             }
       
   852         return ret;
       
   853     }
       
   854 
       
   855 
       
   856 
       
   857 // ---------------------------------------------------------------------------
       
   858 // CMmPhoneBookOperationWrite::UiccPBReqWriteMBIProfile
       
   859 // Send Request for MBBI Profile Write
       
   860 // ---------------------------------------------------------------------------
       
   861 //
       
   862 TInt CMmPhoneBookOperationWrite::UiccPBReqWriteMBIProfile( 
       
   863         TUint8 aTransId,
       
   864         TUint8 aIndex,
       
   865         TUint8 aOperationType)
       
   866     {
       
   867 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::UiccPBReqWriteMBIProfile");
       
   868 OstTrace0( TRACE_FATAL, CMMPHONEBOOKOPERATIONWRITE_UICCPBREQWRITEMBIPROFILE, "CMmPhoneBookOperationWrite::UiccPBReqWriteMBIProfile" );
       
   869 
       
   870     TInt ret ( KErrNone );
       
   871     
       
   872     TUiccWriteLinearFixed cmdParams;
       
   873     cmdParams.messHandlerPtr  = static_cast<MUiccOperationBase*> 
       
   874                                ( iMmPhoneBookStoreMessHandler );
       
   875     cmdParams.filePath.Append( static_cast<TUint8>( MF_FILE >> 8 ));
       
   876     cmdParams.filePath.Append( static_cast<TUint8>( MF_FILE ));
       
   877     cmdParams.filePath.Append( APPL_FILE_ID>>8);
       
   878     cmdParams.filePath.Append( APPL_FILE_ID);
       
   879     cmdParams.filePath.Append( static_cast<TUint8>( DF_PHONEBOOK >> 8 ));
       
   880     cmdParams.filePath.Append( static_cast<TUint8>( DF_PHONEBOOK ));
       
   881     cmdParams.trId = static_cast<TUiccTrId>( aTransId );
       
   882     cmdParams.fileId = PB_MBI_FID;
       
   883     cmdParams.serviceType =  UICC_APPL_READ_LINEAR_FIXED ;
       
   884     cmdParams.dataAmount = 1;
       
   885     cmdParams.dataOffset = aIndex;
       
   886     cmdParams.record = 1;   // only first profile number is supported
       
   887     
       
   888     if( KOperationDelete == aOperationType )
       
   889         {
       
   890         cmdParams.fileData.Append( 0 );
       
   891         }
       
   892     else
       
   893         {
       
   894         cmdParams.fileData.Append( iEntryToWrite );
       
   895         }
       
   896     
       
   897     
       
   898     if( KErrNone == ret )
       
   899         {
       
   900         ret = iMmPhoneBookStoreMessHandler->UiccMessHandler()->
       
   901             CreateUiccApplCmdReq( cmdParams );
       
   902         }
       
   903 
       
   904     return ret;
       
   905     
       
   906     }
       
   907 // ---------------------------------------------------------------------------
       
   908 // CMmPhoneBookOperationWrite::HandleUICCPbRespL
       
   909 // Separate response
       
   910 // ---------------------------------------------------------------------------
       
   911 //
       
   912 TBool CMmPhoneBookOperationWrite::HandleUICCPbRespL(
       
   913     TInt aStatus,
       
   914     TUint8 aDetails,
       
   915     const TDesC8& aFileData,
       
   916     TInt aTransId )
       
   917     {
       
   918 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::HandleUICCPbRespL");
       
   919 OstTrace0( TRACE_NORMAL, CMMPHONEBOOKOPERATIONWRITE_HANDLEUICCPBRESPL, "CMmPhoneBookOperationWrite::HandleUICCPbRespL" );
       
   920     
       
   921     TBool complete ( EFalse );
       
   922     TInt ret ( KErrNone );
       
   923     
       
   924     TUint16 fileIdExt ( 0x0000 );
       
   925     TUint16 fileId = ConvertToPBfileId( iPhoneBookTypeName, fileIdExt );
       
   926     //// Check for PhoenBook Index for which needs to checked
       
   927     TUint8 pbArrayIndex = ConvertToConfArrayIndex( fileId );
       
   928 
       
   929     switch( iCurrentWritePhase )
       
   930         {
       
   931         case EPBWritePhase_Read_Entry:
       
   932             {
       
   933             ret = HandleWriteReadEntryResp(
       
   934                   aStatus,
       
   935                   aFileData,
       
   936                   aTransId,
       
   937                   fileId,
       
   938                   fileIdExt,
       
   939                   pbArrayIndex );
       
   940             break;
       
   941             }
       
   942         case EPBWritePhase_Read_Ext_Entry:
       
   943             {
       
   944             ret = HandleWriteReadExtEntryResp(
       
   945                   aStatus,
       
   946                   aFileData,
       
   947                   aTransId,
       
   948                   fileId,
       
   949                   fileIdExt );
       
   950             break;
       
   951             }
       
   952         case EPBWritePhase_Search_Ext_Entry:
       
   953             {
       
   954             ret = HandleWriteSearchExtEntryResp(
       
   955                   aStatus,
       
   956                   aFileData,
       
   957                   aTransId,
       
   958                   fileId,
       
   959                   fileIdExt );
       
   960             break;
       
   961             }
       
   962         case EPBWritePhase_Write_Entry:
       
   963             {
       
   964             ret = HandleWriteEntryResp(
       
   965                   aStatus,
       
   966                   aTransId,
       
   967                   fileId,
       
   968                   fileIdExt );
       
   969             break;
       
   970             }
       
   971         case EPBWritePhase_Write_Ext_Entry:
       
   972             {
       
   973             ret = HandleWriteExtEntryResp(
       
   974                   aStatus,
       
   975                   aTransId,
       
   976                   fileId,
       
   977                   fileIdExt );
       
   978             break;
       
   979             }
       
   980         case EPBWritePhase_Read_MBI_profile:
       
   981             {
       
   982             ret = HandleWriteMBIReadResp(
       
   983                     aStatus,
       
   984                     aDetails,
       
   985                     aTransId,
       
   986                     aFileData );
       
   987             break;
       
   988             }
       
   989         case EPBWritePhase_Write_MBI_profile:
       
   990             {
       
   991             ret = HandleWriteMBIWriteResp(
       
   992                     aStatus,
       
   993                     aDetails);
       
   994             break;
       
   995             }
       
   996         default:
       
   997             {
       
   998 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::HandleSimPbRespL - NO such Write operation Phase supported ");
       
   999 OstTrace0( TRACE_NORMAL, DUP1_CMMPHONEBOOKOPERATIONWRITE_HANDLEUICCPBRESPL, "CMmPhoneBookOperationWrite::HandleUICCPbRespL - No such write operation phase supported" );
       
  1000             break;
       
  1001             }
       
  1002         }
       
  1003     
       
  1004     if( ( KErrNone != ret ) || ( iCurrentWritePhase == EPBWritePhase_complete ))
       
  1005         {
       
  1006         // Complete the to common TSY
       
  1007         CPhoneBookDataPackage phoneBookData;
       
  1008 
       
  1009         //create a struct
       
  1010         TPBEntryInfo pbEntryInfo;
       
  1011         // Set the structure as it has failed, we don't care of following
       
  1012         // information so set to 0
       
  1013         pbEntryInfo.iMaxNumLength = 0;
       
  1014         pbEntryInfo.iLocation = 0;
       
  1015         if( KErrNone == ret )
       
  1016             {
       
  1017             pbEntryInfo.iLocation = iPhoneBookEntry->iLocation;
       
  1018             }
       
  1019         // For EXT file Errors need not to pass to commontsy
       
  1020         if( KErrGeneral == ret )
       
  1021             {
       
  1022             ret = KErrNone;
       
  1023             }
       
  1024         phoneBookData.SetPhoneBookName( iPhoneBookTypeName );
       
  1025 
       
  1026         //Pack Data and complete
       
  1027         phoneBookData.PackData( &pbEntryInfo );
       
  1028         iMmPhoneBookStoreMessHandler->MessageRouter()->Complete(
       
  1029             EMmTsyPhoneBookStoreWriteIPC,
       
  1030             &phoneBookData,
       
  1031             ret );
       
  1032 
       
  1033         // set flag to indicate that we can remove this operation from array
       
  1034         complete = ETrue;
       
  1035         }
       
  1036     return complete;
       
  1037     }
       
  1038 
       
  1039 
       
  1040 // ---------------------------------------------------------------------------
       
  1041 // CMmPhoneBookOperationWrite::HandleWriteReadEntryResp
       
  1042 // Handle response for Read Entry Phase
       
  1043 // ---------------------------------------------------------------------------
       
  1044 //
       
  1045 TInt CMmPhoneBookOperationWrite::HandleWriteReadEntryResp(
       
  1046     TInt aStatus,
       
  1047     const TDesC8& aFileData,
       
  1048     TUint8 aTransId,
       
  1049     TUint16 aFileId,
       
  1050     TUint16 aFileIdExt,
       
  1051     TUint8 aArrayIndex )
       
  1052     {
       
  1053 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::HandleWriteReadEntryResp");
       
  1054 OstTrace0( TRACE_NORMAL, CMMPHONEBOOKOPERATIONWRITE_HANDLEWRITEREADENTRYRESP, "CMmPhoneBookOperationWrite::HandleWriteReadEntryResp" );
       
  1055     TInt ret ( KErrNone );
       
  1056     
       
  1057     if( UICC_STATUS_OK == aStatus )
       
  1058         {
       
  1059         // Check for Emtry Entry
       
  1060         if( KErrNone == EmptyEntryCheck( aFileData ) )
       
  1061             {
       
  1062             // if entry is present
       
  1063             // Check if its a location search
       
  1064             if( !iLocationSearch )
       
  1065                 {
       
  1066                 
       
  1067                 // Check for Ext data present or not
       
  1068                 if( 0xFF == aFileData[iMmPhoneBookStoreMessHandler->
       
  1069                             iPBStoreConf[aArrayIndex].iAlphaStringlength+ 13] )
       
  1070                     {
       
  1071                     // No EXT Records 
       
  1072                     // Check if EXT reords needed for Entry to be write
       
  1073                     if( ( KErrNotFound != iExtRecordArrayToBeWrite.Find( 0 ) ))
       
  1074                         {
       
  1075                         // Start Search for Ext record
       
  1076                         // Search for more free records
       
  1077                         iCurrentWritePhase = EPBWritePhase_Search_Ext_Entry;
       
  1078                         
       
  1079                         // Send request to read first entry in Ext
       
  1080                         iExtRecordNo = 1;
       
  1081                         ret = UiccPbReqWriteReadExt(
       
  1082                               aFileId,
       
  1083                               aFileIdExt,
       
  1084                               iExtRecordNo,
       
  1085                               aTransId );
       
  1086                         }
       
  1087                     else
       
  1088                         {
       
  1089                         // Start Write main Entry
       
  1090                         iCurrentWritePhase = EPBWritePhase_Write_Entry;
       
  1091                         TUint8 indexToWrite ( 0 );
       
  1092                         if( PB_MBDN_FID == aFileId )
       
  1093                             {
       
  1094                             indexToWrite = iEntryToWrite;
       
  1095                             }
       
  1096                         else
       
  1097                             {
       
  1098                             indexToWrite = iPhoneBookEntry->iLocation;
       
  1099                             }
       
  1100                         ret = UiccPBReqWriteEntry(
       
  1101                               aFileId,
       
  1102                               indexToWrite,
       
  1103                               aTransId,
       
  1104                               *iPhoneBookEntry );
       
  1105                         }
       
  1106                     }
       
  1107                 else
       
  1108                     {
       
  1109                     // Append this Record number to be Delete record Array
       
  1110                     iExtRecordArrayToBeDelete.Append(
       
  1111                                     iMmPhoneBookStoreMessHandler->
       
  1112                                     iPBStoreConf[aArrayIndex].iAlphaStringlength+ 13 );
       
  1113                     
       
  1114                     // Start Reading EXT Record
       
  1115                     iCurrentWritePhase = EPBWritePhase_Read_Ext_Entry;
       
  1116                     TUint8 indexToRead = iMmPhoneBookStoreMessHandler->
       
  1117                                iPBStoreConf[aArrayIndex].iAlphaStringlength+ 13;
       
  1118                     ret = UiccPbReqWriteReadExt(
       
  1119                           aFileId,
       
  1120                           aFileIdExt,
       
  1121                           indexToRead,
       
  1122                           aTransId );
       
  1123                     }
       
  1124                 }
       
  1125             else
       
  1126                 {
       
  1127                 // Serach for next location
       
  1128                 // Start searching for first free Entry
       
  1129                 iCurrentWritePhase = EPBWritePhase_Read_Entry;
       
  1130                 iEntryToWrite++;
       
  1131                 ret = UiccPbReqWriteRead(
       
  1132                       aFileId,
       
  1133                       iEntryToWrite,
       
  1134                       aTransId );
       
  1135                 }
       
  1136             }
       
  1137         else
       
  1138             {
       
  1139             // entry not found and
       
  1140             // Check if EXT reords needed for Entry to be write
       
  1141             iLocationSearch = EFalse;
       
  1142             if( 0 < iExtRecordArrayToBeWrite.Count() )
       
  1143                 {
       
  1144                 // Start Search for Ext record
       
  1145                 // Search for more free records
       
  1146                 iCurrentWritePhase = EPBWritePhase_Search_Ext_Entry;
       
  1147                 
       
  1148                 // Send request to read first entry in Ext
       
  1149                 iExtRecordNo = 1;
       
  1150                 ret = UiccPbReqWriteReadExt(
       
  1151                       aFileId,
       
  1152                       aFileIdExt,
       
  1153                       iExtRecordNo,
       
  1154                       aTransId);
       
  1155                 }
       
  1156             else
       
  1157                 {
       
  1158                 // For MBDN PhoneBook First update MBI File
       
  1159                 
       
  1160                 // Start Write Entry
       
  1161                 iCurrentWritePhase = EPBWritePhase_Write_Entry;
       
  1162                 TUint8 index ( 0 ); 
       
  1163                 if( ( PB_MBDN_FID == aFileId )|| ( 0 == iPhoneBookEntry->iLocation ))
       
  1164                     {
       
  1165                     index = iEntryToWrite; 
       
  1166                     }
       
  1167                 else
       
  1168                     {
       
  1169                     index = iPhoneBookEntry->iLocation;
       
  1170                     }
       
  1171                 ret = UiccPBReqWriteEntry(
       
  1172                         aFileId,
       
  1173                         index,
       
  1174                         aTransId,
       
  1175                         *iPhoneBookEntry );
       
  1176                 }
       
  1177             }
       
  1178         }
       
  1179     else
       
  1180         {
       
  1181         ret = KErrGeneral;
       
  1182         }
       
  1183 
       
  1184     return ret;
       
  1185     }
       
  1186 
       
  1187 
       
  1188 
       
  1189 
       
  1190 
       
  1191 // ---------------------------------------------------------------------------
       
  1192 // CMmPhoneBookOperationWrite::HandleWriteReadExtEntryResp
       
  1193 // Handle Read EXt fiel response
       
  1194 // ---------------------------------------------------------------------------
       
  1195 //
       
  1196 TInt CMmPhoneBookOperationWrite::HandleWriteReadExtEntryResp(
       
  1197     TInt aStatus,
       
  1198     const TDesC8& aFileData,
       
  1199     TUint8 aTransId,
       
  1200     TUint16 aFileId,
       
  1201     TUint16 aFileIdExt)
       
  1202     {
       
  1203 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::HandleWriteReadExtEntryResp");
       
  1204 OstTrace0( TRACE_NORMAL, CMMPHONEBOOKOPERATIONWRITE_HANDLEWRITEREADEXTENTRYRESP, "CMmPhoneBookOperationWrite::HandleWriteReadExtEntryResp" );
       
  1205     TInt ret ( KErrNone );
       
  1206     
       
  1207     if( UICC_STATUS_OK == aStatus )
       
  1208         {
       
  1209         // Check if There is further records for this Entry
       
  1210         if( 0xFF == aFileData[UICC_EXT_REC_NO_OFFSET] )
       
  1211             {
       
  1212             // There is no Further records
       
  1213             if( 0 < iExtRecordArrayToBeWrite.Count() )
       
  1214                 {
       
  1215                 // Check if to be delete records are sufficient to write new entry
       
  1216                 if( iExtRecordArrayToBeWrite.Count() <= 
       
  1217                     iExtRecordArrayToBeDelete.Count())
       
  1218                     {
       
  1219                     // NO need to search for new records
       
  1220                     // Copy record nos
       
  1221                     for( TInt i = 0; i<iExtRecordArrayToBeWrite.Count(); i++)
       
  1222                         {
       
  1223                         iExtRecordArrayToBeWrite[i] = iExtRecordArrayToBeDelete[i];
       
  1224                         }
       
  1225                     // Start Deleting Ext data
       
  1226                     iCurrentWritePhase = EPBWritePhase_Write_Ext_Entry;
       
  1227                     iExtDeleteOperation= ETrue;
       
  1228                     //last index
       
  1229                     TUint8 index = iExtRecordArrayToBeDelete[ iExtRecordArrayToBeDelete.Count() -1 ];
       
  1230                     ret = UiccPbReqWriteExtDelete(
       
  1231                           aFileId,
       
  1232                           aFileIdExt,
       
  1233                           index,
       
  1234                           aTransId );
       
  1235                     }
       
  1236                 else
       
  1237                     {
       
  1238                     // Copy the records
       
  1239                     for( TInt i = 0; i<iExtRecordArrayToBeDelete.Count(); i++)
       
  1240                         {
       
  1241                         iExtRecordArrayToBeWrite[i] = iExtRecordArrayToBeDelete[i];
       
  1242                         }
       
  1243                     // Start Searching for remaining records
       
  1244                     iCurrentWritePhase = EPBWritePhase_Search_Ext_Entry;
       
  1245                     // Start Searching for first location
       
  1246                     iExtRecordNo = 1;
       
  1247                     ret = UiccPbReqWriteReadExt(
       
  1248                           aFileId,
       
  1249                           aFileIdExt,
       
  1250                           iExtRecordNo,
       
  1251                           aTransId );
       
  1252                     }
       
  1253                 }
       
  1254             else
       
  1255                 {
       
  1256                 // Start Writing EXT Data delete
       
  1257                 if( 0 < iExtRecordArrayToBeDelete.Count() )
       
  1258                     {
       
  1259                     // Start Writing Ext data
       
  1260                     iCurrentWritePhase = EPBWritePhase_Write_Ext_Entry;
       
  1261                     iExtDeleteOperation = ETrue;
       
  1262                     //last index
       
  1263                     TUint8 index = 
       
  1264                       iExtRecordArrayToBeDelete[ iExtRecordArrayToBeDelete.Count() -1 ];
       
  1265                     ret = UiccPbReqWriteExtDelete(
       
  1266                           aFileId,
       
  1267                           aFileIdExt,
       
  1268                           index,
       
  1269                           aTransId );
       
  1270                     }
       
  1271                 else
       
  1272                     {
       
  1273                     // Start Writing main Entry
       
  1274                     iCurrentWritePhase = EPBWritePhase_Write_Entry;
       
  1275                     //last index
       
  1276                     TUint8 index (0 );
       
  1277                     if( PB_MBDN_FID == aFileId )
       
  1278                         {
       
  1279                         index = iEntryToWrite;
       
  1280                         }
       
  1281                     else
       
  1282                         {
       
  1283                         index = iPhoneBookEntry->iLocation;
       
  1284                         }
       
  1285                     ret = UiccPBReqWriteEntry(
       
  1286                           aFileId,
       
  1287                           index,
       
  1288                           aTransId,
       
  1289                           *iPhoneBookEntry );
       
  1290                     }
       
  1291                 }
       
  1292             }
       
  1293         else
       
  1294             {
       
  1295             // Append Current record no to the Array
       
  1296             iExtRecordArrayToBeDelete.Append( aFileData[UICC_EXT_REC_NO_OFFSET] );
       
  1297             // Raed Next 
       
  1298             iCurrentWritePhase = EPBWritePhase_Read_Ext_Entry;
       
  1299             ret = UiccPbReqWriteReadExt(
       
  1300                   aFileId,
       
  1301                   aFileIdExt,
       
  1302                   aFileData[UICC_EXT_REC_NO_OFFSET],
       
  1303                   aTransId );
       
  1304             }
       
  1305         }
       
  1306     else
       
  1307         {
       
  1308             ret = KErrGeneral;
       
  1309         }
       
  1310 
       
  1311     return ret;
       
  1312     }
       
  1313 
       
  1314 // ---------------------------------------------------------------------------
       
  1315 // CMmPhoneBookOperationWrite::HandleWriteSearchExtEntryResp
       
  1316 // Handle Search for Ext record response
       
  1317 // ---------------------------------------------------------------------------
       
  1318 //
       
  1319 TInt CMmPhoneBookOperationWrite::HandleWriteSearchExtEntryResp(
       
  1320     TInt aStatus,
       
  1321     const TDesC8& aFileData,
       
  1322     TUint8 aTransId,
       
  1323     TUint16 aFileId,
       
  1324     TUint16 aFileIdExt)
       
  1325     {
       
  1326 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::HandleWriteSearchExtEntryResp");
       
  1327 OstTrace0( TRACE_NORMAL, CMMPHONEBOOKOPERATIONWRITE_HANDLEWRITESEARCHEXTENTRYRESP, "CMmPhoneBookOperationWrite::HandleWriteSearchExtEntryResp" );
       
  1328     TInt ret ( KErrNone );
       
  1329     TUint8 arrayIndex ( ConvertToConfArrayIndex( aFileId ) );
       
  1330     
       
  1331     if( UICC_STATUS_OK == aStatus)
       
  1332         {
       
  1333         // Check if Entry is Free
       
  1334         if( KErrNotFound == EmptyEntryCheck( aFileData ) )
       
  1335             {
       
  1336             TInt location ( iExtRecordArrayToBeWrite.Find ( 0 ) );
       
  1337             // Append this Record no in Array
       
  1338             iExtRecordArrayToBeWrite[location] = iExtRecordNo;
       
  1339             // Check if there is any record no 0 in to be write record array
       
  1340             if( KErrNotFound == iExtRecordArrayToBeWrite.Find ( 0 ) )
       
  1341                 {
       
  1342                 // Start Writing to EXT records
       
  1343                 // first do the delete records
       
  1344                 if( iExtRecordArrayToBeDelete.Count() > 0 )
       
  1345                     {
       
  1346                     // Start Writing or deleting the Entry
       
  1347                     iCurrentWritePhase = EPBWritePhase_Write_Ext_Entry;
       
  1348                     iExtDeleteOperation = ETrue;
       
  1349                     TUint8 index = 
       
  1350                     iExtRecordArrayToBeDelete[ iExtRecordArrayToBeDelete.Count() -1 ];
       
  1351                     ret = UiccPbReqWriteExtDelete( 
       
  1352                             aFileId,
       
  1353                             aFileIdExt,
       
  1354                             index,
       
  1355                             aTransId );
       
  1356                     iExtRecordArrayToBeDelete.Remove( 
       
  1357                             iExtRecordArrayToBeDelete.Count() -1 );
       
  1358                     iExtRecordArrayToBeDelete.Compress();
       
  1359                     }
       
  1360                 else 
       
  1361                     {
       
  1362                     // Start Writing the Entry
       
  1363                     iCurrentWritePhase = EPBWritePhase_Write_Entry;
       
  1364                     TUint8 index ( 0 );
       
  1365                         // Start writing main Entry
       
  1366                     if( ( iPhoneBookEntry->iLocation == 0 )||( PB_MBDN_FID == aFileId ) )
       
  1367                         {
       
  1368                         index = iEntryToWrite;
       
  1369                         }
       
  1370                     else
       
  1371                         {
       
  1372                         index = iPhoneBookEntry->iLocation;
       
  1373                         }
       
  1374                     if( 0 < index )
       
  1375                         {
       
  1376                         ret = UiccPBReqWriteEntry(
       
  1377                                 aFileId,
       
  1378                                 index,
       
  1379                                 aTransId,
       
  1380                                 *iPhoneBookEntry );
       
  1381                         }
       
  1382                     else
       
  1383                         {
       
  1384                         ret = KErrNotFound;
       
  1385                         }
       
  1386                     }
       
  1387                 }
       
  1388             else
       
  1389                 {
       
  1390                 // further search for free records
       
  1391                 iCurrentWritePhase = EPBWritePhase_Search_Ext_Entry;
       
  1392                 TUint8 index = iExtRecordNo++;
       
  1393                 if( index < iMmPhoneBookStoreMessHandler->
       
  1394                             iPBStoreConf[ arrayIndex ].iExtNoOfRec )
       
  1395                     {
       
  1396                     ret = UiccPbReqWriteReadExt(
       
  1397                           aFileId,
       
  1398                           aFileIdExt,
       
  1399                           index,
       
  1400                           aTransId );
       
  1401                     }
       
  1402                 else
       
  1403                     {
       
  1404                     ret = KErrGeneral;
       
  1405                     }
       
  1406                 }
       
  1407             }
       
  1408         else
       
  1409             {
       
  1410             // further search for free records
       
  1411             iCurrentWritePhase = EPBWritePhase_Search_Ext_Entry;
       
  1412             TUint8 index = iExtRecordNo++;
       
  1413             if( index < iMmPhoneBookStoreMessHandler->
       
  1414                         iPBStoreConf[ arrayIndex ].iExtNoOfRec )
       
  1415                 {
       
  1416                 ret = UiccPbReqWriteReadExt(
       
  1417                       aFileId,
       
  1418                       aFileIdExt,
       
  1419                       index,
       
  1420                       aTransId );
       
  1421                 }
       
  1422             else
       
  1423                 {
       
  1424                 ret = KErrGeneral;
       
  1425                 }
       
  1426             }
       
  1427         }
       
  1428     else
       
  1429         {
       
  1430         ret = KErrGeneral;
       
  1431         }
       
  1432 
       
  1433     return ret;
       
  1434     }
       
  1435 
       
  1436 
       
  1437 
       
  1438 // ---------------------------------------------------------------------------
       
  1439 // TBool CMmPhoneBookOperationWrite::HandleWriteEntryResp
       
  1440 // Handle write response for EXT part of Entry
       
  1441 // ---------------------------------------------------------------------------
       
  1442 //
       
  1443 TInt CMmPhoneBookOperationWrite::HandleWriteEntryResp(
       
  1444     TInt aStatus,
       
  1445     TUint8 aTransId,
       
  1446     TUint16 aFileId,
       
  1447     TUint16 aFileIdExt) 
       
  1448     {
       
  1449 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::HandleWriteEntryResp");
       
  1450 OstTrace0( TRACE_NORMAL, CMMPHONEBOOKOPERATIONWRITE_HANDLEWRITEENTRYRESP, "CMmPhoneBookOperationWrite::HandleWriteEntryResp" );
       
  1451     TInt ret ( KErrNone );
       
  1452     TUint8 arrayIndex ( ConvertToConfArrayIndex( aFileId ));
       
  1453     
       
  1454     if( UICC_STATUS_OK == aStatus )
       
  1455         {
       
  1456         iEntryToUpdateInList = new ( ELeave ) TPBEntry();
       
  1457         
       
  1458         // Update the Entry needs to be Stored
       
  1459         if( ( 0 == iPhoneBookEntry->iLocation )|| ( PB_MBDN_FID == aFileId ) )
       
  1460             {
       
  1461             iEntryToUpdateInList->iEntryIndex = iEntryToWrite;
       
  1462             iEntryToUpdateInList->iEntryPresent = ETrue;
       
  1463             }
       
  1464         else
       
  1465             {
       
  1466             iEntryToUpdateInList->iEntryIndex = iPhoneBookEntry->iLocation;
       
  1467             iEntryToUpdateInList->iEntryPresent = ETrue;
       
  1468             }
       
  1469 
       
  1470         // Check there is ant EXT Data to be Write or Delete
       
  1471         if( iExtRecordArrayToBeWrite.Count() > 0 )
       
  1472             {
       
  1473             // Update Entry
       
  1474             iEntryToUpdateInList->PBEntryExtRecord.Append( iExtRecordArrayToBeWrite[0] );
       
  1475             iCurrentWritePhase = EPBWritePhase_Write_Ext_Entry;
       
  1476             // Start Writing to EXT records
       
  1477             TUint8 index = iExtRecordArrayToBeWrite[0];
       
  1478             ret = UiccPbReqWriteExt(
       
  1479                     aTransId,
       
  1480                     index,
       
  1481                     aFileId,
       
  1482                     aFileIdExt,
       
  1483                     *iPhoneBookEntry );
       
  1484             }
       
  1485         else
       
  1486             {
       
  1487             // Remove old Entry from the list 
       
  1488             TInt index = iMmPhoneBookStoreMessHandler->
       
  1489                          GetIndexForPresentEntry( iPhoneBookEntry->iLocation, arrayIndex );
       
  1490             if( 0 <= index )
       
  1491                 {
       
  1492                 iMmPhoneBookStoreMessHandler->UpdateEntryFromList( iEntryToUpdateInList, index, arrayIndex );
       
  1493                 }
       
  1494             else
       
  1495                 {
       
  1496                 // Append the Entry to the List
       
  1497                 iMmPhoneBookStoreMessHandler->StoreEntryToPhoneBookList( iEntryToUpdateInList, arrayIndex );
       
  1498                 }
       
  1499             // If it is MBDN Phone Book then update MBI File also
       
  1500             if( PB_MBDN_FID == aFileId)
       
  1501                 {
       
  1502                 // Start Writing MBI file
       
  1503                 iCurrentWritePhase = EPBWritePhase_Write_MBI_profile;
       
  1504                 ret = UiccPBReqWriteMBIProfile( 
       
  1505                         aTransId,
       
  1506                         iPhoneBookEntry->iLocation,
       
  1507                         KOperationWrite);
       
  1508                 iMBIOperation = KOperationWrite;
       
  1509                 }
       
  1510             else
       
  1511                 {
       
  1512                 iCurrentWritePhase = EPBWritePhase_complete;
       
  1513                 }
       
  1514             }
       
  1515         }
       
  1516     else
       
  1517         {
       
  1518         // If it is a MBDN PhoneBook Then delete MBI profile by writin 0
       
  1519         if( PB_MBDN_FID == aFileId)
       
  1520             {
       
  1521             // Start Writing MBI file
       
  1522             iCurrentWritePhase = EPBWritePhase_Write_MBI_profile;
       
  1523             ret = UiccPBReqWriteMBIProfile( 
       
  1524                     aTransId,
       
  1525                     iPhoneBookEntry->iLocation,
       
  1526                     KOperationDelete );
       
  1527             iMBIOperation = KOperationDelete;
       
  1528             }
       
  1529         else
       
  1530             {
       
  1531             ret = KErrArgument;
       
  1532             }
       
  1533         }
       
  1534     return ret;
       
  1535     
       
  1536     }
       
  1537 
       
  1538 
       
  1539 
       
  1540 // ---------------------------------------------------------------------------
       
  1541 // TBool CMmPhoneBookOperationWrite::HandleWriteExtEntryResp
       
  1542 // Handle write response for EXT part of Entry
       
  1543 // ---------------------------------------------------------------------------
       
  1544 //
       
  1545 TInt CMmPhoneBookOperationWrite::HandleWriteExtEntryResp(
       
  1546     TInt aStatus,
       
  1547     TUint8 aTransId,
       
  1548     TUint16 aFileId,
       
  1549     TUint16 aFileIdExt) 
       
  1550     {
       
  1551 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::HandleWriteExtEntryResp");
       
  1552 OstTrace0( TRACE_NORMAL, CMMPHONEBOOKOPERATIONWRITE_HANDLEWRITEEXTENTRYRESP, "CMmPhoneBookOperationWrite::HandleWriteExtEntryResp" );
       
  1553     TInt ret ( KErrNone );
       
  1554     TUint8 arrayIndex ( ConvertToConfArrayIndex( aFileId ));
       
  1555     
       
  1556     if( UICC_STATUS_OK  == aStatus )
       
  1557         {
       
  1558         if( iExtDeleteOperation )
       
  1559             {
       
  1560             if( iExtRecordArrayToBeDelete.Count() > 0 )
       
  1561                 {
       
  1562                 // remove the Entry Which has been deleted
       
  1563                 iExtRecordArrayToBeDelete.Remove(
       
  1564                                           iExtRecordArrayToBeDelete.Count() - 1 );
       
  1565                 iExtRecordArrayToBeDelete.Compress();
       
  1566                 }
       
  1567             // Remove old Entry from the list 
       
  1568             TInt index = iMmPhoneBookStoreMessHandler->GetIndexForPresentEntry( iPhoneBookEntry->iLocation, arrayIndex );
       
  1569             if( 0 <= index )
       
  1570                 {
       
  1571                 iMmPhoneBookStoreMessHandler->RemoveExtEntryFromList( index, arrayIndex);
       
  1572                 }
       
  1573             
       
  1574             if( iExtRecordArrayToBeDelete.Count() > 0 )
       
  1575                 {
       
  1576                 iCurrentWritePhase = EPBWritePhase_Write_Ext_Entry;
       
  1577                 iExtDeleteOperation = ETrue;
       
  1578                 TUint8 index = iExtRecordArrayToBeDelete[
       
  1579                                iExtRecordArrayToBeDelete.Count() -1 ];
       
  1580                 ret = UiccPbReqWriteExtDelete( aFileId, aFileIdExt, index, aTransId );
       
  1581                 }
       
  1582             else
       
  1583                 {
       
  1584                 // Start Writing the Entry
       
  1585                 iCurrentWritePhase = EPBWritePhase_Write_Entry;
       
  1586                 TUint8 index ( 0 );
       
  1587                 // Start writing main Entry
       
  1588                 if( ( iPhoneBookEntry->iLocation == 0 )||( PB_MBDN_FID == aFileId ) )
       
  1589                     {
       
  1590                     index = iEntryToWrite;
       
  1591                     }
       
  1592                 else
       
  1593                     {
       
  1594                     index = iPhoneBookEntry->iLocation;
       
  1595                     }
       
  1596                 if( 0 < index )
       
  1597                     {
       
  1598                     ret = UiccPBReqWriteEntry(
       
  1599                           aFileId,
       
  1600                           index,
       
  1601                           aTransId,
       
  1602                           *iPhoneBookEntry );
       
  1603                     }
       
  1604                 else
       
  1605                     {
       
  1606                     ret = KErrNotFound;
       
  1607                     }
       
  1608                 }
       
  1609             }
       
  1610         else
       
  1611             {
       
  1612             // Append the record number to the Entry
       
  1613             iEntryToUpdateInList->PBEntryExtRecord.Append( iExtRecordArrayToBeWrite[0] );
       
  1614             // remove the Entry Which has been Written
       
  1615             iExtRecordArrayToBeWrite.Remove( 0 );
       
  1616             iExtRecordArrayToBeWrite.Compress();
       
  1617             
       
  1618             // Start Writing to EXT records
       
  1619             // first do the delete records
       
  1620             if( iExtRecordArrayToBeWrite.Count() > 0 )
       
  1621                 {
       
  1622                 iEntryToUpdateInList->PBEntryExtRecord.Append( iExtRecordArrayToBeWrite[0] );
       
  1623                 TUint8 index = iExtRecordArrayToBeWrite[0];
       
  1624                 ret = UiccPbReqWriteExt(
       
  1625                       aTransId,
       
  1626                       index,
       
  1627                       aFileId,
       
  1628                       aFileIdExt,
       
  1629                       *iPhoneBookEntry );
       
  1630                 }
       
  1631             else
       
  1632                 {
       
  1633                 // Overwrite old Entry from the list 
       
  1634                 TInt index = iMmPhoneBookStoreMessHandler->
       
  1635                              GetIndexForPresentEntry( iPhoneBookEntry->iLocation, arrayIndex );
       
  1636                 if( 0 <= index )
       
  1637                     {
       
  1638                     iMmPhoneBookStoreMessHandler->UpdateEntryFromList( iEntryToUpdateInList, index, arrayIndex );
       
  1639                     }
       
  1640                 else
       
  1641                     {
       
  1642                     // Append the Entry to the List
       
  1643                     iMmPhoneBookStoreMessHandler->StoreEntryToPhoneBookList( iEntryToUpdateInList, arrayIndex );
       
  1644                     }
       
  1645                 // If it is MBDN PhoenBook then update MBI Profile also
       
  1646                 if( PB_MBDN_FID == aFileId)
       
  1647                     {
       
  1648                     // Start Writing MBI file
       
  1649                     iCurrentWritePhase = EPBWritePhase_Write_MBI_profile;
       
  1650                     ret = UiccPBReqWriteMBIProfile( 
       
  1651                             aTransId,
       
  1652                             iPhoneBookEntry->iLocation,
       
  1653                             KOperationWrite);
       
  1654                     iMBIOperation = KOperationWrite;
       
  1655                     }
       
  1656                 else
       
  1657                     {
       
  1658                     // Complete the Task
       
  1659                     iCurrentWritePhase = EPBWritePhase_complete;
       
  1660                     }
       
  1661                 }
       
  1662             }
       
  1663         }
       
  1664     else
       
  1665         {
       
  1666         if( PB_MBDN_FID == aFileId )
       
  1667             {
       
  1668             // Start Writing MBI File
       
  1669             iCurrentWritePhase = EPBWritePhase_Write_MBI_profile;
       
  1670             ret = UiccPBReqWriteMBIProfile( 
       
  1671                     aTransId,
       
  1672                     iPhoneBookEntry->iLocation,
       
  1673                     KOperationWrite);
       
  1674             iMBIOperation = KOperationWrite;
       
  1675             }
       
  1676         else
       
  1677             {
       
  1678             ret = KErrGeneral;
       
  1679             }
       
  1680         }
       
  1681     return ret;
       
  1682     }
       
  1683 
       
  1684 
       
  1685 // ---------------------------------------------------------------------------
       
  1686 // TBool CMmPhoneBookOperationWrite::HandleWriteMBIReadResp
       
  1687 // Handle write response for MBI profile read
       
  1688 // ---------------------------------------------------------------------------
       
  1689 //
       
  1690 TInt CMmPhoneBookOperationWrite::HandleWriteMBIReadResp(
       
  1691         TInt aStatus,
       
  1692         TUint8 aDetails,
       
  1693         TUint8 aTransId,
       
  1694         const TDesC8 &aFileData ) 
       
  1695     {
       
  1696     TInt ret ( KErrNone );
       
  1697 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::HandleWriteMBIReadResp");
       
  1698 OstTrace0( TRACE_NORMAL, DUP1_CMMPHONEBOOKOPERATIONWRITE_HANDLEWRITEMBIREADRESP, "CMmPhoneBookOperationWrite::HandleWriteMBIReadResp" );
       
  1699 
       
  1700 
       
  1701     if( UICC_STATUS_OK  == aStatus )
       
  1702         {
       
  1703         iEntryToWrite = aFileData[0];
       
  1704         ret = UiccPbReqWriteL( aTransId, iEntryToWrite, *iPhoneBookEntry );
       
  1705         }
       
  1706     else
       
  1707         {
       
  1708         if( UICC_SECURITY_CONDITIONS_NOT_SATISFIED == aDetails )
       
  1709             {
       
  1710             ret = KErrAccessDenied;
       
  1711             }
       
  1712         else
       
  1713             {
       
  1714             ret = KErrArgument;
       
  1715             }
       
  1716         }
       
  1717 
       
  1718 
       
  1719     return ret;
       
  1720     }
       
  1721 
       
  1722 
       
  1723 // ---------------------------------------------------------------------------
       
  1724 // TBool CMmPhoneBookOperationWrite::HandleWriteMBIWriteResp
       
  1725 // Handle write response for MBI profile write
       
  1726 // ---------------------------------------------------------------------------
       
  1727 //
       
  1728 TInt CMmPhoneBookOperationWrite::HandleWriteMBIWriteResp(
       
  1729         TInt aStatus,
       
  1730         TUint8 aDetails )
       
  1731     {
       
  1732     TInt ret ( KErrNone );
       
  1733 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::HandleWriteMBIWriteResp");
       
  1734 OstTrace0( TRACE_FATAL, CMMPHONEBOOKOPERATIONWRITE_HANDLEWRITEMBIWRITERESP, "CMmPhoneBookOperationWrite::HandleWriteMBIWriteResp" );
       
  1735 
       
  1736     if( UICC_STATUS_OK  == aStatus )
       
  1737         {
       
  1738         // Check for Which operation this response was 
       
  1739         if ( KOperationDelete == iMBIOperation )
       
  1740             {
       
  1741             ret = KErrAccessDenied;
       
  1742             }
       
  1743         // Send Request to write entry on MBDN file        
       
  1744         iCurrentWritePhase = EPBWritePhase_complete;
       
  1745         }
       
  1746     else
       
  1747         {
       
  1748         if( UICC_SECURITY_CONDITIONS_NOT_SATISFIED == aDetails )
       
  1749             {
       
  1750             ret = KErrAccessDenied;
       
  1751             }
       
  1752         else
       
  1753             {
       
  1754             ret = KErrArgument;
       
  1755             }
       
  1756         }
       
  1757 
       
  1758 
       
  1759     return ret;
       
  1760     }
       
  1761 
       
  1762 // End of file