From pa.dec.com!decwrl!uunet!sparky!kent Sun Aug 11 15:47:07 PDT 1991
Article: 2589 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:  v21i079:  ecu - ECU async comm package rev 3.10, Part27/37
Message-ID: <1991Aug4.163124.18914@sparky.IMD.Sterling.COM>
X-Md4-Signature: 72df10a56514d67e609619069cdfd5fb
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:24 GMT
Approved: kent@sparky.imd.sterling.com
Lines: 1836

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

---- Cut Here and feed the following to sh ----
#!/bin/sh
# this is ecu310.27 (part 27 of ecu310)
# do not concatenate these parts, unpack them in order with /bin/sh
# file gendial/dceTBPlus.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" != 27; 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/dceTBPlus.c'
else
echo 'x - continuing file gendial/dceTBPlus.c'
sed 's/^X//' << 'SHAR_EOF' >> 'gendial/dceTBPlus.c' &&
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--------------------------------------------------------------------------*/
Xvoid
Xinit_TBPlus()
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\r";
X
X	DEBUG(7,"INITIALIZING %s\n",dce_name);
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_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#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_TBPlus();
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
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" : 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,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
echo 'File gendial/dceTBPlus.c is complete' &&
$TOUCH -am 0725125891 'gendial/dceTBPlus.c' &&
chmod 0644 gendial/dceTBPlus.c ||
echo 'restore of gendial/dceTBPlus.c failed'
Wc_c="`wc -c < 'gendial/dceTBPlus.c'`"
test 17953 -eq "$Wc_c" ||
	echo 'gendial/dceTBPlus.c: original size 17953, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= gendial/dceUSR24.c ==============
if test -f 'gendial/dceUSR24.c' -a X"$1" != X"-c"; then
	echo 'x - skipping gendial/dceUSR24.c (File already exists)'
	rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting gendial/dceUSR24.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'gendial/dceUSR24.c' &&
X/*+------------------------------------------------------------------------- dceUSR24.c - DCE-specific portion of generic SCO UUCP dialer
X	Driver for USR Courier 2400
X	wht@n4hgf.Mt-Park.GA.US
X
X Necessary DCE switch setting or other configuration:
X   enable onhook upon loss of DTR
X
XThis dialer does not use the X6 quick dial feature, nor voice detection.
XQuick dial tone recognition often fqails due to the telco granting
Xdial tone ahead of the actual time it is ready to accept dialing.
XVoice recognition fails when dialing 0+ with a credit card, as in "Thank
Xyou for using ATT" - CLICK - "VOICE".
X
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:07-25-1991-12:58-wht@n4hgf-ECU release 3.10 */
X/*:07-25-1991-04:34-wht@n4hgf-add naps around writes */
X/*:04-16-1991-18:18-wht@n4hgf-creation from template */
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 = 500L;
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 = 1000L;
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 = 40;
X
X/*
X * DCE_name     - short name for DCE
X * DCE_revision - revision number for this module
X */
Xchar *DCE_name = "USR Courier 2400";
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 = 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 * 0x4000 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#define rfConnect		0x00400000
X#define rfMASK			0x000000FF
X
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 rVoice			6
X#define rConnect300		(7 | rfConnect)
X#define rConnect1200	(8 | rfConnect)
X#define rConnect2400	(9 | rfConnect)
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	{ "VOICE",					rVoice			},
X	{ "CONNECT",				rConnect300		},
X	{ "CONNECT 1200",			rConnect1200	},
X	{ "CONNECT 2400",			rConnect2400	},
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 50:   return(B50);		/* delete the ones you dont handle */
X		case 75:   return(B75);
X		case 110:  return(B110);
X		case 134:  return(B134);
X		case 150:  return(B150);
X		case 300:  return(B300);
X		case 1200: return(B1200);
X		case 2400: return(B2400);
X		case 4800: return(B4800);
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__)
X	return(0);	/* I wish this wasn't necessary to avoid warnings */
X#endif
X}	/* end of DCE_baud_to_CBAUD */
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
XYou must set any switches necessary to make modem hang up on loss of DTR
X--------------------------------------------------------------------------*/
Xvoid
XDCE_hangup()
X{
Xstruct termio temp;
Xint itmp;
Xint maxretry = 4;
X
X	DEBUG(3,"--> reseting %s\n",DCE_name);
X
X	/*
X	 * drop DTR and pause a while
X	 */
X	temp = dce_termio;
X	temp.c_cflag &= ~CBAUD;		/* use B0 */
X	ioctl(fddce,TCSETA,&temp);	/* drop DTR */
X	nap((DCE_DTR_low_msec) ? DCE_DTR_low_msec : 300L);
X
X	/*
X	 * raise DTR and pause a while
X	 */
X	ioctl(fddce,TCSETA,&dce_termio);	/* raise DTR */
X	nap((DCE_DTR_high_msec) ? DCE_DTR_high_msec : 1500L);
X
X	/*
X	 * reset modem completely
X	 */
X	lwrite("AAAAAATZ\r");
X	nap(2000L);
X	lflush();
X
X	/*
X	 * set up modem
X	 */
X	for(itmp = 0; itmp < maxretry; itmp++)
X	{
X		lwrite("ATS0=1M0Q0V1X3\r");
X		if(lread(2) == rOk)
X			break;
X		nap(500L);
X	}
X	if(itmp == maxretry)
X	{
X		DEBUG(1,"INIT FAILED (init0)\n",0);
X		myexit(RC_FAIL | RCE_TIMOUT);
X	}
X
X	/*
X	 * shut up - no result codes
X	 */
X	nap(500L);
X	lwrite("ATQ1\r");
X	nap(750L);
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--------------------------------------------------------------------------*/
Xint
XDCE_dial(telno)
Xchar *telno;
X{
Xchar cmd[128];
Xchar phone[50];
Xlong timeout;
Xint result;
Xchar *cptr;
Xchar *dialout_default = "ATS0=0S7=40Q0M0V1E0X3\r";
X#define MDVALID	 "0123456789NnSs*#,!/()-"
Xstruct termio temp;
Xint itmp;
Xint maxretry = 4;
X
X/* if root, let him see number, otherwise just say "remote system" */
X	DEBUG(1,"DIALING %s\n", (uid) ? "remote system" : telno);
X
X	/*
X	 * drop DTR and pause a while
X	 */
X	temp = dce_termio;
X	temp.c_cflag &= ~CBAUD;		/* use B0 */
X	ioctl(fddce,TCSETA,&temp);	/* drop DTR */
X	nap((DCE_DTR_low_msec) ? DCE_DTR_low_msec : 300L);
X
X	/*
X	 * raise DTR and pause a while
X	 */
X	ioctl(fddce,TCSETA,&dce_termio);	/* raise DTR */
X	nap((DCE_DTR_high_msec) ? DCE_DTR_high_msec : 1500L);
X
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	/*
X	 * wake up modem
X	 */
X	DEBUG(6,"--> waking up modem\n",0);
X	for(itmp = 0; itmp < maxretry; itmp++)
X	{
X		lwrite(dialout_default);
X		if(lread(2) == rOk)
X			break;
X		nap(200L);
X	}
X	if(itmp == maxretry)
X	{
X		DEBUG(1,"DIAL INIT FAILED\n",0);
X		myexit(RC_FAIL | RCE_TIMOUT);
X	}
X
X	/*
X	 * calculate a timeout for the connect
X	 * allow a minimum of 40 seconds
X	 * if long distance (North American calculation here)
X	 * make it 132 (S7 is calculated as timeout * .95)
X	 */
X	timeout = 40L;
X	if((phone[0] == '1') && (phone[0] != '0'))
X		timeout = 132L;
X	if((timeout < 90L) && (dialer_codes['V' - 'A'] || dialer_codes['P' - 'A']))
X		timeout = 90L;
X	for(cptr = phone; cptr = strchr(cptr,','); cptr++)
X		timeout += 2L;	/* add extra time for pause characters */
X	DEBUG(6,"timeout waiting for connect = %ld seconds\n",timeout);
X
X	/*
X	 * do custom setup here to conserve 40 char max cmd for telno
X	 */
X#ifdef WHT
X	if(!strncmp(*gargv,"ECU",3))
X		dialer_codes['S' - 'A'] = 1;
X#endif
X	sprintf(cmd,"ATM%dS7=%dS11=40T\r",
X		((dialer_codes['S' - 'A']) && !(dialer_codes['N' - 'A'])) ? 1 : 0,
X		(int)((timeout * 95L) / 100L));
X	DEBUG(6,"--> setting speaker, DTMF dialing and wait for carrier time\n",0);
X	nap(200L);
X	for(itmp = 0; itmp < maxretry; itmp++)
X	{
X		lwrite(cmd);
X		if(lread(2) == rOk)
X			break;
X		nap(200L);
X	}
X	if(itmp == maxretry)
X	{
X		DEBUG(1,"DIAL INIT FAILED\n",0);
X		myexit(RC_FAIL | RCE_TIMOUT);
X	}
X
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	sprintf(cmd,"ATD%s\r",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	nap(200L);
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 rVoice:	/* if you get voice, certainly wrong number */
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/* indicate non-root can see DTE->DCE traffic */
X	secure = 0;
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/dceUSR24.c' &&
chmod 0644 gendial/dceUSR24.c ||
echo 'restore of gendial/dceUSR24.c failed'
Wc_c="`wc -c < 'gendial/dceUSR24.c'`"
test 14126 -eq "$Wc_c" ||
	echo 'gendial/dceUSR24.c: original size 14126, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= gendial/dialer.h ==============
if test -f 'gendial/dialer.h' -a X"$1" != X"-c"; then
	echo 'x - skipping gendial/dialer.h (File already exists)'
	rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting gendial/dialer.h (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'gendial/dialer.h' &&
X/*+-------------------------------------------------------------------------
X	dialer.h - SCO UUCP generic dialer program definitions
X	wht%n4hgf.uucp@emory.mathcs.emory.edu -or- emory!n4hgf!wht
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/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
X
X#include <stdio.h>
X#include <ctype.h>
X#include <errno.h>
X#include <fcntl.h>
X#include <setjmp.h>
X#include <signal.h>
X#include <string.h>
X#include <memory.h>
X#include <sys/types.h>
X#include <sys/errno.h>
X#include <sys/stat.h>
X#include <termio.h>
X#include <time.h>
X#include <pwd.h>
X
X#define ff fprintf
X#define se stderr
X
Xlong time();
Xstruct passwd *getpwnam();
X
Xextern int errno;
Xextern char *sys_errlist[];
X
Xextern int gargc;					/* global copy of main's argv */
Xextern char **gargv;				/* global copy of main's argv */
Xextern char *dce_name;				/* full pathname of ACU device */
Xextern char *telno;					/* phone number if dial type request */
Xextern struct termio dce_termio;	/* last termio for device */
Xextern int Debug;					/* set per -x flag */
Xextern int dialing;					/* set while dialing in progress */
Xextern int fddce;					/* file descriptor for dce_name */
Xextern int DialerExitCode; 			/* return code */
Xextern int status;					/* set on errors */
Xextern int hangup_flag;				/* set when DCE being hung up */
Xextern int hiCBAUD;					/* highest permissible baud rate */
Xextern int loCBAUD;					/* lowest permissible baud rate */
Xextern struct passwd *passwd;		/* pointer to password entry of invoker */
Xextern int uid;						/* user id of executor */
Xextern int uid_uucp;				/* user id of uucp */
Xextern int secure;					/* non-zero to suppress display of secure
X									 * DCE traffic
X									 */
Xextern int ecu_calling;				/* true if ecu dialing */
X
Xunsigned char dialer_codes[26];	/* A-Z embedded phone number codes */
X/* return codes: these are set up so that an abort signal at any time can */
X/* set the fail bit and return to the caller with the correct status */
X#define	SUCCESS		0
X#define	RC_FAIL		0x80	/* 1 = failed to connect */
X#define	RC_ENABLED	0x10	/* enabled flag: 1 = ungetty -r required to
X							 * restore the line
X							 */
X#define	RC_BAUD		0x0f	/* CBAUD connected at (0=same as dialed speed) */
X
X/* DCE result device independent flag */
X#define	rfNumeric	0x40000000
X
X/* program exit codes */
X#define	RCE_NULL	0	/* general purpose or unknown error code */
X#define	RCE_INUSE	1	/* line in use */
X#define	RCE_SIG		2	/* signal aborted dialer */
X#define	RCE_ARGS	3	/* invalid arguments */
X#define	RCE_PHNO	4	/* invalid phone number */
X#define	RCE_SPEED	5	/* invalid baud rate -or- bad connect baud */
X#define	RCE_OPEN	6	/* can't open line */
X#define	RCE_IOCTL	7	/* ioctl error */
X#define	RCE_TIMOUT	8	/* timeout */
X#define	RCE_NOTONE	9	/* no dial tone */
X#define	RCE_HANGUP	10	/* hangup failed */
X#define RCE_NORESP	11	/* Modem didn't respond. */
X#define	RCE_BUSY	13	/* phone is busy */
X#define	RCE_NOCARR	14	/* no carrier */
X#define	RCE_ANSWER	15	/* no answer */
X
X/* ungetty return codes */
X#define	UG_NOTENAB	0
X#define	UG_ENAB		1
X#define	UG_RESTART	1
X#define	UG_FAIL		2
X
X/* size for various buffers */
X#define MAXLINE		80
X
X/* How many errors allowed before call retry fails */
X#define	DIAL_ERRORS_MAX	4
X
X/* DCE message to code mapping struct ... array DCE_results of these
X * must be terminated with { (char *)0,0 } */
Xtypedef struct dce_result
X{
X	char *result;
X	long code;
X} DCE_RESULT;
X
X#define DEBUG(level,fmt,arg) if (Debug >= level) fprintf(stderr,fmt,arg)
X#if !defined(DBG)
X#define	DBG	0
X#endif
X
X/*
X * what the hell does __STDC__ mean in reality?  An __STDC__ compiler is
X * more nouveau than an older one.  ANSI C (or 'D') just stirred new
X * food for "standard" readers who went off and did what they wanted
X * to do.  We use __STDC__ to decide between two opinions of
X * what constitute "ANSI prototypes."  As of this writing, __STDC__ is
X * defined by the UNIX (MSC 5) compiler and not by the XENIX (MSC 4)
X * compiler.  We handle the GNU C compiler too.
X */
X#if defined(__STDC__) && !defined(__GNUC__)
Xint DCE_baud_to_CBAUD(unsigned int );
Xvoid DCE_hangup(void );
Xint DCE_dial(char *);
Xvoid DCE_abort(int );
Xvoid DCE_exit(int );
Xint DCE_argv_hook(int ,char **,int ,int );
Xint get_uucp_uid(void );
Xint instr(char *,char *);
Xvoid translate(char *,char *);
Xint decode_phone_number(char *,char *,int );
Xchar *make_printable(unsigned char );
Xchar *RCE_text(int );
Xvoid myexit(int );
XSIGTYPE dial_abort(int );
Xvoid cleanup(int );
Xint SIGALRM_abort(int );
XSIGTYPE SIGALRM_alert(int );
Xlong _lread(int ,int );
Xlong lread_ignore(int );
Xlong lread(int );
Xint lflush(void );
Xvoid _lputc(char );
Xvoid _lputc_paced(long ,char );
Xvoid _lputs(char *);
Xvoid _lputs_paced(long ,char *);
Xint lwrite(char *);
Xint ltoggleDTR(long );
Xint call_ungetty(char );
Xvoid display_termio(struct termio *,char *);
Xint open_dce(void );
Xint main(int ,char **);
X#else
Xint DCE_baud_to_CBAUD();
Xvoid DCE_hangup();
Xint DCE_dial();
Xvoid DCE_abort();
Xvoid DCE_exit();
Xint DCE_argv_hook();
Xint get_uucp_uid();
Xint instr();
Xvoid translate();
Xint decode_phone_number();
Xchar *make_printable();
Xchar *RCE_text();
Xvoid myexit();
XSIGTYPE dial_abort();
Xvoid cleanup();
XSIGTYPE SIGALRM_alert();
Xint SIGALRM_abort();
Xlong _lread();
Xlong lread_ignore();
Xlong lread();
Xint lflush();
Xvoid _lputc();
Xvoid _lputc_paced();
Xvoid _lputs();
Xvoid _lputs_paced();
Xint lwrite();
Xint ltoggleDTR();
Xint call_ungetty();
Xvoid display_termio();
Xint open_dce();
Xint main();
X#endif
X
X/* vi: set tabstop=4 shiftwidth=4: */
X/* end of dialer.h */
SHAR_EOF
$TOUCH -am 0725125891 'gendial/dialer.h' &&
chmod 0644 gendial/dialer.h ||
echo 'restore of gendial/dialer.h failed'
Wc_c="`wc -c < 'gendial/dialer.h'`"
test 5687 -eq "$Wc_c" ||
	echo 'gendial/dialer.h: original size 5687, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= gendial/gendial.c ==============
if test -f 'gendial/gendial.c' -a X"$1" != X"-c"; then
	echo 'x - skipping gendial/gendial.c (File already exists)'
	rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting gendial/gendial.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'gendial/gendial.c' &&
X/* CHK=0xC086 */
Xchar *revision = "1.10";
X/*+-------------------------------------------------------------------------
X	gendial.c - SCO UUCP dialer program device independent portion
X	wht@n4hgf.Mt-Park.GA.US
X
X  Configuration symbols:
X	HDB_UUCP		defined if HDB UUCP used on system, else old Version 2 
X
X  Defined functions:
X	RCE_text(value)
X	SIGALRM_alert(sig)
X	_lputc(lchar)
X	_lputc_paced(pace_msec,lchar)
X	_lputs(string)
X	_lputs_paced(pace_msec,string)
X	_lread(rtime,error_ok)
X	call_ungetty(call_type)
X	cleanup(stat)
X	decode_phone_number(userphno,result,resultlen)
X	dial_abort(sig)
X	display_termio(ttt,text)
X	get_uucp_uid()
X	instr(s1,s2)
X	lflush()
X	lread(rtime)
X	lread_ignore(rtime)
X	ltoggleDTR(msec)
X	lwrite(str)
X	main(argc,argv)
X	make_printable(ch)
X	myexit(code)
X	open_dce()
X	translate(ttab,str)
X
X  Usage:	dial ttyname telnumber speed 
X			dial -h ttyname speed
X
X  ttyname may be of style "ttyxx" or "/dev/ttyxx" (this is not standard)
X
X  Returns:
X		0x80	bit = 1 if connection failed
X		0x10	bit = 1 if line is also used for dialin #if !defined(OLDUUCP)
X		0x0f	if msb=1: error code
X				if msb=0: connected baud rate (0=same as dialed baud)
X                Note: this dialer always returns 0 in the low nibble
X                since cu and uucp expect it
X
X  Note: getty calls the dialer with -h whenever it starts up on a line
X  enabled in /etc/ttys and listed in Devices with this dialer.
X
X  Error codes are split into two categories:
X
X    1) (codes 0-11) Local problems are defined as tty port, or DCE
X    problems: problems that can be worked around by using a different
X    device.
X
X    2) (codes 12-15) Remote problems are phone busy, no answer, etc.:
X    attempt to connect to this remote system should be stopped.
X
X  Note: This dialer can be used both for the old "Version 2" 
X  new HoneyDanBer UUCP.  In HDB, uugetty is used and ungetty is not
X  necessary. Define HDB_UUCP for HDB UUCP.
X
X  Note: This version of the dialer will NOT display the telephone number
X  on the console unless the actual uid is root.  If dial logging is
X  used, make sure the dial_ttyXX.log file is precreated, owned by root
X  and has -rw--w--w- mode (0622).  Now, if uucico would just suppress
X  username and password information it sends out!
X
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:07-25-1991-12:58-wht@n4hgf-ECU release 3.10 */
X/*:05-01-1991-21:28-wht@n4hgf-add dial timing */
X/*:03-12-1991-19:11-wht@n4hgf-if ecu dialing, show complete call progress */
X/*:07-19-1990-17:14-root@n4hgf-modify lread fata timeout handler */
X/*:05-26-1990-02:15-wht@n4hgf-creation */
X
X#include "dialer.h"
X
X/* must be defined by device dependent module */
Xextern long DCE_DTR_low_msec;		/* msecs DTR must be low to be recognized */
Xextern long DCE_DTR_high_msec;		/* msecs for DCE to recover */
Xextern long DCE_write_pace_msec;	/* msecs between chars written to DCE */
Xextern DCE_RESULT DCE_results[];	/* DCE result codes */
Xextern char *DCE_name;				/* name of DCE */
Xextern char *DCE_revision;			/* DCE-dependent code revision */
Xextern short DCE_hangup_CBAUD;		/* BXXX DCE hangup baud rate or zero */
X
X/* globals available to device dependent module */
Xint gargc;					/* global copy of main's argv */
Xchar **gargv;				/* global copy of main's argv */
Xchar *dce_name;					/* full pathname of ACU device */
Xchar *telno = (char *)0;	/* phone number if dial type request */
Xstruct termio dce_termio;	/* last termio for device */
Xint Debug = DBG;			/* set per -x flag */
Xint dialing = 0;			/* set while dialing in progress */
Xint fddce = -1;				/* file descriptor for dce_name */
Xint DialerExitCode = RC_FAIL; /* return code */
Xint status = 0;				/* set on errors */
Xint hangup_flag = 0;		/* set when DCE being hung up */
Xint hiCBAUD;				/* highest permissible baud rate */
Xint loCBAUD;				/* lowest permissible baud rate */
Xstruct passwd *passwd;
Xint uid;					/* user id of executor */
Xint uid_uucp;				/* user id of uucp */
Xint secure = 0;				/* non-zero to suppress display of secure
X							 * DCE traffic
X							 */
Xint ecu_calling = 0;		/* true if ecu is dialing */
X
Xunsigned char dialer_codes[26];	/* A-Z embedded phone number codes */
X
Xjmp_buf	SIGALRM_alert_jmpbuf;
XDCE_RESULT *last_result;
X
X/*+-------------------------------------------------------------------------
X	get_uucp_uid()
X--------------------------------------------------------------------------*/
Xint
Xget_uucp_uid()
X{
X
X	passwd = getpwnam("uucp");
X	endpwent();
X	if(passwd)
X		return(passwd->pw_uid);
X	else
X		return(-1);
X}	/* end of get_uucp_uid */
X
X/*+-------------------------------------------------------------------------
X	instr(s1,s2)
X
X  find s2 in s1; returns 1 if found, 0 if not found
X--------------------------------------------------------------------------*/
Xinstr(s1,s2)
Xregister char *s1;
Xchar *s2;
X{
X	register len = strlen(s2);
X	while(s1 = strchr(s1,*s2))
X	{
X		if(!strncmp(s2,s1,len))
X			return(1);
X		s1++;
X	}
X	return(0);
X}	/* end of instr */
X
X/*+-------------------------------------------------------------------------
X	translate(ttab,str)
X
X  translate the pairs of characters present in the first string
X  whenever the first of the pair appears in the second string
X  (this routine from standard SCO dialer code)
X--------------------------------------------------------------------------*/
Xvoid
Xtranslate(ttab,str)
Xregister char *ttab;
Xchar *str;
X{
X	register char *cptr;
X
X	while(*ttab && *(ttab + 1))
X	{
X		for(cptr = str; *cptr; cptr++)
X		{
X			if(*ttab == *cptr)
X				*cptr = *(ttab + 1);
X		}
X		ttab += 2;
X	}
X}	/* end of translate */
X
X/*+-------------------------------------------------------------------------
X	decode_phone_number(userphno,result,resultlen)
X
Xdecode user flags in phone number, returning phone number in
Xresult, character flags in global dialer_codes[], 'A' or 'a'
Xresults in dialer_codes[0] being 1, etc.  Only letter codes are
Xextracted.
X
XFor example, if userphno contains "123,D45f", result returned
X"123,45" and only elements 3 and 5 of dialer_codes set to 1
X
XFunction returns 0 if successful, -1 if result buffer too small
X--------------------------------------------------------------------------*/
Xint
Xdecode_phone_number(userphno,result,resultlen)
Xregister char *userphno;
Xregister char *result;
Xint resultlen;
X{
Xregister itmp;
X
X	for(itmp = 0; itmp < sizeof(dialer_codes); itmp++)
X		dialer_codes[itmp] = 0;
X
X	if(!resultlen)
X		return(-1);
X	resultlen--;	/* leave room for null */
X
X	while(*userphno)
X	{
X		if(isalpha(*userphno))
X			dialer_codes[*userphno - ((isupper(*userphno)) ? 'A' : 'a')] = 1;
X		else
X		{
X			if(!resultlen--)
X				return(-1);
X			*result++ = *userphno;
X		}
X		userphno++;
X	}
X	*result = 0;
X	return(0);
X}	/* end of decode_phone_number */
X
X/*+-------------------------------------------------------------------------
X	make_printable(ch) - make a character "printable"
X--------------------------------------------------------------------------*/
Xchar *
Xmake_printable(ch)
Xunsigned char ch;
X{
Xstatic char buffer[10];
Xchar *cptr;
X#define	to_print(x)	((x)<' '?((x)+'@'):'?')
X
X	cptr = buffer;
X	/* if not root or uucp and info needs securing */
X	if(!ecu_calling && uid && (uid != uid_uucp) && secure)
X	{
X		*cptr++ = '?';	/* hide it */
X		*cptr = 0;
X		return(buffer);
X	}
X
X	if(iscntrl(ch) || !isprint(ch))
X	{
X		if(!isascii(ch))
X		{			/* Top bit is set */
X			*cptr++ = 'M';
X			*cptr++ = '-';
X			ch = toascii(ch);			/* Strip it */
X		}
X		if(iscntrl(ch))
X		{
X			*cptr++ = '^';
X			ch = to_print(ch);			/* Make it printable */
X		}
X	}
X	*cptr++ = ch;
X	*cptr = 0;
X	return(buffer);
X}	/* end of make_printable */
X
X/*+-------------------------------------------------------------------------
X	RCE_text(value)
X--------------------------------------------------------------------------*/
Xchar *
XRCE_text(value)
Xint value;
X{
Xstatic char errant[32];
X
X	switch(value & 0x0F)
X	{
X		case RCE_NULL: return("unknown or unclassified error");
X		case RCE_INUSE: return("line in use");
X		case RCE_SIG: return("killed with signal");
X		case RCE_ARGS: return("invalid arguments");
X		case RCE_PHNO: return("invalid phone number");
X		case RCE_SPEED: return("invalid line speed or bad connect speed");
X		case RCE_OPEN: return("cannot open line");
X		case RCE_IOCTL: return("ioctl error");
X		case RCE_TIMOUT: return("timeout");
X		case RCE_NOTONE: return("NO DIAL TONE");
X		case RCE_HANGUP: return("hangup failed\n");
X		case RCE_NORESP: return("DCE didn't respond.\n");
X		case RCE_BUSY: return("BUSY");
X		case RCE_NOCARR: return("NO CARRIER");
X		case RCE_ANSWER: return("NO ANSWER");
X	}
X	sprintf(errant,"code 0x%04x",value);
X	return(errant);
X
X}	/* end of RCE_text */
X
X/*+-------------------------------------------------------------------------
X	myexit(code) - all threads exit() thru here
X--------------------------------------------------------------------------*/
Xvoid
Xmyexit(code)
Xint code;
X{
X	if(dialing)
X	{
X		if(code & RC_FAIL)
X		{
X			DEBUG(1,"dial failed: %s\n",RCE_text(code));
X		}
X		else
X		{
X			DEBUG(1,"dial succeeded\n",0);
X		}
X	}
X	DCE_exit(code);	/* should not return */
X	exit(code);		/* in case it does */
X
X}	/* end of myexit */
X
X/*+-------------------------------------------------------------------------
X	dial_abort(sig)
X--------------------------------------------------------------------------*/
XSIGTYPE
Xdial_abort(sig)
Xint sig;
X{
X	if(sig)
X	{
X		DEBUG(2,"\ndialer received signal %d\n\n",sig);
X	}
X	else
X	{
X		DEBUG(2,"\ndialer aborted, fail status = %d\n",DialerExitCode);
X	}
X	DCE_abort(sig);
X	if(fddce != -1)
X	{
X		ioctl(fddce,TCGETA,&dce_termio);
X		dce_termio.c_cflag |= HUPCL;		/* make sure DCE hangs up */
X		ioctl(fddce,TCSETA,&dce_termio);
X		close(fddce);
X	}
X	if(sig)
X		DialerExitCode |= (RC_FAIL | RCE_SIG);
X	myexit(DialerExitCode);
X}	/* end of dial_abort */
X
X/*+-------------------------------------------------------------------------
X	cleanup(stat) - close device and exit
X--------------------------------------------------------------------------*/
Xvoid
Xcleanup(stat)
Xint stat;
X{
X	if(stat & RC_FAIL)
X	{	/* if we failed, drop DTR (in dial_abort) */
X		DialerExitCode = stat;
X		dial_abort(0);
X	}
X	else 
X		myexit(stat);
X}	/* end of cleanup */
X
X/*+-------------------------------------------------------------------------
X	SIGALRM_alert(sig) - catch alarm call and do longjmp
X--------------------------------------------------------------------------*/
XSIGTYPE
XSIGALRM_alert(sig)
Xint sig;
X{
X	longjmp(SIGALRM_alert_jmpbuf,1);
X}	/* end of SIGALRM_alert */
X
X/*+-------------------------------------------------------------------------
X	_lread(rtime,error_ok)
X
X  Common code for lread() and lread_ignore()
X
X  Returns DCE_RESULT->code from matching DCE_RESULT->result
X  or if no match is found and the first digit of the modem
X  response is numeric, the the numeric value is returned ored
X  with 0x4000.
X
X  If error_ok is true and a timeout occurs, -1 is returned.
X  If error_ok is false and a timeout occurs,
X     cleanup(RC_FAIL | RCE_TIMOUT | DialerExitCode);
X     is called, which results in dial_abort(0) thus DCE_abort(0)
X     being called.
X--------------------------------------------------------------------------*/
Xlong
X_lread(rtime,error_ok)
Xint rtime;
Xint error_ok;
X{
Xint itmp;
Xchar rdchar;
XDCE_RESULT *mr;
Xchar buf[MAXLINE];
Xchar *bp;
Xchar *cptr;
X
X	if(error_ok)
X	{
X		signal(SIGALRM,SIGALRM_alert);
X		if(setjmp(SIGALRM_alert_jmpbuf) != 0)
X		{
X			DEBUG(6,">>-%s\n","TIMEOUT (NON-FATAL)");
X			return(-1);
X		}
X	}
X	else
X	{
X		signal(SIGALRM,SIGALRM_alert);
X		if(setjmp(SIGALRM_alert_jmpbuf) != 0)
X		{
X			DEBUG(6,">>-%s\n","TIMEOUT (FATAL)");
X			cleanup(RC_FAIL | RCE_TIMOUT | DialerExitCode);
X		}
X	}
X
X	bp = buf;
X	alarm(rtime);
X	DEBUG(6,"DCE returned %s","<<");
X
X	while((itmp = read(fddce,&rdchar,1)) == 1)
X	{
X		*bp++ = (rdchar &= 0x7F);
X		DEBUG(6,"%s",make_printable(rdchar));
X		if(rdchar == 0x0A)
X			DEBUG(6,"\n",0);
X		if(bp >= buf + MAXLINE)
X		{
X			alarm(0);
X			DEBUG(6,"\n>>-FAIL (%s)\n","BUFFER OVERFLOW");
X			myexit(RC_FAIL | RCE_NULL);
X		}
X		*bp = 0;
X		if(rdchar == '\r')
X		{
X			cptr = buf;
X			if(*cptr == 0x0A)
X				cptr++;
X			for(mr = DCE_results; mr->result; ++mr)
X			{
X				if(instr(buf,mr->result))
X				{
X					alarm(0);
X					DEBUG(6,">>-%s\n","SUCCESS");
X					if(strcmp(mr->result,"OK"))  /* not so modem independent */
X						DEBUG(4,"got %s\n",mr->result);
X					else
X						DEBUG(6,"got %s\n",mr->result);
X					last_result = mr;
X					return(mr->code);
X				}
X			}
X
X			if(isdigit(*cptr))
X			{
X				alarm(0);
X				itmp = atoi(cptr);
X				DEBUG(6,">>-SUCCESS (NUMERIC RESULT %d)\n",itmp);
X				return(rfNumeric | itmp);
X			}
X
X			bp = buf;
X		}
X	}
X
X	alarm(0);
X	if(Debug >= 6)
X	{
X		ff(se,">>-FAIL (%s %d)",
X			(itmp < 0) ? "READ ERRNO" : "READ LENGTH",
X			(itmp < 0) ? errno : 0);
X	}
X	DEBUG(4," incomplete or no response\n",0);
X	return(-1);
X}	/* end of _lread */
X
X/*+-------------------------------------------------------------------------
X	lread_ignore(rtime)
X
X  Reads from the ACU until it finds a valid response (found in
X  DCE_results), a numeric result code (e.g., S-register value), or times
X  out after rtime seconds.  The numeric response feature is designed
X  for Hayes-style DCEs and may not be useful for other DCE types
X
X  Returns: DCE_RESULT code, numeric result + 128, or -1 on timeout or error
X--------------------------------------------------------------------------*/
Xlong
Xlread_ignore(rtime)
Xint rtime;
X{
X	return(_lread(rtime,1));
X}	/* end of lread_ignore */
X
X/*+-------------------------------------------------------------------------
X	lread(rtime)
X
X  Same as lread_ignore, but does not return on timeout or error
X--------------------------------------------------------------------------*/
Xlong
Xlread(rtime)
Xint rtime;
X{
Xint rtn = _lread(rtime,0);
X	if(rtn < 0)
X		myexit(RC_FAIL | RCE_TIMOUT);
X	return(rtn);
X}	/* end of lread */
X
X/*+-------------------------------------------------------------------------
X	lflush() - flushes input clists for DCE
X--------------------------------------------------------------------------*/
Xlflush()
X{
X	ioctl(fddce,TCFLSH,0);
X}	/* end of lflush */
X
X/*+-----------------------------------------------------------------------
X	_lputc(lchar) -- write char to comm line
X------------------------------------------------------------------------*/
Xvoid
X_lputc(lchar)
Xchar lchar;
X{
X	write(fddce,&lchar,1);
X	DEBUG(6,"%s",make_printable(lchar));
X}	/* end of _lputc */
X
X/*+-----------------------------------------------------------------------
X	_lputc_paced(pace_msec,lchar) -- write char to comm line with pacing
X------------------------------------------------------------------------*/
Xvoid
X_lputc_paced(pace_msec,lchar)
Xregister long pace_msec;
Xregister char lchar;
X{
X	_lputc(lchar);
X	if(pace_msec)
X		nap(pace_msec);
X}	/* end of _lputc_paced */
X
X/*+-----------------------------------------------------------------------
X	_lputs(string) -- write string to comm line
X------------------------------------------------------------------------*/
Xvoid
X_lputs(string)
Xregister char *string;
X{
X	while(*string)
X		_lputc(*string++);
X}
X
X/*+-----------------------------------------------------------------------
X	_lputs_paced(pace_msec,string) -- write string to comm line
X  with time between each character 
X------------------------------------------------------------------------*/
Xvoid
X_lputs_paced(pace_msec,string)
Xregister long pace_msec;
Xregister char *string;
X{
X	while(*string)
X		_lputc_paced(pace_msec,*string++);
X
X}	/* end of _lputs_paced */
X
X/*+-------------------------------------------------------------------------
X	lwrite(str) - output string to dce_name
X  Returns:	0 on completion, -1 on write errors.
X--------------------------------------------------------------------------*/
Xlwrite(str)
Xregister char *str;
X{
X
X	nap(200L);
X	DEBUG(6,"Sent DCE %s","<<");
X	_lputs_paced(DCE_write_pace_msec,str);
X	DEBUG(6,">>-%s\n","SUCCESS");
X	ioctl(fddce,TCSETAW,&dce_termio);	/* wait for I/O to drain */
X	return(0);
X
X}	/* end of lwrite */
X
X/*+-------------------------------------------------------------------------
X	ltoggleDTR(msec) - drop DTR, pause, raise DTR
X
XIf msec != 0, drop DTR for that period of time, else DCE_DTR_low_msec
XThis routine trusts that the DTE has already been opened and ioctl'ed
Xonce and that no error checking need be done; this may not catch all
Xchanges in the universe, but the assumption is not naive
X--------------------------------------------------------------------------*/
XltoggleDTR(msec)
Xlong msec;
X{
Xstruct termio temp;
X
X	/*
X	 * drop DTR and pause a while
X	 */
X	temp = dce_termio;
X	temp.c_cflag &= ~CBAUD;		/* use B0 */
X	ioctl(fddce,TCSETA,&temp);	/* drop DTR */
X	nap((msec) ? msec : 300L);
X
X	/*
X	 * raise DTR and pause a while
X	 */
X	ioctl(fddce,TCSETA,&dce_termio);	/* raise DTR */
X	if(DCE_DTR_high_msec)
X		nap(DCE_DTR_high_msec);
X
X}	/* end of ltoggleDTR */
X
X/*+-------------------------------------------------------------------------
X	call_ungetty(call_type)
X
Xtype: 'a' - acquire dce_name
X      't' - test to see if dce_name should be returned
X      'r' - return dce_name
X
XThis function is a no-op in HDB UUCP versions
X--------------------------------------------------------------------------*/
Xcall_ungetty(call_type)
Xchar call_type;
X{
X#if defined(HDB_UUCP)
X	switch(call_type)
X	{
X		case 'a': return(UG_NOTENAB);		/* simulate complete success */
X		case 't': return(UG_RESTART);		/* simulate need for re-setup */
X		case 'r': return(0);				/* simulate complete success */
X	}
X	return(0);
X#else /* HDB_UUCP */
Xint itmp;
Xint pid;
Xunsigned int wait_status;
Xstatic char *ungetty = "/usr/lib/uucp/ungetty";
X
X	if((pid = fork()) == 0)
X	{
X		if(Debug >= 5)
X			ff(se,"%s: %s %s called\n",*gargv,ungetty,dce_name);
X		switch(call_type)
X		{
X			case 'a':
X				execl(ungetty,"ungetty",dce_name + 5,(char *)0);
X				break;
X			case 't':
X				execl(ungetty,"ungetty","-t",dce_name + 5,(char *)0);
X				break;
X			case 'r':
X				execl(ungetty,"ungetty","-r",dce_name + 5,(char *)0);
X				break;
X		}
X		ff(se,"%s exec error %d (%s)\n",ungetty,errno,sys_errlist[errno]);
X		_exit(-1);
X	}
X
X	while(((itmp = wait(&wait_status)) != pid) && itmp != -1)
X		;
X
X	if(Debug >= 6)
X		ff(se,"%s pid %d exit status 0x%04x\n",ungetty,itmp,wait_status);
X
X	return((wait_status >> 8) & 0xFF);
X#endif /* HDB_UUCP */
X}	/* end of call_ungetty */
X
X/*+-----------------------------------------------------------------------
X	display_termio(ttt)
SHAR_EOF
true || echo 'restore of gendial/gendial.c failed'
fi
echo 'End of ecu310 part 27'
echo 'File gendial/gendial.c is continued in part 28'
echo 28 > _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.


