|
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 SRTP packet class (RTP/SRTP/RTCP/SRTCP) |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #ifndef __SRTP_PACKET_H__ |
|
22 #define __SRTP_PACKET_H__ |
|
23 |
|
24 // INCLUDES |
|
25 #include <in_sock.h> |
|
26 // FORWARD DECLARATIONS |
|
27 class CSRTPCryptoHandler; |
|
28 |
|
29 /** |
|
30 * Contains general packet routines |
|
31 */ |
|
32 class CSRTPPacket : public CBase |
|
33 { |
|
34 public: |
|
35 /** |
|
36 * Get payload entry. Here the "payload" denotes the |
|
37 * encrypted portion (incl. RTCP/SRTCP). |
|
38 * @return pointer reference to the encrypted portion. |
|
39 */ |
|
40 TPtrC8 Payload(); |
|
41 |
|
42 /** |
|
43 * Get header length. |
|
44 * @return length of the header. |
|
45 */ |
|
46 TUint HeaderLength(); |
|
47 |
|
48 /** |
|
49 * Get payload length (== length of the encrypted portion). |
|
50 * @return length of the payload. |
|
51 */ |
|
52 TUint PayloadLength(); |
|
53 |
|
54 /** |
|
55 * Get header and encrypted portion, excluding possible |
|
56 * MKI and authentication tag. |
|
57 * @return header and encrypted portion. |
|
58 */ |
|
59 TPtrC8 HeaderAndPayload(); |
|
60 |
|
61 /** |
|
62 * Get the authentication portion for recv stream data |
|
63 * For RTP this gets header and payload as authentication portion |
|
64 * For RTCP it gets payload + SRTCP index |
|
65 * @param rtcp if it is rtcp packet |
|
66 * @leave KErrNone if success, system-wide error code otherwise |
|
67 * @return payload concatenated with ROC. |
|
68 */ |
|
69 HBufC8* Get_Concatenated_MDataL(TBool rtcp); |
|
70 |
|
71 /** |
|
72 * Create a new packet by allocating given size |
|
73 * and by copying header and given payload. |
|
74 * This can be any packet: RTP/SRTP/RTCP/SRTCP |
|
75 * @param aPacketSize new packet size. |
|
76 * @param aPayloadPtr pointer to the payload to be copied. |
|
77 * @leave KErrNone if success, system-wide error code otherwise |
|
78 * @return new packet with header and payload. |
|
79 */ |
|
80 HBufC8* CopyHeaderAndPayloadL(TUint aPacketSize, |
|
81 TUint8* aPayloadPtr); |
|
82 |
|
83 ~CSRTPPacket(); |
|
84 |
|
85 |
|
86 /** |
|
87 * virtual function for creating decrypted packet, |
|
88 * implemented in CSRTPPacketSRTP/CSRTPPacketSRTCP, |
|
89 */ |
|
90 virtual HBufC8* CreateDecryptedPacketL(TUint8* aDecryptedPayloadPtr); |
|
91 |
|
92 /** |
|
93 * virtual function for creating encrypted packet, |
|
94 * implemented in CSRTPPacketRTP/CSRTPPacketRTCP, |
|
95 */ |
|
96 virtual HBufC8* CreateEncryptedPacketL(TUint8* aEncryptedPayloadPtr); |
|
97 |
|
98 /** |
|
99 * virtual function for getting the authentication tag, |
|
100 * implemented in CSRTPPacketSRTP/CSRTPPacketSRTCP |
|
101 */ |
|
102 virtual TPtrC8 AuthenticationTag(); |
|
103 |
|
104 /** |
|
105 * virtual function for getting the sequence number, |
|
106 * implemented in CSRTPPacketRTP |
|
107 */ |
|
108 virtual TUint16 SequenceNumber(); |
|
109 |
|
110 /** |
|
111 * virtual function for setting the packet index value, |
|
112 * implemented in CSRTPPacketRTP |
|
113 */ |
|
114 virtual void SetPacketIndex(TUint64 aPacketIndex); |
|
115 |
|
116 /** |
|
117 * virtual function for getting the MKI value, |
|
118 * implemented in CSRTPPacketSRTP/CSRTPPacketSRTCP |
|
119 */ |
|
120 virtual TPtrC8 MasterKeyIdentifier(); |
|
121 |
|
122 /** |
|
123 * virtual function for counting the sender-side packet index |
|
124 * implemented in CSRTPPacketRTP |
|
125 */ |
|
126 virtual void CountSenderPacketIndex(); |
|
127 |
|
128 /** |
|
129 * virtual function for getting the packet index value, |
|
130 * implemented in CSRTPPacketRTP |
|
131 */ |
|
132 virtual TUint64 PacketIndex(); |
|
133 |
|
134 |
|
135 /** |
|
136 * Get Sender Roll-Over Counter from RTP/SRTP packets defined by RCC mode |
|
137 * @return 32 bit unsigned integer |
|
138 */ |
|
139 virtual TUint32 GetSenderROC(); |
|
140 protected: //methods |
|
141 |
|
142 |
|
143 /* |
|
144 * Update header length member |
|
145 * @leave KErrNone if success, system-wide error code otherwise |
|
146 * @return void |
|
147 */ |
|
148 void UpdatePayloadLengthL(); |
|
149 |
|
150 /* |
|
151 * Update payload member in this class |
|
152 * @leave KErrNone if success, system-wide error code otherwise |
|
153 * @return void |
|
154 */ |
|
155 void UpdatePayload(); |
|
156 |
|
157 /* |
|
158 * Read sequence number. |
|
159 * @return 16 bit sequence number. |
|
160 */ |
|
161 TUint16 GetSequenceNumber(); |
|
162 |
|
163 void ConstructL(); |
|
164 |
|
165 CSRTPPacket (const TDesC8& aPacket, |
|
166 CSRTPCryptoHandler& aHandler); |
|
167 |
|
168 |
|
169 protected: //data |
|
170 TPtrC8 iPacket; // packet |
|
171 const TUint8 *iDataP; // pointer to packet |
|
172 CSRTPCryptoHandler& iHandler; // crypto handler |
|
173 TPtrC8 iPayload; // payload (encrypted portion) |
|
174 TUint iHeaderLength; // header length |
|
175 TUint iPayloadLength; // payload length |
|
176 |
|
177 private: |
|
178 #ifdef EUNIT_TESTING |
|
179 friend class UT_CSRTPCryptoHandlerSRTP; |
|
180 |
|
181 #endif |
|
182 |
|
183 |
|
184 }; |
|
185 |
|
186 #endif // __SRTP_PACKET_H__ |