Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-trel.c
blobfbe359703810ba85f5ef03f3dbacc5218de10cb0
1 /* packet-trel.c
2 * Routines for TREL packet dissection
3 * Copyright 2004, Pranay Nagpure - <pranay.dilip@graniteriverlabs.in>
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
13 #include "config.h"
14 #include <epan/packet.h>
15 #include "packet-ieee802154.h"
16 #include <epan/wmem_scopes.h>
17 #include <epan/packet_info.h>
18 #include <epan/proto_data.h>
19 #include <epan/proto.h>
20 #include <packet-mle.h>
21 #include <packet-6lowpan.h>
22 #include <epan/expert.h>
23 #include<wsutil/wsgcrypt.h>
25 #define TREL_PORT 38196
27 #define TREL_TYPE_BROADCAST 0
28 #define TREL_TYPE_UNICAST 1
29 #define TREL_TYPE_ACK 2
31 static dissector_handle_t trel_handle;
32 static int hf_trel_version;
33 static int hf_trel_rsv;
34 static int hf_trel_ack;
35 static int hf_trel_type;
36 static int hf_trel_channel;
37 static int hf_802154_dest_panid;
38 static int hf_trel_source_addr;
39 static int hf_trel_destination_addr;
40 static int hf_trel_packetno;
42 static int proto_trel;
44 static int ett_trel;
45 static int ett_trel_hdr;
47 void proto_register_trel(void);
49 static const value_string trel_command_vals[] = {
50 { TREL_TYPE_BROADCAST, "TREL Advertisement" },
51 { TREL_TYPE_UNICAST, "TREL Unicast Response" },
52 { TREL_TYPE_ACK, "TREL Acknowledgement"},
53 { 0, NULL}
56 static int
57 dissect_trel(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree, void* data _U_)
59 proto_tree* volatile trel_tree = NULL, * volatile trel_hdr_tree;
60 proto_item* volatile proto_root = NULL;
62 unsigned offset = 0;
64 col_set_str(pinfo->cinfo, COL_PROTOCOL, "TREL");
65 col_clear(pinfo->cinfo, COL_INFO);
67 proto_root = proto_tree_add_item(tree, proto_trel, tvb, 0, tvb_reported_length(tvb), ENC_NA);
68 trel_tree = proto_item_add_subtree(proto_root, ett_trel);
70 //add header subtree
71 trel_hdr_tree = proto_tree_add_subtree(trel_tree, tvb, 0, 4, ett_trel_hdr, NULL, "Header");
73 proto_tree_add_item(trel_hdr_tree, hf_trel_version, tvb, offset, 1, ENC_NA);
74 proto_tree_add_item(trel_hdr_tree, hf_trel_rsv, tvb, offset, 1, ENC_NA);
75 proto_tree_add_item(trel_hdr_tree, hf_trel_ack, tvb, offset, 1, ENC_NA);
76 proto_tree_add_item(trel_hdr_tree, hf_trel_type, tvb, offset, 1, ENC_NA);
78 uint8_t type = tvb_get_uint8(tvb, offset);
79 col_add_str(pinfo->cinfo, COL_INFO, val_to_str(type, trel_command_vals, "Unknown (%x)"));
80 ++offset;
81 proto_tree_add_item(trel_hdr_tree, hf_trel_channel, tvb, offset, 1, ENC_NA);
82 ++offset;
84 proto_tree_add_item(trel_hdr_tree, hf_802154_dest_panid, tvb, offset, 2, ENC_BIG_ENDIAN);
85 offset += 2;
87 proto_tree_add_item(trel_hdr_tree, hf_trel_packetno, tvb, offset, 4, ENC_BIG_ENDIAN);
88 offset += 4;
90 proto_tree_add_item(trel_hdr_tree, hf_trel_source_addr, tvb, offset, 8, ENC_BIG_ENDIAN);
91 offset += 8;
93 if (type)
95 proto_tree_add_item(trel_hdr_tree, hf_trel_destination_addr, tvb, offset, 8, ENC_BIG_ENDIAN);
96 offset += 8;
99 dissector_handle_t frame_handle = find_dissector("wpan_nofcs");
100 tvbuff_t* payload = tvb_new_subset_remaining(tvb, offset);
102 if (tvb_reported_length(payload))
103 call_dissector(frame_handle, payload, pinfo, trel_tree);
105 return tvb_captured_length(tvb);
107 // below code is added to replace mdns dissector registration
108 static bool
109 dissect_trel_heur(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree, void* data)
111 if ((tvb_captured_length(tvb)) < 16 ) {
112 return false;
115 uint8_t first = tvb_get_uint8(tvb, 0);
116 if ((first & 0xE0) != 0)
117 return false;
119 if (pinfo->srcport == pinfo->destport) return false;
121 dissect_trel(tvb, pinfo, tree, data);
122 return true;
124 void
125 proto_register_trel(void)
128 static hf_register_info hf[] = {
130 { &hf_trel_version,
131 { "TREL version",
132 "trel.ver",
133 FT_UINT8, BASE_DEC, NULL, 0xE0,
134 "The TREL protocol version",
135 HFILL
138 { &hf_trel_rsv,
139 { "TREL reserved bit",
140 "trel.rsv",
141 FT_UINT8, BASE_DEC, NULL, 0x18,
142 "The TREL reserved bit",
143 HFILL
146 { &hf_trel_ack,
147 { "TREL acknowledgement",
148 "trel.ack",
149 FT_UINT8, BASE_DEC, NULL, 0x4,
150 "The TREL acknowledgement",
151 HFILL
154 { &hf_trel_type,
155 { "TREL type",
156 "trel.type",
157 FT_UINT8, BASE_DEC, NULL, 0x3,
158 "The TREL type",
159 HFILL
162 { &hf_trel_channel,
163 { "TREL channel",
164 "trel.channel",
165 FT_UINT8, BASE_DEC, NULL, 0x0,
166 "The TREL channel",
167 HFILL
170 { &hf_802154_dest_panid,
171 { "TREL 802.15.4 Dest Pan ID",
172 "trel.panID",
173 FT_UINT16, BASE_DEC, NULL, 0x0,
174 "The TREL 802.15.4 Dest Pan ID",
175 HFILL
178 { &hf_trel_packetno,
179 { "TREL packet number",
180 "trel.packetno",
181 FT_UINT32, BASE_DEC, NULL, 0x0,
182 "The TREL packet number",
183 HFILL
186 { &hf_trel_source_addr,
187 { "TREL Src Address",
188 "trel.source_addr",
189 FT_EUI64, BASE_NONE, NULL, 0x0,
190 "Source address",
191 HFILL
194 { &hf_trel_destination_addr,
195 { "TREL Dest Address",
196 "trel.destination_addr",
197 FT_EUI64, BASE_NONE, NULL, 0x0,
198 "Destination address",
199 HFILL
204 static int* ett[] = {
205 &ett_trel,
206 &ett_trel_hdr
209 proto_trel = proto_register_protocol("TREL Protocol", "TREL", "trel");
211 proto_register_field_array(proto_trel, hf, array_length(hf));
212 proto_register_subtree_array(ett, array_length(ett));
214 trel_handle = register_dissector("trel", dissect_trel, proto_trel);
217 void
218 proto_reg_handoff_trel(void)
220 //heur dissector is disabled as it not strong enough
221 //dissector_add_uint("udp.port", TREL_PORT, trel_handle);
222 dissector_add_uint_with_preference("udp.port", 0, trel_handle);
223 heur_dissector_add("udp", dissect_trel_heur, "TREL over UDP", "trel_udp", proto_trel, HEURISTIC_DISABLE);