GTPv2: fix dissection of APN IE
[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  * SPDX-License-Identifier: GPL-2.0-or-later
10  */
11
12 #include "config.h"
13
14 #include <epan/packet.h>
15 #include <epan/prefs.h>
16 #include <epan/etypes.h>
17
18 void proto_register_llt(void);
19 void proto_reg_handoff_llt(void);
20
21 static const value_string message_type_vs[] = {
22         { 0x0a, "heartbeat" },
23         { 0, NULL}
24 };
25
26 /* Variables for our preferences */
27 static guint preference_alternate_ethertype = 0x0;
28
29 /* Initialize the protocol and registered fields */
30 static int proto_llt = -1;
31
32 static int hf_llt_cluster_num = -1;
33 static int hf_llt_node_id = -1;
34 static int hf_llt_message_type = -1;
35 static int hf_llt_sequence_num = -1;
36 static int hf_llt_message_time = -1;
37
38 /* Initialize the subtree pointers */
39 static gint ett_llt = -1;
40
41 /* Code to actually dissect the packets */
42 static int
43 dissect_llt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
44 {
45         /* Set up structures needed to add the protocol subtree and manage it */
46         proto_item *ti;
47         proto_tree *llt_tree;
48         guint8 message_type;
49
50         /* Make entries in Protocol column and Info column on summary display */
51         col_set_str(pinfo->cinfo, COL_PROTOCOL, "LLT");
52
53         message_type = tvb_get_guint8(tvb, 3);
54
55         col_add_fstr(pinfo->cinfo, COL_INFO, "Message type: %s", val_to_str(message_type, message_type_vs, "Unknown (0x%02x)"));
56
57         ti = proto_tree_add_item(tree, proto_llt, tvb, 0, -1, ENC_NA);
58         llt_tree = proto_item_add_subtree(ti, ett_llt);
59
60         proto_tree_add_item(llt_tree, hf_llt_cluster_num, tvb, 2, 1, ENC_BIG_ENDIAN);
61         proto_tree_add_item(llt_tree, hf_llt_message_type, tvb, 3, 1, ENC_BIG_ENDIAN);
62         proto_tree_add_item(llt_tree, hf_llt_node_id, tvb, 7, 1, ENC_BIG_ENDIAN);
63         proto_tree_add_item(llt_tree, hf_llt_sequence_num, tvb, 24, 4, ENC_BIG_ENDIAN);
64         proto_tree_add_item(llt_tree, hf_llt_message_time, tvb, 40, 4, ENC_BIG_ENDIAN);
65
66         return tvb_captured_length(tvb);
67 }
68
69 /* Register the protocol with Wireshark */
70 void
71 proto_register_llt(void)
72 {
73         module_t *llt_module;
74
75         static hf_register_info hf[] = {
76
77                 { &hf_llt_cluster_num,  { "Cluster number", "llt.cluster_num",
78                                           FT_UINT8, BASE_DEC, NULL, 0,
79                                           "Cluster number that this node belongs to", HFILL } },
80
81                 { &hf_llt_message_type, { "Message type", "llt.message_type",
82                                           FT_UINT8, BASE_HEX, VALS(message_type_vs), 0,
83                                           "Type of LLT message contained in this frame", HFILL } },
84
85                 { &hf_llt_node_id,      { "Node ID", "llt.node_id",
86                                           FT_UINT8, BASE_DEC, NULL, 0,
87                                           "Number identifying this node within the cluster", HFILL } },
88
89                 { &hf_llt_sequence_num, { "Sequence number", "llt.sequence_num",
90                                           FT_UINT32, BASE_DEC, NULL, 0,
91                                           "Sequence number of this frame", HFILL } },
92
93                 { &hf_llt_message_time, { "Message time", "llt.message_time",
94                                           FT_UINT32, BASE_DEC, NULL, 0,
95                                           "Number of ticks since this node was last rebooted", HFILL } }
96         };
97
98         /* Setup protocol subtree array */
99         static gint *ett[] = {
100                 &ett_llt,
101         };
102
103         /* Register the protocol name and description */
104         proto_llt = proto_register_protocol("Veritas Low Latency Transport (LLT)", "LLT", "llt");
105
106         /* Required function calls to register the header fields and subtrees used */
107         proto_register_field_array(proto_llt, hf, array_length(hf));
108         proto_register_subtree_array(ett, array_length(ett));
109
110         /* Register preferences module */
111         llt_module = prefs_register_protocol(proto_llt, proto_reg_handoff_llt);
112
113         /* Register our preferences */
114         prefs_register_uint_preference(llt_module, "alternate_ethertype", "Alternate ethertype value (in hex)",
115                                        "Dissect this ethertype as LLT traffic in addition to the default, 0xCAFE.",
116                                        16, &preference_alternate_ethertype); /* A base-16 (hexadecimal) value */
117
118 }
119
120
121 void
122 proto_reg_handoff_llt(void)
123 {
124         static gboolean initialized = FALSE;
125         static dissector_handle_t llt_handle;
126         static guint preference_alternate_ethertype_last;
127
128         if (!initialized) {
129                 llt_handle = create_dissector_handle(dissect_llt, proto_llt);
130                 dissector_add_uint("ethertype", ETHERTYPE_LLT, llt_handle);
131                 initialized = TRUE;
132         } else {
133                 if (preference_alternate_ethertype_last != 0x0) {
134                         dissector_delete_uint("ethertype", preference_alternate_ethertype_last, llt_handle);
135                 }
136         }
137
138         /* Save the setting to see if it has changed later */
139         preference_alternate_ethertype_last = preference_alternate_ethertype;
140
141         if (preference_alternate_ethertype != 0x0) {
142                 /* Register the new ethertype setting */
143                 dissector_add_uint("ethertype", preference_alternate_ethertype, llt_handle);
144         }
145 }
146
147 /*
148  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
149  *
150  * Local variables:
151  * c-basic-offset: 8
152  * tab-width: 8
153  * indent-tabs-mode: t
154  * End:
155  *
156  * vi: set shiftwidth=8 tabstop=8 noexpandtab:
157  * :indentSize=8:tabSize=8:noTabs=false:
158  */