satengine/SatServer/Commands/OpenChannelCmd/src/COpenChannelHandler.cpp
changeset 0 ff3b6d0fd310
child 11 ba42c4bd84dd
child 15 d7fc66ccd6fb
equal deleted inserted replaced
-1:000000000000 0:ff3b6d0fd310
       
     1 /*
       
     2 * Copyright (c) 2002-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 "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:  Handles OpenChannel command
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include    <etelpckt.h>
       
    20 #include    <etelmmerr.h>
       
    21 
       
    22 #include    "COpenChannelHandler.h"
       
    23 #include    "MSatApi.h"
       
    24 #include    "MSatUtils.h"
       
    25 #include    "MSatUiSession.h"
       
    26 #include    "MSatSystemState.h"
       
    27 #include    "MSatApnHandler.h"
       
    28 #include    "SatSOpcodes.h"
       
    29 #include    "MSatSUiClientHandler.h"
       
    30 #include    "SatLog.h"
       
    31 #include    "extendedconnpref.h"
       
    32 
       
    33 const TUint8 KChannelStatusLength( 2 );
       
    34 
       
    35 // ======== MEMBER FUNCTIONS ========
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // Two-phased constructor.
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 COpenChannelHandler* COpenChannelHandler::NewL( MSatUtils* aUtils )
       
    42     {
       
    43     LOG( SIMPLE, "OPENCHANNEL: COpenChannelHandler::NewL calling" )
       
    44 
       
    45     COpenChannelHandler* self = new( ELeave ) COpenChannelHandler;
       
    46 
       
    47     CleanupStack::PushL( self );
       
    48     self->BaseConstructL( aUtils );
       
    49     self->ConstructL();
       
    50     CleanupStack::Pop( self );
       
    51 
       
    52     LOG( SIMPLE, "OPENCHANNEL: COpenChannelHandler::NewL exiting" )
       
    53     return self;
       
    54     }
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // Destructor
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 COpenChannelHandler::~COpenChannelHandler()
       
    61     {
       
    62     LOG( SIMPLE,
       
    63         "OPENCHANNEL: COpenChannelHandler::~COpenChannelHandler calling" )
       
    64 
       
    65     Cancel();
       
    66     iDataChannel = NULL;
       
    67 
       
    68     LOG( SIMPLE,
       
    69         "OPENCHANNEL: COpenChannelHandler::~CCloseChannelHandler exiting" )
       
    70     }
       
    71 
       
    72 // ---------------------------------------------------------------------------
       
    73 // From class MSatCommand.
       
    74 // Response from the client.
       
    75 // ---------------------------------------------------------------------------
       
    76 //
       
    77 void COpenChannelHandler::ClientResponse()
       
    78     {
       
    79     LOG( SIMPLE, "OPENCHANNEL: COpenChannelHandler::ClientResponse calling" )
       
    80 
       
    81     // Query response from client.
       
    82     if ( !iQueryRsp.iAccepted ) // Not accepted by user
       
    83         {
       
    84         // Close data channel
       
    85         CloseChannel();
       
    86 
       
    87         if ( iQueryRsp.iSessionTerminatedByUser ) // Terminated by user
       
    88             {
       
    89             LOG( NORMAL, "OPENCHANNEL: COpenChannelHandler::ClientResponse \
       
    90                 Session terminated by user" )
       
    91             // Notify sim session end command that next sim session end
       
    92             // should close the ui session.
       
    93             iUtils->NotifyEvent( MSatUtils::ESessionTerminatedByUser );
       
    94 
       
    95             // Terminal response, SimSessionTerminatedByUser
       
    96             iOpenChannelRsp.iGeneralResult = RSat::KPSessionTerminatedByUser;
       
    97             }
       
    98         else
       
    99             {
       
   100             LOG( NORMAL, "OPENCHANNEL: COpenChannelHandler::ClientResponse \
       
   101                 User not accept command" )
       
   102 
       
   103             // Send terminal response -> User not accepted
       
   104             iOpenChannelRsp.iGeneralResult = RSat::KPCmdNotAcceptedByUser;
       
   105             }
       
   106 
       
   107         iOpenChannelRsp.iInfoType = RSat::KNoAdditionalInfo;
       
   108         iOpenChannelRsp.iAdditionalInfo.Zero();
       
   109         iOpenChannelRsp.SetPCmdNumber( iOpenChannelData.PCmdNumber() );
       
   110         TerminalRsp( iPCmd, iOpenChannelRspPckg );
       
   111         }
       
   112     else // Accepted by user
       
   113         {
       
   114         LOG( NORMAL,
       
   115             "OPENCHANNEL: COpenChannelHandler::ClientResponse User accepted" )
       
   116         // User accepted
       
   117         const TInt linkEst( iOpenChannelData.iLinkEst );
       
   118 
       
   119         // SetUp channel if activation is on demand
       
   120         if ( ( RSat::EOnDemand == linkEst ) && ( KErrNone != SetUpChannel() ) )
       
   121             {
       
   122             // Close channel and send error if setup failed
       
   123             CloseChannel();
       
   124             LOG( NORMAL, "OPENCHANNEL: COpenChannelHandler::ClientResponse \
       
   125                 SetUp failed" )
       
   126             iOpenChannelRsp.iGeneralResult = RSat::KMeUnableToProcessCmd;
       
   127             iOpenChannelRsp.iInfoType = RSat::KNoAdditionalInfo;
       
   128             iOpenChannelRsp.iAdditionalInfo.Zero();
       
   129             iOpenChannelRsp.SetPCmdNumber( iOpenChannelData.PCmdNumber() );
       
   130             TerminalRsp( iPCmd, iOpenChannelRspPckg );
       
   131             }
       
   132         else
       
   133             {
       
   134             // Send terminal response
       
   135             SendSuccessTerminalRsp();
       
   136             }
       
   137 
       
   138         }
       
   139 
       
   140     LOG( SIMPLE, "OPENCHANNEL: COpenChannelHandler::ClientResponse exiting" )
       
   141     }
       
   142 
       
   143 // -----------------------------------------------------------------------------
       
   144 // From class MSatConnectionObserver.
       
   145 // Notification from the connection.
       
   146 // -----------------------------------------------------------------------------
       
   147 //
       
   148 void COpenChannelHandler::ConnectionNotification( TInt aError )
       
   149     {
       
   150     LOG2( SIMPLE, "OPENCHANNEL: COpenChannelHandler::ConnectionNotification\
       
   151          calling with code %i", aError )
       
   152 
       
   153     // Check connection status
       
   154     if ( KErrNone == aError )
       
   155         {
       
   156         // If information indication to the user is needed, show it now.
       
   157         if ( iNeedUiSession )
       
   158             {
       
   159             LOG( NORMAL, "OPENCHANNEL: COpenChannelHandler::HandleCommand \
       
   160                 Sending UI Notification" )
       
   161 
       
   162             // Send confirmation to UI and wait for client response
       
   163             SendConfirmToUi();
       
   164             }
       
   165         else
       
   166             {
       
   167             // Send successfull terminal response
       
   168             SendSuccessTerminalRsp();
       
   169             }
       
   170         }
       
   171     else
       
   172         {
       
   173         // Activation failed, Close channel and send error
       
   174         LOG( NORMAL, "OPENCHANNEL: COpenChannelHandler::ConnectionNotification \
       
   175             Channel activation failed" )
       
   176 
       
   177         // Close channel
       
   178         CloseChannel();
       
   179 
       
   180         // PDP Activation failed
       
   181         iOpenChannelRsp.iGeneralResult = RSat::KBearerIndepProtocolError;
       
   182         iOpenChannelRsp.iInfoType = RSat::KMeProblem;
       
   183         iOpenChannelRsp.iAdditionalInfo.SetLength( 1 );
       
   184         iOpenChannelRsp.iAdditionalInfo[0] = RSat::KNoSpecificBIPError;
       
   185         iOpenChannelRsp.SetPCmdNumber( iOpenChannelData.PCmdNumber() );
       
   186         TerminalRsp( iPCmd, iOpenChannelRspPckg );
       
   187         }
       
   188 
       
   189     LOG( SIMPLE,
       
   190         "OPENCHANNEL: COpenChannelHandler::ConnectionNotification exiting" )
       
   191     }
       
   192 
       
   193 // -----------------------------------------------------------------------------
       
   194 // From class CSatCommandHandler.
       
   195 // Event notification.
       
   196 // -----------------------------------------------------------------------------
       
   197 //
       
   198 void COpenChannelHandler::Event( TInt aEvent )
       
   199     {
       
   200     LOG( SIMPLE, "OPENCHANNEL: COpenChannelHandler::Event calling" )
       
   201 
       
   202     // Check event
       
   203     if ( MSatUtils::ESatUiLaunched == aEvent )
       
   204         {
       
   205         LOG( SIMPLE, "OPENCHANNEL: COpenChannelHandler::Event ESatUiLaunched" )
       
   206         iUtils->UnregisterEvent( this, MSatUtils::ESatUiLaunched );
       
   207 
       
   208         // Send confirm to UI
       
   209         SendConfirmToUi();
       
   210         }
       
   211 
       
   212     LOG( SIMPLE, "OPENCHANNEL: COpenChannelHandler::Event exiting" )
       
   213     }
       
   214 
       
   215 // -----------------------------------------------------------------------------
       
   216 // From class CActive.
       
   217 // Cancels the sat request.
       
   218 // -----------------------------------------------------------------------------
       
   219 //
       
   220 void COpenChannelHandler::DoCancel()
       
   221     {
       
   222     LOG( SIMPLE, "OPENCHANNEL: COpenChannelHandler::DoCancel calling" )
       
   223 
       
   224     iUtils->USatAPI().NotifyOpenChannelCancel();
       
   225 
       
   226     LOG( SIMPLE, "OPENCHANNEL: COpenChannelHandler::DoCancel exiting" )
       
   227     }
       
   228 
       
   229 // -----------------------------------------------------------------------------
       
   230 // From class CSatCommandHandler.
       
   231 // Requests the command notification.
       
   232 // -----------------------------------------------------------------------------
       
   233 //
       
   234 void COpenChannelHandler::IssueUSATRequest( TRequestStatus& aStatus )
       
   235     {
       
   236     LOG( SIMPLE, "OPENCHANNEL: COpenChannelHandler::IssueUSATRequest calling" )
       
   237 
       
   238     // Reset values
       
   239     iDataChannel = NULL;
       
   240     iSetUpWithModifications = EFalse;
       
   241     iNeedUiSession = EFalse;
       
   242 
       
   243     // Reset open channel data.
       
   244     new (&iOpenChannelData) RSat::TOpenGprsChannelV4();
       
   245     new (&iQueryData) TSatQueryV1();
       
   246 
       
   247     iUtils->USatAPI().NotifyOpenChannel( aStatus, iOpenChannelPckg );
       
   248     iUtils->NotifyEvent( MSatUtils::EBipCommandDoneExecuting );
       
   249 
       
   250     LOG( SIMPLE, "OPENCHANNEL: COpenChannelHandler::IssueUSATRequest exiting" )
       
   251     }
       
   252 
       
   253 // -----------------------------------------------------------------------------
       
   254 // From class CSatCommandHandler.
       
   255 // OpenChannel command is not allowed in following situations:
       
   256 //      - Phone is not registered to homenetwork and roaming.
       
   257 //      - phone is ringing, alerting or call is on and OpenChannel command
       
   258 //        is "make call only if not busy", "make call only if not busy wiht
       
   259 //        redial" or "Call type not set".
       
   260 // -----------------------------------------------------------------------------
       
   261 //
       
   262 TBool COpenChannelHandler::CommandAllowed()
       
   263     {
       
   264     LOG( SIMPLE, "OPENCHANNEL: COpenChannelHandler::CommandAllowed calling" )
       
   265 
       
   266     // Define the PCmd here since this is the first place after notification
       
   267     iPCmd = RSat::EOpenChannelGprs; // Other possible values
       
   268                                     // RSat::EOpenChannelCs
       
   269                                     // RSat::EOpenChannelLocal
       
   270 
       
   271     // Check parameters here, because every terminal response must contain info
       
   272     // about Bearer Set and BufferSize.
       
   273     TBool result( CheckParameters() );
       
   274 
       
   275     // Indicates channel activation type
       
   276     const TBool activateImmediately(
       
   277         RSat::EImmediate == iOpenChannelData.iLinkEst );
       
   278 
       
   279     //lint -e{961} Else block not needed.
       
   280     if ( ( RSat::EAlphaIdProvided != iOpenChannelData.iAlphaId.iStatus ) &&
       
   281          ( RSat::ESelfExplanatory == iOpenChannelData.iIconId.iQualifier ||
       
   282            RSat::ENotSelfExplanatory == iOpenChannelData.iIconId.iQualifier ) )
       
   283         {
       
   284         iOpenChannelRsp.iGeneralResult = RSat::KCmdDataNotUnderstood;
       
   285         iOpenChannelRsp.iInfoType = RSat::KNoAdditionalInfo;
       
   286         iOpenChannelRsp.iAdditionalInfo.Zero();
       
   287         result = EFalse;
       
   288         LOG( NORMAL, "OPENCHANNEL: COpenChannelHandler::CommandAllowed \
       
   289             icon received without alpha id" )
       
   290         }
       
   291     // If parameters are OK, check rest.
       
   292     else if ( result && activateImmediately )
       
   293         {
       
   294         // Set result to False. If checks goes OK, this is set to ETrue.
       
   295         result = EFalse;
       
   296 
       
   297         RMobilePhone::TMobilePhoneRegistrationStatus registrationStatus(
       
   298             iUtils->SystemState().GetNetworkRegistrationStatus() );
       
   299 
       
   300         // Indicates is there service on network
       
   301         const TBool noService(
       
   302             ( RMobilePhone::ERegisteredOnHomeNetwork != registrationStatus ) &&
       
   303             ( RMobilePhone::ERegisteredRoaming != registrationStatus ) );
       
   304 
       
   305         if ( RMobilePhone::ERegistrationUnknown == registrationStatus )
       
   306             {
       
   307             LOG( NORMAL,
       
   308                 "OPENCHANNEL: COpenChannelHandler::CommandAllowed \
       
   309                 NetworkRegStatus not available" )
       
   310             iOpenChannelRsp.iGeneralResult = RSat::KMeUnableToProcessCmd;
       
   311             iOpenChannelRsp.iInfoType = RSat::KMeProblem;
       
   312             iOpenChannelRsp.iAdditionalInfo.SetLength( 1 );
       
   313             iOpenChannelRsp.iAdditionalInfo[0] = RSat::KNoSpecificMeProblem;
       
   314             }
       
   315         // Check registration status
       
   316         else if ( noService )
       
   317             {
       
   318             // No service
       
   319             LOG( NORMAL,
       
   320                 "OPENCHANNEL: COpenChannelHandler::CommandAllowed No service" )
       
   321 
       
   322             iOpenChannelRsp.iGeneralResult = RSat::KMeUnableToProcessCmd;
       
   323             iOpenChannelRsp.iInfoType = RSat::KMeProblem;
       
   324             iOpenChannelRsp.iAdditionalInfo.SetLength( 1 );
       
   325             iOpenChannelRsp.iAdditionalInfo[0] = RSat::KNoService;
       
   326             }
       
   327         else
       
   328             {
       
   329             // Command allowed
       
   330             LOG( NORMAL, "OPENCHANNEL: COpenChannelHandler::CommandAllowed \
       
   331                 Command is allowed Immediate activation" )
       
   332             result = ETrue;
       
   333             }
       
   334         }
       
   335 
       
   336     if ( !result ) // Send Terminal response, if result is not OK
       
   337         {
       
   338         LOG( NORMAL, "OPENCHANNEL: COpenChannelHandler::CommandAllowed \
       
   339         result not OK" )
       
   340         iOpenChannelRsp.SetPCmdNumber( iOpenChannelData.PCmdNumber() );
       
   341         TerminalRsp( iPCmd, iOpenChannelRspPckg );
       
   342         }
       
   343     else
       
   344         {
       
   345         // Register to handle UI commands.
       
   346         TRAPD( err, iUtils->RegisterServiceRequestL( ESatSProactiveQuery,
       
   347             ESatSProactiveQueryResponse, this ) );
       
   348 
       
   349         LOG2( NORMAL, "OPENCHANNEL: COpenChannelHandler::CommandAllowed \
       
   350         err: %d", err )
       
   351         // Above function leaves only when there is not enough memory to
       
   352         // allocate new object. So this case is very rare.
       
   353         if ( KErrNone != err )
       
   354             {
       
   355             LOG( NORMAL, "OPENCHANNEL: COpenChannelHandler::CommandAllowed \
       
   356                  Error while registering service request" )
       
   357 
       
   358             // Send general terminal response (no BIP specific)
       
   359             iOpenChannelRsp.iGeneralResult = RSat::KMeUnableToProcessCmd;
       
   360             iOpenChannelRsp.iInfoType = RSat::KMeProblem;
       
   361             iOpenChannelRsp.iAdditionalInfo.SetLength( 1 );
       
   362             iOpenChannelRsp.iAdditionalInfo[0] = RSat::KNoSpecificMeProblem;
       
   363             iOpenChannelRsp.SetPCmdNumber( iOpenChannelData.PCmdNumber() );
       
   364             TerminalRsp( iPCmd, iOpenChannelRspPckg );
       
   365 
       
   366             // Cannot complete, there are some major memory problems
       
   367             result = EFalse;
       
   368             }
       
   369         // Set icon command flag whether icon data was received and 
       
   370         // set qualifier to no icon id
       
   371         // To be removed when icons are allowed in this command
       
   372         else if ( ( RSat::ESelfExplanatory ==
       
   373             iOpenChannelData.iIconId.iQualifier ) ||
       
   374             ( RSat::ENotSelfExplanatory ==
       
   375             iOpenChannelData.iIconId.iQualifier ) )
       
   376             {
       
   377             LOG( NORMAL, "OPENCHANNEL: COpenChannelHandler::CommandAllowed \
       
   378                  ENoIconId" )
       
   379             iIconCommand = ETrue;
       
   380             iOpenChannelData.iIconId.iQualifier = RSat::ENoIconId;
       
   381             }
       
   382         else
       
   383             {
       
   384             LOG( NORMAL, "OPENCHANNEL: COpenChannelHandler::CommandAllowed \
       
   385                  others" )
       
   386             iIconCommand = EFalse;
       
   387             }
       
   388         }
       
   389 
       
   390     LOG2( SIMPLE, "OPENCHANNEL: COpenChannelHandler::CommandAllowed exiting,\
       
   391     result: %d", result )
       
   392     return result;
       
   393     }
       
   394 
       
   395 // -----------------------------------------------------------------------------
       
   396 // From class CSatCommandHandler.
       
   397 // Need for ui session.
       
   398 // -----------------------------------------------------------------------------
       
   399 //
       
   400 TBool COpenChannelHandler::NeedUiSession()
       
   401     {
       
   402     LOG( SIMPLE, "OPENCHANNEL: COpenChannelHandler::NeedUiSession calling" )
       
   403 
       
   404     // UI is NOT needed in case where AlphaID is provided and it is a NULL
       
   405     iNeedUiSession =
       
   406         !( RSat::EAlphaIdNull == iOpenChannelData.iAlphaId.iStatus );
       
   407 
       
   408     LOG( SIMPLE, "OPENCHANNEL: COpenChannelHandler::NeedUiSession exiting" )
       
   409     // We do not need UI session at this point, but we will launch it by
       
   410     // ourselves when we do.
       
   411     return EFalse;
       
   412     }
       
   413 
       
   414 // -----------------------------------------------------------------------------
       
   415 // From class CSatCommandHandler.
       
   416 // Called when USAT API notifies that command.
       
   417 // -----------------------------------------------------------------------------
       
   418 //
       
   419 void COpenChannelHandler::HandleCommand()
       
   420     {
       
   421     LOG( SIMPLE, "OPENCHANNEL: COpenChannelHandler::HandleCommand calling" )
       
   422 
       
   423     // Notify others
       
   424     iUtils->NotifyEvent( MSatUtils::EOpenChannelExecuting );
       
   425     iUtils->NotifyEvent( MSatUtils::EBipCommandExecuting );
       
   426 
       
   427     TInt error( MSatBIPUtils::ESatBIPNoChannelAvail ); // By default, negative
       
   428 
       
   429     // Create data channel
       
   430     TRAPD( leaveErr,
       
   431         iDataChannel = iUtils->BipUtils().CreateChannelL(
       
   432             iBearerType, error ) );
       
   433 
       
   434     // Check the channel creation
       
   435     if ( ( MSatBIPUtils::ESatBIPSuccess != error ) || 
       
   436          ( KErrNone != leaveErr ) )
       
   437         {
       
   438         LOG( NORMAL, "OPENCHANNEL: COpenChannelHandler::HandleCommand\
       
   439             Channel creation failed" )
       
   440 
       
   441         // Channel creation failed -> Send terminal response
       
   442         iOpenChannelRsp.iGeneralResult = RSat::KBearerIndepProtocolError;
       
   443         iOpenChannelRsp.iInfoType = RSat::KMeProblem;
       
   444         iOpenChannelRsp.iAdditionalInfo.SetLength( 1 );
       
   445         iOpenChannelRsp.iAdditionalInfo[0] = RSat::KNoChannelAvailable;
       
   446         iOpenChannelRsp.SetPCmdNumber( iOpenChannelData.PCmdNumber() );
       
   447         TerminalRsp( iPCmd, iOpenChannelRspPckg );
       
   448 
       
   449         LOG( SIMPLE, "OPENCHANNEL: COpenChannel::HandleCommand exiting" )
       
   450         return;
       
   451         }
       
   452 
       
   453     LOG( NORMAL,
       
   454         "OPENCHANNEL: COpenChannelHandler::HandleCommand Channel creation OK" )
       
   455 
       
   456     // Open channel or request confirmation from user
       
   457     const TInt linkEst( iOpenChannelData.iLinkEst );
       
   458 
       
   459     // If not confirmation to user or immediate activation, open channel
       
   460     if ( ( !iNeedUiSession || RSat::EImmediate == linkEst )
       
   461            && KErrNone != SetUpChannel() )
       
   462         {
       
   463         // Setup failed, close channel and send error
       
   464         LOG( NORMAL,
       
   465             "OPENCHANNEL: COpenChannelHandler::HandleCommand SetUp failed" )
       
   466 
       
   467         // Close channel, there was an error
       
   468         CloseChannel();
       
   469 
       
   470         // Channel setup failed
       
   471         iOpenChannelRsp.iGeneralResult = RSat::KBearerIndepProtocolError;
       
   472         iOpenChannelRsp.iInfoType = RSat::KMeProblem;
       
   473         iOpenChannelRsp.iAdditionalInfo.SetLength( 1 );
       
   474         iOpenChannelRsp.iAdditionalInfo[0] = RSat::KNoSpecificBIPError;
       
   475         iOpenChannelRsp.SetPCmdNumber( iOpenChannelData.PCmdNumber() );
       
   476         TerminalRsp( iPCmd, iOpenChannelRspPckg );
       
   477 
       
   478         LOG( SIMPLE, "OPENCHANNEL: COpenChannelHandler::HandleCommand \
       
   479             exiting" )
       
   480         return;
       
   481         }
       
   482 
       
   483     // If immediate activation, activate.
       
   484     if ( RSat::EImmediate == linkEst )
       
   485         {
       
   486         LOG( SIMPLE, "OPENCHANNEL: COpenChannelHandler::HandleCommand \
       
   487              immediate activation" )
       
   488         // Check activation
       
   489         TInt activateError = ActivateChannel();
       
   490         if ( KErrNone != activateError )
       
   491             {
       
   492             // Activation failed, Close channel and send error
       
   493             LOG2( NORMAL, "OPENCHANNEL: COpenChannelHandler::HandleCommand \
       
   494                 Channel activation failed error = %i", activateError )
       
   495             // Close channel
       
   496             CloseChannel();
       
   497 
       
   498             // Check is there a call ongoing
       
   499             const TBool callIsOngoing( iUtils->SystemState().IsCallActive() ||
       
   500                 iUtils->SystemState().IsCallIncoming() );
       
   501 
       
   502             iOpenChannelRsp.iGeneralResult = RSat::KBearerIndepProtocolError;
       
   503 
       
   504             // Map the error to correct response
       
   505             if ( KErrGprsUserAuthenticationFailure == activateError )
       
   506                 {
       
   507                 LOG( DETAILED, 
       
   508                 "OPENCHANNEL: COpenChannelHandler::HandleCommand Security \
       
   509                 error" )
       
   510                 activateError = RSat::KSecurityError;
       
   511                 }
       
   512             else if ( KErrGprsServicesNotAllowed == activateError || callIsOngoing )
       
   513                 {
       
   514                 LOG( DETAILED, 
       
   515                 "OPENCHANNEL: COpenChannelHandler::HandleCommand Busy on \
       
   516                 call or CC on GPRS" )
       
   517                 activateError = RSat::KMeBusyOnCall;
       
   518                 iOpenChannelRsp.iGeneralResult = RSat::KMeUnableToProcessCmd;
       
   519                 }
       
   520             else if ( ( KErrMMEtelActivationBlockedByCallControlNoText ==
       
   521                             activateError ) ||
       
   522                       ( KErrMMEtelActivationBlockedByCallControlWithText ==
       
   523                             activateError ) )
       
   524                 {
       
   525                 iOpenChannelRsp.iGeneralResult = RSat::KInteractionWithCCPermanentError;
       
   526                 activateError = RSat::KActionNotAllowed;
       
   527 
       
   528                 LOG( DETAILED, 
       
   529                 "OPENCHANNEL: COpenChannelHandler::HandleCommand CC on GPRS \
       
   530                 not allowed" )
       
   531                 }
       
   532             else
       
   533                 {
       
   534                 LOG( DETAILED, 
       
   535                 "OPENCHANNEL: COpenChannelHandler::HandleCommand No specific \
       
   536                 BIP error" )
       
   537                 activateError = RSat::KNoSpecificBIPError;
       
   538                 }
       
   539 
       
   540             // PDP Activation failed
       
   541             iOpenChannelRsp.iInfoType = RSat::KMeProblem;
       
   542             iOpenChannelRsp.iAdditionalInfo.SetLength( 1 );
       
   543             iOpenChannelRsp.iAdditionalInfo[0] =
       
   544                 static_cast<TUint16>( activateError );
       
   545             iOpenChannelRsp.SetPCmdNumber( iOpenChannelData.PCmdNumber() );
       
   546             TerminalRsp( iPCmd, iOpenChannelRspPckg );
       
   547             }
       
   548         }
       
   549     else // OnDemand. Send terminal response or confirm to UI
       
   550         {
       
   551         // If information indication to the user is needed, show it now.
       
   552         if ( iNeedUiSession )
       
   553             {
       
   554             LOG( NORMAL, "OPENCHANNEL: COpenChannelHandler::HandleCommand \
       
   555                 Sending UI Notification" )
       
   556             // Send confirmation to UI and wait for client response
       
   557             SendConfirmToUi();
       
   558             }
       
   559         else
       
   560             {
       
   561             // Send successfull terminal response
       
   562             SendSuccessTerminalRsp();
       
   563             }
       
   564         }
       
   565 
       
   566     LOG( SIMPLE, "OPENCHANNEL: COpenChannelHandler::HandleCommand exiting" )
       
   567     }
       
   568 
       
   569 // -----------------------------------------------------------------------------
       
   570 // From class CSatCommandHandler.
       
   571 // Indicates the failure of launching ui client.
       
   572 // -----------------------------------------------------------------------------
       
   573 //
       
   574 void COpenChannelHandler::UiLaunchFailed()
       
   575     {
       
   576     LOG( SIMPLE, "OPENCHANNEL: COpenChannelHandler::UiLaunchFailed calling" )
       
   577 
       
   578     iOpenChannelRsp.iGeneralResult = RSat::KMeUnableToProcessCmd;
       
   579     iOpenChannelRsp.iInfoType = RSat::KMeProblem;
       
   580     iOpenChannelRsp.iAdditionalInfo.SetLength( 1 );
       
   581     iOpenChannelRsp.iAdditionalInfo[0] = RSat::KNoSpecificMeProblem;
       
   582     iOpenChannelRsp.SetPCmdNumber( iOpenChannelData.PCmdNumber() );
       
   583     TerminalRsp( iPCmd, iOpenChannelRspPckg );
       
   584 
       
   585     LOG( SIMPLE, "OPENCHANNEL: COpenChannelHandler::UiLaunchFailed exiting" )
       
   586     }
       
   587 
       
   588 // -----------------------------------------------------------------------------
       
   589 // C++ default constructor can NOT contain any code, that
       
   590 // might leave.
       
   591 // -----------------------------------------------------------------------------
       
   592 //
       
   593 //lint -e{1403, 1769} Can not be initialized.
       
   594 COpenChannelHandler::COpenChannelHandler() :
       
   595     CSatCommandHandler(),
       
   596     iOpenChannelData(),
       
   597     iOpenChannelPckg( iOpenChannelData ),
       
   598     iOpenChannelRsp(),
       
   599     iOpenChannelRspPckg( iOpenChannelRsp ),
       
   600     iQueryData(),
       
   601     iQueryPckg( iQueryData ),
       
   602     iQueryRsp(),
       
   603     iQueryRspPckg( iQueryRsp ),
       
   604     // To be removed when icons are allowed in this command
       
   605     iIconCommand( EFalse )
       
   606     {
       
   607     LOG( SIMPLE, "OPENCHANNEL: COpenChannelHandler::COpenChannelHandler \
       
   608         calling - exiting" )
       
   609     }
       
   610 
       
   611 // -----------------------------------------------------------------------------
       
   612 // Symbian 2nd phase constructor can leave.
       
   613 // -----------------------------------------------------------------------------
       
   614 //
       
   615 void COpenChannelHandler::ConstructL()
       
   616     {
       
   617     LOG( SIMPLE, "OPENCHANNEL: COpenChannelHandler::ConstructL calling" )
       
   618 
       
   619     iUtils->RegisterServiceRequestL( ESatSProactiveQuery,
       
   620         ESatSProactiveQueryResponse, this );
       
   621 
       
   622     LOG( SIMPLE, "OPENCHANNEL: COpenChannelHandler::ConstructL exiting" )
       
   623     }
       
   624 
       
   625 // -----------------------------------------------------------------------------
       
   626 // Sets new connection settings for channel to open.
       
   627 // -----------------------------------------------------------------------------
       
   628 //
       
   629 void COpenChannelHandler::SetConnectionSettingsL(
       
   630     MSatBIPUtils::TSatBearerType aBearerType )
       
   631     {
       
   632     LOG2( SIMPLE,
       
   633         "OPENCHANNEL: COpenChannelHandler::SetConnectionSettingsL calling,\
       
   634         aBearerType: %d", aBearerType )
       
   635 
       
   636     switch ( aBearerType )
       
   637         {
       
   638         case MSatBIPUtils::ESatGPRS:
       
   639             {
       
   640             // Resolve override settings
       
   641             if ( iOpenChannelData.iAccessName.Length() > 0 )
       
   642                 {
       
   643                 LOG( NORMAL, 
       
   644                 "OPENCHANNEL: COpenChannelHandler::SetConnectionSettingsL \
       
   645                 Getting APN" )
       
   646 
       
   647                 TUint32 iapId( 0 );
       
   648                 TUint32 nwId( 0 );
       
   649                 TBool apnCreated( EFalse );
       
   650 
       
   651                 RPacketContext::TProtocolType pdpType = 
       
   652                            RPacketContext::EPdpTypeIPv6;
       
   653                 
       
   654                 if ( RSat::EIPv4Address ==
       
   655                     iOpenChannelData.iDestinationAddress.iType )
       
   656                     {
       
   657                     LOG( NORMAL, 
       
   658                     "OPENCHANNEL: COpenChannelHandler::SetConnectionSettingsL \
       
   659                     IPV4 Address" )
       
   660                     pdpType = RPacketContext::EPdpTypeIPv4;
       
   661                     }
       
   662                 iUtils->BipUtils().ApnHandler().GetApnInfoL
       
   663                     (
       
   664                     iOpenChannelData.iAccessName,
       
   665                     iOpenChannelData.iUserLogin,
       
   666                     iOpenChannelData.iUserPassword,
       
   667                     iapId,
       
   668                     nwId,
       
   669                     apnCreated,
       
   670                     pdpType, // IPv6 or IPv4
       
   671                     iOpenChannelData.iLocalAddress.iAddress
       
   672                     );
       
   673 
       
   674                 if ( apnCreated )
       
   675                     {
       
   676                     LOG( NORMAL, 
       
   677                     "OPENCHANNEL: COpenChannelHandler::SetConnectionSettingsL \
       
   678                     APN created by SAT" )
       
   679                     // Store APN Id for later use
       
   680                     iConnectionInfo.iCreatedApnId = nwId;
       
   681                     }
       
   682 
       
   683                 SetOverrideSettingsL( iapId );
       
   684                 }
       
   685             else
       
   686                 {
       
   687                 LOG( NORMAL, "OPENCHANNEL: COpenChannelHandler::SetConnectionSettingsL \
       
   688                 No APN, using defaults" )
       
   689                 // No APN, use default settings
       
   690                 SetOverrideSettingsL( 0 );
       
   691                 }
       
   692             break;
       
   693             }
       
   694 
       
   695         default:
       
   696             {
       
   697             LOG( NORMAL, "OPENCHANNEL: COpenChannelHandler::\
       
   698                 SetConnectionSettingsL exiting default" )
       
   699             // Leave if not supported
       
   700             User::Leave( KErrNotSupported );
       
   701             }
       
   702         }
       
   703 
       
   704 #ifdef SAT_USE_DUMMY_TSY
       
   705     // No APN, use default settings
       
   706     SetOverrideSettingsL( 0 );
       
   707 #endif // SAT_USE_DUMMY_TSY
       
   708 
       
   709     LOG( SIMPLE,
       
   710         "OPENCHANNEL: COpenChannelHandler::SetConnectionSettingsL exiting" )
       
   711     }
       
   712 
       
   713 // -----------------------------------------------------------------------------
       
   714 // Sets override settings into connection information.
       
   715 // -----------------------------------------------------------------------------
       
   716 //
       
   717 void COpenChannelHandler::SetOverrideSettingsL( const TUint32 aIapId )
       
   718     {
       
   719     
       
   720     LOG2( SIMPLE,
       
   721     "OPENCHANNEL: COpenChannelHandler::SetOverrideSettingsL aIapId: %i", 
       
   722     aIapId )
       
   723 
       
   724     // Override connection preferences
       
   725     TExtendedConnPref* overrideSettings = new( ELeave ) TExtendedConnPref;
       
   726     overrideSettings->SetIapId( aIapId );
       
   727     overrideSettings->SetNoteBehaviour( 
       
   728             TExtendedConnPref::ENoteBehaviourConnSilent );
       
   729     iConnectionInfo.iOverrideSet = overrideSettings;
       
   730 
       
   731     LOG( SIMPLE,
       
   732         "OPENCHANNEL: COpenChannelHandler::SetOverrideSettingsL exiting" )
       
   733     }
       
   734 
       
   735 // -----------------------------------------------------------------------------
       
   736 // Sets up data channel. Does not activate context.
       
   737 // -----------------------------------------------------------------------------
       
   738 //
       
   739 TInt COpenChannelHandler::SetUpChannel()
       
   740     {
       
   741     LOG( SIMPLE, "OPENCHANNEL: COpenChannelHandler::SetUpChannel calling" )
       
   742 
       
   743     // get connection settings from CommDB and
       
   744     // set connection settings to data channel
       
   745     TRAPD( status,
       
   746            SetConnectionSettingsL( iBearerType );
       
   747            iDataChannel->SetupConnectionL( iConnectionInfo ); );
       
   748 
       
   749     LOG2( SIMPLE,
       
   750         "OPENCHANNEL: COpenChannelHandler::SetUpChannel exiting with status %i",
       
   751         status )
       
   752     return status;
       
   753     }
       
   754 
       
   755 // -----------------------------------------------------------------------------
       
   756 // Activates context.
       
   757 // -----------------------------------------------------------------------------
       
   758 //
       
   759 TInt COpenChannelHandler::ActivateChannel()
       
   760     {
       
   761     LOG( SIMPLE, "OPENCHANNEL: COpenChannelHandler::ActivateChannel calling" )
       
   762 
       
   763     // Activate the connection
       
   764     TRAPD( err, iDataChannel->ActivateConnectionL( this ) );
       
   765 
       
   766     LOG2( SIMPLE, "OPENCHANNEL: COpenChannelHandler::ActivateChannel exiting\
       
   767         with error %i:", err )
       
   768     return err;
       
   769     }
       
   770 
       
   771 // -----------------------------------------------------------------------------
       
   772 // Creates and sends the terminal response on successful cases.
       
   773 // -----------------------------------------------------------------------------
       
   774 //
       
   775 void COpenChannelHandler::SendSuccessTerminalRsp()
       
   776     {
       
   777     LOG( SIMPLE,
       
   778         "OPENCHANNEL: COpenChannelHandler::SendSuccessTerminalRsp calling" )
       
   779 
       
   780     iDataChannel->GetNegotiatedQoSParams( iOpenChannelRsp.iBearer.iParams );
       
   781 
       
   782     // Get the channel status
       
   783     RSat::TChannelStatus channelStatus;
       
   784     TRAPD( err, channelStatus = iUtils->BipUtils().GenerateChannelStatusL(
       
   785             iDataChannel->ChannelId(), 0 ) );
       
   786     LOG2( SIMPLE, "OPENCHANNEL: COpenChannelHandler::SendSuccessTerminalRsp \
       
   787           error: %i", err )
       
   788     
       
   789     if ( KErrNone == err )
       
   790         {
       
   791         iOpenChannelRsp.iInfoType = RSat::KChannelStatusInfo;
       
   792         iOpenChannelRsp.iAdditionalInfo.SetLength( KChannelStatusLength );
       
   793 
       
   794         // Channel ID + PDP context status
       
   795         iOpenChannelRsp.iAdditionalInfo[0] = channelStatus[0];
       
   796 
       
   797         // Channel status
       
   798         iOpenChannelRsp.iAdditionalInfo[1] = channelStatus[1];
       
   799         iOpenChannelRsp.SetPCmdNumber( iOpenChannelData.PCmdNumber() );
       
   800 
       
   801         // Define the result of this command handling
       
   802         if ( iSetUpWithModifications )
       
   803             {
       
   804             LOG( NORMAL, "OPENCHANNEL: COpenChannelHandler::HandleCommand\
       
   805                 Channel setup modified" )
       
   806             iOpenChannelRsp.iGeneralResult = RSat::KPerformedWithModifications;
       
   807             }
       
   808         else if ( !iQueryRsp.iRequestedIconDisplayed &&
       
   809             ( ( RSat::ESelfExplanatory ==
       
   810             iOpenChannelData.iIconId.iQualifier ) ||
       
   811             ( RSat::ENotSelfExplanatory ==
       
   812             iOpenChannelData.iIconId.iQualifier ) ) )
       
   813             {
       
   814             LOG( NORMAL, "OPENCHANNEL: COpenChannelHandler::HandleCommand\
       
   815                 Open channel successful, no icon displayed" )
       
   816             iOpenChannelRsp.iGeneralResult =
       
   817                 RSat::KSuccessRequestedIconNotDisplayed;
       
   818             }
       
   819         else
       
   820             {
       
   821             LOG( NORMAL, "OPENCHANNEL: COpenChannelHandler::HandleCommand\
       
   822                 Open channel successful" )
       
   823             iOpenChannelRsp.iGeneralResult = RSat::KSuccess;
       
   824             }
       
   825         }
       
   826     else
       
   827         {
       
   828         LOG( NORMAL, "OPENCHANNEL: COpenChannelHandler::HandleCommand\
       
   829             Channel not found!" )
       
   830         iOpenChannelRsp.iGeneralResult = RSat::KMeUnableToProcessCmd;
       
   831         iOpenChannelRsp.iInfoType = RSat::KMeProblem;
       
   832         iOpenChannelRsp.iAdditionalInfo.SetLength( 1 );
       
   833         iOpenChannelRsp.iAdditionalInfo[0] = RSat::KNoSpecificMeProblem;
       
   834         }
       
   835 
       
   836     // If command had icon data and was done succesfully, report that icon
       
   837     // was not shown
       
   838     // To be removed when icons are allowed in this command
       
   839     if ( ( RSat::KSuccess == iOpenChannelRsp.iGeneralResult ) &&
       
   840         iIconCommand )
       
   841         {
       
   842         LOG( SIMPLE, "COpenChannelHandler::SendSuccessTerminalRsp requested\
       
   843              icon not displayed" )
       
   844         iOpenChannelRsp.iGeneralResult =
       
   845             RSat::KSuccessRequestedIconNotDisplayed;
       
   846         }
       
   847 
       
   848     // Sending terminal response
       
   849     TerminalRsp( iPCmd, iOpenChannelRspPckg );
       
   850 
       
   851     LOG( SIMPLE,
       
   852         "OPENCHANNEL: COpenChannelHandler::SendSuccessTerminalRsp exiting" )
       
   853     }
       
   854 
       
   855 // -----------------------------------------------------------------------------
       
   856 // Sends confirmation query to UI.
       
   857 // -----------------------------------------------------------------------------
       
   858 //
       
   859 void COpenChannelHandler::SendConfirmToUi()
       
   860     {
       
   861     LOG( SIMPLE, "OPENCHANNEL: COpenChannelHandler::SendConfirmToUi calling" )
       
   862 
       
   863     // Command Duration for Mediator Client
       
   864     TUint8 commandDuration( KSatDurationNotSet );
       
   865 
       
   866     // Launch UI of not launched. This function is called again when UI is
       
   867     // launched.
       
   868     if ( !LaunchUiSession() )
       
   869         {
       
   870         LOG( SIMPLE, "OPENCHANNEL: COpenChannelHandler::SendConfirmToUi \
       
   871              not launch UI" )
       
   872         // Create IPC data to UI
       
   873         iQueryData.iCommand = ESatOpenChannelQuery;
       
   874         iQueryData.iQueryText = iOpenChannelData.iAlphaId.iAlphaId;
       
   875         iQueryData.iIconId.iIdentifier = iOpenChannelData.iIconId.iIdentifier;
       
   876         LOG2( SIMPLE, "COpenChannelHandler::SendConfirmToUi \
       
   877              iOpenChannelData.iIconId.iQualifier:%d",
       
   878              iOpenChannelData.iIconId.iQualifier )
       
   879         // Check Icon
       
   880         switch ( iOpenChannelData.iIconId.iQualifier )
       
   881             {
       
   882             case RSat::ESelfExplanatory:
       
   883                 {
       
   884                 // Icon qualifier is self explanatory (to display instead
       
   885                 // of the alpha id or text string).
       
   886                 iQueryData.iIconId.iIconQualifier = ESatSelfExplanatory;
       
   887                 break;
       
   888                 }
       
   889 
       
   890             case RSat::ENotSelfExplanatory:
       
   891                 {
       
   892                 // Icon qualifier is not self explanatory.
       
   893                 iQueryData.iIconId.iIconQualifier = ESatNotSelfExplanatory;
       
   894                 break;
       
   895                 }
       
   896 
       
   897             default:
       
   898                 {
       
   899                 // Icon qualifier not present
       
   900                 iQueryData.iIconId.iIconQualifier = ESatENoIconId;
       
   901                 break;
       
   902                 }
       
   903             }
       
   904         LOG2( SIMPLE, "COpenChannelHandler::SendConfirmToUi \
       
   905              iOpenChannelData.iAlphaId.iStatus:%d",
       
   906              iOpenChannelData.iAlphaId.iStatus )
       
   907         // Define AlphaID status
       
   908         switch ( iOpenChannelData.iAlphaId.iStatus )
       
   909             {
       
   910             case RSat::EAlphaIdNotPresent:
       
   911                 {
       
   912                 iQueryData.iAlphaIdStatus = ESatAlphaIdNotProvided;
       
   913                 commandDuration = KSatLongDuration;
       
   914                 break;
       
   915                 }
       
   916 
       
   917             case RSat::EAlphaIdProvided:
       
   918                 {
       
   919                 iQueryData.iAlphaIdStatus = ESatAlphaIdNotNull;
       
   920                 commandDuration = KSatLongDuration;
       
   921                 break;
       
   922                 }
       
   923 
       
   924             default:
       
   925                 {
       
   926                 iQueryData.iAlphaIdStatus = ESatAlphaIdNull;
       
   927                 commandDuration = KSatDurationNotSet;
       
   928                 break;
       
   929                 }
       
   930             }
       
   931 
       
   932         // Send notification to Mediator client if Cover UI is supported
       
   933         if ( iUtils->CoverUiSupported() )
       
   934             {
       
   935             LOG( SIMPLE, "OPENCHANNEL: COpenChannelHandler::SendConfirmToUi \
       
   936                  CoverUiSupported" )
       
   937             TSatCommandData medEventData;
       
   938             medEventData.iPCmdNumber = iPCmd;
       
   939             medEventData.iAlphaId = iOpenChannelData.iAlphaId;
       
   940             medEventData.iDuration.iTimeUnit = RSat::ESeconds;
       
   941             medEventData.iDuration.iNumOfUnits = commandDuration;
       
   942             medEventData.iIconID = iOpenChannelData.iIconId;
       
   943             TSatCommandPckg tPckg( medEventData );
       
   944             iUtils->RaiseSatEvent( tPckg );
       
   945             }
       
   946         // Send notification to UI
       
   947         MSatUiSession* session = iUtils->SatUiHandler().UiSession();
       
   948         session->SendCommand(
       
   949             &iQueryPckg, &iQueryRspPckg, ESatSProactiveQuery );
       
   950         }
       
   951 
       
   952     LOG( SIMPLE, "OPENCHANNEL: COpenChannelHandler::SendConfirmToUi exiting" )
       
   953     }
       
   954 
       
   955 // -----------------------------------------------------------------------------
       
   956 // Closes the channel in error cases.
       
   957 // -----------------------------------------------------------------------------
       
   958 //
       
   959 void COpenChannelHandler::CloseChannel()
       
   960     {
       
   961     LOG( SIMPLE, "OPENCHANNEL: COpenChannelHandler::CloseChannel calling" )
       
   962 
       
   963     // If data channel is not null, close it
       
   964     if ( iDataChannel )
       
   965         {
       
   966         LOG( SIMPLE, "OPENCHANNEL: COpenChannelHandler::CloseChannel have\
       
   967              channel" )
       
   968         iUtils->BipUtils().CloseChannel( iDataChannel->ChannelId() );
       
   969         }
       
   970 
       
   971     if ( iConnectionInfo.iCreatedApnId > 0 )
       
   972         {
       
   973         LOG( SIMPLE, "OPENCHANNEL: COpenChannelHandler::CloseChannel delete\
       
   974              APN" )
       
   975         // APN created -> Remove it
       
   976         TRAP_IGNORE( iUtils->BipUtils().ApnHandler().DeleteApnL(
       
   977             iConnectionInfo.iCreatedApnId ) )
       
   978         }
       
   979 
       
   980     LOG( SIMPLE, "OPENCHANNEL: COpenChannelHandler::CloseChannel exiting" )
       
   981     }
       
   982 
       
   983 // -----------------------------------------------------------------------------
       
   984 // Checks parameters from SIM and makes modifications, if needed.
       
   985 // -----------------------------------------------------------------------------
       
   986 //
       
   987 TBool COpenChannelHandler::CheckParameters()
       
   988     {
       
   989     LOG( SIMPLE, "OPENCHANNEL: COpenChannelHandler::CheckParameters calling" )
       
   990     // Return variable. Indicates is the context activation possible with
       
   991     // given / modified parameters.
       
   992     TBool paramsOk( EFalse );
       
   993 
       
   994     // Check buffer size
       
   995     if ( KSatBIPMaxBufferSize < iOpenChannelData.iBufferSize ||
       
   996          0 == iOpenChannelData.iBufferSize )
       
   997         {
       
   998         LOG( NORMAL, "OPENCHANNEL: COpenChannelHandler::CheckParameters \
       
   999             Changing buffersize" )
       
  1000         // Too big requested buffer size -> set to max
       
  1001         iConnectionInfo.iBufferSize = KSatBIPMaxBufferSize;
       
  1002         // put modified buffer size to terminal response
       
  1003         iOpenChannelRsp.iBufferSize = KSatBIPMaxBufferSize;
       
  1004         // Modified parameters
       
  1005         iSetUpWithModifications = ETrue;
       
  1006         }
       
  1007     else
       
  1008         {
       
  1009         iConnectionInfo.iBufferSize = iOpenChannelData.iBufferSize;
       
  1010         iOpenChannelRsp.iBufferSize = iOpenChannelData.iBufferSize;
       
  1011         }
       
  1012 
       
  1013     // Set bearer for the terminal response. This information is mandatory to
       
  1014     // each terminal response.
       
  1015     iOpenChannelRsp.iBearer = iOpenChannelData.iBearer;
       
  1016 
       
  1017     // Indicates is there destination address defined
       
  1018     const TBool destinationAddressNotDefined
       
  1019         (
       
  1020         RSat::EIPv4Address != iOpenChannelData.iDestinationAddress.iType &&
       
  1021         RSat::EIPv6Address != iOpenChannelData.iDestinationAddress.iType
       
  1022         );
       
  1023 
       
  1024     // Indicates is there a transport protocol defined
       
  1025     const TBool transportProtoNotDefined
       
  1026         (
       
  1027         RSat::ETcp != iOpenChannelData.iSimMeInterface.iTransportProto &&
       
  1028         RSat::EUdp != iOpenChannelData.iSimMeInterface.iTransportProto
       
  1029         );
       
  1030 
       
  1031     // Indicates is there a transport port number defined
       
  1032     const TBool transportPortNumberNotDefined
       
  1033         (
       
  1034         0 == iOpenChannelData.iSimMeInterface.iPrtNumber
       
  1035         );
       
  1036 
       
  1037     // Indicates is selected bearer supported
       
  1038     const TBool bearerNotSupported
       
  1039         (
       
  1040         RSat::EPCmdTypeNotSet != iOpenChannelData.iPCmdType &&
       
  1041         RSat::EGprsBearer != iOpenChannelData.iPCmdType &&
       
  1042         RSat::EAnyBearer != iOpenChannelData.iPCmdType
       
  1043         );
       
  1044 
       
  1045     // Check parameters
       
  1046     paramsOk = !( destinationAddressNotDefined ||
       
  1047                   transportProtoNotDefined ||
       
  1048                   bearerNotSupported ||
       
  1049                   transportPortNumberNotDefined );
       
  1050 
       
  1051     // Check is connection possible
       
  1052     if ( paramsOk )
       
  1053         {
       
  1054         LOG( NORMAL, "OPENCHANNEL: COpenChannelHandler::CheckParameters \
       
  1055         Bearer type is GPRS" )
       
  1056         // Bearer type is GPRS
       
  1057         iBearerType = MSatBIPUtils::ESatGPRS;
       
  1058         // Set bearer type for the terminal response in case it was not defined
       
  1059         iOpenChannelRsp.iBearer.iType = RSat::EGPRSBearer;
       
  1060         // Destination address
       
  1061         iConnectionInfo.iDestination = iOpenChannelData.iDestinationAddress;
       
  1062         // Local address
       
  1063         iConnectionInfo.iSource = iOpenChannelData.iLocalAddress;
       
  1064         // Bearer parameters
       
  1065         iConnectionInfo.iBearerParams = iOpenChannelData.iBearer.iParams;
       
  1066         // Set protocol info to connection data
       
  1067         iConnectionInfo.iProtocol = iOpenChannelData.iSimMeInterface;
       
  1068         }
       
  1069     else if ( transportProtoNotDefined ||
       
  1070               bearerNotSupported ||
       
  1071               transportPortNumberNotDefined )
       
  1072         {
       
  1073         // Fail
       
  1074         LOG( NORMAL, "OPENCHANNEL: COpenChannelHandler::CheckParameters \
       
  1075         Unable to connect" )
       
  1076         // If parameters are not OK, send terminal response
       
  1077         LOG( NORMAL, "OPENCHANNEL: COpenChannelHandler::CommandAllowed \
       
  1078             Not valid parameters" )
       
  1079         iOpenChannelRsp.iGeneralResult = RSat::KCmdBeyondMeCapabilities;
       
  1080         iOpenChannelRsp.iInfoType = RSat::KNoAdditionalInfo;
       
  1081         iOpenChannelRsp.iAdditionalInfo.Zero();
       
  1082         }
       
  1083     else if ( destinationAddressNotDefined )
       
  1084         {
       
  1085         // Fail
       
  1086         LOG( NORMAL, "OPENCHANNEL: COpenChannelHandler::CheckParameters \
       
  1087         Destination not set" )
       
  1088         iOpenChannelRsp.iGeneralResult = RSat::KErrorRequiredValuesMissing;
       
  1089         iOpenChannelRsp.iInfoType = RSat::KNoAdditionalInfo;
       
  1090         iOpenChannelRsp.iAdditionalInfo.Zero();
       
  1091         }
       
  1092     else
       
  1093         {
       
  1094         // Fail
       
  1095         LOG( NORMAL, "OPENCHANNEL: COpenChannelHandler::CheckParameters \
       
  1096         Unable to connect" )
       
  1097         // If parameters are not OK, send terminal response
       
  1098         LOG( NORMAL, "OPENCHANNEL: COpenChannelHandler::CheckParameters \
       
  1099             Not valid parameters" )
       
  1100         iOpenChannelRsp.iGeneralResult = RSat::KCmdBeyondMeCapabilities;
       
  1101         iOpenChannelRsp.iInfoType = RSat::KNoAdditionalInfo;
       
  1102         iOpenChannelRsp.iAdditionalInfo.Zero();
       
  1103         }
       
  1104 
       
  1105     LOG2( SIMPLE, "OPENCHANNEL: COpenChannelHandler::CheckParameters exiting,\
       
  1106           paramsOk: %d", paramsOk )
       
  1107     return paramsOk;
       
  1108     }
       
  1109 
       
  1110 // -----------------------------------------------------------------------------
       
  1111 // Launches UI if it not active.
       
  1112 // -----------------------------------------------------------------------------
       
  1113 //
       
  1114 TBool COpenChannelHandler::LaunchUiSession()
       
  1115     {
       
  1116     LOG( SIMPLE, "OPENCHANNEL: COpenChannelHandler::LaunchUiSession calling" )
       
  1117     TBool retVal( EFalse );
       
  1118 
       
  1119     // If ui session is not availabe, SATUI has to be
       
  1120     // launched.
       
  1121     if ( NULL == iUtils->SatUiHandler().UiSession() )
       
  1122         {
       
  1123         TRAPD( err,
       
  1124                iUtils->RegisterL( this, MSatUtils::ESatUiLaunched );
       
  1125                // Try to launch the ui client.
       
  1126                iUtils->SatUiHandler().LaunchSatUiL();
       
  1127              ); // End of TRAPD
       
  1128 
       
  1129         if ( KErrNone != err )
       
  1130             {
       
  1131             LOG( SIMPLE, "OPENCHANNEL: COpenChannelHandler::LaunchUiSession \
       
  1132                  Ui launch failed" )
       
  1133             // Ui launch failed, unregister event
       
  1134             iUtils->UnregisterEvent( this, MSatUtils::ESatUiLaunched );
       
  1135             // Notify SIM that ui launch failed.
       
  1136             UiLaunchFailed();
       
  1137             }
       
  1138         else
       
  1139             {
       
  1140             LOG( SIMPLE, "OPENCHANNEL: COpenChannelHandler::LaunchUiSession \
       
  1141                  Ui launch successfully" )
       
  1142             // Return true indicating that we had to launch UI
       
  1143             retVal = ETrue;
       
  1144             }
       
  1145         }
       
  1146 
       
  1147     LOG2( SIMPLE, "OPENCHANNEL: COpenChannelHandler::LaunchUiSession exiting,\
       
  1148           retVal: %d", retVal )
       
  1149     return retVal;
       
  1150     }