forked from g8bpq/linbpq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HSMODEM.c
1882 lines (1339 loc) · 43.6 KB
/
HSMODEM.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-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
*/
//
// Interface to allow G8BPQ switch to use HSMODEM TNC
#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#include <time.h>
#ifndef WIN32
#ifndef MACBPQ
#include <sys/ioctl.h>
#endif
#endif
#include "CHeaders.h"
#pragma pack(1)
struct BroadcastMsg
{
unsigned char Type;
unsigned char initialVolTX;
unsigned char initialVolRX;
unsigned char AudioTimespan;
unsigned char intialVolSpeaker;
unsigned char initalVolMic;
unsigned char Retransmits;
unsigned char SendAudio;
unsigned char RTTYAutoSync;
unsigned char Speed;
char playbackDevice[100];
char captureDevice[100];
char Callsign[20];
char Locator[10];
char Name[20];
};
struct FileHeader
{
unsigned char Type;
unsigned char Info; // 0 - First, 1 - Continuation 2 Last 3 - Only
char filename[50];
unsigned short CRC; // of filename = transfer id
unsigned char Size[3]; // Big endian
unsigned char Data[164];
};
struct FileData
{
unsigned char Type;
unsigned char Info; // 0 - First, 1 - Continuation 2 Last 3 - Only
unsigned char Data[219];
};
#pragma pack()
struct HSFILEINFO
{
struct HSFILEINFO * Next; // May want to chain entries for partial files
char fileName[50];
unsigned short CRC; // Used as a transfer ID
int fileSize;
int Sequence;
int State;
int Type;
time_t LastRX;
unsigned char goodBlocks[1024];
unsigned char * Data;
int dataPointer;
int lastBlock;
int lostBlocks;
unsigned char * txData;
int txSize;
int txLeft;
};
struct HSMODEMINFO
{
struct HSFILEINFO * File;
int Mode;
char * Capture; // Capture Device Name
char * Playback; // Playback Device Name
int Seq; // To make CRC more Unique
int txFifo;
int rxFifo;
int Sync;
int DCD;
};
int KillTNC(struct TNCINFO * TNC);
int RestartTNC(struct TNCINFO * TNC);
extern int (WINAPI FAR *GetModuleFileNameExPtr)();
extern int (WINAPI FAR *EnumProcessesPtr)();
#include "bpq32.h"
#include "tncinfo.h"
static int Socket_Data(int sock, int error, int eventcode);
VOID MoveWindows(struct TNCINFO * TNC);
static VOID SendToTNC(struct TNCINFO * TNC, int Stream, UCHAR * Encoded, int EncLen);
int ReadCOMBlockEx(HANDLE fd, char * Block, int MaxLength, BOOL * Error);
BOOL HSMODEMWriteCommBlock(struct TNCINFO * TNC);
void HSMODEMCheckRX(struct TNCINFO * TNC);
int HSMODEMSendData(struct TNCINFO * TNC, UCHAR * data, int txlen);
int HSMODEMSendSingleData(struct TNCINFO * TNC, UCHAR * FN, UCHAR * data, int txlen);
int HSMODEMSendCommand(struct TNCINFO * TNC, UCHAR * data);
int DoScanLine(struct TNCINFO * TNC, char * Buff, int Len);
VOID SendInitScript(struct TNCINFO * TNC);
int HSMODEMGetLine(char * buf);
int ProcessEscape(UCHAR * TXMsg);
BOOL KAMStartPort(struct PORTCONTROL * PORT);
BOOL KAMStopPort(struct PORTCONTROL * PORT);
void SendPoll(struct TNCINFO * TNC);
void SendMode(struct TNCINFO * TNC);
static char ClassName[]="HSMODEMSTATUS";
static char WindowTitle[] = "HSMODEM";
static int RigControlRow = 205;
#ifndef LINBPQ
#include <commctrl.h>
#endif
extern int SemHeldByAPI;
static RECT Rect;
static int ProcessLine(char * buf, int Port);
VOID WritetoTrace(struct TNCINFO * TNC, char * Msg, int Len);
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 = TNCInfo[Port];
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->HSModemInfo = zalloc(sizeof(struct HSMODEMINFO));
TNC->HSModemInfo->File = zalloc(sizeof(struct HSFILEINFO));
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->TCPPort = WINMORport;
TNC->destaddr.sin_family = AF_INET;
TNC->destaddr.sin_port = htons(WINMORport + 2); // We only receive on Port + 2
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)
{
DecodePTTString(TNC, ptr);
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);
}
}
// 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)
{
TNC->HSModemInfo->Capture = _strdup(&buf[8]);
strlop(TNC->HSModemInfo->Capture, 13);
}
else if (_memicmp(buf, "PLAYBACK", 8) == 0)
{
TNC->HSModemInfo->Playback = _strdup(&buf[9]);
strlop(TNC->HSModemInfo->Playback, 13);
}
else if (_memicmp(buf, "MODE ", 5) == 0)
TNC->HSModemInfo->Mode = atoi(&buf[5]);
else if (_memicmp(buf, "LOGDIR ", 7) == 0)
TNC->LogPath = _strdup(&buf[7]);
else
strcat (TNC->InitScript, buf);
}
return (TRUE);
}
static char * Config;
static char * ptr1, * ptr2;
int HSMODEMGetLine(char * buf)
{
loop:
if (ptr2 == NULL)
return 0;
memcpy(buf, ptr1, ptr2 - ptr1 + 2);
buf[ptr2 - ptr1 + 2] = 0;
ptr1 = ptr2 + 2;
ptr2 = strchr(ptr1, 13);
if (buf[0] < 0x20) goto loop;
if (buf[0] == '#') goto loop;
if (buf[0] == ';') goto loop;
if (buf[strlen(buf)-1] < 0x20) buf[strlen(buf)-1] = 0;
if (buf[strlen(buf)-1] < 0x20) buf[strlen(buf)-1] = 0;
buf[strlen(buf)] = 13;
return 1;
}
BOOL HSMODEMReadConfigFile(int Port, int ProcLine())
{
char buf[256],errbuf[256];
Config = PortConfig[Port];
if (Config)
{
// Using config from bpq32.cfg
if (strlen(Config) == 0)
{
return TRUE;
}
ptr1 = Config;
ptr2 = strchr(ptr1, 13);
if (!ProcLine(buf, Port))
{
WritetoConsoleLocal("\n");
WritetoConsoleLocal("Bad config record ");
WritetoConsoleLocal(errbuf);
}
}
else
{
sprintf(buf," ** Error - No Configuration info in bpq32.cfg");
WritetoConsoleLocal(buf);
}
return (TRUE);
}
VOID SuspendOtherPorts(struct TNCINFO * ThisTNC);
VOID ReleaseOtherPorts(struct TNCINFO * ThisTNC);
VOID WritetoTrace(struct TNCINFO * TNC, char * Msg, int Len);
static time_t ltime;
static VOID SendToTNC(struct TNCINFO * TNC, int Stream, UCHAR * Encoded, int EncLen)
{
if (TNC->hDevice)
{
// HSMODEM mode. Queue to Hostmode driver
PMSGWITHLEN buffptr = (PMSGWITHLEN)GetBuff();
if (buffptr == 0) return; // No buffers, so ignore
buffptr->Len = EncLen;
memcpy(&buffptr->Data[0], Encoded, EncLen);
C_Q_ADD(&TNC->Streams[Stream].BPQtoPACTOR_Q, buffptr);
TNC->Streams[Stream].FramesQueued++;
return;
}
}
VOID HSMODEMChangeMYC(struct TNCINFO * TNC, char * Call)
{
UCHAR TXMsg[100];
int datalen;
if (strcmp(Call, TNC->CurrentMYC) == 0)
return; // No Change
strcpy(TNC->CurrentMYC, Call);
datalen = sprintf(TXMsg, "MYCALL %s\r", Call);
HSMODEMSendCommand(TNC, TXMsg);
}
static size_t ExtProc(int fn, int port, PDATAMESSAGE buff)
{
int datalen;
PMSGWITHLEN buffptr;
// char txbuff[500];
unsigned int bytes,txlen = 0;
UCHAR * TXMsg;
size_t Param;
int Stream = 0;
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
switch (fn)
{
case 7:
// 100 mS Timer. May now be needed, as Poll can be called more frequently in some circumstances
// G7TAJ's code to record activity for stats display
if ( TNC->BusyFlags && CDBusy )
TNC->PortRecord->PORTCONTROL.ACTIVE += 2;
if ( TNC->PTTState )
TNC->PortRecord->PORTCONTROL.SENDING += 2;
if (TNC->CONNECTED)
{
TNC->CONNECTED--;
if (TNC->CONNECTED == 0)
{
sprintf(TNC->WEB_COMMSSTATE, "Connection to HSMODEM lost");
MySetWindowText(TNC->xIDC_COMMSSTATE, TNC->WEB_COMMSSTATE);
}
}
TNC->PollDelay++;
if (TNC->PollDelay > 20)
{
TNC->PollDelay = 0;
SendPoll(TNC);
}
return 0;
case 1: // poll
HSMODEMCheckRX(TNC);
while (TNC->PortRecord->UI_Q)
{
int datalen;
char * Buffer;
char FECMsg[512];
char Call[12] = " ";
struct _MESSAGE * buffptr;
int CallLen;
char * ptr = FECMsg;
buffptr = Q_REM(&TNC->PortRecord->UI_Q);
/* if (TNC->CONNECTED == 0 ||
TNC->Streams[0].Connecting ||
TNC->Streams[0].Connected)
{
// discard if TNC not connected or sesison active
ReleaseBuffer(buffptr);
continue;
}
*/
datalen = buffptr->LENGTH - MSGHDDRLEN;
Buffer = &buffptr->DEST[0]; // Raw Frame
Buffer[datalen] = 0;
// Frame has ax.25 format header. Convert to Text
CallLen = ConvFromAX25(Buffer + 7, Call); // Origin
memcpy(ptr, Call, CallLen);
ptr += CallLen;
*ptr++ = '!';
CallLen = ConvFromAX25(Buffer, Call); // Dest
memcpy(ptr, Call, CallLen);
ptr += CallLen;
Buffer += 14; // TO Digis
datalen -= 14;
while ((Buffer[-1] & 1) == 0)
{
*ptr++ = ',';
CallLen = ConvFromAX25(Buffer, Call);
memcpy(ptr, Call, CallLen);
ptr += CallLen;
Buffer += 7; // End of addr
datalen -= 7;
}
*ptr++ = '_';
*ptr++ = 'U'; // UI Frame
*ptr++ = 0; // delimit calls
if (Buffer[0] == 3) // UI
{
Buffer += 2;
datalen -= 2;
}
HSMODEMSendSingleData(TNC, FECMsg, Buffer, datalen);
ReleaseBuffer(buffptr);
}
if (TNC->DiscPending)
{
TNC->DiscPending--;
if (TNC->DiscPending == 0)
{
// Too long in Disc Pending - Kill and Restart TNC
}
}
for (Stream = 0; Stream <= 2; Stream++)
{
STREAM = &TNC->Streams[Stream];
if (STREAM->NeedDisc)
{
STREAM->NeedDisc--;
if (STREAM->NeedDisc == 0)
{
// Send the DISCONNECT
HSMODEMSendCommand(TNC, "DISCONNECT\r");
}
}
if (TNC->PortRecord->ATTACHEDSESSIONS[Stream] && STREAM->Attached == 0)
{
// New Attach
int calllen;
char Msg[80];
Debugprintf("HSMODEM New Attach Stream %d", Stream);
STREAM->Attached = TRUE;
calllen = ConvFromAX25(TNC->PortRecord->ATTACHEDSESSIONS[Stream]->L4USER, TNC->Streams[Stream].MyCall);
TNC->Streams[Stream].MyCall[calllen] = 0;
HSMODEMChangeMYC(TNC, TNC->Streams[0].MyCall);
// 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( (TRANSPORTENTRY *) -1, Msg);
}
if (STREAM->Attached)
CheckForDetach(TNC, Stream, STREAM, TidyClose, ForcedClose, CloseComplete);
}
// See if any frames for this port
for (Stream = 0; Stream <= 2; Stream++)
{
STREAM = &TNC->Streams[Stream];
if (STREAM->BPQtoPACTOR_Q)
{
PMSGWITHLEN buffptr = (PMSGWITHLEN)Q_REM(&STREAM->BPQtoPACTOR_Q);
UCHAR * data = &buffptr->Data[0];
STREAM->FramesQueued--;
txlen = (int)buffptr->Len;
STREAM->BytesTXed += txlen;
bytes=HSMODEMSendData(TNC, data, txlen);
WritetoTrace(TNC, data, txlen);
}
if (STREAM->PACTORtoBPQ_Q != 0)
{
buffptr = (PMSGWITHLEN)Q_REM(&STREAM->PACTORtoBPQ_Q);
datalen = (int)buffptr->Len;
buff->PORT = Stream; // Compatibility with Kam Driver
buff->PID = 0xf0;
memcpy(&buff->L2DATA, &buffptr->Data[0], datalen); // Data goes to + 7, but we have an extra byte
datalen += sizeof(void *) + 4;
PutLengthinBuffer(buff, datalen);
ReleaseBuffer(buffptr);
return (1);
}
if (STREAM->ReportDISC) // May need a delay so treat as a counter
{
STREAM->ReportDISC--;
if (STREAM->ReportDISC == 0)
{
buff->PORT = Stream;
// STREAM->Connected = 0;
// STREAM->Attached = 0;
return -1;
}
}
}
return (0);
case 2: // send
Stream = buff->PORT;
if (!TNC->CONNECTED)
{
// Send Error Response
PMSGWITHLEN buffptr = (PMSGWITHLEN)GetBuff();
if (buffptr == 0) return (0); // No buffers, so ignore
buffptr->Len = 21;
memcpy(&buffptr->Data[0], "No Connection to TNC\r", 21);
C_Q_ADD(&TNC->Streams[Stream].PACTORtoBPQ_Q, buffptr);
return 0; // Don't try if not connected
}
STREAM = &TNC->Streams[Stream];
if (TNC->SwallowSignon)
{
TNC->SwallowSignon = FALSE; // Discard *** connected
return 0;
}
txlen = GetLengthfromBuffer(buff) - (MSGHDDRLEN + 1); // 1 as no PID
TXMsg = &buff->L2DATA[0];
TXMsg[txlen] = 0;
// for now just send, but allow sending control
// characters with \\ or ^ escape
if (STREAM->Connected)
{
STREAM->PacketsSent++;
bytes=HSMODEMSendData(TNC, TXMsg, txlen);
TNC->Streams[Stream].BytesOutstanding += bytes; // So flow control works - will be updated by BUFFER response
STREAM->BytesTXed += bytes;
// WritetoTrace(TNC, &buff->L2DATA[0], txlen);
return 1;
}
if (_memicmp(&buff->L2DATA[0], "D\r", 2) == 0 || _memicmp(&buff->L2DATA[0], "BYE\r", 4) == 0)
{
STREAM->ReportDISC = TRUE; // Tell Node
return 0;
}
// See if Local command (eg RADIO)
if (_memicmp(&buff->L2DATA[0], "RADIO ", 6) == 0)
{
sprintf(&buff->L2DATA[0], "%d %s", TNC->Port, &buff->L2DATA[6]);
if (Rig_Command(TNC->PortRecord->ATTACHEDSESSIONS[0]->L4CROSSLINK, &buff->L2DATA[0]))
{
}
else
{
PMSGWITHLEN buffptr = (PMSGWITHLEN)GetBuff();
if (buffptr == 0) return 1; // No buffers, so ignore
buffptr->Len = sprintf((UCHAR *)&buffptr->Data[0], "%s", &buff->L2DATA[0]);
C_Q_ADD(&TNC->Streams[Stream].PACTORtoBPQ_Q, buffptr);
}
return 1;
}
if (_memicmp(&buff->L2DATA[0], "OVERRIDEBUSY", 12) == 0)
{
PMSGWITHLEN buffptr = (PMSGWITHLEN)GetBuff();
TNC->OverrideBusy = TRUE;
if (buffptr)
{
buffptr->Len = sprintf((UCHAR *)&buffptr->Data[0], "HSMODEM} OK\r");
C_Q_ADD(&TNC->Streams[Stream].PACTORtoBPQ_Q, buffptr);
}
return 0;
}
if (_memicmp(&buff->L2DATA[0], "MODE ", 5) == 0)
{
PMSGWITHLEN buffptr = (PMSGWITHLEN)GetBuff();
TNC->HSModemInfo->Mode = atoi(&buff->L2DATA[5]);
if (buffptr)
{
buffptr->Len = sprintf((UCHAR *)&buffptr->Data[0], "HSMODEM} OK\r");
C_Q_ADD(&TNC->Streams[Stream].PACTORtoBPQ_Q, buffptr);
}
SendMode(TNC);
return 0;
}
// See if a Connect Command. If so, start codec and set Connecting
if (toupper(buff->L2DATA[0]) == 'C' && buff->L2DATA[1] == ' ' && txlen > 2) // Connect
{
char Connect[80];
char * ptr = strchr(&buff->L2DATA[2], 13);
if (ptr)
*ptr = 0;
_strupr(&buff->L2DATA[2]);
if (strlen(&buff->L2DATA[2]) > 9)
buff->L2DATA[11] = 0;
txlen = sprintf(Connect, "C %s\r", &buff->L2DATA[2]);
HSMODEMChangeMYC(TNC, TNC->Streams[0].MyCall);
// 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;
memset(TNC->Streams[0].RemoteCall, 0, 10);
strcpy(TNC->Streams[0].RemoteCall, &buff->L2DATA[2]);
sprintf(TNC->WEB_TNCSTATE, "%s Connecting to %s", STREAM->MyCall, STREAM->RemoteCall);
HSMODEMSendCommand(TNC, Connect);
MySetWindowText(TNC->xIDC_TNCSTATE, TNC->WEB_TNCSTATE);
STREAM->Connecting = TRUE;
return 0;
}
// Normal data. Send to TNC
HSMODEMSendData(TNC, TXMsg, txlen);
return 0;
case 3:
// CHECK IF OK TO SEND (And check TNC Status)
Stream = (int)(size_t)buff;
// I think we should check buffer space for all comms modes
{
int Queued;
int Outstanding = TNC->Streams[Stream].BytesOutstanding;
if (Stream == 0)
Queued = TNC->Streams[13].FramesQueued; // ARDOP Native Mode Send Queue
else
Queued = TNC->Streams[Stream].FramesQueued;
Outstanding = Queued = 0;
if (Queued > 4 || Outstanding > 8500)
return (1 | (TNC->HostMode | TNC->CONNECTED) << 8 | STREAM->Disconnecting << 15);
}
if (TNC->Streams[Stream].Attached == 0)
return (TNC->CONNECTED != 0) << 8 | 1;
return ((TNC->CONNECTED != 0) << 8 | TNC->Streams[Stream].Disconnecting << 15); // OK
case 4: // reinit7
return 0;
case 5: // Close
return 0;
case 6: // Scan Stop Interface
Param = (size_t)buff;
if (Param == 2) // Check Permission (Shouldn't happen)
{
Debugprintf("Scan Check Permission called on ARDOP");
return 1; // OK to change
}
if (Param == 1) // Request Permission
{
if (!TNC->CONNECTED)
return 0; // No connection so no interlock
if (TNC->ConnectPending == 0 && TNC->PTTState == 0)
{
HSMODEMSendCommand(TNC, "CONOK OFF");
TNC->GavePermission = TRUE;
return 0; // OK to Change
}
if (TNC->ConnectPending)
TNC->ConnectPending--; // Time out if set too long
return TRUE;
}
if (Param == 3) // Release Permission
{
if (TNC->GavePermission)
{
TNC->GavePermission = FALSE;
if (TNC->ARDOPCurrentMode[0] != 'S') // Skip
HSMODEMSendCommand(TNC, "CONOK ON");
}
return 0;
}
// Param is Address of a struct ScanEntry
Scan = (struct ScanEntry *)buff;
return 0;
}
return 0;
}
VOID HSMODEMReleaseTNC(struct TNCINFO * TNC)
{
// Set mycall back to Node or Port Call, and Start Scanner
UCHAR TXMsg[1000];
HSMODEMChangeMYC(TNC, TNC->NodeCall);
// Start Scanner
sprintf(TXMsg, "%d SCANSTART 15", TNC->Port);
Rig_Command( (TRANSPORTENTRY *) -1, TXMsg);
ReleaseOtherPorts(TNC);
}
VOID HSMODEMSuspendPort(struct TNCINFO * TNC, struct TNCINFO * ThisTNC)
{
HSMODEMSendCommand(TNC, "CONOK OFF\r");
}
VOID HSMODEMReleasePort(struct TNCINFO * TNC)
{
HSMODEMSendCommand(TNC, "CONOK ON\r");
}
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>HSMODEM 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;
}
#ifndef LINBPQ
#define BGCOLOUR RGB(236,233,216)
HBRUSH RedBrush = NULL;
HBRUSH GreenBrush;
HBRUSH BlueBrush;
static HBRUSH bgBrush = NULL;
extern HWND ClientWnd, FrameWnd;
extern int OffsetH, OffsetW;
extern HMENU hMainFrameMenu;
extern HMENU hBaseMenu;
extern HANDLE hInstance;
extern HKEY REGTREE;
static LRESULT CALLBACK PacWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
MINMAXINFO * mmi;
PAINTSTRUCT ps;
HDC hdc;
int i;
struct TNCINFO * TNC;
HKEY hKey;
char Key[80];
int retCode, disp;
for (i=0; i<41; i++)
{
TNC = TNCInfo[i];
if (TNC == NULL)
continue;
if (TNC->hDlg == hWnd)
break;
}
if (TNC == NULL)
return DefMDIChildProc(hWnd, message, wParam, lParam);
switch (message) {
case WM_CREATE:
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
TextOut(hdc, 10, 162, "RX", 4);
TextOut(hdc, 10, 182, "TX", 4);