2001-08-17 05:46:24 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
2002-01-07 19:16:03 +00:00
|
|
|
* $Id$
|
2001-08-17 05:46:24 +00:00
|
|
|
* Purpose ...............: Fidonet mailer
|
|
|
|
*
|
|
|
|
*****************************************************************************
|
2005-08-28 11:34:24 +00:00
|
|
|
* Copyright (C) 1997-2005
|
2001-08-17 05:46:24 +00:00
|
|
|
*
|
|
|
|
* Michiel Broek FIDO: 2:280/2802
|
|
|
|
* Beekmansbos 10
|
|
|
|
* 1971 BV IJmuiden
|
|
|
|
* the Netherlands
|
|
|
|
*
|
|
|
|
* This file is part of MBSE BBS.
|
|
|
|
*
|
|
|
|
* This BBS 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 2, or (at your option) any
|
|
|
|
* later version.
|
|
|
|
*
|
|
|
|
* MBSE BBS 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 MBSE BBS; see the file COPYING. If not, write to the Free
|
2003-08-15 20:05:34 +00:00
|
|
|
* Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
2001-08-17 05:46:24 +00:00
|
|
|
*****************************************************************************/
|
|
|
|
|
2002-06-30 12:48:44 +00:00
|
|
|
#include "../config.h"
|
2004-02-21 17:22:00 +00:00
|
|
|
#include "../lib/mbselib.h"
|
2002-01-07 19:16:03 +00:00
|
|
|
#include "../lib/users.h"
|
2002-12-28 17:29:06 +00:00
|
|
|
#include "../lib/nodelist.h"
|
2004-02-21 17:22:00 +00:00
|
|
|
#include "../lib/mbsedb.h"
|
2001-08-17 05:46:24 +00:00
|
|
|
#include "ttyio.h"
|
|
|
|
#include "session.h"
|
|
|
|
#include "statetbl.h"
|
|
|
|
#include "config.h"
|
|
|
|
#include "emsi.h"
|
|
|
|
#include "emsidat.h"
|
|
|
|
#include "hydra.h"
|
|
|
|
#include "rdoptions.h"
|
|
|
|
#include "tcp.h"
|
|
|
|
#include "wazoo.h"
|
2003-08-23 14:57:51 +00:00
|
|
|
#include "inbound.h"
|
2005-09-10 20:20:51 +00:00
|
|
|
#include "callstat.h"
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
#define LOCAL_PROTOS (PROT_ZMO | PROT_ZAP | PROT_HYD | PROT_TCP)
|
|
|
|
|
|
|
|
static int rxemsi(void);
|
|
|
|
static int txemsi(void);
|
|
|
|
static char *intro;
|
|
|
|
static int caller;
|
|
|
|
|
2005-09-10 20:20:51 +00:00
|
|
|
extern int laststat;
|
2001-08-17 05:46:24 +00:00
|
|
|
extern int most_debug;
|
2002-11-11 14:52:13 +00:00
|
|
|
extern pid_t mypid;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
|
|
int emsi_local_lcodes;
|
|
|
|
int emsi_remote_lcodes;
|
|
|
|
int emsi_local_protos;
|
|
|
|
int emsi_remote_protos;
|
|
|
|
int emsi_local_opts;
|
|
|
|
int emsi_remote_opts;
|
|
|
|
char *emsi_local_password = NULL;
|
|
|
|
char *emsi_remote_password = NULL;
|
|
|
|
char emsi_remote_comm[4]="8N1";
|
2004-01-25 10:57:35 +00:00
|
|
|
int emsi_akas = 0;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
int rx_emsi(char *data)
|
|
|
|
{
|
2005-09-10 20:20:51 +00:00
|
|
|
int rc, protect = FALSE;
|
|
|
|
fa_list *tmr;
|
|
|
|
int denypw=0;
|
|
|
|
callstat *cst;
|
|
|
|
|
2002-10-21 18:29:29 +00:00
|
|
|
emsi_local_lcodes = LCODE_RH1;
|
|
|
|
emsi_remote_lcodes=0;
|
|
|
|
|
|
|
|
emsi_local_protos=LOCAL_PROTOS;
|
|
|
|
if (localoptions & NOZMODEM)
|
|
|
|
emsi_local_protos &= ~(PROT_ZMO | PROT_ZAP | PROT_DZA);
|
|
|
|
if (localoptions & NOZEDZAP)
|
|
|
|
emsi_local_protos &= ~PROT_ZAP;
|
|
|
|
if (localoptions & NOJANUS)
|
|
|
|
emsi_local_protos &= ~PROT_JAN;
|
|
|
|
if (localoptions & NOHYDRA)
|
|
|
|
emsi_local_protos &= ~PROT_HYD;
|
2002-12-30 22:13:33 +00:00
|
|
|
if ((session_flags & SESSION_TCP) == 0) {
|
2002-10-21 18:29:29 +00:00
|
|
|
emsi_local_protos &= ~PROT_TCP;
|
|
|
|
}
|
|
|
|
|
|
|
|
emsi_remote_protos=0;
|
|
|
|
emsi_local_opts = OPT_XMA;
|
|
|
|
emsi_remote_opts=0;
|
|
|
|
emsi_local_password = NULL;
|
|
|
|
emsi_remote_password = NULL;
|
|
|
|
intro=data+2;
|
|
|
|
caller=0;
|
|
|
|
|
|
|
|
if ((rc=rxemsi()))
|
|
|
|
return MBERR_EMSI;
|
|
|
|
|
|
|
|
Syslog('i', "local lcodes 0x%04x, protos 0x%04x, opts 0x%04x", emsi_local_lcodes,emsi_local_protos,emsi_local_opts);
|
|
|
|
Syslog('i', "remote lcodes 0x%04x, protos 0x%04x, opts 0x%04x", emsi_remote_lcodes,emsi_remote_protos,emsi_remote_opts);
|
|
|
|
|
|
|
|
if (emsi_remote_opts & OPT_EII) {
|
|
|
|
emsi_local_opts |= OPT_EII;
|
|
|
|
}
|
|
|
|
|
|
|
|
emsi_local_protos &= emsi_remote_protos;
|
|
|
|
if (emsi_local_protos & PROT_TCP)
|
|
|
|
emsi_local_protos &= PROT_TCP;
|
|
|
|
else if (emsi_local_protos & PROT_HYD)
|
|
|
|
emsi_local_protos &= PROT_HYD;
|
|
|
|
else if (emsi_local_protos & PROT_JAN)
|
|
|
|
emsi_local_protos &= PROT_JAN;
|
|
|
|
else if (emsi_local_protos & PROT_ZAP)
|
|
|
|
emsi_local_protos &= PROT_ZAP;
|
|
|
|
else if (emsi_local_protos & PROT_ZMO)
|
|
|
|
emsi_local_protos &= PROT_ZMO;
|
|
|
|
else if (emsi_local_protos & PROT_DZA)
|
|
|
|
emsi_local_protos &= PROT_DZA;
|
|
|
|
else if (emsi_local_protos & PROT_KER)
|
|
|
|
emsi_local_protos &= PROT_KER;
|
|
|
|
|
|
|
|
emsi_local_password = NULL;
|
|
|
|
|
2005-09-10 20:20:51 +00:00
|
|
|
for (tmr = remote; tmr; tmr = tmr->next) {
|
2002-10-21 18:29:29 +00:00
|
|
|
if (((nlent = getnlent(tmr->addr))) && (nlent->pflag != NL_DUMMY)) {
|
|
|
|
Syslog('+', "Remote is a listed system");
|
2002-11-11 14:52:13 +00:00
|
|
|
UserCity(mypid, nlent->sysop, nlent->location);
|
2002-10-21 18:29:29 +00:00
|
|
|
break;
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
2005-09-10 20:20:51 +00:00
|
|
|
cst = getstatus(tmr->addr);
|
|
|
|
if (cst->trystat)
|
|
|
|
laststat = cst->trystat;
|
|
|
|
}
|
|
|
|
Syslog('s', "Last connection status %d", laststat);
|
|
|
|
|
2002-10-21 18:29:29 +00:00
|
|
|
if (nlent)
|
|
|
|
rdoptions(TRUE);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Added these options, if they are in the setup for this
|
|
|
|
* calling node, then disable these options.
|
|
|
|
*/
|
|
|
|
if (localoptions & NOHYDRA)
|
|
|
|
emsi_local_opts &= ~PROT_HYD;
|
|
|
|
if (localoptions & NOZEDZAP)
|
|
|
|
emsi_local_opts &= ~PROT_ZAP;
|
|
|
|
if (localoptions & NOZMODEM)
|
|
|
|
emsi_local_opts &= ~(PROT_ZMO | PROT_ZAP | PROT_DZA);
|
|
|
|
|
|
|
|
if (localoptions & NOFREQS)
|
|
|
|
emsi_local_opts |= OPT_NRQ;
|
|
|
|
|
|
|
|
if (strlen(nodes.Spasswd)) {
|
|
|
|
if ((strncasecmp(emsi_remote_password, nodes.Spasswd, strlen(nodes.Spasswd)) == 0) &&
|
|
|
|
(strlen(emsi_remote_password) == strlen(nodes.Spasswd))) {
|
|
|
|
emsi_local_password = xstrcpy(nodes.Spasswd);
|
2003-08-23 14:57:51 +00:00
|
|
|
protect = TRUE;
|
2002-10-21 18:29:29 +00:00
|
|
|
Syslog('+', "Password correct, protected EMSI session");
|
2001-08-17 05:46:24 +00:00
|
|
|
} else {
|
2002-10-21 18:29:29 +00:00
|
|
|
denypw = 1;
|
|
|
|
Syslog('?', "Remote password \"%s\", expected \"%s\"", MBSE_SS(emsi_remote_password), nodes.Spasswd);
|
|
|
|
emsi_local_password = xstrcpy((char *)"BAD_PASS");
|
|
|
|
emsi_local_lcodes = LCODE_HAT;
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
2002-10-21 18:29:29 +00:00
|
|
|
} else {
|
|
|
|
Syslog('i', "No EMSI password check");
|
|
|
|
Syslog('?', "Unexpected remote password \"%s\"", MBSE_SS(emsi_local_password));
|
|
|
|
}
|
|
|
|
|
2003-08-23 14:57:51 +00:00
|
|
|
inbound_open(remote->addr, protect);
|
2002-10-21 18:29:29 +00:00
|
|
|
Syslog('i', "local lcodes 0x%04x, protos 0x%04x, opts 0x%04x", emsi_local_lcodes,emsi_local_protos,emsi_local_opts);
|
|
|
|
|
|
|
|
if ((rc=txemsi()))
|
|
|
|
return MBERR_EMSI;
|
|
|
|
|
|
|
|
if (denypw || (emsi_local_protos == 0)) {
|
|
|
|
Syslog('+', "Refusing remote: %s", emsi_local_protos?"bad password presented": "no common protocols");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
IsDoing("EMSI %s inb", ascfnode(remote->addr, 0x0f));
|
|
|
|
|
|
|
|
if ((emsi_remote_opts & OPT_NRQ) == 0)
|
|
|
|
session_flags |= SESSION_WAZOO;
|
|
|
|
else
|
|
|
|
session_flags &= ~SESSION_WAZOO;
|
|
|
|
|
|
|
|
if (emsi_local_protos & PROT_TCP)
|
|
|
|
return rxtcp();
|
|
|
|
else if (emsi_local_protos & PROT_HYD)
|
|
|
|
return hydra(0);
|
|
|
|
else
|
|
|
|
return rxwazoo();
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int tx_emsi(char *data)
|
|
|
|
{
|
2005-09-10 20:20:51 +00:00
|
|
|
int rc;
|
|
|
|
|
2002-10-21 18:29:29 +00:00
|
|
|
emsi_local_lcodes = LCODE_PUA | LCODE_RH1;
|
|
|
|
emsi_remote_lcodes = 0;
|
|
|
|
|
|
|
|
emsi_local_protos=LOCAL_PROTOS;
|
|
|
|
if (localoptions & NOZMODEM)
|
|
|
|
emsi_local_protos &= ~(PROT_ZMO | PROT_ZAP | PROT_DZA);
|
|
|
|
if (localoptions & NOZEDZAP)
|
|
|
|
emsi_local_protos &= ~PROT_ZAP;
|
|
|
|
if (localoptions & NOJANUS)
|
|
|
|
emsi_local_protos &= ~PROT_JAN;
|
|
|
|
if (localoptions & NOHYDRA)
|
|
|
|
emsi_local_protos &= ~PROT_HYD;
|
2002-12-30 22:13:33 +00:00
|
|
|
if ((session_flags & SESSION_TCP) == 0) {
|
2002-10-21 18:29:29 +00:00
|
|
|
emsi_local_protos &= ~PROT_TCP;
|
|
|
|
}
|
|
|
|
emsi_remote_protos=0;
|
|
|
|
emsi_local_opts=OPT_XMA | OPT_EII | OPT_NRQ;
|
|
|
|
emsi_remote_opts=0;
|
|
|
|
emsi_local_password=NULL;
|
|
|
|
emsi_remote_password=NULL;
|
|
|
|
intro=data+2;
|
|
|
|
caller=1;
|
|
|
|
emsi_local_password=NULL;
|
|
|
|
|
|
|
|
Syslog('i', "local lcodes 0x%04x, protos 0x%04x, opts 0x%04x", emsi_local_lcodes,emsi_local_protos,emsi_local_opts);
|
|
|
|
|
|
|
|
if ((rc=txemsi()))
|
|
|
|
return MBERR_EMSI;
|
|
|
|
else {
|
|
|
|
if ((rc=rxemsi()))
|
|
|
|
return MBERR_EMSI;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((emsi_remote_opts & OPT_EII) == 0) {
|
|
|
|
emsi_local_opts &= ~OPT_EII;
|
|
|
|
}
|
|
|
|
|
|
|
|
Syslog('i', "remote lcodes 0x%04x, protos 0x%04x, opts 0x%04x", emsi_remote_lcodes,emsi_remote_protos,emsi_remote_opts);
|
|
|
|
|
|
|
|
if ((emsi_remote_protos == 0) || (emsi_remote_lcodes & LCODE_HAT)) {
|
|
|
|
Syslog('+', "Remote refused us: %s", emsi_remote_protos?"traffic held":"no common protos");
|
|
|
|
return MBERR_SESSION_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
IsDoing("EMSI %s out", ascfnode(remote->addr, 0x0f));
|
|
|
|
|
|
|
|
emsi_local_protos &= emsi_remote_protos;
|
|
|
|
if ((emsi_remote_opts & OPT_NRQ) == 0)
|
|
|
|
session_flags |= SESSION_WAZOO;
|
|
|
|
else
|
|
|
|
session_flags &= ~SESSION_WAZOO;
|
|
|
|
|
|
|
|
if (emsi_local_protos & PROT_TCP)
|
|
|
|
return txtcp();
|
|
|
|
else if (emsi_local_protos & PROT_HYD)
|
|
|
|
return hydra(1);
|
|
|
|
// else if (emsi_local_protos & PROT_JAN)
|
|
|
|
// return janus();
|
|
|
|
else
|
|
|
|
return txwazoo();
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SM_DECL(rxemsi,(char *)"rxemsi")
|
|
|
|
SM_STATES
|
2003-08-23 21:15:16 +00:00
|
|
|
init,
|
|
|
|
waitpkt,
|
|
|
|
waitchar,
|
|
|
|
checkemsi,
|
|
|
|
getdat,
|
|
|
|
checkpkt,
|
|
|
|
checkdat,
|
|
|
|
sendnak,
|
|
|
|
sendack
|
2001-08-17 05:46:24 +00:00
|
|
|
SM_NAMES
|
2003-08-23 21:15:16 +00:00
|
|
|
(char *)"init",
|
|
|
|
(char *)"waitpkt",
|
|
|
|
(char *)"waitchar",
|
|
|
|
(char *)"checkemsi",
|
|
|
|
(char *)"getdat",
|
|
|
|
(char *)"checkpkt",
|
|
|
|
(char *)"checkdat",
|
|
|
|
(char *)"sendnak",
|
|
|
|
(char *)"sendack"
|
2001-08-17 05:46:24 +00:00
|
|
|
SM_EDECL
|
|
|
|
|
2003-08-23 21:15:16 +00:00
|
|
|
int c = 0;
|
|
|
|
unsigned short lcrc, rcrc;
|
|
|
|
int len;
|
|
|
|
int standby = 0, tries = 0;
|
|
|
|
char buf[13], *p;
|
|
|
|
char *databuf = NULL;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-08-23 21:15:16 +00:00
|
|
|
p = buf;
|
|
|
|
databuf = xstrcpy(intro);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-08-23 21:15:16 +00:00
|
|
|
SM_START(init)
|
|
|
|
|
|
|
|
SM_STATE(init)
|
|
|
|
|
2003-09-17 19:33:34 +00:00
|
|
|
gpt_resettimers();
|
|
|
|
gpt_settimer(0, 60);
|
|
|
|
gpt_settimer(1, 20);
|
2003-08-23 21:15:16 +00:00
|
|
|
SM_PROCEED(checkpkt);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
|
|
SM_STATE(waitpkt)
|
|
|
|
|
2003-08-23 21:15:16 +00:00
|
|
|
standby = 0;
|
2003-09-17 19:33:34 +00:00
|
|
|
gpt_settimer(1, 20);
|
2003-08-23 21:15:16 +00:00
|
|
|
SM_PROCEED(waitchar);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
|
|
SM_STATE(waitchar)
|
|
|
|
|
2003-08-23 21:15:16 +00:00
|
|
|
Syslog('i', "RXEMSI: waitchar, tries=%d", tries);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-09-17 19:33:34 +00:00
|
|
|
if (gpt_expired(0)) {
|
2003-08-23 21:15:16 +00:00
|
|
|
Syslog('+', "EMSI receive 60 seconds timeout");
|
|
|
|
SM_ERROR;
|
|
|
|
}
|
|
|
|
|
2003-09-17 19:33:34 +00:00
|
|
|
if (gpt_expired(1)) {
|
2003-08-23 21:15:16 +00:00
|
|
|
Syslog('s', "20 sec timeout");
|
|
|
|
SM_PROCEED(sendnak);
|
|
|
|
}
|
|
|
|
|
|
|
|
c = GETCHAR(1);
|
|
|
|
if (c == TIMEOUT) {
|
2001-08-17 05:46:24 +00:00
|
|
|
SM_PROCEED(waitchar);
|
2003-08-23 21:15:16 +00:00
|
|
|
} else if (c < 0) {
|
|
|
|
SM_ERROR;
|
|
|
|
} else if ((c >= ' ') && (c <= '~')) {
|
|
|
|
if (c == '*') {
|
|
|
|
standby = 1;
|
|
|
|
p = buf;
|
|
|
|
*p = '\0';
|
|
|
|
} else if (standby) {
|
|
|
|
if ((p - buf) < (sizeof(buf) - 1)) {
|
|
|
|
*p++ = c;
|
|
|
|
*p = '\0';
|
|
|
|
} if ((p - buf) >= (sizeof(buf) - 1)) {
|
|
|
|
standby = 0;
|
|
|
|
SM_PROCEED(checkemsi);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch(c) {
|
|
|
|
case DC1: break;
|
|
|
|
case '\n':
|
|
|
|
case '\r': standby = 0;
|
|
|
|
break;
|
|
|
|
default: standby = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SM_PROCEED(waitchar);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
|
|
SM_STATE(checkemsi)
|
|
|
|
|
2003-08-23 21:15:16 +00:00
|
|
|
Syslog('i', "RXEMSI: rcvd %s", printable(buf, 0));
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-08-23 21:15:16 +00:00
|
|
|
if (strncasecmp(buf, "EMSI_DAT",8) == 0) {
|
|
|
|
SM_PROCEED(getdat);
|
|
|
|
} else if (strncasecmp(buf, "EMSI_",5) == 0) {
|
|
|
|
if (databuf)
|
|
|
|
free(databuf);
|
|
|
|
databuf = xstrcpy(buf);
|
|
|
|
SM_PROCEED(checkpkt);
|
|
|
|
} else {
|
|
|
|
SM_PROCEED(waitpkt);
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
|
|
SM_STATE(getdat)
|
|
|
|
|
2003-08-23 21:15:16 +00:00
|
|
|
if (sscanf(buf+8,"%04x",&len) != 1) {
|
|
|
|
SM_PROCEED(sendnak);
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-08-23 21:15:16 +00:00
|
|
|
len += 16; /* strlen("EMSI_DATxxxxyyyy"), include CRC */
|
|
|
|
if (databuf)
|
|
|
|
free(databuf);
|
|
|
|
databuf = malloc(len + 1);
|
|
|
|
strcpy(databuf, buf);
|
|
|
|
p = databuf + strlen(databuf);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-08-23 21:15:16 +00:00
|
|
|
while (((p-databuf) < len) && ((c=GETCHAR(8)) >= 0)) {
|
|
|
|
*p++ = c;
|
|
|
|
*p = '\0';
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-08-23 21:15:16 +00:00
|
|
|
Syslog('i', "RXEMSI: rcvd %s (%d bytes)", databuf, len);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-08-23 21:15:16 +00:00
|
|
|
if (c == TIMEOUT) {
|
|
|
|
SM_PROCEED(sendnak);
|
|
|
|
} else if (c < 0) {
|
|
|
|
Syslog('+', "Error while reading EMSI_DAT packet");
|
|
|
|
SM_ERROR;
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-08-23 21:15:16 +00:00
|
|
|
SM_PROCEED(checkdat);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
|
|
SM_STATE(checkpkt)
|
|
|
|
|
2003-08-23 21:15:16 +00:00
|
|
|
if (strncasecmp(databuf,"EMSI_DAT",8) == 0) {
|
|
|
|
SM_PROCEED(checkdat);
|
|
|
|
}
|
|
|
|
|
|
|
|
lcrc = crc16xmodem(databuf, 8);
|
|
|
|
sscanf(databuf + 8, "%04hx", &rcrc);
|
|
|
|
if (lcrc != rcrc) {
|
|
|
|
Syslog('+', "Got EMSI packet \"%s\" with bad crc: %04x/%04x", printable(databuf, 0), lcrc, rcrc);
|
|
|
|
SM_PROCEED(sendnak);
|
|
|
|
} if (strncasecmp(databuf, "EMSI_HBT", 8) == 0) {
|
|
|
|
tries = 0;
|
|
|
|
SM_PROCEED(waitpkt);
|
|
|
|
} else if (strncasecmp(databuf, "EMSI_INQ", 8) == 0) {
|
|
|
|
SM_PROCEED(sendnak);
|
|
|
|
} else {
|
|
|
|
SM_PROCEED(waitpkt);
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
|
|
SM_STATE(checkdat)
|
|
|
|
|
2003-08-23 21:15:16 +00:00
|
|
|
sscanf(databuf + 8, "%04x", &len);
|
|
|
|
if (len != (strlen(databuf) - 16)) {
|
|
|
|
Syslog('+', "Bad EMSI_DAT length: %d/%d", len, strlen(databuf));
|
|
|
|
SM_PROCEED(sendnak);
|
|
|
|
}
|
|
|
|
/* Some FD versions send length of the packet including the
|
|
|
|
trailing CR. Arrrgh! Dirty overwork follows: */
|
|
|
|
if (*(p = databuf + strlen(databuf) - 1) == '\r')
|
|
|
|
*p='\0';
|
|
|
|
sscanf(databuf + strlen(databuf) - 4, "%04hx", &rcrc);
|
|
|
|
*(databuf + strlen(databuf) - 4) = '\0';
|
|
|
|
lcrc = crc16xmodem(databuf, strlen(databuf));
|
|
|
|
if (lcrc != rcrc) {
|
|
|
|
Syslog('+', "Got EMSI_DAT packet \"%s\" with bad crc: %04x/%04x", printable(databuf, 0), lcrc, rcrc);
|
|
|
|
SM_PROCEED(sendnak);
|
|
|
|
} if (scanemsidat(databuf + 12) == 0) {
|
2004-01-25 10:57:35 +00:00
|
|
|
if (emsi_akas == 0) {
|
|
|
|
Syslog('+', "All akas busy, abort");
|
|
|
|
SM_ERROR;
|
|
|
|
}
|
2003-08-23 21:15:16 +00:00
|
|
|
SM_PROCEED(sendack);
|
|
|
|
} else {
|
|
|
|
Syslog('+', "Could not parse EMSI_DAT packet \"%s\"",databuf);
|
|
|
|
SM_ERROR;
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
|
|
SM_STATE(sendnak)
|
|
|
|
|
2003-08-23 21:15:16 +00:00
|
|
|
/*
|
|
|
|
* The FSC-0059 says 6 attempts, but to accept maindoor sessions
|
|
|
|
* we seem to need about 11, we set it to 20 since we also have
|
|
|
|
* a global 60 seconds timer running.
|
|
|
|
*/
|
|
|
|
if (++tries > 19) {
|
|
|
|
Syslog('+', "Too many tries getting EMSI_DAT");
|
|
|
|
SM_ERROR;
|
|
|
|
} if (caller) {
|
|
|
|
PUTSTR((char *)"**EMSI_NAKEEC3\r\021");
|
|
|
|
Syslog('i', "RXEMSI: send **EMSI_NAKEEC3");
|
|
|
|
} else {
|
|
|
|
PUTSTR((char *)"**EMSI_REQA77E\r\021");
|
|
|
|
Syslog('i', "RXEMSI: send **EMSI_REQA77E");
|
|
|
|
if (tries > 1) {
|
|
|
|
PUTSTR((char *)"**EMSI_NAKEEC3\r\021");
|
|
|
|
Syslog('i', "RXEMSI: send **EMSI_NAKEEC3");
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
2003-08-23 21:15:16 +00:00
|
|
|
}
|
|
|
|
SM_PROCEED(waitpkt);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
|
|
SM_STATE(sendack)
|
|
|
|
|
2003-08-23 21:15:16 +00:00
|
|
|
PUTSTR((char *)"**EMSI_ACKA490\r\021");
|
|
|
|
PUTSTR((char *)"**EMSI_ACKA490\r\021");
|
|
|
|
SM_SUCCESS;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
|
|
SM_END
|
2004-01-28 21:10:56 +00:00
|
|
|
|
2003-08-23 21:15:16 +00:00
|
|
|
free(databuf);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
|
|
SM_RETURN
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SM_DECL(txemsi,(char *)"txemsi")
|
|
|
|
SM_STATES
|
2003-08-23 21:15:16 +00:00
|
|
|
senddata,
|
|
|
|
waitpkt,
|
|
|
|
waitchar,
|
|
|
|
checkpkt,
|
|
|
|
sendack
|
2001-08-17 05:46:24 +00:00
|
|
|
SM_NAMES
|
2003-08-23 21:15:16 +00:00
|
|
|
(char *)"senddata",
|
|
|
|
(char *)"waitpkt",
|
|
|
|
(char *)"waitchar",
|
|
|
|
(char *)"checkpkt",
|
|
|
|
(char *)"sendack"
|
2001-08-17 05:46:24 +00:00
|
|
|
SM_EDECL
|
|
|
|
|
2003-08-23 21:15:16 +00:00
|
|
|
int c;
|
|
|
|
unsigned short lcrc, rcrc;
|
|
|
|
int standby = 0, tries = 0;
|
|
|
|
char buf[13], *p;
|
|
|
|
char trailer[8];
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-08-23 21:15:16 +00:00
|
|
|
p = buf;
|
|
|
|
memset(&buf, 0, sizeof(buf));
|
|
|
|
strncpy(buf, intro, sizeof(buf) - 1);
|
2003-09-17 19:33:34 +00:00
|
|
|
gpt_resettimers();
|
|
|
|
gpt_settimer(0, 60);
|
2003-08-23 21:15:16 +00:00
|
|
|
Syslog('i', "TXEMSI: 60 seconds timer set");
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
|
|
SM_START(senddata)
|
|
|
|
|
|
|
|
SM_STATE(senddata)
|
|
|
|
|
2003-08-23 21:15:16 +00:00
|
|
|
p = mkemsidat(caller);
|
|
|
|
PUTCHAR('*');
|
|
|
|
PUTCHAR('*');
|
|
|
|
PUTSTR(p);
|
2005-08-28 13:45:26 +00:00
|
|
|
snprintf(trailer, 8, "%04X\r\021", crc16xmodem(p, strlen(p)));
|
2003-08-23 21:15:16 +00:00
|
|
|
PUTSTR(trailer);
|
|
|
|
Syslog('i', "TXEMSI: send **%s%04X", p, crc16xmodem(p, strlen(p)));
|
|
|
|
free(p);
|
2003-09-17 19:33:34 +00:00
|
|
|
gpt_settimer(1, 20);
|
2003-08-23 21:15:16 +00:00
|
|
|
SM_PROCEED(waitpkt);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
|
|
SM_STATE(waitpkt)
|
|
|
|
|
2003-08-23 21:15:16 +00:00
|
|
|
standby = 0;
|
|
|
|
SM_PROCEED(waitchar);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
|
|
SM_STATE(waitchar)
|
|
|
|
|
2003-09-17 19:33:34 +00:00
|
|
|
if (gpt_expired(0)) {
|
2003-08-23 21:15:16 +00:00
|
|
|
Syslog('+', "EMSI transmit 60 seconds timeout");
|
|
|
|
SM_ERROR;
|
|
|
|
}
|
|
|
|
|
2003-09-17 19:33:34 +00:00
|
|
|
if (gpt_expired(1)) {
|
2003-08-23 21:15:16 +00:00
|
|
|
Syslog('i', "TXEMSI: 20 seconds timeout");
|
|
|
|
if (++tries > 19) {
|
|
|
|
Syslog('+', "too many tries sending EMSI");
|
|
|
|
SM_ERROR;
|
|
|
|
} else {
|
|
|
|
SM_PROCEED(senddata);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
c = GETCHAR(1);
|
|
|
|
if (c == TIMEOUT) {
|
|
|
|
SM_PROCEED(waitchar);
|
|
|
|
} else if (c < 0) {
|
|
|
|
SM_ERROR;
|
|
|
|
} else if ((c >= ' ') && (c <= '~')) {
|
|
|
|
if (c == '*') {
|
|
|
|
standby = 1;
|
|
|
|
p = buf;
|
|
|
|
*p = '\0';
|
|
|
|
} else if (standby) {
|
|
|
|
if ((p - buf) < (sizeof(buf) - 1)) {
|
|
|
|
*p++ = c;
|
|
|
|
*p = '\0';
|
|
|
|
} if ((p - buf) >= (sizeof(buf) - 1)) {
|
|
|
|
standby = 0;
|
|
|
|
SM_PROCEED(checkpkt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
switch(c) {
|
|
|
|
case DC1: SM_PROCEED(waitchar);
|
2001-08-17 05:46:24 +00:00
|
|
|
break;
|
2003-08-23 21:15:16 +00:00
|
|
|
case '\n':
|
|
|
|
case '\r': standby = 0;
|
2001-08-17 05:46:24 +00:00
|
|
|
break;
|
2003-08-23 21:15:16 +00:00
|
|
|
default: standby = 0;
|
2001-08-17 05:46:24 +00:00
|
|
|
break;
|
2003-08-23 21:15:16 +00:00
|
|
|
}
|
|
|
|
SM_PROCEED(waitchar);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
|
|
SM_STATE(checkpkt)
|
|
|
|
|
2003-08-23 21:15:16 +00:00
|
|
|
Syslog('i', "TXEMSI: rcvd %s", buf);
|
|
|
|
if (strncasecmp(buf, "EMSI_DAT", 8) == 0) {
|
|
|
|
SM_PROCEED(sendack);
|
|
|
|
} else if (strncasecmp(buf, "EMSI_", 5) == 0) {
|
|
|
|
lcrc = crc16xmodem(buf, 8);
|
|
|
|
sscanf(buf + 8, "%04hx", &rcrc);
|
|
|
|
if (lcrc != rcrc) {
|
|
|
|
Syslog('+', "Got EMSI packet \"%s\" with bad crc: %04x/%04x", printable(buf, 0), lcrc, rcrc);
|
|
|
|
SM_PROCEED(senddata);
|
|
|
|
} if (strncasecmp(buf, "EMSI_REQ", 8) == 0) {
|
|
|
|
SM_PROCEED(waitpkt);
|
|
|
|
} if (strncasecmp(buf, "EMSI_ACK", 8) == 0) {
|
|
|
|
SM_SUCCESS;
|
2001-08-17 05:46:24 +00:00
|
|
|
} else {
|
2003-08-23 21:15:16 +00:00
|
|
|
SM_PROCEED(senddata);
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
2003-08-23 21:15:16 +00:00
|
|
|
} else {
|
|
|
|
SM_PROCEED(waitpkt);
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
|
|
SM_STATE(sendack)
|
|
|
|
|
2003-08-23 21:15:16 +00:00
|
|
|
PUTSTR((char *)"**EMSI_ACKA490\r\021");
|
|
|
|
PUTSTR((char *)"**EMSI_ACKA490\r\021");
|
|
|
|
SM_PROCEED(waitpkt);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
|
|
SM_END
|
|
|
|
|
|
|
|
SM_RETURN
|
|
|
|
|
|
|
|
|