2
2
* Copyright (C) 2004, 2005, 2006, 2009, 2008, 2009, 2010 Savoir-Faire Linux Inc.
3
3
* Author: Pierre-Luc Bacon <pierre-luc.bacon@savoirfairelinux.com>
4
* Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
5
6
* This program is free software; you can redistribute it and/or modify
6
7
* it under the terms of the GNU General Public License as published by
77
80
AccountID accountId = Manager::instance().getAccountFromCall (ca->getCallId());
79
// Check if it is an IP-to-IP call
80
if (accountId == AccountNULL) {
81
_srtpEnabled = Manager::instance().getConfigBool (IP2IP_PROFILE, SRTP_ENABLE);
82
_keyExchangeProtocol = Manager::instance().getConfigInt (IP2IP_PROFILE, SRTP_KEY_EXCHANGE);
83
_debug ("Ip-to-ip profile selected with key exchange protocol number %d", _keyExchangeProtocol);
84
_helloHashEnabled = Manager::instance().getConfigBool (IP2IP_PROFILE, ZRTP_HELLO_HASH);
86
_srtpEnabled = Manager::instance().getConfigBool (accountId, SRTP_ENABLE);
87
_keyExchangeProtocol = Manager::instance().getConfigInt (accountId, SRTP_KEY_EXCHANGE);
82
_debug ("AudioRtpFactory: Init rtp session for account %s", accountId.c_str());
84
// Manager::instance().getAccountLink (accountId);
85
Account *account = Manager::instance().getAccount (accountId);
88
_error ("AudioRtpFactory: Error no account found");
90
if (account->getType() == "SIP") {
91
SIPAccount *sipaccount = static_cast<SIPAccount *> (account);
92
_srtpEnabled = sipaccount->getSrtpEnable();
93
std::string tempkey = sipaccount->getSrtpKeyExchange();
95
if (tempkey == "sdes")
96
_keyExchangeProtocol = Sdes;
97
else if (tempkey == "zrtp")
98
_keyExchangeProtocol = Zrtp;
100
_keyExchangeProtocol = Symmetric;
88
102
_debug ("Registered account %s profile selected with key exchange protocol number %d", accountId.c_str(), _keyExchangeProtocol);
89
_helloHashEnabled = Manager::instance().getConfigBool (accountId, ZRTP_HELLO_HASH);
103
_helloHashEnabled = sipaccount->getZrtpHelloHash();
105
_srtpEnabled = false;
106
_keyExchangeProtocol = Symmetric;
107
_helloHashEnabled = false;
93
112
void AudioRtpFactory::initAudioRtpSession (SIPCall * ca)
95
114
ost::MutexLock m (_audioRtpThreadMutex);
97
_debug ("Srtp enable: %d ", _srtpEnabled);
116
_debug ("AudioRtpFactory: Srtp enable: %d ", _srtpEnabled);
98
118
if (_srtpEnabled) {
99
std::string zidFilename (Manager::instance().getConfigString (SIGNALISATION, ZRTP_ZIDFILE));
119
std::string zidFilename (Manager::instance().voipPreferences.getZidFile());
101
121
switch (_keyExchangeProtocol) {
118
_rtpSession = new AudioSrtpSession (&Manager::instance(), ca);
138
_rtpSession = new AudioSrtpSession (&Manager::instance(), ca);
119
139
_rtpSessionType = Sdes;
121
ca->getLocalSDP()->set_srtp_crypto(static_cast<AudioSrtpSession *> (_rtpSession)->getLocalCryptoInfo());
125
_debug("Unsupported Rtp Session Exception Type!");
143
_debug ("Unsupported Rtp Session Exception Type!");
126
144
throw UnsupportedRtpSessionType();
141
159
switch (_rtpSessionType) {
144
if (static_cast<AudioSrtpSession *> (_rtpSession)->startRtpThread(audiocodec) != 0) {
163
if (static_cast<AudioSrtpSession *> (_rtpSession)->startRtpThread (audiocodec) != 0) {
145
164
throw AudioRtpFactoryException ("RTP: Error: Failed to start AudioSRtpSession thread");
150
170
_debug ("Starting symmetric rtp thread");
152
if (static_cast<AudioSymmetricRtpSession *> (_rtpSession)->startRtpThread(audiocodec) != 0) {
172
if (static_cast<AudioSymmetricRtpSession *> (_rtpSession)->startRtpThread (audiocodec) != 0) {
153
173
throw AudioRtpFactoryException ("RTP: Error: Failed to start AudioSymmetricRtpSession thread");
167
188
void AudioRtpFactory::stop (void)
169
190
ost::MutexLock mutex (_audioRtpThreadMutex);
170
_info("RTP: Stopping audio rtp session");
191
_info ("RTP: Stopping audio rtp session");
172
193
if (_rtpSession == NULL) {
173
194
_debugException ("RTP: Error: _rtpSession is null when trying to stop. Returning.");
193
214
_rtpSession = NULL;
195
216
_debugException ("RTP: Error: Exception caught when stopping the audio rtp session");
196
throw AudioRtpFactoryException("RTP: Error: caught exception in AudioRtpFactory::stop");
217
throw AudioRtpFactoryException ("RTP: Error: caught exception in AudioRtpFactory::stop");
200
221
void AudioRtpFactory::updateDestinationIpAddress (void)
202
223
_info ("RTP: Updating IP address");
203
225
if (_rtpSession == NULL) {
204
226
throw AudioRtpFactoryException ("RTP: Error: _rtpSession was null when trying to update IP address");
207
229
switch (_rtpSessionType) {
210
static_cast<AudioSrtpSession *> (_rtpSession)->updateDestinationIpAddress();
232
static_cast<AudioSrtpSession *> (_rtpSession)->updateDestinationIpAddress();
214
236
static_cast<AudioSymmetricRtpSession *> (_rtpSession)->updateDestinationIpAddress();
218
static_cast<AudioZrtpSession *> (_rtpSession)->updateDestinationIpAddress();
240
static_cast<AudioZrtpSession *> (_rtpSession)->updateDestinationIpAddress();
223
245
sfl::AudioSymmetricRtpSession * AudioRtpFactory::getAudioSymetricRtpSession()
225
if ( (_rtpSessionType == Symmetric) && (_rtpSessionType != NULL)) {
226
return static_cast<AudioSymmetricRtpSession *> (_rtpSession);
228
throw AudioRtpFactoryException("RTP: Error: _rtpSession is NULL in getAudioSymetricRtpSession");
247
if ( (_rtpSessionType == Symmetric) && (_rtpSessionType != NULL)) {
248
return static_cast<AudioSymmetricRtpSession *> (_rtpSession);
250
throw AudioRtpFactoryException ("RTP: Error: _rtpSession is NULL in getAudioSymetricRtpSession");
232
254
sfl::AudioZrtpSession * AudioRtpFactory::getAudioZrtpSession()
234
256
if ( (_rtpSessionType == Zrtp) && (_rtpSessionType != NULL)) {
235
257
return static_cast<AudioZrtpSession *> (_rtpSession);
237
throw AudioRtpFactoryException("RTP: Error: _rtpSession is NULL in getAudioZrtpSession");
241
void AudioRtpFactory::setRemoteCryptoInfo(sfl::SdesNegotiator& nego)
243
if ( _rtpSession && _rtpSessionType && (_rtpSessionType == Sdes)) {
244
static_cast<AudioSrtpSession *> (_rtpSession)->setRemoteCryptoInfo(nego);
247
throw AudioRtpFactoryException("RTP: Error: _rtpSession is NULL in setRemoteCryptoInfo");
251
void AudioRtpFactory::sendDtmfDigit(int digit) {
252
switch(_rtpSessionType) {
255
static_cast<AudioSrtpSession *> (_rtpSession)->putDtmfEvent(digit);
259
static_cast<AudioSymmetricRtpSession *> (_rtpSession)->putDtmfEvent(digit);
263
static_cast<AudioZrtpSession *> (_rtpSession)->putDtmfEvent(digit);
259
throw AudioRtpFactoryException ("RTP: Error: _rtpSession is NULL in getAudioZrtpSession");
263
void sfl::AudioRtpFactory::initLocalCryptoInfo (SIPCall * ca)
265
if (_rtpSession && _rtpSessionType && (_rtpSessionType == Sdes)) {
266
static_cast<AudioSrtpSession *> (_rtpSession)->initLocalCryptoInfo ();
268
ca->getLocalSDP()->set_srtp_crypto (static_cast<AudioSrtpSession *> (_rtpSession)->getLocalCryptoInfo());
272
void AudioRtpFactory::setRemoteCryptoInfo (sfl::SdesNegotiator& nego)
274
if (_rtpSession && _rtpSessionType && (_rtpSessionType == Sdes)) {
275
static_cast<AudioSrtpSession *> (_rtpSession)->setRemoteCryptoInfo (nego);
277
throw AudioRtpFactoryException ("RTP: Error: _rtpSession is NULL in setRemoteCryptoInfo");
281
void AudioRtpFactory::sendDtmfDigit (int digit)
284
switch (_rtpSessionType) {
287
static_cast<AudioSrtpSession *> (_rtpSession)->putDtmfEvent (digit);
291
static_cast<AudioSymmetricRtpSession *> (_rtpSession)->putDtmfEvent (digit);
295
static_cast<AudioZrtpSession *> (_rtpSession)->putDtmfEvent (digit);