forked from openwsn-berkeley/dissectors
-
Notifications
You must be signed in to change notification settings - Fork 0
/
packet-ieee802154.c
3958 lines (3483 loc) · 173 KB
/
packet-ieee802154.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* packet-ieee802154.c
*
* Auxiliary Security Header support and
* option to force TI CC24xx FCS format
* By Jean-Francois Wauthy <[email protected]>
* Copyright 2009 The University of Namur, Belgium
*
* IEEE 802.15.4 Dissectors for Wireshark
* By Owen Kirby <[email protected]>
* Copyright 2007 Exegin Technologies Limited
*
* IEEE 802.15.4 - TSCH options implemented
* By Jonathan Munoz <[email protected]>
*
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <[email protected]>
* Copyright 1998 Gerald Combs
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*------------------------------------------------------------
*
* In IEEE 802.15.4 packets, all fields are little endian. And
* Each byte is transmitted least significant bit first (reflected
* bit ordering).
*------------------------------------------------------------
*
* IEEE 802.15.4 Packets have the following format:
* | FCF |Seq No| Addressing | Data | FCS |
* |2 bytes|1 byte|0 to 20 bytes|Length-(Overhead) bytes|2 Bytes|
*------------------------------------------------------------
*
* CRC16 is calculated using the x^16 + x^12 + x^5 + 1 polynomial
* as specified by ITU-T, and is calculated over the IEEE 802.15.4
* packet (excluding the FCS) as transmitted over the air. Note,
* that because the least significan bits are transmitted first, this
* will require reversing the bit-order in each byte. Also, unlike
* most CRC algorithms, IEEE 802.15.4 uses an initial and final value
* of 0x0000, instead of 0xffff (which is used by the CCITT).
*------------------------------------------------------------
*
* This dissector supports both link-layer IEEE 802.15.4 captures
* and IEEE 802.15.4 packets encapsulated within other layers.
* Additionally, support has been provided for various formats
* of the frame check sequence:
* - IEEE 802.15.4 compliant FCS.
* - ChipCon/Texas Instruments CC24xx style FCS.
*------------------------------------------------------------
*/
/* Include files */
#include "config.h"
#include <epan/packet.h>
#include <epan/decode_as.h>
#include <epan/exceptions.h>
#include <epan/crc16-tvb.h>
#include <epan/expert.h>
#include <epan/addr_resolv.h>
#include <epan/address_types.h>
#include <epan/prefs.h>
#include <epan/uat.h>
#include <epan/strutil.h>
#include <epan/to_str-int.h>
#include <epan/show_exception.h>
#include <wsutil/pint.h>
/* Use libgcrypt for cipher libraries. */
#ifdef HAVE_LIBGCRYPT
#include <wsutil/wsgcrypt.h>
#endif /* HAVE_LIBGCRYPT */
#include "packet-ieee802154.h"
#include "packet-sll.h"
void proto_register_ieee802154(void);
void proto_reg_handoff_ieee802154(void);
/* Dissection Options for dissect_ieee802154_common */
#define DISSECT_IEEE802154_OPTION_CC24xx 0x00000001 /* FCS field contains a TI CC24xx style FCS. */
#define DISSECT_IEEE802154_OPTION_LINUX 0x00000002 /* Addressing fields are padded DLT_IEEE802_15_4_LINUX, not implemented. */
/* ethertype for 802.15.4 tag - encapsulating an Ethernet packet */
static unsigned int ieee802154_ethertype = 0x809A;
/* boolean value set if the FCS field is using the TI CC24xx format */
static gboolean ieee802154_cc24xx = FALSE;
/* boolean value set if the FCS must be ok before payload is dissected */
static gboolean ieee802154_fcs_ok = TRUE;
/* User string with the decryption key. */
static const gchar *ieee802154_key_str = NULL;
static gboolean ieee802154_key_valid;
static guint8 ieee802154_key[IEEE802154_CIPHER_SIZE];
static const char *ieee802154_user = "User";
/*-------------------------------------
* Address Hash Tables
*-------------------------------------
*/
static ieee802154_map_tab_t ieee802154_map = { NULL, NULL };
/*-------------------------------------
* Static Address Mapping UAT
*-------------------------------------
*/
/* UAT entry structure. */
typedef struct {
guchar *eui64;
guint eui64_len;
guint addr16;
guint pan;
} static_addr_t;
/* UAT variables */
static uat_t *static_addr_uat = NULL;
static static_addr_t *static_addrs = NULL;
static guint num_static_addrs = 0;
/* Sanity-checks a UAT record. */
static gboolean
addr_uat_update_cb(void *r, char **err)
{
static_addr_t *map = (static_addr_t *)r;
/* Ensure a valid short address */
if (map->addr16 >= IEEE802154_NO_ADDR16) {
*err = g_strdup("Invalid short address");
return FALSE;
}
/* Ensure a valid PAN identifier. */
if (map->pan >= IEEE802154_BCAST_PAN) {
*err = g_strdup("Invalid PAN identifier");
return FALSE;
}
/* Ensure a valid EUI-64 length */
if (map->eui64_len != sizeof(guint64)) {
*err = g_strdup("Invalid EUI-64 length");
return FALSE;
}
return TRUE;
} /* ieee802154_addr_uat_update_cb */
/* Field callbacks. */
UAT_HEX_CB_DEF(addr_uat, addr16, static_addr_t)
UAT_HEX_CB_DEF(addr_uat, pan, static_addr_t)
UAT_BUFFER_CB_DEF(addr_uat, eui64, static_addr_t, eui64, eui64_len)
/*-------------------------------------
* Dissector Function Prototypes
*-------------------------------------
*/
/* Dissection Routines. */
static void dissect_ieee802154_nonask_phy (tvbuff_t *, packet_info *, proto_tree *);
static void dissect_ieee802154 (tvbuff_t *, packet_info *, proto_tree *);
static void dissect_ieee802154_nofcs (tvbuff_t *, packet_info *, proto_tree *);
static void dissect_ieee802154_cc24xx (tvbuff_t *, packet_info *, proto_tree *);
/*static void dissect_ieee802154_linux (tvbuff_t *, packet_info *, proto_tree *); TODO: Implement Me. */
static void dissect_ieee802154_common (tvbuff_t *, packet_info *, proto_tree *, guint);
/* Sub-dissector helpers. */
static void dissect_ieee802154_fcf (tvbuff_t *, packet_info *, proto_tree *, ieee802154_packet *, guint *);
static void dissect_ieee802154_superframe (tvbuff_t *, packet_info *, proto_tree *, guint *);
static void dissect_ieee802154_gtsinfo (tvbuff_t *, packet_info *, proto_tree *, guint *);
static void dissect_ieee802154_pendaddr (tvbuff_t *, packet_info *, proto_tree *, guint *);
static void dissect_ieee802154_command (tvbuff_t *, packet_info *, proto_tree *, ieee802154_packet *);
static void dissect_ieee802154_assoc_req (tvbuff_t *, packet_info *, proto_tree *, ieee802154_packet *);
static void dissect_ieee802154_assoc_rsp (tvbuff_t *, packet_info *, proto_tree *, ieee802154_packet *);
static void dissect_ieee802154_disassoc (tvbuff_t *, packet_info *, proto_tree *, ieee802154_packet *);
static void dissect_ieee802154_realign (tvbuff_t *, packet_info *, proto_tree *, ieee802154_packet *);
static void dissect_ieee802154_gtsreq (tvbuff_t *, packet_info *, proto_tree *, ieee802154_packet *);
/* Dissector for the Infomation Elements */
static void dissect_ieee802154_h_inf_elem (tvbuff_t *, packet_info *, proto_tree *, ieee802154_packet *, guint *);
static void dissect_ieee802154_p_inf_elem (tvbuff_t *, packet_info *, proto_tree *, ieee802154_packet *, guint *);
static void dissect_ieee802154_p_inf_elem_mlme (tvbuff_t *, packet_info *, proto_tree *, ieee802154_packet *, guint *);
//static void dissect_ieee802154_p_inf_elem_mlme_content (tvbuff_t *, packet_info *, proto_tree *, ieee802154_packet *, guint *);
static void dissect_802154_h_ie_time_correction (tvbuff_t *, proto_tree *, ieee802154_packet *, guint *);
static void dissect_802154_p_ie_sh_mlme_tsch_sync (tvbuff_t *, proto_tree *, ieee802154_packet *, guint *);
static void dissect_802154_p_ie_sh_mlme_tsch_slotframe_link (tvbuff_t *, proto_tree *, guint *);
//static void dissect_802154_p_ie_sh_mlme_slotfr_link (tvbuff_t *, proto_tree *, ieee802154_packet *, guint *);
static void dissect_802154_p_ie_lg_mlme_channel_hopping (tvbuff_t *, packet_info *, proto_tree *, ieee802154_packet *, guint *);
/* Get the size of the MAC HEADER */
int size_header (ieee802154_packet *packet);
/* Decryption helpers. */
typedef enum {
DECRYPT_PACKET_SUCCEEDED,
DECRYPT_NOT_ENCRYPTED,
DECRYPT_VERSION_UNSUPPORTED,
DECRYPT_PACKET_TOO_SMALL,
DECRYPT_PACKET_NO_EXT_SRC_ADDR,
DECRYPT_PACKET_NO_KEY,
DECRYPT_PACKET_DECRYPT_FAILED,
DECRYPT_PACKET_MIC_CHECK_FAILED
} ws_decrypt_status;
static tvbuff_t *dissect_ieee802154_decrypt(tvbuff_t *, guint, packet_info *, ieee802154_packet *,
ws_decrypt_status *);
static void ccm_init_block (gchar *, gboolean, gint, guint64, ieee802154_packet *, gint);
static gboolean ccm_ctr_encrypt (const gchar *, const gchar *, gchar *, gchar *, gint);
static gboolean ccm_cbc_mac (const gchar *, const gchar *, const gchar *, gint, const gchar *, gint, gchar *);
/* Initialize Protocol and Registered fields */
static int proto_ieee802154_nonask_phy = -1;
static int hf_ieee802154_nonask_phy_preamble = -1;
static int hf_ieee802154_nonask_phy_sfd = -1;
static int hf_ieee802154_nonask_phy_length = -1;
static int hf_ieee802154_nonask_phr = -1;
static int proto_ieee802154 = -1;
static int hf_ieee802154_frame_length = -1;
static int hf_ieee802154_fcf = -1;
static int hf_ieee802154_frame_type = -1;
static int hf_ieee802154_security = -1;
static int hf_ieee802154_pending = -1;
static int hf_ieee802154_ack_request = -1;
static int hf_ieee802154_intra_pan = -1;
static int hf_ieee802154_seqno = -1;
static int hf_ieee802154_seqnr_supression = -1;
static int hf_ieee802154_ielist_present = -1;
static int hf_ieee802154_src_addr_mode = -1;
static int hf_ieee802154_dst_addr_mode = -1;
static int hf_ieee802154_version = -1;
static int hf_ieee802154_dst_panID = -1;
static int hf_ieee802154_dst16 = -1;
static int hf_ieee802154_dst64 = -1;
static int hf_ieee802154_src_panID = -1;
static int hf_ieee802154_src16 = -1;
static int hf_ieee802154_src64 = -1;
static int hf_ieee802154_src64_origin = -1;
static int hf_ieee802154_fcs = -1;
static int hf_ieee802154_rssi = -1;
static int hf_ieee802154_fcs_ok = -1;
static int hf_ieee802154_correlation = -1;
/* Registered fields for Command Packets */
static int hf_ieee802154_cmd_id = -1;
static int hf_ieee802154_cinfo_alt_coord = -1;
static int hf_ieee802154_cinfo_device_type = -1;
static int hf_ieee802154_cinfo_power_src = -1;
static int hf_ieee802154_cinfo_idle_rx = -1;
static int hf_ieee802154_cinfo_sec_capable = -1;
static int hf_ieee802154_cinfo_alloc_addr = -1;
static int hf_ieee802154_assoc_addr = -1;
static int hf_ieee802154_assoc_status = -1;
static int hf_ieee802154_disassoc_reason = -1;
static int hf_ieee802154_realign_pan = -1;
static int hf_ieee802154_realign_caddr = -1;
static int hf_ieee802154_realign_channel = -1;
static int hf_ieee802154_realign_addr = -1;
static int hf_ieee802154_realign_channel_page = -1;
static int hf_ieee802154_gtsreq_len = -1;
static int hf_ieee802154_gtsreq_dir = -1;
static int hf_ieee802154_gtsreq_type = -1;
/* Registered fields for Beacon Packets */
static int hf_ieee802154_beacon_order = -1;
static int hf_ieee802154_superframe_order = -1;
static int hf_ieee802154_cap = -1;
static int hf_ieee802154_superframe_battery_ext = -1;
static int hf_ieee802154_superframe_coord = -1;
static int hf_ieee802154_assoc_permit = -1;
static int hf_ieee802154_gts_count = -1;
static int hf_ieee802154_gts_permit = -1;
static int hf_ieee802154_gts_direction = -1;
static int hf_ieee802154_gts_address = -1;
static int hf_ieee802154_pending16 = -1;
static int hf_ieee802154_pending64 = -1;
/* Registered fields for Auxiliary Security Header */
static int hf_ieee802154_security_control_field = -1;
static int hf_ieee802154_security_level = -1;
static int hf_ieee802154_key_id_mode = -1;
static int hf_ieee802154_aux_sec_reserved = -1;
static int hf_ieee802154_aux_sec_frame_counter = -1;
static int hf_ieee802154_aux_sec_key_source = -1;
static int hf_ieee802154_aux_sec_key_index = -1;
/* 802.15.4-2003 security */
static int hf_ieee802154_sec_frame_counter = -1;
static int hf_ieee802154_sec_key_sequence_counter = -1;
/* Initialize Subtree Pointers */
static gint ett_ieee802154_nonask_phy = -1;
static gint ett_ieee802154_nonask_phy_phr = -1;
static gint ett_ieee802154 = -1;
static gint ett_ieee802154_fcf = -1;
static gint ett_ieee802154_auxiliary_security = -1;
static gint ett_ieee802154_aux_sec_control = -1;
static gint ett_ieee802154_aux_sec_key_id = -1;
static gint ett_ieee802154_fcs = -1;
static gint ett_ieee802154_cmd = -1;
static gint ett_ieee802154_superframe = -1;
static gint ett_ieee802154_gts = -1;
static gint ett_ieee802154_gts_direction = -1;
static gint ett_ieee802154_gts_descriptors = -1;
static gint ett_ieee802154_pendaddr = -1;
static gint ett_ieee802154_h_ie = -1;
static gint ett_ieee802154_p_ie = -1;
static gint ett_ieee802154_mlme_sh_p_ie = -1;
static gint ett_ieee802154_mlme_lg_p_ie = -1;
static gint ett_ieee802154_mlme_payload = -1;
static gint ett_ieee802154_mlme_payload_data = -1;
static gint ett_ieee802154_h_ie_payload = -1;
static expert_field ei_ieee802154_invalid_addressing = EI_INIT;
static expert_field ei_ieee802154_fcs = EI_INIT;
static expert_field ei_ieee802154_decrypt_error = EI_INIT;
static expert_field ei_ieee802154_dst = EI_INIT;
static expert_field ei_ieee802154_src = EI_INIT;
static int ieee802_15_4_short_address_type = -1;
/* Header Information Elements header's values */
static int hf_ieee802154_h_ie_content_lenght = -1;
static int hf_ieee802154_h_ie_id = -1;
static int hf_ieee802154_h_ie_type = -1;
/* Payload Information Elements header's values */
static int hf_ieee802154_p_ie_content_lenght = -1;
static int hf_ieee802154_p_ie_id = -1;
static int hf_ieee802154_p_ie_type = -1;
/* (Payload) MLME Information Elements header's values */
static int hf_ieee802154_p_ie_mlme_sh_lenght = -1;
static int hf_ieee802154_p_ie_mlme_sh_id = -1;
static int hf_ieee802154_p_ie_mlme_type = -1;
static int hf_ieee802154_p_ie_mlme_lg_lenght = -1;
static int hf_ieee802154_p_ie_mlme_lg_id = -1;
/* Header Information Elements payload */
static int hf_ieee802154_h_ie_time_correction1 = -1;
static int hf_ieee802154_h_ie_time_correction2 = -1;
static int hf_ieee802154_h_ie_time_correction3 = -1;
static int hf_ieee802154_h_ie_time_correction4 = -1;
/* Payload MLME Information Elements */
static int hf_ieee802154_p_ie_mlme_sh_tsch_asn_lower = -1;
static int hf_ieee802154_p_ie_mlme_sh_tsch_asn_higher = -1;
static int hf_ieee802154_p_ie_mlme_sh_tsch_join_p = -1;
static int hf_ieee802154_p_ie_mlme_sh_tsch_slotf_link_nb_slotf = -1;
static int hf_ieee802154_p_ie_mlme_lg_hopping_sequence_id = -1;
static int hf_ieee802154_p_ie_mlme_sh_tsch_slotf_link_slotf_handle = -1;
static int hf_ieee802154_p_ie_mlme_sh_tsch_slotf_link_slotf_size = -1;
static int hf_ieee802154_p_ie_mlme_sh_tsch_slotf_link_nb_links = -1;
static int hf_ieee802154_p_ie_mlme_sh_tsch_slotf_link_timeslot = -1;
static int hf_ieee802154_p_ie_mlme_sh_tsch_slotf_link_channel_offset = -1;
static int hf_ieee802154_p_ie_mlme_sh_tsch_slotf_link_options = -1;
/*
* Dissector handles
* - beacon dissection is always heuristic.
* - the PANID table is for stateful dissectors only (ie: Decode-As)
* - otherwise, data dissectors fall back to the heuristic dissectors.
*/
static dissector_handle_t data_handle;
static dissector_table_t panid_dissector_table;
static heur_dissector_list_t ieee802154_beacon_subdissector_list;
static heur_dissector_list_t ieee802154_heur_subdissector_list;
/* Name Strings */
static const value_string ieee802154_frame_types[] = {
{ IEEE802154_FCF_BEACON, "Beacon" },
{ IEEE802154_FCF_DATA, "Data" },
{ IEEE802154_FCF_ACK, "Ack" },
{ IEEE802154_FCF_CMD, "Command" },
{ IEEE802154_FCF_RESERVED, "Reserved" }, /* according to 2015 spec. */
{ IEEE802154_FCF_MULTIPURPOSE, "Multipurpose" }, /* according to 2015 spec. */
{ IEEE802154_FCF_FRAGMENT_FRAG, "Fragment or Frak" }, /* according to 2015 spec. */
{ IEEE802154_FCF_EXTENDED, "Extended" }, /* according to 2015 spec. */
{ 0, NULL }
};
static const value_string ieee802154_addr_modes[] = {
{ IEEE802154_FCF_ADDR_NONE, "None" },
{ IEEE802154_FCF_ADDR_SHORT,"Short/16-bit" },
{ IEEE802154_FCF_ADDR_EXT, "Long/64-bit" },
{ 0, NULL }
};
static const value_string ieee802154_cmd_names[] = {
{ IEEE802154_CMD_ASRQ, "Association Request" },
{ IEEE802154_CMD_ASRSP, "Association Response" },
{ IEEE802154_CMD_DISAS, "Disassociation Notification" },
{ IEEE802154_CMD_DATA_RQ, "Data Request" },
{ IEEE802154_CMD_PANID_ERR, "PAN ID Conflict" },
{ IEEE802154_CMD_ORPH_NOTIF,"Orphan Notification" },
{ IEEE802154_CMD_BCN_RQ, "Beacon Request" },
{ IEEE802154_CMD_COORD_REAL,"Coordinator Realignment" },
{ IEEE802154_CMD_GTS_REQ, "GTS Request" },
{ 0, NULL }
};
static const value_string ieee802154_sec_level_names[] = {
{ SECURITY_LEVEL_NONE, "No Security" },
{ SECURITY_LEVEL_MIC_32, "32-bit Message Integrity Code" },
{ SECURITY_LEVEL_MIC_64, "64-bit Message Integrity Code" },
{ SECURITY_LEVEL_MIC_128, "128-bit Message Integrity Code" },
{ SECURITY_LEVEL_ENC, "Encryption" },
{ SECURITY_LEVEL_ENC_MIC_32, "Encryption with 32-bit Message Integrity Code" },
{ SECURITY_LEVEL_ENC_MIC_64, "Encryption with 64-bit Message Integrity Code" },
{ SECURITY_LEVEL_ENC_MIC_128, "Encryption with 128-bit Message Integrity Code" },
{ 0, NULL }
};
static const value_string ieee802154_key_id_mode_names[] = {
{ KEY_ID_MODE_IMPLICIT, "Implicit Key" },
{ KEY_ID_MODE_KEY_INDEX, "Indexed Key using the Default Key Source" },
{ KEY_ID_MODE_KEY_EXPLICIT_4, "Explicit Key with 4-octet Key Source" },
{ KEY_ID_MODE_KEY_EXPLICIT_8, "Explicit Key with 8-octet Key Source" },
{ 0, NULL }
};
/* according to 2015 spec. */
static const value_string ieee802154_h_information_elements[] = {
{ IEEE802154_H_IE_DA_IE_VENDOR_SPECIFIC_HEADER, "DA IE Vendor Specific Header IE" },
{ IEEE802154_H_IE_DA, "DA IE" },
{ IEEE802154_H_IE_CSL, "CSL IE" },
{ IEEE802154_H_IE_RIT, "RIT IE" },
{ IEEE802154_H_IE_DSME_PAN_DESC, "DSME PAN descriptor IE" },
{ IEEE802154_H_IE_RDV_TIME, "Rendezvous Time IE" },
{ IEEE802154_H_IE_TIME_CORRECTION, "Time Correction IE" },
{ IEEE802154_H_IE_EXT_DSME_PAN_DESC, "Extended DSME PAN descriptor IE" },
{ IEEE802154_H_IE_FSCD, "Fragment Sequence Context Description (FSCD) IE" },
{ IEEE802154_H_IE_SIMPL_SF_SPEC, "Simplified Superframe Specification IE" },
{ IEEE802154_H_IE_SIMPL_GTS, "Simplified GTS Specification IE" },
{ IEEE802154_H_IE_LECIM_CAPAB, "LECIM Capabilities IE" },
{ IEEE802154_H_IE_TRLE_DESC, "TRLE Descriptor" },
{ IEEE802154_H_IE_RCC_CAPAB, "RCC Capabilities IE" },
{ IEEE802154_H_IE_RCCN_DESC, "RCCN Descriptor IE"},
{ IEEE802154_H_IE_GLOBAL_TIME, "Global Time IE" },
{ IEEE802154_H_IE_HDR_TERM_1, "Header Termination 1 IE" },
{ IEEE802154_H_IE_HDR_TERM_2, "Header Termination 2 IE" },
{ 0, NULL }
};
static const value_string ieee802154_h_information_elements_defined[] = {
// { IEEE802154_H_IE_DA_IE_VENDOR_SPECIFIC_HEADER, "DA IE Vendor Specific Header IE" },
// { IEEE802154_H_IE_DA, "DA IE" },
// { IEEE802154_H_IE_CSL, "CSL IE" },
// { IEEE802154_H_IE_RIT, "RIT IE" },
// { IEEE802154_H_IE_DSME_PAN_DESC, "DSME PAN descriptor IE" },
// { IEEE802154_H_IE_RDV_TIME, "Rendezvous Time IE" },
{ IEEE802154_H_IE_TIME_CORRECTION, "Time Correction IE" },
// { IEEE802154_H_IE_EXT_DSME_PAN_DESC, "Extended DSME PAN descriptor IE" },
// { IEEE802154_H_IE_FSCD, "Fragment Sequence Context Description (FSCD) IE" },
// { IEEE802154_H_IE_SIMPL_SF_SPEC, "Simplified Superframe Specification IE" },
// { IEEE802154_H_IE_SIMPL_GTS, "Simplified GTS Specification IE" },
// { IEEE802154_H_IE_LECIM_CAPAB, "LECIM Capabilities IE" },
// { IEEE802154_H_IE_TRLE_DESC, "TRLE Descriptor" },
// { IEEE802154_H_IE_RCC_CAPAB, "RCC Capabilities IE" },
// { IEEE802154_H_IE_RCCN_DESC, "RCCN Descriptor IE"},
// { IEEE802154_H_IE_GLOBAL_TIME, "Global Time IE" },
// { IEEE802154_H_IE_HDR_TERM_1, "Header Termination 1 IE" },
// { IEEE802154_H_IE_HDR_TERM_2, "Header Termination 2 IE" },
{ 0, NULL }
};
static const value_string ieee802154_h_mlme_sub_short_information_elements[] = {
{ IEEE802154_P_IE_TSCH_SYNC_SH, "TSCH Synchronization IE" },
{ IEEE802154_P_IE_TSCH_SLOTFR_LINK_SH, "TSCH Slotframe and Link IE" },
{ IEEE802154_P_IE_TSCH_TIMESLOT_SH, "TSCH Timeslot IE" },
{ IEEE802154_P_IE_HOPPING_TIMING_SH, "Hopping timing IE" },
{ IEEE802154_P_IE_ENHACED_BEACON_FILTER_SH, "Enhaced Beacon Filter IE" },
{ IEEE802154_P_IE_MAC_METRICS_SH, "MAC Metrics" },
{ IEEE802154_P_IE_ALL_MAC_METRICS_SH, "All MAC Metrics IE" },
{ IEEE802154_P_IE_COEXISTENCE_SPEC_SH, "Coexistence Specification IE" },
{ IEEE802154_P_IE_SUN_DEVICE_CAPABILITIES_SH, "SUN Device Capabilities IE" },
{ IEEE802154_P_IE_SUN_FSK_GEN_PHY_SH, "SUN FSK Generic PHY IE" },
{ IEEE802154_P_IE_MODE_SWITCH_PARAMETER_SH, "Mode Switch Parameter IE" },
{ IEEE802154_P_IE_PHY_PARAMETER_CHANGE_SH, "PHY Parameter Change IE" },
{ IEEE802154_P_IE_O_QPSK_PHY_MODE_SH, "O-QPSY PHY Mode IE" },
{ IEEE802154_P_IE_PCA_ALLOCATION_SH, "PCA Allocation IE" },
{ IEEE802154_P_IE_DSSS_OPER_MODE_SH, "DSSS Operating Mode IE"},
{ IEEE802154_P_IE_FSK_OPER_MODE_SH, "FSK Operating Mode IE" },
{ IEEE802154_P_IE_TVWS_PHY_OPE_MODE_SH, "TVWS PHY Operating Mode Description IE" },
{ IEEE802154_P_IE_TVWS_DEVICE_CAPAB_SH, "TVWS Device Capabilities IE" },
{ IEEE802154_P_IE_TVWS_DEVICE_CATEG_SH, "TVWS Device Category IE" },
{ IEEE802154_P_IE_TVWS_DEVICE_IDENTIF_SH, "TVWS Device Identification IE" },
{ IEEE802154_P_IE_TVWS_DEVICE_LOCATION_SH, "TVWS Device Location IE" },
{ IEEE802154_P_IE_TVWS_CH_INFOR_QUERY_SH, "TVWS Channel Information Query IE" },
{ IEEE802154_P_IE_TVWS_CH_INFOR_SOURCE_SH, "TVWS Channel Information Source IE" },
{ IEEE802154_P_IE_CTM_SH, "CTM IE" },
{ IEEE802154_P_IE_TIMESTAMP_SH, "Timestamp IE" },
{ IEEE802154_P_IE_TIMESTAMP_DIFF_SH, "Timestamp Difference IE"},
{ IEEE802154_P_IE_TMCP_SPECIFICATION_SH, "TMCTP Specification IE" },
{ IEEE802154_P_IE_RCC_PHY_OPER_MODE_SH, "RCC PHY Operating Mode IE" },
{ 0, NULL }
};
static const value_string ieee802154_h_mlme_sub_short_information_elements_defined[] = {
{ IEEE802154_P_IE_TSCH_SYNC_SH, "TSCH Synchronization IE" },
{ IEEE802154_P_IE_TSCH_SLOTFR_LINK_SH, "TSCH Slotframe and Link IE" },
//{ IEEE802154_P_IE_TSCH_TIMESLOT_SH, "TSCH Timeslot IE" },
//{ IEEE802154_P_IE_HOPPING_TIMING_SH, "Hopping timing IE" },
//{ IEEE802154_P_IE_ENHACED_BEACON_FILTER_SH, "Enhaced Beacon Filter IE" },
//{ IEEE802154_P_IE_MAC_METRICS_SH, "MAC Metrics" },
//{ IEEE802154_P_IE_ALL_MAC_METRICS_SH, "All MAC Metrics IE" },
//{ IEEE802154_P_IE_COEXISTENCE_SPEC_SH, "Coexistence Specification IE" },
//{ IEEE802154_P_IE_SUN_DEVICE_CAPABILITIES_SH, "SUN Device Capabilities IE" },
//{ IEEE802154_P_IE_SUN_FSK_GEN_PHY_SH, "SUN FSK Generic PHY IE" },
//{ IEEE802154_P_IE_MODE_SWITCH_PARAMETER_SH, "Mode Switch Parameter IE" },
//{ IEEE802154_P_IE_PHY_PARAMETER_CHANGE_SH, "PHY Parameter Change IE" },
//{ IEEE802154_P_IE_O_QPSK_PHY_MODE_SH, "O-QPSY PHY Mode IE" },
//{ IEEE802154_P_IE_PCA_ALLOCATION_SH, "PCA Allocation IE" },
//{ IEEE802154_P_IE_DSSS_OPER_MODE_SH, "DSSS Operating Mode IE"},
//{ IEEE802154_P_IE_FSK_OPER_MODE_SH, "FSK Operating Mode IE" },
//{ IEEE802154_P_IE_TVWS_PHY_OPE_MODE_SH, "TVWS PHY Operating Mode Description IE" },
//{ IEEE802154_P_IE_TVWS_DEVICE_CAPAB_SH, "TVWS Device Capabilities IE" },
//{ IEEE802154_P_IE_TVWS_DEVICE_CATEG_SH, "TVWS Device Category IE" },
//{ IEEE802154_P_IE_TVWS_DEVICE_IDENTIF_SH, "TVWS Device Identification IE" },
//{ IEEE802154_P_IE_TVWS_DEVICE_LOCATION_SH, "TVWS Device Location IE" },
//{ IEEE802154_P_IE_TVWS_CH_INFOR_QUERY_SH, "TVWS Channel Information Query IE" },
//{ IEEE802154_P_IE_TVWS_CH_INFOR_SOURCE_SH, "TVWS Channel Information Source IE" },
//{ IEEE802154_P_IE_CTM_SH, "CTM IE" },
//{ IEEE802154_P_IE_TIMESTAMP_SH, "Timestamp IE" },
//{ IEEE802154_P_IE_TIMESTAMP_DIFF_SH, "Timestamp Difference IE"},
//{ IEEE802154_P_IE_TMCP_SPECIFICATION_SH, "TMCTP Specification IE" },
//{ IEEE802154_P_IE_RCC_PHY_OPER_MODE_SH, "RCC PHY Operating Mode IE" },
{ 0, NULL }
};
static const value_string ieee802154_h_mlme_sub_long_information_elements[] = {
{ IEEE802154_P_IE_VENDOR_SPECIFIC_LG, "Vendor Specific IE " },
{ IEEE802154_P_IE_CHANNEL_HOPPING_LG, "Channel Hopping IE" },
{ 0, NULL }
};
static const value_string ieee802154_h_mlme_sub_long_information_elements_defined[] = {
//{ IEEE802154_P_IE_VENDOR_SPECIFIC_LG, "Vendor Specific IE " },
{ IEEE802154_P_IE_CHANNEL_HOPPING_LG, "Channel Hopping IE" },
{ 0, NULL }
};
static const value_string ieee802154_p_information_elements[] = {
{ IEEE802154_P_IE_ESDU, "Encapsulated Service Data Unit" },
{ IEEE802154_P_IE_MLME, "MLME IE" },
{ IEEE802154_P_IE_VENDOR_SPECIFIC, "Vendor Specific IE" },
{ IEEE802154_P_IE_PAYLOAD_TERM, "Payload Termination IE" },
{ 0, NULL }
};
/* ------------------------------------------------------------------------------------- */
static const true_false_string ieee802154_gts_direction_tfs = {
"Receive Only",
"Transmit Only"
};
/* The 802.15.4-2003 security suites for the security preferences (only AES-CCM suites are supported). */
/* NOTE: The equivalent 2006 security level identifer enumerations are used to simplify 2003 & 2006 integration! */
static const enum_val_t ieee802154_2003_sec_suite_enums[] = {
{ "AES-CCM-128", "AES-128 Encryption, 128-bit Integrity Protection", SECURITY_LEVEL_ENC_MIC_128 },
{ "AES-CCM-64", "AES-128 Encryption, 64-bit Integrity Protection", SECURITY_LEVEL_ENC_MIC_64 },
{ "AES-CCM-32", "AES-128 Encryption, 32-bit Integrity Protection", SECURITY_LEVEL_ENC_MIC_32 },
{ NULL, NULL, 0 }
};
/* Preferences for 2003 security */
static gint ieee802154_sec_suite = SECURITY_LEVEL_ENC_MIC_64;
static gboolean ieee802154_extend_auth = TRUE;
/* Macro to check addressing, and throw a warning flag if incorrect. */
#define IEEE802154_CMD_ADDR_CHECK(_pinfo_, _item_, _cmdid_, _x_) \
if (!(_x_)) \
expert_add_info_format(_pinfo_, _item_, &ei_ieee802154_invalid_addressing, \
"Invalid Addressing for %s", \
val_to_str_const(_cmdid_, ieee802154_cmd_names, "Unknown Command"))
/* CRC definitions. IEEE 802.15.4 CRCs vary from CCITT by using an initial value of
* 0x0000, and no XOR out. IEEE802154_CRC_XOR is defined as 0xFFFF in order to un-XOR
* the output from the CCITT CRC routines in Wireshark.
*/
#define IEEE802154_CRC_SEED 0x0000
#define IEEE802154_CRC_XOROUT 0xFFFF
#define ieee802154_crc_tvb(tvb, offset) (crc16_ccitt_tvb_seed(tvb, offset, IEEE802154_CRC_SEED) ^ IEEE802154_CRC_XOROUT)
static int ieee802_15_4_short_address_to_str(const address* addr, gchar *buf, int buf_len)
{
guint16 ieee_802_15_4_short_addr = pletoh16(addr->data);
if (ieee_802_15_4_short_addr == 0xffff)
{
g_strlcpy(buf, "Broadcast", buf_len);
return 10;
}
*buf++ = '0';
*buf++ = 'x';
buf = word_to_hex(buf, ieee_802_15_4_short_addr);
*buf = '\0'; /* NULL terminate */
return 7;
}
static int ieee802_15_4_short_address_str_len(const address* addr _U_)
{
return 11;
}
static int ieee802_15_4_short_address_len(void)
{
return 2;
}
/*FUNCTION:------------------------------------------------------
* NAME
* size_header
* DESCRIPTION
* It provides the size of the IEEE802154 header.
*
* PARAMETERS
* ieee802154_packet *packet - IEEE 802.15.4 packet information.
*
* RETURNS
* int
*---------------------------------------------------------------
*/
int size_header (ieee802154_packet *packet) {
guint8 mac_header_size = 0;
/*FCF size*/
switch (packet->frame_type){
case IEEE802154_FCF_MULTIPURPOSE:
break;
case IEEE802154_FCF_FRAGMENT_FRAG:
break;
case IEEE802154_FCF_EXTENDED:
break;
default:
mac_header_size += 2;
break;
}
/* Destination Addressing Mode field */
switch (packet->dst_addr_mode) {
/* Short address*/
case IEEE802154_FCF_ADDR_SHORT:
mac_header_size += 2;
/* Destination PAN exists */
mac_header_size += 2;
break;
/* Long address*/
case IEEE802154_FCF_ADDR_EXT:
mac_header_size += 8;
/* Destination PAN exists */
mac_header_size += 2;
break;
default:
break;
}
/* Source Addressing Mode field */
switch (packet->src_addr_mode) {
case IEEE802154_FCF_ADDR_SHORT:
mac_header_size += 2;
/* Destination PAN exists */
/* In order to match the technical discussions at the 6TiSCH plugtest telco on 2 July 2015:
THERE WILL NOT BE ANY PAN ID SOURCE, NO MATTER WHAT WITH THE BIT --PAN ID compression-- (packet->intra_pan)
that's why the following 3 lines are commented
*/
//if (!packet->intra_pan){
// mac_header_size += 2;
//}
break;
case IEEE802154_FCF_ADDR_EXT:
mac_header_size += 8;
/* Destination PAN exists */
/* In order to match the technical discussions at the 6TiSCH plugtest telco on 2 July 2015:
THERE WILL NOT BE ANY PAN ID SOURCE, NO MATTER WHAT WITH THE BIT --PAN ID compression-- (packet->intra_pan)
that's why the following 3 lines are commented
*/
//if (!packet->intra_pan){
// mac_header_size += 2;
//}
break;
default:
break;
}
/* bit Sequence Number Suppression*/
if (!packet->seqnr_suppresion){
mac_header_size += 1;
}
return mac_header_size;
}
/*FUNCTION:------------------------------------------------------
* NAME
* dissect_ieee802154_h_inf_elem
* DESCRIPTION
* Dissector helper, parses and displays the header information element(s).
*
* PARAMETERS
* ieee802154_packet *packet - Packet info structure.
* tvbuff_t *tvb - pointer to buffer containing raw packet.
* packet_info *pinfo - pointer to packet information fields
* proto_tree *tree - pointer to data tree wireshark uses to display packet.
* ieee802154_packet *packet - IEEE 802.15.4 packet information.
* guint offset - offset into the tvb to find the FCF.
* RETURNS
* void
*---------------------------------------------------------------
*/
static void
dissect_ieee802154_h_inf_elem(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, ieee802154_packet *packet, guint *offset)
{
/* IEEE802154_FCS_LEN */
gboolean condition;
proto_tree *h_inf_elem_tree = NULL;
condition = TRUE;
packet->keep_dissecting = tvb_captured_length(tvb) - IEEE802154_FCS_LEN - size_header (packet);
packet->h_ie_size = 0;
while (condition) {
guint16 header_ie;
//proto_tree *field_tree;
gint reported_len;
gint captured_len;
tvbuff_t *volatile payload_tvb;
/*value_string pos;*/
/* Get the information within the Information's Element header */
header_ie = tvb_get_letohs(tvb, *offset);
/* Parse the Header IE header */
packet->h_ie_content_lenght = header_ie & IEEE802154_H_IE_LENGTH;
packet->h_ie_id = (header_ie & IEEE802154_H_IE_ID) >> 7;
packet->h_ie_type = (header_ie & IEEE802154_H_IE_TYPE) >> 15;
packet->keep_dissecting -= (packet->h_ie_content_lenght + 2);
packet->h_ie_size += (packet->h_ie_content_lenght + 2);
/* Display the frame type. */
proto_item_append_text(tree, " %s", val_to_str_const(packet->h_ie_id, ieee802154_h_information_elements, "Unknown"));
/* Add the Header Information Element's header to the protocol tree. */
if (tree) {
/* Create the Header IE subtree. */
h_inf_elem_tree = proto_tree_add_subtree_format(tree, tvb, *offset, 2, ett_ieee802154_h_ie, NULL,
"Header Information Elements: %s (0x%04x)",
val_to_str_const(packet->h_ie_id, ieee802154_h_information_elements, "Unknown"), header_ie);
/* Header Information Elements header's values */
proto_tree_add_uint(h_inf_elem_tree, hf_ieee802154_h_ie_content_lenght, tvb, (*offset), 1, header_ie & IEEE802154_H_IE_LENGTH);
proto_tree_add_uint(h_inf_elem_tree, hf_ieee802154_h_ie_id, tvb, (*offset), 1, header_ie & IEEE802154_H_IE_ID);
proto_tree_add_boolean(h_inf_elem_tree, hf_ieee802154_h_ie_type, tvb, (*offset)+1, 1, header_ie & IEEE802154_H_IE_TYPE);
}
*offset += 2 ;
reported_len = packet->h_ie_content_lenght;
captured_len = reported_len;
payload_tvb = tvb_new_subset(tvb, *offset, captured_len, reported_len);
switch(packet->h_ie_id) {
case IEEE802154_H_IE_HDR_TERM_1:
packet->p_ie_present = TRUE;
condition = FALSE;
break;
case IEEE802154_H_IE_HDR_TERM_2:
condition = FALSE;
break;
default:
if (!packet->keep_dissecting > 0) {
condition = FALSE;
if(strcmp(val_to_str_const(packet->h_ie_id, ieee802154_h_information_elements_defined, "Unknown"), "Unknown") != 0) {
switch (packet->h_ie_id){
case IEEE802154_H_IE_TIME_CORRECTION:
dissect_802154_h_ie_time_correction(tvb, h_inf_elem_tree, packet, offset);
*offset += packet->h_ie_content_lenght;
break;
default:
call_dissector(data_handle, payload_tvb, pinfo, h_inf_elem_tree);
*offset += packet->h_ie_content_lenght;
break;
}
}
else{
call_dissector(data_handle, payload_tvb, pinfo, h_inf_elem_tree);
*offset += packet->h_ie_content_lenght;
}
}
break;
}
}
}
/*FUNCTION:------------------------------------------------------
* NAME
* dissect_ieee802154_fcf
* DESCRIPTION
* Dissector helper, parses and displays the frame control
* field.
*
* PARAMETERS
* ieee802154_packet *packet - Packet info structure.
* tvbuff_t *tvb - pointer to buffer containing raw packet.
* packet_info *pinfo - pointer to packet information fields
* proto_tree *tree - pointer to data tree wireshark uses to display packet.
* ieee802154_packet *packet - IEEE 802.15.4 packet information.
* guint offset - offset into the tvb to find the FCF.
* RETURNS
* void
*---------------------------------------------------------------
*/
static void
dissect_ieee802154_fcf(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, ieee802154_packet *packet, guint *offset)
{
guint16 fcf;
static const int * fields[] = {
&hf_ieee802154_frame_type,
&hf_ieee802154_security,
&hf_ieee802154_pending,
&hf_ieee802154_ack_request,
&hf_ieee802154_intra_pan,
&hf_ieee802154_seqnr_supression,
&hf_ieee802154_ielist_present,
&hf_ieee802154_dst_addr_mode,
&hf_ieee802154_version,
&hf_ieee802154_src_addr_mode,
NULL
};
/* Get the FCF field. */
fcf = tvb_get_letohs(tvb, *offset);
/* Parse FCF Flags. */
packet->frame_type = fcf & IEEE802154_FCF_TYPE_MASK;
packet->security_enable = fcf & IEEE802154_FCF_SEC_EN;
packet->frame_pending = fcf & IEEE802154_FCF_FRAME_PND;
packet->ack_request = fcf & IEEE802154_FCF_ACK_REQ;
packet->intra_pan = fcf & IEEE802154_FCF_INTRA_PAN;
packet->seqnr_suppresion = fcf & IEEE802154_FCF_SEQNR_SUPPR; /* according to 2015 spec. */
packet->ielist_present = fcf & IEEE802154_FCF_IELIST_PRESENT; /* according to 2015 spec. */
packet->version = (fcf & IEEE802154_FCF_VERSION) >> 12;
packet->dst_addr_mode = (fcf & IEEE802154_FCF_DADDR_MASK) >> 10;
packet->src_addr_mode = (fcf & IEEE802154_FCF_SADDR_MASK) >> 14;
/* Display the frame type. */
proto_item_append_text(tree, " %s", val_to_str_const(packet->frame_type, ieee802154_frame_types, "Unknown"));
col_set_str(pinfo->cinfo, COL_INFO, val_to_str_const(packet->frame_type, ieee802154_frame_types, "Unknown"));
proto_tree_add_bitmask(tree, tvb, *offset, hf_ieee802154_fcf,
ett_ieee802154_fcf, fields, ENC_LITTLE_ENDIAN);
*offset += 2;
} /* dissect_ieee802154_fcf */
/*FUNCTION:------------------------------------------------------
* NAME
* dissect_ieee802154_p_inf_elem
* DESCRIPTION
* Dissector helper, parses and displays the payload information element(s).
*
* PARAMETERS
* ieee802154_packet *packet - Packet info structure.
* tvbuff_t *tvb - pointer to buffer containing raw packet.
* packet_info *pinfo - pointer to packet information fields
* proto_tree *tree - pointer to data tree wireshark uses to display packet.
* ieee802154_packet *packet - IEEE 802.15.4 packet information.
* guint offset - offset into the tvb to find the FCF.
* RETURNS
* void
*---------------------------------------------------------------
*/
static void
dissect_ieee802154_p_inf_elem(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, ieee802154_packet *packet, guint *offset)
{
gboolean condition;
proto_tree *p_inf_elem_tree = NULL;
/* Create the protocol tree. */
if (tree) {
p_inf_elem_tree = proto_item_add_subtree(tree, ett_ieee802154_p_ie);
}
condition = TRUE;
packet->keep_dissecting_p_ie = tvb_captured_length(tvb) - IEEE802154_FCS_LEN - size_header(packet) - packet->h_ie_size;
while (condition) {
guint16 payload_ie;
//proto_tree *field_tree;
/* Get the information within the Information's Element header */
payload_ie = tvb_get_letohs(tvb, *offset);
/* Parse the Payload IE header */
packet->p_ie_content_lenght = payload_ie & IEEE802154_P_IE_LENGTH;
packet->p_ie_id = (payload_ie & IEEE802154_P_IE_ID) >> 11;
packet->p_ie_type = (payload_ie & IEEE802154_P_IE_TYPE) >> 15;
packet->keep_dissecting_p_ie -= (packet->p_ie_content_lenght + 2);
/* Display the frame type. */
proto_item_append_text(tree, " %s", val_to_str_const(packet->p_ie_id, ieee802154_p_information_elements, "Unknown"));
/* Add the Payload Information Element's header to the protocol tree. */
if (tree) {
/* Create the FCF subtree. */
p_inf_elem_tree = proto_tree_add_subtree_format(tree, tvb, *offset, 2, ett_ieee802154_p_ie, NULL,
"Payload Information Elements: %s (0x%04x)",
val_to_str_const(packet->p_ie_id, ieee802154_p_information_elements, "Unknown"), payload_ie);
/* Payload Information Elements header's values */
proto_tree_add_uint(p_inf_elem_tree, hf_ieee802154_p_ie_content_lenght, tvb, (*offset), 1, payload_ie & IEEE802154_P_IE_LENGTH);
proto_tree_add_uint(p_inf_elem_tree, hf_ieee802154_p_ie_id, tvb, (*offset)+1, 1, payload_ie & IEEE802154_P_IE_ID);
proto_tree_add_boolean(p_inf_elem_tree, hf_ieee802154_p_ie_type, tvb, (*offset)+1, 1, payload_ie & IEEE802154_P_IE_TYPE);
}
switch (packet->p_ie_id) {
case IEEE802154_P_IE_PAYLOAD_TERM:
condition = FALSE;
*offset += (2 + packet->p_ie_content_lenght);
break;
case IEEE802154_P_IE_MLME:
*offset += 2;
dissect_ieee802154_p_inf_elem_mlme(tvb, pinfo, p_inf_elem_tree, packet, offset);
break;
default :
*offset += (2 + packet->p_ie_content_lenght);
break;
}
if (packet->keep_dissecting_p_ie == 0){
condition = FALSE;
}
}
}
/*FUNCTION:------------------------------------------------------
* NAME
* dissect_ieee802154_p_inf_elem_mlme
* DESCRIPTION
* Dissector for IEEE 802.15.4 non-ASK PHY packet with an FCS containing
* a 16-bit CRC value.
*
* PARAMETERS
* ieee802154_packet *packet - Packet info structure.
* tvbuff_t *tvb - pointer to buffer containing raw packet.
* packet_info *pinfo - pointer to packet information fields
* proto_tree *tree - pointer to data tree wireshark uses to display packet.
* ieee802154_packet *packet - IEEE 802.15.4 packet information.
* guint offset - offset into the tvb to find the FCF.
* RETURNS
* void
*---------------------------------------------------------------
*/
static void
dissect_ieee802154_p_inf_elem_mlme(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, ieee802154_packet *packet, guint *offset)
{
gboolean conditionn;
proto_tree *p_inf_elem_tree_mlme = NULL;
conditionn = TRUE;
packet->keep_dissecting = 0;
while (conditionn){
guint16 mlme_header;
gint reported_len;
gint captured_len;
tvbuff_t *volatile payload_tvb;
//proto_tree *field_tree;
mlme_header = tvb_get_letohs(tvb, *offset);
packet->p_ie_mlme_type = (mlme_header & IEEE802154_P_IE_TYPE) >> 15;
if (packet->p_ie_mlme_type) {
packet->p_ie_mlme_lg_lenght = mlme_header & IEEE802154_P_MLME_LONG_LENGTH;
packet->p_ie_mlme_lg_id = (mlme_header & IEEE802154_P_MLME_LONG_ID) >> 11;
packet->keep_dissecting += (2 + packet->p_ie_mlme_lg_lenght);
/*mlme_memory_counter += (2 + packet->p_ie_mlme_lg_lenght);*/
if (packet->keep_dissecting >= packet->p_ie_content_lenght) {
conditionn = FALSE;
}
proto_item_append_text(tree, " %s", val_to_str_const(packet->p_ie_mlme_lg_id, ieee802154_h_mlme_sub_long_information_elements, "Unknown"));
/*col_set_str(pinfo->cinfo, COL_INFO, val_to_str_const(packet->p_ie_mlme_lg_id, ieee802154_h_mlme_sub_long_information_elements, "Unknown"));*/
if (tree) {
//proto_tree *field_tree_data_mlme;