Add HP Switch Protocol SAP value
[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  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 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_HPSW,   "HP Switch Protocol" },
52         { HPEXT_SNMP,   "SNMP" },
53         { 0x00,         NULL }
54 };
55
56 static void
57 dissect_hpext(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
58 {
59         proto_tree      *hpext_tree = NULL;
60         proto_item      *ti = NULL;
61         guint16         dxsap, sxsap;
62         tvbuff_t        *next_tvb;
63
64         if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
65                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "HPEXT");
66         }
67
68         dxsap = tvb_get_ntohs(tvb, 3);
69         sxsap = tvb_get_ntohs(tvb, 5);
70
71         if (tree) {
72                 ti = proto_tree_add_item(tree, proto_hpext, tvb, 0, 7, FALSE);
73                 hpext_tree = proto_item_add_subtree(ti, ett_hpext);
74                 proto_tree_add_text(hpext_tree, tvb, 0, 3, "Reserved");
75                 proto_tree_add_uint(hpext_tree, hf_hpext_dxsap, tvb, 3,
76                         2, dxsap);
77                 proto_tree_add_uint(hpext_tree, hf_hpext_sxsap, tvb, 5,
78                         2, sxsap);
79         }
80
81         if (check_col(pinfo->cinfo, COL_INFO))
82                 col_append_fstr(pinfo->cinfo, COL_INFO,
83                     "; HPEXT; DXSAP %s, SXSAP %s",
84                     val_to_str(dxsap, xsap_vals, "%04x"),
85                     val_to_str(sxsap, xsap_vals, "%04x"));
86
87         if (tvb_length_remaining(tvb, 7) > 0) {
88                 next_tvb = tvb_new_subset(tvb, 7, -1, -1);
89                 if (!dissector_try_port(subdissector_table,
90                     dxsap, next_tvb, pinfo, tree)) {
91                         call_dissector(data_handle, next_tvb, pinfo, tree);
92                 }
93         }
94 }
95
96 void
97 proto_register_hpext(void)
98 {
99         static hf_register_info hf[] = {
100                 { &hf_hpext_dxsap,
101                 { "DXSAP",      "hpext.dxsap", FT_UINT16, BASE_HEX,
102                         VALS(xsap_vals), 0x0, "", HFILL }},
103
104                 { &hf_hpext_sxsap,
105                 { "SXSAP", "hpext.sxsap", FT_UINT16, BASE_HEX,
106                         VALS(xsap_vals), 0x0, "", HFILL }}
107         };
108         static gint *ett[] = {
109                 &ett_hpext
110         };
111
112         proto_hpext = proto_register_protocol(
113             "HP Extended Local-Link Control", "HPEXT", "hpext");
114         proto_register_field_array(proto_hpext, hf, array_length(hf));
115         proto_register_subtree_array(ett, array_length(ett));
116
117 /* subdissector code */
118         subdissector_table = register_dissector_table("hpext.dxsap",
119           "HPEXT XSAP", FT_UINT16, BASE_HEX);
120
121         register_dissector("hpext", dissect_hpext, proto_hpext);
122 }
123
124 void
125 proto_reg_handoff_hpext(void)
126 {
127         dissector_handle_t hpext_handle;
128
129         data_handle = find_dissector("data");
130
131         hpext_handle = find_dissector("hpext");
132         dissector_add("llc.dsap", SAP_HPEXT, hpext_handle);
133 }