multimediacommsengine/mmcesrv/mmcemediamanager/src/mcesecuremediasession.cpp
changeset 0 1bce908db942
child 3 513a8b745b2f
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:    Provides services for SDP Security Descriptions.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 
       
    23 #include <e32base.h>
       
    24 #include <e32std.h>
       
    25 
       
    26 #include <sdporiginfield.h>
       
    27 #include <sdpconnectionfield.h>
       
    28 #include <sdpmediafield.h>
       
    29 #include <sdpattributefield.h>
       
    30 #include <sdpcodecstringpool.h>
       
    31 #include <sdpdocument.h>
       
    32 #include "mcesrvstream.h"
       
    33 #include "mcecomcodec.h"
       
    34 #include "mcemmlogs.h"
       
    35 #include "mcesecuremediasession.h"
       
    36 #include "mcesecuredesstream.h"
       
    37 #include "mceclientserver.h"
       
    38 
       
    39 
       
    40 // ================= MEMBER FUNCTIONS ==========================================
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // CMceSecureMediaSession::CMceSecureMediaSession
       
    44 // -----------------------------------------------------------------------------
       
    45 CMceSecureMediaSession::CMceSecureMediaSession( CMceComSession& aSession,
       
    46                                      CMceMediaManager& aManager,
       
    47                                      CMccSecureInterface& aSecureInterface)
       
    48     :       iManager( aManager ),
       
    49             iSession( aSession ),
       
    50             iSecureInterface(aSecureInterface),
       
    51             iKeyNeedUpdated( ETrue ),
       
    52             iCryptoContextUpdate (EFalse),
       
    53             iLSReadyToBind ( ETrue ),
       
    54             iStringTable( NULL )
       
    55     {
       
    56     
       
    57     }
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // CMceSecureMediaSession::ConstructL
       
    61 // -----------------------------------------------------------------------------
       
    62 void CMceSecureMediaSession::ConstructL()
       
    63     {
       
    64     }
       
    65 
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 // CMceSecureMediaSession::NewL
       
    69 // -----------------------------------------------------------------------------
       
    70  CMceSecureMediaSession* CMceSecureMediaSession::NewL( CMceComSession& aSession,
       
    71                                      CMceMediaManager& aManager,
       
    72                                      CMccSecureInterface& aSecureInterface )
       
    73     {
       
    74     CMceSecureMediaSession* self = NewLC( aSession, aManager, aSecureInterface );
       
    75     CleanupStack::Pop( self ); 
       
    76     return self;
       
    77     }
       
    78 
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CMceSecureMediaSession::NewLC
       
    82 // -----------------------------------------------------------------------------
       
    83  CMceSecureMediaSession* CMceSecureMediaSession::NewLC( CMceComSession& aSession,
       
    84                                        CMceMediaManager& aManager,
       
    85                                        CMccSecureInterface& aSecureInterface )
       
    86     {
       
    87     CMceSecureMediaSession* self = new ( ELeave ) CMceSecureMediaSession( aSession, 
       
    88     																	aManager,
       
    89     																	aSecureInterface );
       
    90     CleanupStack::PushL( self );
       
    91     self->ConstructL();
       
    92     return self;
       
    93     }
       
    94 
       
    95 
       
    96 // -----------------------------------------------------------------------------
       
    97 // CMceSecureMediaSession::~CMceSecureMediaSession
       
    98 // -----------------------------------------------------------------------------    
       
    99  CMceSecureMediaSession::~CMceSecureMediaSession()
       
   100     {
       
   101     //Remove secure streams
       
   102     iMceSecureDesStreams.ResetAndDestroy();
       
   103 	}
       
   104 
       
   105 
       
   106 // -----------------------------------------------------------------------------
       
   107 // CMceSecureMediaSession::
       
   108 // -----------------------------------------------------------------------------
       
   109 //
       
   110 void CMceSecureMediaSession::EncodeSecureDesSdpOfferL(
       
   111 										CMceComMediaStream& aStream,		
       
   112 										CSdpMediaField& aMediaLine)
       
   113     {
       
   114     
       
   115     MCEMM_DEBUG("CMceSecureMediaSession::(), Entry ");
       
   116     User::LeaveIfNull( &aMediaLine );
       
   117     
       
   118     // find media lines and create sec stream and add security attribute
       
   119     CMceSecureDesStream* secStream=NULL;   
       
   120 	
       
   121 	if ( iMceSecureDesStreams.Count()!=0 )
       
   122 		{
       
   123 		//find sec stream
       
   124 	    TInt secStreamCount = iMceSecureDesStreams.Count();
       
   125 	    for (TInt j=0; j<secStreamCount; j++)
       
   126 	    	{
       
   127 	    	CMceSecureDesStream* secDesStream = iMceSecureDesStreams[j];
       
   128 	    	if (IfStreamMatchMedia(aStream, *secDesStream, aMediaLine) )
       
   129 	    		{
       
   130 	    		//out of loop
       
   131 	    		j=secStreamCount;
       
   132 	    		secStream = secDesStream;
       
   133 	    		//remove or clean secure sdp params if any 
       
   134 	    		secStream->RemvoeSecureSdp(aMediaLine);
       
   135 	    		}
       
   136 	    	}
       
   137 		}
       
   138 	if (!secStream)
       
   139 		{
       
   140 	    //create sec stream depends on how many media lines
       
   141 		/*RFC 4568 7.1.1
       
   142 		The inline parameter conveys the SRTP master key used by an endpoint
       
   143 		to encrypt the SRTP and SRTCP streams transmitted by that endpoint.
       
   144 		The same key is used by the recipient to decrypt those streams.
       
   145 		*/
       
   146 		secStream = CMceSecureDesStream::NewL(
       
   147 								*this,
       
   148 								aMediaLine,
       
   149 								iSecureInterface,
       
   150 								aStream);
       
   151 		CleanupStack::PushL(secStream);						
       
   152         iMceSecureDesStreams.AppendL(secStream);
       
   153 		CleanupStack::Pop(secStream);
       
   154 		}
       
   155 	//Encode sdp
       
   156 	if (secStream)
       
   157 		{
       
   158 		secStream->EncodeSecureSdpL(aMediaLine, EFalse);
       
   159 		}
       
   160 	
       
   161     MCEMM_DEBUG("CMceSecureMediaSession::(), Exit ");
       
   162     
       
   163     }
       
   164 
       
   165 // -----------------------------------------------------------------------------
       
   166 // CMceSecureMediaSession::DecodeSecureDesSdpAnswerL
       
   167 // -----------------------------------------------------------------------------
       
   168 //
       
   169 void CMceSecureMediaSession::DecodeSecureDesSdpAnswerL( CMceComMediaStream& aStream,
       
   170                                                         CSdpMediaField& aMediaLine)
       
   171     {
       
   172     MCEMM_DEBUG("CMceSecureMediaSession::DecodeSecureDesSdpAnswerL(), Entry ");
       
   173     // decode media lines for answer
       
   174     
       
   175     User::LeaveIfNull( &aMediaLine );
       
   176    
       
   177     if ( IsSecureSdpMsgL( aMediaLine ) )
       
   178     	{
       
   179        	TBool foundCryptoIn=EFalse;	
       
   180 	   
       
   181 	    CMceSecureDesStream* secStream=NULL;   
       
   182 		//one uplink stream for this codec must be set already
       
   183 		TInt secStreamCount = iMceSecureDesStreams.Count();
       
   184 		for (TInt i=0; i<secStreamCount; i++)
       
   185 	    	{
       
   186 	    	CMceSecureDesStream* secDesStream = iMceSecureDesStreams[i];
       
   187 	    	if (IfStreamMatchMedia(aStream, *secDesStream, aMediaLine))
       
   188 	    		{
       
   189 	    		i=secStreamCount;
       
   190 	    		secStream = secDesStream;
       
   191 	    		foundCryptoIn=ETrue;
       
   192 	    		}
       
   193 	    	}
       
   194 	    	//create sec stream depends on how many media lines
       
   195 		if (!foundCryptoIn && (aStream.iLocalMediaPort == aMediaLine.Port()||
       
   196 				aStream.iRemoteMediaPort ==aMediaLine.Port()) )
       
   197 			{
       
   198 			secStream = CMceSecureDesStream::NewL(*this,
       
   199 										aMediaLine,
       
   200 									iSecureInterface,
       
   201 									aStream);
       
   202 							
       
   203 			iMceSecureDesStreams.Append(secStream);						
       
   204 			}
       
   205 
       
   206 		//Decode sdp
       
   207 		if (secStream)
       
   208 			{
       
   209             TRAPD( err, secStream->DecodeSecureSdpAnswerL( aMediaLine ) );
       
   210             if ( err )
       
   211                 {
       
   212                 TInt index = iMceSecureDesStreams.Find( secStream );
       
   213                 if ( KErrNotFound != index )
       
   214                     {
       
   215                     iMceSecureDesStreams.Remove( index );
       
   216                     }
       
   217                 delete secStream;
       
   218                 secStream = NULL;
       
   219                 User::Leave( err );
       
   220                 }
       
   221             }
       
   222     	}
       
   223     else
       
   224     	{
       
   225     	RemoveSecureCrypto( );
       
   226     	//Expected secure sdp answer but not found. leave to end the sesssion
       
   227     	User::Leave( KErrArgument );
       
   228     	}
       
   229 
       
   230     MCEMM_DEBUG("CMceSecureMediaSession::DecodeSecureDesSdpAnswerL(), Exit ");
       
   231     
       
   232     }
       
   233 
       
   234 // -----------------------------------------------------------------------------
       
   235 // CMceSecureMediaSession::DecodeSecureDesSdpOfferL
       
   236 // -----------------------------------------------------------------------------
       
   237 
       
   238 void CMceSecureMediaSession::DecodeSecureDesSdpOfferL( CMceComMediaStream& aStream,
       
   239 														CSdpMediaField& aMediaLine)
       
   240     {
       
   241     MCEMM_DEBUG("CMceSecureMediaSession::DecodeSecureDesSdpOfferL(), Entry ");
       
   242     
       
   243     User::LeaveIfNull( &aMediaLine );
       
   244    	
       
   245    	TBool foundCryptoIn = EFalse;	
       
   246    	
       
   247     if ( IsSecureSdpMsgL( aMediaLine ) )
       
   248     	{
       
   249 	    CMceSecureDesStream* secStream=NULL;                            
       
   250 		/*RFC 4568 7.1.1
       
   251 		The inline parameter conveys the SRTP master key used by an endpoint
       
   252 		to encrypt the SRTP and SRTCP streams transmitted by that endpoint.
       
   253 		The same key is used by the recipient to decrypt those streams.
       
   254 		*/
       
   255 		TInt secStreamCount = iMceSecureDesStreams.Count();
       
   256 		for (TInt i=0; i<secStreamCount; i++)
       
   257 			{
       
   258 			
       
   259 	    	CMceSecureDesStream* secDesStream = iMceSecureDesStreams[i];
       
   260 	    	if (IfStreamMatchMedia(aStream, *secDesStream, aMediaLine))
       
   261 	    		{
       
   262 	    		i=secStreamCount;
       
   263 	    		secStream = secDesStream;
       
   264 	    		foundCryptoIn=ETrue;
       
   265 	    		}
       
   266 	    			
       
   267 			}
       
   268 	    
       
   269 	    	//create sec stream depends on how many media lines
       
   270 		if (!foundCryptoIn)
       
   271 			{
       
   272 			secStream = CMceSecureDesStream::NewL( *this,
       
   273 													aMediaLine,
       
   274 													iSecureInterface,
       
   275 													aStream);
       
   276 									
       
   277 			iMceSecureDesStreams.Append( secStream );						
       
   278 			}
       
   279 		
       
   280 			//Decode sdp
       
   281 		if (secStream)
       
   282 			{
       
   283             TRAPD( err, secStream->DecodeSecureSdpL( aMediaLine ) );
       
   284             if ( err )
       
   285                 {
       
   286                 TInt index = iMceSecureDesStreams.Find( secStream );
       
   287                 if ( KErrNotFound != index )
       
   288                     {
       
   289                     iMceSecureDesStreams.Remove( index );
       
   290                     }
       
   291                 delete secStream;
       
   292                 secStream = NULL;
       
   293                 User::Leave( err );
       
   294                 }
       
   295             }
       
   296         }
       
   297     else
       
   298     	{
       
   299     	RemoveSecureCrypto( );
       
   300     	}
       
   301 	
       
   302     MCEMM_DEBUG("CMceSecureMediaSession::DecodeSecureDesSdpOfferL(), Exit " );
       
   303     }      
       
   304 
       
   305 // -----------------------------------------------------------------------------
       
   306 // CMceSecureMediaSession::DecodeSecureDesSdpOfferL
       
   307 // -----------------------------------------------------------------------------
       
   308 
       
   309 void CMceSecureMediaSession::DecodeSecureDesSdpUpdateL( CMceComMediaStream& aStream,
       
   310 														CSdpMediaField& aMediaLine)
       
   311     {
       
   312     MCEMM_DEBUG("CMceSecureMediaSession::DecodeSecureDesSdpOfferL(), Entry ");
       
   313     
       
   314     User::LeaveIfNull( &aMediaLine );
       
   315     if ( IsSecureSdpMsgL( aMediaLine ) )
       
   316    		{
       
   317    		
       
   318 	    // find media lines and create sec stream and add security attribute
       
   319 	   	
       
   320 	    CMceSecureDesStream* secStream=NULL;                            
       
   321 	   
       
   322 		//one uplink stream for this codec must be set already
       
   323 		TInt secStreamCount = iMceSecureDesStreams.Count();
       
   324 		for (TInt i=0; i<secStreamCount; i++ )
       
   325 	    	{
       
   326 	    	secStream = iMceSecureDesStreams[i];
       
   327 	    	if (IfStreamMatchMedia(	aStream, *secStream,aMediaLine))
       
   328 	    		{
       
   329 	    		secStream->DecodeSecureSdpL( aMediaLine );    
       
   330 				
       
   331 				}
       
   332 				    
       
   333 	    	}
       
   334    		}
       
   335    	else
       
   336    		{
       
   337    		RemoveSecureCrypto( );
       
   338    		}
       
   339    	
       
   340     MCEMM_DEBUG("CMceSecureMediaSession::DecodeSecureDesSdpOfferL(), Exit ");
       
   341     }          
       
   342 
       
   343 // -----------------------------------------------------------------------------
       
   344 // CMceSecureMediaSession::EncodeSecureDesSdpAnswerL
       
   345 // -----------------------------------------------------------------------------
       
   346 void CMceSecureMediaSession::EncodeSecureDesSdpAnswerL( CMceComMediaStream& aStream, 
       
   347 														CSdpMediaField& aMediaLine )
       
   348     {
       
   349     MCEMM_DEBUG("CMceSecureMediaSession::EncodeSecureDesSdpAnswerL(), Entry ");
       
   350     User::LeaveIfNull( &aMediaLine);
       
   351     
       
   352    	TBool foundCryptoOut=EFalse;	
       
   353    
       
   354    	// find media lines and create sec stream and add security attribute
       
   355 	CMceSecureDesStream* secStream=NULL;                            
       
   356   
       
   357 	TInt secStreamCount = iMceSecureDesStreams.Count();
       
   358 	for (TInt i=0; i<secStreamCount; i++)
       
   359     	{
       
   360     	CMceSecureDesStream* secDesStream = iMceSecureDesStreams[i];
       
   361     	if (IfStreamMatchMedia(aStream, *secDesStream, aMediaLine))
       
   362     		{
       
   363     		//HARDCode here as refresh first later on should also know when to 
       
   364 			// set as updated mode 	
       
   365 		
       
   366 			i=secStreamCount;
       
   367     		secStream = secDesStream;
       
   368     		//remove or clean secure sdp params if any 
       
   369     		secStream->RemvoeSecureSdp(aMediaLine);
       
   370     	
       
   371     		foundCryptoOut=ETrue;
       
   372     		}
       
   373     	
       
   374     	}
       
   375     	//create sec stream depends on how many media lines
       
   376 	if (!foundCryptoOut)
       
   377 		{
       
   378 		secStream = CMceSecureDesStream::NewL(*this,
       
   379 								aMediaLine,
       
   380 								iSecureInterface,
       
   381 								aStream);
       
   382 		CleanupStack::PushL( secStream);						
       
   383 		iMceSecureDesStreams.AppendL(secStream);
       
   384 		CleanupStack::Pop(secStream);
       
   385 								
       
   386 		}
       
   387 	
       
   388 	//Decode sdp
       
   389 	if (secStream)
       
   390 		{
       
   391 		secStream->EncodeSecureSdpL(aMediaLine, ETrue);    
       
   392 		}
       
   393 
       
   394     MCEMM_DEBUG("CMceSecureMediaSession::EncodeSecureDesSdpAnswerL(), Exit ");
       
   395     }       
       
   396 
       
   397 	
       
   398 // -----------------------------------------------------------------------------
       
   399 // CMceSecureMediaSession:: CleanSecureCryptoInfo()
       
   400 // -----------------------------------------------------------------------------
       
   401 void CMceSecureMediaSession:: CleanSecureCryptoInfoL(CSdpMediaField& aMediaLine)
       
   402     {
       
   403     MCEMM_DEBUG("CMceSecureMediaSession::CleanSecureCryptoInfoL(), Entry ");
       
   404     User::LeaveIfNull( &aMediaLine );
       
   405     
       
   406     // find media lines and create sec stream and add security attribute
       
   407     CMceSecureDesStream* secStream=NULL; 
       
   408     
       
   409     //find sec stream
       
   410     TInt secStreamCount = iMceSecureDesStreams.Count();
       
   411     for (TInt j=0; j<secStreamCount; j++)
       
   412     	{
       
   413     	CMceSecureDesStream* secDesStream = iMceSecureDesStreams[j];
       
   414     	if (IfStreamMatchMedia(secDesStream->MediaStream(), *secDesStream, aMediaLine))
       
   415     		{
       
   416     		//out of loop
       
   417     		j=secStreamCount;
       
   418     		secStream = secDesStream;
       
   419     		secStream->RemvoeSecureSdp(aMediaLine );
       
   420     		}
       
   421     	}
       
   422 			    
       
   423 	User::LeaveIfError( aMediaLine.IsValid() );
       
   424     MCEMM_DEBUG("CMceSecureMediaSession::CleanSecureCryptoInfoL(), Exit ");
       
   425    
       
   426     }
       
   427 
       
   428 // -----------------------------------------------------------------------------
       
   429 // CMceSecureMediaSession::Bind()
       
   430 // -----------------------------------------------------------------------------
       
   431 TInt CMceSecureMediaSession::BindStreamCrypto( )
       
   432     					
       
   433 	{
       
   434 	MCEMM_DEBUG("CMceSecureDesStream::BindStreamCrypto(), Entry");
       
   435 	TInt err(KErrNone);
       
   436 	if (iSession.iClientCryptoSuites.Count())
       
   437 		{
       
   438 		for (TInt i=0; i<iSession.MccStreams().Count(); i++)
       
   439 			{
       
   440 			CMceSrvStream* stream = iSession.MccStreams()[i];
       
   441 			MCEMM_DEBUG_DVALUE("	CMceSrvStream id =", stream->Data().Id().iId );	
       
   442 			MCEMM_DEBUG_DVALUE("	App id", stream->Data().Id().iAppId );		
       
   443 			TInt secStreamCount = iMceSecureDesStreams.Count();
       
   444     		for (TInt j=0; j<secStreamCount; j++)
       
   445 				{
       
   446 				CMceSecureDesStream* secureStream=iMceSecureDesStreams[j]; 
       
   447 				MCEMM_DEBUG_DVALUE("	SrvStream id in SecureStream ", secureStream->MediaStream().Id().iId);	
       
   448 				MCEMM_DEBUG_DVALUE("	App id in SecureStream ", secureStream->MediaStream().Id().iAppId);	
       
   449 				if (stream->Data().Id()== secureStream->MediaStream().Id() || 
       
   450 					 ( stream->Data().BoundStream() && 
       
   451 					   stream->Data().iLinkedStream->Id() == secureStream->MediaStream().Id() ) ) 
       
   452 					{
       
   453 					//bind
       
   454 					secureStream->BindCrypto(*stream);
       
   455 					
       
   456 					}
       
   457 				}
       
   458 			}
       
   459 		}
       
   460 	MCEMM_DEBUG("CMceSecureDesStream::BindStreamCrypto(), Exit");
       
   461     return err;									
       
   462 	}
       
   463 
       
   464 
       
   465 // -----------------------------------------------------------------------------
       
   466 // CMceSecureMediaSession::ContextNeedUpdated
       
   467 // -----------------------------------------------------------------------------
       
   468 
       
   469 void CMceSecureMediaSession::ContextNeedUpdated( TUint32 aContextId )
       
   470     {
       
   471    	TInt secStreamCount = iMceSecureDesStreams.Count();
       
   472     for (TInt j=0; j<secStreamCount; j++)
       
   473     	{
       
   474     	CMceSecureDesStream* secDesStream = iMceSecureDesStreams[j];
       
   475     	if (secDesStream->CompareContextId(aContextId))
       
   476     		{
       
   477     		secDesStream->iCryptoUpdateNeeded = ETrue;
       
   478     		}
       
   479     	}
       
   480     }  
       
   481 
       
   482 // -----------------------------------------------------------------------------
       
   483 // CMceSecureMediaSession::IfStreamMatchMedia
       
   484 // -----------------------------------------------------------------------------
       
   485 
       
   486 TBool CMceSecureMediaSession::IfStreamMatchMedia(	CMceComMediaStream& aMediaStream,
       
   487 													CMceSecureDesStream& aStream,
       
   488 													CSdpMediaField& aMediaLine)
       
   489 	{
       
   490 	TBool match=EFalse;
       
   491 	if (aStream.MediaField().Media()== aMediaLine.Media()  && 
       
   492 		aStream.MediaStream().iLocalMediaPort==aMediaStream.iLocalMediaPort &&
       
   493 		aStream.MediaStream().iRemoteMediaPort==aMediaStream.iRemoteMediaPort )
       
   494 		{
       
   495 		match =ETrue;
       
   496 	
       
   497 		if (aMediaStream.iLocalMediaPort != aMediaLine.Port()&&
       
   498 			aMediaStream.iRemoteMediaPort !=aMediaLine.Port())
       
   499 			{
       
   500 			match=EFalse;
       
   501 			}
       
   502 		}
       
   503 	return match;	
       
   504 	}
       
   505 // -----------------------------------------------------------------------------
       
   506 // CMceSecureMediaSession::CloneStreams
       
   507 // -----------------------------------------------------------------------------
       
   508 
       
   509 void CMceSecureMediaSession::CopyStreamsL(CMceSecureMediaSession& aSession)
       
   510 	{
       
   511 	iKeyNeedUpdated = aSession.iKeyNeedUpdated;
       
   512 	TInt secStreamCount = aSession.iMceSecureDesStreams.Count();
       
   513     for (TInt j=0; j<secStreamCount; j++)
       
   514     	{
       
   515     	CMceSecureDesStream* copyFrom =aSession.iMceSecureDesStreams[j];
       
   516     	CMceComMediaStream* mediaStream=NULL;
       
   517     	for (TInt i=0; i<iSession.Streams().Count();i++)
       
   518     		{
       
   519     		mediaStream =  static_cast <CMceComMediaStream*> (iSession.Streams()[i]);
       
   520     		
       
   521     		if (mediaStream->iLocalMediaPort == copyFrom->MediaStream().iLocalMediaPort &&
       
   522     			mediaStream->iRemoteMediaPort == copyFrom->MediaStream().iRemoteMediaPort)
       
   523     			{
       
   524     			CMceSecureDesStream* copy = CMceSecureDesStream::NewL(*this,
       
   525     														copyFrom->MediaField(),
       
   526     														iSecureInterface,
       
   527     														*mediaStream);
       
   528     			CleanupStack::PushL( copy);											
       
   529     			copy->CopyStreamCryptoL(*copyFrom);
       
   530     			iMceSecureDesStreams.AppendL(copy);
       
   531         		CleanupStack::Pop( copy );											
       
   532     			}
       
   533     		}
       
   534     	
       
   535         
       
   536     	}
       
   537 	}
       
   538 
       
   539 
       
   540 //-----------------------------------------------------------------------------
       
   541 // CMceSecureMediaSession::IsSecureSdpMsg ()
       
   542 // 
       
   543 // -----------------------------------------------------------------------------
       
   544 //
       
   545 TBool CMceSecureMediaSession::IsSecureSdpMsgL( CSdpMediaField& aMediaLine )
       
   546 	{
       
   547 	//answer or offer/update or refresh
       
   548 	TInt findSAVP = aMediaLine.Protocol().DesC().Find( KProtocolSAVP );
       
   549 	TInt findSAVPF = aMediaLine.Protocol().DesC().Find( KProtocolSAVPF );	
       
   550     TInt findAVP = aMediaLine.Protocol().DesC().Find( KProtocolAVP );	
       
   551     TBool isSecureMsg = ETrue;
       
   552     TInt attrCount = SdpCryptoAttributeCount( aMediaLine );
       
   553     
       
   554     
       
   555 	if ( findAVP != KErrNotFound && attrCount )
       
   556 		{
       
   557 		iSession.Modifier( KMceSecureSession ) = KMceSecurePlainAVP;
       
   558 		}
       
   559 	else if ( ( findSAVP != KErrNotFound || findSAVPF != KErrNotFound ) &&
       
   560 			attrCount )
       
   561 		{
       
   562 		iSession.Modifier( KMceSecureSession ) = KMceSecureNormal;
       
   563 		}
       
   564 	else if ( ( findSAVP != KErrNotFound || findSAVPF != KErrNotFound ) &&
       
   565 			!attrCount )
       
   566 		{
       
   567 		User::Leave( KErrArgument );
       
   568 		}
       
   569 	else
       
   570 		{
       
   571 		return !isSecureMsg;
       
   572 		}
       
   573 	
       
   574 	
       
   575 	return isSecureMsg;
       
   576 	}
       
   577 	
       
   578 // -----------------------------------------------------------------------------
       
   579 // CMceSecureMediaSession::SdpCryptoAttributeCount()
       
   580 // 
       
   581 // -----------------------------------------------------------------------------
       
   582 //    
       
   583 TInt CMceSecureMediaSession::SdpCryptoAttributeCount( CSdpMediaField& aMediaLine)
       
   584 	{
       
   585 	MCEMM_DEBUG("CMceSecureMediaSession::SdpCryptoAttributeCount(), Entry");   
       
   586 	RPointerArray< CSdpAttributeField > attrList = aMediaLine.AttributeFields();
       
   587     CSdpAttributeField* attributeField = NULL;                
       
   588     TInt attrCount = attrList.Count();
       
   589     TInt attrbuiteCryptoCount = 0;
       
   590     for (TInt j = 0; j < attrCount; j++ )
       
   591         {
       
   592        	attributeField = attrList[j];
       
   593       
       
   594         RStringF attribute = attributeField->Attribute();
       
   595      
       
   596         // check if attribute is 'crypto' 
       
   597         if ( KErrNotFound != attribute.DesC().Match( KCrypto ) )
       
   598             {
       
   599             attrbuiteCryptoCount++;
       
   600            	}
       
   601 		}
       
   602 	
       
   603 	MCEMM_DEBUG("CMceSecureMediaSession::SdpCryptoAttributeCount(), Exit");   
       
   604 	return attrbuiteCryptoCount;
       
   605 	}	
       
   606 
       
   607 // -----------------------------------------------------------------------------
       
   608 // CMceSecureMediaSession::SdpCryptoAttributeCount()
       
   609 // 
       
   610 // -----------------------------------------------------------------------------
       
   611 //    
       
   612 void CMceSecureMediaSession::RemoveSecureCrypto( )
       
   613 	{    	
       
   614 	//clear comsession crypto
       
   615 	TInt count = iSession.iClientCryptoSuites.Count();
       
   616 	for (TInt i = count; i > 0; i--)
       
   617 		{
       
   618 		iSession.iClientCryptoSuites.Remove( i-1 );	
       
   619 		iSession.iIsSecureSession = EFalse;
       
   620 		}
       
   621     }					
       
   622 //  End of File