home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / sources / misc / 3957 < prev    next >
Encoding:
Text File  |  1992-09-14  |  57.2 KB  |  1,995 lines

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