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
|
/* packet-z21.c
* Routines for Z21 LAN protocol dissection
* Copyright 2023, Markku Leiniö <markku.leinio@gmail.com>
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
/*
* Z21 LAN protocol specification can be found at:
* https://www.z21.eu/en/downloads/manuals
*/
#include "config.h"
#define WS_LOG_DOMAIN "Z21"
#include <epan/packet.h>
#include <epan/expert.h>
#include <epan/prefs.h>
#include "packet-udp.h"
void proto_register_z21(void);
void proto_reg_handoff_z21(void);
/* Initialize the protocol and registered fields */
static int proto_z21 = -1;
static int hf_z21_datalen = -1;
static int hf_z21_command = -1;
static int hf_z21_x_bus = -1;
static int hf_z21_serial_number = -1;
static int hf_z21_checksum = -1;
static int hf_z21_main_current = -1;
static int hf_z21_prog_current = -1;
static int hf_z21_filtered_main_current = -1;
static int hf_z21_temperature = -1;
static int hf_z21_supply_voltage = -1;
static int hf_z21_track_voltage = -1;
static int hf_z21_central_state = -1;
static int hf_z21_central_state_ex = -1;
static int hf_z21_systemstate_reserved = -1;
static int hf_z21_capabilities = -1;
static int hf_z21_status = -1;
static int hf_z21_loco_address = -1;
static int hf_z21_loco_direction_and_speed = -1;
static int hf_z21_loco_direction = -1;
static int hf_z21_loco_speed = -1;
static int hf_z21_loco_info_mm = -1;
static int hf_z21_loco_info_busy = -1;
static int hf_z21_loco_info_speed_steps = -1;
static int hf_z21_loco_info_direction = -1;
static int hf_z21_loco_info_speed = -1;
static int hf_z21_loco_info_double_traction = -1;
static int hf_z21_loco_info_smartsearch = -1;
static int hf_z21_loco_info_f0 = -1;
static int hf_z21_loco_info_f1 = -1;
static int hf_z21_loco_info_f2 = -1;
static int hf_z21_loco_info_f3 = -1;
static int hf_z21_loco_info_f4 = -1;
static int hf_z21_loco_info_f5 = -1;
static int hf_z21_loco_info_f6 = -1;
static int hf_z21_loco_info_f7 = -1;
static int hf_z21_loco_info_f8 = -1;
static int hf_z21_loco_info_f9 = -1;
static int hf_z21_loco_info_f10 = -1;
static int hf_z21_loco_info_f11 = -1;
static int hf_z21_loco_info_f12 = -1;
static int hf_z21_loco_info_f13 = -1;
static int hf_z21_loco_info_f14 = -1;
static int hf_z21_loco_info_f15 = -1;
static int hf_z21_loco_info_f16 = -1;
static int hf_z21_loco_info_f17 = -1;
static int hf_z21_loco_info_f18 = -1;
static int hf_z21_loco_info_f19 = -1;
static int hf_z21_loco_info_f20 = -1;
static int hf_z21_loco_info_f21 = -1;
static int hf_z21_loco_info_f22 = -1;
static int hf_z21_loco_info_f23 = -1;
static int hf_z21_loco_info_f24 = -1;
static int hf_z21_loco_info_f25 = -1;
static int hf_z21_loco_info_f26 = -1;
static int hf_z21_loco_info_f27 = -1;
static int hf_z21_loco_info_f28 = -1;
static int hf_z21_loco_info_f29 = -1;
static int hf_z21_loco_info_f30 = -1;
static int hf_z21_loco_info_f31 = -1;
static int hf_z21_loco_info_extensions = -1;
static int hf_z21_loco_func_switch_type = -1;
static int hf_z21_loco_func_index = -1;
static int hf_z21_speed_steps = -1;
static int hf_z21_firmware_version = -1;
static int hf_z21_state_emergency_stop = -1;
static int hf_z21_state_track_voltage_off = -1;
static int hf_z21_state_short_circuit = -1;
static int hf_z21_state_programming_mode = -1;
static int hf_z21_state_high_temperature = -1;
static int hf_z21_state_power_lost = -1;
static int hf_z21_state_short_circuit_external = -1;
static int hf_z21_state_short_circuit_internal = -1;
static int hf_z21_state_rcn_213 = -1;
static int hf_z21_capability_dcc = -1;
static int hf_z21_capability_mm = -1;
static int hf_z21_capability_reserved = -1;
static int hf_z21_capability_railcom = -1;
static int hf_z21_capability_loco_cmds = -1;
static int hf_z21_capability_accessory_cmds = -1;
static int hf_z21_capability_detector_cmds = -1;
static int hf_z21_capability_needs_unlock_code = -1;
static int hf_z21_function_address = -1;
static int hf_z21_turnout_state = -1;
static int hf_z21_turnout_activate_bit = -1;
static int hf_z21_turnout_output_bit = -1;
static int hf_z21_turnout_queue_bit = -1;
static int hf_z21_accessory_address = -1;
static int hf_z21_accessory_state = -1;
static int hf_z21_accessory_status = -1;
static int hf_z21_cv_address = -1;
static int hf_z21_cv_value = -1;
static int hf_z21_register = -1;
static int hf_z21_register_value = -1;
static int hf_z21_pom_operation = -1;
static int hf_z21_cv_bit_position = -1;
static int hf_z21_cv_bit_value = -1;
static int hf_z21_rmbus_group = -1;
static int hf_z21_rmbus_feedbacks = -1;
static int hf_z21_rmbus_address = -1;
static int hf_z21_railcom_receive_counter = -1;
static int hf_z21_railcom_error_counter = -1;
static int hf_z21_railcom_reserved1 = -1;
static int hf_z21_railcom_options = -1;
static int hf_z21_railcom_speed = -1;
static int hf_z21_railcom_qos = -1;
static int hf_z21_railcom_reserved2 = -1;
static int hf_z21_railcom_type = -1;
static int hf_z21_loconet_message = -1;
static int hf_z21_loconet_result = -1;
static int hf_z21_loconet_type = -1;
static int hf_z21_loconet_report_address = -1;
static int hf_z21_loconet_feedback_address = -1;
static int hf_z21_loconet_info = -1;
static int hf_z21_can_type = -1;
static int hf_z21_can_network_id = -1;
static int hf_z21_can_module_address = -1;
static int hf_z21_can_port = -1;
static int hf_z21_can_value1 = -1;
static int hf_z21_can_value2 = -1;
static int hf_z21_can_booster_name = -1;
static int hf_z21_can_booster_output_port = -1;
static int hf_z21_can_booster_state = -1;
static int hf_z21_can_booster_state_bg_active = -1;
static int hf_z21_can_booster_state_short_circuit = -1;
static int hf_z21_can_booster_state_track_voltage_off = -1;
static int hf_z21_can_booster_state_railcom_active = -1;
static int hf_z21_can_booster_state_output_disabled = -1;
static int hf_z21_can_booster_vcc = -1;
static int hf_z21_can_booster_current = -1;
static int hf_z21_can_booster_power = -1;
static int hf_z21_zlink_message_type = -1;
static int hf_z21_zlink_hwid = -1;
static int hf_z21_zlink_fw_major = -1;
static int hf_z21_zlink_fw_minor = -1;
static int hf_z21_zlink_fw_build = -1;
static int hf_z21_zlink_mac = -1;
static int hf_z21_zlink_name = -1;
static int hf_z21_zlink_reserved = -1;
static int hf_z21_booster_name = -1;
static int hf_z21_booster_port = -1;
static int hf_z21_booster_port_state = -1;
static int hf_z21_booster_state_data = -1;
static int hf_z21_decoder_name = -1;
static int hf_z21_decoder_state_data = -1;
static int hf_z21_data = -1;
static dissector_handle_t z21_handle;
#define Z21_UDP_PORTS "21105,21106"
static range_t *udp_port_range;
/* Initialize the subtree pointers */
static int ett_z21 = -1;
/* Initialize expert fields */
static expert_field ei_z21_invalid_checksum = EI_INIT;
#define Z21_MIN_LENGTH 4
/* All commands are here defined as big-endian even though the
* specifications are all little-endian. That's fine as we are
* not comparing the values numerically, just matching them
* in the packets. */
#define Z21_LAN_GET_SERIAL_NUMBER 0x1000
#define Z21_LAN_LOGOFF 0x3000
#define Z21_X_BUS 0x4000
#define Z21_LAN_RMBUS_DATACHANGED 0x8000
#define Z21_LAN_RMBUS_GETDATA 0x8100
#define Z21_LAN_RMBUS_PROGRAMMODULE 0x8200
#define Z21_LAN_SYSTEMSTATE_DATACHANGED 0x8400
#define Z21_LAN_RAILCOM_DATACHANGED 0x8800
#define Z21_LAN_RAILCOM_GETDATA 0x8900
#define Z21_LAN_LOCONET_Z21_RX 0xA000
#define Z21_LAN_LOCONET_Z21_TX 0xA100
#define Z21_LAN_LOCONET_FROM_LAN 0xA200
#define Z21_LAN_LOCONET_DISPATCH_ADDR 0xA300
#define Z21_LAN_LOCONET_DETECTOR 0xA400
#define Z21_LAN_BOOSTER_SET_POWER 0xB200
#define Z21_LAN_BOOSTER_GET_DESCRIPTION 0xB800
#define Z21_LAN_BOOSTER_SET_DESCRIPTION 0xB900
#define Z21_LAN_BOOSTER_SYSTEMSTATE_DATACHANGED 0xBA00
#define Z21_LAN_BOOSTER_SYSTEMSTATE_GETDATA 0xBB00
#define Z21_LAN_CAN_DETECTOR 0xC400
#define Z21_LAN_CAN_DEVICE_GET_DESCRIPTION 0xC800
#define Z21_LAN_CAN_DEVICE_SET_DESCRIPTION 0xC900
#define Z21_LAN_CAN_BOOSTER_SYSTEMSTATE_CHGD 0xCA00
#define Z21_LAN_CAN_BOOSTER_SET_TRACKPOWER 0xCB00
#define Z21_LAN_FAST_CLOCK_CONTROL 0xCC00
#define Z21_LAN_FAST_CLOCK_DATA 0xCD00
#define Z21_LAN_FAST_CLOCK_SETTINGS_GET 0xCE00
#define Z21_LAN_FAST_CLOCK_SETTINGS_SET 0xCF00
#define Z21_LAN_DECODER_GET_DESCRIPTION 0xD800
#define Z21_LAN_DECODER_SET_DESCRIPTION 0xD900
#define Z21_LAN_DECODER_SYSTEMSTATE_DATACHANGED 0xDA00
#define Z21_LAN_DECODER_SYSTEMSTATE_GETDATA 0xDB00
#define Z21_LAN_ZLINK_GET_HWINFO 0xE800
/* X-BUS commands are listed as 32-bit big-endian */
#define Z21_LAN_X_GET_VERSION_REQUEST 0x40002121
#define Z21_LAN_X_GET_VERSION_REPLY 0x40006321
#define Z21_LAN_X_GET_STATUS_REQUEST 0x40002124
#define Z21_LAN_X_SET_TRACK_POWER_OFF 0x40002180
#define Z21_LAN_X_SET_TRACK_POWER_ON 0x40002181
#define Z21_LAN_X_DCC_READ_REGISTER 0x40002211
#define Z21_LAN_X_CV_READ 0x40002311
#define Z21_LAN_X_DCC_WRITE_REGISTER 0x40002312
#define Z21_LAN_X_CV_WRITE 0x40002412
#define Z21_LAN_X_MM_WRITE_BYTE 0x400024FF
#define Z21_LAN_X_GET_TURNOUT_INFO 0x400043
#define Z21_LAN_X_TURNOUT_INFO 0x40FF43 /* To be set manually */
#define Z21_LAN_X_GET_EXT_ACCESSORY_INFO 0x400044
#define Z21_LAN_X_EXT_ACCESSORY_INFO 0x40FF44 /* To be set manually */
#define Z21_LAN_X_SET_TURNOUT 0x400053
#define Z21_LAN_X_SET_EXT_ACCESSORY 0x400054
#define Z21_LAN_X_BC_TRACK_POWER_OFF 0x40006100
#define Z21_LAN_X_BC_TRACK_POWER_ON 0x40006101
#define Z21_LAN_X_BC_PROGRAMMING_MODE 0x40006102
#define Z21_LAN_X_BC_TRACK_SHORT_CIRCUIT 0x40006108
#define Z21_LAN_X_CV_NACK_SC 0x40006112
#define Z21_LAN_X_CV_NACK 0x40006113
#define Z21_LAN_X_UNKNOWN_COMMAND 0x40006182
#define Z21_LAN_X_STATUS_CHANGED 0x40006222
#define Z21_LAN_X_CV_RESULT 0x40006414
#define Z21_LAN_X_SET_STOP 0x400080
#define Z21_LAN_X_BC_STOPPED 0x40008100
#define Z21_LAN_X_SET_LOCO_E_STOP 0x400092
#define Z21_LAN_X_PURGE_LOCO 0x4000E344
#define Z21_LAN_X_GET_LOCO_INFO 0x4000E3F0
#define Z21_LAN_X_SET_LOCO_DRIVE_DCC14 0x4000E410
#define Z21_LAN_X_SET_LOCO_DRIVE_DCC28 0x4000E412
#define Z21_LAN_X_SET_LOCO_DRIVE_DCC128 0x4000E413
#define Z21_LAN_X_SET_LOCO_FUNCTION 0x4000E4F8
#define Z21_LAN_X_SET_LOCO_BINARY_STATE 0x4000E55F
#define Z21_LAN_X_CV_POM_COMMANDS 0x4000E630
#define Z21_LAN_X_CV_POM_WRITE_BYTE 0x40FFE630 /* To be set manually */
#define Z21_LAN_X_CV_POM_WRITE_BIT 0x40FEE630 /* To be set manually */
#define Z21_LAN_X_CV_POM_READ_BYTE 0x40FDE630 /* To be set manually */
#define Z21_LAN_X_CV_POM_ACCESSORY_COMMANDS 0x4000E631
#define Z21_LAN_X_CV_POM_ACCESSORY_WRITE_BYTE 0x40FFE631 /* To be set manually */
#define Z21_LAN_X_CV_POM_ACCESSORY_WRITE_BIT 0x40FEE631 /* To be set manually */
#define Z21_LAN_X_CV_POM_ACCESSORY_READ_BYTE 0x40FDE631 /* To be set manually */
#define Z21_LAN_X_LOCO_INFO 0x4000EF
#define Z21_LAN_X_GET_FIRMWARE_VERSION_REQUEST 0x4000F10A
#define Z21_LAN_X_GET_FIRMWARE_VERSION_REPLY 0x4000F30A
static const value_string z21_command_vals[] = {
{ Z21_LAN_CAN_BOOSTER_SET_TRACKPOWER, "LAN_CAN_BOOSTER_SET_TRACKPOWER" },
{ Z21_LAN_CAN_BOOSTER_SYSTEMSTATE_CHGD, "LAN_CAN_BOOSTER_SYSTEMSTATE_CHGD" },
{ Z21_LAN_CAN_DETECTOR, "LAN_CAN_DETECTOR" },
{ Z21_LAN_CAN_DEVICE_GET_DESCRIPTION, "LAN_CAN_DEVICE_GET_DESCRIPTION" },
{ Z21_LAN_CAN_DEVICE_SET_DESCRIPTION, "LAN_CAN_DEVICE_SET_DESCRIPTION" },
{ Z21_LAN_BOOSTER_GET_DESCRIPTION, "LAN_BOOSTER_GET_DESCRIPTION" },
{ Z21_LAN_BOOSTER_SET_DESCRIPTION, "LAN_BOOSTER_SET_DESCRIPTION" },
{ Z21_LAN_BOOSTER_SET_POWER, "LAN_BOOSTER_SET_POWER" },
{ Z21_LAN_BOOSTER_SYSTEMSTATE_DATACHANGED, "LAN_BOOSTER_SYSTEMSTATE_DATACHANGED" },
{ Z21_LAN_BOOSTER_SYSTEMSTATE_GETDATA, "LAN_BOOSTER_SYSTEMSTATE_GETDATA" },
{ Z21_LAN_DECODER_GET_DESCRIPTION, "LAN_DECODER_GET_DESCRIPTION" },
{ Z21_LAN_DECODER_SET_DESCRIPTION, "LAN_DECODER_SET_DESCRIPTION" },
{ Z21_LAN_DECODER_SYSTEMSTATE_DATACHANGED, "LAN_DECODER_SYSTEMSTATE_DATACHANGED" },
{ Z21_LAN_DECODER_SYSTEMSTATE_GETDATA, "LAN_DECODER_SYSTEMSTATE_GETDATA" },
{ Z21_LAN_FAST_CLOCK_CONTROL, "LAN_FAST_CLOCK_CONTROL" },
{ Z21_LAN_FAST_CLOCK_DATA, "LAN_FAST_CLOCK_DATA" },
{ Z21_LAN_FAST_CLOCK_SETTINGS_GET, "LAN_FAST_CLOCK_SETTINGS_GET" },
{ Z21_LAN_FAST_CLOCK_SETTINGS_SET, "LAN_FAST_CLOCK_SETTINGS_SET" },
{ Z21_LAN_GET_SERIAL_NUMBER, "LAN_GET_SERIAL_NUMBER" },
{ Z21_LAN_LOCONET_DETECTOR, "LAN_LOCONET_DETECTOR" },
{ Z21_LAN_LOCONET_DISPATCH_ADDR, "LAN_LOCONET_DISPATCH_ADDR" },
{ Z21_LAN_LOCONET_FROM_LAN, "LAN_LOCONET_FROM_LAN" },
{ Z21_LAN_LOCONET_Z21_RX, "LAN_LOCONET_Z21_RX" },
{ Z21_LAN_LOCONET_Z21_TX, "LAN_LOCONET_Z21_TX" },
{ Z21_LAN_LOGOFF, "LAN_LOGOFF" },
{ Z21_LAN_RAILCOM_GETDATA, "LAN_RAILCOM_GETDATA" },
{ Z21_LAN_RAILCOM_DATACHANGED, "LAN_RAILCOM_DATACHANGED" },
{ Z21_LAN_RMBUS_DATACHANGED, "LAN_RMBUS_DATACHANGED" },
{ Z21_LAN_RMBUS_GETDATA, "LAN_RMBUS_GETDATA" },
{ Z21_LAN_RMBUS_PROGRAMMODULE, "LAN_RMBUS_PROGRAMMODULE" },
{ Z21_LAN_SYSTEMSTATE_DATACHANGED, "LAN_SYSTEMSTATE_DATACHANGED" },
{ Z21_LAN_X_BC_PROGRAMMING_MODE, "LAN_X_BC_PROGRAMMING_MODE" },
{ Z21_LAN_X_BC_STOPPED, "LAN_X_BC_STOPPED" },
{ Z21_LAN_X_BC_TRACK_POWER_OFF, "LAN_X_BC_TRACK_POWER_OFF" },
{ Z21_LAN_X_BC_TRACK_POWER_ON, "LAN_X_BC_TRACK_POWER_ON" },
{ Z21_LAN_X_BC_TRACK_SHORT_CIRCUIT, "LAN_X_BC_TRACK_SHORT_CIRCUIT" },
{ Z21_LAN_X_CV_NACK, "LAN_X_CV_NACK" },
{ Z21_LAN_X_CV_NACK_SC, "LAN_X_CV_NACK_SC" },
{ Z21_LAN_X_CV_POM_ACCESSORY_READ_BYTE, "LAN_X_CV_POM_ACCESSORY_READ_BYTE" },
{ Z21_LAN_X_CV_POM_ACCESSORY_WRITE_BIT, "LAN_X_CV_POM_ACCESSORY_WRITE_BIT" },
{ Z21_LAN_X_CV_POM_ACCESSORY_WRITE_BYTE, "LAN_X_CV_POM_ACCESSORY_WRITE_BYTE" },
{ Z21_LAN_X_CV_POM_READ_BYTE, "LAN_X_CV_POM_READ_BYTE" },
{ Z21_LAN_X_CV_POM_WRITE_BIT, "LAN_X_CV_POM_WRITE_BIT" },
{ Z21_LAN_X_CV_POM_WRITE_BYTE, "LAN_X_CV_POM_WRITE_BYTE" },
{ Z21_LAN_X_CV_READ, "LAN_X_CV_READ" },
{ Z21_LAN_X_CV_RESULT, "LAN_X_CV_RESULT" },
{ Z21_LAN_X_CV_WRITE, "LAN_X_CV_WRITE" },
{ Z21_LAN_X_DCC_READ_REGISTER, "LAN_X_DCC_READ_REGISTER" },
{ Z21_LAN_X_DCC_WRITE_REGISTER, "LAN_X_DCC_WRITE_REGISTER" },
{ Z21_LAN_X_EXT_ACCESSORY_INFO, "LAN_X_EXT_ACCESSORY_INFO" },
{ Z21_LAN_X_GET_EXT_ACCESSORY_INFO, "LAN_X_GET_EXT_ACCESSORY_INFO" },
{ Z21_LAN_X_GET_FIRMWARE_VERSION_REQUEST, "LAN_X_GET_FIRMWARE_VERSION" },
{ Z21_LAN_X_GET_FIRMWARE_VERSION_REPLY, "LAN_X_GET_FIRMWARE_VERSION" },
{ Z21_LAN_X_GET_LOCO_INFO, "LAN_X_GET_LOCO_INFO" },
{ Z21_LAN_X_GET_TURNOUT_INFO, "LAN_X_GET_TURNOUT_INFO" },
{ Z21_LAN_X_GET_VERSION_REQUEST, "LAN_X_GET_VERSION" },
{ Z21_LAN_X_GET_VERSION_REPLY, "LAN_X_GET_VERSION" },
{ Z21_LAN_X_GET_STATUS_REQUEST, "LAN_X_GET_STATUS" },
{ Z21_LAN_X_LOCO_INFO, "LAN_X_LOCO_INFO" },
{ Z21_LAN_X_MM_WRITE_BYTE, "LAN_X_MM_WRITE_BYTE" },
{ Z21_LAN_X_PURGE_LOCO, "LAN_X_PURGE_LOCO" },
{ Z21_LAN_X_SET_EXT_ACCESSORY, "LAN_X_SET_EXT_ACCESSORY" },
{ Z21_LAN_X_SET_LOCO_BINARY_STATE, "LAN_X_SET_LOCO_BINARY_STATE" },
{ Z21_LAN_X_SET_LOCO_DRIVE_DCC14, "LAN_X_SET_LOCO_DRIVE" },
{ Z21_LAN_X_SET_LOCO_DRIVE_DCC28, "LAN_X_SET_LOCO_DRIVE" },
{ Z21_LAN_X_SET_LOCO_DRIVE_DCC128, "LAN_X_SET_LOCO_DRIVE" },
{ Z21_LAN_X_SET_LOCO_E_STOP, "LAN_X_SET_LOCO_E_STOP" },
{ Z21_LAN_X_SET_LOCO_FUNCTION, "LAN_X_SET_LOCO_FUNCTION" },
{ Z21_LAN_X_SET_STOP, "LAN_X_SET_STOP" },
{ Z21_LAN_X_SET_TRACK_POWER_OFF, "LAN_X_SET_TRACK_POWER_OFF" },
{ Z21_LAN_X_SET_TRACK_POWER_ON, "LAN_X_SET_TRACK_POWER_ON" },
{ Z21_LAN_X_SET_TURNOUT, "LAN_X_SET_TURNOUT" },
{ Z21_LAN_X_STATUS_CHANGED, "LAN_X_STATUS_CHANGED" },
{ Z21_LAN_X_TURNOUT_INFO, "LAN_X_TURNOUT_INFO" },
{ Z21_LAN_X_UNKNOWN_COMMAND, "LAN_X_UNKNOWN_COMMAND" },
{ Z21_LAN_ZLINK_GET_HWINFO, "LAN_ZLINK_GET_HWINFO" },
{ 0, NULL },
};
static const value_string z21_loco_info_speed_steps_vals[] = {
{ 0, "14 speed steps" },
{ 2, "28 speed steps" },
{ 4, "128 speed steps" },
{ 0, NULL },
};
static const value_string z21_loco_func_vals[] = {
{ 0, "Off" },
{ 1, "On" },
{ 2, "Toggle" },
{ 3, "Not allowed" },
{ 0, NULL },
};
static const value_string z21_turnout_state_vals[] = {
{ 0, "Not switched yet" },
{ 1, "Turnout is in position \"P=0\"" },
{ 2, "Turnout is in position \"P=1\"" },
{ 3, "Invalid combination" },
{ 0, NULL },
};
static const value_string z21_pom_operation_vals[] = {
{ 0x39, "Read byte" }, /* 111001 */
{ 0x3a, "Write bit" }, /* 111010 */
{ 0x3b, "Write byte" }, /* 111011 */
{ 0, NULL },
};
static const value_string z21_zlink_message_type_vals[] = {
{ 0x06, "ZLINK_MSG_TYPE_HW_INFO" },
{ 0, NULL },
};
static const true_false_string tfs_forward_reverse = { "Forward", "Reverse" };
static const true_false_string tfs_turnout_command = { "Activate", "Deactivate" };
static const true_false_string tfs_turnout_output = { "Output 2", "Output 1" };
static void
update_command_field(proto_item *ti, unsigned command)
{
int width = 8;
if (command <= 0xff)
width = 2;
else if (command <= 0xffff)
width = 4;
else if (command <= 0xffffff)
width = 6;
proto_item_append_text(ti, ": %s (0x%0*x)",
val_to_str_const(command, z21_command_vals, "unknown"),
width, command);
}
/* Code to actually dissect the packets */
static int
dissect_z21_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
{
proto_item *ti, *temp_ti, *command_ti;
proto_tree *z21_tree;
unsigned offset = 0, datalen, command;
unsigned checksum, calculated_checksum, one_byte, version, temp_uint;
unsigned address_bytes, addr, speed_steps = 0, cv_addr;
guint64 status, direction_and_speed, temp_guint64;
gint32 main_current, temp_gint32;
char *buffer;
float temp_float;
static int * const state_bits_byte1[] = {
&hf_z21_state_programming_mode,
&hf_z21_state_short_circuit,
&hf_z21_state_track_voltage_off,
&hf_z21_state_emergency_stop,
NULL
};
static int * const state_bits_byte2[] = {
&hf_z21_state_rcn_213,
&hf_z21_state_short_circuit_internal,
&hf_z21_state_short_circuit_external,
&hf_z21_state_power_lost,
&hf_z21_state_high_temperature,
NULL
};
static int * const capability_bits[] = {
&hf_z21_capability_needs_unlock_code,
&hf_z21_capability_detector_cmds,
&hf_z21_capability_accessory_cmds,
&hf_z21_capability_loco_cmds,
&hf_z21_capability_railcom,
&hf_z21_capability_reserved,
&hf_z21_capability_mm,
&hf_z21_capability_dcc,
NULL
};
static int * const speed_bits[] = {
&hf_z21_loco_direction,
&hf_z21_loco_speed,
NULL
};
static int * const loco_info_bits1[] = {
&hf_z21_loco_info_mm,
&hf_z21_loco_info_busy,
&hf_z21_loco_info_speed_steps,
NULL
};
static int * const loco_info_bits2[] = {
&hf_z21_loco_info_direction,
&hf_z21_loco_info_speed,
NULL
};
static int * const loco_info_bits3[] = {
&hf_z21_loco_info_double_traction,
&hf_z21_loco_info_smartsearch,
&hf_z21_loco_info_f0,
&hf_z21_loco_info_f4,
&hf_z21_loco_info_f3,
&hf_z21_loco_info_f2,
&hf_z21_loco_info_f1,
NULL
};
static int * const loco_info_bits4[] = {
&hf_z21_loco_info_f12,
&hf_z21_loco_info_f11,
&hf_z21_loco_info_f10,
&hf_z21_loco_info_f9,
&hf_z21_loco_info_f8,
&hf_z21_loco_info_f7,
&hf_z21_loco_info_f6,
&hf_z21_loco_info_f5,
NULL
};
static int * const loco_info_bits5[] = {
&hf_z21_loco_info_f20,
&hf_z21_loco_info_f19,
&hf_z21_loco_info_f18,
&hf_z21_loco_info_f17,
&hf_z21_loco_info_f16,
&hf_z21_loco_info_f15,
&hf_z21_loco_info_f14,
&hf_z21_loco_info_f13,
NULL
};
static int * const loco_info_bits6[] = {
&hf_z21_loco_info_f28,
&hf_z21_loco_info_f27,
&hf_z21_loco_info_f26,
&hf_z21_loco_info_f25,
&hf_z21_loco_info_f24,
&hf_z21_loco_info_f23,
&hf_z21_loco_info_f22,
&hf_z21_loco_info_f21,
NULL
};
static int * const loco_info_bits7[] = {
&hf_z21_loco_info_f31,
&hf_z21_loco_info_f30,
&hf_z21_loco_info_f29,
NULL
};
static int * const loco_func_bits[] = {
&hf_z21_loco_func_switch_type,
&hf_z21_loco_func_index,
NULL
};
static int * const turnout_state_bits[] = {
&hf_z21_turnout_state,
NULL
};
static int * const turnout_set_bits[] = {
&hf_z21_turnout_queue_bit,
&hf_z21_turnout_activate_bit,
&hf_z21_turnout_output_bit,
NULL
};
static int * const cv_bits[] = {
&hf_z21_cv_bit_value,
&hf_z21_cv_bit_position,
NULL
};
static int * const booster_state_bits[] = {
&hf_z21_can_booster_state_railcom_active,
&hf_z21_can_booster_state_output_disabled,
&hf_z21_can_booster_state_track_voltage_off,
&hf_z21_can_booster_state_short_circuit,
&hf_z21_can_booster_state_bg_active,
NULL
};
/* Check that the packet is long enough for it to belong to us. */
if (tvb_reported_length(tvb) < Z21_MIN_LENGTH)
return 0;
col_set_str(pinfo->cinfo, COL_PROTOCOL, "Z21");
ti = proto_tree_add_item(tree, proto_z21, tvb, 0, -1, ENC_NA);
z21_tree = proto_item_add_subtree(ti, ett_z21);
proto_tree_add_item_ret_uint(z21_tree, hf_z21_datalen,
tvb, offset, 2, ENC_LITTLE_ENDIAN, &datalen);
offset += 2;
command = tvb_get_guint16(tvb, offset, ENC_BIG_ENDIAN);
if (command == Z21_X_BUS) {
proto_tree_add_boolean(z21_tree, hf_z21_x_bus, tvb, offset, 2, true);
/* Note that we do not increment the offset yet */
/* Strategy:
* 1. Read two bytes of the data (as big-endian)
* 2. Prepend it with 0x4000 (the header bytes for X-BUS)
* 3. If the three MSBs are one of the "one-byte commands",
* set x_bus_command accordingly and run with that
* 4. Otherwise run with "two-byte commands"...
* 5. ... except that there are some commands that need more data to
* determine the exact command (as their two "command bytes" are the
* same), so check for those and set x_bus_command manually for them.
*/
temp_uint = 0x40000000 + tvb_get_guint16(tvb, offset+2, ENC_BIG_ENDIAN);
unsigned x_bus_command = temp_uint >> 8;
/* Check for all the "one-byte" commands */
if (x_bus_command == Z21_LAN_X_SET_STOP ||
x_bus_command == Z21_LAN_X_SET_LOCO_E_STOP ||
x_bus_command == Z21_LAN_X_GET_EXT_ACCESSORY_INFO ||
x_bus_command == Z21_LAN_X_SET_EXT_ACCESSORY ||
x_bus_command == Z21_LAN_X_GET_TURNOUT_INFO ||
x_bus_command == Z21_LAN_X_SET_TURNOUT ||
x_bus_command == Z21_LAN_X_LOCO_INFO) {
/* Initialize the checksum without the 0x4000 prefix */
calculated_checksum = x_bus_command & 0xff;
/* Check for these that are actually another command */
if (x_bus_command == Z21_LAN_X_GET_TURNOUT_INFO && datalen == 9) {
x_bus_command = Z21_LAN_X_TURNOUT_INFO;
} else if (x_bus_command == Z21_LAN_X_GET_EXT_ACCESSORY_INFO && datalen == 10) {
x_bus_command = Z21_LAN_X_EXT_ACCESSORY_INFO;
}
command_ti = proto_tree_add_uint(z21_tree, hf_z21_command, tvb, offset, 3, x_bus_command);
offset += 3;
}
else {
/* First assume "two-byte command", then check for exceptions */
x_bus_command = temp_uint;
if (x_bus_command == Z21_LAN_X_CV_POM_COMMANDS ||
x_bus_command == Z21_LAN_X_CV_POM_ACCESSORY_COMMANDS) {
/* Read DB3 from data, get the two interesting bits */
temp_uint = tvb_get_guint8(tvb, offset + 6) >> 2 & 0x3;
switch (x_bus_command) {
case Z21_LAN_X_CV_POM_COMMANDS:
if (temp_uint == 0x1)
x_bus_command = Z21_LAN_X_CV_POM_READ_BYTE;
else if (temp_uint == 0x2)
x_bus_command = Z21_LAN_X_CV_POM_WRITE_BIT;
else if (temp_uint == 0x3)
x_bus_command = Z21_LAN_X_CV_POM_WRITE_BYTE;
break;
case Z21_LAN_X_CV_POM_ACCESSORY_COMMANDS:
if (temp_uint == 0x1)
x_bus_command = Z21_LAN_X_CV_POM_ACCESSORY_READ_BYTE;
else if (temp_uint == 0x2)
x_bus_command = Z21_LAN_X_CV_POM_ACCESSORY_WRITE_BIT;
else if (temp_uint == 0x3)
x_bus_command = Z21_LAN_X_CV_POM_ACCESSORY_WRITE_BYTE;
break;
}
}
command_ti = proto_tree_add_uint(z21_tree, hf_z21_command,
tvb, offset, 4, x_bus_command);
offset += 4;
/* Initialize the checksum with the two LSBs */
calculated_checksum = ((x_bus_command & 0xff00) >> 8) ^ (x_bus_command & 0x00ff);
}
update_command_field(command_ti, x_bus_command);
col_add_fstr(pinfo->cinfo, COL_INFO, "Command=%s",
val_to_str_const(x_bus_command, z21_command_vals, "unknown"));
proto_item_append_text(z21_tree, ", Command: %s",
val_to_str_const(x_bus_command, z21_command_vals, "unknown"));
switch (x_bus_command) {
case Z21_LAN_X_STATUS_CHANGED:
proto_tree_add_bitmask_ret_uint64(z21_tree, tvb, offset, hf_z21_status,
ett_z21, state_bits_byte1, ENC_NA, &status);
offset += 1;
calculated_checksum ^= (unsigned)status;
break;
case Z21_LAN_X_SET_LOCO_DRIVE_DCC14:
case Z21_LAN_X_SET_LOCO_DRIVE_DCC28:
case Z21_LAN_X_SET_LOCO_DRIVE_DCC128:
address_bytes = tvb_get_guint16(tvb, offset, ENC_BIG_ENDIAN);
addr = address_bytes & 0x3FFF;
proto_tree_add_uint(z21_tree, hf_z21_loco_address, tvb, offset, 2, addr);
switch (x_bus_command) {
case Z21_LAN_X_SET_LOCO_DRIVE_DCC14: speed_steps = 14; break;
case Z21_LAN_X_SET_LOCO_DRIVE_DCC28: speed_steps = 28; break;
case Z21_LAN_X_SET_LOCO_DRIVE_DCC128: speed_steps = 128; break;
}
proto_tree_add_uint(z21_tree, hf_z21_speed_steps, tvb, offset-1, 1, speed_steps);
offset += 2;
calculated_checksum ^= address_bytes >> 8;
calculated_checksum ^= address_bytes & 0xFF;
col_append_fstr(pinfo->cinfo, COL_INFO, ", Loco=%d (%d SS)",
addr, speed_steps);
temp_ti = proto_tree_add_bitmask_ret_uint64(z21_tree, tvb, offset, hf_z21_loco_direction_and_speed,
ett_z21, speed_bits, ENC_NA, &direction_and_speed);
offset += 1;
calculated_checksum ^= (unsigned)direction_and_speed;
if (direction_and_speed & 0x80) {
proto_item_set_text(temp_ti,
"Locomotive direction and speed: Forward, 0x%02" PRIx64,
direction_and_speed & 0x7F);
col_append_fstr(pinfo->cinfo, COL_INFO, ", Forward");
}
else {
proto_item_set_text(temp_ti,
"Locomotive direction and speed: Reverse, 0x%02" PRIx64,
direction_and_speed & 0x7F);
col_append_fstr(pinfo->cinfo, COL_INFO, ", Reverse");
}
col_append_fstr(pinfo->cinfo, COL_INFO, ", Speed=0x%02" PRIx64,
direction_and_speed & 0x7F);
break;
case Z21_LAN_X_GET_LOCO_INFO:
address_bytes = tvb_get_guint16(tvb, offset, ENC_BIG_ENDIAN);
addr = address_bytes & 0x3FFF;
proto_tree_add_uint(z21_tree, hf_z21_loco_address, tvb, offset, 2, addr);
offset += 2;
calculated_checksum ^= address_bytes >> 8;
calculated_checksum ^= address_bytes & 0xFF;
col_append_fstr(pinfo->cinfo, COL_INFO, ", Loco=%d", addr);
break;
case Z21_LAN_X_LOCO_INFO:
address_bytes = tvb_get_guint16(tvb, offset, ENC_BIG_ENDIAN);
addr = address_bytes & 0x3FFF;
proto_tree_add_uint(z21_tree, hf_z21_loco_address, tvb, offset, 2, addr);
offset += 2;
calculated_checksum ^= address_bytes >> 8;
calculated_checksum ^= address_bytes & 0xFF;
col_append_fstr(pinfo->cinfo, COL_INFO, ", Loco=%d", addr);
proto_item_append_text(z21_tree, ", Loco: %d", addr);
proto_tree_add_bitmask_list_ret_uint64(z21_tree, tvb, offset, 1,
loco_info_bits1, ENC_NA, &temp_guint64);
offset += 1;
calculated_checksum ^= temp_guint64;
col_append_fstr(pinfo->cinfo, COL_INFO, " (%s)",
val_to_str_const((guint32)temp_guint64 & 0x07,
z21_loco_info_speed_steps_vals, "unknown"));
proto_tree_add_bitmask_list_ret_uint64(z21_tree, tvb, offset, 1,
loco_info_bits2, ENC_NA, &temp_guint64);
offset += 1;
calculated_checksum ^= temp_guint64;
col_append_fstr(pinfo->cinfo, COL_INFO, ", %s",
tfs_get_string((gboolean)temp_guint64 >> 7, &tfs_forward_reverse));
col_append_fstr(pinfo->cinfo, COL_INFO, ", Speed=0x%02" PRIx64,
temp_guint64 & 0x7f);
proto_tree_add_bitmask_list_ret_uint64(z21_tree, tvb, offset, 1,
loco_info_bits3, ENC_NA, &temp_guint64);
offset += 1;
calculated_checksum ^= temp_guint64;
if (temp_guint64 & 0x40) {
col_append_str(pinfo->cinfo, COL_INFO, ", in double traction");
}
proto_tree_add_bitmask_list_ret_uint64(z21_tree, tvb, offset, 1,
loco_info_bits4, ENC_NA, &temp_guint64);
offset += 1;
calculated_checksum ^= temp_guint64;
proto_tree_add_bitmask_list_ret_uint64(z21_tree, tvb, offset, 1,
loco_info_bits5, ENC_NA, &temp_guint64);
offset += 1;
calculated_checksum ^= temp_guint64;
/* The following bytes are not always there it seems */
if (offset < datalen-1) {
proto_tree_add_bitmask_list_ret_uint64(z21_tree, tvb, offset, 1,
loco_info_bits6, ENC_NA, &temp_guint64);
offset += 1;
calculated_checksum ^= temp_guint64;
}
if (offset < datalen-1) {
proto_tree_add_bitmask_list_ret_uint64(z21_tree, tvb, offset, 1,
loco_info_bits7, ENC_NA, &temp_guint64);
offset += 1;
calculated_checksum ^= temp_guint64;
}
/* If still something, dissect as bytes */
if (offset < datalen-1) {
proto_tree_add_item(z21_tree, hf_z21_loco_info_extensions,
tvb, offset, datalen-1-offset, ENC_NA);
/* Note: Do not increment offset because the checksum
* will be calculated below! */
}
break;
case Z21_LAN_X_PURGE_LOCO:
address_bytes = tvb_get_guint16(tvb, offset, ENC_BIG_ENDIAN);
addr = address_bytes & 0x3FFF;
proto_tree_add_uint(z21_tree, hf_z21_loco_address, tvb, offset, 2, addr);
offset += 2;
calculated_checksum ^= address_bytes >> 8;
calculated_checksum ^= address_bytes & 0xFF;
col_append_fstr(pinfo->cinfo, COL_INFO, ", Loco=%d", addr);
proto_item_append_text(z21_tree, ", Loco: %d", addr);
break;
case Z21_LAN_X_SET_LOCO_E_STOP:
address_bytes = tvb_get_guint16(tvb, offset, ENC_BIG_ENDIAN);
addr = address_bytes & 0x3FFF;
proto_tree_add_uint(z21_tree, hf_z21_loco_address, tvb, offset, 2, addr);
offset += 2;
calculated_checksum ^= address_bytes >> 8;
calculated_checksum ^= address_bytes & 0xFF;
col_append_fstr(pinfo->cinfo, COL_INFO, ", Loco=%d", addr);
proto_item_append_text(z21_tree, ", Loco: %d", addr);
break;
case Z21_LAN_X_SET_LOCO_BINARY_STATE:
col_append_str(pinfo->cinfo, COL_INFO, ", TO BE COMPLETED");
break;
case Z21_LAN_X_SET_LOCO_FUNCTION:
address_bytes = tvb_get_guint16(tvb, offset, ENC_BIG_ENDIAN);
addr = address_bytes & 0x3FFF;
proto_tree_add_uint(z21_tree, hf_z21_loco_address, tvb, offset, 2, addr);
offset += 2;
calculated_checksum ^= address_bytes >> 8;
calculated_checksum ^= address_bytes & 0xFF;
col_append_fstr(pinfo->cinfo, COL_INFO, ", Loco=%d", addr);
proto_item_append_text(z21_tree, ", Loco: %d", addr);
proto_tree_add_bitmask_list_ret_uint64(z21_tree, tvb, offset, 1,
loco_func_bits, ENC_NA, &temp_guint64);
offset += 1;
calculated_checksum ^= temp_guint64;
col_append_fstr(pinfo->cinfo, COL_INFO, ", Function=%" PRIu64 ", State=%s",
temp_guint64 & 0x3f,
val_to_str_const((guint32)temp_guint64 >> 6, z21_loco_func_vals, "unknown"));
proto_item_append_text(z21_tree, ", Function: %" PRIu64 ", State: %s",
temp_guint64 & 0x3f,
val_to_str_const((guint32)temp_guint64 >> 6, z21_loco_func_vals, "unknown"));
break;
case Z21_LAN_X_GET_TURNOUT_INFO:
addr = tvb_get_guint16(tvb, offset, ENC_BIG_ENDIAN);
proto_tree_add_uint(z21_tree, hf_z21_function_address,
tvb, offset, 2, addr);
offset += 2;
calculated_checksum ^= addr >> 8;
calculated_checksum ^= addr & 0xFF;
col_append_fstr(pinfo->cinfo, COL_INFO, ", Function=%d", addr);
proto_item_append_text(z21_tree, ", Function: %d", addr);
break;
case Z21_LAN_X_TURNOUT_INFO:
addr = tvb_get_guint16(tvb, offset, ENC_BIG_ENDIAN);
proto_tree_add_uint(z21_tree, hf_z21_function_address,
tvb, offset, 2, addr);
offset += 2;
calculated_checksum ^= addr >> 8;
calculated_checksum ^= addr & 0xFF;
proto_tree_add_bitmask_list_ret_uint64(z21_tree, tvb, offset, 1,
turnout_state_bits, ENC_NA, &temp_guint64);
offset += 1;
calculated_checksum ^= temp_guint64;
col_append_fstr(pinfo->cinfo, COL_INFO, ", Address=%d, State=%s",
addr,
val_to_str_const((guint32)temp_guint64 & 0x03, z21_turnout_state_vals, "unknown"));
proto_item_append_text(z21_tree, ", Address: %d, State: %s",
addr,
val_to_str_const((guint32)temp_guint64 & 0x03, z21_turnout_state_vals, "unknown"));
break;
case Z21_LAN_X_SET_TURNOUT:
addr = tvb_get_guint16(tvb, offset, ENC_BIG_ENDIAN);
proto_tree_add_uint(z21_tree, hf_z21_function_address,
tvb, offset, 2, addr);
offset += 2;
calculated_checksum ^= addr >> 8;
calculated_checksum ^= addr & 0xFF;
col_append_fstr(pinfo->cinfo, COL_INFO, ", Address=%d", addr);
proto_item_append_text(z21_tree, ", Address: %d", addr);
proto_tree_add_bitmask_list_ret_uint64(z21_tree, tvb, offset, 1,
turnout_set_bits, ENC_NA, &temp_guint64);
offset += 1;
calculated_checksum ^= temp_guint64;
col_append_fstr(pinfo->cinfo, COL_INFO, ", Address=%d, %s, Output=%s",
addr,
tfs_get_string((gboolean)temp_guint64 & 0x08, &tfs_turnout_command),
tfs_get_string((gboolean)temp_guint64 & 0x01, &tfs_turnout_output));
proto_item_append_text(z21_tree, ", Address: %d, %s, Output: %s",
addr,
tfs_get_string((gboolean)temp_guint64 & 0x08, &tfs_turnout_command),
tfs_get_string((gboolean)temp_guint64 & 0x01, &tfs_turnout_output));
break;
case Z21_LAN_X_GET_EXT_ACCESSORY_INFO:
addr = tvb_get_guint16(tvb, offset, ENC_BIG_ENDIAN);
proto_tree_add_uint(z21_tree, hf_z21_accessory_address,
tvb, offset, 2, addr);
offset += 2;
calculated_checksum ^= addr >> 8;
calculated_checksum ^= addr & 0xFF;
col_append_fstr(pinfo->cinfo, COL_INFO, ", Address=%d", addr);
proto_item_append_text(z21_tree, ", Address: %d", addr);
break;
case Z21_LAN_X_EXT_ACCESSORY_INFO:
addr = tvb_get_guint16(tvb, offset, ENC_BIG_ENDIAN);
proto_tree_add_uint(z21_tree, hf_z21_accessory_address,
tvb, offset, 2, addr);
offset += 2;
calculated_checksum ^= addr >> 8;
calculated_checksum ^= addr & 0xFF;
temp_uint = tvb_get_guint16(tvb, offset, ENC_BIG_ENDIAN);
proto_tree_add_uint(z21_tree, hf_z21_accessory_state,
tvb, offset, 1, temp_uint >> 8);
offset += 1;
calculated_checksum ^= temp_uint >> 8;
proto_tree_add_uint(z21_tree, hf_z21_accessory_status,
tvb, offset, 1, temp_uint & 0xff);
offset += 1;
calculated_checksum ^= temp_uint & 0xff;
col_append_fstr(pinfo->cinfo, COL_INFO, ", Address=%d, State=%d, Status=0x%02x",
addr, temp_uint >> 8, temp_uint & 0xff);
proto_item_append_text(z21_tree, ", Address: %d, State: %d, Status: 0x%02x",
addr, temp_uint >> 8, temp_uint & 0xff);
break;
case Z21_LAN_X_SET_EXT_ACCESSORY:
addr = tvb_get_guint16(tvb, offset, ENC_BIG_ENDIAN);
proto_tree_add_uint(z21_tree, hf_z21_accessory_address,
tvb, offset, 2, addr);
offset += 2;
calculated_checksum ^= addr >> 8;
calculated_checksum ^= addr & 0xFF;
temp_uint = tvb_get_guint8(tvb, offset);
proto_tree_add_uint(z21_tree, hf_z21_accessory_state,
tvb, offset, 1, temp_uint);
offset += 1;
calculated_checksum ^= temp_uint;
col_append_fstr(pinfo->cinfo, COL_INFO, ", Address=%d, State=%d",
addr, temp_uint);
proto_item_append_text(z21_tree, ", Address: %d, State: %d",
addr, temp_uint);
break;
case Z21_LAN_X_CV_READ:
cv_addr = tvb_get_guint16(tvb, offset, ENC_BIG_ENDIAN);
/* CV addresses are 1-based, update checksum first */
calculated_checksum ^= cv_addr >> 8;
calculated_checksum ^= cv_addr & 0xFF;
cv_addr += 1;
proto_tree_add_uint(z21_tree, hf_z21_cv_address,
tvb, offset, 2, cv_addr);
offset += 2;
col_append_fstr(pinfo->cinfo, COL_INFO, ", CV%d", cv_addr);
proto_item_append_text(z21_tree, ", CV%d", cv_addr);
break;
case Z21_LAN_X_CV_WRITE:
cv_addr = tvb_get_guint16(tvb, offset, ENC_BIG_ENDIAN);
/* CV addresses are 1-based, update checksum first */
calculated_checksum ^= cv_addr >> 8;
calculated_checksum ^= cv_addr & 0xFF;
cv_addr += 1;
proto_tree_add_uint(z21_tree, hf_z21_cv_address,
tvb, offset, 2, cv_addr);
offset += 2;
temp_uint = tvb_get_guint8(tvb, offset);
proto_tree_add_uint(z21_tree, hf_z21_cv_value,
tvb, offset, 1, temp_uint);
offset += 1;
calculated_checksum ^= temp_uint;
col_append_fstr(pinfo->cinfo, COL_INFO, ", CV%d, Value=%d",
cv_addr, temp_uint);
proto_item_append_text(z21_tree, ", CV%d, Value: %d",
cv_addr, temp_uint);
break;
case Z21_LAN_X_CV_RESULT:
cv_addr = tvb_get_guint16(tvb, offset, ENC_BIG_ENDIAN);
/* CV addresses are 1-based, update checksum first */
calculated_checksum ^= cv_addr >> 8;
calculated_checksum ^= cv_addr & 0xFF;
cv_addr += 1;
proto_tree_add_uint(z21_tree, hf_z21_cv_address,
tvb, offset, 2, cv_addr);
offset += 2;
temp_uint = tvb_get_guint8(tvb, offset);
proto_tree_add_uint(z21_tree, hf_z21_cv_value,
tvb, offset, 1, temp_uint);
offset += 1;
calculated_checksum ^= temp_uint;
col_append_fstr(pinfo->cinfo, COL_INFO, ", CV%d, Value=%d",
cv_addr, temp_uint);
proto_item_append_text(z21_tree, ", CV%d, Value: %d",
cv_addr, temp_uint);
break;
case Z21_LAN_X_CV_POM_WRITE_BYTE:
address_bytes = tvb_get_guint16(tvb, offset, ENC_BIG_ENDIAN);
addr = address_bytes & 0x3FFF;
proto_tree_add_uint(z21_tree, hf_z21_loco_address, tvb, offset, 2, addr);
offset += 2;
calculated_checksum ^= address_bytes >> 8;
calculated_checksum ^= address_bytes & 0xFF;
temp_uint = tvb_get_guint16(tvb, offset, ENC_BIG_ENDIAN);
calculated_checksum ^= temp_uint >> 8;
calculated_checksum ^= temp_uint & 0xff;
proto_tree_add_uint(z21_tree, hf_z21_pom_operation,
tvb, offset, 1, temp_uint >> 2);
cv_addr = (temp_uint & 0x03ff) + 1;
proto_tree_add_uint(z21_tree, hf_z21_cv_address,
tvb, offset, 2, cv_addr);
offset += 2;
proto_tree_add_item_ret_uint(z21_tree, hf_z21_cv_value,
tvb, offset, 1, ENC_NA, &temp_uint);
offset += 1;
calculated_checksum ^= temp_uint;
col_append_fstr(pinfo->cinfo, COL_INFO, ", Loco=%d, CV%d, Value=%d",
addr, cv_addr, temp_uint);
proto_item_append_text(z21_tree, ", Loco: %d, CV%d, Value: %d",
addr, cv_addr, temp_uint);
break;
case Z21_LAN_X_CV_POM_WRITE_BIT:
address_bytes = tvb_get_guint16(tvb, offset, ENC_BIG_ENDIAN);
addr = address_bytes & 0x3FFF;
proto_tree_add_uint(z21_tree, hf_z21_loco_address, tvb, offset, 2, addr);
offset += 2;
calculated_checksum ^= address_bytes >> 8;
calculated_checksum ^= address_bytes & 0xFF;
temp_uint = tvb_get_guint16(tvb, offset, ENC_BIG_ENDIAN);
calculated_checksum ^= temp_uint >> 8;
calculated_checksum ^= temp_uint & 0xff;
proto_tree_add_uint(z21_tree, hf_z21_pom_operation,
tvb, offset, 1, temp_uint >> 2);
cv_addr = (temp_uint & 0x03ff) + 1;
proto_tree_add_uint(z21_tree, hf_z21_cv_address,
tvb, offset, 2, cv_addr);
offset += 2;
proto_tree_add_bitmask_list_ret_uint64(z21_tree, tvb, offset, 1,
cv_bits, ENC_NA, &temp_guint64);
offset += 1;
calculated_checksum ^= (unsigned)temp_guint64;
col_append_fstr(pinfo->cinfo, COL_INFO, ", Loco=%d, CV%d, Bit position=%" PRIu64 ", Value=%" PRIu64,
addr, cv_addr, temp_guint64 & 0x07, temp_guint64 >> 3 & 0x01);
proto_item_append_text(z21_tree, ", Loco: %d, CV%d, Bit position: %" PRIu64 ", Value: %" PRIu64,
addr, cv_addr, temp_guint64 & 0x07, temp_guint64 >> 3 & 0x01);
break;
case Z21_LAN_X_CV_POM_READ_BYTE:
address_bytes = tvb_get_guint16(tvb, offset, ENC_BIG_ENDIAN);
addr = address_bytes & 0x3FFF;
proto_tree_add_uint(z21_tree, hf_z21_loco_address, tvb, offset, 2, addr);
offset += 2;
calculated_checksum ^= address_bytes >> 8;
calculated_checksum ^= address_bytes & 0xFF;
temp_uint = tvb_get_guint16(tvb, offset, ENC_BIG_ENDIAN);
calculated_checksum ^= temp_uint >> 8;
calculated_checksum ^= temp_uint & 0xff;
proto_tree_add_uint(z21_tree, hf_z21_pom_operation,
tvb, offset, 1, temp_uint >> 2);
cv_addr = (temp_uint & 0x03ff) + 1;
proto_tree_add_uint(z21_tree, hf_z21_cv_address,
tvb, offset, 2, cv_addr);
offset += 2;
col_append_fstr(pinfo->cinfo, COL_INFO, ", Loco=%d, CV%d",
addr, cv_addr);
proto_item_append_text(z21_tree, ", Loco: %d, CV%d",
addr, cv_addr);
break;
case Z21_LAN_X_CV_POM_ACCESSORY_WRITE_BYTE:
case Z21_LAN_X_CV_POM_ACCESSORY_WRITE_BIT:
case Z21_LAN_X_CV_POM_ACCESSORY_READ_BYTE:
col_append_fstr(pinfo->cinfo, COL_INFO, ", *** TO BE COMPLETED ***");
break;
case Z21_LAN_X_DCC_READ_REGISTER:
temp_uint = tvb_get_guint8(tvb, offset);
proto_tree_add_uint(z21_tree, hf_z21_register,
tvb, offset, 1, temp_uint);
offset += 1;
calculated_checksum ^= temp_uint;
col_append_fstr(pinfo->cinfo, COL_INFO, ", Register%d",
temp_uint);
proto_item_append_text(z21_tree, ", Register%d",
temp_uint);
break;
case Z21_LAN_X_DCC_WRITE_REGISTER:
temp_uint = tvb_get_guint16(tvb, offset, ENC_BIG_ENDIAN);
proto_tree_add_uint(z21_tree, hf_z21_register,
tvb, offset, 1, temp_uint >> 8);
offset += 1;
calculated_checksum ^= temp_uint >> 8;
proto_tree_add_uint(z21_tree, hf_z21_register_value,
tvb, offset, 1, temp_uint & 0xff);
offset += 1;
calculated_checksum ^= temp_uint & 0xff;
col_append_fstr(pinfo->cinfo, COL_INFO, ", Register%d, Value=%d",
temp_uint >> 8, temp_uint & 0xff);
proto_item_append_text(z21_tree, ", Register%d, Value: %d",
temp_uint >> 8, temp_uint & 0xff);
break;
case Z21_LAN_X_MM_WRITE_BYTE:
/* Skip one zero byte */
offset += 1;
temp_uint = tvb_get_guint16(tvb, offset, ENC_BIG_ENDIAN);
proto_tree_add_uint(z21_tree, hf_z21_register,
tvb, offset, 1, temp_uint >> 8);
offset += 1;
calculated_checksum ^= temp_uint >> 8;
proto_tree_add_uint(z21_tree, hf_z21_register_value,
tvb, offset, 1, temp_uint & 0xff);
offset += 1;
calculated_checksum ^= temp_uint & 0xff;
col_append_fstr(pinfo->cinfo, COL_INFO, ", Register%d, Value=%d",
temp_uint >> 8, temp_uint & 0xff);
proto_item_append_text(z21_tree, ", Register%d, Value: %d",
temp_uint >> 8, temp_uint & 0xff);
break;
case Z21_LAN_X_GET_FIRMWARE_VERSION_REPLY:
version = tvb_get_guint16(tvb, offset, ENC_BIG_ENDIAN);
buffer = wmem_strdup_printf(pinfo->pool, "%x.%02x",
version >> 8, version & 0xff);
proto_tree_add_string(z21_tree, hf_z21_firmware_version,
tvb, offset, 2, buffer);
offset += 2;
calculated_checksum ^= version >> 8;
calculated_checksum ^= version & 0xFF;
col_append_fstr(pinfo->cinfo, COL_INFO, ", Version=%s",
buffer);
}
/* Calculate checksum for the rest of the bytes (if any) for now */
while (offset < datalen-1) {
one_byte = tvb_get_guint8(tvb, offset);
offset += 1;
calculated_checksum ^= one_byte;
}
/* No more data in the X-BUS command, read the checksum */
temp_ti = proto_tree_add_item_ret_uint(z21_tree, hf_z21_checksum,
tvb, offset, 1, ENC_NA, &checksum);
if (checksum != calculated_checksum) {
expert_add_info_format(pinfo, temp_ti, &ei_z21_invalid_checksum,
"Invalid checksum, calculated: 0x%02x", calculated_checksum);
}
}
else {
/* Not X-BUS */
command_ti = proto_tree_add_uint(z21_tree, hf_z21_command,
tvb, offset, 2, command);
offset += 2;
update_command_field(command_ti, command);
col_add_fstr(pinfo->cinfo, COL_INFO, "Command=%s",
val_to_str_const(command, z21_command_vals, "unknown"));
proto_item_append_text(z21_tree, ", Command: %s",
val_to_str_const(command, z21_command_vals, "unknown"));
switch (command) {
case Z21_LAN_GET_SERIAL_NUMBER:
if (datalen == 8) {
unsigned serial;
proto_tree_add_item_ret_uint(z21_tree, hf_z21_serial_number,
tvb, offset, 4, ENC_LITTLE_ENDIAN, &serial);
offset += 4;
col_append_fstr(pinfo->cinfo, COL_INFO, ", Serial number: %d",
serial);
}
break;
case Z21_LAN_SYSTEMSTATE_DATACHANGED:
main_current = tvb_get_gint16(tvb, offset, ENC_LITTLE_ENDIAN);
proto_tree_add_int_format_value(z21_tree, hf_z21_main_current,
tvb, offset, 2, main_current, "%d mA", main_current);
offset += 2;
temp_gint32 = tvb_get_gint16(tvb, offset, ENC_LITTLE_ENDIAN);
proto_tree_add_int_format_value(z21_tree, hf_z21_prog_current,
tvb, offset, 2, temp_gint32, "%d mA", temp_gint32);
offset += 2;
temp_gint32 = tvb_get_gint16(tvb, offset, ENC_LITTLE_ENDIAN);
proto_tree_add_int_format_value(z21_tree, hf_z21_filtered_main_current,
tvb, offset, 2, temp_gint32, "%d mA", temp_gint32);
offset += 2;
temp_gint32 = tvb_get_gint16(tvb, offset, ENC_LITTLE_ENDIAN);
proto_tree_add_int_format_value(z21_tree, hf_z21_temperature,
tvb, offset, 2, temp_gint32, "%d°C", temp_gint32);
offset += 2;
col_append_fstr(pinfo->cinfo, COL_INFO,
", Temperature=%d°C", temp_gint32);
temp_uint = tvb_get_guint16(tvb, offset, ENC_LITTLE_ENDIAN);
temp_float = (float)temp_uint / 1000;
proto_tree_add_float_format_value(z21_tree, hf_z21_supply_voltage,
tvb, offset, 2, temp_float, "%.3f V", temp_float);
offset += 2;
col_append_fstr(pinfo->cinfo, COL_INFO,
", Track=%.3f V/%d mA", temp_float, main_current);
temp_uint = tvb_get_guint16(tvb, offset, ENC_LITTLE_ENDIAN);
temp_float = (float)temp_uint / 1000;
proto_tree_add_float_format_value(z21_tree, hf_z21_track_voltage,
tvb, offset, 2, temp_float, "%.3f V", temp_float);
offset += 2;
proto_tree_add_bitmask(z21_tree, tvb, offset, hf_z21_central_state,
ett_z21, state_bits_byte1, ENC_NA);
offset += 1;
proto_tree_add_bitmask(z21_tree, tvb, offset, hf_z21_central_state_ex,
ett_z21, state_bits_byte2, ENC_NA);
offset += 1;
proto_tree_add_item(z21_tree, hf_z21_systemstate_reserved,
tvb, offset, 1, ENC_NA);
offset += 1;
temp_uint = tvb_get_guint8(tvb, offset);
if (temp_uint == 0) {
/* Don't interpret the flags */
proto_tree_add_uint_format_value(z21_tree, hf_z21_capabilities,
tvb, offset, 1, 0, "0x00 (Capability flags not supported)");
}
else {
proto_tree_add_bitmask(z21_tree, tvb, offset, hf_z21_capabilities,
ett_z21, capability_bits, ENC_NA);
}
offset += 1;
break;
case Z21_LAN_RMBUS_GETDATA:
proto_tree_add_item_ret_uint(z21_tree, hf_z21_rmbus_group,
tvb, offset, 1, ENC_NA, &temp_uint);
offset += 1;
col_append_fstr(pinfo->cinfo, COL_INFO, ", Group=%d", temp_uint);
proto_item_append_text(z21_tree, ", Group: %d", temp_uint);
break;
case Z21_LAN_RMBUS_DATACHANGED:
proto_tree_add_item_ret_uint(z21_tree, hf_z21_rmbus_group,
tvb, offset, 1, ENC_NA, &temp_uint);
offset += 1;
col_append_fstr(pinfo->cinfo, COL_INFO, ", Group=%d", temp_uint);
proto_item_append_text(z21_tree, ", Group: %d", temp_uint);
proto_tree_add_item(z21_tree, hf_z21_rmbus_feedbacks, tvb, offset, 10, ENC_NA);
offset += 10;
break;
case Z21_LAN_RMBUS_PROGRAMMODULE:
proto_tree_add_item_ret_uint(z21_tree, hf_z21_rmbus_address,
tvb, offset, 1, ENC_NA, &temp_uint);
col_append_fstr(pinfo->cinfo, COL_INFO, ", Address=%d", temp_uint);
proto_item_append_text(z21_tree, ", Address: %d", temp_uint);
offset += 1;
break;
case Z21_LAN_RAILCOM_DATACHANGED:
proto_tree_add_item_ret_uint(z21_tree, hf_z21_loco_address,
tvb, offset, 2, ENC_LITTLE_ENDIAN, &temp_uint);
offset += 2;
col_append_fstr(pinfo->cinfo, COL_INFO, ", Loco=%d", temp_uint);
proto_item_append_text(z21_tree, ", Loco: %d", temp_uint);
proto_tree_add_item(z21_tree, hf_z21_railcom_receive_counter, tvb, offset, 4, ENC_LITTLE_ENDIAN);
offset += 4;
proto_tree_add_item(z21_tree, hf_z21_railcom_error_counter, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
proto_tree_add_item(z21_tree, hf_z21_railcom_reserved1, tvb, offset, 1, ENC_NA);
offset += 1;
proto_tree_add_item(z21_tree, hf_z21_railcom_options, tvb, offset, 1, ENC_NA);
offset += 1;
proto_tree_add_item(z21_tree, hf_z21_railcom_speed, tvb, offset, 1, ENC_NA);
offset += 1;
proto_tree_add_item(z21_tree, hf_z21_railcom_qos, tvb, offset, 1, ENC_NA);
offset += 1;
proto_tree_add_item(z21_tree, hf_z21_railcom_reserved2, tvb, offset, 1, ENC_NA);
offset += 1;
break;
case Z21_LAN_RAILCOM_GETDATA:
proto_tree_add_item(z21_tree, hf_z21_railcom_type, tvb, offset, 1, ENC_NA);
offset += 1;
proto_tree_add_item(z21_tree, hf_z21_loco_address, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
break;
case Z21_LAN_LOCONET_FROM_LAN:
case Z21_LAN_LOCONET_Z21_RX:
case Z21_LAN_LOCONET_Z21_TX:
proto_tree_add_item(z21_tree, hf_z21_loconet_message,
tvb, offset, datalen-4, ENC_NA);
offset += datalen-4;
break;
case Z21_LAN_LOCONET_DISPATCH_ADDR:
proto_tree_add_item_ret_uint(z21_tree, hf_z21_loco_address,
tvb, offset, 2, ENC_LITTLE_ENDIAN, &temp_uint);
offset += 2;
col_append_fstr(pinfo->cinfo, COL_INFO, ", Loco=%d", temp_uint);
proto_item_append_text(z21_tree, ", Loco: %d", temp_uint);
if (datalen > 6) {
/* Response from Z21 */
proto_tree_add_item(z21_tree, hf_z21_loconet_result, tvb, offset, 1, ENC_NA);
offset += 1;
}
break;
case Z21_LAN_LOCONET_DETECTOR:
proto_tree_add_item(z21_tree, hf_z21_loconet_type, tvb, offset, 1, ENC_NA);
offset += 1;
if (datalen == 7) {
/* This is request */
proto_tree_add_item(z21_tree, hf_z21_loconet_report_address,
tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
}
else {
/* This is reply */
proto_tree_add_item(z21_tree, hf_z21_loconet_feedback_address,
tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
proto_tree_add_item(z21_tree, hf_z21_loconet_info,
tvb, offset, datalen-7, ENC_NA);
offset += datalen-7;
}
break;
case Z21_LAN_CAN_DETECTOR:
if (datalen == 7) {
/* This is request */
proto_tree_add_item(z21_tree, hf_z21_can_type, tvb, offset, 1, ENC_NA);
offset += 1;
proto_tree_add_item_ret_uint(z21_tree, hf_z21_can_network_id,
tvb, offset, 2, ENC_LITTLE_ENDIAN, &temp_uint);
offset += 2;
col_append_fstr(pinfo->cinfo, COL_INFO, ", NetworkID=%d", temp_uint);
proto_item_append_text(z21_tree, ", NetworkID: %d", temp_uint);
}
else {
/* This is reply */
proto_tree_add_item_ret_uint(z21_tree, hf_z21_can_network_id,
tvb, offset, 2, ENC_LITTLE_ENDIAN, &temp_uint);
offset += 2;
col_append_fstr(pinfo->cinfo, COL_INFO, ", NetworkID=%d", temp_uint);
proto_item_append_text(z21_tree, ", NetworkID: %d", temp_uint);
proto_tree_add_item(z21_tree, hf_z21_can_module_address,
tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
proto_tree_add_item(z21_tree, hf_z21_can_port, tvb, offset, 1, ENC_NA);
offset += 1;
proto_tree_add_item(z21_tree, hf_z21_can_type, tvb, offset, 1, ENC_NA);
offset += 1;
proto_tree_add_item(z21_tree, hf_z21_can_value1,
tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
proto_tree_add_item(z21_tree, hf_z21_can_value2,
tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
}
break;
case Z21_LAN_CAN_DEVICE_GET_DESCRIPTION:
case Z21_LAN_CAN_DEVICE_SET_DESCRIPTION:
proto_tree_add_item_ret_uint(z21_tree, hf_z21_can_network_id,
tvb, offset, 2, ENC_LITTLE_ENDIAN, &temp_uint);
offset += 2;
col_append_fstr(pinfo->cinfo, COL_INFO, ", NetworkID=%d", temp_uint);
proto_item_append_text(z21_tree, ", NetworkID: %d", temp_uint);
if (datalen > 6) {
proto_tree_add_item(z21_tree, hf_z21_can_booster_name,
tvb, offset, 16, ENC_ISO_8859_1);
offset += 16;
}
break;
case Z21_LAN_CAN_BOOSTER_SYSTEMSTATE_CHGD:
proto_tree_add_item_ret_uint(z21_tree, hf_z21_can_network_id,
tvb, offset, 2, ENC_LITTLE_ENDIAN, &temp_uint);
offset += 2;
col_append_fstr(pinfo->cinfo, COL_INFO, ", NetworkID=%d", temp_uint);
proto_item_append_text(z21_tree, ", NetworkID: %d", temp_uint);
proto_tree_add_item(z21_tree, hf_z21_can_booster_output_port,
tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
proto_tree_add_bitmask(z21_tree, tvb, offset,
hf_z21_can_booster_state, ett_z21, booster_state_bits, ENC_LITTLE_ENDIAN);
offset += 2;
temp_uint = tvb_get_gint16(tvb, offset, ENC_LITTLE_ENDIAN);
proto_tree_add_uint_format_value(z21_tree, hf_z21_can_booster_vcc,
tvb, offset, 2, temp_uint, "%d mV", temp_uint);
offset += 2;
temp_uint = tvb_get_gint16(tvb, offset, ENC_LITTLE_ENDIAN);
proto_tree_add_uint_format_value(z21_tree, hf_z21_can_booster_current,
tvb, offset, 2, temp_uint, "%d mA", temp_uint);
offset += 2;
break;
case Z21_LAN_CAN_BOOSTER_SET_TRACKPOWER:
proto_tree_add_item_ret_uint(z21_tree, hf_z21_can_network_id,
tvb, offset, 2, ENC_LITTLE_ENDIAN, &temp_uint);
offset += 2;
col_append_fstr(pinfo->cinfo, COL_INFO, ", NetworkID=%d", temp_uint);
proto_item_append_text(z21_tree, ", NetworkID: %d", temp_uint);
proto_tree_add_item(z21_tree, hf_z21_can_booster_power, tvb, offset, 1, ENC_NA);
offset += 1;
break;
case Z21_LAN_ZLINK_GET_HWINFO:
proto_tree_add_item(z21_tree, hf_z21_zlink_message_type, tvb, offset, 1, ENC_NA);
offset += 1;
if (datalen > 5) {
proto_tree_add_item(z21_tree, hf_z21_zlink_hwid,
tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
proto_tree_add_item(z21_tree, hf_z21_zlink_fw_major, tvb, offset, 1, ENC_NA);
offset += 1;
proto_tree_add_item(z21_tree, hf_z21_zlink_fw_minor, tvb, offset, 1, ENC_NA);
offset += 1;
proto_tree_add_item(z21_tree, hf_z21_zlink_fw_build, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
proto_tree_add_item(z21_tree, hf_z21_zlink_mac, tvb, offset, 18, ENC_ASCII);
offset += 18;
proto_tree_add_item(z21_tree, hf_z21_zlink_name, tvb, offset, 33, ENC_ISO_8859_1);
offset += 18;
proto_tree_add_item(z21_tree, hf_z21_zlink_reserved, tvb, offset, 1, ENC_NA);
offset += 1;
}
break;
case Z21_LAN_BOOSTER_GET_DESCRIPTION:
case Z21_LAN_BOOSTER_SET_DESCRIPTION:
if (datalen > 4) {
/* SET_DESCRIPTION or reply to GET_DESCRIPTION */
guint8 *buf = tvb_get_stringz_enc(pinfo->pool, tvb, offset, NULL, ENC_ISO_8859_1);
if (buf[0] == 0xff) {
/* Interpreted as an empty name */
proto_tree_add_string(z21_tree, hf_z21_booster_name, tvb, offset, 32, "");
}
else {
proto_tree_add_string(z21_tree, hf_z21_booster_name, tvb, offset, 32, buf);
}
offset += 32;
}
break;
case Z21_LAN_BOOSTER_SYSTEMSTATE_GETDATA:
case Z21_LAN_DECODER_SYSTEMSTATE_GETDATA:
break;
case Z21_LAN_DECODER_GET_DESCRIPTION:
case Z21_LAN_DECODER_SET_DESCRIPTION:
if (datalen > 4) {
/* SET_DESCRIPTION or reply to GET_DESCRIPTION */
guint8 *buf = tvb_get_stringz_enc(pinfo->pool, tvb, offset, NULL, ENC_ISO_8859_1);
if (buf[0] == 0xff) {
/* Interpreted as an empty name */
proto_tree_add_string(z21_tree, hf_z21_decoder_name, tvb, offset, 32, "");
}
else {
proto_tree_add_string(z21_tree, hf_z21_decoder_name, tvb, offset, 32, buf);
}
offset += 32;
}
break;
case Z21_LAN_BOOSTER_SET_POWER:
proto_tree_add_item_ret_uint(z21_tree, hf_z21_booster_port,
tvb, offset, 1, ENC_NA, &temp_uint);
offset += 1;
col_append_fstr(pinfo->cinfo, COL_INFO, ", Port=%d", temp_uint);
proto_item_append_text(z21_tree, ", Port: %d", temp_uint);
proto_tree_add_item_ret_uint(z21_tree, hf_z21_booster_port_state,
tvb, offset, 1, ENC_NA, &temp_uint);
offset += 1;
col_append_fstr(pinfo->cinfo, COL_INFO, ", State=%d", temp_uint);
proto_item_append_text(z21_tree, ", State: %d", temp_uint);
break;
case Z21_LAN_BOOSTER_SYSTEMSTATE_DATACHANGED:
/* To be expanded later... */
proto_tree_add_item(z21_tree, hf_z21_booster_state_data,
tvb, offset, 24, ENC_NA);
offset += 24;
break;
case Z21_LAN_DECODER_SYSTEMSTATE_DATACHANGED:
/* To be expanded later... */
/* Data is variable length */
proto_tree_add_item(z21_tree, hf_z21_decoder_state_data,
tvb, offset, datalen-4, ENC_NA);
offset += datalen-4;
break;
}
if (offset < datalen) {
/* Just dump all the rest, if any */
proto_tree_add_item(z21_tree, hf_z21_data, tvb, offset, datalen-offset, ENC_NA);
offset += datalen-offset;
}
}
return offset;
}
static unsigned
get_z21_pdu_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset, void *data _U_)
{
return tvb_get_guint16(tvb, offset, ENC_LITTLE_ENDIAN);
}
static gboolean
check_z21_header(packet_info *pinfo _U_, tvbuff_t *tvb _U_, int offset _U_, void *data _U_)
{
return TRUE;
}
static int
dissect_z21(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
{
return udp_dissect_pdus(tvb, pinfo, tree, Z21_MIN_LENGTH,
check_z21_header, get_z21_pdu_len, dissect_z21_pdu, data);
}
/* Register the protocol with Wireshark.
*
* This format is required because a script is used to build the C function that
* calls all the protocol registration.
*/
void
proto_register_z21(void)
{
expert_module_t *expert_z21;
static hf_register_info hf[] = {
{ &hf_z21_datalen,
{ "Data length", "z21.datalen",
FT_UINT16, BASE_DEC, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_command,
{ "Command", "z21.command",
FT_UINT32, BASE_HEX|BASE_NO_DISPLAY_VALUE, VALS(z21_command_vals), 0x0,
NULL, HFILL }
},
{ &hf_z21_x_bus,
{ "X-BUS", "z21.xbus",
FT_BOOLEAN, BASE_NONE, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_serial_number,
{ "Serial number", "z21.serialnumber",
FT_UINT32, BASE_DEC, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_checksum,
{ "Checksum", "z21.checksum",
FT_UINT8, BASE_HEX, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_main_current,
{ "Main track current", "z21.maincurrent",
FT_INT16, BASE_DEC, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_prog_current,
{ "Programming track current", "z21.progcurrent",
FT_INT16, BASE_DEC, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_filtered_main_current,
{ "Filtered main track current", "z21.filteredmaincurrent",
FT_INT16, BASE_DEC, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_temperature,
{ "Command station temperature", "z21.temperature",
FT_INT16, BASE_DEC, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_supply_voltage,
{ "Supply voltage", "z21.supplyvoltage",
FT_FLOAT, BASE_DEC, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_track_voltage,
{ "Track voltage", "z21.trackvoltage",
FT_FLOAT, BASE_DEC, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_central_state,
{ "Central state, first byte", "z21.centralstate1",
FT_UINT8, BASE_HEX, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_central_state_ex,
{ "Central state, second byte", "z21.centralstate2",
FT_UINT8, BASE_HEX, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_systemstate_reserved,
{ "Reserved", "z21.systemstatereserved",
FT_UINT8, BASE_HEX, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_capabilities,
{ "Capabilities", "z21.capabilities",
FT_UINT8, BASE_HEX, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_status,
{ "Status", "z21.status",
FT_UINT8, BASE_HEX, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_state_emergency_stop,
{ "Emergency stop", "z21.state.emergencystop",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x01,
NULL, HFILL }
},
{ &hf_z21_state_track_voltage_off,
{ "Track voltage off", "z21.state.trackvoltageoff",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x02,
NULL, HFILL }
},
{ &hf_z21_state_short_circuit,
{ "Short circuit", "z21.state.shortcircuit",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x04,
NULL, HFILL }
},
{ &hf_z21_state_programming_mode,
{ "Programming mode", "z21.state.programmingmode",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x20,
NULL, HFILL }
},
{ &hf_z21_state_high_temperature,
{ "High temperature", "z21.state.hightemperature",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x01,
NULL, HFILL }
},
{ &hf_z21_state_power_lost,
{ "Power lost", "z21.state.powerlost",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x02,
NULL, HFILL }
},
{ &hf_z21_state_short_circuit_external,
{ "External short circuit", "z21.state.externalshortcircuit",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x04,
NULL, HFILL }
},
{ &hf_z21_state_short_circuit_internal,
{ "Internal short circuit", "z21.state.internalshortcircuit",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x08,
NULL, HFILL }
},
{ &hf_z21_state_rcn_213,
{ "RCN-213 turnout addressing", "z21.state.rcn213addressing",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x20,
NULL, HFILL }
},
{ &hf_z21_capability_dcc,
{ "DCC capability", "z21.capability.dcc",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x01,
NULL, HFILL }
},
{ &hf_z21_capability_mm,
{ "MM capability", "z21.capability.mm",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x02,
NULL, HFILL }
},
{ &hf_z21_capability_reserved,
{ "Reserved capability", "z21.capability.reserved",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x04,
NULL, HFILL }
},
{ &hf_z21_capability_railcom,
{ "RailCom capability", "z21.capability.railcom",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x08,
NULL, HFILL }
},
{ &hf_z21_capability_loco_cmds,
{ "Accepts LAN commands for locomotive decoders", "z21.capability.lococmds",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x10,
NULL, HFILL }
},
{ &hf_z21_capability_accessory_cmds,
{ "Accepts LAN commands for accessory decoders", "z21.capability.accessorycmds",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x20,
NULL, HFILL }
},
{ &hf_z21_capability_detector_cmds,
{ "Accepts LAN commands for detectors", "z21.capability.detectorcmds",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x40,
NULL, HFILL }
},
{ &hf_z21_capability_needs_unlock_code,
{ "Needs unlock code", "z21.capability.needsunlockcode",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x80,
NULL, HFILL }
},
{ &hf_z21_loco_address,
{ "Locomotive address", "z21.locoaddress",
FT_UINT16, BASE_DEC, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_loco_direction_and_speed,
{ "Locomotive direction and speed", "z21.locodirectionandspeed",
FT_UINT8, BASE_HEX, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_loco_direction,
{ "Locomotive direction", "z21.locodirection",
FT_BOOLEAN, 8, TFS(&tfs_forward_reverse), 0x80,
NULL, HFILL }
},
{ &hf_z21_loco_speed,
{ "Locomotive speed", "z21.locospeed",
FT_UINT8, BASE_HEX, NULL, 0x7F,
NULL, HFILL }
},
{ &hf_z21_loco_info_mm,
{ "Locomotive is MM (Märklin-Motorola)", "z21.locomm",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x10,
NULL, HFILL }
},
{ &hf_z21_loco_info_busy,
{ "Locomotive is busy", "z21.locoinfobusy",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x08,
"Locomotive is controlled by another X-BUS handset controller", HFILL }
},
{ &hf_z21_loco_info_speed_steps,
{ "Locomotive speed steps", "z21.locoinfospeedsteps",
FT_UINT8, BASE_DEC, VALS(z21_loco_info_speed_steps_vals), 0x07,
NULL, HFILL }
},
{ &hf_z21_loco_info_direction,
{ "Locomotive direction", "z21.locoinfodirection",
FT_BOOLEAN, 8, TFS(&tfs_forward_reverse), 0x80,
NULL, HFILL }
},
{ &hf_z21_loco_info_speed,
{ "Locomotive speed", "z21.locoinfospeed",
FT_UINT8, BASE_HEX, NULL, 0x7f,
NULL, HFILL }
},
{ &hf_z21_loco_info_double_traction,
{ "Double traction", "z21.locoinfodoubletraction",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x40,
NULL, HFILL }
},
{ &hf_z21_loco_info_smartsearch,
{ "Smartsearch", "z21.locoinfosmartsearch",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x20,
NULL, HFILL }
},
{ &hf_z21_loco_info_f0,
{ "Function F0 (lights)", "z21.locoinfof0",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x10,
NULL, HFILL }
},
{ &hf_z21_loco_info_f4,
{ "Function F4", "z21.locoinfof4",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x08,
NULL, HFILL }
},
{ &hf_z21_loco_info_f3,
{ "Function F3", "z21.locoinfof3",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x04,
NULL, HFILL }
},
{ &hf_z21_loco_info_f2,
{ "Function F2", "z21.locoinfof2",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x02,
NULL, HFILL }
},
{ &hf_z21_loco_info_f1,
{ "Function F1", "z21.locoinfof1",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x01,
NULL, HFILL }
},
{ &hf_z21_loco_info_f12,
{ "Function F12", "z21.locoinfof12",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x80,
NULL, HFILL }
},
{ &hf_z21_loco_info_f11,
{ "Function F11", "z21.locoinfof11",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x40,
NULL, HFILL }
},
{ &hf_z21_loco_info_f10,
{ "Function F10", "z21.locoinfof10",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x20,
NULL, HFILL }
},
{ &hf_z21_loco_info_f9,
{ "Function F9", "z21.locoinfof9",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x10,
NULL, HFILL }
},
{ &hf_z21_loco_info_f8,
{ "Function F8", "z21.locoinfof8",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x08,
NULL, HFILL }
},
{ &hf_z21_loco_info_f7,
{ "Function F7", "z21.locoinfof7",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x04,
NULL, HFILL }
},
{ &hf_z21_loco_info_f6,
{ "Function F6", "z21.locoinfof6",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x02,
NULL, HFILL }
},
{ &hf_z21_loco_info_f5,
{ "Function F5", "z21.locoinfof5",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x01,
NULL, HFILL }
},
{ &hf_z21_loco_info_f20,
{ "Function F20", "z21.locoinfof20",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x80,
NULL, HFILL }
},
{ &hf_z21_loco_info_f19,
{ "Function F19", "z21.locoinfof19",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x40,
NULL, HFILL }
},
{ &hf_z21_loco_info_f18,
{ "Function F18", "z21.locoinfof18",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x20,
NULL, HFILL }
},
{ &hf_z21_loco_info_f17,
{ "Function F17", "z21.locoinfof17",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x10,
NULL, HFILL }
},
{ &hf_z21_loco_info_f16,
{ "Function F16", "z21.locoinfof16",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x08,
NULL, HFILL }
},
{ &hf_z21_loco_info_f15,
{ "Function F15", "z21.locoinfof15",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x04,
NULL, HFILL }
},
{ &hf_z21_loco_info_f14,
{ "Function F14", "z21.locoinfof14",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x02,
NULL, HFILL }
},
{ &hf_z21_loco_info_f13,
{ "Function F13", "z21.locoinfof13",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x01,
NULL, HFILL }
},
{ &hf_z21_loco_info_f28,
{ "Function F28", "z21.locoinfof28",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x80,
NULL, HFILL }
},
{ &hf_z21_loco_info_f27,
{ "Function F27", "z21.locoinfof27",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x40,
NULL, HFILL }
},
{ &hf_z21_loco_info_f26,
{ "Function F26", "z21.locoinfof26",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x20,
NULL, HFILL }
},
{ &hf_z21_loco_info_f25,
{ "Function F25", "z21.locoinfof25",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x10,
NULL, HFILL }
},
{ &hf_z21_loco_info_f24,
{ "Function F24", "z21.locoinfof24",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x08,
NULL, HFILL }
},
{ &hf_z21_loco_info_f23,
{ "Function F23", "z21.locoinfof23",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x04,
NULL, HFILL }
},
{ &hf_z21_loco_info_f22,
{ "Function F22", "z21.locoinfof22",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x02,
NULL, HFILL }
},
{ &hf_z21_loco_info_f21,
{ "Function F21", "z21.locoinfof21",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x01,
NULL, HFILL }
},
{ &hf_z21_loco_info_f31,
{ "Function F31", "z21.locoinfof31",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x04,
NULL, HFILL }
},
{ &hf_z21_loco_info_f30,
{ "Function F30", "z21.locoinfof30",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x02,
NULL, HFILL }
},
{ &hf_z21_loco_info_f29,
{ "Function F29", "z21.locoinfof29",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x01,
NULL, HFILL }
},
{ &hf_z21_loco_info_extensions,
{ "Extensions", "z21.locoinfoextensions",
FT_BYTES, BASE_NONE, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_speed_steps,
{ "Speed steps", "z21.speedsteps",
FT_UINT8, BASE_DEC, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_firmware_version,
{ "Firmware version", "z21.firmwareversion",
FT_STRING, BASE_NONE, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_loco_func_switch_type,
{ "Locomotive function switch type", "z21.locofunctionswitchtype",
FT_UINT8, BASE_DEC, VALS(z21_loco_func_vals), 0xc0,
NULL, HFILL }
},
{ &hf_z21_loco_func_index,
{ "Locomotive function index", "z21.locofunctionindex",
FT_UINT8, BASE_DEC, NULL, 0x3f,
NULL, HFILL }
},
{ &hf_z21_function_address,
{ "Function address", "z21.functionaddress",
FT_UINT16, BASE_DEC, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_turnout_state,
{ "Turnout state", "z21.turnoutstate",
FT_UINT8, BASE_DEC, VALS(z21_turnout_state_vals), 0x03,
NULL, HFILL }
},
{ &hf_z21_turnout_queue_bit,
{ "Queue the turnout command", "z21.turnoutqueue",
FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x20,
NULL, HFILL }
},
{ &hf_z21_turnout_activate_bit,
{ "Turnout command", "z21.turnoutcommand",
FT_BOOLEAN, 8, TFS(&tfs_turnout_command), 0x08,
NULL, HFILL }
},
{ &hf_z21_turnout_output_bit,
{ "Select turnout output", "z21.turnoutoutput",
FT_BOOLEAN, 8, TFS(&tfs_turnout_output), 0x01,
NULL, HFILL }
},
{ &hf_z21_accessory_address,
{ "Accessory address", "z21.accessoryaddress",
FT_UINT16, BASE_DEC, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_accessory_state,
{ "Accessory state", "z21.accessorystate",
FT_UINT8, BASE_DEC, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_accessory_status,
{ "Accessory status", "z21.accessorystatus",
FT_UINT8, BASE_HEX, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_cv_address,
{ "CV address", "z21.cvaddress",
FT_UINT16, BASE_DEC, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_cv_value,
{ "CV value", "z21.cvvalue",
FT_UINT8, BASE_DEC, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_register,
{ "Register", "z21.register",
FT_UINT8, BASE_DEC, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_register_value,
{ "Register value", "z21.registervalue",
FT_UINT8, BASE_DEC, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_pom_operation,
{ "POM operation", "z21.pomoperation",
FT_UINT16, BASE_HEX, VALS(z21_pom_operation_vals), 0x0,
NULL, HFILL }
},
{ &hf_z21_cv_bit_position,
{ "CV bit position", "z21.cvbitposition",
FT_UINT8, BASE_DEC, NULL, 0x07,
NULL, HFILL }
},
{ &hf_z21_cv_bit_value,
{ "CV bit value", "z21.cvbitvalue",
FT_BOOLEAN, 8, TFS(&tfs_set_notset), 0x08,
NULL, HFILL }
},
{ &hf_z21_rmbus_group,
{ "R-BUS group index", "z21.rbusgroup",
FT_UINT8, BASE_DEC, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_rmbus_feedbacks,
{ "R-BUS feedbacks", "z21.rbusfeedbacks",
FT_BYTES, BASE_NONE|SEP_SPACE, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_rmbus_address,
{ "R-BUS feedback module address", "z21.rbusaddress",
FT_UINT8, BASE_DEC, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_railcom_receive_counter,
{ "RailCom receive counter", "z21.railcomreceives",
FT_UINT32, BASE_DEC, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_railcom_error_counter,
{ "RailCom error counter", "z21.railcomerrors",
FT_UINT16, BASE_DEC, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_railcom_reserved1,
{ "RailCom reserved 1", "z21.railcomreserved1",
FT_UINT8, BASE_HEX, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_railcom_reserved2,
{ "RailCom reserved 2", "z21.railcomreserved2",
FT_UINT8, BASE_HEX, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_railcom_options,
{ "RailCom options", "z21.railcomoptions",
FT_UINT8, BASE_HEX, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_railcom_speed,
{ "RailCom speed", "z21.railcomspeed",
FT_UINT8, BASE_HEX, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_railcom_qos,
{ "RailCom QoS", "z21.railcomqos",
FT_UINT8, BASE_HEX, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_railcom_type,
{ "RailCom type", "z21.railcomtype",
FT_UINT8, BASE_HEX, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_loconet_message,
{ "LocoNet message", "z21.loconetmessage",
FT_BYTES, BASE_NONE|SEP_SPACE, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_loconet_result,
{ "LocoNet result", "z21.loconetresult",
FT_UINT8, BASE_HEX, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_loconet_type,
{ "LocoNet type", "z21.loconettype",
FT_UINT8, BASE_HEX, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_loconet_report_address,
{ "LocoNet report address", "z21.loconetreportaddress",
FT_UINT16, BASE_DEC, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_loconet_feedback_address,
{ "LocoNet feedback address", "z21.loconetfeedbackaddress",
FT_UINT16, BASE_DEC, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_loconet_info,
{ "LocoNet info", "z21.loconetinfo",
FT_BYTES, BASE_NONE|SEP_SPACE, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_can_type,
{ "CAN type", "z21.cantype",
FT_UINT8, BASE_HEX, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_can_network_id,
{ "CAN network ID", "z21.cannetworkid",
FT_UINT16, BASE_HEX, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_can_module_address,
{ "CAN module address", "z21.canmoduleaddress",
FT_UINT16, BASE_HEX, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_can_port,
{ "CAN input port (pin)", "z21.canport",
FT_UINT8, BASE_DEC, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_can_value1,
{ "CAN value 1", "z21.canvalue1",
FT_UINT16, BASE_HEX, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_can_value2,
{ "CAN value 2", "z21.canvalue2",
FT_UINT16, BASE_HEX, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_can_booster_name,
{ "CAN booster name", "z21.canboostername",
FT_STRINGZ, BASE_NONE, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_can_booster_output_port,
{ "CAN booster output port", "z21.canboosteroutputport",
FT_UINT16, BASE_DEC, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_can_booster_state,
{ "CAN booster state", "z21.canboosterstate",
FT_UINT16, BASE_HEX, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_can_booster_state_bg_active,
{ "CAN booster brake generator active", "z21.canboosterbrakegenerator",
FT_BOOLEAN, 16, NULL, 0x0001,
NULL, HFILL }
},
{ &hf_z21_can_booster_state_short_circuit,
{ "CAN booster short circuit", "z21.canboostershortcircuit",
FT_BOOLEAN, 16, NULL, 0x0020,
NULL, HFILL }
},
{ &hf_z21_can_booster_state_track_voltage_off,
{ "CAN booster track voltage off", "z21.canboostertrackvoltageoff",
FT_BOOLEAN, 16, NULL, 0x0080,
NULL, HFILL }
},
{ &hf_z21_can_booster_state_railcom_active,
{ "CAN booster RailCom cutout active", "z21.canboosterrailcomactive",
FT_BOOLEAN, 16, NULL, 0x0800,
NULL, HFILL }
},
{ &hf_z21_can_booster_state_output_disabled,
{ "CAN booster output disabled", "z21.canboosteroutputdisabled",
FT_BOOLEAN, 16, NULL, 0x0100,
NULL, HFILL }
},
{ &hf_z21_can_booster_vcc,
{ "CAN booster VCC voltage", "z21.canboostervoltage",
FT_UINT16, BASE_DEC, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_can_booster_current,
{ "CAN booster current", "z21.canboostercurrent",
FT_UINT16, BASE_DEC, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_can_booster_power,
{ "CAN booster power", "z21.canboosterpower",
FT_UINT16, BASE_HEX, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_zlink_message_type,
{ "zLink message type", "z21.zlinkmessagetype",
FT_UINT8, BASE_HEX, VALS(z21_zlink_message_type_vals), 0x0,
NULL, HFILL }
},
{ &hf_z21_zlink_hwid,
{ "zLink hardware ID", "z21.zlinkhwid",
FT_UINT16, BASE_DEC_HEX, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_zlink_fw_major,
{ "zLink firmware major version", "z21.zlinkmajorversion",
FT_UINT8, BASE_DEC, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_zlink_fw_minor,
{ "zLink firmware minor version", "z21.zlinkminorversion",
FT_UINT8, BASE_DEC, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_zlink_fw_build,
{ "zLink firmware build version", "z21.zlinkbuildversion",
FT_UINT16, BASE_DEC, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_zlink_mac,
{ "zLink MAC address", "z21.zlinkmac",
FT_STRINGZ, BASE_NONE, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_zlink_name,
{ "zLink name", "z21.zlinkname",
FT_STRINGZ, BASE_NONE, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_zlink_reserved,
{ "zLink reserved", "z21.zlinkreserved",
FT_UINT8, BASE_HEX, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_booster_name,
{ "Booster name", "z21.boostername",
FT_STRINGZ, BASE_NONE, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_booster_port,
{ "Booster port", "z21.boosterport",
FT_UINT8, BASE_HEX, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_booster_port_state,
{ "Booster port state", "z21.boosterportstate",
FT_UINT8, BASE_HEX, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_booster_state_data,
{ "Booster state data", "z21.boosterstatedata",
FT_BYTES, BASE_NONE|SEP_SPACE, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_decoder_name,
{ "Decoder name", "z21.decodername",
FT_STRINGZ, BASE_NONE, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_decoder_state_data,
{ "Decoder state data", "z21.decoderstatedata",
FT_BYTES, BASE_NONE|SEP_SPACE, NULL, 0x0,
NULL, HFILL }
},
{ &hf_z21_data,
{ "Undecoded data", "z21.data",
FT_BYTES, BASE_NONE|SEP_SPACE, NULL, 0x0,
NULL, HFILL }
},
};
/* Setup protocol subtree array */
static int *ett[] = {
&ett_z21,
};
/* Setup protocol expert items */
static ei_register_info ei[] = {
{ &ei_z21_invalid_checksum,
{ "z21.invalidchecksum", PI_CHECKSUM, PI_WARN,
"Invalid XOR checksum", EXPFILL }
},
};
/* Register the protocol name and description */
proto_z21 = proto_register_protocol("Z21 LAN Protocol", "Z21", "z21");
/* Required function calls to register the header fields and subtrees */
proto_register_field_array(proto_z21, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));
/* Required function calls to register expert items */
expert_z21 = expert_register_protocol(proto_z21);
expert_register_field_array(expert_z21, ei, array_length(ei));
z21_handle = register_dissector("z21", dissect_z21, proto_z21);
/* Register a preferences module (see section 2.6 of README.dissector
* for more details). Registration of a prefs callback is not required
* if there are no preferences that affect protocol registration (an example
* of a preference that would affect registration is a port preference).
* If the prefs callback is not needed, use NULL instead of
* proto_reg_handoff_z21 in the following.
*/
prefs_register_protocol(proto_z21, proto_reg_handoff_z21);
}
void
proto_reg_handoff_z21(void)
{
static bool initialized = false;
if (!initialized) {
dissector_add_uint_range_with_preference("udp.port", Z21_UDP_PORTS, z21_handle);
initialized = true;
}
udp_port_range = prefs_get_range_value("Z21", "udp.port");
}
|