Witness: enum witness_notifyResponse_type
[wireshark-wip.git] / ui / cli / tap-h225counter.c
blob81d8df66c0e626ebd3e0d02f2baf98de09c1f93d
1 /* tap_h225counter.c
2 * h225 message counter for wireshark
3 * Copyright 2003 Lars Roland
5 * $Id$
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include "config.h"
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
32 #include "epan/packet.h"
33 #include "epan/packet_info.h"
34 #include <epan/tap.h>
35 #include <epan/stat_cmd_args.h>
36 #include "epan/value_string.h"
37 #include <epan/dissectors/packet-h225.h>
39 /* following values represent the size of their valuestring arrays */
41 #define RAS_MSG_TYPES 33
42 #define CS_MSG_TYPES 13
44 #define GRJ_REASONS 8
45 #define RRJ_REASONS 18
46 #define URQ_REASONS 6
47 #define URJ_REASONS 6
48 #define ARJ_REASONS 22
49 #define BRJ_REASONS 8
50 #define DRQ_REASONS 3
51 #define DRJ_REASONS 4
52 #define LRJ_REASONS 16
53 #define IRQNAK_REASONS 4
54 #define REL_CMP_REASONS 26
55 #define FACILITY_REASONS 11
57 void register_tap_listener_h225counter(void);
59 /* used to keep track of the statistics for an entire program interface */
60 typedef struct _h225counter_t {
61 char *filter;
62 guint32 ras_msg[RAS_MSG_TYPES + 1];
63 guint32 cs_msg[CS_MSG_TYPES + 1];
64 guint32 grj_reason[GRJ_REASONS + 1];
65 guint32 rrj_reason[RRJ_REASONS + 1];
66 guint32 urq_reason[URQ_REASONS + 1];
67 guint32 urj_reason[URJ_REASONS + 1];
68 guint32 arj_reason[ARJ_REASONS + 1];
69 guint32 brj_reason[BRJ_REASONS + 1];
70 guint32 drq_reason[DRQ_REASONS + 1];
71 guint32 drj_reason[DRJ_REASONS + 1];
72 guint32 lrj_reason[LRJ_REASONS + 1];
73 guint32 irqnak_reason[IRQNAK_REASONS + 1];
74 guint32 rel_cmp_reason[REL_CMP_REASONS + 1];
75 guint32 facility_reason[FACILITY_REASONS + 1];
76 } h225counter_t;
79 static void
80 h225counter_reset(void *phs)
82 h225counter_t *hs=(h225counter_t *)phs;
83 char *save_filter = hs->filter;
85 memset(hs, 0, sizeof(h225counter_t));
87 hs->filter = save_filter;
90 static int
91 h225counter_packet(void *phs, packet_info *pinfo _U_, epan_dissect_t *edt _U_, const void *phi)
93 h225counter_t *hs=(h225counter_t *)phs;
94 const h225_packet_info *pi=(const h225_packet_info *)phi;
96 switch (pi->msg_type) {
98 case H225_RAS:
99 if(pi->msg_tag==-1) { /* uninitialized */
100 return 0;
102 else if (pi->msg_tag >= RAS_MSG_TYPES) { /* unknown */
103 hs->ras_msg[RAS_MSG_TYPES]++;
105 else {
106 hs->ras_msg[pi->msg_tag]++;
109 /* Look for reason tag */
110 if(pi->reason==-1) { /* uninitialized */
111 break;
114 switch(pi->msg_tag) {
116 case 2: /* GRJ */
117 if(pi->reason < GRJ_REASONS)
118 hs->grj_reason[pi->reason]++;
119 else
120 hs->grj_reason[GRJ_REASONS]++;
121 break;
122 case 5: /* RRJ */
123 if(pi->reason < RRJ_REASONS)
124 hs->rrj_reason[pi->reason]++;
125 else
126 hs->rrj_reason[RRJ_REASONS]++;
127 break;
128 case 6: /* URQ */
129 if(pi->reason < URQ_REASONS)
130 hs->urq_reason[pi->reason]++;
131 else
132 hs->urq_reason[URQ_REASONS]++;
133 break;
134 case 8: /* URJ */
135 if(pi->reason < URJ_REASONS)
136 hs->urj_reason[pi->reason]++;
137 else
138 hs->urj_reason[URJ_REASONS]++;
139 break;
140 case 11: /* ARJ */
141 if(pi->reason < ARJ_REASONS)
142 hs->arj_reason[pi->reason]++;
143 else
144 hs->arj_reason[ARJ_REASONS]++;
145 break;
146 case 14: /* BRJ */
147 if(pi->reason < BRJ_REASONS)
148 hs->brj_reason[pi->reason]++;
149 else
150 hs->brj_reason[BRJ_REASONS]++;
151 break;
152 case 15: /* DRQ */
153 if(pi->reason < DRQ_REASONS)
154 hs->drq_reason[pi->reason]++;
155 else
156 hs->drq_reason[DRQ_REASONS]++;
157 break;
158 case 17: /* DRJ */
159 if(pi->reason < DRJ_REASONS)
160 hs->drj_reason[pi->reason]++;
161 else
162 hs->drj_reason[DRJ_REASONS]++;
163 break;
164 case 20: /* LRJ */
165 if(pi->reason < LRJ_REASONS)
166 hs->lrj_reason[pi->reason]++;
167 else
168 hs->lrj_reason[LRJ_REASONS]++;
169 break;
170 case 29: /* IRQ Nak */
171 if(pi->reason < IRQNAK_REASONS)
172 hs->irqnak_reason[pi->reason]++;
173 else
174 hs->irqnak_reason[IRQNAK_REASONS]++;
175 break;
177 default:
178 /* do nothing */
179 break;
182 break;
184 case H225_CS:
185 if(pi->msg_tag==-1) { /* uninitialized */
186 return 0;
188 else if (pi->msg_tag >= CS_MSG_TYPES) { /* unknown */
189 hs->cs_msg[CS_MSG_TYPES]++;
191 else {
192 hs->cs_msg[pi->msg_tag]++;
195 /* Look for reason tag */
196 if(pi->reason==-1) { /* uninitialized */
197 break;
200 switch(pi->msg_tag) {
202 case 5: /* ReleaseComplete */
203 if(pi->reason < REL_CMP_REASONS)
204 hs->rel_cmp_reason[pi->reason]++;
205 else
206 hs->rel_cmp_reason[REL_CMP_REASONS]++;
207 break;
208 case 6: /* Facility */
209 if(pi->reason < FACILITY_REASONS)
210 hs->facility_reason[pi->reason]++;
211 else
212 hs->facility_reason[FACILITY_REASONS]++;
213 break;
214 default:
215 /* do nothing */
216 break;
219 break;
221 default:
222 return 0;
225 return 1;
229 static void
230 h225counter_draw(void *phs)
232 h225counter_t *hs=(h225counter_t *)phs;
233 int i,j;
235 printf("================== H225 Message and Reason Counter ==================\n");
236 printf("RAS-Messages:\n");
237 for(i=0;i<=RAS_MSG_TYPES;i++) {
238 if(hs->ras_msg[i]!=0) {
239 printf(" %s : %u\n", val_to_str(i,h225_RasMessage_vals,"unknown ras-messages "), hs->ras_msg[i]);
240 /* reason counter */
241 switch(i) {
242 case 2: /* GRJ */
243 for(j=0;j<=GRJ_REASONS;j++) {
244 if(hs->grj_reason[j]!=0) {
245 printf(" %s : %u\n", val_to_str(j,GatekeeperRejectReason_vals,"unknown reason "), hs->grj_reason[j]);
248 break;
249 case 5: /* RRJ */
250 for(j=0;j<=RRJ_REASONS;j++) {
251 if(hs->rrj_reason[j]!=0) {
252 printf(" %s : %u\n", val_to_str(j,RegistrationRejectReason_vals,"unknown reason "), hs->rrj_reason[j]);
255 break;
256 case 6: /* URQ */
257 for(j=0;j<=URQ_REASONS;j++) {
258 if(hs->urq_reason[j]!=0) {
259 printf(" %s : %u\n", val_to_str(j,UnregRequestReason_vals,"unknown reason "), hs->urq_reason[j]);
262 break;
263 case 8: /* URJ */
264 for(j=0;j<=URJ_REASONS;j++) {
265 if(hs->urj_reason[j]!=0) {
266 printf(" %s : %u\n", val_to_str(j,UnregRejectReason_vals,"unknown reason "), hs->urj_reason[j]);
269 break;
270 case 11: /* ARJ */
271 for(j=0;j<=ARJ_REASONS;j++) {
272 if(hs->arj_reason[j]!=0) {
273 printf(" %s : %u\n", val_to_str(j,AdmissionRejectReason_vals,"unknown reason "), hs->arj_reason[j]);
276 break;
277 case 14: /* BRJ */
278 for(j=0;j<=BRJ_REASONS;j++) {
279 if(hs->brj_reason[j]!=0) {
280 printf(" %s : %u\n", val_to_str(j,BandRejectReason_vals,"unknown reason "), hs->brj_reason[j]);
283 break;
284 case 15: /* DRQ */
285 for(j=0;j<=DRQ_REASONS;j++) {
286 if(hs->drq_reason[j]!=0) {
287 printf(" %s : %u\n", val_to_str(j,DisengageReason_vals,"unknown reason "), hs->drq_reason[j]);
290 break;
291 case 17: /* DRJ */
292 for(j=0;j<=DRJ_REASONS;j++) {
293 if(hs->drj_reason[j]!=0) {
294 printf(" %s : %u\n", val_to_str(j,DisengageRejectReason_vals,"unknown reason "), hs->drj_reason[j]);
297 break;
298 case 20: /* LRJ */
299 for(j=0;j<=LRJ_REASONS;j++) {
300 if(hs->lrj_reason[j]!=0) {
301 printf(" %s : %u\n", val_to_str(j,LocationRejectReason_vals,"unknown reason "), hs->lrj_reason[j]);
304 break;
305 case 29: /* IRQNak */
306 for(j=0;j<=IRQNAK_REASONS;j++) {
307 if(hs->irqnak_reason[j]!=0) {
308 printf(" %s : %u\n", val_to_str(j,InfoRequestNakReason_vals,"unknown reason "), hs->irqnak_reason[j]);
311 break;
312 default:
313 break;
315 /* end of reason counter*/
318 printf("Call Signalling:\n");
319 for(i=0;i<=CS_MSG_TYPES;i++) {
320 if(hs->cs_msg[i]!=0) {
321 printf(" %s : %u\n", val_to_str(i,T_h323_message_body_vals,"unknown cs-messages "), hs->cs_msg[i]);
322 /* reason counter */
323 switch(i) {
324 case 5: /* ReleaseComplete */
325 for(j=0;j<=REL_CMP_REASONS;j++) {
326 if(hs->rel_cmp_reason[j]!=0) {
327 printf(" %s : %u\n", val_to_str(j,h225_ReleaseCompleteReason_vals,"unknown reason "), hs->rel_cmp_reason[j]);
330 break;
331 case 6: /* Facility */
332 for(j=0;j<=FACILITY_REASONS;j++) {
333 if(hs->facility_reason[j]!=0) {
334 printf(" %s : %u\n", val_to_str(j,FacilityReason_vals,"unknown reason "), hs->facility_reason[j]);
337 break;
338 default:
339 break;
343 printf("=====================================================================\n");
347 static void
348 h225counter_init(const char *opt_arg, void* userdata _U_)
350 h225counter_t *hs;
351 GString *error_string;
353 hs = g_new(h225counter_t,1);
354 if(!strncmp(opt_arg,"h225,counter,",13)){
355 hs->filter=g_strdup(opt_arg+13);
356 } else {
357 hs->filter=NULL;
360 h225counter_reset(hs);
362 error_string=register_tap_listener("h225", hs, hs->filter, 0, NULL, h225counter_packet, h225counter_draw);
363 if(error_string){
364 /* error, we failed to attach to the tap. clean up */
365 g_free(hs->filter);
366 g_free(hs);
368 fprintf(stderr, "tshark: Couldn't register h225,counter tap: %s\n",
369 error_string->str);
370 g_string_free(error_string, TRUE);
371 exit(1);
376 void
377 register_tap_listener_h225counter(void)
379 register_stat_cmd_arg("h225,counter", h225counter_init,NULL);