summaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-bpdu.c
blob: ba4e38c78132ab641afa97fd90eb78e71141c56c (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
/* packet-bpdu.c
 * Routines for BPDU (Spanning Tree Protocol) disassembly
 *
 * Copyright 1999 Christophe Tronche <ch.tronche@computer.org>
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include "config.h"

#include <epan/packet.h>
#include <epan/llcsaps.h>
#include <epan/chdlctypes.h>
#include <epan/etypes.h>
#include <epan/addr_resolv.h>
#include <epan/prefs.h>
#include <epan/expert.h>
#include <epan/cisco_pid.h>
#include <epan/tfs.h>

/* Offsets of fields within a BPDU */

#define BPDU_IDENTIFIER                           0
#define BPDU_VERSION_IDENTIFIER                   2
#define BPDU_TYPE                                 3
#define BPDU_FLAGS                                4
#define BPDU_ROOT_IDENTIFIER                      5
#define BPDU_ROOT_PATH_COST                      13
#define BPDU_BRIDGE_IDENTIFIER                   17
#define BPDU_PORT_IDENTIFIER                     25
#define BPDU_MESSAGE_AGE                         27
#define BPDU_MAX_AGE                             29
#define BPDU_HELLO_TIME                          31
#define BPDU_FORWARD_DELAY                       33
#define BPDU_VERSION_1_LENGTH                    35
#define BPDU_VERSION_3_LENGTH                    36
#define BPDU_MST_CONFIG_FORMAT_SELECTOR          38
#define BPDU_MST_CONFIG_NAME                     39
#define BPDU_MST_CONFIG_REVISION_LEVEL           71
#define BPDU_MST_CONFIG_DIGEST                   73
#define BPDU_CIST_INTERNAL_ROOT_PATH_COST        89
#define BPDU_CIST_BRIDGE_IDENTIFIER              93
#define BPDU_CIST_REMAINING_HOPS                101
#define BPDU_MSTI                               102

#define BPDU_PVST_TLV                            36

#define MSTI_FLAGS                                0
#define MSTI_REGIONAL_ROOT                        1
#define MSTI_INTERNAL_ROOT_PATH_COST              9
#define MSTI_BRIDGE_IDENTIFIER_PRIORITY          13
#define MSTI_PORT_IDENTIFIER_PRIORITY            14
#define MSTI_REMAINING_HOPS                      15


#define CONF_BPDU_SIZE                  35
#define TC_BPDU_SIZE                     4
#define MST_BPDU_SIZE                   38
#define VERSION_3_STATIC_LENGTH         64
#define MSTI_MESSAGE_SIZE               16

/* Values for the Alternative MSTI format */

#define ALT_BPDU_CIST_BRIDGE_IDENTIFIER         89
#define ALT_BPDU_CIST_INTERNAL_ROOT_PATH_COST   97

#define ALT_MSTI_MSTID                           0
#define ALT_MSTI_FLAGS                           2
#define ALT_MSTI_REGIONAL_ROOT                   3
#define ALT_MSTI_INTERNAL_ROOT_PATH_COST        11
#define ALT_MSTI_BRIDGE_IDENTIFIER              15
#define ALT_MSTI_PORT_IDENTIFIER                23
#define ALT_MSTI_REMAINING_HOPS                 25

#define ALT_MSTI_MESSAGE_SIZE                   26

/* Flag bits */

#define BPDU_FLAGS_TCACK                0x80
#define BPDU_FLAGS_AGREEMENT            0x40
#define BPDU_FLAGS_FORWARDING           0x20
#define BPDU_FLAGS_LEARNING             0x10
#define BPDU_FLAGS_PORT_ROLE_MASK       0x0C
#define BPDU_FLAGS_PORT_ROLE_SHIFT      2
#define BPDU_FLAGS_PROPOSAL             0x02
#define BPDU_FLAGS_TC                   0x01

void proto_register_bpdu(void);
void proto_reg_handoff_bpdu(void);

static int proto_bpdu;
static int hf_bpdu_proto_id;
static int hf_bpdu_version_id;
static int hf_bpdu_type;
static int hf_bpdu_flags;
static int hf_bpdu_flags_tcack;
static int hf_bpdu_flags_agreement;
static int hf_bpdu_flags_forwarding;
static int hf_bpdu_flags_learning;
static int hf_bpdu_flags_port_role;
static int hf_bpdu_flags_proposal;
static int hf_bpdu_flags_tc;
static int hf_bpdu_root_prio;
static int hf_bpdu_root_sys_id_ext;
static int hf_bpdu_root_mac;
static int hf_bpdu_root_cost;
static int hf_bpdu_bridge_prio;
static int hf_bpdu_bridge_sys_id_ext;
static int hf_bpdu_bridge_mac;
static int hf_bpdu_port_id;
static int hf_bpdu_msg_age;
static int hf_bpdu_max_age;
static int hf_bpdu_hello_time;
static int hf_bpdu_forward_delay;
static int hf_bpdu_version_1_length;
static int hf_bpdu_version_3_length;
static int hf_bpdu_mst_config_format_selector;
static int hf_bpdu_mst_config_name;
static int hf_bpdu_mst_config_revision_level;
static int hf_bpdu_mst_config_digest;
static int hf_bpdu_cist_internal_root_path_cost;
static int hf_bpdu_cist_bridge_prio;
static int hf_bpdu_cist_bridge_sys_id_ext;
static int hf_bpdu_cist_bridge_mac;
static int hf_bpdu_cist_remaining_hops;
static int hf_bpdu_msti_flags;
static int hf_bpdu_msti_id;
static int hf_bpdu_msti_id_FFF;
static int hf_bpdu_mst_priority;
static int hf_bpdu_msti_regional_root_id;
static int hf_bpdu_msti_regional_root_mac;
static int hf_bpdu_msti_internal_root_path_cost;
static int hf_bpdu_msti_bridge_identifier_priority;
static int hf_bpdu_msti_port_identifier_priority;
static int hf_bpdu_msti_port_id;
static int hf_bpdu_msti_bridge_id;
static int hf_bpdu_msti_bridge_id_priority;
static int hf_bpdu_msti_bridge_id_mac;
static int hf_bpdu_msti_remaining_hops;
static int hf_bpdu_version_4_length;
static int hf_bpdu_spt_config_format_selector;
static int hf_bpdu_spt_config_name;
static int hf_bpdu_spt_config_revision_level;
static int hf_bpdu_spt_config_digest;
static int hf_bpdu_flags_agree_num;
static int hf_bpdu_flags_dagree_num;
static int hf_bpdu_flags_agree_valid;
static int hf_bpdu_flags_restricted_role;
static int hf_bpdu_spt_agreement_digest;
static int hf_bpdu_agreement_digest_format_id;
static int hf_bpdu_agreement_digest_format_capabilities;
static int hf_bpdu_agreement_digest_convention_id;
static int hf_bpdu_agreement_digest_convention_capabilities;
static int hf_bpdu_agreement_digest_edge_count;

static int hf_bpdu_pvst_tlvtype;
static int hf_bpdu_pvst_tlvlength;
static int hf_bpdu_pvst_tlvvalue;
static int hf_bpdu_pvst_tlv_origvlan;

static int ett_bpdu;
static int ett_bpdu_flags;
static int ett_root_id;
static int ett_bridge_id;
static int ett_mstp;
static int ett_msti;
static int ett_cist_bridge_id;
static int ett_spt;
static int ett_aux_mcid;
static int ett_agreement;
static int ett_bpdu_pvst_tlv;

static expert_field ei_pvst_tlv_length_invalid;
static expert_field ei_pvst_tlv_origvlan_missing;
static expert_field ei_pvst_tlv_truncated;
static expert_field ei_pvst_tlv_unknown;
static expert_field ei_bpdu_type;
static expert_field ei_bpdu_version_support;


static bool bpdu_use_system_id_extensions = true;

static dissector_handle_t gvrp_handle;
static dissector_handle_t gmrp_handle;

static dissector_handle_t bpdu_handle;
static dissector_handle_t bpdu_cisco_handle;

static const value_string protocol_id_vals[] = {
  { 0, "Spanning Tree Protocol" },
  { 0, NULL }
};

#define BPDU_PVST_TLV_ORIGVLAN  0               /* Originating VLAN TLV in Cisco (R)PVST+ BPDUs */

static const value_string bpdu_pvst_tlv_vals[] = {
  { BPDU_PVST_TLV_ORIGVLAN,             "Originating VLAN" },
  { 0,                                  NULL }
};


#define BPDU_TYPE_CONF                  0x00    /* STP Configuration BPDU */
#define BPDU_TYPE_RST                   0x02    /* RST BPDU (or MST) */
#define BPDU_TYPE_TOPOLOGY_CHANGE       0x80    /* STP TCN (Topology change notify) BPDU */

static const value_string bpdu_type_vals[] = {
  { BPDU_TYPE_CONF,            "Configuration" },
  { BPDU_TYPE_RST,             "Rapid/Multiple Spanning Tree" },
  { BPDU_TYPE_TOPOLOGY_CHANGE, "Topology Change Notification" },
  { 0,                         NULL }
};

#define PROTO_VERSION_STP       0
#define PROTO_VERSION_RSTP      2
#define PROTO_VERSION_MSTP      3
#define PROTO_VERSION_SPB       4

#define MSTI_FORMAT_UNKNOWN     0
#define MSTI_FORMAT_IEEE_8021S  1
#define MSTI_FORMAT_ALTERNATIVE 2

static const value_string version_id_vals[] = {
  { PROTO_VERSION_STP,  "Spanning Tree" },
  { PROTO_VERSION_RSTP, "Rapid Spanning Tree" },
  { PROTO_VERSION_MSTP, "Multiple Spanning Tree" },
  { PROTO_VERSION_SPB,  "Shortest Path Tree" },
  { 0,                  NULL}
};
static const value_string role_vals[] = {
  { 1, "Alternate or Backup" },
  { 2, "Root" },
  { 3, "Designated" },
  { 0, NULL }
};

static const char initial_sep[] = " (";
static const char cont_sep[] = ", ";

static void
dissect_bpdu_pvst_tlv(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb) {
  bool pvst_tlv_origvlan_present = false;
  uint16_t tlv_type, tlv_length;
  int offset = BPDU_PVST_TLV;
  proto_item * ti = NULL;
  proto_item * tlv_length_item = NULL;
  proto_tree * tlv_tree = NULL;

  if (tvb_reported_length_remaining(tvb, offset) < 4) /* TLV Type and Length fields occupy 4 bytes in total */
    expert_add_info(pinfo, tree, &ei_pvst_tlv_truncated);

  while (tvb_reported_length_remaining(tvb, offset) >= 4) { /* TLV Type and Length fields occupy 4 bytes in total */
    tlv_type = tvb_get_ntohs(tvb, offset);
    tlv_length = tvb_get_ntohs(tvb, offset + 2);

    tlv_tree = proto_tree_add_subtree(tree, tvb, offset, 4 + tlv_length,
                        ett_bpdu_pvst_tlv, &ti,
                        val_to_str(tlv_type, bpdu_pvst_tlv_vals, "Unknown TLV type: 0x%04x"));

    proto_tree_add_item(tlv_tree, hf_bpdu_pvst_tlvtype, tvb, offset, 2, ENC_BIG_ENDIAN);
    tlv_length_item = proto_tree_add_item(tlv_tree, hf_bpdu_pvst_tlvlength,
                        tvb, offset + 2, 2, ENC_BIG_ENDIAN);

    if (tvb_reported_length_remaining(tvb, offset + 4) < tlv_length) {
      expert_add_info(pinfo, tlv_length_item, &ei_pvst_tlv_truncated);
      break;
    }

    offset += 4;

    switch (tlv_type) {
      case BPDU_PVST_TLV_ORIGVLAN:
        if (tlv_length == 2) { /* Originating VLAN ID must be 2 bytes long */
          proto_item_append_text(ti, " (PVID): %u", tvb_get_ntohs(tvb, offset));
          proto_tree_add_item(tlv_tree, hf_bpdu_pvst_tlv_origvlan, tvb, offset, tlv_length, ENC_BIG_ENDIAN);
          pvst_tlv_origvlan_present = true;
        }
        else
          expert_add_info(pinfo, tlv_length_item, &ei_pvst_tlv_length_invalid);
        break;

      default:
        proto_tree_add_item(tlv_tree, hf_bpdu_pvst_tlvvalue, tvb, offset, tlv_length, ENC_NA);
        expert_add_info(pinfo, tlv_tree, &ei_pvst_tlv_unknown);
        break;
    }

    offset += tlv_length;
  }

  if (pvst_tlv_origvlan_present == false) /* If a (R)PVST+ BPDU lacks the Originating VLAN TLV, it is malformed */
    expert_add_info(pinfo, tree, &ei_pvst_tlv_origvlan_missing);
}

static void
dissect_bpdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, bool is_bpdu_pvst)
{
  uint16_t protocol_identifier;
  uint8_t protocol_version_identifier;
  uint8_t bpdu_type;
  uint8_t flags;
  uint16_t root_identifier_bridge_priority;
  uint16_t root_identifier_system_id_extension = 0;
  const char *root_identifier_mac_str;
  uint32_t root_path_cost;
  uint16_t bridge_identifier_bridge_priority;
  uint16_t bridge_identifier_system_id_extension = 0;
  const char *bridge_identifier_mac_str;
  uint16_t port_identifier;
  double message_age;
  double max_age;
  double hello_time;
  double forward_delay;
  uint8_t version_1_length;
  uint16_t version_3_length;
  uint16_t version_4_length = 0;
  uint16_t bpdu_version_4_length = 0;
  uint8_t config_format_selector;
  uint16_t cist_bridge_identifier_bridge_priority;
  uint16_t cist_bridge_identifier_system_id_extension = 0;
  const char *cist_bridge_identifier_mac_str;
  uint32_t msti_regional_root_mstid, msti_regional_root_priority;
  const char *msti_regional_root_mac_str;
  uint16_t msti_bridge_identifier_priority, msti_port_identifier_priority;
  int   total_msti_length, offset, msti_format;
  int   msti_length_remaining;

  int spt_offset = 0;

  int MCID_LEN = 51;
  uint8_t spt_agree_data = 0;

  proto_tree *bpdu_tree;
  proto_tree *mstp_tree, *msti_tree, *spt_tree = NULL, *aux_mcid_tree = NULL, *agreement_tree = NULL;
  proto_item *bpdu_item;
  proto_item *agreement_item, *proto_id_item, *type_item;
  proto_tree *root_id_tree;
  proto_tree *bridge_id_tree;
  proto_tree *cist_bridge_id_tree;
  const char *sep;

  static int * const bpdu_flags[] = {
    &hf_bpdu_flags_tcack,
    &hf_bpdu_flags_tc,
    NULL
  };

  static int * const rst_flags[] = {
    &hf_bpdu_flags_tcack,
    &hf_bpdu_flags_agreement,
    &hf_bpdu_flags_forwarding,
    &hf_bpdu_flags_learning,
    &hf_bpdu_flags_port_role,
    &hf_bpdu_flags_proposal,
    &hf_bpdu_flags_tc,
    NULL
  };

  /* GARP application frames require special interpretation of the
     destination address field; otherwise, they will be mistaken as
     BPDU frames.
     Fortunately, they can be recognized by checking the first 6 octets
     of the destination address, which are in the range from
     01-80-C2-00-00-20 to 01-80-C2-00-00-2F.

     Yes - we *do* need to check the destination address type;
     on Linux cooked captures, there *is* no destination address,
     so it's AT_NONE. */
  if (pinfo->dl_dst.type == AT_ETHER) {
    const uint8_t *dstaddr;

    dstaddr = (const uint8_t *)pinfo->dl_dst.data;
    if(dstaddr[0] == 0x01 && dstaddr[1] == 0x80 &&
       dstaddr[2] == 0xC2 && dstaddr[3] == 0x00 &&
       dstaddr[4] == 0x00 && ((dstaddr[5] == 0x0D) || ((dstaddr[5] & 0xF0) == 0x20))) {

      switch (dstaddr[5]) {

      case 0x20:
        /* for GMRP */
        call_dissector(gmrp_handle, tvb, pinfo, tree);
        return;

      case 0x21:
      case 0x0D:
        /* for GVRP */
        call_dissector(gvrp_handle, tvb, pinfo, tree);
        return;
      }
      col_set_str(pinfo->cinfo, COL_PROTOCOL, "GARP");
        /* Generic Attribute Registration Protocol */

      col_add_fstr(pinfo->cinfo, COL_INFO,
                   "Unknown GARP application (0x%02X)",
                   dstaddr[5]);

      return;
    }
  }

  col_set_str(pinfo->cinfo, COL_PROTOCOL, "STP"); /* Spanning Tree Protocol */
  col_clear(pinfo->cinfo, COL_INFO);

  bpdu_type = tvb_get_uint8(tvb, BPDU_TYPE);

  protocol_version_identifier = tvb_get_uint8(tvb, BPDU_VERSION_IDENTIFIER);

  switch (bpdu_type) {

  case BPDU_TYPE_CONF:
  case BPDU_TYPE_RST:
    flags = tvb_get_uint8(tvb, BPDU_FLAGS);
    root_identifier_bridge_priority = tvb_get_ntohs(tvb,BPDU_ROOT_IDENTIFIER);
    if (bpdu_use_system_id_extensions ) {
      root_identifier_system_id_extension = root_identifier_bridge_priority & 0x0fff;
      root_identifier_bridge_priority &= 0xf000;
    }
    root_identifier_mac_str = tvb_ether_to_str(pinfo->pool, tvb, BPDU_ROOT_IDENTIFIER + 2);
    root_path_cost = tvb_get_ntohl(tvb, BPDU_ROOT_PATH_COST);
    port_identifier = tvb_get_ntohs(tvb, BPDU_PORT_IDENTIFIER);
    break;

  default:
    /* Squelch GCC complaints. */
    flags = 0;
    root_identifier_bridge_priority = 0;
    root_identifier_mac_str = NULL;
    root_path_cost = 0;
    port_identifier = 0;
    break;
  }

  switch (bpdu_type) {

  case BPDU_TYPE_CONF:
    if (bpdu_use_system_id_extensions ) {
      col_add_fstr(pinfo->cinfo, COL_INFO,
                   "Conf. %sRoot = %d/%d/%s  Cost = %d  Port = 0x%04x",
                   flags & 0x1 ? "TC + " : "",
                   root_identifier_bridge_priority,
                   root_identifier_system_id_extension,
                   root_identifier_mac_str,
                   root_path_cost, port_identifier);
    } else {
      col_add_fstr(pinfo->cinfo, COL_INFO,
                   "Conf. %sRoot = %d/%s  Cost = %d  Port = 0x%04x",
                   flags & 0x1 ? "TC + " : "",
                   root_identifier_bridge_priority, root_identifier_mac_str,
                   root_path_cost, port_identifier);
    }
    break;

  case BPDU_TYPE_TOPOLOGY_CHANGE:
    col_set_str(pinfo->cinfo, COL_INFO, "Topology Change Notification");
    break;

  case BPDU_TYPE_RST:
    if (bpdu_use_system_id_extensions ) {
      col_add_fstr(pinfo->cinfo, COL_INFO,
                   "%sT. %sRoot = %d/%d/%s  Cost = %d  Port = 0x%04x",
                     protocol_version_identifier == 3 ? "MS":
                     (protocol_version_identifier == 4 ? "SP":"RS"),
                     flags & 0x1 ? "TC + " : "",
                     root_identifier_bridge_priority,
                     root_identifier_system_id_extension,
                     root_identifier_mac_str,
                     root_path_cost, port_identifier);
    } else {
      col_add_fstr(pinfo->cinfo, COL_INFO,
                   "%sT. %sRoot = %d/%s  Cost = %d  Port = 0x%04x",
                   protocol_version_identifier == 3 ? "MS":
                   (protocol_version_identifier == 4 ? "SP":"RS"),
                   flags & 0x1 ? "TC + " : "",
                   root_identifier_bridge_priority, root_identifier_mac_str,
                   root_path_cost, port_identifier);
    }
    break;

  default:
    col_add_fstr(pinfo->cinfo, COL_INFO, "Unknown BPDU type (%u)", bpdu_type);
    break;
  }

    bpdu_item = proto_tree_add_protocol_format(tree, proto_bpdu, tvb, 0, -1,
                                               "Spanning Tree Protocol");
    bpdu_tree = proto_item_add_subtree(bpdu_item, ett_bpdu);

    protocol_identifier = tvb_get_ntohs(tvb, BPDU_IDENTIFIER);
    proto_tree_add_uint(bpdu_tree, hf_bpdu_proto_id, tvb, BPDU_IDENTIFIER, 2,
                        protocol_identifier);

    proto_id_item = proto_tree_add_uint(bpdu_tree, hf_bpdu_version_id, tvb,
                        BPDU_VERSION_IDENTIFIER, 1,
                        protocol_version_identifier);
    switch (protocol_version_identifier) {

    case 0:
      break;

    case 2:
    case 3:
    case 4:
      break;

    default:
      expert_add_info(pinfo, proto_id_item, &ei_bpdu_version_support);
      break;
    }
    type_item = proto_tree_add_uint(bpdu_tree, hf_bpdu_type, tvb, BPDU_TYPE, 1, bpdu_type);

    if (bpdu_type == BPDU_TYPE_TOPOLOGY_CHANGE) {
      set_actual_length(tvb, TC_BPDU_SIZE);
      return;
    }

    if (bpdu_type != BPDU_TYPE_CONF && bpdu_type != BPDU_TYPE_RST) {
      /* Unknown BPDU type - just display the rest of the PDU as data */
      expert_add_info(pinfo, type_item, &ei_bpdu_type);
      return;
    }

    bridge_identifier_bridge_priority = tvb_get_ntohs(tvb, BPDU_BRIDGE_IDENTIFIER);
    if (bpdu_use_system_id_extensions ) {
      bridge_identifier_system_id_extension = bridge_identifier_bridge_priority & 0x0fff;
      bridge_identifier_bridge_priority &= 0xf000;
    }
    bridge_identifier_mac_str = tvb_ether_to_str(pinfo->pool, tvb, BPDU_BRIDGE_IDENTIFIER + 2);

    if (bpdu_type == BPDU_TYPE_RST) {
       proto_tree_add_bitmask_value_with_flags(bpdu_tree, tvb, BPDU_FLAGS, hf_bpdu_flags, ett_bpdu_flags, rst_flags, flags, BMT_NO_FALSE|BMT_NO_TFS);
    } else {
       proto_tree_add_bitmask_value_with_flags(bpdu_tree, tvb, BPDU_FLAGS, hf_bpdu_flags, ett_bpdu_flags, bpdu_flags, flags, BMT_NO_FALSE|BMT_NO_TFS);
    }

    /* add Identifier with format based on preference value
     * bpdu_use_system_id_extensions
     * */
    if (bpdu_use_system_id_extensions) {
      root_id_tree = proto_tree_add_subtree_format(bpdu_tree, tvb,
                                         BPDU_ROOT_IDENTIFIER, 8,
                                         ett_root_id, NULL,
                                         "Root Identifier: %d / %d / %s",
                                         root_identifier_bridge_priority,
                                         root_identifier_system_id_extension,
                                         root_identifier_mac_str);
      proto_tree_add_uint(root_id_tree, hf_bpdu_root_prio, tvb,
                          BPDU_ROOT_IDENTIFIER , 1,
                          root_identifier_bridge_priority);
      proto_tree_add_uint(root_id_tree, hf_bpdu_root_sys_id_ext, tvb,
                          BPDU_ROOT_IDENTIFIER , 2,
                          root_identifier_system_id_extension);
      proto_tree_add_item(root_id_tree, hf_bpdu_root_mac, tvb,
                          BPDU_ROOT_IDENTIFIER + 2, 6, ENC_NA);

    } else {
      root_id_tree = proto_tree_add_subtree_format(bpdu_tree, tvb,
                                         BPDU_ROOT_IDENTIFIER, 8,
                                         ett_root_id, NULL,
                                         "Root Identifier: %d / %s",
                                         root_identifier_bridge_priority,
                                         root_identifier_mac_str);
      proto_tree_add_uint(root_id_tree, hf_bpdu_root_prio, tvb,
                          BPDU_ROOT_IDENTIFIER , 2,
                          root_identifier_bridge_priority);
      proto_tree_add_item(root_id_tree, hf_bpdu_root_mac, tvb,
                          BPDU_ROOT_IDENTIFIER + 2, 6, ENC_NA);
    }
    /* end of Identifier formatting */

    proto_tree_add_uint(bpdu_tree, hf_bpdu_root_cost, tvb,
                        BPDU_ROOT_PATH_COST, 4, root_path_cost);

    /* add Identifier with format based on preference value
     * bpdu_use_system_id_extensions
     * */
    if (bpdu_use_system_id_extensions) {
      bridge_id_tree = proto_tree_add_subtree_format(bpdu_tree, tvb,
                                           BPDU_BRIDGE_IDENTIFIER, 8,
                                           ett_bridge_id, NULL,
                                           "Bridge Identifier: %d / %d / %s",
                                           bridge_identifier_bridge_priority,
                                           bridge_identifier_system_id_extension,
                                           bridge_identifier_mac_str);
      proto_tree_add_uint(bridge_id_tree, hf_bpdu_bridge_prio, tvb,
                          BPDU_BRIDGE_IDENTIFIER , 1,
                          bridge_identifier_bridge_priority);
      proto_tree_add_uint(bridge_id_tree, hf_bpdu_bridge_sys_id_ext, tvb,
                          BPDU_BRIDGE_IDENTIFIER , 2,
                          bridge_identifier_system_id_extension);
      proto_tree_add_item(bridge_id_tree, hf_bpdu_bridge_mac, tvb,
                          BPDU_BRIDGE_IDENTIFIER + 2, 6, ENC_NA);
    } else {
      bridge_id_tree = proto_tree_add_subtree_format(bpdu_tree, tvb,
                                           BPDU_BRIDGE_IDENTIFIER, 8,
                                           ett_bridge_id, NULL,
                                           "Bridge Identifier: %d / %s",
                                           bridge_identifier_bridge_priority,
                                           bridge_identifier_mac_str);
      proto_tree_add_uint(bridge_id_tree, hf_bpdu_bridge_prio, tvb,
                          BPDU_BRIDGE_IDENTIFIER , 2,
                          bridge_identifier_bridge_priority);
      proto_tree_add_item(bridge_id_tree, hf_bpdu_bridge_mac, tvb,
                          BPDU_BRIDGE_IDENTIFIER + 2, 6, ENC_NA);
    }
    /* end of Identifier formatting */

    proto_tree_add_uint(bpdu_tree, hf_bpdu_port_id, tvb,
                        BPDU_PORT_IDENTIFIER, 2, port_identifier);
    message_age = tvb_get_ntohs(tvb, BPDU_MESSAGE_AGE) / 256.0;
    proto_tree_add_double(bpdu_tree, hf_bpdu_msg_age, tvb, BPDU_MESSAGE_AGE, 2,
                          message_age);
    max_age = tvb_get_ntohs(tvb, BPDU_MAX_AGE) / 256.0;
    proto_tree_add_double(bpdu_tree, hf_bpdu_max_age, tvb, BPDU_MAX_AGE, 2,
                          max_age);
    hello_time = tvb_get_ntohs(tvb, BPDU_HELLO_TIME) / 256.0;
    proto_tree_add_double(bpdu_tree, hf_bpdu_hello_time, tvb,
                          BPDU_HELLO_TIME, 2, hello_time);
    forward_delay = tvb_get_ntohs(tvb, BPDU_FORWARD_DELAY) / 256.0;
    proto_tree_add_double(bpdu_tree, hf_bpdu_forward_delay, tvb,
                          BPDU_FORWARD_DELAY, 2, forward_delay);

    if (bpdu_type == BPDU_TYPE_CONF) {
      if (is_bpdu_pvst)
        dissect_bpdu_pvst_tlv(pinfo, bpdu_tree, tvb);

      /* Nothing more in this BPDU */
      set_actual_length(tvb, CONF_BPDU_SIZE);
      return;
    }

    /* RST or MST BPDU */
    version_1_length = tvb_get_uint8(tvb, BPDU_VERSION_1_LENGTH);
    proto_tree_add_uint(bpdu_tree, hf_bpdu_version_1_length, tvb,
                        BPDU_VERSION_1_LENGTH, 1, version_1_length);
    /* Is this an MST BPDU? */
    if (protocol_version_identifier >= 3 && version_1_length == 0 &&
        tvb_reported_length(tvb) >= 102) {
      /*
       * OK, it passes the "Protocol Identifier is 0000 0000
       * 0000 0000", "Protocol Version Identifier is 3 or
       * greater", "BPDU Type is 0000 0010", "contains 102 or
       * more octets", and "a Version 1 Length of 0" tests.
       */
      version_3_length = tvb_get_ntohs(tvb, BPDU_VERSION_3_LENGTH);
      proto_tree_add_uint(bpdu_tree, hf_bpdu_version_3_length, tvb,
                          BPDU_VERSION_3_LENGTH, 2, version_3_length);

      /*
       * Check the Version 3 Length, and see whether it's a
       * multiple of the MSTI Configuration Message length. Also
       * check the config_format_selector because some MST BPDU's
       * have BPDU_VERSION_3_LENGTH set to 0 and use the
       * field BPDU_MST_CONFIG_FORMAT_SELECTOR as a length-field
       * for the MSTI data.
       */
      config_format_selector = tvb_get_uint8(tvb, BPDU_MST_CONFIG_FORMAT_SELECTOR);
      if (version_3_length != 0) {
        msti_format = MSTI_FORMAT_IEEE_8021S;
        if (version_3_length >= VERSION_3_STATIC_LENGTH) {
          total_msti_length = version_3_length - VERSION_3_STATIC_LENGTH;
        } else {
          /*
           * XXX - there appears to be an ambiguity in the 802.3Q-2003
           * standard and at least some of the 802.3s drafts.
           *
           * The "Version 3 Length" field is defined to be "the number of
           * octets taken by the parameters that follow in the BPDU", but
           * it's spoken of as "representing an integral number, from 0 to
           * 64 inclusive, of MSTI Configuration Messages".
           *
           * According to mail from a member of the stds-802-1@ieee.org list,
           * the latter of those is just saying that the length must not have
           * a value that implies that there's a partial MSTI message in the
           * packet; it's still in units of octets, not messages.
           *
           * However, it appears that Cisco's C3550 software (C3550-I5Q3L2-M,
           * Version 12.1(12c)EA1) might be sending out lengths in units of
           * messages.
           *
           * This length can't be the number of octets taken by the parameters
           * that follow in the BPDU, because it's less than the fixed-length
           * portion of those parameters, so we assume the length is a count of
           * messages.
           */
          total_msti_length = version_3_length * MSTI_MESSAGE_SIZE;
        }
      } else {
        if (tvb_reported_length(tvb) == (unsigned)config_format_selector + MST_BPDU_SIZE + 1 ) {
          msti_format = MSTI_FORMAT_ALTERNATIVE;
          total_msti_length = config_format_selector - VERSION_3_STATIC_LENGTH;
        } else {
          /*
           * XXX - Unknown MSTI format, since version_3_length is 0
           * lets assume there are no msti instances in the packet.
           */
          msti_format = MSTI_FORMAT_UNKNOWN;
          total_msti_length = 0;
        }
      }
      if (protocol_version_identifier == 3) {
        set_actual_length(tvb, BPDU_MSTI + total_msti_length);
      }

      mstp_tree = proto_tree_add_subtree(bpdu_tree, tvb, BPDU_VERSION_3_LENGTH,
                                      -1, ett_mstp, NULL, "MST Extension");

      proto_tree_add_item(mstp_tree, hf_bpdu_mst_config_format_selector, tvb,
                          BPDU_MST_CONFIG_FORMAT_SELECTOR, 1, ENC_BIG_ENDIAN);
      proto_tree_add_item(mstp_tree, hf_bpdu_mst_config_name, tvb,
                          BPDU_MST_CONFIG_NAME, 32, ENC_ASCII|ENC_NA);

      proto_tree_add_item(mstp_tree, hf_bpdu_mst_config_revision_level, tvb,
                          BPDU_MST_CONFIG_REVISION_LEVEL, 2, ENC_BIG_ENDIAN);
      proto_tree_add_item(mstp_tree, hf_bpdu_mst_config_digest, tvb,
                          BPDU_MST_CONFIG_DIGEST, 16, ENC_NA);

      switch(msti_format) {

      case MSTI_FORMAT_IEEE_8021S:
        proto_tree_add_item(mstp_tree, hf_bpdu_cist_internal_root_path_cost, tvb,
                            BPDU_CIST_INTERNAL_ROOT_PATH_COST, 4, ENC_BIG_ENDIAN);

        cist_bridge_identifier_bridge_priority = tvb_get_ntohs(tvb,BPDU_CIST_BRIDGE_IDENTIFIER);
        cist_bridge_identifier_mac_str = tvb_ether_to_str(pinfo->pool, tvb, BPDU_CIST_BRIDGE_IDENTIFIER + 2);

        /* add Identifier with format based on preference value
         * bpdu_use_system_id_extensions
         * */
        if (bpdu_use_system_id_extensions ) {
          cist_bridge_identifier_system_id_extension = cist_bridge_identifier_bridge_priority & 0x0fff;
          cist_bridge_identifier_bridge_priority &= 0xf000;

          cist_bridge_id_tree = proto_tree_add_subtree_format(mstp_tree, tvb,
                                                    BPDU_CIST_BRIDGE_IDENTIFIER, 8,
                                                    ett_cist_bridge_id, NULL,
                                                    "CIST Bridge Identifier: %d / %d / %s",
                                                    cist_bridge_identifier_bridge_priority,
                                                    cist_bridge_identifier_system_id_extension,
                                                    cist_bridge_identifier_mac_str);
          proto_tree_add_uint(cist_bridge_id_tree, hf_bpdu_cist_bridge_prio, tvb,
                              BPDU_CIST_BRIDGE_IDENTIFIER , 1,
                              cist_bridge_identifier_bridge_priority);
          proto_tree_add_uint(cist_bridge_id_tree, hf_bpdu_cist_bridge_sys_id_ext, tvb,
                              BPDU_CIST_BRIDGE_IDENTIFIER , 2,
                              cist_bridge_identifier_system_id_extension);
          proto_tree_add_item(cist_bridge_id_tree, hf_bpdu_cist_bridge_mac, tvb,
                              BPDU_CIST_BRIDGE_IDENTIFIER + 2, 6, ENC_NA);

        } else {
          cist_bridge_id_tree = proto_tree_add_subtree_format(mstp_tree, tvb,
                                                    BPDU_CIST_BRIDGE_IDENTIFIER, 8,
                                                    ett_cist_bridge_id, NULL,
                                                    "CIST Bridge Identifier: %d / %s",
                                                    cist_bridge_identifier_bridge_priority,
                                                    cist_bridge_identifier_mac_str);
          proto_tree_add_uint(cist_bridge_id_tree, hf_bpdu_cist_bridge_prio, tvb,
                              BPDU_CIST_BRIDGE_IDENTIFIER , 2,
                              cist_bridge_identifier_bridge_priority);
          proto_tree_add_item(cist_bridge_id_tree, hf_bpdu_cist_bridge_mac, tvb,
                              BPDU_CIST_BRIDGE_IDENTIFIER + 2, 6, ENC_NA);
        }
        /* end of Identifier formatting */

        break;

      case MSTI_FORMAT_ALTERNATIVE:
        cist_bridge_identifier_bridge_priority = tvb_get_ntohs(tvb,ALT_BPDU_CIST_BRIDGE_IDENTIFIER);
        cist_bridge_identifier_mac_str = tvb_ether_to_str(pinfo->pool, tvb, ALT_BPDU_CIST_BRIDGE_IDENTIFIER + 2);

        /* add Identifier with format based on preference value
         * bpdu_use_system_id_extensions
         * */
        if (bpdu_use_system_id_extensions ) {
          cist_bridge_identifier_system_id_extension = cist_bridge_identifier_bridge_priority & 0x0fff;
          cist_bridge_identifier_bridge_priority &= 0xf000;

          cist_bridge_id_tree = proto_tree_add_subtree_format(mstp_tree, tvb,
                                                    ALT_BPDU_CIST_BRIDGE_IDENTIFIER, 8,
                                                    ett_cist_bridge_id, NULL,
                                                    "CIST Bridge Identifier: %d / %d / %s",
                                                    cist_bridge_identifier_bridge_priority,
                                                    cist_bridge_identifier_system_id_extension,
                                                    cist_bridge_identifier_mac_str);
          proto_tree_add_uint(cist_bridge_id_tree, hf_bpdu_cist_bridge_prio, tvb,
                              ALT_BPDU_CIST_BRIDGE_IDENTIFIER , 1,
                              cist_bridge_identifier_bridge_priority);
          proto_tree_add_uint(cist_bridge_id_tree, hf_bpdu_cist_bridge_sys_id_ext, tvb,
                              ALT_BPDU_CIST_BRIDGE_IDENTIFIER , 2,
                              cist_bridge_identifier_system_id_extension);
          proto_tree_add_item(cist_bridge_id_tree, hf_bpdu_cist_bridge_mac, tvb,
                              ALT_BPDU_CIST_BRIDGE_IDENTIFIER + 2, 6, ENC_NA);
        } else {
          cist_bridge_id_tree = proto_tree_add_subtree_format(mstp_tree, tvb,
                                                    ALT_BPDU_CIST_BRIDGE_IDENTIFIER, 8,
                                                    ett_cist_bridge_id, NULL,
                                                    "CIST Bridge Identifier: %d / %s",
                                                    cist_bridge_identifier_bridge_priority,
                                                    cist_bridge_identifier_mac_str);
          proto_tree_add_uint(cist_bridge_id_tree, hf_bpdu_cist_bridge_prio, tvb,
                              ALT_BPDU_CIST_BRIDGE_IDENTIFIER , 2,
                              cist_bridge_identifier_bridge_priority);
          proto_tree_add_item(cist_bridge_id_tree, hf_bpdu_cist_bridge_mac, tvb,
                              ALT_BPDU_CIST_BRIDGE_IDENTIFIER + 2, 6, ENC_NA);
        }
        /* end of Identifier formatting */

        proto_tree_add_item(mstp_tree, hf_bpdu_cist_internal_root_path_cost, tvb,
                            ALT_BPDU_CIST_INTERNAL_ROOT_PATH_COST, 4, ENC_BIG_ENDIAN);

        break;
      }

      proto_tree_add_item(mstp_tree, hf_bpdu_cist_remaining_hops, tvb,
                          BPDU_CIST_REMAINING_HOPS, 1, ENC_BIG_ENDIAN);
      /* MSTI messages */
      offset = BPDU_MSTI;
      msti_length_remaining = total_msti_length;
      while (msti_length_remaining > 0) {
        switch(msti_format) {

        case MSTI_FORMAT_IEEE_8021S:
          msti_regional_root_mstid = tvb_get_uint8(tvb,  offset+ MSTI_REGIONAL_ROOT);
          msti_regional_root_priority = (msti_regional_root_mstid &0xf0) << 8;
          msti_regional_root_mstid = ((msti_regional_root_mstid & 0x0f) << 8) +
                                     tvb_get_uint8(tvb,  offset+ MSTI_REGIONAL_ROOT+1);
          msti_regional_root_mac_str = tvb_ether_to_str(pinfo->pool, tvb, offset + MSTI_REGIONAL_ROOT + 2);

          msti_tree = proto_tree_add_subtree_format(mstp_tree, tvb, offset, 16, ett_msti, NULL,
                                          "MSTID %d, Regional Root Identifier %d / %s",
                                          msti_regional_root_mstid,
                                          msti_regional_root_priority,
                                          msti_regional_root_mac_str);

          /* flags */
          proto_tree_add_bitmask_with_flags(msti_tree, tvb, offset+MSTI_FLAGS, hf_bpdu_msti_flags, ett_bpdu_flags, rst_flags, ENC_NA, BMT_NO_FALSE|BMT_NO_TFS);

          /* pri, MSTID, Regional root */
          proto_tree_add_item(msti_tree, hf_bpdu_mst_priority, tvb, offset + MSTI_REGIONAL_ROOT, 1, ENC_BIG_ENDIAN);
          proto_tree_add_item(msti_tree, hf_bpdu_msti_id_FFF, tvb, offset + MSTI_REGIONAL_ROOT, 2, ENC_BIG_ENDIAN);
          proto_tree_add_item(msti_tree, hf_bpdu_msti_regional_root_mac, tvb,
                                            offset + MSTI_REGIONAL_ROOT + 2, 6, ENC_NA);

          proto_tree_add_item(msti_tree, hf_bpdu_msti_internal_root_path_cost, tvb,
                              offset+MSTI_INTERNAL_ROOT_PATH_COST, 4, ENC_BIG_ENDIAN);

          msti_bridge_identifier_priority = tvb_get_uint8(tvb, offset+MSTI_BRIDGE_IDENTIFIER_PRIORITY) >> 4;
          msti_port_identifier_priority = tvb_get_uint8(tvb, offset+MSTI_PORT_IDENTIFIER_PRIORITY) >> 4;

          proto_tree_add_uint(msti_tree, hf_bpdu_msti_bridge_identifier_priority, tvb,
                              offset+MSTI_BRIDGE_IDENTIFIER_PRIORITY, 1,
                              msti_bridge_identifier_priority);
          proto_tree_add_uint(msti_tree, hf_bpdu_msti_port_identifier_priority, tvb,
                              offset+MSTI_PORT_IDENTIFIER_PRIORITY, 1,
                              msti_port_identifier_priority);

          proto_tree_add_item(msti_tree, hf_bpdu_msti_remaining_hops, tvb,
                              offset + MSTI_REMAINING_HOPS, 1, ENC_BIG_ENDIAN);

          msti_length_remaining -= MSTI_MESSAGE_SIZE;
          offset += MSTI_MESSAGE_SIZE;
          break;

        case MSTI_FORMAT_ALTERNATIVE:
          msti_regional_root_mstid = tvb_get_uint8(tvb,  offset+ ALT_MSTI_REGIONAL_ROOT);
          msti_regional_root_priority = (msti_regional_root_mstid &0xf0) << 8;
          msti_regional_root_mstid = ((msti_regional_root_mstid & 0x0f) << 8) +
                                     tvb_get_uint8(tvb,  offset+ ALT_MSTI_REGIONAL_ROOT+1);
          msti_regional_root_mac_str = tvb_ether_to_str(pinfo->pool, tvb, offset+ ALT_MSTI_REGIONAL_ROOT + 2);

          msti_tree = proto_tree_add_subtree_format(mstp_tree, tvb, offset, 16, ett_msti, NULL,
                                          "MSTID %d, Regional Root Identifier %d / %s",
                                          msti_regional_root_mstid,
                                          msti_regional_root_priority,
                                          msti_regional_root_mac_str);

          proto_tree_add_item(msti_tree, hf_bpdu_msti_id, tvb, offset+ALT_MSTI_MSTID, 2, ENC_BIG_ENDIAN);

          /* flags */
          proto_tree_add_bitmask_with_flags(msti_tree, tvb, offset+ALT_MSTI_FLAGS, hf_bpdu_msti_flags, ett_bpdu_flags, rst_flags, ENC_NA, BMT_NO_FALSE|BMT_NO_TFS);

          /* pri, MSTID, Regional root */
          proto_tree_add_item(msti_tree, hf_bpdu_mst_priority, tvb, offset + ALT_MSTI_REGIONAL_ROOT, 1, ENC_BIG_ENDIAN);
          proto_tree_add_item(msti_tree, hf_bpdu_msti_regional_root_id, tvb, offset + ALT_MSTI_REGIONAL_ROOT, 2, ENC_BIG_ENDIAN);
          proto_tree_add_item(msti_tree, hf_bpdu_msti_regional_root_mac, tvb,
                                            offset + ALT_MSTI_REGIONAL_ROOT + 2, 6, ENC_NA);

          proto_tree_add_item(msti_tree, hf_bpdu_msti_internal_root_path_cost, tvb,
                              offset+ALT_MSTI_INTERNAL_ROOT_PATH_COST, 4, ENC_BIG_ENDIAN);

          proto_tree_add_item(msti_tree, hf_bpdu_msti_bridge_id, tvb, offset + ALT_MSTI_BRIDGE_IDENTIFIER, 2, ENC_BIG_ENDIAN);
          proto_tree_add_item(msti_tree, hf_bpdu_msti_bridge_id_priority, tvb, offset + ALT_MSTI_BRIDGE_IDENTIFIER, 2, ENC_BIG_ENDIAN);
          proto_tree_add_item(msti_tree, hf_bpdu_msti_bridge_id_mac, tvb,
                                            offset + ALT_MSTI_BRIDGE_IDENTIFIER + 2, 6, ENC_NA);

          proto_tree_add_item(msti_tree, hf_bpdu_msti_port_id, tvb, offset+ALT_MSTI_PORT_IDENTIFIER, 2, ENC_BIG_ENDIAN);

          proto_tree_add_item(msti_tree, hf_bpdu_msti_remaining_hops, tvb,
                              offset + ALT_MSTI_REMAINING_HOPS, 1, ENC_BIG_ENDIAN);

          msti_length_remaining -= ALT_MSTI_MESSAGE_SIZE;
          offset += ALT_MSTI_MESSAGE_SIZE;
          break;
        }
      }

      if (protocol_version_identifier >= 4 && version_1_length == 0
          && tvb_reported_length(tvb) >= 106) {
        /*
         * OK, it passes the "Protocol Identifier is 0000 0000
         * 0000 0000", "Protocol Version Identifier is 4 or
         * greater", "BPDU Type is 0000 0010", "contains 106 or
         * more octets", and "a Version 1 Length of 0" tests.
         */
        bpdu_version_4_length = BPDU_MSTI + total_msti_length;
        version_4_length = tvb_get_ntohs(tvb, bpdu_version_4_length);

        proto_tree_add_uint(bpdu_tree, hf_bpdu_version_4_length, tvb,
                            bpdu_version_4_length, 2, version_4_length);

        /* version 4 length is 55 or more.
         */
        if (version_4_length >= 53) {
          static int * const agreements[] = {
              &hf_bpdu_flags_agree_num,
              &hf_bpdu_flags_dagree_num,
              &hf_bpdu_flags_agree_valid,
              &hf_bpdu_flags_restricted_role,
              NULL
          };

          spt_tree = proto_tree_add_subtree(bpdu_tree, tvb, bpdu_version_4_length, -1,
              ett_spt, NULL, "SPT Extension");

          spt_offset = (bpdu_version_4_length + 2);

          /* Aux MCID: */

          aux_mcid_tree = proto_tree_add_subtree(spt_tree, tvb, spt_offset,
                                              MCID_LEN, ett_aux_mcid, NULL, "MCID Data");

          proto_tree_add_item(aux_mcid_tree,
                              hf_bpdu_spt_config_format_selector, tvb, spt_offset, 1,
                              ENC_BIG_ENDIAN);
          proto_tree_add_item(aux_mcid_tree, hf_bpdu_spt_config_name, tvb,
                              spt_offset + 1, 32, ENC_ASCII | ENC_NA);

          proto_tree_add_item(aux_mcid_tree,
                              hf_bpdu_spt_config_revision_level, tvb, spt_offset + 33,
                              2, ENC_BIG_ENDIAN);
          proto_tree_add_item(aux_mcid_tree, hf_bpdu_spt_config_digest,
                              tvb, spt_offset + 35, 16, ENC_NA);
          spt_offset += MCID_LEN;

          /* Agreement Data */
          agreement_tree = proto_tree_add_subtree(spt_tree, tvb, spt_offset,
                                               -1, ett_agreement, &agreement_item, "Agreement Data");

          spt_agree_data = tvb_get_uint8(tvb, spt_offset);

          sep = initial_sep;
          proto_item_append_text(agreement_item, "%sAN: %d", sep, (spt_agree_data & 0x03));

          proto_tree_add_bitmask_list_value(agreement_tree, tvb, spt_offset, 1, agreements, spt_agree_data);
          sep = cont_sep;

          proto_item_append_text(agreement_item, "%sDAN: %d", sep, ((spt_agree_data & 0x0C) >> 2));

          if (sep != initial_sep) {
            proto_item_append_text(agreement_item, ")");
          }
          spt_offset += 2;

          proto_tree_add_item(agreement_tree, hf_bpdu_agreement_digest_format_id, tvb, spt_offset, 1, ENC_NA);
          proto_tree_add_item(agreement_tree, hf_bpdu_agreement_digest_format_capabilities, tvb, spt_offset, 1, ENC_NA);
          spt_offset += 1;

          proto_tree_add_item(agreement_tree, hf_bpdu_agreement_digest_convention_id, tvb, spt_offset, 1, ENC_NA);
          proto_tree_add_item(agreement_tree, hf_bpdu_agreement_digest_convention_capabilities, tvb, spt_offset, 1, ENC_NA);
          spt_offset += 1;

          proto_tree_add_item(agreement_tree, hf_bpdu_agreement_digest_edge_count, tvb, spt_offset, 2, ENC_BIG_ENDIAN);
          spt_offset += 10;

          proto_tree_add_item(agreement_tree, hf_bpdu_spt_agreement_digest,
                              tvb, spt_offset, 20, ENC_NA);
          /*spt_offset += 20;*/

          if (protocol_version_identifier == 4) {
            set_actual_length(tvb, (bpdu_version_4_length + version_4_length + 2));
          }
        }
      }
    } else { /* It is RSTP BPDU and may still be Rapid PVST+ */
      if (is_bpdu_pvst)
        dissect_bpdu_pvst_tlv(pinfo, bpdu_tree, tvb);
    }
}

static int
dissect_bpdu_cisco(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
{
  dissect_bpdu(tvb, pinfo, tree, true);
  return tvb_captured_length(tvb);
}

static int
dissect_bpdu_generic(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
{
  dissect_bpdu(tvb, pinfo, tree, false);
  return tvb_captured_length(tvb);
}

void
proto_register_bpdu(void)
{

  static hf_register_info hf[] = {
    { &hf_bpdu_proto_id,
      { "Protocol Identifier",          "stp.protocol",
        FT_UINT16,      BASE_HEX,       VALS(protocol_id_vals), 0x0,
        NULL, HFILL }},
    { &hf_bpdu_version_id,
      { "Protocol Version Identifier",  "stp.version",
        FT_UINT8,       BASE_DEC,       VALS(version_id_vals),  0x0,
        NULL, HFILL }},
    { &hf_bpdu_type,
      { "BPDU Type",                    "stp.type",
        FT_UINT8,       BASE_HEX,       VALS(bpdu_type_vals),   0x0,
        NULL, HFILL }},
    { &hf_bpdu_flags,
      { "BPDU flags",                   "stp.flags",
        FT_UINT8,       BASE_HEX,       NULL,   0x0,
        NULL, HFILL }},
    { &hf_bpdu_flags_tcack,
      { "Topology Change Acknowledgment",  "stp.flags.tcack",
        FT_BOOLEAN,     8,              TFS(&tfs_yes_no),       BPDU_FLAGS_TCACK,
        NULL, HFILL }},
    { &hf_bpdu_flags_agreement,
      { "Agreement",                    "stp.flags.agreement",
        FT_BOOLEAN,     8,              TFS(&tfs_yes_no),       BPDU_FLAGS_AGREEMENT,
        NULL, HFILL }},
    { &hf_bpdu_flags_forwarding,
      { "Forwarding",                   "stp.flags.forwarding",
        FT_BOOLEAN,     8,              TFS(&tfs_yes_no),       BPDU_FLAGS_FORWARDING,
        NULL, HFILL }},
    { &hf_bpdu_flags_learning,
      { "Learning",                     "stp.flags.learning",
        FT_BOOLEAN,     8,              TFS(&tfs_yes_no),       BPDU_FLAGS_LEARNING,
        NULL, HFILL }},
    { &hf_bpdu_flags_port_role,
      { "Port Role",                    "stp.flags.port_role",
        FT_UINT8,       BASE_DEC,       VALS(role_vals),        BPDU_FLAGS_PORT_ROLE_MASK,
        NULL, HFILL }},
    { &hf_bpdu_flags_proposal,
      { "Proposal",                     "stp.flags.proposal",
        FT_BOOLEAN,     8,              TFS(&tfs_yes_no),       BPDU_FLAGS_PROPOSAL,
        NULL, HFILL }},
    { &hf_bpdu_flags_tc,
      { "Topology Change",              "stp.flags.tc",
        FT_BOOLEAN,     8,              TFS(&tfs_yes_no),       BPDU_FLAGS_TC,
        NULL, HFILL }},
    { &hf_bpdu_root_prio,
      { "Root Bridge Priority",         "stp.root.prio",
        FT_UINT16,      BASE_DEC,       NULL,   0x0,
        NULL, HFILL }},
    { &hf_bpdu_root_sys_id_ext,
      { "Root Bridge System ID Extension",      "stp.root.ext",
        FT_UINT16,      BASE_DEC,       NULL,   0x0,
        NULL, HFILL }},
    { &hf_bpdu_root_mac,
      { "Root Bridge System ID",        "stp.root.hw",
        FT_ETHER,       BASE_NONE,      NULL,   0x0,
        NULL, HFILL }},
    { &hf_bpdu_root_cost,
      { "Root Path Cost",               "stp.root.cost",
        FT_UINT32,      BASE_DEC,       NULL,   0x0,
        NULL, HFILL }},
    { &hf_bpdu_bridge_prio,
      { "Bridge Priority",              "stp.bridge.prio",
        FT_UINT16,      BASE_DEC,       NULL,   0x0,
        NULL, HFILL }},
    { &hf_bpdu_bridge_sys_id_ext,
      { "Bridge System ID Extension",   "stp.bridge.ext",
        FT_UINT16,      BASE_DEC,       NULL,   0x0,
        NULL, HFILL }},
    { &hf_bpdu_bridge_mac,
      { "Bridge System ID",             "stp.bridge.hw",
        FT_ETHER,       BASE_NONE,      NULL,   0x0,
        NULL, HFILL }},
    { &hf_bpdu_port_id,
      { "Port identifier",              "stp.port",
        FT_UINT16,      BASE_HEX,       NULL,   0x0,
        NULL, HFILL }},
    { &hf_bpdu_msg_age,
      { "Message Age",                  "stp.msg_age",
        FT_DOUBLE,      BASE_NONE,      NULL,   0x0,
        NULL, HFILL }},
    { &hf_bpdu_max_age,
      { "Max Age",                      "stp.max_age",
        FT_DOUBLE,      BASE_NONE,      NULL,   0x0,
        NULL, HFILL }},
    { &hf_bpdu_hello_time,
      { "Hello Time",                   "stp.hello",
        FT_DOUBLE,      BASE_NONE,      NULL,   0x0,
        NULL, HFILL }},
    { &hf_bpdu_forward_delay,
      { "Forward Delay",                "stp.forward",
        FT_DOUBLE,      BASE_NONE,      NULL,   0x0,
        NULL, HFILL }},
    { &hf_bpdu_version_1_length,
      { "Version 1 Length",             "stp.version_1_length",
        FT_UINT8,       BASE_DEC,       NULL,   0x0,
        NULL, HFILL }},
    { &hf_bpdu_pvst_tlvtype,
      { "Type",                         "stp.pvst.tlvtype",
        FT_UINT16,      BASE_HEX,       VALS(bpdu_pvst_tlv_vals),       0x0,
        NULL, HFILL }},
    { &hf_bpdu_pvst_tlvlength,
      { "Length",                       "stp.pvst.tlvlen",
        FT_UINT16,      BASE_DEC,       NULL,   0x0,
        NULL, HFILL }},
    { &hf_bpdu_pvst_tlv_origvlan,
      { "Originating VLAN",             "stp.pvst.origvlan",
        FT_UINT16,      BASE_DEC,       NULL,   0x0,
        NULL, HFILL }},
    { &hf_bpdu_pvst_tlvvalue,
      { "Value",        "stp.pvst.tlvval",
        FT_BYTES,       BASE_NONE,      NULL,   0x0,
        NULL, HFILL }},
    { &hf_bpdu_version_3_length,
      { "Version 3 Length",             "mstp.version_3_length",
        FT_UINT16,      BASE_DEC,       NULL,   0x0,
        NULL, HFILL }},
    { &hf_bpdu_mst_config_format_selector,
      { "MST Config ID format selector",        "mstp.config_format_selector",
        FT_UINT8,       BASE_DEC,       NULL,   0x0,
        NULL, HFILL }},
    { &hf_bpdu_mst_config_name,
      { "MST Config name",              "mstp.config_name",
        FT_STRINGZPAD,  BASE_NONE,      NULL,   0x0,
        NULL, HFILL }},
    { &hf_bpdu_mst_config_revision_level,
      { "MST Config revision",          "mstp.config_revision_level",
        FT_UINT16,      BASE_DEC,       NULL,   0x0,
        NULL, HFILL }},
    { &hf_bpdu_mst_config_digest,
      { "MST Config digest",            "mstp.config_digest",
        FT_BYTES,       BASE_NONE,      NULL,   0x0,
        NULL, HFILL }},
    { &hf_bpdu_cist_internal_root_path_cost,
      { "CIST Internal Root Path Cost",         "mstp.cist_internal_root_path_cost",
        FT_UINT32,      BASE_DEC,       NULL,   0x0,
        NULL, HFILL }},
    { &hf_bpdu_cist_bridge_prio,
      { "CIST Bridge Priority",         "mstp.cist_bridge.prio",
        FT_UINT16,      BASE_DEC,       NULL,   0x0,
        NULL, HFILL }},
    { &hf_bpdu_cist_bridge_sys_id_ext,
      { "CIST Bridge Identifier System ID Extension",   "mstp.cist_bridge.ext",
        FT_UINT16,      BASE_DEC,       NULL,   0x0,
        NULL, HFILL }},
    { &hf_bpdu_cist_bridge_mac,
      { "CIST Bridge Identifier System ID",     "mstp.cist_bridge.hw",
        FT_ETHER,       BASE_NONE,      NULL,   0x0,
        NULL, HFILL }},
    { &hf_bpdu_cist_remaining_hops,
      { "CIST Remaining hops",          "mstp.cist_remaining_hops",
        FT_UINT8,       BASE_DEC,       NULL,   0x0,
        NULL, HFILL }},
    { &hf_bpdu_msti_flags,
      { "MSTI flags",                   "mstp.msti.flags",
        FT_UINT8,       BASE_HEX,       NULL,   0x0,
        NULL, HFILL }},
    { &hf_bpdu_mst_priority,
      { "Priority",                   "mstp.msti.priority",
        FT_UINT8,       BASE_HEX,       NULL,   0xF0,
        NULL, HFILL }},
    { &hf_bpdu_msti_id_FFF,
      { "MSTID",                   "mstp.msti.msti_id",
        FT_UINT16,       BASE_DEC,       NULL,   0x0FFF,
        NULL, HFILL }},
    { &hf_bpdu_msti_id,
      { "MSTID",                   "mstp.msti.msti_id",
        FT_UINT16,       BASE_DEC,       NULL,   0x0,
        NULL, HFILL }},
    { &hf_bpdu_msti_regional_root_id,
      { "MSTI Regional Root Identifier", "mstp.msti.regional_root_id",
        FT_UINT16,       BASE_DEC,       NULL,   0x0,
        NULL, HFILL }},
    { &hf_bpdu_msti_regional_root_mac,
      { "Regional Root",                "mstp.msti.root.hw",
        FT_ETHER,       BASE_NONE,      NULL,   0x0,
        NULL, HFILL }},
    { &hf_bpdu_msti_internal_root_path_cost,
      { "Internal root path cost",              "mstp.msti.root_cost",
        FT_UINT32,      BASE_DEC,       NULL,   0x0,
        NULL, HFILL }},
    { &hf_bpdu_msti_bridge_id,
      { "MSTI Bridge Identifier",          "mstp.msti.bridge_id",
        FT_UINT16,       BASE_DEC,       NULL,   0x0FFF,
        NULL, HFILL }},
    { &hf_bpdu_msti_bridge_id_priority,
      { "MSTI Bridge Priority",            "mstp.msti.bridge_id_priority",
        FT_UINT16,       BASE_DEC,       NULL,   0xF000,
        NULL, HFILL }},
    { &hf_bpdu_msti_bridge_id_mac,
      { "MSTI Bridge MAC",                "mstp.msti.bridge_id_mac",
        FT_ETHER,       BASE_NONE,      NULL,   0x0,
        NULL, HFILL }},
    { &hf_bpdu_msti_bridge_identifier_priority,
      { "Bridge Identifier Priority",           "mstp.msti.bridge_priority",
        FT_UINT8,       BASE_DEC,       NULL,   0x0,
        NULL, HFILL }},
    { &hf_bpdu_msti_port_identifier_priority,
      { "Port identifier priority",             "mstp.msti.port_priority",
        FT_UINT8,       BASE_DEC,       NULL,   0x0,
        NULL, HFILL }},
    { &hf_bpdu_msti_port_id,
      { "Port identifier",              "mstp.msti.port",
        FT_UINT16,      BASE_HEX,       NULL,   0x0,
        NULL, HFILL }},
    { &hf_bpdu_msti_remaining_hops,
      { "Remaining hops",               "mstp.msti.remaining_hops",
        FT_UINT8,       BASE_DEC,       NULL,   0x0,
        NULL, HFILL }},
        { &hf_bpdu_version_4_length,
           { "Version 4 Length",                "mstp.version_4_length",
        FT_UINT16,      BASE_DEC,       NULL,   0x0,
                NULL, HFILL }},
    { &hf_bpdu_spt_config_format_selector,
          { "SPT Config ID format selector",    "mstp.config_format_selector",
        FT_UINT8, BASE_DEC, NULL, 0x0,
                NULL, HFILL }},
        { &hf_bpdu_spt_config_name,
          {"SPT Config name",   "mstp.config_name",
        FT_STRINGZPAD, BASE_NONE, NULL, 0x0,
            NULL, HFILL } },
        { &hf_bpdu_spt_config_revision_level,
          { "SPT Config revision",    "mstp.config_revision_level",
        FT_UINT16, BASE_DEC, NULL, 0x0,
            NULL, HFILL } },
        { &hf_bpdu_spt_config_digest,
          { "SPT Config digest",    "mstp.config_digest",
        FT_BYTES, BASE_NONE, NULL, 0x0,
            NULL, HFILL } },
        { &hf_bpdu_flags_agree_num,
          { "Agreement Number",    "mstp.agree_flags.agreement_num",
        FT_UINT8, BASE_DEC, NULL, 0x03,
            NULL, HFILL } },
        { &hf_bpdu_flags_dagree_num,
          { "Disagreement Number",    "mstp.agree_flags.dagreement_num",
        FT_UINT8, BASE_DEC, NULL, 0x0C,
            NULL, HFILL } },
        { &hf_bpdu_flags_agree_valid,
          { "Agreement Valid Flag",    "mstp.agree_flags.agreement_valid",
        FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x10,
            NULL, HFILL } },
        { &hf_bpdu_flags_restricted_role,
          { "Restricted Role",    "mstp.agree_flags.rest_role",
        FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x20,
            NULL, HFILL } },
        { &hf_bpdu_spt_agreement_digest,
          { "Agreement Digest",    "mstp.agreement_digest",
        FT_BYTES, BASE_NONE, NULL, 0x0,
            NULL, HFILL } },
        { &hf_bpdu_agreement_digest_format_id,
          { "Agreement Digest Format Id", "bpdu.agreement_digest_format_id",
        FT_UINT8, BASE_DEC, NULL, 0xF0,
            NULL, HFILL }},
        { &hf_bpdu_agreement_digest_format_capabilities,
          { "Agreement Digest Format Capabilities", "bpdu.agreement_digest_format_capabilities",
        FT_UINT8, BASE_DEC, NULL, 0x0F,
            NULL, HFILL }},
        { &hf_bpdu_agreement_digest_convention_id,
          { "Agreement Digest Convention Id", "bpdu.agreement_digest_convention_id",
        FT_UINT8, BASE_DEC, NULL, 0xF0,
            NULL, HFILL }},
        { &hf_bpdu_agreement_digest_convention_capabilities,
          { "Agreement Digest Convention Capabilities", "bpdu.agreement_digest_convention_capabilities",
        FT_UINT8, BASE_DEC, NULL, 0x0F,
            NULL, HFILL }},
        { &hf_bpdu_agreement_digest_edge_count,
          { "Agreement Digest Edge Count", "bpdu.agreement_digest_edge_count",
        FT_UINT16, BASE_DEC, NULL, 0x0,
            NULL, HFILL }},
  };
  static int *ett[] = {
    &ett_bpdu,
    &ett_bpdu_flags,
    &ett_root_id,
    &ett_bridge_id,
    &ett_mstp,
    &ett_msti,
    &ett_cist_bridge_id,
    &ett_spt,
    &ett_aux_mcid,
    &ett_agreement,
    &ett_bpdu_pvst_tlv
  };

  static ei_register_info ei[] = {
  { &ei_pvst_tlv_length_invalid,
    { "stp.pvst.tlvlen.invalid", PI_MALFORMED, PI_ERROR,
      "Indicated length is not valid for this record type", EXPFILL }},

  { &ei_pvst_tlv_origvlan_missing,
    { "stp.pvst.origvlan.missing", PI_MALFORMED, PI_ERROR,
      "Originating (PVID) VLAN TLV is missing or corrupt", EXPFILL }},

  { &ei_pvst_tlv_truncated,
    { "stp.pvst.tlv.truncated", PI_MALFORMED, PI_ERROR,
      "TLV record is truncated prematurely", EXPFILL }},

  { &ei_pvst_tlv_unknown,
    { "stp.pvst.tlv.unknown", PI_UNDECODED, PI_COMMENT,
      "TLV type is unknown", EXPFILL }},

  { &ei_bpdu_version_support,
    { "bpdu.version_support", PI_PROTOCOL, PI_WARN,
      "This version of Wireshark only knows about versions 0, 2, 3 & 4", EXPFILL }},

  { &ei_bpdu_type,
    { "stp.type.unknown", PI_PROTOCOL, PI_WARN,
      "Unknown BPDU type data", EXPFILL }},
  };

  module_t *bpdu_module;
  expert_module_t *expert_bpdu;

  proto_bpdu = proto_register_protocol("Spanning Tree Protocol", "STP", "stp");
  proto_register_field_array(proto_bpdu, hf, array_length(hf));
  proto_register_subtree_array(ett, array_length(ett));

  bpdu_handle = register_dissector("bpdu", dissect_bpdu_generic, proto_bpdu);
  bpdu_cisco_handle = register_dissector("bpdu_cisco", dissect_bpdu_cisco, proto_bpdu);

  expert_bpdu = expert_register_protocol(proto_bpdu);
  expert_register_field_array(expert_bpdu, ei, array_length(ei));

  bpdu_module = prefs_register_protocol(proto_bpdu, NULL);
  prefs_register_bool_preference(bpdu_module, "use_system_id_extension",
    "Use 802.1t System ID Extensions",
    "Whether the BPDU dissector should use 802.1t System ID Extensions when dissecting the Bridge Identifier",
    &bpdu_use_system_id_extensions);
}

void
proto_reg_handoff_bpdu(void)
{
  /*
   * Get handle for the GVRP dissector.
   */
  gvrp_handle = find_dissector("gvrp");

  /*
   * Get handle for the GMRP dissector.
   */
  gmrp_handle = find_dissector_add_dependency("gmrp", proto_bpdu);

  dissector_add_uint("llc.dsap", SAP_BPDU, bpdu_handle);
  dissector_add_uint("chdlc.protocol", CHDLCTYPE_BPDU, bpdu_handle);
  dissector_add_uint("ethertype", ETHERTYPE_STP, bpdu_handle);
  dissector_add_uint("llc.cisco_pid", CISCO_PID_RLQ_REQ, bpdu_handle); /* Cisco's RLQ is just plain STP */
  dissector_add_uint("llc.cisco_pid", CISCO_PID_RLQ_RESP, bpdu_handle); /* Cisco's RLQ is just plain STP */
  dissector_add_uint("llc.cisco_pid", CISCO_PID_VLAN_BRIDGE, bpdu_handle); /* Cisco's VLAN-bridge STP is just plain STP */
  dissector_add_uint("llc.cisco_pid", CISCO_PID_PVSTPP, bpdu_cisco_handle); /* Handle Cisco's (R)PVST+ TLV extensions */
}

/*
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
 *
 * Local Variables:
 * c-basic-offset: 2
 * tab-width: 8
 * indent-tabs-mode: nil
 * End:
 *
 * ex: set shiftwidth=2 tabstop=8 expandtab:
 * :indentSize=2:tabSize=8:noTabs=true:
 */