Browse code

core:zrtp: separate out ZRTP protocol description

Stefan Sayer authored on 03/11/2014 16:45:30
Showing 4 changed files
... ...
@@ -772,6 +772,13 @@ void AmRtpStream::pause()
772 772
 {
773 773
   DBG("RTP Stream instance [%p] pausing (receiving=false)\n", this);
774 774
   receiving = false;
775
+
776
+#ifdef WITH_ZRTP
777
+  if (session && session->enable_zrtp) {
778
+    session->zrtp_session_state.stopStreams();
779
+  }
780
+#endif
781
+
775 782
 }
776 783
 
777 784
 void AmRtpStream::resume()
... ...
@@ -783,6 +790,12 @@ void AmRtpStream::resume()
783 783
   receive_buf.clear();
784 784
   receive_mut.unlock();
785 785
   receiving = true;
786
+
787
+#ifdef WITH_ZRTP
788
+  if (session && session->enable_zrtp) {
789
+    session->zrtp_session_state.startStreams(get_ssrc());
790
+  }
791
+#endif
786 792
 }
787 793
 
788 794
 void AmRtpStream::setOnHold(bool on_hold) {
... ...
@@ -97,11 +97,6 @@ AmSession::~AmSession()
97 97
       delete *evh;
98 98
   }
99 99
 
100
-#ifdef WITH_ZRTP
101
-  if (enable_zrtp)
102
-    zrtp_session_state.freeSession();
103
-#endif
104
-
105 100
   delete dlg;
106 101
 
107 102
   DBG("AmSession destructor finished\n");
... ...
@@ -434,6 +429,12 @@ void AmSession::finalize()
434 434
   DBG("running finalize sequence...\n");
435 435
   dlg->finalize();
436 436
   
437
+#ifdef WITH_ZRTP
438
+  if (enable_zrtp) {
439
+    zrtp_session_state.freeSession();
440
+  }
441
+#endif
442
+
437 443
   onBeforeDestroy();
438 444
   destroy();
439 445
   
... ...
@@ -1247,23 +1248,9 @@ bool AmSession::removeTimers() {
1247 1247
 #ifdef WITH_ZRTP
1248 1248
 
1249 1249
 void AmSession::onZRTPProtocolEvent(zrtp_protocol_event_t event, zrtp_stream_t *stream_ctx) {
1250
-  DBG("AmSession::onZRTPProtocolEvent\n");
1251
-  switch (event)
1252
-    {
1253
-    case ZRTP_EVENT_UNSUPPORTED:
1254
-      INFO("ZRTP_EVENT_UNSUPPORTED\n");
1255
-      break;
1256
-    case ZRTP_EVENT_IS_CLEAR:
1257
-      INFO("ZRTP_EVENT_IS_CLEAR\n");
1258
-      break;
1259
-    case ZRTP_EVENT_IS_INITIATINGSECURE:
1260
-      INFO("ZRTP_EVENT_IS_INITIATINGSECURE\n");
1261
-      break;
1262
-    case ZRTP_EVENT_IS_PENDINGSECURE:
1263
-      INFO("ZRTP_EVENT_PENDINGSECURE\n");
1264
-      break;
1250
+  DBG("AmSession::onZRTPProtocolEvent: %s\n", zrtp_protocol_event_desc(event));
1265 1251
 
1266
-    case ZRTP_EVENT_IS_SECURE: {
1252
+  if (event==ZRTP_EVENT_IS_SECURE) {
1267 1253
       INFO("ZRTP_EVENT_IS_SECURE \n");
1268 1254
       //         info->is_verified  = ctx->_session_ctx->secrets.verifieds & ZRTP_BIT_RS0;
1269 1255
  
... ...
@@ -1275,66 +1262,19 @@ void AmSession::onZRTPProtocolEvent(zrtp_protocol_event_t event, zrtp_stream_t *
1275 1275
       // 	DBG("Got SAS values SAS1 '%s' and SAS2 '%s'\n", 
1276 1276
       // 	    session->sas_values.str1.buffer,
1277 1277
       // 	    session->sas_values.str2.buffer);
1278
-      // } 
1279
-    } break;
1278
+      // }
1279
+  }
1280 1280
  
1281
-    case ZRTP_EVENT_IS_PENDINGCLEAR:
1282
-      INFO("ZRTP_EVENT_IS_PENDINGCLEAR\n");
1283
-      INFO("other side requested goClear. Going clear.\n\n");
1284
-      //      zrtp_clear_stream(zrtp_audio);
1285
-      break;
1281
+    // case ZRTP_EVENT_IS_PENDINGCLEAR:
1282
+    //   INFO("ZRTP_EVENT_IS_PENDINGCLEAR\n");
1283
+    //   INFO("other side requested goClear. Going clear.\n\n");
1284
+    //   //      zrtp_clear_stream(zrtp_audio);
1285
+    //   break;
1286 1286
   
1287
-    case ZRTP_EVENT_IS_SECURE_DONE:
1288
-      INFO("ZRTP_EVENT_IS_SECURE_DONE\n");
1289
-      break;
1290
-    case ZRTP_EVENT_NO_ZRTP:
1291
-      INFO("ZRTP_EVENT_NO_ZRTP\n");
1292
-      break;
1293
-    case ZRTP_EVENT_NO_ZRTP_QUICK:
1294
-      INFO("ZRTP_EVENT_NO_ZRTP_QUICK\n");
1295
-      break;
1296
- 
1297
-      // pbx functions
1298
-    case ZRTP_EVENT_IS_CLIENT_ENROLLMENT:
1299
-      INFO("ZRTP_EVENT_IS_CLIENT_ENROLLMENT\n");
1300
-      break;
1301
-    case ZRTP_EVENT_NEW_USER_ENROLLED:
1302
-      INFO("ZRTP_EVENT_NEW_USER_ENROLLED\n");
1303
-      break;
1304
-    case ZRTP_EVENT_USER_ALREADY_ENROLLED:
1305
-      INFO("ZRTP_EVENT_USER_ALREADY_ENROLLED\n");
1306
-      break;
1307
-    case ZRTP_EVENT_USER_UNENROLLED:
1308
-      INFO("ZRTP_EVENT_USER_UNENROLLED\n");
1309
-      break;
1310
-    case ZRTP_EVENT_LOCAL_SAS_UPDATED:
1311
-      INFO("ZRTP_EVENT_LOCAL_SAS_UPDATED\n");
1312
-      break;
1313
-    case ZRTP_EVENT_REMOTE_SAS_UPDATED:
1314
-      INFO("ZRTP_EVENT_REMOTE_SAS_UPDATED\n");
1315
-      break;
1316
- 
1317
-      // errors
1318
-    case ZRTP_EVENT_WRONG_SIGNALING_HASH:
1319
-      INFO("ZRTP_EVENT_WRONG_SIGNALING_HASH\n");
1320
-      break;
1321
-    case ZRTP_EVENT_WRONG_MESSAGE_HMAC:
1322
-      INFO("ZRTP_EVENT_WRONG_MESSAGE_HMAC\n");
1323
-      break;
1324
-
1325
-    case ZRTP_EVENT_IS_PASSIVE_RESTRICTION:
1326
-     INFO("ZRTP_EVENT_IS_PASSIVE_RESTRICTION\n");
1327
-      break;
1328
-
1329
-    default: 
1330
-      INFO("unknown ZRTP_EVENT\n");
1331
-      break;
1332
-    } // end events case
1333 1287
 }
1334 1288
 
1335 1289
 void AmSession::onZRTPSecurityEvent(zrtp_security_event_t event, zrtp_stream_t *stream_ctx) {
1336
-  DBG("AmSession::onZRTPSecurityEvent\n");
1337
-
1290
+  DBG("AmSession::onZRTPSecurityEvent: %s\n", zrtp_security_event_desc(event));
1338 1291
 }
1339 1292
  
1340 1293
 #endif
... ...
@@ -192,6 +192,9 @@ int AmZRTPSessionState::initSession(AmSession* session) {
192 192
 }
193 193
 
194 194
 int AmZRTPSessionState::startStreams(uint32_t ssrc){
195
+  if (NULL == zrtp_audio)
196
+    return -1;
197
+
195 198
   zrtp_status_t status = zrtp_stream_start(zrtp_audio, ssrc);
196 199
   if (zrtp_status_ok != status) {
197 200
     ERROR("starting ZRTP stream\n");
... ...
@@ -201,6 +204,9 @@ int AmZRTPSessionState::startStreams(uint32_t ssrc){
201 201
 }
202 202
 
203 203
 int AmZRTPSessionState::stopStreams(){
204
+  if (NULL == zrtp_audio)
205
+    return -1;
206
+
204 207
   zrtp_status_t status = zrtp_stream_stop(zrtp_audio);
205 208
   if (zrtp_status_ok != status) {
206 209
     ERROR("stopping ZRTP stream\n");
... ...
@@ -297,4 +303,38 @@ void AmZRTP::on_zrtp_protocol_event(zrtp_stream_t *stream, zrtp_protocol_event_t
297 297
   sess->postEvent(new AmZRTPProtocolEvent(event, stream));
298 298
 }
299 299
 
300
+const char* zrtp_protocol_event_desc(zrtp_protocol_event_t e) {
301
+  switch (e) {
302
+  case ZRTP_EVENT_UNSUPPORTED: return "ZRTP_EVENT_UNSUPPORTED";
303
+
304
+  case ZRTP_EVENT_IS_CLEAR: return "ZRTP_EVENT_IS_CLEAR";
305
+  case ZRTP_EVENT_IS_INITIATINGSECURE: return "ZRTP_EVENT_IS_INITIATINGSECURE";
306
+  case ZRTP_EVENT_IS_PENDINGSECURE: return "ZRTP_EVENT_IS_PENDINGSECURE";
307
+  case ZRTP_EVENT_IS_PENDINGCLEAR: return "ZRTP_EVENT_IS_PENDINGCLEAR";
308
+  case ZRTP_EVENT_NO_ZRTP: return "ZRTP_EVENT_NO_ZRTP";
309
+  case ZRTP_EVENT_NO_ZRTP_QUICK: return "ZRTP_EVENT_NO_ZRTP_QUICK";
310
+  case ZRTP_EVENT_IS_CLIENT_ENROLLMENT: return "ZRTP_EVENT_IS_CLIENT_ENROLLMENT";
311
+  case ZRTP_EVENT_NEW_USER_ENROLLED: return "ZRTP_EVENT_NEW_USER_ENROLLED";
312
+  case ZRTP_EVENT_USER_ALREADY_ENROLLED: return "ZRTP_EVENT_USER_ALREADY_ENROLLED";
313
+  case ZRTP_EVENT_USER_UNENROLLED: return "ZRTP_EVENT_USER_UNENROLLED";
314
+  case ZRTP_EVENT_LOCAL_SAS_UPDATED: return "ZRTP_EVENT_LOCAL_SAS_UPDATED";
315
+  case ZRTP_EVENT_REMOTE_SAS_UPDATED: return "ZRTP_EVENT_REMOTE_SAS_UPDATED";
316
+  case ZRTP_EVENT_IS_SECURE: return "ZRTP_EVENT_IS_SECURE";
317
+  case ZRTP_EVENT_IS_SECURE_DONE: return "ZRTP_EVENT_IS_SECURE_DONE";
318
+  case ZRTP_EVENT_IS_PASSIVE_RESTRICTION: return "ZRTP_EVENT_IS_PASSIVE_RESTRICTION";
319
+  case ZRTP_EVENT_COUNT: return "ZRTP_EVENT_COUNT"; // ?
320
+  default:    return "UNKNOWN_ZRTP_PROTOCOL_EVENT";
321
+  }
322
+};
323
+
324
+const char* zrtp_security_event_desc(zrtp_security_event_t e) {
325
+  switch (e) {
326
+  case ZRTP_EVENT_PROTOCOL_ERROR: return "ZRTP_EVENT_PROTOCOL_ERROR";
327
+  case ZRTP_EVENT_WRONG_SIGNALING_HASH: return "ZRTP_EVENT_WRONG_SIGNALING_HASH";
328
+  case ZRTP_EVENT_WRONG_MESSAGE_HMAC: return "ZRTP_EVENT_WRONG_MESSAGE_HMAC";
329
+  case ZRTP_EVENT_MITM_WARNING: return "ZRTP_EVENT_MITM_WARNING";
330
+  default:    return "UNKNOWN_ZRTP_SECURITY_EVENT";
331
+  }
332
+}
333
+
300 334
 #endif
... ...
@@ -86,6 +86,10 @@ struct AmZRTPSessionState {
86 86
   zrtp_session_t* zrtp_session; // ZRTP session
87 87
   zrtp_stream_t*  zrtp_audio;   // ZRTP stream for audio
88 88
 };
89
+
90
+const char* zrtp_protocol_event_desc(zrtp_protocol_event_t e);
91
+const char* zrtp_security_event_desc(zrtp_security_event_t e);
92
+
89 93
  
90 94
 #if defined(__cplusplus)
91 95
 extern "C" {