3 * Copyright 2004, Michael Lum <mlum [AT] telostech.com>
4 * In association with Telos Technology Inc.
6 * Modified from gsm_map_stat.c
10 * Wireshark - Network traffic analyzer
11 * By Gerald Combs <gerald@wireshark.org>
12 * Copyright 1998 Gerald Combs
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 * This TAP provides statistics for MTP3:
40 #include "epan/packet_info.h"
41 #include "epan/epan.h"
42 #include "epan/value_string.h"
43 #include <epan/stat_cmd_args.h>
44 #include "../stat_menu.h"
45 #include "gui_stat_menu.h"
46 #include "image/clist_ascend.xpm"
47 #include "image/clist_descend.xpm"
48 #include "simple_dialog.h"
49 #include "dlg_utils.h"
51 #include <epan/emem.h>
52 #include "../register.h"
53 #include "../globals.h"
54 #include "filter_dlg.h"
55 #include "compat_macros.h"
56 #include "gui_utils.h"
58 #include <epan/dissectors/packet-mtp3.h>
59 #include "mtp3_stat.h"
61 typedef struct column_arrows {
64 GtkWidget *descend_pm;
67 #define MTP3_INIT_TABLE_NUM_COLUMNS 6
69 typedef struct _my_columns_t {
72 GtkJustification just;
75 static my_columns_t columns[MTP3_INIT_TABLE_NUM_COLUMNS] = {
76 { 80, "OPC", GTK_JUSTIFY_LEFT },
77 { 80, "DPC", GTK_JUSTIFY_LEFT },
78 { 110, "SI", GTK_JUSTIFY_LEFT },
79 { 80, "Num MSUs", GTK_JUSTIFY_RIGHT },
80 { 100, "Num Bytes", GTK_JUSTIFY_RIGHT },
81 { 80, "Avg Bytes", GTK_JUSTIFY_RIGHT }
84 typedef struct _mtp3_stat_dlg_t {
86 GtkWidget *scrolled_win;
88 char *entries[MTP3_INIT_TABLE_NUM_COLUMNS];
91 static mtp3_stat_dlg_t dlg;
93 mtp3_stat_t mtp3_stat[MTP3_MAX_NUM_OPC_DPC];
101 mtp3_stat_t (*stat_p)[MTP3_MAX_NUM_OPC_DPC] = tapdata;
104 memset(stat_p, 0, MTP3_MAX_NUM_OPC_DPC * sizeof(mtp3_stat_t));
108 gtk_clist_clear(GTK_CLIST(dlg.table));
116 packet_info *pinfo _U_,
117 epan_dissect_t *edt _U_,
120 mtp3_stat_t (*stat_p)[MTP3_MAX_NUM_OPC_DPC] = tapdata;
121 const mtp3_tap_rec_t *data_p = data;
124 if (data_p->si_code >= MTP3_NUM_SI_CODE)
127 * we thought this si_code was not used ?
128 * is MTP3_NUM_SI_CODE out of date ?
134 * look for opc/dpc pair
137 while (i < mtp3_num_used)
139 if (memcmp(&data_p->addr_opc, &(*stat_p)[i].addr_opc, sizeof(mtp3_addr_pc_t)) == 0)
141 if (memcmp(&data_p->addr_dpc, &(*stat_p)[i].addr_dpc, sizeof(mtp3_addr_pc_t)) == 0)
150 if (i == mtp3_num_used)
152 if (mtp3_num_used == MTP3_MAX_NUM_OPC_DPC)
163 (*stat_p)[i].addr_opc = data_p->addr_opc;
164 (*stat_p)[i].addr_dpc = data_p->addr_dpc;
165 (*stat_p)[i].si_code[data_p->si_code].num_msus++;
166 (*stat_p)[i].si_code[data_p->si_code].size += data_p->size;
176 mtp3_stat_t (*stat_p)[MTP3_MAX_NUM_OPC_DPC] = tapdata;
177 int i, j, row_offset;
180 if (!dlg.win || !tapdata)
188 while (i < mtp3_num_used)
190 row_offset = i * MTP3_NUM_SI_CODE;
192 mtp3_addr_to_str_buf((guint8 *) &(*stat_p)[i].addr_opc, str, 256);
193 dlg.entries[0] = g_strdup(str);
195 mtp3_addr_to_str_buf((guint8 *) &(*stat_p)[i].addr_dpc, str, 256);
196 dlg.entries[1] = g_strdup(str);
198 for (j=0; j < MTP3_NUM_SI_CODE; j++)
200 dlg.entries[2] = g_strdup(mtp3_service_indicator_code_short_vals[j].strptr);
202 dlg.entries[3] = g_strdup_printf("%u", (*stat_p)[i].si_code[j].num_msus);
204 dlg.entries[4] = g_strdup_printf("%.0f", (*stat_p)[i].si_code[j].size);
207 g_strdup_printf("%.2f",
208 (*stat_p)[i].si_code[j].size/(*stat_p)[i].si_code[j].num_msus);
210 gtk_clist_insert(GTK_CLIST(dlg.table), row_offset + j, dlg.entries);
216 gtk_clist_sort(GTK_CLIST(dlg.table));
221 mtp3_stat_gtk_click_column_cb(
226 column_arrows *col_arrows = (column_arrows *) data;
230 gtk_clist_freeze(clist);
232 for (i=0; i < MTP3_INIT_TABLE_NUM_COLUMNS; i++)
234 gtk_widget_hide(col_arrows[i].ascend_pm);
235 gtk_widget_hide(col_arrows[i].descend_pm);
238 if (column == clist->sort_column)
240 if (clist->sort_type == GTK_SORT_ASCENDING)
242 clist->sort_type = GTK_SORT_DESCENDING;
243 gtk_widget_show(col_arrows[column].descend_pm);
247 clist->sort_type = GTK_SORT_ASCENDING;
248 gtk_widget_show(col_arrows[column].ascend_pm);
254 * Columns 0-1 sorted in descending order by default
258 clist->sort_type = GTK_SORT_ASCENDING;
259 gtk_widget_show(col_arrows[column].ascend_pm);
263 clist->sort_type = GTK_SORT_DESCENDING;
264 gtk_widget_show(col_arrows[column].descend_pm);
267 gtk_clist_set_sort_column(clist, column);
270 gtk_clist_thaw(clist);
271 gtk_clist_sort(clist);
276 mtp3_stat_gtk_sort_column(
281 const GtkCListRow *row1 = ptr1;
282 const GtkCListRow *row2 = ptr2;
287 text1 = GTK_CELL_TEXT(row1->cell[clist->sort_column])->text;
288 text2 = GTK_CELL_TEXT(row2->cell[clist->sort_column])->text;
290 switch (clist->sort_column)
296 return(strcmp(text1, text2));
300 i1 = strtol(text1, NULL, 0);
301 i2 = strtol(text2, NULL, 0);
305 g_assert_not_reached();
312 mtp3_stat_gtk_win_destroy_cb(
314 gpointer user_data _U_)
316 memset((void *) user_data, 0, sizeof(mtp3_stat_dlg_t));
321 mtp3_stat_gtk_win_create(
322 mtp3_stat_dlg_t *dlg_p,
326 column_arrows *col_arrows;
327 GtkWidget *column_lb;
333 dlg_p->win = window_new(GTK_WINDOW_TOPLEVEL, title);
334 gtk_window_set_default_size(GTK_WINDOW(dlg_p->win), 640, 390);
336 vbox = gtk_vbox_new(FALSE, 3);
337 gtk_container_add(GTK_CONTAINER(dlg_p->win), vbox);
338 gtk_container_set_border_width(GTK_CONTAINER(vbox), 12);
340 dlg_p->scrolled_win = scrolled_window_new(NULL, NULL);
341 gtk_box_pack_start(GTK_BOX(vbox), dlg_p->scrolled_win, TRUE, TRUE, 0);
343 dlg_p->table = gtk_clist_new(MTP3_INIT_TABLE_NUM_COLUMNS);
346 (column_arrows *) g_malloc(sizeof(column_arrows) * MTP3_INIT_TABLE_NUM_COLUMNS);
348 for (i = 0; i < MTP3_INIT_TABLE_NUM_COLUMNS; i++)
350 col_arrows[i].table = gtk_table_new(2, 2, FALSE);
352 gtk_table_set_col_spacings(GTK_TABLE(col_arrows[i].table), 5);
354 column_lb = gtk_label_new(columns[i].strptr);
356 gtk_table_attach(GTK_TABLE(col_arrows[i].table), column_lb,
357 0, 1, 0, 2, GTK_SHRINK, GTK_SHRINK, 0, 0);
359 gtk_widget_show(column_lb);
361 col_arrows[i].ascend_pm = xpm_to_widget(clist_ascend_xpm);
363 gtk_table_attach(GTK_TABLE(col_arrows[i].table), col_arrows[i].ascend_pm,
364 1, 2, 1, 2, GTK_SHRINK, GTK_SHRINK, 0, 0);
366 col_arrows[i].descend_pm = xpm_to_widget(clist_descend_xpm);
368 gtk_table_attach(GTK_TABLE(col_arrows[i].table), col_arrows[i].descend_pm,
369 1, 2, 0, 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
373 /* default column sorting */
374 gtk_widget_show(col_arrows[i].ascend_pm);
377 gtk_clist_set_column_justification(GTK_CLIST(dlg_p->table), i, columns[i].just);
379 gtk_clist_set_column_widget(GTK_CLIST(dlg_p->table), i, col_arrows[i].table);
380 gtk_widget_show(col_arrows[i].table);
382 gtk_clist_column_titles_show(GTK_CLIST(dlg_p->table));
384 gtk_clist_set_compare_func(GTK_CLIST(dlg_p->table), mtp3_stat_gtk_sort_column);
385 gtk_clist_set_sort_column(GTK_CLIST(dlg_p->table), 0);
386 gtk_clist_set_sort_type(GTK_CLIST(dlg_p->table), GTK_SORT_ASCENDING);
388 for (i = 0; i < MTP3_INIT_TABLE_NUM_COLUMNS; i++)
390 gtk_clist_set_column_width(GTK_CLIST(dlg_p->table), i, columns[i].value);
393 gtk_clist_set_shadow_type(GTK_CLIST(dlg_p->table), GTK_SHADOW_IN);
394 gtk_clist_column_titles_show(GTK_CLIST(dlg_p->table));
395 gtk_container_add(GTK_CONTAINER(dlg_p->scrolled_win), dlg_p->table);
397 SIGNAL_CONNECT(dlg_p->table, "click-column", mtp3_stat_gtk_click_column_cb, col_arrows);
400 bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
401 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
403 bt_close = OBJECT_GET_DATA(bbox, GTK_STOCK_CLOSE);
404 window_set_cancel_button(dlg_p->win, bt_close, window_cancel_button_cb);
406 SIGNAL_CONNECT(dlg_p->win, "delete_event", window_delete_event_cb, NULL);
407 SIGNAL_CONNECT(dlg_p->win, "destroy", mtp3_stat_gtk_win_destroy_cb, dlg_p);
409 gtk_widget_show_all(dlg_p->win);
410 window_present(dlg_p->win);
421 * if the window is already open, bring it to front
425 gdk_window_raise(dlg.win->window);
429 mtp3_stat_gtk_win_create(&dlg, "MTP3 Statistics");
431 mtp3_stat_draw(NULL);
436 mtp3_stat_gtk_init( const char *optarg _U_, void* userdata _U_)
438 mtp3_stat_gtk_cb(NULL, NULL);
443 register_tap_listener_gtkmtp3_stat(void)
448 memset((void *) &mtp3_stat, 0, sizeof(mtp3_stat_t));
451 register_tap_listener("mtp3", &mtp3_stat, NULL,
458 simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK, err_p->str);
459 g_string_free(err_p, TRUE);
464 register_stat_menu_item("MTP3/MSUs", REGISTER_STAT_GROUP_TELEPHONY,
465 mtp3_stat_gtk_cb, NULL, NULL, NULL);
466 register_stat_cmd_arg("mtp3,msus", mtp3_stat_gtk_init,NULL);