diff options
| author | Dave Hibberd <hibby@debian.org> | 2025-03-31 00:53:37 +0100 |
|---|---|---|
| committer | Dave Hibberd <hibby@debian.org> | 2025-05-21 21:32:18 +0100 |
| commit | d3b4158645e6e3f1454281f68f1a89b946aef552 (patch) | |
| tree | e1fa7ce3f7b3942e39b0ce578900fd18364eeef3 | |
| parent | fec78cece5eb05c5f9ab7d9684bd66a6652edaaa (diff) | |
New upstream version 6.0.24.69+repack
| -rw-r--r-- | BBSHTMLConfig.c | 30 | ||||
| -rw-r--r-- | BBSUtilities.c | 52 | ||||
| -rw-r--r-- | BPQMail.aps | bin | 0 -> 92636 bytes | |||
| -rw-r--r-- | BPQMail.c | 11 | ||||
| -rw-r--r-- | BPQMail.rc | 1090 | ||||
| -rw-r--r-- | FBBRoutines.c | 191 | ||||
| -rw-r--r-- | FLDigi64.c | 7720 | ||||
| -rw-r--r-- | HALDriver64.c | 3814 | ||||
| -rw-r--r-- | HFCommon.c | 3 | ||||
| -rw-r--r-- | LinBPQ.c | 6 | ||||
| -rw-r--r-- | MULTIPSK64.c | 3086 | ||||
| -rw-r--r-- | MultiConsole.c | 3 | ||||
| -rw-r--r-- | SCSTrackeMulti64.c | 3428 | ||||
| -rw-r--r-- | Versions.h | 4 | ||||
| -rw-r--r-- | WebMail.c | 172 | ||||
| -rw-r--r-- | WinRPR.c | 3 | ||||
| -rw-r--r-- | bpqmail.h | 10 | ||||
| -rw-r--r-- | templatedefs.c | 3 |
18 files changed, 9841 insertions, 9785 deletions
diff --git a/BBSHTMLConfig.c b/BBSHTMLConfig.c index 6207298..027c786 100644 --- a/BBSHTMLConfig.c +++ b/BBSHTMLConfig.c @@ -117,6 +117,7 @@ struct UserInfo * FindBBS(char * Name); void ReleaseWebMailStruct(WebMailInfo * WebMail);
VOID TidyWelcomeMsg(char ** pPrompt);
int MailAPIProcessHTTPMessage(struct HTTPConnectionInfo * Session, char * response, char * Method, char * URL, char * request, BOOL LOCAL, char * Param, char * Token);
+void UndoTransparency(char * input);
char UNC[] = "";
char CHKD[] = "checked=checked ";
@@ -186,7 +187,7 @@ char RefreshMainPage[] = "<html><head>" char StatusPage [] =
"<form style=\"font-family: monospace; text-align: center\" method=post action=/Mail/DisSession?%s>"
-"<br>User Callsign Stream Queue<br>"
+"<br>User Callsign Stream Queue Sent Rxed<br>"
"<select style=\"font-family: monospace;\" tabindex=1 size=10 name=call>";
char StreamEnd[] =
@@ -1701,6 +1702,8 @@ VOID ProcessConfUpdate(struct HTTPConnectionInfo * Session, char * MsgPtr, char free(Filters);
Filters = NULL;
+ UndoTransparency(input);
+
while (input)
{
// extract and validate before saving
@@ -1714,7 +1717,7 @@ VOID ProcessConfUpdate(struct HTTPConnectionInfo * Session, char * MsgPtr, char input = strstr(input, "&Type=");
- if (Filter.Action == 'H' || Filter.Action == 'R')
+ if (Filter.Action == 'H' || Filter.Action == 'R' || Filter.Action == 'A')
{
Filter.Type = toupper(input[6]);
input = strstr(input, "&From=");
@@ -2755,6 +2758,19 @@ VOID SendUIPage(char * Reply, int * ReplyLen, char * Key) *ReplyLen = Len;
}
+void ConvertSpaceTonbsp(char * msg)
+{
+ // Replace any space with
+
+ char * ptr;
+
+ while (ptr = strchr(msg, ' '))
+ {
+ memmove(ptr + 5, ptr, strlen(ptr) + 1);
+ memcpy(ptr, " ", 6);
+ }
+}
+
VOID SendStatusPage(char * Reply, int * ReplyLen, char * Key)
{
int Len;
@@ -2777,6 +2793,8 @@ VOID SendStatusPage(char * Reply, int * ReplyLen, char * Key) {
strcpy(msg,"Idle "
" "
+ " "
+ " "
" \r\n");
}
else
@@ -2789,16 +2807,16 @@ VOID SendStatusPage(char * Reply, int * ReplyLen, char * Key) strcpy(Name, conn->UserPointer->Name);
Name[9] = 0;
- i=sprintf_s(msg, sizeof(msg), "%s%s%s%s%2d %5d\r\n",
+ i=sprintf_s(msg, sizeof(msg), "%-12s %-9s %3d %6d%6d%6d\r\n",
Name,
- &TenSpaces[strlen(Name) * 6],
conn->UserPointer->Call,
- &TenSpaces[strlen(conn->UserPointer->Call) * 6],
conn->BPQStream,
- conn->OutputQueueLength - conn->OutputGetPointer);
+ conn->OutputQueueLength - conn->OutputGetPointer, conn->bytesSent, conn->bytesRxed);
}
}
}
+
+ ConvertSpaceTonbsp(msg);
Len += sprintf(&Reply[Len], StatusLine, conn->BPQStream, msg);
}
diff --git a/BBSUtilities.c b/BBSUtilities.c index 1f6159e..efba62a 100644 --- a/BBSUtilities.c +++ b/BBSUtilities.c @@ -2085,6 +2085,7 @@ hold certain types or sizes of messages. The first letter of each valid line specifies the action :
+A = Accept : Message is accepted without checking other filters
R = Reject : The message will not be received.
H = Hold : The message will be received but held until the sysop reviews.
L = Local Hold : Only messages created on this BBS will be held.
@@ -2179,21 +2180,38 @@ BOOL CheckRejFilters(char * From, char * To, char * ATBBS, char * BID, char Type while (p)
{
- if (p->Action != 'R')
+ if (p->Action != 'R' && p->Action != 'A')
goto Continue;
if (p->Type != Type && p->Type != '*')
goto Continue;
+ // wildcardcompare returns true on a match
+
if (wildcardcompare(From, p->From) == 0)
goto Continue;
- if (wildcardcompare(ToCopy, p->TO) == 0)
- goto Continue;
+ if (p->TO[0] == '!')
+ {
+ if (wildcardcompare(ToCopy, &p->TO[1]) == 1)
+ goto Continue;
+ }
+ else
+ {
+ if (wildcardcompare(ToCopy, p->TO) == 0)
+ goto Continue;
+ }
if (ATBBS)
- if (wildcardcompare(ATBBS, p->AT) == 0)
+ {
+ char AtCopy[256];
+
+ strcpy(AtCopy, ATBBS);
+ _strupr(AtCopy);
+
+ if (wildcardcompare(AtCopy, p->AT) == 0)
goto Continue;
+ }
if (BID)
if (wildcardcompare(BID, p->BID) == 0)
@@ -2202,6 +2220,11 @@ BOOL CheckRejFilters(char * From, char * To, char * ATBBS, char * BID, char Type if (p->MaxLen && Len < p->MaxLen)
goto Continue;
+ // if type 'A' matches all rules then accept without checking rest
+
+ if (p->Action == 'A')
+ return FALSE;
+
return TRUE; // Hold
Continue:
@@ -2244,6 +2267,7 @@ BOOL CheckHoldFilters(struct MsgInfo * Msg, char * From, char * To, char * ATBBS {
char ** Calls;
FBBFilter * p = Filters;
+ char ToCopy[256];
if (HoldFrom && From)
{
@@ -2307,6 +2331,9 @@ BOOL CheckHoldFilters(struct MsgInfo * Msg, char * From, char * To, char * ATBBS // check fbb reject.sys type filters
+ strcpy(ToCopy, To);
+ _strupr(ToCopy);
+
while (p)
{
if (p->Action != 'H')
@@ -2318,9 +2345,16 @@ BOOL CheckHoldFilters(struct MsgInfo * Msg, char * From, char * To, char * ATBBS if (wildcardcompare(Msg->from, p->From) == 0)
goto Continue;
- if (wildcardcompare(Msg->to, p->TO) == 0)
- goto Continue;
-
+ if (p->TO[0] == '!')
+ {
+ if (wildcardcompare(ToCopy, &p->TO[1]) == 1)
+ goto Continue;
+ }
+ else
+ {
+ if (wildcardcompare(ToCopy, p->TO) == 0)
+ goto Continue;
+ }
if (wildcardcompare(Msg->via, p->AT) == 0)
goto Continue;
@@ -3388,6 +3422,7 @@ void Flush(CIRCUIT * conn) SendUnbuffered(conn->BPQStream, &conn->OutputQueue[conn->OutputGetPointer], len);
conn->OutputGetPointer+=len;
+ conn->bytesSent += len;
tosend-=len;
SendUnbuffered(conn->BPQStream, "<A>bort, <CR> Continue..>", 25);
FreeSemaphore(&OutputSEM);
@@ -3399,6 +3434,7 @@ void Flush(CIRCUIT * conn) }
SendUnbuffered(conn->BPQStream, &conn->OutputQueue[conn->OutputGetPointer], len);
+ conn->bytesSent += len;
conn->OutputGetPointer+=len;
@@ -11051,7 +11087,6 @@ int DoReceivedData(int Stream) if (Stream == conn->BPQStream)
{
conn->SIDResponseTimer = 0; // Got a message, so cancel timeout.
-
do
{
// May have several messages per packet, or message split over packets
@@ -11068,6 +11103,7 @@ int DoReceivedData(int Stream) if (InputLen == 0 && conn->InputMode != 'Y')
return 0;
+ conn->bytesRxed += InputLen;
conn->InputLen += InputLen;
if (conn->InputLen == 0) return 0;
diff --git a/BPQMail.aps b/BPQMail.aps Binary files differnew file mode 100644 index 0000000..96bcae6 --- /dev/null +++ b/BPQMail.aps @@ -1149,6 +1149,9 @@ // Fix treating addresses ending in WW as Internet (57)
// Run sending to packetnodes.spots.radio in a separate thread (61)
// Fix loading ISP Account Name from config file (67)
+// Fixes to using {FormFolder} in Webmail Templates (68)
+// Save FBB transfer restart data over program restarts (69)
+// Add Send and Receive byte counts to status displays (69)
#include "bpqmail.h"
#include "winstdint.h"
@@ -1725,6 +1728,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, // SaveUserDatabase();
SaveMessageDatabase();
SaveBIDDatabase();
+ SaveRestartData();
configSaved = 1;
SaveConfig(ConfigName);
@@ -3021,9 +3025,9 @@ int RefreshMainWindow() strcpy(msg,"Logging in");
else
{
- i=sprintf_s(msg, sizeof(msg), "%-10s %-10s %2d %-10s%5d",
+ i=sprintf_s(msg, sizeof(msg), "%-10s %-10s %2d %-10s%5d %5d %5d",
conn->UserPointer->Name, conn->UserPointer->Call, conn->BPQStream,
- "BBS", conn->OutputQueueLength - conn->OutputGetPointer);
+ "BBS", conn->OutputQueueLength - conn->OutputGetPointer, conn->bytesSent, conn->bytesRxed);
}
}
}
@@ -3084,6 +3088,7 @@ static PSOCKADDR_IN psin; SOCKET sock;
+void GetRestartData();
BOOL Initialise()
{
@@ -3271,6 +3276,8 @@ BOOL Initialise() GetBadWordFile();
GetHTMLForms();
+ GetRestartData();
+
UsingingRegConfig = FALSE;
// Make sure SYSOPCALL is set
@@ -1,4 +1,4 @@ -//Microsoft Developer Studio generated resource script.
+// Microsoft Visual C++ generated resource script.
//
#include "BPQMailrc.h"
@@ -22,21 +22,19 @@ #undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
-// English (U.S.) resources
+// English (United States) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
-#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
-#endif //_WIN32
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
-IDD_PROPPAGE_LARGE DIALOG DISCARDABLE 0, 0, 235, 156
-STYLE WS_CHILD | WS_DISABLED | WS_CAPTION
+IDD_PROPPAGE_LARGE DIALOG 0, 0, 235, 156
+STYLE DS_SETFONT | WS_CHILD | WS_DISABLED | WS_CAPTION
CAPTION "Property Page"
FONT 8, "MS Sans Serif"
BEGIN
@@ -49,7 +47,7 @@ END //
#ifdef APSTUDIO_INVOKED
-GUIDELINES DESIGNINFO MOVEABLE PURE
+GUIDELINES DESIGNINFO
BEGIN
IDD_PROPPAGE_LARGE, DIALOG
BEGIN
@@ -61,57 +59,52 @@ BEGIN END
#endif // APSTUDIO_INVOKED
-#endif // English (U.S.) resources
+#endif // English (United States) resources
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
-// English (U.K.) resources
+// English (United Kingdom) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENG)
-#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_UK
#pragma code_page(1252)
-#endif //_WIN32
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
-BPQMAIL DIALOG DISCARDABLE 120, 50, 294, 165
-STYLE DS_3DLOOK | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU |
- WS_THICKFRAME
+BPQMAIL DIALOGEX 120, 50, 341, 165
+STYLE DS_SETFONT | DS_3DLOOK | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
CAPTION "G8BPQ Mail and Chat Server 1.0.0.10 Beta July 2009"
CLASS "BPQMail"
-FONT 8, "FixedSys"
+FONT 8, "FixedSys", 0, 0, 0x0
BEGIN
- LTEXT " User Callsign Stream Conf Queue",101,3,4,184,
- 10
- LTEXT "UTC",IDC_STATIC,197,3,15,10
- LTEXT "Local",IDC_STATIC,241,3,21,10
- LTEXT "",IDC_UTC,215,3,25,10
- LTEXT "",IDC_LOCAL,269,3,25,10
- LISTBOX 100,2,16,190,130,WS_VSCROLL
- LTEXT "Msgs",IDC_STATIC,197,21,40,10
- LTEXT "",IDC_MSGS,243,21,20,8
- LTEXT "Sysop Msgs",IDC_STATIC,197,32,40,10
- LTEXT "Held Msgs",IDC_STATIC,197,43,40,10
- LTEXT "",IDC_SYSOPMSGS,243,32,20,8
- LTEXT "",IDC_HELD,243,43,20,8
- LTEXT "SMTP Msgs",IDC_STATIC,197,54,40,10
- LTEXT "",IDC_SMTP,243,54,20,8
- LTEXT "Msg SEM Clashes",IDC_STATIC,197,70,63,10
- LTEXT "Alloc SEM Clashes",IDC_STATIC,197,81,68,10
- LTEXT "0",IDC_MSGSEM,274,70,20,10
- LTEXT "0",IDC_ALLOCSEM,274,81,20,10
- LTEXT "Con SEM Clashes",IDC_STATIC,197,92,68,10
- LTEXT "0",IDC_CONSEM,274,92,20,10
+ LTEXT " User Callsign Stream Conf Queue Sent Rxed",101,3,4,228,10
+ LTEXT "UTC",IDC_STATIC,236,5,15,10
+ LTEXT "Local",IDC_STATIC,280,5,21,10
+ LTEXT "",IDC_UTC,254,5,25,10
+ LTEXT "",IDC_LOCAL,307,5,25,10
+ LISTBOX 100,2,16,231,130,WS_VSCROLL
+ LTEXT "Msgs",IDC_STATIC,236,25,40,10
+ LTEXT "",IDC_MSGS,282,25,20,8
+ LTEXT "Sysop Msgs",IDC_STATIC,236,36,40,10
+ LTEXT "Held Msgs",IDC_STATIC,236,47,40,10
+ LTEXT "",IDC_SYSOPMSGS,282,36,20,8
+ LTEXT "",IDC_HELD,282,47,20,8
+ LTEXT "SMTP Msgs",IDC_STATIC,236,61,40,10
+ LTEXT "",IDC_SMTP,282,58,20,8
+ LTEXT "Msg SEM Clashes",IDC_STATIC,236,77,63,10
+ LTEXT "Alloc SEM Clashes",IDC_STATIC,236,88,68,10
+ LTEXT "0",IDC_MSGSEM,321,77,20,10
+ LTEXT "0",IDC_ALLOCSEM,321,88,20,10
+ LTEXT "Con SEM Clashes",IDC_STATIC,236,99,68,10
+ LTEXT "0",IDC_CONSEM,321,99,20,10
END
-CONSOLEWINDOW DIALOG DISCARDABLE 17, 25, 400, 301
-STYLE DS_3DLOOK | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU |
- WS_THICKFRAME
+CONSOLEWINDOW DIALOG 17, 25, 400, 301
+STYLE DS_SETFONT | DS_3DLOOK | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
CAPTION "Mail Console"
MENU CONSOLEMENU
CLASS "CONSOLEWINDOW"
@@ -120,21 +113,18 @@ BEGIN EDITTEXT 118,24,228,348,15,ES_AUTOHSCROLL | ES_NOHIDESEL
END
-BPQMONWINDOW DIALOG DISCARDABLE 17, 25, 400, 300
-STYLE DS_3DLOOK | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU |
- WS_THICKFRAME
+BPQMONWINDOW DIALOG 17, 25, 400, 300
+STYLE DS_SETFONT | DS_3DLOOK | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
CAPTION "Mail Monitor"
MENU MENU_2
CLASS "BPQMONWINDOW"
FONT 8, "FixedSys"
BEGIN
- LISTBOX 121,6,25,290,109,LBS_MULTIPLESEL | LBS_NOINTEGRALHEIGHT |
- WS_VSCROLL | WS_HSCROLL
+ LISTBOX 121,6,25,290,109,LBS_MULTIPLESEL | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_HSCROLL
END
-BPQMCWINDOW DIALOG DISCARDABLE 17, 25, 500, 300
-STYLE DS_3DLOOK | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU |
- WS_THICKFRAME
+BPQMCWINDOW DIALOG 17, 25, 500, 300
+STYLE DS_SETFONT | DS_3DLOOK | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
CAPTION "Multicast Monitor"
MENU MENU_1
CLASS "BPQMCWINDOW"
@@ -142,55 +132,45 @@ FONT 8, "FixedSys" BEGIN
END
-BPQDEBUGWINDOW DIALOG DISCARDABLE 17, 25, 400, 300
-STYLE DS_3DLOOK | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU |
- WS_THICKFRAME
+BPQDEBUGWINDOW DIALOG 17, 25, 400, 300
+STYLE DS_SETFONT | DS_3DLOOK | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
CAPTION "Mail Debug Window"
MENU MENU_3
CLASS "BPQDEBUGWINDOW"
FONT 8, "FixedSys"
BEGIN
- LISTBOX 122,5,156,290,109,LBS_MULTIPLESEL | LBS_NOINTEGRALHEIGHT |
- WS_VSCROLL | WS_HSCROLL
+ LISTBOX 122,5,156,290,109,LBS_MULTIPLESEL | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_HSCROLL
END
-102 DIALOG DISCARDABLE 0, 0, 385, 301
-STYLE WS_POPUP | WS_CAPTION | WS_VSCROLL | WS_HSCROLL | WS_SYSMENU |
- WS_THICKFRAME
+102 DIALOG 0, 0, 385, 301
+STYLE DS_SETFONT | WS_POPUP | WS_CAPTION | WS_VSCROLL | WS_HSCROLL | WS_SYSMENU | WS_THICKFRAME
CAPTION "Configuration"
FONT 8, "System"
BEGIN
END
-BBS_CONFIG DIALOG DISCARDABLE 0, 0, 381, 306
-STYLE WS_CHILD
+BBS_CONFIG DIALOG 0, 0, 381, 306
+STYLE DS_SETFONT | WS_CHILD
FONT 8, "System"
BEGIN
- LTEXT "BBS Call is the base callsign, without SSID. This is not necessarily the same as the Application Callsign defined in the BPQ32 configuration. SYSOP Call is the callsign used by the local console.",
- IDC_STATIC,10,4,354,23
- LTEXT "The Application Number defines which BPQ32 Application gives access to the BBS. Note this is the APPLNumber (1-32) not an Application Mask, as used in many BPQ32 programs.",
- IDC_STATIC,10,27,353,18
- LTEXT "The eMail Server Params configure the NNTP, SMTP and POP3 Servers, which allow normal Internet email and News clients to get messages from, and post mesages to the BBS. If you don't want to use this, set them to zero.. ",
- IDC_STATIC,8,52,357,27
- LTEXT "Enable UI System activates FBB compatible UI broadcasting of Message Headers",
- IDC_STATIC,8,80,357,15
+ LTEXT "BBS Call is the base callsign, without SSID. This is not necessarily the same as the Application Callsign defined in the BPQ32 configuration. SYSOP Call is the callsign used by the local console.",IDC_STATIC,10,4,354,23
+ LTEXT "The Application Number defines which BPQ32 Application gives access to the BBS. Note this is the APPLNumber (1-32) not an Application Mask, as used in many BPQ32 programs.",IDC_STATIC,10,27,353,18
+ LTEXT "The eMail Server Params configure the NNTP, SMTP and POP3 Servers, which allow normal Internet email and News clients to get messages from, and post mesages to the BBS. If you don't want to use this, set them to zero.. ",IDC_STATIC,8,52,357,27
+ LTEXT "Enable UI System activates FBB compatible UI broadcasting of Message Headers",IDC_STATIC,8,80,357,15
LTEXT "BBS Call",IDC_STATIC,7,105,37,12
EDITTEXT IDC_BBSCall,83,103,47,14,ES_UPPERCASE
LTEXT "SYSOP Call",IDC_STATIC,138,105,42,12
EDITTEXT IDC_SYSOPCALL,184,103,42,14,ES_UPPERCASE
CONTROL "Send SYSTEM Msgs to SYSOP call",IDC_SYSTOSYSOPCALL,
- "Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | WS_TABSTOP,231,
- 104,129,12
+ "Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | WS_TABSTOP,231,104,129,12
LTEXT "H Route",IDC_STATIC,7,122,37,12
EDITTEXT IDC_HRoute,83,120,119,13,ES_UPPERCASE
LTEXT "BBS Appl Number",IDC_STATIC,7,138,61,10
EDITTEXT IDC_BBSAppl,83,136,29,12
LTEXT "Streams",IDC_STATIC,130,138,32,10
EDITTEXT IDC_BBSStreams,168,136,29,12
- CONTROL "Refuse Bulls",IDC_REFUSEBULLS,"Button",BS_AUTOCHECKBOX |
- BS_LEFTTEXT | WS_TABSTOP,211,138,53,10
- CONTROL "Enable FBB UI System",IDC_ENABLEUI,"Button",
- BS_AUTOCHECKBOX | BS_LEFTTEXT | WS_TABSTOP,6,157,87,10
+ CONTROL "Refuse Bulls",IDC_REFUSEBULLS,"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | WS_TABSTOP,211,138,53,10
+ CONTROL "Enable FBB UI System",IDC_ENABLEUI,"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | WS_TABSTOP,6,157,87,10
LTEXT "Send Mail For Beacons Every",IDC_STATIC,102,157,100,12
EDITTEXT MAILFOR_MINS,205,156,22,12,ES_UPPERCASE
LTEXT "Minutes",IDC_STATIC,232,157,30,12
@@ -202,86 +182,58 @@ BEGIN EDITTEXT IDC_POP3Port,130,241,29,14
LTEXT "SMTP Port",IDC_STATIC,170,243,37,12
EDITTEXT IDC_SMTPPort,210,241,29,14
- CONTROL "Enable Remote Access",1009,"Button",BS_AUTOCHECKBOX |
- WS_TABSTOP,249,240,91,14
+ CONTROL "Enable Remote Access",1009,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,249,240,91,14
PUSHBUTTON "Save",IDC_BBSSAVE,159,281,50,14,BS_CENTER | BS_VCENTER
CONTROL "Don't hold messages from new users",IDC_DONTHOLDNEW,
- "Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | WS_TABSTOP,5,
- 189,134,12
- CONTROL "Forward Messages to BBS Call",IDC_FORWARDTOBBS,"Button",
- BS_AUTOCHECKBOX | BS_LEFTTEXT | WS_TABSTOP,145,189,114,
- 12
- CONTROL "Redirect msgs to BBS Call to SYSOP Call",
- IDC_BBSTOSYSOPCALL,"Button",BS_AUTOCHECKBOX |
- BS_LEFTTEXT | WS_TABSTOP,213,120,146,12
- CONTROL "Don't Request Home BBS",IDC_NOHOMEBBS,"Button",
- BS_AUTOCHECKBOX | BS_LEFTTEXT | WS_TABSTOP,260,174,99,12
- CONTROL "Don't Request Name",IDC_NONAME,"Button",BS_AUTOCHECKBOX |
- BS_LEFTTEXT | WS_TABSTOP,176,174,79,12
+ "Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | WS_TABSTOP,5,189,134,12
+ CONTROL "Forward Messages to BBS Call",IDC_FORWARDTOBBS,"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | WS_TABSTOP,145,189,114,12
+ CONTROL "Redirect msgs to BBS Call to SYSOP Call",IDC_BBSTOSYSOPCALL,
+ "Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | WS_TABSTOP,213,120,146,12
+ CONTROL "Don't Request Home BBS",IDC_NOHOMEBBS,"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | WS_TABSTOP,260,174,99,12
+ CONTROL "Don't Request Name",IDC_NONAME,"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | WS_TABSTOP,176,174,79,12
EDITTEXT IDC_AMPR,72,258,119,13
LTEXT "AMPR Address",IDC_STATIC,6,260,60,12
- CONTROL "Send ampr.org mail to AMPR host",IDC_FORWARDAMPR,
- "Button",BS_AUTOCHECKBOX | WS_TABSTOP,201,258,124,14
- CONTROL "Allow users to kill T msgs",IDC_USERRKILLT,"Button",
- BS_AUTOCHECKBOX | BS_LEFTTEXT | WS_TABSTOP,264,189,95,12
- CONTROL "Set Don't add WINLINK.ORG flag on new users",
- IDC_DEFAULTNOWINLINK,"Button",BS_AUTOCHECKBOX |
- BS_LEFTTEXT | WS_TABSTOP,5,174,162,12
- CONTROL "Don't allow unknown users",IDC_KNOWNUSERS,"Button",
- BS_AUTOCHECKBOX | BS_LEFTTEXT | WS_TABSTOP,277,138,98,10
- CONTROL "Don't Check From Calls",IDC_DONTCHECKFROM,"Button",
- BS_AUTOCHECKBOX | BS_LEFTTEXT | WS_TABSTOP,5,204,95,12
+ CONTROL "Send ampr.org mail to AMPR host",IDC_FORWARDAMPR,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,201,258,124,14
+ CONTROL "Allow users to kill T msgs",IDC_USERRKILLT,"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | WS_TABSTOP,264,189,95,12
+ CONTROL "Set Don't add WINLINK.ORG flag on new users",IDC_DEFAULTNOWINLINK,
+ "Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | WS_TABSTOP,5,174,162,12
+ CONTROL "Don't allow unknown users",IDC_KNOWNUSERS,"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | WS_TABSTOP,277,138,98,10
+ CONTROL "Don't Check From Calls",IDC_DONTCHECKFROM,"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | WS_TABSTOP,5,204,95,12
END
-CHAT_CONFIG DIALOG DISCARDABLE 0, 0, 381, 266
-STYLE WS_CHILD
+CHAT_CONFIG DIALOG 0, 0, 381, 266
+STYLE DS_SETFONT | WS_CHILD
FONT 8, "System"
BEGIN
LTEXT "Chat Appl Number",-1,115,109,61,8
EDITTEXT 2001,185,106,29,14
LTEXT "Nodes to link to",-1,115,129,53,8
- EDITTEXT 2002,185,125,87,88,ES_MULTILINE | ES_UPPERCASE |
- ES_AUTOVSCROLL | ES_WANTRETURN
+ EDITTEXT 2002,185,125,87,88,ES_MULTILINE | ES_UPPERCASE | ES_AUTOVSCROLL | ES_WANTRETURN
DEFPUSHBUTTON "Save",2100,172,226,50,14,BS_CENTER | BS_VCENTER
- LTEXT "The Application Number defines which BPQ32 Application gives access to the Chat Server. Note this is the APPLNumber (1-32) not an Application Mask, as uses in many BPQ32 programs.",
- -1,10,10,353,18
- LTEXT "The Nodes to link to box defines which other Chat Nodes should be connected to, or from which connections may be accepted. The format is ALIAS:CALL, eg BPQCHT:G8BPQ-4. Note these must be directly connectable - ie in your NODES table.",
- -1,10,30,355,25
- LTEXT "The Callsign of the Chat Node is not defined here - It is obtained from the BPQ32 APPLCALL parameter corresponding to the Chat Appl Number.",
- -1,10,60,360,25
+ LTEXT "The Application Number defines which BPQ32 Application gives access to the Chat Server. Note this is the APPLNumber (1-32) not an Application Mask, as uses in many BPQ32 programs.",-1,10,10,353,18
+ LTEXT "The Nodes to link to box defines which other Chat Nodes should be connected to, or from which connections may be accepted. The format is ALIAS:CALL, eg BPQCHT:G8BPQ-4. Note these must be directly connectable - ie in your NODES table.",-1,10,30,355,25
+ LTEXT "The Callsign of the Chat Node is not defined here - It is obtained from the BPQ32 APPLCALL parameter corresponding to the Chat Appl Number.",-1,10,60,360,25
END
IDD_USEREDIT DIALOGEX 20, 20, 293, 281
-STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
+STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Edit User"
FONT 8, "System", 0, 0, 0x1
BEGIN
- COMBOBOX 5000,7,10,57,123,CBS_SIMPLE | CBS_SORT | CBS_UPPERCASE |
- WS_VSCROLL | WS_TABSTOP
- CONTROL "BBS",IDC_BBSFLAG,"Button",BS_AUTOCHECKBOX | BS_LEFT |
- WS_TABSTOP,72,9,57,10
- CONTROL "PMS",IDC_PMSFLAG,"Button",BS_AUTOCHECKBOX | BS_LEFT |
- WS_TABSTOP,72,22,57,10
- CONTROL "Sysop",IDC_SYSOP,"Button",BS_AUTOCHECKBOX | BS_LEFT |
- WS_TABSTOP,72,35,57,10
- CONTROL "Expert",IDC_EXPERT,"Button",BS_AUTOCHECKBOX | BS_LEFT |
- WS_TABSTOP,72,48,57,10
- CONTROL "Excluded",IDC_EXCLUDED,"Button",BS_AUTOCHECKBOX |
- BS_LEFT | WS_TABSTOP,72,61,57,10
- CONTROL "Hold Messages",IDC_HOLDMAIL,"Button",BS_AUTOCHECKBOX |
- BS_LEFT | WS_TABSTOP,72,74,65,10
- CONTROL "NTS MPS",IDC_NTSMPS,"Button",BS_AUTOCHECKBOX | BS_LEFT |
- WS_TABSTOP,72,87,69,10
- CONTROL "Permit Email",IDC_EMAIL,"Button",BS_AUTOCHECKBOX |
- BS_LEFT | WS_TABSTOP,163,9,57,10
- CONTROL "Poll RMS for SSID's",IDC_POLLRMS,"Button",
- BS_AUTOCHECKBOX | BS_LEFT | WS_TABSTOP,163,23,78,8,0,
- HIDC_POLLRMS
+ COMBOBOX 5000,7,10,57,123,CBS_SIMPLE | CBS_SORT | CBS_UPPERCASE | WS_VSCROLL | WS_TABSTOP
+ CONTROL "BBS",IDC_BBSFLAG,"Button",BS_AUTOCHECKBOX | BS_LEFT | WS_TABSTOP,72,9,57,10
+ CONTROL "PMS",IDC_PMSFLAG,"Button",BS_AUTOCHECKBOX | BS_LEFT | WS_TABSTOP,72,22,57,10
+ CONTROL "Sysop",IDC_SYSOP,"Button",BS_AUTOCHECKBOX | BS_LEFT | WS_TABSTOP,72,35,57,10
+ CONTROL "Expert",IDC_EXPERT,"Button",BS_AUTOCHECKBOX | BS_LEFT | WS_TABSTOP,72,48,57,10
+ CONTROL "Excluded",IDC_EXCLUDED,"Button",BS_AUTOCHECKBOX | BS_LEFT | WS_TABSTOP,72,61,57,10
+ CONTROL "Hold Messages",IDC_HOLDMAIL,"Button",BS_AUTOCHECKBOX | BS_LEFT | WS_TABSTOP,72,74,65,10
+ CONTROL "NTS MPS",IDC_NTSMPS,"Button",BS_AUTOCHECKBOX | BS_LEFT | WS_TABSTOP,72,87,69,10
+ CONTROL "Permit Email",IDC_EMAIL,"Button",BS_AUTOCHECKBOX | BS_LEFT | WS_TABSTOP,163,9,57,10
+ CONTROL "Poll RMS for SSID's",IDC_POLLRMS,"Button",BS_AUTOCHECKBOX | BS_LEFT | WS_TABSTOP,163,23,78,8,0,HIDC_POLLRMS
EDITTEXT RMS_SSID1,244,21,13,12,ES_AUTOHSCROLL
EDITTEXT RMS_SSID2,258,21,13,12,ES_AUTOHSCROLL
EDITTEXT RMS_SSID3,272,21,13,12,ES_AUTOHSCROLL
- CONTROL "RMS Express User",RMS_EXPRESS_USER,"Button",
- BS_AUTOCHECKBOX | BS_LEFT | WS_TABSTOP,163,35,77,10
+ CONTROL "RMS Express User",RMS_EXPRESS_USER,"Button",BS_AUTOCHECKBOX | BS_LEFT | WS_TABSTOP,163,35,77,10
LTEXT "Last Listed",IDC_STATIC,163,87,38,12
EDITTEXT IDC_LASTLISTED,248,85,29,12,ES_AUTOHSCROLL
LTEXT "Name",IDC_STATIC,7,184,35,14
@@ -292,8 +244,7 @@ BEGIN EDITTEXT IDC_QTH,55,218,130,14,ES_AUTOHSCROLL
LTEXT "Home BBS",IDC_STATIC,7,238,40,14
EDITTEXT IDC_HOMEBBS,55,236,162,14,ES_UPPERCASE | ES_AUTOHSCROLL
- PUSHBUTTON "Add user",IDC_ADDUSER,79,257,42,14,BS_CENTER |
- BS_VCENTER
+ PUSHBUTTON "Add user",IDC_ADDUSER,79,257,42,14,BS_CENTER | BS_VCENTER
PUSHBUTTON "Delete user",5101,124,257,42,14,BS_CENTER | BS_VCENTER
PUSHBUTTON "Save",5102,169,257,42,14,BS_CENTER | BS_VCENTER
LTEXT "Connects in",IDC_STATIC,10,131,45,10
@@ -314,33 +265,25 @@ BEGIN LTEXT "0",BYTES_IN,45,153,38,10,0,WS_EX_RIGHT
LTEXT "Last Connect",IDC_STATIC,87,153,45,10
LTEXT "Never",LASTCONNECT,134,153,93,10
- CONTROL "Don't add @winlink.org",NO_WINLINKdotORG,"Button",
- BS_AUTOCHECKBOX | BS_LEFT | WS_TABSTOP,163,47,100,10
+ CONTROL "Don't add @winlink.org",NO_WINLINKdotORG,"Button",BS_AUTOCHECKBOX | BS_LEFT | WS_TABSTOP,163,47,100,10
LTEXT "ZIP",IDC_STATIC,189,221,12,11
EDITTEXT IDC_UZIP,207,219,38,12,ES_AUTOHSCROLL
- CONTROL "Allow sending Bulls",ALLOW_BULLS,"Button",
- BS_AUTOCHECKBOX | BS_LEFT | WS_TABSTOP,163,61,100,10
- CONTROL "Include SYSOP msgs in LM",IDC_SYSOP_IN_LM,"Button",
- BS_AUTOCHECKBOX | BS_LEFT | WS_DISABLED | WS_TABSTOP,163,
- 74,100,10
+ CONTROL "Allow sending Bulls",ALLOW_BULLS,"Button",BS_AUTOCHECKBOX | BS_LEFT | WS_TABSTOP,163,61,100,10
+ CONTROL "Include SYSOP msgs in LM",IDC_SYSOP_IN_LM,"Button",BS_AUTOCHECKBOX | BS_LEFT | WS_DISABLED | WS_TABSTOP,163,74,100,10
EDITTEXT IDC_CMSPASS,187,201,88,14,ES_PASSWORD
- CONTROL "CMS Pass",IDC_STATIC,"Static",SS_LEFTNOWORDWRAP |
- WS_GROUP,149,203,34,14
- CONTROL "Send Mail For to APRS ssid",IDC_APRSMFOR,"Button",
- BS_AUTOCHECKBOX | BS_LEFT | WS_TABSTOP,72,113,108,10
+ CONTROL "CMS Pass",IDC_STATIC,"Static",SS_LEFTNOWORDWRAP | WS_GROUP,149,203,34,14
+ CONTROL "Send Mail For to APRS ssid",IDC_APRSMFOR,"Button",BS_AUTOCHECKBOX | BS_LEFT | WS_TABSTOP,72,113,108,10
EDITTEXT IDC_APRSSSID,182,112,16,12,ES_AUTOHSCROLL
- CONTROL "Redirect to RMS",IDC_RMSREDIRECT,"Button",
- BS_AUTOCHECKBOX | BS_LEFT | WS_TABSTOP,72,100,69,10
+ CONTROL "Redirect to RMS",IDC_RMSREDIRECT,"Button",BS_AUTOCHECKBOX | BS_LEFT | WS_TABSTOP,72,100,69,10
END
-ISP_CONFIG DIALOG DISCARDABLE 26, 5, 381, 284
-STYLE WS_CHILD | WS_VISIBLE
+ISP_CONFIG DIALOG 26, 5, 381, 284
+STYLE DS_SETFONT | WS_CHILD | WS_VISIBLE
FONT 8, "System"
BEGIN
EDITTEXT 3001,95,110,100,15
LTEXT "SMTP Server",-1,10,130,53,13
- LTEXT "The system relies on having an email domain which supports forwarding of all email addresses to a fixed mailbox. For example, I could register domain mycall.org.uk, and have any mail sent to anyone@mycall.org.uk forwarded to mymailbox@myisp.com",
- 1,10,34,349,25
+ LTEXT "The system relies on having an email domain which supports forwarding of all email addresses to a fixed mailbox. For example, I could register domain mycall.org.uk, and have any mail sent to anyone@mycall.org.uk forwarded to mymailbox@myisp.com",1,10,34,349,25
LTEXT "POP3 Server",-1,10,146,61,13
LTEXT "ISP Account Name",-1,10,163,63,13
EDITTEXT IDC_ISPSMTPName,95,127,148,15
@@ -350,134 +293,87 @@ BEGIN LTEXT "Port",-1,250,130,19,13
EDITTEXT 3005,275,144,29,15
EDITTEXT 3003,275,127,29,15
- LTEXT "This page configures the BBS <> Internet Mail Gateway. The Gateway allows local users to send messages to Internet email addresses, and get replies from those messages",
- -1,10,10,353,20
+ LTEXT "This page configures the BBS <> Internet Mail Gateway. The Gateway allows local users to send messages to Internet email addresses, and get replies from those messages",-1,10,10,353,20
LTEXT "My Domain",-1,10,112,51,8
LTEXT "ISP Account Password",-1,10,180,80,13
EDITTEXT 3007,95,178,147,15,ES_PASSWORD
LTEXT "POP3 Poll Interval (Seconds)",-1,10,216,80,18
EDITTEXT 3008,95,219,29,12
- LTEXT "WARNING This feature my be illegal in some administrations. Make sure your authorities permit forwarding mail from the Amateur Service before enabling it",
- -1,10,64,348,15
- CONTROL "Enable Internet Gateway",3000,"Button",BS_AUTOCHECKBOX |
- BS_LEFTTEXT | BS_LEFT | WS_TABSTOP,10,90,90,15
+ LTEXT "WARNING This feature my be illegal in some administrations. Make sure your authorities permit forwarding mail from the Amateur Service before enabling it",-1,10,64,348,15
+ CONTROL "Enable Internet Gateway",3000,"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | BS_LEFT | WS_TABSTOP,10,90,90,15
DEFPUSHBUTTON "Save",3100,165,261,57,17,BS_CENTER | BS_VCENTER
CONTROL "SMTP Server Requires Authentication",ISP_SMTP_AUTH,
- "Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | BS_LEFT |
- BS_MULTILINE | WS_TABSTOP,250,159,69,32
+ "Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | BS_LEFT | BS_MULTILINE | WS_TABSTOP,250,159,69,32
EDITTEXT SMTP_EHELO,95,196,100,15
LTEXT "SMTP ""EHELO"" Domain",-1,10,198,80,8
END
-IDD_FORWARDING DIALOG DISCARDABLE 20, 20, 457, 327
-STYLE WS_POPUP | WS_CAPTION | WS_VSCROLL | WS_HSCROLL | WS_SYSMENU |
- WS_THICKFRAME
+IDD_FORWARDING DIALOG 20, 20, 457, 327
+STYLE DS_SETFONT | WS_POPUP | WS_CAPTION | WS_VSCROLL | WS_HSCROLL | WS_SYSMENU | WS_THICKFRAME
CAPTION "Manage Forwarding"
FONT 8, "System"
BEGIN
- LTEXT "Forwarding Rules are define here. BBS Records are created by setting the BBS flag on a User Record.",
- IDC_STATIC,5,7,368,10
- LTEXT "The Enable Forwarding flag allows you to disable forwarding without losing the messages to be forwarded. ",
- IDC_STATIC,5,20,373,8
+ LTEXT "Forwarding Rules are define here. BBS Records are created by setting the BBS flag on a User Record.",IDC_STATIC,5,7,368,10
+ LTEXT "The Enable Forwarding flag allows you to disable forwarding without losing the messages to be forwarded. ",IDC_STATIC,5,20,373,8
GROUPBOX "Global Params",IDC_STATIC,2,33,114,263
LTEXT "Max Size to Send",IDC_STATIC,5,50,58,12
EDITTEXT IDC_MAXSEND,66,49,26,12,ES_AUTOHSCROLL
LTEXT "Max Size to Recv",IDC_STATIC,5,68,58,12
EDITTEXT IDC_MAXRECV,66,66,26,12,ES_AUTOHSCROLL
- CONTROL "Warn if no route for P or T",IDC_WARNNOROUTE,"Button",
- BS_AUTOCHECKBOX | BS_LEFTTEXT | BS_MULTILINE |
- WS_TABSTOP,5,101,103,8
+ CONTROL "Warn if no route for P or T",IDC_WARNNOROUTE,"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | BS_MULTILINE | WS_TABSTOP,5,101,103,8
LTEXT "Aliases",IDC_STATIC,5,165,57,13
- EDITTEXT IDC_ALIAS,4,183,99,81,ES_MULTILINE | ES_UPPERCASE |
- ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN |
- WS_VSCROLL
- CONTROL "Readdress Locally Input",IDC_READDRESSLOCAL,"Button",
- BS_AUTOCHECKBOX | BS_LEFTTEXT | BS_MULTILINE |
- WS_DISABLED | WS_TABSTOP,4,267,97,8
- CONTROL "Readdress Received",IDC_READDRESSRXED,"Button",
- BS_AUTOCHECKBOX | BS_LEFTTEXT | BS_MULTILINE |
- WS_DISABLED | WS_TABSTOP,4,281,97,8
+ EDITTEXT IDC_ALIAS,4,183,99,81,ES_MULTILINE | ES_UPPERCASE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN | WS_VSCROLL
+ CONTROL "Readdress Locally Input",IDC_READDRESSLOCAL,"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | BS_MULTILINE | WS_DISABLED | WS_TABSTOP,4,267,97,8
+ CONTROL "Readdress Received",IDC_READDRESSRXED,"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | BS_MULTILINE | WS_DISABLED | WS_TABSTOP,4,281,97,8
GROUPBOX "Per-BBS Params",IDC_STATIC,121,33,326,263
LTEXT "BBS",IDC_STATIC,128,46,57,10
- COMBOBOX IDC_BBS,122,59,50,60,CBS_SIMPLE | CBS_OEMCONVERT |
- CBS_SORT | CBS_NOINTEGRALHEIGHT | WS_VSCROLL
+ COMBOBOX IDC_BBS,122,59,50,60,CBS_SIMPLE | CBS_OEMCONVERT | CBS_SORT | CBS_NOINTEGRALHEIGHT | WS_VSCROLL
LTEXT "To Calls:",IDC_STATIC,186,46,40,10
- EDITTEXT IDC_TOCALLS,177,59,50,60,ES_MULTILINE | ES_UPPERCASE |
- ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN |
- WS_VSCROLL
+ EDITTEXT IDC_TOCALLS,177,59,50,60,ES_MULTILINE | ES_UPPERCASE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN | WS_VSCROLL
LTEXT "AT Calls:",IDC_STATIC,242,46,43,10
- EDITTEXT IDC_ATCALLS,233,59,50,60,ES_MULTILINE | ES_UPPERCASE |
- ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN |
- WS_VSCROLL
+ EDITTEXT IDC_ATCALLS,233,59,50,60,ES_MULTILINE | ES_UPPERCASE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN | WS_VSCROLL
LTEXT "Times",IDC_STATIC,299,46,30,13
- EDITTEXT IDC_FWDTIMES,288,59,50,60,ES_MULTILINE | ES_UPPERCASE |
- ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN |
- WS_VSCROLL
+ EDITTEXT IDC_FWDTIMES,288,59,50,60,ES_MULTILINE | ES_UPPERCASE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN | WS_VSCROLL
LTEXT "Connect Script",IDC_STATIC,348,46,57,13
- EDITTEXT IDC_CALL,343,59,92,60,ES_MULTILINE | ES_AUTOVSCROLL |
- ES_AUTOHSCROLL | ES_WANTRETURN | WS_VSCROLL
- LTEXT "Hierarchical Routes (Flood Bulls)",IDC_STATIC,141,126,
- 114,12
- EDITTEXT IDC_HROUTES,122,140,148,60,ES_MULTILINE | ES_UPPERCASE |
- ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN |
- WS_VSCROLL | WS_HSCROLL
- LTEXT "HR (Personals and Directed Bulls)",IDC_STATIC,281,126,
- 125,12
- EDITTEXT IDC_HROUTESP,280,141,151,60,ES_MULTILINE | ES_UPPERCASE |
- ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN |
- WS_VSCROLL | WS_HSCROLL
+ EDITTEXT IDC_CALL,343,59,92,60,ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN | WS_VSCROLL
+ LTEXT "Hierarchical Routes (Flood Bulls)",IDC_STATIC,141,126,114,12
+ EDITTEXT IDC_HROUTES,122,140,148,60,ES_MULTILINE | ES_UPPERCASE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN | WS_VSCROLL | WS_HSCROLL
+ LTEXT "HR (Personals and Directed Bulls)",IDC_STATIC,281,126,125,12
+ EDITTEXT IDC_HROUTESP,280,141,151,60,ES_MULTILINE | ES_UPPERCASE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN | WS_VSCROLL | WS_HSCROLL
LTEXT "Interval (Secs)",IDC_STATIC,359,205,48,8
EDITTEXT IDC_FWDINT,253,204,22,12,ES_AUTOHSCROLL
- CONTROL "Enable Forwarding",4000,"Button",BS_AUTOCHECKBOX |
- BS_LEFTTEXT | BS_LEFT | WS_TABSTOP,122,206,72,8
- CONTROL "Request Reverse",4006,"Button",BS_AUTOCHECKBOX |
- BS_LEFTTEXT | BS_LEFT | WS_TABSTOP,286,206,67,8
- CONTROL "Send new messages without waiting for poll timer",
- IDC_SENDNEW,"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT |
- BS_MULTILINE | WS_TABSTOP,122,221,182,8
+ CONTROL "Enable Forwarding",4000,"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | BS_LEFT | WS_TABSTOP,122,206,72,8
+ CONTROL "Request Reverse",4006,"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | BS_LEFT | WS_TABSTOP,286,206,67,8
+ CONTROL "Send new messages without waiting for poll timer",IDC_SENDNEW,
+ "Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | BS_MULTILINE | WS_TABSTOP,122,221,182,8
LTEXT "BBS HA",IDC_STATIC,125,242,30,12
EDITTEXT IDC_BBSHA,162,240,134,12,ES_UPPERCASE | ES_AUTOHSCROLL
LTEXT "Max Block",IDC_STATIC,368,241,37,12
EDITTEXT IDC_MAXBLOCK,407,240,26,12,ES_AUTOHSCROLL
- CONTROL "Send Personal Mail Only",IDC_PERSONALONLY,"Button",
- BS_AUTOCHECKBOX | BS_LEFTTEXT | BS_MULTILINE |
- WS_TABSTOP,321,221,108,8
- CONTROL "Allow Binary",IDC_ALLOWCOMP,"Button",BS_AUTOCHECKBOX |
- BS_LEFTTEXT | BS_MULTILINE | WS_TABSTOP,125,260,58,8
- CONTROL "Use B1 Protocol",IDC_USEB1,"Button",BS_AUTOCHECKBOX |
- BS_LEFTTEXT | BS_MULTILINE | WS_TABSTOP,185,260,72,8
- CONTROL "Use B2 Protocol",IDC_USEB2,"Button",BS_AUTOCHECKBOX |
- BS_LEFTTEXT | BS_MULTILINE | WS_TABSTOP,261,260,67,8
- DEFPUSHBUTTON "? Help",IDC_HRHELP,381,6,33,11,BS_CENTER | BS_VCENTER |
- NOT WS_TABSTOP
+ CONTROL "Send Personal Mail Only",IDC_PERSONALONLY,"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | BS_MULTILINE | WS_TABSTOP,321,221,108,8
+ CONTROL "Allow Binary",IDC_ALLOWCOMP,"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | BS_MULTILINE | WS_TABSTOP,125,260,58,8
+ CONTROL "Use B1 Protocol",IDC_USEB1,"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | BS_MULTILINE | WS_TABSTOP,185,260,72,8
+ CONTROL "Use B2 Protocol",IDC_USEB2,"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | BS_MULTILINE | WS_TABSTOP,261,260,67,8
+ DEFPUSHBUTTON "? Help",IDC_HRHELP,381,6,33,11,BS_CENTER | BS_VCENTER | NOT WS_TABSTOP
DEFPUSHBUTTON "Save",4100,352,303,57,17,BS_CENTER | BS_VCENTER
LTEXT "Interval (Secs)",IDC_STATIC,198,206,48,8
EDITTEXT IDC_REVFWDINT,407,205,23,12,ES_AUTOHSCROLL
- CONTROL "Use Local Time ",IDC_USELOCALTIME,"Button",
- BS_AUTOCHECKBOX | BS_LEFTTEXT | BS_MULTILINE |
- WS_TABSTOP,5,116,103,8
- CONTROL "Send ctrl/Z instead of /ex",IDC_CTRLZ,"Button",
- BS_AUTOCHECKBOX | BS_LEFTTEXT | BS_MULTILINE |
- WS_TABSTOP,333,260,100,8
+ CONTROL "Use Local Time ",IDC_USELOCALTIME,"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | BS_MULTILINE | WS_TABSTOP,5,116,103,8
+ CONTROL "Send ctrl/Z instead of /ex",IDC_CTRLZ,"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | BS_MULTILINE | WS_TABSTOP,333,260,100,8
LTEXT "Max Bull Age",IDC_STATIC,5,86,58,12
EDITTEXT IDC_MAXAGE,66,84,26,12,ES_AUTOHSCROLL
- CONTROL "FBB Blocked",IDC_BLOCKED,"Button",BS_AUTOCHECKBOX |
- BS_LEFTTEXT | BS_MULTILINE | WS_TABSTOP,301,241,61,8
- PUSHBUTTON "Copy From BBS",COPYCONFIG,160,303,57,17,BS_CENTER |
- BS_VCENTER
+ CONTROL "FBB Blocked",IDC_BLOCKED,"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | BS_MULTILINE | WS_TABSTOP,301,241,61,8
+ PUSHBUTTON "Copy From BBS",COPYCONFIG,160,303,57,17,BS_CENTER | BS_VCENTER
EDITTEXT COPYFROMCALL,227,303,35,17,ES_UPPERCASE | ES_AUTOHSCROLL
- CONTROL "Send P to more than 1 BBS",IDC_MULTIP,"Button",
- BS_AUTOCHECKBOX | BS_LEFTTEXT | BS_MULTILINE |
- WS_TABSTOP,5,130,103,8
+ CONTROL "Send P to more than 1 BBS",IDC_MULTIP,"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | BS_MULTILINE | WS_TABSTOP,5,130,103,8
LTEXT "Incoming Connect Timeout",IDC_STATIC,125,278,95,12
EDITTEXT IDC_CONTIMEOUT,219,276,22,12,ES_AUTOHSCROLL
CONTROL "Use 4 Char Continent Codes",IDC_FOURCHARCONTINENT,
- "Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | BS_MULTILINE |
- WS_TABSTOP,6,146,103,8
+ "Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | BS_MULTILINE | WS_TABSTOP,6,146,103,8
END
-IDD_USERADDED_BOX DIALOG DISCARDABLE 176, 132, 129, 68
-STYLE DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_THICKFRAME
+IDD_USERADDED_BOX DIALOG 176, 132, 129, 68
+STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_THICKFRAME
FONT 8, "System"
BEGIN
DEFPUSHBUTTON "Ok",0,47,48,36,17,BS_CENTER | BS_VCENTER
@@ -485,17 +381,14 @@ BEGIN END
IDD_MSGEDIT DIALOGEX 20, 20, 421, 298
-STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
+STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Edit Message"
FONT 8, "System", 0, 0, 0x1
BEGIN
RTEXT "Msg",IDC_STATIC,7,7,19,8
- LISTBOX 0,33,7,65,81,LBS_NOINTEGRALHEIGHT | LBS_EXTENDEDSEL |
- WS_VSCROLL | WS_TABSTOP
- COMBOBOX IDC_MSGTYPE,125,9,25,55,CBS_DROPDOWNLIST | WS_VSCROLL |
- WS_TABSTOP
- COMBOBOX IDC_MSGSTATUS,185,9,25,55,CBS_DROPDOWNLIST | WS_VSCROLL |
- WS_TABSTOP
+ LISTBOX 0,33,7,65,81,LBS_NOINTEGRALHEIGHT | LBS_EXTENDEDSEL | WS_VSCROLL | WS_TABSTOP
+ COMBOBOX IDC_MSGTYPE,125,9,25,55,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
+ COMBOBOX IDC_MSGSTATUS,185,9,25,55,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
RTEXT "From",IDC_STATIC,7,98,19,8
EDITTEXT 6001,33,95,65,14,ES_UPPERCASE | ES_AUTOHSCROLL
RTEXT "BID",IDC_STATIC,7,114,19,8
@@ -516,333 +409,187 @@ BEGIN RTEXT "Size",IDC_STATIC,116,147,32,8
EDITTEXT 6020,153,145,55,14,ES_AUTOHSCROLL
LTEXT "Type",IDC_STATIC,105,10,17,8
- CONTROL "",25,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,221,7,35,10
- CONTROL "",26,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,221,17,35,10
- CONTROL "",27,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,221,27,35,10
- CONTROL "",28,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,221,37,35,10
- CONTROL "",29,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,221,47,35,10
- CONTROL "",30,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,221,57,35,10
- CONTROL "",31,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,221,67,35,10
- CONTROL "",32,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,221,77,35,10
- CONTROL "",33,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,221,87,35,10
- CONTROL "",34,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,221,97,35,10
- CONTROL "",35,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,221,107,35,10
- CONTROL "",36,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,221,117,35,10
- CONTROL "",37,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,221,127,35,10
- CONTROL "",38,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,221,137,35,10
- CONTROL "",39,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,221,147,35,10
- CONTROL "",40,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,221,157,35,10
- CONTROL "",41,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,221,167,35,10
- CONTROL "",42,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,221,177,35,10
- CONTROL "",43,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,221,187,35,10
- CONTROL "",44,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,221,197,35,10
- CONTROL "",45,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,221,208,35,10
- CONTROL "",46,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,221,218,35,10
- CONTROL "",47,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,221,228,35,10
- CONTROL "",48,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,221,238,35,10
- CONTROL "",49,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,221,248,35,10
- CONTROL "",50,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,260,7,35,10
- CONTROL "",51,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,260,17,35,10
- CONTROL "",52,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,260,27,35,10
- CONTROL "",53,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,260,37,35,10
- CONTROL "",54,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,260,47,35,10
- CONTROL "",55,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,260,57,35,10
- CONTROL "",56,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,260,67,35,10
- CONTROL "",57,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,260,77,35,10
- CONTROL "",58,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,260,87,35,10
- CONTROL "",59,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,260,97,35,10
- CONTROL "",60,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,260,107,35,10
- CONTROL "",61,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,260,117,35,10
- CONTROL "",62,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,260,127,35,10
- CONTROL "",63,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,260,137,35,10
- CONTROL "",64,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,260,147,35,10
- CONTROL "",65,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,260,157,35,10
- CONTROL "",66,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,260,167,35,10
- CONTROL "",67,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,260,177,35,10
- CONTROL "",68,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,260,187,35,10
- CONTROL "",69,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,260,197,35,10
- CONTROL "",70,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,260,207,35,10
- CONTROL "",71,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,260,217,35,10
- CONTROL "",72,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,260,227,35,10
- CONTROL "",73,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,260,237,35,10
- CONTROL "",74,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,260,247,35,10
- CONTROL "",75,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,299,7,35,10
- CONTROL "",76,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,299,17,35,10
- CONTROL "",77,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,299,27,35,10
- CONTROL "",78,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,299,37,35,10
- CONTROL "",79,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,299,47,35,10
- CONTROL "",80,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,299,57,35,10
- CONTROL "",81,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,299,67,35,10
- CONTROL "",82,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,299,77,35,10
- CONTROL "",83,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,299,87,35,10
- CONTROL "",84,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,299,97,35,10
- CONTROL "",85,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,299,107,35,10
- CONTROL "",86,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,299,117,35,10
- CONTROL "",87,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,299,127,35,10
- CONTROL "",88,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,299,137,35,10
- CONTROL "",89,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,299,147,35,10
- CONTROL "",90,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,299,157,35,10
- CONTROL "",91,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,299,167,35,10
- CONTROL "",92,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,299,177,35,10
- CONTROL "",93,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,299,187,35,10
- CONTROL "",94,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,299,197,35,10
- CONTROL "",95,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,299,207,35,10
- CONTROL "",96,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,299,217,35,10
- CONTROL "",97,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,299,227,35,10
- CONTROL "",98,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,299,237,35,10
- CONTROL "",99,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,299,247,35,10
- CONTROL "",100,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,337,7,35,10
- CONTROL "",101,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,337,18,35,10
- CONTROL "",102,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,337,27,35,10
- CONTROL "",103,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,337,37,35,10
- CONTROL "",104,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,337,47,35,10
+ CONTROL "",25,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,221,7,35,10
+ CONTROL "",26,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,221,17,35,10
+ CONTROL "",27,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,221,27,35,10
+ CONTROL "",28,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,221,37,35,10
+ CONTROL "",29,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,221,47,35,10
+ CONTROL "",30,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,221,57,35,10
+ CONTROL "",31,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,221,67,35,10
+ CONTROL "",32,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,221,77,35,10
+ CONTROL "",33,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,221,87,35,10
+ CONTROL "",34,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,221,97,35,10
+ CONTROL "",35,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,221,107,35,10
+ CONTROL "",36,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,221,117,35,10
+ CONTROL "",37,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,221,127,35,10
+ CONTROL "",38,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,221,137,35,10
+ CONTROL "",39,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,221,147,35,10
+ CONTROL "",40,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,221,157,35,10
+ CONTROL "",41,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,221,167,35,10
+ CONTROL "",42,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,221,177,35,10
+ CONTROL "",43,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,221,187,35,10
+ CONTROL "",44,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,221,197,35,10
+ CONTROL "",45,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,221,208,35,10
+ CONTROL "",46,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,221,218,35,10
+ CONTROL "",47,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,221,228,35,10
+ CONTROL "",48,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,221,238,35,10
+ CONTROL "",49,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,221,248,35,10
+ CONTROL "",50,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,260,7,35,10
+ CONTROL "",51,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,260,17,35,10
+ CONTROL "",52,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,260,27,35,10
+ CONTROL "",53,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,260,37,35,10
+ CONTROL "",54,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,260,47,35,10
+ CONTROL "",55,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,260,57,35,10
+ CONTROL "",56,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,260,67,35,10
+ CONTROL "",57,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,260,77,35,10
+ CONTROL "",58,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,260,87,35,10
+ CONTROL "",59,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,260,97,35,10
+ CONTROL "",60,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,260,107,35,10
+ CONTROL "",61,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,260,117,35,10
+ CONTROL "",62,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,260,127,35,10
+ CONTROL "",63,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,260,137,35,10
+ CONTROL "",64,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,260,147,35,10
+ CONTROL "",65,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,260,157,35,10
+ CONTROL "",66,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,260,167,35,10
+ CONTROL "",67,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,260,177,35,10
+ CONTROL "",68,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,260,187,35,10
+ CONTROL "",69,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,260,197,35,10
+ CONTROL "",70,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,260,207,35,10
+ CONTROL "",71,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,260,217,35,10
+ CONTROL "",72,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,260,227,35,10
+ CONTROL "",73,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,260,237,35,10
+ CONTROL "",74,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,260,247,35,10
+ CONTROL "",75,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,299,7,35,10
+ CONTROL "",76,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,299,17,35,10
+ CONTROL "",77,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,299,27,35,10
+ CONTROL "",78,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,299,37,35,10
+ CONTROL "",79,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,299,47,35,10
+ CONTROL "",80,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,299,57,35,10
+ CONTROL "",81,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,299,67,35,10
+ CONTROL "",82,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,299,77,35,10
+ CONTROL "",83,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,299,87,35,10
+ CONTROL "",84,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,299,97,35,10
+ CONTROL "",85,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,299,107,35,10
+ CONTROL "",86,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,299,117,35,10
+ CONTROL "",87,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,299,127,35,10
+ CONTROL "",88,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,299,137,35,10
+ CONTROL "",89,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,299,147,35,10
+ CONTROL "",90,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,299,157,35,10
+ CONTROL "",91,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,299,167,35,10
+ CONTROL "",92,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,299,177,35,10
+ CONTROL "",93,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,299,187,35,10
+ CONTROL "",94,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,299,197,35,10
+ CONTROL "",95,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,299,207,35,10
+ CONTROL "",96,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,299,217,35,10
+ CONTROL "",97,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,299,227,35,10
+ CONTROL "",98,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,299,237,35,10
+ CONTROL "",99,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,299,247,35,10
+ CONTROL "",100,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,337,7,35,10
+ CONTROL "",101,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,337,18,35,10
+ CONTROL "",102,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,337,27,35,10
+ CONTROL "",103,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,337,37,35,10
+ CONTROL "",104,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,337,47,35,10
LTEXT "Key",IDC_STATIC,317,267,35,9
- CONTROL "Dont Send",205,"Button",BS_3STATE | BS_CENTER |
- BS_PUSHLIKE,262,281,43,10
- CONTROL "Send",206,"Button",BS_3STATE | BS_CENTER | BS_PUSHLIKE,
- 311,280,35,10
- CONTROL "Sent",207,"Button",BS_3STATE | BS_CENTER | BS_PUSHLIKE,
- 353,280,35,10
- DEFPUSHBUTTON "Edit Text",IDC_EDITTEXT,24,275,38,15,BS_CENTER |
- BS_VCENTER
- DEFPUSHBUTTON "Print",IDC_PRINTMSG,150,275,24,15,BS_CENTER |
- BS_VCENTER
+ CONTROL "Dont Send",205,"Button",BS_3STATE | BS_CENTER | BS_PUSHLIKE,262,281,43,10
+ CONTROL "Send",206,"Button",BS_3STATE | BS_CENTER | BS_PUSHLIKE,311,280,35,10
+ CONTROL "Sent",207,"Button",BS_3STATE | BS_CENTER | BS_PUSHLIKE,353,280,35,10
+ DEFPUSHBUTTON "Edit Text",IDC_EDITTEXT,24,275,38,15,BS_CENTER | BS_VCENTER
+ DEFPUSHBUTTON "Print",IDC_PRINTMSG,150,275,24,15,BS_CENTER | BS_VCENTER
RTEXT "Filter From",IDC_STATIC,104,30,38,8
EDITTEXT FILTER_FROM,147,28,62,14,ES_UPPERCASE | ES_AUTOHSCROLL
EDITTEXT FILTER_TO,147,44,62,14,ES_UPPERCASE | ES_AUTOHSCROLL
- EDITTEXT FILTER_VIA,147,60,62,14,ES_UPPERCASE | ES_AUTOHSCROLL,0,
- HFILTER_VIA
+ EDITTEXT FILTER_VIA,147,60,62,14,ES_UPPERCASE | ES_AUTOHSCROLL,0,HFILTER_VIA
RTEXT "Filter To",IDC_STATIC,104,46,38,8
RTEXT "Filter Via",IDC_STATIC,104,62,38,8
DEFPUSHBUTTON "Save",IDC_SAVEMSG,67,275,24,15,BS_CENTER | BS_VCENTER
- DEFPUSHBUTTON "Save to File",IDC_SAVETOFILE,96,275,49,15,BS_CENTER |
- BS_VCENTER
+ DEFPUSHBUTTON "Save to File",IDC_SAVETOFILE,96,275,49,15,BS_CENTER | BS_VCENTER
DEFPUSHBUTTON "Export",IDC_EXPORT,179,275,32,15,BS_CENTER | BS_VCENTER
EDITTEXT EMAILFROM,33,169,177,14,ES_UPPERCASE | ES_AUTOHSCROLL
RTEXT "Email From",IDC_STATIC,4,168,25,17
- CONTROL "",105,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,337,57,35,10
- CONTROL "",106,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,337,67,35,10
- CONTROL "",107,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,337,77,35,10
- CONTROL "",108,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,337,87,35,10
- CONTROL "",109,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,337,97,35,10
- CONTROL "",110,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,337,107,35,10
- CONTROL "",111,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,337,118,35,10
- CONTROL "",112,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,337,127,35,10
- CONTROL "",113,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,337,137,35,10
- CONTROL "",114,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,337,147,35,10
- CONTROL "",115,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,337,157,35,10
- CONTROL "",116,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,337,167,35,10
- CONTROL "",117,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,337,177,35,10
- CONTROL "",118,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,337,187,35,10
- CONTROL "",119,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,337,197,35,10
- CONTROL "",120,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,337,207,35,10
- CONTROL "",121,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,337,217,35,10
- CONTROL "",122,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,337,227,35,10
- CONTROL "",123,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,337,237,35,10
- CONTROL "",124,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,337,247,35,10
- CONTROL "",148,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,377,237,35,10
- CONTROL "",125,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,377,8,35,10
- CONTROL "",126,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,377,17,35,10
- CONTROL "",127,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,377,27,35,10
- CONTROL "",128,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,377,37,35,10
- CONTROL "",129,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,377,47,35,10
- CONTROL "",130,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,377,57,35,10
- CONTROL "",131,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,377,67,35,10
- CONTROL "",132,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,377,77,35,10
- CONTROL "",133,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,377,87,35,10
- CONTROL "",134,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,377,97,35,10
- CONTROL "",135,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,377,108,35,10
- CONTROL "",136,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,377,117,35,10
- CONTROL "",137,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,377,127,35,10
- CONTROL "",138,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,377,137,35,10
- CONTROL "",139,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,377,147,35,10
- CONTROL "",140,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,377,157,35,10
- CONTROL "",141,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,377,167,35,10
- CONTROL "",150,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,377,247,35,10
- CONTROL "",142,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,377,177,35,10
- CONTROL "",143,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,377,187,35,10
- CONTROL "",144,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,377,197,35,10
- CONTROL "",145,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,377,207,35,10
- CONTROL "",146,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,377,217,35,10
- CONTROL "",147,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE |
- WS_TABSTOP,377,227,35,10
- EDITTEXT FILTER_BID,147,76,62,14,ES_UPPERCASE | ES_AUTOHSCROLL,0,
- HFILTER_BID
+ CONTROL "",105,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,337,57,35,10
+ CONTROL "",106,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,337,67,35,10
+ CONTROL "",107,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,337,77,35,10
+ CONTROL "",108,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,337,87,35,10
+ CONTROL "",109,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,337,97,35,10
+ CONTROL "",110,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,337,107,35,10
+ CONTROL "",111,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,337,118,35,10
+ CONTROL "",112,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,337,127,35,10
+ CONTROL "",113,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,337,137,35,10
+ CONTROL "",114,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,337,147,35,10
+ CONTROL "",115,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,337,157,35,10
+ CONTROL "",116,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,337,167,35,10
+ CONTROL "",117,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,337,177,35,10
+ CONTROL "",118,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,337,187,35,10
+ CONTROL "",119,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,337,197,35,10
+ CONTROL "",120,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,337,207,35,10
+ CONTROL "",121,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,337,217,35,10
+ CONTROL "",122,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,337,227,35,10
+ CONTROL "",123,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,337,237,35,10
+ CONTROL "",124,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,337,247,35,10
+ CONTROL "",148,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,377,237,35,10
+ CONTROL "",125,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,377,8,35,10
+ CONTROL "",126,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,377,17,35,10
+ CONTROL "",127,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,377,27,35,10
+ CONTROL "",128,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,377,37,35,10
+ CONTROL "",129,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,377,47,35,10
+ CONTROL "",130,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,377,57,35,10
+ CONTROL "",131,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,377,67,35,10
+ CONTROL "",132,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,377,77,35,10
+ CONTROL "",133,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,377,87,35,10
+ CONTROL "",134,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,377,97,35,10
+ CONTROL "",135,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,377,108,35,10
+ CONTROL "",136,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,377,117,35,10
+ CONTROL "",137,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,377,127,35,10
+ CONTROL "",138,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,377,137,35,10
+ CONTROL "",139,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,377,147,35,10
+ CONTROL "",140,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,377,157,35,10
+ CONTROL "",141,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,377,167,35,10
+ CONTROL "",150,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,377,247,35,10
+ CONTROL "",142,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,377,177,35,10
+ CONTROL "",143,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,377,187,35,10
+ CONTROL "",144,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,377,197,35,10
+ CONTROL "",145,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,377,207,35,10
+ CONTROL "",146,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,377,217,35,10
+ CONTROL "",147,"Button",BS_AUTO3STATE | BS_LEFT | BS_PUSHLIKE | WS_TABSTOP,377,227,35,10
+ EDITTEXT FILTER_BID,147,76,62,14,ES_UPPERCASE | ES_AUTOHSCROLL,0,HFILTER_BID
RTEXT "Filter BID",IDC_STATIC,104,78,38,8
END
-WELCOMEMSG DIALOG DISCARDABLE 26, 5, 365, 281
-STYLE WS_CHILD | WS_VISIBLE
+WELCOMEMSG DIALOG 26, 5, 365, 281
+STYLE DS_SETFONT | WS_CHILD | WS_VISIBLE
FONT 8, "System"
BEGIN
LTEXT "Normal User Welcome Message",IDC_STATIC,5,7,130,8
- EDITTEXT IDM_USERMSG,5,20,340,50,ES_MULTILINE | ES_AUTOVSCROLL |
- ES_AUTOHSCROLL | ES_WANTRETURN
+ EDITTEXT IDM_USERMSG,5,20,340,50,ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN
LTEXT "New User Welcome Message",IDC_STATIC,5,75,130,8
- EDITTEXT IDM_NEWUSERMSG,5,89,340,65,ES_MULTILINE | ES_AUTOVSCROLL |
- ES_AUTOHSCROLL | ES_WANTRETURN
+ EDITTEXT IDM_NEWUSERMSG,5,89,340,65,ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN
LTEXT "Expert User Welcome Message",IDC_STATIC,5,159,130,8
- EDITTEXT IDM_EXPERTUSERMSG,5,172,340,12,ES_MULTILINE |
- ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN
+ EDITTEXT IDM_EXPERTUSERMSG,5,172,340,12,ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN
DEFPUSHBUTTON "Save",IDM_MSGSAVE,166,264,50,14,BS_CENTER | BS_VCENTER
- LTEXT "$U : Callsign of the user $I : First name of the user $X Messages for user $x Unread messages",
- IDC_STATIC,0,222,365,8
- LTEXT "$L : Number of the latest message $N : Number of active messages. $Z : Last message read by user",
- IDC_STATIC,0,234,365,10
+ LTEXT "$U : Callsign of the user $I : First name of the user $X Messages for user $x Unread messages",IDC_STATIC,0,222,365,8
+ LTEXT "$L : Number of the latest message $N : Number of active messages. $Z : Last message read by user",IDC_STATIC,0,234,365,10
LTEXT "Signoff Message",IDC_STATIC,5,190,130,8
- EDITTEXT IDM_SIGNOFF,5,202,340,12,ES_MULTILINE | ES_AUTOVSCROLL |
- ES_AUTOHSCROLL | ES_WANTRETURN
- LTEXT "$F : Number of mesages to be forwarded to user (if a BBS)",
- IDC_STATIC,0,246,365,10
+ EDITTEXT IDM_SIGNOFF,5,202,340,12,ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN
+ LTEXT "$F : Number of mesages to be forwarded to user (if a BBS)",IDC_STATIC,0,246,365,10
END
-BBSPROMPTS DIALOG DISCARDABLE 26, 5, 381, 266
-STYLE WS_CHILD | WS_VISIBLE
+BBSPROMPTS DIALOG 26, 5, 381, 266
+STYLE DS_SETFONT | WS_CHILD | WS_VISIBLE
FONT 8, "System"
BEGIN
LTEXT "Normal User Prompt",IDC_STATIC,5,7,130,8
- EDITTEXT IDM_USERMSG,5,20,340,35,ES_MULTILINE | ES_AUTOVSCROLL |
- ES_AUTOHSCROLL | ES_WANTRETURN
+ EDITTEXT IDM_USERMSG,5,20,340,35,ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN
LTEXT "New User Prompt",IDC_STATIC,5,59,130,8
- EDITTEXT IDM_NEWUSERMSG,5,70,340,35,ES_MULTILINE | ES_AUTOVSCROLL |
- ES_AUTOHSCROLL | ES_WANTRETURN
+ EDITTEXT IDM_NEWUSERMSG,5,70,340,35,ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN
LTEXT "Expert User Prompt",IDC_STATIC,5,110,130,8
- EDITTEXT IDM_EXPERTUSERMSG,5,120,340,35,ES_MULTILINE |
- ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN
- DEFPUSHBUTTON "Save",IDM_PROMPTSAVE,166,250,50,14,BS_CENTER |
- BS_VCENTER
- LTEXT "$U : Callsign of the user $I : First name of the user $X Messages for user $x Unread messages",
- IDC_STATIC,2,165,353,8
- LTEXT "$L : Number of the latest message $N : Number of active messages. $Z : Last message read by user",
- IDC_STATIC,3,175,347,10
+ EDITTEXT IDM_EXPERTUSERMSG,5,120,340,35,ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN
+ DEFPUSHBUTTON "Save",IDM_PROMPTSAVE,166,250,50,14,BS_CENTER | BS_VCENTER
+ LTEXT "$U : Callsign of the user $I : First name of the user $X Messages for user $x Unread messages",IDC_STATIC,2,165,353,8
+ LTEXT "$L : Number of the latest message $N : Number of active messages. $Z : Last message read by user",IDC_STATIC,3,175,347,10
END
-IDD_MAINTRESULTS DIALOG DISCARDABLE 0, 0, 181, 114
-STYLE DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_THICKFRAME
+IDD_MAINTRESULTS DIALOG 0, 0, 181, 114
+STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_THICKFRAME
CAPTION "Maintenance Results"
FONT 8, "System"
BEGIN
@@ -861,13 +608,12 @@ BEGIN LTEXT "Static",IDC_BIDSLEFT,146,69,30,10
END
-IDD_EDITWP DIALOG DISCARDABLE 0, 0, 398, 265
-STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
+IDD_EDITWP DIALOG 0, 0, 398, 265
+STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "EDIT WP Record"
FONT 8, "MS Sans Serif"
BEGIN
- COMBOBOX IDC_WP,9,9,76,190,CBS_SIMPLE | CBS_SORT | CBS_UPPERCASE |
- WS_VSCROLL | WS_TABSTOP
+ COMBOBOX IDC_WP,9,9,76,190,CBS_SIMPLE | CBS_SORT | CBS_UPPERCASE | WS_VSCROLL | WS_TABSTOP
LTEXT "Name",-1,100,11,47,10
EDITTEXT IDC_WPNAME,165,10,128,12,ES_AUTOHSCROLL
LTEXT "Home BBS 1",-1,100,26,53,10
@@ -892,13 +638,12 @@ BEGIN LTEXT "Seen",-1,100,186,47,12
EDITTEXT IDC_CHANGED,165,170,59,12,ES_AUTOHSCROLL
EDITTEXT IDC_SEEN,165,185,59,12,ES_AUTOHSCROLL
- PUSHBUTTON "Delete",IDC_DELETEWP,106,215,56,17,BS_CENTER |
- BS_VCENTER
+ PUSHBUTTON "Delete",IDC_DELETEWP,106,215,56,17,BS_CENTER | BS_VCENTER
PUSHBUTTON "Save",IDC_SAVEWP,171,216,56,17,BS_CENTER | BS_VCENTER
END
-IDD_UICONFIG DIALOG DISCARDABLE 0, 0, 400, 151
-STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
+IDD_UICONFIG DIALOG 0, 0, 400, 151
+STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "UI Configuration"
FONT 8, "System"
BEGIN
@@ -906,58 +651,48 @@ BEGIN PUSHBUTTON "Cancel",IDCANCEL,342,98,50,14
LTEXT "Mailfor Header",IDC_STATIC,5,5,50,10
EDITTEXT IDC_MAILFOR,61,3,331,12,ES_AUTOHSCROLL
- LTEXT "Send: Mail For Headers Null Mailfor",IDC_STATIC,242,
- 25,127,10
- LTEXT "(use \\r to insert newline in message)",IDC_STATIC,62,
- 16,125,10
+ LTEXT "Send: Mail For Headers Null Mailfor",IDC_STATIC,242,25,127,10
+ LTEXT "(use \\r to insert newline in message)",IDC_STATIC,62,16,125,10
END
-IDD_CHATCOLCONFIG DIALOG DISCARDABLE 0, 0, 224, 120
-STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
+IDD_CHATCOLCONFIG DIALOG 0, 0, 224, 120
+STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Chat Colour Configuration"
FONT 8, "System"
BEGIN
DEFPUSHBUTTON "Save",IDOK,50,95,50,14
PUSHBUTTON "Close",IDCANCEL,120,95,50,14
- COMBOBOX IDC_CHATCALLS,10,5,100,60,CBS_DROPDOWNLIST | CBS_SORT |
- WS_VSCROLL | WS_TABSTOP
- COMBOBOX IDC_CHATCOLOURS,115,5,100,60,CBS_DROPDOWNLIST |
- CBS_OWNERDRAWFIXED | WS_VSCROLL | WS_TABSTOP
+ COMBOBOX IDC_CHATCALLS,10,5,100,60,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP
+ COMBOBOX IDC_CHATCOLOURS,115,5,100,60,CBS_DROPDOWNLIST | CBS_OWNERDRAWFIXED | WS_VSCROLL | WS_TABSTOP
END
-IDD_UPDATECHATMAP DIALOG DISCARDABLE 0, 0, 274, 146
-STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
+IDD_UPDATECHATMAP DIALOG 0, 0, 274, 146
+STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Update Chat Map"
FONT 8, "System"
BEGIN
- LTEXT "Click Help for full information about the Chat Network Map",
- IDC_STATIC,5,10,195,15
+ LTEXT "Click Help for full information about the Chat Network Map",IDC_STATIC,5,10,195,15
DEFPUSHBUTTON "? Help",IDC_MAPHELP,220,10,33,11,BS_CENTER | BS_VCENTER
LTEXT "Position",IDC_STATIC,5,30,35,10
EDITTEXT IDC_MAPPOSITION,5,45,145,15,ES_AUTOHSCROLL
LTEXT "Popup Box Text. ",IDC_STATIC,5,65,70,9
- EDITTEXT IDC_POPUPTEXT,5,80,200,35,ES_MULTILINE | ES_AUTOHSCROLL |
- WS_HSCROLL
+ EDITTEXT IDC_POPUPTEXT,5,80,200,35,ES_MULTILINE | ES_AUTOHSCROLL | WS_HSCROLL
LTEXT "Popup Mode",IDC_STATIC,215,80,49,10
- CONTROL "Hover",IDC_HOVER,"Button",BS_AUTORADIOBUTTON,219,92,45,
- 10
- CONTROL "Click",IDC_CLICK,"Button",BS_AUTORADIOBUTTON,219,104,45,
- 10
+ CONTROL "Hover",IDC_HOVER,"Button",BS_AUTORADIOBUTTON,219,92,45,10
+ CONTROL "Click",IDC_CLICK,"Button",BS_AUTORADIOBUTTON,219,104,45,10
DEFPUSHBUTTON "Send to Map System",IDSENDTOMAP,5,125,90,14
DEFPUSHBUTTON "Save",IDOK,100,125,35,14
PUSHBUTTON "Cancel",IDCANCEL,140,125,40,14
END
IDD_MSGFROMCLIPBOARD DIALOGEX 0, 0, 442, 306
-STYLE WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
+STYLE DS_SETFONT | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
CAPTION "Send Message"
FONT 8, "System", 0, 0, 0x1
BEGIN
PUSHBUTTON "Send",IDSEND,333,5,50,14
PUSHBUTTON "Cancel",IDCANCEL,333,25,50,14
- EDITTEXT IDC_EDIT1,4,57,431,245,ES_MULTILINE | ES_AUTOVSCROLL |
- ES_AUTOHSCROLL | ES_WANTRETURN | WS_VSCROLL | WS_HSCROLL,
- WS_EX_ACCEPTFILES
+ EDITTEXT IDC_EDIT1,4,57,431,245,ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN | WS_VSCROLL | WS_HSCROLL,WS_EX_ACCEPTFILES
LTEXT "To:",IDC_STATIC,66,8,12,8
EDITTEXT IDC_MSGTO,83,7,147,12,ES_UPPERCASE | ES_AUTOHSCROLL
LTEXT "Title:",IDC_STATIC,8,26,22,8
@@ -965,43 +700,37 @@ BEGIN LTEXT "BID:",IDC_STATIC,240,8,20,8
EDITTEXT IDC_MSGBID,262,7,65,12,ES_UPPERCASE | ES_AUTOHSCROLL
LTEXT "Type",IDC_STATIC,8,8,20,8
- COMBOBOX IDC_MSGTYPE,34,7,25,55,CBS_DROPDOWNLIST | WS_VSCROLL |
- WS_TABSTOP
+ COMBOBOX IDC_MSGTYPE,34,7,25,55,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
PUSHBUTTON "Select",IDSelectFiles,333,42,50,14
LTEXT "Attachments",IDC_STATIC,8,43,42,8
EDITTEXT IDC_ATTACHMENTS,50,41,277,12,ES_AUTOHSCROLL
END
-IDD_HRHELP DIALOG DISCARDABLE 0, 0, 415, 182
-STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
+IDD_HRHELP DIALOG 0, 0, 415, 182
+STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Hierarchical Forwarding Help"
FONT 8, "System"
BEGIN
DEFPUSHBUTTON "OK",IDOK,182,158,50,14
- EDITTEXT IDC_HRTEXT,4,4,405,150,ES_MULTILINE | ES_AUTOVSCROLL |
- ES_AUTOHSCROLL | ES_READONLY | WS_VSCROLL | WS_HSCROLL
+ EDITTEXT IDC_HRTEXT,4,4,405,150,ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_READONLY | WS_VSCROLL | WS_HSCROLL
END
IDD_EDITMSGTEXT DIALOGEX 0, 0, 492, 356
-STYLE WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
+STYLE DS_SETFONT | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
CAPTION "Edit Message"
FONT 8, "Fixedsys", 0, 0, 0x1
BEGIN
- EDITTEXT IDC_MESSAGE,4,25,480,327,ES_MULTILINE | ES_AUTOVSCROLL |
- ES_AUTOHSCROLL | ES_WANTRETURN | WS_VSCROLL | WS_HSCROLL,
- WS_EX_ACCEPTFILES
+ EDITTEXT IDC_MESSAGE,4,25,480,327,ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN | WS_VSCROLL | WS_HSCROLL,WS_EX_ACCEPTFILES
PUSHBUTTON "Save",IDSAVE,5,5,40,17
PUSHBUTTON "Cancel",IDCANCEL,125,5,40,17
- PUSHBUTTON "Save Attachments",IDC_SAVEATTACHMENTS,50,5,70,17,
- WS_DISABLED
+ PUSHBUTTON "Save Attachments",IDC_SAVEATTACHMENTS,50,5,70,17,WS_DISABLED
END
-MAINT DIALOG DISCARDABLE 26, 5, 382, 298
-STYLE WS_CHILD | WS_VISIBLE
+MAINT DIALOG 26, 5, 382, 298
+STYLE DS_SETFONT | WS_CHILD | WS_VISIBLE
FONT 8, "System"
BEGIN
- LTEXT "This sets the parameters for deleting old messages. Specify length of time (in days) for messages to be kept before being deleted",
- IDC_STATIC,149,13,226,22
+ LTEXT "This sets the parameters for deleting old messages. Specify length of time (in days) for messages to be kept before being deleted",IDC_STATIC,149,13,226,22
LTEXT "Read",IDC_STATIC,159,46,46,10
EDITTEXT IDM_PR,224,46,20,12,ES_CENTER | ES_AUTOHSCROLL
LTEXT "Unread",IDC_STATIC,159,61,46,10
@@ -1016,50 +745,36 @@ BEGIN EDITTEXT IDM_BNF,324,61,20,12,ES_CENTER | ES_AUTOHSCROLL
GROUPBOX "Personals",IDC_STATIC,149,36,108,107
GROUPBOX "Bulletins",IDC_STATIC,259,36,103,44
- LTEXT "The following boxes allow you to specify different values for different Bulletin origins and destinations. Normally these apply to Sent Messages, to apply to unsent, check box below",
- IDC_STATIC,151,148,214,27
- LTEXT "Specify Call, Lifetime, eg ALL, 10",IDC_STATIC,151,176,
- 154,8
+ LTEXT "The following boxes allow you to specify different values for different Bulletin origins and destinations. Normally these apply to Sent Messages, to apply to unsent, check box below",IDC_STATIC,151,148,214,27
+ LTEXT "Specify Call, Lifetime, eg ALL, 10",IDC_STATIC,151,176,154,8
LTEXT "From",IDC_STATIC,176,189,28,9
- EDITTEXT IDM_LTFROM,151,202,64,55,ES_MULTILINE | ES_UPPERCASE |
- ES_AUTOVSCROLL | ES_WANTRETURN
+ EDITTEXT IDM_LTFROM,151,202,64,55,ES_MULTILINE | ES_UPPERCASE | ES_AUTOVSCROLL | ES_WANTRETURN
LTEXT "To",IDC_STATIC,247,189,27,10
- EDITTEXT IDM_LTTO,221,202,64,55,ES_MULTILINE | ES_UPPERCASE |
- ES_AUTOVSCROLL | ES_WANTRETURN
+ EDITTEXT IDM_LTTO,221,202,64,55,ES_MULTILINE | ES_UPPERCASE | ES_AUTOVSCROLL | ES_WANTRETURN
LTEXT "At",IDC_STATIC,316,189,15,8
- EDITTEXT IDM_LTAT,289,202,64,55,ES_MULTILINE | ES_UPPERCASE |
- ES_AUTOVSCROLL | ES_WANTRETURN
- DEFPUSHBUTTON "Save",IDM_MAINTSAVE,166,279,50,14,BS_CENTER |
- BS_VCENTER
+ EDITTEXT IDM_LTAT,289,202,64,55,ES_MULTILINE | ES_UPPERCASE | ES_AUTOVSCROLL | ES_WANTRETURN
+ DEFPUSHBUTTON "Save",IDM_MAINTSAVE,166,279,50,14,BS_CENTER | BS_VCENTER
GROUPBOX "Lifetimes",IDC_STATIC,144,0,231,275
GROUPBOX "Parameters",IDC_STATIC,3,3,133,275
LTEXT "Max Message Number",IDC_STATIC,7,68,77,10
LTEXT "BID Lifetime (Days)",IDC_STATIC,7,87,77,10
- LTEXT "Maintenance Time (UTC) Enter as HHMM",IDC_STATIC,7,21,
- 83,25
+ LTEXT "Maintenance Time (UTC) Enter as HHMM",IDC_STATIC,7,21,83,25
EDITTEXT IDC_MAXMSG,102,67,25,12,ES_CENTER
EDITTEXT IDC_BIDLIFETIME,102,86,25,12,ES_CENTER | ES_AUTOHSCROLL
EDITTEXT IDC_MAINTTIME,102,23,25,12,ES_CENTER | ES_AUTOHSCROLL
LTEXT "Log File Lifetime (Days)",IDC_STATIC,7,107,80,10
EDITTEXT IDC_LOGLIFETIME,102,105,25,12,ES_CENTER | ES_AUTOHSCROLL
- CONTROL "Delete Log and Message Files to Recycle Bin",
- IDC_DELETETORECYCLE,"Button",BS_AUTOCHECKBOX |
- BS_LEFTTEXT | BS_MULTILINE | WS_TABSTOP,5,142,115,20
- CONTROL "Suppress Mailing of Housekeeping Results",
- IDC_MAINTNOMAIL,"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT |
- BS_MULTILINE | WS_TABSTOP,5,182,115,20
- CONTROL "Generate Traffic Report",IDC_MAINTTRAFFIC,"Button",
- BS_AUTOCHECKBOX | BS_LEFTTEXT | BS_MULTILINE |
- WS_TABSTOP,5,204,115,10
- CONTROL "Send Non-delivery Notifications for P and T messages",
- IDC_MAINTNONDELIVERY,"Button",BS_AUTOCHECKBOX |
- BS_LEFTTEXT | BS_MULTILINE | WS_TABSTOP,5,162,115,20
+ CONTROL "Delete Log and Message Files to Recycle Bin",IDC_DELETETORECYCLE,
+ "Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | BS_MULTILINE | WS_TABSTOP,5,142,115,20
+ CONTROL "Suppress Mailing of Housekeeping Results",IDC_MAINTNOMAIL,
+ "Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | BS_MULTILINE | WS_TABSTOP,5,182,115,20
+ CONTROL "Generate Traffic Report",IDC_MAINTTRAFFIC,"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | BS_MULTILINE | WS_TABSTOP,5,204,115,10
+ CONTROL "Send Non-delivery Notifications for P and T messages",IDC_MAINTNONDELIVERY,
+ "Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | BS_MULTILINE | WS_TABSTOP,5,162,115,20
CONTROL "Apply Overrides to Unsent Bulls",IDC_OVERRIDEUNSENT,
- "Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | BS_MULTILINE |
- WS_TABSTOP,153,261,195,10
+ "Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | BS_MULTILINE | WS_TABSTOP,153,261,195,10
LTEXT "Delete Inactive Users (Days)",IDC_STATIC,7,127,93,10
- EDITTEXT IDC_USERLIFETIME,102,125,25,12,ES_CENTER |
- ES_AUTOHSCROLL
+ EDITTEXT IDC_USERLIFETIME,102,125,25,12,ES_CENTER | ES_AUTOHSCROLL
GROUPBOX "NTS",IDC_STATIC,259,80,102,62
LTEXT "Forwarded",IDC_STATIC,264,109,49,10
EDITTEXT IDM_NTSF,324,108,20,12,ES_CENTER | ES_AUTOHSCROLL
@@ -1067,100 +782,69 @@ BEGIN EDITTEXT IDM_NTSU,324,123,20,12,ES_CENTER | ES_AUTOHSCROLL
LTEXT "Delivered",IDC_STATIC,264,94,49,10
EDITTEXT IDM_NTSD,324,94,20,12,ES_CENTER | ES_AUTOHSCROLL
- CONTROL "Save Registry",IDC_MAINTSAVEREG2,"Button",
- BS_AUTOCHECKBOX | BS_LEFTTEXT | BS_MULTILINE |
- WS_TABSTOP,5,222,115,10
+ CONTROL "Save Registry",IDC_MAINTSAVEREG2,"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | BS_MULTILINE | WS_TABSTOP,5,222,115,10
LTEXT "Maintenance Interval (Hrs)",IDC_STATIC,7,47,93,10
- EDITTEXT IDC_MAINTINTERVAL,102,45,25,12,ES_CENTER |
- ES_AUTOHSCROLL
+ EDITTEXT IDC_MAINTINTERVAL,102,45,25,12,ES_CENTER | ES_AUTOHSCROLL
END
-FILTERS DIALOG DISCARDABLE 26, 5, 382, 371
-STYLE WS_CHILD | WS_VISIBLE
+FILTERS DIALOG 26, 5, 382, 371
+STYLE DS_SETFONT | WS_CHILD | WS_VISIBLE
FONT 8, "System"
BEGIN
LTEXT "Reject Messages:",IDC_STATIC,162,26,70,10
LTEXT "From",IDC_STATIC,83,137,28,10
- EDITTEXT IDC_HOLDFROM,58,149,64,83,ES_MULTILINE | ES_UPPERCASE |
- ES_AUTOVSCROLL | ES_WANTRETURN
+ EDITTEXT IDC_HOLDFROM,58,149,64,83,ES_MULTILINE | ES_UPPERCASE | ES_AUTOVSCROLL | ES_WANTRETURN
LTEXT "To",IDC_STATIC,152,137,27,10
- EDITTEXT IDC_HOLDTO,126,149,64,83,ES_MULTILINE | ES_UPPERCASE |
- ES_AUTOVSCROLL | ES_WANTRETURN
+ EDITTEXT IDC_HOLDTO,126,149,64,83,ES_MULTILINE | ES_UPPERCASE | ES_AUTOVSCROLL | ES_WANTRETURN
LTEXT "At",IDC_STATIC,223,137,15,10
- EDITTEXT IDC_HOLDAT,194,149,64,83,ES_MULTILINE | ES_UPPERCASE |
- ES_AUTOVSCROLL | ES_WANTRETURN
- DEFPUSHBUTTON "Save",IDC_FILTERSAVE,171,341,50,14,BS_CENTER |
- BS_VCENTER
+ EDITTEXT IDC_HOLDAT,194,149,64,83,ES_MULTILINE | ES_UPPERCASE | ES_AUTOVSCROLL | ES_WANTRETURN
+ DEFPUSHBUTTON "Save",IDC_FILTERSAVE,171,341,50,14,BS_CENTER | BS_VCENTER
LTEXT "From",IDC_STATIC,83,40,28,10
- EDITTEXT IDC_REJFROM,58,52,64,67,ES_MULTILINE | ES_UPPERCASE |
- ES_AUTOVSCROLL | ES_WANTRETURN
+ EDITTEXT IDC_REJFROM,58,52,64,67,ES_MULTILINE | ES_UPPERCASE | ES_AUTOVSCROLL | ES_WANTRETURN
LTEXT "To",IDC_STATIC,154,40,27,10
- EDITTEXT IDC_REJTO,126,52,64,68,ES_MULTILINE | ES_UPPERCASE |
- ES_AUTOVSCROLL | ES_WANTRETURN
+ EDITTEXT IDC_REJTO,126,52,64,68,ES_MULTILINE | ES_UPPERCASE | ES_AUTOVSCROLL | ES_WANTRETURN
LTEXT "At",IDC_STATIC,223,40,15,10
- EDITTEXT IDC_REJAT,194,52,64,68,ES_MULTILINE | ES_UPPERCASE |
- ES_AUTOVSCROLL | ES_WANTRETURN
+ EDITTEXT IDC_REJAT,194,52,64,68,ES_MULTILINE | ES_UPPERCASE | ES_AUTOVSCROLL | ES_WANTRETURN
LTEXT "Message Filtering Setup.",IDC_STATIC,152,10,95,15
LTEXT "Hold Messages:",IDC_STATIC,166,128,60,9
- EDITTEXT IDC_REJBID,262,52,64,68,ES_MULTILINE | ES_UPPERCASE |
- ES_AUTOVSCROLL | ES_WANTRETURN
- EDITTEXT IDC_HOLDBID,262,149,64,83,ES_MULTILINE | ES_UPPERCASE |
- ES_AUTOVSCROLL | ES_WANTRETURN
+ EDITTEXT IDC_REJBID,262,52,64,68,ES_MULTILINE | ES_UPPERCASE | ES_AUTOVSCROLL | ES_WANTRETURN
+ EDITTEXT IDC_HOLDBID,262,149,64,83,ES_MULTILINE | ES_UPPERCASE | ES_AUTOVSCROLL | ES_WANTRETURN
LTEXT "BID",IDC_STATIC,289,137,15,10
LTEXT "BID",IDC_STATIC,289,41,15,10
- EDITTEXT IDC_REJSYS,58,265,270,66,ES_MULTILINE | ES_UPPERCASE |
- ES_AUTOVSCROLL | ES_WANTRETURN
- LTEXT "Composite Rules (like fbb reject.sys)",IDC_STATIC,152,
- 236,134,9
- LTEXT "Action, Type, from, @BBS, to, BID, maximum size",
- IDC_STATIC,59,251,247,9
+ EDITTEXT IDC_REJSYS,58,265,270,66,ES_MULTILINE | ES_UPPERCASE | ES_AUTOVSCROLL | ES_WANTRETURN
+ LTEXT "Composite Rules (like fbb reject.sys)",IDC_STATIC,152,236,134,9
+ LTEXT "Action, Type, from, @BBS, to, BID, maximum size",IDC_STATIC,59,251,247,9
END
-WPUPDATE DIALOG DISCARDABLE 26, 5, 382, 287
-STYLE WS_CHILD | WS_VISIBLE
+WPUPDATE DIALOG 26, 5, 382, 287
+STYLE DS_SETFONT | WS_CHILD | WS_VISIBLE
FONT 8, "System"
BEGIN
- CONTROL "Send WP Updates",IDC_SENDWP,"Button",BS_AUTOCHECKBOX |
- BS_LEFTTEXT | WS_TABSTOP,90,18,71,10
- EDITTEXT IDC_WPTO,112,82,154,113,ES_MULTILINE | ES_UPPERCASE |
- ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN |
- WS_VSCROLL
- COMBOBOX IDC_WPTYPE,193,17,19,55,CBS_DROPDOWNLIST | WS_VSCROLL |
- WS_TABSTOP
+ CONTROL "Send WP Updates",IDC_SENDWP,"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | WS_TABSTOP,90,18,71,10
+ EDITTEXT IDC_WPTO,112,82,154,113,ES_MULTILINE | ES_UPPERCASE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN | WS_VSCROLL
+ COMBOBOX IDC_WPTYPE,193,17,19,55,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
LTEXT "Type",IDC_STATIC,172,18,21,10
DEFPUSHBUTTON "Save",IDC_WPSAVE,165,204,50,14,BS_CENTER | BS_VCENTER
- CONTROL "Reject WP Bulls",IDC_FILTERWPB,"Button",BS_AUTOCHECKBOX |
- BS_LEFTTEXT | WS_TABSTOP,222,18,71,10
- LTEXT "Send To.\rBPQMail only automatically processes messages with TO of WP, so for P messages format should be WP@BBSCALL. ",
- IDC_STATIC,98,38,176,35
+ CONTROL "Reject WP Bulls",IDC_FILTERWPB,"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | WS_TABSTOP,222,18,71,10
+ LTEXT "Send To.\rBPQMail only automatically processes messages with TO of WP, so for P messages format should be WP@BBSCALL. ",IDC_STATIC,98,38,176,35
END
-IDD_RMSBULLDLG DIALOG DISCARDABLE 0, 0, 277, 258
-STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
+IDD_RMSBULLDLG DIALOG 0, 0, 277, 258
+STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "RMS Express Bull Configuration"
FONT 8, "MS Sans Serif"
BEGIN
DEFPUSHBUTTON "OK",IDOK,66,237,50,14
PUSHBUTTON "Cancel",IDCANCEL,164,237,50,14
- EDITTEXT IDC_TOCALLS,82,76,54,112,ES_MULTILINE | ES_UPPERCASE |
- ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN |
- WS_VSCROLL
- EDITTEXT IDC_TOCALLS2,144,76,54,112,ES_MULTILINE | ES_UPPERCASE |
- ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN |
- WS_VSCROLL
- EDITTEXT IDC_TOCALLS3,208,76,54,112,ES_MULTILINE | ES_UPPERCASE |
- ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN |
- WS_VSCROLL
- EDITTEXT IDC_TOCALLS4,18,76,54,112,ES_MULTILINE | ES_UPPERCASE |
- ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN |
- WS_VSCROLL
+ EDITTEXT IDC_TOCALLS,82,76,54,112,ES_MULTILINE | ES_UPPERCASE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN | WS_VSCROLL
+ EDITTEXT IDC_TOCALLS2,144,76,54,112,ES_MULTILINE | ES_UPPERCASE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN | WS_VSCROLL
+ EDITTEXT IDC_TOCALLS3,208,76,54,112,ES_MULTILINE | ES_UPPERCASE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN | WS_VSCROLL
+ EDITTEXT IDC_TOCALLS4,18,76,54,112,ES_MULTILINE | ES_UPPERCASE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN | WS_VSCROLL
LTEXT "Common",IDC_STATIC,63,47,48,8
LTEXT "User Specific",IDC_STATIC,174,47,48,8
LTEXT "TO AT",IDC_STATIC,39,62,79,8
- LTEXT "TO AT",IDC_STATIC,163,62,79,
- 8
- LTEXT "This defines Bulls that will be downloaded to RMS Express Users. There are two lists, one for all RMS Express users and one per User. The lists will be combined, Updating the Common list will affect all users.",
- IDC_STATIC,7,7,242,37
+ LTEXT "TO AT",IDC_STATIC,163,62,79,8
+ LTEXT "This defines Bulls that will be downloaded to RMS Express Users. There are two lists, one for all RMS Express users and one per User. The lists will be combined, Updating the Common list will affect all users.",IDC_STATIC,7,7,242,37
END
@@ -1170,8 +854,12 @@ END //
#ifdef APSTUDIO_INVOKED
-GUIDELINES DESIGNINFO MOVEABLE PURE
+GUIDELINES DESIGNINFO
BEGIN
+ "BPQMAIL", DIALOG
+ BEGIN
+ END
+
102, DIALOG
BEGIN
TOPMARGIN, 47
@@ -1286,7 +974,7 @@ END // Menu
//
-IDC_BPQMailChat MENU DISCARDABLE
+IDC_BPQMailChat MENU
BEGIN
POPUP "Actions"
BEGIN
@@ -1306,7 +994,6 @@ BEGIN MENUITEM "Housekeeping", IDM_HOUSEKEEPING
MENUITEM "Send Message", ID_ACTIONS_SENDMESSAGE
MENUITEM "Send Msg from Clipboard", ID_ACTIONS_SENDMSGFROMCLIPBOARD
-
MENUITEM "Rerun Message Routing", RESCANMSGS
MENUITEM "Import Messages", IDM_IMPORT
END
@@ -1331,7 +1018,7 @@ BEGIN END
END
-CONSOLEMENU MENU DISCARDABLE
+CONSOLEMENU MENU
BEGIN
POPUP "Options"
BEGIN
@@ -1357,7 +1044,7 @@ BEGIN END
END
-MENU_2 MENU DISCARDABLE
+MENU_2 MENU
BEGIN
POPUP "Monitor"
BEGIN
@@ -1371,7 +1058,7 @@ BEGIN END
END
-MENU_3 MENU DISCARDABLE
+MENU_3 MENU
BEGIN
POPUP "Edit"
BEGIN
@@ -1380,7 +1067,7 @@ BEGIN END
END
-MENU_1 MENU DISCARDABLE
+MENU_1 MENU
BEGIN
POPUP "Edit"
BEGIN
@@ -1395,7 +1082,7 @@ END // Accelerator
//
-IDC_TELNETSERVER ACCELERATORS MOVEABLE PURE
+IDC_TELNETSERVER ACCELERATORS
BEGIN
"?", IDM_ABOUT, ASCII, ALT
"/", IDM_ABOUT, ASCII, ALT
@@ -1408,12 +1095,12 @@ END // TEXTINCLUDE
//
-1 TEXTINCLUDE MOVEABLE PURE
+1 TEXTINCLUDE
BEGIN
"BPQMailrc.h\0"
END
-2 TEXTINCLUDE MOVEABLE PURE
+2 TEXTINCLUDE
BEGIN
"#define APSTUDIO_HIDDEN_SYMBOLS\r\n"
"#include ""AFXRES.h""\r\n"
@@ -1423,7 +1110,7 @@ BEGIN "\0"
END
-3 TEXTINCLUDE MOVEABLE PURE
+3 TEXTINCLUDE
BEGIN
"#define MAIL\r\n"
"#include ""Versions.h""\r\n"
@@ -1431,7 +1118,7 @@ BEGIN "\0"
END
-1 TEXTINCLUDE MOVEABLE PURE
+1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
@@ -1444,19 +1131,24 @@ END // AFX_DIALOG_LAYOUT
//
-IDD_USEREDIT AFX_DIALOG_LAYOUT MOVEABLE PURE
+IDD_USEREDIT AFX_DIALOG_LAYOUT
+BEGIN
+ 0
+END
+
+IDD_FORWARDING AFX_DIALOG_LAYOUT
BEGIN
- 0x0000
+ 0
END
-IDD_FORWARDING AFX_DIALOG_LAYOUT MOVEABLE PURE
+FILTERS AFX_DIALOG_LAYOUT
BEGIN
- 0x0000
+ 0
END
-FILTERS AFX_DIALOG_LAYOUT MOVEABLE PURE
+BPQMAIL AFX_DIALOG_LAYOUT
BEGIN
- 0x0000
+ 0
END
@@ -1465,13 +1157,13 @@ END // String Table
//
-STRINGTABLE DISCARDABLE
+STRINGTABLE
BEGIN
IDS_APP_TITLE "BPQMail"
IDC_BPQMailChat "BPQMail"
END
-#endif // English (U.K.) resources
+#endif // English (United Kingdom) resources
/////////////////////////////////////////////////////////////////////////////
diff --git a/FBBRoutines.c b/FBBRoutines.c index 1810bf9..c283f32 100644 --- a/FBBRoutines.c +++ b/FBBRoutines.c @@ -27,6 +27,8 @@ along with LinBPQ/BPQ32. If not, see http://www.gnu.org/licenses void _GetSemaphore(struct SEM * Semaphore, int ID, char * File, int Line);
+void DeleteRestartData(CIRCUIT * conn);
+
int32_t Encode(char * in, char * out, int32_t inlen, BOOL B1Protocol, int Compress);
void MQTTMessageEvent(void* message);
@@ -41,6 +43,130 @@ int B2RestartCount = 0; extern char ProperBaseDir[];
+char RestartDir[MAX_PATH] = "";
+
+void GetRestartData()
+{
+ int i;
+ struct FBBRestartData Restart;
+ struct FBBRestartData * RestartRec;
+ char MsgFile[MAX_PATH];
+ FILE * hFile;
+ int FileSize;
+ struct stat STAT;
+ size_t ReadLen = 0;
+ time_t Age;
+
+ strcpy(RestartDir, MailDir);
+ strcat(RestartDir, "/Restart");
+
+ // Make sure RestartDir exists
+
+#ifdef WIN32
+ CreateDirectory(RestartDir, NULL); // Just in case
+#else
+ mkdir(RestartDir, S_IRWXU | S_IRWXG | S_IRWXO);
+ chmod(RestartDir, S_IRWXU | S_IRWXG | S_IRWXO);
+#endif
+
+ // look for restart files. These will be numbered from 1 up
+
+ for (i = 1; 1; i++)
+ {
+ sprintf_s(MsgFile, sizeof(MsgFile), "%s/%d", RestartDir, i);
+
+ if (stat(MsgFile, &STAT) == -1)
+ break;
+
+ FileSize = STAT.st_size;
+
+ Age = time(NULL) - STAT.st_ctime;
+
+ if (Age > 86400 * 2) // Max 2 days
+ continue;
+
+ hFile = fopen(MsgFile, "rb");
+
+ if (hFile == NULL)
+ break;
+
+ // Read Restart Record
+
+ fread(&Restart, 1, sizeof(struct FBBRestartData), hFile);
+
+ if ((Restart.MailBufferSize + sizeof(struct FBBRestartData)) != FileSize) // Duff file
+ {
+ fclose(hFile);
+ break;
+ }
+
+ RestartRec = zalloc(sizeof (struct FBBRestartData));
+
+ GetSemaphore(&AllocSemaphore, 0);
+
+ RestartData = realloc(RestartData,(++RestartCount+1) * sizeof(void *));
+ RestartData[RestartCount] = RestartRec;
+
+ FreeSemaphore(&AllocSemaphore);
+
+ memcpy(RestartRec, &Restart, sizeof(struct FBBRestartData));
+ RestartRec->MailBuffer = malloc(RestartRec->MailBufferSize);
+ ReadLen = fread(RestartRec->MailBuffer, 1, RestartRec->MailBufferSize, hFile);
+
+ Logprintf(LOG_BBS, 0, '?', "Restart Data for %s %s Len %d Loaded", RestartRec->Call, RestartRec->bid, RestartRec->length);
+ fclose(hFile);
+ }
+}
+
+
+void SaveRestartData()
+{
+ // Save restart data to file so we can reload on restart
+ // Restart data has pointers to buffers so we must save copy of data and reconstitue on restart
+
+ // Delete and resave all restart data to keep restart directory clean
+
+ int i, n = 1;
+ char MsgFile[MAX_PATH];
+ FILE * hFile;
+ size_t WriteLen=0;
+ struct FBBRestartData * RestartRec = NULL;
+ struct stat STAT;
+ time_t NOW = time(NULL);
+
+
+ for (i = 1; 1; i++)
+ {
+ sprintf_s(MsgFile, sizeof(MsgFile), "%s/%d", RestartDir, i);
+
+ if (stat(MsgFile, &STAT) == -1)
+ break;
+
+ DeleteFile(MsgFile);
+ }
+
+ for (i = 1; i <= RestartCount; i++)
+ {
+ RestartRec = RestartData[i];
+
+ if (RestartRec == 0)
+ return; // Shouldn't happen!
+
+ if ((NOW - RestartRec->TimeCreated) > 86400 * 2) // Max 2 days
+ continue;
+
+ sprintf_s(MsgFile, sizeof(MsgFile), "%s/%d", RestartDir, n++);
+
+ hFile = fopen(MsgFile, "wb");
+
+ if (hFile)
+ {
+ WriteLen = fwrite(RestartRec, 1, sizeof(struct FBBRestartData), hFile); // Save Header
+ WriteLen = fwrite(RestartRec->MailBuffer, 1, RestartRec->MailBufferSize, hFile); // Save Data
+ fclose(hFile);
+ }
+ }
+}
VOID FBBputs(CIRCUIT * conn, char * buf)
{
// Sends to user and logs
@@ -985,12 +1111,12 @@ loop: {
RestartRec = RestartData[i];
- if ((RestartRec->UserPointer == conn->UserPointer)
- && (strcmp(RestartRec->TempMsg->bid, conn->TempMsg->bid) == 0))
+ if ((strcmp(RestartRec->Call, conn->UserPointer->Call) == 0)
+ && (strcmp(RestartRec->bid, conn->TempMsg->bid) == 0))
{
- if (RestartRec->TempMsg->length <= offset)
+ if (RestartRec->length <= offset)
{
- conn->TempMsg->length = RestartRec->TempMsg->length;
+ conn->TempMsg->length = RestartRec->length;
conn->MailBuffer = RestartRec->MailBuffer;
conn->MailBufferSize = RestartRec->MailBufferSize;
@@ -1019,6 +1145,7 @@ loop: RestartData[n] = RestartData[n+1]; // move down all following entries
}
RestartCount--;
+ SaveRestartData();
}
}
@@ -1146,6 +1273,7 @@ loop: {
#endif
conn->InputMode = 0; // So we won't save Restart data if decode fails
+ DeleteRestartData(conn);
Decode(conn, 0); // Setup Next Message will reset InputMode if needed
#ifndef LINBPQ
}
@@ -1845,14 +1973,14 @@ VOID SaveFBBBinary(CIRCUIT * conn) {
RestartRec = RestartData[i];
- if ((RestartRec->UserPointer == conn->UserPointer)
- && (strcmp(RestartRec->TempMsg->bid, conn->TempMsg->bid) == 0))
+ if ((strcmp(RestartRec->Call, conn->UserPointer->Call) == 0)
+ && (strcmp(RestartRec->bid, conn->TempMsg->bid) == 0))
{
- // Fund it, so reuse
+ // Found it, so reuse
// If we have more data, reset retry count
- if (RestartRec->TempMsg->length < conn->TempMsg->length)
+ if (RestartRec->length < conn->TempMsg->length)
RestartRec->Count = 0;;
break;
@@ -1869,19 +1997,53 @@ VOID SaveFBBBinary(CIRCUIT * conn) RestartData[RestartCount] = RestartRec;
FreeSemaphore(&AllocSemaphore);
+ RestartRec->TimeCreated = time(NULL);
}
- RestartRec->UserPointer = conn->UserPointer;
- RestartRec->TempMsg = conn->TempMsg;
+ strcpy(RestartRec->Call, conn->UserPointer->Call);
+ RestartRec->length = conn->TempMsg->length;
+ strcpy(RestartRec->bid, conn->TempMsg->bid);
RestartRec->MailBuffer = conn->MailBuffer;
RestartRec->MailBufferSize = conn->MailBufferSize;
len = sprintf_s(Msg, sizeof(Msg), "Disconnect received from %s during Binary Transfer - %d Bytes Saved for restart",
conn->Callsign, conn->TempMsg->length);
+ SaveRestartData();
+
WriteLogLine(conn, '|',Msg, len, LOG_BBS);
}
+void DeleteRestartData(CIRCUIT * conn)
+{
+ struct FBBRestartData * RestartRec = NULL;
+ int i, n;
+
+ if (conn->TempMsg == NULL)
+ return;
+
+ for (i = 1; i <= RestartCount; i++)
+ {
+ RestartRec = RestartData[i];
+
+ if ((strcmp(RestartRec->Call, conn->UserPointer->Call) == 0)
+ && (strcmp(RestartRec->bid, conn->TempMsg->bid) == 0))
+ {
+ // Remove restrt data
+
+ for (n = i; n < RestartCount; n++)
+ {
+ RestartData[n] = RestartData[n+1]; // move down all following entries
+ }
+
+ RestartCount--;
+ SaveRestartData();
+ return;
+ }
+ }
+}
+
+
BOOL LookupRestart(CIRCUIT * conn, struct FBBHeaderLine * FBBHeader)
{
int i, n;
@@ -1895,8 +2057,8 @@ BOOL LookupRestart(CIRCUIT * conn, struct FBBHeaderLine * FBBHeader) {
RestartRec = RestartData[i];
- if ((RestartRec->UserPointer == conn->UserPointer)
- && (strcmp(RestartRec->TempMsg->bid, FBBHeader->BID) == 0))
+ if ((strcmp(RestartRec->Call, conn->UserPointer->Call) == 0)
+ && (strcmp(RestartRec->bid, FBBHeader->BID) == 0))
{
char Msg[120];
int len;
@@ -1918,15 +2080,16 @@ BOOL LookupRestart(CIRCUIT * conn, struct FBBHeaderLine * FBBHeader) }
RestartCount--;
+ SaveRestartData();
return FALSE;
}
len = sprintf_s(Msg, sizeof(Msg), "Restart Data found for %s - Requesting restart from %d",
- FBBHeader->BID, RestartRec->TempMsg->length);
+ FBBHeader->BID, RestartRec->length);
WriteLogLine(conn, '|',Msg, len, LOG_BBS);
- return (RestartRec->TempMsg->length);
+ return (RestartRec->length);
}
}
@@ -1,3860 +1,3860 @@ -/* -Copyright 2001-2018 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 -*/ - -// -// FLARQ Emulator/FLDIGI Interface for BPQ32 -// - -#define _CRT_SECURE_NO_DEPRECATE - -#include "CHeaders.h" - -int (WINAPI FAR *GetModuleFileNameExPtr)(); -int (WINAPI FAR *EnumProcessesPtr)(); - - -#include <stdio.h> -#include <time.h> - -#include "tncinfo.h" - -#include "bpq32.h" - -#define VERSION_MAJOR 2 -#define VERSION_MINOR 0 - -#define SD_RECEIVE 0x00 -#define SD_SEND 0x01 -#define SD_BOTH 0x02 - -#define DLE 0x10 -#define SOH 1 -#define STX 2 -#define EOT 4 - -#define FEND 0xC0 -#define FESC 0xDB -#define TFEND 0xDC -#define TFESC 0xDD - -#define TIMESTAMP 352 - -#define CONTIMEOUT 1200 - -#define AGWHDDRLEN sizeof(struct AGWHEADER) - -extern int (WINAPI FAR *GetModuleFileNameExPtr)(); - -//int ResetExtDriver(int num); -extern char * PortConfig[33]; -int SemHeldByAPI; - -struct TNCINFO * TNCInfo[34]; // Records are Malloc'd - -static void ConnecttoFLDigiThread(void * portptr); - -void CreateMHWindow(); -int Update_MH_List(struct in_addr ipad, char * call, char proto); - -static int ConnecttoFLDigi(); -static int ProcessReceivedData(int bpqport); -static int ProcessLine(char * buf, int Port); -int KillTNC(struct TNCINFO * TNC); -static int RestartTNC(struct TNCINFO * TNC); -VOID ProcessFLDigiPacket(struct TNCINFO * TNC, char * Message, int Len); -VOID ProcessFLDigiKISSPacket(struct TNCINFO * TNC, char * Message, int Len); -struct TNCINFO * GetSessionKey(char * key, struct TNCINFO * TNC); -VOID SendARQData(struct TNCINFO * TNC, UINT * Buffer); -static VOID DoMonitorHddr(struct TNCINFO * TNC, struct AGWHEADER * RXHeader, UCHAR * Msg); -VOID SendRPBeacon(struct TNCINFO * TNC); -VOID FLReleaseTNC(struct TNCINFO * TNC); -unsigned int CalcCRC(UCHAR * ptr, int Len); -VOID ARQTimer(struct TNCINFO * TNC); -VOID QueueAndSend(struct TNCINFO * TNC, struct ARQINFO * ARQ, SOCKET sock, char * Msg, int MsgLen); -VOID SaveAndSend(struct TNCINFO * TNC, struct ARQINFO * ARQ, SOCKET sock, char * Msg, int MsgLen); -VOID ProcessARQStatus(struct TNCINFO * TNC, struct ARQINFO * ARQ, char *Input); -VOID SendXMLPoll(struct TNCINFO * TNC); -static int ProcessXMLData(int port); -VOID CheckFLDigiData(struct TNCINFO * TNC); -VOID SendPacket(struct TNCINFO * TNC, UCHAR * Msg, int MsgLen); -int KissEncode(UCHAR * inbuff, UCHAR * outbuff, int len); -VOID SendXMLCommand(struct TNCINFO * TNC, char * Command, char * Value, char ParamType); -VOID FLSlowTimer(struct TNCINFO * TNC); -VOID SendKISSCommand(struct TNCINFO * TNC, char * Msg); - -int DoScanLine(struct TNCINFO * TNC, char * Buff, int Len); -VOID SuspendOtherPorts(struct TNCINFO * ThisTNC); -VOID ReleaseOtherPorts(struct TNCINFO * ThisTNC); - -char * strlop(char * buf, char delim); - -extern UCHAR BPQDirectory[]; - -#define MAXBPQPORTS 32 -#define MAXMPSKPORTS 16 - -//LOGFONT LFTTYFONT ; - -//HFONT hFont ; - -static int MPSKChannel[MAXBPQPORTS+1]; // BPQ Port to MPSK Port -static int BPQPort[MAXMPSKPORTS][MAXBPQPORTS+1]; // MPSK Port and Connection to BPQ Port -//static int MPSKtoBPQ_Q[MAXBPQPORTS+1]; // Frames for BPQ, indexed by BPQ Port -//static int BPQtoMPSK_Q[MAXBPQPORTS+1]; // Frames for MPSK. indexed by MPSK port. Only used it TCP session is blocked - -// Each port may be on a different machine. We only open one connection to each MPSK instance - -static char * MPSKSignon[MAXBPQPORTS+1]; // Pointer to message for secure signin - -static unsigned int MPSKInst = 0; -static int AttachedProcesses=0; - -static HWND hResWnd,hMHWnd; -static BOOL GotMsg; - -static HANDLE STDOUT=0; - -//SOCKET sock; - -static SOCKADDR_IN sinx; -static SOCKADDR_IN rxaddr; -static SOCKADDR_IN destaddr[MAXBPQPORTS+1]; - -static int addrlen=sizeof(sinx); - -//static short MPSKPort=0; - -static time_t ltime,lasttime[MAXBPQPORTS+1]; - -static BOOL CONNECTING[MAXBPQPORTS+1]; -static BOOL CONNECTED[MAXBPQPORTS+1]; - -//HANDLE hInstance; - -static char WindowTitle[] = "FLDIGI"; -static char ClassName[] = "FLDIGISTATUS"; -static int RigControlRow = 165; - -static fd_set readfs; -static fd_set writefs; -static fd_set errorfs; -static struct timeval timeout; - -int Blocksizes[10] = {0,2,4,8,16,32,64,128,256,512}; - - -static size_t ExtProc(int fn, int port, PDATAMESSAGE buff) -{ - PMSGWITHLEN buffptr; - char txbuff[500]; - unsigned int txlen=0; - struct TNCINFO * TNC = TNCInfo[port]; - int Stream = 0; - struct STREAMINFO * STREAM; - int TNCOK; - - if (TNC == NULL) - return 0; // Port not defined - - // Look for attach on any call - -// for (Stream = 0; Stream <= 1; Stream++) - { - STREAM = &TNC->Streams[Stream]; - - if (TNC->PortRecord->ATTACHEDSESSIONS[Stream] && TNC->Streams[Stream].Attached == 0) - { - char Cmd[80]; - - // New Attach - - int calllen; - STREAM->Attached = TRUE; - - TNC->FLInfo->RAW = FALSE; - - calllen = ConvFromAX25(TNC->PortRecord->ATTACHEDSESSIONS[Stream]->L4USER, STREAM->MyCall); - STREAM->MyCall[calllen] = 0; - STREAM->FramesOutstanding = 0; - - SuspendOtherPorts(TNC); // Dont allow connects on interlocked ports - - // Stop Scanning - - sprintf(Cmd, "%d SCANSTOP", TNC->Port); - Rig_Command(-1, Cmd); - - sprintf(TNC->WEB_TNCSTATE, "In Use by %s", TNC->Streams[0].MyCall); - SetWindowText(TNC->xIDC_TNCSTATE, TNC->WEB_TNCSTATE); - -/* len = sprintf(Cmd, "%cSTOP_BEACON_ARQ_FAE\x1b", '\x1a'); - - if (TNC->MPSKInfo->TX) - TNC->CmdSet = TNC->CmdSave = _strdup(Cmd); // Savde till not transmitting - else - SendPacket(TNC->TCPDataSock, Cmd, len, 0); -*/ - } - } - - switch (fn) - { - case 7: - - // 100 mS Timer. - - // See if waiting for busy to clear before sending a connect - - if (TNC->BusyDelay) - { - // Still Busy? - - if (InterlockedCheckBusy(TNC) == FALSE) - { - // No, so send connect - - struct ARQINFO * ARQ = TNC->ARQInfo; - int SendLen; - char Reply[80]; - - SendLen = sprintf(Reply, "c%s:42 %s:24 %c 7 T60R5W10", - STREAM->MyCall, STREAM->RemoteCall, ARQ->OurStream); - - strcpy(TNC->WEB_PROTOSTATE, "Connecting"); - SetWindowText(TNC->xIDC_PROTOSTATE, TNC->WEB_PROTOSTATE); - - ARQ->ARQState = ARQ_ACTIVE; - - ARQ->ARQTimerState = ARQ_CONNECTING; - SaveAndSend(TNC, ARQ, TNC->TCPDataSock, Reply, SendLen); - - STREAM->Connecting = TRUE; - - sprintf(TNC->WEB_TNCSTATE, "%s Connecting to %s", STREAM->MyCall, STREAM->RemoteCall); - SetWindowText(TNC->xIDC_TNCSTATE, TNC->WEB_TNCSTATE); - - strcpy(TNC->WEB_PROTOSTATE, "Connecting"); - SetWindowText(TNC->xIDC_PROTOSTATE, TNC->WEB_PROTOSTATE); - - 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->Streams[0].PACTORtoBPQ_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 (STREAM->NeedDisc) - { - STREAM->NeedDisc--; - - if (STREAM->NeedDisc == 0) - { - // Send the DISCONNECT - - TidyClose(TNC, 0); - } - } - - ARQTimer(TNC); - SendXMLPoll(TNC); - - TNC->SlowTimer--; - - if (TNC->SlowTimer < 0) - { - TNC->SlowTimer = 100; - FLSlowTimer(TNC); // 10 Secs - } - - return 0; - - case 1: // poll - - if (TNC->CONNECTED == FALSE && TNC->CONNECTING == FALSE && TNC->FLInfo->KISSMODE == FALSE) - { - // See if time to reconnect - - time( <ime ); - if (ltime-lasttime[port] >9 ) - { - ConnecttoFLDigi(port); - lasttime[port]=ltime; - } - } - - FD_ZERO(&readfs); - - if (TNC->CONNECTED) - if (TNC->TCPSock) - FD_SET(TNC->TCPSock,&readfs); - - if (TNC->CONNECTED || TNC->FLInfo->KISSMODE) - FD_SET(TNC->TCPDataSock,&readfs); - - -// FD_ZERO(&writefs); - -// if (TNC->BPQtoWINMOR_Q) FD_SET(TNC->TCPDataSock,&writefs); // Need notification of busy clearing - - FD_ZERO(&errorfs); - - if (TNC->CONNECTED) - if (TNC->TCPSock) - FD_SET(TNC->TCPSock,&errorfs); - - if (TNC->CONNECTED || TNC->FLInfo->KISSMODE) - FD_SET(TNC->TCPDataSock,&errorfs); - - - if (select((int)TNC->TCPDataSock + 1, &readfs, &writefs, &errorfs, &timeout) > 0) - { - // See what happened - - if (FD_ISSET(TNC->TCPDataSock,&readfs)) - { - // data available - - ProcessReceivedData(port); - } - - if (FD_ISSET(TNC->TCPSock,&readfs)) - { - // data available - - ProcessXMLData(port); - } - - - if (FD_ISSET(TNC->TCPDataSock,&writefs)) - { - // Connect success - - TNC->CONNECTED = TRUE; - TNC->CONNECTING = FALSE; - - sprintf(TNC->WEB_COMMSSTATE, "Connected to FLDIGI"); - SetWindowText(TNC->xIDC_COMMSSTATE, TNC->WEB_COMMSSTATE); - - // If required, send signon - -// SendPacket(TNC->TCPDataSock,"\x1a", 1, 0); -// SendPacket(TNC->TCPDataSock,"DIGITAL MODE ?", 14, 0); -// SendPacket(TNC->TCPDataSock,"\x1b", 1, 0); - -// EnumWindows(EnumTNCWindowsProc, (LPARAM)TNC); - } - - if (FD_ISSET(TNC->TCPDataSock,&errorfs) || FD_ISSET(TNC->TCPSock,&errorfs)) - { - // if connecting, then failed, if connected then has just disconnected - -// if (CONNECTED[port]) -// if (!CONNECTING[port]) -// { -// i=sprintf(ErrMsg, "MPSK Connection lost for BPQ Port %d\r\n", port); -// WritetoConsole(ErrMsg); -// } - - CONNECTING[port]=FALSE; - CONNECTED[port]=FALSE; - - } - - } - - - - // See if any frames for this port - - for (Stream = 0; Stream <= 1; Stream++) - { - STREAM = &TNC->Streams[Stream]; - - - if (STREAM->Attached) - CheckForDetach(TNC, Stream, STREAM, TidyClose, ForcedClose, CloseComplete); - - if (STREAM->ReportDISC) - { - STREAM->ReportDISC = FALSE; - buff->PORT = Stream; - - return -1; - } - - // if Busy, send buffer status poll - - if (STREAM->PACTORtoBPQ_Q == 0) - { - if (STREAM->DiscWhenAllSent) - { - STREAM->DiscWhenAllSent--; - if (STREAM->DiscWhenAllSent == 0) - STREAM->ReportDISC = TRUE; // Dont want to leave session attached. Causes too much confusion - } - } - else - { - int datalen; - - buffptr=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 (TNC->PortRecord->UI_Q) - { - struct _MESSAGE * buffptr; - int SendLen; - char Reply[256]; - int UILen; - char * UIMsg; - - buffptr = Q_REM(&TNC->PortRecord->UI_Q); - - UILen = buffptr->LENGTH; - UILen -= 23; - UIMsg = buffptr->L2DATA; - - UIMsg[UILen] = 0; - - if (UILen < 129 && TNC->Streams[0].Attached == FALSE) // Be sensible! - { - // >00uG8BPQ:72 TestA - SendLen = sprintf(Reply, "u%s:72 %s", TNC->NodeCall, UIMsg); - SendPacket(TNC, Reply, SendLen); - } - ReleaseBuffer(buffptr); - } - - return (0); - - case 2: // send - - - if (!TNC->CONNECTED) return 0; // Don't try if not connected to TNC - - Stream = buff->PORT; - - STREAM = &TNC->Streams[Stream]; - -// txlen=(buff[6]<<8) + buff[5] - 8; - - txlen = GetLengthfromBuffer((PDATAMESSAGE)buff) - 8; - - if (STREAM->Connected) - { - buffptr = GetBuff(); - - if (buffptr == 0) return (0); // No buffers, so ignore - - buffptr->Len = txlen; - memcpy(buffptr->Data, buff->L2DATA, txlen); - - C_Q_ADD(&TNC->Streams[Stream].BPQtoPACTOR_Q, buffptr); - - return (0); - } - else - { - buff->L2DATA[txlen] = 0; - _strupr(&buff->L2DATA[0]); - - if (_memicmp(&buff->L2DATA[0], "D\r", 2) == 0) - { - if (STREAM->Connected) - TidyClose(TNC, buff->PORT); - - STREAM->ReportDISC = TRUE; // Tell Node - - TNC->FLInfo->MCASTMODE = FALSE; - - 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->CIRCUITINDEX, &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], "MODEM ", 6) == 0) - { - buff->L2DATA[txlen -1] = 0; - _strupr(&buff->L2DATA[0]); - - // If in KISS mode, send as a KISS command Frame - - if (TNC->FLInfo->KISSMODE) - { - sprintf(txbuff, "MODEM:%s MODEM:", &buff->L2DATA[6]); - SendKISSCommand(TNC, txbuff); - } - else - { - SendXMLCommand(TNC, "modem.set_by_name", &buff->L2DATA[6], 'S'); - } - - TNC->InternalCmd = TRUE; - return 1; - } - - if (_memicmp(buff->L2DATA, "FREQ ", 5) == 0) - { - buff->L2DATA[txlen - 1] = 0; - _strupr(&buff->L2DATA[0]); - - // If in KISS mode, send as a KISS command Frame - - if (TNC->FLInfo->KISSMODE) - { - sprintf(txbuff, "WFF:%s WFF:", &buff->L2DATA[5]); - SendKISSCommand(TNC, txbuff); - } - else - { - SendXMLCommand(TNC, "modem.set_carrier", atoi(&buff->L2DATA[5]), 'I'); - } - - TNC->InternalCmd = TRUE; - return 1; - } - - if (_memicmp(buff->L2DATA, "SQUELCH ", 8) == 0) - { - buff->L2DATA[txlen - 1] = 0; - _strupr(&buff->L2DATA[0]); - - // Only works in KISS - - if (TNC->FLInfo->KISSMODE) - { - if (_memicmp(&buff->L2DATA[8], "ON", 2) == 0) - sprintf(txbuff, "KPSQL:ON KPSQL:"); - - else if (_memicmp(&buff->L2DATA[8], "OFF", 3) == 0) - sprintf(txbuff, "KPSQL:OFF KPSQL:"); - else - txlen = sprintf(txbuff, "KPSQLS:%s KPSQLS:", &buff->L2DATA[8]); - - SendKISSCommand(TNC, txbuff); - TNC->InternalCmd = TRUE; - } - return 1; - } - - if (_memicmp(buff->L2DATA, "KPSATT ", 7) == 0) - { - buff->L2DATA[txlen - 1] = 0; - _strupr(&buff->L2DATA[0]); - - // If in KISS mode, send as a KISS command Frame - - if (TNC->FLInfo->KISSMODE) - { - sprintf(txbuff, "KPSATT:%s KPSATT:", &buff->L2DATA[7]); - - SendKISSCommand(TNC, txbuff); - TNC->InternalCmd = TRUE; - } - - return 1; - } - - if (STREAM->Connecting && _memicmp(buff->L2DATA, "ABORT", 5) == 0) - { -// len = sprintf(Command,"%cSTOP_SELECTIVE_CALL_ARQ_FAE\x1b", '\x1a'); - -// if (TNC->MPSKInfo->TX) -// TNC->CmdSet = TNC->CmdSave = _strdup(Command); // Save till not transmitting -// else -// SendPacket(TNC->TCPDataSock, Command, len, 0); - -// TNC->InternalCmd = TRUE; - return (0); - } - - if (_memicmp(&buff->L2DATA[0], "MODE", 4) == 0) - { - PMSGWITHLEN buffptr = GetBuff(); - - buff->L2DATA[txlen - 1] = 0; // Remove CR - - if (strstr(&buff->L2DATA[0], "RAW")) - TNC->FLInfo->RAW = TRUE; - else if (strstr(&buff->L2DATA[0], "KISS")) - TNC->FLInfo->RAW = FALSE; - else - { - buffptr->Len = sprintf(&buffptr->Data[0], "FLDigi} Error - Invalid Mode\r"); - C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr); - return 1; - } - - buffptr->Len = sprintf(&buffptr->Data[0], "FLDigi} Ok - Mode is %s\r", - (TNC->FLInfo->RAW)?"RAW":"KISS"); - - C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr); - - return 1; - } - - if (_memicmp(&buff->L2DATA[0], "MCAST", 5) == 0) - { - UINT * buffptr = GetBuff(); - - TNC->FLInfo->MCASTMODE = TRUE; - - buffptr[1] = sprintf((UCHAR *)&buffptr[2], "FLDigi} Ok\r"); - C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr); - - return 1; - } - - if (_memicmp(&buff->L2DATA[0], "INUSE?", 6) == 0) - { - // Return Error if in use, OK if not - - UINT * buffptr = GetBuff(); - int s = 0; - - while(s <= 1) - { - if (s != Stream) - { - if (TNC->PortRecord->ATTACHEDSESSIONS[s]) - { - buffptr[1] = sprintf((UCHAR *)&buffptr[2], "FLDig} Error - In use\r"); - C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr); - return 1; // Busy - } - } - s++; - } - buffptr[1] = sprintf((UCHAR *)&buffptr[2], "FLDigi} Ok - Not in use\r"); - C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr); - - return 1; - } - - // See if a Connect Command. - - if (toupper(buff->L2DATA[0]) == 'C' && buff->L2DATA[1] == ' ' && txlen > 2) // Connect - { - char * ptr; - char * context; - struct ARQINFO * ARQ = TNC->ARQInfo; - int SendLen; - char Reply[80]; - - buff->L2DATA[txlen] = 0; - _strupr(&buff->L2DATA[0]); - - memset(ARQ, 0, sizeof(struct ARQINFO)); // Reset ARQ State - ARQ->TXSeq = ARQ->TXLastACK = 63; // Last Sent - ARQ->RXHighest = ARQ->RXNoGaps = 63; // Last Received - ARQ->OurStream = (rand() % 78) + 49; // To give some protection against other stuff on channel - ARQ->FarStream = 48; // Not yet defined - TNC->FLInfo->FLARQ = FALSE; - - memset(STREAM->RemoteCall, 0, 10); - - ptr = strtok_s(&buff->L2DATA[2], " ,\r", &context); - strcpy(STREAM->RemoteCall, ptr); - - // 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"); - SetWindowText(TNC->xIDC_TNCSTATE, TNC->WEB_TNCSTATE); - - TNC->BusyDelay = TNC->BusyWait * 10; // BusyWait secs - return 0; - } - } - - TNC->OverrideBusy = FALSE; - -//<SOH>00cG8BPQ:1025 G8BPQ:24 0 7 T60R5W10FA36<EOT> - - SendLen = sprintf(Reply, "c%s:42 %s:24 %c 7 T60R5W10", - STREAM->MyCall, STREAM->RemoteCall, ARQ->OurStream); - - strcpy(TNC->WEB_PROTOSTATE, "Connecting"); - SetWindowText(TNC->xIDC_PROTOSTATE, TNC->WEB_PROTOSTATE); - - ARQ->ARQState = ARQ_ACTIVE; - - ARQ->ARQTimerState = ARQ_CONNECTING; - SaveAndSend(TNC, ARQ, TNC->TCPDataSock, Reply, SendLen); - - STREAM->Connecting = TRUE; - - sprintf(TNC->WEB_TNCSTATE, "%s Connecting to %s", STREAM->MyCall, STREAM->RemoteCall); - SetWindowText(TNC->xIDC_TNCSTATE, TNC->WEB_TNCSTATE); - - strcpy(TNC->WEB_PROTOSTATE, "Connecting"); - SetWindowText(TNC->xIDC_PROTOSTATE, TNC->WEB_PROTOSTATE); - - return 0; - } - - // Send any other command to FLDIGI - - buff->L2DATA[txlen - 1] = 0; - _strupr(&buff->L2DATA[0]); - - // If in KISS mode, send as a KISS command Frame - - if (TNC->FLInfo->KISSMODE) - { - char outbuff[1000]; - int newlen; - - buff->L2DATA[-1] = 6; // KISS Control - - newlen = KissEncode(&buff->L2DATA[-1], outbuff, txlen); - sendto(TNC->TCPDataSock, outbuff, newlen, 0, (struct sockaddr *)&TNC->Datadestaddr, sizeof(struct sockaddr)); - } - else - { - SendXMLCommand(TNC, "modem.set_by_name", &buff->L2DATA[0], 'S'); - } - - TNC->InternalCmd = TRUE; - } - - return (0); - - case 3: - - Stream = (int)(size_t)buff; - - TNCOK = TNC->CONNECTED; - - STREAM = &TNC->Streams[Stream]; - { - // Busy if TX Window reached - - struct ARQINFO * ARQ = TNC->ARQInfo; - int Outstanding; - - Outstanding = ARQ->TXSeq - ARQ->TXLastACK; - - if (Outstanding < 0) - Outstanding += 64; - - TNC->PortRecord->FramesQueued = Outstanding + C_Q_COUNT(&TNC->Streams[0].BPQtoPACTOR_Q); // Save for Appl Level Queued Frames - - if (Outstanding > ARQ->TXWindow) - return (1 | TNCOK << 8 | STREAM->Disconnecting << 15); // 3rd Nibble is frames unacked - else - return TNCOK << 8 | STREAM->Disconnecting << 15; - - } - return TNCOK << 8 | STREAM->Disconnecting << 15; // OK, but lock attach if disconnecting - - case 4: // reinit - - shutdown(TNC->TCPSock, SD_BOTH); - shutdown(TNC->TCPDataSock, SD_BOTH); - Sleep(100); - - closesocket(TNC->TCPSock); - closesocket(TNC->TCPDataSock); - TNC->CONNECTED = FALSE; - - if (TNC->WeStartedTNC) - { - KillTNC(TNC); - RestartTNC(TNC); - } - - return (0); - - case 5: // Close - - shutdown(TNC->TCPSock, SD_BOTH); - shutdown(TNC->TCPDataSock, SD_BOTH); - Sleep(100); - - closesocket(TNC->TCPSock); - closesocket(TNC->TCPDataSock); - - if (TNC->WeStartedTNC) - { - KillTNC(TNC); - } - - return 0; - } - - return 0; -} - -#ifndef LINBPQ - -int FindFLDIGI(char * Path) -{ - HANDLE hProc; - char ExeName[256] = ""; - char FLDIGIName[256]; - DWORD Pid = 0; - DWORD Processes[1024], Needed, Count; - unsigned int i; - - if (EnumProcessesPtr == NULL) - return 0; // Cant get PID - - if (!EnumProcessesPtr(Processes, sizeof(Processes), &Needed)) - return TRUE; - - // Path is to .bat, so need to strip extension of both names - - strcpy(FLDIGIName, Path); - strlop(FLDIGIName, '.'); - - // Calculate how many process identifiers were returned. - - Count = Needed / sizeof(DWORD); - - for (i = 0; i < Count; i++) - { - if (Processes[i] != 0) - { - hProc = OpenProcess(PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, Processes[i]); - - if (hProc) - { - GetModuleFileNameExPtr(hProc, 0, ExeName, 255); - CloseHandle(hProc); - - strlop(ExeName, '.'); - - if (_stricmp(ExeName, FLDIGIName) == 0) - return Processes[i]; - - } - } - } - return 0; -} - - -static KillTNC(struct TNCINFO * TNC) -{ - HANDLE hProc; - - if (TNC->PTTMode) - Rig_PTT(TNC->RIG, FALSE); // Make sure PTT is down - - if (TNC->ProgramPath) - TNC->PID = FindFLDIGI(TNC->ProgramPath); - - if (TNC->PID == 0) return 0; - - hProc = OpenProcess(PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, TNC->PID); - - if (hProc) - { - TerminateProcess(hProc, 0); - CloseHandle(hProc); - } - - TNC->WeStartedTNC = 0; // So we don't try again - - return 0; -} - -#endif - -static int RestartTNC(struct TNCINFO * TNC) -{ - if (TNC->ProgramPath == NULL) - return 0; - - _strlwr(TNC->ProgramPath); - - if (_memicmp(TNC->ProgramPath, "REMOTE:", 7) == 0) - { - int n; - - // Try to start TNC on a remote host - - SOCKET sock = socket(AF_INET,SOCK_DGRAM,0); - struct sockaddr_in destaddr; - - Debugprintf("trying to restart FLDIGI %s", TNC->ProgramPath); - - if (sock == INVALID_SOCKET) - return 0; - - destaddr.sin_family = AF_INET; - destaddr.sin_addr.s_addr = inet_addr(TNC->HostName); - destaddr.sin_port = htons(8500); - - if (destaddr.sin_addr.s_addr == INADDR_NONE) - { - // Resolve name to address - - struct hostent * HostEnt = gethostbyname (TNC->HostName); - - if (!HostEnt) - return 0; // Resolve failed - - memcpy(&destaddr.sin_addr.s_addr,HostEnt->h_addr,4); - } - - n = sendto(sock, TNC->ProgramPath, (int)strlen(TNC->ProgramPath), 0, (struct sockaddr *)&destaddr, sizeof(destaddr)); - - Debugprintf("Restart FLDIGI - sento returned %d", n); - - Sleep(100); - closesocket(sock); - - return 1; // Cant tell if it worked, but assume ok - } -#ifndef LINBPQ - { - STARTUPINFO SInfo; // pointer to STARTUPINFO - PROCESS_INFORMATION PInfo; // pointer to PROCESS_INFORMATION - char HomeDir[MAX_PATH]; - int i, ret; - - SInfo.cb=sizeof(SInfo); - SInfo.lpReserved=NULL; - SInfo.lpDesktop=NULL; - SInfo.lpTitle=NULL; - SInfo.dwFlags=0; - SInfo.cbReserved2=0; - SInfo.lpReserved2=NULL; - - if (TNC->ProgramPath) - { - strcpy(HomeDir, TNC->ProgramPath); - i = strlen(HomeDir); - - while(--i) - { - if (HomeDir[i] == '/' || HomeDir[i] == '\\') - { - HomeDir[i] = 0; - break; - } - } - - // for some reason the program name must be lower case - - _strlwr(TNC->ProgramPath); - - ret = CreateProcess(TNC->ProgramPath, NULL, NULL, NULL, FALSE,0 ,NULL , NULL, &SInfo, &PInfo); - return ret; - } - } -#endif - 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>FLDigi Status</title></head><body id=Text onload=\"ScrollOutput()\">" - "<h2>FLDIGI Status</h2>"); - - - 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 FLDIGISuspendPort(struct TNCINFO * TNC) -{ - TNC->FLInfo->CONOK = FALSE; -} - -VOID FLDIGIReleasePort(struct TNCINFO * TNC) -{ - TNC->FLInfo->CONOK = TRUE; -} - -VOID SendKISSCommand(struct TNCINFO * TNC, char * Msg) -{ - int txlen, rc; - char txbuff[256]; - char outbuff[256]; - - txlen = sprintf(txbuff, "%c%s", 6, Msg); - txlen = KissEncode(txbuff, outbuff, txlen); - rc = sendto(TNC->TCPDataSock, outbuff, txlen, 0, (struct sockaddr *)&TNC->Datadestaddr, sizeof(struct sockaddr)); -} - -VOID * FLDigiExtInit(EXTPORTDATA * PortEntry) -{ - int i, port; - char Msg[255]; - struct TNCINFO * TNC; - char * ptr; - - // - // The Socket to connect to is in IOBASE - // - - srand((unsigned int)time(NULL)); - - 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 ExtProc; - } - - TNC->Port = port; - - 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->PERMITGATEWAY = TRUE; // Can change ax.25 call on each stream - PortEntry->PORTCONTROL.UICAPABLE = 1; // Can send beacons - PortEntry->PORTCONTROL.PORTQUALITY = 0; - PortEntry->SCANCAPABILITIES = NONE; // Scan Control - None - - TNC->FLInfo->CONOK = TRUE; - - if (PortEntry->PORTCONTROL.PORTPACLEN == 0 || PortEntry->PORTCONTROL.PORTPACLEN > 128) - PortEntry->PORTCONTROL.PORTPACLEN = 64; - - TNC->SuspendPortProc = FLDIGISuspendPort; - TNC->ReleasePortProc = FLDIGIReleasePort; - - ptr=strchr(TNC->NodeCall, ' '); - if (ptr) *(ptr) = 0; // Null Terminate - - TNC->Hardware = H_FLDIGI; - - if (TNC->BusyWait == 0) - TNC->BusyWait = 10; - - MPSKChannel[port] = PortEntry->PORTCONTROL.CHANNELNUM-65; - - PortEntry->MAXHOSTMODESESSIONS = 1; - - i=sprintf(Msg,"FLDigi Host %s Port %d \n", - TNC->HostName, TNC->TCPPort); - - WritetoConsole(Msg); - -#ifndef LINBPQ - - if (TNC->ProgramPath) - TNC->PID = FindFLDIGI(TNC->ProgramPath); - - if (TNC->PID == 0) // Not running -#endif - TNC->WeStartedTNC = RestartTNC(TNC); // Always try if Linux - - if (TNC->FLInfo->KISSMODE) - { - // Open Datagram port - - SOCKET sock; - u_long param=1; - BOOL bcopt=TRUE; - struct sockaddr_in sinx; - struct hostent * HostEnt = NULL; - - TNC->FLInfo->CmdControl = 5; //Send params immediately - - TNC->Datadestaddr.sin_addr.s_addr = inet_addr(TNC->HostName); - - if (TNC->Datadestaddr.sin_addr.s_addr == INADDR_NONE) - { - // Resolve name to address - - HostEnt = gethostbyname (TNC->HostName); - - if (HostEnt) - { - memcpy(&TNC->Datadestaddr.sin_addr.s_addr,HostEnt->h_addr,4); - } - } - - TNC->TCPDataSock = sock = socket(AF_INET,SOCK_DGRAM,0); - - ioctl(sock, FIONBIO, ¶m); - - setsockopt(sock, SOL_SOCKET, SO_BROADCAST, (const char FAR *)&bcopt,4); - - sinx.sin_family = AF_INET; - sinx.sin_addr.s_addr = INADDR_ANY; - sinx.sin_port = htons(TNC->TCPPort + 1); - - if (bind(sock, (struct sockaddr *) &sinx, sizeof(sinx)) != 0 ) - { - // Bind Failed - - int err = WSAGetLastError(); - Consoleprintf("Bind Failed for UDP port %d - error code = %d", TNC->TCPPort, err); - } - - TNC->Datadestaddr.sin_family = AF_INET; - TNC->Datadestaddr.sin_port = htons(TNC->TCPPort); - } - else - ConnecttoFLDigi(port); - - time(&lasttime[port]); // Get initial time value - - PortEntry->PORTCONTROL.TNC = TNC; - - TNC->WebWindowProc = WebProc; - TNC->WebWinX = 520; - TNC->WebWinY = 500; - TNC->WebBuffer = zalloc(5000); - - TNC->WEB_COMMSSTATE = zalloc(100); - TNC->WEB_TNCSTATE = zalloc(100); - TNC->WEB_CHANSTATE = zalloc(100); - TNC->WEB_BUFFERS = zalloc(100); - TNC->WEB_PROTOSTATE = zalloc(100); - TNC->WEB_RESTARTTIME = zalloc(100); - TNC->WEB_RESTARTS = zalloc(100); - - TNC->WEB_MODE = zalloc(50); - TNC->WEB_TRAFFIC = zalloc(100); - - -#ifndef LINBPQ - - CreatePactorWindow(TNC, ClassName, WindowTitle, RigControlRow, PacWndProc, 500, 450, ForcedClose); - - CreateWindowEx(0, "STATIC", "Comms State", WS_CHILD | WS_VISIBLE, 10,6,120,20, TNC->hDlg, NULL, hInstance, NULL); - TNC->xIDC_COMMSSTATE = CreateWindowEx(0, "STATIC", "", WS_CHILD | WS_VISIBLE, 116,6,386,20, TNC->hDlg, NULL, hInstance, NULL); - - CreateWindowEx(0, "STATIC", "TNC State", WS_CHILD | WS_VISIBLE, 10,28,106,20, TNC->hDlg, NULL, hInstance, NULL); - TNC->xIDC_TNCSTATE = CreateWindowEx(0, "STATIC", "", WS_CHILD | WS_VISIBLE, 116,28,520,20, TNC->hDlg, NULL, hInstance, NULL); - - CreateWindowEx(0, "STATIC", "Mode/CF", WS_CHILD | WS_VISIBLE, 10,50,80,20, TNC->hDlg, NULL, hInstance, NULL); - TNC->xIDC_MODE = CreateWindowEx(0, "STATIC", "", WS_CHILD | WS_VISIBLE, 116,50,200,20, TNC->hDlg, NULL, hInstance, NULL); - - CreateWindowEx(0, "STATIC", "Channel State", WS_CHILD | WS_VISIBLE, 10,72,110,20, TNC->hDlg, NULL, hInstance, NULL); - TNC->xIDC_CHANSTATE = CreateWindowEx(0, "STATIC", "", WS_CHILD | WS_VISIBLE, 116,72,144,20, TNC->hDlg, NULL, hInstance, NULL); - - CreateWindowEx(0, "STATIC", "Proto State", WS_CHILD | WS_VISIBLE,10,94,80,20, TNC->hDlg, NULL, hInstance, NULL); - TNC->xIDC_PROTOSTATE = CreateWindowEx(0, "STATIC", "", WS_CHILD | WS_VISIBLE,116,94,374,20 , TNC->hDlg, NULL, hInstance, NULL); - - CreateWindowEx(0, "STATIC", "Traffic", WS_CHILD | WS_VISIBLE,10,116,80,20, TNC->hDlg, NULL, hInstance, NULL); - TNC->xIDC_TRAFFIC = CreateWindowEx(0, "STATIC", "RX 0 TX 0 ACKED 0 Resent 0", WS_CHILD | WS_VISIBLE,116,116,374,20 , TNC->hDlg, NULL, hInstance, NULL); - - TNC->hMonitor= CreateWindowEx(0, "LISTBOX", "", WS_CHILD | WS_VISIBLE | LBS_NOINTEGRALHEIGHT | - LBS_DISABLENOSCROLL | WS_HSCROLL | WS_VSCROLL, - 0,170,250,300, TNC->hDlg, NULL, hInstance, NULL); - - TNC->ClientHeight = 450; - TNC->ClientWidth = 500; - - TNC->hMenu = CreatePopupMenu(); - - AppendMenu(TNC->hMenu, MF_STRING, WINMOR_KILL, "Kill FLDigi"); - AppendMenu(TNC->hMenu, MF_STRING, WINMOR_RESTART, "Kill and Restart FLDigi"); - AppendMenu(TNC->hMenu, MF_STRING, ARDOP_ABORT, "Abort Current Session"); - - MoveWindows(TNC); -#endif - - return ExtProc; - -} - - -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; - struct ARQINFO * ARQ; - struct FLINFO * FL; - - 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] = zalloc(sizeof(struct TNCINFO)); - - ARQ = TNC->ARQInfo = zalloc(sizeof(struct ARQINFO)); - FL = TNC->FLInfo = zalloc(sizeof(struct FLINFO)); - - TNC->Timeout = 50; // Default retry = 5 seconds - TNC->Retries = 6; // Default Retries - TNC->Window = 16; - - TNC->FLInfo->KISSMODE = TRUE; // Default to KISS - - 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); - - TNC->TCPPort = atoi(p_port); - - TNC->destaddr.sin_family = AF_INET; - TNC->destaddr.sin_port = htons(TNC->TCPPort + 40); // Defaults XML 7362 ARQ 7322 - - TNC->Datadestaddr.sin_family = AF_INET; - TNC->Datadestaddr.sin_port = htons(TNC->TCPPort); - - 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 (_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, "TIMEOUT", 7) == 0) - TNC->Timeout = atoi(&buf[8]) * 10; - else - if (_memicmp(buf, "RETRIES", 7) == 0) - TNC->Retries = atoi(&buf[8]); - else - if (_memicmp(buf, "WINDOW", 6) == 0) - TNC->Window = atoi(&buf[7]); - else - if (_memicmp(buf, "ARQMODE", 7) == 0) - TNC->FLInfo->KISSMODE = FALSE; - else - if (_memicmp(buf, "DEFAULTMODEM", 12) == 0) // Send Beacon after each session - { - // Check that freq is also specified - - char * Freq = strchr(&buf[13], '/'); - - if (Freq) - { - *(Freq++) = 0; - strcpy(TNC->FLInfo->DefaultMode, &buf[13]); - TNC->FLInfo->DefaultFreq = atoi(Freq); - } - } - else - - strcat (TNC->InitScript, buf); - } - - - return (TRUE); -} - -static int ConnecttoFLDigi(int port) -{ - _beginthread(ConnecttoFLDigiThread, 0, (void *)(size_t)port); - - return 0; -} - -static VOID ConnecttoFLDigiThread(void * portptr) -{ - int port = (int)(size_t)portptr; - char Msg[255]; - int err,i; - u_long param=1; - BOOL bcopt=TRUE; - struct hostent * HostEnt = NULL; - struct TNCINFO * TNC = TNCInfo[port]; - - Sleep(5000); // Allow init to complete - - TNC->destaddr.sin_addr.s_addr = inet_addr(TNC->HostName); - TNC->Datadestaddr.sin_addr.s_addr = inet_addr(TNC->HostName); - - if (TNC->destaddr.sin_addr.s_addr == INADDR_NONE) - { - // Resolve name to address - - HostEnt = gethostbyname (TNC->HostName); - - if (!HostEnt) return; // Resolve failed - - memcpy(&TNC->destaddr.sin_addr.s_addr,HostEnt->h_addr,4); - memcpy(&TNC->Datadestaddr.sin_addr.s_addr,HostEnt->h_addr,4); - } - - if (TNC->TCPSock) - { - Debugprintf("FLDIGI Closing Sock %d", TNC->TCPSock); - closesocket(TNC->TCPSock); - } - - TNC->TCPSock = 0; - - - TNC->TCPSock=socket(AF_INET,SOCK_STREAM,0); - - if (TNC->TCPSock == INVALID_SOCKET) - { - i=sprintf(Msg, "Socket Failed for FLDigi Control socket - error code = %d\n", WSAGetLastError()); - WritetoConsole(Msg); - return; - } - - setsockopt (TNC->TCPSock, SOL_SOCKET, SO_REUSEADDR, (const char FAR *)&bcopt, 4); - - sinx.sin_family = AF_INET; - sinx.sin_addr.s_addr = INADDR_ANY; - sinx.sin_port = 0; - - TNC->CONNECTING = TRUE; - - if (connect(TNC->TCPSock,(LPSOCKADDR) &TNC->destaddr,sizeof(TNC->destaddr)) == 0) - { - // - // Connected successful - // - } - else - { - if (TNC->Alerted == FALSE) - { - err=WSAGetLastError(); - i=sprintf(Msg, "Connect Failed for FLDigi Control socket - error code = %d\n", err); - WritetoConsole(Msg); - - sprintf(TNC->WEB_COMMSSTATE, "Connection to TNC failed"); - MySetWindowText(TNC->xIDC_COMMSSTATE, TNC->WEB_COMMSSTATE); - TNC->Alerted = TRUE; - } - - closesocket(TNC->TCPSock); - TNC->TCPSock = 0; - TNC->CONNECTING = FALSE; - return; - } - - TNC->LastFreq = 0; - - if (TNC->TCPDataSock) - closesocket(TNC->TCPDataSock); - - TNC->TCPDataSock = 0; - - TNC->TCPDataSock=socket(AF_INET,SOCK_STREAM,0); - - setsockopt (TNC->TCPDataSock, SOL_SOCKET, SO_REUSEADDR, (const char FAR *)&bcopt, 4); - - if (TNC->TCPDataSock == INVALID_SOCKET) - { - i=sprintf(Msg, "Socket Failed for FLDigi socket - error code = %d\r\n", WSAGetLastError()); - WritetoConsole(Msg); - - closesocket(TNC->TCPSock); - closesocket(TNC->TCPDataSock); - TNC->TCPSock = 0; - TNC->CONNECTING = FALSE; - - return; - } - - if (bind(TNC->TCPDataSock, (LPSOCKADDR) &sinx, addrlen) != 0 ) - { - // - // Bind Failed - // - - i=sprintf(Msg, "Bind Failed for FLDigi Data socket - error code = %d\r\n", WSAGetLastError()); - WritetoConsole(Msg); - - closesocket(TNC->TCPSock); - closesocket(TNC->TCPDataSock); - TNC->TCPSock = 0; - TNC->TCPDataSock = 0; - TNC->CONNECTING = FALSE; - return; - } - - if (connect(TNC->TCPDataSock,(LPSOCKADDR) &TNC->Datadestaddr,sizeof(TNC->Datadestaddr)) == 0) - { - ioctlsocket (TNC->TCPDataSock,FIONBIO,¶m); // Set nonblocking - TNC->CONNECTED = TRUE; - TNC->CONNECTING = FALSE; - - TNC->Alerted = TRUE; - - sprintf(TNC->WEB_COMMSSTATE, "Connected to FLDIGI"); - SetWindowText(TNC->xIDC_COMMSSTATE, TNC->WEB_COMMSSTATE); - } - else - { - sprintf(Msg, "Connect Failed for FLDigi Data socket Port %d - error code = %d\r\n", port, WSAGetLastError()); - WritetoConsole(Msg); - - closesocket(TNC->TCPSock); - closesocket(TNC->TCPDataSock); - TNC->TCPSock = 0; - TNC->TCPDataSock = 0; - TNC->CONNECTING = FALSE; - } - - return; -} - -VOID UpdateStatsLine(struct TNCINFO * TNC, struct STREAMINFO * STREAM) -{ - sprintf(TNC->WEB_TRAFFIC, "RX %d TX %d ACKED %d Resent %d Queued %d", - STREAM->BytesRXed, STREAM->BytesTXed, STREAM->BytesAcked, STREAM->BytesResent, STREAM->BytesOutstanding); - SetWindowText(TNC->xIDC_TRAFFIC, TNC->WEB_TRAFFIC); -} - -VOID SendPacket(struct TNCINFO * TNC, UCHAR * Msg, int MsgLen) -{ - if (TNC->FLInfo->KISSMODE) - { - char KissMsg[1000]; - char outbuff[1000]; - int newlen; - - if (TNC->FLInfo->RAW) - { - // KISS RAW - - // Add CRC and Send - - unsigned short CRC; - char crcstring[6]; - - KissMsg[0] = 7; // KISS Raw - KissMsg[1] = 1; // SOH - KissMsg[2] = '0'; // Version - KissMsg[3] = TNC->ARQInfo->FarStream; - - Msg[MsgLen] = 0; - - memcpy(&KissMsg[4], Msg, MsgLen +1 ); // Get terminating NULL - - CRC = CalcCRC(KissMsg + 1, MsgLen + 3); - - sprintf(crcstring, "%04X%c", CRC, 4); - - strcat(KissMsg, crcstring); - MsgLen += 9; - } - else - { - // Normal KISS - - KissMsg[0] = 0; // KISS Control - KissMsg[1] = TNC->ARQInfo->FarStream; - memcpy(&KissMsg[2], Msg, MsgLen); - MsgLen += 2; - } - - newlen = KissEncode(KissMsg, outbuff, MsgLen); - sendto(TNC->TCPDataSock, outbuff, newlen, 0, (struct sockaddr *)&TNC->Datadestaddr, sizeof(struct sockaddr)); - - SendKISSCommand(TNC, "TXBUF:"); - - } - else - { - // ARQ Scoket - - // Add Header, CRC and Send - - unsigned short CRC; - char crcstring[6]; - char outbuff[1000]; - - outbuff[0] = 1; // SOH - outbuff[1] = '0'; // Version - outbuff[2] = TNC->ARQInfo->FarStream; - - Msg[MsgLen] = 0; - - memcpy(&outbuff[3], Msg, MsgLen + 1); - - CRC = CalcCRC(outbuff , MsgLen + 3); - - sprintf(crcstring, "%04X%c", CRC, 4); - - strcat(outbuff, crcstring); - MsgLen += 8; - - send(TNC->TCPDataSock, outbuff, MsgLen, 0); - } -} - -VOID ProcessFLDigiData(struct TNCINFO * TNC, UCHAR * Input, int Len, char Channel, BOOL RAW); - -static int ProcessReceivedData(int port) -{ - int bytes, used, bytesleft; - int i; - char ErrMsg[255]; - unsigned char MessageBuff[1500]; - unsigned char * Message = MessageBuff; - unsigned char * MessageBase = MessageBuff; - - struct TNCINFO * TNC = TNCInfo[port]; - struct FLINFO * FL = TNC->FLInfo; - struct STREAMINFO * STREAM = &TNC->Streams[0]; - - // If using KISS/UDP interface use recvfrom - - if (FL->KISSMODE) - { - struct sockaddr_in rxaddr; - int addrlen = sizeof(struct sockaddr_in); - unsigned char * KissEnd; - - bytesleft = recvfrom(TNC->TCPDataSock, Message, 1500, 0, (struct sockaddr *)&rxaddr, &addrlen); - - if (bytesleft < 0) - { - int err = WSAGetLastError(); - // if (err != 11) - // printf("KISS Error %d %d\n", nLength, err); - bytes = 0; - } - - while (bytesleft > 0) - { - unsigned char * in; - unsigned char * out; - unsigned char c; - - if (bytesleft < 3) - return 0; - - if (Message[0] != FEND) - return 0; // Duff - - Message = MessageBase; - in = out = &Message[2]; - - // We may have more than one KISS message in a packet - - KissEnd = memchr(&Message[2], FEND, bytesleft ); - - if (KissEnd == 0) - return 0; // Duff - - *(KissEnd) = 0; - - used = (int)(KissEnd - Message + 1); - - bytesleft -= used; - bytes = used; - - MessageBase += used; - - if (Message[1] == 6) // KISS Command - { - UCHAR * ptr = strchr(&Message[2], FEND); - - if (ptr) *ptr = 0; // Null Terminate - - if (bytes > 250) - Message[250] = 0; - - FL->Responding = 5; - - if (TNC->TNCOK == 0) - { - TNC->TNCOK = TRUE; - TNC->CONNECTED = TRUE; - - sprintf(TNC->WEB_COMMSSTATE, "Connected to FLDIGI"); - SetWindowText(TNC->xIDC_COMMSSTATE, TNC->WEB_COMMSSTATE); - } - - // Trap BUSY fiest - there are lots of them, and they are likely to be confused - // with tesponses to Interactive commands - - if (memcmp(&Message[2], "BUSY", 4) == 0) - { - BOOL Changed = FALSE; - - if (Message[7] == 'T' && FL->Busy == FALSE) - { - TNC->Busy = FL->Busy = TRUE; - Changed = TRUE; - } - else - { - if (Message[7] == 'F' && FL->Busy == TRUE) - { - TNC->Busy = FL->Busy = FALSE; - Changed = TRUE; - } - } - - if (Changed) - { - if (FL->TX) - strcpy(TNC->WEB_CHANSTATE, "TX"); - else - if (FL->Busy) - strcpy(TNC->WEB_CHANSTATE, "Busy"); - else - strcpy(TNC->WEB_CHANSTATE, "Idle"); - - SetWindowText(TNC->xIDC_CHANSTATE, TNC->WEB_CHANSTATE); - } - - continue; - } - - if (TNC->InternalCmd) - { - ULONG * buffptr = GetBuff(); - - TNC->InternalCmd = FALSE; - - if (buffptr) - { - buffptr[1] = sprintf((UCHAR *)&buffptr[2], "FLDIGI} Ok %s\r", &Message[2]); - C_Q_ADD(&TNC->Streams[0].PACTORtoBPQ_Q, buffptr); - } - - // Drop through in case need to extract info from command - } - - // Auto Command - -// Debugprintf("%d %s", TNC->PortRecord->PORTCONTROL.PORTNUMBER, &Message[2]); - - if (memcmp(&Message[2], "FLSTAT", 4) == 0) - { - if (strstr(&Message[2], "FLSTAT:INIT")) - { - // FLDIGI Reloaded - set parmas - SendKISSCommand(TNC, "RSIDBCAST:ON TRXSBCAST:ON TXBEBCAST:ON KISSRAW:ON"); - } - continue; - } - - if (memcmp(&Message[2], "TRXS", 4) == 0) - { - char * ptr1, * context; - BOOL Changed = FALSE; - - ptr1 = strtok_s(&Message[7], ",", &context); - - if (strstr(ptr1, "TX")) - { - if (TNC->FLInfo->TX == FALSE) - { - TNC->FLInfo->TX = TRUE; - Changed = TRUE; - } - } - else - { - if (TNC->FLInfo->TX) - { - TNC->FLInfo->TX = FALSE; - Changed = TRUE; - } - } - - if (Changed) - { - if (FL->TX) - strcpy(TNC->WEB_CHANSTATE, "TX"); - else - if (FL->Busy) - strcpy(TNC->WEB_CHANSTATE, "Busy"); - else - strcpy(TNC->WEB_CHANSTATE, "Idle"); - - SetWindowText(TNC->xIDC_CHANSTATE, TNC->WEB_CHANSTATE); - } - - continue; - } - - if (memcmp(&Message[2], "TXBUF:", 6) == 0) - { - char * ptr1, * context; - - ptr1 = strtok_s(&Message[8], ",", &context); - STREAM->BytesOutstanding = atoi(ptr1); - UpdateStatsLine(TNC, STREAM); - continue; - } - - if (memcmp(&Message[2], "TXBE:", 5) == 0) - { - STREAM->BytesOutstanding = 0; - UpdateStatsLine(TNC, STREAM); - continue; - } - - if (memcmp(&Message[2], "RSIDN:", 6) == 0) - { - char * ptr1, * context; - - ptr1 = strtok_s(&Message[8], ",", &context); - - TNC->FLInfo->CenterFreq = atoi(ptr1); - ptr1 = strtok_s(NULL, ",", &context); - if (strlen(ptr1) > 19) - ptr1[19] = 0; - - strcpy(TNC->FLInfo->CurrentMode, ptr1); - } - - if (memcmp(&Message[2], "MODEM:", 6) == 0) - { - char * ptr1, * context; - - ptr1 = strtok_s(&Message[8], ",", &context); - if (strlen(ptr1) > 19) - ptr1[19] = 0; - - strcpy(TNC->FLInfo->CurrentMode, ptr1); - } - - if (memcmp(&Message[2], "WFF:", 4) == 0) - { - char * ptr1, * context; - - ptr1 = strtok_s(&Message[6], ",", &context); - TNC->FLInfo->CenterFreq = atoi(ptr1); - } - - sprintf(TNC->WEB_MODE, "%s/%d", TNC->FLInfo->CurrentMode, TNC->FLInfo->CenterFreq); - SetWindowText(TNC->xIDC_MODE, TNC->WEB_MODE); - - continue; - } - - if (Message[1] == 7) // Not Normal Data - { - // "RAW" Mode. Just process as if received from TCP Socket Interface - - ProcessFLDigiPacket(TNC, &Message[2] , bytes - 3); // Data may be for another port - continue; - } - - bytes -= 3; // Two FEND and Control - - // Undo KISS - - while (bytes) - { - bytes--; - - c = *(in++); - - if (c == FESC) - { - c = *(in++); - bytes--; - - if (c == TFESC) - c = FESC; - else if (c == TFEND) - c = FEND; - } - *(out++) = c; - } - ProcessFLDigiData(TNC, &Message[3], (int)(out - &Message[3]), Message[2], FALSE); // KISS not RAW - } - return 0; - } - - // Need to extract messages from byte stream - - bytes = recv(TNC->TCPDataSock, Message, 500, 0); - - if (bytes == SOCKET_ERROR) - { -// i=sprintf(ErrMsg, "Read Failed for MPSK socket - error code = %d\r\n", WSAGetLastError()); -// WritetoConsole(ErrMsg); - - closesocket(TNC->TCPDataSock); - - TNC->CONNECTED = FALSE; - if (TNC->Streams[0].Attached) - TNC->Streams[0].ReportDISC = TRUE; - - return (0); - } - - if (bytes == 0) - { - // zero bytes means connection closed - - i=sprintf(ErrMsg, "FlDigi Connection closed for BPQ Port %d\n", port); - WritetoConsole(ErrMsg); - - TNC->CONNECTED = FALSE; - if (TNC->Streams[0].Attached) - TNC->Streams[0].ReportDISC = TRUE; - - return (0); - } - - // Have some data - - ProcessFLDigiPacket(TNC, Message, bytes); // Data may be for another port - - return (0); - -} - - -VOID ProcessFLDigiPacket(struct TNCINFO * TNC, char * Message, int Len) -{ - char * MPTR = Message; - char c; - struct FLINFO * FL = TNC->FLInfo; - - - if (TNC->FLInfo->MCASTMODE) - { - if (TNC->Streams[0].Attached == 0) - return; - - while(Len) - { - c = *(MPTR++); - - if (TNC->InPacket) - { - TNC->DataBuffer[TNC->DataLen++] = c; - - // Sanity Check - - if (TNC->DataLen == 6) - { - char * ptr = &TNC->DataBuffer[1]; - - if (memcmp(ptr, "DATA ", 5) == 0 || - memcmp(ptr, "PROG ", 5) == 0 || - memcmp(ptr, "FILE ", 5) == 0 || - memcmp(ptr, "SIZE ", 5) == 0 || - memcmp(ptr, "DESC ", 5) == 0 || - memcmp(ptr, "CNTL ", 5) == 0 || - memcmp(ptr, "ID ", 3) == 0) - - { - } - else - { - // False Trigger, try again - - TNC->InPacket = FALSE; - } - - } - else - { - if (TNC->InData) - { - if (--TNC->MCASTLen == 0) - { - // Got a packet - - UINT * buffptr; - int Stream = 0; - struct STREAMINFO * STREAM = &TNC->Streams[0]; - - buffptr = GetBuff(); - - if (buffptr) - { - TNC->DataBuffer[TNC->DataLen++] = 13; // Keep Tidy - - buffptr[1] = TNC->DataLen; - memcpy(&buffptr[2], &TNC->DataBuffer[0], TNC->DataLen); - - C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr); - } - - TNC->InPacket = FALSE; - } - } - else - { - // Looking for > - - if (TNC->DataLen == 16) - { - // Not found it - - TNC->InPacket = FALSE; - } - else - { - if (c == '>') - { - // Got Header - extract Length - - char * ptr; - int len; - - ptr = strchr(TNC->DataBuffer, ' '); - - if (ptr) - { - len = atoi(ptr); - - if (len) - { - TNC->InData = TRUE; - TNC->MCASTLen = len; - } - } - } - } - } - } - - if (TNC->DataLen > 520) - TNC->DataLen--; // Protect Buffer - } - else - { - // Look for '<' - - if (c == '<') - { - TNC->DataBuffer[0] = c; - TNC->DataLen = 1; - TNC->InPacket = TRUE; - TNC->InData = FALSE; - } - } - Len--; - } - return; - } - // Look for SOH/EOT delimiters. May Have several SOH before EOTTNC->FL - - while(Len) - { - c = *(MPTR++); - - switch (c) - { - case 01: // New Packet - - if (TNC->InPacket) - CheckFLDigiData(TNC); - - TNC->DataBuffer[0] = 1; - TNC->DataLen = 1; - TNC->InPacket = TRUE; - break; - - case 04: - - if (TNC->InPacket) - CheckFLDigiData(TNC); - TNC->DataLen = 0; - TNC->InPacket = FALSE; - - break; - - default: - - if (TNC->InPacket) - { - if (TNC->DataLen == 1) - { - if (c != '0' && c != '1') - { - // Drop if not Protocol '0' or '1' - this should eliminate almost all noise packets - - TNC->InPacket = 0; - break; - } - } - TNC->DataBuffer[TNC->DataLen++] = c; - } - - if (TNC->DataLen > 520) - TNC->DataLen--; // Protect Buffer - - } - Len--; - } -} -VOID CheckFLDigiData(struct TNCINFO * TNC) -{ - UCHAR * Input = &TNC->DataBuffer[0]; - int Len = TNC->DataLen - 4; // Not including CRC - unsigned short CRC; - char crcstring[6]; - - if (Len < 0) - return; - - TNC->DataBuffer[TNC->DataLen] = 0; - - // RAW format message, either from ARQ Scoket or RAW KISS - - // Check Checksum - - CRC = CalcCRC(Input , Len); - - sprintf(crcstring, "%04X", CRC); - - if (memcmp(&Input[Len], crcstring, 4) !=0) - { - // CRC Error - could just be noise - -// Debugprintf("%s %s", crcstring, Input); - return; - } - ProcessFLDigiData(TNC, &Input[3], Len - 3, Input[2], TRUE); // From RAW -} -/* -VOID ProcessARQPacket(struct PORTCONTROL * PORT, MESSAGE * Buffer) -{ - // ARQ Packet from KISS-Like Hardware - - struct TNCINFO * TNC = TNCInfo[PORT->PORTNUMBER]; - UCHAR * Input; - int Len; - - if (TNC == NULL) - { - // Set up TNC info - - TNC = TNCInfo[PORT->PORTNUMBER] = zalloc(sizeof(struct TNCINFO)); - TNC->ARQInfo = zalloc(sizeof(struct ARQINFO)); - TNC->FLInfo = zalloc(sizeof(struct FLINFO)); - - TNC->Timeout = 50; // Default retry = 10 seconds - TNC->Retries = 6; // Default Retries - TNC->Window = 16; - } - - Input = &Buffer->DEST[0]; - Len = Buffer->LENGTH - 7; // Not including CRC - - // Look for attach on any call - - ProcessFLDigiData(TNC, Input, Len); -} -*/ -static int Stuff(UCHAR * inbuff, UCHAR * outbuff, int len) -{ - int i, txptr = 0; - UCHAR c; - UCHAR * ptr = inbuff; - - // DLE Escape DLE, SOH, EOT - - for (i = 0; i < len; i++) - { - c = *(ptr++); - -// if (c == 0 || c == DLE || c == SOH || c == EOT) - if (c < 32 && c != 10 && c != 13 && c != 8) - { - outbuff[txptr++] = DLE; - - // if between 0 and 0x1F, Add 40, - // if > x80 and less than 0xa0 subtract 20 - - c += 0x40; - } - outbuff[txptr++]=c; - } - - return txptr; -} - - -static int UnStuff(UCHAR * inbuff, int len) -{ - int i, txptr = 0; - UCHAR c; - UCHAR * outbuff = inbuff; - UCHAR * ptr = inbuff; - - // This unstuffs into the input buffer - - for (i = 0; i < len; i++) - { - c = *(ptr++); - - if (c == DLE) - { - c = *(ptr++); - i++; - - // if between 0x40 and 0x5F, subtract 0x40, - // else add 0x20 (so we can send chars 80-9f without a double DLE) - - if (c < 0x60) - c -= 0x40; - else - c += 0x20; - } - outbuff[txptr++] = c; - } - - return txptr; -} - -unsigned int crcval = 0xFFFF; - -void update(char c) -{ - int i; - - crcval ^= c & 255; - for (i = 0; i < 8; ++i) - { - if (crcval & 1) - crcval = (crcval >> 1) ^ 0xA001; - else - crcval = (crcval >> 1); - } -} - -unsigned int CalcCRC(UCHAR * ptr, int Len) -{ - int i; - - crcval = 0xFFFF; - for (i = 0; i < Len; i++) - { - update(*ptr++); - } - return crcval; -} -/* - -<SOH>00cG8BPQ:1025 G8BPQ:24 0 8 T60R6W108E06<EOT> -<SOH>00kG8BPQ:24 G8BPQ 4 85F9B<EOT> - -<SOH>00cG8BPQ:1025 GM8BPQ:24 0 7 T60R5W1051D5<EOT> (128, 5) - -,<SOH>00cG8BPQ:1025 G8BPQ:24 0 7 T60R5W10FA36<EOT> -<SOH>00kG8BPQ:24 G8BPQ 5 89FCA<EOT> - -First no sees to be a connection counter. Next may be stream - - -<SOH>08s___ABFC<EOT> -<SOH>08tG8BPQ:73 xxx 33FA<EOT> -<SOH>00tG8BPQ:73 yyy 99A3<EOT> -<SOH>08dG8BPQ:90986C<EOT> -<SOH>00bG8BPQ:911207<EOT> - -call:90 for dis 91 for dis ack 73<sp> for chat) - -<SOH>08pG8BPQ<SUB>?__645E<EOT> -<SOH>00s_??4235<EOT> - -<SOH>08pG8BPQ<SUB>?__645E<EOT> -<SOH>00s_??4235<EOT> - -i Ident -c Connect -k Connect Ack -r Connect NAK -d Disconnect req -s Data Ack/ Retransmit Req )status) -p Poll -f Format Fail -b dis ack -t talk - -a Abort -o Abort ACK - - -<SOH>00cG8BPQ:1025 G8BPQ:24 0 7 T60R5W10FA36<EOT> -<SOH>00kG8BPQ:24 G8BPQ 6 49A3A<EOT> -<SOH>08s___ABFC<EOT> -<SOH>08 ARQ:FILE::flarqmail-1.eml -ARQ:EMAIL:: -ARQ:SIZE::90 -ARQ::STX -//FLARQ COMPOSER -Date: 09/01/2014 23:24:42 -To: gm8bpq -From: -SubjectA0E0<SOH> -<SOH>08!: Test - -Test Message - -ARQ::ETX -F0F2<SOH> -<SOH>08pG8BPQ<SUB>!__623E<EOT> -<SOH>08pG8BPQ<SUB>!__623E<EOT> -<SOH>08pG8BPQ<SUB>!__623E<EOT> - - - - -*/ -VOID ProcessFLDigiData(struct TNCINFO * TNC, UCHAR * Input, int Len, char Channel, BOOL RAW) -{ - UINT * buffptr; - int Stream = 0; - struct STREAMINFO * STREAM = &TNC->Streams[0]; - char CTRL = Input[0]; - struct ARQINFO * ARQ = TNC->ARQInfo; - struct FLINFO * FL = TNC->FLInfo; - - int SendLen; - char Reply[80]; - - - // Process Message - - // This processes eitrher message from the KISS or RAW interfaces. - // Headers and RAW checksum have been removed, so packet starts with Control Byte - - // Only a connect request is allowed with no session, so check first - - if (CTRL == 'c') - { - // Connect Request - - char * call1; - char * call2; - char * port1; - char * port2; - char * ptr; - char * context; - char FarStream = 0; - int BlockSize = 6; // 64 default - int Window = TNC->Window; - APPLCALLS * APPL; - char * ApplPtr = APPLS; - int App; - char Appl[10]; - struct WL2KInfo * WL2K = TNC->WL2K; - TRANSPORTENTRY * SESS; - - if (FL->CONOK == FALSE) - return; - - call1 = strtok_s(&Input[1], " ", &context); - call2 = strtok_s(NULL, " ", &context); - - port1 = strlop(call1, ':'); - port2 = strlop(call2, ':'); - - // See if for us - - for (App = 0; App < 32; App++) - { - APPL=&APPLCALLTABLE[App]; - memcpy(Appl, APPL->APPLCALL_TEXT, 10); - ptr=strchr(Appl, ' '); - - if (ptr) *ptr = 0; - - if (_stricmp(call2, Appl) == 0) - break; - } - - if (App > 31) - if (strcmp(TNC->NodeCall, call2) !=0) - return; // Not Appl or Port/Node Call - - ptr = strtok_s(NULL, " ", &context); - FarStream = *ptr; - ptr = strtok_s(NULL, " ", &context); - BlockSize = atoi(ptr); - - if (ARQ->ARQState) - { - // We have already received a connect request - just ACK it - - goto AckConnectRequest; - } - - // Get a Session - - SuspendOtherPorts(TNC); - - ProcessIncommingConnect(TNC, call1, 0, FALSE); - - SESS = TNC->PortRecord->ATTACHEDSESSIONS[0]; - - strcpy(STREAM->MyCall, call2); - STREAM->ConnectTime = time(NULL); - STREAM->BytesRXed = STREAM->BytesTXed = STREAM->BytesAcked = STREAM->BytesResent = 0; - - if (TNC->RIG && TNC->RIG != &TNC->DummyRig && strcmp(TNC->RIG->RigName, "PTT")) - { - sprintf(TNC->WEB_TNCSTATE, "%s Connected to %s Inbound Freq %s", TNC->Streams[0].RemoteCall, call2, TNC->RIG->Valchar); - SESS->Frequency = (atof(TNC->RIG->Valchar) * 1000000.0) + 1500; // Convert to Centre Freq - SESS->Mode = TNC->WL2KMode; - } - else - { - sprintf(TNC->WEB_TNCSTATE, "%s Connected to %s Inbound", TNC->Streams[0].RemoteCall, call2); - if (WL2K) - { - SESS->Frequency = WL2K->Freq; - SESS->Mode = WL2K->mode; - } - } - - if (WL2K) - strcpy(SESS->RMSCall, WL2K->RMSCall); - - SetWindowText(TNC->xIDC_TNCSTATE, TNC->WEB_TNCSTATE); - - strcpy(TNC->WEB_PROTOSTATE, "Connect Pending"); - SetWindowText(TNC->xIDC_PROTOSTATE, TNC->WEB_PROTOSTATE); - - memset(ARQ, 0, sizeof(struct ARQINFO)); // Reset ARQ State - ARQ->FarStream = FarStream; - ARQ->TXSeq = ARQ->TXLastACK = 63; // Last Sent - ARQ->RXHighest = ARQ->RXNoGaps = 63; // Last Received - ARQ->ARQState = ARQ_ACTIVE; - ARQ->OurStream = (rand() % 78) + 49; // To give some protection against other stuff on channel - ARQ->FarStream = FarStream; // Not Yet defined - if (strcmp(port1, "1025") == 0) - { - FL->FLARQ = TRUE; // From FLARQ - ARQ->OurStream = '8'; // FLARQ Ignores what we send - } - else - FL->FLARQ = FALSE; // From other app (eg BPQ) - - FL->RAW = RAW; - - STREAM->NeedDisc = 0; - - if (App < 32) - { - char AppName[13]; - - memcpy(AppName, &ApplPtr[App * sizeof(CMDX)], 12); - AppName[12] = 0; - - // Make sure app is available - - if (CheckAppl(TNC, AppName)) - { - char Buffer[32]; - int MsgLen = sprintf(Buffer, "%s\r", AppName); - - buffptr = GetBuff(); - - if (buffptr == 0) - { - return; // No buffers, so ignore - } - - buffptr[1] = MsgLen; - memcpy(buffptr+2, Buffer, MsgLen); - - C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr); - - TNC->SwallowSignon = TRUE; - - // Save Appl Call in case needed for - - } - else - { - STREAM->NeedDisc = 50; // 1 sec - } - } - - ARQ->TXWindow = Window; - - if (BlockSize < 4) BlockSize = 4; - if (BlockSize < 9) BlockSize = 9; - - ARQ->MaxBlock = Blocksizes[BlockSize]; - - - ARQ->ARQTimer = 10; // To force CTEXT to be Queued - - if (App == 32) - { - // Connect to Node - send CTEXT - - if (HFCTEXTLEN > 1) - { - buffptr = GetBuff(); - if (buffptr) - { - buffptr[1] = HFCTEXTLEN; - memcpy(&buffptr[2], HFCTEXT, HFCTEXTLEN); - SendARQData(TNC, buffptr); - } - } - } - - if (STREAM->NeedDisc) - { - // Send Not Avail - - buffptr = GetBuff(); - if (buffptr) - { - buffptr[1] = sprintf((char *)&buffptr[2], "Application Not Available\n"); - SendARQData(TNC, buffptr); - } - } - -AckConnectRequest: - - SendLen = sprintf(Reply, "k%s:24 %s %c 7", call2, call1, ARQ->OurStream); - - SaveAndSend(TNC, ARQ, TNC->TCPDataSock, Reply, SendLen); - ARQ->ARQTimerState = ARQ_CONNECTACK; - - return; - } - - // All others need a session - -// if (!STREAM->Connected && !STREAM->Connecting) -// return; - - if (CTRL == 'k') - { - // Connect ACK - - char * call1; - char * call2; - char * port1; - char * port2; - char * ptr; - char * context; - char FarStream = 0; - int BlockSize = 6; // 64 default - int Window = 16; - - char Reply[80]; - int ReplyLen; - - call1 = strtok_s(&Input[1], " ", &context); - call2 = strtok_s(NULL, " ", &context); - - port1 = strlop(call1, ':'); - port2 = strlop(call2, ':'); - - if (strcmp(call1, STREAM->RemoteCall) != 0) - return; - - if (Channel != ARQ->OurStream) - return; // Wrong Session - - ptr = strtok_s(NULL, " ", &context); - if (ptr) - FarStream = *ptr; - ptr = strtok_s(NULL, " ", &context); - if (ptr) - BlockSize = atoi(ptr); - - if (STREAM->Connected) - goto SendKReply; // Repeated ACK - - STREAM->ConnectTime = time(NULL); - STREAM->BytesRXed = STREAM->BytesTXed = STREAM->BytesAcked = STREAM->BytesResent = 0; - STREAM->Connected = TRUE; - - ARQ->ARQTimerState = 0; - ARQ->ARQTimer = 0; - - if (TNC->RIG) - sprintf(TNC->WEB_TNCSTATE, "%s Connected to %s Outbound Freq %s", STREAM->MyCall, STREAM->RemoteCall, TNC->RIG->Valchar); - else - sprintf(TNC->WEB_TNCSTATE, "%s Connected to %s Outbound", STREAM->MyCall, STREAM->RemoteCall); - - SetWindowText(TNC->xIDC_TNCSTATE, TNC->WEB_TNCSTATE); - - UpdateMH(TNC, STREAM->RemoteCall, '+', 'Z'); - - ARQ->ARQTimerState = 0; - ARQ->FarStream = FarStream; - ARQ->TXWindow = TNC->Window; - ARQ->MaxBlock = Blocksizes[BlockSize]; - - ARQ->ARQState = ARQ_ACTIVE; - - STREAM->NeedDisc = 0; - - buffptr = GetBuff(); - - if (buffptr) - { - ReplyLen = sprintf(Reply, "*** Connected to %s\r", STREAM->RemoteCall); - - buffptr[1] = ReplyLen; - memcpy(buffptr+2, Reply, ReplyLen); - - C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr); - } - - strcpy(TNC->WEB_PROTOSTATE, "Connected"); - SetWindowText(TNC->xIDC_PROTOSTATE, TNC->WEB_PROTOSTATE); - -SendKReply: - - // Reply with status - - SendLen = sprintf(Reply, "s%c%c%c", ARQ->TXSeq + 32, ARQ->RXNoGaps + 32, ARQ->RXHighest + 32); - - if (ARQ->RXHighest != ARQ->RXNoGaps) - { - int n = ARQ->RXNoGaps + 1; - n &= 63; - - while (n != ARQ->RXHighest) - { - if (ARQ->RXHOLDQ[n] == 0) // Dont have it - SendLen += sprintf(&Reply[SendLen], "%c", n + 32); - - n++; - n &= 63; - } - } - - QueueAndSend(TNC, ARQ, TNC->TCPDataSock, Reply, SendLen); - return; - } - - // All others need a session - - //if (!STREAM->Connected) - // return; - - - if (CTRL == 's') - { - // Status - - if (Channel != ARQ->OurStream) - return; // Wrong Session - - ARQ->ARQTimer = 0; // Stop retry timer - Input[Len] = 0; - ProcessARQStatus(TNC, ARQ, &Input[1]); - - return; - } - - if (CTRL == 'p') - { - // Poll - - char * call1; - char * context; - - call1 = strtok_s(&Input[1], " \x1A", &context); - - if (strcmp(call1, STREAM->RemoteCall) != 0) - return; - - if (Channel != ARQ->OurStream) - return; // Wrong Session - - SendLen = sprintf(Reply, "s%c%c%c", ARQ->TXSeq + 32, ARQ->RXNoGaps + 32, ARQ->RXHighest + 32); - - if (ARQ->RXHighest != ARQ->RXNoGaps) - { - int n = ARQ->RXNoGaps + 1; - n &= 63; - - while (n != ARQ->RXHighest) - { - if (ARQ->RXHOLDQ[n] == 0) // Dont have it - SendLen += sprintf(&Reply[SendLen], "%c", n + 32); - - n++; - n &= 63; - } - } - else - ARQ->TurnroundTimer = 15; // Allow us to send it all acked - - QueueAndSend(TNC, ARQ, TNC->TCPDataSock, Reply, SendLen); - - return; - } - - - if (CTRL == 'a') - { - // Abort. Send Abort ACK - same as - - char * call1; - char * context; - - call1 = strtok_s(&Input[1], " :", &context); - - if (strcmp(call1, STREAM->RemoteCall) != 0) - return; - - if (Channel != ARQ->OurStream) - return; // Wrong Session - - SendLen = sprintf(Reply, "o%c%c%c", ARQ->TXSeq + 32, ARQ->RXNoGaps + 32, ARQ->RXHighest + 32); - - if (ARQ->RXHighest != ARQ->RXNoGaps) - { - int n = ARQ->RXNoGaps + 1; - n &= 63; - - while (n != ARQ->RXHighest) - { - if (ARQ->RXHOLDQ[n] == 0) // Dont have it - SendLen += sprintf(&Reply[SendLen], "%c", n + 32); - - n++; - n &= 63; - } - } - - QueueAndSend(TNC, ARQ, TNC->TCPDataSock, Reply, SendLen); - return; - } - - if (CTRL == 'i') - { - // Ident - - return; - } - - if (CTRL == 't') - { - // Talk - not sure what to do with these - - return; - } - - if (CTRL == 'd') - { - // Disconnect Request - - char * call1; - char * context; - - call1 = strtok_s(&Input[1], " ", &context); - strlop(call1, ':'); - - if (strcmp(STREAM->RemoteCall, call1)) - return; - - if (Channel != ARQ->OurStream) - return; // Wrong Session - - - // As the Disc ACK isn't repeated, we have to clear session now - - STREAM->Connected = FALSE; - STREAM->Connecting = FALSE; - STREAM->ReportDISC = TRUE; - - strcpy(TNC->WEB_PROTOSTATE, "Disconncted"); - SetWindowText(TNC->xIDC_PROTOSTATE, TNC->WEB_PROTOSTATE); - - ARQ->ARQState = 0; - - SendLen = sprintf(Reply, "b%s:91", STREAM->MyCall); - - ARQ->ARQTimerState = ARQ_WAITACK; - SaveAndSend(TNC, ARQ, TNC->TCPDataSock, Reply, SendLen); - ARQ->Retries = 2; - return; - } - - if (CTRL == 'b') - { - // Disconnect ACK - - char * call1; - char * context; - - call1 = strtok_s(&Input[1], " ", &context); - strlop(call1, ':'); - - if (strcmp(STREAM->RemoteCall, call1)) - return; - - if (Channel != ARQ->OurStream) - return; // Wrong Session - - ARQ->ARQTimer = 0; - ARQ->ARQTimerState = 0; - ARQ->ARQState = 0; - - if (STREAM->Connected) - { - // Create a traffic record - - char logmsg[120]; - time_t Duration; - - Duration = time(NULL) - STREAM->ConnectTime; - - if (Duration == 0) - Duration = 1; - - sprintf(logmsg,"Port %2d %9s Bytes Sent %d BPS %d Bytes Received %d BPS %d Time %d Seconds", - TNC->Port, STREAM->RemoteCall, - STREAM->BytesTXed, (int)(STREAM->BytesTXed/Duration), - STREAM->BytesRXed, (int)(STREAM->BytesRXed/Duration), (int)Duration); - - Debugprintf(logmsg); - } - - STREAM->Connecting = FALSE; - STREAM->Connected = FALSE; // Back to Command Mode - STREAM->ReportDISC = TRUE; // Tell Node - - if (STREAM->Disconnecting) // - FLReleaseTNC(TNC); - - STREAM->Disconnecting = FALSE; - - strcpy(TNC->WEB_PROTOSTATE, "Disconncted"); - SetWindowText(TNC->xIDC_PROTOSTATE, TNC->WEB_PROTOSTATE); - - return; - } - - if (CTRL == 'u') - { - // Beacon - - //>00uGM8BPQ:72 GM8BPQ TestingAD67 - - char * Call = &Input[1]; - strlop(Call, ':'); - - UpdateMH(TNC, Call, '!', 0); - return; - } - - if (STREAM->Connected) - { - if (Channel != ARQ->OurStream) - return; // Wrong Session - - if (CTRL >= ' ' && CTRL < 96) - { - // ARQ Data - - int Seq = CTRL - 32; - int Work; - -// if (rand() % 5 == 2) -// { -// Debugprintf("Dropping %d", Seq); -// return; -// } - - buffptr = GetBuff(); - - if (buffptr == NULL) - return; // Sould never run out, but cant do much else - - // Remove any DLE transparency - - if (TNC->FLInfo->KISSMODE) - Len -= 1; - else - Len = UnStuff(&Input[1], Len - 1); - - buffptr[1] = Len; - memcpy(&buffptr[2], &Input[1], Len); - STREAM->BytesRXed += Len; - - UpdateStatsLine(TNC, STREAM); - - // Safest always to save, then see what we can process - - if (ARQ->RXHOLDQ[Seq]) - { - // Wot! Shouldn't happen - - ReleaseBuffer(ARQ->RXHOLDQ[Seq]); -// Debugprintf("ARQ Seq %d Duplicate"); - } - - ARQ->RXHOLDQ[Seq] = buffptr; -// Debugprintf("ARQ saving %d", Seq); - - // If this is higher that highest received, save. But beware of wrap' - - // Hi = 2, Seq = 60 dont save s=h = 58 - // Hi = 10 Seq = 12 save s-h = 2 - // Hi = 14 Seq = 10 dont save s-h = -4 - // Hi = 60 Seq = 2 save s-h = -58 - - Work = Seq - ARQ->RXHighest; - - if ((Work > 0 && Work < 32) || Work < -32) - ARQ->RXHighest = Seq; - - // We may now be able to process some - - Work = (ARQ->RXNoGaps + 1) & 63; // The next one we need - - while (ARQ->RXHOLDQ[Work]) - { - // We have it - - C_Q_ADD(&STREAM->PACTORtoBPQ_Q, ARQ->RXHOLDQ[Work]); -// ReleaseBuffer(ARQ->RXHOLDQ[Work]); - - ARQ->RXHOLDQ[Work] = NULL; -// Debugprintf("Processing %d from Q", Work); - - ARQ->RXNoGaps = Work; - Work = (Work + 1) & 63; // The next one we need - } - - ARQ->TurnroundTimer = 200; // Delay before allowing reply. Will normally be reset by the poll following data - return; - } - } -} - - -VOID SendARQData(struct TNCINFO * TNC, UINT * Buffer) -{ - // Send Data, saving a copy until acked. - - struct ARQINFO * ARQ = TNC->ARQInfo; - struct FLINFO * FL = TNC->FLInfo; - struct STREAMINFO * STREAM = &TNC->Streams[0]; - - - UCHAR TXBuffer[300]; - SOCKET sock = TNC->TCPDataSock; - int SendLen; - UCHAR * ptr; - int Origlen = Buffer[1]; - int Stuffedlen; - - ARQ->TXSeq++; - ARQ->TXSeq &= 63; - - SendLen = sprintf(TXBuffer, "%c", ARQ->TXSeq + 32); - - ptr = (UCHAR *)&Buffer[2]; // Start of data; - - ptr[Buffer[1]] = 0; - - if (memcmp(ptr, "ARQ:", 4) == 0) - { - // FLARQ Mail/FIle transfer. Turn off CR > LF translate (used for terminal mode) - - FL->FLARQ = FALSE; - } - - if (FL->FLARQ) - { - // Terminal Mode. Need to convert CR to LF so it displays in FLARQ Window - - ptr = strchr(ptr, 13); - - while (ptr) - { - *(ptr++) = 10; // Replace CR with LF - ptr = strchr(ptr, 13); - } - } - - if (TNC->FLInfo->KISSMODE) - { - memcpy(&TXBuffer[SendLen], (UCHAR *)&Buffer[2], Origlen); - SendLen += Origlen; - } - else - { - Stuffedlen = Stuff((UCHAR *)&Buffer[2], &TXBuffer[SendLen], Origlen); - SendLen += Stuffedlen; - } - - TXBuffer[SendLen] = 0; - -// if (rand() % 5 == 2) -// Debugprintf("Dropping %d", ARQ->TXSeq); -// else - - ARQ->TXHOLDQ[ARQ->TXSeq] = Buffer; - - STREAM->BytesTXed += Origlen; - - UpdateStatsLine(TNC, STREAM); - - // if waiting for ack, don't send, just queue. Will be sent when ack received - - if (ARQ->ARQTimer == 0 || ARQ->ARQTimerState == ARQ_WAITDATA) - { - SendPacket(TNC, TXBuffer, SendLen); - ARQ->ARQTimer = 15; // wait up to 1.5 sec for more data before polling - ARQ->Retries = 1; - ARQ->ARQTimerState = ARQ_WAITDATA; - } - else - STREAM->BytesResent -= Origlen; // So wont be included in resent bytes -} - -VOID TidyClose(struct TNCINFO * TNC, int Stream) -{ - char Reply[80]; - int SendLen; - - struct ARQINFO * ARQ = TNC->ARQInfo; - - SendLen = sprintf(Reply, "d%s:90", TNC->Streams[0].MyCall); - - SaveAndSend(TNC, ARQ, TNC->TCPDataSock, Reply, SendLen); - ARQ->ARQTimerState = ARQ_DISC; - - strcpy(TNC->WEB_PROTOSTATE, "Disconncting"); - SetWindowText(TNC->xIDC_PROTOSTATE, TNC->WEB_PROTOSTATE); -} - -VOID ForcedClose(struct TNCINFO * TNC, int Stream) -{ - TidyClose(TNC, Stream); // I don't think Hostmode has a DD -} - -VOID CloseComplete(struct TNCINFO * TNC, int Stream) -{ - FLReleaseTNC(TNC); -} - -VOID FLReleaseTNC(struct TNCINFO * TNC) -{ - // Set mycall back to Node or Port Call, and Start Scanner - - UCHAR TXMsg[1000]; - - strcpy(TNC->WEB_TNCSTATE, "Free"); - SetWindowText(TNC->xIDC_TNCSTATE, TNC->WEB_TNCSTATE); - - // if a default Modem is defined, select it - - if (TNC->FLInfo->DefaultMode[0]) - { - char txbuff[80]; - - if (TNC->FLInfo->KISSMODE) - { - sprintf(txbuff, "WFF:%d MODEM:%s MODEM: WFF:", TNC->FLInfo->DefaultFreq, TNC->FLInfo->DefaultMode); - SendKISSCommand(TNC, txbuff); - } - else - { - SendXMLCommand(TNC, "modem.set_by_name", TNC->FLInfo->DefaultMode, 'S'); - SendXMLCommand(TNC, "modem.set_carrier", (char *)TNC->FLInfo->DefaultFreq, 'I'); - } - } - // Start Scanner - - sprintf(TXMsg, "%d SCANSTART 15", TNC->Port); - - Rig_Command(-1, TXMsg); - - ReleaseOtherPorts(TNC); - -} -VOID QueueAndSend(struct TNCINFO * TNC, struct ARQINFO * ARQ, SOCKET sock, char * Msg, int MsgLen) -{ - // Queue to be sent after TXDELAY - - memcpy(ARQ->TXMsg, Msg, MsgLen + 1); - ARQ->TXLen = MsgLen; - ARQ->TXDelay = 15; // Try 1500 ms -} - -VOID SaveAndSend(struct TNCINFO * TNC, struct ARQINFO * ARQ, SOCKET sock, char * Msg, int MsgLen) -{ - // Used for Messages that need a reply. Save, send and set timeout - - memcpy(ARQ->LastMsg, Msg, MsgLen + 1); // Include Null - ARQ->LastLen = MsgLen; - - // Delay the send for a short while Just use the timeout code - -// SendPacket(sock, Msg, MsgLen, 0); - ARQ->ARQTimer = 1; // Try 500 ms - ARQ->Retries = TNC->Retries + 1; // First timout is rthe real send - - return; -} - - -VOID ARQTimer(struct TNCINFO * TNC) -{ - struct ARQINFO * ARQ = TNC->ARQInfo; - UINT * buffptr; - struct STREAMINFO * STREAM = &TNC->Streams[0]; - int SendLen; - char Reply[80]; - struct FLINFO * FL = TNC->FLInfo; - - //Send frames, unless held by TurnroundTimer or Window - - int Outstanding; - - // Use new BUSY: poll to detect busy state - - if (FL->TX == FALSE) - if (TNC->FLInfo->KISSMODE) - SendKISSCommand(TNC, "BUSY:"); // Send every poll for now - may need to optimize later - - -/* -// Use Received chars as a rough channel active indicator - - FL->BusyTimer++; - - if (FL->BusyTimer > 4) - { - FL->BusyTimer = 0; - - if (FL->BusyCounter > 2) // 2 chars in last .3 secs - FL->Busy = TRUE; - else - FL->Busy = FALSE; - - if (FL->TX) - strcpy(TNC->WEB_CHANSTATE, "TX"); - else - if (FL->Busy) - strcpy(TNC->WEB_CHANSTATE, "Busy"); - else - strcpy(TNC->WEB_CHANSTATE, "Idle"); - - FL->BusyCounter = 0; - - SetWindowText(TNC->xIDC_CHANSTATE, TNC->WEB_CHANSTATE); - } - -*/ // TXDelay is used as a turn round delay for frames that don't have to be retried. It doesn't - // need to check for busy (or anything else (I think!) - - if (ARQ->TXDelay) - { - ARQ->TXDelay--; - - if (ARQ->TXDelay) - return; - - SendPacket(TNC, ARQ->TXMsg, ARQ->TXLen); - } - - // if We are alredy sending (State = ARQ_WAITDATA) we should allow it to send more (and the Poll at end) - - if (ARQ->ARQTimerState == ARQ_WAITDATA) - { - while (STREAM->BPQtoPACTOR_Q) - { - Outstanding = ARQ->TXSeq - ARQ->TXLastACK; - - if (Outstanding < 0) - Outstanding += 64; - - TNC->PortRecord->FramesQueued = Outstanding + C_Q_COUNT(&STREAM->BPQtoPACTOR_Q); // Save for Appl Level Queued Frames - - if (Outstanding > ARQ->TXWindow) - break; - - buffptr = Q_REM(&STREAM->BPQtoPACTOR_Q); - SendARQData(TNC, buffptr); - } - - ARQ->ARQTimer--; - - if (ARQ->ARQTimer > 0) - return; // Timer Still Running - - // No more data available - send poll - - SendLen = sprintf(Reply, "p%s", TNC->Streams[0].MyCall); - - ARQ->ARQTimerState = ARQ_WAITACK; - - // This is one message that should not be queued so it is sent straiget after data - -// Debugprintf("Sending Poll"); - - memcpy(ARQ->LastMsg, Reply, SendLen + 1); - ARQ->LastLen = SendLen; - - SendPacket(TNC, Reply, SendLen); - - ARQ->ARQTimer = TNC->Timeout; - ARQ->Retries = TNC->Retries; - - strcpy(TNC->WEB_PROTOSTATE, "Wait ACK"); - SetWindowText(TNC->xIDC_PROTOSTATE, TNC->WEB_PROTOSTATE); - - return; - - } - - // TrunroundTimer is used to allow time for far end to revert to RX - - if (ARQ->TurnroundTimer && !FL->Busy) - ARQ->TurnroundTimer--; - - if (ARQ->TurnroundTimer == 0) - { - while (STREAM->BPQtoPACTOR_Q) - { - Outstanding = ARQ->TXSeq - ARQ->TXLastACK; - - if (Outstanding < 0) - Outstanding += 64; - - TNC->PortRecord->FramesQueued = Outstanding + C_Q_COUNT(&STREAM->BPQtoPACTOR_Q) + 1; // Make sure busy is reported to BBS - - if (Outstanding > ARQ->TXWindow) - break; - - buffptr = Q_REM(&STREAM->BPQtoPACTOR_Q); - SendARQData(TNC, buffptr); - } - } - - if (ARQ->ARQTimer) - { - if (FL->TX || FL->Busy) - { - // Only decrement if running send poll timer - - if (ARQ->ARQTimerState != ARQ_WAITDATA) - return; - } - - ARQ->ARQTimer--; - { - if (ARQ->ARQTimer) - return; // Timer Still Running - } - - ARQ->Retries--; - - if (ARQ->Retries) - { - // Retry Current Message - - SendPacket(TNC, ARQ->LastMsg, ARQ->LastLen); - ARQ->ARQTimer = TNC->Timeout + (rand() % 30); - - return; - } - - // Retried out. - - switch (ARQ->ARQTimerState) - { - case ARQ_WAITDATA: - - // No more data available - send poll - - SendLen = sprintf(Reply, "p%s", TNC->Streams[0].MyCall); - - ARQ->ARQTimerState = ARQ_WAITACK; - - // This is one message that should not be queued so it is sent straiget after data - - memcpy(ARQ->LastMsg, Reply, SendLen + 1); - ARQ->LastLen = SendLen; - - SendPacket(TNC, Reply, SendLen); - - ARQ->ARQTimer = TNC->Timeout; - ARQ->Retries = TNC->Retries; - - strcpy(TNC->WEB_PROTOSTATE, "Wait ACK"); - SetWindowText(TNC->xIDC_PROTOSTATE, TNC->WEB_PROTOSTATE); - - return; - - case ARQ_CONNECTING: - - // Report Connect Failed, and drop back to command mode - - buffptr = GetBuff(); - - if (buffptr) - { - buffptr[1] = sprintf((UCHAR *)&buffptr[2], "FLDigi} Failure with %s\r", STREAM->RemoteCall); - C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr); - } - - // Send Disc to TNC in case it got the Connects, but we missed the ACKs - - TidyClose(TNC, 0); - ARQ->Retries = 2; // First timout is the real send, only send once - STREAM->Connecting = FALSE; // Back to Command Mode - ARQ->ARQState = FALSE; - - break; - - case ARQ_WAITACK: - case ARQ_CONNECTACK: - case ARQ_DISC: - - STREAM->Connected = FALSE; // Back to Command Mode - STREAM->ReportDISC = TRUE; - ARQ->ARQState = FALSE; - - while (STREAM->PACTORtoBPQ_Q) - ReleaseBuffer(Q_REM(&STREAM->PACTORtoBPQ_Q)); - - while (STREAM->BPQtoPACTOR_Q) - ReleaseBuffer(Q_REM(&STREAM->BPQtoPACTOR_Q)); - - strcpy(TNC->WEB_TNCSTATE, "Free"); - SetWindowText(TNC->xIDC_TNCSTATE, TNC->WEB_TNCSTATE); - - strcpy(TNC->WEB_PROTOSTATE, "Disconncted"); - SetWindowText(TNC->xIDC_PROTOSTATE, TNC->WEB_PROTOSTATE); - - break; - - } - } -} - -VOID ProcessARQStatus(struct TNCINFO * TNC, struct ARQINFO * ARQ, char * Input) -{ - // Release any acked frames and resend any outstanding - - int LastInSeq = Input[1] - 32; - int LastRXed = Input[2] - 32; - int FirstUnAcked = ARQ->TXLastACK; - int n = (int)strlen(Input) - 3; - char * ptr; - int NexttoResend; - int First, Last, Outstanding; - UINT * Buffer; - struct STREAMINFO * STREAM = &TNC->Streams[0]; - int Acked = 0; - - // First status is an ack of Connect ACK - - if (ARQ->ARQTimerState == ARQ_CONNECTACK) - { - ARQ->Retries = 0; - ARQ->ARQTimer = 0; - ARQ->ARQTimerState = 0; - - strcpy(TNC->WEB_PROTOSTATE, "Connected"); - SetWindowText(TNC->xIDC_PROTOSTATE, TNC->WEB_PROTOSTATE); - } - - // Release all up to LastInSeq - - while (FirstUnAcked != LastInSeq) - { - FirstUnAcked++; - FirstUnAcked &= 63; - - Buffer = ARQ->TXHOLDQ[FirstUnAcked]; - - if (Buffer) - { -// Debugprintf("Acked %d", FirstUnAcked); - STREAM->BytesAcked += Buffer[1]; - ReleaseBuffer(Buffer); - ARQ->TXHOLDQ[FirstUnAcked] = NULL; - Acked++; - } - } - - ARQ->TXLastACK = FirstUnAcked; - - Outstanding = ARQ->TXSeq - ARQ->TXLastACK; - - if (Outstanding < 0) - Outstanding += 64; - - TNC->PortRecord->FramesQueued = Outstanding + C_Q_COUNT(&STREAM->BPQtoPACTOR_Q); // Save for Appl Level Queued Frames - - if (FirstUnAcked == ARQ->TXSeq) - { - UpdateStatsLine(TNC, STREAM); - ARQ->NoAckRetries = 0; - - strcpy(TNC->WEB_PROTOSTATE, "Connected"); - SetWindowText(TNC->xIDC_PROTOSTATE, TNC->WEB_PROTOSTATE); - - return; // All Acked - } - // Release any not in retry list up to LastRXed. - - ptr = &Input[3]; - - while (n) - { - NexttoResend = *(ptr++) - 32; - - FirstUnAcked++; - FirstUnAcked &= 63; - - while (FirstUnAcked != NexttoResend) - { - Buffer = ARQ->TXHOLDQ[FirstUnAcked]; - - if (Buffer) - { -// Debugprintf("Acked %d", FirstUnAcked); - STREAM->BytesAcked += Buffer[1]; - ReleaseBuffer(Buffer); - ARQ->TXHOLDQ[FirstUnAcked] = NULL; - Acked++; - } - - FirstUnAcked++; - FirstUnAcked &= 63; - } - - // We don't ACK this one. Process any more resend values, then release up to LastRXed. - - n--; - } - - // Release rest up to LastRXed - - while (FirstUnAcked != LastRXed) - { - FirstUnAcked++; - FirstUnAcked &= 63; - - Buffer = ARQ->TXHOLDQ[FirstUnAcked]; - - if (Buffer) - { -// Debugprintf("Acked %d", FirstUnAcked); - STREAM->BytesAcked += Buffer[1]; - ReleaseBuffer(Buffer); - ARQ->TXHOLDQ[FirstUnAcked] = NULL; - Acked++; - } - } - - // Resend anything in TX Buffer (From LastACK to TXSeq - - Last = ARQ->TXSeq + 1; - Last &= 63; - - First = LastInSeq; - - while (First != Last) - { - First++; - First &= 63; - - if(ARQ->TXHOLDQ[First]) - { - UINT * Buffer = ARQ->TXHOLDQ[First]; - UCHAR TXBuffer[300]; - SOCKET sock = TNC->TCPDataSock; - int SendLen; - -// Debugprintf("Resend %d", First); - - STREAM->BytesResent += Buffer[1]; - - SendLen = sprintf(TXBuffer, "%c", First + 32); - - if (TNC->FLInfo->KISSMODE) - { - memcpy(&TXBuffer[SendLen], (UCHAR *)&Buffer[2], Buffer[1]); - SendLen += Buffer[1]; - } - else - SendLen += Stuff((UCHAR *)&Buffer[2], &TXBuffer[SendLen], Buffer[1]); - - TXBuffer[SendLen] = 0; - - SendPacket(TNC, TXBuffer, SendLen); - - ARQ->ARQTimer = 10; // wait up to 1 sec for more data before polling - ARQ->Retries = 1; - ARQ->ARQTimerState = ARQ_WAITDATA; - - if (Acked == 0) - { - // Nothing acked by this statis message - - Acked = 0; // Dont count more thna once - ARQ->NoAckRetries++; - if (ARQ->NoAckRetries > TNC->Retries) - { - // Too many retries - just disconnect - - TidyClose(TNC, 0); - return; - } - } - } - } - - UpdateStatsLine(TNC, STREAM); -} - -VOID FLSlowTimer(struct TNCINFO * TNC) -{ - struct FLINFO * FL = TNC->FLInfo; - - // Entered every 10 secs - - // if in MCAST mode, clear KILL timer (MCAST RX can run for a long time - - if (TNC->FLInfo->MCASTMODE) - { - TRANSPORTENTRY * SESS = TNC->PortRecord->ATTACHEDSESSIONS[0]; - - if (SESS) - SESS->L4KILLTIMER = 0; - } - - if (FL->KISSMODE) - { - if (FL->Responding) - FL->Responding--; - - if (FL->Responding == 0) - { - TNC->TNCOK = FALSE; - TNC->CONNECTED = FALSE; - - sprintf(TNC->WEB_COMMSSTATE, "Connection to FLDIGI lost"); - SetWindowText(TNC->xIDC_COMMSSTATE, TNC->WEB_COMMSSTATE); - - // Set basic params till it responds - } - - FL->CmdControl++; - - if (FL->CmdControl > 5) // Every Minute - { - FL->CmdControl = 0; - - SendKISSCommand(TNC, "FLSTAT: MODEM: WFF:"); - } - - SendKISSCommand(TNC, "TRXS: TXBUF:"); // In case TX/RX report is missed - } -} - -static int ProcessXMLData(int port) -{ - unsigned int bytes; - int i; - char ErrMsg[255]; - char Message[500]; - struct TNCINFO * TNC = TNCInfo[port]; - struct FLINFO * FL = TNC->FLInfo; - char * ptr1, * ptr2, *ptr3; - - // Need to extract messages from byte stream - - bytes = recv(TNC->TCPSock,(char *)&Message, 500, 0); - - if (bytes == SOCKET_ERROR) - { -// i=sprintf(ErrMsg, "Read Failed for FLDigi socket - error code = %d\r\n", WSAGetLastError()); -// WritetoConsole(ErrMsg); - - closesocket(TNC->TCPSock); - - TNC->CONNECTED = FALSE; - if (TNC->Streams[0].Attached) - TNC->Streams[0].ReportDISC = TRUE; - - return (0); - } - - if (bytes == 0) - { - // zero bytes means connection closed - - i=sprintf(ErrMsg, "FlDigi Connection closed for BPQ Port %d\n", port); - WritetoConsole(ErrMsg); - - TNC->CONNECTED = FALSE; - if (TNC->Streams[0].Attached) - TNC->Streams[0].ReportDISC = TRUE; - - return (0); - } - - // Have some data. Assume for now we get a whole packet - - if (TNC->InternalCmd) - { - ULONG * buffptr = GetBuff(); - - TNC->InternalCmd = FALSE; - - ptr1 = strstr(Message, "<value>"); - - if (ptr1) - { - ptr1 += 7; - ptr2 = strstr(ptr1, "</value>"); - if (ptr2) *ptr2 = 0; - - ptr3 = strstr(ptr1, "<i4>"); - - if (ptr3) - { - ptr1 = ptr3 + 4; - ptr2 = strstr(ptr1, "</i4>"); - if (ptr2) *ptr2 = 0; - } - - if (buffptr) - { - buffptr[1] = sprintf((UCHAR *)&buffptr[2], "FLDIGI} Ok Was %s\r", ptr1); - C_Q_ADD(&TNC->Streams[0].PACTORtoBPQ_Q, buffptr); - } - } - - return 0; - } - - - ptr1 = strstr(Message, "<value>"); - - if (ptr1) - { - ptr1 += 7; - ptr2 = strstr(ptr1, "</value>"); - if (ptr2) *ptr2 = 0; - - ptr2 = strstr(ptr1, "<string>"); - - if (ptr2) - { - ptr2 += 8; - ptr1 = ptr2; - ptr2 = strstr(ptr1, "</string>"); - if (ptr2) *ptr2 = 0; - } - - if (strcmp(FL->LastXML, "modem.get_name") == 0) - { - strcpy(TNC->WEB_MODE, ptr1); - SetWindowText(TNC->xIDC_MODE, ptr1); - } - else if (strcmp(FL->LastXML, "main.get_trx_state") == 0) - { - if (strcmp(ptr1, "TX") == 0) - FL->TX = TRUE; - else - FL->TX = FALSE; - - - if (FL->TX) - strcpy(TNC->WEB_CHANSTATE, "TX"); - else - if (FL->Busy) - strcpy(TNC->WEB_CHANSTATE, "Busy"); - else - strcpy(TNC->WEB_CHANSTATE, "Idle"); - - SetWindowText(TNC->xIDC_CHANSTATE, TNC->WEB_CHANSTATE); - } - else if (strcmp(FL->LastXML, "main.get_squelch") == 0) - { -/* - if (_memicmp(Buffer, "BUSY TRUE", 9) == 0) - { - TNC->BusyFlags |= CDBusy; - TNC->Busy = TNC->BusyHold * 10; // BusyHold delay - - SetWindowText(TNC->xIDC_CHANSTATE, "Busy"); - strcpy(TNC->WEB_CHANSTATE, "Busy"); - - TNC->WinmorRestartCodecTimer = time(NULL); -*/ - return 0; - } -/* - if (_memicmp(Buffer, "BUSY FALSE", 10) == 0) - { - TNC->BusyFlags &= ~CDBusy; - if (TNC->BusyHold) - strcpy(TNC->WEB_CHANSTATE, "BusyHold"); - else - strcpy(TNC->WEB_CHANSTATE, "Clear"); - - SetWindowText(TNC->xIDC_CHANSTATE, TNC->WEB_CHANSTATE); - TNC->WinmorRestartCodecTimer = time(NULL); - return; - } -*/ - - } - - return (0); - -} - - - -char MsgHddr[] = "POST /RPC2 HTTP/1.1\r\n" - "User-Agent: XMLRPC++ 0.8\r\n" - "Host: 127.0.0.1:7362\r\n" - "Content-Type: text/xml\r\n" - "Content-length: %d\r\n" - "\r\n%s"; - -char Req[] = "<?xml version=\"1.0\"?>\r\n" - "<methodCall><methodName>%s</methodName>\r\n" - "%s" - "</methodCall>\r\n"; - - -VOID SendXMLCommand(struct TNCINFO * TNC, char * Command, char * Value, char ParamType) -{ - int Len; - char ReqBuf[512]; - char SendBuff[512]; - struct FLINFO * FL = TNC->FLInfo; - struct ARQINFO * ARQ = TNC->ARQInfo; - char ValueString[256] =""; - - if (!TNC->CONNECTED || TNC->FLInfo->KISSMODE) - return; - - if (Value) - if (ParamType == 'S') - sprintf(ValueString, "<params><param><value><string>%s</string></value></param></params\r\n>", Value); - else - sprintf(ValueString, "<params><param><value><i4>%d</i4></value></param></params\r\n>", Value); - - strcpy(FL->LastXML, Command); - Len = sprintf(ReqBuf, Req, FL->LastXML, ValueString); - Len = sprintf(SendBuff, MsgHddr, Len, ReqBuf); - send(TNC->TCPSock, SendBuff, Len, 0); - return; -} - -VOID SendXMLPoll(struct TNCINFO * TNC) -{ - int Len; - char ReqBuf[256]; - char SendBuff[256]; - struct FLINFO * FL = TNC->FLInfo; - struct ARQINFO * ARQ = TNC->ARQInfo; - - if (!TNC->CONNECTED) - return; - - if (TNC->FLInfo->KISSMODE) - return; - - if (ARQ->ARQTimer) - { - // if timer is running, poll fot TX State - - strcpy(FL->LastXML, "main.get_trx_state"); - Len = sprintf(ReqBuf, Req, FL->LastXML, ""); - Len = sprintf(SendBuff, MsgHddr, Len, ReqBuf); - send(TNC->TCPSock, SendBuff, Len, 0); - return; - } - - FL->XMLControl++; - - - if (FL->XMLControl > 9) - { - FL->XMLControl = 0; - strcpy(FL->LastXML, "modem.get_name"); - } - else - { - if (FL->XMLControl == 5) - strcpy(FL->LastXML, "main.get_trx_state"); - else - return; - } - - Len = sprintf(ReqBuf, Req, FL->LastXML, ""); - Len = sprintf(SendBuff, MsgHddr, Len, ReqBuf); - send(TNC->TCPSock, SendBuff, Len, 0); -} - -// sudo add-apt-repository ppa:kamalmostafa/fldigi - - +/*
+Copyright 2001-2018 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
+*/
+
+//
+// FLARQ Emulator/FLDIGI Interface for BPQ32
+//
+
+#define _CRT_SECURE_NO_DEPRECATE
+
+#include "CHeaders.h"
+
+int (WINAPI FAR *GetModuleFileNameExPtr)();
+int (WINAPI FAR *EnumProcessesPtr)();
+
+
+#include <stdio.h>
+#include <time.h>
+
+#include "tncinfo.h"
+
+#include "bpq32.h"
+
+#define VERSION_MAJOR 2
+#define VERSION_MINOR 0
+
+#define SD_RECEIVE 0x00
+#define SD_SEND 0x01
+#define SD_BOTH 0x02
+
+#define DLE 0x10
+#define SOH 1
+#define STX 2
+#define EOT 4
+
+#define FEND 0xC0
+#define FESC 0xDB
+#define TFEND 0xDC
+#define TFESC 0xDD
+
+#define TIMESTAMP 352
+
+#define CONTIMEOUT 1200
+
+#define AGWHDDRLEN sizeof(struct AGWHEADER)
+
+extern int (WINAPI FAR *GetModuleFileNameExPtr)();
+
+//int ResetExtDriver(int num);
+extern char * PortConfig[33];
+int SemHeldByAPI;
+
+struct TNCINFO * TNCInfo[34]; // Records are Malloc'd
+
+static void ConnecttoFLDigiThread(void * portptr);
+
+void CreateMHWindow();
+int Update_MH_List(struct in_addr ipad, char * call, char proto);
+
+static int ConnecttoFLDigi();
+static int ProcessReceivedData(int bpqport);
+static int ProcessLine(char * buf, int Port);
+int KillTNC(struct TNCINFO * TNC);
+static int RestartTNC(struct TNCINFO * TNC);
+VOID ProcessFLDigiPacket(struct TNCINFO * TNC, char * Message, int Len);
+VOID ProcessFLDigiKISSPacket(struct TNCINFO * TNC, char * Message, int Len);
+struct TNCINFO * GetSessionKey(char * key, struct TNCINFO * TNC);
+VOID SendARQData(struct TNCINFO * TNC, UINT * Buffer);
+static VOID DoMonitorHddr(struct TNCINFO * TNC, struct AGWHEADER * RXHeader, UCHAR * Msg);
+VOID SendRPBeacon(struct TNCINFO * TNC);
+VOID FLReleaseTNC(struct TNCINFO * TNC);
+unsigned int CalcCRC(UCHAR * ptr, int Len);
+VOID ARQTimer(struct TNCINFO * TNC);
+VOID QueueAndSend(struct TNCINFO * TNC, struct ARQINFO * ARQ, SOCKET sock, char * Msg, int MsgLen);
+VOID SaveAndSend(struct TNCINFO * TNC, struct ARQINFO * ARQ, SOCKET sock, char * Msg, int MsgLen);
+VOID ProcessARQStatus(struct TNCINFO * TNC, struct ARQINFO * ARQ, char *Input);
+VOID SendXMLPoll(struct TNCINFO * TNC);
+static int ProcessXMLData(int port);
+VOID CheckFLDigiData(struct TNCINFO * TNC);
+VOID SendPacket(struct TNCINFO * TNC, UCHAR * Msg, int MsgLen);
+int KissEncode(UCHAR * inbuff, UCHAR * outbuff, int len);
+VOID SendXMLCommand(struct TNCINFO * TNC, char * Command, char * Value, char ParamType);
+VOID FLSlowTimer(struct TNCINFO * TNC);
+VOID SendKISSCommand(struct TNCINFO * TNC, char * Msg);
+
+int DoScanLine(struct TNCINFO * TNC, char * Buff, int Len);
+VOID SuspendOtherPorts(struct TNCINFO * ThisTNC);
+VOID ReleaseOtherPorts(struct TNCINFO * ThisTNC);
+
+char * strlop(char * buf, char delim);
+
+extern UCHAR BPQDirectory[];
+
+#define MAXBPQPORTS 32
+#define MAXMPSKPORTS 16
+
+//LOGFONT LFTTYFONT ;
+
+//HFONT hFont ;
+
+static int MPSKChannel[MAXBPQPORTS+1]; // BPQ Port to MPSK Port
+static int BPQPort[MAXMPSKPORTS][MAXBPQPORTS+1]; // MPSK Port and Connection to BPQ Port
+//static int MPSKtoBPQ_Q[MAXBPQPORTS+1]; // Frames for BPQ, indexed by BPQ Port
+//static int BPQtoMPSK_Q[MAXBPQPORTS+1]; // Frames for MPSK. indexed by MPSK port. Only used it TCP session is blocked
+
+// Each port may be on a different machine. We only open one connection to each MPSK instance
+
+static char * MPSKSignon[MAXBPQPORTS+1]; // Pointer to message for secure signin
+
+static unsigned int MPSKInst = 0;
+static int AttachedProcesses=0;
+
+static HWND hResWnd,hMHWnd;
+static BOOL GotMsg;
+
+static HANDLE STDOUT=0;
+
+//SOCKET sock;
+
+static SOCKADDR_IN sinx;
+static SOCKADDR_IN rxaddr;
+static SOCKADDR_IN destaddr[MAXBPQPORTS+1];
+
+static int addrlen=sizeof(sinx);
+
+//static short MPSKPort=0;
+
+static time_t ltime,lasttime[MAXBPQPORTS+1];
+
+static BOOL CONNECTING[MAXBPQPORTS+1];
+static BOOL CONNECTED[MAXBPQPORTS+1];
+
+//HANDLE hInstance;
+
+static char WindowTitle[] = "FLDIGI";
+static char ClassName[] = "FLDIGISTATUS";
+static int RigControlRow = 165;
+
+static fd_set readfs;
+static fd_set writefs;
+static fd_set errorfs;
+static struct timeval timeout;
+
+int Blocksizes[10] = {0,2,4,8,16,32,64,128,256,512};
+
+
+static size_t ExtProc(int fn, int port, PDATAMESSAGE buff)
+{
+ PMSGWITHLEN buffptr;
+ char txbuff[500];
+ unsigned int txlen=0;
+ struct TNCINFO * TNC = TNCInfo[port];
+ int Stream = 0;
+ struct STREAMINFO * STREAM;
+ int TNCOK;
+
+ if (TNC == NULL)
+ return 0; // Port not defined
+
+ // Look for attach on any call
+
+// for (Stream = 0; Stream <= 1; Stream++)
+ {
+ STREAM = &TNC->Streams[Stream];
+
+ if (TNC->PortRecord->ATTACHEDSESSIONS[Stream] && TNC->Streams[Stream].Attached == 0)
+ {
+ char Cmd[80];
+
+ // New Attach
+
+ int calllen;
+ STREAM->Attached = TRUE;
+
+ TNC->FLInfo->RAW = FALSE;
+
+ calllen = ConvFromAX25(TNC->PortRecord->ATTACHEDSESSIONS[Stream]->L4USER, STREAM->MyCall);
+ STREAM->MyCall[calllen] = 0;
+ STREAM->FramesOutstanding = 0;
+
+ SuspendOtherPorts(TNC); // Dont allow connects on interlocked ports
+
+ // Stop Scanning
+
+ sprintf(Cmd, "%d SCANSTOP", TNC->Port);
+ Rig_Command(-1, Cmd);
+
+ sprintf(TNC->WEB_TNCSTATE, "In Use by %s", TNC->Streams[0].MyCall);
+ SetWindowText(TNC->xIDC_TNCSTATE, TNC->WEB_TNCSTATE);
+
+/* len = sprintf(Cmd, "%cSTOP_BEACON_ARQ_FAE\x1b", '\x1a');
+
+ if (TNC->MPSKInfo->TX)
+ TNC->CmdSet = TNC->CmdSave = _strdup(Cmd); // Savde till not transmitting
+ else
+ SendPacket(TNC->TCPDataSock, Cmd, len, 0);
+*/
+ }
+ }
+
+ switch (fn)
+ {
+ case 7:
+
+ // 100 mS Timer.
+
+ // See if waiting for busy to clear before sending a connect
+
+ if (TNC->BusyDelay)
+ {
+ // Still Busy?
+
+ if (InterlockedCheckBusy(TNC) == FALSE)
+ {
+ // No, so send connect
+
+ struct ARQINFO * ARQ = TNC->ARQInfo;
+ int SendLen;
+ char Reply[80];
+
+ SendLen = sprintf(Reply, "c%s:42 %s:24 %c 7 T60R5W10",
+ STREAM->MyCall, STREAM->RemoteCall, ARQ->OurStream);
+
+ strcpy(TNC->WEB_PROTOSTATE, "Connecting");
+ SetWindowText(TNC->xIDC_PROTOSTATE, TNC->WEB_PROTOSTATE);
+
+ ARQ->ARQState = ARQ_ACTIVE;
+
+ ARQ->ARQTimerState = ARQ_CONNECTING;
+ SaveAndSend(TNC, ARQ, TNC->TCPDataSock, Reply, SendLen);
+
+ STREAM->Connecting = TRUE;
+
+ sprintf(TNC->WEB_TNCSTATE, "%s Connecting to %s", STREAM->MyCall, STREAM->RemoteCall);
+ SetWindowText(TNC->xIDC_TNCSTATE, TNC->WEB_TNCSTATE);
+
+ strcpy(TNC->WEB_PROTOSTATE, "Connecting");
+ SetWindowText(TNC->xIDC_PROTOSTATE, TNC->WEB_PROTOSTATE);
+
+ 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->Streams[0].PACTORtoBPQ_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 (STREAM->NeedDisc)
+ {
+ STREAM->NeedDisc--;
+
+ if (STREAM->NeedDisc == 0)
+ {
+ // Send the DISCONNECT
+
+ TidyClose(TNC, 0);
+ }
+ }
+
+ ARQTimer(TNC);
+ SendXMLPoll(TNC);
+
+ TNC->SlowTimer--;
+
+ if (TNC->SlowTimer < 0)
+ {
+ TNC->SlowTimer = 100;
+ FLSlowTimer(TNC); // 10 Secs
+ }
+
+ return 0;
+
+ case 1: // poll
+
+ if (TNC->CONNECTED == FALSE && TNC->CONNECTING == FALSE && TNC->FLInfo->KISSMODE == FALSE)
+ {
+ // See if time to reconnect
+
+ time( <ime );
+ if (ltime-lasttime[port] >9 )
+ {
+ ConnecttoFLDigi(port);
+ lasttime[port]=ltime;
+ }
+ }
+
+ FD_ZERO(&readfs);
+
+ if (TNC->CONNECTED)
+ if (TNC->TCPSock)
+ FD_SET(TNC->TCPSock,&readfs);
+
+ if (TNC->CONNECTED || TNC->FLInfo->KISSMODE)
+ FD_SET(TNC->TCPDataSock,&readfs);
+
+
+// FD_ZERO(&writefs);
+
+// if (TNC->BPQtoWINMOR_Q) FD_SET(TNC->TCPDataSock,&writefs); // Need notification of busy clearing
+
+ FD_ZERO(&errorfs);
+
+ if (TNC->CONNECTED)
+ if (TNC->TCPSock)
+ FD_SET(TNC->TCPSock,&errorfs);
+
+ if (TNC->CONNECTED || TNC->FLInfo->KISSMODE)
+ FD_SET(TNC->TCPDataSock,&errorfs);
+
+
+ if (select((int)TNC->TCPDataSock + 1, &readfs, &writefs, &errorfs, &timeout) > 0)
+ {
+ // See what happened
+
+ if (FD_ISSET(TNC->TCPDataSock,&readfs))
+ {
+ // data available
+
+ ProcessReceivedData(port);
+ }
+
+ if (FD_ISSET(TNC->TCPSock,&readfs))
+ {
+ // data available
+
+ ProcessXMLData(port);
+ }
+
+
+ if (FD_ISSET(TNC->TCPDataSock,&writefs))
+ {
+ // Connect success
+
+ TNC->CONNECTED = TRUE;
+ TNC->CONNECTING = FALSE;
+
+ sprintf(TNC->WEB_COMMSSTATE, "Connected to FLDIGI");
+ SetWindowText(TNC->xIDC_COMMSSTATE, TNC->WEB_COMMSSTATE);
+
+ // If required, send signon
+
+// SendPacket(TNC->TCPDataSock,"\x1a", 1, 0);
+// SendPacket(TNC->TCPDataSock,"DIGITAL MODE ?", 14, 0);
+// SendPacket(TNC->TCPDataSock,"\x1b", 1, 0);
+
+// EnumWindows(EnumTNCWindowsProc, (LPARAM)TNC);
+ }
+
+ if (FD_ISSET(TNC->TCPDataSock,&errorfs) || FD_ISSET(TNC->TCPSock,&errorfs))
+ {
+ // if connecting, then failed, if connected then has just disconnected
+
+// if (CONNECTED[port])
+// if (!CONNECTING[port])
+// {
+// i=sprintf(ErrMsg, "MPSK Connection lost for BPQ Port %d\r\n", port);
+// WritetoConsole(ErrMsg);
+// }
+
+ CONNECTING[port]=FALSE;
+ CONNECTED[port]=FALSE;
+
+ }
+
+ }
+
+
+
+ // See if any frames for this port
+
+ for (Stream = 0; Stream <= 1; Stream++)
+ {
+ STREAM = &TNC->Streams[Stream];
+
+
+ if (STREAM->Attached)
+ CheckForDetach(TNC, Stream, STREAM, TidyClose, ForcedClose, CloseComplete);
+
+ if (STREAM->ReportDISC)
+ {
+ STREAM->ReportDISC = FALSE;
+ buff->PORT = Stream;
+
+ return -1;
+ }
+
+ // if Busy, send buffer status poll
+
+ if (STREAM->PACTORtoBPQ_Q == 0)
+ {
+ if (STREAM->DiscWhenAllSent)
+ {
+ STREAM->DiscWhenAllSent--;
+ if (STREAM->DiscWhenAllSent == 0)
+ STREAM->ReportDISC = TRUE; // Dont want to leave session attached. Causes too much confusion
+ }
+ }
+ else
+ {
+ int datalen;
+
+ buffptr=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 (TNC->PortRecord->UI_Q)
+ {
+ struct _MESSAGE * buffptr;
+ int SendLen;
+ char Reply[256];
+ int UILen;
+ char * UIMsg;
+
+ buffptr = Q_REM(&TNC->PortRecord->UI_Q);
+
+ UILen = buffptr->LENGTH;
+ UILen -= 23;
+ UIMsg = buffptr->L2DATA;
+
+ UIMsg[UILen] = 0;
+
+ if (UILen < 129 && TNC->Streams[0].Attached == FALSE) // Be sensible!
+ {
+ // >00uG8BPQ:72 TestA
+ SendLen = sprintf(Reply, "u%s:72 %s", TNC->NodeCall, UIMsg);
+ SendPacket(TNC, Reply, SendLen);
+ }
+ ReleaseBuffer(buffptr);
+ }
+
+ return (0);
+
+ case 2: // send
+
+
+ if (!TNC->CONNECTED) return 0; // Don't try if not connected to TNC
+
+ Stream = buff->PORT;
+
+ STREAM = &TNC->Streams[Stream];
+
+// txlen=(buff[6]<<8) + buff[5] - 8;
+
+ txlen = GetLengthfromBuffer((PDATAMESSAGE)buff) - 8;
+
+ if (STREAM->Connected)
+ {
+ buffptr = GetBuff();
+
+ if (buffptr == 0) return (0); // No buffers, so ignore
+
+ buffptr->Len = txlen;
+ memcpy(buffptr->Data, buff->L2DATA, txlen);
+
+ C_Q_ADD(&TNC->Streams[Stream].BPQtoPACTOR_Q, buffptr);
+
+ return (0);
+ }
+ else
+ {
+ buff->L2DATA[txlen] = 0;
+ _strupr(&buff->L2DATA[0]);
+
+ if (_memicmp(&buff->L2DATA[0], "D\r", 2) == 0)
+ {
+ if (STREAM->Connected)
+ TidyClose(TNC, buff->PORT);
+
+ STREAM->ReportDISC = TRUE; // Tell Node
+
+ TNC->FLInfo->MCASTMODE = FALSE;
+
+ 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->CIRCUITINDEX, &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], "MODEM ", 6) == 0)
+ {
+ buff->L2DATA[txlen -1] = 0;
+ _strupr(&buff->L2DATA[0]);
+
+ // If in KISS mode, send as a KISS command Frame
+
+ if (TNC->FLInfo->KISSMODE)
+ {
+ sprintf(txbuff, "MODEM:%s MODEM:", &buff->L2DATA[6]);
+ SendKISSCommand(TNC, txbuff);
+ }
+ else
+ {
+ SendXMLCommand(TNC, "modem.set_by_name", &buff->L2DATA[6], 'S');
+ }
+
+ TNC->InternalCmd = TRUE;
+ return 1;
+ }
+
+ if (_memicmp(buff->L2DATA, "FREQ ", 5) == 0)
+ {
+ buff->L2DATA[txlen - 1] = 0;
+ _strupr(&buff->L2DATA[0]);
+
+ // If in KISS mode, send as a KISS command Frame
+
+ if (TNC->FLInfo->KISSMODE)
+ {
+ sprintf(txbuff, "WFF:%s WFF:", &buff->L2DATA[5]);
+ SendKISSCommand(TNC, txbuff);
+ }
+ else
+ {
+ SendXMLCommand(TNC, "modem.set_carrier", atoi(&buff->L2DATA[5]), 'I');
+ }
+
+ TNC->InternalCmd = TRUE;
+ return 1;
+ }
+
+ if (_memicmp(buff->L2DATA, "SQUELCH ", 8) == 0)
+ {
+ buff->L2DATA[txlen - 1] = 0;
+ _strupr(&buff->L2DATA[0]);
+
+ // Only works in KISS
+
+ if (TNC->FLInfo->KISSMODE)
+ {
+ if (_memicmp(&buff->L2DATA[8], "ON", 2) == 0)
+ sprintf(txbuff, "KPSQL:ON KPSQL:");
+
+ else if (_memicmp(&buff->L2DATA[8], "OFF", 3) == 0)
+ sprintf(txbuff, "KPSQL:OFF KPSQL:");
+ else
+ txlen = sprintf(txbuff, "KPSQLS:%s KPSQLS:", &buff->L2DATA[8]);
+
+ SendKISSCommand(TNC, txbuff);
+ TNC->InternalCmd = TRUE;
+ }
+ return 1;
+ }
+
+ if (_memicmp(buff->L2DATA, "KPSATT ", 7) == 0)
+ {
+ buff->L2DATA[txlen - 1] = 0;
+ _strupr(&buff->L2DATA[0]);
+
+ // If in KISS mode, send as a KISS command Frame
+
+ if (TNC->FLInfo->KISSMODE)
+ {
+ sprintf(txbuff, "KPSATT:%s KPSATT:", &buff->L2DATA[7]);
+
+ SendKISSCommand(TNC, txbuff);
+ TNC->InternalCmd = TRUE;
+ }
+
+ return 1;
+ }
+
+ if (STREAM->Connecting && _memicmp(buff->L2DATA, "ABORT", 5) == 0)
+ {
+// len = sprintf(Command,"%cSTOP_SELECTIVE_CALL_ARQ_FAE\x1b", '\x1a');
+
+// if (TNC->MPSKInfo->TX)
+// TNC->CmdSet = TNC->CmdSave = _strdup(Command); // Save till not transmitting
+// else
+// SendPacket(TNC->TCPDataSock, Command, len, 0);
+
+// TNC->InternalCmd = TRUE;
+ return (0);
+ }
+
+ if (_memicmp(&buff->L2DATA[0], "MODE", 4) == 0)
+ {
+ PMSGWITHLEN buffptr = GetBuff();
+
+ buff->L2DATA[txlen - 1] = 0; // Remove CR
+
+ if (strstr(&buff->L2DATA[0], "RAW"))
+ TNC->FLInfo->RAW = TRUE;
+ else if (strstr(&buff->L2DATA[0], "KISS"))
+ TNC->FLInfo->RAW = FALSE;
+ else
+ {
+ buffptr->Len = sprintf(&buffptr->Data[0], "FLDigi} Error - Invalid Mode\r");
+ C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr);
+ return 1;
+ }
+
+ buffptr->Len = sprintf(&buffptr->Data[0], "FLDigi} Ok - Mode is %s\r",
+ (TNC->FLInfo->RAW)?"RAW":"KISS");
+
+ C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr);
+
+ return 1;
+ }
+
+ if (_memicmp(&buff->L2DATA[0], "MCAST", 5) == 0)
+ {
+ UINT * buffptr = GetBuff();
+
+ TNC->FLInfo->MCASTMODE = TRUE;
+
+ buffptr[1] = sprintf((UCHAR *)&buffptr[2], "FLDigi} Ok\r");
+ C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr);
+
+ return 1;
+ }
+
+ if (_memicmp(&buff->L2DATA[0], "INUSE?", 6) == 0)
+ {
+ // Return Error if in use, OK if not
+
+ UINT * buffptr = GetBuff();
+ int s = 0;
+
+ while(s <= 1)
+ {
+ if (s != Stream)
+ {
+ if (TNC->PortRecord->ATTACHEDSESSIONS[s])
+ {
+ buffptr[1] = sprintf((UCHAR *)&buffptr[2], "FLDig} Error - In use\r");
+ C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr);
+ return 1; // Busy
+ }
+ }
+ s++;
+ }
+ buffptr[1] = sprintf((UCHAR *)&buffptr[2], "FLDigi} Ok - Not in use\r");
+ C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr);
+
+ return 1;
+ }
+
+ // See if a Connect Command.
+
+ if (toupper(buff->L2DATA[0]) == 'C' && buff->L2DATA[1] == ' ' && txlen > 2) // Connect
+ {
+ char * ptr;
+ char * context;
+ struct ARQINFO * ARQ = TNC->ARQInfo;
+ int SendLen;
+ char Reply[80];
+
+ buff->L2DATA[txlen] = 0;
+ _strupr(&buff->L2DATA[0]);
+
+ memset(ARQ, 0, sizeof(struct ARQINFO)); // Reset ARQ State
+ ARQ->TXSeq = ARQ->TXLastACK = 63; // Last Sent
+ ARQ->RXHighest = ARQ->RXNoGaps = 63; // Last Received
+ ARQ->OurStream = (rand() % 78) + 49; // To give some protection against other stuff on channel
+ ARQ->FarStream = 48; // Not yet defined
+ TNC->FLInfo->FLARQ = FALSE;
+
+ memset(STREAM->RemoteCall, 0, 10);
+
+ ptr = strtok_s(&buff->L2DATA[2], " ,\r", &context);
+ strcpy(STREAM->RemoteCall, ptr);
+
+ // 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");
+ SetWindowText(TNC->xIDC_TNCSTATE, TNC->WEB_TNCSTATE);
+
+ TNC->BusyDelay = TNC->BusyWait * 10; // BusyWait secs
+ return 0;
+ }
+ }
+
+ TNC->OverrideBusy = FALSE;
+
+//<SOH>00cG8BPQ:1025 G8BPQ:24 0 7 T60R5W10FA36<EOT>
+
+ SendLen = sprintf(Reply, "c%s:42 %s:24 %c 7 T60R5W10",
+ STREAM->MyCall, STREAM->RemoteCall, ARQ->OurStream);
+
+ strcpy(TNC->WEB_PROTOSTATE, "Connecting");
+ SetWindowText(TNC->xIDC_PROTOSTATE, TNC->WEB_PROTOSTATE);
+
+ ARQ->ARQState = ARQ_ACTIVE;
+
+ ARQ->ARQTimerState = ARQ_CONNECTING;
+ SaveAndSend(TNC, ARQ, TNC->TCPDataSock, Reply, SendLen);
+
+ STREAM->Connecting = TRUE;
+
+ sprintf(TNC->WEB_TNCSTATE, "%s Connecting to %s", STREAM->MyCall, STREAM->RemoteCall);
+ SetWindowText(TNC->xIDC_TNCSTATE, TNC->WEB_TNCSTATE);
+
+ strcpy(TNC->WEB_PROTOSTATE, "Connecting");
+ SetWindowText(TNC->xIDC_PROTOSTATE, TNC->WEB_PROTOSTATE);
+
+ return 0;
+ }
+
+ // Send any other command to FLDIGI
+
+ buff->L2DATA[txlen - 1] = 0;
+ _strupr(&buff->L2DATA[0]);
+
+ // If in KISS mode, send as a KISS command Frame
+
+ if (TNC->FLInfo->KISSMODE)
+ {
+ char outbuff[1000];
+ int newlen;
+
+ buff->L2DATA[-1] = 6; // KISS Control
+
+ newlen = KissEncode(&buff->L2DATA[-1], outbuff, txlen);
+ sendto(TNC->TCPDataSock, outbuff, newlen, 0, (struct sockaddr *)&TNC->Datadestaddr, sizeof(struct sockaddr));
+ }
+ else
+ {
+ SendXMLCommand(TNC, "modem.set_by_name", &buff->L2DATA[0], 'S');
+ }
+
+ TNC->InternalCmd = TRUE;
+ }
+
+ return (0);
+
+ case 3:
+
+ Stream = (int)(size_t)buff;
+
+ TNCOK = TNC->CONNECTED;
+
+ STREAM = &TNC->Streams[Stream];
+ {
+ // Busy if TX Window reached
+
+ struct ARQINFO * ARQ = TNC->ARQInfo;
+ int Outstanding;
+
+ Outstanding = ARQ->TXSeq - ARQ->TXLastACK;
+
+ if (Outstanding < 0)
+ Outstanding += 64;
+
+ TNC->PortRecord->FramesQueued = Outstanding + C_Q_COUNT(&TNC->Streams[0].BPQtoPACTOR_Q); // Save for Appl Level Queued Frames
+
+ if (Outstanding > ARQ->TXWindow)
+ return (1 | TNCOK << 8 | STREAM->Disconnecting << 15); // 3rd Nibble is frames unacked
+ else
+ return TNCOK << 8 | STREAM->Disconnecting << 15;
+
+ }
+ return TNCOK << 8 | STREAM->Disconnecting << 15; // OK, but lock attach if disconnecting
+
+ case 4: // reinit
+
+ shutdown(TNC->TCPSock, SD_BOTH);
+ shutdown(TNC->TCPDataSock, SD_BOTH);
+ Sleep(100);
+
+ closesocket(TNC->TCPSock);
+ closesocket(TNC->TCPDataSock);
+ TNC->CONNECTED = FALSE;
+
+ if (TNC->WeStartedTNC)
+ {
+ KillTNC(TNC);
+ RestartTNC(TNC);
+ }
+
+ return (0);
+
+ case 5: // Close
+
+ shutdown(TNC->TCPSock, SD_BOTH);
+ shutdown(TNC->TCPDataSock, SD_BOTH);
+ Sleep(100);
+
+ closesocket(TNC->TCPSock);
+ closesocket(TNC->TCPDataSock);
+
+ if (TNC->WeStartedTNC)
+ {
+ KillTNC(TNC);
+ }
+
+ return 0;
+ }
+
+ return 0;
+}
+
+#ifndef LINBPQ
+
+int FindFLDIGI(char * Path)
+{
+ HANDLE hProc;
+ char ExeName[256] = "";
+ char FLDIGIName[256];
+ DWORD Pid = 0;
+ DWORD Processes[1024], Needed, Count;
+ unsigned int i;
+
+ if (EnumProcessesPtr == NULL)
+ return 0; // Cant get PID
+
+ if (!EnumProcessesPtr(Processes, sizeof(Processes), &Needed))
+ return TRUE;
+
+ // Path is to .bat, so need to strip extension of both names
+
+ strcpy(FLDIGIName, Path);
+ strlop(FLDIGIName, '.');
+
+ // Calculate how many process identifiers were returned.
+
+ Count = Needed / sizeof(DWORD);
+
+ for (i = 0; i < Count; i++)
+ {
+ if (Processes[i] != 0)
+ {
+ hProc = OpenProcess(PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, Processes[i]);
+
+ if (hProc)
+ {
+ GetModuleFileNameExPtr(hProc, 0, ExeName, 255);
+ CloseHandle(hProc);
+
+ strlop(ExeName, '.');
+
+ if (_stricmp(ExeName, FLDIGIName) == 0)
+ return Processes[i];
+
+ }
+ }
+ }
+ return 0;
+}
+
+
+static KillTNC(struct TNCINFO * TNC)
+{
+ HANDLE hProc;
+
+ if (TNC->PTTMode)
+ Rig_PTT(TNC->RIG, FALSE); // Make sure PTT is down
+
+ if (TNC->ProgramPath)
+ TNC->PID = FindFLDIGI(TNC->ProgramPath);
+
+ if (TNC->PID == 0) return 0;
+
+ hProc = OpenProcess(PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, TNC->PID);
+
+ if (hProc)
+ {
+ TerminateProcess(hProc, 0);
+ CloseHandle(hProc);
+ }
+
+ TNC->WeStartedTNC = 0; // So we don't try again
+
+ return 0;
+}
+
+#endif
+
+static int RestartTNC(struct TNCINFO * TNC)
+{
+ if (TNC->ProgramPath == NULL)
+ return 0;
+
+ _strlwr(TNC->ProgramPath);
+
+ if (_memicmp(TNC->ProgramPath, "REMOTE:", 7) == 0)
+ {
+ int n;
+
+ // Try to start TNC on a remote host
+
+ SOCKET sock = socket(AF_INET,SOCK_DGRAM,0);
+ struct sockaddr_in destaddr;
+
+ Debugprintf("trying to restart FLDIGI %s", TNC->ProgramPath);
+
+ if (sock == INVALID_SOCKET)
+ return 0;
+
+ destaddr.sin_family = AF_INET;
+ destaddr.sin_addr.s_addr = inet_addr(TNC->HostName);
+ destaddr.sin_port = htons(8500);
+
+ if (destaddr.sin_addr.s_addr == INADDR_NONE)
+ {
+ // Resolve name to address
+
+ struct hostent * HostEnt = gethostbyname (TNC->HostName);
+
+ if (!HostEnt)
+ return 0; // Resolve failed
+
+ memcpy(&destaddr.sin_addr.s_addr,HostEnt->h_addr,4);
+ }
+
+ n = sendto(sock, TNC->ProgramPath, (int)strlen(TNC->ProgramPath), 0, (struct sockaddr *)&destaddr, sizeof(destaddr));
+
+ Debugprintf("Restart FLDIGI - sento returned %d", n);
+
+ Sleep(100);
+ closesocket(sock);
+
+ return 1; // Cant tell if it worked, but assume ok
+ }
+#ifndef LINBPQ
+ {
+ STARTUPINFO SInfo; // pointer to STARTUPINFO
+ PROCESS_INFORMATION PInfo; // pointer to PROCESS_INFORMATION
+ char HomeDir[MAX_PATH];
+ int i, ret;
+
+ SInfo.cb=sizeof(SInfo);
+ SInfo.lpReserved=NULL;
+ SInfo.lpDesktop=NULL;
+ SInfo.lpTitle=NULL;
+ SInfo.dwFlags=0;
+ SInfo.cbReserved2=0;
+ SInfo.lpReserved2=NULL;
+
+ if (TNC->ProgramPath)
+ {
+ strcpy(HomeDir, TNC->ProgramPath);
+ i = strlen(HomeDir);
+
+ while(--i)
+ {
+ if (HomeDir[i] == '/' || HomeDir[i] == '\\')
+ {
+ HomeDir[i] = 0;
+ break;
+ }
+ }
+
+ // for some reason the program name must be lower case
+
+ _strlwr(TNC->ProgramPath);
+
+ ret = CreateProcess(TNC->ProgramPath, NULL, NULL, NULL, FALSE,0 ,NULL , NULL, &SInfo, &PInfo);
+ return ret;
+ }
+ }
+#endif
+ 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>FLDigi Status</title></head><body id=Text onload=\"ScrollOutput()\">"
+ "<h2>FLDIGI Status</h2>");
+
+
+ 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 FLDIGISuspendPort(struct TNCINFO * TNC)
+{
+ TNC->FLInfo->CONOK = FALSE;
+}
+
+VOID FLDIGIReleasePort(struct TNCINFO * TNC)
+{
+ TNC->FLInfo->CONOK = TRUE;
+}
+
+VOID SendKISSCommand(struct TNCINFO * TNC, char * Msg)
+{
+ int txlen, rc;
+ char txbuff[256];
+ char outbuff[256];
+
+ txlen = sprintf(txbuff, "%c%s", 6, Msg);
+ txlen = KissEncode(txbuff, outbuff, txlen);
+ rc = sendto(TNC->TCPDataSock, outbuff, txlen, 0, (struct sockaddr *)&TNC->Datadestaddr, sizeof(struct sockaddr));
+}
+
+VOID * FLDigiExtInit(EXTPORTDATA * PortEntry)
+{
+ int i, port;
+ char Msg[255];
+ struct TNCINFO * TNC;
+ char * ptr;
+
+ //
+ // The Socket to connect to is in IOBASE
+ //
+
+ srand((unsigned int)time(NULL));
+
+ 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 ExtProc;
+ }
+
+ TNC->Port = port;
+
+ 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->PERMITGATEWAY = TRUE; // Can change ax.25 call on each stream
+ PortEntry->PORTCONTROL.UICAPABLE = 1; // Can send beacons
+ PortEntry->PORTCONTROL.PORTQUALITY = 0;
+ PortEntry->SCANCAPABILITIES = NONE; // Scan Control - None
+
+ TNC->FLInfo->CONOK = TRUE;
+
+ if (PortEntry->PORTCONTROL.PORTPACLEN == 0 || PortEntry->PORTCONTROL.PORTPACLEN > 128)
+ PortEntry->PORTCONTROL.PORTPACLEN = 64;
+
+ TNC->SuspendPortProc = FLDIGISuspendPort;
+ TNC->ReleasePortProc = FLDIGIReleasePort;
+
+ ptr=strchr(TNC->NodeCall, ' ');
+ if (ptr) *(ptr) = 0; // Null Terminate
+
+ TNC->Hardware = H_FLDIGI;
+
+ if (TNC->BusyWait == 0)
+ TNC->BusyWait = 10;
+
+ MPSKChannel[port] = PortEntry->PORTCONTROL.CHANNELNUM-65;
+
+ PortEntry->MAXHOSTMODESESSIONS = 1;
+
+ i=sprintf(Msg,"FLDigi Host %s Port %d \n",
+ TNC->HostName, TNC->TCPPort);
+
+ WritetoConsole(Msg);
+
+#ifndef LINBPQ
+
+ if (TNC->ProgramPath)
+ TNC->PID = FindFLDIGI(TNC->ProgramPath);
+
+ if (TNC->PID == 0) // Not running
+#endif
+ TNC->WeStartedTNC = RestartTNC(TNC); // Always try if Linux
+
+ if (TNC->FLInfo->KISSMODE)
+ {
+ // Open Datagram port
+
+ SOCKET sock;
+ u_long param=1;
+ BOOL bcopt=TRUE;
+ struct sockaddr_in sinx;
+ struct hostent * HostEnt = NULL;
+
+ TNC->FLInfo->CmdControl = 5; //Send params immediately
+
+ TNC->Datadestaddr.sin_addr.s_addr = inet_addr(TNC->HostName);
+
+ if (TNC->Datadestaddr.sin_addr.s_addr == INADDR_NONE)
+ {
+ // Resolve name to address
+
+ HostEnt = gethostbyname (TNC->HostName);
+
+ if (HostEnt)
+ {
+ memcpy(&TNC->Datadestaddr.sin_addr.s_addr,HostEnt->h_addr,4);
+ }
+ }
+
+ TNC->TCPDataSock = sock = socket(AF_INET,SOCK_DGRAM,0);
+
+ ioctl(sock, FIONBIO, ¶m);
+
+ setsockopt(sock, SOL_SOCKET, SO_BROADCAST, (const char FAR *)&bcopt,4);
+
+ sinx.sin_family = AF_INET;
+ sinx.sin_addr.s_addr = INADDR_ANY;
+ sinx.sin_port = htons(TNC->TCPPort + 1);
+
+ if (bind(sock, (struct sockaddr *) &sinx, sizeof(sinx)) != 0 )
+ {
+ // Bind Failed
+
+ int err = WSAGetLastError();
+ Consoleprintf("Bind Failed for UDP port %d - error code = %d", TNC->TCPPort, err);
+ }
+
+ TNC->Datadestaddr.sin_family = AF_INET;
+ TNC->Datadestaddr.sin_port = htons(TNC->TCPPort);
+ }
+ else
+ ConnecttoFLDigi(port);
+
+ time(&lasttime[port]); // Get initial time value
+
+ PortEntry->PORTCONTROL.TNC = TNC;
+
+ TNC->WebWindowProc = WebProc;
+ TNC->WebWinX = 520;
+ TNC->WebWinY = 500;
+ TNC->WebBuffer = zalloc(5000);
+
+ TNC->WEB_COMMSSTATE = zalloc(100);
+ TNC->WEB_TNCSTATE = zalloc(100);
+ TNC->WEB_CHANSTATE = zalloc(100);
+ TNC->WEB_BUFFERS = zalloc(100);
+ TNC->WEB_PROTOSTATE = zalloc(100);
+ TNC->WEB_RESTARTTIME = zalloc(100);
+ TNC->WEB_RESTARTS = zalloc(100);
+
+ TNC->WEB_MODE = zalloc(50);
+ TNC->WEB_TRAFFIC = zalloc(100);
+
+
+#ifndef LINBPQ
+
+ CreatePactorWindow(TNC, ClassName, WindowTitle, RigControlRow, PacWndProc, 500, 450, ForcedClose);
+
+ CreateWindowEx(0, "STATIC", "Comms State", WS_CHILD | WS_VISIBLE, 10,6,120,20, TNC->hDlg, NULL, hInstance, NULL);
+ TNC->xIDC_COMMSSTATE = CreateWindowEx(0, "STATIC", "", WS_CHILD | WS_VISIBLE, 116,6,386,20, TNC->hDlg, NULL, hInstance, NULL);
+
+ CreateWindowEx(0, "STATIC", "TNC State", WS_CHILD | WS_VISIBLE, 10,28,106,20, TNC->hDlg, NULL, hInstance, NULL);
+ TNC->xIDC_TNCSTATE = CreateWindowEx(0, "STATIC", "", WS_CHILD | WS_VISIBLE, 116,28,520,20, TNC->hDlg, NULL, hInstance, NULL);
+
+ CreateWindowEx(0, "STATIC", "Mode/CF", WS_CHILD | WS_VISIBLE, 10,50,80,20, TNC->hDlg, NULL, hInstance, NULL);
+ TNC->xIDC_MODE = CreateWindowEx(0, "STATIC", "", WS_CHILD | WS_VISIBLE, 116,50,200,20, TNC->hDlg, NULL, hInstance, NULL);
+
+ CreateWindowEx(0, "STATIC", "Channel State", WS_CHILD | WS_VISIBLE, 10,72,110,20, TNC->hDlg, NULL, hInstance, NULL);
+ TNC->xIDC_CHANSTATE = CreateWindowEx(0, "STATIC", "", WS_CHILD | WS_VISIBLE, 116,72,144,20, TNC->hDlg, NULL, hInstance, NULL);
+
+ CreateWindowEx(0, "STATIC", "Proto State", WS_CHILD | WS_VISIBLE,10,94,80,20, TNC->hDlg, NULL, hInstance, NULL);
+ TNC->xIDC_PROTOSTATE = CreateWindowEx(0, "STATIC", "", WS_CHILD | WS_VISIBLE,116,94,374,20 , TNC->hDlg, NULL, hInstance, NULL);
+
+ CreateWindowEx(0, "STATIC", "Traffic", WS_CHILD | WS_VISIBLE,10,116,80,20, TNC->hDlg, NULL, hInstance, NULL);
+ TNC->xIDC_TRAFFIC = CreateWindowEx(0, "STATIC", "RX 0 TX 0 ACKED 0 Resent 0", WS_CHILD | WS_VISIBLE,116,116,374,20 , TNC->hDlg, NULL, hInstance, NULL);
+
+ TNC->hMonitor= CreateWindowEx(0, "LISTBOX", "", WS_CHILD | WS_VISIBLE | LBS_NOINTEGRALHEIGHT |
+ LBS_DISABLENOSCROLL | WS_HSCROLL | WS_VSCROLL,
+ 0,170,250,300, TNC->hDlg, NULL, hInstance, NULL);
+
+ TNC->ClientHeight = 450;
+ TNC->ClientWidth = 500;
+
+ TNC->hMenu = CreatePopupMenu();
+
+ AppendMenu(TNC->hMenu, MF_STRING, WINMOR_KILL, "Kill FLDigi");
+ AppendMenu(TNC->hMenu, MF_STRING, WINMOR_RESTART, "Kill and Restart FLDigi");
+ AppendMenu(TNC->hMenu, MF_STRING, ARDOP_ABORT, "Abort Current Session");
+
+ MoveWindows(TNC);
+#endif
+
+ return ExtProc;
+
+}
+
+
+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;
+ struct ARQINFO * ARQ;
+ struct FLINFO * FL;
+
+ 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] = zalloc(sizeof(struct TNCINFO));
+
+ ARQ = TNC->ARQInfo = zalloc(sizeof(struct ARQINFO));
+ FL = TNC->FLInfo = zalloc(sizeof(struct FLINFO));
+
+ TNC->Timeout = 50; // Default retry = 5 seconds
+ TNC->Retries = 6; // Default Retries
+ TNC->Window = 16;
+
+ TNC->FLInfo->KISSMODE = TRUE; // Default to KISS
+
+ 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);
+
+ TNC->TCPPort = atoi(p_port);
+
+ TNC->destaddr.sin_family = AF_INET;
+ TNC->destaddr.sin_port = htons(TNC->TCPPort + 40); // Defaults XML 7362 ARQ 7322
+
+ TNC->Datadestaddr.sin_family = AF_INET;
+ TNC->Datadestaddr.sin_port = htons(TNC->TCPPort);
+
+ 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 (_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, "TIMEOUT", 7) == 0)
+ TNC->Timeout = atoi(&buf[8]) * 10;
+ else
+ if (_memicmp(buf, "RETRIES", 7) == 0)
+ TNC->Retries = atoi(&buf[8]);
+ else
+ if (_memicmp(buf, "WINDOW", 6) == 0)
+ TNC->Window = atoi(&buf[7]);
+ else
+ if (_memicmp(buf, "ARQMODE", 7) == 0)
+ TNC->FLInfo->KISSMODE = FALSE;
+ else
+ if (_memicmp(buf, "DEFAULTMODEM", 12) == 0) // Send Beacon after each session
+ {
+ // Check that freq is also specified
+
+ char * Freq = strchr(&buf[13], '/');
+
+ if (Freq)
+ {
+ *(Freq++) = 0;
+ strcpy(TNC->FLInfo->DefaultMode, &buf[13]);
+ TNC->FLInfo->DefaultFreq = atoi(Freq);
+ }
+ }
+ else
+
+ strcat (TNC->InitScript, buf);
+ }
+
+
+ return (TRUE);
+}
+
+static int ConnecttoFLDigi(int port)
+{
+ _beginthread(ConnecttoFLDigiThread, 0, (void *)(size_t)port);
+
+ return 0;
+}
+
+static VOID ConnecttoFLDigiThread(void * portptr)
+{
+ int port = (int)(size_t)portptr;
+ char Msg[255];
+ int err,i;
+ u_long param=1;
+ BOOL bcopt=TRUE;
+ struct hostent * HostEnt = NULL;
+ struct TNCINFO * TNC = TNCInfo[port];
+
+ Sleep(5000); // Allow init to complete
+
+ TNC->destaddr.sin_addr.s_addr = inet_addr(TNC->HostName);
+ TNC->Datadestaddr.sin_addr.s_addr = inet_addr(TNC->HostName);
+
+ if (TNC->destaddr.sin_addr.s_addr == INADDR_NONE)
+ {
+ // Resolve name to address
+
+ HostEnt = gethostbyname (TNC->HostName);
+
+ if (!HostEnt) return; // Resolve failed
+
+ memcpy(&TNC->destaddr.sin_addr.s_addr,HostEnt->h_addr,4);
+ memcpy(&TNC->Datadestaddr.sin_addr.s_addr,HostEnt->h_addr,4);
+ }
+
+ if (TNC->TCPSock)
+ {
+ Debugprintf("FLDIGI Closing Sock %d", TNC->TCPSock);
+ closesocket(TNC->TCPSock);
+ }
+
+ TNC->TCPSock = 0;
+
+
+ TNC->TCPSock=socket(AF_INET,SOCK_STREAM,0);
+
+ if (TNC->TCPSock == INVALID_SOCKET)
+ {
+ i=sprintf(Msg, "Socket Failed for FLDigi Control socket - error code = %d\n", WSAGetLastError());
+ WritetoConsole(Msg);
+ return;
+ }
+
+ setsockopt (TNC->TCPSock, SOL_SOCKET, SO_REUSEADDR, (const char FAR *)&bcopt, 4);
+
+ sinx.sin_family = AF_INET;
+ sinx.sin_addr.s_addr = INADDR_ANY;
+ sinx.sin_port = 0;
+
+ TNC->CONNECTING = TRUE;
+
+ if (connect(TNC->TCPSock,(LPSOCKADDR) &TNC->destaddr,sizeof(TNC->destaddr)) == 0)
+ {
+ //
+ // Connected successful
+ //
+ }
+ else
+ {
+ if (TNC->Alerted == FALSE)
+ {
+ err=WSAGetLastError();
+ i=sprintf(Msg, "Connect Failed for FLDigi Control socket - error code = %d\n", err);
+ WritetoConsole(Msg);
+
+ sprintf(TNC->WEB_COMMSSTATE, "Connection to TNC failed");
+ MySetWindowText(TNC->xIDC_COMMSSTATE, TNC->WEB_COMMSSTATE);
+ TNC->Alerted = TRUE;
+ }
+
+ closesocket(TNC->TCPSock);
+ TNC->TCPSock = 0;
+ TNC->CONNECTING = FALSE;
+ return;
+ }
+
+ TNC->LastFreq = 0;
+
+ if (TNC->TCPDataSock)
+ closesocket(TNC->TCPDataSock);
+
+ TNC->TCPDataSock = 0;
+
+ TNC->TCPDataSock=socket(AF_INET,SOCK_STREAM,0);
+
+ setsockopt (TNC->TCPDataSock, SOL_SOCKET, SO_REUSEADDR, (const char FAR *)&bcopt, 4);
+
+ if (TNC->TCPDataSock == INVALID_SOCKET)
+ {
+ i=sprintf(Msg, "Socket Failed for FLDigi socket - error code = %d\r\n", WSAGetLastError());
+ WritetoConsole(Msg);
+
+ closesocket(TNC->TCPSock);
+ closesocket(TNC->TCPDataSock);
+ TNC->TCPSock = 0;
+ TNC->CONNECTING = FALSE;
+
+ return;
+ }
+
+ if (bind(TNC->TCPDataSock, (LPSOCKADDR) &sinx, addrlen) != 0 )
+ {
+ //
+ // Bind Failed
+ //
+
+ i=sprintf(Msg, "Bind Failed for FLDigi Data socket - error code = %d\r\n", WSAGetLastError());
+ WritetoConsole(Msg);
+
+ closesocket(TNC->TCPSock);
+ closesocket(TNC->TCPDataSock);
+ TNC->TCPSock = 0;
+ TNC->TCPDataSock = 0;
+ TNC->CONNECTING = FALSE;
+ return;
+ }
+
+ if (connect(TNC->TCPDataSock,(LPSOCKADDR) &TNC->Datadestaddr,sizeof(TNC->Datadestaddr)) == 0)
+ {
+ ioctlsocket (TNC->TCPDataSock,FIONBIO,¶m); // Set nonblocking
+ TNC->CONNECTED = TRUE;
+ TNC->CONNECTING = FALSE;
+
+ TNC->Alerted = TRUE;
+
+ sprintf(TNC->WEB_COMMSSTATE, "Connected to FLDIGI");
+ SetWindowText(TNC->xIDC_COMMSSTATE, TNC->WEB_COMMSSTATE);
+ }
+ else
+ {
+ sprintf(Msg, "Connect Failed for FLDigi Data socket Port %d - error code = %d\r\n", port, WSAGetLastError());
+ WritetoConsole(Msg);
+
+ closesocket(TNC->TCPSock);
+ closesocket(TNC->TCPDataSock);
+ TNC->TCPSock = 0;
+ TNC->TCPDataSock = 0;
+ TNC->CONNECTING = FALSE;
+ }
+
+ return;
+}
+
+VOID UpdateStatsLine(struct TNCINFO * TNC, struct STREAMINFO * STREAM)
+{
+ sprintf(TNC->WEB_TRAFFIC, "RX %d TX %d ACKED %d Resent %d Queued %d",
+ STREAM->BytesRXed, STREAM->BytesTXed, STREAM->BytesAcked, STREAM->BytesResent, STREAM->BytesOutstanding);
+ SetWindowText(TNC->xIDC_TRAFFIC, TNC->WEB_TRAFFIC);
+}
+
+VOID SendPacket(struct TNCINFO * TNC, UCHAR * Msg, int MsgLen)
+{
+ if (TNC->FLInfo->KISSMODE)
+ {
+ char KissMsg[1000];
+ char outbuff[1000];
+ int newlen;
+
+ if (TNC->FLInfo->RAW)
+ {
+ // KISS RAW
+
+ // Add CRC and Send
+
+ unsigned short CRC;
+ char crcstring[6];
+
+ KissMsg[0] = 7; // KISS Raw
+ KissMsg[1] = 1; // SOH
+ KissMsg[2] = '0'; // Version
+ KissMsg[3] = TNC->ARQInfo->FarStream;
+
+ Msg[MsgLen] = 0;
+
+ memcpy(&KissMsg[4], Msg, MsgLen +1 ); // Get terminating NULL
+
+ CRC = CalcCRC(KissMsg + 1, MsgLen + 3);
+
+ sprintf(crcstring, "%04X%c", CRC, 4);
+
+ strcat(KissMsg, crcstring);
+ MsgLen += 9;
+ }
+ else
+ {
+ // Normal KISS
+
+ KissMsg[0] = 0; // KISS Control
+ KissMsg[1] = TNC->ARQInfo->FarStream;
+ memcpy(&KissMsg[2], Msg, MsgLen);
+ MsgLen += 2;
+ }
+
+ newlen = KissEncode(KissMsg, outbuff, MsgLen);
+ sendto(TNC->TCPDataSock, outbuff, newlen, 0, (struct sockaddr *)&TNC->Datadestaddr, sizeof(struct sockaddr));
+
+ SendKISSCommand(TNC, "TXBUF:");
+
+ }
+ else
+ {
+ // ARQ Scoket
+
+ // Add Header, CRC and Send
+
+ unsigned short CRC;
+ char crcstring[6];
+ char outbuff[1000];
+
+ outbuff[0] = 1; // SOH
+ outbuff[1] = '0'; // Version
+ outbuff[2] = TNC->ARQInfo->FarStream;
+
+ Msg[MsgLen] = 0;
+
+ memcpy(&outbuff[3], Msg, MsgLen + 1);
+
+ CRC = CalcCRC(outbuff , MsgLen + 3);
+
+ sprintf(crcstring, "%04X%c", CRC, 4);
+
+ strcat(outbuff, crcstring);
+ MsgLen += 8;
+
+ send(TNC->TCPDataSock, outbuff, MsgLen, 0);
+ }
+}
+
+VOID ProcessFLDigiData(struct TNCINFO * TNC, UCHAR * Input, int Len, char Channel, BOOL RAW);
+
+static int ProcessReceivedData(int port)
+{
+ int bytes, used, bytesleft;
+ int i;
+ char ErrMsg[255];
+ unsigned char MessageBuff[1500];
+ unsigned char * Message = MessageBuff;
+ unsigned char * MessageBase = MessageBuff;
+
+ struct TNCINFO * TNC = TNCInfo[port];
+ struct FLINFO * FL = TNC->FLInfo;
+ struct STREAMINFO * STREAM = &TNC->Streams[0];
+
+ // If using KISS/UDP interface use recvfrom
+
+ if (FL->KISSMODE)
+ {
+ struct sockaddr_in rxaddr;
+ int addrlen = sizeof(struct sockaddr_in);
+ unsigned char * KissEnd;
+
+ bytesleft = recvfrom(TNC->TCPDataSock, Message, 1500, 0, (struct sockaddr *)&rxaddr, &addrlen);
+
+ if (bytesleft < 0)
+ {
+ int err = WSAGetLastError();
+ // if (err != 11)
+ // printf("KISS Error %d %d\n", nLength, err);
+ bytes = 0;
+ }
+
+ while (bytesleft > 0)
+ {
+ unsigned char * in;
+ unsigned char * out;
+ unsigned char c;
+
+ if (bytesleft < 3)
+ return 0;
+
+ if (Message[0] != FEND)
+ return 0; // Duff
+
+ Message = MessageBase;
+ in = out = &Message[2];
+
+ // We may have more than one KISS message in a packet
+
+ KissEnd = memchr(&Message[2], FEND, bytesleft );
+
+ if (KissEnd == 0)
+ return 0; // Duff
+
+ *(KissEnd) = 0;
+
+ used = (int)(KissEnd - Message + 1);
+
+ bytesleft -= used;
+ bytes = used;
+
+ MessageBase += used;
+
+ if (Message[1] == 6) // KISS Command
+ {
+ UCHAR * ptr = strchr(&Message[2], FEND);
+
+ if (ptr) *ptr = 0; // Null Terminate
+
+ if (bytes > 250)
+ Message[250] = 0;
+
+ FL->Responding = 5;
+
+ if (TNC->TNCOK == 0)
+ {
+ TNC->TNCOK = TRUE;
+ TNC->CONNECTED = TRUE;
+
+ sprintf(TNC->WEB_COMMSSTATE, "Connected to FLDIGI");
+ SetWindowText(TNC->xIDC_COMMSSTATE, TNC->WEB_COMMSSTATE);
+ }
+
+ // Trap BUSY fiest - there are lots of them, and they are likely to be confused
+ // with tesponses to Interactive commands
+
+ if (memcmp(&Message[2], "BUSY", 4) == 0)
+ {
+ BOOL Changed = FALSE;
+
+ if (Message[7] == 'T' && FL->Busy == FALSE)
+ {
+ TNC->Busy = FL->Busy = TRUE;
+ Changed = TRUE;
+ }
+ else
+ {
+ if (Message[7] == 'F' && FL->Busy == TRUE)
+ {
+ TNC->Busy = FL->Busy = FALSE;
+ Changed = TRUE;
+ }
+ }
+
+ if (Changed)
+ {
+ if (FL->TX)
+ strcpy(TNC->WEB_CHANSTATE, "TX");
+ else
+ if (FL->Busy)
+ strcpy(TNC->WEB_CHANSTATE, "Busy");
+ else
+ strcpy(TNC->WEB_CHANSTATE, "Idle");
+
+ SetWindowText(TNC->xIDC_CHANSTATE, TNC->WEB_CHANSTATE);
+ }
+
+ continue;
+ }
+
+ if (TNC->InternalCmd)
+ {
+ ULONG * buffptr = GetBuff();
+
+ TNC->InternalCmd = FALSE;
+
+ if (buffptr)
+ {
+ buffptr[1] = sprintf((UCHAR *)&buffptr[2], "FLDIGI} Ok %s\r", &Message[2]);
+ C_Q_ADD(&TNC->Streams[0].PACTORtoBPQ_Q, buffptr);
+ }
+
+ // Drop through in case need to extract info from command
+ }
+
+ // Auto Command
+
+// Debugprintf("%d %s", TNC->PortRecord->PORTCONTROL.PORTNUMBER, &Message[2]);
+
+ if (memcmp(&Message[2], "FLSTAT", 4) == 0)
+ {
+ if (strstr(&Message[2], "FLSTAT:INIT"))
+ {
+ // FLDIGI Reloaded - set parmas
+ SendKISSCommand(TNC, "RSIDBCAST:ON TRXSBCAST:ON TXBEBCAST:ON KISSRAW:ON");
+ }
+ continue;
+ }
+
+ if (memcmp(&Message[2], "TRXS", 4) == 0)
+ {
+ char * ptr1, * context;
+ BOOL Changed = FALSE;
+
+ ptr1 = strtok_s(&Message[7], ",", &context);
+
+ if (strstr(ptr1, "TX"))
+ {
+ if (TNC->FLInfo->TX == FALSE)
+ {
+ TNC->FLInfo->TX = TRUE;
+ Changed = TRUE;
+ }
+ }
+ else
+ {
+ if (TNC->FLInfo->TX)
+ {
+ TNC->FLInfo->TX = FALSE;
+ Changed = TRUE;
+ }
+ }
+
+ if (Changed)
+ {
+ if (FL->TX)
+ strcpy(TNC->WEB_CHANSTATE, "TX");
+ else
+ if (FL->Busy)
+ strcpy(TNC->WEB_CHANSTATE, "Busy");
+ else
+ strcpy(TNC->WEB_CHANSTATE, "Idle");
+
+ SetWindowText(TNC->xIDC_CHANSTATE, TNC->WEB_CHANSTATE);
+ }
+
+ continue;
+ }
+
+ if (memcmp(&Message[2], "TXBUF:", 6) == 0)
+ {
+ char * ptr1, * context;
+
+ ptr1 = strtok_s(&Message[8], ",", &context);
+ STREAM->BytesOutstanding = atoi(ptr1);
+ UpdateStatsLine(TNC, STREAM);
+ continue;
+ }
+
+ if (memcmp(&Message[2], "TXBE:", 5) == 0)
+ {
+ STREAM->BytesOutstanding = 0;
+ UpdateStatsLine(TNC, STREAM);
+ continue;
+ }
+
+ if (memcmp(&Message[2], "RSIDN:", 6) == 0)
+ {
+ char * ptr1, * context;
+
+ ptr1 = strtok_s(&Message[8], ",", &context);
+
+ TNC->FLInfo->CenterFreq = atoi(ptr1);
+ ptr1 = strtok_s(NULL, ",", &context);
+ if (strlen(ptr1) > 19)
+ ptr1[19] = 0;
+
+ strcpy(TNC->FLInfo->CurrentMode, ptr1);
+ }
+
+ if (memcmp(&Message[2], "MODEM:", 6) == 0)
+ {
+ char * ptr1, * context;
+
+ ptr1 = strtok_s(&Message[8], ",", &context);
+ if (strlen(ptr1) > 19)
+ ptr1[19] = 0;
+
+ strcpy(TNC->FLInfo->CurrentMode, ptr1);
+ }
+
+ if (memcmp(&Message[2], "WFF:", 4) == 0)
+ {
+ char * ptr1, * context;
+
+ ptr1 = strtok_s(&Message[6], ",", &context);
+ TNC->FLInfo->CenterFreq = atoi(ptr1);
+ }
+
+ sprintf(TNC->WEB_MODE, "%s/%d", TNC->FLInfo->CurrentMode, TNC->FLInfo->CenterFreq);
+ SetWindowText(TNC->xIDC_MODE, TNC->WEB_MODE);
+
+ continue;
+ }
+
+ if (Message[1] == 7) // Not Normal Data
+ {
+ // "RAW" Mode. Just process as if received from TCP Socket Interface
+
+ ProcessFLDigiPacket(TNC, &Message[2] , bytes - 3); // Data may be for another port
+ continue;
+ }
+
+ bytes -= 3; // Two FEND and Control
+
+ // Undo KISS
+
+ while (bytes)
+ {
+ bytes--;
+
+ c = *(in++);
+
+ if (c == FESC)
+ {
+ c = *(in++);
+ bytes--;
+
+ if (c == TFESC)
+ c = FESC;
+ else if (c == TFEND)
+ c = FEND;
+ }
+ *(out++) = c;
+ }
+ ProcessFLDigiData(TNC, &Message[3], (int)(out - &Message[3]), Message[2], FALSE); // KISS not RAW
+ }
+ return 0;
+ }
+
+ // Need to extract messages from byte stream
+
+ bytes = recv(TNC->TCPDataSock, Message, 500, 0);
+
+ if (bytes == SOCKET_ERROR)
+ {
+// i=sprintf(ErrMsg, "Read Failed for MPSK socket - error code = %d\r\n", WSAGetLastError());
+// WritetoConsole(ErrMsg);
+
+ closesocket(TNC->TCPDataSock);
+
+ TNC->CONNECTED = FALSE;
+ if (TNC->Streams[0].Attached)
+ TNC->Streams[0].ReportDISC = TRUE;
+
+ return (0);
+ }
+
+ if (bytes == 0)
+ {
+ // zero bytes means connection closed
+
+ i=sprintf(ErrMsg, "FlDigi Connection closed for BPQ Port %d\n", port);
+ WritetoConsole(ErrMsg);
+
+ TNC->CONNECTED = FALSE;
+ if (TNC->Streams[0].Attached)
+ TNC->Streams[0].ReportDISC = TRUE;
+
+ return (0);
+ }
+
+ // Have some data
+
+ ProcessFLDigiPacket(TNC, Message, bytes); // Data may be for another port
+
+ return (0);
+
+}
+
+
+VOID ProcessFLDigiPacket(struct TNCINFO * TNC, char * Message, int Len)
+{
+ char * MPTR = Message;
+ char c;
+ struct FLINFO * FL = TNC->FLInfo;
+
+
+ if (TNC->FLInfo->MCASTMODE)
+ {
+ if (TNC->Streams[0].Attached == 0)
+ return;
+
+ while(Len)
+ {
+ c = *(MPTR++);
+
+ if (TNC->InPacket)
+ {
+ TNC->DataBuffer[TNC->DataLen++] = c;
+
+ // Sanity Check
+
+ if (TNC->DataLen == 6)
+ {
+ char * ptr = &TNC->DataBuffer[1];
+
+ if (memcmp(ptr, "DATA ", 5) == 0 ||
+ memcmp(ptr, "PROG ", 5) == 0 ||
+ memcmp(ptr, "FILE ", 5) == 0 ||
+ memcmp(ptr, "SIZE ", 5) == 0 ||
+ memcmp(ptr, "DESC ", 5) == 0 ||
+ memcmp(ptr, "CNTL ", 5) == 0 ||
+ memcmp(ptr, "ID ", 3) == 0)
+
+ {
+ }
+ else
+ {
+ // False Trigger, try again
+
+ TNC->InPacket = FALSE;
+ }
+
+ }
+ else
+ {
+ if (TNC->InData)
+ {
+ if (--TNC->MCASTLen == 0)
+ {
+ // Got a packet
+
+ UINT * buffptr;
+ int Stream = 0;
+ struct STREAMINFO * STREAM = &TNC->Streams[0];
+
+ buffptr = GetBuff();
+
+ if (buffptr)
+ {
+ TNC->DataBuffer[TNC->DataLen++] = 13; // Keep Tidy
+
+ buffptr[1] = TNC->DataLen;
+ memcpy(&buffptr[2], &TNC->DataBuffer[0], TNC->DataLen);
+
+ C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr);
+ }
+
+ TNC->InPacket = FALSE;
+ }
+ }
+ else
+ {
+ // Looking for >
+
+ if (TNC->DataLen == 16)
+ {
+ // Not found it
+
+ TNC->InPacket = FALSE;
+ }
+ else
+ {
+ if (c == '>')
+ {
+ // Got Header - extract Length
+
+ char * ptr;
+ int len;
+
+ ptr = strchr(TNC->DataBuffer, ' ');
+
+ if (ptr)
+ {
+ len = atoi(ptr);
+
+ if (len)
+ {
+ TNC->InData = TRUE;
+ TNC->MCASTLen = len;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if (TNC->DataLen > 520)
+ TNC->DataLen--; // Protect Buffer
+ }
+ else
+ {
+ // Look for '<'
+
+ if (c == '<')
+ {
+ TNC->DataBuffer[0] = c;
+ TNC->DataLen = 1;
+ TNC->InPacket = TRUE;
+ TNC->InData = FALSE;
+ }
+ }
+ Len--;
+ }
+ return;
+ }
+ // Look for SOH/EOT delimiters. May Have several SOH before EOTTNC->FL
+
+ while(Len)
+ {
+ c = *(MPTR++);
+
+ switch (c)
+ {
+ case 01: // New Packet
+
+ if (TNC->InPacket)
+ CheckFLDigiData(TNC);
+
+ TNC->DataBuffer[0] = 1;
+ TNC->DataLen = 1;
+ TNC->InPacket = TRUE;
+ break;
+
+ case 04:
+
+ if (TNC->InPacket)
+ CheckFLDigiData(TNC);
+ TNC->DataLen = 0;
+ TNC->InPacket = FALSE;
+
+ break;
+
+ default:
+
+ if (TNC->InPacket)
+ {
+ if (TNC->DataLen == 1)
+ {
+ if (c != '0' && c != '1')
+ {
+ // Drop if not Protocol '0' or '1' - this should eliminate almost all noise packets
+
+ TNC->InPacket = 0;
+ break;
+ }
+ }
+ TNC->DataBuffer[TNC->DataLen++] = c;
+ }
+
+ if (TNC->DataLen > 520)
+ TNC->DataLen--; // Protect Buffer
+
+ }
+ Len--;
+ }
+}
+VOID CheckFLDigiData(struct TNCINFO * TNC)
+{
+ UCHAR * Input = &TNC->DataBuffer[0];
+ int Len = TNC->DataLen - 4; // Not including CRC
+ unsigned short CRC;
+ char crcstring[6];
+
+ if (Len < 0)
+ return;
+
+ TNC->DataBuffer[TNC->DataLen] = 0;
+
+ // RAW format message, either from ARQ Scoket or RAW KISS
+
+ // Check Checksum
+
+ CRC = CalcCRC(Input , Len);
+
+ sprintf(crcstring, "%04X", CRC);
+
+ if (memcmp(&Input[Len], crcstring, 4) !=0)
+ {
+ // CRC Error - could just be noise
+
+// Debugprintf("%s %s", crcstring, Input);
+ return;
+ }
+ ProcessFLDigiData(TNC, &Input[3], Len - 3, Input[2], TRUE); // From RAW
+}
+/*
+VOID ProcessARQPacket(struct PORTCONTROL * PORT, MESSAGE * Buffer)
+{
+ // ARQ Packet from KISS-Like Hardware
+
+ struct TNCINFO * TNC = TNCInfo[PORT->PORTNUMBER];
+ UCHAR * Input;
+ int Len;
+
+ if (TNC == NULL)
+ {
+ // Set up TNC info
+
+ TNC = TNCInfo[PORT->PORTNUMBER] = zalloc(sizeof(struct TNCINFO));
+ TNC->ARQInfo = zalloc(sizeof(struct ARQINFO));
+ TNC->FLInfo = zalloc(sizeof(struct FLINFO));
+
+ TNC->Timeout = 50; // Default retry = 10 seconds
+ TNC->Retries = 6; // Default Retries
+ TNC->Window = 16;
+ }
+
+ Input = &Buffer->DEST[0];
+ Len = Buffer->LENGTH - 7; // Not including CRC
+
+ // Look for attach on any call
+
+ ProcessFLDigiData(TNC, Input, Len);
+}
+*/
+static int Stuff(UCHAR * inbuff, UCHAR * outbuff, int len)
+{
+ int i, txptr = 0;
+ UCHAR c;
+ UCHAR * ptr = inbuff;
+
+ // DLE Escape DLE, SOH, EOT
+
+ for (i = 0; i < len; i++)
+ {
+ c = *(ptr++);
+
+// if (c == 0 || c == DLE || c == SOH || c == EOT)
+ if (c < 32 && c != 10 && c != 13 && c != 8)
+ {
+ outbuff[txptr++] = DLE;
+
+ // if between 0 and 0x1F, Add 40,
+ // if > x80 and less than 0xa0 subtract 20
+
+ c += 0x40;
+ }
+ outbuff[txptr++]=c;
+ }
+
+ return txptr;
+}
+
+
+static int UnStuff(UCHAR * inbuff, int len)
+{
+ int i, txptr = 0;
+ UCHAR c;
+ UCHAR * outbuff = inbuff;
+ UCHAR * ptr = inbuff;
+
+ // This unstuffs into the input buffer
+
+ for (i = 0; i < len; i++)
+ {
+ c = *(ptr++);
+
+ if (c == DLE)
+ {
+ c = *(ptr++);
+ i++;
+
+ // if between 0x40 and 0x5F, subtract 0x40,
+ // else add 0x20 (so we can send chars 80-9f without a double DLE)
+
+ if (c < 0x60)
+ c -= 0x40;
+ else
+ c += 0x20;
+ }
+ outbuff[txptr++] = c;
+ }
+
+ return txptr;
+}
+
+unsigned int crcval = 0xFFFF;
+
+void update(char c)
+{
+ int i;
+
+ crcval ^= c & 255;
+ for (i = 0; i < 8; ++i)
+ {
+ if (crcval & 1)
+ crcval = (crcval >> 1) ^ 0xA001;
+ else
+ crcval = (crcval >> 1);
+ }
+}
+
+unsigned int CalcCRC(UCHAR * ptr, int Len)
+{
+ int i;
+
+ crcval = 0xFFFF;
+ for (i = 0; i < Len; i++)
+ {
+ update(*ptr++);
+ }
+ return crcval;
+}
+/*
+
+<SOH>00cG8BPQ:1025 G8BPQ:24 0 8 T60R6W108E06<EOT>
+<SOH>00kG8BPQ:24 G8BPQ 4 85F9B<EOT>
+
+<SOH>00cG8BPQ:1025 GM8BPQ:24 0 7 T60R5W1051D5<EOT> (128, 5)
+
+,<SOH>00cG8BPQ:1025 G8BPQ:24 0 7 T60R5W10FA36<EOT>
+<SOH>00kG8BPQ:24 G8BPQ 5 89FCA<EOT>
+
+First no sees to be a connection counter. Next may be stream
+
+
+<SOH>08s___ABFC<EOT>
+<SOH>08tG8BPQ:73 xxx 33FA<EOT>
+<SOH>00tG8BPQ:73 yyy 99A3<EOT>
+<SOH>08dG8BPQ:90986C<EOT>
+<SOH>00bG8BPQ:911207<EOT>
+
+call:90 for dis 91 for dis ack 73<sp> for chat)
+
+<SOH>08pG8BPQ<SUB>?__645E<EOT>
+<SOH>00s_??4235<EOT>
+
+<SOH>08pG8BPQ<SUB>?__645E<EOT>
+<SOH>00s_??4235<EOT>
+
+i Ident
+c Connect
+k Connect Ack
+r Connect NAK
+d Disconnect req
+s Data Ack/ Retransmit Req )status)
+p Poll
+f Format Fail
+b dis ack
+t talk
+
+a Abort
+o Abort ACK
+
+
+<SOH>00cG8BPQ:1025 G8BPQ:24 0 7 T60R5W10FA36<EOT>
+<SOH>00kG8BPQ:24 G8BPQ 6 49A3A<EOT>
+<SOH>08s___ABFC<EOT>
+<SOH>08 ARQ:FILE::flarqmail-1.eml
+ARQ:EMAIL::
+ARQ:SIZE::90
+ARQ::STX
+//FLARQ COMPOSER
+Date: 09/01/2014 23:24:42
+To: gm8bpq
+From:
+SubjectA0E0<SOH>
+<SOH>08!: Test
+
+Test Message
+
+ARQ::ETX
+F0F2<SOH>
+<SOH>08pG8BPQ<SUB>!__623E<EOT>
+<SOH>08pG8BPQ<SUB>!__623E<EOT>
+<SOH>08pG8BPQ<SUB>!__623E<EOT>
+
+
+
+
+*/
+VOID ProcessFLDigiData(struct TNCINFO * TNC, UCHAR * Input, int Len, char Channel, BOOL RAW)
+{
+ UINT * buffptr;
+ int Stream = 0;
+ struct STREAMINFO * STREAM = &TNC->Streams[0];
+ char CTRL = Input[0];
+ struct ARQINFO * ARQ = TNC->ARQInfo;
+ struct FLINFO * FL = TNC->FLInfo;
+
+ int SendLen;
+ char Reply[80];
+
+
+ // Process Message
+
+ // This processes eitrher message from the KISS or RAW interfaces.
+ // Headers and RAW checksum have been removed, so packet starts with Control Byte
+
+ // Only a connect request is allowed with no session, so check first
+
+ if (CTRL == 'c')
+ {
+ // Connect Request
+
+ char * call1;
+ char * call2;
+ char * port1;
+ char * port2;
+ char * ptr;
+ char * context;
+ char FarStream = 0;
+ int BlockSize = 6; // 64 default
+ int Window = TNC->Window;
+ APPLCALLS * APPL;
+ char * ApplPtr = APPLS;
+ int App;
+ char Appl[10];
+ struct WL2KInfo * WL2K = TNC->WL2K;
+ TRANSPORTENTRY * SESS;
+
+ if (FL->CONOK == FALSE)
+ return;
+
+ call1 = strtok_s(&Input[1], " ", &context);
+ call2 = strtok_s(NULL, " ", &context);
+
+ port1 = strlop(call1, ':');
+ port2 = strlop(call2, ':');
+
+ // See if for us
+
+ for (App = 0; App < 32; App++)
+ {
+ APPL=&APPLCALLTABLE[App];
+ memcpy(Appl, APPL->APPLCALL_TEXT, 10);
+ ptr=strchr(Appl, ' ');
+
+ if (ptr) *ptr = 0;
+
+ if (_stricmp(call2, Appl) == 0)
+ break;
+ }
+
+ if (App > 31)
+ if (strcmp(TNC->NodeCall, call2) !=0)
+ return; // Not Appl or Port/Node Call
+
+ ptr = strtok_s(NULL, " ", &context);
+ FarStream = *ptr;
+ ptr = strtok_s(NULL, " ", &context);
+ BlockSize = atoi(ptr);
+
+ if (ARQ->ARQState)
+ {
+ // We have already received a connect request - just ACK it
+
+ goto AckConnectRequest;
+ }
+
+ // Get a Session
+
+ SuspendOtherPorts(TNC);
+
+ ProcessIncommingConnect(TNC, call1, 0, FALSE);
+
+ SESS = TNC->PortRecord->ATTACHEDSESSIONS[0];
+
+ strcpy(STREAM->MyCall, call2);
+ STREAM->ConnectTime = time(NULL);
+ STREAM->BytesRXed = STREAM->BytesTXed = STREAM->BytesAcked = STREAM->BytesResent = 0;
+
+ if (TNC->RIG && TNC->RIG != &TNC->DummyRig && strcmp(TNC->RIG->RigName, "PTT"))
+ {
+ sprintf(TNC->WEB_TNCSTATE, "%s Connected to %s Inbound Freq %s", TNC->Streams[0].RemoteCall, call2, TNC->RIG->Valchar);
+ SESS->Frequency = (atof(TNC->RIG->Valchar) * 1000000.0) + 1500; // Convert to Centre Freq
+ SESS->Mode = TNC->WL2KMode;
+ }
+ else
+ {
+ sprintf(TNC->WEB_TNCSTATE, "%s Connected to %s Inbound", TNC->Streams[0].RemoteCall, call2);
+ if (WL2K)
+ {
+ SESS->Frequency = WL2K->Freq;
+ SESS->Mode = WL2K->mode;
+ }
+ }
+
+ if (WL2K)
+ strcpy(SESS->RMSCall, WL2K->RMSCall);
+
+ SetWindowText(TNC->xIDC_TNCSTATE, TNC->WEB_TNCSTATE);
+
+ strcpy(TNC->WEB_PROTOSTATE, "Connect Pending");
+ SetWindowText(TNC->xIDC_PROTOSTATE, TNC->WEB_PROTOSTATE);
+
+ memset(ARQ, 0, sizeof(struct ARQINFO)); // Reset ARQ State
+ ARQ->FarStream = FarStream;
+ ARQ->TXSeq = ARQ->TXLastACK = 63; // Last Sent
+ ARQ->RXHighest = ARQ->RXNoGaps = 63; // Last Received
+ ARQ->ARQState = ARQ_ACTIVE;
+ ARQ->OurStream = (rand() % 78) + 49; // To give some protection against other stuff on channel
+ ARQ->FarStream = FarStream; // Not Yet defined
+ if (strcmp(port1, "1025") == 0)
+ {
+ FL->FLARQ = TRUE; // From FLARQ
+ ARQ->OurStream = '8'; // FLARQ Ignores what we send
+ }
+ else
+ FL->FLARQ = FALSE; // From other app (eg BPQ)
+
+ FL->RAW = RAW;
+
+ STREAM->NeedDisc = 0;
+
+ if (App < 32)
+ {
+ char AppName[13];
+
+ memcpy(AppName, &ApplPtr[App * sizeof(CMDX)], 12);
+ AppName[12] = 0;
+
+ // Make sure app is available
+
+ if (CheckAppl(TNC, AppName))
+ {
+ char Buffer[32];
+ int MsgLen = sprintf(Buffer, "%s\r", AppName);
+
+ buffptr = GetBuff();
+
+ if (buffptr == 0)
+ {
+ return; // No buffers, so ignore
+ }
+
+ buffptr[1] = MsgLen;
+ memcpy(buffptr+2, Buffer, MsgLen);
+
+ C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr);
+
+ TNC->SwallowSignon = TRUE;
+
+ // Save Appl Call in case needed for
+
+ }
+ else
+ {
+ STREAM->NeedDisc = 50; // 1 sec
+ }
+ }
+
+ ARQ->TXWindow = Window;
+
+ if (BlockSize < 4) BlockSize = 4;
+ if (BlockSize < 9) BlockSize = 9;
+
+ ARQ->MaxBlock = Blocksizes[BlockSize];
+
+
+ ARQ->ARQTimer = 10; // To force CTEXT to be Queued
+
+ if (App == 32)
+ {
+ // Connect to Node - send CTEXT
+
+ if (HFCTEXTLEN > 1)
+ {
+ buffptr = GetBuff();
+ if (buffptr)
+ {
+ buffptr[1] = HFCTEXTLEN;
+ memcpy(&buffptr[2], HFCTEXT, HFCTEXTLEN);
+ SendARQData(TNC, buffptr);
+ }
+ }
+ }
+
+ if (STREAM->NeedDisc)
+ {
+ // Send Not Avail
+
+ buffptr = GetBuff();
+ if (buffptr)
+ {
+ buffptr[1] = sprintf((char *)&buffptr[2], "Application Not Available\n");
+ SendARQData(TNC, buffptr);
+ }
+ }
+
+AckConnectRequest:
+
+ SendLen = sprintf(Reply, "k%s:24 %s %c 7", call2, call1, ARQ->OurStream);
+
+ SaveAndSend(TNC, ARQ, TNC->TCPDataSock, Reply, SendLen);
+ ARQ->ARQTimerState = ARQ_CONNECTACK;
+
+ return;
+ }
+
+ // All others need a session
+
+// if (!STREAM->Connected && !STREAM->Connecting)
+// return;
+
+ if (CTRL == 'k')
+ {
+ // Connect ACK
+
+ char * call1;
+ char * call2;
+ char * port1;
+ char * port2;
+ char * ptr;
+ char * context;
+ char FarStream = 0;
+ int BlockSize = 6; // 64 default
+ int Window = 16;
+
+ char Reply[80];
+ int ReplyLen;
+
+ call1 = strtok_s(&Input[1], " ", &context);
+ call2 = strtok_s(NULL, " ", &context);
+
+ port1 = strlop(call1, ':');
+ port2 = strlop(call2, ':');
+
+ if (strcmp(call1, STREAM->RemoteCall) != 0)
+ return;
+
+ if (Channel != ARQ->OurStream)
+ return; // Wrong Session
+
+ ptr = strtok_s(NULL, " ", &context);
+ if (ptr)
+ FarStream = *ptr;
+ ptr = strtok_s(NULL, " ", &context);
+ if (ptr)
+ BlockSize = atoi(ptr);
+
+ if (STREAM->Connected)
+ goto SendKReply; // Repeated ACK
+
+ STREAM->ConnectTime = time(NULL);
+ STREAM->BytesRXed = STREAM->BytesTXed = STREAM->BytesAcked = STREAM->BytesResent = 0;
+ STREAM->Connected = TRUE;
+
+ ARQ->ARQTimerState = 0;
+ ARQ->ARQTimer = 0;
+
+ if (TNC->RIG)
+ sprintf(TNC->WEB_TNCSTATE, "%s Connected to %s Outbound Freq %s", STREAM->MyCall, STREAM->RemoteCall, TNC->RIG->Valchar);
+ else
+ sprintf(TNC->WEB_TNCSTATE, "%s Connected to %s Outbound", STREAM->MyCall, STREAM->RemoteCall);
+
+ SetWindowText(TNC->xIDC_TNCSTATE, TNC->WEB_TNCSTATE);
+
+ UpdateMH(TNC, STREAM->RemoteCall, '+', 'Z');
+
+ ARQ->ARQTimerState = 0;
+ ARQ->FarStream = FarStream;
+ ARQ->TXWindow = TNC->Window;
+ ARQ->MaxBlock = Blocksizes[BlockSize];
+
+ ARQ->ARQState = ARQ_ACTIVE;
+
+ STREAM->NeedDisc = 0;
+
+ buffptr = GetBuff();
+
+ if (buffptr)
+ {
+ ReplyLen = sprintf(Reply, "*** Connected to %s\r", STREAM->RemoteCall);
+
+ buffptr[1] = ReplyLen;
+ memcpy(buffptr+2, Reply, ReplyLen);
+
+ C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr);
+ }
+
+ strcpy(TNC->WEB_PROTOSTATE, "Connected");
+ SetWindowText(TNC->xIDC_PROTOSTATE, TNC->WEB_PROTOSTATE);
+
+SendKReply:
+
+ // Reply with status
+
+ SendLen = sprintf(Reply, "s%c%c%c", ARQ->TXSeq + 32, ARQ->RXNoGaps + 32, ARQ->RXHighest + 32);
+
+ if (ARQ->RXHighest != ARQ->RXNoGaps)
+ {
+ int n = ARQ->RXNoGaps + 1;
+ n &= 63;
+
+ while (n != ARQ->RXHighest)
+ {
+ if (ARQ->RXHOLDQ[n] == 0) // Dont have it
+ SendLen += sprintf(&Reply[SendLen], "%c", n + 32);
+
+ n++;
+ n &= 63;
+ }
+ }
+
+ QueueAndSend(TNC, ARQ, TNC->TCPDataSock, Reply, SendLen);
+ return;
+ }
+
+ // All others need a session
+
+ //if (!STREAM->Connected)
+ // return;
+
+
+ if (CTRL == 's')
+ {
+ // Status
+
+ if (Channel != ARQ->OurStream)
+ return; // Wrong Session
+
+ ARQ->ARQTimer = 0; // Stop retry timer
+ Input[Len] = 0;
+ ProcessARQStatus(TNC, ARQ, &Input[1]);
+
+ return;
+ }
+
+ if (CTRL == 'p')
+ {
+ // Poll
+
+ char * call1;
+ char * context;
+
+ call1 = strtok_s(&Input[1], " \x1A", &context);
+
+ if (strcmp(call1, STREAM->RemoteCall) != 0)
+ return;
+
+ if (Channel != ARQ->OurStream)
+ return; // Wrong Session
+
+ SendLen = sprintf(Reply, "s%c%c%c", ARQ->TXSeq + 32, ARQ->RXNoGaps + 32, ARQ->RXHighest + 32);
+
+ if (ARQ->RXHighest != ARQ->RXNoGaps)
+ {
+ int n = ARQ->RXNoGaps + 1;
+ n &= 63;
+
+ while (n != ARQ->RXHighest)
+ {
+ if (ARQ->RXHOLDQ[n] == 0) // Dont have it
+ SendLen += sprintf(&Reply[SendLen], "%c", n + 32);
+
+ n++;
+ n &= 63;
+ }
+ }
+ else
+ ARQ->TurnroundTimer = 15; // Allow us to send it all acked
+
+ QueueAndSend(TNC, ARQ, TNC->TCPDataSock, Reply, SendLen);
+
+ return;
+ }
+
+
+ if (CTRL == 'a')
+ {
+ // Abort. Send Abort ACK - same as
+
+ char * call1;
+ char * context;
+
+ call1 = strtok_s(&Input[1], " :", &context);
+
+ if (strcmp(call1, STREAM->RemoteCall) != 0)
+ return;
+
+ if (Channel != ARQ->OurStream)
+ return; // Wrong Session
+
+ SendLen = sprintf(Reply, "o%c%c%c", ARQ->TXSeq + 32, ARQ->RXNoGaps + 32, ARQ->RXHighest + 32);
+
+ if (ARQ->RXHighest != ARQ->RXNoGaps)
+ {
+ int n = ARQ->RXNoGaps + 1;
+ n &= 63;
+
+ while (n != ARQ->RXHighest)
+ {
+ if (ARQ->RXHOLDQ[n] == 0) // Dont have it
+ SendLen += sprintf(&Reply[SendLen], "%c", n + 32);
+
+ n++;
+ n &= 63;
+ }
+ }
+
+ QueueAndSend(TNC, ARQ, TNC->TCPDataSock, Reply, SendLen);
+ return;
+ }
+
+ if (CTRL == 'i')
+ {
+ // Ident
+
+ return;
+ }
+
+ if (CTRL == 't')
+ {
+ // Talk - not sure what to do with these
+
+ return;
+ }
+
+ if (CTRL == 'd')
+ {
+ // Disconnect Request
+
+ char * call1;
+ char * context;
+
+ call1 = strtok_s(&Input[1], " ", &context);
+ strlop(call1, ':');
+
+ if (strcmp(STREAM->RemoteCall, call1))
+ return;
+
+ if (Channel != ARQ->OurStream)
+ return; // Wrong Session
+
+
+ // As the Disc ACK isn't repeated, we have to clear session now
+
+ STREAM->Connected = FALSE;
+ STREAM->Connecting = FALSE;
+ STREAM->ReportDISC = TRUE;
+
+ strcpy(TNC->WEB_PROTOSTATE, "Disconncted");
+ SetWindowText(TNC->xIDC_PROTOSTATE, TNC->WEB_PROTOSTATE);
+
+ ARQ->ARQState = 0;
+
+ SendLen = sprintf(Reply, "b%s:91", STREAM->MyCall);
+
+ ARQ->ARQTimerState = ARQ_WAITACK;
+ SaveAndSend(TNC, ARQ, TNC->TCPDataSock, Reply, SendLen);
+ ARQ->Retries = 2;
+ return;
+ }
+
+ if (CTRL == 'b')
+ {
+ // Disconnect ACK
+
+ char * call1;
+ char * context;
+
+ call1 = strtok_s(&Input[1], " ", &context);
+ strlop(call1, ':');
+
+ if (strcmp(STREAM->RemoteCall, call1))
+ return;
+
+ if (Channel != ARQ->OurStream)
+ return; // Wrong Session
+
+ ARQ->ARQTimer = 0;
+ ARQ->ARQTimerState = 0;
+ ARQ->ARQState = 0;
+
+ if (STREAM->Connected)
+ {
+ // Create a traffic record
+
+ char logmsg[120];
+ time_t Duration;
+
+ Duration = time(NULL) - STREAM->ConnectTime;
+
+ if (Duration == 0)
+ Duration = 1;
+
+ sprintf(logmsg,"Port %2d %9s Bytes Sent %d BPS %d Bytes Received %d BPS %d Time %d Seconds",
+ TNC->Port, STREAM->RemoteCall,
+ STREAM->BytesTXed, (int)(STREAM->BytesTXed/Duration),
+ STREAM->BytesRXed, (int)(STREAM->BytesRXed/Duration), (int)Duration);
+
+ Debugprintf(logmsg);
+ }
+
+ STREAM->Connecting = FALSE;
+ STREAM->Connected = FALSE; // Back to Command Mode
+ STREAM->ReportDISC = TRUE; // Tell Node
+
+ if (STREAM->Disconnecting) //
+ FLReleaseTNC(TNC);
+
+ STREAM->Disconnecting = FALSE;
+
+ strcpy(TNC->WEB_PROTOSTATE, "Disconncted");
+ SetWindowText(TNC->xIDC_PROTOSTATE, TNC->WEB_PROTOSTATE);
+
+ return;
+ }
+
+ if (CTRL == 'u')
+ {
+ // Beacon
+
+ //>00uGM8BPQ:72 GM8BPQ TestingAD67
+
+ char * Call = &Input[1];
+ strlop(Call, ':');
+
+ UpdateMH(TNC, Call, '!', 0);
+ return;
+ }
+
+ if (STREAM->Connected)
+ {
+ if (Channel != ARQ->OurStream)
+ return; // Wrong Session
+
+ if (CTRL >= ' ' && CTRL < 96)
+ {
+ // ARQ Data
+
+ int Seq = CTRL - 32;
+ int Work;
+
+// if (rand() % 5 == 2)
+// {
+// Debugprintf("Dropping %d", Seq);
+// return;
+// }
+
+ buffptr = GetBuff();
+
+ if (buffptr == NULL)
+ return; // Sould never run out, but cant do much else
+
+ // Remove any DLE transparency
+
+ if (TNC->FLInfo->KISSMODE)
+ Len -= 1;
+ else
+ Len = UnStuff(&Input[1], Len - 1);
+
+ buffptr[1] = Len;
+ memcpy(&buffptr[2], &Input[1], Len);
+ STREAM->BytesRXed += Len;
+
+ UpdateStatsLine(TNC, STREAM);
+
+ // Safest always to save, then see what we can process
+
+ if (ARQ->RXHOLDQ[Seq])
+ {
+ // Wot! Shouldn't happen
+
+ ReleaseBuffer(ARQ->RXHOLDQ[Seq]);
+// Debugprintf("ARQ Seq %d Duplicate");
+ }
+
+ ARQ->RXHOLDQ[Seq] = buffptr;
+// Debugprintf("ARQ saving %d", Seq);
+
+ // If this is higher that highest received, save. But beware of wrap'
+
+ // Hi = 2, Seq = 60 dont save s=h = 58
+ // Hi = 10 Seq = 12 save s-h = 2
+ // Hi = 14 Seq = 10 dont save s-h = -4
+ // Hi = 60 Seq = 2 save s-h = -58
+
+ Work = Seq - ARQ->RXHighest;
+
+ if ((Work > 0 && Work < 32) || Work < -32)
+ ARQ->RXHighest = Seq;
+
+ // We may now be able to process some
+
+ Work = (ARQ->RXNoGaps + 1) & 63; // The next one we need
+
+ while (ARQ->RXHOLDQ[Work])
+ {
+ // We have it
+
+ C_Q_ADD(&STREAM->PACTORtoBPQ_Q, ARQ->RXHOLDQ[Work]);
+// ReleaseBuffer(ARQ->RXHOLDQ[Work]);
+
+ ARQ->RXHOLDQ[Work] = NULL;
+// Debugprintf("Processing %d from Q", Work);
+
+ ARQ->RXNoGaps = Work;
+ Work = (Work + 1) & 63; // The next one we need
+ }
+
+ ARQ->TurnroundTimer = 200; // Delay before allowing reply. Will normally be reset by the poll following data
+ return;
+ }
+ }
+}
+
+
+VOID SendARQData(struct TNCINFO * TNC, UINT * Buffer)
+{
+ // Send Data, saving a copy until acked.
+
+ struct ARQINFO * ARQ = TNC->ARQInfo;
+ struct FLINFO * FL = TNC->FLInfo;
+ struct STREAMINFO * STREAM = &TNC->Streams[0];
+
+
+ UCHAR TXBuffer[300];
+ SOCKET sock = TNC->TCPDataSock;
+ int SendLen;
+ UCHAR * ptr;
+ int Origlen = Buffer[1];
+ int Stuffedlen;
+
+ ARQ->TXSeq++;
+ ARQ->TXSeq &= 63;
+
+ SendLen = sprintf(TXBuffer, "%c", ARQ->TXSeq + 32);
+
+ ptr = (UCHAR *)&Buffer[2]; // Start of data;
+
+ ptr[Buffer[1]] = 0;
+
+ if (memcmp(ptr, "ARQ:", 4) == 0)
+ {
+ // FLARQ Mail/FIle transfer. Turn off CR > LF translate (used for terminal mode)
+
+ FL->FLARQ = FALSE;
+ }
+
+ if (FL->FLARQ)
+ {
+ // Terminal Mode. Need to convert CR to LF so it displays in FLARQ Window
+
+ ptr = strchr(ptr, 13);
+
+ while (ptr)
+ {
+ *(ptr++) = 10; // Replace CR with LF
+ ptr = strchr(ptr, 13);
+ }
+ }
+
+ if (TNC->FLInfo->KISSMODE)
+ {
+ memcpy(&TXBuffer[SendLen], (UCHAR *)&Buffer[2], Origlen);
+ SendLen += Origlen;
+ }
+ else
+ {
+ Stuffedlen = Stuff((UCHAR *)&Buffer[2], &TXBuffer[SendLen], Origlen);
+ SendLen += Stuffedlen;
+ }
+
+ TXBuffer[SendLen] = 0;
+
+// if (rand() % 5 == 2)
+// Debugprintf("Dropping %d", ARQ->TXSeq);
+// else
+
+ ARQ->TXHOLDQ[ARQ->TXSeq] = Buffer;
+
+ STREAM->BytesTXed += Origlen;
+
+ UpdateStatsLine(TNC, STREAM);
+
+ // if waiting for ack, don't send, just queue. Will be sent when ack received
+
+ if (ARQ->ARQTimer == 0 || ARQ->ARQTimerState == ARQ_WAITDATA)
+ {
+ SendPacket(TNC, TXBuffer, SendLen);
+ ARQ->ARQTimer = 15; // wait up to 1.5 sec for more data before polling
+ ARQ->Retries = 1;
+ ARQ->ARQTimerState = ARQ_WAITDATA;
+ }
+ else
+ STREAM->BytesResent -= Origlen; // So wont be included in resent bytes
+}
+
+VOID TidyClose(struct TNCINFO * TNC, int Stream)
+{
+ char Reply[80];
+ int SendLen;
+
+ struct ARQINFO * ARQ = TNC->ARQInfo;
+
+ SendLen = sprintf(Reply, "d%s:90", TNC->Streams[0].MyCall);
+
+ SaveAndSend(TNC, ARQ, TNC->TCPDataSock, Reply, SendLen);
+ ARQ->ARQTimerState = ARQ_DISC;
+
+ strcpy(TNC->WEB_PROTOSTATE, "Disconncting");
+ SetWindowText(TNC->xIDC_PROTOSTATE, TNC->WEB_PROTOSTATE);
+}
+
+VOID ForcedClose(struct TNCINFO * TNC, int Stream)
+{
+ TidyClose(TNC, Stream); // I don't think Hostmode has a DD
+}
+
+VOID CloseComplete(struct TNCINFO * TNC, int Stream)
+{
+ FLReleaseTNC(TNC);
+}
+
+VOID FLReleaseTNC(struct TNCINFO * TNC)
+{
+ // Set mycall back to Node or Port Call, and Start Scanner
+
+ UCHAR TXMsg[1000];
+
+ strcpy(TNC->WEB_TNCSTATE, "Free");
+ SetWindowText(TNC->xIDC_TNCSTATE, TNC->WEB_TNCSTATE);
+
+ // if a default Modem is defined, select it
+
+ if (TNC->FLInfo->DefaultMode[0])
+ {
+ char txbuff[80];
+
+ if (TNC->FLInfo->KISSMODE)
+ {
+ sprintf(txbuff, "WFF:%d MODEM:%s MODEM: WFF:", TNC->FLInfo->DefaultFreq, TNC->FLInfo->DefaultMode);
+ SendKISSCommand(TNC, txbuff);
+ }
+ else
+ {
+ SendXMLCommand(TNC, "modem.set_by_name", TNC->FLInfo->DefaultMode, 'S');
+ SendXMLCommand(TNC, "modem.set_carrier", (char *)TNC->FLInfo->DefaultFreq, 'I');
+ }
+ }
+ // Start Scanner
+
+ sprintf(TXMsg, "%d SCANSTART 15", TNC->Port);
+
+ Rig_Command(-1, TXMsg);
+
+ ReleaseOtherPorts(TNC);
+
+}
+VOID QueueAndSend(struct TNCINFO * TNC, struct ARQINFO * ARQ, SOCKET sock, char * Msg, int MsgLen)
+{
+ // Queue to be sent after TXDELAY
+
+ memcpy(ARQ->TXMsg, Msg, MsgLen + 1);
+ ARQ->TXLen = MsgLen;
+ ARQ->TXDelay = 15; // Try 1500 ms
+}
+
+VOID SaveAndSend(struct TNCINFO * TNC, struct ARQINFO * ARQ, SOCKET sock, char * Msg, int MsgLen)
+{
+ // Used for Messages that need a reply. Save, send and set timeout
+
+ memcpy(ARQ->LastMsg, Msg, MsgLen + 1); // Include Null
+ ARQ->LastLen = MsgLen;
+
+ // Delay the send for a short while Just use the timeout code
+
+// SendPacket(sock, Msg, MsgLen, 0);
+ ARQ->ARQTimer = 1; // Try 500 ms
+ ARQ->Retries = TNC->Retries + 1; // First timout is rthe real send
+
+ return;
+}
+
+
+VOID ARQTimer(struct TNCINFO * TNC)
+{
+ struct ARQINFO * ARQ = TNC->ARQInfo;
+ UINT * buffptr;
+ struct STREAMINFO * STREAM = &TNC->Streams[0];
+ int SendLen;
+ char Reply[80];
+ struct FLINFO * FL = TNC->FLInfo;
+
+ //Send frames, unless held by TurnroundTimer or Window
+
+ int Outstanding;
+
+ // Use new BUSY: poll to detect busy state
+
+ if (FL->TX == FALSE)
+ if (TNC->FLInfo->KISSMODE)
+ SendKISSCommand(TNC, "BUSY:"); // Send every poll for now - may need to optimize later
+
+
+/*
+// Use Received chars as a rough channel active indicator
+
+ FL->BusyTimer++;
+
+ if (FL->BusyTimer > 4)
+ {
+ FL->BusyTimer = 0;
+
+ if (FL->BusyCounter > 2) // 2 chars in last .3 secs
+ FL->Busy = TRUE;
+ else
+ FL->Busy = FALSE;
+
+ if (FL->TX)
+ strcpy(TNC->WEB_CHANSTATE, "TX");
+ else
+ if (FL->Busy)
+ strcpy(TNC->WEB_CHANSTATE, "Busy");
+ else
+ strcpy(TNC->WEB_CHANSTATE, "Idle");
+
+ FL->BusyCounter = 0;
+
+ SetWindowText(TNC->xIDC_CHANSTATE, TNC->WEB_CHANSTATE);
+ }
+
+*/ // TXDelay is used as a turn round delay for frames that don't have to be retried. It doesn't
+ // need to check for busy (or anything else (I think!)
+
+ if (ARQ->TXDelay)
+ {
+ ARQ->TXDelay--;
+
+ if (ARQ->TXDelay)
+ return;
+
+ SendPacket(TNC, ARQ->TXMsg, ARQ->TXLen);
+ }
+
+ // if We are alredy sending (State = ARQ_WAITDATA) we should allow it to send more (and the Poll at end)
+
+ if (ARQ->ARQTimerState == ARQ_WAITDATA)
+ {
+ while (STREAM->BPQtoPACTOR_Q)
+ {
+ Outstanding = ARQ->TXSeq - ARQ->TXLastACK;
+
+ if (Outstanding < 0)
+ Outstanding += 64;
+
+ TNC->PortRecord->FramesQueued = Outstanding + C_Q_COUNT(&STREAM->BPQtoPACTOR_Q); // Save for Appl Level Queued Frames
+
+ if (Outstanding > ARQ->TXWindow)
+ break;
+
+ buffptr = Q_REM(&STREAM->BPQtoPACTOR_Q);
+ SendARQData(TNC, buffptr);
+ }
+
+ ARQ->ARQTimer--;
+
+ if (ARQ->ARQTimer > 0)
+ return; // Timer Still Running
+
+ // No more data available - send poll
+
+ SendLen = sprintf(Reply, "p%s", TNC->Streams[0].MyCall);
+
+ ARQ->ARQTimerState = ARQ_WAITACK;
+
+ // This is one message that should not be queued so it is sent straiget after data
+
+// Debugprintf("Sending Poll");
+
+ memcpy(ARQ->LastMsg, Reply, SendLen + 1);
+ ARQ->LastLen = SendLen;
+
+ SendPacket(TNC, Reply, SendLen);
+
+ ARQ->ARQTimer = TNC->Timeout;
+ ARQ->Retries = TNC->Retries;
+
+ strcpy(TNC->WEB_PROTOSTATE, "Wait ACK");
+ SetWindowText(TNC->xIDC_PROTOSTATE, TNC->WEB_PROTOSTATE);
+
+ return;
+
+ }
+
+ // TrunroundTimer is used to allow time for far end to revert to RX
+
+ if (ARQ->TurnroundTimer && !FL->Busy)
+ ARQ->TurnroundTimer--;
+
+ if (ARQ->TurnroundTimer == 0)
+ {
+ while (STREAM->BPQtoPACTOR_Q)
+ {
+ Outstanding = ARQ->TXSeq - ARQ->TXLastACK;
+
+ if (Outstanding < 0)
+ Outstanding += 64;
+
+ TNC->PortRecord->FramesQueued = Outstanding + C_Q_COUNT(&STREAM->BPQtoPACTOR_Q) + 1; // Make sure busy is reported to BBS
+
+ if (Outstanding > ARQ->TXWindow)
+ break;
+
+ buffptr = Q_REM(&STREAM->BPQtoPACTOR_Q);
+ SendARQData(TNC, buffptr);
+ }
+ }
+
+ if (ARQ->ARQTimer)
+ {
+ if (FL->TX || FL->Busy)
+ {
+ // Only decrement if running send poll timer
+
+ if (ARQ->ARQTimerState != ARQ_WAITDATA)
+ return;
+ }
+
+ ARQ->ARQTimer--;
+ {
+ if (ARQ->ARQTimer)
+ return; // Timer Still Running
+ }
+
+ ARQ->Retries--;
+
+ if (ARQ->Retries)
+ {
+ // Retry Current Message
+
+ SendPacket(TNC, ARQ->LastMsg, ARQ->LastLen);
+ ARQ->ARQTimer = TNC->Timeout + (rand() % 30);
+
+ return;
+ }
+
+ // Retried out.
+
+ switch (ARQ->ARQTimerState)
+ {
+ case ARQ_WAITDATA:
+
+ // No more data available - send poll
+
+ SendLen = sprintf(Reply, "p%s", TNC->Streams[0].MyCall);
+
+ ARQ->ARQTimerState = ARQ_WAITACK;
+
+ // This is one message that should not be queued so it is sent straiget after data
+
+ memcpy(ARQ->LastMsg, Reply, SendLen + 1);
+ ARQ->LastLen = SendLen;
+
+ SendPacket(TNC, Reply, SendLen);
+
+ ARQ->ARQTimer = TNC->Timeout;
+ ARQ->Retries = TNC->Retries;
+
+ strcpy(TNC->WEB_PROTOSTATE, "Wait ACK");
+ SetWindowText(TNC->xIDC_PROTOSTATE, TNC->WEB_PROTOSTATE);
+
+ return;
+
+ case ARQ_CONNECTING:
+
+ // Report Connect Failed, and drop back to command mode
+
+ buffptr = GetBuff();
+
+ if (buffptr)
+ {
+ buffptr[1] = sprintf((UCHAR *)&buffptr[2], "FLDigi} Failure with %s\r", STREAM->RemoteCall);
+ C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr);
+ }
+
+ // Send Disc to TNC in case it got the Connects, but we missed the ACKs
+
+ TidyClose(TNC, 0);
+ ARQ->Retries = 2; // First timout is the real send, only send once
+ STREAM->Connecting = FALSE; // Back to Command Mode
+ ARQ->ARQState = FALSE;
+
+ break;
+
+ case ARQ_WAITACK:
+ case ARQ_CONNECTACK:
+ case ARQ_DISC:
+
+ STREAM->Connected = FALSE; // Back to Command Mode
+ STREAM->ReportDISC = TRUE;
+ ARQ->ARQState = FALSE;
+
+ while (STREAM->PACTORtoBPQ_Q)
+ ReleaseBuffer(Q_REM(&STREAM->PACTORtoBPQ_Q));
+
+ while (STREAM->BPQtoPACTOR_Q)
+ ReleaseBuffer(Q_REM(&STREAM->BPQtoPACTOR_Q));
+
+ strcpy(TNC->WEB_TNCSTATE, "Free");
+ SetWindowText(TNC->xIDC_TNCSTATE, TNC->WEB_TNCSTATE);
+
+ strcpy(TNC->WEB_PROTOSTATE, "Disconncted");
+ SetWindowText(TNC->xIDC_PROTOSTATE, TNC->WEB_PROTOSTATE);
+
+ break;
+
+ }
+ }
+}
+
+VOID ProcessARQStatus(struct TNCINFO * TNC, struct ARQINFO * ARQ, char * Input)
+{
+ // Release any acked frames and resend any outstanding
+
+ int LastInSeq = Input[1] - 32;
+ int LastRXed = Input[2] - 32;
+ int FirstUnAcked = ARQ->TXLastACK;
+ int n = (int)strlen(Input) - 3;
+ char * ptr;
+ int NexttoResend;
+ int First, Last, Outstanding;
+ UINT * Buffer;
+ struct STREAMINFO * STREAM = &TNC->Streams[0];
+ int Acked = 0;
+
+ // First status is an ack of Connect ACK
+
+ if (ARQ->ARQTimerState == ARQ_CONNECTACK)
+ {
+ ARQ->Retries = 0;
+ ARQ->ARQTimer = 0;
+ ARQ->ARQTimerState = 0;
+
+ strcpy(TNC->WEB_PROTOSTATE, "Connected");
+ SetWindowText(TNC->xIDC_PROTOSTATE, TNC->WEB_PROTOSTATE);
+ }
+
+ // Release all up to LastInSeq
+
+ while (FirstUnAcked != LastInSeq)
+ {
+ FirstUnAcked++;
+ FirstUnAcked &= 63;
+
+ Buffer = ARQ->TXHOLDQ[FirstUnAcked];
+
+ if (Buffer)
+ {
+// Debugprintf("Acked %d", FirstUnAcked);
+ STREAM->BytesAcked += Buffer[1];
+ ReleaseBuffer(Buffer);
+ ARQ->TXHOLDQ[FirstUnAcked] = NULL;
+ Acked++;
+ }
+ }
+
+ ARQ->TXLastACK = FirstUnAcked;
+
+ Outstanding = ARQ->TXSeq - ARQ->TXLastACK;
+
+ if (Outstanding < 0)
+ Outstanding += 64;
+
+ TNC->PortRecord->FramesQueued = Outstanding + C_Q_COUNT(&STREAM->BPQtoPACTOR_Q); // Save for Appl Level Queued Frames
+
+ if (FirstUnAcked == ARQ->TXSeq)
+ {
+ UpdateStatsLine(TNC, STREAM);
+ ARQ->NoAckRetries = 0;
+
+ strcpy(TNC->WEB_PROTOSTATE, "Connected");
+ SetWindowText(TNC->xIDC_PROTOSTATE, TNC->WEB_PROTOSTATE);
+
+ return; // All Acked
+ }
+ // Release any not in retry list up to LastRXed.
+
+ ptr = &Input[3];
+
+ while (n)
+ {
+ NexttoResend = *(ptr++) - 32;
+
+ FirstUnAcked++;
+ FirstUnAcked &= 63;
+
+ while (FirstUnAcked != NexttoResend)
+ {
+ Buffer = ARQ->TXHOLDQ[FirstUnAcked];
+
+ if (Buffer)
+ {
+// Debugprintf("Acked %d", FirstUnAcked);
+ STREAM->BytesAcked += Buffer[1];
+ ReleaseBuffer(Buffer);
+ ARQ->TXHOLDQ[FirstUnAcked] = NULL;
+ Acked++;
+ }
+
+ FirstUnAcked++;
+ FirstUnAcked &= 63;
+ }
+
+ // We don't ACK this one. Process any more resend values, then release up to LastRXed.
+
+ n--;
+ }
+
+ // Release rest up to LastRXed
+
+ while (FirstUnAcked != LastRXed)
+ {
+ FirstUnAcked++;
+ FirstUnAcked &= 63;
+
+ Buffer = ARQ->TXHOLDQ[FirstUnAcked];
+
+ if (Buffer)
+ {
+// Debugprintf("Acked %d", FirstUnAcked);
+ STREAM->BytesAcked += Buffer[1];
+ ReleaseBuffer(Buffer);
+ ARQ->TXHOLDQ[FirstUnAcked] = NULL;
+ Acked++;
+ }
+ }
+
+ // Resend anything in TX Buffer (From LastACK to TXSeq
+
+ Last = ARQ->TXSeq + 1;
+ Last &= 63;
+
+ First = LastInSeq;
+
+ while (First != Last)
+ {
+ First++;
+ First &= 63;
+
+ if(ARQ->TXHOLDQ[First])
+ {
+ UINT * Buffer = ARQ->TXHOLDQ[First];
+ UCHAR TXBuffer[300];
+ SOCKET sock = TNC->TCPDataSock;
+ int SendLen;
+
+// Debugprintf("Resend %d", First);
+
+ STREAM->BytesResent += Buffer[1];
+
+ SendLen = sprintf(TXBuffer, "%c", First + 32);
+
+ if (TNC->FLInfo->KISSMODE)
+ {
+ memcpy(&TXBuffer[SendLen], (UCHAR *)&Buffer[2], Buffer[1]);
+ SendLen += Buffer[1];
+ }
+ else
+ SendLen += Stuff((UCHAR *)&Buffer[2], &TXBuffer[SendLen], Buffer[1]);
+
+ TXBuffer[SendLen] = 0;
+
+ SendPacket(TNC, TXBuffer, SendLen);
+
+ ARQ->ARQTimer = 10; // wait up to 1 sec for more data before polling
+ ARQ->Retries = 1;
+ ARQ->ARQTimerState = ARQ_WAITDATA;
+
+ if (Acked == 0)
+ {
+ // Nothing acked by this statis message
+
+ Acked = 0; // Dont count more thna once
+ ARQ->NoAckRetries++;
+ if (ARQ->NoAckRetries > TNC->Retries)
+ {
+ // Too many retries - just disconnect
+
+ TidyClose(TNC, 0);
+ return;
+ }
+ }
+ }
+ }
+
+ UpdateStatsLine(TNC, STREAM);
+}
+
+VOID FLSlowTimer(struct TNCINFO * TNC)
+{
+ struct FLINFO * FL = TNC->FLInfo;
+
+ // Entered every 10 secs
+
+ // if in MCAST mode, clear KILL timer (MCAST RX can run for a long time
+
+ if (TNC->FLInfo->MCASTMODE)
+ {
+ TRANSPORTENTRY * SESS = TNC->PortRecord->ATTACHEDSESSIONS[0];
+
+ if (SESS)
+ SESS->L4KILLTIMER = 0;
+ }
+
+ if (FL->KISSMODE)
+ {
+ if (FL->Responding)
+ FL->Responding--;
+
+ if (FL->Responding == 0)
+ {
+ TNC->TNCOK = FALSE;
+ TNC->CONNECTED = FALSE;
+
+ sprintf(TNC->WEB_COMMSSTATE, "Connection to FLDIGI lost");
+ SetWindowText(TNC->xIDC_COMMSSTATE, TNC->WEB_COMMSSTATE);
+
+ // Set basic params till it responds
+ }
+
+ FL->CmdControl++;
+
+ if (FL->CmdControl > 5) // Every Minute
+ {
+ FL->CmdControl = 0;
+
+ SendKISSCommand(TNC, "FLSTAT: MODEM: WFF:");
+ }
+
+ SendKISSCommand(TNC, "TRXS: TXBUF:"); // In case TX/RX report is missed
+ }
+}
+
+static int ProcessXMLData(int port)
+{
+ unsigned int bytes;
+ int i;
+ char ErrMsg[255];
+ char Message[500];
+ struct TNCINFO * TNC = TNCInfo[port];
+ struct FLINFO * FL = TNC->FLInfo;
+ char * ptr1, * ptr2, *ptr3;
+
+ // Need to extract messages from byte stream
+
+ bytes = recv(TNC->TCPSock,(char *)&Message, 500, 0);
+
+ if (bytes == SOCKET_ERROR)
+ {
+// i=sprintf(ErrMsg, "Read Failed for FLDigi socket - error code = %d\r\n", WSAGetLastError());
+// WritetoConsole(ErrMsg);
+
+ closesocket(TNC->TCPSock);
+
+ TNC->CONNECTED = FALSE;
+ if (TNC->Streams[0].Attached)
+ TNC->Streams[0].ReportDISC = TRUE;
+
+ return (0);
+ }
+
+ if (bytes == 0)
+ {
+ // zero bytes means connection closed
+
+ i=sprintf(ErrMsg, "FlDigi Connection closed for BPQ Port %d\n", port);
+ WritetoConsole(ErrMsg);
+
+ TNC->CONNECTED = FALSE;
+ if (TNC->Streams[0].Attached)
+ TNC->Streams[0].ReportDISC = TRUE;
+
+ return (0);
+ }
+
+ // Have some data. Assume for now we get a whole packet
+
+ if (TNC->InternalCmd)
+ {
+ ULONG * buffptr = GetBuff();
+
+ TNC->InternalCmd = FALSE;
+
+ ptr1 = strstr(Message, "<value>");
+
+ if (ptr1)
+ {
+ ptr1 += 7;
+ ptr2 = strstr(ptr1, "</value>");
+ if (ptr2) *ptr2 = 0;
+
+ ptr3 = strstr(ptr1, "<i4>");
+
+ if (ptr3)
+ {
+ ptr1 = ptr3 + 4;
+ ptr2 = strstr(ptr1, "</i4>");
+ if (ptr2) *ptr2 = 0;
+ }
+
+ if (buffptr)
+ {
+ buffptr[1] = sprintf((UCHAR *)&buffptr[2], "FLDIGI} Ok Was %s\r", ptr1);
+ C_Q_ADD(&TNC->Streams[0].PACTORtoBPQ_Q, buffptr);
+ }
+ }
+
+ return 0;
+ }
+
+
+ ptr1 = strstr(Message, "<value>");
+
+ if (ptr1)
+ {
+ ptr1 += 7;
+ ptr2 = strstr(ptr1, "</value>");
+ if (ptr2) *ptr2 = 0;
+
+ ptr2 = strstr(ptr1, "<string>");
+
+ if (ptr2)
+ {
+ ptr2 += 8;
+ ptr1 = ptr2;
+ ptr2 = strstr(ptr1, "</string>");
+ if (ptr2) *ptr2 = 0;
+ }
+
+ if (strcmp(FL->LastXML, "modem.get_name") == 0)
+ {
+ strcpy(TNC->WEB_MODE, ptr1);
+ SetWindowText(TNC->xIDC_MODE, ptr1);
+ }
+ else if (strcmp(FL->LastXML, "main.get_trx_state") == 0)
+ {
+ if (strcmp(ptr1, "TX") == 0)
+ FL->TX = TRUE;
+ else
+ FL->TX = FALSE;
+
+
+ if (FL->TX)
+ strcpy(TNC->WEB_CHANSTATE, "TX");
+ else
+ if (FL->Busy)
+ strcpy(TNC->WEB_CHANSTATE, "Busy");
+ else
+ strcpy(TNC->WEB_CHANSTATE, "Idle");
+
+ SetWindowText(TNC->xIDC_CHANSTATE, TNC->WEB_CHANSTATE);
+ }
+ else if (strcmp(FL->LastXML, "main.get_squelch") == 0)
+ {
+/*
+ if (_memicmp(Buffer, "BUSY TRUE", 9) == 0)
+ {
+ TNC->BusyFlags |= CDBusy;
+ TNC->Busy = TNC->BusyHold * 10; // BusyHold delay
+
+ SetWindowText(TNC->xIDC_CHANSTATE, "Busy");
+ strcpy(TNC->WEB_CHANSTATE, "Busy");
+
+ TNC->WinmorRestartCodecTimer = time(NULL);
+*/
+ return 0;
+ }
+/*
+ if (_memicmp(Buffer, "BUSY FALSE", 10) == 0)
+ {
+ TNC->BusyFlags &= ~CDBusy;
+ if (TNC->BusyHold)
+ strcpy(TNC->WEB_CHANSTATE, "BusyHold");
+ else
+ strcpy(TNC->WEB_CHANSTATE, "Clear");
+
+ SetWindowText(TNC->xIDC_CHANSTATE, TNC->WEB_CHANSTATE);
+ TNC->WinmorRestartCodecTimer = time(NULL);
+ return;
+ }
+*/
+
+ }
+
+ return (0);
+
+}
+
+
+
+char MsgHddr[] = "POST /RPC2 HTTP/1.1\r\n"
+ "User-Agent: XMLRPC++ 0.8\r\n"
+ "Host: 127.0.0.1:7362\r\n"
+ "Content-Type: text/xml\r\n"
+ "Content-length: %d\r\n"
+ "\r\n%s";
+
+char Req[] = "<?xml version=\"1.0\"?>\r\n"
+ "<methodCall><methodName>%s</methodName>\r\n"
+ "%s"
+ "</methodCall>\r\n";
+
+
+VOID SendXMLCommand(struct TNCINFO * TNC, char * Command, char * Value, char ParamType)
+{
+ int Len;
+ char ReqBuf[512];
+ char SendBuff[512];
+ struct FLINFO * FL = TNC->FLInfo;
+ struct ARQINFO * ARQ = TNC->ARQInfo;
+ char ValueString[256] ="";
+
+ if (!TNC->CONNECTED || TNC->FLInfo->KISSMODE)
+ return;
+
+ if (Value)
+ if (ParamType == 'S')
+ sprintf(ValueString, "<params><param><value><string>%s</string></value></param></params\r\n>", Value);
+ else
+ sprintf(ValueString, "<params><param><value><i4>%d</i4></value></param></params\r\n>", Value);
+
+ strcpy(FL->LastXML, Command);
+ Len = sprintf(ReqBuf, Req, FL->LastXML, ValueString);
+ Len = sprintf(SendBuff, MsgHddr, Len, ReqBuf);
+ send(TNC->TCPSock, SendBuff, Len, 0);
+ return;
+}
+
+VOID SendXMLPoll(struct TNCINFO * TNC)
+{
+ int Len;
+ char ReqBuf[256];
+ char SendBuff[256];
+ struct FLINFO * FL = TNC->FLInfo;
+ struct ARQINFO * ARQ = TNC->ARQInfo;
+
+ if (!TNC->CONNECTED)
+ return;
+
+ if (TNC->FLInfo->KISSMODE)
+ return;
+
+ if (ARQ->ARQTimer)
+ {
+ // if timer is running, poll fot TX State
+
+ strcpy(FL->LastXML, "main.get_trx_state");
+ Len = sprintf(ReqBuf, Req, FL->LastXML, "");
+ Len = sprintf(SendBuff, MsgHddr, Len, ReqBuf);
+ send(TNC->TCPSock, SendBuff, Len, 0);
+ return;
+ }
+
+ FL->XMLControl++;
+
+
+ if (FL->XMLControl > 9)
+ {
+ FL->XMLControl = 0;
+ strcpy(FL->LastXML, "modem.get_name");
+ }
+ else
+ {
+ if (FL->XMLControl == 5)
+ strcpy(FL->LastXML, "main.get_trx_state");
+ else
+ return;
+ }
+
+ Len = sprintf(ReqBuf, Req, FL->LastXML, "");
+ Len = sprintf(SendBuff, MsgHddr, Len, ReqBuf);
+ send(TNC->TCPSock, SendBuff, Len, 0);
+}
+
+// sudo add-apt-repository ppa:kamalmostafa/fldigi
+
+
diff --git a/HALDriver64.c b/HALDriver64.c index 3e3d08b..7c60f9f 100644 --- a/HALDriver64.c +++ b/HALDriver64.c @@ -1,1907 +1,1907 @@ -/* -Copyright 2001-2018 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 -*/ - -// -// DLL to inteface HAL Communications Corp Clover/Pacor controllers to BPQ32 switch -// -// Uses BPQ EXTERNAL interface -// - -#define _CRT_SECURE_NO_WARNINGS -#define _CRT_SECURE_NO_DEPRECATE - -#include "time.h" - -#include "CHeaders.h" -#include "tncinfo.h" - -#include "bpq32.h" - -#define HAL 1 - -#define SetMYCALL 0x13 -#define ConnectEnable 0x52 -#define ConnectDisable 0x42 -#define SetEAS 0x59 // Echo as Sent -#define SetTones 0xec -#define ClearOnDisc 0x57 - -static char ClassName[]="HALSTATUS"; - -static char WindowTitle[] = "HAL"; -static int RigControlRow = 185; - -struct TNCINFO * TNCInfo[34]; // Records are Malloc'd - -#define SOH 0x01 // CONTROL CODES -#define ETB 0x17 -#define DLE 0x10 - -//int MaxStreams = 0; - -#ifndef LINBPQ -extern HFONT hFont; -#endif - -static char status[23][50] = {"IDLE", "TFC", "RQ", "ERR", "PHS", "OVER", "FSK TX", - "FSK RX", "P-MODE100", "P-MODE200", "HUFMAN ON", "HUFMAN OFF", "P-MODE SBY(LISTEN ON)", - "P-MODE SBY(LISTEN OFF)", "ISS", "IRS", - "AMTOR SBY(LISTEN ON)", "AMTOR SBY(LISTEN OFF)", "AMTOR FEC TX", "AMTOR FEC RX", "P-MODE FEC TX", - "FREE SIGNAL TX (AMTOR)", "FREE SIGNAL TX TIMED OUT (AMTOR)"}; - -struct TNCINFO * CreateTTYInfo(int port, int speed); -BOOL OpenConnection(int); -BOOL SetupConnection(int); -static BOOL WriteCommBlock(struct TNCINFO * TNC); -static void CheckRX(struct TNCINFO * TNC); -VOID HALPoll(int Port); -VOID ProcessDEDFrame(struct TNCINFO * TNC, UCHAR * rxbuff, int len); -VOID ProcessTermModeResponse(struct TNCINFO * TNC); -static VOID DoTNCReinit(struct TNCINFO * TNC); -VOID DoTermModeTimeout(struct TNCINFO * TNC); -VOID ProcessHALBuffer(struct TNCINFO * TNC, int Length); -VOID ProcessHALCmd(struct TNCINFO * TNC); -VOID ProcessHALData(struct TNCINFO * TNC); -VOID ProcessKHOSTPacket(struct TNCINFO * TNC, UCHAR * rxbuffer, int Len); -VOID ProcessKNormCommand(struct TNCINFO * TNC, UCHAR * rxbuffer); -VOID ProcessHostFrame(struct TNCINFO * TNC, UCHAR * rxbuffer, int Len); -VOID DoMonitor(struct TNCINFO * TNC, UCHAR * Msg, int Len); - -BOOL HALConnected(struct TNCINFO * TNC, char * Call); -VOID HALDisconnected(struct TNCINFO * TNC); - -static VOID EncodeAndSend(struct TNCINFO * TNC, UCHAR * txbuffer, int Len); -VOID SendCmd(struct TNCINFO * TNC, UCHAR * txbuffer, int Len); -int DLEEncode(UCHAR * inbuff, UCHAR * outbuff, int len); -int DLEDecode(UCHAR * inbuff, UCHAR * outbuff, int len); - -VOID COMClearDTR(HANDLE fd); -VOID COMClearRTS(HANDLE fd); -int DoScanLine(struct TNCINFO * TNC, char * Buff, int Len); - - - -//static HANDLE LogHandle[4] = {INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE}; - -//char * Logs[4] = {"1", "2", "3", "4"}; - -//char BaseDir[]="c:"; - -static VOID CloseLogfile(int Flags) -{ -// CloseHandle(LogHandle[Flags]); -// LogHandle[Flags] = INVALID_HANDLE_VALUE; -} - -static VOID OpenLogfile(int Flags) -{ -/* -UCHAR FN[MAX_PATH]; - time_t T; - struct tm * tm; - - T = time(NULL); - tm = gmtime(&T); - - sprintf(FN,"%s\\HALLog_%02d%02d%02d_%s.bin", BaseDir, tm->tm_mday, tm->tm_hour, tm->tm_min, Logs[Flags]); - - LogHandle[Flags] = CreateFile(FN, - GENERIC_WRITE, - FILE_SHARE_READ, - NULL, - OPEN_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - SetFilePointer(LogHandle[Flags], 0, 0, FILE_END); - - return (LogHandle[Flags] != INVALID_HANDLE_VALUE); -*/ -} - -static void WriteLogLine(int Flags, char * Msg, int MsgLen) -{ -// int cnt; -// WriteFile(LogHandle[Flags] ,Msg , MsgLen, &cnt, NULL); -} - - - -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 - - ptr = strtok(NULL, " \t\n\r"); - - if (_stricmp(buf, "APPL") == 0) // Using BPQ32 COnfig - { - BPQport = Port; - p_cmd = ptr; - } - else - if (_stricmp(buf, "PORT") != 0) // Using Old Config - { - // New config without a PORT or APPL - this is a Config Command - - strcpy(buf, errbuf); - strcat(buf, "\r"); - - BPQport = Port; - - TNC = TNCInfo[BPQport] = zalloc(sizeof(struct TNCINFO)); - - TNC->InitScript = malloc(1000); - TNC->InitScript[0] = 0; - goto ConfigLine; - } - else - - { - - // Old Config from file - - BPQport=0; - BPQport = atoi(ptr); - - p_cmd = strtok(NULL, " \t\n\r"); - - if (Port && Port != BPQport) - { - // Want a particular port, and this isn't it - - while(TRUE) - { - if (GetLine(buf) == 0) - return TRUE; - - if (memcmp(buf, "****", 4) == 0) - return TRUE; - - } - } - } - if(BPQport > 0 && BPQport < 33) - { - TNC = TNCInfo[BPQport] = zalloc(sizeof(struct TNCINFO)); - TNC->InitScript = malloc(1000); - TNC->InitScript[0] = 0; - - if (p_cmd != NULL) - { - if (p_cmd[0] != ';' && p_cmd[0] != '#') - TNC->ApplCmd=_strdup(p_cmd); - } - - // Read Initialisation lines - - while(TRUE) - { - if (GetLine(buf) == 0) - return TRUE; -ConfigLine: - strcpy(errbuf, buf); - - if (memcmp(buf, "****", 4) == 0) - return TRUE; - - ptr = strchr(buf, ';'); - if (ptr) - { - *ptr++ = 13; - *ptr = 0; - } - - if (_memicmp(buf, "WL2KREPORT", 10) == 0) - { - TNC->WL2K = DecodeWL2KReportLine(buf); - continue; - } - if (_memicmp(buf, "NEEDXONXOFF", 10) == 0) - { - TNC->XONXOFF = TRUE; - continue; - } - - if (_memicmp(buf, "TONES", 5) == 0) - { - int tone1 = 0, tone2 = 0; - - ptr = strtok(&buf[6], " ,/\t\n\r"); - if (ptr) - { - tone1 = atoi(ptr); - ptr = strtok(NULL, " ,/\t\n\r"); - if (ptr) - { - tone2 = atoi(ptr); - ptr = &TNC->InitScript[TNC->InitScriptLen]; - - // Try putting into FSK mode first - - *(ptr++) = 0x84; - *(ptr++) = SetTones; // Set Tones (Mark, Space HI byte first) - *(ptr++) = tone1 >> 8; - *(ptr++) = tone1 & 0xff; - *(ptr++) = tone2 >> 8; - *(ptr++) = tone2 & 0xff; - - TNC->InitScriptLen += 6; - - continue; - } - } - goto BadLine; - } - if (_memicmp(buf, "DEFAULTMODE ", 12) == 0) - { - - ptr = strtok(&buf[12], " ,\t\n\r"); - if (ptr) - { - if (_stricmp(ptr, "CLOVER") == 0) - TNC->DefaultMode = Clover; - else if (_stricmp(ptr, "PACTOR") == 0) - TNC->DefaultMode = Pactor; - else if (_stricmp(ptr, "AMTOR") == 0) - TNC->DefaultMode = AMTOR; - else goto BadLine; - - continue; - } - goto BadLine; - } - } - BadLine: - WritetoConsole(" Bad config record "); - WritetoConsole(errbuf); - WritetoConsole("\r\n"); - } - - return (TRUE); -} - -static size_t ExtProc(int fn, int port , PDATAMESSAGE buff) -{ - int txlen = 0; - PMSGWITHLEN buffptr; - struct TNCINFO * TNC = TNCInfo[port]; - struct STREAMINFO * STREAM; - int Stream; - - if (TNC == NULL) - return 0; - - if (fn < 4 || fn > 5) - if (TNC->hDevice == 0) - return 0; // Port not open - - STREAM = &TNC->Streams[0]; - - switch (fn) - { - case 1: // poll - - while (TNC->PortRecord->UI_Q) // Release anything accidentally put on UI_Q - { - buffptr = Q_REM(&TNC->PortRecord->UI_Q); - ReleaseBuffer(buffptr); - } - - //for (Stream = 0; Stream <= MaxStreams; Stream++) - { - if (STREAM->ReportDISC) - { - STREAM->ReportDISC = FALSE; - buff->PORT = 0; - - return -1; - } - } - - CheckRX(TNC); - HALPoll(port); - - //for (Stream = 0; Stream <= MaxStreams; Stream++) - { - if (STREAM->PACTORtoBPQ_Q !=0) - { - int datalen; - - buffptr=Q_REM(&STREAM->PACTORtoBPQ_Q); - - datalen = (int)buffptr->Len; - - buff->PORT = 0; // 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); - } - } - - return 0; - - case 2: // send - - buffptr = GetBuff(); - - if (buffptr == 0) return (0); // No buffers, so ignore - - // Find TNC Record - - Stream = buff->PORT; - - if (!TNC->TNCOK) - { - // Send Error Response - - PMSGWITHLEN buffptr = (PMSGWITHLEN)GetBuff(); - - if (buffptr == 0) return (0); // No buffers, so ignore - - buffptr->Len = 27; - memcpy(&buffptr->Data[0], "No Connection to PACTOR TNC\r", 27); - - C_Q_ADD(&TNC->Streams[Stream].PACTORtoBPQ_Q, buffptr); - return 0; - } - - txlen = GetLengthfromBuffer(buff) - (sizeof(void *) + 4); - - buffptr->Len = txlen; - memcpy(&buffptr->Data[0], &buff->L2DATA[0], txlen); - - C_Q_ADD(&STREAM->BPQtoPACTOR_Q, buffptr); - - STREAM->FramesQueued++; - - return (0); - - - case 3: // CHECK IF OK TO SEND. Also used to check if TNC is responding - - Stream = (int)(size_t)buff; - - if (STREAM->FramesQueued > 4) - return (1 | TNC->HostMode << 8); - - return TNC->HostMode << 8 | STREAM->Disconnecting << 15; // OK, but lock attach if disconnecting - - case 4: // reinit - - return (0); - - case 5: // Close - - CloseCOMPort(TNCInfo[port]->hDevice); - return (0); - - case 6: // Scan Control - - return 0; // None Yet - - } - 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>" - "<head><title>HAL Status</title></head><body><h3>HAL Status</h3>"); - - Len += sprintf(&Buff[Len], "<table style=\"text-align: left; width: 480px; font-family: monospace; align=center \" border=1 cellpadding=2 cellspacing=2>"); - - Len += sprintf(&Buff[Len], "<tr><td width=90px>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>Status</td><td>%s</td></tr>", TNC->WEB_STATE); - Len += sprintf(&Buff[Len], "<tr><td>TX/RX State</td><td>%s</td></tr>", TNC->WEB_TXRX); - Len += sprintf(&Buff[Len], "<tr><td>Traffic</td><td>%s</td></tr>", TNC->WEB_TRAFFIC); - Len += sprintf(&Buff[Len], "<tr><td>LEDS</td><td>STBY CALL LINK ERROR TX RX</td></tr>"); - Len += sprintf(&Buff[Len], "<tr><td> </td><td>%s</td></tr>", TNC->WEB_LEDS); - Len += sprintf(&Buff[Len], "</table>"); - - Len = DoScanLine(TNC, Buff, Len); - - return Len; -} - - -VOID * HALExtInit(EXTPORTDATA * PortEntry) -{ - char msg[500]; - struct TNCINFO * TNC; - int port; - char * ptr; - int len; - char Msg[80]; -#ifndef LINBPQ - HWND x; -#endif - // - // Will be called once for each Pactor Port - // The COM port number is in IOBASE - // - - sprintf(msg,"HAL Driver %s", PortEntry->PORTCONTROL.SerialPortName); - WritetoConsole(msg); - - 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"); - WritetoConsole(msg); - - return ExtProc; - } - - TNC->Port = port; - - TNC->Hardware = H_HAL; - - TNC->Interlock = PortEntry->PORTCONTROL.PORTINTERLOCK; - - PortEntry->MAXHOSTMODESESSIONS = 1; // Default - - TNC->PortRecord = PortEntry; - - if (PortEntry->PORTCONTROL.PORTCALL[0] == 0) - { - memcpy(TNC->NodeCall, MYNODECALL, 10); - } - else - { - ConvFromAX25(&PortEntry->PORTCONTROL.PORTCALL[0], TNC->NodeCall); - } - - PortEntry->PORTCONTROL.PROTOCOL = 10; - PortEntry->PORTCONTROL.PORTQUALITY = 0; - - if (PortEntry->PORTCONTROL.PORTPACLEN == 0) - PortEntry->PORTCONTROL.PORTPACLEN = 100; - - ptr=strchr(TNC->NodeCall, ' '); - if (ptr) *(ptr) = 0; // Null Terminate - - if (TNC->DefaultMode) - TNC->CurrentMode = TNC->DefaultMode; - else - TNC->CurrentMode = Clover; - - TNC->PollDelay = 999999999; - - // Set Disable +?, ExpandedStatus , Channel Stats Off, ClearOnDisc, EAS and MYCALL - - len = sprintf(Msg, "%c%c%c%c%c%c%s", 0xcc, 0x56, 0x41, ClearOnDisc, SetEAS, SetMYCALL, TNC->NodeCall); - len++; // We include the NULL - - memcpy(&TNC->InitScript[TNC->InitScriptLen], Msg, len); - TNC->InitScriptLen += len; - - PortEntry->PORTCONTROL.TNC = TNC; - - TNC->WebWindowProc = WebProc; - TNC->WebWinX = 510; - TNC->WebWinY = 280; - - TNC->WEB_COMMSSTATE = zalloc(100); - TNC->WEB_TNCSTATE = zalloc(100); - strcpy(TNC->WEB_TNCSTATE, "Free"); - TNC->WEB_MODE = zalloc(100); - TNC->WEB_TRAFFIC = zalloc(100); - TNC->WEB_BUFFERS = zalloc(100); - TNC->WEB_STATE = zalloc(100); - TNC->WEB_TXRX = zalloc(100); - TNC->WEB_LEDS = zalloc(100); - strcpy(TNC->WEB_LEDS, " X X X X X X"); - -#ifndef LINBPQ - - CreatePactorWindow(TNC, ClassName, WindowTitle, RigControlRow, PacWndProc, 500, 233, ForcedClose); - - x = CreateWindowEx(0, "STATIC", "Comms State", WS_CHILD | WS_VISIBLE, 10,6,120,20, TNC->hDlg, NULL, hInstance, NULL); - x = TNC->xIDC_COMMSSTATE = CreateWindowEx(0, "STATIC", "", WS_CHILD | WS_VISIBLE, 116,6,386,20, TNC->hDlg, NULL, hInstance, NULL); - - x = CreateWindowEx(0, "STATIC", "TNC State", WS_CHILD | WS_VISIBLE, 10,28,106,20, TNC->hDlg, NULL, hInstance, NULL); - x = TNC->xIDC_TNCSTATE = CreateWindowEx(0, "STATIC", "", WS_CHILD | WS_VISIBLE, 116,28,520,20, TNC->hDlg, NULL, hInstance, NULL); - - x = CreateWindowEx(0, "STATIC", "Mode", WS_CHILD | WS_VISIBLE, 10,50,80,20, TNC->hDlg, NULL, hInstance, NULL); - x = TNC->xIDC_MODE = CreateWindowEx(0, "STATIC", "", WS_CHILD | WS_VISIBLE, 116,50,200,20, TNC->hDlg, NULL, hInstance, NULL); - - x = CreateWindowEx(0, "STATIC", "Status", WS_CHILD | WS_VISIBLE, 10,72,110,20, TNC->hDlg, NULL, hInstance, NULL); - x = TNC->xIDC_STATE = CreateWindowEx(0, "STATIC", "", WS_CHILD | WS_VISIBLE, 116,72,144,20, TNC->hDlg, NULL, hInstance, NULL); - - x = CreateWindowEx(0, "STATIC", "TX/RX State", WS_CHILD | WS_VISIBLE,10,94,80,20, TNC->hDlg, NULL, hInstance, NULL); - x = TNC->xIDC_TXRX = CreateWindowEx(0, "STATIC", "", WS_CHILD | WS_VISIBLE,116,94,374,20 , TNC->hDlg, NULL, hInstance, NULL); - - x = CreateWindowEx(0, "STATIC", "Traffic", WS_CHILD | WS_VISIBLE,10,116,80,20, TNC->hDlg, NULL, hInstance, NULL); - x = TNC->xIDC_TRAFFIC = CreateWindowEx(0, "STATIC", "RX 0 TX 0 ACKED 0", WS_CHILD | WS_VISIBLE,116,116,374,20 , TNC->hDlg, NULL, hInstance, NULL); - - x = CreateWindowEx(0, "STATIC", "LEDS", WS_CHILD | WS_VISIBLE,10,138,60,20, TNC->hDlg, NULL, hInstance, NULL); - SendMessage(x, WM_SETFONT, (WPARAM)hFont, 0); - x = CreateWindowEx(0, "STATIC", "STBY CALL LINK ERROR TX RX", WS_CHILD | WS_VISIBLE,116,138,280,20, TNC->hDlg, NULL, hInstance, NULL); - SendMessage(x, WM_SETFONT, (WPARAM)hFont, 0); - x = TNC->xIDC_LEDS = CreateWindowEx(0, "STATIC", " X X X X X X", WS_CHILD | WS_VISIBLE,116,158,280,20 , TNC->hDlg, NULL, hInstance, NULL); - SendMessage(x, WM_SETFONT, (WPARAM)hFont, 0); - - TNC->ClientHeight = 233; - TNC->ClientWidth = 500; - - MoveWindows(TNC); -#endif - - OpenCOMMPort(TNC, PortEntry->PORTCONTROL.SerialPortName, PortEntry->PORTCONTROL.BAUDRATE, FALSE); - - SendCmd(TNC, "\x09" , 1); // Reset - - WritetoConsole("\n"); - - return ExtProc; -} - - - -static VOID KISSCLOSE(int Port) -{ - struct TNCINFO * conn = TNCInfo[Port]; - - // drop DTR and RTS - - COMClearDTR(conn->hDevice); - COMClearRTS(conn->hDevice); - - // purge any outstanding reads/writes and close device handle - - CloseCOMPort(conn->hDevice); - - return; -} - - -static void CheckRX(struct TNCINFO * TNC) -{ - int Length, Len; - UCHAR * Xptr; - - // only try to read number of bytes in queue - - if (TNC->RXLen == 500) - TNC->RXLen = 0; - - Len = ReadCOMBlock(TNC->hDevice, &TNC->RXBuffer[TNC->RXLen], 500 - TNC->RXLen); - - if (Len == 0) - return; - - TNC->RXLen += Len; - - Length = TNC->RXLen; - - // We need to konw whether data is received or echoed, so we can't split commands and data here. - // Pass everything to the Command Handler. It will check that there are enough bytes for the command, - // and wait for more if not. - - // The USB version also uses 0x91 0x31 to eacape 0x11, 0x91 0x33 for 0x13 and 0x91 0xB1 for 0x91 - - // If USB version, we might get unescaped xon and xoff, which we must ignore - - if (TNC->XONXOFF) - { - Xptr = memchr(&TNC->RXBuffer, 0x11, Length); - - while(Xptr) - { - Debugprintf("XON Port %d", TNC->Port); - memmove(Xptr, Xptr + 1, Length-- - (TNC->RXBuffer - Xptr)); - Xptr = memchr(&TNC->RXBuffer, 0x11, Length); - } - - Xptr = memchr(&TNC->RXBuffer, 0x13, Length); - - while(Xptr) - { - Debugprintf("XOFF Port %d", TNC->Port); - memmove(Xptr, Xptr + 1, Length-- - (TNC->RXBuffer - Xptr)); - Xptr = memchr(&TNC->RXBuffer, 0x13, Length); - } - - Xptr = memchr(&TNC->RXBuffer, 0x91, Length); // See if packet contains 0x91 escape - - if (Xptr) - - // Make sure we have the escaped char as well - - if ((Xptr - &TNC->RXBuffer[0]) == Length - 1) // x91 is last char - return; - } - - ProcessHALBuffer(TNC, Length); - - TNC->RXLen = 0; - - return; - -} - - - -static BOOL WriteCommBlock(struct TNCINFO * TNC) -{ - WriteCOMBlock(TNC->hDevice, TNC->TXBuffer, TNC->TXLen); - return TRUE; -} - -VOID HALPoll(int Port) -{ - struct TNCINFO * TNC = TNCInfo[Port]; - struct STREAMINFO * STREAM = &TNC->Streams[0]; - - UCHAR * Poll = TNC->TXBuffer; - char Status[80]; - UCHAR TXMsg[1000]; - int datalen; - - if (TNC->Timeout) - { - TNC->Timeout--; - - if (TNC->Timeout) // Still waiting - return; - - // Timed Out - - TNC->TNCOK = FALSE; - TNC->HostMode = 0; - - sprintf(TNC->WEB_COMMSSTATE,"%s Open but TNC not responding", TNC->PortRecord->PORTCONTROL.SerialPortName); - MySetWindowText(TNC->xIDC_COMMSSTATE, TNC->WEB_COMMSSTATE); - - //for (Stream = 0; Stream <= MaxStreams; Stream++) - { - if (TNC->PortRecord->ATTACHEDSESSIONS[0]) // Connected - { - STREAM->Connected = FALSE; // Back to Command Mode - STREAM->ReportDISC = TRUE; // Tell Node - } - } - - } - - // if we have just restarted or TNC appears to be in terminal mode, run Initialisation Sequence - - if (TNC->TNCOK) - if (!TNC->HostMode) - { - DoTNCReinit(TNC); - return; - } - - if (TNC->PortRecord->ATTACHEDSESSIONS[0] && STREAM->Attached == 0) - { - // New Attach - - int calllen; - char Msg[80]; - - STREAM->Attached = TRUE; - - STREAM->BytesRXed = STREAM->BytesTXed = STREAM->BytesAcked = 0; - - calllen = ConvFromAX25(TNC->PortRecord->ATTACHEDSESSIONS[0]->L4USER, STREAM->MyCall); - STREAM->MyCall[calllen] = 0; - - datalen = sprintf(TXMsg, "%c%s", SetMYCALL, STREAM->MyCall); - SendCmd(TNC, TXMsg, datalen + 1); // Send the NULL - - sprintf(TNC->WEB_TNCSTATE, "In Use by %s", STREAM->MyCall); - MySetWindowText(TNC->xIDC_TNCSTATE, TNC->WEB_TNCSTATE); - - // Stop Scanning - - sprintf(Msg, "%d SCANSTOP", TNC->Port); - - Rig_Command(-1, Msg); - - SendCmd(TNC, "\x42", 1); // Connect Enable off - - return; - - } - - //for (Stream = 0; Stream <= MaxStreams; Stream++) - - if (STREAM->Attached) - CheckForDetach(TNC, 0, STREAM, TidyClose, ForcedClose, CloseComplete); - - if (TNC->NeedPACTOR) - { - TNC->NeedPACTOR--; - - if (TNC->NeedPACTOR == 0) - { - int datalen; - - UCHAR TXMsg[80]; - - datalen = sprintf(TXMsg, "%c%s", SetMYCALL, TNC->NodeCall); - SendCmd(TNC, TXMsg, datalen + 1); // Send the NULL - - // Set Listen Mode - - switch (TNC->CurrentMode) - { - case Pactor: - - SendCmd(TNC, "\x84", 1); // FSK - SendCmd(TNC, "\x83", 1); // Select P-MODE Standby - SendCmd(TNC, "\x58", 1); // Listen - - break; - - case Clover: - - SendCmd(TNC, "\x80", 1); // Clover - SendCmd(TNC, "\x54", 1); // Enable adaptive Clover format - SendCmd(TNC, "\x41", 1); // No Statistics - SendCmd(TNC, "\x60\x09", 2); // Robust Retries - SendCmd(TNC, "\x61\x09", 2); // Normal Retries - - break; - } - - SendCmd(TNC, "\x52", 1); // ConnectEnable - - // Restart Scanning - - sprintf(Status, "%d SCANSTART 15", TNC->Port); - - Rig_Command(-1, Status); - - return; - } - } - -#define MAXHALTX 256 - - //for (Stream = 0; Stream <= MaxStreams; Stream++) - { - if (TNC->TNCOK && STREAM->BPQtoPACTOR_Q && (STREAM->BytesTXed - STREAM->BytesAcked < 600)) - { - int datalen; - UINT * buffptr; - UCHAR * MsgPtr; - unsigned char TXMsg[500]; - - buffptr = (UINT * )STREAM->BPQtoPACTOR_Q; - datalen=buffptr[1]; - MsgPtr = (UCHAR *)&buffptr[2]; - - if (STREAM->Connected) - { - if (TNC->SwallowSignon) - { - TNC->SwallowSignon = FALSE; - if (strstr(MsgPtr, "Connected")) // Discard *** connected - { - ReleaseBuffer(buffptr); - STREAM->FramesQueued--; - return; - } - } - - // Must send data in small chunks - the Hal has limited buffer space - - // If in IRS force a turnround - - if (TNC->TXRXState == 'R' && TNC->CurrentMode != Clover) - { - if (TNC->TimeInRX++ > 15) - SendCmd(TNC, "\x87", 1); // Changeover to ISS - else - goto Poll; - } - - TNC->TimeInRX = 0; - - EncodeAndSend(TNC, MsgPtr, datalen); - buffptr=Q_REM(&STREAM->BPQtoPACTOR_Q); - ReleaseBuffer(buffptr); - WriteLogLine(2, MsgPtr, datalen); - - STREAM->BytesTXed += datalen; - STREAM->FramesQueued--; - - ShowTraffic(TNC); - - return; - } - else - { - buffptr=Q_REM(&STREAM->BPQtoPACTOR_Q); - STREAM->FramesQueued--; - - // Command. Do some sanity checking and look for things to process locally - - datalen--; // Exclude CR - MsgPtr[datalen] = 0; // Null Terminate - _strupr(MsgPtr); - - if (memcmp(MsgPtr, "RADIO ", 6) == 0) - { - sprintf(&MsgPtr[40], "%d %s", TNC->Port, &MsgPtr[6]); - if (Rig_Command(TNC->PortRecord->ATTACHEDSESSIONS[0]->L4CROSSLINK->CIRCUITINDEX, &MsgPtr[40])) - { - ReleaseBuffer(buffptr); - } - else - { - buffptr[1] = sprintf((UCHAR *)&buffptr[2], "%s", &MsgPtr[40]); - C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr); - } - return; - } - - if (memcmp(MsgPtr, "MODE CLOVER", 11) == 0) - { - TNC->CurrentMode = Clover; - buffptr[1] = sprintf((UCHAR *)&buffptr[2],"HAL} Ok\r"); - C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr); - - MySetWindowText(TNC->xIDC_MODE, "Clover"); - strcpy(TNC->WEB_MODE, "Clover"); - - SendCmd(TNC, "\x80", 1); // Clover - SendCmd(TNC, "\x54", 1); // Enable adaptive Clover format - SendCmd(TNC, "\x41", 1); // No Statistics - - return; - } - - if (memcmp(MsgPtr, "MODE PACTOR", 11) == 0) - { - TNC->CurrentMode = Pactor; - buffptr[1] = sprintf((UCHAR *)&buffptr[2],"HAL} Ok\r"); - C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr); - - SendCmd(TNC, "\x84", 1); // FSK - SendCmd(TNC, "\x83", 1); // Select P-MODE Standby - SendCmd(TNC, "\x48", 1); // Listen Off - - return; - } - if (memcmp(MsgPtr, "MODE AMTOR", 11) == 0) - { - TNC->CurrentMode = AMTOR; - buffptr[1] = sprintf((UCHAR *)&buffptr[2],"HAL} Ok\r"); - C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr); - - return; - } - - if (MsgPtr[0] == 'C' && MsgPtr[1] == ' ' && datalen > 2) // Connect - { - memcpy(STREAM->RemoteCall, &MsgPtr[2], 9); - - switch (TNC->CurrentMode) - { - case Pactor: - - SendCmd(TNC, "\x84", 1); // FSK - SendCmd(TNC, "\x83", 1); // Select P-MODE Standby - - datalen = sprintf(TXMsg, "\x19%s", STREAM->RemoteCall); - - sprintf(TNC->WEB_TNCSTATE, "%s Connecting to %s - PACTOR", STREAM->MyCall, STREAM->RemoteCall); - - // DOnt set connecting till we get the 19 response so we can trap listen as a fail - break; - - case Clover: - - SendCmd(TNC, "\x54", 1); // Enable adaptive Clover format - SendCmd(TNC, "\x57", 1); // Enable TX buffer clear on disconnect - - datalen = sprintf(TXMsg, "\x11%s", STREAM->RemoteCall); - - sprintf(TNC->WEB_TNCSTATE, "%s Connecting to %s - CLOVER", STREAM->MyCall, STREAM->RemoteCall); - - break; - } - - MySetWindowText(TNC->xIDC_TNCSTATE, TNC->WEB_TNCSTATE); - SendCmd(TNC, TXMsg, datalen + 1); // Include NULL - - ReleaseBuffer(buffptr); - - return; - } - - if (memcmp(MsgPtr, "CLOVER ", 7) == 0) - { - memcpy(STREAM->RemoteCall, &MsgPtr[2], 9); - - SendCmd(TNC, "\x54", 1); // Enable adaptive Clover format - SendCmd(TNC, "\x57", 1); // Enable TX buffer clear on disconnect - - datalen = sprintf(TXMsg, "\x11%s", STREAM->RemoteCall); - SendCmd(TNC, TXMsg, datalen + 1); // Include NULL - - sprintf(TNC->WEB_TNCSTATE, "%s Connecting to %s - CLOVER", - STREAM->MyCall, STREAM->RemoteCall); - MySetWindowText(TNC->xIDC_TNCSTATE, TNC->WEB_TNCSTATE); - - ReleaseBuffer(buffptr); - - return; - } - - if (memcmp(MsgPtr, "DISCONNECT", datalen) == 0) // Disconnect - { - SendCmd(TNC, "\x07", 1); // Normal Disconnect - TNC->NeedPACTOR = 50; - - STREAM->Connecting = FALSE; - STREAM->ReportDISC = TRUE; - ReleaseBuffer(buffptr); - - return; - } - - // Other Command ?? Treat as HEX string - - datalen = sscanf(MsgPtr, "%X %X %X %X %X %X %X %X %X %X %X %X %X %X %X %X", - (UINT *)&TXMsg[0], (UINT *)&TXMsg[1], (UINT *)&TXMsg[2], (UINT *)&TXMsg[3], (UINT *)&TXMsg[4], - (UINT *)&TXMsg[5], (UINT *)&TXMsg[6], (UINT *)&TXMsg[7], (UINT *)&TXMsg[8], (UINT *)&TXMsg[9], - (UINT *)&TXMsg[10], (UINT *)&TXMsg[11], (UINT *)&TXMsg[12], (UINT *)&TXMsg[13], - (UINT *)&TXMsg[14], (UINT *)&TXMsg[15]); - -// SendCmd(TNC, TXMsg, datalen); - ReleaseBuffer(buffptr); - TNC->InternalCmd = 0; - } - } - } -Poll: - // Nothing doing - send Poll (but not too often) - - TNC->PollDelay++; - - if (TNC->PollDelay < 20) - return; - - TNC->PollDelay = 0; - - if (TNC->TNCOK) - SendCmd(TNC, "\x7d" , 1); // Use Get LEDS as Poll - else - SendCmd(TNC, "\x09" , 1); // Reset - - TNC->Timeout = 100; - - return; -} - -static VOID DoTNCReinit(struct TNCINFO * TNC) -{ - // TNC Has Restarted, send init commands (can probably send all at once) - -// TNC->TXBuffer[0] = 0x1b; -// TNC->TXLen = 1; - - WriteCommBlock(TNC); - - SendCmd(TNC, TNC->InitScript, TNC->InitScriptLen); - - TNC->HostMode = TRUE; // Should now be in Host Mode - TNC->NeedPACTOR = 20; // Need to set Calls and start scan - - TNC->DataMode = RXDATA; // Start with RX Data - - SendCmd(TNC, "\x7d" , 1); // Use Get LEDS as Poll -// SendCmd(TNC, "\xc9" , 1); // Huffman Off - SendCmd(TNC, "\x57", 1); // Enable TX buffer clear on disconnect - - SendCmd(TNC, "\x60\x06", 2); // Robust Mode Retries - -// SendCmd(TNC, "\x6f\x03" , 2); // Undocumented XON/XOFF On - used to see if old or new style modem - - TNC->Timeout = 50; - - return; - -} - -VOID ProcessHALData(struct TNCINFO * TNC) -{ - // Received Data just pass to Appl - - UINT * buffptr; - int Len = TNC->DataLen; - struct STREAMINFO * STREAM = &TNC->Streams[0]; - - TNC->DataLen = 0; - - if (TNC->DataMode == TXDATA) - { - STREAM->BytesAcked += Len; -// Debugprintf("Acked %d", Len); - - if (STREAM->BytesAcked > STREAM->BytesTXed) - Debugprintf("Too Much Acked"); - - if ((STREAM->BPQtoPACTOR_Q == 0) && STREAM->BytesAcked >= STREAM->BytesTXed) - { - // All sent - - if (STREAM->Disconnecting) - TidyClose(TNC, 0); - else - if (TNC->CurrentMode != Clover) - - // turn round link - - SendCmd(TNC, "\x0c" , 1); // Turnround - - } - } - else - { - if (TNC->DataMode == RXDATA) - { -// Debugprintf("RXed %d", Len); - buffptr = GetBuff(); - if (buffptr == NULL) - return; // No buffers, so ignore - - buffptr[1] = Len; // Length - - WriteLogLine(1, TNC->DataBuffer, Len); - - STREAM->BytesRXed += Len; - - memcpy(&buffptr[2], TNC->DataBuffer, Len); - - C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr); - } - } - - ShowTraffic(TNC); - - return; -} - - - -VOID ProcessHALBuffer(struct TNCINFO * TNC, int Length) -{ - UCHAR Char; - UCHAR * inptr; - UCHAR * cmdptr; - UCHAR * dataptr; - BOOL CmdEsc, DataEsc; - - inptr = TNC->RXBuffer; - - cmdptr = &TNC->CmdBuffer[TNC->CmdLen]; - dataptr = &TNC->DataBuffer[TNC->DataLen]; - CmdEsc = TNC->CmdEsc; - DataEsc = TNC->DataEsc; - - // HAL uses HEX 80 as a command escape, 81 to ESCAPE 80 and 81 - - // The USB version also uses 0x91 0x31 to eacape 0x11, 0x91 0x33 for 0x13 and 0x91 0xB1 for 0x91 - - // Command Responses can be variable length - - // Command Handler will check for each command/response if it has enough - if not it will wait till more arrives - - while(Length--) - { - Char = *(inptr++); - - if (CmdEsc) - { - CmdEsc = FALSE; - - if (TNC->XONXOFF && Char == 0x91) - { - // XON/XOFF escape. We ensured above that data follows so we can process it inline - - Length--; - Char = *(inptr++) - 0x20; - } - *(cmdptr++) = Char; - } - else if (DataEsc) - { - DataEsc = FALSE; - goto DataChar; - } - else -NotData: - if (Char == 0x80) // Next Char is Command - CmdEsc = TRUE; - else if (Char == 0x81) // Next Char is escaped data (80 or 81) - DataEsc = TRUE; - else - { - // This is a Data Char. We must process any Commands received so far, so we know the type of data - - DataChar: - - TNC->CmdLen = (int)(cmdptr - TNC->CmdBuffer); - ProcessHALCmd(TNC); - cmdptr = &TNC->CmdBuffer[TNC->CmdLen]; - dataptr = &TNC->DataBuffer[TNC->DataLen]; - - *(dataptr++) = Char; // Normal Data - - // Now process any other data chars - - while(Length--) - { - Char = *(inptr++); - - if (TNC->XONXOFF && Char == 0x91) - { - // XON/XOFF escape within data. We ensured above that data follows so we - // can process it here - - Length--; - Char = *(inptr++) - 0x20; - } - - if (Char == 0x80 || Char == 0x81) - { - // Process any data we have, then loop back - - TNC->DataLen = (int)(dataptr - TNC->DataBuffer); - ProcessHALData(TNC); - - goto NotData; - } - *(dataptr++) = Char; // Normal Data - } - - // Used all data - - TNC->DataLen = (int)(dataptr - TNC->DataBuffer); - - ProcessHALData(TNC); - TNC->CmdEsc = CmdEsc; - TNC->DataEsc = DataEsc; - - return; - } - } - - // Save State - - TNC->CmdLen = (int)(cmdptr - TNC->CmdBuffer); - - TNC->CmdEsc = CmdEsc; - TNC->DataEsc = DataEsc; - - if (TNC->DataLen) - ProcessHALData(TNC); - - if (TNC->CmdLen) - ProcessHALCmd(TNC); -} - -VOID mySetWindowText(struct TNCINFO * TNC, char * Msg) -{ - MySetWindowText(TNC->xIDC_STATE, Msg); - strcpy(TNC->WEB_STATE, Msg); -} - -VOID ProcessHALCmd(struct TNCINFO * TNC) -{ - char * Call; - int Stream = 0; - int Opcode; - int StatusByte; - int Leds; - int Len; - int Used; - struct STREAMINFO * STREAM = &TNC->Streams[0]; - -CmdLoop: - - Opcode = TNC->CmdBuffer[0]; - Len = TNC->CmdLen; - - if (Len == 0) - return; - - TNC->TNCOK = TRUE; - TNC->Timeout = 0; - - sprintf(TNC->WEB_COMMSSTATE,"%s TNC link OK", TNC->PortRecord->PORTCONTROL.SerialPortName); - MySetWindowText(TNC->xIDC_COMMSSTATE, TNC->WEB_COMMSSTATE); - - // We may have more than one response in the buffer, and only each cmd/response decoder knows how many it needs - - switch(Opcode) - { - case 0x09: //Hardware Reset - equivalent to power on reset - - // Hardware has reset - need to reinitialise - - TNC->HostMode = 0; // Force Reinit - - Used = 1; - break; - - case 0x7a: // FSK Modes Status - - // Mixture of mode and state - eg listen huffman on/off irs/iss, so cant just display - - if (Len < 2) return; // Wait for more - - StatusByte = TNC->CmdBuffer[1]; - - switch (StatusByte) - { - case 0x06: // FSK TX (RTTY) - case 0x07: // FSK RX (RTTY) - case 0x10: // AMTOR STANDBY (LISTEN ON) - case 0x11: // AMTOR STANDBY (LISTEN OFF) - case 0x12: // AMTOR FEC TX (AMTOR) - case 0x13: // AMTOR FEC RX (AMTOR) - case 0x14: // P-MODE FEC TX (P-MODE) - case 0x15: // FREE SIGNAL TX (AMTOR) - case 0x16: // FREE SIGNAL TX TIMED OUT (AMTOR) - - // Diaplay Linke Status - - MySetWindowText(TNC->xIDC_MODE, status[StatusByte]); - strcpy(TNC->WEB_MODE, status[StatusByte]); - - break; - - case 0x0C: // P-MODE STANDBY (LISTEN ON) - case 0x0D: // P-MODE STANDBY (LISTEN OFF) - - // if we were connecting, this means connect failed. - - MySetWindowText(TNC->xIDC_MODE, status[StatusByte]); - strcpy(TNC->WEB_MODE, status[StatusByte]); - - if (STREAM->Connecting) - HALDisconnected(TNC); - - break; - - case 0x0E: // ISS (AMTOR/P-MODE) - - MySetWindowText(TNC->xIDC_TXRX,"ISS"); - strcpy(TNC->WEB_TXRX, "ISS"); - TNC->TXRXState = 'S'; - break; - - case 0x0F: // IRS (AMTOR/P-MODE) - - MySetWindowText(TNC->xIDC_TXRX,"IRS"); - strcpy(TNC->WEB_TXRX, "IRS"); - TNC->TXRXState = 'R'; - break; - - case 0x00: // IDLE (AMTOR/P-MODE) - case 0x01: // TFC (AMTOR/P-MODE) - case 0x02: // RQ (AMTOR/P-MODE) - case 0x03: // ERR (AMTOR/P-MODE) - case 0x04: // PHS (AMTOR/P-MODE) - case 0x05: // OVER (AMTOR/P-MODE) (not implemented) - - MySetWindowText(TNC->xIDC_STATE, status[StatusByte]); - strcpy(TNC->WEB_MODE, status[StatusByte]); - - - -//$807A $8008 P-MODE100 (P-MODE) -//$807A $8009 P-MODE200 (P-MODE) -//$807A $800A HUFFMAN ON (P-MODE) -//$807A $800B HUFFMAN OFF (P-MODE) - ; - } - Used = 2; - break; - - - case 0x7d: // Get LED Status - - // We use Get LED Status as a Poll - - if (Len < 2) return; // Wait for more - - Leds = TNC->CmdBuffer[1]; - sprintf(TNC->WEB_LEDS," %c %c %c %c %c %c ", - (Leds & 0x20)? 'X' : ' ', - (Leds & 0x10)? 'X' : ' ', - (Leds & 0x08)? 'X' : ' ', - (Leds & 0x04)? 'X' : ' ', - (Leds & 0x02)? 'X' : ' ', - (Leds & 0x01)? 'X' : ' '); - -// STBY CALL LINK ERROR TX RX - MySetWindowText(TNC->xIDC_LEDS, TNC->WEB_LEDS); - - Used = 2; - break; - - case 0x21: // Monitored FEC CCB - case 0x22: // Monitored ARQ CCB - - // As the reply is variable, make sure we have the terminating NULL - - if (memchr(TNC->CmdBuffer, 0, Len) == NULL) - return; // Wait for more - - Call = &TNC->CmdBuffer[1]; - Used = (int)strlen(Call) + 2; // Opcode and Null - - UpdateMH(TNC, Call, '!', 0); - - break; - - case 0x27: // Clover ARQ LINK REQUEST status message - - //indicates an incoming link request to either MYCALL ($8027 $8000), or MYALTCALL ($8027 $8001). - - if (Len < 2) return; // Wait for more - - // Don't need to do anything (but may eventally use ALTCALL as an APPLCALL - Used = 2; - break; - - case 0x2D: // FSK ARQ Link Request status message - - // $802D $8001 $8000 CLOVER Link Request (not implemented) - // $802D $8002 $8000 AMTOR CCIR-476 Link Request - // $802D $8003 $8000 AMTOR CCIR-625 Link Request - // $802D $8004 $8000 P-MODE Link Request - - if (Len < 3) return; // Wait for more - - // Don't need to do anything (but may save Session type later - - Used = 3; - break; - - - case 0x28: // Monitored Call - - // As the reply is variable, make sure we have the terminating NULL - - if (memchr(TNC->CmdBuffer, 0, Len) == NULL) - return; // Wait for more - - Call = &TNC->CmdBuffer[1]; - Used = strlen(Call) + 2; // Opcode and Null - - // Could possibly be used for APPLCALLS by changing MYCALL when we see a call to one of our calls - - break; - - - case 0x20: // Clover Linked with - Call Connected - case 0x29: // The Linked 476 message indicates the start of a CCIR 476 linked session. - case 0x2A: // The Linked 625 message indicates the start of a CCIR 625 linked session to <CALL>. - case 0x2B: // P-MODE link to - - // As the reply is variable, make sure we have the terminating NULL - - if (memchr(TNC->CmdBuffer, 0, Len) == NULL) - return; // Wait for more - - Call = &TNC->CmdBuffer[1]; - Used = (int)strlen(Call) + 2; // Opcode and Null - - HALConnected(TNC, Call); - - break; - - case 0x23: // Normal Disconnected - followed by $8000 - case 0x24: // Link failed (any of the link errors) - case 0x25: // Signal Lost (LOS) - - if (Len < 2) return; // Wait for more - - HALDisconnected(TNC); - - Used = 2; - break; - - - // Stream Switch Reports - we will need to do something with these if Echo as Sent is set - // or we do something with the secondary port - - case 0x30: // Switch to Receive Data characters - case 0x31: // Switch to Transmit Data characters - case 0x32: // Switch to RX data from secondary port - - TNC->DataMode = Opcode; - Used = 1; - break; - - case 0x33: // Send TX data to modem - case 0x34: // Send TX data to secondary port - - TNC->TXMode = Opcode; - Used = 1; - break; - - case 0x70: // Channel Spectra Data - // $807F $80xx $8030 Invalid or unimplemented command code - if (Len < 9) return; // Wait for more - - Used = 9; - break; - - case 0x71: // SelCall On/Off - - if (Len < 2) return; // Wait for more - - Used = 2; - break; - - case 0x72: // Channel Spectra Data - // $807F $80xx $8030 Invalid or unimplemented command code - if (Len < 15) return; // Wait for more - - Used = 15; - break; - - case 0x73: // Clover Link state - - if (Len < 2) return; // Wait for more - - StatusByte = TNC->CmdBuffer[1]; - - switch (StatusByte) - { - case 0x00: mySetWindowText(TNC, "Channel idle"); break; - case 0x01: mySetWindowText(TNC, "Channel occupied with non-Clover signal"); break; - case 0x42: mySetWindowText(TNC, "Linked stations monitored"); break; - case 0x64: mySetWindowText(TNC, "Attempting normal link"); break; - case 0x65: mySetWindowText(TNC, "Attempting robust link"); break; - case 0x66: mySetWindowText(TNC, "Calling ARQ CQ"); break; - case 0x78: mySetWindowText(TNC, "Clover Control Block (CCB) send retry"); break; - case 0x79: mySetWindowText(TNC, "Clover Control Block (CCB) receive retry"); break; - case 0x7D: mySetWindowText(TNC, "Clover Control Block (CCB) received successfully"); break; - case 0x8A: mySetWindowText(TNC, "TX data block sent"); break; - case 0x8B: mySetWindowText(TNC, "RX data block received ok (precedes data block)"); break; - case 0x8C: mySetWindowText(TNC, "TX data block re-sent"); break; - case 0x8D: mySetWindowText(TNC, "RX data block decode failed (precedes data block)"); break; - case 0x8E: mySetWindowText(TNC, "TX idle"); break; - case 0x8F: mySetWindowText(TNC, "RX idle"); break; - case 0x9C: mySetWindowText(TNC, "Link failed: CCB send retries exceeded"); break; - case 0x9D: mySetWindowText(TNC, "Link failed: CCB receive retries exceeded"); break; - case 0x9E: mySetWindowText(TNC, "Link failed: protocol error"); break; - case 0xA0: mySetWindowText(TNC, "Receiving FEC SYNC sequence"); break; - } - - Used = 2; - break; - - case 0x75: // Clover waveform format - - if (Len < 5) return; // Wait for more - - Used = 5; - break; - - case 0x7F: // Error $80xx $80yy Error in command $80xx of type $80yy - // $807F $80xx $8030 Invalid or unimplemented command code - // $807F $80xx $8031 Invalid parameter value - // $807F $80xx $8032 Not allowed when connected - // $807F $80xx $8033 Not allowed when disconnected - // $807F $80xx $8034 Not valid in this mode - // $807F $80xx $8035 Not valid in this code - // $807F $8096 $8036 EEPROM write error - - if (Len < 3) return; // Wait for more - - if (TNC->CmdBuffer[1] == 0x6f && TNC->CmdBuffer[2] == 0x31) - { - // Reject of XON/XOFF enable - -// TNC->XONXOFF = FALSE; -// Debugprintf("BPQ32 HAL Port %d - Disabling XON/XOFF mode", TNC->Port); - } - else - Debugprintf("HAL Port %d Command Error Cmd %X Error %X", TNC->Port, TNC->CmdBuffer[1], TNC->CmdBuffer[2]); - - Used = 3; - break; - - // Following are all immediate commands - response is echo of command - - case 0x6f: // XON/XOFF on - -// TNC->XONXOFF = TRUE; // And drop through -// Debugprintf("BPQ32 HAL Port %d - Enabling XON/XOFF mode", TNC->Port); - - case 0x19: // Call P-MODE to <CALL> - case 0x10: // Robust Link to <CALL> using MYCALL - case 0x11: // Normal Link to <CALL> using MYCALL - - STREAM->Connecting = TRUE; - - case 0x00: // P Load LOD file - case 0x01: // P Load S28 file - case 0x02: //Check Unit Error Status - case 0x03: //F Check System Clock - case 0x04: //C Close PTT and transmit Clover waveform - case 0x05: //Open PTT and stop transmit test - case 0x06: //Immediate Abort (Panic Kill) - case 0x07: //Normal disconnect (wait for ACK) - case 0x08: //Software reset - restore all program defaults - case 0x0A: //Send CW ID - case 0x0B: //Close PTT and transmit Single Tone - case 0x0C: //F Normal OVER (AMTOR,P-MODE) - case 0x0D: //F Force RTTY TX (Baudot/ASCII) - case 0x0E: //F Go to RTTY RX (Baudot/ASCII) - case 0x0F: //Go to LOD/S28 file loader - case SetMYCALL: // Set MYCALL Response - - case 0x1E: // Set MYALTCALL Response - - case 0x41: - case 0x42: - case 0x46: - case 0x47: - case 0x48: - case 0x4d: - case 0x52: // Enable adaptive Clover format - case 0x54: // Enable adaptive Clover format - - case 0x56: // Expanded Link State Reports OFF/ON - case 0x57: // Clear buffers on disc - case 0x58: - case 0x59: - case 0x60: // Robust Mode Retries - case 0x61: // Normal Mode Retries - case 0x80: //Switch to CLOVER mode - case 0x81: //Select AMTOR Standby - case 0x82: //Select AMTOR FEC - case 0x83: //Select P-MODE Standby - case 0x84: //Switch to FSK modes - case 0x85: //Select Baudot - case 0x86: //Select ASCII - case 0x87: //Forced OVER (AMTOR, P-MODE) - case 0x88: //Forced END (AMTOR, P-MODE) - case 0x89: //Force LTRS shift - case 0x8A: //Force FIGS shift - case 0x8B: //Send MARK tone - case 0x8C: //Send SPACE tone - case 0x8D: //Send MARK/SPACE tones - case 0x8E: //Received first character on line - case 0x8F: //Close PTT only (no tones) - - case 0xC9: //Huffman Off/On - case 0xCC: - case 0xD9: //Close PTT only (no tones) - - case SetTones: - - Used = 1; - break; - - case 0x91: // ???? - -// if (Len < 2) return; // Wait for more - - Used = 1; - break; - - default: - - // We didn't recognise command, so don't know how long it is - disaster! - - Debugprintf("HAL Port %d Unrecognised Command %x", TNC->Port, Opcode); - TNC->CmdLen = 0; - - return; - } - - if (Used == Len) - { - // All used - most likely case - - TNC->CmdLen = 0; - return; - } - - // Move Command Down buffer, and reenter - - TNC->CmdLen -= Used; - - memmove(TNC->CmdBuffer, &TNC->CmdBuffer[Used], TNC->CmdLen); - - goto CmdLoop; - - -} - - -VOID HALDisconnected(struct TNCINFO * TNC) -{ - struct STREAMINFO * STREAM = &TNC->Streams[0]; - - CloseLogfile(0); - CloseLogfile(1); - CloseLogfile(2); - - if ((STREAM->Connecting | STREAM->Connected) == 0) - { - // Not connected or Connecting. Probably response to going into Pactor Listen Mode - - return; - } - - if (STREAM->Connecting && STREAM->Disconnecting == FALSE) - { - UINT * buffptr; - - // Connect Failed - actually I think HAL uses another code for connect failed, but leave here for now - - buffptr = GetBuff(); - - if (buffptr) - { - buffptr[1] = sprintf((UCHAR *)&buffptr[2], "*** Failure with %s\r", STREAM->RemoteCall); - - C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr); - } - - STREAM->Connecting = FALSE; - STREAM->Connected = FALSE; // In case! - STREAM->FramesQueued = 0; - - sprintf(TNC->WEB_TNCSTATE, "In Use by %s", STREAM->MyCall); - MySetWindowText(TNC->xIDC_TNCSTATE, TNC->WEB_TNCSTATE); - - return; - } - - // Connected, or Disconnecting - Release Session - - STREAM->Connecting = FALSE; - STREAM->Connected = FALSE; // Back to Command Mode - STREAM->FramesQueued = 0; - - if (STREAM->Disconnecting == FALSE) - STREAM->ReportDISC = TRUE; // Tell Node - - STREAM->Disconnecting = FALSE; - - // Need to reset Pactor Call in case it was changed - - TNC->NeedPACTOR = 20; -} - -BOOL HALConnected(struct TNCINFO * TNC, char * Call) -{ - char Msg[80]; - UINT * buffptr; - struct STREAMINFO * STREAM = &TNC->Streams[0]; - char CallCopy[80]; - - strcpy(CallCopy, Call); - strcat(CallCopy, " "); // Some routines expect 10 char calls - - STREAM->BytesRXed = STREAM->BytesTXed = STREAM->BytesAcked = 0; - STREAM->ConnectTime = time(NULL); - - // Stop Scanner - - sprintf(Msg, "%d SCANSTOP", TNC->Port); - - Rig_Command(-1, Msg); - - ShowTraffic(TNC); - - TNC->DataMode = RXDATA; - - OpenLogfile(0); - OpenLogfile(1); - OpenLogfile(2); - - if (TNC->PortRecord->ATTACHEDSESSIONS[0] == 0) - { - // Incoming Connect - - ProcessIncommingConnect(TNC, CallCopy, 0, TRUE); - - sprintf(TNC->WEB_TNCSTATE, "%s Connected to %s Inbound", STREAM->RemoteCall, TNC->NodeCall); - MySetWindowText(TNC->xIDC_TNCSTATE, TNC->WEB_TNCSTATE); - - if (TNC->CurrentMode != Clover) - SendCmd(TNC, "\x87", 1); // Changeover to ISS - - // If an autoconnect APPL is defined, send it - - if (TNC->ApplCmd) - { - buffptr = GetBuff(); - if (buffptr == 0) return TRUE; // No buffers, so ignore - - buffptr[1] = sprintf((UCHAR *)&buffptr[2], "%s\r", TNC->ApplCmd); - C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr); - TNC->SwallowSignon = TRUE; - - return TRUE; - } - - if (FULL_CTEXT && HFCTEXTLEN == 0) - { - EncodeAndSend(TNC, CTEXTMSG, CTEXTLEN); - WriteLogLine(2, CTEXTMSG, CTEXTLEN); - - STREAM->BytesTXed += CTEXTLEN; - } - return TRUE; - } - - // Connect Complete - - buffptr = GetBuff(); - if (buffptr == 0) return TRUE; // No buffers, so ignore - - buffptr[1] = sprintf((UCHAR *)&buffptr[2], "*** Connected to %s\r", Call);; - - C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr); - - STREAM->Connecting = FALSE; - STREAM->Connected = TRUE; // Subsequent data to data channel - - sprintf(TNC->WEB_TNCSTATE, "%s Connected to %s Outbound", TNC->NodeCall, STREAM->RemoteCall); - MySetWindowText(TNC->xIDC_TNCSTATE, TNC->WEB_TNCSTATE); - - UpdateMH(TNC, CallCopy, '+', 'O'); - - - return TRUE; -} - - -static VOID EncodeAndSend(struct TNCINFO * TNC, UCHAR * txbuffer, int Len) -{ - // Send A Packet With DLE Encoding Encoding - - TNC->TXLen = DLEEncode(txbuffer, TNC->TXBuffer, Len); - - WriteCommBlock(TNC); -} - -VOID SendCmd(struct TNCINFO * TNC, UCHAR * txbuffer, int Len) -{ - // Send A Packet With Command Encoding (preceed each with 0x80 - - int i,txptr=0; - UCHAR * outbuff = TNC->TXBuffer; - - for (i=0; i<Len; i++) - { - outbuff[txptr++] = 0x80; - outbuff[txptr++] = txbuffer[i]; - } - - TNC->TXLen = txptr; - WriteCommBlock(TNC); -} - -int DLEEncode(UCHAR * inbuff, UCHAR * outbuff, int len) -{ - int i, txptr = 0; - UCHAR c; - - // Escape x80 and x81 with x81 - -// outbuff[0] = 0x80; -// outbuff[1] = 0x33; // Send data to modem - - for (i=0;i<len;i++) - { - c=inbuff[i]; - - switch (c) - { - case 0x80: - case 0x81: - - outbuff[txptr++] = 0x81; - } - outbuff[txptr++] = c; - } - - return txptr; - -} - -VOID TidyClose(struct TNCINFO * TNC, int Stream) -{ - SendCmd(TNC, "\x07", 1); // Tidy Disconnect -} - -VOID ForcedClose(struct TNCINFO * TNC, int Stream) -{ - SendCmd(TNC, "\x06", 1); // Hard Disconnect -} - -VOID CloseComplete(struct TNCINFO * TNC, int Stream) -{ - TNC->NeedPACTOR = 30; -} - - - - +/*
+Copyright 2001-2018 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
+*/
+
+//
+// DLL to inteface HAL Communications Corp Clover/Pacor controllers to BPQ32 switch
+//
+// Uses BPQ EXTERNAL interface
+//
+
+#define _CRT_SECURE_NO_WARNINGS
+#define _CRT_SECURE_NO_DEPRECATE
+
+#include "time.h"
+
+#include "CHeaders.h"
+#include "tncinfo.h"
+
+#include "bpq32.h"
+
+#define HAL 1
+
+#define SetMYCALL 0x13
+#define ConnectEnable 0x52
+#define ConnectDisable 0x42
+#define SetEAS 0x59 // Echo as Sent
+#define SetTones 0xec
+#define ClearOnDisc 0x57
+
+static char ClassName[]="HALSTATUS";
+
+static char WindowTitle[] = "HAL";
+static int RigControlRow = 185;
+
+struct TNCINFO * TNCInfo[34]; // Records are Malloc'd
+
+#define SOH 0x01 // CONTROL CODES
+#define ETB 0x17
+#define DLE 0x10
+
+//int MaxStreams = 0;
+
+#ifndef LINBPQ
+extern HFONT hFont;
+#endif
+
+static char status[23][50] = {"IDLE", "TFC", "RQ", "ERR", "PHS", "OVER", "FSK TX",
+ "FSK RX", "P-MODE100", "P-MODE200", "HUFMAN ON", "HUFMAN OFF", "P-MODE SBY(LISTEN ON)",
+ "P-MODE SBY(LISTEN OFF)", "ISS", "IRS",
+ "AMTOR SBY(LISTEN ON)", "AMTOR SBY(LISTEN OFF)", "AMTOR FEC TX", "AMTOR FEC RX", "P-MODE FEC TX",
+ "FREE SIGNAL TX (AMTOR)", "FREE SIGNAL TX TIMED OUT (AMTOR)"};
+
+struct TNCINFO * CreateTTYInfo(int port, int speed);
+BOOL OpenConnection(int);
+BOOL SetupConnection(int);
+static BOOL WriteCommBlock(struct TNCINFO * TNC);
+static void CheckRX(struct TNCINFO * TNC);
+VOID HALPoll(int Port);
+VOID ProcessDEDFrame(struct TNCINFO * TNC, UCHAR * rxbuff, int len);
+VOID ProcessTermModeResponse(struct TNCINFO * TNC);
+static VOID DoTNCReinit(struct TNCINFO * TNC);
+VOID DoTermModeTimeout(struct TNCINFO * TNC);
+VOID ProcessHALBuffer(struct TNCINFO * TNC, int Length);
+VOID ProcessHALCmd(struct TNCINFO * TNC);
+VOID ProcessHALData(struct TNCINFO * TNC);
+VOID ProcessKHOSTPacket(struct TNCINFO * TNC, UCHAR * rxbuffer, int Len);
+VOID ProcessKNormCommand(struct TNCINFO * TNC, UCHAR * rxbuffer);
+VOID ProcessHostFrame(struct TNCINFO * TNC, UCHAR * rxbuffer, int Len);
+VOID DoMonitor(struct TNCINFO * TNC, UCHAR * Msg, int Len);
+
+BOOL HALConnected(struct TNCINFO * TNC, char * Call);
+VOID HALDisconnected(struct TNCINFO * TNC);
+
+static VOID EncodeAndSend(struct TNCINFO * TNC, UCHAR * txbuffer, int Len);
+VOID SendCmd(struct TNCINFO * TNC, UCHAR * txbuffer, int Len);
+int DLEEncode(UCHAR * inbuff, UCHAR * outbuff, int len);
+int DLEDecode(UCHAR * inbuff, UCHAR * outbuff, int len);
+
+VOID COMClearDTR(HANDLE fd);
+VOID COMClearRTS(HANDLE fd);
+int DoScanLine(struct TNCINFO * TNC, char * Buff, int Len);
+
+
+
+//static HANDLE LogHandle[4] = {INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE};
+
+//char * Logs[4] = {"1", "2", "3", "4"};
+
+//char BaseDir[]="c:";
+
+static VOID CloseLogfile(int Flags)
+{
+// CloseHandle(LogHandle[Flags]);
+// LogHandle[Flags] = INVALID_HANDLE_VALUE;
+}
+
+static VOID OpenLogfile(int Flags)
+{
+/*
+UCHAR FN[MAX_PATH];
+ time_t T;
+ struct tm * tm;
+
+ T = time(NULL);
+ tm = gmtime(&T);
+
+ sprintf(FN,"%s\\HALLog_%02d%02d%02d_%s.bin", BaseDir, tm->tm_mday, tm->tm_hour, tm->tm_min, Logs[Flags]);
+
+ LogHandle[Flags] = CreateFile(FN,
+ GENERIC_WRITE,
+ FILE_SHARE_READ,
+ NULL,
+ OPEN_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+
+ SetFilePointer(LogHandle[Flags], 0, 0, FILE_END);
+
+ return (LogHandle[Flags] != INVALID_HANDLE_VALUE);
+*/
+}
+
+static void WriteLogLine(int Flags, char * Msg, int MsgLen)
+{
+// int cnt;
+// WriteFile(LogHandle[Flags] ,Msg , MsgLen, &cnt, NULL);
+}
+
+
+
+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
+
+ ptr = strtok(NULL, " \t\n\r");
+
+ if (_stricmp(buf, "APPL") == 0) // Using BPQ32 COnfig
+ {
+ BPQport = Port;
+ p_cmd = ptr;
+ }
+ else
+ if (_stricmp(buf, "PORT") != 0) // Using Old Config
+ {
+ // New config without a PORT or APPL - this is a Config Command
+
+ strcpy(buf, errbuf);
+ strcat(buf, "\r");
+
+ BPQport = Port;
+
+ TNC = TNCInfo[BPQport] = zalloc(sizeof(struct TNCINFO));
+
+ TNC->InitScript = malloc(1000);
+ TNC->InitScript[0] = 0;
+ goto ConfigLine;
+ }
+ else
+
+ {
+
+ // Old Config from file
+
+ BPQport=0;
+ BPQport = atoi(ptr);
+
+ p_cmd = strtok(NULL, " \t\n\r");
+
+ if (Port && Port != BPQport)
+ {
+ // Want a particular port, and this isn't it
+
+ while(TRUE)
+ {
+ if (GetLine(buf) == 0)
+ return TRUE;
+
+ if (memcmp(buf, "****", 4) == 0)
+ return TRUE;
+
+ }
+ }
+ }
+ if(BPQport > 0 && BPQport < 33)
+ {
+ TNC = TNCInfo[BPQport] = zalloc(sizeof(struct TNCINFO));
+ TNC->InitScript = malloc(1000);
+ TNC->InitScript[0] = 0;
+
+ if (p_cmd != NULL)
+ {
+ if (p_cmd[0] != ';' && p_cmd[0] != '#')
+ TNC->ApplCmd=_strdup(p_cmd);
+ }
+
+ // Read Initialisation lines
+
+ while(TRUE)
+ {
+ if (GetLine(buf) == 0)
+ return TRUE;
+ConfigLine:
+ strcpy(errbuf, buf);
+
+ if (memcmp(buf, "****", 4) == 0)
+ return TRUE;
+
+ ptr = strchr(buf, ';');
+ if (ptr)
+ {
+ *ptr++ = 13;
+ *ptr = 0;
+ }
+
+ if (_memicmp(buf, "WL2KREPORT", 10) == 0)
+ {
+ TNC->WL2K = DecodeWL2KReportLine(buf);
+ continue;
+ }
+ if (_memicmp(buf, "NEEDXONXOFF", 10) == 0)
+ {
+ TNC->XONXOFF = TRUE;
+ continue;
+ }
+
+ if (_memicmp(buf, "TONES", 5) == 0)
+ {
+ int tone1 = 0, tone2 = 0;
+
+ ptr = strtok(&buf[6], " ,/\t\n\r");
+ if (ptr)
+ {
+ tone1 = atoi(ptr);
+ ptr = strtok(NULL, " ,/\t\n\r");
+ if (ptr)
+ {
+ tone2 = atoi(ptr);
+ ptr = &TNC->InitScript[TNC->InitScriptLen];
+
+ // Try putting into FSK mode first
+
+ *(ptr++) = 0x84;
+ *(ptr++) = SetTones; // Set Tones (Mark, Space HI byte first)
+ *(ptr++) = tone1 >> 8;
+ *(ptr++) = tone1 & 0xff;
+ *(ptr++) = tone2 >> 8;
+ *(ptr++) = tone2 & 0xff;
+
+ TNC->InitScriptLen += 6;
+
+ continue;
+ }
+ }
+ goto BadLine;
+ }
+ if (_memicmp(buf, "DEFAULTMODE ", 12) == 0)
+ {
+
+ ptr = strtok(&buf[12], " ,\t\n\r");
+ if (ptr)
+ {
+ if (_stricmp(ptr, "CLOVER") == 0)
+ TNC->DefaultMode = Clover;
+ else if (_stricmp(ptr, "PACTOR") == 0)
+ TNC->DefaultMode = Pactor;
+ else if (_stricmp(ptr, "AMTOR") == 0)
+ TNC->DefaultMode = AMTOR;
+ else goto BadLine;
+
+ continue;
+ }
+ goto BadLine;
+ }
+ }
+ BadLine:
+ WritetoConsole(" Bad config record ");
+ WritetoConsole(errbuf);
+ WritetoConsole("\r\n");
+ }
+
+ return (TRUE);
+}
+
+static size_t ExtProc(int fn, int port , PDATAMESSAGE buff)
+{
+ int txlen = 0;
+ PMSGWITHLEN buffptr;
+ struct TNCINFO * TNC = TNCInfo[port];
+ struct STREAMINFO * STREAM;
+ int Stream;
+
+ if (TNC == NULL)
+ return 0;
+
+ if (fn < 4 || fn > 5)
+ if (TNC->hDevice == 0)
+ return 0; // Port not open
+
+ STREAM = &TNC->Streams[0];
+
+ switch (fn)
+ {
+ case 1: // poll
+
+ while (TNC->PortRecord->UI_Q) // Release anything accidentally put on UI_Q
+ {
+ buffptr = Q_REM(&TNC->PortRecord->UI_Q);
+ ReleaseBuffer(buffptr);
+ }
+
+ //for (Stream = 0; Stream <= MaxStreams; Stream++)
+ {
+ if (STREAM->ReportDISC)
+ {
+ STREAM->ReportDISC = FALSE;
+ buff->PORT = 0;
+
+ return -1;
+ }
+ }
+
+ CheckRX(TNC);
+ HALPoll(port);
+
+ //for (Stream = 0; Stream <= MaxStreams; Stream++)
+ {
+ if (STREAM->PACTORtoBPQ_Q !=0)
+ {
+ int datalen;
+
+ buffptr=Q_REM(&STREAM->PACTORtoBPQ_Q);
+
+ datalen = (int)buffptr->Len;
+
+ buff->PORT = 0; // 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);
+ }
+ }
+
+ return 0;
+
+ case 2: // send
+
+ buffptr = GetBuff();
+
+ if (buffptr == 0) return (0); // No buffers, so ignore
+
+ // Find TNC Record
+
+ Stream = buff->PORT;
+
+ if (!TNC->TNCOK)
+ {
+ // Send Error Response
+
+ PMSGWITHLEN buffptr = (PMSGWITHLEN)GetBuff();
+
+ if (buffptr == 0) return (0); // No buffers, so ignore
+
+ buffptr->Len = 27;
+ memcpy(&buffptr->Data[0], "No Connection to PACTOR TNC\r", 27);
+
+ C_Q_ADD(&TNC->Streams[Stream].PACTORtoBPQ_Q, buffptr);
+ return 0;
+ }
+
+ txlen = GetLengthfromBuffer(buff) - (sizeof(void *) + 4);
+
+ buffptr->Len = txlen;
+ memcpy(&buffptr->Data[0], &buff->L2DATA[0], txlen);
+
+ C_Q_ADD(&STREAM->BPQtoPACTOR_Q, buffptr);
+
+ STREAM->FramesQueued++;
+
+ return (0);
+
+
+ case 3: // CHECK IF OK TO SEND. Also used to check if TNC is responding
+
+ Stream = (int)(size_t)buff;
+
+ if (STREAM->FramesQueued > 4)
+ return (1 | TNC->HostMode << 8);
+
+ return TNC->HostMode << 8 | STREAM->Disconnecting << 15; // OK, but lock attach if disconnecting
+
+ case 4: // reinit
+
+ return (0);
+
+ case 5: // Close
+
+ CloseCOMPort(TNCInfo[port]->hDevice);
+ return (0);
+
+ case 6: // Scan Control
+
+ return 0; // None Yet
+
+ }
+ 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>"
+ "<head><title>HAL Status</title></head><body><h3>HAL Status</h3>");
+
+ Len += sprintf(&Buff[Len], "<table style=\"text-align: left; width: 480px; font-family: monospace; align=center \" border=1 cellpadding=2 cellspacing=2>");
+
+ Len += sprintf(&Buff[Len], "<tr><td width=90px>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>Status</td><td>%s</td></tr>", TNC->WEB_STATE);
+ Len += sprintf(&Buff[Len], "<tr><td>TX/RX State</td><td>%s</td></tr>", TNC->WEB_TXRX);
+ Len += sprintf(&Buff[Len], "<tr><td>Traffic</td><td>%s</td></tr>", TNC->WEB_TRAFFIC);
+ Len += sprintf(&Buff[Len], "<tr><td>LEDS</td><td>STBY CALL LINK ERROR TX RX</td></tr>");
+ Len += sprintf(&Buff[Len], "<tr><td> </td><td>%s</td></tr>", TNC->WEB_LEDS);
+ Len += sprintf(&Buff[Len], "</table>");
+
+ Len = DoScanLine(TNC, Buff, Len);
+
+ return Len;
+}
+
+
+VOID * HALExtInit(EXTPORTDATA * PortEntry)
+{
+ char msg[500];
+ struct TNCINFO * TNC;
+ int port;
+ char * ptr;
+ int len;
+ char Msg[80];
+#ifndef LINBPQ
+ HWND x;
+#endif
+ //
+ // Will be called once for each Pactor Port
+ // The COM port number is in IOBASE
+ //
+
+ sprintf(msg,"HAL Driver %s", PortEntry->PORTCONTROL.SerialPortName);
+ WritetoConsole(msg);
+
+ 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");
+ WritetoConsole(msg);
+
+ return ExtProc;
+ }
+
+ TNC->Port = port;
+
+ TNC->Hardware = H_HAL;
+
+ TNC->Interlock = PortEntry->PORTCONTROL.PORTINTERLOCK;
+
+ PortEntry->MAXHOSTMODESESSIONS = 1; // Default
+
+ TNC->PortRecord = PortEntry;
+
+ if (PortEntry->PORTCONTROL.PORTCALL[0] == 0)
+ {
+ memcpy(TNC->NodeCall, MYNODECALL, 10);
+ }
+ else
+ {
+ ConvFromAX25(&PortEntry->PORTCONTROL.PORTCALL[0], TNC->NodeCall);
+ }
+
+ PortEntry->PORTCONTROL.PROTOCOL = 10;
+ PortEntry->PORTCONTROL.PORTQUALITY = 0;
+
+ if (PortEntry->PORTCONTROL.PORTPACLEN == 0)
+ PortEntry->PORTCONTROL.PORTPACLEN = 100;
+
+ ptr=strchr(TNC->NodeCall, ' ');
+ if (ptr) *(ptr) = 0; // Null Terminate
+
+ if (TNC->DefaultMode)
+ TNC->CurrentMode = TNC->DefaultMode;
+ else
+ TNC->CurrentMode = Clover;
+
+ TNC->PollDelay = 999999999;
+
+ // Set Disable +?, ExpandedStatus , Channel Stats Off, ClearOnDisc, EAS and MYCALL
+
+ len = sprintf(Msg, "%c%c%c%c%c%c%s", 0xcc, 0x56, 0x41, ClearOnDisc, SetEAS, SetMYCALL, TNC->NodeCall);
+ len++; // We include the NULL
+
+ memcpy(&TNC->InitScript[TNC->InitScriptLen], Msg, len);
+ TNC->InitScriptLen += len;
+
+ PortEntry->PORTCONTROL.TNC = TNC;
+
+ TNC->WebWindowProc = WebProc;
+ TNC->WebWinX = 510;
+ TNC->WebWinY = 280;
+
+ TNC->WEB_COMMSSTATE = zalloc(100);
+ TNC->WEB_TNCSTATE = zalloc(100);
+ strcpy(TNC->WEB_TNCSTATE, "Free");
+ TNC->WEB_MODE = zalloc(100);
+ TNC->WEB_TRAFFIC = zalloc(100);
+ TNC->WEB_BUFFERS = zalloc(100);
+ TNC->WEB_STATE = zalloc(100);
+ TNC->WEB_TXRX = zalloc(100);
+ TNC->WEB_LEDS = zalloc(100);
+ strcpy(TNC->WEB_LEDS, " X X X X X X");
+
+#ifndef LINBPQ
+
+ CreatePactorWindow(TNC, ClassName, WindowTitle, RigControlRow, PacWndProc, 500, 233, ForcedClose);
+
+ x = CreateWindowEx(0, "STATIC", "Comms State", WS_CHILD | WS_VISIBLE, 10,6,120,20, TNC->hDlg, NULL, hInstance, NULL);
+ x = TNC->xIDC_COMMSSTATE = CreateWindowEx(0, "STATIC", "", WS_CHILD | WS_VISIBLE, 116,6,386,20, TNC->hDlg, NULL, hInstance, NULL);
+
+ x = CreateWindowEx(0, "STATIC", "TNC State", WS_CHILD | WS_VISIBLE, 10,28,106,20, TNC->hDlg, NULL, hInstance, NULL);
+ x = TNC->xIDC_TNCSTATE = CreateWindowEx(0, "STATIC", "", WS_CHILD | WS_VISIBLE, 116,28,520,20, TNC->hDlg, NULL, hInstance, NULL);
+
+ x = CreateWindowEx(0, "STATIC", "Mode", WS_CHILD | WS_VISIBLE, 10,50,80,20, TNC->hDlg, NULL, hInstance, NULL);
+ x = TNC->xIDC_MODE = CreateWindowEx(0, "STATIC", "", WS_CHILD | WS_VISIBLE, 116,50,200,20, TNC->hDlg, NULL, hInstance, NULL);
+
+ x = CreateWindowEx(0, "STATIC", "Status", WS_CHILD | WS_VISIBLE, 10,72,110,20, TNC->hDlg, NULL, hInstance, NULL);
+ x = TNC->xIDC_STATE = CreateWindowEx(0, "STATIC", "", WS_CHILD | WS_VISIBLE, 116,72,144,20, TNC->hDlg, NULL, hInstance, NULL);
+
+ x = CreateWindowEx(0, "STATIC", "TX/RX State", WS_CHILD | WS_VISIBLE,10,94,80,20, TNC->hDlg, NULL, hInstance, NULL);
+ x = TNC->xIDC_TXRX = CreateWindowEx(0, "STATIC", "", WS_CHILD | WS_VISIBLE,116,94,374,20 , TNC->hDlg, NULL, hInstance, NULL);
+
+ x = CreateWindowEx(0, "STATIC", "Traffic", WS_CHILD | WS_VISIBLE,10,116,80,20, TNC->hDlg, NULL, hInstance, NULL);
+ x = TNC->xIDC_TRAFFIC = CreateWindowEx(0, "STATIC", "RX 0 TX 0 ACKED 0", WS_CHILD | WS_VISIBLE,116,116,374,20 , TNC->hDlg, NULL, hInstance, NULL);
+
+ x = CreateWindowEx(0, "STATIC", "LEDS", WS_CHILD | WS_VISIBLE,10,138,60,20, TNC->hDlg, NULL, hInstance, NULL);
+ SendMessage(x, WM_SETFONT, (WPARAM)hFont, 0);
+ x = CreateWindowEx(0, "STATIC", "STBY CALL LINK ERROR TX RX", WS_CHILD | WS_VISIBLE,116,138,280,20, TNC->hDlg, NULL, hInstance, NULL);
+ SendMessage(x, WM_SETFONT, (WPARAM)hFont, 0);
+ x = TNC->xIDC_LEDS = CreateWindowEx(0, "STATIC", " X X X X X X", WS_CHILD | WS_VISIBLE,116,158,280,20 , TNC->hDlg, NULL, hInstance, NULL);
+ SendMessage(x, WM_SETFONT, (WPARAM)hFont, 0);
+
+ TNC->ClientHeight = 233;
+ TNC->ClientWidth = 500;
+
+ MoveWindows(TNC);
+#endif
+
+ OpenCOMMPort(TNC, PortEntry->PORTCONTROL.SerialPortName, PortEntry->PORTCONTROL.BAUDRATE, FALSE);
+
+ SendCmd(TNC, "\x09" , 1); // Reset
+
+ WritetoConsole("\n");
+
+ return ExtProc;
+}
+
+
+
+static VOID KISSCLOSE(int Port)
+{
+ struct TNCINFO * conn = TNCInfo[Port];
+
+ // drop DTR and RTS
+
+ COMClearDTR(conn->hDevice);
+ COMClearRTS(conn->hDevice);
+
+ // purge any outstanding reads/writes and close device handle
+
+ CloseCOMPort(conn->hDevice);
+
+ return;
+}
+
+
+static void CheckRX(struct TNCINFO * TNC)
+{
+ int Length, Len;
+ UCHAR * Xptr;
+
+ // only try to read number of bytes in queue
+
+ if (TNC->RXLen == 500)
+ TNC->RXLen = 0;
+
+ Len = ReadCOMBlock(TNC->hDevice, &TNC->RXBuffer[TNC->RXLen], 500 - TNC->RXLen);
+
+ if (Len == 0)
+ return;
+
+ TNC->RXLen += Len;
+
+ Length = TNC->RXLen;
+
+ // We need to konw whether data is received or echoed, so we can't split commands and data here.
+ // Pass everything to the Command Handler. It will check that there are enough bytes for the command,
+ // and wait for more if not.
+
+ // The USB version also uses 0x91 0x31 to eacape 0x11, 0x91 0x33 for 0x13 and 0x91 0xB1 for 0x91
+
+ // If USB version, we might get unescaped xon and xoff, which we must ignore
+
+ if (TNC->XONXOFF)
+ {
+ Xptr = memchr(&TNC->RXBuffer, 0x11, Length);
+
+ while(Xptr)
+ {
+ Debugprintf("XON Port %d", TNC->Port);
+ memmove(Xptr, Xptr + 1, Length-- - (TNC->RXBuffer - Xptr));
+ Xptr = memchr(&TNC->RXBuffer, 0x11, Length);
+ }
+
+ Xptr = memchr(&TNC->RXBuffer, 0x13, Length);
+
+ while(Xptr)
+ {
+ Debugprintf("XOFF Port %d", TNC->Port);
+ memmove(Xptr, Xptr + 1, Length-- - (TNC->RXBuffer - Xptr));
+ Xptr = memchr(&TNC->RXBuffer, 0x13, Length);
+ }
+
+ Xptr = memchr(&TNC->RXBuffer, 0x91, Length); // See if packet contains 0x91 escape
+
+ if (Xptr)
+
+ // Make sure we have the escaped char as well
+
+ if ((Xptr - &TNC->RXBuffer[0]) == Length - 1) // x91 is last char
+ return;
+ }
+
+ ProcessHALBuffer(TNC, Length);
+
+ TNC->RXLen = 0;
+
+ return;
+
+}
+
+
+
+static BOOL WriteCommBlock(struct TNCINFO * TNC)
+{
+ WriteCOMBlock(TNC->hDevice, TNC->TXBuffer, TNC->TXLen);
+ return TRUE;
+}
+
+VOID HALPoll(int Port)
+{
+ struct TNCINFO * TNC = TNCInfo[Port];
+ struct STREAMINFO * STREAM = &TNC->Streams[0];
+
+ UCHAR * Poll = TNC->TXBuffer;
+ char Status[80];
+ UCHAR TXMsg[1000];
+ int datalen;
+
+ if (TNC->Timeout)
+ {
+ TNC->Timeout--;
+
+ if (TNC->Timeout) // Still waiting
+ return;
+
+ // Timed Out
+
+ TNC->TNCOK = FALSE;
+ TNC->HostMode = 0;
+
+ sprintf(TNC->WEB_COMMSSTATE,"%s Open but TNC not responding", TNC->PortRecord->PORTCONTROL.SerialPortName);
+ MySetWindowText(TNC->xIDC_COMMSSTATE, TNC->WEB_COMMSSTATE);
+
+ //for (Stream = 0; Stream <= MaxStreams; Stream++)
+ {
+ if (TNC->PortRecord->ATTACHEDSESSIONS[0]) // Connected
+ {
+ STREAM->Connected = FALSE; // Back to Command Mode
+ STREAM->ReportDISC = TRUE; // Tell Node
+ }
+ }
+
+ }
+
+ // if we have just restarted or TNC appears to be in terminal mode, run Initialisation Sequence
+
+ if (TNC->TNCOK)
+ if (!TNC->HostMode)
+ {
+ DoTNCReinit(TNC);
+ return;
+ }
+
+ if (TNC->PortRecord->ATTACHEDSESSIONS[0] && STREAM->Attached == 0)
+ {
+ // New Attach
+
+ int calllen;
+ char Msg[80];
+
+ STREAM->Attached = TRUE;
+
+ STREAM->BytesRXed = STREAM->BytesTXed = STREAM->BytesAcked = 0;
+
+ calllen = ConvFromAX25(TNC->PortRecord->ATTACHEDSESSIONS[0]->L4USER, STREAM->MyCall);
+ STREAM->MyCall[calllen] = 0;
+
+ datalen = sprintf(TXMsg, "%c%s", SetMYCALL, STREAM->MyCall);
+ SendCmd(TNC, TXMsg, datalen + 1); // Send the NULL
+
+ sprintf(TNC->WEB_TNCSTATE, "In Use by %s", STREAM->MyCall);
+ MySetWindowText(TNC->xIDC_TNCSTATE, TNC->WEB_TNCSTATE);
+
+ // Stop Scanning
+
+ sprintf(Msg, "%d SCANSTOP", TNC->Port);
+
+ Rig_Command(-1, Msg);
+
+ SendCmd(TNC, "\x42", 1); // Connect Enable off
+
+ return;
+
+ }
+
+ //for (Stream = 0; Stream <= MaxStreams; Stream++)
+
+ if (STREAM->Attached)
+ CheckForDetach(TNC, 0, STREAM, TidyClose, ForcedClose, CloseComplete);
+
+ if (TNC->NeedPACTOR)
+ {
+ TNC->NeedPACTOR--;
+
+ if (TNC->NeedPACTOR == 0)
+ {
+ int datalen;
+
+ UCHAR TXMsg[80];
+
+ datalen = sprintf(TXMsg, "%c%s", SetMYCALL, TNC->NodeCall);
+ SendCmd(TNC, TXMsg, datalen + 1); // Send the NULL
+
+ // Set Listen Mode
+
+ switch (TNC->CurrentMode)
+ {
+ case Pactor:
+
+ SendCmd(TNC, "\x84", 1); // FSK
+ SendCmd(TNC, "\x83", 1); // Select P-MODE Standby
+ SendCmd(TNC, "\x58", 1); // Listen
+
+ break;
+
+ case Clover:
+
+ SendCmd(TNC, "\x80", 1); // Clover
+ SendCmd(TNC, "\x54", 1); // Enable adaptive Clover format
+ SendCmd(TNC, "\x41", 1); // No Statistics
+ SendCmd(TNC, "\x60\x09", 2); // Robust Retries
+ SendCmd(TNC, "\x61\x09", 2); // Normal Retries
+
+ break;
+ }
+
+ SendCmd(TNC, "\x52", 1); // ConnectEnable
+
+ // Restart Scanning
+
+ sprintf(Status, "%d SCANSTART 15", TNC->Port);
+
+ Rig_Command(-1, Status);
+
+ return;
+ }
+ }
+
+#define MAXHALTX 256
+
+ //for (Stream = 0; Stream <= MaxStreams; Stream++)
+ {
+ if (TNC->TNCOK && STREAM->BPQtoPACTOR_Q && (STREAM->BytesTXed - STREAM->BytesAcked < 600))
+ {
+ int datalen;
+ UINT * buffptr;
+ UCHAR * MsgPtr;
+ unsigned char TXMsg[500];
+
+ buffptr = (UINT * )STREAM->BPQtoPACTOR_Q;
+ datalen=buffptr[1];
+ MsgPtr = (UCHAR *)&buffptr[2];
+
+ if (STREAM->Connected)
+ {
+ if (TNC->SwallowSignon)
+ {
+ TNC->SwallowSignon = FALSE;
+ if (strstr(MsgPtr, "Connected")) // Discard *** connected
+ {
+ ReleaseBuffer(buffptr);
+ STREAM->FramesQueued--;
+ return;
+ }
+ }
+
+ // Must send data in small chunks - the Hal has limited buffer space
+
+ // If in IRS force a turnround
+
+ if (TNC->TXRXState == 'R' && TNC->CurrentMode != Clover)
+ {
+ if (TNC->TimeInRX++ > 15)
+ SendCmd(TNC, "\x87", 1); // Changeover to ISS
+ else
+ goto Poll;
+ }
+
+ TNC->TimeInRX = 0;
+
+ EncodeAndSend(TNC, MsgPtr, datalen);
+ buffptr=Q_REM(&STREAM->BPQtoPACTOR_Q);
+ ReleaseBuffer(buffptr);
+ WriteLogLine(2, MsgPtr, datalen);
+
+ STREAM->BytesTXed += datalen;
+ STREAM->FramesQueued--;
+
+ ShowTraffic(TNC);
+
+ return;
+ }
+ else
+ {
+ buffptr=Q_REM(&STREAM->BPQtoPACTOR_Q);
+ STREAM->FramesQueued--;
+
+ // Command. Do some sanity checking and look for things to process locally
+
+ datalen--; // Exclude CR
+ MsgPtr[datalen] = 0; // Null Terminate
+ _strupr(MsgPtr);
+
+ if (memcmp(MsgPtr, "RADIO ", 6) == 0)
+ {
+ sprintf(&MsgPtr[40], "%d %s", TNC->Port, &MsgPtr[6]);
+ if (Rig_Command(TNC->PortRecord->ATTACHEDSESSIONS[0]->L4CROSSLINK->CIRCUITINDEX, &MsgPtr[40]))
+ {
+ ReleaseBuffer(buffptr);
+ }
+ else
+ {
+ buffptr[1] = sprintf((UCHAR *)&buffptr[2], "%s", &MsgPtr[40]);
+ C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr);
+ }
+ return;
+ }
+
+ if (memcmp(MsgPtr, "MODE CLOVER", 11) == 0)
+ {
+ TNC->CurrentMode = Clover;
+ buffptr[1] = sprintf((UCHAR *)&buffptr[2],"HAL} Ok\r");
+ C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr);
+
+ MySetWindowText(TNC->xIDC_MODE, "Clover");
+ strcpy(TNC->WEB_MODE, "Clover");
+
+ SendCmd(TNC, "\x80", 1); // Clover
+ SendCmd(TNC, "\x54", 1); // Enable adaptive Clover format
+ SendCmd(TNC, "\x41", 1); // No Statistics
+
+ return;
+ }
+
+ if (memcmp(MsgPtr, "MODE PACTOR", 11) == 0)
+ {
+ TNC->CurrentMode = Pactor;
+ buffptr[1] = sprintf((UCHAR *)&buffptr[2],"HAL} Ok\r");
+ C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr);
+
+ SendCmd(TNC, "\x84", 1); // FSK
+ SendCmd(TNC, "\x83", 1); // Select P-MODE Standby
+ SendCmd(TNC, "\x48", 1); // Listen Off
+
+ return;
+ }
+ if (memcmp(MsgPtr, "MODE AMTOR", 11) == 0)
+ {
+ TNC->CurrentMode = AMTOR;
+ buffptr[1] = sprintf((UCHAR *)&buffptr[2],"HAL} Ok\r");
+ C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr);
+
+ return;
+ }
+
+ if (MsgPtr[0] == 'C' && MsgPtr[1] == ' ' && datalen > 2) // Connect
+ {
+ memcpy(STREAM->RemoteCall, &MsgPtr[2], 9);
+
+ switch (TNC->CurrentMode)
+ {
+ case Pactor:
+
+ SendCmd(TNC, "\x84", 1); // FSK
+ SendCmd(TNC, "\x83", 1); // Select P-MODE Standby
+
+ datalen = sprintf(TXMsg, "\x19%s", STREAM->RemoteCall);
+
+ sprintf(TNC->WEB_TNCSTATE, "%s Connecting to %s - PACTOR", STREAM->MyCall, STREAM->RemoteCall);
+
+ // DOnt set connecting till we get the 19 response so we can trap listen as a fail
+ break;
+
+ case Clover:
+
+ SendCmd(TNC, "\x54", 1); // Enable adaptive Clover format
+ SendCmd(TNC, "\x57", 1); // Enable TX buffer clear on disconnect
+
+ datalen = sprintf(TXMsg, "\x11%s", STREAM->RemoteCall);
+
+ sprintf(TNC->WEB_TNCSTATE, "%s Connecting to %s - CLOVER", STREAM->MyCall, STREAM->RemoteCall);
+
+ break;
+ }
+
+ MySetWindowText(TNC->xIDC_TNCSTATE, TNC->WEB_TNCSTATE);
+ SendCmd(TNC, TXMsg, datalen + 1); // Include NULL
+
+ ReleaseBuffer(buffptr);
+
+ return;
+ }
+
+ if (memcmp(MsgPtr, "CLOVER ", 7) == 0)
+ {
+ memcpy(STREAM->RemoteCall, &MsgPtr[2], 9);
+
+ SendCmd(TNC, "\x54", 1); // Enable adaptive Clover format
+ SendCmd(TNC, "\x57", 1); // Enable TX buffer clear on disconnect
+
+ datalen = sprintf(TXMsg, "\x11%s", STREAM->RemoteCall);
+ SendCmd(TNC, TXMsg, datalen + 1); // Include NULL
+
+ sprintf(TNC->WEB_TNCSTATE, "%s Connecting to %s - CLOVER",
+ STREAM->MyCall, STREAM->RemoteCall);
+ MySetWindowText(TNC->xIDC_TNCSTATE, TNC->WEB_TNCSTATE);
+
+ ReleaseBuffer(buffptr);
+
+ return;
+ }
+
+ if (memcmp(MsgPtr, "DISCONNECT", datalen) == 0) // Disconnect
+ {
+ SendCmd(TNC, "\x07", 1); // Normal Disconnect
+ TNC->NeedPACTOR = 50;
+
+ STREAM->Connecting = FALSE;
+ STREAM->ReportDISC = TRUE;
+ ReleaseBuffer(buffptr);
+
+ return;
+ }
+
+ // Other Command ?? Treat as HEX string
+
+ datalen = sscanf(MsgPtr, "%X %X %X %X %X %X %X %X %X %X %X %X %X %X %X %X",
+ (UINT *)&TXMsg[0], (UINT *)&TXMsg[1], (UINT *)&TXMsg[2], (UINT *)&TXMsg[3], (UINT *)&TXMsg[4],
+ (UINT *)&TXMsg[5], (UINT *)&TXMsg[6], (UINT *)&TXMsg[7], (UINT *)&TXMsg[8], (UINT *)&TXMsg[9],
+ (UINT *)&TXMsg[10], (UINT *)&TXMsg[11], (UINT *)&TXMsg[12], (UINT *)&TXMsg[13],
+ (UINT *)&TXMsg[14], (UINT *)&TXMsg[15]);
+
+// SendCmd(TNC, TXMsg, datalen);
+ ReleaseBuffer(buffptr);
+ TNC->InternalCmd = 0;
+ }
+ }
+ }
+Poll:
+ // Nothing doing - send Poll (but not too often)
+
+ TNC->PollDelay++;
+
+ if (TNC->PollDelay < 20)
+ return;
+
+ TNC->PollDelay = 0;
+
+ if (TNC->TNCOK)
+ SendCmd(TNC, "\x7d" , 1); // Use Get LEDS as Poll
+ else
+ SendCmd(TNC, "\x09" , 1); // Reset
+
+ TNC->Timeout = 100;
+
+ return;
+}
+
+static VOID DoTNCReinit(struct TNCINFO * TNC)
+{
+ // TNC Has Restarted, send init commands (can probably send all at once)
+
+// TNC->TXBuffer[0] = 0x1b;
+// TNC->TXLen = 1;
+
+ WriteCommBlock(TNC);
+
+ SendCmd(TNC, TNC->InitScript, TNC->InitScriptLen);
+
+ TNC->HostMode = TRUE; // Should now be in Host Mode
+ TNC->NeedPACTOR = 20; // Need to set Calls and start scan
+
+ TNC->DataMode = RXDATA; // Start with RX Data
+
+ SendCmd(TNC, "\x7d" , 1); // Use Get LEDS as Poll
+// SendCmd(TNC, "\xc9" , 1); // Huffman Off
+ SendCmd(TNC, "\x57", 1); // Enable TX buffer clear on disconnect
+
+ SendCmd(TNC, "\x60\x06", 2); // Robust Mode Retries
+
+// SendCmd(TNC, "\x6f\x03" , 2); // Undocumented XON/XOFF On - used to see if old or new style modem
+
+ TNC->Timeout = 50;
+
+ return;
+
+}
+
+VOID ProcessHALData(struct TNCINFO * TNC)
+{
+ // Received Data just pass to Appl
+
+ UINT * buffptr;
+ int Len = TNC->DataLen;
+ struct STREAMINFO * STREAM = &TNC->Streams[0];
+
+ TNC->DataLen = 0;
+
+ if (TNC->DataMode == TXDATA)
+ {
+ STREAM->BytesAcked += Len;
+// Debugprintf("Acked %d", Len);
+
+ if (STREAM->BytesAcked > STREAM->BytesTXed)
+ Debugprintf("Too Much Acked");
+
+ if ((STREAM->BPQtoPACTOR_Q == 0) && STREAM->BytesAcked >= STREAM->BytesTXed)
+ {
+ // All sent
+
+ if (STREAM->Disconnecting)
+ TidyClose(TNC, 0);
+ else
+ if (TNC->CurrentMode != Clover)
+
+ // turn round link
+
+ SendCmd(TNC, "\x0c" , 1); // Turnround
+
+ }
+ }
+ else
+ {
+ if (TNC->DataMode == RXDATA)
+ {
+// Debugprintf("RXed %d", Len);
+ buffptr = GetBuff();
+ if (buffptr == NULL)
+ return; // No buffers, so ignore
+
+ buffptr[1] = Len; // Length
+
+ WriteLogLine(1, TNC->DataBuffer, Len);
+
+ STREAM->BytesRXed += Len;
+
+ memcpy(&buffptr[2], TNC->DataBuffer, Len);
+
+ C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr);
+ }
+ }
+
+ ShowTraffic(TNC);
+
+ return;
+}
+
+
+
+VOID ProcessHALBuffer(struct TNCINFO * TNC, int Length)
+{
+ UCHAR Char;
+ UCHAR * inptr;
+ UCHAR * cmdptr;
+ UCHAR * dataptr;
+ BOOL CmdEsc, DataEsc;
+
+ inptr = TNC->RXBuffer;
+
+ cmdptr = &TNC->CmdBuffer[TNC->CmdLen];
+ dataptr = &TNC->DataBuffer[TNC->DataLen];
+ CmdEsc = TNC->CmdEsc;
+ DataEsc = TNC->DataEsc;
+
+ // HAL uses HEX 80 as a command escape, 81 to ESCAPE 80 and 81
+
+ // The USB version also uses 0x91 0x31 to eacape 0x11, 0x91 0x33 for 0x13 and 0x91 0xB1 for 0x91
+
+ // Command Responses can be variable length
+
+ // Command Handler will check for each command/response if it has enough - if not it will wait till more arrives
+
+ while(Length--)
+ {
+ Char = *(inptr++);
+
+ if (CmdEsc)
+ {
+ CmdEsc = FALSE;
+
+ if (TNC->XONXOFF && Char == 0x91)
+ {
+ // XON/XOFF escape. We ensured above that data follows so we can process it inline
+
+ Length--;
+ Char = *(inptr++) - 0x20;
+ }
+ *(cmdptr++) = Char;
+ }
+ else if (DataEsc)
+ {
+ DataEsc = FALSE;
+ goto DataChar;
+ }
+ else
+NotData:
+ if (Char == 0x80) // Next Char is Command
+ CmdEsc = TRUE;
+ else if (Char == 0x81) // Next Char is escaped data (80 or 81)
+ DataEsc = TRUE;
+ else
+ {
+ // This is a Data Char. We must process any Commands received so far, so we know the type of data
+
+ DataChar:
+
+ TNC->CmdLen = (int)(cmdptr - TNC->CmdBuffer);
+ ProcessHALCmd(TNC);
+ cmdptr = &TNC->CmdBuffer[TNC->CmdLen];
+ dataptr = &TNC->DataBuffer[TNC->DataLen];
+
+ *(dataptr++) = Char; // Normal Data
+
+ // Now process any other data chars
+
+ while(Length--)
+ {
+ Char = *(inptr++);
+
+ if (TNC->XONXOFF && Char == 0x91)
+ {
+ // XON/XOFF escape within data. We ensured above that data follows so we
+ // can process it here
+
+ Length--;
+ Char = *(inptr++) - 0x20;
+ }
+
+ if (Char == 0x80 || Char == 0x81)
+ {
+ // Process any data we have, then loop back
+
+ TNC->DataLen = (int)(dataptr - TNC->DataBuffer);
+ ProcessHALData(TNC);
+
+ goto NotData;
+ }
+ *(dataptr++) = Char; // Normal Data
+ }
+
+ // Used all data
+
+ TNC->DataLen = (int)(dataptr - TNC->DataBuffer);
+
+ ProcessHALData(TNC);
+ TNC->CmdEsc = CmdEsc;
+ TNC->DataEsc = DataEsc;
+
+ return;
+ }
+ }
+
+ // Save State
+
+ TNC->CmdLen = (int)(cmdptr - TNC->CmdBuffer);
+
+ TNC->CmdEsc = CmdEsc;
+ TNC->DataEsc = DataEsc;
+
+ if (TNC->DataLen)
+ ProcessHALData(TNC);
+
+ if (TNC->CmdLen)
+ ProcessHALCmd(TNC);
+}
+
+VOID mySetWindowText(struct TNCINFO * TNC, char * Msg)
+{
+ MySetWindowText(TNC->xIDC_STATE, Msg);
+ strcpy(TNC->WEB_STATE, Msg);
+}
+
+VOID ProcessHALCmd(struct TNCINFO * TNC)
+{
+ char * Call;
+ int Stream = 0;
+ int Opcode;
+ int StatusByte;
+ int Leds;
+ int Len;
+ int Used;
+ struct STREAMINFO * STREAM = &TNC->Streams[0];
+
+CmdLoop:
+
+ Opcode = TNC->CmdBuffer[0];
+ Len = TNC->CmdLen;
+
+ if (Len == 0)
+ return;
+
+ TNC->TNCOK = TRUE;
+ TNC->Timeout = 0;
+
+ sprintf(TNC->WEB_COMMSSTATE,"%s TNC link OK", TNC->PortRecord->PORTCONTROL.SerialPortName);
+ MySetWindowText(TNC->xIDC_COMMSSTATE, TNC->WEB_COMMSSTATE);
+
+ // We may have more than one response in the buffer, and only each cmd/response decoder knows how many it needs
+
+ switch(Opcode)
+ {
+ case 0x09: //Hardware Reset - equivalent to power on reset
+
+ // Hardware has reset - need to reinitialise
+
+ TNC->HostMode = 0; // Force Reinit
+
+ Used = 1;
+ break;
+
+ case 0x7a: // FSK Modes Status
+
+ // Mixture of mode and state - eg listen huffman on/off irs/iss, so cant just display
+
+ if (Len < 2) return; // Wait for more
+
+ StatusByte = TNC->CmdBuffer[1];
+
+ switch (StatusByte)
+ {
+ case 0x06: // FSK TX (RTTY)
+ case 0x07: // FSK RX (RTTY)
+ case 0x10: // AMTOR STANDBY (LISTEN ON)
+ case 0x11: // AMTOR STANDBY (LISTEN OFF)
+ case 0x12: // AMTOR FEC TX (AMTOR)
+ case 0x13: // AMTOR FEC RX (AMTOR)
+ case 0x14: // P-MODE FEC TX (P-MODE)
+ case 0x15: // FREE SIGNAL TX (AMTOR)
+ case 0x16: // FREE SIGNAL TX TIMED OUT (AMTOR)
+
+ // Diaplay Linke Status
+
+ MySetWindowText(TNC->xIDC_MODE, status[StatusByte]);
+ strcpy(TNC->WEB_MODE, status[StatusByte]);
+
+ break;
+
+ case 0x0C: // P-MODE STANDBY (LISTEN ON)
+ case 0x0D: // P-MODE STANDBY (LISTEN OFF)
+
+ // if we were connecting, this means connect failed.
+
+ MySetWindowText(TNC->xIDC_MODE, status[StatusByte]);
+ strcpy(TNC->WEB_MODE, status[StatusByte]);
+
+ if (STREAM->Connecting)
+ HALDisconnected(TNC);
+
+ break;
+
+ case 0x0E: // ISS (AMTOR/P-MODE)
+
+ MySetWindowText(TNC->xIDC_TXRX,"ISS");
+ strcpy(TNC->WEB_TXRX, "ISS");
+ TNC->TXRXState = 'S';
+ break;
+
+ case 0x0F: // IRS (AMTOR/P-MODE)
+
+ MySetWindowText(TNC->xIDC_TXRX,"IRS");
+ strcpy(TNC->WEB_TXRX, "IRS");
+ TNC->TXRXState = 'R';
+ break;
+
+ case 0x00: // IDLE (AMTOR/P-MODE)
+ case 0x01: // TFC (AMTOR/P-MODE)
+ case 0x02: // RQ (AMTOR/P-MODE)
+ case 0x03: // ERR (AMTOR/P-MODE)
+ case 0x04: // PHS (AMTOR/P-MODE)
+ case 0x05: // OVER (AMTOR/P-MODE) (not implemented)
+
+ MySetWindowText(TNC->xIDC_STATE, status[StatusByte]);
+ strcpy(TNC->WEB_MODE, status[StatusByte]);
+
+
+
+//$807A $8008 P-MODE100 (P-MODE)
+//$807A $8009 P-MODE200 (P-MODE)
+//$807A $800A HUFFMAN ON (P-MODE)
+//$807A $800B HUFFMAN OFF (P-MODE)
+ ;
+ }
+ Used = 2;
+ break;
+
+
+ case 0x7d: // Get LED Status
+
+ // We use Get LED Status as a Poll
+
+ if (Len < 2) return; // Wait for more
+
+ Leds = TNC->CmdBuffer[1];
+ sprintf(TNC->WEB_LEDS," %c %c %c %c %c %c ",
+ (Leds & 0x20)? 'X' : ' ',
+ (Leds & 0x10)? 'X' : ' ',
+ (Leds & 0x08)? 'X' : ' ',
+ (Leds & 0x04)? 'X' : ' ',
+ (Leds & 0x02)? 'X' : ' ',
+ (Leds & 0x01)? 'X' : ' ');
+
+// STBY CALL LINK ERROR TX RX
+ MySetWindowText(TNC->xIDC_LEDS, TNC->WEB_LEDS);
+
+ Used = 2;
+ break;
+
+ case 0x21: // Monitored FEC CCB
+ case 0x22: // Monitored ARQ CCB
+
+ // As the reply is variable, make sure we have the terminating NULL
+
+ if (memchr(TNC->CmdBuffer, 0, Len) == NULL)
+ return; // Wait for more
+
+ Call = &TNC->CmdBuffer[1];
+ Used = (int)strlen(Call) + 2; // Opcode and Null
+
+ UpdateMH(TNC, Call, '!', 0);
+
+ break;
+
+ case 0x27: // Clover ARQ LINK REQUEST status message
+
+ //indicates an incoming link request to either MYCALL ($8027 $8000), or MYALTCALL ($8027 $8001).
+
+ if (Len < 2) return; // Wait for more
+
+ // Don't need to do anything (but may eventally use ALTCALL as an APPLCALL
+ Used = 2;
+ break;
+
+ case 0x2D: // FSK ARQ Link Request status message
+
+ // $802D $8001 $8000 CLOVER Link Request (not implemented)
+ // $802D $8002 $8000 AMTOR CCIR-476 Link Request
+ // $802D $8003 $8000 AMTOR CCIR-625 Link Request
+ // $802D $8004 $8000 P-MODE Link Request
+
+ if (Len < 3) return; // Wait for more
+
+ // Don't need to do anything (but may save Session type later
+
+ Used = 3;
+ break;
+
+
+ case 0x28: // Monitored Call
+
+ // As the reply is variable, make sure we have the terminating NULL
+
+ if (memchr(TNC->CmdBuffer, 0, Len) == NULL)
+ return; // Wait for more
+
+ Call = &TNC->CmdBuffer[1];
+ Used = strlen(Call) + 2; // Opcode and Null
+
+ // Could possibly be used for APPLCALLS by changing MYCALL when we see a call to one of our calls
+
+ break;
+
+
+ case 0x20: // Clover Linked with - Call Connected
+ case 0x29: // The Linked 476 message indicates the start of a CCIR 476 linked session.
+ case 0x2A: // The Linked 625 message indicates the start of a CCIR 625 linked session to <CALL>.
+ case 0x2B: // P-MODE link to
+
+ // As the reply is variable, make sure we have the terminating NULL
+
+ if (memchr(TNC->CmdBuffer, 0, Len) == NULL)
+ return; // Wait for more
+
+ Call = &TNC->CmdBuffer[1];
+ Used = (int)strlen(Call) + 2; // Opcode and Null
+
+ HALConnected(TNC, Call);
+
+ break;
+
+ case 0x23: // Normal Disconnected - followed by $8000
+ case 0x24: // Link failed (any of the link errors)
+ case 0x25: // Signal Lost (LOS)
+
+ if (Len < 2) return; // Wait for more
+
+ HALDisconnected(TNC);
+
+ Used = 2;
+ break;
+
+
+ // Stream Switch Reports - we will need to do something with these if Echo as Sent is set
+ // or we do something with the secondary port
+
+ case 0x30: // Switch to Receive Data characters
+ case 0x31: // Switch to Transmit Data characters
+ case 0x32: // Switch to RX data from secondary port
+
+ TNC->DataMode = Opcode;
+ Used = 1;
+ break;
+
+ case 0x33: // Send TX data to modem
+ case 0x34: // Send TX data to secondary port
+
+ TNC->TXMode = Opcode;
+ Used = 1;
+ break;
+
+ case 0x70: // Channel Spectra Data
+ // $807F $80xx $8030 Invalid or unimplemented command code
+ if (Len < 9) return; // Wait for more
+
+ Used = 9;
+ break;
+
+ case 0x71: // SelCall On/Off
+
+ if (Len < 2) return; // Wait for more
+
+ Used = 2;
+ break;
+
+ case 0x72: // Channel Spectra Data
+ // $807F $80xx $8030 Invalid or unimplemented command code
+ if (Len < 15) return; // Wait for more
+
+ Used = 15;
+ break;
+
+ case 0x73: // Clover Link state
+
+ if (Len < 2) return; // Wait for more
+
+ StatusByte = TNC->CmdBuffer[1];
+
+ switch (StatusByte)
+ {
+ case 0x00: mySetWindowText(TNC, "Channel idle"); break;
+ case 0x01: mySetWindowText(TNC, "Channel occupied with non-Clover signal"); break;
+ case 0x42: mySetWindowText(TNC, "Linked stations monitored"); break;
+ case 0x64: mySetWindowText(TNC, "Attempting normal link"); break;
+ case 0x65: mySetWindowText(TNC, "Attempting robust link"); break;
+ case 0x66: mySetWindowText(TNC, "Calling ARQ CQ"); break;
+ case 0x78: mySetWindowText(TNC, "Clover Control Block (CCB) send retry"); break;
+ case 0x79: mySetWindowText(TNC, "Clover Control Block (CCB) receive retry"); break;
+ case 0x7D: mySetWindowText(TNC, "Clover Control Block (CCB) received successfully"); break;
+ case 0x8A: mySetWindowText(TNC, "TX data block sent"); break;
+ case 0x8B: mySetWindowText(TNC, "RX data block received ok (precedes data block)"); break;
+ case 0x8C: mySetWindowText(TNC, "TX data block re-sent"); break;
+ case 0x8D: mySetWindowText(TNC, "RX data block decode failed (precedes data block)"); break;
+ case 0x8E: mySetWindowText(TNC, "TX idle"); break;
+ case 0x8F: mySetWindowText(TNC, "RX idle"); break;
+ case 0x9C: mySetWindowText(TNC, "Link failed: CCB send retries exceeded"); break;
+ case 0x9D: mySetWindowText(TNC, "Link failed: CCB receive retries exceeded"); break;
+ case 0x9E: mySetWindowText(TNC, "Link failed: protocol error"); break;
+ case 0xA0: mySetWindowText(TNC, "Receiving FEC SYNC sequence"); break;
+ }
+
+ Used = 2;
+ break;
+
+ case 0x75: // Clover waveform format
+
+ if (Len < 5) return; // Wait for more
+
+ Used = 5;
+ break;
+
+ case 0x7F: // Error $80xx $80yy Error in command $80xx of type $80yy
+ // $807F $80xx $8030 Invalid or unimplemented command code
+ // $807F $80xx $8031 Invalid parameter value
+ // $807F $80xx $8032 Not allowed when connected
+ // $807F $80xx $8033 Not allowed when disconnected
+ // $807F $80xx $8034 Not valid in this mode
+ // $807F $80xx $8035 Not valid in this code
+ // $807F $8096 $8036 EEPROM write error
+
+ if (Len < 3) return; // Wait for more
+
+ if (TNC->CmdBuffer[1] == 0x6f && TNC->CmdBuffer[2] == 0x31)
+ {
+ // Reject of XON/XOFF enable
+
+// TNC->XONXOFF = FALSE;
+// Debugprintf("BPQ32 HAL Port %d - Disabling XON/XOFF mode", TNC->Port);
+ }
+ else
+ Debugprintf("HAL Port %d Command Error Cmd %X Error %X", TNC->Port, TNC->CmdBuffer[1], TNC->CmdBuffer[2]);
+
+ Used = 3;
+ break;
+
+ // Following are all immediate commands - response is echo of command
+
+ case 0x6f: // XON/XOFF on
+
+// TNC->XONXOFF = TRUE; // And drop through
+// Debugprintf("BPQ32 HAL Port %d - Enabling XON/XOFF mode", TNC->Port);
+
+ case 0x19: // Call P-MODE to <CALL>
+ case 0x10: // Robust Link to <CALL> using MYCALL
+ case 0x11: // Normal Link to <CALL> using MYCALL
+
+ STREAM->Connecting = TRUE;
+
+ case 0x00: // P Load LOD file
+ case 0x01: // P Load S28 file
+ case 0x02: //Check Unit Error Status
+ case 0x03: //F Check System Clock
+ case 0x04: //C Close PTT and transmit Clover waveform
+ case 0x05: //Open PTT and stop transmit test
+ case 0x06: //Immediate Abort (Panic Kill)
+ case 0x07: //Normal disconnect (wait for ACK)
+ case 0x08: //Software reset - restore all program defaults
+ case 0x0A: //Send CW ID
+ case 0x0B: //Close PTT and transmit Single Tone
+ case 0x0C: //F Normal OVER (AMTOR,P-MODE)
+ case 0x0D: //F Force RTTY TX (Baudot/ASCII)
+ case 0x0E: //F Go to RTTY RX (Baudot/ASCII)
+ case 0x0F: //Go to LOD/S28 file loader
+ case SetMYCALL: // Set MYCALL Response
+
+ case 0x1E: // Set MYALTCALL Response
+
+ case 0x41:
+ case 0x42:
+ case 0x46:
+ case 0x47:
+ case 0x48:
+ case 0x4d:
+ case 0x52: // Enable adaptive Clover format
+ case 0x54: // Enable adaptive Clover format
+
+ case 0x56: // Expanded Link State Reports OFF/ON
+ case 0x57: // Clear buffers on disc
+ case 0x58:
+ case 0x59:
+ case 0x60: // Robust Mode Retries
+ case 0x61: // Normal Mode Retries
+ case 0x80: //Switch to CLOVER mode
+ case 0x81: //Select AMTOR Standby
+ case 0x82: //Select AMTOR FEC
+ case 0x83: //Select P-MODE Standby
+ case 0x84: //Switch to FSK modes
+ case 0x85: //Select Baudot
+ case 0x86: //Select ASCII
+ case 0x87: //Forced OVER (AMTOR, P-MODE)
+ case 0x88: //Forced END (AMTOR, P-MODE)
+ case 0x89: //Force LTRS shift
+ case 0x8A: //Force FIGS shift
+ case 0x8B: //Send MARK tone
+ case 0x8C: //Send SPACE tone
+ case 0x8D: //Send MARK/SPACE tones
+ case 0x8E: //Received first character on line
+ case 0x8F: //Close PTT only (no tones)
+
+ case 0xC9: //Huffman Off/On
+ case 0xCC:
+ case 0xD9: //Close PTT only (no tones)
+
+ case SetTones:
+
+ Used = 1;
+ break;
+
+ case 0x91: // ????
+
+// if (Len < 2) return; // Wait for more
+
+ Used = 1;
+ break;
+
+ default:
+
+ // We didn't recognise command, so don't know how long it is - disaster!
+
+ Debugprintf("HAL Port %d Unrecognised Command %x", TNC->Port, Opcode);
+ TNC->CmdLen = 0;
+
+ return;
+ }
+
+ if (Used == Len)
+ {
+ // All used - most likely case
+
+ TNC->CmdLen = 0;
+ return;
+ }
+
+ // Move Command Down buffer, and reenter
+
+ TNC->CmdLen -= Used;
+
+ memmove(TNC->CmdBuffer, &TNC->CmdBuffer[Used], TNC->CmdLen);
+
+ goto CmdLoop;
+
+
+}
+
+
+VOID HALDisconnected(struct TNCINFO * TNC)
+{
+ struct STREAMINFO * STREAM = &TNC->Streams[0];
+
+ CloseLogfile(0);
+ CloseLogfile(1);
+ CloseLogfile(2);
+
+ if ((STREAM->Connecting | STREAM->Connected) == 0)
+ {
+ // Not connected or Connecting. Probably response to going into Pactor Listen Mode
+
+ return;
+ }
+
+ if (STREAM->Connecting && STREAM->Disconnecting == FALSE)
+ {
+ UINT * buffptr;
+
+ // Connect Failed - actually I think HAL uses another code for connect failed, but leave here for now
+
+ buffptr = GetBuff();
+
+ if (buffptr)
+ {
+ buffptr[1] = sprintf((UCHAR *)&buffptr[2], "*** Failure with %s\r", STREAM->RemoteCall);
+
+ C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr);
+ }
+
+ STREAM->Connecting = FALSE;
+ STREAM->Connected = FALSE; // In case!
+ STREAM->FramesQueued = 0;
+
+ sprintf(TNC->WEB_TNCSTATE, "In Use by %s", STREAM->MyCall);
+ MySetWindowText(TNC->xIDC_TNCSTATE, TNC->WEB_TNCSTATE);
+
+ return;
+ }
+
+ // Connected, or Disconnecting - Release Session
+
+ STREAM->Connecting = FALSE;
+ STREAM->Connected = FALSE; // Back to Command Mode
+ STREAM->FramesQueued = 0;
+
+ if (STREAM->Disconnecting == FALSE)
+ STREAM->ReportDISC = TRUE; // Tell Node
+
+ STREAM->Disconnecting = FALSE;
+
+ // Need to reset Pactor Call in case it was changed
+
+ TNC->NeedPACTOR = 20;
+}
+
+BOOL HALConnected(struct TNCINFO * TNC, char * Call)
+{
+ char Msg[80];
+ UINT * buffptr;
+ struct STREAMINFO * STREAM = &TNC->Streams[0];
+ char CallCopy[80];
+
+ strcpy(CallCopy, Call);
+ strcat(CallCopy, " "); // Some routines expect 10 char calls
+
+ STREAM->BytesRXed = STREAM->BytesTXed = STREAM->BytesAcked = 0;
+ STREAM->ConnectTime = time(NULL);
+
+ // Stop Scanner
+
+ sprintf(Msg, "%d SCANSTOP", TNC->Port);
+
+ Rig_Command(-1, Msg);
+
+ ShowTraffic(TNC);
+
+ TNC->DataMode = RXDATA;
+
+ OpenLogfile(0);
+ OpenLogfile(1);
+ OpenLogfile(2);
+
+ if (TNC->PortRecord->ATTACHEDSESSIONS[0] == 0)
+ {
+ // Incoming Connect
+
+ ProcessIncommingConnect(TNC, CallCopy, 0, TRUE);
+
+ sprintf(TNC->WEB_TNCSTATE, "%s Connected to %s Inbound", STREAM->RemoteCall, TNC->NodeCall);
+ MySetWindowText(TNC->xIDC_TNCSTATE, TNC->WEB_TNCSTATE);
+
+ if (TNC->CurrentMode != Clover)
+ SendCmd(TNC, "\x87", 1); // Changeover to ISS
+
+ // If an autoconnect APPL is defined, send it
+
+ if (TNC->ApplCmd)
+ {
+ buffptr = GetBuff();
+ if (buffptr == 0) return TRUE; // No buffers, so ignore
+
+ buffptr[1] = sprintf((UCHAR *)&buffptr[2], "%s\r", TNC->ApplCmd);
+ C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr);
+ TNC->SwallowSignon = TRUE;
+
+ return TRUE;
+ }
+
+ if (FULL_CTEXT && HFCTEXTLEN == 0)
+ {
+ EncodeAndSend(TNC, CTEXTMSG, CTEXTLEN);
+ WriteLogLine(2, CTEXTMSG, CTEXTLEN);
+
+ STREAM->BytesTXed += CTEXTLEN;
+ }
+ return TRUE;
+ }
+
+ // Connect Complete
+
+ buffptr = GetBuff();
+ if (buffptr == 0) return TRUE; // No buffers, so ignore
+
+ buffptr[1] = sprintf((UCHAR *)&buffptr[2], "*** Connected to %s\r", Call);;
+
+ C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr);
+
+ STREAM->Connecting = FALSE;
+ STREAM->Connected = TRUE; // Subsequent data to data channel
+
+ sprintf(TNC->WEB_TNCSTATE, "%s Connected to %s Outbound", TNC->NodeCall, STREAM->RemoteCall);
+ MySetWindowText(TNC->xIDC_TNCSTATE, TNC->WEB_TNCSTATE);
+
+ UpdateMH(TNC, CallCopy, '+', 'O');
+
+
+ return TRUE;
+}
+
+
+static VOID EncodeAndSend(struct TNCINFO * TNC, UCHAR * txbuffer, int Len)
+{
+ // Send A Packet With DLE Encoding Encoding
+
+ TNC->TXLen = DLEEncode(txbuffer, TNC->TXBuffer, Len);
+
+ WriteCommBlock(TNC);
+}
+
+VOID SendCmd(struct TNCINFO * TNC, UCHAR * txbuffer, int Len)
+{
+ // Send A Packet With Command Encoding (preceed each with 0x80
+
+ int i,txptr=0;
+ UCHAR * outbuff = TNC->TXBuffer;
+
+ for (i=0; i<Len; i++)
+ {
+ outbuff[txptr++] = 0x80;
+ outbuff[txptr++] = txbuffer[i];
+ }
+
+ TNC->TXLen = txptr;
+ WriteCommBlock(TNC);
+}
+
+int DLEEncode(UCHAR * inbuff, UCHAR * outbuff, int len)
+{
+ int i, txptr = 0;
+ UCHAR c;
+
+ // Escape x80 and x81 with x81
+
+// outbuff[0] = 0x80;
+// outbuff[1] = 0x33; // Send data to modem
+
+ for (i=0;i<len;i++)
+ {
+ c=inbuff[i];
+
+ switch (c)
+ {
+ case 0x80:
+ case 0x81:
+
+ outbuff[txptr++] = 0x81;
+ }
+ outbuff[txptr++] = c;
+ }
+
+ return txptr;
+
+}
+
+VOID TidyClose(struct TNCINFO * TNC, int Stream)
+{
+ SendCmd(TNC, "\x07", 1); // Tidy Disconnect
+}
+
+VOID ForcedClose(struct TNCINFO * TNC, int Stream)
+{
+ SendCmd(TNC, "\x06", 1); // Hard Disconnect
+}
+
+VOID CloseComplete(struct TNCINFO * TNC, int Stream)
+{
+ TNC->NeedPACTOR = 30;
+}
+
+
+
+
@@ -1866,9 +1866,6 @@ static char ** SeparateMultiString(char * MultiString) return Value;
}
-
-
-
extern int nextDummyInterlock;
int standardParams(struct TNCINFO * TNC, char * buf)
@@ -787,6 +787,8 @@ int Redirected = 0; static void segvhandler(int sig);
static void abrthandler(int sig);
+void GetRestartData();
+
int main(int argc, char * argv[])
{
@@ -1174,6 +1176,8 @@ int main(int argc, char * argv[]) chmod(MailDir, S_IRWXU | S_IRWXG | S_IRWXO);
#endif
+
+
// Make backup copies of Databases
// CopyConfigFile(ConfigName);
@@ -1195,6 +1199,7 @@ int main(int argc, char * argv[]) GetBadWordFile();
GetHTMLForms();
GetPGConfig();
+ GetRestartData();
// Make sure there is a user record for the BBS, with BBS bit set.
@@ -1442,6 +1447,7 @@ int main(int argc, char * argv[]) SaveMessageDatabase();
SaveBIDDatabase();
SaveConfig(ConfigName);
+ SaveRestartData();
}
KEEPGOING--; // Give time for links to close
diff --git a/MULTIPSK64.c b/MULTIPSK64.c index 484d9b5..8fe6a84 100644 --- a/MULTIPSK64.c +++ b/MULTIPSK64.c @@ -1,1543 +1,1543 @@ -/* -Copyright 2001-2018 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 -*/ - -// -// DLL to provide interface to allow G8BPQ switch to use MultoPSK ALE400 Mode -// -// Uses BPQ EXTERNAL interface -// - - -#define _CRT_SECURE_NO_DEPRECATE - -#define _CRT_SECURE_NO_DEPRECATE - -#include "CHeaders.h" -#include <stdio.h> -#include <time.h> - -#include "tncinfo.h" - -#include "bpq32.h" - -#define VERSION_MAJOR 2 -#define VERSION_MINOR 0 - -#define SD_RECEIVE 0x00 -#define SD_SEND 0x01 -#define SD_BOTH 0x02 - -#define TIMESTAMP 352 - -#define CONTIMEOUT 1200 - - - -#define AGWHDDRLEN sizeof(struct AGWHEADER) - -extern int (WINAPI FAR *GetModuleFileNameExPtr)(); - -//int ResetExtDriver(int num); -extern char * PortConfig[33]; - -struct TNCINFO * TNCInfo[34]; // Records are Malloc'd - -static void ConnecttoMPSKThread(void * portptr); - -void CreateMHWindow(); -int Update_MH_List(struct in_addr ipad, char * call, char proto); - -static int ConnecttoMPSK(); -static int ProcessReceivedData(int bpqport); -static int ProcessLine(char * buf, int Port); -int KillTNC(struct TNCINFO * TNC); -int RestartTNC(struct TNCINFO * TNC); -VOID ProcessMPSKPacket(struct TNCINFO * TNC, char * Message, int Len); -struct TNCINFO * GetSessionKey(char * key, struct TNCINFO * TNC); -static VOID SendData(struct TNCINFO * TNC, char * Msg, int MsgLen); -static VOID DoMonitorHddr(struct TNCINFO * TNC, struct AGWHEADER * RXHeader, UCHAR * Msg); -VOID SendRPBeacon(struct TNCINFO * TNC); - -char * strlop(char * buf, char delim); - -extern UCHAR BPQDirectory[]; - -#define MAXBPQPORTS 32 -#define MAXMPSKPORTS 16 - -//LOGFONT LFTTYFONT ; - -//HFONT hFont ; - -static int MPSKChannel[MAXBPQPORTS+1]; // BPQ Port to MPSK Port -static int BPQPort[MAXMPSKPORTS][MAXBPQPORTS+1]; // MPSK Port and Connection to BPQ Port - -static int MasterPort[MAXBPQPORTS+1]; // Pointer to first BPQ port for a specific MPSK host - -// Each port may be on a different machine. We only open one connection to each MPSK instance - -static char * MPSKSignon[MAXBPQPORTS+1]; // Pointer to message for secure signin - -static unsigned int MPSKInst = 0; -static int AttachedProcesses=0; - -static HWND hResWnd,hMHWnd; -static BOOL GotMsg; - -static HANDLE STDOUT=0; - -//SOCKET sock; - -static SOCKADDR_IN sinx; -static SOCKADDR_IN rxaddr; -static SOCKADDR_IN destaddr[MAXBPQPORTS+1]; - -static int addrlen=sizeof(sinx); - -//static short MPSKPort=0; - -static time_t ltime,lasttime[MAXBPQPORTS+1]; - -static BOOL CONNECTING[MAXBPQPORTS+1]; -static BOOL CONNECTED[MAXBPQPORTS+1]; - -//HANDLE hInstance; - - -static fd_set readfs; -static fd_set writefs; -static fd_set errorfs; -static struct timeval timeout; - -#ifndef LINBPQ - -static BOOL CALLBACK EnumTNCWindowsProc(HWND hwnd, LPARAM lParam) -{ - char wtext[200]; - struct TNCINFO * TNC = (struct TNCINFO *)lParam; - UINT ProcessId; - char FN[MAX_PATH] = ""; - - if (TNC->ProgramPath == NULL) - return FALSE; - - GetWindowText(hwnd, wtext, 199); - - if (strstr(wtext,"* MULTIPSK")) - { - GetWindowThreadProcessId(hwnd, &ProcessId); - - TNC->PID = ProcessId; - return FALSE; - } - - return (TRUE); -} - -#endif - -static size_t ExtProc(int fn, int port, PDATAMESSAGE buff) -{ - PMSGWITHLEN buffptr; - - unsigned int txlen=0; - struct TNCINFO * TNC = TNCInfo[port]; - int Stream = 0; - struct STREAMINFO * STREAM; - int TNCOK; - - if (TNC == NULL) - return 0; // Port not defined - - // Look for attach on any call - - for (Stream = 0; Stream <= TNC->MPSKInfo->MaxSessions; Stream++) - { - STREAM = &TNC->Streams[Stream]; - - if (TNC->PortRecord->ATTACHEDSESSIONS[Stream] && TNC->Streams[Stream].Attached == 0) - { - char Cmd[80]; - int len; - - // New Attach - - int calllen; - STREAM->Attached = TRUE; - - calllen = ConvFromAX25(TNC->PortRecord->ATTACHEDSESSIONS[Stream]->L4USER, STREAM->MyCall); - STREAM->MyCall[calllen] = 0; - STREAM->FramesOutstanding = 0; - - // Stop Scanning - - sprintf(Cmd, "%d SCANSTOP", TNC->Port); - Rig_Command(-1, Cmd); - - len = sprintf(Cmd, "%cSTOP_BEACON_ARQ_FAE\x1b", '\x1a'); - - if (TNC->MPSKInfo->TX) - TNC->CmdSet = TNC->CmdSave = _strdup(Cmd); // Savde till not transmitting - else - send(TNC->TCPSock, Cmd, len, 0); - - } - } - - switch (fn) - { - case 1: // poll - - if (MasterPort[port] == port) - { - // Only on first port using a host - - if (TNC->CONNECTED == FALSE && TNC->CONNECTING == FALSE) - { - // See if time to reconnect - - time( <ime ); - if (ltime-lasttime[port] >9 ) - { - ConnecttoMPSK(port); - lasttime[port]=ltime; - } - } - - FD_ZERO(&readfs); - - if (TNC->CONNECTED) FD_SET(TNC->TCPSock,&readfs); - - - FD_ZERO(&writefs); - - if (TNC->CONNECTING) FD_SET(TNC->TCPSock,&writefs); // Need notification of Connect - - if (TNC->BPQtoWINMOR_Q) FD_SET(TNC->TCPSock,&writefs); // Need notification of busy clearing - - - - FD_ZERO(&errorfs); - - if (TNC->CONNECTING ||TNC->CONNECTED) FD_SET(TNC->TCPSock,&errorfs); - - if (select((int)TNC->TCPSock+ 1, &readfs, &writefs, &errorfs, &timeout) > 0) - { - // See what happened - - if (FD_ISSET(TNC->TCPSock,&readfs)) - { - // data available - - ProcessReceivedData(port); - } - - if (FD_ISSET(TNC->TCPSock,&writefs)) - { - // Connect success - - TNC->CONNECTED = TRUE; - TNC->CONNECTING = FALSE; - - // If required, send signon - - send(TNC->TCPSock,"\x1a", 1, 0); - send(TNC->TCPSock,"DIGITAL MODE ?", 14, 0); - send(TNC->TCPSock,"\x1b", 1, 0); - -// EnumWindows(EnumTNCWindowsProc, (LPARAM)TNC); - } - - if (FD_ISSET(TNC->TCPSock,&errorfs)) - { - - // if connecting, then failed, if connected then has just disconnected - -// if (CONNECTED[port]) -// if (!CONNECTING[port]) -// { -// i=sprintf(ErrMsg, "MPSK Connection lost for BPQ Port %d\r\n", port); -// WritetoConsole(ErrMsg); -// } - - CONNECTING[port]=FALSE; - CONNECTED[port]=FALSE; - - } - - } - - } - - // See if any frames for this port - - for (Stream = 0; Stream <= TNC->MPSKInfo->MaxSessions; Stream++) - { - STREAM = &TNC->Streams[Stream]; - - // Have to time out connects, as TNC doesn't report failure - - if (STREAM->Connecting) - { - STREAM->Connecting--; - - if (STREAM->Connecting == 0) - { - // Report Connect Failed, and drop back to command mode - - buffptr = GetBuff(); - - if (buffptr) - { - buffptr->Len = sprintf(buffptr->Data, "MPSK} Failure with %s\r", STREAM->RemoteCall); - C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr); - } - - STREAM->Connected = FALSE; // Back to Command Mode - STREAM->DiscWhenAllSent = 10; - - // Send Disc to TNC - - TidyClose(TNC, Stream); - } - } - - if (STREAM->Attached) - CheckForDetach(TNC, Stream, STREAM, TidyClose, ForcedClose, CloseComplete); - - if (STREAM->ReportDISC) - { - STREAM->ReportDISC = FALSE; - buff->PORT = Stream; - - return -1; - } - - // if Busy, send buffer status poll - - if (STREAM->PACTORtoBPQ_Q == 0) - { - if (STREAM->DiscWhenAllSent) - { - STREAM->DiscWhenAllSent--; - if (STREAM->DiscWhenAllSent == 0) - STREAM->ReportDISC = TRUE; // Dont want to leave session attached. Causes too much confusion - } - } - else - { - int datalen; - - buffptr=Q_REM(&STREAM->PACTORtoBPQ_Q); - - datalen = buffptr->Len; - - buff->PORT = Stream; - buff->PID = 0xf0; - memcpy(buff->L2DATA, buffptr->Data, datalen); // Data goes to +7, but we have an extra byte - datalen += MSGHDDRLEN + 1; - - PutLengthinBuffer((PDATAMESSAGE)buff, datalen); - - ReleaseBuffer(buffptr); - - return (1); - } - } - - if (TNC->PortRecord->UI_Q) - { - struct _MESSAGE * buffptr; - - SOCKET Sock; - buffptr = Q_REM(&TNC->PortRecord->UI_Q); - - Sock = TNCInfo[MasterPort[port]]->TCPSock; - - ReleaseBuffer((UINT *)buffptr); - } - - - return (0); - - - - case 2: // send - - - if (!TNCInfo[MasterPort[port]]->CONNECTED) return 0; // Don't try if not connected to TNC - - Stream = buff->PORT; - - STREAM = &TNC->Streams[Stream]; - -// txlen=(buff[6]<<8) + buff[5] - 8; - - txlen = GetLengthfromBuffer((PDATAMESSAGE)buff) - 8; - - if (STREAM->Connected) - { - SendData(TNC, buff->L2DATA, txlen); - } - else - { - char Command[80]; - int len; - - buff->L2DATA[txlen] = 0; - _strupr(buff->L2DATA); - - if (_memicmp(&buff[8], "D\r", 2) == 0) - { - TidyClose(TNC, buff->PORT); - STREAM->ReportDISC = TRUE; // Tell Node - return 0; - } - - // See if Local command (eg RADIO) - - if (_memicmp(buff->L2DATA, "RADIO ", 6) == 0) - { - sprintf(buff->L2DATA, "%d %s", TNC->Port, &buff->L2DATA[6]); - - if (Rig_Command(TNC->PortRecord->ATTACHEDSESSIONS[0]->L4CROSSLINK->CIRCUITINDEX, buff->L2DATA)) - { - } - else - { - buffptr = (PMSGWITHLEN)GetBuff(); - - if (buffptr == 0) return 1; // No buffers, so ignore - - buffptr->Len= sprintf((UCHAR *)&buffptr->Data, "%s", buff->L2DATA); - C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr); - } - return 1; - } - - if (STREAM->Connecting && _memicmp(&buff[8], "ABORT", 5) == 0) - { - len = sprintf(Command,"%cSTOP_SELECTIVE_CALL_ARQ_FAE\x1b", '\x1a'); - - if (TNC->MPSKInfo->TX) - TNC->CmdSet = TNC->CmdSave = _strdup(Command); // Save till not transmitting - else - send(TNC->TCPSock, Command, len, 0); - - TNC->InternalCmd = TRUE; - return (0); - } - - if (_memicmp(&buff[8], "MODE", 4) == 0) - { - buff->L2DATA[txlen - 1] = 0; // Remove CR - - len = sprintf(Command,"%cDIGITAL MODE %s\x1b", '\x1a', &buff->L2DATA[5]); - - if (TNC->MPSKInfo->TX) - TNC->CmdSet = TNC->CmdSave = _strdup(Command); // Save till not transmitting - else - send(TNC->TCPSock, Command, len, 0); - - TNC->InternalCmd = TRUE; - return (0); - } - - - if (_memicmp(&buff[8], "INUSE?", 6) == 0) - { - // Return Error if in use, OK if not - - UINT * buffptr = GetBuff(); - int s = 0; - - while(s <= TNC->MPSKInfo->MaxSessions) - { - if (s != Stream) - { - if (TNC->PortRecord->ATTACHEDSESSIONS[s]) - { - buffptr[1] = sprintf((UCHAR *)&buffptr[2], "MPSK} Error - In use\r"); - C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr); - return 1; // Busy - } - } - s++; - } - buffptr[1] = sprintf((UCHAR *)&buffptr[2], "MPSK} Ok - Not in use\r"); - C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr); - - return 1; - } - - // See if a Connect Command. - - if (toupper(buff->L2DATA[0]) == 'C' && buff->L2DATA[1] == ' ' && txlen > 2) // Connect - { - char * ptr; - char * context; - - buff->L2DATA[txlen] = 0; - _strupr(buff->L2DATA); - - memset(STREAM->RemoteCall, 0, 10); - - ptr = strtok_s(&buff->L2DATA[2], " ,\r", &context); - strcpy(STREAM->RemoteCall, ptr); - - len = sprintf(Command,"%cCALLSIGN_TO_CALL_ARQ_FAE %s%c%cSELECTIVE_CALL_ARQ_FAE\x1b", - '\x1a', STREAM->RemoteCall, '\x1b', '\x1a'); - - if (TNC->MPSKInfo->TX) - TNC->CmdSet = TNC->CmdSave = _strdup(Command); // Save till not transmitting - else - send(TNC->TCPSock, Command, len, 0); - - STREAM->Connecting = TNC->MPSKInfo->ConnTimeOut; // It doesn't report failure - -// sprintf(Status, "%s Connecting to %s", TNC->Streams[0].MyCall, TNC->Streams[0].RemoteCall); -// SetDlgItemText(TNC->hDlg, IDC_TNCSTATE, Status); - - return 0; - } - - // Send any other command to Multipsk - - buff->L2DATA[txlen - 1] = 0; - _strupr(&buff->L2DATA[0]); - - len = sprintf(Command,"%c%s\x1b", '\x1a', buff->L2DATA); - - if (TNC->MPSKInfo->TX) - TNC->CmdSet = TNC->CmdSave = _strdup(Command); // Save till not transmitting - else - send(TNC->TCPSock, Command, len, 0); - - TNC->InternalCmd = TRUE; - - } - - return (0); - - case 3: - - Stream = buff->PORT; - - TNCOK = TNCInfo[MasterPort[port]]->CONNECTED; - - STREAM = &TNC->Streams[Stream]; - - if (STREAM->FramesOutstanding > 8) - return (1 | TNCOK << 8 | STREAM->Disconnecting << 15); - - return TNCOK << 8 | STREAM->Disconnecting << 15; // OK, but lock attach if disconnecting - - break; - - case 4: // reinit - - shutdown(TNC->TCPSock, SD_BOTH); - Sleep(100); - - closesocket(TNC->TCPSock); - TNC->CONNECTED = FALSE; - - if (TNC->PID && TNC->WeStartedTNC) - { - KillTNC(TNC); - RestartTNC(TNC); - } - - return (0); - - case 5: // Close - - shutdown(TNC->TCPSock, SD_BOTH); - Sleep(100); - - closesocket(TNC->TCPSock); - - if (TNC->PID && TNC->WeStartedTNC) - { - KillTNC(TNC); - } - - return 0; - } - - return 0; -} - -#ifndef LINBPQ - -static KillTNC(struct TNCINFO * TNC) -{ - HANDLE hProc; - - if (TNC->PTTMode) - Rig_PTT(TNC->RIG, FALSE); // Make sure PTT is down - - if (TNC->PID == 0) return 0; - - hProc = OpenProcess(PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, TNC->PID); - - if (hProc) - { - TerminateProcess(hProc, 0); - CloseHandle(hProc); - } - - TNC->PID = 0; // So we don't try again - - return 0; -} - -static RestartTNC(struct TNCINFO * TNC) -{ - STARTUPINFO SInfo; // pointer to STARTUPINFO - PROCESS_INFORMATION PInfo; // pointer to PROCESS_INFORMATION - char HomeDir[MAX_PATH]; - int i, ret; - - SInfo.cb=sizeof(SInfo); - SInfo.lpReserved=NULL; - SInfo.lpDesktop=NULL; - SInfo.lpTitle=NULL; - SInfo.dwFlags=0; - SInfo.cbReserved2=0; - SInfo.lpReserved2=NULL; - - if (TNC->ProgramPath) - { - strcpy(HomeDir, TNC->ProgramPath); - i = strlen(HomeDir); - - while(--i) - { - if (HomeDir[i] == '/' || HomeDir[i] == '\\') - { - HomeDir[i] = 0; - break; - } - } - ret = CreateProcess(TNC->ProgramPath, "MultiPSK TCP_IP_ON", NULL, NULL, FALSE,0 ,NULL ,HomeDir, &SInfo, &PInfo); - - if (ret) - TNC->PID = PInfo.dwProcessId; - - return ret; - } - return 0; -} -#endif - -UINT MPSKExtInit(EXTPORTDATA * PortEntry) -{ - int i, port; - char Msg[255]; - struct TNCINFO * TNC; - char * ptr; - - // - // Will be called once for each MPSK port to be mapped to a BPQ Port - // The MPSK port number is in CHANNEL - A=0, B=1 etc - // - // 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 ExtProc; - } - - TNC->Port = port; - - 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->PERMITGATEWAY = TRUE; // Can change ax.25 call on each stream - PortEntry->PORTCONTROL.PORTQUALITY = 0; - PortEntry->SCANCAPABILITIES = NONE; // Scan Control - None - - if (PortEntry->PORTCONTROL.PORTPACLEN == 0) - PortEntry->PORTCONTROL.PORTPACLEN = 64; - - ptr=strchr(TNC->NodeCall, ' '); - if (ptr) *(ptr) = 0; // Null Terminate - - TNC->Hardware = H_MPSK; - - MPSKChannel[port] = PortEntry->PORTCONTROL.CHANNELNUM-65; - - PortEntry->MAXHOSTMODESESSIONS = 1; - - i=sprintf(Msg,"MPSK Host %s Port %d \n", - TNC->HostName, TNC->TCPPort); - - WritetoConsole(Msg); - - // See if we already have a port for this host - - MasterPort[port] = port; - - for (i = 1; i < port; i++) - { - if (i == port) continue; - - if (TNCInfo[i] && TNCInfo[i]->TCPPort == TNC->TCPPort && - _stricmp(TNCInfo[i]->HostName, TNC->HostName) == 0) - { - MasterPort[port] = i; - break; - } - } - - BPQPort[PortEntry->PORTCONTROL.CHANNELNUM-65][MasterPort[port]] = port; - -#ifndef LINBPQ - if (MasterPort[port] == port) - { - if (EnumWindows(EnumTNCWindowsProc, (LPARAM)TNC)) - if (TNC->ProgramPath) - TNC->WeStartedTNC = RestartTNC(TNC); - - ConnecttoMPSK(port); - } -#endif - time(&lasttime[port]); // Get initial time value - -// SendMessage(0x40eaa, WM_COMMAND, 0x03000eaa, 0x40eaa); - - return ExtProc; - -} - - -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; - struct MPSKINFO * AGW; - - 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] = zalloc(sizeof(struct TNCINFO)); - AGW = TNC->MPSKInfo = zalloc(sizeof(struct MPSKINFO)); // AGW Sream Mode Specific Data - - AGW->MaxSessions = 10; - AGW->ConnTimeOut = CONTIMEOUT; - - 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); - - TNC->TCPPort = atoi(p_port); - - TNC->destaddr.sin_family = AF_INET; - TNC->destaddr.sin_port = htons(TNC->TCPPort); - 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 (_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, "CONTIMEOUT", 10) == 0) - AGW->ConnTimeOut = atoi(&buf[11]) * 10; - else - if (_memicmp(buf, "UPDATEMAP", 9) == 0) - TNC->PktUpdateMap = TRUE; - else - if (_memicmp(buf, "ALEBEACON", 9) == 0) // Send Beacon after each session - TNC->MPSKInfo->Beacon = TRUE; - else - if (_memicmp(buf, "DEFAULTMODE", 11) == 0) // Send Beacon after each session - strcpy(TNC->MPSKInfo->DefaultMode, &buf[12]); - else - - strcat (TNC->InitScript, buf); - } - - - return (TRUE); -} - -static int ConnecttoMPSK(int port) -{ - _beginthread(ConnecttoMPSKThread, 0, (void *)(size_t)port); - - return 0; -} - -VOID ConnecttoMPSKThread(void * portptr) -{ - - int port = (int)(size_t)portptr; - char Msg[255]; - int err,i; - u_long param=1; - BOOL bcopt=TRUE; - struct hostent * HostEnt; - struct TNCINFO * TNC = TNCInfo[port]; - - Sleep(5000); // Allow init to complete - - TNC->destaddr.sin_addr.s_addr = inet_addr(TNC->HostName); - - if (TNC->destaddr.sin_addr.s_addr == INADDR_NONE) - { - // Resolve name to address - - HostEnt = gethostbyname (TNC->HostName); - - if (!HostEnt) return; // Resolve failed - - memcpy(&TNC->destaddr.sin_addr.s_addr,HostEnt->h_addr,4); - memcpy(&TNC->Datadestaddr.sin_addr.s_addr,HostEnt->h_addr,4); - - } - - if (TNC->TCPSock) - closesocket(TNC->TCPSock); - - TNC->TCPSock = 0; - - TNC->TCPSock=socket(AF_INET,SOCK_STREAM,0); - - if (TNC->TCPSock == INVALID_SOCKET) - { - i=sprintf(Msg, "Socket Failed for MPSK socket - error code = %d\n", WSAGetLastError()); - WritetoConsole(Msg); - - return; - } - - sinx.sin_family = AF_INET; - sinx.sin_addr.s_addr = INADDR_ANY; - sinx.sin_port = 0; - - TNC->CONNECTING = TRUE; - - if (connect(TNC->TCPSock,(LPSOCKADDR) &TNC->destaddr,sizeof(TNC->destaddr)) == 0) - { - // - // Connected successful - // - - TNC->CONNECTED=TRUE; - } - else - { - if (TNC->Alerted == FALSE) - { - err=WSAGetLastError(); - i=sprintf(Msg, "Connect Failed for MPSK socket - error code = %d\n", err); - WritetoConsole(Msg); - MySetWindowText(TNC->xIDC_COMMSSTATE, "Connection to TNC failed"); - - TNC->Alerted = TRUE; - } - - TNC->CONNECTING = FALSE; - return; - } - - TNC->LastFreq = 0; // so V4 display will be updated - - MySetWindowText(TNC->xIDC_COMMSSTATE, "Connected to MPSK TNC"); - - return; - -} - -static int ProcessReceivedData(int port) -{ - unsigned int bytes; - int i; - char ErrMsg[255]; - char Message[500]; - struct TNCINFO * TNC = TNCInfo[port]; - - // Need to extract messages from byte stream - - bytes = recv(TNC->TCPSock,(char *)&Message, 500, 0); - - if (bytes == SOCKET_ERROR) - { -// i=sprintf(ErrMsg, "Read Failed for MPSK socket - error code = %d\r\n", WSAGetLastError()); -// WritetoConsole(ErrMsg); - - closesocket(TNC->TCPSock); - - TNC->CONNECTED = FALSE; - if (TNC->Streams[0].Attached) - TNC->Streams[0].ReportDISC = TRUE; - - return (0); - } - - if (bytes == 0) - { - // zero bytes means connection closed - - i=sprintf(ErrMsg, "MPSK Connection closed for BPQ Port %d\n", port); - WritetoConsole(ErrMsg); - - TNC->CONNECTED = FALSE; - if (TNC->Streams[0].Attached) - TNC->Streams[0].ReportDISC = TRUE; - - return (0); - } - - // Have some data - - ProcessMPSKPacket(TNC, Message, bytes); // Data may be for another port - - return (0); - -} - -VOID ProcessMSPKCmd(struct TNCINFO * TNC); -VOID ProcessMSPKComment(struct TNCINFO * TNC); -VOID ProcessMSPKData(struct TNCINFO * TNC); - -VOID ProcessMPSKPacket(struct TNCINFO * TNC, char * Message, int Len) -{ - char * MPTR = Message; - -/* -3) each text character transmitted by the client to the server (for the Multipsk TX text editor) must be preceded by the character CHR(25) or CHR(22) in the case of a special link (KISS in Packet or Pax, for example). - -4) each command string transmitted by the client to the server must be preceded by the character CHR(26) and finished by CHR(27), - -5) each character effectively transmitted by Multipsk to the transceiver and transmitted to the client is preceded by the character CHR(28), - -6) each character received by Multipsk and transmitted to the client is preceded by the character CHR(29), - -7) each command string transmitted by the server to the client must be preceded by the character CHR(30) and finished by CHR(31), - -8) all commands (written in readable text ) will have an answer (see further for details), - -9) each server comment (Call ID or RS ID reception, switch to RX or to TX) string transmitted by the server to the client must be preceded by a string: "CHR(23)RX CALL ID=", "CHR(23)RX RS ID=", "CHR(23)SWITCH=RX", "CHR(23) SWITCH=TX", and finished by CHR(24). - -10) each server command, for the transceiver control, transmitted by the server to the client must be preceded by the string "CHR(23) XCVR=" and finished by CHR(24). - -Data - -End of TX] ARQ FAE CQ[End of TX] ARQ FAE CQ[End of TX] call "THIS I[End of TX] end of link to GM8BPQ[End of TX] sounding "THIS WAS"[End of TX] ARQ FAE CQ[End of TX] ARQ FAE CQ[End of TX] ARQ FAE CQ[End of TX] ARQ FAE CQFAE BEACON OH5RM Kouvola KP30JR -[End of TX] ARQ FAE selective callGM8BPQ DE OH5RM - -[Connection made with OH5RM] - - -18103 but I have to go out to change antenna - -[End of connection with OH5RM]FAE BEACON OH5RM Kouvola KP30JR -S" to GM8BPQ - -10:23:55 AM Comment: SWITCH=RX -10:24:00 AM Comment: RX RS ID=10:24:00 UTC ALE400 1609 Hz 0 MHz -10:24:19 AM Comment: RX RS ID=10:24:19 UTC ALE400 1604 Hz 0 MHz -10:25:04 AM Comment: SWITCH=TX -10:25:07 AM Comment: SWITCH=RX -10:25:15 AM Comment: SWITCH=TX -:30:22 AM Comment: SWITCH=RX -10:30:25 AM Comment: SWITCH=TX -10:30:27 AM Comment: SWITCH=RX -10:30:35 AM Comment: RX RS ID=10:30:35 UTC ALE400 1598 Hz 0 MHz - - -*/ - - // Reuse the HAL CMD and Data Buffers to build messages from TCP stream - - // See if sequence split over a packet boundary - - if (TNC->CmdEsc == 23) - { - TNC->CmdEsc = 0; - goto CommentEsc; - } - - if (TNC->CmdEsc == 29) - { - TNC->CmdEsc = 0; - goto DataEsc; - } - - if (TNC->CmdEsc == 30) - { - TNC->CmdEsc = 0; - goto CmdEsc; - } - - // No Split - - while(Len) - { - switch (*(MPTR++)) - { - case 29: // Data Char - - Len--; - DataEsc: - if (Len) - { - TNC->DataBuffer[TNC->DataLen++] = *MPTR; - MPTR++; - Len--; - goto OuterLoop; - } - - TNC->CmdEsc = 29; - - if (TNC->DataLen) - ProcessMSPKData(TNC); - - - return; // Nothing left - - case 30: - - Len --; - CmdEsc: - while (Len) - { - if (*MPTR == 31) // End of String - { - ProcessMSPKCmd(TNC); - TNC->CmdLen = 0; - - // Process any data left in buffer - - MPTR++; - Len--; - goto OuterLoop; - } - - TNC->CmdBuffer[TNC->CmdLen++] = *MPTR; - MPTR++; - Len--; - } - - TNC->CmdEsc = 30; - return; // Nothing left - - case 23: // Server Comment - - Len --; - CommentEsc: - while (Len) - { - if (*MPTR == 24) // End of String - { - // Process Comment - - ProcessMSPKCmd(TNC); - TNC->CmdLen = 0; - - // Process any data left in buffer - - MPTR++; - Len--; - goto OuterLoop; - } - - TNC->CmdBuffer[TNC->CmdLen++] = *MPTR; - MPTR++; - Len--; - } - - TNC->CmdEsc = 23; - return; // Nothing left - - default: - - Len--; - - } -OuterLoop:; - } - - if (TNC->DataLen) - ProcessMSPKData(TNC); -} - -VOID ProcessMSPKCmd(struct TNCINFO * TNC) -{ - TNC->CmdBuffer[TNC->CmdLen] = 0; - - if (strcmp(TNC->CmdBuffer, "SWITCH=TX") == 0) - TNC->MPSKInfo->TX = TRUE; - else - { - if (strcmp(TNC->CmdBuffer, "SWITCH=RX") == 0) - { - TNC->MPSKInfo->TX = FALSE; - - // See if a command was queued while busy - - if (TNC->CmdSet) - { - send(TNC->TCPSock, TNC->CmdSet, (int)strlen(TNC->CmdSet), 0); - free (TNC->CmdSet); - TNC->CmdSet = NULL; - } - } - else - { - Debugprintf("MPSK CMD %s", TNC->CmdBuffer); - - if (TNC->InternalCmd) - { - ULONG * buffptr = GetBuff(); - char * ptr = strstr(TNC->CmdBuffer, "OK"); - - if (ptr) - *(ptr+2) = 0; // Convert OKn to OK for BBS Connect Script - - TNC->InternalCmd = FALSE; - - if (buffptr) - { - buffptr[1] = sprintf((UCHAR *)&buffptr[2], "MPSK} %s\r", TNC->CmdBuffer); - C_Q_ADD(&TNC->Streams[0].PACTORtoBPQ_Q, buffptr); - } - - if (strstr(TNC->CmdBuffer, "STOP_SELECTIVE_CALL_ARQ_FAE OK")) - TNC->Streams[0].Connecting = FALSE; - - } - } - } -} - -VOID ProcessMSPKComment(struct TNCINFO * TNC) -{ - TNC->CmdBuffer[TNC->CmdLen] = 0; - Debugprintf("MPSK Comment %s", TNC->CmdBuffer); -} - -static int UnStuff(UCHAR * inbuff, int len) -{ - int i,txptr=0; - UCHAR c; - UCHAR * outbuff = inbuff; - - for (i = 0; i < len; i++) - { - c = inbuff[i]; - - if (c == 0xc0) - c = inbuff[++i] - 0x20; - - outbuff[txptr++]=c; - } - - return txptr; -} - -VOID ProcessMSPKData(struct TNCINFO * TNC) -{ - UINT * buffptr; - int Stream = 0; - struct STREAMINFO * STREAM = &TNC->Streams[0]; - char * ptr; - int Len = TNC->DataLen; - - TNC->DataBuffer[TNC->DataLen] = 0; - - // Process Data - - if (STREAM->Connected) - { - ptr = strstr(TNC->DataBuffer, "[End of connection"); - - if (ptr) - { - // Disconnect - - TNC->DataLen = 0; - - if (STREAM->DiscWhenAllSent) - return; // Already notified - - if (STREAM->Connecting) - { - // Report Connect Failed, and drop back to command mode - - STREAM->Connecting = FALSE; - buffptr = GetBuff(); - - if (buffptr == 0) return; // No buffers, so ignore - - buffptr[1] = sprintf((UCHAR *)&buffptr[2], "MPSK} Failure with %s\r", STREAM->RemoteCall); - - C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr); - STREAM->DiscWhenAllSent = 10; - - return; - } - - // Release Session - - STREAM->Connecting = FALSE; - STREAM->Connected = FALSE; // Back to Command Mode - STREAM->ReportDISC = TRUE; // Tell Node - - STREAM->Disconnecting = FALSE; - STREAM->DiscWhenAllSent = 10; - STREAM->FramesOutstanding = 0; - - return; - } - - // Pass to Application. Remove any transparency (hex 0xc0 used as an escape) - - buffptr = GetBuff(); - - if (TNC->DataBuffer[TNC->DataLen - 1] == 0xc0) - return; // Last char is an escape, so wait for the escaped char to arrive - - if (buffptr) - { - if (memchr(TNC->DataBuffer, 0xc0, TNC->DataLen)) - TNC->DataLen = UnStuff(TNC->DataBuffer, TNC->DataLen); - - buffptr[1] = TNC->DataLen; - memcpy(&buffptr[2], TNC->DataBuffer, TNC->DataLen); - - C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr); - - STREAM->BytesRXed += TNC->DataLen; - } - - TNC->DataLen = 0; - return; - } - - // Not Connected. We get various status messages, including Connection made, - // but they may be split across packets, or have more that one to a packet. - // I think they are all CR/LF terminated . No they aren't! - - // Look for [] this seems to be what is important - -DataLoop: - - if (memcmp(TNC->DataBuffer, "[End of TX] ARQ FAE CQ", 22) == 0) - { - // Remove string from buffer - - if (Len == 22) // Most Likely - { - TNC->DataLen = 0; - return; - } - - TNC->DataLen -= 22; - memmove(TNC->DataBuffer, &TNC->DataBuffer[22], Len - 21); //Copy Null - Len -= 22; - goto DataLoop; - - } - - ptr = strchr(TNC->DataBuffer, '['); - - if (ptr) - { - // Start of a significant Message - - char * eptr = strchr(TNC->DataBuffer, ']'); - char CallFrom[20]; - char * cptr ; - - if (eptr == 0) - return; // wait for matching [] - - cptr = strstr(TNC->DataBuffer, "[Connection made with "); - - // TNC->DataLen -= LineLen; - // memmove(TNC->DataBuffer, &TNC->DataBuffer[LineLen], 1 + Len - LineLen); //Copy Null - // Len -= LineLen; - // goto DataLoop; - - - if (cptr) // Have a connection - { - - // Connected - - memcpy(CallFrom, &cptr[22], 18); - cptr = strchr(CallFrom, ']'); - if (cptr) - *cptr = 0; - - if (STREAM->Connecting) - { - // Connect Complete - - STREAM->Connected = TRUE; - STREAM->Connecting = FALSE; - STREAM->ConnectTime = time(NULL); - STREAM->BytesRXed = STREAM->BytesTXed = 0; - - buffptr = GetBuff(); - if (buffptr) - { - buffptr[1] = sprintf((UCHAR *)&buffptr[2], "*** Connected to %s\r", CallFrom); - C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr); - } - } - else - { - // Incoming. Look for a free Stream - - STREAM->Connected = TRUE; - STREAM->ConnectTime = time(NULL); - STREAM->BytesRXed = STREAM->BytesTXed = 0; - - UpdateMH(TNC, CallFrom, '+', 'I'); - - ProcessIncommingConnect(TNC, CallFrom, Stream, FALSE); - - if (HFCTEXTLEN) - { - if (HFCTEXTLEN > 1) - SendData(TNC, HFCTEXT, HFCTEXTLEN); - } - else - { - if (FULL_CTEXT) - { - int Len = CTEXTLEN, CTPaclen = 50; - int Next = 0; - - while (Len > CTPaclen) // CTEXT Paclen - { - SendData(TNC, &CTEXTMSG[Next], CTPaclen); - Next += CTPaclen; - Len -= CTPaclen; - } - SendData(TNC, &CTEXTMSG[Next], Len); - } - } - } - } - - } - - // Doesnt contain [ - just discard - - TNC->DataLen = 0; - Debugprintf(TNC->DataBuffer); - return; - -} - - - -/* - buffptr = GetBuff(); - if (buffptr == 0) return; // No buffers, so ignore - - buffptr[1] = RXHeader->DataLength; - memcpy(&buffptr[2], Message, RXHeader->DataLength); - - C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr); - return; - - return; - - - case 'd': // Disconnected - - - - case 'C': - - // Connect. Can be Incoming or Outgoing - - // "*** CONNECTED To Station [CALLSIGN]" When the other station starts the connection - // "*** CONNECTED With [CALLSIGN]" When we started the connection - - */ - - -VOID SendData(struct TNCINFO * TNC, char * Msg, int MsgLen) -{ - // Preceed each data byte with 25 (decimal) - - char * NewMsg = malloc (MsgLen * 4); - int n; - UCHAR c; - int ExtraLen = 0; - char * ptr = NewMsg; - char * inptr = Msg; - SOCKET sock = TNCInfo[MasterPort[TNC->Port]]->TCPSock; - - TNC->Streams[0].BytesTXed += MsgLen; - - for (n = 0; n < MsgLen; n++) - { - *(ptr++) = 25; - c = *inptr++; - - if (c < 0x20 || c == 0xc0) - { - if (c != 0x0d) - { - *ptr++ = 0x0c0; - *(ptr++) = 25; - *ptr++ = c + 0x20; - ExtraLen += 2; - continue; - } - } - - *ptr++ = c; - } - - send(sock, NewMsg, MsgLen * 2 + ExtraLen, 0); - - free(NewMsg); -} - -VOID TidyClose(struct TNCINFO * TNC, int Stream) -{ - char Command[80]; - int len; - - len = sprintf(Command,"%cSTOP_SELECTIVE_CALL_ARQ_FAE\x1b", '\x1a'); - if (TNC->MPSKInfo->TX) - TNC->CmdSet = TNC->CmdSave = _strdup(Command); // Savde till not transmitting - else - send(TNC->TCPSock, Command, len, 0); -} - -VOID ForcedClose(struct TNCINFO * TNC, int Stream) -{ - TidyClose(TNC, Stream); // I don't think Hostmode has a DD -} - -VOID CloseComplete(struct TNCINFO * TNC, int Stream) -{ - char Cmd[80]; - int Len; - - sprintf(Cmd, "%d SCANSTART 15", TNC->Port); - Rig_Command(-1, Cmd); - - Cmd[0] = 0; - - if (TNC->MPSKInfo->DefaultMode[0]) - sprintf(Cmd, "%cDIGITAL MODE %s\x1b", '\x1a', TNC->MPSKInfo->DefaultMode); - - if (TNC->MPSKInfo->Beacon) - sprintf(Cmd, "%s%cBEACON_ARQ_FAE\x1b", Cmd, '\x1a'); - - Len = (int)strlen(Cmd); - - if(Len) - { - if (TNC->MPSKInfo->TX) - TNC->CmdSet = TNC->CmdSave = _strdup(Cmd); // Savde till not transmitting - else - send(TNC->TCPSock, Cmd, Len, 0); - } -} - +/*
+Copyright 2001-2018 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
+*/
+
+//
+// DLL to provide interface to allow G8BPQ switch to use MultoPSK ALE400 Mode
+//
+// Uses BPQ EXTERNAL interface
+//
+
+
+#define _CRT_SECURE_NO_DEPRECATE
+
+#define _CRT_SECURE_NO_DEPRECATE
+
+#include "CHeaders.h"
+#include <stdio.h>
+#include <time.h>
+
+#include "tncinfo.h"
+
+#include "bpq32.h"
+
+#define VERSION_MAJOR 2
+#define VERSION_MINOR 0
+
+#define SD_RECEIVE 0x00
+#define SD_SEND 0x01
+#define SD_BOTH 0x02
+
+#define TIMESTAMP 352
+
+#define CONTIMEOUT 1200
+
+
+
+#define AGWHDDRLEN sizeof(struct AGWHEADER)
+
+extern int (WINAPI FAR *GetModuleFileNameExPtr)();
+
+//int ResetExtDriver(int num);
+extern char * PortConfig[33];
+
+struct TNCINFO * TNCInfo[34]; // Records are Malloc'd
+
+static void ConnecttoMPSKThread(void * portptr);
+
+void CreateMHWindow();
+int Update_MH_List(struct in_addr ipad, char * call, char proto);
+
+static int ConnecttoMPSK();
+static int ProcessReceivedData(int bpqport);
+static int ProcessLine(char * buf, int Port);
+int KillTNC(struct TNCINFO * TNC);
+int RestartTNC(struct TNCINFO * TNC);
+VOID ProcessMPSKPacket(struct TNCINFO * TNC, char * Message, int Len);
+struct TNCINFO * GetSessionKey(char * key, struct TNCINFO * TNC);
+static VOID SendData(struct TNCINFO * TNC, char * Msg, int MsgLen);
+static VOID DoMonitorHddr(struct TNCINFO * TNC, struct AGWHEADER * RXHeader, UCHAR * Msg);
+VOID SendRPBeacon(struct TNCINFO * TNC);
+
+char * strlop(char * buf, char delim);
+
+extern UCHAR BPQDirectory[];
+
+#define MAXBPQPORTS 32
+#define MAXMPSKPORTS 16
+
+//LOGFONT LFTTYFONT ;
+
+//HFONT hFont ;
+
+static int MPSKChannel[MAXBPQPORTS+1]; // BPQ Port to MPSK Port
+static int BPQPort[MAXMPSKPORTS][MAXBPQPORTS+1]; // MPSK Port and Connection to BPQ Port
+
+static int MasterPort[MAXBPQPORTS+1]; // Pointer to first BPQ port for a specific MPSK host
+
+// Each port may be on a different machine. We only open one connection to each MPSK instance
+
+static char * MPSKSignon[MAXBPQPORTS+1]; // Pointer to message for secure signin
+
+static unsigned int MPSKInst = 0;
+static int AttachedProcesses=0;
+
+static HWND hResWnd,hMHWnd;
+static BOOL GotMsg;
+
+static HANDLE STDOUT=0;
+
+//SOCKET sock;
+
+static SOCKADDR_IN sinx;
+static SOCKADDR_IN rxaddr;
+static SOCKADDR_IN destaddr[MAXBPQPORTS+1];
+
+static int addrlen=sizeof(sinx);
+
+//static short MPSKPort=0;
+
+static time_t ltime,lasttime[MAXBPQPORTS+1];
+
+static BOOL CONNECTING[MAXBPQPORTS+1];
+static BOOL CONNECTED[MAXBPQPORTS+1];
+
+//HANDLE hInstance;
+
+
+static fd_set readfs;
+static fd_set writefs;
+static fd_set errorfs;
+static struct timeval timeout;
+
+#ifndef LINBPQ
+
+static BOOL CALLBACK EnumTNCWindowsProc(HWND hwnd, LPARAM lParam)
+{
+ char wtext[200];
+ struct TNCINFO * TNC = (struct TNCINFO *)lParam;
+ UINT ProcessId;
+ char FN[MAX_PATH] = "";
+
+ if (TNC->ProgramPath == NULL)
+ return FALSE;
+
+ GetWindowText(hwnd, wtext, 199);
+
+ if (strstr(wtext,"* MULTIPSK"))
+ {
+ GetWindowThreadProcessId(hwnd, &ProcessId);
+
+ TNC->PID = ProcessId;
+ return FALSE;
+ }
+
+ return (TRUE);
+}
+
+#endif
+
+static size_t ExtProc(int fn, int port, PDATAMESSAGE buff)
+{
+ PMSGWITHLEN buffptr;
+
+ unsigned int txlen=0;
+ struct TNCINFO * TNC = TNCInfo[port];
+ int Stream = 0;
+ struct STREAMINFO * STREAM;
+ int TNCOK;
+
+ if (TNC == NULL)
+ return 0; // Port not defined
+
+ // Look for attach on any call
+
+ for (Stream = 0; Stream <= TNC->MPSKInfo->MaxSessions; Stream++)
+ {
+ STREAM = &TNC->Streams[Stream];
+
+ if (TNC->PortRecord->ATTACHEDSESSIONS[Stream] && TNC->Streams[Stream].Attached == 0)
+ {
+ char Cmd[80];
+ int len;
+
+ // New Attach
+
+ int calllen;
+ STREAM->Attached = TRUE;
+
+ calllen = ConvFromAX25(TNC->PortRecord->ATTACHEDSESSIONS[Stream]->L4USER, STREAM->MyCall);
+ STREAM->MyCall[calllen] = 0;
+ STREAM->FramesOutstanding = 0;
+
+ // Stop Scanning
+
+ sprintf(Cmd, "%d SCANSTOP", TNC->Port);
+ Rig_Command(-1, Cmd);
+
+ len = sprintf(Cmd, "%cSTOP_BEACON_ARQ_FAE\x1b", '\x1a');
+
+ if (TNC->MPSKInfo->TX)
+ TNC->CmdSet = TNC->CmdSave = _strdup(Cmd); // Savde till not transmitting
+ else
+ send(TNC->TCPSock, Cmd, len, 0);
+
+ }
+ }
+
+ switch (fn)
+ {
+ case 1: // poll
+
+ if (MasterPort[port] == port)
+ {
+ // Only on first port using a host
+
+ if (TNC->CONNECTED == FALSE && TNC->CONNECTING == FALSE)
+ {
+ // See if time to reconnect
+
+ time( <ime );
+ if (ltime-lasttime[port] >9 )
+ {
+ ConnecttoMPSK(port);
+ lasttime[port]=ltime;
+ }
+ }
+
+ FD_ZERO(&readfs);
+
+ if (TNC->CONNECTED) FD_SET(TNC->TCPSock,&readfs);
+
+
+ FD_ZERO(&writefs);
+
+ if (TNC->CONNECTING) FD_SET(TNC->TCPSock,&writefs); // Need notification of Connect
+
+ if (TNC->BPQtoWINMOR_Q) FD_SET(TNC->TCPSock,&writefs); // Need notification of busy clearing
+
+
+
+ FD_ZERO(&errorfs);
+
+ if (TNC->CONNECTING ||TNC->CONNECTED) FD_SET(TNC->TCPSock,&errorfs);
+
+ if (select((int)TNC->TCPSock+ 1, &readfs, &writefs, &errorfs, &timeout) > 0)
+ {
+ // See what happened
+
+ if (FD_ISSET(TNC->TCPSock,&readfs))
+ {
+ // data available
+
+ ProcessReceivedData(port);
+ }
+
+ if (FD_ISSET(TNC->TCPSock,&writefs))
+ {
+ // Connect success
+
+ TNC->CONNECTED = TRUE;
+ TNC->CONNECTING = FALSE;
+
+ // If required, send signon
+
+ send(TNC->TCPSock,"\x1a", 1, 0);
+ send(TNC->TCPSock,"DIGITAL MODE ?", 14, 0);
+ send(TNC->TCPSock,"\x1b", 1, 0);
+
+// EnumWindows(EnumTNCWindowsProc, (LPARAM)TNC);
+ }
+
+ if (FD_ISSET(TNC->TCPSock,&errorfs))
+ {
+
+ // if connecting, then failed, if connected then has just disconnected
+
+// if (CONNECTED[port])
+// if (!CONNECTING[port])
+// {
+// i=sprintf(ErrMsg, "MPSK Connection lost for BPQ Port %d\r\n", port);
+// WritetoConsole(ErrMsg);
+// }
+
+ CONNECTING[port]=FALSE;
+ CONNECTED[port]=FALSE;
+
+ }
+
+ }
+
+ }
+
+ // See if any frames for this port
+
+ for (Stream = 0; Stream <= TNC->MPSKInfo->MaxSessions; Stream++)
+ {
+ STREAM = &TNC->Streams[Stream];
+
+ // Have to time out connects, as TNC doesn't report failure
+
+ if (STREAM->Connecting)
+ {
+ STREAM->Connecting--;
+
+ if (STREAM->Connecting == 0)
+ {
+ // Report Connect Failed, and drop back to command mode
+
+ buffptr = GetBuff();
+
+ if (buffptr)
+ {
+ buffptr->Len = sprintf(buffptr->Data, "MPSK} Failure with %s\r", STREAM->RemoteCall);
+ C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr);
+ }
+
+ STREAM->Connected = FALSE; // Back to Command Mode
+ STREAM->DiscWhenAllSent = 10;
+
+ // Send Disc to TNC
+
+ TidyClose(TNC, Stream);
+ }
+ }
+
+ if (STREAM->Attached)
+ CheckForDetach(TNC, Stream, STREAM, TidyClose, ForcedClose, CloseComplete);
+
+ if (STREAM->ReportDISC)
+ {
+ STREAM->ReportDISC = FALSE;
+ buff->PORT = Stream;
+
+ return -1;
+ }
+
+ // if Busy, send buffer status poll
+
+ if (STREAM->PACTORtoBPQ_Q == 0)
+ {
+ if (STREAM->DiscWhenAllSent)
+ {
+ STREAM->DiscWhenAllSent--;
+ if (STREAM->DiscWhenAllSent == 0)
+ STREAM->ReportDISC = TRUE; // Dont want to leave session attached. Causes too much confusion
+ }
+ }
+ else
+ {
+ int datalen;
+
+ buffptr=Q_REM(&STREAM->PACTORtoBPQ_Q);
+
+ datalen = buffptr->Len;
+
+ buff->PORT = Stream;
+ buff->PID = 0xf0;
+ memcpy(buff->L2DATA, buffptr->Data, datalen); // Data goes to +7, but we have an extra byte
+ datalen += MSGHDDRLEN + 1;
+
+ PutLengthinBuffer((PDATAMESSAGE)buff, datalen);
+
+ ReleaseBuffer(buffptr);
+
+ return (1);
+ }
+ }
+
+ if (TNC->PortRecord->UI_Q)
+ {
+ struct _MESSAGE * buffptr;
+
+ SOCKET Sock;
+ buffptr = Q_REM(&TNC->PortRecord->UI_Q);
+
+ Sock = TNCInfo[MasterPort[port]]->TCPSock;
+
+ ReleaseBuffer((UINT *)buffptr);
+ }
+
+
+ return (0);
+
+
+
+ case 2: // send
+
+
+ if (!TNCInfo[MasterPort[port]]->CONNECTED) return 0; // Don't try if not connected to TNC
+
+ Stream = buff->PORT;
+
+ STREAM = &TNC->Streams[Stream];
+
+// txlen=(buff[6]<<8) + buff[5] - 8;
+
+ txlen = GetLengthfromBuffer((PDATAMESSAGE)buff) - 8;
+
+ if (STREAM->Connected)
+ {
+ SendData(TNC, buff->L2DATA, txlen);
+ }
+ else
+ {
+ char Command[80];
+ int len;
+
+ buff->L2DATA[txlen] = 0;
+ _strupr(buff->L2DATA);
+
+ if (_memicmp(&buff[8], "D\r", 2) == 0)
+ {
+ TidyClose(TNC, buff->PORT);
+ STREAM->ReportDISC = TRUE; // Tell Node
+ return 0;
+ }
+
+ // See if Local command (eg RADIO)
+
+ if (_memicmp(buff->L2DATA, "RADIO ", 6) == 0)
+ {
+ sprintf(buff->L2DATA, "%d %s", TNC->Port, &buff->L2DATA[6]);
+
+ if (Rig_Command(TNC->PortRecord->ATTACHEDSESSIONS[0]->L4CROSSLINK->CIRCUITINDEX, buff->L2DATA))
+ {
+ }
+ else
+ {
+ buffptr = (PMSGWITHLEN)GetBuff();
+
+ if (buffptr == 0) return 1; // No buffers, so ignore
+
+ buffptr->Len= sprintf((UCHAR *)&buffptr->Data, "%s", buff->L2DATA);
+ C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr);
+ }
+ return 1;
+ }
+
+ if (STREAM->Connecting && _memicmp(&buff[8], "ABORT", 5) == 0)
+ {
+ len = sprintf(Command,"%cSTOP_SELECTIVE_CALL_ARQ_FAE\x1b", '\x1a');
+
+ if (TNC->MPSKInfo->TX)
+ TNC->CmdSet = TNC->CmdSave = _strdup(Command); // Save till not transmitting
+ else
+ send(TNC->TCPSock, Command, len, 0);
+
+ TNC->InternalCmd = TRUE;
+ return (0);
+ }
+
+ if (_memicmp(&buff[8], "MODE", 4) == 0)
+ {
+ buff->L2DATA[txlen - 1] = 0; // Remove CR
+
+ len = sprintf(Command,"%cDIGITAL MODE %s\x1b", '\x1a', &buff->L2DATA[5]);
+
+ if (TNC->MPSKInfo->TX)
+ TNC->CmdSet = TNC->CmdSave = _strdup(Command); // Save till not transmitting
+ else
+ send(TNC->TCPSock, Command, len, 0);
+
+ TNC->InternalCmd = TRUE;
+ return (0);
+ }
+
+
+ if (_memicmp(&buff[8], "INUSE?", 6) == 0)
+ {
+ // Return Error if in use, OK if not
+
+ UINT * buffptr = GetBuff();
+ int s = 0;
+
+ while(s <= TNC->MPSKInfo->MaxSessions)
+ {
+ if (s != Stream)
+ {
+ if (TNC->PortRecord->ATTACHEDSESSIONS[s])
+ {
+ buffptr[1] = sprintf((UCHAR *)&buffptr[2], "MPSK} Error - In use\r");
+ C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr);
+ return 1; // Busy
+ }
+ }
+ s++;
+ }
+ buffptr[1] = sprintf((UCHAR *)&buffptr[2], "MPSK} Ok - Not in use\r");
+ C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr);
+
+ return 1;
+ }
+
+ // See if a Connect Command.
+
+ if (toupper(buff->L2DATA[0]) == 'C' && buff->L2DATA[1] == ' ' && txlen > 2) // Connect
+ {
+ char * ptr;
+ char * context;
+
+ buff->L2DATA[txlen] = 0;
+ _strupr(buff->L2DATA);
+
+ memset(STREAM->RemoteCall, 0, 10);
+
+ ptr = strtok_s(&buff->L2DATA[2], " ,\r", &context);
+ strcpy(STREAM->RemoteCall, ptr);
+
+ len = sprintf(Command,"%cCALLSIGN_TO_CALL_ARQ_FAE %s%c%cSELECTIVE_CALL_ARQ_FAE\x1b",
+ '\x1a', STREAM->RemoteCall, '\x1b', '\x1a');
+
+ if (TNC->MPSKInfo->TX)
+ TNC->CmdSet = TNC->CmdSave = _strdup(Command); // Save till not transmitting
+ else
+ send(TNC->TCPSock, Command, len, 0);
+
+ STREAM->Connecting = TNC->MPSKInfo->ConnTimeOut; // It doesn't report failure
+
+// sprintf(Status, "%s Connecting to %s", TNC->Streams[0].MyCall, TNC->Streams[0].RemoteCall);
+// SetDlgItemText(TNC->hDlg, IDC_TNCSTATE, Status);
+
+ return 0;
+ }
+
+ // Send any other command to Multipsk
+
+ buff->L2DATA[txlen - 1] = 0;
+ _strupr(&buff->L2DATA[0]);
+
+ len = sprintf(Command,"%c%s\x1b", '\x1a', buff->L2DATA);
+
+ if (TNC->MPSKInfo->TX)
+ TNC->CmdSet = TNC->CmdSave = _strdup(Command); // Save till not transmitting
+ else
+ send(TNC->TCPSock, Command, len, 0);
+
+ TNC->InternalCmd = TRUE;
+
+ }
+
+ return (0);
+
+ case 3:
+
+ Stream = buff->PORT;
+
+ TNCOK = TNCInfo[MasterPort[port]]->CONNECTED;
+
+ STREAM = &TNC->Streams[Stream];
+
+ if (STREAM->FramesOutstanding > 8)
+ return (1 | TNCOK << 8 | STREAM->Disconnecting << 15);
+
+ return TNCOK << 8 | STREAM->Disconnecting << 15; // OK, but lock attach if disconnecting
+
+ break;
+
+ case 4: // reinit
+
+ shutdown(TNC->TCPSock, SD_BOTH);
+ Sleep(100);
+
+ closesocket(TNC->TCPSock);
+ TNC->CONNECTED = FALSE;
+
+ if (TNC->PID && TNC->WeStartedTNC)
+ {
+ KillTNC(TNC);
+ RestartTNC(TNC);
+ }
+
+ return (0);
+
+ case 5: // Close
+
+ shutdown(TNC->TCPSock, SD_BOTH);
+ Sleep(100);
+
+ closesocket(TNC->TCPSock);
+
+ if (TNC->PID && TNC->WeStartedTNC)
+ {
+ KillTNC(TNC);
+ }
+
+ return 0;
+ }
+
+ return 0;
+}
+
+#ifndef LINBPQ
+
+static KillTNC(struct TNCINFO * TNC)
+{
+ HANDLE hProc;
+
+ if (TNC->PTTMode)
+ Rig_PTT(TNC->RIG, FALSE); // Make sure PTT is down
+
+ if (TNC->PID == 0) return 0;
+
+ hProc = OpenProcess(PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, TNC->PID);
+
+ if (hProc)
+ {
+ TerminateProcess(hProc, 0);
+ CloseHandle(hProc);
+ }
+
+ TNC->PID = 0; // So we don't try again
+
+ return 0;
+}
+
+static RestartTNC(struct TNCINFO * TNC)
+{
+ STARTUPINFO SInfo; // pointer to STARTUPINFO
+ PROCESS_INFORMATION PInfo; // pointer to PROCESS_INFORMATION
+ char HomeDir[MAX_PATH];
+ int i, ret;
+
+ SInfo.cb=sizeof(SInfo);
+ SInfo.lpReserved=NULL;
+ SInfo.lpDesktop=NULL;
+ SInfo.lpTitle=NULL;
+ SInfo.dwFlags=0;
+ SInfo.cbReserved2=0;
+ SInfo.lpReserved2=NULL;
+
+ if (TNC->ProgramPath)
+ {
+ strcpy(HomeDir, TNC->ProgramPath);
+ i = strlen(HomeDir);
+
+ while(--i)
+ {
+ if (HomeDir[i] == '/' || HomeDir[i] == '\\')
+ {
+ HomeDir[i] = 0;
+ break;
+ }
+ }
+ ret = CreateProcess(TNC->ProgramPath, "MultiPSK TCP_IP_ON", NULL, NULL, FALSE,0 ,NULL ,HomeDir, &SInfo, &PInfo);
+
+ if (ret)
+ TNC->PID = PInfo.dwProcessId;
+
+ return ret;
+ }
+ return 0;
+}
+#endif
+
+UINT MPSKExtInit(EXTPORTDATA * PortEntry)
+{
+ int i, port;
+ char Msg[255];
+ struct TNCINFO * TNC;
+ char * ptr;
+
+ //
+ // Will be called once for each MPSK port to be mapped to a BPQ Port
+ // The MPSK port number is in CHANNEL - A=0, B=1 etc
+ //
+ // 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 ExtProc;
+ }
+
+ TNC->Port = port;
+
+ 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->PERMITGATEWAY = TRUE; // Can change ax.25 call on each stream
+ PortEntry->PORTCONTROL.PORTQUALITY = 0;
+ PortEntry->SCANCAPABILITIES = NONE; // Scan Control - None
+
+ if (PortEntry->PORTCONTROL.PORTPACLEN == 0)
+ PortEntry->PORTCONTROL.PORTPACLEN = 64;
+
+ ptr=strchr(TNC->NodeCall, ' ');
+ if (ptr) *(ptr) = 0; // Null Terminate
+
+ TNC->Hardware = H_MPSK;
+
+ MPSKChannel[port] = PortEntry->PORTCONTROL.CHANNELNUM-65;
+
+ PortEntry->MAXHOSTMODESESSIONS = 1;
+
+ i=sprintf(Msg,"MPSK Host %s Port %d \n",
+ TNC->HostName, TNC->TCPPort);
+
+ WritetoConsole(Msg);
+
+ // See if we already have a port for this host
+
+ MasterPort[port] = port;
+
+ for (i = 1; i < port; i++)
+ {
+ if (i == port) continue;
+
+ if (TNCInfo[i] && TNCInfo[i]->TCPPort == TNC->TCPPort &&
+ _stricmp(TNCInfo[i]->HostName, TNC->HostName) == 0)
+ {
+ MasterPort[port] = i;
+ break;
+ }
+ }
+
+ BPQPort[PortEntry->PORTCONTROL.CHANNELNUM-65][MasterPort[port]] = port;
+
+#ifndef LINBPQ
+ if (MasterPort[port] == port)
+ {
+ if (EnumWindows(EnumTNCWindowsProc, (LPARAM)TNC))
+ if (TNC->ProgramPath)
+ TNC->WeStartedTNC = RestartTNC(TNC);
+
+ ConnecttoMPSK(port);
+ }
+#endif
+ time(&lasttime[port]); // Get initial time value
+
+// SendMessage(0x40eaa, WM_COMMAND, 0x03000eaa, 0x40eaa);
+
+ return ExtProc;
+
+}
+
+
+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;
+ struct MPSKINFO * AGW;
+
+ 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] = zalloc(sizeof(struct TNCINFO));
+ AGW = TNC->MPSKInfo = zalloc(sizeof(struct MPSKINFO)); // AGW Sream Mode Specific Data
+
+ AGW->MaxSessions = 10;
+ AGW->ConnTimeOut = CONTIMEOUT;
+
+ 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);
+
+ TNC->TCPPort = atoi(p_port);
+
+ TNC->destaddr.sin_family = AF_INET;
+ TNC->destaddr.sin_port = htons(TNC->TCPPort);
+ 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 (_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, "CONTIMEOUT", 10) == 0)
+ AGW->ConnTimeOut = atoi(&buf[11]) * 10;
+ else
+ if (_memicmp(buf, "UPDATEMAP", 9) == 0)
+ TNC->PktUpdateMap = TRUE;
+ else
+ if (_memicmp(buf, "ALEBEACON", 9) == 0) // Send Beacon after each session
+ TNC->MPSKInfo->Beacon = TRUE;
+ else
+ if (_memicmp(buf, "DEFAULTMODE", 11) == 0) // Send Beacon after each session
+ strcpy(TNC->MPSKInfo->DefaultMode, &buf[12]);
+ else
+
+ strcat (TNC->InitScript, buf);
+ }
+
+
+ return (TRUE);
+}
+
+static int ConnecttoMPSK(int port)
+{
+ _beginthread(ConnecttoMPSKThread, 0, (void *)(size_t)port);
+
+ return 0;
+}
+
+VOID ConnecttoMPSKThread(void * portptr)
+{
+
+ int port = (int)(size_t)portptr;
+ char Msg[255];
+ int err,i;
+ u_long param=1;
+ BOOL bcopt=TRUE;
+ struct hostent * HostEnt;
+ struct TNCINFO * TNC = TNCInfo[port];
+
+ Sleep(5000); // Allow init to complete
+
+ TNC->destaddr.sin_addr.s_addr = inet_addr(TNC->HostName);
+
+ if (TNC->destaddr.sin_addr.s_addr == INADDR_NONE)
+ {
+ // Resolve name to address
+
+ HostEnt = gethostbyname (TNC->HostName);
+
+ if (!HostEnt) return; // Resolve failed
+
+ memcpy(&TNC->destaddr.sin_addr.s_addr,HostEnt->h_addr,4);
+ memcpy(&TNC->Datadestaddr.sin_addr.s_addr,HostEnt->h_addr,4);
+
+ }
+
+ if (TNC->TCPSock)
+ closesocket(TNC->TCPSock);
+
+ TNC->TCPSock = 0;
+
+ TNC->TCPSock=socket(AF_INET,SOCK_STREAM,0);
+
+ if (TNC->TCPSock == INVALID_SOCKET)
+ {
+ i=sprintf(Msg, "Socket Failed for MPSK socket - error code = %d\n", WSAGetLastError());
+ WritetoConsole(Msg);
+
+ return;
+ }
+
+ sinx.sin_family = AF_INET;
+ sinx.sin_addr.s_addr = INADDR_ANY;
+ sinx.sin_port = 0;
+
+ TNC->CONNECTING = TRUE;
+
+ if (connect(TNC->TCPSock,(LPSOCKADDR) &TNC->destaddr,sizeof(TNC->destaddr)) == 0)
+ {
+ //
+ // Connected successful
+ //
+
+ TNC->CONNECTED=TRUE;
+ }
+ else
+ {
+ if (TNC->Alerted == FALSE)
+ {
+ err=WSAGetLastError();
+ i=sprintf(Msg, "Connect Failed for MPSK socket - error code = %d\n", err);
+ WritetoConsole(Msg);
+ MySetWindowText(TNC->xIDC_COMMSSTATE, "Connection to TNC failed");
+
+ TNC->Alerted = TRUE;
+ }
+
+ TNC->CONNECTING = FALSE;
+ return;
+ }
+
+ TNC->LastFreq = 0; // so V4 display will be updated
+
+ MySetWindowText(TNC->xIDC_COMMSSTATE, "Connected to MPSK TNC");
+
+ return;
+
+}
+
+static int ProcessReceivedData(int port)
+{
+ unsigned int bytes;
+ int i;
+ char ErrMsg[255];
+ char Message[500];
+ struct TNCINFO * TNC = TNCInfo[port];
+
+ // Need to extract messages from byte stream
+
+ bytes = recv(TNC->TCPSock,(char *)&Message, 500, 0);
+
+ if (bytes == SOCKET_ERROR)
+ {
+// i=sprintf(ErrMsg, "Read Failed for MPSK socket - error code = %d\r\n", WSAGetLastError());
+// WritetoConsole(ErrMsg);
+
+ closesocket(TNC->TCPSock);
+
+ TNC->CONNECTED = FALSE;
+ if (TNC->Streams[0].Attached)
+ TNC->Streams[0].ReportDISC = TRUE;
+
+ return (0);
+ }
+
+ if (bytes == 0)
+ {
+ // zero bytes means connection closed
+
+ i=sprintf(ErrMsg, "MPSK Connection closed for BPQ Port %d\n", port);
+ WritetoConsole(ErrMsg);
+
+ TNC->CONNECTED = FALSE;
+ if (TNC->Streams[0].Attached)
+ TNC->Streams[0].ReportDISC = TRUE;
+
+ return (0);
+ }
+
+ // Have some data
+
+ ProcessMPSKPacket(TNC, Message, bytes); // Data may be for another port
+
+ return (0);
+
+}
+
+VOID ProcessMSPKCmd(struct TNCINFO * TNC);
+VOID ProcessMSPKComment(struct TNCINFO * TNC);
+VOID ProcessMSPKData(struct TNCINFO * TNC);
+
+VOID ProcessMPSKPacket(struct TNCINFO * TNC, char * Message, int Len)
+{
+ char * MPTR = Message;
+
+/*
+3) each text character transmitted by the client to the server (for the Multipsk TX text editor) must be preceded by the character CHR(25) or CHR(22) in the case of a special link (KISS in Packet or Pax, for example).
+
+4) each command string transmitted by the client to the server must be preceded by the character CHR(26) and finished by CHR(27),
+
+5) each character effectively transmitted by Multipsk to the transceiver and transmitted to the client is preceded by the character CHR(28),
+
+6) each character received by Multipsk and transmitted to the client is preceded by the character CHR(29),
+
+7) each command string transmitted by the server to the client must be preceded by the character CHR(30) and finished by CHR(31),
+
+8) all commands (written in readable text ) will have an answer (see further for details),
+
+9) each server comment (Call ID or RS ID reception, switch to RX or to TX) string transmitted by the server to the client must be preceded by a string: "CHR(23)RX CALL ID=", "CHR(23)RX RS ID=", "CHR(23)SWITCH=RX", "CHR(23) SWITCH=TX", and finished by CHR(24).
+
+10) each server command, for the transceiver control, transmitted by the server to the client must be preceded by the string "CHR(23) XCVR=" and finished by CHR(24).
+
+Data
+
+End of TX] ARQ FAE CQ[End of TX] ARQ FAE CQ[End of TX] call "THIS I[End of TX] end of link to GM8BPQ[End of TX] sounding "THIS WAS"[End of TX] ARQ FAE CQ[End of TX] ARQ FAE CQ[End of TX] ARQ FAE CQ[End of TX] ARQ FAE CQFAE BEACON OH5RM Kouvola KP30JR
+[End of TX] ARQ FAE selective callGM8BPQ DE OH5RM
+
+[Connection made with OH5RM]
+
+
+18103 but I have to go out to change antenna
+
+[End of connection with OH5RM]FAE BEACON OH5RM Kouvola KP30JR
+S" to GM8BPQ
+
+10:23:55 AM Comment: SWITCH=RX
+10:24:00 AM Comment: RX RS ID=10:24:00 UTC ALE400 1609 Hz 0 MHz
+10:24:19 AM Comment: RX RS ID=10:24:19 UTC ALE400 1604 Hz 0 MHz
+10:25:04 AM Comment: SWITCH=TX
+10:25:07 AM Comment: SWITCH=RX
+10:25:15 AM Comment: SWITCH=TX
+:30:22 AM Comment: SWITCH=RX
+10:30:25 AM Comment: SWITCH=TX
+10:30:27 AM Comment: SWITCH=RX
+10:30:35 AM Comment: RX RS ID=10:30:35 UTC ALE400 1598 Hz 0 MHz
+
+
+*/
+
+ // Reuse the HAL CMD and Data Buffers to build messages from TCP stream
+
+ // See if sequence split over a packet boundary
+
+ if (TNC->CmdEsc == 23)
+ {
+ TNC->CmdEsc = 0;
+ goto CommentEsc;
+ }
+
+ if (TNC->CmdEsc == 29)
+ {
+ TNC->CmdEsc = 0;
+ goto DataEsc;
+ }
+
+ if (TNC->CmdEsc == 30)
+ {
+ TNC->CmdEsc = 0;
+ goto CmdEsc;
+ }
+
+ // No Split
+
+ while(Len)
+ {
+ switch (*(MPTR++))
+ {
+ case 29: // Data Char
+
+ Len--;
+ DataEsc:
+ if (Len)
+ {
+ TNC->DataBuffer[TNC->DataLen++] = *MPTR;
+ MPTR++;
+ Len--;
+ goto OuterLoop;
+ }
+
+ TNC->CmdEsc = 29;
+
+ if (TNC->DataLen)
+ ProcessMSPKData(TNC);
+
+
+ return; // Nothing left
+
+ case 30:
+
+ Len --;
+ CmdEsc:
+ while (Len)
+ {
+ if (*MPTR == 31) // End of String
+ {
+ ProcessMSPKCmd(TNC);
+ TNC->CmdLen = 0;
+
+ // Process any data left in buffer
+
+ MPTR++;
+ Len--;
+ goto OuterLoop;
+ }
+
+ TNC->CmdBuffer[TNC->CmdLen++] = *MPTR;
+ MPTR++;
+ Len--;
+ }
+
+ TNC->CmdEsc = 30;
+ return; // Nothing left
+
+ case 23: // Server Comment
+
+ Len --;
+ CommentEsc:
+ while (Len)
+ {
+ if (*MPTR == 24) // End of String
+ {
+ // Process Comment
+
+ ProcessMSPKCmd(TNC);
+ TNC->CmdLen = 0;
+
+ // Process any data left in buffer
+
+ MPTR++;
+ Len--;
+ goto OuterLoop;
+ }
+
+ TNC->CmdBuffer[TNC->CmdLen++] = *MPTR;
+ MPTR++;
+ Len--;
+ }
+
+ TNC->CmdEsc = 23;
+ return; // Nothing left
+
+ default:
+
+ Len--;
+
+ }
+OuterLoop:;
+ }
+
+ if (TNC->DataLen)
+ ProcessMSPKData(TNC);
+}
+
+VOID ProcessMSPKCmd(struct TNCINFO * TNC)
+{
+ TNC->CmdBuffer[TNC->CmdLen] = 0;
+
+ if (strcmp(TNC->CmdBuffer, "SWITCH=TX") == 0)
+ TNC->MPSKInfo->TX = TRUE;
+ else
+ {
+ if (strcmp(TNC->CmdBuffer, "SWITCH=RX") == 0)
+ {
+ TNC->MPSKInfo->TX = FALSE;
+
+ // See if a command was queued while busy
+
+ if (TNC->CmdSet)
+ {
+ send(TNC->TCPSock, TNC->CmdSet, (int)strlen(TNC->CmdSet), 0);
+ free (TNC->CmdSet);
+ TNC->CmdSet = NULL;
+ }
+ }
+ else
+ {
+ Debugprintf("MPSK CMD %s", TNC->CmdBuffer);
+
+ if (TNC->InternalCmd)
+ {
+ ULONG * buffptr = GetBuff();
+ char * ptr = strstr(TNC->CmdBuffer, "OK");
+
+ if (ptr)
+ *(ptr+2) = 0; // Convert OKn to OK for BBS Connect Script
+
+ TNC->InternalCmd = FALSE;
+
+ if (buffptr)
+ {
+ buffptr[1] = sprintf((UCHAR *)&buffptr[2], "MPSK} %s\r", TNC->CmdBuffer);
+ C_Q_ADD(&TNC->Streams[0].PACTORtoBPQ_Q, buffptr);
+ }
+
+ if (strstr(TNC->CmdBuffer, "STOP_SELECTIVE_CALL_ARQ_FAE OK"))
+ TNC->Streams[0].Connecting = FALSE;
+
+ }
+ }
+ }
+}
+
+VOID ProcessMSPKComment(struct TNCINFO * TNC)
+{
+ TNC->CmdBuffer[TNC->CmdLen] = 0;
+ Debugprintf("MPSK Comment %s", TNC->CmdBuffer);
+}
+
+static int UnStuff(UCHAR * inbuff, int len)
+{
+ int i,txptr=0;
+ UCHAR c;
+ UCHAR * outbuff = inbuff;
+
+ for (i = 0; i < len; i++)
+ {
+ c = inbuff[i];
+
+ if (c == 0xc0)
+ c = inbuff[++i] - 0x20;
+
+ outbuff[txptr++]=c;
+ }
+
+ return txptr;
+}
+
+VOID ProcessMSPKData(struct TNCINFO * TNC)
+{
+ UINT * buffptr;
+ int Stream = 0;
+ struct STREAMINFO * STREAM = &TNC->Streams[0];
+ char * ptr;
+ int Len = TNC->DataLen;
+
+ TNC->DataBuffer[TNC->DataLen] = 0;
+
+ // Process Data
+
+ if (STREAM->Connected)
+ {
+ ptr = strstr(TNC->DataBuffer, "[End of connection");
+
+ if (ptr)
+ {
+ // Disconnect
+
+ TNC->DataLen = 0;
+
+ if (STREAM->DiscWhenAllSent)
+ return; // Already notified
+
+ if (STREAM->Connecting)
+ {
+ // Report Connect Failed, and drop back to command mode
+
+ STREAM->Connecting = FALSE;
+ buffptr = GetBuff();
+
+ if (buffptr == 0) return; // No buffers, so ignore
+
+ buffptr[1] = sprintf((UCHAR *)&buffptr[2], "MPSK} Failure with %s\r", STREAM->RemoteCall);
+
+ C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr);
+ STREAM->DiscWhenAllSent = 10;
+
+ return;
+ }
+
+ // Release Session
+
+ STREAM->Connecting = FALSE;
+ STREAM->Connected = FALSE; // Back to Command Mode
+ STREAM->ReportDISC = TRUE; // Tell Node
+
+ STREAM->Disconnecting = FALSE;
+ STREAM->DiscWhenAllSent = 10;
+ STREAM->FramesOutstanding = 0;
+
+ return;
+ }
+
+ // Pass to Application. Remove any transparency (hex 0xc0 used as an escape)
+
+ buffptr = GetBuff();
+
+ if (TNC->DataBuffer[TNC->DataLen - 1] == 0xc0)
+ return; // Last char is an escape, so wait for the escaped char to arrive
+
+ if (buffptr)
+ {
+ if (memchr(TNC->DataBuffer, 0xc0, TNC->DataLen))
+ TNC->DataLen = UnStuff(TNC->DataBuffer, TNC->DataLen);
+
+ buffptr[1] = TNC->DataLen;
+ memcpy(&buffptr[2], TNC->DataBuffer, TNC->DataLen);
+
+ C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr);
+
+ STREAM->BytesRXed += TNC->DataLen;
+ }
+
+ TNC->DataLen = 0;
+ return;
+ }
+
+ // Not Connected. We get various status messages, including Connection made,
+ // but they may be split across packets, or have more that one to a packet.
+ // I think they are all CR/LF terminated . No they aren't!
+
+ // Look for [] this seems to be what is important
+
+DataLoop:
+
+ if (memcmp(TNC->DataBuffer, "[End of TX] ARQ FAE CQ", 22) == 0)
+ {
+ // Remove string from buffer
+
+ if (Len == 22) // Most Likely
+ {
+ TNC->DataLen = 0;
+ return;
+ }
+
+ TNC->DataLen -= 22;
+ memmove(TNC->DataBuffer, &TNC->DataBuffer[22], Len - 21); //Copy Null
+ Len -= 22;
+ goto DataLoop;
+
+ }
+
+ ptr = strchr(TNC->DataBuffer, '[');
+
+ if (ptr)
+ {
+ // Start of a significant Message
+
+ char * eptr = strchr(TNC->DataBuffer, ']');
+ char CallFrom[20];
+ char * cptr ;
+
+ if (eptr == 0)
+ return; // wait for matching []
+
+ cptr = strstr(TNC->DataBuffer, "[Connection made with ");
+
+ // TNC->DataLen -= LineLen;
+ // memmove(TNC->DataBuffer, &TNC->DataBuffer[LineLen], 1 + Len - LineLen); //Copy Null
+ // Len -= LineLen;
+ // goto DataLoop;
+
+
+ if (cptr) // Have a connection
+ {
+
+ // Connected
+
+ memcpy(CallFrom, &cptr[22], 18);
+ cptr = strchr(CallFrom, ']');
+ if (cptr)
+ *cptr = 0;
+
+ if (STREAM->Connecting)
+ {
+ // Connect Complete
+
+ STREAM->Connected = TRUE;
+ STREAM->Connecting = FALSE;
+ STREAM->ConnectTime = time(NULL);
+ STREAM->BytesRXed = STREAM->BytesTXed = 0;
+
+ buffptr = GetBuff();
+ if (buffptr)
+ {
+ buffptr[1] = sprintf((UCHAR *)&buffptr[2], "*** Connected to %s\r", CallFrom);
+ C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr);
+ }
+ }
+ else
+ {
+ // Incoming. Look for a free Stream
+
+ STREAM->Connected = TRUE;
+ STREAM->ConnectTime = time(NULL);
+ STREAM->BytesRXed = STREAM->BytesTXed = 0;
+
+ UpdateMH(TNC, CallFrom, '+', 'I');
+
+ ProcessIncommingConnect(TNC, CallFrom, Stream, FALSE);
+
+ if (HFCTEXTLEN)
+ {
+ if (HFCTEXTLEN > 1)
+ SendData(TNC, HFCTEXT, HFCTEXTLEN);
+ }
+ else
+ {
+ if (FULL_CTEXT)
+ {
+ int Len = CTEXTLEN, CTPaclen = 50;
+ int Next = 0;
+
+ while (Len > CTPaclen) // CTEXT Paclen
+ {
+ SendData(TNC, &CTEXTMSG[Next], CTPaclen);
+ Next += CTPaclen;
+ Len -= CTPaclen;
+ }
+ SendData(TNC, &CTEXTMSG[Next], Len);
+ }
+ }
+ }
+ }
+
+ }
+
+ // Doesnt contain [ - just discard
+
+ TNC->DataLen = 0;
+ Debugprintf(TNC->DataBuffer);
+ return;
+
+}
+
+
+
+/*
+ buffptr = GetBuff();
+ if (buffptr == 0) return; // No buffers, so ignore
+
+ buffptr[1] = RXHeader->DataLength;
+ memcpy(&buffptr[2], Message, RXHeader->DataLength);
+
+ C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr);
+ return;
+
+ return;
+
+
+ case 'd': // Disconnected
+
+
+
+ case 'C':
+
+ // Connect. Can be Incoming or Outgoing
+
+ // "*** CONNECTED To Station [CALLSIGN]" When the other station starts the connection
+ // "*** CONNECTED With [CALLSIGN]" When we started the connection
+
+ */
+
+
+VOID SendData(struct TNCINFO * TNC, char * Msg, int MsgLen)
+{
+ // Preceed each data byte with 25 (decimal)
+
+ char * NewMsg = malloc (MsgLen * 4);
+ int n;
+ UCHAR c;
+ int ExtraLen = 0;
+ char * ptr = NewMsg;
+ char * inptr = Msg;
+ SOCKET sock = TNCInfo[MasterPort[TNC->Port]]->TCPSock;
+
+ TNC->Streams[0].BytesTXed += MsgLen;
+
+ for (n = 0; n < MsgLen; n++)
+ {
+ *(ptr++) = 25;
+ c = *inptr++;
+
+ if (c < 0x20 || c == 0xc0)
+ {
+ if (c != 0x0d)
+ {
+ *ptr++ = 0x0c0;
+ *(ptr++) = 25;
+ *ptr++ = c + 0x20;
+ ExtraLen += 2;
+ continue;
+ }
+ }
+
+ *ptr++ = c;
+ }
+
+ send(sock, NewMsg, MsgLen * 2 + ExtraLen, 0);
+
+ free(NewMsg);
+}
+
+VOID TidyClose(struct TNCINFO * TNC, int Stream)
+{
+ char Command[80];
+ int len;
+
+ len = sprintf(Command,"%cSTOP_SELECTIVE_CALL_ARQ_FAE\x1b", '\x1a');
+ if (TNC->MPSKInfo->TX)
+ TNC->CmdSet = TNC->CmdSave = _strdup(Command); // Savde till not transmitting
+ else
+ send(TNC->TCPSock, Command, len, 0);
+}
+
+VOID ForcedClose(struct TNCINFO * TNC, int Stream)
+{
+ TidyClose(TNC, Stream); // I don't think Hostmode has a DD
+}
+
+VOID CloseComplete(struct TNCINFO * TNC, int Stream)
+{
+ char Cmd[80];
+ int Len;
+
+ sprintf(Cmd, "%d SCANSTART 15", TNC->Port);
+ Rig_Command(-1, Cmd);
+
+ Cmd[0] = 0;
+
+ if (TNC->MPSKInfo->DefaultMode[0])
+ sprintf(Cmd, "%cDIGITAL MODE %s\x1b", '\x1a', TNC->MPSKInfo->DefaultMode);
+
+ if (TNC->MPSKInfo->Beacon)
+ sprintf(Cmd, "%s%cBEACON_ARQ_FAE\x1b", Cmd, '\x1a');
+
+ Len = (int)strlen(Cmd);
+
+ if(Len)
+ {
+ if (TNC->MPSKInfo->TX)
+ TNC->CmdSet = TNC->CmdSave = _strdup(Cmd); // Savde till not transmitting
+ else
+ send(TNC->TCPSock, Cmd, Len, 0);
+ }
+}
+
diff --git a/MultiConsole.c b/MultiConsole.c index 81b3530..f574b53 100644 --- a/MultiConsole.c +++ b/MultiConsole.c @@ -919,6 +919,9 @@ LRESULT APIENTRY InputProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) DoRefresh(Cinfo);
+ Cinfo->Console->bytesRxed += Cinfo->kbptr+1;
+
+
if (Cinfo->Console->SysopChatStream)
SendUnbuffered(Cinfo->Console->SysopChatStream->BPQStream, &Cinfo->kbbuf[0], Cinfo->kbptr+1);
else
diff --git a/SCSTrackeMulti64.c b/SCSTrackeMulti64.c index 3bb2b41..a7dc3bf 100644 --- a/SCSTrackeMulti64.c +++ b/SCSTrackeMulti64.c @@ -1,1714 +1,1714 @@ -/* -Copyright 2001-2018 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 -*/ - -// -// DLL to inteface DED Host Mode TNCs to BPQ32 switch -// -// Uses BPQ EXTERNAL interface - -#define _CRT_SECURE_NO_WARNINGS -#define _CRT_SECURE_NO_DEPRECATE - -#include <stdio.h> -#include <stdlib.h> -#include "time.h" - -#define MaxStreams 10 - -#include "CHeaders.h" -#include "tncinfo.h" - -#include "bpq32.h" - -static char ClassName[]="TRACKERSTATUS"; -static char WindowTitle[] = "SCS Tracker"; -static int RigControlRow = 140; - -#define NARROWMODE 30 -#define WIDEMODE 30 // PIII only - -extern UCHAR BPQDirectory[]; - -extern char * PortConfig[33]; - -static RECT Rect; - -struct TNCINFO * TNCInfo[34]; // Records are Malloc'd - -VOID __cdecl Debugprintf(const char * format, ...); -char * strlop(char * buf, char delim); -BOOL KAMStartPort(struct PORTCONTROL * PORT); -BOOL KAMStopPort(struct PORTCONTROL * PORT); - -char NodeCall[11]; // Nodecall, Null Terminated -void WriteDebugLogLine(int Port, char Dirn, char * Msg, int MsgLen); - -static int ProcessLine(char * buf, int Port) -{ - UCHAR * ptr; - char * p_port = 0; - int BPQport; - int len=510; - struct TNCINFO * TNC; - char errbuf[256]; - - strcpy(errbuf, buf); - - BPQport = Port; - - TNC = TNCInfo[BPQport] = malloc(sizeof(struct TNCINFO)); - memset(TNC, 0, sizeof(struct TNCINFO)); - - TNC->InitScript = malloc(1000); - TNC->InitScript[0] = 0; - - TNC->PacketChannels = 10; // Default - - goto ConfigLine; - - while(TRUE) - { - if (GetLine(buf) == 0) - return TRUE; -ConfigLine: - strcpy(errbuf, buf); - - if (memcmp(buf, "****", 4) == 0) - return TRUE; - - ptr = strchr(buf, ';'); - - if (ptr) - { - *ptr++ = 13; - *ptr = 0; - } - - if (_memicmp(buf, "APPL", 4) == 0) - { - } - else - if (_memicmp(buf, "RIGCONTROL", 10) == 0) - { - } - else - - if (_memicmp(buf, "SWITCHMODES", 11) == 0) - { - } - else - if (_memicmp(buf, "USEAPPLCALLS", 12) == 0) - { -// TNC->UseAPPLCalls = TRUE; - } - else if (_memicmp(buf, "DEBUGLOG", 8) == 0) // Write Debug Log - TNC->WRITELOG = atoi(&buf[8]); - else - if (_memicmp(buf, "DEFAULT ROBUST", 14) == 0) - { - } - else - - if (_memicmp(buf, "WL2KREPORT", 10) == 0) - { - } - else - if (_memicmp(buf, "UPDATEMAP", 9) == 0) - TNC->PktUpdateMap = TRUE; - else - if (_memicmp(buf, "PACKETCHANNELS", 14) == 0) - - // Packet Channels - - TNC->PacketChannels = atoi(&buf[14]); - else - strcat (TNC->InitScript, buf); - } - return (TRUE); - -} - -struct TNCINFO * CreateTTYInfo(int port, int speed); -BOOL OpenConnection(int); -BOOL SetupConnection(int); -BOOL CloseConnection(struct TNCINFO * conn); -static BOOL WriteCommBlock(struct TNCINFO * TNC); -BOOL DestroyTTYInfo(int port); -static void DEDCheckRX(struct TNCINFO * TNC); -static VOID DEDPoll(int Port); -VOID StuffAndSend(struct TNCINFO * TNC, UCHAR * Msg, int Len); -unsigned short int compute_crc(unsigned char *buf,int len); -int Unstuff(UCHAR * MsgIn, UCHAR * MsgOut, int len); -static VOID ProcessDEDFrame(struct TNCINFO * TNC); -static VOID ProcessTermModeResponse(struct TNCINFO * TNC); -static VOID ExitHost(struct TNCINFO * TNC); -static VOID DoTNCReinit(struct TNCINFO * TNC); -static VOID DoTermModeTimeout(struct TNCINFO * TNC); -VOID DoMonitorHddr(struct TNCINFO * TNC, UCHAR * Msg, int Len, int Type); -VOID DoMonitorData(struct TNCINFO * TNC, UCHAR * Msg, int Len); -int Switchmode(struct TNCINFO * TNC, int Mode); -VOID SwitchToRPacket(struct TNCINFO * TNC); -VOID SwitchToNormPacket(struct TNCINFO * TNC); - - -static size_t ExtProc(int fn, int port, PDATAMESSAGE buff) -{ - PMSGWITHLEN buffptr; - unsigned int txlen = 0; - - struct TNCINFO * TNC = TNCInfo[port]; - int Stream = 0; - struct STREAMINFO * STREAM; - int TNCOK; - - if (TNC == NULL) - return 0; - - if (TNC->hDevice == 0) - { - // Clear anything from UI_Q - - while (TNC->PortRecord->UI_Q) - { - buffptr = Q_REM(&TNC->PortRecord->UI_Q); - ReleaseBuffer(buffptr); - } - - if (fn > 3 && fn < 6) - goto ok; - - // Try to reopen every 30 secs - - TNC->ReopenTimer++; - - if (TNC->ReopenTimer < 300) - return 0; - - TNC->ReopenTimer = 0; - - if (TNC->PortRecord->PORTCONTROL.PortStopped == 0) - OpenCOMMPort(TNC, TNC->PortRecord->PORTCONTROL.SerialPortName, TNC->PortRecord->PORTCONTROL.BAUDRATE, TRUE); - - if (TNC->hDevice == 0) - return 0; - } -ok: - switch (fn) - { - case 1: // poll - - for (Stream = 0; Stream <= MaxStreams; Stream++) - { - if (TNC->Streams[Stream].ReportDISC) - { - TNC->Streams[Stream].ReportDISC = FALSE; - buff->PORT = Stream; - - return -1; - } - } - - DEDCheckRX(TNC); - DEDPoll(port); - DEDCheckRX(TNC); - - for (Stream = 0; Stream <= MaxStreams; Stream++) - { - STREAM = &TNC->Streams[Stream]; - - if (STREAM->PACTORtoBPQ_Q == 0) - { - if (STREAM->DiscWhenAllSent) - { - STREAM->DiscWhenAllSent--; - if (STREAM->DiscWhenAllSent == 0) - STREAM->ReportDISC = TRUE; // Dont want to leave session attached. Causes too much confusion - } - } - else - { - int datalen; - - buffptr=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((PDATAMESSAGE)buff, datalen); // Neded for arm5 portability - - // buff[5]=(datalen & 0xff); - // buff[6]=(datalen >> 8); - - ReleaseBuffer(buffptr); - - return (1); - } - } - - - return 0; - - case 2: // send - - buffptr = GetBuff(); - - if (buffptr == 0) return (0); // No buffers, so ignore - - Stream = buff->PORT; - - if (!TNC->TNCOK) - { - // Send Error Response - - buffptr->Len = 21; - memcpy(&buffptr->Data[0], "No Connection to TNC\r", 21); - - C_Q_ADD(&TNC->Streams[Stream].PACTORtoBPQ_Q, buffptr); - - return 0; - } - - txlen = GetLengthfromBuffer(buff) - (sizeof(void *) + 4); - - buffptr->Len = txlen; - memcpy(&buffptr->Data[0], &buff->L2DATA[0], txlen); - - C_Q_ADD(&TNC->Streams[Stream].BPQtoPACTOR_Q, buffptr); - - TNC->Streams[Stream].FramesOutstanding++; - - return (0); - - - case 3: // CHECK IF OK TO SEND. Also used to check if TNC is responding - - Stream = (int)(size_t)buff; - - TNCOK = (TNC->HostMode == 1 && TNC->ReinitState != 10); - - STREAM = &TNC->Streams[Stream]; - - if (Stream == 0) - { - if (STREAM->FramesOutstanding > 4) - return (1 | TNCOK << 8 | STREAM->Disconnecting << 15); - } - else - { - if (STREAM->FramesOutstanding > 3 || TNC->Buffers < 200) - return (1 | TNCOK << 8 | STREAM->Disconnecting << 15); } - - return TNCOK << 8 | STREAM->Disconnecting << 15; // OK, but lock attach if disconnecting - - - case 4: // reinit - - ExitHost(TNC); - Sleep(50); - CloseCOMPort(TNC->hDevice); - TNC->hDevice =(HANDLE) 0; - TNC->ReopenTimer = 250; - TNC->HostMode = FALSE; - - return (0); - - case 5: // Close - - // Ensure in Pactor - - ExitHost(TNC); - - Sleep(25); - - CloseCOMPort(TNCInfo[port]->hDevice); - return (0); - - case 6: - - return 0; // No scan interface -} - return 0; -} - -void * TrackerMExtInit(EXTPORTDATA * PortEntry) -{ - char msg[500]; - struct TNCINFO * TNC; - int port; - char * ptr; - int Stream = 0; - char * TempScript; - char YCmd[10]; - - // - // Will be called once for each DED Host TNC Port - // The COM port number is in IOBASE - // - - sprintf(msg,"SCSTRK M %s", PortEntry->PORTCONTROL.SerialPortName); - - WritetoConsole(msg); - - 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 ExtProc; - } - - TNC->Port = port; - TNC->Hardware = H_TRKM; - - // Set up DED addresses for streams - - for (Stream = 0; Stream <= MaxStreams; Stream++) - { - TNC->Streams[Stream].DEDStream = Stream; // DED Stream = BPQ Stream (We don't use Stream 0) - } - - if (TNC->PacketChannels > MaxStreams) - TNC->PacketChannels = MaxStreams; - - PortEntry->MAXHOSTMODESESSIONS = TNC->PacketChannels + 1; //TNC->PacketChannels + 1; - PortEntry->PERMITGATEWAY = TRUE; // Can change ax.25 call on each stream - PortEntry->SCANCAPABILITIES = NONE; // Scan Control 3 stage/conlock - - TNC->PortRecord = PortEntry; - - if (PortEntry->PORTCONTROL.PORTCALL[0] == 0) - memcpy(TNC->NodeCall, MYNODECALL, 10); - else - ConvFromAX25(&PortEntry->PORTCONTROL.PORTCALL[0], TNC->NodeCall); - - PortEntry->PORTCONTROL.PROTOCOL = 10; - PortEntry->PORTCONTROL.PORTQUALITY = 0; - PortEntry->PORTCONTROL.UICAPABLE = 1; - - if (PortEntry->PORTCONTROL.PORTPACLEN == 0) - PortEntry->PORTCONTROL.PORTPACLEN = 100; - - PortEntry->PORTCONTROL.PORTSTARTCODE = KAMStartPort; - PortEntry->PORTCONTROL.PORTSTOPCODE = KAMStopPort; - - ptr=strchr(TNC->NodeCall, ' '); - if (ptr) *(ptr) = 0; // Null Terminate - - // get NODECALL for RP tests - - memcpy(NodeCall, MYNODECALL, 10); - - ptr=strchr(NodeCall, ' '); - if (ptr) *(ptr) = 0; // Null Terminate - - TempScript = malloc(1000); - - strcpy(TempScript, "M UISC\r"); - strcat(TempScript, "F 200\r"); // Sets SABM retry time to about 5 secs - strcat(TempScript, "%F 1500\r"); // Tones may be changed but I want this as standard - - strcat(TempScript, TNC->InitScript); - - free(TNC->InitScript); - TNC->InitScript = TempScript; - - // Others go on end so they can't be overriden - - strcat(TNC->InitScript, "Z 0\r"); // No Flow Control - sprintf(YCmd, "Y %d\r", TNC->PacketChannels); - strcat(TNC->InitScript, YCmd); - strcat(TNC->InitScript, "E 1\r"); // Echo - Restart process needs echo - - sprintf(msg, "I %s\r", TNC->NodeCall); - strcat(TNC->InitScript, msg); - - OpenCOMMPort(TNC,PortEntry->PORTCONTROL.SerialPortName, PortEntry->PORTCONTROL.BAUDRATE, FALSE); - - TNC->InitPtr = TNC->InitScript; - - WritetoConsole("\n"); - - return ExtProc; -} - -static void DEDCheckRX(struct TNCINFO * TNC) -{ - int Length, Len; - UCHAR * ptr; - UCHAR character; - UCHAR * CURSOR; - - Len = ReadCOMBlock(TNC->hDevice, &TNC->RXBuffer[TNC->RXLen], 500 - TNC->RXLen); - - if (Len == 0) - return; // Nothing doing - - TNC->RXLen += Len; - - Length = TNC->RXLen; - - ptr = TNC->RXBuffer; - - CURSOR = &TNC->DEDBuffer[TNC->InputLen]; - - if ((TNC->HostMode == 0 || TNC->ReinitState == 10) && Length > 80) - { - // Probably Signon Message - - if (TNC->WRITELOG) - WriteDebugLogLine(TNC->Port, 'R', ptr, Length); - - ptr[Length] = 0; - Debugprintf("TRK %s", ptr); - TNC->RXLen = 0; - return; - } - - if (TNC->HostMode == 0) - { - // If we are just restarting, and TNC is in host mode, we may get "Invalid Channel" Back - - if (memcmp(ptr, "\x18\x02INVALID", 9) == 0) - { - if (TNC->WRITELOG) - WriteDebugLogLine(TNC->Port, 'R', ptr, Length); - - TNC->HostMode = TRUE; - TNC->HOSTSTATE = 0; - TNC->Timeout = 0; - TNC->RXLen = 0; - return; - } - - // Command is echoed as * command * - - if (strstr(ptr, "*") || TNC->ReinitState == 5) // 5 is waiting for reponse to JHOST1 - { - ProcessTermModeResponse(TNC); - TNC->RXLen = 0; - TNC->HOSTSTATE = 0; - - return; - } - } - - if (TNC->ReinitState == 10) - { - if (Length == 1 && *(ptr) == '.') // 01 echoed as . - { - // TNC is in Term Mode - - if (TNC->WRITELOG) - WriteDebugLogLine(TNC->Port, 'R', ptr, Length); - TNC->ReinitState = 0; - TNC->HostMode = 0; - - return; - } - } - - while (Length--) - { - character = *(ptr++); - - if (TNC->HostMode) - { - // n 0 Success (nothing follows) - // n 1 Success (message follows, null terminated) - // n 2 Failure (message follows, null terminated) - // n 3 Link Status (null terminated) - // n 4 Monitor Header (null terminated) - // n 5 Monitor Header (null terminated) - // n 6 Monitor Information (preceeded by length-1) - // n 7 Connect Information (preceeded by length-1) - - - switch(TNC->HOSTSTATE) - { - case 0: // SETCHANNEL - - TNC->MSGCHANNEL = character; - TNC->HOSTSTATE++; - break; - - case 1: // SETMSGTYPE - - TNC->MSGTYPE = character; - - if (character == 0) - { - // Success, no more info - - ProcessDEDFrame(TNC); - - TNC->HOSTSTATE = 0; - break; - } - - if (character > 0 && character < 6) - { - // Null Terminated Response) - - TNC->HOSTSTATE = 5; - CURSOR = &TNC->DEDBuffer[0]; - break; - } - - if (character > 5 && character < 8) - { - TNC->HOSTSTATE = 2; // Get Length - break; - } - - // Invalid - - Debugprintf("TRK - Invalid MsgType %d %x %x %x", character, *(ptr), *(ptr+1), *(ptr+2)); - break; - - case 2: // Get Length - - TNC->MSGCOUNT = character; - TNC->MSGCOUNT++; // Param is len - 1 - TNC->MSGLENGTH = TNC->MSGCOUNT; - CURSOR = &TNC->DEDBuffer[0]; - TNC->HOSTSTATE = 3; // Get Data - - break; - - case 5: // Collecting Null Terminated Response - - *(CURSOR++) = character; - - if (character) - continue; // MORE TO COME - - ProcessDEDFrame(TNC); - - TNC->HOSTSTATE = 0; - TNC->InputLen = 0; - - break; - - default: - - // RECEIVING Counted Response - - *(CURSOR++) = character; - TNC->MSGCOUNT--; - - if (TNC->MSGCOUNT) - continue; // MORE TO COME - - TNC->InputLen = (int)(CURSOR - TNC->DEDBuffer); - ProcessDEDFrame(TNC); - - TNC->HOSTSTATE = 0; - TNC->InputLen = 0; - } - } - } - - // End of Input - Save buffer position - - TNC->InputLen = (int)(CURSOR - TNC->DEDBuffer); - TNC->RXLen = 0; -} - -static BOOL WriteCommBlock(struct TNCINFO * TNC) -{ - WriteCOMBlock(TNC->hDevice, TNC->TXBuffer, TNC->TXLen); - - if (TNC->WRITELOG) - WriteDebugLogLine(TNC->Port, 'T', TNC->TXBuffer, TNC->TXLen); - - TNC->Timeout = 20; // 2 secs - return TRUE; -} - -static VOID DEDPoll(int Port) -{ - struct TNCINFO * TNC = TNCInfo[Port]; - UCHAR * Poll = TNC->TXBuffer; - int Stream = 0; - int nn; - struct STREAMINFO * STREAM; - - for (Stream = 0; Stream <= MaxStreams; Stream++) - { - if (TNC->PortRecord->ATTACHEDSESSIONS[Stream] && TNC->Streams[Stream].Attached == 0) - { - // New Attach. Set call my session callsign - - int calllen=0; - - TNC->Streams[Stream].Attached = TRUE; - - TNC->PortRecord->ATTACHEDSESSIONS[Stream]->L4USER[6] |= 0x60; // Ensure P or T aren't used on ax.25 - calllen = ConvFromAX25(TNC->PortRecord->ATTACHEDSESSIONS[Stream]->L4USER, TNC->Streams[Stream].MyCall); - TNC->Streams[Stream].MyCall[calllen] = 0; - - if (Stream) //Leave Stream 0 call alone - { - TNC->Streams[Stream].CmdSet = TNC->Streams[Stream].CmdSave = zalloc(100); - sprintf(TNC->Streams[Stream].CmdSet, "%c%c%cI%s", Stream, 1, 1, TNC->Streams[Stream].MyCall); - } - } - } - - if (TNC->Timeout) - { - TNC->Timeout--; - - if (TNC->Timeout) // Still waiting - return; - - // Can't use retries, as we have no way of detecting lost chars. Have to re-init on timeout - - if (TNC->HostMode == 0 || TNC->ReinitState == 10) // 10 is Recovery Mode - { - DoTermModeTimeout(TNC); - return; - } - - // Timed out in host mode - Clear any connection and reinit the TNC - - Debugprintf("DEDHOST - Link to TNC Lost Port %d", TNC->Port); - TNC->TNCOK = FALSE; - - TNC->HostMode = 0; - TNC->ReinitState = 0; - - CloseCOMPort(TNC->hDevice); - OpenCOMMPort(TNC, TNC->PortRecord->PORTCONTROL.SerialPortName, TNC->PortRecord->PORTCONTROL.BAUDRATE, TRUE); - - TNC->InitPtr = TNC->InitScript; - TNC->HOSTSTATE = 0; - - for (Stream = 0; Stream <= MaxStreams; Stream++) - { - if (TNC->PortRecord->ATTACHEDSESSIONS[Stream]) // Connected - { - TNC->Streams[Stream].Connected = FALSE; // Back to Command Mode - TNC->Streams[Stream].ReportDISC = TRUE; // Tell Node - } - } - } - - for (Stream = 0; Stream <= MaxStreams; Stream++) - { - STREAM = &TNC->Streams[Stream]; - - if (STREAM->Attached) - CheckForDetach(TNC, Stream, STREAM, TidyClose, ForcedClose, CloseComplete); - - if (TNC->Timeout) - return; // We've sent something - } - - // if we have just restarted or TNC appears to be in terminal mode, run Initialisation Sequence - - if (!TNC->HostMode) - { - DoTNCReinit(TNC); - return; - } - - if (TNC->InitPtr) - { - char * start, * end; - int len; - - start = TNC->InitPtr; - - if (*(start) == 0) // End of Script - { - TNC->InitPtr = NULL; - Debugprintf("TRK - Init Complete Port %d", TNC->Port); - } - else - { - end = strchr(start, 13); - len = (int)(++end - start - 1); // exclude cr - - TNC->InitPtr = end; - - Poll[0] = 0; // Channel - Poll[1] = 1; // Command - Poll[2] = len - 1; - memcpy(&Poll[3], start, len); - - StuffAndSend(TNC, Poll, len + 3); - - return; - - } - } - - for (Stream = 0; Stream <= MaxStreams; Stream++) - { - if (TNC->Streams[Stream].CmdSet) - { - char * start, * end; - int len; - - start = TNC->Streams[Stream].CmdSet; - - if (*(start + 2) == 0) // End of Script - { - free(TNC->Streams[Stream].CmdSave); - TNC->Streams[Stream].CmdSet = NULL; - } - else - { - end = strchr(start + 3, 0); - len = (int)(++end - start - 1); // exclude cr - TNC->Streams[Stream].CmdSet = end; - - memcpy(&Poll[0], start, len); - Poll[2] = len - 4; - - StuffAndSend(TNC, Poll, len); - - return; - } - } - } - - for (nn = 0; nn <= MaxStreams; nn++) - { - Stream = TNC->LastStream++; - - if (TNC->LastStream > MaxStreams) TNC->LastStream = 0; - - if (TNC->TNCOK && TNC->Streams[Stream].BPQtoPACTOR_Q) - { - int datalen; - UINT * buffptr; - char * Buffer; - - buffptr=Q_REM(&TNC->Streams[Stream].BPQtoPACTOR_Q); - - datalen=buffptr[1]; - Buffer = (char *)&buffptr[2]; // Data portion of frame - - Poll[0] = TNC->Streams[Stream].DEDStream; // Channel - - if (TNC->Streams[Stream].Connected) - { - if (TNC->SwallowSignon && Stream == 0) - { - TNC->SwallowSignon = FALSE; - if (strstr(Buffer, "Connected")) // Discard *** connected - { - ReleaseBuffer(buffptr); - return; - } - } - - Poll[1] = 0; // Data - TNC->Streams[Stream].BytesTXed += datalen; - - Poll[2] = datalen - 1; - memcpy(&Poll[3], buffptr+2, datalen); - - ReleaseBuffer(buffptr); - - StuffAndSend(TNC, Poll, datalen + 3); - - TNC->Streams[Stream].InternalCmd = TNC->Streams[Stream].Connected; - - if (STREAM->Disconnecting && TNC->Streams[Stream].BPQtoPACTOR_Q == 0) - TidyClose(TNC, 0); - - return; - } - - // Command. Do some sanity checking and look for things to process locally - - Poll[1] = 1; // Command - datalen--; // Exclude CR - - if (datalen == 0) // Null Command - { - ReleaseBuffer(buffptr); - return; - } - - Buffer[datalen] = 0; // Null Terminate - _strupr(Buffer); - - if (_memicmp(Buffer, "D", 1) == 0) - { - TNC->Streams[Stream].ReportDISC = TRUE; // Tell Node - ReleaseBuffer(buffptr); - return; - } - - if (Buffer[0] == 'C' && datalen > 2) // Connect - { - if (Stream == 0) - { - // No connects on Stream zero - for mgmt only - - buffptr[1] = sprintf((UCHAR *)&buffptr[2], "TRK} Can't Connect after ATTACH\r"); - C_Q_ADD(&TNC->Streams[0].PACTORtoBPQ_Q, buffptr); - - return; - - } - - if (*(++Buffer) == ' ') Buffer++; // Space isn't needed - - memcpy(TNC->Streams[Stream].RemoteCall, Buffer, 9); - - TNC->Streams[Stream].Connecting = TRUE; - - TNC->Streams[Stream].CmdSet = TNC->Streams[Stream].CmdSave = zalloc(100); - - sprintf(TNC->Streams[Stream].CmdSet, "%c%c%cI%s%c%c%c%c%s", Stream, 1, 1, - TNC->Streams[Stream].MyCall, 0, Stream, 1, 1, (char *)buffptr+8); - - ReleaseBuffer(buffptr); - - TNC->Streams[Stream].InternalCmd = FALSE; - return; - } - - Poll[2] = datalen - 1; - memcpy(&Poll[3], buffptr+2, datalen); - - ReleaseBuffer(buffptr); - - StuffAndSend(TNC, Poll, datalen + 3); - - TNC->Streams[Stream].InternalCmd = TNC->Streams[Stream].Connected; - - return; - } - } - - if (TNC->TNCOK && TNC->PortRecord->UI_Q) - { - int datalen; - char * Buffer; - char CCMD[80] = "C"; - char Call[12] = " "; - struct _MESSAGE * buffptr; - - buffptr = Q_REM(&TNC->PortRecord->UI_Q); - - datalen = buffptr->LENGTH - 7; - Buffer = &buffptr->DEST[0]; // Raw Frame - Buffer[datalen] = 0; - - TNC->Streams[0].CmdSet = TNC->Streams[0].CmdSave = zalloc(500); - -// sprintf(TNC->Streams[Stream].CmdSet, "I%s\r%s\r", TNC->Streams[Stream].MyCall, buffptr+2); - - // Buffer has an ax.25 header, which we need to pick out and set as channel 0 Connect address - // before sending the beacon - - ConvFromAX25(Buffer, &Call[1]); // Dest - strlop(&Call[1], ' '); - strcat(CCMD, Call); - Buffer += 14; // Skip Origin - datalen -= 7; - - while ((Buffer[-1] & 1) == 0) - { - ConvFromAX25(Buffer, &Call[1]); - strlop(&Call[1], ' '); - strcat(CCMD, Call); - Buffer += 7; // End of addr - datalen -= 7; - } - - if (Buffer[0] == 3) // UI - { - Buffer += 2; - datalen -= 2; - - Poll[0] = 0; // UI Channel - Poll[1] = 1; // Data - Poll[2] = (int)strlen(CCMD) - 1; - strcpy(&Poll[3], CCMD); - StuffAndSend(TNC, Poll, Poll[2] + 4); - - sprintf(TNC->Streams[0].CmdSet, "%c%c%c%s", 0, 0, 1, Buffer); - } - - ReleaseBuffer((UINT *)buffptr); - return; - } - - // if frames outstanding, issue a poll (but not too often) - - TNC->IntCmdDelay++; - - if (TNC->IntCmdDelay > 10) - { - TNC->IntCmdDelay = 0; - - Poll[0] = TNC->Streams[0].DEDStream; - Poll[1] = 0x1; // Command - TNC->Streams[0].InternalCmd = TRUE; - - Poll[2] = 1; // Len-1 - Poll[3] = '@'; - Poll[4] = 'B'; // Buffers - StuffAndSend(TNC, Poll, 5); - return; - } - - // Need to poll all channels . Just Poll zero here, the ProcessMessage will poll next - - Poll[0] = 0; // Channel - Poll[1] = 0x1; // Command - Poll[2] = 0; // Len-1 - Poll[3] = 'G'; // Poll - - StuffAndSend(TNC, Poll, 4); - - return; - - - Stream = TNC->StreamtoPoll; - - STREAM = &TNC->Streams[Stream]; - - STREAM->IntCmdDelay++; - - if (STREAM->IntCmdDelay > 10) - { - STREAM->IntCmdDelay = 0; - - if (STREAM->FramesOutstanding) - { - Poll[0] = STREAM->DEDStream; - Poll[1] = 0x1; // Command - STREAM->InternalCmd = TRUE; - - Poll[2] = 0; // Len-1 - Poll[3] = 'L'; // Status - StuffAndSend(TNC, Poll, 4); - - return; - } - } - - - Poll[0] = Stream; // Channel - Poll[1] = 0x1; // Command - Poll[2] = 0; // Len-1 - Poll[3] = 'G'; // Poll - - StuffAndSend(TNC, Poll, 4); - STREAM->InternalCmd = FALSE; - - return; - -} - -static VOID DoTNCReinit(struct TNCINFO * TNC) -{ - UCHAR * Poll = TNC->TXBuffer; - - if (TNC->ReinitState == 0) - { - // Just Starting - Send a TNC Mode Command to see if in Terminal or Host Mode - - TNC->TNCOK = FALSE; - - memcpy(&TNC->TXBuffer[0], "\x18\x1b\r", 2); - TNC->TXLen = 2; - - if (WriteCommBlock(TNC) == FALSE) - { - CloseCOMPort(TNC->hDevice); - OpenCOMMPort(TNC, TNC->PortRecord->PORTCONTROL.SerialPortName, TNC->PortRecord->PORTCONTROL.BAUDRATE, TRUE); - } - - return; - } - - if (TNC->ReinitState == 1) // Forcing back to Term - TNC->ReinitState = 0; - - if (TNC->ReinitState == 2) // In Term State, Sending Initialisation Commands - { - // Put into Host Mode - - memcpy(Poll, "\x18\x1bJHOST1\r", 9); - - TNC->TXLen = 9; - WriteCommBlock(TNC); - - TNC->ReinitState = 5; - return; - } - - if (TNC->ReinitState == 5) - TNC->ReinitState = 0; - -} - -static VOID DoTermModeTimeout(struct TNCINFO * TNC) -{ - UCHAR * Poll = TNC->TXBuffer; - - if (TNC->ReinitState == 0) - { - //Checking if in Terminal Mode - Try to set back to Term Mode - - TNC->ReinitState = 1; - ExitHost(TNC); - - return; - } - - if (TNC->ReinitState == 1) - { - // No Response to trying to enter term mode - do error recovery - - Debugprintf("TRK - Starting Resync Port %d", TNC->Port); - - TNC->ReinitState = 10; - TNC->ReinitCount = 256; - TNC->HostMode = TRUE; // Must be in Host Mode if we need recovery - - Poll[0] = 1; - TNC->TXLen = 1; - WriteCommBlock(TNC); - TNC->Timeout = 10; // 2 secs - - return; - } - - if (TNC->ReinitState == 10) - { - // Continue error recovery - - TNC->ReinitCount--; - - if (TNC->ReinitCount) - { - Poll[0] = 1; - TNC->TXLen = 1; - WriteCommBlock(TNC); - TNC->Timeout = 3; // 0.3 secs - - return; - } - - // Try Again - - Debugprintf("TRK Continuing recovery Port %d", TNC->Port); - - TNC->ReinitState = 0; - - // Close and re-open TNC - - ExitHost(TNC); - Sleep(50); - CloseCOMPort(TNC->hDevice); - TNC->hDevice =(HANDLE) 0; - TNC->ReopenTimer = 290; - TNC->HostMode = FALSE; - - return; - } - if (TNC->ReinitState == 3) - { - // Entering Host Mode - - // Assume ok - - TNC->HostMode = TRUE; - TNC->IntCmdDelay = 10; - - return; - } -} - - -static VOID ExitHost(struct TNCINFO * TNC) -{ - UCHAR * Poll = TNC->TXBuffer; - - // Try to exit Host Mode - - TNC->TXBuffer[0] = 1; - TNC->TXBuffer[1] = 1; - TNC->TXBuffer[2] = 1; - memcpy(&TNC->TXBuffer[3], "%R", 2); - - StuffAndSend(TNC, Poll, 5); - - return; -} - -static VOID ProcessTermModeResponse(struct TNCINFO * TNC) -{ - UCHAR * Poll = TNC->TXBuffer; - - if (TNC->WRITELOG) - WriteDebugLogLine(TNC->Port, 'R', TNC->RXBuffer, TNC->RXLen); - - if (TNC->ReinitState == 0) - { - // Testing if in Term Mode. It is, so can now send Init Commands - - TNC->InitPtr = TNC->InitScript; - TNC->ReinitState = 2; - } - - if (TNC->ReinitState == 1) - { - // trying to set term mode - - // If already in Term Mode, TNC echos command, with control chars replaced with '.' - - if (memcmp(TNC->RXBuffer, "....%R", 6) == 0) - { - // In term mode, Need to put into Host Mode - - TNC->ReinitState = 2; - DoTNCReinit(TNC); - return; - } - } - - if (TNC->ReinitState == 2) - { - // Sending Init Commands - - DoTNCReinit(TNC); // Send Next Command - return; - } - - if (TNC->ReinitState == 5) // Waiting for response to JHOST1 - { - if (TNC->RXBuffer[TNC->RXLen-1] == 10 || TNC->RXBuffer[TNC->RXLen-1] == 13) // NewLine - { - TNC->HostMode = TRUE; - TNC->Timeout = 0; - } - return; - } -} - -static VOID ProcessDEDFrame(struct TNCINFO * TNC) -{ - UINT * buffptr; - char * Buffer; // Data portion of frame - UINT Stream = 0; - UCHAR * Msg = TNC->DEDBuffer; - int framelen = TNC->InputLen; - struct STREAMINFO * STREAM; - - if (TNC->WRITELOG) - WriteDebugLogLine(TNC->Port, 'R', Msg, framelen); - - if (TNC->ReinitState == 10) - { - // Recovering from Sync Failure - - // Any Response indicates we are in host mode, and back in sync - - TNC->HostMode = TRUE; - TNC->Timeout = 0; - TNC->ReinitState = 0; - TNC->RXLen = 0; - TNC->HOSTSTATE = 0; - return; - } - - // Any valid frame is an ACK - - TNC->Timeout = 0; - TNC->TNCOK = TRUE; - - if (TNC->InitPtr) // Response to Init Script - return; - - if (TNC->MSGCHANNEL > 26) - return; - - Stream = TNC->MSGCHANNEL; - - // See if Poll Reply or Data - - if (TNC->MSGTYPE == 0) - { - // Success - Nothing Follows - - if (TNC->Streams[Stream].CmdSet) - return; // Response to Command Set or Init Script - - if ((TNC->TXBuffer[1] & 1) == 0) // Data - return; - - // If the response to a Command, then we should convert to a text "Ok" for forward scripts, etc - - if (TNC->TXBuffer[3] == 'G') // Poll - { - UCHAR * Poll = TNC->TXBuffer; - - // Poll Next Channel (we need to scan all channels every DEDPOLL cycle - - Stream++; - - if (Stream > MaxStreams) - return; - - STREAM = &TNC->Streams[Stream]; - - STREAM->IntCmdDelay++; - - if (STREAM->IntCmdDelay > 10) - { - STREAM->IntCmdDelay = 0; - - if (STREAM->FramesOutstanding) - { - Poll[0] = STREAM->DEDStream; - Poll[1] = 0x1; // Command - STREAM->InternalCmd = TRUE; - - Poll[2] = 0; // Len-1 - Poll[3] = 'L'; // Status - StuffAndSend(TNC, Poll, 4); - return; - } - } - - Poll[0] = Stream; // Channel - Poll[1] = 0x1; // Command - Poll[2] = 0; // Len-1 - Poll[3] = 'G'; // Poll - - StuffAndSend(TNC, Poll, 4); - STREAM->InternalCmd = FALSE; - - return; - } - - if (TNC->TXBuffer[3] == 'C') // Connect - reply we need is async - return; - - if (TNC->TXBuffer[3] == 'L') // Shouldnt happen! - return; - - - if (TNC->TXBuffer[3] == 'J') // JHOST - { - if (TNC->TXBuffer[8] == '0') // JHOST0 - { - TNC->Timeout = 1; // - return; - } - } - - if (TNC->MSGCHANNEL == 0) // Unproto Channel - return; - - buffptr = GetBuff(); - - if (buffptr == NULL) return; // No buffers, so ignore - - buffptr[1] = sprintf((UCHAR *)&buffptr[2],"TRK} Ok\r"); - - C_Q_ADD(&TNC->Streams[Stream].PACTORtoBPQ_Q, buffptr); - - return; - } - - if (TNC->MSGTYPE > 0 &&TNC->MSGTYPE < 6) - { - // Success with message - null terminated - - char * ptr; - int len; - - Buffer = Msg; - - ptr = strchr(Buffer, 0); - - if (ptr == 0) - return; - - *(ptr++) = 13; - *(ptr) = 0; - - len = (int)(ptr - Buffer); - - if (len > 256) - return; - - // See if we need to process locally (Response to our command, Incoming Call, Disconencted, etc - - if (TNC->MSGTYPE < 3) // 1 or 2 - Success or Fail - { - // See if a response to internal command - - if (TNC->Streams[Stream].InternalCmd) - { - // Process it - - char LastCmd = TNC->TXBuffer[3]; - - if (LastCmd == 'L') // Status - { - int s1, s2, s3, s4, s5, s6, num; - - num = sscanf(Buffer, "%d %d %d %d %d %d", &s1, &s2, &s3, &s4, &s5, &s6); - - TNC->Streams[Stream].FramesOutstanding = s3; - return; - } - - if (LastCmd == '@') // @ Commands - { - if (TNC->TXBuffer[4]== 'B') // Buffer Status - { - TNC->Buffers = atoi(Buffer); -// SetDlgItemText(TNC->hDlg, IDC_BUFFERS, Buffer); - return; - } - } - - return; - } - - // Not Internal Command, so send to user - - if (TNC->Streams[Stream].CmdSet) - return; // Response to Command Set - - if ((TNC->TXBuffer[1] & 1) == 0) // Data - return; - - // If the response to a Command, then we should convert to a text "Ok" for forward scripts, etc - - if (TNC->TXBuffer[3] == 'G') // Poll - return; - - if (TNC->TXBuffer[3] == 'C') // Connect - reply we need is async - return; - - if (TNC->TXBuffer[3] == 'L') // Shouldnt happen! - return; - - if (TNC->TXBuffer[3] == 'J') // JHOST - { - if (TNC->TXBuffer[8] == '0') // JHOST0 - { - TNC->Timeout = 1; // - return; - } - } - - if (TNC->MSGCHANNEL == 0) // Unproto Channel - return; - - buffptr = GetBuff(); - - if (buffptr == NULL) return; // No buffers, so ignore - - buffptr[1] = sprintf((UCHAR *)&buffptr[2],"TRK} %s", Buffer); - - C_Q_ADD(&TNC->Streams[Stream].PACTORtoBPQ_Q, buffptr); - - return; - } - - if (TNC->MSGTYPE == 3) // Status - { - struct STREAMINFO * STREAM = &TNC->Streams[Stream]; - - if (strstr(Buffer, "DISCONNECTED") || strstr(Buffer, "LINK FAILURE") || strstr(Buffer, "BUSY")) - { - if ((STREAM->Connecting | STREAM->Connected) == 0) - return; - - if (STREAM->Connecting && STREAM->Disconnecting == FALSE) - { - // Connect Failed - - buffptr = GetBuff(); - if (buffptr == 0) return; // No buffers, so ignore - - if (strstr(Buffer, "BUSY")) - buffptr[1] = sprintf((UCHAR *)&buffptr[2], "*** Busy from %s\r", TNC->Streams[Stream].RemoteCall); - else - buffptr[1] = sprintf((UCHAR *)&buffptr[2], "*** Failure with %s\r", TNC->Streams[Stream].RemoteCall); - - C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr); - - STREAM->Connecting = FALSE; - STREAM->Connected = FALSE; // In case! - STREAM->FramesOutstanding = 0; - - STREAM->DiscWhenAllSent = 15; // Dont want to leave session attached. Causes too much confusion - - return; - } - - // Must Have been connected or disconnecting - Release Session - - STREAM->Connecting = FALSE; - STREAM->Connected = FALSE; // Back to Command Mode - STREAM->FramesOutstanding = 0; - - if (STREAM->Disconnecting == FALSE) - STREAM->ReportDISC = TRUE; // Tell Node - - STREAM->Disconnecting = FALSE; - return; - } - - if (strstr(Buffer, "CONNECTED")) - { - char * Call = strstr(Buffer, " to "); - char * ptr; - char MHCall[30]; - - Call += 4; - - if (Call[1] == ':') - Call +=2; - - ptr = strchr(Call, ' '); - if (ptr) *ptr = 0; - - ptr = strchr(Call, 13); - if (ptr) *ptr = 0; - - STREAM->Connected = TRUE; // Subsequent data to data channel - STREAM->Connecting = FALSE; - - STREAM->BytesRXed = STREAM->BytesTXed = 0; - - memcpy(MHCall, Call, 9); - MHCall[9] = 0; - - if (TNC->PortRecord->ATTACHEDSESSIONS[Stream] == 0) - { - // Incoming Connect - -// APPLCALLS * APPL; -// char * ApplPtr = &APPLS; -// int App; -// char Appl[10]; -// char DestCall[10]; - - UpdateMH(TNC, MHCall, '+', 'I'); - - ProcessIncommingConnect(TNC, Call, Stream, TRUE); - - if (FULL_CTEXT && HFCTEXTLEN == 0) - { - int Len = CTEXTLEN, CTPaclen = 100; - int Next = 0; - - while (Len > CTPaclen) // CTEXT Paclen - { - buffptr = GetBuff(); - if (buffptr == 0) return; // No buffers, so ignore - - buffptr[1] = CTPaclen; - memcpy(&buffptr[2], &CTEXTMSG[Next], CTPaclen); - C_Q_ADD(&STREAM->BPQtoPACTOR_Q, buffptr); - - Next += CTPaclen; - Len -= CTPaclen; - } - - buffptr = GetBuff(); - if (buffptr == 0) return; // No buffers, so ignore - - buffptr[1] = Len; - memcpy(&buffptr[2], &CTEXTMSG[Next], Len); - C_Q_ADD(&STREAM->BPQtoPACTOR_Q, buffptr); - } - - return; - } - else - { - // Connect Complete - - buffptr = GetBuff(); - if (buffptr == 0) return; // No buffers, so ignore - - buffptr[1] = sprintf((UCHAR *)&buffptr[2], "*** Connected to %s\r", Call);; - - C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr); - - } - } - return; - } - - if (TNC->MSGTYPE == 4 || TNC->MSGTYPE == 5) - { - struct STREAMINFO * STREAM = &TNC->Streams[0]; // RP Stream - - // Monitor - -/* - if (TNC->UseAPPLCalls && strstr(&Msg[4], "SABM") && STREAM->Attached == FALSE) - { - // See if a call to Nodecall or one of our APPLCALLS - if so, stop scan and switch MYCALL - - char DestCall[10] = "NOCALL "; - char * ptr1 = strstr(&Msg[7], "to "); - int i; - APPLCALLS * APPL; - char Appl[11]; - char Status[80]; - - if (ptr1) memcpy(DestCall, &ptr1[3], 10); - - ptr1 = strchr(DestCall, ' '); - if (ptr1) *(ptr1) = 0; // Null Terminate - - Debugprintf("RP SABM Received for %s" , DestCall); - - if (strcmp(TNC->NodeCall, DestCall) != 0) - { - // Not Calling NodeCall/Portcall - - if (strcmp(NodeCall, DestCall) == 0) - goto SetThisCall; - - // See if to one of our ApplCalls - - 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, ' '); - - if (ptr) *ptr = 0; - - if (strcmp(Appl, DestCall) == 0) - { - SetThisCall: - Debugprintf("RP SABM is for NODECALL or one of our APPLCalls - setting MYCALL to %s and pausing scan", DestCall); - - sprintf(Status, "%d SCANSTART 60", TNC->Port); // Pause scan for 60 secs - Rig_Command(-1, Status); - TNC->SwitchToPactor = 600; // Don't change modes for 60 secs - - strcpy(STREAM->MyCall, DestCall); - STREAM->CmdSet = STREAM->CmdSave = zalloc(100); - sprintf(STREAM->CmdSet, "I%s\r", DestCall); - break; - } - } - } - } - } -*/ - DoMonitorHddr(TNC, Msg, framelen, TNC->MSGTYPE); - return; - - } - - // 1, 2, 4, 5 - pass to Appl - - if (TNC->MSGCHANNEL == 0) // Unproto Channel - return; - - buffptr = GetBuff(); - - if (buffptr == NULL) return; // No buffers, so ignore - - buffptr[1] = sprintf((UCHAR *)&buffptr[2],"Trk} %s", &Msg[4]); - - C_Q_ADD(&TNC->Streams[Stream].PACTORtoBPQ_Q, buffptr); - - return; - } - - if (TNC->MSGTYPE == 6) - { - // Monitor Data With length) - - DoMonitorData(TNC, Msg, framelen); - return; - } - - if (TNC->MSGTYPE == 7) - { - //char StatusMsg[60]; - //int Status, ISS, Offset; - - // Connected Data - - buffptr = GetBuff(); - - if (buffptr == NULL) return; // No buffers, so ignore - - buffptr[1] = framelen; // Length - TNC->Streams[Stream].BytesRXed += buffptr[1]; - memcpy(&buffptr[2], Msg, buffptr[1]); - - C_Q_ADD(&TNC->Streams[Stream].PACTORtoBPQ_Q, buffptr); - - return; - } -} - -VOID TidyClose(struct TNCINFO * TNC, int Stream) -{ - // Queue it as we may have just sent data - - TNC->Streams[Stream].CmdSet = TNC->Streams[Stream].CmdSave = zalloc(100); - sprintf(TNC->Streams[Stream].CmdSet, "%c%c%cD", Stream, 1, 1); -} - - -VOID ForcedClose(struct TNCINFO * TNC, int Stream) -{ - TidyClose(TNC, Stream); // I don't think Hostmode has a DD -} - -VOID CloseComplete(struct TNCINFO * TNC, int Stream) -{ -} - - +/*
+Copyright 2001-2018 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
+*/
+
+//
+// DLL to inteface DED Host Mode TNCs to BPQ32 switch
+//
+// Uses BPQ EXTERNAL interface
+
+#define _CRT_SECURE_NO_WARNINGS
+#define _CRT_SECURE_NO_DEPRECATE
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "time.h"
+
+#define MaxStreams 10
+
+#include "CHeaders.h"
+#include "tncinfo.h"
+
+#include "bpq32.h"
+
+static char ClassName[]="TRACKERSTATUS";
+static char WindowTitle[] = "SCS Tracker";
+static int RigControlRow = 140;
+
+#define NARROWMODE 30
+#define WIDEMODE 30 // PIII only
+
+extern UCHAR BPQDirectory[];
+
+extern char * PortConfig[33];
+
+static RECT Rect;
+
+struct TNCINFO * TNCInfo[34]; // Records are Malloc'd
+
+VOID __cdecl Debugprintf(const char * format, ...);
+char * strlop(char * buf, char delim);
+BOOL KAMStartPort(struct PORTCONTROL * PORT);
+BOOL KAMStopPort(struct PORTCONTROL * PORT);
+
+char NodeCall[11]; // Nodecall, Null Terminated
+void WriteDebugLogLine(int Port, char Dirn, char * Msg, int MsgLen);
+
+static int ProcessLine(char * buf, int Port)
+{
+ UCHAR * ptr;
+ char * p_port = 0;
+ int BPQport;
+ int len=510;
+ struct TNCINFO * TNC;
+ char errbuf[256];
+
+ strcpy(errbuf, buf);
+
+ BPQport = Port;
+
+ TNC = TNCInfo[BPQport] = malloc(sizeof(struct TNCINFO));
+ memset(TNC, 0, sizeof(struct TNCINFO));
+
+ TNC->InitScript = malloc(1000);
+ TNC->InitScript[0] = 0;
+
+ TNC->PacketChannels = 10; // Default
+
+ goto ConfigLine;
+
+ while(TRUE)
+ {
+ if (GetLine(buf) == 0)
+ return TRUE;
+ConfigLine:
+ strcpy(errbuf, buf);
+
+ if (memcmp(buf, "****", 4) == 0)
+ return TRUE;
+
+ ptr = strchr(buf, ';');
+
+ if (ptr)
+ {
+ *ptr++ = 13;
+ *ptr = 0;
+ }
+
+ if (_memicmp(buf, "APPL", 4) == 0)
+ {
+ }
+ else
+ if (_memicmp(buf, "RIGCONTROL", 10) == 0)
+ {
+ }
+ else
+
+ if (_memicmp(buf, "SWITCHMODES", 11) == 0)
+ {
+ }
+ else
+ if (_memicmp(buf, "USEAPPLCALLS", 12) == 0)
+ {
+// TNC->UseAPPLCalls = TRUE;
+ }
+ else if (_memicmp(buf, "DEBUGLOG", 8) == 0) // Write Debug Log
+ TNC->WRITELOG = atoi(&buf[8]);
+ else
+ if (_memicmp(buf, "DEFAULT ROBUST", 14) == 0)
+ {
+ }
+ else
+
+ if (_memicmp(buf, "WL2KREPORT", 10) == 0)
+ {
+ }
+ else
+ if (_memicmp(buf, "UPDATEMAP", 9) == 0)
+ TNC->PktUpdateMap = TRUE;
+ else
+ if (_memicmp(buf, "PACKETCHANNELS", 14) == 0)
+
+ // Packet Channels
+
+ TNC->PacketChannels = atoi(&buf[14]);
+ else
+ strcat (TNC->InitScript, buf);
+ }
+ return (TRUE);
+
+}
+
+struct TNCINFO * CreateTTYInfo(int port, int speed);
+BOOL OpenConnection(int);
+BOOL SetupConnection(int);
+BOOL CloseConnection(struct TNCINFO * conn);
+static BOOL WriteCommBlock(struct TNCINFO * TNC);
+BOOL DestroyTTYInfo(int port);
+static void DEDCheckRX(struct TNCINFO * TNC);
+static VOID DEDPoll(int Port);
+VOID StuffAndSend(struct TNCINFO * TNC, UCHAR * Msg, int Len);
+unsigned short int compute_crc(unsigned char *buf,int len);
+int Unstuff(UCHAR * MsgIn, UCHAR * MsgOut, int len);
+static VOID ProcessDEDFrame(struct TNCINFO * TNC);
+static VOID ProcessTermModeResponse(struct TNCINFO * TNC);
+static VOID ExitHost(struct TNCINFO * TNC);
+static VOID DoTNCReinit(struct TNCINFO * TNC);
+static VOID DoTermModeTimeout(struct TNCINFO * TNC);
+VOID DoMonitorHddr(struct TNCINFO * TNC, UCHAR * Msg, int Len, int Type);
+VOID DoMonitorData(struct TNCINFO * TNC, UCHAR * Msg, int Len);
+int Switchmode(struct TNCINFO * TNC, int Mode);
+VOID SwitchToRPacket(struct TNCINFO * TNC);
+VOID SwitchToNormPacket(struct TNCINFO * TNC);
+
+
+static size_t ExtProc(int fn, int port, PDATAMESSAGE buff)
+{
+ PMSGWITHLEN buffptr;
+ unsigned int txlen = 0;
+
+ struct TNCINFO * TNC = TNCInfo[port];
+ int Stream = 0;
+ struct STREAMINFO * STREAM;
+ int TNCOK;
+
+ if (TNC == NULL)
+ return 0;
+
+ if (TNC->hDevice == 0)
+ {
+ // Clear anything from UI_Q
+
+ while (TNC->PortRecord->UI_Q)
+ {
+ buffptr = Q_REM(&TNC->PortRecord->UI_Q);
+ ReleaseBuffer(buffptr);
+ }
+
+ if (fn > 3 && fn < 6)
+ goto ok;
+
+ // Try to reopen every 30 secs
+
+ TNC->ReopenTimer++;
+
+ if (TNC->ReopenTimer < 300)
+ return 0;
+
+ TNC->ReopenTimer = 0;
+
+ if (TNC->PortRecord->PORTCONTROL.PortStopped == 0)
+ OpenCOMMPort(TNC, TNC->PortRecord->PORTCONTROL.SerialPortName, TNC->PortRecord->PORTCONTROL.BAUDRATE, TRUE);
+
+ if (TNC->hDevice == 0)
+ return 0;
+ }
+ok:
+ switch (fn)
+ {
+ case 1: // poll
+
+ for (Stream = 0; Stream <= MaxStreams; Stream++)
+ {
+ if (TNC->Streams[Stream].ReportDISC)
+ {
+ TNC->Streams[Stream].ReportDISC = FALSE;
+ buff->PORT = Stream;
+
+ return -1;
+ }
+ }
+
+ DEDCheckRX(TNC);
+ DEDPoll(port);
+ DEDCheckRX(TNC);
+
+ for (Stream = 0; Stream <= MaxStreams; Stream++)
+ {
+ STREAM = &TNC->Streams[Stream];
+
+ if (STREAM->PACTORtoBPQ_Q == 0)
+ {
+ if (STREAM->DiscWhenAllSent)
+ {
+ STREAM->DiscWhenAllSent--;
+ if (STREAM->DiscWhenAllSent == 0)
+ STREAM->ReportDISC = TRUE; // Dont want to leave session attached. Causes too much confusion
+ }
+ }
+ else
+ {
+ int datalen;
+
+ buffptr=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((PDATAMESSAGE)buff, datalen); // Neded for arm5 portability
+
+ // buff[5]=(datalen & 0xff);
+ // buff[6]=(datalen >> 8);
+
+ ReleaseBuffer(buffptr);
+
+ return (1);
+ }
+ }
+
+
+ return 0;
+
+ case 2: // send
+
+ buffptr = GetBuff();
+
+ if (buffptr == 0) return (0); // No buffers, so ignore
+
+ Stream = buff->PORT;
+
+ if (!TNC->TNCOK)
+ {
+ // Send Error Response
+
+ buffptr->Len = 21;
+ memcpy(&buffptr->Data[0], "No Connection to TNC\r", 21);
+
+ C_Q_ADD(&TNC->Streams[Stream].PACTORtoBPQ_Q, buffptr);
+
+ return 0;
+ }
+
+ txlen = GetLengthfromBuffer(buff) - (sizeof(void *) + 4);
+
+ buffptr->Len = txlen;
+ memcpy(&buffptr->Data[0], &buff->L2DATA[0], txlen);
+
+ C_Q_ADD(&TNC->Streams[Stream].BPQtoPACTOR_Q, buffptr);
+
+ TNC->Streams[Stream].FramesOutstanding++;
+
+ return (0);
+
+
+ case 3: // CHECK IF OK TO SEND. Also used to check if TNC is responding
+
+ Stream = (int)(size_t)buff;
+
+ TNCOK = (TNC->HostMode == 1 && TNC->ReinitState != 10);
+
+ STREAM = &TNC->Streams[Stream];
+
+ if (Stream == 0)
+ {
+ if (STREAM->FramesOutstanding > 4)
+ return (1 | TNCOK << 8 | STREAM->Disconnecting << 15);
+ }
+ else
+ {
+ if (STREAM->FramesOutstanding > 3 || TNC->Buffers < 200)
+ return (1 | TNCOK << 8 | STREAM->Disconnecting << 15); }
+
+ return TNCOK << 8 | STREAM->Disconnecting << 15; // OK, but lock attach if disconnecting
+
+
+ case 4: // reinit
+
+ ExitHost(TNC);
+ Sleep(50);
+ CloseCOMPort(TNC->hDevice);
+ TNC->hDevice =(HANDLE) 0;
+ TNC->ReopenTimer = 250;
+ TNC->HostMode = FALSE;
+
+ return (0);
+
+ case 5: // Close
+
+ // Ensure in Pactor
+
+ ExitHost(TNC);
+
+ Sleep(25);
+
+ CloseCOMPort(TNCInfo[port]->hDevice);
+ return (0);
+
+ case 6:
+
+ return 0; // No scan interface
+}
+ return 0;
+}
+
+void * TrackerMExtInit(EXTPORTDATA * PortEntry)
+{
+ char msg[500];
+ struct TNCINFO * TNC;
+ int port;
+ char * ptr;
+ int Stream = 0;
+ char * TempScript;
+ char YCmd[10];
+
+ //
+ // Will be called once for each DED Host TNC Port
+ // The COM port number is in IOBASE
+ //
+
+ sprintf(msg,"SCSTRK M %s", PortEntry->PORTCONTROL.SerialPortName);
+
+ WritetoConsole(msg);
+
+ 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 ExtProc;
+ }
+
+ TNC->Port = port;
+ TNC->Hardware = H_TRKM;
+
+ // Set up DED addresses for streams
+
+ for (Stream = 0; Stream <= MaxStreams; Stream++)
+ {
+ TNC->Streams[Stream].DEDStream = Stream; // DED Stream = BPQ Stream (We don't use Stream 0)
+ }
+
+ if (TNC->PacketChannels > MaxStreams)
+ TNC->PacketChannels = MaxStreams;
+
+ PortEntry->MAXHOSTMODESESSIONS = TNC->PacketChannels + 1; //TNC->PacketChannels + 1;
+ PortEntry->PERMITGATEWAY = TRUE; // Can change ax.25 call on each stream
+ PortEntry->SCANCAPABILITIES = NONE; // Scan Control 3 stage/conlock
+
+ TNC->PortRecord = PortEntry;
+
+ if (PortEntry->PORTCONTROL.PORTCALL[0] == 0)
+ memcpy(TNC->NodeCall, MYNODECALL, 10);
+ else
+ ConvFromAX25(&PortEntry->PORTCONTROL.PORTCALL[0], TNC->NodeCall);
+
+ PortEntry->PORTCONTROL.PROTOCOL = 10;
+ PortEntry->PORTCONTROL.PORTQUALITY = 0;
+ PortEntry->PORTCONTROL.UICAPABLE = 1;
+
+ if (PortEntry->PORTCONTROL.PORTPACLEN == 0)
+ PortEntry->PORTCONTROL.PORTPACLEN = 100;
+
+ PortEntry->PORTCONTROL.PORTSTARTCODE = KAMStartPort;
+ PortEntry->PORTCONTROL.PORTSTOPCODE = KAMStopPort;
+
+ ptr=strchr(TNC->NodeCall, ' ');
+ if (ptr) *(ptr) = 0; // Null Terminate
+
+ // get NODECALL for RP tests
+
+ memcpy(NodeCall, MYNODECALL, 10);
+
+ ptr=strchr(NodeCall, ' ');
+ if (ptr) *(ptr) = 0; // Null Terminate
+
+ TempScript = malloc(1000);
+
+ strcpy(TempScript, "M UISC\r");
+ strcat(TempScript, "F 200\r"); // Sets SABM retry time to about 5 secs
+ strcat(TempScript, "%F 1500\r"); // Tones may be changed but I want this as standard
+
+ strcat(TempScript, TNC->InitScript);
+
+ free(TNC->InitScript);
+ TNC->InitScript = TempScript;
+
+ // Others go on end so they can't be overriden
+
+ strcat(TNC->InitScript, "Z 0\r"); // No Flow Control
+ sprintf(YCmd, "Y %d\r", TNC->PacketChannels);
+ strcat(TNC->InitScript, YCmd);
+ strcat(TNC->InitScript, "E 1\r"); // Echo - Restart process needs echo
+
+ sprintf(msg, "I %s\r", TNC->NodeCall);
+ strcat(TNC->InitScript, msg);
+
+ OpenCOMMPort(TNC,PortEntry->PORTCONTROL.SerialPortName, PortEntry->PORTCONTROL.BAUDRATE, FALSE);
+
+ TNC->InitPtr = TNC->InitScript;
+
+ WritetoConsole("\n");
+
+ return ExtProc;
+}
+
+static void DEDCheckRX(struct TNCINFO * TNC)
+{
+ int Length, Len;
+ UCHAR * ptr;
+ UCHAR character;
+ UCHAR * CURSOR;
+
+ Len = ReadCOMBlock(TNC->hDevice, &TNC->RXBuffer[TNC->RXLen], 500 - TNC->RXLen);
+
+ if (Len == 0)
+ return; // Nothing doing
+
+ TNC->RXLen += Len;
+
+ Length = TNC->RXLen;
+
+ ptr = TNC->RXBuffer;
+
+ CURSOR = &TNC->DEDBuffer[TNC->InputLen];
+
+ if ((TNC->HostMode == 0 || TNC->ReinitState == 10) && Length > 80)
+ {
+ // Probably Signon Message
+
+ if (TNC->WRITELOG)
+ WriteDebugLogLine(TNC->Port, 'R', ptr, Length);
+
+ ptr[Length] = 0;
+ Debugprintf("TRK %s", ptr);
+ TNC->RXLen = 0;
+ return;
+ }
+
+ if (TNC->HostMode == 0)
+ {
+ // If we are just restarting, and TNC is in host mode, we may get "Invalid Channel" Back
+
+ if (memcmp(ptr, "\x18\x02INVALID", 9) == 0)
+ {
+ if (TNC->WRITELOG)
+ WriteDebugLogLine(TNC->Port, 'R', ptr, Length);
+
+ TNC->HostMode = TRUE;
+ TNC->HOSTSTATE = 0;
+ TNC->Timeout = 0;
+ TNC->RXLen = 0;
+ return;
+ }
+
+ // Command is echoed as * command *
+
+ if (strstr(ptr, "*") || TNC->ReinitState == 5) // 5 is waiting for reponse to JHOST1
+ {
+ ProcessTermModeResponse(TNC);
+ TNC->RXLen = 0;
+ TNC->HOSTSTATE = 0;
+
+ return;
+ }
+ }
+
+ if (TNC->ReinitState == 10)
+ {
+ if (Length == 1 && *(ptr) == '.') // 01 echoed as .
+ {
+ // TNC is in Term Mode
+
+ if (TNC->WRITELOG)
+ WriteDebugLogLine(TNC->Port, 'R', ptr, Length);
+ TNC->ReinitState = 0;
+ TNC->HostMode = 0;
+
+ return;
+ }
+ }
+
+ while (Length--)
+ {
+ character = *(ptr++);
+
+ if (TNC->HostMode)
+ {
+ // n 0 Success (nothing follows)
+ // n 1 Success (message follows, null terminated)
+ // n 2 Failure (message follows, null terminated)
+ // n 3 Link Status (null terminated)
+ // n 4 Monitor Header (null terminated)
+ // n 5 Monitor Header (null terminated)
+ // n 6 Monitor Information (preceeded by length-1)
+ // n 7 Connect Information (preceeded by length-1)
+
+
+ switch(TNC->HOSTSTATE)
+ {
+ case 0: // SETCHANNEL
+
+ TNC->MSGCHANNEL = character;
+ TNC->HOSTSTATE++;
+ break;
+
+ case 1: // SETMSGTYPE
+
+ TNC->MSGTYPE = character;
+
+ if (character == 0)
+ {
+ // Success, no more info
+
+ ProcessDEDFrame(TNC);
+
+ TNC->HOSTSTATE = 0;
+ break;
+ }
+
+ if (character > 0 && character < 6)
+ {
+ // Null Terminated Response)
+
+ TNC->HOSTSTATE = 5;
+ CURSOR = &TNC->DEDBuffer[0];
+ break;
+ }
+
+ if (character > 5 && character < 8)
+ {
+ TNC->HOSTSTATE = 2; // Get Length
+ break;
+ }
+
+ // Invalid
+
+ Debugprintf("TRK - Invalid MsgType %d %x %x %x", character, *(ptr), *(ptr+1), *(ptr+2));
+ break;
+
+ case 2: // Get Length
+
+ TNC->MSGCOUNT = character;
+ TNC->MSGCOUNT++; // Param is len - 1
+ TNC->MSGLENGTH = TNC->MSGCOUNT;
+ CURSOR = &TNC->DEDBuffer[0];
+ TNC->HOSTSTATE = 3; // Get Data
+
+ break;
+
+ case 5: // Collecting Null Terminated Response
+
+ *(CURSOR++) = character;
+
+ if (character)
+ continue; // MORE TO COME
+
+ ProcessDEDFrame(TNC);
+
+ TNC->HOSTSTATE = 0;
+ TNC->InputLen = 0;
+
+ break;
+
+ default:
+
+ // RECEIVING Counted Response
+
+ *(CURSOR++) = character;
+ TNC->MSGCOUNT--;
+
+ if (TNC->MSGCOUNT)
+ continue; // MORE TO COME
+
+ TNC->InputLen = (int)(CURSOR - TNC->DEDBuffer);
+ ProcessDEDFrame(TNC);
+
+ TNC->HOSTSTATE = 0;
+ TNC->InputLen = 0;
+ }
+ }
+ }
+
+ // End of Input - Save buffer position
+
+ TNC->InputLen = (int)(CURSOR - TNC->DEDBuffer);
+ TNC->RXLen = 0;
+}
+
+static BOOL WriteCommBlock(struct TNCINFO * TNC)
+{
+ WriteCOMBlock(TNC->hDevice, TNC->TXBuffer, TNC->TXLen);
+
+ if (TNC->WRITELOG)
+ WriteDebugLogLine(TNC->Port, 'T', TNC->TXBuffer, TNC->TXLen);
+
+ TNC->Timeout = 20; // 2 secs
+ return TRUE;
+}
+
+static VOID DEDPoll(int Port)
+{
+ struct TNCINFO * TNC = TNCInfo[Port];
+ UCHAR * Poll = TNC->TXBuffer;
+ int Stream = 0;
+ int nn;
+ struct STREAMINFO * STREAM;
+
+ for (Stream = 0; Stream <= MaxStreams; Stream++)
+ {
+ if (TNC->PortRecord->ATTACHEDSESSIONS[Stream] && TNC->Streams[Stream].Attached == 0)
+ {
+ // New Attach. Set call my session callsign
+
+ int calllen=0;
+
+ TNC->Streams[Stream].Attached = TRUE;
+
+ TNC->PortRecord->ATTACHEDSESSIONS[Stream]->L4USER[6] |= 0x60; // Ensure P or T aren't used on ax.25
+ calllen = ConvFromAX25(TNC->PortRecord->ATTACHEDSESSIONS[Stream]->L4USER, TNC->Streams[Stream].MyCall);
+ TNC->Streams[Stream].MyCall[calllen] = 0;
+
+ if (Stream) //Leave Stream 0 call alone
+ {
+ TNC->Streams[Stream].CmdSet = TNC->Streams[Stream].CmdSave = zalloc(100);
+ sprintf(TNC->Streams[Stream].CmdSet, "%c%c%cI%s", Stream, 1, 1, TNC->Streams[Stream].MyCall);
+ }
+ }
+ }
+
+ if (TNC->Timeout)
+ {
+ TNC->Timeout--;
+
+ if (TNC->Timeout) // Still waiting
+ return;
+
+ // Can't use retries, as we have no way of detecting lost chars. Have to re-init on timeout
+
+ if (TNC->HostMode == 0 || TNC->ReinitState == 10) // 10 is Recovery Mode
+ {
+ DoTermModeTimeout(TNC);
+ return;
+ }
+
+ // Timed out in host mode - Clear any connection and reinit the TNC
+
+ Debugprintf("DEDHOST - Link to TNC Lost Port %d", TNC->Port);
+ TNC->TNCOK = FALSE;
+
+ TNC->HostMode = 0;
+ TNC->ReinitState = 0;
+
+ CloseCOMPort(TNC->hDevice);
+ OpenCOMMPort(TNC, TNC->PortRecord->PORTCONTROL.SerialPortName, TNC->PortRecord->PORTCONTROL.BAUDRATE, TRUE);
+
+ TNC->InitPtr = TNC->InitScript;
+ TNC->HOSTSTATE = 0;
+
+ for (Stream = 0; Stream <= MaxStreams; Stream++)
+ {
+ if (TNC->PortRecord->ATTACHEDSESSIONS[Stream]) // Connected
+ {
+ TNC->Streams[Stream].Connected = FALSE; // Back to Command Mode
+ TNC->Streams[Stream].ReportDISC = TRUE; // Tell Node
+ }
+ }
+ }
+
+ for (Stream = 0; Stream <= MaxStreams; Stream++)
+ {
+ STREAM = &TNC->Streams[Stream];
+
+ if (STREAM->Attached)
+ CheckForDetach(TNC, Stream, STREAM, TidyClose, ForcedClose, CloseComplete);
+
+ if (TNC->Timeout)
+ return; // We've sent something
+ }
+
+ // if we have just restarted or TNC appears to be in terminal mode, run Initialisation Sequence
+
+ if (!TNC->HostMode)
+ {
+ DoTNCReinit(TNC);
+ return;
+ }
+
+ if (TNC->InitPtr)
+ {
+ char * start, * end;
+ int len;
+
+ start = TNC->InitPtr;
+
+ if (*(start) == 0) // End of Script
+ {
+ TNC->InitPtr = NULL;
+ Debugprintf("TRK - Init Complete Port %d", TNC->Port);
+ }
+ else
+ {
+ end = strchr(start, 13);
+ len = (int)(++end - start - 1); // exclude cr
+
+ TNC->InitPtr = end;
+
+ Poll[0] = 0; // Channel
+ Poll[1] = 1; // Command
+ Poll[2] = len - 1;
+ memcpy(&Poll[3], start, len);
+
+ StuffAndSend(TNC, Poll, len + 3);
+
+ return;
+
+ }
+ }
+
+ for (Stream = 0; Stream <= MaxStreams; Stream++)
+ {
+ if (TNC->Streams[Stream].CmdSet)
+ {
+ char * start, * end;
+ int len;
+
+ start = TNC->Streams[Stream].CmdSet;
+
+ if (*(start + 2) == 0) // End of Script
+ {
+ free(TNC->Streams[Stream].CmdSave);
+ TNC->Streams[Stream].CmdSet = NULL;
+ }
+ else
+ {
+ end = strchr(start + 3, 0);
+ len = (int)(++end - start - 1); // exclude cr
+ TNC->Streams[Stream].CmdSet = end;
+
+ memcpy(&Poll[0], start, len);
+ Poll[2] = len - 4;
+
+ StuffAndSend(TNC, Poll, len);
+
+ return;
+ }
+ }
+ }
+
+ for (nn = 0; nn <= MaxStreams; nn++)
+ {
+ Stream = TNC->LastStream++;
+
+ if (TNC->LastStream > MaxStreams) TNC->LastStream = 0;
+
+ if (TNC->TNCOK && TNC->Streams[Stream].BPQtoPACTOR_Q)
+ {
+ int datalen;
+ UINT * buffptr;
+ char * Buffer;
+
+ buffptr=Q_REM(&TNC->Streams[Stream].BPQtoPACTOR_Q);
+
+ datalen=buffptr[1];
+ Buffer = (char *)&buffptr[2]; // Data portion of frame
+
+ Poll[0] = TNC->Streams[Stream].DEDStream; // Channel
+
+ if (TNC->Streams[Stream].Connected)
+ {
+ if (TNC->SwallowSignon && Stream == 0)
+ {
+ TNC->SwallowSignon = FALSE;
+ if (strstr(Buffer, "Connected")) // Discard *** connected
+ {
+ ReleaseBuffer(buffptr);
+ return;
+ }
+ }
+
+ Poll[1] = 0; // Data
+ TNC->Streams[Stream].BytesTXed += datalen;
+
+ Poll[2] = datalen - 1;
+ memcpy(&Poll[3], buffptr+2, datalen);
+
+ ReleaseBuffer(buffptr);
+
+ StuffAndSend(TNC, Poll, datalen + 3);
+
+ TNC->Streams[Stream].InternalCmd = TNC->Streams[Stream].Connected;
+
+ if (STREAM->Disconnecting && TNC->Streams[Stream].BPQtoPACTOR_Q == 0)
+ TidyClose(TNC, 0);
+
+ return;
+ }
+
+ // Command. Do some sanity checking and look for things to process locally
+
+ Poll[1] = 1; // Command
+ datalen--; // Exclude CR
+
+ if (datalen == 0) // Null Command
+ {
+ ReleaseBuffer(buffptr);
+ return;
+ }
+
+ Buffer[datalen] = 0; // Null Terminate
+ _strupr(Buffer);
+
+ if (_memicmp(Buffer, "D", 1) == 0)
+ {
+ TNC->Streams[Stream].ReportDISC = TRUE; // Tell Node
+ ReleaseBuffer(buffptr);
+ return;
+ }
+
+ if (Buffer[0] == 'C' && datalen > 2) // Connect
+ {
+ if (Stream == 0)
+ {
+ // No connects on Stream zero - for mgmt only
+
+ buffptr[1] = sprintf((UCHAR *)&buffptr[2], "TRK} Can't Connect after ATTACH\r");
+ C_Q_ADD(&TNC->Streams[0].PACTORtoBPQ_Q, buffptr);
+
+ return;
+
+ }
+
+ if (*(++Buffer) == ' ') Buffer++; // Space isn't needed
+
+ memcpy(TNC->Streams[Stream].RemoteCall, Buffer, 9);
+
+ TNC->Streams[Stream].Connecting = TRUE;
+
+ TNC->Streams[Stream].CmdSet = TNC->Streams[Stream].CmdSave = zalloc(100);
+
+ sprintf(TNC->Streams[Stream].CmdSet, "%c%c%cI%s%c%c%c%c%s", Stream, 1, 1,
+ TNC->Streams[Stream].MyCall, 0, Stream, 1, 1, (char *)buffptr+8);
+
+ ReleaseBuffer(buffptr);
+
+ TNC->Streams[Stream].InternalCmd = FALSE;
+ return;
+ }
+
+ Poll[2] = datalen - 1;
+ memcpy(&Poll[3], buffptr+2, datalen);
+
+ ReleaseBuffer(buffptr);
+
+ StuffAndSend(TNC, Poll, datalen + 3);
+
+ TNC->Streams[Stream].InternalCmd = TNC->Streams[Stream].Connected;
+
+ return;
+ }
+ }
+
+ if (TNC->TNCOK && TNC->PortRecord->UI_Q)
+ {
+ int datalen;
+ char * Buffer;
+ char CCMD[80] = "C";
+ char Call[12] = " ";
+ struct _MESSAGE * buffptr;
+
+ buffptr = Q_REM(&TNC->PortRecord->UI_Q);
+
+ datalen = buffptr->LENGTH - 7;
+ Buffer = &buffptr->DEST[0]; // Raw Frame
+ Buffer[datalen] = 0;
+
+ TNC->Streams[0].CmdSet = TNC->Streams[0].CmdSave = zalloc(500);
+
+// sprintf(TNC->Streams[Stream].CmdSet, "I%s\r%s\r", TNC->Streams[Stream].MyCall, buffptr+2);
+
+ // Buffer has an ax.25 header, which we need to pick out and set as channel 0 Connect address
+ // before sending the beacon
+
+ ConvFromAX25(Buffer, &Call[1]); // Dest
+ strlop(&Call[1], ' ');
+ strcat(CCMD, Call);
+ Buffer += 14; // Skip Origin
+ datalen -= 7;
+
+ while ((Buffer[-1] & 1) == 0)
+ {
+ ConvFromAX25(Buffer, &Call[1]);
+ strlop(&Call[1], ' ');
+ strcat(CCMD, Call);
+ Buffer += 7; // End of addr
+ datalen -= 7;
+ }
+
+ if (Buffer[0] == 3) // UI
+ {
+ Buffer += 2;
+ datalen -= 2;
+
+ Poll[0] = 0; // UI Channel
+ Poll[1] = 1; // Data
+ Poll[2] = (int)strlen(CCMD) - 1;
+ strcpy(&Poll[3], CCMD);
+ StuffAndSend(TNC, Poll, Poll[2] + 4);
+
+ sprintf(TNC->Streams[0].CmdSet, "%c%c%c%s", 0, 0, 1, Buffer);
+ }
+
+ ReleaseBuffer((UINT *)buffptr);
+ return;
+ }
+
+ // if frames outstanding, issue a poll (but not too often)
+
+ TNC->IntCmdDelay++;
+
+ if (TNC->IntCmdDelay > 10)
+ {
+ TNC->IntCmdDelay = 0;
+
+ Poll[0] = TNC->Streams[0].DEDStream;
+ Poll[1] = 0x1; // Command
+ TNC->Streams[0].InternalCmd = TRUE;
+
+ Poll[2] = 1; // Len-1
+ Poll[3] = '@';
+ Poll[4] = 'B'; // Buffers
+ StuffAndSend(TNC, Poll, 5);
+ return;
+ }
+
+ // Need to poll all channels . Just Poll zero here, the ProcessMessage will poll next
+
+ Poll[0] = 0; // Channel
+ Poll[1] = 0x1; // Command
+ Poll[2] = 0; // Len-1
+ Poll[3] = 'G'; // Poll
+
+ StuffAndSend(TNC, Poll, 4);
+
+ return;
+
+
+ Stream = TNC->StreamtoPoll;
+
+ STREAM = &TNC->Streams[Stream];
+
+ STREAM->IntCmdDelay++;
+
+ if (STREAM->IntCmdDelay > 10)
+ {
+ STREAM->IntCmdDelay = 0;
+
+ if (STREAM->FramesOutstanding)
+ {
+ Poll[0] = STREAM->DEDStream;
+ Poll[1] = 0x1; // Command
+ STREAM->InternalCmd = TRUE;
+
+ Poll[2] = 0; // Len-1
+ Poll[3] = 'L'; // Status
+ StuffAndSend(TNC, Poll, 4);
+
+ return;
+ }
+ }
+
+
+ Poll[0] = Stream; // Channel
+ Poll[1] = 0x1; // Command
+ Poll[2] = 0; // Len-1
+ Poll[3] = 'G'; // Poll
+
+ StuffAndSend(TNC, Poll, 4);
+ STREAM->InternalCmd = FALSE;
+
+ return;
+
+}
+
+static VOID DoTNCReinit(struct TNCINFO * TNC)
+{
+ UCHAR * Poll = TNC->TXBuffer;
+
+ if (TNC->ReinitState == 0)
+ {
+ // Just Starting - Send a TNC Mode Command to see if in Terminal or Host Mode
+
+ TNC->TNCOK = FALSE;
+
+ memcpy(&TNC->TXBuffer[0], "\x18\x1b\r", 2);
+ TNC->TXLen = 2;
+
+ if (WriteCommBlock(TNC) == FALSE)
+ {
+ CloseCOMPort(TNC->hDevice);
+ OpenCOMMPort(TNC, TNC->PortRecord->PORTCONTROL.SerialPortName, TNC->PortRecord->PORTCONTROL.BAUDRATE, TRUE);
+ }
+
+ return;
+ }
+
+ if (TNC->ReinitState == 1) // Forcing back to Term
+ TNC->ReinitState = 0;
+
+ if (TNC->ReinitState == 2) // In Term State, Sending Initialisation Commands
+ {
+ // Put into Host Mode
+
+ memcpy(Poll, "\x18\x1bJHOST1\r", 9);
+
+ TNC->TXLen = 9;
+ WriteCommBlock(TNC);
+
+ TNC->ReinitState = 5;
+ return;
+ }
+
+ if (TNC->ReinitState == 5)
+ TNC->ReinitState = 0;
+
+}
+
+static VOID DoTermModeTimeout(struct TNCINFO * TNC)
+{
+ UCHAR * Poll = TNC->TXBuffer;
+
+ if (TNC->ReinitState == 0)
+ {
+ //Checking if in Terminal Mode - Try to set back to Term Mode
+
+ TNC->ReinitState = 1;
+ ExitHost(TNC);
+
+ return;
+ }
+
+ if (TNC->ReinitState == 1)
+ {
+ // No Response to trying to enter term mode - do error recovery
+
+ Debugprintf("TRK - Starting Resync Port %d", TNC->Port);
+
+ TNC->ReinitState = 10;
+ TNC->ReinitCount = 256;
+ TNC->HostMode = TRUE; // Must be in Host Mode if we need recovery
+
+ Poll[0] = 1;
+ TNC->TXLen = 1;
+ WriteCommBlock(TNC);
+ TNC->Timeout = 10; // 2 secs
+
+ return;
+ }
+
+ if (TNC->ReinitState == 10)
+ {
+ // Continue error recovery
+
+ TNC->ReinitCount--;
+
+ if (TNC->ReinitCount)
+ {
+ Poll[0] = 1;
+ TNC->TXLen = 1;
+ WriteCommBlock(TNC);
+ TNC->Timeout = 3; // 0.3 secs
+
+ return;
+ }
+
+ // Try Again
+
+ Debugprintf("TRK Continuing recovery Port %d", TNC->Port);
+
+ TNC->ReinitState = 0;
+
+ // Close and re-open TNC
+
+ ExitHost(TNC);
+ Sleep(50);
+ CloseCOMPort(TNC->hDevice);
+ TNC->hDevice =(HANDLE) 0;
+ TNC->ReopenTimer = 290;
+ TNC->HostMode = FALSE;
+
+ return;
+ }
+ if (TNC->ReinitState == 3)
+ {
+ // Entering Host Mode
+
+ // Assume ok
+
+ TNC->HostMode = TRUE;
+ TNC->IntCmdDelay = 10;
+
+ return;
+ }
+}
+
+
+static VOID ExitHost(struct TNCINFO * TNC)
+{
+ UCHAR * Poll = TNC->TXBuffer;
+
+ // Try to exit Host Mode
+
+ TNC->TXBuffer[0] = 1;
+ TNC->TXBuffer[1] = 1;
+ TNC->TXBuffer[2] = 1;
+ memcpy(&TNC->TXBuffer[3], "%R", 2);
+
+ StuffAndSend(TNC, Poll, 5);
+
+ return;
+}
+
+static VOID ProcessTermModeResponse(struct TNCINFO * TNC)
+{
+ UCHAR * Poll = TNC->TXBuffer;
+
+ if (TNC->WRITELOG)
+ WriteDebugLogLine(TNC->Port, 'R', TNC->RXBuffer, TNC->RXLen);
+
+ if (TNC->ReinitState == 0)
+ {
+ // Testing if in Term Mode. It is, so can now send Init Commands
+
+ TNC->InitPtr = TNC->InitScript;
+ TNC->ReinitState = 2;
+ }
+
+ if (TNC->ReinitState == 1)
+ {
+ // trying to set term mode
+
+ // If already in Term Mode, TNC echos command, with control chars replaced with '.'
+
+ if (memcmp(TNC->RXBuffer, "....%R", 6) == 0)
+ {
+ // In term mode, Need to put into Host Mode
+
+ TNC->ReinitState = 2;
+ DoTNCReinit(TNC);
+ return;
+ }
+ }
+
+ if (TNC->ReinitState == 2)
+ {
+ // Sending Init Commands
+
+ DoTNCReinit(TNC); // Send Next Command
+ return;
+ }
+
+ if (TNC->ReinitState == 5) // Waiting for response to JHOST1
+ {
+ if (TNC->RXBuffer[TNC->RXLen-1] == 10 || TNC->RXBuffer[TNC->RXLen-1] == 13) // NewLine
+ {
+ TNC->HostMode = TRUE;
+ TNC->Timeout = 0;
+ }
+ return;
+ }
+}
+
+static VOID ProcessDEDFrame(struct TNCINFO * TNC)
+{
+ UINT * buffptr;
+ char * Buffer; // Data portion of frame
+ UINT Stream = 0;
+ UCHAR * Msg = TNC->DEDBuffer;
+ int framelen = TNC->InputLen;
+ struct STREAMINFO * STREAM;
+
+ if (TNC->WRITELOG)
+ WriteDebugLogLine(TNC->Port, 'R', Msg, framelen);
+
+ if (TNC->ReinitState == 10)
+ {
+ // Recovering from Sync Failure
+
+ // Any Response indicates we are in host mode, and back in sync
+
+ TNC->HostMode = TRUE;
+ TNC->Timeout = 0;
+ TNC->ReinitState = 0;
+ TNC->RXLen = 0;
+ TNC->HOSTSTATE = 0;
+ return;
+ }
+
+ // Any valid frame is an ACK
+
+ TNC->Timeout = 0;
+ TNC->TNCOK = TRUE;
+
+ if (TNC->InitPtr) // Response to Init Script
+ return;
+
+ if (TNC->MSGCHANNEL > 26)
+ return;
+
+ Stream = TNC->MSGCHANNEL;
+
+ // See if Poll Reply or Data
+
+ if (TNC->MSGTYPE == 0)
+ {
+ // Success - Nothing Follows
+
+ if (TNC->Streams[Stream].CmdSet)
+ return; // Response to Command Set or Init Script
+
+ if ((TNC->TXBuffer[1] & 1) == 0) // Data
+ return;
+
+ // If the response to a Command, then we should convert to a text "Ok" for forward scripts, etc
+
+ if (TNC->TXBuffer[3] == 'G') // Poll
+ {
+ UCHAR * Poll = TNC->TXBuffer;
+
+ // Poll Next Channel (we need to scan all channels every DEDPOLL cycle
+
+ Stream++;
+
+ if (Stream > MaxStreams)
+ return;
+
+ STREAM = &TNC->Streams[Stream];
+
+ STREAM->IntCmdDelay++;
+
+ if (STREAM->IntCmdDelay > 10)
+ {
+ STREAM->IntCmdDelay = 0;
+
+ if (STREAM->FramesOutstanding)
+ {
+ Poll[0] = STREAM->DEDStream;
+ Poll[1] = 0x1; // Command
+ STREAM->InternalCmd = TRUE;
+
+ Poll[2] = 0; // Len-1
+ Poll[3] = 'L'; // Status
+ StuffAndSend(TNC, Poll, 4);
+ return;
+ }
+ }
+
+ Poll[0] = Stream; // Channel
+ Poll[1] = 0x1; // Command
+ Poll[2] = 0; // Len-1
+ Poll[3] = 'G'; // Poll
+
+ StuffAndSend(TNC, Poll, 4);
+ STREAM->InternalCmd = FALSE;
+
+ return;
+ }
+
+ if (TNC->TXBuffer[3] == 'C') // Connect - reply we need is async
+ return;
+
+ if (TNC->TXBuffer[3] == 'L') // Shouldnt happen!
+ return;
+
+
+ if (TNC->TXBuffer[3] == 'J') // JHOST
+ {
+ if (TNC->TXBuffer[8] == '0') // JHOST0
+ {
+ TNC->Timeout = 1; //
+ return;
+ }
+ }
+
+ if (TNC->MSGCHANNEL == 0) // Unproto Channel
+ return;
+
+ buffptr = GetBuff();
+
+ if (buffptr == NULL) return; // No buffers, so ignore
+
+ buffptr[1] = sprintf((UCHAR *)&buffptr[2],"TRK} Ok\r");
+
+ C_Q_ADD(&TNC->Streams[Stream].PACTORtoBPQ_Q, buffptr);
+
+ return;
+ }
+
+ if (TNC->MSGTYPE > 0 &&TNC->MSGTYPE < 6)
+ {
+ // Success with message - null terminated
+
+ char * ptr;
+ int len;
+
+ Buffer = Msg;
+
+ ptr = strchr(Buffer, 0);
+
+ if (ptr == 0)
+ return;
+
+ *(ptr++) = 13;
+ *(ptr) = 0;
+
+ len = (int)(ptr - Buffer);
+
+ if (len > 256)
+ return;
+
+ // See if we need to process locally (Response to our command, Incoming Call, Disconencted, etc
+
+ if (TNC->MSGTYPE < 3) // 1 or 2 - Success or Fail
+ {
+ // See if a response to internal command
+
+ if (TNC->Streams[Stream].InternalCmd)
+ {
+ // Process it
+
+ char LastCmd = TNC->TXBuffer[3];
+
+ if (LastCmd == 'L') // Status
+ {
+ int s1, s2, s3, s4, s5, s6, num;
+
+ num = sscanf(Buffer, "%d %d %d %d %d %d", &s1, &s2, &s3, &s4, &s5, &s6);
+
+ TNC->Streams[Stream].FramesOutstanding = s3;
+ return;
+ }
+
+ if (LastCmd == '@') // @ Commands
+ {
+ if (TNC->TXBuffer[4]== 'B') // Buffer Status
+ {
+ TNC->Buffers = atoi(Buffer);
+// SetDlgItemText(TNC->hDlg, IDC_BUFFERS, Buffer);
+ return;
+ }
+ }
+
+ return;
+ }
+
+ // Not Internal Command, so send to user
+
+ if (TNC->Streams[Stream].CmdSet)
+ return; // Response to Command Set
+
+ if ((TNC->TXBuffer[1] & 1) == 0) // Data
+ return;
+
+ // If the response to a Command, then we should convert to a text "Ok" for forward scripts, etc
+
+ if (TNC->TXBuffer[3] == 'G') // Poll
+ return;
+
+ if (TNC->TXBuffer[3] == 'C') // Connect - reply we need is async
+ return;
+
+ if (TNC->TXBuffer[3] == 'L') // Shouldnt happen!
+ return;
+
+ if (TNC->TXBuffer[3] == 'J') // JHOST
+ {
+ if (TNC->TXBuffer[8] == '0') // JHOST0
+ {
+ TNC->Timeout = 1; //
+ return;
+ }
+ }
+
+ if (TNC->MSGCHANNEL == 0) // Unproto Channel
+ return;
+
+ buffptr = GetBuff();
+
+ if (buffptr == NULL) return; // No buffers, so ignore
+
+ buffptr[1] = sprintf((UCHAR *)&buffptr[2],"TRK} %s", Buffer);
+
+ C_Q_ADD(&TNC->Streams[Stream].PACTORtoBPQ_Q, buffptr);
+
+ return;
+ }
+
+ if (TNC->MSGTYPE == 3) // Status
+ {
+ struct STREAMINFO * STREAM = &TNC->Streams[Stream];
+
+ if (strstr(Buffer, "DISCONNECTED") || strstr(Buffer, "LINK FAILURE") || strstr(Buffer, "BUSY"))
+ {
+ if ((STREAM->Connecting | STREAM->Connected) == 0)
+ return;
+
+ if (STREAM->Connecting && STREAM->Disconnecting == FALSE)
+ {
+ // Connect Failed
+
+ buffptr = GetBuff();
+ if (buffptr == 0) return; // No buffers, so ignore
+
+ if (strstr(Buffer, "BUSY"))
+ buffptr[1] = sprintf((UCHAR *)&buffptr[2], "*** Busy from %s\r", TNC->Streams[Stream].RemoteCall);
+ else
+ buffptr[1] = sprintf((UCHAR *)&buffptr[2], "*** Failure with %s\r", TNC->Streams[Stream].RemoteCall);
+
+ C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr);
+
+ STREAM->Connecting = FALSE;
+ STREAM->Connected = FALSE; // In case!
+ STREAM->FramesOutstanding = 0;
+
+ STREAM->DiscWhenAllSent = 15; // Dont want to leave session attached. Causes too much confusion
+
+ return;
+ }
+
+ // Must Have been connected or disconnecting - Release Session
+
+ STREAM->Connecting = FALSE;
+ STREAM->Connected = FALSE; // Back to Command Mode
+ STREAM->FramesOutstanding = 0;
+
+ if (STREAM->Disconnecting == FALSE)
+ STREAM->ReportDISC = TRUE; // Tell Node
+
+ STREAM->Disconnecting = FALSE;
+ return;
+ }
+
+ if (strstr(Buffer, "CONNECTED"))
+ {
+ char * Call = strstr(Buffer, " to ");
+ char * ptr;
+ char MHCall[30];
+
+ Call += 4;
+
+ if (Call[1] == ':')
+ Call +=2;
+
+ ptr = strchr(Call, ' ');
+ if (ptr) *ptr = 0;
+
+ ptr = strchr(Call, 13);
+ if (ptr) *ptr = 0;
+
+ STREAM->Connected = TRUE; // Subsequent data to data channel
+ STREAM->Connecting = FALSE;
+
+ STREAM->BytesRXed = STREAM->BytesTXed = 0;
+
+ memcpy(MHCall, Call, 9);
+ MHCall[9] = 0;
+
+ if (TNC->PortRecord->ATTACHEDSESSIONS[Stream] == 0)
+ {
+ // Incoming Connect
+
+// APPLCALLS * APPL;
+// char * ApplPtr = &APPLS;
+// int App;
+// char Appl[10];
+// char DestCall[10];
+
+ UpdateMH(TNC, MHCall, '+', 'I');
+
+ ProcessIncommingConnect(TNC, Call, Stream, TRUE);
+
+ if (FULL_CTEXT && HFCTEXTLEN == 0)
+ {
+ int Len = CTEXTLEN, CTPaclen = 100;
+ int Next = 0;
+
+ while (Len > CTPaclen) // CTEXT Paclen
+ {
+ buffptr = GetBuff();
+ if (buffptr == 0) return; // No buffers, so ignore
+
+ buffptr[1] = CTPaclen;
+ memcpy(&buffptr[2], &CTEXTMSG[Next], CTPaclen);
+ C_Q_ADD(&STREAM->BPQtoPACTOR_Q, buffptr);
+
+ Next += CTPaclen;
+ Len -= CTPaclen;
+ }
+
+ buffptr = GetBuff();
+ if (buffptr == 0) return; // No buffers, so ignore
+
+ buffptr[1] = Len;
+ memcpy(&buffptr[2], &CTEXTMSG[Next], Len);
+ C_Q_ADD(&STREAM->BPQtoPACTOR_Q, buffptr);
+ }
+
+ return;
+ }
+ else
+ {
+ // Connect Complete
+
+ buffptr = GetBuff();
+ if (buffptr == 0) return; // No buffers, so ignore
+
+ buffptr[1] = sprintf((UCHAR *)&buffptr[2], "*** Connected to %s\r", Call);;
+
+ C_Q_ADD(&STREAM->PACTORtoBPQ_Q, buffptr);
+
+ }
+ }
+ return;
+ }
+
+ if (TNC->MSGTYPE == 4 || TNC->MSGTYPE == 5)
+ {
+ struct STREAMINFO * STREAM = &TNC->Streams[0]; // RP Stream
+
+ // Monitor
+
+/*
+ if (TNC->UseAPPLCalls && strstr(&Msg[4], "SABM") && STREAM->Attached == FALSE)
+ {
+ // See if a call to Nodecall or one of our APPLCALLS - if so, stop scan and switch MYCALL
+
+ char DestCall[10] = "NOCALL ";
+ char * ptr1 = strstr(&Msg[7], "to ");
+ int i;
+ APPLCALLS * APPL;
+ char Appl[11];
+ char Status[80];
+
+ if (ptr1) memcpy(DestCall, &ptr1[3], 10);
+
+ ptr1 = strchr(DestCall, ' ');
+ if (ptr1) *(ptr1) = 0; // Null Terminate
+
+ Debugprintf("RP SABM Received for %s" , DestCall);
+
+ if (strcmp(TNC->NodeCall, DestCall) != 0)
+ {
+ // Not Calling NodeCall/Portcall
+
+ if (strcmp(NodeCall, DestCall) == 0)
+ goto SetThisCall;
+
+ // See if to one of our ApplCalls
+
+ 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, ' ');
+
+ if (ptr) *ptr = 0;
+
+ if (strcmp(Appl, DestCall) == 0)
+ {
+ SetThisCall:
+ Debugprintf("RP SABM is for NODECALL or one of our APPLCalls - setting MYCALL to %s and pausing scan", DestCall);
+
+ sprintf(Status, "%d SCANSTART 60", TNC->Port); // Pause scan for 60 secs
+ Rig_Command(-1, Status);
+ TNC->SwitchToPactor = 600; // Don't change modes for 60 secs
+
+ strcpy(STREAM->MyCall, DestCall);
+ STREAM->CmdSet = STREAM->CmdSave = zalloc(100);
+ sprintf(STREAM->CmdSet, "I%s\r", DestCall);
+ break;
+ }
+ }
+ }
+ }
+ }
+*/
+ DoMonitorHddr(TNC, Msg, framelen, TNC->MSGTYPE);
+ return;
+
+ }
+
+ // 1, 2, 4, 5 - pass to Appl
+
+ if (TNC->MSGCHANNEL == 0) // Unproto Channel
+ return;
+
+ buffptr = GetBuff();
+
+ if (buffptr == NULL) return; // No buffers, so ignore
+
+ buffptr[1] = sprintf((UCHAR *)&buffptr[2],"Trk} %s", &Msg[4]);
+
+ C_Q_ADD(&TNC->Streams[Stream].PACTORtoBPQ_Q, buffptr);
+
+ return;
+ }
+
+ if (TNC->MSGTYPE == 6)
+ {
+ // Monitor Data With length)
+
+ DoMonitorData(TNC, Msg, framelen);
+ return;
+ }
+
+ if (TNC->MSGTYPE == 7)
+ {
+ //char StatusMsg[60];
+ //int Status, ISS, Offset;
+
+ // Connected Data
+
+ buffptr = GetBuff();
+
+ if (buffptr == NULL) return; // No buffers, so ignore
+
+ buffptr[1] = framelen; // Length
+ TNC->Streams[Stream].BytesRXed += buffptr[1];
+ memcpy(&buffptr[2], Msg, buffptr[1]);
+
+ C_Q_ADD(&TNC->Streams[Stream].PACTORtoBPQ_Q, buffptr);
+
+ return;
+ }
+}
+
+VOID TidyClose(struct TNCINFO * TNC, int Stream)
+{
+ // Queue it as we may have just sent data
+
+ TNC->Streams[Stream].CmdSet = TNC->Streams[Stream].CmdSave = zalloc(100);
+ sprintf(TNC->Streams[Stream].CmdSet, "%c%c%cD", Stream, 1, 1);
+}
+
+
+VOID ForcedClose(struct TNCINFO * TNC, int Stream)
+{
+ TidyClose(TNC, Stream); // I don't think Hostmode has a DD
+}
+
+VOID CloseComplete(struct TNCINFO * TNC, int Stream)
+{
+}
+
+
@@ -10,8 +10,8 @@ #endif
-#define KVers 6,0,24,67
-#define KVerstring "6.0.24.67\0"
+#define KVers 6,0,24,69
+#define KVerstring "6.0.24.69\0"
#ifdef CKernel
@@ -1446,7 +1446,12 @@ void ProcessWebMailMessage(struct HTTPConnectionInfo * Session, char * Key, BOOL // Neither do js or file downloads
- if (_memicmp(NodeURL, "/WebMail/WMFile/", 16) == 0)
+ // This could be a request for a Template file
+ // WebMail/Local_Templates/My Forms/inc/logo_ad63.png
+ // WebMail/Standard Templates/
+
+
+ if (_memicmp(NodeURL, "/WebMail/Local", 14) == 0 || (_memicmp(NodeURL, "/WebMail/Standard", 17) == 0))
{
int FileSize;
char * MsgBytes;
@@ -1456,9 +1461,10 @@ void ProcessWebMailMessage(struct HTTPConnectionInfo * Session, char * Key, BOOL char TimeString[64];
char FileTimeString[64];
struct stat STAT;
- char * FN = &NodeURL[16];
+ char * FN = &NodeURL[9];
char * fileBit = FN;
char * ext;
+ char Type[64] = "Content-Type: text/html\r\n";
UndoTransparency(FN);
ext = strchr(FN, '.');
@@ -1491,27 +1497,112 @@ void ProcessWebMailMessage(struct HTTPConnectionInfo * Session, char * Key, BOOL FormatTime2(FileTimeString, STAT.st_ctime);
FormatTime2(TimeString, time(NULL));
- if (_stricmp(ext, ".htm") == 0 || _stricmp(ext, ".html") == 0 || _stricmp(ext, ".css") == 0 || _stricmp(ext, ".js") == 0)
- {
- *RLen = sprintf(Reply, "HTTP/1.1 200 OK\r\nContent-Length: %d\r\n"
- "Content-Type: text/css\r\n"
+ ext++;
+
+ if (_stricmp(ext, "js") == 0)
+ strcpy(Type, "Content-Type: text/javascript\r\n");
+
+ if (_stricmp(ext, "css") == 0)
+ strcpy(Type, "Content-Type: text/css\r\n");
+
+ if (_stricmp(ext, "pdf") == 0)
+ strcpy(Type, "Content-Type: application/pdf\r\n");
+
+ if (_stricmp(ext, "jpg") == 0 || _stricmp(ext, "jpeg") == 0 || _stricmp(ext, "png") == 0 ||
+ _stricmp(ext, "gif") == 0 || _stricmp(ext, "bmp") == 0 || _stricmp(ext, "ico") == 0)
+ strcpy(Type, "Content-Type: image\r\n");
+
+ // File may be binary so output header then copy in message
+
+ *RLen = sprintf(Reply, "HTTP/1.1 200 OK\r\nContent-Length: %d\r\n"
+ "%s"
"Date: %s\r\n"
"Last-Modified: %s\r\n"
- "\r\n%s", FileSize, TimeString, FileTimeString, MsgBytes);
+ "\r\n", FileSize, Type,TimeString, FileTimeString);
+
+ memcpy(&Reply[*RLen], MsgBytes, FileSize);
+ *RLen += FileSize;
+ free (MsgBytes);
+ return;
+ }
+
+ //
+
+ if (_memicmp(NodeURL, "/WebMail/WMFile/", 16) == 0)
+ {
+ int FileSize;
+ char * MsgBytes;
+ char MsgFile[512];
+ FILE * hFile;
+ size_t ReadLen;
+ char TimeString[64];
+ char FileTimeString[64];
+ struct stat STAT;
+ char * FN = &NodeURL[16];
+ char * fileBit = FN;
+ char * ext;
+ char Type[64] = "Content-Type: text/html\r\n";
+
+
+ UndoTransparency(FN);
+ ext = strchr(FN, '.');
+
+ sprintf(MsgFile, "%s/%s", BPQDirectory, FN);
+
+ while (strchr(fileBit, '/'))
+ fileBit = strlop(fileBit, '/');
+
+ if (stat(MsgFile, &STAT) == -1)
+ {
+ *RLen = sprintf(Reply, "HTTP/1.1 404 Not Found\r\nContent-Length: 16\r\n\r\nPage not found\r\n");
+ return;
}
- else
+
+ hFile = fopen(MsgFile, "rb");
+
+ if (hFile == 0)
{
- *RLen = sprintf(Reply, "HTTP/1.1 200 OK\r\nContent-Length: %d\r\n"
- "Content-Type: application/octet-stream\r\n"
- "Content-Disposition: attachment; filename=\"%s\"\r\n"
+ *RLen = sprintf(Reply, "HTTP/1.1 404 Not Found\r\nContent-Length: 16\r\n\r\nPage not found\r\n");
+ return;
+ }
+
+ FileSize = STAT.st_size;
+ MsgBytes = malloc(FileSize + 1);
+ ReadLen = fread(MsgBytes, 1, FileSize, hFile);
+
+ fclose(hFile);
+
+ FormatTime2(FileTimeString, STAT.st_ctime);
+ FormatTime2(TimeString, time(NULL));
+
+ ext++;
+
+ if (_stricmp(ext, "js") == 0)
+ strcpy(Type, "Content-Type: text/javascript\r\n");
+
+ if (_stricmp(ext, "css") == 0)
+ strcpy(Type, "Content-Type: text/css\r\n");
+
+ if (_stricmp(ext, "pdf") == 0)
+ strcpy(Type, "Content-Type: application/pdf\r\n");
+
+ if (_stricmp(ext, "jpg") == 0 || _stricmp(ext, "jpeg") == 0 || _stricmp(ext, "png") == 0 ||
+ _stricmp(ext, "gif") == 0 || _stricmp(ext, "bmp") == 0 || _stricmp(ext, "ico") == 0)
+ strcpy(Type, "Content-Type: image\r\n");
+
+ // File may be binary so output header then copy in message
+
+ *RLen = sprintf(Reply, "HTTP/1.1 200 OK\r\nContent-Length: %d\r\n"
+ "%s"
"Date: %s\r\n"
"Last-Modified: %s\r\n"
- "\r\n%s", FileSize, fileBit, TimeString, FileTimeString, MsgBytes);
+ "\r\n", FileSize, Type,TimeString, FileTimeString);
- }
+ memcpy(&Reply[*RLen], MsgBytes, FileSize);
+ *RLen += FileSize;
free (MsgBytes);
return;
- }
+ }
Session = NULL;
@@ -2883,7 +2974,7 @@ VOID SaveNewMessage(struct HTTPConnectionInfo * Session, char * MsgPtr, char * R // RMS Express Forms Support
-char * GetHTMLViewerTemplate(char * FN)
+char * GetHTMLViewerTemplate(char * FN, struct HtmlFormDir ** FormDir)
{
int i, j, k, l;
@@ -2897,6 +2988,7 @@ char * GetHTMLViewerTemplate(char * FN) {
if (strcmp(FN, Dir->Forms[j]->FileName) == 0)
{
+ *FormDir = Dir;
return CheckFile(Dir, FN);
}
}
@@ -2917,6 +3009,7 @@ char * GetHTMLViewerTemplate(char * FN) {
if (_stricmp(FN, SDir->Forms[k]->FileName) == 0)
{
+ *FormDir = SDir;
return CheckFile(SDir, SDir->Forms[k]->FileName);
}
}
@@ -3293,6 +3386,13 @@ BOOL ParseXML(WebMailInfo * WebMail, char * XMLOrig) // Extract Fields (stuff between < and >. Ignore Whitespace between fields
+ // Add FormFolder Key with our folder
+
+// XMLKeys->Key = "FormFolder";
+// XMLKeys->Value = _strdup(FormDir);
+
+// XMLKeys++;
+
ptr1 = strstr(XML, "<xml_file_version>");
while (ptr1)
@@ -3396,6 +3496,8 @@ int DisplayWebForm(struct HTTPConnectionInfo * Session, struct MsgInfo * Msg, ch size_t varlen, xmllen;
char var[100] = "<";
KeyValues * KeyValue;
+ struct HtmlFormDir * Dir;
+ char FormDir[MAX_PATH];
if (ParseXML(WebMail, XML))
ptr = FindXMLVariable(WebMail, "display_form");
@@ -3409,7 +3511,11 @@ int DisplayWebForm(struct HTTPConnectionInfo * Session, struct MsgInfo * Msg, ch strcpy(FN, ptr);
- Form = GetHTMLViewerTemplate(FN);
+ Form = GetHTMLViewerTemplate(FN, &Dir);
+
+ sprintf(FormDir, "WMFile/%s/%s/", Dir->FormSet, Dir->DirName);
+
+
if (Form == NULL)
{
@@ -3425,6 +3531,15 @@ int DisplayWebForm(struct HTTPConnectionInfo * Session, struct MsgInfo * Msg, ch // Don't know why, but {MsgOriginalBody} is sent instead of {var MsgOriginalBody}
+ // So is {FormFolder} instread of {var FormFolder}
+
+ // As a fiddle replace {FormFolder} with {var Folder} and look for that
+
+ while (varptr = stristr(Form, "{FormFolder}"))
+ {
+ memcpy(varptr, "{var ", 5);
+ }
+
varptr = stristr(Form, "{MsgOriginalBody}");
{
char * temp, * tempsave;
@@ -3564,6 +3679,23 @@ int DisplayWebForm(struct HTTPConnectionInfo * Session, struct MsgInfo * Msg, ch while (KeyValue->Key)
{
+ if (_stricmp(var, "Folder") == 0)
+ {
+ // Local form folder, not senders
+
+ xmllen = strlen(FormDir);
+
+ // Ok, we have the position of the variable and the substitution text.
+ // Copy message up to variable to Result, then copy value
+
+ memcpy(Reply, formptr, varptr - formptr - 5); // omit "{var "
+ Reply += (varptr - formptr - 5);
+
+ strcpy(Reply, FormDir);
+ Reply += xmllen;
+ break;
+ }
+
if (_stricmp(var, KeyValue->Key) == 0)
{
xmllen = strlen(KeyValue->Value);
@@ -3579,6 +3711,8 @@ int DisplayWebForm(struct HTTPConnectionInfo * Session, struct MsgInfo * Msg, ch break;
}
+ KeyValue++;
+
if (KeyValue->Key == NULL)
{
// Not found in XML
@@ -3588,7 +3722,7 @@ int DisplayWebForm(struct HTTPConnectionInfo * Session, struct MsgInfo * Msg, ch sprintf(Err, VarNotFoundMsg, var, "%s");
return ReturnRawMessage(User, Msg, Key, SaveReply, RawMessage, (int)(XML - RawMessage), Err);
}
- KeyValue++;
+
}
formptr = endptr + 1;
@@ -5448,8 +5582,6 @@ char * CheckFile(struct HtmlFormDir * Dir, char * FN) #endif
- printf("%s\n", MsgFile);
-
if (stat(MsgFile, &STAT) != -1)
{
hFile = fopen(MsgFile, "rb");
@@ -5466,8 +5598,6 @@ char * CheckFile(struct HtmlFormDir * Dir, char * FN) MsgBytes[FileSize] = 0;
fclose(hFile);
- printf("%d %s\n", strlen(MsgBytes), MsgBytes);
-
return MsgBytes;
}
return NULL;
@@ -1580,8 +1580,6 @@ TNCRunning: // Send INIT script
- // VARA needs each command in a separate send
-
ptr1 = &TNC->InitScript[0];
GetSemaphore(&Semaphore, 52);
@@ -1606,7 +1604,6 @@ TNCRunning: c = *(ptr2 + 1); // Save next char
*(ptr2 + 1) = 0; // Terminate string
}
-// VARASendCommand(TNC, ptr1, TRUE);
if (ptr2)
*(1 + ptr2++) = c; // Put char back
@@ -290,6 +290,9 @@ typedef struct ConnectionInfo_S struct ConnectionInfo_S * SysopChatStream; // Stream sysop is chatting to
+ int bytesSent;
+ int bytesRxed;
+
} ConnectionInfo, CIRCUIT;
// Flags Equates
@@ -336,11 +339,13 @@ typedef struct ConnectionInfo_S struct FBBRestartData
{
- struct MsgInfo * TempMsg; // Header while message is being received
- struct UserInfo * UserPointer;
+ char Call[10];
+ char bid[13];
+ int length;
UCHAR * MailBuffer; // Mail Message being received
int MailBufferSize; // Total Malloc'ed size. Actual size in in Msg Struct
int Count; // Give up if too many restarts
+ time_t TimeCreated;
};
// We need to keep the B2Message file for B2 messages we are sending until the messages is acked, so
@@ -1387,6 +1392,7 @@ BOOL CheckBBSHElements(struct MsgInfo * Msg, struct UserInfo * bbs, struct BBSFo BOOL CheckBBSHElementsFlood(struct MsgInfo * Msg, struct UserInfo * bbs, struct BBSForwardingInfo * ForwardingInfo, char * ATBBS, char ** HElements);
int CheckBBSToForNTS(struct MsgInfo * Msg, struct BBSForwardingInfo * ForwardingInfo);
int CheckBBSATListWildCarded(struct MsgInfo * Msg, struct BBSForwardingInfo * ForwardingInfo, char * ATBBS);
+void SaveRestartData();
VOID ReRouteMessages();
diff --git a/templatedefs.c b/templatedefs.c index 47bdfc3..2fa2e13 100644 --- a/templatedefs.c +++ b/templatedefs.c @@ -520,7 +520,8 @@ char * MainConfigtxt() "<textarea cols=\"8\" rows=\"5\" name=\"Hat\">%s</textarea>\r\n"
"<textarea cols=\"8\" rows=\"5\" name=\"HBID\">%s</textarea>\r\n"
"<p></p>"
- " FBB reject.sys type filters (all fields must match, wildcards allowed)\r\n"
+ " FBB reject.sys type filters (all fields must match, wildcards allowed)<br>"
+ " 'A' action accepts message if all fields match without checking following lines\r\n"
"<p></p>"
"<div style='position: absolute; left: 20px;height: 120px; overflow:auto;'>%s</div>"
"<div style='position: absolute; top: 1120px;left: 300px; overflow:auto;'>"
|
