aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-turbocell.c
blob: 597f10ce5691ef2199bb7041e26fe7d71ea4ace0 (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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/* packet-turbocell.c
 * Routines for Turbocell Header dissection
 * Copyright 2004, Colin Slater <kiltedtaco@xxxxxxxxx>
 *
 * $Id$
 *
 * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

/* This dissector was written entirely from reverse engineering captured
 * packets. No documentation was used or supplied by Karlnet. Hence, this
 * dissector is very incomplete. If you have any insight into decoding
 * these packets, or if you can supply packet captures from turbocell 
 * networks, contact kiltedtaco@xxxxxxxxx */

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

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

#include <glib.h>

#include <epan/packet.h>

#include "oui.h"

#define TURBOCELL_TYPE_BEACON	0x00
#define TURBOCELL_TYPE_DATA	0x01
#define TURBOCELL_TYPE_MANAGEMENT	0x11
#define TURBOCELL_TYPE_NAME	0xA0

/* Initialize the protocol and registered fields */
static int proto_turbocell = -1;
static int hf_turbocell_type = -1;
static int hf_turbocell_baseid = -1;
static int hf_turbocell_counter = -1;
static int hf_turbocell_station_number = -1;
static int hf_turbocell_name = -1;
static int hf_turbocell_base[6];

/* Initialize the subtree pointers */
static gint ett_turbocell = -1;
static gint ett_network = -1;

/* The ethernet dissector we hand off to */
static dissector_handle_t eth_handle;

/* Guesses at what the first byte of the protocol id means */
static const value_string turbocell_type_values[] = {
    { TURBOCELL_TYPE_BEACON,     "Beacon" },
    { TURBOCELL_TYPE_DATA,       "Data packet" },
    { TURBOCELL_TYPE_MANAGEMENT, "Management Packet" },
    { TURBOCELL_TYPE_NAME,       "Name" },
    { 0, NULL }
};


static void
dissect_turbocell(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{

    proto_item *ti, *name_item;
    proto_tree *turbocell_tree, *network_tree;
    tvbuff_t   *next_tvb;
    int i;

    if (tree) {
        ti = proto_tree_add_item(tree, proto_turbocell, tvb, 0, -1, FALSE);

        turbocell_tree = proto_item_add_subtree(ti, ett_turbocell);

        proto_tree_add_item(turbocell_tree, hf_turbocell_type, tvb, 0, 1, FALSE);
        proto_tree_add_item(turbocell_tree, hf_turbocell_baseid, tvb, 4, 6, FALSE);
        proto_tree_add_item(turbocell_tree, hf_turbocell_station_number, tvb, 10, 1, FALSE);
        proto_tree_add_item(turbocell_tree, hf_turbocell_counter, tvb, 2, 2, FALSE);

        if (tvb_get_guint8(tvb, 0) == TURBOCELL_TYPE_NAME) {
            name_item = proto_tree_add_item(turbocell_tree, hf_turbocell_name, tvb, 0x14, 30, FALSE);
            network_tree = proto_item_add_subtree(name_item, ett_network);

            for (i=0; i<6; i++) {
                proto_tree_add_item(network_tree, hf_turbocell_base[i], tvb, 0x34+8*i, 6, FALSE);
            }
        }
    }

    if (tvb_get_guint8(tvb, 0) == TURBOCELL_TYPE_BEACON) {
        if (check_col(pinfo->cinfo, COL_INFO))
            col_set_str(pinfo->cinfo, COL_INFO, "Turbocell Packet (Beacon)");
        if (check_col(pinfo->cinfo, COL_PROTOCOL))
            col_set_str(pinfo->cinfo, COL_PROTOCOL, "Turbocell");
    } else if ((tvb_get_guint8(tvb, 0) == TURBOCELL_TYPE_DATA) || (tvb_get_guint8(tvb, 0) == TURBOCELL_TYPE_MANAGEMENT)) {
        /* The hardcoded 0x1A offset here is where the ethernet header
         * appears to always start. It would not suprize me if it changed
         * between different networks, though. */
        next_tvb = tvb_new_subset(tvb, 0x1a, -1, -1);
        call_dissector(eth_handle, next_tvb, pinfo, tree);
    } else if (tvb_get_guint8(tvb, 0) == TURBOCELL_TYPE_NAME) {
        if (check_col(pinfo->cinfo, COL_INFO))
            col_set_str(pinfo->cinfo, COL_INFO, "Turbocell Packet (Name)");
        if (check_col(pinfo->cinfo, COL_PROTOCOL))
            col_set_str(pinfo->cinfo, COL_PROTOCOL, "Turbocell");
    } else {
        if (check_col(pinfo->cinfo, COL_INFO))
            col_set_str(pinfo->cinfo, COL_INFO, "Turbocell Packet (Unknown)");
        if (check_col(pinfo->cinfo, COL_PROTOCOL))
            col_set_str(pinfo->cinfo, COL_PROTOCOL, "Turbocell");
    }
}


/* Register the protocol with Wireshark */

void proto_register_turbocell(void)
{

    static hf_register_info hf[] = {
        { &hf_turbocell_type,
            { "Packet Type", "turbocell.type",
            FT_UINT8, BASE_HEX, VALS(turbocell_type_values), 0,
            NULL, HFILL }
        },
        { &hf_turbocell_baseid,
            { "Base Station ID", "turbocell.baseid",
            FT_ETHER, BASE_NONE, NULL, 0,
            "Seems to stay constant per base station", HFILL }
        },
        { &hf_turbocell_station_number,
            { "Station Number", "turbocell.stationnum",
            FT_UINT8, BASE_HEX, NULL, 0,
            "Seems to stay constant per station", HFILL }
        },
        { &hf_turbocell_counter,
            { "Counter", "turbocell.counter",
            FT_UINT16, BASE_DEC, NULL, 0,
            "Increments alot", HFILL }
        },
        { &hf_turbocell_name,
            { "Network Name", "turbocell.name",
            FT_STRINGZ, BASE_NONE, NULL, 0,
            "Name", HFILL }
        },
        { &hf_turbocell_base[0],
            { "Base 0", "turbocell.base0",
            FT_ETHER, BASE_NONE, NULL, 0,
            "Base station ID?", HFILL }
        },
        { &hf_turbocell_base[1],
            { "Base 1", "turbocell.base1",
            FT_ETHER, BASE_NONE, NULL, 0,
            "Base station ID?", HFILL }
        },
        { &hf_turbocell_base[2],
            { "Base 2", "turbocell.base2",
            FT_ETHER, BASE_NONE, NULL, 0,
            "Base station ID?", HFILL }
        },
        { &hf_turbocell_base[3],
            { "Base 3", "turbocell.base3",
            FT_ETHER, BASE_NONE, NULL, 0,
            "Base station ID?", HFILL }
        },
        { &hf_turbocell_base[4],
            { "Base 4", "turbocell.base4",
            FT_ETHER, BASE_NONE, NULL, 0,
            "Base station ID?", HFILL }
        },
        { &hf_turbocell_base[5],
            { "Base 5", "turbocell.base5",
            FT_ETHER, BASE_NONE, NULL, 0,
            "Base station ID?", HFILL }
        }
    };

    static gint *ett[] = {
        &ett_turbocell,
        &ett_network
    };

    proto_turbocell = proto_register_protocol("Turbocell Header", "Turbocell", "turbocell");

    register_dissector("turbocell", dissect_turbocell, proto_turbocell);

    proto_register_field_array(proto_turbocell, hf, array_length(hf));
    proto_register_subtree_array(ett, array_length(ett));
}


void proto_reg_handoff_turbocell(void)
{
    dissector_handle_t turbocell_handle;

    eth_handle = find_dissector("eth_withoutfcs");

    turbocell_handle = create_dissector_handle(dissect_turbocell, proto_turbocell);
}