-
Notifications
You must be signed in to change notification settings - Fork 0
/
VARA.c
2243 lines (1618 loc) · 51.3 KB
/
VARA.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
*/
//
// Interface to allow G8BPQ switch to use VARA Virtual TNC in a form
// of ax.25
#define _CRT_SECURE_NO_DEPRECATE
#define _USE_32BIT_TIME_T
#include <stdio.h>
#include <time.h>
#include "CHeaders.h"
#ifdef WIN32
#include <Psapi.h>
#endif
int (WINAPI FAR *GetModuleFileNameExPtr)();
int (WINAPI FAR *EnumProcessesPtr)();
#define SD_RECEIVE 0x00
#define SD_SEND 0x01
#define SD_BOTH 0x02
#include "bpq32.h"
#include "tncinfo.h"
#define WSA_ACCEPT WM_USER + 1
#define WSA_DATA WM_USER + 2
#define WSA_CONNECT WM_USER + 3
static int Socket_Data(int sock, int error, int eventcode);
int KillTNC(struct TNCINFO * TNC);
int RestartTNC(struct TNCINFO * TNC);
int KillPopups(struct TNCINFO * TNC);
VOID MoveWindows(struct TNCINFO * TNC);
int SendReporttoWL2K(struct TNCINFO * TNC);
char * CheckAppl(struct TNCINFO * TNC, char * Appl);
int DoScanLine(struct TNCINFO * TNC, char * Buff, int Len);
BOOL KillOldTNC(char * Path);
int VARASendData(struct TNCINFO * TNC, UCHAR * Buff, int Len);
VOID VARASendCommand(struct TNCINFO * TNC, char * Buff, BOOL Queue);
VOID VARAProcessDataPacket(struct TNCINFO * TNC, UCHAR * Data, int Length);
#ifndef LINBPQ
BOOL CALLBACK EnumVARAWindowsProc(HWND hwnd, LPARAM lParam);
#endif
static char ClassName[]="VARASTATUS";
static char WindowTitle[] = "VARA";
static int RigControlRow = 165;
#define WINMOR
#define NARROWMODE 21
#define WIDEMODE 22
#ifndef LINBPQ
#include <commctrl.h>
#endif
extern char * PortConfig[33];
extern int SemHeldByAPI;
static RECT Rect;
struct TNCINFO * TNCInfo[34]; // Records are Malloc'd
static int ProcessLine(char * buf, int Port);
unsigned long _beginthread( void( *start_address )(), unsigned stack_size, int arglist);
// RIGCONTROL COM60 19200 ICOM IC706 5e 4 14.103/U1w 14.112/u1 18.1/U1n 10.12/l1
static int ProcessLine(char * buf, int Port)
{
UCHAR * ptr,* p_cmd;
char * p_ipad = 0;
char * p_port = 0;
unsigned short WINMORport = 0;
int BPQport;
int len=510;
struct TNCINFO * TNC;
char errbuf[256];
strcpy(errbuf, buf);
ptr = strtok(buf, " \t\n\r");
if(ptr == NULL) return (TRUE);
if(*ptr =='#') return (TRUE); // comment
if(*ptr ==';') return (TRUE); // comment
if (_stricmp(buf, "ADDR"))
return FALSE; // Must start with ADDR
ptr = strtok(NULL, " \t\n\r");
BPQport = Port;
p_ipad = ptr;
TNC = TNCInfo[BPQport] = malloc(sizeof(struct TNCINFO));
memset(TNC, 0, sizeof(struct TNCINFO));
TNC->InitScript = malloc(1000);
TNC->InitScript[0] = 0;
if (p_ipad == NULL)
p_ipad = strtok(NULL, " \t\n\r");
if (p_ipad == NULL) return (FALSE);
p_port = strtok(NULL, " \t\n\r");
if (p_port == NULL) return (FALSE);
WINMORport = atoi(p_port);
TNC->destaddr.sin_family = AF_INET;
TNC->destaddr.sin_port = htons(WINMORport);
TNC->Datadestaddr.sin_family = AF_INET;
TNC->Datadestaddr.sin_port = htons(WINMORport+1);
TNC->HostName = malloc(strlen(p_ipad)+1);
if (TNC->HostName == NULL) return TRUE;
strcpy(TNC->HostName,p_ipad);
ptr = strtok(NULL, " \t\n\r");
if (ptr)
{
if (_stricmp(ptr, "PTT") == 0)
{
ptr = strtok(NULL, " \t\n\r");
if (ptr)
{
if (_stricmp(ptr, "CI-V") == 0)
TNC->PTTMode = PTTCI_V;
else if (_stricmp(ptr, "CAT") == 0)
TNC->PTTMode = PTTCI_V;
else if (_stricmp(ptr, "RTS") == 0)
TNC->PTTMode = PTTRTS;
else if (_stricmp(ptr, "DTR") == 0)
TNC->PTTMode = PTTDTR;
else if (_stricmp(ptr, "DTRRTS") == 0)
TNC->PTTMode = PTTDTR | PTTRTS;
else if (_stricmp(ptr, "CM108") == 0)
TNC->PTTMode = PTTCM108;
ptr = strtok(NULL, " \t\n\r");
}
}
}
if (ptr)
{
if (_memicmp(ptr, "PATH", 4) == 0)
{
p_cmd = strtok(NULL, "\n\r");
if (p_cmd) TNC->ProgramPath = _strdup(p_cmd);
// if (p_cmd) TNC->ProgramPath = _strdup(_strupr(p_cmd));
}
}
TNC->MaxConReq = 10; // Default
// Read Initialisation lines
while(TRUE)
{
if (GetLine(buf) == 0)
return TRUE;
strcpy(errbuf, buf);
if (memcmp(buf, "****", 4) == 0)
return TRUE;
ptr = strchr(buf, ';');
if (ptr)
{
*ptr++ = 13;
*ptr = 0;
}
if ((_memicmp(buf, "CAPTURE", 7) == 0) || (_memicmp(buf, "PLAYBACK", 8) == 0))
{} // Ignore
else
/*
if (_memicmp(buf, "PATH", 4) == 0)
{
char * Context;
p_cmd = strtok_s(&buf[5], "\n\r", &Context);
if (p_cmd) TNC->ProgramPath = _strdup(p_cmd);
}
else
*/
if (_memicmp(buf, "WL2KREPORT", 10) == 0)
TNC->WL2K = DecodeWL2KReportLine(buf);
else
if (_memicmp(buf, "BUSYHOLD", 8) == 0) // Hold Time for Busy Detect
TNC->BusyHold = atoi(&buf[8]);
else
if (_memicmp(buf, "BUSYWAIT", 8) == 0) // Wait time beofre failing connect if busy
TNC->BusyWait = atoi(&buf[8]);
else
if (_memicmp(buf, "MAXCONREQ", 9) == 0) // Hold Time for Busy Detect
TNC->MaxConReq = atoi(&buf[9]);
else
if (_memicmp(buf, "STARTINROBUST", 13) == 0)
TNC->StartInRobust = TRUE;
else
if (_memicmp(buf, "ROBUST", 6) == 0)
{
if (_memicmp(&buf[7], "TRUE", 4) == 0)
TNC->Robust = TRUE;
strcat (TNC->InitScript, buf);
}
else
strcat (TNC->InitScript, buf);
}
return (TRUE);
}
void VARAThread(int port);
VOID VARAProcessDataSocketData(int port);
int ConnecttoVARA();
VOID VARAProcessReceivedData(struct TNCINFO * TNC);
VOID VARAProcessReceivedControl(struct TNCINFO * TNC);
VOID VARAReleaseTNC(struct TNCINFO * TNC);
VOID SuspendOtherPorts(struct TNCINFO * ThisTNC);
VOID ReleaseOtherPorts(struct TNCINFO * ThisTNC);
VOID WritetoTrace(struct TNCINFO * TNC, char * Msg, int Len);
#define MAXBPQPORTS 32
static time_t ltime;
static SOCKADDR_IN sinx;
static SOCKADDR_IN rxaddr;
static int addrlen=sizeof(sinx);
static int ExtProc(int fn, int port,unsigned char * buff)
{
int datalen;
UINT * buffptr;
char txbuff[500];
unsigned int bytes,txlen=0;
int Param;
HKEY hKey=0;
struct TNCINFO * TNC = TNCInfo[port];
struct STREAMINFO * STREAM = &TNC->Streams[0];
struct ScanEntry * Scan;
if (TNC == NULL)
return 0; // Port not defined
if (TNC->CONNECTED == 0)
{
// clear Q if not connected
while(TNC->BPQtoWINMOR_Q)
{
buffptr = Q_REM(&TNC->BPQtoWINMOR_Q);
if (buffptr)
ReleaseBuffer(buffptr);
}
}
switch (fn)
{
case 1: // poll
while (TNC->PortRecord->UI_Q)
{
buffptr = Q_REM(&TNC->PortRecord->UI_Q);
ReleaseBuffer(buffptr);
}
if (TNC->Busy) // Count down to clear
{
if ((TNC->BusyFlags & CDBusy) == 0) // TNC Has reported not busy
{
TNC->Busy--;
if (TNC->Busy == 0)
SetWindowText(TNC->xIDC_CHANSTATE, "Clear");
strcpy(TNC->WEB_CHANSTATE, "Clear");
}
}
if (TNC->BusyDelay)
{
// Still Busy?
if (InterlockedCheckBusy(TNC) == FALSE)
{
// No, so send
VARASendCommand(TNC, TNC->ConnectCmd, TRUE);
TNC->Streams[0].Connecting = TRUE;
memset(TNC->Streams[0].RemoteCall, 0, 10);
memcpy(TNC->Streams[0].RemoteCall, &TNC->ConnectCmd[8], strlen(TNC->ConnectCmd)-10);
sprintf(TNC->WEB_TNCSTATE, "%s Connecting to %s", TNC->Streams[0].MyCall, TNC->Streams[0].RemoteCall);
SetWindowText(TNC->xIDC_TNCSTATE, TNC->WEB_TNCSTATE);
free(TNC->ConnectCmd);
TNC->BusyDelay = 0;
}
else
{
// Wait Longer
TNC->BusyDelay--;
if (TNC->BusyDelay == 0)
{
// Timed out - Send Error Response
UINT * buffptr = GetBuff();
if (buffptr == 0) return (0); // No buffers, so ignore
buffptr[1]=39;
memcpy(buffptr+2,"Sorry, Can't Connect - Channel is busy\r", 39);
C_Q_ADD(&TNC->WINMORtoBPQ_Q, buffptr);
free(TNC->ConnectCmd);
sprintf(TNC->WEB_TNCSTATE, "In Use by %s", TNC->Streams[0].MyCall);
SetWindowText(TNC->xIDC_TNCSTATE, TNC->WEB_TNCSTATE);
}
}
}
if (TNC->HeartBeat++ > 600) // Every Minute {
{
TNC->HeartBeat = 0;
if (TNC->CONNECTED)
{
// Probe link
if (TNC->Streams[0].Connecting || TNC->Streams[0].Connected)
{}
else
VARASendCommand(TNC, "STATE\r", TRUE);
}
}
// FECPending can be set if not in FEC Mode (eg beacon)
if (TNC->FECPending) // Check if FEC Send needed
{
if (TNC->Streams[0].BytesOutstanding) //Wait for data to be queued (async data session)
{
if (!TNC->Busy)
{
TNC->FECPending = 0;
// VARASendCommand(TNC,"FECSEND TRUE", TRUE);
}
}
}
if (STREAM->NeedDisc)
{
STREAM->NeedDisc--;
if (STREAM->NeedDisc == 0)
{
// Send the DISCONNECT
VARASendCommand(TNC, "DISCONNECT\r", TRUE);
}
}
if (TNC->DiscPending)
{
TNC->DiscPending--;
if (TNC->DiscPending == 0)
{
// Too long in Disc Pending - Kill and Restart TNC
if (TNC->PID)
KillTNC(TNC);
RestartTNC(TNC);
}
}
if (TNC->TimeSinceLast++ > 800) // Allow 10 secs for Keepalive
{
// Restart TNC
TNC->TimeSinceLast = 0;
if (TNC->CONNECTED && TNC->ProgramPath)
{
// if (strstr(TNC->ProgramPath, "WINMOR TNC"))
{
struct tm * tm;
char Time[80];
TNC->Restarts++;
TNC->LastRestart = time(NULL);
tm = gmtime(&TNC->LastRestart);
sprintf_s(Time, sizeof(Time),"%04d/%02d/%02d %02d:%02dZ",
tm->tm_year +1900, tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min);
MySetWindowText(TNC->xIDC_RESTARTTIME, Time);
strcpy(TNC->WEB_RESTARTTIME, Time);
sprintf_s(Time, sizeof(Time),"%d", TNC->Restarts);
MySetWindowText(TNC->xIDC_RESTARTS, Time);
strcpy(TNC->WEB_RESTARTS, Time);
KillTNC(TNC);
RestartTNC(TNC);
}
}
}
if (TNC->PortRecord->ATTACHEDSESSIONS[0] && TNC->Streams[0].Attached == 0)
{
// New Attach
int calllen;
char Msg[80];
TNC->Streams[0].Attached = TRUE;
calllen = ConvFromAX25(TNC->PortRecord->ATTACHEDSESSIONS[0]->L4USER, TNC->Streams[0].MyCall);
TNC->Streams[0].MyCall[calllen] = 0;
// Stop Listening, and set MYCALL to user's call
VARASendCommand(TNC, "LISTEN OFF\r", TRUE);
// Stop other ports in same group
SuspendOtherPorts(TNC);
sprintf(TNC->WEB_TNCSTATE, "In Use by %s", TNC->Streams[0].MyCall);
MySetWindowText(TNC->xIDC_TNCSTATE, TNC->WEB_TNCSTATE);
// Stop Scanning
sprintf(Msg, "%d SCANSTOP", TNC->Port);
Rig_Command(-1, Msg);
}
if (TNC->Streams[0].Attached)
CheckForDetach(TNC, 0, &TNC->Streams[0], TidyClose, ForcedClose, CloseComplete);
if (TNC->Streams[0].ReportDISC)
{
TNC->Streams[0].ReportDISC = FALSE;
buff[4] = 0;
return -1;
}
if (TNC->CONNECTED == FALSE && TNC->CONNECTING == FALSE)
{
// See if time to reconnect
time(<ime);
if (ltime - TNC->lasttime > 9 )
{
TNC->lasttime = ltime;
ConnecttoVARA(port);
}
}
// See if any frames for this port
if (TNC->Streams[0].BPQtoPACTOR_Q) //Used for CTEXT
{
UINT * buffptr = Q_REM(&TNC->Streams[0].BPQtoPACTOR_Q);
txlen=buffptr[1];
memcpy(txbuff,buffptr+2,txlen);
bytes = VARASendData(TNC, &txbuff[0], txlen);
STREAM->BytesTXed += bytes;
ReleaseBuffer(buffptr);
}
if (TNC->WINMORtoBPQ_Q != 0)
{
buffptr=Q_REM(&TNC->WINMORtoBPQ_Q);
datalen=buffptr[1];
buff[4] = 0; // Compatibility with Kam Driver
buff[7] = 0xf0;
memcpy(&buff[8],buffptr+2,datalen); // Data goes to +7, but we have an extra byte
datalen+=8;
buff[5]=(datalen & 0xff);
buff[6]=(datalen >> 8);
ReleaseBuffer(buffptr);
return (1);
}
return (0);
case 2: // send
if (!TNC->CONNECTED)
{
// Send Error Response
UINT * buffptr = GetBuff();
if (buffptr == 0) return (0); // No buffers, so ignore
buffptr[1]=36;
memcpy(buffptr+2,"No Connection to VARA TNC\r", 36);
C_Q_ADD(&TNC->WINMORtoBPQ_Q, buffptr);
return 0; // Don't try if not connected
}
if (TNC->Streams[0].BPQtoPACTOR_Q) //Used for CTEXT
{
UINT * buffptr = Q_REM(&TNC->Streams[0].BPQtoPACTOR_Q);
txlen=buffptr[1];
memcpy(txbuff,buffptr+2,txlen);
bytes=send(TNC->TCPDataSock,(const char FAR *)&buff[8],txlen,0);
STREAM->BytesTXed += bytes;
WritetoTrace(TNC, txbuff, txlen);
ReleaseBuffer(buffptr);
}
if (TNC->SwallowSignon)
{
TNC->SwallowSignon = FALSE; // Discard *** connected
return 0;
}
txlen=(buff[6]<<8) + buff[5]-8;
if (TNC->Streams[0].Connected)
{
STREAM->PacketsSent++;
if (STREAM->PacketsSent == 3)
{
// if (TNC->Robust)
// ARDOPSendCommand(TNC, "ROBUST TRUE");
// else
// ARDOPSendCommand(TNC, "ROBUST FALSE");
}
bytes=send(TNC->TCPDataSock,(const char FAR *)&buff[8],txlen,0);
STREAM->BytesTXed += bytes;
WritetoTrace(TNC, &buff[8], txlen);
}
else
{
if (_memicmp(&buff[8], "D\r", 2) == 0 || _memicmp(&buff[8], "BYE\r", 4) == 0)
{
TNC->Streams[0].ReportDISC = TRUE; // Tell Node
return 0;
}
// See if Local command (eg RADIO)
if (_memicmp(&buff[8], "RADIO ", 6) == 0)
{
sprintf(&buff[8], "%d %s", TNC->Port, &buff[14]);
if (Rig_Command(TNC->PortRecord->ATTACHEDSESSIONS[0]->L4CROSSLINK->CIRCUITINDEX, &buff[8]))
{
}
else
{
UINT * buffptr = GetBuff();
if (buffptr == 0) return 1; // No buffers, so ignore
buffptr[1] = sprintf((UCHAR *)&buffptr[2], "%s", &buff[8]);
C_Q_ADD(&TNC->WINMORtoBPQ_Q, buffptr);
}
return 1;
}
if (_memicmp(&buff[8], "OVERRIDEBUSY", 12) == 0)
{
UINT * buffptr = GetBuff();
TNC->OverrideBusy = TRUE;
if (buffptr)
{
buffptr[1] = sprintf((UCHAR *)&buffptr[2], "VARA} OK\r");
C_Q_ADD(&TNC->WINMORtoBPQ_Q, buffptr);
}
return 0;
}
if (_memicmp(&buff[8], "MAXCONREQ", 9) == 0)
{
if (buff[17] != 13)
{
UINT * buffptr = GetBuff();
// Limit connects
int tries = atoi(&buff[18]);
if (tries > 10) tries = 10;
TNC->MaxConReq = tries;
if (buffptr)
{
buffptr[1] = sprintf((UCHAR *)&buffptr[2], "VARA} OK\r");
C_Q_ADD(&TNC->WINMORtoBPQ_Q, buffptr);
}
return 0;
}
}
if (_memicmp(&buff[8], "ARQBW ", 6) == 0)
TNC->WinmorCurrentMode = 0; // So scanner will set next value
if (_memicmp(&buff[8], "CODEC TRUE", 9) == 0)
TNC->StartSent = TRUE;
if (_memicmp(&buff[8], "D\r", 2) == 0)
{
TNC->Streams[0].ReportDISC = TRUE; // Tell Node
return 0;
}
// See if a Connect Command. If so set Connecting
if (toupper(buff[8]) == 'C' && buff[9] == ' ' && txlen > 2) // Connect
{
char Connect[80];
char * ptr = strchr(&buff[10], 13);
if (ptr)
*ptr = 0;
_strupr(&buff[10]);
sprintf(Connect, "CONNECT %s %s\r", TNC->Streams[0].MyCall, &buff[10]);
// See if Busy
if (InterlockedCheckBusy(TNC))
{
// Channel Busy. Unless override set, wait
if (TNC->OverrideBusy == 0)
{
// Save Command, and wait up to 10 secs
sprintf(TNC->WEB_TNCSTATE, "Waiting for clear channel");
MySetWindowText(TNC->xIDC_TNCSTATE, TNC->WEB_TNCSTATE);
TNC->ConnectCmd = _strdup(Connect);
TNC->BusyDelay = TNC->BusyWait * 10; // BusyWait secs
return 0;
}
}
TNC->OverrideBusy = FALSE;
VARASendCommand(TNC, Connect, TRUE);
TNC->Streams[0].Connecting = TRUE;
memset(TNC->Streams[0].RemoteCall, 0, 10);
strcpy(TNC->Streams[0].RemoteCall, &buff[10]);
sprintf(TNC->WEB_TNCSTATE, "%s Connecting to %s", TNC->Streams[0].MyCall, TNC->Streams[0].RemoteCall);
MySetWindowText(TNC->xIDC_TNCSTATE, TNC->WEB_TNCSTATE);
}
else
{
buff[7 + txlen++] = 13;
buff[7 + txlen] = 0;
VARASendCommand(TNC, &buff[8], TRUE);
}
}
return (0);
case 3:
// CHECK IF OK TO SEND (And check TNC Status)
if (TNC->Streams[0].Attached == 0)
return TNC->CONNECTED << 8 | 1;
return (TNC->CONNECTED << 8 | TNC->Streams[0].Disconnecting << 15); // OK
case 4: // reinit
shutdown(TNC->TCPSock, SD_BOTH);
Sleep(100);
closesocket(TNC->TCPSock);
if (TNC->PID && TNC->WeStartedTNC)
{
KillTNC(TNC);
RestartTNC(TNC);
}
return 0;
case 5: // Close
if (TNC->CONNECTED)
{
// GetSemaphore(&Semaphore, 52);
// VARASendCommand(TNC, "CLOSE", FALSE);
// FreeSemaphore(&Semaphore);
// Sleep(100);
}
shutdown(TNC->TCPSock, SD_BOTH);
Sleep(100);
closesocket(TNC->TCPSock);
if (TNC->WeStartedTNC)
KillTNC(TNC);
return 0;
case 6: // Scan Stop Interface
Param = (int)buff;
if (Param == 1) // Request Permission
{
if (TNC->ConnectPending)
TNC->ConnectPending--; // Time out if set too long
if (!TNC->ConnectPending)
return 0; // OK to Change
VARASendCommand(TNC, "LISTEN OFF\r", TRUE);
return TRUE;
}
if (Param == 2) // Check Permission
{
if (TNC->ConnectPending)
{
TNC->ConnectPending--;
return -1; // Skip Interval
}
return 1; // OK to change
}
if (Param == 3) // Release Permission
{
VARASendCommand(TNC, "LISTEN ON\r", TRUE);
return 0;
}
// Param is Address of a struct ScanEntry
Scan = (struct ScanEntry *)buff;
if (strcmp(Scan->ARDOPMode, TNC->ARDOPCurrentMode) != 0)
{
// Mode changed
char CMD[32];
strcpy(TNC->ARDOPCurrentMode, Scan->ARDOPMode);
if (Scan->ARDOPMode[0] == 'S') // SKIP - Dont Allow Connects
{
if (TNC->ARDOPCurrentMode[0] != 0)
{
VARASendCommand(TNC, "LISTEN OFF\r", TRUE);
TNC->ARDOPCurrentMode[0] = 0;
}
TNC->WL2KMode = 0;
return 0;
}
else
{
if (TNC->ARDOPCurrentMode[0] == 0)
VARASendCommand(TNC, "LISTEN ON\r", TRUE);
}
if (strchr(Scan->ARDOPMode, 'F'))
sprintf(CMD, "ARQBW %sORCED", Scan->ARDOPMode);
else
sprintf(CMD, "ARQBW %sAX", Scan->ARDOPMode);
return 0;
}
return 0;
}
return 0;
}
static int WebProc(struct TNCINFO * TNC, char * Buff, BOOL LOCAL)
{
int Len = sprintf(Buff, "<html><meta http-equiv=expires content=0><meta http-equiv=refresh content=15>"
"<script type=\"text/javascript\">\r\n"
"function ScrollOutput()\r\n"
"{var textarea = document.getElementById('textarea');"
"textarea.scrollTop = textarea.scrollHeight;}</script>"
"</head><title>VARA Status</title></head><body id=Text onload=\"ScrollOutput()\">"
"<h2><form method=post target=\"POPUPW\" onsubmit=\"POPUPW = window.open('about:blank','POPUPW',"
"'width=440,height=150');\" action=ARDOPAbort?%d>VARA Status"
"<input name=Save value=\"Abort Session\" type=submit style=\"position: absolute; right: 20;\"></form></h2>",
TNC->Port);
Len += sprintf(&Buff[Len], "<table style=\"text-align: left; width: 500px; font-family: monospace; align=center \" border=1 cellpadding=2 cellspacing=2>");
Len += sprintf(&Buff[Len], "<tr><td width=110px>Comms State</td><td>%s</td></tr>", TNC->WEB_COMMSSTATE);
Len += sprintf(&Buff[Len], "<tr><td>TNC State</td><td>%s</td></tr>", TNC->WEB_TNCSTATE);
Len += sprintf(&Buff[Len], "<tr><td>Mode</td><td>%s</td></tr>", TNC->WEB_MODE);
Len += sprintf(&Buff[Len], "<tr><td>Channel State</td><td>%s</td></tr>", TNC->WEB_CHANSTATE);
Len += sprintf(&Buff[Len], "<tr><td>Proto State</td><td>%s</td></tr>", TNC->WEB_PROTOSTATE);
Len += sprintf(&Buff[Len], "<tr><td>Traffic</td><td>%s</td></tr>", TNC->WEB_TRAFFIC);
// Len += sprintf(&Buff[Len], "<tr><td>TNC Restarts</td><td></td></tr>", TNC->WEB_RESTARTS);
Len += sprintf(&Buff[Len], "</table>");
Len += sprintf(&Buff[Len], "<textarea rows=10 style=\"width:500px; height:250px;\" id=textarea >%s</textarea>", TNC->WebBuffer);
Len = DoScanLine(TNC, Buff, Len);
return Len;
}
VOID VARASuspendPort(struct TNCINFO * TNC)
{
VARASendCommand(TNC, "LISTEN OFF\r", TRUE);
}
VOID VARAReleasePort(struct TNCINFO * TNC)
{
VARASendCommand(TNC, "LISTEN ON\r", TRUE);
}
UINT VARAExtInit(EXTPORTDATA * PortEntry)
{
int i, port;
char Msg[255];
char * ptr;
APPLCALLS * APPL;
struct TNCINFO * TNC;
int AuxCount = 0;
char Appl[11];
char * TempScript;
struct PORTCONTROL * PORT = &PortEntry->PORTCONTROL;
//
// Will be called once for each VARA port
//
// The Socket to connect to is in IOBASE
//
port = PortEntry->PORTCONTROL.PORTNUMBER;
ReadConfigFile(port, ProcessLine);
TNC = TNCInfo[port];
if (TNC == NULL)
{
// Not defined in Config file
sprintf(Msg," ** Error - no info in BPQ32.cfg for this port\n");
WritetoConsole(Msg);
return (int) ExtProc;
}
TNC->Port = port;
TNC->ARDOPBuffer = malloc(8192);
TNC->ARDOPDataBuffer = malloc(8192);
if (TNC->ProgramPath)
TNC->WeStartedTNC = RestartTNC(TNC);
TNC->Hardware = H_VARA;
if (TNC->BusyWait == 0)
TNC->BusyWait = 10;
if (TNC->BusyHold == 0)
TNC->BusyHold = 1;
TNC->PortRecord = PortEntry;
if (PortEntry->PORTCONTROL.PORTCALL[0] == 0)
memcpy(TNC->NodeCall, MYNODECALL, 10);
else
ConvFromAX25(&PortEntry->PORTCONTROL.PORTCALL[0], TNC->NodeCall);
TNC->Interlock = PortEntry->PORTCONTROL.PORTINTERLOCK;
PortEntry->PORTCONTROL.PROTOCOL = 10;
PortEntry->PORTCONTROL.PORTQUALITY = 0;
PortEntry->MAXHOSTMODESESSIONS = 1;
PortEntry->SCANCAPABILITIES = SIMPLE; // Scan Control - pending connect only
PortEntry->PORTCONTROL.UICAPABLE = FALSE;
if (PortEntry->PORTCONTROL.PORTPACLEN == 0)
PortEntry->PORTCONTROL.PORTPACLEN = 236;
TNC->SuspendPortProc = VARASuspendPort;
TNC->ReleasePortProc = VARAReleasePort;
TNC->ModemCentre = 1500; // WINMOR is always 1500 Offset
ptr=strchr(TNC->NodeCall, ' ');
if (ptr) *(ptr) = 0; // Null Terminate
// Set Essential Params and MYCALL
// Put overridable ones on front, essential ones on end
TempScript = zalloc(1000);
// strcat(TempScript, "ROBUST False\r");
// Set MYCALL
sprintf(Msg, "MYCALL %s", TNC->NodeCall);
for (i = 0; i < 32; i++)
{
APPL=&APPLCALLTABLE[i];
if (APPL->APPLCALL_TEXT[0] > ' ')
{
char * ptr;
memcpy(Appl, APPL->APPLCALL_TEXT, 10);
ptr=strchr(Appl, ' ');