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
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
;
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"},
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
;
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
);
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)"));
81 proto_tree_add_item(trel_hdr_tree
, hf_trel_channel
, tvb
, offset
, 1, ENC_NA
);
84 proto_tree_add_item(trel_hdr_tree
, hf_802154_dest_panid
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
87 proto_tree_add_item(trel_hdr_tree
, hf_trel_packetno
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
90 proto_tree_add_item(trel_hdr_tree
, hf_trel_source_addr
, tvb
, offset
, 8, ENC_BIG_ENDIAN
);
95 proto_tree_add_item(trel_hdr_tree
, hf_trel_destination_addr
, tvb
, offset
, 8, ENC_BIG_ENDIAN
);
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
109 dissect_trel_heur(tvbuff_t
* tvb
, packet_info
* pinfo
, proto_tree
* tree
, void* data
)
111 if ((tvb_captured_length(tvb
)) < 16 ) {
115 uint8_t first
= tvb_get_uint8(tvb
, 0);
116 if ((first
& 0xE0) != 0)
119 if (pinfo
->srcport
== pinfo
->destport
) return false;
121 dissect_trel(tvb
, pinfo
, tree
, data
);
125 proto_register_trel(void)
128 static hf_register_info hf
[] = {
133 FT_UINT8
, BASE_DEC
, NULL
, 0xE0,
134 "The TREL protocol version",
139 { "TREL reserved bit",
141 FT_UINT8
, BASE_DEC
, NULL
, 0x18,
142 "The TREL reserved bit",
147 { "TREL acknowledgement",
149 FT_UINT8
, BASE_DEC
, NULL
, 0x4,
150 "The TREL acknowledgement",
157 FT_UINT8
, BASE_DEC
, NULL
, 0x3,
165 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
170 { &hf_802154_dest_panid
,
171 { "TREL 802.15.4 Dest Pan ID",
173 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
174 "The TREL 802.15.4 Dest Pan ID",
179 { "TREL packet number",
181 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
182 "The TREL packet number",
186 { &hf_trel_source_addr
,
187 { "TREL Src Address",
189 FT_EUI64
, BASE_NONE
, NULL
, 0x0,
194 { &hf_trel_destination_addr
,
195 { "TREL Dest Address",
196 "trel.destination_addr",
197 FT_EUI64
, BASE_NONE
, NULL
, 0x0,
198 "Destination address",
204 static int* ett
[] = {
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
);
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
);