Set the svn:eol-style property on all text files to "native", so that
[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 "tap.h"
49 #include "packet-bssap.h"
50 #include "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,
70     epan_dissect_t              *edt _U_,
71     void                        *data)
72 {
73     gsm_a_stat_t                *stat_p = tapdata;
74     gsm_a_tap_rec_t             *tap_p = data;
75
76
77     pinfo = pinfo;
78
79     switch (tap_p->pdu_type)
80     {
81     case BSSAP_PDU_TYPE_BSSMAP:
82         stat_p->bssmap_message_type[tap_p->message_type]++;
83         break;
84
85     case BSSAP_PDU_TYPE_DTAP:
86         switch (tap_p->protocol_disc)
87         {
88         case PD_CC:
89             stat_p->dtap_cc_message_type[tap_p->message_type]++;
90             break;
91         case PD_MM:
92             stat_p->dtap_mm_message_type[tap_p->message_type]++;
93             break;
94         case PD_RR:
95             stat_p->dtap_rr_message_type[tap_p->message_type]++;
96             break;
97         case PD_GMM:
98             stat_p->dtap_gmm_message_type[tap_p->message_type]++;
99             break;
100         case PD_SMS:
101             stat_p->dtap_sms_message_type[tap_p->message_type]++;
102             break;
103         case PD_SM:
104             stat_p->dtap_sm_message_type[tap_p->message_type]++;
105             break;
106         case PD_SS:
107             stat_p->dtap_ss_message_type[tap_p->message_type]++;
108             break;
109         default:
110             /*
111              * unsupported PD
112              */
113             return(0);
114         }
115         break;
116
117     default:
118         /*
119          * unknown PDU type !!!
120          */
121         return(0);
122     }
123
124     return(1);
125 }
126
127
128 static void
129 gsm_a_stat_draw(
130     void                *tapdata)
131 {
132     gsm_a_stat_t        *stat_p = tapdata;
133     guint8              i;
134
135
136     printf("\n");
137     printf("=========== GS=M A-i/f Statistics ============================\n");
138     printf("BSSMAP\n");
139     printf("Message (ID)Type                                        Number\n");
140
141     i = 0;
142     while (gsm_a_bssmap_msg_strings[i].strptr)
143     {
144         if (stat_p->bssmap_message_type[gsm_a_bssmap_msg_strings[i].value] > 0)
145         {
146             printf("0x%02x  %-50s%d\n",
147                 gsm_a_bssmap_msg_strings[i].value,
148                 gsm_a_bssmap_msg_strings[i].strptr,
149                 stat_p->bssmap_message_type[gsm_a_bssmap_msg_strings[i].value]);
150         }
151
152         i++;
153     }
154
155     printf("\nDTAP %s\n", gsm_a_pd_str[PD_MM]);
156     printf("Message (ID)Type                                        Number\n");
157
158     i = 0;
159     while (gsm_a_dtap_msg_mm_strings[i].strptr)
160     {
161         if (stat_p->dtap_mm_message_type[gsm_a_dtap_msg_mm_strings[i].value] > 0)
162         {
163             printf("0x%02x  %-50s%d\n",
164                 gsm_a_dtap_msg_mm_strings[i].value,
165                 gsm_a_dtap_msg_mm_strings[i].strptr,
166                 stat_p->dtap_mm_message_type[gsm_a_dtap_msg_mm_strings[i].value]);
167         }
168
169         i++;
170     }
171
172     printf("\nDTAP %s\n", gsm_a_pd_str[PD_RR]);
173     printf("Message (ID)Type                                        Number\n");
174
175     i = 0;
176     while (gsm_a_dtap_msg_rr_strings[i].strptr)
177     {
178         if (stat_p->dtap_rr_message_type[gsm_a_dtap_msg_rr_strings[i].value] > 0)
179         {
180             printf("0x%02x  %-50s%d\n",
181                 gsm_a_dtap_msg_rr_strings[i].value,
182                 gsm_a_dtap_msg_rr_strings[i].strptr,
183                 stat_p->dtap_rr_message_type[gsm_a_dtap_msg_rr_strings[i].value]);
184         }
185
186         i++;
187     }
188
189     printf("\nDTAP %s\n", gsm_a_pd_str[PD_CC]);
190     printf("Message (ID)Type                                        Number\n");
191
192     i = 0;
193     while (gsm_a_dtap_msg_cc_strings[i].strptr)
194     {
195         if (stat_p->dtap_cc_message_type[gsm_a_dtap_msg_cc_strings[i].value] > 0)
196         {
197             printf("0x%02x  %-50s%d\n",
198                 gsm_a_dtap_msg_cc_strings[i].value,
199                 gsm_a_dtap_msg_cc_strings[i].strptr,
200                 stat_p->dtap_cc_message_type[gsm_a_dtap_msg_cc_strings[i].value]);
201         }
202
203         i++;
204     }
205
206     printf("\nDTAP %s\n", gsm_a_pd_str[PD_GMM]);
207     printf("Message (ID)Type                                        Number\n");
208
209     i = 0;
210     while (gsm_a_dtap_msg_gmm_strings[i].strptr)
211     {
212         if (stat_p->dtap_gmm_message_type[gsm_a_dtap_msg_gmm_strings[i].value] > 0)
213         {
214             printf("0x%02x  %-50s%d\n",
215                 gsm_a_dtap_msg_gmm_strings[i].value,
216                 gsm_a_dtap_msg_gmm_strings[i].strptr,
217                 stat_p->dtap_gmm_message_type[gsm_a_dtap_msg_gmm_strings[i].value]);
218         }
219
220         i++;
221     }
222
223     printf("\nDTAP %s\n", gsm_a_pd_str[PD_SMS]);
224     printf("Message (ID)Type                                        Number\n");
225
226     i = 0;
227     while (gsm_a_dtap_msg_sms_strings[i].strptr)
228     {
229         if (stat_p->dtap_sms_message_type[gsm_a_dtap_msg_sms_strings[i].value] > 0)
230         {
231             printf("0x%02x  %-50s%d\n",
232                 gsm_a_dtap_msg_sms_strings[i].value,
233                 gsm_a_dtap_msg_sms_strings[i].strptr,
234                 stat_p->dtap_sms_message_type[gsm_a_dtap_msg_sms_strings[i].value]);
235         }
236
237         i++;
238     }
239
240     printf("\nDTAP %s\n", gsm_a_pd_str[PD_SM]);
241     printf("Message (ID)Type                                        Number\n");
242
243     i = 0;
244     while (gsm_a_dtap_msg_sm_strings[i].strptr)
245     {
246         if (stat_p->dtap_sm_message_type[gsm_a_dtap_msg_sm_strings[i].value] > 0)
247         {
248             printf("0x%02x  %-50s%d\n",
249                 gsm_a_dtap_msg_sm_strings[i].value,
250                 gsm_a_dtap_msg_sm_strings[i].strptr,
251                 stat_p->dtap_sm_message_type[gsm_a_dtap_msg_sm_strings[i].value]);
252         }
253
254         i++;
255     }
256
257     printf("\nDTAP %s\n", gsm_a_pd_str[PD_SS]);
258     printf("Message (ID)Type                                        Number\n");
259
260     i = 0;
261     while (gsm_a_dtap_msg_ss_strings[i].strptr)
262     {
263         if (stat_p->dtap_ss_message_type[gsm_a_dtap_msg_ss_strings[i].value] > 0)
264         {
265             printf("0x%02x  %-50s%d\n",
266                 gsm_a_dtap_msg_ss_strings[i].value,
267                 gsm_a_dtap_msg_ss_strings[i].strptr,
268                 stat_p->dtap_ss_message_type[gsm_a_dtap_msg_ss_strings[i].value]);
269         }
270
271         i++;
272     }
273
274     printf("==============================================================\n");
275 }
276
277
278 static void
279 gsm_a_stat_init(char *optarg)
280 {
281     gsm_a_stat_t        *stat_p;
282     GString             *err_p;
283
284
285     optarg = optarg;
286
287     stat_p = g_malloc(sizeof(gsm_a_stat_t));
288
289     memset(stat_p, 0, sizeof(gsm_a_stat_t));
290
291     err_p =
292         register_tap_listener("gsm_a", stat_p, NULL,
293             NULL,
294             gsm_a_stat_packet,
295             gsm_a_stat_draw);
296
297     if (err_p != NULL)
298     {
299         g_free(stat_p);
300         g_string_free(err_p, TRUE);
301
302         exit(1);
303     }
304 }
305
306
307 void
308 register_tap_listener_gsm_astat(void)
309 {
310     register_ethereal_tap("gsm_a,", gsm_a_stat_init);
311 }