Witness: enum witness_notifyResponse_type
[wireshark-wip.git] / ui / cli / tap-gsm_astat.c
blob92e98cc3aacf2e93f8413f04c75976655bf72101
1 /* tap-gsm_astat.c
3 * Copyright 2003, Michael Lum <mlum [AT] telostech.com>
4 * In association with Telos Technology Inc.
6 * $Id$
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 * This TAP provides statistics for the GSM A Interface:
31 #include "config.h"
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
37 #include "epan/packet_info.h"
38 #include "epan/value_string.h"
39 #include <epan/tap.h>
40 #include <epan/stat_cmd_args.h>
41 #include <epan/dissectors/packet-bssap.h>
42 #include <epan/dissectors/packet-gsm_a_common.h>
44 void register_tap_listener_gsm_astat(void);
46 typedef struct _gsm_a_stat_t {
47 int bssmap_message_type[0xff];
48 int dtap_mm_message_type[0xff];
49 int dtap_rr_message_type[0xff];
50 int dtap_cc_message_type[0xff];
51 int dtap_gmm_message_type[0xff];
52 int dtap_sms_message_type[0xff];
53 int dtap_sm_message_type[0xff];
54 int dtap_ss_message_type[0xff];
55 int dtap_tp_message_type[0xff];
56 int sacch_rr_message_type[0xff];
57 } gsm_a_stat_t;
60 static int
61 gsm_a_stat_packet(
62 void *tapdata,
63 packet_info *pinfo _U_,
64 epan_dissect_t *edt _U_,
65 const void *data)
67 gsm_a_stat_t *stat_p = (gsm_a_stat_t *)tapdata;
68 const gsm_a_tap_rec_t *tap_p = (const gsm_a_tap_rec_t *)data;
70 switch (tap_p->pdu_type)
72 case BSSAP_PDU_TYPE_BSSMAP:
73 stat_p->bssmap_message_type[tap_p->message_type]++;
74 break;
76 case BSSAP_PDU_TYPE_DTAP:
77 switch (tap_p->protocol_disc)
79 case PD_CC:
80 stat_p->dtap_cc_message_type[tap_p->message_type]++;
81 break;
82 case PD_MM:
83 stat_p->dtap_mm_message_type[tap_p->message_type]++;
84 break;
85 case PD_RR:
86 stat_p->dtap_rr_message_type[tap_p->message_type]++;
87 break;
88 case PD_GMM:
89 stat_p->dtap_gmm_message_type[tap_p->message_type]++;
90 break;
91 case PD_SMS:
92 stat_p->dtap_sms_message_type[tap_p->message_type]++;
93 break;
94 case PD_SM:
95 stat_p->dtap_sm_message_type[tap_p->message_type]++;
96 break;
97 case PD_SS:
98 stat_p->dtap_ss_message_type[tap_p->message_type]++;
99 break;
100 case PD_TP:
101 stat_p->dtap_tp_message_type[tap_p->message_type]++;
102 break;
103 default:
105 * unsupported PD
107 return(0);
109 break;
111 case GSM_A_PDU_TYPE_SACCH:
112 switch (tap_p->protocol_disc)
114 case 0:
115 stat_p->sacch_rr_message_type[tap_p->message_type]++;
116 break;
117 default:
118 /* unknown Short PD */
119 break;
121 break;
124 default:
126 * unknown PDU type !!!
128 return(0);
131 return(1);
135 static void
136 gsm_a_stat_draw(
137 void *tapdata)
139 gsm_a_stat_t *stat_p = (gsm_a_stat_t *)tapdata;
140 guint8 i;
143 printf("\n");
144 printf("=========== GS=M A-i/f Statistics ============================\n");
145 printf("BSSMAP\n");
146 printf("Message (ID)Type Number\n");
148 i = 0;
149 while (gsm_a_bssmap_msg_strings[i].strptr)
151 if (stat_p->bssmap_message_type[gsm_a_bssmap_msg_strings[i].value] > 0)
153 printf("0x%02x %-50s%d\n",
154 gsm_a_bssmap_msg_strings[i].value,
155 gsm_a_bssmap_msg_strings[i].strptr,
156 stat_p->bssmap_message_type[gsm_a_bssmap_msg_strings[i].value]);
159 i++;
162 printf("\nDTAP %s\n", gsm_a_pd_str[PD_MM]);
163 printf("Message (ID)Type Number\n");
165 i = 0;
166 while (gsm_a_dtap_msg_mm_strings[i].strptr)
168 if (stat_p->dtap_mm_message_type[gsm_a_dtap_msg_mm_strings[i].value] > 0)
170 printf("0x%02x %-50s%d\n",
171 gsm_a_dtap_msg_mm_strings[i].value,
172 gsm_a_dtap_msg_mm_strings[i].strptr,
173 stat_p->dtap_mm_message_type[gsm_a_dtap_msg_mm_strings[i].value]);
176 i++;
179 printf("\nDTAP %s\n", gsm_a_pd_str[PD_RR]);
180 printf("Message (ID)Type Number\n");
182 i = 0;
183 while (gsm_a_dtap_msg_rr_strings[i].strptr)
185 if (stat_p->dtap_rr_message_type[gsm_a_dtap_msg_rr_strings[i].value] > 0)
187 printf("0x%02x %-50s%d\n",
188 gsm_a_dtap_msg_rr_strings[i].value,
189 gsm_a_dtap_msg_rr_strings[i].strptr,
190 stat_p->dtap_rr_message_type[gsm_a_dtap_msg_rr_strings[i].value]);
193 i++;
196 printf("\nDTAP %s\n", gsm_a_pd_str[PD_CC]);
197 printf("Message (ID)Type Number\n");
199 i = 0;
200 while (gsm_a_dtap_msg_cc_strings[i].strptr)
202 if (stat_p->dtap_cc_message_type[gsm_a_dtap_msg_cc_strings[i].value] > 0)
204 printf("0x%02x %-50s%d\n",
205 gsm_a_dtap_msg_cc_strings[i].value,
206 gsm_a_dtap_msg_cc_strings[i].strptr,
207 stat_p->dtap_cc_message_type[gsm_a_dtap_msg_cc_strings[i].value]);
210 i++;
213 printf("\nDTAP %s\n", gsm_a_pd_str[PD_GMM]);
214 printf("Message (ID)Type Number\n");
216 i = 0;
217 while (gsm_a_dtap_msg_gmm_strings[i].strptr)
219 if (stat_p->dtap_gmm_message_type[gsm_a_dtap_msg_gmm_strings[i].value] > 0)
221 printf("0x%02x %-50s%d\n",
222 gsm_a_dtap_msg_gmm_strings[i].value,
223 gsm_a_dtap_msg_gmm_strings[i].strptr,
224 stat_p->dtap_gmm_message_type[gsm_a_dtap_msg_gmm_strings[i].value]);
227 i++;
230 printf("\nDTAP %s\n", gsm_a_pd_str[PD_SMS]);
231 printf("Message (ID)Type Number\n");
233 i = 0;
234 while (gsm_a_dtap_msg_sms_strings[i].strptr)
236 if (stat_p->dtap_sms_message_type[gsm_a_dtap_msg_sms_strings[i].value] > 0)
238 printf("0x%02x %-50s%d\n",
239 gsm_a_dtap_msg_sms_strings[i].value,
240 gsm_a_dtap_msg_sms_strings[i].strptr,
241 stat_p->dtap_sms_message_type[gsm_a_dtap_msg_sms_strings[i].value]);
244 i++;
247 printf("\nDTAP %s\n", gsm_a_pd_str[PD_SM]);
248 printf("Message (ID)Type Number\n");
250 i = 0;
251 while (gsm_a_dtap_msg_sm_strings[i].strptr)
253 if (stat_p->dtap_sm_message_type[gsm_a_dtap_msg_sm_strings[i].value] > 0)
255 printf("0x%02x %-50s%d\n",
256 gsm_a_dtap_msg_sm_strings[i].value,
257 gsm_a_dtap_msg_sm_strings[i].strptr,
258 stat_p->dtap_sm_message_type[gsm_a_dtap_msg_sm_strings[i].value]);
261 i++;
264 printf("\nDTAP %s\n", gsm_a_pd_str[PD_SS]);
265 printf("Message (ID)Type Number\n");
267 i = 0;
268 while (gsm_a_dtap_msg_ss_strings[i].strptr)
270 if (stat_p->dtap_ss_message_type[gsm_a_dtap_msg_ss_strings[i].value] > 0)
272 printf("0x%02x %-50s%d\n",
273 gsm_a_dtap_msg_ss_strings[i].value,
274 gsm_a_dtap_msg_ss_strings[i].strptr,
275 stat_p->dtap_ss_message_type[gsm_a_dtap_msg_ss_strings[i].value]);
278 i++;
281 printf("\nDTAP %s\n", gsm_a_pd_str[PD_TP]);
282 printf("Message (ID)Type Number\n");
284 i = 0;
285 while (gsm_a_dtap_msg_tp_strings[i].strptr)
287 if (stat_p->dtap_tp_message_type[gsm_a_dtap_msg_tp_strings[i].value] > 0)
289 printf("0x%02x %-50s%d\n",
290 gsm_a_dtap_msg_tp_strings[i].value,
291 gsm_a_dtap_msg_tp_strings[i].strptr,
292 stat_p->dtap_tp_message_type[gsm_a_dtap_msg_tp_strings[i].value]);
295 i++;
298 printf("\nSACCH Radio Resources Management messages\n");
299 printf("Message (ID)Type Number\n");
301 i = 0;
302 while (gsm_a_rr_short_pd_msg_strings[i].strptr)
304 if (stat_p->sacch_rr_message_type[gsm_a_rr_short_pd_msg_strings[i].value] > 0)
306 printf("0x%02x %-50s%d\n",
307 gsm_a_rr_short_pd_msg_strings[i].value,
308 gsm_a_rr_short_pd_msg_strings[i].strptr,
309 stat_p->sacch_rr_message_type[gsm_a_rr_short_pd_msg_strings[i].value]);
312 i++;
315 printf("==============================================================\n");
319 static void
320 gsm_a_stat_init(const char *opt_arg _U_,void* userdata _U_)
322 gsm_a_stat_t *stat_p;
323 GString *err_p;
325 stat_p = g_new(gsm_a_stat_t,1);
327 memset(stat_p, 0, sizeof(gsm_a_stat_t));
329 err_p =
330 register_tap_listener("gsm_a", stat_p, NULL, 0,
331 NULL,
332 gsm_a_stat_packet,
333 gsm_a_stat_draw);
335 if (err_p != NULL)
337 g_free(stat_p);
338 g_string_free(err_p, TRUE);
340 exit(1);
345 void
346 register_tap_listener_gsm_astat(void)
348 register_stat_cmd_arg("gsm_a,", gsm_a_stat_init,NULL);