home *** CD-ROM | disk | FTP | other *** search
- From: wht@n4hgf.atl.ga.us (Warren Tucker)
- Newsgroups: comp.sources.misc
- Subject: v42i121: ecu - ECU Asynchronous Communications v3.30, Part23/37
- Date: 24 May 1994 09:07:16 -0500
- Organization: Sterling Software
- Sender: kent@sparky.sterling.com
- Approved: kent@sparky.sterling.com
- Message-ID: <2rt1mk$d3p@sparky.sterling.com>
- X-Md4-Signature: 92b8b557062140cf16f0c57cf52d4c77
-
- Submitted-by: wht@n4hgf.atl.ga.us (Warren Tucker)
- Posting-number: Volume 42, Issue 121
- Archive-name: ecu/part23
- Environment: SCO,SCOXENIX,MOTOROLA,HP-UX,LINUX,NetBSD,SUNOS,SYSVR4,SOLARIS2
- Supersedes: ecu: Volume 32, Issue 36-75
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then feed it
- # into a shell via "sh file" or similar. To overwrite existing files,
- # type "sh file -c".
- # Contents: ecu330/gendial/dceT3000.c ecu330/gendial/dceTBPlus.c
- # ecu330/gendial/dialer.h ecu330/z/zmodem.c
- # Wrapped by kent@sparky on Mon May 23 13:40:58 1994
- PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
- echo If this archive is complete, you will see the following message:
- echo ' "shar: End of archive 23 (of 37)."'
- if test -f 'ecu330/gendial/dceT3000.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'ecu330/gendial/dceT3000.c'\"
- else
- echo shar: Extracting \"'ecu330/gendial/dceT3000.c'\" \(17766 characters\)
- sed "s/^X//" >'ecu330/gendial/dceT3000.c' <<'END_OF_FILE'
- X/*+-------------------------------------------------------------------------
- X dceT3000.c - DCE-specific portion of generic SCO UUCP dialer
- X Driver for Telebit T3000
- X wht@n4hgf.atl.ga.us
- X
- Xdialing registers for V.32
- X
- XT3000SA - Version LA3.00 - Active Configuration
- X B1 E0 L2 M0 P Q2 V1 X12 Y0
- X&C1 &D2 &G0 &J0 &L0 &Q0 &R3 &S0 &T4 &X0
- XS000=0 S001=0 S002:1 S003=13 S004=10 S005=8 S006=2 S007=40
- XS008=2 S009=6 S010=14 S011:50 S012=50 S018=0 S025=5 S026=1
- XS038=0 S041=0 S045=0 S046=0 S047=4 S048:1 S050:6 S051:252
- XS056=17 S057=19 S058:2 S059=0 S060=0 S061=1 S062:25 S063=0
- XS064=0 S068=255 S069=0 S090=0 S093=8 S094=1 S100=0 S102=0
- XS104=0 S105=1 S111=255 S112=1 S180=2 S181=1 S183=25 S190=1
- XS253=10 S254=255 S255=255
- X--------------------------------------------------------------------------*/
- X/*+:EDITS:*/
- X/*:05-04-1994-04:39-wht@n4hgf-ECU release 3.30 */
- X/*:09-10-1992-13:59-wht@n4hgf-ECU release 3.20 */
- X/*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA */
- X/*:05-11-1992-17:51-wht@gyro-convert dceT2500 for a preliminary version */
- 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 lflash_DTR(),
- 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 = 1000L;
- X
- X/*
- X * DCE_write_pace_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 = 10;
- X
- X/*
- X * DCE_name - short name for DCE
- X * DCE_revision - revision number for this module
- X */
- Xchar *DCE_name = "Telebit T3000";
- Xchar *DCE_revision = "x1.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
- 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 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 rDialing 7
- X#define rConnect300 ( 300 | rfConnect)
- X#define rConnect1200 ( 1200 | rfConnect)
- X#define rConnect2400 ( 1200 | rfConnect)
- X#define rConnect9600 ( 9600 | rfConnect)
- X#define rConnect19200 ( 19200 | rfConnect)
- X#define rConnect38400 ( 38400 | 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 {"DIALING", rDialing},
- X {"RRING", rRring},
- X {"CONNECT 300", rConnect300},
- X {"CONNECT 1200", rConnect1200},
- X {"CONNECT 2400", rConnect2400},
- X {"CONNECT 9600", rConnect9600},
- X {"CONNECT 19200", rConnect19200},
- X {"CONNECT 38400", rConnect38400},
- X {(char *)0, -1} /* end table */
- X};
- X
- X#include "tbit.sync.h"
- 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:
- X return (B110);
- X case 300:
- X return (B300);
- X case 1200:
- X return (B1200);
- X case 2400:
- X return (B2400);
- X case 9600:
- X return (B9600);
- X
- X#if defined(B19200)
- X case 19200:
- X return (B19200);
- X#else
- X#ifdef EXTA
- X case 19200:
- X return (EXTA);
- X#endif
- X#endif
- X
- X#if defined(B38400)
- X case 38400:
- X return (B38400);
- X#else
- X#ifdef EXTB
- X case 38400:
- X return (EXTB);
- X#endif
- X#endif
- X
- X }
- X myexit(RC_FAIL | RCE_SPEED);
- X#if defined(OPTIMIZE) || defined(__OPTIMIZE__) /* don't complain */
- X return (0); /* keep gcc from complaining about no rtn at
- X * end */
- X#endif
- X} /* end of DCE_baud_to_CBAUD */
- X
- X/*+-------------------------------------------------------------------------
- X init_T3000() - init T3000 from scratch, assuming nothing
- X
- X reset to factory defaults, then set
- X E0 no local echo in command mode
- X &C1 DCD follows carrier
- X &D2 disconnect on DTR loss
- X M0 speaker off
- X Q2 generate reult codes only for originating use
- X V1 verbal result codes
- X X12 fullest result code set
- X S0=1 answer on first ring
- X S2=255 escape to unusual value
- X S11=50 50 msec DTMF timing
- X S45=0 disable 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 S58=2 DTE uses CTS/RTS flow control.
- X S61=0 send BREAK (rather than go to command mode)
- X S62=25 BREAK duration 250 msec (default is 150)
- X S63=0 send BREAK in sequence
- X S64=1 ignore characters sent by DTE while answering
- X S66=0 don't lock interface speed, just go with the flow.
- X S69=0 omit XON/XOFF flow control
- X S68=255 DCE uses whatever flow control DTE uses
- X S111=255 accept any protocol
- X
- XThe nvram is set to factory + E0 Q0 &C1 &D2 S51=252
- X--------------------------------------------------------------------------*/
- Xvoid
- Xinit_T3000()
- X{
- X register itmp;
- X int maxretry = 4;
- X char *init0 = "AT&F E0 Q0 &C1 &D2 S51=252 &w M0 Q2 V1 X12\r";
- X char *init1 = "ATS0=1 S2=255 S11=50 S45=0 S48=1 S50=0 \r";
- X char *init2 = "ATS58=2 S61=0 S62=25 S63=0 S62=25 S64=1 S66=0 S68=255 S111=255\r";
- X
- X DEBUG(1, "--> initializing %s on ", DCE_name);
- X DEBUG(1, "%s\n", dce_name);
- X
- X lflash_DTR();
- X sync_Telebit();
- X
- X /*
- X * set to factory default (bless them for this command) and a few
- X * initial beachhead values
- X */
- X for (itmp = 0; itmp < maxretry; itmp++)
- X {
- X lwrite(init0);
- X if (lread(5) == 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(5) == 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(5) == 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_T3000 */
- 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(4, "--> hanging up %s\n", dce_name);
- X init_T3000();
- X
- X} /* end of DCE_hangup */
- X
- X/*+-------------------------------------------------------------------------
- X DCE_dial(telno_str) - 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
- XT3000-specific comments:
- X S0=0 dont allow connect while dialing
- X S63=0 pass BREAK signal to remote modem in sequence
- X S64=0 abort dialing if characters sent by DTE
- X S66=1 lock the interface speed
- X--------------------------------------------------------------------------*/
- Xint
- XDCE_dial(telno_str)
- Xchar *telno_str;
- X{
- X char cmd[128];
- X char phone[50];
- X int s111_set = 0;
- X int timeout;
- X int result;
- X int rrings = 0;
- X long then;
- X long now;
- X char *cptr;
- X char *dialout_default = "AT S0=0 S7=40 S63=0 S64=0 S66=1\r";
- X
- X#define MDVALID "0123456789FfKkMmNnRrSsUuWwXxVv*#,!/()-"
- X#ifdef WHT
- X#define RRING_MAX 3
- X#else
- X#define RRING_MAX 6
- X#endif
- X
- X/* preliminary setup */
- X translate("=,-,", telno_str);
- X if (strspn(telno_str, MDVALID) != strlen(telno_str))
- X {
- X DEBUG(1, "phone number has invalid characters\n", 0);
- X return (RC_FAIL | RCE_PHNO);
- X }
- X if (decode_phone_number(telno_str, 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['F' - 'A'])
- X {
- X DEBUG(5, "XON/XOFF FLOW CONTROL requested\n", 0);
- X strcat(cmd, "S69=2");
- 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
- 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 init_T3000();
- X
- X DEBUG(2, "--> issuing default setup command\n", 0);
- X lwrite(dialout_default);
- X if (lread(5) != 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(2, "--> issuing custom setup cmd\n", 0);
- X strcat(cmd, "\r");
- X lwrite(cmd);
- X if (lread(5) != 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(4, "wait for connect = %d seconds\n", timeout);
- X
- X if (Debug > 8)
- X {
- X lwrite("AT&V\r");
- X lread_ignore(40);
- 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)
- X ? "remote system" : telno_str);
- 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 lwrite(cmd);
- X
- X/* indicate non-root can see DTE->DCE traffic */
- X secure = 0;
- X
- X/* wait for connect */
- X WAIT_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 case rDialing:
- 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 clean 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: */
- END_OF_FILE
- if test 17766 -ne `wc -c <'ecu330/gendial/dceT3000.c'`; then
- echo shar: \"'ecu330/gendial/dceT3000.c'\" unpacked with wrong size!
- fi
- # end of 'ecu330/gendial/dceT3000.c'
- fi
- if test -f 'ecu330/gendial/dceTBPlus.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'ecu330/gendial/dceTBPlus.c'\"
- else
- echo shar: Extracting \"'ecu330/gendial/dceTBPlus.c'\" \(18169 characters\)
- sed "s/^X//" >'ecu330/gendial/dceTBPlus.c' <<'END_OF_FILE'
- 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.atl.ga.us
- X--------------------------------------------------------------------------*/
- X/*+:EDITS:*/
- X/*:05-04-1994-04:39-wht@n4hgf-ECU release 3.30 */
- X/*:09-10-1992-13:59-wht@n4hgf-ECU release 3.20 */
- X/*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA */
- X/*:02-10-1992-00:27-wht@n4hgf-improved sync_Telebit */
- X/*:02-02-1992-18:01-root@n4hgf-proper ordering of DCE_result entries */
- X/*:01-26-1992-15:30-wht@n4hgf-gendial 1.2 for ecu 3.20- better hangup */
- 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 lflash_DTR(),
- 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_pace_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 = 10;
- 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.30";
- 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
- 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 * If one possible result is an "early substring" of another, like
- X * "CONNECT" is of "CONNECT 1200", then put such results later in the
- X * table than the larger result.
- X *
- 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#include "tbit.sync.h"
- 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:
- X return (B110);
- X case 300:
- X return (B300);
- X case 1200:
- X return (B1200);
- X case 2400:
- X return (B2400);
- X case 9600:
- X return (B9600);
- X
- X#if defined(B19200)
- X case 19200:
- X return (B19200);
- X#else
- X#ifdef EXTA
- X case 19200:
- X return (EXTA);
- X#endif
- X#endif
- X
- X#if defined(B38400)
- X case 38400:
- X return (B38400);
- X#else
- X#ifdef EXTB
- X case 38400:
- X return (EXTB);
- X#endif
- X#endif
- X
- X }
- X myexit(RC_FAIL | RCE_SPEED);
- X#if defined(OPTIMIZE) || defined(__OPTIMIZE__) /* don't complain */
- X return (0); /* keep gcc from complaining about no rtn at
- X * end */
- X#endif
- X} /* end of DCE_baud_to_CBAUD */
- 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=255 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 DTR low: drop connection and reset to nvram
- 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{
- X register itmp;
- X int maxretry = 4;
- X char *init0 = "AT~&FE0F1M0Q4V1X3S52=2\r";
- X char *init1 = "ATS0=1S2=255S11=50S45=1S48=1S50=0S51=252S53=1S54=3\r";
- X char *init2 = "ATS55=0S58=2S64=1S66=0S68=255S92=1S95=0S110=255S111=255\r";
- X
- X DEBUG(1, "--> initializing %s\n", dce_name);
- X lflash_DTR();
- X sync_Telebit();
- X
- X /*
- X * set to factory default (bless them for this command) and a few
- X * initial beachhead values
- X */
- X for (itmp = 0; itmp < maxretry; itmp++)
- X {
- X lwrite(init0);
- X if (lread(5) == 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(5) == 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(5) == 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 DEBUG(1, "--> reseting %s\n", dce_name);
- X#ifdef TRUSTING
- X lflash_DTR();
- 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_str) - 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_str)
- Xchar *telno_str;
- X{
- X char cmd[128];
- X char phone[50];
- X int s111_set = 0;
- X int timeout;
- X int result;
- X int rrings = 0;
- X long then;
- X long now;
- X char *cptr;
- X char *dialout_default = "ATS0=0S7=40S54=3S64=0S66=1S110=0\r";
- X
- X#define MDVALID "0123456789CcEeFfKkMmNnPpRrSsUuWwXx*#,!/()-"
- X
- X/* preliminary setup */
- X translate("=,-,", telno_str);
- X if (strspn(telno_str, MDVALID) != strlen(telno_str))
- X {
- X DEBUG(1, "phone number has invalid characters\n", 0);
- X return (RC_FAIL | RCE_PHNO);
- X }
- X if (decode_phone_number(telno_str, 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 DEBUG(6, "--> issuing default setup command\n", 0);
- X sync_Telebit();
- X lwrite(dialout_default);
- X if (lread(5) != 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(5) != 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, "wait 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)
- X ? "remote system" : telno_str);
- 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 */
- X WAIT_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: */
- END_OF_FILE
- if test 18169 -ne `wc -c <'ecu330/gendial/dceTBPlus.c'`; then
- echo shar: \"'ecu330/gendial/dceTBPlus.c'\" unpacked with wrong size!
- fi
- # end of 'ecu330/gendial/dceTBPlus.c'
- fi
- if test -f 'ecu330/gendial/dialer.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'ecu330/gendial/dialer.h'\"
- else
- echo shar: Extracting \"'ecu330/gendial/dialer.h'\" \(6114 characters\)
- sed "s/^X//" >'ecu330/gendial/dialer.h' <<'END_OF_FILE'
- 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/*:05-04-1994-04:39-wht@n4hgf-ECU release 3.30 */
- X/*:09-10-1992-13:59-wht@n4hgf-ECU release 3.20 */
- X/*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA */
- X/*:03-29-1992-12:47-cma@ifsbd-added <sys/filio.h> */
- X/*:03-29-1992-12:30-cma@ifsbd-added <sys/time.h> */
- X/*:01-26-1992-15:30-wht@n4hgf-gendial 1.2 for ecu 3.20- better hangup */
- 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 <sys/timeb.h>
- X#include <sys/time.h>
- X#include <termio.h>
- X#include <time.h>
- X#include <pwd.h>
- X
- X#ifdef sun
- X#define BSD
- X#include <sys/filio.h>
- X#endif
- 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 dce_fd; /* 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 DCE
- X * traffic */
- 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#define RC_BAUD 0x0f /* CBAUD connected at (0=same as dialed
- X * 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 2048
- 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}
- XDCE_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);
- Xint _lread(int, int);
- Xint lread_ignore(int);
- Xint lread(int);
- Xvoid lflush(void);
- Xvoid _lputc(char);
- Xvoid _lputc_paced(long, char);
- Xvoid _lputs(char *);
- Xvoid _lputs_paced(long, char *);
- Xvoid lwrite(char *);
- Xvoid lflash_DTR(void);
- Xint call_ungetty(char);
- Xvoid display_termio(struct termio *, char *);
- Xint open_dce(void);
- Xint main(int, char **);
- X
- 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();
- Xint _lread();
- Xint lread_ignore();
- Xint lread();
- Xvoid lflush();
- Xvoid _lputc();
- Xvoid _lputc_paced();
- Xvoid _lputs();
- Xvoid _lputs_paced();
- Xvoid lwrite();
- Xvoid lflash_DTR();
- Xint call_ungetty();
- Xvoid display_termio();
- Xint open_dce();
- Xint main();
- X
- X#endif
- X
- X/* vi: set tabstop=4 shiftwidth=4: */
- X/* end of dialer.h */
- END_OF_FILE
- if test 6114 -ne `wc -c <'ecu330/gendial/dialer.h'`; then
- echo shar: \"'ecu330/gendial/dialer.h'\" unpacked with wrong size!
- fi
- # end of 'ecu330/gendial/dialer.h'
- fi
- if test -f 'ecu330/z/zmodem.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'ecu330/z/zmodem.c'\"
- else
- echo shar: Extracting \"'ecu330/z/zmodem.c'\" \(18074 characters\)
- sed "s/^X//" >'ecu330/z/zmodem.c' <<'END_OF_FILE'
- X#if defined(WHT) && !defined(SHOW_ZHDR_TYPE)
- X#define SHOW_ZHDR_TYPE
- X#endif
- X/*+-------------------------------------------------------------------------
- X zmodem.c - ZMODEM protocol primitives
- X based on code by Chuck Forsberg
- X
- X Defined functions:
- X noxrd7()
- X rclhdr(hdr)
- X stohdr(pos)
- X zdlread()
- X zgeth1()
- X zgethdr(hdr,eflag)
- X zgethex()
- X zputhex(c)
- X zrbhdr(hdr)
- X zrbhdr32(hdr)
- X zrdat32(buf,length)
- X zrdata(buf,length)
- X zrhhdr(hdr)
- X zsbh32(type,hdr)
- X zsbhdr(type,hdr)
- X zsda32(buf,length,frameend)
- X zsdata(buf,length,frameend)
- X zsendline(c)
- X zshhdr(type,hdr)
- X
- X--------------------------------------------------------------------------*/
- X/*+:EDITS:*/
- X/*:05-04-1994-04:40-wht@n4hgf-ECU release 3.30 */
- X/*:01-25-1994-17:02-wht@n4hgf-robertl corrections + mv extern crctab to hdr */
- X/*:09-10-1992-14:00-wht@n4hgf-ECU release 3.20 */
- X/*:08-22-1992-15:39-wht@n4hgf-ECU release 3.20 BETA */
- X/*:07-25-1991-12:59-wht@n4hgf-ECU release 3.10 */
- X/*:08-14-1990-20:41-wht@n4hgf-ecu3.00-flush old edit history */
- X
- X#include "zmodem.h"
- X
- Xextern char s128[];
- Xextern int Zctlesc;
- Xextern int Zmodem;
- Xextern unsigned long Baudrate;
- X
- Xint Rxtimeout = 100; /* Tenths of seconds to wait for something */
- X
- X#if !defined(UNSL)
- X#define UNSL unsigned
- X#endif
- X
- Xstatic lastsent; /* Last char we sent */
- Xstatic evenp; /* Even parity seen on header */
- X
- X/* Globals used by ZMODEM functions */
- Xchar Attn[ZATTNLEN + 1]; /* Attention string rx sends to tx on err */
- Xchar Rxhdr[4]; /* Received header */
- Xchar Txhdr[4]; /* Transmitted header */
- Xint Crc32; /* Display flag indicating 32 bit CRC being
- X * received */
- Xint Crc32t; /* Display flag indicating 32 bit CRC being
- X * sent */
- Xint Rxcount; /* Count of data bytes received */
- Xint Rxframeind; /* ZBIN ZBIN32,or ZHEX type of frame received */
- Xint Rxtype; /* Type of header received */
- Xint Txfcs32; /* TURE means send binary frames with 32 bit
- X * FCS */
- Xint Zrwindow; /* RX window size (controls garbage count) */
- Xlong Rxpos; /* Received file position */
- Xlong Txpos; /* Transmitted file position */
- X
- Xchar *frametypes[] =
- X{
- X "Carrier Lost", /* -3 */
- X "TIMEOUT", /* -2 */
- X "ERROR", /* -1 */
- X/* #define FTOFFSET 3 moved to zmodem.h */
- X "ZRQINIT",
- X "ZRINIT",
- X "ZSINIT",
- X "ZACK ",
- X "ZFILE",
- X "ZSKIP",
- X "ZNAK ",
- X "ZABORT",
- X "ZFIN ",
- X "ZRPOS",
- X "ZDATA",
- X "ZEOF ",
- X "ZFERR",
- X "ZCRC ",
- X "ZCHALLENGE",
- X "ZCOMPL",
- X "ZCAN ",
- X "ZFREECNT",
- X "ZCOMMAND",
- X "ZSTDERR",
- X "xxxxx"
- X#define FRTYPES 22 /* Total number of frame types in this array */
- X /* not including psuedo negative entries */
- X};
- X
- X/*
- X * Send character c with ZMODEM escape sequence encoding.
- X * Escape XON,XOFF. Escape CR following @ (Telenet net escape)
- X */
- Xvoid
- Xzsendline(c)
- Xint c;
- X{
- X
- X /* Quick check for non control characters */
- X if (c & 0140)
- X xsendline(lastsent = c);
- X else
- X {
- X switch (c &= 0377)
- X {
- X case ZDLE:
- X xsendline(ZDLE);
- X xsendline(lastsent = (c ^= 0100));
- X break;
- X case 015:
- X case 0215:
- X if (!Zctlesc && (lastsent & 0177) != '@')
- X goto sendit;
- X /* **** FALL THRU TO **** */
- X case 020:
- X case 021:
- X case 023:
- X case 0220:
- X case 0221:
- X case 0223:
- X xsendline(ZDLE);
- X c ^= 0100;
- X sendit:
- X xsendline(lastsent = c);
- X break;
- X default:
- X if (Zctlesc && !(c & 0140))
- X {
- X xsendline(ZDLE);
- X c ^= 0100;
- X }
- X xsendline(lastsent = c);
- X }
- X }
- X}
- X
- Xstatic char masked[] = "8 bit transparent path required";
- Xstatic char badcrc[] = "Bad CRC";
- X
- X/* Send ZMODEM CRC-32 binary header hdr of type type */
- Xvoid
- Xzsbh32(type, hdr)
- Xint type;
- Xregister char *hdr;
- X{
- X register int n;
- X register UNSL long crc;
- X
- X sprintf(s128,
- X#ifdef SHOW_ZHDR_TYPE
- X "B32 %s %ld",
- X#else
- X "hdr %s %ld",
- X#endif
- X frametypes[type + FTOFFSET], rclhdr(hdr));
- X report_last_txhdr(s128, 0);
- X report_tx_ind(1);
- X xsendline(ZBIN32);
- X zsendline(type);
- X crc = 0xFFFFFFFFL;
- X crc = UPDC32(type, crc);
- X
- X for (n = 4; --n >= 0; ++hdr)
- X {
- X crc = UPDC32((0377 & *hdr), crc);
- X zsendline(*hdr);
- X }
- X crc = ~crc;
- X for (n = 4; --n >= 0;)
- X {
- X zsendline((int)crc);
- X crc >>= 8;
- X }
- X report_tx_ind(0);
- X}
- X
- X/* Send ZMODEM binary header hdr of type type */
- Xvoid
- Xzsbhdr(type, hdr)
- Xint type;
- Xregister unsigned char *hdr;
- X{
- X register int n;
- X register unsigned crc;
- X
- X xsendline(ZPAD);
- X xsendline(ZDLE);
- X
- X if (Crc32t = Txfcs32)
- X zsbh32(type, hdr);
- X else
- X {
- X sprintf(s128,
- X#ifdef SHOW_ZHDR_TYPE
- X "B16 %s %ld",
- X#else
- X "hdr %s %ld",
- X#endif
- X frametypes[type + FTOFFSET], rclhdr(hdr));
- X report_last_txhdr(s128, 0);
- X report_tx_ind(1);
- X
- X xsendline(ZBIN);
- X zsendline(type);
- X crc = updcrc(type, 0);
- X
- X for (n = 4; --n >= 0; ++hdr)
- X {
- X zsendline(*hdr);
- X crc = updcrc(*hdr, crc);
- X }
- X crc = updcrc(0, updcrc(0, crc));
- X zsendline(crc >> 8);
- X zsendline(crc);
- X report_tx_ind(0);
- X }
- X if (type != ZDATA)
- X flushline();
- X}
- X
- X/*
- X * Send binary array buf of length length,with ending ZDLE sequence frameend
- X */
- Xstatic char *Zendnames[] =
- X{"ZCRCE", "ZCRCG", "ZCRCQ", "ZCRCW"};
- X
- Xvoid
- Xzsda32(buf, length, frameend)
- Xregister char *buf;
- Xint length;
- Xint frameend;
- X{
- X register int c;
- X register UNSL long crc;
- X
- X sprintf(s128,
- X#ifdef SHOW_ZHDR_TYPE
- X "D32 %s %d",
- X#else
- X "data %s %d",
- X#endif
- X Zendnames[frameend - ZCRCE & 3], length);
- X report_last_txhdr(s128, 0);
- X report_tx_ind(1);
- X
- X crc = 0xFFFFFFFFL;
- X for (; --length >= 0; ++buf)
- X {
- X c = *buf & 0377;
- X if (c & 0140)
- X xsendline(lastsent = c);
- X else
- X zsendline(c);
- X crc = UPDC32(c, crc);
- X }
- X xsendline(ZDLE);
- X xsendline(frameend);
- X crc = UPDC32(frameend, crc);
- X
- X crc = ~crc;
- X for (length = 4; --length >= 0;)
- X {
- X zsendline((int)crc);
- X crc >>= 8;
- X }
- X report_tx_ind(0);
- X}
- X
- Xvoid
- Xzsdata(buf, length, frameend)
- Xregister unsigned char *buf;
- Xint length;
- Xint frameend;
- X{
- X register unsigned short crc;
- X
- X if (Crc32t)
- X zsda32(buf, length, frameend);
- X else
- X {
- X sprintf(s128,
- X#ifdef SHOW_ZHDR_TYPE
- X "D16 %s %d",
- X#else
- X "data %s %d",
- X#endif
- X Zendnames[frameend - ZCRCE & 3], length);
- X report_last_txhdr(s128, 0);
- X report_tx_ind(1);
- X crc = 0;
- X for (; --length >= 0; ++buf)
- X {
- X zsendline(*buf);
- X crc = updcrc(*buf, crc);
- X }
- X xsendline(ZDLE);
- X xsendline(frameend);
- X crc = updcrc(frameend, crc);
- X
- X crc = updcrc(0, updcrc(0, crc));
- X zsendline(crc >> 8);
- X zsendline(crc);
- X report_tx_ind(0);
- X }
- X if (frameend == ZCRCW)
- X {
- X xsendline(XON);
- X flushline();
- X }
- X
- X}
- X
- X/* Send a byte as two hex digits */
- Xvoid
- Xzputhex(c)
- Xregister int c;
- X{
- X static char digits[] = "0123456789abcdef";
- X
- X sendline(digits[(c & 0xF0) >> 4]);
- X sendline(digits[(c) & 0xF]);
- X}
- X
- Xvoid
- Xzshhdr(type, hdr)
- Xint type;
- Xregister unsigned char *hdr;
- X{
- X register int n;
- X register unsigned short crc;
- X
- X sprintf(s128,
- X#ifdef SHOW_ZHDR_TYPE
- X "HEX %s %ld",
- X#else
- X "hdr %s %ld",
- X#endif
- X frametypes[type + FTOFFSET], rclhdr(hdr));
- X report_last_txhdr(s128, 0);
- X report_tx_ind(1);
- X sendline(ZPAD);
- X sendline(ZPAD);
- X sendline(ZDLE);
- X sendline(ZHEX);
- X zputhex(type);
- X Crc32t = 0;
- X
- X crc = updcrc(type, 0);
- X for (n = 4; --n >= 0; ++hdr)
- X {
- X zputhex(*hdr);
- X crc = updcrc(*hdr, crc);
- X/* crc = updcrc((0377 & *hdr),crc); original - wht */
- X }
- X crc = updcrc(0, updcrc(0, crc));
- X zputhex(crc >> 8);
- X zputhex(crc);
- X
- X /* Make it printable on remote machine */
- X sendline(015);
- X sendline(012);
- X
- X /*
- X * Uncork the remote in case a fake XOFF has stopped data flow
- X */
- X if (type != ZFIN && type != ZACK)
- X sendline(021);
- X flushline();
- X report_tx_ind(0);
- X}
- X
- X/*
- X * Receive array buf of max length with ending ZDLE sequence
- X * and CRC. Returns the ending character or error code.
- X * NB: On errors may store length+1 bytes!
- X */
- Xint
- Xzrdat32(buf, length)
- Xregister char *buf;
- Xint length;
- X{
- X register int c;
- X register UNSL long crc;
- X register char *end;
- X register int d;
- X
- X report_rx_ind(1);
- X crc = 0xFFFFFFFFL;
- X Rxcount = 0;
- X end = buf + length;
- X while (buf <= end)
- X {
- X if ((c = zdlread()) & ~0377)
- X {
- X crcfoo:
- X switch (c)
- X {
- X case GOTCRCE:
- X case GOTCRCG:
- X case GOTCRCQ:
- X case GOTCRCW:
- X d = c;
- X c &= 0377;
- X crc = UPDC32(c, crc);
- X if ((c = zdlread()) & ~0377)
- X goto crcfoo;
- X crc = UPDC32(c, crc);
- X if ((c = zdlread()) & ~0377)
- X goto crcfoo;
- X crc = UPDC32(c, crc);
- X if ((c = zdlread()) & ~0377)
- X goto crcfoo;
- X crc = UPDC32(c, crc);
- X if ((c = zdlread()) & ~0377)
- X goto crcfoo;
- X crc = UPDC32(c, crc);
- X if (crc != 0xDEBB20E3L)
- X {
- X report_str(badcrc, 0);
- X report_rx_ind(0);
- X return (ERROR);
- X }
- X Rxcount = length - (end - buf);
- X report_rxblklen(Rxcount);
- X sprintf(s128,
- X#ifdef SHOW_ZHDR_TYPE
- X "D32 %s %d",
- X#else
- X "data %s %d",
- X#endif
- X Zendnames[d - GOTCRCE & 3], Rxcount);
- X report_last_rxhdr(s128, 0);
- X report_rx_ind(0);
- X return (d);
- X case GOTCAN:
- X report_str("Sender Canceled", 1);
- X report_rx_ind(0);
- X return (ZCAN);
- X case TIMEOUT:
- X report_str("TIMEOUT", 0);
- X report_rx_ind(0);
- X return (c);
- X default:
- X report_str("Bad data subpacket", 0);
- X report_rx_ind(0);
- X return (c);
- X }
- X }
- X *buf++ = c;
- X crc = UPDC32(c, crc);
- X }
- X report_str("Data subpacket too long", 0);
- X report_rx_ind(0);
- X return (ERROR);
- X}
- X
- Xint
- Xzrdata(buf, length)
- Xregister char *buf;
- Xint length;
- X{
- X register int c;
- X register unsigned short crc;
- X register char *end;
- X register int d;
- X
- X if (Rxframeind == ZBIN32)
- X return (zrdat32(buf, length));
- X
- X report_rx_ind(1);
- X crc = Rxcount = 0;
- X end = buf + length;
- X while (buf <= end)
- X {
- X if ((c = zdlread()) & ~0377)
- X {
- X crcfoo:
- X switch (c)
- X {
- X case GOTCRCE:
- X case GOTCRCG:
- X case GOTCRCQ:
- X case GOTCRCW:
- X crc = updcrc(((d = c) & 0377), crc);
- X if ((c = zdlread()) & ~0377)
- X goto crcfoo;
- X crc = updcrc(c, crc);
- X if ((c = zdlread()) & ~0377)
- X goto crcfoo;
- X crc = updcrc(c, crc);
- X if (crc & 0xFFFF)
- X {
- X report_str(badcrc, 0);
- X report_rx_ind(0);
- X return (ERROR);
- X }
- X Rxcount = length - (end - buf);
- X report_rxblklen(Rxcount);
- X sprintf(s128,
- X#ifdef SHOW_ZHDR_TYPE
- X "D16 %s %d",
- X#else
- X "data %s %d",
- X#endif
- X Zendnames[d - GOTCRCE & 3], Rxcount);
- X report_last_rxhdr(s128, 0);
- X report_rx_ind(0);
- X return (d);
- X case GOTCAN:
- X report_str("Sender Cancelled", 1);
- X report_rx_ind(0);
- X return (ZCAN);
- X case TIMEOUT:
- X report_str("TIMEOUT", 0);
- X report_rx_ind(0);
- X return (c);
- X default:
- X report_str("Bad data subpacket", 0);
- X report_rx_ind(0);
- X return (c);
- X }
- X }
- X *buf++ = c;
- X crc = updcrc(c, crc);
- X }
- X report_str("Data subpacket too long", 0);
- X report_rx_ind(0);
- X return (ERROR);
- X}
- X
- X/*
- X * Read a ZMODEM header to hdr,either binary or hex.
- X * eflag controls local display of non zmodem characters:
- X * 0: no display
- X * 1: display printing characters only
- X * 2: display all non ZMODEM characters
- X * On success,set Zmodem to 1,set Rxpos and return type of header.
- X * Otherwise return negative on error.
- X * Return ERROR instantly if ZCRCW sequence,for fast error recovery.
- X */
- Xint
- Xzgethdr(hdr, eflag)
- Xchar *hdr;
- Xint eflag;
- X{
- X register int c, n, cancount;
- X
- X#ifdef SHOW_ZHDR_TYPE
- X char *hdrtyp = "?";
- X
- X#endif
- X
- X report_rx_ind(1);
- X n = Zrwindow + Baudrate; /* Max bytes before start of frame */
- X Rxframeind = Rxtype = 0;
- X
- X startover:
- X cancount = 5;
- X again:
- X /* Return immediate ERROR if ZCRCW sequence seen */
- X switch (c = readline(Rxtimeout))
- X {
- X case RCDO:
- X case TIMEOUT:
- X goto fifi;
- X case CAN:
- X gotcan:
- X if (--cancount <= 0)
- X {
- X c = ZCAN;
- X goto fifi;
- X }
- X switch (c = readline(1))
- X {
- X case TIMEOUT:
- X goto again;
- X case ZCRCW:
- X c = ERROR;
- X /* **** FALL THRU TO **** */
- X case RCDO:
- X goto fifi;
- X default:
- X break;
- X case CAN:
- X if (--cancount <= 0)
- X {
- X c = ZCAN;
- X goto fifi;
- X }
- X goto again;
- X }
- X /* **** FALL THRU TO **** */
- X default:
- X agn2:
- X if (--n == 0)
- X {
- X report_str("Garbage count exceeded", 1);
- X report_last_rxhdr("Noise", 0);
- X report_rx_ind(0);
- X return (ERROR);
- X }
- X goto startover;
- X case ZPAD | 0200: /* This is what we want. */
- X case ZPAD: /* This is what we want. */
- X evenp = c & 0200;
- X break;
- X }
- X cancount = 5;
- X splat:
- X switch (c = noxrd7())
- X {
- X case ZPAD:
- X goto splat;
- X case RCDO:
- X case TIMEOUT:
- X goto fifi;
- X default:
- X goto agn2;
- X case ZDLE: /* This is what we want. */
- X break;
- X }
- X
- X switch (c = noxrd7())
- X {
- X case RCDO:
- X case TIMEOUT:
- X goto fifi;
- X case ZBIN:
- X Rxframeind = ZBIN;
- X Crc32 = FALSE;
- X c = zrbhdr(hdr);
- X break;
- X case ZBIN32:
- X Crc32 = Rxframeind = ZBIN32;
- X c = zrbhdr32(hdr);
- X break;
- X case ZHEX:
- X Rxframeind = ZHEX;
- X Crc32 = FALSE;
- X c = zrhhdr(hdr);
- X break;
- X case CAN:
- X goto gotcan;
- X default:
- X goto agn2;
- X }
- X Rxpos = hdr[ZP3] & 0377;
- X Rxpos = (Rxpos << 8) + (hdr[ZP2] & 0377);
- X Rxpos = (Rxpos << 8) + (hdr[ZP1] & 0377);
- X Rxpos = (Rxpos << 8) + (hdr[ZP0] & 0377);
- X fifi:
- X switch (c)
- X {
- X case GOTCAN:
- X c = ZCAN;
- X /* **** FALL THRU TO **** */
- X case ZNAK:
- X case ZCAN:
- X case ERROR:
- X case TIMEOUT:
- X case RCDO:
- X sprintf(s128, "Got %s", frametypes[c + FTOFFSET]);
- X report_str(s128, 0);
- X /* **** FALL THRU TO **** */
- X default:
- X#ifdef SHOW_ZHDR_TYPE
- X switch (Rxframeind)
- X {
- X case ZBIN:
- X hdrtyp = "B16";
- X break;
- X case ZBIN32:
- X hdrtyp = "B32";
- X break;
- X case ZHEX:
- X hdrtyp = "HEX";
- X break;
- X }
- X if (c >= -3 && c <= FRTYPES)
- X sprintf(s128, "%s %s %ld", hdrtyp, frametypes[c + FTOFFSET], Rxpos);
- X else
- X sprintf(s128, "%s 0x%02x? %ld", hdrtyp, c, Rxpos);
- X#else
- X if (c >= -3 && c <= FRTYPES)
- X sprintf(s128, "hdr %s %ld", frametypes[c + FTOFFSET], Rxpos);
- X else
- X sprintf(s128, "hdr 0x%02x? %ld", c, Rxpos);
- X#endif
- X report_last_rxhdr(s128, 0);
- X }
- X report_rx_ind(0);
- X return (c);
- X}
- X
- X/* Receive a binary style header (type and position) */
- Xint
- Xzrbhdr(hdr)
- Xregister char *hdr;
- X{
- X register int c, n;
- X register unsigned short crc;
- X
- X if ((c = zdlread()) & ~0377)
- X return (c);
- X Rxtype = c;
- X crc = updcrc(c, 0);
- X
- X for (n = 4; --n >= 0; ++hdr)
- X {
- X if ((c = zdlread()) & ~0377)
- X return (c);
- X crc = updcrc(c, crc);
- X *hdr = c;
- X }
- X if ((c = zdlread()) & ~0377)
- X return (c);
- X crc = updcrc(c, crc);
- X if ((c = zdlread()) & ~0377)
- X return (c);
- X crc = updcrc(c, crc);
- X if (crc & 0xFFFF)
- X {
- X if (evenp)
- X report_str(masked, 1);
- X report_str(badcrc, 0);
- X return (ERROR);
- X }
- X#if defined(ZMODEM)
- X Protocol = ZMODEM;
- X#endif
- X Zmodem = 1;
- X return (Rxtype);
- X}
- X
- X/* Receive a binary style header (type and position) with 32 bit FCS */
- Xint
- Xzrbhdr32(hdr)
- Xregister char *hdr;
- X{
- X register int c, n;
- X register UNSL long crc;
- X
- X if ((c = zdlread()) & ~0377)
- X return (c);
- X Rxtype = c;
- X crc = 0xFFFFFFFFL;
- X crc = UPDC32(c, crc);
- X
- X for (n = 4; --n >= 0; ++hdr)
- X {
- X if ((c = zdlread()) & ~0377)
- X return (c);
- X crc = UPDC32(c, crc);
- X *hdr = c;
- X }
- X for (n = 4; --n >= 0;)
- X {
- X if ((c = zdlread()) & ~0377)
- X return (c);
- X crc = UPDC32(c, crc);
- X }
- X if (crc != 0xDEBB20E3)
- X {
- X if (evenp)
- X report_str(masked, 1);
- X report_str(badcrc, 0);
- X return (ERROR);
- X }
- X#if defined(ZMODEM)
- X Protocol = ZMODEM;
- X#endif
- X Zmodem = 1;
- X return (Rxtype);
- X}
- X
- X/* Receive a hex style header (type and position) */
- Xint
- Xzrhhdr(hdr)
- Xchar *hdr;
- X{
- X register int c;
- X register unsigned short crc;
- X register int n;
- X
- X if ((c = zgethex()) < 0)
- X return (c);
- X Rxtype = c;
- X crc = updcrc(c, 0);
- X
- X for (n = 4; --n >= 0; ++hdr)
- X {
- X if ((c = zgethex()) < 0)
- X return (c);
- X crc = updcrc(c, crc);
- X *hdr = c;
- X }
- X if ((c = zgethex()) < 0)
- X return (c);
- X crc = updcrc(c, crc);
- X if ((c = zgethex()) < 0)
- X return (c);
- X crc = updcrc(c, crc);
- X if (crc & 0xFFFF)
- X {
- X report_str(badcrc, 0);
- X return (ERROR);
- X }
- X if (readline(1) == '\r') /* Throw away possible cr/lf */
- X readline(1);
- X#if defined(ZMODEM)
- X Protocol = ZMODEM;
- X#endif
- X Zmodem = 1;
- X return (Rxtype);
- X}
- X
- X/* Decode two lower case hex digits into an 8 bit byte value */
- Xint
- Xzgeth1()
- X{
- X register int c, n;
- X
- X if ((c = noxrd7()) < 0)
- X return (c);
- X n = c - '0';
- X if (n > 9)
- X n -= ('a' - ':');
- X if (n & ~0xF)
- X return (ERROR);
- X if ((c = noxrd7()) < 0)
- X return (c);
- X c -= '0';
- X if (c > 9)
- X c -= ('a' - ':');
- X if (c & ~0xF)
- X return (ERROR);
- X c += (n << 4);
- X return (c);
- X}
- X
- Xint
- Xzgethex()
- X{
- X return (zgeth1());
- X}
- X
- X/*
- X * Read a byte,checking for ZMODEM escape encoding
- X * including CAN*5 which represents a quick abort
- X */
- Xint
- Xzdlread()
- X{
- X register int c;
- X
- X again:
- X /* Quick check for non control characters */
- X if ((c = readline(Rxtimeout)) & 0140)
- X return (c);
- X switch (c)
- X {
- X case ZDLE:
- X break;
- X case 023:
- X case 0223:
- X case 021:
- X case 0221:
- X goto again;
- X default:
- X if (Zctlesc && !(c & 0140))
- X {
- X goto again;
- X }
- X return (c);
- X }
- X again2:
- X if ((c = readline(Rxtimeout)) < 0)
- X return (c);
- X if (c == CAN && (c = readline(Rxtimeout)) < 0)
- X return (c);
- X if (c == CAN && (c = readline(Rxtimeout)) < 0)
- X return (c);
- X if (c == CAN && (c = readline(Rxtimeout)) < 0)
- X return (c);
- X switch (c)
- X {
- X case CAN:
- X return (GOTCAN);
- X case ZCRCE:
- X case ZCRCG:
- X case ZCRCQ:
- X case ZCRCW:
- X return (c | GOTOR);
- X case ZRUB0:
- X return (0177);
- X case ZRUB1:
- X return (0377);
- X case 023:
- X case 0223:
- X case 021:
- X case 0221:
- X goto again2;
- X default:
- X if (Zctlesc && !(c & 0140))
- X {
- X goto again2;
- X }
- X if ((c & 0140) == 0100)
- X return (c ^ 0100);
- X break;
- X }
- X sprintf(s128, "Bad escape sequence %x", c);
- X report_str(s128, 0);
- X return (ERROR);
- X}
- X
- X/*
- X * Read a character from the modem line with timeout.
- X * Eat parity,XON and XOFF characters.
- X */
- Xint
- Xnoxrd7()
- X{
- X register int c;
- X
- X for (;;)
- X {
- X if ((c = readline(Rxtimeout)) < 0)
- X return (c);
- X switch (c &= 0177)
- X {
- X case XON:
- X case XOFF:
- X continue;
- X default:
- X if (Zctlesc && !(c & 0140))
- X continue;
- X case '\r':
- X case '\n':
- X case ZDLE:
- X return (c);
- X }
- X }
- X}
- X
- X/* Store long integer pos in Txhdr */
- Xvoid
- Xstohdr(pos)
- Xlong pos;
- X{
- X Txhdr[ZP0] = pos;
- X Txhdr[ZP1] = pos >> 8;
- X Txhdr[ZP2] = pos >> 16;
- X Txhdr[ZP3] = pos >> 24;
- X}
- X
- X/* Recover a long integer from a header */
- Xlong
- Xrclhdr(hdr)
- Xregister char *hdr;
- X{
- X register long l;
- X
- X l = (hdr[ZP3] & 0377);
- X l = (l << 8) | (hdr[ZP2] & 0377);
- X l = (l << 8) | (hdr[ZP1] & 0377);
- X l = (l << 8) | (hdr[ZP0] & 0377);
- X return (l);
- X}
- X
- X/* end of zmodem.c */
- X/* vi: set tabstop=4 shiftwidth=4: */
- END_OF_FILE
- if test 18074 -ne `wc -c <'ecu330/z/zmodem.c'`; then
- echo shar: \"'ecu330/z/zmodem.c'\" unpacked with wrong size!
- fi
- # end of 'ecu330/z/zmodem.c'
- fi
- echo shar: End of archive 23 \(of 37\).
- cp /dev/null ark23isdone
- MISSING=""
- for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have unpacked all 37 archives.
- rm -f ark[1-9]isdone ark[1-9][0-9]isdone
- else
- echo You still must unpack the following archives:
- echo " " ${MISSING}
- fi
- exit 0
- exit 0 # Just in case...
-