summaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-simulcrypt.c
blob: 67a43c2ba66b17571293f28795b42f077886d315 (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
/* packet-simulcrypt.c
 * Simulcrypt protocol interface as defined in ETSI TS 103.197 v 1.5.1
 *
 * ECMG <-> SCS support
 * David Castleford, Orange Labs / France Telecom R&D
 * Oct 2008
 *
 * EMMG <-> MUX support and generic interface support
 * Copyright 2009, Stig Bjorlykke <stig@bjorlykke.org>
 *
 * EIS <-> SCS support, (P)SIG <-> MUX support, MUX <-> CiM support and (P) <-> CiP support
 * Copyright 2010, Giuliano Fabris <giuliano.fabris@appeartv.com> / AppearTV
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include "config.h"

#include <epan/packet.h>
#include <epan/prefs.h>
#include <epan/tfs.h>
#include <epan/unit_strings.h>

#include <wsutil/array.h>
#include "packet-tcp.h"

#define PROTO_TAG_SIMULCRYPT            "SIMULCRYPT"
#define CA_SYSTEM_ID_MIKEY              0x9999  /* CA_system_ID corresponding to MIKEY ECM */
#define CA_SYSTEM_ID_MIKEY_PROTO        "mikey" /* Protocol name to be used to "decode as" ECMs with CA_SYSTEM_ID_MIKEY */

void proto_register_simulcrypt(void);

/* Tecm_interpretation links ca_system_id to ecmg port and protocol name for dissection of
 * ecm_datagram in ECM_Response message.
 * Currently size is 1 as only have MIKEY protocol but could add extra protocols
 * could add option in preferences for new ca_system_id for new protocol for example
 */
typedef struct Tecm_interpretation
{
	int ca_system_id;
	const char *protocol_name;
	dissector_handle_t protocol_handle;
	unsigned ecmg_port;
} ecm_interpretation;

#define ECM_MIKEY_INDEX 0  /* must agree with tab_ecm_inter initialization */

static ecm_interpretation tab_ecm_inter[] = {
	{CA_SYSTEM_ID_MIKEY, CA_SYSTEM_ID_MIKEY_PROTO, NULL, -1}
};

#define ECM_INTERPRETATION_SIZE array_length(tab_ecm_inter)

static int dissect_simulcrypt_message(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_);
static unsigned get_simulcrypt_message_len(packet_info *pinfo, tvbuff_t *tvb, int offset, void *data);
static void dissect_simulcrypt_data(proto_tree *simulcrypt_tree, proto_item *simulcrypt_item, packet_info *pinfo _U_,
				    tvbuff_t *tvb, proto_tree *tree, int offset,
				    int container_data_length, uint16_t iftype, bool is_subtree);

/* Wireshark ID of the SIMULCRYPT protocol */
static int proto_simulcrypt;

/* Dissector handle for SIMULCRYPT protocol */
static dissector_handle_t simulcrypt_handle;

/* Preferences (with default values) */
static int ca_system_id_mikey = CA_SYSTEM_ID_MIKEY; /* MIKEY ECM CA_system_ID */

/* MIKEY payload start bytes */
/*unsigned char mikey_start[3]={0x01,0x00,0x15};
* mikey_start[0]=0x01;	 first byte mikey payload (version)
* mikey_start[1]=0x00;	 second byte mikey payload (data type)
* mikey_start[2]=0x15;	 third byte (next payload)
*/

/* Dissector-internal values to determine interface, can be re-organized */
#define SIMULCRYPT_RESERVED     0
#define SIMULCRYPT_ECMG_SCS     1
#define SIMULCRYPT_EMMG_MUX     2
#define SIMULCRYPT_CPSIG_PSIG   3
#define SIMULCRYPT_EIS_SCS      4
#define SIMULCRYPT_PSIG_MUX     5
#define SIMULCRYPT_MUX_CIM      6
#define SIMULCRYPT_PSIG_CIP     7
#define SIMULCRYPT_USER_DEFINED 8

static const value_string interfacenames[] = {
	{ SIMULCRYPT_RESERVED,     "DVB reserved" },
	{ SIMULCRYPT_ECMG_SCS,     "ECMG <-> SCS" },
	{ SIMULCRYPT_EMMG_MUX,     "EMMG <-> MUX" },
	{ SIMULCRYPT_CPSIG_PSIG,   "C(P)SIG <-> (P)SIG" },
	{ SIMULCRYPT_EIS_SCS,      "EIS <-> SCS" },
	{ SIMULCRYPT_PSIG_MUX,     "(P)SIG <-> MUX" },
	{ SIMULCRYPT_MUX_CIM,      "Carousel in the MUX - CiM" },
	{ SIMULCRYPT_PSIG_CIP,     "Carousel in the (P) - CiP" },
	{ SIMULCRYPT_USER_DEFINED, "User defined" },
	{ 0, NULL }
};

/* Reserved 0x0000 */
#define SIMULCRYPT_ECMG_CHANNEL_SETUP                   0x0001
#define SIMULCRYPT_ECMG_CHANNEL_TEST                    0x0002
#define SIMULCRYPT_ECMG_CHANNEL_STATUS                  0x0003
#define SIMULCRYPT_ECMG_CHANNEL_CLOSE                   0x0004
#define SIMULCRYPT_ECMG_CHANNEL_ERROR                   0x0005
/* Reserved 0x0006 - 0x0010 */
#define SIMULCRYPT_EMMG_CHANNEL_SETUP                   0x0011
#define SIMULCRYPT_EMMG_CHANNEL_TEST                    0x0012
#define SIMULCRYPT_EMMG_CHANNEL_STATUS                  0x0013
#define SIMULCRYPT_EMMG_CHANNEL_CLOSE                   0x0014
#define SIMULCRYPT_EMMG_CHANNEL_ERROR                   0x0015
/* Reserved 0x0016 - 0x0100 */
#define SIMULCRYPT_ECMG_STREAM_SETUP                    0x0101
#define SIMULCRYPT_ECMG_STREAM_TEST                     0x0102
#define SIMULCRYPT_ECMG_STREAM_STATUS                   0x0103
#define SIMULCRYPT_ECMG_STREAM_CLOSE_REQUEST            0x0104
#define SIMULCRYPT_ECMG_STREAM_CLOSE_RESPONSE           0x0105
#define SIMULCRYPT_ECMG_STREAM_ERROR                    0x0106
/* Reserved 0x0107 - 0x0110 */
#define SIMULCRYPT_EMMG_STREAM_SETUP                    0x0111
#define SIMULCRYPT_EMMG_STREAM_TEST                     0x0112
#define SIMULCRYPT_EMMG_STREAM_STATUS                   0x0113
#define SIMULCRYPT_EMMG_STREAM_CLOSE_REQUEST            0x0114
#define SIMULCRYPT_EMMG_STREAM_CLOSE_RESPONSE           0x0115
#define SIMULCRYPT_EMMG_STREAM_ERROR                    0x0116
#define SIMULCRYPT_EMMG_STREAM_BW_REQUEST               0x0117
#define SIMULCRYPT_EMMG_STREAM_BW_ALLOCATION            0x0118
/* Reserved 0x0119 - 0x0200 */
#define SIMULCRYPT_ECMG_CW_PROVISION                    0x0201
#define SIMULCRYPT_ECMG_ECM_RESPONSE                    0x0202
/* Reserved 0x0203 - 0x0210 */
#define SIMULCRYPT_EMMG_DATA_PROVISION                  0x0211
/* Reserved 0x0212 - 0x0300 */

/* Reserved 0x0322 - 0x0400 */
#define SIMULCRYPT_EIS_CHANNEL_SET_UP                   0x0401
#define SIMULCRYPT_EIS_CHANNEL_TEST                     0x0402
#define SIMULCRYPT_EIS_CHANNEL_STATUS                   0x0403
#define SIMULCRYPT_EIS_CHANNEL_CLOSE                    0x0404
#define SIMULCRYPT_EIS_CHANNEL_ERROR                    0x0405
#define SIMULCRYPT_EIS_CHANNEL_RESET                    0x0406

#define SIMULCRYPT_EIS_SCG_PROVISION                    0x0408
#define SIMULCRYPT_EIS_SCG_TEST                         0x0409
#define SIMULCRYPT_EIS_SCG_STATUS                       0x040A
#define SIMULCRYPT_EIS_SCG_ERROR                        0x040B
#define SIMULCRYPT_EIS_SCG_LIST_REQUEST                 0x040C
#define SIMULCRYPT_EIS_SCG_LIST_RESPONSE                0x040D

#define SIMULCRYPT_PSIG_CHANNEL_SETUP                   0x0411
#define SIMULCRYPT_PSIG_CHANNEL_TEST                    0x0412
#define SIMULCRYPT_PSIG_CHANNEL_STATUS                  0x0413
#define SIMULCRYPT_PSIG_CHANNEL_CLOSE                   0x0414
#define SIMULCRYPT_PSIG_CHANNEL_ERROR                   0x0415

#define SIMULCRYPT_PSIG_STREAM_SETUP                    0x0421
#define SIMULCRYPT_PSIG_STREAM_TEST                     0x0422
#define SIMULCRYPT_PSIG_STREAM_STATUS                   0x0423
#define SIMULCRYPT_PSIG_STREAM_CLOSE_REQUEST            0x0424
#define SIMULCRYPT_PSIG_STREAM_CLOSE_RESPONSE           0x0425
#define SIMULCRYPT_PSIG_STREAM_ERROR                    0x0426

#define SIMULCRYPT_PSIG_CIM_STREAM_SECTION_PROVISION    0x0431
#define SIMULCRYPT_PSIG_CIM_CHANNEL_RESET               0x0432

#define SIMULCRYPT_PSIG_CIM_STREAM_BW_REQUEST           0x0441
#define SIMULCRYPT_PSIG_CIM_STREAM_BW_ALLOCATION        0x0442
#define SIMULCRYPT_PSIG_CIM_STREAM_DATA_PROVISION       0x0443

/* User defined 0x8000 - 0xFFFF */

static const value_string messagetypenames[] = {
	{ SIMULCRYPT_ECMG_CHANNEL_SETUP,                  "CHANNEL_SETUP" },
	{ SIMULCRYPT_ECMG_CHANNEL_TEST,                   "CHANNEL_TEST" },
	{ SIMULCRYPT_ECMG_CHANNEL_STATUS,                 "CHANNEL_STATUS" },
	{ SIMULCRYPT_ECMG_CHANNEL_CLOSE,                  "CHANNEL_CLOSE" },
	{ SIMULCRYPT_ECMG_CHANNEL_ERROR,                  "CHANNEL_ERROR" },

	{ SIMULCRYPT_EMMG_CHANNEL_SETUP,                  "CHANNEL_SETUP" },
	{ SIMULCRYPT_EMMG_CHANNEL_TEST,                   "CHANNEL_TEST" },
	{ SIMULCRYPT_EMMG_CHANNEL_STATUS,                 "CHANNEL_STATUS" },
	{ SIMULCRYPT_EMMG_CHANNEL_CLOSE,                  "CHANNEL_CLOSE" },
	{ SIMULCRYPT_EMMG_CHANNEL_ERROR,                  "CHANNEL_ERROR" },

	{ SIMULCRYPT_ECMG_STREAM_SETUP,                   "STREAM_SETUP" },
	{ SIMULCRYPT_ECMG_STREAM_TEST,                    "STREAM_TEST" },
	{ SIMULCRYPT_ECMG_STREAM_STATUS,                  "STREAM_STATUS" },
	{ SIMULCRYPT_ECMG_STREAM_CLOSE_REQUEST,           "STREAM_CLOSE_REQUEST" },
	{ SIMULCRYPT_ECMG_STREAM_CLOSE_RESPONSE,          "STREAM_CLOSE_RESPONSE" },
	{ SIMULCRYPT_ECMG_STREAM_ERROR,                   "STREAM_ERROR" },

	{ SIMULCRYPT_EMMG_STREAM_SETUP,                   "STREAM_SETUP" },
	{ SIMULCRYPT_EMMG_STREAM_TEST,                    "STREAM_TEST" },
	{ SIMULCRYPT_EMMG_STREAM_STATUS,                  "STREAM_STATUS" },
	{ SIMULCRYPT_EMMG_STREAM_CLOSE_REQUEST,           "STREAM_CLOSE_REQUEST" },
	{ SIMULCRYPT_EMMG_STREAM_CLOSE_RESPONSE,          "STREAM_CLOSE_RESPONSE" },
	{ SIMULCRYPT_EMMG_STREAM_ERROR,                   "STREAM_ERROR" },
	{ SIMULCRYPT_EMMG_STREAM_BW_REQUEST,              "STREAM_BW_REQUEST" },
	{ SIMULCRYPT_EMMG_STREAM_BW_ALLOCATION,           "STREAM_BW_ALLOCATION" },

	{ SIMULCRYPT_ECMG_CW_PROVISION,                   "CW_PROVISION" },
	{ SIMULCRYPT_ECMG_ECM_RESPONSE,                   "ECM_RESPONSE" },

	{ SIMULCRYPT_EMMG_DATA_PROVISION,                 "DATA_PROVISION" },

	{ SIMULCRYPT_EIS_CHANNEL_SET_UP,                  "CHANNEL_SET_UP" },
	{ SIMULCRYPT_EIS_CHANNEL_TEST,                    "CHANNEL_TEST" },
	{ SIMULCRYPT_EIS_CHANNEL_STATUS,                  "CHANNEL_STATUS" },
	{ SIMULCRYPT_EIS_CHANNEL_CLOSE,                   "CHANNEL_CLOSE" },
	{ SIMULCRYPT_EIS_CHANNEL_ERROR,                   "CHANNEL_ERROR" },
	{ SIMULCRYPT_EIS_CHANNEL_RESET,                   "CHANNEL_RESET" },

	{ SIMULCRYPT_EIS_SCG_PROVISION,                   "SCG_PROVISION" },
	{ SIMULCRYPT_EIS_SCG_TEST,                        "SCG_TEST" },
	{ SIMULCRYPT_EIS_SCG_STATUS,                      "SCG_STATUS" },
	{ SIMULCRYPT_EIS_SCG_ERROR,                       "SCG_ERROR" },
	{ SIMULCRYPT_EIS_SCG_LIST_REQUEST,                "SCG_LIST_REQUEST" },
	{ SIMULCRYPT_EIS_SCG_LIST_RESPONSE,               "SCG_LIST_RESPONSE" },


	{ SIMULCRYPT_PSIG_CHANNEL_SETUP,                  "CHANNEL_SETUP" },
	{ SIMULCRYPT_PSIG_CHANNEL_TEST,                   "CHANNEL_TEST" },
	{ SIMULCRYPT_PSIG_CHANNEL_STATUS,                 "CHANNEL_STATUS" },
	{ SIMULCRYPT_PSIG_CHANNEL_CLOSE,                  "CHANNEL_CLOSE" },
	{ SIMULCRYPT_PSIG_CHANNEL_ERROR,                  "CHANNEL_ERROR" },

	{ SIMULCRYPT_PSIG_STREAM_SETUP,                   "STREAM_SETUP" },
	{ SIMULCRYPT_PSIG_STREAM_TEST,                    "STREAM_TEST" },
	{ SIMULCRYPT_PSIG_STREAM_STATUS,                  "STREAM_STATUS" },
	{ SIMULCRYPT_PSIG_STREAM_CLOSE_REQUEST,           "STREAM_CLOSE_REQUEST" },
	{ SIMULCRYPT_PSIG_STREAM_CLOSE_RESPONSE,          "STREAM_CLOSE_RESPONSE" },
	{ SIMULCRYPT_PSIG_STREAM_ERROR,                   "STREAM_ERROR" },

	{ SIMULCRYPT_PSIG_CIM_STREAM_SECTION_PROVISION,   "CIM_STREAM_SECTION_PROVISION"},
	{ SIMULCRYPT_PSIG_CIM_CHANNEL_RESET,              "CIM_CHANNEL_RESET"},

	/* XXX: Following added (since they seem to have been missing) */
	{ SIMULCRYPT_PSIG_CIM_STREAM_BW_REQUEST,          "CIM_STREAM_BW_REQUEST"},
	{ SIMULCRYPT_PSIG_CIM_STREAM_BW_ALLOCATION,       "CIM_STREAM_BW_ALLOCATION"},
	{ SIMULCRYPT_PSIG_CIM_STREAM_DATA_PROVISION,      "CIM_STREAM_DATA_PROVISION"},

	{ 0, NULL }
};
static value_string_ext messagetypenames_ext = VALUE_STRING_EXT_INIT(messagetypenames);

/* Simulcrypt ECMG Parameter Types */
#define SIMULCRYPT_ECMG_DVB_RESERVED                    0x0000
#define SIMULCRYPT_ECMG_SUPER_CAS_ID                    0x0001
#define SIMULCRYPT_ECMG_SECTION_TSPKT_FLAG              0x0002
#define SIMULCRYPT_ECMG_DELAY_START                     0x0003
#define SIMULCRYPT_ECMG_DELAY_STOP                      0x0004
#define SIMULCRYPT_ECMG_TRANSITION_DELAY_START          0x0005
#define SIMULCRYPT_ECMG_TRANSITION_DELAY_STOP           0x0006
#define SIMULCRYPT_ECMG_ECM_REP_PERIOD                  0x0007
#define SIMULCRYPT_ECMG_MAX_STREAMS                     0x0008
#define SIMULCRYPT_ECMG_MIN_CP_DURATION                 0x0009
#define SIMULCRYPT_ECMG_LEAD_CW                         0x000A
#define SIMULCRYPT_ECMG_CW_PER_MESSAGE                  0x000B
#define SIMULCRYPT_ECMG_MAX_COMP_TIME                   0x000C
#define SIMULCRYPT_ECMG_ACCESS_CRITERIA                 0x000D
#define SIMULCRYPT_ECMG_ECM_CHANNEL_ID                  0x000E
#define SIMULCRYPT_ECMG_ECM_STREAM_ID                   0x000F
#define SIMULCRYPT_ECMG_NOMINAL_CP_DURATION             0x0010
#define SIMULCRYPT_ECMG_ACCESS_CRITERIA_TRANSFER_MODE   0x0011
#define SIMULCRYPT_ECMG_CP_NUMBER                       0x0012
#define SIMULCRYPT_ECMG_CP_DURATION                     0x0013
#define SIMULCRYPT_ECMG_CP_CW_COMBINATION               0x0014
#define SIMULCRYPT_ECMG_ECM_DATAGRAM                    0x0015
#define SIMULCRYPT_ECMG_AC_DELAY_START                  0x0016
#define SIMULCRYPT_ECMG_AC_DELAY_STOP                   0x0017
#define SIMULCRYPT_ECMG_CW_ENCRYPTION                   0x0018
#define SIMULCRYPT_ECMG_ECM_ID                          0x0019
#define SIMULCRYPT_ECMG_ERROR_STATUS                    0x7000
#define SIMULCRYPT_ECMG_ERROR_INFORMATION               0x7001

static const value_string ecmg_parametertypenames[] = {
	{ SIMULCRYPT_ECMG_DVB_RESERVED,                  "DVB_RESERVED" },
	{ SIMULCRYPT_ECMG_SUPER_CAS_ID,                  "SUPER_CAS_ID" },
	{ SIMULCRYPT_ECMG_SECTION_TSPKT_FLAG,            "SECTION_TSPKT_FLAG" },
	{ SIMULCRYPT_ECMG_DELAY_START,                   "DELAY_START" },
	{ SIMULCRYPT_ECMG_DELAY_STOP,                    "DELAY_STOP" },
	{ SIMULCRYPT_ECMG_TRANSITION_DELAY_START,        "TRANSITION_DELAY_START" },
	{ SIMULCRYPT_ECMG_TRANSITION_DELAY_STOP,         "TRANSITION_DELAY_STOP" },
	{ SIMULCRYPT_ECMG_ECM_REP_PERIOD,                "ECM_REP_PERIOD" },
	{ SIMULCRYPT_ECMG_MAX_STREAMS,                   "MAX_STREAMS" },
	{ SIMULCRYPT_ECMG_MIN_CP_DURATION,               "MIN_CP_DURATION" },
	{ SIMULCRYPT_ECMG_LEAD_CW,                       "LEAD_CW" },
	{ SIMULCRYPT_ECMG_CW_PER_MESSAGE,                "CW_PER_MESSAGE" },
	{ SIMULCRYPT_ECMG_MAX_COMP_TIME,                 "MAX_COMP_TIME" },
	{ SIMULCRYPT_ECMG_ACCESS_CRITERIA,               "ACCESS_CRITERIA" },
	{ SIMULCRYPT_ECMG_ECM_CHANNEL_ID,                "ECM_CHANNEL_ID" },
	{ SIMULCRYPT_ECMG_ECM_STREAM_ID,                 "ECM_STREAM_ID" },
	{ SIMULCRYPT_ECMG_NOMINAL_CP_DURATION,           "NOMINAL_CP_DURATION" },
	{ SIMULCRYPT_ECMG_ACCESS_CRITERIA_TRANSFER_MODE, "ACCESS_CRITERIA_TRANSFER_MODE" },
	{ SIMULCRYPT_ECMG_CP_NUMBER,                     "CP_NUMBER" },
	{ SIMULCRYPT_ECMG_CP_DURATION,                   "CP_DURATION" },
	{ SIMULCRYPT_ECMG_CP_CW_COMBINATION,             "CP_CW_COMBINATION" },
	{ SIMULCRYPT_ECMG_ECM_DATAGRAM,                  "ECM_DATAGRAM" },
	{ SIMULCRYPT_ECMG_AC_DELAY_START,                "AC_DELAY_START" },
	{ SIMULCRYPT_ECMG_AC_DELAY_STOP,                 "AC_DELAY_STOP" },
	{ SIMULCRYPT_ECMG_CW_ENCRYPTION,                 "CW_ENCRYPTION" },
	{ SIMULCRYPT_ECMG_ECM_ID,                        "ECM_ID" },
	{ SIMULCRYPT_ECMG_ERROR_STATUS,                  "ERROR_STATUS" },
	{ SIMULCRYPT_ECMG_ERROR_INFORMATION,             "ERROR_INFORMATION" },
	{ 0, NULL }
};
static value_string_ext ecmg_parametertypenames_ext = VALUE_STRING_EXT_INIT(ecmg_parametertypenames);

/* Simulcrypt ECMG protocol error values */
static const value_string ecmg_error_values[] = {
	{ 0x0000, "DVB Reserved" },
	{ 0x0001, "Invalid message" },
	{ 0x0002, "Unsupported protocol version" },
	{ 0x0003, "Unknown message type value" },
	{ 0x0004, "Message too long" },
	{ 0x0005, "Unknown super CAS ID value" },
	{ 0x0006, "Unknown ECM channel ID value" },
	{ 0x0007, "Unknown ECM stream ID value" },
	{ 0x0008, "Too many channels on this ECMG" },
	{ 0x0009, "Too many ECM streams on this channel" },
	{ 0x000A, "Too many ECM streams on this ECMG" },
	{ 0x000B, "Not enough control words to compute ECM" },
	{ 0x000C, "ECMG out of storage capacity" },
	{ 0x000D, "ECMG out of computational resources" },
	{ 0x000E, "Unknown parameter type value" },
	{ 0x000F, "Inconsistent length for DVB parameter" },
	{ 0x0010, "Missing mandatory DVB parameter" },
	{ 0x0011, "Invalid value for DVB parameter" },
	{ 0x0012, "Unknown ECM ID value" },
	{ 0x0013, "ECM channel ID value already in use" },
	{ 0x0014, "ECM stream ID value already in use" },
	{ 0x0015, "ECM ID value already in use" },
	{ 0x7000, "Unknown error" },
	{ 0x7001, "Unrecoverable error" },
	{ 0, NULL }
};
static value_string_ext ecmg_error_values_ext = VALUE_STRING_EXT_INIT(ecmg_error_values);

/* Simulcrypt EMMG Parameter Types */
#define SIMULCRYPT_EMMG_DVB_RESERVED                    0x0000
#define SIMULCRYPT_EMMG_CLIENT_ID                       0x0001
#define SIMULCRYPT_EMMG_SECTION_TSPKT_FLAG              0x0002
#define SIMULCRYPT_EMMG_DATA_CHANNEL_ID                 0x0003
#define SIMULCRYPT_EMMG_DATA_STREAM_ID                  0x0004
#define SIMULCRYPT_EMMG_DATAGRAM                        0x0005
#define SIMULCRYPT_EMMG_BANDWIDTH                       0x0006
#define SIMULCRYPT_EMMG_DATA_TYPE                       0x0007
#define SIMULCRYPT_EMMG_DATA_ID                         0x0008
#define SIMULCRYPT_EMMG_ERROR_STATUS                    0x7000
#define SIMULCRYPT_EMMG_ERROR_INFORMATION               0x7001

static const value_string emmg_parametertypenames[] = {
	{ SIMULCRYPT_EMMG_DVB_RESERVED,       "DVB_RESERVED" },
	{ SIMULCRYPT_EMMG_CLIENT_ID,          "CLIENT_ID" },
	{ SIMULCRYPT_EMMG_SECTION_TSPKT_FLAG, "SECTION_TSPKT_FLAG" },
	{ SIMULCRYPT_EMMG_DATA_CHANNEL_ID,    "DATA_CHANNEL_ID" },
	{ SIMULCRYPT_EMMG_DATA_STREAM_ID,     "DATA_STREAM_ID" },
	{ SIMULCRYPT_EMMG_DATAGRAM,           "DATAGRAM" },
	{ SIMULCRYPT_EMMG_BANDWIDTH,          "BANDWIDTH" },
	{ SIMULCRYPT_EMMG_DATA_TYPE,          "DATA_TYPE" },
	{ SIMULCRYPT_EMMG_DATA_ID,            "DATA_ID" },
	{ SIMULCRYPT_EMMG_ERROR_STATUS,       "ERROR_STATUS" },
	{ SIMULCRYPT_EMMG_ERROR_INFORMATION,  "ERROR_INFORMATION" },
	{ 0, NULL }
};
static value_string_ext emmg_parametertypenames_ext = VALUE_STRING_EXT_INIT(emmg_parametertypenames);

/* Simulcrypt EMMG protocol error values */
static const value_string emmg_error_values[] = {
	{ 0x0000, "DVB Reserved" },
	{ 0x0001, "Invalid message" },
	{ 0x0002, "Unsupported protocol version" },
	{ 0x0003, "Unknown message type value" },
	{ 0x0004, "Message too long" },
	{ 0x0005, "Unknown data stream ID value" },
	{ 0x0006, "Unknown data channel ID value" },
	{ 0x0007, "Too many channels on this MUX" },
	{ 0x0008, "Too many data streams on this channel" },
	{ 0x0009, "Too many data streams on this MUX" },
	{ 0x000A, "Unknown parameter type" },
	{ 0x000B, "Inconsistent length for DVB parameter" },
	{ 0x000C, "Missing mandatory DVB parameter" },
	{ 0x000D, "Invalid value for DVB parameter" },
	{ 0x000E, "Unknown client ID value" },
	{ 0x000F, "Exceeded bandwidth" },
	{ 0x0010, "Unknown data ID value" },
	{ 0x0011, "Data channel ID value already in use" },
	{ 0x0012, "Data stream ID value already in use" },
	{ 0x0013, "Data ID value already in use" },
	{ 0x0014, "Client ID value already in use" },
	{ 0x7000, "Unknown error" },
	{ 0x7001, "Unrecoverable error" },
	{ 0, NULL }
};
static value_string_ext emmg_error_values_ext = VALUE_STRING_EXT_INIT(emmg_error_values);

/* Simulcrypt EIS Parameter Types */
#define SIMULCRYPT_EIS_DVB_RESERVED                     0x0000
#define SIMULCRYPT_EIS_CHANNEL_ID                       0x0001
#define SIMULCRYPT_EIS_SERVICE_FLAG                     0x0002
#define SIMULCRYPT_EIS_COMPONENT_FLAG                   0x0003
#define SIMULCRYPT_EIS_MAX_SCG                          0x0004
#define SIMULCRYPT_EIS_ECM_GROUP                        0x0005
#define SIMULCRYPT_EIS_SCG_ID                           0x0006
#define SIMULCRYPT_EIS_SCG_REFERENCE_ID                 0x0007
#define SIMULCRYPT_EIS_SUPER_CAS_ID                     0x0008
#define SIMULCRYPT_EIS_ECM_ID                           0x0009
#define SIMULCRYPT_EIS_ACCESS_CRITERIA                  0x000A
#define SIMULCRYPT_EIS_ACTIVATION_TIME                  0x000B
#define SIMULCRYPT_EIS_ACTIVATION_PENDING_FLAG          0x000C
#define SIMULCRYPT_EIS_COMPONENT_ID                     0x000D
#define SIMULCRYPT_EIS_SERVICE_ID                       0x000E
#define SIMULCRYPT_EIS_TRANSPORT_STREAM_ID              0x000F
#define SIMULCRYPT_EIS_AC_CHANGED_FLAG                  0x0010
#define SIMULCRYPT_EIS_SCG_CURRENT_REFERENCE_ID         0x0011
#define SIMULCRYPT_EIS_SCG_PENDING_REFERENCE_ID         0x0012
#define SIMULCRYPT_EIS_CP_DURATION_FLAG                 0x0013
#define SIMULCRYPT_EIS_RECOMMENDED_CP_DURATION          0x0014
#define SIMULCRYPT_EIS_SCG_NOMINAL_CP_DURATION          0x0015
#define SIMULCRYPT_EIS_ORIGINAL_NETWORK_ID              0x0016

#define SIMULCRYPT_EIS_ERROR_STATUS                     0x7000
#define SIMULCRYPT_EIS_ERROR_INFORMATION                0x7001
#define SIMULCRYPT_EIS_ERROR_DESCRIPTION                0x7002

static const value_string eis_parametertypenames[] = {
	{ SIMULCRYPT_EIS_DVB_RESERVED,                  "DVB_RESERVED" },
	{ SIMULCRYPT_EIS_CHANNEL_ID,                    "EIS_CHANNEL_ID" },
	{ SIMULCRYPT_EIS_SERVICE_FLAG,                  "SERVICE_FLAG" },
	{ SIMULCRYPT_EIS_COMPONENT_FLAG,                "COMPONENT_FLAG" },
	{ SIMULCRYPT_EIS_MAX_SCG,                       "MAX_SCG" },
	{ SIMULCRYPT_EIS_ECM_GROUP,                     "ECM_GROUP" },
	{ SIMULCRYPT_EIS_SCG_ID,                        "SCG_ID" },
	{ SIMULCRYPT_EIS_SCG_REFERENCE_ID,              "SCG_REFERENCE_ID" },
	{ SIMULCRYPT_EIS_SUPER_CAS_ID,                  "SUPER_CAS_ID" },
	{ SIMULCRYPT_EIS_ECM_ID,                        "ECM_ID" },
	{ SIMULCRYPT_EIS_ACCESS_CRITERIA,               "ACCESS_CRITERIA" },
	{ SIMULCRYPT_EIS_ACTIVATION_TIME,               "ACTIVATION_TIME" },
	{ SIMULCRYPT_EIS_ACTIVATION_PENDING_FLAG,       "ACTIVATION_PENDING_FLAG" },
	{ SIMULCRYPT_EIS_COMPONENT_ID,                  "COMPONENT_ID" },
	{ SIMULCRYPT_EIS_SERVICE_ID,                    "SERVICE_ID" },
	{ SIMULCRYPT_EIS_TRANSPORT_STREAM_ID,           "TRANSPORT_STREAM_ID" },
	{ SIMULCRYPT_EIS_AC_CHANGED_FLAG,               "AC_CHANGED_FLAG" },
	{ SIMULCRYPT_EIS_SCG_CURRENT_REFERENCE_ID,      "SCG_CURRENT_REFERENCE_ID" },
	{ SIMULCRYPT_EIS_SCG_PENDING_REFERENCE_ID,      "SCG_PENDING_REFERENCE_ID" },
	{ SIMULCRYPT_EIS_CP_DURATION_FLAG,              "CP_DURATION_FLAG" },
	{ SIMULCRYPT_EIS_RECOMMENDED_CP_DURATION,       "RECOMMENDED_CP_DURATION" },
	{ SIMULCRYPT_EIS_SCG_NOMINAL_CP_DURATION,       "SCG_NOMINAL_CP_DURATION" },
	{ SIMULCRYPT_EIS_ORIGINAL_NETWORK_ID,           "ORIGINAL_NETWORK_ID" },

	{ SIMULCRYPT_EIS_ERROR_STATUS,                  "ERROR_STATUS" },
	{ SIMULCRYPT_EIS_ERROR_INFORMATION,             "ERROR_INFORMATION" },
	{ SIMULCRYPT_EIS_ERROR_DESCRIPTION,             "ERROR_DESCRIPTION" },

	{ 0, NULL }
};
static value_string_ext eis_parametertypenames_ext = VALUE_STRING_EXT_INIT(eis_parametertypenames);

/* Simulcrypt EIS protocol error values */
static const value_string eis_error_values[] = {
	{ 0x0000, "DVB Reserved" },
	{ 0x0001, "Invalid message" },
	{ 0x0002, "Unsupported protocol version" },
	{ 0x0003, "Unknown message_type value" },
	{ 0x0004, "Message too long" },
	{ 0x0005, "Inconsistent length for parameter" },
	{ 0x0006, "Missing mandatory parameter" },
	{ 0x0007, "Invalid value for parameter" },
	{ 0x0008, "Unknown EIS_channel_ID value" },
	{ 0x0009, "Unknown SCG_ID value" },
	{ 0x000A, "Max SCGs already defined" },
	{ 0x000B, "Service level SCG definitions not supportend" },
	{ 0x000C, "Elementary Stream level SCG definitions not supported" },
	{ 0x000D, "Activation_time possibly too soon for SCS to be accurate" },
	{ 0x000E, "SCG definition cannot span transport boundaries" },
	{ 0x000F, "A resource does not exist on this SCG" },
	{ 0x0010, "A resource is already defined in an existing SCG" },
	{ 0x0011, "SCG may not contain one or more content entries and no ECM_Group entries" },
	{ 0x0012, "SCG may not contain one or more ECM_Group entries and no content entries" },
	{ 0x0013, "EIS_channel_ID value already in use" },
	{ 0x0014, "Unknown Super_CAS_Id" },

	{ 0x7000, "Unknown error" },
	{ 0x7001, "Unrecoverable error" },

	{ 0, NULL }
};
static value_string_ext eis_error_values_ext = VALUE_STRING_EXT_INIT(eis_error_values);

/* Simulcrypt PSIG Parameter Types */
#define SIMULCRYPT_PSIG_DVB_RESERVED                    0x0000
#define SIMULCRYPT_PSIG_PSIG_TYPE                       0x0001
#define SIMULCRYPT_PSIG_CHANNEL_ID                      0x0002
#define SIMULCRYPT_PSIG_STREAM_ID                       0x0003
#define SIMULCRYPT_PSIG_TRANSPORT_STREAM_ID             0x0004
#define SIMULCRYPT_PSIG_ORIGINAL_NETWORK_ID             0x0005
#define SIMULCRYPT_PSIG_PACKET_ID                       0x0006
#define SIMULCRYPT_PSIG_INTERFACE_MODE_CONFIGURATION    0x0007
#define SIMULCRYPT_PSIG_MAX_STREAM                      0x0008
#define SIMULCRYPT_PSIG_TABLE_PERIOD_PAIR               0x0009
#define SIMULCRYPT_PSIG_MPEG_SECTION                    0x000A
#define SIMULCRYPT_PSIG_REPETITION_RATE                 0x000B
#define SIMULCRYPT_PSIG_ACTIVATION_TIME                 0x000C
#define SIMULCRYPT_PSIG_DATAGRAM                        0x000D
#define SIMULCRYPT_PSIG_BANDWIDTH                       0x000E
#define SIMULCRYPT_PSIG_INITIAL_BANDWIDTH               0x000F
#define SIMULCRYPT_PSIG_MAX_COMP_TIME                   0x0010
#define SIMULCRYPT_PSIG_ASI_INPUT_PACKET_ID             0x0011

#define SIMULCRYPT_PSIG_ERROR_STATUS                    0x7000
#define SIMULCRYPT_PSIG_ERROR_INFORMATION               0x7001

static const value_string psig_parametertypenames[] = {
	{ SIMULCRYPT_PSIG_DVB_RESERVED,                  "DVB_RESERVED" },
	{ SIMULCRYPT_PSIG_PSIG_TYPE,                     "PSIG_TYPE" },
	{ SIMULCRYPT_PSIG_CHANNEL_ID,                    "PSIG_CHANNEL_ID" },
	{ SIMULCRYPT_PSIG_STREAM_ID,                     "STREAM_ID" },
	{ SIMULCRYPT_PSIG_TRANSPORT_STREAM_ID,           "TRANSPORT_STREAM_ID" },
	{ SIMULCRYPT_PSIG_ORIGINAL_NETWORK_ID,           "ORIGINAL_NETWORK_ID" },
	{ SIMULCRYPT_PSIG_PACKET_ID,                     "PACKET_ID" },
	{ SIMULCRYPT_PSIG_INTERFACE_MODE_CONFIGURATION,  "INTERFACE_MODE_CONFIGURATION" },
	{ SIMULCRYPT_PSIG_MAX_STREAM,                    "MAX_STREAM" },
	{ SIMULCRYPT_PSIG_TABLE_PERIOD_PAIR,             "TABLE_PERIOD_PAIR" },
	{ SIMULCRYPT_PSIG_MPEG_SECTION,                  "MPEG_SECTION" },
	{ SIMULCRYPT_PSIG_REPETITION_RATE,               "REPETITION_RATE" },
	{ SIMULCRYPT_PSIG_ACTIVATION_TIME,               "ACTIVATION_TIME" },
	{ SIMULCRYPT_PSIG_DATAGRAM,                      "DATAGRAM" },
	{ SIMULCRYPT_PSIG_BANDWIDTH,                     "BANDWIDTH" },
	{ SIMULCRYPT_PSIG_INITIAL_BANDWIDTH,             "INITIAL_BANDWIDTH" },
	{ SIMULCRYPT_PSIG_MAX_COMP_TIME,                 "MAX_COMP_TIME" },
	{ SIMULCRYPT_PSIG_ASI_INPUT_PACKET_ID,           "ASI_INPUT_PACKET_ID" },

	{ SIMULCRYPT_PSIG_ERROR_STATUS,                  "ERROR_STATUS" },
	{ SIMULCRYPT_PSIG_ERROR_INFORMATION,             "ERROR_INFORMATION" },

	{ 0, NULL }
};
static value_string_ext psig_parametertypenames_ext = VALUE_STRING_EXT_INIT(psig_parametertypenames);

#if 0
/* Simulcrypt PSIG protocol error values */
static const value_string psig_error_values[] = {
	{ 0x0000, "DVB Reserved" },
	{ 0x0001, "Invalid message" },
	{ 0x0002, "Unsupported protocol version" },
	{ 0x0003, "Unknown message_type value" },
	{ 0x0004, "Message too long" },
	{ 0x0005, "Unknown stream_ID value" },
	{ 0x0006, "Unknown channel_ID value" },
	{ 0x0007, "Too many channels on this MUX" },
	{ 0x0008, "Too many data streams on this channel" },
	{ 0x0009, "Too many data streams on this MUX" },
	{ 0x000A, "Unknown parameter_type" },
	{ 0x000B, "Inconsistent length for parameter" },
	{ 0x000C, "Missing mandatory parameter" },
	{ 0x000D, "Invalid value for parameter" },
	{ 0x000E, "Inconsistent value of transport_stream_ID" },
	{ 0x000F, "Inconsistent value of packet_ID" },
	{ 0x0010, "channel_ID value already in use" },
	{ 0x0011, "stream_ID value already in use" },
	{ 0x0012, "Stream already open for this pair (transport_stream_ID, packet_ID)" },
	{ 0x0013, "Overflow error when receiving the list of MPEG (CiM error type)" },
	{ 0x0014, "Inconsistent format of TOT template (CiM error type)" },
	{ 0x0015, "Warning: Difficulties in respecting the requested repetition_rates for the last 5 minutes (CiM error type)" },
	{ 0x0016, "Warning: Difficulties in respecting the requested Bandwidth for the last 5 minutes (CiM error type)" },

	{ 0x7000, "Unknown error" },
	{ 0x7001, "Unrecoverable error" },

	{ 0, NULL }
};
static value_string_ext psig_error_values_ext = VALUE_STRING_EXT_INIT(psig_error_values);
#endif

/* The following hf_* variables are used to hold the Wireshark IDs of
* our header fields; they are filled out when we call
* proto_register_field_array() in proto_register_simulcrypt()
*/
static int hf_simulcrypt_header;
static int hf_simulcrypt_version;
static int hf_simulcrypt_message_type;
static int hf_simulcrypt_interface;
static int hf_simulcrypt_message_length;
static int hf_simulcrypt_message;
static int hf_simulcrypt_parameter;
static int hf_simulcrypt_parameter_type;
static int hf_simulcrypt_ecmg_parameter_type;
static int hf_simulcrypt_emmg_parameter_type;
static int hf_simulcrypt_parameter_length;
static int hf_simulcrypt_ca_system_id;
static int hf_simulcrypt_ca_subsystem_id;
static int hf_simulcrypt_super_cas_id;
static int hf_simulcrypt_section_tspkt_flag;
static int hf_simulcrypt_ecm_channel_id;
static int hf_simulcrypt_delay_start;
static int hf_simulcrypt_delay_stop;
static int hf_simulcrypt_ac_delay_start;
static int hf_simulcrypt_ac_delay_stop;
static int hf_simulcrypt_transition_delay_start;
static int hf_simulcrypt_transition_delay_stop;
static int hf_simulcrypt_ecm_rep_period;
static int hf_simulcrypt_max_streams;
static int hf_simulcrypt_min_cp_duration;
static int hf_simulcrypt_lead_cw;
static int hf_simulcrypt_cw_per_msg;
static int hf_simulcrypt_max_comp_time;
static int hf_simulcrypt_access_criteria;
static int hf_simulcrypt_ecm_stream_id;
static int hf_simulcrypt_nominal_cp_duration;
static int hf_simulcrypt_access_criteria_transfer_mode;
static int hf_simulcrypt_cp_number;
static int hf_simulcrypt_cp_duration;
static int hf_simulcrypt_cp_cw_combination;
static int hf_simulcrypt_ecm_datagram;
static int hf_simulcrypt_cw_encryption;
static int hf_simulcrypt_ecm_id;
static int hf_simulcrypt_client_id;
static int hf_simulcrypt_data_channel_id;
static int hf_simulcrypt_data_stream_id;
static int hf_simulcrypt_datagram;
static int hf_simulcrypt_bandwidth;
static int hf_simulcrypt_data_type;
static int hf_simulcrypt_data_id;
static int hf_simulcrypt_ecmg_error_status;
static int hf_simulcrypt_emmg_error_status;
static int hf_simulcrypt_error_information;

static int hf_simulcrypt_eis_parameter_type;
static int hf_simulcrypt_eis_channel_id;
static int hf_simulcrypt_service_flag;
static int hf_simulcrypt_component_flag;
static int hf_simulcrypt_max_scg;
static int hf_simulcrypt_ecm_group;
static int hf_simulcrypt_scg_id;
static int hf_simulcrypt_scg_reference_id;
static int hf_simulcrypt_activation_time;
static int hf_simulcrypt_year;
static int hf_simulcrypt_month;
static int hf_simulcrypt_day;
static int hf_simulcrypt_hour;
static int hf_simulcrypt_minute;
static int hf_simulcrypt_second;
static int hf_simulcrypt_hundredth_second;
static int hf_simulcrypt_activation_pending_flag;
static int hf_simulcrypt_component_id;
static int hf_simulcrypt_service_id;
static int hf_simulcrypt_transport_stream_id;
static int hf_simulcrypt_ac_changed_flag;
static int hf_simulcrypt_scg_current_reference_id;
static int hf_simulcrypt_scg_pending_reference_id;
static int hf_simulcrypt_cp_duration_flag;
static int hf_simulcrypt_recommended_cp_duration;
static int hf_simulcrypt_scg_nominal_cp_duration;
static int hf_simulcrypt_original_network_id;
static int hf_simulcrypt_eis_error_status;
static int hf_simulcrypt_error_description;

static int hf_simulcrypt_psig_parameter_type;
static int hf_simulcrypt_psig_type;
static int hf_simulcrypt_channel_id;
static int hf_simulcrypt_stream_id;
static int hf_simulcrypt_packet_id;
static int hf_simulcrypt_interface_mode_configuration;
static int hf_simulcrypt_max_stream;
static int hf_simulcrypt_table_period_pair;
static int hf_simulcrypt_mpeg_section;
static int hf_simulcrypt_repetition_rate;
static int hf_simulcrypt_initial_bandwidth;
static int hf_simulcrypt_asi_input_packet_id;
static int hf_simulcrypt_psig_error_status;
static int hf_simulcrypt_parameter_value;

/* These are the ids of the subtrees that we may be creating */
static int ett_simulcrypt;
static int ett_simulcrypt_header;
static int ett_simulcrypt_message;
static int ett_simulcrypt_parameter;
static int ett_simulcrypt_super_cas_id;
static int ett_simulcrypt_ecm_datagram;
static int ett_simulcrypt_ecm_group;
static int ett_simulcrypt_activation_time;
static int ett_simulcrypt_table_period_pair;


#define FRAME_HEADER_LEN 8

/* The main dissecting routine */
static int
dissect_simulcrypt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
{
	tcp_dissect_pdus(tvb, pinfo, tree, true, FRAME_HEADER_LEN,
			 get_simulcrypt_message_len, dissect_simulcrypt_message, data);
	return tvb_captured_length(tvb);
}

/* Informative tree structure is shown here:
* TREE 	-
*	- HEADER
*		version
*		message type
*		message length
*	- MESSAGE
*		- TYPE of parameter
*			length of parameter
			value of parameter
			- PARAMETER (optional branch for certain parameters only)
*				parameter value sub items here
* End informative tree structure
*/

static uint16_t
get_interface (uint16_t type)
{
	int interface;

	if (type >= 0x8000) {
		return SIMULCRYPT_USER_DEFINED;
	}

	/* Hex values fetched from Table 3: Message-type values for command/response-based protocols */
	switch (type & 0xFFF0) {
	case 0x0000:
	case 0x0100:
	case 0x0200:
		interface = SIMULCRYPT_ECMG_SCS;
		break;
	case 0x0010:
	case 0x0110:
	case 0x0210:
		interface = SIMULCRYPT_EMMG_MUX;
		break;
	case 0x0310:
	case 0x0320:
		interface = SIMULCRYPT_CPSIG_PSIG;
		break;
	case 0x0400:
		interface = SIMULCRYPT_EIS_SCS;
		break;
	case 0x0410:
	case 0x0420:
		interface = SIMULCRYPT_PSIG_MUX;
		break;
	case 0x0430:
		interface = SIMULCRYPT_MUX_CIM;
		break;
	case 0x0440:
		interface = SIMULCRYPT_PSIG_CIP;
		break;
	default:
		interface = SIMULCRYPT_RESERVED;
		break;
	}

	return interface;
}

static void
dissect_ecmg_parameter_value (proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, uint32_t offset,
			      uint16_t plen, uint16_t ptype, char *pvalue_char)
{
	proto_item *simulcrypt_item;
	proto_tree *simulcrypt_super_cas_id_tree;
	proto_tree *simulcrypt_ecm_datagram_tree;
	tvbuff_t   *next_tvb;
	uint32_t    pvaluedec;    /* parameter decimal value */
	int         ca_system_id;
	unsigned    i;

	switch (ptype) {
	case SIMULCRYPT_ECMG_SUPER_CAS_ID:
		/* add super_cas_id item */
		simulcrypt_item = proto_tree_add_item(tree, hf_simulcrypt_super_cas_id, tvb, offset, plen, ENC_BIG_ENDIAN); /* value item */
		simulcrypt_super_cas_id_tree = proto_item_add_subtree(simulcrypt_item, ett_simulcrypt_super_cas_id);

		/* Simulcrypt_super_cas_id_tree */
		simulcrypt_item = proto_tree_add_item(simulcrypt_super_cas_id_tree, hf_simulcrypt_ca_system_id, tvb, offset, 2, ENC_BIG_ENDIAN );

		/* Test for known CA_System_ID */
		ca_system_id = tvb_get_ntohs(tvb,offset);
		for(i=0;i<ECM_INTERPRETATION_SIZE;i++)
		{
			if(tab_ecm_inter[i].ca_system_id==ca_system_id)
			{
				tab_ecm_inter[i].ecmg_port=pinfo->destport;
				proto_item_append_text(simulcrypt_item, ", Port %d, Protocol %s",tab_ecm_inter[i].ecmg_port, tab_ecm_inter[i].protocol_name);
				break;
			}
		}
		proto_tree_add_item(simulcrypt_super_cas_id_tree, hf_simulcrypt_ca_subsystem_id, tvb, offset+2, 2, ENC_BIG_ENDIAN );
		break;
	case SIMULCRYPT_ECMG_SECTION_TSPKT_FLAG:
		proto_tree_add_item(tree, hf_simulcrypt_section_tspkt_flag, tvb, offset, plen, ENC_BIG_ENDIAN); /* value item */
		break;
	case SIMULCRYPT_ECMG_ECM_CHANNEL_ID:
		proto_tree_add_item(tree, hf_simulcrypt_ecm_channel_id, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_ECMG_DELAY_START:
		proto_tree_add_item(tree, hf_simulcrypt_delay_start, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_ECMG_DELAY_STOP:
		proto_tree_add_item(tree, hf_simulcrypt_delay_stop, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_ECMG_TRANSITION_DELAY_START:
		proto_tree_add_item(tree, hf_simulcrypt_transition_delay_start, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_ECMG_TRANSITION_DELAY_STOP:
		proto_tree_add_item(tree, hf_simulcrypt_transition_delay_stop, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_ECMG_AC_DELAY_START:
		proto_tree_add_item(tree, hf_simulcrypt_ac_delay_start, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_ECMG_AC_DELAY_STOP:
		proto_tree_add_item(tree, hf_simulcrypt_ac_delay_stop, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_ECMG_ECM_REP_PERIOD:
		proto_tree_add_item(tree, hf_simulcrypt_ecm_rep_period, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_ECMG_MAX_STREAMS:
		proto_tree_add_item(tree, hf_simulcrypt_max_streams, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_ECMG_MIN_CP_DURATION:
		/* convert value to ms (in units 100 ms) */
		pvaluedec = tvb_get_ntohs(tvb, offset); /* read 2 byte min CP duration value */
		pvaluedec = pvaluedec*100; /* in ms now */
		simulcrypt_item = proto_tree_add_item(tree, hf_simulcrypt_min_cp_duration, tvb, offset, plen, ENC_BIG_ENDIAN);
		proto_item_append_text(simulcrypt_item, " (%d ms)",pvaluedec);
		break;
	case SIMULCRYPT_ECMG_LEAD_CW:
		proto_tree_add_item(tree, hf_simulcrypt_lead_cw, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_ECMG_CW_PER_MESSAGE:
		proto_tree_add_item(tree, hf_simulcrypt_cw_per_msg, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_ECMG_MAX_COMP_TIME:
		proto_tree_add_item(tree, hf_simulcrypt_max_comp_time, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_ECMG_ACCESS_CRITERIA:
		proto_tree_add_item(tree, hf_simulcrypt_access_criteria, tvb, offset, plen, ENC_NA);
		break;
	case SIMULCRYPT_ECMG_ECM_STREAM_ID:
		proto_tree_add_item(tree, hf_simulcrypt_ecm_stream_id, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_ECMG_NOMINAL_CP_DURATION:
		/* convert value to ms (in units 100 ms) */
		pvaluedec = tvb_get_ntohs(tvb, offset); /* read 2 byte nominal CP duration value */
		pvaluedec = pvaluedec*100; /* in ms now */
		simulcrypt_item = proto_tree_add_item(tree, hf_simulcrypt_nominal_cp_duration, tvb, offset, plen, ENC_BIG_ENDIAN);
		proto_item_append_text(simulcrypt_item, " (%d ms)", pvaluedec);
		break;
	case SIMULCRYPT_ECMG_ACCESS_CRITERIA_TRANSFER_MODE:
		proto_tree_add_item(tree, hf_simulcrypt_access_criteria_transfer_mode, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_ECMG_CP_NUMBER:
		proto_tree_add_item(tree, hf_simulcrypt_cp_number, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_ECMG_CP_DURATION:
		/* convert value to ms (in units 100 ms) */
		pvaluedec = tvb_get_ntohs(tvb, offset); /* read 2 byte CP duration value */
		pvaluedec = pvaluedec*100; /* in ms now */
		simulcrypt_item = proto_tree_add_item(tree, hf_simulcrypt_cp_duration, tvb, offset, plen, ENC_BIG_ENDIAN);
		proto_item_append_text(simulcrypt_item, " (%d ms)", pvaluedec);
		break;
	case SIMULCRYPT_ECMG_CP_CW_COMBINATION:
		proto_tree_add_item(tree, hf_simulcrypt_cp_cw_combination, tvb, offset, plen, ENC_NA);
		break;
	case SIMULCRYPT_ECMG_ECM_DATAGRAM:
		simulcrypt_item = proto_tree_add_item(tree, hf_simulcrypt_ecm_datagram, tvb, offset, plen, ENC_NA);
		/* Test srcport against table of ECMG ports & CA_System_ID for known protocol types */
		for(i=0;i<ECM_INTERPRETATION_SIZE;i++)
		{
			if(tab_ecm_inter[i].ecmg_port==pinfo->srcport) /* ECMG source port */
			{ /* recognise port & ca_system_id and hence protocol name for ECM datagram */
				next_tvb = tvb_new_subset_remaining(tvb, offset);
				simulcrypt_ecm_datagram_tree = proto_item_add_subtree(simulcrypt_item, ett_simulcrypt_ecm_datagram);
				if(tab_ecm_inter[i].protocol_handle != NULL)
				{
					call_dissector(tab_ecm_inter[i].protocol_handle, next_tvb,pinfo, simulcrypt_ecm_datagram_tree);
				}
				break;
			}
		}
		break;
	case SIMULCRYPT_ECMG_CW_ENCRYPTION:
		proto_tree_add_item(tree, hf_simulcrypt_cw_encryption, tvb, offset, plen, ENC_NA);
		break;
	case SIMULCRYPT_ECMG_ECM_ID:
		proto_tree_add_item(tree, hf_simulcrypt_ecm_id, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_ECMG_ERROR_STATUS:
		proto_tree_add_item(tree, hf_simulcrypt_ecmg_error_status, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_ECMG_ERROR_INFORMATION:
		proto_tree_add_item(tree, hf_simulcrypt_error_information, tvb, offset, plen, ENC_NA);
		break;
	default:  /* Unknown parameter type */
		proto_tree_add_string(tree, hf_simulcrypt_parameter_value, tvb, offset, plen, pvalue_char);
		break;
	} /* end parameter type switch */
}

static void
dissect_emmg_parameter_value (proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, uint32_t offset,
			      uint16_t plen, uint16_t ptype, char *pvalue_char)
{
	switch (ptype) {
	case SIMULCRYPT_EMMG_CLIENT_ID:
		proto_tree_add_item(tree, hf_simulcrypt_client_id, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_EMMG_SECTION_TSPKT_FLAG:
		proto_tree_add_item(tree, hf_simulcrypt_section_tspkt_flag, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_EMMG_DATA_CHANNEL_ID:
		proto_tree_add_item(tree, hf_simulcrypt_data_channel_id, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_EMMG_DATA_STREAM_ID:
		proto_tree_add_item(tree, hf_simulcrypt_data_stream_id, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_EMMG_DATAGRAM:
		proto_tree_add_item(tree, hf_simulcrypt_datagram, tvb, offset, plen, ENC_NA);
		break;
	case SIMULCRYPT_EMMG_BANDWIDTH:
		proto_tree_add_item(tree, hf_simulcrypt_bandwidth, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_EMMG_DATA_TYPE:
		proto_tree_add_item(tree, hf_simulcrypt_data_type, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_EMMG_DATA_ID:
		proto_tree_add_item(tree, hf_simulcrypt_data_id, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_EMMG_ERROR_STATUS:
		proto_tree_add_item(tree, hf_simulcrypt_emmg_error_status, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_EMMG_ERROR_INFORMATION:
		proto_tree_add_item(tree, hf_simulcrypt_error_information, tvb, offset, plen, ENC_NA);
		break;
	default:  /* Unknown parameter type */
		proto_tree_add_string(tree, hf_simulcrypt_parameter_value, tvb, offset, plen, pvalue_char);
		break;
	} /* end parameter type switch */
}


static void
// NOLINTNEXTLINE(misc-no-recursion)
dissect_eis_parameter_value (proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, uint32_t offset,
			     uint16_t plen, uint16_t ptype, char *pvalue_char)
{
	proto_item *simulcrypt_item;
	proto_tree *simulcrypt_super_cas_id_tree;
	proto_tree *simulcrypt_ecm_group_tree;
	proto_tree *simulcrypt_activation_time_tree;
	uint32_t    pvaluedec;    /* parameter decimal value */
	int         ca_system_id;
	unsigned    i;

	switch (ptype) {
	case SIMULCRYPT_EIS_CHANNEL_ID:
		proto_tree_add_item(tree, hf_simulcrypt_eis_channel_id, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_EIS_SERVICE_FLAG:
		proto_tree_add_item(tree, hf_simulcrypt_service_flag, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_EIS_COMPONENT_FLAG:
		proto_tree_add_item(tree, hf_simulcrypt_component_flag, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_EIS_MAX_SCG:
		proto_tree_add_item(tree, hf_simulcrypt_max_scg, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_EIS_ECM_GROUP:
		/* add ECM_Group item */
		simulcrypt_item = proto_tree_add_item(tree, hf_simulcrypt_ecm_group, tvb, offset, plen, ENC_NA); /* value item */

		/* create subtree */
		simulcrypt_ecm_group_tree = proto_item_add_subtree(simulcrypt_item, ett_simulcrypt_ecm_group);

		/* dissect subtree */
		dissect_simulcrypt_data(simulcrypt_ecm_group_tree, simulcrypt_item, pinfo, tvb, tree, offset, plen, SIMULCRYPT_EIS_SCS, true);
		break;
	case SIMULCRYPT_EIS_SCG_ID:
		proto_tree_add_item(tree, hf_simulcrypt_scg_id, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_EIS_SCG_REFERENCE_ID:
		proto_tree_add_item(tree, hf_simulcrypt_scg_reference_id, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_EIS_SUPER_CAS_ID:
		/* add super_cas_id item */
		simulcrypt_item = proto_tree_add_item(tree, hf_simulcrypt_super_cas_id, tvb, offset, plen, ENC_BIG_ENDIAN); /* value item */
		simulcrypt_super_cas_id_tree = proto_item_add_subtree(simulcrypt_item, ett_simulcrypt_super_cas_id);

		/* Simulcrypt_super_cas_id_tree */
		simulcrypt_item = proto_tree_add_item(simulcrypt_super_cas_id_tree, hf_simulcrypt_ca_system_id, tvb, offset, 2, ENC_BIG_ENDIAN );

		/* Test for known CA_System_ID */
		ca_system_id = tvb_get_ntohs(tvb,offset);
		for(i=0;i<ECM_INTERPRETATION_SIZE;i++)
		{
			if(tab_ecm_inter[i].ca_system_id==ca_system_id)
			{
				tab_ecm_inter[i].ecmg_port=pinfo->destport;
				proto_item_append_text(simulcrypt_item, ", Port %d, Protocol %s",tab_ecm_inter[i].ecmg_port, tab_ecm_inter[i].protocol_name);
				break;
			}
		}
		proto_tree_add_item(simulcrypt_super_cas_id_tree, hf_simulcrypt_ca_subsystem_id, tvb, offset+2, 2, ENC_BIG_ENDIAN );
		break;
	case SIMULCRYPT_EIS_ECM_ID:
		proto_tree_add_item(tree, hf_simulcrypt_ecm_id, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_EIS_ACCESS_CRITERIA:
		proto_tree_add_item(tree, hf_simulcrypt_access_criteria, tvb, offset, plen, ENC_NA);
		break;
	case SIMULCRYPT_EIS_ACTIVATION_TIME:
		simulcrypt_item = proto_tree_add_item(tree, hf_simulcrypt_activation_time, tvb, offset, plen, ENC_NA); /* value item */

		/* create subtree */
		simulcrypt_activation_time_tree = proto_item_add_subtree(simulcrypt_item, ett_simulcrypt_activation_time);

		/* dissect subtree */
		proto_tree_add_item(simulcrypt_activation_time_tree, hf_simulcrypt_year, tvb, offset, 2, ENC_BIG_ENDIAN); /* first 2 bytes */
		proto_tree_add_item(simulcrypt_activation_time_tree, hf_simulcrypt_month, tvb, offset+2, 1, ENC_BIG_ENDIAN); /* third byte */
		proto_tree_add_item(simulcrypt_activation_time_tree, hf_simulcrypt_day, tvb, offset+3, 1, ENC_BIG_ENDIAN); /*fourth byte */
		proto_tree_add_item(simulcrypt_activation_time_tree, hf_simulcrypt_hour, tvb, offset+4, 1, ENC_BIG_ENDIAN); /*fifth byte */
		proto_tree_add_item(simulcrypt_activation_time_tree, hf_simulcrypt_minute, tvb, offset+5, 1, ENC_BIG_ENDIAN); /* sixth byte */
		proto_tree_add_item(simulcrypt_activation_time_tree, hf_simulcrypt_second, tvb, offset+6, 1, ENC_BIG_ENDIAN); /* seventh byte */
		proto_tree_add_item(simulcrypt_activation_time_tree, hf_simulcrypt_hundredth_second, tvb, offset+7, 1, ENC_BIG_ENDIAN); /* eighth byte */
		break;
	case SIMULCRYPT_EIS_ACTIVATION_PENDING_FLAG:
		proto_tree_add_item(tree, hf_simulcrypt_activation_pending_flag, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_EIS_COMPONENT_ID:
		proto_tree_add_item(tree, hf_simulcrypt_component_id, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_EIS_SERVICE_ID:
		proto_tree_add_item(tree, hf_simulcrypt_service_id, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_EIS_TRANSPORT_STREAM_ID:
		proto_tree_add_item(tree, hf_simulcrypt_transport_stream_id, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_EIS_AC_CHANGED_FLAG:
		proto_tree_add_item(tree, hf_simulcrypt_ac_changed_flag, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_EIS_SCG_CURRENT_REFERENCE_ID:
		proto_tree_add_item(tree, hf_simulcrypt_scg_current_reference_id, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_EIS_SCG_PENDING_REFERENCE_ID:
		proto_tree_add_item(tree, hf_simulcrypt_scg_pending_reference_id, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_EIS_CP_DURATION_FLAG:
		proto_tree_add_item(tree, hf_simulcrypt_cp_duration_flag, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_EIS_RECOMMENDED_CP_DURATION:
		/* convert value to ms (in units 100 ms) */
		pvaluedec = tvb_get_ntohs(tvb, offset); /* read 2 byte CP duration value */
		pvaluedec = pvaluedec*100; /* in ms now */
		simulcrypt_item = proto_tree_add_item(tree, hf_simulcrypt_recommended_cp_duration, tvb, offset, plen, ENC_BIG_ENDIAN);
		proto_item_append_text(simulcrypt_item, " (%d ms)", pvaluedec);
		break;
	case SIMULCRYPT_EIS_SCG_NOMINAL_CP_DURATION:
		/* convert value to ms (in units 100 ms) */
		pvaluedec = tvb_get_ntohs(tvb, offset); /* read 2 byte CP duration value */
		pvaluedec = pvaluedec*100; /* in ms now */
		simulcrypt_item = proto_tree_add_item(tree, hf_simulcrypt_scg_nominal_cp_duration, tvb, offset, plen, ENC_BIG_ENDIAN);
		proto_item_append_text(simulcrypt_item, " (%d ms)", pvaluedec);
		break;
	case SIMULCRYPT_EIS_ORIGINAL_NETWORK_ID:
		proto_tree_add_item(tree, hf_simulcrypt_original_network_id, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;

	case SIMULCRYPT_EIS_ERROR_STATUS:
		proto_tree_add_item(tree, hf_simulcrypt_eis_error_status, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_EIS_ERROR_INFORMATION:
		proto_tree_add_item(tree, hf_simulcrypt_error_information, tvb, offset, plen, ENC_NA);
		break;
	case SIMULCRYPT_EIS_ERROR_DESCRIPTION:
		proto_tree_add_item(tree, hf_simulcrypt_error_description, tvb, offset, plen, ENC_ASCII);
		break;

	default:  /* Unknown parameter type */
		proto_tree_add_string(tree, hf_simulcrypt_parameter_value, tvb, offset, plen, pvalue_char);
		break;
	} /* end parameter type switch */
}

static void
// NOLINTNEXTLINE(misc-no-recursion)
dissect_psig_parameter_value (proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, uint32_t offset,
			      uint16_t plen, uint16_t ptype, char *pvalue_char)
{
	proto_tree *simulcrypt_psig_table_period_pair_tree;
	proto_tree *simulcrypt_activation_time_tree;
	proto_item *simulcrypt_item;
	uint32_t    pvaluedec;    /* parameter decimal value */

	increment_dissection_depth(pinfo);
	switch (ptype) {
	case SIMULCRYPT_PSIG_PSIG_TYPE:
		pvaluedec = tvb_get_uint8(tvb, offset);
		simulcrypt_item = proto_tree_add_item(tree, hf_simulcrypt_psig_type, tvb, offset, plen, ENC_BIG_ENDIAN);
		switch(pvaluedec){
		case 1:
			proto_item_append_text(simulcrypt_item, " (PSIG)");
			break;
		case 2:
			proto_item_append_text(simulcrypt_item, " (SIG)");
			break;
		case 3:
			proto_item_append_text(simulcrypt_item, " (PSISIG)");
			break;
		default:
			break;
		}
		break;
	case SIMULCRYPT_PSIG_CHANNEL_ID:
		proto_tree_add_item(tree, hf_simulcrypt_channel_id, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_PSIG_STREAM_ID:
		proto_tree_add_item(tree, hf_simulcrypt_stream_id, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_PSIG_TRANSPORT_STREAM_ID:
		proto_tree_add_item(tree, hf_simulcrypt_transport_stream_id, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_PSIG_ORIGINAL_NETWORK_ID:
		proto_tree_add_item(tree, hf_simulcrypt_original_network_id, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_PSIG_PACKET_ID:
		proto_tree_add_item(tree, hf_simulcrypt_packet_id, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_PSIG_INTERFACE_MODE_CONFIGURATION:
		proto_tree_add_item(tree, hf_simulcrypt_interface_mode_configuration, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_PSIG_MAX_STREAM:
		proto_tree_add_item(tree, hf_simulcrypt_max_stream, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_PSIG_TABLE_PERIOD_PAIR:
		simulcrypt_item = proto_tree_add_item(tree, hf_simulcrypt_table_period_pair, tvb, offset, plen, ENC_NA); /* value item */

		/* create subtree */
		simulcrypt_psig_table_period_pair_tree = proto_item_add_subtree(simulcrypt_item, ett_simulcrypt_table_period_pair);

		/* dissect subtree */
		dissect_simulcrypt_data(simulcrypt_psig_table_period_pair_tree, simulcrypt_item, pinfo, tvb, tree, offset, plen, SIMULCRYPT_MUX_CIM, true);
		break;
	case SIMULCRYPT_PSIG_MPEG_SECTION:
		proto_tree_add_item(tree, hf_simulcrypt_mpeg_section, tvb, offset, plen, ENC_NA);
		break;
	case SIMULCRYPT_PSIG_REPETITION_RATE:
		proto_tree_add_item(tree, hf_simulcrypt_repetition_rate, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_PSIG_ACTIVATION_TIME:
		simulcrypt_item = proto_tree_add_item(tree, hf_simulcrypt_activation_time, tvb, offset, plen, ENC_NA); /* value item */

		/* create subtree */
		simulcrypt_activation_time_tree = proto_item_add_subtree(simulcrypt_item, ett_simulcrypt_activation_time);

		/* dissect subtree */
		proto_tree_add_item(simulcrypt_activation_time_tree, hf_simulcrypt_year, tvb, offset, 2, ENC_BIG_ENDIAN); /* first 2 bytes */
		proto_tree_add_item(simulcrypt_activation_time_tree, hf_simulcrypt_month, tvb, offset+2, 1, ENC_BIG_ENDIAN); /* third byte */
		proto_tree_add_item(simulcrypt_activation_time_tree, hf_simulcrypt_day, tvb, offset+3, 1, ENC_BIG_ENDIAN); /*fourth byte */
		proto_tree_add_item(simulcrypt_activation_time_tree, hf_simulcrypt_hour, tvb, offset+4, 1, ENC_BIG_ENDIAN); /*fifth byte */
		proto_tree_add_item(simulcrypt_activation_time_tree, hf_simulcrypt_minute, tvb, offset+5, 1, ENC_BIG_ENDIAN); /* sixth byte */
		proto_tree_add_item(simulcrypt_activation_time_tree, hf_simulcrypt_second, tvb, offset+6, 1, ENC_BIG_ENDIAN); /* seventh byte */
		proto_tree_add_item(simulcrypt_activation_time_tree, hf_simulcrypt_hundredth_second, tvb, offset+7, 1, ENC_BIG_ENDIAN); /* eighth byte */
		break;
	case SIMULCRYPT_PSIG_DATAGRAM:
		proto_tree_add_item(tree, hf_simulcrypt_datagram, tvb, offset, plen, ENC_NA);
		break;
	case SIMULCRYPT_PSIG_BANDWIDTH:
		proto_tree_add_item(tree, hf_simulcrypt_bandwidth, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_PSIG_INITIAL_BANDWIDTH:
		proto_tree_add_item(tree, hf_simulcrypt_initial_bandwidth, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_PSIG_MAX_COMP_TIME:
		proto_tree_add_item(tree, hf_simulcrypt_max_comp_time, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_PSIG_ASI_INPUT_PACKET_ID:
		proto_tree_add_item(tree, hf_simulcrypt_asi_input_packet_id, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_PSIG_ERROR_STATUS:
		proto_tree_add_item(tree, hf_simulcrypt_psig_error_status, tvb, offset, plen, ENC_BIG_ENDIAN);
		break;
	case SIMULCRYPT_PSIG_ERROR_INFORMATION:
		proto_tree_add_item(tree, hf_simulcrypt_error_information, tvb, offset, plen, ENC_NA);
		break;
	default:  /* Unknown parameter type */
		proto_tree_add_string(tree, hf_simulcrypt_parameter_value, tvb, offset, plen, pvalue_char);
		break;
	} /* end parameter type switch */
	decrement_dissection_depth(pinfo);
}

/* This method dissects fully reassembled messages */
static int
dissect_simulcrypt_message(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
{
	proto_item *simulcrypt_item;
	proto_tree *simulcrypt_tree;
	proto_tree *simulcrypt_header_tree;
	proto_tree *simulcrypt_message_tree;
	uint16_t    type, iftype;

	col_set_str(pinfo->cinfo, COL_PROTOCOL, PROTO_TAG_SIMULCRYPT);
	col_clear(pinfo->cinfo,COL_INFO);

	/* get 2 byte type value */
	type =  tvb_get_ntohs(tvb, 1); /* 2 bytes starting at offset 1 are the message type */
	iftype = get_interface (type);

	col_add_fstr(pinfo->cinfo, COL_INFO, "%d > %d Info Type:[%s]",
		     pinfo->srcport, pinfo->destport,
		     val_to_str_ext(type, &messagetypenames_ext, "Unknown Type:0x%02x"));

	if (tree)
	{
		/* we are being asked for details */
		uint32_t offset = 0;
		uint32_t msg_length;

		simulcrypt_item = proto_tree_add_item(tree, proto_simulcrypt, tvb, 0, -1, ENC_NA);
		simulcrypt_tree = proto_item_add_subtree(simulcrypt_item, ett_simulcrypt);

		proto_item_append_text(simulcrypt_item, ", Interface: %s", val_to_str(iftype, interfacenames, "Unknown (0x%02x)"));

		/* Simulcrypt_tree analysis */
		/* we are being asked for details */
		/* ADD HEADER BRANCH */
		simulcrypt_item = proto_tree_add_item(simulcrypt_tree, hf_simulcrypt_header, tvb, offset, 5, ENC_NA );
		simulcrypt_header_tree = proto_item_add_subtree(simulcrypt_item, ett_simulcrypt_header);
		proto_item_append_text(simulcrypt_header_tree, ", Length: %s", "5 bytes"); /* add text to Header tree indicating Length 5 bytes */

		/* Simulcrypt_header_tree analysis */
		/* Message Version 1 Byte */
		proto_tree_add_item(simulcrypt_header_tree, hf_simulcrypt_version, tvb, offset, 1, ENC_BIG_ENDIAN);
		offset+=1;

		/* Message Type 2 Bytes */
		proto_tree_add_item(simulcrypt_header_tree, hf_simulcrypt_message_type, tvb, offset, 2, ENC_BIG_ENDIAN);
		simulcrypt_item = proto_tree_add_uint_format_value(simulcrypt_header_tree, hf_simulcrypt_interface, tvb, offset, 2, iftype,
							     "%s", val_to_str_const(iftype, interfacenames, "Unknown"));
		proto_item_set_generated (simulcrypt_item);
		offset+=2;

		/* Message Length 2 Bytes */
		proto_tree_add_item(simulcrypt_header_tree, hf_simulcrypt_message_length, tvb, offset, 2, ENC_BIG_ENDIAN);
		msg_length = tvb_get_ntohs(tvb, offset); /* read 2 byte message length value */
		offset+=2;

		/* ADD MESSAGE BRANCH */
		simulcrypt_item = proto_tree_add_item(simulcrypt_tree, hf_simulcrypt_message, tvb, offset, -1, ENC_NA );
		simulcrypt_message_tree = proto_item_add_subtree(simulcrypt_item, ett_simulcrypt_message);
		proto_item_append_text(simulcrypt_message_tree, " containing TLV parameters"); /* add text to Message tree	*/
		proto_item_append_text(simulcrypt_message_tree, ", Length: %d (bytes)", msg_length); /* add length info to message_tree */

		/* end header details */

		/* Simulcrypt_message_tree analysis */
		/*  we are being asked for details */
		/* Navigate through message after header to find one or more parameters */

		dissect_simulcrypt_data(simulcrypt_message_tree, simulcrypt_item, pinfo, tvb, tree, offset, (msg_length+5), iftype, false); /* offset is from beginning of the 5 byte header */

	} /* end tree */

	return tvb_captured_length(tvb);
}

/* this method is used to dissect TLV parameters */
/* can be used both from the main tree (simulcrypt_message_tree) and the subtrees (created from TLV items) */
static void
// NOLINTNEXTLINE(misc-no-recursion)
dissect_simulcrypt_data(proto_tree *simulcrypt_tree, proto_item *simulcrypt_item, packet_info *pinfo _U_,
			tvbuff_t *tvb, proto_tree *tree, int offset,
			int container_data_length, uint16_t iftype, bool is_subtree)
{
	int subtree_offset = 0;
	proto_tree *simulcrypt_parameter_tree;
	int applied_offset;

	if(is_subtree)
	{
		applied_offset = subtree_offset;
	}
	else
	{
		applied_offset = offset;
	}

	while (applied_offset < container_data_length)
	{
		uint16_t plen;         /* parameter length */
		uint16_t ptype;        /* parameter type */
		char   *pvalue_char;  /* parameter value string */

		/* Parameter  Type 2 Bytes */
		ptype = tvb_get_ntohs(tvb, offset); /* read 2 byte type value */
		/* Parameter  Length 2 Bytes */
		plen = tvb_get_ntohs(tvb, offset+2); /* read 2 byte length value */
		/* Parameter  Value plen Bytes */
		pvalue_char = tvb_bytes_to_str(pinfo->pool, tvb, offset+4, plen);

		simulcrypt_item = proto_tree_add_item(simulcrypt_tree, hf_simulcrypt_parameter, tvb, offset, plen+2+2, ENC_NA );

		/* add length and value info to type */
		switch (iftype) {
		case SIMULCRYPT_ECMG_SCS:
			proto_item_append_text(simulcrypt_item, ": Type=%s", val_to_str_ext(ptype, &ecmg_parametertypenames_ext, "Unknown Type:0x%02x"));
			break;
		case SIMULCRYPT_EMMG_MUX:
			proto_item_append_text(simulcrypt_item, ": Type=%s", val_to_str_ext(ptype, &emmg_parametertypenames_ext, "Unknown Type:0x%02x"));
			break;
		case SIMULCRYPT_EIS_SCS:
			proto_item_append_text(simulcrypt_item, ": Type=%s", val_to_str_ext(ptype, &eis_parametertypenames_ext, "Unknown Type:0x%02x"));
			break;
		case SIMULCRYPT_PSIG_MUX:
		case SIMULCRYPT_MUX_CIM:
		case SIMULCRYPT_PSIG_CIP:
			proto_item_append_text(simulcrypt_item, ": Type=%s", val_to_str_ext(ptype, &psig_parametertypenames_ext, "Unknown Type:0x%02x"));
			break;
		default:
			proto_item_append_text(simulcrypt_item, ": Type=0x%02x", ptype);
			break;
		}
		proto_item_append_text(simulcrypt_item, ", Value Length=%d (bytes)", plen); /* add length info to parameter */
		proto_item_append_text(simulcrypt_item, ", Value=0x%s", pvalue_char); /* add value info to parameter */
		/* add subtree for parameter type, length and value items */
		simulcrypt_parameter_tree = proto_item_add_subtree(simulcrypt_item, ett_simulcrypt_parameter); /* add subtree for Length and Value */
		switch (iftype) { /* parameter type */
		case SIMULCRYPT_ECMG_SCS:
			proto_tree_add_item(simulcrypt_parameter_tree, hf_simulcrypt_ecmg_parameter_type, tvb, offset, 2, ENC_BIG_ENDIAN);
			break;
		case SIMULCRYPT_EMMG_MUX:
			proto_tree_add_item(simulcrypt_parameter_tree, hf_simulcrypt_emmg_parameter_type, tvb, offset, 2, ENC_BIG_ENDIAN);
			break;
		case SIMULCRYPT_EIS_SCS:
			proto_tree_add_item(simulcrypt_parameter_tree, hf_simulcrypt_eis_parameter_type, tvb, offset, 2, ENC_BIG_ENDIAN);
			break;
		case SIMULCRYPT_PSIG_MUX:
		case SIMULCRYPT_MUX_CIM:
		case SIMULCRYPT_PSIG_CIP:
			proto_tree_add_item(simulcrypt_parameter_tree, hf_simulcrypt_psig_parameter_type, tvb, offset, 2, ENC_BIG_ENDIAN);
			break;
		default:
			proto_tree_add_item(simulcrypt_parameter_tree, hf_simulcrypt_parameter_type, tvb, offset, 2, ENC_BIG_ENDIAN);
			break;
		}
		proto_tree_add_item(simulcrypt_parameter_tree, hf_simulcrypt_parameter_length, tvb, offset+2, 2, ENC_BIG_ENDIAN); /* length item */
		offset += 2+2;  /* offset --> parameter value */

		switch (iftype) {
		case SIMULCRYPT_ECMG_SCS:
			dissect_ecmg_parameter_value (simulcrypt_parameter_tree, tvb, pinfo, offset, plen, ptype, pvalue_char);
			break;
		case SIMULCRYPT_EMMG_MUX:
			dissect_emmg_parameter_value (simulcrypt_parameter_tree, tvb, pinfo, offset, plen, ptype, pvalue_char);
			break;
		case SIMULCRYPT_EIS_SCS:
			dissect_eis_parameter_value (simulcrypt_parameter_tree, tvb, pinfo, offset, plen, ptype, pvalue_char);
			break;
		case SIMULCRYPT_PSIG_MUX:
		case SIMULCRYPT_MUX_CIM:
		case SIMULCRYPT_PSIG_CIP:
			dissect_psig_parameter_value (simulcrypt_parameter_tree, tvb, pinfo, offset, plen, ptype, pvalue_char);
			break;
		default:
			proto_tree_add_string(tree, hf_simulcrypt_parameter_value, tvb, offset, plen, pvalue_char);
			break;
		}
		offset         += plen;
		subtree_offset += 2+2+plen;

		if(is_subtree)
		{
			applied_offset = subtree_offset;
		}
		else
		{
			applied_offset = offset;
		}
	} /* end parameter tree details */
}


/* determine PDU length of protocol foo */
static unsigned
get_simulcrypt_message_len(packet_info *pinfo _U_, tvbuff_t *tvb,
                           int offset, void *data _U_)
{
	unsigned iLg;

	iLg = tvb_get_ntohs(tvb,offset+3); /*length is at offset 3 */
	iLg += 5; /* add 1 byte version + 2 byte type + 2 byte length (simulcrypt "header" */
	return iLg;
}

/* Clean out the ecm_interpretation port association whenever            */
/* making a pass through a capture file to dissect all its packets       */
/*  (e.g., reading in a new capture file, changing a simulcrypt pref,    */
/*  or running a "filter packets" or "colorize packets" pass over the    */
/*  current capture file.                                                */

static void
simulcrypt_init(void)
{
	unsigned i;

	for(i=0;i<ECM_INTERPRETATION_SIZE;i++)
	{
		tab_ecm_inter[i].ecmg_port = -1;
	}
}

void proto_reg_handoff_simulcrypt(void);

void
proto_register_simulcrypt (void)
{
	/* A header field is something you can search/filter on.
	*
	* We create a structure to register our fields. It consists of an
	* array of hf_register_info structures, each of which are of the format
	* {&(field id), {name, abbrev, type, display, strings, bitmask, blurb, HFILL}}.
	*/
	static hf_register_info hf[] =
	{
		{ &hf_simulcrypt_header,
		{ "Header", "simulcrypt.header", FT_NONE, BASE_NONE, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_version,
		{ "Version", "simulcrypt.version", FT_UINT8, BASE_HEX, NULL, 0x0,  /* version 1 byte */
		 NULL, HFILL }},

		{ &hf_simulcrypt_message_type,
		{ "Message Type", "simulcrypt.message.type", FT_UINT16, BASE_HEX|BASE_EXT_STRING, &messagetypenames_ext, 0x0,  /* type 2 bytes */
		 NULL, HFILL }},

		{ &hf_simulcrypt_interface,
		{ "Interface", "simulcrypt.message.interface", FT_UINT16, BASE_DEC, VALS(interfacenames), 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_message_length,
		{ "Message Length", "simulcrypt.message.len", FT_UINT16, BASE_DEC|BASE_UNIT_STRING, UNS(&units_byte_bytes), 0x0,  /* length 2 bytes, print as decimal value */
		NULL, HFILL }},

		{ &hf_simulcrypt_message,
		{ "Message", "simulcrypt.message", FT_NONE, BASE_NONE, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_parameter,
		{ "Parameter", "simulcrypt.parameter", FT_NONE, BASE_NONE, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_parameter_type,
		{ "Parameter Type", "simulcrypt.parameter.type", FT_UINT16, BASE_HEX, NULL, 0x0, /* type 2 bytes */
		 NULL, HFILL }},

		{ &hf_simulcrypt_ecmg_parameter_type,
		{ "Parameter Type", "simulcrypt.parameter.type", FT_UINT16, BASE_HEX | BASE_EXT_STRING, &ecmg_parametertypenames_ext, 0x0,  /* type 2 bytes */
		 NULL, HFILL }},

		{ &hf_simulcrypt_emmg_parameter_type,
		{ "Parameter Type", "simulcrypt.parameter.type", FT_UINT16, BASE_HEX | BASE_EXT_STRING, &emmg_parametertypenames_ext, 0x0,  /* type 2 bytes */
		 NULL, HFILL }},

		{ &hf_simulcrypt_parameter_length,
		{ "Parameter Length", "simulcrypt.parameter.len", FT_UINT16, BASE_DEC|BASE_UNIT_STRING, UNS(&units_byte_bytes), 0x0,  /* length 2 bytes, print as decimal value */
		 NULL, HFILL }},

		{ &hf_simulcrypt_ca_system_id,
		{ "CA System ID", "simulcrypt.parameter.ca_system_id", FT_UINT16, BASE_DEC, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_ca_subsystem_id,
		{ "CA Subsystem ID", "simulcrypt.parameter.ca_subsystem_id", FT_UINT16, BASE_DEC, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_super_cas_id,
		{ "SuperCAS ID", "simulcrypt.super_cas_id", FT_UINT32, BASE_HEX, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_section_tspkt_flag,
		{ "Section TS pkt flag", "simulcrypt.section_tspkt_flag", FT_UINT8, BASE_HEX, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_ecm_channel_id,
		{ "ECM channel ID", "simulcrypt.ecm_channel_id", FT_UINT16, BASE_DEC, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_delay_start,
		{ "Delay start", "simulcrypt.delay_start", FT_INT16, BASE_DEC|BASE_UNIT_STRING, UNS(&units_milliseconds), 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_delay_stop,
		{ "Delay stop", "simulcrypt.delay_stop", FT_INT16, BASE_DEC|BASE_UNIT_STRING, UNS(&units_milliseconds), 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_ac_delay_start,
		{ "AC delay start", "simulcrypt.ac_delay_start", FT_INT16, BASE_DEC|BASE_UNIT_STRING, UNS(&units_milliseconds), 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_ac_delay_stop,
		{ "AC delay stop", "simulcrypt.ac_delay_stop", FT_INT16, BASE_DEC|BASE_UNIT_STRING, UNS(&units_milliseconds), 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_transition_delay_start,
		{ "Transition delay start", "simulcrypt.transition_delay_start", FT_INT16, BASE_DEC|BASE_UNIT_STRING, UNS(&units_milliseconds), 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_transition_delay_stop,
		{ "Transition delay stop", "simulcrypt.transition_delay_stop", FT_INT16, BASE_DEC|BASE_UNIT_STRING, UNS(&units_milliseconds), 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_ecm_rep_period,
		{ "ECM repetition period", "simulcrypt.ecm_rep_period", FT_UINT16, BASE_DEC|BASE_UNIT_STRING, UNS(&units_milliseconds), 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_max_streams,
		{ "Max streams", "simulcrypt.max_streams", FT_UINT16, BASE_DEC, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_min_cp_duration,
		{ "Min CP duration", "simulcrypt.min_cp_duration", FT_UINT16, BASE_DEC, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_lead_cw,
		{ "Lead CW", "simulcrypt.lead_cw", FT_UINT8, BASE_DEC, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_cw_per_msg,
		{ "CW per msg", "simulcrypt.cw_per_msg", FT_UINT8, BASE_DEC, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_max_comp_time,
		{ "Max comp time", "simulcrypt.max_comp_time", FT_UINT16, BASE_DEC|BASE_UNIT_STRING, UNS(&units_milliseconds), 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_access_criteria,
		{ "Access criteria", "simulcrypt.access_criteria", FT_BYTES, BASE_NONE, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_ecm_stream_id,
		{ "ECM stream ID", "simulcrypt.ecm_stream_id", FT_UINT16, BASE_DEC, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_nominal_cp_duration,
		{ "Nominal CP duration", "simulcrypt.nominal_cp_duration", FT_UINT16, BASE_DEC, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_access_criteria_transfer_mode,
		{ "AC transfer mode", "simulcrypt.access_criteria_transfer_mode", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_cp_number,
		{ "CP number", "simulcrypt.cp_number", FT_UINT16, BASE_DEC, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_cp_duration,
		{ "CP duration", "simulcrypt.cp_duration", FT_UINT16, BASE_DEC, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_cp_cw_combination,
		{ "CP CW combination", "simulcrypt.cp_cw_combination", FT_BYTES, BASE_NONE, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_ecm_datagram,
		{ "ECM datagram", "simulcrypt.ecm_datagram", FT_BYTES, BASE_NONE, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_cw_encryption,
		{ "CW encryption", "simulcrypt.cw_encryption", FT_NONE, BASE_NONE, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_ecm_id,
		{ "ECM ID", "simulcrypt.ecm_id", FT_UINT16, BASE_DEC, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_client_id,
		{ "Client ID", "simulcrypt.client_id", FT_UINT32, BASE_DEC, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_data_channel_id,
		{ "Data Channel ID", "simulcrypt.data_channel_id", FT_UINT16, BASE_DEC, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_data_stream_id,
		{ "Data Stream ID", "simulcrypt.data_stream_id", FT_UINT16, BASE_DEC, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_datagram,
		{ "Datagram", "simulcrypt.datagram", FT_BYTES, BASE_NONE, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_bandwidth,
		{ "Bandwidth", "simulcrypt.bandwidth", FT_UINT16, BASE_DEC|BASE_UNIT_STRING, UNS(&units_kbps), 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_data_type,
		{ "Data Type", "simulcrypt.data_type", FT_UINT8, BASE_DEC, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_data_id,
		{ "Data ID", "simulcrypt.data_id", FT_UINT16, BASE_DEC, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_ecmg_error_status,
		{ "Error status", "simulcrypt.error_status", FT_UINT16, BASE_DEC | BASE_EXT_STRING, &ecmg_error_values_ext, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_emmg_error_status,
		{ "Error status", "simulcrypt.error_status", FT_UINT16, BASE_DEC | BASE_EXT_STRING, &emmg_error_values_ext, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_error_information,
		{ "Error information", "simulcrypt.error_information", FT_BYTES, BASE_NONE, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_eis_parameter_type,
		{ "Parameter Type", "simulcrypt.parameter.type", FT_UINT16, BASE_HEX | BASE_EXT_STRING, &eis_parametertypenames_ext, 0x0, /* type 2 bytes */
		 NULL, HFILL }},

		{ &hf_simulcrypt_eis_channel_id,
		{ "EIS channel ID", "simulcrypt.parameter.eis_channel_id", FT_UINT16, BASE_DEC, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_service_flag,
		{ "Service flag", "simulcrypt.parameter.service_flag", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_component_flag,
		{ "Component flag", "simulcrypt.parameter.component_flag", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_max_scg,
		{ "Max SCG", "simulcrypt.parameter.max_scg", FT_UINT16, BASE_DEC, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_ecm_group,
		{ "ECM group", "simulcrypt.parameter.ecm_group", FT_BYTES, BASE_NONE, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_scg_id,
		{ "SCG ID", "simulcrypt.parameter.scg_id", FT_UINT16, BASE_DEC, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_scg_reference_id,
		{ "SCG reference ID", "simulcrypt.parameter.scg_reference_id", FT_UINT32, BASE_DEC, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_activation_time,
		{ "Activation time", "simulcrypt.parameter.activation_time", FT_BYTES, BASE_NONE, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_year,
		{ "Year", "simulcrypt.parameter.year", FT_UINT16, BASE_DEC, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_month,
		{ "Month", "simulcrypt.parameter.month", FT_UINT8, BASE_DEC, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_day,
		{ "Day", "simulcrypt.parameter.day", FT_UINT8, BASE_DEC, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_hour,
		{ "Hour", "simulcrypt.parameter.hour", FT_UINT8, BASE_DEC, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_minute,
		{ "Minute", "simulcrypt.parameter.minute", FT_UINT8, BASE_DEC, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_second,
		{ "Second", "simulcrypt.parameter.second", FT_UINT8, BASE_DEC, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_hundredth_second,
		{ "Hundredth_second", "simulcrypt.parameter.hundredth_second", FT_UINT8, BASE_DEC, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_activation_pending_flag,
		{ "Activation pending flag", "simulcrypt.parameter.activation_pending_flag", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_component_id,
		{ "Component ID", "simulcrypt.parameter.component_id", FT_UINT16, BASE_DEC, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_service_id,
		{ "Service ID", "simulcrypt.parameter.service_id", FT_UINT16, BASE_DEC, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_transport_stream_id,
		{ "Transport stream ID", "simulcrypt.parameter.transport_stream_id", FT_UINT16, BASE_DEC, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_ac_changed_flag,
		{ "AC changed flag", "simulcrypt.parameter.ac_changed_flag", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_scg_current_reference_id,
		{ "SCG current reference ID", "simulcrypt.parameter.scg_current_reference_id", FT_UINT32, BASE_DEC, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_scg_pending_reference_id,
		{ "SCG pending reference ID", "simulcrypt.parameter.scg_pending_reference_id", FT_UINT32, BASE_DEC, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_cp_duration_flag,
		{ "CP duration flag", "simulcrypt.parameter.cp_duration_flag", FT_UINT8, BASE_DEC, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_recommended_cp_duration,
		{ "Recommended CP duration", "simulcrypt.parameter.recommended_cp_duration", FT_UINT16, BASE_DEC, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_scg_nominal_cp_duration,
		{ "SCG nominal CP duration", "simulcrypt.parameter.scg_nominal_cp_duration", FT_UINT16, BASE_DEC, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_original_network_id,
		{ "Original network ID", "simulcrypt.parameter.original_network_id", FT_UINT16, BASE_DEC, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_eis_error_status,
		{ "Error status", "simulcrypt.error_status", FT_UINT16, BASE_DEC | BASE_EXT_STRING, &eis_error_values_ext, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_error_description,
		{ "Error description", "simulcrypt.error_description", FT_STRING, BASE_NONE, NULL, 0x0,   /* error_description --> ASCII byte string */
		 NULL, HFILL }},

		{ &hf_simulcrypt_psig_parameter_type,
		{ "Parameter Type", "simulcrypt.parameter.type", FT_UINT16, BASE_HEX | BASE_EXT_STRING, &psig_parametertypenames_ext, 0x0,  /* type 2 bytes */
		 NULL, HFILL }},

		{ &hf_simulcrypt_psig_type,
		{ "PSIG type", "simulcrypt.parameter.psig_type", FT_UINT8, BASE_HEX, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_channel_id,
		{ "Channel ID", "simulcrypt.parameter.channel_id", FT_UINT16, BASE_DEC, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_stream_id,
		{ "Stream ID", "simulcrypt.parameter.stream_id", FT_UINT16, BASE_DEC, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_packet_id,
		{ "Packet ID", "simulcrypt.parameter.packet_id", FT_UINT16, BASE_DEC, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_interface_mode_configuration,
		{ "Interface mode configuration", "simulcrypt.parameter.interface_mode_configuration", FT_UINT8, BASE_HEX, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_max_stream,
		{ "Max stream", "simulcrypt.parameter.max_stream", FT_UINT16, BASE_DEC, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_table_period_pair,
		{ "Table period pair", "simulcrypt.parameter.table_period_pair", FT_BYTES, BASE_NONE, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_mpeg_section,
		{ "MPEG section", "simulcrypt.parameter.mpeg_section", FT_BYTES, BASE_NONE, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_repetition_rate,
		{ "Repetition rate", "simulcrypt.parameter.repetition_rate", FT_UINT32, BASE_DEC, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_initial_bandwidth,
		{ "Initial bandwidth", "simulcrypt.parameter.initial_bandwidth", FT_UINT16, BASE_DEC|BASE_UNIT_STRING, UNS(&units_kbps), 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_asi_input_packet_id,
		{ "ASI input packet ID", "simulcrypt.parameter.asi_input_packet_id", FT_UINT16, BASE_DEC, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_psig_error_status,
		{ "Error status", "simulcrypt.parameter.error_status", FT_UINT16, BASE_DEC, NULL, 0x0,
		 NULL, HFILL }},

		{ &hf_simulcrypt_parameter_value,
		{ "Parameter Value", "simulcrypt.parameter.value", FT_STRING, BASE_NONE, NULL, 0x0,
		 NULL, HFILL }}
	};

	static int *ett[] =
	{
		&ett_simulcrypt,
		&ett_simulcrypt_header,
		&ett_simulcrypt_message,
		&ett_simulcrypt_parameter,
		&ett_simulcrypt_super_cas_id,
		&ett_simulcrypt_ecm_datagram,
		&ett_simulcrypt_ecm_group,
		&ett_simulcrypt_activation_time,
		&ett_simulcrypt_table_period_pair
	};

	module_t *simulcrypt_module;

	/* execute protocol initialization only once */
	proto_simulcrypt = proto_register_protocol ("SIMULCRYPT Protocol", "SIMULCRYPT", "simulcrypt");

	proto_register_field_array (proto_simulcrypt, hf, array_length (hf));
	proto_register_subtree_array (ett, array_length (ett));

	register_init_routine(simulcrypt_init);

	simulcrypt_handle = register_dissector("simulcrypt", dissect_simulcrypt, proto_simulcrypt);

	/* Register our configuration options for Simulcrypt, particularly our port. */
	/* This registers our preferences; function proto_reg_handoff_simulcrypt is  */
	/*  called when preferences are applied.                                     */
	simulcrypt_module = prefs_register_protocol(proto_simulcrypt, proto_reg_handoff_simulcrypt);

	prefs_register_uint_preference(simulcrypt_module, "ca_system_id_mikey","MIKEY ECM CA_system_ID (in hex)",
					"Set the CA_system_ID used to decode ECM datagram as MIKEY", 16, &ca_system_id_mikey);
}

/* this is run every time preferences are changed and also during Wireshark initialization */
void
proto_reg_handoff_simulcrypt(void)
{
	static bool initialized=false;
	unsigned  i;

	if (!initialized) {
		for(i=0;i<ECM_INTERPRETATION_SIZE;i++)
		{
			tab_ecm_inter[i].protocol_handle = find_dissector(tab_ecm_inter[i].protocol_name);
		}
		dissector_add_for_decode_as_with_preference("udp.port", simulcrypt_handle);
		dissector_add_for_decode_as_with_preference("tcp.port", simulcrypt_handle);
		initialized = true;
	}

	/* update tab_ecm_inter table (always do this) */
	tab_ecm_inter[ECM_MIKEY_INDEX].ca_system_id=ca_system_id_mikey;
}

/*
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
 *
 * Local variables:
 * c-basic-offset: 8
 * tab-width: 8
 * indent-tabs-mode: t
 * End:
 *
 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
 * :indentSize=8:tabSize=8:noTabs=false:
 */