forked from erikarn/LinBPQ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
L3Code.c
1405 lines (995 loc) · 27.7 KB
/
L3Code.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
*/
/*
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 L3Code.asm
//
#define Kernel
#define _CRT_SECURE_NO_DEPRECATE
#define _USE_32BIT_TIME_T
#pragma data_seg("_BPQDATA")
#include "time.h"
#include "stdio.h"
#include <fcntl.h>
#include "CHeaders.h"
VOID UPDATEDESTLIST();
VOID MOVEALL(dest_list * DEST);
VOID MOVE3TO2(dest_list * DEST);
VOID CLEARTHIRD(dest_list * DEST);
VOID L3TRYNEXTDEST(struct ROUTE * ROUTE);
extern BOOL NODESINPROGRESS ;;
PPORTCONTROL L3CURRENTPORT;
extern dest_list * CURRENTNODE;
int L3_10SECS = 10;
VOID L3BG()
{
// TRANSFER MESSAGES FROM DEST TO LINK
int n = MAXDESTS;
struct DEST_LIST * DEST = DESTS; // NODE LIST
struct PORTCONTROL * PORT = PORTTABLE;
struct ROUTE * ROUTE;
struct _LINKTABLE * LINK;
while (n--)
{
if (DEST->DEST_CALL[0]) // Active entry?
{
while(DEST->DEST_Q) // FRAMES TO SEND?
{
int ActiveRoute = DEST->DEST_ROUTE;
if (ActiveRoute)
{
ROUTE = DEST->NRROUTE[ActiveRoute - 1].ROUT_NEIGHBOUR;
if (ROUTE)
LINK = ROUTE->NEIGHBOUR_LINK;
else
LINK= NULL;
if (LINK)
{
if (LINK->L2STATE == 0)
{
// LINK ENTRY IS INVALID - IT PROBABLY HAS BEEN 'ZAPPED', SO CANCEL IT
ROUTE->NEIGHBOUR_LINK = NULL;
}
else
{
if (LINK->L2STATE < 5)
{
goto NextDest; // Wait for it to activate
}
else
{
ROUTE->NBOUR_IFRAMES++;
C_Q_ADD(&LINK->TX_Q, Q_REM(&DEST->DEST_Q));
continue; // See if more
}
}
}
// Drop through to Activate
}
if (ACTIVATE_DEST(DEST) == FALSE)
{
// Node has no routes - get rid of it
REMOVENODE(DEST);
return; // Avoid riskof looking at lod entries
}
}
}
NextDest:
DEST++;
}
}
BOOL ACTIVATE_DEST(struct DEST_LIST * DEST)
{
int n = MAXDESTS;
struct PORTCONTROL * PORT = PORTTABLE;
struct ROUTE * ROUTE;
struct _LINKTABLE * LINK;
int ActiveRoute;
if (DEST->DEST_ROUTE == 0) // ALREADY HAVE A SELECTED ROUTE?
DEST->DEST_ROUTE = 1; // TRY TO ACTIVATE FIRST
ActiveRoute = DEST->DEST_ROUTE - 1;
ROUTE = DEST->NRROUTE[ActiveRoute].ROUT_NEIGHBOUR;
if (ROUTE == 0)
{
// Currnet Route not present
// If current route is 1, then we must have INP3 routes (or entry is corrupt)
if (DEST->DEST_ROUTE != 1)
goto NOROUTETODEST;
// Current Route is 1
if (DEST->ROUTE[0].ROUT_NEIGHBOUR == 0)
return FALSE; // No INP3 so No Routes
DEST->DEST_ROUTE = 4; // First INP3
ROUTE = DEST->ROUTE[0].ROUT_NEIGHBOUR;
}
LINK = ROUTE->NEIGHBOUR_LINK;
if (LINK == 0)
{
// Need to Activate Link
// SET UP LINK TABLE ENTRY
return L2SETUPCROSSLINK(ROUTE);
}
// We mst be waiting for link to come up
return TRUE;
NOROUTETODEST:
// CURRENT NEIGHBOUR NOT DEFINED - RESET TO USE FIRST
if (DEST->DEST_ROUTE == 1)
return FALSE; // First not defined so give up
DEST->DEST_ROUTE = 0;
return TRUE;
}
// PUBLIC _PROCESSUZ7HONODEMESSAGE
//_PROCESSUZ7HONODEMESSAGE:
// MOV _SAVEPORT,AL
VOID PROCESSNODEMESSAGE(MESSAGE * Msg, struct PORTCONTROL * PORT)
{
// PROCESS A NET/ROM 'NODES' MESSAGE
// UPDATE _NEIGHBOURS LIST WITH ORIGINATING CALL, AND
// DESTINATION LIST WITH ANY PRACTICAL ROUTES
struct DEST_LIST * DEST;
struct ROUTE * ROUTE;
int Portno = PORT->PORTNUMBER;
UINT Stamp, HH, MM;
int Msglen = Msg->LENGTH;
int n;
UCHAR * ptr1, * ptr2, * saveptr;
int Qual;
APPLCALLS * APPL;
int App;
if (PORT->PORTQUALITY == 0 || PORT->INP3ONLY)
return;
// SEE IF OUR CALL - DONT WANT TO PUT IT IN LIST!
if (CompareCalls(Msg->ORIGIN, NETROMCALL))
return;
for (App = 0; App < NumberofAppls; App++)
{
APPL=&APPLCALLTABLE[App];
if (APPL->APPLHASALIAS == 0 && CompareCalls(Msg->ORIGIN, APPL->APPLCALL))
return;
}
Msg->ORIGIN[6] &= 0x1E; // MASK OFF LAST ADDR BIT
// SEE IF ORIGINATING CALL IS IN NEIGHBOUR LIST - IF NOT ADD IT
if (FindNeighbour(Msg->ORIGIN, Portno, &ROUTE) == 0)
{
// Not in list
if (ROUTE == NULL)
return; // Table full
// CREATE NEIGHBOUR RECORD
memcpy(ROUTE->NEIGHBOUR_CALL, Msg->ORIGIN, 7);
ROUTE->NEIGHBOUR_PORT = Portno;
ROUTE->NEIGHBOUR_QUAL = PORT->PORTQUALITY;
ROUTE->NEIGHBOUR_LINK = 0; // CANT HAVE A LINK IF NEW _NODE
ROUTE->NoKeepAlive = PORT->PortNoKeepAlive;
}
// if locked route with quality zero ignore
if ((ROUTE->NEIGHBOUR_FLAG & 1)) // LOCKED ROUTE
if (ROUTE->NEIGHBOUR_QUAL == 0)
return;
// If Ignoreunlocked set, ignore it not locked
if ((ROUTE->NEIGHBOUR_FLAG & 1) == 0) // LOCKED ROUTE
if (PORT->IgnoreUnlocked)
return;
// if not locked, update route quality from port quality (may have changed config and not cleared SAVENODES
if ((ROUTE->NEIGHBOUR_FLAG & 1) == 0) // Not LOCKED ROUTE
ROUTE->NEIGHBOUR_QUAL = PORT->PORTQUALITY;
// GET TIME FROM BIOS DATA AREA OR RTC
time((time_t *)&Stamp);
Stamp = Stamp % 86400; // Secs into day
HH = Stamp / 3600;
Stamp -= HH * 3600;
MM = Stamp / 60;
ROUTE->NEIGHBOUR_TIME = 256 * HH + MM;
// GET QUALITY
Qual = ROUTEQUAL = ROUTE->NEIGHBOUR_QUAL; // FOR INITIAL ROUTE TABLE UPDATE
// CHECK LINK IS IN DEST LIST
if (FindDestination(Msg->ORIGIN, &DEST) == 0)
{
if (DEST == NULL)
return; // Tsble Full
// CREATE DESTINATION RECORD
memset(DEST, 0, sizeof(struct DEST_LIST));
memcpy(DEST->DEST_CALL, Msg->ORIGIN, 7);
NUMBEROFNODES++;
}
// ALWAYS UPDATE ALIAS IN CASE NOT PRESENT IN ORIGINAL TABLE
ptr1 = &Msg->L2DATA[1];
ptr2 = &DEST->DEST_ALIAS[0];
if (*ptr1 > ' ') // Only of present
{
// Validate Alias, mainly for DISABL KPC3 Problem
UCHAR c;
n = 6;
while (n--)
{
c = *(ptr1++);
if (c < 0x20 || c > 0x7A)
c = ' ';
*(ptr2++) = c;
}
}
// UPDATE QUALITY AND OBS COUNT
PROCROUTES(DEST, ROUTE, Qual);
Msglen -= 23; // LEVEL 2 HEADER FLAG and NODE MNEMONIC
// PROCESS DESTINATIONS from message
// ptr1 = start
saveptr = ptr1;
while (Msglen > 21) // STILL AT LEAST 1 ENTRY LEFT
{
Msglen -= 21;
ptr1 = saveptr;
saveptr += 21;
// SEE IF OUR and of our CALLs - DONT WANT TO PUT IT IN LIST!
if (CompareCalls(ptr1, MYCALL))
{
// But use it to get route quality setting from other end
// As we now get qual ftom highest, only use this after a reload in
// case other end has changed.
if (ROUTE->FirstTimeFlag == 0)
{
// Check if route is via our node
if (memcmp(ptr1, &ptr1[13], 7) == 0)
{
if (ROUTE->OtherendLocked == 0) // Dont update locked quality
ROUTE->OtherendsRouteQual = ptr1[20];
ROUTE->FirstTimeFlag = 1; // Only do it first time after load
}
}
continue;
}
for (n = 0; n < 32; n++)
{
if (CompareCalls(ptr1, APPLCALLTABLE[n].APPLCALL))
continue;
}
// MAKE SURE ITS NOT CORRUPTED
n = 6;
while (n--)
{
if (*(ptr1++) < 0x40) // Call
continue;
}
ptr1++; // skip ssid
n = 6;
while (n--)
{
if (*(ptr1++) < 0x20) // Alias
continue;
}
ptr1 -= 13; // Back to start
// CALCULATE ROUTE QUALITY
// Experimantal Code to adjuct received route qualities based on deduced quality
// settings at other end of link.
// Don't mess with Application Qualities. There are almost always 255, and
// if not there is probably a good reason for the value chosen.
if (CompareCalls(Msg->ORIGIN, &ptr1[13]))
{
// Application Node - Just do normal update
Qual = (((ROUTEQUAL * ptr1[20]) + 128)) / 256;
}
else
{
// Try using the highest reported indirect route as remote qual
if (ROUTE->OtherendLocked == 0) // Not locked
{
if (ptr1[20] > ROUTE->OtherendsRouteQual)
ROUTE->OtherendsRouteQual = ptr1[20];
}
// Treat 255 as 254, so 255 routes doen't get included with minquals
// designed to only include applcalls
if (ptr1[20] == 255)
ptr1[20] = 254;
Qual = (((ROUTEQUAL * ptr1[20]) + 128)) / 256;
if (ROUTE->OtherendsRouteQual && PORT->NormalizeQuality)
{
Qual = (Qual * ROUTEQUAL) / ROUTE->OtherendsRouteQual;
if (Qual > ROUTEQUAL)
Qual = ROUTEQUAL;
}
}
// SEE IF BELOW MIN QUAL FOR AUTO UPDATES
if (Qual < MINQUAL)
continue;
// CHECK LINK IS IN DEST LIST
if (FindDestination(ptr1, &DEST) == 0)
{
if (DEST == NULL)
continue;
// CREATE DESTINATION RECORD
memset(DEST, 0, sizeof(struct DEST_LIST));
memcpy(DEST->DEST_CALL, ptr1, 7);
NUMBEROFNODES++;
}
ptr1 += 7;
// UPDATE ALIAS
memcpy(DEST->DEST_ALIAS, ptr1, 6);
ptr1 += 6;
// NOW POINTING AT BEST NEIGHBOUR - IF THIS IS US, THEN ROUTE IS A LOOP
if (CompareCalls(ptr1, NETROMCALL))
Qual = 0;
// DEST IS NOW IN TABLE -
// 1. SEE IF THIS ROUTE IS IN TABLE - IF SO UPDATE QUALITY,
// IF NOT, ADD THIS ONE IF IT HAS HIGHER QUALITY THAN EXISTING ONES
PROCROUTES(DEST, ROUTE, Qual);
ptr1 += 8;
}
}
VOID PROCROUTES(struct DEST_LIST * DEST, struct ROUTE * ROUTE, int Qual)
{
// ADD NEIGHBOUR ADDRESS IN ROUTE TO NODE's ROUTE TABLE IF BETTER QUALITY THAN THOSE PRESENT
int Index = 0;
struct NR_DEST_ROUTE_ENTRY Temp;
if (DEST->DEST_STATE & 0x80) // BBS ENTRY
return;
for (Index = 0; Index < 4; Index++)
{
if (DEST->NRROUTE[Index].ROUT_NEIGHBOUR == ROUTE)
{
if (Index == 0)
{
// THIS IS A REFRESH OF BEST - IF THIS ISNT ACTIVE ROUTE, MAKE IT ACTIVE
if (DEST->DEST_ROUTE > 1) // LEAVE IT IF NOT SELECTED OR ALREADY USING BEST
DEST->DEST_ROUTE = 1;
}
goto UpdatateThisEntry;
}
}
// NOT IN ANY ROUTE
Index = 0;
if (DEST->NRROUTE[0].ROUT_NEIGHBOUR == 0)
goto UpdatateThisEntry; // SPARE ENTRY, SO USE IT
if (DEST->NRROUTE[0].ROUT_QUALITY < Qual)
{
// New route is better than best, so move other two down and add here
DEST->NRROUTE[2] = DEST->NRROUTE[1];
DEST->NRROUTE[1] = DEST->NRROUTE[0];
DEST->DEST_ROUTE = 0; // Se we will switch to new one
goto UpdatateThisEntry;
}
Index = 1;
if (DEST->NRROUTE[1].ROUT_NEIGHBOUR == 0)
goto UpdatateThisEntry; // SPARE ENTRY, SO USE IT
if (DEST->NRROUTE[1].ROUT_QUALITY < Qual)
{
// New route is better than second, so move down and add here
DEST->NRROUTE[2] = DEST->NRROUTE[1];
goto UpdatateThisEntry; // SPARE ENTRY, SO USE IT
}
Index = 2;
if (DEST->NRROUTE[2].ROUT_NEIGHBOUR == 0)
goto UpdatateThisEntry; // SPARE ENTRY, SO USE IT
if (DEST->NRROUTE[2].ROUT_QUALITY < Qual)
{
// New route is better than third, so add here
goto UpdatateThisEntry; // SPARE ENTRY, SO USE IT
}
// THIS ROUTE IS WORSE THAN ANY OF THE CURRENT 3 - IGNORE IT
return;
UpdatateThisEntry:
DEST->NRROUTE[Index].ROUT_NEIGHBOUR = ROUTE;
// I DONT KNOW WHY I DID THIS, BUT IT CAUSES REFLECTED ROUTES
// TO BE SET UP WITH OBS = 0. THIS MAY PREVENT A VALID ALTERNATE
// VIA THE SAME _NODE TO FAIL TO BE FOUND. SO I'LL TAKE OUT THE
// TEST AND SEE IF ANYTHING NASTY HAPPENS
// IT DID - THIS IS ALSO CALLED BY CHECKL3TABLES. TRY RESETING
// OBS, BUT NOT QUALITY
if ((DEST->NRROUTE[Index].ROUT_OBSCOUNT & 0x80) == 0)
DEST->NRROUTE[Index].ROUT_OBSCOUNT = OBSINIT; // SET OBSOLESCENCE COUNT
if (Qual)
DEST->NRROUTE[Index].ROUT_QUALITY = Qual; // IF ZERO, SKIP UPDATE
// IT IS POSSIBLE ROUTES ARE NOW OUT OF ORDER
SORTROUTES:
if (DEST->NRROUTE[1].ROUT_QUALITY > DEST->NRROUTE[0].ROUT_QUALITY)
{
// SWAP 1 AND 2
Temp = DEST->NRROUTE[0];
DEST->NRROUTE[0] = DEST->NRROUTE[1];
DEST->NRROUTE[1] = Temp;
DEST->DEST_ROUTE = 0; // FORCE A RE-ASSESSMENT
}
if (DEST->NRROUTE[2].ROUT_QUALITY > DEST->NRROUTE[1].ROUT_QUALITY)
{
// SWAP 2 AND 3
Temp = DEST->NRROUTE[1];
DEST->NRROUTE[1] = DEST->NRROUTE[2];
DEST->NRROUTE[2] = Temp;
goto SORTROUTES; // 1 AND 2 MAY NOW BE WRONG!
}
}
int COUNTNODES(struct ROUTE * ROUTE)
{
// COUNT NODES WITH ROUTE VIA NEIGHBOUR IN ESI
int count = 0;
int n = MAXDESTS;
struct DEST_LIST * DEST = DESTS; // NODE LIST
while (n--)
{
if (DEST->NRROUTE[0].ROUT_NEIGHBOUR == ROUTE)
count++;
else if (DEST->NRROUTE[1].ROUT_NEIGHBOUR == ROUTE)
count++;
else if (DEST->NRROUTE[2].ROUT_NEIGHBOUR == ROUTE)
count++;
else if (DEST->ROUTE[0].ROUT_NEIGHBOUR == ROUTE)
count++;
else if (DEST->ROUTE[1].ROUT_NEIGHBOUR == ROUTE)
count++;
else if (DEST->ROUTE[2].ROUT_NEIGHBOUR == ROUTE)
count++;
DEST++;
}
return count;
}
VOID SENDNODE00();
VOID L3BG();
VOID SENDNEXTNODESFRAGMENT();
VOID SENDNODESMSG()
{
if (NODESINPROGRESS)
return;
L3CURRENTPORT = PORTTABLE;
SENDNEXTNODESFRAGMENT();
}
VOID SENDNEXTNODESFRAGMENT()
{
// SEND NEXT FRAGMENT OF A NODES BROADCAST
// FRAGMENTS ARE SENT AT 10 SECONDS INTERVALS - PARTLY TO REDUCE
// QRM, PARTLY TO REDUCE LOAD ON BUFFERS (AND TX POWER SUPPLIES!)
// SEND TO PORT IN CURRENTPORT, STARTING AT CURRENTNODE
struct PORTCONTROL * PORT = L3CURRENTPORT;
dest_list * DEST = CURRENTNODE;
MESSAGE * Buffer;
int Count;
int Qual;
int CURRENTPORTNO, TXMINQUAL;
UCHAR * ptr1, * ptr2;
if (DEST == 0)
{
// FIRST FRAGMENT TO A PORT
while (PORT->PORTQUALITY == 0 || PORT->TXPORT || PORT->INP3ONLY)
// Don't send NODES to Shared TX or INP3 Port
{
// No NODES to this port, so go to next
PORT = PORT->PORTPOINTER;
if (PORT == NULL)
{
// Finished
NODESINPROGRESS = 0;
return;
}
}
L3CURRENTPORT = PORT;
DEST = CURRENTNODE = DESTS; // START OF LIST
NODESINPROGRESS = 1;
}
CURRENTPORTNO = PORT->PORTNUMBER;
TXMINQUAL = PORT->PORTMINQUAL;
if (TXMINQUAL == 0)
TXMINQUAL = 1; // Dont send zero
Buffer = GetBuff();
if (Buffer == 0)
return;
Buffer->PORT = CURRENTPORTNO;
memcpy(Buffer->ORIGIN, NETROMCALL, 7);
memcpy(Buffer->DEST, NODECALL, 7);
Buffer->ORIGIN[6] |= 0x61; // SET CMD END AND RESERVED BITS
Buffer->CTL = UI;
Buffer->PID = 0xCF; // Netrom
ptr1 = &Buffer->L2DATA[0];
*(ptr1++) = 0xff; // Nodes Flag
memcpy(ptr1, MYALIASTEXT, 6);
ptr1+= 6;
// ADD DESTINATION INFO (UNLESS BBS ONLY)
if (NODE == 0)
{
CURRENTNODE = 0; // Finished on this port
goto Sendit;
}
Count = PORT->NODESPACLEN;
if (Count == 0)
Count = 256;
if (Count < 50) // STUPIDLY SMALL?
Count = 50; // EVEN THIS IS RATHER SILLY
Count -= 22; // Fixed Part
Count /= 21; // 21 Bytres per entry
while (Count)
{
if (DEST >= ENDDESTLIST)
{
CURRENTNODE = 0; // Finished on this port
L3CURRENTPORT = PORT->PORTPOINTER;
if (L3CURRENTPORT == NULL)
{
// Finished
NODESINPROGRESS = 0;
}
goto Sendit;
}
if (DEST->NRROUTE[0].ROUT_QUALITY >= TXMINQUAL && DEST->NRROUTE[0].ROUT_OBSCOUNT >= OBSMIN)
{
// Send it
ptr2 = &DEST->DEST_CALL[0];
memcpy(ptr1, ptr2, 13); // Dest and Alias
ptr1 += 13;
ptr2 = (UCHAR *)DEST->NRROUTE[0].ROUT_NEIGHBOUR;
if (ptr2 == 0)
// DUMMY POINTER IN BBS ENTRY - PUT IN OUR CALL
ptr2 = MYCALL;
memcpy(ptr1, ptr2, 7); // Neighbour Call
ptr1 += 7;
Qual = 100;
if (DEST->NRROUTE[0].ROUT_NEIGHBOUR && DEST->NRROUTE[0].ROUT_NEIGHBOUR->NEIGHBOUR_PORT == CURRENTPORTNO)
{
// BEST NEIGHBOUR IS ON CURRENT PORT - REDUCE QUALITY BY QUAL_ADJUST
Qual -= PORT->QUAL_ADJUST;
}
Qual *= DEST->NRROUTE[0].ROUT_QUALITY;
Qual /= 100;
*(ptr1++) = (UCHAR)Qual;
Count--;
}
DEST++;
}
CURRENTNODE = DEST;
Sendit:
Buffer->LENGTH = ptr1 - (UCHAR *)Buffer;
PUT_ON_PORT_Q(PORT, Buffer);
}
VOID L3LINKCLOSED(struct _LINKTABLE * LINK, int Reason)
{
// L2 SESSION HAS SHUT DOWN (PROBABLY DUE TO INACTIVITY)
struct ROUTE * ROUTE;
// CLEAR NEIGHBOUR
ROUTE = LINK->NEIGHBOUR; // TO NEIGHBOUR
if (ROUTE)
{
LINK->NEIGHBOUR = NULL; // Clear links
ROUTE->NEIGHBOUR_LINK = NULL;
CLEARACTIVEROUTE(ROUTE, Reason); // CLEAR ASSOCIATED DEST ENTRIES
}
}
VOID CLEARACTIVEROUTE(struct ROUTE * ROUTE, int Reason)
{
// FIND ANY DESINATIONS WITH [ESI] AS ACTIVE NEIGHBOUR, AND
// SET INACTIVE
dest_list * DEST;
int n;
if (Reason != NORMALCLOSE || ROUTE->INP3Node)
TellINP3LinkGone(ROUTE);
DEST = DESTS;
n = MAXDESTS;
DEST--; // So we can increment at start of loop
while (n--)
{
DEST++;
if (DEST->DEST_ROUTE == 0)
continue;
if (DEST->ROUTE[DEST->DEST_ROUTE].ROUT_NEIGHBOUR == ROUTE) // Is this the active route
{
// Yes, so clear
DEST->DEST_ROUTE = 0; // SET NO ACTIVE ROUTE
}
}
}
VOID L3TimerProc()
{
int i;
struct PORTCONTROL * PORT = PORTTABLE;
struct ROUTE * ROUTE;
struct _LINKTABLE * LINK;
// CHECK FOR EXCESSIVE BUFFERS QUEUED AT LINK LEVEL
if (QCOUNT < 100)
{
LINK = LINKS;
i = MAXLINKS;
while (i--);
{
if (LINK->LINKTYPE == 3) // Only if Internode
{
if (COUNT_AT_L2(LINK) > 50)
{
Debugprintf("Excessive L3 Queue");
L3LINKCLOSED(LINK, LINKSTUCK); // REPORT TO LEVEL 3
CLEAROUTLINK(LINK);
}
}
LINK++;
}
}
STATSTIME++;
if (IDTIMER) // Not if Disabled
{
IDTIMER--;
if (IDTIMER == 0)
{
IDTIMER = IDINTERVAL;
SENDIDMSG();
}
}
// CHECK FOR BEACON
if (BTTIMER) // Not if Disabled
{
BTTIMER--;
if (BTTIMER == 0)
{
BTTIMER = BTINTERVAL;
SENDBTMSG();
}
}
// CHECK FOR NODES BROADCAST
if (L3TIMER) // Not if Disabled
{
L3TIMER--;
if (L3TIMER == 0)
{
// UPDATE DEST LIST AND SEND 'NODES' MESSAGE
L3TIMER = L3INTERVAL;
UPDATEDESTLIST();
SENDNODESMSG();
}
}
// TIDY ROUTES
ROUTE = NEIGHBOURS;
i = MAXNEIGHBOURS;
ROUTE--;
while (i--)
{
ROUTE++;
if (ROUTE->NEIGHBOUR_FLAG & 1) // Locked?
continue;
if (ROUTE->NEIGHBOUR_LINK) // Has an active Session
continue;
if (COUNTNODES(ROUTE) == 0) // NODES USING THIS DESTINATION
{
// IF NUMBER USING ROUTE IS ZERO, DELETE IT
memset(ROUTE, 0, sizeof (struct ROUTE));
}
}
}
VOID L3FastTimer()
{
// CALLED ONCE PER SECOND - USED ONLY TO SEND NEXT PART OF A NODES OR
// ID MESSAGE SEQUENCE
MESSAGE * Msg;
struct PORTCONTROL * PORT ;
INP3TIMER();
L3_10SECS--;
if (L3_10SECS == 0)
{
L3_10SECS = 10;
if (IDMSG_Q) // ID/BEACON TO SEND
{
Msg = Q_REM(&IDMSG_Q);
PORT = GetPortTableEntryFromPortNum(Msg->PORT);
if (PORT && PORT->TXPORT == 0) // DONT SEND IF SHARED TX
PUT_ON_PORT_Q(PORT, Msg);
else
ReleaseBuffer(Msg);
}
if (NODESINPROGRESS)
SENDNEXTNODESFRAGMENT();
}
}
VOID UPDATEDESTLIST()
{
// DECREMENT OBS COUNTERS ON EACH ROUTE, AND REMOVE 'DEAD' ENTRIES
dest_list * DEST;
int n;
DEST = DESTS;
n = MAXDESTS;
DEST--; // So we can increment at start of loop
while (n--)
{
DEST++;