1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
|
/* packet-sbus.c
* Routines for Ether-S-Bus dissection
* Copyright 2010, Christian Durrer <christian.durrer@sensemail.ch>
*
* 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/conversation.h>
#include <epan/expert.h>
void proto_register_sbus(void);
void proto_reg_handoff_sbus(void);
static dissector_handle_t sbus_handle;
#define SBUS_UDP_PORT 5050 /* Not IANA registered */
/* Attribute values*/
#define SBUS_REQUEST 0x00
#define SBUS_RESPONSE 0x01
#define SBUS_ACKNAK 0x02
/*SBus command codes*/
#define SBUS_RD_COUNTER 0x00
#define SBUS_RD_DISPLAY_REGISTER 0x01
#define SBUS_RD_FLAG 0x02
#define SBUS_RD_INPUT 0x03
#define SBUS_RD_RTC 0x04
#define SBUS_RD_OUTPUT 0x05
#define SBUS_RD_REGISTER 0x06
#define SBUS_RD_TIMER 0x07
#define SBUS_WR_COUNTER 0x0A
#define SBUS_WR_FLAG 0x0B
#define SBUS_WR_RTC 0x0C
#define SBUS_WR_OUTPUT 0x0D
#define SBUS_WR_REGISTER 0x0E
#define SBUS_WR_TIMER 0x0F
#define SBUS_RDWR_MULTI_MEDIAS 0x13
#define SBUS_RD_PCD_STATUS_CPU0 0x14
#define SBUS_RD_PCD_STATUS_CPU1 0x15
#define SBUS_RD_PCD_STATUS_CPU2 0x16
#define SBUS_RD_PCD_STATUS_CPU3 0x17
#define SBUS_RD_PCD_STATUS_CPU4 0x18
#define SBUS_RD_PCD_STATUS_CPU5 0x19
#define SBUS_RD_PCD_STATUS_CPU6 0x1A
#define SBUS_RD_PCD_STATUS_OWN 0x1B
#define SBUS_RD_SBUS_STN_NBR 0x1D
#define SBUS_RD_USER_MEMORY 0x1E
#define SBUS_RD_PROGRAM_LINE 0x1F
#define SBUS_RD_PROGRAM_VERSION 0x20
#define SBUS_RD_TEXT 0x21
#define SBUS_RD_ACTIVE_TRANSITION 0x22
#define SBUS_WR_USER_MEMORY 0x23
#define SBUS_WR_PROGRAM_LINE 0x24
#define SBUS_WR_TEXT 0x25
#define SBUS_RUN_PROCEDURE_CPU0 0x28
#define SBUS_RUN_PROCEDURE_CPU1 0x29
#define SBUS_RUN_PROCEDURE_CPU2 0x2A
#define SBUS_RUN_PROCEDURE_CPU3 0x2B
#define SBUS_RUN_PROCEDURE_CPU4 0x2C
#define SBUS_RUN_PROCEDURE_CPU5 0x2D
#define SBUS_RUN_PROCEDURE_CPU6 0x2E
#define SBUS_RUN_PROCEDURE_OWN 0x2F
#define SBUS_RUN_PROCEDURE_ALL 0x30
#define SBUS_RESTART_COLD_CPU1 0x32
#define SBUS_RESTART_COLD_CPU2 0x33
#define SBUS_RESTART_COLD_CPU3 0x34
#define SBUS_RESTART_COLD_CPU4 0x35
#define SBUS_RESTART_COLD_CPU5 0x36
#define SBUS_RESTART_COLD_CPU6 0x37
#define SBUS_RESTART_COLD_OWN 0x38
#define SBUS_RESTART_COLD_ALL 0x39
#define SBUS_STOP_PROCEDURE_CPU0 0x3C
#define SBUS_STOP_PROCEDURE_CPU1 0x3D
#define SBUS_STOP_PROCEDURE_CPU2 0x3E
#define SBUS_STOP_PROCEDURE_CPU3 0x3F
#define SBUS_STOP_PROCEDURE_CPU4 0x40
#define SBUS_STOP_PROCEDURE_CPU5 0x41
#define SBUS_STOP_PROCEDURE_CPU6 0x42
#define SBUS_STOP_PROCEDURE_OWN 0x43
#define SBUS_STOP_PROCEDURE_ALL 0x44
#define SBUS_RD_STATUSFLAG_ACCU 0x46
#define SBUS_RD_BYTE 0x47
#define SBUS_RD_HALT_FAILURE_REG 0x48
#define SBUS_RD_INDEX_REGISTER 0x49
#define SBUS_RD_INSTRUCTION_POINTER 0x4A
#define SBUS_FIND_HISTORY 0x4B
#define SBUS_WR_STATUSFLAG_ACCU 0x50
#define SBUS_WR_BYTE 0x51
#define SBUS_WR_INDEX_REGISTER 0x52
#define SBUS_WR_INSTRUCTION_POINTER 0x53
#define SBUS_CLEAR_ALL 0x5A
#define SBUS_CLEAR_FLAGS 0x5B
#define SBUS_CLEAR_OUTPUTS 0x5C
#define SBUS_CLEAR_REGISTERS 0x5D
#define SBUS_CLEAR_TIMERS 0x5E
#define SBUS_RESTART_WARM_CPU1 0x64
#define SBUS_RESTART_WARM_CPU2 0x65
#define SBUS_RESTART_WARM_CPU3 0x66
#define SBUS_RESTART_WARM_CPU4 0x67
#define SBUS_RESTART_WARM_CPU5 0x68
#define SBUS_RESTART_WARM_CPU6 0x69
#define SBUS_RESTART_WARM_OWN 0x6A
#define SBUS_RESTART_WARM_ALL 0x6B
#define SBUS_CHANGE_BLOCK 0x6E
#define SBUS_CLEAR_HISTORY_FAILURE 0x6F
#define SBUS_DELETE_PROGRAM_LINE 0x70
#define SBUS_GO_CONDITIONAL 0x71
#define SBUS_INSERT_PROGRAM_LINE 0x72
#define SBUS_LOCAL_CYCLE 0x73
#define SBUS_ALL_CYCLES 0x74
#define SBUS_MAKE_TEXT 0x75
#define SBUS_EXECUTE_SINGLE_INSTR 0x76
#define SBUS_SINGLE_STEP 0x77
#define SBUS_XOB_17_INTERRUPT 0x82
#define SBUS_XOB_18_INTERRUPT 0x83
#define SBUS_XOB_19_INTERRUPT 0x84
#define SBUS_RD_HANGUP_TIMEOUT 0x91
#define SBUS_RD_DATA_BLOCK 0x96
#define SBUS_WR_DATA_BLOCK 0x97
#define SBUS_MAKE_DATA_BLOCK 0x98
#define SBUS_CLEAR_DATA_BLOCK 0x99
#define SBUS_CLEAR_TEXT 0x9A
#define SBUS_RD_BLOCK_ADDRESSES 0x9B
#define SBUS_RD_BLOCK_SIZES 0x9C
#define SBUS_RD_CURRENT_BLOCK 0x9D
#define SBUS_RD_CALL_STACK 0x9E
#define SBUS_RD_DBX 0x9F
#define SBUS_RD_USER_EEPROM_REGISTER 0xA1
#define SBUS_WR_USER_EEPROM_REGISTER 0xA3
#define SBUS_ERASE_FLASH 0xA5
#define SBUS_RESTART_COLD_FLAG 0xA6
#define SBUS_WR_SYSTEM_BUFFER 0xA7
#define SBUS_RD_SYSTEM_BUFFER 0xA8
#define SBUS_RD_WR_PCD_BLOCK 0xA9
#define SBUS_GET_DIAGNOSTIC 0xAA
#define SBUS_RD_SYSTEM_INFORMATION 0xAB
#define SBUS_CHANGE_BLOCKS_ON_RUN 0xAC
#define SBUS_FLASHCARD_TELEGRAM 0xAD
#define SBUS_DOWNLOAD_FIRMWARE 0xAE
#define SBUS_WEB_SERVER_SERIAL_COMM 0xAF
/* Bitfield in the arithmetic flags and accu*/
#define F_ACCU (1<<0) /* Accumulator of PCD */
#define F_ERROR (1<<1) /* Error flag of PCD */
#define F_NEGATIVE (1<<2) /* Negative arithmetic status flag */
#define F_ZERO (1<<3) /* Zero arithmetic status flag */
/* Bitfield in the system information*/
/*#define F_EMPTY (1<<0) always 0 */
#define F_MEMSIZE (1<<1) /* Memory size information */
#define F_TRACE (1<<2) /* Trace buffer feature */
#define F_INFO_B1 (1<<3) /* EEPROM information of slot B1 */
#define F_INFO_B2 (1<<4) /* EEPROM information of slot B2 */
#define F_PGU_BAUD (1<<5) /* PGU baudrate can be switched */
/* Read/write block command codes*/
#define SBUS_WR_START_OF_STREAM 0x00
#define SBUS_WR_BLOCK_DATA_STREAM 0x01
#define SBUS_WR_BLOCK_END_OF_STREAM 0x02
#define SBUS_WR_ABORT_BLOCK_STREAM 0x07
#define SBUS_WR_BLOCK_DATA_BYTES 0x08
#define SBUS_RD_BLOCK_START_OF_STREAM 0X10
#define SBUS_RD_BLOCK_DATA_STREAM 0x11
#define SBUS_RD_ABORT_BLOCK_STREAM 0x17
#define SBUS_RD_BLOCK_DATA_BYTES 0x18
#define SBUS_DELETE_BLOCK 0x20
#define SBUS_GET_BLOCK_SIZE 0x21
#define SBUS_GET_PROGRAM_BLOCK_LIST 0x22
/* Read/write block types*/
#define SBUS_RD_WR_CONFIGURATION_FILE 0x20
#define SBUS_RD_WR_PROGRAM_BLOCK_FILE 0x21
#define SBUS_RD_WR_UNKNOWN_BLOCK_TYPE 0x83
/* Read/write block error codes*/
#define SBUS_RD_WR_NAK 0x80
#define SBUS_RD_WR_NAK_INVALID_SIZE 0x8A
/* Initialize the protocol and registered fields */
static int proto_sbus;
static int hf_sbus_length;
static int hf_sbus_version;
static int hf_sbus_protocol;
static int hf_sbus_sequence;
static int hf_sbus_attribut;
static int hf_sbus_dest;
static int hf_sbus_address;
static int hf_sbus_command;
static int hf_sbus_command_extension;
static int hf_sbus_rcount;
static int hf_sbus_multimedia_length;
static int hf_sbus_sub_length;
static int hf_sbus_wcount;
static int hf_sbus_wcount_calculated;
static int hf_sbus_fio_count;
static int hf_sbus_addr_rtc;
static int hf_sbus_addr_iof;
static int hf_sbus_addr_db;
static int hf_sbus_addr_base_element;
static int hf_sbus_addr_eeprom;
static int hf_sbus_addr_prog;
static int hf_sbus_addr_68k;
static int hf_sbus_block_type;
static int hf_sbus_block_nr;
static int hf_sbus_nbr_elements;
static int hf_sbus_display_register;
static int hf_sbus_data_rtc;
static int hf_sbus_data_byte;
static int hf_sbus_data_byte_hex;
static int hf_sbus_data_iof;
static int hf_sbus_cpu_type;
static int hf_sbus_fw_version;
static int hf_sbus_sysinfo_nr;
static int hf_sbus_sysinfo0_1;
static int hf_sbus_sysinfo0_2;
static int hf_sbus_sysinfo0_3;
static int hf_sbus_sysinfo0_4;
static int hf_sbus_sysinfo0_5;
static int hf_sbus_acknackcode;
static int hf_sbus_cpu_status;
static int hf_sbus_week_day;
static int hf_sbus_date;
static int hf_sbus_time;
static int hf_sbus_crc;
static int hf_sbus_crc_status;
static int hf_sbus_flags_accu;
static int hf_sbus_flags_error;
static int hf_sbus_flags_negative;
static int hf_sbus_flags_zero;
/* Web server telegram */
static int hf_sbus_web_size;
static int hf_sbus_web_aid;
static int hf_sbus_web_seq;
/* Read/Write block telegram*/
static int hf_sbus_rdwr_block_length;
static int hf_sbus_rdwr_block_length_ext;
static int hf_sbus_rdwr_telegram_type;
static int hf_sbus_rdwr_telegram_sequence;
static int hf_sbus_rdwr_block_size;
static int hf_sbus_rdwr_block_addr;
static int hf_sbus_rdwr_file_name;
static int hf_sbus_rdwr_list_type;
static int hf_sbus_rdwr_acknakcode;
/* Request-Response tracking */
static int hf_sbus_response_in;
static int hf_sbus_response_to;
static int hf_sbus_response_time;
static int hf_sbus_timeout;
static int hf_sbus_request_in;
/* Initialize the subtree pointers */
static int ett_sbus;
static int ett_sbus_ether;
static int ett_sbus_data;
static expert_field ei_sbus_retry;
static expert_field ei_sbus_telegram_not_acked;
static expert_field ei_sbus_crc_bad;
static expert_field ei_sbus_telegram_not_implemented;
static expert_field ei_sbus_no_request_telegram;
/* True/False strings*/
static const true_false_string tfs_sbus_flags= {
"Is high",
"Is low"
};
static const true_false_string tfs_sbus_present= {
"Is present",
"Is not present"
};
/* value to string definitions*/
/* telegram types*/
static const value_string sbus_att_vals[] = {
{0, "Request"},
{1, "Response"},
{2, "ACK/NAK"},
{0, NULL}
};
/* Block types (6 and 7 corrected C. Durrer, 20.02.2019)*/
static const value_string sbus_block_types[] = {
{0x00, "COB"}, /* Cyclic organization block */
{0x01, "XOB"}, /* Exception organization block */
{0x02, "PB"}, /* Program block */
{0x03, "FB"}, /* Function block */
{0x04, "ST"}, /* Step of Graftec structure*/
{0x05, "TR"}, /* Transition of Graftec structure*/
{0x06, "TEXT"}, /* Text*/
{0x07, "DB"}, /* Data Block*/
{0x08, "SB"}, /* Sequential Block (Graftec)*/
{0x09, "DBX"}, /* Special Data Block*/
{0x10, "BACnet"}, /* BACnet configuration block */
{0x11, "CANopen"}, /* CANopen configuration */
{0x12, "LONIP"}, /* LONIP configuration */
{0x20, "Configuration file"}, /* LONIP configuration */
{0x21, "Program block file"}, /* LONIP configuration */
{0xFE, "All configuration blocks"}, /* all configuration blocks (delete blocks only) */
{0xFF, "All blocks"}, /* all blocks (incl. program blocks) (delete blocks only) */
{0, NULL}
};
static value_string_ext sbus_block_types_ext = VALUE_STRING_EXT_INIT(sbus_block_types);
/* ACK NAK values*/
static const value_string sbus_CPU_status[] = {
{0x43, "C"},
{0x44, "D"},
{0x48, "Halt"},
{0x52, "Run"},
{0x53, "Stop"},
{0x58, "X, Exceptional Intermediate Status (MODEMS+)"},
{0, NULL}
};
/* CPU status*/
static const value_string sbus_ack_nak_vals[] = {
{0, "ACK (Acknowledged)"},
{1, "NAK, no reason specified"},
{2, "NAK, because of password"},
{3, "NAK, PGU port is in reduced protocol"},
{4, "NAK, PGU port is already used"},
{0, NULL}
};
/* S-Bus commands*/
static const value_string sbus_command_vals[] = {
{0x00, "Read counter(s)"},
{0x01, "Read display register"},
{0x02, "Read flag(s)"},
{0x03, "Read input(s)"},
{0x04, "Read real time clock"},
{0x05, "Read output(s)"},
{0x06, "Read register(s)"},
{0x07, "Read timer(s)"},
{0x0A, "Write counter(s)"},
{0x0B, "Write flag(s)"},
{0x0C, "Write real time clock"},
{0x0D, "Write output(s)"},
{0x0E, "Write register(s)"},
{0x0F, "Write timer(s)"},
{0x13, "Read write multi-medias"},
{0x14, "Read PCD status, CPU 0"},
{0x15, "Read PCD status, CPU 1"},
{0x16, "Read PCD status, CPU 2"},
{0x17, "Read PCD status, CPU 3"},
{0x18, "Read PCD status, CPU 4"},
{0x19, "Read PCD status, CPU 5"},
{0x1A, "Read PCD status, CPU 6"},
{0x1B, "Read PCD status (own)"},
{0x1D, "Read S-Bus station number"},
{0x1E, "Read user memory*"},
{0x1F, "Read program line*"},
{0x20, "Read firmware version"},
{0x21, "Read text*"},
{0x22, "Read active transition*"},
{0x23, "Write user memory*"},
{0x24, "Write program line*"},
{0x25, "Write text*"},
{0x28, "Run procedure*, CPU 0"},
{0x29, "Run procedure*, CPU 1"},
{0x2A, "Run procedure*, CPU 2"},
{0x2B, "Run procedure*, CPU 3"},
{0x2C, "Run procedure*, CPU 4"},
{0x2D, "Run procedure*, CPU 5"},
{0x2E, "Run procedure*, CPU 6"},
{0x2F, "Run procedure* (own CPU)"},
{0x30, "Run procedure* (All CPUs)"},
{0x32, "Restart cold CPU 1*"},
{0x33, "Restart cold CPU 2*"},
{0x34, "Restart cold CPU 3*"},
{0x35, "Restart cold CPU 4*"},
{0x36, "Restart cold CPU 5*"},
{0x37, "Restart cold CPU 6*"},
{0x38, "Restart cold own CPU*"},
{0x39, "Restart cold all CPUs*"},
{0x3C, "Stop procedure*, CPU 0"},
{0x3D, "Stop procedure*, CPU 1"},
{0x3E, "Stop procedure*, CPU 2"},
{0x3F, "Stop procedure*, CPU 3"},
{0x40, "Stop procedure*, CPU 4"},
{0x41, "Stop procedure*, CPU 5"},
{0x42, "Stop procedure*, CPU 6"},
{0x43, "Stop procedure*, (own CPU)"},
{0x44, "Stop procedure*, (All CPUs)"},
{0x46, "Read arithmetic status and ACCU*"},
{0x47, "Read byte"},
{0x48, "Read halt failure register*"},
{0x49, "Read index register*"},
{0x4A, "Read instruction pointer*"},
{0x4B, "Find history*"},
{0x50, "Write arithmetic status and ACCU*"},
{0x51, "Write byte*"},
{0x52, "Write index register"},
{0x53, "Write instruction pointer*"},
{0x5A, "Clear all (F, O, R, T)*"},
{0x5B, "Clear flags*"},
{0x5C, "Clear outputs*"},
{0x5D, "Clear registers*"},
{0x5E, "Clear timers*"},
{0x64, "Restart warm CPU 1*"},
{0x65, "Restart warm CPU 2*"},
{0x66, "Restart warm CPU 3*"},
{0x67, "Restart warm CPU 4*"},
{0x68, "Restart warm CPU 5*"},
{0x69, "Restart warm CPU 6*"},
{0x6A, "Restart warm (own CPU)*"},
{0x6B, "Restart warm (All CPUs)*"},
{0x6E, "Change block*"},
{0x6F, "Clear history failure*"},
{0x70, "Delete program line*"},
{0x71, "Go conditional*"},
{0x72, "Insert program line*"},
{0x73, "Local cycles*"},
{0x74, "All cycles*"},
{0x75, "Make text*"},
{0x76, "Execute single instruction*"},
{0x77, "Single step*"},
{0x82, "XOB 17 interrupt"},
{0x83, "XOB 18 interrupt"},
{0x84, "XOB 19 interrupt"},
{0x91, "Read hangup timeout"},
{0x96, "Read data block"},
{0x97, "Write data block"},
{0x98, "Make data block*"},
{0x99, "Clear data block*"},
{0x9A, "Clear text*"},
{0x9B, "Read block address"},
{0x9C, "Read block sizes"},
{0x9D, "Read current block*"},
{0x9E, "Read call stack*"},
{0x9F, "Read DBX"},
{0xA1, "Read user EEPROM register"},
{0xA3, "Write user EEPROM register"},
{0xA5, "Erase flash*"},
{0xA6, "Restart cold flag*"},
{0xA7, "Write system buffer"},
{0xA8, "Read system buffer"},
{0xA9, "Read/write block data*"},
{0xAA, "Get diagnostic*"},
{0xAB, "Read system information*"},
{0xAC, "Changes blocks on run*"},
{0xAD, "Flashcard telegram*"},
{0xAE, "Download FW*"},
{0xAF, "Web server serial communication*"},
{0, NULL}
};
static value_string_ext sbus_command_vals_ext = VALUE_STRING_EXT_INIT(sbus_command_vals);
static const value_string webserver_aid_vals[] = {
{0x01, "Partial request"},
{0x02, "Request end"},
{0x07, "Get Data"},
{0x10, "Transfer OK"},
{0x11, "Partial answer"},
{0x12, "Last part of answer"},
{0x13, "Server not ready"},
{0, NULL}
};
static const value_string rdwrblock_vals[] = {
{0x00, "WR block start of stream"},
{0x01, "WR block data stream"},
{0x02, "WR block end of stream"},
{0x07, "Abort block WR stream"},
{0x08, "WR block data"},
{0x10, "RD block start of stream"},
{0x11, "RD block data stream"},
{0x17, "Abort block RD stream"},
{0x18, "RD block data"},
{0x20, "Delete block"},
{0x21, "Get block size"},
{0x22, "Get program block list"},
{0, NULL}
};
static value_string_ext rdwrblock_vals_ext = VALUE_STRING_EXT_INIT(rdwrblock_vals);
static const value_string rdwrblock_sts[] = {
{0x00, "ACK (Acknowledged)"},
{0x01, "Data"},
{0x02, "Busy"},
{0x03, "End of stream"},
{0x04, "Data EOF reached"},
{0x80, "NAK"},
{0x81, "NAK, unknown Tlg_Type"},
{0x82, "NAK, not supported Tlg_Type"},
{0x83, "NAK, unknown Block Type"},
{0x84, "NAK, out of sequence"},
{0x85, "NAK, not supported Block number"},
{0x86, "NAK, Block Size invalid (to big)"},
{0x87, "NAK, Block Address invalid"},
{0x88, "NAK, CRC invalid"},
{0x89, "NAK, invalid status"},
{0x8A, "NAK, invalid command size (w-count)"},
{0xFF, "Abort (stream)"},
{0, NULL}
};
static value_string_ext rdwrblock_sts_ext = VALUE_STRING_EXT_INIT(rdwrblock_sts);
static const value_string rdwrblock_list_type_vals[] = {
{0x40, "Start request of program block"},
{0x41, "Get next program block"},
{0xFF, "Abort get list"},
{0, NULL}
};
static const unsigned crc_table[] = {
0x0000,0x1021,0x2042,0x3063,0x4084,0x50a5,0x60c6,0x70e7,0x8108,0x9129,0xa14a,0xb16b,0xc18c,0xd1ad,0xe1ce,0xf1ef,
0x1231,0x0210,0x3273,0x2252,0x52b5,0x4294,0x72f7,0x62d6,0x9339,0x8318,0xb37b,0xa35a,0xd3bd,0xc39c,0xf3ff,0xe3de,
0x2462,0x3443,0x0420,0x1401,0x64e6,0x74c7,0x44a4,0x5485,0xa56a,0xb54b,0x8528,0x9509,0xe5ee,0xf5cf,0xc5ac,0xd58d,
0x3653,0x2672,0x1611,0x0630,0x76d7,0x66f6,0x5695,0x46b4,0xb75b,0xa77a,0x9719,0x8738,0xf7df,0xe7fe,0xd79d,0xc7bc,
0x48c4,0x58e5,0x6886,0x78a7,0x0840,0x1861,0x2802,0x3823,0xc9cc,0xd9ed,0xe98e,0xf9af,0x8948,0x9969,0xa90a,0xb92b,
0x5af5,0x4ad4,0x7ab7,0x6a96,0x1a71,0x0a50,0x3a33,0x2a12,0xdbfd,0xcbdc,0xfbbf,0xeb9e,0x9b79,0x8b58,0xbb3b,0xab1a,
0x6ca6,0x7c87,0x4ce4,0x5cc5,0x2c22,0x3c03,0x0c60,0x1c41,0xedae,0xfd8f,0xcdec,0xddcd,0xad2a,0xbd0b,0x8d68,0x9d49,
0x7e97,0x6eb6,0x5ed5,0x4ef4,0x3e13,0x2e32,0x1e51,0x0e70,0xff9f,0xefbe,0xdfdd,0xcffc,0xbf1b,0xaf3a,0x9f59,0x8f78,
0x9188,0x81a9,0xb1ca,0xa1eb,0xd10c,0xc12d,0xf14e,0xe16f,0x1080,0x00a1,0x30c2,0x20e3,0x5004,0x4025,0x7046,0x6067,
0x83b9,0x9398,0xa3fb,0xb3da,0xc33d,0xd31c,0xe37f,0xf35e,0x02b1,0x1290,0x22f3,0x32d2,0x4235,0x5214,0x6277,0x7256,
0xb5ea,0xa5cb,0x95a8,0x8589,0xf56e,0xe54f,0xd52c,0xc50d,0x34e2,0x24c3,0x14a0,0x0481,0x7466,0x6447,0x5424,0x4405,
0xa7db,0xb7fa,0x8799,0x97b8,0xe75f,0xf77e,0xc71d,0xd73c,0x26d3,0x36f2,0x0691,0x16b0,0x6657,0x7676,0x4615,0x5634,
0xd94c,0xc96d,0xf90e,0xe92f,0x99c8,0x89e9,0xb98a,0xa9ab,0x5844,0x4865,0x7806,0x6827,0x18c0,0x08e1,0x3882,0x28a3,
0xcb7d,0xdb5c,0xeb3f,0xfb1e,0x8bf9,0x9bd8,0xabbb,0xbb9a,0x4a75,0x5a54,0x6a37,0x7a16,0x0af1,0x1ad0,0x2ab3,0x3a92,
0xfd2e,0xed0f,0xdd6c,0xcd4d,0xbdaa,0xad8b,0x9de8,0x8dc9,0x7c26,0x6c07,0x5c64,0x4c45,0x3ca2,0x2c83,0x1ce0,0x0cc1,
0xef1f,0xff3e,0xcf5d,0xdf7c,0xaf9b,0xbfba,0x8fd9,0x9ff8,0x6e17,0x7e36,0x4e55,0x5e74,0x2e93,0x3eb2,0x0ed1,0x1ef0
};
/* Conversion values passing structure*/
typedef struct {
uint32_t conversation; /*Conversation ID*/
uint16_t sequence; /*Sequence number of request telegram*/
} sbus_request_key;
typedef struct {
uint8_t cmd_code; /*multimedia command code*/
uint8_t count; /*rcount of sub-request*/
} sbus_subrequest;
typedef struct {
uint8_t cmd_code; /*command code from request*/
uint8_t count; /*rcount value*/
uint8_t sysinfo; /*system information number*/
uint8_t block_tlg; /*telegram type of RD/WR block telegrams*/
uint8_t retry_count; /*number of retries*/
uint32_t req_frame; /*frame number of last request*/
uint32_t resp_frame; /*frame number of response*/
nstime_t req_time; /*time of the last request*/
uint8_t mm_request_count; /*multi-media subrequest count*/
wmem_list_t *sbus_subrequests; /*list containing sub requests of multi-media request*/
} sbus_request_val;
/* The hash structure (for conversations)*/
static wmem_map_t *sbus_request_hash;
static unsigned crc_calc (unsigned crc, unsigned val)
{
int indx;
unsigned ncrc;
indx = (((crc >> 8) ^ val) & 0xff);
ncrc = crc_table[indx] ^ ((crc << 8) & 0xffff);
return ncrc;
}
/* Hash functions*/
static int sbus_equal(const void *v, const void *w)
{
const sbus_request_key *v1 = (const sbus_request_key *)v;
const sbus_request_key *v2 = (const sbus_request_key *)w;
if (v1->conversation == v2->conversation &&
v1->sequence == v2->sequence) {
return 1;
}
return 0;
}
static unsigned sbus_hash(const void *v)
{
const sbus_request_key *key = (const sbus_request_key *)v;
unsigned val;
val = key->conversation + key->sequence;
return val;
}
/* check whether the packet looks like SBUS or not */
static bool
is_sbus_pdu(tvbuff_t *tvb)
{
uint32_t length;
/* we need at least 8 bytes to determine whether this is sbus or
not*/
if(tvb_captured_length(tvb)<8){
return false;
}
/* the length must be >= 8 bytes to accommodate the header,
it also must be <65536 to fit inside a udp packet
*/
length=tvb_get_ntohl(tvb, 0);
if ( (length<8) || (length>65535) ) {
return false;
}
if (tvb_reported_length(tvb) != length) {
return false;
}
/* First four byte indicate the length which must be at least 12 bytes*/
if (tvb_get_ntohl(tvb, 0) < 12) {
return false;
}
/* Fifth byte indicates protocol version which can be 0 or 1*/
if (tvb_get_uint8(tvb, 4) > 0x01) {
return false;
}
/* Sixth byte indicates protocol type and must be 0*/
if ( tvb_get_uint8(tvb, 5) > 0x01 ) {
return false;
}
/* Seventh and eighth bytes indicate the packet sequence number and can
be 0 to 65565 (--> check does not make sense)*/
/* Ninth byte the "attributes character" and must be either 0, 1 or 2
(request, response or ACK/NAK)*/
if (tvb_get_uint8(tvb, 8) > 0x02 ) {
return false;
}
return true;
}
/*add the tree structure for one request media type to the tree*/
static int add_media_access_to_tree(int sbus_cmd_code, tvbuff_t *tvb, proto_tree *tree, int offset)
{
int i, j;
int sbus_media_cnt;
proto_tree *sub_tree;
uint8_t sbus_fio_cnt;
uint32_t sbus_binaries;
uint32_t sbus_binarymasked;
uint32_t sbus_show_bin;
uint32_t sbus_helper;
switch (sbus_cmd_code) {
/*Read Counter, Register or Timer*/
case SBUS_RD_COUNTER:
case SBUS_RD_REGISTER:
case SBUS_RD_TIMER:
sbus_media_cnt = (tvb_get_uint8(tvb,offset))+1;
proto_tree_add_uint(tree,
hf_sbus_rcount, tvb, offset, 1, sbus_media_cnt);
offset += 1;
proto_tree_add_item(tree,
hf_sbus_addr_rtc, tvb, offset, 2, ENC_BIG_ENDIAN);
offset += 2;
break;
/*Read Flag, Input or Output*/
case SBUS_RD_FLAG:
case SBUS_RD_INPUT:
case SBUS_RD_OUTPUT:
sbus_media_cnt = (tvb_get_uint8(tvb,offset))+1;
proto_tree_add_uint(tree,
hf_sbus_rcount, tvb, offset, 1, sbus_media_cnt);
offset += 1;
proto_tree_add_item(tree,
hf_sbus_addr_iof, tvb, offset, 2, ENC_BIG_ENDIAN);
offset += 2;
break;
/*Write Register Timer Counter*/
case SBUS_WR_COUNTER:
case SBUS_WR_REGISTER:
case SBUS_WR_TIMER:
sbus_media_cnt = (tvb_get_uint8(tvb,offset));
sbus_media_cnt = ((sbus_media_cnt - 1)/4);
proto_tree_add_uint(tree,
hf_sbus_wcount_calculated, tvb, offset,
1, sbus_media_cnt);
proto_tree_add_item(tree,
hf_sbus_wcount, tvb, offset, 1, ENC_BIG_ENDIAN);
offset += 1;
proto_tree_add_item(tree,
hf_sbus_addr_rtc, tvb, offset, 2, ENC_BIG_ENDIAN);
offset += 2;
/*Add subtree for Data*/
sub_tree = proto_tree_add_subtree(tree, tvb, offset,
((sbus_media_cnt) * 4), ett_sbus_data, NULL, "Data");
for (i=((sbus_media_cnt)); i>0; i--) {
proto_tree_add_item(sub_tree,
hf_sbus_data_rtc, tvb, offset,
4, ENC_BIG_ENDIAN);
offset += 4;
}
break;
/* Write flags and outputs*/
case SBUS_WR_FLAG:
case SBUS_WR_OUTPUT:
sbus_media_cnt = (tvb_get_uint8(tvb,offset));
sbus_media_cnt = (sbus_media_cnt - 2);
proto_tree_add_uint(tree,
hf_sbus_wcount_calculated, tvb, offset,
1, sbus_media_cnt);
proto_tree_add_item(tree,
hf_sbus_wcount, tvb, offset, 1, ENC_BIG_ENDIAN);
offset += 1;
proto_tree_add_item(tree,
hf_sbus_addr_iof, tvb, offset, 2, ENC_BIG_ENDIAN);
offset += 2;
sbus_fio_cnt = (tvb_get_uint8(tvb,offset));
sbus_fio_cnt = ((sbus_fio_cnt + 1));
proto_tree_add_uint(tree,
hf_sbus_fio_count, tvb, offset, 1, sbus_fio_cnt);
offset += 1;
/*Add subtree for Data*/
sub_tree = proto_tree_add_subtree(tree, tvb, offset,
sbus_media_cnt, ett_sbus_data, NULL, "Data");
for (i=sbus_media_cnt; i>0; i--) {
sbus_helper = 1;
sbus_show_bin = 0;
sbus_binarymasked = 0x01;
sbus_binaries = tvb_get_uint8(tvb, offset);
for (j=0; j<8; j++) {
if ((sbus_binarymasked & sbus_binaries) != 0) {
sbus_show_bin = (sbus_show_bin + sbus_helper);
}
sbus_binarymasked = sbus_binarymasked<<1;
sbus_helper = 10 * sbus_helper;
}
proto_tree_add_uint_format(sub_tree,
hf_sbus_data_iof, tvb, offset, 1, sbus_show_bin,
"Binary data: %08u", sbus_show_bin);
offset += 1;
}
break;
case SBUS_RD_DATA_BLOCK:
sbus_media_cnt = (tvb_get_uint8(tvb,offset))+1;
proto_tree_add_uint(tree,
hf_sbus_rcount, tvb, offset, 1, sbus_media_cnt);
offset += 1;
proto_tree_add_item(tree,
hf_sbus_addr_db, tvb, offset, 2, ENC_BIG_ENDIAN);
offset += 2;
/*add base element address*/
proto_tree_add_item(tree,
hf_sbus_addr_base_element, tvb, offset, 2, ENC_BIG_ENDIAN);
offset += 2;
break;
}
return offset;
}
/*add the tree structure for one response media type to the tree*/
static int add_media_response_to_tree(int cmd_code, int count, tvbuff_t *tvb, proto_tree *tree, int offset)
{
int i, j;
proto_tree *sub_tree;
uint32_t sbus_binaries;
uint32_t sbus_binarymasked;
uint32_t sbus_show_bin;
uint32_t sbus_helper;
switch (cmd_code) {
/*Add subtree for Data*/
case SBUS_RD_COUNTER:
case SBUS_RD_REGISTER:
case SBUS_RD_TIMER:
case SBUS_RD_USER_MEMORY:
case SBUS_RD_PROGRAM_LINE:
case SBUS_RD_USER_EEPROM_REGISTER:
case SBUS_RD_DATA_BLOCK:
sub_tree = proto_tree_add_subtree(tree, tvb, offset,
(count * 4), ett_sbus_data, NULL, "Data");
for (i=count; i>0; i--) {
proto_tree_add_item(sub_tree,
hf_sbus_data_rtc, tvb, offset,
4, ENC_BIG_ENDIAN);
offset += 4;
}
break;
/* Add binary data I, O, F*/
case SBUS_RD_FLAG:
case SBUS_RD_INPUT:
case SBUS_RD_OUTPUT:
/*Add subtree for Data*/
sub_tree = proto_tree_add_subtree(tree, tvb, offset,
(((count) + 7) / 8), ett_sbus_data, NULL, "Data");
for (i=(((count) + 7) / 8); i>0; i--) {
sbus_helper = 1;
sbus_show_bin = 0;
sbus_binarymasked = 0x01;
sbus_binaries = tvb_get_uint8(tvb, offset);
for (j=0; j<8; j++){
if ((sbus_binarymasked & sbus_binaries) != 0) {
sbus_show_bin = (sbus_show_bin + sbus_helper);
}
sbus_binarymasked = sbus_binarymasked<<1;
sbus_helper = 10 * sbus_helper;
}
proto_tree_add_uint_format(sub_tree,
hf_sbus_data_iof, tvb, offset, 1, sbus_show_bin,
"Binary data: %08u", sbus_show_bin);
offset += 1;
}
break;
}
return offset;
}
static int get_response_length(int cmd_code, int count)
{
int length;
length = 0;
switch (cmd_code) {
/*Get length of 32 bit data*/
case SBUS_RD_COUNTER:
case SBUS_RD_REGISTER:
case SBUS_RD_TIMER:
case SBUS_RD_USER_MEMORY:
case SBUS_RD_PROGRAM_LINE:
case SBUS_RD_USER_EEPROM_REGISTER:
case SBUS_RD_DATA_BLOCK:
length = count * 4;
break;
/* Get length of binary data I, O, F*/
case SBUS_RD_FLAG:
case SBUS_RD_INPUT:
case SBUS_RD_OUTPUT:
length = ((count) + 7) / 8;
break;
}
return length;
}
static int add_sbus_subrequest(tvbuff_t *tvb, wmem_list_t *request_list, int offset)
{
/*append subrequest info to requests lists and return number of sub-requests*/
int subrequest_count;
int internal_wcount;
int internal_subwcount;
int internal_offset;
int internal_last_offset;
internal_offset = offset;
subrequest_count = 0;
internal_wcount = tvb_get_uint8(tvb,internal_offset);
internal_last_offset = internal_wcount + offset + 1; /*check for new sub requests until this end offset*/
for(int i=0; i < 64; i +=1){ /*max sub-requests number is 64*/
if (internal_last_offset > internal_offset) {
sbus_subrequest *sub_req;
sub_req = wmem_new(wmem_file_scope(), sbus_subrequest);
internal_offset += 1; /*move to the next sub-request wcount*/
internal_subwcount = tvb_get_uint8(tvb,internal_offset);
internal_offset += 1;
sub_req->cmd_code = tvb_get_uint8(tvb,internal_offset);
internal_offset += 1;
sub_req->count = tvb_get_uint8(tvb,internal_offset) + 1;
internal_offset += internal_subwcount -1;
subrequest_count += 1;
wmem_list_append(request_list, sub_req);
}
}
return subrequest_count;
}
/*Dissect the telegram*/
static int
dissect_sbus(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
{
/* Set up structures needed to add the protocol subtree and manage it */
proto_item *ti, *hi;
proto_tree *sbus_tree, *ethsbus_tree, *sbusdata_tree, *sbus_multimedia_tree;
int i; /*for CRC calculation*/
int offset;
int sbus_end_multimedia;
int sbus_eth_len;
unsigned sbus_crc_calc;
uint8_t sbus_attribut;
uint8_t sbus_media_cnt;
sbus_subrequest *mm_sub_req;
wmem_list_frame_t *frame;
uint8_t sbus_multimedia_total;
uint8_t sbus_multimedia_cnt;
uint8_t sbus_multimedia_cmd;
uint8_t sbus_multimedia_att;
uint8_t sbus_multimedia_bytes;
uint8_t sbus_cmd_code;
uint8_t sbus_web_size;
uint8_t sbus_web_aid;
uint8_t sbus_web_seq;
uint8_t sbus_rdwr_type;
uint8_t sbus_rdwr_sequence;
uint8_t sbus_rdwr_block_tlg;
uint8_t sbus_rdwr_block_type;
uint8_t sbus_rdwr_ack_nak;
uint8_t sbus_quint8_helper0;
uint16_t sbus_ack_code;
uint32_t sbus_rdwr_length;
uint32_t sbus_helper;
uint32_t sbus_helper1;
uint32_t sbus_helper2;
char *tmp_string;
nstime_t ns; /*we use this for the response time*/
/* Set up conversations*/
conversation_t *conversation;
sbus_request_key request_key, *new_request_key;
sbus_request_val *request_val;
/*sbus_multimedia_requests *multimedia_requests;*/
/* does this look like an sbus pdu? */
if(!is_sbus_pdu(tvb)){
return 0;
}
/* Make entries in Protocol column and Info column on summary display */
col_set_str(pinfo->cinfo, COL_PROTOCOL, "S-Bus");
col_clear(pinfo->cinfo, COL_INFO);
conversation = find_or_create_conversation(pinfo);
request_key.conversation = conversation->conv_index;
request_key.sequence = tvb_get_ntohs(tvb,6);
request_val = (sbus_request_val *) wmem_map_lookup(sbus_request_hash,
&request_key);
/*Get type of telegram for finding retries
*As we are storing the info in a hash table we need to update the info
*also in case this is no retry*/
sbus_attribut = tvb_get_uint8(tvb,8);
if (request_val && sbus_attribut == SBUS_REQUEST) {
if (request_val->req_frame < pinfo->num){ /*a retry; req_frame smaller this frame*/
request_val->retry_count +=1;
}
else { /*we have a conversation but this is not a retry so we store the packet info*/
request_val->retry_count = 0;
request_val->req_frame = pinfo->num; /*store actual frame nr.*/
request_val->req_time = pinfo->abs_ts;
}
}
if (request_val && (sbus_attribut == SBUS_RESPONSE ||
sbus_attribut == SBUS_ACKNAK)) { /*a response*/
request_val->resp_frame = pinfo->num; /*so store this frame nr.*/
}
/* Only allocate a new hash element when it's a request*/
sbus_attribut = tvb_get_uint8(tvb,8);
if ( !request_val && sbus_attribut == 0 ) {/* request telegram */
new_request_key = wmem_new(wmem_file_scope(), sbus_request_key);
*new_request_key = request_key;
request_val = wmem_new(wmem_file_scope(), sbus_request_val);
request_val->cmd_code=tvb_get_uint8(tvb,10);
request_val->retry_count=0;
request_val->req_frame = pinfo->num; /*store actual frame nr.*/
request_val->req_time = pinfo->abs_ts;
request_val->resp_frame = 0; /*response frame is not known yet*/
request_val->mm_request_count = 0; /*init to 0 in case it is no multi media request*/
if (((request_val->cmd_code) == SBUS_RD_USER_EEPROM_REGISTER) ||
((request_val->cmd_code) == SBUS_WR_USER_EEPROM_REGISTER)) {
request_val->count=((tvb_get_uint8(tvb,12))+1);
} else if ((request_val->cmd_code) == SBUS_RDWR_MULTI_MEDIAS) {
request_val->count=tvb_get_uint8(tvb,11); /*length of all sub requests in bytes*/
/*create list for sub requests to be able to process response frame later on*/
request_val->sbus_subrequests = wmem_list_new(wmem_file_scope());
/*add the sub requests to the list*/
request_val->mm_request_count = add_sbus_subrequest(tvb, request_val->sbus_subrequests, 11);
} else {
request_val->count=((tvb_get_uint8(tvb,11))+1);
}
/*Enter system info or telegram type (for rd/wr block telegrams)*/
if ((request_val->cmd_code) == SBUS_RD_SYSTEM_INFORMATION) {
request_val->sysinfo=(tvb_get_uint8(tvb,12));
request_val->block_tlg=0x0;
} else if ((request_val->cmd_code) == SBUS_RD_WR_PCD_BLOCK) {
request_val->sysinfo=0x0;
request_val->block_tlg=(tvb_get_uint8(tvb,12));
} else {
request_val->sysinfo = 0x0;
request_val->block_tlg = 0x0;
}
wmem_map_insert(sbus_request_hash, new_request_key, request_val);
}
/* End of attaching data to hash table*/
offset = 0;
switch (sbus_attribut){
case SBUS_REQUEST:
sbus_cmd_code = tvb_get_uint8(tvb, 10);
switch (sbus_cmd_code){
case SBUS_WEB_SERVER_SERIAL_COMM:
/* Special treatment of web server request
* as this is very helpful to see more information in the packetlist */
sbus_web_aid = tvb_get_uint8(tvb, 12);
sbus_web_seq = tvb_get_uint8(tvb, 13);
col_add_fstr(pinfo->cinfo, COL_INFO,
"Web Server Request: %s (Seq No: %d)",
val_to_str_const(sbus_web_aid,
webserver_aid_vals,
"Unknown Request!"),
sbus_web_seq);
break;
case SBUS_RDWR_MULTI_MEDIAS:
col_add_fstr( pinfo->cinfo, COL_INFO,
"Request: Multi media telegram (%d sub requests)",
request_val->mm_request_count);
break;
case SBUS_RD_WR_PCD_BLOCK:
sbus_rdwr_type = tvb_get_uint8(tvb, 12);
col_add_fstr( pinfo->cinfo, COL_INFO,
"Request: %s",
val_to_str_ext_const(sbus_rdwr_type,
&rdwrblock_vals_ext,
"This RD/WR block telegram is not implemented"));
/* Add name of file to be written in case of start of file stream */
if (sbus_rdwr_type == SBUS_WR_START_OF_STREAM) {
sbus_rdwr_block_type = tvb_get_uint8(tvb, 14);
if ((sbus_rdwr_block_type == SBUS_RD_WR_CONFIGURATION_FILE) ||
(sbus_rdwr_block_type == SBUS_RD_WR_PROGRAM_BLOCK_FILE)) {
sbus_quint8_helper0=0;
for (i=19; i<43; i++) { /*max length is 24 chars*/
/*find zero-termination of string*/
if ((tvb_get_uint8(tvb, i)) == 0x00) {
break;
}
sbus_quint8_helper0 += 1;
}
tmp_string = tvb_get_string_enc(pinfo->pool, tvb , 19,
sbus_quint8_helper0, ENC_ASCII);
col_append_fstr(pinfo->cinfo, COL_INFO,
": (File: %s)", tmp_string);
}
} else if (sbus_rdwr_type == SBUS_RD_BLOCK_START_OF_STREAM) {
sbus_rdwr_block_type = tvb_get_uint8(tvb, 14);
if ((sbus_rdwr_block_type == SBUS_RD_WR_CONFIGURATION_FILE) ||
(sbus_rdwr_block_type == SBUS_RD_WR_PROGRAM_BLOCK_FILE)) {
sbus_quint8_helper0=0;
for (i=15; i<39; i++) { /*max length is 24 chars*/
/*find zero-termination of string*/
if ((tvb_get_uint8(tvb, i)) == 0x00) {
break;
}
sbus_quint8_helper0 += 1;
}
tmp_string = tvb_get_string_enc(pinfo->pool, tvb , 15,
sbus_quint8_helper0, ENC_ASCII);
col_append_fstr(pinfo->cinfo, COL_INFO,
": (File: %s)", tmp_string);
}
}
break;
default:
/* All other requests */
col_add_fstr(pinfo->cinfo, COL_INFO,
"Request: %s",
val_to_str_ext_const(sbus_cmd_code,
&sbus_command_vals_ext,
"Unknown Command!"));
break;
}
/*mark retries*/
if (request_val->retry_count>0) {
col_append_str(pinfo->cinfo, COL_INFO,
" (Retry)");
} /*no retry number as it is not always correctly calculated*/
break;
case SBUS_RESPONSE:
/* Special treatment of web server request
* as this is very helpful to see more information in the packetlist */
if (request_val && ((request_val->cmd_code) == SBUS_WEB_SERVER_SERIAL_COMM)) {
sbus_web_size = tvb_get_uint8(tvb,9);
sbus_web_aid = tvb_get_uint8(tvb,10);
col_add_fstr(pinfo->cinfo, COL_INFO,
"Response: %s",
val_to_str_const(sbus_web_aid,
webserver_aid_vals, "Unknown Request!"));
if (sbus_web_size > 1) {
sbus_web_seq = tvb_get_uint8(tvb,11);
col_append_fstr(pinfo->cinfo, COL_INFO,
" (Seq No: %d)",
sbus_web_seq);
}
} else if (request_val && ((request_val->cmd_code) == SBUS_RDWR_MULTI_MEDIAS)) {
/* Add some info for multi media response*/
col_append_fstr(pinfo->cinfo, COL_INFO,
"Response: Multi media (%d responses)",
request_val->mm_request_count);
} else if (request_val && ((request_val->cmd_code) == SBUS_RD_WR_PCD_BLOCK)) {
/* Treat the ACK/NAK telgrams in a special way*/
switch (request_val->block_tlg) {
case SBUS_WR_START_OF_STREAM:
case SBUS_WR_BLOCK_DATA_STREAM:
case SBUS_WR_BLOCK_END_OF_STREAM:
case SBUS_WR_ABORT_BLOCK_STREAM:
case SBUS_WR_BLOCK_DATA_BYTES:
case SBUS_DELETE_BLOCK:
case SBUS_RD_ABORT_BLOCK_STREAM:
sbus_rdwr_ack_nak = tvb_get_uint8(tvb, 10);
col_add_fstr( pinfo->cinfo, COL_INFO,
"Response: %s",
val_to_str_ext_const(sbus_rdwr_ack_nak,
&rdwrblock_sts_ext,
"Unknown response!"));
break;
default:
sbus_rdwr_type = tvb_get_uint8(tvb, 9);
col_add_fstr( pinfo->cinfo, COL_INFO,
"Response: (%d byte)", sbus_rdwr_type);
break;
}
} else {
col_set_str(pinfo->cinfo, COL_INFO, "Response");
}
break;
case SBUS_ACKNAK:
sbus_ack_code = tvb_get_ntohs(tvb,9);
col_set_str(pinfo->cinfo, COL_INFO,
val_to_str_const(sbus_ack_code,
sbus_ack_nak_vals,
"Unknown NAK response code!"));
break;
default:
col_set_str(pinfo->cinfo, COL_INFO, "Unknown attribute");
break;
}
/* create display subtree for the protocol */
if (tree) {
ti = proto_tree_add_item(tree, proto_sbus, tvb, offset, -1, ENC_NA);
sbus_tree = proto_item_add_subtree(ti, ett_sbus);
/*Add subtree for Ether-S-Bus header*/
ethsbus_tree = proto_tree_add_subtree(sbus_tree, tvb, offset, 8, ett_sbus_ether, NULL, "Ether-S-Bus header");
/* add an item to the subtree*/
sbus_eth_len = tvb_get_ntohl(tvb,offset);
proto_tree_add_item(ethsbus_tree,
hf_sbus_length, tvb, offset, 4, ENC_BIG_ENDIAN);
offset += 4;
proto_tree_add_item(ethsbus_tree,
hf_sbus_version, tvb, offset, 1, ENC_BIG_ENDIAN);
offset += 1;
proto_tree_add_item(ethsbus_tree,
hf_sbus_protocol, tvb, offset, 1, ENC_BIG_ENDIAN);
offset += 1;
proto_tree_add_item(ethsbus_tree,
hf_sbus_sequence, tvb, offset, 2, ENC_BIG_ENDIAN);
offset += 2;
/* Continue adding stuff to the main tree*/
sbus_attribut = tvb_get_uint8(tvb,offset);
proto_tree_add_item(sbus_tree,
hf_sbus_attribut, tvb, offset, 1, ENC_BIG_ENDIAN);
offset += 1;
if (sbus_attribut == SBUS_REQUEST) {
proto_tree_add_item(sbus_tree,
hf_sbus_dest, tvb, offset, 1, ENC_BIG_ENDIAN);
offset += 1;
sbus_cmd_code = tvb_get_uint8(tvb,offset);
proto_tree_add_item(sbus_tree,
hf_sbus_command, tvb, offset, 1, ENC_BIG_ENDIAN);
offset += 1;
if (request_val && request_val->retry_count > 0) {/*this is a retry telegram*/
expert_add_info(pinfo, sbus_tree, &ei_sbus_retry);
nstime_delta(&ns, &pinfo->abs_ts, &request_val->req_time);
proto_tree_add_time(sbus_tree, hf_sbus_timeout,
tvb, 0, 0, &ns);
proto_tree_add_uint(sbus_tree, hf_sbus_request_in, tvb, 0, 0,
request_val->req_frame);
}
if (request_val && request_val->resp_frame > pinfo->num){
proto_tree_add_uint(sbus_tree, hf_sbus_response_in, tvb, 0, 0,
request_val->resp_frame);
}
switch (sbus_cmd_code) {
/*Read Counter, Register or Timer*/
case SBUS_RD_COUNTER:
case SBUS_RD_REGISTER:
case SBUS_RD_TIMER:
offset = add_media_access_to_tree(sbus_cmd_code, tvb, sbus_tree, offset);
break;
/*Read Flag, Input or Output*/
case SBUS_RD_FLAG:
case SBUS_RD_INPUT:
case SBUS_RD_OUTPUT:
offset = add_media_access_to_tree(sbus_cmd_code, tvb, sbus_tree, offset);
break;
/*Write Register Timer Counter*/
case SBUS_WR_COUNTER:
case SBUS_WR_REGISTER:
case SBUS_WR_TIMER:
offset = add_media_access_to_tree(sbus_cmd_code, tvb, sbus_tree, offset);
break;
/* Write flags and outputs*/
case SBUS_WR_FLAG:
case SBUS_WR_OUTPUT:
offset = add_media_access_to_tree(sbus_cmd_code, tvb, sbus_tree, offset);
break;
/* Request: Write Real time clock*/
case SBUS_WR_RTC:
/*Add subtree for Data*/
sbusdata_tree = proto_tree_add_subtree(sbus_tree, tvb, offset,
8, ett_sbus_data, NULL, "Clock data");
sbus_helper = tvb_get_uint8(tvb, (offset)); /*year-week*/
sbus_helper1 = tvb_get_uint8(tvb, (offset +1)); /*week-day*/
proto_tree_add_uint_format_value(sbusdata_tree,
hf_sbus_week_day, tvb, offset, 2, tvb_get_ntohs(tvb, offset),
"%x, Week day: %x", sbus_helper, sbus_helper1);
offset += 2;
sbus_helper = tvb_get_uint8(tvb, (offset)); /*year*/
sbus_helper1 = tvb_get_uint8(tvb, (offset +1)); /*month*/
sbus_helper2 = tvb_get_uint8(tvb, (offset +2)); /*day*/
proto_tree_add_uint_format_value(sbusdata_tree,
hf_sbus_date, tvb, offset, 3, tvb_get_ntoh24(tvb, offset),
"%02x/%02x/%02x", sbus_helper, sbus_helper1, sbus_helper2);
offset += 3;
sbus_helper = tvb_get_uint8(tvb, (offset)); /*hours*/
sbus_helper1 = tvb_get_uint8(tvb, (offset +1)); /*minutes*/
sbus_helper2 = tvb_get_uint8(tvb, (offset +2)); /*seconds*/
proto_tree_add_uint_format_value(sbusdata_tree,
hf_sbus_time, tvb, offset, 3, tvb_get_ntoh24(tvb, offset),
"%02x:%02x:%02x", sbus_helper, sbus_helper1, sbus_helper2);
offset += 3;
break;
/* Read/write multi media; multiple requests are transmitted within one single telegram*/
case SBUS_RDWR_MULTI_MEDIAS:
/*Add subtree for Sub-requests*/
sbus_multimedia_total = tvb_get_uint8(tvb,offset) + 1;
proto_tree_add_uint(sbus_tree,
hf_sbus_multimedia_length, tvb, offset, 1, sbus_multimedia_total);
offset += 1;
sbusdata_tree = proto_tree_add_subtree(sbus_tree, tvb, offset,
sbus_multimedia_total, ett_sbus_data, NULL, "Sub requests");
sbus_end_multimedia = offset + sbus_multimedia_total;
/*Add subtree for each Subrequest*/
for (i=0; i<64; i++) { /*max number of sub-requests is 64*/
if(offset >= sbus_end_multimedia){
break;
}
sbus_multimedia_cnt = tvb_get_uint8(tvb,offset) + 1;
sbus_multimedia_tree = proto_tree_add_subtree_format(sbusdata_tree, tvb, offset,
sbus_multimedia_cnt + 1, ett_sbus_data, NULL, "Request %d", i);
proto_tree_add_item(sbus_multimedia_tree,
hf_sbus_sub_length, tvb, offset, 1, ENC_BIG_ENDIAN);
offset +=1;
sbus_cmd_code = tvb_get_uint8(tvb,offset);
proto_tree_add_item(sbus_multimedia_tree,
hf_sbus_command, tvb, offset, 1, ENC_BIG_ENDIAN);
offset += 1;
offset = add_media_access_to_tree(sbus_cmd_code, tvb, sbus_multimedia_tree, offset);
}
break;
/* Read user memory or program line*/
case SBUS_RD_USER_MEMORY:
case SBUS_RD_PROGRAM_LINE:
sbus_media_cnt = (tvb_get_uint8(tvb,offset))+1;
proto_tree_add_uint(sbus_tree,
hf_sbus_rcount, tvb, offset, 1, sbus_media_cnt);
offset += 1;
proto_tree_add_item(sbus_tree,
hf_sbus_addr_prog, tvb, offset, 3, ENC_BIG_ENDIAN);
offset += 3;
break;
/*Write user memory*/
case SBUS_WR_USER_MEMORY:
sbus_media_cnt = (tvb_get_uint8(tvb,offset));
sbus_media_cnt = ((sbus_media_cnt - 2)/4);
proto_tree_add_uint(sbus_tree,
hf_sbus_wcount_calculated, tvb, offset,
1, sbus_media_cnt);
proto_tree_add_item(sbus_tree,
hf_sbus_wcount, tvb, offset, 1, ENC_BIG_ENDIAN);
offset += 1;
proto_tree_add_item(sbus_tree,
hf_sbus_addr_68k, tvb, offset, 3, ENC_BIG_ENDIAN);
offset += 3;
/*Add subtree for Data*/
sbusdata_tree = proto_tree_add_subtree(sbus_tree, tvb, offset,
((sbus_media_cnt) * 4), ett_sbus_data, NULL, "Program lines");
for (i=((sbus_media_cnt)); i>0; i--) {
proto_tree_add_item(sbusdata_tree,
hf_sbus_data_rtc, tvb, offset,
4, ENC_BIG_ENDIAN);
offset += 4;
}
break;
/* Read byte*/
case SBUS_RD_BYTE:
sbus_media_cnt = (tvb_get_uint8(tvb,offset))+1;
proto_tree_add_uint(sbus_tree,
hf_sbus_rcount, tvb, offset, 1, sbus_media_cnt);
offset += 1;
proto_tree_add_item(sbus_tree,
hf_sbus_addr_68k, tvb, offset, 3, ENC_BIG_ENDIAN);
offset += 3;
break;
/* Write byte */
case SBUS_WR_BYTE:
sbus_media_cnt = (tvb_get_uint8(tvb,offset));
sbus_media_cnt = (sbus_media_cnt - 2);
proto_tree_add_uint(sbus_tree,
hf_sbus_wcount_calculated, tvb, offset,
1, sbus_media_cnt);
proto_tree_add_item(sbus_tree,
hf_sbus_wcount, tvb, offset, 1, ENC_BIG_ENDIAN);
offset += 1;
proto_tree_add_item(sbus_tree,
hf_sbus_addr_68k, tvb, offset, 3, ENC_BIG_ENDIAN);
offset += 3;
/*Add subtree for Data*/
sbusdata_tree = proto_tree_add_subtree(sbus_tree, tvb, offset,
((sbus_media_cnt) * 4), ett_sbus_data, NULL, "Data (bytes)");
for (i=sbus_media_cnt; i>0; i--) {
proto_tree_add_item(sbusdata_tree,
hf_sbus_data_byte, tvb, offset,
1, ENC_BIG_ENDIAN);
offset += 1;
}
break;
/*Read EEPROM register*/
case SBUS_RD_USER_EEPROM_REGISTER:
proto_tree_add_item(sbus_tree,
hf_sbus_command_extension, tvb, offset, 1, ENC_BIG_ENDIAN);
offset += 1;
sbus_media_cnt = (tvb_get_uint8(tvb,offset))+1;
proto_tree_add_uint(sbus_tree,
hf_sbus_rcount, tvb, offset, 1, sbus_media_cnt);
offset += 1;
proto_tree_add_item(sbus_tree,
hf_sbus_addr_eeprom, tvb, offset, 2, ENC_BIG_ENDIAN);
offset += 2;
break;
/*Request for reading system info*/
/*Syinfo 05 is not implemented as no serial baud is possible*/
case SBUS_RD_SYSTEM_INFORMATION:
proto_tree_add_item(sbus_tree,
hf_sbus_sysinfo_nr, tvb, offset, 1, ENC_BIG_ENDIAN);
offset += 1;
proto_tree_add_item(sbus_tree,
hf_sbus_sysinfo_nr, tvb, offset, 1, ENC_BIG_ENDIAN);
offset += 1;
break;
/* WebServer Request */
case SBUS_WEB_SERVER_SERIAL_COMM:
sbus_web_size = tvb_get_uint8(tvb,offset);
proto_tree_add_uint(sbus_tree,
hf_sbus_web_size, tvb, offset,
1, sbus_web_size);
offset += 1;
sbus_web_aid = tvb_get_uint8(tvb,offset);
proto_tree_add_uint(sbus_tree,
hf_sbus_web_aid, tvb, offset,
1, sbus_web_aid);
offset += 1;
sbus_web_seq = tvb_get_uint8(tvb,offset);
proto_tree_add_uint(sbus_tree,
hf_sbus_web_seq, tvb, offset,
1, sbus_web_seq);
offset += 1;
if (sbus_web_size > 1) {
sbusdata_tree = proto_tree_add_subtree(sbus_tree, tvb, offset,
(sbus_web_size - 1), ett_sbus_data, NULL, "Data (bytes)");
for (i=sbus_web_size -1 ; i>0; i--) {
proto_tree_add_item(sbusdata_tree,
hf_sbus_data_byte, tvb, offset,
1, ENC_BIG_ENDIAN);
offset += 1;
}
}
break;
/* Read/write block request */
case SBUS_RD_WR_PCD_BLOCK:
if (tvb_get_uint8(tvb,offset) == 0xff){
sbus_rdwr_length = ((tvb_get_ntohl(tvb,0))-15);
proto_tree_add_uint(sbus_tree,
hf_sbus_rdwr_block_length_ext, tvb, 0, 4, sbus_rdwr_length);
offset += 1;
} else {
sbus_rdwr_length = tvb_get_uint8(tvb,offset);
proto_tree_add_uint(sbus_tree,
hf_sbus_rdwr_block_length, tvb, offset,
1, sbus_rdwr_length);
offset += 1;
}
sbus_rdwr_type = tvb_get_uint8(tvb,offset);
proto_tree_add_uint(sbus_tree,
hf_sbus_rdwr_telegram_type, tvb, offset,
1, sbus_rdwr_type);
offset += 1;
switch(sbus_rdwr_type) {
case SBUS_WR_START_OF_STREAM:
sbus_rdwr_block_type = tvb_get_uint8(tvb, 14);
proto_tree_add_item(sbus_tree,
hf_sbus_rdwr_telegram_sequence, tvb, offset,
1, ENC_BIG_ENDIAN);
offset += 1;
proto_tree_add_item(sbus_tree,
hf_sbus_block_type, tvb, offset,
1, ENC_BIG_ENDIAN);
offset += 1;
/* Check for file or block download */
if ((sbus_rdwr_block_type == SBUS_RD_WR_CONFIGURATION_FILE) ||
(sbus_rdwr_block_type == SBUS_RD_WR_PROGRAM_BLOCK_FILE)) {
proto_tree_add_item(sbus_tree,
hf_sbus_rdwr_block_size, tvb, offset,
4, ENC_BIG_ENDIAN);
offset += 4;
sbus_quint8_helper0=0;
/*find zero-termination of string*/
for (i=19; i<43; i++) { /*max length string is 24 char*/
if ((tvb_get_uint8(tvb, i)) == 0x00) {
break;
}
sbus_quint8_helper0 += 1;
}
tmp_string = tvb_get_string_enc(pinfo->pool, tvb , 19, sbus_quint8_helper0, ENC_ASCII);
proto_tree_add_string(sbus_tree,
hf_sbus_rdwr_file_name, tvb, offset,
sbus_quint8_helper0, tmp_string);
offset += sbus_quint8_helper0;
/*do not display a field for block data (skip)*/
offset += (sbus_rdwr_length-6-sbus_quint8_helper0);
} else { /* block write telegram, no file write*/
proto_tree_add_item(sbus_tree,
hf_sbus_block_nr, tvb, offset,
2, ENC_BIG_ENDIAN);
offset += 2;
proto_tree_add_item(sbus_tree,
hf_sbus_rdwr_block_size, tvb, offset,
4, ENC_BIG_ENDIAN);
offset += 4;
/*do not display a field for block data (skip)*/
offset += (sbus_rdwr_length-8);
}
break;
case SBUS_WR_BLOCK_DATA_STREAM:
sbus_rdwr_sequence = tvb_get_uint8(tvb,offset);
proto_tree_add_uint(sbus_tree,
hf_sbus_rdwr_telegram_sequence, tvb, offset,
1, sbus_rdwr_sequence);
offset += 1;
/*do not display a field for block data (skip)*/
offset += (sbus_rdwr_length-1);
break;
case SBUS_WR_BLOCK_END_OF_STREAM:
sbus_rdwr_sequence = tvb_get_uint8(tvb,offset);
proto_tree_add_uint(sbus_tree,
hf_sbus_rdwr_telegram_sequence, tvb, offset,
1, sbus_rdwr_sequence);
offset += 1;
/*do not display a field for block data (skip it)*/
offset += (sbus_rdwr_length-5);
/*do not display a field for block CRC (skip it)*/
offset += 4;
break;
case SBUS_WR_ABORT_BLOCK_STREAM:
case SBUS_RD_ABORT_BLOCK_STREAM:
break;
case SBUS_WR_BLOCK_DATA_BYTES:
sbus_rdwr_block_type = tvb_get_uint8(tvb, 14);
proto_tree_add_item(sbus_tree,
hf_sbus_block_type, tvb, offset,
1, ENC_BIG_ENDIAN);
offset += 1;
/* Check for file or block download */
if ((sbus_rdwr_block_type == SBUS_RD_WR_CONFIGURATION_FILE) ||
(sbus_rdwr_block_type == SBUS_RD_WR_PROGRAM_BLOCK_FILE)) {
proto_tree_add_item(sbus_tree,
hf_sbus_rdwr_block_addr, tvb, offset,
4, ENC_BIG_ENDIAN);
offset += 4;
sbus_quint8_helper0=0;
/*find zero-termination of string*/
for (i=19; i<43; i++) { /*max length string is 24 char*/
if ((tvb_get_uint8(tvb, i)) == 0x00) {
break;
}
sbus_quint8_helper0 += 1;
}
tmp_string = tvb_get_string_enc(pinfo->pool, tvb, 19, sbus_quint8_helper0, ENC_ASCII);
proto_tree_add_string(sbus_tree,
hf_sbus_rdwr_file_name, tvb, offset,
sbus_quint8_helper0, tmp_string);
offset += sbus_quint8_helper0;
/*do not display a field for block data (skip)*/
offset += (sbus_rdwr_length-6-sbus_quint8_helper0);
} else { /* block write telegram, no file write*/
proto_tree_add_item(sbus_tree,
hf_sbus_block_nr, tvb, offset,
2, ENC_BIG_ENDIAN);
offset += 2;
proto_tree_add_item(sbus_tree,
hf_sbus_rdwr_block_addr, tvb, offset,
4, ENC_BIG_ENDIAN);
offset += 4;
/*do not display a field for block data (skip)*/
offset += (sbus_rdwr_length-8);
}
break;
case SBUS_RD_BLOCK_START_OF_STREAM:
sbus_rdwr_block_type = tvb_get_uint8(tvb, 14);
proto_tree_add_item(sbus_tree,
hf_sbus_rdwr_telegram_sequence, tvb, offset,
1, ENC_BIG_ENDIAN);
offset += 1;
proto_tree_add_item(sbus_tree,
hf_sbus_block_type, tvb, offset,
1, ENC_BIG_ENDIAN);
offset += 1;
/* Check for file or block download */
if ((sbus_rdwr_block_type == SBUS_RD_WR_CONFIGURATION_FILE) ||
(sbus_rdwr_block_type == SBUS_RD_WR_PROGRAM_BLOCK_FILE)) {
sbus_quint8_helper0=0;
/*find zero-termination of string*/
for (i=14; i<38; i++) { /*max length string is 24 char*/
if ((tvb_get_uint8(tvb, i)) == 0x00) {
break;
}
sbus_quint8_helper0 += 1;
}
tmp_string = tvb_get_string_enc(pinfo->pool, tvb, 14, sbus_quint8_helper0, ENC_ASCII);
proto_tree_add_string(sbus_tree,
hf_sbus_rdwr_file_name, tvb, offset,
sbus_quint8_helper0, tmp_string);
offset += sbus_quint8_helper0;
} else { /* block write telegram, no file write*/
proto_tree_add_item(sbus_tree,
hf_sbus_block_nr, tvb, offset,
2, ENC_BIG_ENDIAN);
offset += 2;
}
break;
case SBUS_RD_BLOCK_DATA_STREAM:
proto_tree_add_item(sbus_tree,
hf_sbus_rdwr_telegram_sequence, tvb, offset,
1, ENC_BIG_ENDIAN);
offset += 1;
break;
case SBUS_RD_BLOCK_DATA_BYTES:
sbus_rdwr_block_type = tvb_get_uint8(tvb, 13);
proto_tree_add_item(sbus_tree,
hf_sbus_block_type, tvb, offset,
1, ENC_BIG_ENDIAN);
offset += 1;
/* Check for file or block read */
if ((sbus_rdwr_block_type == SBUS_RD_WR_CONFIGURATION_FILE) ||
(sbus_rdwr_block_type == SBUS_RD_WR_PROGRAM_BLOCK_FILE)) {
/*reading from a file*/
proto_tree_add_item(sbus_tree,
hf_sbus_rdwr_block_addr, tvb, offset,
4, ENC_BIG_ENDIAN);
offset += 4;
proto_tree_add_item(sbus_tree,
hf_sbus_rdwr_block_size, tvb, offset,
4, ENC_BIG_ENDIAN);
offset += 4;
sbus_quint8_helper0=0;
/*find zero-termination of string*/
for (i=22; i<46; i++) { /*max length string is 24 char*/
if ((tvb_get_uint8(tvb, i)) == 0x00) {
break;
}
sbus_quint8_helper0 += 1;
}
tmp_string = tvb_get_string_enc(pinfo->pool, tvb, 22, sbus_quint8_helper0, ENC_ASCII);
proto_tree_add_string(sbus_tree,
hf_sbus_rdwr_file_name, tvb, offset,
sbus_quint8_helper0, tmp_string);
offset += sbus_quint8_helper0 + 1;
} else { /* block read telegram, no file read*/
proto_tree_add_item(sbus_tree,
hf_sbus_block_nr, tvb, offset,
2, ENC_BIG_ENDIAN);
offset += 2;
proto_tree_add_item(sbus_tree,
hf_sbus_rdwr_block_addr, tvb, offset,
4, ENC_BIG_ENDIAN);
offset += 4;
proto_tree_add_item(sbus_tree,
hf_sbus_rdwr_block_size, tvb, offset,
4, ENC_BIG_ENDIAN);
offset += 4;
}
break;
case SBUS_DELETE_BLOCK:
case SBUS_GET_BLOCK_SIZE:
sbus_rdwr_block_type = tvb_get_uint8(tvb, 13);
proto_tree_add_item(sbus_tree,
hf_sbus_block_type, tvb, offset,
1, ENC_BIG_ENDIAN);
offset += 1;
/* Check for file or block deletion */
if ((sbus_rdwr_block_type == SBUS_RD_WR_CONFIGURATION_FILE) ||
(sbus_rdwr_block_type == SBUS_RD_WR_PROGRAM_BLOCK_FILE)) {
/*delete a file*/
sbus_quint8_helper0=0;
/*find zero-termination of string*/
for (i=14; i<38; i++) { /*max length string is 24 char*/
if ((tvb_get_uint8(tvb, i)) == 0x00) {
break;
}
sbus_quint8_helper0 += 1;
}
tmp_string = tvb_get_string_enc(pinfo->pool, tvb, 14, sbus_quint8_helper0, ENC_ASCII);
proto_tree_add_string(sbus_tree,
hf_sbus_rdwr_file_name, tvb, offset,
sbus_quint8_helper0, tmp_string);
offset += sbus_quint8_helper0 + 1;
} else { /* delete a block*/
proto_tree_add_item(sbus_tree,
hf_sbus_block_nr, tvb, offset,
2, ENC_BIG_ENDIAN);
offset += 2;
}
break;
case SBUS_GET_PROGRAM_BLOCK_LIST:
proto_tree_add_item(sbus_tree,
hf_sbus_rdwr_list_type, tvb, offset,
1, ENC_BIG_ENDIAN);
offset += 1;
break;
default:
break;
}
break;
case SBUS_RD_DATA_BLOCK:
offset = add_media_access_to_tree(sbus_cmd_code, tvb, sbus_tree, offset);
break;
/*Inform that command was not dissected and add remaining length*/
default:
if (sbus_eth_len > 13) { /*13 bytes is the minimal length of a request telegram...*/
sbus_helper = sbus_eth_len - (offset + 2);
proto_tree_add_expert(sbus_tree, pinfo, &ei_sbus_telegram_not_implemented, tvb, offset, sbus_helper);
offset = offset + sbus_helper;
}
break;
}
}
/* Response dissection*/
if (sbus_attribut == SBUS_RESPONSE && request_val) {
/*add response time*/
nstime_delta(&ns, &pinfo->abs_ts, &request_val->req_time);
proto_tree_add_time(sbus_tree, hf_sbus_response_time,
tvb, 0, 0, &ns);
/*add reference to request telegram*/
proto_tree_add_uint(sbus_tree, hf_sbus_response_to, tvb, 0, 0,
request_val->req_frame);
switch (request_val->cmd_code) {
/* Response: 32 bit values*/
case SBUS_RD_COUNTER:
case SBUS_RD_REGISTER:
case SBUS_RD_TIMER:
case SBUS_RD_USER_MEMORY:
case SBUS_RD_PROGRAM_LINE:
case SBUS_RD_USER_EEPROM_REGISTER:
case SBUS_RD_DATA_BLOCK:
/*Add subtree for Data*/
offset = add_media_response_to_tree(request_val->cmd_code, request_val->count, tvb, sbus_tree, offset);
break;
/* Response: PCD Display register*/
case SBUS_RD_DISPLAY_REGISTER:
proto_tree_add_item(sbus_tree,
hf_sbus_display_register, tvb, offset, 4, ENC_BIG_ENDIAN);
offset += 4;
break;
/* Add binary data I, O, F*/
case SBUS_RD_FLAG:
case SBUS_RD_INPUT:
case SBUS_RD_OUTPUT:
/*Add subtree for Data*/
offset = add_media_response_to_tree(request_val->cmd_code, request_val->count, tvb, sbus_tree, offset);
break;
/* Response: Real time clock value*/
case SBUS_RD_RTC:
/*Add subtree for Data*/
sbusdata_tree = proto_tree_add_subtree(sbus_tree, tvb, offset,
8, ett_sbus_data, NULL, "Clock data");
sbus_helper = tvb_get_uint8(tvb, (offset)); /*year-week*/
sbus_helper1 = tvb_get_uint8(tvb, (offset +1)); /*week-day*/
proto_tree_add_uint_format_value(sbusdata_tree,
hf_sbus_week_day, tvb, offset, 2, tvb_get_ntohs(tvb, offset),
"%x, Week day: %x", sbus_helper, sbus_helper1);
offset += 2;
sbus_helper = tvb_get_uint8(tvb, (offset)); /*year*/
sbus_helper1 = tvb_get_uint8(tvb, (offset +1)); /*month*/
sbus_helper2 = tvb_get_uint8(tvb, (offset +2)); /*day*/
proto_tree_add_uint_format_value(sbusdata_tree,
hf_sbus_date, tvb, offset, 3, tvb_get_ntoh24(tvb, offset),
"%02x/%02x/%02x", sbus_helper, sbus_helper1, sbus_helper2);
offset += 3;
sbus_helper = tvb_get_uint8(tvb, (offset)); /*hours*/
sbus_helper1 = tvb_get_uint8(tvb, (offset +1)); /*minutes*/
sbus_helper2 = tvb_get_uint8(tvb, (offset +2)); /*seconds*/
proto_tree_add_uint_format_value(sbusdata_tree,
hf_sbus_time, tvb, offset, 3, tvb_get_ntoh24(tvb, offset),
"%02x:%02x:%02x", sbus_helper, sbus_helper1, sbus_helper2);
offset += 3;
break;
case SBUS_RDWR_MULTI_MEDIAS:
/*Add subtree for Subrequests*/
sbus_multimedia_total = tvb_get_uint8(tvb,offset);
proto_tree_add_uint(sbus_tree,
hf_sbus_multimedia_length, tvb, offset, 1, sbus_multimedia_total);
offset += 1;
sbusdata_tree = proto_tree_add_subtree(sbus_tree, tvb, offset,
sbus_multimedia_total, ett_sbus_data, NULL, "Sub responses");
sbus_end_multimedia = offset + sbus_multimedia_total;
i = 0;
/* Start at front of list and cycle through possible sub-requests,
until all bytes or all requests are processed */
frame = wmem_list_head(request_val->sbus_subrequests);
while (frame && (offset < sbus_end_multimedia)) {
mm_sub_req = (sbus_subrequest *)wmem_list_frame_data(frame);
sbus_multimedia_cmd = mm_sub_req->cmd_code;
sbus_multimedia_cnt = mm_sub_req->count;
/*get the attribute of the sub-response (1: response, 2: ACK/NACK)*/
sbus_multimedia_att = tvb_get_uint8(tvb,offset + 1) ;
if (sbus_multimedia_att == SBUS_ACKNAK) {
sbus_multimedia_tree = proto_tree_add_subtree_format(sbusdata_tree, tvb, offset,
4, ett_sbus_data, NULL, "Response %d", i);
proto_tree_add_item(sbus_multimedia_tree,
hf_sbus_sub_length, tvb, offset, 1, ENC_BIG_ENDIAN);
offset +=1;
proto_tree_add_item(sbus_multimedia_tree,
hf_sbus_attribut, tvb, offset, 1, ENC_BIG_ENDIAN);
offset +=1;
hi = proto_tree_add_item(sbus_multimedia_tree,
hf_sbus_acknackcode, tvb, offset, 2, ENC_BIG_ENDIAN);
if (tvb_get_uint8(tvb, (offset+1)) > 0) {
expert_add_info(pinfo, hi, &ei_sbus_telegram_not_acked);
}
offset += 2;
} else { /*response containing data*/
sbus_multimedia_bytes = get_response_length(sbus_multimedia_cmd, sbus_multimedia_cnt);
sbus_multimedia_tree = proto_tree_add_subtree_format(sbusdata_tree, tvb, offset,
sbus_multimedia_bytes + 2, ett_sbus_data, NULL, "Response %d", i);
proto_tree_add_item(sbus_multimedia_tree,
hf_sbus_sub_length, tvb, offset, 1, ENC_BIG_ENDIAN);
offset +=1;
proto_tree_add_item(sbus_multimedia_tree,
hf_sbus_attribut, tvb, offset, 1, ENC_BIG_ENDIAN);
offset +=1;
add_media_response_to_tree(sbus_multimedia_cmd, sbus_multimedia_cnt, tvb, sbus_multimedia_tree, offset);
offset +=sbus_multimedia_bytes ;
}
/* After processing this sub request, proceed to the next */
frame = wmem_list_frame_next(frame);
i++;
}
break;
/* Response: CPU status, the command codes 14..1B are concerned*/
case SBUS_RD_PCD_STATUS_CPU0:
case SBUS_RD_PCD_STATUS_CPU1:
case SBUS_RD_PCD_STATUS_CPU2:
case SBUS_RD_PCD_STATUS_CPU3:
case SBUS_RD_PCD_STATUS_CPU4:
case SBUS_RD_PCD_STATUS_CPU5:
case SBUS_RD_PCD_STATUS_CPU6:
case SBUS_RD_PCD_STATUS_OWN:
proto_tree_add_item(sbus_tree,
hf_sbus_cpu_status, tvb, offset, 1, ENC_BIG_ENDIAN);
offset += 1;
break;
/* Response: Station address*/
case SBUS_RD_SBUS_STN_NBR:
proto_tree_add_item(sbus_tree,
hf_sbus_address, tvb, offset, 1, ENC_BIG_ENDIAN);
offset += 1;
break;
/* Response: Firmware version */
case SBUS_RD_PROGRAM_VERSION:
/*PCD type*/
proto_tree_add_item(sbus_tree, hf_sbus_cpu_type, tvb, offset, 5, ENC_ASCII);
offset += 5;
/*FW version*/
proto_tree_add_item(sbus_tree, hf_sbus_fw_version, tvb, offset, 3, ENC_ASCII);
offset += 4;
break;
/* Response for Status Flags*/
case SBUS_RD_STATUSFLAG_ACCU:
/*Add subtree for Data*/
sbusdata_tree = proto_tree_add_subtree(sbus_tree, tvb, offset,
1, ett_sbus_data, NULL, "ACCU and arithmetic status");
proto_tree_add_item(sbusdata_tree, hf_sbus_flags_accu,
tvb, offset, 1, ENC_BIG_ENDIAN);
proto_tree_add_item(sbusdata_tree, hf_sbus_flags_error,
tvb, offset, 1, ENC_BIG_ENDIAN);
proto_tree_add_item(sbusdata_tree, hf_sbus_flags_negative,
tvb, offset, 1, ENC_BIG_ENDIAN);
proto_tree_add_item(sbusdata_tree, hf_sbus_flags_zero,
tvb, offset, 1, ENC_BIG_ENDIAN);
offset +=1;
break;
/* Response for Read byte */
case SBUS_RD_BYTE:
/*Add subtree for Data*/
sbusdata_tree = proto_tree_add_subtree(sbus_tree, tvb, offset,
(request_val->count), ett_sbus_data, NULL, "Data (bytes)");
for (i=(request_val->count); i>0; i--) {
proto_tree_add_item(sbusdata_tree,
hf_sbus_data_byte, tvb, offset,
1, ENC_BIG_ENDIAN);
offset += 1;
}
break;
/* Response for Read Index register */
case SBUS_RD_INDEX_REGISTER:
/*Add subtree for Data*/
sbusdata_tree = proto_tree_add_subtree(sbus_tree, tvb, offset,
2, ett_sbus_data, NULL, "Data (hex bytes)");
for (i=0; i<2; i++) { /*2 bytes*/
proto_tree_add_item(sbusdata_tree,
hf_sbus_data_byte_hex, tvb, offset,
1, ENC_BIG_ENDIAN);
offset += 1;
}
break;
/* Response: Instruction pointer*/
case SBUS_RD_INSTRUCTION_POINTER:
proto_tree_add_item(sbus_tree,
hf_sbus_addr_prog, tvb, offset, 3, ENC_BIG_ENDIAN);
offset += 3;
break;
/*Response for Find History*/
case SBUS_FIND_HISTORY:
proto_tree_add_item(sbus_tree,
hf_sbus_addr_68k, tvb, offset, 3, ENC_BIG_ENDIAN);
offset += 3;
proto_tree_add_item(sbus_tree,
hf_sbus_nbr_elements, tvb, offset, 2, ENC_BIG_ENDIAN);
offset += 2;
break;
/* Response: Read current block*/
case SBUS_RD_CURRENT_BLOCK:
proto_tree_add_item(sbus_tree,
hf_sbus_block_type, tvb, offset, 1, ENC_BIG_ENDIAN);
offset += 1;
proto_tree_add_item(sbus_tree,
hf_sbus_block_nr, tvb, offset, 2, ENC_BIG_ENDIAN);
offset += 2;
break;
/* Response: Read system information (without interpretation of module info)*/
case SBUS_RD_SYSTEM_INFORMATION:
if (request_val->sysinfo == 0x00){ /*sysinfo 0*/
offset += 1; /* this byte is always 0x01*/
/*Add subtree for Data*/
sbusdata_tree = proto_tree_add_subtree(sbus_tree, tvb, offset,
1, ett_sbus_data, NULL, "System info");
proto_tree_add_item(sbusdata_tree, hf_sbus_sysinfo0_1,
tvb, offset, 1, ENC_BIG_ENDIAN);
proto_tree_add_item(sbusdata_tree, hf_sbus_sysinfo0_2,
tvb, offset, 1, ENC_BIG_ENDIAN);
proto_tree_add_item(sbusdata_tree, hf_sbus_sysinfo0_3,
tvb, offset, 1, ENC_BIG_ENDIAN);
proto_tree_add_item(sbusdata_tree, hf_sbus_sysinfo0_4,
tvb, offset, 1, ENC_BIG_ENDIAN);
proto_tree_add_item(sbusdata_tree, hf_sbus_sysinfo0_5,
tvb, offset, 1, ENC_BIG_ENDIAN);
offset += 1;
} else {
/*do not dissect all system info telegrams as there is no need*/
offset = (tvb_get_uint8(tvb,9) + 10);
}
break;
/* Response: Webserver request */
case SBUS_WEB_SERVER_SERIAL_COMM:
sbus_web_size = tvb_get_uint8(tvb,offset);
proto_tree_add_uint(sbus_tree,
hf_sbus_web_size, tvb, offset,
1, sbus_web_size);
offset += 1;
sbus_web_aid = tvb_get_uint8(tvb,offset);
proto_tree_add_uint(sbus_tree,
hf_sbus_web_aid, tvb, offset,
1, sbus_web_aid);
offset += 1;
if (sbus_web_size > 1) {
sbus_web_seq = tvb_get_uint8(tvb,offset);
proto_tree_add_uint(sbus_tree,
hf_sbus_web_seq, tvb, offset,
1, sbus_web_seq);
offset += 1;
sbusdata_tree = proto_tree_add_subtree(sbus_tree, tvb, offset,
(sbus_web_size - 2), ett_sbus_data, NULL, "Data (bytes)");
for (i=sbus_web_size - 2; i>0; i--) {
proto_tree_add_item(sbusdata_tree,
hf_sbus_data_byte, tvb, offset,
1, ENC_BIG_ENDIAN);
offset += 1;
}
}
break;
/* Response: Read/Write block data */
case SBUS_RD_WR_PCD_BLOCK:
sbus_rdwr_block_tlg = request_val->block_tlg;
sbus_rdwr_length = tvb_get_uint8(tvb,offset);
proto_tree_add_uint(sbus_tree,
hf_sbus_rdwr_block_length, tvb, offset,
1, sbus_rdwr_length);
offset += 1;
hi = proto_tree_add_item(sbus_tree,
hf_sbus_rdwr_acknakcode, tvb, offset,
1, ENC_BIG_ENDIAN);
if ((tvb_get_uint8(tvb, offset) >= SBUS_RD_WR_NAK)&&
(tvb_get_uint8(tvb, offset) <= SBUS_RD_WR_NAK_INVALID_SIZE)) {
expert_add_info(pinfo, hi, &ei_sbus_telegram_not_acked);
}
offset += 1;
switch(sbus_rdwr_block_tlg) {
case SBUS_WR_START_OF_STREAM:
case SBUS_WR_BLOCK_DATA_STREAM:
case SBUS_WR_BLOCK_END_OF_STREAM:
proto_tree_add_item(sbus_tree,
hf_sbus_rdwr_telegram_sequence, tvb, offset,
1, ENC_BIG_ENDIAN);
offset += 1;
break;
case SBUS_WR_ABORT_BLOCK_STREAM:
case SBUS_RD_ABORT_BLOCK_STREAM:
case SBUS_WR_BLOCK_DATA_BYTES:
case SBUS_DELETE_BLOCK:
break;
case SBUS_RD_BLOCK_START_OF_STREAM:
proto_tree_add_item(sbus_tree,
hf_sbus_rdwr_telegram_sequence, tvb, offset,
1, ENC_BIG_ENDIAN);
offset += 1;
proto_tree_add_item(sbus_tree,
hf_sbus_rdwr_block_size, tvb, offset,
4, ENC_BIG_ENDIAN);
offset += 4;
/*do not display a field for block data (skip)*/
offset += (sbus_rdwr_length-6);
break;
case SBUS_RD_BLOCK_DATA_STREAM:
proto_tree_add_item(sbus_tree,
hf_sbus_rdwr_telegram_sequence, tvb, offset,
1, ENC_BIG_ENDIAN);
offset += 1;
/*do not display a field for block data (skip)*/
offset += (sbus_rdwr_length-2);
break;
case SBUS_RD_BLOCK_DATA_BYTES:
/*do not display a field for block data (skip)*/
offset += (sbus_rdwr_length-1);
break;
case SBUS_GET_BLOCK_SIZE:
sbus_rdwr_block_type = tvb_get_uint8(tvb, 10);
/* Check for unknown block type */
if (sbus_rdwr_block_type == SBUS_RD_WR_UNKNOWN_BLOCK_TYPE) {
/*unknown block, no more data follows*/
} else { /* add block size and CRC32 in case of known block*/
proto_tree_add_item(sbus_tree,
hf_sbus_rdwr_block_size, tvb, offset,
4, ENC_BIG_ENDIAN);
offset += 4;
/*Now the CRC32 follows, but I don't bother calculating it*/
offset += 4;
}
break;
case SBUS_GET_PROGRAM_BLOCK_LIST:
proto_tree_add_item(sbus_tree,
hf_sbus_block_type, tvb, offset,
1, ENC_BIG_ENDIAN);
offset += 1;
proto_tree_add_item(sbus_tree,
hf_sbus_block_nr, tvb, offset,
2, ENC_BIG_ENDIAN);
offset += 2;
proto_tree_add_item(sbus_tree,
hf_sbus_rdwr_block_size, tvb, offset,
4, ENC_BIG_ENDIAN);
offset += 4;
/*do not display block_timestamp as no description is available*/
offset += (sbus_rdwr_length-8);
break;
default:
break;
}
break;
/*Inform that response was not dissected and add remaining length*/
default:
sbus_helper = sbus_eth_len - (offset + 2);
proto_tree_add_expert(sbus_tree, pinfo, &ei_sbus_telegram_not_implemented, tvb, offset, sbus_helper);
offset = offset + sbus_helper;
break;
}
} else if (sbus_attribut == SBUS_RESPONSE && (!request_val)) {
/*calculate the offset in case the request telegram was not found or was broadcasted*/
sbus_eth_len = tvb_get_ntohl(tvb,0);
sbus_helper = sbus_eth_len - 11;
proto_tree_add_expert(sbus_tree, pinfo, &ei_sbus_no_request_telegram, tvb, offset, sbus_helper);
offset = sbus_eth_len - 2;
}
if (sbus_attribut == SBUS_ACKNAK) {
/*Add response time if possible*/
if (request_val) {
nstime_delta(&ns, &pinfo->abs_ts, &request_val->req_time);
proto_tree_add_time(sbus_tree, hf_sbus_response_time,
tvb, 0, 0, &ns);
/*add reference to request telegram*/
proto_tree_add_uint(sbus_tree, hf_sbus_response_to, tvb, 0, 0,
request_val->req_frame);
}
hi = proto_tree_add_item(sbus_tree,
hf_sbus_acknackcode, tvb, offset, 2, ENC_BIG_ENDIAN);
if (tvb_get_uint8(tvb, (offset+1)) > 0) {
expert_add_info(pinfo, hi, &ei_sbus_telegram_not_acked);
}
offset += 2;
}
/* Calculate CRC */
sbus_crc_calc = 0;
for (i = 0; i < sbus_eth_len - 2; i++)
sbus_crc_calc = crc_calc (sbus_crc_calc, tvb_get_uint8(tvb, i));
proto_tree_add_checksum(sbus_tree, tvb, offset, hf_sbus_crc, hf_sbus_crc_status, &ei_sbus_crc_bad, pinfo, sbus_crc_calc,
ENC_BIG_ENDIAN, PROTO_CHECKSUM_VERIFY);
offset += 2; /*now at the end of the telegram*/
}
return offset;
/*End of dissect_sbus*/
}
/* Register the protocol with Wireshark */
void
proto_register_sbus(void)
{
/* Setup list of header fields See Section 1.6.1 for details*/
static hf_register_info hf[] = {
{ &hf_sbus_length,
{ "Length (bytes)", "sbus.len",
FT_UINT32, BASE_DEC, NULL, 0,
"SAIA Ether-S-Bus telegram length", HFILL }
},
{ &hf_sbus_version,
{ "Version", "sbus.vers",
FT_UINT8, BASE_DEC, NULL, 0,
"SAIA Ether-S-Bus version", HFILL }
},
{ &hf_sbus_protocol,
{ "Protocol type", "sbus.proto",
FT_UINT8, BASE_DEC, NULL, 0,
"SAIA Ether-S-Bus protocol type", HFILL }
},
{ &hf_sbus_sequence,
{ "Sequence", "sbus.seq",
FT_UINT16, BASE_DEC, NULL, 0,
"SAIA Ether-S-Bus sequence number", HFILL }
},
{ &hf_sbus_attribut,
{ "Telegram attribute", "sbus.att",
FT_UINT8, BASE_HEX, VALS(sbus_att_vals), 0,
"SAIA Ether-S-Bus telegram attribute, indicating type of telegram", HFILL }
},
{ &hf_sbus_dest,
{ "Destination", "sbus.destination",
FT_UINT8, BASE_DEC, NULL, 0,
"SAIA S-Bus destination address", HFILL }
},
{ &hf_sbus_address,
{ "S-Bus address", "sbus.address",
FT_UINT8, BASE_DEC, NULL, 0,
"SAIA S-Bus station address", HFILL }
},
{ &hf_sbus_command,
{ "Command", "sbus.cmd",
FT_UINT8, BASE_HEX | BASE_EXT_STRING, &sbus_command_vals_ext, 0,
"SAIA S-Bus command", HFILL }
},
{ &hf_sbus_command_extension,
{ "Command extension", "sbus.cmd_extn",
FT_UINT8, BASE_HEX, NULL, 0,
"SAIA S-Bus command extension", HFILL }
},
{ &hf_sbus_rcount,
{ "R-count", "sbus.rcount",
FT_UINT8, BASE_DEC, NULL, 0,
"Number of elements expected in response", HFILL }
},
{ &hf_sbus_sub_length,
{ "Sub length", "sbus.sublength",
FT_UINT8, BASE_DEC, NULL, 0,
"Length of multi-media response or request in bytes, length and command code fields not included", HFILL }
},
{ &hf_sbus_multimedia_length,
{ "Multi-media length", "sbus.mmlength",
FT_UINT8, BASE_DEC, NULL, 0,
"Length of all multi-media request or responses in bytes", HFILL }
},
{ &hf_sbus_wcount,
{ "W-count (raw)", "sbus.wcount",
FT_UINT8, BASE_DEC, NULL, 0,
"Number of bytes to be written", HFILL }
},
{ &hf_sbus_wcount_calculated,
{ "W-count (32 bit values)", "sbus.wcount_calc",
FT_UINT8, BASE_DEC, NULL, 0,
"Number of elements to be written", HFILL }
},
{ &hf_sbus_fio_count,
{ "FIO Count (amount of bits)", "sbus.fio_count",
FT_UINT8, BASE_DEC, NULL, 0,
"Number of binary elements to be written", HFILL }
},
{ &hf_sbus_addr_rtc,
{ "Base address RTC", "sbus.addr_RTC",
FT_UINT16, BASE_DEC, NULL, 0,
"Base address of 32 bit elements to read", HFILL }
},
{ &hf_sbus_addr_iof,
{ "Base address IOF", "sbus.addr_IOF",
FT_UINT16, BASE_DEC, NULL, 0,
"Base address of binary elements to read", HFILL }
},
{ &hf_sbus_addr_db,
{ "DB address", "sbus.addr_db",
FT_UINT16, BASE_DEC, NULL, 0,
"Datablock address to read from", HFILL }
},
{ &hf_sbus_addr_base_element,
{ "Base DB element address", "sbus.db_base_element",
FT_UINT16, BASE_DEC, NULL, 0,
"Base Datablock element address of 32 bit values to read", HFILL }
},
{ &hf_sbus_addr_eeprom,
{ "Base address of EEPROM register", "sbus.addr_EEPROM",
FT_UINT16, BASE_DEC, NULL, 0,
"Base address of 32 bit EEPROM register to read or write", HFILL }
},
{ &hf_sbus_addr_prog,
{ "Base address of user memory or program lines", "sbus.addr_prog",
FT_UINT24, BASE_DEC, NULL, 0,
"Base address of the user memory or program lines (read or write)", HFILL }
},
{ &hf_sbus_addr_68k,
{ "Base address of bytes", "sbus.addr_68k",
FT_UINT24, BASE_HEX, NULL, 0,
"Base address of bytes to read or write (68k address)", HFILL }
},
{ &hf_sbus_block_type,
{ "Block type", "sbus.block_type",
FT_UINT8, BASE_HEX | BASE_EXT_STRING, &sbus_block_types_ext, 0,
"Program block type", HFILL }
},
{ &hf_sbus_block_nr,
{ "Block/Element nr", "sbus.block_nr",
FT_UINT16, BASE_DEC, NULL, 0,
"Program block / DataBlock number", HFILL }
},
{ &hf_sbus_nbr_elements,
{ "Number of elements", "sbus.nbr_elements",
FT_UINT16, BASE_DEC, NULL, 0,
"Number of elements or characters", HFILL }
},
{ &hf_sbus_display_register,
{ "PCD Display register", "sbus.data_display_register",
FT_UINT32, BASE_DEC, NULL, 0,
"The PCD display register (32 bit value)", HFILL }
},
{ &hf_sbus_data_rtc,
{ "S-Bus 32-bit data", "sbus.data_rtc",
FT_UINT32, BASE_DEC, NULL, 0,
"One register/timer of counter (32 bit value)", HFILL }
},
{ &hf_sbus_data_byte,
{ "Data bytes", "sbus.data_byte",
FT_UINT8, BASE_DEC, NULL, 0,
"One byte from PCD", HFILL }
},
{ &hf_sbus_data_byte_hex,
{ "Data bytes (hex)", "sbus.data_byte_hex",
FT_UINT8, BASE_HEX, NULL, 0,
"One byte from PCD (hexadecimal)", HFILL }
},
{ &hf_sbus_data_iof,
{ "S-Bus binary data", "sbus.data_iof",
FT_UINT32, BASE_DEC, NULL, 0,
"8 binaries", HFILL }
},
{ &hf_sbus_cpu_type,
{ "PCD type", "sbus.pcd_type",
FT_STRING, BASE_NONE, NULL, 0,
"PCD type (short form)", HFILL }
},
{ &hf_sbus_fw_version,
{ "Firmware version", "sbus.fw_version",
FT_STRING, BASE_NONE, NULL, 0,
"Firmware version of the PCD or module", HFILL }
},
{ &hf_sbus_sysinfo_nr,
{ "System information number", "sbus.sysinfo",
FT_UINT8, BASE_HEX, NULL, 0,
"System information number (extension to command code)", HFILL }
},
{ &hf_sbus_sysinfo0_1,
{ "Mem size info", "sbus.sysinfo0.mem",
FT_BOOLEAN, 8, TFS(&tfs_sbus_present), F_MEMSIZE,
"Availability of memory size information", HFILL }
},
{ &hf_sbus_sysinfo0_2,
{ "Trace buffer", "sbus.sysinfo0.trace",
FT_BOOLEAN, 8, TFS(&tfs_sbus_present), F_TRACE,
"Availability of trace buffer feature", HFILL }
},
{ &hf_sbus_sysinfo0_3,
{ "Slot B1", "sbus.sysinfo0.b1",
FT_BOOLEAN, 8, TFS(&tfs_sbus_present), F_INFO_B1,
"Presence of EEPROM information on slot B1", HFILL }
},
{ &hf_sbus_sysinfo0_4,
{ "Slot B2", "sbus.sysinfo0.b2",
FT_BOOLEAN, 8, TFS(&tfs_sbus_present), F_INFO_B2,
"Presence of EEPROM information on slot B2", HFILL }
},
{ &hf_sbus_sysinfo0_5,
{ "PGU baud", "sbus.sysinfo0.pgubaud",
FT_BOOLEAN, 8, TFS(&tfs_sbus_present), F_PGU_BAUD,
"Availability of PGU baud switch feature", HFILL }
},
#if 0
{ &hf_sbus_sysinfo_length,
{ "System information length", "sbus.sysinfo_length",
FT_UINT8, BASE_HEX, NULL, 0,
"System information length in response", HFILL }
},
#endif
#if 0
{ &hf_sbus_f_module_type,
{ "F-module type", "sbus.fmodule_type",
FT_STRING, BASE_NONE, NULL, 0,
"Module type mounted on B1/2 slot", HFILL }
},
#endif
#if 0
{ &hf_sbus_harware_version,
{ "Hardware version", "sbus.hw_version",
FT_STRING, BASE_NONE, NULL, 0,
"Hardware version of the PCD or the module", HFILL }
},
#endif
#if 0
{ &hf_sbus_hardware_modification,
{ "Hardware modification", "sbus.hw_modification",
FT_UINT8, BASE_DEC, NULL, 0,
"Hardware modification of the PCD or module", HFILL }
},
#endif
#if 0
{ &hf_sbus_various,
{ "Various data", "sbus.various",
FT_NONE, BASE_NONE, NULL, 0,
"Various data contained in telegrams but nobody will search for it", HFILL }
},
#endif
{ &hf_sbus_acknackcode,
{ "ACK/NAK code", "sbus.nakcode",
FT_UINT16, BASE_HEX, VALS(sbus_ack_nak_vals), 0,
"SAIA S-Bus ACK/NAK response", HFILL }
},
{ &hf_sbus_cpu_status,
{ "CPU status", "sbus.CPU_status",
FT_UINT8, BASE_HEX, VALS(sbus_CPU_status), 0,
"SAIA PCD CPU status", HFILL }
},
{ &hf_sbus_week_day,
{ "Calendar week", "sbus.rtc.week_day",
FT_UINT16, BASE_HEX, NULL, 0,
"Calendar week and week day number of the real time clock", HFILL }
},
{ &hf_sbus_date,
{ "RTC date (YYMMDD)", "sbus.rtc.date",
FT_UINT24, BASE_HEX, NULL, 0,
"Year, month and day of the real time clock", HFILL }
},
{ &hf_sbus_time,
{ "RTC time (HHMMSS)", "sbus.rtc.time",
FT_UINT24, BASE_HEX, NULL, 0,
"Time of the real time clock", HFILL }
},
{ &hf_sbus_web_size,
{ "Web server packet size", "sbus.web.size",
FT_UINT8, BASE_HEX, NULL, 0,
NULL, HFILL }
},
{ &hf_sbus_web_aid,
{ "AID", "sbus.web.aid",
FT_UINT8, BASE_HEX, NULL, 0,
"Web server command/status code (AID)", HFILL }
},
{ &hf_sbus_web_seq,
{ "Sequence", "sbus.web.seq",
FT_UINT8, BASE_HEX, NULL, 0,
"Web server sequence nr (PACK_N)", HFILL }
},
{ &hf_sbus_rdwr_block_length,
{ "Read/write block telegram length", "sbus.block.length",
FT_UINT8, BASE_DEC, NULL, 0,
NULL, HFILL }
},
{ &hf_sbus_rdwr_block_length_ext,
{ "Extended length (bytes)", "sbus.len_ext",
FT_UINT32, BASE_DEC, NULL, 0,
NULL, HFILL }
},
{ &hf_sbus_rdwr_telegram_type,
{ "Read/write block telegram type", "sbus.block.tlgtype",
FT_UINT8, BASE_HEX | BASE_EXT_STRING, &rdwrblock_vals_ext, 0,
"Type of RD/WR block telegram", HFILL }
},
{ &hf_sbus_rdwr_telegram_sequence,
{ "Sequence", "sbus.block.seq",
FT_UINT8, BASE_DEC, NULL, 0,
"Sequence number of block data stream telegram", HFILL }
},
{ &hf_sbus_rdwr_block_size,
{ "Block size in bytes", "sbus.block.size",
FT_UINT32, BASE_DEC, NULL, 0,
"The size of the block in bytes", HFILL }
},
{ &hf_sbus_rdwr_block_addr,
{ "Address inside block", "sbus.block.addr",
FT_UINT32, BASE_DEC, NULL, 0,
"The address inside a block", HFILL }
},
{ &hf_sbus_rdwr_file_name,
{ "File name", "sbus.block.filename",
FT_STRING, BASE_NONE, NULL, 0,
"Name of file to in RD/WR block telegram", HFILL }
},
{ &hf_sbus_rdwr_list_type,
{ "Get program block list, command type", "sbus.block.getlisttype",
FT_UINT8, BASE_HEX, VALS(rdwrblock_list_type_vals), 0,
"Type of the Get Program Block list request", HFILL }
},
{ &hf_sbus_rdwr_acknakcode,
{ "ACK/NAK code", "sbus.block.nakcode",
FT_UINT8, BASE_HEX | BASE_EXT_STRING, &rdwrblock_sts_ext, 0,
"ACK/NAK response for block write requests", HFILL }
},
{ &hf_sbus_crc,
{ "Checksum", "sbus.crc",
FT_UINT16, BASE_HEX, NULL, 0,
"CRC 16", HFILL }
},
{ &hf_sbus_crc_status,
{ "Checksum Status", "sbus.crc.status",
FT_UINT8, BASE_NONE, VALS(proto_checksum_vals), 0x0,
NULL, HFILL }},
{ &hf_sbus_flags_accu,
{ "ACCU", "sbus.flags.accu",
FT_BOOLEAN, 8, TFS(&tfs_sbus_flags), F_ACCU,
"PCD Accumulator", HFILL }
},
{ &hf_sbus_flags_error,
{ "Error flag", "sbus.flags.error",
FT_BOOLEAN, 8, TFS(&tfs_sbus_flags), F_ERROR,
"PCD error flag", HFILL }
},
{ &hf_sbus_flags_negative,
{ "N-flag", "sbus.flags.nflag",
FT_BOOLEAN, 8, TFS(&tfs_sbus_flags), F_NEGATIVE,
"Negative status flag", HFILL }
},
{ &hf_sbus_flags_zero,
{ "Z-flag", "sbus.flags.zflag",
FT_BOOLEAN, 8, TFS(&tfs_sbus_flags), F_ZERO,
"Zero status flag", HFILL }
},
{ &hf_sbus_response_in,
{ "Response in frame nr.", "sbus.response_in",
FT_FRAMENUM, BASE_NONE, NULL, 0x0,
"The response to this Ether-S-Bus request is in this frame", HFILL }
},
{ &hf_sbus_response_to,
{ "Request in frame nr.", "sbus.response_to",
FT_FRAMENUM, BASE_NONE, NULL, 0x0,
"This is a response to the Ether-S-Bus request in this frame", HFILL }
},
{ &hf_sbus_response_time,
{ "Response time", "sbus.response_time",
FT_RELATIVE_TIME, BASE_NONE, NULL, 0x0,
"The time between the request and the response", HFILL }
},
{ &hf_sbus_timeout,
{ "Time passed since first request", "sbus.timeout",
FT_RELATIVE_TIME, BASE_NONE, NULL, 0x0,
"The time between the first (identical) request and the repetition", HFILL }
},
{ &hf_sbus_request_in,
{ "First request in frame nr.", "sbus.request_in",
FT_FRAMENUM, BASE_NONE, NULL, 0x0,
"The first request of this repeated request is in this frame", HFILL }
}
};
/* Setup protocol subtree array */
static int *ett[] = {
&ett_sbus,
&ett_sbus_ether,
&ett_sbus_data
};
static ei_register_info ei[] = {
{ &ei_sbus_retry, { "sbus.retry", PI_SEQUENCE, PI_NOTE, "Repeated telegram (due to timeout?)", EXPFILL }},
{ &ei_sbus_telegram_not_acked, { "sbus.telegram_not_acked", PI_RESPONSE_CODE, PI_CHAT, "Telegram not acknowledged by PCD", EXPFILL }},
{ &ei_sbus_crc_bad, { "sbus.crc_bad.expert", PI_CHECKSUM, PI_ERROR, "Bad checksum", EXPFILL }},
{ &ei_sbus_telegram_not_implemented, { "sbus.telegram_not_implemented", PI_UNDECODED, PI_WARN, "This telegram isn't implemented in the dissector", EXPFILL }},
{ &ei_sbus_no_request_telegram, { "sbus.no_request_telegram", PI_UNDECODED, PI_WARN, "Not dissected, could not find request telegram", EXPFILL }},
};
expert_module_t* expert_sbus;
/* Register the protocol name and description */
proto_sbus = proto_register_protocol("SAIA S-Bus", "SBUS", "sbus");
/* Required function calls to register the header fields and subtrees used */
proto_register_field_array(proto_sbus, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));
expert_sbus = expert_register_protocol(proto_sbus);
expert_register_field_array(expert_sbus, ei, array_length(ei));
sbus_request_hash = wmem_map_new_autoreset(wmem_epan_scope(), wmem_file_scope(), sbus_hash, sbus_equal);
/* Register the dissector handle */
sbus_handle = register_dissector("sbus", dissect_sbus, proto_sbus);
}
void
proto_reg_handoff_sbus(void)
{
dissector_add_uint_with_preference("udp.port", SBUS_UDP_PORT, sbus_handle);
}
/*
* Editor modelines
*
* Local Variables:
* c-basic-offset: 7
* tab-width: 8
* indent-tabs-mode: nil
* End:
*
* ex: set shiftwidth=7 tabstop=8 expandtab:
* :indentSize=7:tabSize=8:noTabs=true:
*/
|