aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-aruba-papi.c
blob: 1155a84c18415d0a558205093ba1281397630091 (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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
/* packet-aruba-papi.c
 * Routines for Aruba PAPI dissection
 * Copyright 2010, Alexis La Goutte <alexis.lagoutte at gmail dot com>
 *
 * Real name of PAPI : Protocol Application Program Interface
 * 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.
 */

#include "config.h"

#include <epan/packet.h>
#include <epan/prefs.h>
#include <epan/expert.h>

/* This is not IANA assigned nor registered */
#define UDP_PORT_PAPI 8211

void proto_register_papi(void);
void proto_reg_handoff_papi(void);

/* Initialize the protocol and registered fields */
static int proto_papi = -1;
static int hf_papi_hdr_id = -1;
static int hf_papi_hdr_version = -1;
static int hf_papi_hdr_ip_destination = -1;
static int hf_papi_hdr_ip_source = -1;
static int hf_papi_hdr_port_destination = -1;
static int hf_papi_hdr_port_source = -1;
static int hf_papi_hdr_unknown = -1;
static int hf_papi_hdr_sequence = -1;
static int hf_papi_hdr_checksum = -1;

static int hf_papi_debug = -1;
static int hf_papi_debug_text = -1;
static int hf_papi_debug_text_length = -1;
static int hf_papi_debug_48bits = -1;
static int hf_papi_debug_8bits = -1;
static int hf_papi_debug_16bits = -1;
static int hf_papi_debug_32bits = -1;
static int hf_papi_debug_ipv4 = -1;
static int hf_papi_debug_64bits = -1;
static int hf_papi_debug_bytes = -1;
static int hf_papi_debug_bytes_length = -1;

static expert_field ei_papi_debug_unknown = EI_INIT;

/* Global PAPI Debug Preference */
static gboolean g_papi_debug = FALSE;

static dissector_handle_t data_handle;

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

/* PAPI Debug loop ! */
static int
dissect_papi_debug(tvbuff_t *tvb, packet_info *pinfo, guint offset, proto_tree *tree)
{
    proto_item *ti;
    proto_tree *debug_tree, *debug_sub_tree;


    ti = proto_tree_add_item(tree, hf_papi_debug, tvb, offset, -1, ENC_NA);
    debug_tree = proto_item_add_subtree(ti, ett_papi);

    while(offset < tvb_reported_length(tvb)) {
        switch(tvb_get_guint8(tvb,offset)) {
        case 0x00:
            ti = proto_tree_add_item(debug_tree, hf_papi_debug_text, tvb, offset+3, tvb_get_ntohs(tvb,offset+1), ENC_ASCII|ENC_NA);
            debug_sub_tree = proto_item_add_subtree(ti, ett_papi);
            proto_tree_add_item(debug_sub_tree, hf_papi_debug_text_length, tvb, offset+1, 2, ENC_BIG_ENDIAN);
            offset += tvb_get_ntohs(tvb, offset+1) + 3;
        break;
        case 0x01:
            proto_tree_add_item(debug_tree, hf_papi_debug_48bits, tvb, offset+1, 6, ENC_BIG_ENDIAN);
            offset += 7;
        break;
        case 0x02:
            proto_tree_add_item(debug_tree, hf_papi_debug_8bits, tvb, offset+1, 1, ENC_BIG_ENDIAN);
            offset += 2;
        break;
        case 0x03:
            proto_tree_add_item(debug_tree, hf_papi_debug_16bits, tvb, offset+1, 2, ENC_BIG_ENDIAN);
            offset += 3;
        break;
        case 0x04:
            proto_tree_add_item(debug_tree, hf_papi_debug_32bits, tvb, offset+1, 4, ENC_BIG_ENDIAN);
            offset += 5;
        break;
        case 0x05:
            proto_tree_add_item(debug_tree, hf_papi_debug_ipv4, tvb, offset+1, 4, ENC_BIG_ENDIAN);
            offset += 5;
        break;
        case 0x07:
            proto_tree_add_item(debug_tree, hf_papi_debug_16bits, tvb, offset+1, 2, ENC_BIG_ENDIAN);
            offset += 3;
        break;
        case 0x08:
            ti = proto_tree_add_item(debug_tree, hf_papi_debug_bytes, tvb, offset+3, tvb_get_ntohs(tvb,offset+1), ENC_NA);
            debug_sub_tree = proto_item_add_subtree(ti, ett_papi);
            proto_tree_add_item(debug_sub_tree, hf_papi_debug_bytes_length, tvb, offset+1, 2, ENC_BIG_ENDIAN);
            offset += tvb_get_ntohs(tvb,offset+1) + 3;
        break;
        case 0x09:
            proto_tree_add_item(debug_tree, hf_papi_debug_64bits, tvb, offset+1, 8, ENC_BIG_ENDIAN);
            offset += 9;
        break;
        default:
            proto_tree_add_expert_format(debug_tree, pinfo, &ei_papi_debug_unknown, tvb, offset, 1, "Unknown (%d)", tvb_get_guint8(tvb, offset));
            offset +=1;
           }
    }

    return offset;
}

static gboolean
dissect_papi(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
{
    proto_item *ti;
    proto_tree *papi_tree;
    guint     offset = 0;
    tvbuff_t *next_tvb;


    /* All PAPI packet start with 0x4972 !  */
    if ( tvb_get_ntohs(tvb, offset) != 0x4972 )
        return FALSE;

    col_set_str(pinfo->cinfo, COL_PROTOCOL, "PAPI");
    col_set_str(pinfo->cinfo, COL_INFO, "PAPI - Aruba AP Control Protocol");

    ti = proto_tree_add_item(tree, proto_papi, tvb, 0, -1, ENC_NA);
    papi_tree = proto_item_add_subtree(ti, ett_papi);

    proto_tree_add_item(papi_tree, hf_papi_hdr_id, tvb, offset, 2, ENC_BIG_ENDIAN);
    offset += 2;

    proto_tree_add_item(papi_tree, hf_papi_hdr_version, tvb, offset, 2, ENC_BIG_ENDIAN);
    offset += 2;

    proto_tree_add_item(papi_tree, hf_papi_hdr_ip_destination, tvb, offset, 4, ENC_BIG_ENDIAN);
    offset += 4;

    proto_tree_add_item(papi_tree, hf_papi_hdr_ip_source, tvb, offset, 4, ENC_BIG_ENDIAN);
    offset += 4;

    proto_tree_add_item(papi_tree, hf_papi_hdr_unknown, tvb, offset, 2, ENC_BIG_ENDIAN);
    offset += 2;

    proto_tree_add_item(papi_tree, hf_papi_hdr_unknown, tvb, offset, 2, ENC_BIG_ENDIAN);
    offset += 2;

    proto_tree_add_item(papi_tree, hf_papi_hdr_port_source, tvb, offset, 2, ENC_BIG_ENDIAN);
    offset += 2;

    proto_tree_add_item(papi_tree, hf_papi_hdr_port_destination, tvb, offset, 2, ENC_BIG_ENDIAN);
    offset += 2;

    proto_tree_add_item(papi_tree, hf_papi_hdr_unknown, tvb, offset, 2, ENC_BIG_ENDIAN);
    offset += 2;

    proto_tree_add_item(papi_tree, hf_papi_hdr_unknown, tvb, offset, 2, ENC_BIG_ENDIAN);
    offset += 2;

    proto_tree_add_item(papi_tree, hf_papi_hdr_sequence, tvb, offset, 2, ENC_BIG_ENDIAN);
    offset += 2;

    proto_tree_add_item(papi_tree, hf_papi_hdr_unknown, tvb, offset, 2, ENC_BIG_ENDIAN);
    offset += 2;

    proto_tree_add_item(papi_tree, hf_papi_hdr_checksum, tvb, offset, 16, ENC_NA);
    offset += 16;

    if(g_papi_debug)
    {
        offset = dissect_papi_debug(tvb, pinfo, offset, papi_tree);
    }

    next_tvb = tvb_new_subset_remaining(tvb, offset);
    call_dissector(data_handle,next_tvb, pinfo, tree);

    return(TRUE);
}

void
proto_register_papi(void)
{
    module_t *papi_module;

    static hf_register_info hf[] = {
        { &hf_papi_hdr_id,
            { "ID", "papi.hdr.id",
            FT_UINT16, BASE_HEX, NULL, 0x0,
            "PAPI Header ID (Magic Number ?)", HFILL }
        },
        { &hf_papi_hdr_version,
            { "Version",  "papi.hdr.version",
            FT_UINT16, BASE_DEC, NULL, 0x0,
            "PAPI Protocol Version", HFILL }
        },
        { &hf_papi_hdr_ip_destination,
            { "IP Destination", "papi.hdr.ip.dst",
            FT_IPv4, BASE_NONE, NULL, 0x0,
            NULL, HFILL }
        },
        { &hf_papi_hdr_ip_source,
            { "IP Source", "papi.hdr.ip.src",
            FT_IPv4, BASE_NONE, NULL, 0x0,
            NULL, HFILL }
        },
        { &hf_papi_hdr_port_source,
            { "Port Source", "papi.hdr.port.src",
            FT_UINT16, BASE_DEC, NULL, 0x0,
            NULL, HFILL }
        },
        { &hf_papi_hdr_port_destination,
            { "Port Destination", "papi.hdr.port.destination",
            FT_UINT16, BASE_DEC, NULL, 0x0,
            NULL, HFILL }
        },
        { &hf_papi_hdr_unknown,
            { "Unknown", "papi.hdr.unknown",
            FT_UINT16, BASE_DEC|BASE_HEX, NULL, 0x0,
            NULL, HFILL }
        },
        { &hf_papi_hdr_sequence,
            { "Sequence", "papi.hdr.sequence",
            FT_UINT16, BASE_DEC, NULL, 0x0,
            NULL, HFILL }
        },
        { &hf_papi_hdr_checksum,
            { "Checksum", "papi.hdr.checksum",
            FT_BYTES, BASE_NONE, NULL, 0x0,
            NULL, HFILL }
        },

        { &hf_papi_debug,
            { "Debug", "papi.debug",
            FT_NONE, BASE_NONE, NULL, 0x0,
            NULL, HFILL }
        },
        { &hf_papi_debug_text,
            { "Debug (Text)", "papi.debug.text",
            FT_STRING, BASE_NONE, NULL, 0x0,
            NULL, HFILL }
        },
        { &hf_papi_debug_text_length,
            { "Debug Text Length", "papi.debug.text_length",
            FT_UINT16, BASE_DEC, NULL, 0x0,
            NULL, HFILL }
        },
        { &hf_papi_debug_bytes,
            { "Debug (Bytes)", "papi.debug.bytes",
            FT_BYTES, BASE_NONE, NULL, 0x0,
            NULL, HFILL }
        },
        { &hf_papi_debug_bytes_length,
            { "Debug Bytes Length", "papi.debug.bytes_length",
            FT_UINT16, BASE_DEC, NULL, 0x0,
            NULL, HFILL }
        },
        { &hf_papi_debug_48bits,
            { "Debug (48 Bits)", "papi.debug.48bits",
            FT_UINT64, BASE_DEC, NULL, 0x0,
            NULL, HFILL }
        },
        { &hf_papi_debug_8bits,
            { "Debug (8 Bits)", "papi.debug.8bits",
            FT_UINT8, BASE_DEC, NULL, 0x0,
            NULL, HFILL }
        },
        { &hf_papi_debug_16bits,
            { "Debug (16 Bits)", "papi.debug.16bits",
            FT_UINT16, BASE_DEC, NULL, 0x0,
            NULL, HFILL }
        },
        { &hf_papi_debug_32bits,
            { "Debug (32 Bits)", "papi.debug.32bits",
            FT_UINT32, BASE_DEC, NULL, 0x0,
            NULL, HFILL }
        },
        { &hf_papi_debug_ipv4,
            { "Debug (IPv4)", "papi.debug.ipv4",
            FT_IPv4, BASE_NONE, NULL, 0x0,
            NULL, HFILL }
        },
        { &hf_papi_debug_64bits,
            { "Debug (64 Bits)", "papi.debug.64bits",
            FT_UINT64, BASE_DEC, NULL, 0x0,
            NULL, HFILL }
        },
    };

    /* Setup protocol subtree array */
    static gint *ett[] = {
        &ett_papi
    };

    static ei_register_info ei[] = {
        { &ei_papi_debug_unknown, { "papi.debug.unknown", PI_PROTOCOL, PI_WARN, "Unknown", EXPFILL }},
    };

    expert_module_t* expert_papi;

    proto_papi = proto_register_protocol("Aruba PAPI", "PAPI", "papi");

    proto_register_field_array(proto_papi, hf, array_length(hf));
    proto_register_subtree_array(ett, array_length(ett));
    expert_papi = expert_register_protocol(proto_papi);
    expert_register_field_array(expert_papi, ei, array_length(ei));

    papi_module = prefs_register_protocol(proto_papi, NULL);

    prefs_register_bool_preference(papi_module, "experimental_decode",
                       "Do experimental decode",
                       "Attempt to decode parts of the message that aren't fully understood yet",
                       &g_papi_debug);
}


void
proto_reg_handoff_papi(void)
{
    dissector_handle_t papi_handle;

    papi_handle = create_dissector_handle(dissect_papi, proto_papi);
    dissector_add_uint("udp.port", UDP_PORT_PAPI, papi_handle);
    data_handle = find_dissector("data");
}
/*
 * 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:
 */