home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume32 / ecu / part30 < prev    next >
Encoding:
Text File  |  1992-09-13  |  57.0 KB  |  1,989 lines

  1. Newsgroups: comp.sources.misc
  2. From: wht@n4hgf.Mt-Park.GA.US (Warren Tucker)
  3. Subject:  v32i065:  ecu - ECU Asynchronous Communications v3.20, Part30/40
  4. Message-ID: <1992Sep14.145042.22461@sparky.imd.sterling.com>
  5. X-Md4-Signature: 6cecb1b7bfeeabacd4166d4f0d1bd347
  6. Date: Mon, 14 Sep 1992 14:50:42 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: wht@n4hgf.Mt-Park.GA.US (Warren Tucker)
  10. Posting-number: Volume 32, Issue 65
  11. Archive-name: ecu/part30
  12. Environment: SCO,XENIX,ISC,SUNOS,SYSVR4,HDB,Curses
  13. Supersedes: ecu: Volume 21, Issue 53-89
  14.  
  15. ---- Cut Here and feed the following to sh ----
  16. #!/bin/sh
  17. # this is ecu320.30 (part 30 of ecu320)
  18. # do not concatenate these parts, unpack them in order with /bin/sh
  19. # file gendial/dceUSR24.c continued
  20. #
  21. if test ! -r _shar_seq_.tmp; then
  22.     echo 'Please unpack part 1 first!'
  23.     exit 1
  24. fi
  25. (read Scheck
  26.  if test "$Scheck" != 30; then
  27.     echo Please unpack part "$Scheck" next!
  28.     exit 1
  29.  else
  30.     exit 0
  31.  fi
  32. ) < _shar_seq_.tmp || exit 1
  33. if test ! -f _shar_wnt_.tmp; then
  34.     echo 'x - still skipping gendial/dceUSR24.c'
  35. else
  36. echo 'x - continuing file gendial/dceUSR24.c'
  37. sed 's/^X//' << 'SHAR_EOF' >> 'gendial/dceUSR24.c' &&
  38. Xthis function is usually a no-op.
  39. X--------------------------------------------------------------------------*/
  40. Xvoid
  41. XDCE_abort(sig)
  42. Xint sig;
  43. X{
  44. X    DEBUG(10,"DCE_abort(%d);\n",sig);
  45. X}    /* end of DCE_abort */
  46. X
  47. X/*+-------------------------------------------------------------------------
  48. X    DCE_exit(exitcode) - "last chance for gas" in this incarnation
  49. X
  50. XThe independent portion of the dialer program calls this routine in
  51. Xlieu of exit() in every case except one (see DCE_argv_hook() below).
  52. XNormally, this function just passes it's argument to exit(), but
  53. Xany necessary post-processing can be done.  The function must,
  54. Xhowever, eventually call exit(exitcode);
  55. X--------------------------------------------------------------------------*/
  56. Xvoid
  57. XDCE_exit(exitcode)
  58. Xint exitcode;
  59. X{
  60. X    DEBUG(10,"DCE_exit(%d);\n",exitcode);
  61. X    exit(exitcode);
  62. X}    /* end of DCE_exit */
  63. X
  64. X/*+-------------------------------------------------------------------------
  65. X    DCE_argv_hook(argc,argv,optind,unrecognized_switches)
  66. X
  67. XThis hook gives DCE-specific code a chance to look over the entire
  68. Xcommand line, such as for -z Telebit processing.
  69. X
  70. Xargc andf argv are the same values passed to main(),
  71. X
  72. Xoptind is the value of optind at the end of normal getopt processing.
  73. X
  74. Xunrecognized_switches is the count of switches not handled by main().
  75. XSpecifically, -h and -x are standard switches.
  76. X
  77. XNormally, this function should just return RC_FAIL|RCE_ARGS if there are
  78. Xany unrecognized switches, otherwise zero.  If you keep your nose clean
  79. Xthough, you can do anything you need to do here and exit the program.
  80. X
  81. XNote: only simple switches (with no argument) may be used with this
  82. Xfacility if the functrion is to return,' since main()'s getopt() will
  83. Xstop processing switches if it runs into an unrecognized switch with an
  84. Xargument.
  85. X
  86. XIf the function returns a non-zero value, then the value will be passed
  87. XDIRECTLY to exit() with no further ado.  Thus, a non-zero value must be
  88. Xof the format expected by dialer program callers, with RC_FAIL set as a
  89. Xminimum.
  90. X--------------------------------------------------------------------------*/
  91. Xint
  92. XDCE_argv_hook(argc,argv,optind,unrecognized_switches)
  93. Xint argc;
  94. Xchar **argv;
  95. Xint optind;
  96. Xint unrecognized_switches;
  97. X{
  98. X    if(unrecognized_switches)
  99. X        return(RC_FAIL | RCE_ARGS);
  100. X    return(0);
  101. X}    /* end of DCE_argv_hook */
  102. X
  103. X/* vi: set tabstop=4 shiftwidth=4: */
  104. SHAR_EOF
  105. echo 'File gendial/dceUSR24.c is complete' &&
  106. chmod 0644 gendial/dceUSR24.c ||
  107. echo 'restore of gendial/dceUSR24.c failed'
  108. Wc_c="`wc -c < 'gendial/dceUSR24.c'`"
  109. test 13878 -eq "$Wc_c" ||
  110.     echo 'gendial/dceUSR24.c: original size 13878, current size' "$Wc_c"
  111. rm -f _shar_wnt_.tmp
  112. fi
  113. # ============= gendial/dialer.h ==============
  114. if test -f 'gendial/dialer.h' -a X"$1" != X"-c"; then
  115.     echo 'x - skipping gendial/dialer.h (File already exists)'
  116.     rm -f _shar_wnt_.tmp
  117. else
  118. > _shar_wnt_.tmp
  119. echo 'x - extracting gendial/dialer.h (Text)'
  120. sed 's/^X//' << 'SHAR_EOF' > 'gendial/dialer.h' &&
  121. X/*+-------------------------------------------------------------------------
  122. X    dialer.h - SCO UUCP generic dialer program definitions
  123. X    wht%n4hgf.uucp@emory.mathcs.emory.edu -or- emory!n4hgf!wht
  124. X--------------------------------------------------------------------------*/
  125. X/*+:EDITS:*/
  126. X/*:09-10-1992-13:59-wht@n4hgf-ECU release 3.20 */
  127. X/*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA */
  128. X/*:03/29/92:12:47:49-cma-added <sys/filio.h> */
  129. X/*:03/29/92:12:30:01-cma-added <sys/time.h> */
  130. X/*:01-26-1992-15:30-wht@n4hgf-gendial 1.2 for ecu 3.20- better hangup */
  131. X/*:07-25-1991-12:58-wht@n4hgf-ECU release 3.10 */
  132. X/*:03-12-1991-19:11-wht@n4hgf-if ecu dialing, show complete call progress */
  133. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  134. X
  135. X#include <stdio.h>
  136. X#include <ctype.h>
  137. X#include <errno.h>
  138. X#include <fcntl.h>
  139. X#include <setjmp.h>
  140. X#include <signal.h>
  141. X#include <string.h>
  142. X#include <memory.h>
  143. X#include <sys/types.h>
  144. X#include <sys/errno.h>
  145. X#include <sys/stat.h>
  146. X#include <sys/timeb.h>
  147. X#include <sys/time.h>
  148. X#include <termio.h>
  149. X#include <time.h>
  150. X#include <pwd.h>
  151. X
  152. X#ifdef sun
  153. X#define BSD
  154. X#include <sys/filio.h>
  155. X#endif
  156. X
  157. X#define ff fprintf
  158. X#define se stderr
  159. X
  160. Xlong time();
  161. Xstruct passwd *getpwnam();
  162. X
  163. Xextern int errno;
  164. Xextern char *sys_errlist[];
  165. X
  166. Xextern int gargc;                    /* global copy of main's argv */
  167. Xextern char **gargv;                /* global copy of main's argv */
  168. Xextern char *dce_name;                /* full pathname of ACU device */
  169. Xextern char *telno;                    /* phone number if dial type request */
  170. Xextern struct termio dce_termio;    /* last termio for device */
  171. Xextern int Debug;                    /* set per -x flag */
  172. Xextern int dialing;                    /* set while dialing in progress */
  173. Xextern int dce_fd;                    /* file descriptor for dce_name */
  174. Xextern int DialerExitCode;             /* return code */
  175. Xextern int status;                    /* set on errors */
  176. Xextern int hangup_flag;                /* set when DCE being hung up */
  177. Xextern int hiCBAUD;                    /* highest permissible baud rate */
  178. Xextern int loCBAUD;                    /* lowest permissible baud rate */
  179. Xextern struct passwd *passwd;        /* pointer to password entry of invoker */
  180. Xextern int uid;                        /* user id of executor */
  181. Xextern int uid_uucp;                /* user id of uucp */
  182. Xextern int secure;                    /* non-zero to suppress display of secure
  183. X                                     * DCE traffic
  184. X                                     */
  185. Xextern int ecu_calling;                /* true if ecu dialing */
  186. X
  187. Xunsigned char dialer_codes[26];    /* A-Z embedded phone number codes */
  188. X/* return codes: these are set up so that an abort signal at any time can */
  189. X/* set the fail bit and return to the caller with the correct status */
  190. X#define    SUCCESS        0
  191. X#define    RC_FAIL        0x80    /* 1 = failed to connect */
  192. X#define    RC_ENABLED    0x10    /* enabled flag: 1 = ungetty -r required to
  193. X                             * restore the line
  194. X                             */
  195. X#define    RC_BAUD        0x0f    /* CBAUD connected at (0=same as dialed speed) */
  196. X
  197. X/* DCE result device independent flag */
  198. X#define    rfNumeric    0x40000000
  199. X
  200. X/* program exit codes */
  201. X#define    RCE_NULL    0    /* general purpose or unknown error code */
  202. X#define    RCE_INUSE    1    /* line in use */
  203. X#define    RCE_SIG        2    /* signal aborted dialer */
  204. X#define    RCE_ARGS    3    /* invalid arguments */
  205. X#define    RCE_PHNO    4    /* invalid phone number */
  206. X#define    RCE_SPEED    5    /* invalid baud rate -or- bad connect baud */
  207. X#define    RCE_OPEN    6    /* can't open line */
  208. X#define    RCE_IOCTL    7    /* ioctl error */
  209. X#define    RCE_TIMOUT    8    /* timeout */
  210. X#define    RCE_NOTONE    9    /* no dial tone */
  211. X#define    RCE_HANGUP    10    /* hangup failed */
  212. X#define RCE_NORESP    11    /* Modem didn't respond. */
  213. X#define    RCE_BUSY    13    /* phone is busy */
  214. X#define    RCE_NOCARR    14    /* no carrier */
  215. X#define    RCE_ANSWER    15    /* no answer */
  216. X
  217. X/* ungetty return codes */
  218. X#define    UG_NOTENAB    0
  219. X#define    UG_ENAB        1
  220. X#define    UG_RESTART    1
  221. X#define    UG_FAIL        2
  222. X
  223. X/* size for various buffers */
  224. X#define MAXLINE        2048
  225. X
  226. X/* How many errors allowed before call retry fails */
  227. X#define    DIAL_ERRORS_MAX    4
  228. X
  229. X/* DCE message to code mapping struct ... array DCE_results of these
  230. X * must be terminated with { (char *)0,0 } */
  231. Xtypedef struct dce_result
  232. X{
  233. X    char *result;
  234. X    long code;
  235. X} DCE_RESULT;
  236. X
  237. X#define DEBUG(level,fmt,arg) if (Debug >= level) fprintf(stderr,fmt,arg)
  238. X#if !defined(DBG)
  239. X#define    DBG    0
  240. X#endif
  241. X
  242. X/*
  243. X * what the hell does __STDC__ mean in reality?  An __STDC__ compiler is
  244. X * more nouveau than an older one.  ANSI C (or 'D') just stirred new
  245. X * food for "standard" readers who went off and did what they wanted
  246. X * to do.  We use __STDC__ to decide between two opinions of
  247. X * what constitute "ANSI prototypes."  As of this writing, __STDC__ is
  248. X * defined by the UNIX (MSC 5) compiler and not by the XENIX (MSC 4)
  249. X * compiler.  We handle the GNU C compiler too.
  250. X */
  251. X#if defined(__STDC__) && !defined(__GNUC__)
  252. Xint DCE_baud_to_CBAUD(unsigned int );
  253. Xvoid DCE_hangup(void );
  254. Xint DCE_dial(char *);
  255. Xvoid DCE_abort(int );
  256. Xvoid DCE_exit(int );
  257. Xint DCE_argv_hook(int ,char **,int ,int );
  258. Xint get_uucp_uid(void );
  259. Xint instr(char *,char *);
  260. Xvoid translate(char *,char *);
  261. Xint decode_phone_number(char *,char *,int );
  262. Xchar *make_printable(unsigned char );
  263. Xchar *RCE_text(int );
  264. Xvoid myexit(int );
  265. XSIGTYPE dial_abort(int );
  266. Xvoid cleanup(int );
  267. Xint SIGALRM_abort(int );
  268. XSIGTYPE SIGALRM_alert(int );
  269. Xint _lread(int ,int );
  270. Xint lread_ignore(int );
  271. Xint lread(int );
  272. Xvoid lflush(void );
  273. Xvoid _lputc(char );
  274. Xvoid _lputc_paced(long ,char );
  275. Xvoid _lputs(char *);
  276. Xvoid _lputs_paced(long ,char *);
  277. Xvoid lwrite(char *);
  278. Xvoid lflash_DTR(void );
  279. Xint call_ungetty(char );
  280. Xvoid display_termio(struct termio *,char *);
  281. Xint open_dce(void );
  282. Xint main(int ,char **);
  283. X#else
  284. Xint DCE_baud_to_CBAUD();
  285. Xvoid DCE_hangup();
  286. Xint DCE_dial();
  287. Xvoid DCE_abort();
  288. Xvoid DCE_exit();
  289. Xint DCE_argv_hook();
  290. Xint get_uucp_uid();
  291. Xint instr();
  292. Xvoid translate();
  293. Xint decode_phone_number();
  294. Xchar *make_printable();
  295. Xchar *RCE_text();
  296. Xvoid myexit();
  297. XSIGTYPE dial_abort();
  298. Xvoid cleanup();
  299. XSIGTYPE SIGALRM_alert();
  300. Xint SIGALRM_abort();
  301. Xint _lread();
  302. Xint lread_ignore();
  303. Xint lread();
  304. Xvoid lflush();
  305. Xvoid _lputc();
  306. Xvoid _lputc_paced();
  307. Xvoid _lputs();
  308. Xvoid _lputs_paced();
  309. Xvoid lwrite();
  310. Xvoid lflash_DTR();
  311. Xint call_ungetty();
  312. Xvoid display_termio();
  313. Xint open_dce();
  314. Xint main();
  315. X#endif
  316. X
  317. X/* vi: set tabstop=4 shiftwidth=4: */
  318. X/* end of dialer.h */
  319. SHAR_EOF
  320. chmod 0644 gendial/dialer.h ||
  321. echo 'restore of gendial/dialer.h failed'
  322. Wc_c="`wc -c < 'gendial/dialer.h'`"
  323. test 6062 -eq "$Wc_c" ||
  324.     echo 'gendial/dialer.h: original size 6062, current size' "$Wc_c"
  325. rm -f _shar_wnt_.tmp
  326. fi
  327. # ============= gendial/gendial.c ==============
  328. if test -f 'gendial/gendial.c' -a X"$1" != X"-c"; then
  329.     echo 'x - skipping gendial/gendial.c (File already exists)'
  330.     rm -f _shar_wnt_.tmp
  331. else
  332. > _shar_wnt_.tmp
  333. echo 'x - extracting gendial/gendial.c (Text)'
  334. sed 's/^X//' << 'SHAR_EOF' > 'gendial/gendial.c' &&
  335. X/* CHK=0xC086 */
  336. Xchar *revision = "1.31";
  337. X/*+-------------------------------------------------------------------------
  338. X    gendial.c - SCO UUCP dialer program device independent portion
  339. X    wht@n4hgf.Mt-Park.GA.US
  340. X
  341. X  Configuration symbols:
  342. X    HDB_UUCP        defined if HDB UUCP used on system, else old Version 2 
  343. X
  344. X  Defined functions:
  345. X    RCE_text(value)
  346. X    SIGALRM_alert(sig)
  347. X    _lputc(lchar)
  348. X    _lputc_paced(pace_msec,lchar)
  349. X    _lputs(string)
  350. X    _lputs_paced(pace_msec,string)
  351. X    _lread(rtime,error_ok)
  352. X    call_ungetty(call_type)
  353. X    cleanup(code)
  354. X    decode_phone_number(userphno,result,resultlen)
  355. X    dial_abort(sig)
  356. X    display_termio(ttt,text)
  357. X    get_uucp_uid()
  358. X    instr(s1,s2)
  359. X    lbreak()
  360. X    lflash_DTR()
  361. X    lflush()
  362. X    lread(rtime)
  363. X    lread_ignore(rtime)
  364. X    ltd_report()
  365. X    lwrite(str)
  366. X    main(argc,argv)
  367. X    make_printable(ch)
  368. X    myexit(code)
  369. X    open_dce()
  370. X    rdchk(fd)
  371. X    translate(ttab,str)
  372. X
  373. X  Usage:    dial ttyname telnumber speed 
  374. X            dial -h ttyname speed
  375. X
  376. X  ttyname may be of style "ttyxx" or "/dev/ttyxx" (this is not standard)
  377. X
  378. X  Returns:
  379. X        0x80    bit = 1 if connection failed
  380. X        0x10    bit = 1 if line is also used for dialin #if !defined(OLDUUCP)
  381. X        0x0f    if msb=1: error code
  382. X                if msb=0: connected baud rate (0=same as dialed baud)
  383. X                Note: this dialer always returns 0 in the low nibble
  384. X                since cu and uucp expect it
  385. X
  386. X  Note: getty calls the dialer with -h whenever it starts up on a line
  387. X  enabled in /etc/ttys and listed in Devices with this dialer.
  388. X
  389. X  Error codes are split into two categories:
  390. X
  391. X    1) (codes 0-11) Local problems are defined as tty port, or DCE
  392. X    problems: problems that can be worked around by using a different
  393. X    device.
  394. X
  395. X    2) (codes 12-15) Remote problems are phone busy, no answer, etc.:
  396. X    attempt to connect to this remote system should be stopped.
  397. X
  398. X  Note: This dialer can be used both for the old "Version 2" 
  399. X  new HoneyDanBer UUCP.  In HDB, uugetty is used and ungetty is not
  400. X  necessary. Define HDB_UUCP for HDB UUCP.
  401. X
  402. X  Note: This version of the dialer will NOT display the telephone number
  403. X  on the console unless the actual uid is root or ECU is calling as
  404. X  detected by a parse of argv[0].  Now, if uucico would just suppress
  405. X  username and password information it emits to debug (some do).
  406. X
  407. X  See below for a description of lread() timing debug.
  408. X
  409. X--------------------------------------------------------------------------*/
  410. X/*+:EDITS:*/
  411. X/*:09-10-1992-13:59-wht@n4hgf-ECU release 3.20 */
  412. X/*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA */
  413. X/*:08-16-1992-03:08-wht@n4hgf-head off another POSIX plot */
  414. X/*:08-10-1992-04:01-wht@n4hgf-use init_Nap */
  415. X/*:07-17-1992-18:28-wht@n4hgf-remove Nap() and use common ../nap.o */
  416. X/*:05-11-1992-17:54-wht@gyro-no naps in lflash_DTR on sun */
  417. X/*:05-11-1992-16:43-wht@gyro-fix WORKING_SELECT nap once and for all */
  418. X/*:03-30-1992-14:18-root@n4hgf-add lbreak */
  419. X/*:03-29-1992-12:30-cma-removed sigint reference in nap */
  420. X/*:02-02-1992-19:37-root@n4hgf-add ltd */
  421. X/*:02-02-1992-17:45-root@n4hgf-_lread: allow rtime secs after each character */
  422. X/*:01-26-1992-15:31-wht@n4hgf-gendial 1.2 for ecu 3.20- better hangup */
  423. X/*:08-13-1991-14:36-wht@n4hgf-perror on dce open error */
  424. X/*:07-25-1991-12:58-wht@n4hgf-ECU release 3.10 */
  425. X/*:05-01-1991-21:28-wht@n4hgf-add dial timing */
  426. X/*:03-12-1991-19:11-wht@n4hgf-if ecu dialing, show complete call progress */
  427. X/*:07-19-1990-17:14-root@n4hgf-modify lread fata timeout handler */
  428. X/*:05-26-1990-02:15-wht@n4hgf-creation */
  429. X
  430. X#include "dialer.h"
  431. X
  432. X/*
  433. X * lread() timing debug
  434. X *
  435. X * if LTD_DEBUG_LEVEL is defined, it should be set to the DEBUG level
  436. X * at which a DCE result arrival report should be printed in the event
  437. X * of a DCE timeout.  This normally would be set at 6, the debugging
  438. X * level for the timeout report itself.  Sample output:
  439. X *
  440. X * Arrival Report for 16 characters (in msec)
  441. X *      0 A    19624 ^M   19624 ^J   19624 C    19624 O    19624 N    19624 N
  442. X *  19624 E    19624 C    19624 T    19872      19872 F    19872 A    19872 S
  443. X *  19888 T    19888 ^M
  444. X *
  445. X * comment out the following line for no LTD.
  446. X */
  447. X#define LTD_DEBUG_LEVEL 6
  448. X#if defined(LTD_DEBUG_LEVEL)
  449. Xstruct ltd {
  450. X    unsigned char rdchar;
  451. X    struct timeb timeb;
  452. X};
  453. Xstruct ltd ltds[MAXLINE];
  454. Xint ltd_count = 0;
  455. Xstruct timeb ltd_initial_timeb;
  456. X#endif /* LTD_DEBUG_LEVEL */
  457. X
  458. X
  459. X#undef NULL    /* some stdio and param.h define these differently */
  460. X#include <sys/param.h>
  461. X#ifndef NULL        /* fake usual sys/param.h value */
  462. X#define NULL 0
  463. X#endif
  464. X
  465. Xlong Nap();
  466. X
  467. X/* must be defined by device dependent module */
  468. Xextern long DCE_DTR_low_msec;        /* msecs DTR must be low to be recognized */
  469. Xextern long DCE_DTR_high_msec;        /* msecs for DCE to recover */
  470. Xextern long DCE_write_pace_msec;    /* msecs between chars written to DCE */
  471. Xextern DCE_RESULT DCE_results[];    /* DCE result codes */
  472. Xextern char *DCE_name;                /* name of DCE */
  473. Xextern char *DCE_revision;            /* DCE-dependent code revision */
  474. Xextern short DCE_hangup_CBAUD;        /* BXXX DCE hangup baud rate or zero */
  475. X
  476. X/* globals available to device dependent module */
  477. Xint gargc;                    /* global copy of main's argv */
  478. Xchar **gargv;                /* global copy of main's argv */
  479. Xchar *dce_name;                /* full pathname of ACU device */
  480. Xchar *telno = (char *)0;    /* phone number if dial type request */
  481. Xstruct termio dce_termio;    /* last termio for device */
  482. Xint Debug = DBG;            /* set per -x flag */
  483. Xint dialing = 0;            /* set while dialing in progress */
  484. Xint dce_fd = -1;                /* file descriptor for dce_name */
  485. Xint DialerExitCode = RC_FAIL; /* return code */
  486. Xint status = 0;                /* set on errors */
  487. Xint hangup_flag = 0;        /* set when DCE being hung up */
  488. Xint hiCBAUD;                /* highest permissible baud rate */
  489. Xint loCBAUD;                /* lowest permissible baud rate */
  490. Xstruct passwd *passwd;
  491. Xint uid;                    /* user id of executor */
  492. Xint uid_uucp;                /* user id of uucp */
  493. Xint secure = 0;                /* non-zero to suppress display of secure
  494. X                             * DCE traffic
  495. X                             */
  496. Xint ecu_calling = 0;        /* true if ecu is dialing */
  497. Xint sigint = 0;            /* dummy for nap.c */
  498. X
  499. Xunsigned char dialer_codes[26];    /* A-Z embedded phone number codes */
  500. X
  501. Xjmp_buf    SIGALRM_alert_jmpbuf;
  502. XDCE_RESULT *last_result;
  503. X
  504. X/*+-------------------------------------------------------------------------
  505. X    get_uucp_uid()
  506. X--------------------------------------------------------------------------*/
  507. Xint
  508. Xget_uucp_uid()
  509. X{
  510. X
  511. X    passwd = getpwnam("uucp");
  512. X    endpwent();
  513. X    if(passwd)
  514. X        return(passwd->pw_uid);
  515. X    else
  516. X        return(-1);
  517. X}    /* end of get_uucp_uid */
  518. X
  519. X/*+-------------------------------------------------------------------------
  520. X    instr(s1,s2)
  521. X
  522. X  find s2 in s1; returns 1 if found, 0 if not found
  523. X--------------------------------------------------------------------------*/
  524. Xinstr(s1,s2)
  525. Xregister char *s1;
  526. Xchar *s2;
  527. X{
  528. X    register len = strlen(s2);
  529. X    while(s1 = strchr(s1,*s2))
  530. X    {
  531. X        if(!strncmp(s2,s1,len))
  532. X            return(1);
  533. X        s1++;
  534. X    }
  535. X    return(0);
  536. X}    /* end of instr */
  537. X
  538. X/*+-------------------------------------------------------------------------
  539. X    translate(ttab,str)
  540. X
  541. X  translate the pairs of characters present in the first string
  542. X  whenever the first of the pair appears in the second string
  543. X  (this routine from standard SCO dialer code)
  544. X--------------------------------------------------------------------------*/
  545. Xvoid
  546. Xtranslate(ttab,str)
  547. Xregister char *ttab;
  548. Xchar *str;
  549. X{
  550. X    register char *cptr;
  551. X
  552. X    while(*ttab && *(ttab + 1))
  553. X    {
  554. X        for(cptr = str; *cptr; cptr++)
  555. X        {
  556. X            if(*ttab == *cptr)
  557. X                *cptr = *(ttab + 1);
  558. X        }
  559. X        ttab += 2;
  560. X    }
  561. X}    /* end of translate */
  562. X
  563. X/*+-------------------------------------------------------------------------
  564. X    decode_phone_number(userphno,result,resultlen)
  565. X
  566. Xdecode user flags in phone number, returning phone number in
  567. Xresult, character flags in global dialer_codes[], 'A' or 'a'
  568. Xresults in dialer_codes[0] being 1, etc.  Only letter codes are
  569. Xextracted.
  570. X
  571. XFor example, if userphno contains "123,D45f", result returned
  572. X"123,45" and only elements 3 and 5 of dialer_codes set to 1
  573. X
  574. XFunction returns 0 if successful, -1 if result buffer too small
  575. X--------------------------------------------------------------------------*/
  576. Xint
  577. Xdecode_phone_number(userphno,result,resultlen)
  578. Xregister char *userphno;
  579. Xregister char *result;
  580. Xint resultlen;
  581. X{
  582. Xregister itmp;
  583. X
  584. X    for(itmp = 0; itmp < sizeof(dialer_codes); itmp++)
  585. X        dialer_codes[itmp] = 0;
  586. X
  587. X    if(!resultlen)
  588. X        return(-1);
  589. X    resultlen--;    /* leave room for null */
  590. X
  591. X    while(*userphno)
  592. X    {
  593. X        if(isalpha(*userphno))
  594. X            dialer_codes[*userphno - ((isupper(*userphno)) ? 'A' : 'a')] = 1;
  595. X        else
  596. X        {
  597. X            if(!resultlen--)
  598. X                return(-1);
  599. X            *result++ = *userphno;
  600. X        }
  601. X        userphno++;
  602. X    }
  603. X    *result = 0;
  604. X    return(0);
  605. X}    /* end of decode_phone_number */
  606. X
  607. X/*+-------------------------------------------------------------------------
  608. X    make_printable(ch) - make a character "printable"
  609. X--------------------------------------------------------------------------*/
  610. Xchar *
  611. Xmake_printable(ch)
  612. Xunsigned char ch;
  613. X{
  614. Xstatic char buffer[10];
  615. Xchar *cptr;
  616. X#define    to_print(x)    ((x)<' '?((x)+'@'):'?')
  617. X
  618. X    cptr = buffer;
  619. X    /* if not root or uucp and info needs securing */
  620. X    if(!ecu_calling && uid && (uid != uid_uucp) && secure)
  621. X    {
  622. X        *cptr++ = '?';    /* hide it */
  623. X        *cptr = 0;
  624. X        return(buffer);
  625. X    }
  626. X
  627. X    if(iscntrl(ch) || !isprint(ch))
  628. X    {
  629. X        if(!isascii(ch))
  630. X        {            /* Top bit is set */
  631. X            *cptr++ = 'M';
  632. X            *cptr++ = '-';
  633. X            ch = toascii(ch);            /* Strip it */
  634. X        }
  635. X        if(iscntrl(ch))
  636. X        {
  637. X            *cptr++ = '^';
  638. X            ch = to_print(ch);            /* Make it printable */
  639. X        }
  640. X    }
  641. X    *cptr++ = ch;
  642. X    *cptr = 0;
  643. X    return(buffer);
  644. X}    /* end of make_printable */
  645. X
  646. X/*+-------------------------------------------------------------------------
  647. X    RCE_text(value)
  648. X--------------------------------------------------------------------------*/
  649. Xchar *
  650. XRCE_text(value)
  651. Xint value;
  652. X{
  653. Xstatic char errant[32];
  654. X
  655. X    switch(value & 0x0F)
  656. X    {
  657. X        case RCE_NULL: return("unknown or unclassified error");
  658. X        case RCE_INUSE: return("line in use");
  659. X        case RCE_SIG: return("killed with signal");
  660. X        case RCE_ARGS: return("invalid arguments");
  661. X        case RCE_PHNO: return("invalid phone number");
  662. X        case RCE_SPEED: return("invalid line speed or bad connect speed");
  663. X        case RCE_OPEN: return("cannot open line");
  664. X        case RCE_IOCTL: return("ioctl error");
  665. X        case RCE_TIMOUT: return("timeout");
  666. X        case RCE_NOTONE: return("NO DIAL TONE");
  667. X        case RCE_HANGUP: return("hangup failed\n");
  668. X        case RCE_NORESP: return("DCE didn't respond.\n");
  669. X        case RCE_BUSY: return("BUSY");
  670. X        case RCE_NOCARR: return("NO CARRIER");
  671. X        case RCE_ANSWER: return("NO ANSWER");
  672. X    }
  673. X    sprintf(errant,"code 0x%04x",value);
  674. X    return(errant);
  675. X
  676. X}    /* end of RCE_text */
  677. X
  678. X/*+-------------------------------------------------------------------------
  679. X    myexit(code) - all threads exit() thru here
  680. X--------------------------------------------------------------------------*/
  681. Xvoid
  682. Xmyexit(code)
  683. Xint code;
  684. X{
  685. X    alarm(0);
  686. X    if(dialing)
  687. X    {
  688. X        if(code & RC_FAIL)
  689. X        {
  690. X            DEBUG(1,"dial failed: %s\n",RCE_text(code));
  691. X        }
  692. X        else
  693. X        {
  694. X            DEBUG(1,"dial succeeded\n",0);
  695. X        }
  696. X    }
  697. X    DCE_exit(code);    /* should not return */
  698. X    exit(code);        /* in case it does */
  699. X
  700. X}    /* end of myexit */
  701. X
  702. X/*+-------------------------------------------------------------------------
  703. X    dial_abort(sig)
  704. X--------------------------------------------------------------------------*/
  705. XSIGTYPE
  706. Xdial_abort(sig)
  707. Xint sig;
  708. X{
  709. X    if(sig)
  710. X    {
  711. X        DEBUG(1,"\ndialer received signal %d\n\n",sig);
  712. X    }
  713. X    else
  714. X    {
  715. X        DEBUG(1,"\ndialer aborted, fail status=0x%02x\n",DialerExitCode);
  716. X    }
  717. X    DCE_abort(sig);
  718. X    if(dce_fd != -1)
  719. X    {
  720. X        ioctl(dce_fd,TCGETA,&dce_termio);
  721. X        dce_termio.c_cflag |= HUPCL;        /* make sure DCE hangs up */
  722. X        ioctl(dce_fd,TCSETA,&dce_termio);
  723. X        close(dce_fd);
  724. X    }
  725. X    if(sig)
  726. X        DialerExitCode |= (RC_FAIL | RCE_SIG);
  727. X    myexit(DialerExitCode);
  728. X}    /* end of dial_abort */
  729. X
  730. X/*+-------------------------------------------------------------------------
  731. X    cleanup(code) - close device and exit
  732. X--------------------------------------------------------------------------*/
  733. Xvoid
  734. Xcleanup(code)
  735. Xint code;
  736. X{
  737. X    if(code & RC_FAIL)
  738. X    {    /* if we failed, drop DTR (in dial_abort) */
  739. X        DialerExitCode = code;
  740. X        dial_abort(0);
  741. X    }
  742. X    else 
  743. X        myexit(code);
  744. X}    /* end of cleanup */
  745. X
  746. X/*+-------------------------------------------------------------------------
  747. X    SIGALRM_alert(sig) - catch alarm call and do longjmp
  748. X--------------------------------------------------------------------------*/
  749. XSIGTYPE
  750. XSIGALRM_alert(sig)
  751. Xint sig;
  752. X{
  753. X    longjmp(SIGALRM_alert_jmpbuf,1);
  754. X}    /* end of SIGALRM_alert */
  755. X
  756. X/*+-------------------------------------------------------------------------
  757. X    ltd_report()
  758. X--------------------------------------------------------------------------*/
  759. X#if defined(LTD_DEBUG_LEVEL)
  760. Xvoid
  761. Xltd_report()
  762. X{
  763. Xstruct ltd *l = ltds;
  764. Xlong msec;
  765. Xint col = 0;
  766. X
  767. X    if(!ltd_count)
  768. X    {
  769. X        fputs("DCE was completely silent\n",stderr);
  770. X        return;
  771. X    }
  772. X    fprintf(stderr,"Arrival Report for %d characters (in msec)\n",ltd_count);
  773. X    while(ltd_count--)
  774. X    {
  775. X        msec =  ((l->timeb.time - ltd_initial_timeb.time) * 1000L) +
  776. X            (l->timeb.millitm - ltd_initial_timeb.millitm);
  777. X        fprintf(stderr,"%6ld %-3.3s ",msec,make_printable(l->rdchar));
  778. X        l++;
  779. X        if(++col > 6)
  780. X        {
  781. X            col = 0;
  782. X            fputs("\n",stderr);
  783. X        }
  784. X    }
  785. X    if(col)
  786. X        fputs("\n",stderr);
  787. X    ltd_count = 0;
  788. X
  789. X}    /* end of ltd_report */
  790. X#endif /* LTD_DEBUG_LEVEL */
  791. X
  792. X/*+-------------------------------------------------------------------------
  793. X    _lread(rtime,error_ok)
  794. X
  795. X  Common code for lread() and lread_ignore()
  796. X
  797. X  Returns DCE_RESULT->code from matching DCE_RESULT->result
  798. X  or if no match is found and the first digit of the modem
  799. X  response is numeric, the the numeric value is returned ored
  800. X  with 0x4000.
  801. X
  802. X  If error_ok is true and a timeout occurs, -1 is returned.
  803. X  If error_ok is false and a timeout occurs,
  804. X     cleanup(RC_FAIL | RCE_TIMOUT | DialerExitCode);
  805. X     is called, which results in dial_abort(0) thus DCE_abort(0)
  806. X     being called.
  807. X--------------------------------------------------------------------------*/
  808. Xint
  809. X_lread(rtime,error_ok)
  810. Xint rtime;
  811. Xint error_ok;
  812. X{
  813. Xint itmp;
  814. Xchar rdchar;
  815. XDCE_RESULT *mr;
  816. Xchar buf[MAXLINE];
  817. Xchar *bp;
  818. Xchar *cptr;
  819. X
  820. X#if defined(LTD_DEBUG_LEVEL)
  821. X    ltd_count = 0;
  822. X    if(Debug >= LTD_DEBUG_LEVEL)
  823. X        ftime(<d_initial_timeb);
  824. X#endif /* LTD_DEBUG_LEVEL */
  825. X
  826. X    if(error_ok)
  827. X    {
  828. X        signal(SIGALRM,SIGALRM_alert);
  829. X        if(setjmp(SIGALRM_alert_jmpbuf) != 0)
  830. X        {
  831. X            DEBUG(6,">>-%s\n","TIMEOUT");
  832. X#if defined(LTD_DEBUG_LEVEL)
  833. X            if(Debug >= LTD_DEBUG_LEVEL)
  834. X                ltd_report();
  835. X#endif /* LTD_DEBUG_LEVEL */
  836. X            return(-1);
  837. X        }
  838. X    }
  839. X    else
  840. X    {
  841. X        signal(SIGALRM,SIGALRM_alert);
  842. X        if(setjmp(SIGALRM_alert_jmpbuf) != 0)
  843. X        {
  844. X            DEBUG(6,">>-%s\n","TIMEOUT (FATAL)");
  845. X#if defined(LTD_DEBUG_LEVEL)
  846. X            if(Debug >= LTD_DEBUG_LEVEL)
  847. X                ltd_report();
  848. X#endif /* LTD_DEBUG_LEVEL */
  849. X            cleanup(RC_FAIL | RCE_TIMOUT | DialerExitCode);
  850. X        }
  851. X    }
  852. X
  853. X    bp = buf;
  854. X    alarm(rtime);
  855. X    DEBUG(6,"DCE returned %s","<<");
  856. X
  857. X    while((itmp = read(dce_fd,&rdchar,1)) == 1)
  858. X    {
  859. X        alarm(rtime);    /* allow rtime secs after each character */
  860. X        if(bp >= (buf + MAXLINE))
  861. X        {
  862. X            alarm(0);
  863. X            DEBUG(6,"\n>>-FAIL (%s)\n","BUFFER OVERFLOW");
  864. X            myexit(RC_FAIL | RCE_NULL);
  865. X        }
  866. X        *bp++ = (rdchar &= 0x7F);
  867. X        *bp = 0;
  868. X#if defined(LTD_DEBUG_LEVEL)
  869. X        if(Debug >= LTD_DEBUG_LEVEL)
  870. X        {
  871. X            ltds[ltd_count].rdchar = rdchar;
  872. X            ftime(<ds[ltd_count++].timeb);
  873. X        }
  874. X#endif /* LTD_DEBUG_LEVEL */
  875. X        DEBUG(6,"%s",make_printable(rdchar));
  876. X        if(rdchar == 0x0A)
  877. X            DEBUG(6,"\n",0);
  878. X        if(rdchar == '\r')
  879. X        {
  880. X            cptr = buf;
  881. X            if(*cptr == 0x0A)
  882. X                cptr++;
  883. X            for(mr = DCE_results; mr->result; ++mr)
  884. X            {
  885. X                if(instr(buf,mr->result))
  886. X                {
  887. X                    alarm(0);
  888. X                    DEBUG(6,">>-%s\n","SUCCESS");
  889. X                    if(strcmp(mr->result,"OK"))  /* not so modem independent */
  890. X                        DEBUG(6,"got %s\n",mr->result);
  891. X                    else
  892. X                        DEBUG(8,"got %s\n",mr->result);
  893. X                    last_result = mr;
  894. X                    return(mr->code);
  895. X                }
  896. X            }
  897. X
  898. X            if(isdigit(*cptr))
  899. X            {
  900. X                alarm(0);
  901. X                itmp = atoi(cptr);
  902. X                DEBUG(6,">>-SUCCESS (NUMERIC RESULT %d)\n",itmp);
  903. X                return(rfNumeric | itmp);
  904. X            }
  905. X
  906. X            bp = buf;
  907. X        }
  908. X    }
  909. X
  910. X    alarm(0);
  911. X    if(Debug >= 6)
  912. X    {
  913. X        ff(se,">>-FAIL (%s %d)",
  914. X            (itmp < 0) ? "READ ERRNO" : "READ LENGTH",
  915. X            (itmp < 0) ? errno : 0);
  916. X    }
  917. X    DEBUG(4," incomplete or no response\n",0);
  918. X    return(-1);
  919. X}    /* end of _lread */
  920. X
  921. X/*+-------------------------------------------------------------------------
  922. X    lread_ignore(rtime)
  923. X
  924. X  Reads from the ACU until it finds a valid response (found in
  925. X  DCE_results), a numeric result code (e.g., S-register value), or times
  926. X  out after rtime seconds.  The numeric response feature is designed
  927. X  for Hayes-style DCEs and may not be useful for other DCE types
  928. X
  929. X  Returns: DCE_RESULT code, numeric result + 128, or -1 on timeout or error
  930. X--------------------------------------------------------------------------*/
  931. Xint
  932. Xlread_ignore(rtime)
  933. Xint rtime;
  934. X{
  935. X    return(_lread(rtime,1));
  936. X}    /* end of lread_ignore */
  937. X
  938. X/*+-------------------------------------------------------------------------
  939. X    lread(rtime)
  940. X
  941. X  Same as lread_ignore, but does not return on timeout or error
  942. X--------------------------------------------------------------------------*/
  943. Xint
  944. Xlread(rtime)
  945. Xint rtime;
  946. X{
  947. Xint rtn = _lread(rtime,0);
  948. X    if(rtn < 0)
  949. X        myexit(RC_FAIL | RCE_TIMOUT);
  950. X    return(rtn);
  951. X}    /* end of lread */
  952. X
  953. X/*+-------------------------------------------------------------------------
  954. X    lflush() - flushes input clists for DCE
  955. X--------------------------------------------------------------------------*/
  956. Xvoid
  957. Xlflush()
  958. X{
  959. X    ioctl(dce_fd,TCFLSH,0);
  960. X}    /* end of lflush */
  961. X
  962. X/*+-----------------------------------------------------------------------
  963. X    _lputc(lchar) -- write char to comm line
  964. X------------------------------------------------------------------------*/
  965. Xvoid
  966. X_lputc(lchar)
  967. Xchar lchar;
  968. X{
  969. X    write(dce_fd,&lchar,1);
  970. X    DEBUG(6,"%s",make_printable(lchar));
  971. X}    /* end of _lputc */
  972. X
  973. X/*+-----------------------------------------------------------------------
  974. X    _lputc_paced(pace_msec,lchar) -- write char to comm line with pacing
  975. X------------------------------------------------------------------------*/
  976. Xvoid
  977. X_lputc_paced(pace_msec,lchar)
  978. Xregister long pace_msec;
  979. Xregister char lchar;
  980. X{
  981. X    _lputc(lchar);
  982. X    if(pace_msec)
  983. X        Nap(pace_msec);
  984. X}    /* end of _lputc_paced */
  985. X
  986. X/*+-----------------------------------------------------------------------
  987. X    _lputs(string) -- write string to comm line
  988. X------------------------------------------------------------------------*/
  989. Xvoid
  990. X_lputs(string)
  991. Xregister char *string;
  992. X{
  993. X    while(*string)
  994. X        _lputc(*string++);
  995. X}
  996. X
  997. X/*+-----------------------------------------------------------------------
  998. X    _lputs_paced(pace_msec,string) -- write string to comm line
  999. X  with time between each character 
  1000. X------------------------------------------------------------------------*/
  1001. Xvoid
  1002. X_lputs_paced(pace_msec,string)
  1003. Xregister long pace_msec;
  1004. Xregister char *string;
  1005. X{
  1006. X    while(*string)
  1007. X        _lputc_paced(pace_msec,*string++);
  1008. X
  1009. X}    /* end of _lputs_paced */
  1010. X
  1011. X/*+-------------------------------------------------------------------------
  1012. X    lwrite(str) - output string to dce_name
  1013. X  Returns:    0 on completion, -1 on write errors.
  1014. X--------------------------------------------------------------------------*/
  1015. Xvoid
  1016. Xlwrite(str)
  1017. Xregister char *str;
  1018. X{
  1019. X
  1020. X    Nap(200L);
  1021. X    DEBUG(6,"Sent DCE %s","<<");
  1022. X    _lputs_paced(DCE_write_pace_msec,str);
  1023. X    DEBUG(6,">>-%s\n","SUCCESS");
  1024. X    ioctl(dce_fd,TCSETAW,&dce_termio);    /* wait for I/O to drain */
  1025. X
  1026. X}    /* end of lwrite */
  1027. X
  1028. X/*+-------------------------------------------------------------------------
  1029. X    lbreak()
  1030. X--------------------------------------------------------------------------*/
  1031. Xvoid
  1032. Xlbreak()
  1033. X{
  1034. X    DEBUG(6,"Sent BREAK to DCE %s","<<");
  1035. X    ioctl(dce_fd,TCSBRK,(char *)1);
  1036. X    DEBUG(6,">>-%s\n","SUCCESS");
  1037. X}    /* end of lbreak */
  1038. X
  1039. X/*+-------------------------------------------------------------------------
  1040. X    lflash_DTR() - flash DTR
  1041. X
  1042. XDTR is lowered and raised again.  The timing can be modified on a
  1043. Xper-DCE basis.
  1044. X
  1045. XOn SunOS and SVR4, an open/close of the line is required to get DTR back
  1046. Xup. SVR3 does not seem to need this (ISC asy, SCO sio, Uwe Doering's FAS)
  1047. Xbut we do it anyway
  1048. X--------------------------------------------------------------------------*/
  1049. Xvoid
  1050. Xlflash_DTR()
  1051. X{
  1052. X#undef NEED_REOPEN
  1053. X#if defined(sun) || defined(SVR4)
  1054. X#define NEED_REOPEN
  1055. X    int tempfd;
  1056. X#endif
  1057. X    struct termio b0t;
  1058. X
  1059. X    b0t = dce_termio;
  1060. X    b0t.c_cflag &= ~CBAUD;
  1061. X
  1062. X    ioctl(dce_fd,TCSETA,(char *)&b0t);        /* drop DTR */
  1063. X    DEBUG(6,"setting DTR low ... ","");
  1064. X#ifdef NEED_REOPEN
  1065. X    if ((tempfd = open(dce_name,O_NDELAY | O_RDWR,0777)) != -1)
  1066. X        close(tempfd);
  1067. X#else
  1068. X    Nap((DCE_DTR_low_msec) ? DCE_DTR_low_msec : 300L);
  1069. X#endif
  1070. X    ioctl(dce_fd,TCSETA,(char *)&dce_termio);    /* raise DTR */
  1071. X    DEBUG(6,"back to high","");
  1072. X    Nap((DCE_DTR_high_msec) ? DCE_DTR_high_msec : 300L);
  1073. X    DEBUG(6,"\n","");
  1074. X#undef NEED_REOPEN
  1075. X}    /* end of lflash_DTR */
  1076. X
  1077. X/*+-------------------------------------------------------------------------
  1078. X    call_ungetty(call_type)
  1079. X
  1080. Xtype: 'a' - acquire dce_name
  1081. X      't' - test to see if dce_name should be returned
  1082. X      'r' - return dce_name
  1083. X
  1084. XThis function is a no-op in HDB UUCP versions
  1085. X--------------------------------------------------------------------------*/
  1086. Xcall_ungetty(call_type)
  1087. Xchar call_type;
  1088. X{
  1089. X#if defined(HDB_UUCP)
  1090. X    switch(call_type)
  1091. X    {
  1092. X        case 'a': return(UG_NOTENAB);        /* simulate complete success */
  1093. X        case 't': return(UG_RESTART);        /* simulate need for re-setup */
  1094. X        case 'r': return(0);                /* simulate complete success */
  1095. X    }
  1096. X    return(0);
  1097. X#else /* HDB_UUCP */
  1098. Xint itmp;
  1099. Xint pid;
  1100. Xunsigned int wait_status;
  1101. Xstatic char *ungetty = "/usr/lib/uucp/ungetty";
  1102. X
  1103. X    if((pid = fork()) == 0)
  1104. X    {
  1105. X        if(Debug >= 5)
  1106. X            ff(se,"%s: %s %s called\n",*gargv,ungetty,dce_name);
  1107. X        switch(call_type)
  1108. X        {
  1109. X            case 'a':
  1110. X                execl(ungetty,"ungetty",dce_name + 5,(char *)0);
  1111. X                break;
  1112. X            case 't':
  1113. X                execl(ungetty,"ungetty","-t",dce_name + 5,(char *)0);
  1114. X                break;
  1115. X            case 'r':
  1116. X                execl(ungetty,"ungetty","-r",dce_name + 5,(char *)0);
  1117. X                break;
  1118. X        }
  1119. X        ff(se,"%s exec error %d (%s)\n",ungetty,errno,sys_errlist[errno]);
  1120. X        _exit(-1);
  1121. X    }
  1122. X
  1123. X    while(((itmp = wait(&wait_status)) != pid) && itmp != -1)
  1124. X        ;
  1125. X
  1126. X    if(Debug >= 6)
  1127. X        ff(se,"%s pid %d exit status 0x%04x\n",ungetty,itmp,wait_status);
  1128. X
  1129. X    return((wait_status >> 8) & 0xFF);
  1130. X#endif /* HDB_UUCP */
  1131. X}    /* end of call_ungetty */
  1132. X
  1133. X/*+-----------------------------------------------------------------------
  1134. X    display_termio(ttt)
  1135. X  display termio 'ttt' on se
  1136. X------------------------------------------------------------------------*/
  1137. Xvoid
  1138. Xdisplay_termio(ttt,text)
  1139. Xstruct termio *ttt;
  1140. Xchar *text;
  1141. X{
  1142. Xregister flag;
  1143. Xregister i_cc;
  1144. Xregister char *cptr;
  1145. Xint dbits;
  1146. Xchar parity;
  1147. X
  1148. X    ff(se,"----->> %s\n",text);
  1149. X
  1150. X    flag = ttt->c_iflag;
  1151. X    ff(se,
  1152. X"iflag: %07o IGNBRK:%d BRKINT:%d IGNPAR:%d PARMRK:%d INPCK:%d ISTRIP:%d\n",
  1153. X                flag,
  1154. X                (flag & IGNBRK) ? 1 : 0,
  1155. X                (flag & BRKINT) ? 1 : 0,
  1156. X                (flag & IGNPAR) ? 1 : 0,
  1157. X                (flag & PARMRK) ? 1 : 0,
  1158. X                (flag & INPCK ) ? 1 : 0,
  1159. X                (flag & ISTRIP) ? 1 : 0);
  1160. X    ff(se,
  1161. X"       INLCR:%d IGNCR:%d ICRNL:%d IUCLC:%d IXON:%d IXANY:%d IXOFF:%d\n",
  1162. X                (flag & INLCR ) ? 1 : 0,
  1163. X                (flag & IGNCR ) ? 1 : 0,
  1164. X                (flag & ICRNL ) ? 1 : 0,
  1165. X                (flag & IUCLC ) ? 1 : 0,
  1166. X                (flag & IXON  ) ? 1 : 0,
  1167. X                (flag & IXANY ) ? 1 : 0,
  1168. X                (flag & IXOFF ) ? 1 : 0);
  1169. X
  1170. X    flag = ttt->c_oflag;
  1171. X    ff(se,
  1172. X"oflag: %07o OPOST:%d OLCUC:%d ONLCR:%d OCRNL:%d ONOCR:%d ONLRET:%d OFDEL:%d\n",
  1173. X                flag,
  1174. X                (flag & OPOST ) ? 1 : 0,
  1175. X                (flag & OLCUC ) ? 1 : 0,
  1176. X                (flag & ONLCR ) ? 1 : 0,
  1177. X                (flag & OCRNL ) ? 1 : 0,
  1178. X                (flag & ONOCR ) ? 1 : 0,
  1179. X                (flag & ONLRET) ? 1 : 0,
  1180. X                (flag & OFDEL ) ? 1 : 0);
  1181. X
  1182. X    flag = ttt->c_cflag;
  1183. X    ff(se,"cflag: %07o ",ttt->c_cflag);
  1184. X    switch(flag & CBAUD)
  1185. X    {
  1186. X        case B0:    cptr = "HUP"; break;
  1187. X        case B50:    cptr = "50"; break;
  1188. X        case B75:    cptr = "75"; break;
  1189. X        case B110:    cptr = "110"; break;
  1190. X        case B134:    cptr = "134.5"; break;
  1191. X        case B150:    cptr = "150"; break;
  1192. X        case B200:    cptr = "200"; break;
  1193. X        case B300:    cptr = "300"; break;
  1194. X        case B600:    cptr = "600"; break;
  1195. X        case B1200:    cptr = "1200"; break;
  1196. X        case B1800:    cptr = "1800"; break;
  1197. X        case B2400:    cptr = "2400"; break;
  1198. X        case B4800:    cptr = "4800"; break;
  1199. X        case B9600:    cptr = "9600"; break;
  1200. X        case EXTA:    cptr = "EXTA(19200?)"; break;
  1201. X        case EXTB:    cptr = "EXTB(38400?)"; break;
  1202. X        default:    cptr = "????"; break;
  1203. X    }
  1204. X    dbits = 5 + ((flag & CSIZE) >> 4);
  1205. X    parity = (flag & PARENB) ? ((flag & PARODD) ? 'O' : 'E') : 'N';
  1206. X    ff(se,"%s-%d-%c-%d ",cptr,dbits,parity,(flag & CSTOPB) ? 2 : 1);
  1207. X    switch(flag & CS8)
  1208. X    {
  1209. X        case CS8: fputs("CS8 ",se); break;
  1210. X        case CS7: fputs("CS7 ",se); break;
  1211. X        case CS6: fputs("CS6 ",se); break;
  1212. X        case CS5: fputs("CS5 ",se); break;
  1213. X    }
  1214. X    ff(se,"CREAD:%d HUPCL:%d CLOCAL:%d",
  1215. X                (flag & CREAD ) ? 1 : 0,
  1216. X                (flag & HUPCL ) ? 1 : 0,
  1217. X                (flag & CLOCAL) ? 1 : 0);
  1218. X#if defined(RTSFLOW)
  1219. X    ff(se," RTSFLOW:%d  CTSFLOW:%d",
  1220. X                (flag & RTSFLOW ) ? 1 : 0,
  1221. X                (flag & CTSFLOW ) ? 1 : 0);
  1222. X#endif
  1223. X    ff(se,"\n");
  1224. X
  1225. X    flag = ttt->c_lflag;
  1226. X    ff(se,"lflag: %07o ISIG:%d ICANON:%d XCASE:%d ECHO:%d ECHOE:%d\n",
  1227. X                flag,
  1228. X                (flag & ISIG  ) ? 1 : 0,
  1229. X                (flag & ICANON) ? 1 : 0,
  1230. X                (flag & XCASE ) ? 1 : 0,
  1231. X                (flag & ECHO  ) ? 1 : 0,
  1232. X                (flag & ECHOE ) ? 1 : 0);
  1233. X    ff(se,"       ECHOK:%d  ECHONL:%d  NOFLSH:%d  \n",
  1234. X                (flag & ECHOK ) ? 1 : 0,
  1235. X                (flag & ECHONL) ? 1 : 0,
  1236. X                (flag & NOFLSH) ? 1 : 0);
  1237. X
  1238. X    ff(se,
  1239. X"           INTR QUIT ERAS KILL EOF  EOL  EOL2 SWTCH VMIN==EOF VTIME==EOL\n");
  1240. X    ff(se,"ctl chars: ");
  1241. X    for(i_cc = 0; i_cc < NCC; i_cc++)
  1242. X        ff(se,"%02x   ",ttt->c_cc[i_cc]);
  1243. X    ff(se,"  (hex)\n");
  1244. X
  1245. X}    /* end of display_termio */
  1246. X
  1247. X/*+-------------------------------------------------------------------------
  1248. X    open_dce() - open the dce_name (DCE)
  1249. Xplugs global 'dce_fd' and returns fd of open DCE line
  1250. X--------------------------------------------------------------------------*/
  1251. Xint
  1252. Xopen_dce()
  1253. X{
  1254. Xint fd1;
  1255. Xint fd2;
  1256. X
  1257. X    /*  open with O_NDELAY set or the open probably will hang */
  1258. X    if((fd1 = open(dce_name,O_RDWR | O_NDELAY)) < 0)
  1259. X    {
  1260. X        ff(se,"%s: Can't open device: ",*gargv);
  1261. X        perror(dce_name);
  1262. X        myexit(RC_FAIL | RCE_OPEN | DialerExitCode);
  1263. X    }
  1264. X
  1265. X    ioctl(fd1,TCGETA,&dce_termio);
  1266. X    dce_termio.c_oflag = 0;
  1267. X    dce_termio.c_iflag = 0;
  1268. X    dce_termio.c_cflag &= ~(CBAUD | HUPCL);
  1269. X    dce_termio.c_cflag |= CLOCAL        |
  1270. X        ((hangup_flag) ? HUPCL : 0)        |
  1271. X        ((hangup_flag && DCE_hangup_CBAUD) ? DCE_hangup_CBAUD : hiCBAUD);
  1272. X    dce_termio.c_cflag |= CS8;
  1273. X    dce_termio.c_cc[VMIN] = 1;
  1274. X    dce_termio.c_cc[VTIME] = 0;
  1275. X    dce_termio.c_cflag &= ~PARENB;
  1276. X    dce_termio.c_lflag &= ~(ECHO | ICANON);
  1277. X#ifdef IEXTEN
  1278. X    dce_termio.c_lflag &= ~IEXTEN;
  1279. X#endif
  1280. X
  1281. X    if (Debug >= 10)
  1282. X
  1283. X        display_termio(&dce_termio,"setting line termio");
  1284. X
  1285. X    if(status = ioctl(fd1,TCSETA,&dce_termio))
  1286. X    {
  1287. X        DEBUG(1,"%s: ioctl error on %s",dce_name);
  1288. X        DEBUG(1,"%s",dce_name);
  1289. X        DEBUG(1," errno=%d\n",errno);
  1290. X        cleanup(RC_FAIL | RCE_IOCTL | DialerExitCode);
  1291. X    }
  1292. X
  1293. X    /* reopen line without O_NDELAY */
  1294. X    fd2 = fd1;
  1295. X    if((fd1 = open(dce_name,O_RDWR)) < 0)
  1296. X    {
  1297. X        ff(se,"%s: Can't open device w/o O_NDELAY: %s\n",*gargv,dce_name);
  1298. X        myexit(RC_FAIL | RCE_OPEN | DialerExitCode);
  1299. X    }
  1300. X    close(fd2);
  1301. X
  1302. X    ioctl(fd1,TCFLSH,2);        /* flush any residue in clists */
  1303. X    dce_fd = fd1;                /* save fd in global */
  1304. X    return(fd1);
  1305. X
  1306. X}    /* end of open_dce */
  1307. X
  1308. X/*+-------------------------------------------------------------------------
  1309. X    main(argc,argv)
  1310. X--------------------------------------------------------------------------*/
  1311. Xmain(argc,argv)
  1312. Xint argc;
  1313. Xchar **argv;
  1314. X{
  1315. Xint itmp;
  1316. Xint unrecognized_switches = 0;
  1317. Xchar *cptr;
  1318. Xlong startsec;
  1319. Xextern int optind;
  1320. Xextern int opterr;
  1321. Xextern char *optarg;
  1322. X
  1323. X    setbuf(stderr,NULL);
  1324. X    setbuf(stdout,NULL);
  1325. X
  1326. X/* security considerations */
  1327. X    uid = getuid();
  1328. X    uid_uucp = get_uucp_uid();
  1329. X    secure = 0;
  1330. X    if(!strncmp(argv[0],"ECU",3))
  1331. X        ecu_calling = 1;
  1332. X
  1333. X    gargv = argv;
  1334. X    gargc = argc;
  1335. X
  1336. X    signal(SIGILL,dial_abort);
  1337. X    signal(SIGIOT,dial_abort);
  1338. X    signal(SIGEMT,dial_abort);
  1339. X    signal(SIGFPE,dial_abort);
  1340. X    signal(SIGBUS,dial_abort);
  1341. X    signal(SIGSEGV,dial_abort);
  1342. X    signal(SIGSYS,dial_abort);
  1343. X    signal(SIGTERM,dial_abort);
  1344. X    signal(SIGINT,dial_abort);
  1345. X
  1346. X    signal(SIGCLD,SIG_DFL);
  1347. X
  1348. X#if    defined(SIGSTOP)
  1349. X    /*
  1350. X     * call Roto-Rooter on POSIX plots
  1351. X     */
  1352. X    signal(SIGSTOP,SIG_IGN);
  1353. X    signal(SIGTSTP,SIG_IGN);
  1354. X    signal(SIGCONT,SIG_IGN);
  1355. X    signal(SIGTTIN,SIG_IGN);
  1356. X    signal(SIGTTOU,SIG_IGN);
  1357. X#endif
  1358. X
  1359. X    opterr = 0;    
  1360. X    while((itmp = getopt(argc,argv,"hx:")) != EOF)
  1361. X    {
  1362. X        switch(itmp)
  1363. X        {
  1364. X            case 'h':
  1365. X                hangup_flag++;
  1366. X                break;
  1367. X            case 'x':
  1368. X                Debug = atoi(optarg);
  1369. X                break;
  1370. X            case '?':    /* dialer-specific code may want to handle these */
  1371. X                unrecognized_switches++;
  1372. X                break;
  1373. X        }
  1374. X    }
  1375. X
  1376. X/* learn tick rate for various timers */
  1377. X    init_Nap();
  1378. X
  1379. X/* announce who we are and our arguments if debugging */
  1380. X    if(Debug > 5)
  1381. X    {
  1382. X        ff(se,"\ngeneric dialer %s (%s %s)\n",revision,
  1383. X            DCE_name,DCE_revision);
  1384. X        if(ecu_calling || !uid)
  1385. X        {
  1386. X            ff(se,"(args ");
  1387. X            for(itmp = 0; itmp < argc; itmp++)
  1388. X                ff(se,"%s ",argv[itmp]);
  1389. X            fputs(")\n",se);
  1390. X        }
  1391. X    }
  1392. X    if(Debug >= 8)
  1393. X        ff(se,"uid = %d  euid=%d\n",uid,geteuid());
  1394. X
  1395. X    chdir(LOCK_DIR_NAME);    /* in case of core dump */
  1396. X
  1397. X    /* give DCE-specific code a chance at the entire command line */
  1398. X    if(status = DCE_argv_hook(argc,argv,optind,unrecognized_switches))
  1399. X    {
  1400. X        DEBUG(1,"dialer failed: %s\n",RCE_text(status));
  1401. X        exit(status);
  1402. X    }
  1403. X
  1404. X/* check argument count */
  1405. X    if(hangup_flag)
  1406. X    {
  1407. X        if((argc - optind) != 2)
  1408. X            status++;
  1409. X    }
  1410. X    else if((argc - optind) != 3)
  1411. X        status++;
  1412. X
  1413. X/* die with usage if argument error */
  1414. X    if(status)
  1415. X    {
  1416. X        if(hangup_flag)
  1417. X            ff(se,"Usage: %s -h devicename speed\n",argv[0]);
  1418. X        else
  1419. X            ff(se,"Usage: %s devicename number speed\n",argv[0]);
  1420. X        myexit(RC_FAIL | RCE_ARGS);
  1421. X    }
  1422. X
  1423. X/* if called with "ttyxx" style ttyname, convert to "/dev/ttyxx" */
  1424. X    cptr = argv[optind++];
  1425. X    if(!strncmp(cptr,"tty",3))
  1426. X    {
  1427. X    char s32[32];
  1428. X        strcpy(s32,"/dev/");
  1429. X        strcat(s32,cptr);
  1430. X        dce_name = strdup(s32);
  1431. X    }
  1432. X    else
  1433. X        dce_name = cptr;
  1434. X
  1435. X/* save phone number */
  1436. X    if(!hangup_flag)
  1437. X        telno = argv[optind++];
  1438. X
  1439. X/* get baud rates (validated by DCE-dependent code) */
  1440. X    loCBAUD = hiCBAUD = DCE_baud_to_CBAUD(atoi(argv[optind]));
  1441. X    if(cptr = strchr(argv[optind],'-'))
  1442. X        hiCBAUD = DCE_baud_to_CBAUD(atoi(++cptr));
  1443. X
  1444. X    (void)open_dce();    /* open the line */
  1445. X
  1446. X/*   H A N G U P     R E Q U E S T   */
  1447. X    if(hangup_flag)
  1448. X    {
  1449. X        if(call_ungetty('t') != UG_RESTART)
  1450. X            cleanup(SUCCESS);
  1451. X        DCE_hangup();
  1452. X        cleanup((call_ungetty('r')) ? RC_FAIL : SUCCESS );
  1453. X    }
  1454. X
  1455. X/*   D I A L    R E Q U E S T    */
  1456. X
  1457. X    switch(call_ungetty('a'))
  1458. X    {
  1459. X        case UG_NOTENAB:    /* line acquired: not enabled */
  1460. X            status = SUCCESS;
  1461. X            break;
  1462. X        case UG_ENAB:        /* line acquired: need ungetty -r when done */
  1463. X            status = RC_ENABLED;
  1464. X            break;
  1465. X        case UG_FAIL:        /* could not acquire line */
  1466. X            myexit(RC_FAIL | RCE_INUSE);
  1467. X        case 255:
  1468. X            myexit(RC_FAIL | RCE_NULL);
  1469. X    }
  1470. X
  1471. X    /*
  1472. X     * indicate we are dialing
  1473. X     * record the time and, oh yeah, dial
  1474. X     */
  1475. X    dialing = 1;
  1476. X    time(&startsec);
  1477. X    status = DCE_dial(telno);        /* if dial succeeded ... */
  1478. X    if(Debug >= 2)
  1479. X    {
  1480. X        ff(se,"connect %s after %ld seconds\n",
  1481. X            (status) ? "FAILED" : "succeeded",
  1482. X            time((long *)0) - startsec);
  1483. X    }
  1484. X
  1485. X    /*
  1486. X     * success or not
  1487. X     */
  1488. X    myexit(((status) ? RC_FAIL : 0) | status);
  1489. X}    /* end of main */
  1490. X
  1491. X/*+-------------------------------------------------------------------------
  1492. X    rdchk(fd) - for systems without it but with FIONREAD
  1493. X--------------------------------------------------------------------------*/
  1494. X#if defined(sun)
  1495. Xint
  1496. Xrdchk(fd)
  1497. Xint fd;
  1498. X{
  1499. Xint chars_waiting;
  1500. X
  1501. X    if(ioctl(fd,FIONREAD,&chars_waiting))
  1502. X    {
  1503. X        if(Debug > 2)
  1504. X        {
  1505. X            fprintf(stderr,"!!! fd %d ",fd);
  1506. X            perror("rdchk FIONREAD");
  1507. X        }
  1508. X        return(0);
  1509. X    }
  1510. X    else
  1511. X    {
  1512. X        DEBUG(11,"rdchk-%d\n",chars_waiting);
  1513. X        return(!!chars_waiting);
  1514. X    }
  1515. X}    /* end of rdchk */
  1516. X#endif
  1517. X
  1518. X/* end of gendial.c */
  1519. X/* vi: set tabstop=4 shiftwidth=4: */
  1520. SHAR_EOF
  1521. chmod 0644 gendial/gendial.c ||
  1522. echo 'restore of gendial/gendial.c failed'
  1523. Wc_c="`wc -c < 'gendial/gendial.c'`"
  1524. test 31052 -eq "$Wc_c" ||
  1525.     echo 'gendial/gendial.c: original size 31052, current size' "$Wc_c"
  1526. rm -f _shar_wnt_.tmp
  1527. fi
  1528. # ============= gendial/tbit.sync.h ==============
  1529. if test -f 'gendial/tbit.sync.h' -a X"$1" != X"-c"; then
  1530.     echo 'x - skipping gendial/tbit.sync.h (File already exists)'
  1531.     rm -f _shar_wnt_.tmp
  1532. else
  1533. > _shar_wnt_.tmp
  1534. echo 'x - extracting gendial/tbit.sync.h (Text)'
  1535. sed 's/^X//' << 'SHAR_EOF' > 'gendial/tbit.sync.h' &&
  1536. X/*+-------------------------------------------------------------------------
  1537. X    sync_Telebit() - sync modem with our DTE speed
  1538. X--------------------------------------------------------------------------*/
  1539. X/*+:EDITS:*/
  1540. X/*:09-10-1992-13:59-wht@n4hgf-ECU release 3.20 */
  1541. X/*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA */
  1542. X/*:03-30-1992-14:18-root@n4hgf-add lbreak before wakeup */
  1543. Xvoid
  1544. Xsync_Telebit()
  1545. X{
  1546. X    register int maxretry = 4;
  1547. X    register int count;
  1548. X    unsigned char rdchar;
  1549. X    long pace_msec_save = DCE_write_pace_msec;
  1550. X
  1551. X    while(--maxretry)
  1552. X    {
  1553. X        lbreak();
  1554. X        Nap(200L);
  1555. X        DCE_write_pace_msec = 50;
  1556. X        lwrite("aaaaaate1\r");
  1557. X        DCE_write_pace_msec = pace_msec_save;
  1558. X        Nap(200L);
  1559. X        lflush();
  1560. X        count = 5;
  1561. X        while(count)    /* wait 120-200 msec for character, depending on HZ */
  1562. X        {
  1563. X            write(dce_fd,"a",1);
  1564. X            ioctl(dce_fd,TCSETAW,&dce_termio);    /* wait for I/O to drain */
  1565. X            Nap(120L);    /* must handle 110 baud */
  1566. X            if(rdchk(dce_fd))
  1567. X                break;
  1568. X            count--;
  1569. X        }
  1570. X        rdchar = 0;
  1571. X        if(count && (read(dce_fd,&rdchar,1) == 1) && ((rdchar & 0x7F) == 'a'))
  1572. X        {
  1573. X            Nap(120L);
  1574. X            lflush();
  1575. X            return;
  1576. X        }
  1577. X        DEBUG(2,"Telebit SYNC failed ... retrying (%02x)\n",rdchar);
  1578. X        lflash_DTR();
  1579. X    }
  1580. X
  1581. X    DEBUG(1,"Telebit SYNC FAILED\n",0);
  1582. X    myexit(RC_FAIL | RCE_TIMOUT);
  1583. X
  1584. X}    /* end of sync_Telebit */
  1585. X
  1586. SHAR_EOF
  1587. chmod 0644 gendial/tbit.sync.h ||
  1588. echo 'restore of gendial/tbit.sync.h failed'
  1589. Wc_c="`wc -c < 'gendial/tbit.sync.h'`"
  1590. test 1263 -eq "$Wc_c" ||
  1591.     echo 'gendial/tbit.sync.h: original size 1263, current size' "$Wc_c"
  1592. rm -f _shar_wnt_.tmp
  1593. fi
  1594. # ============= gendial/template.c ==============
  1595. if test -f 'gendial/template.c' -a X"$1" != X"-c"; then
  1596.     echo 'x - skipping gendial/template.c (File already exists)'
  1597.     rm -f _shar_wnt_.tmp
  1598. else
  1599. > _shar_wnt_.tmp
  1600. echo 'x - extracting gendial/template.c (Text)'
  1601. sed 's/^X//' << 'SHAR_EOF' > 'gendial/template.c' &&
  1602. X/*+-------------------------------------------------------------------------
  1603. X    template.c - DCE-specific portion of generic SCO UUCP dialer
  1604. X    wht@n4hgf.Mt-Park.GA.US
  1605. X
  1606. X Necessary DCE switch setting or other configuration:
  1607. X   Switch foo off: enable onhook upon loss of DTR
  1608. X--------------------------------------------------------------------------*/
  1609. X/*+:EDITS:*/
  1610. X/*:09-10-1992-13:59-wht@n4hgf-ECU release 3.20 */
  1611. X/*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA */
  1612. X/*:02-02-1992-18:01-root@n4hgf-proper ordering of DCE_result entries */
  1613. X/*:01-26-1992-15:31-wht@n4hgf-gendial 1.2 for ecu 3.20- better hangup */
  1614. X/*:07-25-1991-12:58-wht@n4hgf-ECU release 3.10 */
  1615. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  1616. X
  1617. X#include "dialer.h"
  1618. X
  1619. X/*
  1620. X * DCE_DTR_low_msec - milliseconds to hold DTR low to ensure DCE
  1621. X *                    sees the transition; this value may be changed
  1622. X *                    as necessary before each call to lflash_DTR(),
  1623. X * but, generally, a constant value will do.
  1624. X */
  1625. Xlong DCE_DTR_low_msec = 500;
  1626. X
  1627. X/*
  1628. X * DCE_DTR_high_msec - milliseconds DTR must remain high before the
  1629. X *                     DCE may be expected to be ready to be commanded
  1630. X */
  1631. Xlong DCE_DTR_high_msec = 500;
  1632. X
  1633. X/*
  1634. X * DCE_write_pace_msec - milliseconds to pause between each character
  1635. X *                       sent to the DCE (zero if streaming I/O is
  1636. X *                       permitted); this value may be changed as
  1637. X * necessary before each call to lwrite(), but, generally, a constant
  1638. X * value will do.  Note that this value is used to feed a value to Nap(),
  1639. X * which has a granularity of .010 seconds on UNIX/386, .020 on XENIX/286
  1640. X * and .050 seconds on XENIX/86.
  1641. X */
  1642. Xlong DCE_write_pace_msec = 20;
  1643. X
  1644. X/*
  1645. X * DCE_name     - short name for DCE
  1646. X * DCE_revision - revision number for this module
  1647. X */
  1648. Xchar *DCE_name = "Frobozz 9600";
  1649. Xchar *DCE_revision = "1.10";
  1650. X
  1651. X/*
  1652. X * DCE_hangup_CBAUD - baud rate to use for hanging up DCE
  1653. X *                    and readying it for dial in access
  1654. X *                    (BXXX mask); use a value of zero if the speed
  1655. X *                    specified by the invoker is to be used.
  1656. X * This value is useful for DCEs such as the early Hayes 2400
  1657. X * which are so unfortunately compatible with their 1200 predecessor
  1658. X * that they refuse to answer at 2400 baud unless you last spoke to
  1659. X * them at that rate. For such bad boys, use B2400 below.
  1660. X */
  1661. Xint DCE_hangup_CBAUD = 0;
  1662. X/* int DCE_hangup_CBAUD = B2400; */
  1663. X
  1664. X/*
  1665. X * DCE_results - a table of DCE response strings and a token
  1666. X *               code for each; when you call lread() or lread_ignore(),
  1667. X *               if the read routine detects one of the strings,
  1668. X * the appropriate code is returned.  If no string matches, then
  1669. X * lread()/lread_ignore examines the DCE result string for a
  1670. X * numeric value; if one is found, the numeric value or'd with
  1671. X * 0x4000 is returned (in this way, e.g., you can read "modem
  1672. X * S registers."  If nothing agrees with this search, lread()
  1673. X * will abort the program with RC|FAIL|RCE_TIMOUT, lread_ignore()
  1674. X * will return -1.  You may use any value between 0 and 0x3FFFFFFF.
  1675. X * This module is the only consumer  of the codes, although they
  1676. X * are decoded by gendial.c's _lread().
  1677. X *
  1678. X * If one possible result is an "early substring" of another, like
  1679. X * "CONNECT" is of "CONNECT 1200", then put such results later in the
  1680. X * table than the larger result.
  1681. X *
  1682. X */
  1683. X#define rfConnect        0x00400000
  1684. X
  1685. X#define rOk                0
  1686. X#define rNoCarrier        1
  1687. X#define rError            2
  1688. X#define rNoDialTone        3
  1689. X#define rBusy            4
  1690. X#define rNoAnswer        5
  1691. X#define rRring            6
  1692. X#define rConnect300        (7 | rfConnect)
  1693. X#define rConnect1200    (8 | rfConnect)
  1694. X#define rConnect2400    (9 | rfConnect)
  1695. X
  1696. XDCE_RESULT DCE_results[] =
  1697. X{
  1698. X    { "OK",                        rOk,            },
  1699. X    { "NO CARRIER",                rNoCarrier,        },
  1700. X    { "ERROR",                    rError            },
  1701. X    { "NO DIALTONE",            rNoDialTone,    },
  1702. X    { "BUSY",                    rBusy            },
  1703. X    { "NO ANSWER",                rNoAnswer        },
  1704. X    { "CONNECT 1200",            rConnect120        },
  1705. X    { "CONNECT 2400",            rConnect2400    },
  1706. X    { "CONNECT",                rConnect300        },
  1707. X    { (char *)0,                -1                }        /* end table */
  1708. X};
  1709. X
  1710. X/*+-------------------------------------------------------------------------
  1711. X    DCE_baud_to_CBAUD(baud) - check for valid baud rates supported by DCE
  1712. X
  1713. X  DCE dependent function must validate baud rates supported by DCE
  1714. X  returns baud rate in struct termio c_cflag fashion
  1715. X  or terminates program with error
  1716. X--------------------------------------------------------------------------*/
  1717. Xint
  1718. XDCE_baud_to_CBAUD(baud)
  1719. Xunsigned int baud;
  1720. X{
  1721. X    switch(baud)
  1722. X    {
  1723. X        case 50:   return(B50);        /* delete the ones you dont handle */
  1724. X        case 75:   return(B75);
  1725. X        case 110:  return(B110);
  1726. X        case 134:  return(B134);
  1727. X        case 150:  return(B150);
  1728. X        case 300:  return(B300);
  1729. X        case 1200: return(B1200);
  1730. X        case 2400: return(B2400);
  1731. X        case 4800: return(B4800);
  1732. X        case 9600: return(B9600);
  1733. X
  1734. X#if defined(B19200)
  1735. X        case 19200: return(B19200);
  1736. X#else
  1737. X#ifdef EXTA
  1738. X        case 19200: return(EXTA);
  1739. X#endif
  1740. X#endif
  1741. X
  1742. X#if defined(B38400)
  1743. X        case 38400: return(B38400);
  1744. X#else
  1745. X#ifdef EXTB
  1746. X        case 38400: return(EXTB);
  1747. X#endif
  1748. X#endif
  1749. X
  1750. X    }
  1751. X    myexit(RC_FAIL | RCE_SPEED);
  1752. X#if defined(OPTIMIZE) || defined(__OPTIMIZE__)    /* don't complain */
  1753. X    return(0);    /* keep gcc from complaining about no rtn at end */
  1754. X#endif
  1755. X}    /* end of DCE_baud_to_CBAUD */
  1756. X
  1757. X/*+-------------------------------------------------------------------------
  1758. X    DCE_hangup() - issue hangup command to DCE
  1759. X
  1760. XThis function should do whatever is necessary to ensure
  1761. X1) any active connection is terminated
  1762. X2) the DCE is ready to receive an incoming call if DTR is asserted
  1763. X3) the DCE will not accept an incoming call if DTR is false
  1764. X
  1765. XThe function should return when done.
  1766. X
  1767. XAny necessary switch setting or other configuration necessary for this
  1768. Xfunction to succeed should be documented at the top of the module.
  1769. X--------------------------------------------------------------------------*/
  1770. Xvoid
  1771. XDCE_hangup()
  1772. X{
  1773. X    DEBUG(3,"--> reseting %s\n",DCE_name);
  1774. X    lflash_DTR();
  1775. X
  1776. X}    /* end of DCE_hangup */
  1777. X
  1778. X/*+-------------------------------------------------------------------------
  1779. X    DCE_dial(telno) - dial a remote DCE
  1780. X
  1781. XThis function should connect to the remote DCE and use any success
  1782. Xindication to modify the tty baud rate if necessary before returning.
  1783. X
  1784. XUpon successful connection, return 0.
  1785. X
  1786. XUpon unsuccessful connection, return RC_FAIL or'd with an appropriate
  1787. XRCE_XXX value from dialer.h.
  1788. X
  1789. Xlwrite() is used to write to the DCE.
  1790. X
  1791. Xlread() and lread_ignore() are used to read from the DCE.  Read timeouts
  1792. Xfrom calling lread() will result automatically in the proper error
  1793. Xtermination of the program.  Read timeouts from calling lread_ignore()
  1794. Xreturn -1; you handle the execption here.
  1795. X
  1796. XAny necessary coding of phone numbers, switch settings or other
  1797. Xconfiguration necessary for this function to succeed should be
  1798. Xdocumented at the top of the module.
  1799. X--------------------------------------------------------------------------*/
  1800. Xint
  1801. XDCE_dial(telno)
  1802. Xchar *telno;
  1803. X{
  1804. Xchar cmd[80];
  1805. X
  1806. X/* preliminary setup */
  1807. X
  1808. X/* if root, let him see number, otherwise just say "remote system" */
  1809. X    DEBUG(1,"DIALING %s\n", (uid) ? "remote system" : telno);
  1810. X
  1811. X/* indicate non-root should not see DTE->DCE traffic */
  1812. X    secure = 1;
  1813. X
  1814. X/* issue the actual dialing command */
  1815. X
  1816. X/* indicate non-root can see DTE->DCE traffic */
  1817. X    secure = 0;
  1818. X
  1819. X    return(0);        /* succeeded */
  1820. X
  1821. X}    /* end of DCE_dial */
  1822. X
  1823. X/**********************************************************
  1824. X*  You probably do not need to modify the code below here *
  1825. X**********************************************************/
  1826. X
  1827. X/*+-------------------------------------------------------------------------
  1828. X    DCE_abort(sig) - dial attempt aborted
  1829. X
  1830. X sig =  0 if non-signal abort (read timeout, most likely)
  1831. X     != 0 if non-SIGALRM signal caught
  1832. X
  1833. X extern int dialing set  1 if dialing request was active,
  1834. X                    else 0 if hangup request was active
  1835. X
  1836. XThis is a chance for the DCE-specific code to do anything it
  1837. Xneeds to cl,ean up after a failure.  Note that if a dialing
  1838. Xcall fails, it is the responsibility of the higher-level
  1839. Xprogram calling the dialer to call it again with a hangup request, so
  1840. Xthis function is usually a no-op.
  1841. X--------------------------------------------------------------------------*/
  1842. Xvoid
  1843. XDCE_abort(sig)
  1844. Xint sig;
  1845. X{
  1846. X    DEBUG(10,"DCE_abort(%d);\n",sig);
  1847. X}    /* end of DCE_abort */
  1848. X
  1849. X/*+-------------------------------------------------------------------------
  1850. X    DCE_exit(exitcode) - "last chance for gas" in this incarnation
  1851. X
  1852. XThe independent portion of the dialer program calls this routine in
  1853. Xlieu of exit() in every case except one (see DCE_argv_hook() below).
  1854. XNormally, this function just passes it's argument to exit(), but
  1855. Xany necessary post-processing can be done.  The function must,
  1856. Xhowever, eventually call exit(exitcode);
  1857. X--------------------------------------------------------------------------*/
  1858. Xvoid
  1859. XDCE_exit(exitcode)
  1860. Xint exitcode;
  1861. X{
  1862. X    DEBUG(10,"DCE_exit(%d);\n",exitcode);
  1863. X    exit(exitcode);
  1864. X}    /* end of DCE_exit */
  1865. X
  1866. X/*+-------------------------------------------------------------------------
  1867. X    DCE_argv_hook(argc,argv,optind,unrecognized_switches)
  1868. X
  1869. XThis hook gives DCE-specific code a chance to look over the entire
  1870. Xcommand line, such as for -z Telebit processing.
  1871. X
  1872. Xargc andf argv are the same values passed to main(),
  1873. X
  1874. Xoptind is the value of optind at the end of normal getopt processing.
  1875. X
  1876. Xunrecognized_switches is the count of switches not handled by main().
  1877. XSpecifically, -h and -x are standard switches.
  1878. X
  1879. XNormally, this function should just return RC_FAIL|RCE_ARGS if there are
  1880. Xany unrecognized switches, otherwise zero.  If you keep your nose clean
  1881. Xthough, you can do anything you need to do here and exit the program.
  1882. X
  1883. XNote: only simple switches (with no argument) may be used with this
  1884. Xfacility if the functrion is to return,' since main()'s getopt() will
  1885. Xstop processing switches if it runs into an unrecognized switch with an
  1886. Xargument.
  1887. X
  1888. XIf the function returns a non-zero value, then the value will be passed
  1889. XDIRECTLY to exit() with no further ado.  Thus, a non-zero value must be
  1890. Xof the format expected by dialer program callers, with RC_FAIL set as a
  1891. Xminimum.
  1892. X--------------------------------------------------------------------------*/
  1893. Xint
  1894. XDCE_argv_hook(argc,argv,optind,unrecognized_switches)
  1895. Xint argc;
  1896. Xchar **argv;
  1897. Xint optind;
  1898. Xint unrecognized_switches;
  1899. X{
  1900. X    if(unrecognized_switches)
  1901. X        return(RC_FAIL | RCE_ARGS);
  1902. X    return(0);
  1903. X}    /* end of DCE_argv_hook */
  1904. X
  1905. X/* vi: set tabstop=4 shiftwidth=4: */
  1906. SHAR_EOF
  1907. chmod 0644 gendial/template.c ||
  1908. echo 'restore of gendial/template.c failed'
  1909. Wc_c="`wc -c < 'gendial/template.c'`"
  1910. test 10357 -eq "$Wc_c" ||
  1911.     echo 'gendial/template.c: original size 10357, current size' "$Wc_c"
  1912. rm -f _shar_wnt_.tmp
  1913. fi
  1914. # ============= fasi/Makefile ==============
  1915. if test ! -d 'fasi'; then
  1916.     echo 'x - creating directory fasi'
  1917.     mkdir 'fasi'
  1918. fi
  1919. if test -f 'fasi/Makefile' -a X"$1" != X"-c"; then
  1920.     echo 'x - skipping fasi/Makefile (File already exists)'
  1921.     rm -f _shar_wnt_.tmp
  1922. else
  1923. > _shar_wnt_.tmp
  1924. echo 'x - extracting fasi/Makefile (Text)'
  1925. sed 's/^X//' << 'SHAR_EOF' > 'fasi/Makefile' &&
  1926. X# FAS 2.08/FASI 1.00 Makefile for SCO UNIX SYS V/386
  1927. X#+:EDITS:*/
  1928. X#:09-10-1992-13:59-wht@n4hgf-ECU release 3.20
  1929. X#:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA
  1930. X#:01-17-1991-01:38-wht@n4hgf-adapt FAS 2.08 SCO make file
  1931. X
  1932. XSHELL = /bin/sh
  1933. XINCLLOC = /usr/include/local
  1934. XLKDRVRDIR = /etc/conf/pack.d/fas
  1935. XLKSCONFDIR = /etc/conf/sdevice.d
  1936. XLKNCONFDIR = /etc/conf/node.d
  1937. XLKICONFDIR = /etc/conf/init.d
  1938. XLKKCONFDIR = /etc/conf/kconfig.d
  1939. XDRVRNAME = Driver.o
  1940. XCONFNAME = fas
  1941. X
  1942. XCC = rcc
  1943. XCFLAGS = -O -DINKERNEL -DSCO -DNEED_PUT_GETCHAR -DFASI
  1944. X
  1945. XOBJS = fas.o
  1946. X
  1947. Xfas.o:     fas.c $(INCLLOC)/fas.h $(INCLLOC)/digi-pc8.h Makefile
  1948. X
  1949. XDriver.o: fas.o
  1950. X    rm -rf Driver.o
  1951. X    ln fas.o Driver.o
  1952. X
  1953. Xinstall: Driver.o
  1954. X    sh -v idfasi
  1955. X
  1956. Xinstall2: install
  1957. X    cd /etc/conf/cf.d;./link_unix
  1958. X
  1959. Xspace.c:
  1960. X    @echo "You must copy the proper space-xxxxx file to \`space.c'"
  1961. X    @false
  1962. X    
  1963. Xs_$(CONFNAME):
  1964. X    @echo "You must copy the proper s_$(CONFNAME)-xxxxx file to \`s_$(CONFNAME)'"
  1965. X    @false
  1966. X        
  1967. Xn_$(CONFNAME):
  1968. X    @echo "You must copy the proper n_$(CONFNAME)-xxxxx file to \`n_$(CONFNAME)'"
  1969. X    @false
  1970. X        
  1971. Xi_$(CONFNAME):
  1972. X    @echo "You must copy the proper i_$(CONFNAME)-xxxxx file to \`i_$(CONFNAME)'"
  1973. X    @false
  1974. X        
  1975. X$(INCLLOC)/fas.h: fas.h
  1976. X    -mkdir $(INCLLOC) >/dev/null 2>&1
  1977. X    cp fas.h $(INCLLOC)/fas.h
  1978. X
  1979. X$(INCLLOC)/digi-pc8.h: digi-pc8.h
  1980. SHAR_EOF
  1981. true || echo 'restore of fasi/Makefile failed'
  1982. fi
  1983. echo 'End of ecu320 part 30'
  1984. echo 'File fasi/Makefile is continued in part 31'
  1985. echo 31 > _shar_seq_.tmp
  1986. exit 0
  1987.  
  1988. exit 0 # Just in case...
  1989.