2 * h225 message counter for ethereal
3 * Copyright 2003 Lars Roland
5 * $Id: h225_counter.c,v 1.8 2004/01/31 03:22:41 guy Exp $
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@ethereal.com>
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.
32 #ifdef HAVE_SYS_TYPES_H
33 # include <sys/types.h>
38 #include "../epan/packet_info.h"
39 #include "../epan/epan.h"
42 #include "../epan/value_string.h"
43 #include "../register.h"
44 #include "../packet-h225.h"
45 #include "gtk_stat_util.h"
46 #include "compat_macros.h"
47 #include "../simple_dialog.h"
48 #include "dlg_utils.h"
50 #include "../globals.h"
51 #include "../tap_dfilter_dlg.h"
52 #include "tap_dfilter_dlg.h"
54 extern GtkWidget *main_display_filter_widget;
56 void gtk_h225counter_init(char *optarg);
58 tap_dfilter_dlg h225_counter_dlg = {"H.225 Messages and Message Reasons", "h225,counter", gtk_h225counter_init, -1};
60 /* following values represent the size of their valuestring arrays */
62 #define RAS_MSG_TYPES 33
63 #define CS_MSG_TYPES 13
66 #define RRJ_REASONS 18
69 #define ARJ_REASONS 22
73 #define LRJ_REASONS 16
74 #define IRQNAK_REASONS 4
75 #define REL_CMP_REASONS 26
76 #define FACILITY_REASONS 11
79 /* used to keep track of the statistics for an entire program interface */
80 typedef struct _h225counter_t {
84 GtkWidget *scrolled_window;
86 guint32 ras_msg[RAS_MSG_TYPES + 1];
87 guint32 cs_msg[CS_MSG_TYPES + 1];
88 guint32 grj_reason[GRJ_REASONS + 1];
89 guint32 rrj_reason[RRJ_REASONS + 1];
90 guint32 urq_reason[URQ_REASONS + 1];
91 guint32 urj_reason[URJ_REASONS + 1];
92 guint32 arj_reason[ARJ_REASONS + 1];
93 guint32 brj_reason[BRJ_REASONS + 1];
94 guint32 drq_reason[DRQ_REASONS + 1];
95 guint32 drj_reason[DRJ_REASONS + 1];
96 guint32 lrj_reason[LRJ_REASONS + 1];
97 guint32 irqnak_reason[IRQNAK_REASONS + 1];
98 guint32 rel_cmp_reason[REL_CMP_REASONS + 1];
99 guint32 facility_reason[FACILITY_REASONS + 1];
104 h225counter_reset(void *phs)
106 h225counter_t *hs=(h225counter_t *)phs;
109 for(i=0;i<=RAS_MSG_TYPES;i++) {
112 for(i=0;i<=CS_MSG_TYPES;i++) {
115 for(i=0;i<=GRJ_REASONS;i++) {
116 hs->grj_reason[i] = 0;
118 for(i=0;i<=RRJ_REASONS;i++) {
119 hs->rrj_reason[i] = 0;
121 for(i=0;i<=URQ_REASONS;i++) {
122 hs->urq_reason[i] = 0;
124 for(i=0;i<=URJ_REASONS;i++) {
125 hs->urj_reason[i] = 0;
127 for(i=0;i<=ARJ_REASONS;i++) {
128 hs->arj_reason[i] = 0;
130 for(i=0;i<=BRJ_REASONS;i++) {
131 hs->brj_reason[i] = 0;
133 for(i=0;i<=DRQ_REASONS;i++) {
134 hs->drq_reason[i] = 0;
136 for(i=0;i<=DRJ_REASONS;i++) {
137 hs->drj_reason[i] = 0;
139 for(i=0;i<=LRJ_REASONS;i++) {
140 hs->lrj_reason[i] = 0;
142 for(i=0;i<=IRQNAK_REASONS;i++) {
143 hs->irqnak_reason[i] = 0;
145 for(i=0;i<=REL_CMP_REASONS;i++) {
146 hs->rel_cmp_reason[i] = 0;
148 for(i=0;i<=FACILITY_REASONS;i++) {
149 hs->facility_reason[i] = 0;
154 h225counter_packet(void *phs, packet_info *pinfo _U_, epan_dissect_t *edt _U_, void *phi)
156 h225counter_t *hs=(h225counter_t *)phs;
157 h225_packet_info *pi=phi;
159 switch (pi->msg_type) {
162 if(pi->msg_tag==-1) { /* uninitialized */
165 else if (pi->msg_tag >= RAS_MSG_TYPES) { /* unknown */
166 hs->ras_msg[RAS_MSG_TYPES]++;
169 hs->ras_msg[pi->msg_tag]++;
172 /* Look for reason tag */
173 if(pi->reason==-1) { /* uninitialized */
177 switch(pi->msg_tag) {
180 if(pi->reason < GRJ_REASONS)
181 hs->grj_reason[pi->reason]++;
183 hs->grj_reason[GRJ_REASONS]++;
186 if(pi->reason < RRJ_REASONS)
187 hs->rrj_reason[pi->reason]++;
189 hs->rrj_reason[RRJ_REASONS]++;
192 if(pi->reason < URQ_REASONS)
193 hs->urq_reason[pi->reason]++;
195 hs->urq_reason[URQ_REASONS]++;
198 if(pi->reason < URJ_REASONS)
199 hs->urj_reason[pi->reason]++;
201 hs->urj_reason[URJ_REASONS]++;
204 if(pi->reason < ARJ_REASONS)
205 hs->arj_reason[pi->reason]++;
207 hs->arj_reason[ARJ_REASONS]++;
210 if(pi->reason < BRJ_REASONS)
211 hs->brj_reason[pi->reason]++;
213 hs->brj_reason[BRJ_REASONS]++;
216 if(pi->reason < DRQ_REASONS)
217 hs->drq_reason[pi->reason]++;
219 hs->drq_reason[DRQ_REASONS]++;
222 if(pi->reason < DRJ_REASONS)
223 hs->drj_reason[pi->reason]++;
225 hs->drj_reason[DRJ_REASONS]++;
228 if(pi->reason < LRJ_REASONS)
229 hs->lrj_reason[pi->reason]++;
231 hs->lrj_reason[LRJ_REASONS]++;
233 case 29: /* IRQ Nak */
234 if(pi->reason < IRQNAK_REASONS)
235 hs->irqnak_reason[pi->reason]++;
237 hs->irqnak_reason[IRQNAK_REASONS]++;
248 if(pi->msg_tag==-1) { /* uninitialized */
251 else if (pi->msg_tag >= CS_MSG_TYPES) { /* unknown */
252 hs->cs_msg[CS_MSG_TYPES]++;
255 hs->cs_msg[pi->msg_tag]++;
258 /* Look for reason tag */
259 if(pi->reason==-1) { /* uninitialized */
263 switch(pi->msg_tag) {
265 case 5: /* ReleaseComplete */
266 if(pi->reason < REL_CMP_REASONS)
267 hs->rel_cmp_reason[pi->reason]++;
269 hs->rel_cmp_reason[REL_CMP_REASONS]++;
271 case 6: /* Facility */
272 if(pi->reason < FACILITY_REASONS)
273 hs->facility_reason[pi->reason]++;
275 hs->facility_reason[FACILITY_REASONS]++;
293 h225counter_draw(void *phs)
295 h225counter_t *hs=(h225counter_t *)phs;
300 str[i]=g_malloc(sizeof(char[256]));
302 /* Now print Message and Reason Counter Table */
303 /* clear list before printing */
304 gtk_clist_clear(hs->table);
306 for(i=0;i<=RAS_MSG_TYPES;i++) {
307 if(hs->ras_msg[i]!=0) {
308 sprintf(str[0], "%s", val_to_str(i,RasMessage_vals,"unknown ras-messages "));
309 sprintf(str[1], "%d", hs->ras_msg[i]);
310 gtk_clist_append(hs->table, str);
315 for(j=0;j<=GRJ_REASONS;j++) {
316 if(hs->grj_reason[j]!=0) {
317 sprintf(str[0], " %s", val_to_str(j,GatekeeperRejectReason_vals,"unknown reason "));
318 sprintf(str[1], "%d", hs->grj_reason[j]);
319 gtk_clist_append(hs->table, str);
324 for(j=0;j<=RRJ_REASONS;j++) {
325 if(hs->rrj_reason[j]!=0) {
326 sprintf(str[0], " %s", val_to_str(j,RegistrationRejectReason_vals,"unknown reason "));
327 sprintf(str[1], "%d", hs->rrj_reason[j]);
328 gtk_clist_append(hs->table, str);
333 for(j=0;j<=URQ_REASONS;j++) {
334 if(hs->urq_reason[j]!=0) {
335 sprintf(str[0], " %s", val_to_str(j,UnregRequestReason_vals,"unknown reason "));
336 sprintf(str[1], "%d", hs->urq_reason[j]);
337 gtk_clist_append(hs->table, str);
342 for(j=0;j<=URJ_REASONS;j++) {
343 if(hs->urj_reason[j]!=0) {
344 sprintf(str[0], " %s", val_to_str(j,UnregRejectReason_vals,"unknown reason "));
345 sprintf(str[1], "%d", hs->urj_reason[j]);
346 gtk_clist_append(hs->table, str);
351 for(j=0;j<=ARJ_REASONS;j++) {
352 if(hs->arj_reason[j]!=0) {
353 sprintf(str[0], " %s", val_to_str(j,AdmissionRejectReason_vals,"unknown reason "));
354 sprintf(str[1], "%d", hs->arj_reason[j]);
355 gtk_clist_append(hs->table, str);
360 for(j=0;j<=BRJ_REASONS;j++) {
361 if(hs->brj_reason[j]!=0) {
362 sprintf(str[0], " %s", val_to_str(j,BandRejectReason_vals,"unknown reason "));
363 sprintf(str[1], "%d", hs->brj_reason[j]);
364 gtk_clist_append(hs->table, str);
369 for(j=0;j<=DRQ_REASONS;j++) {
370 if(hs->drq_reason[j]!=0) {
371 sprintf(str[0], " %s", val_to_str(j,DisengageReason_vals,"unknown reason "));
372 sprintf(str[1], "%d", hs->drq_reason[j]);
373 gtk_clist_append(hs->table, str);
378 for(j=0;j<=DRJ_REASONS;j++) {
379 if(hs->drj_reason[j]!=0) {
380 sprintf(str[0], " %s", val_to_str(j,DisengageRejectReason_vals,"unknown reason "));
381 sprintf(str[1], "%d", hs->drj_reason[j]);
382 gtk_clist_append(hs->table, str);
387 for(j=0;j<=LRJ_REASONS;j++) {
388 if(hs->lrj_reason[j]!=0) {
389 sprintf(str[0], " %s", val_to_str(j,LocationRejectReason_vals,"unknown reason "));
390 sprintf(str[1], "%d", hs->lrj_reason[j]);
391 gtk_clist_append(hs->table, str);
395 case 29: /* IRQNak */
396 for(j=0;j<=IRQNAK_REASONS;j++) {
397 if(hs->irqnak_reason[j]!=0) {
398 sprintf(str[0], " %s", val_to_str(j,InfoRequestNakReason_vals,"unknown reason "));
399 sprintf(str[1], "%d", hs->irqnak_reason[j]);
400 gtk_clist_append(hs->table, str);
407 /* end of reason counter*/
411 for(i=0;i<=CS_MSG_TYPES;i++) {
412 if(hs->cs_msg[i]!=0) {
413 sprintf(str[0], "%s", val_to_str(i,h323_message_body_vals,"unknown cs-messages "));
414 sprintf(str[1], "%d", hs->cs_msg[i]);
415 gtk_clist_append(hs->table, str);
419 case 5: /* ReleaseComplete */
420 for(j=0;j<=REL_CMP_REASONS;j++) {
421 if(hs->rel_cmp_reason[j]!=0) {
422 sprintf(str[0], " %s", val_to_str(j,ReleaseCompleteReason_vals,"unknown reason "));
423 sprintf(str[1], "%d", hs->rel_cmp_reason[j]);
424 gtk_clist_append(hs->table, str);
428 case 6: /* Facility */
429 for(j=0;j<=FACILITY_REASONS;j++) {
430 if(hs->facility_reason[j]!=0) {
431 sprintf(str[0], " %s", val_to_str(j,FacilityReason_vals,"unknown reason "));
432 sprintf(str[1], "%d", hs->facility_reason[j]);
433 gtk_clist_append(hs->table, str);
443 gtk_widget_show(GTK_WIDGET(hs->table));
447 void protect_thread_critical_region(void);
448 void unprotect_thread_critical_region(void);
450 win_destroy_cb(GtkWindow *win _U_, gpointer data)
452 h225counter_t *hs=(h225counter_t *)data;
454 protect_thread_critical_region();
455 remove_tap_listener(hs);
456 unprotect_thread_critical_region();
466 static gchar *titles[]={"Message Type or Reason",
470 gtk_h225counter_init(char *optarg)
474 GString *error_string;
476 if(strncmp(optarg,"h225,counter,",13) == 0){
483 hs=g_malloc(sizeof(h225counter_t));
484 hs->filter=g_malloc(strlen(filter)+1);
485 strcpy(hs->filter, filter);
487 h225counter_reset(hs);
489 hs->win=gtk_window_new(GTK_WINDOW_TOPLEVEL);
490 SIGNAL_CONNECT(hs->win, "destroy", win_destroy_cb, hs);
492 hs->vbox=gtk_vbox_new(FALSE, 0);
494 init_main_stat_window(hs->win, hs->vbox, "ITU-T H.225 Message and Message Reason Counter", filter);
496 /* init a scrolled window*/
497 hs->scrolled_window = gtk_scrolled_window_new(NULL, NULL);
498 WIDGET_SET_SIZE(hs->scrolled_window, 400, 200);
500 hs->table = create_stat_table(hs->scrolled_window, hs->vbox, 2, titles);
502 error_string=register_tap_listener("h225", hs, filter, h225counter_reset, h225counter_packet, h225counter_draw);
504 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, error_string->str);
505 g_string_free(error_string, TRUE);
511 gtk_widget_show_all(hs->win);
512 redissect_packets(&cfile);
516 register_tap_listener_gtk_h225counter(void)
518 register_ethereal_tap("h225,counter", gtk_h225counter_init);
522 register_tap_menu_gtk_h225counter(void)
524 register_tap_menu_item("_Statistics/Watch protocol/ITU-T H.225...",
525 gtk_tap_dfilter_dlg_cb, NULL, NULL, &(h225_counter_dlg));