rtp/srtpstack/src/srtppacket.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 packet handling routines.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDES
       
    22 #include "srtppacket.h"
       
    23 #include "srtpcryptohandler.h"
       
    24 #include "srtpcryptocontext.h"
       
    25 #include "srtputils.h"
       
    26 #include "srtpmasterkey.h"
       
    27 #include "srtpmastersalt.h"
       
    28 
       
    29 // -----------------------------------------------------------------------------
       
    30 // CSRTPPacket::CSRTPPacket
       
    31 // -----------------------------------------------------------------------------
       
    32 //
       
    33 CSRTPPacket::CSRTPPacket(const TDesC8& aPacket,
       
    34                       CSRTPCryptoHandler& aHandler)
       
    35     :   iPacket(aPacket),
       
    36         iDataP(aPacket.Ptr()),
       
    37         iHandler(aHandler),
       
    38         iPayload(TPtrC8()),
       
    39         iHeaderLength(0), 
       
    40         iPayloadLength(0)
       
    41     {
       
    42     
       
    43     // set the current packet    
       
    44     iPacket.Set(aPacket.Ptr(), aPacket.Length());
       
    45             
       
    46     }
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // CSRTPPacket::~CSRTPPacket
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 CSRTPPacket::~CSRTPPacket()
       
    53             {
       
    54             
       
    55             }
       
    56             
       
    57 // ---------------------------------------------------------------------------
       
    58 // CSRTPPacket::Payload()
       
    59 // ---------------------------------------------------------------------------
       
    60 //
       
    61 TPtrC8 CSRTPPacket::Payload()
       
    62     {
       
    63     return iPayload;
       
    64     }
       
    65 
       
    66 
       
    67 // ---------------------------------------------------------------------------
       
    68 // CSRTPPacket::HeaderLength()
       
    69 // ---------------------------------------------------------------------------
       
    70 //
       
    71 TUint CSRTPPacket::HeaderLength()
       
    72     {
       
    73     return iHeaderLength;
       
    74     }
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 // CSRTPPacket::PayloadLength()
       
    78 // ---------------------------------------------------------------------------
       
    79 //
       
    80 TUint CSRTPPacket::PayloadLength()
       
    81     {
       
    82     return iPayloadLength;
       
    83     }
       
    84 
       
    85 
       
    86 // ---------------------------------------------------------------------------
       
    87 // CSRTPPacket::HeaderAndPayload()
       
    88 // ---------------------------------------------------------------------------
       
    89 //
       
    90 TPtrC8 CSRTPPacket::HeaderAndPayload()
       
    91     {
       
    92     return iPacket.Mid(0, iHeaderLength + iPayloadLength);    
       
    93     }
       
    94 
       
    95 // ---------------------------------------------------------------------------
       
    96 // CSRTPPacket::Get_Concatenated_MDataL()
       
    97 // ---------------------------------------------------------------------------
       
    98 //
       
    99 HBufC8* CSRTPPacket::Get_Concatenated_MDataL(TBool rtcp)
       
   100     {                      
       
   101     TInt size = iHeaderLength + iPayloadLength;
       
   102     if (rtcp)
       
   103     	{
       
   104     	//RFC 3711 3.4 SRCP authentication portion including index
       
   105     	size = size + KSRTCPPacketIndexLength4;
       
   106     	}
       
   107     HBufC8* result = HBufC8::NewMaxL(size);
       
   108     TUint8* ptr = const_cast<TUint8*>(result->Des().Ptr());
       
   109     
       
   110     Mem::FillZ( ptr, size);        
       
   111     Mem::Copy( ptr, iDataP, size );                    
       
   112    
       
   113     return result ;      
       
   114     }
       
   115 
       
   116 // ---------------------------------------------------------------------------
       
   117 // CSRTPPacket::ConstructL()
       
   118 // ---------------------------------------------------------------------------
       
   119 //
       
   120 void CSRTPPacket::ConstructL()
       
   121     {      
       
   122     }
       
   123 
       
   124 
       
   125 // -----------------------------------------------------------------------------
       
   126 // void CSRTPPacket::UpdatePayload
       
   127 // -----------------------------------------------------------------------------
       
   128 //
       
   129 void CSRTPPacket::UpdatePayload()
       
   130     {            
       
   131     TPtrC8 payload = iPacket.Mid(iHeaderLength, iPayloadLength);
       
   132     iPayload.Set(payload.Ptr(), iPayloadLength);
       
   133     }
       
   134         
       
   135 // -----------------------------------------------------------------------------
       
   136 // void CSRTPPacket::CopyHeaderAndPayloadL
       
   137 // -----------------------------------------------------------------------------
       
   138 //
       
   139 HBufC8* CSRTPPacket::CopyHeaderAndPayloadL(TUint aPacketSize,
       
   140                                        TUint8* aPayloadPtr)
       
   141     {    
       
   142     HBufC8* packet = HBufC8::NewMaxL(aPacketSize);
       
   143 
       
   144     TUint8* packetPtr = const_cast<TUint8*>(packet->Des().Ptr());        
       
   145     Mem::FillZ( packetPtr, aPacketSize);        
       
   146 
       
   147     // First copy the header
       
   148     Mem::Copy( packetPtr, iPacket.Ptr(), iHeaderLength);
       
   149     // then copy the encrypted/decrypted payload
       
   150     packetPtr += iHeaderLength;
       
   151     Mem::Copy( packetPtr, aPayloadPtr, iPayloadLength);
       
   152     
       
   153     return packet;
       
   154     }
       
   155     
       
   156 
       
   157 
       
   158 // VIRTUAL functions
       
   159 
       
   160 // ---------------------------------------------------------------------------
       
   161 // CSRTPPacket::CreateDecryptedPacketL()
       
   162 // ---------------------------------------------------------------------------
       
   163 //
       
   164 HBufC8* CSRTPPacket::CreateDecryptedPacketL(TUint8* /*aDecryptedPayloadPtr*/)
       
   165     { 
       
   166     User::Leave(KErrTotalLossOfPrecision);
       
   167     return  NULL;  
       
   168     }
       
   169     
       
   170 // ---------------------------------------------------------------------------
       
   171 // CSRTPPacket::CreateEncryptedPacketL()
       
   172 // ---------------------------------------------------------------------------
       
   173 //
       
   174 HBufC8* CSRTPPacket::CreateEncryptedPacketL(TUint8* /*aEncryptedPayloadPtr*/)
       
   175     {  
       
   176     User::Leave(KErrTotalLossOfPrecision);
       
   177     return  NULL;    
       
   178     }
       
   179 
       
   180 // ---------------------------------------------------------------------------
       
   181 // CSRTPPacket::AuthenticationTag()
       
   182 // ---------------------------------------------------------------------------
       
   183 //
       
   184 TPtrC8 CSRTPPacket::AuthenticationTag()
       
   185     {  
       
   186     return  NULL;      
       
   187     }
       
   188 
       
   189 // ---------------------------------------------------------------------------
       
   190 // CSRTPPacket::SequenceNumber()
       
   191 // ---------------------------------------------------------------------------
       
   192 //
       
   193 TUint16 CSRTPPacket::SequenceNumber()
       
   194     {  
       
   195     return  NULL;      
       
   196     }
       
   197 
       
   198 // ---------------------------------------------------------------------------
       
   199 // CSRTPPacket::SetPacketIndex()
       
   200 // ---------------------------------------------------------------------------
       
   201 //
       
   202 void CSRTPPacket::SetPacketIndex(TUint64 /*aPacketIndex*/)
       
   203     {  
       
   204     }
       
   205 
       
   206 // ---------------------------------------------------------------------------
       
   207 // CSRTPPacket::MasterKeyIdentifier()
       
   208 // ---------------------------------------------------------------------------
       
   209 //
       
   210 TPtrC8 CSRTPPacket::MasterKeyIdentifier()
       
   211     {  
       
   212     return  NULL;      
       
   213     }
       
   214 
       
   215 // ---------------------------------------------------------------------------
       
   216 // CSRTPPacket::CountSenderPacketIndex()
       
   217 // ---------------------------------------------------------------------------
       
   218 //
       
   219 void CSRTPPacket::CountSenderPacketIndex()
       
   220     { 
       
   221     }
       
   222     
       
   223 // ---------------------------------------------------------------------------
       
   224 // CSRTPPacket::PacketIndex()
       
   225 // ---------------------------------------------------------------------------
       
   226 //
       
   227 TUint64 CSRTPPacket::PacketIndex()
       
   228     {  
       
   229     return  NULL;      
       
   230     }
       
   231 // ---------------------------------------------------------------------------
       
   232 // CSRTPPacket::GetSenderROC
       
   233 // ---------------------------------------------------------------------------
       
   234 //    
       
   235 TUint32 CSRTPPacket::GetSenderROC()    
       
   236 	{
       
   237 	return NULL;
       
   238 	}