2 * h225 message counter for ethereal
3 * Copyright 2003 Lars Roland
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.
30 #ifdef HAVE_SYS_TYPES_H
31 # include <sys/types.h>
38 #include <epan/packet_info.h>
39 #include <epan/epan.h>
40 #include <epan/value_string.h>
44 #include "../register.h"
45 #include "../packet-h225.h"
46 #include "gtk_stat_util.h"
47 #include "compat_macros.h"
48 #include "../simple_dialog.h"
49 #include "dlg_utils.h"
51 #include "../globals.h"
52 #include "../tap_dfilter_dlg.h"
53 #include "tap_dfilter_dlg.h"
57 static void gtk_h225counter_init(char *optarg);
59 static tap_dfilter_dlg h225_counter_dlg = {
60 "H.225 Messages and Message Reasons",
66 /* following values represent the size of their valuestring arrays */
68 #define RAS_MSG_TYPES 33
69 #define CS_MSG_TYPES 13
72 #define RRJ_REASONS 18
75 #define ARJ_REASONS 22
79 #define LRJ_REASONS 16
80 #define IRQNAK_REASONS 4
81 #define REL_CMP_REASONS 26
82 #define FACILITY_REASONS 11
85 /* used to keep track of the statistics for an entire program interface */
86 typedef struct _h225counter_t {
90 GtkWidget *scrolled_window;
92 guint32 ras_msg[RAS_MSG_TYPES + 1];
93 guint32 cs_msg[CS_MSG_TYPES + 1];
94 guint32 grj_reason[GRJ_REASONS + 1];
95 guint32 rrj_reason[RRJ_REASONS + 1];
96 guint32 urq_reason[URQ_REASONS + 1];
97 guint32 urj_reason[URJ_REASONS + 1];
98 guint32 arj_reason[ARJ_REASONS + 1];
99 guint32 brj_reason[BRJ_REASONS + 1];
100 guint32 drq_reason[DRQ_REASONS + 1];
101 guint32 drj_reason[DRJ_REASONS + 1];
102 guint32 lrj_reason[LRJ_REASONS + 1];
103 guint32 irqnak_reason[IRQNAK_REASONS + 1];
104 guint32 rel_cmp_reason[REL_CMP_REASONS + 1];
105 guint32 facility_reason[FACILITY_REASONS + 1];
110 h225counter_reset(void *phs)
112 h225counter_t *hs=(h225counter_t *)phs;
115 for(i=0;i<=RAS_MSG_TYPES;i++) {
118 for(i=0;i<=CS_MSG_TYPES;i++) {
121 for(i=0;i<=GRJ_REASONS;i++) {
122 hs->grj_reason[i] = 0;
124 for(i=0;i<=RRJ_REASONS;i++) {
125 hs->rrj_reason[i] = 0;
127 for(i=0;i<=URQ_REASONS;i++) {
128 hs->urq_reason[i] = 0;
130 for(i=0;i<=URJ_REASONS;i++) {
131 hs->urj_reason[i] = 0;
133 for(i=0;i<=ARJ_REASONS;i++) {
134 hs->arj_reason[i] = 0;
136 for(i=0;i<=BRJ_REASONS;i++) {
137 hs->brj_reason[i] = 0;
139 for(i=0;i<=DRQ_REASONS;i++) {
140 hs->drq_reason[i] = 0;
142 for(i=0;i<=DRJ_REASONS;i++) {
143 hs->drj_reason[i] = 0;
145 for(i=0;i<=LRJ_REASONS;i++) {
146 hs->lrj_reason[i] = 0;
148 for(i=0;i<=IRQNAK_REASONS;i++) {
149 hs->irqnak_reason[i] = 0;
151 for(i=0;i<=REL_CMP_REASONS;i++) {
152 hs->rel_cmp_reason[i] = 0;
154 for(i=0;i<=FACILITY_REASONS;i++) {
155 hs->facility_reason[i] = 0;
160 h225counter_packet(void *phs, packet_info *pinfo _U_, epan_dissect_t *edt _U_, void *phi)
162 h225counter_t *hs=(h225counter_t *)phs;
163 h225_packet_info *pi=phi;
165 switch (pi->msg_type) {
168 if(pi->msg_tag==-1) { /* uninitialized */
171 else if (pi->msg_tag >= RAS_MSG_TYPES) { /* unknown */
172 hs->ras_msg[RAS_MSG_TYPES]++;
175 hs->ras_msg[pi->msg_tag]++;
178 /* Look for reason tag */
179 if(pi->reason==-1) { /* uninitialized */
183 switch(pi->msg_tag) {
186 if(pi->reason < GRJ_REASONS)
187 hs->grj_reason[pi->reason]++;
189 hs->grj_reason[GRJ_REASONS]++;
192 if(pi->reason < RRJ_REASONS)
193 hs->rrj_reason[pi->reason]++;
195 hs->rrj_reason[RRJ_REASONS]++;
198 if(pi->reason < URQ_REASONS)
199 hs->urq_reason[pi->reason]++;
201 hs->urq_reason[URQ_REASONS]++;
204 if(pi->reason < URJ_REASONS)
205 hs->urj_reason[pi->reason]++;
207 hs->urj_reason[URJ_REASONS]++;
210 if(pi->reason < ARJ_REASONS)
211 hs->arj_reason[pi->reason]++;
213 hs->arj_reason[ARJ_REASONS]++;
216 if(pi->reason < BRJ_REASONS)
217 hs->brj_reason[pi->reason]++;
219 hs->brj_reason[BRJ_REASONS]++;
222 if(pi->reason < DRQ_REASONS)
223 hs->drq_reason[pi->reason]++;
225 hs->drq_reason[DRQ_REASONS]++;
228 if(pi->reason < DRJ_REASONS)
229 hs->drj_reason[pi->reason]++;
231 hs->drj_reason[DRJ_REASONS]++;
234 if(pi->reason < LRJ_REASONS)
235 hs->lrj_reason[pi->reason]++;
237 hs->lrj_reason[LRJ_REASONS]++;
239 case 29: /* IRQ Nak */
240 if(pi->reason < IRQNAK_REASONS)
241 hs->irqnak_reason[pi->reason]++;
243 hs->irqnak_reason[IRQNAK_REASONS]++;
254 if(pi->msg_tag==-1) { /* uninitialized */
257 else if (pi->msg_tag >= CS_MSG_TYPES) { /* unknown */
258 hs->cs_msg[CS_MSG_TYPES]++;
261 hs->cs_msg[pi->msg_tag]++;
264 /* Look for reason tag */
265 if(pi->reason==-1) { /* uninitialized */
269 switch(pi->msg_tag) {
271 case 5: /* ReleaseComplete */
272 if(pi->reason < REL_CMP_REASONS)
273 hs->rel_cmp_reason[pi->reason]++;
275 hs->rel_cmp_reason[REL_CMP_REASONS]++;
277 case 6: /* Facility */
278 if(pi->reason < FACILITY_REASONS)
279 hs->facility_reason[pi->reason]++;
281 hs->facility_reason[FACILITY_REASONS]++;
299 h225counter_draw(void *phs)
301 h225counter_t *hs=(h225counter_t *)phs;
306 str[i]=g_malloc(sizeof(char[256]));
308 /* Now print Message and Reason Counter Table */
309 /* clear list before printing */
310 gtk_clist_clear(hs->table);
312 for(i=0;i<=RAS_MSG_TYPES;i++) {
313 if(hs->ras_msg[i]!=0) {
314 g_snprintf(str[0], sizeof(char[256]),
315 "%s", val_to_str(i,RasMessage_vals,"unknown ras-messages "));
316 g_snprintf(str[1], sizeof(char[256]),
317 "%d", hs->ras_msg[i]);
318 gtk_clist_append(hs->table, str);
323 for(j=0;j<=GRJ_REASONS;j++) {
324 if(hs->grj_reason[j]!=0) {
325 g_snprintf(str[0], sizeof(char[256]),
326 " %s", val_to_str(j,GatekeeperRejectReason_vals,"unknown reason "));
327 g_snprintf(str[1], sizeof(char[256]),
328 "%d", hs->grj_reason[j]);
329 gtk_clist_append(hs->table, str);
334 for(j=0;j<=RRJ_REASONS;j++) {
335 if(hs->rrj_reason[j]!=0) {
336 g_snprintf(str[0], sizeof(char[256]),
337 " %s", val_to_str(j,RegistrationRejectReason_vals,"unknown reason "));
338 g_snprintf(str[1], sizeof(char[256]),
339 "%d", hs->rrj_reason[j]);
340 gtk_clist_append(hs->table, str);
345 for(j=0;j<=URQ_REASONS;j++) {
346 if(hs->urq_reason[j]!=0) {
347 g_snprintf(str[0], sizeof(char[256]),
348 " %s", val_to_str(j,UnregRequestReason_vals,"unknown reason "));
349 g_snprintf(str[1], sizeof(char[256]),
350 "%d", hs->urq_reason[j]);
351 gtk_clist_append(hs->table, str);
356 for(j=0;j<=URJ_REASONS;j++) {
357 if(hs->urj_reason[j]!=0) {
358 g_snprintf(str[0], sizeof(char[256]),
359 " %s", val_to_str(j,UnregRejectReason_vals,"unknown reason "));
360 g_snprintf(str[1], sizeof(char[256]),
361 "%d", hs->urj_reason[j]);
362 gtk_clist_append(hs->table, str);
367 for(j=0;j<=ARJ_REASONS;j++) {
368 if(hs->arj_reason[j]!=0) {
369 g_snprintf(str[0], sizeof(char[256]),
370 " %s", val_to_str(j,AdmissionRejectReason_vals,"unknown reason "));
371 g_snprintf(str[1], sizeof(char[256]),
372 "%d", hs->arj_reason[j]);
373 gtk_clist_append(hs->table, str);
378 for(j=0;j<=BRJ_REASONS;j++) {
379 if(hs->brj_reason[j]!=0) {
380 g_snprintf(str[0], sizeof(char[256]),
381 " %s", val_to_str(j,BandRejectReason_vals,"unknown reason "));
382 g_snprintf(str[1], sizeof(char[256]),
383 "%d", hs->brj_reason[j]);
384 gtk_clist_append(hs->table, str);
389 for(j=0;j<=DRQ_REASONS;j++) {
390 if(hs->drq_reason[j]!=0) {
391 g_snprintf(str[0], sizeof(char[256]),
392 " %s", val_to_str(j,DisengageReason_vals,"unknown reason "));
393 g_snprintf(str[1], sizeof(char[256]),
394 "%d", hs->drq_reason[j]);
395 gtk_clist_append(hs->table, str);
400 for(j=0;j<=DRJ_REASONS;j++) {
401 if(hs->drj_reason[j]!=0) {
402 g_snprintf(str[0], sizeof(char[256]),
403 " %s", val_to_str(j,DisengageRejectReason_vals,"unknown reason "));
404 g_snprintf(str[1], sizeof(char[256]),
405 "%d", hs->drj_reason[j]);
406 gtk_clist_append(hs->table, str);
411 for(j=0;j<=LRJ_REASONS;j++) {
412 if(hs->lrj_reason[j]!=0) {
413 g_snprintf(str[0], sizeof(char[256]),
414 " %s", val_to_str(j,LocationRejectReason_vals,"unknown reason "));
415 g_snprintf(str[1], sizeof(char[256]),
416 "%d", hs->lrj_reason[j]);
417 gtk_clist_append(hs->table, str);
421 case 29: /* IRQNak */
422 for(j=0;j<=IRQNAK_REASONS;j++) {
423 if(hs->irqnak_reason[j]!=0) {
424 g_snprintf(str[0], sizeof(char[256]),
425 " %s", val_to_str(j,InfoRequestNakReason_vals,"unknown reason "));
426 g_snprintf(str[1], sizeof(char[256]),
427 "%d", hs->irqnak_reason[j]);
428 gtk_clist_append(hs->table, str);
435 /* end of reason counter*/
439 for(i=0;i<=CS_MSG_TYPES;i++) {
440 if(hs->cs_msg[i]!=0) {
441 g_snprintf(str[0], sizeof(char[256]),
442 "%s", val_to_str(i,h323_message_body_vals,"unknown cs-messages "));
443 g_snprintf(str[1], sizeof(char[256]),
444 "%d", hs->cs_msg[i]);
445 gtk_clist_append(hs->table, str);
449 case 5: /* ReleaseComplete */
450 for(j=0;j<=REL_CMP_REASONS;j++) {
451 if(hs->rel_cmp_reason[j]!=0) {
452 g_snprintf(str[0], sizeof(char[256]),
453 " %s", val_to_str(j,ReleaseCompleteReason_vals,"unknown reason "));
454 g_snprintf(str[1], sizeof(char[256]),
455 "%d", hs->rel_cmp_reason[j]);
456 gtk_clist_append(hs->table, str);
460 case 6: /* Facility */
461 for(j=0;j<=FACILITY_REASONS;j++) {
462 if(hs->facility_reason[j]!=0) {
463 g_snprintf(str[0], sizeof(char[256]),
464 " %s", val_to_str(j,FacilityReason_vals,"unknown reason "));
465 g_snprintf(str[1], sizeof(char[256]),
466 "%d", hs->facility_reason[j]);
467 gtk_clist_append(hs->table, str);
477 gtk_widget_show(GTK_WIDGET(hs->table));
481 void protect_thread_critical_region(void);
482 void unprotect_thread_critical_region(void);
484 win_destroy_cb(GtkWindow *win _U_, gpointer data)
486 h225counter_t *hs=(h225counter_t *)data;
488 protect_thread_critical_region();
489 remove_tap_listener(hs);
490 unprotect_thread_critical_region();
500 static gchar *titles[]={"Message Type or Reason",
504 gtk_h225counter_init(char *optarg)
508 GString *error_string;
512 if(strncmp(optarg,"h225,counter,",13) == 0){
519 hs=g_malloc(sizeof(h225counter_t));
520 hs->filter=g_strdup(filter);
522 h225counter_reset(hs);
524 hs->win=window_new(GTK_WINDOW_TOPLEVEL, "Ethereal: H225 counters");
525 gtk_window_set_default_size(GTK_WINDOW(hs->win), 400, 200);
527 hs->vbox=gtk_vbox_new(FALSE, 3);
528 gtk_container_set_border_width(GTK_CONTAINER(hs->vbox), 12);
530 init_main_stat_window(hs->win, hs->vbox, "ITU-T H.225 Message and Message Reason Counter", filter);
532 /* init a scrolled window*/
533 hs->scrolled_window = scrolled_window_new(NULL, NULL);
535 hs->table = create_stat_table(hs->scrolled_window, hs->vbox, 2, titles);
537 error_string=register_tap_listener("h225", hs, filter, h225counter_reset, h225counter_packet, h225counter_draw);
539 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, error_string->str);
540 g_string_free(error_string, TRUE);
547 bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
548 gtk_box_pack_end(GTK_BOX(hs->vbox), bbox, FALSE, FALSE, 0);
550 close_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_CLOSE);
551 window_set_cancel_button(hs->win, close_bt, window_cancel_button_cb);
553 SIGNAL_CONNECT(hs->win, "delete_event", window_delete_event_cb, NULL);
554 SIGNAL_CONNECT(hs->win, "destroy", win_destroy_cb, hs);
556 gtk_widget_show_all(hs->win);
557 window_present(hs->win);
559 /* XXX - shouldn't this be retap_packets? */
560 redissect_packets(&cfile);
564 register_tap_listener_gtk_h225counter(void)
566 register_ethereal_tap("h225,counter", gtk_h225counter_init);
568 register_tap_menu_item("ITU-T H.225...", REGISTER_TAP_GROUP_NONE,
569 gtk_tap_dfilter_dlg_cb, NULL, NULL, &(h225_counter_dlg));