0d872e620bb4e24eab601634a0ab17df370505e0
[obnox/wireshark/wip.git] / epan / dissectors / packet-bofl.c
1 /* packet-bofl.c
2  * Routines for Wellfleet BOFL dissection
3  * Author: Endoh Akira (endoh@netmarks.co.jp)
4  *
5  * $Id$
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@unicom.net>
9  * Copyright 1998 Gerald Combs
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  * 
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  * 
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24  *
25  * The following information was copied from
26  * http://www.protocols.com/pbook/bridge.htm#WellfleetBOFL
27  *
28  * The Wellfleet Breath of Life (BOFL) protocol is used as a line sensing
29  * protocol on:
30  *
31  * - Ethernet LANs to detect transmitter jams.
32  * - Synchronous lines running WFLT STD protocols to determine if the line
33  *   is up.
34  * - Dial backup PPP lines.
35  *
36  * The frame format of Wellfleet BOFL is shown following the Ethernet header
37  * in the following illustration:
38  *
39  *  Destination   Source    8102    PDU   Sequence   Padding
40  *       6           6        2      4       4       n bytes
41  */
42
43 #ifdef HAVE_CONFIG_H
44 # include "config.h"
45 #endif
46
47 #include <glib.h>
48
49 #include <epan/packet.h>
50
51 #define ETHER_TYPE_BOFL 0x8102
52 #define BOFL_MIN_LEN    8
53
54 /* Initialize the protocol and registered fields */
55 static int proto_bofl       = -1;
56 static int hf_bofl_pdu      = -1;
57 static int hf_bofl_sequence = -1;
58
59 /* Initialize the subtree pointers */
60 static gint ett_bofl = -1;
61
62 /* Code to actually dissect the packets */
63 static void
64 dissect_bofl(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
65 {
66     proto_item  *ti;
67     proto_tree  *bofl_tree = NULL;
68     gint        len;
69     guint32     pdu, sequence;
70
71     col_set_str(pinfo->cinfo, COL_PROTOCOL, "BOFL");
72
73     col_clear(pinfo->cinfo, COL_INFO);
74
75     if (tree) {
76         ti = proto_tree_add_item(tree, proto_bofl, tvb, 0, -1, ENC_BIG_ENDIAN);
77         bofl_tree = proto_item_add_subtree(ti, ett_bofl);
78     }
79
80     pdu = tvb_get_ntohl(tvb, 0);
81         col_add_fstr(pinfo->cinfo, COL_INFO,
82             "PDU: 0x%08x", pdu);
83     if (tree)
84                 proto_tree_add_uint(bofl_tree, hf_bofl_pdu, tvb, 0, 4, pdu);
85
86     sequence = tvb_get_ntohl(tvb, 4);
87
88         col_append_fstr(pinfo->cinfo, COL_INFO,
89             " Sequence: %u", sequence);
90     if (tree) {
91                 proto_tree_add_uint(bofl_tree, hf_bofl_sequence, tvb, 4, 4, sequence);
92
93         len = tvb_length_remaining(tvb, 8);
94         if (len > 0)
95             proto_tree_add_text(bofl_tree, tvb, 8, len,
96                 "Padding (%d byte)", len);
97     }
98 }
99
100
101 void
102 proto_register_bofl(void)
103 {
104     static hf_register_info hf[] = {
105         { &hf_bofl_pdu,
106           { "PDU", "bofl.pdu",
107             FT_UINT32, BASE_HEX, NULL, 0,
108             "PDU; normally equals 0x01010000 or 0x01011111", HFILL }
109         },
110         { &hf_bofl_sequence,
111           { "Sequence", "bofl.sequence",
112             FT_UINT32, BASE_DEC, NULL, 0,
113             "incremental counter", HFILL }
114         }
115     };
116
117     static gint *ett[] = {
118         &ett_bofl,
119     };
120
121     proto_bofl = proto_register_protocol("Wellfleet Breath of Life",
122         "BOFL", "bofl");
123     proto_register_field_array(proto_bofl, hf, array_length(hf));
124     proto_register_subtree_array(ett, array_length(ett));
125 }
126
127
128 void
129 proto_reg_handoff_bofl(void)
130 {
131     dissector_handle_t bofl_handle;
132
133     bofl_handle = create_dissector_handle(dissect_bofl, proto_bofl);
134     dissector_add_uint("ethertype", ETHER_TYPE_BOFL, bofl_handle);
135 }