rtp/srtpstack/src/tsrtpstreamoutstatenormal.cpp
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     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:    implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include "tsrtpstreamoutstatenormal.h"
       
    22 #include "msrtpstreamoutcontext.h"
       
    23 #include "msrtpcryptohandlercontext.h"
       
    24 #include "msrtpcryptohandlercontextrtp.h"
       
    25 #include "msrtpcryptohandlercontextrtcp.h"
       
    26 #include "srtputils.h"
       
    27 
       
    28 // ----------------------------------------------------------------------------
       
    29 // TSRTPStreamOutStateNormal::TSRTPStreamOutStateNormal
       
    30 // ----------------------------------------------------------------------------
       
    31 //
       
    32 TSRTPStreamOutStateNormal::TSRTPStreamOutStateNormal(
       
    33     MSRTPStreamOutContext& aStreamContext,
       
    34     MSRTPCryptoHandlerContextRTP& aCryptoHandlerRTPContext,
       
    35     MSRTPCryptoHandlerContextRTCP& aCryptoHandlerRTCPContext)
       
    36     : TSRTPStreamOutStateBase(aStreamContext,
       
    37                             aCryptoHandlerRTPContext, 
       
    38                             aCryptoHandlerRTCPContext)
       
    39     {
       
    40     }
       
    41 
       
    42 // ----------------------------------------------------------------------------
       
    43 // TSRTPStreamOutStateNormal::DoProtectRtpL
       
    44 // ----------------------------------------------------------------------------
       
    45 //		
       
    46 HBufC8* TSRTPStreamOutStateNormal::DoProtectRtpL(const TDesC8& aPacket)
       
    47     {
       
    48     // first initialize current RTP packet..
       
    49     SRTP_DEBUG_DETAIL("TSRTPStreamOutStateNormal::DoProtectRtpL Entry");
       
    50     
       
    51     SRTP_DEBUG_TINT_VALUE( "and packet before encrypted length is", aPacket.Length() );
       
    52                    
       
    53     iCryptoHandlerRTPContext.InitializePlainPacketL(aPacket);    
       
    54     
       
    55     // Step 2 (in RFC 3711, section 3.3):
       
    56     // count the packet index i
       
    57     iCryptoHandlerRTPContext.CountSenderPacketIndexL();
       
    58      
       
    59      // derive session keys..
       
    60     if (iCryptoHandlerRTPContext.MasterKeysUpdated())
       
    61        {
       
    62        iCryptoHandlerRTPContext.DeriveSessionKeysL();        
       
    63        }
       
    64                
       
    65      // encrypt..
       
    66 	SRTP_DEBUG_DETAIL( "EncrypL" );
       
    67      
       
    68     HBufC8* protectedPacket = iCryptoHandlerRTPContext.EncryptL();
       
    69      
       
    70      // finally, conditional update of roll-over counter..
       
    71      //Should check the next Packet Index and decide if need to be re-key
       
    72     iCryptoHandlerRTPContext.UpdateROC();
       
    73                   
       
    74     
       
    75 
       
    76 	SRTP_DEBUG_DETAIL( "TSRTPStreamOutStateNormal::DoProtectRtpL Exit");
       
    77     
       
    78     // return encrypted RTP packet
       
    79     return protectedPacket;    
       
    80     
       
    81     }
       
    82 
       
    83 // ----------------------------------------------------------------------------
       
    84 // TSRTPStreamOutStateNormal::DoProtectRtcpL
       
    85 // ----------------------------------------------------------------------------
       
    86 //		
       
    87 HBufC8* TSRTPStreamOutStateNormal::DoProtectRtcpL(const TDesC8& aPacket)
       
    88     {
       
    89      // first initialize current RTP packet..
       
    90     iCryptoHandlerRTCPContext.InitializePlainPacketL(aPacket);    
       
    91     
       
    92     // Step 2 (in RFC 3711, section 3.3):
       
    93     // count the packet index i
       
    94      iCryptoHandlerRTCPContext.CountSenderPacketIndexL();
       
    95      
       
    96      // derive session keys..
       
    97      if (iCryptoHandlerRTCPContext.MasterKeysUpdated())
       
    98         {
       
    99         iCryptoHandlerRTCPContext.DeriveSessionKeysL();        
       
   100         }
       
   101                
       
   102      // encrypt..
       
   103      HBufC8* protectedPacket = iCryptoHandlerRTCPContext.EncryptL();
       
   104      
       
   105     //Should check the next Packet Index and decide if need to be re-key
       
   106     // return encrypted RTP packet
       
   107     return protectedPacket;    
       
   108     }