telephonyserverplugins/simatktsy/src/csatcctsy.cpp
changeset 0 3553901f7fa8
child 24 6638e7f4bd8f
child 42 3adadc800673
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Name        : CSatCcTsy.cpp
       
    15 // Part of     : Common SIM ATK TSY / commonsimatktsy
       
    16 // Call control-related functionality of Sat Tsy
       
    17 // Version     : 1.0
       
    18 //
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 //INCLUDES
       
    24 #include "etelsat.h"                // SAT specific Etel definitions
       
    25 #include "CSatDataPackage.h"        // Parameter packing 
       
    26 #include "CSatCCTsy.h"              // Class header
       
    27 #include "CSatTsy.h"                // SAT TSY general class
       
    28 #include "CSatNotificationsTsy.h"   // SAT TSY Notifications class
       
    29 #include "cmmmessagemanagerbase.h"  // Message manager class for forwarding req.
       
    30 #include "TfLogger.h"               // For TFLOGSTRING
       
    31 #include "msattsy_ipcdefs.h"		// Sat Tsy specific request types
       
    32 #include "TSatUtility.h"			// Utility class
       
    33 #include "TTlv.h"					// TTlv class
       
    34 
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 // CSatCCTsy::NewL
       
    38 // Two-phased constructor.
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 CSatCCTsy* CSatCCTsy::NewL
       
    42         (    
       
    43         CSatTsy* aSatTsy,
       
    44         CSatNotificationsTsy* aNotificationsTsy   
       
    45         )
       
    46     {
       
    47     TFLOGSTRING("CSAT: CSatCCTsy::NewL");
       
    48     CSatCCTsy* const satCcTsy = new ( ELeave ) CSatCCTsy( aNotificationsTsy );
       
    49     CleanupStack::PushL( satCcTsy );
       
    50     satCcTsy->iSatTsy = aSatTsy;
       
    51     satCcTsy->ConstructL();
       
    52     CleanupStack::Pop( satCcTsy );
       
    53     TFLOGSTRING("CSAT: CSatCCTsy::NewL, end of method");
       
    54     return satCcTsy;
       
    55     }
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // CSatCCTsy::~CSatCCTsy
       
    59 // Destructor
       
    60 // -----------------------------------------------------------------------------
       
    61 //    
       
    62 CSatCCTsy::~CSatCCTsy
       
    63         (    
       
    64         //None   
       
    65         )
       
    66     {
       
    67     TFLOGSTRING("CSAT: CSatCCTsy::~CSatCCTsy");
       
    68     // Unregister.
       
    69     iSatTsy->MessageManager()->RegisterTsyObject(
       
    70 		CMmMessageManagerBase::ESatCCTsyObjType, NULL );
       
    71     }
       
    72     
       
    73 // -----------------------------------------------------------------------------
       
    74 // CSatCCTsy::ConstructL
       
    75 // Symbian 2nd phase constructor. Initialises internal attributes.
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 void CSatCCTsy::ConstructL
       
    79         (    
       
    80         //None
       
    81         )
       
    82     {
       
    83     TFLOGSTRING("CSAT: CSatCCTsy::ConstructL\n" );
       
    84     // Register.
       
    85     iSatTsy->MessageManager()->RegisterTsyObject(
       
    86 		CMmMessageManagerBase::ESatCCTsyObjType, this );
       
    87 	iBearerData.Zero();
       
    88 	// Initialize to false
       
    89 	iTonNpiPresent = EFalse;
       
    90 	// Clean the address buffer
       
    91 	iProactiveCommandAddress.Zero();
       
    92 	// Initialize USSD TLV support to not supported
       
    93 	iUssdTlvSupported = EFalse;
       
    94     }
       
    95 
       
    96 // -----------------------------------------------------------------------------
       
    97 // CSatCCTsy::CSatCCTsy
       
    98 // C++ constructor
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 CSatCCTsy::CSatCCTsy
       
   102         (    
       
   103         CSatNotificationsTsy* aNotificationsTsy 
       
   104         ) : iNotificationsTsy ( aNotificationsTsy )
       
   105     {
       
   106     // None
       
   107     }
       
   108 
       
   109 // -----------------------------------------------------------------------------
       
   110 // CSatCCTsy::CompleteBearerCapability
       
   111 // Saves default bearer data for voice call.
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 void CSatCCTsy::CompleteBearerCapability
       
   115          (
       
   116 		 CSatDataPackage* aDataPackage, 
       
   117 		 TInt /*aResult*/
       
   118 		 )
       
   119     {
       
   120     TFLOGSTRING("CSAT: CSatCCTsy::CompleteBearerCapability");
       
   121     TPtrC8* bearerData = NULL;
       
   122 
       
   123     // Unpack parameters 
       
   124     aDataPackage->UnPackData( &bearerData );
       
   125     iBearerData.Copy( *bearerData );
       
   126 	}
       
   127 	
       
   128 // -----------------------------------------------------------------------------
       
   129 // CSatCCTsy::CreateEnvelope
       
   130 // Identifies the type of envelope and calls appropriate method.
       
   131 // -----------------------------------------------------------------------------
       
   132 void CSatCCTsy::CreateEnvelopeL
       
   133         (
       
   134         CSatDataPackage* aDataPackage
       
   135         )
       
   136     {
       
   137     TFLOGSTRING("CSAT: CSatCCTsy::CreateEnvelope");
       
   138     TCCInfo* ccInfo;
       
   139     
       
   140     // Unpack parameters
       
   141     aDataPackage->UnPackData( &ccInfo );
       
   142     
       
   143     switch ( ccInfo->iTag )
       
   144         {
       
   145         case KTlvAddressTag:
       
   146             {
       
   147             CreateCallEnvelopeL( ccInfo );
       
   148             break;
       
   149             }
       
   150         case KTlvSsStringTag:
       
   151             {
       
   152             CreateSSEnvelopeL( ccInfo );
       
   153             break;
       
   154             }
       
   155         case KTlvUssdStringTag:
       
   156             {
       
   157             CreateUSSDEnvelopeL( ccInfo );
       
   158             break;
       
   159             }
       
   160         default:
       
   161             {
       
   162             TFLOGSTRING2("CSAT: CSatCCTsy::CreateEnvelope,\
       
   163                 Unidentified tag: %d", ccInfo->iTag );
       
   164             }
       
   165         }
       
   166     }
       
   167 
       
   168 // -----------------------------------------------------------------------------
       
   169 // CSatCCTsy::CheckIfAlphaIdPresent
       
   170 // Notifies client if alpha ID was present in incoming data notification.
       
   171 // -----------------------------------------------------------------------------
       
   172 //
       
   173 void CSatCCTsy::CheckIfAlphaIdPresent
       
   174         (
       
   175         CSatDataPackage* aDataPackage
       
   176         )
       
   177     {
       
   178     TFLOGSTRING("CSAT: CSatCCTsy::CheckIfAlphaIdPresent"); 
       
   179     TDesC8* atkData;            
       
   180     RSat::TControlResult* result;
       
   181     
       
   182     // Unpack parameters
       
   183     aDataPackage->UnPackData( &atkData, &result );
       
   184         
       
   185     TUint16 envLength( 0 );
       
   186     TInt lengthOfLength( 1 );
       
   187     TInt index( 1 );
       
   188     
       
   189     // Check first that the data exists
       
   190     if ( 1 < atkData->Length() )
       
   191         {
       
   192         // Check if length is taking two bytes or not.
       
   193         if ( KTwoByteLengthCoding != ( *atkData )[ index ] ) 
       
   194             {
       
   195             // It takes one
       
   196             envLength = ( ( *atkData )[ index ] );
       
   197             }
       
   198         else
       
   199             {
       
   200             // It takes two. ( Actually it takes only one, but first byte is 
       
   201             // meaningless. See ETSI 11.14 Annex D )
       
   202             envLength = ( ( *atkData )[ index + 1 ] );
       
   203             lengthOfLength = 2;
       
   204             }
       
   205 
       
   206         index += lengthOfLength;
       
   207 
       
   208         if ( envLength != 0 )
       
   209             {
       
   210             while ( index < envLength )
       
   211                 {
       
   212     	        // Check next tag
       
   213     	        TUint8 nextTag( ( *atkData )[ index ] );
       
   214 
       
   215                 switch ( nextTag & KTagValueMask )
       
   216                     {
       
   217                     case KTlvAddressTag:
       
   218                     case KTlvCapabilityConfigurationParametersTag:
       
   219                     case KTlvSubaddressTag:
       
   220                     case KTlvSsStringTag:
       
   221                     case KTlvUssdStringTag:
       
   222                     case KTlvBcRepeatIndicatorTag:
       
   223                         {
       
   224                         TUint16 length( 0 );
       
   225                         TUint8 localLengthOfLength( 1 );
       
   226                         index++;
       
   227                         // Check if length is taking two bytes or not.
       
   228                         if ( KTwoByteLengthCoding  != ( *atkData )[ index ] )
       
   229                             {
       
   230                             // It takes one
       
   231                             length = ( ( *atkData )[ index ] );
       
   232                             }
       
   233                         else
       
   234                             {
       
   235                             // It takes two
       
   236                             length = ( ( *atkData )[ index + 1 ] );
       
   237                             localLengthOfLength = 2;
       
   238                             }
       
   239                         index += localLengthOfLength + length;
       
   240                         break;
       
   241                         }
       
   242                     case KTlvAlphaIdentifierTag:
       
   243                         {
       
   244                         TUint16 alphaIdLength( 0 );
       
   245                         lengthOfLength = 1;
       
   246                         index++;
       
   247                         // Check if length is taking two bytes or not
       
   248                         if ( KTwoByteLengthCoding != ( *atkData )[ index ] )
       
   249                             {
       
   250                             alphaIdLength = ( *atkData )[ index ];
       
   251                             }
       
   252                         else
       
   253                             {
       
   254                             alphaIdLength = ( *atkData )[ index + 1 ];
       
   255                             lengthOfLength = 2;
       
   256                             }
       
   257 
       
   258                         // If the alpha identifier is provided by the NAA and is 
       
   259                         // not a null data object, the ME shall use it to inform  
       
   260                         // the user. The ME shall then not display the destination 
       
   261                         // address or SS string given by the NAA. This is also an 
       
   262                         // indication that the ME should not give any other 
       
   263                         // information to the user on the changes made by the NAA 
       
   264                         // to the initial user request. Design decision: If alpha 
       
   265                         // identifier is not given or it is NULL, client will not 
       
   266                         // be notified. Specs leaves this open so this decision 
       
   267                         // can be made.
       
   268                         if ( 0 != alphaIdLength )
       
   269                             {
       
   270                             TFLOGSTRING("CSAT: CSatCCTsy::CheckIfAlphaIdPresent.\
       
   271                                 inform user.");
       
   272 
       
   273                             TPtrC8 sourceString;
       
   274                             sourceString.Set( ( *atkData ).Mid( index + 
       
   275                                 lengthOfLength, alphaIdLength ) );
       
   276 
       
   277                             RSat::TAlphaIdBuf alphaId;                       
       
   278                             // Convert and set the alpha id
       
   279     						TSatUtility::SetAlphaId( sourceString, alphaId ); 
       
   280                                     
       
   281                             iNotificationsTsy->NotifyClientForAlphaId( alphaId, 
       
   282                                 *result );
       
   283                             }
       
   284                         else
       
   285                             {
       
   286                             TFLOGSTRING("CSAT: CSatCCTsy::CheckIfAlphaIdPresent.\
       
   287                                 AlphaID length: 0.");
       
   288                             }
       
   289 
       
   290                         // Update index
       
   291                         index += alphaIdLength + lengthOfLength;
       
   292                         break;
       
   293                         }
       
   294                     default:
       
   295                         {
       
   296                         TFLOGSTRING("CSAT: CSatCCTsy::CheckIfAlphaIdPresent\
       
   297                             Unknown tag.");
       
   298                         index = envLength;
       
   299                         break;
       
   300                         }
       
   301                     }
       
   302                 }
       
   303             }
       
   304         }
       
   305     else
       
   306         {
       
   307         TFLOGSTRING("CSAT: CSatCCTsy::CheckIfAlphaIdPresent. \
       
   308             Input data missing!");
       
   309         }
       
   310     }
       
   311     
       
   312 // -----------------------------------------------------------------------------
       
   313 // CSatCCTsy::CompleteCCEventL
       
   314 // Completes the received call control event data notification
       
   315 // -----------------------------------------------------------------------------
       
   316 //
       
   317 void CSatCCTsy::CompleteCCEventL
       
   318         (
       
   319         TInt aIpc,
       
   320         CSatDataPackage* aDataPackage 
       
   321         )
       
   322     {
       
   323     TFLOGSTRING2("CSAT: CSatCCTsy::CompleteCCEventL, aIpc: %d", aIpc);
       
   324     TCCInfo* ccInfo;
       
   325     
       
   326     // Unpack parameters
       
   327     aDataPackage->UnPackData( &ccInfo );
       
   328     
       
   329     switch ( aIpc )
       
   330         {
       
   331         case ESatTsyCallEvent:
       
   332             {
       
   333             // 3GPP TS 11.14 V8.17.0 (2004-09):
       
   334             // It is possible that NAA requests ME to set up an emergency call by 
       
   335             // supplying "112" as called party number. If NAA supplies a number 
       
   336             // stored in EFECC, this shall not result in an emergency call.
       
   337             //
       
   338             // The number included in the SET UP CALL proactive command is never
       
   339             // checked against FDN list. So no need to done it here.
       
   340             if ( HasProactiveOrigin( ccInfo->iAddress ) )
       
   341                 {
       
   342                 // Match! Address can be reset and envelope sent
       
   343                 iProactiveCommandAddress.Zero();            		
       
   344                 CreateCallEnvelopeL( ccInfo );
       
   345                 }
       
   346             else
       
   347                 {
       
   348                 // Check if this is a emergency call creation attempt. Although 
       
   349                 // emergency calls made through TSY always use emergency flag 
       
   350                 // and emergency mode and are therefore passed straight through
       
   351                 // guardians, emergency calls made by AT commands and bypassing 
       
   352                 // TSY do not use emergency flag and mode. A possility that NAA 
       
   353                 // would alter the emergency call to something else cannot be 
       
   354                 // tolerated. Forward request to the DOS
       
   355                 iSatTsy->MessageManager()->HandleRequestL( 
       
   356             		ESatTsyEmergencyNbrCheck );
       
   357                 }  
       
   358             break;
       
   359             }
       
   360         case ESatTsySSEvent:
       
   361             {
       
   362             // 3GPP TS 11.14 V8.17.0 (2004-09):
       
   363             // The SS control string included in the SEND SS proactive cmd is 
       
   364             // never checked against FDN list. So make sure this wont happen.
       
   365             if ( HasProactiveOrigin( ccInfo->iAddress ) )
       
   366                 {
       
   367                 // Match! Address can be reset and envelope sent without FDN 
       
   368                 // check.
       
   369                 iProactiveCommandAddress.Zero();
       
   370                 CreateSSEnvelopeL( ccInfo );
       
   371                 }
       
   372             // Not proactive originated, check if FDN is activated.
       
   373             else
       
   374                 {
       
   375                 // Forward request to the DOS
       
   376                 iSatTsy->MessageManager()->HandleRequestL( 
       
   377             		ESatTsyFdnStatusCheck );
       
   378                 }  
       
   379             break;
       
   380             }
       
   381         case ESatTsyUSSDEvent:
       
   382             {
       
   383             // Send envelope right away, there's no difference whether the CC 
       
   384             // event was originated by proactive command or not.
       
   385             CreateUSSDEnvelopeL( ccInfo );
       
   386             break;
       
   387             }
       
   388         default:
       
   389             {
       
   390             TFLOGSTRING("CSAT: CSatCCTsy::CompleteCCEventL, Unknown event!");
       
   391             }
       
   392         }
       
   393     }   
       
   394     	
       
   395 // -----------------------------------------------------------------------------
       
   396 // CSatCCTsy::SetTonNpiForSS
       
   397 // Set CSatCC internal Ton and Npi
       
   398 // Called by CSatNotifySendSs::CompleteNotifyL when SEND SS proactive command 
       
   399 // arrives
       
   400 // -----------------------------------------------------------------------------
       
   401 //
       
   402 void CSatCCTsy::SetTonNpiForSS
       
   403         ( 
       
   404         const TUint8 aTonNpi 
       
   405         )
       
   406     {
       
   407     TFLOGSTRING("CSAT: CSatCCTsy::SetTonNpiForSS");
       
   408     iTonNpiForSS = aTonNpi;
       
   409     iTonNpiPresent = ETrue;
       
   410     }
       
   411 
       
   412 // -----------------------------------------------------------------------------
       
   413 // CSatCCTsy::SetUssdStatus
       
   414 // Set internal flag according to EF-SST.
       
   415 // -----------------------------------------------------------------------------
       
   416 //
       
   417 void CSatCCTsy::SetUssdStatus
       
   418 		( 
       
   419     	CSatDataPackage* aDataPackage
       
   420     	)
       
   421     { 
       
   422     TFLOGSTRING("CSAT: CSatCCTsy::SetUssdStatus." );    
       
   423     // Unpack parameters 
       
   424     aDataPackage->UnPackData( iUssdTlvSupported ); 
       
   425     }  
       
   426 
       
   427 // -----------------------------------------------------------------------------
       
   428 // CSatCCTsy::StoreAddressForCC
       
   429 // Stores latest address of Send SS/Setup call proactive command to CSatCC
       
   430 // (other items were commented in a header). Method is also called when 
       
   431 // proactive session is over with parameter NULL.
       
   432 // -----------------------------------------------------------------------------
       
   433 //    
       
   434 void CSatCCTsy::StoreAddressForCC
       
   435         ( 
       
   436         const TDesC8& aAddress 
       
   437         )
       
   438     {
       
   439     TFLOGSTRING("CSAT: CSatCCTsy::StoreAddressForCC");
       
   440     
       
   441     if ( NULL == &aAddress )
       
   442         {
       
   443         iProactiveCommandAddress.Zero();
       
   444         TFLOGSTRING("CSAT: CSatCCTsy::StoreAddressForCC, address cleared");
       
   445         }
       
   446     else
       
   447         {
       
   448         iProactiveCommandAddress.Copy( aAddress );
       
   449         
       
   450         // Remove the '+' sign from the the beginning of the address
       
   451         // if it exists. Otherwise the comparison does not work.     
       
   452         if ( 0 < iProactiveCommandAddress.Length() )
       
   453             {
       
   454             if ( '+' == iProactiveCommandAddress[0] )
       
   455                 {
       
   456                 iProactiveCommandAddress.Delete( 0, 1 );
       
   457                 }
       
   458             }
       
   459         TFLOGSTRING("CSAT: CSatCCTsy::StoreAddressForCC, Address stored");
       
   460         }
       
   461     }     
       
   462        
       
   463 // -----------------------------------------------------------------------------
       
   464 // CSatCCTsy::CreateCallEnvelopeL
       
   465 // Creates call Envelope.
       
   466 // -----------------------------------------------------------------------------
       
   467 //
       
   468 void CSatCCTsy::CreateCallEnvelopeL
       
   469 		( 
       
   470 		const TCCInfo* aCCInfo
       
   471 		)
       
   472     {
       
   473     TFLOGSTRING("CSAT: CSatCCTsy::CreateCallEnvelopeL" );
       
   474     // Create envelope
       
   475     TTlv envelope;
       
   476     envelope.Begin( KBerTlvCallControlTag );
       
   477 
       
   478     // Device identities
       
   479     envelope.AddTag( KTlvDeviceIdentityTag );
       
   480     envelope.AddByte( KMe );
       
   481     envelope.AddByte( KSim );
       
   482 
       
   483     // Address
       
   484     envelope.AddTag( KTlvAddressTag );
       
   485     envelope.AddByte( aCCInfo->iTonNpi ); 
       
   486 
       
   487     // Must be converted to BCD number
       
   488     TBuf8<KAddrMaxLength> address;
       
   489     TSatUtility::AsciiToBCD( aCCInfo->iAddress, address );
       
   490     envelope.AddData( address );
       
   491        
       
   492     // Optional
       
   493     envelope.AddTag( KTlvCapabilityConfigurationParametersTag );
       
   494     
       
   495     if ( 0 != aCCInfo->iBcc1.Length() )
       
   496         {
       
   497         if ( 2 > aCCInfo->iBcc1.Length() )
       
   498             {
       
   499             TBuf8<KMaxBccLength> bcc;
       
   500             bcc.Append( 0x01 );
       
   501             bcc.Append( aCCInfo->iBcc1 );
       
   502             envelope.AddData( bcc );
       
   503             }
       
   504         else
       
   505             {
       
   506             envelope.AddData( aCCInfo->iBcc1 );
       
   507             }
       
   508         }
       
   509     // Although this field is not mandatory, it could help testing.  
       
   510     // Therefore field is included to enable wider testability.
       
   511     else
       
   512         {  
       
   513         if ( iBearerData.Length() < 2 )
       
   514             {
       
   515             iBearerData.Append( 0x01 );
       
   516             // Add the length
       
   517             envelope.AddByte( static_cast<TUint8>( iBearerData.Length() ) );
       
   518             envelope.AddData( iBearerData );
       
   519             }
       
   520         // Design decision: if bearer data is bigger than capability field, 
       
   521         // then this field is not added.
       
   522         else if ( KMaxBccLength >= iBearerData.Length() )
       
   523             {
       
   524             // Add the length
       
   525             envelope.AddByte( static_cast<TUint8>( iBearerData.Length() ) );
       
   526             envelope.AddData( iBearerData ); 
       
   527             }
       
   528         else
       
   529         	{
       
   530         	TFLOGSTRING("CSAT: CSatCCTsy::CreateCallEnvelopeL,\
       
   531         	    Bearer data length exceeded, data not added" );
       
   532         	}
       
   533         }
       
   534 
       
   535 	// Add location information data
       
   536 	iNotificationsTsy->AddLocationInformationToTlv( envelope );
       
   537 
       
   538     if ( 0 != aCCInfo->iBcc2.Length() )
       
   539         {
       
   540         envelope.AddTag( KTlvCapabilityConfigurationParametersTag );
       
   541         envelope.AddData( aCCInfo->iBcc2 ); 
       
   542         }
       
   543 
       
   544     // Prepare data
       
   545     TPtrC8 data = envelope.End();
       
   546 	// Pack data
       
   547     CSatDataPackage dataPackage;
       
   548 	dataPackage.PackData( &data );
       
   549 
       
   550     // Send Call envelope
       
   551     iSatTsy->MessageManager()->HandleRequestL( ESatTsySendEnvelope, 
       
   552         &dataPackage );
       
   553     }
       
   554 
       
   555 // -----------------------------------------------------------------------------
       
   556 // CSatCCTsy::CreateSSEnvelopeL
       
   557 // Creates SS Envelope.
       
   558 // -----------------------------------------------------------------------------
       
   559 //
       
   560 void CSatCCTsy::CreateSSEnvelopeL
       
   561 		( 
       
   562 		const TCCInfo* aCCInfo
       
   563 		)
       
   564     {
       
   565     TFLOGSTRING("CSAT: CSatCCTsy::CreateSSEnvelopeL" );
       
   566     // There is no TON and NPI in SS cc request. Information is part of the 
       
   567     // number string: Spec ETSI TS 122 030 v5.0.0 says that if number starts
       
   568     // with +, TON is international and if it starts without it, it's unknown.
       
   569     // ( ATK isi spec mentions also possibility of no TON and NPI,but so far 
       
   570     // nothing found about it from ETSI specs. SS ISI spec mentions even more )
       
   571     // Default NPI is used if all digits are in the range 0-9. NPI shall be 
       
   572     // unknown if other number information is included ( whatever that means ). 
       
   573     // In any case if the user has selected some particular NPI, that is used.
       
   574     TInt i( 0 );
       
   575     TUint8 tonNpi( KTonNpiUnknown );
       
   576     
       
   577     // If SS is entered by user, there's no SEND SS from where to resolve TonNpi
       
   578     // Then TonNpi is resolved from SS string
       
   579     // TonNpi   = Unknown if '+'-sign is not present
       
   580     //          = International if '+'-sign is found
       
   581     //          = No TonNpi if phone number is not present or SS-string contains
       
   582     //            only SS code
       
   583 
       
   584     if( !iTonNpiPresent )
       
   585         {
       
   586         // Seek '+' from ss string. 3GPP TS 22 030 V7.0.0 (2004-03) states:
       
   587         // "The procedure always starts with *, #, **, ## or *# and is finished
       
   588         // by #. Each part within the procedure is separated by *."
       
   589         
       
   590         // Skip start characters
       
   591         while ( (i < aCCInfo->iAddress.Length()) && 
       
   592               ( ('*' == aCCInfo->iAddress[i] ) || 
       
   593                 ('#' == aCCInfo->iAddress[i]) ) )
       
   594             {
       
   595             i++;
       
   596             }
       
   597 
       
   598         TInt ssCode( 0 );
       
   599         // Seek for separation character and store service code
       
   600         while ( ( i < aCCInfo->iAddress.Length() ) && 
       
   601                 ( '*' != aCCInfo->iAddress[i] ) && 
       
   602                 ( '#' != aCCInfo->iAddress[i] ) )
       
   603             {
       
   604             ssCode *= 10;
       
   605             ssCode += ( aCCInfo->iAddress[i] - 0x30 );
       
   606             i++;
       
   607             }
       
   608         
       
   609         // With these SS codes dialling number is included. It's always located 
       
   610         // after first separation mark '*'. See 3GPP TS 22.030 7.0.0, 6.5.2 and 
       
   611         // Annex B. With checking the service code ton/npi resolving is made 
       
   612         // unambiguous.
       
   613         if( KSsAllForwardings == ssCode || 
       
   614             KSsAllCondForwardings == ssCode || 
       
   615             KSsForwUnconditional == ssCode|| 
       
   616             KSsForwBusy == ssCode || 
       
   617             KSsForwNoReply == ssCode || 
       
   618             KSsForwNotReachable == ssCode )
       
   619             {        
       
   620             // Set tonNpi international, if separation character (*) and 
       
   621             // (+) sign is found
       
   622             if( ( ( i + 1 ) < aCCInfo->iAddress.Length() ) && 
       
   623                 ( ('*' == aCCInfo->iAddress[i] ) && 
       
   624                   ('+' == aCCInfo->iAddress[i + 1] ) ) )
       
   625                 {
       
   626                 tonNpi = KTonNpiInternational;
       
   627                 }
       
   628             // Procedure is finished by #
       
   629             // If * is not found -> no number found
       
   630             else if( (i < aCCInfo->iAddress.Length() ) && 
       
   631                 ('#' == aCCInfo->iAddress[i] ) )
       
   632                 {
       
   633                 tonNpi = KTonNpiNotSet;
       
   634                 }
       
   635             else
       
   636                 {
       
   637                 // Number is found but it's tonnpi id unknown
       
   638                 tonNpi = KTonNpiUnknown;
       
   639                 }
       
   640             }
       
   641         else
       
   642             {
       
   643             // With all other SS codes TON/NPI is set to 0xff
       
   644             tonNpi = KTonNpiNotSet;
       
   645             }
       
   646         }
       
   647     else
       
   648         {
       
   649         // TonNpi is resolved from SEND SS proactive command
       
   650         tonNpi = iTonNpiForSS;
       
   651         }
       
   652         
       
   653     iTonNpiPresent = EFalse;
       
   654 
       
   655     // Create SS envelope
       
   656     TTlv envelope;
       
   657     envelope.Begin( KBerTlvCallControlTag );
       
   658 
       
   659     // Device identities
       
   660     envelope.AddTag( KTlvDeviceIdentityTag );
       
   661     envelope.AddByte( KMe );
       
   662     envelope.AddByte( KSim );
       
   663 
       
   664     // SS string
       
   665     envelope.AddTag( KTlvSsStringTag );
       
   666     envelope.AddByte( tonNpi );
       
   667 
       
   668     TBuf8<KMaxSSStringLength> ss;
       
   669     TSatUtility::AsciiToBCD( aCCInfo->iAddress, ss );
       
   670     envelope.AddData( ss );
       
   671 
       
   672 	// Add location information data
       
   673 	iNotificationsTsy->AddLocationInformationToTlv( envelope );
       
   674 
       
   675     // Prepare data
       
   676     TPtrC8 data = envelope.End();
       
   677 	// Pack data
       
   678     CSatDataPackage dataPackage;
       
   679 	dataPackage.PackData( &data );
       
   680 
       
   681     // Send SS envelope
       
   682     iSatTsy->MessageManager()->HandleRequestL( 
       
   683         ESatTsySendEnvelope, &dataPackage );
       
   684 	}
       
   685 
       
   686 
       
   687 // -----------------------------------------------------------------------------
       
   688 // CSatCCTsy::CreateUSSDEnvelopeL
       
   689 // Creates USSD Envelope.
       
   690 // -----------------------------------------------------------------------------
       
   691 //
       
   692 void CSatCCTsy::CreateUSSDEnvelopeL
       
   693 		( 
       
   694 		const TCCInfo* aCCInfo
       
   695 		)
       
   696     {
       
   697     TFLOGSTRING("CSAT: CSatCCTsy::CreateUSSDEnvelopeL" );
       
   698     // Create USSD envelope
       
   699     TTlv envelope;
       
   700         
       
   701     envelope.Begin( KBerTlvCallControlTag );
       
   702     // Device identities
       
   703     envelope.AddTag( KTlvDeviceIdentityTag );
       
   704     envelope.AddByte( KMe );
       
   705     envelope.AddByte( KSim );
       
   706 
       
   707     // USSD string tlv
       
   708     if ( iUssdTlvSupported )
       
   709         {
       
   710         // USSD string
       
   711         envelope.AddTag( KTlvUssdStringTag );
       
   712         envelope.AddByte( aCCInfo->iDcs );
       
   713         envelope.AddData( aCCInfo->iAddress );
       
   714         
       
   715         iNotificationsTsy->AddLocationInformationToTlv( envelope );
       
   716 
       
   717         // Prepare data
       
   718         TPtrC8 data = envelope.End();
       
   719     	// Pack data
       
   720         CSatDataPackage dataPackage;
       
   721     	dataPackage.PackData( &data );
       
   722      
       
   723         // Send USSD envelope
       
   724         iSatTsy->MessageManager()->HandleRequestL( ESatTsySendEnvelope, 
       
   725             &dataPackage );
       
   726         }
       
   727     else
       
   728         {
       
   729         // UssdTlv is not supported by the NAA
       
   730         // Checks whether the USSD string can be coded in the SS obj. SS obj.
       
   731         // can only contain "*", "#", and the numbers 0-9.
       
   732         if ( IsOnlyDigitsInUssd( aCCInfo->iAddress ) )
       
   733             {
       
   734             envelope.AddTag( KTlvSsStringTag );
       
   735             // If the Dialling Number/SSC String does not contain a dialling 
       
   736             // number e.g. a control string deactivating a service, the TON/NPI
       
   737             // byte shall be set to 'FF' by the ME (see note 3GPP TS 11.11).
       
   738             // in this case TON & NPI must be set to 0xFF    
       
   739             envelope.AddByte( 0xFF );
       
   740             TBuf8<KMaxSSStringLength> ss;     
       
   741             TSatUtility::AsciiToBCD( aCCInfo->iAddress, ss );
       
   742     		envelope.AddData( ss );
       
   743     		iNotificationsTsy->AddLocationInformationToTlv( envelope );
       
   744     		// Prepare data
       
   745             TPtrC8 data = envelope.End();
       
   746             // Create package
       
   747 			CSatDataPackage package;
       
   748 			// Pack the data
       
   749 	    	package.PackData( &data );
       
   750 	    	// Send SS Envelope
       
   751 	    	iSatTsy->MessageManager()->HandleRequestL( ESatTsySendEnvelope, 
       
   752 	    	    &package );   
       
   753             }
       
   754         else
       
   755             {
       
   756             // NAA does not support USSD and converting it to SS was impossible.
       
   757             // The response must be sent back to NAA, to notify for the 
       
   758             // occurred error during the creation of an envelope
       
   759 	    	iSatTsy->MessageManager()->HandleRequestL( ESatTsyEnvelopeError );        
       
   760             }        
       
   761         }
       
   762 	}
       
   763 
       
   764 // -----------------------------------------------------------------------------
       
   765 // CSatCCTsy::IsOnlyDigitsInUssd
       
   766 // This methods returns ETrue when a Ussd string contains only "*", "#", and 
       
   767 // the numbers 0-9. Note: Ussd string is always received in packed format, when 
       
   768 // it is 7-bit GSM default alphabet.
       
   769 // -----------------------------------------------------------------------------
       
   770 //  
       
   771 TBool CSatCCTsy::IsOnlyDigitsInUssd
       
   772         (
       
   773         const TDesC8& aUSSDString
       
   774         )
       
   775     {    
       
   776     TFLOGSTRING("CSAT: CSatCCTsy::IsOnlyDigitsInUssd." );        
       
   777     // Unpack it
       
   778     TBuf8<KMaxUssdStringLengthInBytes> ussdString;
       
   779     TSatUtility::Packed7to8Unpacked( aUSSDString, ussdString );    
       
   780     TBool ret( ETrue );
       
   781     
       
   782     for( TInt k=0; k < ussdString.Length(); k++ )
       
   783         {
       
   784         if ( ( ussdString[k] != '#' ) &&
       
   785              ( ussdString[k] != '*' ) &&
       
   786              ( ussdString[k] != '+' ) &&
       
   787              ( ussdString[k] < '0'  || ussdString[k] > '9' ) )
       
   788             {
       
   789             ret = EFalse;
       
   790             break;
       
   791             }
       
   792         }
       
   793     
       
   794     return ret;
       
   795     }
       
   796     
       
   797 // -----------------------------------------------------------------------------
       
   798 // CSatCCTsy::HasProactiveOrigin
       
   799 // Checks whether the given address matches with the one saved (from PCmd).
       
   800 // -----------------------------------------------------------------------------
       
   801 //    
       
   802 TBool CSatCCTsy::HasProactiveOrigin
       
   803         ( 
       
   804         const TDesC8& aAddress 
       
   805         )
       
   806     {
       
   807     TFLOGSTRING("CSAT: CSatCCTsy::HasProactiveOrigin");
       
   808     TBool match( EFalse );
       
   809     
       
   810     if ( aAddress.Length() )
       
   811         {
       
   812         // Check first if there is a + in the beginning of the given address
       
   813         if ( '+' == aAddress[0] )
       
   814             {
       
   815             // It means we need to drop the first character out from comparison
       
   816             if ( iProactiveCommandAddress == aAddress.Mid( 1 ) )
       
   817                 {
       
   818                 TFLOGSTRING("CSAT: CSatCCTsy::HasProactiveOrigin, Match!");
       
   819                 match = ETrue;
       
   820                 }
       
   821             }
       
   822         // Otherwise we can use the whole string for checking
       
   823         else if ( iProactiveCommandAddress == aAddress )
       
   824             {
       
   825             TFLOGSTRING("CSAT: CSatCCTsy::HasProactiveOrigin, Match!");
       
   826             match = ETrue;
       
   827             }
       
   828         }
       
   829     else
       
   830         {
       
   831         TFLOGSTRING("CSAT: CSatCCTsy::HasProactiveOrigin, \
       
   832             Invalid input address");
       
   833         }
       
   834         
       
   835     return match;
       
   836     }       
       
   837 
       
   838 
       
   839 //  End of File 
       
   840