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_dlg.h"
52 #include "compat_macros.h"
55 #include <epan/dissectors/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];
98 mtp3_stat_t (*stat_p)[MTP3_MAX_NUM_OPC_DPC] = tapdata;
101 memset(stat_p, 0, MTP3_MAX_NUM_OPC_DPC * sizeof(mtp3_stat_t));
105 gtk_clist_clear(GTK_CLIST(dlg.table));
113 packet_info *pinfo _U_,
114 epan_dissect_t *edt _U_,
117 mtp3_stat_t (*stat_p)[MTP3_MAX_NUM_OPC_DPC] = tapdata;
118 const mtp3_tap_rec_t *data_p = data;
121 if (data_p->si_code >= MTP3_NUM_SI_CODE)
124 * we thought this si_code was not used ?
125 * is MTP3_NUM_SI_CODE out of date ?
131 * look for opc/dpc pair
134 while (i < mtp3_num_used)
136 if (memcmp(&data_p->addr_opc, &(*stat_p)[i].addr_opc, sizeof(mtp3_addr_pc_t)) == 0)
138 if (memcmp(&data_p->addr_dpc, &(*stat_p)[i].addr_dpc, sizeof(mtp3_addr_pc_t)) == 0)
147 if (i == mtp3_num_used)
149 if (mtp3_num_used == MTP3_MAX_NUM_OPC_DPC)
160 (*stat_p)[i].addr_opc = data_p->addr_opc;
161 (*stat_p)[i].addr_dpc = data_p->addr_dpc;
162 (*stat_p)[i].si_code[data_p->si_code].num_msus++;
163 (*stat_p)[i].si_code[data_p->si_code].size += data_p->size;
173 mtp3_stat_t (*stat_p)[MTP3_MAX_NUM_OPC_DPC] = tapdata;
174 int i, j, row_offset;
177 if (!dlg.win || !tapdata)
184 while (i < mtp3_num_used)
186 row_offset = i * MTP3_NUM_SI_CODE;
188 mtp3_addr_to_str_buf((guint8 *) &(*stat_p)[i].addr_opc, str);
189 dlg.entries[0] = g_strdup(str);
191 mtp3_addr_to_str_buf((guint8 *) &(*stat_p)[i].addr_dpc, str);
192 dlg.entries[1] = g_strdup(str);
194 for (j=0; j < MTP3_NUM_SI_CODE; j++)
196 dlg.entries[2] = g_strdup(mtp3_service_indicator_code_short_vals[j].strptr);
198 dlg.entries[3] = g_strdup_printf("%u", (*stat_p)[i].si_code[j].num_msus);
200 dlg.entries[4] = g_strdup_printf("%.0f", (*stat_p)[i].si_code[j].size);
203 g_strdup_printf("%.2f",
204 (*stat_p)[i].si_code[j].size/(*stat_p)[i].si_code[j].num_msus);
206 gtk_clist_insert(GTK_CLIST(dlg.table), row_offset + j, dlg.entries);
212 gtk_clist_sort(GTK_CLIST(dlg.table));
217 mtp3_stat_gtk_click_column_cb(
222 column_arrows *col_arrows = (column_arrows *) data;
226 gtk_clist_freeze(clist);
228 for (i=0; i < MTP3_INIT_TABLE_NUM_COLUMNS; i++)
230 gtk_widget_hide(col_arrows[i].ascend_pm);
231 gtk_widget_hide(col_arrows[i].descend_pm);
234 if (column == clist->sort_column)
236 if (clist->sort_type == GTK_SORT_ASCENDING)
238 clist->sort_type = GTK_SORT_DESCENDING;
239 gtk_widget_show(col_arrows[column].descend_pm);
243 clist->sort_type = GTK_SORT_ASCENDING;
244 gtk_widget_show(col_arrows[column].ascend_pm);
250 * Columns 0-1 sorted in descending order by default
254 clist->sort_type = GTK_SORT_ASCENDING;
255 gtk_widget_show(col_arrows[column].ascend_pm);
259 clist->sort_type = GTK_SORT_DESCENDING;
260 gtk_widget_show(col_arrows[column].descend_pm);
263 gtk_clist_set_sort_column(clist, column);
266 gtk_clist_thaw(clist);
267 gtk_clist_sort(clist);
272 mtp3_stat_gtk_sort_column(
277 const GtkCListRow *row1 = ptr1;
278 const GtkCListRow *row2 = ptr2;
283 text1 = GTK_CELL_TEXT(row1->cell[clist->sort_column])->text;
284 text2 = GTK_CELL_TEXT(row2->cell[clist->sort_column])->text;
286 switch (clist->sort_column)
292 return(strcmp(text1, text2));
296 i1 = strtol(text1, NULL, 0);
297 i2 = strtol(text2, NULL, 0);
301 g_assert_not_reached();
308 mtp3_stat_gtk_win_destroy_cb(
310 gpointer user_data _U_)
312 memset((void *) user_data, 0, sizeof(mtp3_stat_dlg_t));
317 mtp3_stat_gtk_win_create(
318 mtp3_stat_dlg_t *dlg_p,
322 column_arrows *col_arrows;
323 GtkWidget *column_lb;
329 dlg_p->win = window_new(GTK_WINDOW_TOPLEVEL, title);
330 gtk_window_set_default_size(GTK_WINDOW(dlg_p->win), 640, 390);
332 vbox = gtk_vbox_new(FALSE, 3);
333 gtk_container_add(GTK_CONTAINER(dlg_p->win), vbox);
334 gtk_container_set_border_width(GTK_CONTAINER(vbox), 12);
336 dlg_p->scrolled_win = scrolled_window_new(NULL, NULL);
337 gtk_box_pack_start(GTK_BOX(vbox), dlg_p->scrolled_win, TRUE, TRUE, 0);
339 dlg_p->table = gtk_clist_new(MTP3_INIT_TABLE_NUM_COLUMNS);
342 (column_arrows *) g_malloc(sizeof(column_arrows) * MTP3_INIT_TABLE_NUM_COLUMNS);
344 for (i = 0; i < MTP3_INIT_TABLE_NUM_COLUMNS; i++)
346 col_arrows[i].table = gtk_table_new(2, 2, FALSE);
348 gtk_table_set_col_spacings(GTK_TABLE(col_arrows[i].table), 5);
350 column_lb = gtk_label_new(columns[i].strptr);
352 gtk_table_attach(GTK_TABLE(col_arrows[i].table), column_lb,
353 0, 1, 0, 2, GTK_SHRINK, GTK_SHRINK, 0, 0);
355 gtk_widget_show(column_lb);
357 col_arrows[i].ascend_pm = xpm_to_widget(clist_ascend_xpm);
359 gtk_table_attach(GTK_TABLE(col_arrows[i].table), col_arrows[i].ascend_pm,
360 1, 2, 1, 2, GTK_SHRINK, GTK_SHRINK, 0, 0);
362 col_arrows[i].descend_pm = xpm_to_widget(clist_descend_xpm);
364 gtk_table_attach(GTK_TABLE(col_arrows[i].table), col_arrows[i].descend_pm,
365 1, 2, 0, 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
369 /* default column sorting */
370 gtk_widget_show(col_arrows[i].ascend_pm);
373 gtk_clist_set_column_justification(GTK_CLIST(dlg_p->table), i, columns[i].just);
375 gtk_clist_set_column_widget(GTK_CLIST(dlg_p->table), i, col_arrows[i].table);
376 gtk_widget_show(col_arrows[i].table);
378 gtk_clist_column_titles_show(GTK_CLIST(dlg_p->table));
380 gtk_clist_set_compare_func(GTK_CLIST(dlg_p->table), mtp3_stat_gtk_sort_column);
381 gtk_clist_set_sort_column(GTK_CLIST(dlg_p->table), 0);
382 gtk_clist_set_sort_type(GTK_CLIST(dlg_p->table), GTK_SORT_ASCENDING);
384 for (i = 0; i < MTP3_INIT_TABLE_NUM_COLUMNS; i++)
386 gtk_clist_set_column_width(GTK_CLIST(dlg_p->table), i, columns[i].value);
389 gtk_clist_set_shadow_type(GTK_CLIST(dlg_p->table), GTK_SHADOW_IN);
390 gtk_clist_column_titles_show(GTK_CLIST(dlg_p->table));
391 gtk_container_add(GTK_CONTAINER(dlg_p->scrolled_win), dlg_p->table);
393 SIGNAL_CONNECT(dlg_p->table, "click-column", mtp3_stat_gtk_click_column_cb, col_arrows);
396 bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
397 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
399 bt_close = OBJECT_GET_DATA(bbox, GTK_STOCK_CLOSE);
400 window_set_cancel_button(dlg_p->win, bt_close, window_cancel_button_cb);
402 SIGNAL_CONNECT(dlg_p->win, "delete_event", window_delete_event_cb, NULL);
403 SIGNAL_CONNECT(dlg_p->win, "destroy", mtp3_stat_gtk_win_destroy_cb, dlg_p);
405 gtk_widget_show_all(dlg_p->win);
406 window_present(dlg_p->win);
411 * Never gets called ?
417 /* does not appear to be called */
430 * if the window is already open, bring it to front
434 gdk_window_raise(dlg.win->window);
438 mtp3_stat_gtk_win_create(&dlg, "MTP3 Statistics");
440 mtp3_stat_draw(NULL);
445 register_tap_listener_gtkmtp3_stat(void)
450 register_tap_listener_cmd_arg("mtp3,", mtp3_stat_gtk_init);
452 memset((void *) &mtp3_stat, 0, sizeof(mtp3_stat_t));
455 register_tap_listener("mtp3", &mtp3_stat, NULL,
462 simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK, err_p->str);
463 g_string_free(err_p, TRUE);
468 register_tap_menu_item("MTP3/MSUs", REGISTER_TAP_GROUP_TELEPHONY,
469 mtp3_stat_gtk_cb, NULL, NULL, NULL);