aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-cipsafety.c
blob: eb40a6b7a1a679db7b000239ea1076cbe26f99f6 (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
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
/* packet-cipsafety.c
 * Routines for CIP (Common Industrial Protocol) Safety dissection
 * CIP Safety Home: www.odva.org
 *
 * Copyright 2011
 * Michael Mann <mmann@pyramidsolutions.com>
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include "config.h"

#include <epan/packet.h>
#include <epan/expert.h>
#include <epan/proto_data.h>

#include <wsutil/pint.h>
#include <wsutil/crc8.h>
#include <wsutil/crc16.h>
#include <wsutil/crc32.h>
#include "packet-cip.h"
#include "packet-cipsafety.h"


void proto_register_cipsafety(void);
void proto_reg_handoff_cipsafety(void);
/* The entry point to the actual dissection is: dissect_cipsafety */

/* Protocol handle for CIP Safety */
static int proto_cipsafety                = -1;
static int proto_cip_class_s_supervisor   = -1;
static int proto_cip_class_s_validator    = -1;
static int proto_cip                      = -1;

static dissector_table_t subdissector_class_table;
static dissector_handle_t cip_class_s_validator_handle;

/* CIP Safety field identifiers */
static int hf_cipsafety_data                      = -1;
static int hf_cipsafety_mode_byte                 = -1;
static int hf_cipsafety_mode_byte_run_idle        = -1;
static int hf_cipsafety_mode_byte_not_run_idle    = -1;
static int hf_cipsafety_mode_byte_tbd_2_bit       = -1;
static int hf_cipsafety_mode_byte_tbd_2_copy      = -1;
static int hf_cipsafety_mode_byte_ping_count      = -1;
static int hf_cipsafety_mode_byte_tbd             = -1;
static int hf_cipsafety_mode_byte_not_tbd         = -1;
static int hf_cipsafety_crc_s1                    = -1;
static int hf_cipsafety_crc_s1_status             = -1;
static int hf_cipsafety_crc_s2                    = -1;
static int hf_cipsafety_crc_s2_status             = -1;
static int hf_cipsafety_crc_s3                    = -1;
static int hf_cipsafety_crc_s3_status             = -1;
static int hf_cipsafety_complement_crc_s3         = -1;
static int hf_cipsafety_complement_crc_s3_status  = -1;
static int hf_cipsafety_timestamp                 = -1;
static int hf_cipsafety_ack_byte                  = -1;
static int hf_cipsafety_ack_byte_ping_count_reply = -1;
static int hf_cipsafety_ack_byte_reserved1        = -1;
static int hf_cipsafety_ack_byte_ping_response    = -1;
static int hf_cipsafety_ack_byte_reserved2        = -1;
static int hf_cipsafety_ack_byte_parity_even      = -1;
static int hf_cipsafety_ack_byte2                 = -1;
static int hf_cipsafety_consumer_time_value       = -1;
static int hf_cipsafety_mcast_byte                = -1;
static int hf_cipsafety_mcast_byte_consumer_num   = -1;
static int hf_cipsafety_mcast_byte_reserved1      = -1;
static int hf_cipsafety_mcast_byte_mai            = -1;
static int hf_cipsafety_mcast_byte_reserved2      = -1;
static int hf_cipsafety_mcast_byte_parity_even    = -1;
static int hf_cipsafety_mcast_byte2               = -1;
static int hf_cipsafety_time_correction           = -1;
static int hf_cipsafety_crc_s5_0                  = -1;
static int hf_cipsafety_crc_s5_1                  = -1;
static int hf_cipsafety_crc_s5_2                  = -1;
static int hf_cipsafety_crc_s5_status             = -1;
static int hf_cipsafety_complement_data           = -1;

/* CIP Safety header field identifiers */
static int hf_cip_reqrsp            = -1;
static int hf_cip_data              = -1;

/* Safety Supervisor header field identifiers */
static int hf_cip_ssupervisor_sc = -1;
static int hf_cip_ssupervisor_recover_data = -1;
static int hf_cip_ssupervisor_perform_diag_data = -1;
static int hf_cip_ssupervisor_configure_request_password = -1;
static int hf_cip_ssupervisor_configure_request_tunid = -1;
static int hf_cip_ssupervisor_configure_request_tunid_ssn_timestamp = -1;
static int hf_cip_ssupervisor_configure_request_tunid_ssn_date = -1;
static int hf_cip_ssupervisor_configure_request_tunid_ssn_time = -1;
static int hf_cip_ssupervisor_configure_request_tunid_macid = -1;
static int hf_cip_ssupervisor_configure_request_ounid = -1;
static int hf_cip_ssupervisor_configure_request_ounid_ssn_timestamp = -1;
static int hf_cip_ssupervisor_configure_request_ounid_ssn_date = -1;
static int hf_cip_ssupervisor_configure_request_ounid_ssn_time = -1;
static int hf_cip_ssupervisor_configure_request_ounid_macid = -1;
static int hf_cip_ssupervisor_validate_configuration_sccrc = -1;
static int hf_cip_ssupervisor_validate_configuration_scts_timestamp = -1;
static int hf_cip_ssupervisor_validate_configuration_scts_date = -1;
static int hf_cip_ssupervisor_validate_configuration_scts_time = -1;
static int hf_cip_ssupervisor_validate_configuration_ext_error = -1;
static int hf_cip_ssupervisor_set_password_current_password = -1;
static int hf_cip_ssupervisor_set_password_new_password = -1;
static int hf_cip_ssupervisor_configure_lock_value = -1;
static int hf_cip_ssupervisor_configure_lock_password = -1;
static int hf_cip_ssupervisor_configure_lock_tunid = -1;
static int hf_cip_ssupervisor_configure_lock_tunid_ssn_timestamp = -1;
static int hf_cip_ssupervisor_configure_lock_tunid_ssn_date = -1;
static int hf_cip_ssupervisor_configure_lock_tunid_ssn_time = -1;
static int hf_cip_ssupervisor_configure_lock_tunid_macid = -1;
static int hf_cip_ssupervisor_mode_change_value = -1;
static int hf_cip_ssupervisor_mode_change_password = -1;
static int hf_cip_ssupervisor_reset_type = -1;
static int hf_cip_ssupervisor_reset_password = -1;
static int hf_cip_ssupervisor_reset_tunid = -1;
static int hf_cip_ssupervisor_reset_tunid_tunid_ssn_timestamp = -1;
static int hf_cip_ssupervisor_reset_tunid_tunid_ssn_date = -1;
static int hf_cip_ssupervisor_reset_tunid_tunid_ssn_time = -1;
static int hf_cip_ssupervisor_reset_tunid_macid = -1;
static int hf_cip_ssupervisor_reset_attr_bitmap = -1;
static int hf_cip_ssupervisor_reset_attr_bitmap_macid = -1;
static int hf_cip_ssupervisor_reset_attr_bitmap_baudrate = -1;
static int hf_cip_ssupervisor_reset_attr_bitmap_tunid = -1;
static int hf_cip_ssupervisor_reset_attr_bitmap_password = -1;
static int hf_cip_ssupervisor_reset_attr_bitmap_cfunid = -1;
static int hf_cip_ssupervisor_reset_attr_bitmap_ocpunid = -1;
static int hf_cip_ssupervisor_reset_attr_bitmap_reserved = -1;
static int hf_cip_ssupervisor_reset_attr_bitmap_extended = -1;
static int hf_cip_ssupervisor_reset_password_data_size = -1;
static int hf_cip_ssupervisor_reset_password_data = -1;
static int hf_cip_ssupervisor_propose_tunid_tunid = -1;
static int hf_cip_ssupervisor_propose_tunid_tunid_ssn_timestamp = -1;
static int hf_cip_ssupervisor_propose_tunid_tunid_ssn_date = -1;
static int hf_cip_ssupervisor_propose_tunid_tunid_ssn_time = -1;
static int hf_cip_ssupervisor_propose_tunid_tunid_macid = -1;
static int hf_cip_ssupervisor_apply_tunid_tunid = -1;
static int hf_cip_ssupervisor_apply_tunid_tunid_ssn_timestamp = -1;
static int hf_cip_ssupervisor_apply_tunid_tunid_ssn_date = -1;
static int hf_cip_ssupervisor_apply_tunid_tunid_ssn_time = -1;
static int hf_cip_ssupervisor_apply_tunid_tunid_macid = -1;

static int hf_cip_ssupervisor_class_subclass = -1;
static int hf_cip_ssupervisor_num_attr = -1;
static int hf_cip_ssupervisor_attr_list = -1;
static int hf_cip_ssupervisor_manufacture_name = -1;
static int hf_cip_ssupervisor_manufacture_model_number = -1;
static int hf_cip_ssupervisor_sw_rev_level = -1;
static int hf_cip_ssupervisor_hw_rev_level = -1;
static int hf_cip_ssupervisor_manufacture_serial_number = -1;
static int hf_cip_ssupervisor_device_config = -1;
static int hf_cip_ssupervisor_device_status = -1;
static int hf_cip_ssupervisor_exception_status = -1;
static int hf_cip_ssupervisor_exception_detail_ced_size = -1;
static int hf_cip_ssupervisor_exception_detail_ced_detail = -1;
static int hf_cip_ssupervisor_exception_detail_ded_size = -1;
static int hf_cip_ssupervisor_exception_detail_ded_detail = -1;
static int hf_cip_ssupervisor_exception_detail_med_size = -1;
static int hf_cip_ssupervisor_exception_detail_med_detail = -1;
static int hf_cip_ssupervisor_alarm_enable = -1;
static int hf_cip_ssupervisor_warning_enable = -1;
static int hf_cip_ssupervisor_time = -1;
static int hf_cip_ssupervisor_clock_power_cycle_behavior = -1;
static int hf_cip_ssupervisor_last_maintenance_date = -1;
static int hf_cip_ssupervisor_next_scheduled_maintenance_date = -1;
static int hf_cip_ssupervisor_scheduled_maintenance_expiration_timer = -1;
static int hf_cip_ssupervisor_scheduled_maintenance_expiration_warning_enable = -1;
static int hf_cip_ssupervisor_run_hours = -1;
static int hf_cip_ssupervisor_configuration_lock = -1;
static int hf_cip_ssupervisor_configuration_unid_ssn_timestamp = -1;
static int hf_cip_ssupervisor_configuration_unid_ssn_date = -1;
static int hf_cip_ssupervisor_configuration_unid_ssn_time = -1;
static int hf_cip_ssupervisor_configuration_unid_macid = -1;
static int hf_cip_ssupervisor_safety_configuration_id_ssn_timestamp = -1;
static int hf_cip_ssupervisor_safety_configuration_id_ssn_date = -1;
static int hf_cip_ssupervisor_safety_configuration_id_ssn_time = -1;
static int hf_cip_ssupervisor_safety_configuration_id_macid = -1;
static int hf_cip_ssupervisor_target_unid_ssn_timestamp = -1;
static int hf_cip_ssupervisor_target_unid_ssn_date = -1;
static int hf_cip_ssupervisor_target_unid_ssn_time = -1;
static int hf_cip_ssupervisor_target_unid_macid = -1;
static int hf_cip_ssupervisor_cp_owners_num_entries = -1;
static int hf_cip_ssupervisor_output_cp_owners_ocpunid_ssn_timestamp = -1;
static int hf_cip_ssupervisor_output_cp_owners_ocpunid_ssn_date = -1;
static int hf_cip_ssupervisor_output_cp_owners_ocpunid_ssn_time = -1;
static int hf_cip_ssupervisor_output_cp_owners_ocpunid_macid = -1;
static int hf_cip_ssupervisor_cp_owners_app_path_size = -1;
static int hf_cip_ssupervisor_proposed_tunid_ssn_timestamp = -1;
static int hf_cip_ssupervisor_proposed_tunid_ssn_date = -1;
static int hf_cip_ssupervisor_proposed_tunid_ssn_time = -1;
static int hf_cip_ssupervisor_proposed_tunid_macid = -1;
static int hf_cip_ssupervisor_instance_subclass = -1;


/* Safety Validator header field identifiers */
static int hf_cip_svalidator_sc = -1;

static int hf_cip_svalidator_sconn_fault_count = -1;
static int hf_cip_svalidator_state = -1;
static int hf_cip_svalidator_type = -1;
static int hf_cip_svalidator_type_pc = -1;
static int hf_cip_svalidator_type_conn_type = -1;
static int hf_cip_svalidator_ping_eri = -1;
static int hf_cip_svalidator_time_coord_msg_min_mult_size = -1;
static int hf_cip_svalidator_time_coord_msg_min_mult_item = -1;
static int hf_cip_svalidator_network_time_multiplier_size = -1;
static int hf_cip_svalidator_network_time_multiplier_item = -1;
static int hf_cip_svalidator_timeout_multiplier_size = -1;
static int hf_cip_svalidator_timeout_multiplier_item = -1;
static int hf_cip_svalidator_max_consumer_num = -1;
static int hf_cip_svalidator_data_conn_inst = -1;
static int hf_cip_svalidator_coordination_conn_inst_size = -1;
static int hf_cip_svalidator_coordination_conn_inst_item = -1;
static int hf_cip_svalidator_correction_conn_inst = -1;
static int hf_cip_svalidator_cco_binding = -1;
static int hf_cip_svalidator_max_data_age = -1;
static int hf_cip_svalidator_error_code = -1;
static int hf_cip_svalidator_prod_cons_fault_count_size = -1;
static int hf_cip_svalidator_prod_cons_fault_count_item = -1;

static int hf_cip_sercosiii_link_snn = -1;
static int hf_cip_sercosiii_link_communication_cycle_time = -1;
static int hf_cip_sercosiii_link_interface_status = -1;
static int hf_cip_sercosiii_link_error_count_mstps = -1;
static int hf_cip_sercosiii_link_sercos_address = -1;
static int hf_cip_sercosiii_link_error_count_p1 = -1;
static int hf_cip_sercosiii_link_error_count_p2 = -1;

/* Initialize the subtree pointers */
static gint ett_cip_safety                = -1;
static gint ett_path                      = -1;
static gint ett_cipsafety_mode_byte       = -1;
static gint ett_cipsafety_ack_byte        = -1;
static gint ett_cipsafety_mcast_byte      = -1;

static gint ett_cip_class_s_supervisor    = -1;
static gint ett_ssupervisor_rrsc          = -1;
static gint ett_ssupervisor_cmd_data      = -1;
static gint ett_ssupervisor_propose_tunid = -1;
static gint ett_ssupervisor_propose_tunid_ssn = -1;
static gint ett_ssupervisor_configure_request_tunid = -1;
static gint ett_ssupervisor_configure_request_tunid_ssn = -1;
static gint ett_ssupervisor_configure_request_ounid = -1;
static gint ett_ssupervisor_configure_request_ounid_ssn = -1;
static gint ett_ssupervisor_configure_lock_tunid = -1;
static gint ett_ssupervisor_configure_lock_tunid_ssn = -1;
static gint ett_ssupervisor_reset_tunid = -1;
static gint ett_ssupervisor_reset_tunid_ssn = -1;
static gint ett_ssupervisor_apply_tunid = -1;
static gint ett_ssupervisor_apply_tunid_ssn = -1;
static gint ett_exception_detail_common = -1;
static gint ett_exception_detail_device = -1;
static gint ett_exception_detail_manufacturer = -1;
static gint ett_ssupervisor_configuration_unid = -1;
static gint ett_ssupervisor_configuration_unid_ssn = -1;
static gint ett_ssupervisor_safety_configuration_id = -1;
static gint ett_ssupervisor_safety_configuration_id_ssn = -1;
static gint ett_ssupervisor_target_unid = -1;
static gint ett_ssupervisor_target_unid_ssn = -1;
static gint ett_ssupervisor_output_cp_owners = -1;
static gint ett_ssupervisor_output_cp_owners_ocpunid = -1;
static gint ett_ssupervisor_output_cp_owners_ocpunid_ssn = -1;
static gint ett_ssupervisor_proposed_tunid = -1;
static gint ett_ssupervisor_proposed_tunid_ssn = -1;
static gint ett_cip_ssupervisor_reset_attr_bitmap = -1;

static gint ett_cip_class_s_validator     = -1;
static gint ett_svalidator_rrsc           = -1;
static gint ett_svalidator_cmd_data       = -1;
static gint ett_svalidator_type           = -1;

static expert_field ei_cipsafety_tbd2_not_complemented = EI_INIT;
static expert_field ei_cipsafety_tbd_not_copied = EI_INIT;
static expert_field ei_cipsafety_run_idle_not_complemented = EI_INIT;
static expert_field ei_mal_io = EI_INIT;
static expert_field ei_mal_sercosiii_link_error_count_p1p2 = EI_INIT;
static expert_field ei_cipsafety_not_complement_data = EI_INIT;
static expert_field ei_cipsafety_crc_s1 = EI_INIT;
static expert_field ei_cipsafety_crc_s2 = EI_INIT;
static expert_field ei_cipsafety_crc_s3 = EI_INIT;
static expert_field ei_cipsafety_complement_crc_s3 = EI_INIT;
static expert_field ei_cipsafety_crc_s5 = EI_INIT;

static expert_field ei_mal_ssupervisor_exception_detail_ced = EI_INIT;
static expert_field ei_mal_ssupervisor_exception_detail_ded = EI_INIT;
static expert_field ei_mal_ssupervisor_exception_detail_med = EI_INIT;
static expert_field ei_mal_ssupervisor_configuration_unid = EI_INIT;
static expert_field ei_mal_ssupervisor_safety_configuration_id = EI_INIT;
static expert_field ei_mal_ssupervisor_target_unid = EI_INIT;
static expert_field ei_mal_ssupervisor_cp_owners = EI_INIT;
static expert_field ei_mal_ssupervisor_cp_owners_entry = EI_INIT;
static expert_field ei_mal_ssupervisor_cp_owners_app_path_size = EI_INIT;
static expert_field ei_mal_ssupervisor_proposed_tunid = EI_INIT;

static expert_field ei_mal_svalidator_type = EI_INIT;
static expert_field ei_mal_svalidator_time_coord_msg_min_mult = EI_INIT;
static expert_field ei_mal_svalidator_network_time_multiplier = EI_INIT;
static expert_field ei_mal_svalidator_timeout_multiplier = EI_INIT;
static expert_field ei_mal_svalidator_coordination_conn_inst = EI_INIT;
static expert_field ei_mal_svalidator_prod_cons_fault_count = EI_INIT;

static dissector_handle_t cipsafety_handle;

typedef struct cip_safety_packet_data {
   guint16 rollover_value;
   guint16 timestamp_value;
} cip_safety_packet_data_t;

#define MODE_BYTE_CRC_S1_MASK  0xE0
#define MODE_BYTE_CRC_S1_TIME_STAMP_MASK  0x1F
#define MODE_BYTE_CRC_S3_MASK  0xE0
#define MODE_BYTE_CRC_S5_BASE_MASK  0xE0
#define MODE_BYTE_CRC_S5_EXTENDED_MASK  0x1F

const value_string cipsafety_ssn_date_vals[8] = {

   { 0,     "NULL SSN" },
   { 1,     "Manual Setting - Backplane" },
   { 2,     "Manual Setting - ControlNet" },
   { 4,     "Manual Setting - EtherNet/IP" },
   { 5,     "Manual Setting - DeviceNet" },
   { 6,     "Manual Setting - SERCOS III" },
   { 65535, "No SSN Set" },

   { 0,     NULL }
};

static const true_false_string cip_safety_vals_active_idle = {
   "Idle",
   "Active"
};

/* Translate function to string - CIP Service codes for Safety Supervisor */
static const value_string cip_sc_vals_ssupervisor[] = {
   GENERIC_SC_LIST

   /* Some class specific services */
   { SC_SSUPER_RECOVER,                "Recover" },
   { SC_SSUPER_PERFORM_DIAGNOSTICS,    "Perform Diagnostics" },
   { SC_SSUPER_CONFIGURE_REQUEST,      "Configure Request" },
   { SC_SSUPER_VALIDATE_CONFIGURATION, "Validate Configuration" },
   { SC_SSUPER_SET_PASSWORD,           "Set Password" },
   { SC_SSUPER_CONFIGURATION_LOCK,     "Configuration (Un)Lock" },
   { SC_SSUPER_MODE_CHANGE,            "Mode Change" },
   { SC_SSUPER_SAFETY_RESET,           "Safety Reset" },
   { SC_SSUPER_RESET_PASSWORD,         "Reset Password" },
   { SC_SSUPER_PROPOSE_TUNID,          "Propose TUNID" },
   { SC_SSUPER_APPLY_TUNID,            "Apply TUNID" },

   { 0,                       NULL }
};

#define SC_SVALID_RESET_ERROR                 0x4B

/* Translate function to string - CIP Service codes for Safety Validator */
static const value_string cip_sc_vals_svalidator[] = {
   GENERIC_SC_LIST

   /* Some class specific services */
   { SC_SVALID_RESET_ERROR,                "Reset Error" },

   { 0,                       NULL }
};

static const value_string cip_ssupervisor_validate_configuration_ext_error_vals[] = {
   { 1,        "CRC mismatch" },
   { 2,        "Invalid Configuration Parameter"     },
   { 3,        "TUNID Not Set"     },

   { 0,        NULL          }
};

static const value_string cip_ssupervisor_lock_vals[] = {
   { 0,        "Unlocked" },
   { 1,        "Locked"     },

   { 0,        NULL          }
};

static const value_string cip_ssupervisor_change_mode_vals[] = {
   { 0,        "Idle" },
   { 1,        "Executing"   },

   { 0,        NULL          }
};

static const value_string cip_ssupervisor_device_status_type_vals[] = {
   { 0,        "Undefined" },
   { 1,        "Self-Testing"   },
   { 2,        "Idle"   },
   { 3,        "Self-Testing Exception"   },
   { 4,        "Executing"   },
   { 5,        "Abort"   },
   { 6,        "Critical Fault"   },
   { 7,        "Configuring"   },
   { 8,        "Waiting for TUNID"   },

   { 0,        NULL          }
};

static const value_string cip_ssupervisor_clock_power_cycle_type_vals[] = {
   { 0,        "Clock always resets" },
   { 1,        "Clock in NVS at power down"   },
   { 2,        "Clock is battery-backed"   },

   { 0,        NULL          }
};

static const value_string cip_svalidator_state_vals[] = {
   { 0,        "Unallocated" },
   { 1,        "Initializing"   },
   { 2,        "Established"   },
   { 3,        "Connection failed"   },

   { 0,        NULL          }
};

static const value_string cip_svalidator_type_pc_vals[] = {
   { 0,        "Producer" },
   { 1,        "Consumer" },

   { 0,        NULL          }
};

static const value_string cip_svalidator_type_conn_type_vals[] = {
   { 0,        "Unallocated" },
   { 1,        "Single-cast" },
   { 2,        "Multi-cast"  },

   { 0,        NULL          }
};

void
dissect_unid(tvbuff_t *tvb, packet_info *pinfo, int offset, proto_item *pi,
             const char* ssn_name, int hf_ssn_timestamp,
             int hf_ssn_date, int hf_ssn_time, int hf_macid, gint ett, gint ett_ssn)
{
   proto_tree *tree, *ssn_tree;

   tree = proto_item_add_subtree(pi, ett);

   ssn_tree = proto_tree_add_subtree(tree, tvb, offset, 6, ett_ssn, NULL, ssn_name);
   dissect_cipsafety_ssn(ssn_tree, tvb, pinfo, offset, hf_ssn_timestamp, hf_ssn_date, hf_ssn_time);

   proto_tree_add_item(tree, hf_macid, tvb, offset+6, 4, ENC_LITTLE_ENDIAN);
}

void dissect_cipsafety_ssn(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, int offset,
                           int hf_real_datetime, int hf_date, int hf_time)
{
   guint16 date;

   date = tvb_get_letohs( tvb, offset);

   if ((date >= 11688) && (date <= 65534))
   {
      /* value is an actual timestamp */
      dissect_cip_date_and_time(tree, tvb, offset, hf_real_datetime);
   }
   else
   {
      /* Treated as UINT16 and UINT32 values */
      proto_tree_add_item(tree, hf_date, tvb, offset, 2, ENC_LITTLE_ENDIAN);
      proto_tree_add_item(tree, hf_time, tvb, offset+2, 4, ENC_LITTLE_ENDIAN);
   }
}

/************************************************
 *
 * Dissector for CIP Safety Supervisor Object
 *
 ************************************************/
static void
dissect_cip_s_supervisor_data( proto_tree *item_tree,
                               tvbuff_t *tvb, int offset, int item_length, packet_info *pinfo )
{
   proto_item                *pi, *rrsc_item;
   proto_tree                *rrsc_tree, *cmd_data_tree, *bitmap_tree;
   int                        req_path_size;
   int                        temp_data;
   guint8                     service, gen_status, add_stat_size;
   cip_simple_request_info_t  req_data;

   col_set_str(pinfo->cinfo, COL_PROTOCOL, "CIPS Supervisor");

   /* Add Service code & Request/Response tree */
   service   = tvb_get_guint8( tvb, offset );
   rrsc_tree = proto_tree_add_subtree( item_tree, tvb, offset, 1, ett_ssupervisor_rrsc, &rrsc_item, "Service: " );

   /* Add Request/Response */
   proto_tree_add_item( rrsc_tree, hf_cip_reqrsp, tvb, offset, 1, ENC_LITTLE_ENDIAN );

   proto_item_append_text( rrsc_item, "%s (%s)",
               val_to_str( ( service & CIP_SC_MASK ), cip_sc_vals_ssupervisor , "Unknown Service (0x%02x)"),
               val_to_str_const( ( service & CIP_SC_RESPONSE_MASK )>>7, cip_sc_rr, "") );

   /* Add Service code */
   proto_tree_add_item(rrsc_tree, hf_cip_ssupervisor_sc, tvb, offset, 1, ENC_LITTLE_ENDIAN );

   load_cip_request_data(pinfo, &req_data);

   if (service & CIP_SC_RESPONSE_MASK)
   {
      /* Response message */

      /* Add additional status size */
      gen_status = tvb_get_guint8( tvb, offset+2 );
      add_stat_size = tvb_get_guint8( tvb, offset+3 ) * 2;

      /* If there is any command specific data create a sub-tree for it */
      if( ( item_length-4-add_stat_size ) != 0 )
      {
         cmd_data_tree = proto_tree_add_subtree( item_tree, tvb, offset+4+add_stat_size,
                         item_length-4-add_stat_size, ett_ssupervisor_cmd_data, NULL, "Command Specific Data" );

         if( gen_status == CI_GRC_SUCCESS || gen_status == CI_GRC_SERVICE_ERROR )
         {
            switch (service & CIP_SC_MASK)
            {
            case SC_SSUPER_VALIDATE_CONFIGURATION:
               proto_tree_add_item(cmd_data_tree, hf_cip_ssupervisor_validate_configuration_sccrc,
                         tvb, offset+4+add_stat_size, 4, ENC_LITTLE_ENDIAN);
               dissect_cipsafety_ssn(cmd_data_tree,
                         tvb, pinfo, offset+4+add_stat_size+4,
                         hf_cip_ssupervisor_validate_configuration_scts_timestamp,
                         hf_cip_ssupervisor_validate_configuration_scts_date,
                         hf_cip_ssupervisor_validate_configuration_scts_time);
               break;
            }
         }
         else if ((gen_status == 0xD0) && ((service & CIP_SC_MASK) == SC_SSUPER_VALIDATE_CONFIGURATION))
         {
            if (add_stat_size > 0)
            {
               proto_tree_add_item(cmd_data_tree, hf_cip_ssupervisor_validate_configuration_ext_error,
                         tvb, offset+4, 2, ENC_LITTLE_ENDIAN);
            }
         }
         else
         {
            /* Error responses */

            /* Add data */
            proto_tree_add_item(cmd_data_tree, hf_cip_data,
                         tvb, offset+4+add_stat_size, item_length-4-add_stat_size, ENC_NA);
         }
      }

   } /* End of if reply */
   else
   {
      /* Request message */

      req_path_size = tvb_get_guint8( tvb, offset+1 )*2;

      /* If there is any command specific data create a sub-tree for it */
      if( (item_length-req_path_size-2) != 0 )
      {
         cmd_data_tree = proto_tree_add_subtree( item_tree, tvb, offset+2+req_path_size, item_length-req_path_size-2,
                                   ett_ssupervisor_cmd_data, NULL, "Command Specific Data" );

         /* Check what service code that received */
         switch (service)
         {
         case SC_SSUPER_RECOVER:
            proto_tree_add_item(cmd_data_tree, hf_cip_ssupervisor_recover_data,
                         tvb, offset+2+req_path_size, item_length-req_path_size-2, ENC_NA);
            break;
         case SC_SSUPER_PERFORM_DIAGNOSTICS:
            proto_tree_add_item(cmd_data_tree, hf_cip_ssupervisor_perform_diag_data,
                         tvb, offset+2+req_path_size, item_length-req_path_size-2, ENC_NA);
            break;
         case SC_SSUPER_CONFIGURE_REQUEST:
            proto_tree_add_item(cmd_data_tree, hf_cip_ssupervisor_configure_request_password,
                         tvb, offset+2+req_path_size, 16, ENC_NA);
            pi = proto_tree_add_item(cmd_data_tree, hf_cip_ssupervisor_configure_request_tunid,
                         tvb, offset+2+req_path_size+16, 10, ENC_NA);
            dissect_unid(tvb, pinfo, offset+2+req_path_size+16, pi, "TUNID SSN",
                         hf_cip_ssupervisor_configure_request_tunid_ssn_timestamp,
                         hf_cip_ssupervisor_configure_request_tunid_ssn_date,
                         hf_cip_ssupervisor_configure_request_tunid_ssn_time,
                         hf_cip_ssupervisor_configure_request_tunid_macid,
                         ett_ssupervisor_configure_request_tunid,
                         ett_ssupervisor_configure_request_tunid_ssn);
            pi = proto_tree_add_item(cmd_data_tree, hf_cip_ssupervisor_configure_request_ounid,
                                     tvb, offset+2+req_path_size+26, 10, ENC_NA);
            dissect_unid(tvb, pinfo, offset+2+req_path_size+16, pi, "OUNID SSN",
                         hf_cip_ssupervisor_configure_request_ounid_ssn_timestamp,
                         hf_cip_ssupervisor_configure_request_ounid_ssn_date,
                         hf_cip_ssupervisor_configure_request_ounid_ssn_time,
                         hf_cip_ssupervisor_configure_request_ounid_macid,
                         ett_ssupervisor_configure_request_ounid,
                         ett_ssupervisor_configure_request_ounid_ssn);
            break;
         case SC_SSUPER_VALIDATE_CONFIGURATION:
            proto_tree_add_item(cmd_data_tree, hf_cip_ssupervisor_validate_configuration_sccrc,
                         tvb, offset+2+req_path_size, 4, ENC_LITTLE_ENDIAN);
            dissect_cipsafety_ssn(cmd_data_tree, tvb, pinfo, offset+2+req_path_size+4,
                         hf_cip_ssupervisor_validate_configuration_scts_timestamp,
                         hf_cip_ssupervisor_validate_configuration_scts_date,
                         hf_cip_ssupervisor_validate_configuration_scts_time);
            break;
         case SC_SSUPER_SET_PASSWORD:
            proto_tree_add_item(cmd_data_tree, hf_cip_ssupervisor_set_password_current_password,
                         tvb, offset+2+req_path_size, 16, ENC_NA);
            proto_tree_add_item(cmd_data_tree, hf_cip_ssupervisor_set_password_new_password,
                         tvb, offset+2+req_path_size+16, 16, ENC_NA);
            break;
         case SC_SSUPER_CONFIGURATION_LOCK:
            proto_tree_add_item(cmd_data_tree, hf_cip_ssupervisor_configure_lock_value,
                         tvb, offset+2+req_path_size+1, 1, ENC_LITTLE_ENDIAN);
            proto_tree_add_item(cmd_data_tree, hf_cip_ssupervisor_configure_lock_password,
                         tvb, offset+2+req_path_size+1, 16, ENC_NA);
            pi = proto_tree_add_item(cmd_data_tree, hf_cip_ssupervisor_configure_lock_tunid,
                         tvb, offset+2+req_path_size+17, 10, ENC_NA);
            dissect_unid(tvb, pinfo, offset+2+req_path_size+17, pi, "TUNID SSN",
                         hf_cip_ssupervisor_configure_lock_tunid_ssn_timestamp,
                         hf_cip_ssupervisor_configure_lock_tunid_ssn_date,
                         hf_cip_ssupervisor_configure_lock_tunid_ssn_time,
                         hf_cip_ssupervisor_configure_lock_tunid_macid,
                         ett_ssupervisor_configure_lock_tunid,
                         ett_ssupervisor_configure_lock_tunid_ssn);
            break;
         case SC_SSUPER_MODE_CHANGE:
            proto_tree_add_item(cmd_data_tree, hf_cip_ssupervisor_mode_change_value,
                         tvb, offset+2+req_path_size+1, 1, ENC_LITTLE_ENDIAN);
            proto_tree_add_item(cmd_data_tree, hf_cip_ssupervisor_mode_change_password,
                         tvb, offset+2+req_path_size+1, 16, ENC_NA);
            break;
         case SC_SSUPER_SAFETY_RESET:
            proto_tree_add_item(cmd_data_tree, hf_cip_ssupervisor_reset_type,
                         tvb, offset+2+req_path_size+1, 1, ENC_LITTLE_ENDIAN);
            temp_data = tvb_get_guint8( tvb, offset+2+req_path_size+1 );
            proto_tree_add_item(cmd_data_tree, hf_cip_ssupervisor_reset_password,
                         tvb, offset+2+req_path_size+1, 16, ENC_NA);
            pi = proto_tree_add_item(cmd_data_tree, hf_cip_ssupervisor_reset_tunid,
                         tvb, offset+2+req_path_size+17, 10, ENC_NA);
            dissect_unid(tvb, pinfo, offset+2+req_path_size+17, pi, "TUNID SSN",
                         hf_cip_ssupervisor_reset_tunid_tunid_ssn_timestamp,
                         hf_cip_ssupervisor_reset_tunid_tunid_ssn_date,
                         hf_cip_ssupervisor_reset_tunid_tunid_ssn_time,
                         hf_cip_ssupervisor_reset_tunid_macid,
                         ett_ssupervisor_reset_tunid,
                         ett_ssupervisor_reset_tunid_ssn);
            /* Attribute bitmap only included on Reset Type 2 */
            if (temp_data == 2)
            {
               pi = proto_tree_add_item(cmd_data_tree, hf_cip_ssupervisor_reset_attr_bitmap,
                         tvb, offset+2+req_path_size+27, 1, ENC_LITTLE_ENDIAN);
               bitmap_tree = proto_item_add_subtree(pi, ett_cip_ssupervisor_reset_attr_bitmap);
               proto_tree_add_item(bitmap_tree, hf_cip_ssupervisor_reset_attr_bitmap_macid,
                         tvb, offset+2+req_path_size+27, 1, ENC_LITTLE_ENDIAN);
               proto_tree_add_item(bitmap_tree, hf_cip_ssupervisor_reset_attr_bitmap_baudrate,
                         tvb, offset+2+req_path_size+27, 1, ENC_LITTLE_ENDIAN);
               proto_tree_add_item(bitmap_tree, hf_cip_ssupervisor_reset_attr_bitmap_tunid,
                         tvb, offset+2+req_path_size+27, 1, ENC_LITTLE_ENDIAN);
               proto_tree_add_item(bitmap_tree, hf_cip_ssupervisor_reset_attr_bitmap_password,
                         tvb, offset+2+req_path_size+27, 1, ENC_LITTLE_ENDIAN);
               proto_tree_add_item(bitmap_tree, hf_cip_ssupervisor_reset_attr_bitmap_cfunid,
                         tvb, offset+2+req_path_size+27, 1, ENC_LITTLE_ENDIAN);
               proto_tree_add_item(bitmap_tree, hf_cip_ssupervisor_reset_attr_bitmap_ocpunid,
                         tvb, offset+2+req_path_size+27, 1, ENC_LITTLE_ENDIAN);
               proto_tree_add_item(bitmap_tree, hf_cip_ssupervisor_reset_attr_bitmap_reserved,
                         tvb, offset+2+req_path_size+27, 1, ENC_LITTLE_ENDIAN);
               proto_tree_add_item(bitmap_tree, hf_cip_ssupervisor_reset_attr_bitmap_extended,
                         tvb, offset+2+req_path_size+27, 1, ENC_LITTLE_ENDIAN);
            }
            break;
         case SC_SSUPER_RESET_PASSWORD:
            proto_tree_add_item(cmd_data_tree, hf_cip_ssupervisor_reset_password_data_size,
                         tvb, offset+2+req_path_size, 1, ENC_LITTLE_ENDIAN);
            temp_data = tvb_get_guint8(tvb, offset+2+req_path_size);
            proto_tree_add_item(cmd_data_tree, hf_cip_ssupervisor_reset_password_data,
                         tvb, offset+2+req_path_size+1, temp_data, ENC_NA);
            break;
         case SC_SSUPER_PROPOSE_TUNID:
            pi = proto_tree_add_item(cmd_data_tree, hf_cip_ssupervisor_propose_tunid_tunid,
                         tvb, offset+2+req_path_size, 10, ENC_NA);
            dissect_unid(tvb, pinfo, offset+2+req_path_size, pi, "TUNID SSN",
                         hf_cip_ssupervisor_propose_tunid_tunid_ssn_timestamp,
                         hf_cip_ssupervisor_propose_tunid_tunid_ssn_date,
                         hf_cip_ssupervisor_propose_tunid_tunid_ssn_time,
                         hf_cip_ssupervisor_propose_tunid_tunid_macid,
                         ett_ssupervisor_propose_tunid,
                         ett_ssupervisor_propose_tunid_ssn);
            break;
         case SC_SSUPER_APPLY_TUNID:
            pi = proto_tree_add_item(cmd_data_tree, hf_cip_ssupervisor_apply_tunid_tunid,
                         tvb, offset+2+req_path_size, 10, ENC_NA);
            dissect_unid(tvb, pinfo, offset+2+req_path_size, pi, "TUNID SSN",
                         hf_cip_ssupervisor_apply_tunid_tunid_ssn_timestamp,
                         hf_cip_ssupervisor_apply_tunid_tunid_ssn_date,
                         hf_cip_ssupervisor_apply_tunid_tunid_ssn_time,
                         hf_cip_ssupervisor_apply_tunid_tunid_macid,
                         ett_ssupervisor_apply_tunid,
                         ett_ssupervisor_apply_tunid_ssn);
            break;
         default:
            proto_tree_add_item(cmd_data_tree, hf_cip_data,
                         tvb, offset+2+req_path_size, item_length-req_path_size-2, ENC_NA);
         }

      } /* End of if command-specific data present */

   } /* End of if-else( request ) */

   add_cip_service_to_info_column(pinfo, service, cip_sc_vals_ssupervisor);
}

static int
dissect_cip_class_s_supervisor(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
{
   proto_item *ti;
   proto_tree *class_tree;

   /* Create display subtree for the protocol */
   ti = proto_tree_add_item(tree, proto_cip_class_s_supervisor, tvb, 0, -1, ENC_NA);
   class_tree = proto_item_add_subtree( ti, ett_cip_class_s_supervisor );

   dissect_cip_s_supervisor_data( class_tree, tvb, 0, tvb_reported_length(tvb), pinfo );

   return tvb_reported_length(tvb);
}

static int dissect_s_supervisor_exception_detail(proto_tree *tree, proto_item *item, tvbuff_t *tvb, int offset, int hf_size, int hf_data)
{
   int size;

   proto_tree_add_item(tree, hf_size, tvb, offset, 1, ENC_LITTLE_ENDIAN );
   size = tvb_get_guint8( tvb, offset);
   proto_tree_add_item(tree, hf_data, tvb, offset+1, size, ENC_NA );
   proto_item_set_len(item, size+1);

   return size+1;
}

static int dissect_s_supervisor_exception_detail_common(packet_info *pinfo, proto_tree *tree, proto_item *item, tvbuff_t *tvb,
                             int offset, int total_len)
{
   proto_item *pi;
   proto_tree *item_tree;
   int total_size = 0, size;

   item_tree = proto_tree_add_subtree(tree, tvb, offset, 1, ett_exception_detail_common, &pi, "Common Exception Detail");
   size = dissect_s_supervisor_exception_detail(item_tree, pi, tvb, offset,
               hf_cip_ssupervisor_exception_detail_ced_size,
               hf_cip_ssupervisor_exception_detail_ced_detail);
   if (size == 0)
   {
      expert_add_info(pinfo, item, &ei_mal_ssupervisor_exception_detail_ced);
      return total_len;
   }
   total_size += size;

   item_tree = proto_tree_add_subtree(tree, tvb, offset + total_size, 1, ett_exception_detail_device, &pi, "Device Exception Detail");
   size = dissect_s_supervisor_exception_detail(item_tree, pi, tvb, offset + total_size,
               hf_cip_ssupervisor_exception_detail_ded_size,
               hf_cip_ssupervisor_exception_detail_ded_detail);
   if (size == 0)
   {
      expert_add_info(pinfo, item, &ei_mal_ssupervisor_exception_detail_ded);
      return total_len;
   }
   total_size += size;

   item_tree = proto_tree_add_subtree(tree, tvb, offset + total_size, 1, ett_exception_detail_manufacturer, &pi, "Manufacturer Exception Detail");
   size = dissect_s_supervisor_exception_detail(item_tree, pi, tvb, offset + total_size,
               hf_cip_ssupervisor_exception_detail_med_size,
               hf_cip_ssupervisor_exception_detail_med_detail);
   if (size == 0)
   {
      expert_add_info(pinfo, item, &ei_mal_ssupervisor_exception_detail_med);
      return total_len;
   }
   total_size += size;

   return total_size;
}

static int dissect_s_supervisor_configuration_unid(packet_info *pinfo, proto_tree *tree _U_, proto_item *item,
                                                   tvbuff_t *tvb, int offset, int total_len)
{
   if (total_len < 10)
   {
      expert_add_info(pinfo, item, &ei_mal_ssupervisor_configuration_unid);
      return total_len;
   }

   dissect_unid(tvb, pinfo, offset, item, "CFUNID SSN",
                  hf_cip_ssupervisor_configuration_unid_ssn_timestamp,
                  hf_cip_ssupervisor_configuration_unid_ssn_date,
                  hf_cip_ssupervisor_configuration_unid_ssn_time,
                  hf_cip_ssupervisor_configuration_unid_macid,
                  ett_ssupervisor_configuration_unid,
                  ett_ssupervisor_configuration_unid_ssn);
   return 10;
}

static int dissect_s_supervisor_safety_configuration_id(packet_info *pinfo, proto_tree *tree _U_, proto_item *item,
                                                        tvbuff_t *tvb, int offset, int total_len)
{
   if (total_len < 10)
   {
      expert_add_info(pinfo, item, &ei_mal_ssupervisor_safety_configuration_id);
      return total_len;
   }

   dissect_unid(tvb, pinfo, offset, item, "SCID SSN",
                  hf_cip_ssupervisor_safety_configuration_id_ssn_timestamp,
                  hf_cip_ssupervisor_safety_configuration_id_ssn_date,
                  hf_cip_ssupervisor_safety_configuration_id_ssn_time,
                  hf_cip_ssupervisor_safety_configuration_id_macid,
                  ett_ssupervisor_safety_configuration_id,
                  ett_ssupervisor_safety_configuration_id_ssn);
   return 10;
}

static int dissect_s_supervisor_target_unid(packet_info *pinfo, proto_tree *tree _U_, proto_item *item,
                                            tvbuff_t *tvb, int offset, int total_len)
{
   if (total_len < 10)
   {
      expert_add_info(pinfo, item, &ei_mal_ssupervisor_target_unid);
      return total_len;
   }

   dissect_unid(tvb, pinfo, offset, item, "TUNID SSN",
                  hf_cip_ssupervisor_target_unid_ssn_timestamp,
                  hf_cip_ssupervisor_target_unid_ssn_date,
                  hf_cip_ssupervisor_target_unid_ssn_time,
                  hf_cip_ssupervisor_target_unid_macid,
                  ett_ssupervisor_target_unid,
                  ett_ssupervisor_target_unid_ssn);
   return 10;
}

static int dissect_s_supervisor_output_connection_point_owners(packet_info *pinfo, proto_tree *tree, proto_item *item,
                                                               tvbuff_t *tvb, int offset, int total_len)
{
   guint16     i, num_entries;
   proto_item *entry_item, *app_path_item;
   proto_tree *entry_tree, *epath_tree;
   int         attr_len = 0, app_path_size;

   if (total_len < 2)
   {
      expert_add_info(pinfo, item, &ei_mal_ssupervisor_cp_owners);
      return total_len;
   }

   entry_item = proto_tree_add_item(tree, hf_cip_ssupervisor_cp_owners_num_entries,
                         tvb, offset, 2, ENC_LITTLE_ENDIAN );
   num_entries = tvb_get_letohs(tvb, offset);
   attr_len += 2;

   if (num_entries > 0)
   {
      entry_tree = proto_item_add_subtree(entry_item, ett_ssupervisor_output_cp_owners);

      for (i = 0; i < num_entries; i++)
      {
         if (total_len < attr_len+11)
         {
            expert_add_info(pinfo, item, &ei_mal_ssupervisor_cp_owners_entry);
            return total_len;
         }

         dissect_unid(tvb, pinfo, offset+attr_len, entry_item, "OCPUNID SSN",
                         hf_cip_ssupervisor_output_cp_owners_ocpunid_ssn_timestamp,
                         hf_cip_ssupervisor_output_cp_owners_ocpunid_ssn_date,
                         hf_cip_ssupervisor_output_cp_owners_ocpunid_ssn_time,
                         hf_cip_ssupervisor_output_cp_owners_ocpunid_macid,
                         ett_ssupervisor_output_cp_owners_ocpunid,
                         ett_ssupervisor_output_cp_owners_ocpunid_ssn);
         attr_len += 10;

         proto_tree_add_item(entry_tree, hf_cip_ssupervisor_cp_owners_app_path_size,
                         tvb, offset+attr_len, 1, ENC_LITTLE_ENDIAN );
         app_path_size = tvb_get_guint8( tvb, offset+attr_len);
         attr_len += 1;

         if (total_len < attr_len+app_path_size)
         {
            expert_add_info(pinfo, item, &ei_mal_ssupervisor_cp_owners_app_path_size);
            return total_len;
         }

         epath_tree = proto_tree_add_subtree(entry_tree,
                         tvb, offset+attr_len, app_path_size, ett_path, &app_path_item, "Application Resource: ");
         dissect_epath(tvb, pinfo, epath_tree, app_path_item, offset+attr_len, app_path_size, FALSE, TRUE, NULL, NULL, NO_DISPLAY, NULL, FALSE);
         attr_len += app_path_size;
      }
   }

   return attr_len;
}

static int dissect_s_supervisor_proposed_tunid(packet_info *pinfo, proto_tree *tree _U_, proto_item *item,
                                               tvbuff_t *tvb, int offset, int total_len)
{
   if (total_len < 10)
   {
      expert_add_info(pinfo, item, &ei_mal_ssupervisor_proposed_tunid);
      return total_len;
   }

   dissect_unid(tvb, pinfo, offset, item, "Proposed TUNID SSN",
                  hf_cip_ssupervisor_proposed_tunid_ssn_timestamp,
                  hf_cip_ssupervisor_proposed_tunid_ssn_date,
                  hf_cip_ssupervisor_proposed_tunid_ssn_time,
                  hf_cip_ssupervisor_proposed_tunid_macid,
                  ett_ssupervisor_proposed_tunid,
                  ett_ssupervisor_proposed_tunid_ssn);
   return 10;
}

/************************************************
 *
 * Dissector for CIP Safety Validator Object
 *
 ************************************************/
static int dissect_s_validator_type(packet_info *pinfo, proto_tree *tree, proto_item *item, tvbuff_t *tvb,
                                    int offset, int total_len)
{
   proto_item *pi;
   proto_tree *item_tree;

   if (total_len < 1)
   {
      expert_add_info(pinfo, item, &ei_mal_svalidator_type);
      return total_len;
   }

   pi = proto_tree_add_item(tree, hf_cip_svalidator_type, tvb, offset, 1, ENC_LITTLE_ENDIAN );
   item_tree = proto_item_add_subtree(pi, ett_svalidator_type);
   proto_tree_add_item(item_tree, hf_cip_svalidator_type_pc, tvb, offset, 1, ENC_LITTLE_ENDIAN );
   proto_tree_add_item(item_tree, hf_cip_svalidator_type_conn_type, tvb, offset, 1, ENC_LITTLE_ENDIAN );
   return 1;
}

static int dissect_s_validator_time_coord_msg_min_mult(packet_info *pinfo, proto_tree *tree, proto_item *item,
                                                       tvbuff_t *tvb, int offset, int total_len)
{
   int i, size;

   proto_tree_add_item(tree, hf_cip_svalidator_time_coord_msg_min_mult_size,
                         tvb, offset, 1, ENC_LITTLE_ENDIAN );
   size = tvb_get_guint8( tvb, offset )*2;

   if (total_len < size+1)
   {
      expert_add_info(pinfo, item, &ei_mal_svalidator_time_coord_msg_min_mult);
      return total_len;
   }

   for (i = 0; i < size; i+=2)
   {
      proto_tree_add_item(tree, hf_cip_svalidator_time_coord_msg_min_mult_item,
                         tvb, offset+1+i, 2, ENC_LITTLE_ENDIAN );
   }

   return (size+1);
}

static int dissect_s_validator_network_time_multiplier(packet_info *pinfo, proto_tree *tree, proto_item *item,
                                                       tvbuff_t *tvb, int offset, int total_len)
{
   int i, size;

   proto_tree_add_item(tree, hf_cip_svalidator_network_time_multiplier_size,
                       tvb, offset, 1, ENC_LITTLE_ENDIAN );
   size = tvb_get_guint8( tvb, offset )*2;

   if (total_len < size+1)
   {
      expert_add_info(pinfo, item, &ei_mal_svalidator_network_time_multiplier);
      return total_len;
   }

   for (i = 0; i < size; i+=2)
   {
      proto_tree_add_item(tree, hf_cip_svalidator_network_time_multiplier_item,
                          tvb, offset+1+i, 2, ENC_LITTLE_ENDIAN );
   }

   return (size+1);
}

static int dissect_s_validator_timeout_multiplier(packet_info *pinfo, proto_tree *tree, proto_item *item, tvbuff_t *tvb,
                             int offset, int total_len)
{
   int i, size;

   proto_tree_add_item(tree, hf_cip_svalidator_timeout_multiplier_size,
                       tvb, offset, 1, ENC_LITTLE_ENDIAN );
   size = tvb_get_guint8( tvb, offset );

   if (total_len < size+1)
   {
      expert_add_info(pinfo, item, &ei_mal_svalidator_timeout_multiplier);
      return total_len;
   }

   for (i = 0; i < size; i++)
   {
      proto_tree_add_item(tree, hf_cip_svalidator_timeout_multiplier_item,
                          tvb, offset+1+i, 1, ENC_LITTLE_ENDIAN );
   }

   return (size+1);
}

static int dissect_s_validator_coordination_conn_inst(packet_info *pinfo, proto_tree *tree, proto_item *item,
                                                      tvbuff_t *tvb, int offset, int total_len)
{
   int i, size;

   proto_tree_add_item(tree, hf_cip_svalidator_coordination_conn_inst_size,
                       tvb, offset, 1, ENC_LITTLE_ENDIAN );
   size = tvb_get_guint8( tvb, offset )*2;

   if (total_len < size+1)
   {
      expert_add_info(pinfo, item, &ei_mal_svalidator_coordination_conn_inst);
      return total_len;
   }

   for (i = 0; i < size; i+=2)
   {
      proto_tree_add_item(tree, hf_cip_svalidator_coordination_conn_inst_item,
                          tvb, offset+1+i, 2, ENC_LITTLE_ENDIAN );
   }

   return (size+1);
}

static int dissect_s_validator_app_data_path(packet_info *pinfo, proto_tree *tree,
                                             proto_item *item _U_, tvbuff_t *tvb, int offset, int total_len)
{
   proto_item* pi;
   proto_tree* epath_tree = proto_tree_add_subtree(tree, tvb, 0, 0, ett_path, &pi, "Application Data Path: ");
   dissect_epath(tvb, pinfo, epath_tree, pi, offset, total_len, FALSE, FALSE, NULL, NULL, NO_DISPLAY, NULL, FALSE);
   return total_len;
}

static int dissect_s_validator_prod_cons_fault_count(packet_info *pinfo, proto_tree *tree, proto_item *item,
                                                     tvbuff_t *tvb, int offset, int total_len)
{
   int i, size;

   proto_tree_add_item(tree, hf_cip_svalidator_prod_cons_fault_count_size,
                         tvb, offset, 1, ENC_LITTLE_ENDIAN );
   size = tvb_get_guint8( tvb, offset );

   if (total_len < size+1)
   {
      expert_add_info(pinfo, item, &ei_mal_svalidator_prod_cons_fault_count);
      return total_len;
   }

   for (i = 0; i < size; i++)
   {
      proto_tree_add_item(tree, hf_cip_svalidator_prod_cons_fault_count_item,
                         tvb, offset+1+i, 1, ENC_LITTLE_ENDIAN );
   }

   return (size+1);
}

static void
dissect_cip_s_validator_data( proto_tree *item_tree,
                              tvbuff_t *tvb, int offset, int item_length, packet_info *pinfo )
{
   proto_item                *pi, *rrsc_item;
   proto_tree                *rrsc_tree, *cmd_data_tree;
   int                        req_path_size;
   guint8                     service, gen_status, add_stat_size;
   cip_simple_request_info_t  req_data;

   col_set_str(pinfo->cinfo, COL_PROTOCOL, "CIPS Validator");

   /* Add Service code & Request/Response tree */
   service   = tvb_get_guint8( tvb, offset );
   rrsc_tree = proto_tree_add_subtree( item_tree, tvb, offset, 1, ett_svalidator_rrsc, &rrsc_item, "Service: " );

   /* Add Request/Response */
   proto_tree_add_item( rrsc_tree, hf_cip_reqrsp, tvb, offset, 1, ENC_LITTLE_ENDIAN );

   proto_item_append_text( rrsc_item, "%s (%s)",
               val_to_str( ( service & CIP_SC_MASK ),
                  cip_sc_vals_svalidator , "Unknown Service (0x%02x)"),
               val_to_str_const( ( service & CIP_SC_RESPONSE_MASK )>>7,
                  cip_sc_rr, "") );

   /* Add Service code */
   proto_tree_add_item(rrsc_tree, hf_cip_svalidator_sc, tvb, offset, 1, ENC_LITTLE_ENDIAN );

   load_cip_request_data(pinfo, &req_data);

   if (service & CIP_SC_RESPONSE_MASK)
   {
      /* Response message */

      /* Add additional status size */
      gen_status = tvb_get_guint8( tvb, offset+2 );
      add_stat_size = tvb_get_guint8( tvb, offset+3 ) * 2;

      /* If there is any command specific data create a sub-tree for it */
      if( ( item_length-4-add_stat_size ) != 0 )
      {
         cmd_data_tree = proto_tree_add_subtree( item_tree, tvb, offset+4+add_stat_size, item_length-4-add_stat_size,
                                ett_ssupervisor_cmd_data, &pi, "Command Specific Data" );

         if( gen_status == CI_GRC_SUCCESS || gen_status == CI_GRC_SERVICE_ERROR )
         {
            /* Success responses */
            if (((service & CIP_SC_MASK) == SC_GET_ATT_ALL) &&
                (req_data.iInstance != (guint32)-1) &&
                (req_data.iInstance != 0))
            {
                dissect_cip_get_attribute_all_rsp(tvb, pinfo, cmd_data_tree, offset + 4 + add_stat_size, &req_data);
            }
            else
            {
               /* Add data */
               proto_tree_add_item(cmd_data_tree, hf_cip_data,
                                   tvb, offset+4+add_stat_size, item_length-4-add_stat_size, ENC_NA);
            }
         }
         else
         {
            /* Error responses */

            /* Add data */
            proto_tree_add_item(cmd_data_tree, hf_cip_data,
                                tvb, offset+4+add_stat_size, item_length-4-add_stat_size, ENC_NA);
         } /* end of if-else( CI_CRC_SUCCESS ) */

      } /* End of if command-specific data present */

   } /* End of if reply */
   else
   {
      /* Request message */

      req_path_size = tvb_get_guint8( tvb, offset+1 )*2;

      /* If there is any command specific data create a sub-tree for it */
      if( (item_length-req_path_size-2) != 0 )
      {
         cmd_data_tree = proto_tree_add_subtree( item_tree, tvb, offset+2+req_path_size, item_length-req_path_size-2,
                                                ett_ssupervisor_cmd_data, NULL, "Command Specific Data" );
         proto_tree_add_item(cmd_data_tree, hf_cip_data,
                         tvb, offset+2+req_path_size, item_length-req_path_size-2, ENC_NA);
      }

   }

   add_cip_service_to_info_column(pinfo, service, cip_sc_vals_svalidator);
}

static int
dissect_cip_class_s_validator(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
{
   proto_item *ti;
   proto_tree *class_tree;

   /* Create display subtree for the protocol */
   ti = proto_tree_add_item(tree, proto_cip_class_s_validator, tvb, 0, -1, ENC_NA);
   class_tree = proto_item_add_subtree( ti, ett_cip_class_s_validator );

   dissect_cip_s_validator_data( class_tree, tvb, 0, tvb_reported_length(tvb), pinfo );

   return tvb_reported_length(tvb);
}

static gboolean
dissect_class_svalidator_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
{
   unsigned char   service, service_code, ioilen, segment;
   cip_req_info_t* preq_info;
   guint32         classid = 0;
   int             offset  = 0;

   service = tvb_get_guint8( tvb, offset );
   service_code = service & CIP_SC_MASK;

   /* Handle GetAttributeAll and SetAttributeAll in CCO class */
   if (service_code == SC_GET_ATT_ALL)
   {
      if (service & CIP_SC_RESPONSE_MASK)
      {
         /* Service response */
         preq_info = (cip_req_info_t*)p_get_proto_data(wmem_file_scope(), pinfo, proto_cip, 0);
         if ((preq_info != NULL) &&
             (preq_info->dissector == dissector_get_uint_handle( subdissector_class_table, CI_CLS_SAFETY_VALIDATOR)))
         {
            call_dissector(preq_info->dissector, tvb, pinfo, tree);
            return TRUE;
         }
      }
      else
      {
         /* Service request */
         ioilen = tvb_get_guint8( tvb, offset + 1 );
         if (ioilen > 1)
         {
            segment = tvb_get_guint8( tvb, offset + 2 );
            if (((segment & CI_SEGMENT_TYPE_MASK) == CI_LOGICAL_SEGMENT) &&
                ((segment & CI_LOGICAL_SEG_TYPE_MASK) == CI_LOGICAL_SEG_CLASS_ID))
            {
               /* Logical Class ID, do a format check */
               switch ( segment & CI_LOGICAL_SEG_FORMAT_MASK )
               {
               case CI_LOGICAL_SEG_8_BIT:
                  classid = tvb_get_guint8( tvb, offset + 3 );
                  break;
               case CI_LOGICAL_SEG_16_BIT:
                  if ( ioilen >= 2 )
                     classid = tvb_get_letohs( tvb, offset + 4 );
                  break;
               case CI_LOGICAL_SEG_32_BIT:
                  if ( ioilen >= 3 )
                     classid = tvb_get_letohl( tvb, offset + 4 );
                  break;
               }
            }
         }

         if (classid == CI_CLS_SAFETY_VALIDATOR)
         {
            call_dissector(cip_class_s_validator_handle, tvb, pinfo, tree );
            return TRUE;
         }

      }
   }

   return FALSE;
}

/************************************************
 *
 * CRC handling
 *
 ************************************************/
static guint8 compute_crc_s1_pid(guint16 conn_serial_number, guint16 vendor_id, guint32 device_serial_number)
{
    guint8 temp_buf[8];
    memcpy(temp_buf, &vendor_id, 2);
    memcpy(&temp_buf[2], &device_serial_number, 4);
    memcpy(&temp_buf[6], &conn_serial_number, 2);

    return crc8_0x37(temp_buf, 8, 0);
}

static guint8 compute_crc_s1_timestamp(guint8 pid_seed, guint8 mode_byte_mask, guint16 timestamp)
{
    guint8 mode_byte_crc = crc8_0x37(&mode_byte_mask, 1, pid_seed);
    guint8 timestamp_crc = crc8_0x37((guint8*)&timestamp, 2, mode_byte_crc);

    return timestamp_crc;
}

static guint8 compute_crc_s1_data(guint8 pid_seed, guint8 mode_byte_mask, guint8 *buf, int len)
{
    guint8 mode_byte_crc = crc8_0x37(&mode_byte_mask, 1, pid_seed);

    return crc8_0x37(buf, len, mode_byte_crc);
}

static guint8 compute_crc_s2_data(guint8 pid_seed, guint8 mode_byte_mask, guint8 *comp_buf, int len)
{
    int i;
    guint8 mode_byte_crc = crc8_0x3B(&mode_byte_mask, 1, pid_seed);

    for (i = 0; i < len; i++)
        comp_buf[i] ^= 0xFF;

    return crc8_0x3B(comp_buf, len, mode_byte_crc);
}

static guint16 compute_crc_s3_pid(guint16 conn_serial_number, guint16 vendor_id, guint32 device_serial_number)
{
    guint8 temp_buf[8];
    memcpy(temp_buf, &vendor_id, 2);
    memcpy(&temp_buf[2], &device_serial_number, 4);
    memcpy(&temp_buf[6], &conn_serial_number, 2);

    return crc16_0x080F_seed(temp_buf, 8, 0);
}

static guint16 compute_crc_s3_base_data(guint16 pid_seed, guint8 mode_byte_mask, guint8 *buf, int len)
{
    guint16 mode_byte_crc = crc16_0x080F_seed(&mode_byte_mask, 1, pid_seed);

    return crc16_0x080F_seed(buf, len, mode_byte_crc);
}

static guint16 compute_crc_s3_extended_data(guint16 pid_seed, guint16 rollover_value, guint8 mode_byte_mask, guint8 *buf, int len)
{
    guint16 rollover_crc = crc16_0x080F_seed((guint8*)&rollover_value, 2, pid_seed);
    guint16 mode_byte_crc = crc16_0x080F_seed(&mode_byte_mask, 1, rollover_crc);

    return crc16_0x080F_seed(buf, len, mode_byte_crc);
}

static guint16 compute_crc_s3_time(guint16 pid_seed, guint8 ack_mcast_byte, guint16 timestamp_value)
{
    guint16 mode_byte_crc = crc16_0x080F_seed(&ack_mcast_byte, 1, pid_seed);
    guint16 timestamp_crc;

    timestamp_crc = crc16_0x080F_seed((guint8*)&timestamp_value, 2, mode_byte_crc);

    return timestamp_crc;
}

static guint32 compute_crc_s5_pid(guint16 conn_serial_number, guint16 vendor_id, guint32 device_serial_number)
{
    guint8 temp_buf[8];
    memcpy(temp_buf, &vendor_id, 2);
    memcpy(&temp_buf[2], &device_serial_number, 4);
    memcpy(&temp_buf[6], &conn_serial_number, 2);

    return crc32_0x5D6DCB_seed(temp_buf, 8, 0);
}

static guint32 compute_crc_s5_short_data(guint32 pid_seed, guint16 rollover_value, guint8 mode_byte_mask, guint16 timestamp_value, guint8 *buf, int len)
{
    guint32 rollover_crc = crc32_0x5D6DCB_seed((guint8*)&rollover_value, 2, pid_seed);
    guint32 mode_byte_crc = crc32_0x5D6DCB_seed(&mode_byte_mask, 1, rollover_crc);
    guint32 data_crc, timestamp_crc;

    data_crc = crc32_0x5D6DCB_seed(buf, len, mode_byte_crc);
    timestamp_crc = crc32_0x5D6DCB_seed((guint8*)&timestamp_value, 2, data_crc);

    return timestamp_crc;
}

static guint32 compute_crc_s5_long_data(guint32 pid_seed, guint16 rollover_value, guint8 mode_byte_mask, guint16 timestamp_value, guint8 *comp_buf, int len)
{
    int i;
    guint32 rollover_crc = crc32_0x5D6DCB_seed((guint8*)&rollover_value, 2, pid_seed);
    guint32 mode_byte_crc = crc32_0x5D6DCB_seed(&mode_byte_mask, 1, rollover_crc);
    guint32 comp_data_crc, timestamp_crc;

    for (i = 0; i < len; i++)
        comp_buf[i] ^= 0xFF;

    comp_data_crc = crc32_0x5D6DCB_seed(comp_buf, len, mode_byte_crc);
    timestamp_crc = crc32_0x5D6DCB_seed((guint8*)&timestamp_value, 2, comp_data_crc);

    return timestamp_crc;
}

static guint32 compute_crc_s5_time(guint32 pid_seed, guint8 ack_mcast_byte, guint16 timestamp_value)
{
    guint32 mode_byte_crc = crc32_0x5D6DCB_seed(&ack_mcast_byte, 1, pid_seed);
    guint32 timestamp_crc;

    timestamp_crc = crc32_0x5D6DCB_seed((guint8*)&timestamp_value, 2, mode_byte_crc);

    return timestamp_crc;
}

static gboolean verify_compliment_data(tvbuff_t *tvb, int data_offset, int complement_data_offset, int data_size)
{
    const guint8 *data = tvb_get_ptr(tvb, data_offset, data_size);
    const guint8 *complement_data = tvb_get_ptr(tvb, complement_data_offset, data_size);
    int i;

    for (i = 0; i < data_size; i++)
    {
        if ((data[i] ^ complement_data[i])!= 0xFF)
            return FALSE;
    }

    return TRUE;
}


/************************************************
 *
 * Dissector for CIP Safety I/O Data
 *
 ************************************************/
static void
dissect_mode_byte( proto_tree *tree, tvbuff_t *tvb, int offset, packet_info *pinfo)
{
   proto_item *mode_item, *run_idle_item, *tbd_item, *tbd2_item;
   proto_tree *mode_tree;
   guint8      mode_byte;

   mode_byte = tvb_get_guint8(tvb, offset);

   /* dissect Mode Byte bits */
   mode_item = proto_tree_add_item(tree, hf_cipsafety_mode_byte, tvb, offset, 1, ENC_LITTLE_ENDIAN);
   mode_tree = proto_item_add_subtree( mode_item, ett_cipsafety_mode_byte);

   proto_tree_add_item(mode_tree, hf_cipsafety_mode_byte_ping_count,               tvb, offset, 1, ENC_LITTLE_ENDIAN);
   proto_tree_add_item(mode_tree, hf_cipsafety_mode_byte_not_tbd,                  tvb, offset, 1, ENC_LITTLE_ENDIAN);
   proto_tree_add_item(mode_tree, hf_cipsafety_mode_byte_tbd_2_copy,               tvb, offset, 1, ENC_LITTLE_ENDIAN);
   proto_tree_add_item(mode_tree, hf_cipsafety_mode_byte_not_run_idle,             tvb, offset, 1, ENC_LITTLE_ENDIAN);
   tbd_item  = proto_tree_add_item(mode_tree, hf_cipsafety_mode_byte_tbd,          tvb, offset, 1, ENC_LITTLE_ENDIAN);
   tbd2_item = proto_tree_add_item(mode_tree, hf_cipsafety_mode_byte_tbd_2_bit,    tvb, offset, 1, ENC_LITTLE_ENDIAN);
   run_idle_item = proto_tree_add_item(mode_tree, hf_cipsafety_mode_byte_run_idle, tvb, offset, 1, ENC_LITTLE_ENDIAN);

   /* verify Mode Byte bits */
   /* TBD */
   if ((((mode_byte & 0x20) >> 5) & 0x01) == (((mode_byte & 0x04) >> 2) & 0x01))
      expert_add_info(pinfo, tbd_item, &ei_cipsafety_tbd2_not_complemented);

   /* TBD 2 */
   if ((((mode_byte & 0x40) >> 6) & 0x01) != (((mode_byte & 0x08) >> 3) & 0x01))
      expert_add_info(pinfo, tbd2_item, &ei_cipsafety_tbd_not_copied);

   /* Run/Idle */
   if ((((mode_byte & 0x80) >> 7) & 0x01) == (((mode_byte & 0x10) >> 4) & 0x01))
      expert_add_info(pinfo, run_idle_item, &ei_cipsafety_run_idle_not_complemented);
}

static void
dissect_ack_byte( proto_tree *tree, tvbuff_t *tvb, int offset, packet_info *pinfo _U_)
{
   proto_item *ack_item;
   proto_tree *ack_tree;
#if 0 /***** Placeholder reminder to add ack_byte validation */
   guint8 ack_byte;

   ack_byte = tvb_get_guint8(tvb, offset);
#endif
   if (!tree)
      return;

   /* dissect Ack Byte bits */
   ack_item = proto_tree_add_item(tree, hf_cipsafety_ack_byte, tvb, offset, 1, ENC_LITTLE_ENDIAN);
   ack_tree = proto_item_add_subtree( ack_item, ett_cipsafety_ack_byte);

   proto_tree_add_item(ack_tree, hf_cipsafety_ack_byte_ping_count_reply, tvb, offset, 1, ENC_LITTLE_ENDIAN);
   proto_tree_add_item(ack_tree, hf_cipsafety_ack_byte_reserved1,        tvb, offset, 1, ENC_LITTLE_ENDIAN);
   proto_tree_add_item(ack_tree, hf_cipsafety_ack_byte_ping_response,    tvb, offset, 1, ENC_LITTLE_ENDIAN);
   proto_tree_add_item(ack_tree, hf_cipsafety_ack_byte_reserved2,        tvb, offset, 1, ENC_LITTLE_ENDIAN);
   proto_tree_add_item(ack_tree, hf_cipsafety_ack_byte_parity_even,      tvb, offset, 1, ENC_LITTLE_ENDIAN);
}

static void
dissect_mcast_byte( proto_tree *tree, tvbuff_t *tvb, int offset, packet_info *pinfo _U_)
{
   proto_item *mcast_item;
   proto_tree *mcast_tree;
#if 0 /*** Placeholder reminder to add mcast_byte validation */
   guint8 mcast_byte;

   mcast_byte = tvb_get_guint8(tvb, offset);
#endif
   /* dissect MCast Byte bits */
   mcast_item = proto_tree_add_item(tree, hf_cipsafety_mcast_byte, tvb, offset, 1, ENC_LITTLE_ENDIAN);
   mcast_tree = proto_item_add_subtree( mcast_item, ett_cipsafety_mcast_byte);

   proto_tree_add_item(mcast_tree, hf_cipsafety_mcast_byte_consumer_num, tvb, offset, 1, ENC_LITTLE_ENDIAN);
   proto_tree_add_item(mcast_tree, hf_cipsafety_mcast_byte_reserved1,    tvb, offset, 1, ENC_LITTLE_ENDIAN);
   proto_tree_add_item(mcast_tree, hf_cipsafety_mcast_byte_mai,          tvb, offset, 1, ENC_LITTLE_ENDIAN);
   proto_tree_add_item(mcast_tree, hf_cipsafety_mcast_byte_reserved2,    tvb, offset, 1, ENC_LITTLE_ENDIAN);
   proto_tree_add_item(mcast_tree, hf_cipsafety_mcast_byte_parity_even,  tvb, offset, 1, ENC_LITTLE_ENDIAN);
}

static void
dissect_cip_safety_data( proto_tree *tree, proto_item *item, tvbuff_t *tvb, int item_length, packet_info *pinfo, cip_safety_info_t* safety_info)
{
   int base_length, io_data_size;
   gboolean multicast = (((pntoh32(pinfo->dst.data)) & 0xf0000000) == 0xe0000000);
   gboolean server_dir = FALSE;
   enum enip_connid_type conn_type = ECIDT_UNKNOWN;
   enum cip_safety_format_type format = CIP_SAFETY_BASE_FORMAT;
   guint16 timestamp, conn_sn = 0, vendorID = 0;
   guint8 mode_byte;
   guint32 device_sn = 0;
   cip_safety_packet_data_t* packet_data = NULL;
   guint32 test_crc_c5, value_c5 = 0, tmp_c5;
   proto_item *complement_item, *crc_s5_item, *crc_s5_status_item;
   gboolean short_format = TRUE;
   gboolean compute_crc = ((safety_info != NULL) && (safety_info->eip_conn_info != NULL));

   /* Make entries in Protocol column and Info column on summary display */
   col_set_str(pinfo->cinfo, COL_PROTOCOL, "CIP Safety");

   /* determine the connection type as it affects the fields dissected */
   if (safety_info != NULL && safety_info->eip_conn_info != NULL)
   {
      conn_type = safety_info->conn_type;
      format = safety_info->eip_conn_info->safety.format;
      server_dir = (safety_info->eip_conn_info->TransportClass_trigger & CI_PRODUCTION_DIR_MASK) ? TRUE : FALSE;
   }

   /* compute the base packet length to determine what is actual I/O data */
   base_length = multicast ? 12 : 6;

   if (((conn_type == ECIDT_O2T) && (server_dir == FALSE)) ||
       ((conn_type == ECIDT_T2O) && (server_dir == TRUE)))
   {
      if (compute_crc)
      {
         if ((conn_type == ECIDT_O2T) && (server_dir == FALSE))
         {
            conn_sn = safety_info->eip_conn_info->ConnSerialNumber;
            vendorID = safety_info->eip_conn_info->VendorID;
            device_sn = safety_info->eip_conn_info->DeviceSerialNumber;
         }
         else
         {
            conn_sn = safety_info->eip_conn_info->safety.target_conn_sn;
            vendorID = safety_info->eip_conn_info->safety.target_vendorID;
            device_sn = safety_info->eip_conn_info->safety.target_device_sn;
         }
      }

      /* consumer data */
      dissect_ack_byte(tree, tvb, 0, pinfo);
      proto_tree_add_item(tree, hf_cipsafety_consumer_time_value, tvb, 1, 2, ENC_LITTLE_ENDIAN);
      timestamp = tvb_get_letohs(tvb, 1);

      switch (format)
      {
      case CIP_SAFETY_BASE_FORMAT:
         proto_tree_add_item(tree, hf_cipsafety_ack_byte2, tvb, 3, 1, ENC_LITTLE_ENDIAN);
         if (compute_crc)
         {
            proto_tree_add_checksum(tree, tvb, 4,
                        hf_cipsafety_crc_s3, hf_cipsafety_crc_s3_status, &ei_cipsafety_crc_s3, pinfo,
                        compute_crc_s3_time(compute_crc_s3_pid(conn_sn, vendorID, device_sn),
                                                                tvb_get_guint8(tvb, 0), /* ack byte */
                                                                timestamp),
                        ENC_LITTLE_ENDIAN, PROTO_CHECKSUM_VERIFY);
         }
         else
         {
            proto_tree_add_checksum(tree, tvb, 4,
                        hf_cipsafety_crc_s3, hf_cipsafety_crc_s3_status, &ei_cipsafety_crc_s3,
                        pinfo, 0, ENC_LITTLE_ENDIAN, PROTO_CHECKSUM_NO_FLAGS);
         }
         break;
      case CIP_SAFETY_EXTENDED_FORMAT:
         proto_tree_add_item(tree, hf_cipsafety_crc_s5_0, tvb, 3, 1, ENC_LITTLE_ENDIAN);
         proto_tree_add_item(tree, hf_cipsafety_crc_s5_1, tvb, 4, 1, ENC_LITTLE_ENDIAN);
         crc_s5_item = proto_tree_add_item(tree, hf_cipsafety_crc_s5_2, tvb, 5, 1, ENC_LITTLE_ENDIAN);

         /* CRC-S5 doesn't use proto_tree_add_checksum because the checksum is broken up into multiple fields */
         if (compute_crc)
         {
            test_crc_c5 = compute_crc_s5_time(compute_crc_s5_pid(conn_sn, vendorID, device_sn),
                                    tvb_get_guint8(tvb, 0), /* ack byte */
                                    timestamp);

            tmp_c5 = tvb_get_guint8(tvb, 3);
            value_c5 = tmp_c5;
            tmp_c5 = tvb_get_guint8(tvb, 4);
            value_c5 += ((tmp_c5 << 8) & 0xFF00);
            tmp_c5 = tvb_get_guint8(tvb, 5);
            value_c5 += ((tmp_c5 << 16) & 0xFF0000);

            if (test_crc_c5 == value_c5)
            {
               proto_item_append_text(crc_s5_item, " [correct]");
               crc_s5_status_item = proto_tree_add_uint(tree, hf_cipsafety_crc_s5_status, tvb, 5, 0, PROTO_CHECKSUM_E_GOOD);
            }
            else
            {
               proto_item_append_text(crc_s5_item, " incorrect, should be 0x%08x", test_crc_c5);
               crc_s5_status_item = proto_tree_add_uint(tree, hf_cipsafety_crc_s5_status, tvb, 5, 0, PROTO_CHECKSUM_E_BAD);
               expert_add_info_format(pinfo, crc_s5_item, &ei_cipsafety_crc_s5, "Bad checksum [should be 0x%08x]", test_crc_c5);
            }
         }
         else
         {
            crc_s5_status_item = proto_tree_add_uint(tree, hf_cipsafety_crc_s5_status, tvb, 5, 0, PROTO_CHECKSUM_E_UNVERIFIED);
         }
         PROTO_ITEM_SET_GENERATED(crc_s5_status_item);

         break;
      }
   }
   else if (((conn_type == ECIDT_O2T) && (server_dir == TRUE)) ||
            ((conn_type == ECIDT_T2O) && (server_dir == FALSE)))
   {
      if (compute_crc)
      {
         if ((conn_type == ECIDT_O2T) && (server_dir == TRUE))
         {
            conn_sn = safety_info->eip_conn_info->ConnSerialNumber;
            vendorID = safety_info->eip_conn_info->VendorID;
            device_sn = safety_info->eip_conn_info->DeviceSerialNumber;
         }
         else
         {
            conn_sn = safety_info->eip_conn_info->safety.target_conn_sn;
            vendorID = safety_info->eip_conn_info->safety.target_vendorID;
            device_sn = safety_info->eip_conn_info->safety.target_device_sn;
         }
      }

      if (item_length-base_length > 2)
         short_format = FALSE;

      /* producer data */
      switch (format)
      {
      case CIP_SAFETY_BASE_FORMAT:
         if (short_format)
         {
            io_data_size = item_length-base_length;

            /* Short Format (1-2 bytes I/O data) */
            proto_tree_add_item(tree, hf_cipsafety_data, tvb, 0, io_data_size, ENC_NA);
            dissect_mode_byte(tree, tvb, io_data_size, pinfo);
            mode_byte = tvb_get_guint8(tvb, io_data_size);

            if (compute_crc)
            {
               proto_tree_add_checksum(tree, tvb, io_data_size+1,
                        hf_cipsafety_crc_s1, hf_cipsafety_crc_s1_status, &ei_cipsafety_crc_s1, pinfo,
                        compute_crc_s1_data(compute_crc_s1_pid(conn_sn, vendorID, device_sn),
                                (mode_byte & MODE_BYTE_CRC_S1_MASK),
                                (guint8*)tvb_get_ptr(tvb, 0, io_data_size), io_data_size),
                        ENC_LITTLE_ENDIAN, PROTO_CHECKSUM_VERIFY);

               proto_tree_add_checksum(tree, tvb, io_data_size+2,
                        hf_cipsafety_crc_s2, hf_cipsafety_crc_s2_status, &ei_cipsafety_crc_s2, pinfo,
                        compute_crc_s2_data(compute_crc_s1_pid(conn_sn, vendorID, device_sn),
                                ((mode_byte ^ 0xFF) & MODE_BYTE_CRC_S1_MASK),
                                /* I/O data is duplicated because it will be complemented inline */
                                (guint8*)tvb_memdup(wmem_packet_scope(), tvb, 0, io_data_size), io_data_size),
                        ENC_LITTLE_ENDIAN, PROTO_CHECKSUM_VERIFY);
            }
            else
            {
               proto_tree_add_checksum(tree, tvb, io_data_size+1,
                        hf_cipsafety_crc_s1, hf_cipsafety_crc_s1_status, &ei_cipsafety_crc_s1,
                        pinfo, 0, ENC_LITTLE_ENDIAN, PROTO_CHECKSUM_NO_FLAGS);
               proto_tree_add_checksum(tree, tvb, io_data_size+2,
                        hf_cipsafety_crc_s2, hf_cipsafety_crc_s2_status, &ei_cipsafety_crc_s2,
                        pinfo, 0, ENC_LITTLE_ENDIAN, PROTO_CHECKSUM_NO_FLAGS);
            }
            proto_tree_add_item(tree, hf_cipsafety_timestamp, tvb, io_data_size+3, 2, ENC_LITTLE_ENDIAN);
            timestamp = tvb_get_letohs(tvb, io_data_size+3);
            if (compute_crc)
            {
               proto_tree_add_checksum(tree, tvb, io_data_size+5,
                        hf_cipsafety_crc_s1, hf_cipsafety_crc_s1_status, &ei_cipsafety_crc_s1, pinfo,
                        compute_crc_s1_timestamp(compute_crc_s1_pid(conn_sn, vendorID, device_sn),
                                (mode_byte & MODE_BYTE_CRC_S1_TIME_STAMP_MASK),
                                timestamp),
                        ENC_LITTLE_ENDIAN, PROTO_CHECKSUM_VERIFY);
            }
            else
            {
               proto_tree_add_checksum(tree, tvb, io_data_size+5,
                        hf_cipsafety_crc_s1, hf_cipsafety_crc_s1_status, &ei_cipsafety_crc_s1,
                        pinfo, 0, ENC_LITTLE_ENDIAN, PROTO_CHECKSUM_NO_FLAGS);
            }

            if (multicast)
            {
               dissect_mcast_byte(tree, tvb, item_length-6, pinfo);
               proto_tree_add_item(tree, hf_cipsafety_time_correction, tvb, item_length-5, 2, ENC_LITTLE_ENDIAN);
               proto_tree_add_item(tree, hf_cipsafety_mcast_byte2,     tvb, item_length-3, 1, ENC_LITTLE_ENDIAN);
               proto_tree_add_item(tree, hf_cipsafety_crc_s3,          tvb, item_length-2, 2, ENC_LITTLE_ENDIAN);
            }
         }
         else
         {
            /* Long Format (3-250 bytes I/O data) */
            if (item_length%2 == 1)
            {
               /* Malformed packet */
               expert_add_info(pinfo, item, &ei_mal_io);
               return;
            }

            io_data_size = multicast ? ((item_length-14)/2) : ((item_length-8)/2);

            proto_tree_add_item(tree, hf_cipsafety_data, tvb, 0, io_data_size, ENC_NA);
            dissect_mode_byte(tree, tvb, io_data_size, pinfo);
            mode_byte = tvb_get_guint8(tvb, io_data_size);

            if (compute_crc)
            {
               proto_tree_add_checksum(tree, tvb, io_data_size+1,
                        hf_cipsafety_crc_s3, hf_cipsafety_crc_s3_status, &ei_cipsafety_crc_s3, pinfo,
                        compute_crc_s3_base_data(compute_crc_s3_pid(conn_sn, vendorID, device_sn),
                                mode_byte & MODE_BYTE_CRC_S3_MASK, (guint8*)tvb_get_ptr(tvb, 0, io_data_size), io_data_size),
                        ENC_LITTLE_ENDIAN, PROTO_CHECKSUM_VERIFY);
            }
            else
            {
               proto_tree_add_checksum(tree, tvb, io_data_size+1,
                        hf_cipsafety_crc_s3, hf_cipsafety_crc_s3_status, &ei_cipsafety_crc_s3,
                        pinfo, 0, ENC_LITTLE_ENDIAN, PROTO_CHECKSUM_NO_FLAGS);
            }

            complement_item = proto_tree_add_item(tree, hf_cipsafety_complement_data, tvb, io_data_size+3, io_data_size, ENC_NA);
            if (!verify_compliment_data(tvb, 0, io_data_size+3, io_data_size))
                expert_add_info(pinfo, complement_item, &ei_cipsafety_not_complement_data);

            if (compute_crc)
            {
               proto_tree_add_checksum(tree, tvb, (io_data_size*2)+3,
                        hf_cipsafety_complement_crc_s3, hf_cipsafety_complement_crc_s3_status, &ei_cipsafety_complement_crc_s3, pinfo,
                        compute_crc_s3_base_data(compute_crc_s3_pid(conn_sn, vendorID, device_sn),
                                ((mode_byte ^ 0xFF) & MODE_BYTE_CRC_S3_MASK),
                                (guint8*)tvb_get_ptr(tvb, io_data_size+3, io_data_size), io_data_size),
                        ENC_LITTLE_ENDIAN, PROTO_CHECKSUM_VERIFY);
            }
            else
            {
               proto_tree_add_checksum(tree, tvb, (io_data_size*2)+3,
                        hf_cipsafety_complement_crc_s3, hf_cipsafety_complement_crc_s3_status, &ei_cipsafety_complement_crc_s3,
                        pinfo, 0, ENC_LITTLE_ENDIAN, PROTO_CHECKSUM_NO_FLAGS);
            }
            proto_tree_add_item(tree, hf_cipsafety_timestamp, tvb, (io_data_size*2)+5, 2, ENC_LITTLE_ENDIAN);
            timestamp = tvb_get_letohs(tvb, (io_data_size*2)+5);
            if (compute_crc)
            {
               proto_tree_add_checksum(tree, tvb, (io_data_size*2)+7,
                        hf_cipsafety_crc_s1, hf_cipsafety_crc_s1_status, &ei_cipsafety_crc_s1, pinfo,
                        compute_crc_s1_timestamp(compute_crc_s1_pid(conn_sn, vendorID, device_sn),
                                (mode_byte & MODE_BYTE_CRC_S1_TIME_STAMP_MASK),
                                timestamp),
                        ENC_LITTLE_ENDIAN, PROTO_CHECKSUM_VERIFY);
            }
            else
            {
               proto_tree_add_checksum(tree, tvb, (io_data_size*2)+7,
                        hf_cipsafety_crc_s1, hf_cipsafety_crc_s1_status, &ei_cipsafety_crc_s1,
                        pinfo, 0, ENC_LITTLE_ENDIAN, PROTO_CHECKSUM_NO_FLAGS);
            }

            if (multicast)
            {
               dissect_mcast_byte(tree, tvb, (io_data_size*2)+5, pinfo);
               proto_tree_add_item(tree, hf_cipsafety_time_correction, tvb, (io_data_size*2)+6, 2, ENC_LITTLE_ENDIAN);
               proto_tree_add_item(tree, hf_cipsafety_mcast_byte2, tvb, (io_data_size*2)+8, 1, ENC_LITTLE_ENDIAN);
               proto_tree_add_item(tree, hf_cipsafety_crc_s3, tvb, (io_data_size*2)+9, 2, ENC_LITTLE_ENDIAN);
            }
         }
         break;
      case CIP_SAFETY_EXTENDED_FORMAT:
         if (short_format)
         {
            io_data_size = item_length-base_length;
            timestamp = tvb_get_letohs(tvb, io_data_size+3);
         }
         else
         {
            io_data_size = multicast ? ((item_length-14)/2) : ((item_length-8)/2);
            timestamp = tvb_get_letohs(tvb, (io_data_size*2)+5);
         }
         mode_byte = tvb_get_guint8(tvb, io_data_size);

         if (compute_crc)
         {
            /* Determine if packet timestamp results in rollover count increment */
            if (!pinfo->fd->flags.visited)
            {
               if ((timestamp != 0) && (timestamp < safety_info->eip_conn_info->safety.running_timestamp_value))
               {
                  safety_info->eip_conn_info->safety.running_rollover_value++;
               }

               safety_info->eip_conn_info->safety.running_timestamp_value = timestamp;

               /* Save the rollover value for CRC calculations */
               packet_data = wmem_new0(wmem_file_scope(), cip_safety_packet_data_t);
               packet_data->rollover_value = safety_info->eip_conn_info->safety.running_rollover_value;

               p_add_proto_data(wmem_file_scope(), pinfo, proto_cipsafety, 0, packet_data);
            }
            else
            {
               packet_data = (cip_safety_packet_data_t*)p_get_proto_data(wmem_file_scope(), pinfo, proto_cipsafety, 0);
            }
         }

         if (short_format)
         {
            /* Short Format (1-2 bytes I/O data) */
            proto_tree_add_item(tree, hf_cipsafety_data, tvb, 0, io_data_size, ENC_NA);
            dissect_mode_byte(tree, tvb, io_data_size, pinfo);

            proto_tree_add_item(tree, hf_cipsafety_crc_s5_0, tvb, io_data_size+1, 1, ENC_LITTLE_ENDIAN);
            proto_tree_add_item(tree, hf_cipsafety_crc_s5_1, tvb, io_data_size+2, 1, ENC_LITTLE_ENDIAN);
            proto_tree_add_item(tree, hf_cipsafety_timestamp, tvb, io_data_size+3, 2, ENC_LITTLE_ENDIAN);
            crc_s5_item = proto_tree_add_item(tree, hf_cipsafety_crc_s5_2, tvb, io_data_size+5, 1, ENC_LITTLE_ENDIAN);

            /* CRC-S5 doesn't use proto_tree_add_checksum because the checksum is broken up in non-consecutive bytes */
            if (compute_crc && (packet_data != NULL))
            {
               test_crc_c5 = compute_crc_s5_short_data(compute_crc_s5_pid(conn_sn, vendorID, device_sn),
                                        ((timestamp != 0) ? packet_data->rollover_value : 0), mode_byte & MODE_BYTE_CRC_S5_BASE_MASK, timestamp,
                                        (guint8*)tvb_get_ptr(tvb, 0, io_data_size), io_data_size);

               tmp_c5 = tvb_get_guint8(tvb, io_data_size+1);
               value_c5 = tmp_c5;
               tmp_c5 = tvb_get_guint8(tvb, io_data_size+2);
               value_c5 += ((tmp_c5 << 8) & 0xFF00);
               tmp_c5 = tvb_get_guint8(tvb, io_data_size+5);
               value_c5 += ((tmp_c5 << 16) & 0xFF0000);

               if (test_crc_c5 == value_c5)
               {
                  proto_item_append_text(crc_s5_item, " [correct]");
                  crc_s5_status_item = proto_tree_add_uint(tree, hf_cipsafety_crc_s5_status, tvb, io_data_size+5, 0, PROTO_CHECKSUM_E_GOOD);
               }
               else
               {
                   proto_item_append_text(crc_s5_item, " incorrect, should be 0x%08x", test_crc_c5);
                   crc_s5_status_item = proto_tree_add_uint(tree, hf_cipsafety_crc_s5_status, tvb, io_data_size+5, 0, PROTO_CHECKSUM_E_BAD);
                   expert_add_info_format(pinfo, crc_s5_item, &ei_cipsafety_crc_s5, "Bad checksum [should be 0x%08x]", test_crc_c5);
               }
            }
            else
            {
               crc_s5_status_item = proto_tree_add_uint(tree, hf_cipsafety_crc_s5_status, tvb, io_data_size+5, 0, PROTO_CHECKSUM_E_UNVERIFIED);
            }
            PROTO_ITEM_SET_GENERATED(crc_s5_status_item);

            if (multicast)
            {
               dissect_mcast_byte(tree, tvb, item_length-6, pinfo);
               proto_tree_add_item(tree, hf_cipsafety_time_correction, tvb, item_length-5, 2, ENC_LITTLE_ENDIAN);
               proto_tree_add_item(tree, hf_cipsafety_crc_s5_0, tvb, item_length-3, 1, ENC_LITTLE_ENDIAN);
               proto_tree_add_item(tree, hf_cipsafety_crc_s5_1, tvb, item_length-2, 1, ENC_LITTLE_ENDIAN);
               proto_tree_add_item(tree, hf_cipsafety_crc_s5_2, tvb, item_length-1, 1, ENC_LITTLE_ENDIAN);
            }
         }
         else
         {
            /* Long Format (3-250 bytes I/O data) */
            if (item_length%2 == 1)
            {
               /* Malformed packet */
               expert_add_info(pinfo, item, &ei_mal_io);
               return;
            }

            proto_tree_add_item(tree, hf_cipsafety_data, tvb, 0, io_data_size, ENC_NA);
            dissect_mode_byte(tree, tvb, io_data_size, pinfo);

            if (compute_crc)
            {
               /* Determine if packet timestamp results in rollover count increment */
               if (!pinfo->fd->flags.visited)
               {
                  if ((timestamp != 0) && (timestamp < safety_info->eip_conn_info->safety.running_timestamp_value))
                  {
                     safety_info->eip_conn_info->safety.running_rollover_value++;
                  }

                  safety_info->eip_conn_info->safety.running_timestamp_value = timestamp;

                  /* Save the rollover value for CRC calculations */
                  packet_data = wmem_new0(wmem_file_scope(), cip_safety_packet_data_t);
                  packet_data->rollover_value = safety_info->eip_conn_info->safety.running_rollover_value;

                  p_add_proto_data(wmem_file_scope(), pinfo, proto_cipsafety, 0, packet_data);
               }
               else
               {
                  packet_data = (cip_safety_packet_data_t*)p_get_proto_data(wmem_file_scope(), pinfo, proto_cipsafety, 0);
               }

               if (packet_data != NULL)
               {
                  proto_tree_add_checksum(tree, tvb, io_data_size+1,
                           hf_cipsafety_crc_s3, hf_cipsafety_crc_s3_status, &ei_cipsafety_crc_s3, pinfo,
                           compute_crc_s3_extended_data(compute_crc_s3_pid(conn_sn, vendorID, device_sn),
                                ((timestamp != 0) ? packet_data->rollover_value : 0), mode_byte & MODE_BYTE_CRC_S3_MASK, (guint8*)tvb_get_ptr(tvb, 0, io_data_size), io_data_size),
                           ENC_LITTLE_ENDIAN, PROTO_CHECKSUM_VERIFY);
               }
            }
            else
            {
               proto_tree_add_checksum(tree, tvb, io_data_size+1,
                        hf_cipsafety_crc_s3, hf_cipsafety_crc_s3_status, &ei_cipsafety_crc_s3,
                        pinfo, 0, ENC_LITTLE_ENDIAN, PROTO_CHECKSUM_NO_FLAGS);

            }
            complement_item = proto_tree_add_item(tree, hf_cipsafety_complement_data, tvb, io_data_size+3, io_data_size, ENC_NA);
            if (!verify_compliment_data(tvb, 0, io_data_size+3, io_data_size))
                expert_add_info(pinfo, complement_item, &ei_cipsafety_not_complement_data);
            proto_tree_add_item(tree, hf_cipsafety_crc_s5_0, tvb, (io_data_size*2)+3, 1, ENC_LITTLE_ENDIAN);
            proto_tree_add_item(tree, hf_cipsafety_crc_s5_1, tvb, (io_data_size*2)+4, 1, ENC_LITTLE_ENDIAN);
            proto_tree_add_item(tree, hf_cipsafety_timestamp, tvb, (io_data_size*2)+5, 2, ENC_LITTLE_ENDIAN);
            crc_s5_item = proto_tree_add_item(tree, hf_cipsafety_crc_s5_2, tvb, (io_data_size*2)+7, 1, ENC_LITTLE_ENDIAN);

            /* CRC-S5 doesn't use proto_tree_add_checksum because the checksum is broken up in non-consecutive bytes */
            if (compute_crc && (packet_data != NULL))
            {
               test_crc_c5 = compute_crc_s5_long_data(compute_crc_s5_pid(conn_sn, vendorID, device_sn),
                                        ((timestamp != 0) ? packet_data->rollover_value : 0), mode_byte & MODE_BYTE_CRC_S5_EXTENDED_MASK, timestamp,
                                        /* I/O data is duplicated because it will be complemented inline */
                                        (guint8*)tvb_memdup(wmem_packet_scope(), tvb, 0, io_data_size), io_data_size);

               tmp_c5 = tvb_get_guint8(tvb, (io_data_size*2)+3);
               value_c5 = tmp_c5;
               tmp_c5 = tvb_get_guint8(tvb, (io_data_size*2)+4);
               value_c5 += ((tmp_c5 << 8) & 0xFF00);
               tmp_c5 = tvb_get_guint8(tvb, (io_data_size*2)+7);
               value_c5 += ((tmp_c5 << 16) & 0xFF0000);

               if (test_crc_c5 == value_c5)
               {
                  proto_item_append_text(crc_s5_item, " [correct]");
                  crc_s5_status_item = proto_tree_add_uint(tree, hf_cipsafety_crc_s5_status, tvb, (io_data_size*2)+7, 0, PROTO_CHECKSUM_E_GOOD);
               }
               else
               {
                   proto_item_append_text(crc_s5_item, " incorrect, should be 0x%08x", test_crc_c5);
                   crc_s5_status_item = proto_tree_add_uint(tree, hf_cipsafety_crc_s5_status, tvb, (io_data_size*2)+7, 0, PROTO_CHECKSUM_E_BAD);
                   expert_add_info_format(pinfo, crc_s5_item, &ei_cipsafety_crc_s5, "Bad checksum [should be 0x%08x]", test_crc_c5);
               }
            }
            else
            {
               crc_s5_status_item = proto_tree_add_uint(tree, hf_cipsafety_crc_s5_status, tvb, (io_data_size*2)+7, 0, PROTO_CHECKSUM_E_UNVERIFIED);
            }
            PROTO_ITEM_SET_GENERATED(crc_s5_status_item);

            if (multicast)
            {
               dissect_mcast_byte(tree, tvb, (io_data_size*2)+8, pinfo);
               proto_tree_add_item(tree, hf_cipsafety_time_correction, tvb, (io_data_size*2)+9, 2, ENC_LITTLE_ENDIAN);
               proto_tree_add_item(tree, hf_cipsafety_crc_s5_0, tvb, (io_data_size*2)+11, 1, ENC_LITTLE_ENDIAN);
               proto_tree_add_item(tree, hf_cipsafety_crc_s5_1, tvb, (io_data_size*2)+12, 1, ENC_LITTLE_ENDIAN);
               proto_tree_add_item(tree, hf_cipsafety_crc_s5_2, tvb, (io_data_size*2)+13, 1, ENC_LITTLE_ENDIAN);
            }
         }
         break;
      }
   }
   else
   {
      /* Shouldn't happen, but at least dissect it as data */
      proto_tree_add_item(tree, hf_cipsafety_data, tvb, 0, item_length, ENC_NA);
   }
}

static int
dissect_cipsafety(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
{
   proto_item *ti;
   proto_tree *safety_tree;
   cip_safety_info_t* safety_info = (cip_safety_info_t*)data;

   /* Create display subtree for the protocol */
   ti = proto_tree_add_item(tree, proto_cipsafety, tvb, 0, -1, ENC_NA);
   safety_tree = proto_item_add_subtree( ti, ett_cip_safety);

   dissect_cip_safety_data(safety_tree, ti, tvb, tvb_reported_length(tvb), pinfo, safety_info);
   return tvb_captured_length(tvb);
}

static int dissect_sercosiii_link_error_count_p1p2(packet_info *pinfo, proto_tree *tree, proto_item *item, tvbuff_t *tvb,
                             int offset, int total_len)
{
   if (total_len < 4)
   {
      expert_add_info(pinfo, item, &ei_mal_sercosiii_link_error_count_p1p2);
      return total_len;
   }

   proto_tree_add_item(tree, hf_cip_sercosiii_link_error_count_p1, tvb, offset, 2, ENC_LITTLE_ENDIAN );
   proto_tree_add_item(tree, hf_cip_sercosiii_link_error_count_p2, tvb, offset+2, 2, ENC_LITTLE_ENDIAN );
   return 4;
}

static int dissect_sercosiii_safety_network_number(packet_info *pinfo _U_, proto_tree *tree, proto_item *item _U_, tvbuff_t *tvb,
    int offset, int total_len _U_)
{
    proto_tree_add_item(tree, hf_cip_sercosiii_link_snn, tvb, offset, 6, ENC_NA);
    return 6;
}

attribute_info_t cip_safety_attribute_vals[51] = {

   /* Safety Supervisor */
   {0x39, TRUE, 99, -1, "Subclass", cip_uint, &hf_cip_ssupervisor_class_subclass, NULL},
   {0x39, FALSE, 1, -1, "Number of Attributes", cip_usint, &hf_cip_ssupervisor_num_attr, NULL},
   {0x39, FALSE, 2, -1, "Attribute List", cip_usint_array, &hf_cip_ssupervisor_attr_list, NULL},
   {0x39, FALSE, 5, -1, "Manufacturer Name", cip_short_string, &hf_cip_ssupervisor_manufacture_name, NULL},
   {0x39, FALSE, 6, -1, "Manufacturer Model Number", cip_short_string, &hf_cip_ssupervisor_manufacture_model_number, NULL},
   {0x39, FALSE, 7, -1, "Software Revision Level", cip_short_string, &hf_cip_ssupervisor_sw_rev_level, NULL},
   {0x39, FALSE, 8, -1, "Hardware Revision Level", cip_short_string, &hf_cip_ssupervisor_hw_rev_level, NULL},
   {0x39, FALSE, 9, -1, "Manufacturer Serial Number", cip_short_string, &hf_cip_ssupervisor_manufacture_serial_number, NULL},
   {0x39, FALSE, 10, -1, "Device Configuration", cip_short_string, &hf_cip_ssupervisor_device_config, NULL},
   {0x39, FALSE, 11, -1, "Device Status", cip_usint, &hf_cip_ssupervisor_device_status, NULL},
   {0x39, FALSE, 12, -1, "Exception Status", cip_byte, &hf_cip_ssupervisor_exception_status, NULL},
   {0x39, FALSE, 13, -1, "Exception Detail Alarm", cip_dissector_func, NULL, dissect_s_supervisor_exception_detail_common},
   {0x39, FALSE, 14, -1, "Exception Detail Warning", cip_dissector_func, NULL, dissect_s_supervisor_exception_detail_common},
   {0x39, FALSE, 15, -1, "Alarm Enable", cip_bool, &hf_cip_ssupervisor_alarm_enable, NULL},
   {0x39, FALSE, 16, -1, "Warning Enable", cip_bool, &hf_cip_ssupervisor_warning_enable, NULL},
   {0x39, FALSE, 17, -1, "Time", cip_date_and_time, &hf_cip_ssupervisor_time, NULL},
   {0x39, FALSE, 18, -1, "Clock Power Cycle Behavior", cip_usint, &hf_cip_ssupervisor_clock_power_cycle_behavior, NULL},
   {0x39, FALSE, 19, -1, "Last Maintenance Date", cip_date, &hf_cip_ssupervisor_last_maintenance_date, NULL},
   {0x39, FALSE, 20, -1, "Next Scheduled Maintenance Date", cip_date, &hf_cip_ssupervisor_next_scheduled_maintenance_date, NULL},
   {0x39, FALSE, 21, -1, "Scheduled Maintenance Expiration Timer", cip_int, &hf_cip_ssupervisor_scheduled_maintenance_expiration_timer, NULL},
   {0x39, FALSE, 22, -1, "Scheduled Maintenance Expiration Warning Enable", cip_bool, &hf_cip_ssupervisor_scheduled_maintenance_expiration_warning_enable, NULL},
   {0x39, FALSE, 23, -1, "Run Hours", cip_udint, &hf_cip_ssupervisor_run_hours, NULL},
   {0x39, FALSE, 24, -1, "Configuration Lock", cip_bool, &hf_cip_ssupervisor_configuration_lock, NULL},
   {0x39, FALSE, 25, -1, "Configuration UNID", cip_dissector_func, NULL, dissect_s_supervisor_configuration_unid},
   {0x39, FALSE, 26, -1, "Safety Configuration Identifier", cip_dissector_func, NULL, dissect_s_supervisor_safety_configuration_id},
   {0x39, FALSE, 27, -1, "Target UNID", cip_dissector_func, NULL, dissect_s_supervisor_target_unid},
   {0x39, FALSE, 28, -1, "Output Connection Point Owners", cip_dissector_func, NULL, dissect_s_supervisor_output_connection_point_owners},
   {0x39, FALSE, 29, -1, "Proposed TUNID", cip_dissector_func, NULL, dissect_s_supervisor_proposed_tunid},
   {0x39, FALSE, 99, -1, "Subclass", cip_uint, &hf_cip_ssupervisor_instance_subclass, NULL},

   /* Safety Validator */
   {0x3A, TRUE, 8, -1, "Safety Connection Fault Count", cip_uint, &hf_cip_svalidator_sconn_fault_count, NULL},
   {0x3A, FALSE, 1, 0, "Safety Validator State", cip_usint, &hf_cip_svalidator_state, NULL},
   {0x3A, FALSE, 2, 1, "Safety Validator Type", cip_dissector_func, NULL, dissect_s_validator_type},
   {0x3A, FALSE, 3, 2, "Ping Interval ERI Multiplier", cip_uint, &hf_cip_svalidator_ping_eri, NULL},
   {0x3A, FALSE, 4, 3, "Time Coord Msg Min Multiplier", cip_dissector_func, NULL, dissect_s_validator_time_coord_msg_min_mult},
   {0x3A, FALSE, 5, 4, "Network Time Expectation Multiplier", cip_dissector_func, NULL, dissect_s_validator_network_time_multiplier},
   {0x3A, FALSE, 6, 5, "Timeout Multiplier", cip_dissector_func, NULL, dissect_s_validator_timeout_multiplier},
   {0x3A, FALSE, 7, 6, "Max Consumer Number", cip_usint, &hf_cip_svalidator_max_consumer_num, NULL},
   {0x3A, FALSE, 8, 7, "Data Connection Instance", cip_uint, &hf_cip_svalidator_data_conn_inst, NULL},
   {0x3A, FALSE, 9, 8, "Coordination Connection Instance", cip_dissector_func, NULL, dissect_s_validator_coordination_conn_inst},
   {0x3A, FALSE, 10, 9, "Correction Connection Instance", cip_uint, &hf_cip_svalidator_correction_conn_inst, NULL},
   {0x3A, FALSE, 11, 10, "CCO Binding", cip_uint, &hf_cip_svalidator_cco_binding, NULL},
   {0x3A, FALSE, 12, 11, "Max Data Age", cip_uint, &hf_cip_svalidator_max_data_age, NULL},
   {0x3A, FALSE, 13, 12, "Application Data Path", cip_dissector_func, NULL, dissect_s_validator_app_data_path},
   /* TODO: GAA code can't get to "Error Code", because dissect_s_validator_app_data_path() will use
      all remaining bytes. Waiting on clarification in a future spec update. */
   {0x3A, FALSE, 14, 13, "Error Code", cip_uint, &hf_cip_svalidator_error_code, NULL},
   {0x3A, FALSE, 15, -1, "Producer/Consumer Fault Counters", cip_dissector_func, NULL, dissect_s_validator_prod_cons_fault_count},

   /* Sercos III Link */
   {0x4C, FALSE, 1, -1, "Safety Network Number", cip_dissector_func, NULL, dissect_sercosiii_safety_network_number},
   {0x4C, FALSE, 2, -1, "Communication Cycle Time", cip_dint, &hf_cip_sercosiii_link_communication_cycle_time, NULL},
   {0x4C, FALSE, 3, -1, "Interface Status", cip_word, &hf_cip_sercosiii_link_interface_status, NULL},
   {0x4C, FALSE, 4, -1, "Error counter MST-P/S", cip_int, &hf_cip_sercosiii_link_error_count_mstps, NULL},
   {0x4C, FALSE, 5, -1, "Error counter Port1 and Port2", cip_dissector_func, NULL, dissect_sercosiii_link_error_count_p1p2},
   {0x4C, FALSE, 6, -1, "SERCOS address", cip_int, &hf_cip_sercosiii_link_sercos_address, NULL},
};

/*
 * Protocol initialization
 */

/*
 * Function name: proto_register_cipsafety
 *
 * Purpose: Register the protocol with Wireshark, a script will add this protocol
 * to the list of protocols during the build process. This function is where the
 * header fields and subtree identifiers are registered.
 *
 * Returns: void
 */
void
proto_register_cipsafety(void)
{
   /* This is a list of header fields that can be used in the dissection or
   * to use in a filter expression */
   static hf_register_info hf[] =
   {
      { &hf_cip_reqrsp,
        { "Request/Response", "cip.rr",
          FT_UINT8, BASE_HEX, VALS(cip_sc_rr), CIP_SC_RESPONSE_MASK, "Request or Response message", HFILL }
      },
      { &hf_cip_data,
        { "Data", "cip.data",
          FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }
      },

      { &hf_cipsafety_data,
        { "Data", "enip.connection_transport_data",
          FT_BYTES, BASE_NONE, NULL, 0, "Connection Transport Data", HFILL }
      },
      { &hf_cipsafety_mode_byte,
        { "Mode Byte", "cipsafety.mode_byte",
          FT_UINT8, BASE_HEX, NULL, 0, NULL, HFILL }
      },
      { &hf_cipsafety_mode_byte_ping_count,
        { "Ping Count", "cipsafety.mode_byte.ping_count",
          FT_UINT8, BASE_DEC, NULL, 0x03, NULL, HFILL }
      },
      { &hf_cipsafety_mode_byte_not_tbd,
        { "Not TBD Bit", "cipsafety.mode_byte.not_tbd",
          FT_BOOLEAN, 8, NULL, 0x04, NULL, HFILL }
      },
      { &hf_cipsafety_mode_byte_tbd_2_copy,
        { "TBD 2 Bit Copy", "cipsafety.mode_byte.tbd_2_copy",
          FT_BOOLEAN, 8, NULL, 0x08, NULL, HFILL }
      },
      { &hf_cipsafety_mode_byte_not_run_idle,
        { "Not Run/Idle", "cipsafety.mode_byte.not_run_idle",
          FT_BOOLEAN, 8, NULL, 0x10, NULL, HFILL }
      },
      { &hf_cipsafety_mode_byte_tbd,
        { "TBD Bit", "cipsafety.mode_byte.tbd",
          FT_BOOLEAN, 8, NULL, 0x20, NULL, HFILL }
      },
      { &hf_cipsafety_mode_byte_tbd_2_bit,
        { "TBD 2 Bit", "cipsafety.mode_byte.tbd_2_bit",
          FT_BOOLEAN, 8, NULL, 0x40, NULL, HFILL }
      },
      { &hf_cipsafety_mode_byte_run_idle,
        { "Run/Idle", "cipsafety.mode_byte.run_idle",
          FT_BOOLEAN, 8, NULL, 0x80, NULL, HFILL }
      },
      { &hf_cipsafety_crc_s1,
        { "CRC S1", "cipsafety.crc_s1",
          FT_UINT8, BASE_HEX, NULL, 0, NULL, HFILL }
      },
      { &hf_cipsafety_crc_s1_status,
        { "CRC S1 Status", "cipsafety.crc_s1.status",
          FT_UINT8, BASE_NONE, VALS(proto_checksum_vals), 0, NULL, HFILL }
      },
      { &hf_cipsafety_crc_s2,
        { "CRC S2", "cipsafety.crc_s2",
          FT_UINT8, BASE_HEX, NULL, 0, NULL, HFILL }
      },
      { &hf_cipsafety_crc_s2_status,
        { "CRC S2 Status", "cipsafety.crc_s2.status",
          FT_UINT8, BASE_NONE, VALS(proto_checksum_vals), 0, NULL, HFILL }
      },
      { &hf_cipsafety_crc_s3,
        { "CRC S3", "cipsafety.crc_s3",
          FT_UINT16, BASE_HEX, NULL, 0, NULL, HFILL }
      },
      { &hf_cipsafety_crc_s3_status,
        { "CRC S3 Status", "cipsafety.crc_s3.status",
          FT_UINT8, BASE_NONE, VALS(proto_checksum_vals), 0, NULL, HFILL }
      },
      { &hf_cipsafety_complement_crc_s3,
        { "Complement CRC S3", "cipsafety.complement_crc_s3",
          FT_UINT16, BASE_HEX, NULL, 0, NULL, HFILL }
      },
      { &hf_cipsafety_complement_crc_s3_status,
        { "Complement CRC S3 Status", "cipsafety.complement_crc_s3.status",
          FT_UINT8, BASE_NONE, VALS(proto_checksum_vals), 0, NULL, HFILL }
      },
      { &hf_cipsafety_timestamp,
        { "Timestamp", "cipsafety.timestamp",
          FT_UINT16, BASE_DEC, NULL, 0, NULL, HFILL }
      },
      { &hf_cipsafety_ack_byte,
        { "ACK Byte", "cipsafety.ack_byte",
          FT_UINT8, BASE_HEX, NULL, 0, NULL, HFILL }
      },
      { &hf_cipsafety_ack_byte_ping_count_reply,
        { "Ping Count Reply", "cipsafety.ack_byte.ping_count_reply",
          FT_UINT8, BASE_HEX, NULL, 0x03, NULL, HFILL }
      },
      { &hf_cipsafety_ack_byte_reserved1,
        { "Reserved", "cipsafety.ack_byte.reserved1",
          FT_UINT8, BASE_HEX, NULL, 0x04, NULL, HFILL }
      },
      { &hf_cipsafety_ack_byte_ping_response,
        { "Ping Response", "cipsafety.ack_byte.ping_response",
          FT_BOOLEAN, 8, NULL, 0x08, NULL, HFILL }
      },
      { &hf_cipsafety_ack_byte_reserved2,
        { "Reserved", "cipsafety.ack_byte.reserved2",
          FT_UINT8, BASE_HEX, NULL, 0x70, NULL, HFILL }
      },
      { &hf_cipsafety_ack_byte_parity_even,
        { "Parity Even", "cipsafety.ack_byte.parity_even",
          FT_BOOLEAN, 8, NULL, 0x80, NULL, HFILL }
      },
      { &hf_cipsafety_ack_byte2,
        { "ACK Byte 2", "cipsafety.ack_byte2",
          FT_UINT8, BASE_HEX, NULL, 0, NULL, HFILL }
      },
      { &hf_cipsafety_consumer_time_value,
        { "Consumer Time Value", "cipsafety.consumer_time_value",
          FT_UINT16, BASE_HEX, NULL, 0, NULL, HFILL }
      },
      { &hf_cipsafety_mcast_byte,
        { "MCAST Byte", "cipsafety.mcast_byte",
          FT_UINT8, BASE_HEX, NULL, 0, NULL, HFILL }
      },
      { &hf_cipsafety_mcast_byte_consumer_num,
        { "Consumer #", "cipsafety.mcast_byte.consumer_num",
          FT_UINT8, BASE_HEX, NULL, 0x0F, NULL, HFILL }
      },
      { &hf_cipsafety_mcast_byte_reserved1,
        { "Reserved", "cipsafety.mcast_byte.reserved1",
          FT_UINT8, BASE_HEX, NULL, 0x10, NULL, HFILL }
      },
      { &hf_cipsafety_mcast_byte_mai,
        { "Multicast Active/Idle", "cipsafety.mcast_byte.active_idle",
          FT_BOOLEAN, 8, TFS(&cip_safety_vals_active_idle), 0x20, NULL, HFILL }
      },
      { &hf_cipsafety_mcast_byte_reserved2,
        { "Reserved", "cipsafety.mcast_byte.reserved2",
          FT_UINT8, BASE_HEX, NULL, 0x40, NULL, HFILL }
      },
      { &hf_cipsafety_mcast_byte_parity_even,
        { "Parity Even", "cipsafety.mcast_byte.parity_even",
          FT_BOOLEAN, 8, NULL, 0x80, NULL, HFILL }
      },
      { &hf_cipsafety_mcast_byte2,
        { "MCAST Byte 2", "cipsafety.mcast_byte2",
          FT_UINT8, BASE_HEX, NULL, 0, NULL, HFILL }
      },
      { &hf_cipsafety_time_correction,
        { "Time Correction", "cipsafety.time_correction",
          FT_UINT16, BASE_HEX, NULL, 0, NULL, HFILL }
      },
      { &hf_cipsafety_crc_s5_0,
        { "CRC S5_0", "cipsafety.crc_s5_0",
          FT_UINT8, BASE_HEX, NULL, 0, NULL, HFILL }
      },
      { &hf_cipsafety_crc_s5_1,
        { "CRC S5_1", "cipsafety.crc_s5_1",
          FT_UINT8, BASE_HEX, NULL, 0, NULL, HFILL }
      },
      { &hf_cipsafety_crc_s5_2,
        { "CRC S5_2", "cipsafety.crc_s5_2",
          FT_UINT8, BASE_HEX, NULL, 0, NULL, HFILL }
      },
      { &hf_cipsafety_crc_s5_status,
        { "CRC S5 Status", "cipsafety.crc_s5.status",
          FT_UINT8, BASE_NONE, VALS(proto_checksum_vals), 0, NULL, HFILL }
      },
      { &hf_cipsafety_complement_data,
        { "Complement Data", "cipsafety.complement_data",
          FT_BYTES, BASE_NONE, NULL, 0, "Connection Transport Data", HFILL }
      },

      { &hf_cip_sercosiii_link_snn,
        { "Data", "cipsafety.sercosiii_link.snn",
          FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_sercosiii_link_communication_cycle_time,
        { "Communication Cycle Time", "cipsafety.sercosiii_link.communication_cycle_time",
          FT_INT32, BASE_DEC, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_sercosiii_link_interface_status,
        { "Communication Cycle Time", "cipsafety.sercosiii_link.interface_status",
          FT_UINT16, BASE_HEX, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_sercosiii_link_error_count_mstps,
        { "Error Counter MST-P/S", "cipsafety.sercosiii_link.error_count_mstps",
          FT_INT16, BASE_DEC, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_sercosiii_link_error_count_p1,
        { "Error Count Port 1", "cipsafety.sercosiii_link.error_count_p1",
          FT_INT16, BASE_DEC, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_sercosiii_link_error_count_p2,
        { "Error Count Port 2", "cipsafety.sercosiii_link.error_count_p2",
          FT_INT16, BASE_DEC, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_sercosiii_link_sercos_address,
        { "SERCOS Address", "cipsafety.sercosiii_link.sercos_address",
          FT_INT16, BASE_DEC, NULL, 0, NULL, HFILL }
      },
   };

   static hf_register_info hf_ssupervisor[] = {
      { &hf_cip_ssupervisor_sc,
        { "Service", "cipsafety.ssupervisor.sc",
          FT_UINT8, BASE_HEX, VALS(cip_sc_vals_ssupervisor), CIP_SC_MASK, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_recover_data,
        { "Data", "cipsafety.ssupervisor.recover.data",
          FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_perform_diag_data,
        { "Data", "cipsafety.ssupervisor.perform_diag.data",
          FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_configure_request_password,
        { "Password", "cipsafety.ssupervisor.configure_request.password",
          FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_configure_request_tunid,
        { "Target UNID", "cipsafety.ssupervisor.configure_request.tunid",
          FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_configure_request_tunid_ssn_timestamp,
        { "TUNID SSN Timestamp", "cipsafety.ssupervisor.configure_request.tunid.ssn.timestamp",
          FT_ABSOLUTE_TIME, ABSOLUTE_TIME_UTC, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_configure_request_tunid_ssn_date,
        { "TUNID SSN  (Manual) Date", "cipsafety.ssupervisor.configure_request.tunid.ssn.date",
          FT_UINT16, BASE_HEX, VALS(cipsafety_ssn_date_vals), 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_configure_request_tunid_ssn_time,
        { "TUNID SSN  (Manual) Time", "cipsafety.ssupervisor.configure_request.tunid.ssn.time",
          FT_UINT32, BASE_HEX, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_configure_request_tunid_macid,
        { "MAC ID", "cipsafety.ssupervisor.configure_request.tunid.macid",
          FT_UINT32, BASE_HEX, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_configure_request_ounid,
        { "Originator UNID", "cipsafety.ssupervisor.configure_request.ounid",
          FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_configure_request_ounid_ssn_timestamp,
        { "OUNID SSN Timestamp", "cipsafety.ssupervisor.configure_request.ounid.ssn.timestamp",
          FT_ABSOLUTE_TIME, ABSOLUTE_TIME_UTC, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_configure_request_ounid_ssn_date,
        { "OUNID SSN  (Manual) Date", "cipsafety.ssupervisor.configure_request.ounid.ssn.date",
          FT_UINT16, BASE_HEX, VALS(cipsafety_ssn_date_vals), 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_configure_request_ounid_ssn_time,
        { "OUNID SSN  (Manual) Time", "cipsafety.ssupervisor.configure_request.ounid.ssn.time",
          FT_UINT32, BASE_HEX, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_configure_request_ounid_macid,
        { "MAC ID", "cipsafety.ssupervisor.configure_request.ounid.macid",
          FT_UINT32, BASE_HEX, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_validate_configuration_sccrc,
        { "SCCRC", "cipsafety.ssupervisor.validate_configuration.sccrc",
          FT_UINT32, BASE_HEX, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_validate_configuration_scts_timestamp,
        { "SCTS (Timestamp)", "cipsafety.ssupervisor.validate_configuration.scts.timestamp",
          FT_ABSOLUTE_TIME, ABSOLUTE_TIME_UTC, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_validate_configuration_scts_date,
        { "SCTS (Manual) Date", "cipsafety.ssupervisor.validate_configuration.scts.date",
          FT_UINT16, BASE_HEX, VALS(cipsafety_ssn_date_vals), 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_validate_configuration_scts_time,
        { "SCTS (Manual) Time", "cipsafety.ssupervisor.validate_configuration.scts.time",
          FT_UINT32, BASE_HEX, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_validate_configuration_ext_error,
        { "Extended Error", "cipsafety.ssupervisor.validate_configuration.ext_error",
          FT_UINT16, BASE_DEC, VALS(cip_ssupervisor_validate_configuration_ext_error_vals), 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_set_password_current_password,
        { "Current Password", "cipsafety.ssupervisor.set_password.current_pass",
          FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_set_password_new_password,
        { "New Password", "cipsafety.ssupervisor.set_password.new_pass",
          FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_configure_lock_value,
        { "Lock Value", "cipsafety.ssupervisor.configure_lock.lock",
          FT_UINT8, BASE_DEC, VALS(cip_ssupervisor_lock_vals), 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_configure_lock_password,
        { "Password", "cipsafety.ssupervisor.configure_lock.password",
          FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_configure_lock_tunid,
        { "Target UNID", "cipsafety.ssupervisor.configure_lock.tunid",
          FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_configure_lock_tunid_ssn_timestamp,
        { "TUNID SSN Timestamp", "cipsafety.ssupervisor.configure_lock.tunid.ssn.timestamp",
          FT_ABSOLUTE_TIME, ABSOLUTE_TIME_UTC, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_configure_lock_tunid_ssn_date,
        { "TUNID SSN  (Manual) Date", "cipsafety.ssupervisor.configure_lock.tunid.ssn.date",
          FT_UINT16, BASE_HEX, VALS(cipsafety_ssn_date_vals), 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_configure_lock_tunid_ssn_time,
        { "TUNID SSN  (Manual) Time", "cipsafety.ssupervisor.configure_lock.tunid.ssn.time",
          FT_UINT32, BASE_HEX, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_configure_lock_tunid_macid,
        { "MAC ID", "cipsafety.ssupervisor.configure_lock.tunid.macid",
          FT_UINT32, BASE_HEX, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_mode_change_value,
        { "Value", "cipsafety.ssupervisor.mode_change.value",
          FT_UINT8, BASE_DEC, VALS(cip_ssupervisor_change_mode_vals), 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_mode_change_password,
        { "Password", "cipsafety.ssupervisor.mode_change.password",
          FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_reset_type,
        { "Reset Type", "cipsafety.ssupervisor.reset.type",
          FT_UINT8, BASE_DEC, VALS(cip_reset_type_vals), 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_reset_password,
        { "Password", "cipsafety.ssupervisor.reset.password",
          FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_reset_tunid,
        { "Target UNID", "cipsafety.ssupervisor.reset.tunid",
          FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_reset_tunid_tunid_ssn_timestamp,
        { "TUNID SSN Timestamp", "cipsafety.ssupervisor.reset.tunid.ssn.timestamp",
          FT_ABSOLUTE_TIME, ABSOLUTE_TIME_UTC, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_reset_tunid_tunid_ssn_date,
        { "TUNID SSN  (Manual) Date", "cipsafety.ssupervisor.reset.tunid.ssn.date",
          FT_UINT16, BASE_HEX, VALS(cipsafety_ssn_date_vals), 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_reset_tunid_tunid_ssn_time,
        { "TUNID SSN  (Manual) Time", "cipsafety.ssupervisor.reset.tunid.ssn.time",
          FT_UINT32, BASE_HEX, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_reset_tunid_macid,
        { "MAC ID", "cipsafety.ssupervisor.reset.tunid.macid",
          FT_UINT32, BASE_HEX, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_reset_attr_bitmap,
        { "Attribute Bit Map", "cipsafety.ssupervisor.reset.attr_bitmap",
          FT_UINT8, BASE_HEX, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_reset_attr_bitmap_macid,
        { "Preserve MacID", "cipsafety.ssupervisor.reset.attr_bitmap.macid",
          FT_BOOLEAN, 8, TFS(&tfs_true_false), 0x01, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_reset_attr_bitmap_baudrate,
        { "Preserve Baud Rate", "cipsafety.ssupervisor.reset.attr_bitmap.baudrate",
          FT_BOOLEAN, 8, TFS(&tfs_true_false), 0x02, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_reset_attr_bitmap_tunid,
        { "Preserve TUNID", "cipsafety.ssupervisor.reset.attr_bitmap.tunid",
          FT_BOOLEAN, 8, TFS(&tfs_true_false), 0x04, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_reset_attr_bitmap_password,
        { "Preserve Password", "cipsafety.ssupervisor.reset.attr_bitmap.password",
          FT_BOOLEAN, 8, TFS(&tfs_true_false), 0x08, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_reset_attr_bitmap_cfunid,
        { "Preserve CFUNID", "cipsafety.ssupervisor.reset.attr_bitmap.cfunid",
          FT_BOOLEAN, 8, TFS(&tfs_true_false), 0x10, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_reset_attr_bitmap_ocpunid,
        { "Preserve OPCUNID", "cipsafety.ssupervisor.reset.attr_bitmap.ocpunid",
          FT_BOOLEAN, 8, TFS(&tfs_true_false), 0x20, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_reset_attr_bitmap_reserved,
        { "Reserved", "cipsafety.ssupervisor.reset.attr_bitmap.reserved",
          FT_BOOLEAN, 8, TFS(&tfs_true_false), 0x40, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_reset_attr_bitmap_extended,
        { "Use Extended Map", "cipsafety.ssupervisor.reset.attr_bitmap.extended",
          FT_BOOLEAN, 8, TFS(&tfs_true_false), 0x80, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_reset_password_data_size,
        { "Data Size", "cipsafety.ssupervisor.reset_password.data_size",
          FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_reset_password_data,
        { "Password Data", "cipsafety.ssupervisor.reset_password.password_data",
          FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_propose_tunid_tunid,
        { "Target UNID", "cipsafety.ssupervisor.propose_tunid.tunid",
          FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_propose_tunid_tunid_ssn_timestamp,
        { "TUNID SSN Timestamp", "cipsafety.ssupervisor.propose_tunid.tunid.ssn.timestamp",
          FT_ABSOLUTE_TIME, ABSOLUTE_TIME_UTC, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_propose_tunid_tunid_ssn_date,
        { "TUNID SSN  (Manual) Date", "cipsafety.ssupervisor.propose_tunid.tunid.ssn.date",
          FT_UINT16, BASE_HEX, VALS(cipsafety_ssn_date_vals), 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_propose_tunid_tunid_ssn_time,
        { "TUNID SSN  (Manual) Time", "cipsafety.ssupervisor.propose_tunid.tunid.ssn.time",
          FT_UINT32, BASE_HEX, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_propose_tunid_tunid_macid,
        { "MAC ID", "cipsafety.ssupervisor.propose_tunid.tunid.macid",
          FT_UINT32, BASE_HEX, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_apply_tunid_tunid,
        { "Target UNID", "cipsafety.ssupervisor.apply_tunid.tunid",
          FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_apply_tunid_tunid_ssn_timestamp,
        { "TUNID SSN Timestamp", "cipsafety.ssupervisor.apply_tunid.tunid.ssn.timestamp",
          FT_ABSOLUTE_TIME, ABSOLUTE_TIME_UTC, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_apply_tunid_tunid_ssn_date,
        { "TUNID SSN  (Manual) Date", "cipsafety.ssupervisor.apply_tunid.tunid.ssn.date",
          FT_UINT16, BASE_HEX, VALS(cipsafety_ssn_date_vals), 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_apply_tunid_tunid_ssn_time,
        { "TUNID SSN  (Manual) Time", "cipsafety.ssupervisor.apply_tunid.tunid.ssn.time",
          FT_UINT32, BASE_HEX, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_apply_tunid_tunid_macid,
        { "MAC ID", "cipsafety.ssupervisor.apply_tunid.tunid.macid",
          FT_UINT32, BASE_HEX, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_class_subclass,
        { "Subclass", "cipsafety.ssupervisor.class_subclass",
          FT_UINT16, BASE_DEC, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_num_attr,
        { "Number of Attributes", "cipsafety.ssupervisor.num_attr",
          FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_attr_list,
        { "Attributes List Item", "cipsafety.ssupervisor.attr_item",
          FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_manufacture_name,
        { "Manufacturer Name", "cipsafety.ssupervisor.manufacture_name",
          FT_STRING, BASE_NONE, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_manufacture_model_number,
        { "Manufacturer Model Number", "cipsafety.ssupervisor.manufacture_model_number",
          FT_STRING, BASE_NONE, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_sw_rev_level,
        { "Software Revision Level", "cipsafety.ssupervisor.sw_rev_level",
          FT_STRING, BASE_NONE, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_hw_rev_level,
        { "Hardware Revision Level", "cipsafety.ssupervisor.hw_rev_level",
          FT_STRING, BASE_NONE, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_manufacture_serial_number,
        { "Manufacturer Serial Number", "cipsafety.ssupervisor.manufacture_serial_number",
          FT_STRING, BASE_NONE, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_device_config,
        { "Device Configuration", "cipsafety.ssupervisor.device_config",
          FT_STRING, BASE_NONE, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_device_status,
        { "Device Status", "cipsafety.ssupervisor.device_status",
          FT_UINT8, BASE_DEC, VALS(cip_ssupervisor_device_status_type_vals), 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_exception_status,
        { "Exception Status", "cipsafety.ssupervisor.exception_status",
          FT_UINT8, BASE_HEX, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_exception_detail_ced_size,
        { "Common Exception Detail Size", "cipsafety.ssupervisor.exception_detail.ced.size",
          FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_exception_detail_ced_detail,
        { "Common Exception Detail Data", "cipsafety.ssupervisor.exception_detail.ced.detail",
          FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_exception_detail_ded_size,
        { "Device Exception Detail Size", "cipsafety.ssupervisor.exception_detail.ded.size",
          FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_exception_detail_ded_detail,
        { "Device Exception Detail Data", "cipsafety.ssupervisor.exception_detail.ded.detail",
          FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_exception_detail_med_size,
        { "Manufacturer Exception Detail Size", "cipsafety.ssupervisor.exception_detail.med.size",
          FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_exception_detail_med_detail,
        { "Manufacturer Exception Detail Data", "cipsafety.ssupervisor.exception_detail.med.detail",
          FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_alarm_enable,
        { "Exception Detail Alarm", "cipsafety.ssupervisor.alarm_enable",
          FT_BOOLEAN, BASE_NONE, TFS(&tfs_true_false), 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_warning_enable,
        { "Exception Detail Warning", "cipsafety.ssupervisor.warning_enable",
          FT_BOOLEAN, BASE_NONE, TFS(&tfs_true_false), 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_time,
        { "Time", "cipsafety.ssupervisor.time",
          FT_ABSOLUTE_TIME, ABSOLUTE_TIME_UTC, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_clock_power_cycle_behavior,
        { "Clock Power Cycle Behavior", "cipsafety.ssupervisor.clock_power_cycle_behavior",
          FT_UINT8, BASE_DEC, VALS(cip_ssupervisor_clock_power_cycle_type_vals), 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_last_maintenance_date,
        { "Last Maintenance Date", "cipsafety.ssupervisor.last_maintenance_date",
          FT_UINT16, BASE_DEC, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_next_scheduled_maintenance_date,
        { "Next Scheduled Maintenance Date", "cipsafety.ssupervisor.next_scheduled_maintenance_date",
          FT_UINT16, BASE_DEC, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_scheduled_maintenance_expiration_timer,
        { "Scheduled Maintenance Expiration Timer", "cipsafety.ssupervisor.scheduled_maintenance_expiration_timer",
          FT_INT16, BASE_DEC, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_scheduled_maintenance_expiration_warning_enable,
        { "Scheduled Maintenance Expiration Warning Enable", "cipsafety.ssupervisor.scheduled_maintenance_expiration_warning",
          FT_BOOLEAN, BASE_NONE, TFS(&tfs_enabled_disabled), 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_run_hours,
        { "Run Hours", "cipsafety.ssupervisor.run_hours",
          FT_UINT32, BASE_DEC, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_configuration_lock,
        { "Configuration Lock", "cipsafety.ssupervisor.configuration_lock",
          FT_UINT8, BASE_DEC, VALS(cip_ssupervisor_lock_vals), 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_configuration_unid_ssn_timestamp,
        { "Configuration UNID SSN Timestamp", "cipsafety.ssupervisor.configuration_unid.ssn.timestamp",
          FT_ABSOLUTE_TIME, ABSOLUTE_TIME_UTC, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_configuration_unid_ssn_date,
        { "Configuration UNID SSN  (Manual) Date", "cipsafety.ssupervisor.configuration_unid.ssn.date",
          FT_UINT16, BASE_HEX, VALS(cipsafety_ssn_date_vals), 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_configuration_unid_ssn_time,
        { "Configuration UNID SSN  (Manual) Time", "cipsafety.ssupervisor.configuration_unid.ssn.time",
          FT_UINT32, BASE_HEX, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_configuration_unid_macid,
        { "Configuration UNID MAC ID", "cipsafety.ssupervisor.configuration_unid.macid",
          FT_UINT32, BASE_HEX, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_safety_configuration_id_ssn_timestamp,
        { "Safety Configuration ID SSN Timestamp", "cipsafety.ssupervisor.safety_configuration_id.ssn.timestamp",
          FT_ABSOLUTE_TIME, ABSOLUTE_TIME_UTC, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_safety_configuration_id_ssn_date,
        { "Safety Configuration ID SSN  (Manual) Date", "cipsafety.ssupervisor.safety_configuration_id.ssn.date",
          FT_UINT16, BASE_HEX, VALS(cipsafety_ssn_date_vals), 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_safety_configuration_id_ssn_time,
        { "Safety Configuration ID SSN  (Manual) Time", "cipsafety.ssupervisor.safety_configuration_id.ssn.time",
          FT_UINT32, BASE_HEX, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_safety_configuration_id_macid,
        { "Safety Configuration ID MAC ID", "cipsafety.ssupervisor.safety_configuration_id.macid",
          FT_UINT32, BASE_HEX, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_target_unid_ssn_timestamp,
        { "Target UNID SSN Timestamp", "cipsafety.ssupervisor.target_unid.ssn.timestamp",
          FT_ABSOLUTE_TIME, ABSOLUTE_TIME_UTC, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_target_unid_ssn_date,
        { "Target UNID SSN  (Manual) Date", "cipsafety.ssupervisor.target_unid.ssn.date",
          FT_UINT16, BASE_HEX, VALS(cipsafety_ssn_date_vals), 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_target_unid_ssn_time,
        { "Target UNID SSN  (Manual) Time", "cipsafety.ssupervisor.target_unid.ssn.time",
          FT_UINT32, BASE_HEX, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_target_unid_macid,
        { "Target UNID MAC ID", "cipsafety.ssupervisor.target_unid.macid",
          FT_UINT32, BASE_HEX, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_cp_owners_num_entries,
        { "Number of Array Entries", "cipsafety.ssupervisor.cp_owners.num_entries",
          FT_UINT16, BASE_DEC, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_output_cp_owners_ocpunid_ssn_timestamp,
        { "OCPUNID SSN Timestamp", "cipsafety.ssupervisor.cp_owners.ssn.timestamp",
          FT_ABSOLUTE_TIME, ABSOLUTE_TIME_UTC, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_output_cp_owners_ocpunid_ssn_date,
        { "OCPUNID SSN  (Manual) Date", "cipsafety.ssupervisor.cp_owners.ssn.date",
          FT_UINT16, BASE_HEX, VALS(cipsafety_ssn_date_vals), 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_output_cp_owners_ocpunid_ssn_time,
        { "OCPUNID SSN  (Manual) Time", "cipsafety.ssupervisor.cp_owners.ssn.time",
          FT_UINT32, BASE_HEX, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_output_cp_owners_ocpunid_macid,
        { "OCPUNID MAC ID", "cipsafety.ssupervisor.cp_owners.ocpunid.macid",
          FT_UINT32, BASE_HEX, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_cp_owners_app_path_size,
        { "EPATH Size", "cipsafety.ssupervisor.cp_owners.epath_size",
          FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_proposed_tunid_ssn_timestamp,
        { "Proposed TUNID SSN Timestamp", "cipsafety.ssupervisor.proposed_tunid.ssn.timestamp",
          FT_ABSOLUTE_TIME, ABSOLUTE_TIME_UTC, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_proposed_tunid_ssn_date,
        { "Proposed TUNID SSN  (Manual) Date", "cipsafety.ssupervisor.proposed_tunid.ssn.date",
          FT_UINT16, BASE_HEX, VALS(cipsafety_ssn_date_vals), 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_proposed_tunid_ssn_time,
        { "Proposed TUNID SSN  (Manual) Time", "cipsafety.ssupervisor.proposed_tunid.ssn.time",
          FT_UINT32, BASE_HEX, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_proposed_tunid_macid,
        { "Proposed TUNID MAC ID", "cipsafety.ssupervisor.proposed_tunid.macid",
          FT_UINT32, BASE_HEX, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_ssupervisor_instance_subclass,
        { "Subclass", "cipsafety.ssupervisor.instance_subclass",
          FT_UINT16, BASE_DEC, NULL, 0, NULL, HFILL }
      }
   };

   static hf_register_info hf_svalidator[] = {
      { &hf_cip_svalidator_sc,
        { "Service", "cipsafety.svalidator.sc",
          FT_UINT8, BASE_HEX, VALS(cip_sc_vals_svalidator), CIP_SC_MASK, NULL, HFILL }
      },

      { &hf_cip_svalidator_sconn_fault_count,
        { "Safety Connection Fault Count", "cipsafety.svalidator.sconn_fault_count",
          FT_UINT16, BASE_DEC, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_svalidator_state,
        { "Safety Validator State", "cipsafety.svalidator.state",
          FT_UINT8, BASE_DEC, VALS(cip_svalidator_state_vals), 0, NULL, HFILL }
      },
      { &hf_cip_svalidator_type,
        { "Safety Validator Type", "cipsafety.svalidator.type",
          FT_UINT8, BASE_HEX, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_svalidator_type_pc,
        { "Producer/Consumer", "cipsafety.svalidator.type.pc",
          FT_UINT8, BASE_HEX, VALS(cip_svalidator_type_pc_vals), 0x80, NULL, HFILL }
      },
      { &hf_cip_svalidator_type_conn_type,
        { "Safety Connection Type", "cipsafety.svalidator.type.conn_type",
          FT_UINT8, BASE_DEC, VALS(cip_svalidator_type_conn_type_vals), 0x7F, NULL, HFILL }
      },
      { &hf_cip_svalidator_ping_eri,
        { "Ping Interval EPI Multiplier", "cipsafety.svalidator.ping_eri",
          FT_UINT16, BASE_DEC, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_svalidator_time_coord_msg_min_mult_size,
        { "Time Coord Msg Min Multiplier Size", "cipsafety.svalidator.time_coord_msg_min_mult.size",
          FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_svalidator_time_coord_msg_min_mult_item,
        { "Time Coord Msg Min Multiplier Item", "cipsafety.svalidator.time_coord_msg_min_mult.item",
          FT_UINT16, BASE_DEC, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_svalidator_network_time_multiplier_size,
        { "Network Time Expectation Multiplier Size", "cipsafety.svalidator.network_time_multiplier.size",
          FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_svalidator_network_time_multiplier_item,
        { "Network Time Expectation Multiplier Item", "cipsafety.svalidator.network_time_multiplier.item",
          FT_UINT16, BASE_DEC, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_svalidator_timeout_multiplier_size,
        { "Timeout Multiplier Size", "cipsafety.svalidator.timeout_multiplier.size",
          FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_svalidator_timeout_multiplier_item,
        { "Timeout Multiplier Item", "cipsafety.svalidator.timeout_multiplier.item",
          FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_svalidator_max_consumer_num,
        { "Max Consumer Number", "cipsafety.svalidator.max_consumer_num",
          FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_svalidator_data_conn_inst,
        { "Data Connection Instance", "cipsafety.svalidator.data_conn_inst",
          FT_UINT16, BASE_DEC, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_svalidator_coordination_conn_inst_size,
        { "Coordination Connection Instance Size", "cipsafety.svalidator.coordination_conn_inst.size",
          FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_svalidator_coordination_conn_inst_item,
        { "Coordination Connection Instance Item", "cipsafety.svalidator.coordination_conn_inst.item",
          FT_UINT16, BASE_DEC, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_svalidator_correction_conn_inst,
        { "Correction Connection Instance", "cipsafety.svalidator.correction_conn_inst",
          FT_UINT16, BASE_DEC, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_svalidator_cco_binding,
        { "CCO Binding", "cipsafety.svalidator.cco_binding",
          FT_UINT16, BASE_DEC, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_svalidator_max_data_age,
        { "Max Data Age", "cipsafety.svalidator.max_data_age",
          FT_UINT16, BASE_DEC, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_svalidator_error_code,
        { "Error Code", "cipsafety.svalidator.error_code",
          FT_UINT16, BASE_DEC, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_svalidator_prod_cons_fault_count_size,
        { "Producer/Consumer Counter Size", "cipsafety.svalidator.prod_cons_fault_count.size",
          FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL }
      },
      { &hf_cip_svalidator_prod_cons_fault_count_item,
        { "Producer/Consumer Counter Item", "cipsafety.svalidator.prod_cons_fault_count.item",
          FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL }
      }
   };

   static gint *ett[] = {
      &ett_cip_safety,
      &ett_path,
      &ett_cipsafety_mode_byte,
      &ett_cipsafety_ack_byte,
      &ett_cipsafety_mcast_byte
   };

   static gint *ett_ssupervisor[] = {
      &ett_cip_class_s_supervisor,
      &ett_ssupervisor_rrsc,
      &ett_ssupervisor_cmd_data,
      &ett_ssupervisor_propose_tunid,
      &ett_ssupervisor_propose_tunid_ssn,
      &ett_ssupervisor_configure_request_tunid,
      &ett_ssupervisor_configure_request_tunid_ssn,
      &ett_ssupervisor_configure_request_ounid,
      &ett_ssupervisor_configure_request_ounid_ssn,
      &ett_ssupervisor_configure_lock_tunid,
      &ett_ssupervisor_configure_lock_tunid_ssn,
      &ett_ssupervisor_reset_tunid,
      &ett_ssupervisor_reset_tunid_ssn,
      &ett_ssupervisor_apply_tunid,
      &ett_ssupervisor_apply_tunid_ssn,
      &ett_exception_detail_common,
      &ett_exception_detail_device,
      &ett_exception_detail_manufacturer,
      &ett_ssupervisor_configuration_unid,
      &ett_ssupervisor_configuration_unid_ssn,
      &ett_ssupervisor_safety_configuration_id,
      &ett_ssupervisor_safety_configuration_id_ssn,
      &ett_ssupervisor_target_unid,
      &ett_ssupervisor_target_unid_ssn,
      &ett_ssupervisor_output_cp_owners,
      &ett_ssupervisor_output_cp_owners_ocpunid,
      &ett_ssupervisor_output_cp_owners_ocpunid_ssn,
      &ett_ssupervisor_proposed_tunid,
      &ett_ssupervisor_proposed_tunid_ssn,
      &ett_cip_ssupervisor_reset_attr_bitmap
   };

   static gint *ett_svalidator[] = {
      &ett_cip_class_s_validator,
      &ett_svalidator_rrsc,
      &ett_svalidator_cmd_data,
      &ett_svalidator_type
   };

   static ei_register_info ei[] = {
      { &ei_cipsafety_tbd2_not_complemented, { "cipsafety.tbd2_not_complemented", PI_PROTOCOL, PI_WARN, "TBD_2_bit not complemented", EXPFILL }},
      { &ei_cipsafety_tbd_not_copied, { "cipsafety.tbd_not_copied", PI_PROTOCOL, PI_WARN, "TBD bit not copied", EXPFILL }},
      { &ei_cipsafety_run_idle_not_complemented, { "cipsafety.run_idle_not_complemented", PI_PROTOCOL, PI_WARN, "Run/Idle bit not complemented", EXPFILL }},
      { &ei_mal_io, { "cipsafety.malformed.io", PI_MALFORMED, PI_ERROR, "Malformed CIP Safety I/O packet", EXPFILL }},
      { &ei_mal_sercosiii_link_error_count_p1p2, { "cipsafety.malformed.sercosiii_link.error_count_p1p2", PI_MALFORMED, PI_ERROR, "Malformed SERCOS III Attribute 5", EXPFILL }},
      { &ei_cipsafety_not_complement_data, { "cipsafety.not_complement_data", PI_PROTOCOL, PI_WARN, "Data not complemented", EXPFILL }},
      { &ei_cipsafety_crc_s1, { "cipsafety.crc_s1.incorrect", PI_PROTOCOL, PI_WARN, "CRC-S1 incorrect", EXPFILL }},
      { &ei_cipsafety_crc_s2, { "cipsafety.crc_s2.incorrect", PI_PROTOCOL, PI_WARN, "CRC-S2 incorrect", EXPFILL }},
      { &ei_cipsafety_crc_s3, { "cipsafety.crc_s3.incorrect", PI_PROTOCOL, PI_WARN, "CRC-S3 incorrect", EXPFILL }},
      { &ei_cipsafety_complement_crc_s3, { "cipsafety.complement_crc_s3.incorrect", PI_PROTOCOL, PI_WARN, "Complement CRC-S3 incorrect", EXPFILL }},
      { &ei_cipsafety_crc_s5, { "cipsafety.crc_s5.incorrect", PI_PROTOCOL, PI_WARN, "CRC-S5 incorrect", EXPFILL }},
      };

   static ei_register_info ei_ssupervisor[] = {
      { &ei_mal_ssupervisor_exception_detail_ced, { "cipsafety.ssupervisor.malformed.exception_detail.ced", PI_MALFORMED, PI_ERROR,
                        "Malformed Safety Supervisor Exception Detail (Common Exception Detail)", EXPFILL }},
      { &ei_mal_ssupervisor_exception_detail_ded, { "cipsafety.ssupervisor.malformed.exception_detail.ded", PI_MALFORMED, PI_ERROR,
                        "Malformed Safety Supervisor Exception Detail (Device Exception Detail)", EXPFILL }},
      { &ei_mal_ssupervisor_exception_detail_med, { "cipsafety.ssupervisor.malformed.exception_detail.med", PI_MALFORMED, PI_ERROR,
                        "Malformed Safety Supervisor Exception Detail (Manufacturer Exception Detail)", EXPFILL }},
      { &ei_mal_ssupervisor_configuration_unid, { "cipsafety.ssupervisor.malformed.configuration_unid", PI_MALFORMED, PI_ERROR,
                        "Malformed Safety Supervisor Configuration UNID", EXPFILL }},
      { &ei_mal_ssupervisor_safety_configuration_id, { "cipsafety.ssupervisor.malformed.safety_configuration_id", PI_MALFORMED, PI_ERROR,
                        "Malformed Safety Supervisor Safety Configuration Identifier", EXPFILL }},
      { &ei_mal_ssupervisor_target_unid, { "cipsafety.ssupervisor.malformed.target_unid", PI_MALFORMED, PI_ERROR,
                        "Malformed Safety Supervisor Target UNID", EXPFILL }},
      { &ei_mal_ssupervisor_cp_owners, { "cipsafety.ssupervisor.malformed.cp_owners", PI_MALFORMED, PI_ERROR,
                        "Malformed Safety Supervisor Output Connection Point Owners", EXPFILL }},
      { &ei_mal_ssupervisor_cp_owners_entry, { "cipsafety.ssupervisor.malformed.cp_owners.entry", PI_MALFORMED, PI_ERROR,
                        "Malformed Safety Supervisor Output Connection Point Owners (UNID)", EXPFILL }},
      { &ei_mal_ssupervisor_cp_owners_app_path_size, { "cipsafety.ssupervisor.malformed.cp_owners.app_path_size", PI_MALFORMED, PI_ERROR,
                        "Malformed Safety Supervisor Output Connection Point Owners (EPATH)", EXPFILL }},
      { &ei_mal_ssupervisor_proposed_tunid, { "cipsafety.ssupervisor.malformed.proposed_tunid", PI_MALFORMED, PI_ERROR,
                        "Malformed Safety Supervisor Proposed TUNID", EXPFILL }},
   };

   static ei_register_info ei_svalidator[] = {
      { &ei_mal_svalidator_type, { "cipsafety.ssupervisor.malformed.svalidator.type", PI_MALFORMED, PI_ERROR,
                        "Malformed Safety Validator Type", EXPFILL }},
      { &ei_mal_svalidator_time_coord_msg_min_mult, { "cipsafety.ssupervisor.malformed.svalidator.time_coord_msg_min_mult", PI_MALFORMED, PI_ERROR,
                        "Malformed Safety Validator Time Coord Msg Min Multiplier", EXPFILL }},
      { &ei_mal_svalidator_network_time_multiplier, { "cipsafety.ssupervisor.malformed.svalidator.network_time_multiplier", PI_MALFORMED, PI_ERROR,
                        "Malformed Safety Validator Network Time Expectation Multiplier", EXPFILL }},
      { &ei_mal_svalidator_timeout_multiplier, { "cipsafety.ssupervisor.malformed.svalidator.timeout_multiplier", PI_MALFORMED, PI_ERROR,
                        "Malformed Safety Validator Timeout Multiplier", EXPFILL }},
      { &ei_mal_svalidator_coordination_conn_inst, { "cipsafety.ssupervisor.malformed.svalidator.coordination_conn_inst", PI_MALFORMED, PI_ERROR,
                        "Malformed Safety Validator Coordination Connection Instance", EXPFILL }},
      { &ei_mal_svalidator_prod_cons_fault_count, { "cipsafety.ssupervisor.malformed.svalidator.prod_cons_fault_count", PI_MALFORMED, PI_ERROR,
                        "Malformed Safety Validator Produce/Consume Fault Counters", EXPFILL }},
   };

   expert_module_t* expert_cip_safety;
   expert_module_t* expert_cip_class_s_supervisor;
   expert_module_t* expert_cip_class_s_validator;

   /* Create a CIP Safety protocol handle */
   proto_cipsafety = proto_register_protocol("Common Industrial Protocol, Safety", "CIP Safety", "cipsafety");
   proto_register_field_array(proto_cipsafety, hf, array_length(hf));
   proto_register_subtree_array(ett, array_length(ett));
   expert_cip_safety = expert_register_protocol(proto_cipsafety);
   expert_register_field_array(expert_cip_safety, ei, array_length(ei));

   cipsafety_handle = register_dissector( "cipsafety", dissect_cipsafety, proto_cipsafety);

   /* Register CIP Safety objects */
   proto_cip_class_s_supervisor = proto_register_protocol("CIP Safety Supervisor",
       "CIPSSupervisor", "cipssupervisor");
   proto_register_field_array(proto_cip_class_s_supervisor, hf_ssupervisor, array_length(hf_ssupervisor));
   proto_register_subtree_array(ett_ssupervisor, array_length(ett_ssupervisor));
   expert_cip_class_s_supervisor = expert_register_protocol(proto_cip_class_s_supervisor);
   expert_register_field_array(expert_cip_class_s_supervisor, ei_ssupervisor, array_length(ei_ssupervisor));

   proto_cip_class_s_validator = proto_register_protocol("CIP Safety Validator",
       "CIPSValidator", "cipsvalidator");
   proto_register_field_array(proto_cip_class_s_validator, hf_svalidator, array_length(hf_svalidator));
   proto_register_subtree_array(ett_svalidator, array_length(ett_svalidator));
   expert_cip_class_s_validator = expert_register_protocol(proto_cip_class_s_validator);
   expert_register_field_array(expert_cip_class_s_validator, ei_svalidator, array_length(ei_svalidator));
}

/*
 * Function name: proto_reg_handoff_cipsafety
 *
 * Purpose: This function will setup the automatic dissection of the CIP Safety datagram,
 * it is called by Wireshark when the protocol is registered
 *
 * Returns: void
 */
void
proto_reg_handoff_cipsafety(void)
{
   dissector_handle_t cip_class_s_supervisor_handle;

   /* Create and register dissector handle for Safety Supervisor */
   cip_class_s_supervisor_handle = create_dissector_handle( dissect_cip_class_s_supervisor, proto_cip_class_s_supervisor );
   dissector_add_uint( "cip.class.iface", CI_CLS_SAFETY_SUPERVISOR, cip_class_s_supervisor_handle );

   /* Create and register dissector handle for Safety Validator */
   cip_class_s_validator_handle = create_dissector_handle( dissect_cip_class_s_validator, proto_cip_class_s_validator );
   dissector_add_uint( "cip.class.iface", CI_CLS_SAFETY_VALIDATOR, cip_class_s_validator_handle );
   heur_dissector_add("cip.sc", dissect_class_svalidator_heur, "CIP Safety Validator", "s_validator_cip", proto_cip_class_s_validator, HEURISTIC_ENABLE);

   /* Register dissector for I/O data handling */
   dissector_add_for_decode_as("enip.io", cipsafety_handle );

   proto_cip = proto_get_id_by_filter_name( "cip" );
   subdissector_class_table = find_dissector_table("cip.class.iface");
}


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