|
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: Represents a sender(outgoing) SRTP stream. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #ifndef __SRTP_STREAM_OUT_H__ |
|
22 #define __SRTP_STREAM_OUT_H__ |
|
23 |
|
24 // INCLUDES |
|
25 #include <e32def.h> |
|
26 #include "srtpstream.h" |
|
27 #include "msrtpstreamoutcontext.h" |
|
28 |
|
29 |
|
30 // FORWARD DECLARATIONS |
|
31 class CSRTPSession; |
|
32 class CSRTPCryptoContext; |
|
33 class MSRTPReKeyingObserver; |
|
34 class TSRTPStreamOutStateBase; |
|
35 |
|
36 /** |
|
37 * Represents an SRTP stream. |
|
38 */ |
|
39 class CSRTPStreamOut : public CSRTPStream, |
|
40 public MSRTPStreamOutContext |
|
41 { |
|
42 public: |
|
43 /** |
|
44 * Two-phased constructor. |
|
45 * Use this function if the stream will use the SRTP session's default |
|
46 * cryptographic context. |
|
47 * @param aSession The session containing the cryptographic |
|
48 * context for this object. |
|
49 * @param aSSRC The synchronization source ID of the RTP stream |
|
50 * that corresponds to this object. |
|
51 * @leave KErrNone if success, system-wide error code otherwise |
|
52 */ |
|
53 IMPORT_C static CSRTPStreamOut* NewL( CSRTPSession& aSession, TUint aSSRC ); |
|
54 |
|
55 /** |
|
56 * Two-phased constructor. |
|
57 * Use this function if the stream will have its own cryptographic |
|
58 * context. |
|
59 * @param aSession The session containing the cryptographic |
|
60 * context for this object. |
|
61 * @param aSSRC The synchronization source ID of the RTP stream |
|
62 * that corresponds to this object. |
|
63 * @param aCon The cryptographic context, ownership is transfered. |
|
64 * @param aObs The callback object |
|
65 * @leave KErrNone if success, system-wide error code otherwise |
|
66 */ |
|
67 IMPORT_C static CSRTPStreamOut* NewL( CSRTPSession& aSession, |
|
68 TUint aSSRC, |
|
69 CSRTPCryptoContext* aCon, |
|
70 MSRTPReKeyingObserver& aObs ); |
|
71 |
|
72 /** |
|
73 * Two-phased constructor. |
|
74 * Use this function if the stream will have its own cryptographic |
|
75 * context. Note that if crypto context is not set later, all data |
|
76 * packet will not be processed. |
|
77 * @param aSession The session containing the cryptographic |
|
78 * context for this object. |
|
79 * @param aSSRC The synchronization source ID of the RTP stream |
|
80 * that corresponds to this object. |
|
81 * @param aCon The cryptographic context |
|
82 * @param aObs The callback object |
|
83 * @leave KErrNone if success, system-wide error code otherwise |
|
84 */ |
|
85 IMPORT_C static CSRTPStreamOut* NewL( CSRTPSession& aSession, |
|
86 TUint aSSRC, |
|
87 MSRTPReKeyingObserver& aObs ); |
|
88 |
|
89 public: |
|
90 /** |
|
91 * Protect an RTP packet. |
|
92 * The settings for the protection are fetched from the appropriate |
|
93 * cryptographic context. If the protection fails, the function leaves |
|
94 * with a system error code and the provided RTP packet is unaltered. |
|
95 * @param aPacket The RTP packet to protect. The length of descriptor |
|
96 * should be the same with the actual data, otherwise encoding will not be |
|
97 * correct. |
|
98 * @leave KErrNone if success, system-wide error code otherwise |
|
99 * @return An SRTP packet. |
|
100 */ |
|
101 IMPORT_C HBufC8* ProtectRtpL( const TDesC8& aPacket ); |
|
102 |
|
103 /** |
|
104 * Protect an RTCP packet. |
|
105 * The settings for the protection are fetched from the appropriate |
|
106 * cryptographic context. If the protection fails, the function leaves |
|
107 * with a system error code and the provided RTCP packet is unaltered. |
|
108 * @param aPacket The RTCP packet to protect. |
|
109 * @leave KErrNone if success, system-wide error code otherwise |
|
110 * @return An SRTCP packet. |
|
111 */ |
|
112 IMPORT_C HBufC8* ProtectRtcpL( const TDesC8& aPacket ); |
|
113 |
|
114 /** |
|
115 * Set CryptoContext for OutStream |
|
116 * Setting cryptographic context must be done to enable encode/decode packets. |
|
117 * During offer/Answer, offerer do not know which crypto context is |
|
118 * chosen by answerer. CryptoContext then can be set after getting response |
|
119 * from answerer. |
|
120 * Updating stream specific crypto Context. |
|
121 * Note that to update crypto context, ROC will not be re-intialed to zero but |
|
122 * the states and number of receiving packets will be reset. This can be |
|
123 * use only when keys lifetime has not expired. |
|
124 * Crypto context ownershíp is transfered. |
|
125 * @param aCon aCryyptoContext which wants be used |
|
126 * @leave KErrNone if success, system-wide error code otherwise |
|
127 * @return void |
|
128 */ |
|
129 IMPORT_C void SetCryptoOutL(CSRTPCryptoContext* aCon); |
|
130 |
|
131 ~CSRTPStreamOut( ); |
|
132 |
|
133 /** |
|
134 * Delete the existed crypto context and re-initial the states |
|
135 * @param None |
|
136 * @leave KErrNone if success, system-wide error code otherwise |
|
137 * @return void |
|
138 */ |
|
139 void UpdateCryptoAndStatesL(); |
|
140 |
|
141 private: //from MSRTPStreamOutContext |
|
142 |
|
143 /* |
|
144 * Change state of the current outgoing stream (for RTP) |
|
145 * @return void. |
|
146 */ |
|
147 void ChangeRTPState(MSRTPStreamOutContext::TContextOutState aNewState); |
|
148 |
|
149 /* |
|
150 * Change state of the current outgoing stream (for RTCP) |
|
151 * @return void. |
|
152 */ |
|
153 void ChangeRTCPState(MSRTPStreamOutContext::TContextOutState aNewState/*TState aNewState*/); |
|
154 |
|
155 private: //methods |
|
156 CSRTPStreamOut (CSRTPSession& aSession, |
|
157 TUint aSSRC); |
|
158 |
|
159 CSRTPStreamOut (CSRTPSession& aSession, |
|
160 TUint aSSRC, |
|
161 CSRTPCryptoContext* aCon, |
|
162 MSRTPReKeyingObserver& aObs ); |
|
163 |
|
164 CSRTPStreamOut (CSRTPSession& aSession, |
|
165 TUint aSSRC, |
|
166 MSRTPReKeyingObserver& aObs ); |
|
167 |
|
168 |
|
169 void ConstructL(); |
|
170 |
|
171 /** |
|
172 * Create states defined in TSRTPStreamOutStateBase |
|
173 * @leave KErrNone if success, system-wide error code otherwise |
|
174 * @return void. |
|
175 */ |
|
176 void InitializeStatesL(); |
|
177 |
|
178 TSRTPStreamOutStateBase& CurrentRTPState(); |
|
179 |
|
180 TSRTPStreamOutStateBase& CurrentRTCPState(); |
|
181 |
|
182 protected: |
|
183 /* |
|
184 states for CSRTPStreamOut |
|
185 */ |
|
186 CArrayVarFlat<TSRTPStreamOutStateBase> iStates; |
|
187 /* |
|
188 the same stream can handle RTP and RTCP packets, |
|
189 these can have different states |
|
190 */ |
|
191 MSRTPStreamOutContext::TContextOutState iCurrentRTPState; |
|
192 MSRTPStreamOutContext::TContextOutState iCurrentRTCPState; |
|
193 |
|
194 private: |
|
195 //friend class CSRTPSession; |
|
196 #ifdef EUNIT_TESTING |
|
197 friend class UT_CSRTPStreamOut; |
|
198 #endif |
|
199 }; |
|
200 |
|
201 #endif // __SRTP_STREAM_OUT_H__ |