From pa.dec.com!decwrl!uunet!sparky!kent Sun Aug 11 15:47:02 PDT 1991
Article: 2588 of comp.sources.misc
Newsgroups: comp.sources.misc
Path: pa.dec.com!decwrl!uunet!sparky!kent
From: Warren Tucker <wht@n4hgf.Mt-Park.GA.US>
Subject:  v21i078:  ecu - ECU async comm package rev 3.10, Part26/37
Message-ID: <1991Aug4.163111.18850@sparky.IMD.Sterling.COM>
X-Md4-Signature: 936736270a5105ebe85f603c705130d3
Sender: kent@sparky.IMD.Sterling.COM (Kent Landfield)
Organization: Sterling Software, IMD
References: <csm-v21i053=ecu.215539@sparky.imd.sterling.com>
Date: Sun, 4 Aug 1991 16:31:11 GMT
Approved: kent@sparky.imd.sterling.com
Lines: 1765

Submitted-by: Warren Tucker <wht@n4hgf.Mt-Park.GA.US>
Posting-number: Volume 21, Issue 78
Archive-name: ecu/part26
Environment: SCO, XENIX, ISC
Supersedes: ecu3: Volume 16, Issue 25-59

---- Cut Here and feed the following to sh ----
#!/bin/sh
# this is ecu310.26 (part 26 of ecu310)
# do not concatenate these parts, unpack them in order with /bin/sh
# file gendial/dceMPAD.c continued
#
if touch 2>&1 | fgrep 'amc' > /dev/null
 then TOUCH=touch
 else TOUCH=true
fi
if test ! -r _shar_seq_.tmp; then
	echo 'Please unpack part 1 first!'
	exit 1
fi
(read Scheck
 if test "$Scheck" != 26; then
	echo Please unpack part "$Scheck" next!
	exit 1
 else
	exit 0
 fi
) < _shar_seq_.tmp || exit 1
if test ! -f _shar_wnt_.tmp; then
	echo 'x - still skipping gendial/dceMPAD.c'
else
echo 'x - continuing file gendial/dceMPAD.c'
sed 's/^X//' << 'SHAR_EOF' >> 'gendial/dceMPAD.c' &&
X
XUpon unsuccessful connection, return RC_FAIL or'd with an appropriate
XRCE_XXX value from dialer.h.
X
Xlwrite() is used to write to the DCE.
X
Xlread() and lread_ignore() are used to read from the DCE.  Read timeouts
Xfrom calling lread() will result automatically in the proper error
Xtermination of the program.  Read timeouts from calling lread_ignore()
Xreturn -1; you handle the execption here.
X
XAny necessary coding of phone numbers, switch settings or other
Xconfiguration necessary for this function to succeed should be
Xdocumented at the top of the module.
X
XMPAD Plus-specific comments:
X Q0          do not be quiet
X E0          do not echo
X V1          verbal result codes
X S0=0        dont allow connect while dialing
X X99         full result codes
X--------------------------------------------------------------------------*/
Xint
XDCE_dial(telno)
Xchar *telno;
X{
Xchar cmd[128];
Xchar phone[50];
Xint timeout;
Xint result;
Xchar *cptr;
Xchar *dialout_default = "ATQ0E0V1E0S0=0X99\r";
X#define MDVALID	 "0123456789NnSs()-"
X
X/* preliminary setup */
X	translate("=,-,",telno);
X	if(strspn(telno,MDVALID) != strlen(telno))
X	{
X		DEBUG(1,"phone number has invalid characters\n",0);
X		return(RC_FAIL | RCE_PHNO);
X	}
X	if(decode_phone_number(telno,phone,sizeof(phone)))
X	{
X		DEBUG(1,"phone number too long\n",0);
X		return(RC_FAIL | RCE_PHNO);
X	}
X
X/* walk through dialer codes, doing custom setup */
X	strcpy(cmd,"AT");
X	cptr = cmd + strlen(cmd);
X
X	DEBUG(6,"--> issuing default setup command\n",0);
X	sync_MPAD();
X	lwrite(dialout_default);
X	if(lread(2) != rOk)
X	{
X		DEBUG(1,"default dialout setup failed\n",0);
X		return(RC_FAIL | RCE_NULL);
X	}
X
X/* issue the custom setup command */
X	if(*cptr)
X	{
X		DEBUG(5,"--> issuing custom setup cmd\n",0);
X		strcat(cmd,"\r");
X		sync_MPAD();
X		lwrite(cmd);
X		if(lread(2) != rOk)
X		{
X			DEBUG(1,"custom modem setup failed\n",0);
X			return(RC_FAIL | RCE_NULL);
X		}
X	}
X
X/*
X * calculate a timeout for the connect
X */
X	timeout = 20;
X	DEBUG(6,"timeout waiting for connect = %d seconds\n",timeout);
X
X/* indicate non-root should not see DTE->DCE traffic */
X	secure = 1;
X
X/*
X * build and issue the actual dialing command
X * if root, let him see number, otherwise just say "remote system"
X */
X	DEBUG(1,"--> dialing %s\n", (!ecu_calling & uid) ? "remote system" : phone);
X	sprintf(cmd,"ATS7=%dDT%s\r",(timeout * 9) / 10,phone);
X
X	/* cmd string can only be 40 characters including "AT" */
X	if(strlen(cmd) > 40)
X	{
X		DEBUG(1,"phone number string too long\n",0);
X		cleanup(RC_FAIL | RCE_PHNO);
X	}
X
X	sync_MPAD();
X	lwrite(cmd);
X
X/* indicate non-root can see DTE->DCE traffic */
X	secure = 0;
X
X/* wait for connect */
X	result = lread(timeout);
X	if(!(result & rfConnect))
X	{
X		switch(result & rfMASK)
X		{
X		case rNoCarrier:
X			return(RC_FAIL | RCE_NOCARR);
X		case rNoDialTone:
X			return(RC_FAIL | RCE_NOTONE);
X		case rBusy:
X			return(RC_FAIL | RCE_BUSY);
X		case rNoAnswer:
X			return(RC_FAIL | RCE_ANSWER);
X		case rError:
X		default:
X			return(RC_FAIL | RCE_NULL);
X		}
X	}
X
X	return(0);		/* succeeded */
X
X}	/* end of DCE_dial */
X
X/**********************************************************
X*  You probably do not need to modify the code below here *
X**********************************************************/
X
X/*+-------------------------------------------------------------------------
X	DCE_abort(sig) - dial attempt aborted
X
X sig =  0 if non-signal abort (read timeout, most likely)
X     != 0 if non-SIGALRM signal caught
X
X extern int dialing set  1 if dialing request was active,
X                    else 0 if hangup request was active
X
XThis is a chance for the DCE-specific code to do anything it
Xneeds to cl,ean up after a failure.  Note that if a dialing
Xcall fails, it is the responsibility of the higher-level
Xprogram calling the dialer to call it again with a hangup request, so
Xthis function is usually a no-op.
X--------------------------------------------------------------------------*/
Xvoid
XDCE_abort(sig)
Xint sig;
X{
X	DEBUG(10,"DCE_abort(%d);\n",sig);
X}	/* end of DCE_abort */
X
X/*+-------------------------------------------------------------------------
X	DCE_exit(exitcode) - "last chance for gas" in this incarnation
X
XThe independent portion of the dialer program calls this routine in
Xlieu of exit() in every case except one (see DCE_argv_hook() below).
XNormally, this function just passes it's argument to exit(), but
Xany necessary post-processing can be done.  The function must,
Xhowever, eventually call exit(exitcode);
X--------------------------------------------------------------------------*/
Xvoid
XDCE_exit(exitcode)
Xint exitcode;
X{
X	DEBUG(10,"DCE_exit(%d);\n",exitcode);
X	exit(exitcode);
X}	/* end of DCE_exit */
X
X/*+-------------------------------------------------------------------------
X	DCE_argv_hook(argc,argv,optind,unrecognized_switches)
X
XThis hook gives DCE-specific code a chance to look over the entire
Xcommand line, such as for -z processing.
X
Xargc andf argv are the same values passed to main(),
X
Xoptind is the value of optind at the end of normal getopt processing.
X
Xunrecognized_switches is the count of switches not handled by main().
XSpecifically, -h and -x are standard switches.
X
XNormally, this function should just return RC_FAIL|RCE_ARGS if there are
Xany unrecognized switches, otherwise zero.  If you keep your nose clean
Xthough, you can do anything you need to do here and exit the program.
X
XNote: only simple switches (with no argument) may be used with this
Xfacility if the functrion is to return,' since main()'s getopt() will
Xstop processing switches if it runs into an unrecognized switch with an
Xargument.
X
XIf the function returns a non-zero value, then the value will be passed
XDIRECTLY to exit() with no further ado.  Thus, a non-zero value must be
Xof the format expected by dialer program callers, with RC_FAIL set as a
Xminimum.
X--------------------------------------------------------------------------*/
Xint
XDCE_argv_hook(argc,argv,optind,unrecognized_switches)
Xint argc;
Xchar **argv;
Xint optind;
Xint unrecognized_switches;
X{
X	if(unrecognized_switches)
X		return(RC_FAIL | RCE_ARGS);
X	return(0);
X}	/* end of DCE_argv_hook */
X
X/* vi: set tabstop=4 shiftwidth=4: */
SHAR_EOF
echo 'File gendial/dceMPAD.c is complete' &&
$TOUCH -am 0725125891 'gendial/dceMPAD.c' &&
chmod 0644 gendial/dceMPAD.c ||
echo 'restore of gendial/dceMPAD.c failed'
Wc_c="`wc -c < 'gendial/dceMPAD.c'`"
test 14132 -eq "$Wc_c" ||
	echo 'gendial/dceMPAD.c: original size 14132, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= gendial/dceT1000.c ==============
if test -f 'gendial/dceT1000.c' -a X"$1" != X"-c"; then
	echo 'x - skipping gendial/dceT1000.c (File already exists)'
	rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting gendial/dceT1000.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'gendial/dceT1000.c' &&
X/* CHK=0xFF53 */
X/*+-------------------------------------------------------------------------
X	dceTBPlus.c - DCE-specific portion of generic SCO UUCP dialer
X	Driver for Telebit Trailblazer Plus
X	wht@n4hgf.Mt-Park.GA.US
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:07-25-1991-12:58-wht@n4hgf-ECU release 3.10 */
X/*:03-12-1991-19:11-wht@n4hgf-if ecu dialing, show complete call progress */
X/*:11-29-1990-18:31-r@n4hgf-revision/1st releasable */
X/*:07-20-1990-00:10-wht@n4hgf-creation */
X
X#include "dialer.h"
X
X/*
X * DCE_DTR_low_msec - milliseconds to hold DTR low to ensure DCE
X *                    sees the transition; this value may be changed
X *                    as necessary before each call to ltoggleDTR(),
X * but, generally, a constant value will do.
X */
Xlong DCE_DTR_low_msec = 500;
X
X/*
X * DCE_DTR_high_msec - milliseconds DTR must remain high before the
X *                     DCE may be expected to be ready to be commanded
X */
Xlong DCE_DTR_high_msec = 500;
X
X/*
X * DCE_write_pase_msec - milliseconds to pause between each character
X *                       sent to the DCE (zero if streaming I/O is
X *                       permitted); this value may be changed as
X * necessary before each call to lwrite(), but, generally, a constant
X * value will do.  Note that this value is used to feed a value to nap(),
X * which has a granularity of .010 seconds on UNIX/386, .020 on XENIX/286
X * and .050 seconds on XENIX/86.
X */
Xlong DCE_write_pace_msec = 0;
X
X/*
X * DCE_name     - short name for DCE
X * DCE_revision - revision number for this module
X */
Xchar *DCE_name = "Telebit T1000";
Xchar *DCE_revision = "1.10";
X
X/*
X * DCE_hangup_CBAUD - baud rate to use for hanging up DCE
X *                    and readying it for dial in access
X *                    (BXXX mask); use a value of zero if the speed
X *                    specified by the invoker is to be used.
X * This value is useful for DCEs such as the early Hayes 2400
X * which are so unfortunately compatible with their 1200 predecessor
X * that they refuse to answer at 2400 baud unless you last spoke to
X * them at that rate. For such bad boys, use B2400 below.
X */
Xint DCE_hangup_CBAUD = 0;
X/* int DCE_hangup_CBAUD = B2400; */
X
X/*
X * DCE_results - a table of DCE response strings and a token
X *               code for each; when you call lread() or lread_ignore(),
X *               if the read routine detects one of the strings,
X * the appropriate code is returned.  If no string matches, then
X * lread()/lread_ignore examines the DCE result string for a
X * numeric value; if one is found, the numeric value or'd with
X * 0x40000000 is returned (in this way, e.g., you can read "modem
X * S registers").  If nothing agrees with this search, lread()
X * will abort the program with RC|FAIL|RCE_TIMOUT, lread_ignore()
X * will return -1.  You may use any value between 0 and 0x3FFFFFFF.
X * This module is the only consumer  of the codes, although they
X * are decoded by gendial.c's _lread()
X */
X
X/* flag bits */
X#define rfConnect		0x00800000
X#define rfREL			0x00400000
X#define rfFAST			0x00200000
X#define rfMASK			0x0000FFFF	/* mask off rfBits */
X
X/* unique codes */
X#define rOk				0
X#define rNoCarrier		1
X#define rError			2
X#define rNoDialTone 	3
X#define rBusy			4
X#define rNoAnswer		5
X#define rRring			6
X#define rConnect300		(  300  | rfConnect)
X#define rConnect1200	( 1200  | rfConnect)
X#define rConnect2400	( 2400  | rfConnect)
X#define rConnect300R	(  300  | rfConnect | rfREL)
X#define rConnect1200R	( 1200  | rfConnect | rfREL)
X#define rConnect2400R	( 2400  | rfConnect | rfREL)
X#define rConnectFASTK	(19200  | rfConnect | rfFAST)	/* may be 9600 */
X#define rConnectFASTX	(19200  | rfConnect | rfFAST)
X#define rConnectFASTU	(19200  | rfConnect | rfFAST)
X#define rConnectFAST	(19200  | rfConnect | rfFAST)
X
XDCE_RESULT DCE_results[] =
X{
X	{ "OK",						rOk,			},
X	{ "NO CARRIER",				rNoCarrier,		},
X	{ "ERROR",					rError			},
X	{ "NO DIALTONE",			rNoDialTone,	},
X	{ "BUSY",					rBusy			},
X	{ "NO ANSWER",				rNoAnswer		},
X	{ "RRING",					rRring			},
X	{ "CONNECT 300/REL",		rConnect300R	},
X	{ "CONNECT 1200/REL",		rConnect1200R	},
X	{ "CONNECT 2400/REL",		rConnect2400R	},
X	{ "CONNECT 300",			rConnect300		},
X	{ "CONNECT 1200",			rConnect1200	},
X	{ "CONNECT 2400",			rConnect2400	},
X	{ "CONNECT FAST/KERM",		rConnectFASTK	},
X	{ "CONNECT FAST/XMDM",		rConnectFASTX	},
X	{ "CONNECT FAST/UUCP",		rConnectFASTU	},
X	{ "CONNECT FAST",			rConnectFAST	},
X	{ (char *)0,				-1				}		/* end table */
X};
X
X/*+-------------------------------------------------------------------------
X	DCE_baud_to_CBAUD(baud) - check for valid baud rates supported by DCE
X
X  DCE dependent function must validate baud rates supported by DCE
X  returns baud rate in struct termio c_cflag fashion
X  or terminates program with error
X--------------------------------------------------------------------------*/
Xint
XDCE_baud_to_CBAUD(baud)
Xunsigned int baud;
X{
X	switch(baud)
X	{
X		case 110:  return(B110);
X		case 300:  return(B300);
X		case 1200: return(B1200);
X		case 2400: return(B2400);
X		case 9600: return(B9600);
X
X#if defined(B19200)
X		case 19200: return(B19200);
X#else
X#ifdef EXTA
X		case 19200: return(EXTA);
X#endif
X#endif
X
X#if defined(B38400)
X		case 38400: return(B38400);
X#else
X#ifdef EXTB
X		case 38400: return(EXTB);
X#endif
X#endif
X
X	}
X	myexit(RC_FAIL | RCE_SPEED);
X}	/* end of DCE_baud_to_CBAUD */
X
X/*+-------------------------------------------------------------------------
X	sync_Telebit() - sync modem with our DTE speed
X--------------------------------------------------------------------------*/
Xvoid
Xsync_Telebit()
X{
Xregister int maxretry = 8;
Xregister int count;
Xunsigned char rdchar;
X
X	while(maxretry--)
X	{
X		lflush();
X		write(fddce,"a",1);
X		count = 5;
X		while(count)	/* wait 50-200 msec for character, depending on HZ */
X		{
X			if(rdchk(fddce))
X				break;
X			nap(50L);
X			count--;
X		}
X		if(count && (read(fddce,&rdchar,1) == 1) && (rdchar == 'a'))
X			return;
X	}
X
X	DEBUG(1,"Telebit SYNC FAILED\n",0);
X	myexit(RC_FAIL | RCE_TIMOUT);
X
X}	/* end of sync_Telebit */
X
X/*+-------------------------------------------------------------------------
X	init_TBPlus() - init TBPlus from scratch, assuming nothing
X
X	reset to factory defaults, then set
X    E0          no local echo in command mode
X    F1          no local echo in data transfer mode
X    M0          speaker off
X    Q4          generate reult codes, but not RING
X    V1          verbal result codes
X    X3          extended result codes
X    S0=1        answer on first ring
X    S2=1        escape to "unusual" value
X    S11=50      50 msec DTMF timing
X    S45=1       enable remote access
X    S48=1       all 8 bits are significant
X    S50=0       use automatic connect speed determination
X    S51=255     default to 9600 and typeahead
X    S52=2       go on hook when dtr drops and reset to NV-RAM
X    S53=1       DCD signal follows remote carrier, DSR on when modem ready
X    S54=3       pass BREAK signal to remote modem
X    S55=0       respond to command escape sequence
X    S58=2       DTE uses CTS/RTS flow control.
X    S64=1       ignore characters sent by DTE while answering
X    S66=0       don't lock interface speed, just go with the flow.
X    S68=255     DCE uses whatever flow control DTE uses
X    S92=1       PEP tones at the end of answer sequence
X    S95=0       no MNP
X    S110=255    use data compression when the remote modem requests it.
X    S111=255    accept any protocol
X--------------------------------------------------------------------------*/
Xvoid
Xinit_TBPlus()
X{
Xregister itmp;
Xint maxretry = 4;
Xchar *init0 = "AT&FE0F1M0Q4V1X3\r";
Xchar *init1 = "ATS0=1S2=1S11=50S45=1S48=1S50=0S51=255S52=2S53=1S54=3\r";
Xchar *init2 = "ATS55=0S58=2S64=1S66=0S68=255S92=1S95=0S110=255S111=255\r";
X
X	DEBUG(7,"--> reseting %s\n",dce_name);
X
X	ltoggleDTR(0L);
X	sync_Telebit();
X
X	/*
X	 * set to factory default (bless them for this command)
X	 * and a few initial beachhead values
X	 */
X	for(itmp = 0; itmp < maxretry; itmp++)
X	{
X		lwrite(init0);
X		if(lread(2) == rOk)
X			break;
X	}
X	if(itmp == maxretry)
X	{
X		DEBUG(1,"reset failed (0)\n",0);
X		myexit(RC_FAIL | RCE_TIMOUT);
X	}
X
X	/*
X	 * send initialization string 1
X	 */
X	for(itmp = 0; itmp < maxretry; itmp++)
X	{
X		lwrite(init1);
X		if(lread(2) == rOk)
X			break;
X	}
X	if(itmp == maxretry)
X	{
X		DEBUG(1,"INIT FAILED (1)\n",0);
X		myexit(RC_FAIL | RCE_TIMOUT);
X	}
X
X	/*
X	 * send initialization string 2
X	 */
X	for(itmp = 0; itmp < maxretry; itmp++)
X	{
X		lwrite(init2);
X		if(lread(2) == rOk)
X			break;
X	}
X	if(itmp == maxretry)
X	{
X		DEBUG(1,"reset failed (2)\n",0);
X		myexit(RC_FAIL | RCE_TIMOUT);
X	}
X
X}	/* end of init_TBPlus */
X
X/*+-------------------------------------------------------------------------
X	DCE_hangup() - issue hangup command to DCE
X
XThis function should do whatever is necessary to ensure
X1) any active connection is terminated
X2) the DCE is ready to receive an incoming call if DTR is asserted
X3) the DCE will not accept an incoming call if DTR is false
X
XThe function should return when done.
X
XAny necessary switch setting or other configuration necessary for this
Xfunction to succeed should be documented at the top of the module.
X--------------------------------------------------------------------------*/
Xvoid
XDCE_hangup()
X{
X	DEBUG(7,"reseting %s\n",dce_name);
X	ltoggleDTR(0L);
X	init_TBPlus();
X
X}	/* end of DCE_hangup */
X
X/*+-------------------------------------------------------------------------
X	DCE_dial(telno) - dial a remote DCE
X
XThis function should connect to the remote DCE and use any success
Xindication to modify the tty baud rate if necessary before returning.
X
XUpon successful connection, return 0.
X
XUpon unsuccessful connection, return RC_FAIL or'd with an appropriate
XRCE_XXX value from dialer.h.
X
Xlwrite() is used to write to the DCE.
X
Xlread() and lread_ignore() are used to read from the DCE.  Read timeouts
Xfrom calling lread() will result automatically in the proper error
Xtermination of the program.  Read timeouts from calling lread_ignore()
Xreturn -1; you handle the execption here.
X
XAny necessary coding of phone numbers, switch settings or other
Xconfiguration necessary for this function to succeed should be
Xdocumented at the top of the module.
X
XTelebit Plus-specific comments:
X S0=0        dont allow connect while dialing
X S54=3       pass BREAK signal to remote modem
X S64=0       abort dialing if characters sent by DTE
X S66=1       lock the interface speed
X S110=0      disable data compression unless requested otherwise
X--------------------------------------------------------------------------*/
Xint
XDCE_dial(telno)
Xchar *telno;
X{
Xchar cmd[128];
Xchar phone[50];
Xint s111_set = 0;
Xint timeout;
Xint result;
Xint rrings = 0;
Xlong then;
Xlong now;
Xchar *cptr;
Xchar *dialout_default = "ATS0=0S7=40S54=3S64=0S66=1S110=0\r";
X#define MDVALID	 "0123456789CcEeFfKkMmNnPpRrSsUuWwXx*#,!/()-"
X
X/* preliminary setup */
X	translate("=,-,",telno);
X	if(strspn(telno,MDVALID) != strlen(telno))
X	{
X		DEBUG(1,"phone number has invalid characters\n",0);
X		return(RC_FAIL | RCE_PHNO);
X	}
X	if(decode_phone_number(telno,phone,sizeof(phone)))
X	{
X		DEBUG(1,"phone number too long\n",0);
X		return(RC_FAIL | RCE_PHNO);
X	}
X
X/* walk through dialer codes, doing custom setup */
X	strcpy(cmd,"AT");
X	cptr = cmd + strlen(cmd);
X	if(dialer_codes['C' - 'A'])
X	{
X		DEBUG(5,"COMPRESSION requested\n",0);
X		strcat(cmd,"S110=1");
X	}
X	if(dialer_codes['E' - 'A'])
X	{
X		DEBUG(5,"ECHO SUPPRESSION requested\n",0);
X		strcat(cmd,"S121=1");
X	}
X	if(dialer_codes['F' - 'A'])
X	{
X		DEBUG(5,"XON/XOFF FLOW CONTROL requested\n",0);
X		strcat(cmd,"S58=3");
X	}
X	if(dialer_codes['K' - 'A'])
X	{
X		DEBUG(5,"KERMIT requested\n",0);
X		strcat(cmd,"S111=10");
X		s111_set++;
X	}
X	if(dialer_codes['X' - 'A'])
X	{
X		DEBUG(5,"XMODEM requested\n",0);
X		strcat(cmd,"S111=20");
X		s111_set++;
X	}
X	if(dialer_codes['U' - 'A'])
X	{
X		DEBUG(5,"UUCP requested\n",0);
X		strcat(cmd,"S111=30");
X		s111_set++;
X	}
X	if(dialer_codes['M' - 'A'])
X	{
X		DEBUG(5,"MNP requested\n",0);
X		strcat(cmd,"S95=1");
X	}
X
X	if((dialer_codes['P' - 'A']) || s111_set || (hiCBAUD >= B9600))
X	{
X		if(hiCBAUD < B9600)
X		{
X			DEBUG(1,"baud rate not high enough for PEP\n",0);
X			return(RC_FAIL | RCE_SPEED);
X		}
X		if(dialer_codes['P' - 'A'])
X			DEBUG(5,"PEP requested\n",0);
X		else
X			DEBUG(5,"PEP inferred: speed >= 9600\n",0);
X
X		dialer_codes['P' - 'A'] = 1;
X		strcat(cmd,"S50=255");
X	}
X
X
X	DEBUG(6,"--> issuing default setup command\n",0);
X	sync_Telebit();
X	lwrite(dialout_default);
X	if(lread(2) != rOk)
X	{
X		DEBUG(1,"default dialout setup failed\n",0);
X		return(RC_FAIL | RCE_NULL);
X	}
X
X/* issue the custom setup command */
X	if(*cptr)
X	{
X		DEBUG(5,"--> issuing custom setup cmd\n",0);
X		strcat(cmd,"\r");
X		sync_Telebit();
X		lwrite(cmd);
X		if(lread(2) != rOk)
X		{
X			DEBUG(1,"custom modem setup failed\n",0);
X			return(RC_FAIL | RCE_NULL);
X		}
X	}
X
X/*
X * calculate a timeout for the connect
X * allow a minimum of 40 seconds, but if PEP, 90
X * also if long distance (North American calculation here)
X * make it 132 (S7 is calculated as timeout * .9)
X */
X	timeout = 40;
X	if((phone[0] == '1') && (phone[0] != '0'))
X		timeout = 132;
X	if((timeout < 90) && dialer_codes['P' - 'A'])
X		timeout = 90;
X	for(cptr = phone; cptr = strchr(cptr,','); cptr++)
X		timeout += 2;	/* add extra time for pause characters */
X	DEBUG(6,"timeout waiting for connect = %d seconds\n",timeout);
X
X/* indicate non-root should not see DTE->DCE traffic */
X	secure = 1;
X
X/*
X * build and issue the actual dialing command
X * if root, let him see number, otherwise just say "remote system"
X */
X	DEBUG(1,"--> dialing %s\n", (!ecu_calling & uid) ? "remote system" : phone);
X#ifdef WHT
X	if(!strncmp(*gargv,"ECU",3))
X		dialer_codes['S' - 'A'] = 1;
X#endif
X	sprintf(cmd,"ATM%dS7=%dDT%s\r",
X		((dialer_codes['S' - 'A']) && !(dialer_codes['N' - 'A'])) ? 1 : 0,
X		(timeout * 9) / 10,phone);
X
X	/* cmd string can only be 80 characters including "AT" */
X	if(strlen(cmd) > 80)
X	{
X		DEBUG(1,"phone number string too long\n",0);
X		cleanup(RC_FAIL | RCE_PHNO);
X	}
X
X	sync_Telebit();
X	lwrite(cmd);
X
X/* indicate non-root can see DTE->DCE traffic */
X	secure = 0;
X
X/* wait for connect */
XWAIT_FOR_CONNECT:
X	time(&then);
X	result = lread(timeout);
X	if(!(result & rfConnect))
X	{
X		switch(result & rfMASK)
X		{
X		case rNoCarrier:
X			return(RC_FAIL | ((rrings > 2) ? RCE_ANSWER : RCE_NOTONE));
X		case rNoDialTone:
X			return(RC_FAIL | RCE_NOTONE);
X		case rBusy:
X			return(RC_FAIL | RCE_BUSY);
X		case rNoAnswer:
X			return(RC_FAIL | RCE_ANSWER);
X		case rRring:
X			if(rrings++ > 7)
X				return(RC_FAIL | RCE_ANSWER);
X			time(&now);
X			if((timeout -= ((int)(then - now))) > 0)
X				goto WAIT_FOR_CONNECT;
X		case rError:
X		default:
X			return(RC_FAIL | RCE_NULL);
X		}
X	}
X
X	return(0);		/* succeeded */
X
X}	/* end of DCE_dial */
X
X/**********************************************************
X*  You probably do not need to modify the code below here *
X**********************************************************/
X
X/*+-------------------------------------------------------------------------
X	DCE_abort(sig) - dial attempt aborted
X
X sig =  0 if non-signal abort (read timeout, most likely)
X     != 0 if non-SIGALRM signal caught
X
X extern int dialing set  1 if dialing request was active,
X                    else 0 if hangup request was active
X
XThis is a chance for the DCE-specific code to do anything it
Xneeds to cl,ean up after a failure.  Note that if a dialing
Xcall fails, it is the responsibility of the higher-level
Xprogram calling the dialer to call it again with a hangup request, so
Xthis function is usually a no-op.
X--------------------------------------------------------------------------*/
Xvoid
XDCE_abort(sig)
Xint sig;
X{
X	DEBUG(10,"DCE_abort(%d);\n",sig);
X}	/* end of DCE_abort */
X
X/*+-------------------------------------------------------------------------
X	DCE_exit(exitcode) - "last chance for gas" in this incarnation
X
XThe independent portion of the dialer program calls this routine in
Xlieu of exit() in every case except one (see DCE_argv_hook() below).
XNormally, this function just passes it's argument to exit(), but
Xany necessary post-processing can be done.  The function must,
Xhowever, eventually call exit(exitcode);
X--------------------------------------------------------------------------*/
Xvoid
XDCE_exit(exitcode)
Xint exitcode;
X{
X	DEBUG(10,"DCE_exit(%d);\n",exitcode);
X	exit(exitcode);
X}	/* end of DCE_exit */
X
X/*+-------------------------------------------------------------------------
X	DCE_argv_hook(argc,argv,optind,unrecognized_switches)
X
XThis hook gives DCE-specific code a chance to look over the entire
Xcommand line, such as for -z Telebit processing.
X
Xargc andf argv are the same values passed to main(),
X
Xoptind is the value of optind at the end of normal getopt processing.
X
Xunrecognized_switches is the count of switches not handled by main().
XSpecifically, -h and -x are standard switches.
X
XNormally, this function should just return RC_FAIL|RCE_ARGS if there are
Xany unrecognized switches, otherwise zero.  If you keep your nose clean
Xthough, you can do anything you need to do here and exit the program.
X
XNote: only simple switches (with no argument) may be used with this
Xfacility if the functrion is to return,' since main()'s getopt() will
Xstop processing switches if it runs into an unrecognized switch with an
Xargument.
X
XIf the function returns a non-zero value, then the value will be passed
XDIRECTLY to exit() with no further ado.  Thus, a non-zero value must be
Xof the format expected by dialer program callers, with RC_FAIL set as a
Xminimum.
X--------------------------------------------------------------------------*/
Xint
XDCE_argv_hook(argc,argv,optind,unrecognized_switches)
Xint argc;
Xchar **argv;
Xint optind;
Xint unrecognized_switches;
X{
X	if(unrecognized_switches)
X		return(RC_FAIL | RCE_ARGS);
X	return(0);
X}	/* end of DCE_argv_hook */
X
X/* vi: set tabstop=4 shiftwidth=4: */
SHAR_EOF
$TOUCH -am 0725125891 'gendial/dceT1000.c' &&
chmod 0644 gendial/dceT1000.c ||
echo 'restore of gendial/dceT1000.c failed'
Wc_c="`wc -c < 'gendial/dceT1000.c'`"
test 17777 -eq "$Wc_c" ||
	echo 'gendial/dceT1000.c: original size 17777, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= gendial/dceT2500.c ==============
if test -f 'gendial/dceT2500.c' -a X"$1" != X"-c"; then
	echo 'x - skipping gendial/dceT2500.c (File already exists)'
	rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting gendial/dceT2500.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'gendial/dceT2500.c' &&
X/* #define TRUSTING		/* trust user has -z'd before use */
X/*+-------------------------------------------------------------------------
X	dceT2500.c - DCE-specific portion of generic SCO UUCP dialer
X	Driver for Telebit T2500
X	wht@n4hgf.Mt-Park.GA.US
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:07-25-1991-12:58-wht@n4hgf-ECU release 3.10 */
X/*:03-12-1991-19:11-wht@n4hgf-if ecu dialing, show complete call progress */
X/*:11-29-1990-18:31-r@n4hgf-revision/1st releasable */
X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
X
X#include "dialer.h"
X
X/*
X * DCE_DTR_low_msec - milliseconds to hold DTR low to ensure DCE
X *                    sees the transition; this value may be changed
X *                    as necessary before each call to ltoggleDTR(),
X * but, generally, a constant value will do.
X */
Xlong DCE_DTR_low_msec = 500;
X
X/*
X * DCE_DTR_high_msec - milliseconds DTR must remain high before the
X *                     DCE may be expected to be ready to be commanded
X */
Xlong DCE_DTR_high_msec = 500;
X
X/*
X * DCE_write_pase_msec - milliseconds to pause between each character
X *                       sent to the DCE (zero if streaming I/O is
X *                       permitted); this value may be changed as
X * necessary before each call to lwrite(), but, generally, a constant
X * value will do.  Note that this value is used to feed a value to nap(),
X * which has a granularity of .010 seconds on UNIX/386, .020 on XENIX/286
X * and .050 seconds on XENIX/86.
X */
Xlong DCE_write_pace_msec = 0;
X
X/*
X * DCE_name     - short name for DCE
X * DCE_revision - revision number for this module
X */
Xchar *DCE_name = "Telebit T2500";
Xchar *DCE_revision = "1.10";
X
X/*
X * DCE_hangup_CBAUD - baud rate to use for hanging up DCE
X *                    and readying it for dial in access
X *                    (BXXX mask); use a value of zero if the speed
X *                    specified by the invoker is to be used.
X * This value is useful for DCEs such as the early Hayes 2400
X * which are so unfortunately compatible with their 1200 predecessor
X * that they refuse to answer at 2400 baud unless you last spoke to
X * them at that rate. For such bad boys, use B2400 below.
X */
Xint DCE_hangup_CBAUD = 0;
X/* int DCE_hangup_CBAUD = B2400; */
X
X/*
X * DCE_results - a table of DCE response strings and a token
X *               code for each; when you call lread() or lread_ignore(),
X *               if the read routine detects one of the strings,
X * the appropriate code is returned.  If no string matches, then
X * lread()/lread_ignore examines the DCE result string for a
X * numeric value; if one is found, the numeric value or'd with
X * 0x40000000 is returned (in this way, e.g., you can read "modem
X * S registers").  If nothing agrees with this search, lread()
X * will abort the program with RC|FAIL|RCE_TIMOUT, lread_ignore()
X * will return -1.  You may use any value between 0 and 0x3FFFFFFF.
X * This module is the only consumer  of the codes, although they
X * are decoded by gendial.c's _lread()
X */
X
X/* flag bits */
X#define rfConnect		0x00800000
X#define rfREL			0x00400000
X#define rfFAST			0x00200000
X#define rfV32			0x00100000
X#define rfMASK			0x0000FFFF	/* mask off rfBits */
X
X/* unique codes */
X#define rOk				0
X#define rNoCarrier		1
X#define rError			2
X#define rNoDialTone 	3
X#define rBusy			4
X#define rNoAnswer		5
X#define rRring			6
X#define rConnect300		(  300  | rfConnect)
X#define rConnect1200	( 1200  | rfConnect)
X#define rConnect2400	( 1200  | rfConnect)
X#define rConnect300R	(  300  | rfConnect | rfREL)
X#define rConnect1200R	( 1200  | rfConnect | rfREL)
X#define rConnect2400R	( 2400  | rfConnect | rfREL)
X#define rConnectFASTK	(19200  | rfConnect | rfFAST)	/* may be 9600 */
X#define rConnectFASTX	(19200  | rfConnect | rfFAST)
X#define rConnectFASTU	(19200  | rfConnect | rfFAST)
X#define rConnectFAST	(19200  | rfConnect | rfFAST)
X#define rConnect9600	( 9600  | rfConnect | rfV32)
X
XDCE_RESULT DCE_results[] =
X{
X	{ "OK",						rOk,			},
X	{ "NO CARRIER",				rNoCarrier,		},
X	{ "ERROR",					rError			},
X	{ "NO DIALTONE",			rNoDialTone,	},
X	{ "BUSY",					rBusy			},
X	{ "NO ANSWER",				rNoAnswer		},
X	{ "RRING",					rRring			},
X	{ "CONNECT 300/REL",		rConnect300R	},
X	{ "CONNECT 1200/REL",		rConnect1200R	},
X	{ "CONNECT 2400/REL",		rConnect2400R	},
X	{ "CONNECT 300",			rConnect300		},
X	{ "CONNECT 1200",			rConnect1200	},
X	{ "CONNECT 2400",			rConnect2400	},
X	{ "CONNECT FAST/KERM",		rConnectFASTK	},
X	{ "CONNECT FAST/XMDM",		rConnectFASTX	},
X	{ "CONNECT FAST/UUCP",		rConnectFASTU	},
X	{ "CONNECT FAST",			rConnectFAST	},
X	{ "CONNECT 9600",			rConnect9600	},
X	{ (char *)0,				-1				}		/* end table */
X};
X
X/*+-------------------------------------------------------------------------
X	DCE_baud_to_CBAUD(baud) - check for valid baud rates supported by DCE
X
X  DCE dependent function must validate baud rates supported by DCE
X  returns baud rate in struct termio c_cflag fashion
X  or terminates program with error
X--------------------------------------------------------------------------*/
Xint
XDCE_baud_to_CBAUD(baud)
Xunsigned int baud;
X{
X	switch(baud)
X	{
X		case 110:  return(B110);
X		case 300:  return(B300);
X		case 1200: return(B1200);
X		case 2400: return(B2400);
X		case 9600: return(B9600);
X
X#if defined(B19200)
X		case 19200: return(B19200);
X#else
X#ifdef EXTA
X		case 19200: return(EXTA);
X#endif
X#endif
X
X#if defined(B38400)
X		case 38400: return(B38400);
X#else
X#ifdef EXTB
X		case 38400: return(EXTB);
X#endif
X#endif
X
X	}
X	myexit(RC_FAIL | RCE_SPEED);
X#if defined(__GNUC__) && defined(__OPTIMIZE)	/* don't complain */
X	return(0);
X#endif
X}	/* end of DCE_baud_to_CBAUD */
X
X/*+-------------------------------------------------------------------------
X	sync_Telebit() - sync modem with our DTE speed
X--------------------------------------------------------------------------*/
Xvoid
Xsync_Telebit()
X{
Xregister int maxretry = 8;
Xregister int count;
Xunsigned char rdchar;
X
X	while(maxretry--)
X	{
X		lflush();
X		write(fddce,"a",1);
X		count = 5;
X		while(count)	/* wait 50-200 msec for character, depending on HZ */
X		{
X			if(rdchk(fddce))
X				break;
X			nap(20L);
X			count--;
X		}
X		if(count && (read(fddce,&rdchar,1) == 1) && (rdchar == 'a'))
X			return;
X	}
X
X	DEBUG(1,"Telebit SYNC FAILED\n",0);
X	myexit(RC_FAIL | RCE_TIMOUT);
X
X}	/* end of sync_Telebit */
X
X/*+-------------------------------------------------------------------------
X	init_T2500() - init T2500 from scratch, assuming nothing
X
X	reset to factory defaults, then set
X    E0          no local echo in command mode
X    F1          no local echo in data transfer mode
X    M0          speaker off
X    Q4          generate reult codes, but not RING
X    V1          verbal result codes
X    X3          extended result codes
X    S0=1        answer on first ring
X    S2=1        escape to unusual value
X    S11=50      50 msec DTMF timing
X    S45=1       enable remote access
X    S48=1       all 8 bits are significant
X    S50=0       use automatic connect speed determination
X    S51=252     set serial port baud rate automatically (no typeahead)
X    S52=2       go on hook when dtr drops and reset to NV-RAM
X    S53=1       DCD signal follows remote carrier, DSR on when modem ready
X    S54=3       pass BREAK signal to remote modem
X    S55=0       respond to command escape sequence
X    S58=2       DTE uses CTS/RTS flow control.
X    S64=1       ignore characters sent by DTE while answering
X    S66=0       don't lock interface speed, just go with the flow.
X    S68=255     DCE uses whatever flow control DTE uses
X    S92=1       PEP tones at the end of answer sequence
X    S95=0       no MNP
X    S110=255    use data compression when the remote modem requests it.
X    S111=255    accept any protocol
X	write to nonvolatile RAM
X--------------------------------------------------------------------------*/
Xvoid
Xinit_T2500()
X{
Xregister itmp;
Xint maxretry = 4;
Xchar *init0 = "AT&FE0F1M0Q4V1X3\r";
Xchar *init1 = "ATS0=1S2=1S11=50S45=1S48=1S50=0S51=252S52=2S53=1S54=3\r";
Xchar *init2 = "ATS55=0S58=2S64=1S66=0S68=255S92=1S95=0S110=255S111=255&W\r";
X
X	DEBUG(7,"INITIALIZING %s\n",dce_name);
X
X	ltoggleDTR(0L);
X	sync_Telebit();
X
X	/*
X	 * set to factory default (bless them for this command)
X	 * and a few initial beachhead values
X	 */
X	for(itmp = 0; itmp < maxretry; itmp++)
X	{
X		lwrite(init0);
X		if(lread(2) == rOk)
X			break;
X	}
X	if(itmp == maxretry)
X	{
X		DEBUG(1,"INIT FAILED (init0)\n",0);
X		myexit(RC_FAIL | RCE_TIMOUT);
X	}
X
X	/*
X	 * send initialization string 1
X	 */
X	for(itmp = 0; itmp < maxretry; itmp++)
X	{
X		lwrite(init1);
X		if(lread(2) == rOk)
X			break;
X	}
X	if(itmp == maxretry)
X	{
X		DEBUG(1,"INIT FAILED (init1)\n",0);
X		myexit(RC_FAIL | RCE_TIMOUT);
X	}
X
X	/*
X	 * send initialization string 2
X	 */
X	for(itmp = 0; itmp < maxretry; itmp++)
X	{
X		lwrite(init2);
X		if(lread(2) == rOk)
X			break;
X	}
X	if(itmp == maxretry)
X	{
X		DEBUG(1,"INIT FAILED (init2)\n",0);
X		myexit(RC_FAIL | RCE_TIMOUT);
X	}
X
X}	/* end of init_T2500 */
X
X/*+-------------------------------------------------------------------------
X	DCE_hangup() - issue hangup command to DCE
X
XThis function should do whatever is necessary to ensure
X1) any active connection is terminated
X2) the DCE is ready to receive an incoming call if DTR is asserted
X3) the DCE will not accept an incoming call if DTR is false
X
XThe function should return when done.
X
XAny necessary switch setting or other configuration necessary for this
Xfunction to succeed should be documented at the top of the module.
X--------------------------------------------------------------------------*/
Xvoid
XDCE_hangup()
X{
X#ifdef TRUSTING
X	DEBUG(7,"--> reseting %s\n",dce_name);
X	ltoggleDTR(0L);
X	lwrite("ATZ\r");
X	(void)lread_ignore(1);
X#else /* !TRUSTING */
X	init_T2500();
X#endif
X
X}	/* end of DCE_hangup */
X
X/*+-------------------------------------------------------------------------
X	DCE_dial(telno) - dial a remote DCE
X
XThis function should connect to the remote DCE and use any success
Xindication to modify the tty baud rate if necessary before returning.
X
XUpon successful connection, return 0.
X
XUpon unsuccessful connection, return RC_FAIL or'd with an appropriate
XRCE_XXX value from dialer.h.
X
Xlwrite() is used to write to the DCE.
X
Xlread() and lread_ignore() are used to read from the DCE.  Read timeouts
Xfrom calling lread() will result automatically in the proper error
Xtermination of the program.  Read timeouts from calling lread_ignore()
Xreturn -1; you handle the execption here.
X
XAny necessary coding of phone numbers, switch settings or other
Xconfiguration necessary for this function to succeed should be
Xdocumented at the top of the module.
X
XT2500-specific comments:
X S0=0        dont allow connect while dialing
X S54=3       pass BREAK signal to remote modem
X S64=0       abort dialing if characters sent by DTE
X S66=1       lock the interface speed
X S110=0      disable data compression unless requested otherwise
X--------------------------------------------------------------------------*/
Xint
XDCE_dial(telno)
Xchar *telno;
X{
Xchar cmd[128];
Xchar phone[50];
Xint s111_set = 0;
Xint timeout;
Xint result;
Xint rrings = 0;
Xlong then;
Xlong now;
Xchar *cptr;
Xchar *dialout_default = "ATS0=0S7=40S54=3S64=0S66=1S110=0\r";
X#define MDVALID	 "0123456789CcEeFfKkMmNnPpRrSsUuWwXxVv*#,!/()-"
X#ifdef WHT
X#define RRING_MAX 3
X#else
X#define RRING_MAX 6
X#endif
X
X/* preliminary setup */
X	translate("=,-,",telno);
X	if(strspn(telno,MDVALID) != strlen(telno))
X	{
X		DEBUG(1,"phone number has invalid characters\n",0);
X		return(RC_FAIL | RCE_PHNO);
X	}
X	if(decode_phone_number(telno,phone,sizeof(phone)))
X	{
X		DEBUG(1,"phone number too long\n",0);
X		return(RC_FAIL | RCE_PHNO);
X	}
X
X/* walk through dialer codes, doing custom setup */
X	strcpy(cmd,"AT");
X	cptr = cmd + strlen(cmd);
X	if(dialer_codes['C' - 'A'])
X	{
X		DEBUG(5,"COMPRESSION requested\n",0);
X		strcat(cmd,"S110=1");
X	}
X	if(dialer_codes['E' - 'A'])
X	{
X		DEBUG(5,"ECHO SUPPRESSION requested\n",0);
X		strcat(cmd,"S121=1");
X	}
X	if(dialer_codes['F' - 'A'])
X	{
X		DEBUG(5,"XON/XOFF FLOW CONTROL requested\n",0);
X		strcat(cmd,"S58=3");
X	}
X	if(dialer_codes['K' - 'A'])
X	{
X		DEBUG(5,"KERMIT requested\n",0);
X		strcat(cmd,"S111=10");
X		s111_set++;
X	}
X	if(dialer_codes['X' - 'A'])
X	{
X		DEBUG(5,"XMODEM requested\n",0);
X		strcat(cmd,"S111=20");
X		s111_set++;
X	}
X	if(dialer_codes['U' - 'A'])
X	{
X		DEBUG(5,"UUCP requested\n",0);
X		strcat(cmd,"S111=30");
X		s111_set++;
X	}
X	if(dialer_codes['M' - 'A'])
X	{
X		DEBUG(5,"MNP requested\n",0);
X		strcat(cmd,"S95=1");
X	}
X
X	if(dialer_codes['V' - 'A'])
X	{
X		DEBUG(5,"V.32 requested\n",0);
X		if(hiCBAUD != B9600)
X		{
X			DEBUG(1,"V.32 baud rate not 9600\n",0);
X			return(RC_FAIL | RCE_SPEED);
X		}
X		if((dialer_codes['P' - 'A']) || s111_set)
X		{
X			DEBUG(1,"both PEP and V.32 requested\n",0);
X			return(RC_FAIL | RCE_ARGS);
X		}
X		strcat(cmd,"S50=6");
X	}
X
X	if((dialer_codes['P' - 'A']) || s111_set ||
X		((hiCBAUD >= B9600) && (!dialer_codes['V' - 'A'])))
X	{
X		if(hiCBAUD < B9600)
X		{
X			DEBUG(1,"baud rate not high enough for PEP\n",0);
X			return(RC_FAIL | RCE_SPEED);
X		}
X		if(dialer_codes['P' - 'A'])
X			DEBUG(5,"PEP requested\n",0);
X		else
X			DEBUG(5,"PEP inferred: speed >= 9600 and no V.32 requested\n",0);
X
X		dialer_codes['P' - 'A'] = 1;
X		strcat(cmd,"S50=255");
X	}
X
X#ifndef TRUSTING
X	init_T2500();
X#endif
X
X	DEBUG(6,"--> issuing default setup command\n",0);
X	sync_Telebit();
X	lwrite(dialout_default);
X	if(lread(2) != rOk)
X	{
X		DEBUG(1,"default dialout setup failed\n",0);
X		return(RC_FAIL | RCE_NULL);
X	}
X
X/* issue the custom setup command */
X	if(*cptr)
X	{
X		DEBUG(5,"--> issuing custom setup cmd\n",0);
X		strcat(cmd,"\r");
X		sync_Telebit();
X		lwrite(cmd);
X		if(lread(2) != rOk)
X		{
X			DEBUG(1,"custom modem setup failed\n",0);
X			return(RC_FAIL | RCE_NULL);
X		}
X	}
X
X/*
X * calculate a timeout for the connect
X * allow a minimum of 40 seconds, but if V.32 or PEP, 90
X * also if long distance (North American calculation here)
X * make it 132 (S7 is calculated as timeout * .9)
X */
X	timeout = 40;
X	if((phone[0] == '1') && (phone[0] != '0'))
X		timeout = 132;
X	if((timeout < 90) && (dialer_codes['V' - 'A'] || dialer_codes['P' - 'A']))
X		timeout = 90;
X	for(cptr = phone; cptr = strchr(cptr,','); cptr++)
X		timeout += 2;	/* add extra time for pause characters */
X	DEBUG(6,"timeout waiting for connect = %d seconds\n",timeout);
X
X/* indicate non-root should not see DTE->DCE traffic */
X	secure = 1;
X
X/*
X * build and issue the actual dialing command
X * if root, let him see number, otherwise just say "remote system"
X */
X	DEBUG(1,"--> dialing %s\n", (!ecu_calling & uid) ? "remote system" : telno);
X#ifdef WHT
X	if(!strncmp(*gargv,"ECU",3))
X		dialer_codes['S' - 'A'] = 1;
X#endif
X	sprintf(cmd,"ATM%dS7=%dDT%s\r",
X		((dialer_codes['S' - 'A']) && !(dialer_codes['N' - 'A'])) ? 1 : 0,
X		(timeout * 9) / 10,
X		phone);
X
X	/* cmd string can only be 80 characters including "AT" */
X	if(strlen(cmd) > 80)
X	{
X		DEBUG(1,"phone number string too long\n",0);
X		cleanup(RC_FAIL | RCE_PHNO);
X	}
X
X	sync_Telebit();
X	lwrite(cmd);
X
X/* indicate non-root can see DTE->DCE traffic */
X	secure = 0;
X
X/* wait for connect */
XWAIT_FOR_CONNECT:
X	time(&then);
X	result = lread(timeout);
X	if(!(result & rfConnect))
X	{
X		switch(result & rfMASK)
X		{
X		case rNoCarrier:
X			return(RC_FAIL | ((rrings > 2) ? RCE_ANSWER : RCE_NOTONE));
X		case rNoDialTone:
X			return(RC_FAIL | RCE_NOTONE);
X		case rBusy:
X			return(RC_FAIL | RCE_BUSY);
X		case rNoAnswer:
X			return(RC_FAIL | RCE_ANSWER);
X		case rRring:
X			if(rrings++ >= RRING_MAX)
X				return(RC_FAIL | RCE_ANSWER);
X			time(&now);
X			if((timeout -= ((int)(then - now))) > 0)
X				goto WAIT_FOR_CONNECT;
X		case rError:
X		default:
X			return(RC_FAIL | RCE_NULL);
X		}
X	}
X
X	return(0);		/* succeeded */
X
X}	/* end of DCE_dial */
X
X/**********************************************************
X*  You probably do not need to modify the code below here *
X**********************************************************/
X
X/*+-------------------------------------------------------------------------
X	DCE_abort(sig) - dial attempt aborted
X
X sig =  0 if non-signal abort (read timeout, most likely)
X     != 0 if non-SIGALRM signal caught
X
X extern int dialing set  1 if dialing request was active,
X                    else 0 if hangup request was active
X
XThis is a chance for the DCE-specific code to do anything it
Xneeds to cl,ean up after a failure.  Note that if a dialing
Xcall fails, it is the responsibility of the higher-level
Xprogram calling the dialer to call it again with a hangup request, so
Xthis function is usually a no-op.
X--------------------------------------------------------------------------*/
Xvoid
XDCE_abort(sig)
Xint sig;
X{
X	DEBUG(10,"DCE_abort(%d);\n",sig);
X}	/* end of DCE_abort */
X
X/*+-------------------------------------------------------------------------
X	DCE_exit(exitcode) - "last chance for gas" in this incarnation
X
XThe independent portion of the dialer program calls this routine in
Xlieu of exit() in every case except one (see DCE_argv_hook() below).
XNormally, this function just passes it's argument to exit(), but
Xany necessary post-processing can be done.  The function must,
Xhowever, eventually call exit(exitcode);
X--------------------------------------------------------------------------*/
Xvoid
XDCE_exit(exitcode)
Xint exitcode;
X{
X	DEBUG(10,"DCE_exit(%d);\n",exitcode);
X	exit(exitcode);
X}	/* end of DCE_exit */
X
X/*+-------------------------------------------------------------------------
X	DCE_argv_hook(argc,argv,optind,unrecognized_switches)
X
XThis hook gives DCE-specific code a chance to look over the entire
Xcommand line, such as for -z Telebit processing.
X
Xargc andf argv are the same values passed to main(),
X
Xoptind is the value of optind at the end of normal getopt processing.
X
Xunrecognized_switches is the count of switches not handled by main().
XSpecifically, -h and -x are standard switches.
X
XNormally, this function should just return RC_FAIL|RCE_ARGS if there are
Xany unrecognized switches, otherwise zero.  If you keep your nose clean
Xthough, you can do anything you need to do here and exit the program.
X
XNote: only simple switches (with no argument) may be used with this
Xfacility if the functrion is to return,' since main()'s getopt() will
Xstop processing switches if it runs into an unrecognized switch with an
Xargument.
X
XIf the function returns a non-zero value, then the value will be passed
XDIRECTLY to exit() with no further ado.  Thus, a non-zero value must be
Xof the format expected by dialer program callers, with RC_FAIL set as a
Xminimum.
X--------------------------------------------------------------------------*/
Xint
XDCE_argv_hook(argc,argv,optind,unrecognized_switches)
Xint argc;
Xchar **argv;
Xint optind;
Xint unrecognized_switches;
X{
X	if(unrecognized_switches)
X		return(RC_FAIL | RCE_ARGS);
X	return(0);
X}	/* end of DCE_argv_hook */
X
X/* vi: set tabstop=4 shiftwidth=4: */
SHAR_EOF
$TOUCH -am 0725125891 'gendial/dceT2500.c' &&
chmod 0644 gendial/dceT2500.c ||
echo 'restore of gendial/dceT2500.c failed'
Wc_c="`wc -c < 'gendial/dceT2500.c'`"
test 18705 -eq "$Wc_c" ||
	echo 'gendial/dceT2500.c: original size 18705, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= gendial/dceTBPlus.c ==============
if test -f 'gendial/dceTBPlus.c' -a X"$1" != X"-c"; then
	echo 'x - skipping gendial/dceTBPlus.c (File already exists)'
	rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting gendial/dceTBPlus.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'gendial/dceTBPlus.c' &&
X/* CHK=0xFF53 */
X/* #define TRUSTING		/* trust user has -z'd before use */
X/*+-------------------------------------------------------------------------
X	dceTBPlus.c - DCE-specific portion of generic SCO UUCP dialer
X	Driver for Telebit Trailblazer Plus
X	wht@n4hgf.Mt-Park.GA.US
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:07-25-1991-12:58-wht@n4hgf-ECU release 3.10 */
X/*:03-12-1991-19:11-wht@n4hgf-if ecu dialing, show complete call progress */
X/*:11-29-1990-18:31-r@n4hgf-revision/1st releasable */
X/*:07-20-1990-00:10-wht@n4hgf-creation */
X
X#include "dialer.h"
X
X/*
X * DCE_DTR_low_msec - milliseconds to hold DTR low to ensure DCE
X *                    sees the transition; this value may be changed
X *                    as necessary before each call to ltoggleDTR(),
X * but, generally, a constant value will do.
X */
Xlong DCE_DTR_low_msec = 500;
X
X/*
X * DCE_DTR_high_msec - milliseconds DTR must remain high before the
X *                     DCE may be expected to be ready to be commanded
X */
Xlong DCE_DTR_high_msec = 500;
X
X/*
X * DCE_write_pase_msec - milliseconds to pause between each character
X *                       sent to the DCE (zero if streaming I/O is
X *                       permitted); this value may be changed as
X * necessary before each call to lwrite(), but, generally, a constant
X * value will do.  Note that this value is used to feed a value to nap(),
X * which has a granularity of .010 seconds on UNIX/386, .020 on XENIX/286
X * and .050 seconds on XENIX/86.
X */
Xlong DCE_write_pace_msec = 0;
X
X/*
X * DCE_name     - short name for DCE
X * DCE_revision - revision number for this module
X */
Xchar *DCE_name = "Telebit Trailblazer Plus";
Xchar *DCE_revision = "1.10";
X
X/*
X * DCE_hangup_CBAUD - baud rate to use for hanging up DCE
X *                    and readying it for dial in access
X *                    (BXXX mask); use a value of zero if the speed
X *                    specified by the invoker is to be used.
X * This value is useful for DCEs such as the early Hayes 2400
X * which are so unfortunately compatible with their 1200 predecessor
X * that they refuse to answer at 2400 baud unless you last spoke to
X * them at that rate. For such bad boys, use B2400 below.
X */
Xint DCE_hangup_CBAUD = 0;
X/* int DCE_hangup_CBAUD = B2400; */
X
X/*
X * DCE_results - a table of DCE response strings and a token
X *               code for each; when you call lread() or lread_ignore(),
X *               if the read routine detects one of the strings,
X * the appropriate code is returned.  If no string matches, then
X * lread()/lread_ignore examines the DCE result string for a
X * numeric value; if one is found, the numeric value or'd with
X * 0x40000000 is returned (in this way, e.g., you can read "modem
X * S registers").  If nothing agrees with this search, lread()
X * will abort the program with RC|FAIL|RCE_TIMOUT, lread_ignore()
X * will return -1.  You may use any value between 0 and 0x3FFFFFFF.
X * This module is the only consumer  of the codes, although they
X * are decoded by gendial.c's _lread()
X */
X
X/* flag bits */
X#define rfConnect		0x00800000
X#define rfREL			0x00400000
X#define rfFAST			0x00200000
X#define rfMASK			0x0000FFFF	/* mask off rfBits */
X
X/* unique codes */
X#define rOk				0
X#define rNoCarrier		1
X#define rError			2
X#define rNoDialTone 	3
X#define rBusy			4
X#define rNoAnswer		5
X#define rRring			6
X#define rConnect300		(  300  | rfConnect)
X#define rConnect1200	( 1200  | rfConnect)
X#define rConnect2400	( 2400  | rfConnect)
X#define rConnect300R	(  300  | rfConnect | rfREL)
X#define rConnect1200R	( 1200  | rfConnect | rfREL)
X#define rConnect2400R	( 2400  | rfConnect | rfREL)
X#define rConnectFASTK	(19200  | rfConnect | rfFAST)
X#define rConnectFASTX	(19200  | rfConnect | rfFAST)
X#define rConnectFASTU	(19200  | rfConnect | rfFAST)
X#define rConnectFAST	(19200  | rfConnect | rfFAST)
X
XDCE_RESULT DCE_results[] =
X{
X	{ "OK",						rOk,			},
X	{ "NO CARRIER",				rNoCarrier,		},
X	{ "ERROR",					rError			},
X	{ "NO DIALTONE",			rNoDialTone,	},
X	{ "BUSY",					rBusy			},
X	{ "NO ANSWER",				rNoAnswer		},
X	{ "RRING",					rRring			},
X	{ "CONNECT 300/REL",		rConnect300R	},
X	{ "CONNECT 1200/REL",		rConnect1200R	},
X	{ "CONNECT 2400/REL",		rConnect2400R	},
X	{ "CONNECT 300",			rConnect300		},
X	{ "CONNECT 1200",			rConnect1200	},
X	{ "CONNECT 2400",			rConnect2400	},
X	{ "CONNECT FAST/KERM",		rConnectFASTK	},
X	{ "CONNECT FAST/XMDM",		rConnectFASTX	},
X	{ "CONNECT FAST/UUCP",		rConnectFASTU	},
X	{ "CONNECT FAST",			rConnectFAST	},
X	{ (char *)0,				-1				}		/* end table */
X};
X
X/*+-------------------------------------------------------------------------
X	DCE_baud_to_CBAUD(baud) - check for valid baud rates supported by DCE
X
X  DCE dependent function must validate baud rates supported by DCE
X  returns baud rate in struct termio c_cflag fashion
X  or terminates program with error
X--------------------------------------------------------------------------*/
Xint
XDCE_baud_to_CBAUD(baud)
Xunsigned int baud;
X{
X	switch(baud)
X	{
X		case 110:  return(B110);
X		case 300:  return(B300);
X		case 1200: return(B1200);
X		case 2400: return(B2400);
X		case 9600: return(B9600);
X
X#if defined(B19200)
X		case 19200: return(B19200);
X#else
X#ifdef EXTA
X		case 19200: return(EXTA);
X#endif
X#endif
X
X#if defined(B38400)
X		case 38400: return(B38400);
X#else
X#ifdef EXTB
X		case 38400: return(EXTB);
X#endif
X#endif
X
X	}
X	myexit(RC_FAIL | RCE_SPEED);
X}	/* end of DCE_baud_to_CBAUD */
X
X/*+-------------------------------------------------------------------------
X	sync_Telebit() - sync modem with our DTE speed
X--------------------------------------------------------------------------*/
Xvoid
Xsync_Telebit()
X{
Xregister int maxretry = 8;
Xregister int count;
Xunsigned char rdchar;
X
X	while(maxretry--)
X	{
X		lflush();
X		write(fddce,"a",1);
X		count = 5;
X		while(count)	/* wait 50-200 msec for character, depending on HZ */
X		{
X			if(rdchk(fddce))
X				break;
X			nap(50L);
X			count--;
X		}
X		if(count && (read(fddce,&rdchar,1) == 1) && (rdchar == 'a'))
X			return;
X	}
X
X	DEBUG(1,"Telebit SYNC FAILED\n",0);
X	myexit(RC_FAIL | RCE_TIMOUT);
X
X}	/* end of sync_Telebit */
X
X/*+-------------------------------------------------------------------------
X	init_TBPlus() - init TBPlus from scratch, assuming nothing
X
X	reset to factory defaults, then set
X    E0          no local echo in command mode
X    F1          no local echo in data transfer mode
X    M0          speaker off
X    Q4          generate reult codes, but not RING
X    V1          verbal result codes
X    X3          extended result codes
X    S0=1        answer on first ring
X    S2=1        escape to "unusual" value
X    S11=50      50 msec DTMF timing
X    S45=1       enable remote access
X    S48=1       all 8 bits are significant
SHAR_EOF
true || echo 'restore of gendial/dceTBPlus.c failed'
fi
echo 'End of ecu310 part 26'
echo 'File gendial/dceTBPlus.c is continued in part 27'
echo 27 > _shar_seq_.tmp
exit 0
--------------------------------------------------------------------
Warren Tucker, TuckerWare emory!n4hgf!wht or wht@n4hgf.Mt-Park.GA.US
Hacker Extraordinaire  d' async PADs,  pods,  proteins and protocols

exit 0 # Just in case...
-- 
Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
Sterling Software, IMD           UUCP:     uunet!sparky!kent
Phone:    (402) 291-8300         FAX:      (402) 291-4362
Please send comp.sources.misc-related mail to kent@uunet.uu.net.


