aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-tipc.c
blob: b2564b3e063d1fe09aba32a788181d70959e5f89 (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
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
/* packet-tipc.c
 * Routines for Transparent Inter Process Communication packet dissection
 *
 * $Id$
 *
 * Copyright 2005, Anders Broman <anders.broman@ericsson.com>
 * 
 * Ethereal - Network traffic analyzer
 * By Gerald Combs <gerald@ethereal.com>
 * 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 * Protocol ref:
 * http://tipc.sourceforge.net/
 */


#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#include <epan/prefs.h>

#include <glib.h>
#include <epan/packet.h>
#include <epan/etypes.h>
#include <epan/emem.h>
#include <epan/reassemble.h>

static int proto_tipc = -1;

static int hf_tipc_msg_fragments = -1;
static int hf_tipc_msg_fragment = -1;
static int hf_tipc_msg_fragment_overlap = -1;
static int hf_tipc_msg_fragment_overlap_conflicts = -1;
static int hf_tipc_msg_fragment_multiple_tails = -1;
static int hf_tipc_msg_fragment_too_long_fragment = -1;
static int hf_tipc_msg_fragment_error = -1;
static int hf_tipc_msg_reassembled_in = -1;

static int hf_tipc_ver = -1;
static int hf_tipc_usr = -1;
static int hf_tipcv2_usr = -1;
static int hf_tipc_hdr_size = -1;
static int hf_tipc_nonsequenced = -1;
static int hf_tipc_destdrop;
static int hf_tipc_unused = -1;
static int hf_tipc_msg_size = -1;
static int hf_tipc_ack_link_lev_seq = -1;
static int hf_tipc_link_lev_seq = -1;
static int hf_tipc_prev_proc = -1;
static int hf_tipc_org_port = -1;
static int hf_tipc_dst_port = -1;
static int hf_tipc_data_msg_type = -1;
static int hf_tipc_err_code = -1;
static int hf_tipc_reroute_cnt = -1;
static int hf_tipc_act_id = -1;
static int hf_tipc_org_proc = -1;
static int hf_tipc_dst_proc = -1;
static int hf_tipc_unused2 = -1;
static int hf_tipc_importance = -1;
static int hf_tipc_link_selector = -1;
static int hf_tipc_msg_cnt = -1;
static int hf_tipc_probe = -1;
static int hf_tipc_bearer_id = -1;
static int hf_tipc_link_selector2 = -1;
static int hf_tipc_remote_addr = -1;
static int hf_tipc_rm_msg_type = -1;
static int hf_tipc_nd_msg_type = -1;
static int hf_tipc_cm_msg_type = -1;
static int hf_tipc_lp_msg_type = -1;
static int hf_tipc_cng_prot_msg_type = -1;
static int hf_tipc_sm_msg_type = -1;
static int hf_tipc_unknown_msg_type = -1;
static int hf_tipc_seq_gap = -1;
static int hf_tipc_nxt_snt_pkg = -1;
static int hf_tipc_unused3 = -1;
static int hf_tipc_bearer_name = -1;

static int hf_tipc_name_dist_type = -1;
static int hf_tipc_name_dist_lower = -1;
static int hf_tipc_name_dist_upper = -1;
static int hf_tipc_name_dist_port = -1;
static int hf_tipc_name_dist_key = -1;

static int hf_tipcv2_data_msg_type = -1;
static int hf_tipcv2_bcast_mtype = -1;
static int hf_tipcv2_link_mtype = -1;
static int hf_tipcv2_connmgr_mtype = -1;
static int hf_tipcv2_route_mtype = -1;
static int hf_tipcv2_changeover_mtype = -1;
static int hf_tipcv2_naming_mtype = -1;
static int hf_tipcv2_fragmenter_mtype = -1;
static int hf_tipcv2_neighbour_mtype = -1;
static int hf_tipcv2_errorcode = -1;
static int hf_tipcv2_rer_cnt = -1;
static int hf_tipcv2_lookup_scope = -1;
static int hf_tipcv2_opt_p = -1;
static int hf_tipcv2_broadcast_ack_no = -1;
static int hf_tipcv2_link_level_ack_no = -1;
static int hf_tipcv2_link_level_seq_no = -1;
static int hf_tipcv2_bcast_seq_no = -1;
static int hf_tipcv2_prev_node = -1;
static int hf_tipcv2_orig_node = -1;
static int hf_tipcv2_dest_node = -1;
static int hf_tipcv2_port_name_type = -1;
static int hf_tipcv2_port_name_instance = -1;

static int hf_tipcv2_bcast_seq_gap = -1;
static int hf_tipcv2_sequence_gap = -1;
static int hf_tipcv2_next_sent_broadcast = -1;
static int hf_tipcv2_fragment_number = -1;
static int hf_tipcv2_next_sent_packet = -1;
static int hf_tipcv2_session_no = -1;
static int hf_tipcv2_link_prio = -1;
static int hf_tipcv2_network_plane = -1;
static int hf_tipcv2_probe = -1;
static int hf_tipcv2_link_tolerance = -1;
static int hf_tipcv2_bearer_instance = -1;
static int hf_tipcv2_bearer_level_orig_addr = -1;
static int hf_tipcv2_cluster_address = -1;
static int hf_tipcv2_bitmap = -1;
static int hf_tipcv2_node_address = -1;
static int hf_tipcv2_destination_domain = -1;
static int hf_tipcv2_network_id = -1;

static gint ett_tipc_msg_fragment = -1;
static gint ett_tipc_msg_fragments = -1;

/* Initialize the subtree pointer */
static gint ett_tipc = -1;
static gint ett_tipc_data = -1;

static gboolean tipc_defragment = TRUE;
static gboolean dissect_tipc_data = FALSE;

static gboolean extra_ethertype = FALSE;

#define ETHERTYPE_TIPC2  0x0807

dissector_handle_t ip_handle;

static proto_tree *top_tree;

static const fragment_items tipc_msg_frag_items = {
	/* Fragment subtrees */
	&ett_tipc_msg_fragment,
	&ett_tipc_msg_fragments,
	/* Fragment fields */
	&hf_tipc_msg_fragments,
	&hf_tipc_msg_fragment,
	&hf_tipc_msg_fragment_overlap,
	&hf_tipc_msg_fragment_overlap_conflicts,
	&hf_tipc_msg_fragment_multiple_tails,
	&hf_tipc_msg_fragment_too_long_fragment,
	&hf_tipc_msg_fragment_error,
	/* Reassembled in field */
	&hf_tipc_msg_reassembled_in,
	/* Tag */
	"TIPC Message fragments"
};


#define MAX_TIPC_ADDRESS_STR_LEN	15
#define TIPCv1 1
#define TIPCv2 2
/* Users */
#define TIPC_DATA_PRIO_0			0
#define TIPC_DATA_PRIO_1			1
#define TIPC_DATA_PRIO_2			2
#define TIPC_DATA_NON_REJECTABLE	3

#define TIPC_ROUTING_MANAGER		8
#define TIPC_NAME_DISTRIBUTOR		9
#define TIPC_CONNECTION_MANAGER		10
#define TIPC_LINK_PROTOCOL			11
#define TIPC_CHANGEOVER_PROTOCOL	13
#define TIPC_SEGMENTATION_MANAGER	14
#define TIPC_MSG_BUNDLER			15

#define TIPC_LINK_PROTOCO_STATE_MSG 0

const value_string tipc_user_values[] = {
	{ 0,	"DATA_PRIO_0"},
	{ 1,	"DATA_PRIO_1"},
	{ 2,	"DATA_PRIO_2"},
	{ 3,	"DATA_NON_REJECTABLE"},
	{ TIPC_ROUTING_MANAGER,			"ROUTING_MANAGER"},
	{ TIPC_NAME_DISTRIBUTOR,		"NAME_DISTRIBUTOR"},
	{ TIPC_CONNECTION_MANAGER,		"CONNECTION_MANAGER"},
	{ TIPC_LINK_PROTOCOL,			"LINK_PROTOCOL"},
	{ TIPC_CHANGEOVER_PROTOCOL,		"CHANGEOVER_PROTOCOL"},
	{ TIPC_SEGMENTATION_MANAGER,	"SEGMENTATION_MANAGER"},
	{ TIPC_MSG_BUNDLER,				"MSG_BUNDLER"},
	{ 0,	NULL},
};

#define TIPCv2_BCAST_PROTOCOL			5
#define TIPCv2_MSG_BUNDLER				6
#define TIPCv2_LINK_PROTOCOL			7
#define TIPCv2_CONN_MANAGER				8
#define TIPCv2_ROUTE_DISTRIBUTOR		9
#define TIPCv2_CHANGEOVER_PROTOCOL		10
#define TIPCv2_NAME_DISTRIBUTOR			11
#define TIPCv2_MSG_FRAGMENTER			12
#define TIPCv2_LINK_CONFIGURATION		13

const value_string tipcv2_user_values[] = {
    { 0,								"Low Priority Payload Data"},
    { 1,								"Normal Priority Payload Data"},
    { 2,								"High Priority Payload Data"},
    { 3,								"Non-Rejectable Payload Data"},
	{ TIPCv2_BCAST_PROTOCOL,			"Broadcast Maintenance Protocol"},
	{ TIPCv2_MSG_BUNDLER,				"Message Bundler Protocol"},
	{ TIPCv2_LINK_PROTOCOL,				"Link State Maintenance Protocol"},
	{ TIPCv2_CONN_MANAGER,				"Connection Manager"},
	{ TIPCv2_ROUTE_DISTRIBUTOR,			"Routing Table Update Protocol"},
	{ TIPCv2_CHANGEOVER_PROTOCOL,		"Link Changeover Protocol"},
	{ TIPCv2_NAME_DISTRIBUTOR,			"Name Table Update Protocol"},
	{ TIPCv2_MSG_FRAGMENTER,			"Message Fragmentation Protocol"},
    { TIPCv2_LINK_CONFIGURATION,		"Link Configuration Protocol"},
	{ 0,	NULL},
};

#define TIPC_CONNECTED_MSG	0
#define TIPC_NAMED_MSG		2
#define TIPC_DIRECT_MSG		3
#define TIPC_OVERLOAD_W_MSG 4

static const value_string tipc_data_msg_type_values[] = {
	{ 0,	"CONN_MSG"},
	{ 2,	"NAMED_MSG"},
	{ 3,	"DIRECT_MSG"},
	{ 4,	"OVERLOAD_W_MSG"},
	{ 0,	NULL},
};

static const value_string tipcv2_data_msg_type_values[] = {
	{ 0,	"Sent on connection (CONN_MSG)"},
	{ 1,	"Logical multicast (MCAST_MSG)"},
	{ 2,	"Port name destination address (NAMED_MSG)"},
	{ 3,	"Port identity destination address (DIRECT_MSG)"},
	{ 0,	NULL},
};
static const value_string tipc_error_code_values[] = {
	{ 0,	"MSG_OK"},
	{ 1,	"NO_PORT_NAME"},
	{ 2,	"NO_REMOTE_PORT"},
	{ 3,	"NO_REMOTE_PROCESSOR"},
	{ 4,	"DEST_OVERLOADED"},
	{ 6,	"NO_CONNECTION"},
	{ 7,	"COMMUNICATION_ERROR"},
	{ 0,	NULL},
};
static const value_string tipcv2_error_code_strings[]={
    { 0           ,"No error (TIPC_OK)"},
    { 1           ,"Destination port name unknown (TIPC_ERR_NO_NAME)"}, 
    { 2           ,"Destination port does not exist (TIPC_ERR_NO_PORT)"},
    { 3           ,"Destination node unavailable (TIPC_ERR_NO_NODE)"},
    { 4           ,"Destination node overloaded (TIPC_ERR_OVERLOAD)"},
    { 5           ,"Connection Shutdown (No error) (TIPC_CONN_SHUTDOWN)"},
    { 6           ,"Communication Error (TIPC_CONN_ERROR)"},
	{ 0,	NULL},
};

static const value_string tipcv2_lookup_scope_strings[]={
    { 0           ,"Zone Scope"},
    { 1           ,"Cluster Scope"},
    { 2           ,"Node Scope"},
	{ 0,	NULL},
};
static const value_string tipc_routing_mgr_msg_type_values[] = {
	{ 0,	"EXT_ROUTING_TABLE"},
	{ 1,	"LOCAL_ROUTING_TABLE"},
	{ 2,	"DP_ROUTING_TABLE"},
	{ 3,	"ROUTE_ADDITION"},
	{ 4,	"ROUTE_REMOVAL"},
	{ 0,	NULL},
};
static const value_string tipc_name_dist_msg_type_values[] = {
	{ 0,	"PUBLICATION"},
	{ 1,	"WITHDRAWAL"},
	{ 0,	NULL},
};
/* CONNECTION_MANAGER */
static const value_string tipc_cm_msg_type_values[] = {
	{ 0,	"CONNECTION_PROBE"},
	{ 1,	"CONNECTION_PROBE_REPLY"},
	{ 0,	NULL},
};
static const value_string tipc_link_prot_msg_type_values[] = {
	{ 10,	"RESET_MSG"},
	{ 11,	"ACTIVATE_MSG"},
	{ 12,	"STATE_MSG"},
	{ 0,	NULL},
};
/* CHANGEOVER_PROTOCOL */
static const value_string tipc_cng_prot_msg_type_values[] = {
	{ 0,	"DUPLICATE_MSG"},
	{ 1,	"ORIGINAL_MSG"},
	{ 2,	"INFO_MSG"},
	{ 0,	NULL},
};
/* SEGMENTATION_MANAGER */
#define TIPC_FIRST_SEGMENT	1
#define TIPC_SEGMENT		2
const value_string tipc_sm_msg_type_values[] = {
	{ 1,	"FIRST_SEGMENT"},
	{ 2,	"SEGMENT"},
	{ 0,	NULL},
};

/* TIPCv2_BCAST_PROTOCOL - Broadcast Maintenance Protocol */
static const value_string tipcv2_bcast_mtype_strings[]={
    { 0           ,"Tunneled, retransmitted broadcast packet (BCAST_MSG)"},
	{ 0,	NULL},
};

/* TIPCv2_MSG_BUNDLER - Message Bundler Protocol */

/* No message types */

/* TIPCv2_LINK_PROTOCOL - Link State Maintenance Protocol */
#define TIPCv2_STATE_MSG 0
#define TIPCv2_RESET_MSG 1

static const value_string tipcv2_link_mtype_strings[]={
    { TIPCv2_STATE_MSG, "STATE_MSG"},
    { TIPCv2_RESET_MSG,	"RESET_MSG"},
    { 2,				"ACTIVATE_MSG"},
	{ 0,	NULL},
};
/* TIPCv2_CONN_MANAGER - Connection Manager */
static const value_string tipcv2_connmgr_mtype_strings[]={
    { 0           ,"CONN_PROBE"},
    { 1           ,"CONN_PROBE_REPLY"},
    { 2           ,"(MSG_ACK)"},
	{ 0,	NULL},
};
/* TIPCv2_ROUTE_DISTRIBUTOR - Routing Table Update Protocol */

#define TIPCv2_EXT_ROUTING_TABLE		0
#define TIPCv2_LOCAL_ROUTING_TABLE		1
#define TIPCv2_SEC_ROUTING_TABLE		2
#define TIPCv2_ROUTE_ADDITION			3
#define TIPCv2_ROUTE_REMOVAL			4
static const value_string tipcv2_route_mtype_strings[]={
    { 0           ,"EXT_ROUTING_TABLE"},
    { 1           ,"LOCAL_ROUTING_TABLE"},
    { 2           ,"SEC_ROUTING_TABLE"},
    { 3           ,"ROUTE_ADDITION"},
    { 4           ,"ROUTE_REMOVAL"},
	{ 0,	NULL},
};
/* TIPCv2_CHANGEOVER_PROTOCOL - Link Changeover Protocol */
static const value_string tipcv2_changeover_mtype_strings[]={
    { 0           ,"DUPLICATE_MSG"},
    { 1           ,"ORIGINAL_MSG"},
	{ 0,	NULL},
};
/* TIPCv2_NAME_DISTRIBUTOR - Name Table Update Protocol */
static const value_string tipcv2_naming_mtype_strings[]={
    { 0           ,"PUBLICATION"},
    { 1           ,"WITHDRAWAL"},
	{ 0,	NULL},
};
/* TIPCv2_MSG_FRAGMENTER - Message Fragmentation Protocol" */
static const value_string tipcv2_fragmenter_mtype_strings[]={
    { 0           ,"FIRST_FRAGMENT"},
    { 1           ,"FRAGMENT"},
    { 2           ,"LAST_FRAGMENT"},
	{ 0,	NULL},
};

/* TIPCv2_LINK_CONFIGURATION - Link Configuration Protocol
 * 4.3.9 Neighbour Detection Protocol
 */

static const value_string tipcv2_neighbour_mtype_strings[]={
    { 0           ,"Link_Request"},
    { 1           ,"Link_Response"},
	{ 0,	NULL},
};


static const value_string tipcv2_networkplane_strings[]={
    { 0           ,"A"},
    { 1           ,"B"},
    { 2           ,"C"},
    { 3           ,"D"},
    { 4           ,"E"},
    { 5           ,"F"},
	{ 0,	NULL},
};


static void dissect_tipc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);


static GHashTable *tipc_msg_fragment_table = NULL;
static GHashTable *tipc_msg_reassembled_table = NULL;


static void
tipc_defragment_init(void)
{
	fragment_table_init (&tipc_msg_fragment_table);
	reassembled_table_init(&tipc_msg_reassembled_table);
}


static gchar*
tipc_addr_to_str(guint tipc_address)
{
	guint8 zone;
	guint16 subnetwork;
	guint16 processor;
	gchar *buff;

	buff=ep_alloc(MAX_TIPC_ADDRESS_STR_LEN);

	processor = tipc_address & 0x0fff;

	tipc_address = tipc_address >> 12;
	subnetwork = tipc_address & 0x0fff;

	tipc_address = tipc_address >> 12;
	zone = tipc_address & 0xff;

	g_snprintf(buff,MAX_TIPC_ADDRESS_STR_LEN,"%u.%u.%u",zone,subnetwork,processor);

	return buff;
}

/*
All name distributor messages have a data part containing one or more table elements with
the following five-word structure:
struct DistributionItem{
	unsigned int type; / Published port name type /
	unsigned int lower; / Lower bound of published sequence /
	unsigned int upper; / Upper bound of published sequence /
	unsigned int port; / Random number part of port identity /
	unsigned int key; / Use for verification at withdrawal /
};
*/
static void
dissect_tipc_name_dist_data(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree){
	int offset = 0;
 
	while ( tvb_reported_length_remaining(tvb,offset) > 0){
		 proto_tree_add_item(tree, hf_tipc_name_dist_type, tvb, offset, 4, FALSE);
		 offset = offset+4;
		 proto_tree_add_item(tree, hf_tipc_name_dist_lower, tvb, offset, 4, FALSE);
		 offset = offset+4;
		 proto_tree_add_item(tree, hf_tipc_name_dist_upper, tvb, offset, 4, FALSE);
		 offset = offset+4;
		 proto_tree_add_item(tree, hf_tipc_name_dist_port, tvb, offset, 4, FALSE);
		 offset = offset+4;
		 proto_tree_add_item(tree, hf_tipc_name_dist_key, tvb, offset, 4, FALSE);
		 offset = offset+4;
	}
}

/* Set message type in COL INFO and return type of message ( data or Internal message type */
static gboolean
tipc_v2_set_col_msgtype(packet_info *pinfo, guint8 user,guint8 msg_type){

	gboolean datatype_hdr = FALSE;

	switch (user){
		case TIPC_DATA_PRIO_0: 	
		case TIPC_DATA_PRIO_1:
		case TIPC_DATA_PRIO_2:
		case TIPC_DATA_NON_REJECTABLE:
			/* 
			 * src and dest address will be found at different location depending on User ad hdr_size
			 */
			datatype_hdr = TRUE;
			if (check_col(pinfo->cinfo, COL_INFO))
				col_append_fstr(pinfo->cinfo, COL_INFO, "%s(%u) ", val_to_str(msg_type, tipcv2_data_msg_type_values, "unknown"),msg_type);
			break;
		case TIPCv2_BCAST_PROTOCOL:
			if (check_col(pinfo->cinfo, COL_INFO))
				col_append_fstr(pinfo->cinfo, COL_INFO, "%s(%u) ", val_to_str(msg_type, tipcv2_bcast_mtype_strings, "unknown"),msg_type);
			break;
		case TIPCv2_MSG_BUNDLER:
			/* No message types */
			break;
		case TIPCv2_LINK_PROTOCOL:
			if (check_col(pinfo->cinfo, COL_INFO))
				col_append_fstr(pinfo->cinfo, COL_INFO, "%s(%u) ", val_to_str(msg_type, tipcv2_link_mtype_strings, "unknown"),msg_type);
			break;
		case TIPCv2_CONN_MANAGER:
			if (check_col(pinfo->cinfo, COL_INFO))
				col_append_fstr(pinfo->cinfo, COL_INFO, "%s(%u) ", val_to_str(msg_type, tipcv2_connmgr_mtype_strings, "unknown"),msg_type);
			break;
		case TIPCv2_ROUTE_DISTRIBUTOR:
			if (check_col(pinfo->cinfo, COL_INFO))
				col_append_fstr(pinfo->cinfo, COL_INFO, "%s(%u) ", val_to_str(msg_type, tipcv2_route_mtype_strings, "unknown"),msg_type);
			break;
		case TIPCv2_CHANGEOVER_PROTOCOL:
			if (check_col(pinfo->cinfo, COL_INFO))
				col_append_fstr(pinfo->cinfo, COL_INFO, "%s(%u) ", val_to_str(msg_type, tipcv2_changeover_mtype_strings, "unknown"),msg_type);
			break;
		case TIPCv2_NAME_DISTRIBUTOR:
			if (check_col(pinfo->cinfo, COL_INFO))
				col_append_fstr(pinfo->cinfo, COL_INFO, "%s(%u) ", val_to_str(msg_type, tipcv2_naming_mtype_strings, "unknown"),msg_type);
			break;
		case TIPCv2_MSG_FRAGMENTER:
			if (check_col(pinfo->cinfo, COL_INFO))
				col_append_fstr(pinfo->cinfo, COL_INFO, "%s(%u) ", val_to_str(msg_type, tipcv2_fragmenter_mtype_strings, "unknown"),msg_type);
			break;
		case TIPCv2_LINK_CONFIGURATION:
			if (check_col(pinfo->cinfo, COL_INFO))
				col_append_fstr(pinfo->cinfo, COL_INFO, "%s(%u) ", val_to_str(msg_type, tipcv2_neighbour_mtype_strings, "unknown"),msg_type);
			break;
		default:
			break;		 
	}
	return datatype_hdr;
}

/* Set message type in COL INFO and return type of message ( data or Internal message type */
static gboolean
tipc_v1_set_col_msgtype(packet_info *pinfo, guint8 user,guint8 msg_type){

	gboolean datatype_hdr = FALSE;

	switch (user){
		case TIPC_DATA_PRIO_0: 	
		case TIPC_DATA_PRIO_1:
		case TIPC_DATA_PRIO_2:
		case TIPC_DATA_NON_REJECTABLE:
			/* 
			 * src and dest address will be found at different location depending on User ad hdr_size
			 */
			datatype_hdr = TRUE;
			if (check_col(pinfo->cinfo, COL_INFO))
				col_append_fstr(pinfo->cinfo, COL_INFO, "%s(%u) ", val_to_str(msg_type, tipc_data_msg_type_values, "unknown"),msg_type);
			break;
		case TIPC_NAME_DISTRIBUTOR:
			if (check_col(pinfo->cinfo, COL_INFO))
				col_append_fstr(pinfo->cinfo, COL_INFO, "%s(%u) ", val_to_str(msg_type, tipc_name_dist_msg_type_values, "unknown"),msg_type);
			break;
		case TIPC_CONNECTION_MANAGER:
			if (check_col(pinfo->cinfo, COL_INFO))
				col_append_fstr(pinfo->cinfo, COL_INFO, "%s(%u) ", val_to_str(msg_type, tipc_cm_msg_type_values, "unknown"),msg_type);
			break;
		case TIPC_ROUTING_MANAGER:
			if (check_col(pinfo->cinfo, COL_INFO))
				col_append_fstr(pinfo->cinfo, COL_INFO, "%s(%u) ", val_to_str(msg_type, tipc_routing_mgr_msg_type_values, "unknown"),msg_type);
			break;
		case TIPC_LINK_PROTOCOL:
			if (check_col(pinfo->cinfo, COL_INFO))
				col_append_fstr(pinfo->cinfo, COL_INFO, "%s(%u) ", val_to_str(msg_type, tipc_link_prot_msg_type_values, "unknown"),msg_type);
			break;
		case TIPC_CHANGEOVER_PROTOCOL:
			if (check_col(pinfo->cinfo, COL_INFO))
				col_append_fstr(pinfo->cinfo, COL_INFO, "%s(%u) ", val_to_str(msg_type, tipc_cng_prot_msg_type_values, "unknown"),msg_type);
			break;
		case TIPC_SEGMENTATION_MANAGER:
			if (check_col(pinfo->cinfo, COL_INFO))
				col_append_fstr(pinfo->cinfo, COL_INFO, "%s(%u) ", val_to_str(msg_type, tipc_sm_msg_type_values, "unknown"),msg_type);
			break;
		case TIPC_MSG_BUNDLER:
			break;
		default:
			break;		 
	}
	return datatype_hdr;
}


/*
	  Version 2(draft-maloy-tipc-01.txt):

4.2.1 Internal Message Header Format



       0                   1                   2                   3
       0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   w0:|vers |msg usr|hdr sz |n|resrv|            packet size          |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   w1:|m typ|bcstsqgap| sequence gap  |       broadcast ack no        |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   w2:|        link level ack no      |   broadcast/link level seq no |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   w3:|                       previous node                           |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   w4:|  next sent broadcast/fragm no | next sent pkt/ fragm msg no   |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   w5:|          session no           | res |r|berid|link prio|netpl|p|
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   w6:|                      originating node                         |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   w7:|                      destination node                         |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   w8:|                  transport sequence number                    |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   w9:|          msg count            |       link tolerance          |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      \                                                               \
      /                     User Specific Data                        /
      \                                                               \
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

  */
static void
dissect_tipc_v2_internal_msg(tvbuff_t *tipc_tvb, packet_info *pinfo, proto_tree *tipc_tree, int offset, guint8 user, guint32 msg_size)
{

	guint32 dword;
	gchar *addr_str_ptr;
	guint8 message_type;
	tvbuff_t *data_tvb;

	dword = tvb_get_ntohl(tipc_tvb,offset+8);
	addr_str_ptr = tipc_addr_to_str(dword);
	message_type = tvb_get_guint8(tipc_tvb,offset) >>1;  

	switch (user){
		case TIPCv2_BCAST_PROTOCOL:
			/* W1 */
			proto_tree_add_item(tipc_tree, hf_tipcv2_bcast_mtype, tipc_tvb, offset, 4, FALSE);
			offset = offset + 4;
			/* W2 */
			offset = offset + 4;
			/* W3 */
			proto_tree_add_string(tipc_tree, hf_tipcv2_prev_node, tipc_tvb, offset, 4,	addr_str_ptr);
			offset = offset + 4;
			/* W4 */
			offset = offset + 4;
			/* W5 */
			offset = offset + 4;
			/* W6 */
			proto_tree_add_text(tipc_tree, tipc_tvb, offset, 4,"Word 6 Unused for this user");
			offset = offset + 4;
			/* W7 */
			proto_tree_add_text(tipc_tree, tipc_tvb, offset, 4,"Word 7 Unused for this user");
			offset = offset + 4;
			break;
		case TIPCv2_MSG_BUNDLER:
			/* W1 */
			/* No message types */
			offset = offset + 4;
			/* W2 */
			offset = offset + 4;
			/* W3 */
			proto_tree_add_string(tipc_tree, hf_tipcv2_prev_node, tipc_tvb, offset, 4,	addr_str_ptr);
			offset = offset + 4;
			/* W5 */
			offset = offset + 4;
			/* W6 */
			proto_tree_add_text(tipc_tree, tipc_tvb, offset, 4,"Word 6 Unused for this user");
			offset = offset + 4;
			/* W7 */
			proto_tree_add_text(tipc_tree, tipc_tvb, offset, 4,"Word 7 Unused for this user");
			offset = offset + 4;
			/* W8 */
			proto_tree_add_text(tipc_tree, tipc_tvb, offset, 4,"Word 8 Unused for this user");
			offset = offset + 4;
			/* W9 */
			/* Message Count: 16 bits. */
			offset = offset + 4;
			break;
		case TIPCv2_LINK_PROTOCOL:
			/* W1 */
			proto_tree_add_item(tipc_tree, hf_tipcv2_link_mtype, tipc_tvb, offset, 4, FALSE);
			/*  Broadcast Sequence Gap: 5 bits. */
			proto_tree_add_item(tipc_tree, hf_tipcv2_bcast_seq_gap, tipc_tvb, offset, 4, FALSE);
			/* Sequence Gap:  8 bits. */
			proto_tree_add_item(tipc_tree, hf_tipcv2_sequence_gap, tipc_tvb, offset, 4, FALSE);
			offset = offset + 4;
			/* W2 */
			offset = offset + 4;
			/* W3 */
			proto_tree_add_string(tipc_tree, hf_tipcv2_prev_node, tipc_tvb, offset, 4,	addr_str_ptr);
			offset = offset + 4;
			/* W4 */
			/* Next Sent Broadcast: 16 bits */
			proto_tree_add_item(tipc_tree, hf_tipcv2_next_sent_broadcast, tipc_tvb, offset, 4, FALSE);
			/* Next Sent Packet:  16 bits. */
			proto_tree_add_item(tipc_tree, hf_tipcv2_next_sent_packet, tipc_tvb, offset, 4, FALSE);
			offset = offset + 4;
			/* W5 */
			/* Session Number: 16 bits. */
			proto_tree_add_item(tipc_tree, hf_tipcv2_session_no, tipc_tvb, offset, 4, FALSE);
			/* Reserved: 3 bits Must be set to zero. */
			/* Redundant Link: 1 bit */
			/* Bearer Identity: 3 bits */
			/* Link Priority: 5 bits. */
			proto_tree_add_item(tipc_tree, hf_tipcv2_link_prio, tipc_tvb, offset, 4, FALSE);
			/* Network Plane: 3 bits. */
			proto_tree_add_item(tipc_tree, hf_tipcv2_network_plane, tipc_tvb, offset, 4, FALSE);
			/* Probe: 1 bit. */
			proto_tree_add_item(tipc_tree, hf_tipcv2_probe, tipc_tvb, offset, 4, FALSE);
			offset = offset + 4;

			/* W6 */
			proto_tree_add_text(tipc_tree, tipc_tvb, offset, 4,"Word 6 Unused for this user");
			offset = offset + 4;
			/* W7 */
			proto_tree_add_text(tipc_tree, tipc_tvb, offset, 4,"Word 7 Unused for this user");
			offset = offset + 4;
			/* W8 */
			proto_tree_add_text(tipc_tree, tipc_tvb, offset, 4,"Word 8 Unused for this user");
			offset = offset + 4;
			/* W9 */
			/* Link Tolerance:  16 bits */
			proto_tree_add_item(tipc_tree, hf_tipcv2_link_tolerance, tipc_tvb, offset, 4, FALSE);
			offset = offset + 4;
			
			if (message_type == TIPCv2_RESET_MSG)
				proto_tree_add_item(tipc_tree, hf_tipcv2_bearer_instance, tipc_tvb, offset, -1, FALSE);
			break;
		case TIPCv2_CONN_MANAGER:
			/* W1 */
			proto_tree_add_item(tipc_tree, hf_tipcv2_connmgr_mtype, tipc_tvb, offset, 4, FALSE);
			offset = offset + 4;
			/* W2 */
			offset = offset + 4;
			/* W3 */
			proto_tree_add_string(tipc_tree, hf_tipcv2_prev_node, tipc_tvb, offset, 4,	addr_str_ptr);
			offset = offset + 4;
			/* W4 */
			offset = offset + 4;
			/* W5 */
			offset = offset + 4;
			/* W6 */
			proto_tree_add_text(tipc_tree, tipc_tvb, offset, 4,"Word 6 Unused for this user");
			offset = offset + 4;
			/* W7 */
			proto_tree_add_text(tipc_tree, tipc_tvb, offset, 4,"Word 7 Unused for this user");
			break;
		case TIPCv2_ROUTE_DISTRIBUTOR:
			/* W1 */
			proto_tree_add_item(tipc_tree, hf_tipcv2_route_mtype, tipc_tvb, offset, 4, FALSE);
			offset = offset + 4;
			/* W2 */
			offset = offset + 4;
			/* W3 */
			proto_tree_add_string(tipc_tree, hf_tipcv2_prev_node, tipc_tvb, offset, 4,	addr_str_ptr);
			offset = offset + 4;
			/* W4 */
			offset = offset + 4;
			/* W5 */
			offset = offset + 4;
			/* W6 */
			proto_tree_add_text(tipc_tree, tipc_tvb, offset, 4,"Word 6 Unused for this user");
			offset = offset + 4;
			/* W7 */
			proto_tree_add_text(tipc_tree, tipc_tvb, offset, 4,"Word 7 Unused for this user");
			offset = offset + 4;
			/* W8 */
			offset = offset + 4;
			/* W9 */
			offset = offset + 4;
			/* W10 */
			switch (message_type){
			case TIPCv2_EXT_ROUTING_TABLE:		/* 0  */
			case TIPCv2_LOCAL_ROUTING_TABLE:	/* 1  */
			case TIPCv2_SEC_ROUTING_TABLE:		/* 2  */
				/* Cluster Address */
				dword = tvb_get_ntohl(tipc_tvb,offset+8);
				addr_str_ptr = tipc_addr_to_str(dword);
				proto_tree_add_string(tipc_tree, hf_tipcv2_cluster_address, tipc_tvb, offset, 4,	addr_str_ptr);
				offset = offset + 4;
				/* bitmap */
				proto_tree_add_item(tipc_tree, hf_tipcv2_bitmap, tipc_tvb, offset, -1, FALSE);
				break;
			case TIPCv2_ROUTE_ADDITION:			/* 3  */
			case TIPCv2_ROUTE_REMOVAL:			/* 4  */
				/* Node Address */
				dword = tvb_get_ntohl(tipc_tvb,offset+8);
				addr_str_ptr = tipc_addr_to_str(dword);
				proto_tree_add_string(tipc_tree, hf_tipcv2_node_address, tipc_tvb, offset, 4,	addr_str_ptr);
				offset = offset + 4;
			default:
				break;
			}
			break;
		case TIPCv2_CHANGEOVER_PROTOCOL:
			/* W1 */
			proto_tree_add_item(tipc_tree, hf_tipcv2_changeover_mtype, tipc_tvb, offset, 4, FALSE);
			offset = offset + 4;
			/* W2 */
			offset = offset + 4;
			/* W3 */
			proto_tree_add_string(tipc_tree, hf_tipcv2_prev_node, tipc_tvb, offset, 4,	addr_str_ptr);
			offset = offset + 4;
			/* W4 */
			offset = offset + 4;
			/* W5 */
			offset = offset + 4;
			/* W6 */
			proto_tree_add_text(tipc_tree, tipc_tvb, offset, 4,"Word 6 Unused for this user");
			offset = offset + 4;
			/* W7 */
			proto_tree_add_text(tipc_tree, tipc_tvb, offset, 4,"Word 7 Unused for this user");
			offset = offset + 4;
			/* W8 */
			offset = offset + 4;
			/* W9 */
			/* Message Count: 16 bits. */
			offset = offset + 4;
			break;
		case TIPCv2_NAME_DISTRIBUTOR:
			/* W1 */
			proto_tree_add_item(tipc_tree, hf_tipcv2_naming_mtype, tipc_tvb, offset, 4, FALSE);
			offset = offset + 4;
			/* W2 */
			offset = offset + 4;
			/* W3 */
			proto_tree_add_string(tipc_tree, hf_tipcv2_prev_node, tipc_tvb, offset, 4,	addr_str_ptr);
			offset = offset + 4;
			/* W4 */
			offset = offset + 4;
			/* W5 */
			offset = offset + 4;
			/* W6 */
			/* Originating Node: 32 bits. */
			dword = tvb_get_ntohl(tipc_tvb,offset);
			addr_str_ptr = tipc_addr_to_str(dword);
			proto_tree_add_string(tipc_tree, hf_tipcv2_dest_node, tipc_tvb, offset, 4,	addr_str_ptr);
			offset = offset + 4;
			/* W7 */
			/* Destination Node: 32 bits.  */
			dword = tvb_get_ntohl(tipc_tvb,offset);
			addr_str_ptr = tipc_addr_to_str(dword);
			proto_tree_add_string(tipc_tree, hf_tipcv2_orig_node, tipc_tvb, offset, 4,	addr_str_ptr);
			offset = offset + 4;
			/* W8 */
			/* Transport Level Sequence Number: 32 bits */
			offset = offset + 4;
			/* W9 */
			/* Message Count: 16 bits. */
			offset = offset + 4;
			/* W10 */
			data_tvb = tvb_new_subset(tipc_tvb, offset, -1, -1);
			dissect_tipc_name_dist_data(data_tvb, pinfo, tipc_tree);
			break;
		case TIPCv2_MSG_FRAGMENTER:
			/* W1 */
			proto_tree_add_item(tipc_tree, hf_tipcv2_fragmenter_mtype, tipc_tvb, offset, 4, FALSE);
			/* Last 16 bits */
			proto_tree_add_item(tipc_tree, hf_tipcv2_fragment_number, tipc_tvb, offset, 4, FALSE);
			offset = offset + 4;
			/* W2 */
			offset = offset + 4;
			/* W3 */
			proto_tree_add_string(tipc_tree, hf_tipcv2_prev_node, tipc_tvb, offset, 4,	addr_str_ptr);
			offset = offset + 4;
			/* W4 */
			/* Fragment Number: 16 Bits. */
			/* Fragment (msg?) Number: 16 bits */
			offset = offset + 4;
			/* W5 */
			offset = offset + 4;
			/* W6 */
			proto_tree_add_text(tipc_tree, tipc_tvb, offset, 4,"Word 6 Unused for this user");
			offset = offset + 4;
			/* W7 */
			proto_tree_add_text(tipc_tree, tipc_tvb, offset, 4,"Word 7 Unused for this user");
			offset = offset + 4;
			break;
		case TIPCv2_LINK_CONFIGURATION:
/*
The protocol for neighbour detection
   uses a special message format, with the following generic structure:

        0                   1                   2                   3
       0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   w0:|vers |msg usr|hdr sz |n|resrv|            packet size          |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   w1:|m typ|0| requested links       |       broadcast ack no        |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   w2:|                      destination domain                       |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   w3:|                       previous node                           |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   w4:|                      network identity                         |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   w5:|                                                               |
      +-+-+-+-+-+-+-                                    +-+-+-+-+-+-+-+
   w6:|                                                               |
      +-+-+-+-+-+-+-  bearer level originating address  +-+-+-+-+-+-+-+
   w7:|                                                               |
      +-+-+-+-+-+-+-                                    +-+-+-+-+-+-+-+
   w8:|                                                               |
      +-+-+-+-+-+-+-                                    +-+-+-+-+-+-+-+
   w9:|                                                               |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      \                                                               \
      /                 vendor specific data  (optional)              /
      \                                                               \
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
	  */
			/* W1 */
			proto_tree_add_item(tipc_tree, hf_tipcv2_neighbour_mtype, tipc_tvb, offset, 4, FALSE);
			/* Requested Links (12 bits) */
			proto_tree_add_item(tipc_tree, hf_tipcv2_broadcast_ack_no , tipc_tvb, offset, 4, FALSE);
			offset = offset + 4;
			/* W2 */
			/* Destination Domain */
			dword = tvb_get_ntohl(tipc_tvb,offset);
			addr_str_ptr = tipc_addr_to_str(dword);
			proto_tree_add_string(tipc_tree, hf_tipcv2_destination_domain, tipc_tvb, offset, 4,	addr_str_ptr);
			offset = offset + 4;
			/* W3 */
			dword = tvb_get_ntohl(tipc_tvb,offset);
			addr_str_ptr = tipc_addr_to_str(dword);
			proto_tree_add_string(tipc_tree, hf_tipcv2_prev_node, tipc_tvb, offset, 4,	addr_str_ptr);
			offset = offset + 4;
			/* W4 */
			/* Network Identity: */
			dword = tvb_get_ntohl(tipc_tvb,offset);
			addr_str_ptr = tipc_addr_to_str(dword);
			proto_tree_add_string(tipc_tree, hf_tipcv2_network_id, tipc_tvb, offset, 4,	addr_str_ptr);
			offset = offset + 4;
			/* W5 - W9 Bearer Level Originating Address: */
			proto_tree_add_item(tipc_tree, hf_tipcv2_bearer_level_orig_addr, tipc_tvb, offset, 20, FALSE);
			offset = offset + 20;
			/*
			proto_tree_add_text(tipc_tree, tipc_tvb, offset, -1,"Vendor specific data");
			*/
			break;
		default:
			break;		 
	}

}

/* Version 2 Header (draft-maloy-tipc-01.txt):
4.1.1 Payload Message Header Format


       0                   1                   2                   3
       0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   w0:|vers | user  |hdr sz |n|d|rsv|          message size           |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   w1:|mstyp| error |rer cnt|lsc|opt p|      broadcast ack no         |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   w2:|        link level ack no      |   broadcast/link level seq no |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   w3:|                       previous node                           |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   w4:|                      originating port                         |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   w5:|                      destination port                         |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   w6:|                      originating node                         |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   w7:|                      destination node                         |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   w8:|             name type / transport sequence number             |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   w9:|              name instance/multicast lower bound              |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   wA:|                    multicast upper bound                      |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      /                                                               /
      \                           options                             \
      /                                                               /
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

  */

static void
dissect_tipc_v2(tvbuff_t *tipc_tvb, packet_info *pinfo, proto_tree *tipc_tree, int offset, guint8 user, guint32 msg_size, guint8 hdr_size,  gboolean datatype_hdr)
{
	guint32 dword;
	gchar *addr_str_ptr;
	guint8 opt_p;
	/* The unit used is 32 bit words */
	guint8 orig_hdr_size;

	orig_hdr_size = hdr_size;

	/*
	 * Word 0
	 */
	/* Version: 3 bits */
	proto_tree_add_item(tipc_tree, hf_tipc_ver, tipc_tvb, offset, 4, FALSE);
	/* User: 4 bits */
	proto_tree_add_item(tipc_tree, hf_tipcv2_usr, tipc_tvb, offset, 4, FALSE);
	/* Header Size: 4 bits */
	proto_tree_add_item(tipc_tree, hf_tipc_hdr_size, tipc_tvb, offset, 4, FALSE);
	/* Non-sequenced: 1 bit */
	proto_tree_add_item(tipc_tree,hf_tipc_nonsequenced, tipc_tvb,offset,4, FALSE);
	if (datatype_hdr)
		/* Drop: 1 bit */
		proto_tree_add_item(tipc_tree,hf_tipc_destdrop, tipc_tvb,offset,4, FALSE);
	/* Reserved: 2 bits */

	/* Message Size: 17 bits */
	proto_tree_add_item(tipc_tree, hf_tipc_msg_size, tipc_tvb, offset, 4, FALSE);
	offset = offset + 4;
	
	if (!datatype_hdr){
		dissect_tipc_v2_internal_msg(tipc_tvb, pinfo, tipc_tree, offset, user, msg_size);
		return;
	}

	/* Word 1 */ 
	/* Message Type: 3 bits */
	proto_tree_add_item(tipc_tree, hf_tipcv2_data_msg_type , tipc_tvb, offset, 4, FALSE);
	/* Error Code: 4 bits */
	proto_tree_add_item(tipc_tree, hf_tipcv2_errorcode , tipc_tvb, offset, 4, FALSE);
	/* Reroute Counter: 4 bits */
	proto_tree_add_item(tipc_tree, hf_tipcv2_rer_cnt , tipc_tvb, offset, 4, FALSE);
	/* Lookup Scope: 2 bits */
	proto_tree_add_item(tipc_tree, hf_tipcv2_lookup_scope , tipc_tvb, offset, 4, FALSE);

	/* Options Position: 3 bits */
	opt_p = tvb_get_guint8(tipc_tvb, offset+1) & 0x7;
	proto_tree_add_item(tipc_tree, hf_tipcv2_opt_p , tipc_tvb, offset, 4, FALSE);
	if (opt_p != 0){
		hdr_size = hdr_size - (opt_p << 2);	
	}
	/* Broadcast Acknowledge Number: 16 bits */
	proto_tree_add_item(tipc_tree, hf_tipcv2_broadcast_ack_no , tipc_tvb, offset, 4, FALSE);
	offset = offset + 4;

	/* W2 */	
	/* Link Level Acknowledge Number: 16 bits */
	proto_tree_add_item(tipc_tree, hf_tipcv2_link_level_ack_no , tipc_tvb, offset, 4, FALSE);
	/* broadcast/link level seq no */
	proto_tree_add_item(tipc_tree, hf_tipcv2_link_level_seq_no , tipc_tvb, offset, 4, FALSE);
	offset = offset + 4;
	/* W3 previous node */
	dword = tvb_get_ntohl(tipc_tvb,offset);
	addr_str_ptr = tipc_addr_to_str(dword);
	proto_tree_add_string(tipc_tree, hf_tipcv2_prev_node, tipc_tvb, offset, 4,	addr_str_ptr);
	offset = offset + 4;

	/* W4 Originating Port: 32 bits */
	proto_tree_add_item(tipc_tree, hf_tipc_org_port , tipc_tvb, offset, 4, FALSE);
	offset = offset + 4;

	/* W5 Destination Port: 32 bits */
	proto_tree_add_item(tipc_tree, hf_tipc_dst_port , tipc_tvb, offset, 4, FALSE);
	offset = offset + 4;
	if (hdr_size > 6 ){

		/* W6 Originating Node: 32 bits */
		dword = tvb_get_ntohl(tipc_tvb,offset);
		addr_str_ptr = tipc_addr_to_str(dword);
		proto_tree_add_string(tipc_tree, hf_tipcv2_orig_node, tipc_tvb, offset, 4,	addr_str_ptr);
		offset = offset + 4;
		/* W7 Destination Node: 32 bits */
		dword = tvb_get_ntohl(tipc_tvb,offset);
		addr_str_ptr = tipc_addr_to_str(dword);
		proto_tree_add_string(tipc_tree, hf_tipcv2_dest_node, tipc_tvb, offset, 4,	addr_str_ptr);
		offset = offset + 4;
		if (hdr_size > 8 ){
			/* W8 name type / transport sequence number */
			/* Transport Level Sequence Number: 32 bits */
			/* Port Name Type: 32 bits */
			proto_tree_add_item(tipc_tree, hf_tipcv2_port_name_type , tipc_tvb, offset, 4, FALSE);
			offset = offset + 4;
			
			if (hdr_size > 9 ){
				/* W9 name instance/multicast lower bound  */
				/*  Port Name Instance: 32 bits */
				proto_tree_add_item(tipc_tree, hf_tipcv2_port_name_instance , tipc_tvb, offset, 4, FALSE);
				/*  Port Name Sequence Lower: 32 bits */
				offset = offset + 4;
				if (hdr_size > 10 ){

					/* W10 multicast upper bound */
					/* Port Name Sequence Upper: 32 bits */
					offset = offset + 4;
				}						
			}
		}
	}
	/* Options */
	if (opt_p != 0){
		proto_tree_add_text(tipc_tree, tipc_tvb, offset,(opt_p >> 2),"Options");
		offset = offset + (opt_p << 2);
	}
	/* TIPCv2 data */
	if ( msg_size > (orig_hdr_size<<2))
		proto_tree_add_text(tipc_tree, tipc_tvb, offset, -1,"TIPCv2 data");

}

/*  From message.h (http://cvs.sourceforge.net/viewcvs.py/tipc/source/stable_ericsson/TIPC_SCC/src/Message.h?rev=1.2&view=markup)
	////////////////////////////////////////////////////////////////////
                TIPC internal header format, version 1:

   :                                                               :
   |                 Word 0-2: common to all users                 |
   |                                                               |
   +-------+-------+-------+-------+-------+-------+-------+-------+
   |netw-|imp|link |                               | |p|bea- |link |
w3:|ork  |ort|sel- |        message count          | |r|rer  |sel- | 
   |id   |anc|ector|                               | |b|id   |ector| 
   +-------+-------+-------+-------+-------+-------+-------+-------+
   |                                                               |
w4:|                        remote address                         |
   |                                                               |
   +-------+-------+-------+-------+-------+-------+-------+-------+
   | msg   |                       |                               |
w5:| type  |           gap         |           next sent           |
   |       |                       |                               |
   +-------+-------+-------+-------+-------+-------+-------+-------+
   |                       | link    |                             |
w6:|        reserve        | prio-   |        link tolerance       |
   |                       | ity     |                             |
   +-------+-------+-------+-------+-------+-------+-------+-------+
   |                                                               |
w7:|                                                               |
   |                                                               |
   +-------+-------+                               +-------+-------+
   |                                                               |
w8:|                                                               |
   |                                                               |
   +-------+-------+       bearer name             +-------+-------+
   |                                                               |
w9:|                                                               |
   |                                                               |
   +-------+-------+                               +-------+-------+
   |                                                               |
wa:|                                                               |
   |                                                               |
   +-------+-------+-------+-------+-------+-------+-------+-------+

 NB: Connection Manager and Name Distributor use data message format.
  
	

*/

static void
dissect_tipc_int_prot_msg(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tipc_tree,int offset,guint8 user, guint32 msg_size)
{	
	guint8 msg_type;
	tvbuff_t *data_tvb;
	guint16 message_count;
	guint32 msg_in_bundle_size;
	guint32 dword;
	guint msg_no = 0;
	guint8 link_sel;
	guint16 link_lev_seq_no;
	guint32 reassembled_msg_length = 0;
	guint32 no_of_segments = 0;

	gboolean   save_fragmented;
	tvbuff_t* new_tvb = NULL;
	tvbuff_t* next_tvb = NULL;
	fragment_data *frag_msg = NULL;
	proto_item *item;
	
	link_lev_seq_no = tvb_get_ntohl(tvb,4) & 0xffff;
	/* Internal Protocol Header */
	/* Unused */

	msg_type = tvb_get_guint8(tvb,20)>>4;
	/* W3 */
	dword = tvb_get_ntohl(tvb,offset);
	link_sel = dword & 0x7;
	proto_tree_add_item(tipc_tree, hf_tipc_unused2, tvb, offset, 4, FALSE);
	/* Importance */
	if ( user == TIPC_SEGMENTATION_MANAGER)
		proto_tree_add_item(tipc_tree, hf_tipc_importance, tvb, offset, 4, FALSE);
	/* Link selector */
	if ( user == TIPC_SEGMENTATION_MANAGER || user == TIPC_NAME_DISTRIBUTOR || user == TIPC_CHANGEOVER_PROTOCOL )
		proto_tree_add_item(tipc_tree, hf_tipc_link_selector, tvb, offset, 4, FALSE);
	/* Message count */
	if ( user == TIPC_MSG_BUNDLER || user == TIPC_CHANGEOVER_PROTOCOL ){
		message_count = tvb_get_ntohs(tvb,offset+2);
		proto_tree_add_item(tipc_tree, hf_tipc_msg_cnt, tvb, offset, 4, FALSE);
	}
	/* Unused */
	/* Probe */
	if ( user == TIPC_LINK_PROTOCOL )
		proto_tree_add_item(tipc_tree, hf_tipc_probe, tvb, offset, 4, FALSE);
	/* Bearer identity */
	if ( user == TIPC_LINK_PROTOCOL || user == TIPC_CHANGEOVER_PROTOCOL )
		proto_tree_add_item(tipc_tree, hf_tipc_bearer_id, tvb, offset, 4, FALSE);
	/* Link selector */
	if ( user == TIPC_SEGMENTATION_MANAGER || user == TIPC_NAME_DISTRIBUTOR || user == TIPC_CHANGEOVER_PROTOCOL )
		proto_tree_add_item(tipc_tree, hf_tipc_link_selector2, tvb, offset, 4, FALSE);
	
	offset = offset + 4;

	/* W4 */
	/* Remote address */
	if ( user == TIPC_ROUTING_MANAGER )
		proto_tree_add_item(tipc_tree, hf_tipc_remote_addr, tvb, offset, 4, FALSE);
	offset = offset + 4;
	
	/* W5 */
	/* Message type */
	switch (user){
	case TIPC_ROUTING_MANAGER:
		proto_tree_add_item(tipc_tree, hf_tipc_rm_msg_type, tvb, offset, 4, FALSE);
		break;
	case TIPC_NAME_DISTRIBUTOR:
		proto_tree_add_item(tipc_tree, hf_tipc_nd_msg_type, tvb, offset, 4, FALSE);
		break;
	case TIPC_CONNECTION_MANAGER:
		break;
	case TIPC_LINK_PROTOCOL:
		proto_tree_add_item(tipc_tree, hf_tipc_lp_msg_type, tvb, offset, 4, FALSE);
		break;
	case TIPC_CHANGEOVER_PROTOCOL:
		proto_tree_add_item(tipc_tree, hf_tipc_cng_prot_msg_type, tvb, offset, 4, FALSE);
		break;
	case TIPC_SEGMENTATION_MANAGER:
		proto_tree_add_item(tipc_tree, hf_tipc_sm_msg_type, tvb, offset, 4, FALSE);
		break;
	default:
		proto_tree_add_item(tipc_tree, hf_tipc_unknown_msg_type, tvb, offset, 4, FALSE);
		break;
	}
	/* Sequence gap */
	if ( user == TIPC_LINK_PROTOCOL && msg_type == TIPC_LINK_PROTOCO_STATE_MSG )
		proto_tree_add_item(tipc_tree, hf_tipc_seq_gap, tvb, offset, 4, FALSE);
	/* Next sent packet */
	proto_tree_add_item(tipc_tree, hf_tipc_nxt_snt_pkg, tvb, offset, 4, FALSE);

	offset = offset + 4;
	/* W6 */
	/* Unused */
	proto_tree_add_item(tipc_tree, hf_tipc_unused3, tvb, offset, 4, FALSE);
	offset = offset + 4;
	/*W7 */
	if (msg_size == 28) /* No data */
		return;

	switch (user){
		case TIPC_LINK_PROTOCOL:
			proto_tree_add_item(tipc_tree, hf_tipc_bearer_name, tvb, offset, -1, FALSE);
			break;
		case TIPC_CHANGEOVER_PROTOCOL:
			switch (msg_type){
			case 0: /* DUPLICATE_MSG */
			case 1: /* ORIGINAL_MSG */
				proto_tree_add_text(tipc_tree, tvb, offset, -1,"TIPC_CHANGEOVER_PROTOCOL %s (%u)",val_to_str(msg_type, tipc_cng_prot_msg_type_values, "unknown"),msg_type);
				data_tvb = tvb_new_subset(tvb, offset, -1, -1);
				if (check_col(pinfo->cinfo, COL_INFO))
					col_set_fence(pinfo->cinfo, COL_INFO);
				dissect_tipc(data_tvb, pinfo, tipc_tree);
				break;
			default:
				/*	INFO_MSG: Even when there are no packets in the send queue of a removed link, the other
					endpoint must be informed about this fact, so it can be unblocked when it has terminated its
					part of the changeover procedure. This message type may be regarded as an empty
					ORIGINAL_MSG, where message count is zero, and no packet is wrapped inside.
				*/
				proto_tree_add_text(tipc_tree, tvb, offset, -1,"TIPC_CHANGEOVER_PROTOCOL Protol/dissection Error");
				return;
				break;
			}
			break;
		case TIPC_SEGMENTATION_MANAGER:
			save_fragmented = pinfo->fragmented;
			if (tipc_defragment){
				pinfo->fragmented = TRUE;
			
				frag_msg = fragment_add_seq_next(tvb, offset, pinfo,
						link_sel,							/* ID for fragments belonging together - NEEDS IMPROVING? */  
						tipc_msg_fragment_table,			/* list of message fragments */
						tipc_msg_reassembled_table,			/* list of reassembled messages */
						tvb_length_remaining(tvb, offset),	/* fragment length - to the end */
						TRUE);								/* More fragments? */
				if (msg_type == TIPC_FIRST_SEGMENT ){
					reassembled_msg_length = tvb_get_ntohl(tvb,offset) & 0x1ffff;
					/* The number of segments needed fot he complete message (Including header) will be
					 * The size of the data section of the first message, divided by the complete message size
					 * + one segment for the remainder (if any).
					 */
					no_of_segments = reassembled_msg_length/(msg_size - 28);
					if (reassembled_msg_length > (no_of_segments * (msg_size - 28)))
						no_of_segments++;
					fragment_set_tot_len(pinfo, link_sel, tipc_msg_fragment_table, no_of_segments-1);
					item = proto_tree_add_text(tipc_tree, tvb, offset, -1,"Segmented message size %u bytes -> No segments = %i",reassembled_msg_length,no_of_segments);
					PROTO_ITEM_SET_GENERATED(item);
				}

				new_tvb = process_reassembled_data(tvb, offset, pinfo,
					"Reassembled Message", frag_msg, &tipc_msg_frag_items,
					NULL, tipc_tree);

				if (frag_msg) { /* Reassembled */
					if (check_col(pinfo->cinfo, COL_INFO))
						col_append_str(pinfo->cinfo, COL_INFO, 
						" (Message Reassembled)");
				} else { /* Not last packet of reassembled Short Message */
					if (check_col(pinfo->cinfo, COL_INFO))
						col_append_fstr(pinfo->cinfo, COL_INFO,
						" (Message fragment %u)", link_lev_seq_no);
				}
			}

			if (new_tvb) { /* take it all */
				next_tvb = new_tvb;
			} else { /* make a new subset */
			 	next_tvb = tvb_new_subset(tvb, offset, -1, -1);
			}
			pinfo->fragmented = save_fragmented;
			if (new_tvb){
				if (check_col(pinfo->cinfo, COL_INFO))
					col_set_fence(pinfo->cinfo, COL_INFO);
				dissect_tipc(next_tvb, pinfo, tipc_tree);
				return;
			}
		
			proto_tree_add_text(tipc_tree, next_tvb, 0, -1,"%u bytes Data Fragment",(msg_size - 28));
			return;
			break;
		case TIPC_MSG_BUNDLER:
			proto_tree_add_text(tipc_tree, tvb, offset, -1,"Message Bundle");
			while ((guint32)offset < msg_size ){
				msg_no++;
				msg_in_bundle_size = tvb_get_ntohl(tvb,offset);
				proto_tree_add_text(tipc_tree, tvb, offset, msg_in_bundle_size,"%u Message in Bundle",msg_no);
				data_tvb = tvb_new_subset(tvb, offset, msg_in_bundle_size, msg_in_bundle_size);
				if (check_col(pinfo->cinfo, COL_INFO))
					col_set_fence(pinfo->cinfo, COL_INFO);
				dissect_tipc(data_tvb, pinfo, tipc_tree);
				offset = offset + msg_in_bundle_size;
			}
			break;
		default:
			proto_tree_add_text(tipc_tree, tvb, offset, -1,"%u bytes Data",(msg_size - 28));
			break;
	}
	return;
}


static void
dissect_tipc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{

	proto_item *ti, *tipc_data_item;
	proto_tree *tipc_tree, *tipc_data_tree;
	int offset = 0;
	int previous_offset;
	guint32 dword;
	guint8 version;
	guint32 msg_size;
	guint8 hdr_size;
	guint8 user;
	gchar *addr_str_ptr;
	const guchar		*src_addr, *dst_addr;
	tvbuff_t *data_tvb, *tipc_tvb;
	gboolean datatype_hdr = FALSE;
	guint8 msg_type = 0;

		/* Make entry in Protocol column on summary display */
	if (check_col(pinfo->cinfo, COL_PROTOCOL)) 
		col_set_str(pinfo->cinfo, COL_PROTOCOL, "TIPC");

	if (check_col(pinfo->cinfo, COL_INFO)) 
		col_clear(pinfo->cinfo, COL_INFO);

	top_tree = tree;
	dword = tvb_get_ntohl(tvb,offset);
	version = (dword >>29) & 0xf;
	hdr_size = (dword >>21) & 0xf;
	user = (dword>>25) & 0xf;
	msg_size = dword & 0x1ffff;

	if ( (guint32)tvb_length_remaining(tvb,offset) < msg_size){
		tipc_tvb = tvb;
	}else{
		tipc_tvb = tvb_new_subset(tvb, offset, msg_size, msg_size);
	}
	/* Set User values in COL INFO different in V1 and V2 */
	switch (version){
	case 0:
	case TIPCv1:
		msg_type = tvb_get_guint8(tipc_tvb,offset + 20)>>4;
		if (check_col(pinfo->cinfo, COL_INFO)){
			col_append_fstr(pinfo->cinfo, COL_INFO, " %s(%u) ", val_to_str(user, tipc_user_values, "unknown"),user);
		}
		/* Set msg type in info col and find out if its a data hdr or not */
		datatype_hdr = tipc_v1_set_col_msgtype(pinfo, user, msg_type);
		if ( datatype_hdr ){
			/* Data type header */
			if ( hdr_size > 5 && user <4){
				/* W6 Originating Processor */
				src_addr = tvb_get_ptr(tipc_tvb, offset + 24, 4);
				SET_ADDRESS(&pinfo->src, AT_TIPC, 4, src_addr);
	
				/* W7 Destination Processor */
				dst_addr = tvb_get_ptr(tipc_tvb, offset + 28, 4);
				SET_ADDRESS(&pinfo->dst, AT_TIPC, 4, dst_addr);
			}else{
				/* Short data hdr */
				/* W2 Previous Processor */
				src_addr = tvb_get_ptr(tipc_tvb, offset + 8, 4);
				SET_ADDRESS(&pinfo->src, AT_TIPC, 4, src_addr);
			}
		}else{
			/* W2 Previous Processor */
			src_addr = tvb_get_ptr(tipc_tvb, offset + 8, 4);
			SET_ADDRESS(&pinfo->src, AT_TIPC, 4, src_addr);
		}
		break;
	case TIPCv2:
		msg_type = tvb_get_guint8(tipc_tvb,offset + 4)>>5;
		if (check_col(pinfo->cinfo, COL_INFO)){
			col_append_fstr(pinfo->cinfo, COL_INFO, " %s(%u) ", val_to_str(user, tipcv2_user_values, "unknown"),user);
		}
		/* Set msg type in info col and find out if its a data hdr or not */
		datatype_hdr = tipc_v2_set_col_msgtype(pinfo, user, msg_type);
		if ( datatype_hdr ){
			if (hdr_size > 5){
				/* W6 Originating Processor */
				src_addr = tvb_get_ptr(tipc_tvb, offset + 24, 4);
				SET_ADDRESS(&pinfo->src, AT_TIPC, 4, src_addr);
	
				/* W7 Destination Processor */
				dst_addr = tvb_get_ptr(tipc_tvb, offset + 28, 4);
				SET_ADDRESS(&pinfo->dst, AT_TIPC, 4, dst_addr);
			}else{
				/* W2 Previous Processor */
				src_addr = tvb_get_ptr(tipc_tvb, offset + 8, 4);
				SET_ADDRESS(&pinfo->src, AT_TIPC, 4, src_addr);
			}

		}else{
			if (user != TIPCv2_LINK_CONFIGURATION){
				/* W6 Originating Processor */
				src_addr = tvb_get_ptr(tipc_tvb, offset + 24, 4);
				SET_ADDRESS(&pinfo->src, AT_TIPC, 4, src_addr);
	
				/* W7 Destination Processor */
				dst_addr = tvb_get_ptr(tipc_tvb, offset + 28, 4);
				SET_ADDRESS(&pinfo->dst, AT_TIPC, 4, dst_addr);
			}else{

			}
		}
		break;
	default:
		break;
	}

	ti = proto_tree_add_item(tree, proto_tipc, tipc_tvb, offset, -1, FALSE);
	tipc_tree = proto_item_add_subtree(ti, ett_tipc);
	if ( version == TIPCv2){
		dissect_tipc_v2(tipc_tvb, pinfo, tipc_tree, offset, user, msg_size, hdr_size, datatype_hdr);
		return;
	}
	/* Word 0-2 common for all messages
	 * Word 0
	 */


	proto_tree_add_item(tipc_tree, hf_tipc_ver, tipc_tvb, offset, 4, FALSE);
	proto_tree_add_item(tipc_tree, hf_tipc_usr, tipc_tvb, offset, 4, FALSE);
	proto_tree_add_item(tipc_tree, hf_tipc_hdr_size, tipc_tvb, offset, 4, FALSE);
	proto_tree_add_item(tipc_tree, hf_tipc_unused, tipc_tvb, offset, 4, FALSE);
	proto_tree_add_item(tipc_tree,hf_tipc_nonsequenced, tipc_tvb,offset,4, FALSE);
	if (datatype_hdr)
		proto_tree_add_item(tipc_tree,hf_tipc_destdrop, tipc_tvb,offset,4, FALSE);

	proto_tree_add_item(tipc_tree, hf_tipc_msg_size, tipc_tvb, offset, 4, FALSE);
	offset = offset + 4;
		
	/* Word 1 */
	proto_tree_add_item(tipc_tree, hf_tipc_ack_link_lev_seq, tipc_tvb, offset, 4, FALSE);
	proto_tree_add_item(tipc_tree, hf_tipc_link_lev_seq, tipc_tvb, offset, 4, FALSE);
	offset = offset + 4;
		
	/* Word 2 */
	dword = tvb_get_ntohl(tipc_tvb,offset);
	addr_str_ptr = tipc_addr_to_str(dword);
	proto_tree_add_string(tipc_tree, hf_tipc_prev_proc, tipc_tvb, offset, 4,	addr_str_ptr);

	offset = offset + 4;
	switch (user){
		case TIPC_ROUTING_MANAGER:
		case TIPC_LINK_PROTOCOL:
		case TIPC_CHANGEOVER_PROTOCOL:
		case TIPC_SEGMENTATION_MANAGER:
		case TIPC_MSG_BUNDLER:
			dissect_tipc_int_prot_msg(tipc_tvb, pinfo, tipc_tree, offset, user, msg_size);
			return;
			break;
		default:
		break;		 
	}

	dword = tvb_get_ntohl(tipc_tvb,offset);
	pinfo->ptype = PT_TIPC;
	pinfo->srcport = dword;
	proto_tree_add_item(tipc_tree, hf_tipc_org_port, tipc_tvb, offset, 4, FALSE);
	offset = offset + 4;
	if(user != TIPC_NAME_DISTRIBUTOR){
		dword = tvb_get_ntohl(tipc_tvb,offset);
		pinfo->destport = dword;
		proto_tree_add_item(tipc_tree, hf_tipc_dst_port, tipc_tvb, offset, 4, FALSE);
	}
	offset = offset + 4;
	/* 20 - 24 Bytes 
		20 bytes: Used in subnetwork local, connection oriented messages, where error code, reroute
		counter and activity identity are zero. A recipient finding that the header size field is 20 does
		by default know both user (DATA), message type (CONNECTED_MSG), error code
		(MSG_OK), reroute counter (0), and activity identity (undefined). Since no more testing for
		this is needed these fields can be left out in the header. Furthermore, since such messages
		only will do zero or one inter-processor hop, we know that previous processor is the real
		origin of the message. Hence the field originating processor can be omitted. For the same
		reason, the recipient processor will know that it is identical to destination processor, so even
		this field can be skipped. Finally, because the link layer guarantees delivery and sequence
		order for this single hop, even the connection sequence number is redundant. So the message
		can just be passed directly on to the destination port. Since this type of message statistically
		should be by far the most frequent one this small optimization pays off.
	*/
	if ( hdr_size <= 5 ){
		proto_tree_add_text(tipc_tree, tipc_tvb, offset, -1,"%u bytes Data",(msg_size - hdr_size *4));
	}else{
		switch (user){
			case TIPC_NAME_DISTRIBUTOR:
				proto_tree_add_item(tipc_tree, hf_tipc_nd_msg_type, tipc_tvb, offset, 4, FALSE);
				break;
			case TIPC_CONNECTION_MANAGER:
				proto_tree_add_item(tipc_tree, hf_tipc_cm_msg_type, tipc_tvb, offset, 4, FALSE);
				break;
			default:
				proto_tree_add_item(tipc_tree, hf_tipc_data_msg_type, tipc_tvb, offset, 4, FALSE);
				break;
			}
			proto_tree_add_item(tipc_tree, hf_tipc_err_code, tipc_tvb, offset, 4, FALSE);
			proto_tree_add_item(tipc_tree, hf_tipc_reroute_cnt, tipc_tvb, offset, 4, FALSE);
			proto_tree_add_item(tipc_tree, hf_tipc_act_id, tipc_tvb, offset, 4, FALSE);
			offset = offset + 4;

			dword = tvb_get_ntohl(tipc_tvb,offset);
			addr_str_ptr = tipc_addr_to_str(dword);

			proto_tree_add_string(tipc_tree, hf_tipc_org_proc, tipc_tvb, offset, 4,	addr_str_ptr);
			offset = offset + 4;

			dword = tvb_get_ntohl(tipc_tvb,offset);
			addr_str_ptr = tipc_addr_to_str(dword);

			proto_tree_add_string(tipc_tree, hf_tipc_dst_proc, tipc_tvb, offset, 4,	addr_str_ptr);
			offset = offset + 4;
				/* 32 bytes 
				32 bytes: The size of all data messages containing an explicit port identity as destination
				address.
				*/
			if ( hdr_size > 8){
				if (user == TIPC_NAME_DISTRIBUTOR ){
					/*
						Although an internal service, the name distributor uses the full 40-byte "external" data header
						format when updating the naming table instances. This is because its messages may need
						routing, - all system processor must contain the publications from all device processors and
						vice versa, whether they are directly linked or not. The fields name type, name instance, and
						destination port of that header have no meaning for such messages
						*/
					offset = offset + 8;
					tipc_data_item = proto_tree_add_text(tipc_tree, tvb, offset, -1,"TIPC_NAME_DISTRIBUTOR %u bytes User Data",(msg_size - hdr_size *4));
					tipc_data_tree = proto_item_add_subtree(tipc_data_item , ett_tipc_data);
					data_tvb = tvb_new_subset(tipc_tvb, offset, -1, -1);
					dissect_tipc_name_dist_data(data_tvb, pinfo, tipc_data_tree);
					return;
				}else{
					/* Port name type / Connection level sequence number */
					proto_tree_add_text(tipc_tree, tipc_tvb, offset, 4,"Port name type / Connection level sequence number");
					offset = offset + 4;
					/* Port name instance */
					proto_tree_add_text(tipc_tree, tipc_tvb, offset, 4,"Port name instance");
					offset = offset + 4;
				}
			}

			if (user < 4 && dissect_tipc_data){ /* DATA type user */
				switch (msg_type){
				case TIPC_CONNECTED_MSG:
					proto_tree_add_text(tipc_tree, tipc_tvb, offset, -1,"%u bytes Data",(msg_size - hdr_size *4));
					break;
				case TIPC_NAMED_MSG:
					data_tvb = tvb_new_subset(tipc_tvb, offset+14, -1, -1);
					proto_tree_add_text(tipc_tree, tipc_tvb, offset, 14,"TIPC_NAMED_MSG Hdr");
					proto_tree_add_text(tipc_tree, data_tvb,0, -1,"%u bytes Data",(msg_size - hdr_size *4));
					return;
					break;
				case TIPC_DIRECT_MSG:
					previous_offset = offset;
					while (tvb_reported_length_remaining(tipc_tvb,offset) > 0){
						dword = tvb_get_ntohl(tipc_tvb,offset);
						if ((dword & 0xff000000) == 0x45000000){ /* && ((dword & 0x0000ffff)== tvb_reported_length_remaining(tvb,offset+2)))*/
							data_tvb = tvb_new_subset(tipc_tvb, offset, -1, -1);
							call_dissector(ip_handle, data_tvb, pinfo, top_tree);
							return;
						}
						offset = offset+4;
					}
					proto_tree_add_text(tipc_tree, tipc_tvb, previous_offset, -1,"%u bytes Data",(msg_size - hdr_size *4));
					return;
					break;
				default:
					proto_tree_add_text(tipc_tree, tipc_tvb, offset, -1,"%u bytes Data",(msg_size - hdr_size *4));
					break;
				}
			}			
			
		}/*if ( hdr_size <= 5 ) */
	/*}if tree */

}




/* Register TIPC with Ethereal */
void
proto_register_tipc(void)
{                 

	static hf_register_info hf[] = {

		{&hf_tipc_msg_fragments,
			{"Message fragments", "tipc.msg.fragments",
			FT_NONE, BASE_NONE, NULL, 0x00,	NULL, HFILL } 
		},
		{&hf_tipc_msg_fragment,
			{"Message fragment", "tipc.msg.fragment",
			FT_FRAMENUM, BASE_NONE, NULL, 0x00, NULL, HFILL } 
		},
		{&hf_tipc_msg_fragment_overlap,
			{"Message fragment overlap", "tipc.msg.fragment.overlap",
			FT_BOOLEAN, BASE_NONE, NULL, 0x00, NULL, HFILL } 
		},
		{&hf_tipc_msg_fragment_overlap_conflicts,
			{"Message fragment overlapping with conflicting data","tipc.msg.fragment.overlap.conflicts",
			FT_BOOLEAN, BASE_NONE, NULL, 0x00, NULL, HFILL } 
		},
		{&hf_tipc_msg_fragment_multiple_tails,
			{"Message has multiple tail fragments", "tipc.msg.fragment.multiple_tails", 
			FT_BOOLEAN, BASE_NONE, NULL, 0x00, NULL, HFILL } 
		},
		{&hf_tipc_msg_fragment_too_long_fragment,
			{"Message fragment too long", "tipc.msg.fragment.too_long_fragment",
			FT_BOOLEAN, BASE_NONE, NULL, 0x00, NULL, HFILL } 
		},
		{&hf_tipc_msg_fragment_error,
			{"Message defragmentation error", "tipc.msg.fragment.error",
			FT_FRAMENUM, BASE_NONE, NULL, 0x00, NULL, HFILL } 
		},
		{&hf_tipc_msg_reassembled_in,
			{"Reassembled in", "tipc.msg.reassembled.in",
			FT_FRAMENUM, BASE_NONE, NULL, 0x00, NULL, HFILL } 
		},
		{ &hf_tipc_ver,
			{ "Version",           "tipc.ver",
			FT_UINT32, BASE_DEC, NULL, 0xe0000000,          
			"TIPC protocol version", HFILL }
		},
		{ &hf_tipc_usr,
			{ "User",           "tipc.usr",
			FT_UINT32, BASE_DEC, VALS(tipc_user_values), 0x1e000000,          
			"TIPC User", HFILL }
		},
		{ &hf_tipcv2_usr,
			{ "User",           "tipc.usr",
			FT_UINT32, BASE_DEC, VALS(tipcv2_user_values), 0x1e000000,          
			"TIPC User", HFILL }
		},
		{ &hf_tipc_hdr_size,
			{ "Header size",           "tipc.hdr_size",
			FT_UINT32, BASE_DEC, NULL, 0x01e00000,          
			"TIPC Header size", HFILL }
		},
		{ &hf_tipc_nonsequenced,
			{ "Non-sequenced","tipc.non_sequenced",
			FT_UINT32,BASE_DEC,NULL,0x00100000,
			"Non-sequenced Bit",HFILL }
		},
		{ &hf_tipc_destdrop,
			{ "Destination Droppable","tipc.destdrop",
			FT_UINT32,BASE_DEC,NULL,0x00080000,
			"Destination Droppable Bit",HFILL }
		},
		{ &hf_tipc_unused,
			{ "Unused",           "tipc.hdr_unused",
			FT_UINT32, BASE_DEC, NULL, 0x001e0000,          
			"TIPC Unused", HFILL }
		},
		{ &hf_tipc_msg_size,
			{ "Message size",           "tipc.msg_size",
			FT_UINT32, BASE_DEC, NULL, 0x0001ffff,          
			"TIPC Message size", HFILL }
		},
		{ &hf_tipc_ack_link_lev_seq,
			{ "Acknowledged link level sequence number",           "tipc.ack_link_lev_seq",
			FT_UINT32, BASE_DEC, NULL, 0xffff0000,          
			"TIPC Acknowledged link level sequence number", HFILL }
		},
		{ &hf_tipc_link_lev_seq,
			{ "Link level sequence number",           "tipc.link_lev_seq",
			FT_UINT32, BASE_DEC, NULL, 0x0000ffff,          
			"TIPC Link level sequence number", HFILL }
		},
		{ &hf_tipc_prev_proc,
			{ "Previous processor",           "tipc.prev_proc",
			FT_STRING, BASE_NONE, NULL, 0x0,          
			"TIPC Previous processor", HFILL }
		},
		{ &hf_tipc_org_port,
			{ "Originating port",           "tipc.org_port",
			FT_UINT32, BASE_DEC, NULL, 0x0,          
			"TIPC Oiginating port", HFILL }
		},
		{ &hf_tipc_dst_port,
			{ "Destination port",           "tipc.dst_port",
			FT_UINT32, BASE_DEC, NULL, 0x0,          
			"TIPC Destination port", HFILL }
		},
		{ &hf_tipc_data_msg_type,
			{ "Message type",           "tipc.msg_type",
			FT_UINT32, BASE_DEC, VALS(tipc_data_msg_type_values), 0xf0000000,          
			"TIPC Message type", HFILL }
		},
		{ &hf_tipc_err_code,
			{ "Error code",           "tipc.err_code",
			FT_UINT32, BASE_DEC, VALS(tipc_error_code_values), 0x0f000000,          
			"TIPC Error code", HFILL }
		},
		{ &hf_tipc_reroute_cnt,
			{ "Reroute counter",           "tipc.route_cnt",
			FT_UINT32, BASE_DEC, NULL, 0x00f00000,          
			"TIPC Reroute counter", HFILL }
		},
		{ &hf_tipc_act_id,
			{ "Activity identity",           "tipc.act_id",
			FT_UINT32, BASE_DEC, NULL, 0x000fffff,          
			"TIPC Activity identity", HFILL }
		},		
		{ &hf_tipc_org_proc,
			{ "Originating processor",           "tipc.org_proc",
			FT_STRING, BASE_NONE, NULL, 0x0,          
			"TIPC Originating processor", HFILL }
		},
		{ &hf_tipc_dst_proc,
			{ "Destination processor",           "tipc.dst_proc",
			FT_STRING, BASE_NONE, NULL, 0x0,          
			"TIPC Destination processor", HFILL }
		},
		{ &hf_tipc_unused2,
			{ "Unused",           "tipc.unused2",
			FT_UINT32, BASE_DEC, NULL, 0xe0000000,          
			"TIPC Unused", HFILL }
		},
		{ &hf_tipc_importance,
			{ "Importance",           "tipc.importance",
			FT_UINT32, BASE_DEC, NULL, 0x18000000,          
			"TIPC Importance", HFILL }
		},
		{ &hf_tipc_link_selector,
			{ "Link selector",           "tipc.link_selector",
			FT_UINT32, BASE_DEC, NULL, 0x07000000,          
			"TIPC Link selector", HFILL }
		},
		{ &hf_tipc_msg_cnt,
			{ "Message count",           "tipc.imsg_cnt",
			FT_UINT32, BASE_DEC, NULL, 0x00ffff00,          
			"TIPC Message count", HFILL }
		},
		{ &hf_tipc_probe,
			{ "Probe",           "tipc.probe",
			FT_UINT32, BASE_DEC, NULL, 0x00000040,          
			"TIPC Probe", HFILL }
		},
		{ &hf_tipc_bearer_id,
			{ "Bearer identity",           "tipc.bearer_id",
			FT_UINT32, BASE_DEC, NULL, 0x00000038,          
			"TIPC Bearer identity", HFILL }
		},
		{ &hf_tipc_link_selector2,
			{ "Link selector",           "tipc.link_selector",
			FT_UINT32, BASE_DEC, NULL, 0x00000007,          
			"TIPC Link selector", HFILL }
		},
		{ &hf_tipc_remote_addr,
			{ "Remote address",           "tipc.remote_addr",
			FT_UINT32, BASE_DEC, NULL, 0x0,          
			"TIPC Remote address", HFILL }
		},
		{ &hf_tipc_rm_msg_type,
			{ "Message type",           "tipc.rm_msg_type",
			FT_UINT32, BASE_DEC, VALS(tipc_routing_mgr_msg_type_values), 0xf0000000,          
			"TIPC Message type", HFILL }
		},
		{ &hf_tipc_nd_msg_type,
			{ "Message type",           "tipc.nd_msg_type",
			FT_UINT32, BASE_DEC, VALS(tipc_name_dist_msg_type_values), 0xf0000000,          
			"TIPC Message type", HFILL }
		},
		{ &hf_tipc_cm_msg_type,
			{ "Message type",           "tipc.nd_msg_type",
			FT_UINT32, BASE_DEC, VALS(tipc_cm_msg_type_values), 0xf0000000,          
			"TIPC Message type", HFILL }
		},
		{ &hf_tipc_lp_msg_type,
			{ "Message type",           "tipc.lp_msg_type",
			FT_UINT32, BASE_DEC, VALS(tipc_link_prot_msg_type_values), 0xf0000000,          
			"TIPC Message type", HFILL }
		},
		{ &hf_tipc_cng_prot_msg_type,
			{ "Message type",           "tipc.cng_prot_msg_type",
			FT_UINT32, BASE_DEC, VALS(tipc_cng_prot_msg_type_values), 0xf0000000,          
			"TIPC Message type", HFILL }
		},
		{ &hf_tipc_sm_msg_type,
			{ "Message type",           "tipc.sm_msg_type",
			FT_UINT32, BASE_DEC, VALS(tipc_sm_msg_type_values), 0xf0000000,          
			"TIPC Message type", HFILL }
		},
		{ &hf_tipc_unknown_msg_type,
			{ "Message type",           "tipc.unknown_msg_type",
			FT_UINT32, BASE_DEC, NULL, 0xf0000000,          
			"TIPC Message type", HFILL }
		},
		{ &hf_tipc_seq_gap,
			{ "Sequence gap",           "tipc.seq_gap",
			FT_UINT32, BASE_DEC, NULL, 0x0fff0000,          
			"TIPC Sequence gap", HFILL }
		},
		{ &hf_tipc_nxt_snt_pkg,
			{ "Next sent packet",           "tipc.nxt_snt_pkg",
			FT_UINT32, BASE_DEC, NULL, 0x0000ffff,          
			"TIPC Next sent packet", HFILL }
		},
		{ &hf_tipc_unused3,
			{ "Unused",           "tipc.unused3",
			FT_UINT32, BASE_DEC, NULL, 0x0,          
			"TIPC Unused", HFILL }
		},
		{ &hf_tipc_bearer_name,
			{ "Bearer name",           "tipc.bearer_name",
			FT_STRINGZ, BASE_NONE, NULL, 0x0,          
			"TIPC Bearer name", HFILL }
		},
		{ &hf_tipc_name_dist_type,
			{ "Published port name type", "tipc.name_dist_type",
			FT_UINT32, BASE_DEC, NULL, 0x0,          
			"TIPC Published port name type", HFILL }
		},
		{ &hf_tipc_name_dist_lower,
			{ "Lower bound of published sequence",  "tipc.ame_dist_lower",
			FT_UINT32, BASE_DEC, NULL, 0x0,          
			"TIPC Lower bound of published sequence", HFILL }
		},
		{ &hf_tipc_name_dist_upper,
			{ "Upper bound of published sequence",  "tipc.name_dist_upper",
			FT_UINT32, BASE_DEC, NULL, 0x0,          
			"TIPC Upper bound of published sequence", HFILL }
		},
		{ &hf_tipc_name_dist_port,
			{ "Random number part of port identity", "tipc.dist_port",
			FT_UINT32, BASE_DEC, NULL, 0x0,          
			"TIPC Random number part of port identity", HFILL }
		},
		{ &hf_tipc_name_dist_key,
			{ "Key (Use for verification at withdrawal)",  "tipc.dist_key",
			FT_UINT32, BASE_DEC, NULL, 0x0,          
			"TIPC key", HFILL }
		},
		{ &hf_tipcv2_data_msg_type ,
			{ "Message type",           "tipc.data_type",
			FT_UINT32, BASE_DEC, VALS(tipc_data_msg_type_values), 0xe0000000,          
			"TIPC Message type", HFILL }
		},
		{ &hf_tipcv2_bcast_mtype ,
			{ "Message type",           "tipcv2.bcast_msg_type",
			FT_UINT32, BASE_DEC, VALS(tipcv2_bcast_mtype_strings), 0xe0000000,          
			"TIPC Message type", HFILL }
		},
		{ &hf_tipcv2_link_mtype ,
			{ "Message type",           "tipcv2.link_msg_type",
			FT_UINT32, BASE_DEC, VALS(tipcv2_link_mtype_strings), 0xe0000000,          
			"TIPC Message type", HFILL }
		},
		{ &hf_tipcv2_connmgr_mtype ,
			{ "Message type",           "tipcv2.connmgr_msg_type",
			FT_UINT32, BASE_DEC, VALS(tipcv2_connmgr_mtype_strings), 0xe0000000,          
			"TIPC Message type", HFILL }
		},
		{ &hf_tipcv2_route_mtype ,
			{ "Message type",           "tipcv2.route_msg_type",
			FT_UINT32, BASE_DEC, VALS(tipcv2_route_mtype_strings), 0xe0000000,          
			"TIPC Message type", HFILL }
		},
		{ &hf_tipcv2_changeover_mtype ,
			{ "Message type",           "tipcv2.changeover_msg_type",
			FT_UINT32, BASE_DEC, VALS(tipcv2_changeover_mtype_strings), 0xe0000000,          
			"TIPC Message type", HFILL }
		},
		{ &hf_tipcv2_naming_mtype ,
			{ "Message type",           "tipcv2.naming_msg_type",
			FT_UINT32, BASE_DEC, VALS(tipcv2_naming_mtype_strings), 0xe0000000,          
			"TIPC Message type", HFILL }
		},
		{ &hf_tipcv2_fragmenter_mtype ,
			{ "Message type",           "tipcv2.fragmenter_msg_type",
			FT_UINT32, BASE_DEC, VALS(tipcv2_fragmenter_mtype_strings), 0xe0000000,          
			"TIPC Message type", HFILL }
		},
		{ &hf_tipcv2_neighbour_mtype ,
			{ "Message type",           "tipcv2.data_msg_type",
			FT_UINT32, BASE_DEC, VALS(tipcv2_neighbour_mtype_strings), 0xe0000000,          
			"TIPC Message type", HFILL }
		},
		{ &hf_tipcv2_errorcode ,
			{ "Error code",           "tipcv2.errorcode",
			FT_UINT32, BASE_DEC, VALS(tipcv2_error_code_strings), 0x1e000000,          
			"Error code", HFILL }
		},
		{ &hf_tipcv2_rer_cnt,
			{ "Lookup Scope",           "tipcv2.rer_cnt",
			FT_UINT32, BASE_DEC, NULL, 0x01e00000,          
			"Lookup Scope", HFILL }
		},
		{ &hf_tipcv2_lookup_scope,
			{ "Reroute Counter",           "tipcv2.lookup_scope",
			FT_UINT32, BASE_DEC, VALS(tipcv2_lookup_scope_strings), 0x00180000,          
			"Reroute Counter", HFILL }
		},
		{ &hf_tipcv2_opt_p,
			{ "Options Position",           "tipcv2.opt_p",
			FT_UINT32, BASE_DEC, NULL, 0x00070000,          
			"Options Position", HFILL }
		},
		{ &hf_tipcv2_broadcast_ack_no,
			{ "Broadcast Acknowledge Number",           "tipcv2.broadcast_ack_no",
			FT_UINT32, BASE_DEC, NULL, 0x0000FFFF,          
			"Broadcast Acknowledge Number", HFILL }
		},

		{ &hf_tipcv2_link_level_ack_no,
			{ "link level ack no",           "tipcv2.link_level_ack_no",
			FT_UINT32, BASE_DEC, NULL, 0xFFFF0000,          
			"link level ack no", HFILL }
		},
		{ &hf_tipcv2_link_level_seq_no,
			{ "Link Level Sequence Number",           "tipcv2.link_level_seq_no",
			FT_UINT32, BASE_DEC, NULL, 0x0000FFFF,          
			"Link Level Sequence Number", HFILL }
		},
		{ &hf_tipcv2_bcast_seq_no,
			{ "Broadcast Sequence Number",           "tipcv2.bcast_seq_no",
			FT_UINT32, BASE_DEC, NULL, 0x0000FFFF,          
			"Broadcast Sequence Number", HFILL }
		},
		{ &hf_tipcv2_prev_node,
			{ "Previous Node",           "tipcv2.prev_node",
			FT_STRING, BASE_NONE, NULL, 0x0,          
			"TIPC Previous Node", HFILL }
		},
		{ &hf_tipcv2_orig_node,
			{ "Originating Node",           "tipcv2.orig_node",
			FT_STRING, BASE_NONE, NULL, 0x0,          
			"TIPC Originating Node", HFILL }
		},
		{ &hf_tipcv2_dest_node,
			{ "Destination Node",           "tipcv2.dest_node",
			FT_STRING, BASE_NONE, NULL, 0x0,          
			"TIPC Destination Node", HFILL }
		},
		{ &hf_tipcv2_port_name_type,
			{ "Port name type",           "tipcv2.port_name_type",
			FT_UINT32, BASE_DEC, NULL, 0,          
			"Port name type", HFILL }
		},
		{ &hf_tipcv2_port_name_instance,
			{ "Port name instance",           "tipcv2.port_name_instance",
			FT_UINT32, BASE_DEC, NULL, 0,          
			"Port name instance", HFILL }
		},
		{ &hf_tipcv2_bcast_seq_gap,
			{ "Broadcast Sequence Gap",           "tipcv2.bcast_seq_gap",
			FT_UINT32, BASE_DEC, NULL, 0x1F000000,          
			"Broadcast Sequence Gap", HFILL }
		},
		{ &hf_tipcv2_sequence_gap,
			{ "Sequence Gap",           "tipcv2.seq_gap",
			FT_UINT32, BASE_DEC, NULL, 0x00FF0000,          
			"Sequence Gap", HFILL }
		},
		{ &hf_tipcv2_next_sent_broadcast,
			{ "Next Sent Broadcast",           "tipcv2.next_sent_broadcast",
			FT_UINT32, BASE_DEC, NULL, 0x0000FFFF,          
			"Next Sent Broadcast", HFILL }
		},
		{ &hf_tipcv2_fragment_number,
			{ "Fragment Number",           "tipcv2.fragment_number",
			FT_UINT32, BASE_DEC, NULL, 0x0000FFFF,          
			"Fragment Number", HFILL }
		},
		{ &hf_tipcv2_next_sent_packet,
			{ "Next Sent Packet",           "tipcv2.next_sent_packet",
			FT_UINT32, BASE_DEC, NULL, 0x0000FFFF,          
			"Next Sent Packet", HFILL }
		},
		{ &hf_tipcv2_session_no,
			{ "Session Number",           "tipcv2.session_no",
			FT_UINT32, BASE_DEC, NULL, 0xFFFF0000,          
			"Session Number", HFILL }
		},
		{ &hf_tipcv2_link_prio,
			{ "Link Priority",           "tipcv2.link_prio",
			FT_UINT32, BASE_DEC, NULL, 0x000001F0,          
			"Link Priority", HFILL }
		},
		{ &hf_tipcv2_network_plane,
			{ "Network Plane",           "tipcv2.network_plane",
			FT_UINT32, BASE_DEC, VALS(tipcv2_networkplane_strings), 0x0000000E,          
			"Network Plane", HFILL }
		},
		{ &hf_tipcv2_probe,
			{ "Probe",           "tipcv2.probe",
			FT_UINT32, BASE_DEC, NULL, 0x00000001,          
			"probe", HFILL }
		},
		{ &hf_tipcv2_link_tolerance,
			{ "Link Tolerance (ms)",           "tipcv2.link_tolerance",
			FT_UINT32, BASE_DEC, NULL, 0x0000FFFF,          
			"Link Tolerance in ms", HFILL }
		},
		{ &hf_tipcv2_bearer_instance,
			{ "Bearer Instance",           "tipcv2.bearer_instance",
			FT_STRINGZ, BASE_NONE, NULL, 0,          
			"Bearer instance used by the sender node for this link", HFILL }
		},
		{ &hf_tipcv2_bearer_level_orig_addr,
			{ "Bearer Level Originating Address",           "tipcv2.bearer_level_orig_addr",
			FT_BYTES, BASE_HEX, NULL, 0,          
			"Bearer Level Originating Address", HFILL }
		},
		{ &hf_tipcv2_cluster_address,
			{ "Cluster Address",           "tipcv2.cluster_address",
			FT_STRING, BASE_NONE, NULL, 0x0,          
			"The remote cluster concerned by the table", HFILL }
		},
		{ &hf_tipcv2_bitmap,
			{ "Bitmap",           "tipcv2.bitmap",
			FT_BYTES, BASE_HEX, NULL, 0,          
			"Bitmap, indicating to which nodes within that cluster the sending node has direct links", HFILL }
		},
		{ &hf_tipcv2_node_address,
			{ "Node Address",           "tipcv2.node_address",
			FT_STRING, BASE_NONE, NULL, 0x0,
			"Which node the route addition/loss concern", HFILL }
		},
		{ &hf_tipcv2_destination_domain,
			{ "Destination Domain",           "tipcv2.destination_domain",
			FT_STRING, BASE_NONE, NULL, 0x0,
			"The domain to which the link request is directed", HFILL }
		},
		{ &hf_tipcv2_network_id,
			{ "Network Identity",           "tipcv2.network_id",
			FT_STRING, BASE_NONE, NULL, 0x0,
			"The sender node's network identity", HFILL }
		},
	};

/* Setup protocol subtree array */
	static gint *ett[] = {
		&ett_tipc,
		&ett_tipc_data,
		&ett_tipc_msg_fragment,
		&ett_tipc_msg_fragments,
	};

	module_t *tipc_module;

/* Register the protocol name and description */
	proto_tipc = proto_register_protocol("Transparent Inter Process Communication(TIPC)",
	    "TIPC", "tipc");

/* Required function calls to register the header fields and subtrees used */
	proto_register_field_array(proto_tipc, hf, array_length(hf));
	proto_register_subtree_array(ett, array_length(ett));

	register_init_routine(tipc_defragment_init);

	/* Register configuration options */
	tipc_module = prefs_register_protocol(proto_tipc, NULL);

	prefs_register_bool_preference(tipc_module, "defragment",
		"Reassemble SEGMENTATION_MANAGER datagrams",
		"Whether SEGMENTATION_MANAGER datagrams should be reassembled",
		&tipc_defragment);

	prefs_register_bool_preference(tipc_module, "dissect_tipc_data",
		"Dissect TIPC data",
		"Whether to try to dissect TIPC data or not",
		&dissect_tipc_data);
}

void
proto_reg_handoff_tipc(void)
{
	dissector_handle_t tipc_handle;

	tipc_handle = create_dissector_handle(dissect_tipc, proto_tipc);
	dissector_add("ethertype", ETHERTYPE_TIPC,     tipc_handle);
	if (extra_ethertype)
		dissector_add("ethertype", ETHERTYPE_TIPC2,     tipc_handle);
	
	ip_handle = find_dissector("ip");
}