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