adaptationlayer/tsy/nokiatsy_dll/src/cmmphonebookoperationdelete.cpp
changeset 5 8ccc39f9d787
child 6 942573423a60
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:   ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 //  INCLUDE FILES
       
    19 #include <etelmm.h>
       
    20 #include <tisi.h>
       
    21 #include <pn_const.h>
       
    22 #include <ctsy/serviceapi/mmtsy_ipcdefs.h>
       
    23 #include "tsylogger.h"
       
    24 #include "cmmmessagerouter.h"
       
    25 #include "cmmphonebookoperationdelete.h"
       
    26 #include "osttracedefinitions.h"
       
    27 #ifdef OST_TRACE_COMPILER_IN_USE
       
    28 #include "cmmphonebookoperationdeletetraces.h"
       
    29 #endif
       
    30 
       
    31 // EXTERNAL DATA STRUCTURES
       
    32     // None
       
    33 
       
    34 // EXTERNAL FUNCTION PROTOTYPES
       
    35     // None
       
    36 
       
    37 // CONSTANTS
       
    38 
       
    39 
       
    40 // MACROS
       
    41     // None
       
    42 
       
    43 // LOCAL CONSTANTS AND MACROS
       
    44 const TUint8 KExtensionDataBytes( 13 );
       
    45 const TUint8 KEfAdnDataBytes( 14 );
       
    46 const TUint8 KMaxAlphaStringBytes( 241 );
       
    47 
       
    48 // MODULE DATA STRUCTURES
       
    49     // None
       
    50 
       
    51 // LOCAL FUNCTION PROTOTYPES
       
    52     // None
       
    53 
       
    54 // ==================== LOCAL FUNCTIONS =====================================
       
    55     // None
       
    56 
       
    57 
       
    58 // ================= MEMBER FUNCTIONS =======================================
       
    59 
       
    60 // ---------------------------------------------------------------------------
       
    61 // CMmPhoneBookOperationDelete::CMmPhoneBookOperationDelete
       
    62 // C++ default constructor can NOT contain any code, that
       
    63 // might leave.
       
    64 // ---------------------------------------------------------------------------
       
    65 //
       
    66 CMmPhoneBookOperationDelete::CMmPhoneBookOperationDelete()
       
    67     {
       
    68 TFLOGSTRING("TSY: CMmPhoneBookOperationDelete::CMmPhoneBookOperationDelete");
       
    69 OstTrace0( TRACE_NORMAL, CMmPhoneBookOperationDelete_CMmPhoneBookOperationDelete, "CMmPhoneBookOperationDelete::CMmPhoneBookOperationDelete" );
       
    70     }
       
    71 
       
    72 // ---------------------------------------------------------------------------
       
    73 // CMmPhoneBookOperationDelete::~CMmPhoneBookOperationDelete
       
    74 // C++ destructor.
       
    75 // ---------------------------------------------------------------------------
       
    76 //
       
    77 CMmPhoneBookOperationDelete::~CMmPhoneBookOperationDelete()
       
    78     {
       
    79 TFLOGSTRING("TSY: CMmPhoneBookOperationDelete::~CMmPhoneBookOperationDelete");
       
    80 OstTrace0( TRACE_NORMAL, DUP1_CMmPhoneBookOperationDelete_CMmPhoneBookOperationDelete, "CMmPhoneBookOperationDelete::~CMmPhoneBookOperationDelete" );
       
    81     }
       
    82 
       
    83 // ---------------------------------------------------------------------------
       
    84 // CMmPhoneBookOperationDelete::NewL
       
    85 // Creates a new CMmPhoneBookOperationDelete object instance.
       
    86 // Two-phased constructor.
       
    87 // ---------------------------------------------------------------------------
       
    88 
       
    89 CMmPhoneBookOperationDelete* CMmPhoneBookOperationDelete::NewL(
       
    90     CMmPhoneBookStoreMessHandler* aMmPhoneBookStoreMessHandler,
       
    91     CMmUiccMessHandler* aUiccMessHandler,
       
    92     const CMmDataPackage* aDataPackage ) // Data
       
    93     {
       
    94 TFLOGSTRING("TSY: CMmPhoneBookOperationDelete::NewL");
       
    95 OstTrace0( TRACE_NORMAL, CMmPhoneBookOperationDelete_NEWL, "CMmPhoneBookOperationDelete::NewL" );
       
    96 
       
    97     CMmPhoneBookOperationDelete* mmPhoneBookOperationDelete =
       
    98         new( ELeave ) CMmPhoneBookOperationDelete();
       
    99 
       
   100     const CPhoneBookDataPackage* phoneBookData =
       
   101         static_cast<const CPhoneBookDataPackage*>( aDataPackage );
       
   102 
       
   103     // Store phonebook name
       
   104     TName phonebookTypeName;
       
   105     phoneBookData->GetPhoneBookName( phonebookTypeName );
       
   106     mmPhoneBookOperationDelete->iPhoneBookTypeName = phonebookTypeName;
       
   107 
       
   108     mmPhoneBookOperationDelete->iMmPhoneBookStoreMessHandler =
       
   109         aMmPhoneBookStoreMessHandler;
       
   110 
       
   111     mmPhoneBookOperationDelete->iMmUiccMessHandler = aUiccMessHandler;
       
   112 
       
   113     mmPhoneBookOperationDelete->iNumOfExtensions = 0;
       
   114     mmPhoneBookOperationDelete->iFileIdExt = 0;
       
   115     mmPhoneBookOperationDelete->iIndex = 0;
       
   116     mmPhoneBookOperationDelete->iEntry.iEntryIndex = 0;
       
   117     mmPhoneBookOperationDelete->iEntry.iEntryPresent = EFalse;
       
   118     mmPhoneBookOperationDelete->iTransId = 0xFF;
       
   119     mmPhoneBookOperationDelete->iArrayIndex = 0;
       
   120     mmPhoneBookOperationDelete->iLocationFoundInPbList = EFalse;
       
   121     mmPhoneBookOperationDelete->iExtRecordArrayToBeDelete.Reset();
       
   122     mmPhoneBookOperationDelete->iNumOfEntries = 0;
       
   123 
       
   124     return mmPhoneBookOperationDelete;
       
   125     }
       
   126 
       
   127 // ---------------------------------------------------------------------------
       
   128 // TInt CMmPhoneBookOperationDelete::UICCCreateReq
       
   129 // Separate requests
       
   130 // ---------------------------------------------------------------------------
       
   131 //
       
   132 TInt CMmPhoneBookOperationDelete::UICCCreateReq(
       
   133     TInt aIpc,
       
   134     const CMmDataPackage* aDataPackage,
       
   135     TUint8 aTransId )
       
   136     {
       
   137 TFLOGSTRING2("TSY: CMmPhoneBookOperationDelete::UICCCreateReq Ipc: %d", aIpc);
       
   138 OstTraceExt1( TRACE_NORMAL, DUP1_CMmPhoneBookOperationDelete_UICCCREATEREQ, "CMmPhoneBookOperationDelete::UICCCreateReq;aIpc=%hd", aIpc );
       
   139 
       
   140     TInt ret( KErrNotSupported );
       
   141     iIpc = aIpc;
       
   142     iTransId = aTransId;
       
   143     // Convert phone book name to file id
       
   144     iFileId = ConvertToPBfileId( iPhoneBookTypeName, iFileIdExt );
       
   145     // Find location from internal array
       
   146     iArrayIndex = ConvertToConfArrayIndex( iFileId );
       
   147 
       
   148     const CPhoneBookDataPackage* phoneBookData(
       
   149         static_cast<const CPhoneBookDataPackage*>( aDataPackage ) );
       
   150 
       
   151     switch( aIpc )
       
   152         {
       
   153         case EMmTsyPhoneBookStoreDeleteIPC:
       
   154             {
       
   155             phoneBookData->UnPackData( iIndex );
       
   156 
       
   157             if( PB_MBDN_FID == iFileId )
       
   158                 {
       
   159                 // For MBDN PhoneBook first read MBI file 
       
   160                 // Check if the mailbox inidcation type is correct
       
   161                 if( iIndex <= iMmPhoneBookStoreMessHandler->
       
   162                         iPBStoreConf[iArrayIndex].iMbiRecLen )
       
   163                     {
       
   164                     iCurrentDeletePhase = EPBDeletePhase_Read_MBI_profile;
       
   165                     // read MBDN record number from MBI first record Profile number
       
   166                     ret = UiccPbReqReadMBI();
       
   167                     }
       
   168                 else
       
   169                     {
       
   170                     ret = KErrArgument;
       
   171                     }
       
   172                 }
       
   173             else
       
   174                 {
       
   175                 ret = UiccPbReqDelete();
       
   176                 }
       
   177             break;
       
   178             }
       
   179         case EMmTsyPhoneBookStoreDeleteAllIPC:
       
   180             {
       
   181             iNumOfEntries = iMmPhoneBookStoreMessHandler->
       
   182                 iPBStoreConf[iArrayIndex].iNoOfRecords;
       
   183             if ( iNumOfEntries )
       
   184                 {
       
   185                 // Start to delete entries from the last one
       
   186                 iIndex = iNumOfEntries;
       
   187                 ret = UiccPbReqDelete();
       
   188                 iNumOfEntries--;
       
   189                 }
       
   190             break;
       
   191             }
       
   192 #ifdef INTERNAL_RD_USIM_PHONEBOOK_GAS_AND_AAS
       
   193         case ECustomDeleteAlphaStringIPC:
       
   194             {
       
   195             break;
       
   196             }
       
   197 #endif // INTERNAL_RD_USIM_PHONEBOOK_GAS_AND_AAS
       
   198         default:
       
   199             {
       
   200 TFLOGSTRING2("TSY: CMmPhoneBookOperationDelete::CreateReq - Unknown IPC: %d", aIpc);
       
   201 OstTrace1( TRACE_NORMAL, DUP1_CMMPHONEBOOKOPERATIONDELETE_CREATEREQ, "CMmPhoneBookOperationDelete::CreateReq;aIpc=%d", aIpc );
       
   202             break;
       
   203             }
       
   204         }
       
   205     return ret;
       
   206     }
       
   207 
       
   208 
       
   209 // ---------------------------------------------------------------------------
       
   210 // CMmPhoneBookOperationDelete::UiccPbReqDelete
       
   211 // Constructs an ISI-message to read entry from SIM
       
   212 // ---------------------------------------------------------------------------
       
   213 //
       
   214 TInt CMmPhoneBookOperationDelete::UiccPbReqDelete()
       
   215     {
       
   216 TFLOGSTRING3("TSY: CMmPhoneBookOperationDelete::UiccPbReqDelete, iTransId:%d,index:%d", iTransId, iIndex);
       
   217 OstTraceExt2( TRACE_NORMAL, CMmPhoneBookOperationDelete_UICCPBREQWRITEL, "CMmPhoneBookOperationDelete::UiccPbReqDelete;iTransId=%hhu;iIndex=%hd", iTransId, iIndex );
       
   218 
       
   219     TInt ret( KErrNotSupported );
       
   220 
       
   221     switch ( iFileId )
       
   222         {
       
   223         case PB_ADN_FID:
       
   224         case PB_FDN_FID:
       
   225         case PB_MBDN_FID:
       
   226         case PB_VMBX_FID:
       
   227             {
       
   228             // Check if the location to be deleted is valid
       
   229             if( iIndex <= iMmPhoneBookStoreMessHandler->
       
   230                 iPBStoreConf[iArrayIndex].iNoOfRecords )
       
   231                 {
       
   232                 // Check if entry can be found in list
       
   233                 if( iMmPhoneBookStoreMessHandler->IndexCheckInPBList(
       
   234                     iIndex,
       
   235                     iArrayIndex,
       
   236                     iEntry ) )
       
   237                     {
       
   238                     iLocationFoundInPbList = ETrue;
       
   239                     // Check if there are extension records for this entry
       
   240                     iNumOfExtensions = iEntry.PBEntryExtRecord.Count();
       
   241                     // Entry is present and there is at least one extension
       
   242                     if( iEntry.iEntryPresent && iNumOfExtensions )
       
   243                         {
       
   244                         // Start to delete the last extension (write 'FF')
       
   245                         iCurrentDeletePhase = EPBDeletePhaseDeleteExtension;
       
   246                         TInt record(
       
   247                             iEntry.PBEntryExtRecord[iNumOfExtensions - 1] );
       
   248                         ret = UiccPbReqDeleteExt( record );
       
   249                         iNumOfExtensions--;
       
   250                         }
       
   251                     // Entry is not present -> fill by 'FF' just in case
       
   252                     // or entry is present but no extensions -> delete entry
       
   253                     else
       
   254                         {
       
   255                         iCurrentDeletePhase = EPBDeletePhaseDeleteEntry;
       
   256                         ret = UiccPbReqDeleteEntry();
       
   257                         }
       
   258                     }
       
   259                 // Index has not been read yet. At first it must be read to
       
   260                 // define number of possible extensions
       
   261                 else
       
   262                     {
       
   263                     iCurrentDeletePhase = EPBDeletePhaseReadEntry;
       
   264                     ret = UiccPbReqReadEntry();
       
   265                     }
       
   266                 }
       
   267             }
       
   268         default:
       
   269             {
       
   270             break;
       
   271             }
       
   272         }
       
   273     return ret;
       
   274     }
       
   275 
       
   276 
       
   277 // ---------------------------------------------------------------------------
       
   278 // CMmPhoneBookOperationDelete::UiccPBReqDeleteEntry
       
   279 // Constructs an ISI-message to Write main Entry data
       
   280 // ---------------------------------------------------------------------------
       
   281 //
       
   282 TInt CMmPhoneBookOperationDelete::UiccPbReqDeleteEntry()
       
   283     {
       
   284 TFLOGSTRING("TSY: CMmPhoneBookOperationDelete::UiccPBReqDeleteEntry");
       
   285 OstTrace0( TRACE_NORMAL, CMmPhoneBookOperationDelete_UICCPBREQWRITEENTRY, "CMmPhoneBookOperationDelete::UiccPBReqDeleteEntry" );
       
   286 
       
   287     TUiccWriteLinearFixed cmdParams;
       
   288     cmdParams.messHandlerPtr =
       
   289         static_cast<MUiccOperationBase*>( iMmPhoneBookStoreMessHandler );
       
   290     cmdParams.filePath.Append( static_cast<TUint8>( MF_FILE >> 8 ) );
       
   291     cmdParams.filePath.Append( static_cast<TUint8>( MF_FILE ) );
       
   292     cmdParams.filePath.Append( APPL_FILE_ID >> 8 );
       
   293     cmdParams.filePath.Append( APPL_FILE_ID );
       
   294     if( UICC_CARD_TYPE_UICC == iMmUiccMessHandler->GetCardType() )
       
   295         {
       
   296         cmdParams.filePath.Append( static_cast<TUint8>( DF_PHONEBOOK >> 8 ));
       
   297         cmdParams.filePath.Append( static_cast<TUint8>( DF_PHONEBOOK ));
       
   298         }
       
   299 
       
   300     cmdParams.serviceType = UICC_APPL_UPDATE_LINEAR_FIXED;
       
   301     cmdParams.fileId = iFileId;
       
   302     cmdParams.trId = static_cast<TUiccTrId>( iTransId );
       
   303 
       
   304     cmdParams.record = iIndex;
       
   305     // Buffer for data to be written, max size is 241 bytes for alpha
       
   306     // string and 14 mandatory data bytes. See 3GPP TS 51.011 V4.15.0
       
   307     // Chapter 10.5.1
       
   308     TBuf8<KEfAdnDataBytes+KMaxAlphaStringBytes> dataBuffer;
       
   309     // Check if alphastring exists
       
   310     TUint16 alphaStringLength( iMmPhoneBookStoreMessHandler->
       
   311         iPBStoreConf[ iArrayIndex ].iAlphaStringlength );
       
   312     // Filel buffer (alpha string bytes + mandatory bytes) by 'FF'
       
   313     dataBuffer.AppendFill( 0xFF, alphaStringLength + KEfAdnDataBytes );
       
   314     cmdParams.fileData.Append( dataBuffer );
       
   315     return iMmPhoneBookStoreMessHandler->UiccMessHandler()->
       
   316         CreateUiccApplCmdReq( cmdParams );
       
   317     }
       
   318 
       
   319 
       
   320 // ---------------------------------------------------------------------------
       
   321 // CMmPhoneBookOperationDelete::UiccPbReqDeleteExt
       
   322 // Constructs an ISI-message to delete extension record
       
   323 // ---------------------------------------------------------------------------
       
   324 //
       
   325 TInt CMmPhoneBookOperationDelete::UiccPbReqDeleteExt( TInt aExtRecordNum )
       
   326     {
       
   327 TFLOGSTRING("TSY: CMmPhoneBookOperationDelete::UiccPbReqDeleteExt");
       
   328 OstTrace0( TRACE_NORMAL, CMmPhoneBookOperationDelete_UICCPBWRITEEXT, "CMmPhoneBookOperationDelete::UiccPbReqDeleteExt" );
       
   329 
       
   330     TUiccWriteLinearFixed cmdParams;
       
   331     cmdParams.messHandlerPtr =
       
   332         static_cast<MUiccOperationBase*>( iMmPhoneBookStoreMessHandler );
       
   333     cmdParams.filePath.Append( static_cast<TUint8>( MF_FILE >> 8 ));
       
   334     cmdParams.filePath.Append( static_cast<TUint8>( MF_FILE ));
       
   335     cmdParams.filePath.Append( APPL_FILE_ID >> 8);
       
   336     cmdParams.filePath.Append( APPL_FILE_ID);
       
   337 
       
   338     if( UICC_CARD_TYPE_UICC == iMmUiccMessHandler->GetCardType() )
       
   339         {
       
   340         cmdParams.filePath.Append( static_cast<TUint8>( DF_PHONEBOOK >> 8 ));
       
   341         cmdParams.filePath.Append( static_cast<TUint8>( DF_PHONEBOOK ));
       
   342         }
       
   343 
       
   344     cmdParams.fileId = iFileIdExt;
       
   345     cmdParams.serviceType = UICC_APPL_UPDATE_LINEAR_FIXED;
       
   346     cmdParams.trId = static_cast<TUiccTrId>( iTransId );
       
   347     cmdParams.record = aExtRecordNum;
       
   348 
       
   349     // File Data
       
   350     TBuf8<KExtensionDataBytes>extFileData;
       
   351     extFileData.Append( 0x00 ); // Type of record ( 0x00 == unknown )
       
   352     // Rest of data is set by 'FF'
       
   353     extFileData.AppendFill( 0xFF, ( KExtensionDataBytes - 1 ) ); 
       
   354     cmdParams.fileData.Append( extFileData );
       
   355 
       
   356     return iMmPhoneBookStoreMessHandler->UiccMessHandler()->
       
   357         CreateUiccApplCmdReq( cmdParams );
       
   358     }
       
   359 
       
   360 
       
   361 // ---------------------------------------------------------------------------
       
   362 // CMmPhoneBookOperationDelete::UiccPbReqReadEntry
       
   363 // Constructs an ISI-message to read main entry data
       
   364 // ---------------------------------------------------------------------------
       
   365 //
       
   366 TInt CMmPhoneBookOperationDelete::UiccPbReqReadEntry()
       
   367     {
       
   368 TFLOGSTRING("TSY: CMmPhoneBookOperationDelete::UiccPBReqDeleteEntry");
       
   369 OstTrace0( TRACE_NORMAL, CMMPHONEBOOKOPERATIONDELETE_UICCPBREQREADENTRY, "CMmPhoneBookOperationDelete::UiccPbReqReadEntry" );
       
   370 
       
   371     TUiccReadLinearFixed cmdParams;
       
   372     cmdParams.messHandlerPtr =
       
   373         static_cast<MUiccOperationBase*>( iMmPhoneBookStoreMessHandler );
       
   374     cmdParams.filePath.Append( static_cast<TUint8>( MF_FILE >> 8 ) );
       
   375     cmdParams.filePath.Append( static_cast<TUint8>( MF_FILE ) );
       
   376     cmdParams.filePath.Append( APPL_FILE_ID >> 8 );
       
   377     cmdParams.filePath.Append( APPL_FILE_ID );
       
   378     if( UICC_CARD_TYPE_UICC == iMmUiccMessHandler->GetCardType() )
       
   379         {
       
   380         cmdParams.filePath.Append( static_cast<TUint8>( DF_PHONEBOOK >> 8 ));
       
   381         cmdParams.filePath.Append( static_cast<TUint8>( DF_PHONEBOOK ));
       
   382         }
       
   383     
       
   384     cmdParams.serviceType = UICC_APPL_READ_LINEAR_FIXED;
       
   385     cmdParams.fileId = iFileId;
       
   386     cmdParams.trId = static_cast<TUiccTrId>( iTransId );
       
   387     cmdParams.record = iIndex;
       
   388     
       
   389     return iMmPhoneBookStoreMessHandler->UiccMessHandler()->
       
   390         CreateUiccApplCmdReq( cmdParams );
       
   391     }
       
   392 
       
   393 
       
   394 // ---------------------------------------------------------------------------
       
   395 // CMmPhoneBookOperationDelete::UiccPbReqReadMBI
       
   396 // Constructs an ISI-message to Read MBI profile from first record 
       
   397 // ---------------------------------------------------------------------------
       
   398 //
       
   399 TInt CMmPhoneBookOperationDelete::UiccPbReqReadMBI( )
       
   400     {
       
   401 TFLOGSTRING("TSY: CMmPhoneBookOperationDelete::UiccPbReqReadMBI");
       
   402 OstTrace0( TRACE_NORMAL, CMMPHONEBOOKOPERATIONDELETE_UICCPBREQREADMBI, "CMmPhoneBookOperationDelete::UiccPbReqReadMBI" );
       
   403         
       
   404         TInt ret ( KErrNone );
       
   405         TUiccReadLinearFixed cmdParams;
       
   406         cmdParams.messHandlerPtr  = static_cast<MUiccOperationBase*> 
       
   407                                    ( iMmPhoneBookStoreMessHandler );
       
   408         cmdParams.filePath.Append( static_cast<TUint8>( MF_FILE >> 8 ));
       
   409         cmdParams.filePath.Append( static_cast<TUint8>( MF_FILE ));
       
   410         cmdParams.filePath.Append( APPL_FILE_ID>>8);
       
   411         cmdParams.filePath.Append( APPL_FILE_ID);
       
   412         
       
   413         if( UICC_CARD_TYPE_UICC == iMmUiccMessHandler->GetCardType() )
       
   414             {
       
   415             cmdParams.filePath.Append( static_cast<TUint8>( DF_PHONEBOOK >> 8 ));
       
   416             cmdParams.filePath.Append( static_cast<TUint8>( DF_PHONEBOOK ));
       
   417             }
       
   418 
       
   419         cmdParams.trId = static_cast<TUiccTrId>( iTransId );
       
   420         cmdParams.fileId = PB_MBI_FID;
       
   421         cmdParams.serviceType =  UICC_APPL_READ_LINEAR_FIXED ;
       
   422         cmdParams.dataAmount = 1;
       
   423         cmdParams.dataOffset = iIndex;
       
   424         cmdParams.record = 1;   // only first profile number is supported
       
   425         
       
   426         
       
   427         if( KErrNone == ret )
       
   428             {
       
   429             ret = iMmPhoneBookStoreMessHandler->UiccMessHandler()->
       
   430                 CreateUiccApplCmdReq( cmdParams );
       
   431             }
       
   432         return ret;
       
   433     }
       
   434 
       
   435 
       
   436 // ---------------------------------------------------------------------------
       
   437 // CMmPhoneBookOperationDelete::UiccPBReqDeleteMBIProfile
       
   438 // Send Request for MBBI Profile Write
       
   439 // ---------------------------------------------------------------------------
       
   440 //
       
   441 TInt CMmPhoneBookOperationDelete::UiccPBReqDeleteMBIProfile()
       
   442     {
       
   443 TFLOGSTRING("TSY: CMmPhoneBookOperationDelete::UiccPBReqWriteMBIProfile");
       
   444 OstTrace0( TRACE_NORMAL, CMMPHONEBOOKOPERATIONDELETE_UICCPBREQDELETEMBIPROFILE, "CMmPhoneBookOperationDelete::UiccPBReqDeleteMBIProfile" );
       
   445 
       
   446     TInt ret ( KErrNone );
       
   447     
       
   448     TUiccWriteLinearFixed cmdParams;
       
   449     cmdParams.messHandlerPtr  = static_cast<MUiccOperationBase*> 
       
   450                                ( iMmPhoneBookStoreMessHandler );
       
   451     cmdParams.filePath.Append( static_cast<TUint8>( MF_FILE >> 8 ));
       
   452     cmdParams.filePath.Append( static_cast<TUint8>( MF_FILE ));
       
   453     cmdParams.filePath.Append( APPL_FILE_ID>>8);
       
   454     cmdParams.filePath.Append( APPL_FILE_ID);
       
   455     if( UICC_CARD_TYPE_UICC == iMmUiccMessHandler->GetCardType() )
       
   456         {
       
   457         cmdParams.filePath.Append( static_cast<TUint8>( DF_PHONEBOOK >> 8 ));
       
   458         cmdParams.filePath.Append( static_cast<TUint8>( DF_PHONEBOOK ));
       
   459         }
       
   460     cmdParams.trId = static_cast<TUiccTrId>( iTransId );
       
   461     cmdParams.fileId = PB_MBI_FID;
       
   462     cmdParams.serviceType =  UICC_APPL_READ_LINEAR_FIXED ;
       
   463     cmdParams.dataAmount = 1;
       
   464     cmdParams.dataOffset = iIndex;
       
   465     cmdParams.record = 1;   // only first profile number is supported
       
   466 
       
   467     // Append FileData needs to be write
       
   468     cmdParams.fileData.Append( 0 );
       
   469     
       
   470     
       
   471     if( KErrNone == ret )
       
   472         {
       
   473         ret = iMmPhoneBookStoreMessHandler->UiccMessHandler()->
       
   474             CreateUiccApplCmdReq( cmdParams );
       
   475         }
       
   476 
       
   477     return ret;
       
   478     
       
   479     }
       
   480 
       
   481 // ---------------------------------------------------------------------------
       
   482 // CMmPhoneBookOperationDelete::HandleReadEntryResp
       
   483 // Handles phonebook entry data
       
   484 // ---------------------------------------------------------------------------
       
   485 //
       
   486 TInt CMmPhoneBookOperationDelete::HandleReadEntryResp(
       
   487     const TDesC8& aFileData )
       
   488     {
       
   489 TFLOGSTRING("TSY: CMmPhoneBookOperationDelete::HandleReadEntryResp");
       
   490 OstTrace0( TRACE_NORMAL, CMMPHONEBOOKOPERATIONDELETE_HANDLEREADENTRYRESP, "CMmPhoneBookOperationDelete::HandleReadEntryResp" );
       
   491 
       
   492     TInt ret( KErrNotFound );
       
   493 
       
   494     // Check if alphastring exists
       
   495     TUint16 alphaStringLength( iMmPhoneBookStoreMessHandler->
       
   496         iPBStoreConf[ iArrayIndex ].iAlphaStringlength );
       
   497 
       
   498     // File contains possible alpha string and 14 mandatory bytes
       
   499     TUint8 index( alphaStringLength + KEfAdnDataBytes - 1 );
       
   500 
       
   501     if ( index < aFileData.Length() )
       
   502         {
       
   503         TUint8 extRecord( aFileData[index] );
       
   504         // Check if this entry has extension records
       
   505         if ( 0xFF == extRecord ) // No extension records, just delete entry
       
   506             {
       
   507             iCurrentDeletePhase = EPBDeletePhaseDeleteEntry;
       
   508             ret = UiccPbReqDeleteEntry();
       
   509             }
       
   510         else // Start to read extensions
       
   511             {
       
   512             iExtRecordArrayToBeDelete.Append( extRecord ); // Store records
       
   513             iCurrentDeletePhase = EPBDeletePhaseReadExtensions;
       
   514             ret = UiccPbReqReadExt( extRecord );
       
   515             }
       
   516         }
       
   517     return ret;
       
   518     }
       
   519 
       
   520 
       
   521 // ---------------------------------------------------------------------------
       
   522 // CMmPhoneBookOperationDelete::UiccPbReqDeleteExt
       
   523 // Constructs an ISI-message to delete extension record
       
   524 // ---------------------------------------------------------------------------
       
   525 //
       
   526 TInt CMmPhoneBookOperationDelete::UiccPbReqReadExt( TUint8 aExtRecordNum )
       
   527     {
       
   528 TFLOGSTRING("TSY: CMmPhoneBookOperationDelete::UiccPbReqDeleteExt");
       
   529 OstTrace0( TRACE_NORMAL, CMMPHONEBOOKOPERATIONDELETE_UICCPBREQREADEXT, "CMmPhoneBookOperationDelete::UiccPbReqReadExt" );
       
   530 
       
   531     TUiccReadLinearFixed cmdParams;
       
   532     cmdParams.messHandlerPtr =
       
   533         static_cast<MUiccOperationBase*>( iMmPhoneBookStoreMessHandler );
       
   534     cmdParams.filePath.Append( static_cast<TUint8>( MF_FILE >> 8 ));
       
   535     cmdParams.filePath.Append( static_cast<TUint8>( MF_FILE ));
       
   536     cmdParams.filePath.Append( APPL_FILE_ID >> 8);
       
   537     cmdParams.filePath.Append( APPL_FILE_ID);
       
   538     if( UICC_CARD_TYPE_UICC == iMmUiccMessHandler->GetCardType() )
       
   539         {
       
   540         cmdParams.filePath.Append( static_cast<TUint8>( DF_PHONEBOOK >> 8 ));
       
   541         cmdParams.filePath.Append( static_cast<TUint8>( DF_PHONEBOOK ));
       
   542         }
       
   543 
       
   544     cmdParams.fileId = iFileIdExt;
       
   545     cmdParams.serviceType = UICC_APPL_READ_LINEAR_FIXED;
       
   546     cmdParams.trId = static_cast<TUiccTrId>( iTransId );
       
   547     cmdParams.record = aExtRecordNum;
       
   548 
       
   549     return iMmPhoneBookStoreMessHandler->UiccMessHandler()->
       
   550         CreateUiccApplCmdReq( cmdParams );
       
   551     }
       
   552 
       
   553 
       
   554 // ---------------------------------------------------------------------------
       
   555 // CMmPhoneBookOperationDelete::HandleReadExtResp
       
   556 // Handles phonebook entry data
       
   557 // ---------------------------------------------------------------------------
       
   558 //
       
   559 TInt CMmPhoneBookOperationDelete::HandleReadExtResp(
       
   560     const TDesC8& aFileData )
       
   561     {
       
   562 TFLOGSTRING("TSY: CMmPhoneBookOperationDelete::HandleReadExtResp");
       
   563 OstTrace0( TRACE_NORMAL, CMMPHONEBOOKOPERATIONDELETE_HANDLEREADEXTRESP, "CMmPhoneBookOperationDelete::HandleReadExtResp" );
       
   564 
       
   565     TInt ret( KErrNotFound );
       
   566 
       
   567     // Read next record
       
   568     if ( KExtensionDataBytes == aFileData.Length() )
       
   569         {
       
   570         // Next record is located in the last byte
       
   571         TUint8 nextRecord( aFileData[KExtensionDataBytes - 1] );
       
   572         if ( 0xFF == nextRecord ) // No more extension records left
       
   573             {
       
   574             iCurrentDeletePhase = EPBDeletePhaseDeleteExtension;
       
   575             iNumOfExtensions = iExtRecordArrayToBeDelete.Count();
       
   576             if ( iNumOfExtensions )
       
   577                 {
       
   578                 // Start to delete extensions in reverse order
       
   579                 ret = UiccPbReqDeleteExt(
       
   580                     iExtRecordArrayToBeDelete[iNumOfExtensions - 1] );
       
   581                 iExtRecordArrayToBeDelete.Remove( iNumOfExtensions - 1 );
       
   582                 iExtRecordArrayToBeDelete.Compress();
       
   583                 }
       
   584             }
       
   585         else // Read the next extension
       
   586             {
       
   587             iExtRecordArrayToBeDelete.Append( nextRecord );
       
   588             ret = UiccPbReqReadExt( nextRecord );
       
   589             }
       
   590         }
       
   591 
       
   592     return ret;
       
   593     }
       
   594 
       
   595 
       
   596 // ---------------------------------------------------------------------------
       
   597 // TBool CMmPhoneBookOperationDelete::HandleWriteMBIReadResp
       
   598 // Handle write response for MBI profile read
       
   599 // ---------------------------------------------------------------------------
       
   600 //
       
   601 TInt CMmPhoneBookOperationDelete::HandleWriteMBIReadResp(
       
   602         TInt aStatus,
       
   603         TUint8 aDetails,
       
   604         const TDesC8 &aFileData ) 
       
   605     {
       
   606     TInt ret ( KErrNone );
       
   607 TFLOGSTRING("TSY: CMmPhoneBookOperationDelete::HandleWriteMBIReadResp");
       
   608 OstTrace0( TRACE_NORMAL, CMMPHONEBOOKOPERATIONDELETE_HANDLEWRITEMBIREADRESP, "CMmPhoneBookOperationDelete::HandleWriteMBIReadResp" );
       
   609 
       
   610     // Store MBI Profile
       
   611     iMBIProfileType = iIndex;
       
   612     if( UICC_STATUS_OK  == aStatus )
       
   613         {
       
   614         iIndex = aFileData[0];
       
   615         ret = UiccPbReqDelete();
       
   616         }
       
   617     else
       
   618         {
       
   619         if( UICC_SECURITY_CONDITIONS_NOT_SATISFIED == aDetails )
       
   620             {
       
   621             ret = KErrAccessDenied;
       
   622             }
       
   623         else
       
   624             {
       
   625             ret = KErrArgument;
       
   626             }
       
   627         }
       
   628     return ret;
       
   629     }
       
   630 
       
   631 
       
   632 
       
   633 // ---------------------------------------------------------------------------
       
   634 // CMmPhoneBookOperationDelete::HandleUICCPbRespL
       
   635 // Separate response
       
   636 // ---------------------------------------------------------------------------
       
   637 //
       
   638 TBool CMmPhoneBookOperationDelete::HandleUICCPbRespL(
       
   639     TInt aStatus,
       
   640     TUint8 aDetails,
       
   641     const TDesC8& aFileData,
       
   642     TInt /*aTransId*/ )
       
   643     {
       
   644 TFLOGSTRING("TSY: CMmPhoneBookOperationDelete::HandleUICCPbRespL");
       
   645 OstTrace0( TRACE_NORMAL, CMmPhoneBookOperationDelete_HANDLEUICCPBRESPL, "CMmPhoneBookOperationDelete::HandleUICCPbRespL" );
       
   646 
       
   647     TInt ret( KErrNone );
       
   648     TBool complete( EFalse );
       
   649 
       
   650     TInt maxNumLength( 0 );
       
   651     TInt location( 0 );
       
   652 
       
   653     if ( UICC_STATUS_OK == aStatus )
       
   654         {
       
   655         switch ( iCurrentDeletePhase )
       
   656             {
       
   657             case EPBDeletePhaseReadExtensions:
       
   658                 {
       
   659                 ret = HandleReadExtResp( aFileData );
       
   660                 break;
       
   661                 }
       
   662             case EPBDeletePhaseReadEntry:
       
   663                 {
       
   664                 ret = HandleReadEntryResp( aFileData );
       
   665                 break;
       
   666                 }
       
   667             case EPBDeletePhaseDeleteExtension:
       
   668                 {
       
   669                 // Entry was read earlier and extension records saved
       
   670                 if ( iLocationFoundInPbList )
       
   671                     {
       
   672                     // Check if there are extensions left, in that case
       
   673                     // continue deleting extensions
       
   674                     if ( iNumOfExtensions )
       
   675                         {
       
   676                         ret = UiccPbReqDeleteExt(
       
   677                             iEntry.PBEntryExtRecord[iNumOfExtensions-1] );
       
   678                         iNumOfExtensions--;
       
   679                         }
       
   680                     // All extensions were deleted, next delete the main entry
       
   681                     else
       
   682                         {
       
   683                         iCurrentDeletePhase = EPBDeletePhaseDeleteEntry;
       
   684                         ret = UiccPbReqDeleteEntry();
       
   685                         }
       
   686                     }
       
   687                 // Extensions were read from SIM and saved to internal buffer
       
   688                 else
       
   689                     {
       
   690                     iNumOfExtensions = iExtRecordArrayToBeDelete.Count();
       
   691                     if ( iNumOfExtensions )
       
   692                         {
       
   693                         ret = UiccPbReqDeleteExt(
       
   694                             iExtRecordArrayToBeDelete[iNumOfExtensions - 1] );
       
   695                         iExtRecordArrayToBeDelete.Remove(
       
   696                             iNumOfExtensions - 1 );
       
   697                         iExtRecordArrayToBeDelete.Compress();
       
   698                         }
       
   699                     else // It is time to delete the main entry
       
   700                         {
       
   701                         iCurrentDeletePhase = EPBDeletePhaseDeleteEntry;
       
   702                         ret = UiccPbReqDeleteEntry();
       
   703                         }
       
   704                     }
       
   705                 break;
       
   706                 }
       
   707             case EPBDeletePhaseDeleteEntry:
       
   708                 {
       
   709                 if ( iLocationFoundInPbList ) // Entry already in list, reset
       
   710                     {
       
   711                     iMmPhoneBookStoreMessHandler->ResetEntryInPhoneBookList(
       
   712                         iArrayIndex,
       
   713                         iIndex );
       
   714                     }
       
   715                 else
       
   716                     {
       
   717                     // This location has not been read earlier, add it to list
       
   718                     TPBEntry* storeEntry = new ( ELeave ) TPBEntry();
       
   719                     storeEntry->iEntryPresent = EFalse;
       
   720                     storeEntry->iEntryIndex = iIndex;
       
   721                     storeEntry->PBEntryExtRecord.Reset();
       
   722                     iMmPhoneBookStoreMessHandler->StoreEntryToPhoneBookList(
       
   723                         storeEntry,
       
   724                         iArrayIndex );
       
   725                     }
       
   726 
       
   727                 // If it is MBDN Phone Book then update MBI File also
       
   728                 if( PB_MBDN_FID == iFileId)
       
   729                     {
       
   730                     // Start Writing MBI file
       
   731                     iCurrentDeletePhase = EPBDeletePhase_delete_MBI_profile;
       
   732                     ret = UiccPBReqDeleteMBIProfile();
       
   733                     }
       
   734                 else
       
   735                     {
       
   736                         // Ready for complete
       
   737                         complete = ETrue;
       
   738                         maxNumLength = iMmPhoneBookStoreMessHandler->
       
   739                             iPBStoreConf[iArrayIndex].iNumlength;
       
   740                     if ( EMmTsyPhoneBookStoreDeleteAllIPC == iIpc &&
       
   741                         iNumOfEntries )
       
   742                         {
       
   743                         // Continue deleting entries
       
   744                         iIndex = iNumOfEntries;
       
   745                         ret = UiccPbReqDelete();
       
   746                         iNumOfEntries--;
       
   747                         }
       
   748                     else
       
   749                         {
       
   750                         // Ready for complete
       
   751                         complete = ETrue;
       
   752                         maxNumLength = iMmPhoneBookStoreMessHandler->
       
   753                             iPBStoreConf[iArrayIndex].iNumlength;
       
   754                         // In case of delete all location is 0
       
   755                         if ( EMmTsyPhoneBookStoreDeleteIPC == iIpc )
       
   756                             {
       
   757                             location = iIndex;
       
   758                             }
       
   759                         }
       
   760                     }
       
   761                 break;
       
   762                 }
       
   763             case EPBDeletePhase_Read_MBI_profile:
       
   764                 {
       
   765                 ret = HandleWriteMBIReadResp( aStatus, aDetails, aFileData );
       
   766                 break;
       
   767                 }
       
   768             case EPBDeletePhase_delete_MBI_profile:
       
   769                 {
       
   770                 if( UICC_STATUS_OK  != aStatus )
       
   771                     {
       
   772                     if( UICC_SECURITY_CONDITIONS_NOT_SATISFIED == aDetails )
       
   773                         {
       
   774                         ret = KErrAccessDenied;
       
   775                         }
       
   776                     else
       
   777                         {
       
   778                         ret = KErrArgument;
       
   779                         }
       
   780                     }
       
   781                 else
       
   782                     {
       
   783                     // Ready for complete
       
   784                     complete = ETrue;
       
   785                     maxNumLength = iMmPhoneBookStoreMessHandler->
       
   786                         iPBStoreConf[iArrayIndex].iNumlength;
       
   787                     location = iMBIProfileType;
       
   788                     }
       
   789                 break;
       
   790                 }
       
   791             default:
       
   792                 {
       
   793 TFLOGSTRING("TSY: CMmPhoneBookOperationWrite::HandleSimPbRespL - No such delete operation phase supported ");
       
   794 OstTrace0( TRACE_NORMAL, DUP1_CMMPHONEBOOKOPERATIONDELETE_HANDLEUICCPBRESPL, "CMmPhoneBookOperationDelete::HandleUICCPbRespL- No such delete operation phase supported" );
       
   795                 break;
       
   796                 }
       
   797             } // End of switch( iCurrentDeletePhase )
       
   798         } // End of if ( UICC_STATUS_OK == aStatus )
       
   799     else // Request failed, complete and remove operation
       
   800         {
       
   801 TFLOGSTRING2("TSY: CMmPhoneBookOperationDelete::HandleUICCPbRespL, Request failed, ret = %d", aStatus );
       
   802 OstTrace1( TRACE_NORMAL, CMMPHONEBOOKOPERATIONDELETE_HANDLEUICCPBRESPL, "CMmPhoneBookOperationDelete::HandleUICCPbRespL;aStatus=%d", aStatus );
       
   803         complete = ETrue;
       
   804         ret = KErrNotFound;
       
   805         }
       
   806 
       
   807     // Error occured in some phase, stop operation and complete
       
   808     if ( ret != KErrNone )
       
   809         {
       
   810         complete = ETrue;
       
   811         }
       
   812 
       
   813     if ( complete )
       
   814         {
       
   815         TPBEntryInfo pbEntryInfo;
       
   816         pbEntryInfo.iMaxNumLength = maxNumLength;
       
   817         pbEntryInfo.iLocation = location;
       
   818 
       
   819         CPhoneBookDataPackage phoneBookData;
       
   820         phoneBookData.SetPhoneBookName( iPhoneBookTypeName );
       
   821         phoneBookData.PackData( &pbEntryInfo );
       
   822 
       
   823         iMmPhoneBookStoreMessHandler->MessageRouter()->Complete(
       
   824             iIpc,
       
   825             &phoneBookData,
       
   826             ret );
       
   827         }
       
   828 
       
   829     return complete;
       
   830     }
       
   831 
       
   832 
       
   833 // End of file