Add in the SliMP3 data protocol dissector.
[obnox/wireshark/wip.git] / packet-dec-bpdu.c
1 /* packet-dec-bpdu.c
2  * Routines for DEC BPDU (DEC Spanning Tree Protocol) disassembly
3  *
4  * $Id: packet-dec-bpdu.c,v 1.9 2001/12/10 00:25:27 guy Exp $
5  *
6  * Copyright 2001 Paul Ionescu <paul@acorp.ro>
7  * 
8  * Ethereal - Network traffic analyzer
9  * By Gerald Combs <gerald@ethereal.com>
10  * Copyright 1998 Gerald Combs
11  * 
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  * 
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  * 
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25  */
26
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #ifdef HAVE_SYS_TYPES_H
32 # include <sys/types.h>
33 #endif
34
35 #ifdef HAVE_NETINET_IN_H
36 # include <netinet/in.h>
37 #endif
38
39 #include <stdio.h>
40 #include <string.h>
41 #include <glib.h>
42 #include "packet.h"
43 #include "resolv.h"
44 #include "etypes.h"
45 #include "ppptypes.h"
46
47 /* Offsets of fields within a BPDU */
48
49 #define BPDU_DEC_CODE            0
50 #define BPDU_TYPE                1
51 #define BPDU_VERSION             2
52 #define BPDU_FLAGS               3
53 #define BPDU_ROOT_PRI            4
54 #define BPDU_ROOT_MAC            6
55 #define BPDU_ROOT_PATH_COST     12
56 #define BPDU_BRIDGE_PRI         14
57 #define BPDU_BRIDGE_MAC         16
58 #define BPDU_PORT_IDENTIFIER    22
59 #define BPDU_MESSAGE_AGE        23
60 #define BPDU_HELLO_TIME         24
61 #define BPDU_MAX_AGE            25
62 #define BPDU_FORWARD_DELAY      26
63
64 #define DEC_BPDU_SIZE           27
65
66
67 static int proto_dec_bpdu = -1;
68
69 static gint ett_dec_bpdu = -1;
70
71 static void
72 dissect_dec_bpdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
73       guint8  protocol_identifier;
74       guint8  protocol_version;
75       guint8  bpdu_type;
76       guint8  flags;
77       proto_tree *bpdu_tree;
78       proto_item *ti;
79
80       if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
81             col_set_str(pinfo->cinfo, COL_PROTOCOL, "DEC_STP");
82       }
83       if (check_col(pinfo->cinfo, COL_INFO)) {
84             col_clear(pinfo->cinfo, COL_INFO);
85       }
86
87       bpdu_type = tvb_get_guint8(tvb, BPDU_TYPE);
88       flags=tvb_get_guint8(tvb,BPDU_FLAGS);
89       
90       if (check_col(pinfo->cinfo, COL_INFO)) {
91             if (bpdu_type == 25)
92                   col_add_fstr(pinfo->cinfo, COL_INFO, "Hello Packet");
93             else if (bpdu_type == 0x02)
94                   col_add_fstr(pinfo->cinfo, COL_INFO, "Topology Change Notification");
95       }
96       
97       tvb_set_reported_length(tvb, DEC_BPDU_SIZE);
98
99       if (tree) {
100             protocol_identifier = tvb_get_guint8(tvb, BPDU_DEC_CODE);
101
102             protocol_version = tvb_get_guint8(tvb, BPDU_VERSION);
103
104             ti = proto_tree_add_protocol_format(tree, proto_dec_bpdu, tvb, 0, DEC_BPDU_SIZE,
105                                 "DEC Spanning Tree Protocol");
106             bpdu_tree = proto_item_add_subtree(ti, ett_dec_bpdu);
107
108             proto_tree_add_text(bpdu_tree, tvb, BPDU_DEC_CODE, 1, "Protocol ID: 0x%02x (%s)",
109                  protocol_identifier,
110                  protocol_identifier==0xe1?"DEC Spanning Tree Protocol":
111                  "Unknown protocol, the dissection may be wrong");
112
113             proto_tree_add_text(bpdu_tree, tvb, BPDU_TYPE,1, "BPDU Type: %u (%s)", bpdu_type,
114                 (bpdu_type==25?"Hello Packet":(bpdu_type==2?"Topology change notice":"Unknown")));
115
116             proto_tree_add_text(bpdu_tree, tvb, BPDU_VERSION,1, "BPDU Version: %u (%s)",
117                 protocol_version,protocol_version==1?"DEC STP Version 1":"Unknown Version");
118
119             proto_tree_add_text(bpdu_tree, tvb, BPDU_FLAGS,1, "Flags: 0x%02x",flags);
120
121             if (flags & 0x80)
122                   proto_tree_add_text(bpdu_tree, tvb, BPDU_FLAGS, 1, "      1... ....  Use short timers");
123             if (flags & 0x02)
124                   proto_tree_add_text(bpdu_tree, tvb, BPDU_FLAGS, 1, "      .... ..1.  Topology Change Acknowledgment");
125             if (flags & 0x01)
126                   proto_tree_add_text(bpdu_tree, tvb, BPDU_FLAGS, 1, "      .... ...1  Topology Change");
127             
128             proto_tree_add_text(bpdu_tree, tvb, BPDU_ROOT_PRI,2, "Root priority: %u",
129                 tvb_get_ntohs(tvb,BPDU_ROOT_PRI));
130             proto_tree_add_text(bpdu_tree, tvb, BPDU_ROOT_MAC,6, "Root MAC: %s",
131                 ether_to_str(tvb_get_ptr(tvb,BPDU_ROOT_MAC,6)));
132             proto_tree_add_text(bpdu_tree, tvb, BPDU_ROOT_PATH_COST,2, "Root path cost: %u",
133                 tvb_get_ntohs(tvb,BPDU_ROOT_PATH_COST));
134             proto_tree_add_text(bpdu_tree, tvb, BPDU_BRIDGE_PRI,2, "Root priority: %u",
135                 tvb_get_ntohs(tvb,BPDU_BRIDGE_PRI));
136             proto_tree_add_text(bpdu_tree, tvb, BPDU_BRIDGE_MAC,6, "Root MAC: %s",
137                 ether_to_str(tvb_get_ptr(tvb,BPDU_BRIDGE_MAC,6)));
138             proto_tree_add_text(bpdu_tree, tvb, BPDU_PORT_IDENTIFIER,1, "Port identifier: %u",
139                 tvb_get_guint8(tvb,BPDU_PORT_IDENTIFIER));
140             proto_tree_add_text(bpdu_tree, tvb, BPDU_MESSAGE_AGE,1, "Age: %u",
141                 tvb_get_guint8(tvb,BPDU_MESSAGE_AGE));
142             proto_tree_add_text(bpdu_tree, tvb, BPDU_HELLO_TIME,1, "Hello time: %u",
143                 tvb_get_guint8(tvb,BPDU_HELLO_TIME));
144             proto_tree_add_text(bpdu_tree, tvb, BPDU_MAX_AGE,1, "Max Age: %u",
145                 tvb_get_guint8(tvb,BPDU_MAX_AGE));
146             proto_tree_add_text(bpdu_tree, tvb, BPDU_FORWARD_DELAY,1, "Forward Delay: %u",
147                 tvb_get_guint8(tvb,BPDU_FORWARD_DELAY));
148
149       }
150 }
151
152 void
153 proto_register_dec_bpdu(void)
154 {
155   static gint *ett[] = {
156     &ett_dec_bpdu,
157   };
158
159   proto_dec_bpdu = proto_register_protocol("DEC Spanning Tree Protocol",
160                                            "DEC_STP", "dec_stp");
161   proto_register_subtree_array(ett, array_length(ett));
162 }
163
164 void
165 proto_reg_handoff_dec_bpdu(void)
166 {
167   dissector_handle_t dec_bpdu_handle;
168
169   dec_bpdu_handle = create_dissector_handle(dissect_dec_bpdu,
170                                             proto_dec_bpdu);
171   dissector_add("ethertype", ETHERTYPE_DEC_LB, dec_bpdu_handle);
172   dissector_add("chdlctype", ETHERTYPE_DEC_LB, dec_bpdu_handle);
173   dissector_add("ppp.protocol", PPP_DEC_LB, dec_bpdu_handle);
174 }