update BUTC and fill in all (bar one) dissectors
[obnox/wireshark/wip.git] / tap-gsm_astat.c
1 /* tap-gsm_astat.c
2  *
3  * Copyright 2003, Michael Lum <mlum [AT] telostech.com>
4  * In association with Telos Technology Inc.
5  *
6  * $Id$
7  *
8  * Ethereal - Network traffic analyzer
9  * By Gerald Combs <gerald@ethereal.com>
10  * Copyright 1998 Gerald Combs
11  *
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.
16  *
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.
21  *
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25  */
26
27 /*
28  * This TAP provides statistics for the GSM A Interface:
29  */
30
31 /* With MSVC and a libethereal.dll this file needs to import some variables 
32    in a special way. Therefore _NEED_VAR_IMPORT_ is defined. */ 
33 #define _NEED_VAR_IMPORT_
34
35 #ifdef HAVE_CONFIG_H
36 # include "config.h"
37 #endif
38
39 #include <stdio.h>
40
41 #ifdef HAVE_SYS_TYPES_H
42 # include <sys/types.h>
43 #endif
44
45 #include <string.h>
46 #include "epan/packet_info.h"
47 #include "epan/value_string.h"
48 #include <epan/tap.h>
49 #include <epan/dissectors/packet-bssap.h>
50 #include <epan/dissectors/packet-gsm_a.h>
51 #include "register.h"
52
53
54 typedef struct _gsm_a_stat_t {
55     int         bssmap_message_type[0xff];
56     int         dtap_mm_message_type[0xff];
57     int         dtap_rr_message_type[0xff];
58     int         dtap_cc_message_type[0xff];
59     int         dtap_gmm_message_type[0xff];
60     int         dtap_sms_message_type[0xff];
61     int         dtap_sm_message_type[0xff];
62     int         dtap_ss_message_type[0xff];
63 } gsm_a_stat_t;
64
65
66 static int
67 gsm_a_stat_packet(
68     void                        *tapdata,
69     packet_info                 *pinfo _U_,
70     epan_dissect_t              *edt _U_,
71     const void                  *data)
72 {
73     gsm_a_stat_t                *stat_p = tapdata;
74     const gsm_a_tap_rec_t       *tap_p = data;
75
76     switch (tap_p->pdu_type)
77     {
78     case BSSAP_PDU_TYPE_BSSMAP:
79         stat_p->bssmap_message_type[tap_p->message_type]++;
80         break;
81
82     case BSSAP_PDU_TYPE_DTAP:
83         switch (tap_p->protocol_disc)
84         {
85         case PD_CC:
86             stat_p->dtap_cc_message_type[tap_p->message_type]++;
87             break;
88         case PD_MM:
89             stat_p->dtap_mm_message_type[tap_p->message_type]++;
90             break;
91         case PD_RR:
92             stat_p->dtap_rr_message_type[tap_p->message_type]++;
93             break;
94         case PD_GMM:
95             stat_p->dtap_gmm_message_type[tap_p->message_type]++;
96             break;
97         case PD_SMS:
98             stat_p->dtap_sms_message_type[tap_p->message_type]++;
99             break;
100         case PD_SM:
101             stat_p->dtap_sm_message_type[tap_p->message_type]++;
102             break;
103         case PD_SS:
104             stat_p->dtap_ss_message_type[tap_p->message_type]++;
105             break;
106         default:
107             /*
108              * unsupported PD
109              */
110             return(0);
111         }
112         break;
113
114     default:
115         /*
116          * unknown PDU type !!!
117          */
118         return(0);
119     }
120
121     return(1);
122 }
123
124
125 static void
126 gsm_a_stat_draw(
127     void                *tapdata)
128 {
129     gsm_a_stat_t        *stat_p = tapdata;
130     guint8              i;
131
132
133     printf("\n");
134     printf("=========== GS=M A-i/f Statistics ============================\n");
135     printf("BSSMAP\n");
136     printf("Message (ID)Type                                        Number\n");
137
138     i = 0;
139     while (gsm_a_bssmap_msg_strings[i].strptr)
140     {
141         if (stat_p->bssmap_message_type[gsm_a_bssmap_msg_strings[i].value] > 0)
142         {
143             printf("0x%02x  %-50s%d\n",
144                 gsm_a_bssmap_msg_strings[i].value,
145                 gsm_a_bssmap_msg_strings[i].strptr,
146                 stat_p->bssmap_message_type[gsm_a_bssmap_msg_strings[i].value]);
147         }
148
149         i++;
150     }
151
152     printf("\nDTAP %s\n", gsm_a_pd_str[PD_MM]);
153     printf("Message (ID)Type                                        Number\n");
154
155     i = 0;
156     while (gsm_a_dtap_msg_mm_strings[i].strptr)
157     {
158         if (stat_p->dtap_mm_message_type[gsm_a_dtap_msg_mm_strings[i].value] > 0)
159         {
160             printf("0x%02x  %-50s%d\n",
161                 gsm_a_dtap_msg_mm_strings[i].value,
162                 gsm_a_dtap_msg_mm_strings[i].strptr,
163                 stat_p->dtap_mm_message_type[gsm_a_dtap_msg_mm_strings[i].value]);
164         }
165
166         i++;
167     }
168
169     printf("\nDTAP %s\n", gsm_a_pd_str[PD_RR]);
170     printf("Message (ID)Type                                        Number\n");
171
172     i = 0;
173     while (gsm_a_dtap_msg_rr_strings[i].strptr)
174     {
175         if (stat_p->dtap_rr_message_type[gsm_a_dtap_msg_rr_strings[i].value] > 0)
176         {
177             printf("0x%02x  %-50s%d\n",
178                 gsm_a_dtap_msg_rr_strings[i].value,
179                 gsm_a_dtap_msg_rr_strings[i].strptr,
180                 stat_p->dtap_rr_message_type[gsm_a_dtap_msg_rr_strings[i].value]);
181         }
182
183         i++;
184     }
185
186     printf("\nDTAP %s\n", gsm_a_pd_str[PD_CC]);
187     printf("Message (ID)Type                                        Number\n");
188
189     i = 0;
190     while (gsm_a_dtap_msg_cc_strings[i].strptr)
191     {
192         if (stat_p->dtap_cc_message_type[gsm_a_dtap_msg_cc_strings[i].value] > 0)
193         {
194             printf("0x%02x  %-50s%d\n",
195                 gsm_a_dtap_msg_cc_strings[i].value,
196                 gsm_a_dtap_msg_cc_strings[i].strptr,
197                 stat_p->dtap_cc_message_type[gsm_a_dtap_msg_cc_strings[i].value]);
198         }
199
200         i++;
201     }
202
203     printf("\nDTAP %s\n", gsm_a_pd_str[PD_GMM]);
204     printf("Message (ID)Type                                        Number\n");
205
206     i = 0;
207     while (gsm_a_dtap_msg_gmm_strings[i].strptr)
208     {
209         if (stat_p->dtap_gmm_message_type[gsm_a_dtap_msg_gmm_strings[i].value] > 0)
210         {
211             printf("0x%02x  %-50s%d\n",
212                 gsm_a_dtap_msg_gmm_strings[i].value,
213                 gsm_a_dtap_msg_gmm_strings[i].strptr,
214                 stat_p->dtap_gmm_message_type[gsm_a_dtap_msg_gmm_strings[i].value]);
215         }
216
217         i++;
218     }
219
220     printf("\nDTAP %s\n", gsm_a_pd_str[PD_SMS]);
221     printf("Message (ID)Type                                        Number\n");
222
223     i = 0;
224     while (gsm_a_dtap_msg_sms_strings[i].strptr)
225     {
226         if (stat_p->dtap_sms_message_type[gsm_a_dtap_msg_sms_strings[i].value] > 0)
227         {
228             printf("0x%02x  %-50s%d\n",
229                 gsm_a_dtap_msg_sms_strings[i].value,
230                 gsm_a_dtap_msg_sms_strings[i].strptr,
231                 stat_p->dtap_sms_message_type[gsm_a_dtap_msg_sms_strings[i].value]);
232         }
233
234         i++;
235     }
236
237     printf("\nDTAP %s\n", gsm_a_pd_str[PD_SM]);
238     printf("Message (ID)Type                                        Number\n");
239
240     i = 0;
241     while (gsm_a_dtap_msg_sm_strings[i].strptr)
242     {
243         if (stat_p->dtap_sm_message_type[gsm_a_dtap_msg_sm_strings[i].value] > 0)
244         {
245             printf("0x%02x  %-50s%d\n",
246                 gsm_a_dtap_msg_sm_strings[i].value,
247                 gsm_a_dtap_msg_sm_strings[i].strptr,
248                 stat_p->dtap_sm_message_type[gsm_a_dtap_msg_sm_strings[i].value]);
249         }
250
251         i++;
252     }
253
254     printf("\nDTAP %s\n", gsm_a_pd_str[PD_SS]);
255     printf("Message (ID)Type                                        Number\n");
256
257     i = 0;
258     while (gsm_a_dtap_msg_ss_strings[i].strptr)
259     {
260         if (stat_p->dtap_ss_message_type[gsm_a_dtap_msg_ss_strings[i].value] > 0)
261         {
262             printf("0x%02x  %-50s%d\n",
263                 gsm_a_dtap_msg_ss_strings[i].value,
264                 gsm_a_dtap_msg_ss_strings[i].strptr,
265                 stat_p->dtap_ss_message_type[gsm_a_dtap_msg_ss_strings[i].value]);
266         }
267
268         i++;
269     }
270
271     printf("==============================================================\n");
272 }
273
274
275 static void
276 gsm_a_stat_init(char *optarg)
277 {
278     gsm_a_stat_t        *stat_p;
279     GString             *err_p;
280
281
282     optarg = optarg;
283
284     stat_p = g_malloc(sizeof(gsm_a_stat_t));
285
286     memset(stat_p, 0, sizeof(gsm_a_stat_t));
287
288     err_p =
289         register_tap_listener("gsm_a", stat_p, NULL,
290             NULL,
291             gsm_a_stat_packet,
292             gsm_a_stat_draw);
293
294     if (err_p != NULL)
295     {
296         g_free(stat_p);
297         g_string_free(err_p, TRUE);
298
299         exit(1);
300     }
301 }
302
303
304 void
305 register_tap_listener_gsm_astat(void)
306 {
307     register_ethereal_tap("gsm_a,", gsm_a_stat_init);
308 }