1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
|
/*
Copyright (C) 2019-2020 Andrei Kopanchuk UZ7HO
This file is part of QtSoundModem
QtSoundModem is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
QtSoundModem is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QtSoundModem. If not, see http://www.gnu.org/licenses
*/
// UZ7HO Soundmodem Port by John Wiseman G8BPQ
#include "UZ7HOStuff.h"
#ifdef WIN32
__declspec(dllimport) unsigned short __stdcall htons(__in unsigned short hostshort);
__declspec(dllimport) unsigned short __stdcall ntohs(__in unsigned short hostshort);
#else
#define strtok_s strtok_r
#include <stddef.h>
#endif
void decode_frame(Byte * frame, int len, Byte * path, string * data,
Byte * pid, Byte * nr, Byte * ns, Byte * f_type, Byte * f_id,
Byte * rpt, Byte * pf, Byte * cr);
/*
unit ax25;
interface
uses classes,sysutils,windows;
procedure get_exclude_list(line: string; var list: TStringList);
procedure get_exclude_frm(line: string; var list: TStringList);
procedure get_monitor_path(path: string; var mycall,corrcall,digi: string);
procedure get_call(src_call: string; var call: string);
procedure get_call_fm_path(path: string; var callto,callfrom: string);
procedure set_corrcall(snd_ch,port: byte; path: string);
procedure set_mycall(snd_ch,port: byte; path: string);
procedure set_digi(snd_ch,port: byte; path: string);
procedure decode_frame(frame: string; var path,data: string; var pid,nr,ns,f_type,f_id: byte; var rpt,pf,cr: boolean);
procedure del_incoming_mycalls(src_call: string);
procedure del_incoming_mycalls_by_sock(socket: integer);
procedure ax25_info_init(snd_ch,port: byte);
procedure write_ax25_info(snd_ch,port: byte);
procedure clr_frm_win(snd_ch,port: byte);
procedure ax25_init;
procedure ax25_free;
function dec2hex(value: byte): string;
function get_corrcall(path: string): string;
function get_mycall(path: string): string;
function get_digi(path: string): string;
function is_excluded_call(snd_ch: byte; path: string): boolean;
function is_excluded_frm(snd_ch,f_id: byte; data: string): boolean;
function is_last_digi(path: string): boolean;
function is_digi(snd_ch,port: byte; path: string): boolean;
function is_corrcall(snd_ch,port: byte; path: string): boolean;
function is_mycall(snd_ch,port: byte; path: string): boolean;
function is_correct_path(path: string; pid: byte): boolean;
function direct_addr(path: string): string;
function reverse_addr(path: string): string;
function reverse_digi(path: string): string;
function number_digi(path: string): byte;
function info_pid(pid: byte): string;
function get_fcs(var data: string; len: word): word;
function set_addr(path: string; rpt,cr: boolean): string;
function set_ctrl(nr,ns,f_type,f_id: byte; pf: boolean): byte;
function make_frame(data,path: string; pid,nr,ns,f_type,f_id: byte; rpt,pf,cr: boolean): string;
function get_incoming_socket_by_call(src_call: string): integer;
function add_incoming_mycalls(socket: integer; src_call: string): boolean;
function in_list_incoming_mycall(path: string): boolean;
function get_UTC_time: string;
function parse_NETROM(data: string; f_id: byte): string;
function parse_IP(data: string): string;
function parse_ARP(data: string): string;
function add_raw_frames(snd_ch: byte; frame: string; var buf: TStringList): boolean;
function scrambler(in_buf: string): string;
function my_indexof(var l: TStringList; s: string): integer;
const
port_num=32;
PKT_ERR=17; //Minimum packet size, bytes
I_MAX=7; //Maximum number of packets
B_IDX_MAX=256;
ADDR_MAX_LEN=10;
FRAME_FLAG=126;
// Status flags
STAT_NO_LINK=0;
STAT_LINK=1;
STAT_CHK_LINK=2;
STAT_WAIT_ANS=3;
STAT_TRY_LINK=4;
STAT_TRY_UNLINK=5;
// Сmd,Resp,Poll,Final,Digipeater flags
SET_P=TRUE;
SET_F=FALSE;
SET_C=TRUE;
SET_R=FALSE;
SET_NO_RPT=FALSE;
SET_RPT=TRUE;
// Frame ID flags
I_FRM=0;
S_FRM=1;
U_FRM=2;
I_I=0;
S_RR=1;
S_RNR=5;
S_REJ=9;
U_SABM=47;
U_DISC=67;
U_DM=15;
U_UA=99;
U_FRMR=135;
U_UI=3;
// PID flags
PID_X25=$01; // 00000001-CCIT X25 PLP
PID_SEGMENT=$08; // 00001000-Segmentation fragment
PID_TEXNET=$C3; // 11000011-TEXNET Datagram Protocol
PID_LQ=$C4; // 11001000-Link Quality Protocol
PID_APPLETALK=$CA; // 11001010-Appletalk
PID_APPLEARP=$CB; // 11001011-Appletalk ARP
PID_IP=$CC; // 11001100-ARPA Internet Protocol
PID_ARP=$CD; // 11001101-ARPA Address Resolution Protocol
PID_NET_ROM=$CF; // 11001111-NET/ROM
*/
#define ADDR_MAX_LEN 10
#define PID_NO_L3 0xF0; // 11110000-No Level 3 Protocol
unsigned short CRCTable[256] = {
0, 4489, 8978, 12955, 17956, 22445, 25910, 29887,
35912, 40385, 44890, 48851, 51820, 56293, 59774, 63735,
4225, 264, 13203, 8730, 22181, 18220, 30135, 25662,
40137, 36160, 49115, 44626, 56045, 52068, 63999, 59510,
8450, 12427, 528, 5017, 26406, 30383, 17460, 21949,
44362, 48323, 36440, 40913, 60270, 64231, 51324, 55797,
12675, 8202, 4753, 792, 30631, 26158, 21685, 17724,
48587, 44098, 40665, 36688, 64495, 60006, 55549, 51572,
16900, 21389, 24854, 28831, 1056, 5545, 10034, 14011,
52812, 57285, 60766, 64727, 34920, 39393, 43898, 47859,
21125, 17164, 29079, 24606, 5281, 1320, 14259, 9786,
57037, 53060, 64991, 60502, 39145, 35168, 48123, 43634,
25350, 29327, 16404, 20893, 9506, 13483, 1584, 6073,
61262, 65223, 52316, 56789, 43370, 47331, 35448, 39921,
29575, 25102, 20629, 16668, 13731, 9258, 5809, 1848,
65487, 60998, 56541, 52564, 47595, 43106, 39673, 35696,
33800, 38273, 42778, 46739, 49708, 54181, 57662, 61623,
2112, 6601, 11090, 15067, 20068, 24557, 28022, 31999,
38025, 34048, 47003, 42514, 53933, 49956, 61887, 57398,
6337, 2376, 15315, 10842, 24293, 20332, 32247, 27774,
42250, 46211, 34328, 38801, 58158, 62119, 49212, 53685,
10562, 14539, 2640, 7129, 28518, 32495, 19572, 24061,
46475, 41986, 38553, 34576, 62383, 57894, 53437, 49460,
14787, 10314, 6865, 2904, 32743, 28270, 23797, 19836,
50700, 55173, 58654, 62615, 32808, 37281, 41786, 45747,
19012, 23501, 26966, 30943, 3168, 7657, 12146, 16123,
54925, 50948, 62879, 58390, 37033, 33056, 46011, 41522,
23237, 19276, 31191, 26718, 7393, 3432, 16371, 11898,
59150, 63111, 50204, 54677, 41258, 45219, 33336, 37809,
27462, 31439, 18516, 23005, 11618, 15595, 3696, 8185,
63375, 58886, 54429, 50452, 45483, 40994, 37561, 33584,
31687, 27214, 22741, 18780, 15843, 11370, 7921, 3960 };
unsigned short pkt_raw_min_len = 8;
int stat_r_mem = 0;
extern struct TKISSMode_t KISS;
TAX25Port AX25Port[4][port_num];
TStringList KISS_acked[4];
TStringList KISS_iacked[4];
// I think this is the queue for a soundcard channel, so can only be
// two of them (L and R)
TStringList all_frame_buf[5];
typedef struct registeredCalls_t
{
UCHAR myCall[7]; // call in ax.25
void * socket;
} registeredCalls;
TStringList list_incoming_mycalls; // list strings containing a registered call
boolean busy = 0;
boolean dcd[5] = { 0 ,0 ,0, 0 };
boolean tx = 0;
int stdtones = 0;
int fullduplex = 0;
UCHAR diddles = 0;
struct TQPSK_t qpsk_set[4];
word MEMRecovery[5] = { 200,200,200,200 };
int NonAX25[5] = { 0 };
boolean dyn_frack[4] = { FALSE,FALSE,FALSE,FALSE };
Byte recovery[4] = { 0,0,0,0 };
Byte users[4] = { 0,0,0,0 };
short txtail[5] = { 50, 50, 50, 50, 50 };
short txdelay[5] = { 400, 400, 400, 400, 400 };
short modem_def[5] = { 1, 1, 1, 1, 1 };
int emph_db[5] = { 0, 0, 0, 0, 0 };
UCHAR emph_all[5] = { 0, 0, 0, 0, 0 };
boolean KISS_opt[4] = { FALSE, FALSE, FALSE, FALSE };
int resptime[4] = { 0,0,0,0 };
int slottime[4] = { 0,0,0,0 };
int persist[4] = { 100,100,100,100 };
int fracks[4] = { 0,0,0,0 };
int frack_time[4] = { 0,0,0,0 };
int idletime[4] = { 0,0,0,0 };
int redtime[4] = { 0,0,0,0 };
int IPOLL[4] = { 30,30,30,30 };
int maxframe[4] = { 0,0,0,0 };
int TXFrmMode[4] = { 0,0,0,0 };
int max_frame_collector[4] = { 0,0,0,0 };
char MyDigiCall[4][512] = { "","","","" };
char exclude_callsigns[4][512] = { "","","","" };
char exclude_APRS_frm[4][512] = { "","","","" };
TStringList list_exclude_callsigns[4];
TStringList list_exclude_APRS_frm[4];
TStringList list_digi_callsigns[4];
Byte xData[256];
Byte xEncoded[256];
Byte xDecoded[256];
int frame_count = 0;
int single_frame_count = 0;
/*
mydigi: string;
//// end of user params
addr: string[70];
ctrl: byte;
pid: byte=PID_NO_L3;
fcs: word;
data: string;
frame: string;
implementation
uses ax25_l2,sm_main;
*/
void scrambler(UCHAR * in_buf, int Len)
{
integer i;
word sreg;
Byte a = 0, k;
sreg = 0x1ff;
for (i = 0; i < Len; i++)
{
for (k = 0; k < 8; k++)
{
// a: = (a shr 1) or (sreg and 1 shl 7);
a = (a >> 1) | ((sreg & 1) << 7);
// sreg: = (sreg shl 4 and $200) xor (sreg shl 8 and $200) or (sreg shr 1);
sreg = (((sreg << 4) & 0x200) ^ ((sreg << 8) & 0x200)) | (sreg >> 1);
}
in_buf[i] = in_buf[i] ^ a;
}
}
/*
function parse_ARP(data: string): string;
function get_callsign(data: string): string;
var
i: integer;
s: string;
a: byte;
begin
s:='';
if length(data)=7 then
begin
for i:=1 to 6 do
begin
a:=ord(data[i]) shr 1;
if (a in [$30..$39,$41..$5A]) then s:=s+chr(a);
end;
a:=ord(data[7]) shr 1 and 15;
if a>0 then s:=s+'-'+inttostr(a);
end
else
begin
if length(data)>0 then
begin
for i:=1 to length(data) do
if i=1 then s:=dec2hex(ord(data[i])) else s:=s+':'+dec2hex(ord(data[i]));
end;
end;
if s<>'' then s:=s+' ';
result:=s;
end;
function get_IP(data: string): string;
var
i: integer;
s: string;
begin
s:='';
if length(data)>0 then
begin
for i:=1 to length(data) do
if i=1 then s:=inttostr(ord(data[i])) else s:=s+'.'+inttostr(ord(data[i]));
end;
if s<>'' then s:=s+' ';
result:=s;
end;
const
opcode: array [0..3] of string = ('ARP Request','ARP Response','RARP Request','RARP Response');
var
oper: word;
hlen,plen: byte;
sha,spa,tha,tpa: string;
s: string;
i: word;
begin
s:=data;
if length(data)>7 then
begin
hlen:=ord(data[5]);
plen:=ord(data[6]);
oper:=(ord(data[7]) shl 8 or ord(data[8])) and 2;
i:=9; sha:=get_callsign(copy(data,i,hlen));
i:=i+hlen; spa:=get_ip(copy(data,i,plen));
i:=i+plen; tha:=get_callsign(copy(data,i,hlen));
i:=i+hlen; tpa:=get_ip(copy(data,i,plen));
s:=' [ARP] '+opcode[oper]+' from '+sha+spa+'to '+tha+tpa;
end;
result:=s;
end;
function parse_NETROM(data: string; f_id: byte): string;
function deshift_AX25(data: string): string;
var
i: byte;
call: string[6];
ssid: string[2];
begin
result:='';
if length(data)<7 then exit;
for i:=1 to 7 do data[i]:=chr(ord(data[i]) shr 1);
call:=trim(copy(data,1,6));
ssid:=trim(inttostr(ord(data[7]) and 15));
if ssid='0' then result:=call else result:=call+'-'+ssid;
end;
function con_req_info(data: string): string;
var
s_call: string;
d_call: string;
w: byte;
t_o: byte;
begin
result:='';
if length(data)>14 then
begin
w:=ord(data[1]);
s_call:=deshift_AX25(copy(data,2,7));
d_call:=deshift_AX25(copy(data,9,7));
result:=' w='+inttostr(w)+' '+s_call+' at '+d_call;
end;
if length(data)>15 then
begin
t_o:=ord(data[16]);
result:=result+' t/o '+inttostr(t_o);
end;
end;
function con_ack_info(data: string): string;
var
w: byte;
begin
result:='';
if length(data)>0 then
begin
w:=ord(data[1]);
result:=' w='+inttostr(w);
end;
end;
const
opcode_arr: array[0..7] of string = ('PE','CON REQ','CON ACK','DISC REQ','DISQ ACK','INFO','INFO ACK','RST');
var
s: string;
netrom_header: string;
c_idx: byte;
c_ID: byte;
TX_nr: byte;
RX_nr: byte;
opcode: byte;
s_call: string;
s_node: string;
d_call: string;
d_node: string;
b_call: string;
r_s_nr: string;
opc_flags: string;
quality: byte;
ttl: byte;
hops: byte;
rtt: word;
inp3_nr_field: byte;
inp3_field_len: byte;
inp3_ext_fields: boolean;
begin
s:=data;
if length(data)>0 then
begin
if data[1]=#$FF then
begin
delete(data,1,1);
//Nodes broadcasting
if (f_id=U_UI) and (length(data)>5) then
begin
s_node:=copy(data,1,6);
delete(data,1,6);
s:='NODES broadcast from '+s_node+#13#10;
while length(data)>20 do
begin
d_call:=deshift_AX25(copy(data,1,7));
d_node:=copy(data,8,6);
b_call:=deshift_AX25(copy(data,14,7));
quality:=ord(data[21]);
delete(data,1,21);
s:=s+' '+d_node+':'+d_call+' via '+b_call+' Q='+inttostr(quality)+#13#10;
end;
end;
// INP3 RIF
if (f_id=I_I) and (length(data)>10) then
begin
s:='[INP3 RIF]'+#13#10;
while length(data)>10 do
begin
d_call:=deshift_AX25(copy(data,1,7));
hops:=ord(data[8]);
rtt:=(ord(data[9]) shl 8) or ord(data[10]);
delete(data,1,10);
inp3_ext_fields:=TRUE;
inp3_nr_field:=0;
while (length(data)>0) and inp3_ext_fields do
begin
inp3_field_len:=ord(data[1]);
if inp3_field_len>0 then
begin
if (inp3_nr_field=0) and (length(data)>1) then
begin
if data[2]=#0 then d_call:=copy(data,3,inp3_field_len-2)+':'+d_call; // Copy alias
end;
delete(data,1,inp3_field_len);
inc(inp3_nr_field);
end
else inp3_ext_fields:=FALSE;
end;
delete(data,1,1);
s:=s+d_call+' hops='+inttostr(hops)+' rtt='+inttostr(rtt)+#13#10;
end;
end;
end
else
begin
// NETROM frames
if length(data)>19 then
begin
s_call:=deshift_AX25(copy(data,1,7));
d_call:=deshift_AX25(copy(data,8,7));
ttl:=ord(data[15]);
netrom_header:=copy(data,16,5);
delete(data,1,20);
c_idx:=ord(netrom_header[1]);
c_ID:=ord(netrom_header[2]);
TX_nr:=ord(netrom_header[3]);
RX_nr:=ord(netrom_header[4]);
opcode:=ord(netrom_header[5]);
// Opcode flags
opc_flags:='';
if opcode and 128 = 128 then opc_flags:=opc_flags+' C';
if opcode and 64 = 64 then opc_flags:=opc_flags+' N';
//
s:=' [NETROM] '+s_call+' to '+d_call+' ttl='+inttostr(ttl)+' cct='+dec2hex(c_idx)+dec2hex(c_ID);
r_s_nr:=' S'+inttostr(TX_nr)+' R'+inttostr(RX_nr);
case (opcode and 7) of
0 : s:=s+' <'+opcode_arr[opcode and 7]+r_s_nr+'>'+#13#10+data;
1 : s:=s+' <'+opcode_arr[opcode and 7]+'>'+con_req_info(data);
2 : s:=s+' <'+opcode_arr[opcode and 7]+'>'+con_ack_info(data)+' my cct='+dec2hex(TX_nr)+dec2hex(RX_nr);
3 : s:=s+' <'+opcode_arr[opcode and 7]+'>';
4 : s:=s+' <'+opcode_arr[opcode and 7]+'>';
5 : s:=s+' <'+opcode_arr[opcode and 7]+r_s_nr+'>:'+#13#10+data;
6 : s:=s+' <'+opcode_arr[opcode and 7]+' R'+inttostr(RX_nr)+'>'+opc_flags;
7 : s:=s+' <'+opcode_arr[opcode and 7]+r_s_nr+'>'+#13#10+data;
end;
end;
end;
end;
result:=s;
end;
function parse_IP(data: string): string;
function parse_ICMP(var data: string): string;
var
ICMP_type: byte;
ICMP_code: byte;
s: string;
begin
result:='';
if length(data)>3 then
begin
ICMP_type:=ord(data[1]);
ICMP_code:=ord(data[2]);
delete(data,1,4);
s:=' [ICMP] Type='+inttostr(ICMP_type)+' Code='+inttostr(ICMP_code)+#13#10;
result:=s;
end;
end;
function parse_TCP(var data: string): string;
var
s: string;
src_port: string;
dest_port: string;
wnd: string;
ihl: word;
idl: word;
flags: byte;
seq: string;
ack: string;
s_flags: string;
s_idl: string;
begin
result:='';
if length(data)>19 then
begin
src_port:=' src_port:'+inttostr((ord(data[1]) shl 8)+ord(data[2]));
dest_port:=' dest_port:'+inttostr((ord(data[3]) shl 8)+ord(data[4]));
seq:=' seq='+dec2hex(ord(data[5]))+dec2hex(ord(data[6]))+dec2hex(ord(data[7]))+dec2hex(ord(data[8]));
ack:=' ack='+dec2hex(ord(data[9]))+dec2hex(ord(data[10]))+dec2hex(ord(data[11]))+dec2hex(ord(data[12]));
ihl:=(ord(data[13]) shr 4)*4;
idl:=length(data)-ihl;
flags:=ord(data[14]);
wnd:=' wnd='+inttostr((ord(data[15]) shl 8)+ord(data[16]));
delete(data,1,ihl);
//
s_flags:=' ';
if (flags and 32)=32 then s_flags:=s_flags+'URG ';
if (flags and 16)=16 then s_flags:=s_flags+'ACK ';
if (flags and 8)=8 then s_flags:=s_flags+'PSH ';
if (flags and 4)=4 then s_flags:=s_flags+'RST ';
if (flags and 2)=2 then s_flags:=s_flags+'SYN ';
if (flags and 1)=1 then s_flags:=s_flags+'FIN ';
//
if idl>0 then s_idl:=' data='+inttostr(idl) else s_idl:='';
if (flags and 16)<>16 then ack:='';
//
s:=' [TCP]'+src_port+dest_port+seq+ack+wnd+s_idl+s_flags+#13#10;
result:=s;
end;
end;
function parse_UDP(var data: string): string;
var
s: string;
src_port: string;
dest_port: string;
idl: word;
len: word;
s_idl: string;
begin
result:='';
if length(data)>7 then
begin
src_port:=' src_port:'+inttostr((ord(data[1]) shl 8)+ord(data[2]));
dest_port:=' dest_port:'+inttostr((ord(data[3]) shl 8)+ord(data[4]));
len:=(ord(data[5]) shl 8)+ord(data[6]);
idl:=len-8;
delete(data,1,8);
//
if idl>0 then s_idl:=' data='+inttostr(idl) else s_idl:='';
//
s:=' [UDP]'+src_port+dest_port+' len='+inttostr(len)+s_idl+#13#10;
result:=s;
end;
end;
const
prot_idx=#1#6#17;
prot_name: array [1..3] of string = ('ICMP','TCP','UDP');
var
s: string;
src_ip: string;
dest_ip: string;
s_prot: string;
len: string;
c_prot: char;
ttl: string;
offset: string;
ihl: byte;
p: byte;
fragment_offset: word;
begin
s:=data;
if length(data)>19 then
begin
ihl:=(ord(data[1]) and 15)*4;
len:=' len='+inttostr((ord(data[3]) shl 8)+ord(data[4]));
fragment_offset:=((ord(data[7]) shl 8)+ord(data[8])) shl 3;
ttl:=' ttl='+inttostr(ord(data[9]));
c_prot:=data[10];
src_ip:=' Fm '+inttostr(ord(data[13]))+'.'+inttostr(ord(data[14]))+'.'+inttostr(ord(data[15]))+'.'+inttostr(ord(data[16]));
dest_ip:=' To '+inttostr(ord(data[17]))+'.'+inttostr(ord(data[18]))+'.'+inttostr(ord(data[19]))+'.'+inttostr(ord(data[20]));
delete(data,1,ihl);
//
p:=pos(c_prot,prot_idx);
if p>0 then s_prot:=' prot='+prot_name[p] else s_prot:=' prot=Type'+inttostr(ord(c_prot));
if fragment_offset>0 then offset:=' offset='+inttostr(fragment_offset) else offset:='';
s:=' [IP]'+src_ip+dest_ip+s_prot+ttl+len+offset+#13#10;
if fragment_offset=0 then
case p of
1 : s:=s+parse_ICMP(data);
2 : s:=s+parse_TCP(data);
3 : s:=s+parse_UDP(data);
end;
s:=s+data;
end;
result:=s;
end;
function get_UTC_time: string;
var
st: TSYSTEMTIME;
sec,hour,minute: string;
begin
GetSystemTime(st);
if st.wSecond<10 then sec:='0'+inttostr(st.wSecond) else sec:=inttostr(st.wSecond);
if st.wMinute<10 then minute:='0'+inttostr(st.wMinute) else minute:=inttostr(st.wMinute);
if st.wHour<10 then Hour:='0'+inttostr(st.wHour) else Hour:=inttostr(st.wHour);
result:=hour+':'+minute+':'+sec;
end;
function dec2hex(value: byte): string;
const
hex='0123456789ABCDEF';
var
lo,hi: byte;
begin
lo:=value and 15;
hi:=value shr 4;
result:=hex[hi+1]+hex[lo+1];
end;
*/
unsigned short get_fcs(UCHAR * Data, unsigned short len)
{
unsigned short i;
unsigned short result;
result = 0xFFFF;
if (len == 0)
return result;
for (i = 0; i < len; i++)
result = (result >> 8) ^ CRCTable[(result ^ Data[i]) & 0xff];
result ^= 0xffff;
return result;
}
unsigned short CRCTAB[256] = {
0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,
0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,
0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,
0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,
0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,
0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,
0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,
0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,
0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,
0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,
0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,
0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,
0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
};
unsigned short int compute_crc(unsigned char *buf, int len)
{
unsigned short fcs = 0xffff;
int i;
for (i = 0; i < len; i++)
fcs = (fcs >> 8) ^ CRCTAB[(fcs ^ buf[i]) & 0xff];
fcs ^= 0xffff;
return fcs;
}
/*
function info_pid(pid: byte): string;
begin
if ((pid and 48=1) or (pid and 48=2)) then result:='0';
if pid=204 then result:='1';
if pid=221 then result:='2';
if pid=240 then result:='3';
if pid=255 then result:='4';
end;
procedure explode(var a: array of string; border, s: string; p1: word);
var
s2: string;
i: integer;
begin
i:=0;
s2:=s+border;
repeat
a[i]:=copy(s2,0,pos(border,s2)-1);
delete(s2,1,length(a[i]+border));
inc(i);
until (s2='') or (i=p1);
end;
function set_addr(path: string; rpt,cr: boolean): string;
const
A_RX=0;
A_TX=1;
C_BIT=64;
H_BIT=64;
RR_BIT=48;
var
cnt,i: byte;
a_call: array [0..1] of string;
a_path: array [0..ADDR_MAX_LEN-1] of string;
calls: array [0..ADDR_MAX_LEN-1] of string;
ssids: array [0..ADDR_MAX_LEN-1] of byte;
addr: string;
n: word;
begin
for i:=0 to ADDR_MAX_LEN-1 do
begin
a_path[i]:='';
calls[i]:='';
ssids[i]:=0;
end;
//Разделяем позывные
try explode(a_path,',',path,ADDR_MAX_LEN); except end;
//Разделяем позывные и ssid
cnt:=0;
repeat
a_call[0]:=''; a_call[1]:='';
try explode(a_call,'-',a_path[cnt],2); except end;
if a_call[0]<>'' then
begin
calls[cnt]:=copy(a_call[0]+' ',1,6);
if a_call[1]='' then a_call[1]:='0';
try ssids[cnt]:=strtoint(a_call[1]); except ssids[cnt]:=0; end;
inc(cnt);
end;
until (a_call[0]='') or (cnt=ADDR_MAX_LEN);
//Формируем адресную строку
addr:='';
if cnt>1 then
begin
for i:=0 to cnt-1 do
begin
if (cr=SET_C) and (i=A_RX) then ssids[i]:=ssids[i]+C_BIT; //Добавляем C в CRRSSID1
if (cr=SET_R) and (i=A_TX) then ssids[i]:=ssids[i]+C_BIT; //Добавляем C в CRRSSID1
if rpt and (i>A_TX) then
if calls[i]=mydigi then ssids[i]:=ssids[i]+H_BIT; //Добавляем H в HRRSSID1
ssids[i]:=ssids[i]+RR_BIT; //Добавляем RR в xRRSSID1
addr:=addr+calls[i]+chr(ssids[i]);
end;
for n:=1 to length(addr) do addr[n]:=chr(ord(addr[n]) shl 1); //сдвигаем на 1 бит октеты
addr[length(addr)]:=chr(ord(addr[length(addr)]) xor 1); //устанавливаем конец адреса
end;
result:=addr;
end;
*/
int get_addr(char * Calls, UCHAR * AXCalls)
{
// CONVERT CALL + OPTIONAL DIGI STRING TO AX25, RETURN
// CONVERTED STRING IN AXCALLS. Return FALSE if invalied
Byte * axptr = AXCalls;
char * ptr, *Context;
int n = 8; // Max digis
memset(AXCalls, 0, 70);
ptr = strtok_s(Calls, " ,", &Context);
if (ptr == NULL)
return FALSE;
// First field is Call
if (ConvToAX25(ptr, axptr) == 0)
return FALSE;
axptr += 7;
ptr = strtok_s(NULL, " ,", &Context);
if (ConvToAX25(ptr, axptr) == 0)
return FALSE;
axptr += 7;
ptr = strtok_s(NULL, " ,", &Context);
while (ptr && n--)
{
// NEXT FIELD = COULD BE CALLSIGN, VIA,
if (memcmp(ptr, "VIA", (int)strlen(ptr)) == 0)
{
} //skip via
else
{
// Convert next digi
if (ConvToAX25(ptr, axptr) == 0)
return FALSE;
axptr += 7;
}
ptr = strtok_s(NULL, " ,", &Context);
}
axptr[-1] |= 1; // Set end of address
return axptr - AXCalls;
}
Byte set_ctrl(Byte nr, Byte ns, Byte f_type, Byte f_id, boolean pf)
{
Byte pf_bit, ctrl;
ctrl = 0;
pf_bit = 0;
if (pf)
pf_bit = 16;
switch (f_type)
{
case I_FRM:
ctrl = (nr << 5) + pf_bit + (ns << 1);
break;
case S_FRM:
ctrl = (nr << 5) + pf_bit + f_id;
break;
case U_FRM:
ctrl = f_id + pf_bit;
}
return ctrl;
}
string * make_frame(string * data, Byte * axaddr, Byte pid, Byte nr, Byte ns, Byte f_type, Byte f_id, boolean rpr, boolean pf, boolean cr)
{
UNUSED(rpr);
Byte ctrl;
string * frame = newString();
int addrlen;
Byte addr[80];
unsigned short CRC;
UCHAR CRCString[2];
frame->Data[0] = 0; // Lower software expects a kiss control byte here
frame->Length = 1;
ctrl = set_ctrl(nr, ns, f_type, f_id, pf);
addrlen = strlen((char *)axaddr);
memcpy(addr, axaddr, addrlen);
if (cr)
addr[6] |= 0x80; // Set Command Bit
else
addr[13] |= 0x80; // Set Response Bit
switch (f_type)
{
case I_FRM:
stringAdd(frame, addr, addrlen);
stringAdd(frame, (Byte *)&ctrl, 1);
stringAdd(frame, (Byte *)&pid, 1);
stringAdd(frame, data->Data, data->Length);
break;
case S_FRM:
stringAdd(frame, addr, addrlen);
stringAdd(frame, (Byte *)&ctrl, 1);
break;
case U_FRM:
if (f_id == U_UI)
{
stringAdd(frame, addr, addrlen);
stringAdd(frame, (Byte *)&ctrl, 1);
stringAdd(frame, (Byte *)&pid, 1);
stringAdd(frame, data->Data, data->Length);
}
else if (f_id == U_FRMR)
{
stringAdd(frame, addr, addrlen);
stringAdd(frame, (Byte *)&ctrl, 1);
stringAdd(frame, data->Data, data->Length);
}
else
{
stringAdd(frame, addr, addrlen);
stringAdd(frame, (Byte *)&ctrl, 1);
}
}
CRC = get_fcs(&frame->Data[1], frame->Length - 1);
CRCString[0] = CRC & 0xff;
CRCString[1] = CRC >> 8;
stringAdd(frame, CRCString, 2);
return frame;
}
int add_raw_frames(int snd_ch, string * frame, TStringList * buf)
{
string *s_data = newString();
Byte s_pid, s_nr, s_ns, s_f_type, s_f_id;
Byte s_rpt, s_cr, s_pf;
string *d_data = newString();
Byte d_pid, d_nr, d_ns, d_f_type, d_f_id;
Byte d_rpt, d_cr, d_pf;
Byte d_path[80];
Byte s_path[80];
boolean found_I;
int i;
unsigned char * framecontents;
int Length;
boolean result = TRUE;
// Have to be careful as at this point frames have KISS Header and maybe trailer
if (buf->Count > 0)
{
// Check for duplicate. Ok to just compare as copy will have same header
if (my_indexof(buf, frame) >= 0)
{
Debugprintf("KISSOptimise discarding duplicate frame");
return FALSE;
}
// Need to adjust for KISS bytes
// Normally one, but ackmode has 3 on front and sizeof(void *) on end
framecontents = frame->Data;
Length = frame->Length;
if ((framecontents[0] & 15) == 12) // Ackmode
{
framecontents += 3;
Length -= (3 + sizeof(void *));
}
else
{
framecontents++;
Length--;
}
decode_frame(framecontents, Length, s_path, s_data, &s_pid, &s_nr, &s_ns, &s_f_type, &s_f_id, &s_rpt, &s_pf, &s_cr);
found_I = FALSE;
// check for multiple RR (r)
if (s_f_id == S_FRM && s_cr == SET_R)
{
for (i = 0; i < buf->Count; i++)
{
framecontents = buf->Items[i]->Data;
Length = buf->Items[i]->Length;
if ((framecontents[0] & 15) == 12) // Ackmode
{
framecontents += 3;
Length -= (3 + sizeof(void *));
}
else
{
framecontents++;
Length--;
}
decode_frame(framecontents, Length, d_path, d_data, &d_pid, &d_nr, &d_ns, &d_f_type, &d_f_id, &d_rpt, &d_pf, &d_cr);
if (d_f_id == S_FRM && d_cr == SET_R && strcmp((char *)s_path, (char *)d_path) == 0)
{
Delete(buf, i);
Debugprintf("KISSOptimise discarding unneeded RR(R%d)", d_nr);
break;
}
}
}
// check for RR after I Frame
if (s_f_id == S_FRM && s_cr == SET_C)
{
for (i = 0; i < buf->Count; i++)
{
framecontents = buf->Items[i]->Data;
Length = buf->Items[i]->Length;
if ((framecontents[0] & 15) == 12) // Ackmode
{
framecontents += 3;
Length -= (3 + sizeof(void *));
}
else
{
framecontents++;
Length--;
}
decode_frame(framecontents, Length, d_path, d_data, &d_pid, &d_nr, &d_ns, &d_f_type, &d_f_id, &d_rpt, &d_pf, &d_cr);
if (d_f_id == I_FRM && strcmp((char *)s_path, (char *)d_path) == 0)
{
found_I = TRUE;
break;
}
}
if (found_I)
{
Debugprintf("KISSOptimise discarding unneeded RR(C %d) after I frame", s_nr);
result = FALSE;
}
}
// check on I
if (s_f_id == I_FRM)
{
for (i = 0; i < buf->Count; i++)
{
framecontents = buf->Items[i]->Data;
Length = buf->Items[i]->Length;
if ((framecontents[0] & 15) == 12) // Ackmode
{
framecontents += 3;
Length -= (3 + sizeof(void *));
}
else
{
framecontents++;
Length--;
}
decode_frame(framecontents, Length, d_path, d_data, &d_pid, &d_nr, &d_ns, &d_f_type, &d_f_id, &d_rpt, &d_pf, &d_cr);
if (strcmp((char *)s_path, (char *)d_path) == 0 && d_f_id == S_FRM && d_cr == SET_C)
{
Delete(buf, i);
Debugprintf("KISSOptimise discarding unneeded RR(C %d)", d_nr);
i--; // i was removed
}
}
}
}
freeString(d_data);
freeString(s_data);
return result;
}
//////////////////////// Register incoming callsign ////////////////////////////
// I think a call should only be registered on one socket (or we won't know where to send
// incoming calls
boolean add_incoming_mycalls(void * socket, char * src_call)
{
registeredCalls * reg = malloc(sizeof(struct registeredCalls_t));
int i = 0;
// Build a string containing Call and Socket
ConvToAX25(src_call, reg->myCall);
reg->socket = socket;
if (list_incoming_mycalls.Count > 0)
{
for (i = 0; i < list_incoming_mycalls.Count; i++)
{
registeredCalls * check = (registeredCalls *)list_incoming_mycalls.Items[i];
if (memcmp(check->myCall, reg->myCall, 7) == 0)
{
// Update socket
check->socket = socket;
return FALSE;
}
}
}
Add(&list_incoming_mycalls, (string *)reg);
return TRUE;
}
void del_incoming_mycalls(char * src_call)
{
int i = 0;
Byte axcall[7];
registeredCalls * reg;
ConvToAX25(src_call, axcall);
while (i < list_incoming_mycalls.Count)
{
reg = (registeredCalls *)list_incoming_mycalls.Items[i];
{
if (memcmp(reg->myCall, axcall, 7) == 0)
{
// cant use Delete as stringlist doesn't contain strings
TStringList * Q = &list_incoming_mycalls;
int Index = i;
free(Q->Items[Index]);
Q->Count--;
while (Index < Q->Count)
{
Q->Items[Index] = Q->Items[Index + 1];
Index++;
}
return;
}
}
i++;
}
}
void del_incoming_mycalls_by_sock(void * socket)
{
int i = 0, snd_ch, port;
registeredCalls * reg;
while (i < list_incoming_mycalls.Count)
{
reg = (registeredCalls *)list_incoming_mycalls.Items[i];
{
if (reg->socket == socket)
{
// cant use Delete as stringlist doesn't contain strings
TStringList * Q = &list_incoming_mycalls;
int Index = i;
free(Q->Items[Index]);
Q->Count--;
while (Index < Q->Count)
{
Q->Items[Index] = Q->Items[Index + 1];
Index++;
}
//Delete(&list_incoming_mycalls, i);
}
else
i++;
}
}
// Should clear all connections on socket
for (snd_ch = 0; snd_ch < 4; snd_ch++)
{
for (port = 0; port < port_num; port++)
{
TAX25Port * AX25Sess = &AX25Port[snd_ch][port];
if (AX25Sess->socket == socket)
{
if (AX25Sess->status != STAT_NO_LINK)
{
// Shouldn't we send DM? -0 try it
set_DM(snd_ch, AX25Sess->ReversePath);
rst_timer(AX25Sess);
rst_values(AX25Sess);
AX25Sess->status = STAT_NO_LINK;
}
AX25Sess->socket = 0;
}
}
}
}
/*
function get_incoming_socket_by_call(src_call: string): integer;
var
i: integer;
found: boolean;
socket: integer;
call,ssid: string;
a_call: array[0..1] of string;
begin
socket:=-1;
i:=0;
found:=FALSE;
try explode(a_call,'-',src_call,2); except end;
call:=trim(a_call[0]);
if a_call[1]<>'' then ssid:=a_call[1] else ssid:='0';
if list_incoming_mycalls.Count>0 then
repeat
if (call+'-'+ssid)=list_incoming_mycalls.Strings[i] then
begin socket:=strtoint(list_incoming_mycalls_sock.Strings[i]); found:=TRUE; end;
inc(i);
until found or (i=list_incoming_mycalls.Count);
result:=socket;
end;
*/
void * in_list_incoming_mycall(Byte * path)
{
// See if to call is in registered calls list
int i = 0;
registeredCalls * check; // list_incoming_mycalls contains registeredCalls, not Strings
while (i < list_incoming_mycalls.Count)
{
check = (registeredCalls *)list_incoming_mycalls.Items[i];
if (memcmp(check->myCall, path, 7) == 0)
return check->socket;
i++;
}
return NULL;
}
/*
////////////////////////////////////////////////////////////////////////////////
function is_corrcall(snd_ch,port: byte; path: string): boolean;
var
call,ssid: string;
begin
call:=trim(copy(path,8,6));
ssid:=copy(path,14,1);
if ssid<>'' then ssid:=inttostr((ord(ssid[1]) and 15)) else ssid:='0';
call:=call+'-'+ssid;
if call=AX25Sess->corrcall then result:=TRUE else result:=FALSE;
end;
function is_mycall(snd_ch,port: byte; path: string): boolean;
var
call,ssid: string;
begin
call:=trim(copy(path,1,6));
ssid:=copy(path,7,1);
if ssid<>'' then ssid:=inttostr((ord(ssid[1]) and 15)) else ssid:='0';
call:=call+'-'+ssid;
if call=AX25Sess->mycall then result:=TRUE else result:=FALSE;
end;
function is_digi(snd_ch,port: byte; path: string): boolean;
var
digi,call,ssid: string;
begin
digi:='';
if length(path)>14 then
begin
delete(path,1,14);
repeat
call:=trim(copy(path,1,6));
ssid:=copy(path,7,1);
delete(path,1,7);
if ssid<>'' then ssid:=inttostr((ord(ssid[1]) and 15))
else ssid:='0';
if path<>'' then digi:=digi+call+'-'+ssid+','
else digi:=digi+call+'-'+ssid;
until path='';
end;
if digi=AX25Sess->digi then result:=TRUE else result:=FALSE;
end;
*/
// Check if laast digi used
boolean is_last_digi(Byte *path)
{
int len = strlen(path);
if (len == 14)
return TRUE;
if ((path[len - 1] & 128) == 128)
return TRUE;
return FALSE;
}
/*
function get_corrcall(path: string): string;
var
call,ssid: string;
begin
call:=trim(copy(path,8,6));
ssid:=copy(path,14,1);
if ssid<>'' then ssid:=inttostr((ord(ssid[1]) and 15)) else ssid:='0';
call:=call+'-'+ssid;
result:=call;
end;
function get_mycall(path: string): string;
var
call,ssid: string;
begin
call:=trim(copy(path,1,6));
ssid:=copy(path,7,1);
if ssid<>'' then ssid:=inttostr((ord(ssid[1]) and 15)) else ssid:='0';
call:=call+'-'+ssid;
result:=call;
end;
function get_digi(path: string): string;
var
digi,call,ssid: string;
begin
digi:='';
if length(path)>14 then
begin
delete(path,1,14);
repeat
call:=trim(copy(path,1,6));
ssid:=copy(path,7,1);
delete(path,1,7);
if ssid<>'' then ssid:=inttostr((ord(ssid[1]) and 15))
else ssid:='0';
if path<>'' then digi:=digi+call+'-'+ssid+','
else digi:=digi+call+'-'+ssid;
until path='';
end;
result:=digi;
end;
*/
boolean is_correct_path(Byte * path, Byte pid)
{
Byte networks[] = { 6, 7, 8, 0xc4, 0xcc, 0xcd, 0xce, 0xcf, 0xf0 , 0 };
Byte call[10];
int i;
if (pid == 0 || strchr(networks, pid))
{
// Validate calls
// I think checking bottom bit of first 13 bytes is enough
for (i = 0; i < 13; i++)
{
if ((*(path) & 1))
return FALSE;
path++;
}
return TRUE;
}
return FALSE;
}
void get_exclude_list(char * line, TStringList * list)
{
// Convert comma separated list of calls to ax25 format in list
// Convert to 6 chars - SSID is ignored
string axcall;
char copy[512];
char * ptr, *Context;
if (line[0] == 0)
return;
strcpy(copy, line); // copy as strtok messes with it
strcat(copy, ",");
axcall.Length = 6;
axcall.AllocatedLength = 8;
axcall.Data = malloc(8);
memset(axcall.Data, 0, 8);
ptr = strtok_s(copy, " ,", &Context);
while (ptr)
{
if (ConvToAX25(ptr, axcall.Data) == 0)
return;
axcall.Data[6] = 0;
Add(list, duplicateString(&axcall));
ptr = strtok_s(NULL, " ,", &Context);
}
}
void get_exclude_frm(char * line, TStringList * list)
{
/*
s: string;
p: integer;
n: integer;
begin
list.Clear;
if line='' then exit;
repeat
p:=pos(',',line);
if p>0 then
begin
s:=trim(copy(line,1,p-1));
if s<>'' then
begin
try n:=strtoint(s); except n:=-1; end;
if n in [0..255] then list.Add(chr(n));
end;
delete(line,1,p);
end
else
begin
s:=trim(line);
if s<>'' then
begin
try n:=strtoint(s); except n:=-1; end;
if n in [0..255] then list.Add(chr(n));
end;
end;
until p=0;
end;
*/
}
/*
function is_excluded_call(snd_ch: byte; path: string): boolean;
var
excluded: boolean;
call: string;
ssid: string;
begin
excluded:=FALSE;
if (list_exclude_callsigns[snd_ch].Count>0) and (length(path)>13) then
begin
// Copy sender
call:=trim(copy(path,8,6));
ssid:=copy(path,14,1);
if ssid<>'' then call:=call+'-'+inttostr((ord(ssid[1]) and 15));
if list_exclude_callsigns[snd_ch].IndexOf(call)>-1 then excluded:=TRUE;
end;
result:=excluded;
end;
function is_excluded_frm(snd_ch,f_id: byte; data: string): boolean;
var
excluded: boolean;
begin
excluded:=FALSE;
if list_exclude_APRS_frm[snd_ch].Count>0 then
if f_id=U_UI then
if length(data)>0 then
if list_exclude_APRS_frm[snd_ch].IndexOf(data[1])>=0 then excluded:=TRUE;
result:=excluded;
end;
procedure set_corrcall(snd_ch,port: byte; path: string);
var
call,ssid: string;
begin
call:=trim(copy(path,8,6));
ssid:=copy(path,14,1);
if ssid<>'' then ssid:=inttostr((ord(ssid[1]) and 15))
else ssid:='0';
AX25Sess->corrcall:=call+'-'+ssid;
end;
procedure set_mycall(snd_ch,port: byte; path: string);
var
call,ssid: string;
begin
call:=trim(copy(path,1,6));
ssid:=copy(path,7,1);
if ssid<>'' then ssid:=inttostr((ord(ssid[1]) and 15))
else ssid:='0';
AX25Sess->mycall:=call+'-'+ssid;
end;
procedure set_digi(snd_ch,port: byte; path: string);
var
digi,call,ssid: string;
begin
digi:='';
if length(path)>14 then
begin
delete(path,1,14);
repeat
call:=trim(copy(path,1,6));
ssid:=copy(path,7,1);
delete(path,1,7);
if ssid<>'' then ssid:=inttostr((ord(ssid[1]) and 15))
else ssid:='0';
if path<>'' then digi:=digi+call+'-'+ssid+','
else digi:=digi+call+'-'+ssid;
until path='';
end;
AX25Sess->digi:=digi;
end;
procedure get_call_fm_path(path: string; var callto,callfrom: string);
var
a_path: array [0..ADDR_MAX_LEN-1] of string;
i: byte;
begin
for i:=0 to ADDR_MAX_LEN-1 do a_path[i]:='';
try explode(a_path,',',path,ADDR_MAX_LEN); except end;
callto:=a_path[0];
callfrom:=a_path[1];
end;
procedure get_call(src_call: string; var call: string);
var
a_call: array[0..1] of string;
ssid: string;
begin
try explode(a_call,'-',src_call,2); except end;
call:=trim(a_call[0]);
if a_call[1]<>'' then ssid:=trim(a_call[1]) else ssid:='0';
call:=call+'-'+ssid;
end;
*/
int is_excluded_call(int snd_ch, unsigned char * path)
{
string * call = newString();
int Excluded = FALSE;
stringAdd(call, &path[7], 6);
if (list_exclude_callsigns[snd_ch].Count > 0)
if (my_indexof(&list_exclude_callsigns[snd_ch], call) > -1)
Excluded = TRUE;
freeString(call);
return Excluded;
}
int is_excluded_frm(int snd_ch, int f_id, string * data)
{
if (f_id == U_UI)
if (data->Length > 0)
if (my_indexof(&list_exclude_APRS_frm[snd_ch], data) >= 0)
return TRUE;
return FALSE;
}
int number_digi(string path)
{
int n = 0;
// a_path: array [0..ADDR_MAX_LEN-3] of string;
int i;
// for i:=0 to ADDR_MAX_LEN-3 do a_path[i]:='';
// try explode(a_path,',',path,ADDR_MAX_LEN-2); except end;
// for i:=0 to ADDR_MAX_LEN-3 do if a_path[i]<>'' then inc(n);
return n;
}
get_monitor_path(Byte * path, char * mycall, char * corrcall, char * digi)
{
Byte * digiptr = digi;
digi[0] = 0;
mycall[ConvFromAX25(path, mycall)] = 0;
path += 7;
corrcall[ConvFromAX25(path, corrcall)] = 0;
while ((path[6] & 1) == 0) // End of call bit
{
if (digi != digiptr)
*(digi++) = ',';
path += 7;
digi += ConvFromAX25(path, digi);
if (((path[6] & 128) == 128)) // Digi'd
*(digi++) = '*';
}
*digi = 0;
}
/*
function reverse_digi(path: string): string;
var
digi: string;
a_path: array [0..ADDR_MAX_LEN-3] of string;
i: word;
begin
digi:='';
for i:=0 to ADDR_MAX_LEN-3 do a_path[i]:='';
try explode(a_path,',',path,ADDR_MAX_LEN-2); except end;
for i:=0 to ADDR_MAX_LEN-3 do
if a_path[i]<>'' then
begin
if digi='' then digi:=a_path[i]+digi
else digi:=a_path[i]+','+digi;
end;
result:=digi;
end;
function direct_addr(path: string): string;
var
s,call,ssid: string;
begin
s:='';
repeat
call:=copy(path,1,6);
delete(path,1,6);
ssid:=copy(path,1,1);
delete(path,1,1);
if ssid<>'' then ssid:=inttostr((ord(ssid[1]) and 15));
if s='' then s:=call+'-'+ssid else s:=s+','+call+'-'+ssid;
until path='';
result:=s;
end;
*/
void reverse_addr(Byte * path, Byte * revpath, int Len)
{
Byte * ptr = path;
Byte * copy = revpath;
int endbit = Len - 1;
int numdigis = (Len - 14) / 7;
int i;
if (Len < 14)
return;
Byte digis[57]; // 8 * 7 + null terminator
memset(digis, 0, 57);
Byte * digiptr = digis + 49; // Last Digi
// remove end of address bit
path[endbit] &= 0xFE;
// first reverse dest and origin
memcpy(copy + 7, ptr, 7);
memcpy(copy, ptr + 7, 7);
Len -= 14;
ptr += 14;
for (i = 0; i < numdigis; i++)
{
memcpy(digiptr, ptr, 7);
ptr += 7;
digiptr -= 7;
}
// Digiptr now points to new first digi
memcpy(©[14], &digiptr[7], 7 * numdigis);
path[endbit] |= 1; // restore original end bit
copy[endbit++] |= 1;
copy[endbit] = 0; // Null terminate
return;
}
void decode_frame(Byte * frame, int len, Byte * path, string * data,
Byte * pid, Byte * nr, Byte * ns, Byte * f_type, Byte * f_id,
Byte * rpt, Byte * pf, Byte * cr)
{
int i;
int addr_end;
Byte ctrl;
Byte * savepath = path;
i = 0;
addr_end = FALSE;
*cr = SET_R;
*pf = SET_F;
data->Length = 0;
ctrl = 0;
*pid = 0;
*nr = 0;
*ns = 0;
*f_type = 0;
*f_id = 0;
*rpt = FALSE;
if (len < PKT_ERR)
return;
if ((frame[6] & 128) == 128 && (frame[13] & 128) == 0)
*cr = SET_C;
while (len > i && i < ADDR_MAX_LEN * 7)
{
*path++ = frame[i];
if ((frame[i] & 1) == 1)
{
addr_end = TRUE;
break;
}
i++;
}
if (addr_end == 0)
return;
// clear the c and r bits from address
savepath[6] &= 0x7f; // Mask
savepath[13] &= 0x7f; // Mask
*path = 0; // add null terminate
i++; // Points to ctrl byte
ctrl = frame[i];
if ((ctrl & 16) == 16)
*pf = SET_P;
if ((ctrl & 1) == 0) // I frame
{
*f_type = I_FRM;
*f_id = I_I;
*nr = (ctrl >> 5);
*ns = (ctrl >> 1) & 7;
}
else
{
// Not I
*f_type = U_FRM;
*f_id = ctrl & 239;
switch (ctrl & 15)
{
case S_RR:
case S_RNR:
case S_REJ:
case S_SREJ:
*f_type = S_FRM;
}
if (*f_type == S_FRM)
{
*f_id = ctrl & 15;
*nr = ctrl >> 5;
}
}
if (*f_id == I_I || *f_id == U_UI)
{
i++;
*pid = frame[i];
i++;
if (len > i)
stringAdd(data, &frame[i], len - i - 2); // Exclude FCS
}
else if (*f_id == U_FRMR)
{
*pid = 0;
i++;
if (len > i)
stringAdd(data, &frame[i], len - i - 2); // Exclude FCS
}
}
void ax25_info_init(TAX25Port * AX25Sess)
{
AX25Sess->info.stat_s_pkt = 0;
AX25Sess->info.stat_s_byte = 0;
AX25Sess->info.stat_r_pkt = 0;
AX25Sess->info.stat_r_byte = 0;
AX25Sess->info.stat_r_fc = 0;
AX25Sess->info.stat_fec_count = 0;
AX25Sess->info.stat_l_r_byte = 0;
AX25Sess->info.stat_l_s_byte = 0;
AX25Sess->info.stat_begin_ses = 0;
AX25Sess->info.stat_end_ses = 0;
}
void clr_frm_win(TAX25Port * AX25Sess)
{
int i;
for (i = 0; i < 8; i++)
initString(&AX25Sess->frm_win[i]);
}
void ax25_init()
{
int snd_ch, port, i;
for (i = 0; i < 4; i++)
{
initTStringList(&all_frame_buf[i]);
initTStringList(&list_exclude_callsigns[i]);
initTStringList(&list_exclude_APRS_frm[i]);
initTStringList(&list_digi_callsigns[i]);
initTStringList(&KISS_acked[i]);
get_exclude_list(MyDigiCall[i], &list_digi_callsigns[i]);
get_exclude_list(exclude_callsigns[i], &list_exclude_callsigns[i]);
get_exclude_frm(exclude_APRS_frm[i], &list_exclude_APRS_frm[i]);
}
initTStringList(&list_incoming_mycalls);
// initTStringList(&list_incoming_mycalls_sock);
for (snd_ch = 0; snd_ch < 4; snd_ch++)
{
for (port = 0; port < port_num; port++)
{
TAX25Port * AX25Sess = &AX25Port[snd_ch][port];
AX25Sess->hi_vs = 0;
AX25Sess->vs = 0;
AX25Sess->vr = 0;
AX25Sess->PID = PID_NO_L3;
initTStringList(&AX25Sess->in_data_buf);
initString(&AX25Sess->out_data_buf);
AX25Sess->t1 = 0;
AX25Sess->t2 = 0;
AX25Sess->t3 = 0;
AX25Sess->i_lo = 0;
AX25Sess->i_hi = 0;
AX25Sess->n1 = 0;
AX25Sess->n2 = 0;
AX25Sess->status = 0;
AX25Sess->clk_frack = 0;
initTStringList(&AX25Sess->frame_buf);
initTStringList(&AX25Sess->I_frame_buf);
initTStringList(&AX25Sess->frm_collector);
AX25Sess->corrcall[0] = 0;
AX25Sess->mycall[0] = 0;
AX25Sess->digi[0] = 0;
AX25Sess->Path[0] = 0;
AX25Sess->kind[0] = 0;
AX25Sess->socket = NULL;
ax25_info_init(AX25Sess);
clr_frm_win(AX25Sess);
}
}
}
/*
procedure ax25_free;
var
snd_ch,port,i: byte;
begin
for snd_ch:=1 to 4 do
for port:=0 to port_num-1 do
begin
AX25Sess->in_data_buf.Free;
AX25Sess->frame_buf.Free;
AX25Sess->I_frame_buf.Free;
AX25Sess->frm_collector.Free;
end;
for i:=1 to 4 do
begin
all_frame_buf[i].Free;
list_exclude_callsigns[i].Free;
list_exclude_APRS_frm[i].Free;
list_digi_callsigns[i].Free;
end;
list_incoming_mycalls.Free;
list_incoming_mycalls_sock.Free;
end;
*/
void write_ax25_info(TAX25Port * AX25Sess)
{}
/*var
new: boolean;
t: text;
s: string;
time_ses: tdatetime;
time_ses_sec: extended;
call,mycall,spkt,sbyte,rpkt,rbyte,rfc,tcps,rcps,acps,startses,timeses: string;
begin
if stat_log then
begin
time_ses:=AX25Sess->info.stat_end_ses-AX25Sess->info.stat_begin_ses;
time_ses_sec:=time_ses*86400; //время сессии в секундах
if time_ses_sec<1 then exit;
mycall:=copy(AX25Sess->mycall+' ',1,9);
call:=copy(AX25Sess->corrcall+' ',1,9);
spkt:=copy(inttostr(AX25Sess->info.stat_s_pkt)+' ',1,6);
sbyte:=copy(inttostr(AX25Sess->info.stat_s_byte)+' ',1,9);
rpkt:=copy(inttostr(AX25Sess->info.stat_r_pkt)+' ',1,6);
rbyte:=copy(inttostr(AX25Sess->info.stat_r_byte)+' ',1,9);
rfc:=copy(inttostr(AX25Sess->info.stat_r_fc)+' ',1,6);
tcps:=copy(inttostr(round(AX25Sess->info.stat_s_byte/time_ses_sec))+' ',1,5);
rcps:=copy(inttostr(round(AX25Sess->info.stat_r_byte/time_ses_sec))+' ',1,5);
acps:=copy(inttostr(round(AX25Sess->info.stat_s_byte/time_ses_sec+AX25Sess->info.stat_r_byte/time_ses_sec))+' ',1,5);
timeses:=FormatDateTime('hh:mm:ss',time_ses);
startses:=FormatDateTime('dd-mm-yy hh:mm:ss',AX25Sess->info.stat_begin_ses);
s:=mycall+' '+call+' '+spkt+' '+sbyte+' '+rpkt+' '+rbyte+' '+rfc+' '+tcps+' '+rcps+' '+acps+' '+startses+' '+timeses;
assignfile(t,'log.txt');
if FileSearch('log.txt','')='' then new:=TRUE else new:=FALSE;
if new then
begin
rewrite(t);
writeln(t,'Mycall CorrCall TXPkt TXByte RXPkt RXByte FCPkt TXCPS RXCPS T.CPS Begin session SesTime');
writeln(t,'-------- --------- ------ --------- ------ --------- ------ ----- ----- ----- ----------------- --------');
end
else append(t);
if (AX25Sess->info.stat_s_byte>0) or (AX25Sess->info.stat_r_byte>0) then writeln(t,s);
closefile(t);
end;
end;
end.
*/
/*
Copyright 2001-2018 John Wiseman G8BPQ
This file is part of LinBPQ/BPQ32.
LinBPQ/BPQ32 is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
LinBPQ/BPQ32 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LinBPQ/BPQ32. If not, see http://www.gnu.org/licenses
*/
// Monitor Code - from moncode.asm
#define CMDBIT 4 // CURRENT MESSAGE IS A COMMAND
#define RESP 2 // CURRENT MSG IS RESPONSE
#define VER1 1 // CURRENT MSG IS VERSION 1
#define UI 3
#define SABM 0x2F
#define DISC 0x43
#define DM 0x0F
#define UA 0x63
#define FRMR 0x87
#define RR 1
#define RNR 5
#define REJ 9
#define PFBIT 0x10 // POLL/FINAL BIT IN CONTROL BYTE
#define NETROM_PID 0xCF
#define IP_PID 0xCC
#define ARP_PID 0xCD
#define NODES_SIG 0xFF
/*
DllExport int APIENTRY SetTraceOptions(int mask, int mtxparam, int mcomparam)
{
// Sets the tracing options for DecodeFrame. Mask is a bit
// mask of ports to monitor (ie 101 binary will monitor ports
// 1 and 3). MTX enables monitoring on transmitted frames. MCOM
// enables monitoring of protocol control frames (eg SABM, UA, RR),
// as well as info frames.
MMASK = mask;
MTX = mtxparam;
MCOM = mcomparam;
return (0);
}
DllExport int APIENTRY SetTraceOptionsEx(int mask, int mtxparam, int mcomparam, int monUIOnly)
{
// Sets the tracing options for DecodeFrame. Mask is a bit
// mask of ports to monitor (ie 101 binary will monitor ports
// 1 and 3). MTX enables monitoring on transmitted frames. MCOM
// enables monitoring of protocol control frames (eg SABM, UA, RR),
// as well as info frames.
MMASK = mask;
MTX = mtxparam;
MCOM = mcomparam;
MUIONLY = monUIOnly;
return 0;
}
*/
#define USHORT unsigned short
UCHAR MCOM = 1;
UCHAR MTX = 1;
ULONG MMASK = 0xF;
UCHAR MUIONLY = 0;
#define SREJ 0x0D
#define SABME 0x6F
#define XID 0xAF
#define TEST 0xE3
#define L4BUSY 0x80 // BNA - DONT SEND ANY MORE
#define L4NAK 0x40 // NEGATIVE RESPONSE FLAG
#define L4MORE 0x20 // MORE DATA FOLLOWS - FRAGMENTATION FLAG
#define L4CREQ 1 // CONNECT REQUEST
#define L4CACK 2 // CONNECT ACK
#define L4DREQ 3 // DISCONNECT REQUEST
#define L4DACK 4 // DISCONNECT ACK
#define L4INFO 5 // INFORMATION
#define L4IACK 6 // INFORMATION ACK
#pragma pack(1)
struct myin_addr {
union {
struct { unsigned char s_b1, s_b2, s_b3, s_b4; } S_un_b;
struct { unsigned short s_w1, s_w2; } S_un_w;
unsigned long addr;
};
};
typedef struct _IPMSG
{
// FORMAT OF IP HEADER
//
// NOTE THESE FIELDS ARE STORED HI ORDER BYTE FIRST (NOT NORMAL 8086 FORMAT)
UCHAR VERLEN; // 4 BITS VERSION, 4 BITS LENGTH
UCHAR TOS; // TYPE OF SERVICE
USHORT IPLENGTH; // DATAGRAM LENGTH
USHORT IPID; // IDENTIFICATION
USHORT FRAGWORD; // 3 BITS FLAGS, 13 BITS OFFSET
UCHAR IPTTL;
UCHAR IPPROTOCOL; // HIGHER LEVEL PROTOCOL
USHORT IPCHECKSUM; // HEADER CHECKSUM
struct myin_addr IPSOURCE;
struct myin_addr IPDEST;
UCHAR Data;
} IPMSG, *PIPMSG;
typedef struct _TCPMSG
{
// FORMAT OF TCP HEADER WITHIN AN IP DATAGRAM
// NOTE THESE FIELDS ARE STORED HI ORDER BYTE FIRST (NOT NORMAL 8086 FORMAT)
USHORT SOURCEPORT;
USHORT DESTPORT;
ULONG SEQNUM;
ULONG ACKNUM;
UCHAR TCPCONTROL; // 4 BITS DATA OFFSET 4 RESERVED
UCHAR TCPFLAGS; // (2 RESERVED) URG ACK PSH RST SYN FIN
USHORT WINDOW;
USHORT CHECKSUM;
USHORT URGPTR;
} TCPMSG, *PTCPMSG;
typedef struct _UDPMSG
{
// FORMAT OF UDP HEADER WITHIN AN IP DATAGRAM
// NOTE THESE FIELDS ARE STORED HI ORDER BYTE FIRST (NOT NORMAL 8086 FORMAT)
USHORT SOURCEPORT;
USHORT DESTPORT;
USHORT LENGTH;
USHORT CHECKSUM;
UCHAR UDPData[0];
} UDPMSG, *PUDPMSG;
// ICMP MESSAGE STRUCTURE
typedef struct _ICMPMSG
{
// FORMAT OF ICMP HEADER WITHIN AN IP DATAGRAM
// NOTE THESE FIELDS ARE STORED HI ORDER BYTE FIRST (NOT NORMAL 8086 FORMAT)
UCHAR ICMPTYPE;
UCHAR ICMPCODE;
USHORT ICMPCHECKSUM;
USHORT ICMPID;
USHORT ICMPSEQUENCE;
UCHAR ICMPData[0];
} ICMPMSG, *PICMPMSG;
typedef struct _L3MESSAGE
{
//
// NETROM LEVEL 3 MESSAGE - WITHOUT L2 INFO
//
UCHAR L3SRCE[7]; // ORIGIN NODE
UCHAR L3DEST[7]; // DEST NODE
UCHAR L3TTL; // TX MONITOR FIELD - TO PREVENT MESSAGE GOING // ROUND THE NETWORK FOR EVER DUE TO ROUTING LOOP
//
// NETROM LEVEL 4 DATA
//
UCHAR L4INDEX; // TRANSPORT SESSION INDEX
UCHAR L4ID; // TRANSPORT SESSION ID
UCHAR L4TXNO; // TRANSMIT SEQUENCE NUMBER
UCHAR L4RXNO; // RECEIVE (ACK) SEQ NUMBER
UCHAR L4FLAGS; // FRAGMENTATION, ACK/NAK, FLOW CONTROL AND MSG TYPE BITS
UCHAR L4DATA[236]; //DATA
} L3MESSAGE, *PL3MESSAGE;
typedef struct _MESSAGE
{
// BASIC LINK LEVEL MESSAGE BUFFER LAYOUT
struct _MESSAGE * CHAIN;
UCHAR PORT;
USHORT LENGTH;
UCHAR DEST[7];
UCHAR ORIGIN[7];
// MAY BE UP TO 56 BYTES OF DIGIS
UCHAR CTL;
UCHAR PID;
union
{ /* array named screen */
UCHAR L2DATA[256];
struct _L3MESSAGE L3MSG;
};
}MESSAGE, *PMESSAGE;
#pragma pack()
char * strlop(char * buf, char delim);
UCHAR * DisplayINP3RIF(UCHAR * ptr1, UCHAR * ptr2, unsigned int msglen);
char * DISPLAY_NETROM(MESSAGE * ADJBUFFER, UCHAR * Output, int MsgLen);
UCHAR * DISPLAYIPDATAGRAM(IPMSG * IP, UCHAR * Output, int MsgLen);
char * DISPLAYARPDATAGRAM(UCHAR * Datagram, UCHAR * Output);
int CountBits(unsigned long in)
{
int n = 0;
while (in)
{
if (in & 1) n++;
in >>= 1;
}
return n;
}
BOOL ConvToAX25(char * callsign, unsigned char * ax25call)
{
int i;
memset(ax25call, 0x40, 6); // in case short
ax25call[6] = 0x60; // default SSID
for (i = 0; i < 7; i++)
{
if (callsign[i] == '-')
{
//
// process ssid and return
//
i = atoi(&callsign[i + 1]);
if (i < 16)
{
ax25call[6] |= i << 1;
return (TRUE);
}
return (FALSE);
}
if (callsign[i] == 0 || callsign[i] == 13 || callsign[i] == ' ' || callsign[i] == ',')
{
//
// End of call - no ssid
//
return (TRUE);
}
ax25call[i] = callsign[i] << 1;
}
//
// Too many chars
//
return (FALSE);
}
int ConvFromAX25(unsigned char * incall, char * outcall)
{
int in, out = 0;
unsigned char chr;
memset(outcall, 0x20, 10);
for (in = 0; in < 6; in++)
{
chr = incall[in];
if (chr == 0x40)
break;
chr >>= 1;
outcall[out++] = chr;
}
chr = incall[6]; // ssid
if (chr == 0x42)
{
outcall[out++] = '-';
outcall[out++] = 'T';
return out;
}
if (chr == 0x44)
{
outcall[out++] = '-';
outcall[out++] = 'R';
return out;
}
chr >>= 1;
chr &= 15;
if (chr > 0)
{
outcall[out++] = '-';
if (chr > 9)
{
chr -= 10;
outcall[out++] = '1';
}
chr += 48;
outcall[out++] = chr;
}
return (out);
}
int IntDecodeFrame(MESSAGE * msg, char * buffer, time_t Stamp, UINT Mask, BOOL APRS, BOOL MCTL);
int APRSDecodeFrame(MESSAGE * msg, char * buffer, time_t Stamp, UINT Mask)
{
return IntDecodeFrame(msg, buffer, Stamp, Mask, TRUE, FALSE);
}
int myDecodeFrame(MESSAGE * msg, char * buffer, int Stamp)
{
return IntDecodeFrame(msg, buffer, Stamp, MMASK, FALSE, FALSE);
}
int IntDecodeFrame(MESSAGE * msg, char * buffer, time_t Stamp, UINT Mask, BOOL APRS, BOOL MINI)
{
UCHAR * ptr;
int n;
MESSAGE * ADJBUFFER;
ptrdiff_t Work;
UCHAR CTL;
BOOL PF = 0;
char CRCHAR[3] = " ";
char PFCHAR[3] = " ";
int Port;
int MSGFLAG = 0; //CR and V1 flags
char * Output = buffer;
int HH, MM, SS;
char TR = 'R';
char From[10], To[10];
BOOL Info = 0;
BOOL FRMRFLAG = 0;
BOOL XIDFLAG = 0;
BOOL TESTFLAG = 0;
size_t MsgLen = msg->LENGTH;
// MINI mode is for Node Listen (remote monitor) Mode. Keep info to minimum
/*
KO6IZ*>K7TMG-1:
/ex
KO6IZ*>K7TMG-1:
b
KO6IZ*>K7TMG-1 (UA)
W0TX*>KC6OAR>KB9KC>ID:
W0TX/R DRC/D W0TX-2/G W0TX-1/B W0TX-7/N
KC6OAR*>ID:
*/
// GET THE CONTROL BYTE, TO SEE IF THIS FRAME IS TO BE DISPLAYED
n = 8; // MAX DIGIS
ptr = &msg->ORIGIN[6]; // End of Address bit
while ((*ptr & 1) == 0)
{
// MORE TO COME
ptr += 7;
n--;
if (n == 0)
{
return 0; // Corrupt - no end of address bit
}
}
// Reached End of digis
Work = ptr - &msg->ORIGIN[6]; // Work is length of digis
MsgLen -= Work;
ADJBUFFER = (MESSAGE *)((UCHAR *)msg + Work); // ADJBUFFER points to CTL, etc. allowing for digis
CTL = ADJBUFFER->CTL;
if (CTL & PFBIT)
PF = TRUE;
CTL &= ~PFBIT;
if (MUIONLY)
if (CTL != 3)
return 0;
if ((CTL & 1) == 0 || CTL == FRMR || CTL == 3)
{
}
else
{
if (((CTL & 2) && MINI) == 0) // Want Control (but not super unless MCOM
if (MCOM == 0)
return 0; // Dont do control
}
Port = msg->PORT;
if (Port & 0x80)
{
if (MTX == 0)
return 0; // TRANSMITTED FRAME - SEE IF MTX ON
TR = 'T';
}
Port &= 0x7F;
if (((1 << (Port - 1)) & Mask) == 0) // Check MMASK
return 0;
Stamp = Stamp % 86400; // Secs
HH = (int)(Stamp / 3600);
Stamp -= HH * 3600;
MM = (int)(Stamp / 60);
SS = (int)(Stamp - MM * 60);
// Add Port: if MINI mode and monitoring more than one port
if (MINI == 0)
Output += sprintf((char *)Output, "%02d:%02d:%02d%c ", HH, MM, SS, TR);
else
if (CountBits(Mask) > 1)
Output += sprintf((char *)Output, "%d:", Port);
From[ConvFromAX25(msg->ORIGIN, From)] = 0;
To[ConvFromAX25(msg->DEST, To)] = 0;
Output += sprintf((char *)Output, "%s>%s", From, To);
// Display any Digi-Peaters
n = 8; // Max number of digi-peaters
ptr = &msg->ORIGIN[6]; // End of Address bit
while ((*ptr & 1) == 0)
{
// MORE TO COME
From[ConvFromAX25(ptr + 1, From)] = 0;
Output += sprintf((char *)Output, ",%s", From);
ptr += 7;
n--;
if (n == 0)
break;
// See if digi actioned - put a * on last actioned
if (*ptr & 0x80)
{
if (*ptr & 1) // if last address, must need *
*(Output++) = '*';
else
if ((ptr[7] & 0x80) == 0) // Repeased by next?
*(Output++) = '*'; // No, so need *
}
}
if (MINI == 0)
Output += sprintf((char *)Output, " Port=%d ", Port);
// Set up CR and PF
CRCHAR[0] = 0;
PFCHAR[0] = 0;
if (msg->DEST[6] & 0x80)
{
if (msg->ORIGIN[6] & 0x80) // Both set, assume V1
MSGFLAG |= VER1;
else
{
MSGFLAG |= CMDBIT;
CRCHAR[0] = ' ';
CRCHAR[1] = 'C';
if (PF) // If FP set
{
PFCHAR[0] = ' ';
PFCHAR[1] = 'P';
}
}
}
else
{
if (msg->ORIGIN[6] & 0x80) // Only Origin Set
{
MSGFLAG |= RESP;
CRCHAR[0] = ' ';
CRCHAR[1] = 'R';
if (PF) // If FP set
{
PFCHAR[0] = ' ';
PFCHAR[1] = 'F';
}
}
else
MSGFLAG |= VER1; // Neither, assume V1
}
if ((CTL & 1) == 0) // I frame
{
int NS = (CTL >> 1) & 7; // ISOLATE RECEIVED N(S)
int NR = (CTL >> 5) & 7;
Info = 1;
if (MINI == 0)
Output += sprintf((char *)Output, "<I%s%s S%d R%d>", CRCHAR, PFCHAR, NS, NR);
}
else if (CTL == 3)
{
// Un-numbered Information Frame
Output += sprintf((char *)Output, "<UI%s>", CRCHAR);
Info = 1;
}
else if (CTL & 2)
{
// UN Numbered
char SUP[6] = "??";
switch (CTL)
{
case SABM:
strcpy(SUP, "C");
break;
case SABME:
strcpy(SUP, "SABME");
break;
case XID:
strcpy(SUP, "XID");
XIDFLAG = 1;
break;
case TEST:
strcpy(SUP, "TEST");
TESTFLAG = 1;
break;
case DISC:
strcpy(SUP, "D");
break;
case DM:
strcpy(SUP, "DM");
break;
case UA:
strcpy(SUP, "UA");
break;
case FRMR:
strcpy(SUP, "FRMR");
FRMRFLAG = 1;
break;
}
if (MINI)
Output += sprintf((char *)Output, "<%s>", SUP);
else
Output += sprintf((char *)Output, "<%s%s%s>", SUP, CRCHAR, PFCHAR);
}
else
{
// Super
int NR = (CTL >> 5) & 7;
char SUP[5] = "??";
switch (CTL & 0x0F)
{
case RR:
strcpy(SUP, "RR");
break;
case RNR:
strcpy(SUP, "RNR");
break;
case REJ:
strcpy(SUP, "REJ");
break;
case SREJ:
strcpy(SUP, "SREJ");
break;
}
Output += sprintf((char *)Output, "<%s%s%s R%d>", SUP, CRCHAR, PFCHAR, NR);
}
if (FRMRFLAG)
Output += sprintf((char *)Output, " %02X %02X %02X", ADJBUFFER->PID, ADJBUFFER->L2DATA[0], ADJBUFFER->L2DATA[1]);
if (XIDFLAG)
{
// Decode and display XID
UCHAR * ptr = &ADJBUFFER->PID;
if (*ptr++ == 0x82 && *ptr++ == 0x80)
{
int Type;
int Len;
unsigned int value;
int xidlen = *(ptr++) << 8;
xidlen += *ptr++;
// XID is set of Type, Len, Value n-tuples
// G8BPQ-2>G8BPQ:(XID cmd, p=1) Half-Duplex SREJ modulo-128 I-Field-Length-Rx=256 Window-Size-Rx=32 Ack-Timer=3000 Retries=10
while (xidlen > 0)
{
Type = *ptr++;
Len = *ptr++;
value = 0;
xidlen -= (Len + 2);
while (Len--)
{
value <<= 8;
value += *ptr++;
}
switch (Type)
{
case 2: //Bin fields
case 3:
Output += sprintf((char *)Output, " %d=%x", Type, value);
break;
case 6: //RX Size
Output += sprintf((char *)Output, " RX Paclen=%d", value / 8);
break;
case 8: //RX Window
Output += sprintf((char *)Output, " RX Window=%d", value);
break;
}
}
}
}
if (Info)
{
// We have an info frame
switch (ADJBUFFER->PID)
{
case 0xF0: // Normal Data
{
char Infofield[257];
char * ptr1 = Infofield;
char * ptr2 = ADJBUFFER->L2DATA;
UCHAR C;
size_t len;
MsgLen = MsgLen - (19 + sizeof(void *));
if (MsgLen < 0 || MsgLen > 257)
return 0; // Duff
while (MsgLen--)
{
C = *(ptr2++);
if (APRS)
*(ptr1++) = C; // MIC-E needs all chars
else
{
// Convert to printable
C &= 0x7F;
if (C == 13 || C == 10 || C > 31)
*(ptr1++) = C;
}
}
len = ptr1 - Infofield;
Output[0] = ':';
Output[1] = 13;
memcpy(&Output[2], Infofield, len);
Output += (len + 2);
break;
}
case NETROM_PID:
Output = DISPLAY_NETROM(ADJBUFFER, Output, (int)MsgLen);
break;
case IP_PID:
Output += sprintf((char *)Output, " <IP>\r");
Output = DISPLAYIPDATAGRAM((IPMSG *)&ADJBUFFER->L2DATA[0], Output, (int)MsgLen);
break;
case ARP_PID:
Output = DISPLAYARPDATAGRAM(&ADJBUFFER->L2DATA[0], Output);
break;
case 8: // Fragmented IP
n = ADJBUFFER->L2DATA[0]; // Frag Count
Output += sprintf((char *)Output, "<Fragmented IP %02x>\r", n);
if (ADJBUFFER->L2DATA[0] & 0x80) // First Frag - Display Header
{
Output = DISPLAYIPDATAGRAM((IPMSG *)&ADJBUFFER->L2DATA[2], Output, (int)MsgLen - 1);
}
break;
}
}
if (Output[-1] != 13)
Output += sprintf((char *)Output, "\r");
return (int)(Output - buffer);
}
// Display NET/ROM data
char * DISPLAY_NETROM(MESSAGE * ADJBUFFER, UCHAR * Output, int MsgLen)
{
char Alias[7] = "";
char Dest[10];
char Node[10];
UCHAR TTL, Index, ID, TXNO, RXNO, OpCode, Flags, Window;
UCHAR * ptr = &ADJBUFFER->L2DATA[0];
if (ADJBUFFER->L2DATA[0] == NODES_SIG)
{
// Display NODES
// If an INP3 RIF (type <> UI) decode as such
if (ADJBUFFER->CTL != 3) // UI
return DisplayINP3RIF(&ADJBUFFER->L2DATA[1], Output, MsgLen - 24);
memcpy(Alias, ++ptr, 6);
ptr += 6;
Output += sprintf((char *)Output, " NODES broadcast from %s\r", Alias);
MsgLen -= 30; //Header, mnemonic and signature length
while (MsgLen > 20) // Entries are 21 bytes
{
Dest[ConvFromAX25(ptr, Dest)] = 0;
ptr += 7;
memcpy(Alias, ptr, 6);
ptr += 6;
strlop(Alias, ' ');
Node[ConvFromAX25(ptr, Node)] = 0;
ptr += 7;
Output += sprintf((char *)Output, " %s:%s via %s qlty=%d\r", Alias, Dest, Node, ptr[0]);
ptr++;
MsgLen -= 21;
}
return Output;
}
// Display normal NET/ROM transmissions
Output += sprintf((char *)Output, " NET/ROM\r ");
Dest[ConvFromAX25(ptr, Dest)] = 0;
ptr += 7;
Node[ConvFromAX25(ptr, Node)] = 0;
ptr += 7;
TTL = *(ptr++);
Index = *(ptr++);
ID = *(ptr++);
TXNO = *(ptr++);
RXNO = *(ptr++);
OpCode = Flags = *(ptr++);
OpCode &= 15; // Remove Flags
Output += sprintf((char *)Output, "%s to %s ttl %d cct=%02X%02X ", Dest, Node, TTL, Index, ID);
MsgLen -= 20;
switch (OpCode)
{
case L4CREQ:
Window = *(ptr++);
Dest[ConvFromAX25(ptr, Dest)] = 0;
ptr += 7;
Node[ConvFromAX25(ptr, Node)] = 0;
ptr += 7;
Output += sprintf((char *)Output, "<CON REQ> w=%d %s at %s", Window, Dest, Node);
if (MsgLen > 38) // BPQ Extended Params
{
short Timeout = (short)*ptr;
Output += sprintf((char *)Output, " t/o %d", Timeout);
}
return Output;
case L4CACK:
if (Flags & L4BUSY) // BUSY RETURNED
return Output + sprintf((char *)Output, " <CON NAK> - BUSY");
return Output + sprintf((char *)Output, " <CON ACK> w=%d my cct=%02X%02X", ptr[1], TXNO, RXNO);
case L4DREQ:
return Output + sprintf((char *)Output, " <DISC REQ>");
case L4DACK:
return Output + sprintf((char *)Output, " <DISC ACK>");
case L4INFO:
{
char Infofield[257];
char * ptr1 = Infofield;
UCHAR C;
size_t len;
Output += sprintf((char *)Output, " <INFO S%d R%d>", TXNO, RXNO);
if (Flags & L4BUSY)
*(Output++) = 'B';
if (Flags & L4NAK)
*(Output++) = 'N';
if (Flags & L4MORE)
*(Output++) = 'M';
MsgLen = MsgLen - (19 + sizeof(void *));
if (MsgLen < 0 || MsgLen > 257)
return Output; // Duff
while (MsgLen--)
{
C = *(ptr++);
// Convert to printable
C &= 0x7F;
if (C == 13 || C == 10 || C > 31)
*(ptr1++) = C;
}
len = ptr1 - Infofield;
Output[0] = ':';
Output[1] = 13;
memcpy(&Output[2], Infofield, len);
Output += (len + 2);
}
return Output;
case L4IACK:
Output += sprintf((char *)Output, " <INFO ACK R%d> ", RXNO);
if (Flags & L4BUSY)
*(Output++) = 'B';
if (Flags & L4NAK)
*(Output++) = 'N';
if (Flags & L4MORE)
*(Output++) = 'M';
return Output;
case 0:
// OPcode zero is used for several things
if (Index == 0x0c && ID == 0x0c) // IP
{
*(Output++) = 13;
*(Output++) = ' ';
Output = DISPLAYIPDATAGRAM((IPMSG *)ptr, Output, MsgLen);
return Output;
}
if (Index == 0 && ID == 1) // NRR
{
Output += sprintf((char *)Output, " <Record Route>\r");
MsgLen -= 23;
while (MsgLen > 6)
{
Dest[ConvFromAX25(ptr, Dest)] = 0;
if (ptr[7] & 0x80)
Output += sprintf((char *)Output, "%s* ", Dest);
else
Output += sprintf((char *)Output, "%s ", Dest);
ptr += 8;
MsgLen -= 8;
}
return Output;
}
}
Output += sprintf((char *)Output, " <???\?>");
return Output;
}
/*
PUBLIC L3IP
L3IP:
;
; TCP/IP DATAGRAM
;
mov EBX,OFFSET IP_MSG
call NORMSTR
;
INC ESI ; NOW POINTING TO IP HEADER
*/
UCHAR * DISPLAYIPDATAGRAM(IPMSG * IP, UCHAR * Output, int MsgLen)
{
UCHAR * ptr;
USHORT FRAGWORD;
ptr = (UCHAR *)&IP->IPSOURCE;
Output += sprintf((char *)Output, "%d.%d.%d.%d>", ptr[0], ptr[1], ptr[2], ptr[3]);
ptr = (UCHAR *)&IP->IPDEST;
Output += sprintf((char *)Output, "%d.%d.%d.%d LEN:%d ", ptr[0], ptr[1], ptr[2], ptr[3], htons(IP->IPLENGTH));
FRAGWORD = ntohs(IP->FRAGWORD);
if (FRAGWORD)
{
// If nonzero, check which bits are set
//Bit 0: reserved, must be zero
//Bit 1: (DF) 0 = May Fragment, 1 = Don't Fragment.
//Bit 2: (MF) 0 = Last Fragment, 1 = More Fragments.
//Fragment Offset: 13 bits
if (FRAGWORD & (1 << 14))
Output += sprintf((char *)Output, "DF ");
if (FRAGWORD & (1 << 13))
Output += sprintf((char *)Output, "MF ");
FRAGWORD &= 0xfff;
if (FRAGWORD)
{
Output += sprintf((char *)Output, "Offset %d ", FRAGWORD * 8);
return Output; // Cant display proto fields
}
}
if (IP->IPPROTOCOL == 6)
{
PTCPMSG TCP = (PTCPMSG)&IP->Data;
Output += sprintf((char *)Output, "TCP Src %d Dest %d ", ntohs(TCP->SOURCEPORT), ntohs(TCP->DESTPORT));
return Output;
}
if (IP->IPPROTOCOL == 1)
{
PICMPMSG ICMPptr = (PICMPMSG)&IP->Data;
Output += sprintf((char *)Output, "ICMP ");
if (ICMPptr->ICMPTYPE == 8)
Output += sprintf((char *)Output, "Echo Request ");
else
if (ICMPptr->ICMPTYPE == 0)
Output += sprintf((char *)Output, "Echo Reply ");
else
Output += sprintf((char *)Output, "Code %d", ICMPptr->ICMPTYPE);
return Output;
}
/*
MOV AL,IPPROTOCOL[ESI]
CMP AL,6
JNE @F
MOV EBX, OFFSET TCP
CALL NORMSTR
JMP ADD_CR
@@:
CMP AL,1
JNE @F
MOV EBX, OFFSET ICMP
CALL NORMSTR
JMP ADD_CR
@@:
CALL DISPLAY_BYTE_1 ; DISPLAY PROTOCOL TYPE
; mov AL,CR
; call PUTCHAR
;
; MOV ECX,39 ; TESTING
;IPLOOP:
; lodsb
; CALL BYTE_TO_HEX
;
; LOOP IPLOOP
JMP ADD_CR
*/
return Output;
}
char * DISPLAYARPDATAGRAM(UCHAR * Datagram, UCHAR * Output)
{
UCHAR * ptr = Datagram;
char Dest[10];
if (ptr[7] == 1) // Request
return Output + sprintf((char *)Output, " ARP Request who has %d.%d.%d.%d? Tell %d.%d.%d.%d",
ptr[26], ptr[27], ptr[28], ptr[29], ptr[15], ptr[16], ptr[17], ptr[18]);
// Response
Dest[ConvFromAX25(&ptr[8], Dest)] = 0;
return Output + sprintf((char *)Output, " ARP Reply %d.%d.%d.%d is at %s Tell %d.%d.%d.%d",
ptr[15], ptr[16], ptr[17], ptr[18], Dest, ptr[26], ptr[27], ptr[28], ptr[29]);
}
UCHAR * DisplayINP3RIF(UCHAR * ptr1, UCHAR * ptr2, unsigned int msglen)
{
char call[10];
int calllen;
int hops;
unsigned short rtt;
unsigned int len;
unsigned int opcode;
char alias[10] = "";
UCHAR IP[6];
int i;
ptr2 += sprintf(ptr2, " INP3 RIF:\r Alias Call Hops RTT\r");
while (msglen > 0)
{
calllen = ConvFromAX25(ptr1, call);
call[calllen] = 0;
// Validate the call
for (i = 0; i < calllen; i++)
{
if (!isupper(call[i]) && !isdigit(call[i]) && call[i] != '-')
{
ptr2 += sprintf(ptr2, " Corrupt RIF\r");
return ptr2;
}
}
ptr1 += 7;
hops = *ptr1++;
rtt = (*ptr1++ << 8);
rtt += *ptr1++;
IP[0] = 0;
strcpy(alias, " ");
msglen -= 10;
while (*ptr1 && msglen > 0)
{
len = *ptr1;
opcode = *(ptr1 + 1);
if (len < 2 || len > msglen)
{
ptr2 += sprintf(ptr2, " Corrupt RIF\r");
return ptr2;
}
if (opcode == 0 && len < 9)
{
memcpy(&alias[6 - (len - 2)], ptr1 + 2, len - 2); // Right Justiify
}
else
if (opcode == 1 && len < 8)
{
memcpy(IP, ptr1 + 2, len - 2);
}
ptr1 += len;
msglen -= len;
}
if (IP[0])
ptr2 += sprintf(ptr2, " %s:%s %d %4.2d %d.%d.%d.%d\r", alias, call, hops, rtt, IP[0], IP[1], IP[2], IP[3]);
else
ptr2 += sprintf(ptr2, " %s:%s %d %4.2d\r", alias, call, hops, rtt);
ptr1++;
msglen--; // EOP
}
return ptr2;
}
|