2 * H323 analysis addition for ethereal
6 * Copyright 2004, Iskratel, Ltd, Kranj
7 * By Miha Jemec <m.jemec@iskratel.si>
9 * Ethereal - Network traffic analyzer
10 * By Gerald Combs <gerald@ethereal.com>
11 * Copyright 1998 Gerald Combs
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 /*do not define this symbol. will be added soon*/
33 /*#define USE_CONVERSATION_GRAPH 1*/
35 #include "h323_analysis.h"
36 #include "h323_conversations.h"
37 #include "h323_conversations_dlg.h"
39 #include <epan/epan_dissect.h>
40 #include <epan/filesystem.h>
47 #include <epan/dissectors/packet-h225.h>
48 #include <epan/dissectors/packet-h245.h>
51 #include "dlg_utils.h"
53 #include "alert_box.h"
54 #include "simple_dialog.h"
57 #include "progress_dlg.h"
58 #include "compat_macros.h"
62 /****************************************************************************/
63 /* structure that holds general information about the connection */
64 typedef struct _user_data_t {
65 /* tap associated data*/
71 guint16 port_src_h245;
76 GtkWidget *label_stats;
77 GtkCList *selected_clist1;
83 static gchar *titles[7] = {
93 typedef const guint8 * ip_addr_p;
95 static gint32 last_sec = 0, last_usec = 0;
98 /****************************************************************************/
101 /****************************************************************************/
102 /* when there is a [re]reading of packet's */
104 h225_reset(void *user_data_arg _U_)
111 /****************************************************************************/
112 /* here we can redraw the output */
114 static void h225_draw(void *prs _U_)
120 static const GdkColor COLOR_DEFAULT = {0, 0xffff, 0xffff, 0xffff};
121 static const GdkColor COLOR_ERROR = {0, 0xffff, 0xbfff, 0xbfff};
122 static const GdkColor COLOR_WARNING = {0, 0xffff, 0xdfff, 0xbfff};
123 static const GdkColor COLOR_CN = {0, 0xbfff, 0xbfff, 0xffff};
125 /****************************************************************************/
126 /* append a line to clist1 */
127 static void add_to_clist1(GtkCList *clist1, guint32 number, gchar *time,
128 double delay, gchar *sideA, gboolean direction, gchar *sideB,
129 gchar *comment, GdkColor *color)
135 data[0]=&field[0][0];
136 data[1]=&field[1][0];
137 data[2]=&field[2][0];
138 data[3]=&field[3][0];
139 data[4]=&field[4][0];
140 data[5]=&field[5][0];
141 data[6]=&field[6][0];
143 g_snprintf(field[0], 32, "%u", number);
144 g_snprintf(field[1], 32, "%s", time);
145 g_snprintf(field[2], 32, "%f", delay);
146 g_snprintf(field[3], 32, "%s", sideA);
147 g_snprintf(field[4], 20, "%s", direction? "---->" : "<----");
148 g_snprintf(field[5], 32, "%s", sideB);
149 g_snprintf(field[6], 32, "%s", comment);
151 added_row = gtk_clist_append(GTK_CLIST(clist1), data);
152 gtk_clist_set_row_data(GTK_CLIST(clist1), added_row, GUINT_TO_POINTER(number));
153 gtk_clist_set_background(GTK_CLIST(clist1), added_row, color);
157 /****************************************************************************/
158 /* whenever a h225 packet is seen by the tap listener */
159 static int h225_packet(void *user_data_arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *h225info_arg)
161 user_data_t *user_data = user_data_arg;
162 const h225_packet_info *h225ptr_info = h225info_arg;
163 GdkColor color = COLOR_DEFAULT;
169 gint32 delay_sec, delay_usec;
171 /* time since beginning of capture */
172 g_snprintf(timeStr, sizeof(timeStr), "%d.%06d", pinfo->fd->rel_secs, pinfo->fd->rel_usecs);
174 /* time since previous packet seen in tap listener */
175 delay_sec = pinfo->fd->rel_secs - last_sec;
176 delay_usec = pinfo->fd->rel_usecs - last_usec;
178 delay = (double)delay_sec + ((double)delay_usec)/1000000;
180 last_sec = pinfo->fd->rel_secs;
181 last_usec = pinfo->fd->rel_usecs;
183 switch (h225ptr_info->cs_type) {
186 g_snprintf(message, sizeof(message),"H225 Setup");
188 case H225_CALL_PROCEDING:
189 g_snprintf(message, sizeof(message),"H225 Call Proceding");
192 g_snprintf(message, sizeof(message),"H225 Alerting");
195 g_snprintf(message, sizeof(message),"H225 Connect");
197 case H225_RELEASE_COMPLET:
198 g_snprintf(message, sizeof(message),"H225 Release Complet");
201 g_snprintf(message, sizeof(message),"H225 Other");
204 g_memmove(&src, pinfo->src.data, 4);
205 g_memmove(&dst, pinfo->dst.data, 4);
207 if (src == user_data->ip_src)
208 add_to_clist1(user_data->clist1,pinfo->fd->num,timeStr,delay,message, 1, "", "", &color);
210 add_to_clist1(user_data->clist1, pinfo->fd->num, timeStr,delay, "", 0, message, "", &color);
216 /****************************************************************************/
217 /* whenever a h245 packet is seen by the tap listener */
218 static int h245_packet(void *user_data_arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *h245info_arg)
221 user_data_t *user_data = user_data_arg;
222 const h245_packet_info *h245ptr_info = h245info_arg;
223 GdkColor color = COLOR_DEFAULT;
229 gint32 delay_sec, delay_usec;
231 /* time since beginning of capture */
232 g_snprintf(timeStr, sizeof(timeStr), "%d.%06d", pinfo->fd->rel_secs, pinfo->fd->rel_usecs);
234 /* time since previous packet seen in tap listener */
235 delay_sec = pinfo->fd->rel_secs - last_sec;
236 delay_usec = pinfo->fd->rel_usecs - last_usec;
238 delay = (double)delay_sec + ((double)delay_usec)/1000000;
240 last_sec = pinfo->fd->rel_secs;
241 last_usec = pinfo->fd->rel_usecs;
243 switch (h245ptr_info->msg_type) {
245 case H245_TermCapSet:
246 g_snprintf(message, sizeof(message),"H245 TermCapSet");
248 case H245_TermCapSetAck:
249 g_snprintf(message, sizeof(message),"H245_TermCapSetAck");
251 case H245_TermCapSetRjc:
252 g_snprintf(message, sizeof(message),"H245_TermCapSetRjc");
254 case H245_TermCapSetRls:
255 g_snprintf(message, sizeof(message),"H245_TermCapSetRls");
257 case H245_OpenLogChn:
258 g_snprintf(message, sizeof(message),"H245_OpenLogChn");
260 case H245_OpenLogChnCnf:
261 g_snprintf(message, sizeof(message),"H245_OpenLogChnCnf");
263 case H245_OpenLogChnAck:
264 g_snprintf(message, sizeof(message),"H245_OpenLogChnAck");
266 case H245_OpenLogChnRjc:
267 g_snprintf(message, sizeof(message),"H245_OpenLogChnRjc");
269 case H245_CloseLogChn:
270 g_snprintf(message, sizeof(message),"H245_CloseLogChn");
272 case H245_CloseLogChnAck:
273 g_snprintf(message, sizeof(message),"H245_CloseLogChnAck");
275 case H245_MastSlvDet:
276 g_snprintf(message, sizeof(message),"H245_MastSlvDet");
278 case H245_MastSlvDetAck:
279 g_snprintf(message, sizeof(message),"H245_MastSlvDetAck");
281 case H245_MastSlvDetRjc:
282 g_snprintf(message, sizeof(message),"H245_MastSlvDetRjc");
284 case H245_MastSlvDetRls:
285 g_snprintf(message, sizeof(message),"H245_MastSlvDetRls");
288 g_snprintf(message, sizeof(message),"H225 Other");
291 g_memmove(&src, pinfo->src.data, 4);
292 g_memmove(&dst, pinfo->dst.data, 4);
294 if (src == user_data->ip_src)
295 add_to_clist1(user_data->clist1,pinfo->fd->num,timeStr,delay,message, 1, "", "", &color);
297 add_to_clist1(user_data->clist1, pinfo->fd->num, timeStr,delay, "", 0, message, "", &color);
303 /**************** Callbacks *************************************************/
304 /****************************************************************************/
305 /* XXX just copied from gtk/rpc_stat.c */
306 void protect_thread_critical_region(void);
307 void unprotect_thread_critical_region(void);
310 /****************************************************************************/
311 /* close the dialog window and remove the tap listener */
312 static void on_destroy(GtkWidget *win _U_, user_data_t *user_data _U_)
317 /****************************************************************************/
318 static void on_clist_select_row(GtkCList *clist1 _U_,
322 user_data_t *user_data _U_)
324 user_data->selected_clist1 = clist1;
325 user_data->selected_row = row;
328 /****************************************************************************/
329 static void on_goto_bt_clicked(GtkWidget *bt _U_, user_data_t *user_data _U_)
333 if (user_data->selected_clist1!=NULL) {
334 fnumber = GPOINTER_TO_UINT(gtk_clist_get_row_data(
335 GTK_CLIST(user_data->selected_clist1), user_data->selected_row) );
336 goto_frame(&cfile, fnumber);
341 /****************************************************************************/
342 /* re-dissects all packets */
343 static void on_refresh_bt_clicked(GtkWidget *bt _U_, user_data_t *user_data _U_)
345 gchar filter_text_h225[256];
346 gchar filter_text_h245[256];
347 /*gchar filter_text_rtp[256];*/
349 GString *error_string;
351 /* clear the dialog box clists */
352 gtk_clist_clear(GTK_CLIST(user_data->clist1));
354 /* try to compile the filter for h225 */
355 g_snprintf(filter_text_h225,sizeof(filter_text_h225),
356 "h225 && (( ip.src==%s && %s.srcport==%u && ip.dst==%s && %s.dstport==%u ) || ( ip.src==%s && %s.srcport==%u && ip.dst==%s && %s.dstport==%u ))",
357 ip_to_str((ip_addr_p)&(user_data->ip_src)),
358 transport_prot_name[user_data->transport],
360 ip_to_str((ip_addr_p)&(user_data->ip_dst)),
361 transport_prot_name[user_data->transport],
363 ip_to_str((ip_addr_p)&(user_data->ip_dst)),
364 transport_prot_name[user_data->transport],
366 ip_to_str((ip_addr_p)&(user_data->ip_src)),
367 transport_prot_name[user_data->transport],
371 if (!dfilter_compile(filter_text_h225, &sfcode)) {
372 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, dfilter_error_msg);
376 /* try to compile the filter for h245 */
377 g_snprintf(filter_text_h245,sizeof(filter_text_h245),
378 "h245 && (( ip.src==%s && %s.srcport==%u ) || ( ip.dst==%s && %s.dstport==%u ))",
379 ip_to_str((ip_addr_p)&(user_data->ip_src_h245)),
380 transport_prot_name[user_data->transport],
381 user_data->port_src_h245,
382 ip_to_str((ip_addr_p)&(user_data->ip_src_h245)),
383 transport_prot_name[user_data->transport],
384 user_data->port_src_h245
387 if (!dfilter_compile(filter_text_h245, &sfcode)) {
388 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, dfilter_error_msg);
392 /* register tap h225 listener */
393 error_string = register_tap_listener("h225", user_data, filter_text_h225,
394 h225_reset, h225_packet, h225_draw);
395 if (error_string != NULL) {
396 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, error_string->str);
397 g_string_free(error_string, TRUE);
401 /* register tap h245 listener */
402 error_string = register_tap_listener("h245", user_data, filter_text_h245,
403 NULL, h245_packet, NULL);
404 if (error_string != NULL) {
405 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, error_string->str);
406 g_string_free(error_string, TRUE);
410 /* retap all packets */
411 retap_packets(&cfile);
413 /* remove tap listener again */
414 protect_thread_critical_region();
415 remove_tap_listener(user_data);
416 remove_tap_listener(user_data);
417 unprotect_thread_critical_region();
422 /************************************************************************************/
423 /************** Create the dialog box with all widgets ******************************/
424 void create_h225_dialog(user_data_t* user_data)
426 GtkWidget *window = NULL;
427 GtkWidget *clist_h225;
428 /*GtkWidget *label_stats;*/
432 GtkWidget *scrolled_window;
433 GtkWidget *box4, *goto_bt, *close_bt, *refresh_bt;
434 GtkTooltips *tooltips = gtk_tooltips_new();
436 gchar label_forward[150];
438 gchar str_ip_src[16];
439 gchar str_ip_dst[16];
441 /* as multiple analysis windows can be opened,
442 * don't use window_new_with_geom(), as that will place them on top of each other! */
443 window = window_new(GTK_WINDOW_TOPLEVEL, "Ethereal: H.323 VoIP Analysis");
444 gtk_window_set_default_size(GTK_WINDOW(window), 700, 350);
446 /* Container for each row of widgets */
447 main_vb = gtk_vbox_new(FALSE, 2);
448 gtk_container_add(GTK_CONTAINER(window), main_vb);
449 gtk_container_set_border_width(GTK_CONTAINER(main_vb), 2);
450 gtk_widget_show(main_vb);
452 strcpy(str_ip_src, ip_to_str((ip_addr_p)&user_data->ip_src));
453 strcpy(str_ip_dst, ip_to_str((ip_addr_p)&user_data->ip_dst));
455 g_snprintf(label_forward, 149,
456 "\nAnalysing H.323 Call between %s port %u (Side A) and %s port %u (Side B)\n",
457 str_ip_src, user_data->port_src, str_ip_dst, user_data->port_dst);
460 label = gtk_label_new(label_forward);
461 gtk_box_pack_start (GTK_BOX (main_vb), label, FALSE, FALSE, 0);
463 /* scrolled window */
464 scrolled_window = scrolled_window_new (NULL, NULL);
465 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
466 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
467 gtk_box_pack_start (GTK_BOX (main_vb), scrolled_window, TRUE, TRUE, 0);
469 /* place for some statistics */
470 /*label_stats = gtk_label_new("\n");*/
471 /*gtk_box_pack_start(GTK_BOX(main_vb), label_stats, FALSE, FALSE, 0);*/
474 clist_h225 = gtk_clist_new_with_titles(7, titles);
475 gtk_container_add(GTK_CONTAINER(scrolled_window), clist_h225);
476 gtk_widget_show(clist_h225);
477 SIGNAL_CONNECT(clist_h225, "select_row", on_clist_select_row, user_data);
479 /* column widths and justification */
480 gtk_clist_set_column_width(GTK_CLIST(clist_h225), 0, 45);
481 gtk_clist_set_column_width(GTK_CLIST(clist_h225), 1, 90);
482 gtk_clist_set_column_width(GTK_CLIST(clist_h225), 2, 90);
483 gtk_clist_set_column_width(GTK_CLIST(clist_h225), 3, 140);
484 gtk_clist_set_column_width(GTK_CLIST(clist_h225), 4, 60);
485 gtk_clist_set_column_width(GTK_CLIST(clist_h225), 5, 140);
486 gtk_clist_set_column_justification(GTK_CLIST(clist_h225), 0, GTK_JUSTIFY_CENTER);
487 gtk_clist_set_column_justification(GTK_CLIST(clist_h225), 1, GTK_JUSTIFY_CENTER);
488 gtk_clist_set_column_justification(GTK_CLIST(clist_h225), 2, GTK_JUSTIFY_CENTER);
489 gtk_clist_set_column_justification(GTK_CLIST(clist_h225), 3, GTK_JUSTIFY_LEFT);
490 gtk_clist_set_column_justification(GTK_CLIST(clist_h225), 4, GTK_JUSTIFY_CENTER);
491 gtk_clist_set_column_justification(GTK_CLIST(clist_h225), 5, GTK_JUSTIFY_LEFT);
492 gtk_clist_set_column_justification(GTK_CLIST(clist_h225), 6, GTK_JUSTIFY_CENTER);
494 gtk_widget_show(scrolled_window);
497 box4 = gtk_hbutton_box_new();
498 gtk_box_pack_start(GTK_BOX(main_vb), box4, FALSE, FALSE, 0);
499 gtk_container_set_border_width(GTK_CONTAINER(box4), 10);
500 gtk_button_box_set_layout(GTK_BUTTON_BOX (box4), GTK_BUTTONBOX_END);
501 gtk_button_box_set_spacing(GTK_BUTTON_BOX (box4), 10);
502 gtk_button_box_set_child_ipadding(GTK_BUTTON_BOX (box4), 4, 0);
503 gtk_widget_show(box4);
505 refresh_bt = BUTTON_NEW_FROM_STOCK(GTK_STOCK_REFRESH);
506 gtk_container_add(GTK_CONTAINER(box4), refresh_bt);
507 gtk_widget_show(refresh_bt);
508 SIGNAL_CONNECT(refresh_bt, "clicked", on_refresh_bt_clicked, user_data);
509 gtk_tooltips_set_tip (tooltips, refresh_bt, "Refresh data", NULL);
511 goto_bt = BUTTON_NEW_FROM_STOCK(GTK_STOCK_JUMP_TO);
512 gtk_container_add(GTK_CONTAINER(box4), goto_bt);
513 gtk_widget_show(goto_bt);
514 SIGNAL_CONNECT(goto_bt, "clicked", on_goto_bt_clicked, user_data);
515 gtk_tooltips_set_tip (tooltips, goto_bt, "Jump to the selected packet", NULL);
517 close_bt = BUTTON_NEW_FROM_STOCK(GTK_STOCK_CLOSE);
518 gtk_container_add(GTK_CONTAINER(box4), close_bt);
519 GTK_WIDGET_SET_FLAGS(close_bt, GTK_CAN_DEFAULT);
520 gtk_widget_show(close_bt);
521 gtk_tooltips_set_tip (tooltips, close_bt, "Close this dialog", NULL);
522 window_set_cancel_button(window, close_bt, window_cancel_button_cb);
524 SIGNAL_CONNECT(window, "delete_event", window_delete_event_cb, NULL);
525 SIGNAL_CONNECT(window, "destroy", on_destroy, user_data);
527 gtk_widget_show_all(window);
528 window_present(window);
530 /* some widget references need to be saved for outside use */
531 user_data->window = window;
532 user_data->clist1 = GTK_CLIST(clist_h225);
533 user_data->label_stats = label;
534 user_data->selected_clist1 = GTK_CLIST(clist_h225);
535 user_data->selected_row = 0;
539 /****************************************************************************/
546 guint16 port_src_h245,
550 user_data_t *user_data;
553 user_data = g_malloc(sizeof(user_data_t));
555 user_data->ip_src = ip_src;
556 user_data->port_src = port_src;
557 user_data->ip_dst = ip_dst;
558 user_data->port_dst = port_dst;
559 user_data->ip_src_h245 = ip_src_h245;
560 user_data->port_src_h245 = port_src_h245;
561 user_data->transport = transport;
563 /* create the dialog box */
564 create_h225_dialog(user_data);
566 /* proceed as if the Refresh button would have been pressed */
567 on_refresh_bt_clicked(NULL, user_data);