forked from erikarn/LinBPQ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cMain.c
2231 lines (1625 loc) · 45.8 KB
/
cMain.c
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
/*
Copyright 2001-2015 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
#define _USE_32BIT_TIME_T
#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"
VOID L2Routine(struct PORTCONTROL * PORT, UINT * Buffer);
VOID ProcessIframe(struct _LINKTABLE * LINK, UINT * Buffer);
VOID FindLostBuffers();
#include "configstructs.h"
struct PORTCONFIG * PortRec;
#define RNRSET 0x2 // RNR RECEIVED FROM OTHER END
// 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];
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)
UINT FREE_Q = 0;
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
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*3; // LINK VALIDATION TIMER (3 MINS) (+ a bit to reduce RR collisions)
int L2KILLTIME = 16*60*3; // 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
//TNCTABLE DD 0
//NUMBEROFSTREAMS DD 0
extern VOID * ENDPOOL;
extern UINT APPL_Q; // Queue of frames for APRS Appl
#define BPQHOSTSTREAMS 64
// Although externally streams are numbered 1 to 64, internally offsets are 0 - 63
BPQVECSTRUC DUMMY = {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];
int BPQVECLENGTH = sizeof(BPQVECSTRUC);
int NODEORDER = 0;
UCHAR LINKEDFLAG = 0;
UCHAR UNPROTOCALL[80] = "";
char * INFOMSG = NULL;
int INFOLEN = 0;
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
UINT TRACE_Q = 0; // TRANSMITTED FRAMES TO BE TRACED
int RANDOM = 0; // 'RANDOM' NUMBER FOR PERSISTENCE CALCS
int L2TIMERFLAG = 0; // INCREMENTED AT 18HZ BY TIMER INTERRUPT
int L3TIMERFLAG = 0; // DITTO
int L4TIMERFLAG = 0; // DITTO
char HEADERCHAR = '}'; // CHAR FOR _NODE HEADER MSGS
VOID * LASTPOINTER = NULL; // PERVIOUS _NODE DURING CHAINING
int REALTIMETICKS = 0;
int BGTIMER = 0; // TO CONTROL BG SCANS
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;
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
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[33][33] = {0};
// Keep Buffers at end
#define DATABYTES 400000 // WAS 320000
UCHAR DATAAREA[DATABYTES] = "";
UINT * 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[];
int IntDecodeFrame(MESSAGE * msg, char * buffer, int Stamp, UINT Mask, BOOL APRS, BOOL MINI);
DllExport int APIENTRY SetTraceOptionsEx(int mask, int mtxparam, int mcomparam, int monUIOnly);
// LOOPBACK PORT ROUTINES
VOID LINKINIT(PEXTPORTDATA PORTVEC)
{
WritetoConsoleLocal("Loopback\n");
}
VOID LINKTX(PEXTPORTDATA PORTVEC, UINT * Buffer)
{
// LOOP BACK TO SWITCH
struct _LINKTABLE * LINK;
LINK = (struct _LINKTABLE *)Buffer[(BUFFLEN-4)/4];
if (LINK)
{
if (LINK->L2TIMER)
LINK->L2TIMER = LINK->L2TIME;
Buffer[(BUFFLEN-4)/4] = 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;
}
int Dummy() // Dummy for missing EXT Driver
{
return 0;
}
VOID EXTINIT(PEXTPORTDATA PORTVEC)
{
// LOAD DLL - NAME IS IN PORT_DLL_NAME
VOID * Routine;
PORTVEC->PORT_EXT_ADDR = Dummy;
Routine = (VOID *)InitializeExtDriver(PORTVEC);
if (Routine == 0)
{
WritetoConsoleLocal("Driver installation failed\n");
return;
}
PORTVEC->PORT_EXT_ADDR = Routine;
// ALSO CALL THE ROUTINE TO START IT UP, ESPECIALLY IF A L2 ROUTINE
Routine = (VOID *)PORTVEC->PORT_EXT_ADDR(PORTVEC);
// Startup returns address of processing routine
PORTVEC->PORT_EXT_ADDR = Routine;
}
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, Buffer);
return; // Baycom driver passes frames to trace once sent
}
LINK = Buffer->Linkptr;
if (LINK)
{
if (LINK->L2TIMER)
LINK->L2TIMER = LINK->L2TIME;
Buffer->Linkptr = 0; // CLEAR FLAG FROM BUFFER
}
PORTVEC->PORT_EXT_ADDR(2, PORT->PORTNUMBER, Buffer);
if (PORT->PROTOCOL == 10)
{
ReleaseBuffer(Buffer);
return;
}
C_Q_ADD(&TRACE_Q, Buffer);
return;
}
VOID EXTRX(PEXTPORTDATA PORTVEC)
{
struct _MESSAGE * Message;
int Len;
struct PORTCONTROL * PORT = (struct PORTCONTROL *)PORTVEC;
Loop:
if (QCOUNT < 10)
return;
Message = GetBuff();
if (Message == NULL)
return;
Len = PORTVEC->PORT_EXT_ADDR(1, PORT->PORTNUMBER, Message);
if (Len == 0)
{
ReleaseBuffer((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;
ReleaseBuffer((UINT *)Message);
// GET RID OF ANY SESSION ENTRIES
Session = PORTVEC->ATTACHEDSESSIONS[Sessno];
if (Session)
{
CloseSessionPartner(Session);
PORTVEC->ATTACHEDSESSIONS[Sessno] = NULL;
}
return;
}
}
C_Q_ADD(&PORT->PORTRX_Q, (UINT *)Message);
goto Loop;
return;
}
VOID EXTTIMER(PEXTPORTDATA PORTVEC)
{
// USED TO SEND A RE-INIT IN THE CORRECT PROCESS
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
}
int EXTTXCHECK(PEXTPORTDATA PORTVEC, int Chan)
{
return PORTVEC->PORT_EXT_ADDR(3, PORTVEC->PORTCONTROL.PORTNUMBER, Chan);
}
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 LINKTX
#define HDLCRX LINKRX
#define HDLCTIMER LINKTIMER
#define HDLCCLOSE LINKCLOSE
#define HDLCTXCHECK LINKTXCHECK
#define PC120INIT LINKINIT
#define DRSIINIT LINKINIT
#define TOSHINIT LINKINIT
#define RLC100INIT LINKINIT
#define BAYCOMINIT LINKINIT
#define PA0INIT LINKINIT
#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(), EXTTX(), LINKRX(), EXTRX();
extern VOID LINKCLOSE(), EXTCLOSE() ,LINKTIMER(), EXTTIMER();
// 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 L3TimerProc();
extern int L4TimerProc();
extern int L3FastTimer();
extern int StatsTimer();
extern int COMMANDHANDLER();
extern int SDETX();
extern int L4BG();
extern int L3BG();
extern int TNCTimerProc();
extern int PROCESSIFRAME();
BOOL Start()
{
struct CONFIGTABLE * cfg = (struct CONFIGTABLE * )ConfigBuffer;
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;
CMDX * CMD;
unsigned char * ptr2, * ptr3, * ptr4;
USHORT * CWPTR;
int i, n, int3;
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
TimeLoaded = time(NULL);
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)
{
// USE BBS CALL FOR NODE AS WELL
memcpy(MYNODECALL, cfg->C_BBSCALL, 10);
memcpy(MYALIASTEXT, cfg->C_BBSALIAS, 6);
memcpy(MYALIASLOPPED, cfg->C_BBSALIAS, 10);
}
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])
memcpy(MYNETROMCALL, cfg->C_NETROMCALL, 10);
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 * 3;
L4LIMIT = cfg->C_IDLETIME;
if (L4LIMIT && L4LIMIT < 120)
L4LIMIT = 120; // Don't allow stupidly low
L2KILLTIME = L4LIMIT * 3;
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;
MAXCIRCUITS = cfg->C_MAXCIRCUITS;
HIDENODES = cfg->C_HIDENODES;
// 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 );
ptr2 = ConfigBuffer + ApplOffset;
ptr1 = (struct APPLCONFIG *)ptr2;
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 PORT TABLE
ptr2 = ConfigBuffer + C_PORTS;
PortRec = (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;
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[0])
PORT->SerialPortName = _strdup(PortRec->SerialPortName);
else
{
if (PORT->IOBASE > 0 && PORT->IOBASE < 256)
{
char Name[80];
#ifdef LINBPQ
sprintf(Name, "com%d", PORT->IOBASE);
#else
sprintf(Name, "COM%d", PORT->IOBASE);
#endif
PORT->SerialPortName = _strdup(Name);
}
}
PORT->INTLEVEL = (char)PortRec->INTLEVEL;
PORT->BAUDRATE = PortRec->SPEED;
if (PORT->BAUDRATE == 49664)
PORT->BAUDRATE = (int)115200;
PORT->CHANNELNUM = (char)PortRec->CHANNEL;
PORT->BBSBANNED = (UCHAR)PortRec->BBSFLAG;
PORT->PORTQUALITY = (UCHAR)PortRec->QUALITY;
PORT->NormalizeQuality = !PortRec->NoNormalize;
PORT->IgnoreUnlocked = PortRec->IGNOREUNLOCKED;
PORT->INP3ONLY = PortRec->INP3ONLY;
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 / 333;
PORT->PORTT2 = PortRec->RESPTIME /333;
PORT->PORTN2 = (UCHAR)PortRec->RETRIES;
PORT->PORTPACLEN = (UCHAR)PortRec->PACLEN;
PORT->QUAL_ADJUST = (UCHAR)PortRec->QUALADJUST;
PORT->DIGIFLAG = PortRec->DIGIFLAG;
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);
#if 0
PORT->XDIGIS = PortRec->XDIGIS; // Crossband digi aliases
#endif
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 0
if (PortRec->WL2K)
memcpy(&PORT->WL2KInfo, PortRec->WL2K, sizeof(struct WL2KInfo));
#endif
// 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 boundsaty (for ARM5 etc)
int3 = (int)ptr3;
int3 += 3;
int3 &= 0xfffffffc;
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++;
}