/src/wireshark/epan/dissectors/packet-trel.c
Line | Count | Source |
1 | | /* packet-trel.c |
2 | | * Routines for TREL packet dissection |
3 | | * Copyright 2004, Pranay Nagpure - <pranay.dilip@graniteriverlabs.in> |
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 | | |
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> |
24 | | |
25 | | #define TREL_PORT 38196 |
26 | | |
27 | | #define TREL_TYPE_BROADCAST 0 |
28 | | #define TREL_TYPE_UNICAST 1 |
29 | | #define TREL_TYPE_ACK 2 |
30 | | |
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; |
41 | | |
42 | | static int proto_trel; |
43 | | |
44 | | static int ett_trel; |
45 | | static int ett_trel_hdr; |
46 | | |
47 | | void proto_register_trel(void); |
48 | | |
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} |
54 | | }; |
55 | | |
56 | | static int |
57 | | dissect_trel(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree, void* data _U_) |
58 | 0 | { |
59 | 0 | proto_tree* volatile trel_tree = NULL, * volatile trel_hdr_tree; |
60 | 0 | proto_item* volatile proto_root = NULL; |
61 | 0 | uint32_t type; |
62 | |
|
63 | 0 | unsigned offset = 0; |
64 | |
|
65 | 0 | col_set_str(pinfo->cinfo, COL_PROTOCOL, "TREL"); |
66 | 0 | col_clear(pinfo->cinfo, COL_INFO); |
67 | |
|
68 | 0 | proto_root = proto_tree_add_item(tree, proto_trel, tvb, 0, tvb_reported_length(tvb), ENC_NA); |
69 | 0 | trel_tree = proto_item_add_subtree(proto_root, ett_trel); |
70 | | |
71 | | //add header subtree |
72 | 0 | trel_hdr_tree = proto_tree_add_subtree(trel_tree, tvb, 0, 4, ett_trel_hdr, NULL, "Header"); |
73 | |
|
74 | 0 | proto_tree_add_item(trel_hdr_tree, hf_trel_version, tvb, offset, 1, ENC_NA); |
75 | 0 | proto_tree_add_item(trel_hdr_tree, hf_trel_rsv, tvb, offset, 1, ENC_NA); |
76 | 0 | proto_tree_add_item(trel_hdr_tree, hf_trel_ack, tvb, offset, 1, ENC_NA); |
77 | 0 | proto_tree_add_item_ret_uint(trel_hdr_tree, hf_trel_type, tvb, offset, 1, ENC_NA, &type); |
78 | |
|
79 | 0 | col_add_str(pinfo->cinfo, COL_INFO, val_to_str(pinfo->pool, type, trel_command_vals, "Unknown (%x)")); |
80 | 0 | ++offset; |
81 | 0 | proto_tree_add_item(trel_hdr_tree, hf_trel_channel, tvb, offset, 1, ENC_NA); |
82 | 0 | ++offset; |
83 | |
|
84 | 0 | proto_tree_add_item(trel_hdr_tree, hf_802154_dest_panid, tvb, offset, 2, ENC_BIG_ENDIAN); |
85 | 0 | offset += 2; |
86 | |
|
87 | 0 | proto_tree_add_item(trel_hdr_tree, hf_trel_packetno, tvb, offset, 4, ENC_BIG_ENDIAN); |
88 | 0 | offset += 4; |
89 | |
|
90 | 0 | proto_tree_add_item(trel_hdr_tree, hf_trel_source_addr, tvb, offset, 8, ENC_BIG_ENDIAN); |
91 | 0 | offset += 8; |
92 | |
|
93 | 0 | if (type) |
94 | 0 | { |
95 | 0 | proto_tree_add_item(trel_hdr_tree, hf_trel_destination_addr, tvb, offset, 8, ENC_BIG_ENDIAN); |
96 | 0 | offset += 8; |
97 | 0 | } |
98 | |
|
99 | 0 | dissector_handle_t frame_handle = find_dissector("wpan_nofcs"); |
100 | 0 | tvbuff_t* payload = tvb_new_subset_remaining(tvb, offset); |
101 | |
|
102 | 0 | if (tvb_reported_length(payload)) |
103 | 0 | call_dissector(frame_handle, payload, pinfo, trel_tree); |
104 | |
|
105 | 0 | return tvb_captured_length(tvb); |
106 | 0 | } |
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) |
110 | 0 | { |
111 | 0 | if ((tvb_captured_length(tvb)) < 16 ) { |
112 | 0 | return false; |
113 | 0 | } |
114 | | |
115 | 0 | uint8_t first = tvb_get_uint8(tvb, 0); |
116 | 0 | if ((first & 0xE0) != 0) |
117 | 0 | return false; |
118 | | |
119 | 0 | if (pinfo->srcport == pinfo->destport) return false; |
120 | | |
121 | 0 | dissect_trel(tvb, pinfo, tree, data); |
122 | 0 | return true; |
123 | 0 | } |
124 | | void |
125 | | proto_register_trel(void) |
126 | 14 | { |
127 | | |
128 | 14 | static hf_register_info hf[] = { |
129 | | |
130 | 14 | { &hf_trel_version, |
131 | 14 | { "TREL version", |
132 | 14 | "trel.ver", |
133 | 14 | FT_UINT8, BASE_DEC, NULL, 0xE0, |
134 | 14 | "The TREL protocol version", |
135 | 14 | HFILL |
136 | 14 | } |
137 | 14 | }, |
138 | 14 | { &hf_trel_rsv, |
139 | 14 | { "TREL reserved bit", |
140 | 14 | "trel.rsv", |
141 | 14 | FT_UINT8, BASE_DEC, NULL, 0x18, |
142 | 14 | "The TREL reserved bit", |
143 | 14 | HFILL |
144 | 14 | } |
145 | 14 | }, |
146 | 14 | { &hf_trel_ack, |
147 | 14 | { "TREL acknowledgement", |
148 | 14 | "trel.ack", |
149 | 14 | FT_UINT8, BASE_DEC, NULL, 0x4, |
150 | 14 | "The TREL acknowledgement", |
151 | 14 | HFILL |
152 | 14 | } |
153 | 14 | }, |
154 | 14 | { &hf_trel_type, |
155 | 14 | { "TREL type", |
156 | 14 | "trel.type", |
157 | 14 | FT_UINT8, BASE_DEC, NULL, 0x3, |
158 | 14 | "The TREL type", |
159 | 14 | HFILL |
160 | 14 | } |
161 | 14 | }, |
162 | 14 | { &hf_trel_channel, |
163 | 14 | { "TREL channel", |
164 | 14 | "trel.channel", |
165 | 14 | FT_UINT8, BASE_DEC, NULL, 0x0, |
166 | 14 | "The TREL channel", |
167 | 14 | HFILL |
168 | 14 | } |
169 | 14 | }, |
170 | 14 | { &hf_802154_dest_panid, |
171 | 14 | { "TREL 802.15.4 Dest Pan ID", |
172 | 14 | "trel.panID", |
173 | 14 | FT_UINT16, BASE_DEC, NULL, 0x0, |
174 | 14 | "The TREL 802.15.4 Dest Pan ID", |
175 | 14 | HFILL |
176 | 14 | } |
177 | 14 | }, |
178 | 14 | { &hf_trel_packetno, |
179 | 14 | { "TREL packet number", |
180 | 14 | "trel.packetno", |
181 | 14 | FT_UINT32, BASE_DEC, NULL, 0x0, |
182 | 14 | "The TREL packet number", |
183 | 14 | HFILL |
184 | 14 | } |
185 | 14 | }, |
186 | 14 | { &hf_trel_source_addr, |
187 | 14 | { "TREL Src Address", |
188 | 14 | "trel.source_addr", |
189 | 14 | FT_EUI64, BASE_NONE, NULL, 0x0, |
190 | 14 | "Source address", |
191 | 14 | HFILL |
192 | 14 | } |
193 | 14 | }, |
194 | 14 | { &hf_trel_destination_addr, |
195 | 14 | { "TREL Dest Address", |
196 | 14 | "trel.destination_addr", |
197 | 14 | FT_EUI64, BASE_NONE, NULL, 0x0, |
198 | 14 | "Destination address", |
199 | 14 | HFILL |
200 | 14 | } |
201 | 14 | } |
202 | 14 | }; |
203 | | |
204 | 14 | static int* ett[] = { |
205 | 14 | &ett_trel, |
206 | 14 | &ett_trel_hdr |
207 | 14 | }; |
208 | | |
209 | 14 | proto_trel = proto_register_protocol("TREL Protocol", "TREL", "trel"); |
210 | | |
211 | 14 | proto_register_field_array(proto_trel, hf, array_length(hf)); |
212 | 14 | proto_register_subtree_array(ett, array_length(ett)); |
213 | | |
214 | 14 | trel_handle = register_dissector("trel", dissect_trel, proto_trel); |
215 | | |
216 | 14 | } |
217 | | void |
218 | | proto_reg_handoff_trel(void) |
219 | 14 | { |
220 | | //heur dissector is disabled as it not strong enough |
221 | | //dissector_add_uint("udp.port", TREL_PORT, trel_handle); |
222 | 14 | dissector_add_uint_with_preference("udp.port", 0, trel_handle); |
223 | 14 | heur_dissector_add("udp", dissect_trel_heur, "TREL over UDP", "trel_udp", proto_trel, HEURISTIC_DISABLE); |
224 | 14 | } |