1 /* packet-wisun.c
2 *
3 * Wi-SUN IE Dissectors for Wireshark
4 * By Owen Kirby <osk@exegin.com>
5 * Copyright 2007 Exegin Technologies Limited
6 *
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 *------------------------------------------------------------
9 */
10 #include "config.h"
11 #include <epan/packet.h>
12 #include <epan/expert.h>
13 #include <epan/proto_data.h>
14 #include <wsutil/pint.h>
15 #include <epan/reassemble.h>
16
17 #include "packet-ieee802154.h"
18
19 void proto_register_wisun(void);
20 void proto_reg_handoff_wisun(void);
21
22 /* EDFE support */
23 typedef struct {
24 ieee802154_map_rec initiator;
25 ieee802154_map_rec target;
26 } edfe_exchange_t;
27
28 // for each exchange, maps both source address and destination address to a
29 // (distinct) tree that uses the frame number of the first exchange frame to
30 // map to the shared edfe_exchange_t
31 static wmem_map_t* edfe_byaddr;
32
33 static dissector_handle_t eapol_handle; // for the eapol relay
34
35 static dissector_handle_t ieee802154_nofcs_handle; // for Netricity Segment Control
36
37 static reassembly_table netricity_reassembly_table;
38
39
40 /* Wi-SUN Header IE Sub-ID Values. */
41 #define WISUN_SUBID_UTT 1
42 #define WISUN_SUBID_BT 2
43 #define WISUN_SUBID_FC 3
44 #define WISUN_SUBID_RSL 4
45 #define WISUN_SUBID_MHDS 5
46 #define WISUN_SUBID_VH 6
47 #define WISUN_SUBID_N_NFT 7
48 #define WISUN_SUBID_N_LQI 8
49 #define WISUN_SUBID_EA 9
50
51 /* Wi-SUN Payload/Nested ID values. */
52 #define WISUN_PIE_SUBID_US 1
53 #define WISUN_PIE_SUBID_BS 2
54 #define WISUN_PIE_SUBID_VP 3
55 #define WISUN_PIE_SUBID_PAN 4
56 #define WISUN_PIE_SUBID_NETNAME 5
57 #define WISUN_PIE_SUBID_PENVER 6
58 #define WISUN_PIE_SUBID_GTKHASH 7
59
60 #define WISUN_CHANNEL_PLAN 0x07
61 #define WISUN_CHANNEL_FUNCTION 0x38
62 #define WISUN_CHANNEL_EXCLUDE 0xc0
63
64 #define WISUN_CHANNEL_PLAN_REGULATORY 0
65 #define WISUN_CHANNEL_PLAN_EXPLICIT 1
66 #define WISUN_CHANNEL_FUNCTION_FIXED 0
67 #define WISUN_CHANNEL_FUNCTION_TR51CF 1
68 #define WISUN_CHANNEL_FUNCTION_DH1CF 2
69 #define WISUN_CHANNEL_FUNCTION_VENDOR 3
70 #define WISUN_CHANNEL_EXCLUDE_NONE 0
71 #define WISUN_CHANNEL_EXCLUDE_RANGE 1
72 #define WISUN_CHANNEL_EXCLUDE_MASK 2
73
74 #define WISUN_CH_PLAN_EXPLICIT_FREQ 0x00ffffff
75 #define WISUN_CH_PLAN_EXPLICIT_RESERVED 0xf0000000
76 #define WISUN_CH_PLAN_EXPLICIT_SPACING 0x0f000000
77
78 #define WISUN_EAPOL_RELAY_UDP_PORT 10253
79
80 static int proto_wisun = -1;
81 static int hf_wisun_subid = -1;
82 static int hf_wisun_unknown_ie = -1;
83 static int hf_wisun_uttie = -1;
84 static int hf_wisun_uttie_type = -1;
85 static int hf_wisun_uttie_ufsi = -1;
86 static int hf_wisun_btie = -1;
87 static int hf_wisun_btie_slot = -1;
88 static int hf_wisun_btie_bio = -1;
89 static int hf_wisun_fcie = -1;
90 static int hf_wisun_fcie_tx = -1;
91 static int hf_wisun_fcie_rx = -1;
92 static int hf_wisun_fcie_src = -1;
93 static int hf_wisun_fcie_initial_frame = -1;
94 static int hf_wisun_rslie = -1;
95 static int hf_wisun_rslie_rsl = -1;
96 static int hf_wisun_vhie = -1;
97 static int hf_wisun_vhie_vid = -1;
98 static int hf_wisun_eaie = -1;
99 static int hf_wisun_eaie_eui = -1;
100 static int hf_wisun_pie = -1;
101 static int hf_wisun_wsie = -1;
102 static int hf_wisun_wsie_type = -1;
103 static int hf_wisun_wsie_id = -1;
104 static int hf_wisun_wsie_length = -1;
105 static int hf_wisun_wsie_id_short = -1;
106 static int hf_wisun_wsie_length_short = -1;
107 static int hf_wisun_usie = -1;
108 static int hf_wisun_usie_dwell_interval = -1;
109 static int hf_wisun_usie_clock_drift = -1;
110 static int hf_wisun_usie_timing_accuracy = -1;
111 static int hf_wisun_usie_channel_control = -1;
112 static int hf_wisun_usie_channel_plan = -1;
113 static int hf_wisun_usie_channel_function = -1;
114 static int hf_wisun_usie_channel_exclude = -1;
115 static int hf_wisun_usie_regulatory_domain = -1;
116 static int hf_wisun_usie_operating_class = -1;
117 static int hf_wisun_usie_explicit = -1;
118 static int hf_wisun_usie_explicit_frequency = -1;
119 static int hf_wisun_usie_explicit_reserved = -1;
120 static int hf_wisun_usie_explicit_spacing = -1;
121 static int hf_wisun_usie_number_channels = -1;
122 static int hf_wisun_usie_fixed_channel = -1;
123 static int hf_wisun_usie_hop_count = -1;
124 static int hf_wisun_usie_hop_list = -1;
125 static int hf_wisun_usie_number_ranges = -1;
126 static int hf_wisun_usie_exclude_range = -1;
127 static int hf_wisun_usie_exclude_mask = -1;
128 static int hf_wisun_bsie = -1;
129 static int hf_wisun_bsie_bcast_interval = -1;
130 static int hf_wisun_bsie_bcast_schedule_id = -1;
131 static int hf_wisun_vpie = -1;
132 static int hf_wisun_vpie_vid = -1;
133 static int hf_wisun_panie = -1;
134 static int hf_wisun_panie_size = -1;
135 static int hf_wisun_panie_cost = -1;
136 static int hf_wisun_panie_flags = -1;
137 static int hf_wisun_panie_flag_parent_bsie = -1;
138 static int hf_wisun_panie_flag_routing_method = -1;
139 static int hf_wisun_panie_flag_version = -1;
140 static int hf_wisun_netnameie = -1;
141 static int hf_wisun_netnameie_name = -1;
142 static int hf_wisun_panverie = -1;
143 static int hf_wisun_panverie_version = -1;
144 static int hf_wisun_gtkhashie = -1;
145 static int hf_wisun_gtkhashie_gtk0 = -1;
146 static int hf_wisun_gtkhashie_gtk1 = -1;
147 static int hf_wisun_gtkhashie_gtk2 = -1;
148 static int hf_wisun_gtkhashie_gtk3 = -1;
149
150 static int proto_wisun_sec = -1;
151 static int hf_wisun_sec_function = -1;
152 static int hf_wisun_sec_error_type = -1;
153 static int hf_wisun_sec_error_nonce = -1;
154
155 // EAPOL Relay
156 static dissector_handle_t wisun_eapol_relay_handle;
157 static int proto_wisun_eapol_relay = -1;
158 static int hf_wisun_eapol_relay_sup = -1;
159 static int hf_wisun_eapol_relay_kmp_id = -1;
160 static int hf_wisun_eapol_relay_direction = -1;
161
162 // Netricity
163 static int proto_wisun_netricity_sc;
164 static int hf_wisun_netricity_nftie = -1;
165 static int hf_wisun_netricity_nftie_type = -1;
166 static int hf_wisun_netricity_lqiie = -1;
167 static int hf_wisun_netricity_lqiie_lqi = -1;
168 static int hf_wisun_netricity_sc_flags = -1;
169 static int hf_wisun_netricity_sc_reserved = -1;
170 static int hf_wisun_netricity_sc_tone_map_request = -1;
171 static int hf_wisun_netricity_sc_contention_control = -1;
172 static int hf_wisun_netricity_sc_channel_access_priority = -1;
173 static int hf_wisun_netricity_sc_last_segment = -1;
174 static int hf_wisun_netricity_sc_segment_count = -1;
175 static int hf_wisun_netricity_sc_segment_length = -1;
176 // Reassembly
177 static int hf_wisun_netricity_scr_segments = -1;
178 static int hf_wisun_netricity_scr_segment = -1;
179 static int hf_wisun_netricity_scr_segment_overlap = -1;
180 static int hf_wisun_netricity_scr_segment_overlap_conflicts = -1;
181 static int hf_wisun_netricity_scr_segment_multiple_tails = -1;
182 static int hf_wisun_netricity_scr_segment_too_long_segment = -1;
183 static int hf_wisun_netricity_scr_segment_error = -1;
184 static int hf_wisun_netricity_scr_segment_count = -1;
185 static int hf_wisun_netricity_scr_reassembled_in = -1;
186 static int hf_wisun_netricity_scr_reassembled_length = -1;
187
188 static gint ett_wisun_unknown_ie = -1;
189 static gint ett_wisun_uttie = -1;
190 static gint ett_wisun_btie = -1;
191 static gint ett_wisun_fcie = -1;
192 static gint ett_wisun_rslie = -1;
193 static gint ett_wisun_vhie = -1;
194 static gint ett_wisun_eaie = -1;
195 static gint ett_wisun_pie = -1;
196 static gint ett_wisun_wsie_bitmap = -1;
197 static gint ett_wisun_usie = -1;
198 static gint ett_wisun_bsie = -1;
199 static gint ett_wisun_vpie = -1;
200 static gint ett_wisun_usie_channel_control;
201 static gint ett_wisun_usie_explicit;
202 static gint ett_wisun_panie = -1;
203 static gint ett_wisun_panie_flags = -1;
204 static gint ett_wisun_netnameie = -1;
205 static gint ett_wisun_panverie = -1;
206 static gint ett_wisun_gtkhashie = -1;
207 static gint ett_wisun_sec = -1;
208 static gint ett_wisun_eapol_relay = -1;
209 // Netricity
210 static gint ett_wisun_netricity_nftie = -1;
211 static gint ett_wisun_netricity_lqiie = -1;
212 static gint ett_wisun_netricity_sc = -1;
213 static gint ett_wisun_netricity_sc_bitmask = -1;
214 static gint ett_wisun_netricity_scr_segment = -1;
215 static gint ett_wisun_netricity_scr_segments = -1;
216
217 static const fragment_items netricity_scr_frag_items = {
218 /* Fragment subtrees */
219 &ett_wisun_netricity_scr_segment,
220 &ett_wisun_netricity_scr_segments,
221
222 /* Fragment fields */
223 &hf_wisun_netricity_scr_segments,
224 &hf_wisun_netricity_scr_segment,
225 &hf_wisun_netricity_scr_segment_overlap,
226 &hf_wisun_netricity_scr_segment_overlap_conflicts,
227 &hf_wisun_netricity_scr_segment_multiple_tails,
228 &hf_wisun_netricity_scr_segment_too_long_segment,
229 &hf_wisun_netricity_scr_segment_error,
230 &hf_wisun_netricity_scr_segment_count,
231
232 /* Reassembled in field */
233 &hf_wisun_netricity_scr_reassembled_in,
234
235 /* Reassembled length field */
236 &hf_wisun_netricity_scr_reassembled_length,
237 /* Reassembled data field */
238 NULL,
239
240 /* Tag */
241 "Netricity Segments"
242 };
243
244 static const value_string wisun_wsie_types[] = {
245 { 0, "Short" },
246 { 1, "Long" },
247 { 0, NULL }
248 };
249
250 static const value_string wisun_subid_vals[] = {
251 { WISUN_SUBID_UTT, "Unicast Timing IE" },
252 { WISUN_SUBID_BT, "Broadcast Timing IE" },
253 { WISUN_SUBID_FC, "Flow Control IE" },
254 { WISUN_SUBID_RSL, "Received Signal Level IE" },
255 { WISUN_SUBID_MHDS, "Multi-Hop Delivery Service IE" },
256 { WISUN_SUBID_VH, "Vendor Header IE" },
257 { WISUN_SUBID_N_NFT, "Netricity Frame Type IE" },
258 { WISUN_SUBID_N_LQI, "Link Quality Index IE" },
259 { WISUN_SUBID_EA, "EAPOL Authenticator EUI-64 IE" },
260 { 0, NULL }
261 };
262
263 static const value_string wisun_wsie_names[] = {
264 { WISUN_PIE_SUBID_US, "Unicast Schedule IE" },
265 { WISUN_PIE_SUBID_BS, "Broadcast Schedule IE" },
266 { WISUN_PIE_SUBID_VP, "Vendor Payload IE" },
267 { WISUN_PIE_SUBID_PAN, "PAN Information IE" },
268 { WISUN_PIE_SUBID_NETNAME, "Network Name IE" },
269 { WISUN_PIE_SUBID_PENVER, "PAN Version IE" },
270 { WISUN_PIE_SUBID_GTKHASH, "GTK Hash IE" },
271 { 0, NULL }
272 };
273
274 static const value_string wisun_frame_type_vals[] = {
275 { 0, "PAN Advertisement" },
276 { 1, "PAN Advertisement Solicit" },
277 { 2, "PAN Configuration" },
278 { 3, "PAN Configuration Solicit" },
279 { 4, "Data" },
280 { 5, "Acknowledgment" },
281 { 6, "EAPOL" },
282 { 0, NULL }
283 };
284
285 static const value_string wisun_usie_clock_drift_names[] = {
286 { 0, "Better than 1ppm" },
287 { 255, "Not provided" },
288 { 0, NULL }
289 };
290
291 static const value_string wisun_channel_plan_names[] = {
292 { WISUN_CHANNEL_PLAN_REGULATORY, "Regulatory Domain and Operating Class" },
293 { WISUN_CHANNEL_PLAN_EXPLICIT, "Explicit Spacing and Number" },
294 { 0, NULL }
295 };
296
297 static const value_string wisun_channel_function_names[] = {
298 { WISUN_CHANNEL_FUNCTION_FIXED, "Fixed Channel" },
299 { WISUN_CHANNEL_FUNCTION_TR51CF, "TR51 Channel Function" },
300 { WISUN_CHANNEL_FUNCTION_DH1CF, "Direct Hash Channel Function" },
301 { WISUN_CHANNEL_FUNCTION_VENDOR, "Vendor Defined Channel Function" },
302 { 0, NULL }
303 };
304
305 static const value_string wisun_channel_exclude_names[] = {
306 { WISUN_CHANNEL_EXCLUDE_NONE, "None" },
307 { WISUN_CHANNEL_EXCLUDE_RANGE, "Ranges" },
308 { WISUN_CHANNEL_EXCLUDE_MASK, "Bitmask" },
309 { 0, NULL }
310 };
311
312 static const value_string wisun_channel_regulatory_domains_names[] = {
313 { 0, "World" },
314 { 1, "North America" },
315 { 2, "Japan" },
316 { 3, "Europe" },
317 { 4, "China" },
318 { 5, "India" },
319 { 6, "Mexico" },
320 { 7, "Brazil" },
321 { 8, "Australia / NZ" },
322 { 9, "Korea" },
323 { 10, "Philippines" },
324 { 11, "Malaysia" },
325 { 12, "Hong Kong" },
326 { 13, "Singapore" },
327 { 14, "Thailand" },
328 { 15, "Vietnam" },
329 { 0, NULL }
330 };
331
332 static const value_string wisun_channel_spacing_names[] = {
333 { 0, "200 kHz" },
334 { 1, "400 kHz" },
335 { 2, "600 kHz" },
336 { 3, "100 kHz" },
337 { 0, NULL }
338 };
339
340 static const value_string wisun_routing_methods[] = {
341 { 0, "MHDS" },
342 { 1, "RPL" },
343 { 0, NULL }
344 };
345
346 static const value_string wisun_sec_functions[] = {
347 { 0x01, "SM Error" },
348 { 0, NULL }
349 };
350
351 static const value_string wisun_sec_sm_errors[] = {
352 { 0x01, "No Session" },
353 { 0x02, "Unavailable Key" },
354 { 0x03, "Unsupported Security" },
355 { 0x04, "Invalid Parameter" },
356 { 0x06, "Unsupported Security" },
357 { 0, NULL }
358 };
359
360 static const true_false_string wisun_netricity_sc_contention_control_tfs = {
361 "Contention-free access",
362 "Contention allowed in next contention state"
363 };
364
365 static int * const wisun_format_nested_ie[] = {
366 &hf_wisun_wsie_type,
367 &hf_wisun_wsie_id,
368 &hf_wisun_wsie_length,
369 NULL
370 };
371
372 static int * const wisun_format_nested_ie_short[] = {
373 &hf_wisun_wsie_type,
374 &hf_wisun_wsie_id_short,
375 &hf_wisun_wsie_length_short,
376 NULL
377 };
378
379 static expert_field ei_wisun_subid_unsupported = EI_INIT;
380 static expert_field ei_wisun_wsie_unsupported = EI_INIT;
381 static expert_field ei_wisun_usie_channel_plan_invalid = EI_INIT;
382 static expert_field ei_wisun_edfe_start_not_found = EI_INIT;
383 static expert_field ei_wisun_usie_explicit_reserved_bits_not_zero = EI_INIT;
384
385 static guint
wisun_add_wbxml_uint(tvbuff_t * tvb,proto_tree * tree,int hf,guint offset)386 wisun_add_wbxml_uint(tvbuff_t *tvb, proto_tree *tree, int hf, guint offset)
387 {
388 guint val = 0;
389 guint len = 0;
390 guint8 b;
391 do {
392 b = tvb_get_guint8(tvb, offset + len++);
393 val = (val << 7) | (b & 0x7f);
394 } while (b & 0x80);
395 proto_tree_add_uint(tree, hf, tvb, offset, len, val);
396 return len;
397 }
398
399 /*-----------------------------------------------
400 * Wi-SUN Header IE Dissection
401 *---------------------------------------------*/
402 static proto_tree *
wisun_create_hie_tree(tvbuff_t * tvb,proto_tree * tree,int hf,gint ett)403 wisun_create_hie_tree(tvbuff_t *tvb, proto_tree *tree, int hf, gint ett)
404 {
405 proto_tree *subtree = ieee802154_create_hie_tree(tvb, tree, hf, ett);
406 proto_tree_add_item(subtree, hf_wisun_subid, tvb, 2, 1, ENC_LITTLE_ENDIAN);
407 return subtree;
408 }
409
410 static int
dissect_wisun_uttie(tvbuff_t * tvb,packet_info * pinfo,proto_tree * tree,guint offset)411 dissect_wisun_uttie(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint offset)
412 {
413 guint8 frame_type = tvb_get_guint8(tvb, offset);
414 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Wi-SUN");
415 col_set_str(pinfo->cinfo, COL_INFO, val_to_str_const(frame_type, wisun_frame_type_vals, "Unknown Wi-SUN Frame"));
416 proto_tree_add_item(tree, hf_wisun_uttie_type, tvb, offset, 1, ENC_LITTLE_ENDIAN);
417 proto_tree_add_item(tree, hf_wisun_uttie_ufsi, tvb, offset+1, 3, ENC_LITTLE_ENDIAN);
418 return 4;
419 }
420
421 static int
dissect_wisun_btie(tvbuff_t * tvb,packet_info * pinfo _U_,proto_tree * tree,guint offset)422 dissect_wisun_btie(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, guint offset)
423 {
424 proto_tree_add_item(tree, hf_wisun_btie_slot, tvb, offset, 2, ENC_LITTLE_ENDIAN);
425 /* as of FAN TPS 1v14, this is 3 bytes instead of 4 */
426 proto_tree_add_item(tree, hf_wisun_btie_bio, tvb, offset+2, 3, ENC_LITTLE_ENDIAN);
427 return 5;
428 }
429
430 static void
edfe_insert_exchange(guint64 * addr,edfe_exchange_t * exchange)431 edfe_insert_exchange(guint64* addr, edfe_exchange_t* exchange)
432 {
433 wmem_tree_t* byframe = (wmem_tree_t *)wmem_map_lookup(edfe_byaddr, addr);
434 if (!byframe) {
435 byframe = wmem_tree_new(wmem_file_scope());
436 wmem_map_insert(edfe_byaddr, addr, byframe);
437 }
438 wmem_tree_insert32(byframe, exchange->initiator.start_fnum, exchange);
439 }
440
441 static int
dissect_wisun_fcie(tvbuff_t * tvb,packet_info * pinfo,proto_tree * tree,guint offset,ieee802154_packet * packet)442 dissect_wisun_fcie(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint offset, ieee802154_packet *packet)
443 {
444 guint32 tx;
445 proto_tree_add_item_ret_uint(tree, hf_wisun_fcie_tx, tvb, offset, 1, ENC_LITTLE_ENDIAN, &tx);
446 guint32 rx;
447 proto_tree_add_item_ret_uint(tree, hf_wisun_fcie_rx, tvb, offset+1, 1, ENC_LITTLE_ENDIAN, &rx);
448
449 // EDFE processing
450 ieee802154_hints_t* hints = (ieee802154_hints_t *)p_get_proto_data(wmem_file_scope(), pinfo,
451 proto_get_id_by_filter_name(IEEE802154_PROTOABBREV_WPAN), 0);
452 if (packet && hints && packet->dst_addr_mode == IEEE802154_FCF_ADDR_EXT) {
453 // first packet has source address
454 if (!hints->map_rec && packet->src_addr_mode == IEEE802154_FCF_ADDR_EXT) {
455 edfe_exchange_t* ex = wmem_new(wmem_file_scope(), edfe_exchange_t);
456 ex->initiator.proto = "Wi-SUN";
457 ex->target.proto = "Wi-SUN";
458 ex->initiator.start_fnum = pinfo->num;
459 ex->target.start_fnum = pinfo->num;
460 ex->initiator.end_fnum = ~(guint)0;
461 ex->target.end_fnum = ~(guint)0;
462
463 ex->initiator.addr64 = packet->src64;
464 ex->target.addr64 = packet->dst64;
465 edfe_insert_exchange(&ex->initiator.addr64, ex);
466 edfe_insert_exchange(&ex->target.addr64, ex);
467 } else if (packet->src_addr_mode == IEEE802154_FCF_ADDR_NONE) {
468 if (!hints->map_rec) {
469 wmem_tree_t* byframe = (wmem_tree_t *)wmem_map_lookup(edfe_byaddr, &packet->dst64);
470 if (byframe) {
471 edfe_exchange_t *ex = (edfe_exchange_t *)wmem_tree_lookup32_le(byframe, pinfo->num);
472 if (ex && pinfo->num <= ex->initiator.end_fnum) {
473 hints->map_rec = ex->initiator.addr64 == packet->dst64 ? &ex->target : &ex->initiator;
474 if (tx == 0 && rx == 0) {
475 // last frame
476 ex->initiator.end_fnum = pinfo->num;
477 }
478 }
479 }
480 }
481 if (hints->map_rec) {
482 // Set address to ensure that 6LoWPAN reassembly works
483 // Adapted from packet-ieee802.15.4.c
484 guint64 *p_addr = wmem_new(pinfo->pool, guint64);
485 /* Copy and convert the address to network byte order. */
486 *p_addr = pntoh64(&(hints->map_rec->addr64));
487 set_address(&pinfo->dl_src, AT_EUI64, 8, p_addr);
488 copy_address_shallow(&pinfo->src, &pinfo->dl_src);
489 proto_item* src = proto_tree_add_eui64(tree, hf_wisun_fcie_src, tvb, 0, 0, hints->map_rec->addr64);
490 proto_item_set_generated(src);
491 proto_item* frm = proto_tree_add_uint(tree, hf_wisun_fcie_initial_frame, tvb, 0, 0, hints->map_rec->start_fnum);
492 proto_item_set_generated(frm);
493 } else {
494 expert_add_info(pinfo, tree, &ei_wisun_edfe_start_not_found);
495 }
496 }
497 }
498
499 return 2;
500 }
501
502 static int
dissect_wisun_rslie(tvbuff_t * tvb,packet_info * pinfo _U_,proto_tree * tree,guint offset)503 dissect_wisun_rslie(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, guint offset)
504 {
505 guint32 rsl = tvb_get_guint8(tvb, offset);
506 if (rsl == 0xff) {
507 // "A value of 255 MUST be used to indicate not measured" [FANTPS 1v21]
508 proto_tree_add_uint_format_value(tree, hf_wisun_rslie_rsl, tvb, offset, 1, rsl, "not measured");
509 } else {
510 // "This provides a range of -174 (0) to +80 (254) dBm" [FANTPS 1v21]
511 proto_tree_add_uint_format_value(tree, hf_wisun_rslie_rsl, tvb, offset, 1, rsl, "%d dBm", rsl-174);
512 }
513 return 1;
514 }
515
516 static int
dissect_wisun_vhie(tvbuff_t * tvb,packet_info * pinfo,proto_tree * tree,guint offset)517 dissect_wisun_vhie(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint offset)
518 {
519 guint vidlen = wisun_add_wbxml_uint(tvb, tree, hf_wisun_vhie_vid, offset);
520 call_data_dissector(tvb_new_subset_remaining(tvb, offset + vidlen), pinfo, tree);
521 return tvb_reported_length(tvb);
522 }
523
524 static int
dissect_wisun_eaie(tvbuff_t * tvb,packet_info * pinfo _U_,proto_tree * tree,guint offset)525 dissect_wisun_eaie(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, guint offset)
526 {
527 proto_tree_add_item(tree, hf_wisun_eaie_eui, tvb, offset, 8, ENC_BIG_ENDIAN);
528 return 8;
529 }
530
531 static int
dissect_wisun_netricity_nftie(tvbuff_t * tvb,packet_info * pinfo _U_,proto_tree * tree,guint offset)532 dissect_wisun_netricity_nftie(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, guint offset)
533 {
534 guint8 frame_type = tvb_get_guint8(tvb, offset);
535 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Wi-SUN Netricity");
536 col_set_str(pinfo->cinfo, COL_INFO, val_to_str_const(frame_type, wisun_frame_type_vals, "Unknown Wi-SUN Netricity Frame"));
537 proto_tree_add_item(tree, hf_wisun_netricity_nftie_type, tvb, offset, 1, ENC_LITTLE_ENDIAN);
538 return 1;
539 }
540
541 static int
dissect_wisun_netricity_lqiie(tvbuff_t * tvb,packet_info * pinfo _U_,proto_tree * tree,guint offset)542 dissect_wisun_netricity_lqiie(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, guint offset)
543 {
544 guint8 lqi = tvb_get_guint8(tvb, offset);
545 switch (lqi) {
546 case 0:
547 // "-10 dB or lower (0x00)" [IEEE1901.2-2013]
548 proto_tree_add_uint_format_value(tree, hf_wisun_netricity_lqiie_lqi, tvb, offset, 1, lqi, "0 (SNR -10 dB or lower)");
549 break;
550 case 255:
551 // "A value of 255 MUST be used to indicate 'not measured'" [NTPS 1v04]
552 proto_tree_add_uint_format_value(tree, hf_wisun_netricity_lqiie_lqi, tvb, offset, 1, lqi, "255 (not measured)");
553 break;
554 default:
555 // "where the value of -9.75 dB is represented as 0x01 and the value of 52.75 dB is represented as 0xFE" [IEEE1901.2-2013]
556 proto_tree_add_uint_format_value(tree, hf_wisun_netricity_lqiie_lqi, tvb, offset, 1, lqi, "%d (SNR %1.2f dB)", lqi,
557 (lqi-1) * (52.75+9.75) / (0xfe - 0x01) - 9.75);
558 }
559 return 1;
560 }
561
562 static int
dissect_wisun_hie(tvbuff_t * tvb,packet_info * pinfo,proto_tree * tree,void * data _U_)563 dissect_wisun_hie(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
564 {
565 guint offset;
566 proto_tree *subtree;
567 guint8 subid = tvb_get_guint8(tvb, 2);
568 ieee802154_packet *packet = (ieee802154_packet*)data;
569
570 offset = 3;
571 switch (subid) {
572 case WISUN_SUBID_UTT:
573 subtree = wisun_create_hie_tree(tvb, tree, hf_wisun_uttie, ett_wisun_uttie);
574 offset += dissect_wisun_uttie(tvb, pinfo, subtree, offset);
575 break;
576
577 case WISUN_SUBID_BT:
578 subtree = wisun_create_hie_tree(tvb, tree, hf_wisun_btie, ett_wisun_btie);
579 offset += dissect_wisun_btie(tvb, pinfo, subtree, offset);
580 break;
581
582 case WISUN_SUBID_FC:
583 subtree = wisun_create_hie_tree(tvb, tree, hf_wisun_fcie, ett_wisun_fcie);
584 offset += dissect_wisun_fcie(tvb, pinfo, subtree, offset, packet);
585 break;
586
587 case WISUN_SUBID_RSL:
588 subtree = wisun_create_hie_tree(tvb, tree, hf_wisun_rslie, ett_wisun_rslie);
589 offset += dissect_wisun_rslie(tvb, pinfo, subtree, offset);
590 break;
591
592 case WISUN_SUBID_VH:
593 subtree = wisun_create_hie_tree(tvb, tree, hf_wisun_vhie, ett_wisun_vhie);
594 offset += dissect_wisun_vhie(tvb, pinfo, subtree, offset);
595 break;
596
597 case WISUN_SUBID_N_NFT:
598 subtree = wisun_create_hie_tree(tvb, tree, hf_wisun_netricity_nftie, ett_wisun_netricity_nftie);
599 offset += dissect_wisun_netricity_nftie(tvb, pinfo, subtree, offset);
600 break;
601
602 case WISUN_SUBID_N_LQI:
603 subtree = wisun_create_hie_tree(tvb, tree, hf_wisun_netricity_lqiie, ett_wisun_netricity_lqiie);
604 offset += dissect_wisun_netricity_lqiie(tvb, pinfo, subtree, offset);
605 break;
606
607 case WISUN_SUBID_EA:
608 subtree = wisun_create_hie_tree(tvb, tree, hf_wisun_eaie, ett_wisun_eaie);
609 offset += dissect_wisun_eaie(tvb, pinfo, subtree, offset);
610 break;
611
612 default:
613 subtree = wisun_create_hie_tree(tvb, tree, hf_wisun_unknown_ie, ett_wisun_unknown_ie);
614 expert_add_info(pinfo, subtree, &ei_wisun_subid_unsupported);
615 call_data_dissector(tvb_new_subset_remaining(tvb, offset), pinfo, subtree);
616 offset = tvb_reported_length(tvb);
617 break;
618 }
619 return offset;
620 }
621
622 /*-----------------------------------------------
623 * Wi-SUN Payload IE Dissection
624 *---------------------------------------------*/
625 static int
dissect_wisun_schedule_common(tvbuff_t * tvb,packet_info * pinfo,guint offset,proto_tree * tree)626 dissect_wisun_schedule_common(tvbuff_t *tvb, packet_info *pinfo, guint offset, proto_tree *tree)
627 {
628 static int * const fields_usie_channel[] = {
629 &hf_wisun_usie_channel_plan,
630 &hf_wisun_usie_channel_function,
631 &hf_wisun_usie_channel_exclude,
632 NULL
633 };
634
635 static int * const fields_usie_channel_plan_explicit[] = {
636 &hf_wisun_usie_explicit_frequency,
637 &hf_wisun_usie_explicit_spacing,
638 &hf_wisun_usie_explicit_reserved,
639 NULL
640 };
641 gint count;
642 proto_item *ti;
643
644 proto_tree_add_item(tree, hf_wisun_usie_dwell_interval, tvb, offset, 1, ENC_LITTLE_ENDIAN);
645 offset++;
646 proto_tree_add_item(tree, hf_wisun_usie_clock_drift, tvb, offset, 1, ENC_LITTLE_ENDIAN);
647 offset++;
648 guint clock_drift = tvb_get_guint8(tvb, offset);
649 // "Resolution is 10 microseconds and the valid range of the field value is 0-255 (0 to 2.55msec)" [FANTPS 1v21]
650 proto_tree_add_uint_format_value(tree, hf_wisun_usie_timing_accuracy, tvb, offset, 1, clock_drift, "%1.2fms", clock_drift/100.0);
651 offset++;
652 guint8 control = tvb_get_guint8(tvb, offset);
653 proto_tree_add_bitmask_with_flags(tree, tvb, offset, hf_wisun_usie_channel_control, ett_wisun_usie_channel_control,
654 fields_usie_channel, ENC_LITTLE_ENDIAN, BMT_NO_FLAGS);
655 offset++;
656
657 switch ((control & WISUN_CHANNEL_PLAN) >> 0) {
658 case WISUN_CHANNEL_PLAN_REGULATORY:
659 proto_tree_add_item(tree, hf_wisun_usie_regulatory_domain, tvb, offset, 1, ENC_LITTLE_ENDIAN);
660 offset++;
661 proto_tree_add_item(tree, hf_wisun_usie_operating_class, tvb, offset, 1, ENC_LITTLE_ENDIAN);
662 offset++;
663 break;
664
665 case WISUN_CHANNEL_PLAN_EXPLICIT:
666 ti = proto_tree_add_bitmask(tree, tvb, offset, hf_wisun_usie_explicit, ett_wisun_usie_explicit,
667 fields_usie_channel_plan_explicit, ENC_LITTLE_ENDIAN);
668 offset += 3;
669 if (tvb_get_guint8(tvb, offset) & 0xf0) {
670 expert_add_info(pinfo, ti, &ei_wisun_usie_explicit_reserved_bits_not_zero);
671 }
672 offset++;
673 proto_tree_add_item(tree, hf_wisun_usie_number_channels, tvb, offset, 2, ENC_LITTLE_ENDIAN);
674 offset += 2;
675 break;
676
677 default:
678 expert_add_info(pinfo, tree, &ei_wisun_usie_channel_plan_invalid);
679 return tvb_reported_length(tvb);
680 }
681
682 switch ((control & WISUN_CHANNEL_FUNCTION) >> 3) {
683 case WISUN_CHANNEL_FUNCTION_FIXED:
684 proto_tree_add_item(tree, hf_wisun_usie_fixed_channel, tvb, offset, 2, ENC_LITTLE_ENDIAN);
685 offset += 2;
686 break;
687
688 case WISUN_CHANNEL_FUNCTION_VENDOR:
689 count = tvb_get_guint8(tvb, offset);
690 proto_tree_add_item(tree, hf_wisun_usie_hop_count, tvb, offset, 1, ENC_LITTLE_ENDIAN);
691 offset++;
692 while (count--) {
693 proto_tree_add_item(tree, hf_wisun_usie_hop_list, tvb, offset, 1, ENC_LITTLE_ENDIAN);
694 offset++;
695 }
696 break;
697
698 default:
699 /* Hopping list is implied by the hashing function. */
700 break;
701 }
702
703 switch ((control & WISUN_CHANNEL_EXCLUDE) >> 6) {
704 case WISUN_CHANNEL_EXCLUDE_RANGE:
705 count = tvb_get_guint8(tvb, offset);
706 proto_tree_add_item(tree, hf_wisun_usie_number_ranges, tvb, offset, 1, ENC_LITTLE_ENDIAN);
707 offset++;
708 while (count) {
709 guint16 ex_start = tvb_get_letohs(tvb, offset);
710 guint16 ex_end = tvb_get_letohs(tvb, offset+2);
711 proto_tree_add_uint_format_value(tree, hf_wisun_usie_exclude_range, tvb, offset, 4, ex_start, "[%u-%u]", ex_start, ex_end);
712 offset += 4;
713 count--;
714 }
715 break;
716
717 case WISUN_CHANNEL_EXCLUDE_MASK:
718 count = tvb_reported_length_remaining(tvb, offset);
719 proto_tree_add_item(tree, hf_wisun_usie_exclude_mask, tvb, offset, count, ENC_NA);
720 offset += count;
721 break;
722
723 default:
724 /* Assume there is nothing to exclude. */
725 break;
726 }
727 return offset;
728 }
729
730 static int
dissect_wisun_usie(tvbuff_t * tvb,packet_info * pinfo,proto_tree * tree,void * data _U_)731 dissect_wisun_usie(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
732 {
733 proto_item *item;
734 proto_tree *subtree;
735 guint offset = 0;
736
737 item = proto_tree_add_item(tree, hf_wisun_usie, tvb, 0, tvb_reported_length_remaining(tvb, 0), ENC_NA);
738 subtree = proto_item_add_subtree(item, ett_wisun_usie);
739
740 proto_tree_add_bitmask(subtree, tvb, offset, hf_wisun_wsie, ett_wisun_wsie_bitmap, wisun_format_nested_ie, ENC_LITTLE_ENDIAN);
741 offset += 2;
742
743 return dissect_wisun_schedule_common(tvb, pinfo, offset, subtree);
744 }
745
746 static int
dissect_wisun_bsie(tvbuff_t * tvb,packet_info * pinfo,proto_tree * tree,void * data _U_)747 dissect_wisun_bsie(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
748 {
749 proto_item *item;
750 proto_tree *subtree;
751 guint offset = 0;
752
753 item = proto_tree_add_item(tree, hf_wisun_bsie, tvb, 0, tvb_reported_length(tvb), ENC_NA);
754 subtree = proto_item_add_subtree(item, ett_wisun_bsie);
755
756 proto_tree_add_bitmask(subtree, tvb, offset, hf_wisun_wsie, ett_wisun_wsie_bitmap, wisun_format_nested_ie, ENC_LITTLE_ENDIAN);
757 offset += 2;
758 proto_tree_add_item(subtree, hf_wisun_bsie_bcast_interval, tvb, offset, 4, ENC_LITTLE_ENDIAN);
759 offset += 4;
760 proto_tree_add_item(subtree, hf_wisun_bsie_bcast_schedule_id, tvb, offset, 2, ENC_LITTLE_ENDIAN);
761 offset += 2;
762
763 return dissect_wisun_schedule_common(tvb, pinfo, offset, subtree);
764 }
765
766 static int
dissect_wisun_vpie(tvbuff_t * tvb,packet_info * pinfo _U_,proto_tree * tree,void * data _U_)767 dissect_wisun_vpie(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, void *data _U_)
768 {
769 proto_item *item;
770 proto_tree *subtree;
771 guint vidlen;
772
773 item = proto_tree_add_item(tree, hf_wisun_vpie, tvb, 0, tvb_reported_length(tvb), ENC_NA);
774 subtree = proto_item_add_subtree(item, ett_wisun_vpie);
775
776 vidlen = wisun_add_wbxml_uint(tvb, subtree, hf_wisun_vpie_vid, 2);
777 call_data_dissector(tvb_new_subset_remaining(tvb, 2 + vidlen), pinfo, subtree);
778 return tvb_reported_length(tvb);
779 }
780
781 static int
dissect_wisun_panie(tvbuff_t * tvb,packet_info * pinfo _U_,proto_tree * tree,void * data _U_)782 dissect_wisun_panie(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, void *data _U_)
783 {
784 proto_item *item;
785 proto_tree *subtree;
786 guint offset = 0;
787 guint32 routingCost;
788 static int * const fields_panie_flags[] = {
789 &hf_wisun_panie_flag_parent_bsie,
790 &hf_wisun_panie_flag_routing_method,
791 &hf_wisun_panie_flag_version,
792 NULL
793 };
794
795 item = proto_tree_add_item(tree, hf_wisun_panie, tvb, 0, tvb_reported_length(tvb), ENC_NA);
796 subtree = proto_item_add_subtree(item, ett_wisun_panie);
797
798 proto_tree_add_bitmask(subtree, tvb, offset, hf_wisun_wsie, ett_wisun_wsie_bitmap, wisun_format_nested_ie_short, ENC_LITTLE_ENDIAN);
799 offset += 2;
800 proto_tree_add_item(subtree, hf_wisun_panie_size, tvb, offset, 2, ENC_LITTLE_ENDIAN);
801 offset += 2;
802 proto_tree_add_item_ret_uint(subtree, hf_wisun_panie_cost, tvb, offset, 2, ENC_LITTLE_ENDIAN, &routingCost);
803 offset += 2;
804 proto_tree_add_bitmask_with_flags(subtree, tvb, offset, hf_wisun_panie_flags, ett_wisun_panie_flags,
805 fields_panie_flags, ENC_LITTLE_ENDIAN, BMT_NO_FLAGS);
806 offset++;
807
808 col_append_sep_fstr(pinfo->cinfo, COL_INFO, ", ", "Routing Cost: %d", routingCost);
809
810 return offset;
811 }
812
813 static int
dissect_wisun_netnameie(tvbuff_t * tvb,packet_info * pinfo _U_,proto_tree * tree,void * data _U_)814 dissect_wisun_netnameie(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, void *data _U_)
815 {
816 proto_item *item;
817 proto_tree *subtree;
818
819 item = proto_tree_add_item(tree, hf_wisun_netnameie, tvb, 0, tvb_reported_length(tvb), ENC_NA);
820 subtree = proto_item_add_subtree(item, ett_wisun_netnameie);
821
822 proto_tree_add_bitmask(subtree, tvb, 0, hf_wisun_wsie, ett_wisun_wsie_bitmap, wisun_format_nested_ie_short, ENC_LITTLE_ENDIAN);
823 proto_tree_add_item(subtree, hf_wisun_netnameie_name, tvb, 2, tvb_reported_length_remaining(tvb, 2), ENC_ASCII|ENC_NA);
824
825 col_append_sep_fstr(pinfo->cinfo, COL_INFO, ", ", "Netname: %s",
826 tvb_get_string_enc(pinfo->pool, tvb, 2, tvb_reported_length_remaining(tvb, 2), ENC_ASCII));
827 return tvb_reported_length(tvb);
828 }
829
830 static int
dissect_wisun_panverie(tvbuff_t * tvb,packet_info * pinfo _U_,proto_tree * tree,void * data _U_)831 dissect_wisun_panverie(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, void *data _U_)
832 {
833 proto_item *item;
834 proto_tree *subtree;
835
836 item = proto_tree_add_item(tree, hf_wisun_panverie, tvb, 0, tvb_reported_length(tvb), ENC_NA);
837 subtree = proto_item_add_subtree(item, ett_wisun_panverie);
838
839 proto_tree_add_bitmask(subtree, tvb, 0, hf_wisun_wsie, ett_wisun_wsie_bitmap, wisun_format_nested_ie_short, ENC_LITTLE_ENDIAN);
840 proto_tree_add_item(subtree, hf_wisun_panverie_version, tvb, 2, 2, ENC_LITTLE_ENDIAN);
841
842 col_append_sep_fstr(pinfo->cinfo, COL_INFO, ", ", "PAN Version: %d", tvb_get_guint16(tvb, 2, ENC_LITTLE_ENDIAN));
843
844 return tvb_reported_length(tvb);
845 }
846
847 static int
dissect_wisun_gtkhashie(tvbuff_t * tvb,packet_info * pinfo _U_,proto_tree * tree,void * data _U_)848 dissect_wisun_gtkhashie(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, void *data _U_)
849 {
850 proto_item *item;
851 proto_tree *subtree;
852
853 item = proto_tree_add_item(tree, hf_wisun_gtkhashie, tvb, 0, tvb_reported_length(tvb), ENC_NA);
854 subtree = proto_item_add_subtree(item, ett_wisun_gtkhashie);
855
856 proto_tree_add_bitmask(subtree, tvb, 0, hf_wisun_wsie, ett_wisun_wsie_bitmap, wisun_format_nested_ie_short, ENC_LITTLE_ENDIAN);
857 proto_tree_add_item(subtree, hf_wisun_gtkhashie_gtk0, tvb, 2, 8, ENC_NA);
858 proto_tree_add_item(subtree, hf_wisun_gtkhashie_gtk1, tvb, 10, 8, ENC_NA);
859 proto_tree_add_item(subtree, hf_wisun_gtkhashie_gtk2, tvb, 18, 8, ENC_NA);
860 proto_tree_add_item(subtree, hf_wisun_gtkhashie_gtk3, tvb, 26, 8, ENC_NA);
861 return 34;
862 }
863
864 static int
dissect_wisun_pie(tvbuff_t * tvb,packet_info * pinfo,proto_tree * ies_tree,void * data)865 dissect_wisun_pie(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ies_tree, void *data)
866 {
867 proto_tree *tree = ieee802154_create_pie_tree(tvb, ies_tree, hf_wisun_pie, ett_wisun_pie);
868 guint offset = 2;
869 while (tvb_reported_length_remaining(tvb, offset) > 1) {
870 /* Wi-SUN Payload IE contains nested IE's using the same format as IEEE802.15.4 */
871 guint16 wsie_ie = tvb_get_letohs(tvb, offset);
872 guint16 wsie_len;
873 tvbuff_t * wsie_tvb;
874
875 if (wsie_ie & IEEE802154_PSIE_TYPE_MASK) {
876 /* long format: Table 7-17-Sub-ID allocation for long format */
877 wsie_len = (wsie_ie & IEEE802154_PSIE_LENGTH_MASK_LONG);
878 wsie_tvb = tvb_new_subset_length(tvb, offset, wsie_len + 2);
879 switch ((wsie_ie & IEEE802154_PSIE_ID_MASK_LONG) >> 11) {
880 case WISUN_PIE_SUBID_US:
881 dissect_wisun_usie(wsie_tvb, pinfo, tree, data);
882 break;
883 case WISUN_PIE_SUBID_BS:
884 dissect_wisun_bsie(wsie_tvb, pinfo, tree, data);
885 break;
886 case WISUN_PIE_SUBID_VP:
887 dissect_wisun_vpie(wsie_tvb, pinfo, tree, data);
888 break;
889
890 default:{
891 proto_item *item = proto_tree_add_item(tree, hf_wisun_unknown_ie, wsie_tvb, 0, tvb_reported_length(wsie_tvb), ENC_NA);
892 proto_tree *subtree = proto_item_add_subtree(item, ett_wisun_unknown_ie);
893 proto_tree_add_bitmask(subtree, wsie_tvb, 0, hf_wisun_wsie, ett_wisun_wsie_bitmap, wisun_format_nested_ie, ENC_LITTLE_ENDIAN);
894 expert_add_info(pinfo, subtree, &ei_wisun_wsie_unsupported);
895 call_data_dissector(tvb_new_subset_remaining(wsie_tvb, 2), pinfo, subtree);
896 break;
897 }
898 }
899 } else {
900 /* short format: Table 7-16-Sub-ID allocation for short format */
901 wsie_len = (wsie_ie & IEEE802154_PSIE_LENGTH_MASK_SHORT);
902 wsie_tvb = tvb_new_subset_length(tvb, offset, wsie_len + 2);
903 switch ((wsie_ie & IEEE802154_PSIE_ID_MASK_SHORT) >> 8) {
904 case WISUN_PIE_SUBID_PAN:
905 dissect_wisun_panie(wsie_tvb, pinfo, tree, data);
906 break;
907 case WISUN_PIE_SUBID_NETNAME:
908 dissect_wisun_netnameie(wsie_tvb, pinfo, tree, data);
909 break;
910 case WISUN_PIE_SUBID_PENVER:
911 dissect_wisun_panverie(wsie_tvb, pinfo, tree, data);
912 break;
913 case WISUN_PIE_SUBID_GTKHASH:
914 dissect_wisun_gtkhashie(wsie_tvb, pinfo, tree, data);
915 break;
916
917 default:{
918 proto_item *item = proto_tree_add_item(tree, hf_wisun_unknown_ie, wsie_tvb, 0, tvb_reported_length(wsie_tvb), ENC_NA);
919 proto_tree *subtree = proto_item_add_subtree(item, ett_wisun_unknown_ie);
920 proto_tree_add_bitmask(subtree, wsie_tvb, 0, hf_wisun_wsie, ett_wisun_wsie_bitmap, wisun_format_nested_ie, ENC_LITTLE_ENDIAN);
921 expert_add_info(pinfo, subtree, &ei_wisun_wsie_unsupported);
922 call_data_dissector(tvb_new_subset_remaining(wsie_tvb, 2), pinfo, subtree);
923 break;
924 }
925 }
926 }
927 offset += tvb_reported_length(wsie_tvb);
928 }
929 return offset;
930 }
931
932 /*-----------------------------------------------
933 * Wi-SUN FAN Security Extensions Dissection
934 *---------------------------------------------*/
935 static int
dissect_wisun_sec(tvbuff_t * tvb,packet_info * pinfo,proto_tree * tree,void * data _U_)936 dissect_wisun_sec(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
937 {
938 proto_item *ws_root;
939 proto_tree *ws_tree;
940 guint8 function = tvb_get_guint8(tvb, 0);
941 const char *function_name = val_to_str_const(function, wisun_sec_functions, "Unknown Function");
942
943 /* Create the protocol tree. */
944 ws_root = proto_tree_add_protocol_format(tree, proto_wisun_sec, tvb, 0, -1, "Wi-SUN %s", function_name);
945 ws_tree = proto_item_add_subtree(ws_root, ett_wisun_sec);
946
947 /* Add the protocol name. */
948 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Wi-SUN");
949 col_set_str(pinfo->cinfo, COL_INFO, function_name);
950
951 /* Decode based on the function code. */
952 proto_tree_add_item(ws_tree, hf_wisun_sec_function, tvb, 0, 1, ENC_LITTLE_ENDIAN);
953 switch (function) {
954 case 0x01:{
955 const char *err_name = val_to_str_const(tvb_get_guint8(tvb, 1), wisun_sec_sm_errors, "Unknown Error");
956 col_append_fstr(pinfo->cinfo, COL_INFO, ": %s", err_name);
957 proto_item_append_text(ws_root, ": %s", err_name);
958
959 proto_tree_add_item(ws_tree, hf_wisun_sec_error_type, tvb, 1, 1, ENC_LITTLE_ENDIAN);
960 proto_tree_add_item(ws_tree, hf_wisun_sec_error_nonce, tvb, 2, tvb_reported_length_remaining(tvb, 2), ENC_NA);
961 return tvb_reported_length(tvb);
962 }
963
964 default:
965 call_data_dissector(tvb_new_subset_remaining(tvb, 2), pinfo, ws_tree);
966 return tvb_reported_length(tvb);
967 }
968 }
969
970
971 /*-----------------------------------------------
972 * Wi-SUN FAN EAPOL Relay
973 *---------------------------------------------*/
974
dissect_wisun_eapol_relay(tvbuff_t * tvb,packet_info * pinfo,proto_tree * tree,void * data _U_)975 static int dissect_wisun_eapol_relay(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
976 {
977 guint offset = 0;
978 proto_item *subitem = proto_tree_add_item(tree, proto_wisun_eapol_relay, tvb, offset, 9, ENC_NA);
979 proto_tree *subtree = proto_item_add_subtree(subitem, ett_wisun_eapol_relay);
980
981 proto_tree_add_item(subtree, hf_wisun_eapol_relay_sup, tvb, offset, 8, ENC_BIG_ENDIAN);
982 offset += 8;
983 proto_tree_add_item(subtree, hf_wisun_eapol_relay_kmp_id, tvb, offset, 1, ENC_NA);
984 offset += 1;
985
986 int up = 0;
987 // eapol.type == EAP_PACKET?
988 if (tvb_get_guint8(tvb, offset+1) == 0) {
989 up = tvb_get_guint8(tvb, offset+4) == 2; // eap.code == EAP_CODE_RESPONSE
990 } else {
991 up = (tvb_get_guint8(tvb, offset+6) & 0x80) == 0; // Key Info ACK==0
992 }
993 proto_item* diritem = proto_tree_add_boolean(subtree, hf_wisun_eapol_relay_direction, tvb, offset, 0, (guint32) up);
994 proto_item_set_generated(diritem);
995
996 int r = call_dissector(eapol_handle, tvb_new_subset_remaining(tvb, offset), pinfo, tree);
997
998 // UTF-8 arrow up or down
999 col_append_str(pinfo->cinfo, COL_INFO, up ? " [Relay \xe2\x86\x91]" : " [Relay \xe2\x86\x93]");
1000
1001 return offset + r;
1002 }
1003
1004 /*-----------------------------------------------
1005 * Wi-SUN Netricity Segment Control
1006 *---------------------------------------------*/
1007
dissect_wisun_netricity_sc(tvbuff_t * tvb,packet_info * pinfo,proto_tree * tree,void * data _U_)1008 static int dissect_wisun_netricity_sc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
1009 {
1010 static int * const fields_sc[] = {
1011 &hf_wisun_netricity_sc_reserved,
1012 &hf_wisun_netricity_sc_tone_map_request,
1013 &hf_wisun_netricity_sc_contention_control,
1014 &hf_wisun_netricity_sc_channel_access_priority,
1015 &hf_wisun_netricity_sc_last_segment,
1016 NULL
1017 };
1018
1019 guint offset = 0;
1020
1021 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Wi-SUN Netricity");
1022
1023 proto_item *subitem = proto_tree_add_item(tree, proto_wisun_netricity_sc, tvb, offset, -1, ENC_NA);
1024 proto_tree *subtree = proto_item_add_subtree(subitem, ett_wisun_netricity_sc);
1025
1026 gboolean is_last = tvb_get_guint8(tvb, 0) & 1;
1027 proto_tree_add_bitmask(subtree, tvb, offset++, hf_wisun_netricity_sc_flags, ett_wisun_netricity_sc_bitmask, fields_sc, ENC_BIG_ENDIAN);
1028 guint32 seg_count;
1029 guint32 seg_len;
1030 proto_tree_add_item_ret_uint(subtree, hf_wisun_netricity_sc_segment_count, tvb, offset, 2, ENC_BIG_ENDIAN, &seg_count);
1031 proto_tree_add_item_ret_uint(subtree, hf_wisun_netricity_sc_segment_length, tvb, offset, 2, ENC_BIG_ENDIAN, &seg_len);
1032 offset += 2;
1033
1034 gboolean is_segmented = !is_last || seg_count != 0;
1035 proto_tree *ieee802154_tree;
1036 ieee802154_packet *packet;
1037 tvbuff_t *frame = tvb_new_subset_remaining(tvb, offset);
1038 // if security is used, all segments have the flag set in the FCF, but only the first has the Auxiliary Security Header
1039 guint mhr_len = ieee802154_dissect_header(frame, pinfo,
1040 is_segmented ? subtree : tree,
1041 seg_count == 0 ? 0 : IEEE802154_DISSECT_HEADER_OPTION_NO_AUX_SEC_HDR,
1042 &ieee802154_tree, &packet);
1043 if (!mhr_len) {
1044 return tvb_captured_length(tvb);
1045 }
1046 frame = tvb_new_subset_length(frame, 0, mhr_len + seg_len);
1047
1048 if (is_segmented) {
1049 gboolean save_fragmented = pinfo->fragmented;
1050 pinfo->fragmented = TRUE;
1051 fragment_head *frag_msg = fragment_add_seq_check(&netricity_reassembly_table,
1052 frame,
1053 seg_count == 0 ? 0 : mhr_len,
1054 pinfo,
1055 packet->seqno,
1056 NULL,
1057 seg_count,
1058 (seg_count == 0 ? mhr_len : 0) + seg_len,
1059 !is_last);
1060 tvbuff_t *reframe = process_reassembled_data(tvb, offset, pinfo, "Reassembled segments", frag_msg, &netricity_scr_frag_items, NULL, subtree);
1061
1062 if (reframe) {
1063 call_dissector(ieee802154_nofcs_handle, reframe, pinfo, tree);
1064 col_append_fstr(pinfo->cinfo, COL_INFO, " (Reassembled %u segments)", seg_count + 1);
1065 } else {
1066 call_data_dissector(tvb_new_subset_remaining(frame, mhr_len), pinfo, subtree);
1067 col_append_fstr(pinfo->cinfo, COL_INFO, " (Segment %u)", seg_count);
1068 }
1069
1070 pinfo->fragmented = save_fragmented;
1071 } else {
1072 tvbuff_t *payload = ieee802154_decrypt_payload(frame, mhr_len, pinfo, ieee802154_tree, packet);
1073 if (payload) {
1074 guint pie_size = ieee802154_dissect_payload_ies(payload, pinfo, ieee802154_tree, packet);
1075 payload = tvb_new_subset_remaining(payload, pie_size);
1076 ieee802154_dissect_frame_payload(payload, pinfo, ieee802154_tree, packet, TRUE);
1077 }
1078 }
1079
1080 return tvb_captured_length(tvb);
1081 }
1082
1083 /*-----------------------------------------------
1084 * Wi-SUN Protocol Registration
1085 *---------------------------------------------*/
proto_register_wisun(void)1086 void proto_register_wisun(void)
1087 {
1088 static hf_register_info hf[] = {
1089 /* Wi-SUN Header IEs */
1090 { &hf_wisun_subid,
1091 { "Header Sub ID", "wisun.subid", FT_UINT8, BASE_DEC, VALS(wisun_subid_vals), 0x0,
1092 NULL, HFILL }
1093 },
1094
1095 { &hf_wisun_unknown_ie,
1096 { "Unknown IE", "wisun.unknown", FT_NONE, BASE_NONE, NULL, 0x0,
1097 NULL, HFILL }
1098 },
1099
1100 { &hf_wisun_uttie,
1101 { "Unicast Timing IE", "wisun.uttie", FT_NONE, BASE_NONE, NULL, 0x0,
1102 NULL, HFILL }
1103 },
1104
1105 { &hf_wisun_uttie_type,
1106 { "Frame Type", "wisun.uttie.type", FT_UINT8, BASE_DEC, VALS(wisun_frame_type_vals), 0x0,
1107 NULL, HFILL }
1108 },
1109
1110 { &hf_wisun_uttie_ufsi,
1111 { "Unicast Fractional Sequence Interval", "wisun.uttie.ufsi", FT_UINT24, BASE_DEC, NULL, 0x0,
1112 NULL, HFILL }
1113 },
1114
1115 { &hf_wisun_btie,
1116 { "Broadcast Timing IE", "wisun.btie", FT_NONE, BASE_NONE, NULL, 0x0,
1117 NULL, HFILL }
1118 },
1119
1120 { &hf_wisun_btie_slot,
1121 { "Broadcast Slot Number", "wisun.btie.slot", FT_UINT24, BASE_DEC, NULL, 0x0,
1122 NULL, HFILL }
1123 },
1124
1125 { &hf_wisun_btie_bio,
1126 { "Broadcast Interval Offset", "wisun.btie.bio", FT_UINT24, BASE_DEC|BASE_UNIT_STRING, &units_milliseconds, 0x0,
1127 NULL, HFILL }
1128 },
1129
1130 { &hf_wisun_fcie,
1131 { "Flow Control IE", "wisun.fcie", FT_NONE, BASE_NONE, NULL, 0x0,
1132 NULL, HFILL }
1133 },
1134
1135 { &hf_wisun_fcie_tx,
1136 { "Transmit Flow Control", "wisun.fcie.tx", FT_UINT8, BASE_DEC|BASE_UNIT_STRING, &units_milliseconds, 0x0,
1137 NULL, HFILL }
1138 },
1139
1140 { &hf_wisun_fcie_rx,
1141 { "Receive Flow Control", "wisun.fcie.rx", FT_UINT8, BASE_DEC|BASE_UNIT_STRING, &units_milliseconds, 0x0,
1142 NULL, HFILL }
1143 },
1144
1145 { &hf_wisun_fcie_src,
1146 { "Source Address", "wisun.fcie.src", FT_EUI64, BASE_NONE, NULL, 0x0,
1147 NULL, HFILL }
1148 },
1149
1150 { &hf_wisun_fcie_initial_frame,
1151 { "Initial Frame", "wisun.fcie.initial_frame", FT_FRAMENUM, BASE_NONE, FRAMENUM_TYPE(FT_FRAMENUM_REQUEST), 0x0,
1152 NULL, HFILL }
1153 },
1154
1155 { &hf_wisun_rslie,
1156 { "Received Signal Level IE", "wisun.rslie", FT_NONE, BASE_NONE, NULL, 0x0,
1157 NULL, HFILL }
1158 },
1159
1160 { &hf_wisun_rslie_rsl,
1161 { "Received Signal Level", "wisun.rslie.rsl", FT_UINT8, BASE_DEC, NULL, 0x0,
1162 NULL, HFILL }
1163 },
1164
1165 { &hf_wisun_vhie,
1166 { "Vendor Header IE", "wisun.vhie", FT_NONE, BASE_NONE, NULL, 0x0,
1167 NULL, HFILL }
1168 },
1169
1170 { &hf_wisun_vhie_vid,
1171 { "Vendor ID", "wisun.vhie.vid", FT_UINT32, BASE_DEC, NULL, 0x0,
1172 NULL, HFILL }
1173 },
1174
1175 { &hf_wisun_eaie,
1176 { "EAPOL Authenticator IE", "wisun.eaie", FT_NONE, BASE_NONE, NULL, 0x0,
1177 NULL, HFILL }
1178 },
1179
1180 { &hf_wisun_eaie_eui,
1181 { "Authenticator EUI-64", "wisun.eaie.eui", FT_EUI64, BASE_NONE, NULL, 0x0,
1182 NULL, HFILL }
1183 },
1184
1185 /* Wi-SUN Payload IE */
1186 { &hf_wisun_pie,
1187 { "Wi-SUN Payload IE", "wisun.pie", FT_NONE, BASE_NONE, NULL, 0x0,
1188 NULL, HFILL }
1189 },
1190
1191 { &hf_wisun_wsie,
1192 { "Wi-SUN Sub IE", "wisun.wsie", FT_UINT16, BASE_HEX, NULL, 0x0,
1193 NULL, HFILL }
1194 },
1195
1196 { &hf_wisun_wsie_type,
1197 { "Type", "wisun.wsie.type", FT_UINT16, BASE_DEC, VALS(wisun_wsie_types), IEEE802154_PSIE_TYPE_MASK,
1198 NULL, HFILL }
1199 },
1200
1201 { &hf_wisun_wsie_id,
1202 { "Sub ID", "wisun.wsie.id", FT_UINT16, BASE_DEC, VALS(wisun_wsie_names), IEEE802154_PSIE_ID_MASK_LONG,
1203 NULL, HFILL }
1204 },
1205
1206 { &hf_wisun_wsie_length,
1207 { "Length", "wisun.wsie.length", FT_UINT16, BASE_DEC, NULL, IEEE802154_PSIE_LENGTH_MASK_LONG,
1208 NULL, HFILL }
1209 },
1210
1211 { &hf_wisun_wsie_id_short,
1212 { "Sub ID", "wisun.wsie.id", FT_UINT16, BASE_DEC, VALS(wisun_wsie_names), IEEE802154_PSIE_ID_MASK_SHORT,
1213 NULL, HFILL }
1214 },
1215
1216 { &hf_wisun_wsie_length_short,
1217 { "Length", "wisun.wsie.length", FT_UINT16, BASE_DEC, NULL, IEEE802154_PSIE_LENGTH_MASK_SHORT,
1218 NULL, HFILL }
1219 },
1220
1221 { &hf_wisun_usie,
1222 { "Unicast Schedule IE", "wisun.usie", FT_NONE, BASE_NONE, NULL, 0x0,
1223 NULL, HFILL }
1224 },
1225
1226 { &hf_wisun_usie_dwell_interval,
1227 { "Dwell Interval", "wisun.usie.dwell", FT_UINT8, BASE_DEC|BASE_UNIT_STRING, &units_milliseconds, 0x0,
1228 NULL, HFILL }
1229 },
1230
1231 { &hf_wisun_usie_clock_drift,
1232 { "Clock Drift", "wisun.usie.drift", FT_UINT8, BASE_DEC|BASE_SPECIAL_VALS, VALS(wisun_usie_clock_drift_names), 0x0,
1233 "Clock Drift in +/- ppm", HFILL }
1234 },
1235
1236 { &hf_wisun_usie_timing_accuracy,
1237 { "Timing Accuracy", "wisun.usie.accuracy", FT_UINT8, BASE_DEC, NULL, 0x0,
1238 NULL, HFILL }
1239 },
1240
1241 { &hf_wisun_usie_channel_control,
1242 { "Channel Control", "wisun.usie.channel", FT_UINT8, BASE_HEX, NULL, 0x0,
1243 NULL, HFILL }
1244 },
1245
1246 { &hf_wisun_usie_channel_plan,
1247 { "Channel Plan", "wisun.usie.channel.plan", FT_UINT8, BASE_DEC, VALS(wisun_channel_plan_names), WISUN_CHANNEL_PLAN,
1248 NULL, HFILL }
1249 },
1250
1251 { &hf_wisun_usie_channel_function,
1252 { "Channel Function", "wisun.usie.channel.function", FT_UINT8, BASE_DEC, VALS(wisun_channel_function_names), WISUN_CHANNEL_FUNCTION,
1253 NULL, HFILL }
1254 },
1255
1256 { &hf_wisun_usie_channel_exclude,
1257 { "Excluded Channels", "wisun.usie.channel.exclude", FT_UINT8, BASE_DEC, VALS(wisun_channel_exclude_names), WISUN_CHANNEL_EXCLUDE,
1258 NULL, HFILL }
1259 },
1260
1261 { &hf_wisun_usie_regulatory_domain,
1262 { "Regulatory Domain", "wisun.usie.domain", FT_UINT8, BASE_DEC, VALS(wisun_channel_regulatory_domains_names), 0x0,
1263 NULL, HFILL }
1264 },
1265
1266 { &hf_wisun_usie_operating_class,
1267 { "Operating Class", "wisun.usie.class", FT_UINT8, BASE_DEC, NULL, 0x0,
1268 NULL, HFILL }
1269 },
1270
1271 { &hf_wisun_usie_explicit,
1272 { "Explicit Channel Plan", "wisun.usie.explicit", FT_UINT32, BASE_HEX, NULL, 0x0,
1273 NULL, HFILL }
1274 },
1275
1276 { &hf_wisun_usie_explicit_frequency,
1277 { "CH0 Frequency", "wisun.usie.explicit.frequency", FT_UINT32, BASE_DEC|BASE_UNIT_STRING, &units_khz, WISUN_CH_PLAN_EXPLICIT_FREQ,
1278 NULL, HFILL }
1279 },
1280
1281 { &hf_wisun_usie_explicit_reserved,
1282 { "Reserved", "wisun.usie.explicit.reserved", FT_UINT32, BASE_DEC, NULL, WISUN_CH_PLAN_EXPLICIT_RESERVED,
1283 NULL, HFILL }
1284 },
1285
1286 { &hf_wisun_usie_explicit_spacing,
1287 { "Channel Spacing", "wisun.usie.explicit.spacing", FT_UINT32, BASE_DEC, VALS(wisun_channel_spacing_names), WISUN_CH_PLAN_EXPLICIT_SPACING,
1288 NULL, HFILL }
1289 },
1290
1291 { &hf_wisun_usie_number_channels,
1292 { "Number of Channels", "wisun.usie.num_channels", FT_UINT16, BASE_DEC, NULL, 0x0,
1293 NULL, HFILL }
1294 },
1295
1296 { &hf_wisun_usie_fixed_channel,
1297 { "Fixed Channel", "wisun.usie.fixed_channel", FT_UINT16, BASE_DEC, NULL, 0x0,
1298 NULL, HFILL }
1299 },
1300
1301 { &hf_wisun_usie_hop_count,
1302 { "Chanel Hop Count", "wisun.usie.hop_count", FT_UINT8, BASE_DEC, NULL, 0x0,
1303 NULL, HFILL }
1304 },
1305
1306 { &hf_wisun_usie_hop_list,
1307 { "Channel Hop List", "wisun.usie.hop_list", FT_UINT8, BASE_DEC, NULL, 0x0,
1308 NULL, HFILL }
1309 },
1310
1311 { &hf_wisun_usie_number_ranges,
1312 { "Number of Excluded Ranges", "wisun.usie.num_ranges", FT_UINT8, BASE_DEC, NULL, 0x0,
1313 NULL, HFILL }
1314 },
1315
1316 { &hf_wisun_usie_exclude_range,
1317 { "Excluded Channel Range", "wisun.usie.exclude.range", FT_UINT16, BASE_DEC, NULL, 0x0,
1318 NULL, HFILL }
1319 },
1320
1321 { &hf_wisun_usie_exclude_mask,
1322 { "Excluded Channel Mask", "wisun.usie.exclude.mask", FT_BYTES, BASE_NONE, NULL, 0x0,
1323 NULL, HFILL }
1324 },
1325
1326 { &hf_wisun_bsie,
1327 { "Broadcast Schedule IE", "wisun.bsie", FT_NONE, BASE_NONE, NULL, 0x0,
1328 NULL, HFILL }
1329 },
1330
1331 { &hf_wisun_bsie_bcast_interval,
1332 { "Broadcast Interval", "wisun.bsie.interval", FT_UINT32, BASE_DEC|BASE_UNIT_STRING, &units_milliseconds, 0x0,
1333 NULL, HFILL }
1334 },
1335
1336 { &hf_wisun_bsie_bcast_schedule_id,
1337 { "Broadcast Schedule ID", "wisun.bsie.schedule", FT_UINT16, BASE_DEC, NULL, 0x0,
1338 NULL, HFILL }
1339 },
1340
1341 { &hf_wisun_vpie,
1342 { "Vendor Payload IE", "wisun.vpie", FT_NONE, BASE_NONE, NULL, 0x0,
1343 NULL, HFILL }
1344 },
1345
1346 { &hf_wisun_vpie_vid,
1347 { "Vendor ID", "wisun.vpie.vid", FT_UINT32, BASE_DEC, NULL, 0x0,
1348 NULL, HFILL }
1349 },
1350
1351 { &hf_wisun_panie,
1352 { "PAN Information IE", "wisun.panie", FT_NONE, BASE_NONE, NULL, 0x0,
1353 NULL, HFILL }
1354 },
1355
1356 { &hf_wisun_panie_size,
1357 { "PAN Size", "wisun.panie.size", FT_UINT16, BASE_DEC, NULL, 0x0,
1358 NULL, HFILL }
1359 },
1360
1361 { &hf_wisun_panie_cost,
1362 { "Routing Cost", "wisun.panie.cost", FT_UINT16, BASE_DEC, NULL, 0x0,
1363 NULL, HFILL }
1364 },
1365
1366 { &hf_wisun_panie_flags,
1367 { "PAN Flags", "wisun.panie.flags", FT_UINT8, BASE_HEX, NULL, 0x0,
1368 NULL, HFILL }
1369 },
1370
1371 { &hf_wisun_panie_flag_parent_bsie,
1372 { "Use Parent BS-IE", "wisun.panie.flags.parent_bsie", FT_BOOLEAN, 8, NULL, 0x01,
1373 NULL, HFILL }
1374 },
1375
1376 { &hf_wisun_panie_flag_routing_method,
1377 { "Routing Method", "wisun.panie.flags.routing_method", FT_UINT8, BASE_HEX, VALS(wisun_routing_methods), 0x02,
1378 NULL, HFILL }
1379 },
1380
1381 { &hf_wisun_panie_flag_version,
1382 { "FAN TPS Version", "wisun.panie.flags.version", FT_UINT8, BASE_DEC, NULL, 0xe0,
1383 NULL, HFILL }
1384 },
1385
1386 { &hf_wisun_netnameie,
1387 { "Network Name IE", "wisun.netnameie", FT_NONE, BASE_NONE, NULL, 0x0,
1388 NULL, HFILL }
1389 },
1390
1391 { &hf_wisun_netnameie_name,
1392 { "Network Name", "wisun.netnameie.name", FT_STRING, STR_ASCII, NULL, 0x0,
1393 NULL, HFILL }
1394 },
1395
1396 { &hf_wisun_panverie,
1397 { "PAN Version IE", "wisun.panverie", FT_NONE, BASE_NONE, NULL, 0x0,
1398 NULL, HFILL }
1399 },
1400
1401 { &hf_wisun_panverie_version,
1402 { "PAN Version", "wisun.panverie.version", FT_UINT16, BASE_DEC, NULL, 0x0,
1403 NULL, HFILL }
1404 },
1405
1406 { &hf_wisun_gtkhashie,
1407 { "GTK Hash IE", "wisun.gtkhashie", FT_NONE, BASE_NONE, NULL, 0x0,
1408 NULL, HFILL }
1409 },
1410
1411 { &hf_wisun_gtkhashie_gtk0,
1412 { "GTK0 Hash", "wisun.gtkhashie.gtk0", FT_BYTES, BASE_NONE, NULL, 0x0,
1413 NULL, HFILL }
1414 },
1415
1416 { &hf_wisun_gtkhashie_gtk1,
1417 { "GTK1 Hash", "wisun.gtkhashie.gtk1", FT_BYTES, BASE_NONE, NULL, 0x0,
1418 NULL, HFILL }
1419 },
1420
1421 { &hf_wisun_gtkhashie_gtk2,
1422 { "GTK2 Hash", "wisun.gtkhashie.gtk2", FT_BYTES, BASE_NONE, NULL, 0x0,
1423 NULL, HFILL }
1424 },
1425
1426 { &hf_wisun_gtkhashie_gtk3,
1427 { "GTK3 Hash", "wisun.gtkhashie.gtk3", FT_BYTES, BASE_NONE, NULL, 0x0,
1428 NULL, HFILL }
1429 },
1430
1431 /* Wi-SUN FAN Security Extension */
1432 { &hf_wisun_sec_function,
1433 { "Function Code", "wisun.sec.function", FT_UINT8, BASE_HEX, VALS(wisun_sec_functions), 0x0,
1434 NULL, HFILL }
1435 },
1436
1437 { &hf_wisun_sec_error_type,
1438 { "Error Type", "wisun.sec.error", FT_UINT8, BASE_HEX, VALS(wisun_sec_sm_errors), 0x0,
1439 NULL, HFILL }
1440 },
1441
1442 { &hf_wisun_sec_error_nonce,
1443 { "Initiator Nonce", "wisun.sec.nonce", FT_BYTES, BASE_NONE, NULL, 0x0,
1444 NULL, HFILL }
1445 },
1446
1447 /* EAPOL Relay */
1448 { &hf_wisun_eapol_relay_sup,
1449 { "SUP EUI-64", "wisun.eapol_relay.sup", FT_EUI64, BASE_NONE, NULL, 0x0,
1450 NULL, HFILL }},
1451
1452 { &hf_wisun_eapol_relay_kmp_id,
1453 { "KMP ID", "wisun.eapol_relay.kmp_id", FT_UINT8, BASE_DEC, VALS(ieee802154_mpx_kmp_id_vals), 0x0,
1454 NULL, HFILL }},
1455
1456 { &hf_wisun_eapol_relay_direction,
1457 { "Direction", "wisun.eapol_relay.direction", FT_BOOLEAN, BASE_NONE, TFS(&tfs_up_down), 0x0,
1458 NULL, HFILL }},
1459
1460 /* Wi-SUN Netricity */
1461 { &hf_wisun_netricity_nftie,
1462 { "Netricity Frame Type IE", "wisun.netricity.nftie", FT_NONE, BASE_NONE, NULL, 0x0,
1463 NULL, HFILL }
1464 },
1465
1466 { &hf_wisun_netricity_nftie_type,
1467 { "Frame Type", "wisun.netricity.nftie.type", FT_UINT8, BASE_DEC, VALS(wisun_frame_type_vals), 0x0,
1468 NULL, HFILL }
1469 },
1470
1471 { &hf_wisun_netricity_lqiie,
1472 { "Link Quality Index IE", "wisun.netricity.lqiie", FT_NONE, BASE_NONE, NULL, 0x0,
1473 NULL, HFILL }
1474 },
1475
1476 { &hf_wisun_netricity_lqiie_lqi,
1477 { "Link Quality Index", "wisun.netricity.lqiie.lqi", FT_UINT8, BASE_DEC, NULL, 0x0,
1478 NULL, HFILL }
1479 },
1480
1481 /* Wi-SUN Netricity Segment Control Field and reassembly */
1482 { &hf_wisun_netricity_sc_flags,
1483 { "Segment Control", "wisun.netricity.sc.flags", FT_UINT8, BASE_HEX, NULL, 0x0,
1484 NULL, HFILL }
1485 },
1486 { &hf_wisun_netricity_sc_reserved,
1487 { "Reserved", "wisun.netricity.sc.reserved", FT_UINT8, BASE_DEC, NULL, 0xf0,
1488 NULL, HFILL }
1489 },
1490 { &hf_wisun_netricity_sc_tone_map_request,
1491 { "Tone Map Request", "wisun.netricity.sc.tone_map_request", FT_BOOLEAN, 8, NULL, 1<<3,
1492 NULL, HFILL }
1493 },
1494 { &hf_wisun_netricity_sc_contention_control,
1495 { "Contention Control", "wisun.netricity.sc.contention_control", FT_BOOLEAN, 8, TFS(&wisun_netricity_sc_contention_control_tfs), 1<<2,
1496 NULL, HFILL }
1497 },
1498 { &hf_wisun_netricity_sc_channel_access_priority,
1499 { "Channel access priority", "wisun.netricity.sc.channel_access_priority", FT_BOOLEAN, 8, TFS(&tfs_high_normal), 1<<1,
1500 NULL, HFILL }
1501 },
1502 { &hf_wisun_netricity_sc_last_segment,
1503 { "Last Segment", "wisun.netricity.sc.last_segment", FT_BOOLEAN, 8, NULL, 1<<0,
1504 NULL, HFILL }
1505 },
1506 { &hf_wisun_netricity_sc_segment_count,
1507 { "Segment Count", "wisun.netricity.sc.segment_count", FT_UINT16, BASE_DEC, NULL, 0xfc00,
1508 NULL, HFILL }
1509 },
1510 { &hf_wisun_netricity_sc_segment_length,
1511 { "Segment Length", "wisun.netricity.sc.segment_length", FT_UINT16, BASE_DEC, NULL, 0x03ff,
1512 NULL, HFILL }
1513 },
1514
1515 { &hf_wisun_netricity_scr_segments,
1516 { "Message segments", "wisun.netricity.scr.segments",
1517 FT_NONE, BASE_NONE, NULL, 0x00, NULL, HFILL }
1518 },
1519 { &hf_wisun_netricity_scr_segment,
1520 { "Message segment", "wisun.netricity.scr.segment",
1521 FT_FRAMENUM, BASE_NONE, NULL, 0x00, NULL, HFILL }
1522 },
1523 { &hf_wisun_netricity_scr_segment_overlap,
1524 { "Message segment overlap", "wisun.netricity.scr.segment.overlap",
1525 FT_BOOLEAN, 0, NULL, 0x00, NULL, HFILL }
1526 },
1527 { &hf_wisun_netricity_scr_segment_overlap_conflicts,
1528 { "Message segment overlapping with conflicting data", "wisun.netricity.scr.segment.overlap.conflicts",
1529 FT_BOOLEAN, 0, NULL, 0x00, NULL, HFILL }
1530 },
1531 { &hf_wisun_netricity_scr_segment_multiple_tails,
1532 { "Message has multiple tail segments", "wisun.netricity.scr.segment.multiple_tails",
1533 FT_BOOLEAN, 0, NULL, 0x00, NULL, HFILL }
1534 },
1535 { &hf_wisun_netricity_scr_segment_too_long_segment,
1536 { "Message segment too long", "wisun.netricity.scr.segment.too_long_segment",
1537 FT_BOOLEAN, 0, NULL, 0x00, NULL, HFILL }
1538 },
1539 { &hf_wisun_netricity_scr_segment_error,
1540 { "Message segment reassembly error", "wisun.netricity.scr.segment.error",
1541 FT_FRAMENUM, BASE_NONE, NULL, 0x00, NULL, HFILL }
1542 },
1543 { &hf_wisun_netricity_scr_segment_count,
1544 { "Message segment count", "wisun.netricity.scr.segment.count",
1545 FT_UINT32, BASE_DEC, NULL, 0x00, NULL, HFILL }
1546 },
1547 { &hf_wisun_netricity_scr_reassembled_in,
1548 { "Reassembled in", "wisun.netricity.scr.reassembled.in",
1549 FT_FRAMENUM, BASE_NONE, NULL, 0x00, NULL, HFILL }
1550 },
1551 { &hf_wisun_netricity_scr_reassembled_length,
1552 { "Reassembled length", "wisun.netricity.scr.reassembled.length",
1553 FT_UINT32, BASE_DEC, NULL, 0x00, NULL, HFILL }
1554 },
1555
1556
1557 };
1558
1559 /* Subtrees */
1560 static gint *ett[] = {
1561 &ett_wisun_unknown_ie,
1562 &ett_wisun_uttie,
1563 &ett_wisun_btie,
1564 &ett_wisun_fcie,
1565 &ett_wisun_rslie,
1566 &ett_wisun_vhie,
1567 &ett_wisun_eaie,
1568 &ett_wisun_pie,
1569 &ett_wisun_wsie_bitmap,
1570 &ett_wisun_usie,
1571 &ett_wisun_bsie,
1572 &ett_wisun_vpie,
1573 &ett_wisun_panie,
1574 &ett_wisun_panie_flags,
1575 &ett_wisun_netnameie,
1576 &ett_wisun_panverie,
1577 &ett_wisun_gtkhashie,
1578 &ett_wisun_sec,
1579 &ett_wisun_eapol_relay,
1580 &ett_wisun_netricity_nftie,
1581 &ett_wisun_netricity_lqiie,
1582 &ett_wisun_netricity_sc,
1583 &ett_wisun_netricity_sc_bitmask,
1584 &ett_wisun_netricity_scr_segment,
1585 &ett_wisun_netricity_scr_segments,
1586 };
1587
1588 static ei_register_info ei[] = {
1589 { &ei_wisun_subid_unsupported, { "wisun.subid.unsupported", PI_PROTOCOL, PI_WARN,
1590 "Unsupported Header Sub ID", EXPFILL }},
1591 { &ei_wisun_usie_channel_plan_invalid, { "wisun.usie.channel.plan.invalid", PI_PROTOCOL, PI_WARN,
1592 "Invalid Channel Plan", EXPFILL }},
1593 { &ei_wisun_wsie_unsupported, { "wisun.wsie.unsupported", PI_PROTOCOL, PI_WARN,
1594 "Unsupported Sub-IE ID", EXPFILL }},
1595 { &ei_wisun_edfe_start_not_found, { "wisun.edfe.start_not_found", PI_SEQUENCE, PI_WARN,
1596 "EDFE Transfer: start frame not found", EXPFILL }},
1597 { &ei_wisun_usie_explicit_reserved_bits_not_zero, { "wisun.usie.explicit.reserved.invalid", PI_MALFORMED, PI_ERROR,
1598 "Reserved bits not zero", EXPFILL }},
1599 };
1600
1601 expert_module_t* expert_wisun;
1602
1603 proto_wisun = proto_register_protocol("Wi-SUN Field Area Network", "Wi-SUN", "wisun");
1604 proto_wisun_sec = proto_register_protocol("Wi-SUN FAN Security Extension", "Wi-SUN WM-SEC", "wisun.sec");
1605 proto_wisun_eapol_relay = proto_register_protocol("Wi-SUN FAN EAPOL Relay", "Wi-SUN EAPOL Relay", "wisun.eapol_relay");
1606 proto_wisun_netricity_sc = proto_register_protocol("Wi-SUN Netricity Segment", "Wi-SUN Netricity Segment", "wisun.netricity.sc");
1607
1608 proto_register_field_array(proto_wisun, hf, array_length(hf));
1609 proto_register_subtree_array(ett, array_length(ett));
1610
1611 expert_wisun = expert_register_protocol(proto_wisun);
1612 expert_register_field_array(expert_wisun, ei, array_length(ei));
1613
1614 register_dissector("wisun.sec", dissect_wisun_sec, proto_wisun_sec);
1615
1616 edfe_byaddr = wmem_map_new_autoreset(wmem_epan_scope(), wmem_file_scope(), g_int64_hash, g_int64_equal);
1617
1618 wisun_eapol_relay_handle = register_dissector("wisun.eapol_relay", dissect_wisun_eapol_relay, proto_wisun_eapol_relay);
1619
1620 register_dissector("wisun.netricity.sc", dissect_wisun_netricity_sc, proto_wisun_netricity_sc);
1621 reassembly_table_register(&netricity_reassembly_table, &addresses_reassembly_table_functions);
1622 }
1623
proto_reg_handoff_wisun(void)1624 void proto_reg_handoff_wisun(void)
1625 {
1626 dissector_add_uint(IEEE802154_HEADER_IE_DTABLE, IEEE802154_HEADER_IE_WISUN, create_dissector_handle(dissect_wisun_hie, proto_wisun));
1627 dissector_add_uint(IEEE802154_PAYLOAD_IE_DTABLE, IEEE802154_PAYLOAD_IE_WISUN, create_dissector_handle(dissect_wisun_pie, proto_wisun));
1628
1629 // For EAPOL relay
1630 dissector_add_uint("udp.port", WISUN_EAPOL_RELAY_UDP_PORT, wisun_eapol_relay_handle);
1631 eapol_handle = find_dissector("eapol");
1632
1633 // For Netricity reassembly
1634 ieee802154_nofcs_handle = find_dissector("wpan_nofcs");
1635 }
1636
1637 /*
1638 * Editor modelines - https://www.wireshark.org/tools/modelines.html
1639 *
1640 * Local variables:
1641 * c-basic-offset: 4
1642 * tab-width: 8
1643 * indent-tabs-mode: nil
1644 * End:
1645 *
1646 * vi: set shiftwidth=4 tabstop=8 expandtab:
1647 * :indentSize=4:tabSize=8:noTabs=true:
1648 */
1649