Move a pile of protocol-related headers from the top-level source
[obnox/wireshark/wip.git] / epan / dissectors / packet-hpext.c
1 /* packet-hpext.c
2  * Routines for HP extended IEEE 802.2 LLC layer
3  * Jochen Friedrich <jochen@scram.de>
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/xdlc.h>
33 #include <epan/etypes.h>
34 #include <epan/llcsaps.h>
35 #include "packet-hpext.h"
36
37 static dissector_table_t subdissector_table;
38
39 static dissector_handle_t data_handle;
40
41 static int proto_hpext = -1;
42
43 static int hf_hpext_dxsap = -1;
44 static int hf_hpext_sxsap = -1;
45
46 static gint ett_hpext = -1;
47
48 const value_string xsap_vals[] = {
49         { HPEXT_DXSAP,  "RBOOT Destination Service Access Point" },
50         { HPEXT_SXSAP,  "RBOOT Source Service Access Point" },
51         { HPEXT_SNMP,   "SNMP" },
52         { 0x00,         NULL }
53 };
54
55 static void
56 dissect_hpext(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
57 {
58         proto_tree      *hpext_tree = NULL;
59         proto_item      *ti = NULL;
60         guint16         dxsap, sxsap;
61         tvbuff_t        *next_tvb;
62
63         if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
64                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "HPEXT");
65         }
66
67         dxsap = tvb_get_ntohs(tvb, 3);
68         sxsap = tvb_get_ntohs(tvb, 5);
69
70         if (tree) {
71                 ti = proto_tree_add_item(tree, proto_hpext, tvb, 0, 7, FALSE);
72                 hpext_tree = proto_item_add_subtree(ti, ett_hpext);
73                 proto_tree_add_text(hpext_tree, tvb, 0, 3, "Reserved");
74                 proto_tree_add_uint(hpext_tree, hf_hpext_dxsap, tvb, 3,
75                         2, dxsap);
76                 proto_tree_add_uint(hpext_tree, hf_hpext_sxsap, tvb, 5,
77                         2, sxsap);
78         }
79
80         if (check_col(pinfo->cinfo, COL_INFO))
81                 col_append_fstr(pinfo->cinfo, COL_INFO,
82                     "; HPEXT; DXSAP %s, SXSAP %s",
83                     val_to_str(dxsap, xsap_vals, "%04x"),
84                     val_to_str(sxsap, xsap_vals, "%04x"));
85
86         if (tvb_length_remaining(tvb, 7) > 0) {
87                 next_tvb = tvb_new_subset(tvb, 7, -1, -1);
88                 if (!dissector_try_port(subdissector_table,
89                     dxsap, next_tvb, pinfo, tree)) {
90                         call_dissector(data_handle, next_tvb, pinfo, tree);
91                 }
92         }
93 }
94
95 void
96 proto_register_hpext(void)
97 {
98         static hf_register_info hf[] = {
99                 { &hf_hpext_dxsap,
100                 { "DXSAP",      "hpext.dxsap", FT_UINT16, BASE_HEX,
101                         VALS(xsap_vals), 0x0, "", HFILL }},
102
103                 { &hf_hpext_sxsap,
104                 { "SXSAP", "hpext.sxsap", FT_UINT16, BASE_HEX,
105                         VALS(xsap_vals), 0x0, "", HFILL }},
106         };
107         static gint *ett[] = {
108                 &ett_hpext,
109         };
110
111         proto_hpext = proto_register_protocol(
112             "HP Extended Local-Link Control", "HPEXT", "hpext");
113         proto_register_field_array(proto_hpext, hf, array_length(hf));
114         proto_register_subtree_array(ett, array_length(ett));
115
116 /* subdissector code */
117         subdissector_table = register_dissector_table("hpext.dxsap",
118           "HPEXT XSAP", FT_UINT16, BASE_HEX);
119
120         register_dissector("hpext", dissect_hpext, proto_hpext);
121 }
122
123 void
124 proto_reg_handoff_hpext(void)
125 {
126         dissector_handle_t hpext_handle;
127
128         data_handle = find_dissector("data");
129
130         hpext_handle = find_dissector("hpext");
131         dissector_add("llc.dsap", SAP_HPEXT, hpext_handle);
132 }