aboutsummaryrefslogtreecommitdiffstats
path: root/ui/cli/tap-ansi_astat.c
blob: 6c8a418777fd692bd71ee8add32237a61b0e97c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/* tap-ansi_astat.c
 *
 * Copyright 2003, Michael Lum <mlum [AT] telostech.com>
 * In association with Telos Technology Inc.
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

/*
 * This TAP provides statistics for the ANSI A Interface:
 */

#include "config.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "epan/packet_info.h"
#include "epan/value_string.h"
#include <epan/tap.h>
#include <epan/stat_tap_ui.h>
#include <epan/dissectors/packet-bssap.h>
#include <epan/dissectors/packet-ansi_a.h>

void register_tap_listener_ansi_astat(void);

typedef struct _ansi_a_stat_t {
    int         bsmap_message_type[0xff];
    int         dtap_message_type[0xff];
} ansi_a_stat_t;


static int
ansi_a_stat_packet(
    void                        *tapdata,
    packet_info                 *pinfo _U_,
    epan_dissect_t              *edt _U_,
    const void                  *data)
{
    ansi_a_stat_t               *stat_p = (ansi_a_stat_t *)tapdata;
    const ansi_a_tap_rec_t      *tap_p = (const ansi_a_tap_rec_t *)data;


    switch (tap_p->pdu_type)
    {
    case BSSAP_PDU_TYPE_BSMAP:
        stat_p->bsmap_message_type[tap_p->message_type]++;
        break;

    case BSSAP_PDU_TYPE_DTAP:
        stat_p->dtap_message_type[tap_p->message_type]++;
        break;

    default:
        /*
         * unknown PDU type !!!
         */
        return(0);
    }

    return(1);
}


static void
ansi_a_stat_draw(
    void                *tapdata)
{
    ansi_a_stat_t       *stat_p = (ansi_a_stat_t *)tapdata;
    guint8              i;


    printf("\n");
    printf("=========== ANSI A-i/f Statistics ============================\n");
    printf("BSMAP\n");
    printf("Message (ID)Type                                        Number\n");

    i = 0;
    while (ansi_a_ios401_bsmap_strings[i].strptr)
    {
        if (stat_p->bsmap_message_type[ansi_a_ios401_bsmap_strings[i].value] > 0)
        {
            printf("0x%02x  %-50s%d\n",
                ansi_a_ios401_bsmap_strings[i].value,
                ansi_a_ios401_bsmap_strings[i].strptr,
                stat_p->bsmap_message_type[ansi_a_ios401_bsmap_strings[i].value]);
        }

        i++;
    }

    printf("\nDTAP\n");
    printf("Message (ID)Type                                        Number\n");

    i = 0;
    while (ansi_a_ios401_dtap_strings[i].strptr)
    {
        if (stat_p->dtap_message_type[ansi_a_ios401_dtap_strings[i].value] > 0)
        {
            printf("0x%02x  %-50s%d\n",
                ansi_a_ios401_dtap_strings[i].value,
                ansi_a_ios401_dtap_strings[i].strptr,
                stat_p->dtap_message_type[ansi_a_ios401_dtap_strings[i].value]);
        }

        i++;
    }

    printf("==============================================================\n");
}


static void
ansi_a_stat_init(const char *opt_arg _U_, void *userdata _U_)
{
    ansi_a_stat_t       *stat_p;
    GString             *err_p;

    stat_p = (ansi_a_stat_t *)g_malloc(sizeof(ansi_a_stat_t));

    memset(stat_p, 0, sizeof(ansi_a_stat_t));

    err_p =
        register_tap_listener("ansi_a", stat_p, NULL, 0,
            NULL,
            ansi_a_stat_packet,
            ansi_a_stat_draw);

    if (err_p != NULL)
    {
        g_free(stat_p);
        g_string_free(err_p, TRUE);

        exit(1);
    }
}


static stat_tap_ui ansi_a_stat_ui = {
    REGISTER_STAT_GROUP_GENERIC,
    NULL,
    "ansi_a,",
    ansi_a_stat_init,
    -1,
    0,
    NULL
};

void
register_tap_listener_ansi_astat(void)
{
    register_stat_tap_ui(&ansi_a_stat_ui, NULL);
}

/*
 * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
 *
 * Local variables:
 * c-basic-offset: 4
 * tab-width: 8
 * indent-tabs-mode: nil
 * End:
 *
 * vi: set shiftwidth=4 tabstop=8 expandtab:
 * :indentSize=4:tabSize=8:noTabs=true:
 */