3 * Copyright 2004, Michael Lum <mlum [AT] telostech.com>
4 * In association with Telos Technology Inc.
6 * Modified from gsm_map_stat.c
10 * Ethereal - Network traffic analyzer
11 * By Gerald Combs <gerald@ethereal.com>
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"
44 #include "image/clist_ascend.xpm"
45 #include "image/clist_descend.xpm"
46 #include "simple_dialog.h"
47 #include "dlg_utils.h"
49 #include "../register.h"
50 #include "../globals.h"
51 #include "filter_prefs.h"
52 #include "compat_macros.h"
55 #include "packet-mtp3.h"
56 #include "mtp3_stat.h"
58 typedef struct column_arrows {
61 GtkWidget *descend_pm;
64 #define MTP3_INIT_TABLE_NUM_COLUMNS 6
66 typedef struct _my_columns_t {
69 GtkJustification just;
72 static my_columns_t columns[MTP3_INIT_TABLE_NUM_COLUMNS] = {
73 { 80, "OPC", GTK_JUSTIFY_LEFT },
74 { 80, "DPC", GTK_JUSTIFY_LEFT },
75 { 110, "SI", GTK_JUSTIFY_LEFT },
76 { 80, "Num MSUs", GTK_JUSTIFY_RIGHT },
77 { 100, "Num Bytes", GTK_JUSTIFY_RIGHT },
78 { 80, "Avg Bytes", GTK_JUSTIFY_RIGHT }
81 typedef struct _mtp3_stat_dlg_t {
83 GtkWidget *scrolled_win;
85 char *entries[MTP3_INIT_TABLE_NUM_COLUMNS];
88 static mtp3_stat_dlg_t dlg;
90 mtp3_stat_t mtp3_stat[MTP3_MAX_NUM_OPC_DPC];
101 memset((void *) mtp3_stat, 0, MTP3_MAX_NUM_OPC_DPC * sizeof(mtp3_stat_t));
105 gtk_clist_clear(GTK_CLIST(dlg.table));
114 epan_dissect_t *edt _U_,
117 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, &mtp3_stat[i].addr_opc, sizeof(mtp3_addr_pc_t)) == 0)
141 if (memcmp(&data_p->addr_dpc, &mtp3_stat[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 mtp3_stat[i].addr_opc = data_p->addr_opc;
164 mtp3_stat[i].addr_dpc = data_p->addr_dpc;
165 mtp3_stat[i].si_code[data_p->si_code].num_msus++;
166 mtp3_stat[i].si_code[data_p->si_code].size += data_p->size;
176 int i, j, row_offset;
189 while (i < mtp3_num_used)
191 row_offset = i * MTP3_NUM_SI_CODE;
193 mtp3_addr_to_str_buf((guint8 *) &mtp3_stat[i].addr_opc, str);
194 dlg.entries[0] = g_strdup(str);
196 mtp3_addr_to_str_buf((guint8 *) &mtp3_stat[i].addr_dpc, str);
197 dlg.entries[1] = g_strdup(str);
199 for (j=0; j < MTP3_NUM_SI_CODE; j++)
201 dlg.entries[2] = g_strdup(mtp3_service_indicator_code_short_vals[j].strptr);
203 dlg.entries[3] = g_strdup_printf("%u", mtp3_stat[i].si_code[j].num_msus);
205 dlg.entries[4] = g_strdup_printf("%.0f", mtp3_stat[i].si_code[j].size);
208 g_strdup_printf("%.2f",
209 mtp3_stat[i].si_code[j].size/mtp3_stat[i].si_code[j].num_msus);
211 gtk_clist_insert(GTK_CLIST(dlg.table), row_offset + j, dlg.entries);
217 gtk_clist_sort(GTK_CLIST(dlg.table));
222 mtp3_stat_gtk_click_column_cb(
227 column_arrows *col_arrows = (column_arrows *) data;
231 gtk_clist_freeze(clist);
233 for (i=0; i < MTP3_INIT_TABLE_NUM_COLUMNS; i++)
235 gtk_widget_hide(col_arrows[i].ascend_pm);
236 gtk_widget_hide(col_arrows[i].descend_pm);
239 if (column == clist->sort_column)
241 if (clist->sort_type == GTK_SORT_ASCENDING)
243 clist->sort_type = GTK_SORT_DESCENDING;
244 gtk_widget_show(col_arrows[column].descend_pm);
248 clist->sort_type = GTK_SORT_ASCENDING;
249 gtk_widget_show(col_arrows[column].ascend_pm);
255 * Columns 0-1 sorted in descending order by default
259 clist->sort_type = GTK_SORT_ASCENDING;
260 gtk_widget_show(col_arrows[column].ascend_pm);
264 clist->sort_type = GTK_SORT_DESCENDING;
265 gtk_widget_show(col_arrows[column].descend_pm);
268 gtk_clist_set_sort_column(clist, column);
271 gtk_clist_thaw(clist);
272 gtk_clist_sort(clist);
277 mtp3_stat_gtk_sort_column(
282 GtkCListRow *row1 = (GtkCListRow *) ptr1;
283 GtkCListRow *row2 = (GtkCListRow *) ptr2;
288 text1 = GTK_CELL_TEXT(row1->cell[clist->sort_column])->text;
289 text2 = GTK_CELL_TEXT(row2->cell[clist->sort_column])->text;
291 switch (clist->sort_column)
297 return(strcmp(text1, text2));
301 i1 = strtol(text1, NULL, 0);
302 i2 = strtol(text2, NULL, 0);
306 g_assert_not_reached();
313 mtp3_stat_gtk_win_destroy_cb(
315 gpointer user_data _U_)
317 memset((void *) user_data, 0, sizeof(mtp3_stat_dlg_t));
322 mtp3_stat_gtk_win_create(
323 mtp3_stat_dlg_t *dlg_p,
327 column_arrows *col_arrows;
328 GtkWidget *column_lb;
334 dlg_p->win = window_new(GTK_WINDOW_TOPLEVEL, title);
335 gtk_window_set_default_size(GTK_WINDOW(dlg_p->win), 640, 390);
337 vbox = gtk_vbox_new(FALSE, 3);
338 gtk_container_add(GTK_CONTAINER(dlg_p->win), vbox);
339 gtk_container_set_border_width(GTK_CONTAINER(vbox), 12);
341 dlg_p->scrolled_win = scrolled_window_new(NULL, NULL);
342 gtk_box_pack_start(GTK_BOX(vbox), dlg_p->scrolled_win, TRUE, TRUE, 0);
344 dlg_p->table = gtk_clist_new(MTP3_INIT_TABLE_NUM_COLUMNS);
347 (column_arrows *) g_malloc(sizeof(column_arrows) * MTP3_INIT_TABLE_NUM_COLUMNS);
349 for (i = 0; i < MTP3_INIT_TABLE_NUM_COLUMNS; i++)
351 col_arrows[i].table = gtk_table_new(2, 2, FALSE);
353 gtk_table_set_col_spacings(GTK_TABLE(col_arrows[i].table), 5);
355 column_lb = gtk_label_new(columns[i].strptr);
357 gtk_table_attach(GTK_TABLE(col_arrows[i].table), column_lb,
358 0, 1, 0, 2, GTK_SHRINK, GTK_SHRINK, 0, 0);
360 gtk_widget_show(column_lb);
362 col_arrows[i].ascend_pm = xpm_to_widget(clist_ascend_xpm);
364 gtk_table_attach(GTK_TABLE(col_arrows[i].table), col_arrows[i].ascend_pm,
365 1, 2, 1, 2, GTK_SHRINK, GTK_SHRINK, 0, 0);
367 col_arrows[i].descend_pm = xpm_to_widget(clist_descend_xpm);
369 gtk_table_attach(GTK_TABLE(col_arrows[i].table), col_arrows[i].descend_pm,
370 1, 2, 0, 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
374 /* default column sorting */
375 gtk_widget_show(col_arrows[i].ascend_pm);
378 gtk_clist_set_column_justification(GTK_CLIST(dlg_p->table), i, columns[i].just);
380 gtk_clist_set_column_widget(GTK_CLIST(dlg_p->table), i, col_arrows[i].table);
381 gtk_widget_show(col_arrows[i].table);
383 gtk_clist_column_titles_show(GTK_CLIST(dlg_p->table));
385 gtk_clist_set_compare_func(GTK_CLIST(dlg_p->table), mtp3_stat_gtk_sort_column);
386 gtk_clist_set_sort_column(GTK_CLIST(dlg_p->table), 0);
387 gtk_clist_set_sort_type(GTK_CLIST(dlg_p->table), GTK_SORT_ASCENDING);
389 for (i = 0; i < MTP3_INIT_TABLE_NUM_COLUMNS; i++)
391 gtk_clist_set_column_width(GTK_CLIST(dlg_p->table), i, columns[i].value);
394 gtk_clist_set_shadow_type(GTK_CLIST(dlg_p->table), GTK_SHADOW_IN);
395 gtk_clist_column_titles_show(GTK_CLIST(dlg_p->table));
396 gtk_container_add(GTK_CONTAINER(dlg_p->scrolled_win), dlg_p->table);
398 SIGNAL_CONNECT(dlg_p->table, "click-column", mtp3_stat_gtk_click_column_cb, col_arrows);
401 bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
402 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
404 bt_close = OBJECT_GET_DATA(bbox, GTK_STOCK_CLOSE);
405 window_set_cancel_button(dlg_p->win, bt_close, window_cancel_button_cb);
407 SIGNAL_CONNECT(dlg_p->win, "delete_event", window_delete_event_cb, NULL);
408 SIGNAL_CONNECT(dlg_p->win, "destroy", mtp3_stat_gtk_win_destroy_cb, dlg_p);
410 gtk_widget_show_all(dlg_p->win);
411 window_present(dlg_p->win);
416 * Never gets called ?
422 /* does not appear to be called */
435 * if the window is already open, bring it to front
439 gdk_window_raise(dlg.win->window);
443 mtp3_stat_gtk_win_create(&dlg, "MTP3 Statistics");
445 mtp3_stat_draw(NULL);
450 register_tap_listener_gtkmtp3_stat(void)
455 register_ethereal_tap("mtp3,", mtp3_stat_gtk_init);
457 memset((void *) &mtp3_stat, 0, sizeof(mtp3_stat_t));
460 register_tap_listener("mtp3", NULL, NULL,
467 simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK, err_p->str);
468 g_string_free(err_p, TRUE);
473 register_tap_menu_item("MTP3/MSUs", REGISTER_TAP_GROUP_NONE,
474 mtp3_stat_gtk_cb, NULL, NULL, NULL);