phoneclientserver/phoneclient/Src/UssdWrapper/CPhCltUssdImp.cpp
changeset 46 2fa1fa551b0b
parent 42 35488577e233
child 48 78df25012fda
equal deleted inserted replaced
42:35488577e233 46:2fa1fa551b0b
     1 /*
       
     2 * Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Interface for sending messages.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "cphcltussdimp.h" 
       
    22 #include "cphcltussdrequesthandler.h" 
       
    23 #include "phcltclientserver.h" 
       
    24 #include <phclttypes.h> 
       
    25 
       
    26 #include <etelmm.h>
       
    27 #include <f32file.h>
       
    28 #include <charconv.h>
       
    29 #include <gsmuelem.h>
       
    30 #include <coemain.h>  
       
    31 //#include <phoneclient.rsg> 
       
    32 #include <exterror.h>
       
    33 
       
    34 #include <gsmerror.h>
       
    35 #include <etelsat.h>
       
    36 
       
    37 #include "mphcltussdnotecontrollercallback.h" 
       
    38 #include "cphcltussdnotecontroller.h" 
       
    39 #include "cphcltussdcommonconstant.h"
       
    40 #include "tflogger.h"
       
    41 // CONSTANTS
       
    42 
       
    43 const TUint8 KPhCltUssdDcsDefaultAlphabet = 0x0f; // 00001111
       
    44                        
       
    45 const TUint8 KPhCltUssdDcsAlphabetDefaultPrecededLanguage = 0x10; // 00010000 
       
    46 const TUint8 KPhCltUssdDcsAlphabetDefaultPrecededLanguageSkipChars3 = 3;
       
    47 const TUint8 KPhCltUssdDcsAlphabetDefaultPrecededLanguageSkipChars2 = 2;
       
    48 const TUint8 KPhCltUssdDcsAlphabetDefaultPrecededLanguageStartBit = 5;
       
    49 
       
    50 const TUint8 KPhCltUssdDcsAlphabetUCS2PrecededLanguage = 0x11;   // 00010001
       
    51 const TUint8 KPhCltUssdDcsAlphabetUCS2PrecededLanguageSkipChars = 2;
       
    52 
       
    53 const TUint8 KPhCltUssdDcsGeneralInformationMask = 0xc0;         // 11000000
       
    54 const TUint8 KPhCltUssdDcsGeneralInformation = 0x40;             // 01xxxxxx
       
    55 const TUint8 KPhCltUssdDcsGeneralInformationCompressed = 0x20;   // xx1xxxxx
       
    56 const TUint8 KPhCltUssdDcsGeneralInformationSimMask = 0x13;      // 00010011
       
    57 const TUint8 KPhCltUssdDcsGeneralInformationSim = 0x12;          // xxx1xx10
       
    58 const TUint8 KPhCltUssdDcsGeneralInformationAlphabetMask = 0x0c; // 00001100
       
    59 const TUint8 KPhCltUssdDcsGeneralInformationAlphabet8Bit = 0x04; // xxxx01xx 
       
    60 const TUint8 KPhCltUssdDcsGeneralInformationAlphabetUCS2 = 0x08; // xxxx10xx 
       
    61 
       
    62 const TUint8 KPhCltUssdDcsMessageHandlingAlphabetMask = 0xf4;    // 11110100
       
    63 const TUint8 KPhCltUssdDcsMessageHandlingAlphabet8Bit = 0xf4;    // 1111x1xx 
       
    64 
       
    65 const TUint8 KPhCltUssdCarriageReturn = 0x0d;
       
    66 const TUint8 KPhCltUssdDcsNotSet  = 0x00; // not set
       
    67 
       
    68 
       
    69 // ============================= LOCAL FUNCTIONS ===============================
       
    70 
       
    71 // CLASS DECLARATION
       
    72 
       
    73 #ifndef TPHCLTUSSDALPHABETPACKER_H
       
    74 #define TPHCLTUSSDALPHABETPACKER_H
       
    75 
       
    76 /**
       
    77 * Class for packing the Ussd string.
       
    78 */
       
    79 class TPhCltUssdAlphabetPacker
       
    80     {
       
    81     public:  // Constructors and destructor
       
    82 
       
    83         /**
       
    84         * Constructor.
       
    85         *
       
    86         * @param aAlphabet The used Data Coding Scheme.
       
    87         * @param aIsBinary Is the data binary.
       
    88         * @param aStartBit The start bit of the conversion.
       
    89         */
       
    90         TPhCltUssdAlphabetPacker(
       
    91             TSmsDataCodingScheme::TSmsAlphabet aAlphabet,
       
    92             TBool aIsBinary,
       
    93             TInt aStartBit );
       
    94 
       
    95     public:  // New functions
       
    96 
       
    97         /**
       
    98         * Pack the given string to the desired coding scheme.
       
    99         *
       
   100         * @param aOut The output string of packing
       
   101         * @param aIn The string to be packed.
       
   102         * @return The number of octets used.
       
   103         */
       
   104         TInt PackL(TDes8& aOut,const TDesC8& aIn);
       
   105 
       
   106         /**
       
   107         * Convert and pack the given string to the desired coding scheme.
       
   108         *
       
   109         * @param aCharacterSetConverter The character converter.
       
   110         * @param aFs Reference to file system.
       
   111         * @param aOut The output string of packing
       
   112         * @param aIn The string to be packed.
       
   113         * @param aConvertedNumUDUnits The number of converted units.
       
   114         * @return The number of octets used.
       
   115         */
       
   116         TInt ConvertAndPackL(
       
   117             CCnvCharacterSetConverter& aCharacterSetConverter,
       
   118             RFs& aFs,
       
   119             TDes8& aOut,
       
   120             const TDesC& aIn,
       
   121             TInt& aConvertedNumUDUnits );
       
   122 
       
   123         /**
       
   124         * Return information of how many octets are required when
       
   125         * the aNumUDUnits number of characters is packed.
       
   126         *
       
   127         * @param aNumUDUnits The number of characters to be packed.
       
   128         * @return The number of octets required.
       
   129         */
       
   130         TInt PackedOctetsRequiredL( TInt aNumUDUnits ) const;
       
   131         
       
   132     private:
       
   133 
       
   134         // Private helper methods
       
   135         TInt ElementSizeInBitsL() const;
       
   136         
       
   137     private:    // Data
       
   138 
       
   139         // The Data Coding Scheme of the conversion.
       
   140         TSmsDataCodingScheme::TSmsAlphabet iAlphabet;
       
   141 
       
   142         // Information is the given descriptor binary.
       
   143         TBool iIsBinary;
       
   144 
       
   145         // The start bit of the conversion.
       
   146         TInt iStartBit;
       
   147     };
       
   148 
       
   149 #endif // TPHCLTUSSDALPHABETPACKER_H
       
   150 
       
   151 
       
   152 // -----------------------------------------------------------------------------
       
   153 // TPhCltUssdAlphabetPacker::TPhCltUssdAlphabetPacker
       
   154 //
       
   155 // -----------------------------------------------------------------------------
       
   156 //
       
   157 TPhCltUssdAlphabetPacker::TPhCltUssdAlphabetPacker(
       
   158     TSmsDataCodingScheme::TSmsAlphabet aAlphabet,
       
   159     TBool aIsBinary,
       
   160     TInt aStartBit)
       
   161     : iAlphabet( aAlphabet ),
       
   162       iIsBinary( aIsBinary ),
       
   163       iStartBit( aStartBit )
       
   164     {
       
   165     }
       
   166 
       
   167 
       
   168 // -----------------------------------------------------------------------------
       
   169 // TPhCltUssdAlphabetPacker::PackL
       
   170 //
       
   171 // -----------------------------------------------------------------------------
       
   172 //
       
   173 TInt TPhCltUssdAlphabetPacker::PackL( TDes8& aOut,const TDesC8& aIn )
       
   174     {
       
   175     // Ensure we've got the right length
       
   176     TInt packedOctetsRequired = PackedOctetsRequiredL( aIn.Length() );
       
   177     if ( packedOctetsRequired > ( aOut.MaxLength() - aOut.Length() ) )
       
   178         {
       
   179         User::Leave( KErrOverflow );
       
   180         }
       
   181 
       
   182     // Do the conversion
       
   183     TInt elementSizeInBits = ElementSizeInBitsL();
       
   184     if ( elementSizeInBits == 8 ) // 8 bit data
       
   185         {
       
   186         // Straight copy here
       
   187         aOut.Append( aIn );
       
   188         }
       
   189     else if ( elementSizeInBits == 7 ) // Need packing to 7-bit
       
   190         {
       
   191         // Get raw pointers and do packing
       
   192         TUint8* outPtr = ( TUint8* )aOut.Ptr() + aOut.Length();
       
   193         const TUint8* inPtr = aIn.Ptr();
       
   194         
       
   195         outPtr[0] = 0;
       
   196         for ( TInt i = 0; i < aIn.Length() ; i++ )
       
   197             {
       
   198             TUint8 to = inPtr[i];
       
   199             *outPtr |= ( to << iStartBit );
       
   200             if ( iStartBit )
       
   201                 {
       
   202                 outPtr++;
       
   203                 *outPtr = ( TUint8 ) ( to >> ( 8 - iStartBit ) );
       
   204                 }
       
   205             iStartBit = ( iStartBit + 7 )%8; // roll 0,1,2,3,4,5,6,7,0,1,2,...
       
   206             
       
   207             if ( i == aIn.Length() - 1 ) // if this is the last time
       
   208                 {
       
   209                 if ( ( to == KPhCltUssdCarriageReturn && iStartBit == 0 ) || 
       
   210                      iStartBit == 1 )
       
   211                     {
       
   212                     //We have to add one CR more
       
   213                     *outPtr |= ( KPhCltUssdCarriageReturn << iStartBit );
       
   214                     if ( iStartBit )
       
   215                         {
       
   216                         outPtr++;
       
   217                         *outPtr = ( TUint8 ) (
       
   218                             KPhCltUssdCarriageReturn >> ( 8 - iStartBit ) );
       
   219                         }
       
   220                     else
       
   221                         {
       
   222                         packedOctetsRequired++;
       
   223                         }
       
   224                     iStartBit = ( iStartBit + 7 )%8;
       
   225                     }
       
   226                 }
       
   227             }
       
   228         // Increment the length for the packed data
       
   229         aOut.SetLength( aOut.Length() + packedOctetsRequired );
       
   230         }
       
   231     else
       
   232         {
       
   233         User::Invariant();
       
   234         }
       
   235     // Return number of bytes used
       
   236     return packedOctetsRequired;
       
   237     }
       
   238 
       
   239 
       
   240 // -----------------------------------------------------------------------------
       
   241 // TPhCltUssdAlphabetPacker::ConvertAndPackL
       
   242 //
       
   243 // -----------------------------------------------------------------------------
       
   244 //
       
   245 TInt TPhCltUssdAlphabetPacker::ConvertAndPackL(
       
   246     CCnvCharacterSetConverter& aCharacterSetConverter,
       
   247     RFs& aFs,
       
   248     TDes8& aOut,
       
   249     const TDesC& aIn,
       
   250     TInt& aConvertedNumUDUnits )
       
   251     {
       
   252     
       
   253     // Do the conversion
       
   254     CSmsAlphabetConverter* converter = 
       
   255         CSmsAlphabetConverter::NewLC( 
       
   256             aCharacterSetConverter, aFs, iAlphabet, iIsBinary );
       
   257 
       
   258     TPtrC8 convertedPtr = converter->ConvertFromNativeL( aIn );
       
   259     aConvertedNumUDUnits = convertedPtr.Length();
       
   260 
       
   261     // Do the packing
       
   262     TInt octetsUsed = PackL( aOut,convertedPtr );
       
   263 
       
   264     // Cleanup and return
       
   265     CleanupStack::PopAndDestroy(); // converter
       
   266     return octetsUsed;
       
   267     }
       
   268 
       
   269 
       
   270 // -----------------------------------------------------------------------------
       
   271 // TPhCltUssdAlphabetPacker::PackedOctetsRequiredL
       
   272 //
       
   273 // -----------------------------------------------------------------------------
       
   274 //
       
   275 TInt TPhCltUssdAlphabetPacker::PackedOctetsRequiredL( TInt aNumUDUnits ) const
       
   276 
       
   277     {  
       
   278     TInt octetsRequired = 0;
       
   279     TInt elementSizeInBits = ElementSizeInBitsL();
       
   280     if ( elementSizeInBits == 8 )
       
   281         {
       
   282         octetsRequired=aNumUDUnits;
       
   283         }
       
   284     else
       
   285         {
       
   286         octetsRequired =
       
   287             ( iStartBit + aNumUDUnits*elementSizeInBits + 7 )/8;    // Rounds up
       
   288         }
       
   289     return octetsRequired;
       
   290     }
       
   291 
       
   292 
       
   293 // -----------------------------------------------------------------------------
       
   294 // TPhCltUssdAlphabetPacker::ElementSizeInBitsL
       
   295 //
       
   296 // -----------------------------------------------------------------------------
       
   297 //
       
   298 TInt TPhCltUssdAlphabetPacker::ElementSizeInBitsL() const
       
   299     {   
       
   300     if ( iIsBinary )
       
   301         return 8;
       
   302     switch ( iAlphabet )
       
   303         {
       
   304         case TSmsDataCodingScheme::ESmsAlphabet7Bit:
       
   305             {
       
   306             return 7;
       
   307             }
       
   308         case TSmsDataCodingScheme::ESmsAlphabet8Bit:
       
   309         case TSmsDataCodingScheme::ESmsAlphabetUCS2:
       
   310             {
       
   311             return 8;
       
   312             }
       
   313         default:
       
   314             {
       
   315             User::Leave( KErrGsmSMSDataCodingSchemeNotSupported );
       
   316             return 8;
       
   317             }
       
   318         }
       
   319     }
       
   320 
       
   321 
       
   322 
       
   323 
       
   324 // ============================ MEMBER FUNCTIONS ===============================
       
   325 
       
   326 // -----------------------------------------------------------------------------
       
   327 // CPhCltUssdImp::NewL
       
   328 // Two-phased constructor.
       
   329 // -----------------------------------------------------------------------------
       
   330 //
       
   331 CPhCltUssdImp* CPhCltUssdImp::NewL( TBool aShowNotes )
       
   332     {
       
   333     TFLOGSTRING("CPhCltUssdImp: NewL call")
       
   334     CPhCltUssdImp* self = new( ELeave ) CPhCltUssdImp;
       
   335     CleanupStack::PushL( self );
       
   336     self->ConstructL( aShowNotes );
       
   337     CleanupStack::Pop(); // self
       
   338     TFLOGSTRING("CPhCltUssdImp: NewL exit")
       
   339     return self;
       
   340     }
       
   341 
       
   342 
       
   343 // -----------------------------------------------------------------------------
       
   344 // CPhCltUssdImp::ConstructL
       
   345 // Symbian 2nd phase constructor can leave.
       
   346 // -----------------------------------------------------------------------------
       
   347 //
       
   348 void CPhCltUssdImp::ConstructL( TBool aShowNotes )
       
   349     {
       
   350     TFLOGSTRING("CPhCltUssdImp: ConstructL call")
       
   351     // The note controller is needed only if the notes are shown.
       
   352     iNoteController = NULL;
       
   353     
       
   354     if ( aShowNotes )
       
   355         {
       
   356         iNoteController = CPhCltUssdNoteController::NewL( 
       
   357             *this );
       
   358         }
       
   359 
       
   360     iDCS = KPhCltUssdDcsDefaultAlphabet;
       
   361     iWait = new( ELeave ) CActiveSchedulerWait;
       
   362 
       
   363     // The one that send the request forward.
       
   364     iRequestHandler = CPhCltUssdRequestHandler::NewL( 
       
   365         *this, 
       
   366         CActive::EPriorityStandard );
       
   367     TFLOGSTRING("CPhCltUssdImp: ConstructL exit")
       
   368     }
       
   369 
       
   370 
       
   371 // -----------------------------------------------------------------------------
       
   372 // CPhCltUssdImp::CPhCltUssdImp
       
   373 // C++ default constructor can NOT contain any code, that
       
   374 // might leave.
       
   375 // -----------------------------------------------------------------------------
       
   376 //
       
   377 CPhCltUssdImp::CPhCltUssdImp()
       
   378     {
       
   379     TFLOGSTRING("CPhCltUssdImp: CPhCltUssdImp call_exit")
       
   380     } 
       
   381 
       
   382 
       
   383 // -----------------------------------------------------------------------------
       
   384 // CPhCltUssdImp::~CPhCltUssdImp
       
   385 // Destructor.
       
   386 // -----------------------------------------------------------------------------
       
   387 //
       
   388 CPhCltUssdImp::~CPhCltUssdImp()
       
   389     {
       
   390     TFLOGSTRING("CPhCltUssdImp: ~CPhCltUssdImp call") 
       
   391     if ( iWait )
       
   392         {
       
   393         if ( iWait->IsStarted() )
       
   394             {
       
   395             iWait->AsyncStop();
       
   396             }
       
   397         delete iWait;
       
   398         iWait = NULL;
       
   399         }
       
   400 
       
   401     delete iRequestHandler;
       
   402     iRequestHandler = NULL;
       
   403     
       
   404     delete iNoteController;
       
   405     iNoteController = NULL;
       
   406     TFLOGSTRING("CPhCltUssdImp: ~CPhCltUssdImp exit") 
       
   407     }
       
   408 
       
   409 
       
   410 // -----------------------------------------------------------------------------
       
   411 // CPhCltUssdImp::HandleSendEventL
       
   412 // 
       
   413 // Called when the Send request is completed. aError might be
       
   414 // positive -> the Send is completed due received message.
       
   415 // -----------------------------------------------------------------------------
       
   416 //
       
   417 void CPhCltUssdImp::HandleSendEventL( const TInt aError )
       
   418     {
       
   419     iSendError = Min( aError , KErrNone );
       
   420     TFLOGSTRING2("CPhCltUssdImp: HandleSendEventL\
       
   421             aError = %d call", aError)
       
   422     // iNoteController is allocated only if notes are shown.
       
   423     if ( iNoteController )
       
   424         {
       
   425         // Send request is completed, now destroy the wait note
       
   426         iNoteController->DestroyGlobalWaitNote();
       
   427 
       
   428         // Show a different note depenging on the error code.
       
   429         if ( aError <= 0 )
       
   430             {
       
   431             switch ( aError )
       
   432                 {
       
   433                 // All Ok.
       
   434                 case KErrNone:
       
   435                     iNoteController->ShowGlobalInformationNoteL( EPhCltUssdDone );
       
   436                     break;
       
   437 
       
   438                 // Operation cancelled.
       
   439                 case KErrCancel:
       
   440                     iNoteController->ShowGlobalInformationNoteL( EPhCltUssdUnconfirme );
       
   441                     break;
       
   442 
       
   443                 // Ongoing Ussd session or the string is barred due SS request
       
   444                 // or Fixed Dialling feature.
       
   445                 case KErrInUse:
       
   446                 case KErrAccessDenied:
       
   447                 case KErrGsmSSCallBarred:
       
   448                     iNoteController->ShowGlobalInformationNoteL( EPhCltUssdNotallowed );
       
   449                     break;
       
   450 
       
   451                 // No network coverage.
       
   452                 case KErrGsmSMSNoNetworkService:
       
   453                     iNoteController->ShowGlobalInformationNoteL(EPhCltUssdNoservice );
       
   454                     break;
       
   455 
       
   456                 // Offline mode.
       
   457                 case KErrGsmOfflineOpNotAllowed:
       
   458                     iNoteController->ShowGlobalInformationNoteL( EPhCltUssdOffline );
       
   459                     break;
       
   460                     
       
   461                 case KErrSatControl:
       
   462                     break; 
       
   463 
       
   464                 // Unknown error.
       
   465                 default:
       
   466                     iNoteController->ShowGlobalInformationNoteL( EPhCltUssdNotDone );
       
   467                     break;
       
   468                 }
       
   469             }
       
   470         }
       
   471 
       
   472     // Let the original active object (one that did the send request) run again.
       
   473     if ( iWait->IsStarted() )
       
   474         {
       
   475         iWait->AsyncStop();
       
   476         }
       
   477     TFLOGSTRING("CPhCltUssdImp: HandleSendEventL exit")
       
   478     }
       
   479 
       
   480 
       
   481 // -----------------------------------------------------------------------------
       
   482 // CPhCltUssdImp::SendUssd
       
   483 // 
       
   484 // 16-bit buffer is packed into 7-bit stream and sent.
       
   485 // Default alphabet is used.
       
   486 // -----------------------------------------------------------------------------
       
   487 //
       
   488 TInt CPhCltUssdImp::SendUssd( const TDesC& aMsgData )
       
   489     {
       
   490     __ASSERT_ALWAYS( aMsgData.Length() <= KPhCltUssdMax8BitCharacters,
       
   491         User::Invariant() );
       
   492 
       
   493     TRAPD( err ,
       
   494         {
       
   495         HBufC8* buffer8 = HBufC8::NewLC( KPhCltUssdMax7BitCharacterOctets );
       
   496         
       
   497         TPtr8 ptr8 = buffer8->Des();
       
   498         EncodeL( aMsgData , ptr8 );
       
   499         
       
   500         User::LeaveIfError( SendUssd( ptr8 ) );
       
   501         
       
   502         CleanupStack::PopAndDestroy(); // ptr8
       
   503         });
       
   504 
       
   505     return err;
       
   506     }
       
   507 
       
   508 
       
   509 // -----------------------------------------------------------------------------
       
   510 // CPhCltUssdImp::SendUssd
       
   511 // 
       
   512 // Packed buffer is send to the network with default alphabet.
       
   513 // -----------------------------------------------------------------------------
       
   514 //
       
   515 /*****************************************************
       
   516 *   Series 60 Customer / ETel
       
   517 *   Series 60  ETel API
       
   518 *****************************************************/
       
   519 
       
   520 TInt CPhCltUssdImp::SendUssd( const TDesC8& aMsgData )
       
   521     {
       
   522     __ASSERT_ALWAYS( aMsgData.Length() <= KPhCltUssdMax7BitCharacterOctets,
       
   523         User::Invariant() );
       
   524  
       
   525     return SendUssd( aMsgData , iDCS );
       
   526     }
       
   527 
       
   528 
       
   529 // -----------------------------------------------------------------------------
       
   530 // CPhCltUssdImp::SendUssd
       
   531 // 
       
   532 // Packed buffer is sent to network with given alphabet.
       
   533 // -----------------------------------------------------------------------------
       
   534 //
       
   535 TInt CPhCltUssdImp::SendUssd( 
       
   536     const TDesC8& aMsgData, 
       
   537     const TUint8 iSendDcs )
       
   538     {
       
   539     TFLOGSTRING("CPhCltUssdImp: SendUssd call")
       
   540     __ASSERT_ALWAYS( aMsgData.Length() <= KPhCltUssdMax7BitCharacterOctets,
       
   541         User::Invariant() );
       
   542 
       
   543     RMobileUssdMessaging::TMobileUssdAttributesV1 attribute;
       
   544 
       
   545     attribute.iFlags = 
       
   546         RMobileUssdMessaging::KUssdDataFormat + 
       
   547         RMobileUssdMessaging::KUssdMessageDcs;
       
   548     if ( iDCS2  == KPhCltDcs7Bit )
       
   549         {
       
   550         attribute.iFormat = RMobileUssdMessaging::EFormatPackedString;
       
   551         }
       
   552     else
       
   553         {
       
   554         attribute.iFormat = RMobileUssdMessaging::EFormatUnspecified;
       
   555         }
       
   556         
       
   557     if ( iSendDcs == KPhCltUssdDcsNotSet  ) // 0x00
       
   558         {
       
   559         attribute.iDcs = KPhCltUssdDcsDefaultAlphabet;
       
   560         }
       
   561     else
       
   562         {
       
   563         attribute.iDcs = iSendDcs;
       
   564         } 
       
   565     
       
   566     RMobileUssdMessaging::TMobileUssdAttributesV1Pckg 
       
   567         attributePckg( attribute );
       
   568 
       
   569 
       
   570     if ( iWait->IsStarted() )
       
   571         {
       
   572         return KErrInUse;
       
   573         }
       
   574 
       
   575     iSendError = KErrNone;
       
   576     TFLOGSTRING("CPhCltUssdImp: SendUssd iRequestHandler")
       
   577     iRequestHandler->SendUssd( aMsgData , attributePckg );
       
   578     // iNoteController is allocated only if notes are shown.
       
   579     TFLOGSTRING("CPhCltUssdImp: SendUssd ShowGlobalWaitNoteL")
       
   580     if ( iNoteController )
       
   581         {
       
   582         TRAP_IGNORE( iNoteController->ShowGlobalWaitNoteL(); 
       
   583                     );
       
   584         }
       
   585     TFLOGSTRING("CPhCltUssdImp: SendUssd iWait") 
       
   586 
       
   587     // Set this active object to wait the completion of the send request.
       
   588     iWait->Start();
       
   589 
       
   590     TFLOGSTRING("CPhCltUssdImp: SendUssd exit") 
       
   591     return iSendError;
       
   592     }
       
   593 
       
   594 
       
   595 // -----------------------------------------------------------------------------
       
   596 // CPhCltUssdImp::SendUssdCancel
       
   597 // 
       
   598 // Cancels the out-standing request.
       
   599 // -----------------------------------------------------------------------------
       
   600 //
       
   601 void CPhCltUssdImp::SendUssdCancel()
       
   602     {
       
   603     TFLOGSTRING("CPhCltUssdImp: SendUssdCancel call")
       
   604     iRequestHandler->SendUssdCancel();
       
   605     TFLOGSTRING("CPhCltUssdImp: SendUssdCancel exit")
       
   606     }
       
   607 
       
   608 
       
   609 // -----------------------------------------------------------------------------
       
   610 // CPhCltUssdImp::StartUssdEditor
       
   611 // 
       
   612 // Request Ussd App to start
       
   613 // ---------------------------------------------------------------------------
       
   614 //
       
   615 TInt CPhCltUssdImp::StartUssdEditor() const
       
   616     {
       
   617     return iRequestHandler->UssdClient().StartUssdEditor();
       
   618     }
       
   619 
       
   620 // -----------------------------------------------------------------------------
       
   621 // CPhCltUssdImp::AppStarting
       
   622 // 
       
   623 // UI informs that it is been created
       
   624 // -----------------------------------------------------------------------------
       
   625 //
       
   626 TInt CPhCltUssdImp::AppStarting()
       
   627     {
       
   628     TFLOGSTRING("CPhCltUssdImp: AppStarting call")
       
   629     TInt res = iRequestHandler->UssdClient().AppStarting();
       
   630     TFLOGSTRING2("CPhCltUssdImp: AppStarting exit res = %d",res)
       
   631     return res;
       
   632     }
       
   633     
       
   634 // -----------------------------------------------------------------------------
       
   635 // CPhCltUssdImp::AppTerminating
       
   636 // 
       
   637 // UI informs that it is terminating
       
   638 // -----------------------------------------------------------------------------
       
   639 //    
       
   640 TInt CPhCltUssdImp::AppTerminating( 
       
   641       TPhCltUssdAppExitReason aExitReason )
       
   642     {
       
   643     TFLOGSTRING("CPhCltUssdImp: AppTerminating call")
       
   644     TInt res = iRequestHandler->UssdClient().AppTerminating( aExitReason );
       
   645     TFLOGSTRING2("CPhCltUssdImp: AppTerminating exit res = %d",res)
       
   646     return res;
       
   647     }
       
   648     
       
   649 // -----------------------------------------------------------------------------
       
   650 // CPhCltUssdImp::AppToForeground
       
   651 // 
       
   652 // UI informs that it is brougth to foreground
       
   653 // -----------------------------------------------------------------------------
       
   654 //    
       
   655 TBool CPhCltUssdImp::AppToForeground()
       
   656     {
       
   657     TFLOGSTRING("CPhCltUssdImp: AppToForeground call")
       
   658     TBool res =  iRequestHandler->UssdClient().AppToForeground();
       
   659     TFLOGSTRING2("CPhCltUssdImp: AppToForeground exit res = %d",res)
       
   660     return res;
       
   661     }
       
   662     
       
   663 // -----------------------------------------------------------------------------
       
   664 // CPhCltUssdImp::AppToBackground
       
   665 // 
       
   666 // UI informs that it is gone background
       
   667 // -----------------------------------------------------------------------------
       
   668 //    
       
   669 TInt CPhCltUssdImp::AppToBackground()
       
   670     {
       
   671     TFLOGSTRING("CPhCltUssdImp: AppToBackground call")
       
   672     TInt res = iRequestHandler->UssdClient().AppToBackground();
       
   673     TFLOGSTRING2("CPhCltUssdImp: AppToBackground exit res = %d",res)
       
   674     return res;
       
   675     }
       
   676 
       
   677 // -----------------------------------------------------------------------------
       
   678 // CPhCltUssdImp::StartSAT
       
   679 // 
       
   680 // 
       
   681 // -----------------------------------------------------------------------------
       
   682 //    
       
   683 void  CPhCltUssdImp::StartSAT( 
       
   684             TRequestStatus& aStatus, 
       
   685             TDes& aReceiveMessage, 
       
   686             TPckg< TUint >& aShowNotesAndDcs )
       
   687     {
       
   688     TFLOGSTRING("CPhCltUssdImp: StartSAT call")
       
   689     iRequestHandler->UssdClient().StartSAT( aStatus, aReceiveMessage, aShowNotesAndDcs );
       
   690     TFLOGSTRING("CPhCltUssdImp: StartSAT exit")
       
   691     }
       
   692  
       
   693 // -----------------------------------------------------------------------------
       
   694 // CPhCltUssdImp::StopSAT
       
   695 // 
       
   696 // Cancels SAT session
       
   697 // -----------------------------------------------------------------------------
       
   698 //   
       
   699  void CPhCltUssdImp::StopSAT()
       
   700     {
       
   701     TFLOGSTRING("CPhCltUssdImp: StopSAT call")
       
   702     iRequestHandler->UssdClient().StopSAT();
       
   703     TFLOGSTRING("CPhCltUssdImp: StopSAT exit")
       
   704     }
       
   705 
       
   706 
       
   707 // -----------------------------------------------------------------------------
       
   708 // CPhCltUssdImp::GlobalWaitNoteHidden
       
   709 //
       
   710 // Dialog is hidden by the cancel key.
       
   711 // -----------------------------------------------------------------------------
       
   712 //
       
   713 void CPhCltUssdImp::GlobalWaitNoteHidden()
       
   714     {
       
   715     TFLOGSTRING("CPhCltUssdImp: GlobalWaitNoteHidden call")
       
   716     TFLOGSTRING("CPhCltUssdImp: GlobalWaitNoteHidden exit")
       
   717     }
       
   718 
       
   719 
       
   720 // -----------------------------------------------------------------------------
       
   721 // CPhCltUssdImp::EncodeL
       
   722 //
       
   723 // Converts a given Uniocde string into 7-bit buffer.
       
   724 // -----------------------------------------------------------------------------
       
   725 //
       
   726 void CPhCltUssdImp::EncodeL( const TDesC& aSrc, TDes8& aDes )
       
   727     {
       
   728     TFLOGSTRING("CPhCltUssdImp: EncodeL call")
       
   729     aDes.Zero();
       
   730     TSmsDataCodingScheme::TSmsAlphabet alphabet = 
       
   731         TSmsDataCodingScheme::ESmsAlphabet7Bit; // default
       
   732         
       
   733     CCnvCharacterSetConverter* charConv = CCnvCharacterSetConverter::NewLC();
       
   734     
       
   735     TUint cutChars = 0;
       
   736     TUint startBit = 0;
       
   737 
       
   738     if ( iDCS == KPhCltUssdDcsAlphabetDefaultPrecededLanguage )
       
   739         {
       
   740         alphabet = TSmsDataCodingScheme::TSmsDataCodingScheme::ESmsAlphabet7Bit;
       
   741         FindFirstCarriageReturnL( aSrc , cutChars , startBit );
       
   742         
       
   743         }
       
   744     else if ( iDCS == KPhCltUssdDcsAlphabetUCS2PrecededLanguage )
       
   745         {
       
   746         alphabet = TSmsDataCodingScheme::ESmsAlphabetUCS2;
       
   747         cutChars = KPhCltUssdDcsAlphabetUCS2PrecededLanguageSkipChars;
       
   748         }
       
   749     else if ( (iDCS & KPhCltUssdDcsGeneralInformationMask)  == 
       
   750             KPhCltUssdDcsGeneralInformation ) // General data coding information
       
   751         {
       
   752         //Is text compressed?
       
   753         if ( iDCS & KPhCltUssdDcsGeneralInformationCompressed )
       
   754             {
       
   755             User::Leave( KErrNotSupported );
       
   756             }
       
   757         // Is SIM specific message
       
   758         else if ( ( iDCS & KPhCltUssdDcsGeneralInformationSimMask ) 
       
   759                    == KPhCltUssdDcsGeneralInformationSim )
       
   760             {
       
   761             User::Leave( KErrAbort ); // Do not show any messages
       
   762             }
       
   763         // 8 bit data?
       
   764         else if ( ( iDCS & KPhCltUssdDcsGeneralInformationAlphabetMask ) ==  
       
   765                    KPhCltUssdDcsGeneralInformationAlphabet8Bit )
       
   766             {
       
   767             alphabet = TSmsDataCodingScheme::ESmsAlphabet8Bit;
       
   768             }
       
   769         // UCS2 bit data?
       
   770         else if ( ( iDCS & KPhCltUssdDcsGeneralInformationAlphabetMask ) == 
       
   771                    KPhCltUssdDcsGeneralInformationAlphabetUCS2 )
       
   772             {
       
   773             alphabet = TSmsDataCodingScheme::ESmsAlphabetUCS2;
       
   774             }
       
   775         }
       
   776     // Data coding/message handling
       
   777     else if ( ( iDCS & KPhCltUssdDcsMessageHandlingAlphabetMask ) 
       
   778                == KPhCltUssdDcsMessageHandlingAlphabet8Bit )
       
   779         {
       
   780         alphabet = TSmsDataCodingScheme::ESmsAlphabet8Bit;
       
   781         }
       
   782     
       
   783     TPhCltUssdAlphabetPacker* packer = 
       
   784         new ( ELeave ) TPhCltUssdAlphabetPacker( 
       
   785             alphabet, EFalse, startBit );
       
   786         CleanupStack::PushL( packer );
       
   787         
       
   788    
       
   789     RFs fs;
       
   790     User::LeaveIfError( fs.Connect() );
       
   791     CleanupClosePushL( fs );
       
   792     
       
   793     TInt numberOfElem = 0;
       
   794    // packer->ConvertAndPackL( 
       
   795     //    *charConv , fs , aDes , aSrc , numberOfElem );
       
   796         
       
   797         
       
   798     if ( alphabet == TSmsDataCodingScheme::ESmsAlphabet7Bit )
       
   799         {
       
   800         //TInt numberOfElem = (( aSrc.Length() - cutChars ) * 8 - startBit ) / 7;
       
   801             
       
   802          packer->ConvertAndPackL( 
       
   803         *charConv , fs , aDes , aSrc.Right( aSrc.Length() - cutChars ), numberOfElem );
       
   804 
       
   805         // DCS was 7-bit data.
       
   806         iDCS2 = KPhCltDcs7Bit; 
       
   807         }
       
   808     else // ESmsAlphabet8Bit || ESmsAlphabetUCS2
       
   809         {
       
   810         CSmsAlphabetConverter* converter =
       
   811             CSmsAlphabetConverter::NewLC(
       
   812                 *charConv ,fs, alphabet, EFalse );
       
   813 
       
   814         aDes = converter->ConvertFromNativeL(
       
   815             aSrc.Right( aSrc.Length() - cutChars ) );
       
   816         CleanupStack::PopAndDestroy(); //converter
       
   817 
       
   818         if( alphabet == TSmsDataCodingScheme::ESmsAlphabet8Bit )
       
   819             {
       
   820             // DCS was 8-bit data.
       
   821             iDCS2 = KPhCltDcs8Bit;
       
   822             }
       
   823         else if( alphabet == TSmsDataCodingScheme::ESmsAlphabetUCS2 )
       
   824             {
       
   825              //DCS was UCS2 data.
       
   826             iDCS2 = KPhCltDcsUcs2;
       
   827             }
       
   828         // If DCS not 8-bit or UCS2, then EPhCltDcsUnknown is returned.
       
   829         }
       
   830     
       
   831     CleanupStack::PopAndDestroy(3); // fs, packer, charConv
       
   832     TFLOGSTRING("CPhCltUssdImp: EncodeL exit")
       
   833     }
       
   834 
       
   835 // -----------------------------------------------------------------------------
       
   836 // CPhCltUssdImp::SetDCS()
       
   837 //
       
   838 // Set data coding scheme 
       
   839 // -----------------------------------------------------------------------------
       
   840 //
       
   841 void CPhCltUssdImp::SetDCS( TUint8 aDCS )
       
   842     {
       
   843     iDCS = aDCS;
       
   844     }
       
   845 
       
   846 // -----------------------------------------------------------------------------
       
   847 // CPhCltUssdImp::FindFirstCarriageReturnL
       
   848 // -----------------------------------------------------------------------------
       
   849 //
       
   850 void CPhCltUssdImp::FindFirstCarriageReturnL( 
       
   851     const TDesC& aBuffer ,
       
   852     TUint& aSkipChars , 
       
   853     TUint& aStartBit )
       
   854     {
       
   855     if ( aBuffer.Length() < 3 )
       
   856         {
       
   857         User::Leave( KErrUnderflow );
       
   858         }
       
   859 
       
   860     aSkipChars = 0;
       
   861     aStartBit = 0;
       
   862 
       
   863     // Try out two different cases:
       
   864     // 1. Find CR from thrid byte
       
   865     // 2. Find CR from second byte, starting from bit 6
       
   866 
       
   867     // 1.:
       
   868     if ( aBuffer[2] == KPhCltUssdCarriageReturn )
       
   869         {
       
   870         aSkipChars = KPhCltUssdDcsAlphabetDefaultPrecededLanguageSkipChars3;
       
   871         aStartBit = 0;
       
   872         return;
       
   873         }
       
   874 
       
   875     // 2.:
       
   876     // First put the pieces together and then compare
       
   877     // Take last 2 bits from the second byte:
       
   878     TUint result1 = aBuffer[1];
       
   879     result1 = result1 >> 6;
       
   880 
       
   881     // Take first 5 bits from the third byte:
       
   882     TUint result2 = aBuffer[2];
       
   883     result2 = result2 & 0x1f; // bits 0-4.
       
   884     result2 = result2 << 2; // move to bits 2-6.
       
   885 
       
   886     TUint result = result1 + result2; // 0000 00xx + 0xxx xx00
       
   887     if ( result == KPhCltUssdCarriageReturn )
       
   888         {
       
   889         aSkipChars = KPhCltUssdDcsAlphabetDefaultPrecededLanguageSkipChars2;
       
   890         aStartBit = KPhCltUssdDcsAlphabetDefaultPrecededLanguageStartBit;
       
   891         return;
       
   892         }
       
   893 
       
   894     // Is was not case 1. or 2. so we are not supporting sort of string.
       
   895     User::Leave( KErrNotSupported );
       
   896     }
       
   897 
       
   898 // End of File