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
|
/*
Copyright 2001-2022 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
*/
//
// C replacement for Main.asm
//
#define Kernel
#define _CRT_SECURE_NO_DEPRECATE
#pragma data_seg("_BPQDATA")
//#include "windows.h"
//#include "winerror.h"
#include "time.h"
#include "stdio.h"
#include <fcntl.h>
#include "kernelresource.h"
#include "cheaders.h"
#include "tncinfo.h"
#include "mqtt.h"
#include "kiss.h"
VOID L2Routine(struct PORTCONTROL * PORT, PMESSAGE Buffer);
VOID ProcessIframe(struct _LINKTABLE * LINK, PDATAMESSAGE Buffer);
VOID FindLostBuffers();
VOID ReadMH();
void GetPortCTEXT(TRANSPORTENTRY * Session, char * Bufferptr, char * CmdTail, struct CMDX * CMD);
int upnpInit();
void AISTimer();
void ADSBTimer();
VOID SendSmartID(struct PORTCONTROL * PORT);
int CanPortDigi(int Port);
int KissEncode(UCHAR * inbuff, UCHAR * outbuff, int len);
void MQTTTimer();
void SaveMH();
VOID InformPartner(struct _LINKTABLE * LINK, int Reason);
VOID L2SENDCOMMAND(struct _LINKTABLE * LINK, int CMD);
void WritePacketLogThread(void * param);
void hookNodeStarted();
void hookNodeRunning();
void DeleteLogFiles(int Age);
void APIL2Trace(struct _MESSAGE * Message, char * Dirn);
DllExport VOID APIENTRY CloseDebugLog();
#include "configstructs.h"
extern struct CONFIGTABLE xxcfg;
extern BOOL needAIS;
extern int needADSB;
extern int EnableOARCAPI;
extern SOCKET NodeAPISocket;
extern int nodeStartedSent;
extern SOCKADDR_IN UDPreportdest;
extern char NodeAPIServer[80];
extern int NodeAPIPort;
extern int RIFInterval;
extern int LOCALNOTSECURE;
time_t LastNodeStatus = 0;
int nodeStatusTimer = 20 * 60; // 20 mins
int LogAge = 10;
struct PORTCONFIG * PortRec;
#define RNRSET 0x2 // RNR RECEIVED FROM OTHER END
#define PFBIT 0x10 // POLL/FINAL BIT IN CONTROL BYTE
// STATION INFORMATION
char DATABASESTART[14] = "";
char xMAJORVERSION = 4;
char xMINORVERSION = 9;
char FILLER1[16] = "";
struct ROUTE * NEIGHBOURS = NULL;
int ROUTE_LEN = sizeof(struct ROUTE);
int MAXNEIGHBOURS = 20;
struct DEST_LIST * DESTS = NULL; // NODE LIST
int DEST_LIST_LEN = sizeof(struct DEST_LIST);
struct _LINKTABLE * LINKS = NULL;
int LINK_TABLE_LEN = sizeof (struct _LINKTABLE);
int MAXLINKS = 30;
char MYCALL[7] = ""; // DB 7 DUP (0) ; NODE CALLSIGN (BIT SHIFTED)
char MYALIASTEXT[6] = ""; // DB ' ' ; NODE ALIAS (KEEP TOGETHER)
char MYALIASLOPPED[10];
char MYCALLLOPPED[10];
UCHAR MYCALLWITHALIAS[13] = "";
UCHAR NETROMCALL[7] = ""; // Call used for NETROM (can be MYCALL)
APPLCALLS APPLCALLTABLE[NumberofAppls] = {0};
UCHAR MYNODECALL[10] = ""; // NODE CALLSIGN (ASCII)
UCHAR MYNETROMCALL[10] = ""; // NETROM CALLSIGN (ASCII)
char NODECALLLOPPED[10];
VOID * FREE_Q = NULL;
time_t TimeLoaded = 0;
struct PORTCONTROL * PORTTABLE = NULL;
int NUMBEROFPORTS = 0;
int PORTENTRYLEN = sizeof(struct PORTCONTROL);
struct DEST_LIST * ENDDESTLIST = NULL; // ; NODE LIST+1
;
VOID * BUFFERPOOL = NULL; // START OF BUFFER POOL
VOID * ENDBUFFERPOOL = NULL;
int OBSINIT = 5; // INITIAL OBSOLESCENCE VALUE
int OBSMIN = 4; // MINIMUM TO BROADCAST
int L3INTERVAL = 60; // 'NODES' INTERVAL IN MINS
int IDINTERVAL = 20; // 'ID' BROADCAST INTERVAL
int BTINTERVAL = 20; // 'BT' BROADCAST INTERVAL
int MINQUAL = 10; // MIN QUALITY FOR AUTOUPDATES
int HIDENODES = 0; // N * COMMAND SWITCH
int BBSQUAL = 255; // QUALITY OF BBS RELATIVE TO NODE
int NUMBEROFBUFFERS = 999; // PACKET BUFFERS
int PACLEN = 100; //MAX PACKET SIZE
// L2 SYSTEM TIMER RUNS AT 3 HZ
int T3 = 3*61*10; // LINK VALIDATION TIMER (3 MINS) (+ a bit to reduce RR collisions)
int L2KILLTIME = 16*60*10; // IDLE LINK TIMER (16 MINS)
int L3LIVES = 15; // MAX L3 HOPS
int L4N2 = 3; // LEVEL 4 RETRY COUNT
int L4LIMIT = 60*15; // IDLE SESSION LIMIT - 15 MINS
int L4DELAY = 5; // L4 DELAYED ACK TIMER
int BBS = 1; // INCLUDE BBS SUPPORT
int NODE = 1; // INCLUDE SWITCH SUPPORT
int FULL_CTEXT = 1; // CTEXT ON ALL CONNECTS IF NZ
int L4Compress = 0;
int L4CompMaxframe = 3;
int L4CompPaclen = 236;
int L2Compress = 0;
int L2CompMaxframe = 3;
int L2CompPaclen = 236;
int PREFERINP3ROUTES = 0;
BOOL LogL4Connects = FALSE;
BOOL LogAllConnects = FALSE;
BOOL AUTOSAVEMH = TRUE;
extern BOOL ADIFLogEnabled;
extern UCHAR LogDirectory[260];
extern BOOL EventsEnabled;
extern BOOL SaveAPRSMsgs;
BOOL M0LTEMap = FALSE;
BOOL MQTT = FALSE;
char MQTT_HOST[80] = "";
int MQTT_PORT = 0;
char MQTT_USER[80] = "";
char MQTT_PASS[80] = "";
int MQTT_Connecting = 0;
int MQTT_Connected = 0;
int PoolBuilt = 0;
//TNCTABLE DD 0
//NUMBEROFSTREAMS DD 0
extern VOID * ENDPOOL;
extern void * APPL_Q; // Queue of frames for APRS Appl
extern BOOL APRSActive;
extern int DEBUGINP3;
#define BPQHOSTSTREAMS 64
// Although externally streams are numbered 1 to 64, internally offsets are 0 - 63
BPQVECSTRUC XDUMMY = {0}; // Needed to force correct order of following
BPQVECSTRUC BPQHOSTVECTOR[BPQHOSTSTREAMS + 5] = {0};
BPQVECSTRUC * TELNETMONVECPTR = &BPQHOSTVECTOR[BPQHOSTSTREAMS];
BPQVECSTRUC * AGWMONVECPTR = &BPQHOSTVECTOR[BPQHOSTSTREAMS + 1];
BPQVECSTRUC * APRSMONVECPTR = &BPQHOSTVECTOR[BPQHOSTSTREAMS + 2];
BPQVECSTRUC * IPHOSTVECTORPTR = &BPQHOSTVECTOR[BPQHOSTSTREAMS + 3];
BPQVECSTRUC * FILEMONVECTOR = &BPQHOSTVECTOR[BPQHOSTSTREAMS + 4];
int BPQVECLENGTH = sizeof(BPQVECSTRUC);
int MONTOFILEFLAG = 0;
int NODEORDER = 0;
UCHAR LINKEDFLAG = 0;
UCHAR UNPROTOCALL[80] = "";
UCHAR ExcludeList[71] = ""; // 10 ENTRIES, 7 BYTES EACH
char * INFOMSG = NULL;
char * CTEXTMSG = NULL;
int CTEXTLEN = 0;
UCHAR MYALIAS[7] = ""; // ALIAS IN AX25 FORM
UCHAR BBSALIAS[7] = "";
UCHAR AX25CALL[7] = ""; // WORK AREA FOR AX25 <> NORMAL CALL CONVERSION
UCHAR NORMCALL[10] = ""; // CALLSIGN IN NORMAL FORMAT
int NORMLEN = 0; // LENGTH OF CALL IN NORMCALL
int CURRENTPORT = 0; // PORT FOR CURRENT MESSAGE
VOID * CURRENTPORTPTR = NULL; // PORT CONTROL TABLE ENTRY FOR CURRENT PORT
int SDCBYTE = 0; // CONTROL BYTE FOR CURRENT FRAME
VOID * BUFFER = NULL; // GENERAL SAVE AREA FOR BUFFER ADDR
VOID * ADJBUFFER = NULL; // BASE ADJUSED FOR DIGIS
UCHAR TEMPFIELD[7] = ""; // ADDRESS WORK FILED
void * TRACE_Q = NULL; // TRANSMITTED FRAMES TO BE TRACED
int RANDOM = 0; // 'RANDOM' NUMBER FOR PERSISTENCE CALCS
int L2TIMERFLAG = 0; // INCREMENTED AT 18HZ BY TIMER INTERRUPT
char HEADERCHAR = '}'; // CHAR FOR _NODE HEADER MSGS
VOID * LASTPOINTER = NULL; // PERVIOUS _NODE DURING CHAINING
int REALTIMETICKS = 0; // Count of 100 ms intervals since load
VOID * CONFIGPTR = NULL; // Internal Config Get Offset
int AUTOSAVE = 0; // AUTO SAVE NODES ON EXIT FLAG
int L4APPL = 1; // Application for BBSCALL/ALIAS connects
int CFLAG = 0; // C =HOST Command
VOID * IDMSG_Q = NULL; // ID/BEACONS WAITING TO BE SENT
int NODESINPROGRESS = 0;
int NODESToOnePort = 0; // Set to port num to send NODES to only one port.
VOID * CURRENTNODE = NULL; // NEXT _NODE TO SEND
VOID * DESTHEADER = NULL; // HEAD OF SORTED NODES CHAIN
int L3TIMER = 1; // TIMER FOR 'NODES' MESSAGE
int IDTIMER = 0; // TIMER FOR ID MESSAGE
int BTTIMER = 0; // TIMER FOR BT MESSAGE
UCHAR * NEXTFREEDATA = NULL; // ADDRESS OF NEXT FREE BYTE of shared memory
int NEEDMH = 0;
struct DATAMESSAGE BTHDDR = {0,0,9,240,13};
struct _MESSAGE IDHDDR = {0,0,23,0,0,3, 240};
VOID * IDMSG = &IDHDDR;
//DD 0 ; CHAIN
// DB 0 ; PORT
int BTLENGTH = 9; // DW 9 ; LENGTH
// DB 0F0H ; PID
char BTEXTFLD[256] ="\r";
char BridgeMap[MaxBPQPortNo + 1][MaxBPQPortNo + 1] = {0};
// Keep Buffers at end
#define DATABYTES 800000 // WAS 320000
UCHAR XXXXXXXX[DATABYTES] = "";
UCHAR * DATAAREA = &XXXXXXXX[0];
void ** Bufferlist[1000] = {0};
extern BOOL IPRequired;
extern BOOL PMRequired;
extern int MaxHops;
extern int MAXRTT;
extern USHORT CWTABLE[];
extern struct _TRANSPORTENTRY * L4TABLE;
extern UCHAR ROUTEQUAL;
extern UINT BPQMsg;
extern int NUMBEROFTNCPORTS;
extern APPLCALLS APPLCALLTABLE[];
// LOOPBACK PORT ROUTINES
VOID LINKINIT(PEXTPORTDATA PORTVEC)
{
WritetoConsoleLocal("Loopback\n");
}
VOID LINKTX(PEXTPORTDATA PORTVEC, PMESSAGE Buffer)
{
// LOOP BACK TO SWITCH
struct _LINKTABLE * LINK;
LINK = Buffer->Linkptr;
if (LINK)
{
if (LINK->L2TIMER)
LINK->L2TIMER = LINK->L2TIME;
Buffer->Linkptr = 0; // CLEAR FLAG FROM BUFFER
}
C_Q_ADD(&PORTVEC->PORTCONTROL.PORTRX_Q, Buffer);
}
VOID LINKRX()
{
}
VOID LINKTIMER()
{
}
VOID LINKCLOSE()
{
}
VOID EXTCLOSE()
{
}
BOOL KISSTXCHECK()
{
return 0;
}
BOOL LINKTXCHECK()
{
return 0;
}
void * Dummy(int fn, int port, PDATAMESSAGE buff) // Dummy for missing EXT Driver
{
return 0;
}
VOID EXTINIT(PEXTPORTDATA PORTVEC)
{
// LOAD DLL - NAME IS IN PORT_DLL_NAME
void *(* Startup) (PEXTPORTDATA PORTVEC); // ADDR OF Startup ROUTINE
PORTVEC->PORT_EXT_ADDR = Dummy;
Startup = InitializeExtDriver(PORTVEC);
if (Startup == 0)
{
WritetoConsoleLocal("Driver installation failed\n");
return;
}
// CALL THE ROUTINE TO START IT UP
// Startup returns address of processing routine
PORTVEC->PORT_EXT_ADDR = (void *(__cdecl *)(int,int,PDATAMESSAGE))Startup(PORTVEC);;
if (PORTVEC->PORT_EXT_ADDR == 0)
{
WritetoConsoleLocal("Driver Initialisation failed\n");
return;
}
}
VOID EXTTX(PEXTPORTDATA PORTVEC, MESSAGE * Buffer)
{
struct _LINKTABLE * LINK;
struct PORTCONTROL * PORT = (struct PORTCONTROL *)PORTVEC;
// RESET TIMER, unless BAYCOM
if (PORT->KISSFLAGS == 255) // Used for BAYCOM
{
PORTVEC->PORT_EXT_ADDR(2, PORT->PORTNUMBER, (PDATAMESSAGE)Buffer);
return; // Baycom driver passes frames to trace once sent
}
LINK = Buffer->Linkptr;
if (LINK)
{
if (LINK->L2TIMER)
LINK->L2TIMER = LINK->L2TIME;
if (PORT->TNC == 0 || PORT->TNC->Hardware != H_KISSHF)
Buffer->Linkptr = 0; // CLEAR FLAG FROM BUFFER
}
PORTVEC->PORT_EXT_ADDR(2, PORT->PORTNUMBER, (PDATAMESSAGE)Buffer);
if (PORT->PROTOCOL == 10 && PORT->TNC && PORT->TNC->Hardware != H_KISSHF)
{
ReleaseBuffer(Buffer);
return;
}
C_Q_ADD(&TRACE_Q, Buffer);
return;
}
VOID * GetBuffQuick();
UINT ReleaseBufferQuick(VOID *pBUFF);
VOID EXTRX(PEXTPORTDATA PORTVEC)
{
struct _MESSAGE * Message;
size_t Len;
struct PORTCONTROL * PORT = (struct PORTCONTROL *)PORTVEC;
Loop:
if (QCOUNT < 10)
return;
Message = GetBuffQuick();
if (Message == NULL)
return;
Len = (size_t)PORTVEC->PORT_EXT_ADDR(1, PORT->PORTNUMBER, (PDATAMESSAGE)Message);
if (Len == 0)
{
ReleaseBufferQuick((UINT *)Message);
return;
}
if (PORT->PROTOCOL == 10)
{
// PACTOR Style Port - Negative values used to report events - for now -1 = Disconnected
if (Len == -1)
{
int Sessno = Message->PORT;
TRANSPORTENTRY * Session;
ReleaseBufferQuick((UINT *)Message);
// GET RID OF ANY SESSION ENTRIES
Session = PORTVEC->ATTACHEDSESSIONS[Sessno];
if (Session)
{
struct TNCINFO * TNC = PORTVEC->PORTCONTROL.TNC;
CloseSessionPartner(Session);
// is this the place to run DisconnectScript?
if (TNC->DisconnectScript)
{
int n = 0;
struct DATAMESSAGE * Buffer;
TRANSPORTENTRY Session = {0}; // = TNC->PortRecord->ATTACHEDSESSIONS[Sessno];
while (TNC->DisconnectScript[n])
{
Buffer = GetBuff();
if (Buffer)
{
Session.Secure_Session = 1;
Session.CIRCUITINDEX = -1;
Buffer->LENGTH = sprintf(Buffer->L2DATA, "%s\r", TNC->DisconnectScript[n++]) + (sizeof(void *) + 4);
CommandHandler(&Session, Buffer);
strlop(Buffer->L2DATA, 13);
Debugprintf("Disconnect Script Output %s", Buffer->L2DATA);
};
}
}
PORTVEC->ATTACHEDSESSIONS[Sessno] = NULL;
}
return;
}
}
C_Q_ADD(&PORT->PORTRX_Q, (UINT *)Message);
goto Loop;
return;
}
VOID EXTTIMER(PEXTPORTDATA PORTVEC)
{
// Called every 100 mS
// USED TO SEND A RE-INIT IN THE CORRECT PROCESS
struct TNCINFO * TNC = TNCInfo[PORTVEC->PORTCONTROL.PORTNUMBER];
if (PORTVEC->EXTRESTART)
{
PORTVEC->EXTRESTART = 0; //CLEAR
PORTVEC->PORT_EXT_ADDR(4, PORTVEC->PORTCONTROL.PORTNUMBER, 0);
}
PORTVEC->PORT_EXT_ADDR(7, PORTVEC->PORTCONTROL.PORTNUMBER, 0); // Timer Routine
if (TNC && TNC->PageChanged)
{
BuildDevicePage(TNC);
TNC->PageChanged = FALSE;
}
}
VOID EXTSLOWTIMER(PEXTPORTDATA PORTVEC)
{
// Called every minute 60 secs
PORTVEC->PORT_EXT_ADDR(8, PORTVEC->PORTCONTROL.PORTNUMBER, 0); // Timer Routine
}
size_t EXTTXCHECK(PEXTPORTDATA PORTVEC, int Chan)
{
uintptr_t Temp = Chan;
return (size_t)PORTVEC->PORT_EXT_ADDR(3, PORTVEC->PORTCONTROL.PORTNUMBER, (void *)Temp);
}
VOID PostDataAvailable(TRANSPORTENTRY * Session)
{
#ifndef LINBPQ
if (Session->L4CIRCUITTYPE & BPQHOST)
{
BPQVECSTRUC * HostSess = Session->L4TARGET.HOST;
if (HostSess)
{
if (HostSess->HOSTHANDLE)
{
PostMessage(HostSess->HOSTHANDLE, BPQMsg, HostSess->HOSTSTREAM, 2);
}
}
}
#endif
}
VOID PostStateChange(TRANSPORTENTRY * Session)
{
#ifndef LINBPQ
if (Session->L4CIRCUITTYPE & BPQHOST)
{
BPQVECSTRUC * HostSess = Session->L4TARGET.HOST;
if (HostSess)
{
if (HostSess->HOSTHANDLE);
{
PostMessage(HostSess->HOSTHANDLE, BPQMsg, HostSess->HOSTSTREAM, 4);
}
}
}
#endif
}
#ifdef LINBPQ
#define HDLCTX KHDLCTX
#define HDLCRX KHDLCRX
#define HDLCTIMER KHDLCTIMER
#define HDLCCLOSE KHDLCCLOSE
#define HDLCTXCHECK KHDLCTXCHECK
#define PC120INIT KHDLCINIT
#define DRSIINIT KHDLCINIT
#define TOSHINIT KHDLCINIT
#define RLC100INIT KHDLCINIT
#define BAYCOMINIT KHDLCINIT
#define PA0INIT KHDLCINIT
int KHDLCINIT(PHDLCDATA PORTVEC);
void KHDLCTX(struct KISSINFO * KISS, PMESSAGE Buffer);
int KHDLCRX(PHDLCDATA PORTVEC);
void KHDLCTIMER(PHDLCDATA PORTVEC);
void KHDLCCLOSE(PHDLCDATA PORTVEC);
BOOL KHDLCTXCHECK();
#else
extern VOID PC120INIT(), DRSIINIT(), TOSHINIT();
extern VOID RLC100INIT(), BAYCOMINIT(), PA0INIT();
extern VOID HDLCTX();
extern VOID HDLCRX();
extern VOID HDLCTIMER();
extern VOID HDLCCLOSE();
extern VOID HDLCTXCHECK();
#endif
extern VOID KISSINIT(), KISSTX(), KISSRX(), KISSTIMER(), KISSCLOSE();
extern VOID EXTINIT(PEXTPORTDATA PORTVEC), EXTTX(PEXTPORTDATA PORTVEC, MESSAGE * Buffer), LINKRX(), EXTRX(PEXTPORTDATA PORTVEC);
extern VOID LINKCLOSE(), EXTCLOSE() ,LINKTIMER(), EXTTIMER(PEXTPORTDATA PORTVEC);
// VECTORS TO HARDWARE DEPENDENT ROUTINES
VOID * INITCODE[12] = {KISSINIT, PC120INIT, DRSIINIT, TOSHINIT, KISSINIT,
RLC100INIT, RLC100INIT, LINKINIT, EXTINIT, BAYCOMINIT, PA0INIT, KISSINIT};
VOID * TXCODE[12] = {KISSTX, HDLCTX, HDLCTX, HDLCTX, KISSTX,
HDLCTX, HDLCTX, LINKTX, EXTTX, HDLCTX, HDLCTX, KISSTX};
VOID * RXCODE[12] = {KISSRX, HDLCRX, HDLCRX, HDLCRX, KISSRX,
HDLCRX, HDLCRX, LINKRX, EXTRX, HDLCRX, HDLCRX, KISSRX};
VOID * TIMERCODE[12] = {KISSTIMER, HDLCTIMER, HDLCTIMER, HDLCTIMER, KISSTIMER,
HDLCTIMER, HDLCTIMER, LINKTIMER, EXTTIMER, HDLCTIMER, HDLCTIMER, KISSTIMER};
VOID * CLOSECODE[12] = {KISSCLOSE, HDLCCLOSE, HDLCCLOSE, HDLCCLOSE, KISSCLOSE,
HDLCCLOSE, HDLCCLOSE, LINKCLOSE, EXTCLOSE, HDLCCLOSE, HDLCCLOSE, KISSCLOSE};
VOID * TXCHECKCODE[12] = {KISSTXCHECK, HDLCTXCHECK, HDLCTXCHECK, HDLCTXCHECK, KISSTXCHECK,
HDLCTXCHECK, HDLCTXCHECK, LINKTXCHECK, EXTTXCHECK, HDLCTXCHECK, HDLCTXCHECK, KISSTXCHECK};
extern int BACKGROUND();
extern int L2TimerProc();
extern int L3MinuteTimerProc();
extern int L4SecTimer();
extern int L3SecTimer();
extern int StatsTimer();
extern int COMMANDHANDLER();
VOID SDETX(struct _LINKTABLE * LINK);
extern int L4BG();
extern int L3BG();
extern int TNCTimerProc();
extern int PROCESSIFRAME();
int xxxxx = MAXDATA;
BOOL Start()
{
struct CONFIGTABLE * cfg = &xxcfg;
struct APPLCONFIG * ptr1;
struct PORTCONTROL * PORT;
struct FULLPORTDATA * FULLPORT; // Including HW Data
struct FULLPORTDATA * NEXTPORT; // Including HW Data
struct _EXTPORTDATA * EXTPORT;
APPLCALLS * APPL;
struct ROUTE * ROUTE;
struct DEST_LIST * DEST;
struct CMDX * CMD;
int PortSlot = 1;
uintptr_t int3;
int index = 0; // Entry No. in ROUTES
unsigned char * ptr2 = 0, * ptr3, * ptr4;
USHORT * CWPTR;
int i, n;
struct ROUTECONFIG * Rcfg;
NEXTFREEDATA = &DATAAREA[0]; // For Reinit
memset(DATAAREA, 0, DATABYTES);
// Reinit everything in case of restart
FREE_Q = 0;
TRACE_Q = 0;
IDMSG_Q = 0;
NUMBEROFPORTS = 0;
MAXBUFFS = 0;
QCOUNT = 0;
NUMBEROFNODES = 0;
DESTHEADER = 0;
NODESINPROGRESS = 0;
CURRENTNODE = 0;
L3TIMER = 1; // SEND NODES
if (cfg->C_NODEALIAS[0] == 0)
memset(cfg->C_NODEALIAS, ' ', 10);
TimeLoaded = NOW;
AUTOSAVE = cfg->C_AUTOSAVE;
if (cfg->C_L4APPL)
L4APPL = cfg->C_L4APPL;
CFLAG = cfg->C_C;
IPRequired = cfg->C_IP;
PMRequired = cfg->C_PM;
if (cfg->C_MAXHOPS)
MaxHops = cfg->C_MAXHOPS;
if (cfg->C_MAXRTT)
MAXRTT = cfg->C_MAXRTT * 100;
if (cfg->C_NODE == 0 && cfg->C_BBS)
{
// USE BBS CALL FOR NODE if Set, otherwise find first APPLCALL
// Unless BBS also = 0
if (cfg->C_BBSCALL[0])
{
memcpy(MYNODECALL, cfg->C_BBSCALL, 10);
memcpy(MYALIASTEXT, cfg->C_BBSALIAS, 6);
memcpy(MYALIASLOPPED, cfg->C_BBSALIAS, 10);
}
else
{
ptr1 = &cfg->C_APPL[0];
for (i = 0; i < NumberofAppls; i++)
{
if (ptr1->ApplCall[0] != ' ')
{
memcpy(MYNODECALL, &ptr1->ApplCall[0], 10);
memcpy(MYALIASTEXT, &ptr1->ApplAlias, 6);
memcpy(MYALIASLOPPED, &ptr1->ApplAlias, 10);
break;
}
ptr1++;
}
}
}
else
{
memcpy(MYNODECALL, cfg->C_NODECALL, 10);
memcpy(MYALIASTEXT, cfg->C_NODEALIAS, 6);
memcpy(MYALIASLOPPED, cfg->C_NODEALIAS, 10);
}
strlop(MYALIASLOPPED, ' ');
// IF NO BBS, SET BOTH TO _NODE CALLSIGN
if (cfg->C_BBS == 0)
{
memcpy(APPLCALLTABLE[0].APPLCALL_TEXT, cfg->C_NODECALL, 10);
memcpy(APPLCALLTABLE[0].APPLALIAS_TEXT, cfg->C_NODEALIAS, 10);
}
else
{
memcpy(APPLCALLTABLE[0].APPLCALL_TEXT, cfg->C_BBSCALL, 10);
memcpy(APPLCALLTABLE[0].APPLALIAS_TEXT, cfg->C_BBSALIAS, 10 );
}
BBSQUAL = cfg->C_BBSQUAL;
// copy MYCALL to NETROMCALL
memcpy(MYNETROMCALL, MYNODECALL, 10);
// if NETROMCALL Defined, use it
if (cfg->C_NETROMCALL[0] && cfg->C_NETROMCALL[0] != ' ')
memcpy(MYNETROMCALL, cfg->C_NETROMCALL, 10);
strlop(MYNETROMCALL, ' ');
strlop(MYNODECALL, ' ');
memcpy(NODECALLLOPPED, MYNODECALL, 10);
strlop(NODECALLLOPPED, ' ');
APPLCALLTABLE[0].APPLQUAL = BBSQUAL;
if (cfg->C_WASUNPROTO == 0 && cfg->C_BTEXT)
{
char * ptr1 = &cfg->C_BTEXT[0];
char * ptr2 = BTHDDR.L2DATA;
int len = 120;
BTHDDR.LENGTH = 1; // PID
while ((*ptr1) && len--)
{
*(ptr2++) = *(ptr1++);
BTHDDR.LENGTH ++;
}
}
OBSINIT = cfg->C_OBSINIT;
OBSMIN = cfg->C_OBSMIN;
L3INTERVAL = cfg->C_NODESINTERVAL;
IDINTERVAL = cfg->C_IDINTERVAL;
if (IDINTERVAL)
IDTIMER = 2;
BTINTERVAL = cfg->C_BTINTERVAL;
if (BTINTERVAL)
BTTIMER = 2;
MINQUAL = cfg->C_MINQUAL;
FULL_CTEXT = cfg->C_FULLCTEXT;
L3LIVES = cfg->C_L3TIMETOLIVE;
L4N2 = cfg->C_L4RETRIES;
L4DEFAULTWINDOW = cfg->C_L4WINDOW;
L4T1 = cfg->C_L4TIMEOUT;
// MOV AX,C_BUFFERS
// MOV NUMBEROFBUFFERS,AX
PACLEN = cfg->C_PACLEN;
T3 = cfg->C_T3 * 10;
L4LIMIT = cfg->C_IDLETIME;
if (L4LIMIT && L4LIMIT < 120)
L4LIMIT = 120; // Don't allow stupidly low
L2KILLTIME = L4LIMIT * 10;
L4DELAY = cfg->C_L4DELAY;
BBS = cfg->C_BBS;
NODE = cfg->C_NODE;
LINKEDFLAG = cfg->C_LINKEDFLAG;
MAXLINKS = cfg->C_MAXLINKS;
MAXDESTS = cfg->C_MAXDESTS;
MAXNEIGHBOURS = cfg->C_MAXNEIGHBOURS;
if (MAXNEIGHBOURS == 0)
MAXNEIGHBOURS = 1;
MAXCIRCUITS = cfg->C_MAXCIRCUITS;
HIDENODES = cfg->C_HIDENODES;
LogL4Connects = cfg->C_LogL4Connects;
LogAllConnects = cfg->C_LogAllConnects;
AUTOSAVEMH = cfg->C_SaveMH;
ADIFLogEnabled = cfg->C_ADIF;
EventsEnabled = cfg->C_EVENTS;
SaveAPRSMsgs = cfg->C_SaveAPRSMsgs;
M0LTEMap = cfg->C_M0LTEMap;
MQTT = cfg->C_MQTT;
strcpy(MQTT_HOST, cfg->C_MQTT_HOST);
MQTT_PORT = cfg->C_MQTT_PORT;
strcpy(MQTT_USER, cfg->C_MQTT_USER);
strcpy(MQTT_PASS, cfg->C_MQTT_PASS);
L4Compress = cfg->C_L4Compress;
L4CompMaxframe = cfg->C_L4CompMaxframe;
L4CompPaclen = cfg->C_L4CompPaclen;
if (L4CompMaxframe < 1 || L4CompMaxframe > 16)
L4CompMaxframe = 3;
if (L4CompPaclen < 64 || L4CompPaclen > 236)
L4CompPaclen = 236;
L2Compress = cfg->C_L2Compress;
L2CompMaxframe = cfg->C_L2CompMaxframe;
L2CompPaclen = cfg->C_L2CompPaclen;
if (L2CompMaxframe < 1 || L2CompMaxframe > 16)
L2CompMaxframe = 3;
if (L2CompPaclen < 64 || L2CompPaclen > 236)
L2CompPaclen = 236;
PREFERINP3ROUTES = cfg->C_PREFERINP3ROUTES;
DEBUGINP3 = cfg->C_DEBUGINP3;
EnableOARCAPI = cfg->C_OARCAPI;
LOCALNOTSECURE = cfg->C_LOCALNOTSECURE;
MONTOFILEFLAG = cfg->C_MONTOFILE;
if (cfg->C_RIFInterval)
RIFInterval = cfg->C_RIFInterval;
if (cfg->C_OnlyVer2point0)
SUPPORT2point2 = 0;
// Get pointers to PASSWORD and APPL1 commands
// int APPL1 = 0;
//int PASSCMD = 0;
CMD = &COMMANDS[0];
n = 0;
for (n = 0; n < NUMBEROFCOMMANDS; n++)
{
if (APPL1 == 0 && CMD->String[0] == '*') // First appl
{
APPLS = (char *)CMD;
APPL1 = n;
}
if (PASSCMD == 0 && memcmp(CMD->String, "PASSWORD", 8) == 0)
PASSCMD = n;
CMD++;
}
// SET UP APPLICATION LIST
memset(&CMDALIAS[0][0], ' ', NumberofAppls * ALIASLEN );
ptr1 = (struct APPLCONFIG *)&xxcfg.C_APPL[0];
ptr3 = &CMDALIAS[0][0];
for (i = 0; i < NumberofAppls; i++)
{
if (ptr1->Command[0] != ' ')
{
ptr2 = (char *)&COMMANDS[APPL1 + i];
memcpy(ptr2, ptr1, 12);
// See if an Alias
if (ptr1->CommandAlias[0] != ' ')
memcpy(ptr3, ptr1->CommandAlias, ALIASLEN);
// SET LENGTH FIELD
*(ptr2 + 12) = 0; // LENGTH
ptr4 = ptr2;
while (*(ptr4) > 32)
{
ptr4++;
*(ptr2 + 12) = *(ptr2 + 12) + 1;
}
}
ptr1 ++;
ptr2 += CMDXLEN;
ptr3 += ALIASLEN;
}
// Set up Exclude List
memcpy(ExcludeList, cfg->C_EXCLUDE, 71);
// SET UP PORT TABLE
PortRec = &cfg->C_PORT[0];// (struct PORTCONFIG *)ptr2;
PORTTABLE = (VOID *)NEXTFREEDATA;
FULLPORT = (struct FULLPORTDATA *)PORTTABLE;
while (PortRec->PORTNUM)
{
// SET UP NEXT PORT PTR
PORT = &FULLPORT->PORTCONTROL;
NEXTPORT = FULLPORT;
NEXTPORT++;
PORT->PORTPOINTER = (struct PORTCONTROL *)NEXTPORT;
PORT->PORTNUMBER = (UCHAR)PortRec->PORTNUM;
PORT->PortSlot = PortSlot++;
memcpy(PORT->PORTDESCRIPTION, PortRec->ID, 30);
PORT->PORTTYPE = (char)PortRec->TYPE;
PORT->PORTINITCODE = INITCODE[PORT->PORTTYPE / 2]; // ADDR OF INIT ROUTINE
PORT->PORTTXROUTINE = TXCODE[PORT->PORTTYPE / 2]; // ADDR OF INIT ROUTINE
PORT->PORTRXROUTINE = RXCODE[PORT->PORTTYPE / 2]; // ADDR OF INIT ROUTINE
PORT->PORTTIMERCODE = TIMERCODE[PORT->PORTTYPE / 2]; // ADDR OF INIT ROUTINE
PORT->PORTCLOSECODE = CLOSECODE[PORT->PORTTYPE / 2]; // ADDR OF INIT ROUTINE
PORT->PORTTXCHECKCODE = TXCHECKCODE[PORT->PORTTYPE / 2]; // ADDR OF INIT ROUTINE
PORT->PROTOCOL = (char)PortRec->PROTOCOL;
PORT->IOBASE = PortRec->IOADDR;
if (PortRec->SerialPortName && PortRec->SerialPortName[0])
PORT->SerialPortName = _strdup(PortRec->SerialPortName);
else
{
if (PORT->IOBASE > 0 && PORT->IOBASE < 256)
{
char Name[80];
#ifndef WIN32
sprintf(Name, "com%d", PORT->IOBASE);
#else
sprintf(Name, "COM%d", PORT->IOBASE);
#endif
PORT->SerialPortName = _strdup(Name);
}
else
PORT->SerialPortName = _strdup("NOPORT");
}
PORT->INTLEVEL = (char)PortRec->INTLEVEL;
PORT->BAUDRATE = PortRec->SPEED;
if (PORT->BAUDRATE == 49664)
PORT->BAUDRATE = (int)115200;
PORT->CHANNELNUM = (char)PortRec->CHANNEL;
PORT->PORTQUALITY = (UCHAR)PortRec->QUALITY;
PORT->NormalizeQuality = !PortRec->NoNormalize;
PORT->IgnoreUnlocked = PortRec->IGNOREUNLOCKED;
PORT->INP3ONLY = PortRec->INP3ONLY;
PORT->ALLOWINP3 = PortRec->AllowINP3;
PORT->ENABLEINP3 = PortRec->EnableINP3;
PORT->isRF = PortRec->isRF;
PORT->FREQ = PortRec->FREQ;
PORT->BW = PortRec->BW;
PORT->SF = PortRec->SF;
PORT->CR = PortRec->CR;
PORT->PORTWINDOW = (UCHAR)PortRec->MAXFRAME;
if (PortRec->PROTOCOL == 0 || PORT->PORTTYPE == 22) // KISS or I2C
PORT->PORTTXDELAY = PortRec->TXDELAY /10;
else
PORT->PORTTXDELAY = PortRec->TXDELAY;
if (PortRec->PROTOCOL == 0 || PORT->PORTTYPE == 22) // KISS or I2C
PORT->PORTSLOTTIME = (UCHAR)PortRec->SLOTTIME / 10;
else
PORT->PORTSLOTTIME = (UCHAR)PortRec->SLOTTIME;
PORT->PORTPERSISTANCE = (UCHAR)PortRec->PERSIST;
PORT->FULLDUPLEX = (UCHAR)PortRec->FULLDUP;
PORT->SOFTDCDFLAG = (UCHAR)PortRec->SOFTDCD;
PORT->PORTT1 = PortRec->FRACK / 100;
PORT->PORTT2 = PortRec->RESPTIME /100;
PORT->PORTN2 = (UCHAR)PortRec->RETRIES;
PORT->PORTPACLEN = (UCHAR)PortRec->PACLEN;
PORT->QUAL_ADJUST = (UCHAR)PortRec->QUALADJUST;
if (PORT->QUAL_ADJUST < 0 || PORT->QUAL_ADJUST > 100)
PORT->QUAL_ADJUST = 100;
PORT->DIGIFLAG = PortRec->DIGIFLAG;
if (PortRec->DIGIPORT && CanPortDigi(PortRec->DIGIPORT))
PORT->DIGIPORT = PortRec->DIGIPORT;
PORT->DIGIMASK = PortRec->DIGIMASK;
PORT->USERS = (UCHAR)PortRec->USERS;
// PORTTAILTIME - if KISS, set a default, and cnvert to ticks
if (PORT->PORTTYPE == 0)
{
if (PortRec->TXTAIL)
PORT->PORTTAILTIME = PortRec->TXTAIL / 10;
else
PORT->PORTTAILTIME = 3; // 10ths
}
else
//; ON HDLC, TAIL TIMER IS USED TO HOLD RTS FOR 'CONTROLLED FULL DUP' - Val in seconds
PORT->PORTTAILTIME = (UCHAR)PortRec->TXTAIL;
PORT->PORTBBSFLAG = (char)PortRec->ALIAS_IS_BBS;
PORT->PORTL3FLAG = (char)PortRec->L3ONLY;
PORT->KISSFLAGS = PortRec->KISSOPTIONS;
PORT->PORTINTERLOCK = (UCHAR)PortRec->INTERLOCK;
PORT->NODESPACLEN = (UCHAR)PortRec->NODESPACLEN;
PORT->TXPORT = (UCHAR)PortRec->TXPORT;
PORT->PORTMINQUAL = PortRec->MINQUAL;
if (PortRec->MAXDIGIS)
PORT->PORTMAXDIGIS = PortRec->MAXDIGIS;
else
PORT->PORTMAXDIGIS = 8;
PORT->PortNoKeepAlive = PortRec->DefaultNoKeepAlives;
PORT->PortUIONLY = PortRec->UIONLY;
PORT->TXPORT = (UCHAR)PortRec->TXPORT;
// SET UP CWID
if (PortRec->CWIDTYPE == 'o')
PORT->CWTYPE = 'O';
else
PORT->CWTYPE = PortRec->CWIDTYPE;
ptr2 = &PortRec->CWID[0];
CWPTR = &PORT->CWID[0];
PORT->CWIDTIMER = (29 - PORT->PORTNUMBER) * 600; // TICKSPERMINUTE
PORT->CWPOINTER = &PORT->CWID[0];
for (i = 0; i < 8; i++) // MAX ID LENGTH
{
char c = *(ptr2++);
if (c < 32)
break;
if (c > 'Z')
continue;
c -= '/'; // Table stats at /
c &= 127;
*(CWPTR) = CWTABLE[c];
CWPTR++;
}
// SEE IF LINK CALLSIGN/ALIAS SPECIFIED
if (PortRec->PORTCALL[0])
ConvToAX25(PortRec->PORTCALL, PORT->PORTCALL);
if (PortRec->PORTALIAS[0])
ConvToAX25(PortRec->PORTALIAS, PORT->PORTALIAS);
if (PortRec->PORTALIAS2[0])
ConvToAX25(PortRec->PORTALIAS2, PORT->PORTALIAS2);
if (PortRec->DLLNAME[0])
{
EXTPORT = (struct _EXTPORTDATA *)PORT;
memcpy(EXTPORT->PORT_DLL_NAME, PortRec->DLLNAME, 16);
}
if (PortRec->BCALL[0])
ConvToAX25(PortRec->BCALL, PORT->PORTBCALL);
PORT->XDIGIS = PortRec->XDIGIS; // Crossband digi aliases
memcpy(&PORT->PORTIPADDR, &PortRec->IPADDR, 4);
PORT->ListenPort = PortRec->ListenPort;
if (PortRec->TCPPORT)
{
PORT->KISSTCP = TRUE;
PORT->IOBASE = PortRec->TCPPORT;
if (PortRec->IPADDR == 0)
PORT->KISSSLAVE = TRUE;
}
if (PortRec->WL2K)
memcpy(&PORT->WL2KInfo, PortRec->WL2K, sizeof(struct WL2KInfo));
PORT->RIGPort = PortRec->RIGPORT;
if (PortRec->HavePermittedAppls)
PORT->PERMITTEDAPPLS = PortRec->PERMITTEDAPPLS;
else
PORT->PERMITTEDAPPLS = 0xffffffff; // Default to all
PORT->Hide = PortRec->Hide;
PORT->SmartIDInterval = PortRec->SmartID;
if (PortRec->KissParams && (PORT->PORTTYPE == 0 || PORT->PORTTYPE == 22))
{
struct KISSINFO * KISS = (struct KISSINFO *)PORT;
UCHAR KissString[128];
int KissLen = 0;
unsigned char * Kissptr = KissString;
char * ptr;
char * Context;
ptr = strtok_s(PortRec->KissParams, " ", &Context);
while (ptr && ptr[0] && KissLen < 120)
{
*(Kissptr++) = atoi (ptr);
KissLen++;
ptr = strtok_s(NULL, " ", &Context);
}
KISS->KISSCMD = malloc(256);
KISS->KISSCMDLEN = KissEncode(KissString, KISS->KISSCMD, KissLen);
KISS->KISSCMD = realloc(KISS->KISSCMD, KISS->KISSCMDLEN);
}
PORT->SendtoM0LTEMap = PortRec->SendtoM0LTEMap;
PORT->PortFreq = PortRec->PortFreq;
PORT->M0LTEMapInfo = PortRec->M0LTEMapInfo;
PORT->QtSMPort = PortRec->QtSMPort;
if (PortRec->BBSFLAG) // Appl 1 not permitted - BBSFLAG=NOBBS
PORT->PERMITTEDAPPLS &= 0xfffffffe; // Clear bottom bit
// SEE IF PERMITTED LINK CALLSIGNS SPECIFIED
ptr2 = &PortRec->VALIDCALLS[0];
if (*(ptr2))
{
ptr3 = (char *)PORT->PORTPOINTER; // Permitted Calls follows Port Info
PORT->PERMITTEDCALLS = ptr3;
while (*(ptr2) > 32)
{
ConvToAX25(ptr2, ptr3);
ptr3 += 7;
PORT->PORTPOINTER = (struct PORTCONTROL *)ptr3;
if (strchr(ptr2, ','))
{
ptr2 = strchr(ptr2, ',');
ptr2++;
}
else
break;
}
ptr3 ++; // Terminating NULL
// Round to word boundary (for ARM5 etc)
int3 = (uintptr_t)ptr3;
int3 += 7;
int3 &= 0xfffffffffffffff8;
ptr3 = (UCHAR *)int3;
PORT->PORTPOINTER = (struct PORTCONTROL *)ptr3;
}
// SEE IF PORT UNPROTO ADDR SPECIFIED
ptr2 = &PortRec->UNPROTO[0];
if (*(ptr2))
{
ptr3 = (char *)PORT->PORTPOINTER; // Unproto follows port info
PORT->PORTUNPROTO = ptr3;
while (*(ptr2) > 32)
{
ConvToAX25(ptr2, ptr3);
ptr3 += 7;
PORT->PORTPOINTER = (struct PORTCONTROL *)ptr3;
if (strchr(ptr2, ','))
{
ptr2 = strchr(ptr2, ',');
ptr2++;
}
else
break;
}
ptr3 ++; // Terminating NULL
// Round to word boundsaty (for ARM5 etc)
int3 = (uintptr_t)ptr3;
int3 += 7;
int3 &= 0xfffffffffffffff8;
ptr3 = (UCHAR *)int3;
PORT->PORTPOINTER = (struct PORTCONTROL *)ptr3;
}
// ADD MH AREA IF NEEDED
if (PortRec->MHEARD != 'N')
{
NEEDMH = 1; // Include MH in Command List
ptr3 = (char *)PORT->PORTPOINTER; // Permitted Calls follows Port Info
PORT->PORTMHEARD = (PMHSTRUC)ptr3;
ptr3 += (MHENTRIES + 1)* sizeof(MHSTRUC);
// Round to word boundsaty (for ARM5 etc)
int3 = (uintptr_t)ptr3;
int3 += 7;
int3 &= 0xfffffffffffffff8;
ptr3 = (UCHAR *)int3;
PORT->PORTPOINTER = (struct PORTCONTROL *)ptr3;
}
PortRec++;
NUMBEROFPORTS ++;
FULLPORT = (struct FULLPORTDATA *)PORT->PORTPOINTER;
}
PORT->PORTPOINTER = NULL; // End of list
NEXTFREEDATA = (UCHAR *)FULLPORT;
// SET UP APPLICATION CALLS AND ALIASES
APPL = &APPLCALLTABLE[0];
ptr1 = (struct APPLCONFIG *)&xxcfg.C_APPL[0];
i = NumberofAppls;
if (ptr1->ApplCall[0] == ' ')
{
// APPL1CALL IS NOT SPECIFED - LEAVE VALUES SET FROM BBSCALL
APPL++;
ptr1++;
i--;
}
while (i)
{
memcpy(APPL->APPLCALL_TEXT, ptr1->ApplCall, 10);
ConvToAX25(APPL->APPLCALL_TEXT, APPL->APPLCALL);
memcpy(APPL->APPLALIAS_TEXT, ptr1->ApplAlias, 10);
ConvToAX25(APPL->APPLALIAS_TEXT, APPL->APPLALIAS);
ConvToAX25(ptr1->L2Alias, APPL->L2ALIAS);
memcpy(APPL->APPLCMD, ptr1->Command, 12);
APPL->APPLQUAL = ptr1->ApplQual;
if (ptr1->CommandAlias[0] != ' ')
{
APPL->APPLHASALIAS = 1;
memcpy(APPL->APPLALIASVAL, &ptr1->CommandAlias[0], 48);
}
APPL++;
ptr1++;
i--;
}
// SET UP VARIOUS CONTROL TABLES
LINKS = (VOID *)NEXTFREEDATA;
NEXTFREEDATA += MAXLINKS * sizeof(struct _LINKTABLE);
DESTS = (VOID *)NEXTFREEDATA;
NEXTFREEDATA += MAXDESTS * sizeof(struct DEST_LIST);
ENDDESTLIST = (VOID *)NEXTFREEDATA;
NEIGHBOURS = (VOID *)NEXTFREEDATA;
NEXTFREEDATA += MAXNEIGHBOURS * sizeof(struct ROUTE);
L4TABLE = (VOID *)NEXTFREEDATA;
NEXTFREEDATA += MAXCIRCUITS * sizeof(TRANSPORTENTRY);
// SET UP DEFAULT ROUTES LIST
Rcfg = &cfg->C_ROUTE[0];
ROUTE = NEIGHBOURS;
while (Rcfg->call[0])
{
int FRACK;
char * VIA;
char axcall[8];
ConvToAX25(Rcfg->call, ROUTE->NEIGHBOUR_CALL);
// if VIA convert digis
VIA = strstr(Rcfg->call, "VIA");
if (VIA)
{
VIA += 4;
if (ConvToAX25(VIA, axcall))
{
memcpy(ROUTE->NEIGHBOUR_DIGI1, axcall, 7);
VIA = strchr(VIA, ' ');
if (VIA)
{
VIA++;
if (ConvToAX25(VIA, axcall))
memcpy(ROUTE->NEIGHBOUR_DIGI2, axcall, 7);
}
}
}
ROUTE->NEIGHBOUR_QUAL = Rcfg->quality;
ROUTE->NEIGHBOUR_PORT = Rcfg->port;
PORT = GetPortTableEntryFromPortNum(ROUTE->NEIGHBOUR_PORT);
if (Rcfg->nokeepalives)
ROUTE->NoKeepAlive = 1;
else
if (PORT != NULL)
ROUTE->NoKeepAlive = PORT->PortNoKeepAlive;
if (Rcfg->inp3 || (PORT && PORT->INP3ONLY))
{
ROUTE->INP3Node = 1;
ROUTE->NoKeepAlive = 0; // Cant have INP3 and NOKEEPALIVES
}
if (Rcfg->noV2point2)
ROUTE->noV2point2 = 1;
ROUTE->NBOUR_MAXFRAME = Rcfg->pwind & 0x3f;
FRACK = Rcfg->pfrack;
ROUTE->NBOUR_FRACK = FRACK / 100;
ROUTE->NBOUR_PACLEN = Rcfg->ppacl;
ROUTE->OtherendsRouteQual = ROUTE->OtherendLocked = Rcfg->farQual;
ROUTE->NEIGHBOUR_FLAG = LOCKEDBYCONFIG; // Locked
if (Rcfg->tcphost)
{
ROUTE->TCPHost = Rcfg->tcphost;
ROUTE->TCPPort = Rcfg->tcpport;
ROUTE->TCPAddress = (struct addrinfo *)zalloc(sizeof(struct addrinfo));
ROUTE->TCPAddress->ai_addr = (struct sockaddr *) zalloc(sizeof(struct sockaddr));
}
ROUTE->NPR = Rcfg->NPR;
ROUTE->recNum = index++;
Rcfg++;
ROUTE++;
}
// SET UP INFO MESSAGE
ptr2 = &cfg->C_INFOMSG[0];
ptr3 = NEXTFREEDATA;
INFOMSG = ptr3;
while ((*ptr2))
{
*(ptr3++) = *(ptr2++);
}
*ptr3++ = 0; // Null Terminate
NEXTFREEDATA = ptr3;
// SET UP CTEXT MESSAGE
ptr2 = &cfg->C_CTEXT[0];
ptr3 = NEXTFREEDATA;
CTEXTMSG = ptr3;
while ((*ptr2))
{
*(ptr3++) = *(ptr2++);
}
CTEXTLEN = (int)(ptr3 - (unsigned char *)CTEXTMSG);
NEXTFREEDATA = ptr3;
// SET UP ID MESSAGE
IDHDDR.DEST[0] = 'I'+'I';
IDHDDR.DEST[1] = 'D'+'D';
IDHDDR.DEST[2] = 0x40;
IDHDDR.DEST[3] = 0x40;
IDHDDR.DEST[4] = 0x40;
IDHDDR.DEST[5] = 0x40;
IDHDDR.DEST[6] = 0xe0; // ; ID IN AX25 FORM
IDHDDR.CTL = 3;
IDHDDR.PID = 0xf0;
ptr2 = &cfg->C_IDMSG[0];
ptr3 = &IDHDDR.L2DATA[0];
while ((*ptr2))
{
*(ptr3++) = *(ptr2++);
}
IDHDDR.LENGTH = (int)(ptr3 - (unsigned char *)&IDHDDR);
int3 = (uintptr_t)NEXTFREEDATA;
int3 += 7;
int3 &= 0xfffffffffffffff8;
NEXTFREEDATA = (UCHAR *)int3;
ENDBUFFERPOOL = NEXTFREEDATA + DATABYTES; // So init will work, set to actual end later
BUFFERPOOL = NEXTFREEDATA;
Consoleprintf("PORTS %p LINKS %p DESTS %p ROUTES %p L4 %p BUFFERS %p\n",
PORTTABLE, LINKS, DESTS, NEIGHBOURS, L4TABLE, BUFFERPOOL);
Debugprintf("PORTS %p LINKS %p DESTS %p ROUTES %p L4 %p BUFFERS %p END POOL %p",
PORTTABLE, LINKS, DESTS, NEIGHBOURS, L4TABLE, BUFFERPOOL, DATAAREA + DATABYTES);
i = NUMBEROFBUFFERS;
NUMBEROFBUFFERS = 0;
while (i-- && NEXTFREEDATA < (DATAAREA + DATABYTES - (512 + 8192))) // Keep 8K free for anything that needs shared memory
{
Bufferlist[NUMBEROFBUFFERS] = (void **)NEXTFREEDATA;
ReleaseBuffer((UINT *)NEXTFREEDATA);
NEXTFREEDATA += BUFFALLOC; // was BUFFLEN
NUMBEROFBUFFERS++;
MAXBUFFS++;
}
ENDBUFFERPOOL = NEXTFREEDATA;
PoolBuilt = 1;
// Copy Bridge Map
memcpy(BridgeMap, &cfg->CfgBridgeMap, sizeof(BridgeMap));
// MOV EAX,_NEXTFREEDATA
// CALL HEXOUT
// SET UP OUR CALLIGN(S)
ConvToAX25(MYNETROMCALL, NETROMCALL);
ConvToAX25(MYNODECALL, MYCALL);
memcpy(&IDHDDR.ORIGIN[0], MYCALL, 7);
IDHDDR.ORIGIN[6] |= 0x61; // SET CMD END AND RESERVED BITS
ConvToAX25(MYALIASTEXT, MYALIAS);
// SET UP INITIAL DEST ENTRY FOR APPLICATIONS (IF BOTH NODE AND BBS NEEDED)
// Actually wrong - we need to set up application node entries even if node = 0
DEST = DESTS;
// If NODECALL isn't same as NETROMCALL, Add Dest Entry for NODECALL
if (memcmp(NETROMCALL, MYCALL, 7) != 0)
{
memcpy(DEST->DEST_CALL, MYCALL, 7);
memcpy(DEST->DEST_ALIAS, MYALIASTEXT, 6);
DEST->DEST_STATE = 0x80; // SPECIAL ENTRY
DEST->NRROUTE[0].ROUT_QUALITY = 255;
DEST->NRROUTE[0].ROUT_OBSCOUNT = 255;
DEST++;
NUMBEROFNODES++;
}
if (BBS)
{
// Add Application Entries
APPL = &APPLCALLTABLE[0];
i = NumberofAppls;
while (i--)
{
if (APPL->APPLQUAL)
{
memcpy(DEST->DEST_CALL, APPL->APPLCALL, 13);
DEST->DEST_STATE = 0x80; // SPECIAL ENTRY
DEST->NRROUTE[0].ROUT_QUALITY = (UCHAR)APPL->APPLQUAL;
DEST->NRROUTE[0].ROUT_OBSCOUNT = 255;
APPL->NODEPOINTER = DEST;
DEST++;
NUMBEROFNODES++;
}
APPL++;
}
}
// Read Node and MH Recovery Files
ReadNodes();
if (AUTOSAVEMH)
ReadMH(); // Only if AutoSave configured
// Tidy Log Files
DeleteLogFiles(LogAge);
// set up stream number in BPQHOSTVECTOR
for (i = 0; i < 64; i++)
{
BPQHOSTVECTOR[i].HOSTSTREAM = i + 1;
}
memcpy(MYCALLWITHALIAS, MYCALL, 7);
memcpy(&MYCALLWITHALIAS[7], MYALIASTEXT, 6);
// Set random start value for NETROM Session ID
NEXTID = (rand() % 254) + 1;
GetPortCTEXT(0, 0, 0, 0);
upnpInit();
// Start Monitor to file thread
_beginthread(WritePacketLogThread, 0, NULL);
// Initialise interval timers
lastMinuteSecs = lastHourSecs = lastTenSecSecs = NOW = time(NULL);
last100mSTickCount = lastSecTickCount = GetTickCount();
// if EnableOARCAPI set try to resolve host here so we can send Node up event before anything else
if (EnableOARCAPI)
{
struct hostent * HostEnt3;
HostEnt3 = gethostbyname(NodeAPIServer);
NodeAPISocket = socket(AF_INET, SOCK_DGRAM, 0);
UDPreportdest.sin_family = AF_INET;
UDPreportdest.sin_port = htons(NodeAPIPort);
if (HostEnt3)
{
memcpy(&UDPreportdest.sin_addr.s_addr,HostEnt3->h_addr,4);
hookNodeStarted();
nodeStartedSent = 1;
LastNodeStatus = NOW;
}
}
return 0;
}
BOOL CompareCalls(UCHAR * c1, UCHAR * c2)
{
// COMPARE AX25 CALLSIGNS IGNORING EXTRA BITS IN SSID
if (memcmp(c1, c2, 6))
return FALSE; // No Match
if ((c1[6] & 0x1e) == (c2[6] & 0x1e))
return TRUE;
return FALSE;
}
BOOL CompareAliases(UCHAR * c1, UCHAR * c2)
{
// COMPARE first 6 chars of AX25 CALLSIGNS
if (memcmp(c1, c2, 6))
return FALSE; // No Match
return TRUE;
}
BOOL FindNeighbour(UCHAR * Call, int Port, struct ROUTE ** REQROUTE)
{
struct ROUTE * ROUTE = NEIGHBOURS;
struct ROUTE * FIRSTSPARE = NULL;
char Normcall[10];
int n;
for (n = 0; n < MAXNEIGHBOURS; n++)
{
if (ROUTE->NEIGHBOUR_CALL[0] == 0) // Spare
{
if (FIRSTSPARE == NULL)
{
FIRSTSPARE = ROUTE;
ROUTE->recNum = n;
}
}
if (ROUTE->NEIGHBOUR_PORT != Port)
{
ROUTE++;
continue;
}
Normcall[ConvFromAX25(ROUTE->NEIGHBOUR_CALL, Normcall)] = 0;
if (CompareCalls(ROUTE->NEIGHBOUR_CALL, Call))
{
*REQROUTE = ROUTE;
return TRUE;
}
ROUTE++;
}
// ENTRY NOT FOUND - FIRSTSPARE HAS FIRST FREE ENTRY, OR ZERO IF TABLE FULL
*REQROUTE = FIRSTSPARE;
return FALSE;
}
BOOL FindDestination(UCHAR * Call, struct DEST_LIST ** REQDEST)
{
struct DEST_LIST * DEST = DESTS;
struct DEST_LIST * FIRSTSPARE = NULL;
int n = MAXDESTS;
while (n--)
{
if (DEST->DEST_CALL[0] == 0) // Spare
{
if (FIRSTSPARE == NULL)
FIRSTSPARE = DEST;
DEST++;
continue;
}
if (CompareCalls(DEST->DEST_CALL, Call))
{
*REQDEST = DEST;
return TRUE;
}
DEST++;
}
// ENTRY NOT FOUND - FIRSTSPARE HAS FIRST FREE ENTRY, OR ZERO IF TABLE FULL
*REQDEST = FIRSTSPARE;
return FALSE;
}
extern UCHAR BPQDirectory[];
#define LINE_MAX 256
// Reload saved MH file
VOID ReadMH()
{
char FN[260];
FILE *fp;
char line[LINE_MAX];
UCHAR axcall[7];
char * ptr, *digi, *locptr, *locend;
char * Context, * Context2;
char seps[] = " \n";
int Port;
struct PORTCONTROL * PORT = NULL;
MHSTRUC * MH;
int count = MHENTRIES;
char * Digiptr;
BOOL Digiused;
char * HasStar;
// Set up pointer to BPQNODES file
if (BPQDirectory[0] == 0)
{
strcpy(FN,"MHSave.txt");
}
else
{
strcpy(FN,BPQDirectory);
strcat(FN,"/");
strcat(FN,"MHSave.txt");
}
if ((fp = fopen(FN, "r")) == NULL)
{
return;
}
while (fgets(line, LINE_MAX, fp) != NULL)
{
if (memcmp(line, "Port:", 5) == 0)
{
Port = atoi(&line[5]);
PORT = GetPortTableEntryFromPortNum(Port);
if (PORT)
MH = PORT->PORTMHEARD;
else
MH = NULL;
continue;
}
// 1548777630 N9LYA-8 Jan 29 16:00:30
if (MH)
{
ptr = strtok_s(line, seps, &Context);
if (ptr == NULL)
continue;
MH->MHTIME = atoi(ptr);
ptr = strtok_s(NULL, seps, &Context);
if (ptr == NULL)
continue;
MH->MHCOUNT = atoi(ptr);
// Get LOC and Freq First before strtok messes with line
locptr = strchr(Context, '|');
if (locptr == NULL)
continue;
locend = strchr(++locptr, '|');
if (locend == NULL)
continue;
if ((locend - locptr) == 6)
memcpy(MH->MHLocator, locptr, 6);
locend++;
strlop(locend, '\n');
if (strlen(locend) < 12)
strcpy(MH->MHFreq, locend);
ptr = strtok_s(NULL, "|\n", &Context);
if (ptr == NULL)
continue;
if (ConvToAX25(ptr, axcall) == FALSE)
continue; // Duff
memcpy(MH->MHCALL, axcall, 7);
if (ptr[10] != ' ')
MH->MHDIGI = ptr[10];
// SEE IF ANY DIGIS
digi = strstr(ptr, " via ");
if (digi)
{
digi = digi + 5;
Digiptr = &MH->MHDIGIS[0][0];
if (strchr(ptr, '*'))
Digiused = 1; // At least one digi used
else
Digiused = 0;
digi = strtok_s(digi, ",\n", &Context2);
while(digi)
{
HasStar = strlop(digi, '*');
if (ConvToAX25(digi, axcall) == FALSE)
break;
memcpy(Digiptr, axcall, 7);
if (Digiused)
Digiptr[6] |= 0x80; // Set used
if (HasStar)
Digiused = 0; // Only last used has *
Digiptr += 7;
digi = strtok_s(NULL, ",/n", &Context2);
}
*(--Digiptr) |= 1; // Set end of address on last
}
else
{
// No Digis
MH->MHCALL[6] |= 1; // Set end of address
}
MH++;
}
}
fclose(fp);
return;
}
VOID ReadNodes()
{
char FN[260];
FILE *fp;
char line[LINE_MAX];
UCHAR axcall[7];
char * ptr;
char * Context;
char seps[] = " \r";
int Port, Qual;
struct PORTCONTROL * PORT;
// Set up pointer to BPQNODES file
if (BPQDirectory[0] == 0)
{
strcpy(FN,"BPQNODES.dat");
}
else
{
strcpy(FN,BPQDirectory);
strcat(FN,"/");
strcat(FN,"BPQNODES.dat");
}
if ((fp = fopen(FN, "r")) == NULL)
{
WritetoConsoleLocal(
"Route/Node recovery file BPQNODES.dat not found - Continuing without it\n");
return;
}
// Read the saved ROUTES/NODES file
while (fgets(line, LINE_MAX, fp) != NULL)
{
if (memcmp(line, "ROUTE ADD", 9) == 0)
{
struct ROUTE * ROUTE = NULL;
// FORMAT IS ROUTE ADD CALLSIGN PORT QUAL (VIA ....
ptr = strtok_s(&line[10], seps, &Context);
if (ConvToAX25(ptr, axcall) == FALSE)
continue; // DUff
ptr = strtok_s(NULL, seps, &Context);
if (ptr == NULL) continue;
Port = atoi(ptr);
PORT = GetPortTableEntryFromPortNum(Port);
if (PORT == NULL)
continue; // Port has gone
if (FindNeighbour(axcall, Port, &ROUTE))
continue; // Already added from ROUTES:
if (ROUTE == NULL)
continue; // Tsble Full
memcpy(ROUTE->NEIGHBOUR_CALL, axcall, 7);
ROUTE->NEIGHBOUR_PORT = Port;
ptr = strtok_s(NULL, seps, &Context);
if (ptr == NULL) continue;
Qual = atoi(ptr);
ROUTE->NEIGHBOUR_QUAL = Qual;
ptr = strtok_s(NULL, seps, &Context); // MAXFRAME
if (ptr == NULL) continue;
// I don't thinlk we should load locked flag from save file - only from config
// Now (2025) have two locked flags, from config or by sysop. Latter is saved and restored
if (ptr[0] == '!')
{
ROUTE->NEIGHBOUR_FLAG = LOCKEDBYSYSOP; // LOCKED ROUTE
ptr = strtok_s(NULL, seps, &Context);
if (ptr == NULL) continue;
}
// SEE IF ANY DIGIS
if (ptr[0] == 'V')
{
ptr = strtok_s(NULL, seps, &Context);
if (ptr == NULL) continue;
if (ConvToAX25(ptr, axcall) == FALSE)
continue; // DUff
memcpy(ROUTE->NEIGHBOUR_DIGI1, axcall, 7);
ROUTE->NEIGHBOUR_FLAG = LOCKEDBYSYSOP; // LOCKED ROUTE - Digi'ed routes must be locked
ptr = strtok_s(NULL, seps, &Context);
if (ptr == NULL) continue;
// See if another digi or MAXFRAME
if (strlen(ptr) > 2)
{
if (ConvToAX25(ptr, axcall) == FALSE)
continue; // DUff
memcpy(ROUTE->NEIGHBOUR_DIGI2, axcall, 7);
ptr = strtok_s(NULL, seps, &Context);
if (ptr == NULL) continue;
}
}
Qual = atoi(ptr);
ROUTE->NBOUR_MAXFRAME = Qual;
ptr = strtok_s(NULL, seps, &Context); // FRACK
if (ptr == NULL) continue;
Qual = atoi(ptr);
ROUTE->NBOUR_FRACK = Qual;
ptr = strtok_s(NULL, seps, &Context); // PACLEN
if (ptr == NULL) continue;
Qual = atoi(ptr);
ROUTE->NBOUR_PACLEN = Qual;
ptr = strtok_s(NULL, seps, &Context); // INP3
if (ptr == NULL) continue;
Qual = atoi(ptr);
// We now take Nokeepalives from the PORT, unless specifically
// Requested
ROUTE->NoKeepAlive = PORT->PortNoKeepAlive;
if (Qual & 4)
ROUTE->NoKeepAlive = TRUE;
if ((Qual & 1) || PORT->INP3ONLY)
{
ROUTE->NoKeepAlive = FALSE;
ROUTE->INP3Node = TRUE;
}
ptr = strtok_s(NULL, seps, &Context); // INP3
if (ptr == NULL) continue;
if (ROUTE->NEIGHBOUR_FLAG == 0 || ROUTE->OtherendLocked == 0) // Not LOCKED ROUTE
ROUTE->OtherendsRouteQual = atoi(ptr);
ptr = strtok_s(NULL, seps, &Context); // INP3
if (ptr == NULL) continue;
if (ptr[0] == '!')
{
ROUTE->NEIGHBOUR_FLAG = LOCKEDBYSYSOP; // LOCKED ROUTE
ptr = strtok_s(NULL, seps, &Context);
}
continue;
}
if (memcmp(line, "NODE ADD", 8) == 0)
{
// FORMAT IS NODE ADD ALIAS:CALL ROUTE QUAL
dest_list * DEST = NULL;
struct ROUTE * ROUTE = NULL;
char * ALIAS;
char FULLALIAS[6] = " ";
int SavedOBSINIT = OBSINIT;
if (line[9] == ':')
{
// No alias
Context = &line[10];
}
else
{
ALIAS = strtok_s(&line[9], ":", &Context);
if (ALIAS == NULL)
continue;
memcpy(FULLALIAS, ALIAS, (int)strlen(ALIAS));
}
ptr = strtok_s(NULL, seps, &Context);
if (ptr == NULL)
continue;
if (ConvToAX25(ptr, axcall) == FALSE)
continue; // Duff
if (CompareCalls(axcall, MYCALL))
continue; // Shoiuldn't happen, but to be safe!
if (FindDestination(axcall, &DEST))
continue;
if (DEST == NULL)
continue; // Tsble Full
memcpy(DEST->DEST_CALL, axcall, 7);
memcpy(DEST->DEST_ALIAS, FULLALIAS, 6);
NUMBEROFNODES++;
RouteLoop:
// GET NEIGHBOURS FOR THIS DESTINATION - CALL PORT QUAL
ptr = strtok_s(NULL, seps, &Context);
if (ptr == NULL) continue;
if (ConvToAX25(ptr, axcall) == FALSE)
continue; // DUff
ptr = strtok_s(NULL, seps, &Context);
if (ptr == NULL) continue;
Port = atoi(ptr);
ptr = strtok_s(NULL, seps, &Context);
if (ptr == NULL) continue;
Qual = atoi(ptr);
if (Context[0] == '!')
{
OBSINIT = 255; //; SPECIAL FOR LOCKED
}
if (FindNeighbour(axcall, Port, &ROUTE))
{
PROCROUTES(DEST, ROUTE, Qual);
}
OBSINIT = SavedOBSINIT;
goto RouteLoop;
}
}
fclose(fp);
// loadedmsg DB cr,lf,lf,'Switch loaded and initialised OK',lf,0
return;
}
int DelayBuffers = 0;
void sendModeReport();
void sendFreqReport();
int TIMERINTERRUPT()
{
// Main Processing - Called rapidly (maybe 1 mS)
// Returns 1 if 100mS has passed since last call
int retval = 0;
int i;
struct PORTCONTROL * PORT = PORTTABLE;
PMESSAGE Buffer;
struct _LINKTABLE * LINK;
struct _MESSAGE * Message;
int toPort;
if (GetTickCount() - last100mSTickCount >= 100)
{
// 100mS has elaped
retval = 1;
last100mSTickCount = GetTickCount();
REALTIMETICKS++;
// CALL PORT TIMER 100 mS ROUTINES
for (i = 0; i < NUMBEROFPORTS; i++)
{
PORT->PORTTIMERCODE(PORT);
// Check Smart ID timer
if (PORT->SmartIDNeeded && PORT->SmartIDNeeded < NOW)
SendSmartID(PORT);
PORT = PORT->PORTPOINTER;
}
if (last100mSTickCount - lastSecTickCount >= 1000)
{
lastSecTickCount = last100mSTickCount;
L3SecTimer();
L4SecTimer();
}
L2TimerProc(); // Now 100 mS
}
if (NOW - lastMinuteSecs >= 60) // 1 PER MIN
{
lastMinuteSecs = NOW;
CloseDebugLog();
L3MinuteTimerProc();
if (needAIS)
AISTimer();
if (needADSB)
ADSBTimer();
if (APRSActive)
Debugprintf("BPQ32 Heartbeat Buffers %d APRS Queues %d %d", QCOUNT, C_Q_COUNT(&APRSMONVECPTR->HOSTTRACEQ), C_Q_COUNT(&APPL_Q));
else
Debugprintf("BPQ32 Heartbeat Buffers %d", QCOUNT);
StatsTimer();
// Call EXT Port Slow Timer
PORT = PORTTABLE;
for (i = 0; i < NUMBEROFPORTS; i++)
{
if (PORT->PROTOCOL == 10)
{
PEXTPORTDATA PORTVEC = (PEXTPORTDATA)PORT;
EXTSLOWTIMER(PORTVEC);
}
PORT = PORT->PORTPOINTER;
}
// Call Mode Map support routine
sendFreqReport();
sendModeReport();
if (MQTT)
MQTTTimer();
if (LastNodeStatus && (NOW - LastNodeStatus) > nodeStatusTimer)
{
LastNodeStatus = NOW;
hookNodeRunning();
}
/*
if (QCOUNT < 200)
{
if (DelayBuffers == 0)
{
FindLostBuffers();
DelayBuffers = 10;
}
else
{
DelayBuffers--;
}
}
*/
}
// Check Autosave Nodes and MH timer
if (NOW - lastHourSecs >= 3600) // 1 per hour
{
lastHourSecs = NOW;
if (AUTOSAVE == 1)
SaveNodes();
if (AUTOSAVEMH == 1)
SaveMH();
}
// SEE IF ANY FRAMES TO TRACE
// The rest runs on every call
Buffer = Q_REM(&TRACE_Q);
while (Buffer)
{
// IF BUFFER HAS A LINK TABLE ENTRY ON END, RESET TIMEOUT
LINK = Buffer->Linkptr;
if (LINK)
{
if (LINK->L2TIMER)
LINK->L2TIMER = LINK->L2TIME;
Buffer->Linkptr = 0; // CLEAR FLAG FROM BUFFER
}
Message = (struct _MESSAGE *)Buffer;
if(NodeAPISocket)
APIL2Trace(Message, "sent");
Message->PORT |= 0x80; // Set TX Bit
BPQTRACE(Message, FALSE); // Dont send TX'ed frames to APRS
ReleaseBuffer(Buffer);
Buffer = Q_REM(&TRACE_Q);
}
// CHECK FOR MESSAGES RECEIVED FROM COMMS LINKS
PORT = PORTTABLE;
for (i = 0; i < NUMBEROFPORTS; i++)
{
int Sent = 0;
CURRENTPORT = PORT->PORTNUMBER; // PORT NUMBER
CURRENTPORTPTR = PORT;
Buffer = (PMESSAGE)Q_REM((void *)&PORT->PORTRX_Q);
while (Buffer)
{
Message = (struct _MESSAGE *) Buffer;
if (PORT->PROTOCOL == 10)
{
int Sessno = Message->PORT;
PEXTPORTDATA PORTVEC = (PEXTPORTDATA)PORT;
TRANSPORTENTRY * Session;
TRANSPORTENTRY * Partner;
if (PORT->TNC && PORT->TNC->Hardware == H_KISSHF)
{
// KISSHF - May be L2 packet or Test Response
if (Message->DEST[0] != 240) // Should only be ax.25 address field
goto L2Packet;
}
// PACTOR Style Message
InOctets[PORT->PORTNUMBER] += Message->LENGTH - (MSGHDDRLEN + 1);
PORT->L2FRAMESFORUS++;
Session = PORTVEC->ATTACHEDSESSIONS[Sessno];
if (Session == NULL)
{
// TNC not attached - discard
ReleaseBuffer(Buffer);
Buffer = (PMESSAGE)Q_REM((void *)&PORT->PORTRX_Q);
continue;
}
Session->L4KILLTIMER = 0; // Reset Idle Timeout
Partner = Session->L4CROSSLINK;
if (Partner == NULL)
{
// No Crosslink - pass to command handler
CommandHandler(Session, (PDATAMESSAGE)Buffer);
break;
}
if (Partner->L4STATE < 5)
{
// MESSAGE RECEIVED BEFORE SESSION IS UP - CANCEL SESSION
// AND PASS MESSAGE TO COMMAND HANDLER
if (Partner->L4CIRCUITTYPE & L2LINK) // L2 SESSION?
{
// MUST CANCEL L2 SESSION
LINK = Partner->L4TARGET.LINK;
LINK->CIRCUITPOINTER = NULL; // CLEAR REVERSE LINK
LINK->L2STATE = 4; // DISCONNECTING
LINK->L2TIMER = 1; // USE TIMER TO KICK OFF DISC
LINK->L2RETRIES = LINK->LINKPORT->PORTN2 - 2; //ONLY SEND DISC ONCE
}
CLEARSESSIONENTRY(Partner);
Session->L4CROSSLINK = 0; // CLEAR CROSS LINK
CommandHandler(Session, (struct DATAMESSAGE *)Buffer);
break;
}
C_Q_ADD(&Partner->L4TX_Q, Buffer);
PostDataAvailable(Partner);
Buffer = (PMESSAGE)Q_REM((void *)&PORT->PORTRX_Q);
continue;
}
L2Packet:
// TIME STAMP IT
Message->Timestamp = NOW;
Message->PORT = CURRENTPORT;
if (MQTT && PORT->PROTOCOL == 0)
MQTTKISSRX(Buffer);
if(NodeAPISocket && PORT->PROTOCOL == 0)
APIL2Trace(Message, "rcvd");
// Bridge if requested
for (toPort = 1; toPort <= MaxBPQPortNo; toPort++)
{
if (BridgeMap[CURRENTPORT][toPort])
{
MESSAGE * BBuffer = GetBuff();
struct PORTCONTROL * BPORT;
if (BBuffer)
{
memcpy(BBuffer, Message, Message->LENGTH);
BBuffer->PORT = toPort;
BPORT = GetPortTableEntryFromPortNum(toPort);
if (BPORT)
{
if (BPORT->SmartIDInterval && BPORT->SmartIDNeeded == 0)
{
// Using Smart ID, but none scheduled
BPORT->SmartIDNeeded = NOW + BPORT->SmartIDInterval;
}
PUT_ON_PORT_Q(BPORT, BBuffer);
}
else
ReleaseBuffer(BBuffer);
}
}
}
L2Routine(PORT, Buffer);
Buffer = (PMESSAGE)Q_REM((void *)&PORT->PORTRX_Q);
continue;
}
// End of RX_Q
Sent = 0;
while (PORT->PORTTX_Q && Sent < 5)
{
int ret;
void * PACTORSAVEQ;
Buffer = PORT->PORTTX_Q;
Message = (struct _MESSAGE *) Buffer;
ret = PORT->PORTTXCHECKCODE(PORT, Message->PORT);
// Busy but not connected means TNC has gone - clear queue
if (ret == 1)
{
MESSAGE * Buffer = (PMESSAGE)Q_REM((void *)&PORT->PORTTX_Q);
if (Buffer == 0)
break; // WOT!!
// Debugprintf("Busy but not connected - discard message %s", Buffer->L2DATA);
ReleaseBuffer(Buffer);
break;
}
ret = ret & 0xff; // Only check bottom byte
if (ret == 0) // Not busy
{
MESSAGE * Buffer = (PMESSAGE)Q_REM((void *)&PORT->PORTTX_Q);
if (Buffer == 0)
break; // WOT!!
if (PORT->PORTDISABLED)
{
ReleaseBuffer(Buffer);
break;
}
PORT->L2FRAMESSENT++;
OutOctets[PORT->PORTNUMBER] += Buffer->LENGTH - MSGHDDRLEN;
PORT->PORTTXROUTINE((struct _EXTPORTDATA *)PORT, Buffer);
Sent++;
continue;
}
// If a Pactor Port, some channels could be busy whilst others are not.
if (PORT->PROTOCOL != 10)
break; // BUSY
// Try passing any other messages on the queue to the node.
PACTORSAVEQ = 0;
PACTORLOOP:
Buffer = PORT->PORTTX_Q;
if (Buffer == NULL)
goto ENDOFLIST;
Message = (struct _MESSAGE *) Buffer;
ret = PORT->PORTTXCHECKCODE(PORT, Message->PORT);
ret = ret & 0xff; // Only check bottom byte
if (ret) // Busy
{
// Save it
Buffer = (PMESSAGE)Q_REM((void *)&PORT->PORTTX_Q);
C_Q_ADD(&PACTORSAVEQ, Buffer);
goto PACTORLOOP;
}
Buffer = (PMESSAGE)Q_REM((void *)&PORT->PORTTX_Q);
if (PORT->PORTDISABLED)
{
ReleaseBuffer(Buffer);
goto PACTORLOOP;
}
PORT->L2FRAMESSENT++;
OutOctets[PORT->PORTNUMBER] += Message->LENGTH;
PORT->PORTTXROUTINE((struct _EXTPORTDATA *)PORT, Buffer);
Sent++;
if (Sent < 5)
goto PACTORLOOP; // SEE IF MORE
ENDOFLIST:
// Move the saved frames back onto Port Q
PORT->PORTTX_Q = PACTORSAVEQ;
break;
}
PORT->PORTRXROUTINE((struct _EXTPORTDATA *)PORT); // SEE IF MESSAGE RECEIVED
PORT = PORT->PORTPOINTER;
}
/*
;
; CHECK FOR INCOMING MESSAGES ON LINK CONTROL TABLE -
; BY NOW ONLY 'I' FRAMES WILL BE PRESENT -
; LEVEL 2 PROTOCOL HANDLING IS DONE IN MESSAGE RECEIVE CODE
; AND LINK HANDLING INTERRUPT ROUTINES
;
*/
LINK = LINKS;
i = MAXLINKS;
while (i--)
{
if (LINK->LINKCALL[0])
{
Buffer = Q_REM(&LINK->RX_Q);
while (Buffer)
{
ProcessIframe(LINK, (PDATAMESSAGE)Buffer);
Buffer =(PMESSAGE)Q_REM((void *)&LINK->RX_Q);
}
// CHECK FOR OUTGOING MSGS
if (LINK->L2STATE >= 5) // CANT SEND TEXT TILL CONNECTED
{
// CMP VER1FLAG[EBX],1
// JE SHORT MAINL35 ; NEED TO RETRY WITH I FRAMES IF VER 1
// CMP L2RETRIES[EBX],0
// JNE SHORT MAINL40 ; CANT SEND TEXT IF RETRYING
if ((LINK->L2FLAGS & RNRSET) == 0)
SDETX(LINK);
else
{
// Stuck link debug check
if (LINK->LINKWINDOW == 0 || LINK->LASTFRAMESENT == 0 || (NOW - LINK->LASTFRAMESENT) > 60) // No send for 60 secs
{
if (COUNT_AT_L2(LINK) > 16 || LINK->LINKWINDOW == 0)
{
// Dump Link State
char Normcall[11] = "";
char Normcall2[11] = "";
int Count = COUNT_AT_L2(LINK);
int secs = NOW - LINK->LASTFRAMESENT;
ConvFromAX25(LINK->LINKCALL, Normcall);
ConvFromAX25(LINK->OURCALL, Normcall2);
Debugprintf("*** Stuck L2 Session for %d Secs RNR Set %s %s %d", secs, Normcall, Normcall2, Count);
Debugprintf("LINK->LINKNS %d LINK->LINKOWS %d SDTSLOT %d LINKWINDOW %d L2FLAGS %d", LINK->LINKNS, LINK->LINKOWS, LINK->SDTSLOT, LINK->LINKWINDOW, LINK->L2FLAGS);
Debugprintf("Slots %x %x %x %x %x %x %x %x", LINK->FRAMES[0], LINK->FRAMES[1], LINK->FRAMES[2], LINK->FRAMES[3],
LINK->FRAMES[4], LINK->FRAMES[5], LINK->FRAMES[6], LINK->FRAMES[7]);
// Reset Link
InformPartner(LINK, NORMALCLOSE); // TELL OTHER END ITS GONE
LINK->L2RETRIES -= 1; // Just send one DISC
LINK->L2STATE = 4; // CLOSING
L2SENDCOMMAND(LINK, DISC | PFBIT);
return retval; // why??
}
}
}
}
}
LINK++;
}
L4BG(); // DO LEVEL 4 PROCESSING
L3BG();
TNCTimerProc();
return retval;
}
VOID DoListenMonitor(TRANSPORTENTRY * L4, MESSAGE * Msg)
{
uint64_t SaveMMASK = MMASK;
BOOL SaveMTX = MTX;
BOOL SaveMCOM = MCOM;
BOOL SaveMUI = MUIONLY;
PDATAMESSAGE Buffer;
char MonBuffer[1024];
int len;
struct tm * TM;
UCHAR * monchars = (UCHAR *)Msg;
if (CountFramesQueuedOnSession(L4) > 10)
return;
if (monchars[21] == 3 && monchars[22] == 0xcf && monchars[23] == 0xff) // Netrom Nodes
return;
IntSetTraceOptionsEx(L4->LISTEN, 1, 0, 0);
TM = gmtime(&Msg->Timestamp);
sprintf(MonBuffer, "%02d:%02d:%02d ", TM->tm_hour, TM->tm_min, TM->tm_sec);
len = IntDecodeFrame(Msg, &MonBuffer[9], Msg->Timestamp, L4->LISTEN, FALSE, TRUE);
IntSetTraceOptionsEx(SaveMMASK, SaveMTX, SaveMCOM, SaveMUI);
if (len == 0)
return;
len += 9;
if (len > 256)
len = 256;
Buffer = GetBuff();
if (Buffer)
{
char * ptr = &Buffer->L2DATA[0];
Buffer->PID = 0xf0;
memcpy(ptr, MonBuffer, len);
Buffer->LENGTH = (USHORT)len + 4 + sizeof(void *);
C_Q_ADD(&L4->L4TX_Q, Buffer);
PostDataAvailable(L4);
}
}
DllExport int APIENTRY DllBPQTRACE(MESSAGE * Msg, BOOL TOAPRS)
{
int ret;
GetSemaphore(&Semaphore, 88);
ret = BPQTRACE(Msg, TOAPRS);
FreeSemaphore(&Semaphore);
return ret;
}
int BPQTRACE(MESSAGE * Msg, BOOL TOAPRS)
{
// ATTACH A COPY OF FRAME TO ANY BPQ HOST PORTS WITH MONITORING ENABLED
TRANSPORTENTRY * L4 = L4TABLE;
MESSAGE * Buffer;
int i = BPQHOSTSTREAMS + 2; // Include Telnet and AGW Stream
if (TOAPRS)
i++; // Include APRS Stream
while(i)
{
i--;
if (QCOUNT < 100)
return FALSE;
if (BPQHOSTVECTOR[i].HOSTAPPLFLAGS & 0x80) // Trace Enabled?
{
Buffer = GetBuff();
if (Buffer)
{
memcpy(&Buffer->PORT, &Msg->PORT, BUFFLEN - sizeof(void *)); // Dont copy chain word
C_Q_ADD(&BPQHOSTVECTOR[i].HOSTTRACEQ, Buffer);
#ifndef LINBPQ
if (BPQHOSTVECTOR[i].HOSTHANDLE)
PostMessage(BPQHOSTVECTOR[i].HOSTHANDLE, BPQMsg, BPQHOSTVECTOR[i].HOSTSTREAM, 1);
#endif
}
}
}
// Also pass to any users LISTENING on this port
i = MAXCIRCUITS;
if (QCOUNT < 300)
return FALSE; // Until I add by session flow control
while (i--)
{
if (L4->LISTEN)
if ((((uint64_t)1 << ((Msg->PORT & 0x7f) - 1)) & L4->LISTEN))
// if ((Msg->PORT & 0x7f) == L4->LISTEN)
DoListenMonitor(L4, Msg);
L4++;
}
// And to the Monitor to File system.
if (MONTOFILEFLAG) // Trace Enabled?
{
Buffer = GetBuff();
if (Buffer)
{
memcpy(&Buffer->PORT, &Msg->PORT, BUFFLEN - sizeof(void *)); // Dont copy chain word
C_Q_ADD(&FILEMONVECTOR->HOSTTRACEQ, Buffer);
}
}
return TRUE;
}
;
VOID INITIALISEPORTS()
{
char INITMSG[80];
struct PORTCONTROL * PORT = PORTTABLE;
struct PORTCONTROL * SAVEPORT;
while (PORT)
{
sprintf(INITMSG, "Initialising Port %02d ", PORT->PORTNUMBER);
WritetoConsoleLocal(INITMSG);
PORT->PORTINITCODE(PORT);
SAVEPORT=PORT;
// See if it is an RF port
if (PORT->isRF == -1) // Not set
{
// Try to determine if RF
if (PORT->PORTTYPE == 0)
{
struct KISSINFO * KISS = (struct KISSINFO *)PORT;
NPASYINFO Port;
if (KISS->FIRSTPORT && KISS->FIRSTPORT != KISS)
{
// Not first port on device
PORT = (struct PORTCONTROL *)KISS->FIRSTPORT;
}
Port = KISSInfo[PORT->PORTNUMBER];
if (Port)
{
// KISS like
if (PORT->PORTIPADDR.s_addr || PORT->KISSSLAVE)
{
// KISS over UDP or TCP
if (PORT->KISSTCP)
PORT->isRF = 1; // Assume TCP is RF (software modem)
else
PORT->isRF = 0; // Assuem UDP is Internet
}
else
PORT->isRF = 1; // Serial port
}
}
else if (PORT->PORTTYPE == 14) // Loopback
PORT->isRF = 0;
else if (PORT->PORTTYPE == 16) // External
{
if (PORT->PROTOCOL == 10) // 'HF' Port
{
struct TNCINFO * TNC = TNCInfo[PORT->PORTNUMBER];
if (TNC && TNC->Hardware == H_TELNET)
PORT->isRF = 0;
else
PORT->isRF = 1; // ARDOP etc
}
else
{
// External but not HF - AXIP, BPQETHER VKISS, ??
PORT->isRF = 0;
}
}
}
PORT = SAVEPORT->PORTPOINTER;
}
}
VOID FindLostBuffers()
{
void ** Buff;
int n, i;
unsigned int rev;
UINT CodeDump[16];
char codeText[65] = "";
unsigned char * codeByte = (unsigned char *) CodeDump;
PBPQVECSTRUC HOSTSESS = BPQHOSTVECTOR;
struct _TRANSPORTENTRY * L4; // Pointer to Session
struct DEST_LIST * DEST = DESTS;
struct ROUTE * Routes = NEIGHBOURS;
int MaxRoutes = MAXNEIGHBOURS;
int Queued;
char Call[10];
n = MAXDESTS;
Debugprintf("Looking for missing Buffers");
while (n--)
{
if (DEST->DEST_CALL[0] && DEST->DEST_Q) // Spare
{
Debugprintf("DEST Queue %s %d", DEST->DEST_ALIAS, C_Q_COUNT(&DEST->DEST_Q));
}
DEST++;
}
n = 0;
while (n < BPQHOSTSTREAMS + 4)
{
// Check Trace Q
if (HOSTSESS->HOSTTRACEQ)
{
int Count = C_Q_COUNT(&HOSTSESS->HOSTTRACEQ);
Debugprintf("Trace Buffers Stream %d Count %d", n, Count);
L4 = HOSTSESS->HOSTSESSION;
if (L4 && (L4->L4TX_Q || L4->L4RX_Q || L4->L4HOLD_Q || L4->L4RESEQ_Q))
Debugprintf("Stream %d %d %d %d %d", n, C_Q_COUNT(&L4->L4TX_Q),
C_Q_COUNT(&L4->L4RX_Q), C_Q_COUNT(&L4->L4HOLD_Q), C_Q_COUNT(&L4->L4RESEQ_Q));
}
n++;
HOSTSESS++;
}
n = MAXCIRCUITS;
L4 = L4TABLE;
while (n--)
{
if (L4->L4USER[0] == 0)
{
L4++;
continue;
}
if (L4->L4TX_Q || L4->L4RX_Q || L4->L4HOLD_Q || L4->L4RESEQ_Q)
Debugprintf("L4 %d TX %d RX %d HOLD %d RESEQ %d", MAXCIRCUITS - n, C_Q_COUNT(&L4->L4TX_Q),
C_Q_COUNT(&L4->L4RX_Q), C_Q_COUNT(&L4->L4HOLD_Q), C_Q_COUNT(&L4->L4RESEQ_Q));
L4++;
}
// Routes
while (MaxRoutes--)
{
if (Routes->NEIGHBOUR_CALL[0] != 0)
{
Call[ConvFromAX25(Routes->NEIGHBOUR_CALL, Call)] = 0;
if (Routes->NEIGHBOUR_LINK)
{
Queued = COUNT_AT_L2(Routes->NEIGHBOUR_LINK); // SEE HOW MANY QUEUED
if (Queued)
Debugprintf("Route %s %d", Call, Queued);
}
}
Routes++;
}
// Build list of buffers, then mark off all on free Q
Buff = BUFFERPOOL;
n = 0;
for (i = 0; i < NUMBEROFBUFFERS; i++)
{
Bufferlist[n++] = Buff;
Buff += (BUFFALLOC / sizeof(void *));
}
Buff = FREE_Q;
while (Buff)
{
n = NUMBEROFBUFFERS;
while (n--)
{
if (Bufferlist[n] == Buff)
{
Bufferlist[n] = 0;
break;
}
}
if (Buff == *Buff)
break;
Buff = *Buff;
}
n = NUMBEROFBUFFERS;
while (n--)
{
if (Bufferlist[n])
{
char * fileptr = (char *)Bufferlist[n];
MESSAGE * Msg = (MESSAGE *)Bufferlist[n];
memcpy(CodeDump, Bufferlist[n], 64);
for (i = 0; i < 64; i++)
{
if (codeByte[i] > 0x1f && codeByte[i] < 0x80)
codeText[i] = codeByte[i];
else
codeText[i] = '.';
}
for (i = 0; i < 16; i++)
{
rev = (CodeDump[i] & 0xff) << 24;
rev |= (CodeDump[i] & 0xff00) << 8;
rev |= (CodeDump[i] & 0xff0000) >> 8;
rev |= (CodeDump[i] & 0xff000000) >> 24;
CodeDump[i] = rev;
}
Debugprintf("%08x %08x %08x %08x %08x %08x %08x %08x %08x ",
Bufferlist[n], CodeDump[0], CodeDump[1], CodeDump[2], CodeDump[3], CodeDump[4], CodeDump[5], CodeDump[6], CodeDump[7]);
Debugprintf(" %08x %08x %08x %08x %08x %08x %08x %08x %d",
CodeDump[8], CodeDump[9], CodeDump[10], CodeDump[11], CodeDump[12], CodeDump[13], CodeDump[14], CodeDump[15], Msg->Process);
Debugprintf(" %s %s", &fileptr[400], codeText);
}
}
// rebuild list for buffer check
Buff = BUFFERPOOL;
n = 0;
for (i = 0; i < NUMBEROFBUFFERS; i++)
{
Bufferlist[n++] = Buff;
Buff += (BUFFALLOC / sizeof(void *));
}
}
void WriteConnectLog(char * fromCall, char * toCall, UCHAR * Mode)
{
UCHAR FN[MAX_PATH];
FILE * LogHandle;
time_t T;
struct tm * tm;
char LogMsg[256];
int MsgLen;
T = NOW;
tm = gmtime(&T);
sprintf(FN,"%s/logs/ConnectLog_%02d%02d%02d.log", LogDirectory, tm->tm_year - 100, tm->tm_mon + 1, tm->tm_mday);
LogHandle = fopen(FN, "ab");
if (LogHandle == NULL)
return;
MsgLen = sprintf(LogMsg, "%02d:%02d:%02d Call from %s to %s Mode %s\r\n", tm->tm_hour, tm->tm_min, tm->tm_sec, fromCall, toCall, Mode);
fwrite(LogMsg , 1, MsgLen, LogHandle);
fclose(LogHandle);
}
|