rtp/srtpstack/src/srtppacketrtcp.cpp
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 /*
       
     2 * Copyright (c) 2004 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:    General RTCP packet handling routines.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDES
       
    22 #include "srtppacketrtcp.h"
       
    23 #include "srtputils.h"
       
    24 #include "srtpcryptohandler.h"
       
    25 #include "srtpcryptocontext.h"
       
    26 #include "srtpmasterkey.h"
       
    27 #include "srtpmastersalt.h"
       
    28 
       
    29 // -----------------------------------------------------------------------------
       
    30 // CSRTPPacketRTCP::CSRTPPacketRTCP
       
    31 // -----------------------------------------------------------------------------
       
    32 //
       
    33 CSRTPPacketRTCP::CSRTPPacketRTCP(const TDesC8& aPacket,
       
    34                    CSRTPCryptoHandler& aHandler)
       
    35     : CSRTPPacket(aPacket, aHandler)
       
    36             {
       
    37             
       
    38             }
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // CSRTPPacketRTCP::~CSRTPPacketRTCP
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 CSRTPPacketRTCP::~CSRTPPacketRTCP()
       
    45             {
       
    46             
       
    47             }
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 // Two-phased constructor. 
       
    51 // 
       
    52 // ---------------------------------------------------------------------------
       
    53 //
       
    54 CSRTPPacketRTCP* CSRTPPacketRTCP::NewL(const TDesC8& aPacket,
       
    55                       CSRTPCryptoHandler& aHandler)
       
    56     {
       
    57     CSRTPPacketRTCP* self = new( ELeave )CSRTPPacketRTCP( aPacket, aHandler);
       
    58     CleanupStack::PushL( self );    
       
    59     self->ConstructL();
       
    60     CleanupStack::Pop( self );        
       
    61     return self;
       
    62     }
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // void CSRTPPacketRTCP::ConstructL
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 void CSRTPPacketRTCP::ConstructL()
       
    69     {            
       
    70     CSRTPPacket::ConstructL(); 
       
    71     UpdateHeaderLengthL(); 
       
    72     UpdatePayloadLength();
       
    73     UpdatePayload();           
       
    74     }
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 // CSRTPPacketRTCP::UpdatePayloadLength()
       
    78 // ---------------------------------------------------------------------------
       
    79 //
       
    80 void CSRTPPacketRTCP::UpdatePayloadLength()
       
    81     {    
       
    82      // In RTP case the payload length is easy to calculate
       
    83      iPayloadLength = iPacket.Length() - iHeaderLength;     
       
    84      if ( iPacket.Length() <= iHeaderLength )
       
    85      	{
       
    86      	iPayloadLength = 0;
       
    87      	}
       
    88     }
       
    89 
       
    90 // ---------------------------------------------------------------------------
       
    91 // CSRTPPacketRTCP::UpdateHeaderLengthL()
       
    92 // ---------------------------------------------------------------------------
       
    93 //
       
    94 void CSRTPPacketRTCP::UpdateHeaderLengthL()
       
    95     {    
       
    96     TInt size = iPacket.Length();
       
    97     
       
    98 	const TUint8 *pointer = iDataP;	
       
    99 
       
   100      // version
       
   101     if ( ( ( pointer[0] & 0xC0 ) >> 6 ) != 2/*RTPVersion*/ )
       
   102         {
       
   103        	User::Leave(KErrCorrupt);
       
   104         }
       
   105 
       
   106     // padding
       
   107     if ( pointer[0] & 0x20 )
       
   108         {
       
   109     	size -= iDataP[size - 1];
       
   110     	}
       
   111 
       
   112     // determine RTCP packet type
       
   113     TInt pt = static_cast<TInt>( pointer[1] );
       
   114 
       
   115     if ( ( pt!= 200 ) && (pt != 201) &&
       
   116 	     ( pt != 202) && ( pt != 203 ) &&
       
   117 	     ( pt != 204 ) )
       
   118         {
       
   119         User::Leave(KErrCorrupt);
       
   120         }
       
   121 
       
   122     // source/report Count
       
   123     //TInt sourceCount = ( pointer[0] & 0x1F );
       
   124 
       
   125     pointer += 2;
       
   126     
       
   127     TInt length =static_cast<TInt>( TSRTPUtils::Read16( pointer ) );
       
   128 
       
   129     if ( length * 4 > size )
       
   130         {
       
   131         User::Leave(KErrCorrupt);
       
   132         }
       
   133     pointer += 2;
       
   134 
       
   135     // SSRC of sender in case of RR
       
   136     if ( pt == 201 || pt==200 )
       
   137         {
       
   138 	    TUint32 SSRC = TSRTPUtils::Read32( pointer );
       
   139 	    pointer += 4;
       
   140         }
       
   141                         
       
   142     
       
   143 
       
   144     //RFC 3711 3.4 - RR & SR
       
   145     iHeaderLength =pointer-iDataP;
       
   146     }
       
   147 // ---------------------------------------------------------------------------
       
   148 // CSRTPPacketRTCP::CountEncryptedPacketSizeL()
       
   149 // ---------------------------------------------------------------------------
       
   150 //
       
   151 TUint CSRTPPacketRTCP::CountEncryptedPacketSizeL()
       
   152     {
       
   153    	TUint srtpPacketSize = iHeaderLength + iPayloadLength + KSRTCPPacketIndexLength4;
       
   154    	srtpPacketSize += iHandler.Context().MasterKey().MKI().Length();
       
   155     if ( iHandler.Context().CryptoParams().iSrtcpAuthAlg == EAuthHMAC_SHA1)
       
   156         {
       
   157         srtpPacketSize += iHandler.Context().CryptoParams().iSrtcpAuthTagLen/8;
       
   158         }
       
   159     
       
   160     return srtpPacketSize;
       
   161     }
       
   162         
       
   163 // ---------------------------------------------------------------------------
       
   164 // CSRTPPacketRTCP::CreateEncryptedPacketL()
       
   165 // ---------------------------------------------------------------------------
       
   166 //        
       
   167 HBufC8* CSRTPPacketRTCP::CreateEncryptedPacketL(TUint8* aEncryptedPayloadPtr)
       
   168     {
       
   169      TUint srtpPacketSize = CountEncryptedPacketSizeL();
       
   170     
       
   171     return CopyHeaderAndPayloadL(srtpPacketSize, aEncryptedPayloadPtr);    
       
   172     }    
       
   173 
       
   174 
       
   175 // ---------------------------------------------------------------------------
       
   176 // CSRTPPacketRTCP::SetPacketIndex()
       
   177 // ---------------------------------------------------------------------------
       
   178 //
       
   179 void CSRTPPacketRTCP::SetPacketIndex(TUint64 aPacketIndex)
       
   180     {
       
   181     iPacketIndex = aPacketIndex;
       
   182     }
       
   183 // ---------------------------------------------------------------------------
       
   184 // CSRTPPacketRTCP::PacketIndex()
       
   185 // ---------------------------------------------------------------------------
       
   186 //
       
   187 TUint64 CSRTPPacketRTCP::PacketIndex()
       
   188     {
       
   189     return iPacketIndex;
       
   190     }
       
   191 
       
   192  // ---------------------------------------------------------------------------
       
   193 // CSRTPPacketRTCP::CreateDecryptedPacketL()
       
   194 // ---------------------------------------------------------------------------
       
   195 //   
       
   196 HBufC8* CSRTPPacketRTCP::CreateDecryptedPacketL(TUint8* /*aDecryptedPayloadPtr*/)
       
   197     { 
       
   198     User::Leave(KErrTotalLossOfPrecision);
       
   199     return  NULL;           
       
   200     }
       
   201 // ---------------------------------------------------------------------------
       
   202 // CSRTPPacketRTCP::AuthenticationTag()
       
   203 // ---------------------------------------------------------------------------
       
   204 //
       
   205 TPtrC8 CSRTPPacketRTCP::AuthenticationTag()
       
   206     {
       
   207     return  NULL;            
       
   208     }
       
   209 // ---------------------------------------------------------------------------
       
   210 // CSRTPPacketRTCP::MasterKeyIdentifier()
       
   211 // ---------------------------------------------------------------------------
       
   212 //
       
   213 TPtrC8 CSRTPPacketRTCP::MasterKeyIdentifier()
       
   214     {
       
   215     return  NULL;            
       
   216     }
       
   217