2 * camel message counter for Wireshark
3 * Copyright 2006 Florent Drouin (based on h225_counter.c from Lars Roland)
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 #ifdef HAVE_SYS_TYPES_H
31 # include <sys/types.h>
37 #include <epan/epan.h>
38 #include <epan/packet_info.h>
39 #include <epan/value_string.h>
41 #include <epan/packet.h>
42 #include <epan/asn1.h>
43 #include <epan/camel-persistentdata.h>
45 #include "../globals.h"
46 #include "../stat_menu.h"
47 #include "../register.h"
48 #include "../timestats.h"
49 #include "../simple_dialog.h"
52 #include "gtk/dlg_utils.h"
53 #include "gtk/gui_utils.h"
54 #include "gtk/gui_stat_util.h"
55 #include "gtk/tap_dfilter_dlg.h"
58 static void gtk_camelcounter_reset(void *phs);
59 static int gtk_camelcounter_packet(void *phs,
60 packet_info *pinfo _U_,
61 epan_dissect_t *edt _U_,
63 static void gtk_camelcounter_draw(void *phs);
64 static void win_destroy_cb(GtkWindow *win _U_, gpointer data);
65 static void gtk_camelcounter_init(const char *optarg, void *userdata _U_);
66 void register_tap_listener_gtk_camelcounter(void);
68 /* following values represent the size of their valuestring arrays */
70 struct camelcounter_t {
74 GtkWidget *scrolled_window;
76 guint32 camel_msg[camel_MAX_NUM_OPR_CODES];
79 static void gtk_camelcounter_reset(void *phs)
81 struct camelcounter_t * p_counter= ( struct camelcounter_t *) phs;
84 /* Erase Message Type count */
85 for(i=0;i<camel_MAX_NUM_OPR_CODES;i++) {
86 p_counter->camel_msg[i]=0;
92 * If there is a valid camel operation, increase the value in the array of counter
94 static int gtk_camelcounter_packet(void *phs,
95 packet_info *pinfo _U_,
96 epan_dissect_t *edt _U_,
99 struct camelcounter_t * p_counter =(struct camelcounter_t *)phs;
100 const struct camelsrt_info_t * pi=phi;
101 if (pi->opcode != 255)
102 p_counter->camel_msg[pi->opcode]++;
107 static void gtk_camelcounter_draw(void *phs)
109 struct camelcounter_t *p_counter=(struct camelcounter_t *)phs;
114 str[i]=g_malloc(sizeof(char[256]));
116 /* Now print Message and Reason Counter Table */
117 /* clear list before printing */
118 gtk_clist_clear(p_counter->table);
120 for(i=0;i<camel_MAX_NUM_OPR_CODES;i++) {
121 /* Message counter */
122 if(p_counter->camel_msg[i]!=0) {
123 g_snprintf(str[0], sizeof(char[256]),
124 "Request %s", val_to_str(i,camel_opr_code_strings,"Unknown message "));
125 g_snprintf(str[1], sizeof(char[256]),
126 "%d", p_counter->camel_msg[i]);
127 gtk_clist_append(p_counter->table, str);
130 gtk_widget_show(GTK_WIDGET(p_counter->table));
133 static void win_destroy_cb(GtkWindow *win _U_, gpointer data)
135 struct camelcounter_t *hs=(struct camelcounter_t *)data;
137 protect_thread_critical_region();
138 remove_tap_listener(hs);
139 unprotect_thread_critical_region();
148 static const gchar *titles[]={
149 "Message Type or Reason",
152 static void gtk_camelcounter_init(const char *optarg, void *userdata _U_)
154 struct camelcounter_t *p_camelcounter;
155 const char *filter=NULL;
156 GString *error_string;
160 if(strncmp(optarg,"camel,counter,",14) == 0){
166 p_camelcounter=g_malloc(sizeof(struct camelcounter_t));
167 p_camelcounter->filter=g_strdup(filter);
169 gtk_camelcounter_reset(p_camelcounter);
171 p_camelcounter->win=window_new(GTK_WINDOW_TOPLEVEL, "Wireshark: CAMEL counters");
172 gtk_window_set_default_size(GTK_WINDOW(p_camelcounter->win), 500, 300);
174 p_camelcounter->vbox=gtk_vbox_new(FALSE, 3);
175 gtk_container_set_border_width(GTK_CONTAINER(p_camelcounter->vbox), 12);
177 init_main_stat_window(p_camelcounter->win, p_camelcounter->vbox, "CAMEL Messages Counters", filter);
179 /* init a scrolled window*/
180 p_camelcounter->scrolled_window = scrolled_window_new(NULL, NULL);
182 p_camelcounter->table = create_stat_table(p_camelcounter->scrolled_window, p_camelcounter->vbox, 2, titles);
184 error_string=register_tap_listener("CAMEL", p_camelcounter, filter, 0,
185 gtk_camelcounter_reset,
186 gtk_camelcounter_packet,
187 gtk_camelcounter_draw);
190 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", error_string->str);
191 g_string_free(error_string, TRUE);
192 g_free(p_camelcounter);
197 bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
198 gtk_box_pack_end(GTK_BOX(p_camelcounter->vbox), bbox, FALSE, FALSE, 0);
200 close_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CLOSE);
201 window_set_cancel_button(p_camelcounter->win, close_bt, window_cancel_button_cb);
203 g_signal_connect(p_camelcounter->win, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
204 g_signal_connect(p_camelcounter->win, "destroy", G_CALLBACK(win_destroy_cb), p_camelcounter);
206 gtk_widget_show_all(p_camelcounter->win);
207 window_present(p_camelcounter->win);
209 cf_retap_packets(&cfile);
210 gdk_window_raise(p_camelcounter->win->window);
213 static tap_dfilter_dlg camel_counter_dlg = {
214 "CAMEL Messages and Response Status",
216 gtk_camelcounter_init,
220 void /* Next line mandatory */
221 register_tap_listener_gtk_camelcounter(void)
223 register_dfilter_stat(&camel_counter_dlg, "GSM/CAMEL",
224 REGISTER_STAT_GROUP_TELEPHONY);