multimediacommsengine/mmcesrv/mmceserver/src/mcenatstateconnected.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "mcenatstateconnected.h"
       
    21 #include "mcenatsipsession.h"
       
    22 #include "mceactionset.h"
       
    23 #include "mceclientserver.h"
       
    24 #include "mcenatevents.h"
       
    25 #include "mcenatactions.h"
       
    26 #include "mcesrvlogs.h"
       
    27 
       
    28 // -----------------------------------------------------------------------------
       
    29 // CMceNatStateConnected::CMceNatStateConnected
       
    30 // -----------------------------------------------------------------------------
       
    31 //
       
    32 CMceNatStateConnected::CMceNatStateConnected()
       
    33 	{
       
    34 	}
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 // CMceNatStateConnected::~CMceNatStateConnected
       
    38 // -----------------------------------------------------------------------------
       
    39 //
       
    40 CMceNatStateConnected::~CMceNatStateConnected()
       
    41 	{
       
    42 	}
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // CMceNatStateConnected::Accept
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 
       
    49 TBool CMceNatStateConnected::Accept( TMceNatStateTransitionEvent& aEvent )
       
    50     {
       
    51     switch ( aEvent.NatCode() )
       
    52         {
       
    53         case EMceNatUpdated:
       
    54             {
       
    55             return aEvent.Session().DoesMediaManagerNeedToNegotiate( NULL );
       
    56             }
       
    57         case EMceNatHandleSIP:
       
    58             {
       
    59             return ( EMceInvite == aEvent.Code() || 
       
    60                      EMcePrack == aEvent.Code()  ||
       
    61             	  	 ( EMceAck == aEvent.Code() &&
       
    62             	  	   MceSip::HasContent( aEvent.Session().Request() ) ) );
       
    63            	}
       
    64            	
       
    65         case EMceNatUpdateSdp:
       
    66         case EMceNatError:
       
    67         case EMceNatICMPError: 
       
    68             {
       
    69             return ETrue;
       
    70             }
       
    71         default:
       
    72             {
       
    73             return EFalse;
       
    74             }
       
    75         }
       
    76     }    
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // CMceNatStateConnected::EntryL
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 void CMceNatStateConnected::EntryL( TMceNatStateTransitionEvent& aEvent )
       
    83 	{
       
    84 	MCESRV_DEBUG( "*** CMceNatStateConnected::EntryL, Entry" );
       
    85 	
       
    86 	if ( EMceNatSync == aEvent.NatCode() ||
       
    87 	     EMceNatOffer == aEvent.NatCode() )
       
    88 	    {
       
    89 	    // NOP
       
    90 	    }
       
    91     else
       
    92         {
       
    93 	    aEvent.NatActions().Continue();
       
    94 	    }
       
    95     
       
    96     MCESRV_DEBUG( "*** CMceNatStateConnected::EntryL, Exit" );
       
    97 	}
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 // CMceNatStateConnected::ExitL
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 void CMceNatStateConnected::ExitL( TMceNatStateTransitionEvent& aEvent )
       
   104 	{
       
   105 	MCESRV_DEBUG( "*** CMceNatStateConnected::ExitL, Entry" );
       
   106 	
       
   107 	switch ( aEvent.NatCode() )
       
   108 	    {
       
   109 	    case EMceNatError:
       
   110 	    case EMceNatICMPError:
       
   111 	        {
       
   112 	        ExitErrorL( aEvent );
       
   113 	        break;
       
   114 	        }
       
   115 	    case EMceNatUpdateSdp:
       
   116 	        {
       
   117 	        ExitUpdateSdpL( aEvent );
       
   118 	        break;
       
   119 	        }
       
   120 
       
   121 	  	case EMceNatHandleSIP:
       
   122 	        {
       
   123 	        if ( EMceInvite == aEvent.Code() )
       
   124 	        	{
       
   125 		        ExitHandleInviteL( aEvent );
       
   126 	        	}
       
   127 			else
       
   128 				{
       
   129 	        	ExitDefaultL( aEvent );
       
   130 				}	        	
       
   131 	        break;
       
   132 	        }
       
   133 	    	
       
   134 	    default:
       
   135 	        {
       
   136 	        ExitDefaultL( aEvent );
       
   137 	        break;
       
   138 	        }
       
   139 	    }
       
   140     
       
   141 	MCESRV_DEBUG( "*** CMceNatStateConnected::ExitL, Exit" );
       
   142 	}
       
   143 
       
   144 // -----------------------------------------------------------------------------
       
   145 // CMceNatStateConnected::ExitErrorL
       
   146 // -----------------------------------------------------------------------------
       
   147 //
       
   148 void CMceNatStateConnected::ExitErrorL( TMceNatStateTransitionEvent& aEvent )
       
   149     {
       
   150     TMceStateIndex sipState = aEvent.Session().CurrentState().Id();
       
   151     
       
   152     if (( aEvent.NatCode() == EMceNatICMPError && 
       
   153     		KMceStateEstablished == sipState ) || 
       
   154     		aEvent.NatCode() == EMceNatError )
       
   155     
       
   156     	{
       
   157     	aEvent.Session().Actions().ClientErrorOccured( aEvent.ParamStatus() );
       
   158     	User::Leave( aEvent.ParamStatus() );		
       
   159     	}
       
   160       
       
   161     }
       
   162 
       
   163 // -----------------------------------------------------------------------------
       
   164 // CMceNatStateConnected::ExitUpdateSdpL
       
   165 // -----------------------------------------------------------------------------
       
   166 //
       
   167 void CMceNatStateConnected::ExitUpdateSdpL( 
       
   168     TMceNatStateTransitionEvent& /*aEvent*/ )
       
   169     {
       
   170     // NAT has resulted in different transport address than initial O/A 
       
   171     // exchange suggested, hence re-INVITE must be sent.
       
   172     
       
   173     //CMceSipSession& session = aEvent.Session();
       
   174     //CSdpDocument* previous = session.Offer();
       
   175     //aEvent.Session().SetOffer( aEvent.Document() );
       
   176     //aEvent.NatActions().SetOffered( KMceNatOfferSdp );
       
   177     //aEvent.NatActions().SdpCleanup( previous, session.Offer() );
       
   178     //aEvent.Session().Actions().SendInviteL();
       
   179     }
       
   180 
       
   181 // -----------------------------------------------------------------------------
       
   182 // CMceNatStateConnected::ExitHandleInviteL
       
   183 // -----------------------------------------------------------------------------
       
   184 //
       
   185 void CMceNatStateConnected::ExitHandleInviteL( 
       
   186     TMceNatStateTransitionEvent& aEvent )
       
   187     {
       
   188     if ( !MceSip::HasContent( aEvent.Session().Request() ) )
       
   189         {
       
   190         // TBD: Restart of ICE
       
   191         }
       
   192     
       
   193     // Not consumed, done by SIP state machine
       
   194     aEvent.NatActions().Continue();        
       
   195     }
       
   196 
       
   197 // -----------------------------------------------------------------------------
       
   198 // CMceNatStateConnected::ExitDefaultL
       
   199 // -----------------------------------------------------------------------------
       
   200 //
       
   201 void CMceNatStateConnected::ExitDefaultL( TMceNatStateTransitionEvent& aEvent )
       
   202     {
       
   203   	
       
   204   	TMceStateIndex sipState = aEvent.Session().CurrentState().Id();
       
   205   
       
   206     if ( KMceStateServerEstablishing == sipState || 
       
   207         KMceStateUpdating == sipState || 
       
   208        	( aEvent.NatCode() == EMceNatUpdated && 
       
   209        	KMceStateAcknowledgementRequired == sipState )) //i.e. DecodeL
       
   210     	{
       
   211     	// MT state loop
       
   212     	//Check if the invite package received includes corresponding SDP;
       
   213     	if ( !MceSip::HasContent( aEvent.Session().Request() ) )
       
   214     		{
       
   215     		//no SDP, so certify to Pull mode Re-INVITE 
       
   216     		aEvent.NatActions().StateChangedL( aEvent, KMceNatStateCreateOffer );
       
   217     		}
       
   218     	else
       
   219     		{
       
   220     		//including SDP, so certify to normal INVITE request
       
   221     		aEvent.NatActions().StateChangedL( aEvent, KMceNatStateCreateAnswer  );
       
   222     		}
       
   223     	}
       
   224     
       
   225     else if ( aEvent.NatCode() == EMceNatUpdated && 
       
   226 		 	  ( KMceStateEstablished == sipState ||
       
   227      	  	    KMceStateConfirming == sipState ||
       
   228     	  	    KMceStateClientEstablishing == sipState ) ||
       
   229     	  	 ( aEvent.ParamStatus() == KMceReady ) &&
       
   230     	  	 ( aEvent.Code() == EMceProvisionalResponse ) )
       
   231           
       
   232 		//i.e. UpdateL	
       
   233 		{
       
   234         // MO state loop
       
   235         aEvent.NatActions().StateChangedL( aEvent, KMceNatStateCreateOffer );
       
   236 		}
       
   237 
       
   238 	else
       
   239 		{
       
   240 		aEvent.NatActions().Continue();        	
       
   241 		}		
       
   242     }
       
   243 
       
   244 // End of File