3a9e9dd2f79cddc4b4141502a491be3b7fa41dd3
[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  * Ethereal - 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     if (check_col(pinfo->cinfo, COL_PROTOCOL))
72         col_set_str(pinfo->cinfo, COL_PROTOCOL, "BOFL");
73
74     if (check_col(pinfo->cinfo, COL_INFO))
75         col_clear(pinfo->cinfo, COL_INFO);
76
77     if (tree) {
78         ti = proto_tree_add_item(tree, proto_bofl, tvb, 0, -1, FALSE);
79         bofl_tree = proto_item_add_subtree(ti, ett_bofl);
80     }
81
82     pdu = tvb_get_ntohl(tvb, 0);
83     if (check_col(pinfo->cinfo, COL_INFO)) {
84         col_add_fstr(pinfo->cinfo, COL_INFO,
85             "PDU: 0x%08x", pdu);
86     }
87     if (tree)
88         proto_tree_add_uint(bofl_tree, hf_bofl_pdu, tvb, 0, 4, pdu);
89
90     sequence = tvb_get_ntohl(tvb, 4);
91     if (check_col(pinfo->cinfo, COL_INFO)) {
92         col_append_fstr(pinfo->cinfo, COL_INFO,
93             " Sequence: %u", sequence);
94     }
95     if (tree) {
96         proto_tree_add_uint(bofl_tree, hf_bofl_sequence, tvb, 4, 4, sequence);
97
98         len = tvb_length_remaining(tvb, 8);
99         if (len > 0)
100             proto_tree_add_text(bofl_tree, tvb, 8, len,
101                 "Padding (%d byte)", len);
102     }
103 }
104
105
106 void
107 proto_register_bofl(void)
108 {
109     static hf_register_info hf[] = {
110         { &hf_bofl_pdu,
111           { "PDU", "bofl.pdu",
112             FT_UINT32, BASE_HEX, NULL, 0,
113             "PDU; normally equals 0x01010000 or 0x01011111", HFILL }
114         },
115         { &hf_bofl_sequence,
116           { "Sequence", "bofl.sequence",
117             FT_UINT32, BASE_DEC, NULL, 0,
118             "incremental counter", HFILL }
119         }
120     };
121
122     static gint *ett[] = {
123         &ett_bofl,
124     };
125
126     proto_bofl = proto_register_protocol("Wellfleet Breath of Life",
127         "BOFL", "bofl");
128     proto_register_field_array(proto_bofl, hf, array_length(hf));
129     proto_register_subtree_array(ett, array_length(ett));
130 }
131
132
133 void
134 proto_reg_handoff_bofl(void)
135 {
136     dissector_handle_t bofl_handle;
137
138     bofl_handle = create_dissector_handle(dissect_bofl, proto_bofl);
139     dissector_add("ethertype", ETHER_TYPE_BOFL, bofl_handle);
140 }