Fixup: tvb_get_string(z) -> tvb_get_string(z)_enc
[metze/wireshark/wip.git] / epan / dissectors / packet-llt.c
1 /* packet-llt.c
2  * Routines for Veritas Low Latency Transport (LLT) dissection
3  * Copyright 2006, Stephen Fisher (see AUTHORS file)
4  *
5  * Wireshark - Network traffic analyzer
6  * By Gerald Combs <gerald@wireshark.org>
7  * Copyright 1998 Gerald Combs
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23
24 #include "config.h"
25
26 #include <glib.h>
27
28 #include <epan/packet.h>
29 #include <epan/prefs.h>
30 #include <epan/etypes.h>
31
32 void proto_register_llt(void);
33 void proto_reg_handoff_llt(void);
34
35 static const value_string message_type_vs[] = {
36   { 0x0a, "heartbeat" },
37   { 0, NULL}
38 };
39
40 /* Variables for our preferences */
41 static guint preference_alternate_ethertype = 0x0;
42
43 /* Initialize the protocol and registered fields */
44 static int proto_llt = -1;
45
46 static int hf_llt_cluster_num = -1;
47 static int hf_llt_node_id = -1;
48 static int hf_llt_message_type = -1;
49 static int hf_llt_sequence_num = -1;
50 static int hf_llt_message_time = -1;
51
52 /* Initialize the subtree pointers */
53 static gint ett_llt = -1;
54
55 /* Code to actually dissect the packets */
56 static void
57 dissect_llt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
58 {
59         /* Set up structures needed to add the protocol subtree and manage it */
60         proto_item *ti;
61         proto_tree *llt_tree;
62         guint8 message_type;
63
64         /* Make entries in Protocol column and Info column on summary display */
65         col_set_str(pinfo->cinfo, COL_PROTOCOL, "LLT");
66
67         message_type = tvb_get_guint8(tvb, 3);
68
69         col_add_fstr(pinfo->cinfo, COL_INFO, "Message type: %s", val_to_str(message_type, message_type_vs, "Unknown (0x%02x)"));
70
71         ti = proto_tree_add_item(tree, proto_llt, tvb, 0, -1, ENC_NA);
72         llt_tree = proto_item_add_subtree(ti, ett_llt);
73
74         proto_tree_add_item(llt_tree, hf_llt_cluster_num, tvb, 2, 1, ENC_BIG_ENDIAN);
75         proto_tree_add_item(llt_tree, hf_llt_message_type, tvb, 3, 1, ENC_BIG_ENDIAN);
76         proto_tree_add_item(llt_tree, hf_llt_node_id, tvb, 7, 1, ENC_BIG_ENDIAN);
77         proto_tree_add_item(llt_tree, hf_llt_sequence_num, tvb, 24, 4, ENC_BIG_ENDIAN);
78         proto_tree_add_item(llt_tree, hf_llt_message_time, tvb, 40, 4, ENC_BIG_ENDIAN);
79
80 }
81
82 /* Register the protocol with Wireshark */
83 void
84 proto_register_llt(void)
85 {
86         module_t *llt_module;
87
88         static hf_register_info hf[] = {
89
90                 { &hf_llt_cluster_num,  { "Cluster number", "llt.cluster_num",
91                                           FT_UINT8, BASE_DEC, NULL, 0,
92                                           "Cluster number that this node belongs to", HFILL } },
93
94                 { &hf_llt_message_type, { "Message type", "llt.message_type",
95                                           FT_UINT8, BASE_HEX, VALS(message_type_vs), 0,
96                                           "Type of LLT message contained in this frame", HFILL } },
97
98                 { &hf_llt_node_id,      { "Node ID", "llt.node_id",
99                                           FT_UINT8, BASE_DEC, NULL, 0,
100                                           "Number identifying this node within the cluster", HFILL } },
101
102                 { &hf_llt_sequence_num, { "Sequence number", "llt.sequence_num",
103                                           FT_UINT32, BASE_DEC, NULL, 0,
104                                           "Sequence number of this frame", HFILL } },
105
106                 { &hf_llt_message_time, { "Message time", "llt.message_time",
107                                           FT_UINT32, BASE_DEC, NULL, 0,
108                                           "Number of ticks since this node was last rebooted", HFILL } }
109         };
110
111         /* Setup protocol subtree array */
112         static gint *ett[] = {
113                 &ett_llt,
114         };
115
116         /* Register the protocol name and description */
117         proto_llt = proto_register_protocol("Veritas Low Latency Transport (LLT)", "LLT", "llt");
118
119         /* Required function calls to register the header fields and subtrees used */
120         proto_register_field_array(proto_llt, hf, array_length(hf));
121         proto_register_subtree_array(ett, array_length(ett));
122
123         /* Register preferences module */
124         llt_module = prefs_register_protocol(proto_llt, proto_reg_handoff_llt);
125
126         /* Register our preferences */
127         prefs_register_uint_preference(llt_module, "alternate_ethertype", "Alternate ethertype value (in hex)",
128                                        "Dissect this ethertype as LLT traffic in addition to the default, 0xCAFE.",
129                                        16, &preference_alternate_ethertype); /* A base-16 (hexadecimal) value */
130
131 }
132
133
134 void
135 proto_reg_handoff_llt(void)
136 {
137         static gboolean initialized = FALSE;
138         static dissector_handle_t llt_handle;
139         static guint preference_alternate_ethertype_last;
140
141         if (!initialized) {
142                 llt_handle = create_dissector_handle(dissect_llt, proto_llt);
143                 dissector_add_uint("ethertype", ETHERTYPE_LLT, llt_handle);
144                 initialized = TRUE;
145         } else {
146                 if (preference_alternate_ethertype_last != 0x0) {
147                         dissector_delete_uint("ethertype", preference_alternate_ethertype_last, llt_handle);
148                 }
149         }
150
151         /* Save the setting to see if it has changed later */
152         preference_alternate_ethertype_last = preference_alternate_ethertype;
153
154         if (preference_alternate_ethertype != 0x0) {
155                 /* Register the new ethertype setting */
156                 dissector_add_uint("ethertype", preference_alternate_ethertype, llt_handle);
157         }
158 }