adaptationlayer/tsy/simatktsy_dll/src/satcc.cpp
changeset 0 63b37f68c1ce
child 5 8ccc39f9d787
equal deleted inserted replaced
-1:000000000000 0:63b37f68c1ce
       
     1 /*
       
     2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 //  INCLUDE FILES
       
    22 #include "satcc.h"              // sat call control class
       
    23 #include "satmessaging.h"       // sat messaging class
       
    24 #include "satmesshandler.h"     // sat message handler class
       
    25 #include "ber_tlv.h"            // sat ber-tlv classes
       
    26 #include "satutil.h"            // sat utility class
       
    27 
       
    28 #include <pn_const.h>           // server id constants
       
    29 #include <tisi.h>               // isi message
       
    30 #include <ss_wmisi.h>           // Modem SS server
       
    31 #include <call_modemisi.h>      // Modem Call server
       
    32 #include <gpdsisi.h>            // GPDS server
       
    33 #include <uiccisi.h>            // UICC server
       
    34 #include "osttracedefinitions.h"
       
    35 #ifdef OST_TRACE_COMPILER_IN_USE
       
    36 #include "satcctraces.h"
       
    37 #endif
       
    38 
       
    39 
       
    40 
       
    41 // CONSTANTS
       
    42 // Zero character code
       
    43 const TUint8 KZeroCharacterCode                 = 0x30;
       
    44 // Maximum length for PDP Context Activation Parameters, see 3GPP TS 31.111
       
    45 const TUint8 KPdpContextActivationParamsMaxSize = 124;
       
    46 // From 3GPP TS 31.111, 7.3.1.6 Structure of ENVELOPE (CALL CONTROL)
       
    47 const TUint8 KCcResultAllowedNoModification     = 0x00;
       
    48 const TUint8 KCcResultNotAllowed                = 0x01;
       
    49 const TUint8 KCcResultAllowedWithModifications  = 0x02;
       
    50 
       
    51 // Maximum data length without additional TLVs in envelope response
       
    52 const TUint8 KCcEmptyResponseLenght     = 0x02;
       
    53 // Buffer seze used for all CC responses
       
    54 const TInt KMaximumCcBufferSize =
       
    55     4 +     //CALL_MODEM_SB_RESOURCE
       
    56     4 +     //CALL_MODEM_SB_RESOURCE_SEQ_ID
       
    57     4 +     //CALL_MODEM_SB_RESOURCE_STATUS
       
    58     4 +     //CALL_MODEM_SB_MODE
       
    59     252 +   //CALL_MODEM_SB_BC
       
    60     252 +   //CALL_MODEM_SB_DESTINATION_ADDRESS
       
    61     252 +   //CALL_MODEM_SB_DESTINATION_SUBADDRESS
       
    62     252 +   //CALL_MODEM_SB_BC
       
    63     4;      //CALL_MODEM_SB_CAUSE
       
    64 
       
    65 const TUint8 KMSBMask = 0x80;
       
    66 
       
    67 
       
    68 // ==================== MEMBER FUNCTIONS ====================================
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // CSatCC::CSatCC
       
    72 // C++ default constructor can NOT contain any code, that
       
    73 // might leave.
       
    74 // -----------------------------------------------------------------------------
       
    75 //
       
    76 CSatCC::CSatCC
       
    77         (
       
    78         CSatMessHandler*    aSatMessHandler, //Pointer to the message handler
       
    79         CTsySatMessaging*   aSatMessaging    //Pointer to satmessaging class
       
    80         )
       
    81         :
       
    82         iSatMessHandler( aSatMessHandler ),
       
    83         iSatMessaging( aSatMessaging ),
       
    84         iTonNpiPresent( EFalse ),
       
    85         iEnvelopeResponseData( NULL )
       
    86     {
       
    87     OstTrace0( TRACE_NORMAL, CSATCC_CSATCC, "CSatCC::CSatCC" );
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // CSatCC::ConstructL
       
    92 // Symbian 2nd phase constructor can leave.
       
    93 // -----------------------------------------------------------------------------
       
    94 //
       
    95 void CSatCC::ConstructL()
       
    96     {
       
    97     OstTrace0( TRACE_NORMAL, CSATCC_CONSTRUCTL, "CSatCC::ConstructL" );
       
    98     TFLOGSTRING("TSY: CSatCC::ConstructL");
       
    99 
       
   100     // Create array for CC request information storing
       
   101     iCallControlArray = new( ELeave ) RArray<TCallControl>( 1 );
       
   102 
       
   103     iUssdTlvSupported = EFalse;
       
   104     }
       
   105 
       
   106 // -----------------------------------------------------------------------------
       
   107 // CSatCC::NewL
       
   108 // Two-phased constructor.
       
   109 // -----------------------------------------------------------------------------
       
   110 //
       
   111 CSatCC* CSatCC::NewL
       
   112         (
       
   113         CSatMessHandler*    aSatMessHandler, //Pointer to the message handler
       
   114         CTsySatMessaging*   aSatMessaging    //Pointer to satmessaging class
       
   115         )
       
   116     {
       
   117     OstTrace0( TRACE_NORMAL, CSATCC_NEWL, "CSatCC::NewL" );
       
   118     TFLOGSTRING("TSY: CSatCC::NewL");
       
   119 
       
   120     CSatCC* self = new( ELeave ) CSatCC( aSatMessHandler, aSatMessaging );
       
   121 
       
   122     CleanupStack::PushL( self );
       
   123     self->ConstructL();
       
   124     CleanupStack::Pop( self );
       
   125 
       
   126     return self;
       
   127     }
       
   128 
       
   129 
       
   130 // -----------------------------------------------------------------------------
       
   131 // CSatCC::~CSatCC
       
   132 // C++ destructor
       
   133 // -----------------------------------------------------------------------------
       
   134 //
       
   135 CSatCC::~CSatCC()
       
   136     {
       
   137     OstTrace0( TRACE_NORMAL, DUP1_CSATCC_CSATCC, "CSatCC::~CSatCC" );
       
   138     TFLOGSTRING("TSY: CSatCC::~CSatCC");
       
   139     
       
   140     if( iCallControlArray )
       
   141         {
       
   142         iCallControlArray->Close();
       
   143         delete iCallControlArray;
       
   144         }
       
   145 
       
   146     if ( iEnvelopeResponseData )
       
   147         {
       
   148         delete iEnvelopeResponseData;
       
   149         }
       
   150     }
       
   151 
       
   152 
       
   153 // -----------------------------------------------------------------------------
       
   154 // CSatCC::GetArrayIndexById
       
   155 // Helper method for searching desired information from array
       
   156 // used for locating stored call control event information
       
   157 // -----------------------------------------------------------------------------
       
   158 //
       
   159 TInt CSatCC::GetArrayIndexById
       
   160         (
       
   161         const TInt &aTid
       
   162         )
       
   163     {
       
   164     OstTrace0( TRACE_NORMAL, CSATCC_GETARRAYINDEXBYID, "CSatCC::GetArrayIndexById" );
       
   165     TFLOGSTRING("TSY: CSatCC::GetArrayIndexById");
       
   166 
       
   167     TInt ret ( KErrNotFound );
       
   168     TInt arraySize ( iCallControlArray->Count() );
       
   169 
       
   170     // Only there's Cc transaction ongoing
       
   171     if ( arraySize )
       
   172         {
       
   173         for ( TInt i = 0 ; ret == KErrNotFound && i < arraySize ; i++ )
       
   174             {
       
   175             if ( ( *iCallControlArray )[i].iTransId == aTid )
       
   176                 {
       
   177                 ret = i;
       
   178                 }
       
   179             }
       
   180         if ( KErrNotFound == ret)
       
   181             {
       
   182             TFLOGSTRING3("TSY: CSatCC::GetArrayIndexById, Error:ID 0x%x not found. Array size: %d", aTid, arraySize );
       
   183             OstTraceExt2( TRACE_NORMAL, DUP1_CSATCC_GETARRAYINDEXBYID, "CSatCC::GetArrayIndexById, Error: ID 0x%x not found. Array size: %d", aTid, arraySize );
       
   184             }
       
   185         }
       
   186     else
       
   187         {
       
   188         //None. This is not our message.
       
   189         }
       
   190 
       
   191     return ret;
       
   192     }
       
   193 
       
   194 // -----------------------------------------------------------------------------
       
   195 // CSatCC::AddLocationInformationToTlv
       
   196 // Adds location informating to given TTlv.
       
   197 // -----------------------------------------------------------------------------
       
   198 //
       
   199 void CSatCC::AddLocationInformationToTlv
       
   200         (
       
   201         TTlv& aTlv //Tlv to be sent
       
   202         )
       
   203     {
       
   204     OstTrace0( TRACE_NORMAL, CSATCC_ADDLOCATIONINFORMATIONTOTLV, "CSatCC::AddLocationInformationToTlv" );
       
   205     TFLOGSTRING("TSY: CSatCC::AddLocationInformationToTlv");
       
   206 
       
   207     const CSatMessHandler::TLocationInfo& locInfo
       
   208         = iSatMessHandler->LocationInfo();
       
   209 
       
   210     aTlv.AddTag( KTlvLocationInformationTag );
       
   211     // append Mobile Country  & Network Codes, 3 bytes
       
   212     aTlv.AddData( locInfo.iOperatorCode );
       
   213     // append LAC code
       
   214     aTlv.AddData( locInfo.iLac );
       
   215     // append CellId
       
   216     aTlv.AddData( locInfo.iCellId );
       
   217     }
       
   218 
       
   219 
       
   220 // -----------------------------------------------------------------------------
       
   221 // CSatCC::SendSSEnvelope
       
   222 // Sends call control SS envelope
       
   223 // -----------------------------------------------------------------------------
       
   224 //
       
   225 TInt CSatCC::SendSSEnvelope
       
   226         (
       
   227         const TCallControl& aCcstruct //Structure containing call event info
       
   228         )
       
   229     {
       
   230     OstTrace0( TRACE_NORMAL, CSATCC_SENDSSENVELOPE, "CSatCC::SendSSEnvelope" );
       
   231     TFLOGSTRING("TSY: CSatCC::SendSSEnvelope");
       
   232 
       
   233     // create envelope
       
   234     TTlv envelope;
       
   235     envelope.Begin  ( KBerTlvCallControlTag );
       
   236     // device identities
       
   237     envelope.AddTag ( KTlvDeviceIdentityTag );
       
   238     envelope.AddByte( KMe );
       
   239     envelope.AddByte( KSim );
       
   240     // SS string
       
   241     envelope.AddTag( KTlvSsStringTag );
       
   242 
       
   243     //There is no TON and NPI in SS cc request. Information is part of the
       
   244     //number string: Spec ETSI TS 122 030 v5.0.0 says that if number starts
       
   245     //with +, TON is international and if it starts without it, it's unknown.
       
   246     //Default NPI is used if all digits are in the range 0-9.
       
   247     //NPI shall be unknown if other number information is included.
       
   248     //In any case if the user has selected some particular
       
   249     //NPI, that will be used.
       
   250     TInt i( 0 );
       
   251     TUint8 tonNpi( KTonNpiUnknown );
       
   252 
       
   253     // If SS is entered by user, there's no SEND SS from where to resolve TonNpi
       
   254     // Then TonNpi is resolved from SS string
       
   255     // TonNpi   = Unknown if '+'-sign is not present
       
   256     //          = International if '+'-sign is found
       
   257     //          = No TonNpi if phone number is not present or SS-string contains
       
   258     //            only SS code
       
   259     if ( !iTonNpiPresent )
       
   260         {
       
   261         // 3GPP TS 22 030 V7.0.0 (2004-03) says:
       
   262         // "The procedure always starts with *, #, **, ## or *#
       
   263         // and is finished by #. Each part within the procedure
       
   264         // is separated by *."
       
   265 
       
   266         // skip start characters
       
   267         while ( ( i < aCcstruct.iString.Length() ) &&
       
   268                  ( ( '*' == aCcstruct.iString[i] ) ||
       
   269                    ( '#' == aCcstruct.iString[i] ) ) )
       
   270             {
       
   271             i++;
       
   272             }
       
   273         TInt ssCode( 0 );
       
   274         // seek for separation character and store service code
       
   275         while ( ( i < aCcstruct.iString.Length() )
       
   276                 && ( '*' != aCcstruct.iString[i] )
       
   277                 && ( '#' != aCcstruct.iString[i] ) )
       
   278             {
       
   279             ssCode *= 10;
       
   280             ssCode += ( aCcstruct.iString[i] - KZeroCharacterCode );
       
   281             i++;
       
   282             }
       
   283         // With these SS codes dialling number may be included. It's located
       
   284         // after first separation mark '*', but it can be empty.
       
   285         // See 3GPP TS 22.030 7.0.0, 6.5.2 and Annex B.
       
   286         // With checking the service code ton/npi resolving is made
       
   287         // unambiguous.
       
   288         // Structure of SS string: *service code*SIA*SIB*SIC#
       
   289         // Content of SIB and SIC have no impact to ton/npi
       
   290         if( SS_GSM_ALL_FORWARDINGS == ssCode
       
   291             || SS_GSM_ALL_COND_FORWARDINGS == ssCode
       
   292             || SS_GSM_FORW_UNCONDITIONAL == ssCode
       
   293             || SS_GSM_FORW_BUSY == ssCode
       
   294             || SS_GSM_FORW_NO_REPLY == ssCode
       
   295             || SS_GSM_FORW_NO_REACH == ssCode)
       
   296             {
       
   297             // Set tonNpi international, if separation character (*) and (+)
       
   298             // sign is found
       
   299             if ( ( ( i + 1 ) < aCcstruct.iString.Length() )
       
   300                 && ( ( '*' == aCcstruct.iString[i] )
       
   301                 && ( '+' == aCcstruct.iString[i + 1] ) ) )
       
   302                 {
       
   303                 tonNpi = KTonNpiInternational;
       
   304                 }
       
   305             // Procedure is finished by #
       
   306             // If * is not found -> no number found
       
   307             else if ( ( i < aCcstruct.iString.Length() )
       
   308                     && ('#' == aCcstruct.iString[i] ) )
       
   309                 {
       
   310                 tonNpi = KNoTonNpi;
       
   311                 }
       
   312             // Additional check for (**) "double star" case
       
   313             else if ( ( ( i + 1 )  < aCcstruct.iString.Length() )
       
   314                     && ( '*' == aCcstruct.iString[i] )
       
   315                     && ( '*' == aCcstruct.iString[i + 1] ) )
       
   316                 {
       
   317                 // ** means there is an additional SIB field included,
       
   318                 // but SIA (number) is empty
       
   319                 // PhoneNumber is not present
       
   320                 tonNpi = KNoTonNpi;
       
   321                 }
       
   322             // All other compinations shall result the "unknown" ton/npi
       
   323             else
       
   324                 {
       
   325                 // Number is found but its tonnpi is unknown
       
   326                 tonNpi = KTonNpiUnknown;
       
   327                 }
       
   328             }
       
   329         else
       
   330             {
       
   331             //With all other SS codes TON/NPI is set to 0xff
       
   332             tonNpi = KNoTonNpi;
       
   333             }
       
   334         }
       
   335     else
       
   336         {
       
   337         // TonNpi is resolved from SEND SS proactive command
       
   338         tonNpi = iTonNpiForSS;
       
   339         }
       
   340     iTonNpiPresent = EFalse;
       
   341 
       
   342     envelope.AddByte( tonNpi );
       
   343 
       
   344     TBuf8<255> ss;
       
   345     TSatUtility::AsciiToBCD( aCcstruct.iString, ss );
       
   346     envelope.AddData( ss );
       
   347     // location information
       
   348     AddLocationInformationToTlv( envelope );
       
   349     // send it away...
       
   350     return iSatMessHandler->UiccCatReqEnvelope(
       
   351         aCcstruct.iTransId,
       
   352         envelope.End());
       
   353     }
       
   354 
       
   355 
       
   356 // -----------------------------------------------------------------------------
       
   357 // CSatCC::SendUSSDEnvelope
       
   358 // Sends call control USSD envelope
       
   359 // -----------------------------------------------------------------------------
       
   360 //
       
   361 TInt CSatCC::SendUSSDEnvelope
       
   362         (
       
   363         const TCallControl& aCcstruct //Structure containing call event info
       
   364         )
       
   365     {
       
   366     OstTrace0( TRACE_NORMAL, CSATCC_SENDUSSDENVELOPE, "CSatCC::SendUSSDEnvelope" );
       
   367 
       
   368     TInt ret( KErrNone );
       
   369     // create envelope
       
   370     TTlv envelope;
       
   371     envelope.Begin( KBerTlvCallControlTag );
       
   372 
       
   373     // device identities
       
   374     envelope.AddTag( KTlvDeviceIdentityTag );
       
   375     envelope.AddByte( KMe );
       
   376     envelope.AddByte( KSim );
       
   377 
       
   378     // USSD string tlv supported
       
   379     if ( iUssdTlvSupported )
       
   380         {
       
   381         envelope.AddTag( KTlvUssdStringTag );
       
   382         envelope.AddByte( aCcstruct.iUssdCodingInfo );
       
   383         envelope.AddData( aCcstruct.iUssdString );
       
   384         AddLocationInformationToTlv( envelope );
       
   385 
       
   386         ret = iSatMessHandler->UiccCatReqEnvelope(
       
   387             aCcstruct.iTransId,
       
   388             envelope.End() );
       
   389         }
       
   390     else
       
   391         {
       
   392         // UssdTlv is not supported by the SIM, with Call control
       
   393         // Checks whether the USSD string can be coded in the SS obj. SS obj.
       
   394         // can only contain "*", "#", and the numbers 0-9.
       
   395         if ( IsOnlyDigitsInUssd( aCcstruct.iUssdString ) )
       
   396             {
       
   397             envelope.AddTag( KTlvSsStringTag );
       
   398             // If the Dialling Number/SSC String does not contain a dialling
       
   399             // number e.g. a control string deactivating a service, the
       
   400             // TON/NPI byte shall be set to 'FF' by the ME (see note
       
   401             // 3GPP TS 11.11). in this case TON & NPI must be set to 0xFF
       
   402             envelope.AddByte( 0xFF );
       
   403             TBuf8<255> ss;
       
   404             TSatUtility::AsciiToBCD( aCcstruct.iUssdString, ss );
       
   405             envelope.AddData( ss );
       
   406             AddLocationInformationToTlv( envelope );
       
   407 
       
   408             ret = iSatMessHandler->UiccCatReqEnvelope(
       
   409                 aCcstruct.iTransId,
       
   410                 envelope.End());
       
   411             }
       
   412         else
       
   413             {
       
   414             // SIM does not support USSD and converting it to SS was
       
   415             // impossible. Remove the created CcStruct from the CC array and
       
   416             // send CC event response.
       
   417             TPtrC8 atkData;
       
   418             SendSsResourceControlReq( aCcstruct, KError, atkData );
       
   419             
       
   420             TInt index( GetArrayIndexById( aCcstruct.iTransId ) );
       
   421             if ( index != KErrNotFound )
       
   422                 {
       
   423                 iCallControlArray->Remove( index );
       
   424                 iCallControlArray->Compress();
       
   425                 }
       
   426             }
       
   427         }
       
   428 
       
   429     return ret;
       
   430     }
       
   431 
       
   432 // -----------------------------------------------------------------------------
       
   433 // CSatCC::SendCallEnvelope
       
   434 // Sends call control call envelope
       
   435 // -----------------------------------------------------------------------------
       
   436 //
       
   437 TInt CSatCC::SendCallEnvelope
       
   438         (
       
   439         const TIsiReceiveC& aIsiMessage,
       
   440         const TCallControl& aCallControl //Structure containing call event info
       
   441         )
       
   442     {
       
   443     OstTrace0( TRACE_NORMAL, CSATCC_SENDCALLENVELOPE, "CSatCC::SendCallEnvelope" );
       
   444 
       
   445     // create envelope
       
   446     TTlv envelope;
       
   447     envelope.Begin( KBerTlvCallControlTag );
       
   448     // device identities
       
   449     envelope.AddTag( KTlvDeviceIdentityTag );
       
   450     envelope.AddByte( KMe );
       
   451     envelope.AddByte( KSim );
       
   452     // address is mandatory
       
   453     TInt addressLength( 0 );
       
   454     TUint sbStartOffset( 0 );
       
   455 
       
   456     TInt retValue( aIsiMessage.FindSubBlockOffsetById(
       
   457        ISI_HEADER_SIZE + SIZE_CALL_MODEM_RESOURCE_IND ,
       
   458        CALL_MODEM_SB_DESTINATION_ADDRESS,
       
   459        EIsiSubBlockTypeId8Len8,
       
   460        sbStartOffset ) );
       
   461     
       
   462     if ( KErrNone == retValue )
       
   463         {
       
   464         envelope.AddTag( KTlvAddressTag );
       
   465         envelope.AddByte( KMSBMask | aCallControl.iAddressType );
       
   466         // Unicode address must be converted to BCD number
       
   467         TBuf8<123> address;
       
   468         TSatUtility::AsciiToBCD( aCallControl.iString, address );
       
   469         envelope.AddData( address );
       
   470         }
       
   471     // In Nokia context BC is mandatory
       
   472     envelope.AddTag( KTlvCapabilityConfigurationParametersTag );
       
   473     // Length of actual BC information element
       
   474     envelope.AddByte( aCallControl.iBearerCapabilities.Length() );
       
   475     envelope.AddData( aCallControl.iBearerCapabilities );
       
   476     // If subaddress present
       
   477     retValue = aIsiMessage.FindSubBlockOffsetById(
       
   478           ISI_HEADER_SIZE + SIZE_CALL_MODEM_RESOURCE_IND ,
       
   479           CALL_MODEM_SB_DESTINATION_SUBADDRESS,
       
   480           EIsiSubBlockTypeId8Len8,
       
   481           sbStartOffset );
       
   482     if ( KErrNone == retValue )
       
   483         {
       
   484         envelope.AddTag( KTlvSubaddressTag );
       
   485         // Subaddress is given in same form as expected in envelope
       
   486         addressLength = aIsiMessage.Get8bit( sbStartOffset + 
       
   487             CALL_MODEM_SB_DESTINATION_SUBADDRESS_OFFSET_ADDRLEN );
       
   488         envelope.AddData( aIsiMessage.GetData( sbStartOffset + 
       
   489             CALL_MODEM_SB_DESTINATION_SUBADDRESS_OFFSET_ADDR, 
       
   490             addressLength ) );
       
   491         }
       
   492     // Add mandatory location information
       
   493     AddLocationInformationToTlv( envelope );
       
   494     // send it away..
       
   495     return iSatMessHandler->UiccCatReqEnvelope(
       
   496         aCallControl.iTransId,
       
   497         envelope.End() );
       
   498     }
       
   499 
       
   500 // -----------------------------------------------------------------------------
       
   501 // CSatCC::SendPdpContextActivationEnvelope
       
   502 // Sends Call Control PDP context activation envelope
       
   503 // -----------------------------------------------------------------------------
       
   504 //
       
   505 TInt CSatCC::SendPdpContextActivationEnvelope
       
   506         (
       
   507         const TUint8 aPdpCcEnvelopeTid,
       
   508         const TDesC8& aPdpContextActivationParams
       
   509         )
       
   510     {
       
   511     OstTrace0( TRACE_NORMAL, CSATCC_SENDPDPCONTEXTACTIVATIONENVELOPE, "CSatCC::SendPdpContextActivationEnvelope" );
       
   512     TFLOGSTRING( "TSY: CSatCC::SendPdpContextActivationEnvelope" );
       
   513     // Create envelope
       
   514     TTlv envelope;
       
   515     envelope.Begin( KBerTlvCallControlTag );
       
   516     // Add Device identities
       
   517     envelope.AddTag( KTlvDeviceIdentityTag );
       
   518     envelope.AddByte( KMe);
       
   519     envelope.AddByte( KSim);
       
   520     // Add PDP context activation parameters
       
   521     envelope.AddTag ( KTlvPdpContextActivationParametersTag );
       
   522     envelope.AddData( aPdpContextActivationParams );
       
   523     // Add location information
       
   524     AddLocationInformationToTlv( envelope );
       
   525     // send it away..
       
   526     return iSatMessHandler->UiccCatReqEnvelope( aPdpCcEnvelopeTid,
       
   527         envelope.End() );
       
   528     }
       
   529 
       
   530 
       
   531 // -----------------------------------------------------------------------------
       
   532 // CSatCC::UiccCatRespEnvelopeReceived
       
   533 // Handler function of incoming call control related data notification messages
       
   534 // -----------------------------------------------------------------------------
       
   535 //
       
   536 void CSatCC::UiccCatRespEnvelopeReceived( const TIsiReceiveC& aIsiMessage )
       
   537     {
       
   538     OstTrace0( TRACE_NORMAL, CSATCC_UICCCATRESPENVELOPERECEIVED, "CSatCC::UiccCatRespEnvelopeReceived" );
       
   539     TFLOGSTRING( "TSY:CSatCC::UiccCatRespEnvelopeReceived" );
       
   540 
       
   541     TUint8 status( aIsiMessage.Get8bit(
       
   542         ISI_HEADER_SIZE + UICC_CAT_RESP_OFFSET_STATUS ) );
       
   543     TUint8 transId( aIsiMessage.Get8bit( ISI_HEADER_OFFSET_TRANSID ) );
       
   544 
       
   545     if ( UICC_STATUS_OK  == status )
       
   546         {
       
   547         TUint uiccSbApduOffset( 0 );
       
   548         if ( KErrNone == aIsiMessage.FindSubBlockOffsetById(
       
   549             ISI_HEADER_SIZE + SIZE_UICC_CAT_RESP,
       
   550             UICC_SB_APDU,
       
   551             EIsiSubBlockTypeId16Len16,
       
   552             uiccSbApduOffset ) )
       
   553             {
       
   554             TPtrC8 apduData;
       
   555             TUint16 apduLength( aIsiMessage.Get16bit(
       
   556                 uiccSbApduOffset + UICC_SB_APDU_OFFSET_APDULENGTH ) );
       
   557             apduData.Set( aIsiMessage.GetData(
       
   558                 uiccSbApduOffset + UICC_SB_APDU_OFFSET_APDU,
       
   559                 apduLength ) );
       
   560             // Status bytes are two last bytes in APDU
       
   561             TUint8 sw1( apduData[apduLength - 2] );
       
   562             TUint8 sw2( apduData[apduLength - 1] );
       
   563 
       
   564             // Get Call Control General Result
       
   565             TInt result( TSatUtility::Sw1Sw2Check( sw1, sw2 ) );
       
   566 
       
   567             // This msg comes for envelope, terminal response and
       
   568             // terminal profile. So let's check first if this response is for
       
   569             // CC event by comparing transaction id with the one used when
       
   570             // sending the CC event envelope.
       
   571             TInt ccIndex( GetArrayIndexById( transId ) );
       
   572 
       
   573             // This is a response to either Voice Call, SS or USSD CC envelope
       
   574             if ( ccIndex != KErrNotFound )
       
   575                 {
       
   576                 switch( ( *iCallControlArray )[ccIndex].iRecourceId )
       
   577                     {
       
   578                     case PN_MODEM_CALL:
       
   579                         {
       
   580                         SendCallModemResourceReq(
       
   581                             ( *iCallControlArray )[ccIndex],
       
   582                             result,
       
   583                             apduData );
       
   584                         break;
       
   585                         }
       
   586                     case PN_SS:
       
   587                         {
       
   588                         SendSsResourceControlReq(
       
   589                             ( *iCallControlArray )[ccIndex],
       
   590                             result,
       
   591                             apduData );
       
   592                         break;
       
   593                         }
       
   594                     case PN_GPDS:
       
   595                         {
       
   596                         SendGpdsResourceControlReq(
       
   597                             ( *iCallControlArray )[ccIndex],
       
   598                             result,
       
   599                             apduData );
       
   600                         break;
       
   601                         }
       
   602                     default:
       
   603                         {
       
   604                         break;
       
   605                         }
       
   606                     } // End of switch
       
   607                 iCallControlArray->Remove( ccIndex );
       
   608                 iCallControlArray->Compress();
       
   609                 } // End of if ( ccIndex != KErrNotFound )
       
   610             }
       
   611         else // Subblock is mandatory
       
   612             {
       
   613             TFLOGSTRING("TSY: CSatMessHandler::UiccCatRespEnvelopeReceived - Mandatory subblock UICC_SB_APDU not found");
       
   614             OstTrace0( TRACE_NORMAL, DUP1_CSATCC_UICCCATRESPENVELOPERECEIVED, "CSatCC::UiccCatRespEnvelopeReceived - Mandatory subblock UICC_SB_APDU not found" );
       
   615             }
       
   616         } // End of if ( UICC_STATUS_OK  == status )
       
   617     }
       
   618 
       
   619 // -----------------------------------------------------------------------------
       
   620 // CSatCC::ClearArraysForRefresh
       
   621 // Clears the array containing call control event data due refresh.
       
   622 // Empiric studies show that transaction id count starts from beginning
       
   623 // in SIMSON after refresh and therefore possible incoming responses
       
   624 // for call control are no longer recognizable.
       
   625 // -----------------------------------------------------------------------------
       
   626 //
       
   627 void CSatCC::ClearArraysForRefresh()
       
   628     {
       
   629     OstTrace0( TRACE_NORMAL, CSATCC_CLEARARRAYSFORREFRESH, "CSatCC::ClearArraysForRefresh" );
       
   630     TFLOGSTRING("TSY: CSatCC::ClearArraysForRefresh");
       
   631 
       
   632     iCallControlArray->Reset();
       
   633     }
       
   634 
       
   635 // -----------------------------------------------------------------------------
       
   636 // CSatCC::SetStatusOfUssdSupport
       
   637 // Set internal flag according to EF-SST
       
   638 // -----------------------------------------------------------------------------
       
   639 //
       
   640 void CSatCC::SetStatusOfUssdSupport
       
   641         (
       
   642         TBool aStatus
       
   643         )
       
   644     {
       
   645     OstTrace0( TRACE_NORMAL, CSATCC_SETSTATUSOFUSSDSUPPORT, "CSatCC::SetStatusOfUssdSupport" );
       
   646     TFLOGSTRING("TSY: CSatCC::SetStatusOfUssdSupport");
       
   647     iUssdTlvSupported = aStatus;
       
   648     }
       
   649 
       
   650 // -----------------------------------------------------------------------------
       
   651 // CSatCC::IsOnlyDigitsInUssd
       
   652 // This methods returns ETrue when a Ussd string contains only "*", "#",
       
   653 // and the numbers 0-9.
       
   654 // Note: Ussd string is always received in packed format, when  it 7-bit GSM
       
   655 // default alphabet.
       
   656 // -----------------------------------------------------------------------------
       
   657 //
       
   658 TBool CSatCC::IsOnlyDigitsInUssd
       
   659         (
       
   660         TPtrC8 aUSSDString
       
   661         )
       
   662     {
       
   663     OstTrace0( TRACE_NORMAL, CSATCC_ISONLYDIGITSINUSSD, "CSatCC::IsOnlyDigitsInUssd" );
       
   664     TFLOGSTRING("TSY: CSatCC::IsOnlyDigitsInUssd");
       
   665 
       
   666     // Unpack it
       
   667     TBuf8<256> ussdString;
       
   668     TSatUtility::Packed7to8Unpacked( aUSSDString, ussdString );
       
   669 
       
   670     TBool ret( ETrue );
       
   671     for( TInt k=0; k < ussdString.Length(); k++)
       
   672         {
       
   673         if ( ussdString[k]!='#' &&
       
   674              ussdString[k]!='*' &&
       
   675              ussdString[k]!='+' &&
       
   676              ( ussdString[k]<'0'  ||
       
   677              ussdString[k]>'9' ) )
       
   678             {
       
   679             ret = EFalse;
       
   680             break;
       
   681             }
       
   682         }
       
   683 
       
   684     return ret;
       
   685     }
       
   686 
       
   687 
       
   688 // -----------------------------------------------------------------------------
       
   689 // CSatCC::MessageReceivedL
       
   690 // Handle received messages related to event download
       
   691 // Called by CSatMessHandler::MessageReceivedL, when a new ISI message arrives.
       
   692 // -----------------------------------------------------------------------------
       
   693 //
       
   694 void CSatCC::MessageReceivedL
       
   695         (
       
   696         const TIsiReceiveC& aIsiMessage
       
   697         )
       
   698     {
       
   699     OstTrace0( TRACE_NORMAL, CSATCC_MESSAGERECEIVEDL, "CSatCC::MessageReceivedL" );
       
   700     TFLOGSTRING("TSY: CSatCC::MessageReceivedL");
       
   701 
       
   702     TUint8 resource( aIsiMessage.Get8bit( ISI_HEADER_OFFSET_RESOURCEID ) );
       
   703     TUint8 messageId( aIsiMessage.Get8bit( ISI_HEADER_OFFSET_MESSAGEID ) );
       
   704 
       
   705 
       
   706     if ( PN_MODEM_CALL == resource )
       
   707         {
       
   708         switch( messageId )
       
   709             {
       
   710             case CALL_MODEM_RESOURCE_IND:
       
   711                 {
       
   712                 CallModemResourceInd( aIsiMessage );
       
   713                 break;
       
   714                 }
       
   715             case CALL_MODEM_RESOURCE_CONF_IND:
       
   716                 {
       
   717     TFLOGSTRING("TSY: CSatCC::MessageReceived, CALL_MODEM_RESOURCE_CONF_IND");
       
   718     OstTrace0( TRACE_NORMAL, DUP1_CSATCC_MESSAGERECEIVED, "TSY: CSatCC::MessageReceived, CALL_MODEM_RESOURCE_CONF_IND" );
       
   719                 
       
   720                 if ( CALL_MODEM_RES_CONF_STARTUP == 
       
   721                     aIsiMessage.Get8bit( ISI_HEADER_SIZE + 
       
   722                         CALL_MODEM_RESOURCE_CONF_IND_OFFSET_CONFSTATUS ) )
       
   723                     {
       
   724                     // configure resource control if CC enabled in (U)SIM
       
   725                     // MT call is always controlled by NTSY
       
   726                     if ( iCallControlEnabled )
       
   727                         {
       
   728                         iSatMessHandler->CallModemResourceConfReq(
       
   729                             CALL_MODEM_RES_ID_MO_INIT |
       
   730                             CALL_MODEM_RES_ID_MT_INIT,
       
   731                             CALL_MODEM_RES_ID_MASK_MO_INIT |
       
   732                             CALL_MODEM_RES_ID_MASK_MT_INIT );
       
   733                         }
       
   734                     else
       
   735                         {
       
   736                         iSatMessHandler->CallModemResourceConfReq(
       
   737                             CALL_MODEM_RES_ID_MT_INIT,
       
   738                             CALL_MODEM_RES_ID_MASK_MT_INIT );
       
   739                         }
       
   740                     }
       
   741                 break;
       
   742                 }
       
   743             case CALL_MODEM_RESOURCE_CONF_RESP:
       
   744                 {
       
   745     TFLOGSTRING("TSY: CSatCC::MessageReceived, CALL_MODEM_RESOURCE_CONF_RESP");
       
   746     OstTrace0( TRACE_NORMAL, DUP2_CSATCC_MESSAGERECEIVED, "TSY: CSatCC::MessageReceived, CALL_MODEM_RESOURCE_CONF_RESP" );
       
   747     
       
   748                 if ( CALL_MODEM_RES_CONF_SET == 
       
   749                     aIsiMessage.Get8bit( ISI_HEADER_SIZE + 
       
   750                         CALL_MODEM_RESOURCE_CONF_RESP_OFFSET_CONFOPERATION ) )
       
   751                     {
       
   752     TFLOGSTRING("TSY: CSatCC::MessageReceived, CALL_MODEM_RESOURCE_CONF_RESP Resource configured");
       
   753     OstTrace0( TRACE_NORMAL, DUP3_CSATCC_MESSAGERECEIVED, "TSY: CSatCC::MessageReceived, CALL_MODEM_RESOURCE_CONF_RESP Resource configured" );
       
   754     
       
   755                     }
       
   756                 break;
       
   757                 }
       
   758             case CALL_MODEM_RESOURCE_RESP:
       
   759                 {
       
   760     TFLOGSTRING("TSY: CSatCC::MessageReceived, CALL_MODEM_RESOURCE_RESP Resource control sequence done");
       
   761     OstTrace0( TRACE_NORMAL, DUP4_CSATCC_MESSAGERECEIVED, "TSY: CSatCC::MessageReceived, CALL_MODEM_RESOURCE_RESP Resource control sequence done" );
       
   762     
       
   763                 break;
       
   764                 }
       
   765             default:
       
   766                 {
       
   767                 // none
       
   768                 break;
       
   769                 }
       
   770 
       
   771             }
       
   772         }
       
   773     else if ( PN_SS == resource )
       
   774         {
       
   775         switch( messageId )
       
   776             {
       
   777             case SS_RESOURCE_CONTROL_IND:
       
   778                 {
       
   779                 SsResourceControlInd( aIsiMessage );
       
   780                 break;
       
   781                 }
       
   782             case SS_RESOURCE_CONF_IND:
       
   783                 {
       
   784     TFLOGSTRING("TSY: CSatCC::MessageReceived, SS_RESOURCE_CONF_IND");
       
   785     OstTrace0( TRACE_NORMAL, DUP5_CSATCC_MESSAGERECEIVED, "TSY: CSatCC::MessageReceived, SS_RESOURCE_CONF_IND" );
       
   786     
       
   787                 if ( SS_RESOURCE_CONF_READY  == 
       
   788                     aIsiMessage.Get8bit( ISI_HEADER_SIZE + 
       
   789                         SS_RESOURCE_CONF_IND_OFFSET_CONFSTATUS  ) )
       
   790                     {
       
   791                     // configure resource control if CC enabled in (U)SIM
       
   792                     if ( iCallControlEnabled )
       
   793                         {
       
   794                         iSatMessHandler->SsResourceConfReq();
       
   795                         }
       
   796                     }
       
   797                 break;
       
   798                 }
       
   799             case SS_RESOURCE_CONF_RESP:
       
   800                 {
       
   801                 if ( SS_RESOURCE_CONF_SET == 
       
   802                         aIsiMessage.Get8bit( ISI_HEADER_SIZE + 
       
   803                             SS_RESOURCE_CONF_RESP_OFFSET_CONFOPERATION  ) )
       
   804                     {
       
   805     TFLOGSTRING("TSY: CSatCC::MessageReceived, SS_RESOURCE_CONF_RESP Resource configured");
       
   806     OstTrace0( TRACE_NORMAL, DUP6_CSATCC_MESSAGERECEIVED, "TSY: CSatCC::MessageReceived, SS_RESOURCE_CONF_RESP Resource configured" );
       
   807     
       
   808                     }
       
   809                 break;
       
   810                 }
       
   811             case SS_STATUS_IND:
       
   812                 {
       
   813                 TUint8 status( aIsiMessage.Get8bit( ISI_HEADER_SIZE + 
       
   814                     SS_STATUS_IND_OFFSET_SSSTATUSINDICATION  ) );
       
   815 
       
   816                 if ( SS_STATUS_REQUEST_SERVICE_FAILED == status
       
   817                     || SS_GSM_STATUS_REQUEST_USSD_FAILED )
       
   818                     {
       
   819                     if( iEnvelopeResponseData )
       
   820                         {
       
   821                         iSatMessaging->NotifyClientAboutCallControlEventL(
       
   822                             iCcResult,
       
   823                             iEnvelopeResponseData->Des() );
       
   824                         // Delete temporarily stored envelope response data
       
   825                         delete iEnvelopeResponseData;
       
   826                         // No matter what the response was, set related data to
       
   827                         // init values
       
   828                         iCcResult = KAllowed;
       
   829                         }
       
   830                     }
       
   831                 break;
       
   832                 }
       
   833             default:
       
   834                 {
       
   835                 // none
       
   836                 break;
       
   837                 }
       
   838             }
       
   839         }
       
   840     else if ( PN_GPDS == resource )
       
   841         {
       
   842         switch( messageId )
       
   843             {
       
   844             case GPDS_RESOURCE_CONTROL_IND:
       
   845                 {
       
   846                 GpdsResourceControlInd( aIsiMessage );
       
   847                 break;
       
   848                 }
       
   849             case GPDS_RESOURCE_CONTROL_RESP:
       
   850                 {
       
   851     TFLOGSTRING("TSY: CSatCC::MessageReceived, GPDS_RESOURCE_CONTROL_RESP Resource control sequence done");
       
   852     OstTrace0( TRACE_NORMAL, DUP7_CSATCC_MESSAGERECEIVED, "TSY: CSatCC::MessageReceived, GPDS_RESOURCE_CONTROL_RESP Resource control sequence done" );
       
   853 
       
   854                 break;
       
   855                 }
       
   856             case GPDS_RESOURCE_CONF_IND:
       
   857                 {
       
   858     TFLOGSTRING("TSY: CSatCC::MessageReceived, GPDS_RESOURCE_CONF_IND");
       
   859     OstTrace0( TRACE_NORMAL, DUP8_CSATCC_MESSAGERECEIVED, "TSY: CSatCC::MessageReceived, GPDS_RESOURCE_CONF_IND" );
       
   860 
       
   861                 if ( iCallControlOnGPRSEnabled )
       
   862                     {
       
   863                     iSatMessHandler->GpdsResourceConfReq();
       
   864                     }
       
   865                 break;
       
   866                 }
       
   867             case GPDS_RESOURCE_CONF_RESP:
       
   868                 {
       
   869                 if ( GPDS_RESOURCE_CONF_SET == 
       
   870                         aIsiMessage.Get8bit( ISI_HEADER_SIZE + 
       
   871                             GPDS_RESOURCE_CONF_RESP_OFFSET_CONFOPERATION  ) )
       
   872                     {
       
   873     TFLOGSTRING("TSY: CSatCC::MessageReceived, GPDS_RESOURCE_CONF_RESP Resource configured");
       
   874     OstTrace0( TRACE_NORMAL, DUP9_CSATCC_MESSAGERECEIVED, "TSY: CSatCC::MessageReceived, GPDS_RESOURCE_CONF_RESP Resource configured" );
       
   875 
       
   876                     }
       
   877                 break;
       
   878                 }
       
   879             default:
       
   880                 {
       
   881                 // none
       
   882                 break;
       
   883                 }
       
   884             }
       
   885         }
       
   886     else if ( PN_UICC == resource )
       
   887         {
       
   888         switch( messageId )
       
   889             {
       
   890             case UICC_APPL_CMD_RESP:
       
   891                 {
       
   892                 TUint8 trId( aIsiMessage.Get8bit(
       
   893                     ISI_HEADER_SIZE + UICC_APPL_CMD_RESP_OFFSET_TRANSID ) );
       
   894                 TUint8 status( aIsiMessage.Get8bit( ISI_HEADER_SIZE +
       
   895                     UICC_APPL_CMD_RESP_OFFSET_STATUS ) );
       
   896                 TUint8 serviceType( aIsiMessage.Get8bit( ISI_HEADER_SIZE +
       
   897                     UICC_APPL_CMD_RESP_OFFSET_SERVICETYPE ) );
       
   898                 // Card type
       
   899                 TUint8 cardType( aIsiMessage.Get8bit(
       
   900                     ISI_HEADER_SIZE + UICC_APPL_CMD_RESP_OFFSET_CARDTYPE ) );
       
   901 
       
   902                 if ( UICC_STATUS_OK == status &&
       
   903                     UICC_APPL_READ_TRANSPARENT == serviceType )
       
   904                     {
       
   905                     // Read file data from UICC_SB_FILE_DATA
       
   906                     TInt fileDataLength( 0 );
       
   907                     TPtrC8 fileData;
       
   908                     TUint uiccSbFileDataOffset( 0 );
       
   909                     if ( KErrNone == aIsiMessage.FindSubBlockOffsetById(
       
   910                         ISI_HEADER_SIZE + SIZE_UICC_APPL_CMD_RESP,
       
   911                         UICC_SB_FILE_DATA,
       
   912                         EIsiSubBlockTypeId16Len16,
       
   913                         uiccSbFileDataOffset ) )
       
   914                         {
       
   915                         fileDataLength = aIsiMessage.Get32bit(
       
   916                             uiccSbFileDataOffset + UICC_SB_FILE_DATA_OFFSET_DATALENGTH );
       
   917                         fileData.Set( aIsiMessage.GetData(
       
   918                             uiccSbFileDataOffset + UICC_SB_FILE_DATA_OFFSET_DATA,
       
   919                             fileDataLength ) );
       
   920                         // Check call control status
       
   921                         if ( KUiccTrIdServiceTableByte4 == trId )
       
   922                             {
       
   923                             TUint8 usedBitMaskCallControl( KCallControlBitMaskUsim );
       
   924                             if ( UICC_CARD_TYPE_ICC == cardType )
       
   925                                 {
       
   926                                 usedBitMaskCallControl = KCallControlBitMaskSim;
       
   927                                 }
       
   928                             // Bit 6 is the status bit of call control
       
   929                             if ( fileData[0] & usedBitMaskCallControl )
       
   930                                 {
       
   931                                 // Call control enabled in (U)SIM
       
   932                                 iCallControlEnabled = ETrue;
       
   933                                 iSatMessHandler->CallModemResourceConfReq(
       
   934                                     CALL_MODEM_RES_ID_MO_INIT |
       
   935                                     CALL_MODEM_RES_ID_MT_INIT,
       
   936                                     CALL_MODEM_RES_ID_MASK_MO_INIT |
       
   937                                     CALL_MODEM_RES_ID_MASK_MT_INIT );
       
   938                                 iSatMessHandler->SsResourceConfReq();
       
   939                                 }
       
   940                              else
       
   941                                 {
       
   942                                 // Call control disabled in (U)SIM
       
   943                                 iCallControlEnabled = EFalse;
       
   944                                 iSatMessHandler->CallModemResourceConfReq(
       
   945                                     CALL_MODEM_RES_ID_MT_INIT,
       
   946                                     CALL_MODEM_RES_ID_MASK_MT_INIT );
       
   947                                 }
       
   948                             }
       
   949                         // Check call control GPRS status
       
   950                         else if ( KUiccTrIdServiceTableByte7 == trId )
       
   951                             {
       
   952                             if ( fileData[0] & KCallControlBitMaskUsim )
       
   953                                 {
       
   954                                 // Call control on GPRS enabled in USIM
       
   955                                 iCallControlOnGPRSEnabled = ETrue;
       
   956                                 iSatMessHandler->GpdsResourceConfReq();
       
   957                                 }
       
   958                             else
       
   959                                 {
       
   960                                 // Call control on GPRS disabled in USIM
       
   961                                 iCallControlOnGPRSEnabled = EFalse;
       
   962                                 }
       
   963                             }
       
   964                         }
       
   965                     else // Subblock is mandatory
       
   966                         {
       
   967                         TFLOGSTRING("TSY: CSatCC::MessageReceivedL - Mandatory subblock UICC_SB_FILE_DATA not found");
       
   968                         OstTrace0( TRACE_NORMAL, DUP1_CSATCC_MESSAGERECEIVEDL, "CSatCC::MessageReceivedL - - Mandatory subblock UICC_SB_FILE_DATA not found" );
       
   969                         }
       
   970                     } // End of if ( UICC_STATUS_OK == status
       
   971                 break;
       
   972                 } // End of case UICC_APPL_CMD_RESP
       
   973             case UICC_CAT_RESP:
       
   974                 {
       
   975                 // In case of envelope response handle the data
       
   976                 TUint8 serviceType(
       
   977                     aIsiMessage.Get8bit(
       
   978                         ISI_HEADER_SIZE + UICC_CAT_RESP_OFFSET_SERVICETYPE ) );
       
   979                 if ( UICC_CAT_ENVELOPE == serviceType )
       
   980                     {
       
   981                     UiccCatRespEnvelopeReceived( aIsiMessage );
       
   982                     }
       
   983                 break;
       
   984                 }
       
   985             default:
       
   986                 {
       
   987                 break;
       
   988                 }
       
   989             } // End of switch( messageId )
       
   990         } // End of else if ( PN_UICC == resource )
       
   991     // No else
       
   992     }
       
   993 
       
   994 // -----------------------------------------------------------------------------
       
   995 // CSatCC::SetTonNpi
       
   996 // Set CSatCC internal Ton and Npi
       
   997 // Called by CTsySatMessaging::SetTonNpi when SEND SS proactive command arrives
       
   998 // -----------------------------------------------------------------------------
       
   999 //
       
  1000 void CSatCC::SetTonNpi
       
  1001         (
       
  1002         const TUint8 aTonNpi
       
  1003         )
       
  1004     {
       
  1005     OstTrace0( TRACE_NORMAL, CSATCC_SETTONNPI, "CSatCC::SetTonNpi" );
       
  1006     TFLOGSTRING("TSY: CSatCC::SetTonNpi");
       
  1007 
       
  1008     iTonNpiForSS = aTonNpi;
       
  1009     iTonNpiPresent = ETrue;
       
  1010     }
       
  1011 
       
  1012 // -----------------------------------------------------------------------------
       
  1013 // CSatCC::CallModemResourceInd
       
  1014 // Handles resource control request from modem Call server
       
  1015 // -----------------------------------------------------------------------------
       
  1016 //
       
  1017 void CSatCC::CallModemResourceInd( const TIsiReceiveC& aIsiMessage )
       
  1018     {
       
  1019     TFLOGSTRING("TSY: CSatCC::CallModemResourceInd");
       
  1020     OstTrace0( TRACE_NORMAL, CSATCC_CALLMODEMRESOURCEIND, "CSatCC::CallModemResourceInd" );
       
  1021 
       
  1022     TUint sbStartOffset( 0 );
       
  1023     // Check if resource control is requested for MO call.
       
  1024 
       
  1025     TInt retValue( aIsiMessage.FindSubBlockOffsetById(
       
  1026            ISI_HEADER_SIZE + SIZE_CALL_MODEM_RESOURCE_IND ,
       
  1027            CALL_MODEM_SB_RESOURCE,
       
  1028            EIsiSubBlockTypeId8Len8,
       
  1029            sbStartOffset ) );
       
  1030 
       
  1031     if ( KErrNone == retValue 
       
  1032         && CALL_MODEM_RES_ID_MO_INIT & aIsiMessage.Get16bit( sbStartOffset +
       
  1033             CALL_MODEM_SB_RESOURCE_OFFSET_RES  ) )
       
  1034         {
       
  1035         TCallControl callcontrol;
       
  1036         // store traid's
       
  1037         callcontrol.iTransId = aIsiMessage.Get8bit( ISI_HEADER_SIZE + 
       
  1038             CALL_MODEM_RESOURCE_IND_OFFSET_TRID );
       
  1039         callcontrol.iRecourceId = aIsiMessage.Get8bit(
       
  1040             ISI_HEADER_OFFSET_RESOURCEID);
       
  1041         callcontrol.iCallId = aIsiMessage.Get8bit( ISI_HEADER_SIZE + 
       
  1042             CALL_MODEM_RESOURCE_IND_OFFSET_CALLID );
       
  1043 
       
  1044         retValue = aIsiMessage.FindSubBlockOffsetById(
       
  1045            ISI_HEADER_SIZE + SIZE_CALL_MODEM_RESOURCE_IND ,
       
  1046            CALL_MODEM_SB_RESOURCE_SEQ_ID,
       
  1047            EIsiSubBlockTypeId8Len8,
       
  1048            sbStartOffset );
       
  1049         if( KErrNone == retValue )
       
  1050             {
       
  1051             callcontrol.iResourceSeqId = aIsiMessage.Get8bit( sbStartOffset + 
       
  1052                 CALL_MODEM_SB_RESOURCE_SEQ_ID_OFFSET_SEQUENCEID );
       
  1053             }
       
  1054 
       
  1055         retValue = aIsiMessage.FindSubBlockOffsetById(
       
  1056             ISI_HEADER_SIZE + SIZE_CALL_MODEM_RESOURCE_IND ,
       
  1057             CALL_MODEM_SB_MODE,
       
  1058             EIsiSubBlockTypeId8Len8,
       
  1059             sbStartOffset );
       
  1060         if( KErrNone == retValue )
       
  1061             {
       
  1062             callcontrol.iCallMode.Append( aIsiMessage.Get8bit( sbStartOffset + 
       
  1063                 CALL_MODEM_SB_MODE_OFFSET_MODE ) );
       
  1064             callcontrol.iCallMode.Append( aIsiMessage.Get8bit( sbStartOffset + 
       
  1065                 CALL_MODEM_SB_MODE_OFFSET_MODEINFO ) );
       
  1066             }
       
  1067 
       
  1068         retValue = aIsiMessage.FindSubBlockOffsetById(
       
  1069             ISI_HEADER_SIZE + SIZE_CALL_MODEM_RESOURCE_IND ,
       
  1070             CALL_MODEM_SB_BC,
       
  1071             EIsiSubBlockTypeId8Len8,
       
  1072             sbStartOffset );
       
  1073         if( KErrNone == retValue )
       
  1074             {
       
  1075             TInt bearerLength( aIsiMessage.Get8bit( sbStartOffset +
       
  1076                 CALL_MODEM_SB_BC_OFFSET_BCLENGTH ) );
       
  1077             
       
  1078             callcontrol.iBearerCapabilities.Copy( aIsiMessage.GetData( 
       
  1079                 sbStartOffset + CALL_MODEM_SB_BC_OFFSET_BCDATA,
       
  1080                 bearerLength ) );
       
  1081             }
       
  1082 
       
  1083         retValue = aIsiMessage.FindSubBlockOffsetById(
       
  1084            ISI_HEADER_SIZE + SIZE_CALL_MODEM_RESOURCE_IND ,
       
  1085            CALL_MODEM_SB_DESTINATION_ADDRESS,
       
  1086            EIsiSubBlockTypeId8Len8,
       
  1087            sbStartOffset );
       
  1088 
       
  1089         if( KErrNone == retValue )
       
  1090             {
       
  1091             callcontrol.iAddressType = aIsiMessage.Get8bit( sbStartOffset +
       
  1092                 CALL_MODEM_SB_DESTINATION_ADDRESS_OFFSET_ADDRTYPE );
       
  1093             TUint8 addressLength( aIsiMessage.Get8bit( sbStartOffset +
       
  1094                 CALL_MODEM_SB_DESTINATION_ADDRESS_OFFSET_ADDRLEN ) );
       
  1095             callcontrol.iString.Copy( aIsiMessage.GetData( sbStartOffset + 
       
  1096                 CALL_MODEM_SB_DESTINATION_ADDRESS_OFFSET_ADDR,
       
  1097                 addressLength * 2 ) );
       
  1098             }
       
  1099 
       
  1100         if( CALL_MODEM_MODE_EMERGENCY == callcontrol.iCallMode[0] )
       
  1101             {
       
  1102             // Do not make SIM call control, allow emergency calls always
       
  1103             TPtrC8 atkData;
       
  1104             SendCallModemResourceReq(
       
  1105                 callcontrol,
       
  1106                 KAllowed,
       
  1107                 atkData );
       
  1108             }
       
  1109         else
       
  1110             {
       
  1111             // store struct
       
  1112             iCallControlArray->Append( callcontrol );
       
  1113             // Send envelope
       
  1114             SendCallEnvelope( aIsiMessage, callcontrol );
       
  1115             }
       
  1116         }
       
  1117     }
       
  1118 
       
  1119 // -----------------------------------------------------------------------------
       
  1120 // CSatCC::SendCallModemResourceReq
       
  1121 // Creates resource control response for modem Call server
       
  1122 // -----------------------------------------------------------------------------
       
  1123 //
       
  1124 void CSatCC::SendCallModemResourceReq(
       
  1125     const TCallControl& aTcc,
       
  1126     const TUint8 aResult,
       
  1127     TPtrC8 aApduData )
       
  1128     {
       
  1129     TFLOGSTRING("TSY: CSatCC::SendCallModemResourceReq");
       
  1130     OstTrace0( TRACE_NORMAL, CSATCC_SENDCALLMODEMRESOURCEREQ, "CSatCC::SendCallModemResourceReq" );
       
  1131 
       
  1132     TBuf8<KMaximumCcBufferSize> isiMessage;
       
  1133     TInt ret( KErrNotFound );
       
  1134     CBerTlv response;
       
  1135     response.SetData( aApduData );
       
  1136     // Set initial cc result, e.g. the SIM has responded with sw1/sw2 90 00
       
  1137     // without any additional data. In error case reject the initiated action.
       
  1138     TUint8 ccresult( KAllowed == aResult ?
       
  1139         KCcResultAllowedNoModification : KCcResultNotAllowed );
       
  1140     // if result provided in SIM response
       
  1141     if ( KCcEmptyResponseLenght < aApduData.Length() )
       
  1142         {
       
  1143         ccresult = aApduData[ 0 ];
       
  1144         }
       
  1145     // Internal call control result
       
  1146     TUint8 internalCcResult( KAllowed );
       
  1147     // CALL_MODEM_RESOURCE_REQ has 5 mandatory sb's
       
  1148     TUint8 sbcount( 5 );
       
  1149 
       
  1150     // Add mandatory data
       
  1151     // Modem Call ID [M]: the unique call ID or CALL_ID_NONE.
       
  1152     isiMessage.Append( aTcc.iCallId );
       
  1153     // CALL_MODEM_SB_RESOURCE [M]: resource. Shall be same as in the corresponding indication.
       
  1154     TIsiSubBlock resource( 
       
  1155         isiMessage,
       
  1156         CALL_MODEM_SB_RESOURCE,
       
  1157         EIsiSubBlockTypeId8Len8 );
       
  1158     TSatUtility::AppendWord( CALL_MODEM_RES_ID_MO_INIT, isiMessage );
       
  1159     resource.CompleteSubBlock();
       
  1160     
       
  1161     // CALL_MODEM_SB_RESOURCE_SEQ_ID [M]: Sequence ID. Shall be same as in the corresponding indication.
       
  1162     TIsiSubBlock resourceSeqId( 
       
  1163         isiMessage,
       
  1164         CALL_MODEM_SB_RESOURCE_SEQ_ID,
       
  1165         EIsiSubBlockTypeId8Len8 );
       
  1166     isiMessage.Append( aTcc.iResourceSeqId  );
       
  1167     isiMessage.Append( KPadding );
       
  1168     resourceSeqId.CompleteSubBlock();
       
  1169 
       
  1170     // CALL_MODEM_SB_RESOURCE_STATUS [M]: resource status is allowed or denied.
       
  1171     TIsiSubBlock status(
       
  1172         isiMessage,
       
  1173         CALL_MODEM_SB_RESOURCE_STATUS,
       
  1174         EIsiSubBlockTypeId8Len8 );
       
  1175 
       
  1176     switch( ccresult )
       
  1177         {
       
  1178         case KCcResultAllowedNoModification:
       
  1179             {
       
  1180             isiMessage.Append( CALL_MODEM_RESOURCE_ALLOWED );
       
  1181             isiMessage.Append( KPadding );
       
  1182             break;
       
  1183             }
       
  1184         case KCcResultNotAllowed:
       
  1185             {
       
  1186             isiMessage.Append( CALL_MODEM_RESOURCE_DENIED );
       
  1187             isiMessage.Append( KPadding );
       
  1188             internalCcResult = KRejected;
       
  1189             break;
       
  1190             }
       
  1191         case KCcResultAllowedWithModifications:
       
  1192             {
       
  1193             // First check if this has been modified to a new SS/USSD action
       
  1194             CTlv ssServerString;
       
  1195             
       
  1196             if ( KErrNone == response.TlvByTagValue( &ssServerString, 
       
  1197                 KTlvSsStringTag ) ||
       
  1198                 KErrNone == response.TlvByTagValue( &ssServerString,
       
  1199                 KTlvUssdStringTag ) )
       
  1200                 {
       
  1201                 isiMessage.Append( CALL_MODEM_RESOURCE_DENIED );
       
  1202                 isiMessage.Append( KPadding );
       
  1203                 internalCcResult = KChanged;
       
  1204                 }
       
  1205             else
       
  1206                 {
       
  1207                 // Other parameters have been changed
       
  1208                 isiMessage.Append( CALL_MODEM_RESOURCE_ALLOWED );
       
  1209                 isiMessage.Append( KPadding );
       
  1210                 internalCcResult = KModified;
       
  1211                 }
       
  1212             break;
       
  1213             }
       
  1214         default:
       
  1215             {
       
  1216             break;
       
  1217             }
       
  1218         }
       
  1219     status.CompleteSubBlock();
       
  1220 
       
  1221     if ( KRejected == internalCcResult || KChanged == internalCcResult )
       
  1222         {
       
  1223         // CALL_MODEM_SB_CAUSE sb is needed in rejected cases
       
  1224         TIsiSubBlock cause( 
       
  1225             isiMessage,
       
  1226             CALL_MODEM_SB_CAUSE,
       
  1227             EIsiSubBlockTypeId8Len8 );
       
  1228         isiMessage.Append( CALL_MODEM_CAUSE_TYPE_CLIENT  );
       
  1229         isiMessage.Append( CALL_MODEM_CAUSE_NOT_ALLOWED );
       
  1230         cause.CompleteSubBlock();
       
  1231         sbcount++;
       
  1232         }
       
  1233     
       
  1234     // CALL_MODEM_SB_MODE [M]: call mode.
       
  1235     TIsiSubBlock mode( 
       
  1236         isiMessage,
       
  1237         CALL_MODEM_SB_MODE,
       
  1238         EIsiSubBlockTypeId8Len8 );
       
  1239     // 2 byte buffer
       
  1240     isiMessage.Append( aTcc.iCallMode );
       
  1241     mode.CompleteSubBlock();
       
  1242     
       
  1243     // CALL_MODEM_SB_BC [M]: Bearer Capabilities for the call.
       
  1244     TIsiSubBlock bearer( 
       
  1245         isiMessage,
       
  1246         CALL_MODEM_SB_BC,
       
  1247         EIsiSubBlockTypeId8Len8 );
       
  1248 
       
  1249     // Check if (U)SIM has provided new bearer caps
       
  1250     CTlv bcTlv;
       
  1251     if ( KCcEmptyResponseLenght < aApduData.Length() &&
       
  1252         KErrNone == response.TlvByTagValue( &bcTlv,
       
  1253             KTlvCapabilityConfigurationParametersTag ) )
       
  1254         {
       
  1255         // BC length is the first byte in BC data
       
  1256         isiMessage.Append( bcTlv.GetData(
       
  1257             ETLV_CapabilityConfigurationParameters ) );
       
  1258         }
       
  1259     else
       
  1260         {
       
  1261         isiMessage.Append( aTcc.iBearerCapabilities.Length() );
       
  1262         isiMessage.Append( aTcc.iBearerCapabilities );
       
  1263         }
       
  1264     bearer.CompleteSubBlock();
       
  1265 
       
  1266     TIsiSubBlock address( 
       
  1267         isiMessage,
       
  1268         CALL_MODEM_SB_DESTINATION_ADDRESS ,
       
  1269         EIsiSubBlockTypeId8Len8 );
       
  1270     // Check if request has been modified and therefore response includes
       
  1271     // additional data
       
  1272     if ( KModified == internalCcResult &&
       
  1273         ( KCcEmptyResponseLenght < aApduData.Length() ) )
       
  1274         {
       
  1275         CTlv addressTlv;
       
  1276         ret = response.TlvByTagValue( &addressTlv, KTlvAddressTag );
       
  1277         if ( KErrNone == ret  )
       
  1278             {
       
  1279             // CALL_MODEM_ADDRESS_TYPE, mask MSB off
       
  1280             isiMessage.Append( addressTlv.GetValue()[ 0 ] ^KMSBMask );
       
  1281             isiMessage.Append( KPadding );
       
  1282             isiMessage.Append( KPadding );
       
  1283             
       
  1284             // Temp storage for address
       
  1285             TBuf8<2 * KCallServerMaxAddressLenght> asciiAddress;
       
  1286             TSatUtility::BCDToAscii( addressTlv.GetValue().Mid( 1 ),
       
  1287                 asciiAddress );
       
  1288 
       
  1289             //add the number string as unicode.
       
  1290             TBuf16<KCallServerMaxAddressLenght> unicodeNumber;
       
  1291             TSatUtility::ConvertSms7ToUnicode16( unicodeNumber, asciiAddress );
       
  1292             TBuf8<2 * KCallServerMaxAddressLenght> temp;
       
  1293             TIsiUtility::CopyToBigEndian( unicodeNumber, temp );
       
  1294             
       
  1295             // Address length = Number of Unicode characters in address
       
  1296             isiMessage.Append( temp.Length()/2 );
       
  1297             isiMessage.Append( temp );
       
  1298             
       
  1299             address.CompleteSubBlock();
       
  1300             sbcount++;
       
  1301             }
       
  1302         
       
  1303         CTlv subAddressTlv;
       
  1304         ret = response.TlvByTagValue( &subAddressTlv, KTlvSubaddressTag );
       
  1305         if ( KErrNone == ret )
       
  1306             {
       
  1307             TIsiSubBlock subAddress( 
       
  1308                 isiMessage,
       
  1309                 CALL_MODEM_SB_DESTINATION_SUBADDRESS,
       
  1310                 EIsiSubBlockTypeId8Len8 );
       
  1311             isiMessage.Append( subAddressTlv.GetLength() );
       
  1312             isiMessage.Append( subAddressTlv.GetData( ETLV_SubAddress ) );
       
  1313             subAddress.CompleteSubBlock();
       
  1314             sbcount++;
       
  1315             }
       
  1316         }
       
  1317     else
       
  1318         {
       
  1319         // use original destination address
       
  1320         isiMessage.Append( aTcc.iAddressType );
       
  1321         isiMessage.Append( KPadding );
       
  1322         isiMessage.Append( KPadding );
       
  1323         // Number of Unicode characters
       
  1324         isiMessage.Append( aTcc.iString.Length()/2 );
       
  1325         isiMessage.Append( aTcc.iString );
       
  1326         address.CompleteSubBlock();
       
  1327         sbcount++;
       
  1328         }
       
  1329 
       
  1330     TBuf8<1> numOfSubblocks;
       
  1331     numOfSubblocks.Append( sbcount);
       
  1332     isiMessage.Insert( 1, numOfSubblocks );
       
  1333     // send request
       
  1334     iSatMessHandler->CallModemResourceReq( aTcc.iTransId, isiMessage );
       
  1335 
       
  1336     if ( KCcEmptyResponseLenght < aApduData.Length() )
       
  1337         {
       
  1338         // Notify client about call control if alpha id present or original
       
  1339         // action has changed to new action
       
  1340         iSatMessaging->NotifyClientAboutCallControlEventL(
       
  1341             internalCcResult,
       
  1342             aApduData );
       
  1343         }
       
  1344    }
       
  1345 
       
  1346 // -----------------------------------------------------------------------------
       
  1347 // CSatCC::SsResourceControlInd
       
  1348 // Handles resource control request from modem SS server
       
  1349 // -----------------------------------------------------------------------------
       
  1350 //
       
  1351 void CSatCC::SsResourceControlInd( const TIsiReceiveC& aIsiMessage )
       
  1352     {
       
  1353     TFLOGSTRING("TSY: CSatCC::SsResourceControlInd");
       
  1354     OstTrace0( TRACE_NORMAL, CSATCC_SSRESOURCECONTROLIND, "CSatCC::SsResourceControlInd" );
       
  1355 
       
  1356     TCallControl callcontrol;
       
  1357     TInt stringLength;
       
  1358     // store traid's
       
  1359     callcontrol.iTransId = aIsiMessage.Get8bit( ISI_HEADER_SIZE + 
       
  1360         SS_RESOURCE_CONTROL_IND_OFFSET_TRANSID );    
       
  1361     callcontrol.iRecourceId = aIsiMessage.Get8bit(
       
  1362         ISI_HEADER_OFFSET_RESOURCEID);
       
  1363 
       
  1364     TUint sbStartOffset( 0 );
       
  1365     TInt retValue( aIsiMessage.FindSubBlockOffsetById(
       
  1366        ISI_HEADER_SIZE + SIZE_SS_RESOURCE_CONTROL_IND,
       
  1367        SS_SB_RESOURCE_SEQ_ID,
       
  1368        EIsiSubBlockTypeId8Len8,
       
  1369        sbStartOffset ) );
       
  1370     
       
  1371     if( KErrNone == retValue )
       
  1372         {
       
  1373         callcontrol.iResourceSeqId = aIsiMessage.Get8bit( sbStartOffset + 
       
  1374             SS_SB_RESOURCE_SEQ_ID_OFFSET_SEQUENCEID );
       
  1375         }
       
  1376     
       
  1377     retValue = aIsiMessage.FindSubBlockOffsetById(
       
  1378         ISI_HEADER_SIZE + SIZE_SS_RESOURCE_CONTROL_IND,
       
  1379         SS_SB_SS_CONTROL,
       
  1380         EIsiSubBlockTypeId8Len8,
       
  1381         sbStartOffset );
       
  1382     
       
  1383     if( KErrNone == retValue )
       
  1384         {
       
  1385         stringLength = aIsiMessage.Get8bit( sbStartOffset +
       
  1386             SS_SB_SS_CONTROL_OFFSET_SSSTRINGLENGTH );
       
  1387         callcontrol.iString.Copy( aIsiMessage.GetData( 
       
  1388             sbStartOffset + SS_SB_SS_CONTROL_OFFSET_SSSTRING,
       
  1389             stringLength) );
       
  1390         }
       
  1391     
       
  1392     retValue = aIsiMessage.FindSubBlockOffsetById(
       
  1393         ISI_HEADER_SIZE + SIZE_SS_RESOURCE_CONTROL_IND,
       
  1394         SS_SB_USSD_CONTROL,
       
  1395         EIsiSubBlockTypeId8Len8,
       
  1396         sbStartOffset );
       
  1397     
       
  1398     if( KErrNone == retValue )
       
  1399         {
       
  1400         callcontrol.iUssdCodingInfo = aIsiMessage.Get8bit( sbStartOffset +
       
  1401             SS_SB_USSD_CONTROL_OFFSET_CODINGINFO );
       
  1402         stringLength = aIsiMessage.Get8bit( sbStartOffset +
       
  1403             SS_SB_USSD_CONTROL_OFFSET_USSDSTRINGLENGTH  );
       
  1404        
       
  1405         callcontrol.iUssdString.Copy( aIsiMessage.GetData( 
       
  1406             sbStartOffset + SS_SB_USSD_CONTROL_OFFSET_USSDSTRING,
       
  1407             stringLength ) );
       
  1408         }
       
  1409     // store struct
       
  1410     iCallControlArray->Append( callcontrol );
       
  1411     // Send envelope
       
  1412     if ( callcontrol.iString.Length() )
       
  1413         {
       
  1414         SendSSEnvelope( callcontrol );
       
  1415         }
       
  1416     else
       
  1417         {
       
  1418         SendUSSDEnvelope( callcontrol );
       
  1419         }
       
  1420     }
       
  1421 
       
  1422 // -----------------------------------------------------------------------------
       
  1423 // CSatCC::SendSsResourceControlReq
       
  1424 // Creates resource control response for modem SS server
       
  1425 // -----------------------------------------------------------------------------
       
  1426 //
       
  1427 void CSatCC::SendSsResourceControlReq( 
       
  1428         const TCallControl& aTcc,
       
  1429         const TUint8 aResult,
       
  1430         TPtrC8 aApduData )
       
  1431     {
       
  1432     TFLOGSTRING("TSY: CSatCC::SendSsResourceControlReq");
       
  1433     OstTrace0( TRACE_NORMAL, CSATCC_SENDSSRESOURCECONTROLREQ, "CSatCC::SendSsResourceControlReq" );
       
  1434 
       
  1435     TBuf8<KMaximumCcBufferSize> isiMessage;
       
  1436     CBerTlv response;
       
  1437     response.SetData( aApduData );
       
  1438     // Set initial cc result, e.g. the SIM has responded with sw1/sw2 90 00
       
  1439     // without any additional data. In error case reject the initiated action.
       
  1440     TUint8 ccresult( KAllowed == aResult ?
       
  1441         KCcResultAllowedNoModification : KCcResultNotAllowed );
       
  1442     // if provided in SIM response
       
  1443     if ( KCcEmptyResponseLenght < aApduData.Length() )
       
  1444         {
       
  1445         ccresult = aApduData[0];
       
  1446         }
       
  1447 
       
  1448     // Internal call control result
       
  1449     TUint8 internalCcResult( KAllowed );
       
  1450     // if original request is changed to new action, the sequence differs
       
  1451     // when the original action is changed to other SS server action
       
  1452     TBool changedSsServerAction( EFalse );
       
  1453     // SS_RESOURCE_CONTROL_REQ has 3 mandatory sb's
       
  1454     TUint8 sbcount( 3 );
       
  1455     // Add mandatory data
       
  1456     isiMessage.Append( KPadding );
       
  1457     // SS_SB_RESOURCE [M]: resource. Shall be same as in the corresponding indication.
       
  1458     TIsiSubBlock resource( 
       
  1459         isiMessage,
       
  1460         SS_SB_RESOURCE ,
       
  1461         EIsiSubBlockTypeId8Len8 );
       
  1462     TSatUtility::AppendWord( SS_RES_ID_MO_SS_OPERATION, isiMessage );
       
  1463     resource.CompleteSubBlock();
       
  1464     
       
  1465     // SS_SB_RESOURCE_SEQ_ID [M]: [M]: Sequence ID. Shall be same as in the corresponding indication.
       
  1466     TIsiSubBlock resourceSeqId( 
       
  1467         isiMessage,
       
  1468         SS_SB_RESOURCE_SEQ_ID,
       
  1469         EIsiSubBlockTypeId8Len8 );
       
  1470     isiMessage.Append( aTcc.iResourceSeqId  );
       
  1471     isiMessage.Append( KPadding );
       
  1472     resourceSeqId.CompleteSubBlock();
       
  1473 
       
  1474     // CALL_MODEM_SB_RESOURCE_STATUS [M]: resource status is allowed or denied.
       
  1475     TIsiSubBlock status(
       
  1476         isiMessage,
       
  1477         SS_SB_RESOURCE_STATUS,
       
  1478         EIsiSubBlockTypeId8Len8 );
       
  1479 
       
  1480     switch( ccresult )
       
  1481         {
       
  1482         case KCcResultAllowedNoModification:
       
  1483             {
       
  1484             isiMessage.Append( SS_RESOURCE_ALLOWED );
       
  1485             isiMessage.Append( KPadding );
       
  1486             break;
       
  1487             }
       
  1488         case KCcResultNotAllowed:
       
  1489             {
       
  1490             isiMessage.Append( SS_RESOURCE_DENIED );
       
  1491             isiMessage.Append( KPadding );
       
  1492             internalCcResult = KRejected;
       
  1493             break;
       
  1494             }
       
  1495         case KCcResultAllowedWithModifications:
       
  1496             {
       
  1497             // First check if this has been modified to a new CALL
       
  1498             CTlv address;
       
  1499 
       
  1500             if ( KErrNone == response.TlvByTagValue(
       
  1501                 &address, KTlvAddressTag ) )
       
  1502                 {
       
  1503                 // Original action has been modified to call
       
  1504                 isiMessage.Append( SS_RESOURCE_DENIED );
       
  1505                 isiMessage.Append( KPadding );
       
  1506                 internalCcResult = KChanged;
       
  1507                 }
       
  1508             // Now check if original SS action has been changed to USSD action
       
  1509             CTlv ssServerString;
       
  1510             if ( aTcc.iString.Length() )
       
  1511                 {
       
  1512                 if ( KErrNone == response.TlvByTagValue( &ssServerString,
       
  1513                         KTlvUssdStringTag ) )
       
  1514                     {
       
  1515                     isiMessage.Append( SS_RESOURCE_DENIED );
       
  1516                     isiMessage.Append( KPadding );
       
  1517                     internalCcResult = KChanged;
       
  1518                     changedSsServerAction = ETrue;
       
  1519                     }
       
  1520                 else
       
  1521                     {
       
  1522                     // original SS string has been modified to new SS string
       
  1523                     isiMessage.Append( SS_RESOURCE_ALLOWED );
       
  1524                     isiMessage.Append( KPadding );
       
  1525                     internalCcResult = KModified;
       
  1526                     }
       
  1527                 }
       
  1528             else if ( aTcc.iUssdString.Length() )
       
  1529                 {
       
  1530                 // Or original USSD action has been modified to SS action
       
  1531                 if ( KErrNone == response.TlvByTagValue( &ssServerString,
       
  1532                         KTlvSsStringTag ) )
       
  1533                     {
       
  1534                     isiMessage.Append( SS_RESOURCE_DENIED );
       
  1535                     isiMessage.Append( KPadding );
       
  1536                     internalCcResult = KChanged;
       
  1537                     changedSsServerAction = ETrue;
       
  1538                     }
       
  1539                 else
       
  1540                     {
       
  1541                     // USSD string has been modified to new USSD string
       
  1542                     isiMessage.Append( SS_RESOURCE_ALLOWED );
       
  1543                     isiMessage.Append( KPadding );
       
  1544                     internalCcResult = KModified;
       
  1545                     }
       
  1546                 }
       
  1547             break;
       
  1548             }
       
  1549         default:
       
  1550             {
       
  1551             break;
       
  1552             }
       
  1553         }
       
  1554     status.CompleteSubBlock();
       
  1555 
       
  1556     // SS_SB_SS_CONTROL/SS_SB_USSD_CONTROL is added only if original action has
       
  1557     // been modified
       
  1558     if ( KModified == internalCcResult )
       
  1559         {
       
  1560         if ( aTcc.iString.Length() )
       
  1561             {
       
  1562             CTlv ssStringTlv;
       
  1563             if ( KErrNone == response.TlvByTagValue( &ssStringTlv,
       
  1564                 KTlvSsStringTag ) )
       
  1565                 {
       
  1566                 TIsiSubBlock ssControl(
       
  1567                     isiMessage,
       
  1568                     SS_SB_SS_CONTROL,
       
  1569                     EIsiSubBlockTypeId8Len8 );
       
  1570                 
       
  1571                 TUint8 tonNpi( ssStringTlv.GetValue()[0] );
       
  1572                 TPtrC8 ssString( ssStringTlv.GetValue().Mid(1) );
       
  1573 
       
  1574                 TBuf8<255> ss;
       
  1575                 TSatUtility::BCDToAscii( ssString, ss );
       
  1576 
       
  1577                 if ( KTonNpiInternational == tonNpi )
       
  1578                     {
       
  1579                     // insert '+' to the number
       
  1580                     // ETSI TS 122 030 V5.0.0 (2002-06) says:
       
  1581                     // "The procedure always starts with *, #, **, ## or *#
       
  1582                     // and is finished by #. Each part within the procedure
       
  1583                     // is separated by *."
       
  1584                     TInt i( 0 );
       
  1585                     // skip start
       
  1586                     while ( (i < ss.Length()) && ('*' == ss[i]  || '#' == ss[i] ) )
       
  1587                         {
       
  1588                         i++;
       
  1589                         }
       
  1590                     // seek to separation
       
  1591                     while ( (i < ss.Length()) && (ss[i] != '*') )
       
  1592                         {
       
  1593                         i++;
       
  1594                         }
       
  1595                     // now insert '+' to start of SI
       
  1596                     if ( i < ss.Length() )
       
  1597                         {
       
  1598                         _LIT8(KPlus, "+");
       
  1599                         ss.Insert(i+1, KPlus);
       
  1600                         }
       
  1601                     }
       
  1602                 isiMessage.Append( ss.Length() );
       
  1603                 isiMessage.Append( ss );
       
  1604                 ssControl.CompleteSubBlock();
       
  1605                 sbcount++;
       
  1606                 }
       
  1607             }
       
  1608         else
       
  1609             {
       
  1610             CTlv ussdStringTlv;
       
  1611             if ( KErrNone == response.TlvByTagValue( &ussdStringTlv,
       
  1612                 KTlvUssdStringTag ) )
       
  1613                 {
       
  1614                 TIsiSubBlock ussdControl(
       
  1615                     isiMessage,
       
  1616                     SS_SB_USSD_CONTROL,
       
  1617                     EIsiSubBlockTypeId8Len8 );
       
  1618                 // Coding of USSD string. 3GPP TS 23.038 CBS Data Coding Sceme
       
  1619                 isiMessage.Append( ussdStringTlv.GetValue()[0] );
       
  1620                 TPtrC8 ussdString( ussdStringTlv.GetValue().Mid(1) );
       
  1621                 isiMessage.Append( ussdString.Length() );
       
  1622                 isiMessage.Append( ussdString );
       
  1623                 ussdControl.CompleteSubBlock();
       
  1624                 sbcount++;
       
  1625                 }
       
  1626             }
       
  1627         }
       
  1628     
       
  1629     TBuf8<1> numOfSubblocks;
       
  1630     numOfSubblocks.Append( sbcount);
       
  1631     isiMessage.Insert( 1, numOfSubblocks );
       
  1632     // send request
       
  1633     iSatMessHandler->SsResourceControlReq( aTcc.iTransId, isiMessage );
       
  1634 
       
  1635     if ( KCcEmptyResponseLenght < aApduData.Length()
       
  1636         && !changedSsServerAction )
       
  1637         {
       
  1638         // Notify client about call control if alpha id present
       
  1639         iSatMessaging->NotifyClientAboutCallControlEventL(
       
  1640             internalCcResult,
       
  1641             aApduData );
       
  1642         }
       
  1643     else if ( changedSsServerAction )
       
  1644         {
       
  1645         // SIM ATK TSY has to wait SS_STATUS_IND before continuing with
       
  1646         // changed action. This because SS server is still busy with original
       
  1647         // action. Therefore save data for later usage.
       
  1648         iEnvelopeResponseData = aApduData.Alloc();
       
  1649         iCcResult = internalCcResult;
       
  1650         }
       
  1651     }
       
  1652 
       
  1653 // -----------------------------------------------------------------------------
       
  1654 // CSatCC::GpdsResourceControlInd
       
  1655 // Handles resource control request from modem GPDS server
       
  1656 // -----------------------------------------------------------------------------
       
  1657 //
       
  1658 void CSatCC::GpdsResourceControlInd( const TIsiReceiveC& aIsiMessage )
       
  1659     {
       
  1660     TFLOGSTRING("TSY: CSatCC::GpdsResourceControlInd");
       
  1661     OstTrace0( TRACE_NORMAL, CSATCC_GPDSRESOURCECONTROLIND, "CSatCC::GpdsResourceControlInd" );
       
  1662 
       
  1663     TCallControl callcontrol;
       
  1664     TInt paramsLength;
       
  1665     TBuf8<KPdpContextActivationParamsMaxSize> paramsBuffer;
       
  1666     // store traid's
       
  1667     callcontrol.iTransId = aIsiMessage.Get8bit( ISI_HEADER_SIZE + 
       
  1668         GPDS_RESOURCE_CONTROL_REQ_OFFSET_UTID );    
       
  1669     callcontrol.iRecourceId = aIsiMessage.Get8bit(
       
  1670         ISI_HEADER_OFFSET_RESOURCEID);
       
  1671     callcontrol.iResourceSeqId = aIsiMessage.Get8bit( ISI_HEADER_SIZE +
       
  1672         GPDS_RESOURCE_CONTROL_IND_OFFSET_SEQUENCEID );
       
  1673 
       
  1674     TUint sbStartOffset( 0 );
       
  1675     TInt retValue( KErrNotFound );
       
  1676 
       
  1677     // GPDS_RESOURCE sub block is skipped since resource is always
       
  1678     // GPDS_RES_ID_CC_FOR_GPRS
       
  1679     retValue = aIsiMessage.FindSubBlockOffsetById(
       
  1680         ISI_HEADER_SIZE + SIZE_GPDS_RESOURCE_CONTROL_IND + SIZE_GPDS_RESOURCE,
       
  1681         GPDS_ACTIVATE_PDP_CONTEXT_REQUEST,
       
  1682         EIsiSubBlockTypeId8Len16,
       
  1683         sbStartOffset );
       
  1684 
       
  1685     if( KErrNone == retValue )
       
  1686         {
       
  1687         paramsLength = aIsiMessage.Get16bit( sbStartOffset +
       
  1688             GPDS_ACTIVATE_PDP_CONTEXT_REQUEST_OFFSET_DATALENGTH );
       
  1689         paramsBuffer.Copy( aIsiMessage.GetData( 
       
  1690             sbStartOffset + GPDS_ACTIVATE_PDP_CONTEXT_REQUEST_OFFSET_DATA,
       
  1691             paramsLength) );
       
  1692         }
       
  1693 
       
  1694     // store struct
       
  1695     iCallControlArray->Append( callcontrol );
       
  1696     // Send envelope
       
  1697     SendPdpContextActivationEnvelope( callcontrol.iTransId, paramsBuffer );
       
  1698     }
       
  1699 
       
  1700 // -----------------------------------------------------------------------------
       
  1701 // CSatCC::SendGpdsResourceControlReq
       
  1702 // Creates resource control response for modem GPDS server
       
  1703 // -----------------------------------------------------------------------------
       
  1704 //
       
  1705 void CSatCC::SendGpdsResourceControlReq( 
       
  1706         const TCallControl& aTcc,
       
  1707         const TUint8 aResult, 
       
  1708         TPtrC8 aAtkData )
       
  1709     {
       
  1710     TFLOGSTRING("TSY: CSatCC::SendGpdsResourceControlReq");
       
  1711     OstTrace0( TRACE_NORMAL, CSATCC_SENDGPDSRESOURCECONTROLREQ, "CSatCC::SendGpdsResourceControlReq" );
       
  1712 
       
  1713     TBuf8<KMaximumCcBufferSize> isiMessage;
       
  1714     CBerTlv response;
       
  1715     response.SetData( aAtkData );
       
  1716     RSat::TControlResult internalCcResult = RSat::EAllowedNoModification;
       
  1717     // Set initial cc result, e.g. the SIM has responded with sw1/sw2 90 00
       
  1718     // without any additional data. In error case reject the initiated action.
       
  1719     TUint8 ccresult( KAllowed == aResult ?
       
  1720         KCcResultAllowedNoModification : KCcResultNotAllowed );
       
  1721     // if provided in SIM response
       
  1722     if ( aAtkData.Length() )
       
  1723         {
       
  1724         ccresult = response.Data()[ 0 ];
       
  1725         }
       
  1726     TInt retValue( KErrNotFound );
       
  1727     CTlv paramsTlv;
       
  1728 
       
  1729     isiMessage.Append( aTcc.iResourceSeqId );
       
  1730     switch( ccresult )
       
  1731             {
       
  1732             case KCcResultAllowedNoModification:
       
  1733                 {
       
  1734                 isiMessage.Append( GPDS_ALLOWED );
       
  1735                 isiMessage.AppendFill( KPadding, 3 );
       
  1736                 // no of sb's
       
  1737                 isiMessage.Append( 1 );
       
  1738                 break;
       
  1739                 }
       
  1740             case KCcResultNotAllowed:
       
  1741                 {
       
  1742                 isiMessage.Append( GPDS_REJECTED );
       
  1743                 isiMessage.AppendFill( KPadding, 3 );
       
  1744                 // no of sb's
       
  1745                 isiMessage.Append( 1 );
       
  1746                 internalCcResult = RSat::ENotAllowed;
       
  1747                 break;
       
  1748                 }
       
  1749             case KCcResultAllowedWithModifications:
       
  1750                 {
       
  1751                 // response is modified in GPDS server terminology only if
       
  1752                 // new PDP params are provided
       
  1753                 if ( KCcEmptyResponseLenght < aAtkData.Length() 
       
  1754                     && KErrNone == response.TlvByTagValue( &paramsTlv,
       
  1755                         KTlvPdpContextActivationParametersTag ) )
       
  1756                     {
       
  1757                     isiMessage.Append( GPDS_MODIFIED );
       
  1758                     isiMessage.AppendFill( KPadding, 3 );
       
  1759                     // no of sb's
       
  1760                     isiMessage.Append( 2 );
       
  1761                     internalCcResult = RSat::EAllowedWithModifications;
       
  1762                     }
       
  1763                 else
       
  1764                     {
       
  1765                     // No new PDP params provided, hence GPDS_ALLOWED
       
  1766                     isiMessage.Append( GPDS_ALLOWED );
       
  1767                     isiMessage.AppendFill( KPadding, 3 );
       
  1768                     // no of sb's
       
  1769                     isiMessage.Append( 1 );
       
  1770                     }
       
  1771                 break;
       
  1772                 }
       
  1773             default:
       
  1774                 {
       
  1775                 break;
       
  1776                 }
       
  1777             }
       
  1778     isiMessage.Append( GPDS_RESOURCE  );
       
  1779     isiMessage.Append( 4 );
       
  1780     TSatUtility::AppendWord( GPDS_RES_ID_CC_FOR_GPRS, isiMessage );
       
  1781 
       
  1782     if ( KCcEmptyResponseLenght < aAtkData.Length() )
       
  1783         {
       
  1784         // GPDS_ACTIVATE_PDP_CONTEXT_REQUEST is shall be present if and only if
       
  1785         // Resource is GPDS_CC_FOR_GPRS and Result is GPDS_MODIFIED
       
  1786         if ( RSat::EAllowedWithModifications == internalCcResult )
       
  1787             {
       
  1788             TIsiSubBlock contextParams( 
       
  1789                 isiMessage,
       
  1790                 GPDS_ACTIVATE_PDP_CONTEXT_REQUEST,
       
  1791                 EIsiSubBlockTypeId8Len16 );
       
  1792             TInt paramsLength( paramsTlv.GetLength() );
       
  1793             // Set data length
       
  1794             TSatUtility::AppendWord( paramsLength, isiMessage);
       
  1795             // Copy data after tag & length value
       
  1796             isiMessage.Append( paramsTlv.Data().Mid( 2, paramsLength ) );
       
  1797             //isiMessage.Append( paramsTlv.GetValue() );
       
  1798             contextParams.CompleteSubBlock();
       
  1799             }
       
  1800         // Check if alpha id present and valid
       
  1801         CTlv aidTlv;
       
  1802         retValue = response.TlvByTagValue( &aidTlv, KTlvAlphaIdentifierTag );
       
  1803         if ( KErrNone == retValue && aidTlv.GetLength() )
       
  1804             {
       
  1805             TPtrC8 sourceString;
       
  1806             sourceString.Set( aidTlv.GetData( ETLV_AlphaIdentifier ) );
       
  1807             RSat::TAlphaIdBuf alphaId;
       
  1808             // convert and set the alpha id
       
  1809             TSatUtility::SetAlphaId( sourceString,
       
  1810                 alphaId );
       
  1811             iSatMessaging->NotifyClientAboutGprsCallControlEvent(
       
  1812                 alphaId,
       
  1813                 internalCcResult );
       
  1814             }
       
  1815         }
       
  1816     iSatMessHandler->GpdsResourceControlReq( aTcc.iTransId, isiMessage );
       
  1817     }
       
  1818 // End of File
       
  1819