Move a pile of protocol-related headers from the top-level source
[obnox/wireshark/wip.git] / epan / dissectors / packet-3com-xns.c
1 /* packet-xns-llc.c
2  * Routines for 3Com's encapsulation of XNS over 802.2 LLC
3  * (and other protocols using DSAP 80)
4  *
5  * $Id$
6  *
7  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@ethereal.com>
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
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include <glib.h>
31 #include <epan/packet.h>
32 #include <epan/etypes.h>
33
34 static int proto_3com_xns = -1;
35
36 static int hf_3com_xns_type_ethertype = -1;
37 static int hf_3com_xns_type_retix_bpdu = -1;
38
39 static gint ett_3com_xns = -1;
40
41 static const value_string retix_bpdu_type_vals[] = {
42         { 0x0004, "Retix Spanning Tree" },
43         { 0, NULL }
44 };
45
46 static dissector_handle_t retix_bpdu_handle;
47
48 /*
49  * Apparently 3Com had some scheme for encapsulating XNS in 802.2 LLC,
50  * using a DSAP and SSAP of 0x80, and putting a 2-byte field that appeared
51  * to contain, at least for IPP, the Ethertype value for IPP.
52  *
53  * We assume that the value there is an Ethertype value, except for
54  * the Retix spanning tree protocol, which also uses a DSAP and SSAP
55  * of 0x80 but has, at least in one capture, 0x0004 as the type
56  * field.  We handle that specially.
57  *
58  * XXX - I've also seen packets on 802.11 with a DSAP and SSAP of 0x80,
59  * but with random stuff that appears neither to be XNS nor Retix
60  * spanning tree.
61  */
62 static void
63 dissect_3com_xns(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
64 {
65         proto_tree *subtree = NULL;
66         proto_tree *ti;
67         guint16 type;
68
69         if (check_col(pinfo->cinfo, COL_PROTOCOL))
70                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "3Com XNS");
71         if (check_col(pinfo->cinfo, COL_INFO))
72                 col_clear(pinfo->cinfo, COL_INFO);
73
74         if (tree) {
75                 ti = proto_tree_add_item(tree, proto_3com_xns, tvb, 0, 4, FALSE);
76                 subtree = proto_item_add_subtree(ti, ett_3com_xns);
77         }
78
79         type = tvb_get_ntohs(tvb, 0);
80         if (type == 0x0004) {
81                 proto_tree_add_uint(subtree, hf_3com_xns_type_retix_bpdu,
82                     tvb, 0, 2, type);
83                 call_dissector(retix_bpdu_handle,
84                     tvb_new_subset(tvb, 2, -1, -1), pinfo, tree);
85         } else {
86                 ethertype(type, tvb, 2, pinfo, tree, subtree,
87                     hf_3com_xns_type_ethertype, -1, 0);
88         }
89 }
90
91 void
92 proto_register_3com_xns(void)
93 {
94         static hf_register_info hf[] = {
95                 /* registered here but handled in ethertype.c */
96                 { &hf_3com_xns_type_ethertype,
97                 { "Type", "xnsllc.type", FT_UINT16, BASE_HEX,
98                         VALS(etype_vals), 0x0, "", HFILL }},
99
100                 { &hf_3com_xns_type_retix_bpdu,
101                 { "Type", "xnsllc.type", FT_UINT16, BASE_HEX,
102                         VALS(retix_bpdu_type_vals), 0x0, "", HFILL }},
103         };
104
105         static gint *ett[] ={
106                 &ett_3com_xns,
107         };
108
109         proto_3com_xns = proto_register_protocol("3Com XNS Encapsulation", "3COMXNS", "3comxns");
110         proto_register_field_array(proto_3com_xns, hf, array_length(hf)); 
111         proto_register_subtree_array(ett, array_length(ett));
112 }
113
114 void
115 proto_reg_handoff_3com_xns(void)
116 {
117         dissector_handle_t our_xns_handle;
118
119         retix_bpdu_handle = find_dissector("rbpdu");
120
121         our_xns_handle = create_dissector_handle(dissect_3com_xns,
122             proto_3com_xns);
123         dissector_add("llc.dsap", 0x80, our_xns_handle);
124 }